summaryrefslogtreecommitdiff
path: root/email-core
diff options
context:
space:
mode:
authorjk7744.park <jk7744.park@samsung.com>2015-10-24 16:46:12 +0900
committerjk7744.park <jk7744.park@samsung.com>2015-10-24 16:46:12 +0900
commit387edc5c45273dbb909f2c1f565c536f9755e9f4 (patch)
tree7b08e049f1c096c170b057b36821e20630eccdf9 /email-core
parente19fb4a5f4276630b562ccbb55aa9080662f66d4 (diff)
downloademail-service-387edc5c45273dbb909f2c1f565c536f9755e9f4.tar.gz
email-service-387edc5c45273dbb909f2c1f565c536f9755e9f4.tar.bz2
email-service-387edc5c45273dbb909f2c1f565c536f9755e9f4.zip
Diffstat (limited to 'email-core')
-rwxr-xr-xemail-core/CMakeLists.txt42
-rwxr-xr-xemail-core/email-core-account.c509
-rwxr-xr-xemail-core/email-core-alarm.c13
-rwxr-xr-xemail-core/email-core-auto-download.c65
-rwxr-xr-xemail-core/email-core-cert.c147
-rw-r--r--email-core/email-core-container.c441
-rwxr-xr-xemail-core/email-core-event.c120
-rwxr-xr-xemail-core/email-core-gmime.c589
-rwxr-xr-xemail-core/email-core-imap-idle.c177
-rwxr-xr-xemail-core/email-core-imap-mailbox.c109
-rwxr-xr-xemail-core/email-core-mail.c2758
-rwxr-xr-xemail-core/email-core-mailbox-sync.c2515
-rwxr-xr-xemail-core/email-core-mailbox.c318
-rwxr-xr-xemail-core/email-core-mime.c5050
-rwxr-xr-xemail-core/email-core-mm-callbacks.c19
-rw-r--r--email-core/email-core-pgp.c132
-rwxr-xr-xemail-core/email-core-signal.c95
-rwxr-xr-xemail-core/email-core-smime.c269
-rwxr-xr-xemail-core/email-core-smtp.c708
-rwxr-xr-xemail-core/email-core-task-manager.c1324
-rwxr-xr-xemail-core/email-core-tasks.c119
-rwxr-xr-xemail-core/email-core-timer.c11
-rwxr-xr-xemail-core/email-core-utils.c980
-rwxr-xr-xemail-core/email-network/email-network.c6
-rwxr-xr-xemail-core/email-storage/email-storage.c2016
-rwxr-xr-xemail-core/email-storage/include/email-storage.h420
-rwxr-xr-xemail-core/include/email-core-account.h32
-rwxr-xr-xemail-core/include/email-core-alarm.h3
-rwxr-xr-xemail-core/include/email-core-auto-download.h5
-rwxr-xr-xemail-core/include/email-core-cert.h4
-rw-r--r--email-core/include/email-core-container.h45
-rwxr-xr-xemail-core/include/email-core-event.h2
-rw-r--r--email-core/include/email-core-gmime.h5
-rwxr-xr-xemail-core/include/email-core-imap-mailbox.h15
-rwxr-xr-xemail-core/include/email-core-mail.h134
-rwxr-xr-xemail-core/include/email-core-mailbox-sync.h35
-rwxr-xr-xemail-core/include/email-core-mailbox.h26
-rwxr-xr-xemail-core/include/email-core-mime.h4
-rwxr-xr-xemail-core/include/email-core-smime.h6
-rwxr-xr-xemail-core/include/email-core-smtp.h24
-rwxr-xr-xemail-core/include/email-core-task-manager.h6
-rwxr-xr-xemail-core/include/email-core-tasks.h5
-rwxr-xr-xemail-core/include/email-core-utils.h53
43 files changed, 7958 insertions, 11398 deletions
diff --git a/email-core/CMakeLists.txt b/email-core/CMakeLists.txt
index ab63631..c2aa3a8 100755
--- a/email-core/CMakeLists.txt
+++ b/email-core/CMakeLists.txt
@@ -29,7 +29,6 @@ INCLUDE_DIRECTORIES(
${CMAKE_SOURCE_DIR}/email-core/email-device/include
)
-
INCLUDE(FindPkgConfig)
pkg_check_modules(device_pkgs REQUIRED glib-2.0 dlog vconf capi-system-device dbus-1)
@@ -132,6 +131,39 @@ SET_TARGET_PROPERTIES(${NETWORK-LIB} PROPERTIES VERSION ${VERSION})
INSTALL(TARGETS ${NETWORK-LIB} DESTINATION lib COMPONENT RuntimeLibraries)
##########################################################
+# Define container lib
+##########################################################
+
+SET(CONTAINER-LIB "email-container")
+SET(CONTAINER-SRCS
+ ${CMAKE_SOURCE_DIR}/email-core/email-core-container.c
+)
+
+INCLUDE_DIRECTORIES(
+ ${CMAKE_SOURCE_DIR}/email-common-use/include
+)
+
+INCLUDE(FindPkgConfig)
+SET(PKG_MODULES glib-2.0 vasum)
+
+pkg_check_modules(container_pkgs REQUIRED ${PKG_MODULES})
+
+FOREACH(flag ${container_pkgs_CFLAGS})
+ SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
+
+SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed")
+
+ADD_LIBRARY(${CONTAINER-LIB} SHARED ${CONTAINER-SRCS})
+TARGET_LINK_LIBRARIES(${CONTAINER-LIB} ${container_pkgs_LDFLAGS} dl)
+SET_TARGET_PROPERTIES(${CONTAINER-LIB} PROPERTIES SOVERSION ${VERSION_MAJOR})
+SET_TARGET_PROPERTIES(${CONTAINER-LIB} PROPERTIES VERSION ${VERSION})
+
+INSTALL(TARGETS ${CONTAINER-LIB} DESTINATION lib COMPONENT RuntimeLibraries)
+
+##########################################################
# Define Core lib
##########################################################
@@ -169,11 +201,13 @@ INCLUDE_DIRECTORIES(
INCLUDE(FindPkgConfig)
-pkg_check_modules(core_pkgs REQUIRED glib-2.0 dlog dbus-1 gthread-2.0
+SET(PKG_MODULES glib-2.0 dlog dbus-1 gthread-2.0
uw-imap-toolkit vconf vconf-internal-keys contacts-service2 secure-storage
- openssl accounts-svc alarm-service notification libcurl libxml-2.0 feedback
+ openssl accounts-svc alarm-service notification libcurl libxml-2.0
cert-svc cert-svc-vcore badge capi-appfw-application icu-i18n gmime-2.6 storage)
+pkg_check_modules(core_pkgs REQUIRED ${PKG_MODULES})
+
set(EXTRA_CFLAGS "")
FOREACH(flag ${core_pkgs_CFLAGS})
SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
@@ -208,7 +242,7 @@ SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed")
ADD_LIBRARY(${CORE-LIB} SHARED ${CORE-SRCS})
-TARGET_LINK_LIBRARIES(${CORE-LIB} ${core_pkgs_LDFLAGS} ${STORAGE-LIB} ${NETWORK-LIB} ${DEVICE-LIB})
+TARGET_LINK_LIBRARIES(${CORE-LIB} ${core_pkgs_LDFLAGS} ${STORAGE-LIB} ${NETWORK-LIB} ${DEVICE-LIB} ${CONTAINER-LIB})
SET_TARGET_PROPERTIES(${CORE-LIB} PROPERTIES SOVERSION ${VERSION_MAJOR})
SET_TARGET_PROPERTIES(${CORE-LIB} PROPERTIES VERSION ${VERSION})
diff --git a/email-core/email-core-account.c b/email-core/email-core-account.c
index 27c4d2b..0a42f25 100755
--- a/email-core/email-core-account.c
+++ b/email-core/email-core-account.c
@@ -53,6 +53,7 @@
#include "email-core-mailbox.h"
#include "email-core-signal.h"
#include "email-core-imap-mailbox.h"
+#include "email-core-container.h"
#include "imap4r1.h"
@@ -89,57 +90,86 @@ email_mailbox_type_e g_default_mbox_type[MAILBOX_COUNT] =
EMAIL_MAILBOX_TYPE_SPAMBOX,
};
-static email_account_list_t *g_account_list = NULL;
-static int g_account_num = 0;
-static pthread_mutex_t _account_ref_lock = PTHREAD_MUTEX_INITIALIZER;
-
-INTERNAL_FUNC email_account_t* emcore_get_account_reference(int account_id)
+INTERNAL_FUNC email_account_t* emcore_get_account_reference(char *multi_user_name, int account_id, int with_password)
{
EM_DEBUG_FUNC_BEGIN("account_id[%d]", account_id);
- email_account_list_t **p;
- email_account_t *result_account = NULL;
-
- if (account_id < 0){
- emcore_get_account_from_unvalidated_account_list(account_id, &result_account);
- return result_account;
- }
- else if (account_id > 0) {
- ENTER_CRITICAL_SECTION(_account_ref_lock);
- p = &g_account_list;
- while (*p) {
- if ((*p)->account->account_id == account_id) {
- emcore_duplicate_account((*p)->account, &result_account, NULL);
- break;
+ int err = EMAIL_ERROR_NONE;
+ email_account_t *result_account = NULL;
+ emstorage_account_tbl_t *p_result_account = NULL;
+
+ if (account_id < 0){
+ emcore_get_account_from_unvalidated_account_list(account_id, &result_account);
+ return result_account;
+ } else if (account_id > 0) {
+ if (with_password) {
+ if (!emstorage_get_account_by_id(multi_user_name, account_id, EMAIL_ACC_GET_OPT_FULL_DATA, &p_result_account, false, &err)) {
+ EM_DEBUG_EXCEPTION("emstorage_get_account_by_id failed : [%d]", err);
+ return NULL;
+ }
+ } else {
+ if (!emstorage_get_account_by_id(multi_user_name, account_id, GET_FULL_DATA_WITHOUT_PASSWORD, &p_result_account, false, &err)) {
+ EM_DEBUG_EXCEPTION("emstorage_get_account_by_id failed : [%d]", err);
+ return NULL;
+ }
}
- p = &(*p)->next;
- }
- LEAVE_CRITICAL_SECTION(_account_ref_lock);
-
- if (result_account)
- goto FINISH_OFF;
- /* refresh and check once again */
- EM_DEBUG_LOG ("init_account_id [%d]", account_id);
- emcore_init_account_reference();
- ENTER_CRITICAL_SECTION(_account_ref_lock);
- if (g_account_num > 0 && g_account_list) {
- p = &g_account_list;
- while (*p) {
- if ((*p)->account->account_id == account_id) {
- emcore_duplicate_account((*p)->account, &result_account, NULL);
- break;
- }
- p = &(*p)->next;
+ result_account = (email_account_t *)em_malloc(sizeof(email_account_t));
+ if (result_account == NULL) {
+ EM_DEBUG_EXCEPTION("em_malloc failed");
+ return NULL;
}
- }
- LEAVE_CRITICAL_SECTION(_account_ref_lock);
- }
-FINISH_OFF:
+ em_convert_account_tbl_to_account(p_result_account, result_account);
+
+ emstorage_free_account(&p_result_account, 1, NULL);
+ }
+
EM_DEBUG_FUNC_END("[%p]", result_account);
return result_account;
}
+INTERNAL_FUNC int emcore_get_account_reference_list(char *multi_user_name, email_account_t **output_account_list, int *output_count)
+{
+ EM_DEBUG_FUNC_BEGIN("account_list[%p], count[%p]", output_account_list, output_count);
+ int err = EMAIL_ERROR_NONE;
+ int i = 0;
+ int account_count = 0;
+ email_account_t *account_list = NULL;
+ emstorage_account_tbl_t *account_list_tbl = NULL;
+
+ if (!emstorage_get_account_list(multi_user_name, &account_count, &account_list_tbl, false, true, &err)) {
+ EM_DEBUG_EXCEPTION("emstorage_get_account_list failed : [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ if (account_count > 0) {
+ account_list = em_malloc(sizeof(email_account_t) * (account_count));
+ if (account_list == NULL) {
+ EM_DEBUG_EXCEPTION("em_malloc failed");
+ err = EMAIL_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+ }
+
+ for (i = 0; i < account_count; i++) {
+ em_convert_account_tbl_to_account(&account_list_tbl[i], &account_list[i]);
+ }
+
+FINISH_OFF:
+
+ if (account_list_tbl)
+ emstorage_free_account(&account_list_tbl, account_count, NULL);
+
+ if (output_account_list)
+ *output_account_list = account_list;
+
+ if (output_count)
+ *output_count = account_count;
+
+ EM_DEBUG_FUNC_END();
+ return err;
+}
+
static char *emcore_get_imap_capability_string(MAILSTREAM *input_stream)
{
EM_DEBUG_FUNC_BEGIN_SEC("input_stream[%p]", input_stream);
@@ -165,7 +195,7 @@ static char *emcore_get_imap_capability_string(MAILSTREAM *input_stream)
return result_string;
}
-INTERNAL_FUNC int emcore_validate_account_with_account_info(email_account_t *account, email_event_type_t event_type, char **output_server_capability_string, int event_handle, int *err_code)
+INTERNAL_FUNC int emcore_validate_account_with_account_info(char *multi_user_name, email_account_t *account, email_event_type_t event_type, char **output_server_capability_string, int event_handle, int *err_code)
{
EM_DEBUG_FUNC_BEGIN_SEC("account[%p] output_server_capability_string[%p] err_code[%p] incoming_server_address [%s]", account, output_server_capability_string, err_code, account->incoming_server_address);
@@ -199,7 +229,7 @@ INTERNAL_FUNC int emcore_validate_account_with_account_info(email_account_t *acc
FINISH_OFF_IF_EVENT_CANCELED (err, event_handle);
- if (!emcore_connect_to_remote_mailbox_with_account_info(account, 0, (void **)&tmp_stream, &err) || !tmp_stream) {
+ if (!emcore_connect_to_remote_mailbox_with_account_info(multi_user_name, account, 0, (void **)&tmp_stream, &err) || !tmp_stream) {
EM_DEBUG_LOG("emcore_connect_to_remote_mailbox failed [%d]", err);
if (EMAIL_ERROR_AUTHENTICATE == err || EMAIL_ERROR_LOGIN_FAILURE == err) { /* wrong password or etc */
EM_DEBUG_EXCEPTION("emcore_connect_to_remote_mailbox failed : Login or Authentication failed - %d", err);
@@ -218,7 +248,7 @@ INTERNAL_FUNC int emcore_validate_account_with_account_info(email_account_t *acc
FINISH_OFF_IF_EVENT_CANCELED (err, event_handle);
- if (!emcore_connect_to_remote_mailbox_with_account_info(account, EMAIL_CONNECT_FOR_SENDING, (void **)&stream, &err) || !stream) {
+ if (!emcore_connect_to_remote_mailbox_with_account_info(multi_user_name, account, EMAIL_CONNECT_FOR_SENDING, (void **)&stream, &err) || !stream) {
EM_DEBUG_EXCEPTION("emcore_connect_to_remote_mailbox failed [%d]", err);
err = EMAIL_ERROR_VALIDATE_ACCOUNT_OF_SMTP;
goto FINISH_OFF;
@@ -230,7 +260,7 @@ INTERNAL_FUNC int emcore_validate_account_with_account_info(email_account_t *acc
EM_DEBUG_LOG("Retry with TLS");
account->outgoing_server_secure_connection = 0x02; /* 0x02 == TLS */
- if (!emcore_connect_to_remote_mailbox_with_account_info(account, EMAIL_CONNECT_FOR_SENDING, (void **)&stream, &err) || !stream) {
+ if (!emcore_connect_to_remote_mailbox_with_account_info(multi_user_name, account, EMAIL_CONNECT_FOR_SENDING, (void **)&stream, &err) || !stream) {
EM_DEBUG_LOG("emcore_connect_to_remote_mailbox failed [%d]", err);
err = EMAIL_ERROR_VALIDATE_ACCOUNT_OF_SMTP;
account->outgoing_server_secure_connection = 0x01; /* restore to the previous value */
@@ -258,7 +288,7 @@ INTERNAL_FUNC int emcore_validate_account_with_account_info(email_account_t *acc
if (!emcore_check_event_thread_status(&dummy, event_handle)) {
EM_DEBUG_LOG ("canceled event: [%d]", dummy);
if (event_type == EMAIL_EVENT_VALIDATE_AND_CREATE_ACCOUNT || event_type == EMAIL_EVENT_VALIDATE_ACCOUNT_EX) {
- if (!emcore_delete_account(account->account_id, false, NULL))
+ if (!emcore_delete_account(multi_user_name, account->account_id, false, NULL))
EM_DEBUG_EXCEPTION("emdaemon_delete_account failed [%d]", account->account_id);
}
err = EMAIL_ERROR_CANCELLED;
@@ -303,7 +333,7 @@ FINISH_OFF:
}
-INTERNAL_FUNC int emcore_validate_account(int account_id, int handle, int *err_code)
+INTERNAL_FUNC int emcore_validate_account(char *multi_user_name, int account_id, int handle, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("account_id[%d], err_code[%p]", account_id, err_code);
@@ -317,9 +347,9 @@ INTERNAL_FUNC int emcore_validate_account(int account_id, int handle, int *err_c
goto FINISH_OFF;
}
- ref_account = emcore_get_account_reference(account_id);
+ ref_account = emcore_get_account_reference(multi_user_name, account_id, false);
- if (ref_account && emcore_validate_account_with_account_info(ref_account, EMAIL_EVENT_VALIDATE_ACCOUNT, NULL, handle, &err) == false) {
+ if (ref_account && emcore_validate_account_with_account_info(multi_user_name, ref_account, EMAIL_EVENT_VALIDATE_ACCOUNT, NULL, handle, &err) == false) {
EM_DEBUG_EXCEPTION("emcore_validate_account_with_account_info failed (%d)", err);
goto FINISH_OFF;
}
@@ -343,7 +373,7 @@ FINISH_OFF:
key_t del_account_key = 4511; /* name of the segment d/4 e/5 l/11 */
-INTERNAL_FUNC int emcore_delete_account(int account_id, int input_delete_from_account_svc, int *err_code)
+INTERNAL_FUNC int emcore_delete_account(char *multi_user_name, int account_id, int input_delete_from_account_svc, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("account_id[%d], err_code[%p]", account_id, err_code);
@@ -380,11 +410,10 @@ INTERNAL_FUNC int emcore_delete_account(int account_id, int input_delete_from_ac
#ifdef __FEATURE_LOCAL_ACTIVITY__
/* Delete all local activities of previous account */
-
-
emstorage_activity_tbl_t activity;
memset(&activity, 0x00, sizeof(emstorage_activity_tbl_t));
activity.account_id = account_id;
+ activity.multi_user_name = EM_SAFE_STRDUP(multi_user_name);
if (!emcore_delete_activity(&activity, &err)) {
EM_DEBUG_LOG("\t emcore_delete_activity failed - %d", err);
@@ -397,7 +426,7 @@ INTERNAL_FUNC int emcore_delete_account(int account_id, int input_delete_from_ac
if (false == emcore_clear_partial_body_thd_event_que(&err))
EM_DEBUG_EXCEPTION(" emcore_clear_partial_body_thd_event_que [%d]", err);
- if (false == emstorage_delete_full_pbd_activity_data(account_id, true, &err))
+ if (false == emstorage_delete_full_pbd_activity_data(multi_user_name, account_id, true, &err))
EM_DEBUG_EXCEPTION("emstorage_delete_full_pbd_activity_data failed [%d]", err);
#endif
@@ -406,23 +435,35 @@ INTERNAL_FUNC int emcore_delete_account(int account_id, int input_delete_from_ac
if (!emcore_clear_auto_download_queue())
EM_DEBUG_EXCEPTION("emcore_clear_auto_download_queue failed");
- if (!emstorage_delete_all_auto_download_activity(account_id, true, &err))
+ if (!emstorage_delete_all_auto_download_activity(multi_user_name, account_id, true, &err))
EM_DEBUG_EXCEPTION("emstorage_delete_all_auto_download_activity failed [%d]", err);
#endif
if (input_delete_from_account_svc == true) {
- int error_code_from_account_svc;
+ int error_code_from_account_svc = 0;
email_account_t *account_to_be_deleted;
+ void *join_zone = NULL;
- account_to_be_deleted = emcore_get_account_reference(account_id);
+ account_to_be_deleted = emcore_get_account_reference(multi_user_name, account_id, false);
if (account_to_be_deleted && account_to_be_deleted->incoming_server_type != EMAIL_SERVER_TYPE_ACTIVE_SYNC) {
EM_DEBUG_LOG("Calling account_svc_delete with account_svc_id[%d]", account_to_be_deleted->account_svc_id);
+ if (EM_SAFE_STRLEN(multi_user_name) > 0) {
+ if ((err = emcore_set_join_zone(multi_user_name, &join_zone)) != EMAIL_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("emcore_set_join_zone failed : [%d]", err);
+ goto FINISH_OFF;
+ }
+ }
+
error_code_from_account_svc = account_connect();
+
EM_DEBUG_LOG("account_connect returns [%d]", error_code_from_account_svc);
error_code_from_account_svc = account_delete_from_db_by_id(account_to_be_deleted->account_svc_id);
EM_DEBUG_LOG("account_delete_from_db_by_id returns [%d]", error_code_from_account_svc);
error_code_from_account_svc = account_disconnect();
EM_DEBUG_LOG("account_disconnect returns [%d]", error_code_from_account_svc);
+
+ if (join_zone)
+ emcore_unset_join_zone(join_zone);
}
if (account_to_be_deleted) {
@@ -431,7 +472,7 @@ INTERNAL_FUNC int emcore_delete_account(int account_id, int input_delete_from_ac
}
}
- if (emcore_cancel_all_threads_of_an_account(account_id) < EMAIL_ERROR_NONE) {
+ if (emcore_cancel_all_threads_of_an_account(multi_user_name, account_id) < EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("There are some remaining jobs. I couldn't stop them.");
err = EMAIL_ERROR_CANNOT_STOP_THREAD;
before_tr_begin = 1;
@@ -439,18 +480,18 @@ INTERNAL_FUNC int emcore_delete_account(int account_id, int input_delete_from_ac
}
/* Delete contact log */
- if ( ((err = emcore_delete_contacts_log(account_id)) != EMAIL_ERROR_NONE) && (err != EMAIL_ERROR_DATA_NOT_FOUND) ) {
- EM_DEBUG_EXCEPTION("emcore_delete_contacts_log failed : [%d]", err);
+ if (((err = emcore_delete_contacts_log(multi_user_name, account_id)) != EMAIL_ERROR_NONE) && (err != EMAIL_ERROR_DATA_NOT_FOUND)) {
+ EM_DEBUG_EXCEPTION("emcore_delete_contacts_log failed : [%d]", err);
}
/* BEGIN TRANSACTION; */
- if (!emstorage_begin_transaction(NULL, NULL, &err)) {
+ if (!emstorage_begin_transaction(multi_user_name, NULL, NULL, &err)) {
EM_DEBUG_EXCEPTION("emstorage_begin_transaction failed [%d]", err);
before_tr_begin = 1;
goto FINISH_OFF;
}
- if (!emstorage_delete_account(account_id, false, &err)) {
+ if (!emstorage_delete_account(multi_user_name, account_id, false, &err)) {
if(err != EMAIL_ERROR_SYSTEM_FAILURE) {
EM_DEBUG_EXCEPTION("emstorage_delete_account failed [%d]", err);
goto FINISH_OFF;
@@ -461,14 +502,14 @@ INTERNAL_FUNC int emcore_delete_account(int account_id, int input_delete_from_ac
/* emcore_reset_streams(); */
emcore_remove_connection_info(account_id);
#endif
-
- if ((err = emcore_delete_all_mails_of_acount(account_id)) != EMAIL_ERROR_NONE) {
+
+ if ((err = emcore_delete_all_mails_of_acount(multi_user_name, account_id)) != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("emcore_delete_all_mails_of_acount failed [%d]", err);
goto FINISH_OFF;
}
/* delete all mailboxes */
- if (!emstorage_delete_mailbox(account_id, -1, 0, false, &err)) {
+ if (!emstorage_delete_mailbox(multi_user_name, account_id, -1, 0, false, &err)) {
if(err != EMAIL_ERROR_MAILBOX_NOT_FOUND) {
EM_DEBUG_EXCEPTION("emstorage_delete_mailbox failed - %d", err);
goto FINISH_OFF;
@@ -476,19 +517,19 @@ INTERNAL_FUNC int emcore_delete_account(int account_id, int input_delete_from_ac
}
/* delete local imap sync mailbox from imap mailbox table */
- if (!emstorage_remove_downloaded_mail(account_id, NULL, NULL, false, &err)) {
+ if (!emstorage_remove_downloaded_mail(multi_user_name, account_id, NULL, NULL, false, &err)) {
EM_DEBUG_EXCEPTION("emstorage_remove_downloaded_mail failed - %d", err);
goto FINISH_OFF;
}
- emcore_display_unread_in_badge(NULL);
- emcore_delete_notification_by_account(account_id, true);
+ emcore_display_unread_in_badge(multi_user_name);
+ emcore_delete_notification_by_account(multi_user_name, account_id, true);
ret = true;
FINISH_OFF:
if (ret == true) { /* COMMIT TRANSACTION; */
- if (emstorage_commit_transaction(NULL, NULL, NULL) == false) {
+ if (emstorage_commit_transaction(multi_user_name, NULL, NULL, NULL) == false) {
err = EMAIL_ERROR_DB_FAILURE;
ret = false;
}
@@ -497,14 +538,12 @@ FINISH_OFF:
}
else { /* ROLLBACK TRANSACTION; */
- if (!before_tr_begin && emstorage_rollback_transaction(NULL, NULL, NULL) == false)
+ if (!before_tr_begin && emstorage_rollback_transaction(multi_user_name, NULL, NULL, NULL) == false)
err = EMAIL_ERROR_DB_FAILURE;
if (!emcore_notify_storage_event (NOTI_ACCOUNT_DELETE_FAIL, account_id, err, NULL, 0))
EM_DEBUG_EXCEPTION (" emcore_notify_storage_event[ NOTI_ACCOUNT_DELETE] : Notification Failed >>> ");
}
- emcore_init_account_reference();
-
if (err_code)
*err_code = err;
@@ -518,7 +557,7 @@ FINISH_OFF:
return ret;
}
-INTERNAL_FUNC int emcore_create_account(email_account_t *account, int add_account_to_account_svc, int *err_code)
+INTERNAL_FUNC int emcore_create_account(char *multi_user_name, email_account_t *account, int add_account_to_account_svc, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("account[%p] add_account_to_account_svc [%d] err_code[%p]", account, add_account_to_account_svc, err_code);
@@ -536,7 +575,7 @@ INTERNAL_FUNC int emcore_create_account(email_account_t *account, int add_accoun
goto FINISH_OFF;
}
- if (!emstorage_get_account_count(&count, true, &err)) {
+ if (!emstorage_get_account_count(multi_user_name, &count, true, &err)) {
EM_DEBUG_EXCEPTION("emstorage_get_account_count failed - %d", err);
goto FINISH_OFF;
}
@@ -573,12 +612,22 @@ INTERNAL_FUNC int emcore_create_account(email_account_t *account, int add_accoun
if (add_account_to_account_svc) {
if (account->incoming_server_type != EMAIL_SERVER_TYPE_ACTIVE_SYNC) {
int account_svc_id = 0;
- int error_code;
+ int error_code = 0;
account_h account_handle = NULL;
+ void *join_zone = NULL;
+
+ if (EM_SAFE_STRLEN(multi_user_name) > 0) {
+ err = emcore_set_join_zone(multi_user_name, &join_zone);
+ if (err != EMAIL_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("emcore_set_join_zone failed : [%d]", err);
+ goto FINISH_OFF;
+ }
+ }
error_code = account_connect();
if(error_code != ACCOUNT_ERROR_NONE) {
- EM_DEBUG_EXCEPTION("account_connect failed [%d]", error_code);
+ if (join_zone) emcore_unset_join_zone(join_zone);
+ EM_DEBUG_EXCEPTION("account_connect_to_container failed [%d]", error_code);
err = error_code;
goto FINISH_OFF;
}
@@ -588,6 +637,7 @@ INTERNAL_FUNC int emcore_create_account(email_account_t *account, int add_accoun
EM_DEBUG_EXCEPTION("account_create failed [%d]", error_code);
err = error_code;
account_disconnect();
+ if (join_zone) emcore_unset_join_zone(join_zone);
goto FINISH_OFF;
}
@@ -647,6 +697,7 @@ INTERNAL_FUNC int emcore_create_account(email_account_t *account, int add_accoun
account_destroy(account_handle);
account_disconnect();
+ if (join_zone) emcore_unset_join_zone(join_zone);
}
}
@@ -658,7 +709,7 @@ INTERNAL_FUNC int emcore_create_account(email_account_t *account, int add_accoun
em_convert_account_to_account_tbl(account, temp_account_tbl);
- if (!emstorage_add_account(temp_account_tbl, true, &err)) {
+ if (!emstorage_add_account(multi_user_name, temp_account_tbl, true, &err)) {
EM_DEBUG_EXCEPTION("emstorage_add_account failed - %d", err);
goto FINISH_OFF;
}
@@ -672,7 +723,7 @@ INTERNAL_FUNC int emcore_create_account(email_account_t *account, int add_accoun
local_mailbox.account_id = temp_account_tbl->account_id;
local_mailbox.mailbox_name = EM_SAFE_STRDUP(g_default_mbox_name[i]);
local_mailbox.alias = EM_SAFE_STRDUP(g_default_mbox_alias[i]);
- local_mailbox.mailbox_type = g_default_mbox_type[i];
+ local_mailbox.mailbox_type = g_default_mbox_type[i];
local_mailbox.mail_slot_size = temp_account_tbl->default_mail_slot_size;
local_mailbox.eas_data = NULL;
local_mailbox.eas_data_length = 0;
@@ -682,7 +733,7 @@ INTERNAL_FUNC int emcore_create_account(email_account_t *account, int add_accoun
else
local_mailbox.local = EMAIL_MAILBOX_FROM_LOCAL;
- if (!emcore_create_mailbox(&local_mailbox, 0, account->incoming_server_type, account->default_mail_slot_size, &err)) {
+ if (!emcore_create_mailbox(multi_user_name, &local_mailbox, 0, account->incoming_server_type, account->default_mail_slot_size, &err)) {
EM_DEBUG_EXCEPTION("emcore_create failed [%d]", err);
emcore_free_mailbox(&local_mailbox);
goto FINISH_OFF;
@@ -709,7 +760,7 @@ FINISH_OFF:
emstorage_free_account(&temp_account_tbl, 1, NULL);
if (ret == false && account != NULL) {
- if (!emcore_delete_account(account->account_id, false, NULL))
+ if (!emcore_delete_account(multi_user_name, account->account_id, false, NULL))
EM_DEBUG_EXCEPTION("emdaemon_delete_account Failed [%d]", account->account_id);
}
@@ -720,179 +771,6 @@ FINISH_OFF:
return ret;
}
-
-INTERNAL_FUNC int emcore_init_account_reference()
-{
-// static int num_call = 0;
-// EM_DEBUG_LOG("num_call [%d]", num_call++);
-
- int err = EMAIL_ERROR_NONE;
-
- email_account_list_t *account_list = NULL;
- email_account_list_t **p = NULL;
- email_account_t *account = NULL;
- emstorage_account_tbl_t *account_tbl_array = NULL;
- int count = 0;
- int i = 0;
-
- /* free account reference if any */
- emcore_free_account_reference();
-
- if (!emstorage_get_account_list(&count, &account_tbl_array, true, true, &err)) {
- EM_DEBUG_EXCEPTION("emstorage_get_account_list failed [%d]", err);
- goto FINISH_OFF;
- }
-
- for (p = &account_list, i = 0; i < count; i++) {
- account = em_malloc(sizeof(email_account_t));
- if (!account) {
- EM_DEBUG_EXCEPTION("malloc failed...");
- err = EMAIL_ERROR_OUT_OF_MEMORY;
- goto FINISH_OFF;
- }
-
- em_convert_account_tbl_to_account(account_tbl_array + i, account);
-
- *p = (email_account_list_t*) em_malloc(sizeof(email_account_list_t));
- if (!(*p)) {
- EM_DEBUG_EXCEPTION("malloc failed...");
- emcore_free_account(account);
- EM_SAFE_FREE(account);
- err = EMAIL_ERROR_OUT_OF_MEMORY;
- goto FINISH_OFF;
- }
-
- (*p)->account = account;
-
- p = &(*p)->next;
- }
-
- ENTER_CRITICAL_SECTION(_account_ref_lock);
- g_account_num = count;
- g_account_list = account_list;
- LEAVE_CRITICAL_SECTION(_account_ref_lock);
-
-FINISH_OFF:
- if (account_tbl_array)
- emstorage_free_account(&account_tbl_array, count, NULL);
-
- EM_DEBUG_FUNC_END("err [%d]", err);
- return err;
-}
-
-INTERNAL_FUNC int emcore_add_account_reference(email_account_t *account)
-{
- EM_DEBUG_FUNC_BEGIN();
-
- email_account_list_t *account_iter = NULL;
- email_account_list_t **p = NULL;
- email_account_t *dup_account = NULL;
- int account_count = 0;
-
- if (account == NULL) {
- EM_DEBUG_EXCEPTION("account [%p]", account);
- return false;
- }
-
- emcore_duplicate_account(account, &dup_account, NULL);
-
- if (dup_account == NULL) {
- EM_DEBUG_EXCEPTION("dup_account [%p]", dup_account);
- return false;
- }
-
- ENTER_CRITICAL_SECTION(_account_ref_lock);
- account_iter = g_account_list;
-
- p = &g_account_list;
- while (*p) {
- if ((*p)->account->account_id == account->account_id) {
- EM_DEBUG_LOG("already added to g_account_list");
- emcore_free_account(dup_account);
- EM_SAFE_FREE(dup_account);
- LEAVE_CRITICAL_SECTION(_account_ref_lock);
- return false;
- }
- p = &(*p)->next;
- }
-
- if (account_iter == NULL) {
- email_account_list_t *new_item = (email_account_list_t*) em_malloc(sizeof(email_account_list_t));
- if (!new_item) {
- EM_DEBUG_EXCEPTION("malloc failed...");
- emcore_free_account(dup_account);
- EM_SAFE_FREE(dup_account);
- LEAVE_CRITICAL_SECTION(_account_ref_lock);
- return false;
- }
-
- new_item->account = dup_account;
- new_item->next = NULL;
-
- g_account_list = new_item;
- EM_DEBUG_LOG("added 1 th item to g_account_list");
- LEAVE_CRITICAL_SECTION(_account_ref_lock);
- return true;
- }
-
- while(account_iter) {
- if (account_iter->account)
- account_count++;
-
- EM_DEBUG_LOG_DEV("account count[%d]", account_count);
-
- if (account_iter->next == NULL) {
- email_account_list_t *new_item = (email_account_list_t*) em_malloc(sizeof(email_account_list_t));
- if (!new_item) {
- EM_DEBUG_EXCEPTION("malloc failed...");
- emcore_free_account(dup_account);
- EM_SAFE_FREE(dup_account);
- LEAVE_CRITICAL_SECTION(_account_ref_lock);
- return false;
- }
-
- new_item->account = dup_account;
- new_item->next = NULL;
-
- account_iter->next = new_item;
- EM_DEBUG_LOG("added %d th item to g_account_list", account_count+1);
- break;
- }
- else {
- account_iter = account_iter->next;
- }
- }
-
- LEAVE_CRITICAL_SECTION(_account_ref_lock);
-
- EM_DEBUG_FUNC_END();
- return true;
-}
-
-INTERNAL_FUNC int emcore_free_account_reference()
-{
- EM_DEBUG_FUNC_BEGIN();
- ENTER_CRITICAL_SECTION(_account_ref_lock);
-
- email_account_list_t *p = g_account_list;
- email_account_list_t *p_next = NULL;
- while (p) {
- emcore_free_account(p->account);
- EM_SAFE_FREE(p->account);
-
- p_next = p->next;
- EM_SAFE_FREE(p);
- p = p_next;
- }
-
- g_account_num = 0;
- g_account_list = NULL;
-
- LEAVE_CRITICAL_SECTION(_account_ref_lock);
- EM_DEBUG_FUNC_END();
- return true;
-}
-
INTERNAL_FUNC int emcore_free_account_list(email_account_t **account_list, int count, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("account_list[%p], count[%d], err_code[%p]", account_list, count, err_code);
@@ -1003,67 +881,6 @@ INTERNAL_FUNC void emcore_duplicate_account(const email_account_t *account, emai
EM_DEBUG_FUNC_END();
}
-INTERNAL_FUNC int emcore_get_account_reference_list(email_account_t **account_list, int *count, int *err_code)
-{
- EM_DEBUG_FUNC_BEGIN("account_list[%p], count[%p], err_code[%p]", account_list, count, err_code);
- int i, countOfAccounts = 0;
- int ret = false;
- int err = EMAIL_ERROR_NONE;
- email_account_t *accountRef;
- email_account_list_t *p;
-
- ENTER_CRITICAL_SECTION(_account_ref_lock);
-
- if (!account_list || !count) {
- EM_DEBUG_EXCEPTION("account_list[%p], count[%p]", account_list, count);
- err = EMAIL_ERROR_INVALID_PARAM;
- goto FINISH_OFF;
- }
-
- p = g_account_list;
-
- while (p) {
- countOfAccounts++;
- p = p->next;
- }
-
- EM_DEBUG_LOG("Result count[%d]", countOfAccounts);
- *count = countOfAccounts;
-
- if (countOfAccounts > 0) {
- *account_list = em_malloc(sizeof(email_account_t) * countOfAccounts);
- if (!*account_list) {
- EM_DEBUG_LOG("malloc failed...");
- err = EMAIL_ERROR_OUT_OF_MEMORY;
- goto FINISH_OFF;
- }
- }
-
- p = g_account_list;
- for (i = 0; i < countOfAccounts; i++) {
- accountRef = (*account_list) + i;
- emcore_free_account(accountRef);
- emcore_duplicate_account_members(p->account, accountRef);
- EM_DEBUG_LOG_SEC("Result account id[%d], name[%s]", accountRef->account_id, accountRef->account_name);
- p = p->next;
- }
-
- ret = true;
-
-FINISH_OFF:
- if (ret == false) {
- if (account_list && *account_list)
- EM_SAFE_FREE(*account_list);
- }
-
- LEAVE_CRITICAL_SECTION(_account_ref_lock);
-
- if (err_code != NULL)
- *err_code = err;
- EM_DEBUG_FUNC_END();
- return ret;
-}
-
#ifdef __FEATURE_BACKUP_ACCOUNT__
#include <ss_manager.h>
@@ -1152,7 +969,7 @@ FINISH_OFF:
return ret_code;
}
-INTERNAL_FUNC int emcore_backup_accounts(const char *file_path, int *error_code)
+INTERNAL_FUNC int emcore_backup_accounts(char *multi_user_name, const char *file_path, int *error_code)
{
EM_DEBUG_FUNC_BEGIN_SEC("file_path [%s], error_code [%p]", file_path, error_code);
int local_error_code = EMAIL_ERROR_NONE, local_error_code_2 = EMAIL_ERROR_NONE, ret_code = false;
@@ -1170,7 +987,7 @@ INTERNAL_FUNC int emcore_backup_accounts(const char *file_path, int *error_code)
select_num = 1000;
- if (!emstorage_get_account_list(&select_num, &account_list, true, true, &local_error_code)) {
+ if (!emstorage_get_account_list(multi_user_name, &select_num, &account_list, true, true, &local_error_code)) {
EM_DEBUG_EXCEPTION("emstorage_get_account_list failed [%d]", local_error_code);
goto FINISH_OFF;
}
@@ -1215,6 +1032,7 @@ INTERNAL_FUNC int emcore_backup_accounts(const char *file_path, int *error_code)
int data_length = 0;
char *encrypted_data_block = NULL;
+ char errno_buf[ERRNO_BUF_SIZE] = {0};
local_error_code = em_open(file_path, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR, &fd);
if (local_error_code != EMAIL_ERROR_NONE) {
@@ -1230,7 +1048,7 @@ INTERNAL_FUNC int emcore_backup_accounts(const char *file_path, int *error_code)
}
if (write(fd, encrypted_data_block, data_length) != data_length) {
- EM_DEBUG_EXCEPTION("write failed : [%s]", strerror(errno));
+ EM_DEBUG_EXCEPTION("write failed : [%d][%s]", errno, EM_STRERROR(errno_buf));
local_error_code = EMAIL_ERROR_SYSTEM_FAILURE;
goto FINISH_OFF;
}
@@ -1252,7 +1070,7 @@ FINISH_OFF:
return ret_code;
}
-INTERNAL_FUNC int emcore_restore_accounts(const char *file_path)
+INTERNAL_FUNC int emcore_restore_accounts(char *multi_user_name, const char *file_path)
{
EM_DEBUG_FUNC_BEGIN_SEC("file_path [%s]", file_path);
int err = EMAIL_ERROR_NONE, buffer_length = 0, read_length = 0;
@@ -1272,10 +1090,10 @@ INTERNAL_FUNC int emcore_restore_accounts(const char *file_path)
goto FINISH_OFF;
}
- if (emcore_get_account_reference_list(&account_list, &account_count, &err)) {
+ if ((err = emcore_get_account_reference_list(multi_user_name, &account_list, &account_count)) == EMAIL_ERROR_NONE) {
for (i = 0; i < account_count; i++) {
if (account_list[i].incoming_server_type != EMAIL_SERVER_TYPE_ACTIVE_SYNC) {
- if (!emcore_delete_account(account_list[i].account_id, true, &err)) {
+ if (!emcore_delete_account(multi_user_name, account_list[i].account_id, true, &err)) {
EM_DEBUG_EXCEPTION("emcore_delete_account failed [%d]", err);
goto FINISH_OFF;
}
@@ -1347,7 +1165,7 @@ INTERNAL_FUNC int emcore_restore_accounts(const char *file_path)
em_convert_byte_stream_to_account(account_stream, account_stream_length, &temp_account);
EM_SAFE_FREE(account_stream);
- if ((emstorage_check_duplicated_account(&temp_account, true, &err) == false) && (err = EMAIL_ERROR_ALREADY_EXISTS)) {
+ if ((emstorage_check_duplicated_account(multi_user_name, &temp_account, true, &err) == false) && (err = EMAIL_ERROR_ALREADY_EXISTS)) {
EM_DEBUG_EXCEPTION("An account is duplicated. ");
buffer_ptr += account_stream_length;
account_stream_length = 0;
@@ -1356,13 +1174,12 @@ INTERNAL_FUNC int emcore_restore_accounts(const char *file_path)
continue;
}
- if (!emcore_create_account(&temp_account, true, &err)) {
+ if (!emcore_create_account(multi_user_name, &temp_account, true, &err)) {
EM_DEBUG_EXCEPTION("emcore_create_account() failed. [%d]", err);
goto FINISH_OFF;
}
emcore_free_account(&temp_account);
- emcore_init_account_reference();
}
buffer_ptr += account_stream_length;
account_stream_length = 0;
@@ -1392,7 +1209,6 @@ FINISH_OFF:
account_list = NULL;
}
emcore_free_account(&temp_account);
-
EM_SAFE_FREE(account_stream);
EM_SAFE_FREE(temp_buffer);
EM_SAFE_FREE(encrypt_buffer);
@@ -1403,7 +1219,7 @@ FINISH_OFF:
#endif /* __FEATURE_BACKUP_ACCOUNT_ */
-INTERNAL_FUNC int emcore_save_default_account_id(int input_account_id)
+INTERNAL_FUNC int emcore_save_default_account_id(char *multi_user_name, int input_account_id)
{
EM_DEBUG_FUNC_BEGIN("account_id [%d]", input_account_id);
int ret_code = EMAIL_ERROR_NONE, result_value = 0;
@@ -1418,7 +1234,7 @@ INTERNAL_FUNC int emcore_save_default_account_id(int input_account_id)
return ret_code;
}
-static int _recover_from_invalid_default_account_id(int *output_account_id)
+static int _recover_from_invalid_default_account_id(char *multi_user_name, int *output_account_id)
{
EM_DEBUG_FUNC_BEGIN("account_id [%p]", output_account_id);
int ret_code = EMAIL_ERROR_NONE;
@@ -1430,7 +1246,7 @@ static int _recover_from_invalid_default_account_id(int *output_account_id)
goto FINISH_OFF;
}
- if(!emstorage_get_account_list(&account_count, &result_account_list, false, false, &ret_code) || !result_account_list) {
+ if(!emstorage_get_account_list(multi_user_name, &account_count, &result_account_list, false, false, &ret_code) || !result_account_list) {
if (ret_code == EMAIL_ERROR_ACCOUNT_NOT_FOUND)
EM_DEBUG_LOG ("no account found");
else
@@ -1454,7 +1270,7 @@ FINISH_OFF:
return ret_code;
}
-INTERNAL_FUNC int emcore_load_default_account_id(int *output_account_id)
+INTERNAL_FUNC int emcore_load_default_account_id(char *multi_user_name, int *output_account_id)
{
EM_DEBUG_FUNC_BEGIN("account_id [%p]", output_account_id);
int ret_code = EMAIL_ERROR_NONE;
@@ -1475,7 +1291,7 @@ INTERNAL_FUNC int emcore_load_default_account_id(int *output_account_id)
}
if (*output_account_id != 0) {
- if (!emstorage_get_account_by_id(*output_account_id, EMAIL_ACC_GET_OPT_DEFAULT, &result_account, false, &ret_code)) {
+ if (!emstorage_get_account_by_id(multi_user_name, *output_account_id, EMAIL_ACC_GET_OPT_DEFAULT, &result_account, false, &ret_code)) {
if (ret_code == EMAIL_ERROR_ACCOUNT_NOT_FOUND) {
EM_DEBUG_LOG ("no account found account_id[%d]", *output_account_id);
*output_account_id = 0;
@@ -1488,7 +1304,7 @@ INTERNAL_FUNC int emcore_load_default_account_id(int *output_account_id)
}
if (*output_account_id == 0) {
- if ((ret_code = _recover_from_invalid_default_account_id (output_account_id)) != EMAIL_ERROR_NONE) {
+ if ((ret_code = _recover_from_invalid_default_account_id (multi_user_name, output_account_id)) != EMAIL_ERROR_NONE) {
if (ret_code == EMAIL_ERROR_ACCOUNT_NOT_FOUND)
EM_DEBUG_LOG ("no account found");
else
@@ -1505,7 +1321,7 @@ FINISH_OFF:
return ret_code;
}
-INTERNAL_FUNC int emcore_recover_from_secured_storage_failure()
+INTERNAL_FUNC int emcore_recover_from_secured_storage_failure(char *multi_user_name)
{
EM_DEBUG_FUNC_BEGIN();
int err = EMAIL_ERROR_NONE;
@@ -1514,15 +1330,15 @@ INTERNAL_FUNC int emcore_recover_from_secured_storage_failure()
emstorage_account_tbl_t *temp_account_tbl_list = NULL;
emstorage_account_tbl_t *temp_account_tbl = NULL;
- if (!emstorage_get_account_list(&account_count, &temp_account_tbl_list, true, false, &err)) {
+ if (!emstorage_get_account_list(multi_user_name, &account_count, &temp_account_tbl_list, true, false, &err)) {
EM_DEBUG_EXCEPTION("emstorage_get_account_list failed [%d]", err);
goto FINISH_OFF;
}
for (i = 0; i < account_count; i++) {
- if(!emstorage_get_account_by_id(temp_account_tbl_list[i].account_id, EMAIL_ACC_GET_OPT_DEFAULT | EMAIL_ACC_GET_OPT_PASSWORD, &temp_account_tbl, true, &err)) {
+ if(!emstorage_get_account_by_id(multi_user_name, temp_account_tbl_list[i].account_id, EMAIL_ACC_GET_OPT_DEFAULT | EMAIL_ACC_GET_OPT_PASSWORD, &temp_account_tbl, true, &err)) {
if(err == EMAIL_ERROR_SECURED_STORAGE_FAILURE) {
- if(!emcore_delete_account(temp_account_tbl_list[i].account_id, true, &err)) {
+ if(!emcore_delete_account(multi_user_name, temp_account_tbl_list[i].account_id, true, &err)) {
EM_DEBUG_EXCEPTION("emcore_delete_account failed [%d]", err);
goto FINISH_OFF;
}
@@ -1539,7 +1355,7 @@ FINISH_OFF:
return err;
}
-INTERNAL_FUNC int emcore_update_sync_status_of_account(int input_account_id, email_set_type_t input_set_operator, int input_sync_status)
+INTERNAL_FUNC int emcore_update_sync_status_of_account(char *multi_user_name, int input_account_id, email_set_type_t input_set_operator, int input_sync_status)
{
EM_DEBUG_FUNC_BEGIN("input_account_id [%d], input_set_operator [%d], input_sync_status [%d]", input_account_id, input_set_operator, input_sync_status);
int err = EMAIL_ERROR_NONE;
@@ -1547,12 +1363,22 @@ INTERNAL_FUNC int emcore_update_sync_status_of_account(int input_account_id, ema
#ifdef __FEATURE_USING_ACCOUNT_SVC_FOR_SYNC_STATUS__
int err_from_account_svc = 0;
emstorage_account_tbl_t *account_tbl_data = NULL;
+ void *join_zone = NULL;
+
if (input_account_id != ALL_ACCOUNT && (input_sync_status == SYNC_STATUS_SYNCING)) {
- if (!emstorage_get_account_by_id(input_account_id, EMAIL_ACC_GET_OPT_DEFAULT | EMAIL_ACC_GET_OPT_OPTIONS, &account_tbl_data, true, &err)) {
+ if (!emstorage_get_account_by_id(multi_user_name, input_account_id, EMAIL_ACC_GET_OPT_DEFAULT | EMAIL_ACC_GET_OPT_OPTIONS, &account_tbl_data, true, &err)) {
EM_DEBUG_EXCEPTION("emstorage_get_account_by_id failed [%d]", err);
goto FINISH_OFF;
}
+ if (EM_SAFE_STRLEN(multi_user_name) > 0) {
+ err = emcore_set_join_zone(multi_user_name, &join_zone);
+ if (err != EMAIL_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("emcore_set_join_zone failed : [%d]", err);
+ goto FINISH_OFF;
+ }
+ }
+
err_from_account_svc = account_connect();
EM_DEBUG_LOG_DEV("account_connect returns [%d]", err_from_account_svc);
@@ -1565,10 +1391,11 @@ INTERNAL_FUNC int emcore_update_sync_status_of_account(int input_account_id, ema
err_from_account_svc = account_disconnect();
EM_DEBUG_LOG_DEV("account_disconnect returns [%d]", err_from_account_svc);
+ if (join_zone) emcore_unset_join_zone(join_zone);
}
#endif /* __FEATURE_USING_ACCOUNT_SVC_FOR_SYNC_STATUS__ */
- if (!emstorage_update_sync_status_of_account(input_account_id, input_set_operator, input_sync_status, true, &err))
+ if (!emstorage_update_sync_status_of_account(multi_user_name, input_account_id, input_set_operator, input_sync_status, true, &err))
EM_DEBUG_EXCEPTION("emstorage_update_sync_status_of_account failed [%d]", err);
#ifdef __FEATURE_USING_ACCOUNT_SVC_FOR_SYNC_STATUS__
@@ -1733,7 +1560,7 @@ FINISH_OFF:
return err;
}
-INTERNAL_FUNC int emcore_refresh_xoauth2_access_token(int input_account_id)
+INTERNAL_FUNC int emcore_refresh_xoauth2_access_token(char *multi_user_name, int input_account_id)
{
EM_DEBUG_FUNC_BEGIN("input_account_id [%d]", input_account_id);
int err = EMAIL_ERROR_NONE;
@@ -1746,8 +1573,7 @@ INTERNAL_FUNC int emcore_refresh_xoauth2_access_token(int input_account_id)
email_account_t *ref_account = NULL;
- ref_account = emcore_get_account_reference(input_account_id);
-
+ ref_account = emcore_get_account_reference(multi_user_name, input_account_id, true);
if(ref_account == NULL) {
EM_DEBUG_EXCEPTION("emcore_get_account_reference() failed");
err = EMAIL_ERROR_INVALID_ACCOUNT;
@@ -1755,7 +1581,6 @@ INTERNAL_FUNC int emcore_refresh_xoauth2_access_token(int input_account_id)
}
access_token = EM_SAFE_STRDUP(strtok_r(ref_account->incoming_server_password, "\001", &saveptr));
-
if(access_token == NULL) {
EM_DEBUG_EXCEPTION("invalid token string.");
err = EMAIL_ERROR_XOAUTH_BAD_REQUEST;
@@ -1790,13 +1615,11 @@ INTERNAL_FUNC int emcore_refresh_xoauth2_access_token(int input_account_id)
SNPRINTF(new_password_string, new_password_string_length, "%s\001%s", new_access_token, refresh_token);
- if((err = emstorage_update_account_password(input_account_id, new_password_string, new_password_string)) != EMAIL_ERROR_NONE) {
+ if((err = emstorage_update_account_password(multi_user_name, input_account_id, new_password_string, new_password_string)) != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("emstorage_update_account_password() failed [%d]", err);
goto FINISH_OFF;
}
- emcore_init_account_reference();
-
FINISH_OFF:
EM_SAFE_FREE(access_token);
diff --git a/email-core/email-core-alarm.c b/email-core/email-core-alarm.c
index d1d75f3..0876dce 100755
--- a/email-core/email-core-alarm.c
+++ b/email-core/email-core-alarm.c
@@ -154,7 +154,7 @@ INTERNAL_FUNC int emcore_check_alarm_by_class_id(email_alarm_class_t input_class
return err;
}
-static int emcore_add_alarm_data_to_alarm_data_list(alarm_id_t input_alarm_id, email_alarm_class_t input_class_id, int input_reference_id, time_t input_trigger_at_time, int (*input_alarm_callback)(email_alarm_data_t*, void *), void *user_data)
+static int emcore_add_alarm_data_to_alarm_data_list(char *multi_user_name, alarm_id_t input_alarm_id, email_alarm_class_t input_class_id, int input_reference_id, time_t input_trigger_at_time, int (*input_alarm_callback)(email_alarm_data_t*, void *), void *user_data)
{
EM_DEBUG_FUNC_BEGIN("input_alarm_id [%d] input_class_id[%d] input_reference_id[%d] input_trigger_at_time[%d] input_alarm_callback [%p] user_data[%p]", input_alarm_id, input_class_id, input_reference_id, input_trigger_at_time, input_alarm_callback, user_data);
int err = EMAIL_ERROR_NONE;
@@ -173,12 +173,14 @@ static int emcore_add_alarm_data_to_alarm_data_list(alarm_id_t input_alarm_id, e
err = EMAIL_ERROR_OUT_OF_MEMORY;
goto FINISH_OFF;
}
+
alarm_data->alarm_id = input_alarm_id;
alarm_data->class_id = input_class_id;
alarm_data->reference_id = input_reference_id;
alarm_data->trigger_at_time = input_trigger_at_time;
alarm_data->alarm_callback = input_alarm_callback;
alarm_data->user_data = user_data;
+ alarm_data->multi_user_name = EM_SAFE_STRDUP(multi_user_name);
ENTER_CRITICAL_SECTION(alarm_data_lock);
alarm_data_list = g_list_append(alarm_data_list, (gpointer)alarm_data);
@@ -203,6 +205,7 @@ static int emcore_remove_alarm(email_alarm_data_t *input_alarm_data)
EM_DEBUG_EXCEPTION ("alarmmgr_remove_alarm failed [%d]", ret);
err = EMAIL_ERROR_SYSTEM_FAILURE;
}
+ EM_SAFE_FREE(input_alarm_data->multi_user_name);
LEAVE_CRITICAL_SECTION(alarm_data_lock);
EM_DEBUG_FUNC_END("err [%d]", err);
@@ -232,7 +235,9 @@ INTERNAL_FUNC int emcore_delete_alram_data_from_alarm_data_list(email_alarm_data
alarm_data_list = NULL;
}
LEAVE_CRITICAL_SECTION(alarm_data_lock);
+
FINISH_OFF:
+
EM_DEBUG_FUNC_END("err [%d]", err);
return err;
}
@@ -244,7 +249,7 @@ INTERNAL_FUNC int emcore_delete_alram_data_by_reference_id(email_alarm_class_t i
email_alarm_data_t *alarm_data = NULL;
if ((err = emcore_get_alarm_data_by_reference_id(input_class_id, input_reference_id, &alarm_data)) != EMAIL_ERROR_NONE) {
- EM_DEBUG_LOG ("emcore_remove_alarm return [%d]", err);
+ EM_DEBUG_LOG ("emcore_get_alarm_data_by_reference_id return [%d]", err);
goto FINISH_OFF;
}
@@ -257,7 +262,7 @@ FINISH_OFF:
return err;
}
-INTERNAL_FUNC int emcore_add_alarm(time_t input_trigger_at_time, email_alarm_class_t input_class_id, int input_reference_id, int (*input_alarm_callback)(email_alarm_data_t*, void *), void *input_user_data)
+INTERNAL_FUNC int emcore_add_alarm(char *multi_user_name, time_t input_trigger_at_time, email_alarm_class_t input_class_id, int input_reference_id, int (*input_alarm_callback)(email_alarm_data_t*, void *), void *input_user_data)
{
EM_DEBUG_FUNC_BEGIN("input_trigger_at_time[%d] input_class_id[%d] input_reference_id[%d] input_alarm_callback[%p] input_user_data[%p]", input_trigger_at_time, input_class_id, input_reference_id, input_alarm_callback, input_user_data);
@@ -279,7 +284,7 @@ INTERNAL_FUNC int emcore_add_alarm(time_t input_trigger_at_time, email_alarm_cla
goto FINISH_OFF;
}
- if((err = emcore_add_alarm_data_to_alarm_data_list(alarm_id, input_class_id, input_reference_id, input_trigger_at_time, input_alarm_callback, input_user_data)) != EMAIL_ERROR_NONE) {
+ if ((err = emcore_add_alarm_data_to_alarm_data_list(multi_user_name, alarm_id, input_class_id, input_reference_id, input_trigger_at_time, input_alarm_callback, input_user_data)) != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("emcore_add_alarm_data_to_alarm_data_list failed [%d]", err);
goto FINISH_OFF;
}
diff --git a/email-core/email-core-auto-download.c b/email-core/email-core-auto-download.c
index f5bdc5c..66f7a3e 100755
--- a/email-core/email-core-auto-download.c
+++ b/email-core/email-core-auto-download.c
@@ -346,7 +346,7 @@ static void* worker_auto_download_queue(void *arg)
email_event_auto_download *activity_list = NULL;
- if (!emstorage_open(&err)) {
+ if (!emstorage_open(NULL, &err)) {
EM_DEBUG_EXCEPTION("emstorage_open falied [%d]", err);
return false;
}
@@ -364,7 +364,7 @@ static void* worker_auto_download_queue(void *arg)
}
activity_count = 0;
- if (!emstorage_get_auto_download_activity_count(&activity_count, false, &err)) {
+ if (!emstorage_get_auto_download_activity_count(NULL, &activity_count, false, &err)) {
EM_DEBUG_LOG("emstorage_get_auto_download_activity_count failed [%d]", err);
goto CHECK_CONTINUE;
}
@@ -376,7 +376,7 @@ static void* worker_auto_download_queue(void *arg)
account_count = 0;
EM_SAFE_FREE(account_list);
- if (!emstorage_get_auto_download_account_list(&account_list, &account_count, false, &err)) {
+ if (!emstorage_get_auto_download_account_list(NULL, &account_list, &account_count, false, &err)) {
EM_DEBUG_EXCEPTION(" emstorage_get_auto_download_account_list failed.. [%d]", err);
goto CHECK_CONTINUE;
}
@@ -389,7 +389,7 @@ static void* worker_auto_download_queue(void *arg)
for (ai = 0; ai < account_count; ai++) {
email_account_t *account_ref = NULL;
- if (!(account_ref = emcore_get_account_reference(account_list[ai]))) {
+ if (!(account_ref = emcore_get_account_reference(NULL, account_list[ai], false))) {
EM_DEBUG_EXCEPTION("emcore_get_account_reference failed [%d]", account_list[ai]);
err = EMAIL_ERROR_INVALID_ACCOUNT;
continue;
@@ -411,7 +411,7 @@ static void* worker_auto_download_queue(void *arg)
mailbox_count = 0;
EM_SAFE_FREE(mailbox_list);
- if (!emstorage_get_auto_download_mailbox_list(account_list[ai], &mailbox_list, &mailbox_count, false, &err)) {
+ if (!emstorage_get_auto_download_mailbox_list(NULL, account_list[ai], &mailbox_list, &mailbox_count, false, &err)) {
EM_DEBUG_EXCEPTION(" emstorage_get_auto_download_mailbox_list failed.. [%d]", err);
goto CHECK_CONTINUE;
}
@@ -427,7 +427,7 @@ static void* worker_auto_download_queue(void *arg)
activity_list_count = 0;
EM_SAFE_FREE(activity_list);
- if ((err = emstorage_get_mailbox_by_id(mailbox_list[mi], &target_mailbox)) != EMAIL_ERROR_NONE) {
+ if ((err = emstorage_get_mailbox_by_id(NULL, mailbox_list[mi], &target_mailbox)) != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("emstorage_get_mailbox_by_id failed. [%d]", err);
}
@@ -440,7 +440,7 @@ static void* worker_auto_download_queue(void *arg)
emstorage_free_mailbox(&target_mailbox, 1, NULL);
}
- if (!emstorage_get_auto_download_activity(account_list[ai], mailbox_list[mi], &activity_list, &activity_list_count, false, &err)) {
+ if (!emstorage_get_auto_download_activity(NULL, account_list[ai], mailbox_list[mi], &activity_list, &activity_list_count, false, &err)) {
EM_DEBUG_EXCEPTION(" emstorage_get_auto_download_activity failed.. [%d]", err);
goto CHECK_CONTINUE;
}
@@ -524,7 +524,7 @@ CHECK_CONTINUE:
auto_download_thread_run = 1;
}
- if (!(account_ref = emcore_get_account_reference(event_data->account_id))) {
+ if (!(account_ref = emcore_get_account_reference(event_data->multi_user_name, event_data->account_id, false))) {
EM_DEBUG_EXCEPTION("emcore_get_account_reference failed [%d]", event_data->account_id);
err = EMAIL_ERROR_INVALID_ACCOUNT;
goto POP_HEAD;
@@ -540,7 +540,7 @@ CHECK_CONTINUE:
EM_SAFE_FREE(account_ref);
}
- if ((err = emstorage_get_mailbox_by_id(event_data->mailbox_id, &target_mailbox)) != EMAIL_ERROR_NONE) {
+ if ((err = emstorage_get_mailbox_by_id(event_data->multi_user_name, event_data->mailbox_id, &target_mailbox)) != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("emstorage_get_mailbox_by_id failed. [%d]", err);
}
@@ -568,7 +568,12 @@ CHECK_CONTINUE:
}
snprintf(uid_str, sizeof(uid_str), "%ld", event_data->server_mail_id);
- if (!emstorage_get_maildata_by_servermailid(event_data->mailbox_id, uid_str, &mail, true, &err) || !mail) {
+ if (!emstorage_get_maildata_by_servermailid(event_data->multi_user_name,
+ uid_str,
+ event_data->mailbox_id,
+ &mail,
+ true,
+ &err) || !mail) {
EM_DEBUG_EXCEPTION("emstorage_get_mail_data_by_servermailid failed : [%d]", err);
}
else {
@@ -580,7 +585,7 @@ CHECK_CONTINUE:
event_data->account_id, event_data->mailbox_id,
event_data->mail_id, event_data->server_mail_id, event_data->activity_id);
- if (!emcore_gmime_download_body_sections(NULL, event_data->account_id, event_data->mail_id,
+ if (!emcore_gmime_download_body_sections(event_data->multi_user_name, NULL, event_data->account_id, event_data->mail_id,
1, NO_LIMITATION, -1, 0, 1, &err))
EM_DEBUG_EXCEPTION("emcore_gmime_download_body_sections failed - %d", err);
}
@@ -591,7 +596,7 @@ CHECK_CONTINUE:
int attachment_count = 0;
emstorage_attachment_tbl_t *attachment_list = NULL;
- if ((err = emstorage_get_attachment_list(event_data->mail_id, true, &attachment_list, &attachment_count)) != EMAIL_ERROR_NONE ) {
+ if ((err = emstorage_get_attachment_list(event_data->multi_user_name, event_data->mail_id, true, &attachment_list, &attachment_count)) != EMAIL_ERROR_NONE ) {
EM_DEBUG_EXCEPTION("emstorage_get_attachment_list failed [%d]", err);
} else {
for (i = 0; i < attachment_count; i++) {
@@ -607,7 +612,7 @@ CHECK_CONTINUE:
j, event_data->account_id, event_data->mailbox_id,
event_data->mail_id, event_data->server_mail_id, event_data->activity_id);
- if (!emcore_gmime_download_attachment(event_data->mail_id, j, 0, -1, 1, &err))
+ if (!emcore_gmime_download_attachment(event_data->multi_user_name, event_data->mail_id, j, 0, -1, 1, &err))
EM_DEBUG_EXCEPTION("emcore_gmime_download_attachment failed [%d]", err);
}
@@ -621,7 +626,7 @@ CHECK_CONTINUE:
}
DELETE_ACTIVITY:
- if (!emcore_delete_auto_download_activity(event_data->account_id, event_data->mail_id, event_data->activity_id, &err)) {
+ if (!emcore_delete_auto_download_activity(event_data->multi_user_name, event_data->account_id, event_data->mail_id, event_data->activity_id, &err)) {
EM_DEBUG_EXCEPTION("emcore_delete_auto_download_activity failed [%d]", err);
}
@@ -635,6 +640,7 @@ POP_HEAD:
EM_DEBUG_EXCEPTION("Failed to g_queue_pop_head");
}
else {
+ EM_SAFE_FREE(started_event->multi_user_name);
EM_SAFE_FREE(started_event);
}
@@ -642,8 +648,6 @@ POP_HEAD:
emcore_free_account(account_ref);
EM_SAFE_FREE(account_ref);
}
-
- em_flush_memory();
}
}
@@ -657,7 +661,7 @@ POP_HEAD:
}
-INTERNAL_FUNC int emcore_insert_auto_download_job(int account_id, int mailbox_id, int mail_id, int auto_download_on, char *uid, int *err_code)
+INTERNAL_FUNC int emcore_insert_auto_download_job(char *multi_user_name, int account_id, int mailbox_id, int mail_id, int auto_download_on, char *uid, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("account_id [%d], maibox_id[%d], mail_id[%d], uid[%p]", account_id, mailbox_id, mail_id, uid);
@@ -685,6 +689,7 @@ INTERNAL_FUNC int emcore_insert_auto_download_job(int account_id, int mailbox_id
ad_event->mail_id = mail_id;
ad_event->server_mail_id = strtoul(uid, NULL, 0);
ad_event->mailbox_id = mailbox_id;
+ ad_event->multi_user_name = EM_SAFE_STRDUP(multi_user_name);
if (!emcore_insert_auto_download_activity(ad_event, &(ad_event->activity_id), &err)) {
EM_DEBUG_EXCEPTION("Inserting auto download activity failed with error[%d]", err);
@@ -711,8 +716,12 @@ INTERNAL_FUNC int emcore_insert_auto_download_job(int account_id, int mailbox_id
FINISH_OFF:
- if (!event_pushed)
- EM_SAFE_FREE(ad_event);
+ if (!event_pushed) {
+ if (ad_event) {
+ EM_SAFE_FREE(ad_event->multi_user_name);
+ free(ad_event);
+ }
+ }
EM_DEBUG_FUNC_END();
return ret;
@@ -734,13 +743,13 @@ INTERNAL_FUNC int emcore_insert_auto_download_activity(email_event_auto_download
int err = EMAIL_ERROR_NONE;
int before_tr_begin = 0;
- if (!emstorage_begin_transaction(NULL, NULL, &err)) {
+ if (!emstorage_begin_transaction(local_activity->multi_user_name, NULL, NULL, &err)) {
EM_DEBUG_EXCEPTION("emstorage_begin_transaction failed [%d]", err);
before_tr_begin = 1;
goto FINISH_OFF;
}
- if (!emstorage_add_auto_download_activity(local_activity, activity_id, false, &err)) {
+ if (!emstorage_add_auto_download_activity(local_activity->multi_user_name, local_activity, activity_id, false, &err)) {
EM_DEBUG_EXCEPTION("emstorage_add_auto_download_activity failed [%d]", err);
goto FINISH_OFF;
}
@@ -749,12 +758,12 @@ INTERNAL_FUNC int emcore_insert_auto_download_activity(email_event_auto_download
FINISH_OFF:
if (ret == true) { /* COMMIT TRANSACTION; */
- if (emstorage_commit_transaction(NULL, NULL, NULL) == false) {
+ if (emstorage_commit_transaction(local_activity->multi_user_name, NULL, NULL, NULL) == false) {
err = EMAIL_ERROR_DB_FAILURE;
ret = false;
}
} else { /* ROLLBACK TRANSACTION; */
- if (!before_tr_begin && emstorage_rollback_transaction(NULL, NULL, NULL) == false)
+ if (!before_tr_begin && emstorage_rollback_transaction(local_activity->multi_user_name, NULL, NULL, NULL) == false)
err = EMAIL_ERROR_DB_FAILURE;
}
@@ -765,7 +774,7 @@ FINISH_OFF:
}
-INTERNAL_FUNC int emcore_delete_auto_download_activity(int account_id, int mail_id, int activity_id, int *err_code)
+INTERNAL_FUNC int emcore_delete_auto_download_activity(char *multi_user_name, int account_id, int mail_id, int activity_id, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("account_id[%d], mail_id[%d], err_code[%p]", account_id, mail_id, err_code);
@@ -780,13 +789,13 @@ INTERNAL_FUNC int emcore_delete_auto_download_activity(int account_id, int mail_
int err = EMAIL_ERROR_NONE;
int before_tr_begin = 0;
- if (!emstorage_begin_transaction(NULL, NULL, &err)) {
+ if (!emstorage_begin_transaction(multi_user_name, NULL, NULL, &err)) {
EM_DEBUG_EXCEPTION("emstorage_begin_transaction failed [%d]", err);
before_tr_begin = 1;
goto FINISH_OFF;
}
- if (!emstorage_delete_auto_download_activity(account_id, mail_id, activity_id, false, &err)) {
+ if (!emstorage_delete_auto_download_activity(multi_user_name, account_id, mail_id, activity_id, false, &err)) {
EM_DEBUG_EXCEPTION("emstorage_delete_auto_download_activity failed [%d]", err);
goto FINISH_OFF;
}
@@ -798,12 +807,12 @@ INTERNAL_FUNC int emcore_delete_auto_download_activity(int account_id, int mail_
FINISH_OFF:
if (ret == true) { /* COMMIT TRANSACTION; */
- if (emstorage_commit_transaction(NULL, NULL, NULL) == false) {
+ if (emstorage_commit_transaction(multi_user_name, NULL, NULL, NULL) == false) {
err = EMAIL_ERROR_DB_FAILURE;
ret = false;
}
} else { /* ROLLBACK TRANSACTION; */
- if (!before_tr_begin && emstorage_rollback_transaction(NULL, NULL, NULL) == false)
+ if (!before_tr_begin && emstorage_rollback_transaction(multi_user_name, NULL, NULL, NULL) == false)
err = EMAIL_ERROR_DB_FAILURE;
}
diff --git a/email-core/email-core-cert.c b/email-core/email-core-cert.c
index 0b7de69..39be3fb 100755
--- a/email-core/email-core-cert.c
+++ b/email-core/email-core-cert.c
@@ -238,6 +238,10 @@ INTERNAL_FUNC int emcore_load_PFX_file(char *certificate, EVP_PKEY **pri_key, X5
CertSvcInstance cert_instance;
CertSvcCertificate csc_cert;
CertSvcCertificateList certificate_list;
+ CertSvcStoreCertList* certList = NULL;
+ CertSvcStoreCertList* tempList = NULL;
+ char *alias = NULL;
+ int length = 0;
if (certificate == NULL) {
EM_DEBUG_EXCEPTION("Invalid parameter");
@@ -245,6 +249,8 @@ INTERNAL_FUNC int emcore_load_PFX_file(char *certificate, EVP_PKEY **pri_key, X5
goto FINISH_OFF;
}
+ EM_DEBUG_LOG("emcore_load_PFX_file - certificate passed : %s", certificate);
+
/* Create instance */
err = certsvc_instance_new(&cert_instance);
if (err != CERTSVC_SUCCESS) {
@@ -253,8 +259,32 @@ INTERNAL_FUNC int emcore_load_PFX_file(char *certificate, EVP_PKEY **pri_key, X5
goto FINISH_OFF;
}
+ if (certsvc_pkcs12_get_end_user_certificate_list_from_store(cert_instance, EMAIL_STORE, &certList, &length)!=CERTSVC_SUCCESS)
+ {
+ EM_DEBUG_EXCEPTION("certsvc_string_new failed : [%d]", err);
+ err = EMAIL_ERROR_LOAD_CERTIFICATE_FAILURE;
+ goto FINISH_OFF;
+ }
+ tempList = certList;
+ while(tempList!=NULL)
+ {
+ if (strcmp(tempList->title, certificate)==0)
+ {
+ alias = strdup(tempList->gname);
+ break;
+ }
+ if (strcmp(tempList->gname, certificate)==0)
+ {
+ alias = strdup(tempList->gname);
+ break;
+ }
+ tempList = tempList->next;
+ }
+
+ certsvc_pkcs12_free_certificate_list_loaded_from_store(cert_instance, &certList);
+
/* Make the pfxID string */
- err = certsvc_string_new(cert_instance, certificate, EM_SAFE_STRLEN(certificate), &csstring);
+ err = certsvc_string_new(cert_instance, alias, EM_SAFE_STRLEN(alias), &csstring);
if (err != CERTSVC_SUCCESS) {
EM_DEBUG_EXCEPTION("certsvc_string_new failed : [%d]", err);
err = EMAIL_ERROR_LOAD_CERTIFICATE_FAILURE;
@@ -262,11 +292,23 @@ INTERNAL_FUNC int emcore_load_PFX_file(char *certificate, EVP_PKEY **pri_key, X5
}
/* Load the certificate list of pkcs12 type */
- err = certsvc_pkcs12_load_certificate_list(cert_instance, csstring, &certificate_list);
+ err = certsvc_pkcs12_load_certificate_list_from_store(cert_instance, EMAIL_STORE, csstring, &certificate_list);
if (err != CERTSVC_SUCCESS) {
- EM_DEBUG_EXCEPTION("certsvc_pkcs12_load_certificate_list failed : [%d]", err);
- err = EMAIL_ERROR_LOAD_CERTIFICATE_FAILURE;
- goto FINISH_OFF;
+ certsvc_string_free(csstring);
+ err = certsvc_string_new(cert_instance, certificate, EM_SAFE_STRLEN(certificate), &csstring);
+ if (err != CERTSVC_SUCCESS) {
+ EM_DEBUG_EXCEPTION("certsvc_string_new failed : [%d]", err);
+ err = EMAIL_ERROR_LOAD_CERTIFICATE_FAILURE;
+ goto FINISH_OFF;
+ }
+
+ /* Load the certificate list of pkcs12 type */
+ err = certsvc_pkcs12_load_certificate_list_from_store(cert_instance, EMAIL_STORE, csstring, &certificate_list);
+ if (err != CERTSVC_SUCCESS) {
+ EM_DEBUG_EXCEPTION("certsvc_pkcs12_load_certificate_list_from_store failed : [%d]", err);
+ err = EMAIL_ERROR_LOAD_CERTIFICATE_FAILURE;
+ goto FINISH_OFF;
+ }
}
/* Get a certificate */
@@ -286,9 +328,9 @@ INTERNAL_FUNC int emcore_load_PFX_file(char *certificate, EVP_PKEY **pri_key, X5
}
/* Get the private key */
- err = certsvc_pkcs12_private_key_dup(cert_instance, csstring, &private_key, &key_size);
+ err = certsvc_pkcs12_private_key_dup_from_store(cert_instance, EMAIL_STORE, csstring, &private_key, &key_size);
if (err != CERTSVC_SUCCESS) {
- EM_DEBUG_EXCEPTION("certsvc_pkcs12_private_key_dup failed : [%d]", err);
+ EM_DEBUG_EXCEPTION("certsvc_pkcs12_private_key_dup_from_store failed : [%d]", err);
err = EMAIL_ERROR_LOAD_CERTIFICATE_FAILURE;
goto FINISH_OFF;
}
@@ -334,8 +376,8 @@ FINISH_OFF:
EVP_PKEY_free(t_pri_key);
}
- if (private_key)
- EM_SAFE_FREE(private_key);
+ EM_SAFE_FREE(private_key);
+ EM_SAFE_FREE(alias);
if (err_code)
*err_code = err;
@@ -350,6 +392,10 @@ INTERNAL_FUNC int emcore_load_PFX_file_from_string(char *certificate, char **key
int ret = false;
size_t p_key_size = 0;
char *private_key = NULL;
+ CertSvcStoreCertList* certList = NULL;
+ CertSvcStoreCertList* tempList = NULL;
+ char *alias = NULL;
+ int length = 0;
/* Variable for certificate */
X509 *t_cert = NULL;
@@ -369,6 +415,8 @@ INTERNAL_FUNC int emcore_load_PFX_file_from_string(char *certificate, char **key
goto FINISH_OFF;
}
+ EM_DEBUG_EXCEPTION("emcore_load_PFX_file_from_string - certificate passed : %s",certificate);
+
/* Create instance */
err = certsvc_instance_new(&cert_instance);
if (err != CERTSVC_SUCCESS) {
@@ -385,14 +433,46 @@ INTERNAL_FUNC int emcore_load_PFX_file_from_string(char *certificate, char **key
goto FINISH_OFF;
}
- /* Load the certificate list of pkcs12 type */
- err = certsvc_pkcs12_load_certificate_list(cert_instance, csstring, &certificate_list);
- if (err != CERTSVC_SUCCESS) {
- EM_DEBUG_EXCEPTION("certsvc_pkcs12_load_certificate_list failed : [%d]", err);
+ if (certsvc_pkcs12_get_end_user_certificate_list_from_store(cert_instance, EMAIL_STORE, &certList, &length)!=CERTSVC_SUCCESS) {
+ EM_DEBUG_EXCEPTION("certsvc_string_new failed : [%d]", err);
err = EMAIL_ERROR_LOAD_CERTIFICATE_FAILURE;
goto FINISH_OFF;
}
+ tempList = certList;
+ while(tempList!=NULL) {
+ if (strcmp(tempList->title, certificate)==0) {
+ alias = strdup(tempList->gname);
+ break;
+ } else if (strcmp(tempList->gname, certificate)==0) {
+ alias = strdup(tempList->gname);
+ break;
+ }
+ tempList = tempList->next;
+ }
+
+ certsvc_pkcs12_free_certificate_list_loaded_from_store(cert_instance, &certList);
+
+ /* Load the certificate list of pkcs12 type */
+ err = certsvc_pkcs12_load_certificate_list_from_store(cert_instance, EMAIL_STORE, csstring, &certificate_list);
+ if (err != CERTSVC_SUCCESS) {
+ certsvc_string_free(csstring);
+ err = certsvc_string_new(cert_instance, alias, EM_SAFE_STRLEN(alias), &csstring);
+ if (err != CERTSVC_SUCCESS) {
+ EM_DEBUG_EXCEPTION("certsvc_string_new failed : [%d]", err);
+ err = EMAIL_ERROR_LOAD_CERTIFICATE_FAILURE;
+ goto FINISH_OFF;
+ }
+
+ /* Load the certificate list of pkcs12 type */
+ err = certsvc_pkcs12_load_certificate_list_from_store(cert_instance, EMAIL_STORE, csstring, &certificate_list);
+ if (err != CERTSVC_SUCCESS) {
+ EM_DEBUG_EXCEPTION("certsvc_pkcs12_load_certificate_list_from_store failed : [%d]", err);
+ err = EMAIL_ERROR_LOAD_CERTIFICATE_FAILURE;
+ goto FINISH_OFF;
+ }
+ }
+
/* Get a certificate */
err = certsvc_certificate_list_get_one(certificate_list, 0, &csc_cert);
if (err != CERTSVC_SUCCESS) {
@@ -410,9 +490,9 @@ INTERNAL_FUNC int emcore_load_PFX_file_from_string(char *certificate, char **key
}
/* Get the private key */
- err = certsvc_pkcs12_private_key_dup(cert_instance, csstring, &private_key, &p_key_size);
+ err = certsvc_pkcs12_private_key_dup_from_store(cert_instance, EMAIL_STORE, csstring, &private_key, &p_key_size);
if (err != CERTSVC_SUCCESS) {
- EM_DEBUG_EXCEPTION("certsvc_pkcs12_private_key_dup failed : [%d]", err);
+ EM_DEBUG_EXCEPTION("certsvc_pkcs12_private_key_dup_from_store failed : [%d]", err);
err = EMAIL_ERROR_LOAD_CERTIFICATE_FAILURE;
goto FINISH_OFF;
}
@@ -434,13 +514,15 @@ FINISH_OFF:
EM_SAFE_FREE(private_key);
}
+ EM_SAFE_FREE(alias);
+
if (err_code)
*err_code = err;
return ret;
}
-INTERNAL_FUNC int emcore_add_public_certificate(char *public_cert_path, char *save_name, int *err_code)
+INTERNAL_FUNC int emcore_add_public_certificate(char *multi_user_name, char *public_cert_path, char *save_name, int *err_code)
{
EM_DEBUG_FUNC_BEGIN_SEC("Path [%s], filename [%s]", public_cert_path, save_name);
int err = EMAIL_ERROR_NONE;
@@ -547,7 +629,7 @@ INTERNAL_FUNC int emcore_add_public_certificate(char *public_cert_path, char *sa
cert->subject_str = EM_SAFE_STRDUP(context->certDesc->info.issuerStr);
cert->filepath = EM_SAFE_STRDUP(filepath);
- if (!emstorage_add_certificate(cert, true, &err)) {
+ if (emstorage_add_certificate(multi_user_name, cert, true, &err)) {
EM_DEBUG_EXCEPTION("emstorage_add_certificate failed");
goto FINISH_OFF;
}
@@ -563,9 +645,11 @@ FINISH_OFF:
emstorage_delete_file(temp_file, NULL);
- emstorage_free_certificate(&cert, 1, NULL);
+ if (cert)
+ emstorage_free_certificate(&cert, 1, NULL);
- cert_svc_cert_context_final(context);
+ if (context)
+ cert_svc_cert_context_final(context);
if (err_code != NULL) {
*err_code = err;
@@ -577,7 +661,7 @@ FINISH_OFF:
}
-INTERNAL_FUNC int emcore_delete_public_certificate(char *email_address, int *err_code)
+INTERNAL_FUNC int emcore_delete_public_certificate(char *multi_user_name, char *email_address, int *err_code)
{
EM_DEBUG_FUNC_BEGIN();
int ret = false;
@@ -590,7 +674,7 @@ INTERNAL_FUNC int emcore_delete_public_certificate(char *email_address, int *err
goto FINISH_OFF;
}
- if (!emstorage_get_certificate_by_email_address(email_address, &certificate, false, 0, &err)) {
+ if (!emstorage_get_certificate_by_email_address(multi_user_name, email_address, &certificate, false, 0, &err)) {
EM_DEBUG_EXCEPTION("emstorage_get_certificate failed");
goto FINISH_OFF;
}
@@ -600,7 +684,7 @@ INTERNAL_FUNC int emcore_delete_public_certificate(char *email_address, int *err
goto FINISH_OFF;
}
- if (!emstorage_delete_certificate(certificate->certificate_id, true, &err)) {
+ if (!emstorage_delete_certificate(multi_user_name, certificate->certificate_id, true, &err)) {
EM_DEBUG_EXCEPTION("emstorage_delete_certificate failed");
goto FINISH_OFF;
}
@@ -628,9 +712,7 @@ INTERNAL_FUNC int emcore_verify_signature(char *p7s_file_path, char *mime_entity
int flags = PKCS7_NOVERIFY;
BIO *bio_p7s = NULL;
-
BIO *bio_indata = NULL;
-
PKCS7 *pkcs7_p7s = NULL;
/* Open p7s file */
@@ -652,13 +734,15 @@ INTERNAL_FUNC int emcore_verify_signature(char *p7s_file_path, char *mime_entity
/* Load the p7s file */
pkcs7_p7s = d2i_PKCS7_bio(bio_p7s, NULL);
if (!pkcs7_p7s) {
- EM_DEBUG_EXCEPTION("d2i_PKCS7_bio failed");
+ unsigned long error = ERR_get_error();
+ EM_DEBUG_EXCEPTION("d2i_PKCS7_bio failed : [%ld][%s]", error, ERR_error_string(error, NULL));
err = EMAIL_ERROR_LOAD_CERTIFICATE_FAILURE;
goto FINISH_OFF;
}
if (!PKCS7_verify(pkcs7_p7s, NULL, NULL, bio_indata, NULL, flags)) {
- EM_DEBUG_EXCEPTION("PKCS7_verify failed");
+ unsigned long error = ERR_get_error();
+ EM_DEBUG_EXCEPTION("PKCS7_verify failed : [%ld][%s]", error, ERR_error_string(error, NULL));
goto FINISH_OFF;
}
@@ -668,14 +752,9 @@ INTERNAL_FUNC int emcore_verify_signature(char *p7s_file_path, char *mime_entity
FINISH_OFF:
- if (pkcs7_p7s)
- PKCS7_free(pkcs7_p7s);
-
- if (bio_p7s)
- BIO_free(bio_p7s);
-
- if (bio_indata)
- BIO_free(bio_indata);
+ PKCS7_free(pkcs7_p7s);
+ BIO_free(bio_p7s);
+ BIO_free(bio_indata);
if (validity)
*validity = t_validity;
diff --git a/email-core/email-core-container.c b/email-core/email-core-container.c
new file mode 100644
index 0000000..da21028
--- /dev/null
+++ b/email-core/email-core-container.c
@@ -0,0 +1,441 @@
+/*
+* email-service
+*
+* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+*
+* Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com>
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*
+*/
+
+/**
+ *
+ * This file contains functionality related to KNOX
+ * to interact with email-service.
+ * @file email-core-container.c
+ * @author
+ * @version 0.1
+ * @brief This file contains functionality to provide KNOX support in email-service.
+ */
+
+#include <vasum.h>
+
+#include "email-utilities.h"
+#include "email-core-container.h"
+#include "email-debug-log.h"
+
+int vsm_state_handle = 0;
+int vsm_event_handle = 0;
+vsm_context_h container;
+
+enum {
+ CONTAINER_DISABLE = 0,
+ CONTAINER_ENABLE = 1
+};
+
+static int container_status = CONTAINER_DISABLE;
+
+static int container_state_listener(vsm_zone_h zone, vsm_zone_state_t state, void *user_data)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ EM_DEBUG_LOG("Container name : [%s]", vsm_get_zone_name(zone));
+ EM_DEBUG_LOG("Container state : [%d]", state);
+ EM_DEBUG_FUNC_END();
+ return 0;
+}
+
+static int container_event_listener(vsm_zone_h zone, vsm_zone_event_t event, void *user_data)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ EM_DEBUG_LOG("Container name : [%s]", vsm_get_zone_name(zone));
+ EM_DEBUG_LOG("Container event : [%d]", event);
+ EM_DEBUG_FUNC_END();
+ return 0;
+}
+
+INTERNAL_FUNC void emcore_create_container()
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ container = NULL;
+
+ container = vsm_create_context();
+ if (container == NULL) {
+ EM_DEBUG_EXCEPTION("vsm_create_context failed");
+ return;
+ }
+
+ vsm_state_handle = vsm_add_state_changed_callback(container, container_state_listener, NULL);
+ vsm_event_handle = vsm_add_event_callback(container, container_event_listener, NULL);
+
+ EM_DEBUG_FUNC_END();
+}
+
+INTERNAL_FUNC void emcore_destroy_container()
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ if (container) {
+ vsm_del_state_changed_callback(container, vsm_state_handle);
+
+ vsm_del_event_callback(container, vsm_event_handle);
+
+ vsm_cleanup_context(container);
+
+ container = NULL;
+ }
+
+ EM_DEBUG_FUNC_END();
+}
+
+static gboolean mainloop_callback(GIOChannel *channel, GIOCondition condition, void *data)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ vsm_context_h ctx = (vsm_context_h)data;
+
+ EM_DEBUG_LOG("Enter event loop");
+ vsm_enter_eventloop(ctx, 0, 0);
+ EM_DEBUG_LOG("Finish event loop");
+
+ EM_DEBUG_FUNC_END();
+ return TRUE;
+}
+
+INTERNAL_FUNC void emcore_bind_vsm_context()
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ int fd;
+
+ GIOChannel *domain_channel = NULL;
+
+ fd = vsm_get_poll_fd(container);
+ if (fd < 0) {
+ EM_DEBUG_EXCEPTION("vsm_get_poll_fd failed");
+ return;
+ }
+
+ domain_channel = g_io_channel_unix_new(fd);
+ if (domain_channel == NULL) {
+ EM_DEBUG_EXCEPTION("Channel allocation failed");
+ return;
+ }
+
+ g_io_add_watch(domain_channel, G_IO_IN, mainloop_callback, container);
+
+ EM_DEBUG_FUNC_END();
+}
+
+INTERNAL_FUNC int emcore_get_container_path(char *multi_user, char **container_path)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int err = EMAIL_ERROR_NONE;
+
+ if (multi_user == NULL) {
+ EM_DEBUG_LOG("user_name is NULL");
+ return EMAIL_ERROR_INVALID_PARAM;
+ }
+
+ if (container_status == CONTAINER_DISABLE) {
+ EM_DEBUG_LOG("Single container");
+ return err;
+ }
+
+ if (container == NULL) {
+ EM_DEBUG_LOG("Container not intialize");
+ return EMAIL_ERROR_CONTAINER_NOT_INITIALIZATION;
+ }
+
+ vsm_zone_h zone = NULL;
+ char *p_container_path = NULL;
+ char errno_buf[ERRNO_BUF_SIZE] = {0};
+
+ if (EM_SAFE_STRLEN(multi_user) == 0) {
+ EM_DEBUG_LOG("multi_user name is NULL");
+ goto FINISH_OFF;
+ }
+
+ EM_DEBUG_LOG("name : [%s], container : [%p]", multi_user, container);
+ zone = vsm_lookup_zone_by_name(container, multi_user);
+ if (zone == NULL) {
+ EM_DEBUG_EXCEPTION("NULL returned : %s, %d", EM_STRERROR(errno_buf), errno);
+ err = EMAIL_ERROR_CONTAINER_GET_DOMAIN;
+ goto FINISH_OFF;
+ }
+
+ p_container_path = (char *)vsm_get_zone_rootpath(zone);
+
+FINISH_OFF:
+
+ if (container_path)
+ *container_path = EM_SAFE_STRDUP(p_container_path);
+
+ EM_DEBUG_FUNC_END();
+ return err;
+}
+
+INTERNAL_FUNC int emcore_get_user_name(int pid, char **multi_user)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ int err = EMAIL_ERROR_NONE;
+
+ if (pid <= 0) {
+ EM_DEBUG_EXCEPTION("Invalid parameter");
+ return EMAIL_ERROR_INVALID_PARAM;
+ }
+
+ if (container_status == CONTAINER_DISABLE) {
+ EM_DEBUG_LOG("Single container");
+ return err;
+ }
+
+ if (container == NULL) {
+ EM_DEBUG_LOG("Container not intialize");
+ return EMAIL_ERROR_CONTAINER_NOT_INITIALIZATION;
+ }
+
+ char *user_name = NULL;
+ vsm_zone_h zone = NULL;
+ char errno_buf[ERRNO_BUF_SIZE] = {0};
+
+ EM_DEBUG_LOG("pid : [%d], container : [%p]", pid, container);
+ zone = vsm_lookup_zone_by_pid(container, pid);
+ if (zone == NULL) {
+ EM_DEBUG_EXCEPTION("NULL returned : %s, %d", EM_STRERROR(errno_buf), errno);
+ err = EMAIL_ERROR_CONTAINER_GET_DOMAIN;
+ goto FINISH_OFF;
+ }
+
+ user_name = (char *)vsm_get_zone_name(zone);
+ EM_DEBUG_LOG("user_name : [%s]", user_name);
+
+FINISH_OFF:
+
+ if (multi_user)
+ *multi_user = EM_SAFE_STRDUP(user_name);
+
+ EM_DEBUG_FUNC_END();
+ return err;
+}
+
+INTERNAL_FUNC int emcore_lookup_zone_by_name(char *user_name)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int ret = false;
+
+ if (EM_SAFE_STRLEN(user_name) == 0) {
+ EM_DEBUG_LOG("user_name is NULL");
+ return ret;
+ }
+
+ if (container_status == CONTAINER_DISABLE) {
+ EM_DEBUG_LOG("Single container");
+ return true;
+ }
+
+ if (container == NULL) {
+ EM_DEBUG_LOG("Container not intialize");
+ return ret;
+ }
+
+ vsm_zone_h zone = NULL;
+ char errno_buf[ERRNO_BUF_SIZE] = {0};
+
+ EM_DEBUG_LOG("name : [%s], container : [%p]", user_name, container);
+ zone = vsm_lookup_zone_by_name(container, user_name);
+ if (zone == NULL) {
+ EM_DEBUG_EXCEPTION("NULL returned : %s, %d", EM_STRERROR(errno_buf), errno);
+ goto FINISH_OFF;
+ }
+
+ ret = true;
+
+FINISH_OFF:
+
+ EM_DEBUG_FUNC_END();
+ return ret;
+}
+
+INTERNAL_FUNC void emcore_set_declare_link(const char *file_path)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ if (container_status == CONTAINER_DISABLE) {
+ EM_DEBUG_LOG("Single container");
+ return;
+ }
+
+ if (container == NULL) {
+ EM_DEBUG_EXCEPTION("Not initialize");
+ return;
+ }
+
+ int ret = 0;
+ if ((ret = vsm_declare_link(container, file_path /* src path */, file_path /* dst path */)) != 0) {
+ EM_DEBUG_EXCEPTION("vsm_declare_link failed : [%s] [%d]", file_path, ret);
+ }
+
+ EM_DEBUG_FUNC_END();
+}
+
+void iterate_callback(vsm_zone_h zone, void *user_data)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ char *zone_name = NULL;
+ GList *zone_name_list = (GList *)user_data;
+
+ zone_name = EM_SAFE_STRDUP(vsm_get_zone_name(zone));
+ if (EM_SAFE_STRLEN(zone_name) > 0)
+ zone_name_list = g_list_append(zone_name_list, zone_name);
+
+ EM_DEBUG_FUNC_END();
+}
+
+INTERNAL_FUNC int emcore_get_zone_name_list(GList **output_name_list)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int err = EMAIL_ERROR_NONE;
+ int ret = 0;
+ GList *zone_name_list = NULL;
+ GList *node = NULL;
+
+ if (output_name_list == NULL) {
+ EM_DEBUG_EXCEPTION("Invalid parameter");
+ err = EMAIL_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ if (container_status == CONTAINER_DISABLE) {
+ EM_DEBUG_LOG("Single container");
+ goto FINISH_OFF;
+ }
+
+ if (container == NULL) {
+ EM_DEBUG_EXCEPTION("Not initialize");
+ err = EMAIL_ERROR_CONTAINER_CREATE_FAILED;
+ goto FINISH_OFF;
+ }
+
+ zone_name_list = g_list_alloc();
+ if (zone_name_list == NULL) {
+ EM_DEBUG_EXCEPTION("g_list_alloc failed");
+ err = EMAIL_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ if ((ret = vsm_iterate_zone(container, iterate_callback, (void *)zone_name_list)) < 0) {
+ EM_DEBUG_EXCEPTION("vsm_iterate_domain failed : [%d]", ret);
+ err = EMAIL_ERROR_CONTAINER_ITERATE_DOMAIN;
+ goto FINISH_OFF;
+ }
+
+FINISH_OFF:
+
+ if (err != EMAIL_ERROR_NONE) {
+ node = g_list_first(zone_name_list);
+ while (node != NULL) {
+ /* Free the domain name */
+ EM_SAFE_FREE(node->data);
+ node = g_list_next(node);
+ }
+ g_list_free(zone_name_list);
+ zone_name_list = NULL;
+ }
+
+ if (output_name_list)
+ *output_name_list = zone_name_list;
+
+ EM_DEBUG_FUNC_END();
+ return err;
+}
+
+INTERNAL_FUNC int emcore_get_canonicalize_path(char *db_path, char **output_path)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int err = EMAIL_ERROR_NONE;
+
+ int ret = 0;
+ ret = vsm_canonicalize_path(db_path, output_path);
+ if (ret < 0) {
+ EM_DEBUG_EXCEPTION("vsm_canonicalize_path failed : [%d]", ret);
+ err = EMAIL_ERROR_FILE_NOT_FOUND;
+ }
+
+ EM_DEBUG_FUNC_END();
+ return err;
+}
+
+INTERNAL_FUNC int emcore_set_join_zone(char *multi_user_name, void **join_zone)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int err = EMAIL_ERROR_NONE;
+ char errno_buf[ERRNO_BUF_SIZE] = {0};
+ vsm_zone_h temp_zone = NULL;
+ vsm_zone_h p_join_zone = NULL;
+
+ if (container_status == CONTAINER_DISABLE) {
+ EM_DEBUG_LOG("Single container");
+ goto FINISH_OFF;
+ }
+
+ if (container == NULL) {
+ EM_DEBUG_EXCEPTION("Not initialize");
+ err = EMAIL_ERROR_CONTAINER_CREATE_FAILED;
+ goto FINISH_OFF;
+ }
+
+ if (EM_SAFE_STRLEN(multi_user_name) == 0) {
+ EM_DEBUG_LOG("multi_user_name is NULL");
+ return err;
+ }
+
+ temp_zone = vsm_lookup_zone_by_name(container, multi_user_name);
+ if (temp_zone == NULL) {
+ EM_DEBUG_EXCEPTION("NULL returned : %s %d", EM_STRERROR(errno_buf), errno);
+ err = EMAIL_ERROR_CONTAINER_LOOKUP_ZONE_FAILED;
+ goto FINISH_OFF;
+ }
+
+ p_join_zone = vsm_join_zone(temp_zone);
+ if (p_join_zone == NULL) {
+ EM_DEBUG_EXCEPTION("NULL returned : %s %d", EM_STRERROR(errno_buf), errno);
+ err = EMAIL_ERROR_CONTAINER_JOIN_ZONE_FAILED;
+ goto FINISH_OFF;
+ }
+
+FINISH_OFF:
+
+ if (join_zone)
+ *join_zone = (void *)p_join_zone;
+
+ EM_DEBUG_FUNC_END();
+ return err;
+}
+
+INTERNAL_FUNC void emcore_unset_join_zone(void *join_zone)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ char errno_buf[ERRNO_BUF_SIZE] = {0};
+ vsm_zone_h temp_zone = NULL;
+
+ temp_zone = vsm_join_zone((vsm_zone_h)join_zone);
+ if (temp_zone == NULL) {
+ EM_DEBUG_EXCEPTION("NULL returned : %s %d", EM_STRERROR(errno_buf), errno);
+ }
+
+ EM_DEBUG_FUNC_END();
+}
diff --git a/email-core/email-core-event.c b/email-core/email-core-event.c
index f40374e..de6a63f 100755
--- a/email-core/email-core-event.c
+++ b/email-core/email-core-event.c
@@ -160,67 +160,72 @@ static void fail_status_notify(email_event_t *event_data, int error)
case EMAIL_EVENT_SEND_MAIL:
/* case EMAIL_EVENT_SEND_MAIL_SAVED: */
/* emcore_execute_event_callback(EMAIL_ACTION_SEND_MAIL, 0, 0, EMAIL_SEND_FAIL, account_id, mail_id, -1, error); */
- emcore_show_user_message(mail_id, EMAIL_ACTION_SEND_MAIL, error);
+ emcore_show_user_message(event_data->multi_user_name, mail_id, EMAIL_ACTION_SEND_MAIL, error);
break;
case EMAIL_EVENT_SYNC_HEADER:
emcore_execute_event_callback(EMAIL_ACTION_SYNC_HEADER, 0, 0, EMAIL_LIST_FAIL, account_id, 0, -1, error);
- emcore_show_user_message(account_id, EMAIL_ACTION_SYNC_HEADER, error);
+ emcore_show_user_message(event_data->multi_user_name, account_id, EMAIL_ACTION_SYNC_HEADER, error);
break;
case EMAIL_EVENT_DOWNLOAD_BODY:
emcore_execute_event_callback(EMAIL_ACTION_DOWNLOAD_BODY, 0, 0, EMAIL_DOWNLOAD_FAIL, account_id, mail_id, -1, error);
- emcore_show_user_message(account_id, EMAIL_ACTION_DOWNLOAD_BODY, error);
+ emcore_show_user_message(event_data->multi_user_name, account_id, EMAIL_ACTION_DOWNLOAD_BODY, error);
break;
case EMAIL_EVENT_DOWNLOAD_ATTACHMENT:
emcore_execute_event_callback(EMAIL_ACTION_DOWNLOAD_ATTACHMENT, 0, 0, EMAIL_DOWNLOAD_FAIL, account_id, mail_id, -1, error);
- emcore_show_user_message(account_id, EMAIL_ACTION_DOWNLOAD_ATTACHMENT, error);
+ emcore_show_user_message(event_data->multi_user_name, account_id, EMAIL_ACTION_DOWNLOAD_ATTACHMENT, error);
break;
case EMAIL_EVENT_DELETE_MAIL:
case EMAIL_EVENT_DELETE_MAIL_ALL:
emcore_execute_event_callback(EMAIL_ACTION_DELETE_MAIL, 0, 0, EMAIL_DELETE_FAIL, account_id, 0, -1, error);
- emcore_show_user_message(account_id, EMAIL_ACTION_DELETE_MAIL, error);
+ emcore_show_user_message(event_data->multi_user_name, account_id, EMAIL_ACTION_DELETE_MAIL, error);
break;
case EMAIL_EVENT_VALIDATE_ACCOUNT:
emcore_execute_event_callback(EMAIL_ACTION_VALIDATE_ACCOUNT, 0, 0, EMAIL_VALIDATE_ACCOUNT_FAIL, account_id, 0, -1, error);
- emcore_show_user_message(account_id, EMAIL_ACTION_VALIDATE_ACCOUNT, error);
+ emcore_show_user_message(event_data->multi_user_name, account_id, EMAIL_ACTION_VALIDATE_ACCOUNT, error);
break;
case EMAIL_EVENT_VALIDATE_AND_CREATE_ACCOUNT:
emcore_execute_event_callback(EMAIL_ACTION_VALIDATE_AND_CREATE_ACCOUNT, 0, 0, EMAIL_VALIDATE_ACCOUNT_FAIL, account_id, 0, -1, error);
- emcore_show_user_message(account_id, EMAIL_ACTION_VALIDATE_AND_CREATE_ACCOUNT, error);
+ emcore_show_user_message(event_data->multi_user_name, account_id, EMAIL_ACTION_VALIDATE_AND_CREATE_ACCOUNT, error);
break;
case EMAIL_EVENT_VALIDATE_ACCOUNT_EX:
emcore_execute_event_callback(EMAIL_ACTION_VALIDATE_ACCOUNT_EX, 0, 0, EMAIL_VALIDATE_ACCOUNT_FAIL, account_id, 0, -1, error);
- emcore_show_user_message(account_id, EMAIL_ACTION_VALIDATE_ACCOUNT_EX, error);
+ emcore_show_user_message(event_data->multi_user_name, account_id, EMAIL_ACTION_VALIDATE_ACCOUNT_EX, error);
break;
case EMAIL_EVENT_CREATE_MAILBOX:
emcore_execute_event_callback(EMAIL_ACTION_CREATE_MAILBOX, 0, 0, EMAIL_LIST_FAIL, account_id, 0, -1, error);
- emcore_show_user_message(account_id, EMAIL_ACTION_CREATE_MAILBOX, error);
+ emcore_show_user_message(event_data->multi_user_name, account_id, EMAIL_ACTION_CREATE_MAILBOX, error);
break;
case EMAIL_EVENT_DELETE_MAILBOX:
emcore_execute_event_callback(EMAIL_ACTION_DELETE_MAILBOX, 0, 0, EMAIL_LIST_FAIL, account_id, 0, -1, error);
- emcore_show_user_message(account_id, EMAIL_ACTION_DELETE_MAILBOX, error);
+ emcore_show_user_message(event_data->multi_user_name, account_id, EMAIL_ACTION_DELETE_MAILBOX, error);
break;
case EMAIL_EVENT_VALIDATE_AND_UPDATE_ACCOUNT:
emcore_execute_event_callback(EMAIL_ACTION_VALIDATE_AND_UPDATE_ACCOUNT, 0, 0, EMAIL_VALIDATE_ACCOUNT_FAIL, account_id, 0, -1, error);
- emcore_show_user_message(account_id, EMAIL_ACTION_VALIDATE_AND_UPDATE_ACCOUNT, error);
+ emcore_show_user_message(event_data->multi_user_name, account_id, EMAIL_ACTION_VALIDATE_AND_UPDATE_ACCOUNT, error);
break;
case EMAIL_EVENT_SET_MAIL_SLOT_SIZE:
emcore_execute_event_callback(EMAIL_ACTION_SET_MAIL_SLOT_SIZE, 0, 0, EMAIL_SET_SLOT_SIZE_FAIL, account_id, 0, -1, EMAIL_ERROR_NONE);
break;
+ case EMAIL_EVENT_SEARCH_ON_SERVER:
+ emcore_execute_event_callback(EMAIL_ACTION_SEARCH_ON_SERVER, 0, 0, EMAIL_SEARCH_ON_SERVER_FAIL, account_id, 0, -1, EMAIL_ERROR_NONE);
+ emcore_show_user_message(event_data->multi_user_name, account_id, EMAIL_ACTION_SEARCH_ON_SERVER, error);
+ break;
+
case EMAIL_EVENT_RENAME_MAILBOX_ON_IMAP_SERVER:
emcore_execute_event_callback(EMAIL_ACTION_MOVE_MAILBOX, 0, 0, EMAIL_MOVE_MAILBOX_ON_IMAP_SERVER_FAIL, account_id, 0, -1, EMAIL_ERROR_NONE);
- emcore_show_user_message(account_id, EMAIL_ACTION_SEARCH_ON_SERVER, error);
+ emcore_show_user_message(event_data->multi_user_name, account_id, EMAIL_ACTION_SEARCH_ON_SERVER, error);
break;
case EMAIL_EVENT_UPDATE_MAIL:
@@ -400,6 +405,12 @@ INTERNAL_FUNC int emcore_insert_event(email_event_t *event_data, int *handle, in
WAKE_CONDITION_VARIABLE(_event_available_signal);
ret = true;
}
+ else {
+ EM_DEBUG_EXCEPTION("event queue is full...");
+ error = EMAIL_ERROR_EVENT_QUEUE_FULL;
+ ret = false;
+ }
+
}
LEAVE_RECURSIVE_CRITICAL_SECTION(_event_queue_lock);
@@ -424,6 +435,7 @@ INTERNAL_FUNC int emcore_insert_event(email_event_t *event_data, int *handle, in
case EMAIL_EVENT_SET_MAIL_SLOT_SIZE:
case EMAIL_EVENT_UPDATE_MAIL:
case EMAIL_EVENT_EXPUNGE_MAILS_DELETED_FLAGGED:
+ case EMAIL_EVENT_SEARCH_ON_SERVER:
case EMAIL_EVENT_RENAME_MAILBOX_ON_IMAP_SERVER:
break;
@@ -432,6 +444,7 @@ INTERNAL_FUNC int emcore_insert_event(email_event_t *event_data, int *handle, in
{
int is_local_activity_event_inserted = false;
emcore_partial_body_thd_local_activity_sync (
+ event_data->multi_user_name,
&is_local_activity_event_inserted,
&error);
if (error != EMAIL_ERROR_NONE) {
@@ -583,12 +596,12 @@ INTERNAL_FUNC void emcore_get_sync_fail_event_data(email_event_t **event_data)
new_event->event_param_data_3 = EM_SAFE_STRDUP(sync_failed_event_data->event_param_data_3);
new_event->event_param_data_4 = sync_failed_event_data->event_param_data_4;
new_event->event_param_data_5 = sync_failed_event_data->event_param_data_5;
+ new_event->multi_user_name = EM_SAFE_STRDUP(sync_failed_event_data->multi_user_name);
*event_data = new_event;
emcore_free_event(sync_failed_event_data);
EM_SAFE_FREE(sync_failed_event_data);
- sync_failed_event_data = NULL;
}
INTERNAL_FUNC int emcore_insert_event_for_sending_mails(email_event_t *event_data, int *handle, int *err_code)
@@ -809,6 +822,7 @@ case EMAIL_EVENT_UPDATE_MAIL:
case EMAIL_EVENT_SET_MAIL_SLOT_SIZE:
case EMAIL_EVENT_EXPUNGE_MAILS_DELETED_FLAGGED:
case EMAIL_EVENT_LOCAL_ACTIVITY:
+case EMAIL_EVENT_SEARCH_ON_SERVER:
case EMAIL_EVENT_RENAME_MAILBOX_ON_IMAP_SERVER:
case EMAIL_EVENT_QUERY_SMTP_MAIL_SIZE_LIMIT:
*/
@@ -922,6 +936,7 @@ INTERNAL_FUNC int emcore_cancel_thread(int handle, void *arg, int *err_code)
case EMAIL_EVENT_CREATE_MAILBOX:
case EMAIL_EVENT_DELETE_MAILBOX:
case EMAIL_EVENT_SET_MAIL_SLOT_SIZE:
+ case EMAIL_EVENT_SEARCH_ON_SERVER:
case EMAIL_EVENT_RENAME_MAILBOX_ON_IMAP_SERVER:
EM_DEBUG_LOG("EMAIL_EVENT_DELETE_MAIL, EMAIL_EVENT_SYNC_IMAP_MAILBOX");
break;
@@ -946,7 +961,7 @@ INTERNAL_FUNC int emcore_cancel_thread(int handle, void *arg, int *err_code)
EM_DEBUG_LOG("EMAIL_EVENT_SYNC_HEADER");
if (!emcore_notify_network_event(NOTI_DOWNLOAD_CANCEL, found_elm->account_id, NULL , found_elm->event_param_data_4, err))
EM_DEBUG_EXCEPTION("emcore_notify_network_event [ NOTI_DOWNLOAD_CANCEL] Failed >>>>");
- if ((err = emcore_update_sync_status_of_account(found_elm->account_id, SET_TYPE_MINUS, SYNC_STATUS_SYNCING)) != EMAIL_ERROR_NONE)
+ if ((err = emcore_update_sync_status_of_account(found_elm->multi_user_name, found_elm->account_id, SET_TYPE_MINUS, SYNC_STATUS_SYNCING)) != EMAIL_ERROR_NONE)
EM_DEBUG_EXCEPTION("emcore_update_sync_status_of_account failed [%d]", err);
break;
@@ -1033,6 +1048,7 @@ INTERNAL_FUNC int emcore_cancel_all_thread(int *err_code)
case EMAIL_EVENT_CREATE_MAILBOX:
case EMAIL_EVENT_DELETE_MAILBOX:
case EMAIL_EVENT_SET_MAIL_SLOT_SIZE:
+ case EMAIL_EVENT_SEARCH_ON_SERVER:
case EMAIL_EVENT_RENAME_MAILBOX_ON_IMAP_SERVER:
EM_DEBUG_LOG("EMAIL_EVENT_DELETE_MAIL, EMAIL_EVENT_SYNC_IMAP_MAILBOX");
break;
@@ -1053,7 +1069,7 @@ INTERNAL_FUNC int emcore_cancel_all_thread(int *err_code)
}
else {
- pop_elm->status = EMAIL_EVENT_STATUS_CANCELED;
+ if (pop_elm) pop_elm->status = EMAIL_EVENT_STATUS_CANCELED;
}
}
LEAVE_RECURSIVE_CRITICAL_SECTION(_event_queue_lock);
@@ -1100,7 +1116,7 @@ INTERNAL_FUNC int emcore_check_send_mail_thread_status(void)
return ret;
}
-INTERNAL_FUNC int emcore_cancel_all_threads_of_an_account(int account_id)
+INTERNAL_FUNC int emcore_cancel_all_threads_of_an_account(char *multi_user_name, int account_id)
{
EM_DEBUG_FUNC_BEGIN();
int error_code = EMAIL_ERROR_NONE;
@@ -1116,7 +1132,9 @@ INTERNAL_FUNC int emcore_cancel_all_threads_of_an_account(int account_id)
for (i = 0; i < q_length; i++) {
found_elm = (email_event_t *)g_queue_peek_nth(g_event_que, i);
- if (found_elm && (found_elm->account_id == account_id || found_elm->account_id == ALL_ACCOUNT)) {
+ if (found_elm && (found_elm->account_id == account_id || found_elm->account_id == ALL_ACCOUNT) &&
+ ((!found_elm->multi_user_name && !multi_user_name) || (
+ (multi_user_name) && !EM_SAFE_STRCASECMP(found_elm->multi_user_name, multi_user_name)))) {
EM_DEBUG_LOG("Found Queue element[%d]", i);
if (found_elm->status == EMAIL_EVENT_STATUS_WAIT) {
@@ -1127,13 +1145,15 @@ INTERNAL_FUNC int emcore_cancel_all_threads_of_an_account(int account_id)
case EMAIL_EVENT_SEND_MAIL:
case EMAIL_EVENT_SEND_MAIL_SAVED:
EM_DEBUG_LOG("EMAIL_EVENT_SEND_MAIL or EMAIL_EVENT_SEND_MAIL_SAVED");
- if (!emcore_notify_network_event(NOTI_SEND_CANCEL, found_elm->account_id, NULL , found_elm->event_param_data_4, error_code))
+ if (!emcore_notify_network_event(NOTI_SEND_CANCEL, found_elm->account_id, NULL ,
+ found_elm->event_param_data_4, error_code))
EM_DEBUG_EXCEPTION("emcore_notify_network_event [ NOTI_SEND_CANCEL] Failed >>>>");
break;
case EMAIL_EVENT_DOWNLOAD_BODY:
EM_DEBUG_LOG("EMAIL_EVENT_DOWNLOAD_BODY");
- if (!emcore_notify_network_event(NOTI_DOWNLOAD_BODY_CANCEL, found_elm->account_id, NULL , found_elm->event_param_data_4, error_code))
+ if (!emcore_notify_network_event(NOTI_DOWNLOAD_BODY_CANCEL, found_elm->account_id, NULL,
+ found_elm->event_param_data_4, error_code))
EM_DEBUG_EXCEPTION("emcore_notify_network_event [ NOTI_SEND_CANCEL] Failed >>>>");
break;
@@ -1159,6 +1179,7 @@ INTERNAL_FUNC int emcore_cancel_all_threads_of_an_account(int account_id)
case EMAIL_EVENT_CREATE_MAILBOX:
case EMAIL_EVENT_DELETE_MAILBOX:
case EMAIL_EVENT_SET_MAIL_SLOT_SIZE:
+ case EMAIL_EVENT_SEARCH_ON_SERVER:
case EMAIL_EVENT_RENAME_MAILBOX_ON_IMAP_SERVER:
EM_DEBUG_LOG("EMAIL_EVENT_DELETE_MAIL, EMAIL_EVENT_SYNC_IMAP_MAILBOX");
break;
@@ -1303,7 +1324,7 @@ INTERNAL_FUNC int emcore_cancel_all_send_mail_thread(int *err_code)
q_length = g_queue_get_length(g_send_event_que);
} else {
- pop_elm->status = EMAIL_EVENT_STATUS_CANCELED;
+ if (pop_elm) pop_elm->status = EMAIL_EVENT_STATUS_CANCELED;
}
}
LEAVE_RECURSIVE_CRITICAL_SECTION(_send_event_queue_lock);
@@ -1462,6 +1483,37 @@ INTERNAL_FUNC int emcore_free_event(email_event_t *event_data)
break;
#endif /* __FEATURE_LOCAL_ACTIVITY__*/
+ case EMAIL_EVENT_SEARCH_ON_SERVER: {
+ int i = 0;
+ int search_filter_count = event_data->event_param_data_5;
+ email_search_filter_t *search_filter = (email_search_filter_t *)event_data->event_param_data_1;
+
+ if (event_data->event_param_data_1) {
+ for(i = 0; i < search_filter_count; i++) {
+ switch(search_filter[i].search_filter_type) {
+ case EMAIL_SEARCH_FILTER_TYPE_BCC :
+ case EMAIL_SEARCH_FILTER_TYPE_BODY :
+ case EMAIL_SEARCH_FILTER_TYPE_CC :
+ case EMAIL_SEARCH_FILTER_TYPE_FROM :
+ case EMAIL_SEARCH_FILTER_TYPE_KEYWORD :
+ case EMAIL_SEARCH_FILTER_TYPE_TEXT :
+ case EMAIL_SEARCH_FILTER_TYPE_SUBJECT :
+ case EMAIL_SEARCH_FILTER_TYPE_TO :
+ case EMAIL_SEARCH_FILTER_TYPE_MESSAGE_ID :
+ case EMAIL_SEARCH_FILTER_TYPE_ATTACHMENT_NAME :
+ case EMAIL_SEARCH_FILTER_TYPE_CHARSET :
+ case EMAIL_SEARCH_FILTER_TYPE_USER_DEFINED :
+ EM_SAFE_FREE(search_filter[i].search_filter_key_value.string_type_key_value);
+ break;
+ default:
+ break;
+ }
+ }
+ }
+ }
+ EM_SAFE_FREE(event_data->event_param_data_1);
+ break;
+
case EMAIL_EVENT_RENAME_MAILBOX_ON_IMAP_SERVER:
EM_SAFE_FREE(event_data->event_param_data_1);
EM_SAFE_FREE(event_data->event_param_data_2);
@@ -1488,6 +1540,7 @@ INTERNAL_FUNC int emcore_free_event(email_event_t *event_data)
EM_DEBUG_EXCEPTION("event %d is NOT freed, possibly memory leaks", event_data->type);
}
+ EM_SAFE_FREE(event_data->multi_user_name);
event_data->event_param_data_1 = event_data->event_param_data_2 = event_data->event_param_data_3 = NULL;
EM_DEBUG_FUNC_END();
@@ -1776,7 +1829,7 @@ static int emcore_copy_partial_body_thd_event(email_event_partial_body_thd *src,
dest->mailbox_name = EM_SAFE_STRDUP(src->mailbox_name);
dest->activity_type = src->activity_type;
dest->event_type = src->event_type;
-
+ dest->multi_user_name = EM_SAFE_STRDUP(src->multi_user_name);
ret = true;
@@ -1816,6 +1869,7 @@ INTERNAL_FUNC int emcore_free_partial_body_thd_event(email_event_partial_body_th
/*Free character pointers in event_data cell */
EM_SAFE_FREE(pbd_event->mailbox_name);
+ EM_SAFE_FREE(pbd_event->multi_user_name);
memset(pbd_event, 0x00, sizeof(email_event_partial_body_thd));
EM_DEBUG_FUNC_END();
return true;
@@ -1951,7 +2005,7 @@ INTERNAL_FUNC int emcore_retrieve_partial_body_thread_event(email_event_partial_
}
/*Function to flush the bulk partial body download queue [santosh.br@samsung.com]*/
-static int emcore_partial_body_bulk_flush(int *error_code)
+static int emcore_partial_body_bulk_flush(char *multi_user_name, int *error_code)
{
EM_DEBUG_FUNC_BEGIN();
int error = EMAIL_ERROR_NONE;
@@ -1959,7 +2013,7 @@ static int emcore_partial_body_bulk_flush(int *error_code)
MAILSTREAM *stream = NULL;
void *tmp_stream = NULL;
- if (!emcore_connect_to_remote_mailbox(g_partial_body_bulk_dwd_que[0].account_id, g_partial_body_bulk_dwd_que[0].mailbox_id, (void **)&tmp_stream, &error) || (NULL == tmp_stream)) {
+ if (!emcore_connect_to_remote_mailbox(multi_user_name, g_partial_body_bulk_dwd_que[0].account_id, g_partial_body_bulk_dwd_que[0].mailbox_id, (void **)&tmp_stream, &error) || (NULL == tmp_stream)) {
EM_DEBUG_EXCEPTION("emcore_connect_to_remote_mailbox failed [%d]", error);
goto FINISH_OFF;
}
@@ -2020,7 +2074,7 @@ INTERNAL_FUNC int emcore_mail_partial_body_download (email_event_partial_body_th
EM_DEBUG_LOG("Event is for the same mailbox and same account as the already present events in download que");
EM_DEBUG_LOG("Check if the download que reached its limit. If yes then first flush the que.");
if (g_partial_body_bulk_dwd_next_event_idx == BULK_PARTIAL_BODY_DOWNLOAD_COUNT) {
- if (false == emcore_partial_body_bulk_flush(&error)) {
+ if (false == emcore_partial_body_bulk_flush(pbd_event->multi_user_name, &error)) {
EM_DEBUG_EXCEPTION("Partial Body thread emcore_partial_body_bulk_flush failed - %d", error);
goto FINISH_OFF;
}
@@ -2031,7 +2085,7 @@ INTERNAL_FUNC int emcore_mail_partial_body_download (email_event_partial_body_th
EM_DEBUG_LOG("Flush the current que if not empty");
EM_DEBUG_LOG("g_partial_body_bulk_dwd_queue_empty [%d]", g_partial_body_bulk_dwd_queue_empty);
if (!g_partial_body_bulk_dwd_queue_empty) {
- if (false == emcore_partial_body_bulk_flush(&error)) {
+ if (false == emcore_partial_body_bulk_flush(pbd_event->multi_user_name, &error)) {
EM_DEBUG_EXCEPTION("Partial Body thread emcore_partial_body_bulk_flush failed - %d", error);
goto FINISH_OFF;
}
@@ -2053,7 +2107,7 @@ INTERNAL_FUNC int emcore_mail_partial_body_download (email_event_partial_body_th
EM_DEBUG_LOG("Event is coming from local activity.");
/* Get all the accounts for which local activities are pending */
- if (false == emstorage_get_pbd_account_list(&account_list, &account_count, false, &error)) {
+ if (false == emstorage_get_pbd_account_list(pbd_event->multi_user_name, &account_list, &account_count, false, &error)) {
EM_DEBUG_EXCEPTION(" emstorage_get_mailbox_list failed.. [%d]", error);
error = EMAIL_ERROR_MAILBOX_NOT_FOUND;
goto FINISH_OFF;
@@ -2061,7 +2115,7 @@ INTERNAL_FUNC int emcore_mail_partial_body_download (email_event_partial_body_th
for (m = 0; m < account_count; ++m) {
/* Get the mailbox list for the account to start bulk partial body fetch for mails in each mailbox of accounts one by one*/
- if (false == emstorage_get_pbd_mailbox_list(account_list[m], &mailbox_list, &count, false, &error)) {
+ if (false == emstorage_get_pbd_mailbox_list(pbd_event->multi_user_name, account_list[m], &mailbox_list, &count, false, &error)) {
EM_DEBUG_EXCEPTION(" emstorage_get_mailbox_list failed.. [%d]", error);
error = EMAIL_ERROR_MAILBOX_NOT_FOUND;
goto FINISH_OFF;
@@ -2071,17 +2125,17 @@ INTERNAL_FUNC int emcore_mail_partial_body_download (email_event_partial_body_th
int k = 0;
int activity_count = 0;
- if (!emcore_connect_to_remote_mailbox(account_list[m], mailbox_list[i], (void **)&stream, &error)) {
+ if (!emcore_connect_to_remote_mailbox(pbd_event->multi_user_name, account_list[m], mailbox_list[i], (void **)&stream, &error)) {
EM_DEBUG_EXCEPTION("emcore_connect_to_remote_mailbox failed [%d]", error);
stream = mail_close (stream);
goto FINISH_OFF;
}
- if (false == emstorage_get_pbd_activity_data(account_list[m], mailbox_list[i], &activity_data_list, &activity_count, false, &error))
+ if (false == emstorage_get_pbd_activity_data(pbd_event->multi_user_name, account_list[m], mailbox_list[i], &activity_data_list, &activity_count, false, &error))
EM_DEBUG_EXCEPTION(" emstorage_get_pbd_activity_data failed.. [%d]", error);
/* it is duplicated with emstorage_get_pbd_activity_data
- if (false == emstorage_get_mailbox_pbd_activity_count(account_list[m], mailbox_list[i], &activity_count, false, &error)) {
+ if (false == emstorage_get_mailbox_pbd_activity_count(pbd_evnet->multi_user_name, account_list[m], mailbox_list[i], &activity_count, false, &error)) {
EM_DEBUG_EXCEPTION(" emstorage_get_mailbox_pbd_activity_count failed.. [%d]", error);
continue;
}
@@ -2095,7 +2149,7 @@ INTERNAL_FUNC int emcore_mail_partial_body_download (email_event_partial_body_th
int index = 0;
/*
- if (false == emstorage_get_pbd_activity_data(account_list[j], mailbox_list[i], &activity_data_list, &num_activity, false, &error))
+ if (false == emstorage_get_pbd_activity_data(pbd_event->multi_user_name, account_list[j], mailbox_list[i], &activity_data_list, &num_activity, false, &error))
EM_DEBUG_EXCEPTION(" emstorage_get_pbd_activity_data failed.. [%d]", error);
if (NULL == activity_data_list) {
@@ -2126,6 +2180,7 @@ INTERNAL_FUNC int emcore_mail_partial_body_download (email_event_partial_body_th
for (k = 0; k < activity_count; k++)
emcore_free_partial_body_thd_event(activity_data_list + k, &error);
+
EM_SAFE_FREE(activity_data_list);
/*check: empty check required?*/
@@ -2150,7 +2205,8 @@ INTERNAL_FUNC int emcore_mail_partial_body_download (email_event_partial_body_th
ret = true;
goto FINISH_OFF; /* Stop Local Activity Sync */
}
- if (false == emcore_partial_body_bulk_flush(&error)) {
+
+ if (false == emcore_partial_body_bulk_flush(pbd_event->multi_user_name, &error)) {
EM_DEBUG_EXCEPTION("\t Partial Body thread emcore_partial_body_bulk_flush failed - %d", error);
goto FINISH_OFF;
}
diff --git a/email-core/email-core-gmime.c b/email-core/email-core-gmime.c
index e4d885d..ebf2f97 100755
--- a/email-core/email-core-gmime.c
+++ b/email-core/email-core-gmime.c
@@ -63,6 +63,10 @@ INTERNAL_FUNC void emcore_gmime_init(void)
#endif
g_mime_init(0);
+#ifdef __FEATURE_SECURE_PGP__
+ setenv("GNUPGHOME", "/opt/usr/apps/org.tizen.email/data/.gnupg", 1);
+#endif
+
EM_DEBUG_FUNC_END();
}
@@ -172,7 +176,10 @@ INTERNAL_FUNC int emcore_gmime_pop3_parse_mime(char *eml_path, struct _m_content
}
-INTERNAL_FUNC int emcore_gmime_eml_parse_mime(char *eml_path, struct _rfc822header *rfc822_header, struct _m_content_info *cnt_info, int *err_code)
+INTERNAL_FUNC int emcore_gmime_eml_parse_mime(char *eml_path,
+ struct _rfc822header *rfc822_header,
+ struct _m_content_info *cnt_info,
+ int *err_code)
{
EM_DEBUG_FUNC_BEGIN("cnt_info[%p], err_code[%p]", cnt_info, err_code);
EM_DEBUG_LOG_SEC("eml_path[%s]", eml_path);
@@ -372,6 +379,9 @@ static void emcore_gmime_pop3_parse_foreach_cb(GMimeObject *parent, GMimeObject
EM_DEBUG_LOG("Multi Part Count:%d", multi_count);
EM_DEBUG_LOG("Boundary:%s\n\n", g_mime_multipart_get_boundary(multi_part));
+ if (GMIME_IS_MULTIPART_SIGNED(part))
+ cnt_info->text.mime_entity = emcore_gmime_get_mime_entity_signed_message(part);
+
} else if (GMIME_IS_PART(part)) {
EM_DEBUG_LOG("Part");
int content_size = 0;
@@ -482,44 +492,20 @@ static void emcore_gmime_pop3_parse_foreach_cb(GMimeObject *parent, GMimeObject
/*Figure out TEXT or ATTACHMENT(INLINE) ?*/
int result = false;
- if (disposition_str && g_ascii_strcasecmp(disposition_str, GMIME_DISPOSITION_ATTACHMENT) == 0) {
+ if (content_id && (emcore_search_string_from_file(cnt_info->text.html, content_id, NULL, &result) == EMAIL_ERROR_NONE && result)) {
+ content_disposition_type = INLINE_ATTACHMENT;
+ EM_DEBUG_LOG("INLINE_ATTACHMENT");
+ } else if ((disposition_str && g_ascii_strcasecmp(disposition_str, GMIME_DISPOSITION_ATTACHMENT) == 0) || disposition_filename || ctype_name) {
+ content_disposition_type = ATTACHMENT;
+ EM_DEBUG_LOG("ATTACHMENT");
+ } else if (ctype_subtype && g_ascii_strcasecmp(ctype_subtype, "delivery-status") == 0) {
+ content_disposition_type = ATTACHMENT;
+ EM_DEBUG_LOG("ATTACHMENT");
+ } else if (ctype_subtype && g_ascii_strcasecmp(ctype_subtype, "calendar") == 0) {
content_disposition_type = ATTACHMENT;
EM_DEBUG_LOG("ATTACHMENT");
- } else if ((content_id || content_location) && (ctype_name || disposition_filename)) {
- if (cnt_info->attachment_only) {
- content_disposition_type = ATTACHMENT;
- EM_DEBUG_LOG("ATTACHMENT");
- } else {
- content_disposition_type = INLINE_ATTACHMENT;
- EM_DEBUG_LOG("INLINE_ATTACHMENT");
- }
} else {
- if (content_id &&
- (emcore_search_string_from_file(cnt_info->text.html, content_id, NULL, &result) == EMAIL_ERROR_NONE && result)) {
- content_disposition_type = INLINE_ATTACHMENT;
- EM_DEBUG_LOG("INLINE_ATTACHMENT");
- } else if (content_id || content_location) {
- if (g_ascii_strcasecmp(ctype_type, "text") == 0 &&
- (g_ascii_strcasecmp(ctype_subtype, "plain") == 0 || g_ascii_strcasecmp(ctype_subtype, "html") == 0)) {
- EM_DEBUG_LOG("TEXT");
- } else {
- if (cnt_info->attachment_only) {
- content_disposition_type = ATTACHMENT;
- EM_DEBUG_LOG("ATTACHMENT");
- } else {
- content_disposition_type = INLINE_ATTACHMENT;
- EM_DEBUG_LOG("INLINE_ATTACHMENT");
- }
- }
- } else {
- if (g_ascii_strcasecmp(ctype_type, "text") == 0 &&
- (g_ascii_strcasecmp(ctype_subtype, "plain") == 0 || g_ascii_strcasecmp(ctype_subtype, "html") == 0)) {
- EM_DEBUG_LOG("TEXT");
- } else {
- content_disposition_type = ATTACHMENT;
- EM_DEBUG_LOG("ATTACHMENT");
- }
- }
+ EM_DEBUG_LOG("Not INLINE or ATTACHMENT");
}
if (content_disposition_type != ATTACHMENT && content_disposition_type != INLINE_ATTACHMENT) {
@@ -681,7 +667,6 @@ FINISH_OFF:
EM_DEBUG_FUNC_END();
}
-
static int emcore_gmime_parse_mime_header(GMimeMessage *message, struct _rfc822header *rfc822_header)
{
EM_DEBUG_FUNC_BEGIN("message[%p], rfc822header[%p]", message, rfc822_header);
@@ -696,7 +681,7 @@ static int emcore_gmime_parse_mime_header(GMimeMessage *message, struct _rfc822h
rfc822_header->reply_to = EM_SAFE_STRDUP(g_mime_message_get_reply_to(message));
EM_DEBUG_LOG_SEC("reply_to : [%s]", rfc822_header->reply_to);
- rfc822_header->date = g_mime_message_get_date_as_string(message); //PREVENT
+ rfc822_header->date = EM_SAFE_STRDUP(g_mime_message_get_date_as_string(message));
EM_DEBUG_LOG_SEC("date : [%s]", rfc822_header->date);
rfc822_header->subject = EM_SAFE_STRDUP(g_mime_message_get_subject(message));
@@ -794,8 +779,7 @@ static void emcore_gmime_eml_parse_foreach_cb(GMimeObject *parent, GMimeObject *
if (msg_disposition) {
msg_disposition_str = (char *)g_mime_content_disposition_get_disposition(msg_disposition);
msg_disposition_filename = (char *)g_mime_content_disposition_get_parameter(msg_disposition, "filename");
- if (EM_SAFE_STRLEN(msg_disposition_filename) == 0)
- msg_disposition_filename = NULL;
+ if (EM_SAFE_STRLEN(msg_disposition_filename) == 0) msg_disposition_filename = NULL;
}
EM_DEBUG_LOG("RFC822/Message Disposition[%s]", msg_disposition_str);
EM_DEBUG_LOG_SEC("RFC822/Message Disposition-Filename[%s]", msg_disposition_filename);
@@ -924,6 +908,9 @@ static void emcore_gmime_eml_parse_foreach_cb(GMimeObject *parent, GMimeObject *
EM_DEBUG_LOG("Multi Part Count:%d", multi_count);
EM_DEBUG_LOG("Boundary:%s\n\n", g_mime_multipart_get_boundary(multi_part));
+ if (GMIME_IS_MULTIPART_SIGNED(part))
+ cnt_info->text.mime_entity = emcore_gmime_get_mime_entity_signed_message(part);
+
} else if (GMIME_IS_PART(part)) {
EM_DEBUG_LOG("Part");
int content_size = 0;
@@ -1182,21 +1169,21 @@ static void emcore_gmime_eml_parse_foreach_cb(GMimeObject *parent, GMimeObject *
EM_DEBUG_EXCEPTION("emcore_get_content_from_file failed");
}
- EM_DEBUG_LOG_SEC("html_charset : [%s]", cnt_info->text.html_charset);
- if (strcasecmp(cnt_info->text.html_charset, "UTF-8") != 0) {
- cd = g_mime_iconv_open(cnt_info->text.html_charset, "UTF-8");
- if (cd) {
- encoding_file_name = g_mime_iconv_strdup(cd, file->name);
- }
+ EM_DEBUG_LOG_SEC("html_charset : [%s]", cnt_info->text.html_charset);
+ if (strcasecmp(cnt_info->text.html_charset, "UTF-8") != 0) {
+ cd = g_mime_iconv_open(cnt_info->text.html_charset, "UTF-8");
+ if (cd) {
+ encoding_file_name = g_mime_iconv_strdup(cd, file->name);
+ }
- if (cd)
- g_mime_iconv_close(cd);
+ if (cd)
+ g_mime_iconv_close(cd);
- } else {
- encoding_file_name = g_strdup(file->name);
- }
+ } else {
+ encoding_file_name = g_strdup(file->name);
+ }
- EM_DEBUG_LOG_SEC("File name : [%s], encoding file name : [%s]", file->name, encoding_file_name);
+ EM_DEBUG_LOG_SEC("File name : [%s], encoding file name : [%s]", file->name, encoding_file_name);
if (file_content && html_size > 0) {
em_replace_string_ex(&file_content, "cid:", "");
@@ -1209,7 +1196,7 @@ static void emcore_gmime_eml_parse_foreach_cb(GMimeObject *parent, GMimeObject *
}
g_free(file_content); /* prevent 39110 */
- g_free(encoding_file_name);
+ g_free(encoding_file_name);
}
if(ctype_type && ctype_subtype) {
@@ -1381,7 +1368,7 @@ INTERNAL_FUNC void emcore_gmime_imap_parse_foreach_cb(GMimeObject *parent, GMime
int multi_count = g_mime_multipart_get_count(multi_part);
EM_DEBUG_LOG("Multi Part Count:%d", multi_count);
- EM_DEBUG_LOG("Boundary:%s\n\n", g_mime_multipart_get_boundary(multi_part));
+ EM_DEBUG_LOG("Boundary:%s", g_mime_multipart_get_boundary(multi_part));
} else if (GMIME_IS_PART(part)) {
/* a normal leaf part, could be text/plain or
@@ -1451,14 +1438,16 @@ INTERNAL_FUNC void emcore_gmime_imap_parse_foreach_cb(GMimeObject *parent, GMime
/*Figure out TEXT or ATTACHMENT(INLINE) ?*/
int result = false;
if (disposition_str && g_ascii_strcasecmp(disposition_str, GMIME_DISPOSITION_ATTACHMENT) == 0) {
- if (content_id &&
- (emcore_search_string_from_file(cnt_info->text.html, content_id, NULL, &result) == EMAIL_ERROR_NONE && result)) {
+ if (content_id && (emcore_search_string_from_file(cnt_info->text.html,
+ content_id,
+ NULL,
+ &result) == EMAIL_ERROR_NONE && result)) {
content_disposition_type = INLINE_ATTACHMENT;
EM_DEBUG_LOG("INLINE_ATTACHMENT");
- } else {
- content_disposition_type = ATTACHMENT;
- EM_DEBUG_LOG("ATTACHMENT");
- }
+ } else {
+ content_disposition_type = ATTACHMENT;
+ EM_DEBUG_LOG("ATTACHMENT");
+ }
} else if ((content_id || content_location) && (ctype_name || disposition_filename)) {
if (cnt_info->attachment_only) {
content_disposition_type = ATTACHMENT;
@@ -1800,7 +1789,7 @@ INTERNAL_FUNC void emcore_gmime_imap_parse_full_foreach_cb(GMimeObject *parent,
char *msg_tmp_content_path = NULL;
int real_size = 0;
- if (cnt_info->grab_type != (GRAB_TYPE_TEXT|GRAB_TYPE_ATTACHMENT) &&
+ if (cnt_info->grab_type != (GRAB_TYPE_TEXT | GRAB_TYPE_ATTACHMENT) &&
cnt_info->grab_type != GRAB_TYPE_ATTACHMENT) {
goto FINISH_OFF;
}
@@ -1900,6 +1889,7 @@ INTERNAL_FUNC void emcore_gmime_imap_parse_full_foreach_cb(GMimeObject *parent,
int multi_count = g_mime_multipart_get_count(multi_part);
EM_DEBUG_LOG("Multi Part Count:%d", multi_count);
EM_DEBUG_LOG("Boundary:%s\n\n", g_mime_multipart_get_boundary(multi_part));
+
} else if (GMIME_IS_PART(part)) {
EM_DEBUG_LOG("Part");
int content_disposition_type = 0;
@@ -1968,8 +1958,10 @@ INTERNAL_FUNC void emcore_gmime_imap_parse_full_foreach_cb(GMimeObject *parent,
EM_DEBUG_LOG("INLINE_ATTACHMENT");
}
} else {
- if (content_id &&
- (emcore_search_string_from_file(cnt_info->text.html, content_id, NULL, &result) == EMAIL_ERROR_NONE && result)) {
+ if (content_id && (emcore_search_string_from_file(cnt_info->text.html,
+ content_id,
+ NULL,
+ &result) == EMAIL_ERROR_NONE && result)) {
content_disposition_type = INLINE_ATTACHMENT;
EM_DEBUG_LOG("INLINE_ATTACHMENT");
} else if (content_id || content_location) {
@@ -1986,8 +1978,9 @@ INTERNAL_FUNC void emcore_gmime_imap_parse_full_foreach_cb(GMimeObject *parent,
}
}
} else {
- if (g_ascii_strcasecmp(ctype_type, "text") == 0 &&
- (g_ascii_strcasecmp(ctype_subtype, "plain") == 0 || g_ascii_strcasecmp(ctype_subtype, "html") == 0)) {
+ if (g_ascii_strcasecmp(ctype_type, "text") == 0 &&
+ (g_ascii_strcasecmp(ctype_subtype, "plain") == 0 ||
+ g_ascii_strcasecmp(ctype_subtype, "html") == 0)) {
EM_DEBUG_LOG("TEXT");
} else {
content_disposition_type = ATTACHMENT;
@@ -2343,6 +2336,8 @@ INTERNAL_FUNC void emcore_gmime_imap_parse_bodystructure_foreach_cb(GMimeObject
} else if (GMIME_IS_MESSAGE_PARTIAL(part)) {
EM_DEBUG_LOG("Partial Part");
//TODO
+ } else if (GMIME_IS_MULTIPART_SIGNED(part)) {
+ EM_DEBUG_LOG("Multi Part Signed");
} else if (GMIME_IS_MULTIPART(part)) {
EM_DEBUG_LOG("Multi Part");
GMimeMultipart *multi_part = NULL;
@@ -2426,7 +2421,8 @@ INTERNAL_FUNC void emcore_gmime_imap_parse_bodystructure_foreach_cb(GMimeObject
} else {
if (content_id || content_location) {
if (g_ascii_strcasecmp(ctype_type, "text") == 0 &&
- (g_ascii_strcasecmp(ctype_subtype, "plain") == 0 || g_ascii_strcasecmp(ctype_subtype, "html") == 0)) {
+ (g_ascii_strcasecmp(ctype_subtype, "plain") == 0 ||
+ g_ascii_strcasecmp(ctype_subtype, "html") == 0)) {
cnt_info->total_body_size += content_size;
EM_DEBUG_LOG("TEXT");
} else {
@@ -2442,7 +2438,8 @@ INTERNAL_FUNC void emcore_gmime_imap_parse_bodystructure_foreach_cb(GMimeObject
}
} else {
if (g_ascii_strcasecmp(ctype_type, "text") == 0 &&
- (g_ascii_strcasecmp(ctype_subtype, "plain") == 0 || g_ascii_strcasecmp(ctype_subtype, "html") == 0)) {
+ (g_ascii_strcasecmp(ctype_subtype, "plain") == 0 ||
+ g_ascii_strcasecmp(ctype_subtype, "html") == 0)) {
cnt_info->total_body_size += content_size;
EM_DEBUG_LOG("TEXT");
} else {
@@ -2490,7 +2487,9 @@ FINISH_OFF:
}
-INTERNAL_FUNC void emcore_gmime_get_body_sections_foreach_cb(GMimeObject *parent, GMimeObject *part, gpointer user_data)
+INTERNAL_FUNC void emcore_gmime_get_body_sections_foreach_cb(GMimeObject *parent,
+ GMimeObject *part,
+ gpointer user_data)
{
EM_DEBUG_FUNC_BEGIN("parent[%p], part[%p], user_data[%p]", parent, part, user_data);
@@ -2558,6 +2557,14 @@ INTERNAL_FUNC void emcore_gmime_get_body_sections_foreach_cb(GMimeObject *parent
EM_DEBUG_LOG("sections <%s>", cnt_info->sections);
} else if (GMIME_IS_MESSAGE_PARTIAL(part)) {
EM_DEBUG_LOG("Partial Part");
+ } else if (GMIME_IS_MULTIPART_SIGNED(part)) {
+ EM_DEBUG_LOG("Multi Part Signed");
+ snprintf(sections, sizeof(sections), "BODY.PEEK[1.mime] BODY.PEEK[1]");
+
+ cnt_info->content_type = 1;
+ cnt_info->sections = EM_SAFE_STRDUP(sections);
+
+ EM_DEBUG_LOG("sections <%s>", cnt_info->sections);
} else if (GMIME_IS_MULTIPART(part)) {
EM_DEBUG_LOG("Multi Part");
} else if (GMIME_IS_PART(part)) {
@@ -2593,7 +2600,7 @@ INTERNAL_FUNC void emcore_gmime_get_body_sections_foreach_cb(GMimeObject *parent
goto FINISH_OFF;
}
/*Content Type - END*/
-
+
/*Content Disposition*/
disposition = g_mime_object_get_content_disposition(mobject);
if (disposition) {
@@ -2628,7 +2635,8 @@ INTERNAL_FUNC void emcore_gmime_get_body_sections_foreach_cb(GMimeObject *parent
} else {
if (content_id || content_location) {
if (g_ascii_strcasecmp(ctype_type, "text") == 0 &&
- (g_ascii_strcasecmp(ctype_subtype, "plain") == 0 || g_ascii_strcasecmp(ctype_subtype, "html") == 0)) {
+ (g_ascii_strcasecmp(ctype_subtype, "plain") == 0 ||
+ g_ascii_strcasecmp(ctype_subtype, "html") == 0)) {
EM_DEBUG_LOG("TEXT");
} else {
if (cnt_info->attachment_only) {
@@ -2641,7 +2649,8 @@ INTERNAL_FUNC void emcore_gmime_get_body_sections_foreach_cb(GMimeObject *parent
}
} else {
if (g_ascii_strcasecmp(ctype_type, "text") == 0 &&
- (g_ascii_strcasecmp(ctype_subtype, "plain") == 0 || g_ascii_strcasecmp(ctype_subtype, "html") == 0)) {
+ (g_ascii_strcasecmp(ctype_subtype, "plain") == 0 ||
+ g_ascii_strcasecmp(ctype_subtype, "html") == 0)) {
EM_DEBUG_LOG("TEXT");
} else {
content_disposition_type = ATTACHMENT;
@@ -2658,8 +2667,13 @@ INTERNAL_FUNC void emcore_gmime_get_body_sections_foreach_cb(GMimeObject *parent
}
else {
snprintf(sections, sizeof(sections), "BODY.PEEK[%s.MIME] BODY.PEEK[%s]", ctype_section, ctype_section);
-
+
if (cnt_info->sections) {
+ /* Signed message : Did not need sections */
+ if (cnt_info->content_type == 1) {
+ goto FINISH_OFF;
+ }
+
char *tmp_str = NULL;
tmp_str = g_strconcat(cnt_info->sections, " ", sections, NULL);
@@ -2682,7 +2696,9 @@ FINISH_OFF:
}
-INTERNAL_FUNC void emcore_gmime_get_attachment_section_foreach_cb(GMimeObject *parent, GMimeObject *part, gpointer user_data)
+INTERNAL_FUNC void emcore_gmime_get_attachment_section_foreach_cb(GMimeObject *parent,
+ GMimeObject *part,
+ gpointer user_data)
{
EM_DEBUG_FUNC_BEGIN("parent[%p], part[%p], user_data[%p]", parent, part, user_data);
@@ -2819,7 +2835,8 @@ INTERNAL_FUNC void emcore_gmime_get_attachment_section_foreach_cb(GMimeObject *p
} else {
if (content_id || content_location) {
if (g_ascii_strcasecmp(ctype_type, "text") == 0 &&
- (g_ascii_strcasecmp(ctype_subtype, "plain") == 0 || g_ascii_strcasecmp(ctype_subtype, "html") == 0)) {
+ (g_ascii_strcasecmp(ctype_subtype, "plain") == 0 ||
+ g_ascii_strcasecmp(ctype_subtype, "html") == 0)) {
EM_DEBUG_LOG("TEXT");
} else {
if (cnt_info->attachment_only) {
@@ -2832,7 +2849,8 @@ INTERNAL_FUNC void emcore_gmime_get_attachment_section_foreach_cb(GMimeObject *p
}
} else {
if (g_ascii_strcasecmp(ctype_type, "text") == 0 &&
- (g_ascii_strcasecmp(ctype_subtype, "plain") == 0 || g_ascii_strcasecmp(ctype_subtype, "html") == 0)) {
+ (g_ascii_strcasecmp(ctype_subtype, "plain") == 0 ||
+ g_ascii_strcasecmp(ctype_subtype, "html") == 0)) {
EM_DEBUG_LOG("TEXT");
} else {
content_disposition_type = ATTACHMENT;
@@ -2868,7 +2886,7 @@ INTERNAL_FUNC void emcore_gmime_search_section_foreach_cb(GMimeObject *parent, G
search_section *search_info = (search_section *)user_data;
GMimeContentType *ctype = NULL;
- char buf[255] = {0};
+ char buf[255] = {0};
char *ctype_section = NULL;
if (!search_info) {
@@ -2900,23 +2918,47 @@ INTERNAL_FUNC void emcore_gmime_search_section_foreach_cb(GMimeObject *parent, G
goto FINISH_OFF;
}
- SNPRINTF(buf, sizeof(buf), "%s.MIME", ctype_section);
+ SNPRINTF(buf, sizeof(buf), "%s.MIME", ctype_section);
if (g_ascii_strcasecmp(ctype_section, search_info->section) == 0) {
EM_DEBUG_LOG("found section");
if (!(search_info->section_object)) search_info->section_object = part;
- } else if (g_ascii_strcasecmp(search_info->section, buf) == 0) {
- EM_DEBUG_LOG("Mime header");
- if (!(search_info->section_object)) search_info->section_object = part;
- }
+ } else if (g_ascii_strcasecmp(search_info->section, buf) == 0) {
+ EM_DEBUG_LOG("Mime header");
+ if (!(search_info->section_object)) search_info->section_object = part;
+ }
FINISH_OFF:
EM_DEBUG_FUNC_END();
}
+INTERNAL_FUNC void emcore_gmime_get_mime_entity_cb(GMimeObject *parent, GMimeObject *part, gpointer user_data)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ struct _m_content_info *cnt_info = (struct _m_content_info *)user_data;
+
+ if (GMIME_IS_MESSAGE_PART(part)) {
+ EM_DEBUG_LOG("Message Part");
+ } else if (GMIME_IS_MESSAGE_PARTIAL(part)) {
+ EM_DEBUG_LOG("Partial Part");
+ } else if (GMIME_IS_MULTIPART_SIGNED(part)) {
+ EM_DEBUG_LOG("Multi Part Signed");
+ cnt_info->text.mime_entity = emcore_gmime_get_mime_entity_signed_message(part);
+ } else if (GMIME_IS_MULTIPART(part)) {
+ EM_DEBUG_LOG("Multi Part");
+ } else if (GMIME_IS_PART(part)) {
+ EM_DEBUG_LOG("Part");
+ }
+
+ EM_DEBUG_FUNC_END();
+}
+
INTERNAL_FUNC void emcore_gmime_construct_multipart (GMimeMultipart *multipart,
- BODY *body, const char *spec, int *total_mail_size)
+ BODY *body,
+ const char *spec,
+ int *total_mail_size)
{
EM_DEBUG_FUNC_BEGIN();
PART *part = NULL;
@@ -2959,8 +3001,8 @@ INTERNAL_FUNC void emcore_gmime_construct_multipart (GMimeMultipart *multipart,
if (EM_SAFE_STRLEN(subspec) > 2)
section = EM_SAFE_STRDUP(subspec+2);
- EM_DEBUG_LOG("constructing a %s/%s part (%s/%s)", body_types[part->body.type],
- part->body.subtype, subspec, section);
+ EM_DEBUG_LOG("constructing a %s/%s part (%s/%s)", body_types[part->body.type], part->body.subtype,
+ subspec, section);
if (part->body.type == TYPEMULTIPART) {
/*multipart*/
@@ -3069,7 +3111,7 @@ INTERNAL_FUNC void emcore_gmime_construct_multipart (GMimeMultipart *multipart,
if (part->body.parameter) {
PARAMETER *param = part->body.parameter;
while(param) {
- EM_DEBUG_LOG_SEC("Content-Type Parameter: attribute[%s], value[%s]", param->attribute, param->value);
+ EM_DEBUG_LOG("Content-Type Parameter: attribute[%s], value[%s]", param->attribute, param->value);
if (param->attribute || param->value)
g_mime_object_set_content_type_parameter(subpart, param->attribute, param->value);
param = param->next;
@@ -3130,7 +3172,9 @@ INTERNAL_FUNC void emcore_gmime_construct_multipart (GMimeMultipart *multipart,
}
INTERNAL_FUNC void emcore_gmime_construct_part (GMimePart *part,
- BODY *body, const char *spec, int *total_mail_size)
+ BODY *body,
+ const char *spec,
+ int *total_mail_size)
{
EM_DEBUG_FUNC_BEGIN();
GMimeObject *part_object = NULL;
@@ -3155,8 +3199,8 @@ INTERNAL_FUNC void emcore_gmime_construct_part (GMimePart *part,
ctype_subtype = (char *)g_mime_content_type_get_media_subtype(ctype);
/* Type-Subtype */
- if (g_strcmp0(ctype_type, "text") == 0 && g_strcmp0(ctype_subtype, "plain") == 0 &&
- body->type >= (unsigned int)0 && body->subtype) {
+ if (g_strcmp0(ctype_type, "text") == 0 && g_strcmp0(ctype_subtype, "plain") == 0
+ && body->subtype) {
GMimeContentType *content_type = NULL;
char *type = g_ascii_strdown(body_types[body->type], -1);
char *subtype = g_ascii_strdown(body->subtype, -1);
@@ -3268,18 +3312,20 @@ INTERNAL_FUNC void emcore_gmime_construct_part (GMimePart *part,
EM_DEBUG_LOG("Content-ID: %s", body->id);
int i = 0;
char *cid = EM_SAFE_STRDUP(body->id);
- if (cid) g_strstrip(cid);
+ if (cid) {
+ g_strstrip(cid);
- while (strlen(cid) > 0 && cid[i] != '\0') {
- if (cid[i] == '<' || cid[i] == '>')
- cid[i] = ' ';
- i++;
- }
+ while (strlen(cid) > 0 && cid[i] != '\0') {
+ if (cid[i] == '<' || cid[i] == '>')
+ cid[i] = ' ';
+ i++;
+ }
- g_strstrip(cid);
- EM_DEBUG_LOG_DEV("Content-ID stripped: %s", cid);
- g_mime_object_set_content_id(part_object, cid);
- EM_SAFE_FREE(cid);
+ g_strstrip(cid);
+ EM_DEBUG_LOG_DEV("Content-ID stripped: %s", cid);
+ g_mime_object_set_content_id(part_object, cid);
+ free(cid);
+ }
}
EM_DEBUG_FUNC_END();
@@ -3311,7 +3357,6 @@ INTERNAL_FUNC int emcore_gmime_construct_mime_part_with_bodystructure(BODY *mbod
if (mbody->parameter) {
PARAMETER *param = mbody->parameter;
while(param) {
- EM_DEBUG_LOG("Content-Type Parameter: attribute[%s], value[%s]", param->attribute, param->value);
if (g_ascii_strcasecmp(param->attribute, "boundary") == 0 && param->value)
boundary_ok = 1;
param = param->next;
@@ -3324,13 +3369,28 @@ INTERNAL_FUNC int emcore_gmime_construct_mime_part_with_bodystructure(BODY *mbod
}
char *subtype = g_ascii_strdown(mbody->subtype, -1);
- multipart = g_mime_multipart_new_with_subtype(subtype);
+ EM_DEBUG_LOG("Constructing a MULTIPART/%s", subtype);
+ if (g_ascii_strcasecmp(subtype, "signed") == 0) {
+ multipart = (GMimeMultipart *)g_mime_multipart_signed_new();
+ } else {
+ multipart = g_mime_multipart_new_with_subtype(subtype);
+ }
/* Fill up mime part of message1 using bodystructure info */
emcore_gmime_construct_multipart(multipart, mbody, spec, &total_size);
mime_part = GMIME_OBJECT(multipart);
EM_SAFE_FREE(subtype);
+
+ if (mbody->parameter) {
+ PARAMETER *param = mbody->parameter;
+ while(param) {
+ EM_DEBUG_LOG("Content-Type Parameter: attribute[%s], value[%s]", param->attribute, param->value);
+ if (param->attribute || param->value)
+ g_mime_object_set_content_type_parameter(mime_part, param->attribute, param->value);
+ param = param->next;
+ }
+ }
}
else {
char *type = g_ascii_strdown(body_types[mbody->type], -1);
@@ -3363,7 +3423,8 @@ FINISH_OFF:
}
INTERNAL_FUNC int emcore_gmime_get_body_sections_from_message(GMimeMessage *message,
- struct _m_content_info *cnt_info, char **sections_to_fetch)
+ struct _m_content_info *cnt_info,
+ char **sections_to_fetch)
{
EM_DEBUG_FUNC_BEGIN();
@@ -3461,7 +3522,9 @@ FINISH_OFF:
}
INTERNAL_FUNC int emcore_gmime_get_attachment_section_from_message(GMimeMessage *message,
- struct _m_content_info *cnt_info, int nth, char **section_to_fetch)
+ struct _m_content_info *cnt_info,
+ int nth,
+ char **section_to_fetch)
{
EM_DEBUG_FUNC_BEGIN();
@@ -3597,7 +3660,9 @@ static int emcore_gmime_get_section_n_bodysize(char *response, char *section, in
}
INTERNAL_FUNC int emcore_gmime_fetch_imap_body_sections(MAILSTREAM *stream, int msg_uid, int mail_id,
- struct _m_content_info *cnt_info, GMimeMessage *message, int event_handle, int auto_download, int *err_code)
+ struct _m_content_info *cnt_info,
+ GMimeMessage *message, int event_handle,
+ int auto_download, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("stream[%p], msg_uid[%d], cnt_info[%p], err_code[%p]",
stream, msg_uid, cnt_info, err_code);
@@ -3624,13 +3689,20 @@ INTERNAL_FUNC int emcore_gmime_fetch_imap_body_sections(MAILSTREAM *stream, int
int flag_first_write = 1;
char *tag_position = NULL;
- int part_header = 0;
+ int part_header = 0;
+ int signed_message = 0;
int download_interval = 0;
int download_total_size = 0;
int downloaded_size = 0;
int download_progress = 0;
int last_notified_download_size = 0;
+ char *full_text = NULL;
+ char *body_string = NULL;
+ char *header_string = NULL;
+ GMimeObject *entity_part = NULL;
+ GMimeParser *entity_parser = NULL;
+
GMimeDataWrapper *content = NULL;
GMimeStream *content_stream = NULL;
GMimeObject *mime_object = NULL;
@@ -3648,8 +3720,9 @@ INTERNAL_FUNC int emcore_gmime_fetch_imap_body_sections(MAILSTREAM *stream, int
}
if (!cnt_info || !cnt_info->sections) {
- EM_DEBUG_EXCEPTION("invalid parameter detected...");
- err = EMAIL_ERROR_INVALID_PARAM;
+ EM_DEBUG_LOG("invalid parameter detected...");
+ /* Encrypted message did not have a text body So did not have a body section */
+ ret = TRUE;
goto FINISH_OFF;
}
@@ -3664,6 +3737,11 @@ INTERNAL_FUNC int emcore_gmime_fetch_imap_body_sections(MAILSTREAM *stream, int
goto FINISH_OFF;
}
+ if (GMIME_IS_MULTIPART_SIGNED(message->mime_part)) {
+ EM_DEBUG_LOG("Multi Part Signed");
+ signed_message = 1;
+ }
+
while (imaplocal->netstream) {
/* receive response */
@@ -3686,13 +3764,13 @@ INTERNAL_FUNC int emcore_gmime_fetch_imap_body_sections(MAILSTREAM *stream, int
server_response_yn = 1;
}
- part_header = 0;
+ part_header = 0;
flag_first_write = 1;
total = 0;
memset(encoded, 0x00, sizeof(encoded));
if (!emcore_gmime_get_section_n_bodysize(response, section, &body_size)) {
- EM_DEBUG_EXCEPTION("emcore_get_section_body_size failed [%d]", err);
+ EM_DEBUG_EXCEPTION("emcore_gmime_get_section_body_size failed [%d]", err);
err = EMAIL_ERROR_INVALID_RESPONSE;
goto FINISH_OFF;
}
@@ -3751,26 +3829,30 @@ INTERNAL_FUNC int emcore_gmime_fetch_imap_body_sections(MAILSTREAM *stream, int
mime_part = NULL;
mime_object = search_info->section_object;
if (GMIME_IS_MESSAGE_PART(mime_object)) {
- if (strcasestr(section, "MIME"))
- part_header = 1;
+ if (strcasestr(section, "MIME"))
+ part_header = 1;
- mime_message_part = GMIME_MESSAGE_PART(mime_object);
+ mime_message_part = GMIME_MESSAGE_PART(mime_object);
} else if (GMIME_IS_PART(mime_object)) {
- if (strcasestr(section, "MIME"))
- part_header = 1;
+ if (strcasestr(section, "MIME"))
+ part_header = 1;
mime_part = GMIME_PART(mime_object);
+ } else if (signed_message) {
+ if (strcasestr(section, "MIME"))
+ part_header = 1;
} else {
EM_DEBUG_EXCEPTION("invalid mime part type");
goto FINISH_OFF;
}
-
+
if (!part_header) {
if (!emcore_get_temp_file_name(&buf, &err) || !buf) {
EM_DEBUG_EXCEPTION("emcore_get_temp_file_name failed [%d]", err);
goto FINISH_OFF;
}
+ EM_DEBUG_LOG("TMP name : [%s]", buf);
g_mime_object_set_content_type_parameter(mime_object, "tmp_content_path", buf);
if (event_handle > 0)
@@ -3780,7 +3862,11 @@ INTERNAL_FUNC int emcore_gmime_fetch_imap_body_sections(MAILSTREAM *stream, int
if (cnt_info->total_body_size > body_size) {
EM_DEBUG_LOG("Multipart body size is [%d]", cnt_info->total_body_size);
if (!auto_download) {
- if (!emcore_notify_network_event(NOTI_DOWNLOAD_MULTIPART_BODY, mail_id, buf, cnt_info->total_body_size, 0))
+ if (!emcore_notify_network_event(NOTI_DOWNLOAD_MULTIPART_BODY,
+ mail_id,
+ buf,
+ cnt_info->total_body_size,
+ 0))
EM_DEBUG_EXCEPTION(" emcore_notify_network_event [ NOTI_DOWNLOAD_BODY_START] Failed >>>> ");
}
@@ -3800,7 +3886,11 @@ INTERNAL_FUNC int emcore_gmime_fetch_imap_body_sections(MAILSTREAM *stream, int
if (cnt_info->grab_type == (GRAB_TYPE_TEXT | GRAB_TYPE_ATTACHMENT)) {
if (!auto_download) {
- if (!emcore_notify_network_event(NOTI_DOWNLOAD_MULTIPART_BODY, mail_id, buf, cnt_info->total_mail_size, 0))
+ if (!emcore_notify_network_event(NOTI_DOWNLOAD_MULTIPART_BODY,
+ mail_id,
+ buf,
+ cnt_info->total_mail_size,
+ 0))
EM_DEBUG_EXCEPTION(" emcore_notify_network_event [ NOTI_DOWNLOAD_BODY_START] Failed >>>> ");
}
@@ -3819,8 +3909,18 @@ INTERNAL_FUNC int emcore_gmime_fetch_imap_body_sections(MAILSTREAM *stream, int
goto FINISH_OFF;
}
- if (GMIME_IS_PART(mime_object) && mime_part) {
- content_stream = g_mime_stream_mem_new_with_buffer((const char *)encoded, EM_SAFE_STRLEN(encoded));
+ if (signed_message) {
+ content_stream = g_mime_stream_mem_new_with_buffer((const char *)encoded,
+ EM_SAFE_STRLEN(encoded));
+ entity_parser = g_mime_parser_new_with_stream(content_stream);
+ if (content_stream) g_object_unref(content_stream);
+
+ entity_part = g_mime_parser_construct_part(entity_parser);
+ if (entity_parser) g_object_unref(entity_parser);
+ }
+ else if (GMIME_IS_PART(mime_object) && mime_part) {
+ content_stream = g_mime_stream_mem_new_with_buffer((const char *)encoded,
+ EM_SAFE_STRLEN(encoded));
//parser = g_mime_parser_new_with_stream(content_stream);
content = g_mime_data_wrapper_new_with_stream(content_stream, mime_part->encoding);
if (content_stream) g_object_unref (content_stream);
@@ -3983,7 +4083,22 @@ INTERNAL_FUNC int emcore_gmime_fetch_imap_body_sections(MAILSTREAM *stream, int
EM_DEBUG_LOG("%d has been written", EM_SAFE_STRLEN((char *)test_buffer));
}
- if (GMIME_IS_PART(mime_object) && mime_part) {
+ if (signed_message) {
+ err = em_open(buf, O_RDONLY, 0, &fd);
+ if (err != EMAIL_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("holder open failed : holder is a filename that will be saved.");
+ goto FINISH_OFF;
+ }
+
+ content_stream = g_mime_stream_fs_new(fd);
+
+ entity_parser = g_mime_parser_new_with_stream(content_stream);
+ if (content_stream) g_object_unref(content_stream);
+
+ entity_part = g_mime_parser_construct_part(entity_parser);
+ if (entity_parser) g_object_unref(entity_parser);
+ }
+ else if (GMIME_IS_PART(mime_object) && mime_part) {
err = em_open(buf, O_RDONLY, 0, &fd);
if (err != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("holder open failed : holder is a filename that will be saved.");
@@ -3996,54 +4111,58 @@ INTERNAL_FUNC int emcore_gmime_fetch_imap_body_sections(MAILSTREAM *stream, int
if (content_stream) g_object_unref (content_stream);
g_mime_part_set_content_object(mime_part, content);
if (content) g_object_unref(content);
- }
+ }
}
} else {
- EM_DEBUG_LOG("MIME header");
-
- char *file_name = NULL;
-
- GMimeObject *object_header = NULL;
- GMimeParser *parser_header = NULL;
- GMimeContentType *ctype_header = NULL;
- GMimeContentDisposition *disposition_header = NULL;
-
- if (net_getbuffer(imaplocal->netstream, (long)body_size, (char *)encoded) <= 0) {
- EM_DEBUG_EXCEPTION("net_getbuffer failed...");
- err = EMAIL_ERROR_NO_RESPONSE;
- goto FINISH_OFF;
- }
-
- EM_DEBUG_LOG_DEV("Data : [%s]", encoded);
+ EM_DEBUG_LOG("MIME header");
- content_stream = g_mime_stream_mem_new_with_buffer((const char *)encoded, EM_SAFE_STRLEN(encoded));
+ char *file_name = NULL;
- parser_header = g_mime_parser_new_with_stream(content_stream);
- if (content_stream) g_object_unref (content_stream);
+ GMimeObject *object_header = NULL;
+ GMimeParser *parser_header = NULL;
+ GMimeContentType *ctype_header = NULL;
+ GMimeContentDisposition *disposition_header = NULL;
- object_header = g_mime_parser_construct_part(parser_header);
- if (parser_header) g_object_unref(parser_header);
+ if (net_getbuffer(imaplocal->netstream, (long)body_size, (char *)encoded) <= 0) {
+ EM_DEBUG_EXCEPTION("net_getbuffer failed...");
+ err = EMAIL_ERROR_NO_RESPONSE;
+ goto FINISH_OFF;
+ }
- /* Content type */
- ctype_header = g_mime_object_get_content_type(object_header);
- file_name = (char *)g_mime_content_type_get_parameter(ctype_header, "name");
- EM_DEBUG_LOG_DEV("Content name : [%s]", file_name);
+ EM_DEBUG_LOG_DEV("Data : [%s]", encoded);
- if (file_name == NULL) {
- /* Content Disposition */
- disposition_header = g_mime_object_get_content_disposition(object_header);
- file_name = (char *)g_mime_content_disposition_get_parameter(disposition_header, "filename");
- EM_DEBUG_LOG_DEV("Disposition name : [%s]", file_name);
- }
+ if (signed_message) {
+ header_string = g_strdup((const gchar *)encoded);
+ } else {
+ content_stream = g_mime_stream_mem_new_with_buffer((const char *)encoded, EM_SAFE_STRLEN(encoded));
+ parser_header = g_mime_parser_new_with_stream(content_stream);
+ if (content_stream) g_object_unref(content_stream);
+
+ object_header = g_mime_parser_construct_part(parser_header);
+ if (parser_header) g_object_unref(parser_header);
+
+ /* Content type */
+ ctype_header = g_mime_object_get_content_type(object_header);
+ file_name = (char *)g_mime_content_type_get_parameter(ctype_header, "name");
+ EM_DEBUG_LOG_DEV("Content name : [%s]", file_name);
+
+ if (file_name == NULL) {
+ /* Content Disposition */
+ disposition_header = g_mime_object_get_content_disposition(object_header);
+ file_name = (char *)g_mime_content_disposition_get_parameter(disposition_header, "filename");
+ EM_DEBUG_LOG_DEV("Disposition name : [%s]", file_name);
+ }
- /* Replace the file name (Becase the server sometimes send the invalid name in bodystructure) */
- if (mime_part && file_name) g_mime_part_set_filename(mime_part, file_name);
+ /* Replace the file name (Becase the server sometimes send the invalid name in bodystructure) */
+ if (mime_part && file_name) g_mime_part_set_filename(mime_part, file_name);
+ }
- if (object_header) g_object_unref(object_header);
- if (ctype_header) g_object_unref(ctype_header);
- if (disposition_header) g_object_unref(disposition_header);
- }
+ if (object_header) g_object_unref(object_header);
+ if (ctype_header) g_object_unref(ctype_header);
+ if (disposition_header) g_object_unref(disposition_header);
+ }
+ if (buf) g_remove(buf);
EM_SAFE_FREE(buf);
}
else if ((tag_position = g_strrstr(response, tag))) /* end of response */ {
@@ -4062,6 +4181,43 @@ INTERNAL_FUNC int emcore_gmime_fetch_imap_body_sections(MAILSTREAM *stream, int
EM_SAFE_FREE (response);
}
+ if (signed_message) {
+ int part_index = -1;
+
+ GMimeStream *tmp_stream = NULL;
+ GMimeParser *tmp_parser = NULL;
+ GMimeMessage *tmp_message = NULL;
+
+ body_string = g_mime_object_to_string(entity_part);
+ if (entity_part) g_object_unref(entity_part);
+
+ full_text = g_strconcat(header_string, body_string, NULL);
+ tmp_stream = g_mime_stream_mem_new_with_buffer(full_text, EM_SAFE_STRLEN(full_text));
+
+ tmp_parser = g_mime_parser_new_with_stream(tmp_stream);
+ if (tmp_stream) g_object_unref(tmp_stream);
+
+ tmp_message = g_mime_parser_construct_message(tmp_parser);
+ if (tmp_parser) g_object_unref(tmp_parser);
+
+ /* Search get index of multipart for replacing */
+ part_index = g_mime_multipart_index_of(GMIME_MULTIPART(message->mime_part), mime_object);
+ if (part_index == -1) {
+ EM_DEBUG_EXCEPTION("g_mime_multipart_index_of failed");
+ if (tmp_message) g_object_unref(tmp_message);
+ goto FINISH_OFF;
+ }
+
+ /* replace the entity part */
+ if (g_mime_multipart_replace(GMIME_MULTIPART(message->mime_part), part_index, tmp_message->mime_part) == NULL) {
+ EM_DEBUG_EXCEPTION("g_mime_multipart_replaced failed");
+ if (tmp_message) g_object_unref(tmp_message);
+ goto FINISH_OFF;
+ }
+
+ if (tmp_message) g_object_unref(tmp_message);
+ }
+
ret = TRUE;
FINISH_OFF:
@@ -4071,11 +4227,19 @@ FINISH_OFF:
mime_iter = NULL;
}*/
+ EM_SAFE_FREE(header_string);
+ EM_SAFE_FREE(body_string);
+ EM_SAFE_FREE(full_text);
+
+ if (entity_part) g_object_unref(entity_part);
+ if (entity_parser) g_object_unref(entity_parser);
+
if (search_info) {
EM_SAFE_FREE(search_info->section);
EM_SAFE_FREE(search_info);
}
+ if (buf) g_remove(buf);
EM_SAFE_FREE(buf);
EM_SAFE_FREE(response);
@@ -4747,3 +4911,114 @@ INTERNAL_FUNC char *emcore_gmime_get_encoding_to_utf8(const char *text)
return encoded_text;
}
+
+INTERNAL_FUNC char *emcore_gmime_get_decoding_text(const char *text)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ if (text == NULL) {
+ EM_DEBUG_EXCEPTION("Invalid parameter");
+ return NULL;
+ }
+
+ char *decoded_text = NULL;
+
+ decoded_text = g_mime_utils_header_decode_text(text);
+ if (decoded_text == NULL) {
+ EM_DEBUG_EXCEPTION("g_mime_utils_header_encode_text failed : [%s]", text);
+ return NULL;
+ }
+
+ EM_DEBUG_LOG("decoded_text : [%s]", decoded_text);
+
+ return decoded_text;
+}
+
+INTERNAL_FUNC char *emcore_gmime_get_mime_entity_signed_message(GMimeObject *multipart)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ int entity_fd = 0;
+ int error = EMAIL_ERROR_NONE;
+ char *mime_entity_path = NULL;
+
+ GMimeObject *mime_entity = NULL;
+ GMimeStream *out_stream = NULL, *filtered = NULL, *stream = NULL;
+ GMimeFilter *filter = NULL;
+
+ if (!GMIME_IS_MULTIPART_SIGNED(multipart)) {
+ EM_DEBUG_EXCEPTION("Invalid param");
+ error = EMAIL_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ if (!emcore_get_temp_file_name(&mime_entity_path, &error)) {
+ EM_DEBUG_EXCEPTION("emcore_get_temp_file_name failed : [%d]", error);
+ goto FINISH_OFF;
+ }
+
+ entity_fd = open(mime_entity_path, O_WRONLY|O_CREAT, 0644);
+ if (entity_fd < 0) {
+ EM_DEBUG_EXCEPTION("open failed");
+ error = EMAIL_ERROR_SYSTEM_FAILURE;
+ goto FINISH_OFF;
+ }
+
+ mime_entity = g_mime_multipart_get_part(GMIME_MULTIPART(multipart), GMIME_MULTIPART_SIGNED_CONTENT);
+ stream = g_mime_stream_mem_new();
+ g_mime_object_write_to_stream(mime_entity, stream);
+ g_mime_stream_reset(stream);
+
+ filtered = g_mime_stream_filter_new(stream);
+ filter = g_mime_filter_crlf_new(TRUE, FALSE);
+ g_mime_stream_filter_add(GMIME_STREAM_FILTER(filtered), filter);
+
+ if (filter) g_object_unref(filter);
+ if (stream) g_object_unref(stream);
+ if (filtered) g_mime_stream_reset(filtered);
+
+ out_stream = g_mime_stream_fs_new(entity_fd);
+ g_mime_stream_write_to_stream(filtered, out_stream);
+ g_mime_stream_flush(out_stream);
+
+ if (filtered) g_object_unref(filtered);
+ if (out_stream) g_object_unref(out_stream);
+
+FINISH_OFF:
+
+ if (error != EMAIL_ERROR_NONE) {
+ EM_SAFE_FREE(mime_entity_path);
+ return NULL;
+ } else {
+ return mime_entity_path;
+ }
+}
+
+INTERNAL_FUNC char *emcore_gmime_get_mime_entity(int fd)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ char *output_path = NULL;
+
+ GMimeStream *stream = NULL;
+ GMimeParser *parser = NULL;
+ GMimeObject *part = NULL;
+
+ stream = g_mime_stream_fs_new(fd);
+
+ parser = g_mime_parser_new_with_stream(stream);
+ if (stream) g_object_unref(stream);
+
+ part = g_mime_parser_construct_part(parser);
+ if (parser) g_object_unref(parser);
+ if (part == NULL) {
+ EM_DEBUG_EXCEPTION("Data is invalid");
+ return NULL;
+ }
+
+ output_path = emcore_gmime_get_mime_entity_signed_message(part);
+
+ if (part) g_object_unref(part);
+
+ EM_DEBUG_FUNC_END();
+ return output_path;
+}
diff --git a/email-core/email-core-imap-idle.c b/email-core/email-core-imap-idle.c
index 9443d58..7f5e4f2 100755
--- a/email-core/email-core-imap-idle.c
+++ b/email-core/email-core-imap-idle.c
@@ -47,6 +47,7 @@
#include "email-core-account.h"
#include "email-core-alarm.h"
#include "email-utilities.h"
+#include "email-core-container.h"
/*Definitions copied temporarily from ssl_unix.c */
#define SSLBUFLEN 8192
@@ -67,6 +68,7 @@ typedef struct _email_imap_idle_connection_info_t {
int mailbox_id;
MAILSTREAM *mail_stream;
int socket_fd;
+ char *multi_user_name;
} email_imap_idle_connection_info_t;
int imap_idle_pipe_fd[2];
@@ -134,7 +136,10 @@ static int emcore_clear_old_connections(int input_epoll_fd, GList **input_imap_i
}
/* Close connection */
- connection_info->mail_stream = mail_close(connection_info->mail_stream);
+ if (connection_info->mail_stream)
+ connection_info->mail_stream = mail_close(connection_info->mail_stream);
+
+ EM_SAFE_FREE(connection_info->multi_user_name);
EM_SAFE_FREE(connection_info);
index = g_list_next(index);
@@ -148,7 +153,7 @@ FINISH_OFF:
return err;
}
-static int emcore_imap_idle_insert_sync_event(int input_account_id, int input_mailbox_id, int *err_code)
+static int emcore_imap_idle_insert_sync_event(char *multi_user_name, int input_account_id, int input_mailbox_id, int *err_code)
{
EM_DEBUG_FUNC_BEGIN();
@@ -163,7 +168,7 @@ static int emcore_imap_idle_insert_sync_event(int input_account_id, int input_ma
goto FINISH_OFF;
}
- event_data = em_malloc(sizeof(email_event_t));
+ event_data = em_malloc(sizeof(email_event_t));
if (event_data == NULL) {
EM_DEBUG_EXCEPTION("em_malloc failed");
err = EMAIL_ERROR_OUT_OF_MEMORY;
@@ -173,6 +178,7 @@ static int emcore_imap_idle_insert_sync_event(int input_account_id, int input_ma
event_data->type = EMAIL_EVENT_SYNC_HEADER;
event_data->event_param_data_5 = input_mailbox_id;
event_data->account_id = input_account_id;
+ event_data->multi_user_name = EM_SAFE_STRDUP(multi_user_name);
if (!emcore_insert_event(event_data, &handle, &err)) {
EM_DEBUG_EXCEPTION("emcore_insert_event failed [%d]", err);
@@ -195,7 +201,7 @@ FINISH_OFF:
return ret;
}
-static int emcore_parse_imap_idle_response(int input_account_id, int input_mailbox_id, MAILSTREAM *input_mailstream, int input_socket_fd)
+static int emcore_parse_imap_idle_response(char *multi_user_name, int input_account_id, int input_mailbox_id, MAILSTREAM *input_mailstream, int input_socket_fd)
{
EM_DEBUG_FUNC_BEGIN("input_account_id[%d] input_mailbox_id [%d] input_mailstream[%p] input_socket_fd[%d]", input_account_id, input_mailbox_id, input_mailstream, input_socket_fd);
int err = EMAIL_ERROR_NONE;
@@ -228,7 +234,7 @@ static int emcore_parse_imap_idle_response(int input_account_id, int input_mailb
}
else {
if (strstr(p, "EXIST") != NULL) {
- if (!emcore_imap_idle_insert_sync_event(input_account_id, input_mailbox_id, &err))
+ if (!emcore_imap_idle_insert_sync_event(multi_user_name, input_account_id, input_mailbox_id, &err))
EM_DEBUG_EXCEPTION_SEC("Syncing mailbox[%d] failed with err_code [%d]", input_mailbox_id, err);
}
else
@@ -256,7 +262,7 @@ FINISH_OFF:
}
/* connects to given mailbox. send idle and returns socket id */
-static int emcore_connect_and_idle_on_mailbox(GList **input_connection_list, email_account_t *input_account, email_mailbox_t *input_mailbox, MAILSTREAM **output_mailstream, int *output_socket_fd)
+static int emcore_connect_and_idle_on_mailbox(char *multi_user_name, GList **input_connection_list, email_account_t *input_account, email_mailbox_t *input_mailbox, MAILSTREAM **output_mailstream, int *output_socket_fd)
{
EM_DEBUG_FUNC_BEGIN("input_connection_list [%p] input_account [%p] input_mailbox[%p] output_mailstream [%p] output_socket_fd [%p]", input_connection_list, input_account, input_mailbox, output_mailstream, output_socket_fd);
void *mail_stream = NULL;
@@ -284,7 +290,7 @@ static int emcore_connect_and_idle_on_mailbox(GList **input_connection_list, ema
EM_DEBUG_EXCEPTION("emcore_get_empty_session failed...");
/* Open connection to mailbox */
- if (!emcore_connect_to_remote_mailbox(input_mailbox->account_id, input_mailbox->mailbox_id, (void **)&mail_stream, &err) || !mail_stream) {
+ if (!emcore_connect_to_remote_mailbox(multi_user_name, input_mailbox->account_id, input_mailbox->mailbox_id, (void **)&mail_stream, &err) || !mail_stream) {
EM_DEBUG_EXCEPTION("emcore_connect_to_remote_mailbox failed [%d]", err);
goto FINISH_OFF;
}
@@ -343,10 +349,11 @@ static int emcore_connect_and_idle_on_mailbox(GList **input_connection_list, ema
goto FINISH_OFF;
}
- connection_info->account_id = input_account->account_id;
- connection_info->mailbox_id = input_mailbox->mailbox_id;
- connection_info->mail_stream = mail_stream;
- connection_info->socket_fd = socket_fd;
+ connection_info->account_id = input_account->account_id;
+ connection_info->mailbox_id = input_mailbox->mailbox_id;
+ connection_info->mail_stream = mail_stream;
+ connection_info->socket_fd = socket_fd;
+ connection_info->multi_user_name = EM_SAFE_STRDUP(multi_user_name);
imap_idle_connection_list = g_list_append(imap_idle_connection_list, (gpointer)connection_info);
@@ -378,7 +385,7 @@ static int emcore_imap_idle_cb(email_alarm_data_t *alarm_data, void *user_parame
return err;
}
-static int emcore_refresh_alarm_for_imap_idle()
+static int emcore_refresh_alarm_for_imap_idle(char *multi_user_name)
{
EM_DEBUG_FUNC_BEGIN();
int err = EMAIL_ERROR_NONE;
@@ -395,7 +402,7 @@ static int emcore_refresh_alarm_for_imap_idle()
emcore_delete_alram_data_by_reference_id(EMAIL_ALARM_CLASS_IMAP_IDLE, 0);
}
- if (!emcore_get_account_reference_list(&account_ref_list, &account_count, &err)) {
+ if ((err = emcore_get_account_reference_list(multi_user_name, &account_ref_list, &account_count)) != EMAIL_ERROR_NONE) {
EM_DEBUG_LOG("emcore_get_account_reference_list failed [%d]", err);
goto FINISH_OFF;
}
@@ -406,14 +413,14 @@ static int emcore_refresh_alarm_for_imap_idle()
}
}
- if(account_ref_list)
+ if (account_ref_list)
emcore_free_account_list(&account_ref_list, account_count, NULL);
if (auto_sync_account_count) {
time(&current_time);
trigger_at_time = current_time + (29 * 60);
- if ((err = emcore_add_alarm(trigger_at_time, EMAIL_ALARM_CLASS_IMAP_IDLE, 0, emcore_imap_idle_cb, NULL)) != EMAIL_ERROR_NONE) {
+ if ((err = emcore_add_alarm(multi_user_name, trigger_at_time, EMAIL_ALARM_CLASS_IMAP_IDLE, 0, emcore_imap_idle_cb, NULL)) != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("emcore_add_alarm failed [%d]",err);
}
}
@@ -442,6 +449,8 @@ void* emcore_imap_idle_worker(void* thread_user_data)
email_mailbox_t inbox_mailbox = {0};
email_account_t *account_ref_list = NULL;
GList *imap_idle_connection_list = NULL;
+ GList *zone_name_list = NULL;
+ GList *node = NULL;
email_imap_idle_connection_info_t *connection_info = NULL;
EM_DEBUG_LOG("emcore_imap_idle_worker start ");
@@ -470,56 +479,124 @@ void* emcore_imap_idle_worker(void* thread_user_data)
EM_DEBUG_LOG("Enter imap idle loop");
while (1) {
if (refresh_connection_flag) {
+
EM_DEBUG_LOG("Clear old connections");
emcore_clear_old_connections(epoll_fd, &imap_idle_connection_list);
EM_DEBUG_LOG("Getting account list");
- if (!emcore_get_account_reference_list(&account_ref_list, &account_count, &err)) {
- EM_DEBUG_LOG("emcore_get_account_reference_list failed [%d]", err);
- break;
+ if ((err = emcore_get_zone_name_list(&zone_name_list)) != EMAIL_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("emcore_get_zone_name_list failed : err[%d]", err);
+ if (zone_name_list) g_list_free(zone_name_list);
+ continue;
}
- for (i = 0; i < account_count; i++) {
- if (account_ref_list[i].incoming_server_type != EMAIL_SERVER_TYPE_IMAP4 || (account_ref_list[i].check_interval != 0 && account_ref_list[i].peak_interval != 0)) {
- EM_DEBUG_LOG("account_id[%d] is not for auto sync", account_ref_list[i].account_id);
- continue;
- }
+ if (g_list_length(zone_name_list) <= 1) {
+ if ((err = emcore_get_account_reference_list(NULL, &account_ref_list, &account_count)) != EMAIL_ERROR_NONE)
+ EM_DEBUG_LOG("emcore_get_account_reference_list failed [%d]", err);
- /* TODO: peak schedule handling */
+ for (i = 0; i < account_count; i++) {
+ if (account_ref_list[i].incoming_server_type != EMAIL_SERVER_TYPE_IMAP4 || (account_ref_list[i].check_interval != 0 && account_ref_list[i].peak_interval != 0)) {
+ EM_DEBUG_LOG("account_id[%d] is not for auto sync", account_ref_list[i].account_id);
+ continue;
+ }
- memset(&inbox_mailbox, 0, sizeof(email_mailbox_t));
+ /* TODO: peak schedule handling */
- if (!emcore_get_mailbox_by_type(account_ref_list[i].account_id, EMAIL_MAILBOX_TYPE_INBOX, &inbox_mailbox, &err)) {
- EM_DEBUG_EXCEPTION("emcore_get_mailbox_by_type failed [%d]", err);
- continue;
- }
+ memset(&inbox_mailbox, 0, sizeof(email_mailbox_t));
+
+ if (!emcore_get_mailbox_by_type(NULL, account_ref_list[i].account_id, EMAIL_MAILBOX_TYPE_INBOX, &inbox_mailbox, &err)) {
+ EM_DEBUG_EXCEPTION("emcore_get_mailbox_by_type failed [%d]", err);
+ continue;
+ }
- EM_DEBUG_LOG("Connect to IMAP server");
- err = emcore_connect_and_idle_on_mailbox(&imap_idle_connection_list, &(account_ref_list[i]), &inbox_mailbox, &mail_stream, &socket_fd);
+ EM_DEBUG_LOG("Connect to IMAP server");
+ err = emcore_connect_and_idle_on_mailbox(NULL, &imap_idle_connection_list, &(account_ref_list[i]), &inbox_mailbox, &mail_stream, &socket_fd);
- emcore_free_mailbox(&inbox_mailbox);
+ emcore_free_mailbox(&inbox_mailbox);
- if (err != EMAIL_ERROR_NONE) {
- EM_DEBUG_EXCEPTION("emcore_connect_and_idle_on_mailbox failed [%d]", err);
- continue;
- }
+ if (err != EMAIL_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("emcore_connect_and_idle_on_mailbox failed [%d]", err);
+ continue;
+ }
- ev.events = EPOLLIN;
- ev.data.fd = socket_fd;
+ ev.events = EPOLLIN;
+ ev.data.fd = socket_fd;
- EM_DEBUG_LOG("Add listener for socket buffer");
- if (epoll_ctl(epoll_fd, EPOLL_CTL_ADD, socket_fd, &ev) == -1) {
- EM_DEBUG_EXCEPTION("epoll_ctl failed: %s[%d]", EM_STRERROR(errno_buf), errno);
+ EM_DEBUG_LOG("Add listener for socket buffer");
+ if (epoll_ctl(epoll_fd, EPOLL_CTL_ADD, socket_fd, &ev) == -1) {
+ EM_DEBUG_EXCEPTION("epoll_ctl failed: %s[%d]", EM_STRERROR(errno_buf), errno);
+ }
}
- }
- if(account_ref_list)
- emcore_free_account_list(&account_ref_list, account_count, NULL);
+ if(account_ref_list)
+ emcore_free_account_list(&account_ref_list, account_count, NULL);
+
+ EM_DEBUG_LOG(" Delete old an alarm and add an alarm to refresh connections every 29min");
+ emcore_refresh_alarm_for_imap_idle(NULL);
+
+ refresh_connection_flag = 0;
+ } else {
+ node = g_list_first(zone_name_list);
+
+ while (node != NULL) {
+ if (!node->data)
+ node = g_list_next(node);
- EM_DEBUG_LOG(" Delete old an alarm and add an alarm to refresh connections every 29min");
- emcore_refresh_alarm_for_imap_idle();
+ EM_DEBUG_LOG("Data name of node : [%s]", node->data);
+
+ if ((err = emcore_get_account_reference_list(node->data, &account_ref_list, &account_count)) != EMAIL_ERROR_NONE) {
+ EM_DEBUG_LOG("emcore_get_account_reference_list failed [%d]", err);
+ }
+
+ for (i = 0; i < account_count; i++) {
+ if (account_ref_list[i].incoming_server_type != EMAIL_SERVER_TYPE_IMAP4 || (account_ref_list[i].check_interval != 0 && account_ref_list[i].peak_interval != 0)) {
+ EM_DEBUG_LOG("account_id[%d] is not for auto sync", account_ref_list[i].account_id);
+ continue;
+ }
+
+ /* TODO: peak schedule handling */
+
+ memset(&inbox_mailbox, 0, sizeof(email_mailbox_t));
+
+ if (!emcore_get_mailbox_by_type(node->data, account_ref_list[i].account_id, EMAIL_MAILBOX_TYPE_INBOX, &inbox_mailbox, &err)) {
+ EM_DEBUG_EXCEPTION("emcore_get_mailbox_by_type failed [%d]", err);
+ continue;
+ }
+
+ EM_DEBUG_LOG("Connect to IMAP server");
+ err = emcore_connect_and_idle_on_mailbox(node->data, &imap_idle_connection_list, &(account_ref_list[i]), &inbox_mailbox, &mail_stream, &socket_fd);
+
+ emcore_free_mailbox(&inbox_mailbox);
+
+ if (err != EMAIL_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("emcore_connect_and_idle_on_mailbox failed [%d]", err);
+ continue;
+ }
+
+ ev.events = EPOLLIN;
+ ev.data.fd = socket_fd;
+
+ EM_DEBUG_LOG("Add listener for socket buffer");
+ if (epoll_ctl(epoll_fd, EPOLL_CTL_ADD, socket_fd, &ev) == -1) {
+ EM_DEBUG_EXCEPTION("epoll_ctl failed: %s[%d]", EM_STRERROR(errno_buf), errno);
+ }
+ }
+
+ if(account_ref_list)
+ emcore_free_account_list(&account_ref_list, account_count, NULL);
+
+ EM_DEBUG_LOG(" Delete old an alarm and add an alarm to refresh connections every 29min");
+ emcore_refresh_alarm_for_imap_idle(node->data);
+
+ EM_SAFE_FREE(node->data);
+ node = g_list_next(node);
+ }
+
+ refresh_connection_flag = 0;
+ }
- refresh_connection_flag = 0;
+ if (zone_name_list)
+ g_list_free(zone_name_list);
}
EM_DEBUG_LOG("Waiting.......");
@@ -547,7 +624,11 @@ void* emcore_imap_idle_worker(void* thread_user_data)
continue;
}
- if ((err = emcore_parse_imap_idle_response(connection_info->account_id, connection_info->mailbox_id, connection_info->mail_stream, connection_info->socket_fd)) != EMAIL_ERROR_NONE) {
+ if ((err = emcore_parse_imap_idle_response(connection_info->multi_user_name,
+ connection_info->account_id,
+ connection_info->mailbox_id,
+ connection_info->mail_stream,
+ connection_info->socket_fd)) != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("emcore_parse_imap_idle_response failed. [%d] ", err);
refresh_connection_flag = 1;
// mail_stream = mail_close (mail_stream);
diff --git a/email-core/email-core-imap-mailbox.c b/email-core/email-core-imap-mailbox.c
index a9ecf2c..839d497 100755
--- a/email-core/email-core-imap-mailbox.c
+++ b/email-core/email-core-imap-mailbox.c
@@ -52,8 +52,8 @@
#include "email-debug-log.h"
-INTERNAL_FUNC int emcore_get_default_mail_slot_count(int input_account_id, int *output_count)
-{
+INTERNAL_FUNC int emcore_get_default_mail_slot_count(char *multi_user_name, int input_account_id, int *output_count)
+{
EM_DEBUG_FUNC_BEGIN("input_account_id [%d] output_count[%p]", input_account_id, output_count);
int err = EMAIL_ERROR_NONE;
@@ -65,7 +65,7 @@ INTERNAL_FUNC int emcore_get_default_mail_slot_count(int input_account_id, int *
goto FINISH_OFF;
}
- account_ref = emcore_get_account_reference(input_account_id);
+ account_ref = emcore_get_account_reference(multi_user_name, input_account_id, false);
if (account_ref)
default_mail_slot_count = account_ref->default_mail_slot_size;
@@ -84,7 +84,7 @@ FINISH_OFF:
}
-INTERNAL_FUNC int emcore_remove_overflowed_mails(emstorage_mailbox_tbl_t *intput_mailbox_tbl, int *err_code)
+INTERNAL_FUNC int emcore_remove_overflowed_mails(char *multi_user_name, emstorage_mailbox_tbl_t *intput_mailbox_tbl, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("intput_mailbox_tbl[%p], err_code[%p]", intput_mailbox_tbl, err_code);
@@ -100,7 +100,7 @@ INTERNAL_FUNC int emcore_remove_overflowed_mails(emstorage_mailbox_tbl_t *intput
goto FINISH_OFF;
}
- account_ref = emcore_get_account_reference(intput_mailbox_tbl->account_id);
+ account_ref = emcore_get_account_reference(multi_user_name, intput_mailbox_tbl->account_id, false);
if (account_ref) {
if (account_ref->incoming_server_type == EMAIL_SERVER_TYPE_ACTIVE_SYNC) {
EM_DEBUG_LOG("ActiveSync Account didn't support mail slot");
@@ -109,7 +109,7 @@ INTERNAL_FUNC int emcore_remove_overflowed_mails(emstorage_mailbox_tbl_t *intput
}
}
- if (!emstorage_get_overflowed_mail_id_list(intput_mailbox_tbl->account_id, intput_mailbox_tbl->mailbox_id, intput_mailbox_tbl->mailbox_type, intput_mailbox_tbl->mail_slot_size, &mail_id_list, &mail_id_list_count, true, &err)) {
+ if (!emstorage_get_overflowed_mail_id_list(multi_user_name, intput_mailbox_tbl->account_id, intput_mailbox_tbl->mailbox_id, intput_mailbox_tbl->mail_slot_size, &mail_id_list, &mail_id_list_count, true, &err)) {
if (err == EMAIL_ERROR_MAIL_NOT_FOUND) {
EM_DEBUG_LOG_SEC("There are enough slot in intput_mailbox_tbl [%s]", intput_mailbox_tbl->mailbox_name);
err = EMAIL_ERROR_NONE;
@@ -121,7 +121,7 @@ INTERNAL_FUNC int emcore_remove_overflowed_mails(emstorage_mailbox_tbl_t *intput
}
if (mail_id_list) {
- if (!emcore_delete_mail(intput_mailbox_tbl->account_id, mail_id_list, mail_id_list_count, EMAIL_DELETE_LOCALLY, EMAIL_DELETED_BY_OVERFLOW, false, &err)) {
+ if (!emcore_delete_mail(multi_user_name, intput_mailbox_tbl->account_id, mail_id_list, mail_id_list_count, EMAIL_DELETE_LOCALLY, EMAIL_DELETED_BY_OVERFLOW, false, &err)) {
EM_DEBUG_EXCEPTION("emcore_delete_mail failed [%d]", err);
goto FINISH_OFF;
}
@@ -144,7 +144,7 @@ FINISH_OFF:
}
-INTERNAL_FUNC int emcore_set_mail_slot_size(int account_id, int mailbox_id, int new_slot_size, int *err_code)
+INTERNAL_FUNC int emcore_set_mail_slot_size(char *multi_user_name, int account_id, int mailbox_id, int new_slot_size, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("account_id [%d], mailbox_id[%d], err_code[%p]", account_id, mailbox_id, err_code);
@@ -157,7 +157,7 @@ INTERNAL_FUNC int emcore_set_mail_slot_size(int account_id, int mailbox_id, int
emstorage_mailbox_tbl_t *mailbox_tbl_list = NULL;
if (account_id > ALL_ACCOUNT) {
- account_ref = emcore_get_account_reference(account_id);
+ account_ref = emcore_get_account_reference(multi_user_name, account_id, false);
if (account_ref && account_ref->incoming_server_type == EMAIL_SERVER_TYPE_ACTIVE_SYNC) {
EM_DEBUG_LOG("ActiveSync account didn't support mail slot");
ret = true;
@@ -168,7 +168,7 @@ INTERNAL_FUNC int emcore_set_mail_slot_size(int account_id, int mailbox_id, int
goto FINISH_OFF;
}
if (mailbox_id == 0) {
- if ( (err = emstorage_set_field_of_accounts_with_integer_value(account_id, "default_mail_slot_size", new_slot_size, true)) != EMAIL_ERROR_NONE) {
+ if ( (err = emstorage_set_field_of_accounts_with_integer_value(multi_user_name, account_id, "default_mail_slot_size", new_slot_size, true)) != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("emstorage_set_field_of_accounts_with_integer_value failed [%d]", err);
goto FINISH_OFF;
}
@@ -176,12 +176,12 @@ INTERNAL_FUNC int emcore_set_mail_slot_size(int account_id, int mailbox_id, int
}
else {
if (mailbox_id == 0) {
- if ( !emstorage_get_account_list(&account_count, &account_tbl_list, false, false, &err)) {
+ if ( !emstorage_get_account_list(multi_user_name, &account_count, &account_tbl_list, false, false, &err)) {
EM_DEBUG_EXCEPTION("emstorage_get_account_list failed [%d]", err);
goto FINISH_OFF;
}
for ( i = 0; i < account_count; i++) {
- if ( (err = emstorage_set_field_of_accounts_with_integer_value(account_tbl_list[i].account_id, "default_mail_slot_size", new_slot_size, true)) != EMAIL_ERROR_NONE) {
+ if ( (err = emstorage_set_field_of_accounts_with_integer_value(multi_user_name, account_tbl_list[i].account_id, "default_mail_slot_size", new_slot_size, true)) != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("emstorage_set_field_of_accounts_with_integer_value failed [%d]", err);
goto FINISH_OFF;
}
@@ -189,8 +189,7 @@ INTERNAL_FUNC int emcore_set_mail_slot_size(int account_id, int mailbox_id, int
}
}
-
- if (!emstorage_set_mail_slot_size(account_id, mailbox_id, new_slot_size, true, &err)) {
+ if (!emstorage_set_mail_slot_size(multi_user_name, account_id, mailbox_id, new_slot_size, true, &err)) {
EM_DEBUG_EXCEPTION("emstorage_set_mail_slot_size failed [%d]", err);
goto FINISH_OFF;
}
@@ -208,7 +207,7 @@ INTERNAL_FUNC int emcore_set_mail_slot_size(int account_id, int mailbox_id, int
mailbox_tbl_list->mail_slot_size = new_slot_size;
}
else { /* read information from DB */
- if ((err = emstorage_get_mailbox_by_id(mailbox_id, &mailbox_tbl_list)) != EMAIL_ERROR_NONE) {
+ if ((err = emstorage_get_mailbox_by_id(multi_user_name, mailbox_id, &mailbox_tbl_list)) != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("emstorage_get_mailbox_by_id failed [%d]", err);
goto FINISH_OFF;
}
@@ -216,14 +215,14 @@ INTERNAL_FUNC int emcore_set_mail_slot_size(int account_id, int mailbox_id, int
}
}
else {
- if (!emstorage_get_mailbox_list(account_id, EMAIL_MAILBOX_ALL, EMAIL_MAILBOX_SORT_BY_NAME_ASC, &mailbox_count, &mailbox_tbl_list, true, &err)) {
+ if (!emstorage_get_mailbox_list(multi_user_name, account_id, EMAIL_MAILBOX_ALL, EMAIL_MAILBOX_SORT_BY_NAME_ASC, &mailbox_count, &mailbox_tbl_list, true, &err)) {
EM_DEBUG_EXCEPTION("emstorage_get_mailbox failed [%d]", err);
goto FINISH_OFF;
}
}
for (i = 0; i < mailbox_count; i++) {
- if (!emcore_remove_overflowed_mails(mailbox_tbl_list + i, &err)) {
+ if (!emcore_remove_overflowed_mails(multi_user_name, mailbox_tbl_list + i, &err)) {
if (err == EMAIL_ERROR_MAIL_NOT_FOUND || err == EMAIL_ERROR_NOT_SUPPORTED)
err = EMAIL_ERROR_NONE;
else
@@ -252,7 +251,7 @@ FINISH_OFF:
return ret;
}
-static int emcore_get_mailbox_connection_path(int account_id, char *mailbox_name, char **path, int *err_code)
+static int emcore_get_mailbox_connection_path(char *multi_user_name, int account_id, char *mailbox_name, char **path, int *err_code)
{
EM_DEBUG_FUNC_BEGIN_SEC("account_id [%d], mailbox_name[%s], err_code[%p]", account_id, mailbox_name, err_code);
email_account_t *ref_account = NULL;
@@ -260,7 +259,7 @@ static int emcore_get_mailbox_connection_path(int account_id, char *mailbox_name
int ret = false;
int err = EMAIL_ERROR_NONE;
- ref_account = emcore_get_account_reference(account_id);
+ ref_account = emcore_get_account_reference(multi_user_name, account_id, false);
if (!ref_account) {
EM_DEBUG_EXCEPTION("emcore_get_account_reference failed");
goto FINISH_OFF;
@@ -379,7 +378,7 @@ static void emcore_find_mailbox_diff_between_local_and_remote (email_internal_ma
if (remote_head) g_list_free(remote_head);
}
-INTERNAL_FUNC int emcore_sync_mailbox_list(int account_id, char *mailbox_name, int event_handle, int *err_code)
+INTERNAL_FUNC int emcore_sync_mailbox_list(char *multi_user_name, int account_id, char *mailbox_name, int event_handle, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("account_id[%d], mailbox_name[%p], handle[%d], err_code[%p]", account_id, mailbox_name, event_handle, err_code);
@@ -408,8 +407,8 @@ INTERNAL_FUNC int emcore_sync_mailbox_list(int account_id, char *mailbox_name, i
EM_DEBUG_EXCEPTION("emnetwork_check_network_status failed [%d]", err);
goto FINISH_OFF;
}
-
- ref_account = emcore_get_account_reference(account_id);
+
+ ref_account = emcore_get_account_reference(multi_user_name, account_id, false);
if (!ref_account) {
EM_DEBUG_EXCEPTION("emcore_get_account_reference failed - %d", account_id);
err = EMAIL_ERROR_INVALID_ACCOUNT;
@@ -425,7 +424,7 @@ INTERNAL_FUNC int emcore_sync_mailbox_list(int account_id, char *mailbox_name, i
/* get mail server path */
/* mbox_path is not used. the below func might be unnecessary */
- if (!emcore_get_mailbox_connection_path(account_id, NULL, &mbox_path, &err) || !mbox_path) {
+ if (!emcore_get_mailbox_connection_path(multi_user_name, account_id, NULL, &mbox_path, &err) || !mbox_path) {
EM_DEBUG_EXCEPTION("emcore_get_mailbox_connection_path - %d", err);
goto FINISH_OFF;
}
@@ -434,7 +433,7 @@ INTERNAL_FUNC int emcore_sync_mailbox_list(int account_id, char *mailbox_name, i
FINISH_OFF_IF_EVENT_CANCELED (err, event_handle);
stream = NULL;
- if (!emcore_connect_to_remote_mailbox(account_id, 0, (void **)&tmp_stream, &err) || !tmp_stream) {
+ if (!emcore_connect_to_remote_mailbox(multi_user_name, account_id, 0, (void **)&tmp_stream, &err) || !tmp_stream) {
EM_DEBUG_EXCEPTION("emcore_connect_to_remote_mailbox failed - %d", err);
if (err == EMAIL_ERROR_CONNECTION_BROKEN)
@@ -457,7 +456,7 @@ INTERNAL_FUNC int emcore_sync_mailbox_list(int account_id, char *mailbox_name, i
}
/* get all mailboxes which is previously synced */
- if (!emstorage_get_mailbox_list (account_id, EMAIL_MAILBOX_FROM_SERVER, EMAIL_MAILBOX_SORT_BY_NAME_ASC,\
+ if (!emstorage_get_mailbox_list (multi_user_name, account_id, EMAIL_MAILBOX_FROM_SERVER, EMAIL_MAILBOX_SORT_BY_NAME_ASC,\
&local_mailbox_count, &local_mailbox_list, 1, &err)) {
if (err != EMAIL_ERROR_MAILBOX_NOT_FOUND) {
EM_DEBUG_EXCEPTION("emstorage_get_mailbox_list error [%d]", err);
@@ -517,10 +516,11 @@ INTERNAL_FUNC int emcore_sync_mailbox_list(int account_id, char *mailbox_name, i
mailbox_tbl.modifiable_yn = 1;
mailbox_tbl.total_mail_count_on_server = 0;
- if (!emstorage_add_mailbox (&mailbox_tbl, true, &err)) {
+ if (!emstorage_add_mailbox (multi_user_name, &mailbox_tbl, true, &err)) {
EM_DEBUG_EXCEPTION ("emstorage_add_mailbox error [%d]", err);
goto FINISH_OFF;
}
+
if (mailbox_tbl.mailbox_type == EMAIL_MAILBOX_TYPE_INBOX)
inbox_added = 1;
EM_DEBUG_LOG_SEC ("MAILBOX ADDED: mailbox_name [%s] alias [%s] mailbox_type [%d]", new_mailbox->mailbox_name,\
@@ -532,17 +532,19 @@ INTERNAL_FUNC int emcore_sync_mailbox_list(int account_id, char *mailbox_name, i
p = local_box_only;
for (; p; p = g_list_next (p)) {
emstorage_mailbox_tbl_t *del_box = (emstorage_mailbox_tbl_t *) g_list_nth_data (p, 0);
- if (!emstorage_delete_mail_by_mailbox (del_box, 1, &err)) {
+
+ if (!emstorage_delete_mail_by_mailbox (multi_user_name, del_box, 1, &err)) {
EM_DEBUG_EXCEPTION ("emstorage_delete_mail_by_mailbox error [%d] account_id [%d] mailbox_name [%s]",\
err, del_box->account_id, del_box->mailbox_name);
}
- if (!emstorage_delete_mailbox (del_box->account_id, EMAIL_MAILBOX_FROM_SERVER, del_box->mailbox_id, 1, &err)) {
+
+ if (!emstorage_delete_mailbox (multi_user_name, del_box->account_id, EMAIL_MAILBOX_FROM_SERVER, del_box->mailbox_id, 1, &err)) {
EM_DEBUG_EXCEPTION ("emstorage_delete_mailbox error [%d] account_id [%d] mailbox_name [%s]",\
err, del_box->account_id, del_box->mailbox_name);
}
#ifdef __FEATURE_WIFI_AUTO_DOWNLOAD__
- if (!emstorage_delete_auto_download_activity_by_mailbox(del_box->account_id, del_box->mailbox_id, 1, &err))
+ if (!emstorage_delete_auto_download_activity_by_mailbox(multi_user_name, del_box->account_id, del_box->mailbox_id, 1, &err))
EM_DEBUG_EXCEPTION("emstorage_delete_auto_download_activity_by_mailbox failed");
#endif
@@ -555,7 +557,7 @@ INTERNAL_FUNC int emcore_sync_mailbox_list(int account_id, char *mailbox_name, i
emstorage_mailbox_tbl_t mailbox_tbl;
emstorage_mailbox_tbl_t *result_mailbox_tbl = NULL;
- if(emstorage_get_mailbox_by_mailbox_type(account_id, counter, &result_mailbox_tbl, true, &err2)) {
+ if(emstorage_get_mailbox_by_mailbox_type(multi_user_name, account_id, counter, &result_mailbox_tbl, true, &err2)) {
if(result_mailbox_tbl) {
emstorage_free_mailbox(&result_mailbox_tbl, 1, NULL);
continue;
@@ -605,14 +607,15 @@ INTERNAL_FUNC int emcore_sync_mailbox_list(int account_id, char *mailbox_name, i
break;
}
- if (!emstorage_add_mailbox(&mailbox_tbl, true, &err)) {
+ if (!emstorage_add_mailbox(multi_user_name, &mailbox_tbl, true, &err)) {
EM_DEBUG_EXCEPTION("emstorage_add_mailbox failed - %d", err);
goto FINISH_OFF;
}
}
EM_SAFE_FREE(mailbox_name_for_mailbox_type);
}
- if (!emstorage_set_all_mailbox_modifiable_yn(account_id, 0, true, &err)) {
+
+ if (!emstorage_set_all_mailbox_modifiable_yn(multi_user_name, account_id, 0, true, &err)) {
EM_DEBUG_EXCEPTION(" >>>> emstorage_set_all_mailbox_modifiable_yn Failed [ %d ]", err);
goto FINISH_OFF;
}
@@ -662,7 +665,6 @@ FINISH_OFF:
if (err_code != NULL)
*err_code = err;
-
EM_DEBUG_FUNC_END("ret [%d]", ret);
return ret;
}
@@ -734,7 +736,7 @@ FINISH_OFF:
* succeed : 1
* fail : 0
*/
-INTERNAL_FUNC int emcore_create_imap_mailbox(email_mailbox_t *mailbox, int *err_code)
+INTERNAL_FUNC int emcore_create_imap_mailbox(char *multi_user_name, email_mailbox_t *mailbox, int *err_code)
{
MAILSTREAM *stream = NULL;
char *long_enc_path = NULL;
@@ -755,7 +757,7 @@ INTERNAL_FUNC int emcore_create_imap_mailbox(email_mailbox_t *mailbox, int *err_
/* connect mail server */
stream = NULL;
- if (!emcore_connect_to_remote_mailbox(mailbox->account_id, 0, (void **)&tmp_stream, &err)) {
+ if (!emcore_connect_to_remote_mailbox(multi_user_name, mailbox->account_id, 0, (void **)&tmp_stream, &err)) {
EM_DEBUG_EXCEPTION("emcore_connect_to_remote_mailbox failed [%d]", err);
goto FINISH_OFF;
}
@@ -763,7 +765,7 @@ INTERNAL_FUNC int emcore_create_imap_mailbox(email_mailbox_t *mailbox, int *err_
stream = (MAILSTREAM *) tmp_stream;
/* encode mailbox name by UTF7, and rename to full path (ex : {mail.test.com}child_mailbox) */
- if (!emcore_get_long_encoded_path(mailbox->account_id, mailbox->mailbox_name, '/', &long_enc_path, &err)) {
+ if (!emcore_get_long_encoded_path(multi_user_name, mailbox->account_id, mailbox->mailbox_name, '/', &long_enc_path, &err)) {
EM_DEBUG_EXCEPTION("emcore_get_long_encoded_path failed [%d]", err);
goto FINISH_OFF;
}
@@ -823,7 +825,7 @@ FINISH_OFF:
* succeed : 1
* fail : 0
*/
-INTERNAL_FUNC int emcore_delete_imap_mailbox(int input_mailbox_id, int *err_code)
+INTERNAL_FUNC int emcore_delete_imap_mailbox(char *multi_user_name, int input_mailbox_id, int *err_code)
{
EM_DEBUG_FUNC_BEGIN();
@@ -838,13 +840,12 @@ INTERNAL_FUNC int emcore_delete_imap_mailbox(int input_mailbox_id, int *err_code
if(!emcore_notify_network_event(NOTI_DELETE_MAILBOX_START, input_mailbox_id, 0, 0, 0))
EM_DEBUG_EXCEPTION("emcore_notify_network_event[NOTI_DELETE_MAILBOX_START] failed");
- if ((err = emstorage_get_mailbox_by_id(input_mailbox_id, &mailbox_tbl)) != EMAIL_ERROR_NONE || !mailbox_tbl) {
+ if ((err = emstorage_get_mailbox_by_id(multi_user_name, input_mailbox_id, &mailbox_tbl)) != EMAIL_ERROR_NONE || !mailbox_tbl) {
EM_DEBUG_EXCEPTION("emstorage_get_mailbox_by_id failed. [%d]", err);
goto FINISH_OFF;
}
- ref_account = emcore_get_account_reference(mailbox_tbl->account_id);
-
+ ref_account = emcore_get_account_reference(multi_user_name, mailbox_tbl->account_id, false);
if (!ref_account || ref_account->incoming_server_type != EMAIL_SERVER_TYPE_IMAP4) {
EM_DEBUG_EXCEPTION("Invalid account information");
err = EMAIL_ERROR_INVALID_ACCOUNT;
@@ -852,7 +853,7 @@ INTERNAL_FUNC int emcore_delete_imap_mailbox(int input_mailbox_id, int *err_code
}
/* connect mail server */
- if (!emcore_connect_to_remote_mailbox(mailbox_tbl->account_id, 0, (void **)&tmp_stream, &err)) {
+ if (!emcore_connect_to_remote_mailbox(multi_user_name, mailbox_tbl->account_id, 0, (void **)&tmp_stream, &err)) {
EM_DEBUG_EXCEPTION("emcore_connect_to_remote_mailbox failed [%d]", err);
goto FINISH_OFF;
}
@@ -860,7 +861,7 @@ INTERNAL_FUNC int emcore_delete_imap_mailbox(int input_mailbox_id, int *err_code
stream = (MAILSTREAM *)tmp_stream;
/* encode mailbox name by UTF7, and rename to full path (ex : {mail.test.com}child_mailbox) */
- if (!emcore_get_long_encoded_path(mailbox_tbl->account_id, mailbox_tbl->mailbox_name, '/', &long_enc_path, &err)) {
+ if (!emcore_get_long_encoded_path(multi_user_name, mailbox_tbl->account_id, mailbox_tbl->mailbox_name, '/', &long_enc_path, &err)) {
EM_DEBUG_EXCEPTION("emcore_get_long_encoded_path failed [%d]", err);
goto FINISH_OFF;
}
@@ -905,7 +906,7 @@ FINISH_OFF:
}
-INTERNAL_FUNC int emcore_rename_mailbox_on_imap_server(int input_account_id, int input_mailbox_id, char *input_old_mailbox_path, char *input_new_mailbox_path, int handle_to_be_published)
+INTERNAL_FUNC int emcore_rename_mailbox_on_imap_server(char *multi_user_name, int input_account_id, int input_mailbox_id, char *input_old_mailbox_path, char *input_new_mailbox_path, int handle_to_be_published)
{
EM_DEBUG_FUNC_BEGIN("input_account_id [%d], input_mailbox_id [%d], input_old_mailbox_path [%p], input_new_mailbox_path [%p] handle_to_be_published[%d]", input_account_id, input_mailbox_id, input_old_mailbox_path, input_new_mailbox_path, handle_to_be_published);
MAILSTREAM *stream = NULL;
@@ -921,8 +922,7 @@ INTERNAL_FUNC int emcore_rename_mailbox_on_imap_server(int input_account_id, int
goto FINISH_OFF;
}
- ref_account = emcore_get_account_reference(input_account_id);
-
+ ref_account = emcore_get_account_reference(multi_user_name, input_account_id, false);
if (!ref_account || ref_account->incoming_server_type != EMAIL_SERVER_TYPE_IMAP4) {
EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_ACCOUNT");
err = EMAIL_ERROR_INVALID_ACCOUNT;
@@ -931,7 +931,7 @@ INTERNAL_FUNC int emcore_rename_mailbox_on_imap_server(int input_account_id, int
/* connect mail server */
stream = NULL;
- if (!emcore_connect_to_remote_mailbox(input_account_id, 0, (void **)&tmp_stream, &err)) {
+ if (!emcore_connect_to_remote_mailbox(multi_user_name, input_account_id, 0, (void **)&tmp_stream, &err)) {
EM_DEBUG_EXCEPTION("emcore_connect_to_remote_mailbox failed. [%d]", err);
goto FINISH_OFF;
}
@@ -939,13 +939,13 @@ INTERNAL_FUNC int emcore_rename_mailbox_on_imap_server(int input_account_id, int
stream = (MAILSTREAM *)tmp_stream;
/* encode mailbox name by UTF7, and rename to full path (ex : {mail.test.com}child_mailbox) */
- if (!emcore_get_long_encoded_path(input_account_id, input_old_mailbox_path, '/', &long_enc_path_old, &err)) {
+ if (!emcore_get_long_encoded_path(multi_user_name, input_account_id, input_old_mailbox_path, '/', &long_enc_path_old, &err)) {
EM_DEBUG_EXCEPTION("emcore_get_long_encoded_path failed. [%d]", err);
goto FINISH_OFF;
}
/* encode mailbox name by UTF7, and rename to full path (ex : {mail.test.com}child_mailbox) */
- if (!emcore_get_long_encoded_path(input_account_id, input_new_mailbox_path, '/', &long_enc_path_new, &err)) {
+ if (!emcore_get_long_encoded_path(multi_user_name, input_account_id, input_new_mailbox_path, '/', &long_enc_path_new, &err)) {
EM_DEBUG_EXCEPTION("emcore_get_long_encoded_path failed. [%d]", err);
goto FINISH_OFF;
}
@@ -1022,13 +1022,12 @@ INTERNAL_FUNC int emcore_get_quota_root(int input_mailbox_id, email_quota_resour
email_account_t *ref_account = NULL;
emstorage_mailbox_tbl_t *mailbox_tbl = NULL;
- if ((err = emstorage_get_mailbox_by_id(input_mailbox_id, &mailbox_tbl)) != EMAIL_ERROR_NONE || !mailbox_tbl) {
+ if ((err = emstorage_get_mailbox_by_id(multi_user_name, input_mailbox_id, &mailbox_tbl)) != EMAIL_ERROR_NONE || !mailbox_tbl) {
EM_DEBUG_EXCEPTION("emstorage_get_mailbox_by_id failed. [%d]", err);
goto FINISH_OFF;
}
- ref_account = emcore_get_account_reference(mailbox_tbl->account_id);
-
+ ref_account = emcore_get_account_reference(multi_user_name, mailbox_tbl->account_id, false);
if (!ref_account || ref_account->incoming_server_type != EMAIL_SERVER_TYPE_IMAP4) {
EM_DEBUG_EXCEPTION("Invalid account information");
err = EMAIL_ERROR_INVALID_ACCOUNT;
@@ -1036,7 +1035,7 @@ INTERNAL_FUNC int emcore_get_quota_root(int input_mailbox_id, email_quota_resour
}
/* connect mail server */
- if (!emcore_connect_to_remote_mailbox(mailbox_tbl->account_id, 0, (void **)&stream, &err)) {
+ if (!emcore_connect_to_remote_mailbox(multi_user_name, mailbox_tbl->account_id, 0, (void **)&stream, &err)) {
EM_DEBUG_EXCEPTION("emcore_connect_to_remote_mailbox failed [%d]", err);
goto FINISH_OFF;
}
@@ -1057,12 +1056,12 @@ INTERNAL_FUNC int emcore_get_quota(int input_mailbox_id, char *input_quota_root,
email_account_t *ref_account = NULL;
emstorage_mailbox_tbl_t *mailbox_tbl = NULL;
- if ((err = emstorage_get_mailbox_by_id(input_mailbox_id, &mailbox_tbl)) != EMAIL_ERROR_NONE || !mailbox_tbl) {
+ if ((err = emstorage_get_mailbox_by_id(multi_user_name, input_mailbox_id, &mailbox_tbl)) != EMAIL_ERROR_NONE || !mailbox_tbl) {
EM_DEBUG_EXCEPTION("emstorage_get_mailbox_by_id failed. [%d]", err);
goto FINISH_OFF;
}
- ref_account = emcore_get_account_reference(mailbox_tbl->account_id);
+ ref_account = emcore_get_account_reference(multi_user_name, mailbox_tbl->account_id, false);
if (!ref_account || ref_account->incoming_server_type != EMAIL_SERVER_TYPE_IMAP4) {
EM_DEBUG_EXCEPTION("Invalid account information");
@@ -1071,7 +1070,7 @@ INTERNAL_FUNC int emcore_get_quota(int input_mailbox_id, char *input_quota_root,
}
/* connect mail server */
- if (!emcore_connect_to_remote_mailbox(mailbox_tbl->account_id, 0, (void **)&stream, &err)) {
+ if (!emcore_connect_to_remote_mailbox(multi_user_name, mailbox_tbl->account_id, 0, (void **)&stream, &err)) {
EM_DEBUG_EXCEPTION("emcore_connect_to_remote_mailbox failed [%d]", err);
goto FINISH_OFF;
}
diff --git a/email-core/email-core-mail.c b/email-core/email-core-mail.c
index 20318f9..dbebf98 100755
--- a/email-core/email-core-mail.c
+++ b/email-core/email-core-mail.c
@@ -64,13 +64,12 @@
#include "email-core-account.h"
#include "email-core-signal.h"
#include "email-core-smtp.h"
+#include "email-core-container.h"
+#include "email-core-gmime.h"
#include "email-convert.h"
#include "email-debug-log.h"
-#ifdef __FEATURE_USE_GMIME__
-#include "email-core-gmime.h"
-#endif /* __FEATURE_USE_GMIME__ */
#define ST_SILENT (long) 0x2 /* don't return results */
@@ -78,6 +77,7 @@
static char g_new_server_uid[129];
static int g_copyuid_account_id = 0;
+static char *g_multi_user_name = NULL;
bool only_body_download = false;
@@ -93,7 +93,7 @@ int _imap4_last_notified_body_size = 0;
int _imap4_total_body_size = 0;
int _imap4_download_noti_interval_value = 0;
-static int emcore_delete_mails_from_pop3_server(email_account_t *input_account, int input_mail_ids[], int input_mail_id_count);
+static int emcore_delete_mails_from_pop3_server(char *multi_user_name, email_account_t *input_account, int input_mail_ids[], int input_mail_id_count);
static int emcore_mail_cmd_read_mail_pop3(void *stream, int msgno, int limited_size, int *downloded_size, int *total_body_size, int *err_code);
extern long pop3_send (MAILSTREAM *stream, char *command, char *args);
@@ -330,14 +330,21 @@ static void emcore_mail_copyuid_ex(MAILSTREAM *stream, char *mailbox, unsigned l
}
-
-
EM_DEBUG_LOG("Count of mails copied [%d]", count);
old_server_uid = em_malloc(count * sizeof(unsigned long));
+ if (old_server_uid == NULL) {
+ EM_DEBUG_EXCEPTION("em_malloc failed : EMAIL_ERROR_OUT_OF_MEMORY");
+ return;
+ }
+
new_server_uid = em_malloc(count * sizeof(unsigned long));
+ if (new_server_uid == NULL) {
+ EM_DEBUG_EXCEPTION("em_malloc failed : EMAIL_ERROR_OUT_OF_MEMORY");
+ EM_SAFE_FREE(old_server_uid);
+ return;
+ }
/* While loop below will collect all old server uid from sourceset into old_server_uid array */
-
while (sourceset) {
if (sourceset->first > 0) {
first_uid = sourceset->first;
@@ -388,7 +395,7 @@ static void emcore_mail_copyuid_ex(MAILSTREAM *stream, char *mailbox, unsigned l
}
#ifdef __FEATURE_WIFI_AUTO_DOWNLOAD__
- if (!emstorage_get_mailbox_by_name(g_copyuid_account_id, -1, mailbox, &mailbox_tbl, false, &err)) {
+ if (!emstorage_get_mailbox_by_name(g_multi_user_name, g_copyuid_account_id, -1, mailbox, &mailbox_tbl, false, &err)) {
EM_DEBUG_EXCEPTION("emstorage_get_mailbox_by_name failed [%d", err);
}
#endif
@@ -407,17 +414,16 @@ static void emcore_mail_copyuid_ex(MAILSTREAM *stream, char *mailbox, unsigned l
EM_DEBUG_LOG("New Server Uid Char[%s]", new_server_uid_char);
- if (!emstorage_update_server_uid(old_server_uid_char, new_server_uid_char, &err)) {
+ if (!emstorage_update_server_uid(g_multi_user_name, old_server_uid_char, new_server_uid_char, &err)) {
EM_DEBUG_EXCEPTION("emstorage_update_server_uid failed...[%d]", err);
}
-
- if (!emstorage_update_read_mail_uid_by_server_uid(old_server_uid_char, new_server_uid_char, mailbox, &err)) {
+
+ if (!emstorage_update_read_mail_uid_by_server_uid(g_multi_user_name, old_server_uid_char, new_server_uid_char, mailbox, &err)) {
EM_DEBUG_EXCEPTION("emstorage_update_read_mail_uid_by_server_uid failed... [%d]", err);
}
#ifdef __FEATURE_PARTIAL_BODY_DOWNLOAD__
-
- if (false == emstorage_update_pbd_activity(old_server_uid_char, new_server_uid_char, mailbox, &err)) {
+ if (false == emstorage_update_pbd_activity(g_multi_user_name, old_server_uid_char, new_server_uid_char, mailbox, &err)) {
EM_DEBUG_EXCEPTION("emstorage_update_pbd_activity failed... [%d]", err);
}
@@ -425,7 +431,7 @@ static void emcore_mail_copyuid_ex(MAILSTREAM *stream, char *mailbox, unsigned l
#ifdef __FEATURE_WIFI_AUTO_DOWNLOAD__
if (mailbox_tbl) {
- if (!emstorage_update_auto_download_activity(old_server_uid_char, new_server_uid_char, NULL, mailbox_tbl->mailbox_id, &err))
+ if (!emstorage_update_auto_download_activity(g_multi_user_name, old_server_uid_char, new_server_uid_char, NULL, mailbox_tbl->mailbox_id, &err))
EM_DEBUG_EXCEPTION("emstorage_update_auto_download_activity failed : [%d]", err);
}
#endif
@@ -435,14 +441,16 @@ static void emcore_mail_copyuid_ex(MAILSTREAM *stream, char *mailbox, unsigned l
#ifdef __FEATURE_WIFI_AUTO_DOWNLOAD__
if (mailbox_tbl)
emstorage_free_mailbox(&mailbox_tbl, 1, NULL);
+
g_copyuid_account_id = 0;
+ EM_SAFE_FREE(g_multi_user_name);
#endif
EM_SAFE_FREE(old_server_uid);
EM_SAFE_FREE(new_server_uid);
}
-INTERNAL_FUNC int emcore_move_mail_on_server_ex(int account_id, int src_mailbox_id, int mail_ids[], int num, int dest_mailbox_id, int *error_code)
+INTERNAL_FUNC int emcore_move_mail_on_server_ex(char *multi_user_name, int account_id, int src_mailbox_id, int mail_ids[], int num, int dest_mailbox_id, int *error_code)
{
EM_DEBUG_FUNC_BEGIN();
MAILSTREAM *stream = NULL;
@@ -470,8 +478,8 @@ INTERNAL_FUNC int emcore_move_mail_on_server_ex(int account_id, int src_mailbox_
return false;
}
- ref_account = emcore_get_account_reference(account_id);
-
+ ref_account = emcore_get_account_reference(multi_user_name, account_id, false);
+
if (NULL == ref_account) {
EM_DEBUG_EXCEPTION(" emcore_get_account_reference failed[%d]", account_id);
@@ -484,8 +492,7 @@ INTERNAL_FUNC int emcore_move_mail_on_server_ex(int account_id, int src_mailbox_
goto FINISH_OFF;
}
-
- if (!emcore_connect_to_remote_mailbox(account_id, src_mailbox_id, (void **)&stream, &err_code)) {
+ if (!emcore_connect_to_remote_mailbox(multi_user_name, account_id, src_mailbox_id, (void **)&stream, &err_code)) {
EM_DEBUG_EXCEPTION("emcore_connect_to_remote_mailbox failed[%d]", err_code);
goto FINISH_OFF;
@@ -493,6 +500,7 @@ INTERNAL_FUNC int emcore_move_mail_on_server_ex(int account_id, int src_mailbox_
if (NULL != stream) {
g_copyuid_account_id = account_id;
+ g_multi_user_name = EM_SAFE_STRDUP(multi_user_name);
mail_parameters(stream, SET_COPYUID, emcore_mail_copyuid_ex);
EM_DEBUG_LOG("calling mail_copy_full FODLER MAIL COPY ");
/* [h.gahlaut] Break the set of mail_ids into comma separated strings of given length */
@@ -505,7 +513,7 @@ INTERNAL_FUNC int emcore_move_mail_on_server_ex(int account_id, int src_mailbox_
goto FINISH_OFF;
}
- if ( (err_code = emstorage_get_mailbox_by_id(dest_mailbox_id, &dest_mailbox)) != EMAIL_ERROR_NONE || !dest_mailbox) {
+ if ( (err_code = emstorage_get_mailbox_by_id(multi_user_name, dest_mailbox_id, &dest_mailbox)) != EMAIL_ERROR_NONE || !dest_mailbox) {
EM_DEBUG_EXCEPTION("emstorage_get_mailbox_by_id failed [%d]", err_code);
goto FINISH_OFF;
}
@@ -514,8 +522,7 @@ INTERNAL_FUNC int emcore_move_mail_on_server_ex(int account_id, int src_mailbox_
for (i = 0; i < string_count; ++i) {
/* Get the set of mail_ds and corresponding server_mail_ids sorted by server mail ids in ascending order */
-
- if (false == emstorage_get_id_set_from_mail_ids(string_list[i], &id_set, &id_set_count, &err_code)) {
+ if (false == emstorage_get_id_set_from_mail_ids(multi_user_name, string_list[i], &id_set, &id_set_count, &err_code)) {
EM_DEBUG_EXCEPTION("emstorage_get_id_set_from_mail_ids failed [%d]", err_code);
goto FINISH_OFF;
}
@@ -607,7 +614,7 @@ FINISH_OFF:
return ret;
}
-int emcore_delete_mails_from_imap4_server(int mail_ids[], int num, int from_server, int *err_code)
+int emcore_delete_mails_from_imap4_server(char *multi_user_name, int mail_ids[], int num, int from_server, int *err_code)
{
EM_DEBUG_FUNC_BEGIN();
@@ -635,7 +642,7 @@ int emcore_delete_mails_from_imap4_server(int mail_ids[], int num, int from_serv
}
for(i = 0; i < num; i++) {
- if (!emstorage_get_downloaded_mail(mail_ids[i], &mail_tbl_data, false, &err)) {
+ if (!emstorage_get_downloaded_mail(multi_user_name, mail_ids[i], &mail_tbl_data, false, &err)) {
EM_DEBUG_EXCEPTION("emstorage_get_downloaded_mail failed [%d]", err);
if (err == EMAIL_ERROR_MAIL_NOT_FOUND) { /* not server mail */
@@ -655,7 +662,7 @@ int emcore_delete_mails_from_imap4_server(int mail_ids[], int num, int from_serv
goto FINISH_OFF;
}
- if (!emcore_connect_to_remote_mailbox(mail_tbl_data->account_id, mail_tbl_data->mailbox_id , (void **)&stream, &err)) {
+ if (!emcore_connect_to_remote_mailbox(multi_user_name, mail_tbl_data->account_id, mail_tbl_data->mailbox_id , (void **)&stream, &err)) {
EM_DEBUG_EXCEPTION("emcore_connect_to_remote_mailbox failed [%d]", err);
goto FINISH_OFF;
}
@@ -674,8 +681,7 @@ int emcore_delete_mails_from_imap4_server(int mail_ids[], int num, int from_serv
for (i = 0; i < string_count; ++i) {
/* Get the set of mail_ds and corresponding server_mail_ids sorted by server mail ids in ascending order */
-
- if (false == emstorage_get_id_set_from_mail_ids(string_list[i], &id_set, &id_set_count, &err)) {
+ if (false == emstorage_get_id_set_from_mail_ids(multi_user_name, string_list[i], &id_set, &id_set_count, &err)) {
EM_DEBUG_EXCEPTION("emstorage_get_id_set_from_mail_ids failed [%d]", err);
goto FINISH_OFF;
}
@@ -805,7 +811,7 @@ int emcore_delete_mails_from_imap4_server(int mail_ids[], int num, int from_serv
if (delete_success) {
for (index = 0 ; index < num; index++) {
- if (!emstorage_get_downloaded_mail(mail_ids[index], &mail[index], false, &err)) {
+ if (!emstorage_get_downloaded_mail(multi_user_name, mail_ids[index], &mail[index], false, &err)) {
EM_DEBUG_LOG("emstorage_get_uid_by_mail_id failed [%d]", err);
if (err == EMAIL_ERROR_MAIL_NOT_FOUND) {
@@ -817,7 +823,7 @@ int emcore_delete_mails_from_imap4_server(int mail_ids[], int num, int from_serv
if (mail[index]) {
/* Clear entry from mail_read_mail_uid_tbl */
if (mail[index]->server_mail_id != NULL) {
- if (!emstorage_remove_downloaded_mail(mail[index]->account_id, mail[index]->mailbox_name, mail[index]->server_mail_id, true, &err)) {
+ if (!emstorage_remove_downloaded_mail(multi_user_name, mail[index]->account_id, mail[index]->mailbox_name, mail[index]->server_mail_id, true, &err)) {
EM_DEBUG_LOG("emstorage_remove_downloaded_mail falied [%d]", err);
}
}
@@ -1074,7 +1080,7 @@ FINISH_OFF:
return ret;
}
-int emcore_get_mail_contact_info_with_update(email_mail_contact_info_t *contact_info, char *full_address, int mail_id, int *err_code)
+int emcore_get_mail_contact_info_with_update(char *multi_user_name, email_mail_contact_info_t *contact_info, char *full_address, int mail_id, int *err_code)
{
EM_DEBUG_FUNC_BEGIN_SEC("contact_info[%p], full_address[%s], mail_id[%d], err_code[%p]", contact_info, full_address, mail_id, err_code);
@@ -1175,8 +1181,8 @@ int emcore_get_mail_contact_info_with_update(email_mail_contact_info_t *contact_
is_searched = false;
EM_DEBUG_LOG(" >>>>> emcore_get_mail_contact_info - 10");
-
- err = emcore_get_mail_display_name (email_address,
+
+ err = emcore_get_mail_display_name (multi_user_name, email_address,
&contact_display_name_from_contact_info);
if ( err == EMAIL_ERROR_NONE) {
contact_display_name = contact_display_name_from_contact_info;
@@ -1372,7 +1378,7 @@ FINISH_OFF:
return ret;
}
-int emcore_sync_contact_info(int mail_id, int *err_code)
+int emcore_sync_contact_info(char *multi_user_name, int mail_id, int *err_code)
{
EM_PROFILE_BEGIN(emCoreMailContactSync);
EM_DEBUG_FUNC_BEGIN();
@@ -1394,54 +1400,59 @@ int emcore_sync_contact_info(int mail_id, int *err_code)
memset(&contact_info_cc, 0x00, sizeof(email_mail_contact_info_t));
memset(&contact_info_bcc, 0x00, sizeof(email_mail_contact_info_t));
- if (!emstorage_get_mail_by_id(mail_id, &mail, true, &err) || !mail) {
+ if (!emstorage_get_mail_by_id(multi_user_name, mail_id, &mail, true, &err) || !mail) {
EM_DEBUG_EXCEPTION("emstorage_get_mail_by_id failed [%d]", err);
-
goto FINISH_OFF;
}
if (mail->full_address_from != NULL) {
- if (!emcore_get_mail_contact_info_with_update(&contact_info_from, mail->full_address_from, mail_id, &err)) {
+ if (!emcore_get_mail_contact_info_with_update(multi_user_name, &contact_info_from, mail->full_address_from, mail_id, &err)) {
EM_DEBUG_EXCEPTION("emcore_get_mail_contact_info failed [%d]", err);
}
}
if (mail->full_address_to != NULL) {
- if (!emcore_get_mail_contact_info_with_update(&contact_info_to, mail->full_address_to, mail_id, &err)) {
+ if (!emcore_get_mail_contact_info_with_update(multi_user_name, &contact_info_to, mail->full_address_to, mail_id, &err)) {
EM_DEBUG_EXCEPTION("emcore_get_mail_contact_info failed [%d]", err);
}
}
if (mail->full_address_cc != NULL) {
- if (!emcore_get_mail_contact_info_with_update(&contact_info_cc, mail->full_address_cc, mail_id, &err)) {
+ if (!emcore_get_mail_contact_info_with_update(multi_user_name, &contact_info_cc, mail->full_address_cc, mail_id, &err)) {
EM_DEBUG_EXCEPTION("emcore_get_mail_contact_info failed [%d]", err);
}
}
if (mail->full_address_bcc != NULL) {
- if (!emcore_get_mail_contact_info_with_update(&contact_info_bcc, mail->full_address_bcc, mail_id, &err)) {
+ if (!emcore_get_mail_contact_info_with_update(multi_user_name, &contact_info_bcc, mail->full_address_bcc, mail_id, &err)) {
EM_DEBUG_EXCEPTION("emcore_get_mail_contact_info failed [%d]", err);
}
}
EM_SAFE_FREE(mail->email_address_sender);
mail->email_address_sender = contact_info_from.email_address;
-
+ contact_info_from.contact_name = NULL;
+ contact_info_from.email_address = NULL;
EM_SAFE_FREE(mail->email_address_recipient);
if (mail->full_address_to != NULL) {
mail->email_address_recipient = contact_info_to.email_address;
+ contact_info_to.contact_name = NULL;
+ contact_info_to.email_address = NULL;
}
else if (mail->full_address_cc != NULL) {
mail->email_address_recipient = contact_info_cc.email_address;
+ contact_info_cc.contact_name = NULL;
+ contact_info_cc.email_address = NULL;
}
else if (mail->full_address_bcc != NULL) {
mail->email_address_recipient = contact_info_bcc.email_address;
+ contact_info_bcc.contact_name = NULL;
+ contact_info_bcc.email_address = NULL;
}
/* Update DB */
- if (!emstorage_change_mail_field(mail_id, UPDATE_ALL_CONTACT_INFO, mail, false, &err)) {
+ if (!emstorage_change_mail_field(multi_user_name, mail_id, UPDATE_ALL_CONTACT_INFO, mail, false, &err)) {
EM_DEBUG_EXCEPTION("emstorage_change_mail_field failed [%d]", err);
-
goto FINISH_OFF;
}
@@ -1466,7 +1477,7 @@ FINISH_OFF:
/* 1. parsing : alias and address */
/* 2. sync with contact */
/* 3. make glist of address info */
-static int emcore_sync_address_info(email_address_type_t address_type, char *full_address, GList **address_info_list, int *err_code)
+static int emcore_sync_address_info(char *multi_user_name, email_address_type_t address_type, char *full_address, GList **address_info_list, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("address type[%d], address_info_list[%p], full_address[%p]", address_type, address_info_list, full_address);
@@ -1546,7 +1557,7 @@ static int emcore_sync_address_info(email_address_type_t address_type, char *ful
EM_DEBUG_LOG_SEC("Search a contact : address[%s]", email_address);
is_search = false;
- error = emcore_get_mail_display_name (email_address,
+ error = emcore_get_mail_display_name (multi_user_name, email_address,
&contact_display_name_from_contact_info);
if (error == EMAIL_ERROR_NONE) {
EM_DEBUG_LOG_SEC(">>> contact display name[%s]", contact_display_name_from_contact_info);
@@ -1632,7 +1643,7 @@ static gint address_compare(gconstpointer a, gconstpointer b)
return strcmp(recipients_list1->address, recipients_list2->address);
}
-INTERNAL_FUNC GList *emcore_get_recipients_list(GList *old_recipients_list, char *full_address, int *err_code)
+INTERNAL_FUNC GList *emcore_get_recipients_list(char *multi_user_name, GList *old_recipients_list, char *full_address, int *err_code)
{
EM_DEBUG_FUNC_BEGIN();
@@ -1702,7 +1713,7 @@ INTERNAL_FUNC GList *emcore_get_recipients_list(GList *old_recipients_list, char
EM_DEBUG_LOG_SEC("Search a contact : address[%s]", email_address);
- err = emcore_get_mail_display_name(email_address, &display_name);
+ err = emcore_get_mail_display_name(multi_user_name, email_address, &display_name);
if ( err == EMAIL_ERROR_NONE) {
EM_DEBUG_LOG_SEC(">>> contact display name[%s]", display_name);
is_search = true;
@@ -1769,7 +1780,7 @@ FINISH_OFF:
return new_recipients_list;
}
-INTERNAL_FUNC int emcore_get_mail_address_info_list(int mail_id, email_address_info_list_t **address_info_list, int *err_code)
+INTERNAL_FUNC int emcore_get_mail_address_info_list(char *multi_user_name, int mail_id, email_address_info_list_t **address_info_list, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("mail_id[%d], address_info_list[%p]", mail_id, address_info_list);
@@ -1786,10 +1797,8 @@ INTERNAL_FUNC int emcore_get_mail_address_info_list(int mail_id, email_address_i
}
/* get mail from mail table */
- if (!emstorage_get_mail_by_id(mail_id, &mail, true, &err) || !mail) {
+ if (!emstorage_get_mail_by_id(multi_user_name, mail_id, &mail, true, &err) || !mail) {
EM_DEBUG_EXCEPTION("emstorage_get_mail_by_id failed [%d]", err);
-
-
goto FINISH_OFF;
}
@@ -1800,21 +1809,21 @@ INTERNAL_FUNC int emcore_get_mail_address_info_list(int mail_id, email_address_i
}
memset(p_address_info_list, 0x00, sizeof(email_address_info_list_t));
- if ((err = emcore_connect_contacts_service()) != EMAIL_ERROR_NONE) {
+ if ((err = emcore_connect_contacts_service(multi_user_name)) != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("emcore_connect_contacts_service error : [%d]", err);
goto FINISH_OFF;
}
- if (mail->full_address_from && emcore_sync_address_info(EMAIL_ADDRESS_TYPE_FROM, mail->full_address_from, &p_address_info_list->from, &err))
+ if (mail->full_address_from && emcore_sync_address_info(multi_user_name, EMAIL_ADDRESS_TYPE_FROM, mail->full_address_from, &p_address_info_list->from, &err))
failed = false;
- if (mail->full_address_to && emcore_sync_address_info(EMAIL_ADDRESS_TYPE_TO, mail->full_address_to, &p_address_info_list->to, &err))
+ if (mail->full_address_to && emcore_sync_address_info(multi_user_name, EMAIL_ADDRESS_TYPE_TO, mail->full_address_to, &p_address_info_list->to, &err))
failed = false;
- if (mail->full_address_cc && emcore_sync_address_info(EMAIL_ADDRESS_TYPE_CC, mail->full_address_cc, &p_address_info_list->cc, &err))
+ if (mail->full_address_cc && emcore_sync_address_info(multi_user_name, EMAIL_ADDRESS_TYPE_CC, mail->full_address_cc, &p_address_info_list->cc, &err))
failed = false;
- if (mail->full_address_bcc && emcore_sync_address_info(EMAIL_ADDRESS_TYPE_BCC, mail->full_address_bcc, &p_address_info_list->bcc, &err))
+ if (mail->full_address_bcc && emcore_sync_address_info(multi_user_name, EMAIL_ADDRESS_TYPE_BCC, mail->full_address_bcc, &p_address_info_list->bcc, &err))
failed = false;
- if ((err = emcore_disconnect_contacts_service()) != EMAIL_ERROR_NONE) {
+ if ((err = emcore_disconnect_contacts_service(multi_user_name)) != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("emcore_disconnect_contacts_service failed : [%d]", err);
}
@@ -1845,7 +1854,7 @@ FINISH_OFF:
* succeed : EMAIL_ERROR_NONE
* fail : error code
*/
-INTERNAL_FUNC int emcore_get_mail_data(int input_mail_id, email_mail_data_t **output_mail_data)
+INTERNAL_FUNC int emcore_get_mail_data(char *multi_user_name, int input_mail_id, email_mail_data_t **output_mail_data)
{
EM_DEBUG_FUNC_BEGIN("input_mail_id[%d], output_mail_data[%p]", input_mail_id, output_mail_data);
@@ -1862,7 +1871,7 @@ INTERNAL_FUNC int emcore_get_mail_data(int input_mail_id, email_mail_data_t **ou
SNPRINTF(conditional_clause_string, QUERY_SIZE, "WHERE mail_id = %d", input_mail_id);
- if(!emstorage_query_mail_tbl(conditional_clause_string, true, &result_mail_tbl, &result_mail_count, &error)) {
+ if(!emstorage_query_mail_tbl(multi_user_name, conditional_clause_string, true, &result_mail_tbl, &result_mail_count, &error)) {
EM_DEBUG_EXCEPTION("emstorage_query_mail_tbl falied [%d]", error);
goto FINISH_OFF;
}
@@ -1901,7 +1910,7 @@ int emcore_check_drm(emstorage_attachment_tbl_t *input_attachment_tb_data)
* succeed : 1
* fail : 0
*/
-INTERNAL_FUNC int emcore_get_attachment_info(int attachment_id, email_attachment_data_t **attachment, int *err_code)
+INTERNAL_FUNC int emcore_get_attachment_info(char *multi_user_name, int attachment_id, email_attachment_data_t **attachment, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("attachment_id[%d], attachment[%p], err_code[%p]", attachment_id, attachment, err_code);
@@ -1917,9 +1926,8 @@ INTERNAL_FUNC int emcore_get_attachment_info(int attachment_id, email_attachment
emstorage_attachment_tbl_t *attachment_tbl = NULL;
/* get attachment from attachment tbl */
- if (!emstorage_get_attachment(attachment_id, &attachment_tbl, true, &err) || !attachment_tbl) {
+ if (!emstorage_get_attachment(multi_user_name, attachment_id, &attachment_tbl, true, &err) || !attachment_tbl) {
EM_DEBUG_EXCEPTION("emstorage_get_attachment failed [%d]", err);
-
goto FINISH_OFF;
}
@@ -1962,7 +1970,7 @@ FINISH_OFF:
* succeed : EMAIL_ERROR_NONE
* fail : error code
*/
-INTERNAL_FUNC int emcore_get_attachment_data_list(int input_mail_id, email_attachment_data_t **output_attachment_data, int *output_attachment_count)
+INTERNAL_FUNC int emcore_get_attachment_data_list(char *multi_user_name, int input_mail_id, email_attachment_data_t **output_attachment_data, int *output_attachment_count)
{
EM_DEBUG_FUNC_BEGIN("input_mail_id[%d], output_attachment_data[%p], output_attachment_count[%p]", input_mail_id, output_attachment_data, output_attachment_count);
@@ -1978,9 +1986,8 @@ INTERNAL_FUNC int emcore_get_attachment_data_list(int input_mail_id, email_attac
email_attachment_data_t *temp_attachment_data = NULL;
/* get attachment from attachment tbl */
- if ( (err = emstorage_get_attachment_list(input_mail_id, true, &attachment_tbl_list, &attachment_tbl_count)) != EMAIL_ERROR_NONE ){
+ if ( (err = emstorage_get_attachment_list(multi_user_name, input_mail_id, true, &attachment_tbl_list, &attachment_tbl_count)) != EMAIL_ERROR_NONE ){
EM_DEBUG_EXCEPTION("emstorage_get_attachment_list failed [%d]", err);
-
goto FINISH_OFF;
}
@@ -2023,262 +2030,7 @@ FINISH_OFF:
return err;
}
-
-INTERNAL_FUNC int emcore_download_attachment (int account_id, int mail_id, int nth,
- int cancellable, int event_handle, int *err_code)
-{
- EM_DEBUG_FUNC_BEGIN("account_id[%d], mail_id[%d], nth[%d], err_code[%p]", account_id, mail_id, nth, err_code);
-
- int err = EMAIL_ERROR_NONE;
-
- if (mail_id < 1) {
- EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
- err = EMAIL_ERROR_INVALID_PARAM;
-
- if (err_code != NULL)
- *err_code = err;
-
- emcore_notify_network_event(NOTI_DOWNLOAD_ATTACH_FAIL, mail_id, 0, nth, err);
- return false;
- }
-
- int ret = false;
- MAILSTREAM *stream = NULL;
- BODY *mbody = NULL;
- emstorage_mail_tbl_t *mail = NULL;
- emstorage_attachment_tbl_t *attachment = NULL;
- struct attachment_info *ai = NULL;
- struct _m_content_info *cnt_info = NULL;
- void *tmp_stream = NULL;
- char *server_uid = NULL, buf[1024];
- int msg_no = 0;
- emstorage_attachment_tbl_t *attachment_list = NULL;
- int current_attachment_no = 0;
- int attachment_count_to_be_downloaded = 0; /* how many attachments should be downloaded */
- int i = 0;
- int server_mbox_id = 0;
- int decoded_attachment_size = 0;
-
- if (cancellable)
- FINISH_OFF_IF_EVENT_CANCELED (err, event_handle);
-
- only_body_download = false;
-
- /* get mail from mail table. */
- if (!emstorage_get_mail_by_id(mail_id, &mail, true, &err) || !mail) {
- EM_DEBUG_EXCEPTION("emstorage_get_mail_by_id failed [%d]", err);
- goto FINISH_OFF;
- }
-
- if (!mail->server_mail_status) {
- EM_DEBUG_EXCEPTION("not synchronous mail...");
- err = EMAIL_ERROR_MAIL_NOT_FOUND_ON_SERVER;
- goto FINISH_OFF;
- }
-
- if (nth == 0) { /* download all attachments, nth starts from 1, not zero */
- /* get attachment list from db */
- attachment_count_to_be_downloaded = EMAIL_ATTACHMENT_MAX_COUNT;
- if ( (err = emstorage_get_attachment_list(mail_id, true, &attachment_list, &attachment_count_to_be_downloaded)) != EMAIL_ERROR_NONE ){
- EM_DEBUG_EXCEPTION("emstorage_get_attachment_list failed [%d]", err);
- goto FINISH_OFF;
- }
- }
- else { /* download only nth attachment */
- attachment_count_to_be_downloaded = 1;
- if (!emstorage_get_attachment_nth(mail_id, nth, &attachment_list, true, &err) || !attachment_list) {
- EM_DEBUG_EXCEPTION("emstorage_get_attachment_nth failed [%d]", err);
-
- goto FINISH_OFF;
- }
- }
-
- if (cancellable)
- FINISH_OFF_IF_EVENT_CANCELED (err, event_handle);
-
- account_id = mail->account_id;
- server_uid = EM_SAFE_STRDUP(mail->server_mail_id);
- server_mbox_id = mail->mailbox_id;
-
- if (attachment_count_to_be_downloaded == 1 && attachment_list) {
- if (!emcore_notify_network_event(NOTI_DOWNLOAD_ATTACH_START, mail_id, attachment_list[0].attachment_name, nth, 0))
- EM_DEBUG_EXCEPTION("emcore_notify_network_event [ NOTI_DOWNLOAD_ATTACH_START] Failed >>>>");
- }
-
- /* open mail server. */
- if (!emcore_connect_to_remote_mailbox(account_id, server_mbox_id, (void **)&tmp_stream, &err) || !tmp_stream) {
- EM_DEBUG_EXCEPTION("emcore_connect_to_remote_mailbox failed [%d]", err);
- if(err == EMAIL_ERROR_NO_SUCH_HOST)
- err = EMAIL_ERROR_CONNECTION_FAILURE;
- goto FINISH_OFF;
- }
-
- stream = (MAILSTREAM *)tmp_stream;
-
- for (i = 0; i < attachment_count_to_be_downloaded; i++) {
- EM_DEBUG_LOG(" >>>>>> Attachment Downloading [%d / %d] start", i + 1, attachment_count_to_be_downloaded);
-
- attachment = attachment_list + i;
- if (nth == 0) /* download all attachments, nth starts from 1, not zero */
- current_attachment_no = i + 1; /* attachment no */
- else /* download only nth attachment */
- current_attachment_no = nth; /* attachment no */
-
- if (cancellable)
- FINISH_OFF_IF_EVENT_CANCELED (err, event_handle);
-
- /*free cnt_info before reusing*/
- if (cnt_info) {
- emcore_free_content_info(cnt_info);
- EM_SAFE_FREE(cnt_info);
- }
-
- if (!(cnt_info = em_malloc(sizeof(struct _m_content_info)))) {
- EM_DEBUG_EXCEPTION("malloc failed...");
- err = EMAIL_ERROR_OUT_OF_MEMORY;
- goto FINISH_OFF;
- }
-
- cnt_info->grab_type = GRAB_TYPE_ATTACHMENT; /* attachment */
- cnt_info->file_no = current_attachment_no; /* attachment no */
-
-#ifdef CHANGE_HTML_BODY_TO_ATTACHMENT
- /* text/html be changed to attachment, this isn't real attachment in RFC822. */
- if (html_changed)
- cnt_info->file_no--;
-#endif
-
- /* set sparep(member of BODY) memory free function. */
- mail_parameters(stream, SET_FREEBODYSPAREP, emcore_free_body_sparep);
-
- if (cancellable)
- FINISH_OFF_IF_EVENT_CANCELED (err, event_handle);
-
- msg_no = server_uid? atoi(server_uid): 0;
-
- /* get body structure. */
- /* don't free mbody because mbody is freed in closing mail_stream. */
- if ((!stream) || emcore_get_body_structure(stream, msg_no, &mbody, &err) < 0) {
- EM_DEBUG_EXCEPTION("emcore_get_body_structure failed [%d]", err);
- goto FINISH_OFF;
- }
-
- if (cancellable)
- FINISH_OFF_IF_EVENT_CANCELED (err, event_handle);
-
- /* set body fetch section. */
- if (emcore_set_fetch_body_section(mbody, false, NULL, NULL, &err) < 0) {
- EM_DEBUG_EXCEPTION("emcore_set_fetch_body_section failed [%d]", err);
- goto FINISH_OFF;
- }
-
- /* download attachment. */
- _imap4_received_body_size = 0;
- _imap4_last_notified_body_size = 0;
- _imap4_total_body_size = 0; /* This will be assigned in imap_mail_write_body_to_file() */
- _imap4_download_noti_interval_value = 0; /* This will be assigned in imap_mail_write_body_to_file() */
-
- EM_DEBUG_LOG("cnt_info->file_no[%d], current_attachment_no[%d]", cnt_info->file_no, current_attachment_no);
- if (emcore_get_body(stream, account_id, mail_id, msg_no, mbody, NULL, cnt_info, &err) < 0) {
- EM_DEBUG_EXCEPTION("emcore_get_body failed [%d]", err);
- goto FINISH_OFF;
- }
-
- if (cancellable)
- FINISH_OFF_IF_EVENT_CANCELED (err, event_handle);
-
- /* select target attachment information. */
- for (ai = cnt_info->file ; ai; ai = ai->next) {
- EM_DEBUG_LOG_SEC("[in loop] save[%s] name[%s] no[%d]", ai->save, ai->name, cnt_info->file_no);
-
- if (ai->type == INLINE_ATTACHMENT)
- continue;
-
- if (--cnt_info->file_no == 0)
- break;
- }
- EM_DEBUG_LOG("selected cnt_info->file_no = %d, ai = %p", cnt_info->file_no, ai);
-
- if (cnt_info->file_no == 0 && ai) {
- /* rename temporary file to real file. */
- if (!emstorage_create_dir(account_id, mail_id, current_attachment_no, &err)) {
- EM_DEBUG_EXCEPTION("emstorage_create_dir failed [%d]", err);
- goto FINISH_OFF;
- }
-
- if (!emstorage_get_save_name(account_id, mail_id, current_attachment_no, ai->name, buf, sizeof(buf), &err)) {
- EM_DEBUG_EXCEPTION("emstorage_get_save_name failed [%d]", err);
- goto FINISH_OFF;
- }
-
- if (!emstorage_move_file(ai->save, buf, false, &err)) {
- EM_DEBUG_EXCEPTION("emstorage_move_file failed [%d]", err);
- err = EMAIL_ERROR_INVALID_ATTACHMENT_SAVE_NAME;
- goto FINISH_OFF;
- }
-
- EM_SAFE_FREE(ai->save);
-
- emcore_get_file_size(buf, &decoded_attachment_size, NULL);
- EM_DEBUG_LOG("decoded_attachment_size [%d]", decoded_attachment_size);
- attachment->attachment_size = decoded_attachment_size;
- attachment->attachment_path = EM_SAFE_STRDUP(buf);
- attachment->content_id = EM_SAFE_STRDUP(ai->content_id);
- attachment->attachment_save_status = 1;
-
- /* update attachment information. */
- if (!emstorage_change_attachment_field(mail_id, UPDATE_SAVENAME, attachment, true, &err)) {
- EM_DEBUG_EXCEPTION("emstorage_change_attachment_field failed [%d]", err);
- /* delete created file. */
- remove(buf);
-
- goto FINISH_OFF;
- }
- }
- else {
- EM_DEBUG_EXCEPTION("invalid attachment sequence...");
- err = EMAIL_ERROR_INVALID_ATTACHMENT;
- goto FINISH_OFF;
- }
-
- EM_DEBUG_LOG(" >>>>>> Attachment Downloading [%d / %d] completed", i+1, attachment_count_to_be_downloaded);
- }
-
- ret = true;
-
-FINISH_OFF:
-
- if (ret == true)
- emcore_notify_network_event(NOTI_DOWNLOAD_ATTACH_FINISH, mail_id, NULL, nth, 0);
- else {
- if (err != EMAIL_ERROR_CANCELLED)
- emcore_notify_network_event(NOTI_DOWNLOAD_ATTACH_FAIL, mail_id, NULL, nth, err);
- }
-
- EM_SAFE_FREE(server_uid);
-
- if (stream) {
- stream = mail_close (stream);
- }
-
- if (attachment_list)
- emstorage_free_attachment(&attachment_list, attachment_count_to_be_downloaded, NULL);
- if (cnt_info) {
- emcore_free_content_info(cnt_info);
- EM_SAFE_FREE(cnt_info);
- }
-
- if (mail)
- emstorage_free_mail(&mail, 1, NULL);
-
- if (err_code != NULL)
- *err_code = err;
-
- EM_DEBUG_FUNC_END();
- return ret;
-}
-
-INTERNAL_FUNC int emcore_gmime_download_attachment(int mail_id, int nth,
+INTERNAL_FUNC int emcore_gmime_download_attachment(char *multi_user_name, int mail_id, int nth,
int cancellable, int event_handle, int auto_download, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("mail_id[%d], nth[%d], err_code[%p]", mail_id, nth, err_code);
@@ -2308,7 +2060,7 @@ INTERNAL_FUNC int emcore_gmime_download_attachment(int mail_id, int nth,
struct _m_content_info *cnt_info = NULL;
void *tmp_stream = NULL;
char *server_uid = NULL;
- char buf[1024];
+ char move_buf[512], path_buf[512];
int msg_no = 0;
int account_id = 0;
@@ -2325,7 +2077,7 @@ INTERNAL_FUNC int emcore_gmime_download_attachment(int mail_id, int nth,
FINISH_OFF_IF_EVENT_CANCELED (err, event_handle);
/* get mail from mail table. */
- if (!emstorage_get_mail_by_id(mail_id, &mail, true, &err) || !mail) {
+ if (!emstorage_get_mail_by_id(multi_user_name, mail_id, &mail, true, &err) || !mail) {
EM_DEBUG_EXCEPTION("emstorage_get_mail_by_id failed [%d]", err);
goto FINISH_OFF;
}
@@ -2337,16 +2089,15 @@ INTERNAL_FUNC int emcore_gmime_download_attachment(int mail_id, int nth,
}
if (nth == 0) { /* download all attachments, nth starts from 1, not zero */
- if ((err = emstorage_get_attachment_list(mail_id, true, &attachment_list, &attachment_count)) != EMAIL_ERROR_NONE ) {
+ if ((err = emstorage_get_attachment_list(multi_user_name, mail_id, true, &attachment_list, &attachment_count)) != EMAIL_ERROR_NONE ) {
EM_DEBUG_EXCEPTION("emstorage_get_attachment_list failed [%d]", err);
goto FINISH_OFF;
}
}
else { /* download only nth attachment */
attachment_count = 1;
- if (!emstorage_get_attachment_nth(mail_id, nth, &attachment_list, true, &err) || !attachment_list) {
+ if (!emstorage_get_attachment_nth(multi_user_name, mail_id, nth, &attachment_list, true, &err) || !attachment_list) {
EM_DEBUG_EXCEPTION("emstorage_get_attachment_nth failed [%d]", err);
-
goto FINISH_OFF;
}
}
@@ -2367,7 +2118,7 @@ INTERNAL_FUNC int emcore_gmime_download_attachment(int mail_id, int nth,
/* open mail server. */
if (!auto_download) {
- if (!emcore_connect_to_remote_mailbox(account_id, server_mbox_id, (void **)&tmp_stream, &err) || !tmp_stream) {
+ if (!emcore_connect_to_remote_mailbox(multi_user_name, account_id, server_mbox_id, (void **)&tmp_stream, &err) || !tmp_stream) {
EM_DEBUG_EXCEPTION("emcore_connect_to_remote_mailbox failed [%d]", err);
if(err == EMAIL_ERROR_NO_SUCH_HOST)
err = EMAIL_ERROR_CONNECTION_FAILURE;
@@ -2378,7 +2129,7 @@ INTERNAL_FUNC int emcore_gmime_download_attachment(int mail_id, int nth,
}
else {
MAILSTREAM **mstream = NULL;
- mstream = emcore_get_recv_stream (account_id, server_mbox_id, &err);
+ mstream = emcore_get_recv_stream (multi_user_name, account_id, server_mbox_id, &err);
if (!mstream) {
EM_DEBUG_EXCEPTION("emcore_get_recv_stream failed [%d]", err);
@@ -2481,34 +2232,37 @@ INTERNAL_FUNC int emcore_gmime_download_attachment(int mail_id, int nth,
}
/* rename temporary file to real file. */
- if (!emstorage_create_dir(account_id, mail_id, current_attachment_no, &err)) {
+ memset(move_buf, 0x00, sizeof(move_buf));
+ memset(path_buf, 0x00, sizeof(path_buf));
+
+ if (!emstorage_create_dir(multi_user_name, account_id, mail_id, current_attachment_no, &err)) {
EM_DEBUG_EXCEPTION("emstorage_create_dir failed [%d]", err);
goto FINISH_OFF;
}
- if (!emstorage_get_save_name(account_id, mail_id, current_attachment_no, ai->name, buf, sizeof(buf), &err)) {
+ if (!emstorage_get_save_name(multi_user_name, account_id, mail_id, current_attachment_no, ai->name, move_buf, path_buf, sizeof(path_buf), &err)) {
EM_DEBUG_EXCEPTION("emstorage_get_save_name failed [%d]", err);
goto FINISH_OFF;
}
- if (!emstorage_move_file(ai->save, buf, false, &err)) {
+ if (!emstorage_move_file(ai->save, move_buf, false, &err)) {
EM_DEBUG_EXCEPTION("emstorage_move_file failed [%d]", err);
err = EMAIL_ERROR_INVALID_ATTACHMENT_SAVE_NAME;
goto FINISH_OFF;
}
- emcore_get_file_size(buf, &decoded_attachment_size, NULL);
+ emcore_get_file_size(move_buf, &decoded_attachment_size, NULL);
EM_DEBUG_LOG("decoded_attachment_size [%d]", decoded_attachment_size);
attachment->attachment_size = decoded_attachment_size;
- attachment->attachment_path = EM_SAFE_STRDUP(buf);
+ attachment->attachment_path = EM_SAFE_STRDUP(path_buf);
attachment->content_id = EM_SAFE_STRDUP(ai->content_id);
attachment->attachment_save_status = 1;
/* update attachment information. */
- if (!emstorage_change_attachment_field(mail_id, UPDATE_SAVENAME, attachment, true, &err)) {
+ if (!emstorage_change_attachment_field(multi_user_name, mail_id, UPDATE_SAVENAME, attachment, true, &err)) {
EM_DEBUG_EXCEPTION("emstorage_change_attachment_field failed [%d]", err);
/* delete created file. */
- g_remove(buf);
+ g_remove(move_buf);
goto FINISH_OFF;
}
@@ -2570,7 +2324,7 @@ INTERNAL_FUNC int emcore_download_attachment_bulk(int account_id, int mail_id, i
emstorage_mail_tbl_t *mail = NULL;
emstorage_attachment_tbl_t *attachment = NULL;
void *tmp_stream = NULL;
- char *s_uid = NULL, *server_mbox = NULL, buf[512];
+ char *s_uid = NULL, *server_mbox = NULL, move_buf[512], path_buf[512];
emstorage_attachment_tbl_t *attachment_list = NULL;
int current_attachment_no = 0;
int attachment_count_to_be_downloaded = 0; /* how many attachments should be downloaded */
@@ -2590,8 +2344,10 @@ INTERNAL_FUNC int emcore_download_attachment_bulk(int account_id, int mail_id, i
email_file_list *pFileList = NULL;
#endif /* SUPPORT_EXTERNAL_MEMORY */
int decoded_attachment_size = 0;
+
+ memset(move_buf, 0x00, 512);
+ memset(path_buf, 0x00, 512);
- memset(buf, 0x00, 512);
/* CID FIX 31230 */
if (mail_id < 1 || !nth) {
EM_DEBUG_EXCEPTION("account_id[%d], mail_id[%d], nth[%p]", account_id, mail_id, nth);
@@ -2619,18 +2375,15 @@ INTERNAL_FUNC int emcore_download_attachment_bulk(int account_id, int mail_id, i
/* download all attachments, nth starts from 1, not zero */
/* get attachment list from db */
attachment_count_to_be_downloaded = EMAIL_ATTACHMENT_MAX_COUNT;
- if ( (err = emstorage_get_attachment_list(mail_id, true, &attachment_list, &attachment_count_to_be_downloaded)) != EMAIL_ERROR_NONE || !attachment_list){
+ if ( (err = emstorage_get_attachment_list(multi_user_name, mail_id, true, &attachment_list, &attachment_count_to_be_downloaded)) != EMAIL_ERROR_NONE || !attachment_list){
EM_DEBUG_EXCEPTION("emstorage_get_attachment_list failed [%d]", err);
-
goto FINISH_OFF;
}
}
else { /* download only nth attachment */
attachment_count_to_be_downloaded = 1;
- if (!emstorage_get_attachment_nth(mail_id, attachment_no, &attachment_list, true, &err) || !attachment_list) {
+ if (!emstorage_get_attachment_nth(multi_user_name, mail_id, attachment_no, &attachment_list, true, &err) || !attachment_list) {
EM_DEBUG_EXCEPTION("emstorage_get_attachment_nth failed [%d]", err);
-
-
goto FINISH_OFF;
}
}
@@ -2639,10 +2392,8 @@ INTERNAL_FUNC int emcore_download_attachment_bulk(int account_id, int mail_id, i
FINISH_OFF_IF_EVENT_CANCELED (err, event_handle);
/* get mail from mail table. */
- if (!emstorage_get_mail_by_id(mail_id, &mail, true, &err) || !mail) {
+ if (!emstorage_get_mail_by_id(multi_user_name, mail_id, &mail, true, &err) || !mail) {
EM_DEBUG_EXCEPTION("emstorage_get_mail_by_id failed [%d]", err);
-
-
goto FINISH_OFF;
}
@@ -2657,7 +2408,7 @@ INTERNAL_FUNC int emcore_download_attachment_bulk(int account_id, int mail_id, i
/* open mail server. */
- if (!emcore_connect_to_remote_mailbox(account_id, server_mbox, (void **)&tmp_stream, &err) || !tmp_stream) {
+ if (!emcore_connect_to_remote_mailbox(multi_user_name, account_id, server_mbox, (void **)&tmp_stream, &err) || !tmp_stream) {
EM_DEBUG_EXCEPTION("emcore_connect_to_remote_mailbox failed [%d]", err);
status = EMAIL_DOWNLOAD_CONNECTION_FAIL;
@@ -2727,31 +2478,29 @@ INTERNAL_FUNC int emcore_download_attachment_bulk(int account_id, int mail_id, i
}
#endif /* SUPPORT_EXTERNAL_MEMORY */
- if (!emstorage_create_dir(account_id, mail_id, attachment_no, &err)) {
+ if (!emstorage_create_dir(multi_user_name, account_id, mail_id, attachment_no, &err)) {
EM_DEBUG_EXCEPTION("emstorage_create_dir failed [%d]", err);
goto FINISH_OFF;
}
- if (!emstorage_get_save_name(account_id, mail_id, attachment_no, attachment->name, buf, &err)) {
+ if (!emstorage_get_save_name(account_id, mail_id, attachment_no, attachment->name, move_buf, path_buf, sizeof(path_buf), &err)) {
EM_DEBUG_EXCEPTION("emstorage_get_save_name failed [%d]", err);
goto FINISH_OFF;
}
- if (!emstorage_move_file(savefile, buf, false, &err)) {
+ if (!emstorage_move_file(savefile, move_buf, false, &err)) {
EM_DEBUG_EXCEPTION("emstorage_move_file failed [%d]", err);
-
goto FINISH_OFF;
}
- emcore_get_file_size(buf, &decoded_attachment_size, NULL);
+ emcore_get_file_size(move_buf, &decoded_attachment_size, NULL);
EM_DEBUG_LOG("decoded_attachment_size [%d]", decoded_attachment_size);
attachment->attachment_size = decoded_attachment_size;
- attachment->attachment_path = EM_SAFE_STRDUP(buf);
+ attachment->attachment_path = EM_SAFE_STRDUP(path_buf);
attachment->attachment_save_status = 1;
/* update attachment information. */
- if (!emstorage_change_attachment_field(mail_id, UPDATE_SAVENAME, attachment, true, &err)) {
+ if (!emstorage_change_attachment_field(multi_user_name, mail_id, UPDATE_SAVENAME, attachment, true, &err)) {
EM_DEBUG_EXCEPTION("emstorage_change_attachment_field failed [%d]", err);
-
goto FINISH_OFF;
}
@@ -2792,710 +2541,16 @@ INTERNAL_FUNC int emcore_download_attachment_bulk(int account_id, int mail_id, i
}
#endif
-/*
-Three thread can call this function :
- event worker thread,
- partial body thread,
- thread_func_EMAIL_ASYNC_TASK_MOVE_MAILS_TO_MAILBOX_OF_ANOTHER_ACCOUNT
- CANCEL should be revised, later
-*/
-INTERNAL_FUNC int emcore_download_body_multi_sections_bulk ( void *mail_stream,
- int account_id,
- int mail_id,
- int verbose,
- int with_attach,
- int limited_size,
- int event_handle,
- int cancellable,
- int *err_code)
-{
- EM_DEBUG_FUNC_BEGIN("mail_stream[%p], account_id[%d], mail_id[%d], verbose[%d], with_attach[%d], event_handle [%d]",
- mail_stream, account_id, mail_id, verbose, with_attach, event_handle);
-
- int ret = false;
- int err = EMAIL_ERROR_NONE;
- int pop3_body_size = 0;
- int pop3_downloaded_size = 0;
- int p_with_attach = with_attach;
- MAILSTREAM *stream = NULL;
- BODY *mbody = NULL;
- PARTLIST *section_list = NULL;
- email_internal_mailbox_t mailbox = {0};
- emstorage_mail_tbl_t *mail = NULL;
- emstorage_attachment_tbl_t attachment = {0};
- email_account_t *ref_account = NULL;
- struct attachment_info *ai = NULL;
- struct _m_content_info *cnt_info = NULL;
- char *s_uid = NULL;
- char buf[512] = {0};
- int msgno = 0, attachment_num = 1, local_attachment_count = 0, local_inline_content_count = 0;
- int iActualSize = 0;
- char html_body[MAX_PATH] = {0};
- emcore_uid_list *uid_list = NULL;
-#ifdef CHANGE_HTML_BODY_TO_ATTACHMENT
- int html_changed = 0;
-#endif
-
- if (mail_id < 1) {
- EM_DEBUG_EXCEPTION("mail_stream[%p], account_id[%d], mail_id[%d], verbose[%d], with_attach[%d]",
- mail_stream, account_id, mail_id, verbose, with_attach);
- err = EMAIL_ERROR_INVALID_PARAM;
- if (err_code != NULL)
- *err_code = err;
-
- emcore_notify_network_event(NOTI_DOWNLOAD_BODY_FAIL, mail_id, NULL, event_handle, err);
- return false;
- }
- if (cancellable)
- FINISH_OFF_IF_EVENT_CANCELED (err, event_handle);
-
- only_body_download = true;
-
- /* looking for mail by mail_id in DB*/
- if (!emstorage_get_mail_by_id (mail_id, &mail, true, &err) || !mail) {
- EM_DEBUG_EXCEPTION("emstorage_get_mail_by_id failed [%d]", err);
- goto FINISH_OFF;
- }
-
- /* if mail is downloaded */
- if (mail->body_download_status & EMAIL_BODY_DOWNLOAD_STATUS_FULLY_DOWNLOADED) {
- /* after entering viewer, the mail has been just downloaded */
- if (!emcore_notify_network_event (NOTI_DOWNLOAD_BODY_START,
- mail_id,
- "dummy-file", /* ?? */
- mail->mail_size, /*_pop3_total_body_size*/
- 0))
- EM_DEBUG_EXCEPTION ("emcore_notify_network_event [ NOTI_DOWNLOAD_BODY_START] error >>>> ");
- else
- EM_DEBUG_LOG("NOTI_DOWNLOAD_BODY_START notified (%d / %d)",
- 0, mail->mail_size);
-
- err = EMAIL_ERROR_NONE; //EMAIL_ERROR_MAIL_IS_ALREADY_DOWNLOADED;
- ret = true;
- goto FINISH_OFF;
- }
-
- s_uid = EM_SAFE_STRDUP(mail->server_mail_id);
- attachment.account_id = mail->account_id;
- attachment.mail_id = mail->mail_id;
- attachment.mailbox_id = mail->mailbox_id;
- attachment.attachment_save_status = 0;
-
- if (!(ref_account = emcore_get_account_reference(account_id))) {
- EM_DEBUG_EXCEPTION("emcore_get_account_reference failed [%d]", account_id);
- err = EMAIL_ERROR_INVALID_ACCOUNT;
- goto FINISH_OFF;
- }
-
- if (cancellable)
- FINISH_OFF_IF_EVENT_CANCELED (err, event_handle);
-
- /* open mail server. */
- if (!mail_stream) {
-#if 0
- MAILSTREAM *tmp_stream = NULL;
- if (!emcore_connect_to_remote_mailbox(account_id, mail->mailbox_id, (void **)&tmp_stream, &err) || !tmp_stream) {
- EM_DEBUG_EXCEPTION("emcore_connect_to_remote_mailbox failed [%d]", err);
- goto FINISH_OFF;
- }
-
- stream = (MAILSTREAM *)tmp_stream;
-#endif
- MAILSTREAM **mstream = NULL;
- mstream = emcore_get_recv_stream (account_id, mail->mailbox_id, &err);
- if (!mstream) {
- EM_DEBUG_EXCEPTION("emcore_get_recv_stream failed [%d]", err);
- goto FINISH_OFF;
- }
- stream = (MAILSTREAM *)*mstream;
- }
- else
- stream = (MAILSTREAM *)mail_stream;
-
- if (cancellable)
- FINISH_OFF_IF_EVENT_CANCELED (err, event_handle);
-
- if (!(cnt_info = em_malloc(sizeof(struct _m_content_info)))) {
- EM_DEBUG_EXCEPTION("em_malloc failed...");
- err = EMAIL_ERROR_OUT_OF_MEMORY;
- goto FINISH_OFF;
- }
-
- if (ref_account->incoming_server_type == EMAIL_SERVER_TYPE_POP3) {
- /* POP3 */
- /* in POP3 case, both text and attachment are downloaded in this call. */
- cnt_info->grab_type = GRAB_TYPE_TEXT | GRAB_TYPE_ATTACHMENT;
-
- mailbox.account_id = account_id;
-
- /* download all uids from server. */
- if (!emcore_download_uid_all (stream, &mailbox, &uid_list, NULL, NULL, 0, EM_CORE_GET_UIDS_FOR_NO_DELETE, &err)) {
- EM_DEBUG_EXCEPTION("emcore_download_uid_all failed [%d]", err);
- goto FINISH_OFF;
- }
-
- /* get mesg number to be related to last download mail from uid list file */
- if (!emcore_get_msgno(uid_list, s_uid, &msgno, &err)) {
- EM_DEBUG_EXCEPTION("emcore_get_msgno failed [%d]", err);
- err = EMAIL_ERROR_MAIL_NOT_FOUND_ON_SERVER;
- goto FINISH_OFF;
- }
-
- if (cancellable)
- FINISH_OFF_IF_EVENT_CANCELED (err, event_handle);
-
- _pop3_received_body_size = 0;
- _pop3_total_body_size = 0;
- _pop3_last_notified_body_size = 0;
- _pop3_receiving_mail_id = mail_id;
-
- /* send read mail commnad. */
- if (!emcore_mail_cmd_read_mail_pop3(stream, msgno, limited_size, &pop3_downloaded_size, &pop3_body_size, &err)) {
- EM_DEBUG_EXCEPTION("emcore_mail_cmd_read_mail_pop3 failed [%d]", err);
- goto FINISH_OFF;
- }
-
- _pop3_total_body_size = pop3_body_size;
-
- if (!emcore_notify_network_event(NOTI_DOWNLOAD_BODY_START, mail_id, "dummy-file", _pop3_total_body_size, 0))
- EM_DEBUG_EXCEPTION(" emcore_notify_network_event [ NOTI_DOWNLOAD_BODY_START] failed >>>> ");
- else
- EM_DEBUG_LOG("NOTI_DOWNLOAD_BODY_START notified (%d / %d)", 0, _pop3_total_body_size);
-
- if (cancellable)
- FINISH_OFF_IF_EVENT_CANCELED (err, event_handle);
-
- /* save message into tempfile */
- /* parsing mime from stream. */
-#ifdef __FEATURE_USE_GMIME__
- char sock_buf[1024] = {0, };
- int fd = 0;
- char *tmp_path = emcore_mime_get_save_file_name(&err);
- EM_DEBUG_LOG ("tmp_path[%s]", tmp_path);
- err = em_open(tmp_path, O_WRONLY | O_CREAT, 0644, &fd);
- if (err != EMAIL_ERROR_NONE) {
- EM_DEBUG_EXCEPTION("open error [%d]: holder is a filename that will be saved.", err);
- }
-
- while(emcore_mime_get_line_from_sock((void *)stream, sock_buf, 1024, &err)) {
- if (write(fd, sock_buf, EM_SAFE_STRLEN(sock_buf)) != EM_SAFE_STRLEN(sock_buf)) {
- EM_DEBUG_EXCEPTION("write failed");
- }
-
- if (cancellable) {
- int type = 0;
- if (!emcore_check_event_thread_status(&type, event_handle)) {
- EM_DEBUG_LOG ("CANCELED EVENT: type [%d]", type);
- err = EMAIL_ERROR_CANCELLED;
- EM_SAFE_CLOSE (fd);
- g_remove(tmp_path);
- goto FINISH_OFF;
- }
- }
- }
- EM_SAFE_CLOSE (fd);
-
- emcore_gmime_pop3_parse_mime(tmp_path, cnt_info, &err);
-
- g_remove(tmp_path);
-#else
- if (!emcore_parse_mime(stream, 0, cnt_info, &err)) {
- EM_DEBUG_EXCEPTION("emcore_parse_mime failed [%d]", err);
- goto FINISH_OFF;
- }
-#endif /* __FEATURE_USE_GMIME__ */
- if (cancellable)
- FINISH_OFF_IF_EVENT_CANCELED (err, event_handle);
-
- }
- else { /* in IMAP case, both text and attachment list are downloaded in this call. */
- /* This flag is just for downloading mailbox.(sync header), don't be used when retrieve body. */
- if (p_with_attach > 0)
- cnt_info->grab_type = GRAB_TYPE_TEXT | GRAB_TYPE_ATTACHMENT;
- else
- cnt_info->grab_type = GRAB_TYPE_TEXT;
-
- int uid = s_uid? atoi(s_uid):0; /*prevent 39118*/
-
- /* set sparep(member of BODY) memory free function */
- mail_parameters(stream, SET_FREEBODYSPAREP, emcore_free_body_sparep);
-
- /* get body strucutre. */
- /* don't free mbody because mbody is freed in closing mail_stream. */
- if (emcore_get_body_structure(stream, uid, &mbody, &err) < 0 || (mbody == NULL)) {
- EM_DEBUG_EXCEPTION("emcore_get_body_structure failed [%d]", err);
- err = EMAIL_ERROR_MAIL_NOT_FOUND_ON_SERVER;
- goto FINISH_OFF;
- }
-
- if (cancellable)
- FINISH_OFF_IF_EVENT_CANCELED (err, event_handle);
-
- if (mbody->type == TYPEMULTIPART) {
- EM_DEBUG_LOG(">>> check multipart body size to download : only_body_download[%d]", only_body_download);
- PART *part_child = mbody->nested.part;
- int counter = 0;
-
- char filename[MAX_PATH+1] = {0, };
- int is_attachment = 0;
- while (part_child) {
- BODY *body = &(part_child->body);
- if (only_body_download == true) {
- if (((body->id) && EM_SAFE_STRLEN(body->id) > 1) || (body->location))
- is_attachment = 0;
- else if (body->disposition.type) { /* "attachment" or "inline" or etc... */
- PARAMETER *param = body->disposition.parameter;
-
- while (param) {
- EM_DEBUG_LOG("param->attribute [%s], param->value [%s]", param->attribute, param->value);
-
- if (!strcasecmp(param->attribute, "filename")) { /* attribute is "filename" */
- strncpy(filename, param->value, MAX_PATH);
- EM_DEBUG_LOG_SEC(">>>>> FILENAME [%s] ", filename);
- break;
- }
- param = param->next;
- }
-
- is_attachment = 1;
-
- if (!*filename) {
- /* it may be report msg */
- if (body->disposition.type[0] == 'i' || body->disposition.type[0] == 'I')
- is_attachment = 0;
- }
- }
-
- if (is_attachment == 0) {
- EM_DEBUG_LOG("%d : body->size.bytes[%ld]", counter+1, body->size.bytes);
- multi_part_body_size = multi_part_body_size + body->size.bytes;
- }
- }
- else {
- /* download all */
- EM_DEBUG_LOG("%d : body->size.bytes[%ld]", counter+1, body->size.bytes);
- multi_part_body_size = multi_part_body_size + body->size.bytes;
- }
- part_child = part_child->next;
- counter++;
- }
- }
-
- /* set body fetch section. */
- if (emcore_set_fetch_body_section(mbody, true, NULL, &iActualSize, &err) < 0) {
- EM_DEBUG_EXCEPTION("emcore_set_fetch_body_section failed [%d]", err);
- goto FINISH_OFF;
- }
-
- EM_DEBUG_LOG("iActualSize [%d]", iActualSize);
- multi_part_body_size = iActualSize;
-
- _imap4_received_body_size = 0;
- _imap4_last_notified_body_size = 0;
-
- if (multi_part_body_size > 0) { /* download multiparts */
- _imap4_total_body_size = multi_part_body_size;
- _imap4_download_noti_interval_value = DOWNLOAD_NOTI_INTERVAL_PERCENT * multi_part_body_size / 100;
- }
- else { /* download only one body part */
- _imap4_total_body_size = 0; /* This will be assigned in imap_mail_write_body_to_file() */
- _imap4_download_noti_interval_value = 0; /* This will be assigned in imap_mail_write_body_to_file() */
- }
-
- /* save message into tempfile */
- /* download body text and get attachment list. */
- if (emcore_get_body_part_list_full(stream, uid, account_id, mail_id, mbody, cnt_info, &err, section_list, event_handle) < 0) {
- EM_DEBUG_EXCEPTION("emcore_get_body_part_list_full failed [%d]", err);
- goto FINISH_OFF;
- }
-
- if (cancellable)
- FINISH_OFF_IF_EVENT_CANCELED (err, event_handle);
- }
-
- if (cnt_info->text.plain) {
- char *charset_plain_text = NULL;
- EM_DEBUG_LOG_SEC("cnt_info->text.plain [%s]", cnt_info->text.plain);
-
- char *file_content = NULL;
- int content_size = 0;
-
- if (emcore_get_content_from_file(cnt_info->text.plain, &file_content, &content_size) != EMAIL_ERROR_NONE) {
- EM_DEBUG_EXCEPTION("emcore_get_content_from_file failed");
- }
-
- if (file_content && content_size > 0) {
- char escape = 0x1b;
- char detector[25] = {0,};
- snprintf(detector, sizeof(detector), "%c$B", escape);
- if (g_strrstr(cnt_info->text.plain_charset, "UTF-8") && g_strrstr(file_content, detector)) {
- cnt_info->text.plain_charset = "ISO-2022-JP";
- }
- }
-
- EM_SAFE_FREE(file_content);
-
- if (cnt_info->text.plain_charset)
- charset_plain_text = cnt_info->text.plain_charset;
- else {
- if (mail->default_charset) {
- charset_plain_text = mail->default_charset;
- } else {
- charset_plain_text = "UTF-8";
- }
- }
- EM_DEBUG_LOG("PLAIN DEFAULT CHARSET : %s", charset_plain_text);
-
- if (!emstorage_create_dir(account_id, mail_id, 0, &err)) {
- EM_DEBUG_EXCEPTION("emstorage_create_dir failed [%d]", err);
- goto FINISH_OFF;
- }
-
- if (!emstorage_get_save_name(account_id, mail_id, 0, charset_plain_text, buf, sizeof(buf), &err)) {
- EM_DEBUG_EXCEPTION("emstorage_get_save_name failed [%d]", err);
- goto FINISH_OFF;
- }
-
- if (!emstorage_move_file(cnt_info->text.plain, buf, false, &err)) {
- EM_DEBUG_EXCEPTION("emstorage_move_file failed [%d]", err);
- goto FINISH_OFF;
- }
-
- EM_SAFE_FREE(mail->file_path_plain);
- mail->file_path_plain = EM_SAFE_STRDUP(buf);
- EM_DEBUG_LOG_SEC("mail->file_path_plain [%s]", mail->file_path_plain);
- }
-
- if (cnt_info->text.html) {
- if (!emstorage_create_dir(account_id, mail_id, 0, &err)) {
- EM_DEBUG_EXCEPTION("emstorage_create_dir failed [%d]", err);
- goto FINISH_OFF;
- }
-
- if (cnt_info->text.html_charset != NULL) {
- memcpy(html_body, cnt_info->text.html_charset, EM_SAFE_STRLEN(cnt_info->text.html_charset));
- strcat(html_body, HTML_EXTENSION_STRING);
- }
- else if (cnt_info->text.plain_charset != NULL) {
- memcpy(html_body, cnt_info->text.plain_charset, EM_SAFE_STRLEN(cnt_info->text.plain_charset));
- strcat(html_body, HTML_EXTENSION_STRING);
- }
- else {
- memcpy(html_body, "UTF-8.htm", strlen("UTF-8.htm"));
- }
- if (!emstorage_get_save_name(account_id, mail_id, 0, html_body, buf, sizeof(buf), &err)) {
- EM_DEBUG_EXCEPTION("emstorage_get_save_name failed [%d]", err);
- goto FINISH_OFF;
- }
-
- if (!emstorage_move_file(cnt_info->text.html, buf, false, &err)) {
- EM_DEBUG_EXCEPTION("emstorage_move_file failed [%d]", err);
- goto FINISH_OFF;
- }
- EM_SAFE_FREE(mail->file_path_html);
- mail->file_path_html = EM_SAFE_STRDUP(buf);
- }
-
- if (ref_account->incoming_server_type == EMAIL_SERVER_TYPE_POP3 && limited_size != NO_LIMITATION &&
- limited_size < pop3_body_size) {
- mail->body_download_status = (mail->body_download_status & ~0x00000003) | EMAIL_BODY_DOWNLOAD_STATUS_PARTIALLY_DOWNLOADED;
- }
- else {
- mail->body_download_status = (mail->body_download_status & ~0x00000003) | EMAIL_BODY_DOWNLOAD_STATUS_FULLY_DOWNLOADED;
- p_with_attach = true;
- }
-
- /* Update local_preview_text */
- if ((err = emcore_get_preview_text_from_file (mail->file_path_plain, mail->file_path_html,
- MAX_PREVIEW_TEXT_LENGTH, &mail->preview_text)) != EMAIL_ERROR_NONE) {
- EM_DEBUG_EXCEPTION("emcore_get_preview_text_from_file error [%d]", err);
- }
-
-#ifdef CHANGE_HTML_BODY_TO_ATTACHMENT
- if (html_changed) mail->flag2 = 1;
-#endif
-
- if (cancellable)
- FINISH_OFF_IF_EVENT_CANCELED (err, event_handle);
-
- for (ai = cnt_info->file; ai; ai = ai->next, attachment_num++) {
-
- if (ai->type == 1)
- local_inline_content_count++;
- else
- local_attachment_count++;
-
- if (ref_account->incoming_server_type == EMAIL_SERVER_TYPE_IMAP4 && only_body_download && ai->type != INLINE_ATTACHMENT)
- continue;
-
- attachment.attachment_id = attachment_num;
- attachment.attachment_size = ai->size;
- attachment.attachment_path = ai->save;
- attachment.content_id = ai->content_id;
- attachment.attachment_name = ai->name;
- attachment.attachment_drm_type = ai->drm;
- attachment.attachment_inline_content_status = ai->type == 1;
- attachment.attachment_mime_type = ai->attachment_mime_type;
-
- if (p_with_attach)
- attachment.attachment_save_status = EMAIL_BODY_DOWNLOAD_STATUS_FULLY_DOWNLOADED;
- else
- attachment.attachment_save_status = (ai->type == 1) ? EMAIL_BODY_DOWNLOAD_STATUS_PARTIALLY_DOWNLOADED:EMAIL_BODY_DOWNLOAD_STATUS_NONE;
-
-#ifdef __ATTACHMENT_OPTI__
- attachment.encoding = ai->encoding;
- attachment.section = ai->section;
-#endif
- EM_DEBUG_LOG("attachment.attachment_id[%d]", attachment.attachment_id);
- EM_DEBUG_LOG("attachment.attachment_size[%d]", attachment.attachment_size);
- EM_DEBUG_LOG_SEC("attachment.attachment_path[%s]", attachment.attachment_path);
- EM_DEBUG_LOG("attachment.content_id[%s]", attachment.content_id);
- EM_DEBUG_LOG_SEC("attachment.attachment_name[%s]", attachment.attachment_name);
- EM_DEBUG_LOG("attachment.attachment_drm_type[%d]", attachment.attachment_drm_type);
- EM_DEBUG_LOG("attachment.attachment_save_status[%d]", attachment.attachment_save_status);
- EM_DEBUG_LOG("attachment.attachment_inline_content_status[%d]", attachment.attachment_inline_content_status);
-
- if (ai->save) {
- /* in POP3 case, rename temporary file to real file. */
- if (ai->type == 1) { /* it is inline content */
- if (!emstorage_create_dir(account_id, mail_id, 0, &err)) {
- EM_DEBUG_EXCEPTION("emstorage_create_dir failed [%d]", err);
- goto FINISH_OFF;
- }
- if (!emstorage_get_save_name(account_id, mail_id, 0, attachment.attachment_name, buf, sizeof(buf), &err)) {
- EM_DEBUG_EXCEPTION("emstorage_get_save_name failed [%d]", err);
- goto FINISH_OFF;
- }
- }
- else {
- if (!emstorage_create_dir(account_id, mail_id, attachment_num, &err)) {
- EM_DEBUG_EXCEPTION("emstorage_create_dir failed [%d]", err);
- goto FINISH_OFF;
- }
-
- if (!emstorage_get_save_name(account_id, mail_id, attachment_num, attachment.attachment_name, buf, sizeof(buf), &err)) {
- EM_DEBUG_EXCEPTION("emstorage_get_save_name failed [%d]", err);
- goto FINISH_OFF;
- }
- }
-
- if (!emstorage_move_file(ai->save, buf, false, &err)) {
- EM_DEBUG_EXCEPTION("emstorage_move_file failed [%d]", err);
-
- /* delete all created files. */
- if (!emstorage_get_save_name(account_id, mail_id, 0, NULL, buf, sizeof(buf),NULL)) {
- EM_DEBUG_EXCEPTION("emstorage_get_save_name failed...");
- /* goto FINISH_OFF; */
- }
-
- if (!emstorage_delete_dir(buf, NULL)) {
- EM_DEBUG_EXCEPTION("emstorage_delete_dir failed...");
- /* goto FINISH_OFF; */
- }
-
-
- goto FINISH_OFF;
- }
-
- EM_SAFE_FREE(ai->save);
- ai->save = EM_SAFE_STRDUP(buf);
-
- attachment.attachment_path = ai->save;
-
- }
-
-#ifdef __FEATURE_PARTIAL_BODY_DOWNLOAD__
- /* Information : Attachment info already saved if partial body is dowloaded. */
- if (ai->type) {
- emstorage_attachment_tbl_t *attch_info = NULL;
- /* Get attachment details */
- if (!emstorage_get_attachment_nth(mail_id, attachment.attachment_id, &attch_info, true, &err) || !attch_info) {
- EM_DEBUG_EXCEPTION("emstorage_get_attachment_nth failed [%d]", err);
- if (err == EMAIL_ERROR_ATTACHMENT_NOT_FOUND) { /* save only attachment file. */
- if (!emstorage_add_attachment(&attachment, 0, false, &err)) {
- EM_DEBUG_EXCEPTION("emstorage_add_attachment failed [%d]", err);
- if (attch_info)
- emstorage_free_attachment(&attch_info, 1, NULL);
- /* delete all created files. */
- if (!emstorage_get_save_name(account_id, mail_id, 0, NULL, buf, sizeof(buf), &err)) {
- EM_DEBUG_EXCEPTION("emstorage_get_save_name failed [%d]", err);
- goto FINISH_OFF;
- }
-
- if (!emstorage_delete_dir(buf, &err)) {
- EM_DEBUG_EXCEPTION("emstorage_delete_dir failed [%d]", err);
- goto FINISH_OFF;
- }
-
- /* ROLLBACK TRANSACTION; */
- emstorage_rollback_transaction(NULL, NULL, NULL);
-
-
- goto FINISH_OFF;
- }
- }
- }
- else {
- EM_DEBUG_LOG("Attachment info already exists...!");
- /* Update attachment size */
- EM_DEBUG_LOG("attachment_size [%d], ai->size [%d]", attch_info->attachment_size, ai->size);
- attch_info->attachment_size = ai->size;
- attch_info->attachment_save_status = attachment.attachment_save_status;
- if (!emstorage_update_attachment(attch_info, true, &err)) {
- EM_DEBUG_EXCEPTION("emstorage_update_attachment failed [%d]", err);
- emstorage_free_attachment(&attch_info, 1, NULL); /*prevent 17956*/
- goto FINISH_OFF;
- }
- }
-
- if (attch_info)
- emstorage_free_attachment(&attch_info, 1, NULL);
- }
-
-#else
-
- if (ai->type) {
- mail->attachment_yn = 1;
- /* save only attachment file. */
- if (!emstorage_add_attachment(&attachment, 0, false, &err)) {
- EM_DEBUG_EXCEPTION("emstorage_add_attachment failed [%d]", err);
- if (bIsAdd_to_mmc) {
- if (attachment.attachment) {
- }
- }
- else {
- /* delete all created files. */
- if (!emstorage_get_save_name(account_id, mail_id, 0, NULL, buf, &err)) {
- EM_DEBUG_EXCEPTION("emstorage_get_save_name failed [%d]", err);
- goto FINISH_OFF;
- }
-
- if (!emstorage_delete_dir(buf, &err)) {
- EM_DEBUG_EXCEPTION("emstorage_delete_dir failed [%d]", err);
- goto FINISH_OFF;
- }
-
- /* ROLLBACK TRANSACTION; */
- emstorage_rollback_transaction(NULL, NULL, NULL);
- goto FINISH_OFF;
- }
- }
- }
-#endif /* End of #ifdef __FEATURE_PARTIAL_BODY_DOWNLOAD__ */
-
- }
-
- mail->attachment_count = local_attachment_count;
- mail->inline_content_count = local_inline_content_count;
-
- /* change mail's information. */
- if (!emstorage_change_mail_field(mail_id, APPEND_BODY, mail, false, &err)) {
- EM_DEBUG_EXCEPTION("emstorage_change_mail_field failed [%d]", err);
- emstorage_rollback_transaction(NULL, NULL, NULL); /* ROLLBACK TRANSACTION; */
-
- goto FINISH_OFF;
- }
-
-#ifdef __FEATURE_BODY_SEARCH__
- /* strip html content and save into mail_text_tbl */
- char *stripped_text = NULL;
- if (!emcore_strip_mail_body_from_file(mail, &stripped_text, &err) || stripped_text == NULL) {
- EM_DEBUG_EXCEPTION("emcore_strip_mail_body_from_file failed [%d]", err);
- }
-
- emstorage_mail_text_tbl_t *mail_text;
- if (!emstorage_get_mail_text_by_id(mail_id, &mail_text, true, &err) || !mail_text) {
- EM_DEBUG_EXCEPTION("emstorage_get_mail_text_by_id failed [%d]", err);
- emstorage_rollback_transaction(NULL, NULL, NULL); /* ROLLBACK TRANSACTION; */
- EM_SAFE_FREE(stripped_text);
- goto FINISH_OFF;
- }
-
- EM_SAFE_FREE(mail_text->body_text);
- mail_text->body_text = stripped_text;
-
- if (!emstorage_change_mail_text_field(mail_id, mail_text, false, &err)) {
- EM_DEBUG_EXCEPTION("emstorage_change_mail_text_field failed [%d]", err);
- emstorage_rollback_transaction(NULL, NULL, NULL); /* ROLLBACK TRANSACTION; */
- emstorage_free_mail_text(&mail_text, 1, NULL); /*prevent 17957*/
- goto FINISH_OFF;
- }
-
- if (mail_text)
- emstorage_free_mail_text(&mail_text, 1, NULL);
-#endif
-
- EM_DEBUG_LOG("cnt_info->text.plain [%s], cnt_info->text.html [%s]", cnt_info->text.plain, cnt_info->text.html);
-
- /* in pop3 mail case, the mail is deleted from server after being downloaded. */
- if (ref_account->incoming_server_type == EMAIL_SERVER_TYPE_POP3) {
-#ifdef DELETE_AFTER_DOWNLOADING
- char delmsg[24];
-
- SNPRINTF(delmsg, sizeof(delmsg), "%d", msg_no);
-
- if (!ref_account->keep_mails_on_pop_server_after_download) {
- if (!emcore_delete_mails_from_pop3_server(&mbox, delmsg, &err))
- EM_DEBUG_EXCEPTION("emcore_delete_mails_from_pop3_server failed [%d]", err);
- }
-#endif
-
- }
-
- if (cancellable)
- FINISH_OFF_IF_EVENT_CANCELED (err, event_handle);
-
- ret = true;
-
-FINISH_OFF:
-
- if (ref_account) {
- emcore_free_account(ref_account);
- EM_SAFE_FREE(ref_account);
- }
-
-#if 0
- /* note that local stream should be freed here*/
- if (mail_stream == NULL && stream != NULL) {
- stream = mail_close (stream);
- }
-#endif
-
- multi_part_body_size = 0;
- _pop3_received_body_size = 0;
- _pop3_last_notified_body_size = 0;
- _pop3_total_body_size = 0;
- _pop3_receiving_mail_id = 0;
-
- _imap4_received_body_size = 0;
- _imap4_last_notified_body_size = 0;
- _imap4_total_body_size = 0;
- _imap4_download_noti_interval_value = 0;
-
- if (cnt_info) {
- emcore_free_content_info(cnt_info);
- EM_SAFE_FREE(cnt_info);
- }
- if (mail)
- emstorage_free_mail(&mail, 1, NULL);
- EM_SAFE_FREE(s_uid);
-
- multi_part_body_size = 0;
-
- if (ret == true)
- emcore_notify_network_event(NOTI_DOWNLOAD_BODY_FINISH, mail_id, NULL, event_handle, 0);
- else
- emcore_notify_network_event(NOTI_DOWNLOAD_BODY_FAIL, mail_id, NULL, event_handle, err);
-
- if (err_code != NULL)
- *err_code = err;
-
- return ret;
-}
-
-INTERNAL_FUNC int emcore_gmime_download_body_sections(void *mail_stream,
- int account_id, int mail_id, int with_attach, int limited_size,
- int event_handle, int cancellable, int auto_download, int *err_code)
+INTERNAL_FUNC int emcore_gmime_download_body_sections(char *multi_user_name,
+ void *mail_stream,
+ int account_id,
+ int mail_id,
+ int with_attach,
+ int limited_size,
+ int event_handle,
+ int cancellable,
+ int auto_download,
+ int *err_code)
{
EM_DEBUG_FUNC_BEGIN("mail_stream[%p], account_id[%d], mail_id[%d], "
"with_attach[%d], event_handle [%d]", mail_stream, account_id, mail_id,
@@ -3518,7 +2573,8 @@ INTERNAL_FUNC int emcore_gmime_download_body_sections(void *mail_stream,
struct attachment_info *ai = NULL;
char *s_uid = NULL;
- char buf[512] = {0};
+ char move_buf[512] = {0};
+ char path_buf[512] = {0};
int msgno = 0;
int attachment_num = 1;
@@ -3548,7 +2604,7 @@ INTERNAL_FUNC int emcore_gmime_download_body_sections(void *mail_stream,
FINISH_OFF_IF_EVENT_CANCELED (err, event_handle);
/* looking for mail by mail_id in DB*/
- if (!emstorage_get_mail_by_id (mail_id, &mail, true, &err) || !mail) {
+ if (!emstorage_get_mail_by_id (multi_user_name, mail_id, &mail, true, &err) || !mail) {
EM_DEBUG_EXCEPTION("emstorage_get_mail_by_id failed [%d]", err);
goto FINISH_OFF;
}
@@ -3573,7 +2629,7 @@ INTERNAL_FUNC int emcore_gmime_download_body_sections(void *mail_stream,
s_uid = EM_SAFE_STRDUP(mail->server_mail_id);
- if (!(ref_account = emcore_get_account_reference(account_id))) {
+ if (!(ref_account = emcore_get_account_reference(multi_user_name, account_id, false))) {
EM_DEBUG_EXCEPTION("emcore_get_account_reference failed [%d]", account_id);
err = EMAIL_ERROR_INVALID_ACCOUNT;
goto FINISH_OFF;
@@ -3586,7 +2642,7 @@ INTERNAL_FUNC int emcore_gmime_download_body_sections(void *mail_stream,
if (!mail_stream) {
#if 0
MAILSTREAM *tmp_stream = NULL;
- if (!emcore_connect_to_remote_mailbox(account_id, mail->mailbox_id, (void **)&tmp_stream, &err) || !tmp_stream) {
+ if (!emcore_connect_to_remote_mailbox(multi_user_name, account_id, mail->mailbox_id, (void **)&tmp_stream, &err) || !tmp_stream) {
EM_DEBUG_EXCEPTION("emcore_connect_to_remote_mailbox failed [%d]", err);
goto FINISH_OFF;
}
@@ -3594,7 +2650,7 @@ INTERNAL_FUNC int emcore_gmime_download_body_sections(void *mail_stream,
#endif
MAILSTREAM **mstream = NULL;
- mstream = emcore_get_recv_stream (account_id, mail->mailbox_id, &err);
+ mstream = emcore_get_recv_stream (multi_user_name, account_id, mail->mailbox_id, &err);
if (!mstream) {
EM_DEBUG_EXCEPTION("emcore_get_recv_stream failed [%d]", err);
@@ -3628,7 +2684,7 @@ INTERNAL_FUNC int emcore_gmime_download_body_sections(void *mail_stream,
mailbox.account_id = account_id;
/* download all uids from server. */
- if (!emcore_download_uid_all (stream, &mailbox, &uid_list, NULL, NULL, 0, EM_CORE_GET_UIDS_FOR_NO_DELETE, &err)) {
+ if (!emcore_download_uid_all (multi_user_name, stream, &mailbox, &uid_list, NULL, NULL, 0, EM_CORE_GET_UIDS_FOR_NO_DELETE, &err)) {
EM_DEBUG_EXCEPTION("emcore_download_uid_all failed [%d]", err);
goto FINISH_OFF;
}
@@ -3676,7 +2732,7 @@ INTERNAL_FUNC int emcore_gmime_download_body_sections(void *mail_stream,
goto FINISH_OFF;
}
- while(emcore_mime_get_line_from_sock((void *)stream, sock_buf, 1024, &err)) {
+ while (emcore_mime_get_line_from_sock((void *)stream, sock_buf, 1024, &err)) {
if (write(fd, sock_buf, EM_SAFE_STRLEN(sock_buf)) != EM_SAFE_STRLEN(sock_buf)) {
EM_DEBUG_EXCEPTION("write failed");
}
@@ -3755,7 +2811,8 @@ INTERNAL_FUNC int emcore_gmime_download_body_sections(void *mail_stream,
/* FETCH sections and set content to message */
if (!emcore_gmime_fetch_imap_body_sections(stream, uid, mail_id,
- cnt_info, message1, event_handle, auto_download, &err)) {
+ cnt_info, message1, event_handle,
+ auto_download, &err)) {
EM_DEBUG_EXCEPTION("emcore_gmime_get_imap_sections failed");
goto FINISH_OFF;
}
@@ -3763,6 +2820,10 @@ INTERNAL_FUNC int emcore_gmime_download_body_sections(void *mail_stream,
/* decoding contents */
g_mime_message_foreach(message1, emcore_gmime_imap_parse_full_foreach_cb, (gpointer)cnt_info);
+ /* Get mime entity */
+ if (cnt_info->content_type == 1)
+ g_mime_message_foreach(message1, emcore_gmime_get_mime_entity_cb, (gpointer)cnt_info);
+
/* free resources */
if (message1) {
g_object_unref(message1);
@@ -3806,29 +2867,37 @@ INTERNAL_FUNC int emcore_gmime_download_body_sections(void *mail_stream,
}
EM_DEBUG_LOG("PLAIN DEFAULT CHARSET : %s", charset_plain_text);
- if (!emstorage_create_dir(account_id, mail_id, 0, &err)) {
+ memset(move_buf, 0x00, sizeof(move_buf));
+ memset(path_buf, 0x00, sizeof(path_buf));
+
+ if (!emstorage_create_dir(multi_user_name, account_id, mail_id, 0, &err)) {
EM_DEBUG_EXCEPTION("emstorage_create_dir failed [%d]", err);
goto FINISH_OFF;
}
- if (!emstorage_get_save_name(account_id, mail_id, 0, charset_plain_text, buf, sizeof(buf), &err)) {
+ if (!emstorage_get_save_name(multi_user_name, account_id, mail_id, 0,
+ charset_plain_text, move_buf, path_buf,
+ sizeof(path_buf), &err)) {
EM_DEBUG_EXCEPTION("emstorage_get_save_name failed [%d]", err);
goto FINISH_OFF;
}
- if (!emstorage_move_file(cnt_info->text.plain, buf, false, &err)) {
+ if (!emstorage_move_file(cnt_info->text.plain, move_buf, false, &err)) {
EM_DEBUG_EXCEPTION("emstorage_move_file failed [%d]", err);
goto FINISH_OFF;
}
EM_SAFE_FREE(mail->file_path_plain);
- mail->file_path_plain = EM_SAFE_STRDUP(buf);
+ mail->file_path_plain = EM_SAFE_STRDUP(path_buf);
EM_DEBUG_LOG_SEC("mail->file_path_plain [%s]", mail->file_path_plain);
}
/* text/html */
if (cnt_info->text.html) {
- if (!emstorage_create_dir(account_id, mail_id, 0, &err)) {
+ memset(move_buf, 0x00, sizeof(move_buf));
+ memset(path_buf, 0x00, sizeof(path_buf));
+
+ if (!emstorage_create_dir(multi_user_name, account_id, mail_id, 0, &err)) {
EM_DEBUG_EXCEPTION("emstorage_create_dir failed [%d]", err);
goto FINISH_OFF;
}
@@ -3845,23 +2914,47 @@ INTERNAL_FUNC int emcore_gmime_download_body_sections(void *mail_stream,
memcpy(html_body, "UTF-8.htm", strlen("UTF-8.htm"));
}
- if (!emstorage_get_save_name(account_id, mail_id, 0, html_body, buf, sizeof(buf), &err)) {
+ if (!emstorage_get_save_name(multi_user_name, account_id, mail_id, 0, html_body, move_buf, path_buf, sizeof(path_buf), &err)) {
EM_DEBUG_EXCEPTION("emstorage_get_save_name failed [%d]", err);
goto FINISH_OFF;
}
- if (!emstorage_move_file(cnt_info->text.html, buf, false, &err)) {
+ if (!emstorage_move_file(cnt_info->text.html, move_buf, false, &err)) {
EM_DEBUG_EXCEPTION("emstorage_move_file failed [%d]", err);
goto FINISH_OFF;
}
EM_SAFE_FREE(mail->file_path_html);
- mail->file_path_html = EM_SAFE_STRDUP(buf);
+ mail->file_path_html = EM_SAFE_STRDUP(path_buf);
+ }
+
+ /* mime_entity */
+ if (cnt_info->text.mime_entity) {
+ memset(move_buf, 0x00, sizeof(move_buf));
+ memset(path_buf, 0x00, sizeof(path_buf));
+
+ if (!emstorage_get_save_name(multi_user_name, account_id, mail_id,
+ 0, "mime_entity", move_buf, path_buf,
+ sizeof(path_buf), &err)) {
+ EM_DEBUG_EXCEPTION("emstorage_get_save_name failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ if (!emstorage_move_file(cnt_info->text.mime_entity, move_buf, false, &err)) {
+ EM_DEBUG_EXCEPTION("emstorage_move_file failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ EM_SAFE_FREE(mail->file_path_mime_entity);
+ mail->file_path_mime_entity = EM_SAFE_STRDUP(path_buf);
}
/* Update local_preview_text */
- if ((err = emcore_get_preview_text_from_file (mail->file_path_plain,
- mail->file_path_html, MAX_PREVIEW_TEXT_LENGTH, &mail->preview_text)) != EMAIL_ERROR_NONE) {
+ if ((err = emcore_get_preview_text_from_file (multi_user_name,
+ mail->file_path_plain,
+ mail->file_path_html,
+ MAX_PREVIEW_TEXT_LENGTH,
+ &mail->preview_text)) != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("emcore_get_preview_text_from_file error [%d]", err);
}
@@ -3879,9 +2972,14 @@ INTERNAL_FUNC int emcore_gmime_download_body_sections(void *mail_stream,
int attachment_num_from_cnt_info;
int inline_attachment_num_from_cnt_info;
- if ((err = emcore_update_attachment_except_inline(cnt_info, mail->account_id,
- mail->mail_id, mail->mailbox_id, &total_attachment_size,
- &attachment_num_from_cnt_info, &inline_attachment_num_from_cnt_info)) != EMAIL_ERROR_NONE) {
+ if ((err = emcore_update_attachment_except_inline(multi_user_name,
+ cnt_info,
+ mail->account_id,
+ mail->mail_id,
+ mail->mailbox_id,
+ &total_attachment_size,
+ &attachment_num_from_cnt_info,
+ &inline_attachment_num_from_cnt_info)) != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("emcore_update_attachment_except_inline failed : [%d]", err);
goto FINISH_OFF;
}
@@ -3894,6 +2992,7 @@ INTERNAL_FUNC int emcore_gmime_download_body_sections(void *mail_stream,
if (b_with_attach == 0) {
attachment_num++;
+ if (ai->save) g_remove(ai->save);
ai = ai->next;
continue;
}
@@ -3923,26 +3022,29 @@ INTERNAL_FUNC int emcore_gmime_download_body_sections(void *mail_stream,
continue;
}
- if (!emstorage_create_dir(account_id, mail_id, attachment_num, &err)) {
+ memset(move_buf, 0x00, sizeof(move_buf));
+ memset(path_buf, 0x00, sizeof(path_buf));
+
+ if (!emstorage_create_dir(multi_user_name, account_id, mail_id, attachment_num, &err)) {
EM_DEBUG_EXCEPTION("emstorage_create_dir failed [%d]", err);
goto FINISH_OFF;
}
- if (!emstorage_get_save_name(account_id, mail_id, attachment_num, attachment.attachment_name, buf, sizeof(buf), &err)) {
+ if (!emstorage_get_save_name(multi_user_name, account_id, mail_id, attachment_num, attachment.attachment_name, move_buf, path_buf, sizeof(path_buf), &err)) {
EM_DEBUG_EXCEPTION("emstorage_get_save_name failed [%d]", err);
goto FINISH_OFF;
}
- if (!emstorage_move_file(ai->save, buf, false, &err)) {
+ if (!emstorage_move_file(ai->save, move_buf, false, &err)) {
EM_DEBUG_EXCEPTION("emstorage_move_file failed [%d]", err);
/* delete all created files. */
- if (!emstorage_get_save_name(account_id, mail_id, 0, NULL, buf, sizeof(buf), NULL)) {
+ if (!emstorage_get_save_name(multi_user_name, account_id, mail_id, 0, NULL, move_buf, path_buf, sizeof(path_buf), NULL)) {
EM_DEBUG_EXCEPTION("emstorage_get_save_name failed...");
/* goto FINISH_OFF; */
}
- if (!emstorage_delete_dir(buf, NULL)) {
+ if (!emstorage_delete_dir(move_buf, NULL)) {
EM_DEBUG_EXCEPTION("emstorage_delete_dir failed...");
/* goto FINISH_OFF; */
}
@@ -3951,33 +3053,33 @@ INTERNAL_FUNC int emcore_gmime_download_body_sections(void *mail_stream,
}
EM_SAFE_FREE(ai->save);
- ai->save = EM_SAFE_STRDUP(buf);
+ ai->save = EM_SAFE_STRDUP(path_buf);
attachment.attachment_path = ai->save;
/* Get attachment details */
- if (!emstorage_get_attachment_nth(mail_id, attachment.attachment_id, &attch_info, true, &err) || !attch_info) {
+ if (!emstorage_get_attachment_nth(multi_user_name, mail_id, attachment.attachment_id, &attch_info, true, &err) || !attch_info) {
EM_DEBUG_EXCEPTION("emstorage_get_attachment_nth failed [%d]", err);
if (err == EMAIL_ERROR_ATTACHMENT_NOT_FOUND) { /* save only attachment file. */
- if (!emstorage_add_attachment(&attachment, 0, false, &err)) {
+ if (!emstorage_add_attachment(multi_user_name, &attachment, 0, false, &err)) {
EM_DEBUG_EXCEPTION("emstorage_add_attachment failed [%d]", err);
if (attch_info)
emstorage_free_attachment(&attch_info, 1, NULL);
/* delete all created files. */
- if (!emstorage_get_save_name(account_id, mail_id, 0, NULL, buf, sizeof(buf), &err)) {
+ if (!emstorage_get_save_name(multi_user_name, account_id, mail_id, 0, NULL, move_buf, path_buf, sizeof(path_buf), &err)) {
EM_DEBUG_EXCEPTION("emstorage_get_save_name failed [%d]", err);
goto FINISH_OFF;
}
- if (!emstorage_delete_dir(buf, &err)) {
+ if (!emstorage_delete_dir(move_buf, &err)) {
EM_DEBUG_EXCEPTION("emstorage_delete_dir failed [%d]", err);
goto FINISH_OFF;
}
/* ROLLBACK TRANSACTION; */
- emstorage_rollback_transaction(NULL, NULL, NULL);
+ emstorage_rollback_transaction(multi_user_name, NULL, NULL, NULL);
goto FINISH_OFF;
}
@@ -4001,7 +3103,7 @@ INTERNAL_FUNC int emcore_gmime_download_body_sections(void *mail_stream,
attch_info->attachment_inline_content_status = 0;
attch_info->attachment_mime_type = EM_SAFE_STRDUP(attachment.attachment_mime_type);
- if (!emstorage_update_attachment(attch_info, true, &err)) {
+ if (!emstorage_update_attachment(multi_user_name, attch_info, true, &err)) {
EM_DEBUG_EXCEPTION("emstorage_update_attachment failed [%d]", err);
emstorage_free_attachment(&attch_info, 1, NULL); /*prevent 17956*/
goto FINISH_OFF;
@@ -4045,25 +3147,29 @@ INTERNAL_FUNC int emcore_gmime_download_body_sections(void *mail_stream,
continue;
}
- if (!emstorage_create_dir(account_id, mail_id, 0, &err)) {
+ memset(move_buf, 0x00, sizeof(move_buf));
+ memset(path_buf, 0x00, sizeof(path_buf));
+
+ if (!emstorage_create_dir(multi_user_name, account_id, mail_id, 0, &err)) {
EM_DEBUG_EXCEPTION("emstorage_create_dir failed [%d]", err);
goto FINISH_OFF;
}
- if (!emstorage_get_save_name(account_id, mail_id, 0, attachment.attachment_name, buf, sizeof(buf), &err)) {
+
+ if (!emstorage_get_save_name(multi_user_name, account_id, mail_id, 0, attachment.attachment_name, move_buf, path_buf, sizeof(path_buf), &err)) {
EM_DEBUG_EXCEPTION("emstorage_get_save_name failed [%d]", err);
goto FINISH_OFF;
}
- if (!emstorage_move_file(ai->save, buf, false, &err)) {
+ if (!emstorage_move_file(ai->save, move_buf, false, &err)) {
EM_DEBUG_EXCEPTION("emstorage_move_file failed [%d]", err);
/* delete all created files. */
- if (!emstorage_get_save_name(account_id, mail_id, 0, NULL, buf, sizeof(buf), NULL)) {
+ if (!emstorage_get_save_name(multi_user_name, account_id, mail_id, 0, NULL, move_buf, path_buf, sizeof(path_buf), NULL)) {
EM_DEBUG_EXCEPTION("emstorage_get_save_name failed...");
/* goto FINISH_OFF; */
}
- if (!emstorage_delete_dir(buf, NULL)) {
+ if (!emstorage_delete_dir(move_buf, NULL)) {
EM_DEBUG_EXCEPTION("emstorage_delete_dir failed...");
/* goto FINISH_OFF; */
}
@@ -4072,34 +3178,33 @@ INTERNAL_FUNC int emcore_gmime_download_body_sections(void *mail_stream,
}
EM_SAFE_FREE(ai->save);
- ai->save = EM_SAFE_STRDUP(buf);
+ ai->save = EM_SAFE_STRDUP(path_buf);
attachment.attachment_path = ai->save;
/* Get attachment details */
- if (!emstorage_get_attachment_nth(mail_id, attachment.attachment_id, &attch_info, true, &err) || !attch_info) {
+ if (!emstorage_get_attachment_nth(multi_user_name, mail_id, attachment.attachment_id, &attch_info, true, &err) || !attch_info) {
EM_DEBUG_EXCEPTION("emstorage_get_attachment_nth failed [%d]", err);
if (err == EMAIL_ERROR_ATTACHMENT_NOT_FOUND) { /* save only attachment file. */
- if (!emstorage_add_attachment(&attachment, 0, false, &err)) {
+ if (!emstorage_add_attachment(multi_user_name, &attachment, 0, false, &err)) {
EM_DEBUG_EXCEPTION("emstorage_add_attachment failed [%d]", err);
if (attch_info)
emstorage_free_attachment(&attch_info, 1, NULL);
/* delete all created files. */
- if (!emstorage_get_save_name(account_id, mail_id, 0, NULL, buf, sizeof(buf), &err)) {
+ if (!emstorage_get_save_name(multi_user_name, account_id, mail_id, 0, NULL, move_buf, path_buf, sizeof(path_buf), &err)) {
EM_DEBUG_EXCEPTION("emstorage_get_save_name failed [%d]", err);
goto FINISH_OFF;
}
- if (!emstorage_delete_dir(buf, &err)) {
+ if (!emstorage_delete_dir(move_buf, &err)) {
EM_DEBUG_EXCEPTION("emstorage_delete_dir failed [%d]", err);
goto FINISH_OFF;
}
/* ROLLBACK TRANSACTION; */
- emstorage_rollback_transaction(NULL, NULL, NULL);
-
+ emstorage_rollback_transaction(multi_user_name, NULL, NULL, NULL);
goto FINISH_OFF;
}
}
@@ -4122,7 +3227,7 @@ INTERNAL_FUNC int emcore_gmime_download_body_sections(void *mail_stream,
attch_info->attachment_inline_content_status = 1;
attch_info->attachment_mime_type = EM_SAFE_STRDUP(attachment.attachment_mime_type);
- if (!emstorage_update_attachment(attch_info, true, &err)) {
+ if (!emstorage_update_attachment(multi_user_name, attch_info, true, &err)) {
EM_DEBUG_EXCEPTION("emstorage_update_attachment failed [%d]", err);
emstorage_free_attachment(&attch_info, 1, NULL); /*prevent 17956*/
goto FINISH_OFF;
@@ -4140,24 +3245,23 @@ INTERNAL_FUNC int emcore_gmime_download_body_sections(void *mail_stream,
mail->inline_content_count = local_inline_content_count;
/* change mail's information. */
- if (!emstorage_change_mail_field(mail_id, APPEND_BODY, mail, false, &err)) {
+ if (!emstorage_change_mail_field(multi_user_name, mail_id, APPEND_BODY, mail, false, &err)) {
EM_DEBUG_EXCEPTION("emstorage_change_mail_field failed [%d]", err);
- emstorage_rollback_transaction(NULL, NULL, NULL); /* ROLLBACK TRANSACTION; */
-
+ emstorage_rollback_transaction(multi_user_name, NULL, NULL, NULL); /* ROLLBACK TRANSACTION; */
goto FINISH_OFF;
}
#ifdef __FEATURE_BODY_SEARCH__
/* strip html content and save into mail_text_tbl */
char *stripped_text = NULL;
- if (!emcore_strip_mail_body_from_file(mail, &stripped_text, &err) || stripped_text == NULL) {
+ if (!emcore_strip_mail_body_from_file(multi_user_name, mail, &stripped_text, &err) || stripped_text == NULL) {
EM_DEBUG_EXCEPTION("emcore_strip_mail_body_from_file failed [%d]", err);
}
emstorage_mail_text_tbl_t *mail_text;
- if (!emstorage_get_mail_text_by_id(mail_id, &mail_text, true, &err) || !mail_text) {
+ if (!emstorage_get_mail_text_by_id(multi_user_name, mail_id, &mail_text, true, &err) || !mail_text) {
EM_DEBUG_EXCEPTION("emstorage_get_mail_text_by_id failed [%d]", err);
- emstorage_rollback_transaction(NULL, NULL, NULL); /* ROLLBACK TRANSACTION; */
+ emstorage_rollback_transaction(multi_user_name, NULL, NULL, NULL); /* ROLLBACK TRANSACTION; */
EM_SAFE_FREE(stripped_text);
goto FINISH_OFF;
}
@@ -4165,9 +3269,9 @@ INTERNAL_FUNC int emcore_gmime_download_body_sections(void *mail_stream,
EM_SAFE_FREE(mail_text->body_text);
mail_text->body_text = stripped_text;
- if (!emstorage_change_mail_text_field(mail_id, mail_text, false, &err)) {
+ if (!emstorage_change_mail_text_field(multi_user_name, mail_id, mail_text, false, &err)) {
EM_DEBUG_EXCEPTION("emstorage_change_mail_text_field failed [%d]", err);
- emstorage_rollback_transaction(NULL, NULL, NULL); /* ROLLBACK TRANSACTION; */
+ emstorage_rollback_transaction(multi_user_name, NULL, NULL, NULL); /* ROLLBACK TRANSACTION; */
emstorage_free_mail_text(&mail_text, 1, NULL); /*prevent 17957*/
goto FINISH_OFF;
}
@@ -4186,7 +3290,7 @@ INTERNAL_FUNC int emcore_gmime_download_body_sections(void *mail_stream,
SNPRINTF(delmsg, sizeof(delmsg), "%d", msg_no);
if (!ref_account->keep_mails_on_pop_server_after_download) {
- if (!emcore_delete_mails_from_pop3_server(&mbox, delmsg, &err))
+ if (!emcore_delete_mails_from_pop3_server(multi_user_name, &mbox, delmsg, &err))
EM_DEBUG_EXCEPTION("emcore_delete_mails_from_pop3_server failed [%d]", err);
}
#endif
@@ -4201,7 +3305,7 @@ FINISH_OFF:
if (ref_account) {
emcore_free_account(ref_account);
- EM_SAFE_FREE(ref_account);
+ free(ref_account);
}
#if 0
@@ -4220,7 +3324,7 @@ FINISH_OFF:
if (cnt_info) {
emcore_free_content_info(cnt_info);
- EM_SAFE_FREE(cnt_info);
+ free(cnt_info);
}
if (mail)
@@ -4268,12 +3372,12 @@ void emcore_mail_copyuid(MAILSTREAM *stream, char *mailbox,
sprintf(g_new_server_uid, "%ld", destset->first);
EM_DEBUG_LOG(">>>>> new_server_uid =%s", g_new_server_uid);
- if (!emstorage_update_server_uid(old_server_uid, g_new_server_uid, NULL)) {
+ if (!emstorage_update_server_uid(NULL, old_server_uid, g_new_server_uid, NULL)) {
EM_DEBUG_EXCEPTION("emstorage_update_server_uid falied...");
}
}
-static int emcore_delete_mails_from_remote_server(int input_account_id, int input_mail_ids[], int input_mail_id_count, int input_delete_option)
+static int emcore_delete_mails_from_remote_server(char *multi_user_name, int input_account_id, int input_mail_ids[], int input_mail_id_count, int input_delete_option)
{
EM_DEBUG_FUNC_BEGIN("input_account_id[%d], input_mail_ids[%p], input_mail_id_count[%d], input_delete_option [%d]", input_account_id, input_mail_ids, input_mail_id_count, input_delete_option);
@@ -4286,7 +3390,7 @@ static int emcore_delete_mails_from_remote_server(int input_account_id, int inpu
int bulk_flag = false;
#endif
- if (!(account = emcore_get_account_reference(input_account_id))) {
+ if (!(account = emcore_get_account_reference(multi_user_name, input_account_id, false))) {
EM_DEBUG_EXCEPTION("emcore_get_account_reference failed [%d]", input_account_id);
err = EMAIL_ERROR_INVALID_ACCOUNT;
goto FINISH_OFF;
@@ -4319,7 +3423,7 @@ static int emcore_delete_mails_from_remote_server(int input_account_id, int inpu
EM_DEBUG_EXCEPTION(" emcore_notify_storage_event failed [ NOTI_DELETE_MAIL_START ] >>>> ");
if (account->incoming_server_type == EMAIL_SERVER_TYPE_IMAP4) {
- if (!bulk_flag && !emcore_delete_mails_from_imap4_server(input_mail_ids, input_mail_id_count, input_delete_option, &err)) {
+ if (!bulk_flag && !emcore_delete_mails_from_imap4_server(multi_user_name, input_mail_ids, input_mail_id_count, input_delete_option, &err)) {
EM_DEBUG_EXCEPTION("emcore_delete_mails_from_imap4_server failed [%d]", err);
if (err == EMAIL_ERROR_IMAP4_STORE_FAILURE)
err = EMAIL_ERROR_MAIL_NOT_FOUND_ON_SERVER;
@@ -4330,7 +3434,7 @@ static int emcore_delete_mails_from_remote_server(int input_account_id, int inpu
#ifdef __FEATURE_WIFI_AUTO_DOWNLOAD__
for(i = 0; i < input_mail_id_count; i++) {
- if (!emcore_delete_auto_download_activity(input_account_id, input_mail_ids[i], 0, &err)) {
+ if (!emcore_delete_auto_download_activity(multi_user_name, input_account_id, input_mail_ids[i], 0, &err)) {
EM_DEBUG_EXCEPTION("emcore_delete_auto_download_activity failed [%d]", err);
}
}
@@ -4338,14 +3442,14 @@ static int emcore_delete_mails_from_remote_server(int input_account_id, int inpu
}
}
else if (account->incoming_server_type == EMAIL_SERVER_TYPE_POP3) {
- if (!emcore_delete_mails_from_pop3_server(account, input_mail_ids, input_mail_id_count)) {
+ if (!emcore_delete_mails_from_pop3_server(multi_user_name, account, input_mail_ids, input_mail_id_count)) {
EM_DEBUG_EXCEPTION("emcore_delete_mails_from_pop3_server falied [%d]", err);
goto FINISH_OFF;
}
#ifdef __FEATURE_WIFI_AUTO_DOWNLOAD__
else {
for(i = 0; i < input_mail_id_count; i++) {
- if (!emcore_delete_auto_download_activity(input_account_id, input_mail_ids[i], 0, &err)) {
+ if (!emcore_delete_auto_download_activity(multi_user_name, input_account_id, input_mail_ids[i], 0, &err)) {
EM_DEBUG_EXCEPTION("emcore_delete_auto_download_activity failed [%d]", err);
}
}
@@ -4375,7 +3479,7 @@ static int emcore_delete_mails_from_remote_server(int input_account_id, int inpu
}
/* Fix for issue - Sometimes mail move and immediately followed by mail delete is not reflected on server */
- if (!emstorage_remove_downloaded_mail(input_account_id, mail->server_mailbox_name, mail->server_mail_id, true, &err)) {
+ if (!emstorage_remove_downloaded_mail(multi_user_name, input_account_id, mail->server_mailbox_name, mail->server_mail_id, true, &err)) {
EM_DEBUG_LOG("emstorage_remove_downloaded_mail falied [%d]", err);
}
}
@@ -4405,7 +3509,7 @@ FINISH_OFF:
return err;
}
-int emcore_delete_mail(int account_id, int mail_ids[], int num, int from_server, int noti_param_1, int noti_param_2, int *err_code)
+int emcore_delete_mail(char *multi_user_name, int account_id, int mail_ids[], int num, int from_server, int noti_param_1, int noti_param_2, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("account_id[%d], mail_ids[%p], num[%d], from_server[%d], noti_param_1 [%d], noti_param_2 [%d], err_code[%p]", account_id, mail_ids, num, from_server, noti_param_1, noti_param_2, err_code);
@@ -4419,7 +3523,7 @@ int emcore_delete_mail(int account_id, int mail_ids[], int num, int from_server,
goto FINISH_OFF;
}
- if (!(account = emcore_get_account_reference(account_id))) {
+ if (!(account = emcore_get_account_reference(multi_user_name, account_id, false))) {
EM_DEBUG_EXCEPTION("emcore_get_account_reference failed [%d]", account_id);
err = EMAIL_ERROR_INVALID_ACCOUNT;
goto FINISH_OFF;
@@ -4429,11 +3533,11 @@ int emcore_delete_mail(int account_id, int mail_ids[], int num, int from_server,
/* FINISH_OFF_IF_CANCELED; */
if (from_server == EMAIL_DELETE_LOCALLY) /* Delete mails from local storage*/ {
- emcore_delete_mails_from_local_storage(account_id, mail_ids, num, noti_param_1, noti_param_2, err_code);
- emcore_display_unread_in_badge(NULL);
+ emcore_delete_mails_from_local_storage(multi_user_name, account_id, mail_ids, num, noti_param_1, noti_param_2, err_code);
+ emcore_display_unread_in_badge(multi_user_name);
}
else { /* Delete mails from server*/
- emcore_delete_mails_from_remote_server(account_id, mail_ids, num, from_server);
+ emcore_delete_mails_from_remote_server(multi_user_name, account_id, mail_ids, num, from_server);
}
@@ -4441,7 +3545,7 @@ int emcore_delete_mail(int account_id, int mail_ids[], int num, int from_server,
FINISH_OFF:
if (from_server)
- emcore_show_user_message(account_id, EMAIL_ACTION_DELETE_MAIL, ret == true ? 0 : err);
+ emcore_show_user_message(multi_user_name, account_id, EMAIL_ACTION_DELETE_MAIL, ret == true ? 0 : err);
if (account) {
emcore_free_account(account);
@@ -4501,22 +3605,23 @@ INTERNAL_FUNC void emcore_send_signal_for_del_account (int signal)
pthread_mutex_unlock (&mu_del_account);
}
-int emcore_delete_all_mails_of_acount(int input_account_id)
+int emcore_delete_all_mails_of_acount(char *multi_user_name, int input_account_id)
{
EM_DEBUG_FUNC_BEGIN("input_account_id [%d]");
int err = EMAIL_ERROR_NONE;
- char *buf = NULL;
+ char* move_buf = NULL;
+ char path_buf[512] = {0};
/* emstorage_delete_mail_by_account is available only locally */
- if (!emstorage_delete_mail_by_account(input_account_id, false, &err)) {
+ if (!emstorage_delete_mail_by_account(multi_user_name, input_account_id, false, &err)) {
if(err != EMAIL_ERROR_MAIL_NOT_FOUND) {
EM_DEBUG_EXCEPTION("emstorage_delete_mail_by_account failed [%d]", err);
goto FINISH_OFF;
}
}
- if (!emstorage_delete_attachment_all_on_db(input_account_id, NULL, false, &err)) {
+ if (!emstorage_delete_attachment_all_on_db(multi_user_name, input_account_id, NULL, false, &err)) {
if(err != EMAIL_ERROR_MAIL_NOT_FOUND) {
EM_DEBUG_EXCEPTION("emstorage_delete_attachment_all_on_db failed [%d]", err);
goto FINISH_OFF;
@@ -4524,37 +3629,43 @@ int emcore_delete_all_mails_of_acount(int input_account_id)
}
/* delete mail contents from filesystem */
- buf = em_malloc(512);
- if (!buf) {
+ move_buf = em_malloc (512);
+ if (!move_buf) {
EM_DEBUG_EXCEPTION("em_malloc failed");
goto FINISH_OFF;
}
- if (!emstorage_get_save_name(input_account_id, 0, 0, NULL, buf, 512, &err)) {
+ if (!emstorage_get_save_name(multi_user_name, input_account_id, 0, 0, NULL, move_buf, path_buf, sizeof(path_buf), &err)) {
EM_DEBUG_EXCEPTION("emstorage_get_save_name failed [%d]", err);
goto FINISH_OFF;
}
if (!del_thd)
- del_thd = em_thread_create(del_exit, NULL);
+ del_thd = em_thread_create (del_exit, NULL);
- em_thread_run(del_thd, del_dir, free_buf, buf);
+ em_thread_run (del_thd, del_dir, free_buf, move_buf);
/* delete meeting request */
- if (!emstorage_delete_meeting_request(input_account_id, 0, 0, false, &err)) {
+ if (!emstorage_delete_meeting_request(multi_user_name, input_account_id, 0, 0, false, &err)) {
EM_DEBUG_EXCEPTION("emstorage_delete_attachment_all_on_db failed [%d]", err);
goto FINISH_OFF;
}
FINISH_OFF:
-
+
EM_DEBUG_FUNC_END("err [%d]",err);
return err;
}
-INTERNAL_FUNC int emcore_delete_all_mails_of_mailbox(int input_account_id, int input_mailbox_id, int input_from_server, int *err_code)
+INTERNAL_FUNC int emcore_delete_all_mails_of_mailbox(char *multi_user_name,
+ int input_account_id,
+ int input_mailbox_id,
+ int input_mailbox_type,
+ int input_from_server,
+ int *err_code)
{
- EM_DEBUG_FUNC_BEGIN("input_account_id[%d] input_mailbox_id[%d] input_from_server[%d] err_code[%p]", input_account_id, input_mailbox_id, input_from_server, err_code);
+ EM_DEBUG_FUNC_BEGIN("input_account_id[%d] input_mailbox_id[%d] input_from_server[%d] err_code[%p]",
+ input_account_id, input_mailbox_id, input_from_server, err_code);
int ret = false;
int err = EMAIL_ERROR_NONE;
@@ -4562,22 +3673,49 @@ INTERNAL_FUNC int emcore_delete_all_mails_of_mailbox(int input_account_id, int i
int mail_id_count = 0;
char conditional_clause[QUERY_SIZE] = { 0, };
- if (!input_mailbox_id) {
+ if (input_mailbox_id <= 0 && input_mailbox_type <= 0) {
err = EMAIL_ERROR_INVALID_PARAM;
EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
goto FINISH_OFF;
}
/* Delete all mails in specific mailbox */
+ SNPRINTF(conditional_clause, QUERY_SIZE, " where ");
+
+ if (input_mailbox_id <= 0 && input_mailbox_type > 0) {
+ SNPRINTF(conditional_clause + strlen(conditional_clause),
+ QUERY_SIZE - strlen(conditional_clause),
+ "mailbox_type = %d ", input_mailbox_type);
+ } else if (input_mailbox_id > 0 && input_mailbox_type <= 0) {
+ SNPRINTF(conditional_clause + strlen(conditional_clause),
+ QUERY_SIZE - strlen(conditional_clause),
+ "mailbox_id = %d ", input_mailbox_id);
+ } else {
+ SNPRINTF(conditional_clause + strlen(conditional_clause),
+ QUERY_SIZE - strlen(conditional_clause),
+ "mailbox_type = %d and mailbox_id = %d ",
+ input_mailbox_type, input_mailbox_id);
+ }
- SNPRINTF(conditional_clause, QUERY_SIZE, " where mailbox_id = %d ", input_mailbox_id);
+ EM_DEBUG_LOG("command : [%s]", conditional_clause);
- emstorage_query_mail_id_list(conditional_clause, false, &mail_id_array, &mail_id_count);
+ err = emstorage_query_mail_id_list(multi_user_name, conditional_clause, false, &mail_id_array, &mail_id_count);
+ if (err != EMAIL_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("emstorage_query_mail_id_list failed : [%d]", err);
+ goto FINISH_OFF;
+ }
EM_DEBUG_LOG("emstorage_query_mail_id_list returns [%d]", mail_id_count);
if (mail_id_count > 0) {
- if (!emcore_delete_mail(input_account_id, mail_id_array, mail_id_count, input_from_server, EMAIL_DELETED_BY_COMMAND, false, &err)) {
+ if (!emcore_delete_mail(multi_user_name,
+ input_account_id,
+ mail_id_array,
+ mail_id_count,
+ input_from_server,
+ EMAIL_DELETED_BY_COMMAND,
+ false,
+ &err)) {
EM_DEBUG_EXCEPTION("emcore_delete_mail failed [%d]", err);
goto FINISH_OFF;
}
@@ -4586,6 +3724,7 @@ INTERNAL_FUNC int emcore_delete_all_mails_of_mailbox(int input_account_id, int i
ret = true;
FINISH_OFF:
+
EM_SAFE_FREE(mail_id_array);
if (err_code != NULL)
@@ -4595,21 +3734,23 @@ FINISH_OFF:
return ret;
}
-INTERNAL_FUNC int emcore_delete_mails_from_local_storage(int account_id, int *mail_ids, int num, int noti_param_1, int noti_param_2, int *err_code)
+INTERNAL_FUNC int emcore_delete_mails_from_local_storage(char *multi_user_name, int account_id, int *mail_ids, int num, int noti_param_1, int noti_param_2, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("account_id[%d], mail_ids[%p], num [%d], noti_param_1 [%d], noti_param_2 [%d], err_code[%p]", account_id, mail_ids, num, noti_param_1, noti_param_2, num, err_code);
int ret = false, err = EMAIL_ERROR_NONE, i;
emstorage_mail_tbl_t *result_mail_list = NULL;
- char mail_id_string[10], *noti_param_string = NULL, buf[512] = {0, };
+ char mail_id_string[10], *noti_param_string = NULL;
+ char move_buf[512] = {0, };
+ char path_buf[512] = {0,};
/* Getting mail list by using select mail_id [in] */
- if(!emstorage_get_mail_field_by_multiple_mail_id(mail_ids, num, RETRIEVE_SUMMARY, &result_mail_list, true, &err) || !result_mail_list) {
+ if(!emstorage_get_mail_field_by_multiple_mail_id(multi_user_name, mail_ids, num, RETRIEVE_SUMMARY, &result_mail_list, true, &err) || !result_mail_list) {
EM_DEBUG_EXCEPTION("emstorage_get_mail_field_by_multiple_mail_id failed [%d]", err);
goto FINISH_OFF;
}
/* Deleting mails by using select mail_id [in] */
- if(!emstorage_delete_multiple_mails(mail_ids, num, true, &err)) {
+ if(!emstorage_delete_multiple_mails(multi_user_name, mail_ids, num, true, &err)) {
EM_DEBUG_EXCEPTION("emstorage_delete_multiple_mails failed [%d]", err);
goto FINISH_OFF;
}
@@ -4636,7 +3777,17 @@ INTERNAL_FUNC int emcore_delete_mails_from_local_storage(int account_id, int *ma
/* Updating Thread informations */
for(i = 0; i < num; i++) {
if (result_mail_list[i].thread_id != 0) {
- if (!emstorage_update_latest_thread_mail(account_id, result_mail_list[i].mailbox_id, result_mail_list[i].thread_id, NULL, 0, 0, NOTI_THREAD_ID_CHANGED_BY_MOVE_OR_DELETE, false, &err)) {
+ if (!emstorage_update_latest_thread_mail(multi_user_name,
+ account_id,
+ result_mail_list[i].mailbox_id,
+ result_mail_list[i].mailbox_type,
+ result_mail_list[i].thread_id,
+ NULL,
+ 0,
+ 0,
+ NOTI_THREAD_ID_CHANGED_BY_MOVE_OR_DELETE,
+ false,
+ &err)) {
EM_DEBUG_EXCEPTION("emstorage_update_latest_thread_mail failed [%d]", err);
goto FINISH_OFF;
}
@@ -4649,7 +3800,7 @@ INTERNAL_FUNC int emcore_delete_mails_from_local_storage(int account_id, int *ma
for(i = 0; i < num; i++) {
/* Deleting attachments */
- if (!emstorage_delete_all_attachments_of_mail(result_mail_list[i].mail_id, false, &err)) {
+ if (!emstorage_delete_all_attachments_of_mail(multi_user_name, result_mail_list[i].mail_id, false, &err)) {
EM_DEBUG_EXCEPTION("emstorage_delete_all_attachments_of_mail failed [%d]", err);
if (err == EMAIL_ERROR_ATTACHMENT_NOT_FOUND)
err = EMAIL_ERROR_NONE;
@@ -4657,17 +3808,17 @@ INTERNAL_FUNC int emcore_delete_mails_from_local_storage(int account_id, int *ma
/* Deleting Directories */
/* delete mail contents from filesystem */
- if (!emstorage_get_save_name(account_id, result_mail_list[i].mail_id, 0, NULL, buf, sizeof(buf), &err)) {
+ if (!emstorage_get_save_name(multi_user_name, account_id, result_mail_list[i].mail_id, 0, NULL, move_buf, path_buf, sizeof(path_buf), &err)) {
EM_DEBUG_EXCEPTION("emstorage_get_save_name failed [%d]", err);
goto FINISH_OFF;
}
- if (!emstorage_delete_dir(buf, &err)) {
+ if (!emstorage_delete_dir(move_buf, &err)) {
EM_DEBUG_EXCEPTION("emstorage_delete_dir failed [%d]", err);
}
/* Deleting Meeting Request */
- if (!emstorage_delete_meeting_request(account_id, result_mail_list[i].mail_id, 0, false, &err)) {
+ if (!emstorage_delete_meeting_request(multi_user_name, account_id, result_mail_list[i].mail_id, 0, false, &err)) {
EM_DEBUG_EXCEPTION("emstorage_delete_meeting_request failed [%d]", err);
if (err != EMAIL_ERROR_CONTACT_NOT_FOUND) {
goto FINISH_OFF;
@@ -4675,7 +3826,7 @@ INTERNAL_FUNC int emcore_delete_mails_from_local_storage(int account_id, int *ma
}
/* Deleting mail_read_mail_uid_tbl */
- if (!emstorage_remove_downloaded_mail(account_id, result_mail_list[i].server_mailbox_name, result_mail_list[i].server_mail_id, true, &err)) {
+ if (!emstorage_remove_downloaded_mail(multi_user_name, account_id, result_mail_list[i].server_mailbox_name, result_mail_list[i].server_mail_id, true, &err)) {
EM_DEBUG_EXCEPTION("emstorage_remove_downloaded_mail failed [%d]", err);
goto FINISH_OFF;
}
@@ -4683,7 +3834,7 @@ INTERNAL_FUNC int emcore_delete_mails_from_local_storage(int account_id, int *ma
#ifdef __FEATURE_WIFI_AUTO_DOWNLOAD__
for(i = 0; i < num; i++) {
- if (!emcore_delete_auto_download_activity(account_id, mail_ids[i], 0, &err)) {
+ if (!emcore_delete_auto_download_activity(multi_user_name, account_id, mail_ids[i], 0, &err)) {
EM_DEBUG_EXCEPTION("emcore_delete_auto_download_activity failed [%d]", err);
}
}
@@ -4710,7 +3861,7 @@ FINISH_OFF:
return ret;
}
-static int emcore_delete_mails_from_pop3_server(email_account_t *input_account, int input_mail_ids[], int input_mail_id_count)
+static int emcore_delete_mails_from_pop3_server(char *multi_user_name, email_account_t *input_account, int input_mail_ids[], int input_mail_id_count)
{
EM_DEBUG_FUNC_BEGIN("input_account[%p], input_mail_ids[%p], input_mail_id_count[%d]", input_account, input_mail_ids, input_mail_id_count);
@@ -4734,9 +3885,8 @@ static int emcore_delete_mails_from_pop3_server(email_account_t *input_account,
mail_id = input_mail_ids[i];
- if (!emstorage_get_downloaded_mail(mail_id, &mail_tbl_data, false, &err) || !mail_tbl_data) {
+ if (!emstorage_get_downloaded_mail(multi_user_name, mail_id, &mail_tbl_data, false, &err) || !mail_tbl_data) {
EM_DEBUG_EXCEPTION("emstorage_get_downloaded_mail failed [%d]", err);
-
if (err == EMAIL_ERROR_MAIL_NOT_FOUND) { /* not server mail */
continue;
}
@@ -4745,7 +3895,7 @@ static int emcore_delete_mails_from_pop3_server(email_account_t *input_account,
}
if (stream == NULL) {
- if (!emcore_connect_to_remote_mailbox(input_account->account_id, 0, (void **)&stream, &err)) {
+ if (!emcore_connect_to_remote_mailbox(multi_user_name, input_account->account_id, 0, (void **)&stream, &err)) {
EM_DEBUG_EXCEPTION("emcore_connect_to_remote_mailbox failed [%d]", err);
goto FINISH_OFF;
}
@@ -4776,7 +3926,7 @@ static int emcore_delete_mails_from_pop3_server(email_account_t *input_account,
goto FINISH_OFF;
}
- if (!emstorage_remove_downloaded_mail(input_account->account_id, mail_tbl_data->server_mailbox_name, mail_tbl_data->server_mail_id, true, &err))
+ if (!emstorage_remove_downloaded_mail(multi_user_name, input_account->account_id, mail_tbl_data->server_mailbox_name, mail_tbl_data->server_mail_id, true, &err))
EM_DEBUG_LOG("emstorage_remove_downloaded_mail falied [%d]", err);
NOT_FOUND_ON_SERVER :
@@ -4863,7 +4013,7 @@ FINISH_OFF:
return ret;
}
-INTERNAL_FUNC int emcore_expunge_mails_deleted_flagged_from_local_storage(int input_mailbox_id)
+INTERNAL_FUNC int emcore_expunge_mails_deleted_flagged_from_local_storage(char *multi_user_name, int input_mailbox_id)
{
EM_DEBUG_FUNC_BEGIN("input_mailbox_id[%d]", input_mailbox_id);
int err = EMAIL_ERROR_NONE;
@@ -4880,7 +4030,7 @@ INTERNAL_FUNC int emcore_expunge_mails_deleted_flagged_from_local_storage(int in
goto FINISH_OFF;
}
- if ((err = emstorage_get_mailbox_by_id(input_mailbox_id, &mailbox_tbl)) != EMAIL_ERROR_NONE) {
+ if ((err = emstorage_get_mailbox_by_id(multi_user_name, input_mailbox_id, &mailbox_tbl)) != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("emstorage_get_mailbox_by_id failed [%d]", err);
goto FINISH_OFF;
}
@@ -4908,19 +4058,19 @@ INTERNAL_FUNC int emcore_expunge_mails_deleted_flagged_from_local_storage(int in
filter_list[2].list_filter_item.rule.target_attribute = EMAIL_MAIL_ATTRIBUTE_FLAGS_DELETED_FIELD;
filter_list[2].list_filter_item.rule.key_value.integer_type_value = 1;
- if ( (err = emstorage_write_conditional_clause_for_getting_mail_list(filter_list, filter_count, NULL, 0, -1, -1, &conditional_clause_string)) != EMAIL_ERROR_NONE) {
+ if ( (err = emstorage_write_conditional_clause_for_getting_mail_list(multi_user_name, filter_list, filter_count, NULL, 0, -1, -1, &conditional_clause_string)) != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("emstorage_write_conditional_clause_for_getting_mail_list failed[%d]", err);
goto FINISH_OFF;
}
EM_DEBUG_LOG("conditional_clause_string[%s].", conditional_clause_string);
- if ((err = emstorage_query_mail_id_list(conditional_clause_string, true, &result_mail_id_list, &result_count)) != EMAIL_ERROR_NONE) {
+ if ((err = emstorage_query_mail_id_list(multi_user_name, conditional_clause_string, true, &result_mail_id_list, &result_count)) != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("emstorage_query_mail_id_list [%d]", err);
goto FINISH_OFF;
}
- if (!emcore_delete_mails_from_local_storage(mailbox_tbl->account_id, result_mail_id_list, result_count, 1, EMAIL_DELETED_BY_COMMAND, &err)) {
+ if (!emcore_delete_mails_from_local_storage(multi_user_name, mailbox_tbl->account_id, result_mail_id_list, result_count, 1, EMAIL_DELETED_BY_COMMAND, &err)) {
EM_DEBUG_EXCEPTION("emcore_delete_mails_from_local_storage [%d]", err);
goto FINISH_OFF;
}
@@ -4940,7 +4090,7 @@ FINISH_OFF:
return err;
}
-INTERNAL_FUNC int emcore_expunge_mails_deleted_flagged_from_remote_server(int input_account_id, int input_mailbox_id)
+INTERNAL_FUNC int emcore_expunge_mails_deleted_flagged_from_remote_server(char *multi_user_name, int input_account_id, int input_mailbox_id)
{
int err = EMAIL_ERROR_NONE;
char *conditional_clause_string = NULL;
@@ -4978,19 +4128,19 @@ INTERNAL_FUNC int emcore_expunge_mails_deleted_flagged_from_remote_server(int in
filter_list[2].list_filter_item.rule.target_attribute = EMAIL_MAIL_ATTRIBUTE_FLAGS_DELETED_FIELD;
filter_list[2].list_filter_item.rule.key_value.integer_type_value = 1;
- if ( (err = emstorage_write_conditional_clause_for_getting_mail_list(filter_list, filter_count, NULL, 0, -1, -1, &conditional_clause_string)) != EMAIL_ERROR_NONE) {
+ if ( (err = emstorage_write_conditional_clause_for_getting_mail_list(multi_user_name, filter_list, filter_count, NULL, 0, -1, -1, &conditional_clause_string)) != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("emstorage_write_conditional_clause_for_getting_mail_list failed[%d]", err);
goto FINISH_OFF;
}
EM_DEBUG_LOG("conditional_clause_string[%s].", conditional_clause_string);
- if ((err = emstorage_query_mail_id_list(conditional_clause_string, true, &result_mail_id_list, &result_count)) != EMAIL_ERROR_NONE) {
+ if ((err = emstorage_query_mail_id_list(multi_user_name, conditional_clause_string, true, &result_mail_id_list, &result_count)) != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("emstorage_query_mail_id_list [%d]", err);
goto FINISH_OFF;
}
- if (!emcore_delete_mail(input_account_id, result_mail_id_list, result_count, EMAIL_DELETE_FROM_SERVER, 1, EMAIL_DELETED_BY_COMMAND, &err)) {
+ if (!emcore_delete_mail(multi_user_name, input_account_id, result_mail_id_list, result_count, EMAIL_DELETE_FROM_SERVER, 1, EMAIL_DELETED_BY_COMMAND, &err)) {
EM_DEBUG_EXCEPTION("emcore_delete_mail [%d]", err);
goto FINISH_OFF;
}
@@ -5018,7 +4168,7 @@ FINISH_OFF:
* succeed : 1
* fail : 0
*/
-INTERNAL_FUNC int emcore_add_attachment(int mail_id, email_attachment_data_t *attachment, int *err_code)
+INTERNAL_FUNC int emcore_add_attachment(char *multi_user_name, int mail_id, email_attachment_data_t *attachment, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("mail_id[%d], attachment[%p], err_code[%p]", mail_id, attachment, err_code);
@@ -5034,10 +4184,8 @@ INTERNAL_FUNC int emcore_add_attachment(int mail_id, email_attachment_data_t *at
int attachment_id = 0;
int before_tr_begin = 0;
-
- if (!emstorage_get_mail_field_by_id(mail_id, RETRIEVE_SUMMARY, &mail_table_data, true, &err) || !mail_table_data) {
+ if (!emstorage_get_mail_field_by_id(multi_user_name, mail_id, RETRIEVE_SUMMARY, &mail_table_data, true, &err) || !mail_table_data) {
EM_DEBUG_EXCEPTION("emstorage_get_mail_field_by_id failed [%d]", err);
-
goto FINISH_OFF2;
}
@@ -5059,80 +4207,77 @@ INTERNAL_FUNC int emcore_add_attachment(int mail_id, email_attachment_data_t *at
attachment_tbl.content_id = attachment->content_id;
/* BEGIN TRANSACTION; */
- if (!emstorage_begin_transaction(NULL, NULL, &err)) {
+ if (!emstorage_begin_transaction(multi_user_name, NULL, NULL, &err)) {
EM_DEBUG_EXCEPTION("emstorage_begin_transaction failed [%d]", err);
before_tr_begin = 1;
goto FINISH_OFF;
}
- if (!emstorage_add_attachment(&attachment_tbl, 0, false, &err)) {
+ if (!emstorage_add_attachment(multi_user_name, &attachment_tbl, 0, false, &err)) {
EM_DEBUG_EXCEPTION("emstorage_add_attachment failed [%d]", err);
-
goto FINISH_OFF;
}
attachment->attachment_id = attachment_tbl.attachment_id;
if (attachment->attachment_path) {
- char buf[512];
+ char move_buf[512] = {0};
+ char path_buf[512] = {0};
if (!attachment->inline_content_status) {
- if (!emstorage_create_dir(account_id, mail_id, attachment_tbl.attachment_id, &err)) {
+ if (!emstorage_create_dir(multi_user_name, account_id, mail_id, attachment_tbl.attachment_id, &err)) {
EM_DEBUG_EXCEPTION("emstorage_create_dir failed [%d]", err);
goto FINISH_OFF;
}
attachment_id = attachment_tbl.attachment_id;
}
- if (!emstorage_get_save_name(account_id, mail_id, attachment_id, attachment->attachment_name, buf, sizeof(buf), &err)) {
+ if (!emstorage_get_save_name(multi_user_name, account_id, mail_id, attachment_id, attachment->attachment_name, move_buf, path_buf, sizeof(path_buf), &err)) {
EM_DEBUG_EXCEPTION("emstorage_get_save_name failed [%d]", err);
goto FINISH_OFF;
}
- attachment_tbl.attachment_path = buf;
- if (!emstorage_change_attachment_field(mail_id, UPDATE_SAVENAME, &attachment_tbl, false, &err)) {
- EM_DEBUG_EXCEPTION("emstorage_change_attachment_field failed [%d]", err);
+ attachment_tbl.attachment_path = path_buf;
+ if (!emstorage_change_attachment_field(multi_user_name, mail_id, UPDATE_SAVENAME, &attachment_tbl, false, &err)) {
+ EM_DEBUG_EXCEPTION("emstorage_change_attachment_field failed [%d]", err);
goto FINISH_OFF;
}
- if (!emstorage_change_mail_field(mail_id, APPEND_BODY, mail_table_data, false, &err)) {
+ if (!emstorage_change_mail_field(multi_user_name, mail_id, APPEND_BODY, mail_table_data, false, &err)) {
EM_DEBUG_EXCEPTION("emstorage_change_mail_field failed [%d]", err);
-
goto FINISH_OFF;
}
if (attachment->save_status) {
- if (!emstorage_move_file(attachment->attachment_path, buf, false, &err)) {
+ if (!emstorage_move_file(attachment->attachment_path, move_buf, false, &err)) {
EM_DEBUG_EXCEPTION("emstorage_move_file failed [%d]", err);
-
goto FINISH_OFF;
}
}
/* Here only filename is being updated. Since first add is being done there will not be any old files.
So no need to check for old files in this update case */
- if (!emstorage_change_attachment_field(mail_id, UPDATE_SAVENAME, &attachment_tbl, false, &err)) {
+ if (!emstorage_change_attachment_field(multi_user_name, mail_id, UPDATE_SAVENAME, &attachment_tbl, false, &err)) {
EM_DEBUG_EXCEPTION("emstorage_change_attachment_field failed [%d]", err);
-
goto FINISH_OFF;
}
EM_SAFE_FREE(attachment->attachment_path);
- attachment->attachment_path = EM_SAFE_STRDUP(buf);
+ attachment->attachment_path = EM_SAFE_STRDUP(path_buf);
}
ret = true;
FINISH_OFF:
if (ret == true) { /* COMMIT TRANSACTION; */
- if (emstorage_commit_transaction(NULL, NULL, NULL) == false) {
+ if (emstorage_commit_transaction(multi_user_name, NULL, NULL, NULL) == false) {
err = EMAIL_ERROR_DB_FAILURE;
ret = false;
}
}
else { /* ROLLBACK TRANSACTION; */
- if (!before_tr_begin && emstorage_rollback_transaction(NULL, NULL, NULL) == false)
+ if (!before_tr_begin && emstorage_rollback_transaction(multi_user_name, NULL, NULL, NULL) == false)
err = EMAIL_ERROR_DB_FAILURE;
}
@@ -5142,12 +4287,13 @@ FINISH_OFF2:
if (err_code)
*err_code = err;
+
EM_DEBUG_FUNC_END("err [%d]", err);
return ret;
}
-INTERNAL_FUNC int emcore_add_attachment_data(int input_mail_id, email_attachment_data_t *input_attachment_data)
+INTERNAL_FUNC int emcore_add_attachment_data(char *multi_user_name, int input_mail_id, email_attachment_data_t *input_attachment_data)
{
EM_DEBUG_FUNC_BEGIN("input_mail_id[%d], input_attachment_data[%p]", input_mail_id, input_attachment_data);
@@ -5155,7 +4301,9 @@ INTERNAL_FUNC int emcore_add_attachment_data(int input_mail_id, email_attachment
int attachment_id = 0;
int ret = false;
int before_tr_begin = 0;
- char buf[512] = { 0, };
+ char move_buf[512] = { 0, };
+ char path_buf[512] = { 0, };
+
emstorage_mail_tbl_t *mail_table_data = NULL;
emstorage_attachment_tbl_t attachment_tbl = { 0 };
@@ -5164,7 +4312,7 @@ INTERNAL_FUNC int emcore_add_attachment_data(int input_mail_id, email_attachment
return EMAIL_ERROR_INVALID_PARAM;
}
- if (!emstorage_get_mail_field_by_id(input_mail_id, RETRIEVE_SUMMARY, &mail_table_data, true, &err) || !mail_table_data) {
+ if (!emstorage_get_mail_field_by_id(multi_user_name, input_mail_id, RETRIEVE_SUMMARY, &mail_table_data, true, &err) || !mail_table_data) {
EM_DEBUG_EXCEPTION("emstorage_get_mail_field_by_id failed [%d]", err);
before_tr_begin = 1;
goto FINISH_OFF;
@@ -5183,13 +4331,13 @@ INTERNAL_FUNC int emcore_add_attachment_data(int input_mail_id, email_attachment
attachment_tbl.content_id = input_attachment_data->content_id;
/* BEGIN TRANSACTION; */
- if (!emstorage_begin_transaction(NULL, NULL, &err)) {
+ if (!emstorage_begin_transaction(multi_user_name, NULL, NULL, &err)) {
EM_DEBUG_EXCEPTION("emstorage_begin_transaction failed [%d]", err);
before_tr_begin = 1;
goto FINISH_OFF;
}
- if (!emstorage_add_attachment(&attachment_tbl, 0, false, &err)) {
+ if (!emstorage_add_attachment(multi_user_name, &attachment_tbl, 0, false, &err)) {
EM_DEBUG_EXCEPTION("emstorage_add_attachment failed [%d]", err);
goto FINISH_OFF;
}
@@ -5198,34 +4346,32 @@ INTERNAL_FUNC int emcore_add_attachment_data(int input_mail_id, email_attachment
if (input_attachment_data->attachment_path) {
if (!input_attachment_data->inline_content_status) {
- if (!emstorage_create_dir(mail_table_data->account_id, input_mail_id, attachment_tbl.attachment_id, &err)) {
+ if (!emstorage_create_dir(multi_user_name, mail_table_data->account_id, input_mail_id, attachment_tbl.attachment_id, &err)) {
EM_DEBUG_EXCEPTION("emstorage_create_dir failed [%d]", err);
goto FINISH_OFF;
}
attachment_id = attachment_tbl.attachment_id;
}
- if (!emstorage_get_save_name(mail_table_data->account_id, input_mail_id, attachment_id, input_attachment_data->attachment_name, buf, sizeof(buf), &err)) {
+ if (!emstorage_get_save_name(multi_user_name, mail_table_data->account_id, input_mail_id, attachment_id, input_attachment_data->attachment_name, move_buf, path_buf, sizeof(path_buf), &err)) {
EM_DEBUG_EXCEPTION("emstorage_get_save_name failed [%d]", err);
goto FINISH_OFF;
}
- attachment_tbl.attachment_path = buf;
+ attachment_tbl.attachment_path = path_buf;
- if (!emstorage_change_attachment_field(input_mail_id, UPDATE_SAVENAME, &attachment_tbl, false, &err)) {
+ if (!emstorage_change_attachment_field(multi_user_name, input_mail_id, UPDATE_SAVENAME, &attachment_tbl, false, &err)) {
EM_DEBUG_EXCEPTION("emstorage_change_attachment_field failed [%d]", err);
-
goto FINISH_OFF;
}
- if (!emstorage_change_mail_field(input_mail_id, APPEND_BODY, mail_table_data, false, &err)) {
+ if (!emstorage_change_mail_field(multi_user_name, input_mail_id, APPEND_BODY, mail_table_data, false, &err)) {
EM_DEBUG_EXCEPTION("emstorage_change_mail_field failed [%d]", err);
-
goto FINISH_OFF;
}
if (input_attachment_data->save_status) {
- if (!emstorage_copy_file(input_attachment_data->attachment_path, buf, false, &err)) {
+ if (!emstorage_copy_file(input_attachment_data->attachment_path, move_buf, false, &err)) {
EM_DEBUG_EXCEPTION("emstorage_move_file failed [%d]", err);
goto FINISH_OFF;
}
@@ -5233,25 +4379,24 @@ INTERNAL_FUNC int emcore_add_attachment_data(int input_mail_id, email_attachment
/* Here only filename is being updated. Since first add is being done there will not be any old files.
So no need to check for old files in this update case */
- if (!emstorage_change_attachment_field(input_mail_id, UPDATE_SAVENAME, &attachment_tbl, false, &err)) {
+ if (!emstorage_change_attachment_field(multi_user_name, input_mail_id, UPDATE_SAVENAME, &attachment_tbl, false, &err)) {
EM_DEBUG_EXCEPTION("emstorage_change_attachment_field failed [%d]", err);
-
goto FINISH_OFF;
}
EM_SAFE_FREE(input_attachment_data->attachment_path);
- input_attachment_data->attachment_path = EM_SAFE_STRDUP(buf);
+ input_attachment_data->attachment_path = EM_SAFE_STRDUP(path_buf);
}
ret = true;
FINISH_OFF:
if (ret) { /* COMMIT TRANSACTION; */
- if (emstorage_commit_transaction(NULL, NULL, NULL) == false) {
+ if (emstorage_commit_transaction(multi_user_name, NULL, NULL, NULL) == false) {
err = EMAIL_ERROR_DB_FAILURE;
}
} else { /* ROLLBACK TRANSACTION; */
- if (!before_tr_begin && emstorage_rollback_transaction(NULL, NULL, NULL) == false)
+ if (!before_tr_begin && emstorage_rollback_transaction(multi_user_name, NULL, NULL, NULL) == false)
err = EMAIL_ERROR_DB_FAILURE;
}
@@ -5274,7 +4419,7 @@ FINISH_OFF:
* succeed : 1
* fail : 0
*/
-int emcore_delete_mail_attachment(int attachment_id, int *err_code)
+int emcore_delete_mail_attachment(char *multi_user_name, int attachment_id, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("attachment_id[%d], err_code[%p]", attachment_id, err_code);
@@ -5290,21 +4435,20 @@ int emcore_delete_mail_attachment(int attachment_id, int *err_code)
char attachment_folder_path[MAX_PATH] = {0, };
emstorage_attachment_tbl_t *attachment_tbl = NULL;
- if (!emstorage_get_attachment(attachment_id, &attachment_tbl, true, &error)) {
+ if (!emstorage_get_attachment(multi_user_name, attachment_id, &attachment_tbl, true, &error)) {
EM_DEBUG_EXCEPTION("emstorage_get_attachment failed");
return false;
}
/* BEGIN TRANSACTION; */
- if(!emstorage_begin_transaction(NULL, NULL, &error)) {
+ if(!emstorage_begin_transaction(multi_user_name, NULL, NULL, &error)) {
EM_DEBUG_EXCEPTION("emstorage_begin_transaction failed [%d]", error);
goto FINISH_OFF;
}
- if (!emstorage_delete_attachment_on_db(attachment_id, false, &error)) {
+ if (!emstorage_delete_attachment_on_db(multi_user_name, attachment_id, false, &error)) {
EM_DEBUG_EXCEPTION("emstorage_delete_attachment_on_db failed [%d]", error);
-
- if (emstorage_rollback_transaction(NULL, NULL, NULL) == false)
+ if (emstorage_rollback_transaction(multi_user_name, NULL, NULL, NULL) == false)
error = EMAIL_ERROR_DB_FAILURE;
ret = false;
@@ -5323,7 +4467,7 @@ int emcore_delete_mail_attachment(int attachment_id, int *err_code)
}
}
- if (emstorage_commit_transaction(NULL, NULL, NULL) == false) {
+ if (emstorage_commit_transaction(multi_user_name, NULL, NULL, NULL) == false) {
error = EMAIL_ERROR_DB_FAILURE;
ret = false;
}
@@ -5339,13 +4483,14 @@ FINISH_OFF:
return ret;
}
-static int emcore_mail_update_attachment_data(int input_mail_id, email_attachment_data_t *input_attachment_data)
+static int emcore_mail_update_attachment_data(char *multi_user_name, int input_mail_id, email_attachment_data_t *input_attachment_data)
{
EM_DEBUG_FUNC_BEGIN("input_mail_id[%d], input_attachment_data[%p]", input_mail_id, input_attachment_data);
int err = EMAIL_ERROR_NONE;
int attachment_id = 0;
- char buf[512] = { 0 , };
+ char move_buf[512] = { 0 , };
+ char path_buf[512] = {0,};
emstorage_attachment_tbl_t *existing_attachment_info = NULL;
emstorage_attachment_tbl_t attachment_tbl = { 0 };
@@ -5355,9 +4500,8 @@ static int emcore_mail_update_attachment_data(int input_mail_id, email_attachmen
goto FINISH_OFF;
}
- if (!emstorage_get_attachment(input_attachment_data->attachment_id, &existing_attachment_info, 1, &err)) {
+ if (!emstorage_get_attachment(multi_user_name, input_attachment_data->attachment_id, &existing_attachment_info, 1, &err)) {
EM_DEBUG_EXCEPTION("emstorage_get_attachment failed [%d]", err);
-
goto FINISH_OFF;
}
@@ -5375,25 +4519,24 @@ static int emcore_mail_update_attachment_data(int input_mail_id, email_attachmen
attachment_tbl.content_id = input_attachment_data->content_id;
if (!input_attachment_data->inline_content_status) {
- if (!emstorage_create_dir(attachment_tbl.account_id, input_mail_id, attachment_tbl.attachment_id, &err)) {
+ if (!emstorage_create_dir(multi_user_name, attachment_tbl.account_id, input_mail_id, attachment_tbl.attachment_id, &err)) {
EM_DEBUG_EXCEPTION("emstorage_create_dir failed [%d]", err);
goto FINISH_OFF;
}
attachment_id = attachment_tbl.attachment_id;
}
-
- if (!emstorage_get_save_name(attachment_tbl.account_id, input_mail_id, attachment_id, input_attachment_data->attachment_name, buf, sizeof(buf), &err)) {
+
+ if (!emstorage_get_save_name(multi_user_name, attachment_tbl.account_id, input_mail_id, attachment_id, input_attachment_data->attachment_name, move_buf, path_buf, sizeof(path_buf), &err)) {
EM_DEBUG_EXCEPTION("emstorage_get_save_name failed [%d]", err);
goto FINISH_OFF;
}
- attachment_tbl.attachment_path = buf;
+ attachment_tbl.attachment_path = path_buf;
EM_DEBUG_LOG_SEC("downloaded [%d], savename [%s], attachment_path [%s]", input_attachment_data->save_status, input_attachment_data->attachment_path, existing_attachment_info->attachment_path);
if (input_attachment_data->save_status && EM_SAFE_STRCMP(input_attachment_data->attachment_path, existing_attachment_info->attachment_path) != 0) {
- if (!emstorage_move_file(input_attachment_data->attachment_path, buf, false ,&err)) {
+ if (!emstorage_move_file(input_attachment_data->attachment_path, move_buf, false ,&err)) {
EM_DEBUG_EXCEPTION("emstorage_move_file failed [%d]", err);
-
goto FINISH_OFF;
}
}
@@ -5401,23 +4544,23 @@ static int emcore_mail_update_attachment_data(int input_mail_id, email_attachmen
EM_DEBUG_LOG("no need to move");
EM_SAFE_FREE(input_attachment_data->attachment_path);
- input_attachment_data->attachment_path = EM_SAFE_STRDUP(buf);
+ input_attachment_data->attachment_path = EM_SAFE_STRDUP(path_buf);
- if (!emstorage_begin_transaction(NULL, NULL, &err)) {
+ if (!emstorage_begin_transaction(multi_user_name, NULL, NULL, &err)) {
EM_DEBUG_EXCEPTION("emstorage_begin_transaction failed [%d]", err);
goto FINISH_OFF;
}
- if (!emstorage_update_attachment(&attachment_tbl, false, &err)) {
+ if (!emstorage_update_attachment(multi_user_name, &attachment_tbl, false, &err)) {
EM_DEBUG_EXCEPTION("emstorage_update_attachment failed [%d]", err);
}
if (err == EMAIL_ERROR_NONE) { /* COMMIT TRANSACTION; */
- if (emstorage_commit_transaction(NULL, NULL, NULL) == false) {
+ if (emstorage_commit_transaction(multi_user_name, NULL, NULL, NULL) == false) {
err = EMAIL_ERROR_DB_FAILURE;
}
} else { /* ROLLBACK TRANSACTION; */
- if (emstorage_rollback_transaction(NULL, NULL, NULL) == false)
+ if (emstorage_rollback_transaction(multi_user_name, NULL, NULL, NULL) == false)
err = EMAIL_ERROR_DB_FAILURE;
}
@@ -5430,7 +4573,7 @@ FINISH_OFF:
}
-static int emcore_mail_compare_filename_of_attachment_data(int input_mail_id, int input_attachment_a_id, email_attachment_data_t *input_attachment_b_data, int *result)
+static int emcore_mail_compare_filename_of_attachment_data(char *multi_user_name, int input_mail_id, int input_attachment_a_id, email_attachment_data_t *input_attachment_b_data, int *result)
{
EM_DEBUG_FUNC_BEGIN("input_mail_id[%d], input_attachment_a_id[%d], input_attachment_b_data[%p], result[%p]", input_mail_id, input_attachment_a_id, input_attachment_b_data, result);
@@ -5457,7 +4600,7 @@ static int emcore_mail_compare_filename_of_attachment_data(int input_mail_id, in
linkpath[st_buf.st_size] = '\0';
EM_DEBUG_LOG("symbolic link path : [%s]", linkpath);
- if (emstorage_get_attachment_by_attachment_path(linkpath, &attachment_a_tbl, false, &err)) {
+ if (emstorage_get_attachment_by_attachment_path(multi_user_name, linkpath, &attachment_a_tbl, false, &err)) {
if (attachment_a_tbl->mail_id == input_mail_id) {
input_attachment_b_data->attachment_id = attachment_a_tbl->attachment_id;
*result = 2;
@@ -5470,7 +4613,7 @@ static int emcore_mail_compare_filename_of_attachment_data(int input_mail_id, in
}
}
- if (!emstorage_get_attachment(input_attachment_a_id, &attachment_a_tbl, 1, &err)) {
+ if (!emstorage_get_attachment(multi_user_name, input_attachment_a_id, &attachment_a_tbl, 1, &err)) {
if (err == EMAIL_ERROR_ATTACHMENT_NOT_FOUND)
EM_DEBUG_LOG ("no attachment found");
else
@@ -5511,7 +4654,7 @@ FINISH_OFF:
* succeed : 1
* fail : 0
*/
-INTERNAL_FUNC int emcore_mail_copy(int mail_id, email_mailbox_t *dst_mailbox, int *err_code)
+INTERNAL_FUNC int emcore_mail_copy(char *multi_user_name, int mail_id, email_mailbox_t *dst_mailbox, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("mail_id[%d], dst_mailbox[%p], err_code[%p]", mail_id, dst_mailbox, err_code);
@@ -5520,62 +4663,76 @@ INTERNAL_FUNC int emcore_mail_copy(int mail_id, email_mailbox_t *dst_mailbox, in
int i;
emstorage_mail_tbl_t *mail = NULL;
emstorage_attachment_tbl_t *atch_list = NULL;
- char buf[512];
int count = EMAIL_ATTACHMENT_MAX_COUNT;
char *mailbox_name = NULL;
char *stripped_text = NULL;
+ char *prefix_path = NULL;
+ char virtual_path[512];
+ char real_path[512];
+ char real_file_path[512];
- if (!emstorage_get_mail_by_id(mail_id, &mail, true, &err) || !mail) {
+ if (!emstorage_get_mail_by_id(multi_user_name, mail_id, &mail, true, &err) || !mail) {
EM_DEBUG_EXCEPTION("emstorage_get_mail_by_id failed [%d]", err);
goto FINISH_OFF;
}
- if ( (err = emstorage_get_attachment_list(mail_id, true, &atch_list, &count)) != EMAIL_ERROR_NONE ){
+ if ( (err = emstorage_get_attachment_list(multi_user_name, mail_id, true, &atch_list, &count)) != EMAIL_ERROR_NONE ){
EM_DEBUG_EXCEPTION("emstorage_get_attachment_list failed [%d]", err);
-
goto FINISH_OFF;
}
/* get increased uid. */
- if (!emstorage_increase_mail_id(&mail->mail_id, true, &err)) {
+ if (!emstorage_increase_mail_id(multi_user_name, &mail->mail_id, true, &err)) {
EM_DEBUG_EXCEPTION("emstorage_increase_mail_id failed [%d]", err);
-
goto FINISH_OFF;
}
+ if (EM_SAFE_STRLEN(multi_user_name) > 0) {
+ err = emcore_get_container_path(multi_user_name, &prefix_path);
+ if (err != EMAIL_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("emcore_get_container_path failed : [%d]", err);
+ goto FINISH_OFF;
+ }
+ } else {
+ prefix_path = strdup("");
+ }
+
/* copy mail body(text) file */
if (mail->file_path_plain) {
- if (!emstorage_create_dir(dst_mailbox->account_id, mail->mail_id, 0, &err)) {
+ if (!emstorage_create_dir(multi_user_name, dst_mailbox->account_id, mail->mail_id, 0, &err)) {
EM_DEBUG_EXCEPTION("emstorage_create_dir failed [%d]", err);
-
goto FINISH_OFF;
}
gchar *filename = g_path_get_basename(mail->file_path_plain);
- if (!emstorage_get_save_name(dst_mailbox->account_id, mail->mail_id, 0, filename, buf, sizeof(buf), &err)) {
+ memset(virtual_path, 0x00, sizeof(virtual_path));
+ memset(real_path, 0x00, sizeof(virtual_path));
+
+ memset(real_file_path, 0x00, sizeof(real_file_path));
+ SNPRINTF(real_file_path, sizeof(real_file_path), "%s%s", prefix_path, mail->file_path_plain);
+
+ if (!emstorage_get_save_name(multi_user_name, dst_mailbox->account_id, mail->mail_id, 0, filename, real_path, virtual_path, sizeof(virtual_path), &err)) {
EM_DEBUG_EXCEPTION("emstorage_get_save_name failed [%d]", err);
g_free(filename);
-
goto FINISH_OFF;
}
g_free(filename);
- if (!emstorage_copy_file(mail->file_path_plain, buf, false, &err)) {
+ if (!emstorage_copy_file(real_file_path, real_path, false, &err)) {
EM_DEBUG_EXCEPTION("emstorage_copy_file failed [%d]", err);
-
goto FINISH_OFF;
}
EM_SAFE_FREE(mail->file_path_plain);
- mail->file_path_plain = EM_SAFE_STRDUP(buf);
+ mail->file_path_plain = EM_SAFE_STRDUP(virtual_path);
}
/* copy mail body(html) file */
if (mail->file_path_html) {
- if (!emstorage_create_dir(dst_mailbox->account_id, mail->mail_id, 0, &err)) {
+ if (!emstorage_create_dir(multi_user_name, dst_mailbox->account_id, mail->mail_id, 0, &err)) {
EM_DEBUG_EXCEPTION("emstorage_create_dir failed [%d]", err);
goto FINISH_OFF;
@@ -5583,27 +4740,39 @@ INTERNAL_FUNC int emcore_mail_copy(int mail_id, email_mailbox_t *dst_mailbox, in
gchar *filename = g_path_get_basename(mail->file_path_html);
- if (!emstorage_get_save_name(dst_mailbox->account_id, mail->mail_id, 0, filename, buf, sizeof(buf), &err)) {
+ memset(virtual_path, 0x00, sizeof(virtual_path));
+ memset(real_path, 0x00, sizeof(virtual_path));
+
+ memset(real_file_path, 0x00, sizeof(real_file_path));
+ SNPRINTF(real_file_path, sizeof(real_file_path), "%s%s", prefix_path, mail->file_path_html);
+
+ if (!emstorage_get_save_name(multi_user_name,
+ dst_mailbox->account_id,
+ mail->mail_id,
+ 0,
+ filename,
+ real_path,
+ virtual_path,
+ sizeof(virtual_path),
+ &err)) {
EM_DEBUG_EXCEPTION("emstorage_get_save_name failed [%d]", err);
g_free(filename);
-
goto FINISH_OFF;
}
g_free(filename);
- if (!emstorage_copy_file(mail->file_path_html, buf, false, &err)) {
+ if (!emstorage_copy_file(real_file_path, real_path, false, &err)) {
EM_DEBUG_EXCEPTION("emstorage_copy_file failed [%d]", err);
-
goto FINISH_OFF;
}
EM_SAFE_FREE(mail->file_path_html); /*valgrind*/
- mail->file_path_html = EM_SAFE_STRDUP(buf);
+ mail->file_path_html = EM_SAFE_STRDUP(virtual_path);
}
/* BEGIN TRANSACTION; */
- if (!emstorage_begin_transaction(NULL, NULL, &err)) {
+ if (!emstorage_begin_transaction(multi_user_name, NULL, NULL, &err)) {
EM_DEBUG_EXCEPTION("emstorage_begin_transaction failed [%d]", err);
goto FINISH_OFF;
}
@@ -5614,27 +4783,33 @@ INTERNAL_FUNC int emcore_mail_copy(int mail_id, email_mailbox_t *dst_mailbox, in
mail->mailbox_id = dst_mailbox->mailbox_id;
mail->mailbox_type = dst_mailbox->mailbox_type;
- if (!emstorage_add_mail(mail, 0, false, &err)) {
+ if (!emstorage_add_mail(multi_user_name, mail, 0, false, &err)) {
EM_DEBUG_EXCEPTION("emstorage_add_mail failed [%d]", err);
if (mail->file_path_plain) {
+ memset(real_file_path, 0x00, sizeof(real_file_path));
+ SNPRINTF(real_file_path, sizeof(real_file_path), "%s%s", prefix_path, mail->file_path_plain);
+
if (!emstorage_delete_file(mail->file_path_plain, &err)) {
EM_DEBUG_EXCEPTION("emstorage_delete_file failed [%d]", err);
- emstorage_rollback_transaction(NULL, NULL, NULL);
+ emstorage_rollback_transaction(multi_user_name, NULL, NULL, NULL);
goto FINISH_OFF;
}
}
+
if (mail->file_path_html) {
- if (!emstorage_delete_file(mail->file_path_html, &err)) {
+ memset(real_file_path, 0x00, sizeof(real_file_path));
+ SNPRINTF(real_file_path, sizeof(real_file_path), "%s%s", prefix_path, mail->file_path_html);
+
+ if (!emstorage_delete_file(real_file_path, &err)) {
EM_DEBUG_EXCEPTION("emstorage_delete_file failed [%d]", err);
- emstorage_rollback_transaction(NULL, NULL, NULL);
+ emstorage_rollback_transaction(multi_user_name, NULL, NULL, NULL);
goto FINISH_OFF;
}
}
/* ROLLBACK TRANSACTION; */
- emstorage_rollback_transaction(NULL, NULL, NULL);
-
+ emstorage_rollback_transaction(multi_user_name, NULL, NULL, NULL);
goto FINISH_OFF;
}
@@ -5642,33 +4817,45 @@ INTERNAL_FUNC int emcore_mail_copy(int mail_id, email_mailbox_t *dst_mailbox, in
/* copy attachment file */
for (i = 0; i<count; i++) {
if (atch_list[i].attachment_path) {
- if (!emstorage_create_dir(dst_mailbox->account_id, mail->mail_id, i+1, &err)) {
+ if (!emstorage_create_dir(multi_user_name, dst_mailbox->account_id, mail->mail_id, i+1, &err)) {
EM_DEBUG_EXCEPTION("emstorage_create_dir failed [%d]", err);
break;
}
- if (!emstorage_get_save_name(dst_mailbox->account_id, mail->mail_id, i+1, atch_list[i].attachment_name, buf, sizeof(buf), &err)) {
+ memset(virtual_path, 0x00, sizeof(virtual_path));
+ memset(real_path, 0x00, sizeof(virtual_path));
+
+ memset(real_file_path, 0x00, sizeof(real_file_path));
+ SNPRINTF(real_file_path, sizeof(real_file_path), "%s%s", prefix_path, atch_list[i].attachment_path);
+
+ if (!emstorage_get_save_name(multi_user_name,
+ dst_mailbox->account_id,
+ mail->mail_id,
+ i+1,
+ atch_list[i].attachment_name,
+ real_path,
+ virtual_path,
+ sizeof(virtual_path),
+ &err)) {
EM_DEBUG_EXCEPTION("emstorage_get_save_name failed [%d]", err);
break;
}
- if (!emstorage_copy_file(atch_list[i].attachment_path, buf, false, &err)) {
+ if (!emstorage_copy_file(real_file_path, real_path, false, &err)) {
EM_DEBUG_EXCEPTION("emstorage_copy_file failed [%d]", err);
break;
}
EM_SAFE_FREE(atch_list[i].attachment_path);
-
- atch_list[i].attachment_path = EM_SAFE_STRDUP(buf);
+ atch_list[i].attachment_path = EM_SAFE_STRDUP(virtual_path);
}
atch_list[i].account_id = dst_mailbox->account_id;
atch_list[i].mail_id = mail->mail_id;
atch_list[i].mailbox_id = mail->mailbox_id;
- if (!emstorage_add_attachment(&atch_list[i], 0, false, &err)) {
+ if (!emstorage_add_attachment(multi_user_name, &atch_list[i], 0, false, &err)) {
EM_DEBUG_EXCEPTION("emstorage_add_attachment failed [%d]", err);
-
break;
}
}
@@ -5677,51 +4864,60 @@ INTERNAL_FUNC int emcore_mail_copy(int mail_id, email_mailbox_t *dst_mailbox, in
if (i && i != count) {
for (;i >= 0; i--) {
if (atch_list[i].attachment_path) {
+ memset(real_file_path, 0x00, sizeof(real_file_path));
+ SNPRINTF(real_file_path, sizeof(real_file_path), "%s%s", prefix_path, atch_list[i].attachment_path);
- if (!emstorage_delete_file(atch_list[i].attachment_path, &err)) {
+ if (!emstorage_delete_file(real_file_path, &err)) {
EM_DEBUG_EXCEPTION("emstorage_delete_file failed [%d]", err);
- emstorage_rollback_transaction(NULL, NULL, NULL);
+ emstorage_rollback_transaction(multi_user_name, NULL, NULL, NULL);
goto FINISH_OFF;
}
}
}
if (mail->file_path_plain) {
- if (!emstorage_delete_file(mail->file_path_plain, &err)) {
+ memset(real_file_path, 0x00, sizeof(real_file_path));
+ SNPRINTF(real_file_path, sizeof(real_file_path), "%s%s", prefix_path, mail->file_path_plain);
+
+ if (!emstorage_delete_file(real_file_path, &err)) {
EM_DEBUG_EXCEPTION("emstorage_delete_file failed [%d]", err);
- emstorage_rollback_transaction(NULL, NULL, NULL);
+ emstorage_rollback_transaction(multi_user_name, NULL, NULL, NULL);
goto FINISH_OFF;
}
}
- if (mail->file_path_html) {
- if (!emstorage_delete_file(mail->file_path_html, &err)) {
+
+ if (mail->file_path_html) {
+ memset(real_file_path, 0x00, sizeof(real_file_path));
+ SNPRINTF(real_file_path, sizeof(real_file_path), "%s%s", prefix_path, mail->file_path_html);
+
+ if (!emstorage_delete_file(real_file_path, &err)) {
EM_DEBUG_EXCEPTION("emstorage_delete_file failed [%d]", err);
- emstorage_rollback_transaction(NULL, NULL, NULL);
+ emstorage_rollback_transaction(multi_user_name, NULL, NULL, NULL);
goto FINISH_OFF;
}
}
/* ROLLBACK TRANSACTION; */
- emstorage_rollback_transaction(NULL, NULL, NULL);
+ emstorage_rollback_transaction(multi_user_name, NULL, NULL, NULL);
goto FINISH_OFF;
}
#ifdef __FEATURE_BODY_SEARCH__
/* Insert mail_text to DB */
emstorage_mailbox_tbl_t *output_mailbox;
- if (!emcore_strip_mail_body_from_file(mail, &stripped_text, &err) || stripped_text == NULL) {
+ if (!emcore_strip_mail_body_from_file(multi_user_name, mail, &stripped_text, &err) || stripped_text == NULL) {
EM_DEBUG_EXCEPTION("emcore_strip_mail_body_from_file failed [%d]", err);
}
- if (emstorage_get_mailbox_by_id(dst_mailbox->mailbox_id, &output_mailbox) != EMAIL_ERROR_NONE) {
+ if (emstorage_get_mailbox_by_id(multi_user_name, dst_mailbox->mailbox_id, &output_mailbox) != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("emstorage_get_mailbox_by_id failed");
- emstorage_rollback_transaction(NULL, NULL, NULL);
+ emstorage_rollback_transaction(multi_user_name, NULL, NULL, NULL);
goto FINISH_OFF;
}
- if (!emcore_add_mail_text(output_mailbox, mail, stripped_text, &err)) {
+ if (!emcore_add_mail_text(multi_user_name, output_mailbox, mail, stripped_text, &err)) {
EM_DEBUG_EXCEPTION("emcore_add_mail_text failed [%d]", err);
- emstorage_rollback_transaction(NULL, NULL, NULL);
+ emstorage_rollback_transaction(multi_user_name, NULL, NULL, NULL);
goto FINISH_OFF;
}
@@ -5730,20 +4926,20 @@ INTERNAL_FUNC int emcore_mail_copy(int mail_id, email_mailbox_t *dst_mailbox, in
#endif
- if (emstorage_commit_transaction(NULL, NULL, NULL) == false) {
+ if (emstorage_commit_transaction(multi_user_name, NULL, NULL, NULL) == false) {
err = EMAIL_ERROR_DB_FAILURE;
- if (emstorage_rollback_transaction(NULL, NULL, NULL) == false)
+ if (emstorage_rollback_transaction(multi_user_name, NULL, NULL, NULL) == false)
err = EMAIL_ERROR_DB_FAILURE;
goto FINISH_OFF;
}
- if (!emstorage_get_mailbox_name_by_mailbox_type(dst_mailbox->account_id, EMAIL_MAILBOX_TYPE_INBOX, &mailbox_name, false, &err)) {
+ if (!emstorage_get_mailbox_name_by_mailbox_type(multi_user_name, dst_mailbox->account_id, EMAIL_MAILBOX_TYPE_INBOX, &mailbox_name, false, &err)) {
EM_DEBUG_EXCEPTION("emstorage_get_mailbox_name_by_mailbox_type failed [%d]", err);
goto FINISH_OFF;
}
if (!strcmp(dst_mailbox->mailbox_name, mailbox_name) && !(mail->flags_seen_field))
- emcore_display_unread_in_badge(NULL);
+ emcore_display_unread_in_badge(multi_user_name);
ret = true;
@@ -5758,6 +4954,7 @@ FINISH_OFF:
EM_SAFE_FREE(stripped_text);
#endif
EM_SAFE_FREE(mailbox_name);
+ EM_SAFE_FREE(prefix_path);
if (err_code != NULL)
*err_code = err;
@@ -5775,7 +4972,7 @@ FINISH_OFF:
* succeed : 1
* fail : 0
*/
-INTERNAL_FUNC int emcore_move_mail(int mail_ids[], int mail_ids_count, int dst_mailbox_id, int noti_param_1, int noti_param_2 ,int *err_code)
+INTERNAL_FUNC int emcore_move_mail(char *multi_user_name, int mail_ids[], int mail_ids_count, int dst_mailbox_id, int noti_param_1, int noti_param_2 ,int *err_code)
{
EM_DEBUG_FUNC_BEGIN("mail_ids[%p], mail_ids_count[%d], dst_mailbox_id[%d], noti_param [%d], err_code[%p]", mail_ids, mail_ids_count, dst_mailbox_id, noti_param_1, err_code);
@@ -5796,13 +4993,13 @@ INTERNAL_FUNC int emcore_move_mail(int mail_ids[], int mail_ids_count, int dst_m
int find_striped_subject = 0;
char stripped_subject[4086];
- if ( dst_mailbox_id <= 0 && mail_ids_count < 1) {
+ if (dst_mailbox_id <= 0 && mail_ids_count < 1) {
EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
err = EMAIL_ERROR_INVALID_PARAM;
goto FINISH_OFF;
}
- if (!emstorage_get_mail_field_by_multiple_mail_id(mail_ids, mail_ids_count, RETRIEVE_SUMMARY, &mail_list, true, &err) || !mail_list) {
+ if (!emstorage_get_mail_field_by_multiple_mail_id(multi_user_name, mail_ids, mail_ids_count, RETRIEVE_SUMMARY, &mail_list, true, &err) || !mail_list) {
EM_DEBUG_EXCEPTION("emstorage_get_mail_field_by_multiple_mail_id failed [%d]", err);
goto FINISH_OFF;
}
@@ -5818,18 +5015,19 @@ INTERNAL_FUNC int emcore_move_mail(int mail_ids[], int mail_ids_count, int dst_m
for (i = 0; i < mail_ids_count; i++) {
/* Get the thread_id before move */
- if (emstorage_get_thread_id_from_mailbox(account_id, dst_mailbox_id, mail_list[i].subject, &dest_prev_thread_id, &dest_prev_thread_item_count) != EMAIL_ERROR_NONE)
+ if (emstorage_get_thread_id_from_mailbox(multi_user_name, account_id, dst_mailbox_id, mail_list[i].subject, &dest_prev_thread_id, &dest_prev_thread_item_count) != EMAIL_ERROR_NONE)
EM_DEBUG_LOG("emstorage_get_thread_id_of_thread_mails is failed.");
+
dest_prev_thread_id_list[i] = dest_prev_thread_id;
}
- if(!emstorage_move_multiple_mails_on_db(account_id, dst_mailbox_id, mail_ids, mail_ids_count, true, &err)) {
+ if(!emstorage_move_multiple_mails_on_db(multi_user_name, account_id, dst_mailbox_id, mail_ids, mail_ids_count, true, &err)) {
EM_DEBUG_EXCEPTION("emstorage_move_multiple_mails_on_db failed [%d]", err);
goto FINISH_OFF;
}
-
+
for (i = 0; i < mail_ids_count; i++) {
- if (mail_list[i].subject == NULL)
+ if (mail_list[i].subject == NULL)
continue;
if (dest_prev_thread_id_list[i] == -1) {
if (em_find_pos_stripped_subject_for_thread_view(mail_list[i].subject, stripped_subject, sizeof(stripped_subject)) != EMAIL_ERROR_NONE) {
@@ -5856,7 +5054,7 @@ INTERNAL_FUNC int emcore_move_mail(int mail_ids[], int mail_ids_count, int dst_m
}
}
- if (!emstorage_update_thread_id_of_mail(account_id, dst_mailbox_id, mail_ids[i], dest_prev_thread_id_list[i], 0, false, &err)) {
+ if (!emstorage_update_thread_id_of_mail(multi_user_name, account_id, dst_mailbox_id, mail_ids[i], dest_prev_thread_id_list[i], 0, false, &err)) {
EM_DEBUG_EXCEPTION("emstorage_update_latest_thread_mail failed [%d]", err);
goto FINISH_OFF;
}
@@ -5895,29 +5093,59 @@ INTERNAL_FUNC int emcore_move_mail(int mail_ids[], int mail_ids_count, int dst_m
p_lastest_mail_id = -1;
/* Get the information of moved mail */
- if (!emstorage_get_mail_by_id(mail_ids[i], &p_mail_data, false, &err)) {
+ if (!emstorage_get_mail_by_id(multi_user_name, mail_ids[i], &p_mail_data, false, &err)) {
EM_DEBUG_EXCEPTION("emstorage_get_mail_by_id failed : [%d]", err);
goto FINISH_OFF;
}
- /* Get the thread_id of moved mail */
- if (emstorage_get_thread_id_of_thread_mails(p_mail_data, &p_thread_id, &p_lastest_mail_id, &p_thread_item_count) != EMAIL_ERROR_NONE)
+ /* Get the thread_id of moved mail */
+ if (emstorage_get_thread_id_of_thread_mails(multi_user_name, p_mail_data, &p_thread_id, &p_lastest_mail_id, &p_thread_item_count) != EMAIL_ERROR_NONE)
EM_DEBUG_LOG("emstorage_get_thread_id_of_thread_mails is failed.");
/* Original mailbox replace thread id */
- if (!emstorage_update_latest_thread_mail(account_id, mail_list[i].mailbox_id, mail_list[i].thread_id, NULL, 0, 0, NOTI_THREAD_ID_CHANGED_BY_MOVE_OR_DELETE, false, &err)) {
+ if (!emstorage_update_latest_thread_mail(multi_user_name,
+ account_id,
+ mail_list[i].mailbox_id,
+ mail_list[i].mailbox_type,
+ mail_list[i].thread_id,
+ NULL,
+ 0,
+ 0,
+ NOTI_THREAD_ID_CHANGED_BY_MOVE_OR_DELETE,
+ false,
+ &err)) {
EM_DEBUG_EXCEPTION("emstorage_update_latest_thread_mail failed [%d]", err);
goto FINISH_OFF;
}
/* Destination mailbox replace thread id */
if (p_thread_id == -1) {
- if (!emstorage_update_latest_thread_mail(account_id, p_mail_data->mailbox_id, p_mail_data->mail_id, NULL, p_mail_data->mail_id, 1, NOTI_THREAD_ID_CHANGED_BY_MOVE_OR_DELETE, false, &err)) {
+ if (!emstorage_update_latest_thread_mail(multi_user_name,
+ account_id,
+ p_mail_data->mailbox_id,
+ p_mail_data->mailbox_type,
+ p_mail_data->mail_id,
+ NULL,
+ p_mail_data->mail_id,
+ 1,
+ NOTI_THREAD_ID_CHANGED_BY_MOVE_OR_DELETE,
+ false,
+ &err)) {
EM_DEBUG_EXCEPTION("emstorage_update_latest_thread_mail failed [%d]", err);
goto FINISH_OFF;
}
} else {
- if (!emstorage_update_latest_thread_mail(account_id, p_mail_data->mailbox_id, dest_prev_thread_id_list[i], NULL, 0, 0, NOTI_THREAD_ID_CHANGED_BY_MOVE_OR_DELETE, false, &err)) {
+ if (!emstorage_update_latest_thread_mail(multi_user_name,
+ account_id,
+ p_mail_data->mailbox_id,
+ p_mail_data->mailbox_type,
+ dest_prev_thread_id_list[i],
+ NULL,
+ 0,
+ 0,
+ NOTI_THREAD_ID_CHANGED_BY_MOVE_OR_DELETE,
+ false,
+ &err)) {
EM_DEBUG_EXCEPTION("emstorage_update_latest_thread_mail failed [%d]", err);
goto FINISH_OFF;
}
@@ -5928,7 +5156,7 @@ INTERNAL_FUNC int emcore_move_mail(int mail_ids[], int mail_ids_count, int dst_m
if (!emcore_notify_storage_event(NOTI_MAIL_MOVE_FINISH, account_id, noti_param_1, parameter_string, noti_param_2))
EM_DEBUG_EXCEPTION(" emcore_notify_storage_event failed [NOTI_MAIL_MOVE_FINISH] >>>> ");
- emcore_display_unread_in_badge(NULL);
+ emcore_display_unread_in_badge(multi_user_name);
ret = true;
@@ -5951,7 +5179,7 @@ FINISH_OFF:
}
-INTERNAL_FUNC int emcore_move_mail_on_server(int account_id, int src_mailbox_id, int mail_ids[], int num, char *dest_mailbox, int *error_code)
+INTERNAL_FUNC int emcore_move_mail_on_server(char *multi_user_name, int account_id, int src_mailbox_id, int mail_ids[], int num, char *dest_mailbox, int *error_code)
{
EM_DEBUG_FUNC_BEGIN();
MAILSTREAM *stream = NULL;
@@ -5963,8 +5191,8 @@ INTERNAL_FUNC int emcore_move_mail_on_server(int account_id, int src_mailbox_id,
int i = 0;
mail_id = mail_ids[0];
-
- ref_account = emcore_get_account_reference(account_id);
+
+ ref_account = emcore_get_account_reference(multi_user_name, account_id, false);
if (!ref_account) {
EM_DEBUG_EXCEPTION("emcore_move_mail_on_server failed : get account reference[%d]", account_id);
*error_code = EMAIL_ERROR_INVALID_ACCOUNT;
@@ -5982,7 +5210,7 @@ INTERNAL_FUNC int emcore_move_mail_on_server(int account_id, int src_mailbox_id,
for (i = 0; i < num; i++) {
mail_id = mail_ids[i];
- if (!emstorage_get_mail_by_id(mail_id, &mail, false, &err_code) || !mail) {
+ if (!emstorage_get_mail_by_id(multi_user_name, mail_id, &mail, false, &err_code) || !mail) {
EM_DEBUG_EXCEPTION("emstorage_get_uid_by_mail_id : emstorage_get_downloaded_mail failed [%d]", err_code);
mail = NULL;
if (err_code == EMAIL_ERROR_MAIL_NOT_FOUND) { /* not server mail */
@@ -5997,7 +5225,7 @@ INTERNAL_FUNC int emcore_move_mail_on_server(int account_id, int src_mailbox_id,
goto FINISH_OFF;
}
- if (!emcore_connect_to_remote_mailbox(account_id, src_mailbox_id, (void **)&stream, &err_code)) /* faizan.h@samsung.com mail_move_fix_07042009 */ {
+ if (!emcore_connect_to_remote_mailbox(multi_user_name, account_id, src_mailbox_id, (void **)&stream, &err_code)) /* faizan.h@samsung.com mail_move_fix_07042009 */ {
EM_DEBUG_EXCEPTION("emcore_move_mail_on_server failed : Mailbox open[%d]", err_code);
ret = 0;
@@ -6025,7 +5253,7 @@ INTERNAL_FUNC int emcore_move_mail_on_server(int account_id, int src_mailbox_id,
goto FINISH_OFF;
}
- if (!emstorage_update_read_mail_uid(mail_id, g_new_server_uid, mail->server_mailbox_name, &err_code)) {
+ if (!emstorage_update_read_mail_uid(multi_user_name, mail_id, g_new_server_uid, mail->server_mailbox_name, &err_code)) {
EM_DEBUG_EXCEPTION("emstorage_update_read_mail_uid failed [%d]", err_code);
goto FINISH_OFF;
}
@@ -6096,7 +5324,7 @@ FINISH_OFF:
return err_code;
}
-static int emcore_copy_mail_to_another_account_on_local_storeage(int input_mail_id, emstorage_mailbox_tbl_t *input_source_mailbox, emstorage_mailbox_tbl_t *input_target_mailbox, int input_task_id, int *output_mail_id)
+static int emcore_copy_mail_to_another_account_on_local_storeage(char *multi_user_name, int input_mail_id, emstorage_mailbox_tbl_t *input_source_mailbox, emstorage_mailbox_tbl_t *input_target_mailbox, int input_task_id, int *output_mail_id)
{
EM_DEBUG_FUNC_BEGIN("input_mail_id[%d] input_source_mailbox[%p] input_target_mailbox[%p] input_task_id [%d] output_mail_id[%p]", input_mail_id, input_source_mailbox, input_target_mailbox, input_task_id, output_mail_id);
@@ -6111,7 +5339,7 @@ static int emcore_copy_mail_to_another_account_on_local_storeage(int input_mail_
goto FINISH_OFF;
}
- if((err = emcore_get_mail_data(input_mail_id, &mail_data)) != EMAIL_ERROR_NONE) {
+ if((err = emcore_get_mail_data(multi_user_name, input_mail_id, &mail_data)) != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("emcore_get_mail_data failed [%d]", err);
err = EMAIL_ERROR_MAIL_NOT_FOUND;
goto FINISH_OFF;
@@ -6120,30 +5348,23 @@ static int emcore_copy_mail_to_another_account_on_local_storeage(int input_mail_
/* Check download status */
if(!(mail_data->body_download_status & EMAIL_BODY_DOWNLOAD_STATUS_FULLY_DOWNLOADED)) {
/* If not downloaded, download fully */
-#ifdef __FEATURE_USE_GMIME__
- if (!emcore_gmime_download_body_sections(NULL, input_source_mailbox->account_id,
- input_mail_id, (mail_data->attachment_count > 0)?1:0, NO_LIMITATION, input_task_id, 0, 0, &err)) {
- EM_DEBUG_EXCEPTION("emcore_gmime_download_body_sections failed - %d", err);
- goto FINISH_OFF;
- }
-#else
- if (!emcore_download_body_multi_sections_bulk(NULL,
+ if (!emcore_gmime_download_body_sections(multi_user_name,
+ NULL,
input_source_mailbox->account_id,
- input_mail_id,
- 0,
- (mail_data->attachment_count > 0)?1:0,
- NO_LIMITATION,
- input_task_id,
- 0, /*0: thread excluding event thread */
+ input_mail_id,
+ (mail_data->attachment_count > 0)?1:0,
+ NO_LIMITATION,
+ input_task_id,
+ 0,
+ 0,
&err)) {
- EM_DEBUG_EXCEPTION("emcore_download_body_multi_sections_bulk failed [%d]", err);
+ EM_DEBUG_EXCEPTION("emcore_gmime_download_body_sections failed - %d", err);
goto FINISH_OFF;
}
-#endif
}
/* Get attachments */
- if((err = emcore_get_attachment_data_list(input_mail_id, &attachment_data, &attachment_count)) != EMAIL_ERROR_NONE) {
+ if((err = emcore_get_attachment_data_list(multi_user_name, input_mail_id, &attachment_data, &attachment_count)) != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("emcore_get_attachment_data_list failed [%d]", err);
goto FINISH_OFF;
}
@@ -6155,7 +5376,7 @@ static int emcore_copy_mail_to_another_account_on_local_storeage(int input_mail_
mail_data->thread_id = 0;
mail_data->thread_item_count = 0;
- if((err = emcore_add_mail(mail_data, attachment_data, attachment_count, NULL, false, true)) != EMAIL_ERROR_NONE) {
+ if((err = emcore_add_mail(multi_user_name, mail_data, attachment_data, attachment_count, NULL, false, true)) != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("emcore_add_mail failed [%d]", err);
goto FINISH_OFF;
}
@@ -6175,7 +5396,7 @@ FINISH_OFF:
return err;
}
-INTERNAL_FUNC int emcore_move_mail_to_another_account(int input_mail_id, int input_source_mailbox_id, int input_target_mailbox_id, int input_task_id)
+INTERNAL_FUNC int emcore_move_mail_to_another_account(char *multi_user_name, int input_mail_id, int input_source_mailbox_id, int input_target_mailbox_id, int input_task_id)
{
EM_DEBUG_FUNC_BEGIN("input_mail_id[%d] input_source_mailbox_id[%d] input_target_mailbox_id[%d] result_mail_id[%p] input_task_id [%d]", input_mail_id, input_source_mailbox_id, input_target_mailbox_id, input_task_id);
int err = EMAIL_ERROR_NONE;
@@ -6186,12 +5407,12 @@ INTERNAL_FUNC int emcore_move_mail_to_another_account(int input_mail_id, int inp
email_account_t *source_account_ref = NULL;
email_account_t *target_account_ref = NULL;
- if((err = emstorage_get_mailbox_by_id(input_source_mailbox_id, &source_mailbox)) != EMAIL_ERROR_NONE) {
+ if((err = emstorage_get_mailbox_by_id(multi_user_name, input_source_mailbox_id, &source_mailbox)) != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("emstorage_get_mailbox_by_id failed for source_mailbox [%d]", err);
goto FINISH_OFF;
}
- if((err = emstorage_get_mailbox_by_id(input_target_mailbox_id, &target_mailbox)) != EMAIL_ERROR_NONE) {
+ if((err = emstorage_get_mailbox_by_id(multi_user_name, input_target_mailbox_id, &target_mailbox)) != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("emstorage_get_mailbox_by_id failed for target_mailbox [%d]", err);
goto FINISH_OFF;
}
@@ -6202,7 +5423,7 @@ INTERNAL_FUNC int emcore_move_mail_to_another_account(int input_mail_id, int inp
/* EAS -> X impossible */
/* X -> EAS impossible */
- source_account_ref = emcore_get_account_reference(source_mailbox->account_id);
+ source_account_ref = emcore_get_account_reference(multi_user_name, source_mailbox->account_id, false);
if(source_account_ref == NULL || source_account_ref->incoming_server_type == EMAIL_SERVER_TYPE_ACTIVE_SYNC) {
EM_DEBUG_EXCEPTION("Invalid account");
@@ -6210,7 +5431,7 @@ INTERNAL_FUNC int emcore_move_mail_to_another_account(int input_mail_id, int inp
goto FINISH_OFF;
}
- target_account_ref = emcore_get_account_reference(target_mailbox->account_id);
+ target_account_ref = emcore_get_account_reference(multi_user_name, target_mailbox->account_id, false);
if(target_account_ref == NULL || target_account_ref->incoming_server_type == EMAIL_SERVER_TYPE_ACTIVE_SYNC) {
EM_DEBUG_EXCEPTION("Invalid account");
@@ -6219,33 +5440,33 @@ INTERNAL_FUNC int emcore_move_mail_to_another_account(int input_mail_id, int inp
}
- if((err = emcore_copy_mail_to_another_account_on_local_storeage(input_mail_id, source_mailbox, target_mailbox, input_task_id, &moved_mail_id)) != EMAIL_ERROR_NONE) {
+ if((err = emcore_copy_mail_to_another_account_on_local_storeage(multi_user_name, input_mail_id, source_mailbox, target_mailbox, input_task_id, &moved_mail_id)) != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("emcore_copy_mail_to_another_account_on_local_storeage failed [%d]", err);
goto FINISH_OFF;
}
- if(!emcore_set_flags_field(source_mailbox->account_id, &input_mail_id, 1, EMAIL_FLAGS_DELETED_FIELD, 1 , &err)) {
+ if(!emcore_set_flags_field(multi_user_name, source_mailbox->account_id, &input_mail_id, 1, EMAIL_FLAGS_DELETED_FIELD, 1 , &err)) {
EM_DEBUG_EXCEPTION("emcore_set_flags_field failed [%d]", err);
goto FINISH_OFF;
}
if(target_account_ref->incoming_server_type == EMAIL_SERVER_TYPE_IMAP4) {
- if((err = emcore_sync_mail_from_client_to_server(moved_mail_id)) != EMAIL_ERROR_NONE) {
+ if((err = emcore_sync_mail_from_client_to_server(multi_user_name, moved_mail_id)) != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("emcore_sync_mail_from_client_to_server failed [%d]", err);
/* if append is failed, restore source mail and delete copied mail. */
- if(!emcore_set_flags_field(source_mailbox->account_id, &input_mail_id, 1, EMAIL_FLAGS_DELETED_FIELD, 0 , &err)) {
+ if(!emcore_set_flags_field(multi_user_name, source_mailbox->account_id, &input_mail_id, 1, EMAIL_FLAGS_DELETED_FIELD, 0 , &err)) {
EM_DEBUG_EXCEPTION("emcore_set_flags_field failed [%d]", err);
goto FINISH_OFF;
}
- if(!emcore_delete_mail(target_mailbox->account_id, &moved_mail_id, 1, false, 0, 0, &err_for_delete_mail))
+ if(!emcore_delete_mail(multi_user_name, target_mailbox->account_id, &moved_mail_id, 1, false, 0, 0, &err_for_delete_mail))
EM_DEBUG_EXCEPTION("emcore_delete_mail failed [%d]", err_for_delete_mail);
goto FINISH_OFF;
}
}
- if(!emcore_delete_mail(source_mailbox->account_id, &input_mail_id, 1, true, 0, 0, &err)) {
+ if(!emcore_delete_mail(multi_user_name, source_mailbox->account_id, &input_mail_id, 1, true, 0, 0, &err)) {
EM_DEBUG_EXCEPTION("emcore_delete_mail failed [%d]", err);
goto FINISH_OFF;
}
@@ -6272,9 +5493,12 @@ FINISH_OFF:
return err;
}
-INTERNAL_FUNC int emcore_save_mail_file(int account_id, int mail_id, int attachment_id, char *src_file_path, char *file_name, char *full_path, int max_path_len, int *err_code)
+INTERNAL_FUNC int emcore_save_mail_file(char *multi_user_name, int account_id, int mail_id, int attachment_id,
+ char *src_file_path, char *file_name, char *full_path, char *virtual_path,
+ int *err_code)
{
- EM_DEBUG_FUNC_BEGIN("account_id[%d], mail_id[%d], attachment_id[%d] , file_name[%p] , full_path[%p] , err_code[%p]", account_id, mail_id, attachment_id, file_name, full_path, err_code);
+ EM_DEBUG_FUNC_BEGIN("account_id[%d], mail_id[%d], attachment_id[%d], file_name[%p], full_path[%p], err_code[%p]",
+ account_id, mail_id, attachment_id, file_name, full_path, err_code);
int err = EMAIL_ERROR_NONE;
@@ -6284,12 +5508,20 @@ INTERNAL_FUNC int emcore_save_mail_file(int account_id, int mail_id, int attachm
goto FINISH_OFF;
}
- if (!emstorage_create_dir(account_id, mail_id, attachment_id, &err)) {
+ if (!emstorage_create_dir(multi_user_name, account_id, mail_id, attachment_id, &err)) {
EM_DEBUG_EXCEPTION("emstorage_create_dir failed [%d]", err);
goto FINISH_OFF;
}
-
- if (!emstorage_get_save_name(account_id, mail_id, attachment_id, file_name, full_path, max_path_len, &err)) {
+
+ if (!emstorage_get_save_name(multi_user_name,
+ account_id,
+ mail_id,
+ attachment_id,
+ file_name,
+ full_path,
+ virtual_path,
+ MAX_PATH,
+ &err)) {
EM_DEBUG_EXCEPTION("emstorage_get_save_name failed [%d]", err);
goto FINISH_OFF;
}
@@ -6304,15 +5536,24 @@ INTERNAL_FUNC int emcore_save_mail_file(int account_id, int mail_id, int attachm
FINISH_OFF:
if (err_code)
*err_code = err;
+
return 1;
}
/* description : update mail information */
-INTERNAL_FUNC int emcore_update_mail(email_mail_data_t *input_mail_data, email_attachment_data_t *input_attachment_data_list, int input_attachment_count, email_meeting_request_t* input_meeting_request, int input_from_eas)
+INTERNAL_FUNC int emcore_update_mail(char *multi_user_name, email_mail_data_t *input_mail_data,
+ email_attachment_data_t *input_attachment_data_list,
+ int input_attachment_count,
+ email_meeting_request_t* input_meeting_request,
+ int input_from_eas)
{
- EM_DEBUG_FUNC_BEGIN("input_mail_data[%p], input_attachment_data_list[%p], input_attachment_count[%d], input_meeting_request[%p], input_from_eas[%d]", input_mail_data, input_attachment_data_list, input_attachment_count, input_meeting_request, input_from_eas);
+ EM_DEBUG_FUNC_BEGIN("input_mail_data[%p], input_attachment_data_list[%p], input_attachment_count[%d], "
+ "input_meeting_request[%p], input_from_eas[%d]",
+ input_mail_data, input_attachment_data_list, input_attachment_count,
+ input_meeting_request, input_from_eas);
char filename_buf[1024] = {0, };
+ char virtual_path[1024] = {0, };
char mailbox_id_param_string[10] = {0, };
char *body_text_file_name = NULL;
int i = 0;
@@ -6324,35 +5565,56 @@ INTERNAL_FUNC int emcore_update_mail(email_mail_data_t *input_mail_data, email_a
int ori_attachment_count = 0;
int *temp_attachment_id_array = NULL;
email_attachment_data_t *ori_attachment_data_list = NULL;
+ char *prefix_path = NULL;
+ char real_file_path[MAX_PATH] = {0};
-
- if (!input_mail_data || (input_attachment_count && !input_attachment_data_list) || (!input_attachment_count &&input_attachment_data_list)) {
+ if (!input_mail_data || (input_attachment_count && !input_attachment_data_list) ||
+ (!input_attachment_count &&input_attachment_data_list)) {
EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
err = EMAIL_ERROR_INVALID_PARAM;
goto FINISH_OFF2;
}
+ if (EM_SAFE_STRLEN(multi_user_name) > 0) {
+ err = emcore_get_container_path(multi_user_name, &prefix_path);
+ if (err != EMAIL_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("emcore_get_container_path failed : [%d]", err);
+ goto FINISH_OFF2;
+ }
+ } else {
+ prefix_path = strdup("");
+ }
+
if(input_from_eas == 0) {
if (input_mail_data->file_path_plain) {
- if (stat(input_mail_data->file_path_plain, &st_buf) < 0) {
+ memset(real_file_path, 0x00, sizeof(real_file_path));
+ SNPRINTF(real_file_path, sizeof(real_file_path), "%s%s", prefix_path, input_mail_data->file_path_plain);
+
+ if (stat(real_file_path, &st_buf) < 0) {
EM_DEBUG_EXCEPTION_SEC("input_mail_data->file_path_plain, stat(\"%s\") failed...", input_mail_data->file_path_plain);
err = EMAIL_ERROR_FILE_NOT_FOUND;
goto FINISH_OFF2;
}
}
-
+
if (input_mail_data->file_path_html) {
- if (stat(input_mail_data->file_path_html, &st_buf) < 0) {
+ memset(real_file_path, 0x00, sizeof(real_file_path));
+ SNPRINTF(real_file_path, sizeof(real_file_path), "%s%s", prefix_path, input_mail_data->file_path_html);
+
+ if (stat(real_file_path, &st_buf) < 0) {
EM_DEBUG_EXCEPTION_SEC("input_mail_data->file_path_html, stat(\"%s\") failed...", input_mail_data->file_path_html);
err = EMAIL_ERROR_FILE_NOT_FOUND;
goto FINISH_OFF2;
}
}
-
+
if (input_attachment_count && input_attachment_data_list) {
for (i = 0; i < input_attachment_count; i++) {
if (input_attachment_data_list[i].save_status) {
- if (!input_attachment_data_list[i].attachment_path || stat(input_attachment_data_list[i].attachment_path, &st_buf) < 0) {
+ memset(real_file_path, 0x00, sizeof(real_file_path));
+ SNPRINTF(real_file_path, sizeof(real_file_path), "%s%s", prefix_path, input_attachment_data_list[i].attachment_path);
+
+ if (!input_attachment_data_list[i].attachment_path || stat(real_file_path, &st_buf) < 0) {
EM_DEBUG_EXCEPTION("stat(\"%s\") failed...", input_attachment_data_list[i].attachment_path);
err = EMAIL_ERROR_FILE_NOT_FOUND;
goto FINISH_OFF2;
@@ -6363,25 +5625,35 @@ INTERNAL_FUNC int emcore_update_mail(email_mail_data_t *input_mail_data, email_a
}
if(input_mail_data->mail_size == 0) {
- emcore_calc_mail_size(input_mail_data, input_attachment_data_list, input_attachment_count, &(input_mail_data->mail_size));
+ emcore_calc_mail_size(multi_user_name, input_mail_data, input_attachment_data_list, input_attachment_count, &(input_mail_data->mail_size));
}
- if (input_mail_data->file_path_plain) { /* Save plain text body. */
+ if (input_mail_data->file_path_plain) {
+ /* Save plain text body. */
if ( (err = em_get_file_name_from_file_path(input_mail_data->file_path_plain, &body_text_file_name)) != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("em_get_file_name_from_file_path failed [%d]", err);
err = EMAIL_ERROR_INVALID_FILE_PATH;
goto FINISH_OFF2;
}
- if (!emcore_save_mail_file(input_mail_data->account_id, input_mail_data->mail_id, 0, input_mail_data->file_path_plain, body_text_file_name, filename_buf, sizeof(filename_buf), &err)) {
+ if (!emcore_save_mail_file(multi_user_name,
+ input_mail_data->account_id,
+ input_mail_data->mail_id,
+ 0,
+ input_mail_data->file_path_plain,
+ body_text_file_name,
+ filename_buf,
+ virtual_path,
+ &err)) {
EM_DEBUG_EXCEPTION("emcore_save_mail_file failed [%d]", err);
goto FINISH_OFF2;
}
EM_SAFE_FREE(input_mail_data->file_path_plain);
- input_mail_data->file_path_plain = EM_SAFE_STRDUP(filename_buf);
+ input_mail_data->file_path_plain = EM_SAFE_STRDUP(virtual_path);
}
- if (input_mail_data->file_path_html) { /* Save HTML text body. */
+ if (input_mail_data->file_path_html) {
+ /* Save HTML text body. */
EM_SAFE_FREE(body_text_file_name);
if ( (err = em_get_file_name_from_file_path(input_mail_data->file_path_html, &body_text_file_name)) != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("em_get_file_name_from_file_path failed [%d]", err);
@@ -6389,21 +5661,38 @@ INTERNAL_FUNC int emcore_update_mail(email_mail_data_t *input_mail_data, email_a
goto FINISH_OFF2;
}
- if (!emcore_save_mail_file(input_mail_data->account_id, input_mail_data->mail_id, 0, input_mail_data->file_path_html, body_text_file_name, filename_buf, sizeof(filename_buf), &err)) {
+ if (!emcore_save_mail_file(multi_user_name,
+ input_mail_data->account_id,
+ input_mail_data->mail_id,
+ 0,
+ input_mail_data->file_path_html,
+ body_text_file_name,
+ filename_buf,
+ virtual_path,
+ &err)) {
EM_DEBUG_EXCEPTION("emcore_save_mail_file failed [%d]", err);
goto FINISH_OFF2;
}
EM_SAFE_FREE(input_mail_data->file_path_html);
- input_mail_data->file_path_html = EM_SAFE_STRDUP(filename_buf);
- }
-
- if (input_mail_data->file_path_mime_entity) { /* Save mime entity. */
- if (!emcore_save_mail_file(input_mail_data->account_id, input_mail_data->mail_id, 0, input_mail_data->file_path_mime_entity, "mime_entity", filename_buf, sizeof(filename_buf), &err)) {
+ input_mail_data->file_path_html = EM_SAFE_STRDUP(virtual_path);
+ }
+
+ if (input_mail_data->file_path_mime_entity) {
+ /* Save mime entity. */
+ if (!emcore_save_mail_file(multi_user_name,
+ input_mail_data->account_id,
+ input_mail_data->mail_id,
+ 0,
+ input_mail_data->file_path_mime_entity,
+ "mime_entity",
+ filename_buf,
+ virtual_path,
+ &err)) {
EM_DEBUG_EXCEPTION("emcore_save_mail_file failed [%d]", err);
goto FINISH_OFF2;
}
EM_SAFE_FREE(input_mail_data->file_path_mime_entity);
- input_mail_data->file_path_mime_entity = EM_SAFE_STRDUP(filename_buf);
+ input_mail_data->file_path_mime_entity = EM_SAFE_STRDUP(virtual_path);
}
if (input_attachment_data_list && input_attachment_count) {
@@ -6411,8 +5700,8 @@ INTERNAL_FUNC int emcore_update_mail(email_mail_data_t *input_mail_data, email_a
int j = 0;
int compare_result = 1;
email_attachment_data_t *temp_attachment_data = NULL;
-
- if ((err = emcore_get_attachment_data_list(input_mail_data->mail_id, &ori_attachment_data_list, &ori_attachment_count)) != EMAIL_ERROR_NONE) {
+
+ if ((err = emcore_get_attachment_data_list(multi_user_name, input_mail_data->mail_id, &ori_attachment_data_list, &ori_attachment_count)) != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("emcore_get_attachment_data_list failed : [%d]", err);
}
@@ -6425,7 +5714,7 @@ INTERNAL_FUNC int emcore_update_mail(email_mail_data_t *input_mail_data, email_a
for(i = 0; i < input_attachment_count; i++) {
temp_attachment_data = input_attachment_data_list + i;
- if ( (err = emcore_mail_compare_filename_of_attachment_data(input_mail_data->mail_id, \
+ if ( (err = emcore_mail_compare_filename_of_attachment_data(multi_user_name, input_mail_data->mail_id, \
temp_attachment_data->attachment_id, temp_attachment_data, &compare_result)) != EMAIL_ERROR_NONE) {
if (err == EMAIL_ERROR_ATTACHMENT_NOT_FOUND)
EM_DEBUG_LOG ("no attachment found");
@@ -6436,7 +5725,7 @@ INTERNAL_FUNC int emcore_update_mail(email_mail_data_t *input_mail_data, email_a
switch (compare_result) {
case 0 :
EM_DEBUG_LOG("file name and attachment id are same, update exising attachment");
- if (!emcore_mail_update_attachment_data(input_mail_data->mail_id, temp_attachment_data)) {
+ if (!emcore_mail_update_attachment_data(multi_user_name, input_mail_data->mail_id, temp_attachment_data)) {
EM_DEBUG_EXCEPTION("emcore_mail_update_attachment_data failed [%d]", err);
goto FINISH_OFF2;
}
@@ -6444,7 +5733,7 @@ INTERNAL_FUNC int emcore_update_mail(email_mail_data_t *input_mail_data, email_a
break;
case 1 :
EM_DEBUG_LOG("save names are different");
- if ( (err = emcore_add_attachment_data(input_mail_data->mail_id, temp_attachment_data)) != EMAIL_ERROR_NONE) {
+ if ( (err = emcore_add_attachment_data(multi_user_name, input_mail_data->mail_id, temp_attachment_data)) != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("emcore_add_attachment failed [%d]", err);
goto FINISH_OFF2;
}
@@ -6468,7 +5757,7 @@ INTERNAL_FUNC int emcore_update_mail(email_mail_data_t *input_mail_data, email_a
compare_result = 0;
for (j = 0; j < input_attachment_count; j++) {
- if (!emstorage_get_attachment(temp_attachment_id_array[j], &temp_attachment_tbl_t, false, &err)) {
+ if (!emstorage_get_attachment(multi_user_name, temp_attachment_id_array[j], &temp_attachment_tbl_t, false, &err)) {
EM_DEBUG_EXCEPTION("emstorage_get_attachment failed : [%d]", err);
continue;
}
@@ -6487,12 +5776,12 @@ INTERNAL_FUNC int emcore_update_mail(email_mail_data_t *input_mail_data, email_a
switch (compare_result) {
case 0 : /* Delete the attachment on db and file */
- if (!emcore_delete_mail_attachment(temp_attachment_data->attachment_id, &err)) {
+ if (!emcore_delete_mail_attachment(multi_user_name, temp_attachment_data->attachment_id, &err)) {
EM_DEBUG_EXCEPTION("emcore_delete_mail_attachment failed [%d]", err);
}
break;
case 2 : /* Delete the attachment on db */
- if (!emstorage_delete_attachment_on_db(temp_attachment_data->attachment_id, true, &err)) {
+ if (!emstorage_delete_attachment_on_db(multi_user_name, temp_attachment_data->attachment_id, true, &err)) {
EM_DEBUG_EXCEPTION("emstorage_delete_attachment_on_db failed : [%d]", err);
}
break;
@@ -6514,7 +5803,11 @@ INTERNAL_FUNC int emcore_update_mail(email_mail_data_t *input_mail_data, email_a
EM_DEBUG_LOG("preview_text[%p]", input_mail_data->preview_text);
if (input_mail_data->preview_text == NULL) {
- if ( (err =emcore_get_preview_text_from_file(input_mail_data->file_path_plain, input_mail_data->file_path_html, MAX_PREVIEW_TEXT_LENGTH, &(input_mail_data->preview_text))) != EMAIL_ERROR_NONE) {
+ if ( (err =emcore_get_preview_text_from_file(multi_user_name,
+ input_mail_data->file_path_plain,
+ input_mail_data->file_path_html,
+ MAX_PREVIEW_TEXT_LENGTH,
+ &(input_mail_data->preview_text))) != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("emcore_get_preview_text_from_file failed[%d]", err);
if (err != EMAIL_ERROR_EMPTY_FILE)
goto FINISH_OFF2;
@@ -6527,12 +5820,12 @@ INTERNAL_FUNC int emcore_update_mail(email_mail_data_t *input_mail_data, email_a
}
/* BEGIN TRANSACTION; */
- if (!emstorage_begin_transaction(NULL, NULL, &err)) {
+ if (!emstorage_begin_transaction(multi_user_name, NULL, NULL, &err)) {
EM_DEBUG_EXCEPTION("emstorage_begin_transaction failed [%d]", err);
goto FINISH_OFF2;
}
- if (!emstorage_change_mail_field(input_mail_data->mail_id, UPDATE_MAIL, converted_mail_tbl_data, false, &err)) {
+ if (!emstorage_change_mail_field(multi_user_name, input_mail_data->mail_id, UPDATE_MAIL, converted_mail_tbl_data, false, &err)) {
EM_DEBUG_EXCEPTION("emstorage_change_mail_field failed [%d]", err);
goto FINISH_OFF;
}
@@ -6540,12 +5833,13 @@ INTERNAL_FUNC int emcore_update_mail(email_mail_data_t *input_mail_data, email_a
#ifdef __FEATURE_BODY_SEARCH__
/* strip html content and save into mail_text_tbl */
char *stripped_text = NULL;
- if (!emcore_strip_mail_body_from_file(converted_mail_tbl_data, &stripped_text, &err) || stripped_text == NULL) {
+ if (!emcore_strip_mail_body_from_file(multi_user_name, converted_mail_tbl_data, &stripped_text, &err) || stripped_text == NULL) {
EM_DEBUG_EXCEPTION("emcore_strip_mail_body_from_file failed [%d]", err);
}
emstorage_mail_text_tbl_t *mail_text;
- if (!emstorage_get_mail_text_by_id(input_mail_data->mail_id, &mail_text, true, &err) || !mail_text) {
+
+ if (!emstorage_get_mail_text_by_id(multi_user_name, input_mail_data->mail_id, &mail_text, true, &err) || !mail_text) {
EM_DEBUG_EXCEPTION("emstorage_get_mail_text_by_id failed [%d]", err);
EM_SAFE_FREE(stripped_text);
goto FINISH_OFF;
@@ -6554,7 +5848,7 @@ INTERNAL_FUNC int emcore_update_mail(email_mail_data_t *input_mail_data, email_a
EM_SAFE_FREE(mail_text->body_text);
mail_text->body_text = stripped_text;
- if (!emstorage_change_mail_text_field(input_mail_data->mail_id, mail_text, false, &err)) {
+ if (!emstorage_change_mail_text_field(multi_user_name, input_mail_data->mail_id, mail_text, false, &err)) {
EM_DEBUG_EXCEPTION("emstorage_change_mail_text_field failed [%d]", err);
emstorage_free_mail_text(&mail_text, 1, NULL); /*prevent 17955*/
goto FINISH_OFF;
@@ -6568,31 +5862,31 @@ INTERNAL_FUNC int emcore_update_mail(email_mail_data_t *input_mail_data, email_a
|| input_mail_data->meeting_request_status == EMAIL_MAIL_TYPE_MEETING_RESPONSE
|| input_mail_data->meeting_request_status == EMAIL_MAIL_TYPE_MEETING_ORIGINATINGREQUEST) {
/* check where there is a meeting request in DB */
- if (!emstorage_get_meeting_request(input_mail_data->mail_id, &meeting_req, false, &err) && err != EMAIL_ERROR_DATA_NOT_FOUND) {
+ if (!emstorage_get_meeting_request(multi_user_name, input_mail_data->mail_id, &meeting_req, false, &err) && err != EMAIL_ERROR_DATA_NOT_FOUND) {
EM_DEBUG_EXCEPTION("emstorage_get_meeting_request failed [%d]", err);
goto FINISH_OFF;
}
+
if (err == EMAIL_ERROR_DATA_NOT_FOUND) { /* insert */
emstorage_mail_tbl_t *original_mail = NULL;
- if (!emstorage_get_mail_by_id(input_mail_data->mail_id, &original_mail, false, &err)) {
+ if (!emstorage_get_mail_by_id(multi_user_name, input_mail_data->mail_id, &original_mail, false, &err)) {
EM_DEBUG_EXCEPTION("emstorage_get_mail_by_id failed [%d]", err);
goto FINISH_OFF;
}
- if (original_mail) {
- if (!emstorage_add_meeting_request(input_mail_data->account_id, original_mail->mailbox_id, input_meeting_request, false, &err)) {
- EM_DEBUG_EXCEPTION("emstorage_add_meeting_request failed [%d]", err);
- emstorage_free_mail(&original_mail, 1, NULL);
- goto FINISH_OFF;
+ if (original_mail) {
+ if (!emstorage_add_meeting_request(multi_user_name, input_mail_data->account_id, original_mail->mailbox_id, input_meeting_request, false, &err)) {
+ EM_DEBUG_EXCEPTION("emstorage_add_meeting_request failed [%d]", err);
+ emstorage_free_mail(&original_mail, 1, NULL);
+ goto FINISH_OFF;
+ }
+ emstorage_free_mail(&original_mail, 1, NULL);
}
- emstorage_free_mail(&original_mail, 1, NULL);
- }
}
else { /* update */
- if (!emstorage_update_meeting_request(input_meeting_request, false, &err)) {
+ if (!emstorage_update_meeting_request(multi_user_name, input_meeting_request, false, &err)) {
EM_DEBUG_EXCEPTION("emstorage_update_meeting_request failed [%d]", err);
-
goto FINISH_OFF;
}
}
@@ -6601,22 +5895,18 @@ INTERNAL_FUNC int emcore_update_mail(email_mail_data_t *input_mail_data, email_a
FINISH_OFF:
if (err == EMAIL_ERROR_NONE) {
/* COMMIT TRANSACTION; */
- if (emstorage_commit_transaction(NULL, NULL, NULL) == false) {
+ if (emstorage_commit_transaction(multi_user_name, NULL, NULL, NULL) == false) {
err = EMAIL_ERROR_DB_FAILURE;
}
SNPRINTF(mailbox_id_param_string, 10, "%d", input_mail_data->mailbox_id);
- if (!emcore_notify_storage_event(NOTI_MAIL_UPDATE,
- input_mail_data->account_id,
- input_mail_data->mail_id,
- mailbox_id_param_string,
- (input_mail_data->meeting_request_status != EMAIL_MAIL_TYPE_NORMAL) ? UPDATE_MEETING : UPDATE_MAIL))
+ if (!emcore_notify_storage_event(NOTI_MAIL_UPDATE, input_mail_data->account_id, input_mail_data->mail_id, mailbox_id_param_string, input_mail_data->meeting_request_status?UPDATE_MEETING:UPDATE_MAIL))
EM_DEBUG_EXCEPTION(" emcore_notify_storage_event failed [NOTI_MAIL_UPDATE] ");
}
else {
/* ROLLBACK TRANSACTION; */
- if (emstorage_rollback_transaction(NULL, NULL, NULL) == false)
+ if (emstorage_rollback_transaction(multi_user_name, NULL, NULL, NULL) == false)
err = EMAIL_ERROR_DB_FAILURE;
}
@@ -6624,6 +5914,7 @@ FINISH_OFF2:
EM_SAFE_FREE(body_text_file_name);
EM_SAFE_FREE(temp_attachment_id_array);
+ EM_SAFE_FREE(prefix_path);
if (ori_attachment_data_list)
emcore_free_attachment_data(&ori_attachment_data_list, ori_attachment_count, NULL);
@@ -6641,7 +5932,7 @@ FINISH_OFF2:
}
-INTERNAL_FUNC int emcore_set_flags_field(int account_id, int mail_ids[], int num, email_flags_field_type field_type, int value, int *err_code)
+INTERNAL_FUNC int emcore_set_flags_field(char *multi_user_name, int account_id, int mail_ids[], int num, email_flags_field_type field_type, int value, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("account_id [%d], mail_ids[%p], num [%d], field_type [%d], value[%d], err_code[%p]", account_id, mail_ids, num, field_type, value, err_code);
@@ -6657,13 +5948,13 @@ INTERNAL_FUNC int emcore_set_flags_field(int account_id, int mail_ids[], int num
goto FINISH_OFF;
}
- if (!emstorage_set_field_of_mails_with_integer_value(account_id, mail_ids, num, field_type_name[field_type], value, true, &err)) {
+ if (!emstorage_set_field_of_mails_with_integer_value(multi_user_name, account_id, mail_ids, num, field_type_name[field_type], value, true, &err)) {
EM_DEBUG_EXCEPTION("emstorage_set_field_of_mails_with_integer_value failed [%d]", err);
goto FINISH_OFF;
}
- if(field_type == EMAIL_FLAGS_SEEN_FIELD)
- emcore_display_unread_in_badge(NULL);
+ if (field_type == EMAIL_FLAGS_SEEN_FIELD)
+ emcore_display_unread_in_badge(multi_user_name);
ret = true;
@@ -6803,7 +6094,7 @@ FINISH_OFF:
}
-INTERNAL_FUNC int emcore_sync_flag_with_server(int mail_id, int event_handle, int *err_code)
+INTERNAL_FUNC int emcore_sync_flag_with_server(char *multi_user_name, int mail_id, int event_handle, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("mail_id[%p], err_code[%p]", mail_id, err_code);
@@ -6827,15 +6118,14 @@ INTERNAL_FUNC int emcore_sync_flag_with_server(int mail_id, int event_handle, in
FINISH_OFF_IF_EVENT_CANCELED (err, event_handle);
- if (!emstorage_get_mail_by_id(mail_id, &mail, true, &err) || !mail) {
+ if (!emstorage_get_mail_by_id(multi_user_name, mail_id, &mail, true, &err) || !mail) {
EM_DEBUG_EXCEPTION("emstorage_get_mail_by_id failed [%d]", err);
-
goto FINISH_OFF;
}
account_id = mail->account_id;
- if (!(ref_account = emcore_get_account_reference(account_id))) {
+ if (!(ref_account = emcore_get_account_reference(multi_user_name, account_id, false))) {
EM_DEBUG_EXCEPTION("emcore_get_account_reference failed [%d]", account_id);
err = EMAIL_ERROR_INVALID_ACCOUNT;
goto FINISH_OFF;
@@ -6844,7 +6134,7 @@ INTERNAL_FUNC int emcore_sync_flag_with_server(int mail_id, int event_handle, in
FINISH_OFF_IF_EVENT_CANCELED (err, event_handle);
/* open mail server. */
- if (!emcore_connect_to_remote_mailbox(account_id, mail->mailbox_id, (void **)&stream, &err) || !stream) {
+ if (!emcore_connect_to_remote_mailbox(multi_user_name, account_id, mail->mailbox_id, (void **)&stream, &err) || !stream) {
EM_DEBUG_EXCEPTION("emcore_connect_to_remote_mailbox failed [%d]", err);
goto FINISH_OFF;
}
@@ -6930,7 +6220,7 @@ FINISH_OFF:
return ret;
}
-INTERNAL_FUNC int emcore_sync_seen_flag_with_server(int mail_ids[], int num, int event_handle, int *err_code)
+INTERNAL_FUNC int emcore_sync_seen_flag_with_server(char *multi_user_name, int mail_ids[], int num, int event_handle, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("mail_ids[%p], err_code[%p]", mail_ids[0], err_code);
@@ -6958,22 +6248,21 @@ INTERNAL_FUNC int emcore_sync_seen_flag_with_server(int mail_ids[], int num, int
mail_id = mail_ids[0];
- if (!emstorage_get_mail_by_id(mail_id, &mail, true, &err) || !mail) {
+ if (!emstorage_get_mail_by_id(multi_user_name, mail_id, &mail, true, &err) || !mail) {
EM_DEBUG_EXCEPTION("emstorage_get_mail_by_id failed [%d]", err);
-
goto FINISH_OFF;
}
account_id = mail->account_id;
- if (!(ref_account = emcore_get_account_reference(account_id))) {
+ if (!(ref_account = emcore_get_account_reference(multi_user_name, account_id, false))) {
EM_DEBUG_EXCEPTION("emcore_get_account_reference failed [%d]", account_id);
err = EMAIL_ERROR_INVALID_ACCOUNT;
goto FINISH_OFF;
}
/* open mail server. */
- if (!emcore_connect_to_remote_mailbox(account_id, mail->mailbox_id, (void **)&stream, &err) || !stream) {
+ if (!emcore_connect_to_remote_mailbox(multi_user_name, account_id, mail->mailbox_id, (void **)&stream, &err) || !stream) {
EM_DEBUG_EXCEPTION("emcore_connect_to_remote_mailbox failed [%d]", err);
goto FINISH_OFF;
}
@@ -6987,9 +6276,8 @@ INTERNAL_FUNC int emcore_sync_seen_flag_with_server(int mail_ids[], int num, int
FINISH_OFF_IF_EVENT_CANCELED (err, event_handle);
- if (!emstorage_get_mail_by_id(mail_id, &mail, true, &err) || !mail) {
+ if (!emstorage_get_mail_by_id(multi_user_name, mail_id, &mail, true, &err) || !mail) {
EM_DEBUG_EXCEPTION("emstorage_get_mail_by_id failed [%d]", err);
-
goto FINISH_OFF;
}
@@ -7133,7 +6421,7 @@ INTERNAL_FUNC int emcore_free_attachment_data(email_attachment_data_t **attachme
#ifdef __FEATURE_PARTIAL_BODY_DOWNLOAD__
-INTERNAL_FUNC int emcore_delete_pbd_activity(int account_id, int mail_id, int activity_id, int *err_code)
+INTERNAL_FUNC int emcore_delete_pbd_activity(char *multi_user_name, int account_id, int mail_id, int activity_id, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("account_id[%d], mail_id[%d], err_code[%p]", account_id, mail_id, err_code);
@@ -7148,13 +6436,13 @@ INTERNAL_FUNC int emcore_delete_pbd_activity(int account_id, int mail_id, int ac
int err = EMAIL_ERROR_NONE;
int before_tr_begin = 0;
- if (!emstorage_begin_transaction(NULL, NULL, &err)) {
+ if (!emstorage_begin_transaction(multi_user_name, NULL, NULL, &err)) {
EM_DEBUG_EXCEPTION("emstorage_begin_transaction failed [%d]", err);
before_tr_begin = 1;
goto FINISH_OFF;
}
- if (!emstorage_delete_pbd_activity(account_id, mail_id, activity_id, false, &err)) {
+ if (!emstorage_delete_pbd_activity(multi_user_name, account_id, mail_id, activity_id, false, &err)) {
EM_DEBUG_EXCEPTION("emstorage_delete_pbd_activity failed [%d]", err);
goto FINISH_OFF;
}
@@ -7163,12 +6451,12 @@ INTERNAL_FUNC int emcore_delete_pbd_activity(int account_id, int mail_id, int ac
FINISH_OFF:
if (ret == true) { /* COMMIT TRANSACTION; */
- if (emstorage_commit_transaction(NULL, NULL, NULL) == false) {
+ if (emstorage_commit_transaction(multi_user_name, NULL, NULL, NULL) == false) {
err = EMAIL_ERROR_DB_FAILURE;
ret = false;
}
} else { /* ROLLBACK TRANSACTION; */
- if (!before_tr_begin && emstorage_rollback_transaction(NULL, NULL, NULL) == false)
+ if (!before_tr_begin && emstorage_rollback_transaction(multi_user_name, NULL, NULL, NULL) == false)
err = EMAIL_ERROR_DB_FAILURE;
}
@@ -7193,13 +6481,13 @@ INTERNAL_FUNC int emcore_insert_pbd_activity(email_event_partial_body_thd *local
int err = EMAIL_ERROR_NONE;
int before_tr_begin = 0;
- if (!emstorage_begin_transaction(NULL, NULL, &err)) {
+ if (!emstorage_begin_transaction(local_activity->multi_user_name, NULL, NULL, &err)) {
EM_DEBUG_EXCEPTION("emstorage_begin_transaction failed [%d]", err);
before_tr_begin = 1;
goto FINISH_OFF;
}
- if (!emstorage_add_pbd_activity(local_activity, activity_id, false, &err)) {
+ if (!emstorage_add_pbd_activity(local_activity->multi_user_name, local_activity, activity_id, false, &err)) {
EM_DEBUG_EXCEPTION("emstorage_add_pbd_activity failed [%d]", err);
goto FINISH_OFF;
}
@@ -7208,17 +6496,18 @@ INTERNAL_FUNC int emcore_insert_pbd_activity(email_event_partial_body_thd *local
FINISH_OFF:
if (ret == true) { /* COMMIT TRANSACTION; */
- if (emstorage_commit_transaction(NULL, NULL, NULL) == false) {
+ if (emstorage_commit_transaction(local_activity->multi_user_name, NULL, NULL, NULL) == false) {
err = EMAIL_ERROR_DB_FAILURE;
ret = false;
}
} else { /* ROLLBACK TRANSACTION; */
- if (!before_tr_begin && emstorage_rollback_transaction(NULL, NULL, NULL) == false)
+ if (!before_tr_begin && emstorage_rollback_transaction(local_activity->multi_user_name, NULL, NULL, NULL) == false)
err = EMAIL_ERROR_DB_FAILURE;
}
if (err_code != NULL)
*err_code = err;
+
EM_DEBUG_FUNC_END();
return ret;
}
@@ -7229,7 +6518,7 @@ FINISH_OFF:
/* API to set or unset a field of flags on server in single IMAP request to server */
-INTERNAL_FUNC int emcore_sync_flags_field_with_server(int mail_ids[], int num, email_flags_field_type field_type, int value, int *err_code)
+INTERNAL_FUNC int emcore_sync_flags_field_with_server(char *multi_user_name, int mail_ids[], int num, email_flags_field_type field_type, int value, int *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);
@@ -7266,16 +6555,14 @@ INTERNAL_FUNC int emcore_sync_flags_field_with_server(int mail_ids[], int num, e
mail_id = mail_ids[0];
- if (!emstorage_get_mail_field_by_id(mail_id, RETRIEVE_FLAG, &mail, true, &err) || !mail) /*To DO : This is a existing bug. on mail deletion before this call it will fail always */ {
+ if (!emstorage_get_mail_field_by_id(multi_user_name, mail_id, RETRIEVE_FLAG, &mail, true, &err) || !mail) /*To DO : This is a existing bug. on mail deletion before this call it will fail always */ {
EM_DEBUG_LOG("emstorage_get_mail_by_id failed [%d]", err);
-
goto FINISH_OFF;
}
account_id = mail[0].account_id;
- temp_account = emcore_get_account_reference(account_id);
-
+ temp_account = emcore_get_account_reference(multi_user_name, account_id, false);
if (!temp_account) {
EM_DEBUG_EXCEPTION("emcore_get_account_reference failed [%d]", account_id);
err = EMAIL_ERROR_INVALID_ACCOUNT;
@@ -7287,8 +6574,8 @@ INTERNAL_FUNC int emcore_sync_flags_field_with_server(int mail_ids[], int num, e
err = EMAIL_ERROR_NOT_SUPPORTED;
goto FINISH_OFF;
}
-
- if (!emcore_connect_to_remote_mailbox(account_id, mail->mailbox_id, (void **)&stream, &err) || !stream) {
+
+ if (!emcore_connect_to_remote_mailbox(multi_user_name, account_id, mail->mailbox_id, (void **)&stream, &err) || !stream) {
EM_DEBUG_EXCEPTION("emcore_connect_to_remote_mailbox failed [%d]", err);
goto FINISH_OFF;
}
@@ -7312,8 +6599,7 @@ INTERNAL_FUNC int emcore_sync_flags_field_with_server(int mail_ids[], int num, e
for (i = 0; i < string_count; ++i) {
/* Get the set of mail_ds and corresponding server_mail_ids sorted by server mail ids in ascending order */
-
- if (false == emstorage_get_id_set_from_mail_ids(string_list[i], &id_set, &id_set_count, &err)) {
+ if (false == emstorage_get_id_set_from_mail_ids(multi_user_name, string_list[i], &id_set, &id_set_count, &err)) {
EM_DEBUG_EXCEPTION("emstorage_get_id_set_from_mail_ids failed [%d]", err);
goto FINISH_OFF;
}
@@ -7403,6 +6689,8 @@ INTERNAL_FUNC int emcore_sync_flags_field_with_server(int mail_ids[], int num, e
FINISH_OFF:
+ EM_SAFE_FREE(id_set);
+
#ifdef __FEATURE_LOCAL_ACTIVITY__
if (ret) {
emstorage_activity_tbl_t new_activity;
@@ -7439,12 +6727,13 @@ FINISH_OFF:
if (err_code != NULL)
*err_code = err;
+
EM_DEBUG_FUNC_END();
return ret;
}
#endif
-static int emcore_mail_move_by_filter_rule(int account_id, int mailbox_id, int mailbox_type, emstorage_rule_tbl_t *filter_info)
+static int emcore_mail_move_by_filter_rule(char *multi_user_name, int account_id, int mailbox_id, int mailbox_type, emstorage_rule_tbl_t *filter_info)
{
EM_DEBUG_FUNC_BEGIN("account_id:[%d], mailbox_id:[%d], filter_info:[%p]", account_id, mailbox_id, filter_info);
int err = EMAIL_ERROR_NONE;
@@ -7464,11 +6753,10 @@ static int emcore_mail_move_by_filter_rule(int account_id, int mailbox_id, int m
return err;
}
- if (filter_info->rule_id > 0 && !emstorage_update_tag_id(filter_info->rule_id, 0, &err)) {
- EM_DEBUG_EXCEPTION("emstorage_update_tag_id failed : [%d]", err);
- }
+ if (filter_info->rule_id > 0 && !emstorage_update_tag_id(multi_user_name, filter_info->rule_id, 0, &err))
+ EM_DEBUG_EXCEPTION("emstorage_update_tag_id failed : [%d]", err);
- if (!emstorage_filter_mails_by_rule(account_id, mailbox_id, mailbox_type, false, filter_info, &filter_mail_id_list, &filter_mail_id_count, &err)) {
+ if (!emstorage_filter_mails_by_rule(multi_user_name, account_id, mailbox_id, mailbox_type, false, filter_info, &filter_mail_id_list, &filter_mail_id_count, &err)) {
EM_DEBUG_EXCEPTION("emstorage_filter_mails_by_rule failed [%d]", err);
goto FINISH_OFF;
}
@@ -7505,29 +6793,29 @@ static int emcore_mail_move_by_filter_rule(int account_id, int mailbox_id, int m
if (filter_info->action_type != EMAIL_FILTER_MOVE) {
/* Move the mails on server */
- if ((err = emstorage_get_mailbox_by_id(mailbox_id, &dst_mailbox_tbl)) != EMAIL_ERROR_NONE || !dst_mailbox_tbl) {
+ if ((err = emstorage_get_mailbox_by_id(multi_user_name, mailbox_id, &dst_mailbox_tbl)) != EMAIL_ERROR_NONE || !dst_mailbox_tbl) {
EM_DEBUG_EXCEPTION("emstorage_get_mailbox_by_id failed : [%d]", err);
goto FINISH_OFF;
}
for (mail_id_index = 0; mail_id_index < filter_mail_id_count; mail_id_index++) {
- if (!emstorage_get_mail_by_id(filter_mail_id_list[mail_id_index], &mail_tbl, false, &err)) {
+ if (!emstorage_get_mail_by_id(multi_user_name, filter_mail_id_list[mail_id_index], &mail_tbl, false, &err)) {
EM_DEBUG_EXCEPTION("emstorage_get_mail_by_id failed : [%d]", err);
goto FINISH_OFF;
}
- if ((err = emstorage_get_mailbox_by_id(mail_tbl->mailbox_id, &src_mailbox_tbl)) != EMAIL_ERROR_NONE) {
+ if ((err = emstorage_get_mailbox_by_id(multi_user_name, mail_tbl->mailbox_id, &src_mailbox_tbl)) != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("emstorage_get_mailbox_by_id failed : [%d]", err);
goto FINISH_OFF;
}
- if (!emcore_move_mail_on_server(account_id, src_mailbox_tbl->mailbox_id, filter_mail_id_list, filter_mail_id_count, dst_mailbox_tbl->mailbox_name, &err)) {
+ if (!emcore_move_mail_on_server(multi_user_name, account_id, src_mailbox_tbl->mailbox_id, filter_mail_id_list, filter_mail_id_count, dst_mailbox_tbl->mailbox_name, &err)) {
EM_DEBUG_EXCEPTION("emcore_move_mail_on_server failed : [%d]", err);
goto FINISH_OFF;
}
#ifdef __FEATURE_WIFI_AUTO_DOWNLOAD__
- if (!emstorage_update_auto_download_activity(mail_tbl->server_mail_id, g_new_server_uid, NULL, dst_mailbox_tbl->mailbox_id, &err))
+ if (!emstorage_update_auto_download_activity(multi_user_name, mail_tbl->server_mail_id, g_new_server_uid, NULL, dst_mailbox_tbl->mailbox_id, &err))
EM_DEBUG_EXCEPTION("emstorage_update_auto_download_activity failed : [%d]", err);
#endif
@@ -7551,7 +6839,7 @@ FINISH_OFF:
}
-INTERNAL_FUNC int emcore_mail_filter_by_rule(email_rule_t *filter_info, int *err_code)
+INTERNAL_FUNC int emcore_mail_filter_by_rule(char *multi_user_name, email_rule_t *filter_info, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("filter_info[%p], err_code[%p]", filter_info, err_code);
@@ -7571,13 +6859,13 @@ INTERNAL_FUNC int emcore_mail_filter_by_rule(email_rule_t *filter_info, int *err
if (filter_info->type != EMAIL_PRIORITY_SENDER)
break;
- if ((err = emcore_mail_move_by_filter_rule(filter_info->account_id, 0, 0, (emstorage_rule_tbl_t *)filter_info)) != EMAIL_ERROR_NONE) {
+ if ((err = emcore_mail_move_by_filter_rule(multi_user_name, filter_info->account_id, 0, 0, (emstorage_rule_tbl_t *)filter_info)) != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("emcore_mail_move_by_filter_rule failed : [%d]", err);
goto FINISH_OFF;
}
break;
case EMAIL_FILTER_BLOCK :
- if (!emstorage_get_account_list(&account_count, &account_tbl_t_list, false, false, &err)) {
+ if (!emstorage_get_account_list(multi_user_name, &account_count, &account_tbl_t_list, false, false, &err)) {
EM_DEBUG_EXCEPTION("emstorage_get_account_list failed [%d]", err);
goto FINISH_OFF;
}
@@ -7585,12 +6873,12 @@ INTERNAL_FUNC int emcore_mail_filter_by_rule(email_rule_t *filter_info, int *err
for (account_index = 0; account_index < account_count; account_index++) {
account_tbl_t = account_tbl_t_list + account_index;
- if (!emstorage_get_mailbox_by_mailbox_type(account_tbl_t->account_id, EMAIL_MAILBOX_TYPE_SPAMBOX, &spam_mailbox, false, &err)) {
+ if (!emstorage_get_mailbox_by_mailbox_type(multi_user_name, account_tbl_t->account_id, EMAIL_MAILBOX_TYPE_SPAMBOX, &spam_mailbox, false, &err)) {
EM_DEBUG_EXCEPTION("emstorage_get_mailbox_by_mailbox_type for account_id[%d] failed : [%d]", account_tbl_t->account_id, err);
continue;
}
- if ((err = emcore_mail_move_by_filter_rule(account_tbl_t->account_id, spam_mailbox->mailbox_id, spam_mailbox->mailbox_type, (emstorage_rule_tbl_t *)filter_info)) != EMAIL_ERROR_NONE) {
+ if ((err = emcore_mail_move_by_filter_rule(multi_user_name, account_tbl_t->account_id, spam_mailbox->mailbox_id, spam_mailbox->mailbox_type, (emstorage_rule_tbl_t *)filter_info)) != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("emcore_mail_move_by_filter_rule failed : [%d]", err);
goto FINISH_OFF;
}
@@ -7604,7 +6892,7 @@ INTERNAL_FUNC int emcore_mail_filter_by_rule(email_rule_t *filter_info, int *err
break;
}
- emcore_display_unread_in_badge(NULL);
+ emcore_display_unread_in_badge(multi_user_name);
ret = true;
@@ -7622,12 +6910,12 @@ FINISH_OFF:
return ret;
}
-INTERNAL_FUNC int emcore_add_rule(email_rule_t *filter_info)
+INTERNAL_FUNC int emcore_add_rule(char *multi_user_name, email_rule_t *filter_info)
{
EM_DEBUG_FUNC_BEGIN();
int err = EMAIL_ERROR_NONE;
- if (!emstorage_find_rule((emstorage_rule_tbl_t*)filter_info, true, &err)) {
+ if (!emstorage_find_rule(multi_user_name, (emstorage_rule_tbl_t*)filter_info, true, &err)) {
EM_DEBUG_EXCEPTION("emstorage_find_rule failed [%d]", err);
goto FINISH_OFF;
} else {
@@ -7655,7 +6943,7 @@ INTERNAL_FUNC int emcore_add_rule(email_rule_t *filter_info)
break;
}
- if (!emstorage_add_rule((emstorage_rule_tbl_t*)filter_info, true, &err)) {
+ if (!emstorage_add_rule(multi_user_name, (emstorage_rule_tbl_t*)filter_info, true, &err)) {
EM_DEBUG_EXCEPTION("emstorage_add_rule failed [%d]", err);
goto FINISH_OFF;
}
@@ -7671,7 +6959,7 @@ FINISH_OFF:
return err;
}
-INTERNAL_FUNC int emcore_update_rule(int filter_id, email_rule_t *filter_info)
+INTERNAL_FUNC int emcore_update_rule(char *multi_user_name, int filter_id, email_rule_t *filter_info)
{
EM_DEBUG_FUNC_BEGIN();
@@ -7691,12 +6979,12 @@ INTERNAL_FUNC int emcore_update_rule(int filter_id, email_rule_t *filter_info)
return err;
}
- if (!emstorage_get_rule_by_id(filter_id, &old_filter_info, false, &err)) {
+ if (!emstorage_get_rule_by_id(multi_user_name, filter_id, &old_filter_info, false, &err)) {
EM_DEBUG_EXCEPTION("emstorage_get_rule_by_id failed : [%d]", err);
goto FINISH_OFF;
}
- if (!emstorage_filter_mails_by_rule(old_filter_info->account_id, old_filter_info->target_mailbox_id, false, true, old_filter_info, &filter_mail_id_list, &filter_mail_id_count, &err)) {
+ if (!emstorage_filter_mails_by_rule(multi_user_name, old_filter_info->account_id, old_filter_info->target_mailbox_id, false, true, old_filter_info, &filter_mail_id_list, &filter_mail_id_count, &err)) {
EM_DEBUG_EXCEPTION("emstorage_filter_mails_by_rule failed : [%d]", err);
goto FINISH_OFF;
}
@@ -7723,7 +7011,7 @@ INTERNAL_FUNC int emcore_update_rule(int filter_id, email_rule_t *filter_info)
EM_DEBUG_LOG("param string [%s]", parameter_string);
}
- if (!emstorage_change_rule(filter_id, (emstorage_rule_tbl_t *)filter_info, true, &err)) {
+ if (!emstorage_change_rule(multi_user_name, filter_id, (emstorage_rule_tbl_t *)filter_info, true, &err)) {
EM_DEBUG_EXCEPTION("emstorage_change_rule failed [%d]", err);
goto FINISH_OFF;
}
@@ -7743,7 +7031,7 @@ FINISH_OFF:
return err;
}
-INTERNAL_FUNC int emcore_delete_rule(int filter_id)
+INTERNAL_FUNC int emcore_delete_rule(char *multi_user_name, int filter_id)
{
EM_DEBUG_FUNC_BEGIN();
int err = EMAIL_ERROR_NONE;
@@ -7762,12 +7050,12 @@ INTERNAL_FUNC int emcore_delete_rule(int filter_id)
goto FINISH_OFF;
}
- if (!emstorage_get_rule_by_id(filter_id, &filter_info, false, &err)) {
+ if (!emstorage_get_rule_by_id(multi_user_name, filter_id, &filter_info, false, &err)) {
EM_DEBUG_EXCEPTION("emstorage_get_rule_by_id failed : [%d]", err);
goto FINISH_OFF;
}
- if (!emstorage_filter_mails_by_rule(filter_info->account_id, filter_info->target_mailbox_id, false, true, filter_info, &filter_mail_id_list, &filter_mail_id_count, &err)) {
+ if (!emstorage_filter_mails_by_rule(multi_user_name, filter_info->account_id, filter_info->target_mailbox_id, false, true, filter_info, &filter_mail_id_list, &filter_mail_id_count, &err)) {
EM_DEBUG_EXCEPTION("emstorage_filter_mails_by_rule failed : [%d]", err);
goto FINISH_OFF;
}
@@ -7794,7 +7082,7 @@ INTERNAL_FUNC int emcore_delete_rule(int filter_id)
EM_DEBUG_LOG("param string [%s]", parameter_string);
}
- if (!emstorage_delete_rule(filter_id, true, &err)) {
+ if (!emstorage_delete_rule(multi_user_name, filter_id, true, &err)) {
EM_DEBUG_EXCEPTION(" emstorage_delete_rule failed [%d]", err);
goto FINISH_OFF;
}
@@ -7824,6 +7112,7 @@ INTERNAL_FUNC void emcore_free_content_info(struct _m_content_info *cnt_info)
EM_SAFE_FREE(cnt_info->text.plain_charset);
EM_SAFE_FREE(cnt_info->text.html);
EM_SAFE_FREE(cnt_info->text.html_charset);
+ EM_SAFE_FREE(cnt_info->text.mime_entity);
EM_SAFE_FREE(cnt_info->sections);
while (cnt_info->file) {
@@ -7868,3 +7157,558 @@ INTERNAL_FUNC void emcore_free_attachment_info(struct attachment_info *attchment
EM_DEBUG_FUNC_END();
}
+
+static int get_search_filter_string(email_search_filter_t *search_filter, int search_filter_count, char **output_filter_string)
+{
+ EM_DEBUG_FUNC_BEGIN("search_filter : [%p], search_filter_count : [%d]", search_filter, search_filter_count);
+
+ int i = 0, j = 0;
+ int err = EMAIL_ERROR_NONE;
+ char time_string[20];
+ char filter_string[MAX_PREVIEW_TEXT_LENGTH] = { 0, };
+ char temp_criteria[MAX_PREVIEW_TEXT_LENGTH] = { 0, };
+
+ if (search_filter == NULL || search_filter_count < 0 || output_filter_string == NULL) {
+ EM_DEBUG_EXCEPTION("Invalid paramter");
+ err = EMAIL_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ for (i = 0; i < search_filter_count; i++) {
+ EM_DEBUG_LOG("search_filter_type [%d]", search_filter[i].search_filter_type);
+ memset(temp_criteria, 0x00, MAX_PREVIEW_TEXT_LENGTH);
+
+ switch (search_filter[i].search_filter_type) {
+ case EMAIL_SEARCH_FILTER_TYPE_ALL:
+ EM_DEBUG_LOG("integer_type_key_value [%d]", search_filter[i].search_filter_key_value.integer_type_key_value);
+ if (search_filter[i].search_filter_key_value.integer_type_key_value == 0) {
+ for (j = i + 1; j < search_filter_count; j++) {
+ if (search_filter[j + 1].search_filter_type == EMAIL_SEARCH_FILTER_TYPE_ALL &&
+ search_filter[j + 1].search_filter_key_value.integer_type_key_value) {
+ break;
+ }
+
+ SNPRINTF(temp_criteria, STRING_LENGTH_FOR_DISPLAY, "OR ");
+ strncat(filter_string, temp_criteria, STRING_LENGTH_FOR_DISPLAY);
+ }
+ }
+ break;
+
+ case EMAIL_SEARCH_FILTER_TYPE_FLAGS_ANSWERED :
+ EM_DEBUG_LOG("integer_type_key_value [%d]", search_filter[i].search_filter_key_value.integer_type_key_value);
+ if (search_filter[i].search_filter_key_value.integer_type_key_value)
+ SNPRINTF(temp_criteria, STRING_LENGTH_FOR_DISPLAY, "ANSWERED ");
+ else
+ SNPRINTF(temp_criteria, STRING_LENGTH_FOR_DISPLAY, "UNANSWERED ");
+ strncat(filter_string, temp_criteria, STRING_LENGTH_FOR_DISPLAY);
+ break;
+
+ case EMAIL_SEARCH_FILTER_TYPE_BCC :
+ EM_DEBUG_LOG_SEC("string_type_key_value [%s]", search_filter[i].search_filter_key_value.string_type_key_value);
+ SNPRINTF(temp_criteria, STRING_LENGTH_FOR_DISPLAY, "BCC \"%s\" ",
+ search_filter[i].search_filter_key_value.string_type_key_value);
+ strncat(filter_string, temp_criteria, STRING_LENGTH_FOR_DISPLAY);
+ break;
+
+ case EMAIL_SEARCH_FILTER_TYPE_SENT_DATE_BEFORE :
+ EM_DEBUG_LOG("time_type_key_value [%d]", search_filter[i].search_filter_key_value.time_type_key_value);
+ emcore_make_date_string_for_search(search_filter[i].search_filter_key_value.time_type_key_value, time_string);
+ SNPRINTF(temp_criteria, STRING_LENGTH_FOR_DISPLAY, "BEFORE %s ", time_string);
+ strncat(filter_string, temp_criteria, STRING_LENGTH_FOR_DISPLAY);
+ break;
+
+ case EMAIL_SEARCH_FILTER_TYPE_BODY :
+ EM_DEBUG_LOG_SEC("string_type_key_value [%s]", search_filter[i].search_filter_key_value.string_type_key_value);
+ SNPRINTF(temp_criteria, STRING_LENGTH_FOR_DISPLAY, "BODY \"%s\" ",
+ search_filter[i].search_filter_key_value.string_type_key_value);
+ strncat(filter_string, temp_criteria, STRING_LENGTH_FOR_DISPLAY);
+ break;
+
+ case EMAIL_SEARCH_FILTER_TYPE_CC :
+ EM_DEBUG_LOG_SEC("string_type_key_value [%s]", search_filter[i].search_filter_key_value.string_type_key_value);
+ SNPRINTF(temp_criteria, STRING_LENGTH_FOR_DISPLAY, "CC \"%s\" ",
+ search_filter[i].search_filter_key_value.string_type_key_value);
+ strncat(filter_string, temp_criteria, STRING_LENGTH_FOR_DISPLAY);
+ break;
+
+ case EMAIL_SEARCH_FILTER_TYPE_FLAGS_DELETED :
+ EM_DEBUG_LOG("integer_type_key_value [%d]", search_filter[i].search_filter_key_value.integer_type_key_value);
+ if (search_filter[i].search_filter_key_value.integer_type_key_value)
+ SNPRINTF(temp_criteria, STRING_LENGTH_FOR_DISPLAY, "DELETED ");
+ else
+ SNPRINTF(temp_criteria, STRING_LENGTH_FOR_DISPLAY, "UNDELETED ");
+
+ strncat(filter_string, temp_criteria, STRING_LENGTH_FOR_DISPLAY);
+ break;
+
+ case EMAIL_SEARCH_FILTER_TYPE_FLAGS_FLAGED :
+ EM_DEBUG_LOG("integer_type_key_value [%d]", search_filter[i].search_filter_key_value.integer_type_key_value);
+ if (search_filter[i].search_filter_key_value.integer_type_key_value)
+ SNPRINTF(temp_criteria, STRING_LENGTH_FOR_DISPLAY, "FLAGGED ");
+ else
+ SNPRINTF(temp_criteria, STRING_LENGTH_FOR_DISPLAY, "UNFLAGGED ");
+
+ strncat(filter_string, temp_criteria, STRING_LENGTH_FOR_DISPLAY);
+ break;
+
+ case EMAIL_SEARCH_FILTER_TYPE_FROM :
+ EM_DEBUG_LOG_SEC("string_type_key_value [%s]", search_filter[i].search_filter_key_value.string_type_key_value);
+ SNPRINTF(temp_criteria, STRING_LENGTH_FOR_DISPLAY, "FROM \"%s\" ",
+ search_filter[i].search_filter_key_value.string_type_key_value);
+ strncat(filter_string, temp_criteria, STRING_LENGTH_FOR_DISPLAY);
+ break;
+
+ case EMAIL_SEARCH_FILTER_TYPE_KEYWORD :
+ EM_DEBUG_LOG_SEC("string_type_key_value [%s]", search_filter[i].search_filter_key_value.string_type_key_value);
+ SNPRINTF(temp_criteria, STRING_LENGTH_FOR_DISPLAY, "KEYWORD \"%s\" ",
+ search_filter[i].search_filter_key_value.string_type_key_value);
+
+ strncat(filter_string, temp_criteria, STRING_LENGTH_FOR_DISPLAY);
+ break;
+
+ case EMAIL_SEARCH_FILTER_TYPE_FLAGS_NEW:
+ EM_DEBUG_LOG("integer_type_key_value [%d]", search_filter[i].search_filter_key_value.integer_type_key_value);
+ if (search_filter[i].search_filter_key_value.integer_type_key_value)
+ SNPRINTF(temp_criteria, STRING_LENGTH_FOR_DISPLAY, "NEW ");
+
+ strncat(filter_string, temp_criteria, STRING_LENGTH_FOR_DISPLAY);
+ break;
+
+ case EMAIL_SEARCH_FILTER_TYPE_FLAGS_OLD:
+ EM_DEBUG_LOG("integer_type_key_value [%d]", search_filter[i].search_filter_key_value.integer_type_key_value);
+ if (search_filter[i].search_filter_key_value.integer_type_key_value)
+ SNPRINTF(temp_criteria, STRING_LENGTH_FOR_DISPLAY, "OLD ");
+
+ strncat(filter_string, temp_criteria, STRING_LENGTH_FOR_DISPLAY);
+ break;
+
+ case EMAIL_SEARCH_FILTER_TYPE_SENT_DATE_ON :
+ EM_DEBUG_LOG("time_type_key_value [%d]", search_filter[i].search_filter_key_value.time_type_key_value);
+ emcore_make_date_string_for_search(search_filter[i].search_filter_key_value.time_type_key_value, time_string);
+ SNPRINTF(temp_criteria, STRING_LENGTH_FOR_DISPLAY, "ON %s ", time_string);
+ strncat(filter_string, temp_criteria, STRING_LENGTH_FOR_DISPLAY);
+ break;
+
+ case EMAIL_SEARCH_FILTER_TYPE_FLAGS_RECENT :
+ EM_DEBUG_LOG("integer_type_key_value [%d]", search_filter[i].search_filter_key_value.integer_type_key_value);
+ if (search_filter[i].search_filter_key_value.integer_type_key_value)
+ SNPRINTF(temp_criteria, STRING_LENGTH_FOR_DISPLAY, "RECENT ");
+ strncat(filter_string, temp_criteria, STRING_LENGTH_FOR_DISPLAY);
+ break;
+
+ case EMAIL_SEARCH_FILTER_TYPE_FLAGS_SEEN :
+ EM_DEBUG_LOG("integer_type_key_value [%d]", search_filter[i].search_filter_key_value.integer_type_key_value);
+ if (search_filter[i].search_filter_key_value.integer_type_key_value)
+ SNPRINTF(temp_criteria, STRING_LENGTH_FOR_DISPLAY, "SEEN ");
+ else
+ SNPRINTF(temp_criteria, STRING_LENGTH_FOR_DISPLAY, "UNSEEN ");
+
+ strncat(filter_string, temp_criteria, STRING_LENGTH_FOR_DISPLAY);
+ break;
+
+ case EMAIL_SEARCH_FILTER_TYPE_SENT_DATE_SINCE :
+ EM_DEBUG_LOG("time_type_key_value [%d]", search_filter[i].search_filter_key_value.time_type_key_value);
+ emcore_make_date_string_for_search(search_filter[i].search_filter_key_value.time_type_key_value, time_string);
+ SNPRINTF(temp_criteria, STRING_LENGTH_FOR_DISPLAY, "SINCE %s ", time_string);
+ strncat(filter_string, temp_criteria, STRING_LENGTH_FOR_DISPLAY);
+ break;
+
+ case EMAIL_SEARCH_FILTER_TYPE_SUBJECT :
+ EM_DEBUG_LOG_SEC("string_type_key_value [%s]", search_filter[i].search_filter_key_value.string_type_key_value);
+ SNPRINTF(temp_criteria, STRING_LENGTH_FOR_DISPLAY, "SUBJECT \"%s\" ",
+ search_filter[i].search_filter_key_value.string_type_key_value);
+ strncat(filter_string, temp_criteria, STRING_LENGTH_FOR_DISPLAY);
+ break;
+
+ case EMAIL_SEARCH_FILTER_TYPE_TEXT :
+ EM_DEBUG_LOG_SEC("string_type_key_value [%s]", search_filter[i].search_filter_key_value.string_type_key_value);
+ SNPRINTF(temp_criteria, STRING_LENGTH_FOR_DISPLAY, "TEXT \"%s\" ",
+ search_filter[i].search_filter_key_value.string_type_key_value);
+ strncat(filter_string, temp_criteria, STRING_LENGTH_FOR_DISPLAY);
+ break;
+
+ case EMAIL_SEARCH_FILTER_TYPE_TO :
+ EM_DEBUG_LOG_SEC("string_type_key_value [%s]", search_filter[i].search_filter_key_value.string_type_key_value);
+ SNPRINTF(temp_criteria, STRING_LENGTH_FOR_DISPLAY, "TO \"%s\" ",
+ search_filter[i].search_filter_key_value.string_type_key_value);
+ strncat(filter_string, temp_criteria, STRING_LENGTH_FOR_DISPLAY);
+ break;
+
+ case EMAIL_SEARCH_FILTER_TYPE_HEADER_PRIORITY :
+ EM_DEBUG_LOG("integer_type_key_value [%d]", search_filter[i].search_filter_key_value.integer_type_key_value);
+ SNPRINTF(temp_criteria, STRING_LENGTH_FOR_DISPLAY, "HEADER x-priority %d ", search_filter[i].search_filter_key_value.integer_type_key_value);
+ strncat(filter_string, temp_criteria, STRING_LENGTH_FOR_DISPLAY);
+ break;
+
+ case EMAIL_SEARCH_FILTER_TYPE_SIZE_LARSER :
+ EM_DEBUG_LOG("integer_type_key_value [%d]", search_filter[i].search_filter_key_value.integer_type_key_value);
+ break;
+
+ case EMAIL_SEARCH_FILTER_TYPE_SIZE_SMALLER :
+ EM_DEBUG_LOG("integer_type_key_value [%d]", search_filter[i].search_filter_key_value.integer_type_key_value);
+ break;
+
+ case EMAIL_SEARCH_FILTER_TYPE_FLAGS_DRAFT :
+ EM_DEBUG_LOG("integer_type_key_value [%d]", search_filter[i].search_filter_key_value.integer_type_key_value);
+ break;
+
+ case EMAIL_SEARCH_FILTER_TYPE_ATTACHMENT_NAME :
+ EM_DEBUG_LOG_SEC("string_type_key_value [%s]", search_filter[i].search_filter_key_value.string_type_key_value);
+ SNPRINTF(temp_criteria, STRING_LENGTH_FOR_DISPLAY, "X-GM-RAW \"has:attachment filename:%s\"",
+ search_filter[i].search_filter_key_value.string_type_key_value);
+ strncat(filter_string, temp_criteria, STRING_LENGTH_FOR_DISPLAY);
+ break;
+
+ case EMAIL_SEARCH_FILTER_TYPE_CHARSET:
+ EM_DEBUG_LOG("string_type_key_value [%s]", search_filter[i].search_filter_key_value.string_type_key_value);
+ SNPRINTF(temp_criteria, STRING_LENGTH_FOR_DISPLAY, "charset %s", search_filter[i].search_filter_key_value.string_type_key_value);
+ strncat(filter_string, temp_criteria, STRING_LENGTH_FOR_DISPLAY);
+ break;
+
+
+ case EMAIL_SEARCH_FILTER_TYPE_USER_DEFINED:
+ EM_DEBUG_LOG("string_type_key_value [%s]", search_filter[i].search_filter_key_value.string_type_key_value);
+ SNPRINTF(temp_criteria, STRING_LENGTH_FOR_DISPLAY, "%s", search_filter[i].search_filter_key_value.string_type_key_value);
+ strncat(filter_string, temp_criteria, STRING_LENGTH_FOR_DISPLAY);
+ break;
+
+ case EMAIL_SEARCH_FILTER_TYPE_MESSAGE_NO :
+ case EMAIL_SEARCH_FILTER_TYPE_UID :
+ EM_DEBUG_LOG("integer_type_key_value [%d]", search_filter[i].search_filter_key_value.integer_type_key_value);
+ break;
+
+ case EMAIL_SEARCH_FILTER_TYPE_MESSAGE_ID :
+ EM_DEBUG_LOG("string_type_key_value [%s]", search_filter[i].search_filter_key_value.string_type_key_value);
+ break;
+
+ default :
+ EM_DEBUG_EXCEPTION("Invalid list_filter_item_type [%d]", search_filter);
+ err = EMAIL_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+ }
+
+ em_trim_right(filter_string);
+
+ EM_DEBUG_LOG_SEC("filter_string[%s]", filter_string);
+
+FINISH_OFF:
+
+ if(output_filter_string)
+ *output_filter_string = EM_SAFE_STRDUP(filter_string);
+
+ EM_DEBUG_FUNC_END();
+ return err;
+}
+
+int emcore_search_mail_and_uids(MAILSTREAM *stream, email_search_filter_t *input_search_filter,
+ int input_search_filter_count, emcore_uid_list** output_uid_list,
+ int *output_uid_count)
+{
+ EM_DEBUG_FUNC_BEGIN("stream[%p] input_search_filter[%p] input_search_filter_count[%d] "
+ "output_uid_list[%p] output_uid_count[%p]",
+ stream, input_search_filter_count, output_uid_list, output_uid_count);
+
+ int err = EMAIL_ERROR_NONE;
+
+ IMAPLOCAL *imaplocal = NULL;
+ char tag[16], command[MAX_PREVIEW_TEXT_LENGTH];
+ char *response = NULL;
+ emcore_uid_list *uid_elem = NULL;
+ char delims[] = " ";
+ char *result = NULL;
+ int uid_count = 0;
+ char *search_filter_string = NULL;
+ char *uid_range_string = NULL;
+ emcore_uid_list *uid_list_for_listing = NULL;
+
+ if (stream == NULL || output_uid_list == NULL || input_search_filter == NULL || output_uid_count == NULL) {
+ EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
+ err = EMAIL_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ if (!(imaplocal = stream->local) || !imaplocal->netstream) {
+ EM_DEBUG_EXCEPTION(" invalid IMAP4 stream detected...");
+ err = EMAIL_ERROR_INVALID_PARAM; /* EMAIL_ERROR_UNKNOWN */
+ goto FINISH_OFF;
+ }
+
+ memset(tag, 0x00, sizeof(tag));
+ memset(command, 0x00, sizeof(command));
+
+ if ((err = get_search_filter_string(input_search_filter,
+ input_search_filter_count,
+ &search_filter_string)) != EMAIL_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("get_search_filter_string failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ SNPRINTF(tag, sizeof(tag), "%08lx", 0xffffffff & (stream->gensym++));
+ SNPRINTF(command, MAX_PREVIEW_TEXT_LENGTH, "%s UID SEARCH %s\015\012", tag, search_filter_string);
+ EM_DEBUG_LOG_SEC("COMMAND [%s] ", command);
+
+#ifdef FEATURE_CORE_DEBUG
+ EM_DEBUG_LOG_SEC(" [IMAP4] >>> [%s]", command);
+#endif
+
+ /* send command : get msgno/uid for all message */
+ if (!net_sout(imaplocal->netstream, command, (int)EM_SAFE_STRLEN(command))) {
+ EM_DEBUG_EXCEPTION(" net_sout failed...");
+ err = EMAIL_ERROR_CONNECTION_BROKEN;
+ goto FINISH_OFF;
+ }
+
+ while (imaplocal->netstream) {
+ char *p = NULL;
+ /* receive response */
+ if (!(response = net_getline(imaplocal->netstream))) {
+ EM_DEBUG_EXCEPTION(" net_getline failed...");
+ err = EMAIL_ERROR_INVALID_RESPONSE;
+ goto FINISH_OFF;
+ }
+#ifdef FEATURE_CORE_DEBUG
+ EM_DEBUG_LOG(" [IMAP4] <<< [%s]", response);
+#endif
+
+ if (!strncmp(response, tag, EM_SAFE_STRLEN(tag))) {
+ if (!strncmp(response + EM_SAFE_STRLEN(tag) + 1, "OK", 2)) {
+ EM_SAFE_FREE (response);
+ break;
+ }
+ else { /* 'NO' or 'BAD' */
+ err = EMAIL_ERROR_IMAP4_FETCH_UID_FAILURE; /* EMAIL_ERROR_INVALID_RESPONSE; */
+ goto FINISH_OFF;
+ }
+ }
+
+ if ((p = strstr(response, " SEARCH "))){
+ *p = '\0'; p += strlen(" SEARCH ");
+
+ result = strtok(p, delims);
+
+ while (result != NULL)
+ {
+ EM_DEBUG_LOG("UID VALUE DEEP is [%s]", result);
+
+ if (!(uid_elem = em_malloc(sizeof(emcore_uid_list)))) {
+ EM_DEBUG_EXCEPTION(" malloc failed...");
+ err = EMAIL_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ uid_elem->uid = EM_SAFE_STRDUP(result);
+
+ if (uid_list_for_listing != NULL)
+ uid_elem->next = uid_list_for_listing;
+ uid_list_for_listing = uid_elem;
+ result = strtok(NULL, delims);
+ uid_count++;
+ }
+
+ EM_SAFE_FREE(response);
+ continue;
+ }
+ else if ((p = strstr(response, " SEARCH"))){
+ /* there is no mail */
+ continue;
+ }
+ else {
+ err = EMAIL_ERROR_INVALID_RESPONSE;
+ goto FINISH_OFF;
+ }
+ }
+
+ EM_DEBUG_LOG("uid_count [%d] ", uid_count);
+ if (uid_count > 0) {
+ if ((err = emcore_make_uid_range_string(uid_list_for_listing,
+ uid_count,
+ &uid_range_string)) != EMAIL_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("emcore_make_uid_range_string failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ EM_DEBUG_LOG("uid_range_string [%s] ", uid_range_string);
+
+ /* Get uids with flags */
+ if(!imap4_mailbox_get_uids(stream, uid_range_string, output_uid_list, &err)) {
+ EM_DEBUG_EXCEPTION("imap4_mailbox_get_uids failed [%d]", err);
+ goto FINISH_OFF;
+ }
+ }
+
+FINISH_OFF:
+
+ if (output_uid_count)
+ *output_uid_count = uid_count;
+
+ if (uid_list_for_listing)
+ emcore_free_uids(uid_list_for_listing, NULL);
+
+ EM_SAFE_FREE (response);
+ EM_SAFE_FREE (uid_range_string);
+ EM_SAFE_FREE (search_filter_string);
+
+ EM_DEBUG_FUNC_END("err [%d]", err);
+ return err;
+}
+
+
+INTERNAL_FUNC int emcore_search_on_server(char *multi_user_name, int account_id, int mailbox_id,
+ email_search_filter_t *input_search_filter,
+ int input_search_filter_count,
+ int cancellable,
+ int event_handle)
+{
+ EM_DEBUG_FUNC_BEGIN_SEC("account_id : [%d], mailbox_id : [%d]", account_id, mailbox_id);
+
+ int err = EMAIL_ERROR_NONE;
+ int i = 0;
+ int mail_id = 0;
+ int thread_id = 0;
+ int uid_count = 0;
+ char *uid_range = NULL;
+ char mailbox_id_param_string[10] = {0,};
+ emcore_uid_list *uid_list = NULL;
+ emcore_uid_list *uid_elem = NULL;
+ emstorage_mailbox_tbl_t *search_mailbox = NULL;
+ emstorage_mail_tbl_t *new_mail_tbl_data = NULL;
+
+ MAILSTREAM *stream = NULL;
+ ENVELOPE *env = NULL;
+
+ if (account_id < 0 || mailbox_id == 0) {
+ EM_DEBUG_EXCEPTION("Invalid parameter");
+ err = EMAIL_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ if (cancellable)
+ FINISH_OFF_IF_EVENT_CANCELED(err, event_handle);
+
+ if (!emcore_connect_to_remote_mailbox(multi_user_name, account_id, mailbox_id, (void **)&stream, &err)) {
+ EM_DEBUG_EXCEPTION("emcore_connect_to_remote_mailbox failed");
+ goto FINISH_OFF;
+ }
+
+ if (cancellable)
+ FINISH_OFF_IF_EVENT_CANCELED(err, event_handle);
+
+ if ((err = emcore_search_mail_and_uids(stream,
+ input_search_filter,
+ input_search_filter_count,
+ &uid_list,
+ &uid_count)) != EMAIL_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("emcore_search_mail_and_uids failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ if (cancellable)
+ FINISH_OFF_IF_EVENT_CANCELED(err, event_handle);
+
+ uid_elem = uid_list;
+
+ if (uid_count > 0) {
+ if ((err = emcore_make_uid_range_string(uid_list, uid_count, &uid_range)) != EMAIL_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("emcore_make_uid_range_string failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ EM_DEBUG_LOG("Calling ... mail_fetch_fast. uid_range [%s]", uid_range);
+ mail_fetch_fast(stream, uid_range, FT_UID | FT_PEEK | FT_NEEDENV);
+ EM_SAFE_FREE(uid_range);
+
+ EM_DEBUG_LOG("stream->nmsgs : [%d]", stream->nmsgs);
+ }
+
+ while (uid_elem) {
+ if (cancellable)
+ FINISH_OFF_IF_EVENT_CANCELED(err, event_handle);
+
+ EM_DEBUG_LOG("msgno : [%4lu]", uid_elem->msgno);
+#ifdef __FEATURE_HEADER_OPTIMIZATION__
+ env = mail_fetchstructure_full(stream, uid_elem->msgno, NULL, FT_PEEK, 0);
+#else
+ env = mail_fetchstructure_full(stream, uid_elem->msgno, NULL, FT_PEEK);
+#endif
+ EM_DEBUG_LOG("env[%p]", env);
+ if (env)
+ EM_DEBUG_LOG("message_id[%s]", env->message_id);
+
+ if (!emcore_make_mail_tbl_data_from_envelope(multi_user_name,
+ account_id,
+ stream,
+ env,
+ uid_elem,
+ &new_mail_tbl_data,
+ &err) || !new_mail_tbl_data) {
+ EM_DEBUG_EXCEPTION("emcore_make_mail_tbl_data_from_envelope failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ search_mailbox = em_malloc(sizeof(emstorage_mailbox_tbl_t));
+ if (search_mailbox == NULL) {
+ EM_DEBUG_EXCEPTION("em_malloc failed");
+ err = EMAIL_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ search_mailbox->account_id = account_id;
+ search_mailbox->mailbox_id = mailbox_id;
+ search_mailbox->mailbox_name = EM_SAFE_STRDUP(EMAIL_SEARCH_RESULT_MAILBOX_NAME);
+ search_mailbox->mailbox_type = EMAIL_MAILBOX_TYPE_SEARCH_RESULT;
+
+ if ((err = emcore_add_mail_to_mailbox(multi_user_name,
+ search_mailbox,
+ new_mail_tbl_data,
+ &mail_id,
+ &thread_id)) != EMAIL_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("emcore_add_mail_to_mailbox failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ memset(mailbox_id_param_string, 0, 10);
+ SNPRINTF(mailbox_id_param_string, 10, "%d", search_mailbox->mailbox_id);
+
+ if (!emcore_initiate_pbd(multi_user_name,
+ stream,
+ account_id,
+ mail_id,
+ uid_elem->uid,
+ search_mailbox->mailbox_id,
+ search_mailbox->mailbox_name,
+ &err)) {
+ EM_DEBUG_EXCEPTION("emcore_initiate_pbd failed : [%d]", err);
+ }
+
+ if (!emcore_notify_storage_event(NOTI_MAIL_ADD, account_id, mail_id, mailbox_id_param_string, thread_id)) {
+ EM_DEBUG_EXCEPTION("emcore_notify_storage_event [NOTI_MAIL_ADD] failed");
+ }
+
+ if (new_mail_tbl_data) {
+ emstorage_free_mail(&new_mail_tbl_data, 1, NULL);
+ new_mail_tbl_data = NULL;
+ }
+
+ uid_elem = uid_elem->next;
+ i++;
+ }
+
+FINISH_OFF:
+
+ if (stream)
+ mail_close (stream);
+
+ if (uid_list)
+ emcore_free_uids(uid_list, NULL);
+
+ if (search_mailbox != NULL)
+ emstorage_free_mailbox(&search_mailbox, 1, NULL);
+
+ if (new_mail_tbl_data)
+ emstorage_free_mail(&new_mail_tbl_data, 1, NULL);
+
+ EM_DEBUG_FUNC_END();
+ return err;
+
+}
diff --git a/email-core/email-core-mailbox-sync.c b/email-core/email-core-mailbox-sync.c
index 957a861..23c831e 100755
--- a/email-core/email-core-mailbox-sync.c
+++ b/email-core/email-core-mailbox-sync.c
@@ -47,7 +47,6 @@
#include "email-utilities.h"
#include "email-convert.h"
#include "email-core-mailbox-sync.h"
-#include "email-core-global.h"
#include "email-core-imap-mailbox.h"
#include "email-core-event.h"
#include "email-core-mailbox.h"
@@ -72,7 +71,6 @@ extern void imap_parse_body_structure (MAILSTREAM *stream, BODY *body, unsigned
#ifdef __FEATURE_PARTIAL_BODY_DOWNLOAD__
static void emcore_free_email_partial_buffer(email_partial_buffer **partial_buffer, int item_count);
static email_partial_buffer *emcore_get_response_from_server (NETSTREAM *nstream, char *tag, IMAPPARSEDREPLY **reply, int input_download_size, int item_count);
-static int emcore_initiate_pbd(MAILSTREAM *stream, int account_id, int mail_id, char *uid, int mailbox_id, int *err_code);
#endif
#ifdef __FEATURE_SYNC_CLIENT_TO_SERVER__
@@ -447,6 +445,7 @@ int imap4_mailbox_get_uids(MAILSTREAM *stream, char *input_target_uid_string, em
char *p_date = NULL;
char *s = NULL;
int seen = 0;
+ int answered = 0;
int forwarded = 0;
int draft = 0;
int flagged = 0;
@@ -479,6 +478,7 @@ int imap4_mailbox_get_uids(MAILSTREAM *stream, char *input_target_uid_string, em
seen = strstr(p, "\\Seen") ? 1 : 0;
draft = strstr(p, "\\Draft") ? 1 : 0;
flagged = strstr(p, "\\Flagged") ? 1 : 0;
+ answered = strstr(p, "\\Answered") ? 1 : 0;
forwarded = strstr(p, "$Forwarded") ? 1 : 0;
if ((p = strstr(p, "UID "))) {
@@ -512,8 +512,9 @@ int imap4_mailbox_get_uids(MAILSTREAM *stream, char *input_target_uid_string, em
uid_elem->uid = EM_SAFE_STRDUP(p + strlen("UID "));
uid_elem->flag.seen = seen;
uid_elem->flag.draft = draft;
- uid_elem->flag.forwarded = forwarded;
uid_elem->flag.flagged = flagged;
+ uid_elem->flag.answered = answered;
+ uid_elem->flag.forwarded = forwarded;
uid_elem->internaldate = EM_SAFE_STRDUP(internaldate);
if (*uid_list != NULL)
uid_elem->next = *uid_list; /* prepend new data to list */
@@ -639,7 +640,7 @@ int emcore_get_uids_order_by_datetime_from_imap_server(MAILSTREAM *stream, int c
while (result != NULL)
{
- EM_DEBUG_LOG("UID VALUE DEEP is [%s]", result);
+ EM_DEBUG_LOG_DEV("UID VALUE DEEP is [%s]", result);
if (!(uid_elem = em_malloc(sizeof(emcore_uid_list)))) {
EM_DEBUG_EXCEPTION(" malloc failed...");
@@ -754,6 +755,11 @@ int imap4_mailbox_get_uids_by_timestamp(MAILSTREAM *stream, emcore_uid_list** ui
/* Reading the current timeinfo */
timeinfo = localtime (&week_before_RawTime);
+ if (timeinfo == NULL) {
+ EM_DEBUG_EXCEPTION("localtime failed");
+ err = EMAIL_ERROR_SYSTEM_FAILURE;
+ goto FINISH_OFF;
+ }
EM_DEBUG_LOG(">>>>>Mobile Date a Week before %d %d %d %d %d %d", 1900 + timeinfo->tm_year, timeinfo->tm_mon+1, timeinfo->tm_mday);
@@ -1159,10 +1165,19 @@ static gint emcore_compare_uid_elem(gconstpointer a, gconstpointer b)
return ret;
}
-static int emcore_get_uids_to_download(MAILSTREAM *stream, email_account_t *account, emstorage_mailbox_tbl_t *input_mailbox_tbl, int limit_count, emcore_uid_list** uid_list, int *uids, int retrieve_mode , int *err_code)
+static int emcore_get_uids_to_download(char *multi_user_name,
+ MAILSTREAM *stream,
+ email_account_t *account,
+ emstorage_mailbox_tbl_t *input_mailbox_tbl,
+ int limit_count,
+ emcore_uid_list** uid_list,
+ int *uids,
+ int retrieve_mode,
+ int *err_code)
{
EM_PROFILE_BEGIN(emCoreGetUidsDownload);
- EM_DEBUG_FUNC_BEGIN("account[%p], input_mailbox_tbl[%p], limit_count[%d], uid_list[%p], err_code[%p]", account, input_mailbox_tbl, limit_count, uid_list, err_code);
+ EM_DEBUG_FUNC_BEGIN("account[%p], input_mailbox_tbl[%p], limit_count[%d], uid_list[%p], err_code[%p]",
+ account, input_mailbox_tbl, limit_count, uid_list, err_code);
int ret = false;
int err = EMAIL_ERROR_NONE;
@@ -1196,7 +1211,9 @@ static int emcore_get_uids_to_download(MAILSTREAM *stream, email_account_t *acco
else { /* EMAIL_SERVER_TYPE_IMAP4 */
EM_DEBUG_LOG("nmsgs[%d]", ((MAILSTREAM *)stream)->nmsgs);
if ((limit_count < ((MAILSTREAM *)stream)->nmsgs)) {
- if ((err = emcore_get_uids_order_by_datetime_from_imap_server(stream, limit_count, uid_list)) != EMAIL_ERROR_NONE ) {
+ if ((err = emcore_get_uids_order_by_datetime_from_imap_server(stream,
+ limit_count,
+ uid_list)) != EMAIL_ERROR_NONE ) {
EM_DEBUG_EXCEPTION("emcore_get_uids_order_by_datetime_from_imap_server failed [%d]", err);
if (err != EMAIL_ERROR_MAIL_NOT_FOUND_ON_SERVER)
goto FINISH_OFF;
@@ -1211,9 +1228,14 @@ static int emcore_get_uids_to_download(MAILSTREAM *stream, email_account_t *acco
}
}
- if (!emstorage_get_downloaded_list(input_mailbox_tbl->account_id,
- (account->incoming_server_type == EMAIL_SERVER_TYPE_POP3) ? 0 : input_mailbox_tbl->mailbox_id,
- &downloaded_uids, &downloaded_uid_count, true, &err)) {
+ if (!emstorage_get_downloaded_list(multi_user_name,
+ input_mailbox_tbl->account_id,
+ (account->incoming_server_type == EMAIL_SERVER_TYPE_POP3) ?
+ 0 : input_mailbox_tbl->mailbox_id,
+ &downloaded_uids,
+ &downloaded_uid_count,
+ true,
+ &err)) {
EM_DEBUG_EXCEPTION("emstorage_get_downloaded_list failed [%d]", err);
goto FINISH_OFF;
}
@@ -1222,7 +1244,7 @@ static int emcore_get_uids_to_download(MAILSTREAM *stream, email_account_t *acco
uid_elem = *uid_list;
uid_count = 0;
- if(!uid_elem) { /* If there is no mail in the input_mailbox_tbl, remove all mails in the input_mailbox_tbl */
+ if (!uid_elem) { /* If there is no mail in the input_mailbox_tbl, remove all mails in the input_mailbox_tbl */
for (i = 0; i < downloaded_uid_count; i++) {
downloaded_uids[i].sync_status = EMAIL_SYNC_STATUS_NOT_EXIST_ON_SERVER;
}
@@ -1265,7 +1287,8 @@ static int emcore_get_uids_to_download(MAILSTREAM *stream, email_account_t *acco
while (uid_elem) {
next_uid_elem = uid_elem->next;
- if ((account->retrieval_mode & EMAIL_IMAP4_RETRIEVAL_MODE_NEW) && (uid_elem->flag.seen != 0)) { /* already seen */
+ if ((account->retrieval_mode & EMAIL_IMAP4_RETRIEVAL_MODE_NEW) && (uid_elem->flag.seen != 0)) {
+ /* already seen */
EM_SAFE_FREE (uid_elem->uid);
EM_SAFE_FREE (uid_elem->internaldate);
EM_SAFE_FREE (uid_elem);
@@ -1273,25 +1296,25 @@ static int emcore_get_uids_to_download(MAILSTREAM *stream, email_account_t *acco
else {
int to_be_downloaded = 1;
- if (limit_count > 0 && uid_count >= limit_count){
+ if (limit_count > 0 && uid_count >= limit_count) {
/* EM_DEBUG_LOG("hit the limit[%d] for [%s]", limit_count, uid_elem->uid); */
to_be_downloaded = 0;
- }
- else{
+ } else {
for (i = downloaded_uid_count; i > 0; i--) {
if (downloaded_uids[i - 1].sync_status == EMAIL_SYNC_STATUS_NOT_EXIST_ON_SERVER
&& !EM_SAFE_STRCMP(uid_elem->uid, downloaded_uids[i - 1].server_uid)) {
if (downloaded_uids[i - 1].mailbox_id != input_mailbox_tbl->mailbox_id) {
uid_count--;
- }
- else {
- /* The mail exists on server and local storage, so it should not be downloaded, just check seen flag */
- if(downloaded_uids[i - 1].flags_seen_field != uid_elem->flag.seen ||
+ } else {
+ /* The mail exists on server and local storage,
+ so it should not be downloaded, just check seen flag */
+ if (downloaded_uids[i - 1].flags_seen_field != uid_elem->flag.seen ||
downloaded_uids[i - 1].flags_flagged_field != uid_elem->flag.flagged) {
if(downloaded_uids[i - 1].flags_seen_field != uid_elem->flag.seen) {
downloaded_uids[i - 1].sync_status = EMAIL_SYNC_STATUS_FLAG_CHANGED;
downloaded_uids[i - 1].flags_seen_field = uid_elem->flag.seen;
}
+
if (downloaded_uids[i - 1].flags_flagged_field != uid_elem->flag.flagged) {
downloaded_uids[i - 1].sync_status = EMAIL_SYNC_STATUS_FLAG_CHANGED;
downloaded_uids[i - 1].flags_flagged_field = uid_elem->flag.flagged;
@@ -1299,43 +1322,74 @@ static int emcore_get_uids_to_download(MAILSTREAM *stream, email_account_t *acco
} else {
downloaded_uids[i - 1].sync_status = EMAIL_SYNC_STATUS_EXIST_ON_SERVER;
}
+
+ if (!emstorage_get_mail_by_id(multi_user_name,
+ downloaded_uids[i-1].local_uid,
+ &mail,
+ false,
+ &err)) {
+ EM_DEBUG_EXCEPTION("emstorage_get_mail_by_id failed : [%d]", err);
+ continue;
+ }
+
+ if (mail->flags_answered_field != uid_elem->flag.answered) {
+ if (!emcore_set_flags_field(multi_user_name,
+ downloaded_uids[i-1].account_id,
+ &(downloaded_uids[i-1].local_uid),
+ 1,
+ EMAIL_FLAGS_ANSWERED_FIELD,
+ uid_elem->flag.answered,
+ &err)) {
+ EM_DEBUG_EXCEPTION("emcore_set_flags_field failed : [%d]", err);
+ }
+ }
+
+ if (mail->flags_forwarded_field != uid_elem->flag.forwarded) {
+ if (!emcore_set_flags_field(multi_user_name,
+ downloaded_uids[i-1].account_id,
+ &(downloaded_uids[i-1].local_uid),
+ 1,
+ EMAIL_FLAGS_FORWARDED_FIELD,
+ uid_elem->flag.forwarded,
+ &err)) {
+ EM_DEBUG_EXCEPTION("emcore_set_flags_field failed : [%d]", err);
+ }
+ }
+
+ emstorage_free_mail(&mail, 1, NULL);
+ mail = NULL;
}
+
to_be_downloaded = 0;
break;
}
}
}
- //EM_DEBUG_LOG("Is uid[%s] datetime[%s] going to be downloaded ? [%d]", uid_elem->uid, uid_elem->internaldate, to_be_downloaded);
-
if (to_be_downloaded) {
- if (retrieve_mode == EMAIL_SYNC_OLDEST_MAILS_FIRST){
+ if (retrieve_mode == EMAIL_SYNC_OLDEST_MAILS_FIRST) {
uid_elem->next = head_uid_elem;
head_uid_elem = uid_elem;
- }
- else{ /* if retrieve_mode is EMAIL_SYNC_LATEST_MAILS_FIRST, add uid elem to end so that latest mails are in front of list */
- if (head_uid_elem == NULL){
+ } else {
+ /* if retrieve_mode is EMAIL_SYNC_LATEST_MAILS_FIRST,
+ add uid elem to end so that latest mails are in front of list */
+ if (head_uid_elem == NULL) {
uid_elem->next = head_uid_elem;
head_uid_elem = uid_elem;
end = head_uid_elem;
- }
- else{
+ } else {
end->next = uid_elem;
uid_elem->next = NULL;
end = uid_elem;
}
}
uid_to_be_downloaded_count++;
-
- }
- else {
+ } else {
EM_SAFE_FREE (uid_elem->uid);
EM_SAFE_FREE (uid_elem);
}
-
uid_count++;
}
-
uid_elem = next_uid_elem;
}
@@ -1343,27 +1397,44 @@ static int emcore_get_uids_to_download(MAILSTREAM *stream, email_account_t *acco
EM_PROFILE_BEGIN(emCoreGetUidsDownloadForLoop);
for (i = 0; i < downloaded_uid_count; i++) {
- /* EM_DEBUG_LOG("input_mailbox_tbl[%s] sync_status[%d]", input_mailbox_tbl->name, downloaded_uids[i].sync_status); */
if ((downloaded_uids[i].sync_status == EMAIL_SYNC_STATUS_NOT_EXIST_ON_SERVER) &&
- (EM_SAFE_STRCMP(downloaded_uids[i].mailbox_name, EMAIL_SEARCH_RESULT_MAILBOX_NAME) != 0)) { /* deleted on server */
- if (!emstorage_get_maildata_by_servermailid(input_mailbox_tbl->mailbox_id, downloaded_uids[i].server_uid, &mail, true, &err)){
- EM_DEBUG_EXCEPTION("emstorage_get_maildata_by_servermailid for uid[%s] Failed [%d] \n ", downloaded_uids[i].server_uid, err);
+ (EM_SAFE_STRCMP(downloaded_uids[i].mailbox_name, EMAIL_SEARCH_RESULT_MAILBOX_NAME) != 0)) {
+ /* deleted on server */
+ if (!emstorage_get_maildata_by_servermailid(multi_user_name,
+ downloaded_uids[i].server_uid,
+ input_mailbox_tbl->mailbox_id,
+ &mail,
+ true,
+ &err)){
+ EM_DEBUG_EXCEPTION("emstorage_get_maildata_by_servermailid for uid[%s] Failed [%d] \n ",
+ downloaded_uids[i].server_uid, err);
if (err == EMAIL_ERROR_MAIL_NOT_FOUND){
continue;
}
}
if (account->incoming_server_type == EMAIL_SERVER_TYPE_IMAP4) {
- ret = emcore_delete_mails_from_local_storage(input_mailbox_tbl->account_id, &(mail->mail_id), 1, EMAIL_DELETED_FROM_SERVER, false, &err);
+ ret = emcore_delete_mails_from_local_storage(multi_user_name,
+ input_mailbox_tbl->account_id,
+ &(mail->mail_id),
+ 1,
+ EMAIL_DELETED_FROM_SERVER,
+ false,
+ &err);
/* Update badge count */
- emcore_display_unread_in_badge(NULL);
+ emcore_display_unread_in_badge(multi_user_name);
if (!ret) {
EM_DEBUG_EXCEPTION("emcore_delete_mails_from_local_storage falied - %d", err);
goto FINISH_OFF;
}
}
- if (!emstorage_remove_downloaded_mail(input_mailbox_tbl->account_id, input_mailbox_tbl->mailbox_name, downloaded_uids[i].server_uid, true, &err)) { /* remove uid from uid list */
+ if (!emstorage_remove_downloaded_mail(multi_user_name,
+ input_mailbox_tbl->account_id,
+ input_mailbox_tbl->mailbox_name,
+ downloaded_uids[i].server_uid,
+ true,
+ &err)) { /* remove uid from uid list */
EM_DEBUG_EXCEPTION("emstorage_remove_downloaded_mail failed - %d", err);
/* goto FINISH_OFF; */
}
@@ -1372,19 +1443,30 @@ static int emcore_get_uids_to_download(MAILSTREAM *stream, email_account_t *acco
else if (account->incoming_server_type == EMAIL_SERVER_TYPE_IMAP4) {
/* set seen flag of downloaded mail */
if (downloaded_uids[i].sync_status == EMAIL_SYNC_STATUS_FLAG_CHANGED) {
- if (!emcore_set_flags_field(downloaded_uids[i].account_id, &(downloaded_uids[i].local_uid), 1, EMAIL_FLAGS_FLAGGED_FIELD, downloaded_uids[i].flags_flagged_field, &err)) {
+ if (!emcore_set_flags_field(multi_user_name,
+ downloaded_uids[i].account_id,
+ &(downloaded_uids[i].local_uid),
+ 1,
+ EMAIL_FLAGS_FLAGGED_FIELD,
+ downloaded_uids[i].flags_flagged_field,
+ &err)) {
EM_DEBUG_EXCEPTION("emcore_set_flags_field failed [%d]", err);
}
- if (!emcore_set_flags_field(downloaded_uids[i].account_id, &(downloaded_uids[i].local_uid), 1, EMAIL_FLAGS_SEEN_FIELD, downloaded_uids[i].flags_seen_field, &err)) {
+ if (!emcore_set_flags_field(multi_user_name,
+ downloaded_uids[i].account_id,
+ &(downloaded_uids[i].local_uid),
+ 1,
+ EMAIL_FLAGS_SEEN_FIELD,
+ downloaded_uids[i].flags_seen_field,
+ &err)) {
EM_DEBUG_EXCEPTION("emcore_set_flags_field failed [%d]", err);
}
else
- emcore_display_unread_in_badge(NULL);
+ emcore_display_unread_in_badge(multi_user_name);
}
-
-
}
+
if (mail != NULL)
emstorage_free_mail(&mail, 1, NULL);
mail = NULL;
@@ -1417,7 +1499,14 @@ FINISH_OFF:
}
/* insert received mail UID to read mail uid table */
-static int emcore_add_read_mail_uid(emstorage_mailbox_tbl_t *input_maibox_data, char *server_mailbox_name, int mail_id, char *uid, int rfc822_size, int rule_id, int *err_code)
+static int emcore_add_read_mail_uid(char *multi_user_name,
+ emstorage_mailbox_tbl_t *input_maibox_data,
+ char *server_mailbox_name,
+ int mail_id,
+ char *uid,
+ int rfc822_size,
+ int rule_id,
+ int *err_code)
{
EM_DEBUG_FUNC_BEGIN_SEC("input_maibox_data[%p], server_mailbox_name[%s], uid[%s], rfc822_size[%d], rule_id[%d], err_code[%p]", input_maibox_data, server_mailbox_name, uid, rfc822_size, rule_id, err_code);
@@ -1434,9 +1523,13 @@ static int emcore_add_read_mail_uid(emstorage_mailbox_tbl_t *input_maibox_data,
}
read_mail_uid.account_id = input_maibox_data->account_id;
-
- if (!(input_maibox_data->mailbox_id) || !(server_mailbox_name)){
- if (!emstorage_get_mailbox_by_mailbox_type(input_maibox_data->account_id, EMAIL_MAILBOX_TYPE_INBOX, &mailbox_tbl, false, &err)) {
+ if (!(input_maibox_data->mailbox_id) || !(server_mailbox_name)) {
+ if (!emstorage_get_mailbox_by_mailbox_type(multi_user_name,
+ input_maibox_data->account_id,
+ EMAIL_MAILBOX_TYPE_INBOX,
+ &mailbox_tbl,
+ false,
+ &err)) {
EM_DEBUG_EXCEPTION("emstorage_get_mailbox_by_mailbox_type failed [%d]", err);
goto FINISH_OFF;
}
@@ -1458,9 +1551,8 @@ static int emcore_add_read_mail_uid(emstorage_mailbox_tbl_t *input_maibox_data,
read_mail_uid.server_uid = uid;
read_mail_uid.rfc822_size = rfc822_size;
- if (!emstorage_add_downloaded_mail(&read_mail_uid, false, &err)) {
+ if (!emstorage_add_downloaded_mail(multi_user_name, &read_mail_uid, false, &err)) {
EM_DEBUG_EXCEPTION("emstorage_add_downloaded_mail failed [%d]", err);
-
goto FINISH_OFF;
}
@@ -1478,7 +1570,7 @@ FINISH_OFF:
}
#ifdef __FEATURE_BODY_SEARCH__
-int emcore_add_mail_text(emstorage_mailbox_tbl_t *input_maibox_data, emstorage_mail_tbl_t *input_new_mail_tbl_data, char *stripped_text, int *err_code)
+int emcore_add_mail_text(char *multi_user_name, emstorage_mailbox_tbl_t *input_maibox_data, emstorage_mail_tbl_t *input_new_mail_tbl_data, char *stripped_text, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("input_maibox_data[%p], input_new_mail_tbl_data[%p], err_code[%p]", input_maibox_data, input_new_mail_tbl_data, err_code);
@@ -1502,7 +1594,7 @@ int emcore_add_mail_text(emstorage_mailbox_tbl_t *input_maibox_data, emstorage_m
else
mail_text.body_text = NULL;
- if (!emstorage_add_mail_text(&mail_text, false, &err)) {
+ if (!emstorage_add_mail_text(multi_user_name, &mail_text, false, &err)) {
EM_DEBUG_EXCEPTION("emstorage_add_mail_text failed [%d]", err);
goto FINISH_OFF;
}
@@ -1521,9 +1613,15 @@ FINISH_OFF:
}
#endif
-INTERNAL_FUNC int emcore_add_mail_to_mailbox(emstorage_mailbox_tbl_t *input_maibox_data, emstorage_mail_tbl_t *input_new_mail_tbl_data, int *output_mail_id, int *output_thread_id)
+INTERNAL_FUNC int emcore_add_mail_to_mailbox(char *multi_user_name,
+ emstorage_mailbox_tbl_t *input_maibox_data,
+ emstorage_mail_tbl_t *input_new_mail_tbl_data,
+ int *output_mail_id,
+ int *output_thread_id)
{
- EM_DEBUG_FUNC_BEGIN("input_maibox_data[%p], input_new_mail_tbl_data[%p], uid_elem[%p], output_mail_id[%p], output_thread_id[%p]", mail_stream, input_maibox_data, input_new_mail_tbl_data, output_mail_id, output_thread_id);
+ EM_DEBUG_FUNC_BEGIN("input_maibox_data[%p], input_new_mail_tbl_data[%p], "
+ "uid_elem[%p], output_mail_id[%p], output_thread_id[%p]", mail_stream, input_maibox_data,
+ input_new_mail_tbl_data, output_mail_id, output_thread_id);
int err = EMAIL_ERROR_NONE;
int thread_id = -1;
@@ -1540,48 +1638,79 @@ INTERNAL_FUNC int emcore_add_mail_to_mailbox(emstorage_mailbox_tbl_t *input_maib
input_new_mail_tbl_data->mailbox_id = input_maibox_data->mailbox_id;
input_new_mail_tbl_data->mailbox_type = input_maibox_data->mailbox_type;
- emstorage_begin_transaction(NULL, NULL, NULL);
+ emstorage_begin_transaction(multi_user_name, NULL, NULL, NULL);
/* Get the Mail_id */
- if (!emstorage_increase_mail_id(&(input_new_mail_tbl_data->mail_id), false, &err)) {
+ if (!emstorage_increase_mail_id(multi_user_name, &(input_new_mail_tbl_data->mail_id), false, &err)) {
EM_DEBUG_EXCEPTION("emstorage_increase_mail_id failed [%d]", err);
- emstorage_rollback_transaction(NULL, NULL, NULL);
+ emstorage_rollback_transaction(multi_user_name, NULL, NULL, NULL);
goto FINISH_OFF;
}
- if (emstorage_get_thread_id_of_thread_mails(input_new_mail_tbl_data, &thread_id, &latest_mail_id_in_thread, &thread_item_count) != EMAIL_ERROR_NONE)
+ err = emstorage_get_thread_id_of_thread_mails(multi_user_name,
+ input_new_mail_tbl_data,
+ &thread_id,
+ &latest_mail_id_in_thread,
+ &thread_item_count);
+ if (err != EMAIL_ERROR_NONE)
EM_DEBUG_LOG(" emstorage_get_thread_id_of_thread_mails is failed.");
if (thread_id == -1){
input_new_mail_tbl_data->thread_id = input_new_mail_tbl_data->mail_id;
input_new_mail_tbl_data->thread_item_count = thread_item_count = 1;
- }
- else {
+ } else {
input_new_mail_tbl_data->thread_id = thread_id;
thread_item_count++;
}
- if (!emstorage_add_mail(input_new_mail_tbl_data, 0, false, &err)) {
+ EM_DEBUG_LOG("MULTI USER NAME: [%s]", multi_user_name);
+ input_new_mail_tbl_data->user_name = EM_SAFE_STRDUP(multi_user_name);
+
+ if (!emstorage_add_mail(multi_user_name, input_new_mail_tbl_data, 0, false, &err)) {
EM_DEBUG_EXCEPTION("emstorage_add_mail failed [%d]", err);
- emstorage_rollback_transaction(NULL, NULL, NULL);
+ emstorage_rollback_transaction(multi_user_name, NULL, NULL, NULL);
goto FINISH_OFF;
}
if (thread_item_count > 1) {
- if (!emstorage_update_latest_thread_mail(input_new_mail_tbl_data->account_id, input_new_mail_tbl_data->mailbox_id, input_new_mail_tbl_data->thread_id, NULL, -1, -1, NOTI_THREAD_ID_CHANGED_BY_ADD, false, &err)) {
+ if (!emstorage_update_latest_thread_mail(multi_user_name,
+ input_new_mail_tbl_data->account_id,
+ input_new_mail_tbl_data->mailbox_id,
+ input_new_mail_tbl_data->mailbox_type,
+ input_new_mail_tbl_data->thread_id,
+ NULL,
+ -1,
+ -1,
+ NOTI_THREAD_ID_CHANGED_BY_ADD,
+ false,
+ &err)) {
EM_DEBUG_EXCEPTION("emstorage_update_latest_thread_mail failed [%d]", err);
- emstorage_rollback_transaction(NULL, NULL, NULL);
+ emstorage_rollback_transaction(multi_user_name, NULL, NULL, NULL);
goto FINISH_OFF;
}
- if (!emstorage_update_latest_thread_mail(input_new_mail_tbl_data->account_id, input_new_mail_tbl_data->mailbox_id, input_new_mail_tbl_data->thread_id, NULL, 0, 0, NOTI_THREAD_ID_CHANGED_BY_ADD, false, &err)) {
+ if (!emstorage_update_latest_thread_mail(multi_user_name,
+ input_new_mail_tbl_data->account_id,
+ input_new_mail_tbl_data->mailbox_id,
+ input_new_mail_tbl_data->mailbox_type,
+ input_new_mail_tbl_data->thread_id,
+ NULL,
+ 0,
+ 0,
+ NOTI_THREAD_ID_CHANGED_BY_ADD,
+ false,
+ &err)) {
EM_DEBUG_EXCEPTION("emstorage_update_latest_thread_mail failed [%d]", err);
- emstorage_rollback_transaction(NULL, NULL, NULL);
+ emstorage_rollback_transaction(multi_user_name, NULL, NULL, NULL);
goto FINISH_OFF;
}
}
- if (emstorage_get_thread_id_of_thread_mails(input_new_mail_tbl_data, &thread_id, &latest_mail_id_in_thread, &thread_item_count) != EMAIL_ERROR_NONE)
+ if (emstorage_get_thread_id_of_thread_mails(multi_user_name,
+ input_new_mail_tbl_data,
+ &thread_id,
+ &latest_mail_id_in_thread,
+ &thread_item_count) != EMAIL_ERROR_NONE)
EM_DEBUG_LOG(" emstorage_get_thread_id_of_thread_mails is failed.");
if (output_thread_id)
@@ -1590,23 +1719,28 @@ INTERNAL_FUNC int emcore_add_mail_to_mailbox(emstorage_mailbox_tbl_t *input_maib
if (output_mail_id != NULL)
*output_mail_id = input_new_mail_tbl_data->mail_id;
-
-
- if (!emcore_add_read_mail_uid(input_maibox_data, input_maibox_data->mailbox_name, input_new_mail_tbl_data->mail_id, input_new_mail_tbl_data->server_mail_id, input_new_mail_tbl_data->mail_size, 0, &err)) {
+ if (!emcore_add_read_mail_uid(multi_user_name,
+ input_maibox_data,
+ input_maibox_data->mailbox_name,
+ input_new_mail_tbl_data->mail_id,
+ input_new_mail_tbl_data->server_mail_id,
+ input_new_mail_tbl_data->mail_size,
+ 0,
+ &err)) {
EM_DEBUG_EXCEPTION("emcore_add_read_mail_uid failed [%d]", err);
- emstorage_rollback_transaction(NULL, NULL, NULL);
+ emstorage_rollback_transaction(multi_user_name, NULL, NULL, NULL);
goto FINISH_OFF;
}
#ifdef __FEATURE_BODY_SEARCH__
- if (!emcore_add_mail_text(input_maibox_data, input_new_mail_tbl_data, NULL, &err)) {
+ if (!emcore_add_mail_text(multi_user_name, input_maibox_data, input_new_mail_tbl_data, NULL, &err)) {
EM_DEBUG_EXCEPTION("emcore_add_mail_text failed [%d]", err);
- emstorage_rollback_transaction(NULL, NULL, NULL);
+ emstorage_rollback_transaction(multi_user_name, NULL, NULL, NULL);
goto FINISH_OFF;
}
#endif
- emstorage_commit_transaction(NULL, NULL, NULL);
+ emstorage_commit_transaction(multi_user_name, NULL, NULL, NULL);
FINISH_OFF:
@@ -1743,7 +1877,7 @@ FINISH_OFF:
return ret;
}
-INTERNAL_FUNC int emcore_make_mail_tbl_data_from_envelope(int account_id, MAILSTREAM *mail_stream, ENVELOPE *input_envelope, emcore_uid_list *input_uid_elem, emstorage_mail_tbl_t **output_mail_tbl_data, int *err_code)
+INTERNAL_FUNC int emcore_make_mail_tbl_data_from_envelope(char *multi_user_name, int account_id, MAILSTREAM *mail_stream, ENVELOPE *input_envelope, emcore_uid_list *input_uid_elem, emstorage_mail_tbl_t **output_mail_tbl_data, int *err_code)
{
EM_PROFILE_BEGIN(emCoreParseEnvelope);
EM_DEBUG_FUNC_BEGIN("input_envelope[%p], input_uid_elem [%p], output_mail_tbl_data[%p], err_code[%p]", input_envelope, input_uid_elem, output_mail_tbl_data, err_code);
@@ -1760,7 +1894,7 @@ INTERNAL_FUNC int emcore_make_mail_tbl_data_from_envelope(int account_id, MAILST
char *rfc822_subject = NULL;
char *rfc822_from = NULL;
- account_ref = emcore_get_account_reference(account_id);
+ account_ref = emcore_get_account_reference(multi_user_name, account_id, false);
if (!account_ref) {
EM_DEBUG_EXCEPTION("emcore_get_account_reference failed - %d", account_id);
err = EMAIL_ERROR_INVALID_ACCOUNT;
@@ -1820,7 +1954,7 @@ INTERNAL_FUNC int emcore_make_mail_tbl_data_from_envelope(int account_id, MAILST
}
if (input_envelope->subject) {
- temp_mail_tbl_data->subject = emcore_decode_rfc2047_text(input_envelope->subject, &err);
+ temp_mail_tbl_data->subject = emcore_gmime_get_decoding_text(input_envelope->subject);
em_trim_left(temp_mail_tbl_data->subject);
char *charset = NULL;
@@ -1846,8 +1980,6 @@ INTERNAL_FUNC int emcore_make_mail_tbl_data_from_envelope(int account_id, MAILST
EM_DEBUG_EXCEPTION("emcore_get_utf8_address failed [%d]", err);
goto FINISH_OFF;
}
-
-
}
if (input_envelope->to) {
@@ -1855,8 +1987,6 @@ INTERNAL_FUNC int emcore_make_mail_tbl_data_from_envelope(int account_id, MAILST
EM_DEBUG_EXCEPTION("emcore_get_utf8_address failed [%d]", err);
goto FINISH_OFF;
}
-
-
}
if (input_envelope->cc) {
@@ -1922,12 +2052,12 @@ INTERNAL_FUNC int emcore_make_mail_tbl_data_from_envelope(int account_id, MAILST
temp_mail_tbl_data->server_mail_id = EM_SAFE_STRDUP(input_uid_elem->uid);
temp_mail_tbl_data->mail_size = mail_cache_element->rfc822_size;
temp_mail_tbl_data->flags_seen_field = input_uid_elem->flag.seen;
+ temp_mail_tbl_data->flags_draft_field = input_uid_elem->flag.draft;
+ temp_mail_tbl_data->flags_flagged_field = input_uid_elem->flag.flagged;
+ temp_mail_tbl_data->flags_answered_field = input_uid_elem->flag.answered;
+ temp_mail_tbl_data->flags_forwarded_field = input_uid_elem->flag.forwarded;
temp_mail_tbl_data->flags_deleted_field = mail_cache_element->deleted;
- temp_mail_tbl_data->flags_flagged_field = mail_cache_element->flagged;
- temp_mail_tbl_data->flags_answered_field = mail_cache_element->answered;
temp_mail_tbl_data->flags_recent_field = mail_cache_element->recent;
- temp_mail_tbl_data->flags_draft_field = mail_cache_element->draft;
- temp_mail_tbl_data->flags_forwarded_field = input_uid_elem->flag.forwarded;
temp_mail_tbl_data->priority = priority;
temp_mail_tbl_data->report_status = (req_read_receipt ? EMAIL_MAIL_REQUEST_MDN : 0);
temp_mail_tbl_data->attachment_count = 0;
@@ -1935,7 +2065,7 @@ INTERNAL_FUNC int emcore_make_mail_tbl_data_from_envelope(int account_id, MAILST
temp_mail_tbl_data->eas_data = NULL;
temp_mail_tbl_data->account_id = account_id;
- emcore_fill_address_information_of_mail_tbl(temp_mail_tbl_data);
+ emcore_fill_address_information_of_mail_tbl(multi_user_name, temp_mail_tbl_data);
*output_mail_tbl_data = temp_mail_tbl_data;
temp_mail_tbl_data = NULL;
@@ -1964,12 +2094,11 @@ FINISH_OFF:
return ret;
}
-
-
-INTERNAL_FUNC int emcore_sync_header (emstorage_mailbox_tbl_t *input_mailbox_tbl,
- void **stream,
- emcore_uid_list **input_uid_list,
- int *mail_count,
+INTERNAL_FUNC int emcore_sync_header (char *multi_user_name,
+ emstorage_mailbox_tbl_t *input_mailbox_tbl,
+ void **stream,
+ emcore_uid_list **input_uid_list,
+ int *mail_count,
int *unread_mail,
int *vip_mail_count,
int *vip_unread_mail,
@@ -1978,7 +2107,9 @@ INTERNAL_FUNC int emcore_sync_header (emstorage_mailbox_tbl_t *input_mailbox_tbl
int *err_code)
{
EM_PROFILE_BEGIN(emCoreSyncHeader);
- EM_DEBUG_FUNC_BEGIN("input_mailbox_tbl[%p], input_uid_list [%p], err_code[%p]", input_mailbox_tbl, input_uid_list, err_code);
+ EM_DEBUG_FUNC_BEGIN("input_mailbox_tbl[%p], input_uid_list [%p], err_code[%p]",
+ input_mailbox_tbl, input_uid_list, err_code);
+
if (!stream) {
EM_DEBUG_EXCEPTION ("NULL stream");
if (err_code)
@@ -1988,12 +2119,12 @@ INTERNAL_FUNC int emcore_sync_header (emstorage_mailbox_tbl_t *input_mailbox_tbl
int ret = false;
int err = EMAIL_ERROR_NONE, err_2 = EMAIL_ERROR_NONE;
- int err_from_vconf = 0;
int download_limit_count;
- email_account_t *account_ref = NULL;
+ email_session_t *session = NULL;
+ email_account_t *account_ref = NULL;
emstorage_rule_tbl_t *rule = NULL;
- emcore_uid_list *uid_list = NULL;
- emcore_uid_list *uid_elem = NULL;
+ emcore_uid_list *uid_list = NULL;
+ emcore_uid_list *uid_elem = NULL;
emstorage_mail_tbl_t *new_mail_tbl_data = NULL;
emstorage_mailbox_tbl_t *destination_mailbox = NULL;
@@ -2011,7 +2142,7 @@ INTERNAL_FUNC int emcore_sync_header (emstorage_mailbox_tbl_t *input_mailbox_tbl
account_id = input_mailbox_tbl->account_id;
g_current_sync_account_id = account_id;
- account_ref = emcore_get_account_reference(account_id);
+ account_ref = emcore_get_account_reference(multi_user_name, account_id, false);
if (!account_ref) {
EM_DEBUG_EXCEPTION("emcore_get_account_reference failed - %d", account_id);
err = EMAIL_ERROR_INVALID_ACCOUNT;
@@ -2024,18 +2155,18 @@ INTERNAL_FUNC int emcore_sync_header (emstorage_mailbox_tbl_t *input_mailbox_tbl
goto FINISH_OFF;
}
-
if (account_ref->incoming_server_type == EMAIL_SERVER_TYPE_IMAP4 && input_mailbox_tbl->local_yn == 1) {
/* mailbox recovery starts */
if (input_mailbox_tbl->mailbox_type == EMAIL_MAILBOX_TYPE_INBOX) {
- if (!emcore_sync_mailbox_list (account_id, "", event_handle, &err)) {
+ if (!emcore_sync_mailbox_list (multi_user_name, account_id, "", event_handle, &err)) {
EM_DEBUG_EXCEPTION("emcore_sync_mailbox_list error [%d] account_id [%d]", err, account_id);
goto FINISH_OFF;
}
}
else {
- EM_DEBUG_EXCEPTION ("because mailbox_name[%s] mailbox_type[%d] of account[%d] is a local box, it cant be synced",
- input_mailbox_tbl->mailbox_name, input_mailbox_tbl->mailbox_type, account_id);
+ EM_DEBUG_EXCEPTION("because mailbox_name[%s] mailbox_type[%d] of account[%d] is "
+ "a local box, it cant be synced",
+ input_mailbox_tbl->mailbox_name, input_mailbox_tbl->mailbox_type, account_id);
err = EMAIL_ERROR_INVALID_MAILBOX;
goto FINISH_OFF;
}
@@ -2045,12 +2176,18 @@ INTERNAL_FUNC int emcore_sync_header (emstorage_mailbox_tbl_t *input_mailbox_tbl
FINISH_OFF_IF_EVENT_CANCELED(err, event_handle);
#ifdef __FEATURE_SUPPORT_SYNC_STATE_ON_NOTI_BAR__
+ int err_from_vconf = 0;
+
if ((err_from_vconf = vconf_set_int(VCONFKEY_EMAIL_SYNC_STATE, 1)) != 0 ) {
EM_DEBUG_EXCEPTION("vconf_set_int failed (sync state) [%d]", err_from_vconf);
}
#endif /* __FEATURE_SUPPORT_SYNC_STATE_ON_NOTI_BAR__ */
- if (!emcore_connect_to_remote_mailbox(account_id, input_mailbox_tbl->mailbox_id, (void **)stream, &err) || !*stream) {
+ if (!emcore_connect_to_remote_mailbox(multi_user_name,
+ account_id,
+ input_mailbox_tbl->mailbox_id,
+ (void **)stream,
+ &err) || !*stream) {
EM_DEBUG_EXCEPTION("emcore_connect_to_remote_mailbox failed - %d", err);
goto FINISH_OFF;
}
@@ -2058,286 +2195,367 @@ INTERNAL_FUNC int emcore_sync_header (emstorage_mailbox_tbl_t *input_mailbox_tbl
if (cancellable)
FINISH_OFF_IF_EVENT_CANCELED(err, event_handle);
+
+ /* check the connection broken */
+ EM_DEBUG_LOG("((MAILSTREAM *)stream)->nmsgs [%ld]", ((MAILSTREAM *)*stream)->nmsgs);
+
+ unsigned long nmsgs_count = ((MAILSTREAM *)*stream)->nmsgs;
+ if (!nmsgs_count) {
+ EM_DEBUG_LOG("MAILSTREAM");
+ if (!emcore_get_current_session(&session)) {
+ EM_DEBUG_EXCEPTION("emcore_get_current_session failed");
+ err = EMAIL_ERROR_SESSION_NOT_FOUND;
+ goto FINISH_OFF;
+ }
+
+ if (session->error == EMAIL_ERROR_CONNECTION_BROKEN) {
+ EM_DEBUG_EXCEPTION("session error : [%d]", session->error);
+ err = session->error;
+ goto FINISH_OFF;
+ }
+ }
+
/* save total mail count on server to DB */
- if (!emstorage_update_mailbox_total_count(account_id, input_mailbox_tbl->mailbox_id, ((MAILSTREAM *)*stream)->nmsgs, 1, &err)){
+ if (!emstorage_update_mailbox_total_count(multi_user_name,
+ account_id,
+ input_mailbox_tbl->mailbox_id,
+ ((MAILSTREAM *)*stream)->nmsgs,
+ 1,
+ &err)){
EM_DEBUG_EXCEPTION("emstorage_update_mailbox_total_count failed [%d]", err);
+ goto FINISH_OFF;
+ }
+ email_option_t *opt_ref = &account_ref->options;
+ EM_DEBUG_LOG_SEC("block_address = %d, block_subject = %d", opt_ref->block_address, opt_ref->block_subject);
+
+ if (opt_ref->block_address || opt_ref->block_subject) {
+ int is_completed = false;
+ int type = 0;
+
+ if (!opt_ref->block_address)
+ type = EMAIL_FILTER_SUBJECT;
+ else if (!opt_ref->block_subject)
+ type = EMAIL_FILTER_FROM;
+
+ if (!emstorage_get_rule(multi_user_name,
+ ALL_ACCOUNT,
+ type,
+ 0,
+ &rule_count,
+ &is_completed,
+ &rule,
+ true,
+ &err) || !rule) {
+ if ( err != EMAIL_ERROR_FILTER_NOT_FOUND )
+ EM_DEBUG_EXCEPTION ("emstorage_get_rule error [%d]", err);
+ }
+ }
+
+ download_limit_count = input_mailbox_tbl->mail_slot_size;
+ if (!emcore_get_uids_to_download(multi_user_name,
+ *stream,
+ account_ref,
+ input_mailbox_tbl,
+ download_limit_count,
+ &uid_list,
+ &total,
+ EMAIL_SYNC_LATEST_MAILS_FIRST,
+ &err)) {
+ EM_DEBUG_EXCEPTION("emcore_get_uids_to_download failed [%d]", err);
goto FINISH_OFF;
}
- /* if (((MAILSTREAM *)stream)->nmsgs > 0) */
- {
- email_option_t *opt_ref = &account_ref->options;
- EM_DEBUG_LOG_SEC("block_address = %d, block_subject = %d", opt_ref->block_address, opt_ref->block_subject);
+ if (cancellable)
+ FINISH_OFF_IF_EVENT_CANCELED(err, event_handle);
- if (opt_ref->block_address || opt_ref->block_subject) {
- int is_completed = false;
- int type = 0;
+ if (input_uid_list && *input_uid_list){
+ emcore_free_uids(*input_uid_list, NULL);
+ *input_uid_list = uid_list;
+ }
+ uid_elem = uid_list;
+ i = 0;
+ EM_PROFILE_BEGIN(emCoreSyncHeaderwhileloop);
- if (!opt_ref->block_address)
- type = EMAIL_FILTER_SUBJECT;
- else if (!opt_ref->block_subject)
- type = EMAIL_FILTER_FROM;
+#ifdef __FEATURE_HEADER_OPTIMIZATION__
+ /* g.shyamakshi@samsung.com : Bulk fetch of headers only if the receiving server type is IMAP */
- if (!emstorage_get_rule(ALL_ACCOUNT, type, 0, &rule_count, &is_completed, &rule, true, &err) || !rule) {
- if ( err != EMAIL_ERROR_FILTER_NOT_FOUND )
- EM_DEBUG_EXCEPTION ("emstorage_get_rule error [%d]", err);
- }
- }
+ EM_DEBUG_LOG("uid_list [%p]", uid_list);
- download_limit_count = input_mailbox_tbl->mail_slot_size;
+ if (account_ref->incoming_server_type == EMAIL_SERVER_TYPE_IMAP4 && uid_list != NULL) {
- if (!emcore_get_uids_to_download(*stream, account_ref, input_mailbox_tbl, download_limit_count, &uid_list,
- &total, EMAIL_SYNC_LATEST_MAILS_FIRST, &err)){
- EM_DEBUG_EXCEPTION("emcore_get_uids_to_download failed [%d]", err);
+ if ((err = emcore_make_uid_range_string(uid_list, total, &uid_range)) != EMAIL_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("emcore_make_uid_range_string failed [%d]", err);
goto FINISH_OFF;
}
if (cancellable)
FINISH_OFF_IF_EVENT_CANCELED(err, event_handle);
- if (input_uid_list && *input_uid_list){
- emcore_free_uids(*input_uid_list, NULL);
- *input_uid_list = uid_list;
- }
uid_elem = uid_list;
- i = 0;
- EM_PROFILE_BEGIN(emCoreSyncHeaderwhileloop);
-
-#ifdef __FEATURE_HEADER_OPTIMIZATION__
- /* g.shyamakshi@samsung.com : Bulk fetch of headers only if the receiving server type is IMAP */
-
- EM_DEBUG_LOG("((MAILSTREAM *)stream)->nmsgs [%d]", ((MAILSTREAM *)*stream)->nmsgs);
- EM_DEBUG_LOG("uid_list [%p]", uid_list);
-
- if (account_ref->incoming_server_type == EMAIL_SERVER_TYPE_IMAP4 && uid_list != NULL) {
-
- if ((err = emcore_make_uid_range_string(uid_list, total, &uid_range)) != EMAIL_ERROR_NONE) {
- EM_DEBUG_EXCEPTION("emcore_make_uid_range_string failed [%d]", err);
- goto FINISH_OFF;
- }
-
- if (cancellable)
- FINISH_OFF_IF_EVENT_CANCELED(err, event_handle);
-
- uid_elem = uid_list;
- if (*stream && uid_elem){
- EM_DEBUG_LOG("msgno : %d", uid_elem->msgno);
- ((MAILSTREAM *)*stream)->nmsgs = uid_elem->msgno;
- }
- else{
- EM_DEBUG_LOG("Uid List Null");
- }
- EM_DEBUG_LOG("Calling ... mail_fetch_fast. uid_range [%s]", uid_range);
- mail_fetch_fast(*stream, uid_range, FT_UID | FT_PEEK | FT_NEEDENV);
- EM_SAFE_FREE(uid_range);
+ if (*stream && uid_elem){
+ EM_DEBUG_LOG("msgno : %d", uid_elem->msgno);
+ ((MAILSTREAM *)*stream)->nmsgs = uid_elem->msgno;
+ }
+ else{
+ EM_DEBUG_LOG("Uid List Null");
}
+ EM_DEBUG_LOG("Calling ... mail_fetch_fast. uid_range [%s]", uid_range);
+ mail_fetch_fast(*stream, uid_range, FT_UID | FT_PEEK | FT_NEEDENV);
+ EM_SAFE_FREE(uid_range);
+ }
#endif
- /* h.gahlaut@samsung.com : Clear the event queue of partial body download thread before starting fetching new headers */
+ /* h.gahlaut@samsung.com : Clear the event queue of partial body download thread before starting fetching new headers */
#ifndef __FEATURE_PARTIAL_BODY_FOR_POP3__
- if (account_ref->incoming_server_type == EMAIL_SERVER_TYPE_IMAP4){
+ if (account_ref->incoming_server_type == EMAIL_SERVER_TYPE_IMAP4){
#endif /* __FEATURE_PARTIAL_BODY_FOR_POP3__ */
- /* Partial body download feature is only for IMAP accounts */
- if (false == emcore_clear_partial_body_thd_event_que(&err))
- EM_DEBUG_LOG("emcore_clear_partial_body_thd_event_que failed [%d]", err);
+ /* Partial body download feature is only for IMAP accounts */
+ if (false == emcore_clear_partial_body_thd_event_que(&err))
+ EM_DEBUG_LOG("emcore_clear_partial_body_thd_event_que failed [%d]", err);
#ifndef __FEATURE_PARTIAL_BODY_FOR_POP3__
- }
+ }
#endif /* __FEATURE_PARTIAL_BODY_FOR_POP3__ */
- while (uid_elem) {
- EM_PROFILE_BEGIN(emCoreSyncHeaderEachMail);
- EM_DEBUG_LOG("mail_fetchstructure_full : uid_elem->msgno[%d]", uid_elem->msgno);
+ while (uid_elem) {
+ EM_PROFILE_BEGIN(emCoreSyncHeaderEachMail);
+ EM_DEBUG_LOG("mail_fetchstructure_full : uid_elem->msgno[%d]", uid_elem->msgno);
- env = NULL;
+ env = NULL;
- if (uid_elem->msgno > ((MAILSTREAM *)*stream)->nmsgs) {
- EM_DEBUG_LOG ("WARN: msgno[%d] can't be greater than nmsgs[%d].",
- uid_elem->msgno, ((MAILSTREAM *)*stream)->nmsgs);
- }
- else{
+ if (uid_elem->msgno > ((MAILSTREAM *)*stream)->nmsgs) {
+ EM_DEBUG_LOG ("WARN: msgno[%d] can't be greater than nmsgs[%d].",
+ uid_elem->msgno, ((MAILSTREAM *)*stream)->nmsgs);
+ }
+ else{
#ifdef __FEATURE_HEADER_OPTIMIZATION__
- if (account_ref->incoming_server_type == EMAIL_SERVER_TYPE_IMAP4) /* Fetch env from cache in case of IMAP */
- env = mail_fetchstructure_full (*stream, uid_elem->msgno, NULL, FT_PEEK, 0);
- else /* Fetch header from network in case of POP */
- env = mail_fetchstructure_full (*stream, uid_elem->msgno, NULL, FT_PEEK, 1);
+ if (account_ref->incoming_server_type == EMAIL_SERVER_TYPE_IMAP4) /* Fetch env from cache in case of IMAP */
+ env = mail_fetchstructure_full (*stream, uid_elem->msgno, NULL, FT_PEEK, 0);
+ else /* Fetch header from network in case of POP */
+ env = mail_fetchstructure_full (*stream, uid_elem->msgno, NULL, FT_PEEK, 1);
#else
- env = mail_fetchstructure_full (*stream, uid_elem->msgno, NULL, FT_PEEK);
+ env = mail_fetchstructure_full (*stream, uid_elem->msgno, NULL, FT_PEEK);
#endif
- }
-
- if (cancellable)
- FINISH_OFF_IF_EVENT_CANCELED(err, event_handle);
-
- if (env != NULL) {
- int searched_mail_id = 0;
- int blocked = false;
- int priority_sender = false;
+ }
- if (!emcore_make_mail_tbl_data_from_envelope (account_id, *stream, env, uid_elem,
- &new_mail_tbl_data, &err) || !new_mail_tbl_data) {
- EM_DEBUG_EXCEPTION("emcore_make_mail_tbl_data_from_envelope failed [%d]", err);
- goto CONTINUE_NEXT;
- }
+ if (cancellable)
+ FINISH_OFF_IF_EVENT_CANCELED(err, event_handle);
- /* Check message_id for duplicated mail in sentbox */
- if ((input_mailbox_tbl->mailbox_type == EMAIL_MAILBOX_TYPE_SENTBOX) && (emstorage_check_and_update_server_uid_by_message_id(new_mail_tbl_data->account_id, input_mailbox_tbl->mailbox_type, new_mail_tbl_data->message_id, new_mail_tbl_data->server_mail_id, &searched_mail_id) == EMAIL_ERROR_NONE)) {
- EM_DEBUG_LOG("Existed the duplicated mail : message_id[%s]", new_mail_tbl_data->message_id);
+ if (env != NULL) {
+ int searched_mail_id = 0;
+ int blocked = false;
+ int priority_sender = false;
- if (!emcore_add_read_mail_uid(input_mailbox_tbl, input_mailbox_tbl->mailbox_name, searched_mail_id, new_mail_tbl_data->server_mail_id, new_mail_tbl_data->mail_size, 0, &err)) {
- EM_DEBUG_EXCEPTION("emcore_add_read_mail_uid failed");
- }
+ if (!emcore_make_mail_tbl_data_from_envelope (multi_user_name, account_id, *stream, env, uid_elem,
+ &new_mail_tbl_data, &err) || !new_mail_tbl_data) {
+ EM_DEBUG_EXCEPTION("emcore_make_mail_tbl_data_from_envelope failed [%d]", err);
+ goto CONTINUE_NEXT;
+ }
+ /* Check message_id for duplicated mail in sentbox */
+ if ((input_mailbox_tbl->mailbox_type == EMAIL_MAILBOX_TYPE_SENTBOX) &&
+ (emstorage_check_and_update_server_uid_by_message_id(multi_user_name,
+ new_mail_tbl_data->account_id,
+ input_mailbox_tbl->mailbox_type,
+ new_mail_tbl_data->message_id,
+ new_mail_tbl_data->server_mail_id,
+ &searched_mail_id) == EMAIL_ERROR_NONE)) {
+ EM_DEBUG_LOG("Existed the duplicated mail : message_id[%s]", new_mail_tbl_data->message_id);
+
+ if (!emcore_add_read_mail_uid(multi_user_name, input_mailbox_tbl,
+ input_mailbox_tbl->mailbox_name, searched_mail_id,
+ new_mail_tbl_data->server_mail_id, new_mail_tbl_data->mail_size,
+ 0, &err)) {
+ EM_DEBUG_EXCEPTION("emcore_add_read_mail_uid failed : [%d]", err);
goto CONTINUE_NEXT;
}
-
- if (rule && !emcore_check_rule(new_mail_tbl_data->full_address_from, new_mail_tbl_data->subject, rule, rule_count, &priority_sender, &blocked, &err)) {
- EM_DEBUG_EXCEPTION("emcore_check_rule failed [%d]", err);
+
+ if (!emstorage_change_mail_field(multi_user_name, searched_mail_id, UPDATE_DATETIME,
+ new_mail_tbl_data, true, &err)) {
+ EM_DEBUG_EXCEPTION("emstorage_change_mail_field failed : [%d]", err);
+ goto CONTINUE_NEXT;
}
- if(destination_mailbox) /* cleanup before reusing */
- emstorage_free_mailbox(&destination_mailbox, 1, NULL);
+ goto CONTINUE_NEXT;
+ }
- if (priority_sender) {
- new_mail_tbl_data->tag_id = PRIORITY_SENDER_TAG_ID;
- vip_total ++;
- }
+ if (rule && !emcore_check_rule(new_mail_tbl_data->full_address_from,
+ new_mail_tbl_data->subject,
+ rule,
+ rule_count,
+ &priority_sender,
+ &blocked,
+ &err)) {
+ EM_DEBUG_EXCEPTION("emcore_check_rule failed [%d]", err);
+ }
- if (blocked && (input_mailbox_tbl->mailbox_type == EMAIL_MAILBOX_TYPE_INBOX)) {
- if (input_mailbox_tbl->mailbox_type != EMAIL_MAILBOX_TYPE_SPAMBOX) {
- EM_DEBUG_LOG("mail[%d] added to spambox", mail_id);
- if (!emstorage_get_mailbox_by_mailbox_type(account_id, EMAIL_MAILBOX_TYPE_SPAMBOX,
- &destination_mailbox, false, &err)) {
- EM_DEBUG_LOG("emstorage_get_mailbox_by_mailbox_type failed [%d]", err);
- }
- }
- else
- blocked = 0;
- }
+ if (destination_mailbox) /* cleanup before reusing */
+ emstorage_free_mailbox(&destination_mailbox, 1, NULL);
- /* Set the noti waited */
- new_mail_tbl_data->save_status = EMAIL_MAIL_STATUS_NOTI_WAITED;
+ if (priority_sender) {
+ new_mail_tbl_data->tag_id = PRIORITY_SENDER_TAG_ID;
+ vip_total ++;
+ }
- if (destination_mailbox) {
- if (destination_mailbox->local_yn == 0 || account_ref->incoming_server_type == EMAIL_SERVER_TYPE_IMAP4) {
- if ((err = emcore_move_mail_on_server_by_server_mail_id((void*)*stream, new_mail_tbl_data->server_mail_id, destination_mailbox->mailbox_name)) != EMAIL_ERROR_NONE){
- EM_DEBUG_EXCEPTION("emcore_move_mail_on_server_by_server_mail_id falied [%d]", err);
- goto CONTINUE_NEXT;
- }
+ if (blocked && (input_mailbox_tbl->mailbox_type == EMAIL_MAILBOX_TYPE_INBOX)) {
+ if (input_mailbox_tbl->mailbox_type != EMAIL_MAILBOX_TYPE_SPAMBOX) {
+ EM_DEBUG_LOG("This mail would be added to spambox");
+ if (!emstorage_get_mailbox_by_mailbox_type(multi_user_name,
+ account_id,
+ EMAIL_MAILBOX_TYPE_SPAMBOX,
+ &destination_mailbox,
+ false,
+ &err)) {
+ EM_DEBUG_LOG("emstorage_get_mailbox_by_mailbox_type failed [%d]", err);
}
- else { /* local mailbox */
- if ((err = emcore_add_mail_to_mailbox(destination_mailbox, new_mail_tbl_data, &mail_id,
- &thread_id)) != EMAIL_ERROR_NONE) {
- EM_DEBUG_EXCEPTION("emcore_add_mail_to_mailbox failed [%d]", err);
- goto CONTINUE_NEXT;
- }
+ }
+ else
+ blocked = 0;
+ }
+ /* Set the noti waited */
+ new_mail_tbl_data->save_status = EMAIL_MAIL_STATUS_NOTI_WAITED;
+
+ if (destination_mailbox) {
+ if (destination_mailbox->local_yn == 0 ||
+ account_ref->incoming_server_type == EMAIL_SERVER_TYPE_IMAP4) {
+ err = emcore_move_mail_on_server_by_server_mail_id((void*)*stream,
+ new_mail_tbl_data->server_mail_id,
+ destination_mailbox->mailbox_name);
+ if (err != EMAIL_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("emcore_move_mail_on_server_by_server_mail_id falied [%d]", err);
+ goto CONTINUE_NEXT;
}
- SNPRINTF(mailbox_id_param_string, 10, "%d", destination_mailbox->mailbox_id);
- } else {
- /* add mails to specified mail box */
- EM_DEBUG_LOG_SEC("mail[%d] moved to input_mailbox_tbl [%s]", mail_id, input_mailbox_tbl->mailbox_name);
- if ( (err = emcore_add_mail_to_mailbox (input_mailbox_tbl, new_mail_tbl_data,
- &mail_id, &thread_id)) != EMAIL_ERROR_NONE) {
+ } else { /* local mailbox */
+ if ((err = emcore_add_mail_to_mailbox(multi_user_name,
+ destination_mailbox,
+ new_mail_tbl_data,
+ &mail_id,
+ &thread_id)) != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("emcore_add_mail_to_mailbox falied [%d]", err);
goto CONTINUE_NEXT;
}
+ }
+ SNPRINTF(mailbox_id_param_string, 10, "%d", destination_mailbox->mailbox_id);
+ } else {
+ /* add mails to specified mail box */
+ EM_DEBUG_LOG_SEC("mail[%d] moved to input_mailbox_tbl [%s]", mail_id, input_mailbox_tbl->mailbox_name);
+ if ((err = emcore_add_mail_to_mailbox(multi_user_name,
+ input_mailbox_tbl,
+ new_mail_tbl_data,
+ &mail_id,
+ &thread_id)) != EMAIL_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("emcore_add_mail_to_mailbox falied [%d]", err);
+ goto CONTINUE_NEXT;
+ }
+
#ifndef __FEATURE_PARTIAL_BODY_FOR_POP3__
- if (account_ref->incoming_server_type == EMAIL_SERVER_TYPE_IMAP4) {
+ if (account_ref->incoming_server_type == EMAIL_SERVER_TYPE_IMAP4) {
#endif /* __FEATURE_PARTIAL_BODY_FOR_POP3__ */
- if (account_ref->auto_download_size != 0) {
- if (false == emcore_initiate_pbd (*stream, account_id, mail_id, uid_elem->uid,
- input_mailbox_tbl->mailbox_id, &err))
- EM_DEBUG_LOG("Partial body download initiation failed [%d]", err);
- }
-#ifndef __FEATURE_PARTIAL_BODY_FOR_POP3__
+ if (account_ref->auto_download_size != 0) {
+ if (false == emcore_initiate_pbd(multi_user_name,
+ *stream,
+ account_id,
+ mail_id,
+ uid_elem->uid,
+ input_mailbox_tbl->mailbox_id,
+ input_mailbox_tbl->mailbox_name,
+ &err))
+ EM_DEBUG_LOG("Partial body download initiation failed [%d]", err);
}
+#ifndef __FEATURE_PARTIAL_BODY_FOR_POP3__
+ }
#endif /* __FEATURE_PARTIAL_BODY_FOR_POP3__ */
#ifdef __FEATURE_WIFI_AUTO_DOWNLOAD__
- if (input_mailbox_tbl->mailbox_type == EMAIL_MAILBOX_TYPE_INBOX) {
- if (!emcore_insert_auto_download_job(account_id, input_mailbox_tbl->mailbox_id,
- mail_id, /*account_ref->wifi_auto_download*/ 1, uid_elem->uid, &err))
- EM_DEBUG_LOG("emcore_insert_auto_download_job failed [%d]", err);
- }
+ if (input_mailbox_tbl->mailbox_type == EMAIL_MAILBOX_TYPE_INBOX) {
+ if (!emcore_insert_auto_download_job(multi_user_name,
+ account_id,
+ input_mailbox_tbl->mailbox_id,
+ mail_id,
+ /*account_ref->wifi_auto_download*/ 1,
+ uid_elem->uid,
+ &err))
+ EM_DEBUG_LOG("emcore_insert_auto_download_job failed [%d]", err);
+ }
#endif
/*
- if (!uid_elem->flag.seen && input_mailbox_tbl->mailbox_type != EMAIL_MAILBOX_TYPE_SPAMBOX)
- emcore_add_notification_for_unread_mail(new_mail_tbl_data);
+ if (!uid_elem->flag.seen && input_mailbox_tbl->mailbox_type != EMAIL_MAILBOX_TYPE_SPAMBOX)
+ emcore_add_notification_for_unread_mail(new_mail_tbl_data);
*/
- if (cancellable)
- FINISH_OFF_IF_EVENT_CANCELED(err, event_handle);
+ if (cancellable)
+ FINISH_OFF_IF_EVENT_CANCELED(err, event_handle);
- if (!uid_elem->flag.seen) {
- unread++;
- if (priority_sender) {
- vip_unread++;
- }
+ if (!uid_elem->flag.seen) {
+ unread++;
+ if (priority_sender) {
+ vip_unread++;
}
-
- percentage = ((i+1) * 100) / total ;
- EM_DEBUG_LOG("Header Percentage Completed [%d] : [%d/%d] mail_id [%d]", percentage, i+1,
- total, mail_id);
- SNPRINTF(mailbox_id_param_string, 10, "%d", input_mailbox_tbl->mailbox_id);
}
- if (!emcore_notify_storage_event (NOTI_MAIL_ADD, account_id, mail_id, mailbox_id_param_string, thread_id))
- EM_DEBUG_EXCEPTION ("emcore_notify_storage_event [NOTI_MAIL_ADD] failed");
+ percentage = ((i+1) * 100) / total ;
+ EM_DEBUG_LOG("Header Percentage Completed [%d] : [%d/%d] mail_id [%d]", percentage, i+1,
+ total, mail_id);
+ SNPRINTF(mailbox_id_param_string, 10, "%d", input_mailbox_tbl->mailbox_id);
+ }
-#ifdef __FEATURE_BLOCKING_MODE__
- /* Check the blocking mode */
- int blocking_mode = false;
-
- blocking_mode = emcore_get_blocking_mode_status();
- if (!blocking_mode) {
- if ((err = emcore_check_blocking_mode (new_mail_tbl_data->email_address_sender,
- &blocking_mode)) != EMAIL_ERROR_NONE) {
- EM_DEBUG_EXCEPTION ("emcore_check_blocking_mode failed : [%d]", err);
- }
+ if (!emcore_notify_storage_event (NOTI_MAIL_ADD, account_id, mail_id, mailbox_id_param_string, thread_id))
+ EM_DEBUG_EXCEPTION ("emcore_notify_storage_event [NOTI_MAIL_ADD] failed");
- if (blocking_mode)
- emcore_set_blocking_mode_status (blocking_mode);
+#ifdef __FEATURE_BLOCKING_MODE__
+ /* Check the blocking mode */
+ int blocking_mode = false;
+
+ blocking_mode = emcore_get_blocking_mode_status();
+ if (!blocking_mode) {
+ if ((err = emcore_check_blocking_mode (multi_user_name, new_mail_tbl_data->email_address_sender,
+ &blocking_mode)) != EMAIL_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION ("emcore_check_blocking_mode failed : [%d]", err);
}
+
+ if (blocking_mode)
+ emcore_set_blocking_mode_status (blocking_mode);
+ }
#endif /* __FEATURE_BLOCKING_MODE__ */
- /* Set contact log */
- switch (input_mailbox_tbl->mailbox_type) {
- case EMAIL_MAILBOX_TYPE_INBOX :
- if ((err = emcore_set_received_contacts_log(new_mail_tbl_data)) != EMAIL_ERROR_NONE) {
- EM_DEBUG_EXCEPTION("emcore_set_received_contacts_log failed : [%d]", err);
- }
- break;
- case EMAIL_MAILBOX_TYPE_SENTBOX:
- case EMAIL_MAILBOX_TYPE_OUTBOX:
- if ((err = emcore_set_sent_contacts_log(new_mail_tbl_data)) != EMAIL_ERROR_NONE) {
- EM_DEBUG_EXCEPTION("emcore_set_sent_contacts_log failed : [%d]", err);
- }
- break;
- default:
- EM_DEBUG_LOG("Mailbox type : [%d]", input_mailbox_tbl->mailbox_type);
- break;
+ /* Set contact log */
+ switch (input_mailbox_tbl->mailbox_type) {
+ case EMAIL_MAILBOX_TYPE_INBOX :
+ if ((err = emcore_set_received_contacts_log(multi_user_name, new_mail_tbl_data)) != EMAIL_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("emcore_set_received_contacts_log failed : [%d]", err);
+ }
+ break;
+ case EMAIL_MAILBOX_TYPE_SENTBOX:
+ case EMAIL_MAILBOX_TYPE_OUTBOX:
+ if ((err = emcore_set_sent_contacts_log(multi_user_name, new_mail_tbl_data)) != EMAIL_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("emcore_set_sent_contacts_log failed : [%d]", err);
}
+ break;
+ default:
+ EM_DEBUG_LOG("Mailbox type : [%d]", input_mailbox_tbl->mailbox_type);
+ break;
+ }
- /* Release for envelope is not required and it may cause crash. Don't free the memory for envelope here. */
- /* Envelope data will be freed by garbage collector in mail_close_full */
+ /* Release for envelope is not required and it may cause crash. Don't free the memory for envelope here. */
+ /* Envelope data will be freed by garbage collector in mail_close_full */
- if (cancellable)
- FINISH_OFF_IF_EVENT_CANCELED(err, event_handle);
- }
+ if (cancellable)
+ FINISH_OFF_IF_EVENT_CANCELED(err, event_handle);
+ }
CONTINUE_NEXT:
- if (new_mail_tbl_data){
- emstorage_free_mail(&new_mail_tbl_data, 1, NULL);
- new_mail_tbl_data = NULL;
- }
- uid_elem = uid_elem->next;
- i++;
- EM_PROFILE_END(emCoreSyncHeaderEachMail);
+ if (new_mail_tbl_data){
+ emstorage_free_mail(&new_mail_tbl_data, 1, NULL);
+ new_mail_tbl_data = NULL;
}
- EM_PROFILE_END(emCoreSyncHeaderwhileloop);
+ uid_elem = uid_elem->next;
+ i++;
+ EM_PROFILE_END(emCoreSyncHeaderEachMail);
}
+ EM_PROFILE_END(emCoreSyncHeaderwhileloop);
ret = true;
+
FINISH_OFF:
if (mail_count != NULL)
@@ -2357,11 +2575,11 @@ FINISH_OFF:
EM_SAFE_FREE(account_ref);
}
- if (!emcore_remove_overflowed_mails(input_mailbox_tbl, &err_2))
+ if (!emcore_remove_overflowed_mails(multi_user_name, input_mailbox_tbl, &err_2))
EM_DEBUG_EXCEPTION("emcore_remove_overflowed_mails failed - %d", err_2);
if (ret && input_mailbox_tbl)
- emstorage_stamp_last_sync_time_of_mailbox(input_mailbox_tbl->mailbox_id, 1);
+ emstorage_stamp_last_sync_time_of_mailbox(multi_user_name, input_mailbox_tbl->mailbox_id, 1);
#ifdef __FEATURE_SUPPORT_SYNC_STATE_ON_NOTI_BAR__
if ((err_from_vconf = vconf_set_int(VCONFKEY_EMAIL_SYNC_STATE, 0)) != 0 ) {
@@ -2417,7 +2635,7 @@ emcore_uid_list *__ReverseList(emcore_uid_list *uid_list)
-int emcore_download_uid_all(MAILSTREAM *mail_stream, email_internal_mailbox_t *mailbox, emcore_uid_list** uid_list, int *total, emstorage_read_mail_uid_tbl_t *downloaded_uids, int count, emcore_get_uids_for_delete_t for_delete, int *err_code)
+int emcore_download_uid_all(char *multi_user_name, MAILSTREAM *mail_stream, email_internal_mailbox_t *mailbox, emcore_uid_list** uid_list, int *total, emstorage_read_mail_uid_tbl_t *downloaded_uids, int count, emcore_get_uids_for_delete_t for_delete, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("mailbox[%p], uid_list[%p], total[%p], downloaded_uids[%p], count[%d], for_delete[%d], err_code[%p]", mailbox, uid_list, total, downloaded_uids, count, for_delete, err_code);
@@ -2439,7 +2657,7 @@ int emcore_download_uid_all(MAILSTREAM *mail_stream, email_internal_mailbox_t *m
goto FINISH_OFF;
}
- if (!(ref_account = emcore_get_account_reference(mailbox->account_id))) {
+ if (!(ref_account = emcore_get_account_reference(multi_user_name, mailbox->account_id, false))) {
EM_DEBUG_EXCEPTION("emcore_get_account_reference failed - %d", mailbox->account_id);
err = EMAIL_ERROR_INVALID_ACCOUNT;
@@ -2447,7 +2665,7 @@ int emcore_download_uid_all(MAILSTREAM *mail_stream, email_internal_mailbox_t *m
}
if (!mail_stream) {
- if (!emcore_connect_to_remote_mailbox(mailbox->account_id, mailbox->mailbox_id, (void **)&tmp_stream, &err)){
+ if (!emcore_connect_to_remote_mailbox(multi_user_name, mailbox->account_id, mailbox->mailbox_id, (void **)&tmp_stream, &err)){
EM_DEBUG_EXCEPTION("emcore_connect_to_remote_mailbox failed...");
goto FINISH_OFF;
@@ -2477,7 +2695,6 @@ int emcore_download_uid_all(MAILSTREAM *mail_stream, email_internal_mailbox_t *m
if (!net_sout(pop3local->netstream, cmd, (int)EM_SAFE_STRLEN(cmd))) {
EM_DEBUG_EXCEPTION("net_sout failed...");
-
err = EMAIL_ERROR_CONNECTION_BROKEN;
goto FINISH_OFF;
}
@@ -2580,7 +2797,6 @@ int emcore_download_uid_all(MAILSTREAM *mail_stream, email_internal_mailbox_t *m
#endif
if (!net_sout(imaplocal->netstream, cmd, (int)EM_SAFE_STRLEN(cmd))) {
EM_DEBUG_EXCEPTION("net_sout failed...");
-
err = EMAIL_ERROR_CONNECTION_BROKEN;
goto FINISH_OFF;
}
@@ -2716,7 +2932,7 @@ FINISH_OFF:
return ret;
}
-int emcore_download_imap_msgno(email_internal_mailbox_t *mailbox, char *uid, int *msgno, int *err_code)
+int emcore_download_imap_msgno(char *multi_user_name, email_internal_mailbox_t *mailbox, char *uid, int *msgno, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("mailbox[%p], uid[%p], msgno[%p], err_code[%p]", mailbox, uid, msgno, err_code);
@@ -2736,7 +2952,7 @@ int emcore_download_imap_msgno(email_internal_mailbox_t *mailbox, char *uid, int
goto FINISH_OFF;
}
- if (!(ref_account = emcore_get_account_reference(mailbox->account_id))) {
+ if (!(ref_account = emcore_get_account_reference(multi_user_name, mailbox->account_id, false))) {
EM_DEBUG_EXCEPTION("emcore_get_account_reference failed [%d]", mailbox->account_id);
err = EMAIL_ERROR_INVALID_ACCOUNT;
@@ -2749,7 +2965,7 @@ int emcore_download_imap_msgno(email_internal_mailbox_t *mailbox, char *uid, int
}
if (!mailbox->mail_stream) {
- if (!emcore_connect_to_remote_mailbox(mailbox->account_id, mailbox->mailbox_id, (void **)&tmp_stream, &err)) {
+ if (!emcore_connect_to_remote_mailbox(multi_user_name, mailbox->account_id, mailbox->mailbox_id, (void **)&tmp_stream, &err)) {
EM_DEBUG_EXCEPTION("emcore_connect_to_remote_mailbox failed - %d", err);
goto FINISH_OFF;
@@ -2935,7 +3151,7 @@ FINISH_OFF:
return ret;
}
-INTERNAL_FUNC char *emcore_guess_charset(char *source_string)
+INTERNAL_FUNC char *emcore_guess_charset(char *multi_user_name, char *source_string)
{
EM_DEBUG_FUNC_BEGIN("source - %s", source_string);
@@ -2995,9 +3211,9 @@ INTERNAL_FUNC char *emcore_guess_charset(char *source_string)
EM_DEBUG_LOG("ucsdet_getConfidence failed");
charset = ucsdet_getName(match[i], &err);
- if (U_FAILURE(err))
+ if(U_FAILURE(err))
EM_DEBUG_LOG("ucsdet_getName failed");
-
+
if (most_confidence < confidence) {
most_confidence = confidence;
detected_charset = charset;
@@ -3019,7 +3235,7 @@ INTERNAL_FUNC char *emcore_guess_charset(char *source_string)
if (uscdet_result_charset)
return uscdet_result_charset;
- account_ref = emcore_get_account_reference(g_current_sync_account_id);
+ account_ref = emcore_get_account_reference(multi_user_name, g_current_sync_account_id, false);
if (!account_ref) {
EM_DEBUG_EXCEPTION("emcore_get_account_reference failed - %d",
g_current_sync_account_id);
@@ -3051,7 +3267,7 @@ void mail_appenduid(char *mailbox, unsigned long uidvalidity, SEARCHSET *set)
EM_DEBUG_LOG("append uid - %s", g_append_uid_rsp);
}
-INTERNAL_FUNC int emcore_sync_mail_from_client_to_server(int mail_id)
+INTERNAL_FUNC int emcore_sync_mail_from_client_to_server(char *multi_user_name, int mail_id)
{
EM_DEBUG_FUNC_BEGIN("mail_id [%d]", mail_id);
@@ -3077,26 +3293,26 @@ INTERNAL_FUNC int emcore_sync_mail_from_client_to_server(int mail_id)
int alloc_size = 0;
/* get a mail from mail table */
- if (!emstorage_get_mail_by_id(mail_id, &mail_table_data, true, &err)) {
+ if (!emstorage_get_mail_by_id(multi_user_name, mail_id, &mail_table_data, true, &err)) {
EM_DEBUG_EXCEPTION("emstorage_get_mail_by_id failed [%d]", err);
goto FINISH_OFF;
}
- account_ref = emcore_get_account_reference(mail_table_data->account_id);
-
+ account_ref = emcore_get_account_reference(multi_user_name, mail_table_data->account_id, false);
if(account_ref == NULL || account_ref->incoming_server_type != EMAIL_SERVER_TYPE_IMAP4) {
EM_DEBUG_EXCEPTION("This account doesn't support sync");
err = EMAIL_ERROR_INVALID_ACCOUNT;
goto FINISH_OFF;
}
- if ((err = emstorage_get_attachment_list(mail_id, false, &attachment_tbl_data, &attachment_tbl_count)) != EMAIL_ERROR_NONE) {
+ if ((err = emstorage_get_attachment_list(multi_user_name, mail_id, false, &attachment_tbl_data, &attachment_tbl_count)) != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("emstorage_get_attachment_list failed [%d]", err);
goto FINISH_OFF;
}
EM_DEBUG_LOG("mailbox_id [%d]", mail_table_data->mailbox_id);
- if ((err = emstorage_get_mailbox_by_id(mail_table_data->mailbox_id, &mailbox_tbl)) != EMAIL_ERROR_NONE || !mailbox_tbl){
+
+ if ((err = emstorage_get_mailbox_by_id(multi_user_name, mail_table_data->mailbox_id, &mailbox_tbl)) != EMAIL_ERROR_NONE || !mailbox_tbl){
EM_DEBUG_EXCEPTION("emstorage_get_mailbox_by_name failed [%d]", err);
goto FINISH_OFF;
}
@@ -3107,7 +3323,7 @@ INTERNAL_FUNC int emcore_sync_mail_from_client_to_server(int mail_id)
goto FINISH_OFF;
}
- if (!emcore_get_long_encoded_path(mailbox_tbl->account_id, mailbox_tbl->mailbox_name, '/', &long_enc_path, &err)) {
+ if (!emcore_get_long_encoded_path(multi_user_name, mailbox_tbl->account_id, mailbox_tbl->mailbox_name, '/', &long_enc_path, &err)) {
EM_DEBUG_EXCEPTION(">>emcore_get_long_encoded_path : Failed [%d] ", err);
goto FINISH_OFF;
}
@@ -3117,7 +3333,7 @@ INTERNAL_FUNC int emcore_sync_mail_from_client_to_server(int mail_id)
goto FINISH_OFF;
}
- if (!emcore_make_rfc822_file_from_mail(mail_table_data, attachment_tbl_data, attachment_tbl_count, &envelope, &fname, NULL, &err)){
+ if (!emcore_make_rfc822_file_from_mail(multi_user_name, mail_table_data, attachment_tbl_data, attachment_tbl_count, &envelope, &fname, NULL, &err)){
EM_DEBUG_EXCEPTION(" emcore_make_rfc822_file_from_mail failed [%d]", err);
goto FINISH_OFF;
}
@@ -3150,7 +3366,7 @@ INTERNAL_FUNC int emcore_sync_mail_from_client_to_server(int mail_id)
rewind(fp);
- if (!emcore_connect_to_remote_mailbox(mail_table_data->account_id, 0, (void **)&stream, &err)){
+ if (!emcore_connect_to_remote_mailbox(multi_user_name, mail_table_data->account_id, 0, (void **)&stream, &err)){
EM_DEBUG_EXCEPTION("emcore_move_mail_on_server failed : Mailbox open[%d]", err);
goto FINISH_OFF;
}
@@ -3259,16 +3475,16 @@ INTERNAL_FUNC int emcore_sync_mail_from_client_to_server(int mail_id)
}
/* Update read_mail_uid tbl */
- if (!emcore_add_read_mail_uid(mailbox_tbl, mailbox_tbl->mailbox_name, mail_table_data->mail_id, g_append_uid_rsp, mail_table_data->mail_size, 0, &err)) {
+ if (!emcore_add_read_mail_uid(multi_user_name, mailbox_tbl, mailbox_tbl->mailbox_name, mail_table_data->mail_id, g_append_uid_rsp, mail_table_data->mail_size, 0, &err)) {
EM_DEBUG_EXCEPTION(" emcore_add_read_mail_uid failed [%d]", err);
- emstorage_rollback_transaction(NULL, NULL, NULL);
+ emstorage_rollback_transaction(multi_user_name, NULL, NULL, NULL);
goto FINISH_OFF;
}
/* Update mail_data tbl */
- if (!emstorage_update_server_uid(mail_table_data->server_mail_id, g_append_uid_rsp, &err)) {
+ if (!emstorage_update_server_uid(multi_user_name, mail_table_data->server_mail_id, g_append_uid_rsp, &err)) {
EM_DEBUG_EXCEPTION("emstorage_update_server_uid failed : [%d]", err);
- emstorage_rollback_transaction(NULL, NULL, NULL);
+ emstorage_rollback_transaction(multi_user_name, NULL, NULL, NULL);
goto FINISH_OFF;
}
@@ -3330,14 +3546,16 @@ FINISH_OFF:
#ifdef __FEATURE_PARTIAL_BODY_DOWNLOAD__
-static int emcore_initiate_pbd(MAILSTREAM *stream, int account_id, int mail_id, char *uid, int input_maibox_id, int *err_code)
+INTERNAL_FUNC int emcore_initiate_pbd(char *multi_user_name, MAILSTREAM *stream, int account_id,
+ int mail_id, char *uid, int input_maibox_id,
+ char *input_mailbox_name, int *err_code)
{
- EM_DEBUG_FUNC_BEGIN("account_id [%d], mail_id[%d], uid[%p], input_maibox_id[%d]", account_id, mail_id, uid, input_maibox_id);
+ EM_DEBUG_FUNC_BEGIN("account_id [%d], mail_id[%d], uid[%p], input_maibox_id[%d], input_mailbox_name[%s]",
+ account_id, mail_id, uid, input_maibox_id, input_mailbox_name);
int ret = false;
int err = EMAIL_ERROR_NONE;
email_account_t *account_ref = NULL;
- emstorage_mailbox_tbl_t* mailbox = NULL;
if (account_id < FIRST_ACCOUNT_ID || mail_id < 0 || NULL == uid || 0 == input_maibox_id){
EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
@@ -3345,10 +3563,20 @@ static int emcore_initiate_pbd(MAILSTREAM *stream, int account_id, int mail_id,
goto FINISH_OFF;
}
- account_ref = emcore_get_account_reference(account_id);
+ account_ref = emcore_get_account_reference(multi_user_name, account_id, false);
+ if (account_ref == NULL) {
+ EM_DEBUG_EXCEPTION("emcore_get_account_reference failed");
+ err = EMAIL_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
- email_event_partial_body_thd pbd_event;
+ if (account_ref->auto_download_size == 0) {
+ EM_DEBUG_LOG("Header only download");
+ ret = true;
+ goto FINISH_OFF;
+ }
+ email_event_partial_body_thd pbd_event;
memset(&pbd_event, 0x00, sizeof(email_event_partial_body_thd));
pbd_event.account_id = account_id;
@@ -3357,19 +3585,16 @@ static int emcore_initiate_pbd(MAILSTREAM *stream, int account_id, int mail_id,
else
pbd_event.activity_type = ACTIVITY_PARTIAL_BODY_DOWNLOAD_IMAP4;
- if ( (err = emstorage_get_mailbox_by_id(input_maibox_id, &mailbox)) != EMAIL_ERROR_NONE || !mailbox) {
- EM_DEBUG_EXCEPTION("emstorage_get_mailbox_by_id failed [%d]", err);
- goto FINISH_OFF;
- }
-
- pbd_event.mailbox_id = input_maibox_id;
- pbd_event.mail_id = mail_id;
- pbd_event.server_mail_id = strtoul(uid, NULL, 0);
- pbd_event.mailbox_name = EM_SAFE_STRDUP(mailbox->mailbox_name);
+ pbd_event.mail_id = mail_id;
+ pbd_event.server_mail_id = strtoul(uid, NULL, 0);
+ pbd_event.mailbox_id = input_maibox_id;
+ pbd_event.mailbox_name = EM_SAFE_STRDUP(input_mailbox_name);
+ pbd_event.multi_user_name = EM_SAFE_STRDUP(multi_user_name);
EM_DEBUG_LOG("input_mailbox_name name [%d]", pbd_event.mailbox_id);
EM_DEBUG_LOG("uid [%s]", uid);
- EM_DEBUG_LOG("pbd_event.account_id[%d], pbd_event.mail_id[%d], pbd_event.server_mail_id [%d]", pbd_event.account_id, pbd_event.mail_id , pbd_event.server_mail_id);
+ EM_DEBUG_LOG("pbd_event.account_id[%d], pbd_event.mail_id[%d], pbd_event.server_mail_id [%d]",
+ pbd_event.account_id, pbd_event.mail_id , pbd_event.server_mail_id);
if (!emcore_insert_pbd_activity(&pbd_event, &pbd_event.activity_id, &err)){
EM_DEBUG_EXCEPTION("Inserting Partial Body Download activity failed with error[%d]", err);
@@ -3402,16 +3627,12 @@ static int emcore_initiate_pbd(MAILSTREAM *stream, int account_id, int mail_id,
FINISH_OFF:
- if (mailbox) {
- emstorage_free_mailbox(&mailbox, 1, &err);
- }
-
if (account_ref) {
emcore_free_account(account_ref);
EM_SAFE_FREE(account_ref);
}
- emcore_free_partial_body_thd_event(&pbd_event, NULL);
+ emcore_free_partial_body_thd_event(&pbd_event, NULL);
if (NULL != err_code)
*err_code = err;
@@ -3420,96 +3641,17 @@ FINISH_OFF:
return ret;
}
-static int emcore_parse_bodystructure(void *stream, IMAPPARSEDREPLY *reply_from_server, char *bodystructure, BODY **body, struct _m_content_info **cnt_info, int *total_mail_size)
-{
- EM_DEBUG_FUNC_BEGIN("stream:[%p], reply_from_server:[%p], bodystructure:[%p]", stream, reply_from_server, bodystructure);
-
- int err = EMAIL_ERROR_NONE;
- char* ptr = NULL;
-
- if (!stream || !reply_from_server || !bodystructure || !cnt_info || !body || !total_mail_size) {
- EM_DEBUG_EXCEPTION("Invalid paramter stream[%p] reply_from_server[%p] bodystructure[%p] cnt_info[%p] body[%p] total_mail_size[%p]",
- stream, reply_from_server, bodystructure, cnt_info, body, total_mail_size);
- err = EMAIL_ERROR_INVALID_PARAM;
- return err;
- }
-
- int p_total_mail_size = 0;
- char *bodystructure_start = NULL;
- char *bodystructure_string = NULL;
- BODY *p_body = NULL;
- struct _m_content_info *p_cnt_info = NULL;
-
- /* Get the body strcuture string */
- bodystructure_start = strstr(bodystructure, "BODYSTRUCTURE (");
- if (!bodystructure_start) {
- EM_DEBUG_EXCEPTION("Invalid bodystructure :[%s]", bodystructure);
- err = EMAIL_ERROR_INVALID_PARAM;
- goto FINISH_OFF;
- }
-
- bodystructure_start = bodystructure_start + strlen("BODYSTRUCTURE");
- ptr = bodystructure_string = strdup(bodystructure_start);
-
- EM_DEBUG_LOG_DEV("BODYSTRUCTURE:%s", bodystructure_string);
-
- /* Parse the bodystructure string */
- p_body = mail_newbody();
- if (p_body == NULL) {
- EM_DEBUG_EXCEPTION("New body creationg failed");
- err = EMAIL_ERROR_OUT_OF_MEMORY;
- goto FINISH_OFF;
- }
-
- /* valgrind : free body->sparep */
- mail_parameters(stream, SET_FREEBODYSPAREP, emcore_free_body_sparep);
-
- /*imap_parse_body_structure changes param pointer*/
- imap_parse_body_structure(stream, p_body, (unsigned char **)&bodystructure_string, reply_from_server);
-
- /* Get the total mail size */
- if (emcore_set_fetch_body_section(p_body, true, &p_total_mail_size, NULL, &err) < 0) {
- EM_DEBUG_EXCEPTION("emcore_set_fetch_body_section failed:[%d]", err);
- goto FINISH_OFF;
- }
-
- /* Fill the content_info structure */
- if (!(p_cnt_info = em_malloc(sizeof(struct _m_content_info)))) {
- EM_DEBUG_EXCEPTION("em_malloc failed");
- err = EMAIL_ERROR_OUT_OF_MEMORY;
- goto FINISH_OFF;
- }
-
- if (emcore_get_body(stream, 0, 0, 0, p_body, NULL, p_cnt_info, &err) < 0 || !p_cnt_info) {
- EM_DEBUG_EXCEPTION("emcore_get_body failed[%d]", err);
- err = EMAIL_ERROR_IMAP4_FETCH_UID_FAILURE;
- goto FINISH_OFF;
- }
-
-FINISH_OFF:
-
- EM_SAFE_FREE(ptr);
-
- if (err != EMAIL_ERROR_NONE) {
- if (p_cnt_info) {
- emcore_free_content_info(p_cnt_info);
- EM_SAFE_FREE(p_cnt_info);
- }
- if (p_body)
- mail_free_body(&p_body);
- } else {
- *cnt_info = p_cnt_info;
- *body = p_body;
- *total_mail_size = p_total_mail_size;
- }
-
- EM_DEBUG_FUNC_END("Err:[%d]", err);
- return err;
-}
-
-INTERNAL_FUNC int emcore_update_attachment_except_inline(struct _m_content_info *cnt_info, int account_id, int mail_id, int mailbox_id, int *output_total_attachment_size, int *output_attachment_count, int *output_inline_attachment_count)
+INTERNAL_FUNC int emcore_update_attachment_except_inline(char *multi_user_name,
+ struct _m_content_info *cnt_info,
+ int account_id,
+ int mail_id,
+ int mailbox_id,
+ int *output_total_attachment_size,
+ int *output_attachment_count,
+ int *output_inline_attachment_count)
{
- EM_DEBUG_FUNC_BEGIN("cnt_info : [%p], account_id : [%d], mail_id : [%d], mailbox_id : [%d]", cnt_info, account_id, mail_id, mailbox_id);
+ EM_DEBUG_FUNC_BEGIN("cnt_info : [%p], account_id : [%d], mail_id : [%d], mailbox_id : [%d]",
+ cnt_info, account_id, mail_id, mailbox_id);
int err = EMAIL_ERROR_NONE;
if (!cnt_info || !account_id || !mail_id || !mailbox_id) {
@@ -3530,23 +3672,13 @@ INTERNAL_FUNC int emcore_update_attachment_except_inline(struct _m_content_info
attachment_tbl.mailbox_id = mailbox_id;
attachment_tbl.attachment_save_status = 0;
-#ifdef __FEATURE_USE_GMIME__
for (inline_attachment_count = 0, attach_info = cnt_info->inline_file; attach_info; attach_info = attach_info->next) {
if (attach_info->type == INLINE_ATTACHMENT) {
inline_attachment_count++;
}
}
-#endif
for (attachment_count = 0, attach_info = cnt_info->file; attach_info; attach_info = attach_info->next, attachment_count++) {
-
-#ifndef __FEATURE_USE_GMIME__
- if (attach_info->type == INLINE_ATTACHMENT) {
- EM_DEBUG_LOG("INLINE ATTACHMENT");
- inline_attachment_count++;
- continue;
- }
-#endif
total_attach_size += attach_info->size;
attachment_tbl.attachment_size = attach_info->size;
attachment_tbl.attachment_path = attach_info->save;
@@ -3558,8 +3690,7 @@ INTERNAL_FUNC int emcore_update_attachment_except_inline(struct _m_content_info
attachment_tbl.encoding = attach_info->encoding;
attachment_tbl.section = attach_info->section;
#endif
-
- if (!emstorage_add_attachment(&attachment_tbl, 0, false, &err)) {
+ if (!emstorage_add_attachment(multi_user_name, &attachment_tbl, 0, false, &err)) {
EM_DEBUG_EXCEPTION("emstorage_add_attachment failed : [%d]", err);
goto FINISH_OFF;
}
@@ -3571,11 +3702,7 @@ INTERNAL_FUNC int emcore_update_attachment_except_inline(struct _m_content_info
FINISH_OFF:
if (output_attachment_count)
-#ifdef __FEATURE_USE_GMIME__
*output_attachment_count = attachment_count;
-#else
- *output_attachment_count = attachment_count - inline_attachment_count;
-#endif
if (output_inline_attachment_count)
*output_inline_attachment_count = inline_attachment_count;
@@ -3592,850 +3719,6 @@ FINISH_OFF:
#define TEMP_STRING_LENGTH 50
#define CONTENT_TRANSFER_ENCODING_STRING "Content-Transfer-Encoding"
-static int emcore_parse_html_part_for_partial_body(char *start_header, char *boundary_string, char *bufsendforparse, char *text_html, int body_size)
-{
- EM_DEBUG_FUNC_BEGIN("start_header [%p], boundary_string [%s], bufsendforparse [%s], text_html [%s], body_size [%d]", start_header, boundary_string, bufsendforparse, text_html, body_size);
-
- int err = EMAIL_ERROR_NONE;
- int iEncodingHeader = 0;
- int enc_type = ENCOTHER, dec_len = 0;
- char EncodingHeader[40] = {0};
- char Encoding[30] = {0};
- char *pEncodingHeaderEnd = NULL;
- char *txt_html = NULL;
- char *pHeaderStart = NULL;
- char *start = NULL, *end = NULL;
- char *temp_enc1 = NULL;
-
- EM_DEBUG_LOG("Content-Type : text/html or message/rfc822 or text/rfc822-headers");
-
- if(start_header == NULL) { /*prevent 27448*/
- EM_DEBUG_EXCEPTION("start_header NULL");
- return false;
- }
-
- pHeaderStart = start_header;
- pHeaderStart = pHeaderStart-2;
- do{
- pHeaderStart--;
- } while (*pHeaderStart != LF && bufsendforparse < pHeaderStart);
-
- pHeaderStart++;
-
- /* Check string size */
- if (EM_SAFE_STRLEN(pHeaderStart) < strlen(CONTENT_TRANSFER_ENCODING_STRING)) {
- EM_DEBUG_EXCEPTION("pHeaderStart is truncated.");
- return false;
- }
-
- memcpy(EncodingHeader, pHeaderStart, strlen(CONTENT_TRANSFER_ENCODING_STRING));
-
- if (strcasecmp(EncodingHeader, CONTENT_TRANSFER_ENCODING_STRING) == 0){
- pEncodingHeaderEnd = strstr(pHeaderStart, CRLF_STRING);
-
- if ((pEncodingHeaderEnd - (pHeaderStart+27)) > 30) {
- EM_DEBUG_EXCEPTION("Encoding is too long");
- return false;
- }
- memcpy(Encoding, pHeaderStart + 27, pEncodingHeaderEnd - (pHeaderStart+27));
- iEncodingHeader = 1;
- }
-
- /* HTML Content found */
- txt_html = start_header;
- txt_html = strstr(txt_html, CRLF_STRING CRLF_STRING);
-
- if (txt_html != NULL){
- txt_html += 4; /* txt_html points at html content */
- start = txt_html;
- char multipart_boundary[MULTIPART_BOUNDARY_LENGTH] = {0};
- char *multipart_related_boundry = NULL;
- char *multipart_related_boundry_end = NULL;
-
- if (iEncodingHeader == 1)
- multipart_related_boundry = pHeaderStart;
- else
- multipart_related_boundry = start_header;
-
- multipart_related_boundry = multipart_related_boundry - 3;
- multipart_related_boundry_end = multipart_related_boundry;
-
- while (bufsendforparse < multipart_related_boundry && *multipart_related_boundry != LF && *multipart_related_boundry != NULL_CHAR)
- multipart_related_boundry -= 1;
-
- if ((multipart_related_boundry_end - multipart_related_boundry) > MULTIPART_BOUNDARY_LENGTH) {
- EM_DEBUG_EXCEPTION("Encoding is too long");
- return false;
- }
-
- memcpy(multipart_boundary, multipart_related_boundry, multipart_related_boundry_end - multipart_related_boundry);
-
- if (strcmp(multipart_boundary, boundary_string) == 0)
- end = strstr(txt_html, boundary_string);
- else
- end = strstr(txt_html, multipart_boundary);
-
- memset(multipart_boundary, 0, EM_SAFE_STRLEN(multipart_boundary));
-
- if (end == NULL) {
- EM_DEBUG_LOG("HTML body contents exceeds limited Bytes");
- end = txt_html + body_size - (txt_html - bufsendforparse);
- }
- else if(end == txt_html) { /* empty multipart */
- EM_DEBUG_LOG("Emtpy HTML multipart");
- return false;
- }
- else {
- if ((*(end-2) == CR) && (*(end-1) == LF))
- end -= 2;
- else if ((*(end-2) == CR) && (*(end-1) == LF)
- && (*(end-4) == CR) && (*(end-3) == LF))
- end -= 4;
- else
- EM_DEBUG_EXCEPTION(" Content not per as grammar.");
- }
- EM_DEBUG_LOG("iEncodingHeader [%d]", iEncodingHeader);
-
- if (iEncodingHeader == 1){
- enc_type = ENCOTHER;
- if (strncasecmp(Encoding, "base64", strlen("base64")) == 0)
- enc_type = ENCBASE64;
- else if (strncasecmp(Encoding, "quoted-printable", strlen("quoted-printable")) == 0)
- enc_type = ENCQUOTEDPRINTABLE;
-
- EM_DEBUG_LOG("enc_type [%d]", enc_type);
-
- memcpy(text_html, start, end - txt_html);
-
- if (emcore_decode_body_text(text_html, end - txt_html, enc_type , &dec_len, &err) < 0)
- EM_DEBUG_EXCEPTION("emcore_decode_body_text failed [%d]", err);
- }
- else if ((temp_enc1 = (char *)strcasestr(start_header, "Content-transfer-encoding:")) && (temp_enc1 < end)){ /*prevent 27448*/
- if (temp_enc1)
- start_header = temp_enc1;
-
- start_header += strlen(CONTENT_TRANSFER_ENCODING_STRING);
- start_header = em_skip_whitespace_without_strdup(start_header);
-
- if (!start_header)
- EM_DEBUG_EXCEPTION(" Invalid parsing ");
- else{
- enc_type = ENCOTHER;
- if (strncasecmp(start_header, "base64", strlen("base64")) == 0)
- enc_type = ENCBASE64;
- else if (strncasecmp(start_header, "quoted-printable", strlen("quoted-printable")) == 0)
- enc_type = ENCQUOTEDPRINTABLE;
-
- EM_DEBUG_LOG("enc_type [%d]", enc_type);
-
- memcpy(text_html, start, end - txt_html);
-
- if (emcore_decode_body_text(text_html, end - txt_html, enc_type , &dec_len, &err) < 0)
- EM_DEBUG_EXCEPTION("emcore_decode_body_text failed [%d]", err);
- }
-
- EM_DEBUG_LOG("Decoded length = %d", dec_len);
- }
- else{
- memcpy(text_html, start, end-txt_html);
- }
-
- /* EM_DEBUG_LOG(" Content-Type: text/html [%s]\n", text_html); */
- }
- else
- EM_DEBUG_EXCEPTION(" Invalid html body content ");
-
- EM_DEBUG_FUNC_END();
- return true;
-}
-
-
-
-/*For the following scenario
-*------= SAMSUNG_mySingle_MIME_MULTIPART_BOUNDARY
-*Content-Transfer-Encoding : base64
-*Content-Type : text/plain; charset = "windows-1252"
-*MIME-Version : 1.0
-*Message-ID: <11512468.945901271910226702.JavaMail.weblogic@epml03>
-*/
-
-#define CONTENT_TRANSFER_ENCODING "Content-Transfer-Encoding"
-
-static int emcore_parse_plain_part_for_partial_body(char *header_start_string, char *start_header, char *boundary_string, char *bufsendforparse, char *text_plain, int body_size)
-{
- EM_DEBUG_FUNC_BEGIN("header_start_string[%p], start_header[%p], boundary_string [%p], bufsendforparse [%p], text_plain [%p]", header_start_string, start_header, boundary_string, bufsendforparse, text_plain);
- int err = EMAIL_ERROR_NONE, iEncodingHeader = 0, enc_type = ENCOTHER;
- int dec_len = 0, strcmpret = -1;
- char *pHeaderStart = NULL, *pEncodingHeaderEnd = NULL;
- char EncodingHeader[40] = {0, };
- char Encoding[30] = {0, };
- char *start = NULL, *end = NULL, *txt_plain = NULL, *temp_enc1 = NULL;
-
- EM_DEBUG_LOG("Content-Type : text/plain");
-
- pHeaderStart = header_start_string;
-
- memcpy(EncodingHeader, pHeaderStart, 25);
-
- if (strcasecmp(EncodingHeader, CONTENT_TRANSFER_ENCODING_STRING) == 0){
- pEncodingHeaderEnd = strstr(pHeaderStart, CRLF_STRING);
- memcpy(Encoding, pHeaderStart + 27, pEncodingHeaderEnd - (pHeaderStart + 27));
- iEncodingHeader = 1;
- }
-
- /* Plain text content found */
- if(!start_header) { /*prevent 27450*/
- EM_DEBUG_EXCEPTION("start_header NULL");
- return false;
- }
- txt_plain = start_header;
- txt_plain = strstr(txt_plain, CRLF_STRING CRLF_STRING);
-
- if (txt_plain != NULL){
- txt_plain += EM_SAFE_STRLEN(CRLF_STRING CRLF_STRING); /* txt_plain points at plain text content */
-
- /* Fix is done for mail having "Content-Type: text/plain" but there is no content but having only attachment. */
-
- strcmpret = strncmp(txt_plain, boundary_string, EM_SAFE_STRLEN(boundary_string));
- if (strcmpret == 0){
- }
- else{
- start = txt_plain;
- end = strstr(txt_plain, boundary_string);
-
- if (end == NULL){
- EM_DEBUG_LOG("Text body contents exceeds limited Bytes");
- end = txt_plain + body_size - (txt_plain - bufsendforparse);
- }
- else{
- /* EM_DEBUG_LOG("pbd_event[temp_count].partial_body_complete - %d", partial_body_complete); */
-
- if ((*(end-2) == CR) && (*(end-1) == LF))
- end -= 2;
- else if ((*(end-2) == CR) && (*(end-1) == LF)
- && (*(end-4) == CR) && (*(end-3) == LF))
- end -= 4;
- else
- EM_DEBUG_EXCEPTION(" Content not per as grammar.");
- }
-
- if (iEncodingHeader == 1){
- enc_type = ENCOTHER;
- if (strncasecmp(Encoding, "base64", strlen("base64")) == 0)
- enc_type = ENCBASE64;
- else if (strncasecmp(Encoding, "quoted-printable", strlen("quoted-printable")) == 0)
- enc_type = ENCQUOTEDPRINTABLE;
-
- EM_DEBUG_LOG("enc_type [%d]", enc_type);
-
- memcpy(text_plain, start, end - txt_plain);
-
- if (emcore_decode_body_text(text_plain, end - txt_plain, enc_type , &dec_len, &err) < 0)
- EM_DEBUG_EXCEPTION("emcore_decode_body_text failed [%d]", err);
- }
- else if (start_header && ((temp_enc1 = (char *)strcasestr(start_header, "Content-transfer-encoding:")) != NULL) && !(temp_enc1 && temp_enc1 >= end)){
- if (temp_enc1)
- start_header = temp_enc1;
-
- start_header += strlen(CONTENT_TRANSFER_ENCODING_STRING);
- start_header = em_skip_whitespace_without_strdup(start_header);
-
- if (!start_header)
- EM_DEBUG_EXCEPTION(" Invalid parsing ");
- else{
- enc_type = ENCOTHER;
- if (strncasecmp(start_header, "base64", strlen("base64")) == 0)
- enc_type = ENCBASE64;
- else if (strncasecmp(start_header, "quoted-printable", strlen("quoted-printable")) == 0)
- enc_type = ENCQUOTEDPRINTABLE;
-
- EM_DEBUG_LOG("enc_type [%d]", enc_type);
- memcpy(text_plain, start, end - txt_plain);
- if (emcore_decode_body_text(text_plain, end - txt_plain, enc_type , &dec_len, &err) < 0)
- EM_DEBUG_EXCEPTION("emcore_decode_body_text failed [%d]", err);
- }
-
- EM_DEBUG_LOG("Decoded length = %d", dec_len);
- /* EM_DEBUG_LOG("start - %s", start); */ /* print raw MIME content. */
- }
- else
- memcpy(text_plain, start, end-txt_plain);
-
- /* EM_DEBUG_LOG(" Content-type: text/plain [%s]\n", text_plain); */
- }
- }
- else
- EM_DEBUG_EXCEPTION(" Invalid text body content ");
-
- EM_DEBUG_FUNC_END();
- return 1;
-}
-
-
-
-/* Content-Type: IMAGE/octet-stream; name = Default.png */
-/* Content-Transfer-Encoding: BASE64 */
-/* Content-ID: <4b0d6810b17291f9438783a8eb9d5228@org.tizen.email> */
-/* Content-Disposition: inline; filename = Default.png */
-
-static void emcore_free_email_image_data(email_image_data **image_data, int count)
-{
- EM_DEBUG_FUNC_BEGIN("image_data : [%p], count : [%d]", image_data, count);
-
- if ((image_data == NULL) || (*image_data == NULL) || (count <= 0)) {
- EM_DEBUG_EXCEPTION("Invalid paramter");
- return;
- }
-
- email_image_data *p = *image_data;
- int i = 0;
-
- for (i = 0; i < count; i++) {
- EM_SAFE_FREE(p[i].image_file_name);
- EM_SAFE_FREE(p[i].text_image);
- EM_SAFE_FREE(p[i].content_id);
- EM_SAFE_FREE(p[i].mime_type);
- }
-
- EM_SAFE_FREE(p);
- *image_data = NULL;
-
- EM_DEBUG_FUNC_END();
-}
-
-static int emcore_parse_image_part_for_partial_body(char *header_start_string, char *start_header, char *boundary_string, char *bufsendforparse, email_image_data *image_data, int body_size)
-{
- EM_DEBUG_FUNC_BEGIN("boundary_string : [%s]", boundary_string);
-
- int err = EMAIL_ERROR_NONE;
- char *multiple_image = NULL;
- int donot_parse_next_image = 0;
- char *image_boundary = NULL;
- char *image_boundary_end = NULL;
- char *temp_image_boundary = NULL;
- int i = 0, ch_image = 0;
- int enc_type = ENCOTHER;
- char *p = header_start_string;
- char *start = NULL, *end = NULL, *txt_image = NULL;
- char *temp_image = NULL;
- char *temp_cid1 = NULL;
- char *cid_end = NULL;
- char *temp_enc1 = NULL;
- char *p_boundary_string = NULL;
-
- if(image_data == NULL) {
- EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
- err = EMAIL_ERROR_INVALID_PARAM;
- return false;
- }
-
- image_boundary = start_header;
- image_boundary_end = image_boundary - 2;
- image_boundary = image_boundary - 2;
-
- EM_DEBUG_LOG("Content-type: image");
-
- while (bufsendforparse < image_boundary && image_boundary && *image_boundary != LF)
- image_boundary--;
-
- image_boundary++;
-
- temp_image_boundary = em_malloc((image_boundary_end - image_boundary) + 1);
- if (temp_image_boundary == NULL) {
- EM_DEBUG_EXCEPTION("em_malloc failed");
- err = EMAIL_ERROR_OUT_OF_MEMORY;
- return false;
- }
-
- if (image_boundary != NULL && image_boundary_end != NULL)
- memcpy(temp_image_boundary, image_boundary, image_boundary_end-image_boundary);
-
-
- if (((char *)strcasestr((const char *)temp_image_boundary, "Content-type:") == NULL) && (temp_image_boundary[0] == '-'))
- p_boundary_string = strdup(temp_image_boundary);
- else
- p_boundary_string = EM_SAFE_STRDUP(boundary_string);
-
- EM_SAFE_FREE(temp_image_boundary);
-
- do {
- if (multiple_image != NULL){
- p = multiple_image;
- start_header = multiple_image;
- }
-
- emcore_get_content_type_from_mime_string(start_header, &(image_data[i].mime_type));
- EM_DEBUG_LOG("image_data[i].mime_type : [%s]", image_data[i].mime_type);
-
- if ((strcasestr(p, "Content-Disposition: attachment")) || (!strcasestr(p, "Content-ID: <"))) {
- EM_DEBUG_LOG("Body has attachment no need to parse ");
- end = NULL;
- multiple_image = NULL;
- }
- else { /* HTML Content found */
- ch_image = 0;
- char *cid = NULL;
- char *temp_name = NULL;
- char *decoded_filename = NULL;
-
- image_data[i].image_file_name = NULL;
-
- if(!start_header) { /*prevent 27449*/
- EM_DEBUG_EXCEPTION("start_header NULL");
- EM_SAFE_FREE(p_boundary_string);
- return false;
- }
-
- txt_image = start_header;
- temp_image = start_header;
-
- temp_name = strstr(txt_image, "name=");
- if (temp_name != NULL){
- temp_image = temp_name;
- if (*(temp_image + 5) == '"') {
- temp_image = temp_image + 6;
- temp_name = temp_name + 6 ;
- } else {
- temp_image = temp_image + 5;
- temp_name = temp_name + 5;
- }
-
- while (*temp_image != CR){
- temp_image++;
- ch_image++;
- }
-
- if (ch_image > 0) {
- image_data[i].image_file_name = em_malloc(ch_image+3);
- if (image_data[i].image_file_name == NULL) {
- EM_DEBUG_EXCEPTION("em_malloc failed");
- EM_SAFE_FREE(p_boundary_string);
- return false;
- }
- if (*(temp_image - 1) == '"') {
- memcpy(image_data[i].image_file_name, temp_name, ch_image - 2);
- } else {
- memcpy(image_data[i].image_file_name, temp_name, ch_image);
- }
- }
-
- decoded_filename = emcore_decode_rfc2047_text(image_data[i].image_file_name, &err);
- if(decoded_filename) {
- memset(image_data[i].image_file_name, 0, ch_image);
- memcpy(image_data[i].image_file_name, decoded_filename, EM_SAFE_STRLEN(decoded_filename));
- EM_SAFE_FREE(decoded_filename);
- }
- }
-
- if (((temp_cid1 = (char *)strcasestr((const char *)start_header, "Content-ID: <")) != NULL)){
- if (temp_cid1) {
- cid = temp_cid1;
- temp_image = temp_cid1;
- }
-
- cid += 13;
- cid_end = strstr(temp_image, "\076"); /* 076 == '>' */
-
- image_data[i].content_id = (char *)em_malloc(cid_end-cid+5);
- if (image_data[i].content_id != NULL){
- strcpy(image_data[i].content_id, "cid:");
- memcpy(image_data[i].content_id+4, cid, cid_end-cid);
- }
- else
- EM_DEBUG_EXCEPTION("em_malloc() failed");
-
- if (image_data[i].image_file_name == NULL) {
- image_data[i].image_file_name = em_malloc((cid_end - cid) + 1);
- if (image_data[i].image_file_name == NULL) {
- EM_DEBUG_EXCEPTION("em_malloc failed");
- EM_SAFE_FREE(p_boundary_string);
- return false;
- }
- memcpy(image_data[i].image_file_name, cid, cid_end - cid);
- }
- }
-
- txt_image = strstr(txt_image, CRLF_STRING CRLF_STRING);
-
- if (txt_image != NULL){
- txt_image += 4; /* txt_image points at image content */
- start = txt_image;
-
- if (p_boundary_string)
- end = strstr(txt_image, p_boundary_string);
-
- if (end == NULL){
- EM_DEBUG_LOG("HTML body contents exceeds limited Bytes");
- /* end points to end of partial body data */
- end = txt_image + body_size - (txt_image-bufsendforparse);
- }
- else{
- EM_DEBUG_LOG("This image is fully downloaded");
- end -= 2;
- image_data[i].fully_downloaded = 1;
- }
-
- if ((temp_enc1 = (char *)strcasestr((const char *)start_header, "Content-transfer-encoding:")) != NULL){ /*prevent 27449*/
- if (temp_enc1)
- start_header = temp_enc1;
-
- start_header += strlen(CONTENT_TRANSFER_ENCODING_STRING);
- start_header = em_skip_whitespace_without_strdup(start_header);
-
- if (!start_header)
- EM_DEBUG_EXCEPTION(" Invalid parsing ");
- else{
- enc_type = ENCOTHER;
- if (strncasecmp(start_header, "base64", strlen("base64")) == 0)
- enc_type = ENCBASE64;
- else if (strncasecmp(start_header, "quoted-printable", strlen("quoted-printable")) == 0)
- enc_type = ENCQUOTEDPRINTABLE;
-
- EM_DEBUG_LOG("enc_type [%d]", enc_type);
-
- image_data[i].text_image = (char *)em_malloc((end-txt_image)+1);
- if (image_data[i].text_image){
- memcpy(image_data[i].text_image, start, end-txt_image);
- if (emcore_decode_body_text(image_data[i].text_image, end-txt_image, enc_type , &(image_data[i].dec_len), &err) < 0)
- EM_DEBUG_EXCEPTION("emcore_decode_body_text failed [%d]", err);
- }
- else
- EM_DEBUG_EXCEPTION("em_malloc() failed");
- }
-
- EM_DEBUG_LOG("Decoded length [%d]", image_data[i].dec_len);
- }
- else{
- image_data[i].text_image = (char *)em_malloc(end-txt_image);
- if (image_data[i].text_image)
- memcpy(image_data[i].text_image, start, end - txt_image);
- else
- EM_DEBUG_EXCEPTION("em_malloc() failed");
- }
- }
- else{
- donot_parse_next_image = 1;
- EM_DEBUG_EXCEPTION(" Invalid html body content ");
- }
- }
-
- if (end != NULL) {
- multiple_image = (char *)strcasestr((const char *)end, "Content-type: image");
- i++;
- }
- } while (multiple_image != NULL && donot_parse_next_image != 1 && (i < IMAGE_DISPLAY_PARTIAL_BODY_COUNT));
-
- EM_SAFE_FREE(p_boundary_string);
-
- EM_DEBUG_FUNC_END();
- return 1;
-}
-
-static int emcore_find_boundary_string_of_the_part(const char *whole_string, const char *first_line_of_part, char **result_boundary_string, int *error)
-{
- EM_DEBUG_FUNC_BEGIN("whole_string[%p], first_line_of_part[%p], result_boundary_string[%p]", whole_string, first_line_of_part, result_boundary_string);
- int ret = false, err = EMAIL_ERROR_NONE;
- char *boundary_cur = NULL, *boundary_end = NULL, *boundary_string = NULL;
-
- if(!whole_string || !first_line_of_part || !result_boundary_string) {
- EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
- err = EMAIL_ERROR_INVALID_PARAM;
- goto FINISH_OFF;
- }
-
- if(first_line_of_part - 2 > whole_string) {
- boundary_cur = (char*)first_line_of_part - 2; /* 2 means CRLF. */
- boundary_end = boundary_cur;
-
- do{
- boundary_cur--;
- } while (whole_string <= boundary_cur && *boundary_cur != LF && *boundary_cur != NULL_CHAR);
-
- boundary_cur++;
-
- if(boundary_end > boundary_cur && boundary_cur >= whole_string) {
-
- boundary_string = em_malloc(boundary_end - boundary_cur + 15);
- if(!boundary_string) {
- EM_DEBUG_EXCEPTION("em_malloc failed");
- err = EMAIL_ERROR_OUT_OF_MEMORY;
- goto FINISH_OFF;
- }
- memcpy(boundary_string, boundary_cur, boundary_end - boundary_cur);
- EM_DEBUG_LOG("boundary_string [%s]", boundary_string);
- *result_boundary_string = boundary_string;
- }
- else {
- EM_DEBUG_EXCEPTION("There is no string before the part");
- err = EMAIL_ERROR_ON_PARSING;
- goto FINISH_OFF;
- }
- }
- else {
- EM_DEBUG_EXCEPTION("There is no string before the part");
- err = EMAIL_ERROR_ON_PARSING;
- goto FINISH_OFF;
- }
- ret = true;
-FINISH_OFF:
-
- if(error)
- *error = err;
-
- EM_DEBUG_FUNC_END("ret[%d], err[%d]", ret, err);
- return ret;
-}
-
-static int emcore_parse_body_for_imap(char *body_str, int body_size, struct _m_content_info *cnt_info, int encoding_type, char **output_text_plain, char **output_text_html, email_image_data **output_image_data)
-{
- EM_DEBUG_FUNC_BEGIN("body_str:[%p], cnt_info:[%p], encoding_type:[%d]", body_str, cnt_info, encoding_type);
- int err = EMAIL_ERROR_NONE;
-
- if (!body_str || strlen(body_str) == 0 || !cnt_info) {
- EM_DEBUG_EXCEPTION("Invalid paramter");
- err = EMAIL_ERROR_INVALID_PARAM;
- return err;
- }
-
- if (!output_text_plain || !output_text_html || !output_image_data) {
- EM_DEBUG_EXCEPTION("Invalid parameter");
- err = EMAIL_ERROR_INVALID_PARAM;
- return err;
- }
-
- int dec_len = 0;
- int no_alternative_part_flag = 0;
- int no_html = 0;
- char *boundary_start = NULL;
- char *boundary_end = NULL;
- char *boundary_string = NULL;
- char *p_body_str = NULL;
- char *start_header = NULL;
- char *text_plain = NULL;
- char *text_html = NULL;
- email_image_data *image_data = NULL;
-
- char *temp_alternative_plain_header = NULL;
- char *temp_content_type = NULL;
-
- char *local_encoding_str = NULL;
- char *local_boundary_str = NULL;
- char *local_body_str = NULL;
-
- p_body_str = g_strdup(body_str);
-
- text_plain = em_malloc(body_size + 1);
- text_html = em_malloc(body_size + 1);
-
- if (!text_plain || !text_html) {
- EM_DEBUG_EXCEPTION("em_malloc failed");
- err = EMAIL_ERROR_OUT_OF_MEMORY;
- goto FINISH_OFF;
- }
-
- if ((cnt_info->text.plain && cnt_info->text.html) || cnt_info->file) {
- /* Start multipart parsing */
- /* Partial body has headers with Content-Type: text/html or Content-Type: text/plain */
- no_alternative_part_flag = 0;
- if (((temp_alternative_plain_header = (char *)strcasestr(p_body_str, "Content-type: multipart/alternative")) != NULL)) { /* Found 'alternative' */
- if (((temp_content_type = (char *)strcasestr(p_body_str, "Content-type: text/plain")) != NULL)) {
- if (temp_content_type < temp_alternative_plain_header) {
- /* This part is text/plain not alternative. */
- no_html = 1;
- no_alternative_part_flag = 1;
- } else {
- EM_DEBUG_LOG(" Content-type: multipart/alternative ");
- boundary_start = strstr(temp_alternative_plain_header, "--");
- if(!boundary_start) { /*prevent 37946 */
- err = EMAIL_ERROR_INVALID_DATA;
- goto FINISH_OFF;
- }
- boundary_end = strcasestr(boundary_start, "Content-type:");
- if(!boundary_end) { /*prevent 37946 */
- err = EMAIL_ERROR_INVALID_DATA;
- goto FINISH_OFF;
- }
-
- boundary_string = em_malloc(boundary_end - (boundary_start + strlen("--")));
- if (boundary_string == NULL) {
- EM_DEBUG_EXCEPTION("em_malloc failed");
- err = EMAIL_ERROR_OUT_OF_MEMORY;
- goto FINISH_OFF;
- }
-
- memcpy(boundary_string, boundary_start, boundary_end - (boundary_start + strlen("--")));
- }
- }
- } else
- no_alternative_part_flag = 1;
-
- if (no_alternative_part_flag) {
- boundary_start = strstr(p_body_str, "--");
- if(!boundary_start) { /*prevent 37946 */
- err = EMAIL_ERROR_INVALID_DATA;
- goto FINISH_OFF;
- }
- boundary_end = strcasestr(boundary_start, "\r\n");
- if(!boundary_end) { /*prevent 37946 */
- err = EMAIL_ERROR_INVALID_DATA;
- goto FINISH_OFF;
- }
-
- boundary_string = em_malloc(boundary_end - (boundary_start + strlen("--")));
- if (boundary_string == NULL) {
- EM_DEBUG_EXCEPTION("em_malloc failed");
- err = EMAIL_ERROR_OUT_OF_MEMORY;
- goto FINISH_OFF;
- }
-
- memcpy(boundary_string, boundary_start, boundary_end - (boundary_start + strlen("--")));
- }
-
- if (boundary_string && boundary_end) { /*prevent 37946 */
- /* EM_DEBUG_LOG("boundary_string : [%s]", boundary_string); */
-
- if (((start_header = (char *)strcasestr(boundary_end, "Content-Type: text/html")) != NULL) && (no_html != 1) &&(((char *)strcasestr(boundary_end, "Content-Type: message/rfc822")) == NULL) &&
- (((char *)strcasestr(boundary_end, "Content-Type: text/rfc822-headers")) == NULL))
- emcore_parse_html_part_for_partial_body(start_header, boundary_string, p_body_str, text_html, body_size);
-
- if (((start_header = (char *)strcasestr(boundary_end, "Content-Type: text/plain")) != NULL)) {
- char *internal_boundary_string = NULL;
-
- if(!emcore_find_boundary_string_of_the_part(p_body_str, start_header, &internal_boundary_string, &err)) {
- EM_DEBUG_EXCEPTION("internal_boundary_string failed [%d]", err);
- }
-
- if(!internal_boundary_string)
- internal_boundary_string = EM_SAFE_STRDUP(boundary_string);
-
- emcore_parse_plain_part_for_partial_body(boundary_end, start_header, internal_boundary_string, p_body_str, text_plain, body_size);
- EM_SAFE_FREE(internal_boundary_string);
- }
-
- if (((start_header = (char *)strcasestr((const char *)boundary_end, "Content-type: image/jpeg")) != (char *)NULL) ||
- ((start_header = (char *)strcasestr((const char *)boundary_end, "Content-Type: image/jpg")) != (char *)NULL) ||
- ((start_header = (char *)strcasestr((const char *)boundary_end, "Content-Type: image/gif")) != (char *)NULL) ||
- ((start_header = (char *)strcasestr((const char *)boundary_end, "Content-Type: image/bmp")) != (char *)NULL) ||
- ((start_header = (char *)strcasestr((const char *)boundary_end, "Content-Type: image/png")) != (char *)NULL)) {
- image_data = em_malloc(sizeof(email_image_data) * IMAGE_DISPLAY_PARTIAL_BODY_COUNT);
- if (image_data == NULL) {
- EM_DEBUG_EXCEPTION("em_malloc failed");
- err = EMAIL_ERROR_OUT_OF_MEMORY;
- goto FINISH_OFF;
- }
- emcore_parse_image_part_for_partial_body(boundary_end, start_header, boundary_string, p_body_str, image_data, body_size);
- }
- }
- }
- else {
- /* Encoded Content-Type: text/html or Content-Type: text/plain */
- /* No Partial body has No headers with Content-Type: text/html or Content-Type: text/plain */
- char *start_of_body = NULL;
- char *end_of_body = NULL;
- char *local_encoding = NULL;
- char *local_encoding_end = NULL;
- char *local_boundary_end = NULL;
- int local_encoding_len = 0;
- int local_boundary_len = 0;
- int enc_type = encoding_type;
- EM_DEBUG_LOG_DEV("mbody->encoding [%d] ", enc_type);
-
- if (EM_SAFE_STRLEN(p_body_str) > 2 && p_body_str[0] == '-' && p_body_str[1] == '-') {
-
- local_boundary_end = strstr(p_body_str, "\r\n");
- if (local_boundary_end) {
- local_boundary_len = local_boundary_end - p_body_str;
- local_boundary_str = em_malloc(local_boundary_len + 2);
- memcpy(local_boundary_str, p_body_str+2, local_boundary_len-2);
- EM_DEBUG_LOG_DEV("local_boundary_str : %s", local_boundary_str);
- end_of_body = strstr(local_boundary_end, local_boundary_str);
- if (end_of_body) end_of_body -= 2;
- }
-
- local_encoding = strcasestr(p_body_str, "Content-Transfer-Encoding: ");
- if (local_encoding) {
- local_encoding_end = strstr(local_encoding, "\r\n");
-
- if (local_encoding && (local_encoding_end > local_encoding)) {
- local_encoding_len = local_encoding_end - local_encoding;
- local_encoding_str = em_malloc(local_encoding_len + 2);
- if (local_encoding_str == NULL) {
- EM_DEBUG_EXCEPTION("em_malloc failed");
- err = EMAIL_ERROR_OUT_OF_MEMORY;
- goto FINISH_OFF;
- }
-
- if (local_encoding_str) {
- memcpy(local_encoding_str, local_encoding + EM_SAFE_STRLEN("Content-Transfer-Encoding: "), local_encoding_len);
-
- enc_type = ENCOTHER;
- if (strncasecmp(local_encoding_str, "base64", strlen("base64")) == 0)
- enc_type = ENCBASE64;
- else if (strncasecmp(local_encoding_str, "quoted-printable", strlen("quoted-printable")) == 0)
- enc_type = ENCQUOTEDPRINTABLE;
-
- EM_DEBUG_LOG_DEV("local enc_type [%d]", enc_type);
- }
- }
- }
-
- start_of_body = strstr(p_body_str, "\r\n\r\n");
- if (start_of_body) {
- start_of_body = start_of_body+strlen("\r\n\r\n");
- if (end_of_body && (end_of_body > start_of_body)) {
- local_body_str = em_malloc(end_of_body - start_of_body + 2);
- memcpy(local_body_str, start_of_body, end_of_body - start_of_body);
- } else {
- local_body_str = EM_SAFE_STRDUP(start_of_body);
- }
- }
- }
-
- if (!local_body_str)
- local_body_str = g_strdup(p_body_str);
-
- if (emcore_decode_body_text(local_body_str, EM_SAFE_STRLEN(local_body_str), enc_type, &dec_len, &err) < 0) {
- EM_DEBUG_EXCEPTION("emcore_decode_body_text failed [%d]", err);
- goto FINISH_OFF;
- }
-
- EM_DEBUG_LOG("Decoded length [%d]", dec_len);
-
- if (dec_len > 0) {
- if (cnt_info->text.plain) {
- memcpy(text_plain, local_body_str, dec_len);
- }
-
- if (cnt_info->text.html) {
- memcpy(text_html, local_body_str, dec_len);
- }
- }
- }
-
-FINISH_OFF:
-
- EM_SAFE_FREE(p_body_str);
- EM_SAFE_FREE(boundary_string);
- EM_SAFE_FREE(local_boundary_str);
- EM_SAFE_FREE(local_encoding_str);
- EM_SAFE_FREE(local_body_str);
-
- if (err != EMAIL_ERROR_NONE) {
- EM_SAFE_FREE(text_plain);
- EM_SAFE_FREE(text_html);
-
- if (image_data)
- emcore_free_email_image_data(&image_data, IMAGE_DISPLAY_PARTIAL_BODY_COUNT);
- } else {
- *output_text_plain = text_plain;
- *output_text_html = text_html;
- *output_image_data = image_data;
- }
-
- EM_DEBUG_FUNC_END("err : [%d]", err);
- return err;
-}
-
#define TAG_LENGTH 16
#define COMMAND_LENGTH 2000
static int emcore_gmime_download_imap_partial_mail_body(MAILSTREAM *stream, int input_download_size, email_event_partial_body_thd *pbd_event, int item_count, int *error)
@@ -4448,7 +3731,8 @@ static int emcore_gmime_download_imap_partial_mail_body(MAILSTREAM *stream, int
int total_mail_size = 0, total_attachment_size = 0;
int temp_count = 0, attachment_num = 0, inline_attachment_num = 0;
int inline_download_count = 0;
- char buf[512] = {0, };
+ char path_buf[512] = {0,};
+ char move_buf[512] = {0,};
char uid_range_string_to_be_downloaded[UID_RANGE_STRING_LENGTH] = {0,};
char imap_tag[TAG_LENGTH] = {0, };
char command[COMMAND_LENGTH] = {0, };
@@ -4459,6 +3743,7 @@ static int emcore_gmime_download_imap_partial_mail_body(MAILSTREAM *stream, int
IMAPLOCAL *imaplocal = NULL;
IMAPPARSEDREPLY *reply_from_server = NULL;
emstorage_mail_tbl_t *mail = NULL;
+ emstorage_mailbox_tbl_t *mailbox_tbl = NULL;
email_partial_buffer *imap_response = NULL;
BODY *body = NULL;
struct _m_content_info *cnt_info = NULL;
@@ -4555,12 +3840,22 @@ static int emcore_gmime_download_imap_partial_mail_body(MAILSTREAM *stream, int
/* Check the body download status and body size */
SNPRINTF(uid_string, sizeof(uid_string), "%ld", imap_response[i].uid_no);
- if (!emstorage_get_maildata_by_servermailid(pbd_event[temp_count].mailbox_id, uid_string, &mail, true, &err) || !mail) {
+ if (!emstorage_get_maildata_by_servermailid(pbd_event[temp_count].multi_user_name,
+ uid_string,
+ pbd_event[temp_count].mailbox_id,
+ &mail,
+ false,
+ &err) || !mail) {
EM_DEBUG_EXCEPTION("emstorage_get_mail_data_by_servermailid failed : [%d]", err);
if (err == EMAIL_ERROR_MAIL_NOT_FOUND || !mail)
goto FINISH_OFF;
}
+ if (mailbox_tbl) {
+ emstorage_free_mailbox(&mailbox_tbl, 1, NULL);
+ mailbox_tbl = NULL;
+ }
+
if (mail->body_download_status & EMAIL_BODY_DOWNLOAD_STATUS_FULLY_DOWNLOADED) {
EM_DEBUG_LOG("Downloaded mail");
continue;
@@ -4617,6 +3912,11 @@ static int emcore_gmime_download_imap_partial_mail_body(MAILSTREAM *stream, int
message1 = g_mime_parser_construct_message(parser1);
if (parser1) g_object_unref(parser1);
+ if (message1 == NULL) {
+ EM_DEBUG_LOG("message1 is NULL");
+ continue;
+ }
+
/* message1 is multipart? */
if (GMIME_IS_MULTIPART (message1->mime_part)) {
@@ -4726,6 +4026,7 @@ static int emcore_gmime_download_imap_partial_mail_body(MAILSTREAM *stream, int
message2 = NULL;
}
+
if (g_strrstr(g_mime_message_get_sender(message1), "mmsc.plusnet.pl") != NULL ||
g_strrstr(g_mime_message_get_sender(message1), "mms.t-mobile.pl") != NULL) {
cnt_info->attachment_only = 1;
@@ -4733,6 +4034,7 @@ static int emcore_gmime_download_imap_partial_mail_body(MAILSTREAM *stream, int
g_mime_message_foreach(message1, emcore_gmime_imap_parse_foreach_cb, (gpointer)cnt_info);
+
} else if (GMIME_IS_PART (message1->mime_part)) {
GMimeDataWrapper *content = NULL;
GMimePart *single_part = GMIME_PART(message1->mime_part);
@@ -4761,7 +4063,12 @@ static int emcore_gmime_download_imap_partial_mail_body(MAILSTREAM *stream, int
}
if (!strcasecmp(body->subtype, "pkcs7-mime")) {
- if (emcore_get_attribute_value_of_body_part(body->parameter, "PROTOCOL", rfc822_protocol, TEMP_STRING_LENGTH, false, &err)) {
+ if (emcore_get_attribute_value_of_body_part(body->parameter,
+ "PROTOCOL",
+ rfc822_protocol,
+ TEMP_STRING_LENGTH,
+ false,
+ &err)) {
if (strcasestr(rfc822_protocol, "enveloped-data"))
mail->smime_type = EMAIL_SMIME_ENCRYPTED;
else
@@ -4770,11 +4077,21 @@ static int emcore_gmime_download_imap_partial_mail_body(MAILSTREAM *stream, int
} else if (!strcasecmp(body->subtype, "encrypted")) {
mail->smime_type = EMAIL_PGP_ENCRYPTED;
} else if (!strcasecmp(body->subtype, "signed")) {
- if (emcore_get_attribute_value_of_body_part(body->parameter, "MICALG", rfc822_micalg, TEMP_STRING_LENGTH, false, &err)) {
+ if (emcore_get_attribute_value_of_body_part(body->parameter,
+ "MICALG",
+ rfc822_micalg,
+ TEMP_STRING_LENGTH,
+ false,
+ &err)) {
mail->digest_type = emcore_get_digest_type(rfc822_micalg);
}
- if (emcore_get_attribute_value_of_body_part(body->parameter, "PROTOCOL", rfc822_protocol, TEMP_STRING_LENGTH, false, &err)) {
+ if (emcore_get_attribute_value_of_body_part(body->parameter,
+ "PROTOCOL",
+ rfc822_protocol,
+ TEMP_STRING_LENGTH,
+ false,
+ &err)) {
if (strcasestr(rfc822_protocol, "pkcs7-signature"))
mail->smime_type = EMAIL_SMIME_SIGNED;
else
@@ -4795,9 +4112,14 @@ static int emcore_gmime_download_imap_partial_mail_body(MAILSTREAM *stream, int
}
/* Update the attachment info except inline attachment */
- if ((err = emcore_update_attachment_except_inline(cnt_info, pbd_event[temp_count].account_id,
- mail->mail_id, pbd_event[temp_count].mailbox_id, &total_attachment_size,
- &attachment_num, &inline_attachment_num)) != EMAIL_ERROR_NONE) {
+ if ((err = emcore_update_attachment_except_inline(pbd_event[temp_count].multi_user_name,
+ cnt_info,
+ pbd_event[temp_count].account_id,
+ mail->mail_id,
+ pbd_event[temp_count].mailbox_id,
+ &total_attachment_size,
+ &attachment_num,
+ &inline_attachment_num)) != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("emcore_update_attachment_except_inline failed : [%d]", err);
goto FINISH_OFF;
}
@@ -4814,7 +4136,8 @@ static int emcore_gmime_download_imap_partial_mail_body(MAILSTREAM *stream, int
/* text/plain */
if (cnt_info->text.plain) {
char *charset_plain_text = NULL;
- memset(buf, 0x00, sizeof(buf));
+ memset(path_buf, 0x00, sizeof(path_buf));
+ memset(move_buf, 0x00, sizeof(move_buf));
if (cnt_info->text.plain_charset)
charset_plain_text = cnt_info->text.plain_charset;
@@ -4826,25 +4149,38 @@ static int emcore_gmime_download_imap_partial_mail_body(MAILSTREAM *stream, int
}
}
- if (!emstorage_create_dir(pbd_event[temp_count].account_id, mail->mail_id, 0, &err))
+ if (!emstorage_create_dir(pbd_event[temp_count].multi_user_name,
+ pbd_event[temp_count].account_id,
+ mail->mail_id,
+ 0,
+ &err))
EM_DEBUG_EXCEPTION("emstorage_create_dir failed [%d]", err);
- if (!emstorage_get_save_name(pbd_event[temp_count].account_id, mail->mail_id, 0, charset_plain_text, buf, sizeof(buf), &err))
+ if (!emstorage_get_save_name(pbd_event[temp_count].multi_user_name,
+ pbd_event[temp_count].account_id,
+ mail->mail_id,
+ 0,
+ charset_plain_text,
+ move_buf,
+ path_buf,
+ sizeof(path_buf),
+ &err))
EM_DEBUG_EXCEPTION("emstorage_get_save_name failed [%d]", err);
- if (!emstorage_move_file(cnt_info->text.plain, buf, false, &err)) {
+ if (!emstorage_move_file(cnt_info->text.plain, move_buf, false, &err)) {
EM_DEBUG_EXCEPTION("emstorage_move_file failed [%d]", err);
mail->file_path_plain = NULL;
}
else
- mail->file_path_plain = EM_SAFE_STRDUP(buf);
+ mail->file_path_plain = EM_SAFE_STRDUP(path_buf);
EM_DEBUG_LOG_SEC("mail->file_path_plain [%s]", mail->file_path_plain);
}
/* text/html */
if (cnt_info->text.html) {
char *charset_html_text = NULL;
- memset(buf, 0x00, sizeof(buf));
+ memset(path_buf, 0x00, sizeof(path_buf));
+ memset(move_buf, 0x00, sizeof(move_buf));
if (cnt_info->text.html_charset)
charset_html_text = cnt_info->text.html_charset;
@@ -4858,21 +4194,64 @@ static int emcore_gmime_download_imap_partial_mail_body(MAILSTREAM *stream, int
charset_html_text = g_strconcat(charset_html_text, HTML_EXTENSION_STRING, NULL);
- if (!emstorage_create_dir(pbd_event[temp_count].account_id, mail->mail_id, 0, &err))
+ if (!emstorage_create_dir(pbd_event[temp_count].multi_user_name,
+ pbd_event[temp_count].account_id,
+ mail->mail_id,
+ 0,
+ &err))
EM_DEBUG_EXCEPTION("emstorage_create_dir failed [%d]", err);
- if (!emstorage_get_save_name(pbd_event[temp_count].account_id, mail->mail_id, 0, charset_html_text, buf, sizeof(buf), &err))
+ if (!emstorage_get_save_name(pbd_event[temp_count].multi_user_name,
+ pbd_event[temp_count].account_id,
+ mail->mail_id,
+ 0,
+ charset_html_text,
+ move_buf,
+ path_buf,
+ sizeof(path_buf),
+ &err))
EM_DEBUG_EXCEPTION("emstorage_get_save_name failed [%d]", err);
- if (!emstorage_move_file(cnt_info->text.html, buf, false, &err)) {
+ if (!emstorage_move_file(cnt_info->text.html, move_buf, false, &err)) {
EM_DEBUG_EXCEPTION("emstorage_move_file failed [%d]", err);
mail->file_path_html = NULL;
}
else
- mail->file_path_html = EM_SAFE_STRDUP(buf);
+ mail->file_path_html = EM_SAFE_STRDUP(path_buf);
g_free(charset_html_text);
}
+ /* mime_entity */
+ if (cnt_info->text.mime_entity) {
+ memset(path_buf, 0x00, sizeof(path_buf));
+ memset(move_buf, 0x00, sizeof(move_buf));
+
+ if (!emstorage_create_dir(pbd_event[temp_count].multi_user_name,
+ pbd_event[temp_count].account_id,
+ mail->mail_id,
+ 0,
+ &err))
+ EM_DEBUG_EXCEPTION("emstorage_create_dir failed [%d]", err);
+
+ if (!emstorage_get_save_name(pbd_event[temp_count].multi_user_name,
+ pbd_event[temp_count].account_id,
+ mail->mail_id,
+ 0,
+ "mime_entity",
+ move_buf,
+ path_buf,
+ sizeof(path_buf),
+ &err))
+ EM_DEBUG_EXCEPTION("emstorage_get_save_name failed [%d]", err);
+
+ if (!emstorage_move_file(cnt_info->text.mime_entity, move_buf, false, &err)) {
+ EM_DEBUG_EXCEPTION("emstorage_move_file failed [%d]", err);
+ mail->file_path_mime_entity = NULL;
+ }
+
+ mail->file_path_mime_entity = EM_SAFE_STRDUP(path_buf);
+ }
+
/* inline attachment */
inline_download_count = 0;
if (cnt_info->inline_file) {
@@ -4883,15 +4262,28 @@ static int emcore_gmime_download_imap_partial_mail_body(MAILSTREAM *stream, int
while (temp_file) {
if (temp_file->type == INLINE_ATTACHMENT && temp_file->save_status == 1) {
inline_download_count++;
- memset(buf, 0x00, sizeof(buf));
-
- if (!emstorage_create_dir(pbd_event[temp_count].account_id, mail->mail_id, 0, &err))
+ memset(path_buf, 0x00, sizeof(path_buf));
+ memset(move_buf, 0x00, sizeof(move_buf));
+
+ if (!emstorage_create_dir(pbd_event[temp_count].multi_user_name,
+ pbd_event[temp_count].account_id,
+ mail->mail_id,
+ 0,
+ &err))
EM_DEBUG_EXCEPTION("emstorage_create_dir failed [%d]", err);
- if (!emstorage_get_save_name(pbd_event[temp_count].account_id, mail->mail_id, 0, temp_file->name, buf, sizeof(buf), &err))
+ if (!emstorage_get_save_name(pbd_event[temp_count].multi_user_name,
+ pbd_event[temp_count].account_id,
+ mail->mail_id,
+ 0,
+ temp_file->name,
+ move_buf,
+ path_buf,
+ sizeof(path_buf),
+ &err))
EM_DEBUG_EXCEPTION("emstorage_get_save_name failed [%d]", err);
- if (!emstorage_move_file(temp_file->save, buf, false, &err)) {
+ if (!emstorage_move_file(temp_file->save, move_buf, false, &err)) {
EM_DEBUG_EXCEPTION("emstorage_move_file failed [%d]", err);
goto FINISH_OFF;
}
@@ -4903,13 +4295,18 @@ static int emcore_gmime_download_imap_partial_mail_body(MAILSTREAM *stream, int
attachment_tbl.mailbox_id = pbd_event[temp_count].mailbox_id;
attachment_tbl.attachment_name = temp_file->name;
attachment_tbl.attachment_size = temp_file->size;
- attachment_tbl.attachment_path = buf;
+ attachment_tbl.attachment_path = path_buf;
attachment_tbl.attachment_save_status = 1;
attachment_tbl.attachment_inline_content_status = 1; /* set to 1 for inline image */
attachment_tbl.attachment_mime_type = temp_file->attachment_mime_type;
attachment_tbl.content_id = temp_file->content_id;
EM_DEBUG_LOG("mime_type : [%s]", temp_file->attachment_mime_type);
- if (!emstorage_add_attachment(&attachment_tbl, false, false, &err))
+
+ if (!emstorage_add_attachment(pbd_event[temp_count].multi_user_name,
+ &attachment_tbl,
+ false,
+ false,
+ &err))
EM_DEBUG_EXCEPTION("emstorage_add_attachment failed - %d", err);
}
}
@@ -4922,20 +4319,33 @@ static int emcore_gmime_download_imap_partial_mail_body(MAILSTREAM *stream, int
}
}
- mail->body_download_status = (mail->body_download_status & ~0x00000003) | (( (total_mail_size - total_attachment_size <= input_download_size) && (inline_download_count == inline_attachment_num))?
- EMAIL_BODY_DOWNLOAD_STATUS_FULLY_DOWNLOADED: EMAIL_BODY_DOWNLOAD_STATUS_PARTIALLY_DOWNLOADED);
+ mail->body_download_status = (mail->body_download_status & ~0x00000003) |
+ (((total_mail_size - total_attachment_size <= input_download_size) &&
+ (inline_download_count == inline_attachment_num)) ?
+ EMAIL_BODY_DOWNLOAD_STATUS_FULLY_DOWNLOADED :
+ EMAIL_BODY_DOWNLOAD_STATUS_PARTIALLY_DOWNLOADED);
- EM_DEBUG_LOG("inline_download_count[%d] inline_attachment_num[%d]", inline_download_count, inline_attachment_num);
- EM_DEBUG_LOG("total_mail_size[%d] total_attachment_size[%d] input_download_size[%d]", total_mail_size, total_attachment_size, input_download_size);
+ EM_DEBUG_LOG("inline_download_count[%d] inline_attachment_num[%d]",
+ inline_download_count, inline_attachment_num);
+ EM_DEBUG_LOG("total_mail_size[%d] total_attachment_size[%d] input_download_size[%d]",
+ total_mail_size, total_attachment_size, input_download_size);
EM_DEBUG_LOG("mail_id [%d] body_download_status [%d]", mail->mail_id, mail->body_download_status);
/* Get preview text */
- if ( (err = emcore_get_preview_text_from_file(mail->file_path_plain,
- mail->file_path_html, MAX_PREVIEW_TEXT_LENGTH, &(mail->preview_text))) != EMAIL_ERROR_NONE)
+ if ( (err = emcore_get_preview_text_from_file(pbd_event[temp_count].multi_user_name,
+ mail->file_path_plain,
+ mail->file_path_html,
+ MAX_PREVIEW_TEXT_LENGTH,
+ &(mail->preview_text))) != EMAIL_ERROR_NONE)
EM_DEBUG_EXCEPTION("emcore_get_preview_text_from_file() failed[%d]", err);
/* Update body contents */
- if (!emstorage_change_mail_field(mail->mail_id, UPDATE_PARTIAL_BODY_DOWNLOAD, mail, true, &err)) {
+ if (!emstorage_change_mail_field(pbd_event[temp_count].multi_user_name,
+ mail->mail_id,
+ UPDATE_PARTIAL_BODY_DOWNLOAD,
+ mail,
+ true,
+ &err)) {
EM_DEBUG_EXCEPTION("emstorage_change_mail_field failed - %d", err);
goto FINISH_OFF;
}
@@ -4943,18 +4353,30 @@ static int emcore_gmime_download_imap_partial_mail_body(MAILSTREAM *stream, int
#ifdef __FEATURE_BODY_SEARCH__
/* strip html content and save into mail_text_tbl */
char *stripped_text = NULL;
- if (!emcore_strip_mail_body_from_file(mail, &stripped_text, &err) || stripped_text == NULL) {
+ if (!emcore_strip_mail_body_from_file(pbd_event[temp_count].multi_user_name,
+ mail,
+ &stripped_text,
+ &err) || stripped_text == NULL) {
EM_DEBUG_EXCEPTION("emcore_strip_mail_body_from_file failed [%d]", err);
}
- if (!emstorage_get_mail_text_by_id(mail->mail_id, &mail_text, true, &err) || !mail_text) {
+ if (!emstorage_get_mail_text_by_id(pbd_event[temp_count].multi_user_name,
+ mail->mail_id,
+ &mail_text,
+ true,
+ &err) || !mail_text) {
EM_DEBUG_EXCEPTION("emstorage_get_mail_text_by_id failed [%d]", err);
goto FINISH_OFF;
}
EM_SAFE_FREE(mail_text->body_text);
mail_text->body_text = stripped_text;
- if (!emstorage_change_mail_text_field(mail->mail_id, mail_text, false, &err)) {
+
+ if (!emstorage_change_mail_text_field(pbd_event[temp_count].multi_user_name,
+ mail->mail_id,
+ mail_text,
+ false,
+ &err)) {
EM_DEBUG_EXCEPTION("emstorage_change_mail_text_field failed [%d]", err);
goto FINISH_OFF;
}
@@ -4966,7 +4388,11 @@ static int emcore_gmime_download_imap_partial_mail_body(MAILSTREAM *stream, int
if (mail)
emstorage_free_mail(&mail, 1, NULL);
- if (false == emcore_delete_pbd_activity(pbd_event[temp_count].account_id, pbd_event[temp_count].mail_id, pbd_event[temp_count].activity_id, &err)){
+ if (false == emcore_delete_pbd_activity(pbd_event[temp_count].multi_user_name,
+ pbd_event[temp_count].account_id,
+ pbd_event[temp_count].mail_id,
+ pbd_event[temp_count].activity_id,
+ &err)){
EM_DEBUG_EXCEPTION("emcore_delete_pbd_activity failed [%d]", err);
goto FINISH_OFF;
}
@@ -5023,6 +4449,9 @@ FINISH_OFF:
if (mail)
emstorage_free_mail(&mail, 1, NULL);
+ if (mailbox_tbl)
+ emstorage_free_mailbox(&mailbox_tbl, 1, NULL);
+
if (mail_text)
emstorage_free_mail_text(&mail_text, 1, NULL);
@@ -5035,376 +4464,6 @@ FINISH_OFF:
return ret;
}
-static int emcore_download_bulk_partial_mail_body_for_imap(MAILSTREAM *stream, int input_download_size, email_event_partial_body_thd *pbd_event, int item_count, int *error)
-{
- EM_DEBUG_FUNC_BEGIN("stream [%p], input_download_size[%d], pbd_event [%p], item_count [%d], error [%p]", stream, input_download_size, pbd_event, item_count, error);
-
- int ret = false, err = EMAIL_ERROR_NONE;
- int j = 0, i = 0;
- int i32_index = 0;
- int total_mail_size = 0, total_attachment_size = 0;
- int temp_count = 0, attachment_num = 0, inline_attachment_num = 0;
- char buf[512] = {0, };
- char *text_plain = NULL;
- char *text_html = NULL;
- char uid_range_string_to_be_downloaded[UID_RANGE_STRING_LENGTH] = {0, };
- char imap_tag[TAG_LENGTH] = {0, };
- char command[COMMAND_LENGTH] = {0, };
- char *temp_data_html = NULL;
- char uid_string[TEMP_STRING_LENGTH] = {0, };
- IMAPLOCAL *imaplocal = NULL;
- IMAPPARSEDREPLY *reply_from_server = NULL;
- emstorage_mail_tbl_t *mail = NULL;
- email_partial_buffer *imap_response = NULL;
- BODY *body = NULL;
- struct _m_content_info *cnt_info = NULL;
- emstorage_attachment_tbl_t attachment_tbl;
- email_event_partial_body_thd *stSectionNo = NULL;
- email_image_data *image_data = NULL;
-
- if (!(stream) || !(imaplocal = stream->local) || !imaplocal->netstream || !pbd_event) {
- EM_DEBUG_EXCEPTION("invalid parameter");
- err = EMAIL_ERROR_INVALID_PARAM;
- EM_DEBUG_FUNC_END("ret [%d]", ret);
- return ret;
- }
-
- EM_DEBUG_LOG("Start of emcore_get_section_for_partial_download, item_count = %d ", item_count);
-
- /* For constructing UID list which is having 10 UID or less at a time */
- for (j = 0, stSectionNo = pbd_event; (stSectionNo != NULL && j < item_count); j++)
- {
- /* delete log before uploading master branch. it is flooding */
-
- if (i32_index >= UID_RANGE_STRING_LENGTH){
- EM_DEBUG_EXCEPTION("String length exceeded its limitation!");
- goto FINISH_OFF;
- }
-
- if (j == item_count - 1)
- i32_index += SNPRINTF(uid_range_string_to_be_downloaded + i32_index, UID_RANGE_STRING_LENGTH - i32_index, "%lu", stSectionNo[j].server_mail_id);
- else
- i32_index += SNPRINTF(uid_range_string_to_be_downloaded + i32_index, UID_RANGE_STRING_LENGTH - i32_index, "%lu,", stSectionNo[j].server_mail_id);
- }
-
- SNPRINTF(imap_tag, TAG_LENGTH, "%08lx", 0xffffffff & (stream->gensym++));
- SNPRINTF(command, COMMAND_LENGTH, "%s UID FETCH %s (BODYSTRUCTURE BODY.PEEK[TEXT]<0.%d>)\015\012", imap_tag, uid_range_string_to_be_downloaded, input_download_size);
-
- EM_DEBUG_LOG("command : %s", command);
-
- /* Sending out the IMAP request */
- if (!net_sout(imaplocal->netstream, command, (int)EM_SAFE_STRLEN(command))) {
- EM_DEBUG_EXCEPTION("net_sout failed...");
- err = EMAIL_ERROR_CONNECTION_BROKEN;
- goto FINISH_OFF;
- }
-
- /* responce from the server */
- imap_response = emcore_get_response_from_server(imaplocal->netstream, imap_tag, &reply_from_server, input_download_size, item_count);
-
- if (!imap_response || !reply_from_server ){
- EM_DEBUG_EXCEPTION(" Invalid response from emcore_get_response_from_server");
- goto FINISH_OFF;
- }
-
- for (i = 0; i < item_count ; i++) {
- total_mail_size = 0;
- total_attachment_size = 0;
- attachment_num = 0;
-
- if( !(imap_response[i].bodystructure) ) continue;
-
- if (body) {
- mail_free_body(&body);
- body = NULL;
- }
-
- if (cnt_info) {
- emcore_free_content_info(cnt_info);
- EM_SAFE_FREE(cnt_info);
- }
-
- err = emcore_parse_bodystructure(stream, reply_from_server, imap_response[i].bodystructure, &body, &cnt_info, &total_mail_size);
- if (err != EMAIL_ERROR_NONE || !body) {
- EM_DEBUG_EXCEPTION("emcore_parse_bodystructure failed : [%d]", err);
- err = EMAIL_ERROR_ON_PARSING;
- goto FINISH_OFF;
- }
-
- /* Search the account id of pbd_event */
- for (temp_count = 0; temp_count <= item_count && pbd_event[temp_count].server_mail_id != imap_response[i].uid_no; temp_count++)
- continue;
-
- if (temp_count > item_count) {
- EM_DEBUG_EXCEPTION("Can't find proper server_mail_id");
- goto FINISH_OFF;
- }
-
- /* Start to parse the body */
- EM_DEBUG_LOG("Start partial body of server_mail_id %d", imap_response[i].uid_no);
-
- /* Check the body download status and body size */
- SNPRINTF(uid_string, sizeof(uid_string), "%ld", imap_response[i].uid_no);
- if (!emstorage_get_maildata_by_servermailid(pbd_event[temp_count].mailbox_id, uid_string, &mail, true, &err) || !mail) {
- EM_DEBUG_EXCEPTION("emstorage_get_mail_data_by_servermailid failed : [%d]", err);
- if (err == EMAIL_ERROR_MAIL_NOT_FOUND || !mail)
- goto FINISH_OFF;
- }
-
- if (mail->body_download_status & EMAIL_BODY_DOWNLOAD_STATUS_FULLY_DOWNLOADED) {
- EM_DEBUG_LOG("Downloaded mail");
- continue;
- }
-
- /* Update the attachment info except inline attachment */
- if ((err = emcore_update_attachment_except_inline(cnt_info, pbd_event[temp_count].account_id, mail->mail_id, pbd_event[temp_count].mailbox_id, &total_attachment_size, &attachment_num, &inline_attachment_num)) != EMAIL_ERROR_NONE) {
- EM_DEBUG_EXCEPTION("emcore_update_attachment_except_inline failed : [%d]", err);
- goto FINISH_OFF;
- }
-
-
- mail->mail_size = total_mail_size;
- mail->attachment_count = attachment_num;
- mail->inline_content_count = inline_attachment_num;
-
- if (imap_response[i].bodytext_len == 0) {
- EM_DEBUG_LOG("BODY size is zero");
- continue;
- }
-
- /*free the plain, html, and image_data before reusing*/
- if (image_data)
- emcore_free_email_image_data(&image_data, IMAGE_DISPLAY_PARTIAL_BODY_COUNT);
-
- EM_SAFE_FREE(text_plain);
- EM_SAFE_FREE(text_html);
-
- if ((err = emcore_parse_body_for_imap(imap_response[i].bodytext, imap_response[i].bodytext_len, cnt_info, body->encoding, &text_plain, &text_html, &image_data)) != EMAIL_ERROR_NONE) {
- EM_DEBUG_EXCEPTION("emcore_parse_body_for_imap failed");
- goto FINISH_OFF;
- }
-
- int text_plain_len = EM_SAFE_STRLEN(text_plain);
- if (text_plain_len > 0) {
- char *charset_plain_text = NULL;
- memset(buf, 0x00, sizeof(buf));
-
- if (cnt_info->text.plain_charset)
- charset_plain_text = cnt_info->text.plain_charset;
- else {
- if (mail->default_charset) {
- charset_plain_text = mail->default_charset;
- } else {
- charset_plain_text = "UTF-8";
- }
- }
-
- if (!emstorage_create_dir(pbd_event[temp_count].account_id, mail->mail_id, 0, &err))
- EM_DEBUG_EXCEPTION("emstorage_create_dir failed [%d]", err);
-
- if (!emstorage_get_save_name(pbd_event[temp_count].account_id, mail->mail_id, 0, charset_plain_text, buf, sizeof(buf), &err))
- EM_DEBUG_EXCEPTION("emstorage_get_save_name failed [%d]", err);
-
- if (!emstorage_create_file(text_plain, text_plain_len, buf, &err))
- EM_DEBUG_EXCEPTION("emstorage_create_file failed [%d]", err);
-
- mail->file_path_plain = EM_SAFE_STRDUP(buf);
- EM_DEBUG_LOG_SEC("mail->file_path_plain [%s]", mail->file_path_plain);
- }
-
- if (image_data != NULL && image_data[0].text_image != NULL && image_data[0].text_image[0] != NULL_CHAR) {
- char *result_string_of_replacing = NULL;
- int store_file = 0;
- int content_index = 0;
-
- temp_data_html = em_malloc(imap_response[i].bodytext_len + 1);
- if(!temp_data_html) {
- EM_DEBUG_EXCEPTION("em_malloc failed");
- err = EMAIL_ERROR_OUT_OF_MEMORY;
- goto FINISH_OFF;
- }
-
- memset(buf, 0x00, sizeof(buf));
- if (text_html != NULL)
- memcpy(temp_data_html, text_html, EM_SAFE_STRLEN(text_html));
- /* EM_SAFE_STRNCPY(temp_data_html, text_html, text_html); */
-
- do {
- if(image_data[store_file].fully_downloaded == 1) {
- if (!emstorage_create_dir(pbd_event[temp_count].account_id, mail->mail_id, 0, &err))
- EM_DEBUG_EXCEPTION("emstorage_create_dir failed [%d]", err);
-
- if (!emstorage_get_save_name(pbd_event[temp_count].account_id, mail->mail_id, 0, image_data[store_file].image_file_name, buf, sizeof(buf), &err))
- EM_DEBUG_EXCEPTION("emstorage_get_save_name failed [%d]", err);
-
- if (image_data[store_file].dec_len>0)
- if (!emstorage_create_file(image_data[store_file].text_image, image_data[store_file].dec_len, buf, &err))
- EM_DEBUG_EXCEPTION("emstorage_create_file failed [%d]", err);
-
- if (!(mail->body_download_status & EMAIL_BODY_DOWNLOAD_STATUS_PARTIALLY_DOWNLOADED)){
- memset(&attachment_tbl, 0x00, sizeof(emstorage_attachment_tbl_t));
- attachment_tbl.mail_id = mail->mail_id;
- attachment_tbl.account_id = pbd_event[temp_count].account_id;
- attachment_tbl.mailbox_id = pbd_event[temp_count].mailbox_id;
- attachment_tbl.attachment_name = image_data[store_file].image_file_name;
- attachment_tbl.attachment_size = image_data[store_file].dec_len;
- attachment_tbl.attachment_path = buf;
- attachment_tbl.attachment_save_status = 1;
- attachment_tbl.attachment_inline_content_status = 1; /* set to 1 for inline image */
- attachment_tbl.attachment_mime_type = image_data[store_file].mime_type;
- attachment_tbl.content_id = image_data[store_file].content_id;
- EM_DEBUG_LOG("mime_type : [%s]", image_data[store_file].mime_type);
- if (!emstorage_add_attachment (&attachment_tbl, false, false, &err))
- EM_DEBUG_EXCEPTION("emstorage_add_attachment failed - %d", err);
- }
- }
-
- store_file++;
- } while (image_data[store_file].text_image != NULL && image_data[store_file].text_image[0] != NULL_CHAR && (store_file < IMAGE_DISPLAY_PARTIAL_BODY_COUNT));
-
- while (image_data[content_index].text_image != NULL && image_data[content_index].text_image[0] != NULL_CHAR &&
- image_data[content_index].content_id && image_data[content_index].content_id[0] != NULL_CHAR && (content_index < IMAGE_DISPLAY_PARTIAL_BODY_COUNT)){
- /* Finding CID in HTML and replacing with image name. */
- if(image_data[content_index].fully_downloaded == 1) {
- result_string_of_replacing = em_replace_string((char *)temp_data_html, (char *)image_data[content_index].content_id, (char *)image_data[content_index].image_file_name);
- if (result_string_of_replacing) {
- memset(temp_data_html, 0x00, imap_response[i].bodytext_len + 1);
- strncpy(temp_data_html, result_string_of_replacing, strlen(result_string_of_replacing));
- EM_SAFE_FREE (result_string_of_replacing);
- }
-
- if (strstr(temp_data_html, image_data[content_index].content_id) != NULL)
- continue; /* Replace content id on HTML with same file name one more time. */
- }
- content_index++;
- }
-
- memset(text_html, 0, imap_response[i].bodytext_len + 1);
-
- if (temp_data_html != NULL)
- memcpy(text_html, temp_data_html, EM_SAFE_STRLEN(temp_data_html));
-
- EM_SAFE_FREE(temp_data_html);
- }
-
- if (EM_SAFE_STRLEN(text_html) > 0) {
- memset(buf, 0x00, sizeof(buf));
- char html_body[MAX_CHARSET_VALUE] = {0x00, };
- if (cnt_info->text.plain_charset != NULL){
- if (EM_SAFE_STRLEN(cnt_info->text.plain_charset) < MAX_CHARSET_VALUE)
- memcpy(html_body, cnt_info->text.plain_charset, EM_SAFE_STRLEN(cnt_info->text.plain_charset));
- else
- memcpy(html_body, "UTF-8", strlen("UTF-8"));
- }
- if (html_body[0] != NULL_CHAR)
- strcat(html_body, HTML_EXTENSION_STRING);
- else
- memcpy(html_body, "UTF-8.htm", strlen("UTF-8.htm"));
-
- if (!emstorage_create_dir(pbd_event[temp_count].account_id, mail->mail_id, 0, &err))
- EM_DEBUG_EXCEPTION("emstorage_create_dir failed [%d]", err);
-
- if (!emstorage_get_save_name(pbd_event[temp_count].account_id, mail->mail_id, 0, html_body, buf, sizeof(buf), &err))
- EM_DEBUG_EXCEPTION("emstorage_get_save_name failed [%d]", err);
-
- int text_html_len = EM_SAFE_STRLEN(text_html);
- if (text_html_len>0)
- if (!emstorage_create_file(text_html, EM_SAFE_STRLEN(text_html), buf, &err))
- EM_DEBUG_EXCEPTION("emstorage_create_file failed [%d]", err);
-
- mail->file_path_html = EM_SAFE_STRDUP(buf);
-
- }
-
- mail->body_download_status = (mail->body_download_status & ~0x00000003) | ((total_mail_size - total_attachment_size < input_download_size) ? 1 : 2);
- EM_DEBUG_LOG("total_mail_size[%d] total_attachment_size[%d] input_download_size[%d]", total_mail_size, total_attachment_size, input_download_size);
- EM_DEBUG_LOG("mail_id [%d] body_download_status [%d]", mail->mail_id, mail->body_download_status);
-
- /* Get preview text */
- if ( (err = emcore_get_preview_text_from_file(mail->file_path_plain, mail->file_path_html, MAX_PREVIEW_TEXT_LENGTH, &(mail->preview_text))) != EMAIL_ERROR_NONE)
- EM_DEBUG_EXCEPTION("emcore_get_preview_text_from_file() failed[%d]", err);
-
- /* Update body contents */
- if (!emstorage_change_mail_field(mail->mail_id, UPDATE_PARTIAL_BODY_DOWNLOAD, mail, true, &err)) {
- EM_DEBUG_EXCEPTION("emstorage_change_mail_field failed - %d", err);
- goto FINISH_OFF;
- }
-
-#ifdef __FEATURE_BODY_SEARCH__
- /* strip html content and save into mail_text_tbl */
- char *stripped_text = NULL;
- if (!emcore_strip_mail_body_from_file(mail, &stripped_text, &err) || stripped_text == NULL) {
- EM_DEBUG_EXCEPTION("emcore_strip_mail_body_from_file failed [%d]", err);
- }
-
- emstorage_mail_text_tbl_t *mail_text;
- if (!emstorage_get_mail_text_by_id(mail->mail_id, &mail_text, true, &err) || !mail_text) {
- EM_DEBUG_EXCEPTION("emstorage_get_mail_text_by_id failed [%d]", err);
- goto FINISH_OFF;
- }
-
- EM_SAFE_FREE(mail_text->body_text);
- mail_text->body_text = stripped_text;
- if (!emstorage_change_mail_text_field(mail->mail_id, mail_text, false, &err)) {
- EM_DEBUG_EXCEPTION("emstorage_change_mail_text_field failed [%d]", err);
- goto FINISH_OFF;
- }
-
- if (mail_text)
- emstorage_free_mail_text(&mail_text, 1, NULL);
-#endif
-
- if (mail)
- emstorage_free_mail(&mail, 1, NULL);
-
- if (false == emcore_delete_pbd_activity(pbd_event[temp_count].account_id, pbd_event[temp_count].mail_id, pbd_event[temp_count].activity_id, &err)){
- EM_DEBUG_EXCEPTION("emcore_delete_pbd_activity failed [%d]", err);
- goto FINISH_OFF;
- }
- }
-
- ret = true;
-
-FINISH_OFF:
-
- if (error)
- *error = err;
-
- if (true != ret)
- EM_DEBUG_EXCEPTION("Failed download for the uid list %s", command);
-
- if(reply_from_server) {
- EM_SAFE_FREE(reply_from_server->key);
- EM_SAFE_FREE(reply_from_server->line);
- EM_SAFE_FREE(reply_from_server->tag);
- EM_SAFE_FREE(reply_from_server->text);
- EM_SAFE_FREE(reply_from_server);
- }
-
- EM_SAFE_FREE(text_plain);
- EM_SAFE_FREE(text_html);
-
- if (image_data)
- emcore_free_email_image_data(&image_data, IMAGE_DISPLAY_PARTIAL_BODY_COUNT);
-
- if (cnt_info) {
- emcore_free_content_info(cnt_info);
- EM_SAFE_FREE(cnt_info);
- }
-
- if (body)
- mail_free_body(&body);
-
- if (mail)
- emstorage_free_mail(&mail, 1, NULL);
-
- if (imap_response)
- emcore_free_email_partial_buffer(&imap_response, item_count);
-
- EM_DEBUG_FUNC_END("ret [%d]", ret);
- return ret;
-}
-
INTERNAL_FUNC int emcore_download_bulk_partial_mail_body_for_pop3(MAILSTREAM *stream, int input_download_size, email_event_partial_body_thd *pbd_event, int item_count, int *error)
{
EM_DEBUG_FUNC_BEGIN("stream [%p], pbd_event [%p], item_count [%d], error [%p]", stream, pbd_event, item_count, error);
@@ -5421,28 +4480,13 @@ INTERNAL_FUNC int emcore_download_bulk_partial_mail_body_for_pop3(MAILSTREAM *st
EM_DEBUG_LOG_SEC("pbd_event[%d].account_id [%d], mail_id [%d], server_mail_id [%d], activity_id [%d]", \
i, pbd_event[i].account_id, pbd_event[i].mail_id, pbd_event[i].server_mail_id, pbd_event[i].activity_id);
-#ifdef __FEATURE_USE_GMIME__
- if (!emcore_gmime_download_body_sections(stream, pbd_event[i].account_id,
+ if (!emcore_gmime_download_body_sections(pbd_event[i].multi_user_name, stream, pbd_event[i].account_id,
pbd_event[i].mail_id, 0, input_download_size, -1, 0, 0, &err)) {
EM_DEBUG_EXCEPTION("emcore_gmime_download_body_sections failed - %d", err);
goto FINISH_OFF;
}
-#else
- if (!emcore_download_body_multi_sections_bulk (stream,
- pbd_event[i].account_id,
- pbd_event[i].mail_id,
- false,
- false,
- input_download_size,
- -1,
- 0,
- &err)) {
- EM_DEBUG_EXCEPTION("emcore_download_body_multi_sections_bulk failed");
- goto FINISH_OFF;
- }
-#endif
- if (false == emcore_delete_pbd_activity(pbd_event[i].account_id, pbd_event[i].mail_id, pbd_event[i].activity_id, &err)){
+ if (false == emcore_delete_pbd_activity(pbd_event[i].multi_user_name, pbd_event[i].account_id, pbd_event[i].mail_id, pbd_event[i].activity_id, &err)){
EM_DEBUG_EXCEPTION("emcore_delete_pbd_activity failed [%d]", err);
goto FINISH_OFF;
}
@@ -5458,8 +4502,6 @@ FINISH_OFF:
return ret;
}
-
-
INTERNAL_FUNC int emcore_download_bulk_partial_mail_body(MAILSTREAM *stream, email_event_partial_body_thd *pbd_event, int item_count, int *error)
{
EM_DEBUG_FUNC_BEGIN("stream [%p], pbd_event [%p], item_count [%d], error [%p]", stream, pbd_event, item_count, error);
@@ -5473,20 +4515,16 @@ INTERNAL_FUNC int emcore_download_bulk_partial_mail_body(MAILSTREAM *stream, ema
goto FINISH_OFF;
}
- if (!emstorage_get_account_by_id(pbd_event[0].account_id, EMAIL_ACC_GET_OPT_DEFAULT, &pbd_account_tbl, true, &err)) {
+ if (!emstorage_get_account_by_id(pbd_event[0].multi_user_name, pbd_event[0].account_id, EMAIL_ACC_GET_OPT_DEFAULT, &pbd_account_tbl, true, &err)) {
EM_DEBUG_EXCEPTION("emstorage_get_account_by_id failed [%d]", err);
goto FINISH_OFF;
}
- auto_download_size = (pbd_account_tbl->auto_download_size<4096)?4096:pbd_account_tbl->auto_download_size;
+ auto_download_size = (pbd_account_tbl->auto_download_size < 4096) ? 4096 : pbd_account_tbl->auto_download_size;
switch (pbd_account_tbl->incoming_server_type){
case EMAIL_SERVER_TYPE_IMAP4:
-#ifdef __FEATURE_USE_GMIME__
ret = emcore_gmime_download_imap_partial_mail_body(stream, auto_download_size, pbd_event, item_count, &err);
-#else
- ret = emcore_download_bulk_partial_mail_body_for_imap(stream, auto_download_size, pbd_event, item_count, &err);
-#endif
break;
case EMAIL_SERVER_TYPE_POP3:
@@ -5581,7 +4619,7 @@ static email_partial_buffer *emcore_get_response_from_server (NETSTREAM *nstream
EM_SAFE_FREE(cur_line);
EM_SAFE_FREE(tmp);
- p_rfc822header = strcasestr(full_line, "RFC822.HEADER {");
+ if (full_line) p_rfc822header = strcasestr(full_line, "RFC822.HEADER {");
if (p_rfc822header && server_response[count].rfc822header == NULL) {
p_rfc822header += strlen("RFC822.HEADER {");
rfc822header_size = atoi(p_rfc822header);
@@ -5593,7 +4631,8 @@ static email_partial_buffer *emcore_get_response_from_server (NETSTREAM *nstream
goto FINISH_OFF;
}
- if (net_getbuffer(nstream, server_response[count].rfc822header_len, server_response[count].rfc822header) <= 0) {
+ if (net_getbuffer(nstream, server_response[count].rfc822header_len,
+ server_response[count].rfc822header) <= 0) {
EM_DEBUG_EXCEPTION("net_getbuffer failed");
goto FINISH_OFF;
}
@@ -5602,8 +4641,8 @@ static email_partial_buffer *emcore_get_response_from_server (NETSTREAM *nstream
continue;
}
- p_bodystructure = strcasestr(full_line, "BODYSTRUCTURE");
- p_bodystructure_end = strcasestr(full_line, "BODY[TEXT]");
+ if (full_line) p_bodystructure = strcasestr(full_line, "BODYSTRUCTURE");
+ if (full_line) p_bodystructure_end = strcasestr(full_line, "BODY[TEXT]");
/* check whether full header is received */
if (p_bodystructure && p_bodystructure_end) {
diff --git a/email-core/email-core-mailbox.c b/email-core/email-core-mailbox.c
index baccd2f..3c9b5ab 100755
--- a/email-core/email-core-mailbox.c
+++ b/email-core/email-core-mailbox.c
@@ -189,7 +189,7 @@ INTERNAL_FUNC void emcore_close_recv_stream_list (void)
EM_DEBUG_FUNC_END();
}
-INTERNAL_FUNC MAILSTREAM** emcore_get_recv_stream (int account_id, int mailbox_id, int *error)
+INTERNAL_FUNC MAILSTREAM** emcore_get_recv_stream (char *multi_user_name, int account_id, int mailbox_id, int *error)
{
EM_DEBUG_FUNC_BEGIN("account_id[%d]", account_id);
GList* cur = g_recv_stream_list;
@@ -198,7 +198,7 @@ INTERNAL_FUNC MAILSTREAM** emcore_get_recv_stream (int account_id, int mailbox_i
int err = EMAIL_ERROR_NONE;
email_account_t *ref_account = NULL;
- if (!(ref_account = emcore_get_account_reference(account_id))) {
+ if (!(ref_account = emcore_get_account_reference(multi_user_name, account_id, false))) {
EM_DEBUG_EXCEPTION("emcore_get_account_reference failed [%d]", account_id);
err = EMAIL_ERROR_INVALID_ACCOUNT;
goto FINISH_OFF;
@@ -257,7 +257,7 @@ INTERNAL_FUNC MAILSTREAM** emcore_get_recv_stream (int account_id, int mailbox_i
goto FINISH_OFF;
}
- if (!emcore_connect_to_remote_mailbox(account_id, mailbox_id, (void **)ret, &err)) {
+ if (!emcore_connect_to_remote_mailbox(multi_user_name, account_id, mailbox_id, (void **)ret, &err)) {
EM_DEBUG_EXCEPTION("emcore_connect_to_remote_mailbox failed [%d]", err);
EM_SAFE_FREE(ret);
goto FINISH_OFF;
@@ -296,12 +296,15 @@ FINISH_OFF:
/* description
* get local mailbox list
*/
-INTERNAL_FUNC int emcore_get_mailbox_list(int account_id, email_mailbox_t **mailbox_list, int *p_count, int *err_code)
+INTERNAL_FUNC int emcore_get_mailbox_list(char *multi_user_name, int account_id, email_mailbox_t **mailbox_list,
+ int *p_count, int *err_code)
{
- EM_DEBUG_FUNC_BEGIN("account_id[%d], mailbox_list[%p], p_count[%p], err_code[%p]", account_id, mailbox_list, p_count, err_code);
+ EM_DEBUG_FUNC_BEGIN("account_id[%d], mailbox_list[%p], p_count[%p], err_code[%p]",
+ account_id, mailbox_list, p_count, err_code);
if (account_id <= 0 || !mailbox_list || !p_count) {
- EM_DEBUG_EXCEPTION("PARAM Failed account_id[%d], mailbox_list[%p], p_count[%p]", account_id, mailbox_list, p_count);
+ EM_DEBUG_EXCEPTION("PARAM Failed account_id[%d], mailbox_list[%p], p_count[%p]",
+ account_id, mailbox_list, p_count);
if (err_code != NULL)
*err_code = EMAIL_ERROR_INVALID_PARAM;
return false;
@@ -314,16 +317,16 @@ INTERNAL_FUNC int emcore_get_mailbox_list(int account_id, email_mailbox_t **mail
int i, count = 512;
/* get mailbox list from mailbox table */
-
- if (!(ref_account = emcore_get_account_reference(account_id))) {
+ if (!(ref_account = emcore_get_account_reference(multi_user_name, account_id, false))) {
EM_DEBUG_EXCEPTION(" emcore_get_account_reference failed - %d", account_id);
error = EMAIL_ERROR_INVALID_ACCOUNT;
goto FINISH_OFF;
}
- if (!emstorage_get_mailbox_list(ref_account->account_id, EMAIL_MAILBOX_ALL, EMAIL_MAILBOX_SORT_BY_NAME_ASC, &count, &local_mailbox_list, true, &error)) {
+ if (!emstorage_get_mailbox_list(multi_user_name, ref_account->account_id,
+ EMAIL_MAILBOX_ALL, EMAIL_MAILBOX_SORT_BY_NAME_ASC,
+ &count, &local_mailbox_list, true, &error)) {
EM_DEBUG_EXCEPTION(" emstorage_get_mailbox failed - %d", error);
-
goto FINISH_OFF;
}
@@ -366,7 +369,7 @@ FINISH_OFF:
/* description
* get imap sync mailbox list
*/
-int emcore_get_mailbox_list_to_be_sync(int account_id, email_mailbox_t **mailbox_list, int *p_count, int *err_code)
+int emcore_get_mailbox_list_to_be_sync(char *multi_user_name, int account_id, email_mailbox_t **mailbox_list, int *p_count, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("account_id[%d], mailbox_list[%p], p_count[%p], err_code[%p]", account_id, mailbox_list, p_count, err_code);
@@ -385,15 +388,16 @@ int emcore_get_mailbox_list_to_be_sync(int account_id, email_mailbox_t **mailbox
int i, count = 512;
/* get mailbox list from mailbox table */
- if (!(ref_account = emcore_get_account_reference(account_id))) {
+ if (!(ref_account = emcore_get_account_reference(multi_user_name, account_id, false))) {
EM_DEBUG_EXCEPTION("emcore_get_account_reference failed - %d", account_id);
error = EMAIL_ERROR_INVALID_ACCOUNT;
goto FINISH_OFF;
}
- if (!emstorage_get_mailbox_list(ref_account->account_id, 0, EMAIL_MAILBOX_SORT_BY_TYPE_ASC, &count, &mailbox_tbl_list, true, &error)) {
+ if (!emstorage_get_mailbox_list(multi_user_name, ref_account->account_id, 0,
+ EMAIL_MAILBOX_SORT_BY_TYPE_ASC, &count,
+ &mailbox_tbl_list, true, &error)) {
EM_DEBUG_EXCEPTION("emstorage_get_mailbox failed - %d", error);
-
goto FINISH_OFF;
}
@@ -433,7 +437,7 @@ FINISH_OFF:
return ret;
}
-INTERNAL_FUNC int emcore_get_mail_count(email_mailbox_t *mailbox, int *total, int *unseen, int *err_code)
+INTERNAL_FUNC int emcore_get_mail_count(char *multi_user_name, email_mailbox_t *mailbox, int *total, int *unseen, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("mailbox[%p], total[%p], unseen[%p], err_code[%p]", mailbox, total, unseen, err_code);
@@ -446,9 +450,8 @@ INTERNAL_FUNC int emcore_get_mail_count(email_mailbox_t *mailbox, int *total, in
goto FINISH_OFF;
}
- if (!emstorage_get_mail_count(mailbox->account_id, mailbox->mailbox_id, total, unseen, true, &err)) {
+ if (!emstorage_get_mail_count(multi_user_name, mailbox->account_id, mailbox->mailbox_id, total, unseen, true, &err)) {
EM_DEBUG_EXCEPTION(" emstorage_get_mail_count failed - %d", err);
-
goto FINISH_OFF;
}
@@ -456,13 +459,14 @@ INTERNAL_FUNC int emcore_get_mail_count(email_mailbox_t *mailbox, int *total, in
ret = true;
FINISH_OFF:
+
if (err_code != NULL)
*err_code = err;
return ret;
}
-INTERNAL_FUNC int emcore_create_mailbox(email_mailbox_t *new_mailbox, int on_server, int server_type, int slot_size, int *err_code)
+INTERNAL_FUNC int emcore_create_mailbox(char *multi_user_name, email_mailbox_t *new_mailbox, int on_server, int server_type, int slot_size, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("new_mailbox[%p], err_code[%p]", new_mailbox, err_code);
int ret = false;
@@ -483,7 +487,7 @@ INTERNAL_FUNC int emcore_create_mailbox(email_mailbox_t *new_mailbox, int on_ser
mail_slot_size = slot_size;
}
else {
- account_ref = emcore_get_account_reference(new_mailbox->account_id);
+ account_ref = emcore_get_account_reference(multi_user_name, new_mailbox->account_id, false);
if (!account_ref) {
EM_DEBUG_EXCEPTION("Invalid account_id [%d]", new_mailbox->account_id);
err = EMAIL_ERROR_INVALID_ACCOUNT;
@@ -505,11 +509,14 @@ INTERNAL_FUNC int emcore_create_mailbox(email_mailbox_t *new_mailbox, int on_ser
}
EM_SAFE_FREE(new_mailbox->mailbox_name);
new_mailbox->mailbox_name = enc_mailbox_name;
+
+ EM_SAFE_FREE(new_mailbox->alias);
+ new_mailbox->alias = emcore_get_alias_of_mailbox((const char *)new_mailbox->mailbox_name);
}
if (on_server) {
/* Create a mailbox from Sever */
- if (!emcore_create_imap_mailbox(new_mailbox, &err)) {
+ if (!emcore_create_imap_mailbox(multi_user_name, new_mailbox, &err)) {
EM_DEBUG_EXCEPTION("Creating a mailbox on server failed.");
goto FINISH_OFF;
}
@@ -528,7 +535,7 @@ INTERNAL_FUNC int emcore_create_mailbox(email_mailbox_t *new_mailbox, int on_ser
local_mailbox->mail_slot_size = mail_slot_size;
- if (!emstorage_add_mailbox(local_mailbox, true, &err)) {
+ if (!emstorage_add_mailbox(multi_user_name, local_mailbox, true, &err)) {
EM_DEBUG_EXCEPTION("emstorage_add_mailbox failed [%d]", err);
goto FINISH_OFF;
}
@@ -547,13 +554,14 @@ FINISH_OFF:
return ret;
}
-INTERNAL_FUNC int emcore_delete_mailbox(int input_mailbox_id, int input_on_server, int input_recursive)
+INTERNAL_FUNC int emcore_delete_mailbox(char *multi_user_name, int input_mailbox_id, int input_on_server, int input_recursive)
{
EM_DEBUG_FUNC_BEGIN("input_mailbox_id[%d] input_on_server[%d] input_recursive[%d]", input_mailbox_id, input_on_server, input_recursive);
int err = EMAIL_ERROR_NONE;
int i = 0;
int mailbox_count = 0;
+ char *old_mailbox_name = NULL;
emstorage_mailbox_tbl_t *target_mailbox = NULL;
emstorage_mailbox_tbl_t *target_mailbox_array = NULL;
@@ -563,21 +571,30 @@ INTERNAL_FUNC int emcore_delete_mailbox(int input_mailbox_id, int input_on_serve
goto FINISH_OFF;
}
- if ((err = emstorage_get_mailbox_by_id(input_mailbox_id, &target_mailbox)) != EMAIL_ERROR_NONE || !target_mailbox) {
+ if ((err = emstorage_get_mailbox_by_id(multi_user_name, input_mailbox_id, &target_mailbox)) != EMAIL_ERROR_NONE || !target_mailbox) {
EM_DEBUG_EXCEPTION("emstorage_get_mailbox_by_id failed. [%d]", err);
goto FINISH_OFF;
}
+ old_mailbox_name = g_strdup(target_mailbox->mailbox_name);
+
#ifdef __FEATURE_DELETE_MAILBOX_RECURSIVELY__
if(input_recursive) {
/* Getting children mailbox list */
- if(!emstorage_get_child_mailbox_list(target_mailbox->account_id, target_mailbox->mailbox_name, &mailbox_count, &target_mailbox_array, false,&err)) {
+ if(!emstorage_get_child_mailbox_list(multi_user_name,
+ target_mailbox->account_id,
+ target_mailbox->mailbox_name,
+ &mailbox_count,
+ &target_mailbox_array,
+ false,
+ &err)) {
EM_DEBUG_EXCEPTION("emstorage_get_child_mailbox_list failed. [%d]", err);
goto FINISH_OFF;
}
if (target_mailbox)
- emstorage_free_mailbox(&target_mailbox, 1, NULL);
+ emstorage_free_mailbox(&target_mailbox, 1, NULL);
+
target_mailbox = NULL;
}
else
@@ -589,11 +606,18 @@ INTERNAL_FUNC int emcore_delete_mailbox(int input_mailbox_id, int input_on_serve
}
/* Remove mailboxes */
- for(i = 0; i < mailbox_count ; i++) {
+ for (i = 0; i < mailbox_count; i++) {
+ if (strncasecmp(target_mailbox_array[i].mailbox_name, old_mailbox_name, strlen(old_mailbox_name))) {
+ if (!strcasestr(target_mailbox_array[i].mailbox_name, "/")) {
+ EM_DEBUG_LOG("Not folder");
+ continue;
+ }
+ }
+
EM_DEBUG_LOG("Deleting mailbox_id [%d]", target_mailbox_array[i].mailbox_id);
if (input_on_server) {
EM_DEBUG_LOG("Delete the mailbox in Sever >>> ");
- if (!emcore_delete_imap_mailbox(target_mailbox_array[i].mailbox_id, &err)) {
+ if (!emcore_delete_imap_mailbox(multi_user_name, target_mailbox_array[i].mailbox_id, &err)) {
EM_DEBUG_EXCEPTION("Delete the mailbox in server : failed [%d]", err);
goto FINISH_OFF;
}
@@ -601,18 +625,28 @@ INTERNAL_FUNC int emcore_delete_mailbox(int input_mailbox_id, int input_on_serve
EM_DEBUG_LOG("Delete the mailbox in server : success");
}
- if (!emcore_delete_all_mails_of_mailbox(target_mailbox_array[i].account_id, target_mailbox_array[i].mailbox_id, false, &err)) {
- EM_DEBUG_EXCEPTION("emcore_delete_all_mails_of_mailbox failed [%d]", err);
- goto FINISH_OFF;
+ if (!emcore_delete_all_mails_of_mailbox(multi_user_name,
+ target_mailbox_array[i].account_id,
+ target_mailbox_array[i].mailbox_id,
+ 0,
+ false,
+ &err)) {
+ if (err != EMAIL_ERROR_MAIL_NOT_FOUND) {
+ EM_DEBUG_EXCEPTION("emcore_delete_all_mails_of_mailbox failed [%d]", err);
+ goto FINISH_OFF;
+ }
}
- if (!emstorage_delete_mailbox(target_mailbox_array[i].account_id, -1, target_mailbox_array[i].mailbox_id, true, &err)) {
+ if (!emstorage_delete_mailbox(multi_user_name, target_mailbox_array[i].account_id, -1, target_mailbox_array[i].mailbox_id, true, &err)) {
EM_DEBUG_EXCEPTION("emstorage_delete_mailbox failed [%d]", err);
goto FINISH_OFF;
}
}
FINISH_OFF:
+
+ EM_SAFE_FREE(old_mailbox_name);
+
if (target_mailbox)
emstorage_free_mailbox(&target_mailbox, 1, NULL);
@@ -624,7 +658,7 @@ FINISH_OFF:
}
-INTERNAL_FUNC int emcore_delete_mailbox_ex(int input_account_id, int *input_mailbox_id_array, int input_mailbox_id_count, int input_on_server, int input_recursive)
+INTERNAL_FUNC int emcore_delete_mailbox_ex(char *multi_user_name, int input_account_id, int *input_mailbox_id_array, int input_mailbox_id_count, int input_on_server, int input_recursive)
{
EM_DEBUG_FUNC_BEGIN("input_account_id [%d] input_mailbox_id_array[%p] input_mailbox_id_count[%d] input_on_server[%d] input_recursive[%d]", input_mailbox_id_array, input_mailbox_id_array, input_mailbox_id_count, input_on_server, input_recursive);
int err = EMAIL_ERROR_NONE;
@@ -636,13 +670,13 @@ INTERNAL_FUNC int emcore_delete_mailbox_ex(int input_account_id, int *input_mail
goto FINISH_OFF;
}
- if((err = emstorage_set_field_of_mailbox_with_integer_value(input_account_id, input_mailbox_id_array, input_mailbox_id_count, "deleted_flag", 1, true)) != EMAIL_ERROR_NONE) {
+ if((err = emstorage_set_field_of_mailbox_with_integer_value(multi_user_name, input_account_id, input_mailbox_id_array, input_mailbox_id_count, "deleted_flag", 1, true)) != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("emstorage_set_field_of_mailbox_with_integer_value failed[%d]", err);
goto FINISH_OFF;
}
for(i = 0; i < input_mailbox_id_count; i++) {
- if((err = emcore_delete_mailbox(input_mailbox_id_array[i] , input_on_server, input_recursive)) != EMAIL_ERROR_NONE) {
+ if((err = emcore_delete_mailbox(multi_user_name, input_mailbox_id_array[i] , input_on_server, input_recursive)) != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("emcore_delete_mailbox failed [%d]", err);
goto FINISH_OFF;
}
@@ -653,7 +687,7 @@ FINISH_OFF:
return err;
}
-INTERNAL_FUNC int emcore_delete_mailbox_all(email_mailbox_t *mailbox, int *err_code)
+INTERNAL_FUNC int emcore_delete_mailbox_all(char *multi_user_name, email_mailbox_t *mailbox, int *err_code)
{
EM_DEBUG_FUNC_BEGIN(" mailbox[%p], err_code[%p]", mailbox, err_code);
@@ -665,17 +699,21 @@ INTERNAL_FUNC int emcore_delete_mailbox_all(email_mailbox_t *mailbox, int *err_c
err = EMAIL_ERROR_INVALID_PARAM;
goto FINISH_OFF;
}
-
- if (!emcore_delete_all_mails_of_mailbox(mailbox->account_id, mailbox->mailbox_id, 0, /*NULL, */ &err)) {
- EM_DEBUG_EXCEPTION(" emcore_delete_all_mails_of_mailbox failed - %d", err);
-
- goto FINISH_OFF;
+
+ if (!emcore_delete_all_mails_of_mailbox(multi_user_name,
+ mailbox->account_id,
+ mailbox->mailbox_id,
+ 0,
+ 0, /*NULL, */
+ &err)) {
+ if (err != EMAIL_ERROR_MAIL_NOT_FOUND) {
+ EM_DEBUG_EXCEPTION(" emcore_delete_all_mails_of_mailbox failed - %d", err);
+ goto FINISH_OFF;
+ }
}
- if (!emstorage_delete_mailbox(mailbox->account_id, -1, mailbox->mailbox_id, true, &err)) {
+ if (!emstorage_delete_mailbox(multi_user_name, mailbox->account_id, -1, mailbox->mailbox_id, true, &err)) {
EM_DEBUG_EXCEPTION(" emstorage_delete_mailbox failed - %d", err);
-
-
goto FINISH_OFF;
}
@@ -688,7 +726,15 @@ FINISH_OFF:
return ret;
}
-INTERNAL_FUNC int emcore_rename_mailbox(int input_mailbox_id, char *input_new_mailbox_name, char *input_new_mailbox_alias, void *input_eas_data, int input_eas_data_length, int input_on_server, int input_recursive, int handle_to_be_published)
+INTERNAL_FUNC int emcore_rename_mailbox(char *multi_user_name,
+ int input_mailbox_id,
+ char *input_new_mailbox_name,
+ char *input_new_mailbox_alias,
+ void *input_eas_data,
+ int input_eas_data_length,
+ int input_on_server,
+ int input_recursive,
+ int handle_to_be_published)
{
EM_DEBUG_FUNC_BEGIN("input_mailbox_id[%d] input_new_mailbox_name[%p] input_new_mailbox_alias[%p] input_eas_data[%p] input_eas_data_length[%d] input_on_server[%d] input_recursive[%d] handle_to_be_published[%d]", input_mailbox_id, input_new_mailbox_name, input_new_mailbox_alias, input_eas_data, input_eas_data_length, input_on_server, input_recursive, handle_to_be_published);
@@ -709,13 +755,12 @@ INTERNAL_FUNC int emcore_rename_mailbox(int input_mailbox_id, char *input_new_ma
goto FINISH_OFF;
}
- if ((err = emstorage_get_mailbox_by_id(input_mailbox_id, &target_mailbox)) != EMAIL_ERROR_NONE || !target_mailbox) {
+ if ((err = emstorage_get_mailbox_by_id(multi_user_name, input_mailbox_id, &target_mailbox)) != EMAIL_ERROR_NONE || !target_mailbox) {
EM_DEBUG_EXCEPTION("emstorage_get_mailbox_by_id failed. [%d]", err);
goto FINISH_OFF;
}
- account_ref = emcore_get_account_reference(target_mailbox->account_id);
-
+ account_ref = emcore_get_account_reference(multi_user_name, target_mailbox->account_id, false);
if (account_ref == NULL) {
EM_DEBUG_EXCEPTION("emcore_get_account_reference failed.");
goto FINISH_OFF;
@@ -738,7 +783,12 @@ INTERNAL_FUNC int emcore_rename_mailbox(int input_mailbox_id, char *input_new_ma
if (input_on_server) {
EM_DEBUG_LOG("Rename the mailbox in Sever >>> ");
- if ((err = emcore_rename_mailbox_on_imap_server(target_mailbox->account_id, target_mailbox->mailbox_id, target_mailbox->mailbox_name, new_mailbox_name, handle_to_be_published)) != EMAIL_ERROR_NONE) {
+ if ((err = emcore_rename_mailbox_on_imap_server(multi_user_name,
+ target_mailbox->account_id,
+ target_mailbox->mailbox_id,
+ target_mailbox->mailbox_name,
+ new_mailbox_name,
+ handle_to_be_published)) != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("emcore_rename_mailbox_on_imap_server failed [%d]", err);
goto FINISH_OFF;
}
@@ -749,7 +799,13 @@ INTERNAL_FUNC int emcore_rename_mailbox(int input_mailbox_id, char *input_new_ma
#ifdef __FEATURE_RENAME_MAILBOX_RECURSIVELY__
if(account_ref->incoming_server_type != EMAIL_SERVER_TYPE_ACTIVE_SYNC && input_recursive) {
/* Getting children mailbox list */
- if(!emstorage_get_child_mailbox_list(target_mailbox->account_id, target_mailbox->mailbox_name, &mailbox_count, &target_mailbox_array, false,&err)) {
+ if(!emstorage_get_child_mailbox_list(multi_user_name,
+ target_mailbox->account_id,
+ target_mailbox->mailbox_name,
+ &mailbox_count,
+ &target_mailbox_array,
+ false,
+ &err)) {
EM_DEBUG_EXCEPTION("emstorage_get_child_mailbox_list failed. [%d]", err);
goto FINISH_OFF;
}
@@ -768,20 +824,49 @@ INTERNAL_FUNC int emcore_rename_mailbox(int input_mailbox_id, char *input_new_ma
/* Rename mailboxes */
for(i = 0; i < mailbox_count ; i++) {
- EM_DEBUG_LOG_SEC("Rename mailbox_id [%d] mailbox_name [%s]", target_mailbox_array[i].mailbox_id, target_mailbox_array[i].mailbox_name);
+ EM_DEBUG_LOG_SEC("Rename mailbox_id [%d], mailbox_name [%s], old_mailbox_name [%s]",
+ target_mailbox_array[i].mailbox_id,
+ target_mailbox_array[i].mailbox_name,
+ old_mailbox_name);
+
+ if (old_mailbox_name && strcasecmp(target_mailbox_array[i].mailbox_name, old_mailbox_name)) {
+ if (!strstr(target_mailbox_array[i].mailbox_name, "/")) {
+ EM_DEBUG_LOG("Not folder");
+ continue;
+ }
+ }
- if(input_mailbox_id == target_mailbox_array[i].mailbox_id) {
- if ((err = emstorage_rename_mailbox(target_mailbox_array[i].mailbox_id, new_mailbox_name, input_new_mailbox_alias, input_eas_data, input_eas_data_length, true)) != EMAIL_ERROR_NONE) {
+ if (input_mailbox_id == target_mailbox_array[i].mailbox_id) {
+ if ((err = emstorage_rename_mailbox(multi_user_name,
+ target_mailbox_array[i].mailbox_id,
+ new_mailbox_name,
+ input_new_mailbox_alias,
+ input_eas_data,
+ input_eas_data_length,
+ true)) != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("emstorage_rename_mailbox failed [%d]", err);
goto FINISH_OFF;
}
}
else {
- EM_DEBUG_LOG_SEC("target_mailbox_array[i].mailbox_name[%s] old_mailbox_name[%s] input_new_mailbox_name [%s]", target_mailbox_array[i].mailbox_name, old_mailbox_name, new_mailbox_name);
- renamed_mailbox_name = em_replace_string(target_mailbox_array[i].mailbox_name, old_mailbox_name, new_mailbox_name);
+ EM_DEBUG_LOG_SEC("target_mailbox_array[i].mailbox_name[%s] "
+ "old_mailbox_name[%s] "
+ "new_mailbox_name [%s]",
+ target_mailbox_array[i].mailbox_name,
+ old_mailbox_name,
+ new_mailbox_name);
+ renamed_mailbox_name = em_replace_string(target_mailbox_array[i].mailbox_name,
+ old_mailbox_name,
+ new_mailbox_name);
EM_DEBUG_LOG_SEC("renamed_mailbox_name[%s]", renamed_mailbox_name);
- if ((err = emstorage_rename_mailbox(target_mailbox_array[i].mailbox_id, renamed_mailbox_name, target_mailbox_array[i].alias, NULL, 0, true)) != EMAIL_ERROR_NONE) {
+ if ((err = emstorage_rename_mailbox(multi_user_name,
+ target_mailbox_array[i].mailbox_id,
+ renamed_mailbox_name,
+ target_mailbox_array[i].alias,
+ NULL,
+ 0,
+ true)) != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("emstorage_rename_mailbox failed [%d]", err);
goto FINISH_OFF;
}
@@ -791,6 +876,7 @@ INTERNAL_FUNC int emcore_rename_mailbox(int input_mailbox_id, char *input_new_ma
}
FINISH_OFF:
+
EM_SAFE_FREE(renamed_mailbox_name);
EM_SAFE_FREE(old_mailbox_name);
EM_SAFE_FREE(new_mailbox_name);
@@ -813,9 +899,11 @@ FINISH_OFF:
extern long smtp_send(SENDSTREAM *stream, char *command, char *args);
#endif /* __FEATURE_KEEP_CONNECTION__ */
-INTERNAL_FUNC int emcore_connect_to_remote_mailbox_with_account_info (email_account_t *account,
- int input_mailbox_id, void **result_stream, /*either MAILSTREAM or SENDSTREAM*/
- int *err_code)
+INTERNAL_FUNC int emcore_connect_to_remote_mailbox_with_account_info (char *multi_user_name,
+ email_account_t *account,
+ int input_mailbox_id,
+ /*either MAILSTREAM or SENDSTREAM*/ void **result_stream,
+ int *err_code)
{
EM_PROFILE_BEGIN(emCoreMailboxOpen);
EM_DEBUG_FUNC_BEGIN("account[%p], input_mailbox_id[%d], mail_stream[%p], err_code[%p]", account, input_mailbox_id,
@@ -865,17 +953,16 @@ INTERNAL_FUNC int emcore_connect_to_remote_mailbox_with_account_info (email_acco
EM_DEBUG_LOG("Stream reuse desired");
#endif
+ /* set current network error as EMAIL_ERROR_NONE before network operation */
session->error = EMAIL_ERROR_NONE;
- emcore_set_network_error (EMAIL_ERROR_NONE); /* set current network error as EMAIL_ERROR_NONE before network operation */
-
+ emcore_set_network_error(EMAIL_ERROR_NONE);
+
if (input_mailbox_id == EMAIL_CONNECT_FOR_SENDING) {
mailbox_name = EM_SAFE_STRDUP(ENCODED_PATH_SMTP);
- }
- else if (input_mailbox_id == 0) {
+ } else if (input_mailbox_id == 0) {
mailbox_name = NULL;
- }
- else {
- if ((error = emstorage_get_mailbox_by_id (input_mailbox_id, &mailbox)) != EMAIL_ERROR_NONE || !mailbox) {
+ } else {
+ if ((error = emstorage_get_mailbox_by_id (multi_user_name, input_mailbox_id, &mailbox)) != EMAIL_ERROR_NONE || !mailbox) {
EM_DEBUG_EXCEPTION("emstorage_get_mailbox_by_id failed [%d]", error);
goto FINISH_OFF;
}
@@ -884,7 +971,12 @@ INTERNAL_FUNC int emcore_connect_to_remote_mailbox_with_account_info (email_acco
if (is_connection_for == _SERVICE_THREAD_TYPE_RECEIVING) {
/* open pop3/imap server */
- if (!emcore_get_long_encoded_path_with_account_info (account, mailbox_name, '/', &mbox_path, &error)) {
+ if (!emcore_get_long_encoded_path_with_account_info(multi_user_name,
+ account,
+ mailbox_name,
+ '/',
+ &mbox_path,
+ &error)) {
EM_DEBUG_EXCEPTION("emcore_get_long_encoded_path failed - %d", error);
session->error = error;
goto FINISH_OFF;
@@ -894,32 +986,39 @@ INTERNAL_FUNC int emcore_connect_to_remote_mailbox_with_account_info (email_acco
session->auth = 0; /* ref_account->receiving_auth ? 1 : 0 */
- if (!(*result_stream = mail_open (*result_stream, mbox_path, IMAP_2004_LOG))) {
- EM_DEBUG_EXCEPTION("mail_open failed. session->error[%d], session->network[%d]", session->error, session->network);
- *result_stream = mail_close (*result_stream);
+ if (!(*result_stream = mail_open(*result_stream, mbox_path, IMAP_2004_LOG))) {
+ EM_DEBUG_EXCEPTION("mail_open failed. session->error[%d], session->network[%d]",
+ session->error, session->network);
+ *result_stream = mail_close(*result_stream);
+
+ if (account->account_id > 0 && (session->network == EMAIL_ERROR_XOAUTH_BAD_REQUEST ||
+ session->network == EMAIL_ERROR_XOAUTH_INVALID_UNAUTHORIZED)) {
+ error = emcore_refresh_xoauth2_access_token (multi_user_name, account->account_id);
- if(account->account_id > 0 && (session->network == EMAIL_ERROR_XOAUTH_BAD_REQUEST || session->network == EMAIL_ERROR_XOAUTH_INVALID_UNAUTHORIZED)) {
- if((error = emcore_refresh_xoauth2_access_token (account->account_id)) != EMAIL_ERROR_NONE) {
+ if (error != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("emcore_refresh_xoauth2_access_token failed. [%d]", error);
- }
- else {
+ } else {
while (*result_stream == NULL && connection_retry_count < 3) {
sleep(3); /* wait for updating access token */
- if (!(*result_stream = mail_open (*result_stream, mbox_path, IMAP_2004_LOG))) {
- EM_DEBUG_LOG("mail_open failed. session->error[%d], session->network[%d]", session->error, session->network);
+ if (!(*result_stream = mail_open(*result_stream, mbox_path, IMAP_2004_LOG))) {
+ EM_DEBUG_LOG("mail_open failed. session->error[%d], session->network[%d]",
+ session->error, session->network);
}
connection_retry_count++;
EM_DEBUG_LOG ("connection_retry_count [%d]", connection_retry_count);
}
}
- } else if ((session->error == EMAIL_ERROR_TLS_SSL_FAILURE || session->error == EMAIL_ERROR_CANNOT_NEGOTIATE_TLS)) {
+ } else if ((session->error == EMAIL_ERROR_TLS_SSL_FAILURE ||
+ session->error == EMAIL_ERROR_CANNOT_NEGOTIATE_TLS)) {
char *replaced_mbox_path = NULL;
replaced_mbox_path = em_replace_string(mbox_path, "}", "/force_tls_v1_0}");
- if (replaced_mbox_path != NULL && !(*result_stream = mail_open (*result_stream, replaced_mbox_path, IMAP_2004_LOG))) {
- EM_DEBUG_EXCEPTION("retry --> mail_open failed. session->error[%d], session->network[%d]", session->error, session->network);
- *result_stream = mail_close (*result_stream);
+ if (replaced_mbox_path != NULL &&
+ !(*result_stream = mail_open(*result_stream, replaced_mbox_path, IMAP_2004_LOG))) {
+ EM_DEBUG_EXCEPTION("retry --> mail_open failed. session->error[%d], session->network[%d]",
+ session->error, session->network);
+ *result_stream = mail_close(*result_stream);
}
EM_SAFE_FREE(replaced_mbox_path);
@@ -932,8 +1031,7 @@ INTERNAL_FUNC int emcore_connect_to_remote_mailbox_with_account_info (email_acco
goto FINISH_OFF;
}
}
- }
- else {
+ } else {
/* open smtp server */
char *host_list[2] = {NULL, NULL};
@@ -953,7 +1051,12 @@ INTERNAL_FUNC int emcore_connect_to_remote_mailbox_with_account_info (email_acco
}
#endif
if (!*result_stream) {
- if (!emcore_get_long_encoded_path_with_account_info (account, mailbox_name, 0, &mbox_path, &error)) {
+ if (!emcore_get_long_encoded_path_with_account_info(multi_user_name,
+ account,
+ mailbox_name,
+ 0,
+ &mbox_path,
+ &error)) {
EM_DEBUG_EXCEPTION(" emcore_get_long_encoded_path failed - %d", error);
session->error = error;
goto FINISH_OFF;
@@ -967,13 +1070,16 @@ INTERNAL_FUNC int emcore_connect_to_remote_mailbox_with_account_info (email_acco
if (!(*result_stream = smtp_open (host_list, 1))) {
EM_DEBUG_EXCEPTION_SEC("smtp_open error : outgoing_server_secure_connection[%d] "
- "session->error[%d] session->network[%d]",
- account->outgoing_server_secure_connection, session->error, session->network);
+ "session->error[%d] session->network[%d]",
+ account->outgoing_server_secure_connection,
+ session->error, session->network);
if (account->account_id > 0 && (session->network == EMAIL_ERROR_XOAUTH_BAD_REQUEST ||
- session->network == EMAIL_ERROR_XOAUTH_INVALID_UNAUTHORIZED)) {
- *result_stream = smtp_close (*result_stream);
- if((error = emcore_refresh_xoauth2_access_token (account->account_id)) != EMAIL_ERROR_NONE) {
+ session->network == EMAIL_ERROR_XOAUTH_INVALID_UNAUTHORIZED)) {
+ *result_stream = smtp_close(*result_stream);
+
+ error = emcore_refresh_xoauth2_access_token(multi_user_name, account->account_id);
+ if (error != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION ("emcore_refresh_xoauth2_access_token failed. [%d]", error);
if ((session->error == EMAIL_ERROR_UNKNOWN) || (session->error == EMAIL_ERROR_NONE))
session->error = EMAIL_ERROR_CONNECTION_FAILURE;
@@ -982,8 +1088,7 @@ INTERNAL_FUNC int emcore_connect_to_remote_mailbox_with_account_info (email_acco
}
sleep(2); /* wait for updating access token */
-
- if (!(*result_stream = smtp_open (host_list, 1))) {
+ if (!(*result_stream = smtp_open(host_list, 1))) {
if (session->network != EMAIL_ERROR_NONE)
session->error = session->network;
if ((session->error == EMAIL_ERROR_UNKNOWN) || (session->error == EMAIL_ERROR_NONE))
@@ -992,8 +1097,7 @@ INTERNAL_FUNC int emcore_connect_to_remote_mailbox_with_account_info (email_acco
error = session->error;
goto FINISH_OFF;
}
- }
- else {
+ } else {
error = EMAIL_ERROR_CONNECTION_FAILURE;
goto FINISH_OFF;
}
@@ -1053,7 +1157,7 @@ emcore_close_mailbox uses mail_close inside it.
mail_close is only used in emcore_connect_to_remote_mailbox and emcore_reset_streams as an exception to above rule*/
-INTERNAL_FUNC int emcore_connect_to_remote_mailbox(int account_id, char *mailbox, void **mail_stream, int *err_code)
+INTERNAL_FUNC int emcore_connect_to_remote_mailbox(char *multi_user_name, int account_id, char *mailbox, void **mail_stream, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("account_id[%d], mailbox[%p], mail_stream[%p], err_code[%p]", account_id, mailbox, mail_stream, err_code);
@@ -1061,15 +1165,14 @@ INTERNAL_FUNC int emcore_connect_to_remote_mailbox(int account_id, char *mailbox
int error = EMAIL_ERROR_NONE;
email_account_t *ref_account = NULL;
- ref_account = emcore_get_account_reference(account_id);
-
+ ref_account = emcore_get_account_reference(multi_user_name, account_id, false);
if (!ref_account) {
EM_DEBUG_EXCEPTION("emcore_get_account_reference failed - account id[%d]", account_id);
error = EMAIL_ERROR_INVALID_ACCOUNT;
goto FINISH_OFF;
}
-
- ret = emcore_connect_to_remote_mailbox_with_account_info(ref_account, mailbox, mail_stream, &error);
+
+ ret = emcore_connect_to_remote_mailbox_with_account_info(multi_user_name, ref_account, mailbox, mail_stream, &error);
FINISH_OFF:
@@ -1080,6 +1183,7 @@ FINISH_OFF:
if (err_code)
*err_code = error;
+
EM_DEBUG_FUNC_END("ret [%d]", ret);
return ret;
}
@@ -1124,7 +1228,7 @@ INTERNAL_FUNC void emcore_reset_streams()
#else /* __FEATURE_KEEP_CONNECTION__ */
-INTERNAL_FUNC int emcore_connect_to_remote_mailbox(int account_id, int input_mailbox_id, void **mail_stream, int *err_code)
+INTERNAL_FUNC int emcore_connect_to_remote_mailbox(char *multi_user_name, int account_id, int input_mailbox_id, void **mail_stream, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("account_id[%d], input_mailbox_id[%d], mail_stream[%p], err_code[%p]", account_id, input_mailbox_id, mail_stream, err_code);
@@ -1133,8 +1237,7 @@ INTERNAL_FUNC int emcore_connect_to_remote_mailbox(int account_id, int input_mai
email_session_t *session = NULL;
email_account_t *ref_account = NULL;
- ref_account = emcore_get_account_reference(account_id);
-
+ ref_account = emcore_get_account_reference(multi_user_name, account_id, false);
if (!ref_account) {
EM_DEBUG_EXCEPTION("emcore_get_account_reference failed - account id[%d]", account_id);
error = EMAIL_ERROR_INVALID_ACCOUNT;
@@ -1158,7 +1261,7 @@ INTERNAL_FUNC int emcore_connect_to_remote_mailbox(int account_id, int input_mai
goto FINISH_OFF; */
}
- ret = emcore_connect_to_remote_mailbox_with_account_info(ref_account, input_mailbox_id, mail_stream, &error);
+ ret = emcore_connect_to_remote_mailbox_with_account_info(multi_user_name, ref_account, input_mailbox_id, mail_stream, &error);
EM_DEBUG_LOG("ret[%d] incoming_server_type[%d] input_mailbox_id[%d]", ret, ref_account->incoming_server_type, input_mailbox_id);
@@ -1169,8 +1272,7 @@ INTERNAL_FUNC int emcore_connect_to_remote_mailbox(int account_id, int input_mai
if (send_stream->protocol.esmtp.size.ok && send_stream->protocol.esmtp.size.limit > 0) {
EM_DEBUG_LOG("Server size limit : %ld", send_stream->protocol.esmtp.size.limit);
if (send_stream->protocol.esmtp.size.limit != ref_account->outgoing_server_size_limit) {
- emstorage_set_field_of_accounts_with_integer_value(account_id, "outgoing_server_size_limit", send_stream->protocol.esmtp.size.limit, true);
- emcore_init_account_reference();
+ emstorage_set_field_of_accounts_with_integer_value(multi_user_name, account_id, "outgoing_server_size_limit", send_stream->protocol.esmtp.size.limit, true);
}
}
}
@@ -1188,8 +1290,7 @@ INTERNAL_FUNC int emcore_connect_to_remote_mailbox(int account_id, int input_mai
ref_account->retrieval_mode += EMAIL_IMAP4_IDLE_SUPPORTED;
else
ref_account->retrieval_mode -= EMAIL_IMAP4_IDLE_SUPPORTED;
- emstorage_set_field_of_accounts_with_integer_value(account_id, "retrieval_mode", ref_account->retrieval_mode, true);
- emcore_init_account_reference();
+ emstorage_set_field_of_accounts_with_integer_value(multi_user_name, account_id, "retrieval_mode", ref_account->retrieval_mode, true);
}
}
}
@@ -1389,14 +1490,14 @@ FINISH_OFF:
return ret;
}
-INTERNAL_FUNC int emcore_partial_body_thd_local_activity_sync(int *is_event_inserted, int *err_code)
+INTERNAL_FUNC int emcore_partial_body_thd_local_activity_sync(char *multi_user_name, int *is_event_inserted, int *err_code)
{
EM_DEBUG_FUNC_BEGIN();
int activity_count = 0;
int ret = false;
int error = EMAIL_ERROR_NONE;
- if (false == emstorage_get_pbd_activity_count(&activity_count, false, &error)) {
+ if (false == emstorage_get_pbd_activity_count(multi_user_name, &activity_count, false, &error)) {
EM_DEBUG_LOG("emstorage_get_pbd_activity_count failed [%d]", error);
goto FINISH_OFF;
}
@@ -1436,7 +1537,7 @@ FINISH_OFF:
return ret;
}
-INTERNAL_FUNC int emcore_get_mailbox_by_type(int account_id, email_mailbox_type_e mailbox_type, email_mailbox_t *result_mailbox, int *err_code)
+INTERNAL_FUNC int emcore_get_mailbox_by_type(char *multi_user_name, int account_id, email_mailbox_type_e mailbox_type, email_mailbox_t *result_mailbox, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("account_id [%d], result_mailbox [%p], err_code [%p]", account_id, result_mailbox, err_code);
int ret = false, err = EMAIL_ERROR_NONE;
@@ -1448,8 +1549,7 @@ INTERNAL_FUNC int emcore_get_mailbox_by_type(int account_id, email_mailbox_type_
goto FINISH_OFF;
}
- if (!emstorage_get_mailbox_by_mailbox_type(account_id, mailbox_type, &mail_box_tbl_spam, false, &err)) {
-
+ if (!emstorage_get_mailbox_by_mailbox_type(multi_user_name, account_id, mailbox_type, &mail_box_tbl_spam, false, &err)) {
EM_DEBUG_LOG("emstorage_get_mailbox_by_mailbox_type failed - %d", err);
}
else {
diff --git a/email-core/email-core-mime.c b/email-core/email-core-mime.c
index 33a1df4..b86a4fd 100755
--- a/email-core/email-core-mime.c
+++ b/email-core/email-core-mime.c
@@ -43,7 +43,6 @@
#include "email-internal-types.h"
#include "lnx_inc.h"
#include "email-utilities.h"
-#include "email-core-global.h"
#include "email-core-utils.h"
#include "email-core-mail.h"
#include "email-core-mime.h"
@@ -53,6 +52,7 @@
#include "email-core-account.h"
#include "email-core-signal.h"
#include "email-core-mailbox-sync.h"
+#include "email-core-container.h"
#include "email-debug-log.h"
#define MIME_MESG_IS_SOCKET
@@ -98,9 +98,6 @@
#define SAVE_TYPE_BUFFER 2 /* save content to buffe */
#define SAVE_TYPE_FILE 3 /* save content to temporary fil */
-#define EML_FOLDER 20 /* save eml content to temporary folder */
-
-
/* ---------------------------------------------------------------------- */
/* Global variable */
static int eml_data_count = 0;
@@ -124,32 +121,6 @@ extern bool only_body_download;
__thread BODY **g_inline_list = NULL;
__thread int g_inline_count = 0;
-/* Function Declaration */
-
-/* parsing the first header (RFC822 Header and Message Header and Etc... */
-static int emcore_mime_parse_header(void *stream, int is_file, struct _rfc822header **rfcheader, struct _m_mesg_header **header, int *err_code);
-
-/* parsing the first bod */
-static int emcore_mime_parse_body(void *stream, int is_file, struct _m_mesg *mmsg, struct _m_content_info *cnt_info, void *callback, int *err_code);
-
-/* parsing the message part header (CONTENT-... header */
-static int emcore_mime_parse_part_header(void *stream, int is_file, struct _m_part_header **header, int *err_code);
-
-/* parsing the message part by boundar */
-static int emcore_mime_parse_part(void *stream, int is_file, struct _m_part_header *parent_header, struct _m_part *nested, struct _m_content_info *cnt_info, int *end_of_parsing, int *err_code);
-
-/* set RFC822 Header valu */
-static int emcore_mime_set_rfc822_header_value(struct _rfc822header **rfc822header, char *name, char *value, int *err_code);
-
-/* set Message Part Header (Content-... Header */
-static int emcore_mime_set_part_header_value(struct _m_part_header **header, char *name, char *value, int *err_code);
-
-static int emcore_mime_get_param_from_str(char *str, struct _parameter **param, int *err_code);
-
-static int emcore_mime_add_param_to_list(struct _parameter **param_list, struct _parameter *param, int *err_code);
-
-char *emcore_mime_get_header_value(struct _m_part_header *header, int type, int *err_code);
-
void emcore_mime_free_param(struct _parameter *param);
void emcore_mime_free_part_header(struct _m_part_header *header);
void emcore_mime_free_message_header(struct _m_mesg_header *header);
@@ -158,39 +129,6 @@ void emcore_mime_free_part(struct _m_part *part);
void emcore_mime_free_part_body(struct _m_body *body);
void emcore_mime_free_mime(struct _m_mesg *mmsg);
-/* get content data and save buffer or fil */
-/* mode - 1 : get the only siz */
-/* 2 : save content to buffer (holder is buffer */
-/* 3 : save content to file (holder is file name */
-static int emcore_mime_get_content_data(void *stream,
- int is_file,
- char *boundary_str,
- char *content_encoding,
- int *end_of_parsing,
- int mode,
- char **holder,
- int *size,
- void *callback,
- int *err_code);
-
-int emcore_decode_body_text_from_sock(void *stream, char *boundary_str, int encoding, int mode, int fd, char **holder, int *end_of_parsing, int *size);
-int emcore_decode_body_text_from_file(FILE *stream, char *boundary_str, int encoding, int mode, int fd, char **holder, int *end_of_parsing, int *size);
-/* skip content data to boundary_str or end of fil */
-int emcore_mime_skip_content_data(void *stream,
- int is_file,
- char *boundary_str,
- int *end_of_parsing,
- int *size,
- void *callback,
- int *err_code);
-
-static int emcore_get_file_pointer(BODY *body, bool input_check_duplicated_file_name, char *buf, struct _m_content_info *cnt_info , int *err);
-static PARTLIST *emcore_get_body_full(MAILSTREAM *stream, int msg_uid, BODY *body, struct _m_content_info *cnt_info, int *err_code, PARTLIST *section_list);
-static int emcore_get_body_part_imap_full(MAILSTREAM *stream, int msg_uid, int account_id, int mail_id, PARTLIST *section_list, struct _m_content_info *cnt_info, int *err_code, int event_handle);
-static PARTLIST *emcore_add_node(PARTLIST *section_list, BODY *body);
-static void emcore_free_section_list(PARTLIST *section_list);
-static int emcore_get_section_body_size(char *response, char *section, int *body_size);
-static void parse_file_path_to_filename(char *src_string, char **out_string);
extern long pop3_reply (MAILSTREAM *stream);
/* ------------------------------------------------------------------------------------------------- */
@@ -204,14 +142,14 @@ char *em_get_escaped_str(const char *str)
if (!str)
return NULL;
len = strlen(str);
- int ret_i = 0;
- const char to_be_escaped[10] = {'\\', '\"', '\0',};
char *ret = calloc(1, 2 * len);
if (ret == NULL) {
- EM_DEBUG_EXCEPTION("calloc failed");
return NULL;
}
+ int ret_i = 0;
+ const char to_be_escaped[10] = {'\\', '\"', '\0',};
+
for (i = 0; i < len; i++) {
for (j = 0; to_be_escaped[j] != '\0'; j++) {
if (str[i] == to_be_escaped[j]) {
@@ -242,11 +180,17 @@ char *em_split_file_path(char *str)
char *temp_cid_data = NULL;
char *temp_cid = NULL;
- temp_str = EM_SAFE_STRDUP(str);
+ if (str == NULL) {
+ EM_DEBUG_EXCEPTION("Invalid parameter");
+ return NULL;
+ }
+
+ temp_str = g_strdup(str);
buf_length = EM_SAFE_STRLEN(str) + 1024;
buf = em_malloc(buf_length);
if (buf == NULL) {
EM_DEBUG_EXCEPTION("em_malloc failed");
+ EM_SAFE_FREE(temp_str);
return NULL;
}
@@ -261,6 +205,7 @@ char *em_split_file_path(char *str)
temp_cid_data = em_malloc((temp_cid-temp_str)+1);
if (temp_cid_data == NULL) {
EM_DEBUG_EXCEPTION("em_malloc failed");
+ EM_SAFE_FREE(buf);
return temp_str;
}
@@ -302,1434 +247,6 @@ char *em_split_file_path(char *str)
return buf;
}
-
-static char *em_replace_string_with_split_file_path(char *source_string, char *old_string, char *new_string)
-{
- EM_DEBUG_FUNC_BEGIN();
- char *buffer = NULL;
- char *split_str = NULL;
- char *p = NULL;
- char *q = NULL;
- int buf_len = 0;
-
- EM_IF_NULL_RETURN_VALUE(source_string, NULL);
- EM_IF_NULL_RETURN_VALUE(old_string, NULL);
- EM_IF_NULL_RETURN_VALUE(new_string, NULL);
-
- EM_DEBUG_LOG("source_string [%s] ", source_string);
- EM_DEBUG_LOG("old_string [%s] ", old_string);
- EM_DEBUG_LOG("new_string [%s] ", new_string);
-
- p = strstr(source_string, old_string);
-
- if (!p) {
- EM_DEBUG_EXCEPTION("Orig not found in source_string");
- return NULL;
- }
-
- buf_len = EM_SAFE_STRLEN(source_string) + 1024;
- buffer = (char *)em_malloc(buf_len);
- if (buffer == NULL) {
- EM_DEBUG_EXCEPTION("em_malloc failed");
- return NULL;
- }
-
- if (p - source_string < EM_SAFE_STRLEN(source_string) + 1024 + 1) {
- strncpy(buffer, source_string, p - source_string);
-
- EM_DEBUG_LOG("BUFFER [%s]", buffer);
-
- split_str = em_split_file_path(p);
- if (!split_str) {
- EM_DEBUG_EXCEPTION(">> SPLIT STRING IS NULL ");
- goto FINISH_OFF;
- }
-
- q = strstr(split_str, old_string);
- if (q) {
- EM_DEBUG_LOG("Split string [%s]", split_str);
- snprintf(buffer + EM_SAFE_STRLEN(buffer), buf_len - EM_SAFE_STRLEN(buffer), "%s%s", new_string, q+strlen(old_string)); /*prevent 34353*/
- EM_DEBUG_LOG("BUFFER 1 [%s]", buffer);
- EM_SAFE_FREE(split_str);
- EM_DEBUG_FUNC_END("Suceeded");
- return buffer;
- }
- }
- else {
- EM_DEBUG_EXCEPTION("Buffer is too small.");
- EM_SAFE_FREE(buffer);
- return NULL;
- }
-
-FINISH_OFF:
- EM_SAFE_FREE(split_str);
- EM_SAFE_FREE(buffer);
-
- EM_DEBUG_FUNC_END("Failed");
- return NULL;
-
-}
-
-
-int emcore_mime_flush_receiving_buffer(void *stream, int is_file, char *boundary_string, char *boundary_end_string, int *end_of_parsing, int *err_code)
-{
- EM_DEBUG_FUNC_BEGIN("stream[%p], is_file[%d], boundary_string[%s], boundary_end_string[%s], end_of_parsing[%p], err_code[%p]", stream, is_file, boundary_string, boundary_end_string, end_of_parsing, err_code);
- int err = EMAIL_ERROR_NONE;
- int local_end_of_parsing = 0;
- char buf[MIME_LINE_LEN] = {0, };
-
- if (!stream) {
- EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
- if (err_code)
- *err_code = EMAIL_ERROR_INVALID_PARAM;
- return false;
- }
-
- while (TRUE) {
-/* Several threads including event thd call it, don't delete comment
- if (!emcore_check_thread_status()) {
- EM_DEBUG_FUNC_END("EMAIL_ERROR_CANCELLED");
- if (err_code)
- *err_code = EMAIL_ERROR_CANCELLED;
- return false;
- }
-*/
- if ((is_file == 0 && !emcore_mime_get_line_from_sock(stream, buf, MIME_LINE_LEN, &err)) ||
- (is_file == 1 && !emcore_get_line_from_file(stream, buf, MIME_LINE_LEN, &err))) {
- if (err != EMAIL_ERROR_NO_MORE_DATA) {
- EM_DEBUG_EXCEPTION("file : [%d], emcore_mime_get_line_from_sock or emcore_mime_get_line_from_file failed", is_file);
- local_end_of_parsing = 0;
- break;
- }
-
- local_end_of_parsing = 1;
- break;
- }
-
- if (boundary_string && boundary_end_string) {
- if (!strcmp(buf, boundary_string)) {
- EM_DEBUG_LOG("found boundary");
- local_end_of_parsing = 0;
- break;
- }
- else if (!strcmp(buf, boundary_end_string)) {
- EM_DEBUG_LOG("found boundary_end");
- local_end_of_parsing = 1;
- break;
- }
- }
- }
-
- if (end_of_parsing)
- *end_of_parsing = local_end_of_parsing;
-
- if (err_code)
- *err_code = err;
-
- EM_DEBUG_FUNC_END();
- return true;
-}
-
-int emcore_parse_mime(void *stream, int is_file, struct _m_content_info *cnt_info, int *err_code)
-{
- EM_DEBUG_FUNC_BEGIN("stream[%p], is_file[%d], cnt_info[%p], err_code[%p]", stream, is_file, cnt_info, err_code);
-
- struct _m_mesg *mmsg = em_malloc(sizeof(struct _m_mesg));
-
- if (!mmsg) return false;
-
- memset(mmsg, 0x00, sizeof(struct _m_mesg));
-
- /* 1. parse the first found header */
- EM_DEBUG_LOG(">>>>>> 1. parse the first found header");
- if (!emcore_mime_parse_header(stream, is_file, &mmsg->rfc822header, &mmsg->header, err_code)) {
- emcore_mime_free_mime(mmsg);
- return false;
- }
-
-/* Several threads including event thd call it, don't delete comment
- if (!emcore_check_thread_status()) {
- if (err_code != NULL)
- *err_code = EMAIL_ERROR_CANCELLED;
- emcore_mime_free_mime(mmsg);
- return false;
- }
-*/
- /* 2. parse body */
- EM_DEBUG_LOG(">>>>>> 2. parse body");
- if (mmsg && mmsg->header && mmsg->header->part_header && mmsg->header->part_header->parameter) {
- EM_DEBUG_LOG_SEC("name[%s]", mmsg->header->part_header->parameter->name);
- EM_DEBUG_LOG("value[%s]", mmsg->header->part_header->parameter->value);
- EM_DEBUG_LOG("next : %p", mmsg->header->part_header->parameter->next);
- }
-
- if (!emcore_mime_parse_body(stream, is_file, mmsg, cnt_info, NULL, err_code)) {
- emcore_mime_free_mime(mmsg);
- return false;
- }
-
- /* 3. free memory */
- EM_DEBUG_LOG(">>>>>> 3. free memory");
- if (mmsg && mmsg->header && mmsg->header->part_header && mmsg->header->part_header->parameter) {
- EM_DEBUG_LOG_SEC("name[%s]", mmsg->header->part_header->parameter->name);
- EM_DEBUG_LOG("value[%s]", mmsg->header->part_header->parameter->value);
- EM_DEBUG_LOG("next : %p", mmsg->header->part_header->parameter->next);
- }
- emcore_mime_free_mime(mmsg);
- EM_DEBUG_FUNC_END();
- return true;
-}
-
-int emcore_mime_parse_header(void *stream, int is_file, struct _rfc822header **rfc822header, struct _m_mesg_header **header, int *err_code)
-{
- EM_DEBUG_FUNC_BEGIN("stream[%p], is_file[%d], rfc822header[%p], header[%p], err_code[%p]", stream, is_file, rfc822header, header, err_code);
-
- struct _m_mesg_header *tmp_header = NULL;
- struct _rfc822header *tmp_rfc822header = NULL;
- char buf[MIME_LINE_LEN] = {0, };
- char *name = NULL;
- char *value = NULL;
- char *pTemp = NULL;
- int is_longheader;
-
-/* Several threads including event thd call it, don't delete comment
- if (!emcore_check_thread_status()) {
- if (err_code != NULL)
- *err_code = EMAIL_ERROR_CANCELLED;
- return false;
- }
-*/
-
- if ((is_file == 0 && !emcore_mime_get_line_from_sock(stream, buf, MIME_LINE_LEN, err_code)) ||
- (is_file == 1 && !emcore_get_line_from_file(stream, buf, MIME_LINE_LEN, err_code))) {
- return false;
- }
-
- if (!(tmp_header = em_malloc(sizeof(struct _m_mesg_header)))) {
- EM_DEBUG_EXCEPTION("malloc failed...");
- if (err_code != NULL)
- *err_code = EMAIL_ERROR_OUT_OF_MEMORY;
- return false;
- }
-
-/* Several threads including event thd call it, don't delete comment
- if (!emcore_check_thread_status()) {
- if (err_code != NULL)
- *err_code = EMAIL_ERROR_CANCELLED;
- return false;
- }
-*/
-
- while (TRUE) {
- EM_DEBUG_LOG("buf[%s]", buf);
-
- if (!strncmp(buf, CRLF_STRING, 2))
- break;
-
- is_longheader = (buf[0] == ' ' || buf[0] == '\t') ? TRUE : FALSE;
-
-
- if (!is_longheader) { /* Normal header (format : "Name : Value" or "Name : Value; Parameters" */
- if (name) {
- EM_SAFE_FREE(name);
- }
-
- if ((pTemp = strtok(buf, ":")) == NULL)
- break;
-
- name = EM_SAFE_STRDUP(pTemp);
-
- value = strtok(NULL, CRLF_STRING);
-
- if (name) em_upper_string(name);
- }
- else { /* Long header */
- value = strtok(buf, CRLF_STRING);
- em_trim_left(value);
- }
-
- /* --> 2007-05-08 by cy */
- if (!name)
- break;
-
- EM_DEBUG_LOG_SEC("> name[%s]", name);
- EM_DEBUG_LOG("> value[%s]", value);
-
- /* MIME Part Header */
- if (memcmp(name, "CONTENT-", 8) == 0 && value) {
- emcore_mime_set_part_header_value(&tmp_header->part_header, name, value, err_code);
-
- if (tmp_header->part_header && tmp_header->part_header->parameter) {
- EM_DEBUG_LOG_SEC("name[%s]", tmp_header->part_header->parameter->name);
- EM_DEBUG_LOG("value[%s]", tmp_header->part_header->parameter->value);
- EM_DEBUG_LOG("next : %p", tmp_header->part_header->parameter->next);
- }
-
- /* MIME Version Header */
- }
- else if (memcmp(name, "MIME-VERSION", 12) == 0) {
- /* EM_DEBUG_FUNC_BEGIN() */
- /* ignored because we need only contents information */
- /* tmp_header->version = EM_SAFE_STRDUP(value) */
- /* RFC822 Header */
- }
- /*
- else if (strncmp(name, "MESSAGE-CONTEXT", strlen("MESSAGE-CONTEXT")) == 0) {
- em_upper_string(value);
- tmp_header->message_context = EM_SAFE_STRDUP(value);
- }
- else if (strncmp(name, "CONTENT-DURATION", strlen("CONTENT-DURATION")) == 0) {
- tmp_header->content_duration = atoi(value);
- }
- else if (strncmp(name, "X-CONTENT-PAGES", strlen("X-CONTENT-PAGES")) == 0) {
- tmp_header->x_content_pages = atoi(value);
- }
- else if (strncmp(name, "SENSITIVITY", strlen("SENSITIVITY")) == 0) {
- em_upper_string(value);
- tmp_header->sensitivity = EM_SAFE_STRDUP(value);
- }
- */
- else {
- /* in socket stream case, ignored because we need only contents information */
- if (is_file == 1)
- emcore_mime_set_rfc822_header_value(&tmp_rfc822header, name, value, err_code);
- }
-
-/* Several threads including event thd call it, don't delete comment
- if (!emcore_check_thread_status()) {
- if (err_code != NULL)
- *err_code = EMAIL_ERROR_CANCELLED;
- return false;
- }
-*/
-
- if ((is_file == 0 && !emcore_mime_get_line_from_sock(stream, buf, MIME_LINE_LEN, err_code)) ||
- (is_file == 1 && !emcore_get_line_from_file(stream, buf, MIME_LINE_LEN, err_code))) {
-
- if (tmp_rfc822header)
- emcore_mime_free_rfc822_header(tmp_rfc822header);
-
-
- if (tmp_header) {
- emcore_mime_free_part_header(tmp_header->part_header);
-
- EM_SAFE_FREE(tmp_header->version);
- EM_SAFE_FREE(tmp_header);
- }
- return false;
- }
- }
-
- *header = tmp_header;
- *rfc822header = tmp_rfc822header;
-
- EM_SAFE_FREE(name);
- EM_DEBUG_FUNC_END();
- return true;
-}
-
-int emcore_mime_parse_part_header(void *stream, int is_file, struct _m_part_header **header, int *err_code)
-{
- EM_DEBUG_FUNC_BEGIN("stream[%p], is_file[%d], header[%p], err_code[%p]", stream, is_file, header, err_code);
-
- struct _m_part_header *tmp_header = NULL;
- char buf[MIME_LINE_LEN] = {0x00};
- char *name = NULL;
- char *value = NULL;
- char *p = NULL;
- int is_longheader = false;
-
-/* Several threads including event thd call it, don't delete comment
- if (!emcore_check_thread_status()) {
- if (err_code != NULL)
- *err_code = EMAIL_ERROR_CANCELLED;
- return false;
- }
-*/
-
- if ((is_file == 0 && !emcore_mime_get_line_from_sock(stream, buf, MIME_LINE_LEN, err_code)) ||
- (is_file == 1 && !emcore_get_line_from_file(stream, buf, MIME_LINE_LEN, err_code)))
- return false;
-
- tmp_header = em_malloc(sizeof(struct _m_part_header));
- if (!tmp_header) {
- EM_DEBUG_EXCEPTION("em_malloc failed");
- return false;
- }
-
- memset(tmp_header, 0, sizeof(struct _m_part_header));
-
- while (true) {
- if (!strncmp(buf, CRLF_STRING, EM_SAFE_STRLEN(CRLF_STRING))) break;
-
- is_longheader = (buf[0] == ' ' || buf[0] == TAB);
-
- if (!is_longheader) { /* Normal header (format : "Name : Value" or "Name : Value; Parameters" */
- EM_SAFE_FREE(name);
- p = strtok(buf , ":");
-
- if (p) {
- name = EM_SAFE_STRDUP(p);
- value = strtok(NULL, CRLF_STRING);
- if (value) em_upper_string(name);
- }
- }
- else /* Long header */
- value = strtok(buf, CRLF_STRING);
-
- if (!name)
- break;
-
- emcore_mime_set_part_header_value(&tmp_header, name, value, err_code);
-
-/* Several threads including event thd call it, don't delete comment
- if (!emcore_check_thread_status()) {
- if (err_code != NULL)
- *err_code = EMAIL_ERROR_CANCELLED;
- return false;
- }
-*/
-
- if ((is_file == 0 && !emcore_mime_get_line_from_sock(stream, buf, MIME_LINE_LEN, err_code)) ||
- (is_file == 1 && !emcore_get_line_from_file(stream, buf, MIME_LINE_LEN, err_code))) {
- EM_SAFE_FREE(name);
- EM_SAFE_FREE(tmp_header);
-
- return false;
- }
- }
-
- *header = tmp_header;
-
- EM_SAFE_FREE(name);
- EM_DEBUG_FUNC_END();
- return true;
-}
-
-
-int emcore_mime_parse_body(void *stream, int is_file, struct _m_mesg *mmsg, struct _m_content_info *cnt_info, void *callback, int *err_code)
-{
- EM_DEBUG_FUNC_BEGIN("stream[%p], is_file[%d], mmsg[%p], cnt_info[%p], callback[%p], err_code[%p]", stream, is_file, mmsg, cnt_info, callback, err_code);
-
- if (!mmsg->header) {
- EM_DEBUG_EXCEPTION("Invalid paramter");
- *err_code = EMAIL_ERROR_INVALID_PARAM;
- return false;
- }
-
- char *content_type = NULL, *content_encoding = NULL, *holder = NULL, *attachment_name, *t = NULL;
- int type = 0, end_of_parsing = 0, size;
- int err = EMAIL_ERROR_NONE;
-
-/* Several threads including event thd call it, don't delete comment
- if (!emcore_check_thread_status()) {
- if (err_code != NULL)
- *err_code = EMAIL_ERROR_CANCELLED;
- return false;
- }
-*/
-
- if (mmsg->header)
- content_type = emcore_mime_get_header_value(mmsg->header->part_header, CONTENT_TYPE, err_code);
- if (!content_type)
- content_type = "TEXT/PLAIN";
-
- if (mmsg->header)
- content_encoding = emcore_mime_get_header_value(mmsg->header->part_header, CONTENT_ENCODING, err_code);
- if (!content_encoding)
- content_encoding = "7BIT";
-
- if (strstr(content_type, TEXT_STR)) type = TYPE_TEXT;
- else if (strstr(content_type, IMAGE_STR)) type = TYPE_IMAGE;
- else if (strstr(content_type, AUDIO_STR)) type = TYPE_AUDIO;
- else if (strstr(content_type, VIDEO_STR)) type = TYPE_VIDEO;
- else if (strstr(content_type, APPLICATION_STR)) type = TYPE_APPLICATION;
- else if (strstr(content_type, MULTIPART_STR)) type = TYPE_MULTIPART;
- else if (strstr(content_type, MESSAGE_STR)) type = TYPE_MESSAGE;
- else type = TYPE_UNKNOWN;
-
- switch (type) {
- case TYPE_MULTIPART:
- if (mmsg->header && !emcore_mime_get_header_value(mmsg->header->part_header, CONTENT_BOUNDARY, &err)) {
- EM_DEBUG_FUNC_END("false");
- if (err_code != NULL)
- *err_code = err;
- return false;
- }
-
- if (mmsg->header && !emcore_mime_parse_part(stream, is_file, mmsg->header->part_header, &mmsg->nested, cnt_info, &end_of_parsing, &err)) {
- EM_DEBUG_FUNC_END("false");
- if (err_code != NULL)
- *err_code = err;
- return false;
- }
-
- /* after finishing body parsing, make stream empty to get next mail. (get line from sock or file until '.' is read */
- if (end_of_parsing && err != EMAIL_ERROR_NO_MORE_DATA)
- emcore_mime_flush_receiving_buffer(stream, is_file, NULL, NULL, NULL, NULL);
-
- break;
-
- default:
- attachment_name = NULL;
-
- if (mmsg->header && emcore_mime_get_header_value(mmsg->header->part_header, CONTENT_DISPOSITION, err_code)) {
- attachment_name = emcore_mime_get_header_value(mmsg->header->part_header, CONTENT_FILENAME, err_code);
- /* if (!attachment_name) attachment_name = "unknown" */
- if (attachment_name) EM_DEBUG_LOG_SEC(" attachment = [%s]", attachment_name);
- }
-
- if (strcasestr(content_type, "PKCS7-MIME")) {
- EM_DEBUG_LOG("Encrypted mail do not include the body");
-
- if (attachment_name == NULL)
- attachment_name = emcore_mime_get_header_value(mmsg->header->part_header, CONTENT_NAME, err_code);
-
- EM_DEBUG_LOG_SEC("attachment_name : [%s]", attachment_name);
-
- cnt_info->file = em_malloc(sizeof(struct attachment_info));
- if (cnt_info->file) {
- cnt_info->file->type = ATTACHMENT;
- cnt_info->file->name = EM_SAFE_STRDUP(attachment_name);
- if (!emcore_mime_get_content_data(stream, is_file, NULL, content_encoding, &end_of_parsing, SAVE_TYPE_FILE, &holder, &size, NULL, err_code)) {
- EM_DEBUG_EXCEPTION("emcore_mime_get_content_data failed : [%d]", err_code);
- return false;
- }
- cnt_info->file->save = holder;
- cnt_info->file->size = size;
- cnt_info->file->attachment_mime_type = EM_SAFE_STRDUP(content_type);
- cnt_info->file->next = NULL;
- }
- break;
- }
-
- if (cnt_info->grab_type & GRAB_TYPE_TEXT) {
- /* EM_DEBUG_LINE */
- /* get content data. content data is saved in file */
- if (!emcore_mime_get_content_data(stream, is_file, NULL, content_encoding, &end_of_parsing, SAVE_TYPE_FILE, &holder, &size, NULL, err_code)) {
- EM_DEBUG_EXCEPTION("emcore_mime_get_content_data failed : [%d]", err_code);
- return false;
- }
-
- EM_DEBUG_LOG("After emcore_mime_get_content_data");
-
- char *charset = mmsg->header? emcore_mime_get_header_value(mmsg->header->part_header, CONTENT_CHARSET, err_code) : NULL; /* prevent 27453 */
- EM_DEBUG_LOG(">>>> charset [%s]", charset);
-
- if (mmsg->header && mmsg->header->part_header && strstr((t = emcore_mime_get_header_value(mmsg->header->part_header, CONTENT_TYPE, err_code)) ? t : "", "HTML")) {
- if (!charset || !strncmp(charset, "X-UNKNOWN", strlen("X-UNKNOWN")))
- cnt_info->text.html_charset = strdup("UTF-8");
- else
- cnt_info->text.html_charset = EM_SAFE_STRDUP(charset);
- EM_DEBUG_LOG(">>>> cnt_info->text.html_charset [%s]", cnt_info->text.html_charset);
-
- cnt_info->text.html = holder;
- EM_DEBUG_LOG(">>>> cnt_info->text.html [%s]", cnt_info->text.html);
- }
- else if (mmsg->header) {
-
- if (!charset || !strncmp(charset, "X-UNKNOWN", strlen("X-UNKNOWN")))
- cnt_info->text.plain_charset = strdup("UTF-8");
- else
- cnt_info->text.plain_charset = EM_SAFE_STRDUP(charset);
- EM_DEBUG_LOG(">>>> cnt_info->text.plain_charset [%s]", cnt_info->text.plain_charset);
-
- cnt_info->text.plain = holder;
- EM_DEBUG_LOG(">>>> cnt_info->text.plain [%s]", cnt_info->text.plain);
- }
- }
-
- break;
- }
- EM_DEBUG_FUNC_END();
- return true;
-}
-
-int emcore_mime_parse_part(void *stream, int is_file, struct _m_part_header *parent_header, struct _m_part *nested, struct _m_content_info *cnt_info, int *eop, int *err_code)
-{
- EM_DEBUG_FUNC_BEGIN("stream[%p], is_file[%d], parent_header[%p], nested[%p], cnt_info[%p], eop[%p], err_code[%p]", stream, is_file, parent_header, nested, cnt_info, eop, err_code);
-
- struct _m_body *tmp_body = NULL;
- struct _m_part **p = NULL;
- char buf[MIME_LINE_LEN] = {0x00, };
- char boundary[BOUNDARY_LEN] = {0x00, };
- char boundary_end[BOUNDARY_LEN] = {0x00, };
- char temp_inline_attachment_name[20] = {0x00, };
- char *boundary_str = NULL;
- char *content_type = NULL;
- char *content_encoding = NULL;
- char *holder = NULL;
- char *attachment_name = NULL;
- char *content_id = NULL;
- char *content_disposition = NULL;
- char *pTemp = NULL;
- int type = 0;
- int content_disposition_type = 0;
- int end_of_parsing = 0;
- int size = 0, local_err_code = EMAIL_ERROR_NONE;
- int result = 0;
- int inline_attach_index = 0;
-
- boundary_str = emcore_mime_get_header_value(parent_header, CONTENT_BOUNDARY, err_code);
-
- SNPRINTF(boundary, BOUNDARY_LEN, "--%s%s", boundary_str, CRLF_STRING);
- SNPRINTF(boundary_end, BOUNDARY_LEN, "--%s%s", boundary_str, "--\r\n");
-
- nested->body = NULL;
- nested->next = NULL;
-
- /* goto the first found useful mime dat */
- EM_DEBUG_LOG("Before first loop");
- while (true) {
-/* Several threads including event thd call it, don't delete comment
- if (!emcore_check_thread_status()) {
- if (err_code != NULL)
- *err_code = EMAIL_ERROR_CANCELLED;
- return false;
- }
-*/
- if ((is_file == 0 && !emcore_mime_get_line_from_sock(stream, buf, MIME_LINE_LEN, err_code)) ||
- (is_file == 1 && !emcore_get_line_from_file(stream, buf, MIME_LINE_LEN, err_code))) {
- EM_DEBUG_EXCEPTION("emcore_mime_get_line_from_sock failed.");
- if (eop)
- *eop = true;
- EM_DEBUG_FUNC_END("false");
- return false;
- }
-
- if (!strcmp(buf, boundary))
- break;
- }
-
- EM_DEBUG_LOG("Before second loop");
- while (true) {
- if (!(tmp_body = em_malloc(sizeof(struct _m_body)))) {
- EM_DEBUG_EXCEPTION("em_malloc failed.");
- if (nested->body)
- emcore_mime_free_part_body(nested->body);
- if (nested->next)
- emcore_mime_free_part(nested->next);
- EM_DEBUG_FUNC_END("false");
- return false;
- }
-
- memset(tmp_body, 0, sizeof(struct _m_body));
-
- /* parsing MIME Header */
- if (!emcore_mime_parse_part_header(stream, is_file, &tmp_body->part_header, err_code)) {
- EM_DEBUG_EXCEPTION("emcore_mime_parse_part_header failed.");
- if (nested->body)
- emcore_mime_free_part_body(nested->body);
- if (nested->next)
- emcore_mime_free_part(nested->next);
-
- emcore_mime_free_part_body(tmp_body);
- return false;
- }
-
- content_type = emcore_mime_get_header_value(tmp_body->part_header, CONTENT_TYPE, err_code);
-
- if (!content_type)
- content_type = "TEXT/PLAIN";
-
- content_encoding = emcore_mime_get_header_value(tmp_body->part_header, CONTENT_ENCODING, err_code);
- if (!content_encoding)
- content_encoding = "7BIT";
-
- if (strstr(content_type, TEXT_STR)) type = TYPE_TEXT;
- else if (strstr(content_type, IMAGE_STR)) type = TYPE_IMAGE;
- else if (strstr(content_type, AUDIO_STR)) type = TYPE_AUDIO;
- else if (strstr(content_type, VIDEO_STR)) type = TYPE_VIDEO;
- else if (strstr(content_type, APPLICATION_STR)) type = TYPE_APPLICATION;
- else if (strstr(content_type, MULTIPART_STR)) type = TYPE_MULTIPART;
- else if (strstr(content_type, MESSAGE_STR)) type = TYPE_MESSAGE;
- else type = TYPE_UNKNOWN;
-
- switch (type) {
- case TYPE_MULTIPART:
- EM_DEBUG_LOG("TYPE_MULTIPART");
- if (!emcore_mime_get_header_value(tmp_body->part_header, CONTENT_BOUNDARY, err_code)) {
- EM_DEBUG_EXCEPTION("emcore_mime_get_header_value failed.");
- emcore_mime_free_part_body(tmp_body);
- EM_DEBUG_FUNC_END("false");
- return false;
- }
-
- emcore_mime_parse_part(stream, is_file, tmp_body->part_header, &tmp_body->nested, cnt_info, &end_of_parsing, &local_err_code);
-
- if (!nested->body)
- nested->body = tmp_body;
- else {
- p = &nested->next;
-
- while (*p && (*p)->next)
- *p = (*p)->next;
-
- if (*p)
- p = &(*p)->next;
-
- if (!(*p = em_malloc(sizeof(struct _m_part)))) {
- EM_DEBUG_EXCEPTION("em_malloc failed");
- if (nested->body) emcore_mime_free_part_body(nested->body);
- if (nested->next) emcore_mime_free_part(nested->next);
- emcore_mime_free_part_body(tmp_body);
- EM_DEBUG_FUNC_END("false");
- return false;
- }
-
- (*p)->body = tmp_body;
- (*p)->next = NULL;
- }
-
- if (err_code)
- *err_code = local_err_code;
-
- if (end_of_parsing && local_err_code != EMAIL_ERROR_NO_MORE_DATA) /* working with imap */
- /* if (!end_of_parsing) */ /* working with pop */ {
- EM_DEBUG_LOG("Enter flushing socket buffer.");
- emcore_mime_flush_receiving_buffer(stream, is_file, boundary, boundary_end, &end_of_parsing, err_code);
- }
-
- break;
-
- default:
- EM_DEBUG_LOG("default");
- content_disposition_type = 0;
- attachment_name = NULL;
- content_id = NULL;
- content_disposition = NULL;
-
- /* first check inline content */
- /* if the content id or content location exis */
- content_disposition = emcore_mime_get_header_value(tmp_body->part_header, CONTENT_DISPOSITION, err_code);
- EM_DEBUG_LOG_SEC("content_disposition : [%s]", content_disposition);
-
- content_id = emcore_mime_get_header_value(tmp_body->part_header, CONTENT_ID, err_code);
- EM_DEBUG_LOG_SEC("content_id : [%s]", content_id);
-
- if (content_id) {
- if (emcore_search_string_from_file(cnt_info->text.html, content_id, NULL, &result) == EMAIL_ERROR_NONE && result) {
-
- SNPRINTF(temp_inline_attachment_name, sizeof(temp_inline_attachment_name), "image_%d", ++inline_attach_index);
- attachment_name = temp_inline_attachment_name;
-
- if (emcore_search_string_from_file(cnt_info->text.html, content_id, attachment_name, &result) != EMAIL_ERROR_NONE) {
- EM_DEBUG_EXCEPTION("emcore_search_string_from file failed");
- }
-
- content_disposition_type = INLINE_ATTACHMENT;
-
- } else if (!strcasecmp(content_disposition ? content_disposition : "", "attachment")) {
- attachment_name = emcore_mime_get_header_value(tmp_body->part_header, CONTENT_NAME, err_code);
-
- if (!attachment_name)
- attachment_name = emcore_mime_get_header_value(tmp_body->part_header, CONTENT_FILENAME, err_code);
-
- content_disposition_type = ATTACHMENT;
-
- } else if (!strcasecmp(content_disposition ? content_disposition : "", "inline")) {
- attachment_name = emcore_mime_get_header_value(tmp_body->part_header, CONTENT_NAME, err_code);
-
- if (!attachment_name)
- attachment_name = emcore_mime_get_header_value(tmp_body->part_header, CONTENT_FILENAME, err_code);
-
- content_disposition_type = INLINE_ATTACHMENT;
-
- } else {
- EM_DEBUG_EXCEPTION("Unknown mime type");
- }
- } else {
- if (!strcasecmp(content_disposition ? content_disposition : "", "attachment")) {
- attachment_name = emcore_mime_get_header_value(tmp_body->part_header, CONTENT_NAME, err_code);
-
- if (!attachment_name)
- attachment_name = emcore_mime_get_header_value(tmp_body->part_header, CONTENT_FILENAME, err_code);
-
- if (!attachment_name && type == TYPE_MESSAGE)
- attachment_name = strdup("unknown_name");
-
- content_disposition_type = ATTACHMENT;
-
- } else if (!strcasecmp(content_disposition ? content_disposition : "", "inline")) {
-
- SNPRINTF(temp_inline_attachment_name, sizeof(temp_inline_attachment_name), "image_%d", ++inline_attach_index);
- attachment_name = temp_inline_attachment_name;
-
- if (emcore_search_string_from_file(cnt_info->text.html, content_id, attachment_name, &result) != EMAIL_ERROR_NONE) {
- EM_DEBUG_EXCEPTION("emcore_search_string_from file failed");
- } else {
- content_disposition_type = INLINE_ATTACHMENT;
- }
- } else if (strstr(content_type ? content_type : "", "PKCS7")) {
- attachment_name = emcore_mime_get_header_value(tmp_body->part_header, CONTENT_NAME, err_code);
- EM_DEBUG_LOG_MIME(">> attachment = [%s]", attachment_name ? attachment_name : NIL);
-
- content_disposition_type = ATTACHMENT;
-
- } else {
- EM_DEBUG_LOG("No attachment");
- }
- }
-
-/* Several threads including event thd call it, don't delete comment
- if (!emcore_check_thread_status()) {
- if (err_code != NULL)
- *err_code = EMAIL_ERROR_CANCELLED;
- EM_DEBUG_EXCEPTION("EMAIL_ERROR_CANCELLED");
- emcore_mime_free_part_body(tmp_body);
- EM_DEBUG_FUNC_END("false");
- return false;
- }
-*/
-
- EM_DEBUG_LOG_SEC("attachment_name : [%s]", attachment_name);
- /* get content and content information */
- if (content_disposition_type != ATTACHMENT && content_disposition_type != INLINE_ATTACHMENT) { /* text */
- /* get content by buffer */
- EM_DEBUG_LOG_MIME("attachment_name is NULL. It's a text message");
- if (!emcore_mime_get_content_data(stream, is_file, boundary_str, content_encoding, &end_of_parsing, SAVE_TYPE_FILE, &holder, &size, NULL, err_code)) {
- EM_DEBUG_EXCEPTION("emcore_mime_get_content_data failed [%d]", err_code);
- emcore_mime_free_part_body(tmp_body);
- return false;
- }
-
- EM_DEBUG_LOG("After emcore_mime_get_content_data");
-
- if (cnt_info->grab_type & GRAB_TYPE_TEXT) {
- char *charset = emcore_mime_get_header_value(tmp_body->part_header, CONTENT_CHARSET, err_code);
- EM_DEBUG_LOG(" charset [%s]", charset);
-
- if (tmp_body->part_header && strstr(content_type ? content_type : "", "HTML")) {
- if (!charset || !strncmp(charset, "X-UNKNOWN", strlen("X-UNKNOWN")))
- cnt_info->text.html_charset = strdup("UTF-8");
- else
- cnt_info->text.html_charset = EM_SAFE_STRDUP(charset);
- EM_DEBUG_LOG(" cnt_info->text.html_charset [%s]", cnt_info->text.html_charset);
-
- cnt_info->text.html = holder;
- EM_DEBUG_LOG(" cnt_info->text.html [%s]", cnt_info->text.html);
- } else {
- if (!charset || !strncmp(charset, "X-UNKNOWN", strlen("X-UNKNOWN")))
- cnt_info->text.plain_charset = strdup("UTF-8");
- else
- cnt_info->text.plain_charset = EM_SAFE_STRDUP(charset);
- EM_DEBUG_LOG(" cnt_info->text.plain_charset [%s]", cnt_info->text.plain_charset);
-
- cnt_info->text.plain = holder;
- EM_DEBUG_LOG(" cnt_info->text.plain [%s]", cnt_info->text.plain);
- }
- } else {
- EM_SAFE_FREE (holder);
- }
- } else { /* attachment */
- EM_DEBUG_LOG("attachment_name is not NULL. It's a attachment");
- struct attachment_info *file = NULL;
- struct attachment_info *temp_file = cnt_info->file;
-
- file = em_malloc(sizeof(struct attachment_info));
- if (file == NULL) {
- EM_DEBUG_EXCEPTION("em_malloc failed...");
- emcore_mime_free_part_body(tmp_body);
- EM_DEBUG_FUNC_END("false");
- return false;
- }
-
- file->type = content_disposition_type;
-
- EM_DEBUG_LOG("file->type : %d", file->type);
-
- file->name = EM_SAFE_STRDUP(attachment_name);
- file->content_id = EM_SAFE_STRDUP(tmp_body->part_header->content_id);
- file->attachment_mime_type = EM_SAFE_STRDUP(content_type);
-
-
- /* check if the current file is target file */
- if ((cnt_info->grab_type & GRAB_TYPE_ATTACHMENT) || file->type == INLINE_ATTACHMENT) {
- /* get content by file */
- EM_DEBUG_LOG_MIME("Trying to get content");
- if (!emcore_mime_get_content_data(stream, is_file, boundary_str, content_encoding, &end_of_parsing, SAVE_TYPE_FILE, &holder, &size, NULL, err_code)) {
- EM_DEBUG_EXCEPTION("emcore_mime_get_content_data failed [%d]", err_code);
- emcore_mime_free_part_body(tmp_body);
- emcore_free_attachment_info(file);
- EM_DEBUG_FUNC_END("false");
- return false;
- }
-
- file->save = holder;
- } else {
- /* only get content size */
- EM_DEBUG_LOG_MIME("Pass downloading");
- if (!emcore_mime_get_content_data(stream, is_file, boundary_str, content_encoding, &end_of_parsing, SAVE_TYPE_SIZE, NULL, &size, NULL, err_code)) {
- EM_DEBUG_EXCEPTION("emcore_mime_get_content_data failed [%d]", err_code);
- emcore_mime_free_part_body(tmp_body);
- emcore_free_attachment_info(file);
- EM_DEBUG_FUNC_END("false");
- return false;
- }
-
- file->save = NULL;
- }
-
- if (err_code)
- EM_DEBUG_LOG("end_of_parsing [%d], err_code [%d]", end_of_parsing, *err_code);
-
- file->size = size;
- file->attachment_mime_type = strdup(content_type);
-
- switch (end_of_parsing) {
- case 0:
- case 1:
- /* Downloaded */
- file->save_status = 1;
- break;
- case 2:
- file->save_status = 2;
- break;
- }
-
-
- if (strstr(content_type, APPLICATION_STR)) {
- pTemp = content_type + EM_SAFE_STRLEN(APPLICATION_STR);
-
- if (strcasecmp(pTemp, MIME_SUBTYPE_DRM_OBJECT) == 0)
- file->drm = EMAIL_ATTACHMENT_DRM_OBJECT;
- else if (strcasecmp(pTemp, MIME_SUBTYPE_DRM_RIGHTS) == 0)
- file->drm = EMAIL_ATTACHMENT_DRM_RIGHTS;
- else if (strcasecmp(pTemp, MIME_SUBTYPE_DRM_DCF) == 0)
- file->drm = EMAIL_ATTACHMENT_DRM_DCF;
- }
-
- while (temp_file && temp_file->next)
- temp_file = temp_file->next;
-
- if (temp_file == NULL)
- cnt_info->file = file;
- else
- temp_file->next = file;
- }
-
-/* Several threads including event thd call it, don't delete comment
- if (!emcore_check_thread_status()) {
- if (err_code != NULL)
- *err_code = EMAIL_ERROR_CANCELLED;
- EM_DEBUG_EXCEPTION("EMAIL_ERROR_CANCELLED");
- emcore_mime_free_part_body(tmp_body);
- EM_DEBUG_FUNC_END("false");
- return false;
- }
-*/
-
- if (!nested->body)
- nested->body = tmp_body;
- else {
- p = &nested->next;
-
- while (*p && (*p)->next)
- p = &(*p)->next;
-
- if (*p)
- p = &(*p)->next;
-
- if (!(*p = em_malloc(sizeof(struct _m_part)))) {
- EM_DEBUG_EXCEPTION("em_malloc failed");
- if (nested->body) emcore_mime_free_part_body(nested->body);
- if (nested->next) emcore_mime_free_part(nested->next);
-
- emcore_mime_free_part_body(tmp_body);
- EM_DEBUG_FUNC_END("false");
- return false;
- }
-
- (*p)->body = tmp_body;
- (*p)->next = NULL;
- }
-
- break;
- }
-
- /* End of parsin */
- if (end_of_parsing)
- break;
- }
-
- if (eop != NULL)
- *eop = end_of_parsing;
-
- EM_DEBUG_FUNC_END("end_of_parsing [%d]", end_of_parsing);
- return true;
-}
-
-/* set RFC822 Heade */
-int emcore_mime_set_rfc822_header_value(struct _rfc822header **header, char *name, char *value, int *err_code)
-{
- EM_DEBUG_FUNC_BEGIN_SEC("header[%p], name[%s], value[%s], err_code[%p]", header, name, value, err_code);
-
- char **p = NULL;
- char *t = NULL;
-
- if (!value || !*value || !name ) return false; /*prevent 34354*/
-
- if (!*header) {
- *header = em_malloc(sizeof(struct _rfc822header));
- if (!*header) {
- EM_DEBUG_EXCEPTION("em_malloc failed");
- return false;
- }
- }
-
-
- em_upper_string(name);
-
- if (strncmp(name, "RETURN-PATH", strlen("RETURN-PATH")) == 0)
- p = &(*header)->return_path;/* Return-Rat */
- else if (strncmp(name, "RECEIVED", strlen("RECEIVED")) == 0)
- p = &(*header)->received; /* Receive */
- else if (strncmp(name, "REPLY-TO", strlen("REPLY-TO")) == 0)
- p = &(*header)->reply_to; /* Reply-T */
- else if (strncmp(name, "DATE", strlen("DATE")) == 0)
- p = &(*header)->date; /* Dat */
- else if (strncmp(name, "FROM", strlen("FROM")) == 0)
- p = &(*header)->from; /* Fro */
- else if (strncmp(name, "SUBJECT", strlen("SUBJECT")) == 0)
- p = &(*header)->subject; /* Subjec */
- else if (strncmp(name, "SENDER", strlen("SENDER")) == 0)
- p = &(*header)->sender; /* Sende */
- else if (strncmp(name, "TO", strlen("TO")) == 0)
- p = &(*header)->to; /* T */
- else if (strncmp(name, "CC", strlen("CC")) == 0)
- p = &(*header)->cc; /* C */
- else if (strncmp(name, "BCC", strlen("BCC")) == 0)
- p = &(*header)->bcc; /* Bc */
- else if (strncmp(name, "X-PRIORITY", strlen("X-PRIORITY")) == 0)
- p = &(*header)->priority; /* Prorit */
- else if (strncmp(name, "X-MSMAIL-PRIORITY", strlen("X-MSMAIL-PRIORITY")) == 0)
- p = &(*header)->ms_priority;/* Prorit */
- else if (strncmp(name, "DISPOSITION-NOTIFICATION-TO", strlen("DISPOSITION-NOTIFICATION-TO")) == 0)
- p = &(*header)->dsp_noti_to;/* Disposition-Notification-T */
- else {
- return false;
- }
-
- em_trim_left(value);
-
- if (!*p)
- *p = EM_SAFE_STRDUP(value);
- else { /* Long Header */
- if (!(t = realloc(*p, strlen(*p) + strlen(value)+1))) /*prevent 34354*/
- return false;
-
- strncat(t, value, strlen(value)); /*prevent 34354*/
- *p = t;
- }
-
- EM_DEBUG_FUNC_END();
- return true;
-}
-
-/* set MIME Part Heade */
-int emcore_mime_set_part_header_value(struct _m_part_header **header, char *name, char *value, int *err_code)
-{
- EM_DEBUG_FUNC_BEGIN_SEC("header[%p], name[%s], value[%s], err_code[%p]", header, name, value, err_code);
-
- if (!name || !value) {
- EM_DEBUG_EXCEPTION("Invalid parameter");
- if (err_code != NULL)
- *err_code = EMAIL_ERROR_INVALID_PARAM;
- return false;
- }
-
- struct _parameter *p = NULL;
- struct _parameter *tmp = NULL;
- char *p_val = NULL;
-
- if (!*header) {
- *header = em_malloc(sizeof(struct _m_part_header));
- if (!(*header)) {
- EM_DEBUG_EXCEPTION("em_malloc failed...");
- return false;
- }
- }
-
- em_upper_string(name);
-
- em_trim_left(value);
- em_trim_right(value);
-
-/* Several threads including event thd call it, don't delete comment
- if (!emcore_check_thread_status()) {
- if (err_code != NULL)
- *err_code = EMAIL_ERROR_CANCELLED;
- return false;
- }
-*/
- if (name) {
- if (strncmp(name, "CONTENT-TYPE", strlen("CONTENT-TYPE")) == 0) {
- p_val = strtok(value, ";");
-
- if (p_val) {
- if (!(*header)->type) { /* Content-Type */
- em_upper_string(p_val);
- (*header)->type = EM_SAFE_STRDUP(p_val);
- }
-
- /* Content-Type Parameter (format : "name =value" */
- do {
- if (emcore_mime_get_param_from_str(p_val, &p, err_code)) {
- /* Save the start node */
- tmp = (*header)->parameter;
- /* insert node */
- emcore_mime_add_param_to_list(&((*header)->parameter), p, err_code);
- if (tmp != NULL) {
- (*header)->parameter = tmp;
- tmp = NULL;
- }
- }
- else /* name= CRLF value */ {
- struct _parameter *t = (*header)->parameter;
- while (t && t->next) {
- EM_DEBUG_LOG_SEC("name : [%s]", t->name);
- EM_DEBUG_LOG("value : [%s]", t->value);
- t = t->next;
- }
-
- if (t && t->name) {
- char *pointer = NULL;
-
- if (EM_SAFE_STRLEN(p_val) > 0) {
- /* "=?charset?B?value?= */
- /* "=?charset?B?value.... */
- /* =?charset?B?value" */
- if ((pointer = strchr(p_val, '\"'))) {
- if (!*(pointer + 1)) { /* line end '"' */
- if (*p_val == *pointer) /* Example : '"' */
- return true;
- else
- *pointer = '\0'; /* Example : 'abcde"' */
- }
- else { /* line start '"' */
- p_val = pointer + 1;
- if ((pointer = strchr(p_val, '\"')))
- *pointer = '\0';
- }
- }
-
- /* = ? ENCODING_TYPE ? B(Q) ? ENCODED_STRING ? */
- int err = EMAIL_ERROR_NONE;
- char *utf8_text = NULL;
-
- if (!(utf8_text = emcore_decode_rfc2047_text(p_val, &err))) {
- EM_DEBUG_EXCEPTION("emcore_decode_rfc2047_text failed [%d]", err);
- continue; /*prevent 53050*/
- }
- EM_DEBUG_LOG_SEC("utf8_text : [%s]", utf8_text);
-
- if (t->value == NULL) {
- EM_DEBUG_LOG("value is NULL");
- t->value = EM_SAFE_STRDUP(utf8_text);
- } else {
- EM_DEBUG_LOG("value is not NULL");
- t->value = realloc(t->value, strlen(t->value) + EM_SAFE_STRLEN(utf8_text) + 1);
- strcpy((t->value + strlen(t->value)), utf8_text);
- EM_DEBUG_LOG("long name : [%s]", t->value);
- }
-
- EM_DEBUG_LOG("value : [%s]", t->value);
- EM_SAFE_FREE (utf8_text);
- }
- }
- }
- } while ((p_val = strtok(NULL, ";")));
- }
- }
- else if (strncmp(name, "CONTENT-TRANSFER-ENCODING", strlen("CONTENT-TRANSFER-ENCODING")) == 0) {
- em_upper_string(value);
- (*header)->encoding = EM_SAFE_STRDUP(value);
- }
- else if (strncmp(name, "CONTENT-DESCRPTION", strlen("CONTENT-DESCRPTION")) == 0) {
- em_upper_string(value);
- (*header)->desc = EM_SAFE_STRDUP(value);
- }
- else if (strncmp(name, "CONTENT-DISPOSITION", strlen("CONTENT-DISPOSITION")) == 0) {
- p_val = strtok(value, ";");
-
- if (p_val) {
- if (!(*header)->disp_type) { /* Content-Dispositio */
- em_upper_string(p_val);
- (*header)->disp_type = EM_SAFE_STRDUP(p_val);
- }
- /* Content-Disposition Parameter (format : "name =value" */
- do {
- if (emcore_mime_get_param_from_str(p_val, &p, err_code)) {
- /* Save the start node */
- tmp = (*header)->disp_parameter;
- /* insert node */
- emcore_mime_add_param_to_list(&((*header)->disp_parameter), p, err_code);
- if (tmp != NULL) {
- (*header)->disp_parameter = tmp;
- tmp = NULL;
- }
- }
- else /* name= CRLF value */ {
- struct _parameter *t = (*header)->disp_parameter;
- while (t && t->next) {
-// EM_DEBUG_LOG_SEC("name : [%s]", t->name);
-// EM_DEBUG_LOG("value : [%s]", t->value);
- t = t->next;
- }
-
- if (t && t->name) {
- char *pointer = NULL;
-
- if (EM_SAFE_STRLEN(p_val) > 0) {
- /* "=?charset?B?value?= */
- /* "=?charset?B?value.... */
- /* =?charset?B?value" */
- if ((pointer = strchr(p_val, '\"'))) {
- if (!*(pointer + 1)) { /* line end '"' */
- if (*p_val == *pointer) /* Example : '"' */
- return true;
- else
- *pointer = '\0'; /* Example : 'abcde"' */
- }
- else { /* line start '"' */
- p_val = pointer + 1;
- if ((pointer = strchr(p_val, '\"')))
- *pointer = '\0';
- }
- }
-
- /* = ? ENCODING_TYPE ? B(Q) ? ENCODED_STRING ? */
- int err = EMAIL_ERROR_NONE;
- char *utf8_text = NULL;
-
- if (!(utf8_text = emcore_decode_rfc2047_text(p_val, &err))) {
- EM_DEBUG_EXCEPTION("emcore_decode_rfc2047_text failed [%d]", err);
- continue; /*prevent 53050*/
- }
- EM_DEBUG_LOG("utf8_text : [%s]", utf8_text);
-
- if (t->value == NULL) {
- EM_DEBUG_LOG("value is NULL");
- t->value = EM_SAFE_STRDUP(utf8_text);
- } else {
- EM_DEBUG_LOG("value is not NULL");
- t->value = realloc(t->value, strlen(t->value) + EM_SAFE_STRLEN(utf8_text) + 1);
- if (t->value == NULL) {
- EM_DEBUG_EXCEPTION("realloc failed");
- continue;
- }
- strcpy((t->value + strlen(t->value)), utf8_text);
- EM_DEBUG_LOG("long name : [%s]", t->value);
- }
-
- EM_DEBUG_LOG_SEC("value : [%s]", t->value);
- EM_SAFE_FREE (utf8_text);
- }
- }
- }
- } while ((p_val = strtok(NULL, ";")));
- }
- }
- else if (strncmp(name, "CONTENT-ID", strlen("CONTENT-ID")) == 0) {
- size_t len = 0;
- len = EM_SAFE_STRLEN(value);
- /* em_upper_string(value) */
-
- if ((len) && (value[0] == '<')) {
- ++value;
- --len;
- }
-
- if ((len > 1) && (value[len-1] == '>'))
- value[len-1] = '\0';
-
- (*header)->content_id = EM_SAFE_STRDUP(value);
- }
- else if (strncmp(name, "CONTENT-LOCATION", strlen("CONTENT-LOCATION")) == 0) {
- (*header)->content_location = EM_SAFE_STRDUP(value);
- }
- else if (strncmp(name, "X-PRIORITY", strlen("X-PRIORITY")) == 0) {
- (*header)->priority = EM_SAFE_STRDUP(value);
- }
- else if (strncmp(name, "X-MSMAIL-PRIORITY", strlen("X-MSMAIL-PRIORITY")) == 0) {
- (*header)->ms_priority = EM_SAFE_STRDUP(value);
- }
- }
-
- EM_DEBUG_FUNC_END();
- return true;
-}
-
-/* get header parameter from string */
-int emcore_mime_get_param_from_str(char *str, struct _parameter **param, int *err_code)
-{
- EM_DEBUG_FUNC_BEGIN("str[%s], param[%p], err_code[%p]", str, param, err_code);
-
- char *p_name, *p_val, *p;
-
- *param = NULL;
-
- if (!(p = strchr(str, '='))) return false;
-
- if (*(p+1) == '?') {
- EM_DEBUG_LOG("The parameter is invalid : [%s]", str);
- return false;
- }
-
- *p = '\0';
-
- p_name = str;
- p_val = p+1;
-
- em_trim_left(p_name);
- em_trim_right(p_name);
-
- if (!*p_name) return false;
-
- if (!(*param = em_malloc(sizeof(struct _parameter)))) return false;
-
- (*param)->next = NULL;
-
- /* Name set */
- /* Check string length */
- if (EM_SAFE_STRLEN(p_name) > 0) {
- em_upper_string(p_name);
- (*param)->name = EM_SAFE_STRDUP(p_name);
- }
-
- em_trim_left(p_val);
- em_trim_right(p_val);
-
- if (!*p_val) {
- EM_DEBUG_LOG("Parameter value is NULL");
- return true;
- }
-
- if (EM_SAFE_STRLEN(p_val) > 0) {
- if ((p = strchr(p_val, '\"'))) {
- p_val = p + 1;
- if (!*p_val) return false;
- }
- if ((p = strchr(p_val, '\"')))
- *p = '\0';
-
- if (strncmp(p_name, "BOUNDARY", strlen("BOUNDARY")) != 0 && !strstr(p_name, "NAME"))
- em_upper_string(p_val);
-
- /* = ? ENCODING_TYPE ? B(Q) ? ENCODED_STRING ? */
- int err = EMAIL_ERROR_NONE;
- char *utf8_text = NULL;
-
- if (!(utf8_text = emcore_decode_rfc2047_text(p_val, &err)))
- EM_DEBUG_EXCEPTION("emcore_decode_rfc2047_text failed [%d]", err);
- (*param)->value = utf8_text;
- }
- EM_DEBUG_FUNC_END();
- return true;
-}
-
-/* add a parameter to parameter lis */
-int emcore_mime_add_param_to_list(struct _parameter **param_list, struct _parameter *param, int *err_code)
-{
- EM_DEBUG_FUNC_BEGIN("param_list[%p], param[%p]", param_list, *param_list);
- struct _parameter **t = param_list;
-
- while (*t && (*t)->next)
- *t = (*t)->next;
-
- if (*t)
- (*t)->next = param;
- else
- *t = param;
-
- return true;
-}
-
-/* get header value from MIME Part Heade */
-char *emcore_mime_get_header_value(struct _m_part_header *header, int type, int *err_code)
-{
- EM_DEBUG_FUNC_BEGIN("header[%p], type[%d], err_code[%p]", header, type, err_code);
-
- struct _parameter *p = NULL;
- char *name = NULL;
-
- if (!header) {
- EM_DEBUG_EXCEPTION("header[%p], type[%d]", header, type);
-
- if (err_code != NULL)
- *err_code = EMAIL_ERROR_INVALID_PARAM;
- return NULL;
- }
-
- switch (type) {
- case CONTENT_TYPE:
- return header->type;
-
- case CONTENT_SUBTYPE:
- return header->subtype;
-
- case CONTENT_ENCODING:
- return header->encoding;
-
- case CONTENT_CHARSET:
- name = "CHARSET";
- p = header->parameter;
- break;
-
- case CONTENT_DISPOSITION:
- return header->disp_type;
-
- case CONTENT_NAME:
- name = "NAME";
- p = header->parameter;
- break;
-
- case CONTENT_FILENAME:
- name = "FILENAME";
- p = header->disp_parameter;
- break;
-
- case CONTENT_BOUNDARY:
- name = "BOUNDARY";
- p = header->parameter;
- break;
-
- case CONTENT_REPORT_TYPE:
- name = "REPORT-TYPE";
- p = header->parameter;
- break;
-
- case CONTENT_ID:
- return header->content_id;
-
- case CONTENT_LOCATION:
- return header->content_location;
-
- case CONTENT_SMIME_TYPE:
- name = "SMIME-TYPE";
- p = header->parameter;
- break;
-
- case CONTENT_PROTOCOL:
- name = "PROTOCOL";
- p = header->parameter;
- break;
-
- default:
- return NULL;
- }
-
- for (; p; p = p->next) {
- if (strcmp(p->name, name) == 0)
- break;
- }
-
- if (!p)
- return NULL;
- EM_DEBUG_FUNC_END();
- return p->value;
-}
-
/*
* decode body text (quoted-printable, base64)
* enc_type : encoding type (base64/quotedprintable)
@@ -1778,192 +295,6 @@ INTERNAL_FUNC int emcore_decode_body_text(char *enc_buf, int enc_len, int enc_ty
return EMAIL_ERROR_NONE;
}
-/* 1. if boundary is NULL, contnent has not multipart */
-/* 2. if boundary isn't NULL, content is from current line to the next found boundary */
-/* if next found boundary is the other part boundary ("--boundary"), return and set end_of_parsing to 1 */
-/* if next found boundary is the multipart ending boundary ("--boundary--"), return and set end_of_parsing to 0 */
-/* mode - SAVE_TYPE_SIZE : no saving (only hold content size */
-/* SAVE_TYPE_BUFFER : content is saved to buffer (holder is buffer */
-/* SAVE_TYPE_FILE : content is saved to temporary file (holder is file name */
-int emcore_mime_get_content_data(void *stream, int is_file, char *boundary_str, char *content_encoding, int *end_of_parsing, int mode, char **holder, int *size, void *callback, int *err_code)
-{
- EM_DEBUG_FUNC_BEGIN_SEC("stream[%p], is_file[%d], boundary_str[%s], content_encoding[%s], end_of_parsing[%p], mode[%d], holder[%p], size[%p], callback[%p], err_code[%p]", stream, is_file, boundary_str, content_encoding, end_of_parsing, mode, holder, size, callback, err_code);
-
- int encoding = ENC7BIT;
- int error = EMAIL_ERROR_NONE, ret = false;
- int fd = 0;
- int sz = 0;
-
- if ((mode == SAVE_TYPE_FILE || mode == SAVE_TYPE_BUFFER) && !holder)
- return false;
-
- if (holder)
- *holder = NULL;
-
- if (size)
- *size = 0;
-
- EM_DEBUG_LOG("get content");
-
- if (content_encoding) {
- switch (content_encoding[0]) {
- case 'Q':
- encoding = ENCQUOTEDPRINTABLE;
- break; /* qutoed-printabl */
- case 'B':
- if (content_encoding[1] == 'A') {
- encoding = ENCBASE64;
- break; /* base6 */
- }
- if (content_encoding[1] == 'I') {
- encoding = ENCBINARY;
- break; /* binar */
- }
- encoding = ENC7BIT;
- break;
- case '7':
- encoding = ENC7BIT;
- break; /* 7bi */
- case '8':
- encoding = ENC8BIT;
- break; /* 8bi */
- default:
- encoding = ENCOTHER;
- break; /* unknow */
- }
- }
-
- /* saving type is file */
- if (mode == SAVE_TYPE_FILE) {
- *holder = emcore_mime_get_save_file_name(&error);
-
- EM_DEBUG_LOG("holder[%s]", *holder);
-
- error = em_open(*holder, O_WRONLY|O_CREAT, 0644, &fd);
- if (error != EMAIL_ERROR_NONE) {
- EM_DEBUG_EXCEPTION("holder em_open failed : holder is a filename that will be saved.");
- goto FINISH_OFF;
- }
- }
-
- if (is_file) {
- EM_DEBUG_LOG("from file");
- error = emcore_decode_body_text_from_file((FILE *)stream, boundary_str, encoding, mode, fd, holder, end_of_parsing, &sz);
- if (error != EMAIL_ERROR_NONE) {
- if (error != EMAIL_ERROR_NO_MORE_DATA) {
- EM_DEBUG_EXCEPTION("emcore_decode_body_text_from_file failed : [%d]", error);
- goto FINISH_OFF;
- }
- }
- } else {
- EM_DEBUG_LOG("from sock");
- error = emcore_decode_body_text_from_sock(stream, boundary_str, encoding, mode, fd, holder, end_of_parsing, &sz);
- if (error != EMAIL_ERROR_NONE) {
- EM_DEBUG_EXCEPTION("emcore_decode_body_text_from_sock failed : [%d]", error);
- goto FINISH_OFF;
- }
- }
-
- ret = true;
-FINISH_OFF:
- if (err_code != NULL)
- *err_code = error;
-
- EM_SAFE_CLOSE (fd); /*prevent 32736*/
-
- if (ret) {
- if (size)
- *size = sz;
- }
-
- EM_DEBUG_FUNC_END("ret [%d], sz [%d]", ret, sz);
- return ret;
-}
-
-int emcore_mime_skip_content_data(void *stream,
- int is_file,
- char *boundary_str,
- int *end_of_parsing,
- int *size,
- void *callback,
- int *err_code)
-{
- EM_DEBUG_FUNC_BEGIN("stream[%p], is_file[%d], boundary_str[%s], end_of_parsing[%p], size[%p], callback[%p], err_code[%p]", stream, is_file, boundary_str, end_of_parsing, size, callback, err_code);
-
- char buf[MIME_LINE_LEN] = {0x00}, boundary[BOUNDARY_LEN], boundary_end[BOUNDARY_LEN];
- int sz = 0;
-
- if (size)
- *size = 0;
-
- EM_DEBUG_LOG(">>> skip content <<<<<<<<<<<<<");
-
- if (!boundary_str) { /* if no boundary, this content is from current line to end of all multipart */
- while (TRUE) {
-/* Several threads including event thd call it, don't delete comment
- if (!emcore_check_thread_status()) {
- if (err_code != NULL)
- *err_code = EMAIL_ERROR_CANCELLED;
- return false;
- }
-*/
- if ((is_file == 0 && !emcore_mime_get_line_from_sock(stream, buf, MIME_LINE_LEN, err_code)) ||
- (is_file == 1 && !emcore_get_line_from_file(stream, buf, MIME_LINE_LEN, err_code))) {
- *end_of_parsing = 1;
- if (size)
- *size = sz;
- return false;
- }
- sz += EM_SAFE_STRLEN(buf);
- }
- }
- else { /* if there boundary, this content is from current line to ending boundary */
- memset(boundary, 0x00, BOUNDARY_LEN);
- memset(boundary_end, 0x00, BOUNDARY_LEN);
-
- SNPRINTF(boundary, BOUNDARY_LEN, "--%s%s", boundary_str, CRLF_STRING);
- SNPRINTF(boundary_end, BOUNDARY_LEN, "--%s%s", boundary_str, "--\r\n");
-
- while (TRUE) {
-/* Several threads including event thd call it, don't delete comment
- if (!emcore_check_thread_status()) {
- if (err_code != NULL)
- *err_code = EMAIL_ERROR_CANCELLED;
- return false;
- }
-*/
- if ((is_file == 0 && !emcore_mime_get_line_from_sock(stream, buf, MIME_LINE_LEN, err_code)) ||
- (is_file == 1 && !emcore_get_line_from_file(stream, buf, MIME_LINE_LEN, err_code))) {
- /* end of fil */
- *end_of_parsing = 1;
- if (size)
- *size = sz;
- return true;
- }
-
- if (!strcmp(buf, boundary)) { /* the other part started. the parsing of other part will be started */
- *end_of_parsing = 0;
- if (size)
- *size = sz;
- return true;
- }
- else if (!strcmp(buf, boundary_end)) { /* if ending boundary, the parsing of other multipart will be started */
- *end_of_parsing = 1;
- if (size)
- *size = sz;
- return true;
- }
-
- sz += EM_SAFE_STRLEN(buf);
- }
- }
-
- if (size)
- *size = sz;
- EM_DEBUG_FUNC_END();
- return true;
-}
-
/* get temporary file name */
char *emcore_mime_get_save_file_name(int *err_code)
{
@@ -2183,1612 +514,6 @@ void emcore_mime_free_mime(struct _m_mesg *mmsg)
EM_DEBUG_FUNC_END();
}
-/* get body-part in nested part */
-static PARTLIST *emcore_get_allnested_part_full(MAILSTREAM *stream, int msg_uid, BODY *body, struct _m_content_info *cnt_info, int *err_code, PARTLIST *section_list)
-{
- EM_DEBUG_FUNC_BEGIN("stream[%p], msg_uid[%d], body[%p], cnt_info[%p], err_code[%p]", stream, msg_uid, body, cnt_info, err_code);
-
- PART *part_child = body->nested.part;
-
- while (part_child) {
- section_list = emcore_get_body_full(stream, msg_uid, &part_child->body, cnt_info, err_code, section_list);
- part_child = part_child->next;
- }
-
- EM_DEBUG_FUNC_END();
- return section_list;
-}
-
-/* get body-part in alternative multiple part */
-static PARTLIST *emcore_get_alternative_multi_part_full(MAILSTREAM *stream, int msg_uid, BODY *body, struct _m_content_info *cnt_info, int *err_code, PARTLIST *section_list)
-{
- EM_DEBUG_FUNC_BEGIN("stream[%p], msg_uid[%d], body[%p], cnt_info[%p], err_code[%p]", stream, msg_uid, body, cnt_info, err_code);
-
- PART *part_child = body->nested.part;
-
- /* find the best sub part we can show */
- while (part_child) {
- section_list = emcore_get_body_full(stream, msg_uid, &part_child->body, cnt_info, err_code, section_list);
- part_child = part_child->next;
- }
-
- EM_DEBUG_FUNC_END("section_list[%p]", section_list);
- return section_list;
-}
-
-/* get body part in signed multiple part */
-static PARTLIST *emcore_get_signed_multi_part_full(MAILSTREAM *stream, int msg_uid, BODY *body, struct _m_content_info *cnt_info, int *err_code, PARTLIST *section_list)
-{
- EM_DEBUG_FUNC_BEGIN("stream[%p], msg_uid[%d], body[%p], cnt_info[%p], err_code[%p]", stream, msg_uid, body, cnt_info, err_code);
-
- PART *part_child = body->nested.part;
-
- /* find the best sub part we can show */
- while (part_child) {
- section_list = emcore_get_body_full(stream, msg_uid, &part_child->body, cnt_info, err_code, section_list);
- part_child = part_child->next;
- }
-
- EM_DEBUG_FUNC_END();
- return section_list;
-}
-
-/* get body part in encrypted multiple part */
-static PARTLIST *emcore_get_encrypted_multi_part_full(MAILSTREAM *stream, int msg_uid, BODY *body, struct _m_content_info *cnt_info, int *err_code, PARTLIST *section_list)
-{
- EM_DEBUG_FUNC_BEGIN("stream[%p], msg_uid[%d], body[%p], cnt_info[%p], err_code[%p]", stream, msg_uid, body, cnt_info, err_code);
-
- /* "protocol" = "application/pgp-encrypted */
- EM_DEBUG_FUNC_END();
- return section_list;
-}
-
-/* get body part in multiple part */
-static PARTLIST *emcore_get_multi_part_full(MAILSTREAM *stream, int msg_uid, BODY *body, struct _m_content_info *cnt_info, int *err_code, PARTLIST *section_list)
-{
- EM_DEBUG_FUNC_BEGIN("stream[%p], msg_uid[%d], body[%p], cnt_info[%p], err_code[%p]", stream, msg_uid, body, cnt_info, err_code);
-
- switch (body->subtype[0]) {
- case 'A': /* ALTERNATIV */
- return section_list = emcore_get_alternative_multi_part_full(stream, msg_uid, body, cnt_info, err_code, section_list);
-
- case 'S': /* SIGNE */
- return section_list = emcore_get_signed_multi_part_full(stream, msg_uid, body, cnt_info, err_code, section_list);
-
- case 'E': /* ENCRYPTE */
- return section_list = emcore_get_encrypted_multi_part_full(stream, msg_uid, body, cnt_info, err_code, section_list);
-
- default: /* process all unknown as MIXED (according to the RFC 2047 */
- return section_list = emcore_get_allnested_part_full(stream, msg_uid, body, cnt_info, err_code, section_list);
- }
- EM_DEBUG_FUNC_END();
-}
-
-
-PARTLIST* emcore_get_body_full(MAILSTREAM *stream, int msg_uid, BODY *body, struct _m_content_info *cnt_info, int *err_code, PARTLIST *section_list)
-{
- EM_DEBUG_FUNC_BEGIN("stream[%p], msg_uid[%d], body[%p], cnt_info[%p], err_code[%p]", stream, msg_uid, body, cnt_info, err_code);
- char content_type_buffer[512] = { 0, };
-
- if (!stream || !body || !cnt_info) {
- EM_DEBUG_EXCEPTION("stream[%p], msg_uid[%d], body[%p], cnt_info[%p]", stream, msg_uid, body, cnt_info);
- if (err_code != NULL)
- *err_code = EMAIL_ERROR_INVALID_PARAM;
- EM_DEBUG_FUNC_END();
- return NULL;
- }
-
- switch (body->type) {
- case TYPEMULTIPART:
- section_list = emcore_get_multi_part_full(stream, msg_uid, body, cnt_info, err_code, section_list);
- EM_DEBUG_FUNC_END("section_list [%p]", section_list);
- return section_list;
-
- case TYPEMESSAGE:
- break;
-
- case TYPETEXT:
- case TYPEAPPLICATION:
- case TYPEAUDIO:
- case TYPEIMAGE:
- case TYPEVIDEO:
- case TYPEMODEL:
- case TYPEOTHER:
-
- /* Form list of attachment followed by list of inline images */
- if (body->id || body->location || body->disposition.type) {
-
- char filename[512] = {0, };
- struct attachment_info *current_ai = NULL;
- struct attachment_info *prev_ai = NULL;
- struct attachment_info *ai = NULL;
-
- if (emcore_get_file_pointer(body, true, filename, cnt_info, (int*)NULL) < 0)
- EM_DEBUG_EXCEPTION("emcore_get_file_pointer failed");
- else {
- /* To form list of attachment info - Attachment list followed by inline attachment list */
- current_ai = cnt_info->file;
-
- EM_DEBUG_LOG("current_ai - %p", current_ai);
-
- ai = em_malloc(sizeof(struct attachment_info));
- if (ai == NULL) {
- EM_DEBUG_EXCEPTION("em_malloc failed...");
- if(err_code)
- *err_code = EMAIL_ERROR_OUT_OF_MEMORY;
- return NULL;
- }
-
- if (body->disposition.type != NULL && ((body->disposition.type[0] == 'a') || (body->disposition.type[0] == 'A'))) {
- ai->type = ATTACHMENT; /* attachment */
- } else {
- if ((body->id) || (body->location) || ((body->disposition.type != NULL) && ((body->disposition.type[0] == 'i') || (body->disposition.type[0] == 'I'))))
- ai->type = INLINE_ATTACHMENT; /* inline contents */
- else
- ai->type = ATTACHMENT; /* attachment */
- }
-
- ai->name = EM_SAFE_STRDUP(filename);
- ai->size = body->size.bytes;
- ai->content_id = EM_SAFE_STRDUP(body->id);
- if (emcore_get_content_type_from_mail_bodystruct(body, 512, content_type_buffer) == EMAIL_ERROR_NONE)
- ai->attachment_mime_type = EM_SAFE_STRDUP(content_type_buffer);
-
-#ifdef __ATTACHMENT_OPTI__
- ai->encoding = body->encoding;
- if (body->sparep)
- ai->section = EM_SAFE_STRDUP(body->sparep);
-
- EM_DEBUG_LOG("Encoding - %d Section No - %s ", ai->encoding, ai->section);
-#endif
-
- EM_DEBUG_LOG_SEC("Type[%d], Name[%s], Path[%s] ", ai->type, ai->name, ai->save);
- if (body->type == TYPEAPPLICATION) {
- if (!strcasecmp(body->subtype, MIME_SUBTYPE_DRM_OBJECT))
- ai->drm = EMAIL_ATTACHMENT_DRM_OBJECT;
- else if (!strcasecmp(body->subtype, MIME_SUBTYPE_DRM_RIGHTS))
- ai->drm = EMAIL_ATTACHMENT_DRM_RIGHTS;
- else if (!strcasecmp(body->subtype, MIME_SUBTYPE_DRM_DCF))
- ai->drm = EMAIL_ATTACHMENT_DRM_DCF;
- else if (!strcasecmp(body->subtype, "pkcs7-mime"))
- cnt_info->grab_type = cnt_info->grab_type | GRAB_TYPE_ATTACHMENT;
- }
-
- if (current_ai == NULL) {
- cnt_info->file = ai;
- } else {
- while(current_ai->next != NULL) {
- if (ai->type == ATTACHMENT) {
- if (current_ai->type == INLINE_ATTACHMENT)
- break;
- }
-
- prev_ai = current_ai;
- current_ai = current_ai->next;
- }
-
- EM_DEBUG_LOG("current_ai:[%p], prev_ai:[%p]", current_ai, prev_ai);
-
- if (ai->type == ATTACHMENT) {
- if (prev_ai == NULL) {
- cnt_info->file = ai;
- ai->next = current_ai;
- } else {
- prev_ai->next = ai;
- ai->next = current_ai;
- }
- } else {
- current_ai->next = ai;
- }
- }
- }
- }
-
- /* if (cnt_info->grab_type == GRAB_TYPE_ATTACHMENT */
- if (cnt_info->grab_type & GRAB_TYPE_ATTACHMENT) {
- if (((body->disposition.type != NULL) && ((body->disposition.type[0] == 'a') || (body->disposition.type[0] == 'A'))) && (cnt_info->file != NULL)) {
- PARAMETER *param = NULL;
- char *fn = NULL;
-
- param = body->parameter;
-
- while (param) {
- if (!strcasecmp(param->attribute, "NAME")) {
- fn = EM_SAFE_STRDUP(param->value);
- break;
- }
- if (!strcasecmp(param->attribute, "FILENAME")) {
- fn = EM_SAFE_STRDUP(param->value);
- break;
- }
- param = param->next;
- }
- if ((fn != NULL)&& (!strcmp(fn, cnt_info->file->name)) && (body->size.bytes == cnt_info->file->size)) /* checks to zero in on particular attachmen */ {
- section_list = emcore_add_node(section_list, body);
- if (section_list == NULL) {
- EM_DEBUG_EXCEPTION("adding node to section list failed");
- if(err_code)
- *err_code = EMAIL_ERROR_OUT_OF_MEMORY;
- EM_SAFE_FREE(fn);
- return NULL;
- }
- else {
- EM_SAFE_FREE(fn);
- EM_DEBUG_FUNC_END("section_list [%p]", section_list);
- return section_list; /* single attachment download, so if a match found break the recursion */
- }
- }
- EM_SAFE_FREE(fn);
- }
- }
- else {
- /* get a section list which has only plain, html and inline */
- if (!((body->disposition.type != NULL) && ((body->disposition.type[0] == 'a') || (body->disposition.type[0] == 'A'))))/* if the body not an attachmen */ {
- section_list = emcore_add_node(section_list, body);
- if (section_list == NULL) {
- EM_DEBUG_EXCEPTION("adding node to section list failed");
- if(err_code)
- *err_code = EMAIL_ERROR_OUT_OF_MEMORY;
- return NULL;
- }
- }
- }
-
- break;
-
- default:
- break;
- }
-
- if(section_list == NULL && err_code != NULL) {
- *err_code = EMAIL_ERROR_ON_PARSING;
- }
-
- EM_DEBUG_FUNC_END("section_list [%p]", section_list);
- return section_list;
-}
-
-INTERNAL_FUNC int emcore_get_body_part_list_full(MAILSTREAM *stream, int msg_uid, int account_id, int mail_id, BODY *body, struct _m_content_info *cnt_info, int *err_code, PARTLIST *section_list, int event_handle)
-{
- EM_DEBUG_FUNC_BEGIN("stream[%p], msg_uid[%d], body[%p], cnt_info[%p], err_code[%p]", stream, msg_uid, body, cnt_info, err_code);
-
- if (!stream || !body || !cnt_info) {
- EM_DEBUG_EXCEPTION("stream[%p], msg_uid[%d], body[%p], cnt_info[%p]", stream, msg_uid, body, cnt_info);
-
- if (err_code != NULL)
- *err_code = EMAIL_ERROR_INVALID_PARAM;
- return FAILURE;
- }
- section_list = emcore_get_body_full(stream, msg_uid, body, cnt_info, err_code, section_list);
-
- if (section_list == NULL) {
- /* assumed at least one body part exist */
- if(err_code)
- EM_DEBUG_EXCEPTION("emcore_get_body_full failed [%d]", *err_code);
- else
- EM_DEBUG_EXCEPTION("emcore_get_body_full failed");
- return FAILURE;
- }
-
- if (emcore_get_body_part_imap_full(stream, msg_uid, account_id, mail_id, section_list, cnt_info, err_code, event_handle) < 0) {
- EM_DEBUG_EXCEPTION("emcore_get_body_part_imap_full failed");
- emcore_free_section_list(section_list);
- return FAILURE;
- }
- emcore_free_section_list(section_list);
- return SUCCESS;
-}
-
-static int emcore_write_response_into_file(char *filename, char *write_mode, char *encoded, int encoding_type, char *subtype, int account_id, int mail_id, int *err)
-{
- EM_DEBUG_FUNC_BEGIN();
- int ret = false;
- int error = EMAIL_ERROR_NONE;
- int not_found = true;
- int encoded_len = 0;
- int written_bytes = 0;
- unsigned long decoded_len = 0;
- char *decoded = NULL;
- char *decoded_temp = NULL;
- char save_file_name[MAX_PATH+1] = {0, };
- char html_cid_path[MAX_PATH+1] = {0, };
- FILE *fp = NULL;
- PARAMETER *param = NULL;
- PARAMETER *param1 = NULL;
-
-
- if (!encoded || !filename || !write_mode) {
- EM_DEBUG_EXCEPTION("Invalid Param ");
- if( err ) *err = EMAIL_ERROR_INVALID_PARAM; /* prevent 28347 */
- return false;
- }
-
-
- EM_DEBUG_LOG("Encoded buffer length [%d]", EM_SAFE_STRLEN(encoded));
- encoded_len = EM_SAFE_STRLEN(encoded);
-
- EM_DEBUG_LOG("encoding_type [%d]", encoding_type);
- switch (encoding_type) {
- case ENCQUOTEDPRINTABLE: {
- unsigned char *orignal = (unsigned char *)g_strdup_printf("%s\r\n", encoded);
- decoded = (char *)rfc822_qprint(orignal, encoded_len + 2, &decoded_len);
- g_free(orignal);
- break;
- }
-
- case ENCBASE64:
- decoded = (char *)rfc822_base64((unsigned char *)encoded, encoded_len, &decoded_len);
- if (!decoded) {
- gsize dlen = 0;
- EM_DEBUG_LOG("rfc822_base64 decode failed");
- decoded = (char *)g_base64_decode(encoded, &dlen);
- decoded_len = (unsigned long)dlen;
- }
- break;
-
- default: {
- unsigned char *orignal = (unsigned char *)g_strdup_printf("%s\r\n", encoded);
- decoded = em_malloc(encoded_len + 3); /*prevent 28347*/
- if(!decoded) {
- EM_DEBUG_EXCEPTION("em_malloc failed");
- error = EMAIL_ERROR_OUT_OF_MEMORY;
- g_free(orignal);
- goto FINISH_OFF;
- }
- memcpy(decoded, orignal, encoded_len + 3);
- decoded_len = encoded_len + 2;
- g_free(orignal);
- }
- break;
- }
-
- if (decoded != NULL) {
- EM_DEBUG_LOG("Decoded Length [%d] " , decoded_len);
- EM_DEBUG_LOG_SEC("filename [%s] " , filename);
-
- error = em_fopen(filename, write_mode, &fp);
- if (error != EMAIL_ERROR_NONE) {
- EM_DEBUG_EXCEPTION_SEC("em_fopen failed - %s", filename);
- goto FINISH_OFF;
- }
-
- if (subtype && subtype[0] == 'H') {
- char body_inline_id[512] = {0};
-
- while (strstr(decoded, "cid:")) {
- EM_DEBUG_LOG("Found cid:");
- EM_DEBUG_LOG("g_inline_count : [%d]", g_inline_count);
- not_found = true;
- if (g_inline_count) {
- BODY *body_inline = NULL;
- int inline_count = 0;
- char *decoded_content_id = NULL;
- while (inline_count < g_inline_count && g_inline_list[inline_count]) {
- EM_DEBUG_LOG("inline_count [%d], g_inline_count [%d]", inline_count, g_inline_count);
- body_inline = g_inline_list[inline_count];
- param = body_inline->disposition.parameter;
- param1 = body_inline->parameter;
-
- memset(body_inline_id, 0x00, 512);
-
- if (body_inline->id && EM_SAFE_STRLEN(body_inline->id) > 0) { /*prevent 27454*/
- EM_DEBUG_LOG_SEC("body_inline->id - %s", body_inline->id);
- EM_DEBUG_LOG("param - %p param1 - %p", param, param1);
- decoded_content_id = strstr(decoded, "cid:");
-
- if (body_inline->id[0] == '<')
- memcpy(body_inline_id, body_inline->id + 1, EM_SAFE_STRLEN(body_inline->id) - 2);
- else
- memcpy(body_inline_id, body_inline->id , EM_SAFE_STRLEN(body_inline->id));
-
- /* Handle the 'space__content_id(example : (yahoo : content_id: __abcdefgh__ijkl...) */
- em_trim_left(body_inline_id);
- EM_DEBUG_LOG_SEC("Inline body_inline_id [%s] ", body_inline_id);
-
- if ((param || param1) && (decoded_content_id && 0 == strncmp(body_inline_id , decoded_content_id + strlen("cid:"), EM_SAFE_STRLEN(body_inline_id)))) {
- EM_DEBUG_LOG(" Inline CID Found ");
-
- memset(save_file_name, 0x00, MAX_PATH);
- memset(html_cid_path, 0x00, MAX_PATH);
-
- /* Finding 'filename' attribute from content inf */
- emcore_get_file_pointer(body_inline, true, save_file_name, NULL, &error);
-
- if (EM_SAFE_STRLEN(save_file_name) > 0) {
- /* Content ID will be replaced with its file name in html */
- memcpy(html_cid_path, decoded_content_id , strlen("cid:") + EM_SAFE_STRLEN(body_inline_id));
-
- EM_DEBUG_LOG_SEC("Replacing %s with %s ", html_cid_path, save_file_name);
- if ((decoded_temp = em_replace_string(decoded, html_cid_path, save_file_name))) {
- EM_SAFE_FREE(decoded);
- decoded = decoded_temp;
- decoded_len = EM_SAFE_STRLEN(decoded);
- EM_DEBUG_LOG("Decoded Length [%d] ", decoded_len);
- not_found = false;
- /* only_body_download = false */
- break;
- }
- }
- }
- }
- inline_count++;
- }
- }
-
- if (not_found) {
- EM_DEBUG_LOG("not_found is true");
- memset(body_inline_id, 0x00, sizeof(body_inline_id));
- decoded_temp = em_replace_string_with_split_file_path(decoded, "cid:", body_inline_id);
- if (decoded_temp) {
- /* only_body_download = false */
- /* EM_DEBUG_LOG(">>>> decoded_temp 2 [ %s ] ", decoded_temp) */
- EM_SAFE_FREE(decoded);
- decoded = decoded_temp;
- decoded_len = EM_SAFE_STRLEN(decoded);
- EM_DEBUG_LOG("Decoded Length [%d] ", decoded_len);
- }
- }
- }
- g_inline_count = 0;
- EM_SAFE_FREE(g_inline_list);
- }
-
- EM_DEBUG_LOG("Trying to fwrite. decoded_len [%d]", decoded_len);
-
- if (decoded_len > 0 && fwrite(decoded, decoded_len, 1, fp) == 0) {
- EM_DEBUG_EXCEPTION("Error Occured while writing. fwrite(\"%s\") failed. decoded_len [%d], written_bytes [%d] ", decoded, decoded_len, written_bytes);
- error = EMAIL_ERROR_SYSTEM_FAILURE;
- goto FINISH_OFF;
- }
-
- EM_DEBUG_LOG("fwrite succeed");
- }
- else {
- EM_DEBUG_EXCEPTION("Error Occured while decoding ");
- goto FINISH_OFF;
- }
-
- ret = true;
-
-FINISH_OFF:
-
- if (err)
- *err = error;
-
- EM_SAFE_FREE(decoded);
-
- if (fp != NULL)
- fclose(fp);
-
- EM_DEBUG_FUNC_END();
-
- return ret;
-}
-
-
-static BODY *emcore_select_body_structure_from_section_list(PARTLIST *section_list, char *section)
-{
- PARTLIST *temp = section_list;
- BODY *body = NULL;
-
- while (temp != NULL) {
- body = temp->body;
- if (!strcmp(section, body->sparep))
- return body;
- temp = (PARTLIST *)temp->next;
- }
- return body;
-}
-
-
-#define MAX_WRITE_BUFFER_SIZE 0 /* should be tuned */
-
-static int imap_mail_write_body_to_file(MAILSTREAM *stream, int account_id, int mail_id, int is_attachment, char *filepath, int uid, char *section, int encoding, int *decoded_total, char *section_subtype, int *err_code)
-{
- EM_PROFILE_BEGIN(imapMailWriteBodyToFile);
- EM_DEBUG_FUNC_BEGIN_SEC("stream[%p], filepath[%s], uid[%d], section[%s], encoding[%d], decoded_total[%p], err_code[%p]",
- stream, filepath, uid, section, encoding, decoded_total, err_code);
-
- int ret = false;
- int err = EMAIL_ERROR_NONE;
- FILE *fp = NULL;
- IMAPLOCAL *imaplocal = NULL;
- char tag[16], command[64];
- char *response = NULL;
- char *decoded = NULL;
- int body_size = 0, total = 0;
- char *file_id = NULL;
- char server_uid[129] = { 0, };
- char *filename = NULL;
- int server_response_yn = 0;
- unsigned char encoded[DOWNLOAD_MAX_BUFFER_SIZE] = {0, };
- unsigned char test_buffer[LOCAL_MAX_BUFFER_SIZE] = {0, };
- int flag_first_write = true;
- int preline_len = 0;
- int nskip = 0;
- char *concat_encoded = NULL;
- char *new_response = NULL;
- char *tag_position = NULL;
-
- if (!stream || !filepath || !section) {
- EM_DEBUG_EXCEPTION_SEC("stream[%p], filepath[%s], uid[%d], section[%s], encoding[%d], decoded_total[%p]",
- stream, filepath, uid, section, encoding, decoded_total);
- err = EMAIL_ERROR_INVALID_PARAM;
- goto FINISH_OFF;
- }
-
-/* don't delete the comment. several threads including event thread call it
- FINISH_OFF_IF_CANCELED;
-*/
-
- err = em_fopen(filepath, "wb+", &fp);
- if (err != EMAIL_ERROR_NONE) {
- EM_DEBUG_EXCEPTION_SEC("fopen failed - %s : [%d]", filepath, err);
- goto FINISH_OFF;
- }
-
- imaplocal = stream->local;
-
- if (!imaplocal->netstream) {
- EM_DEBUG_EXCEPTION("invalid IMAP4 stream detected... %p", imaplocal->netstream);
- err = EMAIL_ERROR_INVALID_STREAM;
- goto FINISH_OFF;
- }
-
- memset(tag, 0x00, sizeof(tag));
- memset(command, 0x00, sizeof(command));
-
- SNPRINTF(tag, sizeof(tag), "%08lx", 0xffffffff & (stream->gensym++));
- SNPRINTF(command, sizeof(command), "%s UID FETCH %d BODY.PEEK[%s]\015\012", tag, uid, section);
- EM_DEBUG_LOG("[IMAP4] >>> [%s]", command);
-
- /* send command : get msgno/uid for all message */
- if (!net_sout(imaplocal->netstream, command, (int)EM_SAFE_STRLEN(command))) {
- EM_DEBUG_EXCEPTION("net_sout failed...");
- err = EMAIL_ERROR_CONNECTION_BROKEN;
- goto FINISH_OFF;
- }
-
- char *p_stream = NULL;
- char *p_content = NULL;
-
- while (imaplocal->netstream) {
-
-/* don't delete the comment. several threads including event thread call this func
- if (!emcore_check_thread_status()) {
- EM_DEBUG_LOG("Canceled...");
- imaplocal->netstream = NULL;
- err = EMAIL_ERROR_CANCELLED;
- goto FINISH_OFF;
- }
-*/
- /* receive response */
- if (!(response = net_getline(imaplocal->netstream))) {
- EM_DEBUG_EXCEPTION("net_getline failed...");
- err = EMAIL_ERROR_INVALID_RESPONSE;
- goto FINISH_OFF;
- }
-#ifdef FEATURE_CORE_DEBUG
- EM_DEBUG_LOG("recv[%s]", response);
-#endif
-
- /* start of response */
- if (response[0] == '*' && !server_response_yn) {
- p_stream = strstr(response, "BODY[");
- if (p_stream) {
- server_response_yn = 1;
- p_stream += strlen("BODY[");
- p_content = p_stream;
-
- while (*p_content != ']')
- p_content++;
-
- *p_content = '\0';
-
- /* check correct section */
- if (strcmp(section, p_stream)) {
- EM_DEBUG_LOG("Invalid response of section");
- err = EMAIL_ERROR_INVALID_RESPONSE;
- goto FINISH_OFF;
- }
-
- /* get body size */
- p_stream = strstr(p_content+1, " {");
- if (p_stream) {
- p_stream += strlen(" {");
- p_content = p_stream;
-
- while (isdigit(*p_content))
- p_content++;
-
- *p_content = '\0';
-
- body_size = atoi(p_stream);
- } else { /* no body length is replied */
- /* seek the termination of double quot */
- p_stream = strstr(p_content+1, " \"");
- if (p_stream) {
- char *t = NULL;
- p_stream += strlen(" \"");
- t = strstr(p_stream, "\"");
- if (t) {
- body_size = t - p_stream;
- *t = '\0';
- EM_DEBUG_LOG("Body : start[%p] end[%p] : body[%s]", p_stream, t, p_stream);
- /* need to decode */
- EM_SAFE_FREE(response);
- response = EM_SAFE_STRDUP(p_stream);
- } else {
- err = EMAIL_ERROR_INVALID_RESPONSE;
- goto FINISH_OFF;
- }
- } else {
- err = EMAIL_ERROR_INVALID_RESPONSE;
- goto FINISH_OFF;
- }
- }
-
- /* sending progress noti to application.
- 1. mail_id
- 2. file_id
- 3. bodysize
- */
- parse_file_path_to_filename(filepath, &file_id);
-
- filename = file_id;
- snprintf(server_uid, sizeof(server_uid), "%d", uid);
-
- EM_DEBUG_LOG_SEC("file_id [%s]", file_id);
- EM_DEBUG_LOG_SEC("filename [%p]-[%s]", filename, filename);
- EM_DEBUG_LOG("body_size [%d]", body_size);
- EM_DEBUG_LOG("server_uid [%s]", server_uid);
- EM_DEBUG_LOG("mail_id [%d]", mail_id);
-
-/* don't delete the comment. several threads including event thread call it
- if (!emcore_check_thread_status()) {
- EM_DEBUG_LOG("Canceled...");
- imaplocal->netstream = NULL;
- err = EMAIL_ERROR_CANCELLED;
- goto FINISH_OFF;
- }
-*/
- if (is_attachment) {
- EM_DEBUG_LOG("Attachment number [%d]", is_attachment);
- if (!emcore_notify_network_event(NOTI_DOWNLOAD_ATTACH_START, mail_id, filename, is_attachment, 0))
- EM_DEBUG_EXCEPTION("emcore_notify_network_event [ NOTI_DOWNLOAD_ATTACH_START] Failed >>>>");
- _imap4_download_noti_interval_value = body_size * DOWNLOAD_NOTI_INTERVAL_PERCENT / 100;
- _imap4_total_body_size = body_size;
- } else {
- if (multi_part_body_size) {
- EM_DEBUG_LOG("Multipart body size is [%d]", multi_part_body_size);
- if (!emcore_notify_network_event(NOTI_DOWNLOAD_MULTIPART_BODY, mail_id, filename, multi_part_body_size, 0))
- EM_DEBUG_EXCEPTION("emcore_notify_network_event [ NOTI_DOWNLOAD_BODY_START] Failed >>>>");
- _imap4_download_noti_interval_value = multi_part_body_size * DOWNLOAD_NOTI_INTERVAL_PERCENT / 100;
- /* _imap4_total_body_size should be set before calling this functio */
- /* _imap4_total_body_size */
- } else {
- if (!emcore_notify_network_event(NOTI_DOWNLOAD_BODY_START, mail_id, filename, body_size, 0))
- EM_DEBUG_EXCEPTION("emcore_notify_network_event [ NOTI_DOWNLOAD_BODY_START] Failed >>>>");
- _imap4_download_noti_interval_value = body_size * DOWNLOAD_NOTI_INTERVAL_PERCENT / 100;
- _imap4_total_body_size = body_size;
- }
- }
-
- /* remove new lines */
- do {
- EM_SAFE_FREE(response);
- if (!(response = net_getline(imaplocal->netstream))) {
- EM_DEBUG_EXCEPTION("net_getline failed...");
- err = EMAIL_ERROR_INVALID_RESPONSE;
- goto FINISH_OFF;
- }
-
- EM_DEBUG_LOG("response:%s", response);
- if (EM_SAFE_STRLEN(response) == 0) {
- EM_DEBUG_LOG("Skip newline !!");
- nskip++;
- } else {
- EM_SAFE_FREE (new_response); /* detected by valgrind */
- new_response = g_strconcat(response, "\r\n", NULL);
- EM_SAFE_FREE(response);
- break;
- }
- } while(1);
-
- preline_len = EM_SAFE_STRLEN(new_response);
- EM_DEBUG_LOG("preline_len : %d", preline_len);
-
- if (body_size - preline_len - nskip*2 < 0)
- continue;
-
- if ((body_size - preline_len -nskip*2) == 0) {
- /* 1 line content */
- if (!emcore_write_response_into_file(filepath, "wb+", new_response, encoding, section_subtype, account_id, mail_id, &err)) {
- EM_DEBUG_EXCEPTION("write_response_into_file failed [%d]", err);
- goto FINISH_OFF;
- }
-
- total = preline_len;
- EM_DEBUG_LOG("total = %d", total);
- EM_DEBUG_LOG_SEC("write_response_into_file successful %s.....", filename);
-
- /* In some situation, total_encoded_len includes the length of dummy bytes. So it might be greater than body_size */
-
- _imap4_received_body_size += total;
-// EM_DEBUG_LOG("DOWNLOADING STATUS NOTIFY : received_body[%d] / total_body[%d] = %d %% Completed.",
-// _imap4_received_body_size, _imap4_total_body_size, 100*_imap4_received_body_size/_imap4_total_body_size);
-
- if (((_imap4_last_notified_body_size + _imap4_download_noti_interval_value) <= _imap4_received_body_size)
- || (_imap4_received_body_size >= _imap4_total_body_size)) {
-
- _imap4_last_notified_body_size = _imap4_received_body_size;
-
- if (is_attachment) {
- if (_imap4_total_body_size && !emcore_notify_network_event(NOTI_DOWNLOAD_ATTACH_START, mail_id, filename, is_attachment, 100 *total/body_size))
- EM_DEBUG_EXCEPTION("emcore_notify_network_event [ NOTI_DOWNLOAD_ATTACH_START] Failed >>>>");
- } else {
- if (multi_part_body_size) {
- if (!emcore_notify_network_event(NOTI_DOWNLOAD_MULTIPART_BODY, mail_id, filename, _imap4_total_body_size, _imap4_received_body_size))
- EM_DEBUG_EXCEPTION("emcore_notify_network_event [ NOTI_DOWNLOAD_BODY_START] Failed >>>>");
- } else {
- if (!emcore_notify_network_event(NOTI_DOWNLOAD_BODY_START, mail_id, filename, _imap4_total_body_size, _imap4_received_body_size))
- EM_DEBUG_EXCEPTION("emcore_notify_network_event [ NOTI_DOWNLOAD_BODY_START] Failed >>>>");
- }
- }
- }
- }
- else if (body_size - preline_len - nskip*2 < DOWNLOAD_MAX_BUFFER_SIZE) {
- memset(encoded, 0x00, sizeof(encoded));
- if (net_getbuffer(imaplocal->netstream, body_size - preline_len - nskip*2, (char *)encoded) <= 0) {
- EM_DEBUG_EXCEPTION("net_getbuffer failed...");
- err = EMAIL_ERROR_NO_RESPONSE;
- goto FINISH_OFF;
- }
-
- concat_encoded = g_strconcat(new_response, encoded, NULL);
- memset(encoded, 0x00, sizeof(encoded));
- memcpy(encoded, concat_encoded, EM_SAFE_STRLEN(concat_encoded));
- EM_SAFE_FREE(concat_encoded);
- EM_SAFE_FREE(new_response);
- if (!emcore_write_response_into_file(filepath, "wb+", (char *)encoded, encoding, section_subtype, account_id, mail_id, &err)) {
- EM_DEBUG_EXCEPTION("write_response_into_file failed [%d]", err);
- goto FINISH_OFF;
- }
-
- total = EM_SAFE_STRLEN((char *)encoded);
- EM_DEBUG_LOG("total = %d", total);
- EM_DEBUG_LOG_SEC("write_response_into_file successful %s.....", filename);
-
- /* In some situation, total_encoded_len includes the length of dummy bytes. So it might be greater than body_size */
-
- _imap4_received_body_size += total;
-
- EM_DEBUG_LOG("DOWNLOADING STATUS NOTIFY : received_body[%d] / total_body[%d] = %d %% Completed.",
- _imap4_received_body_size, _imap4_total_body_size, 100*_imap4_received_body_size/_imap4_total_body_size);
-
- if (((_imap4_last_notified_body_size + _imap4_download_noti_interval_value) <= _imap4_received_body_size)
- || (_imap4_received_body_size >= _imap4_total_body_size)) {
-
- _imap4_last_notified_body_size = _imap4_received_body_size;
-
- if (is_attachment) {
- if (_imap4_total_body_size && !emcore_notify_network_event(NOTI_DOWNLOAD_ATTACH_START, mail_id, filename, is_attachment, 100 *total/body_size))
- EM_DEBUG_EXCEPTION("emcore_notify_network_event [ NOTI_DOWNLOAD_ATTACH_START] Failed >>>>");
- } else {
- if (multi_part_body_size) {
- if (!emcore_notify_network_event(NOTI_DOWNLOAD_MULTIPART_BODY, mail_id, filename, _imap4_total_body_size, _imap4_received_body_size))
- EM_DEBUG_EXCEPTION("emcore_notify_network_event [ NOTI_DOWNLOAD_BODY_START] Failed >>>>");
- } else {
- if (!emcore_notify_network_event(NOTI_DOWNLOAD_BODY_START, mail_id, filename, _imap4_total_body_size, _imap4_received_body_size))
- EM_DEBUG_EXCEPTION("emcore_notify_network_event [ NOTI_DOWNLOAD_BODY_START] Failed >>>>");
- }
- }
- }
- }
- else {
- int remain_body_size = body_size - preline_len - nskip*2;
- int x = 0;
- int nsize = 0;
- total += preline_len + nskip*2;
- _imap4_received_body_size += preline_len + nskip*2;
-
- memset(test_buffer, 0x00, sizeof(test_buffer));
-
- while (remain_body_size > 0 && (total < body_size)) {
-
- memset(test_buffer, 0x00, sizeof(test_buffer));
-
- if (encoding == ENCBASE64)
- x = (sizeof(encoded)/preline_len)*preline_len; /* to solve base64 decoding pro */
- else
- x = sizeof(encoded)-1;
-
- if (new_response) {
- strncat((char *)test_buffer, (char *)new_response, preline_len);
- EM_SAFE_FREE(new_response);
- }
-
- while (remain_body_size > 0 && (total < body_size) && ((EM_SAFE_STRLEN((char *)test_buffer) + x) < sizeof(test_buffer))) {
-
- memset(encoded, 0x00, sizeof(encoded));
-
- if (net_getbuffer(imaplocal->netstream, (long)x, (char *)encoded) <= 0) {
- EM_DEBUG_EXCEPTION("net_getbuffer failed...");
- err = EMAIL_ERROR_NO_RESPONSE;
- goto FINISH_OFF;
- }
-
- nsize = EM_SAFE_STRLEN((char *)encoded);
- remain_body_size = remain_body_size - nsize;
- strncat((char *)test_buffer, (char *)encoded, nsize);
- total = total + nsize;
- _imap4_received_body_size += nsize;
- EM_DEBUG_LOG("nsize : %d", nsize);
- EM_DEBUG_LOG("remain_body_size : %d", remain_body_size);
- EM_DEBUG_LOG("total : %d", total);
- EM_DEBUG_LOG("imap_received_body_size : %d", _imap4_received_body_size);
-
- if (!(remain_body_size/x) && remain_body_size%x)
- x = remain_body_size%x;
-
- /* notify event every 5% increase */
- if (((_imap4_last_notified_body_size + _imap4_download_noti_interval_value) <= _imap4_received_body_size)
- || (_imap4_received_body_size >= _imap4_total_body_size)) {
-
- /* In some situation, total_encoded_len includes the length of dummy bytes.
- * So it might be greater than body_size */
- if (total > body_size)
- _imap4_received_body_size = body_size;
-
-
-/* don't delete the comment. it can be called by several threads
- if (!emcore_check_thread_status()) {
- EM_DEBUG_LOG("Canceled...");
- imaplocal->netstream = NULL;
- err = EMAIL_ERROR_CANCELLED;
- goto FINISH_OFF;
- }
-
-*/ EM_DEBUG_LOG("DOWNLOADING STATUS NOTIFY : Total[%d] / [%d] = %d %% Completed.\n", total, body_size, 100*total/body_size);
-
- if (((_imap4_last_notified_body_size + _imap4_download_noti_interval_value) <= _imap4_received_body_size)
- || (_imap4_received_body_size >= _imap4_total_body_size)) {
-
- _imap4_last_notified_body_size = _imap4_received_body_size;
-
- if (is_attachment) {
- if (!emcore_notify_network_event(NOTI_DOWNLOAD_ATTACH_START, mail_id, filename, is_attachment, 100*total/body_size))
- EM_DEBUG_EXCEPTION("emcore_notify_network_event [ NOTI_DOWNLOAD_ATTACH_START] Failed >>>>");
- } else {
- if (multi_part_body_size) {
- /* EM_DEBUG_LOG("DOWNLOADING.......... : Multipart body size is [%d]", multi_part_body_size) */
- if (!emcore_notify_network_event(NOTI_DOWNLOAD_MULTIPART_BODY, mail_id, filename, _imap4_total_body_size, _imap4_received_body_size))
- EM_DEBUG_EXCEPTION("emcore_notify_network_event [ NOTI_DOWNLOAD_BODY_START] Failed >>>>");
- } else {
- if (!emcore_notify_network_event(NOTI_DOWNLOAD_BODY_START, mail_id, filename, _imap4_total_body_size, _imap4_received_body_size))
- EM_DEBUG_EXCEPTION("emcore_notify_network_event [ NOTI_DOWNLOAD_BODY_START] Failed >>>>");
- }
- }
- }
- }
- }
-
- if (flag_first_write == true) {
- if (!emcore_write_response_into_file(filepath, "wb+", (char *)test_buffer, encoding, section_subtype, account_id, mail_id, &err)) {
- EM_DEBUG_EXCEPTION_SEC("write_response_into_file %s failed [%d]", filepath, err);
- goto FINISH_OFF;
- }
- flag_first_write = false;
- } else {
- if (!emcore_write_response_into_file(filepath, "ab+", (char *)test_buffer, encoding, section_subtype, account_id, mail_id, &err)) /* append */ {
- EM_DEBUG_EXCEPTION_SEC("write_response_into_file %s failed [%d]", filepath, err);
- goto FINISH_OFF;
- }
- }
- EM_DEBUG_LOG("%d has been written", EM_SAFE_STRLEN((char *)test_buffer));
- }
- }
- } else {
- err = EMAIL_ERROR_INVALID_RESPONSE;
- goto FINISH_OFF;
- }
- }
- else if ((tag_position = g_strrstr(response, tag))) /* end of response */ {
- if (!strncmp(tag_position + EM_SAFE_STRLEN(tag) + 1, "OK", 2)) {
- EM_SAFE_FREE(response);
- } else { /* 'NO' or 'BAD */
- err = EMAIL_ERROR_IMAP4_FETCH_UID_FAILURE;
- goto FINISH_OFF;
- }
- break;
- }
- else if (!strcmp(response, ")")) {
- /* The end of response which contains body information */
- }
- } /* while (imaplocal->netstream) */
-
- if (decoded_total != NULL)
- *decoded_total = total;
-
- ret = true;
-
-FINISH_OFF:
- EM_SAFE_FREE(decoded);
- EM_SAFE_FREE(response);
- EM_SAFE_FREE (file_id); /* detected by valgrind */
- EM_SAFE_FREE (new_response); /* detected by valgrind */
-
- if (fp != NULL)
- fclose(fp);
-
- if (ret == false) { /* delete temp file */
- struct stat temp_file_stat;
- if (filepath && stat(filepath, &temp_file_stat) == 0)
- remove(filepath);
- }
-
- if (err_code != NULL)
- *err_code = err;
-
- EM_PROFILE_END(imapMailWriteBodyToFile);
-
- return ret;
-}
-
-static int emcore_get_body_part_imap_full(MAILSTREAM *stream, int msg_uid, int account_id, int mail_id, PARTLIST *section_list, struct _m_content_info *cnt_info, int *err_code, int event_handle)
-{
- EM_DEBUG_FUNC_BEGIN("stream[%p], msg_uid[%d], body[%p], cnt_info[%p], err_code[%p]", stream, msg_uid, section_list, cnt_info, err_code);
-
- int err = EMAIL_ERROR_NONE;
- char sections[IMAP_MAX_COMMAND_LENGTH] = {0,};
- IMAPLOCAL *imaplocal = NULL;
- char tag[16] = {0,};
- char command[IMAP_MAX_COMMAND_LENGTH] = {0,};
- char section[16] = {0,};
- char *response = NULL;
- BODY *body = NULL;
- int server_response_yn = 0;
- int body_size = 0;
- char *buf = NULL;
- char filename[512] = {0,};
- int return_value = 0;
- int encoding = 0;
- unsigned char encoded[DOWNLOAD_MAX_BUFFER_SIZE] = {0,};
- unsigned char test_buffer[LOCAL_MAX_BUFFER_SIZE] = {0,};
- struct attachment_info *ai = NULL;
- int i = 0;
- int total = 0;
- int flag_first_write = 1;
- int imap4_total_body_download_progress = 0;
- char *tag_position = NULL;
-
- if (!(imaplocal = stream->local) || !imaplocal->netstream || !section_list || !cnt_info) {
- EM_DEBUG_EXCEPTION("invalid IMAP4 stream detected...");
- err = EMAIL_ERROR_INVALID_PARAM;
- return_value = -1;
- goto FINISH_OFF;
- }
-
- PARTLIST *temp = section_list;
-
- if (cnt_info->grab_type == GRAB_TYPE_ATTACHMENT) {
- /* to download attachment */
- body = temp->body;
- if (body->sparep != NULL) {
- snprintf(sections, sizeof(sections), "BODY.PEEK[%s]", (char *)body->sparep);
- } else {
- EM_DEBUG_EXCEPTION("body->sparep can not be null. ");
- return_value = -1;
- goto FINISH_OFF;
- }
- } else {
- while (temp != NULL) {
- char t[64] = {0,};
- body = temp->body;
-
- if ((body->type == TYPETEXT) || (body->id != NULL) || ((body->disposition.type != NULL) && ((body->disposition.type[0] == 'i') || (body->disposition.type[0] == 'I')))) {
- snprintf(t, sizeof(t), "BODY.PEEK[%s] ", (char *)body->sparep); /* body parts seperated by period */
- if (EM_SAFE_STRLEN(sections) + EM_SAFE_STRLEN(t) < sizeof(sections))
- strcat(sections, t);
- else {
- EM_DEBUG_EXCEPTION("Too many body parts. IMAP command may cross 2000bytes.");
- break;
- }
- }
- temp = (PARTLIST *)temp->next;
- }
- }
-
- if (EM_SAFE_STRLEN (sections) > 0 && sections[EM_SAFE_STRLEN(sections)-1] == ' ') { /*prevent 32317*/
- sections[EM_SAFE_STRLEN(sections)-1] = '\0';
- }
-
- EM_DEBUG_LOG("sections <%s>", sections);
- SNPRINTF(tag, sizeof(tag), "%08lx", 0xffffffff & (stream->gensym++));
- SNPRINTF(command, sizeof(command), "%s UID FETCH %d (%s)\015\012", tag, msg_uid, sections);
- EM_DEBUG_LOG("command <%s>", command);
-
- /* send command : get msgno/uid for all message */
- if (!net_sout(imaplocal->netstream, command, (int)EM_SAFE_STRLEN(command))) {
- EM_DEBUG_EXCEPTION("net_sout failed...");
- err = EMAIL_ERROR_CONNECTION_BROKEN;
- return_value = -1;
- goto FINISH_OFF;
- }
-
- while (imaplocal->netstream) {
-
- /* receive response */
- if (!(response = net_getline(imaplocal->netstream))) {
- EM_DEBUG_EXCEPTION("net_getline failed...");
- err = EMAIL_ERROR_INVALID_RESPONSE;
- return_value = -1;
- goto FINISH_OFF;
- }
-
- EM_DEBUG_LOG("response :%s", response);
-
- if (strstr(response, "BODY[")) {
-
- if (!server_response_yn) { /* start of response */
- if (response[0] != '*') {
- err = EMAIL_ERROR_INVALID_RESPONSE;
- EM_DEBUG_EXCEPTION("Start of response doesn't contain *");
- return_value = -1;
- goto FINISH_OFF;
- }
- server_response_yn = 1;
- }
-
- flag_first_write = 1;
- total = 0;
- memset(encoded, 0x00, sizeof(encoded));
-
- if (emcore_get_section_body_size(response, section, &body_size) < 0) {
- EM_DEBUG_EXCEPTION("emcore_get_section_body_size failed [%d]", err);
- err = EMAIL_ERROR_INVALID_RESPONSE;
- return_value = -1;
- goto FINISH_OFF;
- }
- EM_DEBUG_LOG("section :%s, body_size :%d", section, body_size);
-
- /* get body from seciton_list */
- if ((body = emcore_select_body_structure_from_section_list(section_list, section)) == NULL) {
- EM_DEBUG_EXCEPTION("emcore_select_body_structure_from_section_list failed [%d]", err);
- err = EMAIL_ERROR_INVALID_RESPONSE;
- return_value = -1;
- goto FINISH_OFF;
- }
- encoding = body->encoding;
-
- /* if (emcore_get_file_pointer(account_id, mail_id, body, buf, cnt_info , err)<0) {
- EM_DEBUG_EXCEPTION("emcore_get_file_pointer failed [%d]", err);
- goto FINISH_OFF;
- }*/
-
- if (!emcore_get_temp_file_name(&buf, &err)) {
- EM_DEBUG_EXCEPTION("emcore_get_temp_file_name failed [%d]", err);
- goto FINISH_OFF;
- }
-
- EM_DEBUG_LOG_SEC("temp filename :%s", buf);
-
- /* notifying UI start */
- /* parse_file_path_to_filename(buf, &file_id); */
- /* EM_DEBUG_LOG(">>>> filename - %p >>>>>>", file_id) */
-
- if (body->type == TYPETEXT && body->subtype && (!body->disposition.type || (body->disposition.type && (body->disposition.type[0] == 'i' || body->disposition.type[0] == 'I')))) {
- if (body->subtype[0] == 'H')
- cnt_info->text.html = buf;
- else
- cnt_info->text.plain = buf;
-
- PARAMETER *param = NULL;
- param = body->parameter;
-
- while (param) {
- if (!strcasecmp(param->attribute, "CHARSET")) {
- EM_SAFE_FREE (cnt_info->text.plain_charset); /* detected by valgrind */
- cnt_info->text.plain_charset = EM_SAFE_STRDUP(param->value);
- break;
- }
- param = param->next;
- }
- } else if (body->subtype && (body->id || body->location || body->disposition.type)) { /*prevent 23712*/ /*refactoring : body->subtype*/
-
- if (emcore_get_file_pointer(body, false, filename, cnt_info , &err) < 0) {
- EM_DEBUG_EXCEPTION("emcore_get_file_pointer failed [%d]", err);
- goto FINISH_OFF;
- }
-
- /* Search info from attachment list followed by inline attachment list */
-
- ai = cnt_info->file;
- EM_DEBUG_LOG("ai - %p", (ai));
-
- /* For Inline content append to the end */
- for (i = 1; ai; ai = ai->next, i++) {
- if (ai->save == NULL && (ai->content_id != NULL && EM_SAFE_STRCMP(ai->content_id, body->id) == 0)) {
- EM_DEBUG_LOG("Found matching details");
- ai->save = buf;
- break;
- }
- }
- }
-
- if (event_handle > 0)
- FINISH_OFF_IF_EVENT_CANCELED (err, event_handle);
-
- if (cnt_info->grab_type == GRAB_TYPE_ATTACHMENT) {
- if (!emcore_notify_network_event(NOTI_DOWNLOAD_ATTACH_START, mail_id, buf, cnt_info->file_no, 0))
- EM_DEBUG_EXCEPTION(" emcore_notify_network_event [NOTI_DOWNLOAD_ATTACH_START] Failed >>>>");
-
- _imap4_download_noti_interval_value = body_size * DOWNLOAD_NOTI_INTERVAL_PERCENT / 100;
- _imap4_total_body_size = body_size;
- } else {
- if (multi_part_body_size) {
- EM_DEBUG_LOG("Multipart body size is [%d]", multi_part_body_size);
- if (!emcore_notify_network_event(NOTI_DOWNLOAD_MULTIPART_BODY, mail_id, buf, multi_part_body_size, 0))
- EM_DEBUG_EXCEPTION(" emcore_notify_network_event [ NOTI_DOWNLOAD_BODY_START] Failed >>>> ");
-
- _imap4_download_noti_interval_value = multi_part_body_size * DOWNLOAD_NOTI_INTERVAL_PERCENT / 100;
- } else {
- if (!emcore_notify_network_event(NOTI_DOWNLOAD_BODY_START, mail_id, buf, body_size, 0))
- EM_DEBUG_EXCEPTION(" emcore_notify_network_event [ NOTI_DOWNLOAD_BODY_START] Failed >>>> ");
-
- _imap4_download_noti_interval_value = body_size * DOWNLOAD_NOTI_INTERVAL_PERCENT / 100;
- _imap4_total_body_size = body_size;
- }
- }
-
- if (_imap4_download_noti_interval_value > DOWNLOAD_NOTI_INTERVAL_SIZE) {
- _imap4_download_noti_interval_value = DOWNLOAD_NOTI_INTERVAL_SIZE;
- }
-
- /* EM_SAFE_FREE(file_id) */
- /* notifying UI end */
-
- if (body_size < DOWNLOAD_MAX_BUFFER_SIZE) {
- if (net_getbuffer(imaplocal->netstream, (long)body_size, (char *)encoded) <= 0) {
- EM_DEBUG_EXCEPTION("net_getbuffer failed...");
- err = EMAIL_ERROR_NO_RESPONSE;
- return_value = -1;
- goto FINISH_OFF;
- }
-
- if (!emcore_write_response_into_file(buf, "wb+", (char *)encoded, encoding, body->subtype, account_id, mail_id, &err)) {
- EM_DEBUG_EXCEPTION("write_response_into_file failed [%d]", err);
- return_value = -1;
- goto FINISH_OFF;
- }
-
- total = EM_SAFE_STRLEN((char *)encoded);
- _imap4_received_body_size = _imap4_received_body_size + EM_SAFE_STRLEN((char *)encoded);
-
- EM_DEBUG_LOG("total = %d", total);
- EM_DEBUG_LOG("write_response_into_file successful %s.....", buf);
-
- EM_DEBUG_LOG("_imap4_last_notified_body_size [%d]", _imap4_last_notified_body_size);
- EM_DEBUG_LOG("_imap4_download_noti_interval_value [%d]", _imap4_download_noti_interval_value);
- EM_DEBUG_LOG("_imap4_received_body_size [%d]", _imap4_received_body_size);
- EM_DEBUG_LOG("_imap4_total_body_size [%d] ", _imap4_total_body_size);
-
- /* In some situation, total_encoded_len includes the length of dummy bytes.
- * So it might be greater than body_size */
-
- _imap4_last_notified_body_size = _imap4_received_body_size;
-
- if (_imap4_total_body_size)
- imap4_total_body_download_progress = 100*_imap4_received_body_size/_imap4_total_body_size;
- else
- imap4_total_body_download_progress = _imap4_received_body_size;
-
- EM_DEBUG_LOG("DOWNLOADING STATUS NOTIFY :Total[%d] / [%d] = %d %% Completed.", _imap4_received_body_size, _imap4_total_body_size, imap4_total_body_download_progress);
-
- if (cnt_info->grab_type == GRAB_TYPE_ATTACHMENT) {
- if (!emcore_notify_network_event(NOTI_DOWNLOAD_ATTACH_START, mail_id, buf, cnt_info->file_no, imap4_total_body_download_progress))
- EM_DEBUG_EXCEPTION("emcore_notify_network_event [NOTI_DOWNLOAD_ATTACH_START] Failed >>>>");
- } else {
- if (multi_part_body_size) {
- /* EM_DEBUG_LOG("DOWNLOADING.......... : Multipart body size is [%d]", multi_part_body_size) */
- if (!emcore_notify_network_event(NOTI_DOWNLOAD_MULTIPART_BODY, mail_id, buf, _imap4_total_body_size, _imap4_received_body_size))
- EM_DEBUG_EXCEPTION(" emcore_notify_network_event [NOTI_DOWNLOAD_BODY_START] Failed >>>>");
- } else {
- if (!emcore_notify_network_event(NOTI_DOWNLOAD_BODY_START, mail_id, buf, _imap4_total_body_size, _imap4_received_body_size))
- EM_DEBUG_EXCEPTION(" emcore_notify_network_event [NOTI_DOWNLOAD_BODY_START] Failed >>>>");
- }
- }
- } else {
- int remain_body_size = body_size;
- int x = 0;
- int nsize = 0;
- total = 0;
-
- if (encoding == ENCBASE64)
- x = (sizeof(encoded)/78) *78; /* to solve base64 decoding pro */
- else
- x = sizeof(encoded)-1;
-
- memset(test_buffer, 0x00, sizeof(test_buffer));
- while (remain_body_size && (total <body_size)) {
-
- memset(test_buffer, 0x00, sizeof(test_buffer));
- while ((total != body_size) && remain_body_size && ((EM_SAFE_STRLEN((char *)test_buffer) + x) < sizeof(test_buffer))) {
- memset(encoded, 0x00, sizeof(encoded));
-
- if (net_getbuffer (imaplocal->netstream, (long)x, (char *)encoded) <= 0) {
- EM_DEBUG_EXCEPTION("net_getbuffer failed...");
- err = EMAIL_ERROR_NO_RESPONSE;
- return_value = -1;
- goto FINISH_OFF;
- }
-
- nsize = EM_SAFE_STRLEN((char *)encoded);
- remain_body_size = remain_body_size - nsize;
- strncat((char *)test_buffer, (char *)encoded, nsize);
- total = total + nsize;
- _imap4_received_body_size += nsize;
-
- EM_DEBUG_LOG("total = %d", total);
-
- if (!(remain_body_size/x) && remain_body_size%x)
- x = remain_body_size%x;
-
- EM_DEBUG_LOG(" _imap4_last_notified_body_size - %d ", _imap4_last_notified_body_size);
- EM_DEBUG_LOG(" _imap4_download_noti_interval_value - %d ", _imap4_download_noti_interval_value);
- EM_DEBUG_LOG(" _imap4_received_body_size - %d ", _imap4_received_body_size);
- EM_DEBUG_LOG(" _imap4_received_body_size - %d ", _imap4_received_body_size);
- EM_DEBUG_LOG(" _imap4_total_body_size - %d ", _imap4_total_body_size);
-
- if (((_imap4_last_notified_body_size + _imap4_download_noti_interval_value) <= _imap4_received_body_size)
- || (_imap4_received_body_size >= _imap4_total_body_size)) {
- /* In some situation, total_encoded_len includes the length of dummy bytes.
- * So it might be greater than body_size */
-
- if (_imap4_received_body_size > _imap4_total_body_size)
- _imap4_received_body_size = _imap4_total_body_size;
- _imap4_last_notified_body_size = _imap4_received_body_size;
-
- if (_imap4_total_body_size)
- imap4_total_body_download_progress = 100*_imap4_received_body_size/_imap4_total_body_size;
- else
- imap4_total_body_download_progress = _imap4_received_body_size;
-
- EM_DEBUG_LOG("DOWNLOADING STATUS NOTIFY :Total[%d] / [%d] = %d %% Completed.", _imap4_received_body_size, _imap4_total_body_size, imap4_total_body_download_progress);
-
- if (cnt_info->grab_type == GRAB_TYPE_ATTACHMENT) {
- if (!emcore_notify_network_event(NOTI_DOWNLOAD_ATTACH_START, mail_id, buf, cnt_info->file_no, imap4_total_body_download_progress))
- EM_DEBUG_EXCEPTION("emcore_notify_network_event [NOTI_DOWNLOAD_ATTACH_START] Failed >>>>");
- } else {
- if (multi_part_body_size) {
- /* EM_DEBUG_LOG("DOWNLOADING.......... : Multipart body size is [%d]", multi_part_body_size) */
- if (!emcore_notify_network_event(NOTI_DOWNLOAD_MULTIPART_BODY, mail_id, buf, _imap4_total_body_size, _imap4_received_body_size))
- EM_DEBUG_EXCEPTION("emcore_notify_network_event [NOTI_DOWNLOAD_BODY_START] Failed >>>>");
- } else {
- if (!emcore_notify_network_event(NOTI_DOWNLOAD_BODY_START, mail_id, buf, _imap4_total_body_size, _imap4_received_body_size))
- EM_DEBUG_EXCEPTION("emcore_notify_network_event [NOTI_DOWNLOAD_BODY_START] Failed >>>>");
- }
- }
- }
- }
-
- if (flag_first_write == 1) {
- if (!emcore_write_response_into_file(buf, "wb+", (char *)test_buffer, encoding, body->subtype, account_id, mail_id, &err)) {
- EM_DEBUG_EXCEPTION("write_response_into_file %s failed [%d]", buf, err);
- return_value = -1;
- goto FINISH_OFF;
- }
- flag_first_write = 0;
- } else {
- if (!emcore_write_response_into_file(buf, "ab+", (char *)test_buffer, encoding, body->subtype, account_id, mail_id, &err)) /* append */ {
- EM_DEBUG_EXCEPTION("write_response_into_file %s failed [%d]", buf, err);
- return_value = -1;
- goto FINISH_OFF;
- }
- }
- EM_DEBUG_LOG("%d has been written", EM_SAFE_STRLEN((char *)test_buffer));
- }
- }
- }
- else if ((tag_position = g_strrstr(response, tag))) /* end of response */ {
- if (!strncmp(tag_position + EM_SAFE_STRLEN(tag) + 1, "OK", 2)) {
- EM_SAFE_FREE(response);
- } else { /* 'NO' or 'BAD */
- err = EMAIL_ERROR_IMAP4_FETCH_UID_FAILURE;
- return_value = -1;
- goto FINISH_OFF;
- }
- break;
- }
- else if (!strcmp(response, ")")) {
- }
-
- EM_SAFE_FREE (response);
- }
-
- return_value = 0;
-
- FINISH_OFF:
-
- if (err_code)
- *err_code = err;
-
- EM_SAFE_FREE(response);
-
- return return_value;
-}
-
-static int _find_duplicated_inline_content_file(char *input_source_file_name, struct _m_content_info *input_content_info, bool *output_result)
-{
- EM_DEBUG_FUNC_BEGIN("input_source_file_name [%s], input_content_info [%p], output_result [%p]", input_source_file_name,input_content_info, output_result);
- struct attachment_info *cur_attachment_info = NULL;
- int err = EMAIL_ERROR_NONE;
- bool result = false;
-
- if(!input_source_file_name || !input_content_info || !output_result || strlen(input_source_file_name) <= 0) {
- EM_DEBUG_EXCEPTION("Invalid parameter");
- return EMAIL_ERROR_INVALID_PARAM;
- }
-
- cur_attachment_info = input_content_info->file;
-
- while(cur_attachment_info) {
- if(strcmp(input_source_file_name, cur_attachment_info->name) == 0) {
- result = true;
- break;
- }
- cur_attachment_info = cur_attachment_info->next;
- }
-
- *output_result = result;
-
- EM_DEBUG_FUNC_END("err [%d], result [%d]", err, result);
- return err;
-}
-
-static int _modify_file_name_string_for_duplicated_inline_content(char *input_source_file_name, struct _m_content_info *input_content_info)
-{
- EM_DEBUG_FUNC_BEGIN("input_source_file_name [%s], input_content_info [%p]", input_source_file_name,input_content_info);
- int err = EMAIL_ERROR_NONE;
- char temp_file_name[MAX_PATH] = { 0, };
- char *file_name = NULL;
- char *extension = NULL;
-
- if(!input_source_file_name || !input_content_info) {
- EM_DEBUG_EXCEPTION("Invalid parameter");
- return EMAIL_ERROR_INVALID_PARAM;
- }
-
- if ( (err = em_get_file_name_and_extension_from_file_path(input_source_file_name, &file_name, &extension)) != EMAIL_ERROR_NONE) {
- EM_DEBUG_EXCEPTION("em_get_file_name_and_extension_from_file_path failed [%d]", err);
- goto FINISH_OFF;
- }
-
- if(file_name && extension)
- SNPRINTF(temp_file_name, MAX_PATH, "%s_.%s", file_name, extension);
- else if(!extension)
- SNPRINTF(temp_file_name, MAX_PATH, "%s_", file_name);
-
- EM_SAFE_STRCPY(input_source_file_name, temp_file_name);
- EM_DEBUG_LOG_SEC("temp_file_name [%s]", temp_file_name);
-
-FINISH_OFF:
-
- EM_SAFE_FREE(file_name);
- EM_SAFE_FREE(extension);
-
- EM_DEBUG_FUNC_END("err [%d]", err);
- return err;
-}
-
-static int emcore_get_file_pointer(BODY *body, bool input_check_duplicated_file_name, char *output_file_name_string, struct _m_content_info *cnt_info , int *err)
-{
- EM_DEBUG_FUNC_BEGIN();
-
- char *decoded_filename = NULL;
- char attachment_file_name[MAX_PATH] = { 0, };
- char attachment_file_name_source[MAX_PATH] = {0, };
- int error = EMAIL_ERROR_NONE;
- bool file_name_duplicated = false;
-
- if ((body->type == TYPETEXT) && (body->disposition.type == NULL)) {
- EM_DEBUG_LOG("body->type == TYPETEXT");
- if (!cnt_info) {
- EM_DEBUG_EXCEPTION("But, cnt_info is null");
- error = EMAIL_ERROR_INVALID_PARAM;
- goto FINISH_OFF;
- }
- if (body->subtype[0] == 'H') {
- if (cnt_info->text.plain_charset != NULL) {
- memcpy(output_file_name_string, cnt_info->text.plain_charset, EM_SAFE_STRLEN(cnt_info->text.plain_charset));
- strcat(output_file_name_string, HTML_EXTENSION_STRING);
- }
- else {
- memcpy(output_file_name_string, "UTF-8.htm", strlen("UTF-8.htm"));
- }
- cnt_info->text.html = EM_SAFE_STRDUP(output_file_name_string);
- }
- else {
- PARAMETER *param = body->parameter;
- char charset_string[512];
-
- if (emcore_get_attribute_value_of_body_part(param, "CHARSET", charset_string, 512, false, &error)) {
- EM_SAFE_FREE(cnt_info->text.plain_charset); /*valgrind*/
- cnt_info->text.plain_charset = EM_SAFE_STRDUP(charset_string);
- memcpy(output_file_name_string, cnt_info->text.plain_charset, EM_SAFE_STRLEN(cnt_info->text.plain_charset));
- }
- else
- memcpy(output_file_name_string, "UTF-8", strlen("UTF-8"));
-
- cnt_info->text.plain = EM_SAFE_STRDUP(output_file_name_string);
- }
-
- }
- else if ((body->id != NULL) || ((body->disposition.type != NULL) && ((body->disposition.type[0] == 'i') || (body->disposition.type[0] == 'I')))) {
- /* body id is exising or disposition type is inline */
- size_t len = 0;
- if (body->parameter) /* Get actual name of file */ {
- PARAMETER *param_body = body->parameter;
- if (!emcore_get_attribute_value_of_body_part(param_body, "NAME", attachment_file_name_source, MAX_PATH, true, &error))
- emcore_get_attribute_value_of_body_part(param_body, "CHARSET", attachment_file_name_source, MAX_PATH, true, &error);
- if (!emcore_make_attachment_file_name_with_extension(attachment_file_name_source, body->subtype, attachment_file_name, MAX_PATH, &error)) {
- EM_DEBUG_EXCEPTION("emcore_make_attachment_file_name_with_extension failed [%d]", error);
- goto FINISH_OFF;
- }
- }
- else if (body->disposition.type) {
- PARAMETER *param_disposition = body->disposition.parameter;
- EM_DEBUG_LOG("body->disposition.type exist");
- emcore_get_attribute_value_of_body_part(param_disposition, "filename", attachment_file_name_source, MAX_PATH, true, &error);
- if (!emcore_make_attachment_file_name_with_extension(attachment_file_name_source, body->subtype, attachment_file_name, MAX_PATH, &error)) {
- EM_DEBUG_EXCEPTION("emcore_make_attachment_file_name_with_extension failed [%d]", error);
- goto FINISH_OFF;
- }
- }
- else { /* body id is not null but disposition type is null */
- if ((body->id[0] == '<'))
- SNPRINTF(attachment_file_name, MAX_PATH, "%s", body->id+1); /* fname = em_parse_filename(body->id + 1 */
- else
- SNPRINTF(attachment_file_name, MAX_PATH, "%s", body->id); /* fname = em_parse_filename(body->id */
-
- len = EM_SAFE_STRLEN(attachment_file_name);
-
- if ((len > 1) && (attachment_file_name[len-1] == '>'))
- attachment_file_name[len - 1] = '\0';
- decoded_filename = emcore_decode_rfc2047_text(attachment_file_name, &error);
- }
- EM_DEBUG_LOG_SEC("attachment_file_name [%s]", attachment_file_name);
- if (decoded_filename != NULL)
- memcpy(output_file_name_string, decoded_filename, EM_SAFE_STRLEN(decoded_filename));
- else
- memcpy(output_file_name_string, attachment_file_name, EM_SAFE_STRLEN(attachment_file_name));
-
- }
- else if (body->disposition.type != NULL) { /* disposition type is existing and not inline and body_id is nul */
- PARAMETER *param = body->parameter;
- if (!emcore_get_attribute_value_of_body_part(param, "NAME", attachment_file_name, MAX_PATH, true, &error))
- emcore_get_attribute_value_of_body_part(param, "FILENAME", attachment_file_name, MAX_PATH, true, &error);
- memcpy(output_file_name_string, attachment_file_name, EM_SAFE_STRLEN(attachment_file_name));
- }
-
- if(input_check_duplicated_file_name) {
- if ( (error = _find_duplicated_inline_content_file(output_file_name_string, cnt_info, &file_name_duplicated)) != EMAIL_ERROR_NONE) {
- EM_DEBUG_EXCEPTION("_find_duplicated_inline_content_file failed [%d]", error);
- goto FINISH_OFF;
- }
-
- if (file_name_duplicated == true) {
- if ( ( error = _modify_file_name_string_for_duplicated_inline_content(output_file_name_string, cnt_info)) != EMAIL_ERROR_NONE) {
- EM_DEBUG_EXCEPTION("_modify_file_name_string_for_duplicated_inline_content failed [%d]", error);
- goto FINISH_OFF;
- }
- }
- }
-
-FINISH_OFF:
-
- EM_SAFE_FREE(decoded_filename);
-
- if (err)
- *err = error;
- EM_DEBUG_LOG_SEC("output_file_name_string[%s]", output_file_name_string);
- EM_DEBUG_FUNC_END("error [%d]", error);
- return SUCCESS;
-}
-
-
-static PARTLIST *emcore_add_node(PARTLIST *section_list, BODY *body)
-{
- PARTLIST *temp = (PARTLIST *)malloc(sizeof(PARTLIST));
-
- if (temp == NULL) {
- EM_DEBUG_EXCEPTION("PARTLIST node creation failed");
- return NULL;
- }
- temp->body = body;
- temp->next = NULL;
-
- if (section_list == NULL)/* first node in list */ {
- section_list = temp;
- }
- else/* has min 1 nod */ {
- PARTLIST *t = section_list;
- while (t->next != NULL) /* go to last nod */ {
- t = (PARTLIST *) t->next;
- }
- t->next = (PART *)temp;/* I think this should be PARTLIST, but why this is PART */
-/*
-in imap-2007e/c-client/mail.h
-PARTLIST{
- BODY *body;
- PART *next;
-};
-*/
- }
- return section_list;
-}
-
-
-static void emcore_free_section_list(PARTLIST *section_list)
-{
- PARTLIST *temp = NULL;
-
- while (section_list != NULL) {
- temp = (PARTLIST *)section_list->next;
- EM_SAFE_FREE(section_list);
- section_list = temp;
- }
-}
-
-static int emcore_get_section_body_size(char *response, char *section, int *body_size)
-{
- char *p = NULL;
- char *s = NULL;
- int size = 0;
-
- if ((p = strstr(response, "BODY[")) /* || (p = strstr(s + 1, "BODY["))*/) {
-
- p += strlen("BODY[");
- s = p;
-
- while (*s != ']')
- s++;
-
- *s = '\0';
- strcpy(section, p);
-
- /* if (strcmp(section, p)) {
- err = EMAIL_ERROR_INVALID_RESPONSE;
- goto FINISH_OFF;
- }*/
- p = strstr(s+1, " {");
- if (p) {
- p += strlen(" {");
- s = p;
-
- while (isdigit(*s))
- s++;
-
- *s = '\0';
-
- size = atoi(p);
- *body_size = size;
-
- /* sending progress noti to application.
- 1. mail_id
- 2. file_id
- 3. bodysize
- */
- } else {
- return FAILURE;
- }
- } else {
- return FAILURE;
- }
-
- return SUCCESS;
-}
-
/*
static char *em_parse_filename(char *filename)
{
@@ -3902,8 +627,8 @@ INTERNAL_FUNC int emcore_get_utf8_address(char **dest, ADDRESS *address, int *er
while (address) {
if (address->personal) {
- if (!(nickname = emcore_decode_rfc2047_text(address->personal, &err))) {
- EM_DEBUG_EXCEPTION("emcore_decode_rfc2047_text failed - %d", err);
+ if (!(nickname = emcore_gmime_get_decoding_text(address->personal))) {
+ EM_DEBUG_EXCEPTION("emcore_gmime_get_decoding_text failed - %d", err);
goto FINISH_OFF;
}
EM_DEBUG_LOG_DEV("nickname[%s]", nickname);
@@ -4030,14 +755,12 @@ INTERNAL_FUNC int emcore_get_attribute_value_of_body_part(PARAMETER *input_param
if (!strcasecmp(temp_param->attribute, atribute_name)) {
if (temp_param->value) {
if (with_rfc2047_text) {
- decoded_value = emcore_decode_rfc2047_text(temp_param->value, &err);
- if (decoded_value)
- result_value = decoded_value;
- else
- result_value = decoded_value;
+ decoded_value = emcore_gmime_get_decoding_text(temp_param->value);
+ result_value = EM_SAFE_STRDUP(decoded_value);
+ EM_SAFE_FREE(decoded_value);
}
else
- result_value = temp_param->value;
+ result_value = g_strdup(temp_param->value);
}
else {
EM_DEBUG_EXCEPTION("EMAIL_ERROR_DATA_NOT_FOUND");
@@ -4065,6 +788,7 @@ INTERNAL_FUNC int emcore_get_attribute_value_of_body_part(PARAMETER *input_param
FINISH_OFF:
EM_SAFE_FREE(decoded_value);
+ EM_SAFE_FREE(result_value);
if(err_code)
*err_code = err;
@@ -4073,680 +797,6 @@ FINISH_OFF:
return ret;
}
-
-/*
- *download body part of imap mail (body-text and attachment)
- */
-static int emcore_get_body_part_imap(MAILSTREAM *stream, int account_id, int mail_id, int msg_uid, BODY *body, char *part_body_type, struct _m_content_info *cnt_info, int *err_code)
-{
- EM_DEBUG_FUNC_BEGIN("stream[%p], msg_uid[%d], body[%p], cnt_info[%p], err_code[%p]", stream, msg_uid, body, cnt_info, err_code);
-
- int err = EMAIL_ERROR_NONE, ret = -1;
- struct attachment_info **ai;
- struct attachment_info *prev_ai = NULL;
- struct attachment_info *next_ai = NULL;
- char *savefile = NULL;
- char *o_data = NULL;
- char filename[MAX_PATH + 1] = { 0, };
- char *decoded_filename = NULL;
- int is_attachment = 0;
- int attachment_type = 0;
- int o_data_len = 0;
- char charset_value_buffer[512] = { 0, };
- char content_type_buffer[512] = { 0, };
-/* { is_pb */
- PART *part = NULL;
- int dec_len;
- int i = 0;
- int section_plain = 0;
- int section_html = 0;
- int is_pbd = (account_id == 0 && mail_id == 0) ? true : false;
- int search_result = false;
-/* } is_pb */
-
-
-
- /* unknown type */
- if (body->type > TYPEOTHER) { /* unknown type */
- EM_DEBUG_EXCEPTION("Unknown type.");
- err = EMAIL_ERROR_NOT_SUPPORTED;
- goto FINISH_OFF;
- }
-
- if (NULL == body->subtype) {
- EM_DEBUG_LOG("body->subtype is null. "); /* not exceptional case */
- if (err_code != NULL)
- *err_code = EMAIL_ERROR_INVALID_PARAM;
- return FAILURE;
- }
-
- if (is_pbd) {
- if (body->type == TYPETEXT && body->subtype &&
- (!body->disposition.type || (body->disposition.type && (body->disposition.type[0] == 'i' || body->disposition.type[0] == 'I')))) {
-
- if (!emcore_get_temp_file_name(&o_data, &err) || !o_data) {
- EM_DEBUG_EXCEPTION("emcore_get_temp_file_name failed [%d]", err);
- if (err_code != NULL)
- *err_code = err;
- return FAILURE;
- }
-
- if (body->subtype[0] == 'H' || body->subtype[0] == 'h')
- cnt_info->text.html = EM_SAFE_STRDUP(o_data);
- else
- cnt_info->text.plain = EM_SAFE_STRDUP(o_data);
-
- memset(charset_value_buffer, 0, 512);
-
- if (emcore_get_attribute_value_of_body_part(body->parameter, "CHARSET", charset_value_buffer, 512, true, &err)) {
- EM_SAFE_FREE(cnt_info->text.plain_charset);
- cnt_info->text.plain_charset = EM_SAFE_STRDUP(charset_value_buffer);
-
- }
- }
- } /* is_pbd */
-
- if ((body->id) && EM_SAFE_STRLEN(body->id) > 1) { /* if Content-ID or Content-Location exists, it is inline contents */
- EM_DEBUG_LOG("body->id exist");
- size_t len = 0;
- /* Get actual name of file - fix for inline images to be stored with actual names and not .jpeg */
- if (body->parameter) {
- PARAMETER *param1 = body->parameter;
- while (param1) {
- EM_DEBUG_LOG("param1->attribute - %s ", param1->attribute);
- if (!strcasecmp(param1->attribute, "NAME")) { /* attribute is "NAME" */
- char *extcheck = NULL;
-
- if (param1->value) {
- decoded_filename = emcore_decode_rfc2047_text(param1->value, &err);
- strncpy(filename, decoded_filename, MAX_PATH);
- EM_SAFE_FREE(decoded_filename);
- }
- EM_DEBUG_LOG_SEC(">>>>> FILENAME [%s] ", filename);
- extcheck = strchr(filename, '.');
-
- if (extcheck)
- EM_DEBUG_LOG(">>>> Extension Exist in the Attachment [ %s ] ", extcheck);
- else /* No extension attached , So add the Extension based on the subtyp */ {
- if (body->subtype) {
- strcat(filename, ".");
- strcat(filename, body->subtype);
- EM_DEBUG_LOG_SEC(">>>>> FILENAME Identified the Extension [%s] ", filename);
- }
- else
- EM_DEBUG_EXCEPTION("UnKnown Extesnsion : _ (");
-
- }
-
- break;
- }
- param1 = param1->next;
- }
-
- }
- else if (body->disposition.type) {
- PARAMETER *param = body->disposition.parameter;
-
- while (param) {
- EM_DEBUG_LOG(">>>>> body->disposition.parameter->attribute [ %s ] ", param->attribute);
- EM_DEBUG_LOG(">>>>> body->disposition.parameter->value [ %s ] ", param->value);
-
- /* attribute is "filename" */
- if (!strcasecmp(param->attribute, "filename")) {
- decoded_filename = emcore_decode_rfc2047_text(param->value, &err);
- strncpy(filename, decoded_filename, MAX_PATH);
- EM_SAFE_FREE(decoded_filename);
- EM_DEBUG_LOG_SEC(">>>>> FILENAME [%s] ", filename);
- break;
- }
-
- param = param->next;
- }
- }
- else {
- if ((body->id[0] == '<'))
- SNPRINTF(filename, MAX_PATH, "%s", body->id+1);
- else
- SNPRINTF(filename, MAX_PATH, "%s", body->id);
-
- len = EM_SAFE_STRLEN(filename);
-
- if ((len > 1) && (filename[len-1] == '>'))
- filename[len-1] = '\0';
- }
- }
- else if (body->location) {
- EM_DEBUG_LOG("body->location exist");
- decoded_filename = emcore_decode_rfc2047_text(body->location, &err);
- strncpy(filename, decoded_filename, MAX_PATH);
- EM_SAFE_FREE(decoded_filename);
- EM_DEBUG_LOG_SEC("body->location [%s]", body->location);
- }
- else if (is_pbd && (strncmp(body->subtype, "RFC822", strlen("RFC822")) == 0) && (cnt_info->grab_type == 0 || (cnt_info->grab_type & GRAB_TYPE_ATTACHMENT))) {
- EM_DEBUG_LOG("Beause subtype is RFC822. This is ttachment");
-
- if (cnt_info->grab_type == 0) {
- if ((body->nested.msg != NULL) && (body->nested.msg->env != NULL) && (body->nested.msg->env->subject != NULL)) {
- decoded_filename = emcore_decode_rfc2047_text(body->nested.msg->env->subject, &err);
- strncpy(filename, decoded_filename, MAX_PATH);
- EM_SAFE_FREE(decoded_filename);
- }
- else
- strncpy(filename, "Unknown <message/rfc822>", MAX_PATH);
- }
- else if (cnt_info->grab_type & GRAB_TYPE_ATTACHMENT) {
- BODY *temp_body = NULL;
- if (body->nested.msg->env->subject != NULL) {
- int i = 0;
- int subject_count = 0;
- if (g_str_has_prefix(body->nested.msg->env->subject, "= ? ") && g_str_has_suffix(body->nested.msg->env->subject, " ? = "))
- strncpy(filename, "unknown", MAX_PATH);
- else {
- for (subject_count = 0; body->nested.msg->env->subject[subject_count] != '\0' ; subject_count++) {
- if (body->nested.msg->env->subject[subject_count] != ':' &&
- body->nested.msg->env->subject[subject_count] != ';' &&
- body->nested.msg->env->subject[subject_count] != '*' &&
- body->nested.msg->env->subject[subject_count] != '?' &&
- body->nested.msg->env->subject[subject_count] != '\"' &&
- body->nested.msg->env->subject[subject_count] != '<' &&
- body->nested.msg->env->subject[subject_count] != '>' &&
- body->nested.msg->env->subject[subject_count] != '|' &&
- body->nested.msg->env->subject[subject_count] != '/') {
- filename[i] = body->nested.msg->env->subject[subject_count];
- i++;
- }
- else
- continue;
- }
- }
- }
- else
- strncpy(filename, "Unknown", MAX_PATH);
-
- body = ((MESSAGE *)body->nested.msg)->body;
- part = body->nested.part;
-
- if ((body->subtype[0] == 'P') || (body->subtype[0] == 'H'))
- temp_body = body;
- else if (part != NULL) {
- temp_body = &(part->body);
- if ((temp_body->subtype[0] == 'P' || temp_body->subtype[0] == 'H') && part->next != NULL) {
- part = part->next;
- temp_body = &(part->body);
- }
- }
-
- if (temp_body) {
- if (temp_body->subtype[0] == 'P')
- section_plain = 1;
- else if (temp_body->subtype[0] == 'H')
- section_html = 1;
- }
- }
- }
- else if (body->disposition.type) /* if disposition exists, get filename from disposition parameter */ { /* "attachment" or "inline" or etc.. */
- EM_DEBUG_LOG("body->disposition.type exist");
-
- if (emcore_get_attribute_value_of_body_part(body->disposition.parameter, "filename", filename, MAX_PATH, true, &err))
- EM_DEBUG_LOG_SEC(">>>>> FILENAME [%s] ", filename);
-
- if (!*filename) { /* If the part has no filename, it may be report ms */
- if (body->parameter) /* Fix for the MMS attachment File name as unknown */ {
- char *extcheck = NULL;
-
- if (emcore_get_attribute_value_of_body_part(body->parameter, "NAME", filename, MAX_PATH, true, &err))
- EM_DEBUG_LOG_SEC("NAME [%s] ", filename);
-
- extcheck = strchr(filename, '.');
-
- if (extcheck)
- EM_DEBUG_LOG(">>>> Extension Exist in the Attachment [ %s ] ", extcheck);
- else { /* No extension attached , So add the Extension based on the subtype */
- if (body->subtype) {
- if (EM_SAFE_STRLEN(filename) + strlen(body->subtype) + 1 < MAX_PATH) {
- strcat(filename, ".");
- strcat(filename, body->subtype);
- }
- EM_DEBUG_LOG_SEC(">>>>> FILENAME Identified the Extension [%s] ", filename);
- }
- else
- EM_DEBUG_EXCEPTION("UnKnown Extesnsion : _ (");
- }
-
- }
- else
- strncpy(filename, "unknown", MAX_PATH);
- }
- }
- else {
- char *attr_upper = NULL;
- char *decoded_value = NULL;
- PARAMETER *param = body->parameter;
- if (param) {
- do {
- EM_DEBUG_LOG_DEV("BODY-PARAM-ATTRIBUTE:%s", param->attribute);
- EM_DEBUG_LOG_DEV("BODY-PARAM-VALUE:%s", param->value);
-
- EM_SAFE_FREE(attr_upper); /* valgrind */
- attr_upper = g_ascii_strup(param->attribute, -1);
- if (g_strcmp0(attr_upper, "NAME") == 0) {
- decoded_value = emcore_decode_rfc2047_text(param->value, &err);
- if (decoded_value) strncpy(filename, decoded_value, MAX_PATH);
- break;
- }
- param = param->next;
- } while(param);
- }
-
- if (!decoded_value)
- strncpy(filename, "unknown", MAX_PATH);
-
- EM_SAFE_FREE(attr_upper);
- EM_SAFE_FREE(decoded_value);
- }
-
- /* if (!is_pbd) */ {
- EM_DEBUG_LOG_SEC("filename [%s]", filename);
- if (*filename) {
- decoded_filename = emcore_decode_rfc2047_text(filename, &err);
- strncpy(filename, decoded_filename, MAX_PATH);
- EM_SAFE_FREE(decoded_filename);
-
- }
- }
-
- /* the subtype of content-type is related and the dispostion type is attachment or inline, It is inline attachment */
- if (part_body_type != NULL) {
- if ((part_body_type[0] == 'R' || part_body_type[0] == 'r') && body->disposition.type) {
- attachment_type = INLINE_ATTACHMENT;
- is_attachment = 1;
- } else if ((part_body_type[0] == 'M' || part_body_type[0] == 'm') && body->disposition.type) {
- /* the subtype of content-type is mixed and the dispostion type is attachment , It is attachment */
- attachment_type = ATTACHMENT;
- is_attachment = 1;
- }
- }
-
- if (!is_attachment) { /* Text or RFC822 Message */
- if (((cnt_info->grab_type & GRAB_TYPE_TEXT) && (body->type == TYPEMESSAGE || body->type == TYPETEXT || body->type == TYPEIMAGE)) ||
- (cnt_info->grab_type & GRAB_TYPE_ATTACHMENT)) {
- if (is_pbd) {
- EM_SAFE_FREE(o_data);
- return SUCCESS;
- }
- else { /* fetch body */
- if (!emcore_get_temp_file_name(&o_data, &err)) {
- EM_DEBUG_EXCEPTION("emcore_get_temp_file_name failed [%d]", err);
- goto FINISH_OFF;
- }
-
- if (!imap_mail_write_body_to_file(stream, account_id, mail_id, 0, o_data, msg_uid, body->sparep, body->encoding, &o_data_len, body->subtype, &err)) {
- EM_DEBUG_EXCEPTION("imap_mail_write_body_to_file failed [%d]", err);
- if(err == EMAIL_ERROR_INVALID_STREAM) {
- email_session_t *session = NULL;
- if (emcore_get_current_session(&session) && session)
- err = session->error;
- }
- goto FINISH_OFF;
- }
- }
- }
-
- switch (body->type) {
- case TYPETEXT:
-
- if (body->subtype[0] == 'H') {
- EM_SAFE_FREE(cnt_info->text.html);
- cnt_info->text.html = EM_SAFE_STRDUP(o_data);
- } else {
- EM_SAFE_FREE(cnt_info->text.plain);
- cnt_info->text.plain = EM_SAFE_STRDUP(o_data);
- memset(charset_value_buffer, 0, 512);
- /*check: cnt_info->text.plain_charset is malloc'd twice */
- if (emcore_get_attribute_value_of_body_part(body->parameter, "CHARSET", charset_value_buffer, 512, true, &err)) {
- EM_SAFE_FREE(cnt_info->text.plain_charset);
- cnt_info->text.plain_charset = EM_SAFE_STRDUP(charset_value_buffer);
- }
- }
- break;
- case TYPEIMAGE:
- case TYPEAPPLICATION:
- case TYPEAUDIO:
- case TYPEVIDEO:
- /* Inline Content - suspect of crash on partial body download */
- /* if (!is_pbd) */ {
- EM_DEBUG_LOG("TYPEIMAGE or TYPEAPPLICATION : inline content");
- ai = &(cnt_info->file);
-
- while(*ai != NULL)
- ai = &(*ai)->next;
-
- dec_len = body->size.bytes;
- if ((cnt_info->grab_type & GRAB_TYPE_ATTACHMENT) &&
- (cnt_info->grab_type & GRAB_TYPE_TEXT)) { /* it is 'download all */
- only_body_download = false;
- cnt_info->file_no = 1;
- }
-
- /* add attachment info to content info */
- if (!(*ai = em_malloc(sizeof(struct attachment_info)))) {
- EM_DEBUG_EXCEPTION("em_malloc failed...");
- if (err_code != NULL)
- *err_code = EMAIL_ERROR_OUT_OF_MEMORY;
- return FAILURE;
- }
-
- if (((body->id) || (body->location)) && (body->type == TYPEIMAGE || body->type == TYPEAPPLICATION)) /* Some composer writes a content type of gif as application/octet-stream */
- (*ai)->type = INLINE_ATTACHMENT; /* inline */
- else
- (*ai)->type = ATTACHMENT; /* attachment */
-
- (*ai)->name = EM_SAFE_STRDUP(filename);
- (*ai)->size = body->size.bytes;
- (*ai)->save = EM_SAFE_STRDUP(o_data);
- (*ai)->content_id = EM_SAFE_STRDUP(body->id);
-
- if (body->id && (emcore_search_string_from_file(cnt_info->text.html, body->id, NULL, &search_result) == EMAIL_ERROR_NONE && search_result)) {
- (*ai)->type = INLINE_ATTACHMENT;
- EM_DEBUG_LOG("INLINE_ATTACHMENT");
- } else if ((body->disposition.type && g_ascii_strcasecmp(body->disposition.type, "ATTACHMENT") == 0)) {
- (*ai)->type = ATTACHMENT;
- EM_DEBUG_LOG("ATTACHMENT");
- }
-
- memset(content_type_buffer, 0, 512);
- if ( (err = emcore_get_content_type_from_mail_bodystruct(body, 512, content_type_buffer) ) == EMAIL_ERROR_NONE)
- (*ai)->attachment_mime_type = EM_SAFE_STRDUP(content_type_buffer);
-
- EM_DEBUG_LOG_SEC("name[%s], size[%d], save[%s], content_type_buffer [%s]", cnt_info->file->name, cnt_info->file->size, cnt_info->file->save, content_type_buffer);
-#ifdef __ATTACHMENT_OPTI__
- (*ai)->encoding = body->encoding;
- if (body->sparep)
- (*ai)->section = EM_SAFE_STRDUP(body->sparep);
- EM_DEBUG_LOG(" Encoding - %d Section No - %s ", (*ai)->encoding, (*ai)->section);
-#endif
- }
- break;
-
- case TYPEMESSAGE: /* RFC822 Message */
- EM_DEBUG_EXCEPTION("MESSAGE/RFC822");
- err = EMAIL_ERROR_NOT_SUPPORTED;
- goto FINISH_OFF;
-
- default:
- EM_DEBUG_EXCEPTION("Unknown type. body->type [%d]", body->type);
- err = EMAIL_ERROR_NOT_SUPPORTED;
- goto FINISH_OFF;
- }
-
- stream->text.data = NULL; /* ? ? ? ? ? ? ? ? */
- }
- else { /* Attachment */
- prev_ai = NULL;
- next_ai = NULL;
- ai = &cnt_info->file;
- EM_DEBUG_LOG(" ai - %p ", (*ai));
-
- if (attachment_type == INLINE_ATTACHMENT) {
- /* For Inline content append to the end */
- for (i = 1; *ai; ai = &(*ai)->next)
- i++;
- }
- else { /* For attachment - search till Inline content found and insert before inline */
- for (i = 1; *ai; ai = &(*ai)->next) {
- if ((*ai)->type == 1) {
- /* Means inline image */
- EM_DEBUG_LOG("Found Inline Content ");
- next_ai = (*ai);
- break;
- }
- i++;
- prev_ai = (*ai);
- }
- }
-
- EM_DEBUG_LOG("i - %d next_ai - %p prev_ai - %p", i, next_ai, prev_ai);
-
- if ((cnt_info->grab_type & GRAB_TYPE_ATTACHMENT) &&
- (cnt_info->grab_type & GRAB_TYPE_TEXT)) { /* it is 'download all */
- EM_DEBUG_LOG("Download All");
- only_body_download = false;
- cnt_info->file_no = 1;
- i = 1;
- }
- /* meaningless code */
- dec_len = body->size.bytes;
-
- EM_DEBUG_LOG("i : %d, cnt_info->file_no : %d", i, cnt_info->file_no);
-
- if (
- ((cnt_info->grab_type & GRAB_TYPE_ATTACHMENT) && i == cnt_info->file_no) || /* Is it correct attachment */
- ((attachment_type == INLINE_ATTACHMENT) && (cnt_info->grab_type & GRAB_TYPE_TEXT)) /* Is it inline contents */
- ) {
- /* fetch attachment */
- EM_DEBUG_LOG_SEC("attachment (enc) : %s %ld bytes", filename, body->size.bytes);
- EM_DEBUG_LOG(">>>>> ONLY BODY DOWNLOAD [ %d ] ", only_body_download);
-
- if (only_body_download == false) {
- if (!emcore_get_temp_file_name(&savefile, &err)) {
- EM_DEBUG_EXCEPTION("emcore_get_temp_file_name failed [%d]", err);
- goto FINISH_OFF;
- }
-
- if (!is_pbd && attachment_type == ATTACHMENT) {
- if (!imap_mail_write_body_to_file(stream, account_id, mail_id, cnt_info->file_no, savefile, msg_uid, body->sparep, body->encoding, &dec_len, body->subtype, &err)) {
- EM_DEBUG_EXCEPTION("imap_mail_write_body_to_file failed [%d]", err);
- goto FINISH_OFF;
- }
- }
- }
- }
-
- EM_DEBUG_LOG_SEC("attachment (dec) : %s %d bytes", filename, dec_len);
-
- /* add attachment info to content inf */
- if (!(*ai = em_malloc(sizeof(struct attachment_info)))) {
- EM_DEBUG_EXCEPTION("em_malloc failed...");
- err = EMAIL_ERROR_OUT_OF_MEMORY;
- goto FINISH_OFF;
- }
-
- if (is_pbd) {
- if (savefile != NULL) {
- if (section_plain == 1)
- strcat(filename, ".txt");
- if (section_html == 1)
- strcat(filename, ".html");
- section_plain = 0;
- section_html = 0;
- }
- } /* is_pbd */
- (*ai)->name = EM_SAFE_STRDUP(filename);
- (*ai)->size = dec_len;
- (*ai)->save = EM_SAFE_STRDUP(savefile);
- (*ai)->content_id = EM_SAFE_STRDUP(body->id);
- (*ai)->type = attachment_type;
-
- memset(content_type_buffer, 0, 512);
- if ( (err = emcore_get_content_type_from_mail_bodystruct(body, 512, content_type_buffer) ) == EMAIL_ERROR_NONE)
- (*ai)->attachment_mime_type = EM_SAFE_STRDUP(content_type_buffer);
-#ifdef __ATTACHMENT_OPTI__
- (*ai)->encoding = body->encoding;
- if (body->sparep)
- (*ai)->section = EM_SAFE_STRDUP(body->sparep);
-
- EM_DEBUG_LOG(" Encoding - %d Section No - %s ", (*ai)->encoding, (*ai)->section);
-#endif
- if (body->type == TYPEAPPLICATION) {
- if (!strcasecmp(body->subtype, MIME_SUBTYPE_DRM_OBJECT))
- (*ai)->drm = EMAIL_ATTACHMENT_DRM_OBJECT;
- else if (!strcasecmp(body->subtype, MIME_SUBTYPE_DRM_RIGHTS))
- (*ai)->drm = EMAIL_ATTACHMENT_DRM_RIGHTS;
- else if (!strcasecmp(body->subtype, MIME_SUBTYPE_DRM_DCF))
- (*ai)->drm = EMAIL_ATTACHMENT_DRM_DCF;
- }
-
- /* All inline images information are stored at the end of list */
- if ((*ai)->type != 1 && next_ai != NULL) {
- /* Means next_ai points to the inline attachment info structure */
- if (prev_ai == NULL) {
- /* First node is inline attachment */
- (*ai)->next = next_ai;
- cnt_info->file = (*ai);
- }
- else {
- prev_ai->next = (*ai);
- (*ai)->next = next_ai;
- }
- }
- }
-
- ret = 0;
-FINISH_OFF:
- if (err_code)
- *err_code = err;
- EM_SAFE_FREE(savefile);
- EM_SAFE_FREE(o_data);
- EM_DEBUG_FUNC_END("ret [%d]", ret);
- return ret;
-}
-/* get body-part in nested part */
-
-static int emcore_get_allnested_part(MAILSTREAM *stream, int account_id, int mail_id, int msg_uid, BODY *body, struct _m_content_info *cnt_info, int *err_code)
-{
- EM_DEBUG_FUNC_BEGIN("stream[%p], msg_uid[%d], body[%p], cnt_info[%p], err_code[%p]", stream, msg_uid, body, cnt_info, err_code);
- PART *part_child = body->nested.part;
-
- while (part_child) {
- if (emcore_get_body(stream, account_id, mail_id, msg_uid, &part_child->body, body->subtype, cnt_info, err_code) < 0)
- return FAILURE;
-
- part_child = part_child->next;
- }
-
- EM_DEBUG_FUNC_END();
- return SUCCESS;
-}
-
-/* get body-part in alternative multiple part */
-static int emcore_get_alternative_multi_part(MAILSTREAM *stream, int account_id, int mail_id, int msg_uid, BODY *body, struct _m_content_info *cnt_info, int *err_code)
-{
- EM_DEBUG_FUNC_BEGIN("stream[%p], msg_uid[%d], body[%p], cnt_info[%p], err_code[%p]", stream, msg_uid, body, cnt_info, err_code);
-
- PART *part_child = body->nested.part;
-
- /* find the best sub part we can show */
- while (part_child) {
- if (emcore_get_body(stream, account_id, mail_id, msg_uid, &part_child->body, body->subtype, cnt_info, err_code) < 0)
- return FAILURE;
-
- part_child = part_child->next;
- }
- EM_DEBUG_FUNC_END();
- return SUCCESS;
-}
-
-/* get body part in signed multiple part */
-static int emcore_get_signed_multi_part(MAILSTREAM *stream, int account_id, int mail_id, int msg_uid, BODY *body, struct _m_content_info *cnt_info, int *err_code)
-{
- EM_DEBUG_FUNC_BEGIN("stream[%p], msg_uid[%d], body[%p], cnt_info[%p], err_code[%p]", stream, msg_uid, body, cnt_info, err_code);
-
- PART *part_child = body->nested.part;
-
- /* find the best sub part we can show */
- while (part_child) {
- if (emcore_get_body(stream, account_id, mail_id, msg_uid, &part_child->body, body->subtype, cnt_info, err_code) < 0)
- return FAILURE;
-
- part_child = part_child->next;
- }
-
- EM_DEBUG_FUNC_END();
- return SUCCESS;
-}
-
-/* get body part in encrypted multiple part */
-static int emcore_get_encrypted_multi_part(MAILSTREAM *stream, int account_id, int mail_id, int msg_uid, BODY *body, struct _m_content_info *cnt_info, int *err_code)
-{
- EM_DEBUG_FUNC_BEGIN("stream[%p], msg_uid[%d], body[%p], cnt_info[%p], err_code[%p]", stream, msg_uid, body, cnt_info, err_code);
- EM_DEBUG_FUNC_END();
- return SUCCESS;
-}
-
-/* get body part in multiple part */
-static int emcore_get_multi_part(MAILSTREAM *stream, int account_id, int mail_id, int msg_uid, BODY *body, struct _m_content_info *cnt_info, int *err_code)
-{
- EM_DEBUG_FUNC_BEGIN("stream[%p], msg_uid[%d], body[%p], cnt_info[%p], err_code[%p]", stream, msg_uid, body, cnt_info, err_code);
-
- if (!body) {
- EM_DEBUG_EXCEPTION("Invalid Parameter.");
- if (err_code)
- *err_code = EMAIL_ERROR_INVALID_PARAM;
- return FAILURE;
- }
-
- switch (body->subtype[0]) {
- case 'A': /* ALTERNATIVE */
- EM_DEBUG_LOG("body->subtype[0] = ALTERNATIVE");
- return emcore_get_alternative_multi_part(stream, account_id, mail_id, msg_uid, body, cnt_info, err_code);
-
- case 'S': /* SIGNED */
- EM_DEBUG_LOG("body->subtype[0] = SIGNED");
- return emcore_get_signed_multi_part(stream, account_id, mail_id, msg_uid, body, cnt_info, err_code);
-
- case 'E': /* ENCRYPTED */
- EM_DEBUG_LOG("body->subtype[0] = ENCRYPTED");
- return emcore_get_encrypted_multi_part(stream, account_id, mail_id, msg_uid, body, cnt_info, err_code);
-
- default: /* process all unknown as MIXED (according to the RFC 2047) */
- EM_DEBUG_LOG("body->subtype[0] = [%c].", body->subtype[0]);
- return emcore_get_allnested_part(stream, account_id, mail_id, msg_uid, body, cnt_info, err_code);
- }
- /* Delete the dead code */
-}
-
-/* get body data by body structure */
-/* if POP3, ignored */
-INTERNAL_FUNC int emcore_get_body(MAILSTREAM *stream, int account_id, int mail_id, int msg_uid, BODY *body, char *part_body_type, struct _m_content_info *cnt_info, int *err_code)
-{
- EM_DEBUG_FUNC_BEGIN("stream[%p], msg_uid[%d], body[%p], cnt_info[%p], err_code[%p]", stream, msg_uid, body, cnt_info, err_code);
-
- if (!stream || !body || !cnt_info) {
- EM_DEBUG_EXCEPTION("Invalid parameter");
-
- if (err_code != NULL)
- *err_code = EMAIL_ERROR_INVALID_PARAM;
- return FAILURE;
- }
-
-
-
- switch (body->type) {
- case TYPEMULTIPART:
- return emcore_get_multi_part(stream, account_id, mail_id, msg_uid, body, cnt_info, err_code);
-
- case TYPEMESSAGE: /* not support */
- if (strcasecmp(body->subtype, "RFC822") == 0)
- return emcore_get_body_part_imap(stream, account_id, mail_id, msg_uid, body, part_body_type, cnt_info, err_code);
- break;
-
- case TYPETEXT:
- case TYPEAPPLICATION:
- case TYPEAUDIO:
- case TYPEIMAGE:
- case TYPEVIDEO:
- case TYPEMODEL:
- case TYPEOTHER:
- /* exactly, get a pure body part (text and attachment */
- return emcore_get_body_part_imap(stream, account_id, mail_id, msg_uid, body, part_body_type, cnt_info, err_code);
-
- default:
- break;
- }
- EM_DEBUG_FUNC_END();
- return SUCCESS;
-}
-
/* get body structure */
INTERNAL_FUNC int emcore_get_body_structure(MAILSTREAM *stream, int msg_uid, BODY **body, int *err_code)
{
@@ -4884,347 +934,25 @@ int emcore_set_fetch_part_section(BODY *body, char *section_pfx, int section_sub
EM_DEBUG_FUNC_END();
return SUCCESS;
}
-
-
-static void parse_file_path_to_filename(char *src_string, char **out_string)
-{
- char *token = NULL;
- char *filepath = NULL;
- char *str = NULL;
- char *prev1 = NULL;
-
- filepath = EM_SAFE_STRDUP(src_string);
- token = strtok_r(filepath, "/", &str);
-
- do {
- prev1 = token;
- } while ((token = strtok_r(NULL , "/", &str)));
-
- *out_string = EM_SAFE_STRDUP(prev1);
- EM_SAFE_FREE(filepath);
-}
-
-static char *emcore_decode_rfc2047_word(char *encoded_word, int *err_code)
-{
- EM_DEBUG_FUNC_BEGIN("encoded_word[%p], err_code[%p]", encoded_word, err_code);
-
- int err = EMAIL_ERROR_NONE;
- int base64_encoded = false, length = 0;
- SIZEDTEXT src = { NULL, 0 };
- SIZEDTEXT dst = { NULL, 0 };
- gchar *charset = NULL, *encoded_text = NULL;
- char *decoded_text = NULL, *decoded_word = NULL;
- char *current = NULL, *start = NULL, *end = NULL;
- char *buffer = (char*) em_malloc(EM_SAFE_STRLEN(encoded_word) * 2 + 1);
-
- if (buffer == NULL) {
- EM_DEBUG_EXCEPTION("Memory allocation fail");
- err = EMAIL_ERROR_OUT_OF_MEMORY;
- goto FINISH_OFF;
- }
-
- strcpy(buffer, "");
-
- /* encoding format : =?charset?encoding?encoded-text ?= */
- /* charset : UTF-8, EUC-KR, ... */
- /* encoding : b/B (BASE64), q/Q (QUOTED-PRINTABLE) */
- current = encoded_word;
-
- while (*current != NULL_CHAR) {
- /* search next */
- start = strstr(current, "=?"); /* start of encoding */
- end = g_strrstr(current, "?="); /* end of encoding */
-
-#ifdef FEATURE_CORE_DEBUG
- EM_DEBUG_LOG("current[%p][%s], start[%p][%s], end[%p][%s]", current, current, start, start, end, end);
-#endif
- if (start != NULL) {
- if (current != start) { /* copy the string between current and start to buffer */
- strncat(buffer, current, start - current);
- current = start;
-#ifdef FEATURE_CORE_DEBUG
- EM_DEBUG_LOG("1 - Buffer[%s]", buffer);
-#endif
- }
-
- if (end) { /* decode text between start and end */
- char *p = strstr(start, "?b?");
-
- if (p || (p = strstr(start, "?B?"))) /* BASE64 */
- base64_encoded = true;
- else {
- p = strstr(start, "?q?");
-
- if (p || (p = strstr(start, "?Q?"))) /* QUOTED-PRINTABLE */
- base64_encoded = false;
- else {
- EM_DEBUG_EXCEPTION("unknown encoding found...");
-
- err = EMAIL_ERROR_UNKNOWN;
- goto FINISH_OFF;
- }
- }
-
- if (base64_encoded) { /* BASE64 */
- if (p - (start + 2) > 0)
- charset = g_strndup(start + 2, p - (start + 2));
- encoded_text = g_strndup(p + 3, end - (p + 3));
- }
- else { /* QUOTED-PRINTABLE */
- charset = g_strndup(start + 2, p - (start + 2));
- if (*(p+3) == '=') { /* encoded text might start with '='. ex) '?Q?=E0' */
- end = g_strrstr(p+3, "?="); /* find new end flag */
- if (end) {
- encoded_text = g_strndup(p + 3, end - (p + 3));
- }
- else { /* end flag is not found */
- EM_DEBUG_EXCEPTION("emcore_decode_rfc2047_word decoding error : '?=' is not found...");
-
- err = EMAIL_ERROR_UNKNOWN;
- goto FINISH_OFF;
- }
- }
- else {
- encoded_text = g_strndup(p + 3, end - (p + 3));
- }
- }
-
-#ifdef FEATURE_CORE_DEBUG
- EM_DEBUG_LOG("\t >>>>>>>>>>>>>>> CHARSET[%s]", charset);
- EM_DEBUG_LOG("\t >>>>>>>>>>>>>>> ENCODED_TEXT[%s]", encoded_text);
-#endif
-
- unsigned long len = 0;
- if (encoded_text != NULL) {
- if (base64_encoded == true) {
- if (!(decoded_text = (char *)rfc822_base64((unsigned char *)encoded_text, EM_SAFE_STRLEN(encoded_text), &len))) {
- EM_DEBUG_EXCEPTION("rfc822_base64 falied...");
- goto FINISH_OFF;
- }
- }
- else {
- g_strdelimit(encoded_text, "_", ' ');
-
- if (!(decoded_text = (char *)rfc822_qprint((unsigned char *)encoded_text, EM_SAFE_STRLEN(encoded_text), &len))) {
- EM_DEBUG_EXCEPTION("rfc822_base64 falied...");
- goto FINISH_OFF;
- }
- }
-
- src.data = (unsigned char *)decoded_text;
- src.size = EM_SAFE_STRLEN(decoded_text);
-
- if (!utf8_text(&src, charset, &dst, 0)) {
- EM_DEBUG_EXCEPTION("utf8_text falied...");
- if (src.data)
- strncat(buffer, (char *)src.data, src.size); /* Eventhough failed to decode, downloading should go on. Kyuho Jo */
- } else {
- if (dst.data)
- strncat(buffer, (char *)dst.data, dst.size);
- }
-#ifdef FEATURE_CORE_DEBUG
- EM_DEBUG_LOG("2 - Buffer[%s]", buffer);
-#endif
-
- /* free all of the temp variables */
- if (dst.data != NULL && dst.data != src.data)
- EM_SAFE_FREE(dst.data);
-
- EM_SAFE_FREE(decoded_text);
-
- g_free(encoded_text);
- encoded_text = NULL;
- }
- if (charset != NULL) {
- g_free(charset);
- charset = NULL;
- }
-
- if( *(end + 2) == ' ')
- current = end + 3; /* skip '?= ' */
- else
- current = end + 2; /* skip '?=' */
- }
- else {
- /* unencoded text */
- length = EM_SAFE_STRLEN(start);
- strncat(buffer, start, length);
- current = start + length;
-#ifdef FEATURE_CORE_DEBUG
- EM_DEBUG_LOG("3 - Buffer[%s]", buffer);
-#endif
- }
- }
- else {
- /* unencoded text */
- char *tmp_buffer = NULL;
- char *charset_guess = emcore_guess_charset(current);
- length = EM_SAFE_STRLEN(current);
-
- if (charset_guess) {
- SIZEDTEXT extra_src = { NULL, 0 };
- SIZEDTEXT extra_dst = { NULL, 0 };
- extra_src.data = (unsigned char *)current;
- extra_src.size = length;
- if (!utf8_text(&extra_src, charset_guess, &extra_dst, 0)) {
- EM_DEBUG_EXCEPTION("utf8_text falied...");
- if (extra_src.data) {
- tmp_buffer = buffer;
- buffer = g_strconcat(tmp_buffer, (char *)extra_src.data, NULL);
- EM_SAFE_FREE(tmp_buffer);
- }
- } else {
- if (extra_dst.data) {
- tmp_buffer = buffer;
- buffer = g_strconcat(tmp_buffer, (char *)extra_dst.data, NULL);
- EM_SAFE_FREE(tmp_buffer);
- }
- }
-
- EM_SAFE_FREE(charset_guess);
- } else {
- tmp_buffer = buffer;
- buffer = g_strconcat(tmp_buffer, current, NULL);
- EM_SAFE_FREE(tmp_buffer);
- }
-
- current = current + length;
-#ifdef FEATURE_CORE_DEBUG
- EM_DEBUG_LOG("4 - Buffer[%s]", buffer);
-#endif
- }
- }
-
- decoded_word = EM_SAFE_STRDUP(buffer);
-
-#ifdef FEATURE_CORE_DEBUG
- EM_DEBUG_LOG(">>>>>>>>>>>>>>> DECODED_WORD[%s]", decoded_word);
-#endif
-
-FINISH_OFF:
- if (dst.data != NULL && dst.data != src.data)
- EM_SAFE_FREE(dst.data);
- EM_SAFE_FREE(decoded_text);
- EM_SAFE_FREE(buffer);
-
- if (encoded_text != NULL)
- g_free(encoded_text);
- if (charset != NULL)
- g_free(charset);
-
- if (err_code != NULL)
- *err_code = err;
-
- EM_DEBUG_FUNC_END();
- return decoded_word;
-}
-
-INTERNAL_FUNC char *emcore_decode_rfc2047_text(char *rfc2047_text, int *err_code)
+static int emcore_make_mail_data_from_m_mesg(email_mail_data_t *dst_mail_data, struct _m_mesg *mmsg)
{
- EM_DEBUG_FUNC_BEGIN("rfc2047_text[%s], err_code[%p]", rfc2047_text, err_code);
-
+ EM_DEBUG_FUNC_BEGIN();
int err = EMAIL_ERROR_NONE;
- char *p = NULL;
- gchar **encoded_words = NULL;
- gchar **decoded_words = NULL;
-
- if (!rfc2047_text) {
- EM_DEBUG_EXCEPTION("rfc2047_text[%p]", rfc2047_text);
- if (err_code != NULL)
- *err_code = EMAIL_ERROR_INVALID_PARAM;
- return NULL;
- }
-
- char *p_text = NULL;
- char *text = NULL;
-
- text = strdup(rfc2047_text);
-
- /* Handle the no include charset */
- while (EM_SAFE_STRLEN(text) != 0) {
- if (g_str_has_prefix(text, "=?"))
- encoded_words = g_strsplit_set(text, "\t\r\n ", -1);
- else
- encoded_words = g_strsplit_set(text, "\t\r\n", -1);
- decoded_words = g_new0(char *, g_strv_length(encoded_words) + 1);
-
- EM_DEBUG_LOG_DEV("rfc2047_text [%s]", text);
- EM_DEBUG_LOG_DEV("g_strv_length(encoded_words) [%d]", g_strv_length(encoded_words));
- if (encoded_words != NULL) {
- int i = 0;
-
- while (encoded_words[i] != NULL) {
- EM_DEBUG_LOG_DEV("encoded_words[%d] [%s]", i, encoded_words[i]);
- if (!(decoded_words[i] = emcore_decode_rfc2047_word(encoded_words[i], &err))) {
- EM_DEBUG_EXCEPTION("emcore_decode_rfc2047_word falied [%d]", err);
- goto FINISH_OFF;
- }
- EM_DEBUG_LOG_DEV("decoded_words[%d] [%s]", i, decoded_words[i]);
- i++;
- }
-
- p_text = g_strjoinv("", decoded_words);
- }
- else
- p_text = EM_SAFE_STRDUP(text);
-
-
- if (p_text) {
- p = strstr(p_text, LF_STRING);
- if (p) *p = '\0';
- }
-#ifdef FEATURE_CORE_DEBUG
- EM_DEBUG_LOG(">>>>>>>>>>>>>>>>> TEXT[%s]", p_text);
-#endif /* FEATURE_CORE_DEBUG */
-
- char *charset_guess = NULL;
- charset_guess = emcore_guess_charset(p_text);
- EM_DEBUG_LOG("charset : [%s]", charset_guess);
-
- EM_SAFE_FREE(text);
- text = EM_SAFE_STRDUP(p_text);
- EM_SAFE_FREE(p_text);
-
- if (charset_guess && !strcasecmp(charset_guess, "euc-kr")) {
- EM_SAFE_FREE(charset_guess);
- } else {
- EM_SAFE_FREE(charset_guess);
- break;
- }
+ if (!mmsg || !dst_mail_data) {
+ EM_DEBUG_EXCEPTION("Invalid parameter");
+ err = EMAIL_ERROR_INVALID_PARAM;
+ return err;
}
-FINISH_OFF:
-
- EM_SAFE_FREE(p_text);
- g_strfreev(decoded_words);
- g_strfreev(encoded_words);
-
- if (err_code != NULL)
- *err_code = err;
- EM_DEBUG_FUNC_END();
- return text;
-}
-
-static int emcore_make_mail_data_from_m_mesg(email_mail_data_t *dst_mail_data, struct _m_mesg *mmsg)
-{
- EM_DEBUG_FUNC_BEGIN();
- int err = EMAIL_ERROR_NONE;
-
- if (!mmsg || !dst_mail_data) {
- EM_DEBUG_EXCEPTION("Invalid parameter");
- err = EMAIL_ERROR_INVALID_PARAM;
- return err;
- }
-
char *encoded_subject = NULL;
char *first_address = NULL;
char *first_alias = NULL;
struct tm temp_time_info;
- ADDRESS *from = NULL;
- ADDRESS *to = NULL;
- ADDRESS *cc = NULL;
- ADDRESS *bcc = NULL;
+ ADDRESS *from = NULL;
+ ADDRESS *to = NULL;
+ ADDRESS *cc = NULL;
+ ADDRESS *bcc = NULL;
ADDRESS *return_path = NULL;
ADDRESS *reply_to = NULL;
MESSAGECACHE mail_cache_element = {0, };
@@ -5233,17 +961,17 @@ static int emcore_make_mail_data_from_m_mesg(email_mail_data_t *dst_mail_data, s
memset((void *)&temp_time_info, 0, sizeof(struct tm));
/* Set the smime_type */
- if (mmsg->rfc822header && mmsg->rfc822header->content_type) {
- if (strcasestr(mmsg->rfc822header->content_type, "pkcs7-mime")) {
+ if (mmsg->rfc822header && mmsg->rfc822header->content_type) {
+ if (strcasestr(mmsg->rfc822header->content_type, "pkcs7-mime")) {
if (strcasestr(mmsg->rfc822header->content_type, "enveloped-data"))
- dst_mail_data->smime_type = EMAIL_SMIME_ENCRYPTED;
+ dst_mail_data->smime_type = EMAIL_SMIME_ENCRYPTED;
else
dst_mail_data->smime_type = EMAIL_SMIME_SIGNED_AND_ENCRYPTED;
} else if (strcasestr(mmsg->rfc822header->content_type, "encrypted")) {
- dst_mail_data->smime_type = EMAIL_PGP_ENCRYPTED;
+ dst_mail_data->smime_type = EMAIL_PGP_ENCRYPTED;
} else if (strcasestr(mmsg->rfc822header->content_type, "signed")) {
if (strcasestr(mmsg->rfc822header->content_type, "pkcs7-signature"))
- dst_mail_data->smime_type = EMAIL_SMIME_SIGNED;
+ dst_mail_data->smime_type = EMAIL_SMIME_SIGNED;
else
dst_mail_data->smime_type = EMAIL_PGP_SIGNED;
@@ -5251,7 +979,7 @@ static int emcore_make_mail_data_from_m_mesg(email_mail_data_t *dst_mail_data, s
} else {
dst_mail_data->smime_type = EMAIL_SMIME_NONE;
}
- }
+ }
/* Set the priority */
if (mmsg->rfc822header) {
@@ -5305,87 +1033,85 @@ static int emcore_make_mail_data_from_m_mesg(email_mail_data_t *dst_mail_data, s
}
if (!mmsg->rfc822header) {
- EM_DEBUG_LOG("This mail did not have envelop");
- return err;
- }
+ EM_DEBUG_LOG("This mail did not have envelop");
+ return err;
+ }
/* Set the date */
- if (mmsg->rfc822header->date) {
- EM_DEBUG_LOG("date : [%s]", mmsg->rfc822header->date);
- mail_parse_date(&mail_cache_element, (unsigned char *)mmsg->rfc822header->date);
- }
+ if (mmsg->rfc822header->date) {
+ EM_DEBUG_LOG("date : [%s]", mmsg->rfc822header->date);
+ mail_parse_date(&mail_cache_element, (unsigned char *)mmsg->rfc822header->date);
+ }
- temp_time_info.tm_sec = mail_cache_element.seconds;
- temp_time_info.tm_min = mail_cache_element.minutes - mail_cache_element.zminutes;
- temp_time_info.tm_hour = mail_cache_element.hours - mail_cache_element.zhours;
+ temp_time_info.tm_sec = mail_cache_element.seconds;
+ temp_time_info.tm_min = mail_cache_element.minutes - mail_cache_element.zminutes;
+ temp_time_info.tm_hour = mail_cache_element.hours - mail_cache_element.zhours;
- if (mail_cache_element.hours - mail_cache_element.zhours < 0) {
- temp_time_info.tm_mday = mail_cache_element.day - 1;
- temp_time_info.tm_hour += 24;
- } else
- temp_time_info.tm_mday = mail_cache_element.day;
+ if (mail_cache_element.hours - mail_cache_element.zhours < 0) {
+ temp_time_info.tm_mday = mail_cache_element.day - 1;
+ temp_time_info.tm_hour += 24;
+ } else
+ temp_time_info.tm_mday = mail_cache_element.day;
- temp_time_info.tm_mon = mail_cache_element.month - 1;
- temp_time_info.tm_year = mail_cache_element.year + 70;
+ temp_time_info.tm_mon = mail_cache_element.month - 1;
+ temp_time_info.tm_year = mail_cache_element.year + 70;
- dst_mail_data->date_time = timegm(&temp_time_info);
+ dst_mail_data->date_time = timegm(&temp_time_info);
/* Set the subject */
- encoded_subject = emcore_decode_rfc2047_text(mmsg->rfc822header->subject, NULL);
- dst_mail_data->subject = EM_SAFE_STRDUP(encoded_subject);
+ dst_mail_data->subject = EM_SAFE_STRDUP(mmsg->rfc822header->subject);
/* Set the email address(from, to, cc, bcc, received ...) */
- dst_mail_data->email_address_recipient = EM_SAFE_STRDUP(mmsg->rfc822header->received);
-
- if (mmsg->rfc822header->from) {
- rfc822_parse_adrlist(&from, mmsg->rfc822header->from, NULL);
- if (!emcore_get_utf8_address(&dst_mail_data->full_address_from, from, &err)) {
- EM_DEBUG_EXCEPTION_SEC("emcore_get_utf8_address failed : [%d], [%s]", err, mmsg->rfc822header->from);
- }
- }
-
- if (mmsg->rfc822header->to) {
- rfc822_parse_adrlist(&to, mmsg->rfc822header->to, NULL);
- if (!emcore_get_utf8_address(&dst_mail_data->full_address_to, to, &err)) {
- EM_DEBUG_EXCEPTION_SEC("emcore_get_utf8_address failed : [%d], [%s]", err, mmsg->rfc822header->to);
- }
- }
-
- if (mmsg->rfc822header->cc) {
- rfc822_parse_adrlist(&cc, mmsg->rfc822header->cc, NULL);
- if (!emcore_get_utf8_address(&dst_mail_data->full_address_cc, cc, &err)) {
- EM_DEBUG_EXCEPTION_SEC("emcore_get_utf8_address failed : [%d], [%s]", err, mmsg->rfc822header->cc);
- }
- }
-
- if (mmsg->rfc822header->bcc) {
- rfc822_parse_adrlist(&bcc, mmsg->rfc822header->bcc, NULL);
- if (!emcore_get_utf8_address(&dst_mail_data->full_address_bcc, bcc, &err)) {
- EM_DEBUG_EXCEPTION_SEC("emcore_get_utf8_address failed : [%d], [%s]", err, mmsg->rfc822header->bcc);
- }
- }
-
- if (mmsg->rfc822header->return_path) {
- rfc822_parse_adrlist(&return_path, mmsg->rfc822header->return_path, NULL);
- if (!emcore_get_utf8_address(&dst_mail_data->full_address_return, return_path, &err)) {
- EM_DEBUG_EXCEPTION_SEC("emcore_get_utf8_address failed : [%d], [%s]", err, mmsg->rfc822header->return_path);
- }
- }
-
- if (mmsg->rfc822header->reply_to) {
- rfc822_parse_adrlist(&reply_to, mmsg->rfc822header->reply_to, NULL);
- if (!emcore_get_utf8_address(&dst_mail_data->full_address_reply, reply_to, &err)) {
- EM_DEBUG_EXCEPTION_SEC("emcore_get_utf8_address failed : [%d], [%s]", err, mmsg->rfc822header->reply_to);
- }
- }
+ dst_mail_data->email_address_recipient = EM_SAFE_STRDUP(mmsg->rfc822header->received);
+
+ if (mmsg->rfc822header->from) {
+ rfc822_parse_adrlist(&from, mmsg->rfc822header->from, NULL);
+ if (!emcore_get_utf8_address(&dst_mail_data->full_address_from, from, &err)) {
+ EM_DEBUG_EXCEPTION_SEC("emcore_get_utf8_address failed : [%d], [%s]", err, mmsg->rfc822header->from);
+ }
+ }
+
+ if (mmsg->rfc822header->to) {
+ rfc822_parse_adrlist(&to, mmsg->rfc822header->to, NULL);
+ if (!emcore_get_utf8_address(&dst_mail_data->full_address_to, to, &err)) {
+ EM_DEBUG_EXCEPTION_SEC("emcore_get_utf8_address failed : [%d], [%s]", err, mmsg->rfc822header->to);
+ }
+ }
+
+ if (mmsg->rfc822header->cc) {
+ rfc822_parse_adrlist(&cc, mmsg->rfc822header->cc, NULL);
+ if (!emcore_get_utf8_address(&dst_mail_data->full_address_cc, cc, &err)) {
+ EM_DEBUG_EXCEPTION_SEC("emcore_get_utf8_address failed : [%d], [%s]", err, mmsg->rfc822header->cc);
+ }
+ }
+
+ if (mmsg->rfc822header->bcc) {
+ rfc822_parse_adrlist(&bcc, mmsg->rfc822header->bcc, NULL);
+ if (!emcore_get_utf8_address(&dst_mail_data->full_address_bcc, bcc, &err)) {
+ EM_DEBUG_EXCEPTION_SEC("emcore_get_utf8_address failed : [%d], [%s]", err, mmsg->rfc822header->bcc);
+ }
+ }
+
+ if (mmsg->rfc822header->return_path) {
+ rfc822_parse_adrlist(&return_path, mmsg->rfc822header->return_path, NULL);
+ if (!emcore_get_utf8_address(&dst_mail_data->full_address_return, return_path, &err)) {
+ EM_DEBUG_EXCEPTION_SEC("emcore_get_utf8_address failed : [%d], [%s]", err, mmsg->rfc822header->return_path);
+ }
+ }
+
+ if (mmsg->rfc822header->reply_to) {
+ rfc822_parse_adrlist(&reply_to, mmsg->rfc822header->reply_to, NULL);
+ if (!emcore_get_utf8_address(&dst_mail_data->full_address_reply, reply_to, &err)) {
+ EM_DEBUG_EXCEPTION_SEC("emcore_get_utf8_address failed : [%d], [%s]", err, mmsg->rfc822header->reply_to);
+ }
+ }
if (emcore_get_first_address(dst_mail_data->full_address_from, &first_alias, &first_address) == true) {
dst_mail_data->alias_sender = EM_SAFE_STRDUP(first_alias);
dst_mail_data->email_address_sender = EM_SAFE_STRDUP(first_address);
}
-
EM_SAFE_FREE(encoded_subject);
EM_SAFE_FREE(first_alias);
EM_SAFE_FREE(first_address);
@@ -5412,20 +1138,27 @@ static int emcore_make_mail_data_from_m_mesg(email_mail_data_t *dst_mail_data, s
return err;
}
-INTERNAL_FUNC int emcore_make_mail_data_from_mime_data(struct _m_mesg *mmsg, struct _m_content_info *cnt_info, email_mail_data_t **output_mail_data, email_attachment_data_t **output_attachment_data, int *output_attachment_count, int *err_code)
+INTERNAL_FUNC int emcore_make_mail_data_from_mime_data(struct _m_mesg *mmsg,
+ struct _m_content_info *cnt_info,
+ email_mail_data_t **output_mail_data,
+ email_attachment_data_t **output_attachment_data,
+ int *output_attachment_count,
+ int *err_code)
{
EM_DEBUG_FUNC_BEGIN();
int i = 0;
int ret = false;
- int eml_mail_id = 0;
+ int eml_mail_id = 0;
int err = EMAIL_ERROR_NONE;
int save_status = EMAIL_BODY_DOWNLOAD_STATUS_NONE;
int attachment_num = 0;
int local_attachment_count = 0;
int local_inline_content_count = 0;
- char buf[512];
+ char move_buf[512];
+ char path_buf[512];
char html_body[MAX_PATH] = {0, };
- struct timeval tv;
+ char *multi_user_name = NULL;
+ struct timeval tv;
struct attachment_info *ai = NULL;
email_attachment_data_t *attachment = NULL;
email_mail_data_t *p_mail_data = NULL;
@@ -5452,35 +1185,43 @@ INTERNAL_FUNC int emcore_make_mail_data_from_mime_data(struct _m_mesg *mmsg, str
p_mail_data->account_id = EML_FOLDER;
p_mail_data->mail_size = cnt_info->total_body_size;
- if ((err = emcore_make_mail_data_from_m_mesg(p_mail_data, mmsg)) != EMAIL_ERROR_NONE) {
- EM_DEBUG_EXCEPTION("emcore_make_mail_data_from_m_mesg failed : [%d]", err);
- }
+ if ((err = emcore_make_mail_data_from_m_mesg(p_mail_data, mmsg)) != EMAIL_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("emcore_make_mail_data_from_m_mesg failed : [%d]", err);
+ }
EM_DEBUG_LOG("cnt_info->text.plain [%s], cnt_info->text.html [%s]", cnt_info->text.plain, cnt_info->text.html);
if (cnt_info->text.plain) {
+ memset(move_buf, 0x00, sizeof(move_buf));
+ memset(path_buf, 0x00, sizeof(path_buf));
+
EM_DEBUG_LOG("cnt_info->text.plain [%s]", cnt_info->text.plain);
- if (!emstorage_create_dir(EML_FOLDER, eml_mail_id, 0, &err)) {
+ if (!emstorage_create_dir(multi_user_name, EML_FOLDER, eml_mail_id, 0, &err)) {
EM_DEBUG_EXCEPTION("emstorage_create_dir failed [%d]", err);
goto FINISH_OFF;
}
- if (!emstorage_get_save_name(EML_FOLDER, eml_mail_id, 0, cnt_info->text.plain_charset ? cnt_info->text.plain_charset : UNKNOWN_CHARSET_PLAIN_TEXT_FILE, buf, sizeof(buf), &err)) {
+ if (!emstorage_get_save_name(multi_user_name, EML_FOLDER, eml_mail_id, 0,
+ cnt_info->text.plain_charset ? cnt_info->text.plain_charset : UNKNOWN_CHARSET_PLAIN_TEXT_FILE,
+ move_buf, path_buf, sizeof(path_buf), &err)) {
EM_DEBUG_EXCEPTION("emstorage_get_save_name failed [%d]", err);
goto FINISH_OFF;
}
- if (!emstorage_move_file(cnt_info->text.plain, buf, false, &err)) {
+ if (!emstorage_move_file(cnt_info->text.plain, move_buf, false, &err)) {
EM_DEBUG_EXCEPTION("emstorage_move_file failed [%d]", err);
goto FINISH_OFF;
}
- p_mail_data->file_path_plain = EM_SAFE_STRDUP(buf);
+ p_mail_data->file_path_plain = EM_SAFE_STRDUP(path_buf);
save_status = cnt_info->text.plain_save_status;
}
if (cnt_info->text.html) {
- if (!emstorage_create_dir(EML_FOLDER, eml_mail_id, 0, &err)) {
+ memset(move_buf, 0x00, sizeof(move_buf));
+ memset(path_buf, 0x00, sizeof(path_buf));
+
+ if (!emstorage_create_dir(multi_user_name, EML_FOLDER, eml_mail_id, 0, &err)) {
EM_DEBUG_EXCEPTION("emstorage_create_dir failed [%d]", err);
goto FINISH_OFF;
}
@@ -5491,21 +1232,51 @@ INTERNAL_FUNC int emcore_make_mail_data_from_mime_data(struct _m_mesg *mmsg, str
strcpy(html_body, UNKNOWN_CHARSET_HTML_TEXT_FILE);
}
- if (!emstorage_get_save_name(EML_FOLDER, eml_mail_id, 0, html_body, buf, sizeof(buf), &err)) {
+ if (!emstorage_get_save_name(multi_user_name, EML_FOLDER, eml_mail_id,
+ 0, html_body, move_buf, path_buf,
+ sizeof(path_buf), &err)) {
EM_DEBUG_EXCEPTION("emstorage_get_save_name failed [%d]", err);
goto FINISH_OFF;
}
- if (!emstorage_move_file(cnt_info->text.html, buf, false, &err)) {
+ if (!emstorage_move_file(cnt_info->text.html, move_buf, false, &err)) {
EM_DEBUG_EXCEPTION("emstorage_move_file failed [%d]", err);
goto FINISH_OFF;
}
- p_mail_data->file_path_html = EM_SAFE_STRDUP(buf);
+ p_mail_data->file_path_html = EM_SAFE_STRDUP(path_buf);
save_status = cnt_info->text.html_save_status;
}
- if ((err = emcore_get_preview_text_from_file(p_mail_data->file_path_plain, p_mail_data->file_path_html, MAX_PREVIEW_TEXT_LENGTH, &p_mail_data->preview_text)) != EMAIL_ERROR_NONE)
+ if (cnt_info->text.mime_entity) {
+ memset(move_buf, 0x00, sizeof(move_buf));
+ memset(path_buf, 0x00, sizeof(path_buf));
+
+ if (!emstorage_create_dir(multi_user_name, EML_FOLDER, eml_mail_id, 0, &err)) {
+ EM_DEBUG_EXCEPTION("emstorage_create_dir failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ if (!emstorage_get_save_name(multi_user_name, EML_FOLDER, eml_mail_id,
+ 0, "mime_entity", move_buf, path_buf,
+ sizeof(path_buf), &err)) {
+ EM_DEBUG_EXCEPTION("emstorage_get_save_name failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ if (!emstorage_move_file(cnt_info->text.mime_entity, move_buf, false, &err)) {
+ EM_DEBUG_EXCEPTION("emstorage_move_file failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ p_mail_data->file_path_mime_entity = EM_SAFE_STRDUP(path_buf);
+ }
+
+ if ((err = emcore_get_preview_text_from_file(multi_user_name,
+ p_mail_data->file_path_plain,
+ p_mail_data->file_path_html,
+ MAX_PREVIEW_TEXT_LENGTH,
+ &p_mail_data->preview_text)) != EMAIL_ERROR_NONE)
EM_DEBUG_EXCEPTION("emcore_get_preview_text_from_file error [%d]", err);
for (ai = cnt_info->file; ai; ai = ai->next, local_attachment_count++) {}
@@ -5542,29 +1313,36 @@ INTERNAL_FUNC int emcore_make_mail_data_from_mime_data(struct _m_mesg *mmsg, str
EM_DEBUG_LOG_SEC("attachment[%d].attachment_name[%s]", i, attachment[i].attachment_name);
EM_DEBUG_LOG("attachment[%d].drm_status[%d]", i, attachment[i].drm_status);
EM_DEBUG_LOG("attachment[%d].inline_content_status[%d]", i, attachment[i].inline_content_status);
- EM_DEBUG_LOG("attachment[%d].attachment_mime_type : [%s]", i, attachment[i].attachment_mime_type);
+ EM_DEBUG_LOG("attachment[%d].attachment_mime_type : [%s]", i, attachment[i].attachment_mime_type);
if (ai->save) {
- if (!emstorage_create_dir(EML_FOLDER, eml_mail_id, i + 1, &err)) {
+ memset(move_buf, 0x00, sizeof(move_buf));
+ memset(path_buf, 0x00, sizeof(path_buf));
+
+ if (!emstorage_create_dir(multi_user_name, EML_FOLDER, eml_mail_id, i + 1, &err)) {
EM_DEBUG_EXCEPTION("emstorage_create_dir failed [%d]", err);
goto FINISH_OFF;
}
- if (!emstorage_get_save_name(EML_FOLDER, eml_mail_id, i + 1, attachment[i].attachment_name, buf, sizeof(buf), &err)) {
+ if (!emstorage_get_save_name(multi_user_name, EML_FOLDER, eml_mail_id,
+ i + 1, attachment[i].attachment_name, move_buf,
+ path_buf, sizeof(path_buf), &err)) {
EM_DEBUG_EXCEPTION("emstorage_get_save_name failed [%d]", err);
goto FINISH_OFF;
}
- if (!emstorage_move_file(ai->save, buf, false, &err)) {
+ if (!emstorage_move_file(ai->save, move_buf, false, &err)) {
EM_DEBUG_EXCEPTION("emstorage_move_file failed [%d]", err);
/* delete all created files. */
- if (!emstorage_get_save_name(EML_FOLDER, eml_mail_id, 0, NULL, buf, sizeof(buf), NULL)) {
+ if (!emstorage_get_save_name(multi_user_name, EML_FOLDER, eml_mail_id,
+ 0, NULL, move_buf, path_buf,
+ sizeof(path_buf), NULL)) {
EM_DEBUG_EXCEPTION("emstorage_get_save_name failed...");
/* goto FINISH_OFF; */
}
- if (!emstorage_delete_dir(buf, NULL)) {
+ if (!emstorage_delete_dir(move_buf, NULL)) {
EM_DEBUG_EXCEPTION("emstorage_delete_dir failed...");
/* goto FINISH_OFF; */
}
@@ -5573,7 +1351,7 @@ INTERNAL_FUNC int emcore_make_mail_data_from_mime_data(struct _m_mesg *mmsg, str
goto FINISH_OFF;
}
- attachment[i].attachment_path = EM_SAFE_STRDUP(buf);
+ attachment[i].attachment_path = EM_SAFE_STRDUP(path_buf);
}
EM_DEBUG_LOG_SEC("attachment[%d].attachment_path[%s]", i, attachment[i].attachment_path);
@@ -5598,29 +1376,35 @@ INTERNAL_FUNC int emcore_make_mail_data_from_mime_data(struct _m_mesg *mmsg, str
EM_DEBUG_LOG_SEC("attachment[%d].attachment_name[%s]", i, attachment[i].attachment_name);
EM_DEBUG_LOG("attachment[%d].drm_status[%d]", i, attachment[i].drm_status);
EM_DEBUG_LOG("attachment[%d].inline_content_status[%d]", i, attachment[i].inline_content_status);
- EM_DEBUG_LOG("attachment[%d].attachment_mime_type : [%s]", i, attachment[i].attachment_mime_type);
+ EM_DEBUG_LOG("attachment[%d].attachment_mime_type : [%s]", i, attachment[i].attachment_mime_type);
if (ai->save) {
- if (!emstorage_create_dir(EML_FOLDER, eml_mail_id, 0, &err)) {
+ memset(move_buf, 0x00, sizeof(move_buf));
+ memset(path_buf, 0x00, sizeof(path_buf));
+
+ if (!emstorage_create_dir(multi_user_name, EML_FOLDER, eml_mail_id, 0, &err)) {
EM_DEBUG_EXCEPTION("emstorage_create_dir failed [%d]", err);
goto FINISH_OFF;
}
- if (!emstorage_get_save_name(EML_FOLDER, eml_mail_id, 0, attachment[i].attachment_name, buf, sizeof(buf), &err)) {
+ if (!emstorage_get_save_name(multi_user_name, EML_FOLDER, eml_mail_id, 0,
+ attachment[i].attachment_name, move_buf, path_buf,
+ sizeof(path_buf), &err)) {
EM_DEBUG_EXCEPTION("emstorage_get_save_name failed [%d]", err);
goto FINISH_OFF;
}
- if (!emstorage_move_file(ai->save, buf, false, &err)) {
+ if (!emstorage_move_file(ai->save, move_buf, false, &err)) {
EM_DEBUG_EXCEPTION("emstorage_move_file failed [%d]", err);
/* delete all created files. */
- if (!emstorage_get_save_name(EML_FOLDER, eml_mail_id, 0, NULL, buf, sizeof(buf), NULL)) {
+ if (!emstorage_get_save_name(multi_user_name, EML_FOLDER, eml_mail_id, 0,
+ NULL, move_buf, path_buf, sizeof(path_buf), NULL)) {
EM_DEBUG_EXCEPTION("emstorage_get_save_name failed...");
/* goto FINISH_OFF; */
}
- if (!emstorage_delete_dir(buf, NULL)) {
+ if (!emstorage_delete_dir(move_buf, NULL)) {
EM_DEBUG_EXCEPTION("emstorage_delete_dir failed...");
/* goto FINISH_OFF; */
}
@@ -5629,7 +1413,7 @@ INTERNAL_FUNC int emcore_make_mail_data_from_mime_data(struct _m_mesg *mmsg, str
goto FINISH_OFF;
}
- attachment[i].attachment_path = EM_SAFE_STRDUP(buf);
+ attachment[i].attachment_path = EM_SAFE_STRDUP(path_buf);
}
EM_DEBUG_LOG_SEC("attachment[%d].attachment_path[%s]", i, attachment[i].attachment_path);
@@ -5675,13 +1459,16 @@ FINISH_OFF:
return ret;
}
-INTERNAL_FUNC int emcore_parse_mime_file_to_mail(char *eml_file_path, email_mail_data_t **output_mail_data, email_attachment_data_t **output_attachment_data, int *output_attachment_count, int *err_code)
+INTERNAL_FUNC int emcore_parse_mime_file_to_mail(char *eml_file_path,
+ email_mail_data_t **output_mail_data,
+ email_attachment_data_t **output_attachment_data,
+ int *output_attachment_count,
+ int *err_code)
{
EM_DEBUG_FUNC_BEGIN_SEC("eml_file_path : [%s], output_mail_data : [%p]", eml_file_path, output_mail_data);
int err = EMAIL_ERROR_NONE;
int ret = false;
- char buf[512];
char *mime_entity = NULL;
struct _m_content_info *cnt_info = NULL;
struct _m_mesg *mmsg = NULL;
@@ -5718,37 +1505,24 @@ INTERNAL_FUNC int emcore_parse_mime_file_to_mail(char *eml_file_path, email_mail
emcore_gmime_init();
if (!emcore_gmime_eml_parse_mime(eml_file_path, mmsg->rfc822header, cnt_info, &err)) {
+ emcore_gmime_shutdown();
EM_DEBUG_EXCEPTION("emcore_gmime_parse_mime failed : [%d]", err);
err = EMAIL_ERROR_INVALID_DATA;
- emcore_gmime_shutdown();
goto FINISH_OFF;
}
- emcore_gmime_shutdown();
- if (!emcore_make_mail_data_from_mime_data(mmsg, cnt_info, output_mail_data, output_attachment_data, output_attachment_count, &err)) {
+ if (!emcore_make_mail_data_from_mime_data(mmsg,
+ cnt_info,
+ output_mail_data,
+ output_attachment_data,
+ output_attachment_count,
+ &err)) {
+ emcore_gmime_shutdown();
EM_DEBUG_EXCEPTION("emcore_make_mail_tbl_data_from_mime failed : [%d]", err);
goto FINISH_OFF;
}
-
- if ((*output_mail_data)->smime_type == EMAIL_SMIME_SIGNED || (*output_mail_data)->smime_type == EMAIL_PGP_SIGNED) {
- if (!emcore_get_mime_entity(eml_file_path, &mime_entity, &err)) {
- EM_DEBUG_EXCEPTION("emcore_get_mime_entity failed: [%d]", err);
- goto FINISH_OFF;
- }
-
- if (!emstorage_get_save_name((*output_mail_data)->account_id, (*output_mail_data)->mail_id, 0, "mime_entity", buf, sizeof(buf), &err)) {
- EM_DEBUG_EXCEPTION("emstorage_get_save_name failed : [%d]", err);
- goto FINISH_OFF;
- }
-
- if (!emstorage_move_file(mime_entity, buf, false, &err)) {
- EM_DEBUG_EXCEPTION("emstorage_move_file failed [%d]", err);
- goto FINISH_OFF;
- }
-
- (*output_mail_data)->file_path_mime_entity = EM_SAFE_STRDUP(buf);
- }
+ emcore_gmime_shutdown();
ret = true;
@@ -5771,12 +1545,13 @@ FINISH_OFF:
return ret;
}
-INTERNAL_FUNC int emcore_delete_parsed_data(email_mail_data_t *input_mail_data, int *err_code)
+INTERNAL_FUNC int emcore_delete_parsed_data(char *multi_user_name, email_mail_data_t *input_mail_data, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("input_mail_data : [%p]", input_mail_data);
int err = EMAIL_ERROR_NONE;
int ret = false;
- char buf[512];
+ char buf[MAX_PATH] = {0};
+ char *prefix_path = NULL;
if (!input_mail_data) {
EM_DEBUG_EXCEPTION("Invliad parameter");
@@ -5790,25 +1565,41 @@ INTERNAL_FUNC int emcore_delete_parsed_data(email_mail_data_t *input_mail_data,
goto FINISH_OFF;
}
- eml_data_count = eml_data_count - 1;
-
- if (eml_data_count == 0) {
- SNPRINTF(buf, sizeof(buf), "%s%s%d", MAILHOME, DIR_SEPERATOR, input_mail_data->account_id);
+ if (EM_SAFE_STRLEN(multi_user_name) > 0) {
+ err = emcore_get_container_path(multi_user_name, &prefix_path);
+ if (err != EMAIL_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("emcore_get_container_path failed :[%d]", err);
+ goto FINISH_OFF;
+ }
} else {
- SNPRINTF(buf, sizeof(buf), "%s%s%d%s%d", MAILHOME, DIR_SEPERATOR, input_mail_data->account_id, DIR_SEPERATOR, input_mail_data->mail_id);
+ prefix_path = strdup("");
}
- EM_DEBUG_LOG("Directory : [%s]", buf);
+ if (!input_mail_data->mail_id) {
+ SNPRINTF(buf, sizeof(buf), "%s%s%s%d", prefix_path, MAILHOME, DIR_SEPERATOR, input_mail_data->account_id);
+ } else {
+ SNPRINTF(buf, sizeof(buf), "%s%s%s%d%s%d", prefix_path, MAILHOME, DIR_SEPERATOR, input_mail_data->account_id, DIR_SEPERATOR, input_mail_data->mail_id);
+ }
if (!emstorage_delete_dir(buf, &err)) {
- EM_DEBUG_EXCEPTION("emstorage_delete_dir failed");
- goto FINISH_OFF;
+ EM_DEBUG_LOG("emstorage_delete_dir failed : buf[%s]", buf);
+ memset(buf, 0x00, sizeof(buf));
+ SNPRINTF(buf, sizeof(buf), "%s%s%d", MAILHOME, DIR_SEPERATOR, input_mail_data->account_id);
+
+ if (!emstorage_delete_dir(buf, &err)) {
+ EM_DEBUG_EXCEPTION("emstorage_delete_dir failed : buf[%s]", buf);
+ goto FINISH_OFF;
+ }
+
+ err = EMAIL_ERROR_NONE;
}
ret = true;
FINISH_OFF:
+ EM_SAFE_FREE(prefix_path);
+
if (err_code)
*err_code = err;
@@ -5818,22 +1609,10 @@ FINISH_OFF:
INTERNAL_FUNC int emcore_get_mime_entity(char *mime_path, char **output_path, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("mime_path : [%s], output_path : [%p]", mime_path, output_path);
- int ret = false;
int err = EMAIL_ERROR_NONE;
- int is_file = 1;
- int search = 0;
- long start_mime_entity = 0;
- long end_mime_entity = 0;
- char buf[MIME_LINE_LEN] = {0x00, };
- char *mime_entity_path = NULL;
- char *content_type = NULL;
- char boundary[BOUNDARY_LEN] = {0x00,};
- char *boundary_string = NULL;
- char *p_mime_entity = NULL;
- FILE *fp_read = NULL;
- FILE *fp_write = NULL;
- struct _m_mesg *mmsg = NULL;
- char errno_buf[ERRNO_BUF_SIZE] = {0};
+ int ret = false;
+ int fd = 0;
+ char *tmp_path = NULL;
if (!mime_path) {
EM_DEBUG_EXCEPTION("Invalid parameter");
@@ -5841,385 +1620,38 @@ INTERNAL_FUNC int emcore_get_mime_entity(char *mime_path, char **output_path, in
goto FINISH_OFF;
}
- /* Get the header info */
- mmsg = (struct _m_mesg *)em_malloc(sizeof(struct _m_mesg));
- if (mmsg == NULL) {
- EM_DEBUG_EXCEPTION("em_malloc failed");
- err = EMAIL_ERROR_OUT_OF_MEMORY;
- goto FINISH_OFF;
- }
-
- err = em_fopen(mime_path, "r", &fp_read);
+ err = em_open(mime_path, O_RDONLY, 0, &fd);
if (err != EMAIL_ERROR_NONE) {
- EM_DEBUG_EXCEPTION_SEC("File em_fopen(read) is failed : filename [%s][%d]", mime_path, err);
- goto FINISH_OFF;
- }
-
- if (!emcore_mime_parse_header(fp_read, is_file, &mmsg->rfc822header, &mmsg->header, &err)) {
- EM_DEBUG_EXCEPTION("emcore_mime_parse_header failed : [%d]", err);
- err = EMAIL_ERROR_INVALID_DATA;
- goto FINISH_OFF;
- }
-
- /* Parsing the mime header */
- content_type = emcore_mime_get_header_value(mmsg->header->part_header, CONTENT_TYPE, NULL);
- EM_DEBUG_LOG_SEC("Content_type : [%s]", content_type);
- if (content_type && strcasestr(content_type, "signed")==NULL) {
- EM_DEBUG_EXCEPTION("Invalid parameter : No signed mail");
- err = EMAIL_ERROR_INVALID_PARAM;
- goto FINISH_OFF;
- }
-
- /* Create mime_entity file */
- if (!emcore_get_temp_file_name(&mime_entity_path, &err)) {
- EM_DEBUG_EXCEPTION("emcore_get_temp_file_name failed[%d]", err);
- goto FINISH_OFF;
- }
- EM_DEBUG_LOG("mime_entity_path = %s", mime_entity_path);
-
- err = em_fopen(mime_entity_path, "w", &fp_write);
- if (err != EMAIL_ERROR_NONE) {
- EM_DEBUG_EXCEPTION_SEC("File em_fopen(write) is failed : filename [%s][%d]", mime_entity_path, err);
- goto FINISH_OFF;
- }
-
- boundary_string = emcore_mime_get_header_value(mmsg->header->part_header, CONTENT_BOUNDARY, NULL);
- SNPRINTF(boundary, BOUNDARY_LEN, "--%s%s", boundary_string, CRLF_STRING);
-
- while (TRUE) {
- if (!emcore_get_line_from_file((void *)fp_read, buf, MIME_LINE_LEN, &err)) {
- if (err == EMAIL_ERROR_NO_MORE_DATA) {
- EM_DEBUG_LOG("this mail is partial body");
- end_mime_entity = ftell(fp_read);
- if ( end_mime_entity < 0 ) {
- EM_DEBUG_EXCEPTION("ftell failed [%s]", EM_STRERROR(errno_buf));
- goto FINISH_OFF;
- }
- err = EMAIL_ERROR_NONE;
- break;
- }
- EM_DEBUG_EXCEPTION("emcore_mime_get_line_from_file failed [%d]", err);
- goto FINISH_OFF;
- }
-
- if (!strcmp(buf, boundary)) {
- search++;
- if (search == 1) {
- start_mime_entity = ftell(fp_read);
- if( start_mime_entity < 0 ) { /*prevent 24473*/
- EM_DEBUG_EXCEPTION("ftell failed [%s]", EM_STRERROR(errno_buf));
- goto FINISH_OFF;
- }
- } else if (search == 2) {
- end_mime_entity = ftell(fp_read);
- if( end_mime_entity < 0 ) { /*prevent 24473*/
- EM_DEBUG_EXCEPTION("ftell failed [%s]", EM_STRERROR(errno_buf));
- goto FINISH_OFF;
- }
- break;
- }
- }
- }
-
- p_mime_entity = em_malloc(end_mime_entity - start_mime_entity);
- if (p_mime_entity == NULL) {
- EM_DEBUG_EXCEPTION("em_malloc failed");
- err = EMAIL_ERROR_OUT_OF_MEMORY;
+ EM_DEBUG_EXCEPTION("em_open failed");
goto FINISH_OFF;
}
- if (fseek(fp_read, start_mime_entity, SEEK_SET) < 0) {
- EM_DEBUG_EXCEPTION("fseek failed");
- err = EMAIL_ERROR_SYSTEM_FAILURE;
- goto FINISH_OFF;
- }
+ emcore_gmime_init();
+ tmp_path = emcore_gmime_get_mime_entity(fd);
+ emcore_gmime_shutdown();
- /* +2 : CRLF line */
- if ((ret = fread(p_mime_entity, 1, end_mime_entity - (start_mime_entity + EM_SAFE_STRLEN(boundary) + 2), fp_read)) < 0) {
- EM_DEBUG_EXCEPTION("fread failed");
- err = EMAIL_ERROR_SYSTEM_FAILURE;
+ if (tmp_path == NULL) {
+ EM_DEBUG_EXCEPTION("emcore_gmime_get_mime_entity failed");
+ err = EMAIL_ERROR_INVALID_DATA;
goto FINISH_OFF;
}
- fprintf(fp_write, "%s", p_mime_entity);
-
ret = true;
FINISH_OFF:
-
- if (fp_read)
- fclose(fp_read);
-
- if (fp_write)
- fclose(fp_write);
-
- if (mmsg)
- emcore_mime_free_mime(mmsg);
-
- if (output_path)
- *output_path = EM_SAFE_STRDUP(mime_entity_path);
- EM_SAFE_FREE(mime_entity_path);
+
+ EM_SAFE_CLOSE(fd);
if (err_code)
*err_code = err;
- EM_SAFE_FREE(p_mime_entity);
+ if (output_path)
+ *output_path = tmp_path;
EM_DEBUG_FUNC_END();
return ret;
}
-int emcore_decode_body_text_from_file(FILE *stream, char *boundary_str, int encoding, int mode, int fd, char **holder, int *end_of_parsing, int *size)
-{
- EM_DEBUG_FUNC_BEGIN();
- int error = EMAIL_ERROR_NONE;
- int p_size = 0;
- int partial_body = 0;
- int dec_len = 0;
- long start_location = 0;
- long end_location = 0;
- char boundary[BOUNDARY_LEN] = {0x00, };
- char boundary_end[BOUNDARY_LEN] = {0x00, };
- char buf[MIME_LINE_LEN] = {0x00, };
- char *body = NULL;
- int modified_body_size = 0;
- char *modified_body = NULL;
- char errno_buf[ERRNO_BUF_SIZE] = {0};
-
- if (boundary_str) {
- /* if there boundary, this content is from current line to ending boundary */
- memset(boundary, 0x00, BOUNDARY_LEN);
- memset(boundary_end, 0x00, BOUNDARY_LEN);
-
- SNPRINTF(boundary, BOUNDARY_LEN, "--%s%s", boundary_str, CRLF_STRING);
- SNPRINTF(boundary_end, BOUNDARY_LEN, "--%s%s", boundary_str, "--");
- }
-
- start_location = ftell(stream);
- if(start_location < 0 ) { /*prevent 35555*/
- error = EMAIL_ERROR_INVALID_PARAM;
- EM_DEBUG_EXCEPTION("ftell failed : %s", EM_STRERROR(errno_buf));
- goto FINISH_OFF;
- }
-
- while (TRUE) {
- if (!emcore_get_line_from_file(stream, buf, MIME_LINE_LEN, &error)) {
- if (error != EMAIL_ERROR_NO_MORE_DATA) {
- EM_DEBUG_EXCEPTION("emcore_get_line_from_file failed");
- error = EMAIL_ERROR_SYSTEM_FAILURE;
- goto FINISH_OFF;
- }
- }
-
- if (boundary_str) {
- if (!strcmp(buf, boundary)) { /* the other part started. the parsing of other part will be started */
- *end_of_parsing = 0;
- break;
- }
- else if (strcasestr(buf, boundary_end)) { /* if ending boundary, the parsing of other multipart will be started */
- *end_of_parsing = 1;
- break;
- }
- }
-
- if (error != EMAIL_ERROR_NONE) {
- partial_body = 1;
- *end_of_parsing = 2;
- break;
- }
- }
-
- EM_DEBUG_LOG("partial_body : [%d], buf:[%s]", partial_body, buf);
- end_location = ftell(stream);
- if(end_location < 0 ) { /*prevent 35555*/
- error = EMAIL_ERROR_INVALID_PARAM;
- EM_DEBUG_EXCEPTION("ftell failed : %s", EM_STRERROR(errno_buf));
- goto FINISH_OFF;
- }
-
- if (partial_body)
- p_size = end_location - start_location;
- else
- p_size = end_location - start_location - EM_SAFE_STRLEN(buf);
-
- body = em_malloc(p_size + 1);
- if (body == NULL) {
- EM_DEBUG_EXCEPTION("em_malloc failed");
- error = EMAIL_ERROR_OUT_OF_MEMORY;
- goto FINISH_OFF;
- }
-
- fseek(stream, start_location, SEEK_SET);
- if (fread(body, sizeof(char), p_size, stream) != p_size) {
- EM_DEBUG_EXCEPTION("fread failed");
- error = EMAIL_ERROR_SYSTEM_FAILURE;
- goto FINISH_OFF;
- }
-
- if (mode > SAVE_TYPE_SIZE) { /* decode content */
- emcore_decode_body_text(body, p_size, encoding, &dec_len, &error);
-
- modified_body = em_malloc(dec_len + 1);
- if (modified_body == NULL) {
- EM_DEBUG_EXCEPTION("em_malloc failed");
- error = EMAIL_ERROR_OUT_OF_MEMORY;
- goto FINISH_OFF;
- }
-
- memcpy(modified_body, body, dec_len); /*prevent 35585 */
- modified_body_size = dec_len;
-
- if (mode == SAVE_TYPE_BUFFER) { /* save content to buffer */
- *holder = EM_SAFE_STRDUP(modified_body);
- } else if (mode == SAVE_TYPE_FILE) { /* save content to file */
- EM_DEBUG_LOG("Before write : size[%d]", modified_body_size);
- if (write(fd, modified_body, modified_body_size) != modified_body_size) {
- EM_DEBUG_EXCEPTION("write failed");
- error = EMAIL_ERROR_SYSTEM_FAILURE;
- goto FINISH_OFF;
- }
- }
- }
-
- fseek((FILE *)stream, end_location, SEEK_SET);
-
-FINISH_OFF:
-
- if (size)
- *size = modified_body_size;
-
- EM_SAFE_FREE(modified_body);
- EM_SAFE_FREE(body); /*prevent 35585 */
- return error;
-}
-
-int emcore_decode_body_text_from_sock(void *stream, char *boundary_str, int encoding, int mode, int fd, char **holder, int *end_of_parsing, int *size)
-{
- EM_DEBUG_FUNC_BEGIN();
- int error = EMAIL_ERROR_NONE;
- int sz = 0;
- int dec_len = 0;
- char boundary[BOUNDARY_LEN] = {0x00, };
- char boundary_end[BOUNDARY_LEN] = {0x00, };
- char buf[MIME_LINE_LEN] = {0x00, };
- char *result_buffer = NULL;
- int result_buffer_size = 0;
- char *pTemp = NULL;
-
- if (boundary_str) {
- /* if there boundary, this content is from current line to ending boundary */
- memset(boundary, 0x00, BOUNDARY_LEN);
- memset(boundary_end, 0x00, BOUNDARY_LEN);
-
- SNPRINTF(boundary, BOUNDARY_LEN, "--%s%s", boundary_str, CRLF_STRING);
- SNPRINTF(boundary_end, BOUNDARY_LEN, "--%s%s", boundary_str, "--\r\n");
- }
-
- while (TRUE) {
-/* don't delete the comment. several threads including event thread call it
- if (!emcore_check_thread_status()) {
- EM_DEBUG_EXCEPTION("EMAIL_ERROR_CANCELLED");
- error = EMAIL_ERROR_CANCELLED;
- goto FINISH_OFF;
- }
-*/
- if (!emcore_mime_get_line_from_sock(stream, buf, MIME_LINE_LEN, &error)) {
- if (error != EMAIL_ERROR_NO_MORE_DATA) {
- EM_DEBUG_EXCEPTION("emcore_mime_get_line_from_sock failed");
- error = EMAIL_ERROR_SYSTEM_FAILURE;
- goto FINISH_OFF;
- }
-
- EM_DEBUG_LOG("This mail is partial body");
-
- *end_of_parsing = 2;
-
- error = EMAIL_ERROR_NONE;
-
- break;
- }
-
- if (boundary_str) {
- if (!strcmp(buf, boundary)) { /* the other part started. the parsing of other part will be started */
- *end_of_parsing = 0;
- break;
- }
- else if (!strcmp(buf, boundary_end)) { /* if ending boundary, the parsing of other multipart will be started */
- *end_of_parsing = 1;
- break;
- }
- }
-
- /* parsing string started by '.' in POP3 */
- if ((buf[0] == '.' && buf[1] == '.') && (encoding == ENCQUOTEDPRINTABLE || encoding == ENC7BIT)) {
- strncpy(buf, buf+1, MIME_LINE_LEN-1);
- buf[EM_SAFE_STRLEN(buf)] = NULL_CHAR;
- }
-
- if (encoding == ENCBASE64) {
- if (EM_SAFE_STRLEN(buf) >= 2)
- buf[EM_SAFE_STRLEN(buf)-2] = NULL_CHAR;
- } else if (encoding == ENCQUOTEDPRINTABLE) {
-/* if (strcmp(buf, CRLF_STRING) == 0 */
-/* continue */
- }
-
- dec_len = EM_SAFE_STRLEN(buf);
-
- if (mode > SAVE_TYPE_SIZE) { /* decode content */
- emcore_decode_body_text(buf, dec_len, encoding, &dec_len, &error);
-
- result_buffer = em_malloc(dec_len + 1);
- if (result_buffer == NULL) {
- EM_DEBUG_EXCEPTION("em_malloc failed");
- error = EMAIL_ERROR_OUT_OF_MEMORY;
- goto FINISH_OFF;
- }
-
- memcpy(result_buffer, buf, dec_len); /*prevent 35499*/
- result_buffer_size = dec_len;
-
- if (mode == SAVE_TYPE_BUFFER) { /* save content to buffer */
- pTemp = realloc(*holder, sz + result_buffer_size + 2);
- if (!pTemp) {
- EM_DEBUG_EXCEPTION("realloc failed...");
- error = EMAIL_ERROR_OUT_OF_MEMORY;
-
- EM_SAFE_FREE(*holder);
- EM_SAFE_FREE(result_buffer);
- goto FINISH_OFF;
- }
- else
- *holder = pTemp;
-
- memcpy(*holder + sz, result_buffer, result_buffer_size);
- (*holder)[sz + EM_SAFE_STRLEN(result_buffer) + 1] = NULL_CHAR;
- } else if (mode == SAVE_TYPE_FILE) { /* save content to file */
- if (write(fd, result_buffer, result_buffer_size) != result_buffer_size) {
- EM_DEBUG_EXCEPTION("write failed");
- error = EMAIL_ERROR_SYSTEM_FAILURE;
- goto FINISH_OFF;
- }
- }
-
- EM_SAFE_FREE(result_buffer);
- }
- sz += dec_len;
- }
-
-FINISH_OFF:
-
- EM_SAFE_FREE(result_buffer); /*prevent 35499*/
-
- if (error == EMAIL_ERROR_NONE) {
- if (size)
- *size = sz;
- }
-
- EM_DEBUG_FUNC_END("error [%d], sz[%d]", error, sz);
- return error;
-}
-
INTERNAL_FUNC int emcore_get_digest_type(char *micalg_value)
{
EM_DEBUG_FUNC_BEGIN();
diff --git a/email-core/email-core-mm-callbacks.c b/email-core/email-core-mm-callbacks.c
index 5bbb5ea..8990b9f 100755
--- a/email-core/email-core-mm-callbacks.c
+++ b/email-core/email-core-mm-callbacks.c
@@ -210,16 +210,26 @@ INTERNAL_FUNC void mm_login(NETMBX *mb, char *user, char *pwd, long trial)
char *password = NULL;
char *token = NULL;
char *save_ptr = NULL;
+ char *user_info = NULL;
+ char *temp = NULL;
+ char *multi_user_name = NULL;
if (!mb->user[0]) {
EM_DEBUG_EXCEPTION("invalid account_id...");
goto FINISH_OFF;
}
- account_id = atoi(mb->user);
+ user_info = EM_SAFE_STRDUP(mb->user);
- ref_account = emcore_get_account_reference(account_id);
+ token = strtok_r(user_info, TOKEN_FOR_MULTI_USER, &temp);
+ EM_DEBUG_LOG_SEC("Token : [%s], multi_user_name:[%s][%d]", token, temp, EM_SAFE_STRLEN(temp));
+ account_id = atoi(token);
+ token = NULL;
+ if (temp != NULL && EM_SAFE_STRLEN(temp) > 0)
+ multi_user_name = EM_SAFE_STRDUP(temp);
+
+ ref_account = emcore_get_account_reference(multi_user_name, account_id, true);
if (!ref_account) {
EM_DEBUG_EXCEPTION("emcore_get_account_reference failed");
goto FINISH_OFF;
@@ -240,7 +250,6 @@ INTERNAL_FUNC void mm_login(NETMBX *mb, char *user, char *pwd, long trial)
EM_DEBUG_LOG("incoming_server_authentication_method [%d]", ref_account->incoming_server_authentication_method);
if(ref_account->incoming_server_authentication_method == EMAIL_AUTHENTICATION_METHOD_XOAUTH2) {
-
token = strtok_r(ref_account->incoming_server_password, "\001", &save_ptr);
EM_DEBUG_LOG_SEC("token [%s]", token);
password = EM_SAFE_STRDUP(token);
@@ -263,8 +272,10 @@ FINISH_OFF:
EM_SAFE_FREE(ref_account);
}
+ EM_SAFE_FREE(user_info);
EM_SAFE_FREE(username);
EM_SAFE_FREE(password);
+ EM_SAFE_FREE(multi_user_name);
EM_DEBUG_FUNC_END();
}
@@ -280,7 +291,7 @@ INTERNAL_FUNC void mm_dlog(char *string)
INTERNAL_FUNC void mm_log(char *string, long errflg)
{
- switch ((short)errflg) {
+ switch (errflg) {
case NIL:
EM_DEBUG_LOG("IMAP_TOOLKIT_LOG [%s]", string);
break;
diff --git a/email-core/email-core-pgp.c b/email-core/email-core-pgp.c
index 4367af9..17afa56 100644
--- a/email-core/email-core-pgp.c
+++ b/email-core/email-core-pgp.c
@@ -61,7 +61,9 @@
static char *passphrase = NULL;
-static gboolean request_passwd(GMimeCryptoContext *ctx, const char *user_id, const char *prompt_ctx, gboolean reprompt, GMimeStream *response, GError **err)
+static gboolean request_passwd(GMimeCryptoContext *ctx, const char *user_id,
+ const char *prompt_ctx, gboolean reprompt,
+ GMimeStream *response, GError **err)
{
EM_DEBUG_FUNC_BEGIN();
EM_DEBUG_LOG("passpharse : [%s]", passphrase);
@@ -128,12 +130,11 @@ static int emcore_pgp_get_gmime_digest_algo(email_digest_type digest_type)
static int get_stack_of_recipients(char *recipients, GPtrArray **output_recipients_array) {
EM_DEBUG_FUNC_BEGIN();
int err = EMAIL_ERROR_NONE;
- int i, j = 0;
- char *temp_recipients = NULL;
- char *email_address = NULL;
-
- ADDRESS *token_address = NULL;
+ char *temp_key = NULL;
+ char *keys = NULL;
GPtrArray *p_recipients_array = NULL;
+ gchar **strings = NULL;
+ gchar **ptr = NULL;
p_recipients_array = g_ptr_array_new();
if (p_recipients_array == NULL) {
@@ -142,22 +143,18 @@ static int get_stack_of_recipients(char *recipients, GPtrArray **output_recipien
goto FINISH_OFF;
}
- temp_recipients = EM_SAFE_STRDUP(recipients);
- for (i = 0, j = EM_SAFE_STRLEN(temp_recipients); i < j ; i++)
- if (temp_recipients[i] == ';') temp_recipients[i] = ',';
+ keys = EM_SAFE_STRDUP(recipients);
+ strings = g_strsplit(keys, ",", -1);
- rfc822_parse_adrlist(&token_address, temp_recipients, NULL);
+ for (ptr = strings; *ptr; ptr++){
+ temp_key = NULL;
+ temp_key = g_strdup_printf("0x%s",*(ptr));
+ g_ptr_array_add(p_recipients_array, temp_key);
+ }
- while (token_address) {
- email_address = NULL;
- email_address = g_strdup_printf("%s@%s", token_address->mailbox, token_address->host);
-
- g_ptr_array_add(p_recipients_array, email_address);
- token_address = token_address->next;
- }
-
FINISH_OFF:
-
+ g_strfreev(strings);
+ EM_SAFE_FREE(keys);
if (err != EMAIL_ERROR_NONE)
g_ptr_array_free(p_recipients_array, true);
else
@@ -171,25 +168,30 @@ static GMimeSignatureStatus get_signature_status(GMimeSignatureList *signatures)
{
EM_DEBUG_FUNC_BEGIN();
- int i = 0;
+ int i = 0;
- GMimeSignature *sig = NULL;
- GMimeSignatureStatus status = GMIME_SIGNATURE_STATUS_GOOD;
-
- if (!signatures || signatures->array->len == 0)
- return GMIME_SIGNATURE_STATUS_ERROR;
-
- for (i = 0; i < g_mime_signature_list_length(signatures); i++) {
- sig = g_mime_signature_list_get_signature(signatures, i);
- if (sig) status = MAX(status, sig->status);
- }
+ GMimeSignature *sig = NULL;
+ GMimeSignatureStatus status = GMIME_SIGNATURE_STATUS_GOOD;
+
+ if (!signatures || signatures->array->len == 0)
+ return GMIME_SIGNATURE_STATUS_ERROR;
+
+ for (i = 0; i < g_mime_signature_list_length(signatures); i++) {
+ sig = g_mime_signature_list_get_signature(signatures, i);
+ if (sig) status = MAX(status, sig->status);
+ }
EM_DEBUG_FUNC_END();
return status;
}
-INTERNAL_FUNC int emcore_pgp_set_signed_message(char *certificate, char *password, char *mime_entity, char *user_id, email_digest_type digest_type, char **file_path)
+INTERNAL_FUNC int emcore_pgp_set_signed_message(char *certificate,
+ char *password,
+ char *mime_entity,
+ char *user_id,
+ email_digest_type digest_type,
+ char **file_path)
{
EM_DEBUG_FUNC_BEGIN_SEC("Certificate path : [%s], mime_entity : [%s]", certificate, mime_entity);
@@ -258,7 +260,12 @@ INTERNAL_FUNC int emcore_pgp_set_signed_message(char *certificate, char *passwor
p_digest_type = emcore_pgp_get_gmime_digest_algo(digest_type);
/* Set the signed message */
- if ((g_mime_crypto_context_sign(ctx, user_id, p_digest_type, clear_text, signed_text, &g_err) < 0) && (g_err != NULL)) {
+ if ((g_mime_crypto_context_sign(ctx,
+ user_id,
+ p_digest_type,
+ clear_text,
+ signed_text,
+ &g_err) < 0) && (g_err != NULL)) {
EM_DEBUG_EXCEPTION("g_mime_crypto_context_sign failed : [%s]", g_err->message);
err = EMAIL_ERROR_SYSTEM_FAILURE;
goto FINISH_OFF;
@@ -294,7 +301,13 @@ FINISH_OFF:
#endif
}
-INTERNAL_FUNC int emcore_pgp_set_encrypted_message(char *recipient_list, char *certificate, char *password, char *mime_entity, char *user_id, email_digest_type digest_type, char **file_path)
+INTERNAL_FUNC int emcore_pgp_set_encrypted_message(char *recipient_list,
+ char *certificate,
+ char *password,
+ char *mime_entity,
+ char *user_id,
+ email_digest_type digest_type,
+ char **file_path)
{
EM_DEBUG_FUNC_BEGIN_SEC("Certificate path : [%s], mime_entity : [%s]", certificate, mime_entity);
@@ -312,16 +325,13 @@ INTERNAL_FUNC int emcore_pgp_set_encrypted_message(char *recipient_list, char *c
GMimeStream *encrypted_text = NULL;
GError *g_err = NULL;
- if (!recipient_list || !password || !mime_entity || !user_id) {
+ if (!recipient_list || !mime_entity || !user_id) {
EM_DEBUG_EXCEPTION("Invalid param");
err = EMAIL_ERROR_INVALID_PARAM;
return err;
}
/* Initialized the output stream (signed stream) */
- EM_SAFE_FREE(passphrase);
- passphrase = EM_SAFE_STRDUP(password);
-
#if !GLIB_CHECK_VERSION(2, 31, 0)
g_thread_init(NULL);
#endif
@@ -371,7 +381,14 @@ INTERNAL_FUNC int emcore_pgp_set_encrypted_message(char *recipient_list, char *c
}
/* Set the signed message */
- if ((g_mime_crypto_context_encrypt(ctx, false, user_id, p_digest_type, recipients, clear_text, encrypted_text, &g_err) < 0) && (g_err != NULL)) {
+ if ((g_mime_crypto_context_encrypt(ctx,
+ false,
+ user_id,
+ p_digest_type,
+ recipients,
+ clear_text,
+ encrypted_text,
+ &g_err) < 0) && (g_err != NULL)) {
EM_DEBUG_EXCEPTION("NO signature : g_mime_crypto_context_encrypt failed : [%s]", g_err->message);
err = EMAIL_ERROR_SYSTEM_FAILURE;
goto FINISH_OFF;
@@ -410,7 +427,13 @@ FINISH_OFF:
}
-INTERNAL_FUNC int emcore_pgp_set_signed_and_encrypted_message(char *recipient_list, char *certificate, char *password, char *mime_entity, char *user_id, email_digest_type digest_type, char **file_path)
+INTERNAL_FUNC int emcore_pgp_set_signed_and_encrypted_message(char *recipient_list,
+ char *certificate,
+ char *password,
+ char *mime_entity,
+ char *user_id,
+ email_digest_type digest_type,
+ char **file_path)
{
EM_DEBUG_FUNC_BEGIN_SEC("mime_entity : [%s]", mime_entity);
@@ -422,7 +445,6 @@ INTERNAL_FUNC int emcore_pgp_set_signed_and_encrypted_message(char *recipient_li
char temp_pgp_filepath[512] = {0, };
GPtrArray *recipients = NULL;
-
GMimeCryptoContext *ctx = NULL;
GMimeStream *clear_text = NULL;
GMimeStream *encrypted_text = NULL;
@@ -487,7 +509,14 @@ INTERNAL_FUNC int emcore_pgp_set_signed_and_encrypted_message(char *recipient_li
}
/* Set the signed message */
- if ((g_mime_crypto_context_encrypt(ctx, true, user_id, p_digest_type, recipients, clear_text, encrypted_text, &g_err) < 0) && (g_err != NULL)) {
+ if ((g_mime_crypto_context_encrypt(ctx,
+ true,
+ user_id,
+ p_digest_type,
+ recipients,
+ clear_text,
+ encrypted_text,
+ &g_err) < 0) && (g_err != NULL)) {
EM_DEBUG_EXCEPTION("Signature : g_mime_crypto_context_encrypt failed : [%s]", g_err->message);
err = EMAIL_ERROR_SYSTEM_FAILURE;
goto FINISH_OFF;
@@ -526,7 +555,10 @@ FINISH_OFF:
}
-INTERNAL_FUNC int emcore_pgp_get_verify_signature(char *signature_path, char *mime_entity, email_digest_type digest_type, int *verify)
+INTERNAL_FUNC int emcore_pgp_get_verify_signature(char *signature_path,
+ char *mime_entity,
+ email_digest_type digest_type,
+ int *verify)
{
EM_DEBUG_FUNC_BEGIN_SEC("signature path : [%s], mime_entity : [%s]", signature_path, mime_entity);
@@ -640,7 +672,11 @@ FINISH_OFF:
}
-INTERNAL_FUNC int emcore_pgp_get_decrypted_message(char *encrypted_message, char *password, int sign, char **decrypted_file, int *verify)
+INTERNAL_FUNC int emcore_pgp_get_decrypted_message(char *encrypted_message,
+ char *password,
+ int sign,
+ char **decrypted_file,
+ int *verify)
{
EM_DEBUG_FUNC_BEGIN_SEC("Encrypted message : [%s], password : [%s]", encrypted_message, password);
@@ -714,12 +750,14 @@ INTERNAL_FUNC int emcore_pgp_get_decrypted_message(char *encrypted_message, char
goto FINISH_OFF;
}
- if (sign) {
- if (!result->signatures || get_signature_status(result->signatures) != GMIME_SIGNATURE_STATUS_GOOD)
+ if (result->signatures) {
+ if (get_signature_status(result->signatures) != GMIME_SIGNATURE_STATUS_GOOD)
p_verify = false;
else
p_verify = true;
- }
+ } else {
+ p_verify = -1;
+ }
FINISH_OFF:
@@ -744,7 +782,7 @@ FINISH_OFF:
close(decrypted_fd);
if (verify)
- *verify = p_verify;
+ *verify = p_verify;
if (decrypted_file)
*decrypted_file = EM_SAFE_STRDUP(temp_decrypt_filepath);
diff --git a/email-core/email-core-signal.c b/email-core/email-core-signal.c
index 8964cb6..b9756b2 100755
--- a/email-core/email-core-signal.c
+++ b/email-core/email-core-signal.c
@@ -163,8 +163,6 @@ FINISH_OFF:
return ret;
}
-
-
INTERNAL_FUNC int em_send_notification_to_active_sync_engine(int subType, ASNotiData *data)
{
EM_DEBUG_FUNC_BEGIN("subType [%d], data [%p]", subType, data);
@@ -175,6 +173,7 @@ INTERNAL_FUNC int em_send_notification_to_active_sync_engine(int subType, ASNoti
int i = 0;
dbus_uint32_t error = 0;
int ret = true;
+ const char *null_string = "";
ENTER_CRITICAL_SECTION(_dbus_noti_lock);
@@ -199,6 +198,11 @@ INTERNAL_FUNC int em_send_notification_to_active_sync_engine(int subType, ASNoti
dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->send_mail.handle), DBUS_TYPE_INVALID);
dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->send_mail.account_id), DBUS_TYPE_INVALID);
dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->send_mail.mail_id), DBUS_TYPE_INVALID);
+ if (data->send_mail.multi_user_name)
+ dbus_message_append_args(signal, DBUS_TYPE_STRING, &(data->send_mail.multi_user_name), DBUS_TYPE_INVALID);
+ else
+ dbus_message_append_args(signal, DBUS_TYPE_STRING, &(null_string), DBUS_TYPE_INVALID);
+
break;
case ACTIVE_SYNC_NOTI_SEND_SAVED: /* publish a send notification to ASE (active sync engine) */
EM_DEBUG_EXCEPTION("Not support yet : subType[ACTIVE_SYNC_NOTI_SEND_SAVED]", subType);
@@ -214,6 +218,11 @@ INTERNAL_FUNC int em_send_notification_to_active_sync_engine(int subType, ASNoti
dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->sync_header.handle ), DBUS_TYPE_INVALID);
dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->sync_header.account_id ), DBUS_TYPE_INVALID);
dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->sync_header.mailbox_id ), DBUS_TYPE_INVALID);
+ if (data->sync_header.multi_user_name)
+ dbus_message_append_args(signal, DBUS_TYPE_STRING, &(data->sync_header.multi_user_name), DBUS_TYPE_INVALID);
+ else
+ dbus_message_append_args(signal, DBUS_TYPE_STRING, &(null_string), DBUS_TYPE_INVALID);
+
break;
case ACTIVE_SYNC_NOTI_DOWNLOAD_BODY: /* publish a download body notification to ASE */
EM_DEBUG_LOG("handle:[%d]", data->download_body.handle);
@@ -225,6 +234,13 @@ INTERNAL_FUNC int em_send_notification_to_active_sync_engine(int subType, ASNoti
dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->download_body.account_id ), DBUS_TYPE_INVALID);
dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->download_body.mail_id ), DBUS_TYPE_INVALID);
dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->download_body.with_attachment ), DBUS_TYPE_INVALID);
+ if (data->download_body.multi_user_name)
+ dbus_message_append_args(signal, DBUS_TYPE_STRING, &(data->download_body.multi_user_name), DBUS_TYPE_INVALID);
+ else
+ dbus_message_append_args(signal, DBUS_TYPE_STRING, &(null_string), DBUS_TYPE_INVALID);
+
+ break;
+
break;
case ACTIVE_SYNC_NOTI_DOWNLOAD_ATTACHMENT:
EM_DEBUG_LOG("handle:[%d]", data->download_attachment.handle);
@@ -236,10 +252,17 @@ INTERNAL_FUNC int em_send_notification_to_active_sync_engine(int subType, ASNoti
dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->download_attachment.account_id ), DBUS_TYPE_INVALID);
dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->download_attachment.mail_id ), DBUS_TYPE_INVALID);
dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->download_attachment.attachment_order), DBUS_TYPE_INVALID);
+ if (data->download_attachment.multi_user_name)
+ dbus_message_append_args(signal, DBUS_TYPE_STRING, &(data->download_attachment.multi_user_name), DBUS_TYPE_INVALID);
+ else
+ dbus_message_append_args(signal, DBUS_TYPE_STRING, &(null_string), DBUS_TYPE_INVALID);
+
break;
+
case ACTIVE_SYNC_NOTI_VALIDATE_ACCOUNT:
EM_DEBUG_EXCEPTION("Not support yet : subType[ACTIVE_SYNC_NOTI_VALIDATE_ACCOUNT]", subType);
break;
+
case ACTIVE_SYNC_NOTI_CANCEL_JOB:
EM_DEBUG_LOG("account_id:[%d]", data->cancel_job.account_id );
EM_DEBUG_LOG("handle to cancel:[%d]", data->cancel_job.handle);
@@ -248,7 +271,13 @@ INTERNAL_FUNC int em_send_notification_to_active_sync_engine(int subType, ASNoti
dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->cancel_job.account_id ), DBUS_TYPE_INVALID);
dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->cancel_job.handle ), DBUS_TYPE_INVALID);
dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->cancel_job.cancel_type ), DBUS_TYPE_INVALID);
+ if (data->cancel_job.multi_user_name)
+ dbus_message_append_args(signal, DBUS_TYPE_STRING, &(data->cancel_job.multi_user_name), DBUS_TYPE_INVALID);
+ else
+ dbus_message_append_args(signal, DBUS_TYPE_STRING, &(null_string), DBUS_TYPE_INVALID);
+
break;
+
case ACTIVE_SYNC_NOTI_SEARCH_ON_SERVER:
EM_DEBUG_LOG("account_id:[%d]", data->search_mail_on_server.account_id );
EM_DEBUG_LOG("mailbox_id:[%d]", data->search_mail_on_server.mailbox_id );
@@ -288,6 +317,8 @@ INTERNAL_FUNC int em_send_notification_to_active_sync_engine(int subType, ASNoti
case EMAIL_SEARCH_FILTER_TYPE_TO :
case EMAIL_SEARCH_FILTER_TYPE_MESSAGE_ID :
case EMAIL_SEARCH_FILTER_TYPE_ATTACHMENT_NAME :
+ case EMAIL_SEARCH_FILTER_TYPE_CHARSET :
+ case EMAIL_SEARCH_FILTER_TYPE_USER_DEFINED :
dbus_message_append_args(signal, DBUS_TYPE_STRING, &(data->search_mail_on_server.search_filter_list[i].search_filter_key_value.string_type_key_value), DBUS_TYPE_INVALID);
break;
@@ -302,11 +333,21 @@ INTERNAL_FUNC int em_send_notification_to_active_sync_engine(int subType, ASNoti
}
}
dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->search_mail_on_server.handle), DBUS_TYPE_INVALID);
+ if (data->search_mail_on_server.multi_user_name)
+ dbus_message_append_args(signal, DBUS_TYPE_STRING, &(data->search_mail_on_server.multi_user_name), DBUS_TYPE_INVALID);
+ else
+ dbus_message_append_args(signal, DBUS_TYPE_STRING, &(null_string), DBUS_TYPE_INVALID);
+
break;
case ACTIVE_SYNC_NOTI_CLEAR_RESULT_OF_SEARCH_ON_SERVER :
EM_DEBUG_LOG("account_id:[%d]", data->clear_result_of_search_mail_on_server.account_id );
dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->search_mail_on_server.account_id), DBUS_TYPE_INVALID);
+ if (data->search_mail_on_server.multi_user_name)
+ dbus_message_append_args(signal, DBUS_TYPE_STRING, &(data->search_mail_on_server.multi_user_name), DBUS_TYPE_INVALID);
+ else
+ dbus_message_append_args(signal, DBUS_TYPE_STRING, &(null_string), DBUS_TYPE_INVALID);
+
break;
case ACTIVE_SYNC_NOTI_EXPUNGE_MAILS_DELETED_FLAGGED :
@@ -314,18 +355,33 @@ INTERNAL_FUNC int em_send_notification_to_active_sync_engine(int subType, ASNoti
dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->expunge_mails_deleted_flagged.mailbox_id), DBUS_TYPE_INVALID);
dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->expunge_mails_deleted_flagged.on_server), DBUS_TYPE_INVALID);
dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->expunge_mails_deleted_flagged.handle), DBUS_TYPE_INVALID);
+ if (data->expunge_mails_deleted_flagged.multi_user_name)
+ dbus_message_append_args(signal, DBUS_TYPE_STRING, &(data->expunge_mails_deleted_flagged.multi_user_name), DBUS_TYPE_INVALID);
+ else
+ dbus_message_append_args(signal, DBUS_TYPE_STRING, &(null_string), DBUS_TYPE_INVALID);
+
break;
case ACTIVE_SYNC_NOTI_RESOLVE_RECIPIENT :
dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->get_resolve_recipients.account_id), DBUS_TYPE_INVALID);
dbus_message_append_args(signal, DBUS_TYPE_STRING, &(data->get_resolve_recipients.email_address), DBUS_TYPE_INVALID);
dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->get_resolve_recipients.handle), DBUS_TYPE_INVALID);
+ if (data->get_resolve_recipients.multi_user_name)
+ dbus_message_append_args(signal, DBUS_TYPE_STRING, &(data->get_resolve_recipients.multi_user_name), DBUS_TYPE_INVALID);
+ else
+ dbus_message_append_args(signal, DBUS_TYPE_STRING, &(null_string), DBUS_TYPE_INVALID);
+
break;
case ACTIVE_SYNC_NOTI_VALIDATE_CERTIFICATE :
dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->validate_certificate.account_id), DBUS_TYPE_INVALID);
dbus_message_append_args(signal, DBUS_TYPE_STRING, &(data->validate_certificate.email_address), DBUS_TYPE_INVALID);
dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->validate_certificate.handle), DBUS_TYPE_INVALID);
+ if (data->validate_certificate.multi_user_name)
+ dbus_message_append_args(signal, DBUS_TYPE_STRING, &(data->validate_certificate.multi_user_name), DBUS_TYPE_INVALID);
+ else
+ dbus_message_append_args(signal, DBUS_TYPE_STRING, &(null_string), DBUS_TYPE_INVALID);
+
break;
case ACTIVE_SYNC_NOTI_ADD_MAILBOX :
@@ -340,6 +396,11 @@ INTERNAL_FUNC int em_send_notification_to_active_sync_engine(int subType, ASNoti
dbus_message_append_args (signal, DBUS_TYPE_ARRAY, DBUS_TYPE_INT32, &(data->add_mailbox.eas_data),\
data->add_mailbox.eas_data_length,DBUS_TYPE_INVALID);
} */
+ if (data->add_mailbox.multi_user_name)
+ dbus_message_append_args(signal, DBUS_TYPE_STRING, &(data->add_mailbox.multi_user_name), DBUS_TYPE_INVALID);
+ else
+ dbus_message_append_args(signal, DBUS_TYPE_STRING, &(null_string), DBUS_TYPE_INVALID);
+
break;
case ACTIVE_SYNC_NOTI_RENAME_MAILBOX :
@@ -355,12 +416,22 @@ INTERNAL_FUNC int em_send_notification_to_active_sync_engine(int subType, ASNoti
dbus_message_append_args (signal, DBUS_TYPE_ARRAY, DBUS_TYPE_INT32, &(data->rename_mailbox.eas_data),\
data->rename_mailbox.eas_data_length, DBUS_TYPE_INVALID);
}*/
+ if (data->rename_mailbox.multi_user_name)
+ dbus_message_append_args(signal, DBUS_TYPE_STRING, &(data->rename_mailbox.multi_user_name), DBUS_TYPE_INVALID);
+ else
+ dbus_message_append_args(signal, DBUS_TYPE_STRING, &(null_string), DBUS_TYPE_INVALID);
+
break;
case ACTIVE_SYNC_NOTI_DELETE_MAILBOX :
dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->delete_mailbox.account_id), DBUS_TYPE_INVALID);
dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->delete_mailbox.mailbox_id), DBUS_TYPE_INVALID);
dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->delete_mailbox.handle), DBUS_TYPE_INVALID);
+ if (data->delete_mailbox.multi_user_name)
+ dbus_message_append_args(signal, DBUS_TYPE_STRING, &(data->delete_mailbox.multi_user_name), DBUS_TYPE_INVALID);
+ else
+ dbus_message_append_args(signal, DBUS_TYPE_STRING, &(null_string), DBUS_TYPE_INVALID);
+
break;
case ACTIVE_SYNC_NOTI_DELETE_MAILBOX_EX :
@@ -369,12 +440,22 @@ INTERNAL_FUNC int em_send_notification_to_active_sync_engine(int subType, ASNoti
for(i = 0; i <data->delete_mailbox_ex.mailbox_id_count; i++)
dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->delete_mailbox_ex.mailbox_id_array[i]), DBUS_TYPE_INVALID);
dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->delete_mailbox_ex.handle), DBUS_TYPE_INVALID);
+ if (data->delete_mailbox_ex.multi_user_name)
+ dbus_message_append_args(signal, DBUS_TYPE_STRING, &(data->delete_mailbox_ex.multi_user_name), DBUS_TYPE_INVALID);
+ else
+ dbus_message_append_args(signal, DBUS_TYPE_STRING, &(null_string), DBUS_TYPE_INVALID);
+
break;
case ACTIVE_SYNC_NOTI_SEND_MAIL_WITH_DOWNLOADING_OF_ORIGINAL_MAIL:
dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->send_mail_with_downloading_attachment_of_original_mail.handle), DBUS_TYPE_INVALID);
dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->send_mail_with_downloading_attachment_of_original_mail.mail_id), DBUS_TYPE_INVALID);
dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->send_mail_with_downloading_attachment_of_original_mail.account_id), DBUS_TYPE_INVALID);
+ if (data->send_mail_with_downloading_attachment_of_original_mail.multi_user_name)
+ dbus_message_append_args(signal, DBUS_TYPE_STRING, &(data->send_mail_with_downloading_attachment_of_original_mail.multi_user_name), DBUS_TYPE_INVALID);
+ else
+ dbus_message_append_args(signal, DBUS_TYPE_STRING, &(null_string), DBUS_TYPE_INVALID);
+
break;
case ACTIVE_SYNC_NOTI_SCHEDULE_SENDING_MAIL:
@@ -382,12 +463,22 @@ INTERNAL_FUNC int em_send_notification_to_active_sync_engine(int subType, ASNoti
dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->schedule_sending_mail.account_id), DBUS_TYPE_INVALID);
dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->schedule_sending_mail.mail_id), DBUS_TYPE_INVALID);
dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->schedule_sending_mail.scheduled_time), DBUS_TYPE_INVALID);
+ if (data->schedule_sending_mail.multi_user_name)
+ dbus_message_append_args(signal, DBUS_TYPE_STRING, &(data->schedule_sending_mail.multi_user_name), DBUS_TYPE_INVALID);
+ else
+ dbus_message_append_args(signal, DBUS_TYPE_STRING, &(null_string), DBUS_TYPE_INVALID);
+
break;
case ACTIVE_SYNC_NOTI_CANCEL_SENDING_MAIL:
dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->cancel_sending_mail.handle), DBUS_TYPE_INVALID);
dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->cancel_sending_mail.account_id ), DBUS_TYPE_INVALID);
dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->cancel_sending_mail.mail_id), DBUS_TYPE_INVALID);
+ if (data->cancel_sending_mail.multi_user_name)
+ dbus_message_append_args(signal, DBUS_TYPE_STRING, &(data->cancel_sending_mail.multi_user_name), DBUS_TYPE_INVALID);
+ else
+ dbus_message_append_args(signal, DBUS_TYPE_STRING, &(null_string), DBUS_TYPE_INVALID);
+
break;
default:
diff --git a/email-core/email-core-smime.c b/email-core/email-core-smime.c
index 19aa539..8dc102b 100755
--- a/email-core/email-core-smime.c
+++ b/email-core/email-core-smime.c
@@ -126,7 +126,10 @@ static const EVP_CIPHER *emcore_get_cipher_algorithm(email_cipher_type cipher_ty
return cipher;
}
-static int get_x509_stack_of_recipient_certs(char *recipients, STACK_OF(X509) **output_recipient_certs, int *err_code)
+static int get_x509_stack_of_recipient_certs(char *multi_user_name,
+ char *recipients,
+ STACK_OF(X509) **output_recipient_certs,
+ int *err_code)
{
EM_DEBUG_FUNC_BEGIN("recipients : [%s], STACK_OF(X509) : [%p]", recipients, output_recipient_certs);
@@ -156,7 +159,7 @@ static int get_x509_stack_of_recipient_certs(char *recipients, STACK_OF(X509) **
/* Initialize the variable */
temp_recipient_certs = sk_X509_new_null();
- temp_recipients = EM_SAFE_STRDUP(recipients);
+ temp_recipients = g_strdup(recipients);
for (i = 0, j = EM_SAFE_STRLEN(temp_recipients); i < j; i++)
if (temp_recipients[i] == ';') temp_recipients[i] = ',';
@@ -170,10 +173,11 @@ static int get_x509_stack_of_recipient_certs(char *recipients, STACK_OF(X509) **
goto FINISH_OFF;
}
- EM_DEBUG_LOG_SEC("email_address_mailbox : [%s], email_address_host : [%s]", token_address->mailbox, token_address->host);
+ EM_DEBUG_LOG_SEC("email_address_mailbox : [%s], email_address_host : [%s]", token_address->mailbox,
+ token_address->host);
email_address = g_strdup_printf("<%s@%s>", token_address->mailbox, token_address->host);
- if (!emstorage_get_certificate_by_email_address(email_address, &cert, false, 0, &err)) {
+ if (!emstorage_get_certificate_by_email_address(multi_user_name, email_address, &cert, false, 0, &err)) {
EM_DEBUG_EXCEPTION("emstorage_get_certificate_by_email_address failed : [%d]", err);
goto FINISH_OFF;
}
@@ -183,11 +187,11 @@ static int get_x509_stack_of_recipient_certs(char *recipients, STACK_OF(X509) **
goto FINISH_OFF;
}
-
SNPRINTF(file_name, sizeof(file_name), "%s", cert->filepath);
EM_DEBUG_LOG_SEC("file_name : [%s]", file_name);
- if (cert_svc_load_file_to_context(context, file_name) != CERT_SVC_ERR_NO_ERROR) {
- EM_DEBUG_EXCEPTION("cert_svc_load_file_to_context failed");
+ int cert_err = cert_svc_load_file_to_context(context, file_name);
+ if (cert_err != CERT_SVC_ERR_NO_ERROR) {
+ EM_DEBUG_EXCEPTION("cert_svc_load_file_to_context failed : [%d]", err);
err = EMAIL_ERROR_SYSTEM_FAILURE;
goto FINISH_OFF;
}
@@ -246,13 +250,19 @@ FINISH_OFF:
if (err_code)
*err_code = err;
- EM_DEBUG_FUNC_END();
+ EM_DEBUG_FUNC_END("err : [%d]", err);
return ret;
}
/* Opaque signed and encrypted method */
/*
-static PKCS7 *opaque_signed_and_encrypt(STACK_OF(X509) *recipients_cert, X509 *signer, EVP_PKEY *private_key, BIO *mime_entity, const EVP_CIPHER *cipher, const EVP_MD *md, int flags)
+static PKCS7 *opaque_signed_and_encrypt(STACK_OF(X509) *recipients_cert,
+ X509 *signer,
+ EVP_PKEY *private_key,
+ BIO *mime_entity,
+ const EVP_CIPHER *cipher,
+ const EVP_MD *md,
+ int flags)
{
EM_DEBUG_FUNC_BEGIN();
int i = 0;
@@ -306,7 +316,11 @@ FINISH_OFF:
}
*/
-INTERNAL_FUNC int emcore_smime_set_signed_message(char *certificate, char *mime_entity, email_digest_type digest_type, char **file_path, int *err_code)
+INTERNAL_FUNC int emcore_smime_set_signed_message(char *certificate,
+ char *mime_entity,
+ email_digest_type digest_type,
+ char **file_path,
+ int *err_code)
{
EM_DEBUG_FUNC_BEGIN_SEC("certificate path : [%s], mime_entity : [%s]", certificate, mime_entity);
int err, ret = false;
@@ -345,7 +359,8 @@ INTERNAL_FUNC int emcore_smime_set_signed_message(char *certificate, char *mime_
signed_message = PKCS7_sign(NULL, NULL, other_certs, bio_mime_entity, flags);
if (!signed_message) {
- EM_DEBUG_EXCEPTION("Error creating PKCS#7 structure");
+ unsigned long error = ERR_get_error();
+ EM_DEBUG_EXCEPTION("Error creating PKCS#7 structure : [%ld][%s]", error, ERR_error_string(error, NULL));
err = EMAIL_ERROR_SYSTEM_FAILURE;
goto FINISH_OFF;
}
@@ -354,19 +369,22 @@ INTERNAL_FUNC int emcore_smime_set_signed_message(char *certificate, char *mime_
digest = emcore_get_digest_algorithm(digest_type);
if (!PKCS7_sign_add_signer(signed_message, cert, private_key, digest, flags)) {
- EM_DEBUG_EXCEPTION("PKCS7_sign_add_signer failed");
+ unsigned long error = ERR_get_error();
+ EM_DEBUG_EXCEPTION("PKCS7_sign_add_signer failed : [%ld][%s]", error, ERR_error_string(error, NULL));
err = EMAIL_ERROR_SYSTEM_FAILURE;
goto FINISH_OFF;
}
if (!PKCS7_final(signed_message, bio_mime_entity, flags)) {
- EM_DEBUG_EXCEPTION("PKCS7_final failed");
+ unsigned long error = ERR_get_error();
+ EM_DEBUG_EXCEPTION("PKCS7_final failed : [%ld][%s]", error, ERR_error_string(error, NULL));
err = EMAIL_ERROR_SYSTEM_FAILURE;
goto FINISH_OFF;
}
if (!i2d_PKCS7_bio_stream(smime_attachment, signed_message, bio_mime_entity, flags)) {
- EM_DEBUG_EXCEPTION("i2d_PKCS7_bio_stream failed");
+ unsigned long error = ERR_get_error();
+ EM_DEBUG_EXCEPTION("i2d_PKCS7_bio_stream failed : [%ld][%s]", error, ERR_error_string(error, NULL));
err = EMAIL_ERROR_SYSTEM_FAILURE;
goto FINISH_OFF;
}
@@ -375,7 +393,7 @@ INTERNAL_FUNC int emcore_smime_set_signed_message(char *certificate, char *mime_
FINISH_OFF:
if (file_path && ret)
- *file_path = EM_SAFE_STRDUP(temp_smime_filepath);
+ *file_path = g_strdup(temp_smime_filepath);
X509_free(cert);
sk_X509_pop_free(other_certs, X509_free);
@@ -394,7 +412,12 @@ FINISH_OFF:
return ret;
}
-INTERNAL_FUNC int emcore_smime_set_encrypt_message(char *recipient_list, char *mime_entity, email_cipher_type cipher_type, char **file_path, int *err_code)
+INTERNAL_FUNC int emcore_smime_set_encrypt_message(char *multi_user_name,
+ char *recipient_list,
+ char *mime_entity,
+ email_cipher_type cipher_type,
+ char **file_path,
+ int *err_code)
{
EM_DEBUG_FUNC_BEGIN("certificate path : [%p], mime_entity : [%p]", recipient_list, mime_entity);
char temp_smime_filepath[512];
@@ -422,7 +445,7 @@ INTERNAL_FUNC int emcore_smime_set_encrypt_message(char *recipient_list, char *m
goto FINISH_OFF;
}
- if (!get_x509_stack_of_recipient_certs(recipient_list, &recipient_certs, &err)) {
+ if (!get_x509_stack_of_recipient_certs(multi_user_name, recipient_list, &recipient_certs, &err)) {
EM_DEBUG_EXCEPTION("get_x509_stack_of_recipient_certs failed [%d]", err);
goto FINISH_OFF;
}
@@ -438,13 +461,15 @@ INTERNAL_FUNC int emcore_smime_set_encrypt_message(char *recipient_list, char *m
encrypt_message = PKCS7_encrypt(recipient_certs, bio_mime_entity, cipher, flags);
if (encrypt_message == NULL) {
- EM_DEBUG_EXCEPTION("PKCS7_encrypt failed [%ld]", ERR_get_error());
+ unsigned long error = ERR_get_error();
+ EM_DEBUG_EXCEPTION("PKCS7_encrypt failed [%ld][%s]", error, ERR_error_string(error, NULL));
err = EMAIL_ERROR_SYSTEM_FAILURE;
goto FINISH_OFF;
}
if (!i2d_PKCS7_bio_stream(smime_attachment, encrypt_message, bio_mime_entity, flags)) {
- EM_DEBUG_EXCEPTION("i2d_PKCS7_bio_stream failed");
+ unsigned long error = ERR_get_error();
+ EM_DEBUG_EXCEPTION("i2d_PKCS7_bio_stream failed : [%ld][%s]", error, ERR_error_string(error, NULL));
err = EMAIL_ERROR_SYSTEM_FAILURE;
goto FINISH_OFF;
}
@@ -454,7 +479,7 @@ INTERNAL_FUNC int emcore_smime_set_encrypt_message(char *recipient_list, char *m
FINISH_OFF:
if (file_path && ret)
- *file_path = EM_SAFE_STRDUP(temp_smime_filepath);
+ *file_path = g_strdup(temp_smime_filepath);
PKCS7_free(encrypt_message);
@@ -473,7 +498,14 @@ FINISH_OFF:
return ret;
}
-INTERNAL_FUNC int emcore_smime_set_signed_and_encrypt_message(char *recipient_list, char *certificate, char *mime_entity, email_cipher_type cipher_type, email_digest_type digest_type, char **file_path, int *err_code)
+INTERNAL_FUNC int emcore_smime_set_signed_and_encrypt_message(char *multi_user_name,
+ char *recipient_list,
+ char *certificate,
+ char *mime_entity,
+ email_cipher_type cipher_type,
+ email_digest_type digest_type,
+ char **file_path,
+ int *err_code)
{
EM_DEBUG_FUNC_BEGIN_SEC("certificate path : [%s], mime_entity : [%s]", recipient_list, mime_entity);
char temp_smime_filepath[512];
@@ -523,7 +555,8 @@ INTERNAL_FUNC int emcore_smime_set_signed_and_encrypt_message(char *recipient_li
/* 3. signing */
signed_message = PKCS7_sign(NULL, NULL, other_certs, bio_mime_entity, flags);
if (!signed_message) {
- EM_DEBUG_EXCEPTION("Error creating PKCS#7 structure");
+ unsigned long error = ERR_get_error();
+ EM_DEBUG_EXCEPTION("Error creating PKCS#7 structure : [%ld][%s]", error, ERR_error_string(error, NULL));
err = EMAIL_ERROR_SYSTEM_FAILURE;
goto FINISH_OFF;
}
@@ -533,7 +566,8 @@ INTERNAL_FUNC int emcore_smime_set_signed_and_encrypt_message(char *recipient_li
/* 5. Apply a digest algorithm */
if (!PKCS7_sign_add_signer(signed_message, cert, private_key, digest, flags)) {
- EM_DEBUG_EXCEPTION("PKCS7_sign_add_signer failed");
+ unsigned long error = ERR_get_error();
+ EM_DEBUG_EXCEPTION("PKCS7_sign_add_signer failed : [%ld][%s]", error, ERR_error_string(error, NULL));
err = EMAIL_ERROR_SYSTEM_FAILURE;
goto FINISH_OFF;
}
@@ -549,8 +583,10 @@ INTERNAL_FUNC int emcore_smime_set_signed_and_encrypt_message(char *recipient_li
goto FINISH_OFF;
}
- if (!SMIME_write_PKCS7(bio_signed_message, signed_message, bio_mime_entity, flags | SMIME_OLDMIME | SMIME_CRLFEOL)) {
- EM_DEBUG_EXCEPTION("SMIME_write_PKCS7 error");
+ if (!SMIME_write_PKCS7(bio_signed_message, signed_message, bio_mime_entity,
+ flags | SMIME_OLDMIME | SMIME_CRLFEOL)) {
+ unsigned long error = ERR_get_error();
+ EM_DEBUG_EXCEPTION("SMIME_write_PKCS7 error : [%ld][%s]", error, ERR_error_string(error, NULL));
err = EMAIL_ERROR_SYSTEM_FAILURE;
goto FINISH_OFF;
}
@@ -559,7 +595,7 @@ INTERNAL_FUNC int emcore_smime_set_signed_and_encrypt_message(char *recipient_li
/* Encrypting the mail */
/* 1. Get the recipient certs */
- if (!get_x509_stack_of_recipient_certs(recipient_list, &recipient_certs, &err)) {
+ if (!get_x509_stack_of_recipient_certs(multi_user_name, recipient_list, &recipient_certs, &err)) {
EM_DEBUG_EXCEPTION("get_x509_stack_of_recipient_certs failed [%d]", err);
goto FINISH_OFF;
}
@@ -579,14 +615,16 @@ INTERNAL_FUNC int emcore_smime_set_signed_and_encrypt_message(char *recipient_li
encrypt_message = PKCS7_encrypt(recipient_certs, bio_signed_message, cipher, flags);
if (encrypt_message == NULL) {
- EM_DEBUG_EXCEPTION("PKCS7_encrypt failed [%ld]", ERR_get_error());
+ unsigned long error = ERR_get_error();
+ EM_DEBUG_EXCEPTION("PKCS7_encrypt failed [%ld][%s]", error, ERR_error_string(error, NULL));
err = EMAIL_ERROR_SYSTEM_FAILURE;
goto FINISH_OFF;
}
/* 4. Write the encrypt message in file */
if (!i2d_PKCS7_bio_stream(smime_attachment, encrypt_message, bio_mime_entity, flags)) {
- EM_DEBUG_EXCEPTION("i2d_PKCS7_bio_stream failed");
+ unsigned long error = ERR_get_error();
+ EM_DEBUG_EXCEPTION("i2d_PKCS7_bio_stream failed : [%ld][%s]", error, ERR_error_string(error, NULL));
err = EMAIL_ERROR_SYSTEM_FAILURE;
goto FINISH_OFF;
}
@@ -596,7 +634,7 @@ INTERNAL_FUNC int emcore_smime_set_signed_and_encrypt_message(char *recipient_li
FINISH_OFF:
if (file_path && ret)
- *file_path = EM_SAFE_STRDUP(temp_smime_filepath);
+ *file_path = g_strdup(temp_smime_filepath);
emstorage_delete_file(temp_mime_entity_path, NULL);
@@ -620,7 +658,10 @@ FINISH_OFF:
return ret;
}
-INTERNAL_FUNC int emcore_smime_get_decrypt_message(char *encrypt_message, char *certificate, char **decrypt_message, int *err_code)
+INTERNAL_FUNC int emcore_smime_get_decrypt_message(char *encrypt_message,
+ char *certificate,
+ char **decrypt_message,
+ int *err_code)
{
EM_DEBUG_FUNC_BEGIN_SEC("encrypt_file : [%s], certificate : [%s]", encrypt_message, certificate);
int ret = false;
@@ -666,7 +707,8 @@ INTERNAL_FUNC int emcore_smime_get_decrypt_message(char *encrypt_message, char *
}
if (!PKCS7_decrypt(p7_encrypt_message, private_key, cert, out_buf, 0)) {
- EM_DEBUG_EXCEPTION("Decrpyt failed");
+ unsigned long error = ERR_get_error();
+ EM_DEBUG_EXCEPTION("Decrpyt failed : [%ld][%s]", error, ERR_error_string(error, NULL));
err = EMAIL_ERROR_DECRYPT_FAILED;
goto FINISH_OFF;
}
@@ -676,7 +718,7 @@ INTERNAL_FUNC int emcore_smime_get_decrypt_message(char *encrypt_message, char *
FINISH_OFF:
if (decrypt_message && ret)
- *decrypt_message = EM_SAFE_STRDUP(temp_decrypt_filepath);
+ *decrypt_message = g_strdup(temp_decrypt_filepath);
X509_free(cert);
EVP_PKEY_free(private_key);
@@ -771,14 +813,22 @@ FINISH_OFF:
}
*/
-INTERNAL_FUNC int emcore_convert_mail_data_to_smime_data(emstorage_account_tbl_t *account_tbl_item, email_mail_data_t *input_mail_data, email_attachment_data_t *input_attachment_data_list, int input_attachment_count, email_mail_data_t **output_mail_data, email_attachment_data_t **output_attachment_data_list, int *output_attachment_count)
+INTERNAL_FUNC int emcore_convert_mail_data_to_smime_data(char *multi_user_name,
+ emstorage_account_tbl_t *account_tbl_item,
+ email_mail_data_t *input_mail_data,
+ email_attachment_data_t *input_attachment_data_list,
+ int input_attachment_count,
+ email_mail_data_t **output_mail_data,
+ email_attachment_data_t **output_attachment_data_list,
+ int *output_attachment_count)
{
- EM_DEBUG_FUNC_BEGIN("input_mail_data[%p], input_attachment_data_list [%p], input_attachment_count [%d], output_mail_data [%p], output_attachment_data_list [%p]", input_mail_data, input_attachment_data_list, input_attachment_count, output_mail_data, output_attachment_data_list);
+ EM_DEBUG_FUNC_BEGIN("input_mail_data[%p], input_attachment_data_list [%p], input_attachment_count [%d], output_mail_data [%p], output_attachment_data_list [%p]",
+ input_mail_data, input_attachment_data_list, input_attachment_count,
+ output_mail_data, output_attachment_data_list);
int i = 0;
int err = EMAIL_ERROR_NONE;
int smime_type = EMAIL_SMIME_NONE;
- int address_length = 0;
int attachment_count = input_attachment_count;
int file_size = 0;
char *name = NULL;
@@ -802,7 +852,11 @@ INTERNAL_FUNC int emcore_convert_mail_data_to_smime_data(emstorage_account_tbl_t
/* Signed and Encrypt the message */
switch (smime_type) {
case EMAIL_SMIME_SIGNED: /* Clear signed message */
- if (!emcore_smime_set_signed_message(account_tbl_item->certificate_path, input_mail_data->file_path_mime_entity, account_tbl_item->digest_type, &smime_file_path, &err)) {
+ if (!emcore_smime_set_signed_message(account_tbl_item->certificate_path,
+ input_mail_data->file_path_mime_entity,
+ account_tbl_item->digest_type,
+ &smime_file_path,
+ &err)) {
EM_DEBUG_EXCEPTION("em_core_smime_set_clear_signed_message is failed : [%d]", err);
goto FINISH_OFF;
}
@@ -810,21 +864,26 @@ INTERNAL_FUNC int emcore_convert_mail_data_to_smime_data(emstorage_account_tbl_t
EM_DEBUG_LOG_SEC("smime_file_path : %s", smime_file_path);
name = strrchr(smime_file_path, '/');
- new_attachment_data.attachment_name = EM_SAFE_STRDUP(name + 1);
- new_attachment_data.attachment_path = EM_SAFE_STRDUP(smime_file_path);
+ new_attachment_data.attachment_name = g_strdup(name + 1);
+ new_attachment_data.attachment_path = g_strdup(smime_file_path);
new_attachment_data.attachment_mime_type = strdup("pkcs7-signature");
attachment_count += 1;
break;
- case EMAIL_SMIME_ENCRYPTED: /* Encryption message */
- address_length = EM_SAFE_STRLEN(input_mail_data->full_address_from) + EM_SAFE_STRLEN(input_mail_data->full_address_to) + EM_SAFE_STRLEN(input_mail_data->full_address_cc) + EM_SAFE_STRLEN(input_mail_data->full_address_bcc);
-
- other_certificate_list = em_malloc(address_length + 4);
-
- SNPRINTF(other_certificate_list, address_length + 2, "%s;%s;%s;%s", input_mail_data->full_address_from, input_mail_data->full_address_to, input_mail_data->full_address_cc, input_mail_data->full_address_bcc);
- if (!emcore_smime_set_encrypt_message(other_certificate_list, input_mail_data->file_path_mime_entity, account_tbl_item->cipher_type, &smime_file_path, &err)) {
+ case EMAIL_SMIME_ENCRYPTED: /* Encryption message */
+ other_certificate_list = g_strconcat(input_mail_data->full_address_from, ";",
+ input_mail_data->full_address_to, ";",
+ input_mail_data->full_address_cc, ";",
+ input_mail_data->full_address_bcc, NULL);
+
+ if (!emcore_smime_set_encrypt_message(multi_user_name,
+ other_certificate_list,
+ input_mail_data->file_path_mime_entity,
+ account_tbl_item->cipher_type,
+ &smime_file_path,
+ &err)) {
EM_DEBUG_EXCEPTION("emcore_smime_set_encrypt_message is failed : [%d]", err);
goto FINISH_OFF;
}
@@ -832,21 +891,28 @@ INTERNAL_FUNC int emcore_convert_mail_data_to_smime_data(emstorage_account_tbl_t
EM_DEBUG_LOG_SEC("smime_file_path : %s", smime_file_path);
name = strrchr(smime_file_path, '/');
- new_attachment_data.attachment_name = EM_SAFE_STRDUP(name + 1);
- new_attachment_data.attachment_path = EM_SAFE_STRDUP(smime_file_path);
+ new_attachment_data.attachment_name = g_strdup(name + 1);
+ new_attachment_data.attachment_path = g_strdup(smime_file_path);
new_attachment_data.attachment_mime_type = strdup("pkcs7-mime");
attachment_count = 1;
break;
- case EMAIL_SMIME_SIGNED_AND_ENCRYPTED: /* Signed and Encryption message */
- address_length = EM_SAFE_STRLEN(input_mail_data->full_address_from) + EM_SAFE_STRLEN(input_mail_data->full_address_to) + EM_SAFE_STRLEN(input_mail_data->full_address_cc) + EM_SAFE_STRLEN(input_mail_data->full_address_bcc);
-
- other_certificate_list = em_malloc(address_length + 4);
-
- SNPRINTF(other_certificate_list, address_length + 2, "%s;%s;%s;%s", input_mail_data->full_address_from, input_mail_data->full_address_to, input_mail_data->full_address_cc, input_mail_data->full_address_bcc);
- if (!emcore_smime_set_signed_and_encrypt_message(other_certificate_list, account_tbl_item->certificate_path, input_mail_data->file_path_mime_entity, account_tbl_item->cipher_type, account_tbl_item->digest_type, &smime_file_path, &err)) {
+ case EMAIL_SMIME_SIGNED_AND_ENCRYPTED: /* Signed and Encryption message */
+ other_certificate_list = g_strconcat(input_mail_data->full_address_from, ";",
+ input_mail_data->full_address_to, ";",
+ input_mail_data->full_address_cc, ";",
+ input_mail_data->full_address_bcc, NULL);
+
+ if (!emcore_smime_set_signed_and_encrypt_message(multi_user_name,
+ other_certificate_list,
+ account_tbl_item->certificate_path,
+ input_mail_data->file_path_mime_entity,
+ account_tbl_item->cipher_type,
+ account_tbl_item->digest_type,
+ &smime_file_path,
+ &err)) {
EM_DEBUG_EXCEPTION("em_core_smime_set_signed_and_encrypt_message is failed : [%d]", err);
goto FINISH_OFF;
}
@@ -854,79 +920,98 @@ INTERNAL_FUNC int emcore_convert_mail_data_to_smime_data(emstorage_account_tbl_t
EM_DEBUG_LOG_SEC("smime_file_path : %s", smime_file_path);
name = strrchr(smime_file_path, '/');
- new_attachment_data.attachment_name = EM_SAFE_STRDUP(name + 1);
- new_attachment_data.attachment_path = EM_SAFE_STRDUP(smime_file_path);
+ new_attachment_data.attachment_name = g_strdup(name + 1);
+ new_attachment_data.attachment_path = g_strdup(smime_file_path);
new_attachment_data.attachment_mime_type = strdup("pkcs7-mime");
attachment_count = 1;
break;
+
case EMAIL_PGP_SIGNED:
- if ((err = emcore_pgp_set_signed_message(NULL, input_mail_data->pgp_password, input_mail_data->file_path_mime_entity, account_tbl_item->user_email_address, account_tbl_item->digest_type, &smime_file_path)) != EMAIL_ERROR_NONE) {
- EM_DEBUG_EXCEPTION("em_core_smime_set_clear_signed_message is failed : [%d]", err);
+ if ((err = emcore_pgp_set_signed_message(NULL,
+ input_mail_data->pgp_password,
+ input_mail_data->file_path_mime_entity,
+ input_mail_data->key_id,
+ account_tbl_item->digest_type,
+ &smime_file_path)) != EMAIL_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("emcore_pgp_set_signed_message is failed : [%d]", err);
goto FINISH_OFF;
}
EM_DEBUG_LOG_SEC("smime_file_path : %s", smime_file_path);
name = strrchr(smime_file_path, '/');
- new_attachment_data.attachment_name = EM_SAFE_STRDUP(name + 1);
- new_attachment_data.attachment_path = EM_SAFE_STRDUP(smime_file_path);
+ new_attachment_data.attachment_name = g_strdup(name + 1);
+ new_attachment_data.attachment_path = g_strdup(smime_file_path);
new_attachment_data.attachment_mime_type = strdup("pgp-signature");
attachment_count += 1;
break;
- case EMAIL_PGP_ENCRYPTED:
- address_length = EM_SAFE_STRLEN(input_mail_data->full_address_from) + EM_SAFE_STRLEN(input_mail_data->full_address_to) + EM_SAFE_STRLEN(input_mail_data->full_address_cc) + EM_SAFE_STRLEN(input_mail_data->full_address_bcc);
-
- other_certificate_list = em_malloc(address_length + 4);
-
- SNPRINTF(other_certificate_list, address_length + 2, "%s;%s;%s;%s", input_mail_data->full_address_from, input_mail_data->full_address_to, input_mail_data->full_address_cc, input_mail_data->full_address_bcc);
- if ((err = emcore_pgp_set_encrypted_message(other_certificate_list, NULL, input_mail_data->pgp_password, input_mail_data->file_path_mime_entity, account_tbl_item->user_email_address, input_mail_data->digest_type, &smime_file_path)) != EMAIL_ERROR_NONE) {
+ case EMAIL_PGP_ENCRYPTED:
+/*
+ other_certificate_list = g_strconcat(input_mail_data->full_address_from, ";",
+ input_mail_data->full_address_to, ";",
+ input_mail_data->full_address_cc, ";",
+ input_mail_data->full_address_bcc, NULL);
+*/
+ other_certificate_list = g_strdup(input_mail_data->key_list);
+ if ((err = emcore_pgp_set_encrypted_message(other_certificate_list,
+ NULL,
+ input_mail_data->pgp_password,
+ input_mail_data->file_path_mime_entity,
+ account_tbl_item->user_email_address,
+ input_mail_data->digest_type,
+ &smime_file_path)) != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("emcore_pgp_set_encrypted_message failed : [%d]", err);
goto FINISH_OFF;
}
name = strrchr(smime_file_path, '/');
- new_attachment_data.attachment_name = EM_SAFE_STRDUP(name + 1);
- new_attachment_data.attachment_path = EM_SAFE_STRDUP(smime_file_path);
+ new_attachment_data.attachment_name = g_strdup(name + 1);
+ new_attachment_data.attachment_path = g_strdup(smime_file_path);
new_attachment_data.attachment_mime_type = strdup("octet-stream");
attachment_count = 1;
break;
- case EMAIL_PGP_SIGNED_AND_ENCRYPTED:
- address_length = EM_SAFE_STRLEN(input_mail_data->full_address_from) + EM_SAFE_STRLEN(input_mail_data->full_address_to) + EM_SAFE_STRLEN(input_mail_data->full_address_cc) + EM_SAFE_STRLEN(input_mail_data->full_address_bcc);
-
- other_certificate_list = em_malloc(address_length + 4);
- if (other_certificate_list == NULL) {
- EM_DEBUG_EXCEPTION("em_malloc failed");
- err = EMAIL_ERROR_OUT_OF_MEMORY;
- goto FINISH_OFF;
- }
-
- SNPRINTF(other_certificate_list, address_length + 2, "%s;%s;%s;%s", input_mail_data->full_address_from, input_mail_data->full_address_to, input_mail_data->full_address_cc, input_mail_data->full_address_bcc);
- if ((err = emcore_pgp_set_signed_and_encrypted_message(other_certificate_list, NULL, input_mail_data->pgp_password, input_mail_data->file_path_mime_entity, account_tbl_item->user_email_address, input_mail_data->digest_type, &smime_file_path)) != EMAIL_ERROR_NONE) {
- EM_DEBUG_EXCEPTION("emcore_pgp_set_encrypted_message failed : [%d]", err);
+ case EMAIL_PGP_SIGNED_AND_ENCRYPTED:
+/*
+ other_certificate_list = g_strconcat(input_mail_data->full_address_from, ";",
+ input_mail_data->full_address_to, ";",
+ input_mail_data->full_address_cc, ";",
+ input_mail_data->full_address_bcc, NULL);
+*/
+ other_certificate_list = g_strdup(input_mail_data->key_list);
+ if ((err = emcore_pgp_set_signed_and_encrypted_message(other_certificate_list,
+ NULL,
+ input_mail_data->pgp_password,
+ input_mail_data->file_path_mime_entity,
+ input_mail_data->key_id,
+ input_mail_data->digest_type,
+ &smime_file_path)) != EMAIL_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("emcore_pgp_set_signed_and_encrypted_message failed : [%d]", err);
goto FINISH_OFF;
}
name = strrchr(smime_file_path, '/');
- new_attachment_data.attachment_name = EM_SAFE_STRDUP(name + 1);
- new_attachment_data.attachment_path = EM_SAFE_STRDUP(smime_file_path);
+ new_attachment_data.attachment_name = g_strdup(name + 1);
+ new_attachment_data.attachment_path = g_strdup(smime_file_path);
new_attachment_data.attachment_mime_type = strdup("octet-stream");
attachment_count = 1;
break;
+
default:
EM_DEBUG_LOG("MIME none");
break;
+
}
if (!emcore_get_file_size(smime_file_path, &file_size, NULL)) {
@@ -947,9 +1032,9 @@ INTERNAL_FUNC int emcore_convert_mail_data_to_smime_data(emstorage_account_tbl_t
if (smime_type == EMAIL_SMIME_SIGNED) {
for (i = 0; i < input_attachment_count; i++) {
new_attachment_list[i].attachment_id = input_attachment_data_list[i].attachment_id;
- new_attachment_list[i].attachment_name = EM_SAFE_STRDUP(input_attachment_data_list[i].attachment_name);
- new_attachment_list[i].attachment_path = EM_SAFE_STRDUP(input_attachment_data_list[i].attachment_path);
- new_attachment_list[i].content_id = EM_SAFE_STRDUP(input_attachment_data_list[i].content_id);
+ new_attachment_list[i].attachment_name = g_strdup(input_attachment_data_list[i].attachment_name);
+ new_attachment_list[i].attachment_path = g_strdup(input_attachment_data_list[i].attachment_path);
+ new_attachment_list[i].content_id = g_strdup(input_attachment_data_list[i].content_id);
new_attachment_list[i].attachment_size = input_attachment_data_list[i].attachment_size;
new_attachment_list[i].mail_id = input_attachment_data_list[i].mail_id;
new_attachment_list[i].account_id = input_attachment_data_list[i].account_id;
@@ -957,14 +1042,14 @@ INTERNAL_FUNC int emcore_convert_mail_data_to_smime_data(emstorage_account_tbl_t
new_attachment_list[i].save_status = input_attachment_data_list[i].save_status;
new_attachment_list[i].drm_status = input_attachment_data_list[i].drm_status;
new_attachment_list[i].inline_content_status = input_attachment_data_list[i].inline_content_status;
- new_attachment_list[i].attachment_mime_type = EM_SAFE_STRDUP(input_attachment_data_list[i].attachment_mime_type);
+ new_attachment_list[i].attachment_mime_type = g_strdup(input_attachment_data_list[i].attachment_mime_type);
}
}
new_attachment_list[attachment_count - 1].attachment_id = new_attachment_data.attachment_id;
- new_attachment_list[attachment_count - 1].attachment_name = EM_SAFE_STRDUP(new_attachment_data.attachment_name);
- new_attachment_list[attachment_count - 1].attachment_path = EM_SAFE_STRDUP(new_attachment_data.attachment_path);
- new_attachment_list[attachment_count - 1].content_id = EM_SAFE_STRDUP(new_attachment_data.content_id);
+ new_attachment_list[attachment_count - 1].attachment_name = g_strdup(new_attachment_data.attachment_name);
+ new_attachment_list[attachment_count - 1].attachment_path = g_strdup(new_attachment_data.attachment_path);
+ new_attachment_list[attachment_count - 1].content_id = g_strdup(new_attachment_data.content_id);
new_attachment_list[attachment_count - 1].attachment_size = new_attachment_data.attachment_size;
new_attachment_list[attachment_count - 1].mail_id = new_attachment_data.mail_id;
new_attachment_list[attachment_count - 1].account_id = new_attachment_data.account_id;
@@ -972,7 +1057,7 @@ INTERNAL_FUNC int emcore_convert_mail_data_to_smime_data(emstorage_account_tbl_t
new_attachment_list[attachment_count - 1].save_status = new_attachment_data.save_status;
new_attachment_list[attachment_count - 1].drm_status = new_attachment_data.drm_status;
new_attachment_list[attachment_count - 1].inline_content_status = new_attachment_data.inline_content_status;
- new_attachment_list[attachment_count - 1].attachment_mime_type = EM_SAFE_STRDUP(new_attachment_data.attachment_mime_type);
+ new_attachment_list[attachment_count - 1].attachment_mime_type = g_strdup(new_attachment_data.attachment_mime_type);
input_mail_data->smime_type = smime_type;
input_mail_data->digest_type = account_tbl_item->digest_type;
diff --git a/email-core/email-core-smtp.c b/email-core/email-core-smtp.c
index b1d2e13..fbf8000 100755
--- a/email-core/email-core-smtp.c
+++ b/email-core/email-core-smtp.c
@@ -54,16 +54,18 @@
#include "email-convert.h"
#include "email-debug-log.h"
#include "email-core-gmime.h"
+#include "email-core-container.h"
+#include "email-network.h"
#undef min
#ifdef __FEATURE_SUPPORT_REPORT_MAIL__
-static int emcore_get_report_mail_body(ENVELOPE *envelope, BODY **multipart_body, int *err_code);
+static int emcore_get_report_mail_body(char *multi_user_name, ENVELOPE *envelope, BODY **multipart_body, int *err_code);
#endif
-static int emcore_make_envelope_from_mail(emstorage_mail_tbl_t *input_mail_tbl_data, ENVELOPE **output_envelope);
-static int emcore_send_mail_smtp(SENDSTREAM *stream, ENVELOPE *env, char *data_file, int account_id, int mail_id, int *err_code);
+static int emcore_make_envelope_from_mail(char *multi_user_name, emstorage_mail_tbl_t *input_mail_tbl_data, ENVELOPE **output_envelope);
+static int emcore_send_mail_smtp(char *multi_user_name, SENDSTREAM *stream, ENVELOPE *env, char *data_file, int account_id, int mail_id, int *err_code);
char *emcore_generate_content_id_string(const char *hostname, int *err);
/* Functions from uw-imap-toolkit */
@@ -268,7 +270,6 @@ static int emcore_write_body (BODY *body, BODY *root_body, FILE *fp)
if (body->type == TYPETEXT && body->subtype && toupper(body->subtype[0]) == 'H') {
EM_DEBUG_LOG ("HTML Part");
-
struct stat st_buf;
unsigned int byte_read = 0;
@@ -415,8 +416,6 @@ static int emcore_write_body (BODY *body, BODY *root_body, FILE *fp)
if (body->encoding == ENCQUOTEDPRINTABLE || body->encoding == ENCBASE64)
fprintf(fp, CRLF_STRING);
- fprintf(fp, CRLF_STRING);
-
FINISH_OFF: /* prevent 34226 */
/* cleanup local vars */
@@ -463,26 +462,27 @@ static int emcore_write_rfc822_body(BODY *body, BODY *root_body, FILE *fp, int *
rfc822_write_body_header(&p, &part->body);
- fprintf(fp, "--%s"CRLF_STRING, bndry);
+ fprintf(fp, CRLF_STRING"--%s"CRLF_STRING, bndry);
if (body->subtype && (body->subtype[0] == 'S' || body->subtype[0] == 's')) {
if ((error = emcore_write_body (body, root_body, fp)) != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("emcore_write_body failed : [%d]", error);
return false;
}
- fprintf(fp, "--%s"CRLF_STRING, bndry);
+ fprintf(fp, CRLF_STRING"--%s"CRLF_STRING, bndry);
}
- fprintf(fp, "%s"CRLF_STRING, buf);
-
+ fprintf(fp, "%s", buf);
emcore_write_rfc822_body(&part->body, root_body, fp, err_code);
+
} while ((part = part->next));
- fprintf(fp, "--%s--"CRLF_STRING, bndry);
+ fprintf(fp, CRLF_STRING"--%s--"CRLF_STRING, bndry);
break;
default:
EM_DEBUG_LOG_DEV("body->type is not TYPEMULTIPART");
+ fprintf(fp, CRLF_STRING);
if ((error = emcore_write_body (body, root_body, fp)) != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("emcore_write_body failed : [%d]", error);
return false;
@@ -553,7 +553,6 @@ static int emcore_write_rfc822 (ENVELOPE *env, BODY *body, email_mail_priority_t
rfc822_output_header(&buf, env, body, NIL, NIL); /* Excluding BCC */
EM_DEBUG_LOG("header_buffer [%d]", strlen(header_buffer));
-
{
gchar **tokens = g_strsplit(header_buffer, "CHARSET=X-UNKNOWN", 2);
@@ -634,8 +633,7 @@ static int emcore_write_rfc822 (ENVELOPE *env, BODY *body, email_mail_priority_t
}
}
- SNPRINTF(header_buffer + EM_SAFE_STRLEN(header_buffer), header_buffer_lenth-(EM_SAFE_STRLEN(header_buffer)), CRLF_STRING);
-
+// SNPRINTF(header_buffer + EM_SAFE_STRLEN(header_buffer), header_buffer_lenth-(EM_SAFE_STRLEN(header_buffer)), CRLF_STRING);
if (data && EM_SAFE_STRLEN(*data) > 0) {
fname = EM_SAFE_STRDUP(*data);
file_exist = 1;
@@ -685,7 +683,7 @@ FINISH_OFF:
return error;
}
-INTERNAL_FUNC int emcore_add_mail(email_mail_data_t *input_mail_data, email_attachment_data_t *input_attachment_data_list, int input_attachment_count, email_meeting_request_t *input_meeting_request, int input_from_eas, int move_flag)
+INTERNAL_FUNC int emcore_add_mail(char *multi_user_name, email_mail_data_t *input_mail_data, email_attachment_data_t *input_attachment_data_list, int input_attachment_count, email_meeting_request_t *input_meeting_request, int input_from_eas, int move_flag)
{
EM_DEBUG_FUNC_BEGIN("input_mail_data[%p], input_attachment_data_list [%p], input_attachment_count [%d], input_meeting_request [%p], input_from_eas[%d]", input_mail_data, input_attachment_data_list, input_attachment_count, input_meeting_request, input_from_eas);
@@ -715,10 +713,11 @@ INTERNAL_FUNC int emcore_add_mail(email_mail_data_t *input_mail_data, email_atta
int mailbox_id_spam = 0, mailbox_id_target = 0;
int mail_smime_flag = 0;
char name_buf[MAX_PATH] = {0x00, };
+ char path_buf[MAX_PATH] = {0, };
char *body_text_file_name = NULL;
char *dl_error = NULL;
void *dl_handle = NULL;
- int (*convert_mail_data_to_smime)(emstorage_account_tbl_t*, email_mail_data_t*, email_attachment_data_t*, int, email_mail_data_t**, email_attachment_data_t**, int*);
+ int (*convert_mail_data_to_smime)(char*, emstorage_account_tbl_t*, email_mail_data_t*, email_attachment_data_t*, int, email_mail_data_t**, email_attachment_data_t**, int*);
int attachment_count = 0;
email_mail_data_t *mail_data = NULL;
@@ -732,6 +731,8 @@ INTERNAL_FUNC int emcore_add_mail(email_mail_data_t *input_mail_data, email_atta
char mailbox_id_param_string[10] = {0,};
char errno_buf[ERRNO_BUF_SIZE] = {0};
int updated_thread_id = 0;
+ char *prefix_path = NULL;
+ char real_file_path[MAX_PATH] = {0};
#ifdef __FEATURE_BODY_SEARCH__
char *stripped_text = NULL;
@@ -749,7 +750,7 @@ INTERNAL_FUNC int emcore_add_mail(email_mail_data_t *input_mail_data, email_atta
goto FINISH_OFF;
}
- if (!emstorage_get_account_by_id(input_mail_data->account_id, EMAIL_ACC_GET_OPT_DEFAULT | EMAIL_ACC_GET_OPT_OPTIONS, &account_tbl_item, true, &err)) {
+ if (!emstorage_get_account_by_id(multi_user_name, input_mail_data->account_id, EMAIL_ACC_GET_OPT_DEFAULT | EMAIL_ACC_GET_OPT_OPTIONS, &account_tbl_item, true, &err)) {
EM_DEBUG_EXCEPTION("emstorage_get_account_by_id failed. account_id[%d] err[%d]", input_mail_data->account_id, err);
err = EMAIL_ERROR_INVALID_ACCOUNT;
goto FINISH_OFF;
@@ -771,8 +772,8 @@ INTERNAL_FUNC int emcore_add_mail(email_mail_data_t *input_mail_data, email_atta
goto FINISH_OFF;
}
- if ((err = convert_mail_data_to_smime(account_tbl_item, input_mail_data, input_attachment_data_list, input_attachment_count, &mail_data, &attachment_data_list, &attachment_count)) != EMAIL_ERROR_NONE) {
- EM_DEBUG_EXCEPTION("S/MIME failed : [%d]", err);
+ if ((err = convert_mail_data_to_smime(multi_user_name, account_tbl_item, input_mail_data, input_attachment_data_list, input_attachment_count, &mail_data, &attachment_data_list, &attachment_count)) != EMAIL_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("S/MIME failed");
goto FINISH_OFF;
}
@@ -785,11 +786,24 @@ INTERNAL_FUNC int emcore_add_mail(email_mail_data_t *input_mail_data, email_atta
mailbox_id_target = mail_data->mailbox_id;
+ if (EM_SAFE_STRLEN(multi_user_name) > 0) {
+ err = emcore_get_container_path(multi_user_name, &prefix_path);
+ if (err != EMAIL_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("emcore_get_container_path failed : [%d]", err);
+ goto FINISH_OFF;
+ }
+ } else {
+ prefix_path = strdup("");
+ }
+
if (input_from_eas == 0 &&
!(input_mail_data->message_class & EMAIL_MESSAGE_CLASS_SMART_REPLY) &&
!(input_mail_data->message_class & EMAIL_MESSAGE_CLASS_SMART_FORWARD) ) {
if (mail_data->file_path_plain) {
- if (stat(mail_data->file_path_plain, &st_buf) < 0) {
+ memset(real_file_path, 0x00, sizeof(real_file_path));
+ SNPRINTF(real_file_path, sizeof(real_file_path), "%s%s", prefix_path, mail_data->file_path_plain);
+
+ if (stat(real_file_path, &st_buf) < 0) {
EM_DEBUG_EXCEPTION_SEC("mail_data->file_path_plain, stat(\"%s\") failed...", mail_data->file_path_plain);
EM_DEBUG_EXCEPTION("%s", EM_STRERROR(errno_buf));
err = EMAIL_ERROR_INVALID_MAIL;
@@ -798,7 +812,10 @@ INTERNAL_FUNC int emcore_add_mail(email_mail_data_t *input_mail_data, email_atta
}
if (mail_data->file_path_html) {
- if (stat(mail_data->file_path_html, &st_buf) < 0) {
+ memset(real_file_path, 0x00, sizeof(real_file_path));
+ SNPRINTF(real_file_path, sizeof(real_file_path), "%s%s", prefix_path, mail_data->file_path_html);
+
+ if (stat(real_file_path, &st_buf) < 0) {
EM_DEBUG_EXCEPTION_SEC("mail_data->file_path_html, stat(\"%s\") failed...", mail_data->file_path_html);
EM_DEBUG_EXCEPTION("%s", EM_STRERROR(errno_buf) );
err = EMAIL_ERROR_INVALID_MAIL;
@@ -809,7 +826,10 @@ INTERNAL_FUNC int emcore_add_mail(email_mail_data_t *input_mail_data, email_atta
if (attachment_count && attachment_data_list) {
for (i = 0; i < attachment_count; i++) {
if (attachment_data_list[i].save_status) {
- if (!attachment_data_list[i].attachment_path || stat(attachment_data_list[i].attachment_path, &st_buf) < 0) {
+ memset(real_file_path, 0x00, sizeof(real_file_path));
+ SNPRINTF(real_file_path, sizeof(real_file_path), "%s%s", prefix_path, attachment_data_list[i].attachment_path);
+
+ if (!attachment_data_list[i].attachment_path || stat(real_file_path, &st_buf) < 0) {
EM_DEBUG_EXCEPTION("stat(\"%s\") failed...", attachment_data_list[i].attachment_path);
err = EMAIL_ERROR_INVALID_ATTACHMENT;
goto FINISH_OFF;
@@ -836,7 +856,7 @@ INTERNAL_FUNC int emcore_add_mail(email_mail_data_t *input_mail_data, email_atta
}
/* Create report mail body */
/*
- if (!emcore_make_rfc822_file_from_mail(mail_src, NULL, NULL, NULL, &err)) {
+ if (!emcore_make_rfc822_file_from_mail(multi_user_name, mail_src, NULL, NULL, NULL, &err)) {
EM_DEBUG_EXCEPTION("emcore_make_rfc822_file_from_mail failed [%d]", err);
goto FINISH_OFF;
}
@@ -847,47 +867,47 @@ INTERNAL_FUNC int emcore_add_mail(email_mail_data_t *input_mail_data, email_atta
email_option_t *opt = &account_tbl_item->options;
EM_DEBUG_LOG_SEC("block_address [%d], block_subject [%d]", opt->block_address, opt->block_subject);
- /* For eas moving from spambox to other mailbox */
- if (mail_data->save_status != EMAIL_MAIL_STATUS_SAVED) {
- if (opt->block_address || opt->block_subject) {
- int is_completed = false;
- int type = 0;
-
- if (!opt->block_address)
- type = EMAIL_FILTER_SUBJECT;
- else if (!opt->block_subject)
- type = EMAIL_FILTER_FROM;
-
- if (!emstorage_get_rule(ALL_ACCOUNT, type, 0, &rule_len, &is_completed, &rule, true, &err) || !rule)
- EM_DEBUG_LOG("No proper rules. emstorage_get_rule returns [%d]", err);
-
- if (rule && !emcore_check_rule(mail_data->full_address_from, mail_data->subject, rule, rule_len, &priority_sender, &blocked, &err)) {
- EM_DEBUG_EXCEPTION("emcore_check_rule failed [%d]", err);
- }
-
- if (priority_sender)
- mail_data->tag_id = PRIORITY_SENDER_TAG_ID;
-
- if (blocked && (mail_data->mailbox_type == EMAIL_MAILBOX_TYPE_INBOX)) {
- EM_DEBUG_LOG("mail[%d] added to spambox", mail_data->mail_id);
- if (!emstorage_get_mailbox_id_by_mailbox_type(mail_data->account_id, EMAIL_MAILBOX_TYPE_SPAMBOX, &mailbox_id_spam, false, &err)) {
- EM_DEBUG_EXCEPTION("emstorage_get_mailbox_name_by_mailbox_type failed [%d]", err);
- mailbox_id_spam = 0;
- }
-
- if (mailbox_id_spam)
- mailbox_id_target = mailbox_id_spam;
- }
- }
+ /* For eas moving from spambox to other mailbox */
+ if (mail_data->save_status != EMAIL_MAIL_STATUS_SAVED) {
+ if (opt->block_address || opt->block_subject) {
+ int is_completed = false;
+ int type = 0;
+
+ if (!opt->block_address)
+ type = EMAIL_FILTER_SUBJECT;
+ else if (!opt->block_subject)
+ type = EMAIL_FILTER_FROM;
+
+ if (!emstorage_get_rule(multi_user_name, ALL_ACCOUNT, type, 0, &rule_len, &is_completed, &rule, true, &err) || !rule)
+ EM_DEBUG_LOG("No proper rules. emstorage_get_rule returns [%d]", err);
+
+ if (rule && !emcore_check_rule(mail_data->full_address_from, mail_data->subject, rule, rule_len, &priority_sender, &blocked, &err)) {
+ EM_DEBUG_EXCEPTION("emcore_check_rule failed [%d]", err);
}
+
+ if (priority_sender)
+ mail_data->tag_id = PRIORITY_SENDER_TAG_ID;
+
+ if (blocked && (mail_data->mailbox_type == EMAIL_MAILBOX_TYPE_INBOX)) {
+ EM_DEBUG_LOG("mail[%d] added to spambox", mail_data->mail_id);
+ if (!emstorage_get_mailbox_id_by_mailbox_type(multi_user_name, mail_data->account_id, EMAIL_MAILBOX_TYPE_SPAMBOX, &mailbox_id_spam, false, &err)) {
+ EM_DEBUG_EXCEPTION("emstorage_get_mailbox_name_by_mailbox_type failed [%d]", err);
+ mailbox_id_spam = 0;
+ }
+
+ if (mailbox_id_spam)
+ mailbox_id_target = mailbox_id_spam;
+ }
+ }
+ }
}
- if ((err = emstorage_get_mailbox_by_id(mailbox_id_target, (emstorage_mailbox_tbl_t**)&mailbox_tbl)) != EMAIL_ERROR_NONE) {
+ if ((err = emstorage_get_mailbox_by_id(multi_user_name, mailbox_id_target, (emstorage_mailbox_tbl_t**)&mailbox_tbl)) != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("emstorage_get_mailbox_by_id failed [%d]", err);
goto FINISH_OFF;
}
- if (!emstorage_increase_mail_id(&mail_data->mail_id, true, &err)) {
+ if (!emstorage_increase_mail_id(multi_user_name, &mail_data->mail_id, true, &err)) {
EM_DEBUG_EXCEPTION("emstorage_increase_mail_id failed [%d]", err);
goto FINISH_OFF;
}
@@ -895,21 +915,26 @@ INTERNAL_FUNC int emcore_add_mail(email_mail_data_t *input_mail_data, email_atta
EM_DEBUG_LOG("mail_data->mail_size [%d]", mail_data->mail_size);
if(mail_data->mail_size == 0)
- emcore_calc_mail_size(mail_data, attachment_data_list, attachment_count, &(mail_data->mail_size)); /* Getting file size before file moved. */
+ emcore_calc_mail_size(multi_user_name, mail_data, attachment_data_list, attachment_count, &(mail_data->mail_size)); /* Getting file size before file moved. */
EM_DEBUG_LOG("input_from_eas [%d] mail_data->body_download_status [%d]", input_from_eas, mail_data->body_download_status);
if (input_from_eas == 0|| mail_data->body_download_status) {
- if (!emstorage_create_dir(mail_data->account_id, mail_data->mail_id, 0, &err)) {
+ if (!emstorage_create_dir(multi_user_name, mail_data->account_id, mail_data->mail_id, 0, &err)) {
EM_DEBUG_EXCEPTION("emstorage_create_dir failed [%d]", err);
goto FINISH_OFF;
}
if (mail_data->file_path_plain) {
+ memset(name_buf, 0x00, sizeof(name_buf));
+ memset(path_buf, 0x00, sizeof(path_buf));
+ memset(real_file_path, 0x00, sizeof(real_file_path));
+ SNPRINTF(real_file_path, sizeof(real_file_path), "%s%s", prefix_path, mail_data->file_path_plain);
+
EM_DEBUG_LOG_SEC("mail_data->file_path_plain [%s]", mail_data->file_path_plain);
/* EM_SAFE_STRNCPY(body_text_file_name, "UTF-8", MAX_PATH); */
- if ( (err = em_get_file_name_from_file_path(mail_data->file_path_plain, &body_text_file_name)) != EMAIL_ERROR_NONE) {
+ if ( (err = em_get_file_name_from_file_path(real_file_path, &body_text_file_name)) != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("em_get_file_name_from_file_path failed [%d]", err);
err = EMAIL_ERROR_INVALID_FILE_PATH;
goto FINISH_OFF;
@@ -922,12 +947,14 @@ INTERNAL_FUNC int emcore_add_mail(email_mail_data_t *input_mail_data, email_atta
EM_SAFE_STRNCPY(body_text_file_name, "UTF-8", MAX_PATH);
*/
- if (!emstorage_get_save_name(mail_data->account_id, mail_data->mail_id, 0, body_text_file_name, name_buf, sizeof(name_buf), &err)) {
+ if (!emstorage_get_save_name(multi_user_name, mail_data->account_id, mail_data->mail_id,
+ 0, body_text_file_name, name_buf, path_buf,
+ sizeof(path_buf), &err)) {
EM_DEBUG_EXCEPTION("emstorage_get_save_name failed [%d]", err);
goto FINISH_OFF;
}
- if (!emstorage_move_file(mail_data->file_path_plain, name_buf, input_from_eas, &err)) {
+ if (!emstorage_move_file(real_file_path, name_buf, input_from_eas, &err)) {
EM_DEBUG_EXCEPTION("emstorage_move_file failed [%d]", err);
goto FINISH_OFF;
}
@@ -935,16 +962,21 @@ INTERNAL_FUNC int emcore_add_mail(email_mail_data_t *input_mail_data, email_atta
mail_data->body_download_status = EMAIL_BODY_DOWNLOAD_STATUS_FULLY_DOWNLOADED;
EM_SAFE_FREE(mail_data->file_path_plain);
- mail_data->file_path_plain = EM_SAFE_STRDUP(name_buf);
+ mail_data->file_path_plain = EM_SAFE_STRDUP(path_buf);
}
if (mail_data->file_path_html) {
+ memset(name_buf, 0x00, sizeof(name_buf));
+ memset(path_buf, 0x00, sizeof(path_buf));
+ memset(real_file_path, 0x00, sizeof(real_file_path));
+ SNPRINTF(real_file_path, sizeof(real_file_path), "%s%s", prefix_path, mail_data->file_path_html);
+
EM_DEBUG_LOG_SEC("mail_data->file_path_html [%s]", mail_data->file_path_html);
/* EM_SAFE_STRNCPY(body_text_file_name, "UTF-8.htm", MAX_PATH); */
EM_SAFE_FREE(body_text_file_name);
- if ( (err = em_get_file_name_from_file_path(mail_data->file_path_html, &body_text_file_name)) != EMAIL_ERROR_NONE) {
+ if ( (err = em_get_file_name_from_file_path(real_file_path, &body_text_file_name)) != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("em_get_file_name_from_file_path failed [%d]", err);
err = EMAIL_ERROR_INVALID_FILE_PATH;
goto FINISH_OFF;
@@ -956,12 +988,14 @@ INTERNAL_FUNC int emcore_add_mail(email_mail_data_t *input_mail_data, email_atta
EM_SAFE_STRNCPY(body_text_file_name, "UTF-8.htm", MAX_PATH);
*/
- if (!emstorage_get_save_name(mail_data->account_id, mail_data->mail_id, 0, body_text_file_name, name_buf, sizeof(name_buf), &err)) {
+ if (!emstorage_get_save_name(multi_user_name, mail_data->account_id, mail_data->mail_id,
+ 0, body_text_file_name, name_buf, path_buf,
+ sizeof(path_buf), &err)) {
EM_DEBUG_EXCEPTION("emstorage_get_save_name failed [%d]", err);
goto FINISH_OFF;
}
- if (!emstorage_move_file(mail_data->file_path_html, name_buf, input_from_eas, &err)) {
+ if (!emstorage_move_file(real_file_path, name_buf, input_from_eas, &err)) {
EM_DEBUG_EXCEPTION("emstorage_move_file failed [%d]", err);
goto FINISH_OFF;
}
@@ -970,25 +1004,32 @@ INTERNAL_FUNC int emcore_add_mail(email_mail_data_t *input_mail_data, email_atta
mail_data->body_download_status = EMAIL_BODY_DOWNLOAD_STATUS_FULLY_DOWNLOADED;
EM_SAFE_FREE(mail_data->file_path_html);
- mail_data->file_path_html = EM_SAFE_STRDUP(name_buf);
+ mail_data->file_path_html = EM_SAFE_STRDUP(path_buf);
}
}
if (mail_data->file_path_mime_entity) {
+ memset(name_buf, 0x00, sizeof(name_buf));
+ memset(path_buf, 0x00, sizeof(path_buf));
+ memset(real_file_path, 0x00, sizeof(real_file_path));
+ SNPRINTF(real_file_path, sizeof(real_file_path), "%s%s", prefix_path, mail_data->file_path_mime_entity);
+
EM_DEBUG_LOG_SEC("mail_data->file_path_mime_entity [%s]", mail_data->file_path_mime_entity);
- if (!emstorage_get_save_name(mail_data->account_id, mail_data->mail_id, 0, "mime_entity", name_buf, sizeof(name_buf), &err)) {
+ if (!emstorage_get_save_name(multi_user_name, mail_data->account_id, mail_data->mail_id,
+ 0, "mime_entity", name_buf, path_buf,
+ sizeof(path_buf), &err)) {
EM_DEBUG_EXCEPTION("emstorage_get_save_name failed [%d]", err);
goto FINISH_OFF;
}
- if (!emstorage_move_file(mail_data->file_path_mime_entity, name_buf, input_from_eas, &err)) {
+ if (!emstorage_move_file(real_file_path, name_buf, input_from_eas, &err)) {
EM_DEBUG_EXCEPTION("emstorage_move_file failed [%d]", err);
goto FINISH_OFF;
}
EM_SAFE_FREE(mail_data->file_path_mime_entity);
- mail_data->file_path_mime_entity = EM_SAFE_STRDUP(name_buf);
+ mail_data->file_path_mime_entity = EM_SAFE_STRDUP(path_buf);
}
if (!mail_data->date_time) {
@@ -1024,7 +1065,11 @@ INTERNAL_FUNC int emcore_add_mail(email_mail_data_t *input_mail_data, email_atta
EM_DEBUG_LOG("preview_text[%p]", mail_data->preview_text);
if (mail_data->preview_text == NULL) {
- if ( (err = emcore_get_preview_text_from_file(mail_data->file_path_plain, mail_data->file_path_html, MAX_PREVIEW_TEXT_LENGTH, &(mail_data->preview_text))) != EMAIL_ERROR_NONE) {
+ if ( (err = emcore_get_preview_text_from_file(multi_user_name,
+ mail_data->file_path_plain,
+ mail_data->file_path_html,
+ MAX_PREVIEW_TEXT_LENGTH,
+ &(mail_data->preview_text))) != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("emcore_get_preview_text_from_file failed[%d]", err);
if (err != EMAIL_ERROR_EMPTY_FILE)
@@ -1040,11 +1085,11 @@ INTERNAL_FUNC int emcore_add_mail(email_mail_data_t *input_mail_data, email_atta
converted_mail_tbl->mailbox_id = mailbox_tbl->mailbox_id;
/* Fill address information */
- emcore_fill_address_information_of_mail_tbl(converted_mail_tbl);
+ emcore_fill_address_information_of_mail_tbl(multi_user_name, converted_mail_tbl);
/* Fill thread id */
if(mail_data->thread_id == 0) {
- if (emstorage_get_thread_id_of_thread_mails(converted_mail_tbl, &thread_id, &latest_mail_id_in_thread, &thread_item_count) != EMAIL_ERROR_NONE)
+ if (emstorage_get_thread_id_of_thread_mails(multi_user_name, converted_mail_tbl, &thread_id, &latest_mail_id_in_thread, &thread_item_count) != EMAIL_ERROR_NONE)
EM_DEBUG_LOG(" emstorage_get_thread_id_of_thread_mails is failed");
if (thread_id == -1) {
@@ -1061,14 +1106,14 @@ INTERNAL_FUNC int emcore_add_mail(email_mail_data_t *input_mail_data, email_atta
}
mail_data->thread_id = converted_mail_tbl->thread_id;
-
- emstorage_begin_transaction(NULL, NULL, NULL);
+ converted_mail_tbl->user_name = EM_SAFE_STRDUP(account_tbl_item->user_name);
+ emstorage_begin_transaction(multi_user_name, NULL, NULL, NULL);
/* insert mail to mail table */
- if (!emstorage_add_mail(converted_mail_tbl, 0, false, &err)) {
+ if (!emstorage_add_mail(multi_user_name, converted_mail_tbl, 0, false, &err)) {
EM_DEBUG_EXCEPTION("emstorage_add_mail failed [%d]", err);
/* ROLLBACK TRANSACTION; */
- emstorage_rollback_transaction(NULL, NULL, NULL);
+ emstorage_rollback_transaction(multi_user_name, NULL, NULL, NULL);
goto FINISH_OFF;
}
@@ -1076,9 +1121,19 @@ INTERNAL_FUNC int emcore_add_mail(email_mail_data_t *input_mail_data, email_atta
EM_DEBUG_LOG("thread_item_count [%d]", thread_item_count);
if (thread_item_count > 1) {
- if (!emstorage_update_latest_thread_mail(mail_data->account_id, mail_data->mailbox_id, converted_mail_tbl->thread_id, &updated_thread_id, 0, 0, NOTI_THREAD_ID_CHANGED_BY_ADD, false, &err)) {
+ if (!emstorage_update_latest_thread_mail(multi_user_name,
+ mail_data->account_id,
+ mail_data->mailbox_id,
+ mail_data->mailbox_type,
+ converted_mail_tbl->thread_id,
+ &updated_thread_id,
+ 0,
+ 0,
+ NOTI_THREAD_ID_CHANGED_BY_ADD,
+ false,
+ &err)) {
EM_DEBUG_EXCEPTION("emstorage_update_latest_thread_mail failed [%d]", err);
- emstorage_rollback_transaction(NULL, NULL, NULL);
+ emstorage_rollback_transaction(multi_user_name, NULL, NULL, NULL);
goto FINISH_OFF;
}
@@ -1089,43 +1144,56 @@ INTERNAL_FUNC int emcore_add_mail(email_mail_data_t *input_mail_data, email_atta
/* Insert attachment information to DB */
for (i = 0; i < attachment_count; i++) {
+ memset(name_buf, 0x00, sizeof(name_buf));
+ memset(path_buf, 0x00, sizeof(path_buf));
+
+ /* set attachment size */
+ memset(real_file_path, 0x00, sizeof(real_file_path));
+ SNPRINTF(real_file_path, sizeof(real_file_path), "%s%s", prefix_path, attachment_data_list[i].attachment_path);
+
if (attachment_data_list[i].attachment_size == 0) {
- /* set attachment size */
- if(attachment_data_list[i].attachment_path && stat(attachment_data_list[i].attachment_path, &st_buf) < 0)
+ if(attachment_data_list[i].attachment_path && stat(real_file_path, &st_buf) < 0)
attachment_data_list[i].attachment_size = st_buf.st_size;
}
if (!attachment_data_list[i].inline_content_status) {
- if (!emstorage_get_new_attachment_no(&attachment_id, &err)) {
+ if (!emstorage_get_new_attachment_no(multi_user_name, &attachment_id, &err)) {
EM_DEBUG_EXCEPTION("emstorage_get_new_attachment_no failed [%d]", err);
- emstorage_rollback_transaction(NULL, NULL, NULL);
+ emstorage_rollback_transaction(multi_user_name, NULL, NULL, NULL);
goto FINISH_OFF;
}
}
- if (!emstorage_create_dir(mail_data->account_id, mail_data->mail_id, attachment_data_list[i].inline_content_status ? 0 : attachment_id, &err)) {
+ if (!emstorage_create_dir(multi_user_name, mail_data->account_id, mail_data->mail_id, attachment_data_list[i].inline_content_status ? 0 : attachment_id, &err)) {
EM_DEBUG_EXCEPTION("emstorage_create_dir failed [%d]", err);
- emstorage_rollback_transaction(NULL, NULL, NULL);
+ emstorage_rollback_transaction(multi_user_name, NULL, NULL, NULL);
goto FINISH_OFF;
}
- if (!emstorage_get_save_name(mail_data->account_id, mail_data->mail_id, attachment_data_list[i].inline_content_status ? 0 : attachment_id, attachment_data_list[i].attachment_name, name_buf, sizeof(name_buf), &err)) {
+ if (!emstorage_get_save_name(multi_user_name,
+ mail_data->account_id,
+ mail_data->mail_id, attachment_data_list[i].inline_content_status ? 0 : attachment_id,
+ attachment_data_list[i].attachment_name,
+ name_buf,
+ path_buf,
+ sizeof(path_buf),
+ &err)) {
EM_DEBUG_EXCEPTION("emstorage_get_save_name failed [%d]", err);
- emstorage_rollback_transaction(NULL, NULL, NULL);
+ emstorage_rollback_transaction(multi_user_name, NULL, NULL, NULL);
goto FINISH_OFF;
}
/* if (input_from_eas == 0 || attachment_data_list[i].save_status) { */
if (attachment_data_list[i].save_status) {
if (attachment_data_list[i].attachment_mime_type && strcasestr(attachment_data_list[i].attachment_mime_type, "PKCS7")) {
- if (!emstorage_move_file(attachment_data_list[i].attachment_path, name_buf, input_from_eas, &err)) {
+ if (!emstorage_move_file(real_file_path, name_buf, input_from_eas, &err)) {
EM_DEBUG_EXCEPTION("emstorage_move_file failed [%d]", err);
- emstorage_rollback_transaction(NULL, NULL, NULL);
+ emstorage_rollback_transaction(multi_user_name, NULL, NULL, NULL);
goto FINISH_OFF;
}
} else {
- if (!emstorage_copy_file(attachment_data_list[i].attachment_path, name_buf, input_from_eas, &err)) {
+ if (!emstorage_copy_file(real_file_path, name_buf, input_from_eas, &err)) {
EM_DEBUG_EXCEPTION("emstorage_copy_file failed [%d]", err);
- emstorage_rollback_transaction(NULL, NULL, NULL);
+ emstorage_rollback_transaction(multi_user_name, NULL, NULL, NULL);
goto FINISH_OFF;
}
}
@@ -1133,7 +1201,7 @@ INTERNAL_FUNC int emcore_add_mail(email_mail_data_t *input_mail_data, email_atta
memset(&attachment_tbl, 0, sizeof(emstorage_attachment_tbl_t));
attachment_tbl.attachment_name = attachment_data_list[i].attachment_name;
- attachment_tbl.attachment_path = name_buf;
+ attachment_tbl.attachment_path = path_buf;
attachment_tbl.attachment_size = attachment_data_list[i].attachment_size;
attachment_tbl.mail_id = mail_data->mail_id;
attachment_tbl.account_id = mail_data->account_id;
@@ -1144,10 +1212,9 @@ INTERNAL_FUNC int emcore_add_mail(email_mail_data_t *input_mail_data, email_atta
attachment_tbl.attachment_mime_type = attachment_data_list[i].attachment_mime_type;
attachment_tbl.content_id = attachment_data_list[i].content_id;
- if (!emstorage_add_attachment(&attachment_tbl, 0, false, &err)) {
+ if (!emstorage_add_attachment(multi_user_name, &attachment_tbl, 0, false, &err)) {
EM_DEBUG_EXCEPTION("emstorage_add_attachment failed [%d]", err);
- emstorage_rollback_transaction(NULL, NULL, NULL);
-
+ emstorage_rollback_transaction(multi_user_name, NULL, NULL, NULL);
goto FINISH_OFF;
}
@@ -1158,13 +1225,13 @@ INTERNAL_FUNC int emcore_add_mail(email_mail_data_t *input_mail_data, email_atta
#ifdef __FEATURE_BODY_SEARCH__
/* Insert mail_text to DB */
- if (!emcore_strip_mail_body_from_file(converted_mail_tbl, &stripped_text, &err) || stripped_text == NULL) {
+ if (!emcore_strip_mail_body_from_file(multi_user_name, converted_mail_tbl, &stripped_text, &err) || stripped_text == NULL) {
EM_DEBUG_EXCEPTION("emcore_strip_mail_body_from_file failed [%d]", err);
}
- if (!emcore_add_mail_text(mailbox_tbl, converted_mail_tbl, stripped_text, &err)) {
+ if (!emcore_add_mail_text(multi_user_name, mailbox_tbl, converted_mail_tbl, stripped_text, &err)) {
EM_DEBUG_EXCEPTION("emcore_add_mail_text failed [%d]", err);
- emstorage_rollback_transaction(NULL, NULL, NULL);
+ emstorage_rollback_transaction(multi_user_name, NULL, NULL, NULL);
goto FINISH_OFF;
}
#endif
@@ -1175,16 +1242,17 @@ INTERNAL_FUNC int emcore_add_mail(email_mail_data_t *input_mail_data, email_atta
|| mail_data->meeting_request_status == EMAIL_MAIL_TYPE_MEETING_ORIGINATINGREQUEST) {
EM_DEBUG_LOG("This mail has the meeting request");
input_meeting_request->mail_id = mail_data->mail_id;
- if (!emstorage_add_meeting_request(mail_data->account_id, mailbox_tbl->mailbox_id, input_meeting_request, false, &err)) {
+
+ if (!emstorage_add_meeting_request(multi_user_name, mail_data->account_id, mailbox_tbl->mailbox_id, input_meeting_request, false, &err)) {
EM_DEBUG_EXCEPTION("emstorage_add_meeting_request failed [%d]", err);
- emstorage_rollback_transaction(NULL, NULL, NULL);
+ emstorage_rollback_transaction(multi_user_name, NULL, NULL, NULL);
goto FINISH_OFF;
}
}
- emstorage_commit_transaction(NULL, NULL, NULL);
+ emstorage_commit_transaction(multi_user_name, NULL, NULL, NULL);
- if (emstorage_get_thread_id_of_thread_mails(converted_mail_tbl, &thread_id, &latest_mail_id_in_thread, &thread_item_count) != EMAIL_ERROR_NONE)
+ if (emstorage_get_thread_id_of_thread_mails(multi_user_name, converted_mail_tbl, &thread_id, &latest_mail_id_in_thread, &thread_item_count) != EMAIL_ERROR_NONE)
EM_DEBUG_LOG(" emstorage_get_thread_id_of_thread_mails is failed.");
SNPRINTF(mailbox_id_param_string, 10, "%d", mailbox_tbl->mailbox_id);
@@ -1192,7 +1260,7 @@ INTERNAL_FUNC int emcore_add_mail(email_mail_data_t *input_mail_data, email_atta
EM_DEBUG_LOG("emcore_notify_storage_event [NOTI_MAIL_ADD] failed.");
if (account_tbl_item->incoming_server_type != EMAIL_SERVER_TYPE_ACTIVE_SYNC && !move_flag) {
- if (!emcore_remove_overflowed_mails(mailbox_tbl, &err)) {
+ if (!emcore_remove_overflowed_mails(multi_user_name, mailbox_tbl, &err)) {
if (err == EMAIL_ERROR_MAIL_NOT_FOUND || err == EMAIL_ERROR_NOT_SUPPORTED)
err = EMAIL_ERROR_NONE;
else
@@ -1203,7 +1271,7 @@ INTERNAL_FUNC int emcore_add_mail(email_mail_data_t *input_mail_data, email_atta
if ( input_from_eas && (mail_data->flags_seen_field == 0)) {
// && mail_data->mailbox_type != EMAIL_MAILBOX_TYPE_TRASH
// && mail_data->mailbox_type != EMAIL_MAILBOX_TYPE_SPAMBOX) {
- if ((err = emcore_update_sync_status_of_account(mail_data->account_id, SET_TYPE_SET, SYNC_STATUS_SYNCING | SYNC_STATUS_HAVE_NEW_MAILS)) != EMAIL_ERROR_NONE)
+ if ((err = emcore_update_sync_status_of_account(multi_user_name, mail_data->account_id, SET_TYPE_SET, SYNC_STATUS_SYNCING | SYNC_STATUS_HAVE_NEW_MAILS)) != EMAIL_ERROR_NONE)
EM_DEBUG_LOG("emcore_update_sync_status_of_account failed [%d]", err);
}
@@ -1212,6 +1280,7 @@ FINISH_OFF:
dlclose(dl_handle);
EM_SAFE_FREE(body_text_file_name);
+ EM_SAFE_FREE(prefix_path);
#ifdef __FEATURE_BODY_SEARCH__
EM_SAFE_FREE(stripped_text);
@@ -1233,7 +1302,7 @@ FINISH_OFF:
return err;
}
-INTERNAL_FUNC int emcore_add_read_receipt(int input_read_mail_id, int *output_receipt_mail_id)
+INTERNAL_FUNC int emcore_add_read_receipt(char *multi_user_name, int input_read_mail_id, int *output_receipt_mail_id)
{
EM_DEBUG_FUNC_BEGIN("input_read_mail_id [%d], output_receipt_mail_id [%p]", input_read_mail_id, output_receipt_mail_id);
int err = EMAIL_ERROR_NONE;
@@ -1246,7 +1315,7 @@ INTERNAL_FUNC int emcore_add_read_receipt(int input_read_mail_id, int *output_re
emstorage_mailbox_tbl_t *mailbox_tbl = NULL;
BODY *root_body = NULL;
- if( (err = emcore_get_mail_data(input_read_mail_id, &read_mail_data)) != EMAIL_ERROR_NONE) {
+ if( (err = emcore_get_mail_data(multi_user_name, input_read_mail_id, &read_mail_data)) != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("emcore_get_mail_data failed [%d]", err);
goto FINISH_OFF;
}
@@ -1275,7 +1344,7 @@ INTERNAL_FUNC int emcore_add_read_receipt(int input_read_mail_id, int *output_re
SNPRINTF(receipt_mail_data->subject, EM_SAFE_STRLEN(read_mail_data->subject) + 7, "Read: %s", read_mail_data->subject);
}
- if (!emstorage_get_mailbox_by_mailbox_type(receipt_mail_data->account_id, EMAIL_MAILBOX_TYPE_OUTBOX, &mailbox_tbl, true, &err)) {
+ if (!emstorage_get_mailbox_by_mailbox_type(multi_user_name, receipt_mail_data->account_id, EMAIL_MAILBOX_TYPE_OUTBOX, &mailbox_tbl, true, &err)) {
EM_DEBUG_EXCEPTION("emstorage_get_mailbox_name_by_mailbox_type failed [%d]", err);
goto FINISH_OFF;
}
@@ -1293,14 +1362,14 @@ INTERNAL_FUNC int emcore_add_read_receipt(int input_read_mail_id, int *output_re
goto FINISH_OFF;
}
- if ( (err = emcore_make_envelope_from_mail(receipt_mail_tbl_data, &envelope)) != EMAIL_ERROR_NONE) {
+ if ( (err = emcore_make_envelope_from_mail(multi_user_name, receipt_mail_tbl_data, &envelope)) != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("emcore_make_envelope_from_mail failed [%d]", err);
goto FINISH_OFF;
}
envelope->references = EM_SAFE_STRDUP(read_mail_data->message_id);
- if (!emcore_get_report_mail_body(envelope, &root_body, &err)) {
+ if (!emcore_get_report_mail_body(multi_user_name, envelope, &root_body, &err)) {
EM_DEBUG_EXCEPTION("emcore_get_report_mail_body failed [%d]", err);
goto FINISH_OFF;
}
@@ -1334,7 +1403,7 @@ INTERNAL_FUNC int emcore_add_read_receipt(int input_read_mail_id, int *output_re
attachment_data->attachment_name = cpystr(p);
*/
- if ( (err = emcore_add_mail(receipt_mail_data, attachment_data, attachment_count, NULL, 0, false)) != EMAIL_ERROR_NONE) {
+ if ( (err = emcore_add_mail(multi_user_name, receipt_mail_data, attachment_data, attachment_count, NULL, 0, false)) != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("emcore_add_mail failed [%d]", err);
goto FINISH_OFF;
}
@@ -1342,24 +1411,23 @@ INTERNAL_FUNC int emcore_add_read_receipt(int input_read_mail_id, int *output_re
*output_receipt_mail_id = receipt_mail_data->mail_id;
FINISH_OFF:
-
- if (receipt_mail_data) {
+ if(receipt_mail_data) {
EM_SAFE_FREE(receipt_mail_data->full_address_to);
EM_SAFE_FREE(receipt_mail_data->message_id);
EM_SAFE_FREE(receipt_mail_data->subject);
EM_SAFE_FREE(receipt_mail_data);
}
- if (mailbox_tbl)
+ if(mailbox_tbl)
emstorage_free_mailbox(&mailbox_tbl, 1, NULL);
- if (read_mail_data)
+ if(read_mail_data)
emcore_free_mail_data_list(&read_mail_data, 1);
- if (attachment_data)
+ if(attachment_data)
emcore_free_attachment_data(&attachment_data, 1, NULL);
- if (receipt_mail_tbl_data)
+ if(receipt_mail_tbl_data)
emstorage_free_mail(&receipt_mail_tbl_data, 1, NULL);
if (root_body)
@@ -1369,7 +1437,7 @@ FINISH_OFF:
return err;
}
-INTERNAL_FUNC int emcore_add_meeting_request(int account_id, int input_mailbox_id, email_meeting_request_t *meeting_req, int *err_code)
+INTERNAL_FUNC int emcore_add_meeting_request(char *multi_user_name, int account_id, int input_mailbox_id, email_meeting_request_t *meeting_req, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("account_id[%d], input_mailbox_id[%d], meeting_req[%p], err_code[%p]", account_id, input_mailbox_id, meeting_req, err_code);
int ret = false;
@@ -1383,9 +1451,8 @@ INTERNAL_FUNC int emcore_add_meeting_request(int account_id, int input_mailbox_i
goto FINISH_OFF;
}
- if (!emstorage_add_meeting_request(account_id, input_mailbox_id, meeting_req, 1, &err)) {
+ if (!emstorage_add_meeting_request(multi_user_name, account_id, input_mailbox_id, meeting_req, 1, &err)) {
EM_DEBUG_EXCEPTION(" emstorage_add_meeting_request failed [%d]", err);
-
goto FINISH_OFF;
}
@@ -1400,7 +1467,7 @@ FINISH_OFF:
return ret;
}
-INTERNAL_FUNC int emcore_query_mail_size_limit(int account_id, int handle, int *err_code)
+INTERNAL_FUNC int emcore_query_mail_size_limit(char *multi_user_name, int account_id, int handle, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("account_id[%d], err_code[%p]", account_id, err_code);
int ret = false;
@@ -1418,7 +1485,7 @@ INTERNAL_FUNC int emcore_query_mail_size_limit(int account_id, int handle, int *
goto FINISH_OFF;
}
- if (!(ref_account = emcore_get_account_reference(account_id))) {
+ if (!(ref_account = emcore_get_account_reference(multi_user_name, account_id, false))) {
EM_DEBUG_EXCEPTION("emcore_get_account_reference failed [%d]", account_id);
err = EMAIL_ERROR_INVALID_ACCOUNT;
goto FINISH_OFF;
@@ -1431,13 +1498,13 @@ INTERNAL_FUNC int emcore_query_mail_size_limit(int account_id, int handle, int *
}
if (ref_account->pop_before_smtp != FALSE) {
- if (!emcore_connect_to_remote_mailbox(account_id, 0, (void **)&mail_stream, &err)) {
+ if (!emcore_connect_to_remote_mailbox(multi_user_name, account_id, 0, (void **)&mail_stream, &err)) {
EM_DEBUG_EXCEPTION(" POP before SMTP Authentication failed [%d]", err);
goto FINISH_OFF;
}
}
- if (!emcore_connect_to_remote_mailbox(account_id, EMAIL_CONNECT_FOR_SENDING, (void **)&tmp_stream, &err)) {
+ if (!emcore_connect_to_remote_mailbox(multi_user_name, account_id, EMAIL_CONNECT_FOR_SENDING, (void **)&tmp_stream, &err)) {
EM_DEBUG_EXCEPTION(" emcore_connect_to_remote_mailbox failed [%d]", err);
goto FINISH_OFF;
}
@@ -1517,7 +1584,7 @@ INTERNAL_FUNC void emcore_close_smtp_stream_list ()
if threads exit after calling the function, emcore_close_smtp_stream_list should be called.
Otherwise, memory leaks
*/
-INTERNAL_FUNC SENDSTREAM** emcore_get_smtp_stream (int account_id, int *error)
+INTERNAL_FUNC SENDSTREAM** emcore_get_smtp_stream (char *multi_user_name, int account_id, int *error)
{
EM_DEBUG_FUNC_BEGIN("account_id[%d]", account_id);
GList* cur = g_send_stream_list;
@@ -1556,7 +1623,7 @@ INTERNAL_FUNC SENDSTREAM** emcore_get_smtp_stream (int account_id, int *error)
goto FINISH_OFF;
}
- if (!emcore_connect_to_remote_mailbox(account_id, EMAIL_CONNECT_FOR_SENDING, (void **)ret, &err)) {
+ if (!emcore_connect_to_remote_mailbox(multi_user_name, account_id, EMAIL_CONNECT_FOR_SENDING, (void **)ret, &err)) {
EM_DEBUG_EXCEPTION("emcore_connect_to_remote_mailbox failed [%d]", err);
EM_SAFE_FREE(ret);
@@ -1595,14 +1662,13 @@ mainloop (by alarm),
thread_func_EMAIL_ASYNC_TASK_SEND_MAIL_WITH_DOWNLOADING_ATTACHMENT_OF_ORIGINAL_MAIL,
*/
-INTERNAL_FUNC int emcore_send_mail(int mail_id, int *err_code)
+INTERNAL_FUNC int emcore_send_mail(char *multi_user_name, int mail_id, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("mail_id[%d], err_code[%p]", mail_id, err_code);
EM_PROFILE_BEGIN(profile_emcore_send_mail);
int ret = false;
int err = EMAIL_ERROR_NONE, err2 = EMAIL_ERROR_NONE;
int attachment_tbl_count = 0;
- int i = 0;
int account_id = 0;
SENDSTREAM** send_stream = NULL;
ENVELOPE *envelope = NULL;
@@ -1625,20 +1691,20 @@ INTERNAL_FUNC int emcore_send_mail(int mail_id, int *err_code)
}
/* get mail to send */
- if (!emstorage_get_mail_by_id(mail_id, &mail_tbl_data, false, &err) || err != EMAIL_ERROR_NONE) {
+ if (!emstorage_get_mail_by_id(multi_user_name, mail_id, &mail_tbl_data, false, &err) || err != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("emstorage_get_mail_by_id failed [%d]", err);
goto FINISH_OFF;
}
account_id = mail_tbl_data->account_id;
- if (!(ref_account = emcore_get_account_reference(account_id))) {
+ if (!(ref_account = emcore_get_account_reference(multi_user_name, account_id, false))) {
EM_DEBUG_EXCEPTION("emcore_get_account_reference failed [%d]", account_id);
err = EMAIL_ERROR_INVALID_ACCOUNT;
goto FINISH_OFF;
}
- if ((err = emstorage_get_attachment_list(mail_id, false, &attachment_tbl_data, &attachment_tbl_count)) != EMAIL_ERROR_NONE) {
+ if ((err = emstorage_get_attachment_list(multi_user_name, mail_id, false, &attachment_tbl_data, &attachment_tbl_count)) != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("emstorage_get_attachment_list failed [%d]", err);
goto FINISH_OFF;
}
@@ -1671,6 +1737,7 @@ INTERNAL_FUNC int emcore_send_mail(int mail_id, int *err_code)
opt = &(ref_account->options);
#ifdef __FEATURE_SUPPORT_VALIDATION_SYSTEM__
+ int i = 0;
EM_VALIDATION_SYSTEM_LOG("INFO", mail_id, "Email Send Start, %s -> %s, success", mail_tbl_data->full_address_from, mail_tbl_data->full_address_to);
for (i = 0; i < attachment_tbl_count; i++) {
if(attachment_tbl_data)
@@ -1681,7 +1748,7 @@ INTERNAL_FUNC int emcore_send_mail(int mail_id, int *err_code)
/*Update status flag to DB*/
/* get rfc822 data */
- if (!emcore_make_rfc822_file_from_mail(mail_tbl_data, attachment_tbl_data, attachment_tbl_count, &envelope, &fpath, opt, &err)) {
+ if (!emcore_make_rfc822_file_from_mail(multi_user_name, mail_tbl_data, attachment_tbl_data, attachment_tbl_count, &envelope, &fpath, opt, &err)) {
EM_DEBUG_EXCEPTION("emcore_make_rfc822_file_from_mail failed [%d]", err);
goto FINISH_OFF;
}
@@ -1705,22 +1772,27 @@ INTERNAL_FUNC int emcore_send_mail(int mail_id, int *err_code)
}
if (ref_account->pop_before_smtp != FALSE) {
- if (!emcore_connect_to_remote_mailbox(account_id, 0, (void **)&mail_stream, &err)) {
+ if (!emcore_connect_to_remote_mailbox(multi_user_name, account_id, 0, (void **)&mail_stream, &err)) {
EM_DEBUG_EXCEPTION(" POP before SMTP Authentication failed [%d]", err);
if (err == EMAIL_ERROR_CONNECTION_BROKEN)
err = EMAIL_ERROR_CANCELLED;
goto FINISH_OFF;
}
}
- if (!emstorage_get_mailbox_by_mailbox_type(account_id, EMAIL_MAILBOX_TYPE_DRAFT, &local_mailbox, false, &err)) {
+
+ if (!emstorage_get_mailbox_by_mailbox_type(multi_user_name, account_id, EMAIL_MAILBOX_TYPE_DRAFT, &local_mailbox, false, &err)) {
EM_DEBUG_EXCEPTION(" emstorage_get_mailbox_by_mailbox_type failed [%d]", err);
goto FINISH_OFF;
}
dst_mailbox_id = local_mailbox->mailbox_id;
emstorage_free_mailbox(&local_mailbox, 1, NULL);
+ if (!emnetwork_check_network_status(&err)) {
+ EM_DEBUG_EXCEPTION("emnetwork_check_network_status failed [%d]", err);
+ goto FINISH_OFF;
+ }
- send_stream = emcore_get_smtp_stream (account_id, &err);
+ send_stream = emcore_get_smtp_stream (multi_user_name, account_id, &err);
if (!send_stream) {
EM_DEBUG_EXCEPTION(" emcore_get_smtp_stream failed [%d]", err);
if (err == EMAIL_ERROR_CONNECTION_BROKEN)
@@ -1729,7 +1801,7 @@ INTERNAL_FUNC int emcore_send_mail(int mail_id, int *err_code)
}
#if 0
- if (!emcore_connect_to_remote_mailbox(account_id, EMAIL_CONNECT_FOR_SENDING, (void **)&tmp_stream, &err)) {
+ if (!emcore_connect_to_remote_mailbox(multi_user_name, account_id, EMAIL_CONNECT_FOR_SENDING, (void **)&tmp_stream, &err)) {
EM_DEBUG_EXCEPTION(" emcore_connect_to_remote_mailbox failed [%d]", err);
if (err == EMAIL_ERROR_CONNECTION_BROKEN)
@@ -1771,20 +1843,20 @@ INTERNAL_FUNC int emcore_send_mail(int mail_id, int *err_code)
}
mail_tbl_data->save_status = EMAIL_MAIL_STATUS_SENDING;
- emcore_show_user_message(mail_id, EMAIL_ACTION_SENDING_MAIL, EMAIL_ERROR_NONE);
+ emcore_show_user_message(multi_user_name, mail_id, EMAIL_ACTION_SENDING_MAIL, EMAIL_ERROR_NONE);
/*Update status save_status to DB*/
- if (!emstorage_set_field_of_mails_with_integer_value(account_id, &mail_id, 1, "save_status", mail_tbl_data->save_status, true, &err))
+ if (!emstorage_set_field_of_mails_with_integer_value(multi_user_name, account_id, &mail_id, 1, "save_status", mail_tbl_data->save_status, true, &err))
EM_DEBUG_EXCEPTION("emstorage_set_field_of_mails_with_integer_value failed [%d]", err);
/* send mail to server. */
- if (!emcore_send_mail_smtp(*send_stream, envelope, fpath, account_id, mail_id, &err)) {
+ if (!emcore_send_mail_smtp(multi_user_name, *send_stream, envelope, fpath, account_id, mail_id, &err)) {
EM_DEBUG_EXCEPTION(" emcore_send_mail_smtp failed [%d]", err);
if (err == SMTP_RESPONSE_EXCEED_SIZE_LIMIT)
err = EMAIL_ERROR_SMTP_SEND_FAILURE_BY_OVERSIZE;
#ifndef __FEATURE_MOVE_TO_OUTBOX_FIRST__
- if (!emstorage_get_mailbox_by_mailbox_type(account_id, EMAIL_MAILBOX_TYPE_OUTBOX, &local_mailbox, false, &err)) {
+ if (!emstorage_get_mailbox_by_mailbox_type(multi_user_name, account_id, EMAIL_MAILBOX_TYPE_OUTBOX, &local_mailbox, false, &err)) {
EM_DEBUG_EXCEPTION("emstorage_get_mailbox_by_mailbox_type failed [%d]", err);
goto FINISH_OFF;
}
@@ -1792,7 +1864,7 @@ INTERNAL_FUNC int emcore_send_mail(int mail_id, int *err_code)
emstorage_free_mailbox(&local_mailbox, 1, NULL);
/* unsent mail is moved to 'OUTBOX'. */
- if (!emcore_move_mail(&mail_id, 1, dst_mailbox_id, EMAIL_MOVED_BY_COMMAND, 0, NULL))
+ if (!emcore_move_mail(multi_user_name, &mail_id, 1, dst_mailbox_id, EMAIL_MOVED_BY_COMMAND, 0, NULL))
EM_DEBUG_EXCEPTION(" emcore_mail_move falied...");
#endif
if (err > 0)
@@ -1800,18 +1872,18 @@ INTERNAL_FUNC int emcore_send_mail(int mail_id, int *err_code)
goto FINISH_OFF;
}
- emcore_show_user_message(mail_id, EMAIL_ACTION_SEND_MAIL, err);
+ emcore_show_user_message(multi_user_name, mail_id, EMAIL_ACTION_SEND_MAIL, err);
sent_flag = 1;
/* sent mail is moved to 'SENT' box or deleted. */
if (opt->keep_local_copy) {
- if (!emstorage_get_mailbox_by_mailbox_type(account_id, EMAIL_MAILBOX_TYPE_SENTBOX, &local_mailbox, true, &err)) {
+ if (!emstorage_get_mailbox_by_mailbox_type(multi_user_name, account_id, EMAIL_MAILBOX_TYPE_SENTBOX, &local_mailbox, true, &err)) {
EM_DEBUG_EXCEPTION("emstorage_get_mailbox_by_mailbox_type failed [%d]", err);
goto FINISH_OFF;
}
dst_mailbox_id = local_mailbox->mailbox_id;
- if (!emcore_move_mail(&mail_id, 1, dst_mailbox_id, EMAIL_MOVED_AFTER_SENDING, 0, &err))
+ if (!emcore_move_mail(multi_user_name, &mail_id, 1, dst_mailbox_id, EMAIL_MOVED_AFTER_SENDING, 0, &err))
EM_DEBUG_EXCEPTION(" emcore_mail_move falied [%d]", err);
#ifdef __FEATURE_SYNC_CLIENT_TO_SERVER__
#ifdef __FEATURE_LOCAL_ACTIVITY__
@@ -1836,7 +1908,7 @@ INTERNAL_FUNC int emcore_send_mail(int mail_id, int *err_code)
EM_DEBUG_EXCEPTION(" emcore_add_activity Failed [%d] ", err);
}
- if (!emcore_move_mail_on_server(dest_mbox.account_id, dst_mailbox_id, &mail_id, 1, dest_mbox.name, &err)) {
+ if (!emcore_move_mail_on_server(multi_user_name, dest_mbox.account_id, dst_mailbox_id, &mail_id, 1, dest_mbox.name, &err)) {
EM_DEBUG_EXCEPTION(" emcore_move_mail_on_server falied [%d]", err);
}
else {
@@ -1859,23 +1931,29 @@ INTERNAL_FUNC int emcore_send_mail(int mail_id, int *err_code)
#endif
if (ref_account->incoming_server_type == EMAIL_SERVER_TYPE_IMAP4) {
emstorage_mailbox_tbl_t* src_mailbox = NULL;
- emstorage_mail_tbl_t *temp_mail = NULL;
+// emstorage_mail_tbl_t *temp_mail = NULL;
- if (!emstorage_get_mailbox_by_mailbox_type(account_id, EMAIL_MAILBOX_TYPE_OUTBOX, &src_mailbox, true, &err)) {
+ if (!emstorage_get_mailbox_by_mailbox_type(multi_user_name, account_id, EMAIL_MAILBOX_TYPE_OUTBOX, &src_mailbox, true, &err)) {
EM_DEBUG_EXCEPTION("emstorage_get_mailbox_by_mailbox_type failed [%d]", err);
goto FINISH_OFF;
}
EM_DEBUG_LOG("local_yn:[%d]", src_mailbox->local_yn);
- if (src_mailbox->local_yn) {
-
+ if (src_mailbox->local_yn) {
+ /* This is syncing operation in sent box
+ but it slowed operation */
+ /*
void *local_stream = NULL;
- if (!emcore_sync_header (local_mailbox, &local_stream, NULL, NULL, NULL, NULL, NULL, 0, -1, &err)) {
+ if (!emcore_sync_header (multi_user_name, local_mailbox, &local_stream, NULL, NULL, NULL, NULL, NULL, 0, -1, &err)) {
EM_DEBUG_EXCEPTION("emcore_sync_header failed");
}
mail_close (local_stream);
-
- if (!emstorage_get_maildata_by_servermailid(local_mailbox->mailbox_id, "0", &temp_mail, false, &err)) {
+ if (!emstorage_get_maildata_by_servermailid(multi_user_name,
+ "0",
+ local_mailbox->mailbox_id,
+ &temp_mail,
+ false,
+ &err)) {
if (err != EMAIL_ERROR_MAIL_NOT_FOUND) {
EM_DEBUG_EXCEPTION("emstorage_get_maildata_by_servermailid failed : [%d]", err);
goto FINISH_OFF;
@@ -1883,12 +1961,19 @@ INTERNAL_FUNC int emcore_send_mail(int mail_id, int *err_code)
}
if (temp_mail) {
- emcore_sync_mail_from_client_to_server(mail_id);
- emstorage_free_mail(&temp_mail, 1, NULL);
+ emcore_sync_mail_from_client_to_server(multi_user_name, mail_id);
+ emstorage_free_mail(&temp_mail, 1, NULL);
+ }
+ */
+
+ /* sent box exception list : gmail (After the mail sent, moved the sent box) */
+ if (ref_account->outgoing_server_address) {
+ if (!strcasestr(ref_account->outgoing_server_address, "gmail"))
+ emcore_sync_mail_from_client_to_server(multi_user_name, mail_id);
}
}
else {
- if (!emcore_move_mail_on_server(account_id, src_mailbox->mailbox_id, &mail_id, 1, local_mailbox->mailbox_name, &err)) {
+ if (!emcore_move_mail_on_server(multi_user_name, account_id, src_mailbox->mailbox_id, &mail_id, 1, local_mailbox->mailbox_name, &err)) {
EM_DEBUG_EXCEPTION(" emcore_move_mail_on_server falied [%d]", err);
}
}
@@ -1899,22 +1984,22 @@ INTERNAL_FUNC int emcore_send_mail(int mail_id, int *err_code)
/* On Successful Mail sent remove the Draft flag */
mail_tbl_data->flags_draft_field = 0;
- if (!emstorage_set_field_of_mails_with_integer_value(account_id, &mail_id, 1, "flags_draft_field", mail_tbl_data->flags_draft_field, true, &err))
+ if (!emstorage_set_field_of_mails_with_integer_value(multi_user_name, account_id, &mail_id, 1, "flags_draft_field", mail_tbl_data->flags_draft_field, true, &err))
EM_DEBUG_EXCEPTION("Failed to modify extra flag [%d]", err);
}
else {
- if (!emcore_delete_mail(account_id, &mail_id, 1, EMAIL_DELETE_LOCALLY, EMAIL_DELETED_AFTER_SENDING, false, &err))
+ if (!emcore_delete_mail(multi_user_name, account_id, &mail_id, 1, EMAIL_DELETE_LOCALLY, EMAIL_DELETED_AFTER_SENDING, false, &err))
EM_DEBUG_EXCEPTION(" emcore_delete_mail failed [%d]", err);
}
/* Set the phone log */
- if ((err = emcore_set_sent_contacts_log(mail_tbl_data)) != EMAIL_ERROR_NONE) {
+ if ((err = emcore_set_sent_contacts_log(multi_user_name, mail_tbl_data)) != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("emcore_set_sent_contacts_log failed : [%d]", err);
}
/*Update save_status */
mail_tbl_data->save_status = EMAIL_MAIL_STATUS_SENT;
- if (!emstorage_set_field_of_mails_with_integer_value(account_id, &mail_id, 1, "save_status", mail_tbl_data->save_status, true, &err))
+ if (!emstorage_set_field_of_mails_with_integer_value(multi_user_name, account_id, &mail_id, 1, "save_status", mail_tbl_data->save_status, true, &err))
EM_DEBUG_EXCEPTION("emstorage_set_field_of_mails_with_integer_value failed [%d]", err);
if (!emcore_delete_transaction_info_by_mailId(mail_id))
@@ -1924,13 +2009,13 @@ INTERNAL_FUNC int emcore_send_mail(int mail_id, int *err_code)
FINISH_OFF:
if (ret == false && sent_flag == 0) {
- emcore_show_user_message(mail_id, EMAIL_ACTION_SEND_MAIL, err);
+ emcore_show_user_message(multi_user_name, mail_id, EMAIL_ACTION_SEND_MAIL, err);
}
if (ret == false && err != EMAIL_ERROR_INVALID_PARAM && mail_tbl_data) {
if (err != EMAIL_ERROR_CANCELLED) {
mail_tbl_data->save_status = EMAIL_MAIL_STATUS_SEND_FAILURE;
- if (!emstorage_set_field_of_mails_with_integer_value(account_id, &mail_id, 1, "save_status", mail_tbl_data->save_status, true, &err2))
+ if (!emstorage_set_field_of_mails_with_integer_value(multi_user_name, account_id, &mail_id, 1, "save_status", mail_tbl_data->save_status, true, &err2))
EM_DEBUG_EXCEPTION("emstorage_set_field_of_mails_with_integer_value failed [%d]", err2);
}
else {
@@ -1938,7 +2023,7 @@ FINISH_OFF:
EM_DEBUG_LOG("EMAIL_MAIL_STATUS_SEND_CANCELED Already set for ");
else {
mail_tbl_data->save_status = EMAIL_MAIL_STATUS_SEND_CANCELED;
- if (!emstorage_set_field_of_mails_with_integer_value(account_id, &mail_id, 1, "save_status", mail_tbl_data->save_status, true, &err2))
+ if (!emstorage_set_field_of_mails_with_integer_value(multi_user_name, account_id, &mail_id, 1, "save_status", mail_tbl_data->save_status, true, &err2))
EM_DEBUG_EXCEPTION("emstorage_set_field_of_mails_with_integer_value failed [%d]", err2);
}
}
@@ -1995,7 +2080,7 @@ FINISH_OFF:
if (err != EMAIL_ERROR_SMTP_SEND_FAILURE_BY_OVERSIZE) {
/* Add alarm for next sending mails */
- if( (err2 = emcore_create_alarm_for_auto_resend(AUTO_RESEND_INTERVAL)) != EMAIL_ERROR_NONE) {
+ if( (err2 = emcore_create_alarm_for_auto_resend(multi_user_name, AUTO_RESEND_INTERVAL)) != EMAIL_ERROR_NONE) {
if (err2 != EMAIL_ERROR_MAIL_NOT_FOUND)
EM_DEBUG_EXCEPTION("emcore_create_alarm_for_auto_resend failed [%d]", err2);
}
@@ -2013,7 +2098,7 @@ FINISH_OFF:
}
/* send a saved all mails */
-INTERNAL_FUNC int emcore_send_saved_mail(int account_id, char *input_mailbox_name, int *err_code)
+INTERNAL_FUNC int emcore_send_saved_mail(char *multi_user_name, int account_id, char *input_mailbox_name, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("account_id[%d], input_mailbox_name[%p], err_code[%p]", account_id, input_mailbox_name, err_code);
@@ -2022,7 +2107,7 @@ INTERNAL_FUNC int emcore_send_saved_mail(int account_id, char *input_mailbox_nam
int err2 = EMAIL_ERROR_NONE;
int status = EMAIL_SEND_FAIL;
int *mail_ids = NULL;
- int handle = 0;
+ DB_STMT handle = NULL;
int i = 0;
int total = 0;
int attachment_tbl_count = 0;
@@ -2045,7 +2130,7 @@ INTERNAL_FUNC int emcore_send_saved_mail(int account_id, char *input_mailbox_nam
}
- if (!(ref_account = emcore_get_account_reference(account_id))) {
+ if (!(ref_account = emcore_get_account_reference(multi_user_name, account_id, false))) {
EM_DEBUG_EXCEPTION("emcore_get_account_reference failed [%d]", account_id);
err = EMAIL_ERROR_INVALID_ACCOUNT;
goto FINISH_OFF;
@@ -2054,15 +2139,20 @@ INTERNAL_FUNC int emcore_send_saved_mail(int account_id, char *input_mailbox_nam
/*don't delete the comment. several threads including event thread call this func */
/* FINISH_OFF_IF_CANCELED; */
+ if (!emnetwork_check_network_status(&err)) {
+ EM_DEBUG_EXCEPTION("emnetwork_check_network_status failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
opt = &(ref_account->options);
- if (!emstorage_get_mailbox_by_name(account_id, -1, input_mailbox_name, &local_mailbox, false, &err)) {
+ if (!emstorage_get_mailbox_by_name(multi_user_name, account_id, -1, input_mailbox_name, &local_mailbox, false, &err)) {
EM_DEBUG_EXCEPTION("emstorage_get_mailbox_by_name failed : [%d]", err);
goto FINISH_OFF;
}
/* search mail. */
- if (!emstorage_mail_search_start(NULL, account_id, local_mailbox->mailbox_id, 0, &handle, &total, true, &err)) {
+ if (!emstorage_mail_search_start(multi_user_name, NULL, account_id, local_mailbox->mailbox_id, 0, &handle, &total, true, &err)) {
EM_DEBUG_EXCEPTION("emstorage_mail_search_start failed [%d]", err);
goto FINISH_OFF;
}
@@ -2097,7 +2187,7 @@ INTERNAL_FUNC int emcore_send_saved_mail(int account_id, char *input_mailbox_nam
/*don't delete the comment. several threads including event thread call this func */
/* FINISH_OFF_IF_CANCELED;*/
- if (!emstorage_get_mail_by_id(mail_ids[i], &searched_mail_tbl_data, false, &err)) {
+ if (!emstorage_get_mail_by_id(multi_user_name, mail_ids[i], &searched_mail_tbl_data, false, &err)) {
EM_DEBUG_EXCEPTION("emstorage_get_mail_by_id failed [%d]", err);
goto FINISH_OFF;
}
@@ -2110,7 +2200,7 @@ INTERNAL_FUNC int emcore_send_saved_mail(int account_id, char *input_mailbox_nam
continue;
}
- if ( (err = emstorage_get_attachment_list(mail_ids[i], false, &attachment_tbl_data, &attachment_tbl_count)) != EMAIL_ERROR_NONE) {
+ if ( (err = emstorage_get_attachment_list(multi_user_name, mail_ids[i], false, &attachment_tbl_data, &attachment_tbl_count)) != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("emstorage_get_attachment_list failed [%d]", err);
goto FINISH_OFF;
}
@@ -2124,7 +2214,7 @@ INTERNAL_FUNC int emcore_send_saved_mail(int account_id, char *input_mailbox_nam
searched_mail_tbl_data->save_status = EMAIL_MAIL_STATUS_SENDING;
- if (!emcore_make_rfc822_file_from_mail(searched_mail_tbl_data, attachment_tbl_data, attachment_tbl_count, &envelope, &fpath, opt, &err)) {
+ if (!emcore_make_rfc822_file_from_mail(multi_user_name, searched_mail_tbl_data, attachment_tbl_data, attachment_tbl_count, &envelope, &fpath, opt, &err)) {
EM_DEBUG_EXCEPTION("emcore_make_rfc822_file_from_mail falied [%d]", err);
goto FINISH_OFF;
}
@@ -2141,7 +2231,7 @@ INTERNAL_FUNC int emcore_send_saved_mail(int account_id, char *input_mailbox_nam
}
stream = NULL;
- if (!emcore_connect_to_remote_mailbox(account_id, EMAIL_CONNECT_FOR_SENDING, &tmp_stream, &err) || !tmp_stream) {
+ if (!emcore_connect_to_remote_mailbox(multi_user_name, account_id, EMAIL_CONNECT_FOR_SENDING, &tmp_stream, &err) || !tmp_stream) {
EM_DEBUG_EXCEPTION("emcore_connect_to_remote_mailbox failed [%d]", err);
if (err == EMAIL_ERROR_CONNECTION_BROKEN)
@@ -2172,29 +2262,29 @@ INTERNAL_FUNC int emcore_send_saved_mail(int account_id, char *input_mailbox_nam
searched_mail_tbl_data->save_status = EMAIL_MAIL_STATUS_SENDING;
/* update mail status to sending. */
- if (!emstorage_change_mail_field(mail_ids[i], UPDATE_EXTRA_FLAG, searched_mail_tbl_data, true, &err)) {
+ if (!emstorage_change_mail_field(multi_user_name, mail_ids[i], UPDATE_EXTRA_FLAG, searched_mail_tbl_data, true, &err)) {
EM_DEBUG_EXCEPTION("emstorage_change_mail_field failed [%d]", err);
goto FINISH_OFF;
}
- if (!emcore_send_mail_smtp(stream, envelope, fpath, account_id, mail_ids[i], &err)) {
+ if (!emcore_send_mail_smtp(multi_user_name, stream, envelope, fpath, account_id, mail_ids[i], &err)) {
EM_DEBUG_EXCEPTION("emcore_send_mail_smtp failed [%d]", err);
if (err == SMTP_RESPONSE_EXCEED_SIZE_LIMIT) err = EMAIL_ERROR_SMTP_SEND_FAILURE_BY_OVERSIZE;
searched_mail_tbl_data->save_status = EMAIL_MAIL_STATUS_SEND_FAILURE;
/* update mail status to failure. */
- if (!emstorage_change_mail_field(mail_ids[i], UPDATE_EXTRA_FLAG, searched_mail_tbl_data, true, &err2))
+ if (!emstorage_change_mail_field(multi_user_name, mail_ids[i], UPDATE_EXTRA_FLAG, searched_mail_tbl_data, true, &err2))
EM_DEBUG_EXCEPTION("emstorage_change_mail_field failed [%d]", err);
- if (!emstorage_get_mailbox_by_mailbox_type(account_id, EMAIL_MAILBOX_TYPE_OUTBOX, &local_mailbox, true, &err)) {
+ if (!emstorage_get_mailbox_by_mailbox_type(multi_user_name, account_id, EMAIL_MAILBOX_TYPE_OUTBOX, &local_mailbox, true, &err)) {
EM_DEBUG_EXCEPTION("emstorage_get_mailbox_by_mailbox_type failed [%d]", err);
goto FINISH_OFF;
}
dst_mailbox_id = local_mailbox->mailbox_id;
- emcore_move_mail(&mail_ids[i], 1, dst_mailbox_id, EMAIL_MOVED_AFTER_SENDING, 0, NULL);
+ emcore_move_mail(multi_user_name, &mail_ids[i], 1, dst_mailbox_id, EMAIL_MOVED_AFTER_SENDING, 0, NULL);
if(local_mailbox)
emstorage_free_mailbox(&local_mailbox, 1, NULL);
@@ -2205,32 +2295,32 @@ INTERNAL_FUNC int emcore_send_saved_mail(int account_id, char *input_mailbox_nam
searched_mail_tbl_data->save_status = EMAIL_MAIL_STATUS_SENT;
/* update mail status to sent mail. */
- if (!emstorage_change_mail_field(mail_ids[i], UPDATE_EXTRA_FLAG, searched_mail_tbl_data, true, &err)) {
+ if (!emstorage_change_mail_field(multi_user_name, mail_ids[i], UPDATE_EXTRA_FLAG, searched_mail_tbl_data, true, &err)) {
EM_DEBUG_EXCEPTION("emstorage_change_mail_field failed [%d]", err);
goto FINISH_OFF;
}
/* sent mail is moved to 'SENT' box or deleted. */
if (opt->keep_local_copy) {
- if (!emstorage_get_mailbox_by_mailbox_type(account_id, EMAIL_MAILBOX_TYPE_SENTBOX, &local_mailbox, true, &err)) {
+ if (!emstorage_get_mailbox_by_mailbox_type(multi_user_name, account_id, EMAIL_MAILBOX_TYPE_SENTBOX, &local_mailbox, true, &err)) {
EM_DEBUG_EXCEPTION("emstorage_get_mailbox_by_mailbox_type failed [%d]", err);
goto FINISH_OFF;
}
dst_mailbox_id = local_mailbox->mailbox_id;
- if (!emcore_move_mail(&mail_ids[i], 1, dst_mailbox_id, EMAIL_MOVED_AFTER_SENDING, 0, &err))
+ if (!emcore_move_mail(multi_user_name, &mail_ids[i], 1, dst_mailbox_id, EMAIL_MOVED_AFTER_SENDING, 0, &err))
EM_DEBUG_EXCEPTION("emcore_mail_move falied [%d]", err);
if(local_mailbox)
emstorage_free_mailbox(&local_mailbox, 1, NULL);
}
else {
- if (!emcore_delete_mail(account_id, &mail_ids[i], 1, EMAIL_DELETE_LOCALLY, EMAIL_DELETED_AFTER_SENDING, false, &err))
+ if (!emcore_delete_mail(multi_user_name, account_id, &mail_ids[i], 1, EMAIL_DELETE_LOCALLY, EMAIL_DELETED_AFTER_SENDING, false, &err))
EM_DEBUG_EXCEPTION("emcore_delete_mail falied [%d]", err);
}
/* Set the phone log */
- if ((err = emcore_set_sent_contacts_log(searched_mail_tbl_data)) != EMAIL_ERROR_NONE) {
+ if ((err = emcore_set_sent_contacts_log(multi_user_name, searched_mail_tbl_data)) != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("emcore_set_sent_contacts_log failed : [%d]", err);
}
@@ -2290,11 +2380,11 @@ FINISH_OFF:
if (ret == true) {
mail_send_notify(EMAIL_SEND_FINISH, 0, 0, account_id, mail_ids[total], err);
- emcore_show_user_message(account_id, EMAIL_ACTION_SEND_MAIL, err);
+ emcore_show_user_message(multi_user_name, account_id, EMAIL_ACTION_SEND_MAIL, err);
} else {
if(mail_ids) /* prevent 34385 */
mail_send_notify(status, 0, 0, account_id, mail_ids[total], err);
- emcore_show_user_message(account_id, EMAIL_ACTION_SEND_MAIL, err);
+ emcore_show_user_message(multi_user_name, account_id, EMAIL_ACTION_SEND_MAIL, err);
}
EM_SAFE_FREE(mail_ids);
@@ -2305,9 +2395,16 @@ FINISH_OFF:
return ret;
}
-static int emcore_send_mail_smtp(SENDSTREAM *stream, ENVELOPE *env, char *data_file, int account_id, int mail_id, int *err_code)
+static int emcore_send_mail_smtp(char *multi_user_name,
+ SENDSTREAM *stream,
+ ENVELOPE *env,
+ char *data_file,
+ int account_id,
+ int mail_id,
+ int *err_code)
{
- EM_DEBUG_FUNC_BEGIN_SEC("stream[%p], env[%p], data_file[%s], account_id[%d], mail_id[%d], err_code[%p]", stream, env, data_file, account_id, mail_id, err_code);
+ EM_DEBUG_FUNC_BEGIN_SEC("stream[%p], env[%p], data_file[%s], account_id[%d], mail_id[%d], err_code[%p]",
+ stream, env, data_file, account_id, mail_id, err_code);
EM_PROFILE_BEGIN(profile_emcore_send_mail_smtp);
int ret = false;
@@ -2331,7 +2428,7 @@ static int emcore_send_mail_smtp(SENDSTREAM *stream, ENVELOPE *env, char *data_f
goto FINISH_OFF;
}
- if (!(ref_account = emcore_get_account_reference(account_id))) {
+ if (!(ref_account = emcore_get_account_reference(multi_user_name, account_id, false))) {
EM_DEBUG_EXCEPTION("emcore_get_account_reference failed [%d]", account_id);
err = EMAIL_ERROR_INVALID_ACCOUNT;
goto FINISH_OFF;
@@ -2354,9 +2451,12 @@ static int emcore_send_mail_smtp(SENDSTREAM *stream, ENVELOPE *env, char *data_f
if (stream->protocol.esmtp.dsn.ok && stream->protocol.esmtp.dsn.want) {
EM_DEBUG_LOG("stream->protocol.esmtp.dsn.want is required");
- strncat (buf, stream->protocol.esmtp.dsn.full ? " RET=FULL" : " RET=HDRS", sizeof(buf)-EM_SAFE_STRLEN(buf)-1);
+ strncat(buf, stream->protocol.esmtp.dsn.full ? " RET=FULL" : " RET=HDRS",
+ sizeof(buf)-EM_SAFE_STRLEN(buf)-1);
+
if (stream->protocol.esmtp.dsn.envid)
- SNPRINTF (buf + EM_SAFE_STRLEN (buf), sizeof(buf)-(EM_SAFE_STRLEN(buf)), " ENVID=%.100s", stream->protocol.esmtp.dsn.envid);
+ SNPRINTF (buf + EM_SAFE_STRLEN (buf), sizeof(buf)-(EM_SAFE_STRLEN(buf)),
+ " ENVID=%.100s", stream->protocol.esmtp.dsn.envid);
}
else
EM_DEBUG_LOG("stream->protocol.esmtp.dsn.want is not required or DSN is not supported");
@@ -2434,7 +2534,6 @@ static int emcore_send_mail_smtp(SENDSTREAM *stream, ENVELOPE *env, char *data_f
recipients++;
}
-
if (send_err) {
EM_DEBUG_EXCEPTION("One or more recipients failed...");
err = EMAIL_ERROR_INVALID_ADDRESS;
@@ -2476,9 +2575,7 @@ static int emcore_send_mail_smtp(SENDSTREAM *stream, ENVELOPE *env, char *data_f
}
EM_PROFILE_END(profile_open_file);
-
#ifdef __FEATURE_SEND_OPTMIZATION__
- {
char *data = NULL;
int read_size, allocSize, dataSize, gMaxAllocSize = 40960; /* 40KB */
int total_fixed = 0;
@@ -2505,15 +2602,15 @@ static int emcore_send_mail_smtp(SENDSTREAM *stream, ENVELOPE *env, char *data_f
}
while (total) {
-#if 0
/* Cancel the sending event */
if (!emcore_check_send_mail_thread_status()) {
+ EM_SAFE_FREE(data);
EM_DEBUG_EXCEPTION(" emcore_check_send_mail_thread_status failed...");
err = EMAIL_ERROR_CANCELLED;
goto FINISH_OFF;
}
-#endif
- if (total < allocSize)
+
+ if (total < allocSize)
dataSize = total;
else
dataSize = allocSize;
@@ -2546,7 +2643,8 @@ static int emcore_send_mail_smtp(SENDSTREAM *stream, ENVELOPE *env, char *data_f
emcore_update_notification_for_send(account_id, mail_id, progress);
}
- EM_DEBUG_LOG("Sent data Successfully. sent[%d] total[%d]", sent, total);
+ EM_DEBUG_LOG("Sent data Successfully. sent[%d] total[%d] datasize[%d]",
+ sent, total, dataSize);
}
total -= dataSize;
}
@@ -2577,13 +2675,13 @@ static int emcore_send_mail_smtp(SENDSTREAM *stream, ENVELOPE *env, char *data_f
}
}
-#endif
if (!send_ret) {
EM_DEBUG_EXCEPTION("smtp_soutr failed - %ld", send_ret);
err = EMAIL_ERROR_SMTP_SEND_FAILURE;
goto FINISH_OFF;
}
}
+#endif
send_ret = smtp_send(stream, ".", 0);
EM_DEBUG_LOG("[SMTP] . --------> %s", stream->reply);
@@ -2596,6 +2694,7 @@ static int emcore_send_mail_smtp(SENDSTREAM *stream, ENVELOPE *env, char *data_f
ret = true;
FINISH_OFF:
+
if (ret == false)
smtp_send(stream, "RSET", 0);
@@ -2805,7 +2904,7 @@ static int attach_part (BODY *body, const unsigned char *data, int data_len,
if (strcasecmp(content_sub_type, "IMAGE") == 0) {
part->body.type = TYPEIMAGE;
if ((p = strstr(content_sub_type, "/"))) {
- EM_SAFE_FREE(part->body.subtype);
+ EM_SAFE_FREE(part->body.subtype);
part->body.subtype = EM_SAFE_STRDUP(p+1);
}
}
@@ -3049,7 +3148,7 @@ FINISH_OFF:
return new_part;
}
#ifdef __FEATURE_SUPPORT_REPORT_MAIL__
-static int attach_attachment_to_body(BODY **multipart_body, BODY *text_body, emstorage_attachment_tbl_t *input_attachment_tbl, int input_attachment_tbl_count, int *err_code)
+static int attach_attachment_to_body(char *multi_user_name, BODY **multipart_body, BODY *text_body, emstorage_attachment_tbl_t *input_attachment_tbl, int input_attachment_tbl_count, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("multipart_body[%p], text_body[%p], input_attachment_tbl[%p], input_attachment_tbl_count [%d], err_code[%p]", multipart_body, text_body, input_attachment_tbl, input_attachment_tbl_count, err_code);
@@ -3057,6 +3156,9 @@ static int attach_attachment_to_body(BODY **multipart_body, BODY *text_body, ems
int i = 0;
int error = EMAIL_ERROR_NONE;
BODY *frame_body = NULL;
+ char *prefix_path = NULL;
+ char real_file_path[MAX_PATH] = {0};
+
/* make multipart body(multipart frame_body..) .. that has not content.. */
if (!multipart_body || !text_body || !input_attachment_tbl) {
@@ -3088,14 +3190,27 @@ static int attach_attachment_to_body(BODY **multipart_body, BODY *text_body, ems
char *name = NULL;
struct stat st_buf;
+ if (EM_SAFE_STRLEN(multi_user_name) > 0) {
+ error = emcore_get_container_path(multi_user_name, &prefix_path);
+ if (error != EMAIL_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("emcore_get_container_path failed : [%d]", error);
+ goto FINISH_OFF;
+ }
+ } else {
+ prefix_path = strdup("");
+ }
+
for(i = 0; i < input_attachment_tbl_count; i++) {
temp_attachment_tbl = input_attachment_tbl + i;
EM_DEBUG_LOG("insert files - attachment id[%d]", temp_attachment_tbl->attachment_id);
+ memset(real_file_path, 0x00, sizeof(real_file_path));
+ SNPRINTF(real_file_path, sizeof(real_file_path), "%s%s", prefix_path, temp_attachment_tbl->attachment_path);
+
if (stat(temp_attachment_tbl->attachment_path, &st_buf) == 0) {
if (!temp_attachment_tbl->attachment_name) {
- if (!emcore_get_file_name(temp_attachment_tbl->attachment_path, &name, &error)) {
+ if (!emcore_get_file_name(real_file_path, &name, &error)) {
EM_DEBUG_EXCEPTION("emcore_get_file_name failed [%d]", error);
goto FINISH_OFF;
}
@@ -3103,7 +3218,7 @@ static int attach_attachment_to_body(BODY **multipart_body, BODY *text_body, ems
else
name = temp_attachment_tbl->attachment_name;
- if (!attach_part(frame_body, (unsigned char *)temp_attachment_tbl->attachment_path, 0, name, NULL, false, &error)) {
+ if (!attach_part(frame_body, (unsigned char *)real_file_path, 0, name, NULL, false, &error)) {
EM_DEBUG_EXCEPTION("attach_part failed [%d]", error);
goto FINISH_OFF;
}
@@ -3113,6 +3228,9 @@ static int attach_attachment_to_body(BODY **multipart_body, BODY *text_body, ems
ret = true;
FINISH_OFF:
+
+ EM_SAFE_FREE(prefix_path);
+
if (ret == true)
*multipart_body = frame_body;
else if (frame_body != NULL)
@@ -3140,10 +3258,8 @@ static char *emcore_encode_rfc2047_text(char *utf8_text, int *err_code)
if (len > 0) {
-#ifdef __FEATURE_USE_GMIME__
return emcore_gmime_get_encoding_to_utf8(utf8_text);
// return g_strdup(utf8_text); /* emoji handle */
-#endif /* __FEATURE_USE_GMIME__ */
}
else
return strdup("");
@@ -3166,7 +3282,7 @@ static void emcore_encode_rfc2047_address(ADDRESS *address, int *err_code)
#define DATE_STR_LENGTH 100
-static int emcore_make_envelope_from_mail(emstorage_mail_tbl_t *input_mail_tbl_data, ENVELOPE **output_envelope)
+static int emcore_make_envelope_from_mail(char *multi_user_name, emstorage_mail_tbl_t *input_mail_tbl_data, ENVELOPE **output_envelope)
{
EM_DEBUG_FUNC_BEGIN("input_mail_tbl_data[%p], output_envelope[%p]", input_mail_tbl_data, output_envelope);
@@ -3198,7 +3314,7 @@ static int emcore_make_envelope_from_mail(emstorage_mail_tbl_t *input_mail_tbl_d
is_incomplete = input_mail_tbl_data->flags_draft_field || (input_mail_tbl_data->save_status == EMAIL_MAIL_STATUS_SENDING);
if (is_incomplete && (input_mail_tbl_data->account_id > 0)) {
- ref_account = emcore_get_account_reference(input_mail_tbl_data->account_id);
+ ref_account = emcore_get_account_reference(multi_user_name, input_mail_tbl_data->account_id, false);
if (!ref_account) {
EM_DEBUG_EXCEPTION("emcore_get_account_reference failed [%d]", input_mail_tbl_data->account_id);
error = EMAIL_ERROR_INVALID_ACCOUNT;
@@ -3351,8 +3467,9 @@ static int emcore_make_envelope_from_mail(emstorage_mail_tbl_t *input_mail_tbl_d
emcore_encode_rfc2047_address(envelope->cc, &error);
emcore_encode_rfc2047_address(envelope->bcc, &error);
- if (input_mail_tbl_data->subject)
+ if (input_mail_tbl_data->subject) {
envelope->subject = emcore_encode_rfc2047_text(input_mail_tbl_data->subject, &error);
+ }
char rfc822_date_string[DATE_STR_LENGTH] = { 0, };
rfc822_date(rfc822_date_string);
@@ -3491,7 +3608,7 @@ static char *emcore_get_digest_string(int digest_type, int mime_type)
/* input_mail_tbl_data : */
/* is_draft : this mail is draft mail. */
/* file_path : path of file that rfc822 data will be written to. */
-INTERNAL_FUNC int emcore_make_rfc822_file_from_mail(emstorage_mail_tbl_t *input_mail_tbl_data, emstorage_attachment_tbl_t *input_attachment_tbl, int input_attachment_count, ENVELOPE **env, char **file_path, email_option_t *sending_option, int *err_code)
+INTERNAL_FUNC int emcore_make_rfc822_file_from_mail(char *multi_user_name, emstorage_mail_tbl_t *input_mail_tbl_data, emstorage_attachment_tbl_t *input_attachment_tbl, int input_attachment_count, ENVELOPE **env, char **file_path, email_option_t *sending_option, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("input_mail_tbl_data[%p], env[%p], file_path[%p], sending_option[%p], err_code[%p]", input_mail_tbl_data, env, file_path, sending_option, err_code);
@@ -3508,6 +3625,9 @@ INTERNAL_FUNC int emcore_make_rfc822_file_from_mail(emstorage_mail_tbl_t *input_
PART *part_for_related = NULL;
PARAMETER *param = NULL;
+ char *prefix_path = NULL;
+ char real_file_path[MAX_PATH] = {0};
+
if (!input_mail_tbl_data) {
EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
error = EMAIL_ERROR_INVALID_PARAM;
@@ -3520,7 +3640,7 @@ INTERNAL_FUNC int emcore_make_rfc822_file_from_mail(emstorage_mail_tbl_t *input_
goto FINISH_OFF;
}
- if ( (error = emcore_make_envelope_from_mail(input_mail_tbl_data, &envelope)) != EMAIL_ERROR_NONE) {
+ if ( (error = emcore_make_envelope_from_mail(multi_user_name, input_mail_tbl_data, &envelope)) != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("emcore_make_envelope_from_mail failed [%d]", error);
goto FINISH_OFF;
}
@@ -3544,6 +3664,16 @@ INTERNAL_FUNC int emcore_make_rfc822_file_from_mail(emstorage_mail_tbl_t *input_
goto FINISH_OFF;
}
+ if (EM_SAFE_STRLEN(multi_user_name) > 0) {
+ error = emcore_get_container_path(multi_user_name, &prefix_path);
+ if (error != EMAIL_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("emcore_get_container_path failed : [%d]", error);
+ goto FINISH_OFF;
+ }
+ } else {
+ prefix_path = strdup("");
+ }
+
if (input_attachment_count > 0) {
/* handle the Multipart/mixed, Multipart/related and S/MIME */
EM_DEBUG_LOG("input_attachment_num [%d]", input_attachment_count);
@@ -3636,9 +3766,12 @@ INTERNAL_FUNC int emcore_make_rfc822_file_from_mail(emstorage_mail_tbl_t *input_
if (strlen(input_mail_tbl_data->file_path_plain) > 0) {
EM_DEBUG_LOG_SEC("file_path_plain[%s]", input_mail_tbl_data->file_path_plain);
+
+ memset(real_file_path, 0x00, sizeof(real_file_path));
+ SNPRINTF(real_file_path, sizeof(real_file_path), "%s%s", prefix_path, input_mail_tbl_data->file_path_plain);
text_body = &(part_for_alternative->body);
- if (!attach_part(text_body, (unsigned char *)input_mail_tbl_data->file_path_plain, 0, NULL, "plain", false, &error)) {
+ if (!attach_part(text_body, (unsigned char *)real_file_path, 0, NULL, "plain", false, &error)) {
EM_DEBUG_EXCEPTION("attach_part failed [%d]", error);
goto FINISH_OFF;
}
@@ -3647,8 +3780,11 @@ INTERNAL_FUNC int emcore_make_rfc822_file_from_mail(emstorage_mail_tbl_t *input_
if (strlen(input_mail_tbl_data->file_path_html) > 0) {
EM_DEBUG_LOG_SEC("file_path_html[%s]", input_mail_tbl_data->file_path_html);
+ memset(real_file_path, 0x00, sizeof(real_file_path));
+ SNPRINTF(real_file_path, sizeof(real_file_path), "%s%s", prefix_path, input_mail_tbl_data->file_path_html);
+
html_body = &(part_for_alternative->body);
- if (!attach_part (html_body, (unsigned char *)input_mail_tbl_data->file_path_html, 0, NULL, "html", false, &error)) {
+ if (!attach_part (html_body, (unsigned char *)real_file_path, 0, NULL, "html", false, &error)) {
EM_DEBUG_EXCEPTION("attach_part failed [%d]", error);
goto FINISH_OFF;
}
@@ -3658,8 +3794,11 @@ INTERNAL_FUNC int emcore_make_rfc822_file_from_mail(emstorage_mail_tbl_t *input_
(input_mail_tbl_data->file_path_plain || input_mail_tbl_data->file_path_html)) {
if (input_mail_tbl_data->file_path_plain && EM_SAFE_STRLEN(input_mail_tbl_data->file_path_plain) > 0) {
EM_DEBUG_LOG_SEC("file_path_plain[%s]", input_mail_tbl_data->file_path_plain);
- if (!attach_part (root_body, (unsigned char *) input_mail_tbl_data->file_path_plain, 0,
- NULL, "plain", false, &error)) {
+
+ memset(real_file_path, 0x00, sizeof(real_file_path));
+ SNPRINTF(real_file_path, sizeof(real_file_path), "%s%s", prefix_path, input_mail_tbl_data->file_path_plain);
+
+ if (!attach_part (root_body, (unsigned char *)real_file_path, 0, NULL, "plain", false, &error)) {
EM_DEBUG_EXCEPTION("attach_part failed [%d]", error);
goto FINISH_OFF;
}
@@ -3667,7 +3806,8 @@ INTERNAL_FUNC int emcore_make_rfc822_file_from_mail(emstorage_mail_tbl_t *input_
if (input_mail_tbl_data->file_path_html && EM_SAFE_STRLEN(input_mail_tbl_data->file_path_html) > 0) {
EM_DEBUG_LOG_SEC("file_path_html[%s]", input_mail_tbl_data->file_path_html);
- if (input_mail_tbl_data->inline_content_count > 0 && (strcasecmp(root_body->subtype, "RELATED") != 0)) {
+ if (input_mail_tbl_data->inline_content_count > 0 &&
+ (root_body->subtype && (strcasecmp(root_body->subtype, "RELATED") != 0))) {
part_for_related = attach_multipart_with_sub_type(root_body, "RELATED", &error);
if (!part_for_related) {
EM_DEBUG_EXCEPTION("attach_multipart_with_sub_type [related] failed [%d]", error);
@@ -3675,15 +3815,18 @@ INTERNAL_FUNC int emcore_make_rfc822_file_from_mail(emstorage_mail_tbl_t *input_
}
}
+ memset(real_file_path, 0x00, sizeof(real_file_path));
+ SNPRINTF(real_file_path, sizeof(real_file_path), "%s%s", prefix_path, input_mail_tbl_data->file_path_html);
+
if (part_for_related) {
- if (!attach_part(&(part_for_related->body), (unsigned char *)input_mail_tbl_data->file_path_html, 0,
- NULL, "html", false, &error)) {
+ if (!attach_part(&(part_for_related->body), (unsigned char *)real_file_path, 0,
+ NULL, "html", false, &error)) {
EM_DEBUG_EXCEPTION("attach_part failed [%d]", error);
goto FINISH_OFF;
}
} else {
- if (!attach_part (root_body, (unsigned char *)input_mail_tbl_data->file_path_html, 0,
- NULL, "html", false, &error)) {
+ if (!attach_part (root_body, (unsigned char *)real_file_path, 0,
+ NULL, "html", false, &error)) {
EM_DEBUG_EXCEPTION("attach_part failed [%d]", error);
goto FINISH_OFF;
}
@@ -3692,6 +3835,10 @@ INTERNAL_FUNC int emcore_make_rfc822_file_from_mail(emstorage_mail_tbl_t *input_
} else if (input_mail_tbl_data->smime_type == EMAIL_SMIME_SIGNED || input_mail_tbl_data->smime_type == EMAIL_PGP_SIGNED) {
if (input_mail_tbl_data->file_path_mime_entity && EM_SAFE_STRLEN(input_mail_tbl_data->file_path_mime_entity) > 0) {
EM_DEBUG_LOG_SEC("file_path_mime_entity[%s]", input_mail_tbl_data->file_path_mime_entity);
+
+ memset(real_file_path, 0x00, sizeof(real_file_path));
+ SNPRINTF(real_file_path, sizeof(real_file_path), "%s%s", prefix_path, input_mail_tbl_data->file_path_mime_entity);
+
root_body->sparep = EM_SAFE_STRDUP(input_mail_tbl_data->file_path_mime_entity);
}
} else if (input_mail_tbl_data->smime_type == EMAIL_PGP_ENCRYPTED || input_mail_tbl_data->smime_type == EMAIL_PGP_SIGNED_AND_ENCRYPTED) {
@@ -3732,12 +3879,15 @@ INTERNAL_FUNC int emcore_make_rfc822_file_from_mail(emstorage_mail_tbl_t *input_
else
body_to_attach = root_body;
+ memset(real_file_path, 0x00, sizeof(real_file_path));
+ SNPRINTF(real_file_path, sizeof(real_file_path), "%s%s", prefix_path, temp_attachment_tbl->attachment_path);
+
if (!attach_part(body_to_attach,
- (unsigned char *)temp_attachment_tbl->attachment_path,
- 0,
- name,
- temp_attachment_tbl->attachment_mime_type,
- temp_attachment_tbl->attachment_inline_content_status,
+ (unsigned char *)real_file_path,
+ 0,
+ name,
+ temp_attachment_tbl->attachment_mime_type,
+ temp_attachment_tbl->attachment_inline_content_status,
&error))
{
EM_DEBUG_EXCEPTION("attach_part failed [%d]", error);
@@ -3763,7 +3913,10 @@ INTERNAL_FUNC int emcore_make_rfc822_file_from_mail(emstorage_mail_tbl_t *input_
if (strlen(input_mail_tbl_data->file_path_plain) > 0) {
EM_DEBUG_LOG_SEC("file_path_plain[%s]", input_mail_tbl_data->file_path_plain);
- if (!attach_part(root_body, (unsigned char *)input_mail_tbl_data->file_path_plain, 0, NULL, "plain", false, &error)) {
+ memset(real_file_path, 0x00, sizeof(real_file_path));
+ SNPRINTF(real_file_path, sizeof(real_file_path), "%s%s", prefix_path, input_mail_tbl_data->file_path_plain);
+
+ if (!attach_part(root_body, (unsigned char *)real_file_path, 0, NULL, "plain", false, &error)) {
EM_DEBUG_EXCEPTION("attach_part failed [%d]", error);
goto FINISH_OFF;
}
@@ -3772,7 +3925,10 @@ INTERNAL_FUNC int emcore_make_rfc822_file_from_mail(emstorage_mail_tbl_t *input_
if (strlen(input_mail_tbl_data->file_path_html) > 0) {
EM_DEBUG_LOG_SEC("file_path_html[%s]", input_mail_tbl_data->file_path_html);
- if (!attach_part (root_body, (unsigned char *)input_mail_tbl_data->file_path_html, 0, NULL, "html", false, &error)) {
+ memset(real_file_path, 0x00, sizeof(real_file_path));
+ SNPRINTF(real_file_path, sizeof(real_file_path), "%s%s", prefix_path, input_mail_tbl_data->file_path_html);
+
+ if (!attach_part (root_body, (unsigned char *)real_file_path, 0, NULL, "html", false, &error)) {
EM_DEBUG_EXCEPTION("attach_part failed [%d]", error);
goto FINISH_OFF;
}
@@ -3781,8 +3937,17 @@ INTERNAL_FUNC int emcore_make_rfc822_file_from_mail(emstorage_mail_tbl_t *input_
else {
root_body->type = TYPETEXT;
root_body->encoding = ENC8BIT;
- if (input_mail_tbl_data->file_path_plain || input_mail_tbl_data->file_path_html)
- root_body->sparep = EM_SAFE_STRDUP(input_mail_tbl_data->file_path_plain ? input_mail_tbl_data->file_path_plain : input_mail_tbl_data->file_path_html);
+ if (input_mail_tbl_data->file_path_plain || input_mail_tbl_data->file_path_html) {
+ if (input_mail_tbl_data->file_path_plain) {
+ memset(real_file_path, 0x00, sizeof(real_file_path));
+ SNPRINTF(real_file_path, sizeof(real_file_path), "%s%s", prefix_path, input_mail_tbl_data->file_path_plain);
+ } else {
+ memset(real_file_path, 0x00, sizeof(real_file_path));
+ SNPRINTF(real_file_path, sizeof(real_file_path), "%s%s", prefix_path, input_mail_tbl_data->file_path_html);
+ }
+
+ root_body->sparep = EM_SAFE_STRDUP(real_file_path);
+ }
else
root_body->sparep = NULL;
@@ -3826,6 +3991,7 @@ FINISH_OFF:
mail_free_body(&root_body);
EM_SAFE_FREE(digest_string);
+ EM_SAFE_FREE(prefix_path);
if (err_code != NULL)
*err_code = error;
@@ -3834,7 +4000,7 @@ FINISH_OFF:
return ret;
}
-INTERNAL_FUNC int emcore_make_rfc822_file(email_mail_data_t *input_mail_tbl_data, email_attachment_data_t *input_attachment_tbl, int input_attachment_count, int mime_entity_status, char **file_path, int *err_code)
+INTERNAL_FUNC int emcore_make_rfc822_file(char *multi_user_name, email_mail_data_t *input_mail_tbl_data, email_attachment_data_t *input_attachment_tbl, int input_attachment_count, int mime_entity_status, char **file_path, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("input_mail_tbl_data[%p], file_path[%p], err_code[%p]", input_mail_tbl_data, file_path, err_code);
@@ -3887,9 +4053,9 @@ INTERNAL_FUNC int emcore_make_rfc822_file(email_mail_data_t *input_mail_tbl_data
}
modified_mail_data->attachment_count = attachment_count;
- modified_mail_data->inline_content_count = inline_content_count;
-
- if (!emcore_make_rfc822_file_from_mail(modified_mail_data, modified_attachment_data, input_attachment_count, NULL, file_path, NULL, &err)) {
+ modified_mail_data->inline_content_count = inline_content_count;
+
+ if (!emcore_make_rfc822_file_from_mail(multi_user_name, modified_mail_data, modified_attachment_data, input_attachment_count, NULL, file_path, NULL, &err)) {
EM_DEBUG_EXCEPTION("emcore_make_rfc822_file_from_mail failed [%d]", err);
goto FINISH_OFF;
}
@@ -3912,7 +4078,7 @@ FINISH_OFF:
}
#ifdef __FEATURE_SUPPORT_REPORT_MAIL__
-static int emcore_get_report_mail_body(ENVELOPE *envelope, BODY **multipart_body, int *err_code)
+static int emcore_get_report_mail_body(char *multi_user_name, ENVELOPE *envelope, BODY **multipart_body, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("envelope[%p], mulitpart_body[%p], err_code[%p]", envelope, multipart_body, err_code);
@@ -4021,7 +4187,7 @@ static int emcore_get_report_mail_body(ENVELOPE *envelope, BODY **multipart_body
goto FINISH_OFF;
}
- if (!attach_attachment_to_body(&m_body, text_body, temp_attachment_tbl, 1, &err)) {
+ if (!attach_attachment_to_body(multi_user_name, &m_body, text_body, temp_attachment_tbl, 1, &err)) {
EM_DEBUG_EXCEPTION(" attach_attachment_to_body failed [%d]", err);
goto FINISH_OFF;
}
@@ -4137,7 +4303,7 @@ FINISH_OFF:
return ret;
}
-static int emcore_copy_attachment_from_original_mail(int input_original_mail_id, int input_target_mail_id)
+static int emcore_copy_attachment_from_original_mail(char *multi_user_name, int input_original_mail_id, int input_target_mail_id)
{
EM_DEBUG_FUNC_BEGIN("input_original_mail_id[%d] input_target_mail_id[%d]", input_original_mail_id, input_target_mail_id);
int err = EMAIL_ERROR_NONE;
@@ -4147,16 +4313,17 @@ static int emcore_copy_attachment_from_original_mail(int input_original_mail_id,
int attachment_id = 0;
char output_file_name[MAX_PATH] = { 0, };
char output_file_path[MAX_PATH] = { 0, };
+ char virtual_file_path[MAX_PATH] = { 0, };
emstorage_attachment_tbl_t *original_mail_attachment_array = NULL;
emstorage_attachment_tbl_t *target_mail_attachment_array = NULL;
emstorage_attachment_tbl_t *target_attach = NULL;
- if((err = emstorage_get_attachment_list(input_original_mail_id, false, &original_mail_attachment_array, &original_mail_attachment_count)) != EMAIL_ERROR_NONE) {
+ if((err = emstorage_get_attachment_list(multi_user_name, input_original_mail_id, false, &original_mail_attachment_array, &original_mail_attachment_count)) != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("emstorage_get_attachment_list failed [%d]", err);
goto FINISH_OFF;
}
- if((err = emstorage_get_attachment_list(input_target_mail_id, false, &target_mail_attachment_array, &target_mail_attachment_count)) != EMAIL_ERROR_NONE) {
+ if((err = emstorage_get_attachment_list(multi_user_name, input_target_mail_id, false, &target_mail_attachment_array, &target_mail_attachment_count)) != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("emstorage_get_attachment_list failed [%d]", err);
goto FINISH_OFF;
}
@@ -4174,19 +4341,28 @@ static int emcore_copy_attachment_from_original_mail(int input_original_mail_id,
EM_DEBUG_LOG("attachment_inline_content_status [%d] attachment_id[%d]", target_attach->attachment_inline_content_status, attachment_id);
- if(!emcore_save_mail_file(target_attach->account_id, target_attach->mail_id, attachment_id, original_mail_attachment_array[i].attachment_path, original_mail_attachment_array[i].attachment_name, output_file_path, sizeof(output_file_path), &err)) {
+ if(!emcore_save_mail_file(multi_user_name,
+ target_attach->account_id,
+ target_attach->mail_id,
+ attachment_id,
+ original_mail_attachment_array[i].attachment_path,
+ original_mail_attachment_array[i].attachment_name,
+ output_file_path,
+ virtual_file_path,
+ &err)) {
EM_DEBUG_EXCEPTION("emcore_save_mail_file failed [%d]", err);
goto FINISH_OFF;
}
EM_SAFE_FREE(target_attach->attachment_path);
- target_attach->attachment_path = EM_SAFE_STRDUP(output_file_path);
+ target_attach->attachment_path = EM_SAFE_STRDUP(virtual_file_path);
target_attach->attachment_save_status = 1;
- if(!emstorage_update_attachment(target_attach, false, &err)) {
+ if(!emstorage_update_attachment(multi_user_name, target_attach, false, &err)) {
EM_DEBUG_EXCEPTION("emstorage_update_attachment failed [%d]", err);
goto FINISH_OFF;
}
+
memset(output_file_path, 0, MAX_PATH);
memset(output_file_name, 0, MAX_PATH);
break;
@@ -4206,7 +4382,7 @@ FINISH_OFF:
}
/* send a mail */
-INTERNAL_FUNC int emcore_send_mail_with_downloading_attachment_of_original_mail(int input_mail_id)
+INTERNAL_FUNC int emcore_send_mail_with_downloading_attachment_of_original_mail(char *multi_user_name, int input_mail_id)
{
EM_DEBUG_FUNC_BEGIN("input_mail_id[%d]", input_mail_id);
int err = EMAIL_ERROR_NONE;
@@ -4217,7 +4393,7 @@ INTERNAL_FUNC int emcore_send_mail_with_downloading_attachment_of_original_mail(
email_attachment_data_t *attachment_array = NULL;
/* Get mail data */
- if((err = emcore_get_mail_data(input_mail_id, &mail_to_be_sent)) != EMAIL_ERROR_NONE) {
+ if((err = emcore_get_mail_data(multi_user_name, input_mail_id, &mail_to_be_sent)) != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("emcore_get_mail_data failed [%d]", err);
goto FINISH_OFF;
}
@@ -4229,13 +4405,13 @@ INTERNAL_FUNC int emcore_send_mail_with_downloading_attachment_of_original_mail(
}
/* Get original mail data */
- if((err = emcore_get_mail_data(mail_to_be_sent->reference_mail_id, &original_mail)) != EMAIL_ERROR_NONE) {
+ if((err = emcore_get_mail_data(multi_user_name, mail_to_be_sent->reference_mail_id, &original_mail)) != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("emcore_get_mail_data failed [%d]", err);
goto FINISH_OFF;
}
/* Check necessity of download */
- if((err = emcore_get_attachment_data_list(original_mail->mail_id, &attachment_array, &attachment_count)) != EMAIL_ERROR_NONE) {
+ if((err = emcore_get_attachment_data_list(multi_user_name, original_mail->mail_id, &attachment_array, &attachment_count)) != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("emcore_get_attachment_data_list failed [%d]", err);
goto FINISH_OFF;
}
@@ -4245,28 +4421,21 @@ INTERNAL_FUNC int emcore_send_mail_with_downloading_attachment_of_original_mail(
if(attachment_array[i].save_status != 1) {
/* this function is not run by event thread,
so cancellable should be set to 0*/
-#ifdef __FEATURE_USE_GMIME__
- if(!emcore_gmime_download_attachment (original_mail->mail_id, i + 1, 0, -1, 0, &err)) {
- EM_DEBUG_EXCEPTION("emcore_download_attachment failed [%d]", err);
+ if(!emcore_gmime_download_attachment(multi_user_name, original_mail->mail_id, i + 1, 0, -1, 0, &err)) {
+ EM_DEBUG_EXCEPTION("emcore_gmime_download_attachment failed [%d]", err);
goto FINISH_OFF;
}
-#else
- if(!emcore_download_attachment (original_mail->account_id, original_mail->mail_id, i + 1, 0, -1, &err)) {
- EM_DEBUG_EXCEPTION("emcore_download_attachment failed [%d]", err);
- goto FINISH_OFF;
- }
-#endif
}
}
/* Copy attachment to the mail to be sent */
- if((err = emcore_copy_attachment_from_original_mail(original_mail->mail_id, mail_to_be_sent->mail_id)) != EMAIL_ERROR_NONE) {
- EM_DEBUG_EXCEPTION("emcore_download_attachment failed [%d]", err);
+ if((err = emcore_copy_attachment_from_original_mail(multi_user_name, original_mail->mail_id, mail_to_be_sent->mail_id)) != EMAIL_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("emcore_copy_attachment_from_original failed [%d]", err);
goto FINISH_OFF;
}
/* Send the mail */
- if(!emcore_send_mail(mail_to_be_sent->mail_id, &err)) {
+ if(!emcore_send_mail(multi_user_name, mail_to_be_sent->mail_id, &err)) {
EM_DEBUG_EXCEPTION("emcore_send_mail failed [%d]", err);
goto FINISH_OFF;
}
@@ -4297,6 +4466,7 @@ static int emcore_sending_alarm_cb(email_alarm_data_t *alarm_data, void *user_pa
EM_DEBUG_FUNC_BEGIN("alarm_data [%p] user_parameter [%p]", alarm_data, user_parameter);
int err = EMAIL_ERROR_NONE;
int ret = 0;
+ char *multi_user_name = (char *)user_parameter;
if (alarm_data == NULL) {
EM_DEBUG_EXCEPTION("Invalid parameter");
@@ -4304,7 +4474,7 @@ static int emcore_sending_alarm_cb(email_alarm_data_t *alarm_data, void *user_pa
}
/* send mail here */
- if(!emcore_send_mail(alarm_data->reference_id, &err)) {
+ if(!emcore_send_mail(multi_user_name, alarm_data->reference_id, &err)) {
EM_DEBUG_EXCEPTION("emcore_send_mail failed [%d]", ret);
goto FINISH_OFF;
}
@@ -4316,38 +4486,39 @@ FINISH_OFF:
}
-INTERNAL_FUNC int emcore_schedule_sending_mail(int input_mail_id, time_t input_time_to_send)
+INTERNAL_FUNC int emcore_schedule_sending_mail(char *multi_user_name, int input_mail_id, time_t input_time_to_send)
{
EM_DEBUG_FUNC_BEGIN("input_mail_id[%d] input_time_to_send[%d]", input_mail_id, input_time_to_send);
int err = EMAIL_ERROR_NONE;
emstorage_mail_tbl_t *mail_data = NULL;
/* get mail data */
- if (!emstorage_get_mail_by_id(input_mail_id, &mail_data, true, &err) || mail_data == NULL) {
+ if (!emstorage_get_mail_by_id(multi_user_name, input_mail_id, &mail_data, true, &err) || mail_data == NULL) {
EM_DEBUG_EXCEPTION("emstorage_get_mail_by_id failed [%d]", err);
goto FINISH_OFF;
}
/*
- if (!emstorage_set_field_of_mails_with_integer_value(mail_data->account_id, &(mail_data->mail_id), 1, "save_status", EMAIL_MAIL_STATUS_SEND_SCHEDULED, true, &err)) {
+ if (!emstorage_set_field_of_mails_with_integer_value(multi_user_name, mail_data->account_id, &(mail_data->mail_id), 1, "save_status", EMAIL_MAIL_STATUS_SEND_SCHEDULED, true, &err)) {
EM_DEBUG_EXCEPTION("emstorage_set_field_of_mails_with_integer_value failed [%d]", err);
goto FINISH_OFF;
}
*/
- if (!emstorage_set_field_of_mails_with_integer_value(mail_data->account_id, &(mail_data->mail_id), 1, "scheduled_sending_time", input_time_to_send, true, &err)) {
+ if (!emstorage_set_field_of_mails_with_integer_value(multi_user_name, mail_data->account_id, &(mail_data->mail_id), 1, "scheduled_sending_time", input_time_to_send, true, &err)) {
EM_DEBUG_EXCEPTION("emstorage_set_field_of_mails_with_integer_value failed [%d]", err);
goto FINISH_OFF;
}
/* add alarm */
- if ((err = emcore_add_alarm(input_time_to_send, EMAIL_ALARM_CLASS_SCHEDULED_SENDING, input_mail_id, emcore_sending_alarm_cb, NULL)) != EMAIL_ERROR_NONE) {
+ if ((err = emcore_add_alarm(multi_user_name, input_time_to_send, EMAIL_ALARM_CLASS_SCHEDULED_SENDING, input_mail_id, emcore_sending_alarm_cb, NULL)) != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("emcore_add_alarm failed [%d]", err);
goto FINISH_OFF;
}
FINISH_OFF:
- if(mail_data)
+
+ if (mail_data)
emstorage_free_mail(&mail_data, 1, NULL);
EM_DEBUG_FUNC_END("err [%d]", err);
@@ -4370,6 +4541,7 @@ static int emcore_auto_resend_cb(email_alarm_data_t *alarm_data, void *user_para
int sorting_rule_count = 2;
int result_mail_count = 0;
int i = 0;
+ char *multi_user_name = (char *)user_parameter;
/* Get all mails have remaining resend counts in outbox with status 'EMAIL_MAIL_STATUS_SEND_FAILURE or EMAIL_MAIL_STATUS_SEND_WAIT' */
attribute_field_name = emcore_get_mail_field_name_by_attribute_type(EMAIL_MAIL_ATTRIBUTE_REMAINING_RESEND_TIMES);
@@ -4404,14 +4576,14 @@ static int emcore_auto_resend_cb(email_alarm_data_t *alarm_data, void *user_para
sorting_rule_list[1].target_attribute = EMAIL_MAIL_ATTRIBUTE_MAIL_ID;
sorting_rule_list[1].sort_order = EMAIL_SORT_ORDER_ASCEND;
- if( (err = emstorage_write_conditional_clause_for_getting_mail_list(filter_list, filter_rule_count, sorting_rule_list, sorting_rule_count, -1, -1, &conditional_clause_string)) != EMAIL_ERROR_NONE) {
+ if( (err = emstorage_write_conditional_clause_for_getting_mail_list(multi_user_name, filter_list, filter_rule_count, sorting_rule_list, sorting_rule_count, -1, -1, &conditional_clause_string)) != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("emstorage_write_conditional_clause_for_getting_mail_list failed[%d]", err);
goto FINISH_OFF;
}
EM_DEBUG_LOG("conditional_clause_string[%s].", conditional_clause_string);
- if(!emstorage_query_mail_list(conditional_clause_string, true, &result_mail_list, &result_mail_count, &err) && !result_mail_list) {
+ if(!emstorage_query_mail_list(multi_user_name, conditional_clause_string, true, &result_mail_list, &result_mail_count, &err) && !result_mail_list) {
EM_DEBUG_LOG("There is no mails to be sent [%d]", err);
goto FINISH_OFF;
}
@@ -4419,12 +4591,12 @@ static int emcore_auto_resend_cb(email_alarm_data_t *alarm_data, void *user_para
/* Send mails in loop */
for(i = 0; i < result_mail_count; i++) {
- if(!emcore_send_mail(result_mail_list[i].mail_id, &err)) {
+ if(!emcore_send_mail(multi_user_name, result_mail_list[i].mail_id, &err)) {
EM_DEBUG_EXCEPTION("emcore_send_mail failed [%d]", err);
}
if(attribute_field_name) {
- if(!emstorage_set_field_of_mails_with_integer_value(result_mail_list[i].account_id, &(result_mail_list[i].mail_id), 1, attribute_field_name, result_mail_list[i].remaining_resend_times - 1, true, &err)) {
+ if(!emstorage_set_field_of_mails_with_integer_value(multi_user_name, result_mail_list[i].account_id, &(result_mail_list[i].mail_id), 1, attribute_field_name, result_mail_list[i].remaining_resend_times - 1, true, &err)) {
EM_DEBUG_EXCEPTION("emstorage_set_field_of_mails_with_integer_value failed [%d]", err);
}
}
@@ -4438,7 +4610,7 @@ FINISH_OFF:
return err;
}
-INTERNAL_FUNC int emcore_create_alarm_for_auto_resend(int input_alarm_interval_in_second)
+INTERNAL_FUNC int emcore_create_alarm_for_auto_resend(char *multi_user_name, int input_alarm_interval_in_second)
{
EM_DEBUG_FUNC_BEGIN("input_alarm_interval_in_second[%d]", input_alarm_interval_in_second);
int err = EMAIL_ERROR_NONE;
@@ -4496,14 +4668,14 @@ INTERNAL_FUNC int emcore_create_alarm_for_auto_resend(int input_alarm_interval_i
sorting_rule_list[1].target_attribute = EMAIL_MAIL_ATTRIBUTE_MAIL_ID;
sorting_rule_list[1].sort_order = EMAIL_SORT_ORDER_ASCEND;
- if( (err = emstorage_write_conditional_clause_for_getting_mail_list(filter_list, filter_rule_count, sorting_rule_list, sorting_rule_count, -1, -1, &conditional_clause_string)) != EMAIL_ERROR_NONE) {
+ if( (err = emstorage_write_conditional_clause_for_getting_mail_list(multi_user_name, filter_list, filter_rule_count, sorting_rule_list, sorting_rule_count, -1, -1, &conditional_clause_string)) != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("emstorage_write_conditional_clause_for_getting_mail_list failed[%d]", err);
goto FINISH_OFF;
}
EM_DEBUG_LOG("conditional_clause_string[%s].", conditional_clause_string);
- if(!emstorage_query_mail_list(conditional_clause_string, true, &result_mail_list, &result_mail_count, &err) && !result_mail_list) {
+ if(!emstorage_query_mail_list(multi_user_name, conditional_clause_string, true, &result_mail_list, &result_mail_count, &err) && !result_mail_list) {
if (err == EMAIL_ERROR_MAIL_NOT_FOUND)
EM_DEBUG_LOG ("no mail found");
else
@@ -4517,7 +4689,7 @@ INTERNAL_FUNC int emcore_create_alarm_for_auto_resend(int input_alarm_interval_i
trigger_at_time = current_time + input_alarm_interval_in_second;
- if ((err = emcore_add_alarm(trigger_at_time, EMAIL_ALARM_CLASS_AUTO_RESEND, 0, emcore_auto_resend_cb, NULL)) != EMAIL_ERROR_NONE) {
+ if ((err = emcore_add_alarm(multi_user_name, trigger_at_time, EMAIL_ALARM_CLASS_AUTO_RESEND, 0, emcore_auto_resend_cb, NULL)) != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("emcore_add_alarm failed [%d]",err);
goto FINISH_OFF;
}
diff --git a/email-core/email-core-task-manager.c b/email-core/email-core-task-manager.c
index bad8921..bf0e57b 100755
--- a/email-core/email-core-task-manager.c
+++ b/email-core/email-core-task-manager.c
@@ -1,646 +1,678 @@
-/*
-* email-service
-*
-* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
-*
-* Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com>
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*
-*/
-
-/*
- * email-core-task-manager.c
- *
- * Created on: 2012. 11. 1.
- * Author: kyuho.jo@samsung.com
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <pthread.h>
-#include <dbus/dbus.h>
-
-#include "email-internal-types.h"
-#include "email-utilities.h"
-#include "email-core-tasks.h"
-#include "email-core-task-manager.h"
-#include "email-core-signal.h"
-#include "email-core-global.h"
-#include "email-core-utils.h"
-#include "email-debug-log.h"
-
-/* TODO : implement a function for removing a task from task pool */
-/* TODO : after fetching a task from DB, update status of the task. */
-
-
-#define REGISTER_TASK_BINDER(TASK_NAME) emcore_register_task_handler(TASK_NAME, task_handler_##TASK_NAME, email_encode_task_parameter_##TASK_NAME, email_decode_task_parameter_##TASK_NAME)
-
-/*- variables - begin --------------------------------------------------------*/
-static pthread_cond_t _task_available_signal = PTHREAD_COND_INITIALIZER;
-static pthread_mutex_t _task_available_lock = PTHREAD_MUTEX_INITIALIZER;
-static pthread_mutex_t _task_manager_loop_lock = PTHREAD_MUTEX_INITIALIZER;
-static pthread_mutex_t _active_task_pool_lock = PTHREAD_MUTEX_INITIALIZER;
-
-static email_active_task_t _active_task_pool[MAX_ACTIVE_TASK];
-static thread_t _thread_task_manager_loop;
-static int _task_manager_loop_availability = 1;
-/*- variables - end ----------------------------------------------------------*/
-static int emcore_insert_task_to_active_task_pool(int input_task_slot_index, int input_task_id, email_task_type_t input_task_type, thread_t input_thread_id);
-static int emcore_remove_task_from_active_task_pool(int input_task_id);
-static int emcore_find_available_slot_in_active_task_pool(int *result_index);
-static int emcore_update_task_status_on_task_table(int input_task_id, email_task_status_type_t task_status);
-static int emcore_get_task_handler_reference(email_task_type_t input_task_type, email_task_handler_t **output_task_handler);
-
-/*- task handlers helpers - begin --------------------------------------------*/
-static int emcore_initialize_async_task_handler(email_task_t *input_task)
-{
- EM_DEBUG_FUNC_BEGIN("input_task [%p]", input_task);
- int err = EMAIL_ERROR_NONE;
-
- if(input_task == NULL) {
- EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
- err = EMAIL_ERROR_INVALID_PARAM;
- goto FINISH_OFF;
- }
-
- /* insert task to _active_task_pool */
- emcore_insert_task_to_active_task_pool(input_task->active_task_id
- , input_task->task_id
- , input_task->task_type
- , THREAD_SELF());
-
- /* send notification for 'task start */
- if( (err = emcore_send_task_status_signal(input_task->task_type, input_task->task_id, EMAIL_TASK_STATUS_STARTED, EMAIL_ERROR_NONE, 0)) != EMAIL_ERROR_NONE) {
- EM_DEBUG_EXCEPTION("emcore_send_task_status_signal failed [%d]", err);
- goto FINISH_OFF;
- }
-
-FINISH_OFF:
-
- EM_DEBUG_FUNC_END("err [%d]", err);
- return err;
-}
-
-static int emcore_finalize_async_task_handler(email_task_t *input_task, int input_error_code)
-{
- EM_DEBUG_FUNC_BEGIN("input_task [%p] input_error_code [%d]",input_task ,input_error_code);
- int err = EMAIL_ERROR_NONE;
- email_task_status_type_t task_status = EMAIL_TASK_STATUS_FINISHED;
-
- if(input_task == NULL) {
- EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
- err = EMAIL_ERROR_INVALID_PARAM;
- goto FINISH_OFF;
- }
-
- if(input_error_code != EMAIL_ERROR_NONE) {
- task_status = EMAIL_TASK_STATUS_FAILED;
- }
-
- /* remove task from task table */
- if( (err = emcore_remove_task_from_task_table(input_task->task_id)) != EMAIL_ERROR_NONE) {
- EM_DEBUG_EXCEPTION("emcore_remove_task_from_active_task_pool failed [%d]", err);
- goto FINISH_OFF;
- }
-
- /* remove task id from active task id array */
- if( (err = emcore_remove_task_from_active_task_pool(input_task->task_id)) != EMAIL_ERROR_NONE) {
- EM_DEBUG_EXCEPTION("emcore_remove_task_from_active_task_pool failed [%d]", err);
- goto FINISH_OFF;
- }
-
- /* send signal for 'task finish or failure */
- if( (err = emcore_send_task_status_signal(input_task->task_type, input_task->task_id, task_status, input_error_code, 0)) != EMAIL_ERROR_NONE) {
- EM_DEBUG_EXCEPTION("emcore_send_task_status_signal failed [%d]", err);
- goto FINISH_OFF;
- }
-
- ENTER_CRITICAL_SECTION(_task_available_lock);
- WAKE_CONDITION_VARIABLE(_task_available_signal);
- LEAVE_CRITICAL_SECTION(_task_available_lock);
-
-FINISH_OFF:
- EM_DEBUG_FUNC_END("err [%d]", err);
- return err;
-}
-
-INTERNAL_FUNC void* emcore_default_async_task_handler(void *input_param)
-{
- EM_DEBUG_FUNC_BEGIN("intput_param [%p]", input_param);
- int err = EMAIL_ERROR_NONE;
- email_task_t *task = input_param;
- email_task_handler_t *task_handler = NULL;
- void *decoded_task_parameter = NULL;
-
- if((err = emcore_initialize_async_task_handler(task)) != EMAIL_ERROR_NONE) {
- EM_DEBUG_EXCEPTION("emcore_initialize_async_task_handler failed. [%d]", err);
- goto FINISH_OFF;
- }
-
- /* create a thread to do this task */
- if((err = emcore_get_task_handler_reference(task->task_type, &task_handler)) != EMAIL_ERROR_NONE) {
- EM_DEBUG_LOG("emcore_get_task_handler_reference returns [%d]", err);
- }
- else {
- /* Decode parameter */
- emcore_decode_task_parameter(task->task_type, task->task_parameter, task->task_parameter_length, &decoded_task_parameter);
- task_handler->task_handler_function(decoded_task_parameter);
- }
-
-FINISH_OFF:
- emcore_finalize_async_task_handler(task, err);
-
- EM_SAFE_FREE(decoded_task_parameter);
-
- EM_DEBUG_FUNC_END("err [%d]", err);
- return NULL;
-}
-
-INTERNAL_FUNC void* emcore_default_sync_task_handler(void *intput_param)
-{
- EM_DEBUG_FUNC_BEGIN("intput_param [%p]", intput_param);
- int err = EMAIL_ERROR_NONE;
- email_task_t *task = intput_param;
- email_task_handler_t *task_handler = NULL;
- void *decoded_task_parameter = NULL;
-
- /* create a thread to do this task */
- if((err = emcore_get_task_handler_reference(task->task_type, &task_handler)) != EMAIL_ERROR_NONE) {
- EM_DEBUG_LOG("emcore_get_task_handler_reference returns [%d]", err);
- }
- else {
- /* Decode parameter */
- emcore_decode_task_parameter(task->task_type, task->task_parameter, task->task_parameter_length, &decoded_task_parameter);
- err = (int)task_handler->task_handler_function(decoded_task_parameter);
- }
-
- EM_DEBUG_FUNC_END("err [%d]", err);
- return (void*)err;
-}
-/*- task handlers helpers - end --------------------------------------------*/
-
-int _task_handler_array_size;
-email_task_handler_t **_task_handler_array;
-
-static int emcore_register_task_handler(email_task_type_t input_task_type, void* (*input_task_handler)(void *), int (*input_task_parameter_encoder)(void*,char**,int*), int (*input_task_parameter_decoder)(char*,int,void**))
-{
- EM_DEBUG_FUNC_BEGIN("input_task_type [%d] input_task_handler [%p] input_task_parameter_encoder [%p] input_task_parameter_decoder [%p]", input_task_type, input_task_handler, input_task_parameter_encoder, input_task_parameter_decoder);
- int err = EMAIL_ERROR_NONE;
- email_task_handler_t *new_task_handler = NULL;
-
- new_task_handler = malloc(sizeof(email_task_handler_t));
- if (new_task_handler == NULL) {
- err = EMAIL_ERROR_OUT_OF_MEMORY;
- EM_DEBUG_EXCEPTION("EMAIL_ERROR_OUT_OF_MEMORY");
- goto FINISH_OFF;
- }
-
- new_task_handler->task_type = input_task_type;
- new_task_handler->task_handler_function = input_task_handler;
- new_task_handler->task_parameter_encoder = input_task_parameter_encoder;
- new_task_handler->task_parameter_decoder = input_task_parameter_decoder;
-
- _task_handler_array_size++;
-
- if (_task_handler_array) {
- _task_handler_array = realloc(_task_handler_array, sizeof(email_task_handler_t*) * _task_handler_array_size);
- }
- else {
- _task_handler_array = malloc(sizeof(email_task_handler_t*) * _task_handler_array_size);
- }
-
- if (_task_handler_array == NULL) {
- err = EMAIL_ERROR_OUT_OF_MEMORY;
- EM_SAFE_FREE(new_task_handler);
- goto FINISH_OFF;
- }
-
- _task_handler_array[_task_handler_array_size - 1] = new_task_handler;
-
-FINISH_OFF:
-
- EM_DEBUG_FUNC_END("err [%d]", err);
- return err;
-}
-
-INTERNAL_FUNC int emcore_init_task_handler_array()
-{
- EM_DEBUG_FUNC_BEGIN();
-
- if (_task_handler_array == NULL) {
- _task_handler_array = NULL;
- _task_handler_array_size = 0;
-
- REGISTER_TASK_BINDER(EMAIL_ASYNC_TASK_MOVE_MAILS_TO_MAILBOX_OF_ANOTHER_ACCOUNT);
- REGISTER_TASK_BINDER(EMAIL_ASYNC_TASK_DELETE_MAILBOX_EX);
- REGISTER_TASK_BINDER(EMAIL_ASYNC_TASK_SEND_MAIL_WITH_DOWNLOADING_ATTACHMENT_OF_ORIGINAL_MAIL);
- REGISTER_TASK_BINDER(EMAIL_SYNC_TASK_SCHEDULE_SENDING_MAIL);
- REGISTER_TASK_BINDER(EMAIL_SYNC_TASK_UPDATE_ATTRIBUTE);
- }
-
- EM_DEBUG_FUNC_END();
- return EMAIL_ERROR_NONE;
-}
-
-INTERNAL_FUNC int emcore_free_task_handler_array()
-{
- EM_DEBUG_FUNC_BEGIN();
-
- int i = 0;
-
- for(i = 0; i < _task_handler_array_size; i++) {
- EM_SAFE_FREE (_task_handler_array[i]);
- }
-
- EM_SAFE_FREE (_task_handler_array);
- _task_handler_array_size = 0;
-
- EM_DEBUG_FUNC_END();
- return EMAIL_ERROR_NONE;
-}
-
-static int emcore_get_task_handler_reference(email_task_type_t input_task_type, email_task_handler_t **output_task_handler)
-{
- EM_DEBUG_FUNC_BEGIN("input_task_type [%d] output_task_handler [%p]", input_task_type, output_task_handler);
- int i = 0;
- int err = EMAIL_ERROR_NONE;
-
- if (output_task_handler == NULL) {
- EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
- err = EMAIL_ERROR_INVALID_PARAM;
- goto FINISH_OFF;
- }
-
- *output_task_handler = NULL;
- for (i = 0; i < _task_handler_array_size; i++) {
- if (_task_handler_array[i]->task_type == input_task_type) {
- *output_task_handler = _task_handler_array[i];
- break;
- }
- }
-
- if (*output_task_handler == NULL) {
- EM_DEBUG_EXCEPTION("EMAIL_ERROR_TASK_BINDER_NOT_FOUND");
- err = EMAIL_ERROR_TASK_BINDER_NOT_FOUND;
- goto FINISH_OFF;
- }
-
-FINISH_OFF:
- EM_DEBUG_FUNC_END("err [%d]", err);
- return err;
-}
-
-INTERNAL_FUNC int emcore_encode_task_parameter(email_task_type_t input_task_type, void *input_task_parameter_struct, char **output_byte_stream, int *output_stream_size)
-{
- EM_DEBUG_FUNC_BEGIN("input_task_type [%d] input_task_parameter_struct [%p] output_byte_stream [%p] output_stream_size [%p]", input_task_type, input_task_parameter_struct, output_byte_stream, output_stream_size);
- int err = EMAIL_ERROR_NONE;
- email_task_handler_t *task_handler = NULL;
- int (*task_parameter_encoder)(void*, char**, int*);
-
- if (input_task_parameter_struct == NULL || output_byte_stream == NULL || output_stream_size == NULL) {
- EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
- err = EMAIL_ERROR_INVALID_PARAM;
- goto FINISH_OFF;
- }
-
- if ((err = emcore_get_task_handler_reference(input_task_type, &task_handler)) != EMAIL_ERROR_NONE) {
- EM_DEBUG_EXCEPTION("emcore_get_task_handler_reference failed [%d]", err);
- goto FINISH_OFF;
- }
-
- task_parameter_encoder = task_handler->task_parameter_encoder;
-
- if ((err = task_parameter_encoder(input_task_parameter_struct, output_byte_stream, output_stream_size)) != EMAIL_ERROR_NONE) {
- EM_DEBUG_EXCEPTION("task_parameter_encoder failed [%d]", err);
- goto FINISH_OFF;
- }
-
-FINISH_OFF:
- EM_DEBUG_FUNC_END("err [%d]", err);
- return err;
-}
-
-INTERNAL_FUNC int emcore_decode_task_parameter(email_task_type_t input_task_type, char *input_byte_stream, int input_stream_size, void **output_task_parameter_struct)
-{
- EM_DEBUG_FUNC_BEGIN("input_task_type [%d] input_byte_stream [%p] input_stream_size [%d] output_task_parameter_struct [%p]", input_task_type, input_byte_stream, input_stream_size, output_task_parameter_struct);
- int err = EMAIL_ERROR_NONE;
- email_task_handler_t *task_handler = NULL;
- int (*task_parameter_decoder)(char*, int, void**);
-
- if (input_byte_stream == NULL || output_task_parameter_struct == NULL) {
- EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
- err = EMAIL_ERROR_INVALID_PARAM;
- goto FINISH_OFF;
- }
-
- if ((err = emcore_get_task_handler_reference(input_task_type, &task_handler)) != EMAIL_ERROR_NONE) {
- EM_DEBUG_EXCEPTION("emcore_get_task_handler_reference failed [%d]", err);
- goto FINISH_OFF;
- }
-
- task_parameter_decoder = task_handler->task_parameter_decoder;
-
- if ((err = task_parameter_decoder(input_byte_stream, input_stream_size, output_task_parameter_struct)) != EMAIL_ERROR_NONE) {
- EM_DEBUG_EXCEPTION("task_parameter_decoder failed [%d]", err);
- goto FINISH_OFF;
- }
-
-FINISH_OFF:
- EM_DEBUG_FUNC_END("err [%d]", err);
- return err;
-}
-
-int emcore_fetch_task_from_task_pool(email_task_t **output_task)
-{
- EM_DEBUG_FUNC_BEGIN("output_task [%p]", output_task);
- int err = EMAIL_ERROR_NONE;
- int output_task_count;
-
- if((err = emstorage_query_task("WHERE task_status == 1", " ORDER BY date_time ASC, task_priority ASC LIMIT 0, 1", output_task, &output_task_count)) != EMAIL_ERROR_NONE) {
- EM_DEBUG_EXCEPTION("emstorage_query_task failed [%d]", err);
- goto FINISH_OFF;
- }
-
-FINISH_OFF:
-
- EM_DEBUG_FUNC_END("err [%d]", err);
- return err;
-}
-
-
-/*-Task manager loop - begin -------------------------------------------------------------*/
-
-
-static int emcore_insert_task_to_active_task_pool(int input_task_slot_index, int input_task_id, email_task_type_t input_task_type, thread_t input_thread_id)
-{
- EM_DEBUG_FUNC_BEGIN("input_task_slot_index [%d] input_task_id [%d] input_task_type [%d] input_thread_id [%d]", input_task_slot_index, input_task_id, input_task_type, input_thread_id);
- int err = EMAIL_ERROR_NONE;
-
- ENTER_CRITICAL_SECTION(_active_task_pool_lock);
- _active_task_pool[input_task_slot_index].task_id = input_task_id;
- _active_task_pool[input_task_slot_index].task_type = input_task_type;
- _active_task_pool[input_task_slot_index].thread_id = input_thread_id;
- LEAVE_CRITICAL_SECTION(_active_task_pool_lock);
-
- EM_DEBUG_LOG("_active_task_pool[%d].task_id [%d]", input_task_slot_index, _active_task_pool[input_task_slot_index].task_id);
-
- EM_DEBUG_FUNC_END("err [%d]", err);
- return err;
-}
-
-static int emcore_remove_task_from_active_task_pool(int input_task_id)
-{
- EM_DEBUG_FUNC_BEGIN(" input_task_id [%d]", input_task_id);
- int err = EMAIL_ERROR_NONE;
- int i = 0;
-
- ENTER_CRITICAL_SECTION(_active_task_pool_lock);
- for(i = 0; i < MAX_ACTIVE_TASK; i++) {
- if(_active_task_pool[i].task_id == input_task_id) {
- _active_task_pool[i].task_id = 0;
- _active_task_pool[i].task_type = 0;
- _active_task_pool[i].thread_id = 0;
- break;
- }
- }
- LEAVE_CRITICAL_SECTION(_active_task_pool_lock);
-
- if(i >= MAX_ACTIVE_TASK) {
- EM_DEBUG_LOG("couldn't find proper task in active task pool [%d]", input_task_id);
- err = EMAIL_ERROR_TASK_NOT_FOUND;
- }
-
- EM_DEBUG_FUNC_END("err [%d]", err);
- return err;
-}
-
-INTERNAL_FUNC int emcore_get_active_task_by_thread_id(thread_t input_thread_id, email_active_task_t **output_active_task)
-{
- EM_DEBUG_FUNC_BEGIN(" input_thread_id [%d] output_active_task [%p]", input_thread_id, output_active_task);
- int err = EMAIL_ERROR_NONE;
- int i = 0;
-
- if (output_active_task == NULL) {
- EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
- err = EMAIL_ERROR_INVALID_PARAM;
- goto FINISH_OFF;
- }
-
- for(i = 0; i < MAX_ACTIVE_TASK; i++) {
- if(_active_task_pool[i].thread_id == input_thread_id) {
- *output_active_task = _active_task_pool + i;
- break;
- }
- }
-
- if(i >= MAX_ACTIVE_TASK) {
- EM_DEBUG_LOG("couldn't find proper task in active task pool [%d]", input_thread_id);
- err = EMAIL_ERROR_TASK_NOT_FOUND;
- }
-
-FINISH_OFF:
-
- EM_DEBUG_FUNC_END("err [%d]", err);
- return err;
-}
-
-
-static int emcore_find_available_slot_in_active_task_pool(int *result_index)
-{
- EM_DEBUG_FUNC_BEGIN("result_index [%p]", result_index);
- int i = 0;
- int err = EMAIL_ERROR_NONE;
-
- if (result_index == NULL) {
- EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
- err = EMAIL_ERROR_INVALID_PARAM;
- goto FINISH_OFF;
- }
-
- ENTER_CRITICAL_SECTION(_active_task_pool_lock);
- for(i = 0; i < MAX_ACTIVE_TASK; i++) {
- if(_active_task_pool[i].task_id == 0) {
- break;
- }
- }
-
- if(i >= MAX_ACTIVE_TASK) {
- EM_DEBUG_EXCEPTION("There is no available task slot");
- err = EMAIL_NO_AVAILABLE_TASK_SLOT;
- }
- else {
- _active_task_pool[i].task_id = -1;
- *result_index = i;
- }
- LEAVE_CRITICAL_SECTION(_active_task_pool_lock);
-
-FINISH_OFF :
- EM_DEBUG_FUNC_END("err [%d]", err);
- return err;
-}
-
-void* thread_func_task_manager_loop(void *arg)
-{
- EM_DEBUG_FUNC_BEGIN();
- int err = EMAIL_ERROR_NONE;
- int thread_error;
- int available_slot_index = 0;
- email_task_t *new_task = NULL;
-
- /* while loop */
- while (_task_manager_loop_availability) {
- /* fetch task from DB */
- if( ((err = emcore_fetch_task_from_task_pool(&new_task)) == EMAIL_ERROR_NONE) &&
- ((err = emcore_find_available_slot_in_active_task_pool(&available_slot_index)) == EMAIL_ERROR_NONE) ) {
-
- /* update task status as STARTED */
- if((err = emcore_update_task_status_on_task_table(new_task->task_id, EMAIL_TASK_STATUS_STARTED)) != EMAIL_ERROR_NONE) {
- EM_DEBUG_EXCEPTION("emcore_update_task_status_on_task_table failed [%d]", err);
- }
- new_task->active_task_id = available_slot_index;
-
- /* create a thread to do this task */
- THREAD_CREATE(new_task->thread_id, emcore_default_async_task_handler, new_task, thread_error);
- EM_DEBUG_LOG("pthread_create returns [%d]", thread_error);
-
- /* new_task and task_parameter will be free in task handler. */
- EM_SAFE_FREE(new_task->task_parameter);
- EM_SAFE_FREE(new_task);
- }
- else {
- /* If there is no task or no available slot, sleep until someone wake you up. */
- /* Wake up case 1 : by emcore_add_task_to_task_table */
- /* Wake up case 2 : when some task terminated */
- ENTER_CRITICAL_SECTION(_task_available_lock);
- SLEEP_CONDITION_VARIABLE(_task_available_signal, _task_available_lock);
- LEAVE_CRITICAL_SECTION(_task_available_lock);
- EM_DEBUG_LOG("thread_func_task_manager_loop wake up!");
- }
- }
-
- EM_DEBUG_FUNC_END();
- return NULL;
-}
-
-INTERNAL_FUNC int emcore_start_task_manager_loop()
-{
- EM_DEBUG_FUNC_BEGIN();
- int thread_error;
- int err = EMAIL_ERROR_NONE;
-
- memset(&_active_task_pool, 0, sizeof(email_active_task_t) * MAX_ACTIVE_TASK);
-
- if (_thread_task_manager_loop) {
- EM_DEBUG_EXCEPTION("service thread is already running...");
- err = EMAIL_ERROR_ALREADY_INITIALIZED;
- goto FINISH_OFF;
- }
-
- _task_manager_loop_availability = 10;
-
- /* create thread */
- THREAD_CREATE(_thread_task_manager_loop, thread_func_task_manager_loop, NULL, thread_error);
-
- if (thread_error != 0) {
- EM_DEBUG_EXCEPTION("cannot create thread [%d]", thread_error);
- err = EMAIL_ERROR_SYSTEM_FAILURE;
- goto FINISH_OFF;
- }
-
-FINISH_OFF :
- EM_DEBUG_FUNC_END("err [%d]", err);
- return err;
-}
-
-INTERNAL_FUNC int emcore_stop_task_manager_loop()
-{
- EM_DEBUG_FUNC_BEGIN();
-
- int err = EMAIL_ERROR_NONE;
-
- /* TODO : cancel tasks */
-
- /* stop event_data loop */
- _task_manager_loop_availability = 0;
-
- ENTER_CRITICAL_SECTION(_task_manager_loop_lock);
- WAKE_CONDITION_VARIABLE(_task_available_signal);
- LEAVE_CRITICAL_SECTION(_task_manager_loop_lock);
-
- /* wait for thread finished */
- THREAD_JOIN(_thread_task_manager_loop);
-
- _thread_task_manager_loop = 0;
-
- DELETE_CRITICAL_SECTION(_task_manager_loop_lock);
- DELETE_CONDITION_VARIABLE(_task_available_signal);
-
- /* Free _active_task_pool */
-
- //FINISH_OFF :
-
- EM_DEBUG_FUNC_END("err [%d]", err);
- return err;
-}
-
-INTERNAL_FUNC int emcore_add_task_to_task_table(email_task_type_t input_task_type, email_task_priority_t input_task_priority, char *input_task_parameter, int input_task_parameter_length, int *output_task_id)
-{
- EM_DEBUG_FUNC_BEGIN("input_task_type [%d] input_task_priority [%d] input_task_parameter [%p] input_task_parameter_length [%d] output_task_id [%p]", input_task_type, input_task_priority, input_task_parameter, input_task_parameter_length, output_task_id);
- int err = EMAIL_ERROR_NONE;
-
- if((err = emstorage_add_task(input_task_type, input_task_priority, input_task_parameter, input_task_parameter_length, false, output_task_id)) != EMAIL_ERROR_NONE) {
- EM_DEBUG_EXCEPTION("emstorage_add_task failed [%d]", err);
- goto FINISH_OFF;
- }
-
- ENTER_CRITICAL_SECTION(_task_available_lock);
- WAKE_CONDITION_VARIABLE(_task_available_signal);
- LEAVE_CRITICAL_SECTION(_task_available_lock);
-
-FINISH_OFF:
- EM_DEBUG_FUNC_END("err [%d]", err);
- return err;
-}
-
-INTERNAL_FUNC int emcore_remove_task_from_task_table(int input_task_id)
-{
- EM_DEBUG_FUNC_BEGIN("input_task_id [%d]", input_task_id);
- int err = EMAIL_ERROR_NONE;
-
- if((err = emstorage_delete_task(input_task_id, true)) != EMAIL_ERROR_NONE) {
- EM_DEBUG_EXCEPTION("emstorage_delete_task failed [%d]", err);
- goto FINISH_OFF;
- }
-
-FINISH_OFF:
- EM_DEBUG_FUNC_END("err [%d]", err);
- return err;
-}
-
-static int emcore_update_task_status_on_task_table(int input_task_id, email_task_status_type_t task_status)
-{
- EM_DEBUG_FUNC_BEGIN("input_task_id [%d] task_status [%d]", input_task_id, task_status);
- int err = EMAIL_ERROR_NONE;
-
- if((err = emstorage_update_task_status(input_task_id, task_status, true)) != EMAIL_ERROR_NONE) {
- EM_DEBUG_EXCEPTION("emstorage_update_task_status failed [%d]", err);
- goto FINISH_OFF;
- }
-
-FINISH_OFF:
- EM_DEBUG_FUNC_END("err [%d]", err);
- return err;
-}
-
-/*-Task manager loop - end-------------------------------------------------------------*/
+/*
+* email-service
+*
+* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+*
+* Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com>
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*
+*/
+
+/*
+ * email-core-task-manager.c
+ *
+ * Created on: 2012. 11. 1.
+ * Author: kyuho.jo@samsung.com
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <pthread.h>
+#include <dbus/dbus.h>
+
+#include "email-internal-types.h"
+#include "email-utilities.h"
+#include "email-core-tasks.h"
+#include "email-core-task-manager.h"
+#include "email-core-signal.h"
+#include "email-core-global.h"
+#include "email-core-utils.h"
+#include "email-debug-log.h"
+
+/* TODO : implement a function for removing a task from task pool */
+/* TODO : after fetching a task from DB, update status of the task. */
+
+
+#define REGISTER_TASK_BINDER(TASK_NAME) emcore_register_task_handler(TASK_NAME, task_handler_##TASK_NAME, email_encode_task_parameter_##TASK_NAME, email_decode_task_parameter_##TASK_NAME)
+
+/*- variables - begin --------------------------------------------------------*/
+static pthread_cond_t _task_available_signal = PTHREAD_COND_INITIALIZER;
+static pthread_mutex_t _task_available_lock = PTHREAD_MUTEX_INITIALIZER;
+static pthread_mutex_t _task_manager_loop_lock = PTHREAD_MUTEX_INITIALIZER;
+static pthread_mutex_t _active_task_pool_lock = PTHREAD_MUTEX_INITIALIZER;
+
+static email_active_task_t _active_task_pool[MAX_ACTIVE_TASK];
+static thread_t _thread_task_manager_loop;
+static int _task_manager_loop_availability = 1;
+/*- variables - end ----------------------------------------------------------*/
+static int emcore_insert_task_to_active_task_pool(int input_task_slot_index, int input_task_id, email_task_type_t input_task_type, thread_t input_thread_id);
+static int emcore_remove_task_from_active_task_pool(int input_task_id);
+static int emcore_find_available_slot_in_active_task_pool(int *result_index);
+static int emcore_update_task_status_on_task_table(char *multi_user_name, int input_task_id, email_task_status_type_t task_status);
+static int emcore_get_task_handler_reference(email_task_type_t input_task_type, email_task_handler_t **output_task_handler);
+
+/*- task handlers helpers - begin --------------------------------------------*/
+static int emcore_initialize_async_task_handler(email_task_t *input_task)
+{
+ EM_DEBUG_FUNC_BEGIN("input_task [%p]", input_task);
+ int err = EMAIL_ERROR_NONE;
+
+ if(input_task == NULL) {
+ EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
+ err = EMAIL_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ /* insert task to _active_task_pool */
+ emcore_insert_task_to_active_task_pool(input_task->active_task_id
+ , input_task->task_id
+ , input_task->task_type
+ , THREAD_SELF());
+
+ /* send notification for 'task start */
+ if( (err = emcore_send_task_status_signal(input_task->task_type, input_task->task_id, EMAIL_TASK_STATUS_STARTED, EMAIL_ERROR_NONE, 0)) != EMAIL_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("emcore_send_task_status_signal failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+FINISH_OFF:
+
+ EM_DEBUG_FUNC_END("err [%d]", err);
+ return err;
+}
+
+static int emcore_finalize_async_task_handler(email_task_t *input_task, int input_error_code)
+{
+ EM_DEBUG_FUNC_BEGIN("input_task [%p] input_error_code [%d]",input_task ,input_error_code);
+ int err = EMAIL_ERROR_NONE;
+ email_task_status_type_t task_status = EMAIL_TASK_STATUS_FINISHED;
+
+ if(input_task == NULL) {
+ EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
+ err = EMAIL_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ if(input_error_code != EMAIL_ERROR_NONE) {
+ task_status = EMAIL_TASK_STATUS_FAILED;
+ }
+
+ /* remove task from task table */
+ if( (err = emcore_remove_task_from_task_table(NULL, input_task->task_id)) != EMAIL_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("emcore_remove_task_from_active_task_pool failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ /* remove task id from active task id array */
+ if( (err = emcore_remove_task_from_active_task_pool(input_task->task_id)) != EMAIL_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("emcore_remove_task_from_active_task_pool failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ /* send signal for 'task finish or failure */
+ if( (err = emcore_send_task_status_signal(input_task->task_type, input_task->task_id, task_status, input_error_code, 0)) != EMAIL_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("emcore_send_task_status_signal failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ ENTER_CRITICAL_SECTION(_task_available_lock);
+ WAKE_CONDITION_VARIABLE(_task_available_signal);
+ LEAVE_CRITICAL_SECTION(_task_available_lock);
+
+FINISH_OFF:
+ EM_DEBUG_FUNC_END("err [%d]", err);
+ return err;
+}
+
+INTERNAL_FUNC void* emcore_default_async_task_handler(void *input_param)
+{
+ EM_DEBUG_FUNC_BEGIN("intput_param [%p]", input_param);
+ int err = EMAIL_ERROR_NONE;
+ email_task_t *task = input_param;
+ email_task_handler_t *task_handler = NULL;
+ void *decoded_task_parameter = NULL;
+
+ if((err = emcore_initialize_async_task_handler(task)) != EMAIL_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("emcore_initialize_async_task_handler failed. [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ /* create a thread to do this task */
+ if ((err = emcore_get_task_handler_reference(task->task_type, &task_handler)) != EMAIL_ERROR_NONE) {
+ EM_DEBUG_LOG("emcore_get_task_handler_reference returns [%d]", err);
+ }
+ else {
+ /* Decode parameter */
+ emcore_decode_task_parameter(task->task_type,
+ task->task_parameter,
+ task->task_parameter_length,
+ &decoded_task_parameter);
+
+ task_handler->task_handler_function(decoded_task_parameter);
+ }
+
+FINISH_OFF:
+
+ emcore_finalize_async_task_handler(task, err);
+
+ EM_DEBUG_FUNC_END("err [%d]", err);
+ return NULL;
+}
+
+INTERNAL_FUNC int emcore_default_sync_task_handler(void *intput_param)
+{
+ EM_DEBUG_FUNC_BEGIN("intput_param [%p]", intput_param);
+ int err = EMAIL_ERROR_NONE;
+ int *return_err = NULL;
+ email_task_t *task = intput_param;
+ email_task_handler_t *task_handler = NULL;
+ void *decoded_task_parameter = NULL;
+
+ /* create a thread to do this task */
+ if ((err = emcore_get_task_handler_reference(task->task_type, &task_handler)) != EMAIL_ERROR_NONE) {
+ EM_DEBUG_LOG("emcore_get_task_handler_reference returns [%d]", err);
+ } else {
+ /* Decode parameter */
+ emcore_decode_task_parameter(task->task_type,
+ task->task_parameter,
+ task->task_parameter_length,
+ &decoded_task_parameter);
+
+ return_err = (int *)task_handler->task_handler_function(decoded_task_parameter);
+ }
+
+ if (return_err) {
+ err = *return_err;
+ free(return_err);
+ }
+
+ EM_DEBUG_FUNC_END("err [%d]", err);
+ return err;
+}
+/*- task handlers helpers - end --------------------------------------------*/
+
+int _task_handler_array_size;
+email_task_handler_t **_task_handler_array;
+
+static int emcore_register_task_handler(email_task_type_t input_task_type,
+ void* (*input_task_handler)(void *),
+ int (*input_task_parameter_encoder)(void*,char**,int*),
+ int (*input_task_parameter_decoder)(char*,int,void**))
+{
+ EM_DEBUG_FUNC_BEGIN("input_task_type [%d] input_task_handler [%p] "
+ "input_task_parameter_encoder [%p] input_task_parameter_decoder [%p]",
+ input_task_type, input_task_handler,
+ input_task_parameter_encoder, input_task_parameter_decoder);
+
+ int err = EMAIL_ERROR_NONE;
+ email_task_handler_t *new_task_handler = NULL;
+
+ new_task_handler = malloc(sizeof(email_task_handler_t));
+
+ if (new_task_handler == NULL) {
+ err = EMAIL_ERROR_OUT_OF_MEMORY;
+ EM_DEBUG_EXCEPTION("EMAIL_ERROR_OUT_OF_MEMORY");
+ goto FINISH_OFF;
+ }
+
+ new_task_handler->task_type = input_task_type;
+ new_task_handler->task_handler_function = input_task_handler;
+ new_task_handler->task_parameter_encoder = input_task_parameter_encoder;
+ new_task_handler->task_parameter_decoder = input_task_parameter_decoder;
+
+ _task_handler_array_size++;
+
+ if (_task_handler_array) {
+ _task_handler_array = realloc(_task_handler_array, sizeof(email_task_handler_t*) * _task_handler_array_size);
+ }
+ else {
+ _task_handler_array = malloc(sizeof(email_task_handler_t*) * _task_handler_array_size);
+ }
+
+ if (_task_handler_array == NULL) {
+ err = EMAIL_ERROR_OUT_OF_MEMORY;
+ EM_SAFE_FREE(new_task_handler);
+ goto FINISH_OFF;
+ }
+
+ _task_handler_array[_task_handler_array_size - 1] = new_task_handler;
+
+FINISH_OFF:
+
+ EM_DEBUG_FUNC_END("err [%d]", err);
+ return err;
+}
+
+INTERNAL_FUNC int emcore_init_task_handler_array()
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ if (_task_handler_array == NULL) {
+ _task_handler_array = NULL;
+ _task_handler_array_size = 0;
+
+ REGISTER_TASK_BINDER(EMAIL_ASYNC_TASK_MOVE_MAILS_TO_MAILBOX_OF_ANOTHER_ACCOUNT);
+ REGISTER_TASK_BINDER(EMAIL_ASYNC_TASK_DELETE_MAILBOX_EX);
+ REGISTER_TASK_BINDER(EMAIL_ASYNC_TASK_SEND_MAIL_WITH_DOWNLOADING_ATTACHMENT_OF_ORIGINAL_MAIL);
+ REGISTER_TASK_BINDER(EMAIL_SYNC_TASK_SCHEDULE_SENDING_MAIL);
+ REGISTER_TASK_BINDER(EMAIL_SYNC_TASK_UPDATE_ATTRIBUTE);
+ }
+
+ EM_DEBUG_FUNC_END();
+ return EMAIL_ERROR_NONE;
+}
+
+INTERNAL_FUNC int emcore_free_task_handler_array()
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ int i = 0;
+
+ for(i = 0; i < _task_handler_array_size; i++) {
+ EM_SAFE_FREE (_task_handler_array[i]);
+ }
+
+ EM_SAFE_FREE (_task_handler_array);
+ _task_handler_array_size = 0;
+
+ EM_DEBUG_FUNC_END();
+ return EMAIL_ERROR_NONE;
+}
+
+static int emcore_get_task_handler_reference(email_task_type_t input_task_type, email_task_handler_t **output_task_handler)
+{
+ EM_DEBUG_FUNC_BEGIN("input_task_type [%d] output_task_handler [%p]", input_task_type, output_task_handler);
+ int i = 0;
+ int err = EMAIL_ERROR_NONE;
+
+ if (output_task_handler == NULL) {
+ EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
+ err = EMAIL_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ *output_task_handler = NULL;
+ for (i = 0; i < _task_handler_array_size; i++) {
+ if (_task_handler_array[i]->task_type == input_task_type) {
+ *output_task_handler = _task_handler_array[i];
+ break;
+ }
+ }
+
+ if (*output_task_handler == NULL) {
+ EM_DEBUG_EXCEPTION("EMAIL_ERROR_TASK_BINDER_NOT_FOUND");
+ err = EMAIL_ERROR_TASK_BINDER_NOT_FOUND;
+ goto FINISH_OFF;
+ }
+
+FINISH_OFF:
+ EM_DEBUG_FUNC_END("err [%d]", err);
+ return err;
+}
+
+INTERNAL_FUNC int emcore_encode_task_parameter(email_task_type_t input_task_type, void *input_task_parameter_struct, char **output_byte_stream, int *output_stream_size)
+{
+ EM_DEBUG_FUNC_BEGIN("input_task_type [%d] input_task_parameter_struct [%p] output_byte_stream [%p] output_stream_size [%p]", input_task_type, input_task_parameter_struct, output_byte_stream, output_stream_size);
+ int err = EMAIL_ERROR_NONE;
+ email_task_handler_t *task_handler = NULL;
+ int (*task_parameter_encoder)(void*, char**, int*);
+
+ if (input_task_parameter_struct == NULL || output_byte_stream == NULL || output_stream_size == NULL) {
+ EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
+ err = EMAIL_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ if ((err = emcore_get_task_handler_reference(input_task_type, &task_handler)) != EMAIL_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("emcore_get_task_handler_reference failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ task_parameter_encoder = task_handler->task_parameter_encoder;
+
+ if ((err = task_parameter_encoder(input_task_parameter_struct, output_byte_stream, output_stream_size)) != EMAIL_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("task_parameter_encoder failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+FINISH_OFF:
+ EM_DEBUG_FUNC_END("err [%d]", err);
+ return err;
+}
+
+INTERNAL_FUNC int emcore_decode_task_parameter(email_task_type_t input_task_type, char *input_byte_stream, int input_stream_size, void **output_task_parameter_struct)
+{
+ EM_DEBUG_FUNC_BEGIN("input_task_type [%d] input_byte_stream [%p] input_stream_size [%d] output_task_parameter_struct [%p]", input_task_type, input_byte_stream, input_stream_size, output_task_parameter_struct);
+ int err = EMAIL_ERROR_NONE;
+ email_task_handler_t *task_handler = NULL;
+ int (*task_parameter_decoder)(char*, int, void**);
+
+ if (input_byte_stream == NULL || output_task_parameter_struct == NULL) {
+ EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
+ err = EMAIL_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ if ((err = emcore_get_task_handler_reference(input_task_type, &task_handler)) != EMAIL_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("emcore_get_task_handler_reference failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ task_parameter_decoder = task_handler->task_parameter_decoder;
+
+ if ((err = task_parameter_decoder(input_byte_stream,
+ input_stream_size,
+ output_task_parameter_struct)) != EMAIL_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("task_parameter_decoder failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+FINISH_OFF:
+ EM_DEBUG_FUNC_END("err [%d]", err);
+ return err;
+}
+
+int emcore_fetch_task_from_task_pool(email_task_t **output_task)
+{
+ EM_DEBUG_FUNC_BEGIN("output_task [%p]", output_task);
+ int err = EMAIL_ERROR_NONE;
+ int output_task_count;
+
+ if ((err = emstorage_query_task(NULL,
+ "WHERE task_status == 1",
+ "ORDER BY date_time ASC, task_priority ASC LIMIT 0, 1",
+ output_task,
+ &output_task_count)) != EMAIL_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("emstorage_query_task failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+FINISH_OFF:
+
+ EM_DEBUG_FUNC_END("err [%d]", err);
+ return err;
+}
+
+
+/*-Task manager loop - begin -------------------------------------------------------------*/
+
+
+static int emcore_insert_task_to_active_task_pool(int input_task_slot_index, int input_task_id, email_task_type_t input_task_type, thread_t input_thread_id)
+{
+ EM_DEBUG_FUNC_BEGIN("input_task_slot_index [%d] input_task_id [%d] input_task_type [%d] input_thread_id [%d]", input_task_slot_index, input_task_id, input_task_type, input_thread_id);
+ int err = EMAIL_ERROR_NONE;
+
+ ENTER_CRITICAL_SECTION(_active_task_pool_lock);
+ _active_task_pool[input_task_slot_index].task_id = input_task_id;
+ _active_task_pool[input_task_slot_index].task_type = input_task_type;
+ _active_task_pool[input_task_slot_index].thread_id = input_thread_id;
+ LEAVE_CRITICAL_SECTION(_active_task_pool_lock);
+
+ EM_DEBUG_LOG("_active_task_pool[%d].task_id [%d]", input_task_slot_index, _active_task_pool[input_task_slot_index].task_id);
+
+ EM_DEBUG_FUNC_END("err [%d]", err);
+ return err;
+}
+
+static int emcore_remove_task_from_active_task_pool(int input_task_id)
+{
+ EM_DEBUG_FUNC_BEGIN(" input_task_id [%d]", input_task_id);
+ int err = EMAIL_ERROR_NONE;
+ int i = 0;
+
+ ENTER_CRITICAL_SECTION(_active_task_pool_lock);
+ for(i = 0; i < MAX_ACTIVE_TASK; i++) {
+ if(_active_task_pool[i].task_id == input_task_id) {
+ _active_task_pool[i].task_id = 0;
+ _active_task_pool[i].task_type = 0;
+ _active_task_pool[i].thread_id = 0;
+ break;
+ }
+ }
+ LEAVE_CRITICAL_SECTION(_active_task_pool_lock);
+
+ if(i >= MAX_ACTIVE_TASK) {
+ EM_DEBUG_LOG("couldn't find proper task in active task pool [%d]", input_task_id);
+ err = EMAIL_ERROR_TASK_NOT_FOUND;
+ }
+
+ EM_DEBUG_FUNC_END("err [%d]", err);
+ return err;
+}
+
+INTERNAL_FUNC int emcore_get_active_task_by_thread_id(thread_t input_thread_id, email_active_task_t **output_active_task)
+{
+ EM_DEBUG_FUNC_BEGIN(" input_thread_id [%d] output_active_task [%p]", input_thread_id, output_active_task);
+ int err = EMAIL_ERROR_NONE;
+ int i = 0;
+
+ if (output_active_task == NULL) {
+ EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
+ err = EMAIL_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ for(i = 0; i < MAX_ACTIVE_TASK; i++) {
+ if(_active_task_pool[i].thread_id == input_thread_id) {
+ *output_active_task = _active_task_pool + i;
+ break;
+ }
+ }
+
+ if(i >= MAX_ACTIVE_TASK) {
+ EM_DEBUG_LOG("couldn't find proper task in active task pool [%d]", input_thread_id);
+ err = EMAIL_ERROR_TASK_NOT_FOUND;
+ }
+
+FINISH_OFF:
+
+ EM_DEBUG_FUNC_END("err [%d]", err);
+ return err;
+}
+
+
+static int emcore_find_available_slot_in_active_task_pool(int *result_index)
+{
+ EM_DEBUG_FUNC_BEGIN("result_index [%p]", result_index);
+ int i = 0;
+ int err = EMAIL_ERROR_NONE;
+
+ if (result_index == NULL) {
+ EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
+ err = EMAIL_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ ENTER_CRITICAL_SECTION(_active_task_pool_lock);
+ for(i = 0; i < MAX_ACTIVE_TASK; i++) {
+ if(_active_task_pool[i].task_id == 0) {
+ break;
+ }
+ }
+
+ if(i >= MAX_ACTIVE_TASK) {
+ EM_DEBUG_EXCEPTION("There is no available task slot");
+ err = EMAIL_NO_AVAILABLE_TASK_SLOT;
+ }
+ else {
+ _active_task_pool[i].task_id = -1;
+ *result_index = i;
+ }
+ LEAVE_CRITICAL_SECTION(_active_task_pool_lock);
+
+FINISH_OFF :
+ EM_DEBUG_FUNC_END("err [%d]", err);
+ return err;
+}
+
+void* thread_func_task_manager_loop(void *arg)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int err = EMAIL_ERROR_NONE;
+ int thread_error;
+ int available_slot_index = 0;
+ email_task_t *new_task = NULL;
+
+ /* while loop */
+ while (_task_manager_loop_availability) {
+ /* fetch task from DB */
+ if( ((err = emcore_fetch_task_from_task_pool(&new_task)) == EMAIL_ERROR_NONE) &&
+ ((err = emcore_find_available_slot_in_active_task_pool(&available_slot_index)) == EMAIL_ERROR_NONE) ) {
+
+ /* update task status as STARTED */
+ if((err = emcore_update_task_status_on_task_table(NULL, new_task->task_id, EMAIL_TASK_STATUS_STARTED)) != EMAIL_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("emcore_update_task_status_on_task_table failed [%d]", err);
+ }
+ new_task->active_task_id = available_slot_index;
+
+ /* create a thread to do this task */
+ THREAD_CREATE(new_task->thread_id, emcore_default_async_task_handler, new_task, thread_error);
+ EM_DEBUG_LOG("pthread_create returns [%d]", thread_error);
+
+ /* new_task and task_parameter will be free in task handler. */
+ EM_SAFE_FREE(new_task->task_parameter);
+ EM_SAFE_FREE(new_task);
+ }
+ else {
+ /* If there is no task or no available slot, sleep until someone wake you up. */
+ /* Wake up case 1 : by emcore_add_task_to_task_table */
+ /* Wake up case 2 : when some task terminated */
+ ENTER_CRITICAL_SECTION(_task_available_lock);
+ SLEEP_CONDITION_VARIABLE(_task_available_signal, _task_available_lock);
+ LEAVE_CRITICAL_SECTION(_task_available_lock);
+ EM_DEBUG_LOG("thread_func_task_manager_loop wake up!");
+ }
+ }
+
+ EM_DEBUG_FUNC_END();
+ return NULL;
+}
+
+INTERNAL_FUNC int emcore_start_task_manager_loop()
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int thread_error;
+ int err = EMAIL_ERROR_NONE;
+
+ memset(&_active_task_pool, 0, sizeof(email_active_task_t) * MAX_ACTIVE_TASK);
+
+ if (_thread_task_manager_loop) {
+ EM_DEBUG_EXCEPTION("service thread is already running...");
+ err = EMAIL_ERROR_ALREADY_INITIALIZED;
+ goto FINISH_OFF;
+ }
+
+ _task_manager_loop_availability = 10;
+
+ /* create thread */
+ THREAD_CREATE(_thread_task_manager_loop, thread_func_task_manager_loop, NULL, thread_error);
+
+ if (thread_error != 0) {
+ EM_DEBUG_EXCEPTION("cannot create thread [%d]", thread_error);
+ err = EMAIL_ERROR_SYSTEM_FAILURE;
+ goto FINISH_OFF;
+ }
+
+FINISH_OFF :
+ EM_DEBUG_FUNC_END("err [%d]", err);
+ return err;
+}
+
+INTERNAL_FUNC int emcore_stop_task_manager_loop()
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ int err = EMAIL_ERROR_NONE;
+
+ if (!_thread_task_manager_loop) {
+ EM_DEBUG_LOG("_thread_task_manager_loop is NULL ");
+ err = EMAIL_ERROR_UNKNOWN;
+ return err;
+ }
+
+ /* TODO : cancel tasks */
+
+ /* stop event_data loop */
+ _task_manager_loop_availability = 0;
+
+ ENTER_CRITICAL_SECTION(_task_manager_loop_lock);
+ WAKE_CONDITION_VARIABLE(_task_available_signal);
+ LEAVE_CRITICAL_SECTION(_task_manager_loop_lock);
+
+ /* wait for thread finished */
+ THREAD_JOIN(_thread_task_manager_loop);
+
+ _thread_task_manager_loop = 0;
+
+ DELETE_CRITICAL_SECTION(_task_manager_loop_lock);
+ DELETE_CONDITION_VARIABLE(_task_available_signal);
+
+ /* Free _active_task_pool */
+
+ //FINISH_OFF :
+
+ EM_DEBUG_FUNC_END("err [%d]", err);
+ return err;
+}
+
+INTERNAL_FUNC int emcore_add_task_to_task_table(char *multi_user_name, email_task_type_t input_task_type, email_task_priority_t input_task_priority, char *input_task_parameter, int input_task_parameter_length, int *output_task_id)
+{
+ EM_DEBUG_FUNC_BEGIN("input_task_type [%d] input_task_priority [%d] input_task_parameter [%p] input_task_parameter_length [%d] output_task_id [%p]", input_task_type, input_task_priority, input_task_parameter, input_task_parameter_length, output_task_id);
+ int err = EMAIL_ERROR_NONE;
+
+ if((err = emstorage_add_task(multi_user_name, input_task_type, input_task_priority, input_task_parameter, input_task_parameter_length, false, output_task_id)) != EMAIL_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("emstorage_add_task failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ ENTER_CRITICAL_SECTION(_task_available_lock);
+ WAKE_CONDITION_VARIABLE(_task_available_signal);
+ LEAVE_CRITICAL_SECTION(_task_available_lock);
+
+FINISH_OFF:
+ EM_DEBUG_FUNC_END("err [%d]", err);
+ return err;
+}
+
+INTERNAL_FUNC int emcore_remove_task_from_task_table(char *multi_user_name, int input_task_id)
+{
+ EM_DEBUG_FUNC_BEGIN("input_task_id [%d]", input_task_id);
+ int err = EMAIL_ERROR_NONE;
+
+ if((err = emstorage_delete_task(multi_user_name, input_task_id, true)) != EMAIL_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("emstorage_delete_task failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+FINISH_OFF:
+ EM_DEBUG_FUNC_END("err [%d]", err);
+ return err;
+}
+
+static int emcore_update_task_status_on_task_table(char *multi_user_name, int input_task_id, email_task_status_type_t task_status)
+{
+ EM_DEBUG_FUNC_BEGIN("input_task_id [%d] task_status [%d]", input_task_id, task_status);
+ int err = EMAIL_ERROR_NONE;
+
+ if((err = emstorage_update_task_status(multi_user_name, input_task_id, task_status, true)) != EMAIL_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("emstorage_update_task_status failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+FINISH_OFF:
+ EM_DEBUG_FUNC_END("err [%d]", err);
+ return err;
+}
+
+/*-Task manager loop - end-------------------------------------------------------------*/
diff --git a/email-core/email-core-tasks.c b/email-core/email-core-tasks.c
index d04e258..ca7a67e 100755
--- a/email-core/email-core-tasks.c
+++ b/email-core/email-core-tasks.c
@@ -67,6 +67,12 @@ INTERNAL_FUNC int email_encode_task_parameter_EMAIL_ASYNC_TASK_MOVE_MAILS_TO_MAI
, &task_parameter->target_mailbox_id
, &task_parameter->mail_id_count
, &tb);
+ if (tn == NULL) {
+ EM_DEBUG_EXCEPTION("tpl_map failed");
+ err = EMAIL_ERROR_SYSTEM_FAILURE;
+ goto FINISH_OFF;
+ }
+
tb.sz = sizeof(int) * task_parameter->mail_id_count;
tb.addr = task_parameter->mail_id_array;
tpl_pack(tn, 0);
@@ -97,8 +103,7 @@ INTERNAL_FUNC int email_decode_task_parameter_EMAIL_ASYNC_TASK_MOVE_MAILS_TO_MAI
}
task_parameter = em_malloc(sizeof(task_parameter_EMAIL_ASYNC_TASK_MOVE_MAILS_TO_MAILBOX_OF_ANOTHER_ACCOUNT));
-
- if(task_parameter == NULL) {
+ if (task_parameter == NULL) {
EM_DEBUG_EXCEPTION("EMAIL_ERROR_OUT_OF_MEMORY");
err = EMAIL_ERROR_OUT_OF_MEMORY;
goto FINISH_OFF;
@@ -111,6 +116,7 @@ INTERNAL_FUNC int email_decode_task_parameter_EMAIL_ASYNC_TASK_MOVE_MAILS_TO_MAI
, &tb);
if (tn == NULL) {
EM_DEBUG_EXCEPTION("tpl_map failed");
+ EM_SAFE_FREE(task_parameter);
err = EMAIL_ERROR_SYSTEM_FAILURE;
goto FINISH_OFF;
}
@@ -145,7 +151,7 @@ INTERNAL_FUNC void* task_handler_EMAIL_ASYNC_TASK_MOVE_MAILS_TO_MAILBOX_OF_ANOTH
task_parameter_EMAIL_ASYNC_TASK_MOVE_MAILS_TO_MAILBOX_OF_ANOTHER_ACCOUNT *task_param = input_param;
for(i = 0; i < task_param->mail_id_count; i++) {
- if((err = emcore_move_mail_to_another_account(task_param->mail_id_array[i], task_param->source_mailbox_id, task_param->target_mailbox_id, task_id)) != EMAIL_ERROR_NONE) {
+ if((err = emcore_move_mail_to_another_account(task_param->multi_user_name, task_param->mail_id_array[i], task_param->source_mailbox_id, task_param->target_mailbox_id, task_id)) != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("emcore_move_mail_to_another_account failed [%d]", err);
goto FINISH_OFF;
}
@@ -225,7 +231,6 @@ INTERNAL_FUNC int email_decode_task_parameter_EMAIL_ASYNC_TASK_DELETE_MAILBOX_EX
}
task_parameter = em_malloc(sizeof(task_parameter_EMAIL_ASYNC_TASK_DELETE_MAILBOX_EX));
-
if(task_parameter == NULL) {
EM_DEBUG_EXCEPTION("EMAIL_ERROR_OUT_OF_MEMORY");
err = EMAIL_ERROR_OUT_OF_MEMORY;
@@ -239,6 +244,7 @@ INTERNAL_FUNC int email_decode_task_parameter_EMAIL_ASYNC_TASK_DELETE_MAILBOX_EX
, &task_parameter->on_server);
if (tn == NULL) {
EM_DEBUG_EXCEPTION("tpl_map failed");
+ EM_SAFE_FREE(task_parameter);
err = EMAIL_ERROR_SYSTEM_FAILURE;
goto FINISH_OFF;
}
@@ -322,7 +328,6 @@ INTERNAL_FUNC int email_decode_task_parameter_EMAIL_ASYNC_TASK_SEND_MAIL_WITH_DO
}
task_parameter = em_malloc(sizeof(task_parameter_EMAIL_ASYNC_TASK_SEND_MAIL_WITH_DOWNLOADING_ATTACHMENT_OF_ORIGINAL_MAIL));
-
if (task_parameter == NULL) {
EM_DEBUG_EXCEPTION("EMAIL_ERROR_OUT_OF_MEMORY");
err = EMAIL_ERROR_OUT_OF_MEMORY;
@@ -333,6 +338,7 @@ INTERNAL_FUNC int email_decode_task_parameter_EMAIL_ASYNC_TASK_SEND_MAIL_WITH_DO
, &task_parameter->mail_id);
if (tn == NULL) {
EM_DEBUG_EXCEPTION("tpl_map failed");
+ EM_SAFE_FREE(task_parameter);
err = EMAIL_ERROR_SYSTEM_FAILURE;
goto FINISH_OFF;
}
@@ -341,7 +347,7 @@ INTERNAL_FUNC int email_decode_task_parameter_EMAIL_ASYNC_TASK_SEND_MAIL_WITH_DO
tpl_unpack(tn, 0);
*output_task_parameter_struct = task_parameter;
-
+
FINISH_OFF:
if(tn)
@@ -410,7 +416,6 @@ INTERNAL_FUNC int email_decode_task_parameter_EMAIL_SYNC_TASK_SCHEDULE_SENDING_M
}
task_parameter = em_malloc(sizeof(task_parameter_EMAIL_SYNC_TASK_SCHEDULE_SENDING_MAIL));
-
if(task_parameter == NULL) {
EM_DEBUG_EXCEPTION("EMAIL_ERROR_OUT_OF_MEMORY");
err = EMAIL_ERROR_OUT_OF_MEMORY;
@@ -421,6 +426,7 @@ INTERNAL_FUNC int email_decode_task_parameter_EMAIL_SYNC_TASK_SCHEDULE_SENDING_M
, &task_parameter->mail_id, &task_parameter->scheduled_time);
if (tn == NULL) {
EM_DEBUG_EXCEPTION("tpl_map failed");
+ EM_SAFE_FREE(task_parameter);
err = EMAIL_ERROR_SYSTEM_FAILURE;
goto FINISH_OFF;
}
@@ -442,21 +448,35 @@ FINISH_OFF:
INTERNAL_FUNC void* task_handler_EMAIL_SYNC_TASK_SCHEDULE_SENDING_MAIL(void *input_param)
{
EM_DEBUG_FUNC_BEGIN("input_param [%p]", input_param);
+
int err = EMAIL_ERROR_NONE;
+ int *return_err = NULL;
task_parameter_EMAIL_SYNC_TASK_SCHEDULE_SENDING_MAIL *task_param = input_param;
- if((err = emcore_schedule_sending_mail(task_param->mail_id, task_param->scheduled_time)) != EMAIL_ERROR_NONE) {
+ if ((err = emcore_schedule_sending_mail(task_param->multi_user_name,
+ task_param->mail_id,
+ task_param->scheduled_time)) != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("emcore_schedule_sending_mail [%d]", err);
err = EMAIL_ERROR_OUT_OF_MEMORY;
goto FINISH_OFF;
}
+ return_err = em_malloc(sizeof(int));
+ if (return_err == NULL) {
+ EM_DEBUG_EXCEPTION("em_malloc failed");
+ err = EMAIL_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ *return_err = err;
+
FINISH_OFF:
EM_SAFE_FREE(task_param);
- emcore_close_smtp_stream_list ();
+ emcore_close_smtp_stream_list();
EM_DEBUG_FUNC_END("err [%d]", err);
- return (void*)err;
+
+ return (void *)return_err;
}
/*-------------------------------------------------------------------------------------------*/
/* to handle EMAIL_SYNC_TASK_UPDATE_ATTRIBUTE */
@@ -536,13 +556,26 @@ FINISH_OFF:
if(tn)
tpl_free(tn);
+ if (err != EMAIL_ERROR_NONE) {
+ EM_SAFE_FREE(result_data);
+
+ if (task_parameter) {
+ EM_SAFE_FREE(task_parameter->multi_user_name);
+ EM_SAFE_FREE(task_parameter->mail_id_array);
+ free(task_parameter);
+ }
+ }
+
EM_DEBUG_FUNC_END("err [%d]", err);
- return EMAIL_ERROR_NONE;
+ return err;
}
-INTERNAL_FUNC int email_decode_task_parameter_EMAIL_SYNC_TASK_UPDATE_ATTRIBUTE(char *input_byte_stream, int input_stream_size, void **output_task_parameter_struct)
+INTERNAL_FUNC int email_decode_task_parameter_EMAIL_SYNC_TASK_UPDATE_ATTRIBUTE(char *input_byte_stream,
+ int input_stream_size,
+ void **output_task_parameter_struct)
{
- EM_DEBUG_FUNC_BEGIN("input_byte_stream [%p] input_stream_size [%d] output_task_parameter_struct [%p]", input_byte_stream, input_stream_size, output_task_parameter_struct);
+ EM_DEBUG_FUNC_BEGIN("input_byte_stream [%p] input_stream_size [%d] output_task_parameter_struct [%p]",
+ input_byte_stream, input_stream_size, output_task_parameter_struct);
int err = EMAIL_ERROR_NONE;
tpl_node *tn = NULL;
tpl_bin tb_mail_id_array;
@@ -557,7 +590,6 @@ INTERNAL_FUNC int email_decode_task_parameter_EMAIL_SYNC_TASK_UPDATE_ATTRIBUTE(c
}
task_parameter = em_malloc(sizeof(task_parameter_EMAIL_SYNC_TASK_UPDATE_ATTRIBUTE));
-
if(task_parameter == NULL) {
EM_DEBUG_EXCEPTION("EMAIL_ERROR_OUT_OF_MEMORY");
err = EMAIL_ERROR_OUT_OF_MEMORY;
@@ -581,14 +613,16 @@ INTERNAL_FUNC int email_decode_task_parameter_EMAIL_SYNC_TASK_UPDATE_ATTRIBUTE(c
tpl_unpack(tn, 0);
if(task_parameter->mail_id_count <= 0 || tb_mail_id_array.addr == NULL) {
- EM_DEBUG_LOG("No mail id list. mail_id_count[%d] addr[%p]", task_parameter->mail_id_count, tb_mail_id_array.addr);
+ EM_DEBUG_LOG("No mail id list. mail_id_count[%d] addr[%p]",
+ task_parameter->mail_id_count, tb_mail_id_array.addr);
}
else {
task_parameter->mail_id_array = tb_mail_id_array.addr;
}
if(tb_value.addr) {
- if ((err = emcore_get_mail_attribute_value_type(task_parameter->attribute_type, &attribute_value_type)) != EMAIL_ERROR_NONE) {
+ if ((err = emcore_get_mail_attribute_value_type(task_parameter->attribute_type,
+ &attribute_value_type)) != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("emcore_get_mail_attribute_value_type failed [%d]", err);
goto FINISH_OFF;
}
@@ -621,40 +655,57 @@ INTERNAL_FUNC int email_decode_task_parameter_EMAIL_SYNC_TASK_UPDATE_ATTRIBUTE(c
FINISH_OFF:
- if(tn)
+ if (tn)
tpl_free(tn);
+ if (err != EMAIL_ERROR_NONE) {
+ if (task_parameter) {
+ EM_SAFE_FREE(task_parameter->multi_user_name);
+ EM_SAFE_FREE(task_parameter->mail_id_array);
+ free(task_parameter);
+ }
+ }
+
EM_DEBUG_FUNC_END("err [%d]", err);
- return EMAIL_ERROR_NONE;
+ return err;
}
-INTERNAL_FUNC void* task_handler_EMAIL_SYNC_TASK_UPDATE_ATTRIBUTE(void *input_param)
+INTERNAL_FUNC void *task_handler_EMAIL_SYNC_TASK_UPDATE_ATTRIBUTE(void *input_param)
{
EM_DEBUG_FUNC_BEGIN("input_param [%p]", input_param);
- if(!input_param) { /*prevent 43681*/
+ if (!input_param) { /*prevent 43681*/
EM_DEBUG_EXCEPTION("NULL parameter");
return NULL;
}
int err = EMAIL_ERROR_NONE;
+ int *return_err = NULL;
char *field_name = NULL;
task_parameter_EMAIL_SYNC_TASK_UPDATE_ATTRIBUTE *task_param = input_param;
email_mail_attribute_value_type attribute_value_type = EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_NONE; /*prevent 43700*/
- if((field_name = emcore_get_mail_field_name_by_attribute_type(task_param->attribute_type)) == NULL) {
+ if ((field_name = emcore_get_mail_field_name_by_attribute_type(task_param->attribute_type)) == NULL) {
EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
err = EMAIL_ERROR_INVALID_PARAM;
goto FINISH_OFF;
}
- if((err = emcore_get_mail_attribute_value_type(task_param->attribute_type, &attribute_value_type)) != EMAIL_ERROR_NONE) {
+ if ((err = emcore_get_mail_attribute_value_type(task_param->attribute_type,
+ &attribute_value_type)) != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("emcore_get_mail_attribute_value_type failed [%d]", err);
goto FINISH_OFF;
}
switch(attribute_value_type) {
case EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_INTEGER :
- if(!emstorage_set_field_of_mails_with_integer_value(task_param->account_id, task_param->mail_id_array, task_param->mail_id_count, field_name, task_param->value.integer_type_value, true, &err)) {
+ if (!emstorage_set_field_of_mails_with_integer_value(task_param->multi_user_name,
+ task_param->account_id,
+ task_param->mail_id_array,
+ task_param->mail_id_count,
+ field_name,
+ task_param->value.integer_type_value,
+ true,
+ &err)) {
EM_DEBUG_EXCEPTION("emstorage_set_field_of_mails_with_integer_value failed [%d]", err);
goto FINISH_OFF;
}
@@ -664,7 +715,14 @@ INTERNAL_FUNC void* task_handler_EMAIL_SYNC_TASK_UPDATE_ATTRIBUTE(void *input_pa
EM_DEBUG_LOG("EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_STRING is not supported");
break;
case EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_TIME :
- if(!emstorage_set_field_of_mails_with_integer_value(task_param->account_id, task_param->mail_id_array, task_param->mail_id_count, field_name, task_param->value.datetime_type_value, true, &err)) {
+ if (!emstorage_set_field_of_mails_with_integer_value(task_param->multi_user_name,
+ task_param->account_id,
+ task_param->mail_id_array,
+ task_param->mail_id_count,
+ field_name,
+ task_param->value.datetime_type_value,
+ true,
+ &err)) {
EM_DEBUG_EXCEPTION("emstorage_set_field_of_mails_with_integer_value failed [%d]", err);
goto FINISH_OFF;
}
@@ -676,8 +734,18 @@ INTERNAL_FUNC void* task_handler_EMAIL_SYNC_TASK_UPDATE_ATTRIBUTE(void *input_pa
break;
}
+ return_err = em_malloc(sizeof(int));
+ if (return_err == NULL) {
+ EM_DEBUG_EXCEPTION("em_malloc failed");
+ err = EMAIL_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ *return_err = err;
+
FINISH_OFF:
+ EM_SAFE_FREE(task_param->multi_user_name);
EM_SAFE_FREE(task_param->mail_id_array);
if (attribute_value_type == EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_STRING) {
EM_SAFE_FREE(task_param->value.string_type_value);
@@ -686,6 +754,7 @@ FINISH_OFF:
EM_SAFE_FREE (task_param);
EM_DEBUG_FUNC_END("err [%d]", err);
- return (void*)err;
+
+ return (void *)return_err;
}
/*-------------------------------------------------------------------------------------------*/
diff --git a/email-core/email-core-timer.c b/email-core/email-core-timer.c
index 0f293cb..d6943aa 100755
--- a/email-core/email-core-timer.c
+++ b/email-core/email-core-timer.c
@@ -72,7 +72,7 @@ INTERNAL_FUNC int emcore_timer_ex_callback(void *a_pData)
if (pUserData)
return 0;
else
- return 1;
+ return 1;
}
INTERNAL_FUNC int emcore_set_timer_ex(long a_nSetTimeValue, EMAIL_TIMER_CALLBACK a_pCallBack, void *a_pData)
@@ -80,17 +80,14 @@ INTERNAL_FUNC int emcore_set_timer_ex(long a_nSetTimeValue, EMAIL_TIMER_CALLBACK
EM_DEBUG_LOG("emcore_set_timer_ex %d", a_nSetTimeValue);
em_timer_callback_data *pTimerData = NULL;
pTimerData = malloc(sizeof(em_timer_callback_data));
- char *data = NULL;
if (!pTimerData)
return -1;
- memset(pTimerData, 0x00, sizeof(em_timer_callback_data));
- if (a_pData)
- EM_DEBUG_LOG("emcore_set_timer_ex >>> data : %s", (char *)a_pData);
+
+ memset(pTimerData, 0x00, sizeof(em_timer_callback_data));
pTimerData->user_callback_function = a_pCallBack;
if (a_pData) {
- data = (char *) a_pData;
- pTimerData->callback_user_data = EM_SAFE_STRDUP(data);
+ pTimerData->callback_user_data = a_pData;
}
pTimerData->time_id = g_timeout_add(a_nSetTimeValue, emcore_timer_ex_callback, pTimerData);
return pTimerData->time_id;
diff --git a/email-core/email-core-utils.c b/email-core/email-core-utils.c
index b942f70..001017f 100755
--- a/email-core/email-core-utils.c
+++ b/email-core/email-core-utils.c
@@ -50,13 +50,13 @@
#include <notification.h>
#include <notification_type.h>
#include <notification_internal.h>
+#include <notification_text_domain.h>
#include <badge.h>
#include <badge_internal.h>
#ifdef __FEATURE_USE_DRM_API__
#include <drm_client_types.h>
#include <drm_client.h>
#endif /* __FEATURE_USE_DRM_API__ */
-#include <feedback.h>
#include <storage.h>
#include <bundle.h>
#include <curl/curl.h>
@@ -73,20 +73,21 @@
#include "email-core-account.h"
#include "email-core-mailbox-sync.h"
#include "email-core-mime.h"
+#include "email-core-gmime.h"
#include "email-core-signal.h"
#include "email-daemon.h"
#include "email-utilities.h"
#include "email-convert.h"
#include "email-internal-types.h"
#include "email-device.h"
+#include "email-core-container.h"
#include <gio/gio.h>
#include "email-dbus-activation.h"
-#ifdef __FEATURE_DRIVING_MODE__
#include <app_control.h>
-#endif /* __FEATURE_DRIVING_MODE__ */
+#include <app_control_internal.h>
#define LED_TIMEOUT_SECS 12
#define G_DISPLAY_LENGTH 256
@@ -102,7 +103,7 @@
#define EMAIL_CH_SQUARE_BRACKET_S '['
#define EMAIL_CH_SQUARE_BRACKET_E ']'
#define EMAIL_CH_SPACE ' '
-#define EMAIL_NOTI_ICON_PATH "/usr/apps/org.tizen.quickpanel/shared/res/noti_icons/noti_email.png"
+#define EMAIL_NOTI_ICON_PATH "/usr/apps/org.tizen.quickpanel/shared/res/noti_icons/E-mail/noti_email.png"
#define EMAIL_NOTI_INDICATOR_ICON_PATH "/usr/apps/org.tizen.indicator/res/icons/Event/B03_Event_email.png"
#define EMAIL_NOTI_MAX_MAIL_ID 100
@@ -126,7 +127,6 @@ struct emcore_account_list_t {
#include <gmime/gmime.h>
-
INTERNAL_FUNC char *emcore_convert_mutf7_to_utf8(char *mailbox_name)
{
EM_DEBUG_FUNC_BEGIN("mailbox_name[%p]", mailbox_name);
@@ -150,7 +150,7 @@ INTERNAL_FUNC char *emcore_convert_mutf7_to_utf8(char *mailbox_name)
EM_DEBUG_EXCEPTION("EMAIL_ERROR_OUT_OF_MEMORY");
return NULL;
}
-
+
for (; *cursor; ++cursor)
switch (*cursor) {
case '+':
@@ -194,7 +194,7 @@ INTERNAL_FUNC char *emcore_convert_mutf7_to_utf8(char *mailbox_name)
}
}
else {
- result_mailbox_name = (char *)utf8_from_mutf7 ((unsigned char *)mailbox_name);
+ result_mailbox_name = (char *)utf8_from_mutf7((unsigned char *)mailbox_name);
EM_DEBUG_LOG_SEC("result_mailbox_name[%s]", result_mailbox_name);
if (result_mailbox_name == NULL)
result_mailbox_name = EM_SAFE_STRDUP(mutf7_text);
@@ -212,7 +212,7 @@ INTERNAL_FUNC char *emcore_convert_mutf7_to_utf8(char *mailbox_name)
}
/* in smtp case, path argument must be ENCODED_PATH_SMTP */
-int emcore_get_long_encoded_path_with_account_info(email_account_t *account, char *path, int delimiter, char **long_enc_path, int *err_code)
+int emcore_get_long_encoded_path_with_account_info(char *multi_user_name, email_account_t *account, char *path, int delimiter, char **long_enc_path, int *err_code)
{
EM_PROFILE_BEGIN(emCorelongEncodedpath);
EM_DEBUG_FUNC_BEGIN_SEC("account[%p], path[%s], delimiter[%d], long_enc_path[%p], err_code[%p]", account, path, delimiter, long_enc_path, err_code);
@@ -247,10 +247,21 @@ int emcore_get_long_encoded_path_with_account_info(email_account_t *account, cha
/* ex:"{mai.test.com:143/imap} or {mai.test.com:143/imap/tls}my-mailbox" */
- SNPRINTF(p, long_enc_path_len, "{%s:%d/%s/user=%d",
- account->incoming_server_address,
- account->incoming_server_port_number,
- account->incoming_server_type == EMAIL_SERVER_TYPE_POP3 ? "pop3" : "imap", account->account_id);
+ if (multi_user_name) {
+ SNPRINTF(p, long_enc_path_len, "{%s:%d/%s/user=%d%s%s",
+ account->incoming_server_address,
+ account->incoming_server_port_number,
+ account->incoming_server_type == EMAIL_SERVER_TYPE_POP3 ? "pop3" : "imap",
+ account->account_id,
+ TOKEN_FOR_MULTI_USER,
+ multi_user_name);
+ } else {
+ SNPRINTF(p, long_enc_path_len, "{%s:%d/%s/user=%d",
+ account->incoming_server_address,
+ account->incoming_server_port_number,
+ account->incoming_server_type == EMAIL_SERVER_TYPE_POP3 ? "pop3" : "imap",
+ account->account_id);
+ }
if (account->incoming_server_secure_connection & 0x01) {
strncat(p, "/ssl", long_enc_path_len-(EM_SAFE_STRLEN(p)+1));
@@ -286,7 +297,16 @@ int emcore_get_long_encoded_path_with_account_info(email_account_t *account, cha
"smtp");
if (account->outgoing_server_need_authentication > 0) {
- SNPRINTF(p + EM_SAFE_STRLEN(p), long_enc_path_len-(EM_SAFE_STRLEN(p)), "/user=%d", account->account_id);
+ if (multi_user_name) {
+ SNPRINTF(p + EM_SAFE_STRLEN(p), long_enc_path_len-(EM_SAFE_STRLEN(p)), "/user=%d%s%s",
+ account->account_id,
+ TOKEN_FOR_MULTI_USER,
+ multi_user_name);
+ } else {
+ SNPRINTF(p + EM_SAFE_STRLEN(p), long_enc_path_len-(EM_SAFE_STRLEN(p)), "/user=%d",
+ account->account_id);
+ }
+
if (account->outgoing_server_need_authentication == EMAIL_AUTHENTICATION_METHOD_XOAUTH2) {
strncat(p, "/xoauth2", long_enc_path_len-(EM_SAFE_STRLEN(p)+1));
}
@@ -344,7 +364,7 @@ FINISH_OFF:
return ret;
}
-int emcore_get_long_encoded_path(int account_id, char *path, int delimiter, char **long_enc_path, int *err_code)
+int emcore_get_long_encoded_path(char *multi_user_name, int account_id, char *path, int delimiter, char **long_enc_path, int *err_code)
{
EM_PROFILE_BEGIN(emCorelongEncodedpath);
EM_DEBUG_FUNC_BEGIN("account_id[%d], delimiter[%d], long_enc_path[%p], err_code[%p]", account_id, delimiter, long_enc_path, err_code);
@@ -353,14 +373,14 @@ int emcore_get_long_encoded_path(int account_id, char *path, int delimiter, char
int error = EMAIL_ERROR_NONE;
email_account_t *ref_account = NULL;
- ref_account = emcore_get_account_reference(account_id);
+ ref_account = emcore_get_account_reference(multi_user_name, account_id, false);
if (!ref_account) {
EM_DEBUG_EXCEPTION("emcore_get_account_reference failed [%d]", account_id);
error = EMAIL_ERROR_INVALID_ACCOUNT;
goto FINISH_OFF;
}
- if (emcore_get_long_encoded_path_with_account_info(ref_account, path, delimiter, long_enc_path, &error) == false) {
+ if (emcore_get_long_encoded_path_with_account_info(multi_user_name, ref_account, path, delimiter, long_enc_path, &error) == false) {
EM_DEBUG_EXCEPTION("emcore_get_long_encoded_path_with_account_info failed [%d]", error);
goto FINISH_OFF;
}
@@ -763,7 +783,7 @@ INTERNAL_FUNC int emcore_get_current_session(email_session_t **session)
return true;
}
-INTERNAL_FUNC int emcore_get_mail_count_by_query(int account_id, int mailbox_type, int priority_sender, int *total_mail, int *unread_mail, int *err_code)
+INTERNAL_FUNC int emcore_get_mail_count_by_query(char *multi_user_name, int account_id, int mailbox_type, int priority_sender, int *total_mail, int *unread_mail, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("account_id : [%d], mailbox_type : [%d], priority_sender : [%d]", account_id, mailbox_type, priority_sender);
@@ -784,7 +804,7 @@ INTERNAL_FUNC int emcore_get_mail_count_by_query(int account_id, int mailbox_typ
/* Get rule list */
if (priority_sender) {
- if (!emstorage_get_rule(ALL_ACCOUNT, type, 0, &rule_count, &is_completed, &rule, true, &err)) {
+ if (!emstorage_get_rule(multi_user_name, ALL_ACCOUNT, type, 0, &rule_count, &is_completed, &rule, true, &err)) {
EM_DEBUG_EXCEPTION("emstorage_get_rule failed");
goto FINISH_OFF;
}
@@ -892,8 +912,7 @@ INTERNAL_FUNC int emcore_get_mail_count_by_query(int account_id, int mailbox_typ
filter_list[k++].list_filter_item.rule.key_value.integer_type_value = mailbox_type;
}
-
- if ((err = emstorage_write_conditional_clause_for_getting_mail_list(filter_list, filter_count, NULL, 0, -1, -1, &conditional_clause_string)) != EMAIL_ERROR_NONE) {
+ if ((err = emstorage_write_conditional_clause_for_getting_mail_list(multi_user_name, filter_list, filter_count, NULL, 0, -1, -1, &conditional_clause_string)) != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("emstorage_write_conditional_clause_for_getting_mail_list failed[%d]", err);
goto FINISH_OFF;
}
@@ -901,7 +920,7 @@ INTERNAL_FUNC int emcore_get_mail_count_by_query(int account_id, int mailbox_typ
EM_DEBUG_LOG_DEV ("conditional_clause_string[%s]", conditional_clause_string);
/* Search the mail of priority sender in DB */
- if ((err = emstorage_query_mail_count(conditional_clause_string, true, &total_count, &unread_count)) != EMAIL_ERROR_NONE) {
+ if ((err = emstorage_query_mail_count(multi_user_name, conditional_clause_string, true, &total_count, &unread_count)) != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("emstorage_query_mail_count failed:[%d]", err);
goto FINISH_OFF;
}
@@ -930,13 +949,19 @@ FINISH_OFF:
return ret;
}
-INTERNAL_FUNC int emcore_display_badge_count(int count)
+INTERNAL_FUNC int emcore_display_badge_count(char *multi_user_name, int count)
{
EM_DEBUG_FUNC_BEGIN();
/* Use badge API */
int err = EMAIL_ERROR_NONE;
badge_error_e badge_err = BADGE_ERROR_NONE;
bool exist;
+ void *join_zone = NULL;
+
+ if ((err = emcore_set_join_zone(multi_user_name, &join_zone)) != EMAIL_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("emcore_set_join_zone failed : [%d]", err);
+ goto FINISH_OFF;
+ }
if((badge_err = badge_is_existing("org.tizen.email", &exist)) != BADGE_ERROR_NONE) {
EM_DEBUG_EXCEPTION("badge_is_existing failed [%d]", badge_err);
@@ -971,6 +996,9 @@ INTERNAL_FUNC int emcore_display_badge_count(int count)
FINISH_OFF:
+ if (join_zone)
+ emcore_unset_join_zone(join_zone);
+
EM_DEBUG_FUNC_END();
return err;
}
@@ -984,7 +1012,10 @@ void emcore_display_unread_in_badge(void *data)
int total_mail_count = 0;
int unseen = 0;
- if (!emcore_get_mail_count_by_query(ALL_ACCOUNT, EMAIL_MAILBOX_TYPE_INBOX, 0, &total_mail_count, &total_unread_count, &err)) {
+ if (!emcore_get_mail_count_by_query((char *)data, ALL_ACCOUNT,
+ EMAIL_MAILBOX_TYPE_INBOX, 0,
+ &total_mail_count, &total_unread_count,
+ &err)) {
EM_DEBUG_EXCEPTION("emcore_get_mail_count_by_query failed");
goto FINISH_OFF;
}
@@ -994,11 +1025,11 @@ void emcore_display_unread_in_badge(void *data)
FINISH_OFF:
if (unseen <= 0) {
- if ((err = emcore_display_badge_count(0)) != EMAIL_ERROR_NONE) {
+ if ((err = emcore_display_badge_count((char *)data, 0)) != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("emcore_display_badge_count failed : [%d]", err);
}
} else {
- if ((err = emcore_display_badge_count(unseen)) != EMAIL_ERROR_NONE) {
+ if ((err = emcore_display_badge_count((char *)data, unseen)) != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("emcore_display_badge_count failed : [%d]", err);
}
}
@@ -1018,7 +1049,7 @@ static int emcore_layout_multi_noti(notification_h noti, int unread_mail, char *
goto FINISH_OFF;
}
- noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE, "New email", dgettext(NATIVE_EMAIL_DOMAIN,"IDS_EMAIL_TPOP_NEW_EMAIL_RECEIVED_ABB"), NOTIFICATION_VARIABLE_TYPE_NONE);
+ noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE, "New emails", dgettext(NATIVE_EMAIL_DOMAIN,"IDS_EMAIL_MBODY_NEW_EMAILS_ABB"), NOTIFICATION_VARIABLE_TYPE_NONE);
if (noti_err != NOTIFICATION_ERROR_NONE) {
EM_DEBUG_EXCEPTION("notification_set_text TEXT_TYPE_TITLE failed");
goto FINISH_OFF;
@@ -1156,7 +1187,9 @@ static int emcore_get_alert_type(int vibrate_status)
int email_vibe_status = 0;
int call_state = 0;
int alert_type = EMAIL_ALERT_TYPE_MUTE;
+#ifdef __FEATURE_VOICERECORDER_STATUS_FOR_NOTI__
int voicerecoder_state = 0;
+#endif /* __FEATURE_VOICERECORDER_STATUS_FOR_NOTI__ */
if (vconf_get_bool(VCONFKEY_SETAPPL_SOUND_STATUS_BOOL, &global_sound_status) != 0) {
EM_DEBUG_LOG("vconf_get_bool for VCONFKEY_SETAPPL_SOUND_STATUS_BOOL failed");
@@ -1171,26 +1204,28 @@ static int emcore_get_alert_type(int vibrate_status)
EM_DEBUG_LOG("global_sound_status [%d] global_vibe_status [%d]", global_sound_status, global_vibe_status);
if (global_sound_status || global_vibe_status) {
-
+#ifdef __FEATURE_VOICERECORDER_STATUS_FOR_NOTI__
if (vconf_get_int(VCONFKEY_VOICERECORDER_STATE, &voicerecoder_state) != 0) {
EM_DEBUG_LOG("vconf_get_int for VCONFKEY_VOICERECORDER_STATE failed");
}
EM_DEBUG_LOG("voicerecoder_state [%d]", voicerecoder_state);
+#endif /* __FEATURE_VOICERECORDER_STATUS_FOR_NOTI__ */
- if (vconf_get_int(VCONFKEY_CALL_STATE, &call_state) != 0) {
- EM_DEBUG_LOG("vconf_get_int for VCONFKEY_CALL_STATE failed");
- }
+ call_state = emcore_get_call_status();
EM_DEBUG_LOG("call_state [%d] ", call_state);
email_vibe_status = vibrate_status;
EM_DEBUG_LOG("email_vibe_status [%d] ", email_vibe_status);
-
+#ifdef __FEATURE_VOICERECORDER_STATUS_FOR_NOTI__
if (voicerecoder_state == VCONFKEY_VOICERECORDER_RECORDING) {
alert_type = EMAIL_ALERT_TYPE_VIB;
EM_DEBUG_LOG("voice recorder is on recording...");
}
- else if (call_state > VCONFKEY_CALL_OFF && call_state < VCONFKEY_CALL_STATE_MAX) {
+/* else if (call_state > VCONFKEY_CALL_OFF && call_state < VCONFKEY_CALL_STATE_MAX) { */
+#endif /* __FEATURE_VOICERECORDER_STATUS_FOR_NOTI__ */
+
+ if (call_state > VCONFKEY_CALL_OFF && call_state < VCONFKEY_CALL_STATE_MAX) {
EM_DEBUG_LOG("Calling");
if (global_sound_status)
alert_type = EMAIL_ALERT_TYPE_MELODY;
@@ -1209,11 +1244,12 @@ static int emcore_get_alert_type(int vibrate_status)
}
FINISH_OFF:
+
EM_DEBUG_FUNC_END("alert_type [%d]", alert_type);
return alert_type;
}
-static char * emcore_get_sound_file_path(int default_ringtone_status, char *alert_ringtone_path)
+static char *emcore_get_sound_file_path(int default_ringtone_status, char *alert_ringtone_path)
{
EM_DEBUG_FUNC_BEGIN();
char *ret = NULL;
@@ -1253,7 +1289,7 @@ INTERNAL_FUNC int emcore_show_toast_popup(char *input_popup_string)
goto FINISH_OFF;
}
- ret = app_control_set_app_id(svc_handle, "com.samsung.email-tts-play");
+ ret = app_control_set_app_id(svc_handle, "org.tizen.email-tts-play");
if (ret != APP_CONTROL_ERROR_NONE) {
EM_DEBUG_LOG("app_control_set_app_id() failed! ret:[%d]", ret);
err = EMAIL_ERROR_SYSTEM_FAILURE;
@@ -1296,7 +1332,7 @@ FINISH_OFF:
#endif
-INTERNAL_FUNC int emcore_add_notification(int account_id, int mail_id, int unread_mail_count, int vip_unread_mail_count, int input_play_alert_tone, int sending_error, unsigned long display)
+INTERNAL_FUNC int emcore_add_notification(char *multi_user_name, int account_id, int mail_id, int unread_mail_count, int vip_unread_mail_count, int input_play_alert_tone, int sending_error, unsigned long display)
{
EM_DEBUG_FUNC_BEGIN("account_id[%d] mail_id[%d] unread_mail_count[%d] input_play_alert_tone[%d]", account_id, mail_id, unread_mail_count, input_play_alert_tone );
int err = EMAIL_ERROR_NONE;
@@ -1317,6 +1353,7 @@ INTERNAL_FUNC int emcore_add_notification(int account_id, int mail_id, int unrea
int display_status = false;
EMAIL_ALERT_TYPE alert_type = EMAIL_ALERT_TYPE_NONE;
char *alert_tone_path = NULL;
+ void *join_zone = NULL;
/* For service bundle */
char buf[256] = {0,};
@@ -1324,7 +1361,7 @@ INTERNAL_FUNC int emcore_add_notification(int account_id, int mail_id, int unrea
app_control_h service = NULL;
bundle *b = NULL;
- if (!emstorage_get_account_by_id(account_id, GET_FULL_DATA_WITHOUT_PASSWORD, &account_tbl, true, &err)) {
+ if (!emstorage_get_account_by_id(multi_user_name, account_id, GET_FULL_DATA_WITHOUT_PASSWORD, &account_tbl, true, &err)) {
EM_DEBUG_EXCEPTION("emstorage_get_account_by_id failed [%d]", err);
goto FINISH_OFF;
}
@@ -1335,7 +1372,7 @@ INTERNAL_FUNC int emcore_add_notification(int account_id, int mail_id, int unrea
}
/* Get the unread mail id */
- if (!emstorage_get_unread_mailid(account_id, 0, &p_mail_id, &unread_mail_count_t, &err)) {
+ if (!emstorage_get_unread_mailid(multi_user_name, account_id, 0, &p_mail_id, &unread_mail_count_t, &err)) {
EM_DEBUG_EXCEPTION("emstorage_get_unread_mailid failed [%d]", err);
goto FINISH_OFF;
}
@@ -1352,6 +1389,11 @@ INTERNAL_FUNC int emcore_add_notification(int account_id, int mail_id, int unrea
/* Turn display on to blink LED */
// emdevice_change_display_state(DISPLAY_STATE_ON);
+ if ((err = emcore_set_join_zone(multi_user_name, &join_zone)) != EMAIL_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("emcore_set_join_zone failed : [%d]", err);
+ goto FINISH_OFF;
+ }
+
noti = notification_load(NULL, private_id);
if(noti == NULL) {
EM_DEBUG_EXCEPTION("notification_load failed");
@@ -1392,7 +1434,7 @@ INTERNAL_FUNC int emcore_add_notification(int account_id, int mail_id, int unrea
goto FINISH_OFF;
}
- if ( (alert_type == EMAIL_ALERT_TYPE_MELODY_AND_VIB || alert_type == EMAIL_ALERT_TYPE_MELODY) && EM_SAFE_STRLEN(alert_tone_path)) {
+ if ((alert_type == EMAIL_ALERT_TYPE_MELODY_AND_VIB || alert_type == EMAIL_ALERT_TYPE_MELODY) && EM_SAFE_STRLEN(alert_tone_path)) {
if(strcmp(alert_tone_path, "silent") == 0) {
if ((noti_err = notification_set_sound(noti, NOTIFICATION_SOUND_TYPE_DEFAULT, NULL)) != NOTIFICATION_ERROR_NONE) {
EM_DEBUG_EXCEPTION("notification_set_sound failed [%d]", noti_err);
@@ -1409,7 +1451,7 @@ INTERNAL_FUNC int emcore_add_notification(int account_id, int mail_id, int unrea
}
}
- if ( alert_type == EMAIL_ALERT_TYPE_MELODY_AND_VIB || alert_type == EMAIL_ALERT_TYPE_VIB)
+ if (alert_type == EMAIL_ALERT_TYPE_MELODY_AND_VIB || alert_type == EMAIL_ALERT_TYPE_VIB)
noti_vibe_type = NOTIFICATION_VIBRATION_TYPE_DEFAULT;
if ((noti_err = notification_set_vibration(noti, noti_vibe_type, NULL)) != NOTIFICATION_ERROR_NONE) {
@@ -1418,13 +1460,13 @@ INTERNAL_FUNC int emcore_add_notification(int account_id, int mail_id, int unrea
goto FINISH_OFF;
}
- if ((noti_err = notification_set_text_domain(noti, NATIVE_EMAIL_DOMAIN, "/usr/apps/com.samsung.email/res/locale")) != NOTIFICATION_ERROR_NONE) {
+ if ((noti_err = notification_set_text_domain(noti, NATIVE_EMAIL_DOMAIN, "/usr/apps/org.tizen.email/res/locale")) != NOTIFICATION_ERROR_NONE) {
EM_DEBUG_EXCEPTION("notification_set_text_domain failed [%d]", noti_err);
err = EMAIL_ERROR_SYSTEM_FAILURE;
goto FINISH_OFF;
}
- if (!emstorage_get_mailbox_name_by_mailbox_type(account_id, EMAIL_MAILBOX_TYPE_INBOX, &mailbox_name, false, &err)) {
+ if (!emstorage_get_mailbox_name_by_mailbox_type(multi_user_name, account_id, EMAIL_MAILBOX_TYPE_INBOX, &mailbox_name, false, &err)) {
EM_DEBUG_EXCEPTION("emstorage_get_mailbox_name_by_mailbox_type failed [%d]", err);
goto FINISH_OFF;
}
@@ -1438,7 +1480,7 @@ INTERNAL_FUNC int emcore_add_notification(int account_id, int mail_id, int unrea
}
if (unseen == 1) {
- if (!emstorage_get_mail_by_id(p_mail_id[0], &p_mail_data, false, &err)) {
+ if (!emstorage_get_mail_by_id(multi_user_name, p_mail_id[0], &p_mail_data, false, &err)) {
EM_DEBUG_EXCEPTION("emstorage_get_mail_by_id failed [%d]", err);
goto FINISH_OFF;
}
@@ -1539,14 +1581,25 @@ INTERNAL_FUNC int emcore_add_notification(int account_id, int mail_id, int unrea
}
}
+#ifdef __FEATURE_DRIVING_MODE__
if (unseen) {
- err = emcore_start_driving_mode(p_mail_id[unseen - 1]);
+ err = emcore_start_driving_mode(multi_user_name, p_mail_id[unseen - 1]);
if (err != EMAIL_ERROR_NONE)
EM_DEBUG_EXCEPTION("emcore_start_driving_mode failed : [%d]", err);
}
+#endif /* __FEATURE_DRIVING_MODE__ */
FINISH_OFF:
+ if (service)
+ app_control_destroy(service);
+
+ if (noti)
+ notification_free(noti);
+
+ if (join_zone)
+ emcore_unset_join_zone(join_zone);
+
EM_SAFE_FREE(alert_tone_path);
EM_SAFE_FREE(p_mail_id); /* prevent */
@@ -1564,22 +1617,21 @@ FINISH_OFF:
EM_SAFE_FREE(mailbox_name);
- notification_free(noti);
-
- app_control_destroy(service);
#endif /* __FEATURE_NOTIFICATION_ENABLE__ */
EM_DEBUG_FUNC_END("ret [%d]", err);
return err;
}
-INTERNAL_FUNC int emcore_add_notification_for_send(int account_id, int mail_id, email_action_t action, int sending_error, unsigned long display)
+INTERNAL_FUNC int emcore_add_notification_for_send(char *multi_user_name, int account_id, int mail_id, email_action_t action, int sending_error, unsigned long display)
{
EM_DEBUG_FUNC_BEGIN("account_id: %d, mail_id: %d, action:%d", account_id, mail_id, action );
int err = EMAIL_ERROR_NONE;
-#ifdef __FEATURE_NOTIFICATION_ENABLE__
+#ifdef __FEATURE_NOTIFICATION_ENABLE__
int private_id = 0;
+ void *join_zone = NULL;
char *mailbox_name = NULL;
+ char *dgettext_string = NULL;
char vconf_private_id[MAX_PATH] = {0, };
notification_h noti = NULL;
notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
@@ -1592,7 +1644,7 @@ INTERNAL_FUNC int emcore_add_notification_for_send(int account_id, int mail_id,
bundle *b = NULL;
/* get general noti status */
- if (!emstorage_get_account_by_id(account_id, GET_FULL_DATA_WITHOUT_PASSWORD, &account_tbl, true, &err)) {
+ if (!emstorage_get_account_by_id(multi_user_name, account_id, GET_FULL_DATA_WITHOUT_PASSWORD, &account_tbl, true, &err)) {
EM_DEBUG_EXCEPTION("emstorage_get_account_by_id failed [%d]", err);
goto FINISH_OFF;
}
@@ -1608,19 +1660,24 @@ INTERNAL_FUNC int emcore_add_notification_for_send(int account_id, int mail_id,
}
/* Delete the previous noti */
- emcore_delete_notification_by_account(account_id, true);
+ emcore_delete_notification_by_account(multi_user_name, account_id, true);
if (g_sending_noti_handle) {
if((noti_err = notification_free(g_sending_noti_handle)) != NOTIFICATION_ERROR_NONE)
err = EMAIL_ERROR_NOTI;
g_sending_noti_handle = NULL;
}
+ if ((err = emcore_set_join_zone(multi_user_name, &join_zone)) != EMAIL_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("emcore_set_join_zone failed : [%d]", err);
+ goto FINISH_OFF;
+ }
+
if (action == EMAIL_ACTION_SENDING_MAIL)
noti = notification_create(NOTIFICATION_TYPE_ONGOING);
else
noti = notification_new(NOTIFICATION_TYPE_NOTI, NOTIFICATION_GROUP_ID_NONE, NOTIFICATION_PRIV_ID_NONE);
- if(noti == NULL) {
+ if (noti == NULL) {
EM_DEBUG_EXCEPTION("notification_new failed");
err = EMAIL_ERROR_NOTI;
goto FINISH_OFF;
@@ -1632,7 +1689,7 @@ INTERNAL_FUNC int emcore_add_notification_for_send(int account_id, int mail_id,
goto FINISH_OFF;
}
- if (!emstorage_get_mail_by_id(mail_id, &p_mail_data, false, &err)) {
+ if (!emstorage_get_mail_by_id(multi_user_name, mail_id, &p_mail_data, false, &err)) {
EM_DEBUG_EXCEPTION("emstorage_get_mail_by_id failed [%d]", err);
goto FINISH_OFF;
}
@@ -1663,130 +1720,134 @@ INTERNAL_FUNC int emcore_add_notification_for_send(int account_id, int mail_id,
switch (action) {
case EMAIL_ACTION_SEND_MAIL :
-
+/*
setlocale(LC_MESSAGES, vconf_get_str(VCONFKEY_LANGSET));
bindtextdomain("sys_string", "/usr/share/locale");
textdomain("sys_string");
+*/
+ setlocale(LC_MESSAGES, vconf_get_str(VCONFKEY_LANGSET));
+ bindtextdomain(NATIVE_EMAIL_DOMAIN, "/usr/apps/org.tizen.email/res/locale");
+ textdomain(NATIVE_EMAIL_DOMAIN);
- if (sending_error == EMAIL_ERROR_NONE) {
- /*if ((noti_err = emcore_layout_single_noti(noti, account_tbl->account_name, 1, "IDS_COM_POP_SENT", p_mail_data->date_time, p_mail_data->subject)) != NOTIFICATION_ERROR_NONE) {
- EM_DEBUG_EXCEPTION("notification_layout_single_noti failed [%d]", err);
- err = EMAIL_ERROR_SYSTEM_FAILURE;
- goto FINISH_OFF;
- }*/
+ switch(sending_error) {
+ case EMAIL_ERROR_NONE:
+ dgettext_string = dgettext(NATIVE_EMAIL_DOMAIN, "IDS_EMAIL_TPOP_EMAIL_SENT");
+ break;
+ case EMAIL_ERROR_FLIGHT_MODE_ENABLE:
+ dgettext_string = dgettext(NATIVE_EMAIL_DOMAIN, "IDS_EMAIL_TPOP_FAILED_TO_CONNECT_TO_NETWORK");
+ break;
+ case EMAIL_ERROR_NETWORK_NOT_AVAILABLE:
+ case EMAIL_ERROR_NO_SIM_INSERTED:
+ dgettext_string = dgettext(NATIVE_EMAIL_DOMAIN, "IDS_EMAIL_TPOP_NETWORK_NOT_AVAILABLE_EMAIL_WILL_BE_SENT_WHEN_CONNECTED_TO_NETWORK");
+ break;
+ case EMAIL_ERROR_SERVER_STORAGE_FULL:
+ dgettext_string = dgettext(NATIVE_EMAIL_DOMAIN, "IDS_EMAIL_TPOP_SENDING_FAILED_SERVER_STORAGE_FULL_ABB");
+ break;
+ default:
+ dgettext_string = dgettext(NATIVE_EMAIL_DOMAIN, "IDS_EMAIL_TPOP_SENDING_FAILED");
+ break;
+ }
- if ((noti_err = notification_status_message_post(dgettext(NATIVE_EMAIL_DOMAIN, "IDS_EMAIL_TPOP_EMAIL_SENT"))) != NOTIFICATION_ERROR_NONE) {
- EM_DEBUG_EXCEPTION("notification_status_message_post failed [%d]", noti_err);
- err = EMAIL_ERROR_NOTI;
- goto FINISH_OFF;
- }
+ if ((noti_err = notification_set_layout(noti,
+ NOTIFICATION_LY_NOTI_EVENT_SINGLE)) != NOTIFICATION_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("notification_set_layout failed [%d]", noti_err);
+ err = EMAIL_ERROR_NOTI;
+ goto FINISH_OFF;
+ }
- } else {
- /*if ((noti_err = emcore_layout_single_noti(noti, account_tbl->account_name, 1, "IDS_COM_POP_SENDING_FAILED", p_mail_data->date_time, p_mail_data->subject)) != NOTIFICATION_ERROR_NONE) {
- EM_DEBUG_EXCEPTION("notification_layout_single_noti failed [%d]", err);
- err = EMAIL_ERROR_SYSTEM_FAILURE;
- goto FINISH_OFF;
- }*/
-
- switch(sending_error) {
- case EMAIL_ERROR_FLIGHT_MODE_ENABLE:
- EM_DEBUG_LOG("Flight mode enable");
- if ((noti_err = notification_status_message_post(dgettext(NATIVE_EMAIL_DOMAIN, "IDS_EMAIL_TPOP_FAILED_TO_CONNECT_TO_NETWORK"))) != NOTIFICATION_ERROR_NONE)
- {
- EM_DEBUG_EXCEPTION("notification_status_message_post failed [%d]", noti_err);
- err = EMAIL_ERROR_NOTI;
- goto FINISH_OFF;
- }
- break;
+ if ((noti_err = notification_set_image(noti,
+ NOTIFICATION_IMAGE_TYPE_ICON,
+ EMAIL_NOTI_ICON_PATH)) != NOTIFICATION_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("notification_set_image failed [%d]", noti_err);
+ err = EMAIL_ERROR_NOTI;
+ goto FINISH_OFF;
+ }
- case EMAIL_ERROR_NETWORK_NOT_AVAILABLE:
- case EMAIL_ERROR_NO_SIM_INSERTED:
- if ((noti_err = notification_status_message_post(dgettext(NATIVE_EMAIL_DOMAIN, "IDS_EMAIL_TPOP_NETWORK_NOT_AVAILABLE_EMAIL_WILL_BE_SENT_WHEN_CONNECTED_TO_NETWORK"))) != NOTIFICATION_ERROR_NONE)
- {
- EM_DEBUG_EXCEPTION("notification_status_message_post failed [%d]", noti_err);
- err = EMAIL_ERROR_NOTI;
- goto FINISH_OFF;
- }
- break;
- default:
- if ((noti_err = notification_status_message_post(dgettext(NATIVE_EMAIL_DOMAIN, "IDS_EMAIL_TPOP_SENDING_FAILED"))) != NOTIFICATION_ERROR_NONE) {
- EM_DEBUG_EXCEPTION("notification_status_message_post failed [%d]", noti_err);
- err = EMAIL_ERROR_NOTI;
- goto FINISH_OFF;
- }
- }
- if ((noti_err = notification_set_layout(noti, NOTIFICATION_LY_NOTI_EVENT_SINGLE)) != NOTIFICATION_ERROR_NONE) {
- EM_DEBUG_EXCEPTION("notification_set_layout failed [%d]", noti_err);
- err = EMAIL_ERROR_NOTI;
- goto FINISH_OFF;
- }
+ if ((noti_err = notification_set_text(noti,
+ NOTIFICATION_TEXT_TYPE_TITLE,
+ p_mail_data->alias_recipient,
+ NULL,
+ NOTIFICATION_VARIABLE_TYPE_NONE)) != NOTIFICATION_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("notification_set_text failed [%d]", noti_err);
+ err = EMAIL_ERROR_NOTI;
+ goto FINISH_OFF;
+ }
- if ((noti_err = notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON, EMAIL_NOTI_ICON_PATH)) != NOTIFICATION_ERROR_NONE) {
- EM_DEBUG_EXCEPTION("notification_set_image failed [%d]", noti_err);
+ switch (sending_error) {
+ case EMAIL_ERROR_NONE:
+ if ((noti_err = notification_set_text(noti,
+ NOTIFICATION_TEXT_TYPE_CONTENT,
+ "Email Sent",
+ dgettext_string,
+ NOTIFICATION_VARIABLE_TYPE_NONE)) != NOTIFICATION_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("notification_set_text failed [%d]", noti_err);
err = EMAIL_ERROR_NOTI;
goto FINISH_OFF;
}
-
- if ((noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE, "Sending failed", dgettext(NATIVE_EMAIL_DOMAIN, "IDS_EMAIL_TPOP_SENDING_FAILED"), NOTIFICATION_VARIABLE_TYPE_NONE)) != NOTIFICATION_ERROR_NONE) {
+ break;
+ case EMAIL_ERROR_SERVER_STORAGE_FULL:
+ if ((noti_err = notification_set_text(noti,
+ NOTIFICATION_TEXT_TYPE_CONTENT,
+ "Sending failed. Server storage full.",
+ dgettext_string,
+ NOTIFICATION_VARIABLE_TYPE_NONE)) != NOTIFICATION_ERROR_NONE) {
EM_DEBUG_EXCEPTION("notification_set_text failed [%d]", noti_err);
err = EMAIL_ERROR_NOTI;
goto FINISH_OFF;
}
-
- if (p_mail_data->subject) {
- if ((noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT, p_mail_data->subject, NULL, NOTIFICATION_VARIABLE_TYPE_NONE)) != NOTIFICATION_ERROR_NONE) {
- EM_DEBUG_EXCEPTION("notification_set_text failed [%d]", noti_err);
- err = EMAIL_ERROR_NOTI;
- goto FINISH_OFF;
- }
- } else {
- if ((noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT, "No subject", NULL, NOTIFICATION_VARIABLE_TYPE_NONE)) != NOTIFICATION_ERROR_NONE) {
- EM_DEBUG_EXCEPTION("notification_set_text failed [%d]", noti_err);
- err = EMAIL_ERROR_NOTI;
- goto FINISH_OFF;
- }
- }
-
- if (sending_error == EMAIL_ERROR_SMTP_SEND_FAILURE_BY_OVERSIZE) {
- setlocale(LC_MESSAGES, vconf_get_str(VCONFKEY_LANGSET));
- bindtextdomain(NATIVE_EMAIL_DOMAIN, "/usr/apps/com.samsung.email/res/locale");
- textdomain(NATIVE_EMAIL_DOMAIN);
- if ((noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_INFO_1, dgettext(NATIVE_EMAIL_DOMAIN, "IDS_EMAIL_POP_THE_EMAIL_IS_TOO_LARGE"), NULL, NOTIFICATION_VARIABLE_TYPE_NONE)) != NOTIFICATION_ERROR_NONE) {
- EM_DEBUG_EXCEPTION("notification_set_text TEXT_TYPE_INFO_1 failed");
- err = EMAIL_ERROR_NOTI;
- goto FINISH_OFF;
- }
- }
-
- /*notification_set_execute_option(noti, NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, NULL, NULL, args);*/
-
- if ((noti_err = notification_set_display_applist(noti, NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY)) != NOTIFICATION_ERROR_NONE) {
- EM_DEBUG_EXCEPTION("notification_insert failed [%d]", noti_err);
+ break;
+ default:
+ if ((noti_err = notification_set_text(noti,
+ NOTIFICATION_TEXT_TYPE_CONTENT,
+ "Sending failed",
+ dgettext_string,
+ NOTIFICATION_VARIABLE_TYPE_NONE)) != NOTIFICATION_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("notification_set_text failed [%d]", noti_err);
err = EMAIL_ERROR_NOTI;
goto FINISH_OFF;
}
+ break;
+ }
- if ((noti_err = notification_insert(noti, &private_id)) != NOTIFICATION_ERROR_NONE) {
- EM_DEBUG_EXCEPTION("notification_insert failed [%d]", noti_err);
+ if (sending_error == EMAIL_ERROR_SMTP_SEND_FAILURE_BY_OVERSIZE) {
+ if ((noti_err = notification_set_text(noti,
+ NOTIFICATION_TEXT_TYPE_INFO_1,
+ dgettext(NATIVE_EMAIL_DOMAIN, "IDS_EMAIL_POP_THE_EMAIL_IS_TOO_LARGE"),
+ NULL,
+ NOTIFICATION_VARIABLE_TYPE_NONE)) != NOTIFICATION_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("notification_set_text TEXT_TYPE_INFO_1 failed");
err = EMAIL_ERROR_NOTI;
goto FINISH_OFF;
}
+ }
- EM_DEBUG_LOG("Private_id = [%d]", private_id);
+ if ((noti_err = notification_set_display_applist(noti,
+ NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY | NOTIFICATION_DISPLAY_APP_TICKER)) != NOTIFICATION_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("notification_insert failed [%d]", noti_err);
+ err = EMAIL_ERROR_NOTI;
+ goto FINISH_OFF;
+ }
- SNPRINTF(vconf_private_id, sizeof(vconf_private_id), "%s/%d", VCONF_KEY_NOTI_PRIVATE_ID, account_id);
- if (vconf_set_int(vconf_private_id, private_id) != 0) {
- EM_DEBUG_EXCEPTION("vconf_set_int failed");
- err = EMAIL_ERROR_GCONF_FAILURE;
- goto FINISH_OFF;
- }
+ if ((noti_err = notification_insert(noti, &private_id)) != NOTIFICATION_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("notification_insert failed [%d]", noti_err);
+ err = EMAIL_ERROR_NOTI;
+ goto FINISH_OFF;
+ }
+
+ EM_DEBUG_LOG("Private_id = [%d]", private_id);
+
+ SNPRINTF(vconf_private_id, sizeof(vconf_private_id), "%s/%d", VCONF_KEY_NOTI_PRIVATE_ID, account_id);
+ if (vconf_set_int(vconf_private_id, private_id) != 0) {
+ EM_DEBUG_EXCEPTION("vconf_set_int failed");
+ err = EMAIL_ERROR_GCONF_FAILURE;
+ goto FINISH_OFF;
}
break;
case EMAIL_ACTION_SENDING_MAIL :
- if ((noti_err = notification_set_text_domain(noti, NATIVE_EMAIL_DOMAIN, "/usr/apps/com.samsung.email/res/locale")) != NOTIFICATION_ERROR_NONE) {
+ if ((noti_err = notification_set_text_domain(noti, NATIVE_EMAIL_DOMAIN, "/usr/apps/org.tizen.email/res/locale")) != NOTIFICATION_ERROR_NONE) {
EM_DEBUG_EXCEPTION("notification_set_text_domain failed [%d]", noti_err);
err = EMAIL_ERROR_NOTI;
goto FINISH_OFF;
@@ -1834,8 +1895,8 @@ INTERNAL_FUNC int emcore_add_notification_for_send(int account_id, int mail_id,
EM_DEBUG_LOG("Private_id = [%d]", private_id);
SNPRINTF(vconf_private_id, sizeof(vconf_private_id), "%s/%d", VCONF_KEY_NOTI_PRIVATE_ID, account_id);
- if ((err = vconf_set_int (vconf_private_id, private_id)) != 0) {
- EM_DEBUG_EXCEPTION("vconf_set_int failed [%d]", err);
+ if (vconf_set_int (vconf_private_id, private_id) != 0) {
+ EM_DEBUG_EXCEPTION("vconf_set_int failed");
err = EMAIL_ERROR_GCONF_FAILURE;
goto FINISH_OFF;
}
@@ -1847,16 +1908,31 @@ INTERNAL_FUNC int emcore_add_notification_for_send(int account_id, int mail_id,
EM_DEBUG_EXCEPTION ("notification_free error [%d]", noti_err);
err = EMAIL_ERROR_NOTI;
}
+
break;
}
FINISH_OFF:
+ if (service)
+ app_control_destroy(service);
+
if ((action == EMAIL_ACTION_SEND_MAIL) && noti) {
- if( (noti_err = notification_free(noti)) != NOTIFICATION_ERROR_NONE)
+ if ((noti_err = notification_free(noti)) != NOTIFICATION_ERROR_NONE) {
err = EMAIL_ERROR_NOTI;
+ }
}
+ if ((action != EMAIL_ACTION_SEND_MAIL) && (err != EMAIL_ERROR_NONE)) {
+ if (noti) {
+ notification_free(noti);
+ g_sending_noti_handle = NULL;
+ }
+ }
+
+ if (join_zone)
+ emcore_unset_join_zone(join_zone);
+
if (p_mail_data)
emstorage_free_mail(&p_mail_data, 1, NULL);
@@ -1865,7 +1941,6 @@ FINISH_OFF:
EM_SAFE_FREE(mailbox_name);
- app_control_destroy(service);
#endif /* __FEATURE_NOTIFICATION_ENABLE__ */
EM_DEBUG_FUNC_END("ret [%d]", err);
@@ -1894,7 +1969,7 @@ INTERNAL_FUNC void emcore_update_notification_for_send(int account_id, int mail_
EM_DEBUG_FUNC_END();
}
-INTERNAL_FUNC int emcore_show_user_message(int id, email_action_t action, int error)
+INTERNAL_FUNC int emcore_show_user_message(char *multi_user_name, int id, email_action_t action, int error)
{
EM_DEBUG_FUNC_BEGIN("id[%d], action[%d], error[%d]", id, action, error);
@@ -1910,13 +1985,13 @@ INTERNAL_FUNC int emcore_show_user_message(int id, email_action_t action, int er
return false;
}
- if (!emstorage_get_mail_by_id(id, &mail_table_data, true, NULL)) {
+ if (!emstorage_get_mail_by_id(multi_user_name, id, &mail_table_data, true, NULL)) {
EM_DEBUG_LOG("Mail not found");
return false;
}
EM_DEBUG_LOG ("smtp_stream : sent_end");
- if (emcore_add_notification_for_send(mail_table_data->account_id, id, action, error, display) != EMAIL_ERROR_NONE) {
+ if (emcore_add_notification_for_send(multi_user_name, mail_table_data->account_id, id, action, error, display) != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("emcore_notification_set error");
goto FINISH_OFF;
}
@@ -1939,8 +2014,8 @@ int emcore_get_storage_status(void)
EM_DEBUG_FUNC_BEGIN();
int storage_status = 0, nError = 0;
-#if !GLIB_CHECK_VERSION(2, 36, 0)
- g_type_init();
+#if !GLIB_CHECK_VERSION(2, 36, 0)
+ g_type_init();
#endif
#ifdef STORAGE_STATUS
@@ -1985,7 +2060,7 @@ FINISH_OFF:
return err;
}
-int emcore_calc_mail_size(email_mail_data_t *input_mail_data, email_attachment_data_t *input_attachment_data_list, int input_attachment_count, int *output_size)
+int emcore_calc_mail_size(char *multi_user_name, email_mail_data_t *input_mail_data, email_attachment_data_t *input_attachment_data_list, int input_attachment_count, int *output_size)
{
EM_DEBUG_FUNC_BEGIN("input_mail_data[%p], input_attachment_data_list[%p], input_attachment_count[%d], output_size[%p]", input_mail_data, input_attachment_data_list, input_attachment_count, output_size);
@@ -1993,6 +2068,8 @@ int emcore_calc_mail_size(email_mail_data_t *input_mail_data, email_attachment_d
int mail_size = 0; /* size of the plain text body and attachments */
int err = EMAIL_ERROR_NONE;
int i = 0;
+ char *prefix_path = NULL;
+ char real_file_path[255] = {0};
if (!input_mail_data || (input_attachment_count && !input_attachment_data_list) || (!input_attachment_count &&input_attachment_data_list) || !output_size) {
EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
@@ -2000,8 +2077,21 @@ int emcore_calc_mail_size(email_mail_data_t *input_mail_data, email_attachment_d
goto FINISH_OFF;
}
+ if (EM_SAFE_STRLEN(multi_user_name) > 0) {
+ err = emcore_get_container_path(multi_user_name, &prefix_path);
+ if (err != EMAIL_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("emcore_get_container_path failed :[%d]", err);
+ goto FINISH_OFF;
+ }
+ } else {
+ prefix_path = strdup("");
+ }
+
if (input_mail_data->file_path_plain != NULL) {
- if (stat(input_mail_data->file_path_plain, &st_buf) < 0) {
+ memset(real_file_path, 0x00, sizeof(real_file_path));
+ SNPRINTF(real_file_path, sizeof(real_file_path), "%s%s", prefix_path, input_mail_data->file_path_plain);
+
+ if (stat(real_file_path, &st_buf) < 0) {
EM_DEBUG_EXCEPTION_SEC("input_mail_data->file_path_plain : stat(\"%s\") failed...", input_mail_data->file_path_plain);
err = EMAIL_ERROR_FILE_NOT_FOUND;
goto FINISH_OFF;
@@ -2012,7 +2102,10 @@ int emcore_calc_mail_size(email_mail_data_t *input_mail_data, email_attachment_d
}
if (input_mail_data->file_path_html != NULL) {
- if (stat(input_mail_data->file_path_html, &st_buf) < 0) {
+ memset(real_file_path, 0x00, sizeof(real_file_path));
+ SNPRINTF(real_file_path, sizeof(real_file_path), "%s%s", prefix_path, input_mail_data->file_path_html);
+
+ if (stat(real_file_path, &st_buf) < 0) {
EM_DEBUG_EXCEPTION_SEC("input_mail_data->file_path_html : stat(\"%s\") failed...", input_mail_data->file_path_html);
err = EMAIL_ERROR_FILE_NOT_FOUND;
goto FINISH_OFF;
@@ -2022,7 +2115,10 @@ int emcore_calc_mail_size(email_mail_data_t *input_mail_data, email_attachment_d
}
for(i = 0; i < input_attachment_count; i++) {
- if (stat(input_attachment_data_list[i].attachment_path, &st_buf) < 0) {
+ memset(real_file_path, 0x00, sizeof(real_file_path));
+ SNPRINTF(real_file_path, sizeof(real_file_path), "%s%s", prefix_path, input_attachment_data_list[i].attachment_path);
+
+ if (stat(real_file_path, &st_buf) < 0) {
EM_DEBUG_EXCEPTION("stat(\"%s\") failed...", input_attachment_data_list[i].attachment_path);
err = EMAIL_ERROR_FILE_NOT_FOUND;
goto FINISH_OFF;
@@ -2034,6 +2130,8 @@ int emcore_calc_mail_size(email_mail_data_t *input_mail_data, email_attachment_d
FINISH_OFF:
+ EM_SAFE_FREE(prefix_path);
+
EM_DEBUG_FUNC_END("mail_size [%d]", mail_size);
return err;
}
@@ -2050,8 +2148,9 @@ char *emcore_get_alias_of_mailbox(const char *mailbox_path)
gchar *mailbox = NULL, *name = NULL;
char *converted_name;
+
mailbox = g_strdup(mailbox_path);
- token_list = g_strsplit_set(mailbox, "/", -1);
+ token_list = g_strsplit_set(mailbox, "/\\", -1);
if(token_list == NULL) {
EM_DEBUG_LOG("g_strsplit_set failed.");
@@ -2139,7 +2238,7 @@ FINISH_OFF:
return err;
}
-void emcore_fill_address_information_of_mail_tbl(emstorage_mail_tbl_t *mail_data)
+void emcore_fill_address_information_of_mail_tbl(char *multi_user_name, emstorage_mail_tbl_t *mail_data)
{
EM_DEBUG_FUNC_BEGIN("mail_data [%p]", mail_data);
@@ -2154,7 +2253,7 @@ void emcore_fill_address_information_of_mail_tbl(emstorage_mail_tbl_t *mail_data
email_account_t *ref_account = NULL;
- ref_account = emcore_get_account_reference(mail_data->account_id);
+ ref_account = emcore_get_account_reference(multi_user_name, mail_data->account_id, false);
if (!ref_account) {
EM_DEBUG_LOG("emcore_get_account_reference failed [%d]", mail_data->account_id);
}
@@ -2346,7 +2445,7 @@ FINISH_OFF:
}
#ifdef __FEATURE_BODY_SEARCH__
-int emcore_strip_mail_body_from_file(emstorage_mail_tbl_t *mail, char **stripped_text, int *err_code)
+int emcore_strip_mail_body_from_file(char *multi_user_name, emstorage_mail_tbl_t *mail, char **stripped_text, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("mail[%p]", mail);
@@ -2355,8 +2454,11 @@ int emcore_strip_mail_body_from_file(emstorage_mail_tbl_t *mail, char **stripped
char *buf = NULL;
char *encoding_type = NULL;
char *utf8_encoded_string = NULL;
- unsigned int byte_read = 0;
- unsigned int byte_written = 0;
+ char *prefix_path = NULL;
+ char real_html_path[255] = {0};
+ char real_plain_path[255] = {0};
+ gsize byte_read = 0;
+ gsize byte_written = 0;
GError *glib_error = NULL;
FILE *fp_plain = NULL;
struct stat st_buf;
@@ -2367,23 +2469,34 @@ int emcore_strip_mail_body_from_file(emstorage_mail_tbl_t *mail, char **stripped
goto FINISH_OFF;
}
- /* MAX_PREVIEW_TEXT_LENGTH */
+ if (EM_SAFE_STRLEN(multi_user_name) > 0) {
+ err = emcore_get_container_path(multi_user_name, &prefix_path);
+ if (err != EMAIL_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("emcore_get_container_path failed :[%d]", err);
+ goto FINISH_OFF;
+ }
+ } else {
+ prefix_path = strdup("");
+ }
/* read file to buf & strip if html text */
if (mail->file_path_html) {
char result_buffer[MAX_PREVIEW_TEXT_LENGTH] = { 0, };
+
if (mail->preview_text) {
*stripped_text = EM_SAFE_STRDUP(mail->preview_text);
ret = true;
goto FINISH_OFF;
}
+ SNPRINTF(real_html_path, sizeof(real_html_path), "%s%s", prefix_path, mail->file_path_html);
+
if ((err = em_get_encoding_type_from_file_path(mail->file_path_plain, &encoding_type)) != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("em_get_encoding_type_from_file_path failed [%d]", err);
goto FINISH_OFF;
}
- if ((err = emcore_strip_HTML_tag(mail->file_path_html, encoding_type, result_buffer, MAX_PREVIEW_TEXT_LENGTH)) != EMAIL_ERROR_NONE) {
+ if ((err = emcore_strip_HTML_tag(real_html_path, encoding_type, result_buffer, MAX_PREVIEW_TEXT_LENGTH)) != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("emcore_strip_HTML_tag failed");
goto FINISH_OFF;
}
@@ -2392,21 +2505,23 @@ int emcore_strip_mail_body_from_file(emstorage_mail_tbl_t *mail, char **stripped
}
if (!buf && mail->file_path_plain) {
+ SNPRINTF(real_plain_path, sizeof(real_plain_path), "%s%s", prefix_path, mail->file_path_plain);
+
if ((err = em_get_encoding_type_from_file_path(mail->file_path_plain, &encoding_type)) != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("em_get_encoding_type_from_file_path failed [%d]", err);
goto FINISH_OFF;
}
memset(&st_buf, 0, sizeof(struct stat));
- if (stat(mail->file_path_plain, &st_buf) < 0) {
- EM_DEBUG_EXCEPTION_SEC("stat(\"%s\") failed...", mail->file_path_plain);
+ if (stat(real_plain_path, &st_buf) < 0) {
+ EM_DEBUG_EXCEPTION_SEC("stat(\"%s\") failed...", real_plain_path);
err = EMAIL_ERROR_INVALID_MAIL;
goto FINISH_OFF;
}
- err = em_fopen(mail->file_path_plain, "r", &fp_plain);
+ err = em_fopen(real_plain_path, "r", &fp_plain);
if (err != EMAIL_ERROR_NONE) {
- EM_DEBUG_EXCEPTION_SEC("em_fopen failed [%s]", mail->file_path_plain);
+ EM_DEBUG_EXCEPTION_SEC("em_fopen failed [%s]", real_plain_path);
goto FINISH_OFF;
}
@@ -2427,7 +2542,7 @@ int emcore_strip_mail_body_from_file(emstorage_mail_tbl_t *mail, char **stripped
EM_SAFE_FREE(buf);
err = EMAIL_ERROR_NULL_VALUE;
if (ferror(fp_plain)) {
- EM_DEBUG_EXCEPTION_SEC("fread failed [%s]", mail->file_path_plain);
+ EM_DEBUG_EXCEPTION_SEC("fread failed [%s]", real_plain_path);
err = EMAIL_ERROR_SYSTEM_FAILURE;
}
goto FINISH_OFF;
@@ -2453,19 +2568,22 @@ int emcore_strip_mail_body_from_file(emstorage_mail_tbl_t *mail, char **stripped
if(utf8_encoded_string == NULL) {
if (!g_error_matches(glib_error, G_CONVERT_ERROR, G_CONVERT_ERROR_ILLEGAL_SEQUENCE)) {
+ EM_SAFE_FREE(*stripped_text);
*stripped_text = EM_SAFE_STRDUP(buf);
goto FINISH_OFF;
}
EM_DEBUG_LOG("Extract the preview text, again");
- utf8_encoded_string = (char *)g_convert(buf, byte_read, "UTF-8", encoding_type, &byte_read, &byte_written, &glib_error);
+ utf8_encoded_string = (char *)g_convert(buf, -1, "UTF-8", encoding_type, &byte_read, &byte_written, &glib_error);
if (utf8_encoded_string == NULL) {
+ EM_SAFE_FREE(*stripped_text);
*stripped_text = EM_SAFE_STRDUP(buf);
goto FINISH_OFF;
}
}
EM_SAFE_FREE(buf);
+ EM_SAFE_FREE(*stripped_text);
*stripped_text = EM_SAFE_STRDUP(utf8_encoded_string);
} else {
EM_SAFE_FREE(*stripped_text);
@@ -2481,6 +2599,7 @@ FINISH_OFF:
*err_code = err;
EM_SAFE_FREE(buf);
+ EM_SAFE_FREE(prefix_path);
EM_SAFE_FREE(encoding_type);
EM_SAFE_FREE(utf8_encoded_string);
@@ -2493,13 +2612,13 @@ FINISH_OFF:
#endif
-int emcore_get_preview_text_from_file(const char *input_plain_path, const char *input_html_path, int input_preview_buffer_length, char **output_preview_buffer)
+int emcore_get_preview_text_from_file(char *multi_user_name, const char *input_plain_path, const char *input_html_path, int input_preview_buffer_length, char **output_preview_buffer)
{
EM_DEBUG_FUNC_BEGIN("input_plain_path[%p], input_html_path[%p], input_preview_buffer_length [%d], output_preview_buffer[%p]", input_plain_path, input_html_path, input_preview_buffer_length, output_preview_buffer);
int err = EMAIL_ERROR_NONE;
- unsigned int byte_read = 0;
- unsigned int byte_written = 0;
+ gsize byte_read = 0;
+ gsize byte_written = 0;
int local_preview_buffer_length = 0;
char *local_preview_text = NULL;
char *encoding_type = NULL;
@@ -2507,6 +2626,8 @@ int emcore_get_preview_text_from_file(const char *input_plain_path, const char *
FILE *fp_plain = NULL;
GError *glib_error = NULL;
struct stat st_buf;
+ char *prefix_path = NULL;
+ char real_file_path[255] = {0};
if (!output_preview_buffer) {
EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
@@ -2516,23 +2637,40 @@ int emcore_get_preview_text_from_file(const char *input_plain_path, const char *
local_preview_buffer_length = input_preview_buffer_length * 2;
- if ( input_html_path ) { /*prevent 26249*/
+ if (EM_SAFE_STRLEN(multi_user_name) > 0) {
+ err = emcore_get_container_path(multi_user_name, &prefix_path);
+ if (err != EMAIL_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("emcore_get_container_path failed :[%d]", err);
+ goto FINISH_OFF;
+ }
+ } else {
+ prefix_path = strdup("");
+ }
+
+ if (input_html_path) { /*prevent 26249*/
/* get preview text from html file */
char result_buffer[MAX_PREVIEW_TEXT_LENGTH] = { 0, };
+ memset(real_file_path, 0x00, sizeof(real_file_path));
+ SNPRINTF(real_file_path, sizeof(real_file_path), "%s%s", prefix_path, input_html_path);
+
if( (err = em_get_encoding_type_from_file_path(input_html_path, &encoding_type)) != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("em_get_encoding_type_from_file_path failed [%d]", err);
goto FINISH_OFF;
}
- if ((err = emcore_strip_HTML_tag(input_html_path, encoding_type, result_buffer, MAX_PREVIEW_TEXT_LENGTH)) != EMAIL_ERROR_NONE) {
+ if ((err = emcore_strip_HTML_tag(real_file_path, encoding_type, result_buffer, MAX_PREVIEW_TEXT_LENGTH)) != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("emcore_strip_HTML_tag failed");
goto FINISH_OFF;
}
local_preview_text = EM_SAFE_STRDUP(result_buffer);
}
- if ( !local_preview_text && input_plain_path) { /*prevent 26249*/
+ if (!local_preview_text && input_plain_path) { /*prevent 26249*/
+
+ memset(real_file_path, 0x00, sizeof(real_file_path));
+ SNPRINTF(real_file_path, sizeof(real_file_path), "%s%s", prefix_path, input_plain_path);
+
/* get preview text from plain text file */
if( (err = em_get_encoding_type_from_file_path(input_plain_path, &encoding_type)) != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("em_get_encoding_type_from_file_path failed [%d]", err);
@@ -2540,13 +2678,13 @@ int emcore_get_preview_text_from_file(const char *input_plain_path, const char *
}
memset(&st_buf, 0, sizeof(struct stat));
- if (stat(input_plain_path, &st_buf) < 0) {
+ if (stat(real_file_path, &st_buf) < 0) {
EM_DEBUG_EXCEPTION("stat(\"%s\") failed...", input_plain_path);
err = EMAIL_ERROR_INVALID_MAIL;
goto FINISH_OFF;
}
- err = em_fopen(input_plain_path, "r", &fp_plain);
+ err = em_fopen(real_file_path, "r", &fp_plain);
if (err != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("em_fopen failed [%s]", input_plain_path);
goto FINISH_OFF;
@@ -2590,7 +2728,7 @@ int emcore_get_preview_text_from_file(const char *input_plain_path, const char *
encoding_type = EM_SAFE_STRDUP("EUC-KR");
}
- utf8_encoded_string = (char*)g_convert (local_preview_text, -1, "UTF-8", encoding_type, &byte_read, &byte_written, &glib_error);
+ utf8_encoded_string = (char *)g_convert(local_preview_text, -1, "UTF-8", encoding_type, &byte_read, &byte_written, &glib_error);
if(utf8_encoded_string == NULL) {
if (!g_error_matches (glib_error, G_CONVERT_ERROR, G_CONVERT_ERROR_ILLEGAL_SEQUENCE)) {
@@ -2598,7 +2736,7 @@ int emcore_get_preview_text_from_file(const char *input_plain_path, const char *
}
EM_DEBUG_LOG("Extract the preview text, again");
- utf8_encoded_string = (char *)g_convert(local_preview_text, byte_read, "UTF-8", encoding_type, &byte_read, &byte_written, &glib_error);
+ utf8_encoded_string = (char *)g_convert(local_preview_text, -1, "UTF-8", encoding_type, &byte_read, &byte_written, &glib_error);
if (utf8_encoded_string == NULL) {
EM_DEBUG_LOG("g_convert fail, again");
goto FINISH_OFF;
@@ -2621,6 +2759,7 @@ FINISH_OFF:
EM_SAFE_FREE(local_preview_text);
EM_SAFE_FREE(encoding_type);
+ EM_SAFE_FREE(prefix_path);
if (fp_plain != NULL)
fclose(fp_plain);
@@ -2816,41 +2955,46 @@ FINISH_OFF:
}
-INTERNAL_FUNC int reg_replace_new (char **input_source_text, char *input_old_pattern_string, char *input_new_string)
+INTERNAL_FUNC char *reg_replace_new(char *input_source_text, char *input_old_pattern_string, char *input_new_string)
{
char *replaced_str = NULL;
- int error_code = EMAIL_ERROR_NONE;
GRegex *regex = NULL;
GError *error = NULL;
- if (input_source_text == NULL || *input_source_text == NULL) {
- return EMAIL_ERROR_INVALID_PARAM;
+ if (input_source_text == NULL) {
+ EM_DEBUG_EXCEPTION("Invalid parameter");
+ return NULL;
}
regex = g_regex_new(input_old_pattern_string, G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, &error);
-
if (!regex) {
EM_DEBUG_LOG("g_regex_new failed");
- error_code = EMAIL_ERROR_SYSTEM_FAILURE;
goto FINISH_OFF;
}
- replaced_str = g_regex_replace_literal(regex, *input_source_text, EM_SAFE_STRLEN(*input_source_text), 0, input_new_string, 0, &error);
-
- EM_SAFE_FREE(*input_source_text);
-
- *input_source_text = replaced_str;
+ replaced_str = g_regex_replace_literal(regex,
+ input_source_text,
+ strlen(input_source_text),
+ 0,
+ input_new_string,
+ 0,
+ &error);
+ if (replaced_str == NULL) {
+ EM_DEBUG_EXCEPTION("g_regex_replace_literal failed : [%s][%d]", error->message, error->code);
+ goto FINISH_OFF;
+ }
FINISH_OFF:
+
+ if (regex) g_regex_unref(regex);
- g_regex_unref(regex);
- return error_code;
+ return replaced_str;
}
#include <libxml/HTMLparser.h>
-static void emcore_get_content_string(xmlNode *input_node, char *input_result_buffer, int input_result_buffer_legnth, int *input_exit_flag)
+static void emcore_get_content_string(xmlNode *input_node, char *input_result_buffer, int input_result_buffer_length, int *input_exit_flag)
{
xmlNode *cur_node = NULL;
char *temp_content_string = NULL;
@@ -2864,41 +3008,60 @@ static void emcore_get_content_string(xmlNode *input_node, char *input_result_bu
if (cur_node->name && (strcasecmp((const char *)cur_node->name, "head") == 0 || strcasecmp((const char *)cur_node->name, "title") == 0))
continue;
+ if (cur_node->name && (strcasecmp((const char *)cur_node->name, "BR") == 0)) {
+ if (EM_SAFE_STRLEN(input_result_buffer) + 1 >= input_result_buffer_length) {
+ *input_exit_flag = 1;
+ break;
+ } else {
+ EM_SAFE_STRCAT(input_result_buffer, " ");
+ continue;
+ }
+ }
+
if (cur_node->type == XML_TEXT_NODE && cur_node->content) {
- if ((EM_SAFE_STRLEN(cur_node->content) + EM_SAFE_STRLEN(input_result_buffer)) >= input_result_buffer_legnth) {
+ if ((EM_SAFE_STRLEN(cur_node->content) + EM_SAFE_STRLEN(input_result_buffer)) >= input_result_buffer_length) {
int len1 = EM_SAFE_STRLEN(input_result_buffer);
- if (len1 >= 0 && len1 < input_result_buffer_legnth) {
- int remain_size = input_result_buffer_legnth - len1 - 2;
- char *remain_str = em_malloc(remain_size);
- if (remain_str && cur_node->content) {
- snprintf(remain_str, remain_size, "%s", (char*)(cur_node->content));
- }
+ if (len1 >= 0 && len1 < input_result_buffer_length) {
+ int remain_size = input_result_buffer_length - len1 - 2;
+ EM_DEBUG_LOG("remain_size : [%d], len1 : [%d]", remain_size, len1);
+ char *remain_str = NULL;
- if (remain_str)
- EM_SAFE_STRCAT(input_result_buffer, remain_str);
+ if (remain_size > 0)
+ remain_str = g_strndup((char *)(cur_node->content), remain_size);
- EM_SAFE_FREE(remain_str);
+ if (remain_str) {
+ char *replaced_string = NULL;
+ replaced_string = reg_replace_new(remain_str, "[ \t\r\n\v\f]+", " ");
+ EM_SAFE_STRCAT(input_result_buffer, replaced_string);
+ EM_SAFE_FREE(replaced_string);
+ free(remain_str);
+ }
}
*input_exit_flag = 1;
break;
}
+
temp_content_string = EM_SAFE_STRDUP((const char *)cur_node->content);
if (temp_content_string) {
- reg_replace_new(&temp_content_string, "[ \t\r\n\v\f]+", " ");
- EM_SAFE_STRCAT(input_result_buffer, temp_content_string);
- EM_SAFE_FREE(temp_content_string);
+ char *replaced_string = NULL;
+ replaced_string = reg_replace_new(temp_content_string, "[ \t\r\n\v\f]+", " ");
+ EM_SAFE_STRCAT(input_result_buffer, replaced_string);
+ EM_SAFE_FREE(replaced_string);
+ free(temp_content_string);
}
}
if (cur_node->children)
- emcore_get_content_string(cur_node->children, input_result_buffer, input_result_buffer_legnth, input_exit_flag);
+ emcore_get_content_string(cur_node->children, input_result_buffer, input_result_buffer_length, input_exit_flag);
if (*input_exit_flag == 1)
break;
}
+
FINISH_OFF:
+
return;
}
@@ -2925,7 +3088,6 @@ int emcore_strip_HTML_tag(const char *input_html_file_path, char *input_encoding
}
result_string = em_malloc(sizeof(char) * input_result_buffer_legnth);
-
if (result_string == NULL) {
EM_DEBUG_EXCEPTION("EMAIL_ERROR_OUT_OF_MEMORY");
err = EMAIL_ERROR_OUT_OF_MEMORY;
@@ -2954,11 +3116,11 @@ int emcore_strip_HTML_tag(const char *input_html_file_path, char *input_encoding
root_element = xmlDocGetRootElement(result_html_document);
-
emcore_get_content_string(root_element, result_string, input_result_buffer_legnth, &exit_flag);
- reg_replace_new(&result_string, "[ \t\r\n\v\f]+", " ");
- EM_SAFE_STRCPY(output_result_buffer, result_string);
- // em_trim_left(output_result_buffer);
+ char *replaced_string = reg_replace_new(result_string, "[ \t\r\n\v\f]+", " ");
+ EM_SAFE_STRCPY(output_result_buffer, replaced_string);
+ EM_SAFE_FREE(replaced_string);
+ em_trim_left(output_result_buffer);
FINISH_OFF:
if (result_html_document) {
@@ -3035,10 +3197,9 @@ int convert_app_err_to_email_err(int app_error)
return err;
}
-INTERNAL_FUNC int emcore_start_driving_mode(int mail_id)
+INTERNAL_FUNC int emcore_start_driving_mode(char *multi_user_name, int mail_id)
{
EM_DEBUG_FUNC_BEGIN();
-
int err = APP_CONTROL_ERROR_NONE;
int tts_enable = 0;
char string_mail[10] = { 0 };
@@ -3066,7 +3227,7 @@ INTERNAL_FUNC int emcore_start_driving_mode(int mail_id)
if (!tts_enable)
goto FINISH_OFF;
- if (!emstorage_get_mail_by_id(mail_id, &p_mail_data, false, NULL)) {
+ if (!emstorage_get_mail_by_id(multi_user_name, mail_id, &p_mail_data, false, NULL)) {
EM_DEBUG_EXCEPTION("emstorage_get_mail_by_id failed");
goto FINISH_OFF;
}
@@ -3113,30 +3274,30 @@ FINISH_OFF:
}
#endif /* __FEATURE_DRIVING_MODE__ */
-INTERNAL_FUNC int emcore_clear_notifications(int account_id)
+INTERNAL_FUNC int emcore_clear_notifications(char *multi_user_name, int account_id)
{
int account_count = 0, i;
emstorage_account_tbl_t *account_list;
int error_code = EMAIL_ERROR_NONE;
if (account_id == ALL_ACCOUNT) {
- if(!emstorage_get_account_list(&account_count, &account_list, true, false, &error_code)) {
+ if(!emstorage_get_account_list(multi_user_name, &account_count, &account_list, true, false, &error_code)) {
EM_DEBUG_EXCEPTION("emstorage_get_account_list failed");
goto FINISH_OFF;
}
for(i = 0; i < account_count; i++) {
- error_code = emcore_delete_notification_by_account(account_list[i].account_id, true);
+ error_code = emcore_delete_notification_by_account(multi_user_name, account_list[i].account_id, true);
if (error_code != EMAIL_ERROR_NONE)
EM_DEBUG_EXCEPTION("emcore_delete_notification_by_account failed");
}
} else {
- error_code = emcore_delete_notification_by_account(account_id, true);
+ error_code = emcore_delete_notification_by_account(multi_user_name, account_id, true);
if (error_code != EMAIL_ERROR_NONE)
EM_DEBUG_EXCEPTION("emcore_delete_notification_by_account failed");
}
- if (!emstorage_update_save_status(account_id, &error_code)) {
+ if (!emstorage_update_save_status(multi_user_name, account_id, &error_code)) {
EM_DEBUG_EXCEPTION("emstorage_update_save_status failed : [%d]", error_code);
goto FINISH_OFF;
}
@@ -3153,7 +3314,7 @@ FINISH_OFF:
#define EAS_EXECUTABLE_PATH "/usr/bin/eas-engine"
-INTERNAL_FUNC int emcore_delete_notification_by_account(int account_id, int with_noti_tray)
+INTERNAL_FUNC int emcore_delete_notification_by_account(char *multi_user_name, int account_id, int with_noti_tray)
{
EM_DEBUG_FUNC_BEGIN("account_id [%d]", account_id);
int error_code = EMAIL_ERROR_NONE;
@@ -3950,7 +4111,7 @@ static int emcore_get_next_peak_start_time(emstorage_account_tbl_t *input_accoun
if (time_info == NULL) {
EM_DEBUG_EXCEPTION("localtime failed");
err = EMAIL_ERROR_SYSTEM_FAILURE;
- goto FINISH_OFF;
+ goto FINISH_OFF;
}
EM_DEBUG_LOG("input time and date: %s", asctime(time_info));
@@ -4024,7 +4185,7 @@ static int emcore_check_time_in_peak_schedule(emstorage_account_tbl_t *input_acc
if (time_info == NULL) {
EM_DEBUG_EXCEPTION("localtime failed");
err = EMAIL_ERROR_SYSTEM_FAILURE;
- goto FINISH_OFF;
+ goto FINISH_OFF;
}
EM_DEBUG_LOG("input time and date: %s", asctime(time_info));
@@ -4061,7 +4222,7 @@ FINISH_OFF:
return err;
}
-INTERNAL_FUNC int emcore_calc_next_time_to_sync(int input_account_id, time_t input_current_time, time_t *output_time)
+INTERNAL_FUNC int emcore_calc_next_time_to_sync(char *multi_user_name, int input_account_id, time_t input_current_time, time_t *output_time)
{
EM_DEBUG_FUNC_BEGIN("input_account_id[%d] input_current_time[%d] output_time[%p]", input_account_id, input_current_time, output_time);
int err = EMAIL_ERROR_NONE;
@@ -4071,7 +4232,7 @@ INTERNAL_FUNC int emcore_calc_next_time_to_sync(int input_account_id, time_t inp
time_t result_time = 0;
int is_time_in_peak_schedule = 0;
- emstorage_get_account_by_id(input_account_id, EMAIL_ACC_GET_OPT_DEFAULT, &account, true, &err);
+ emstorage_get_account_by_id(multi_user_name, input_account_id, EMAIL_ACC_GET_OPT_DEFAULT, &account, true, &err);
if (account == NULL) {
EM_DEBUG_EXCEPTION("emstorage_get_account_by_id failed [%d]",err);
goto FINISH_OFF;
@@ -4171,14 +4332,14 @@ static int convert_contact_err_to_email_err(int contact_err)
return err;
}
-int emcore_get_mail_contact_info(email_mail_contact_info_t *contact_info, char *full_address, int *err_code)
+int emcore_get_mail_contact_info(char *multi_user_name, email_mail_contact_info_t *contact_info, char *full_address, int *err_code)
{
EM_DEBUG_FUNC_BEGIN_SEC("contact_info[%p], full_address[%s], err_code[%p]", contact_info, full_address, err_code);
int ret = false;
int err = EMAIL_ERROR_NONE;
- if (!emcore_get_mail_contact_info_with_update(contact_info, full_address, 0, &err))
+ if (!emcore_get_mail_contact_info_with_update(multi_user_name, contact_info, full_address, 0, &err))
EM_DEBUG_EXCEPTION("emcore_get_mail_contact_info_with_update failed [%d]", err);
else
ret = true;
@@ -4189,7 +4350,7 @@ int emcore_get_mail_contact_info(email_mail_contact_info_t *contact_info, char *
return ret;
}
-int emcore_search_contact_info(const char *contact_uri, int address_property_id, char *address, int favorite_property_id, bool is_favorite, int limit, contacts_record_h *contacts_record)
+int emcore_search_contact_info(char *multi_user_name, const char *contact_uri, int address_property_id, char *address, int favorite_property_id, bool is_favorite, int limit, contacts_record_h *contacts_record)
{
EM_DEBUG_FUNC_BEGIN();
int contact_err = CONTACTS_ERROR_NONE;
@@ -4198,6 +4359,15 @@ int emcore_search_contact_info(const char *contact_uri, int address_property_id,
contacts_filter_h filter = NULL;
contacts_list_h list = NULL;
+ void *join_zone = NULL;
+
+ if (EM_SAFE_STRLEN(multi_user_name) > 0) {
+ if (emcore_set_join_zone(multi_user_name, &join_zone) != EMAIL_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("emcore_set_join_zone failed");
+ goto FINISH_OFF;
+ }
+ }
+
if ((contact_err = contacts_query_create(contact_uri, &query)) != CONTACTS_ERROR_NONE) {
EM_DEBUG_EXCEPTION("contacts_query_create failed");
goto FINISH_OFF;
@@ -4249,10 +4419,13 @@ FINISH_OFF:
if (list != NULL)
contacts_list_destroy(list, false);
+ if (join_zone)
+ emcore_unset_join_zone(join_zone);
+
return contact_err;
}
-int emcore_search_contact_info_by_address(const char *contact_uri, int property_id, char *address, int limit, contacts_record_h *contacts_record)
+int emcore_search_contact_info_by_address(char *multi_user_name, const char *contact_uri, int property_id, char *address, int limit, contacts_record_h *contacts_record)
{
EM_DEBUG_FUNC_BEGIN();
int contact_err = CONTACTS_ERROR_NONE;
@@ -4261,6 +4434,15 @@ int emcore_search_contact_info_by_address(const char *contact_uri, int property_
contacts_filter_h filter = NULL;
contacts_list_h list = NULL;
+ void *join_zone = NULL;
+
+ if (EM_SAFE_STRLEN(multi_user_name) > 0) {
+ if (emcore_set_join_zone(multi_user_name, &join_zone) != EMAIL_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("emcore_set_join_zone failed");
+ goto FINISH_OFF;
+ }
+ }
+
if ((contact_err = contacts_query_create(contact_uri, &query)) != CONTACTS_ERROR_NONE) {
EM_DEBUG_EXCEPTION("contacts_query_create failed");
goto FINISH_OFF;
@@ -4303,6 +4485,9 @@ FINISH_OFF:
if (list != NULL)
contacts_list_destroy(list, false);
+ if (join_zone)
+ emcore_unset_join_zone(join_zone);
+
return contact_err;
}
@@ -4310,6 +4495,7 @@ typedef struct {
int account_id;
char *email_address;
char *subject;
+ char *multi_user_name;
time_t date_time;
email_action_t action;
} set_contacts_log_internal_t;
@@ -4326,6 +4512,7 @@ gboolean emcore_set_contacts_log_internal (void* arg)
char *subject = tmp->subject;
time_t date_time = tmp->date_time;
email_action_t action = tmp->action;
+ char *multi_user_name = tmp->multi_user_name;
int contacts_error = CONTACTS_ERROR_NONE;
int person_id = 0;
@@ -4334,12 +4521,15 @@ gboolean emcore_set_contacts_log_internal (void* arg)
contacts_record_h phone_record = NULL;
contacts_record_h person_record = NULL;
-/*
- if ((contacts_error = contacts_connect_on_thread()) != CONTACTS_ERROR_NONE) {
- EM_DEBUG_EXCEPTION("Open connect service failed [%d]", contacts_error);
- goto FINISH_OFF;
+ void *join_zone = NULL;
+
+ if (EM_SAFE_STRLEN(multi_user_name) > 0) {
+ if (emcore_set_join_zone(multi_user_name, &join_zone) != EMAIL_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("emcore_set_join_zone failed");
+ goto FINISH_OFF;
+ }
}
-*/
+
if ((contacts_error = contacts_record_create(_contacts_phone_log._uri, &phone_record)) != CONTACTS_ERROR_NONE) {
EM_DEBUG_EXCEPTION("contacts_query_create failed [%d]", contacts_error);
goto FINISH_OFF;
@@ -4352,7 +4542,7 @@ gboolean emcore_set_contacts_log_internal (void* arg)
}
/* Search contact person info */
- if ((contacts_error = emcore_search_contact_info_by_address(_contacts_person_email._uri, _contacts_person_email.email, email_address, 1, &person_record)) != CONTACTS_ERROR_NONE) {
+ if ((contacts_error = emcore_search_contact_info_by_address(multi_user_name, _contacts_person_email._uri, _contacts_person_email.email, email_address, 1, &person_record)) != CONTACTS_ERROR_NONE) {
if (contacts_error != CONTACTS_ERROR_NO_DATA) /* no matching record found */
EM_DEBUG_EXCEPTION("emcore_search_contact_info_by_address failed [%d]", contacts_error);
} else {
@@ -4419,12 +4609,9 @@ FINISH_OFF:
if (person_record != NULL)
contacts_record_destroy(person_record, false);
-/*
- if ((contacts_error = contacts_disconnect_on_thread()) != CONTACTS_ERROR_NONE) {
- EM_DEBUG_EXCEPTION("Open connect service failed [%d]", contacts_error);
- err = convert_contact_err_to_email_err(contacts_error);
- }
-*/
+ if (join_zone)
+ emcore_unset_join_zone(join_zone);
+
EM_SAFE_FREE (email_address);
EM_SAFE_FREE (subject);
EM_SAFE_FREE (tmp);
@@ -4433,11 +4620,12 @@ FINISH_OFF:
return FALSE;
}
-int emcore_set_contacts_log (int account_id,
- char *email_address,
- char *subject,
- time_t date_time,
- email_action_t action)
+int emcore_set_contacts_log (char *multi_user_name,
+ int account_id,
+ char *email_address,
+ char *subject,
+ time_t date_time,
+ email_action_t action)
{
/* arg shall be destroyed in emcore_set_contacts_log_internal */
set_contacts_log_internal_t *arg = em_malloc (sizeof(set_contacts_log_internal_t));
@@ -4447,18 +4635,19 @@ int emcore_set_contacts_log (int account_id,
}
/* deep copy */
- arg->account_id = account_id;
- arg->email_address = EM_SAFE_STRDUP (email_address);
- arg->subject = EM_SAFE_STRDUP (subject);
- arg->date_time = date_time;
- arg->action = action;
+ arg->account_id = account_id;
+ arg->email_address = EM_SAFE_STRDUP (email_address);
+ arg->subject = EM_SAFE_STRDUP (subject);
+ arg->date_time = date_time;
+ arg->action = action;
+ arg->multi_user_name = EM_SAFE_STRDUP (multi_user_name);
g_main_context_invoke (NULL, emcore_set_contacts_log_internal, arg);
return EMAIL_ERROR_NONE;
}
-INTERNAL_FUNC int emcore_set_sent_contacts_log(emstorage_mail_tbl_t *input_mail_data)
+INTERNAL_FUNC int emcore_set_sent_contacts_log(char *multi_user_name, emstorage_mail_tbl_t *input_mail_data)
{
EM_DEBUG_FUNC_BEGIN("input_mail_data : [%p]", input_mail_data);
@@ -4474,7 +4663,12 @@ INTERNAL_FUNC int emcore_set_sent_contacts_log(emstorage_mail_tbl_t *input_mail_
rfc822_parse_adrlist(&addr, address_array[i], NULL);
for (p_addr = addr ; p_addr ;p_addr = p_addr->next) {
SNPRINTF(email_address, MAX_EMAIL_ADDRESS_LENGTH, "%s@%s", addr->mailbox, addr->host);
- if ((err = emcore_set_contacts_log(input_mail_data->account_id, email_address, input_mail_data->subject, input_mail_data->date_time, EMAIL_ACTION_SEND_MAIL)) != EMAIL_ERROR_NONE) {
+ if ((err = emcore_set_contacts_log(multi_user_name,
+ input_mail_data->account_id,
+ email_address,
+ input_mail_data->subject,
+ input_mail_data->date_time,
+ EMAIL_ACTION_SEND_MAIL)) != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("emcore_set_contacts_log failed : [%d]", err);
goto FINISH_OFF;
}
@@ -4497,12 +4691,17 @@ FINISH_OFF:
}
-INTERNAL_FUNC int emcore_set_received_contacts_log(emstorage_mail_tbl_t *input_mail_data)
+INTERNAL_FUNC int emcore_set_received_contacts_log(char *multi_user_name, emstorage_mail_tbl_t *input_mail_data)
{
EM_DEBUG_FUNC_BEGIN("input_mail_data : [%p]", input_mail_data);
int err = EMAIL_ERROR_NONE;
- if ((err = emcore_set_contacts_log(input_mail_data->account_id, input_mail_data->email_address_sender, input_mail_data->subject, input_mail_data->date_time, EMAIL_ACTION_SYNC_HEADER)) != EMAIL_ERROR_NONE) {
+ if ((err = emcore_set_contacts_log(multi_user_name,
+ input_mail_data->account_id,
+ input_mail_data->email_address_sender,
+ input_mail_data->subject,
+ input_mail_data->date_time,
+ EMAIL_ACTION_SYNC_HEADER)) != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("emcore_set_contacts_log failed [%d]", err);
}
@@ -4510,45 +4709,63 @@ INTERNAL_FUNC int emcore_set_received_contacts_log(emstorage_mail_tbl_t *input_m
return err;
}
+typedef struct _contacts_delete_data
+{
+ int account_id;
+ char *multi_user_name;
+} contacts_delete_data;
+
gboolean emcore_delete_contacts_log_internal(void* arg)
{
EM_DEBUG_FUNC_BEGIN();
-
- int account_id = (int) arg; /* it is not a pointer */
+ contacts_delete_data *data = (contacts_delete_data *)arg;
int contacts_error = CONTACTS_ERROR_NONE;
-/*
- if ((contacts_error = contacts_connect_on_thread()) != CONTACTS_ERROR_NONE) {
- EM_DEBUG_EXCEPTION("Open connect service failed [%d]", contacts_error);
- goto FINISH_OFF;
+ void *join_zone = NULL;
+
+ if (EM_SAFE_STRLEN(data->multi_user_name) > 0) {
+ if (emcore_set_join_zone(data->multi_user_name, &join_zone) != EMAIL_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("emcore_set_join_zone failed");
+ return FALSE;
+ }
}
-*/
+
/* Delete record of the account id */
- if ((contacts_error = contacts_phone_log_delete(CONTACTS_PHONE_LOG_DELETE_BY_EMAIL_EXTRA_DATA1, account_id)) != CONTACTS_ERROR_NONE) {
+ if ((contacts_error = contacts_phone_log_delete(CONTACTS_PHONE_LOG_DELETE_BY_EMAIL_EXTRA_DATA1, data->account_id)) != CONTACTS_ERROR_NONE) {
EM_DEBUG_EXCEPTION("contacts_phone_log_delete failed [%d]", contacts_error);
}
-
/* err = convert_contact_err_to_email_err(contacts_error); */
-/*
- if ((contacts_error = contacts_disconnect_on_thread()) != CONTACTS_ERROR_NONE) {
- EM_DEBUG_EXCEPTION("Open connect service failed [%d]", contacts_error);
- err = convert_contact_err_to_email_err(contacts_error);
- }
-*/
+ if (join_zone)
+ emcore_unset_join_zone(join_zone);
+
+ EM_SAFE_FREE(data->multi_user_name);
+ EM_SAFE_FREE(data);
+
EM_DEBUG_FUNC_END();
return FALSE;
}
-INTERNAL_FUNC int emcore_delete_contacts_log(int account_id)
+INTERNAL_FUNC int emcore_delete_contacts_log(char *multi_user_name, int account_id)
{
- g_main_context_invoke (NULL, emcore_delete_contacts_log_internal, (void*) account_id);
+ contacts_delete_data *data = NULL;
+
+ data = (contacts_delete_data *)em_malloc(sizeof(contacts_delete_data));
+ if (data == NULL) {
+ EM_DEBUG_EXCEPTION("em_malloc failed");
+ return EMAIL_ERROR_OUT_OF_MEMORY;
+ }
+
+ data->account_id = account_id;
+ data->multi_user_name = EM_SAFE_STRDUP(multi_user_name);
+
+ g_main_context_invoke (NULL, emcore_delete_contacts_log_internal, (void*) data);
return EMAIL_ERROR_NONE;
}
-INTERNAL_FUNC int emcore_get_mail_display_name (char *email_address, char **contact_display_name)
+INTERNAL_FUNC int emcore_get_mail_display_name (char *multi_user_name, char *email_address, char **contact_display_name)
{
if (!email_address || !contact_display_name) {
EM_DEBUG_EXCEPTION ("NULL_PARAM email_address[%p] contact_display_name[%p]",
@@ -4560,8 +4777,8 @@ INTERNAL_FUNC int emcore_get_mail_display_name (char *email_address, char **cont
GVariant *result = NULL;
int ret = EMAIL_ERROR_NONE;
-#if !GLIB_CHECK_VERSION(2, 36, 0)
- g_type_init();
+#if !GLIB_CHECK_VERSION(2, 36, 0)
+ g_type_init();
#endif
GDBusProxy* bproxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
@@ -4581,7 +4798,7 @@ INTERNAL_FUNC int emcore_get_mail_display_name (char *email_address, char **cont
result = g_dbus_proxy_call_sync (bproxy,
"GetDisplayName",
- g_variant_new ("(s)", email_address),
+ g_variant_new ("(ss)", email_address, multi_user_name),
G_DBUS_CALL_FLAGS_NONE,
-1,
NULL,
@@ -4589,7 +4806,7 @@ INTERNAL_FUNC int emcore_get_mail_display_name (char *email_address, char **cont
if (!result) {
- EM_DEBUG_EXCEPTION ("g_dbus_proxy_call_sync 'SetContactsLog' error [%s]",
+ EM_DEBUG_EXCEPTION ("g_dbus_proxy_call_sync 'GetDisplayName' error [%s]",
gerror->message);
ret = EMAIL_ERROR_IPC_PROTOCOL_FAILURE;
goto FINISH_OFF;
@@ -4614,8 +4831,9 @@ FINISH_OFF:
}
-INTERNAL_FUNC int emcore_get_mail_display_name_internal (char *email_address,
- char **contact_display_name)
+INTERNAL_FUNC int emcore_get_mail_display_name_internal (char *multi_user_name,
+ char *email_address,
+ char **contact_display_name)
{
EM_DEBUG_FUNC_BEGIN_SEC("contact_name_value[%s], contact_display_name[%p]", email_address, contact_display_name);
@@ -4632,7 +4850,7 @@ INTERNAL_FUNC int emcore_get_mail_display_name_internal (char *email_address,
goto FINISH_OFF;
}
*/
- if ((contact_err = emcore_search_contact_info_by_address(_contacts_contact_email._uri, _contacts_contact_email.email, email_address, 1, &record)) != CONTACTS_ERROR_NONE) {
+ if ((contact_err = emcore_search_contact_info_by_address(multi_user_name, _contacts_contact_email._uri, _contacts_contact_email.email, email_address, 1, &record)) != CONTACTS_ERROR_NONE) {
if (contact_err != CONTACTS_ERROR_NO_DATA) /* no matching record found */
EM_DEBUG_EXCEPTION("emcore_search_contact_info_by_address failed [%d]", contact_err);
goto FINISH_OFF;
@@ -4680,34 +4898,58 @@ FINISH_OFF:
return err;
}
-INTERNAL_FUNC int emcore_connect_contacts_service()
+INTERNAL_FUNC int emcore_connect_contacts_service(char *multi_user_name)
{
EM_DEBUG_FUNC_BEGIN();
int contact_err = 0;
int err = EMAIL_ERROR_NONE;
+ void *join_zone = NULL;
+
+ if (EM_SAFE_STRLEN(multi_user_name) > 0) {
+ if ((err = emcore_set_join_zone(multi_user_name, &join_zone)) != EMAIL_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("emcore_set_join_zone failed : [%d]", err);
+ return err;
+ }
+ }
+
if ((contact_err = contacts_connect()) != CONTACTS_ERROR_NONE) {
EM_DEBUG_EXCEPTION("contacts_connect failed : [%d]", contact_err);
}
err = convert_contact_err_to_email_err(contact_err);
+ if (join_zone)
+ emcore_unset_join_zone(join_zone);
+
EM_DEBUG_FUNC_END();
return err;
}
-INTERNAL_FUNC int emcore_disconnect_contacts_service()
+INTERNAL_FUNC int emcore_disconnect_contacts_service(char *multi_user_name)
{
EM_DEBUG_FUNC_BEGIN();
int contact_err = 0;
int err = EMAIL_ERROR_NONE;
+ void *join_zone = NULL;
+
+ if (EM_SAFE_STRLEN(multi_user_name) > 0) {
+ if ((err = emcore_set_join_zone(multi_user_name, &join_zone)) != EMAIL_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("emcore_set_join_zone failed : [%d]", err);
+ return err;
+ }
+ }
+
if ((contact_err = contacts_disconnect()) != CONTACTS_ERROR_NONE) {
- EM_DEBUG_EXCEPTION("contacts_connect failed : [%d]", contact_err);
+ EM_DEBUG_EXCEPTION("contacts_disconnect failed : [%d]", contact_err);
}
err = convert_contact_err_to_email_err(contact_err);
+ if (join_zone)
+ emcore_unset_join_zone(join_zone);
+
EM_DEBUG_FUNC_END();
return err;
}
@@ -4740,7 +4982,7 @@ INTERNAL_FUNC void emcore_set_blocking_mode_status(int blocking_mode)
blocking_mode_status = blocking_mode;
}
-INTERNAL_FUNC int emcore_check_blocking_mode (char *sender_address, int *blocking_status)
+INTERNAL_FUNC int emcore_check_blocking_mode (char *multi_user_name, char *sender_address, int *blocking_status)
{
if ( !sender_address || !blocking_status ) {
EM_DEBUG_EXCEPTION ("NULL_PARAM sender_address[%p] blocking_status[%p]",
@@ -4748,12 +4990,13 @@ INTERNAL_FUNC int emcore_check_blocking_mode (char *sender_address, int *blockin
return EMAIL_ERROR_INVALID_PARAM;
}
+
GError *gerror = NULL;
GVariant *result = NULL;
int ret = EMAIL_ERROR_NONE;
-#if !GLIB_CHECK_VERSION(2, 36, 0)
- g_type_init();
+#if !GLIB_CHECK_VERSION(2, 36, 0)
+ g_type_init();
#endif
GDBusProxy* bproxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
@@ -4773,7 +5016,7 @@ INTERNAL_FUNC int emcore_check_blocking_mode (char *sender_address, int *blockin
result = g_dbus_proxy_call_sync (bproxy,
"CheckBlockingMode",
- g_variant_new ("(s)", sender_address),
+ g_variant_new ("(ss)", sender_address, multi_user_name),
G_DBUS_CALL_FLAGS_NONE,
-1,
NULL,
@@ -4781,7 +5024,7 @@ INTERNAL_FUNC int emcore_check_blocking_mode (char *sender_address, int *blockin
if (!result) {
- EM_DEBUG_EXCEPTION ("g_dbus_proxy_call_sync 'SetContactsLog' error [%s]",
+ EM_DEBUG_EXCEPTION ("g_dbus_proxy_call_sync 'CheckBlockingMode' error [%s]",
gerror->message);
ret = EMAIL_ERROR_IPC_PROTOCOL_FAILURE;
goto FINISH_OFF;
@@ -4800,7 +5043,7 @@ FINISH_OFF:
return ret;
}
-INTERNAL_FUNC int emcore_check_blocking_mode_internal (char *sender_address, int *blocking_status)
+INTERNAL_FUNC int emcore_check_blocking_mode_internal (char *multi_user_name, char *sender_address, int *blocking_status)
{
EM_DEBUG_FUNC_BEGIN();
int err = EMAIL_ERROR_NONE;
@@ -4813,7 +5056,6 @@ INTERNAL_FUNC int emcore_check_blocking_mode_internal (char *sender_address, int
contacts_record_h record = NULL;
if (!blocking_mode_of_setting) {
-
return err;
}
@@ -4837,7 +5079,7 @@ INTERNAL_FUNC int emcore_check_blocking_mode_internal (char *sender_address, int
case ALLOWED_CONTACT_TYPE_ALL :
EM_DEBUG_LOG("allowed_contact_type is ALL");
/* Search the allowed contact type in contact DB */
- if ((contact_error = emcore_search_contact_info_by_address(_contacts_person_email._uri, _contacts_person_email.email, sender_address, 1, &record)) != CONTACTS_ERROR_NONE) {
+ if ((contact_error = emcore_search_contact_info_by_address(multi_user_name, _contacts_person_email._uri, _contacts_person_email.email, sender_address, 1, &record)) != CONTACTS_ERROR_NONE) {
if (contact_error != CONTACTS_ERROR_NO_DATA) /* no matching record found */
EM_DEBUG_EXCEPTION("emcore_search_contact_info_by_address failed [%d]", contact_error);
goto FINISH_OFF;
@@ -4852,7 +5094,7 @@ INTERNAL_FUNC int emcore_check_blocking_mode_internal (char *sender_address, int
break;
case ALLOWED_CONTACT_TYPE_FAVORITES :
- if ((contact_error = emcore_search_contact_info(_contacts_person_email._uri, _contacts_person_email.email, sender_address, _contacts_person_email.is_favorite, true, 1, &record)) != CONTACTS_ERROR_NONE) {
+ if ((contact_error = emcore_search_contact_info(multi_user_name, _contacts_person_email._uri, _contacts_person_email.email, sender_address, _contacts_person_email.is_favorite, true, 1, &record)) != CONTACTS_ERROR_NONE) {
EM_DEBUG_EXCEPTION("emcore_search_contact_info failed : [%d]", contact_error);
goto FINISH_OFF;
}
@@ -4872,7 +5114,7 @@ INTERNAL_FUNC int emcore_check_blocking_mode_internal (char *sender_address, int
goto FINISH_OFF;
}
- if ((contact_error = emcore_search_contact_info_by_address(_contacts_person_email._uri, _contacts_person_email.email, sender_address, 1, &record)) != CONTACTS_ERROR_NONE) {
+ if ((contact_error = emcore_search_contact_info_by_address(multi_user_name, _contacts_person_email._uri, _contacts_person_email.email, sender_address, 1, &record)) != CONTACTS_ERROR_NONE) {
if (contact_error != CONTACTS_ERROR_NO_DATA) /* no matching record found */
EM_DEBUG_EXCEPTION("emcore_search_contact_info_by_address failed [%d]", contact_error);
goto FINISH_OFF;
@@ -4976,31 +5218,6 @@ FINISH_OFF:
return mime_entity_path;
}
-/* Feedback LED api */
-INTERNAL_FUNC void emcore_set_flash_noti()
-{
- EM_DEBUG_FUNC_BEGIN();
- int flash_error = FEEDBACK_ERROR_NONE;
-
- flash_error = feedback_initialize();
- if (flash_error != FEEDBACK_ERROR_NONE) {
- EM_DEBUG_EXCEPTION("feedback_initialize failed : [%d]", flash_error);
- return;
- }
-
- flash_error = feedback_play_type(FEEDBACK_TYPE_LED, FEEDBACK_PATTERN_EMAIL);
- if (flash_error != FEEDBACK_ERROR_NONE) {
- EM_DEBUG_EXCEPTION("feedback_play_type failed : [%d]", flash_error);
- }
-
- flash_error = feedback_deinitialize();
- if (flash_error != FEEDBACK_ERROR_NONE) {
- EM_DEBUG_EXCEPTION("feedback_play_type failed : [%d]", flash_error);
- }
-
- EM_DEBUG_FUNC_END();
-}
-
INTERNAL_FUNC int emcore_get_content_from_file(char *filename, char **contents, int *length)
{
EM_DEBUG_FUNC_BEGIN("filename[%s], contents[%p], length[%p]", filename, contents, length);
@@ -5152,12 +5369,12 @@ FINISH_OFF:
#ifdef __FEATURE_UPDATE_DB_TABLE_SCHEMA__
-INTERNAL_FUNC int emcore_update_db_table_schema()
+INTERNAL_FUNC int emcore_update_db_table_schema(char *multi_user_name)
{
EM_DEBUG_FUNC_BEGIN();
int err = EMAIL_ERROR_NONE;
- err = emstorage_update_db_table_schema();
+ err = emstorage_update_db_table_schema(multi_user_name);
EM_DEBUG_FUNC_END("err[%d]", err);
return err;
@@ -5361,4 +5578,119 @@ FINISH_OFF:
EM_DEBUG_FUNC_END("err [%d]", err);
return err;
}
+
+/* Replace the VCONFKEY_CALL_STATE to dbus */
+#ifdef __FEATURE_DBUS_CALL_STATUS__
+
+static pthread_mutex_t call_status_mutex = PTHREAD_MUTEX_INITIALIZER;
+static int call_status = 0;
+static guint g_dbus_return_id = 0;
+GDBusConnection *call_status_connection = NULL;
+
+static void call_status_dbus_callback(GDBusConnection *connection,
+ const gchar *sender_name,
+ const gchar *object_path,
+ const gchar *interface_name,
+ const gchar *signal_name,
+ GVariant *parameters,
+ gpointer data)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ int call_status_t = 0;
+ int call_type_t = 0;
+ char *phone_number_t = NULL;
+
+ if (strncasecmp(interface_name, "org.tizen.callmgr", strlen("org.tizen.callmgr")) &&
+ strncasecmp(sender_name, "CallStatus", strlen("CallStatus"))) {
+ EM_DEBUG_EXCEPTION("Invalid interface : [%s]", interface_name);
+ return;
+ }
+
+ g_variant_get(parameters, "(iis)",
+ &call_status_t,
+ &call_type_t,
+ &phone_number_t);
+
+ EM_DEBUG_LOG("Call status : [%d], Call type : [%d], Phone_number : [%s]", call_status_t, call_type_t, phone_number_t);
+
+ ENTER_CRITICAL_SECTION(call_status_mutex);
+ call_status = call_status_t;
+ LEAVE_CRITICAL_SECTION(call_status_mutex);
+
+ EM_SAFE_FREE(phone_number_t);
+
+ EM_DEBUG_FUNC_END();
+}
+
+INTERNAL_FUNC int emcore_init_dbus_call_status()
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int err = EMAIL_ERROR_NONE;
+ GError *error = NULL;
+
+ call_status_connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
+ if (call_status_connection == NULL) {
+ EM_DEBUG_EXCEPTION("g_bus_get_sync failed : [%s]", error->message);
+ err = EMAIL_ERROR_SYSTEM_FAILURE;
+ goto FINISH_OFF;
+ }
+
+ g_dbus_return_id = g_dbus_connection_signal_subscribe(call_status_connection,
+ NULL,
+ "org.tizen.callmgr",
+ "CallStatus",
+ "/org/tizen/callmgr",
+ NULL,
+ G_DBUS_SIGNAL_FLAGS_NONE,
+ call_status_dbus_callback,
+ NULL,
+ NULL);
+ if (g_dbus_return_id == -1) {
+ EM_DEBUG_EXCEPTION("DBus connection failed");
+ err = EMAIL_ERROR_SYSTEM_FAILURE;
+ goto FINISH_OFF;
+ }
+
+FINISH_OFF:
+
+ if (error)
+ g_error_free(error);
+
+ EM_DEBUG_FUNC_END();
+ return err;
+}
+
+INTERNAL_FUNC void emcore_shutdown_dbus_call_status()
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ if (g_dbus_return_id) {
+ g_dbus_connection_signal_unsubscribe(call_status_connection, g_dbus_return_id);
+ g_dbus_return_id = 0;
+ }
+
+ if (call_status_connection) {
+ g_object_unref(call_status_connection);
+ call_status_connection = NULL;
+ }
+
+ EM_DEBUG_FUNC_END();
+}
+
+INTERNAL_FUNC int emcore_get_call_status()
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int call_status_t = 0;
+
+ ENTER_CRITICAL_SECTION(call_status_mutex);
+ call_status_t = call_status;
+ LEAVE_CRITICAL_SECTION(call_status_mutex);
+
+ EM_DEBUG_FUNC_END();
+ return call_status_t;
+}
+
+#endif /* __FEATURE_DBUS_CALL_STATUS__ */
+
/* EOF */
diff --git a/email-core/email-network/email-network.c b/email-core/email-network/email-network.c
index 04d44e8..ce47151 100755
--- a/email-core/email-network/email-network.c
+++ b/email-core/email-network/email-network.c
@@ -154,10 +154,10 @@ INTERNAL_FUNC int emnetwork_check_network_status(int *err_code)
int err = EMAIL_ERROR_NONE;
int ret = false;
- if(network_status == 0) {
+ if (network_status == 0) {
EM_DEBUG_LOG("VCONFKEY_NETWORK_STATUS is 0");
- if ( (err = _get_flight_mode(&flight_mode)) != EMAIL_ERROR_NONE) {
+ if ((err = _get_flight_mode(&flight_mode)) != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("_get_flight_mode failed : [%d]", err);
goto FINISH_OFF;
}
@@ -168,7 +168,7 @@ INTERNAL_FUNC int emnetwork_check_network_status(int *err_code)
goto FINISH_OFF;
}
- if ( (err = emnetwork_get_wifi_status(&wifi_status)) != EMAIL_ERROR_NONE) {
+ if ((err = emnetwork_get_wifi_status(&wifi_status)) != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("emnetwork_get_wifi_status failed [%d]", err);
goto FINISH_OFF;
}
diff --git a/email-core/email-storage/email-storage.c b/email-core/email-storage/email-storage.c
index e684653..b6b81d3 100755
--- a/email-core/email-storage/email-storage.c
+++ b/email-core/email-storage/email-storage.c
@@ -62,11 +62,10 @@
#include "email-convert.h"
#include "email-core-signal.h"
#include "email-core-event.h"
-
-#define DB_STMT sqlite3_stmt *
+#include "email-core-container.h"
+#include "email-core-gmime.h"
#define SETTING_MEMORY_TEMP_FILE_PATH "/tmp/email_tmp_file"
-
#define CONTENT_DATA "<head><meta http-equiv=\"Content-Type\" content=\"text/html; charset="
#define CONTENT_TYPE_DATA "<meta http-equiv=\"Content-Type\" content=\"text/html; charset="
@@ -143,10 +142,10 @@
#define CERTIFICATE_PATH_LEN_IN_MAIL_ACCOUNT_TBL 256
/* this define is used for query to change data (delete, insert, update) */
-#define EMSTORAGE_START_WRITE_TRANSACTION(transaction_flag, error_code) \
+#define EMSTORAGE_START_WRITE_TRANSACTION(multi_user_name, transaction_flag, error_code) \
do {\
if (transaction_flag) {\
- if (emstorage_begin_transaction(NULL, NULL, &error_code) == false) {\
+ if (emstorage_begin_transaction(multi_user_name, NULL, NULL, &error_code) == false) {\
EM_DEBUG_EXCEPTION("emstorage_begin_transaction error [%d]", error_code);\
goto FINISH_OFF;\
}\
@@ -154,18 +153,18 @@
} while(0)
/* this define is used for query to change data (delete, insert, update) */
-#define EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction_flag, result_code, error_code) \
+#define EMSTORAGE_FINISH_WRITE_TRANSACTION(multi_user_name, transaction_flag, result_code, error_code) \
do {\
if (transaction_flag) {\
if (result_code == true) {\
- if (emstorage_commit_transaction(NULL, NULL, NULL) == false) {\
+ if (emstorage_commit_transaction(multi_user_name, NULL, NULL, NULL) == false) {\
EM_DEBUG_EXCEPTION("emstorage_commit_transaction error");\
error_code = EMAIL_ERROR_DB_FAILURE;\
result_code = false;\
}\
}\
else {\
- if (emstorage_rollback_transaction(NULL, NULL, NULL) == false) {\
+ if (emstorage_rollback_transaction(multi_user_name, NULL, NULL, NULL) == false) {\
EM_DEBUG_EXCEPTION("emstorage_rollback_transaction error");\
error_code = EMAIL_ERROR_DB_FAILURE;\
}\
@@ -177,14 +176,14 @@
#define EMSTORAGE_START_READ_TRANSACTION(transaction_flag) \
if (transaction_flag)\
{\
- /*_timedlock_shm_mutex(&mapped_for_db_lock, 2);*/\
+ /*_timedlock_shm_mutex(mapped_for_db_lock, 2);*/\
}
/* this define is used for query to read (select) */
#define EMSTORAGE_FINISH_READ_TRANSACTION(transaction_flag) \
if (transaction_flag)\
{\
- /*_unlockshm_mutex(&mapped_for_db_lock);*/\
+ /*_unlockshm_mutex(mapped_for_db_lock);*/\
}
/* for safety DB operation */
@@ -199,6 +198,7 @@ static pthread_mutex_t _ss_handle_lock = PTHREAD_MUTEX_INITIALIZER;
typedef struct
{
+ char *user_name;
pthread_t thread_id;
sqlite3 *db_handle;
} db_handle_t;
@@ -206,24 +206,43 @@ typedef struct
#define MAX_DB_CLIENT 100
/* static int _db_handle_count = 0; */
-db_handle_t _db_handle_list[MAX_DB_CLIENT] = {{0, 0}, };
+db_handle_t _db_handle_list[MAX_DB_CLIENT] = {{NULL, 0, 0}, };
+
-sqlite3 *emstorage_get_db_handle()
+sqlite3 *emstorage_get_db_handle(char *multi_user_name)
{
EM_DEBUG_FUNC_BEGIN();
int i;
pthread_t current_thread_id = THREAD_SELF();
sqlite3 *result_db_handle = NULL;
- ENTER_CRITICAL_SECTION(_db_handle_lock);
- for (i = 0; i < MAX_DB_CLIENT; i++) {
- if (pthread_equal(current_thread_id, _db_handle_list[i].thread_id)) {
- EM_DEBUG_LOG_DEV("found db handle at [%d]", i);
- result_db_handle = _db_handle_list[i].db_handle;
- break;
+ if (EM_SAFE_STRLEN(multi_user_name) > 0) {
+ ENTER_CRITICAL_SECTION(_db_handle_lock);
+ for (i = 0; i < MAX_DB_CLIENT; i++) {
+ if (EM_SAFE_STRCASECMP(_db_handle_list[i].user_name, multi_user_name) != 0)
+ continue;
+
+ if (pthread_equal(current_thread_id, _db_handle_list[i].thread_id)) {
+ EM_DEBUG_LOG_DEV("found db handle at [%d]", i);
+ result_db_handle = _db_handle_list[i].db_handle;
+ break;
+ }
}
+ LEAVE_CRITICAL_SECTION(_db_handle_lock);
+ } else {
+ ENTER_CRITICAL_SECTION(_db_handle_lock);
+ for (i = 0; i < MAX_DB_CLIENT; i++) {
+ if (EM_SAFE_STRLEN(_db_handle_list[i].user_name) > 0)
+ continue;
+
+ if (pthread_equal(current_thread_id, _db_handle_list[i].thread_id)) {
+ EM_DEBUG_LOG_DEV("found db handle at [%d]", i);
+ result_db_handle = _db_handle_list[i].db_handle;
+ break;
+ }
+ }
+ LEAVE_CRITICAL_SECTION(_db_handle_lock);
}
- LEAVE_CRITICAL_SECTION(_db_handle_lock);
if (!result_db_handle)
EM_DEBUG_LOG("no db_handle for [%d] found", current_thread_id);
@@ -232,7 +251,7 @@ sqlite3 *emstorage_get_db_handle()
return result_db_handle;
}
-int emstorage_set_db_handle(sqlite3 *db_handle)
+int emstorage_set_db_handle(char *multi_user_name, sqlite3 *db_handle)
{
EM_DEBUG_FUNC_BEGIN();
int i, error_code = EMAIL_ERROR_MAX_EXCEEDED;
@@ -243,6 +262,8 @@ int emstorage_set_db_handle(sqlite3 *db_handle)
if (_db_handle_list[i].thread_id == 0) {
_db_handle_list[i].thread_id = current_thread_id;
_db_handle_list[i].db_handle = db_handle;
+ /* Only distinguished container and host */
+ _db_handle_list[i].user_name = EM_SAFE_STRDUP(multi_user_name);
EM_DEBUG_LOG("current_thread_id [%d], index [%d]", current_thread_id, i);
error_code = EMAIL_ERROR_NONE;
break;
@@ -268,6 +289,8 @@ int emstorage_remove_db_handle()
{
_db_handle_list[i].thread_id = 0;
_db_handle_list[i].db_handle = NULL;
+ EM_SAFE_FREE(_db_handle_list[i].user_name);
+
EM_DEBUG_LOG("index [%d]", i);
error_code = EMAIL_ERROR_NONE;
break;
@@ -282,7 +305,6 @@ int emstorage_remove_db_handle()
return error_code;
}
-
int emstorage_reset_db_handle_list()
{
EM_DEBUG_FUNC_BEGIN();
@@ -293,6 +315,7 @@ int emstorage_reset_db_handle_list()
{
_db_handle_list[i].thread_id = 0;
_db_handle_list[i].db_handle = NULL;
+ EM_SAFE_FREE(_db_handle_list[i].user_name);
}
LEAVE_CRITICAL_SECTION(_db_handle_lock)
@@ -300,9 +323,10 @@ int emstorage_reset_db_handle_list()
return EMAIL_ERROR_NONE;
}
-sqlite3 *emstorage_get_db_connection()
+
+sqlite3 *emstorage_get_db_connection(char *multi_user_name)
{
- return emstorage_db_open(NULL);
+ return emstorage_db_open(multi_user_name, NULL);
}
#else /* _MULTIPLE_DB_HANDLE */
@@ -336,9 +360,9 @@ int shm_fd_for_generating_mail_id = 0;
#ifdef __FEATURE_USE_SHARED_MUTEX_FOR_PROTECTED_FUNC_CALL__
#define EMSTORAGE_PROTECTED_FUNC_CALL(function_call, return_value) \
do {\
- _timedlock_shm_mutex(&mapped_for_db_lock, 2);\
+ _timedlock_shm_mutex(mapped_for_db_lock, 2);\
return_value = function_call;\
- _unlockshm_mutex(&mapped_for_db_lock);\
+ _unlockshm_mutex(mapped_for_db_lock);\
} while(0)
#else /* __FEATURE_USE_SHARED_MUTEX_FOR_PROTECTED_FUNC_CALL__ */
@@ -377,6 +401,7 @@ FINISH_OFF :
INTERNAL_FUNC int emstorage_shm_file_init(const char *shm_file_name)
{
EM_DEBUG_FUNC_BEGIN("shm_file_name [%p]", shm_file_name);
+ char errno_buf[ERRNO_BUF_SIZE] = {0};
if(!shm_file_name) {
EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
@@ -384,9 +409,8 @@ INTERNAL_FUNC int emstorage_shm_file_init(const char *shm_file_name)
}
int fd = shm_open (shm_file_name, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP); /* note: permission is not working */
-
if (fd < 0) {
- EM_DEBUG_EXCEPTION("shm_open errno [%d]", errno);
+ EM_DEBUG_EXCEPTION("shm_open errno [%d] [%s]", errno, EM_STRERROR(errno_buf));
return EMAIL_ERROR_SYSTEM_FAILURE;
}
@@ -411,15 +435,13 @@ INTERNAL_FUNC int emstorage_shm_file_init(const char *shm_file_name)
pthread_mutexattr_setpshared(&mattr, PTHREAD_PROCESS_SHARED);
pthread_mutexattr_setrobust(&mattr, PTHREAD_MUTEX_ROBUST_NP);
pthread_mutex_init(&(m->mutex), &mattr);
-
pthread_mutexattr_destroy(&mattr);
- pthread_mutex_destroy(&(m->mutex));
+ pthread_mutex_destroy(&(m->mutex));
munmap(m, sizeof(mmapped_t));
EM_SAFE_CLOSE (fd);
EM_DEBUG_FUNC_END();
-
return EMAIL_ERROR_NONE;
}
@@ -451,15 +473,21 @@ int _initialize_shm_mutex(const char *shm_file_name, int *param_shm_fd, mmapped_
if (!(*param_mapped)) {
EM_DEBUG_LOG("** mapping begin **");
-
if (!(*param_shm_fd)) { /* open shm_file_name at first. Otherwise, the num of files in /proc/pid/fd will be increasing */
- *param_shm_fd = shm_open(shm_file_name, O_RDWR, 0);
+ *param_shm_fd = shm_open(shm_file_name, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
if ((*param_shm_fd) == -1) {
EM_DEBUG_EXCEPTION("FAIL: shm_open(): %s", EM_STRERROR(errno_buf));
return EMAIL_ERROR_SYSTEM_FAILURE;
}
}
+ fchmod((*param_shm_fd), 0666);
+ EM_DEBUG_LOG("** Create SHM FILE **");
+ if (ftruncate((*param_shm_fd), sizeof(mmapped_t)) != 0) {
+ EM_DEBUG_EXCEPTION("ftruncate errno [%d]", errno);
+ return EMAIL_ERROR_SYSTEM_FAILURE;
+ }
+
mmapped_t *tmp = (mmapped_t *)mmap(NULL, sizeof(mmapped_t), PROT_READ|PROT_WRITE, MAP_SHARED, (*param_shm_fd), 0);
if (tmp == MAP_FAILED) {
EM_DEBUG_EXCEPTION("mmap failed: %s", EM_STRERROR(errno_buf));
@@ -482,7 +510,7 @@ int _initialize_shm_mutex(const char *shm_file_name, int *param_shm_fd, mmapped_
return EMAIL_ERROR_NONE;
}
-int _timedlock_shm_mutex(mmapped_t **param_mapped, int sec)
+int _timedlock_shm_mutex(mmapped_t *param_mapped, int sec)
{
EM_DEBUG_FUNC_BEGIN("param_mapped [%p], sec [%d]", param_mapped, sec);
@@ -496,10 +524,10 @@ int _timedlock_shm_mutex(mmapped_t **param_mapped, int sec)
abs_time.tv_sec += sec;
char errno_buf[ERRNO_BUF_SIZE] = {0};
- int err = pthread_mutex_timedlock(&((*param_mapped)->mutex), &abs_time);
+ int err = pthread_mutex_timedlock(&(param_mapped->mutex), &abs_time);
if (err == EOWNERDEAD) {
- err = pthread_mutex_consistent(&((*param_mapped)->mutex));
+ err = pthread_mutex_consistent(&(param_mapped->mutex));
EM_DEBUG_EXCEPTION("Previous owner is dead with lock. Fix mutex : %s", EM_STRERROR(errno_buf));
}
else if (err != 0) {
@@ -511,10 +539,10 @@ int _timedlock_shm_mutex(mmapped_t **param_mapped, int sec)
return EMAIL_ERROR_NONE;
}
-void _unlockshm_mutex(mmapped_t **param_mapped)
+void _unlockshm_mutex(mmapped_t *param_mapped)
{
EM_DEBUG_FUNC_BEGIN();
- pthread_mutex_unlock(&((*param_mapped)->mutex));
+ pthread_mutex_unlock(&(param_mapped->mutex));
EM_DEBUG_FUNC_END();
}
/* ------------------------------------------------------------------------------ */
@@ -522,7 +550,7 @@ void _unlockshm_mutex(mmapped_t **param_mapped)
static int _open_counter = 0;
-static int _get_password_file_name(int account_id, char *recv_password_file_name, char *send_password_file_name);
+static int _get_password_file_name(char *multi_user_name, int account_id, char *recv_password_file_name, char *send_password_file_name);
static int _read_password_from_secure_storage(char *file_name, char **password);
#ifdef __FEATURE_SUPPORT_PRIVATE_CERTIFICATE__
@@ -734,6 +762,7 @@ enum
DEFAULT_CHARSET_IDX_IN_MAIL_TBL,
EAS_DATA_LENGTH_IDX_IN_MAIL_TBL,
EAS_DATA_IDX_IN_MAIL_TBL,
+ USER_NAME_IDX_IN_MAIL_TBL,
FIELD_COUNT_OF_MAIL_TBL, /* End of mail_tbl */
};
@@ -785,6 +814,7 @@ enum
MAIL_ID_IDX_MAIL_AUTO_DOWNLOAD_ACTIVITY_TBL,
SERVER_MAIL_ID_IDX_MAIL_AUTO_DOWNLOAD_ACTIVITY_TBL,
MAILBOX_ID_IDX_MAIL_AUTO_DOWNLOAD_ACTIVITY_TBL,
+ MULTI_USER_NAME_IDX_MAIL_AUTO_DOWNLOAD_ACTIVITY_TBL,
};
#endif
@@ -972,6 +1002,7 @@ static char *g_test_query[] = {
" activity_type, "
" mailbox_id, "
" mailbox_name "
+ " multi_user_name "
" FROM mail_partial_body_activity_tbl ",
#endif
@@ -1043,6 +1074,7 @@ static char *g_test_query[] = {
" mail_id, "
" server_mail_id, "
" mailbox_id, "
+ " multi_user_name, "
" FROM mail_auto_download_activity_tbl ",
#endif
NULL,
@@ -1545,7 +1577,7 @@ INTERNAL_FUNC int emstorage_close(int *err_code)
int ret = false;
int error = EMAIL_ERROR_NONE;
- emstorage_db_close(&error);
+ if (!emstorage_db_close(NULL, &error))
if (--_open_counter == 0)
_emstorage_close_once();
@@ -1559,53 +1591,118 @@ INTERNAL_FUNC int emstorage_close(int *err_code)
return ret;
}
-static void *_emstorage_open_once(int *err_code)
+static void *_emstorage_open_once(char *multi_user_name, int *err_code)
{
EM_DEBUG_FUNC_BEGIN();
int error = EMAIL_ERROR_NONE;
- mkdir(USERDATA_PATH, DIRECTORY_PERMISSION);
- mkdir(DATA_PATH, DIRECTORY_PERMISSION);
- mkdir(EMAILPATH, DIRECTORY_PERMISSION);
- mkdir(MAILHOME, DIRECTORY_PERMISSION);
- mkdir(MAILTEMP, DIRECTORY_PERMISSION);
+ if (EM_SAFE_STRLEN(multi_user_name) > 0) {
+ char buf[MAX_PATH] = {0};
+ char *prefix_path = NULL;
- _delete_temp_file(MAILTEMP);
+ error = emcore_get_container_path(multi_user_name, &prefix_path);
+ if (error != EMAIL_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("emcore_get_container_path failed : [%d]", error);
+ goto FINISH_OFF;
+ }
+
+ memset(buf, 0x00, sizeof(buf));
+ SNPRINTF(buf, sizeof(buf), "%s%s", prefix_path, USERDATA_PATH);
+ mkdir(buf, DIRECTORY_PERMISSION);
+
+ memset(buf, 0x00, sizeof(buf));
+ SNPRINTF(buf, sizeof(buf), "%s%s", prefix_path, EMAILPATH);
+ mkdir(buf, DIRECTORY_PERMISSION);
+
+ memset(buf, 0x00, sizeof(buf));
+ SNPRINTF(buf, sizeof(buf), "%s%s", prefix_path, MAILHOME);
+ mkdir(buf, DIRECTORY_PERMISSION);
+
+ memset(buf, 0x00, sizeof(buf));
+ SNPRINTF(buf, sizeof(buf), "%s%s", prefix_path, MAILTEMP);
+ mkdir(buf, DIRECTORY_PERMISSION);
+ chmod(buf, 0777);
+
+ _delete_temp_file(buf);
+ EM_SAFE_FREE(prefix_path);
+ } else {
+ mkdir(USERDATA_PATH, DIRECTORY_PERMISSION);
+ mkdir(DATA_PATH, DIRECTORY_PERMISSION);
+ mkdir(EMAILPATH, DIRECTORY_PERMISSION);
+ mkdir(MAILHOME, DIRECTORY_PERMISSION);
+ mkdir(MAILTEMP, DIRECTORY_PERMISSION);
+ chmod(MAILTEMP, 0777);
+
+ _delete_temp_file(MAILTEMP);
+ }
- if (!emstorage_create_table(EMAIL_CREATE_DB_NORMAL, &error)) {
+ if (!emstorage_create_table(multi_user_name, EMAIL_CREATE_DB_NORMAL, &error)) {
EM_DEBUG_EXCEPTION(" emstorage_create_table failed - %d", error);
goto FINISH_OFF;
}
FINISH_OFF:
+
+
if (err_code != NULL)
*err_code = error;
-
return NULL;
}
/* pData : a parameter which is registered when busy handler is registerd */
/* count : retry count */
-#define EMAIL_STORAGE_MAX_RETRY_COUNT 20
static int _callback_sqlite_busy_handler(void *pData, int count)
{
- EM_DEBUG_LOG("Busy Handler Called!!: [%d]", count);
- usleep(200000); /* sleep time when SQLITE_LOCK */
+ if (10 - count > 0) {
+ struct timespec time = {
+ .tv_sec = 0,
+ .tv_nsec = (count + 1) * 100 * 1000 * 1000
+ };
+ EM_DEBUG_LOG("Busy handler called!!: PID[%d] / CNT [%d]", getpid(), count);
+ nanosleep(&time, NULL);
+ return 1;
+ } else {
+ EM_DEBUG_EXCEPTION("Busy handler will be returned SQLITE_BUSY error PID[%d] / CNT[%d]", getpid(), count);
+ return 0;
+ }
+}
- /* retry will be stopped if busy handler return 0 */
- return EMAIL_STORAGE_MAX_RETRY_COUNT - count;
+static int _callback_collation_utf7_sort(void *data, int length_text_a, const void *text_a,
+ int length_text_b, const void *text_b)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int result = 0;
+ char *converted_string_a = NULL;
+ char *converted_string_b = NULL;
+
+ EM_DEBUG_LOG_DEV("text_a : [%s]", text_a);
+ converted_string_a = emcore_convert_mutf7_to_utf8((char *)text_a);
+ EM_DEBUG_LOG_DEV("Converted text_a : [%s]", converted_string_a);
+
+ EM_DEBUG_LOG_DEV("text_b : [%s]", text_b);
+ converted_string_b = emcore_convert_mutf7_to_utf8((char *)text_b);
+ EM_DEBUG_LOG_DEV("Converted text_b : [%s]", converted_string_b);
+
+ if (converted_string_a && converted_string_b)
+ result = strcmp(converted_string_a, converted_string_b);
+
+ EM_SAFE_FREE(converted_string_a);
+ EM_SAFE_FREE(converted_string_b);
+
+ EM_DEBUG_FUNC_END();
+ return result;
}
-static int _delete_all_files_and_directories(int *err_code)
+static int _delete_all_files_and_directories(char *db_file_path, int *err_code)
{
EM_DEBUG_FUNC_BEGIN();
int error = EMAIL_ERROR_NONE;
int ret = false;
- if (!emstorage_delete_file(EMAIL_SERVICE_DB_FILE_PATH, &error)) {
+ if (!emstorage_delete_file(db_file_path, &error)) {
if (error != EMAIL_ERROR_FILE_NOT_FOUND) {
EM_DEBUG_EXCEPTION_SEC("remove failed - %s", EMAIL_SERVICE_DB_FILE_PATH);
goto FINISH_OFF;
@@ -1626,7 +1723,7 @@ FINISH_OFF:
return ret;
}
-static int _recovery_from_malformed_db_file(int *err_code)
+static int _recovery_from_malformed_db_file(char *db_file_path, int *err_code)
{
EM_DEBUG_FUNC_BEGIN();
@@ -1634,7 +1731,7 @@ static int _recovery_from_malformed_db_file(int *err_code)
int ret = false;
/* Delete all files and directories */
- if (!_delete_all_files_and_directories(&error)) {
+ if (!_delete_all_files_and_directories(db_file_path, &error)) {
EM_DEBUG_EXCEPTION("_delete_all_files_and_directories failed [%d]", error);
goto FINISH_OFF;
}
@@ -1653,8 +1750,7 @@ FINISH_OFF:
return ret;
}
-
-INTERNAL_FUNC int em_db_open(sqlite3 **sqlite_handle, int *err_code)
+INTERNAL_FUNC int em_db_open(char *db_file_path, sqlite3 **sqlite_handle, int *err_code)
{
EM_DEBUG_FUNC_BEGIN();
int rc = 0;
@@ -1670,8 +1766,10 @@ INTERNAL_FUNC int em_db_open(sqlite3 **sqlite_handle, int *err_code)
return true;
}
+ EM_DEBUG_LOG("DB file path : [%s]", db_file_path);
+
/* db open */
- EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_open(EMAIL_SERVICE_DB_FILE_PATH, sqlite_handle), rc);
+ EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_open(db_file_path, sqlite_handle), rc);
if (SQLITE_OK != rc) {
EM_DEBUG_EXCEPTION("sqlite3_open fail:%d -%s", rc, sqlite3_errmsg(*sqlite_handle));
if (SQLITE_PERM == rc || SQLITE_CANTOPEN == rc) {
@@ -1684,13 +1782,13 @@ INTERNAL_FUNC int em_db_open(sqlite3 **sqlite_handle, int *err_code)
if (SQLITE_CORRUPT == rc) /* SQLITE_CORRUPT : The database disk image is malformed */ {/* Recovery DB file */
EM_DEBUG_LOG("The database disk image is malformed. Trying to remove and create database disk image and directories");
- if (!_recovery_from_malformed_db_file(&error)) {
+ if (!_recovery_from_malformed_db_file(db_file_path, &error)) {
EM_DEBUG_EXCEPTION("_recovery_from_malformed_db_file failed [%d]", error);
goto FINISH_OFF;
}
EM_DEBUG_LOG("Open DB again");
- EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_open(EMAIL_SERVICE_DB_FILE_PATH, sqlite_handle), rc);
+ EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_open(db_file_path, sqlite_handle), rc);
if (SQLITE_OK != rc) {
EM_DEBUG_EXCEPTION("sqlite3_open fail:%d -%s", rc, sqlite3_errmsg(*sqlite_handle));
if (SQLITE_PERM == rc) {
@@ -1707,8 +1805,8 @@ INTERNAL_FUNC int em_db_open(sqlite3 **sqlite_handle, int *err_code)
goto FINISH_OFF;
}
- EM_DEBUG_LOG_DEV(">>>>> Register DB Handle to busy handler: *sqlite_handle[%p]", *sqlite_handle);
/* register busy handler */
+ EM_DEBUG_LOG_DEV(">>>>> Register DB Handle to busy handler: *sqlite_handle[%p]", *sqlite_handle);
rc = sqlite3_busy_handler(*sqlite_handle, _callback_sqlite_busy_handler, NULL); /* Busy Handler registration, NULL is a parameter which will be passed to handler */
if (SQLITE_OK != rc) {
EM_DEBUG_EXCEPTION("sqlite3_busy_handler fail:%d -%s", rc, sqlite3_errmsg(*sqlite_handle));
@@ -1718,6 +1816,16 @@ INTERNAL_FUNC int em_db_open(sqlite3 **sqlite_handle, int *err_code)
goto FINISH_OFF;
}
+ /* Register collation callback function */
+ rc = sqlite3_create_collation(*sqlite_handle, "CONVERTUTF8", SQLITE_UTF8, NULL, _callback_collation_utf7_sort);
+ if (SQLITE_OK != rc) {
+ EM_DEBUG_EXCEPTION("sqlite3_create_collation failed : [%d][%s]", rc, sqlite3_errmsg(*sqlite_handle));
+ error = EMAIL_ERROR_DB_FAILURE;
+ sqlite3_close(*sqlite_handle);
+ *sqlite_handle = NULL;
+ goto FINISH_OFF;
+ }
+
ret = true;
FINISH_OFF:
@@ -1728,33 +1836,63 @@ FINISH_OFF:
return ret;
}
-INTERNAL_FUNC sqlite3* emstorage_db_open(int *err_code)
+INTERNAL_FUNC sqlite3* emstorage_db_open(char *multi_user_name, int *err_code)
{
EM_DEBUG_FUNC_BEGIN();
sqlite3 *_db_handle = NULL;
int error = EMAIL_ERROR_NONE;
+ char *prefix_path = NULL;
- _db_handle = emstorage_get_db_handle();
+ _db_handle = emstorage_get_db_handle(multi_user_name);
if( _db_handle == NULL) {
- if (!em_db_open(&_db_handle, &error)) {
+ char *output_file_path = NULL;
+ char temp_file_path[MAX_PATH] = {0};
+
+ if (EM_SAFE_STRLEN(multi_user_name) > 0) {
+ error = emcore_get_container_path(multi_user_name, &prefix_path);
+ if (error != EMAIL_ERROR_CONTAINER_NOT_INITIALIZATION && error != EMAIL_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("emcore_get_container_path failed :[%d]", error);
+ goto FINISH_OFF;
+ }
+ } else {
+ prefix_path = strdup("");
+ }
+
+ if (error == EMAIL_ERROR_CONTAINER_NOT_INITIALIZATION) {
+ if ((error = emcore_get_canonicalize_path(EMAIL_SERVICE_DB_FILE_PATH, &output_file_path)) != EMAIL_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("emcore_get_canonicalize_path failed : [%d]", error);
+ goto FINISH_OFF;
+ }
+
+ SNPRINTF(temp_file_path, sizeof(temp_file_path), "%s", output_file_path);
+ EM_SAFE_FREE(output_file_path);
+ } else {
+ SNPRINTF(temp_file_path, sizeof(temp_file_path), "%s%s", prefix_path, EMAIL_SERVICE_DB_FILE_PATH);
+ }
+
+ if (!em_db_open(temp_file_path, &_db_handle, &error)) {
EM_DEBUG_EXCEPTION("em_db_open failed[%d]", error);
goto FINISH_OFF;
}
+
_initialize_shm_mutex(SHM_FILE_FOR_DB_LOCK, &shm_fd_for_db_lock, &mapped_for_db_lock);
#ifdef __FEATURE_USE_SHARED_MUTEX_FOR_GENERATING_MAIL_ID__
_initialize_shm_mutex(SHM_FILE_FOR_MAIL_ID_LOCK, &shm_fd_for_generating_mail_id, &mapped_for_generating_mail_id);
#endif /*__FEATURE_USE_SHARED_MUTEX_FOR_GENERATING_MAIL_ID__ */
- emstorage_set_db_handle(_db_handle);
+ emstorage_set_db_handle(multi_user_name, _db_handle);
+
emstorage_initialize_field_count();
}
-
FINISH_OFF:
+
+ EM_SAFE_FREE(prefix_path);
+
if (err_code != NULL)
*err_code = error;
@@ -1762,11 +1900,11 @@ FINISH_OFF:
return _db_handle;
}
-INTERNAL_FUNC int emstorage_db_close(int *err_code)
+INTERNAL_FUNC int emstorage_db_close(char *multi_user_name, int *err_code)
{
EM_DEBUG_FUNC_BEGIN();
#ifdef _MULTIPLE_DB_HANDLE
- sqlite3 *_db_handle = emstorage_get_db_handle();
+ sqlite3 *_db_handle = emstorage_get_db_handle(multi_user_name);
#endif
int error = EMAIL_ERROR_NONE;
@@ -1796,38 +1934,52 @@ FINISH_OFF:
return ret;
}
-
-INTERNAL_FUNC int emstorage_open(int *err_code)
+INTERNAL_FUNC int emstorage_open(char *multi_user_name, int *err_code)
{
EM_DEBUG_FUNC_BEGIN();
- int ret = false;
- int error = EMAIL_ERROR_NONE;
+ int ret = false;
+ int error = EMAIL_ERROR_NONE;
+ int retValue;
+ char *prefix_path = NULL;
+ char buf[MAX_PATH] = {0};
- int retValue;
+ if (EM_SAFE_STRLEN(multi_user_name) <= 0) {
+ SNPRINTF(buf, sizeof(buf), "%s", DB_PATH);
+ } else {
+ error = emcore_get_container_path(multi_user_name, &prefix_path);
+ if (error != EMAIL_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("emcore_get_container_path failed : [%d]", error);
+ goto FINISH_OFF;
+ }
+ SNPRINTF(buf, sizeof(buf), "%s/%s", prefix_path, DB_PATH);
+ }
- retValue = mkdir(DB_PATH, DIRECTORY_PERMISSION);
+ retValue = mkdir(buf, DIRECTORY_PERMISSION);
- EM_DEBUG_LOG("mkdir return- %d", retValue);
- EM_DEBUG_LOG("emstorage_open - before sqlite3_open - pid = %d", getpid());
+ EM_DEBUG_LOG("mkdir return- %d", retValue);
+ EM_DEBUG_LOG("emstorage_open - before sqlite3_open - pid = %d", getpid());
- if (emstorage_db_open(&error) == NULL) {
- EM_DEBUG_EXCEPTION("emstorage_db_open failed[%d]", error);
- goto FINISH_OFF;
- }
+ if (emstorage_db_open(multi_user_name, &error) == NULL) {
+ EM_DEBUG_EXCEPTION("emstorage_db_open failed[%d]", error);
+ goto FINISH_OFF;
+ }
- if (_open_counter++ == 0) {
- _emstorage_open_once(&error);
- }
+ if (_open_counter++ == 0) {
+ _emstorage_open_once(multi_user_name, &error);
+ }
- ret = true;
+ ret = true;
FINISH_OFF:
- if (err_code != NULL)
- *err_code = error;
- EM_DEBUG_FUNC_END("ret [%d]", ret);
- return ret;
+ EM_SAFE_FREE(prefix_path);
+
+ if (err_code != NULL)
+ *err_code = error;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
}
static int emstorage_get_field_count_from_create_table_query(char *input_create_table_query, int *output_field_count)
@@ -1910,7 +2062,7 @@ FINISH_OFF:
return err;
}
-INTERNAL_FUNC int emstorage_create_table(emstorage_create_db_type_t type, int *err_code)
+INTERNAL_FUNC int emstorage_create_table(char *multi_user_name, emstorage_create_db_type_t type, int *err_code)
{
EM_DEBUG_FUNC_BEGIN();
@@ -1919,7 +2071,8 @@ INTERNAL_FUNC int emstorage_create_table(emstorage_create_db_type_t type, int *e
int query_len = 0;
char sql_query_string[QUERY_SIZE] = {0, };
char **create_table_query = NULL;
- sqlite3 *local_db_handle = emstorage_get_db_connection();
+
+ sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name);
error = emcore_load_query_from_file(EMAIL_SERVICE_CREATE_TABLE_QUERY_FILE_PATH, &create_table_query, &query_len);
if (error != EMAIL_ERROR_NONE) {
@@ -2360,11 +2513,11 @@ INTERNAL_FUNC int emstorage_create_table(emstorage_create_db_type_t type, int *e
EM_DEBUG_LOG("CREATE TABLE mail_text_tbl");
EM_SAFE_STRNCPY(sql_query_string, create_table_query[CREATE_TABLE_MAIL_TEXT_TBL], sizeof(sql_query_string)-1); /*prevent 21984 */
- error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string);
- if (error != EMAIL_ERROR_NONE) {
- EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error);
- goto FINISH_OFF;
- }
+ error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string);
+ if (error != EMAIL_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error);
+ goto FINISH_OFF;
+ }
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, "END;", NULL, NULL, NULL), rc);
} /* mail_text_tbl */
@@ -2391,11 +2544,11 @@ INTERNAL_FUNC int emstorage_create_table(emstorage_create_db_type_t type, int *e
EM_DEBUG_LOG("CREATE TABLE mail_auto_download_activity_tbl");
EM_SAFE_STRNCPY(sql_query_string, create_table_query[CREATE_TABLE_MAIL_AUTO_DOWNLOAD_ACTIVITY_TBL], sizeof(sql_query_string)-1);
- error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string);
- if (error != EMAIL_ERROR_NONE) {
- EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error);
- goto FINISH_OFF;
- }
+ error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string);
+ if (error != EMAIL_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error);
+ goto FINISH_OFF;
+ }
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, "END;", NULL, NULL, NULL), rc);
} /* mail_auto_download_activity_tbl */
@@ -2441,8 +2594,7 @@ FINISH_OFF2:
}
/* Query series --------------------------------------------------------------*/
-
-INTERNAL_FUNC int emstorage_query_mail_count(const char *input_conditional_clause, int input_transaction, int *output_total_mail_count, int *output_unseen_mail_count)
+INTERNAL_FUNC int emstorage_query_mail_count(char *multi_user_name, const char *input_conditional_clause, int input_transaction, int *output_total_mail_count, int *output_unseen_mail_count)
{
EM_DEBUG_FUNC_BEGIN("input_conditional_clause[%p], input_transaction[%d], output_total_mail_count[%p], output_unseen_mail_count[%p]", input_conditional_clause, input_transaction, output_total_mail_count, output_unseen_mail_count);
int rc = -1;
@@ -2466,7 +2618,7 @@ INTERNAL_FUNC int emstorage_query_mail_count(const char *input_conditional_claus
goto FINISH_OFF;
}
- local_db_handle = emstorage_get_db_connection();
+ local_db_handle = emstorage_get_db_connection(multi_user_name);
EMSTORAGE_START_READ_TRANSACTION(input_transaction);
@@ -2513,7 +2665,7 @@ FINISH_OFF:
return error;
}
-INTERNAL_FUNC int emstorage_query_mail_id_list(const char *input_conditional_clause, int input_transaction, int **output_mail_id_list, int *output_mail_id_count)
+INTERNAL_FUNC int emstorage_query_mail_id_list(char *multi_user_name, const char *input_conditional_clause, int input_transaction, int **output_mail_id_list, int *output_mail_id_count)
{
EM_DEBUG_FUNC_BEGIN("input_conditional_clause [%p], input_transaction [%d], output_mail_id_list [%p], output_mail_id_count [%p]", input_conditional_clause, input_transaction, output_mail_id_list, output_mail_id_count);
@@ -2527,7 +2679,7 @@ INTERNAL_FUNC int emstorage_query_mail_id_list(const char *input_conditional_cla
int *result_mail_id_list = NULL;
char **result = NULL;
char *sql_query_string = NULL;
- sqlite3 *local_db_handle = emstorage_get_db_connection();
+ sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name);
EM_IF_NULL_RETURN_VALUE(input_conditional_clause, EMAIL_ERROR_INVALID_PARAM);
EM_IF_NULL_RETURN_VALUE(output_mail_id_list, EMAIL_ERROR_INVALID_PARAM);
@@ -2597,7 +2749,7 @@ FINISH_OFF:
return error;
}
-INTERNAL_FUNC int emstorage_query_mail_list(const char *conditional_clause, int transaction, email_mail_list_item_t** result_mail_list, int *result_count, int *err_code)
+INTERNAL_FUNC int emstorage_query_mail_list(char *multi_user_name, const char *conditional_clause, int transaction, email_mail_list_item_t** result_mail_list, int *result_count, int *err_code)
{
EM_DEBUG_FUNC_BEGIN();
EM_PROFILE_BEGIN(emstorage_query_mail_list_func);
@@ -2615,7 +2767,7 @@ INTERNAL_FUNC int emstorage_query_mail_list(const char *conditional_clause, int
char *target_field = NULL;
char *sql_query_string = NULL;
email_mail_list_item_t *mail_list_item_from_tbl = NULL;
- sqlite3 *local_db_handle = emstorage_get_db_connection();
+ sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name);
EM_IF_NULL_RETURN_VALUE(conditional_clause, false);
EM_IF_NULL_RETURN_VALUE(result_count, false);
@@ -2757,7 +2909,7 @@ FINISH_OFF:
EMSTORAGE_FINISH_READ_TRANSACTION(transaction);
- sqlite3_db_release_memory(local_db_handle);
+// sqlite3_db_release_memory(local_db_handle);
EM_SAFE_FREE(sql_query_string);
EM_SAFE_FREE(date_time_string);
@@ -2771,7 +2923,7 @@ FINISH_OFF:
}
-INTERNAL_FUNC int emstorage_query_mail_tbl(const char *conditional_clause, int transaction, emstorage_mail_tbl_t** result_mail_tbl, int *result_count, int *err_code)
+INTERNAL_FUNC int emstorage_query_mail_tbl(char *multi_user_name, const char *conditional_clause, int transaction, emstorage_mail_tbl_t** result_mail_tbl, int *result_count, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("conditional_clause[%s], result_mail_tbl[%p], result_count [%p], transaction[%d], err_code[%p]", conditional_clause, result_mail_tbl, result_count, transaction, err_code);
@@ -2786,7 +2938,7 @@ INTERNAL_FUNC int emstorage_query_mail_tbl(const char *conditional_clause, int t
int error = EMAIL_ERROR_NONE;
char **result = NULL, sql_query_string[QUERY_SIZE] = {0, };
emstorage_mail_tbl_t* p_data_tbl = NULL;
- sqlite3 *local_db_handle = emstorage_get_db_connection();
+ sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name);
EMSTORAGE_START_READ_TRANSACTION(transaction);
@@ -2869,6 +3021,7 @@ INTERNAL_FUNC int emstorage_query_mail_tbl(const char *conditional_clause, int t
_get_table_field_data_string(result, &(p_data_tbl[i].default_charset), 0, col_index++);
_get_table_field_data_int (result, (int*)&(p_data_tbl[i].eas_data_length), col_index++);
_get_table_field_data_blob (result, (void**)&(p_data_tbl[i].eas_data), p_data_tbl[i].eas_data_length, col_index++);
+ _get_table_field_data_string(result, &(p_data_tbl[i].user_name), 0, col_index++);
}
ret = true;
@@ -2888,7 +3041,7 @@ FINISH_OFF:
EMSTORAGE_FINISH_READ_TRANSACTION(transaction);
- sqlite3_db_release_memory(local_db_handle);
+// sqlite3_db_release_memory(local_db_handle);
if (err_code != NULL)
*err_code = error;
@@ -2898,7 +3051,7 @@ FINISH_OFF:
}
#ifdef __FEATURE_BODY_SEARCH__
-INTERNAL_FUNC int emstorage_query_mail_text_tbl(const char *conditional_clause, int transaction, emstorage_mail_text_tbl_t** result_mail_text_tbl, int *result_count, int *err_code)
+INTERNAL_FUNC int emstorage_query_mail_text_tbl(char *multi_user_name, const char *conditional_clause, int transaction, emstorage_mail_text_tbl_t** result_mail_text_tbl, int *result_count, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("conditional_clause[%s], result_mail_text_tbl[%p], result_count [%p], transaction[%d], err_code[%p]", conditional_clause, result_mail_text_tbl, result_count, transaction, err_code);
@@ -2918,7 +3071,7 @@ INTERNAL_FUNC int emstorage_query_mail_text_tbl(const char *conditional_clause,
char **result = NULL;
char sql_query_string[QUERY_SIZE] = {0, };
emstorage_mail_text_tbl_t* p_data_tbl = NULL;
- sqlite3 *local_db_handle = emstorage_get_db_connection();
+ sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name);
EMSTORAGE_START_READ_TRANSACTION(transaction);
@@ -2967,7 +3120,7 @@ FINISH_OFF:
EMSTORAGE_FINISH_READ_TRANSACTION(transaction);
- sqlite3_db_release_memory(local_db_handle);
+// sqlite3_db_release_memory(local_db_handle);
if (err_code != NULL)
*err_code = error;
@@ -2977,7 +3130,7 @@ FINISH_OFF:
}
#endif
-INTERNAL_FUNC int emstorage_query_mailbox_tbl(const char *input_conditional_clause, const char *input_ordering_clause, int input_get_mail_count, int input_transaction, emstorage_mailbox_tbl_t **output_mailbox_list, int *output_mailbox_count)
+INTERNAL_FUNC int emstorage_query_mailbox_tbl(char *multi_user_name, const char *input_conditional_clause, const char *input_ordering_clause, int input_get_mail_count, int input_transaction, emstorage_mailbox_tbl_t **output_mailbox_list, int *output_mailbox_count)
{
EM_DEBUG_FUNC_BEGIN("input_conditional_clause[%p], input_ordering_clause [%p], input_get_mail_count[%d], input_transaction[%d], output_mailbox_list[%p], output_mailbox_count[%d]", input_conditional_clause, input_ordering_clause, input_get_mail_count, input_transaction, output_mailbox_list, output_mailbox_count);
@@ -2992,7 +3145,7 @@ INTERNAL_FUNC int emstorage_query_mailbox_tbl(const char *input_conditional_clau
char sql_query_string[QUERY_SIZE] = {0, };
char *fields = "MBT.mailbox_id, MBT.account_id, local_yn, MBT.mailbox_name, MBT.mailbox_type, alias, deleted_flag, modifiable_yn, total_mail_count_on_server, has_archived_mails, mail_slot_size, no_select, last_sync_time, MBT.eas_data_length, MBT.eas_data ";
emstorage_mailbox_tbl_t* p_data_tbl = NULL;
- sqlite3 *local_db_handle = emstorage_get_db_connection();
+ sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name);
EMSTORAGE_START_READ_TRANSACTION(input_transaction);
@@ -3005,13 +3158,13 @@ INTERNAL_FUNC int emstorage_query_mailbox_tbl(const char *input_conditional_clau
SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT %s, total, read FROM mail_box_tbl AS MBT LEFT OUTER JOIN (SELECT mailbox_id, count(mail_id) AS total, SUM(flags_seen_field) AS read FROM mail_tbl WHERE flags_deleted_field = 0 GROUP BY mailbox_id) AS MT ON MBT.mailbox_id = MT.mailbox_id %s %s", fields, input_conditional_clause, input_ordering_clause);
}
- EM_DEBUG_LOG_DEV ("query[%s]", sql_query_string);
+ EM_DEBUG_LOG_DEV("query[%s]", sql_query_string);
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, &count, NULL, NULL), rc);
EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
("sqlite3_get_table failed [%d] [%s]", rc, sql_query_string))
- EM_DEBUG_LOG_DEV ("result count [%d]", count);
+ EM_DEBUG_LOG_DEV("result count [%d]", count);
if(count == 0) {
EM_DEBUG_LOG_SEC ("Can't find mailbox query[%s]", sql_query_string);
@@ -3063,15 +3216,14 @@ FINISH_OFF:
EMSTORAGE_FINISH_READ_TRANSACTION(input_transaction);
- sqlite3_db_release_memory(local_db_handle);
+// sqlite3_db_release_memory(local_db_handle);
EM_DEBUG_FUNC_END("error [%d]", error);
return error;
}
/* Query series --------------------------------------------------------------*/
-
-INTERNAL_FUNC int emstorage_check_duplicated_account(email_account_t* account, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_check_duplicated_account(char *multi_user_name, email_account_t* account, int transaction, int *err_code)
{
EM_DEBUG_FUNC_BEGIN();
int rc = -1, ret = false;
@@ -3088,7 +3240,7 @@ INTERNAL_FUNC int emstorage_check_duplicated_account(email_account_t* account, i
return false;
}
- local_db_handle = emstorage_get_db_connection();
+ local_db_handle = emstorage_get_db_connection(multi_user_name);
EMSTORAGE_START_READ_TRANSACTION(transaction);
@@ -3138,7 +3290,7 @@ FINISH_OFF:
}
-INTERNAL_FUNC int emstorage_get_account_count(int *count, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_get_account_count(char *multi_user_name, int *count, int transaction, int *err_code)
{
EM_DEBUG_FUNC_BEGIN();
@@ -3155,7 +3307,7 @@ INTERNAL_FUNC int emstorage_get_account_count(int *count, int transaction, int *
char sql_query_string[QUERY_SIZE] = {0, };
- sqlite3 *local_db_handle = emstorage_get_db_connection();
+ sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name);
EMSTORAGE_START_READ_TRANSACTION(transaction);
SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT COUNT(*) FROM mail_account_tbl");
EM_DEBUG_LOG_SEC("SQL STMT [%s]", sql_query_string);
@@ -3193,8 +3345,7 @@ FINISH_OFF:
return ret;
}
-
-INTERNAL_FUNC int emstorage_get_account_list(int *select_num, emstorage_account_tbl_t** account_list, int transaction, int with_password, int *err_code)
+INTERNAL_FUNC int emstorage_get_account_list(char *multi_user_name, int *select_num, emstorage_account_tbl_t **account_list, int transaction, int with_password, int *err_code)
{
EM_DEBUG_FUNC_BEGIN();
@@ -3216,7 +3367,8 @@ INTERNAL_FUNC int emstorage_get_account_list(int *select_num, emstorage_account_
return false;
}
- local_db_handle = emstorage_get_db_connection();
+ local_db_handle = emstorage_get_db_connection(multi_user_name);
+
EMSTORAGE_START_READ_TRANSACTION(transaction);
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql, &result, NULL, NULL, NULL), rc);
@@ -3414,8 +3566,8 @@ INTERNAL_FUNC int emstorage_get_account_list(int *select_num, emstorage_account_
EM_SAFE_FREE(p_data_tbl[i].outgoing_server_password);
/* get password file name */
- error = _get_password_file_name (p_data_tbl[i].account_id,
- recv_password_file_name,
+ error = _get_password_file_name (multi_user_name, p_data_tbl[i].account_id,
+ recv_password_file_name,
send_password_file_name);
if (error != EMAIL_ERROR_NONE){
EM_DEBUG_EXCEPTION("_get_password_file_name error [%d]", error);
@@ -3477,10 +3629,15 @@ FINISH_OFF:
return ret;
}
-
-INTERNAL_FUNC int emstorage_get_maildata_by_servermailid(int mailbox_id, char *server_mail_id, emstorage_mail_tbl_t** mail, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_get_maildata_by_servermailid(char *multi_user_name,
+ char *server_mail_id,
+ int mailbox_id,
+ emstorage_mail_tbl_t **mail,
+ int transaction,
+ int *err_code)
{
- EM_DEBUG_FUNC_BEGIN_SEC("mailbox_id [%d], server_mail_id[%s], mail[%p], transaction[%d], err_code[%p]", mailbox_id, server_mail_id, mail, transaction, err_code);
+ EM_DEBUG_FUNC_BEGIN_SEC("mailbox_id [%d], server_mail_id[%s], mail[%p], transaction[%d], err_code[%p]",
+ mailbox_id, server_mail_id, mail, transaction, err_code);
int ret = false, error = EMAIL_ERROR_NONE, result_count;
char conditional_clause[QUERY_SIZE] = {0, };
@@ -3492,14 +3649,22 @@ INTERNAL_FUNC int emstorage_get_maildata_by_servermailid(int mailbox_id, char *s
goto FINISH_OFF;
}
- if (mailbox_id == 0)
- SNPRINTF(conditional_clause, QUERY_SIZE, "WHERE UPPER(server_mail_id) =UPPER('%s')", server_mail_id);
- else
- SNPRINTF(conditional_clause, QUERY_SIZE, "WHERE UPPER(server_mail_id) =UPPER('%s') AND mailbox_id = %d", server_mail_id, mailbox_id);
+ SNPRINTF(conditional_clause, QUERY_SIZE, "WHERE UPPER(server_mail_id) = UPPER('%s')", server_mail_id);
- EM_DEBUG_LOG("conditional_clause [%s]", conditional_clause);
+ if (mailbox_id > 0) {
+ SNPRINTF(conditional_clause + strlen(conditional_clause),
+ QUERY_SIZE - strlen(conditional_clause),
+ " AND mailbox_id = %d",
+ mailbox_id);
+ }
- if(!emstorage_query_mail_tbl(conditional_clause, transaction, &p_data_tbl, &result_count, &error)) {
+ EM_DEBUG_LOG("conditional_clause [%s]", conditional_clause);
+ if (!emstorage_query_mail_tbl(multi_user_name,
+ conditional_clause,
+ transaction,
+ &p_data_tbl,
+ &result_count,
+ &error)) {
EM_DEBUG_EXCEPTION("emstorage_query_mail_tbl failed [%d]", error);
goto FINISH_OFF;
}
@@ -3507,6 +3672,7 @@ INTERNAL_FUNC int emstorage_get_maildata_by_servermailid(int mailbox_id, char *s
ret = true;
FINISH_OFF:
+
if (ret == true)
*mail = p_data_tbl;
@@ -3664,7 +3830,7 @@ static int _write_conditional_clause_for_getting_mail_list(int account_id, int m
*
*
*/
-INTERNAL_FUNC int emstorage_get_mail_list(int account_id, int mailbox_id, email_email_address_list_t* addr_list, int thread_id, int start_index, int limit_count, int search_type, const char *search_value, email_sort_type_t sorting, int transaction, email_mail_list_item_t** mail_list, int *result_count, int *err_code)
+INTERNAL_FUNC int emstorage_get_mail_list(char *multi_user_name, int account_id, int mailbox_id, email_email_address_list_t* addr_list, int thread_id, int start_index, int limit_count, int search_type, const char *search_value, email_sort_type_t sorting, int transaction, email_mail_list_item_t** mail_list, int *result_count, int *err_code)
{
EM_DEBUG_FUNC_BEGIN();
EM_PROFILE_BEGIN(emstorage_get_mail_list_func);
@@ -3682,7 +3848,7 @@ INTERNAL_FUNC int emstorage_get_mail_list(int account_id, int mailbox_id, email_
EM_DEBUG_LOG("conditional_clause_string[%s].", conditional_clause_string);
- if(!emstorage_query_mail_list(conditional_clause_string, transaction, mail_list, result_count, &error)) {
+ if(!emstorage_query_mail_list(multi_user_name, conditional_clause_string, transaction, mail_list, result_count, &error)) {
EM_DEBUG_EXCEPTION("emstorage_query_mail_list [%d]", error);
goto FINISH_OFF;
}
@@ -3704,7 +3870,7 @@ FINISH_OFF:
*
*
*/
-INTERNAL_FUNC int emstorage_get_mails(int account_id, int mailbox_id, email_email_address_list_t* addr_list, int thread_id, int start_index, int limit_count, email_sort_type_t sorting, int transaction, emstorage_mail_tbl_t** mail_list, int *result_count, int *err_code)
+INTERNAL_FUNC int emstorage_get_mails(char *multi_user_name, int account_id, int mailbox_id, email_email_address_list_t* addr_list, int thread_id, int start_index, int limit_count, email_sort_type_t sorting, int transaction, emstorage_mail_tbl_t** mail_list, int *result_count, int *err_code)
{
EM_DEBUG_FUNC_BEGIN();
EM_PROFILE_BEGIN(emStorageGetMails);
@@ -3727,7 +3893,7 @@ INTERNAL_FUNC int emstorage_get_mails(int account_id, int mailbox_id, email_emai
EM_DEBUG_LOG("conditional_clause_string [%s]", conditional_clause_string);
- if(!emstorage_query_mail_tbl(conditional_clause_string, transaction, &p_data_tbl, &count, &error)) {
+ if(!emstorage_query_mail_tbl(multi_user_name, conditional_clause_string, transaction, &p_data_tbl, &count, &error)) {
EM_DEBUG_EXCEPTION("emstorage_query_mail_tbl failed [%d]", error);
goto FINISH_OFF;
}
@@ -3758,7 +3924,7 @@ FINISH_OFF:
*
*
*/
-INTERNAL_FUNC int emstorage_get_searched_mail_list(int account_id, int mailbox_id, int thread_id, int search_type, const char *search_value, int start_index, int limit_count, email_sort_type_t sorting, int transaction, email_mail_list_item_t** mail_list, int *result_count, int *err_code)
+INTERNAL_FUNC int emstorage_get_searched_mail_list(char *multi_user_name, int account_id, int mailbox_id, int thread_id, int search_type, const char *search_value, int start_index, int limit_count, email_sort_type_t sorting, int transaction, email_mail_list_item_t **mail_list, int *result_count, int *err_code)
{
EM_DEBUG_FUNC_BEGIN();
@@ -3783,7 +3949,7 @@ INTERNAL_FUNC int emstorage_get_searched_mail_list(int account_id, int mailbox_i
EM_DEBUG_LOG("conditional_clause[%s]", conditional_clause);
- if(!emstorage_query_mail_list(conditional_clause, transaction, mail_list, result_count, &error)) {
+ if(!emstorage_query_mail_list(multi_user_name, conditional_clause, transaction, mail_list, result_count, &error)) {
EM_DEBUG_EXCEPTION("emstorage_query_mail_list [%d]", error);
goto FINISH_OFF;
}
@@ -3804,7 +3970,7 @@ FINISH_OFF:
}
-static int _get_password_file_name(int account_id, char *recv_password_file_name, char *send_password_file_name)
+static int _get_password_file_name(char *multi_user_name, int account_id, char *recv_password_file_name, char *send_password_file_name)
{
EM_DEBUG_FUNC_BEGIN("account_id[%d]", account_id);
@@ -3813,8 +3979,16 @@ static int _get_password_file_name(int account_id, char *recv_password_file_name
return EMAIL_ERROR_INVALID_PARAM;
}
- sprintf(recv_password_file_name, ".email_account_%d_recv", account_id);
- sprintf(send_password_file_name, ".email_account_%d_send", account_id);
+ EM_DEBUG_LOG("MULTI_USER_NAME : [%s]", multi_user_name);
+
+ if (EM_SAFE_STRLEN(multi_user_name) > 0) {
+ sprintf(recv_password_file_name, ".email_account_%d_recv_%s", account_id, multi_user_name);
+ sprintf(send_password_file_name, ".email_account_%d_send_%s", account_id, multi_user_name);
+ } else {
+ sprintf(recv_password_file_name, ".email_account_%d_recv", account_id);
+ sprintf(send_password_file_name, ".email_account_%d_send", account_id);
+ }
+
EM_DEBUG_FUNC_END();
return EMAIL_ERROR_NONE;
}
@@ -3844,8 +4018,7 @@ static int _read_password_from_secure_storage(char *file_name, char **password)
return ret;
}
-
-INTERNAL_FUNC int emstorage_get_account_by_id(int account_id, int pulloption, emstorage_account_tbl_t **account, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_get_account_by_id(char *multi_user_name, int account_id, int pulloption, emstorage_account_tbl_t **account, int transaction, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("account_id[%d], pulloption[%d], account[%p], transaction[%d], err_code[%p]", account_id, pulloption, account, transaction, err_code);
@@ -3866,7 +4039,8 @@ INTERNAL_FUNC int emstorage_get_account_by_id(int account_id, int pulloption, em
char recv_password_file_name[MAX_PW_FILE_NAME_LENGTH];
char send_password_file_name[MAX_PW_FILE_NAME_LENGTH];
- sqlite3 *local_db_handle = emstorage_get_db_connection();
+ sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name);
+
EMSTORAGE_START_READ_TRANSACTION(transaction);
/* Make query string */
@@ -4028,7 +4202,7 @@ INTERNAL_FUNC int emstorage_get_account_by_id(int account_id, int pulloption, em
if (pulloption & EMAIL_ACC_GET_OPT_PASSWORD) {
/* get password file name */
- if ((error = _get_password_file_name(p_data_tbl->account_id, recv_password_file_name, send_password_file_name)) != EMAIL_ERROR_NONE) {
+ if ((error = _get_password_file_name(multi_user_name, p_data_tbl->account_id, recv_password_file_name, send_password_file_name)) != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("_get_password_file_name failed [%d]", error);
goto FINISH_OFF;
}
@@ -4106,7 +4280,7 @@ FINISH_OFF:
return ret;
}
-INTERNAL_FUNC int emstorage_get_password_length_of_account(int account_id, int password_type, int *password_length, int *err_code)
+INTERNAL_FUNC int emstorage_get_password_length_of_account(char *multi_user_name, int account_id, int password_type, int *password_length, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("account_id[%d], password_length[%p], err_code[%p]", account_id, password_length, err_code);
@@ -4125,7 +4299,7 @@ INTERNAL_FUNC int emstorage_get_password_length_of_account(int account_id, int p
/* get password file name */
- if ((error = _get_password_file_name(account_id, recv_password_file_name, send_password_file_name)) != EMAIL_ERROR_NONE) {
+ if ((error = _get_password_file_name(multi_user_name, account_id, recv_password_file_name, send_password_file_name)) != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("_get_password_file_name failed.");
goto FINISH_OFF;
}
@@ -4164,7 +4338,7 @@ FINISH_OFF:
return ret;
}
-INTERNAL_FUNC int emstorage_update_account_password(int input_account_id, char *input_incoming_server_password, char *input_outgoing_server_password)
+INTERNAL_FUNC int emstorage_update_account_password(char *multi_user_name, int input_account_id, char *input_incoming_server_password, char *input_outgoing_server_password)
{
EM_DEBUG_FUNC_BEGIN("input_account_id[%d], input_incoming_server_password[%p], input_outgoing_server_password[%p]", input_account_id, input_incoming_server_password, input_outgoing_server_password);
@@ -4180,7 +4354,7 @@ INTERNAL_FUNC int emstorage_update_account_password(int input_account_id, char *
}
/* get password file name */
- if ((err = _get_password_file_name(input_account_id, recv_password_file_name, send_password_file_name)) != EMAIL_ERROR_NONE) {
+ if ((err = _get_password_file_name(multi_user_name, input_account_id, recv_password_file_name, send_password_file_name)) != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("_get_password_file_name failed.");
goto FINISH_OFF;
}
@@ -4225,7 +4399,7 @@ FINISH_OFF:
return err;
}
-INTERNAL_FUNC int emstorage_update_account(int account_id, emstorage_account_tbl_t* account_tbl, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_update_account(char *multi_user_name, int account_id, emstorage_account_tbl_t *account_tbl, int transaction, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("account_id[%d], account[%p], transaction[%d], err_code[%p]", account_id, account_tbl, transaction, err_code);
@@ -4242,8 +4416,9 @@ INTERNAL_FUNC int emstorage_update_account(int account_id, emstorage_account_tbl
DB_STMT hStmt = NULL;
char sql_query_string[QUERY_SIZE] = {0, };
- sqlite3 *local_db_handle = emstorage_get_db_connection();
- EMSTORAGE_START_WRITE_TRANSACTION(transaction, error);
+ sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name);
+
+ EMSTORAGE_START_WRITE_TRANSACTION(multi_user_name, transaction, error);
SNPRINTF(sql_query_string, sizeof(sql_query_string),
"UPDATE mail_account_tbl SET"
@@ -4310,6 +4485,7 @@ INTERNAL_FUNC int emstorage_update_account(int account_id, emstorage_account_tbl
", certificate_path = ?"
", cipher_type = ?"
", digest_type = ?"
+ ", user_name = ?"
" WHERE account_id = ?");
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc);
@@ -4383,6 +4559,7 @@ INTERNAL_FUNC int emstorage_update_account(int account_id, emstorage_account_tbl
_bind_stmt_field_data_string(hStmt, i++, account_tbl->certificate_path, 0, CERTIFICATE_PATH_LEN_IN_MAIL_ACCOUNT_TBL);
_bind_stmt_field_data_int(hStmt, i++, account_tbl->cipher_type);
_bind_stmt_field_data_int(hStmt, i++, account_tbl->digest_type);
+ _bind_stmt_field_data_string(hStmt, i++, account_tbl->user_name, 0, DISPLAY_NAME_FROM_LEN_IN_MAIL_ACCOUNT_TBL);
_bind_stmt_field_data_int(hStmt, i++, account_id);
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
@@ -4400,7 +4577,7 @@ INTERNAL_FUNC int emstorage_update_account(int account_id, emstorage_account_tbl
}
if (account_tbl->incoming_server_password || account_tbl->outgoing_server_password) {
- if((error = emstorage_update_account_password(account_id, account_tbl->incoming_server_password, account_tbl->outgoing_server_password)) != EMAIL_ERROR_NONE) {
+ if((error = emstorage_update_account_password(multi_user_name, account_id, account_tbl->incoming_server_password, account_tbl->outgoing_server_password)) != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("emstorage_update_account_password failed [%d]", error);
goto FINISH_OFF;
}
@@ -4409,7 +4586,7 @@ INTERNAL_FUNC int emstorage_update_account(int account_id, emstorage_account_tbl
ret = true;
FINISH_OFF:
- EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
+ EMSTORAGE_FINISH_WRITE_TRANSACTION(multi_user_name, transaction, ret, error);
if (hStmt != NULL) {
rc = sqlite3_finalize(hStmt);
@@ -4431,7 +4608,7 @@ FINISH_OFF:
return ret;
}
-INTERNAL_FUNC int emstorage_set_field_of_accounts_with_integer_value(int account_id, char *field_name, int value, int transaction)
+INTERNAL_FUNC int emstorage_set_field_of_accounts_with_integer_value(char *multi_user_name, int account_id, char *field_name, int value, int transaction)
{
EM_DEBUG_FUNC_BEGIN_SEC("account_id[%d], field_name[%s], value[%d], transaction[%d]", account_id, field_name, value, transaction);
int error = EMAIL_ERROR_NONE;
@@ -4444,7 +4621,7 @@ INTERNAL_FUNC int emstorage_set_field_of_accounts_with_integer_value(int account
return EMAIL_ERROR_INVALID_PARAM;
}
- local_db_handle = emstorage_get_db_connection();
+ local_db_handle = emstorage_get_db_connection(multi_user_name);
/* Write query string */
SNPRINTF(sql_query_string, QUERY_SIZE, "UPDATE mail_account_tbl SET %s = %d WHERE account_id = %d", field_name, value, account_id);
@@ -4452,7 +4629,7 @@ INTERNAL_FUNC int emstorage_set_field_of_accounts_with_integer_value(int account
EM_DEBUG_LOG_SEC("sql_query_string [%s]", sql_query_string);
/* Execute query */
- EMSTORAGE_START_WRITE_TRANSACTION(transaction, error);
+ EMSTORAGE_START_WRITE_TRANSACTION(multi_user_name, transaction, error);
error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string);
if (error != EMAIL_ERROR_NONE) {
@@ -4466,7 +4643,7 @@ INTERNAL_FUNC int emstorage_set_field_of_accounts_with_integer_value(int account
FINISH_OFF:
result = (error == EMAIL_ERROR_NONE) ? true : false;
- EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, result, error);
+ EMSTORAGE_FINISH_WRITE_TRANSACTION(multi_user_name, transaction, result, error);
if (error == EMAIL_ERROR_NONE) {
if (!emcore_notify_storage_event (NOTI_ACCOUNT_UPDATE, account_id, 0, field_name, value))
@@ -4476,7 +4653,7 @@ FINISH_OFF:
return error;
}
-INTERNAL_FUNC int emstorage_get_sync_status_of_account(int account_id, int *result_sync_status,int *err_code)
+INTERNAL_FUNC int emstorage_get_sync_status_of_account(char *multi_user_name, int account_id, int *result_sync_status,int *err_code)
{
EM_DEBUG_FUNC_BEGIN("account_id[%d], result_sync_status [%p], err_code[%p]", account_id, result_sync_status, err_code);
@@ -4490,7 +4667,7 @@ INTERNAL_FUNC int emstorage_get_sync_status_of_account(int account_id, int *resu
int error = EMAIL_ERROR_NONE, rc, ret = false, sync_status, count, i, col_index;
char sql_query_string[QUERY_SIZE] = {0, };
char **result = NULL;
- sqlite3 *local_db_handle = emstorage_get_db_connection();
+ sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name);
if(account_id)
SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT sync_status FROM mail_account_tbl WHERE account_id = %d", account_id);
@@ -4531,16 +4708,16 @@ FINISH_OFF:
return ret;
}
-INTERNAL_FUNC int emstorage_update_sync_status_of_account(int account_id, email_set_type_t set_operator, int sync_status, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_update_sync_status_of_account(char *multi_user_name, int account_id, email_set_type_t set_operator, int sync_status, int transaction, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("account_id[%d], set_operator[%d], sync_status [%d], transaction[%d], err_code[%p]", account_id, set_operator, sync_status, transaction, err_code);
int error = EMAIL_ERROR_NONE, rc, ret = false, set_value = sync_status, result_sync_status;
char sql_query_string[QUERY_SIZE] = {0, };
- sqlite3 *local_db_handle = emstorage_get_db_connection();
+ sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name);
if(set_operator != SET_TYPE_SET && account_id) {
- if(!emstorage_get_sync_status_of_account(account_id, &result_sync_status, &error)) {
+ if(!emstorage_get_sync_status_of_account(multi_user_name, account_id, &result_sync_status, &error)) {
EM_DEBUG_EXCEPTION("emstorage_get_sync_status_of_account failed [%d]", error);
if (err_code != NULL)
*err_code = error;
@@ -4561,7 +4738,7 @@ INTERNAL_FUNC int emstorage_update_sync_status_of_account(int account_id, email_
EM_DEBUG_LOG("set_value [%d]", set_value);
}
- EMSTORAGE_START_WRITE_TRANSACTION(transaction, error);
+ EMSTORAGE_START_WRITE_TRANSACTION(multi_user_name, transaction, error);
if(account_id)
SNPRINTF(sql_query_string, sizeof(sql_query_string), "UPDATE mail_account_tbl SET sync_status = %d WHERE account_id = %d", set_value, account_id);
@@ -4587,7 +4764,7 @@ INTERNAL_FUNC int emstorage_update_sync_status_of_account(int account_id, email_
ret = true;
FINISH_OFF:
- EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
+ EMSTORAGE_FINISH_WRITE_TRANSACTION(multi_user_name, transaction, ret, error);
if (error == EMAIL_ERROR_NONE) {
if (!emcore_notify_storage_event (NOTI_ACCOUNT_UPDATE_SYNC_STATUS, account_id, set_value, NULL, 0))
@@ -4601,7 +4778,7 @@ FINISH_OFF:
return ret;
}
-INTERNAL_FUNC int emstorage_add_account(emstorage_account_tbl_t* account_tbl, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_add_account(char *multi_user_name, emstorage_account_tbl_t *account_tbl, int transaction, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("account[%p], transaction[%d], err_code[%p]", account_tbl, transaction, err_code);
@@ -4620,9 +4797,9 @@ INTERNAL_FUNC int emstorage_add_account(emstorage_account_tbl_t* account_tbl, in
char recv_password_file_name[MAX_PW_FILE_NAME_LENGTH];
char send_password_file_name[MAX_PW_FILE_NAME_LENGTH];
- sqlite3 *local_db_handle = emstorage_get_db_connection();
+ sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name);
- EMSTORAGE_START_WRITE_TRANSACTION(transaction, error);
+ EMSTORAGE_START_WRITE_TRANSACTION(multi_user_name, transaction, error);
char *sql = "SELECT max(rowid) FROM mail_account_tbl;";
char **result = NULL;
@@ -4638,7 +4815,7 @@ INTERNAL_FUNC int emstorage_add_account(emstorage_account_tbl_t* account_tbl, in
account_tbl->account_id = rc;
- if ((error = _get_password_file_name(account_tbl->account_id, recv_password_file_name, send_password_file_name)) != EMAIL_ERROR_NONE) {
+ if ((error = _get_password_file_name(multi_user_name, account_tbl->account_id, recv_password_file_name, send_password_file_name)) != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("_get_password_file_name failed.");
goto FINISH_OFF;
}
@@ -4713,6 +4890,7 @@ INTERNAL_FUNC int emstorage_add_account(emstorage_account_tbl_t* account_tbl, in
" , ? " /* display_content_status */
" , ? " /* default_ringtone_status */
" , ? " /* alert_ringtone_path */
+ " , ? " /* user_name */
") ");
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc);
@@ -4787,6 +4965,7 @@ INTERNAL_FUNC int emstorage_add_account(emstorage_account_tbl_t* account_tbl, in
_bind_stmt_field_data_int(hStmt, i++, account_tbl->options.display_content_status);
_bind_stmt_field_data_int(hStmt, i++, account_tbl->options.default_ringtone_status);
_bind_stmt_field_data_string(hStmt, i++, account_tbl->options.alert_ringtone_path, 0, CERTIFICATE_PATH_LEN_IN_MAIL_ACCOUNT_TBL);
+ _bind_stmt_field_data_string(hStmt, i++, account_tbl->user_name, 0, CERTIFICATE_PATH_LEN_IN_MAIL_ACCOUNT_TBL);
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
@@ -4798,9 +4977,8 @@ INTERNAL_FUNC int emstorage_add_account(emstorage_account_tbl_t* account_tbl, in
/* save passwords to the secure storage */
EM_DEBUG_LOG_SEC("save to the secure storage : recv_file[%s], send_file[%s]", recv_password_file_name, send_password_file_name);
-
- error_from_ssm = ssa_put (recv_password_file_name,
- account_tbl->incoming_server_password,
+ error_from_ssm = ssa_put (recv_password_file_name,
+ account_tbl->incoming_server_password,
EM_SAFE_STRLEN(account_tbl->incoming_server_password)+1, /*must include null*/
ACCOUNT_PASSWORD_SS_GROUP_ID, NULL);
if (error_from_ssm < 0) {
@@ -4823,7 +5001,7 @@ INTERNAL_FUNC int emstorage_add_account(emstorage_account_tbl_t* account_tbl, in
ret = true;
FINISH_OFF:
- EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
+ EMSTORAGE_FINISH_WRITE_TRANSACTION(multi_user_name, transaction, ret, error);
if (hStmt != NULL) {
rc = sqlite3_finalize(hStmt);
@@ -4845,8 +5023,7 @@ FINISH_OFF:
return ret;
}
-
-INTERNAL_FUNC int emstorage_delete_account(int account_id, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_delete_account(char *multi_user_name, int account_id, int transaction, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("account_id[%d], transaction[%d], err_code[%p]", account_id, transaction, err_code);
@@ -4861,8 +5038,10 @@ INTERNAL_FUNC int emstorage_delete_account(int account_id, int transaction, int
int rc = -1, ret = false;
int error = EMAIL_ERROR_NONE;
int ssa_err = 0;
- sqlite3 *local_db_handle = emstorage_get_db_connection();
- EMSTORAGE_START_WRITE_TRANSACTION(transaction, error);
+
+ sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name);
+
+ EMSTORAGE_START_WRITE_TRANSACTION(multi_user_name, transaction, error);
/* TODO : delete password files - file names can be obtained from db or a rule that makes a name */
char sql_query_string[QUERY_SIZE] = {0, };
@@ -4870,7 +5049,7 @@ INTERNAL_FUNC int emstorage_delete_account(int account_id, int transaction, int
char send_password_file_name[MAX_PW_FILE_NAME_LENGTH];
/* get password file name */
- if ((error = _get_password_file_name(account_id, recv_password_file_name, send_password_file_name)) != EMAIL_ERROR_NONE) {
+ if ((error = _get_password_file_name(multi_user_name, account_id, recv_password_file_name, send_password_file_name)) != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("_get_password_file_name failed.");
goto FINISH_OFF;
}
@@ -4910,7 +5089,7 @@ INTERNAL_FUNC int emstorage_delete_account(int account_id, int transaction, int
ret = true;
FINISH_OFF:
- EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
+ EMSTORAGE_FINISH_WRITE_TRANSACTION(multi_user_name, transaction, ret, error);
if (err_code != NULL)
*err_code = error;
@@ -4955,6 +5134,7 @@ INTERNAL_FUNC int emstorage_free_account(emstorage_account_tbl_t** account_list,
EM_SAFE_FREE(p[i].options.signature);
EM_SAFE_FREE(p[i].options.alert_ringtone_path);
EM_SAFE_FREE(p[i].certificate_path);
+ EM_SAFE_FREE(p[i].user_name);
}
EM_SAFE_FREE(p);
@@ -4971,7 +5151,7 @@ FINISH_OFF:
return ret;
}
-INTERNAL_FUNC int emstorage_get_mailbox_count(int account_id, int local_yn, int *count, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_get_mailbox_count(char *multi_user_name, int account_id, int local_yn, int *count, int transaction, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("account_id[%d], local_yn[%d], count[%p], transaction[%d], err_code[%p]", account_id, local_yn, count, transaction, err_code);
@@ -4987,7 +5167,7 @@ INTERNAL_FUNC int emstorage_get_mailbox_count(int account_id, int local_yn, int
int error = EMAIL_ERROR_NONE;
char sql_query_string[QUERY_SIZE] = {0, };
- sqlite3 *local_db_handle = emstorage_get_db_connection();
+ sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name);
EMSTORAGE_START_READ_TRANSACTION(transaction);
SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT COUNT(*) FROM mail_box_tbl WHERE account_id = %d AND local_yn = %d", account_id, local_yn);
@@ -5015,7 +5195,7 @@ FINISH_OFF:
return ret;
}
-INTERNAL_FUNC int emstorage_get_mailbox_list(int account_id, int local_yn, email_mailbox_sort_type_t sort_type, int *select_num, emstorage_mailbox_tbl_t** mailbox_list, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_get_mailbox_list(char *multi_user_name, int account_id, int local_yn, email_mailbox_sort_type_t sort_type, int *select_num, emstorage_mailbox_tbl_t** mailbox_list, int transaction, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("account_id[%d], local_yn[%d], select_num[%p], mailbox_list[%p], transaction[%d], err_code[%p]", account_id, local_yn, select_num, mailbox_list, transaction, err_code);
@@ -5065,7 +5245,7 @@ INTERNAL_FUNC int emstorage_get_mailbox_list(int account_id, int local_yn, email
EM_DEBUG_LOG("ordering_clause_string[%s]", ordering_clause_string);
- if( (error = emstorage_query_mailbox_tbl(conditional_clause_string, ordering_clause_string, 0, transaction, mailbox_list, select_num)) != EMAIL_ERROR_NONE) {
+ if( (error = emstorage_query_mailbox_tbl(multi_user_name, conditional_clause_string, ordering_clause_string, 0, transaction, mailbox_list, select_num)) != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("emstorage_query_mailbox_tbl failed [%d]", error);
goto FINISH_OFF;
}
@@ -5081,7 +5261,7 @@ FINISH_OFF:
return ret;
}
-INTERNAL_FUNC int emstorage_get_mailbox_list_ex(int account_id, int local_yn, int with_count, int *select_num, emstorage_mailbox_tbl_t** mailbox_list, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_get_mailbox_list_ex(char *multi_user_name, int account_id, int local_yn, int with_count, int *select_num, emstorage_mailbox_tbl_t **mailbox_list, int transaction, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("account_id[%d], local_yn[%d], select_num[%p], mailbox_list[%p], transaction[%d], err_code[%p]", account_id, local_yn, select_num, mailbox_list, transaction, err_code);
@@ -5111,11 +5291,14 @@ INTERNAL_FUNC int emstorage_get_mailbox_list_ex(int account_id, int local_yn, in
SNPRINTF(conditional_clause_string + EM_SAFE_STRLEN(conditional_clause_string), sizeof(conditional_clause_string)-(EM_SAFE_STRLEN(conditional_clause_string)+1), " AND account_id = %d ", account_id);
}
- SNPRINTF(ordering_clause_string, QUERY_SIZE, " ORDER BY MBT.mailbox_name ");
+ SNPRINTF(ordering_clause_string, QUERY_SIZE, " ORDER BY CASE WHEN MBT.mailbox_name"
+ " GLOB \'[][~`!@#$%%^&*()_-+=|\\{}:;<>,.?/ ]*\'"
+ " THEN 2 ELSE 1 END ASC,"
+ " MBT.mailbox_name COLLATE CONVERTUTF8 ASC ");
EM_DEBUG_LOG("conditional_clause_string[%s]", conditional_clause_string);
EM_DEBUG_LOG("ordering_clause_string[%s]", ordering_clause_string);
- if( (error = emstorage_query_mailbox_tbl(conditional_clause_string, ordering_clause_string, 1, 1, mailbox_list, select_num)) != EMAIL_ERROR_NONE) {
+ if ((error = emstorage_query_mailbox_tbl(multi_user_name, conditional_clause_string, ordering_clause_string, 1, 1, mailbox_list, select_num)) != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("emstorage_query_mailbox_tbl failed [%d]", error);
goto FINISH_OFF;
}
@@ -5131,7 +5314,7 @@ FINISH_OFF:
return ret;
}
-INTERNAL_FUNC int emstorage_get_child_mailbox_list(int account_id, char *parent_mailbox_name, int *select_num, emstorage_mailbox_tbl_t** mailbox_list, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_get_child_mailbox_list(char *multi_user_name, int account_id, char *parent_mailbox_name, int *select_num, emstorage_mailbox_tbl_t **mailbox_list, int transaction, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("account_id[%d], parent_mailbox_name[%p], select_num[%p], mailbox_list[%p], transaction[%d], err_code[%p]", account_id, parent_mailbox_name, select_num, mailbox_list, transaction, err_code);
@@ -5149,7 +5332,7 @@ INTERNAL_FUNC int emstorage_get_child_mailbox_list(int account_id, char *parent_
sqlite3_snprintf(sizeof(conditional_clause_string), conditional_clause_string, "WHERE account_id = %d AND UPPER(mailbox_name) LIKE UPPER('%q%%')", account_id, parent_mailbox_name);
EM_DEBUG_LOG("conditional_clause_string[%s]", conditional_clause_string);
- if( (error = emstorage_query_mailbox_tbl(conditional_clause_string, " ORDER BY mailbox_name DESC ", 0, transaction, mailbox_list, select_num)) != EMAIL_ERROR_NONE) {
+ if( (error = emstorage_query_mailbox_tbl(multi_user_name, conditional_clause_string, " ORDER BY mailbox_name DESC ", 0, transaction, mailbox_list, select_num)) != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("emstorage_query_mailbox_tbl failed [%d]", error);
goto FINISH_OFF;
}
@@ -5165,7 +5348,7 @@ FINISH_OFF:
return ret;
}
-INTERNAL_FUNC int emstorage_get_mailbox_by_modifiable_yn(int account_id, int local_yn, int *select_num, emstorage_mailbox_tbl_t** mailbox_list, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_get_mailbox_by_modifiable_yn(char *multi_user_name, int account_id, int local_yn, int *select_num, emstorage_mailbox_tbl_t** mailbox_list, int transaction, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("account_id[%d], local_yn[%d], select_num[%p], mailbox_list[%p], transaction[%d], err_code[%p]", account_id, local_yn, select_num, mailbox_list, transaction, err_code);
if (account_id < FIRST_ACCOUNT_ID || !select_num || !mailbox_list) {
@@ -5184,7 +5367,7 @@ INTERNAL_FUNC int emstorage_get_mailbox_by_modifiable_yn(int account_id, int loc
SNPRINTF(conditional_clause_string, sizeof(conditional_clause_string), "WHERE account_id = %d AND modifiable_yn = 0", account_id);
EM_DEBUG_LOG("conditional_clause_string [%s]", conditional_clause_string);
- if( (error = emstorage_query_mailbox_tbl(conditional_clause_string, " ORDER BY mailbox_name", 0, transaction, mailbox_list, select_num)) != EMAIL_ERROR_NONE) {
+ if( (error = emstorage_query_mailbox_tbl(multi_user_name, conditional_clause_string, " ORDER BY mailbox_name", 0, transaction, mailbox_list, select_num)) != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("emstorage_query_mailbox_tbl failed [%d]", error);
goto FINISH_OFF;
}
@@ -5200,7 +5383,7 @@ FINISH_OFF:
return ret;
}
-INTERNAL_FUNC int emstorage_stamp_last_sync_time_of_mailbox(int input_mailbox_id, int input_transaction)
+INTERNAL_FUNC int emstorage_stamp_last_sync_time_of_mailbox(char *multi_user_name, int input_mailbox_id, int input_transaction)
{
EM_DEBUG_FUNC_BEGIN("input_mailbox_id [%d], input_transaction [%d]", input_mailbox_id, input_transaction);
@@ -5217,12 +5400,11 @@ INTERNAL_FUNC int emstorage_stamp_last_sync_time_of_mailbox(int input_mailbox_id
time(&current_time);
- local_db_handle = emstorage_get_db_connection();
-
- EMSTORAGE_START_WRITE_TRANSACTION(input_transaction, error);
+ local_db_handle = emstorage_get_db_connection(multi_user_name);
+ EMSTORAGE_START_WRITE_TRANSACTION(multi_user_name, input_transaction, error);
- SNPRINTF(sql_query_string, sizeof(sql_query_string),
- "UPDATE mail_box_tbl SET"
+ SNPRINTF(sql_query_string, sizeof(sql_query_string),
+ "UPDATE mail_box_tbl SET"
" last_sync_time = %d"
" WHERE mailbox_id = %d"
, (int)current_time
@@ -5240,13 +5422,13 @@ FINISH_OFF:
if(error == EMAIL_ERROR_NONE)
result_code = true;
- EMSTORAGE_FINISH_WRITE_TRANSACTION(input_transaction, result_code, error);
+ EMSTORAGE_FINISH_WRITE_TRANSACTION(multi_user_name, input_transaction, result_code, error);
EM_DEBUG_FUNC_END("error [%d]", error);
return error;
}
-INTERNAL_FUNC int emstorage_get_mailbox_by_name(int account_id, int local_yn, char *mailbox_name, emstorage_mailbox_tbl_t** result_mailbox, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_get_mailbox_by_name(char *multi_user_name, int account_id, int local_yn, char *mailbox_name, emstorage_mailbox_tbl_t **result_mailbox, int transaction, int *err_code)
{
EM_DEBUG_FUNC_BEGIN_SEC("account_id[%d], local_yn[%d], mailbox_name[%s], result_mailbox[%p], transaction[%d], err_code[%p]", account_id, local_yn, mailbox_name, result_mailbox, transaction, err_code);
EM_PROFILE_BEGIN(profile_emstorage_get_mailbox_by_name);
@@ -5293,7 +5475,7 @@ INTERNAL_FUNC int emstorage_get_mailbox_by_name(int account_id, int local_yn, ch
EM_DEBUG_LOG("conditional_clause_string = [%s]", conditional_clause_string);
- if( (error = emstorage_query_mailbox_tbl(conditional_clause_string, "", 0, transaction, result_mailbox, &result_count)) != EMAIL_ERROR_NONE) {
+ if( (error = emstorage_query_mailbox_tbl(multi_user_name, conditional_clause_string, "", 0, transaction, result_mailbox, &result_count)) != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("emstorage_query_mailbox_tbl failed [%d]", error);
goto FINISH_OFF;
}
@@ -5311,7 +5493,7 @@ FINISH_OFF:
return ret;
}
-INTERNAL_FUNC int emstorage_get_mailbox_by_mailbox_type(int account_id, email_mailbox_type_e mailbox_type, emstorage_mailbox_tbl_t **output_mailbox, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_get_mailbox_by_mailbox_type(char *multi_user_name, int account_id, email_mailbox_type_e mailbox_type, emstorage_mailbox_tbl_t **output_mailbox, int transaction, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("account_id[%d], mailbox_type[%d], output_mailbox[%p], transaction[%d], err_code[%p]", account_id, mailbox_type, output_mailbox, transaction, err_code);
@@ -5333,7 +5515,7 @@ INTERNAL_FUNC int emstorage_get_mailbox_by_mailbox_type(int account_id, email_ma
EM_DEBUG_LOG("conditional_clause_string = [%s]", conditional_clause_string);
- if( (error = emstorage_query_mailbox_tbl(conditional_clause_string, "", true, false, &result_mailbox, &result_count)) != EMAIL_ERROR_NONE) {
+ if( (error = emstorage_query_mailbox_tbl(multi_user_name, conditional_clause_string, "", true, false, &result_mailbox, &result_count)) != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("emstorage_query_mailbox_tbl error [%d]", error);
goto FINISH_OFF;
}
@@ -5351,7 +5533,7 @@ FINISH_OFF:
return ret;
}
-INTERNAL_FUNC int emstorage_get_mailbox_by_id(int input_mailbox_id, emstorage_mailbox_tbl_t** output_mailbox)
+INTERNAL_FUNC int emstorage_get_mailbox_by_id(char *multi_user_name, int input_mailbox_id, emstorage_mailbox_tbl_t** output_mailbox)
{
EM_DEBUG_FUNC_BEGIN("input_mailbox_id[%d], output_mailbox[%p]", input_mailbox_id, output_mailbox);
@@ -5368,7 +5550,9 @@ INTERNAL_FUNC int emstorage_get_mailbox_by_id(int input_mailbox_id, emstorage_ma
EM_DEBUG_LOG("conditional_clause_string = [%s]", conditional_clause_string);
- if( (ret = emstorage_query_mailbox_tbl(conditional_clause_string, "", true, false, output_mailbox, &result_count)) != EMAIL_ERROR_NONE) {
+ if ((ret = emstorage_query_mailbox_tbl(multi_user_name,
+ conditional_clause_string,
+ "", true, false, output_mailbox, &result_count)) != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("emstorage_query_mailbox_tbl failed [%d]", ret);
goto FINISH_OFF;
}
@@ -5379,7 +5563,7 @@ FINISH_OFF:
return ret;
}
-INTERNAL_FUNC int emstorage_get_mailbox_by_keyword(int account_id, char *keyword, emstorage_mailbox_tbl_t** result_mailbox, int * result_count, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_get_mailbox_by_keyword(char *multi_user_name, int account_id, char *keyword, emstorage_mailbox_tbl_t** result_mailbox, int * result_count, int transaction, int *err_code)
{
EM_DEBUG_FUNC_BEGIN_SEC("account_id[%d], keyword[%s], result_mailbox[%p], transaction[%d], err_code[%p]", account_id, keyword, result_mailbox, transaction, err_code);
@@ -5404,7 +5588,7 @@ INTERNAL_FUNC int emstorage_get_mailbox_by_keyword(int account_id, char *keyword
EM_DEBUG_LOG("conditional_clause_string = [%s]", conditional_clause_string);
- if ((error = emstorage_query_mailbox_tbl(conditional_clause_string, "", 0, transaction, result_mailbox, result_count)) != EMAIL_ERROR_NONE) {
+ if ((error = emstorage_query_mailbox_tbl(multi_user_name, conditional_clause_string, "", 0, transaction, result_mailbox, result_count)) != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("emstorage_query_mailbox_tbl failed [%d]", error);
goto FINISH_OFF;
}
@@ -5420,7 +5604,7 @@ FINISH_OFF:
return ret;
}
-INTERNAL_FUNC int emstorage_get_mailbox_id_by_mailbox_type(int account_id, email_mailbox_type_e mailbox_type, int *mailbox_id, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_get_mailbox_id_by_mailbox_type(char *multi_user_name, int account_id, email_mailbox_type_e mailbox_type, int *mailbox_id, int transaction, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("account_id[%d], mailbox_type[%d], mailbox_id[%p], transaction[%d], err_code[%p]", account_id, mailbox_type, mailbox_id, transaction, err_code);
if (account_id < FIRST_ACCOUNT_ID || (mailbox_type < EMAIL_MAILBOX_TYPE_INBOX || mailbox_type > EMAIL_MAILBOX_TYPE_ALL_EMAILS) || !mailbox_id) {
@@ -5436,16 +5620,16 @@ INTERNAL_FUNC int emstorage_get_mailbox_id_by_mailbox_type(int account_id, email
DB_STMT hStmt = NULL;
char sql_query_string[QUERY_SIZE] = {0, };
- sqlite3 *local_db_handle = emstorage_get_db_connection();
+ sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name);
EMSTORAGE_START_READ_TRANSACTION(transaction);
/* Check whether the account exists. */
- if (!emstorage_get_account_by_id(account_id, EMAIL_ACC_GET_OPT_ACCOUNT_NAME, &account, true, &error) || !account) {
+ if (!emstorage_get_account_by_id(multi_user_name, account_id, EMAIL_ACC_GET_OPT_ACCOUNT_NAME, &account, true, &error) || !account) {
EM_DEBUG_EXCEPTION("emstorage_get_account_by_id failed - %d", error);
goto FINISH_OFF;
}
- if (account )
+ if (account)
emstorage_free_account(&account, 1, NULL);
SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT mailbox_id FROM mail_box_tbl WHERE account_id = %d AND mailbox_type = %d ", account_id, mailbox_type);
@@ -5490,7 +5674,7 @@ FINISH_OFF:
return ret;
}
-INTERNAL_FUNC int emstorage_get_mailbox_name_by_mailbox_type(int account_id, email_mailbox_type_e mailbox_type, char **mailbox_name, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_get_mailbox_name_by_mailbox_type(char *multi_user_name, int account_id, email_mailbox_type_e mailbox_type, char **mailbox_name, int transaction, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("account_id[%d], mailbox_type[%d], mailbox_name[%p], transaction[%d], err_code[%p]", account_id, mailbox_type, mailbox_name, transaction, err_code);
if (account_id < FIRST_ACCOUNT_ID || (mailbox_type < EMAIL_MAILBOX_TYPE_INBOX || mailbox_type > EMAIL_MAILBOX_TYPE_ALL_EMAILS) || !mailbox_name) {
@@ -5506,16 +5690,16 @@ INTERNAL_FUNC int emstorage_get_mailbox_name_by_mailbox_type(int account_id, ema
DB_STMT hStmt = NULL;
char sql_query_string[QUERY_SIZE] = {0, };
- sqlite3 *local_db_handle = emstorage_get_db_connection();
+ sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name);
EMSTORAGE_START_READ_TRANSACTION(transaction);
/* Check whether the account exists. */
- if (!emstorage_get_account_by_id(account_id, EMAIL_ACC_GET_OPT_ACCOUNT_NAME, &account, true, &error) || !account) {
+ if (!emstorage_get_account_by_id(multi_user_name, account_id, EMAIL_ACC_GET_OPT_ACCOUNT_NAME, &account, true, &error) || !account) {
EM_DEBUG_EXCEPTION("emstorage_get_account_by_id failed - %d", error);
goto FINISH_OFF;
}
- if (account )
+ if (account)
emstorage_free_account(&account, 1, NULL);
SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT mailbox_name FROM mail_box_tbl WHERE account_id = %d AND mailbox_type = %d ", account_id, mailbox_type);
@@ -5561,7 +5745,7 @@ FINISH_OFF:
return ret;
}
-INTERNAL_FUNC int emstorage_update_mailbox_modifiable_yn(int account_id, int local_yn, char *mailbox_name, int modifiable_yn, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_update_mailbox_modifiable_yn(char *multi_user_name, int account_id, int local_yn, char *mailbox_name, int modifiable_yn, int transaction, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("account_id [%d], local_yn [%d], mailbox_name [%p], modifiable_yn [%d], transaction [%d], err_code [%p]", account_id, local_yn, mailbox_name, modifiable_yn, transaction, err_code);
int ret = false;
@@ -5577,9 +5761,9 @@ INTERNAL_FUNC int emstorage_update_mailbox_modifiable_yn(int account_id, int loc
}
}
- sqlite3 *local_db_handle = emstorage_get_db_connection();
+ sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name);
- EMSTORAGE_START_WRITE_TRANSACTION(transaction, error);
+ EMSTORAGE_START_WRITE_TRANSACTION(multi_user_name, transaction, error);
SNPRINTF(sql_query_string, sizeof(sql_query_string),
"UPDATE mail_box_tbl SET"
@@ -5601,7 +5785,7 @@ INTERNAL_FUNC int emstorage_update_mailbox_modifiable_yn(int account_id, int loc
ret = true;
FINISH_OFF:
- EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
+ EMSTORAGE_FINISH_WRITE_TRANSACTION(multi_user_name, transaction, ret, error);
EM_SAFE_FREE(replaced_mailbox_name);
@@ -5613,25 +5797,32 @@ FINISH_OFF:
}
-
-INTERNAL_FUNC int emstorage_update_mailbox_total_count(int account_id, int input_mailbox_id, int total_count_on_server, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_update_mailbox_total_count(char *multi_user_name,
+ int account_id,
+ int input_mailbox_id,
+ int total_count_on_server,
+ int transaction,
+ int *err_code)
{
- EM_DEBUG_FUNC_BEGIN("account_id[%d], input_mailbox_id[%d], total_count_on_server[%d], transaction[%d], err_code[%p]", account_id, input_mailbox_id, total_count_on_server, transaction, err_code);
+ EM_DEBUG_FUNC_BEGIN("account_id[%d], input_mailbox_id[%d], total_count_on_server[%d], "
+ "transaction[%d], err_code[%p]",
+ account_id, input_mailbox_id, total_count_on_server, transaction, err_code);
+
int ret = false;
int error = EMAIL_ERROR_NONE;
char sql_query_string[QUERY_SIZE] = {0, };
if (account_id <= 0 || input_mailbox_id <= 0) {
EM_DEBUG_EXCEPTION("account_id[%d], input_mailbox_id[%d]", account_id, input_mailbox_id);
-
if (err_code != NULL)
*err_code = EMAIL_ERROR_INVALID_PARAM;
EM_DEBUG_FUNC_END("ret [%d]", ret);
return false;
}
- sqlite3 *local_db_handle = emstorage_get_db_connection();
- EMSTORAGE_START_WRITE_TRANSACTION(transaction, error);
+ sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name);
+
+ EMSTORAGE_START_WRITE_TRANSACTION(multi_user_name, transaction, error);
SNPRINTF(sql_query_string, sizeof(sql_query_string),
"UPDATE mail_box_tbl SET"
@@ -5652,7 +5843,8 @@ INTERNAL_FUNC int emstorage_update_mailbox_total_count(int account_id, int input
ret = true;
FINISH_OFF:
- EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
+
+ EMSTORAGE_FINISH_WRITE_TRANSACTION(multi_user_name, transaction, ret, error);
if (err_code != NULL)
*err_code = error;
@@ -5662,8 +5854,7 @@ FINISH_OFF:
}
-
-INTERNAL_FUNC int emstorage_update_mailbox(int account_id, int local_yn, int input_mailbox_id, emstorage_mailbox_tbl_t* result_mailbox, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_update_mailbox(char *multi_user_name, int account_id, int local_yn, int input_mailbox_id, emstorage_mailbox_tbl_t *result_mailbox, int transaction, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("account_id[%d], local_yn[%d], input_mailbox_id[%d], result_mailbox[%p], transaction[%d], err_code[%p]", account_id, local_yn, input_mailbox_id, result_mailbox, transaction, err_code);
@@ -5682,8 +5873,8 @@ INTERNAL_FUNC int emstorage_update_mailbox(int account_id, int local_yn, int inp
DB_STMT hStmt = NULL;
int i = 0;
- sqlite3 *local_db_handle = emstorage_get_db_connection();
- EMSTORAGE_START_WRITE_TRANSACTION(transaction, error);
+ sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name);
+ EMSTORAGE_START_WRITE_TRANSACTION(multi_user_name, transaction, error);
if (local_yn != -1) {
SNPRINTF(sql_query_string, sizeof(sql_query_string),
@@ -5745,7 +5936,7 @@ INTERNAL_FUNC int emstorage_update_mailbox(int account_id, int local_yn, int inp
ret = true;
FINISH_OFF:
- EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
+ EMSTORAGE_FINISH_WRITE_TRANSACTION(multi_user_name, transaction, ret, error);
if (hStmt != NULL) {
rc = sqlite3_finalize(hStmt);
@@ -5762,8 +5953,7 @@ FINISH_OFF:
return ret;
}
-
-INTERNAL_FUNC int emstorage_update_mailbox_type(int account_id, int local_yn, int input_mailbox_id, email_mailbox_type_e new_mailbox_type, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_update_mailbox_type(char *multi_user_name, int account_id, int local_yn, int input_mailbox_id, email_mailbox_type_e new_mailbox_type, int transaction, int *err_code)
{
EM_DEBUG_FUNC_BEGIN_SEC("account_id[%d], local_yn[%d], input_mailbox_id[%d], new_mailbox_type[%d], transaction[%d], err_code[%p]", account_id, local_yn, input_mailbox_id, new_mailbox_type, transaction, err_code);
@@ -5779,8 +5969,8 @@ INTERNAL_FUNC int emstorage_update_mailbox_type(int account_id, int local_yn, in
int error = EMAIL_ERROR_NONE;
char sql_query_string[QUERY_SIZE] = {0, };
- sqlite3 *local_db_handle = emstorage_get_db_connection();
- EMSTORAGE_START_WRITE_TRANSACTION(transaction, error);
+ sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name);
+ EMSTORAGE_START_WRITE_TRANSACTION(multi_user_name, transaction, error);
EM_DEBUG_LOG("emstorage_update_mailbox_type");
@@ -5875,7 +6065,7 @@ INTERNAL_FUNC int emstorage_update_mailbox_type(int account_id, int local_yn, in
ret = true;
FINISH_OFF:
- EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
+ EMSTORAGE_FINISH_WRITE_TRANSACTION(multi_user_name, transaction, ret, error);
if (hStmt_box_tbl != NULL) {
rc = sqlite3_finalize(hStmt_box_tbl);
@@ -5900,7 +6090,7 @@ FINISH_OFF:
return ret;
}
-INTERNAL_FUNC int emstorage_set_local_mailbox(int input_mailbox_id, int input_is_local_mailbox, int transaction)
+INTERNAL_FUNC int emstorage_set_local_mailbox(char *multi_user_name, int input_mailbox_id, int input_is_local_mailbox, int transaction)
{
EM_DEBUG_FUNC_BEGIN("input_mailbox_id[%d], new_mailbox_type[%d], transaction[%d], err_code[%p]", input_mailbox_id, input_is_local_mailbox, transaction);
@@ -5913,9 +6103,9 @@ INTERNAL_FUNC int emstorage_set_local_mailbox(int input_mailbox_id, int input_is
return EMAIL_ERROR_INVALID_PARAM;
}
- sqlite3 *local_db_handle = emstorage_get_db_connection();
+ sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name);
- EMSTORAGE_START_WRITE_TRANSACTION(transaction, error);
+ EMSTORAGE_START_WRITE_TRANSACTION(multi_user_name, transaction, error);
EM_DEBUG_LOG("emstorage_update_mailbox_type");
@@ -5955,7 +6145,7 @@ INTERNAL_FUNC int emstorage_set_local_mailbox(int input_mailbox_id, int input_is
ret = true;
FINISH_OFF:
- EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
+ EMSTORAGE_FINISH_WRITE_TRANSACTION(multi_user_name, transaction, ret, error);
if (hStmt != NULL) {
rc = sqlite3_finalize(hStmt);
@@ -5969,7 +6159,7 @@ FINISH_OFF:
return error;
}
-INTERNAL_FUNC int emstorage_set_field_of_mailbox_with_integer_value(int input_account_id, int *input_mailbox_id_array, int input_mailbox_id_count, char *input_field_name, int input_value, int transaction)
+INTERNAL_FUNC int emstorage_set_field_of_mailbox_with_integer_value(char *multi_user_name, int input_account_id, int *input_mailbox_id_array, int input_mailbox_id_count, char *input_field_name, int input_value, int transaction)
{
EM_DEBUG_FUNC_BEGIN("input_account_id [%d] input_mailbox_id_array[%p] input_mailbox_id_count[%d] input_field_name[%p] input_value[%d] err_code[%p]", input_account_id, input_mailbox_id_array, input_mailbox_id_count, input_field_name, input_value, transaction);
int i = 0;
@@ -5987,7 +6177,7 @@ INTERNAL_FUNC int emstorage_set_field_of_mailbox_with_integer_value(int input_ac
return EMAIL_ERROR_INVALID_PARAM;
}
- local_db_handle = emstorage_get_db_connection();
+ local_db_handle = emstorage_get_db_connection(multi_user_name);
/* Generating mail id list string */
mailbox_id_string_buffer_length = MAILBOX_ID_STRING_LENGTH * input_mailbox_id_count;
@@ -6023,7 +6213,7 @@ INTERNAL_FUNC int emstorage_set_field_of_mailbox_with_integer_value(int input_ac
EM_DEBUG_LOG_SEC("sql_query_string [%s]", sql_query_string);
/* Execute query */
- EMSTORAGE_START_WRITE_TRANSACTION(transaction, err);
+ EMSTORAGE_START_WRITE_TRANSACTION(multi_user_name, transaction, err);
err = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string);
if (err != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", err);
@@ -6036,7 +6226,7 @@ INTERNAL_FUNC int emstorage_set_field_of_mailbox_with_integer_value(int input_ac
result = true;
FINISH_OFF:
- EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, result, err);
+ EMSTORAGE_FINISH_WRITE_TRANSACTION(multi_user_name, transaction, result, err);
if (err == EMAIL_ERROR_NONE && parameter_string) {
if (!emcore_notify_storage_event (NOTI_MAILBOX_FIELD_UPDATE, input_account_id, 0, parameter_string, input_value))
@@ -6051,7 +6241,7 @@ FINISH_OFF:
return err;
}
-INTERNAL_FUNC int emstorage_add_mailbox(emstorage_mailbox_tbl_t* mailbox_tbl, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_add_mailbox(char *multi_user_name, emstorage_mailbox_tbl_t *mailbox_tbl, int transaction, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("mailbox_tbl[%p], transaction[%d], err_code[%p]", mailbox_tbl, transaction, err_code);
@@ -6067,8 +6257,8 @@ INTERNAL_FUNC int emstorage_add_mailbox(emstorage_mailbox_tbl_t* mailbox_tbl, in
char sql_query_string[QUERY_SIZE] = {0,};
char **result = NULL;
time_t current_time;
- sqlite3 *local_db_handle = emstorage_get_db_connection();
- EMSTORAGE_START_WRITE_TRANSACTION(transaction, error);
+ sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name);
+ EMSTORAGE_START_WRITE_TRANSACTION(multi_user_name, transaction, error);
EM_SAFE_STRCPY(sql_query_string, "SELECT max(rowid) FROM mail_box_tbl;");
@@ -6139,7 +6329,7 @@ INTERNAL_FUNC int emstorage_add_mailbox(emstorage_mailbox_tbl_t* mailbox_tbl, in
ret = true;
FINISH_OFF:
- EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
+ EMSTORAGE_FINISH_WRITE_TRANSACTION(multi_user_name, transaction, ret, error);
if (hStmt != NULL) {
rc = sqlite3_finalize(hStmt);
if (rc != SQLITE_OK) {
@@ -6161,7 +6351,7 @@ FINISH_OFF:
return ret;
}
-INTERNAL_FUNC int emstorage_set_all_mailbox_modifiable_yn(int account_id, int modifiable_yn, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_set_all_mailbox_modifiable_yn(char *multi_user_name, int account_id, int modifiable_yn, int transaction, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("account_id[%d], modifiable_yn[%d], err_code[%p]", account_id, modifiable_yn, err_code);
@@ -6176,8 +6366,8 @@ INTERNAL_FUNC int emstorage_set_all_mailbox_modifiable_yn(int account_id, int mo
int rc, ret = false;
int error = EMAIL_ERROR_NONE;
char sql_query_string[QUERY_SIZE] = {0,};
- sqlite3 *local_db_handle = emstorage_get_db_connection();
- EMSTORAGE_START_WRITE_TRANSACTION(transaction, error);
+ sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name);
+ EMSTORAGE_START_WRITE_TRANSACTION(multi_user_name, transaction, error);
SNPRINTF(sql_query_string, sizeof(sql_query_string), "UPDATE mail_box_tbl SET modifiable_yn = %d WHERE account_id = %d", modifiable_yn, account_id);
@@ -6196,7 +6386,7 @@ INTERNAL_FUNC int emstorage_set_all_mailbox_modifiable_yn(int account_id, int mo
ret = true;
FINISH_OFF:
- EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
+ EMSTORAGE_FINISH_WRITE_TRANSACTION(multi_user_name, transaction, ret, error);
if (err_code != NULL)
*err_code = error;
@@ -6206,7 +6396,7 @@ FINISH_OFF:
}
-INTERNAL_FUNC int emstorage_delete_mailbox(int account_id, int local_yn, int input_mailbox_id, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_delete_mailbox(char *multi_user_name, int account_id, int local_yn, int input_mailbox_id, int transaction, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("account_id[%d], local_yn[%d], input_mailbox_id[%d], transaction[%d], err_code[%p]", account_id, local_yn, input_mailbox_id, transaction, err_code);
@@ -6221,8 +6411,8 @@ INTERNAL_FUNC int emstorage_delete_mailbox(int account_id, int local_yn, int inp
int rc, ret = false;
int error = EMAIL_ERROR_NONE;
char sql_query_string[QUERY_SIZE] = {0, };
- sqlite3 *local_db_handle = emstorage_get_db_connection();
- EMSTORAGE_START_WRITE_TRANSACTION(transaction, error);
+ sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name);
+ EMSTORAGE_START_WRITE_TRANSACTION(multi_user_name, transaction, error);
if (local_yn == -1)
SNPRINTF(sql_query_string, sizeof(sql_query_string), "DELETE FROM mail_box_tbl WHERE account_id = %d ", account_id);
@@ -6250,7 +6440,7 @@ INTERNAL_FUNC int emstorage_delete_mailbox(int account_id, int local_yn, int inp
FINISH_OFF:
- EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
+ EMSTORAGE_FINISH_WRITE_TRANSACTION(multi_user_name, transaction, ret, error);
if(error == EMAIL_ERROR_NONE) {
if (!emcore_notify_storage_event (NOTI_MAILBOX_DELETE, account_id, input_mailbox_id, NULL, 0))
@@ -6301,7 +6491,7 @@ FINISH_OFF:
return ret;
}
-INTERNAL_FUNC int emstorage_get_count_read_mail_uid(int account_id, char *mailbox_name, int *count, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_get_count_read_mail_uid(char *multi_user_name, int account_id, char *mailbox_name, int *count, int transaction, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("account_id[%d], mailbox_name[%p], count[%p], transaction[%d], err_code[%p]", account_id, mailbox_name , count, transaction, err_code);
@@ -6327,7 +6517,7 @@ INTERNAL_FUNC int emstorage_get_count_read_mail_uid(int account_id, char *mailbo
EM_DEBUG_LOG_SEC("replaced_mailbox_name : [%s]", replaced_mailbox_name);
- sqlite3 *local_db_handle = emstorage_get_db_connection();
+ sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name);
EMSTORAGE_START_READ_TRANSACTION(transaction);
SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT COUNT(*) FROM mail_read_mail_uid_tbl WHERE account_id = %d AND mailbox_name = '%s' ", account_id, replaced_mailbox_name);
EM_DEBUG_LOG_SEC(">>> SQL [ %s ] ", sql_query_string);
@@ -6355,9 +6545,7 @@ FINISH_OFF:
return ret;
}
-
-
-INTERNAL_FUNC int emstorage_check_read_mail_uid(int account_id, char *mailbox_name, char *uid, int *exist, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_check_read_mail_uid(char *multi_user_name, int account_id, char *mailbox_name, char *uid, int *exist, int transaction, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("account_id[%d], mailbox_name[%p], uid[%p], exist[%p], transaction[%d], err_code[%p]", account_id, mailbox_name , uid, exist, transaction, err_code);
@@ -6376,7 +6564,7 @@ INTERNAL_FUNC int emstorage_check_read_mail_uid(int account_id, char *mailbox_na
EM_DEBUG_LOG_SEC("replaced_mailbox_name : [%s]", replaced_mailbox_name);
- sqlite3 *local_db_handle = emstorage_get_db_connection();
+ sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name);
EMSTORAGE_START_READ_TRANSACTION(transaction);
if (mailbox_name) {
@@ -6420,7 +6608,7 @@ FINISH_OFF:
return ret;
}
-INTERNAL_FUNC int emstorage_get_downloaded_mail(int mail_id, emstorage_mail_tbl_t** mail, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_get_downloaded_mail(char *multi_user_name, int mail_id, emstorage_mail_tbl_t **mail, int transaction, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("mail_id[%d], mail[%p], err_code[%p]", mail_id, mail, err_code);
@@ -6436,7 +6624,7 @@ INTERNAL_FUNC int emstorage_get_downloaded_mail(int mail_id, emstorage_mail_tbl_
DB_STMT hStmt = NULL;
char sql_query_string[QUERY_SIZE] = {0, };
- sqlite3 *local_db_handle = emstorage_get_db_connection();
+ sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name);
EMSTORAGE_START_READ_TRANSACTION(transaction);
SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT * FROM mail_read_mail_uid_tbl WHERE local_uid = %d", mail_id);
@@ -6491,7 +6679,7 @@ FINISH_OFF:
return ret;
}
-INTERNAL_FUNC int emstorage_get_downloaded_list(int account_id, int mailbox_id, emstorage_read_mail_uid_tbl_t** read_mail_uid, int *count, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_get_downloaded_list(char *multi_user_name, int account_id, int mailbox_id, emstorage_read_mail_uid_tbl_t **read_mail_uid, int *count, int transaction, int *err_code)
{
EM_PROFILE_BEGIN(emStorageGetDownloadList);
EM_DEBUG_FUNC_BEGIN("account_id[%d], mailbox_id[%d], read_mail_uid[%p], count[%p], transaction[%d], err_code[%p]", account_id, mailbox_id, read_mail_uid, count, transaction, err_code);
@@ -6512,7 +6700,7 @@ INTERNAL_FUNC int emstorage_get_downloaded_list(int account_id, int mailbox_id,
emstorage_read_mail_uid_tbl_t* p_data_tbl = NULL;
int i = 0;
- sqlite3 *local_db_handle = emstorage_get_db_connection();
+ sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name);
EMSTORAGE_START_READ_TRANSACTION(transaction);
if (mailbox_id)
@@ -6597,7 +6785,7 @@ FINISH_OFF:
return ret;
}
-INTERNAL_FUNC int emstorage_get_downloaded_mail_size(int account_id, char *mailbox_id, int local_uid, char *mailbox_name, char *uid, int *mail_size, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_get_downloaded_mail_size(char *multi_user_name, int account_id, char *mailbox_id, int local_uid, char *mailbox_name, char *uid, int *mail_size, int transaction, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("account_id[%d], mailbox_id[%p], locacal_uid[%d], mailbox_name[%p], uid[%p], mail_size[%p], transaction[%d], err_code[%p]", account_id, mailbox_id, local_uid, mailbox_name, uid, mail_size, transaction, err_code);
@@ -6615,7 +6803,7 @@ INTERNAL_FUNC int emstorage_get_downloaded_mail_size(int account_id, char *mailb
char sql_query_string[QUERY_SIZE] = {0, };
char *replaced_mailbox_name = NULL;
- sqlite3 *local_db_handle = emstorage_get_db_connection();
+ sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name);
EMSTORAGE_START_READ_TRANSACTION(transaction);
if (mailbox_name) {
@@ -6686,7 +6874,7 @@ FINISH_OFF:
return ret;
}
-INTERNAL_FUNC int emstorage_add_downloaded_mail(emstorage_read_mail_uid_tbl_t* read_mail_uid, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_add_downloaded_mail(char *multi_user_name, emstorage_read_mail_uid_tbl_t *read_mail_uid, int transaction, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("read_mail_uid[%p], transaction[%d], err_code[%p]", read_mail_uid, transaction, err_code);
@@ -6702,8 +6890,8 @@ INTERNAL_FUNC int emstorage_add_downloaded_mail(emstorage_read_mail_uid_tbl_t* r
DB_STMT hStmt = NULL;
char sql_query_string[QUERY_SIZE] = {0, };
- sqlite3 *local_db_handle = emstorage_get_db_connection();
- EMSTORAGE_START_WRITE_TRANSACTION(transaction, error);
+ sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name);
+ EMSTORAGE_START_WRITE_TRANSACTION(multi_user_name, transaction, error);
char *sql = "SELECT max(rowid) FROM mail_read_mail_uid_tbl;";
char **result = NULL;
@@ -6766,7 +6954,7 @@ INTERNAL_FUNC int emstorage_add_downloaded_mail(emstorage_read_mail_uid_tbl_t* r
ret = true;
FINISH_OFF:
- EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
+ EMSTORAGE_FINISH_WRITE_TRANSACTION(multi_user_name, transaction, ret, error);
if (hStmt != NULL) {
rc = sqlite3_finalize(hStmt);
if (rc != SQLITE_OK) {
@@ -6783,7 +6971,7 @@ FINISH_OFF:
}
#ifdef __FEATURE_BODY_SEARCH__
-INTERNAL_FUNC int emstorage_add_mail_text(emstorage_mail_text_tbl_t* mail_text, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_add_mail_text(char *multi_user_name, emstorage_mail_text_tbl_t* mail_text, int transaction, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("mail_text[%p], transaction[%d], err_code[%p]", mail_text, transaction, err_code);
@@ -6799,8 +6987,8 @@ INTERNAL_FUNC int emstorage_add_mail_text(emstorage_mail_text_tbl_t* mail_text,
DB_STMT hStmt = NULL;
char sql_query_string[QUERY_SIZE] = {0, };
- sqlite3 *local_db_handle = emstorage_get_db_connection();
- EMSTORAGE_START_WRITE_TRANSACTION(transaction, error);
+ sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name);
+ EMSTORAGE_START_WRITE_TRANSACTION(multi_user_name, transaction, error);
char *sql = "SELECT max(rowid) FROM mail_text_tbl;";
char **result = NULL;
@@ -6844,7 +7032,7 @@ INTERNAL_FUNC int emstorage_add_mail_text(emstorage_mail_text_tbl_t* mail_text,
ret = true;
FINISH_OFF:
- EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
+ EMSTORAGE_FINISH_WRITE_TRANSACTION(multi_user_name, transaction, ret, error);
if (hStmt != NULL) {
rc = sqlite3_finalize(hStmt);
if (rc != SQLITE_OK) {
@@ -6861,7 +7049,7 @@ FINISH_OFF:
}
#endif
-INTERNAL_FUNC int emstorage_change_read_mail_uid(int account_id, int mailbox_id, int local_uid, char *mailbox_name, char *uid, emstorage_read_mail_uid_tbl_t* read_mail_uid, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_change_read_mail_uid(char *multi_user_name, int account_id, int mailbox_id, int local_uid, char *mailbox_name, char *uid, emstorage_read_mail_uid_tbl_t* read_mail_uid, int transaction, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("account_id[%d], mailbox_id[%d], local_uid[%d], mailbox_name[%p], uid[%p], read_mail_uid[%p], transaction[%d], err_code[%p]", account_id, mailbox_id, local_uid, mailbox_name, uid, read_mail_uid, transaction, err_code);
@@ -6878,9 +7066,9 @@ INTERNAL_FUNC int emstorage_change_read_mail_uid(int account_id, int mailbox_id,
DB_STMT hStmt = NULL;
char sql_query_string[QUERY_SIZE] = {0, };
- sqlite3 *local_db_handle = emstorage_get_db_connection();
+ sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name);
- EMSTORAGE_START_WRITE_TRANSACTION(transaction, error);
+ EMSTORAGE_START_WRITE_TRANSACTION(multi_user_name, transaction, error);
SNPRINTF(sql_query_string, sizeof(sql_query_string),
"UPDATE mail_read_mail_uid_tbl SET"
@@ -6929,7 +7117,7 @@ INTERNAL_FUNC int emstorage_change_read_mail_uid(int account_id, int mailbox_id,
ret = true;
FINISH_OFF:
- EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
+ EMSTORAGE_FINISH_WRITE_TRANSACTION(multi_user_name, transaction, ret, error);
if (hStmt != NULL) {
rc = sqlite3_finalize(hStmt);
if (rc != SQLITE_OK) {
@@ -6945,7 +7133,7 @@ FINISH_OFF:
return ret;
}
-INTERNAL_FUNC int emstorage_remove_downloaded_mail(int account_id, char *mailbox_name, char *uid, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_remove_downloaded_mail(char *multi_user_name, int account_id, char *mailbox_name, char *uid, int transaction, int *err_code)
{
EM_DEBUG_FUNC_BEGIN_SEC("account_id[%d], mailbox_name[%s], uid[%s], transaction[%d], err_code[%p]", account_id, mailbox_name, uid, transaction, err_code);
@@ -6961,9 +7149,9 @@ INTERNAL_FUNC int emstorage_remove_downloaded_mail(int account_id, char *mailbox
int error = EMAIL_ERROR_NONE;
char sql_query_string[QUERY_SIZE] = {0, };
char *replaced_mailbox_name = NULL;
- sqlite3 *local_db_handle = emstorage_get_db_connection();
+ sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name);
- EMSTORAGE_START_WRITE_TRANSACTION(transaction, error);
+ EMSTORAGE_START_WRITE_TRANSACTION(multi_user_name, transaction, error);
SNPRINTF(sql_query_string, sizeof(sql_query_string), "DELETE FROM mail_read_mail_uid_tbl WHERE account_id = %d ", account_id);
@@ -6990,7 +7178,7 @@ INTERNAL_FUNC int emstorage_remove_downloaded_mail(int account_id, char *mailbox
ret = true;
FINISH_OFF:
- EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
+ EMSTORAGE_FINISH_WRITE_TRANSACTION(multi_user_name, transaction, ret, error);
EM_SAFE_FREE(replaced_mailbox_name);
@@ -7037,7 +7225,7 @@ FINISH_OFF:
return ret;
}
-INTERNAL_FUNC int emstorage_get_rule_count_by_account_id(int account_id, int *count, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_get_rule_count_by_account_id(char *multi_user_name, int account_id, int *count, int transaction, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("account_id [%d], count[%p], transaction[%d], err_code[%p]", count, transaction, err_code);
@@ -7053,7 +7241,7 @@ INTERNAL_FUNC int emstorage_get_rule_count_by_account_id(int account_id, int *co
int error = EMAIL_ERROR_NONE;
char sql_query_string[QUERY_SIZE] = {0, };
- sqlite3 *local_db_handle = emstorage_get_db_connection();
+ sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name);
EMSTORAGE_START_READ_TRANSACTION(transaction);
if (account_id != ALL_ACCOUNT)
@@ -7082,7 +7270,7 @@ FINISH_OFF:
return ret;
}
-INTERNAL_FUNC int emstorage_get_rule(int account_id, int type, int start_idx, int *select_num, int *is_completed, emstorage_rule_tbl_t** rule_list, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_get_rule(char *multi_user_name, int account_id, int type, int start_idx, int *select_num, int *is_completed, emstorage_rule_tbl_t** rule_list, int transaction, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("account_id[%d], type[%d], start_idx[%d], select_num[%p], is_completed[%p], rule_list[%p], transaction[%d], err_code[%p]", account_id, type, start_idx, select_num, is_completed, rule_list, transaction, err_code);
@@ -7104,7 +7292,7 @@ INTERNAL_FUNC int emstorage_get_rule(int account_id, int type, int start_idx, in
int rc;
- sqlite3 *local_db_handle = emstorage_get_db_connection();
+ sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name);
EMSTORAGE_START_READ_TRANSACTION(transaction);
if (account_id != ALL_ACCOUNT) {
@@ -7201,25 +7389,30 @@ FINISH_OFF:
return ret;
}
-INTERNAL_FUNC int emstorage_get_rule_by_id(int rule_id, emstorage_rule_tbl_t** rule, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_get_rule_by_id(char *multi_user_name, int rule_id, emstorage_rule_tbl_t** rule, int transaction, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("rule_id[%d], rule[%p], transaction[%d], err_code[%p]", rule_id, rule, transaction, err_code);
+ int error = EMAIL_ERROR_NONE;
+ int ret = false;
+ DB_STMT hStmt = NULL;
+
+ if (rule_id <= 0) {
+ EM_DEBUG_EXCEPTION("Invalid parameter");
+ error = EMAIL_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
if (!rule) {
EM_DEBUG_EXCEPTION("rule_id[%d], rule[%p]", rule_id, rule);
-
- if (err_code != NULL)
- *err_code = EMAIL_ERROR_INVALID_PARAM;
- return false;
+ error = EMAIL_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
}
emstorage_rule_tbl_t* p_data_tbl = NULL;
- int rc, ret = false;
- int error = EMAIL_ERROR_NONE;
+ int rc;
- DB_STMT hStmt = NULL;
char sql_query_string[QUERY_SIZE] = {0, };
- sqlite3 *local_db_handle = emstorage_get_db_connection();
+ sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name);
EMSTORAGE_START_READ_TRANSACTION(transaction);
SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT * FROM mail_rule_tbl WHERE rule_id = %d", rule_id);
@@ -7260,6 +7453,7 @@ INTERNAL_FUNC int emstorage_get_rule_by_id(int rule_id, emstorage_rule_tbl_t** r
ret = true;
FINISH_OFF:
+
if (ret == true)
*rule = p_data_tbl;
@@ -7280,7 +7474,7 @@ FINISH_OFF:
return ret;
}
-INTERNAL_FUNC int emstorage_change_rule(int rule_id, emstorage_rule_tbl_t* new_rule, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_change_rule(char *multi_user_name, int rule_id, emstorage_rule_tbl_t* new_rule, int transaction, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("rule_id[%d], new_rule[%p], transaction[%d], err_code[%p]", rule_id, new_rule, transaction, err_code);
@@ -7297,8 +7491,8 @@ INTERNAL_FUNC int emstorage_change_rule(int rule_id, emstorage_rule_tbl_t* new_r
DB_STMT hStmt = NULL;
char sql_query_string[QUERY_SIZE] = {0, };
- sqlite3 *local_db_handle = emstorage_get_db_connection();
- EMSTORAGE_START_WRITE_TRANSACTION(transaction, error);
+ sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name);
+ EMSTORAGE_START_WRITE_TRANSACTION(multi_user_name, transaction, error);
SNPRINTF(sql_query_string, sizeof(sql_query_string),
"UPDATE mail_rule_tbl SET"
@@ -7342,7 +7536,7 @@ INTERNAL_FUNC int emstorage_change_rule(int rule_id, emstorage_rule_tbl_t* new_r
ret = true;
FINISH_OFF:
- EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
+ EMSTORAGE_FINISH_WRITE_TRANSACTION(multi_user_name, transaction, ret, error);
if (hStmt != NULL) {
rc = sqlite3_finalize(hStmt);
if (rc != SQLITE_OK) {
@@ -7358,7 +7552,7 @@ FINISH_OFF:
return ret;
}
-INTERNAL_FUNC int emstorage_find_rule(emstorage_rule_tbl_t* rule, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_find_rule(char *multi_user_name, emstorage_rule_tbl_t* rule, int transaction, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("rule[%p], transaction[%d], err_code[%p]", rule, transaction, err_code);
@@ -7375,7 +7569,7 @@ INTERNAL_FUNC int emstorage_find_rule(emstorage_rule_tbl_t* rule, int transactio
int rc = 0;
int ret = false;
- sqlite3 *local_db_handle = emstorage_get_db_connection();
+ sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name);
EMSTORAGE_START_READ_TRANSACTION(transaction);
switch(rule->action_type) {
@@ -7445,7 +7639,7 @@ FINISH_OFF:
return ret;
}
-INTERNAL_FUNC int emstorage_add_rule(emstorage_rule_tbl_t* rule, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_add_rule(char *multi_user_name, emstorage_rule_tbl_t* rule, int transaction, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("rule[%p], transaction[%d], err_code[%p]", rule, transaction, err_code);
@@ -7461,10 +7655,9 @@ INTERNAL_FUNC int emstorage_add_rule(emstorage_rule_tbl_t* rule, int transaction
DB_STMT hStmt = NULL;
char sql_query_string[QUERY_SIZE] = {0, };
+ sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name);
- sqlite3 *local_db_handle = emstorage_get_db_connection();
-
- EMSTORAGE_START_WRITE_TRANSACTION(transaction, error);
+ EMSTORAGE_START_WRITE_TRANSACTION(multi_user_name, transaction, error);
char *sql;
char **result;
@@ -7521,7 +7714,7 @@ INTERNAL_FUNC int emstorage_add_rule(emstorage_rule_tbl_t* rule, int transaction
ret = true;
FINISH_OFF:
- EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
+ EMSTORAGE_FINISH_WRITE_TRANSACTION(multi_user_name, transaction, ret, error);
if (hStmt != NULL) {
rc = sqlite3_finalize(hStmt);
if (rc != SQLITE_OK) {
@@ -7537,7 +7730,7 @@ FINISH_OFF:
return ret;
}
-INTERNAL_FUNC int emstorage_delete_rule(int rule_id, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_delete_rule(char *multi_user_name, int rule_id, int transaction, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("rule_id[%d], transaction[%d], err_code[%p]", rule_id, transaction, err_code);
@@ -7552,8 +7745,8 @@ INTERNAL_FUNC int emstorage_delete_rule(int rule_id, int transaction, int *err_c
int rc, ret = false;
int error = EMAIL_ERROR_NONE;
char sql_query_string[QUERY_SIZE] = {0, };
- sqlite3 *local_db_handle = emstorage_get_db_connection();
- EMSTORAGE_START_WRITE_TRANSACTION(transaction, error);
+ sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name);
+ EMSTORAGE_START_WRITE_TRANSACTION(multi_user_name, transaction, error);
SNPRINTF(sql_query_string, sizeof(sql_query_string), "DELETE FROM mail_rule_tbl WHERE rule_id = %d", rule_id);
error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string);
@@ -7573,7 +7766,7 @@ INTERNAL_FUNC int emstorage_delete_rule(int rule_id, int transaction, int *err_c
ret = true;
FINISH_OFF:
- EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
+ EMSTORAGE_FINISH_WRITE_TRANSACTION(multi_user_name, transaction, ret, error);
if (err_code != NULL)
*err_code = error;
@@ -7615,7 +7808,7 @@ FINISH_OFF:
return ret;
}
-INTERNAL_FUNC int emstorage_get_mail_count(int account_id, int mailbox_id, int *total, int *unseen, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_get_mail_count(char *multi_user_name, int account_id, int mailbox_id, int *total, int *unseen, int transaction, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("account_id[%d], mailbox_id[%d], total[%p], unseen[%p], transaction[%d], err_code[%p]", account_id, mailbox_id, total, unseen, transaction, err_code);
@@ -7633,7 +7826,7 @@ INTERNAL_FUNC int emstorage_get_mail_count(int account_id, int mailbox_id, int *
char *replaced_mailbox_name = NULL;
memset(&sql_query_string, 0x00, sizeof(sql_query_string));
- sqlite3 *local_db_handle = emstorage_get_db_connection();
+ sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name);
EMSTORAGE_START_READ_TRANSACTION(transaction);
if (total) {
@@ -7716,7 +7909,7 @@ FINISH_OFF2:
return ret;
}
-INTERNAL_FUNC int emstorage_get_mail_field_by_id(int mail_id, int type, emstorage_mail_tbl_t** mail, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_get_mail_field_by_id(char *multi_user_name, int mail_id, int type, emstorage_mail_tbl_t** mail, int transaction, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("mail_id[%d], type[%d], mail[%p], transaction[%d], err_code[%p]", mail_id, type, mail, transaction, err_code);
@@ -7744,28 +7937,52 @@ INTERNAL_FUNC int emstorage_get_mail_field_by_id(int mail_id, int type, emstorag
int rc, ret = false;
int error = EMAIL_ERROR_NONE;
- sqlite3 *local_db_handle = emstorage_get_db_connection();
+ sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name);
EMSTORAGE_START_READ_TRANSACTION(transaction);
switch (type) {
case RETRIEVE_SUMMARY:
SNPRINTF(sql_query_string, sizeof(sql_query_string),
- "SELECT account_id, mail_id, mailbox_id, server_mail_status, server_mailbox_name, server_mail_id, file_path_plain, file_path_html, flags_seen_field, save_status, lock_status, thread_id, thread_item_count FROM mail_tbl WHERE mail_id = %d", mail_id);
+ "SELECT account_id, "
+ "mail_id, "
+ "mailbox_id, "
+ "server_mail_status, "
+ "server_mailbox_name, "
+ "server_mail_id, "
+ "file_path_plain, "
+ "file_path_html,"
+ "file_path_mime_entity, "
+ "flags_seen_field, "
+ "save_status, "
+ "lock_status, "
+ "thread_id, "
+ "thread_item_count "
+ "FROM mail_tbl WHERE mail_id = %d", mail_id);
break;
case RETRIEVE_FIELDS_FOR_DELETE:
SNPRINTF(sql_query_string, sizeof(sql_query_string),
- "SELECT account_id, mail_id, server_mail_status, server_mailbox_name, server_mail_id FROM mail_tbl WHERE mail_id = %d", mail_id);
+ "SELECT account_id, "
+ "mail_id, "
+ "server_mail_status, "
+ "server_mailbox_name, "
+ "server_mail_id "
+ "FROM mail_tbl WHERE mail_id = %d", mail_id);
break;
case RETRIEVE_ACCOUNT:
SNPRINTF(sql_query_string, sizeof(sql_query_string),
- "SELECT account_id FROM mail_tbl WHERE mail_id = %d", mail_id);
+ "SELECT account_id "
+ "FROM mail_tbl WHERE mail_id = %d", mail_id);
break;
case RETRIEVE_FLAG:
SNPRINTF(sql_query_string, sizeof(sql_query_string),
- "SELECT account_id, flags_seen_field, thread_id, mailbox_id FROM mail_tbl WHERE mail_id = %d", mail_id);
+ "SELECT account_id, "
+ "flags_seen_field, "
+ "thread_id, "
+ "mailbox_id "
+ "FROM mail_tbl WHERE mail_id = %d", mail_id);
break;
default :
@@ -7800,6 +8017,7 @@ INTERNAL_FUNC int emstorage_get_mail_field_by_id(int mail_id, int type, emstorag
_get_stmt_field_data_string(hStmt, &(p_data_tbl->server_mail_id), 0, col_index++);
_get_stmt_field_data_string(hStmt, &(p_data_tbl->file_path_plain), 0, col_index++);
_get_stmt_field_data_string(hStmt, &(p_data_tbl->file_path_html), 0, col_index++);
+ _get_stmt_field_data_string(hStmt, &(p_data_tbl->file_path_mime_entity), 0, col_index++);
_get_stmt_field_data_char(hStmt, &(p_data_tbl->flags_seen_field), col_index++);
_get_stmt_field_data_int(hStmt, (int*)&(p_data_tbl->save_status), col_index++);
_get_stmt_field_data_int(hStmt, &(p_data_tbl->lock_status), col_index++);
@@ -7853,7 +8071,7 @@ FINISH_OFF:
return ret;
}
-INTERNAL_FUNC int emstorage_get_mail_field_by_multiple_mail_id(int mail_ids[], int number_of_mails, int type, emstorage_mail_tbl_t** mail, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_get_mail_field_by_multiple_mail_id(char *multi_user_name, int mail_ids[], int number_of_mails, int type, emstorage_mail_tbl_t** mail, int transaction, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("mail_ids[%p], number_of_mails [%d], type[%d], mail[%p], transaction[%d], err_code[%p]", mail_ids, number_of_mails, type, mail, transaction, err_code);
@@ -7889,20 +8107,40 @@ INTERNAL_FUNC int emstorage_get_mail_field_by_multiple_mail_id(int mail_ids[], i
return false;
}
- local_db_handle = emstorage_get_db_connection();
+ local_db_handle = emstorage_get_db_connection(multi_user_name);
EMSTORAGE_START_READ_TRANSACTION(transaction);
switch (type) {
case RETRIEVE_SUMMARY:
cur_sql_query_string = SNPRINTF(sql_query_string, query_string_length,
- "SELECT account_id, mail_id, mailbox_id, server_mail_status, server_mailbox_name, server_mail_id, file_path_plain, file_path_html, subject, flags_seen_field, save_status, lock_status, thread_id, thread_item_count FROM mail_tbl WHERE mail_id in (");
- field_count = 14;
+ "SELECT account_id, "
+ "mail_id, "
+ "mailbox_id, "
+ "server_mail_status, "
+ "server_mailbox_name, "
+ "server_mail_id, "
+ "file_path_plain, "
+ "file_path_html, "
+ "file_path_mime_entity, "
+ "subject, "
+ "flags_seen_field, "
+ "save_status, "
+ "lock_status, "
+ "thread_id, "
+ "thread_item_count "
+ "FROM mail_tbl WHERE mail_id in (");
+ field_count = 15;
break;
case RETRIEVE_FIELDS_FOR_DELETE:
cur_sql_query_string = SNPRINTF(sql_query_string, query_string_length,
- "SELECT account_id, mail_id, server_mail_status, server_mailbox_name, server_mail_id FROM mail_tbl WHERE mail_id in (");
+ "SELECT account_id, "
+ "mail_id, "
+ "server_mail_status, "
+ "server_mailbox_name, "
+ "server_mail_id "
+ "FROM mail_tbl WHERE mail_id in (");
field_count = 5;
break;
@@ -7914,7 +8152,12 @@ INTERNAL_FUNC int emstorage_get_mail_field_by_multiple_mail_id(int mail_ids[], i
case RETRIEVE_FLAG:
cur_sql_query_string = SNPRINTF(sql_query_string, query_string_length,
- "SELECT account_id, mail_id, mailbox_id, flags_seen_field, thread_id FROM mail_tbl WHERE mail_id in (");
+ "SELECT account_id, "
+ "mail_id, "
+ "mailbox_id, "
+ "flags_seen_field, "
+ "thread_id "
+ "FROM mail_tbl WHERE mail_id in (");
field_count = 5;
break;
@@ -7925,7 +8168,7 @@ INTERNAL_FUNC int emstorage_get_mail_field_by_multiple_mail_id(int mail_ids[], i
}
for(i = 0; i < number_of_mails; i++)
- cur_sql_query_string += SNPRINTF_OFFSET(sql_query_string, cur_sql_query_string, QUERY_SIZE, "%d,", mail_ids[i]);
+ cur_sql_query_string += SNPRINTF_OFFSET(sql_query_string, cur_sql_query_string, query_string_length, "%d,", mail_ids[i]);
sql_query_string[EM_SAFE_STRLEN(sql_query_string) - 1] = ')';
EM_DEBUG_LOG_SEC("Query [%s], Length [%d]", sql_query_string, EM_SAFE_STRLEN(sql_query_string));
@@ -7964,6 +8207,7 @@ INTERNAL_FUNC int emstorage_get_mail_field_by_multiple_mail_id(int mail_ids[], i
_get_table_field_data_string(result, &(p_data_tbl[i].server_mail_id), 0, col_index++);
_get_table_field_data_string(result, &(p_data_tbl[i].file_path_plain), 0, col_index++);
_get_table_field_data_string(result, &(p_data_tbl[i].file_path_html), 0, col_index++);
+ _get_table_field_data_string(result, &(p_data_tbl[i].file_path_mime_entity), 0, col_index++);
_get_table_field_data_string(result, &(p_data_tbl[i].subject), 0, col_index++);
_get_table_field_data_char(result, &(p_data_tbl[i].flags_seen_field), col_index++);
_get_table_field_data_int(result, (int*)&(p_data_tbl[i].save_status), col_index++);
@@ -8016,7 +8260,7 @@ FINISH_OFF:
return ret;
}
-INTERNAL_FUNC int emstorage_get_mail_by_id(int mail_id, emstorage_mail_tbl_t** mail, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_get_mail_by_id(char *multi_user_name, int mail_id, emstorage_mail_tbl_t **mail, int transaction, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("mail_id[%d], mail[%p], transaction[%d], err_code[%p]", mail_id, mail, transaction, err_code);
@@ -8034,7 +8278,7 @@ INTERNAL_FUNC int emstorage_get_mail_by_id(int mail_id, emstorage_mail_tbl_t** m
SNPRINTF(conditional_clause, QUERY_SIZE, "WHERE mail_id = %d", mail_id);
EM_DEBUG_LOG_SEC("query = [%s]", conditional_clause);
- if(!emstorage_query_mail_tbl(conditional_clause, transaction, &p_data_tbl, &count, &error)) {
+ if(!emstorage_query_mail_tbl(multi_user_name, conditional_clause, transaction, &p_data_tbl, &count, &error)) {
EM_DEBUG_EXCEPTION("emstorage_query_mail_tbl [%d]", error);
goto FINISH_OFF;
}
@@ -8055,7 +8299,7 @@ FINISH_OFF:
}
#ifdef __FEATURE_BODY_SEARCH__
-INTERNAL_FUNC int emstorage_get_mail_text_by_id(int mail_id, emstorage_mail_text_tbl_t **mail_text, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_get_mail_text_by_id(char *multi_user_name, int mail_id, emstorage_mail_text_tbl_t **mail_text, int transaction, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("mail_id[%d], mail_text[%p], transaction[%d], err_code[%p]", mail_id, mail_text, transaction, err_code);
@@ -8075,7 +8319,7 @@ INTERNAL_FUNC int emstorage_get_mail_text_by_id(int mail_id, emstorage_mail_text
SNPRINTF(conditional_clause, QUERY_SIZE, "WHERE mail_id = %d", mail_id);
EM_DEBUG_LOG_SEC("query = [%s]", conditional_clause);
- if(!emstorage_query_mail_text_tbl(conditional_clause, transaction, &p_data_tbl, &count, &error)) {
+ if(!emstorage_query_mail_text_tbl(multi_user_name, conditional_clause, transaction, &p_data_tbl, &count, &error)) {
EM_DEBUG_EXCEPTION("emstorage_query_mail_tbl [%d]", error);
goto FINISH_OFF;
}
@@ -8096,9 +8340,20 @@ FINISH_OFF:
}
#endif
-INTERNAL_FUNC int emstorage_mail_search_start(emstorage_search_filter_t* search, int account_id, int mailbox_id, int sorting, int *search_handle, int *searched, int transaction, int *err_code)
-{
- EM_DEBUG_FUNC_BEGIN("search[%p], account_id[%d], mailbox_id[%d], sorting[%d], search_handle[%p], searched[%p], transaction[%d], err_code[%p]", search, account_id, mailbox_id, sorting, search_handle, searched, transaction, err_code);
+INTERNAL_FUNC int emstorage_mail_search_start(char *multi_user_name,
+ emstorage_search_filter_t *search,
+ int account_id,
+ int mailbox_id,
+ int sorting,
+ DB_STMT *search_handle,
+ int *searched,
+ int transaction,
+ int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("search[%p], account_id[%d], mailbox_id[%d], sorting[%d], "
+ "search_handle[%p], searched[%p], transaction[%d], err_code[%p]",
+ search, account_id, mailbox_id, sorting, search_handle,
+ searched, transaction, err_code);
if (!search_handle || !searched) {
if (err_code != NULL)
@@ -8115,7 +8370,7 @@ INTERNAL_FUNC int emstorage_mail_search_start(emstorage_search_filter_t* search,
int rc, ret = false;
int and = false, mail_count = 0;
- sqlite3 *local_db_handle = emstorage_get_db_connection();
+ sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name);
EMSTORAGE_START_READ_TRANSACTION(transaction);
SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT * FROM mail_tbl");
@@ -8180,7 +8435,7 @@ INTERNAL_FUNC int emstorage_mail_search_start(emstorage_search_filter_t* search,
FINISH_OFF:
if (ret == true) {
- *search_handle = (int)hStmt;
+ *search_handle = hStmt;
*searched = mail_count;
EM_DEBUG_LOG("mail_count [%d]", mail_count);
}
@@ -8203,7 +8458,7 @@ FINISH_OFF:
return ret;
}
-INTERNAL_FUNC int emstorage_mail_search_result(int search_handle, emstorage_mail_field_type_t type, void** data, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_mail_search_result(DB_STMT search_handle, emstorage_mail_field_type_t type, void** data, int transaction, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("search_handle[%d], type[%d], data[%p], transaction[%d], err_code[%p]", search_handle, type, data, transaction, err_code);
@@ -8216,7 +8471,7 @@ INTERNAL_FUNC int emstorage_mail_search_result(int search_handle, emstorage_mail
}
emstorage_mail_tbl_t* p_data_tbl = NULL;
- DB_STMT hStmt = (DB_STMT)search_handle;
+ DB_STMT hStmt = search_handle;
int rc, ret = false;
int error = EMAIL_ERROR_NONE;
@@ -8352,7 +8607,7 @@ FINISH_OFF:
return ret;
}
-INTERNAL_FUNC int emstorage_mail_search_end(int search_handle, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_mail_search_end(DB_STMT search_handle, int transaction, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("search_handle[%d], transaction[%d], err_code[%p]", search_handle, transaction, err_code);
@@ -8365,8 +8620,7 @@ INTERNAL_FUNC int emstorage_mail_search_end(int search_handle, int transaction,
goto FINISH_OFF;
}
- DB_STMT hStmt = (DB_STMT)search_handle;
-
+ DB_STMT hStmt = search_handle;
rc = sqlite3_finalize(hStmt);
if (rc != SQLITE_OK) {
@@ -8386,7 +8640,7 @@ FINISH_OFF:
return ret;
}
-INTERNAL_FUNC int emstorage_change_mail(int mail_id, emstorage_mail_tbl_t* mail, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_change_mail(char *multi_user_name, int mail_id, emstorage_mail_tbl_t *mail, int transaction, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("mail_id[%d], mail[%p], transaction[%d], err_code[%p]", mail_id, mail, transaction, err_code);
@@ -8404,10 +8658,10 @@ INTERNAL_FUNC int emstorage_change_mail(int mail_id, emstorage_mail_tbl_t* mail,
int ret = false;
int error = EMAIL_ERROR_NONE;
int i = 0;
- sqlite3 *local_db_handle = emstorage_get_db_connection();
+ sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name);
char mailbox_id_param_string[10] = {0,};
- EMSTORAGE_START_WRITE_TRANSACTION(transaction, error);
+ EMSTORAGE_START_WRITE_TRANSACTION(multi_user_name, transaction, error);
SNPRINTF(sql_query_string, sizeof(sql_query_string),
"UPDATE mail_tbl SET"
@@ -8429,6 +8683,7 @@ INTERNAL_FUNC int emstorage_change_mail(int mail_id, emstorage_mail_tbl_t* mail,
", body_download_status = ?"
", file_path_plain = ?"
", file_path_html = ?"
+ ", file_path_mime_entity = ?"
", date_time = ?"
", flags_seen_field = ?"
", flags_deleted_field = ?"
@@ -8479,6 +8734,7 @@ INTERNAL_FUNC int emstorage_change_mail(int mail_id, emstorage_mail_tbl_t* mail,
_bind_stmt_field_data_int (hStmt, i++, mail->body_download_status);
_bind_stmt_field_data_string(hStmt, i++, (char *)mail->file_path_plain, 0, TEXT_1_LEN_IN_MAIL_TBL);
_bind_stmt_field_data_string(hStmt, i++, (char *)mail->file_path_html, 0, TEXT_2_LEN_IN_MAIL_TBL);
+ _bind_stmt_field_data_string(hStmt, i++, (char *)mail->file_path_mime_entity, 0, MIME_ENTITY_LEN_IN_MAIL_TBL);
_bind_stmt_field_data_int (hStmt, i++, mail->date_time);
_bind_stmt_field_data_char (hStmt, i++, mail->flags_seen_field);
_bind_stmt_field_data_char (hStmt, i++, mail->flags_deleted_field);
@@ -8518,7 +8774,7 @@ INTERNAL_FUNC int emstorage_change_mail(int mail_id, emstorage_mail_tbl_t* mail,
ret = true;
FINISH_OFF:
- EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
+ EMSTORAGE_FINISH_WRITE_TRANSACTION(multi_user_name, transaction, ret, error);
if (hStmt != NULL) {
rc = sqlite3_finalize(hStmt);
if (rc != SQLITE_OK) {
@@ -8546,7 +8802,7 @@ FINISH_OFF:
*
*
**/
-INTERNAL_FUNC int emstorage_clean_save_status(int save_status, int *err_code)
+INTERNAL_FUNC int emstorage_clean_save_status(char *multi_user_name, int save_status, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("save_status[%d], err_code[%p]", save_status, err_code);
@@ -8556,7 +8812,7 @@ INTERNAL_FUNC int emstorage_clean_save_status(int save_status, int *err_code)
int error = EMAIL_ERROR_NONE;
int rc = 0;
char sql_query_string[QUERY_SIZE] = {0, };
- sqlite3 *local_db_handle = emstorage_get_db_connection();
+ sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name);
memset(sql_query_string, 0x00, sizeof(sql_query_string));
SNPRINTF(sql_query_string, sizeof(sql_query_string), "UPDATE mail_tbl SET save_status = %d WHERE save_status = %d", save_status, EMAIL_MAIL_STATUS_SENDING);
@@ -8585,18 +8841,20 @@ FINISH_OFF:
return ret;
}
-INTERNAL_FUNC int emstorage_set_field_of_mails_with_integer_value(int account_id, int mail_ids[], int mail_ids_count, char *field_name, int value, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_set_field_of_mails_with_integer_value(char *multi_user_name, int account_id, int mail_ids[], int mail_ids_count, char *field_name, int value, int transaction, int *err_code)
{
EM_DEBUG_FUNC_BEGIN_SEC("account_id [%d], mail_ids[%p], mail_ids_count[%d], field_name[%s], value[%d], transaction[%d], err_code[%p]", account_id, mail_ids, mail_ids_count, field_name, value, transaction, err_code);
int i = 0;
int error = EMAIL_ERROR_NONE;
int ret = false;
+ int query_size = 0;
int cur_mail_id_string = 0;
int mail_id_string_buffer_length = 0;
- char sql_query_string[QUERY_SIZE] = {0, };
+ int parameter_string_length = 0;
+ char *sql_query_string = NULL;
char *mail_id_string_buffer = NULL;
char *parameter_string = NULL;
- sqlite3 *local_db_handle = emstorage_get_db_connection();
+ sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name);
email_mail_attribute_type target_mail_attribute_type = 0;
if (!mail_ids || !field_name || account_id == 0) {
@@ -8632,7 +8890,8 @@ INTERNAL_FUNC int emstorage_set_field_of_mails_with_integer_value(int account_id
mail_id_string_buffer[EM_SAFE_STRLEN(mail_id_string_buffer) - 1] = NULL_CHAR;
/* Generating notification parameter string */
- parameter_string = em_malloc(mail_id_string_buffer_length + EM_SAFE_STRLEN(field_name) + 2);
+ parameter_string_length = mail_id_string_buffer_length + EM_SAFE_STRLEN(field_name) + 2;
+ parameter_string = em_malloc(parameter_string_length);
if(!parameter_string) {
EM_DEBUG_EXCEPTION("em_malloc failed");
@@ -8642,15 +8901,22 @@ INTERNAL_FUNC int emstorage_set_field_of_mails_with_integer_value(int account_id
return false;
}
- SNPRINTF(parameter_string, QUERY_SIZE, "%s%c%s", field_name, 0x01, mail_id_string_buffer);
+ SNPRINTF(parameter_string, parameter_string_length, "%s%c%s", field_name, 0x01, mail_id_string_buffer);
+ query_size = EM_SAFE_STRLEN(mail_id_string_buffer) + EM_SAFE_STRLEN(field_name) + 250;
+ sql_query_string = em_malloc(query_size);
+ if (sql_query_string == NULL) {
+ EM_DEBUG_EXCEPTION("em_malloc failed");
+ error = EMAIL_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
/* Write query string */
- SNPRINTF(sql_query_string, QUERY_SIZE, "UPDATE mail_tbl SET %s = %d WHERE mail_id in (%s) AND account_id = %d", field_name, value, mail_id_string_buffer, account_id);
+ SNPRINTF(sql_query_string, query_size, "UPDATE mail_tbl SET %s = %d WHERE mail_id in (%s) AND account_id = %d", field_name, value, mail_id_string_buffer, account_id);
EM_DEBUG_LOG_DEV ("sql_query_string [%s]", sql_query_string);
/* Execute query */
- EMSTORAGE_START_WRITE_TRANSACTION(transaction, error);
+ EMSTORAGE_START_WRITE_TRANSACTION(multi_user_name, transaction, error);
error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string);
if (error != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error);
@@ -8663,7 +8929,7 @@ INTERNAL_FUNC int emstorage_set_field_of_mails_with_integer_value(int account_id
ret = true;
FINISH_OFF:
- EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
+ EMSTORAGE_FINISH_WRITE_TRANSACTION(multi_user_name, transaction, ret, error);
if (error == EMAIL_ERROR_NONE && parameter_string) {
if (!emcore_notify_storage_event (NOTI_MAIL_FIELD_UPDATE, account_id, target_mail_attribute_type, parameter_string, value))
@@ -8672,6 +8938,8 @@ FINISH_OFF:
EM_SAFE_FREE(mail_id_string_buffer);
EM_SAFE_FREE(parameter_string);
+ EM_SAFE_FREE(sql_query_string);
+
if (err_code != NULL)
*err_code = error;
@@ -8681,7 +8949,7 @@ FINISH_OFF:
}
#ifdef __FEATURE_BODY_SEARCH__
-INTERNAL_FUNC int emstorage_change_mail_text_field(int mail_id, emstorage_mail_text_tbl_t* mail_text, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_change_mail_text_field(char *multi_user_name, int mail_id, emstorage_mail_text_tbl_t* mail_text, int transaction, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("mail_id[%d], mail_text[%p], transaction[%d], err_code[%p]", mail_id, mail_text, transaction, err_code);
@@ -8700,8 +8968,8 @@ INTERNAL_FUNC int emstorage_change_mail_text_field(int mail_id, emstorage_mail_t
int i = 0;
int rc = 0;
- sqlite3 *local_db_handle = emstorage_get_db_connection();
- EMSTORAGE_START_WRITE_TRANSACTION(transaction, error);
+ sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name);
+ EMSTORAGE_START_WRITE_TRANSACTION(multi_user_name, transaction, error);
SNPRINTF(sql_query_string, sizeof(sql_query_string),
"UPDATE mail_text_tbl SET"
@@ -8733,7 +9001,7 @@ INTERNAL_FUNC int emstorage_change_mail_text_field(int mail_id, emstorage_mail_t
ret = true;
FINISH_OFF:
- EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
+ EMSTORAGE_FINISH_WRITE_TRANSACTION(multi_user_name, transaction, ret, error);
if (hStmt != NULL) {
rc = sqlite3_finalize(hStmt);
@@ -8752,7 +9020,7 @@ FINISH_OFF:
}
#endif
-INTERNAL_FUNC int emstorage_change_mail_field(int mail_id, email_mail_change_type_t type, emstorage_mail_tbl_t* mail, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_change_mail_field(char *multi_user_name, int mail_id, email_mail_change_type_t type, emstorage_mail_tbl_t *mail, int transaction, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("mail_id[%d], type[%d], mail[%p], transaction[%d], err_code[%p]", mail_id, type, mail, transaction, err_code);
@@ -8774,9 +9042,9 @@ INTERNAL_FUNC int emstorage_change_mail_field(int mail_id, email_mail_change_typ
return false;
}
- local_db_handle = emstorage_get_db_connection();
+ local_db_handle = emstorage_get_db_connection(multi_user_name);
- EMSTORAGE_START_WRITE_TRANSACTION(transaction, error);
+ EMSTORAGE_START_WRITE_TRANSACTION(multi_user_name, transaction, error);
switch (type) {
case APPEND_BODY:
@@ -8785,6 +9053,7 @@ INTERNAL_FUNC int emstorage_change_mail_field(int mail_id, email_mail_change_typ
" body_download_status = ?"
", file_path_plain = ?"
", file_path_html = ?"
+ ", file_path_mime_entity = ?"
", flags_seen_field = ?"
", flags_deleted_field = ?"
", flags_flagged_field = ?"
@@ -8811,6 +9080,7 @@ INTERNAL_FUNC int emstorage_change_mail_field(int mail_id, email_mail_change_typ
_bind_stmt_field_data_int(hStmt, i++, mail->body_download_status);
_bind_stmt_field_data_string(hStmt, i++, (char *)mail->file_path_plain, 0, TEXT_1_LEN_IN_MAIL_TBL);
_bind_stmt_field_data_string(hStmt, i++, (char *)mail->file_path_html, 0, TEXT_2_LEN_IN_MAIL_TBL);
+ _bind_stmt_field_data_string(hStmt, i++, (char *)mail->file_path_mime_entity, 0, MIME_ENTITY_LEN_IN_MAIL_TBL);
_bind_stmt_field_data_int(hStmt, i++, mail->flags_seen_field);
_bind_stmt_field_data_int(hStmt, i++, mail->flags_deleted_field);
_bind_stmt_field_data_int(hStmt, i++, mail->flags_flagged_field);
@@ -8831,7 +9101,7 @@ INTERNAL_FUNC int emstorage_change_mail_field(int mail_id, email_mail_change_typ
int err;
emstorage_mailbox_tbl_t *mailbox_tbl;
- if ((err = emstorage_get_mailbox_by_id(mail->mailbox_id, &mailbox_tbl)) != EMAIL_ERROR_NONE) {
+ if ((err = emstorage_get_mailbox_by_id(multi_user_name, mail->mailbox_id, &mailbox_tbl)) != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION(" emstorage_get_mailbox_by_id failed [%d]", err);
goto FINISH_OFF;
}
@@ -9020,13 +9290,11 @@ INTERNAL_FUNC int emstorage_change_mail_field(int mail_id, email_mail_change_typ
break;
case UPDATE_DATETIME: {
- time_t now = time(NULL);
-
SNPRINTF(sql_query_string, sizeof(sql_query_string),
"UPDATE mail_tbl SET"
- " date_time = '%d'"
+ " date_time = '%ld'"
" WHERE mail_id = %d AND account_id != 0"
- , (int)now
+ , mail->date_time
, mail_id);
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc);
@@ -9097,6 +9365,7 @@ INTERNAL_FUNC int emstorage_change_mail_field(int mail_id, email_mail_change_typ
" body_download_status = ?"
", file_path_plain = ?"
", file_path_html = ?"
+ ", file_path_mime_entity = ?"
", attachment_count = ?"
", inline_content_count = ?"
", preview_text = ?"
@@ -9114,6 +9383,7 @@ INTERNAL_FUNC int emstorage_change_mail_field(int mail_id, email_mail_change_typ
_bind_stmt_field_data_int(hStmt, i++, mail->body_download_status);
_bind_stmt_field_data_string(hStmt, i++, (char *)mail->file_path_plain, 0, TEXT_1_LEN_IN_MAIL_TBL);
_bind_stmt_field_data_string(hStmt, i++, (char *)mail->file_path_html, 0, TEXT_2_LEN_IN_MAIL_TBL);
+ _bind_stmt_field_data_string(hStmt, i++, (char *)mail->file_path_mime_entity, 0, MIME_ENTITY_LEN_IN_MAIL_TBL);
_bind_stmt_field_data_int(hStmt, i++, mail->attachment_count);
_bind_stmt_field_data_int(hStmt, i++, mail->inline_content_count);
_bind_stmt_field_data_nstring(hStmt, i++, (char *)mail->preview_text, 0, PREVIEWBODY_LEN_IN_MAIL_TBL);
@@ -9167,7 +9437,7 @@ INTERNAL_FUNC int emstorage_change_mail_field(int mail_id, email_mail_change_typ
if (mail->account_id == 0) {
emstorage_mail_tbl_t* mail_for_account_tbl = NULL;
- if (!emstorage_get_mail_field_by_id(mail_id, RETRIEVE_ACCOUNT, &mail_for_account_tbl, true, &error) || !mail_for_account_tbl) {
+ if (!emstorage_get_mail_field_by_id(multi_user_name, mail_id, RETRIEVE_ACCOUNT, &mail_for_account_tbl, true, &error) || !mail_for_account_tbl) {
EM_DEBUG_EXCEPTION ("emstorage_get_mail_field_by_id error [%d]", error);
goto FINISH_OFF;
}
@@ -9179,7 +9449,7 @@ INTERNAL_FUNC int emstorage_change_mail_field(int mail_id, email_mail_change_typ
ret = true;
FINISH_OFF:
- EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
+ EMSTORAGE_FINISH_WRITE_TRANSACTION(multi_user_name, transaction, ret, error);
if (hStmt != NULL) {
rc = sqlite3_finalize(hStmt);
@@ -9190,7 +9460,7 @@ FINISH_OFF:
hStmt = NULL;
}
if (error == EMAIL_ERROR_NONE && move_flag != 1 && transaction) {
- if (!emstorage_get_mailbox_id_by_mailbox_type( mail->account_id, EMAIL_MAILBOX_TYPE_SENTBOX, &mailbox_id, false, &error))
+ if (!emstorage_get_mailbox_id_by_mailbox_type(multi_user_name, mail->account_id, EMAIL_MAILBOX_TYPE_SENTBOX, &mailbox_id, false, &error))
EM_DEBUG_EXCEPTION("emstorage_get_mailbox_id_by_mailbox_type error [%d]", error);
if (mail->mailbox_id == mailbox_id) {
@@ -9211,7 +9481,8 @@ FINISH_OFF:
EM_DEBUG_FUNC_END("ret [%d]", ret);
return ret;
}
-INTERNAL_FUNC int emstorage_increase_mail_id(int *mail_id, int transaction, int *err_code)
+
+INTERNAL_FUNC int emstorage_increase_mail_id(char *multi_user_name, int *mail_id, int transaction, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("mail_id[%p], transaction[%d], err_code[%p]", mail_id, transaction, err_code);
@@ -9223,14 +9494,14 @@ INTERNAL_FUNC int emstorage_increase_mail_id(int *mail_id, int transaction, int
char **result = NULL;
#ifdef __FEATURE_USE_SHARED_MUTEX_FOR_GENERATING_MAIL_ID__
- _timedlock_shm_mutex(&mapped_for_generating_mail_id, 2);
+ _timedlock_shm_mutex(mapped_for_generating_mail_id, 2);
#endif /* __FEATURE_USE_SHARED_MUTEX_FOR_GENERATING_MAIL_ID__ */
ret = vconf_get_int(VCONF_KEY_LATEST_MAIL_ID, &latest_mail_id);
if (ret < 0 || latest_mail_id == 0) {
EM_DEBUG_LOG("vconf_get_int() failed [%d] or latest_mail_id is zero", ret);
- local_db_handle = emstorage_get_db_connection();
+ local_db_handle = emstorage_get_db_connection(multi_user_name);
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql, &result, NULL, NULL, NULL), rc);
EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
@@ -9252,7 +9523,7 @@ INTERNAL_FUNC int emstorage_increase_mail_id(int *mail_id, int transaction, int
*mail_id = latest_mail_id;
#ifdef __FEATURE_USE_SHARED_MUTEX_FOR_GENERATING_MAIL_ID__
- _unlockshm_mutex(&mapped_for_generating_mail_id);
+ _unlockshm_mutex(mapped_for_generating_mail_id);
#endif /* __FEATURE_USE_SHARED_MUTEX_FOR_GENERATING_MAIL_ID__ */
ret = true;
@@ -9266,8 +9537,7 @@ FINISH_OFF:
return ret;
}
-
-INTERNAL_FUNC int emstorage_add_mail(emstorage_mail_tbl_t *mail_tbl_data, int get_id, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_add_mail(char *multi_user_name, emstorage_mail_tbl_t *mail_tbl_data, int get_id, int transaction, int *err_code)
{
EM_PROFILE_BEGIN(profile_emstorage_add_mail);
EM_DEBUG_FUNC_BEGIN("mail_tbl_data[%p], get_id[%d], transaction[%d], err_code[%p]", mail_tbl_data, get_id, transaction, err_code);
@@ -9283,9 +9553,10 @@ INTERNAL_FUNC int emstorage_add_mail(emstorage_mail_tbl_t *mail_tbl_data, int ge
int error = EMAIL_ERROR_NONE;
char sql_query_string[QUERY_SIZE] = {0, };
DB_STMT hStmt = NULL;
- sqlite3 *local_db_handle = emstorage_get_db_connection();
- EMSTORAGE_START_WRITE_TRANSACTION(transaction, error);
+ sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name);
+
+ EMSTORAGE_START_WRITE_TRANSACTION(multi_user_name, transaction, error);
if (get_id) {
/* increase unique id */
@@ -9383,6 +9654,7 @@ INTERNAL_FUNC int emstorage_add_mail(emstorage_mail_tbl_t *mail_tbl_data, int ge
", ?" /* default charset */
", ?" /* eas_data_length */
", ?" /* eas_data */
+ ", ?" /* user_name */
")");
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle,
@@ -9392,8 +9664,8 @@ INTERNAL_FUNC int emstorage_add_mail(emstorage_mail_tbl_t *mail_tbl_data, int ge
NULL),
rc);
if (rc != SQLITE_OK) {
- EM_DEBUG_EXCEPTION ("sqlite3_prepare error [%d] [%s] SQL(%s) ",
- sql_query_string, rc, sqlite3_errmsg(local_db_handle));
+ EM_DEBUG_EXCEPTION ("sqlite3_prepare error [%d] [%s] SQL(%s) ",
+ rc, sql_query_string, sqlite3_errmsg(local_db_handle));
error = EMAIL_ERROR_DB_FAILURE;
goto FINISH_OFF;
}
@@ -9463,6 +9735,7 @@ INTERNAL_FUNC int emstorage_add_mail(emstorage_mail_tbl_t *mail_tbl_data, int ge
_bind_stmt_field_data_string(hStmt, DEFAULT_CHARSET_IDX_IN_MAIL_TBL, (char*)mail_tbl_data->default_charset, 0, TEXT_2_LEN_IN_MAIL_TBL);
_bind_stmt_field_data_int (hStmt, EAS_DATA_LENGTH_IDX_IN_MAIL_TBL, mail_tbl_data->eas_data_length);
_bind_stmt_field_data_blob (hStmt, EAS_DATA_IDX_IN_MAIL_TBL, (void*)mail_tbl_data->eas_data, mail_tbl_data->eas_data_length);
+ _bind_stmt_field_data_string(hStmt, USER_NAME_IDX_IN_MAIL_TBL, (char*)mail_tbl_data->user_name, 0, TEXT_2_LEN_IN_MAIL_TBL);
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
if (rc == SQLITE_FULL) {
@@ -9478,7 +9751,7 @@ INTERNAL_FUNC int emstorage_add_mail(emstorage_mail_tbl_t *mail_tbl_data, int ge
ret = true;
FINISH_OFF:
- EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
+ EMSTORAGE_FINISH_WRITE_TRANSACTION(multi_user_name, transaction, ret, error);
if (hStmt != NULL) {
rc = sqlite3_finalize(hStmt);
@@ -9496,14 +9769,15 @@ FINISH_OFF:
return ret;
}
-INTERNAL_FUNC int emstorage_move_multiple_mails_on_db(int input_source_account_id, int input_mailbox_id, int mail_ids[], int number_of_mails, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_move_multiple_mails_on_db(char *multi_user_name, int input_source_account_id, int input_mailbox_id, int mail_ids[], int number_of_mails, int transaction, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("input_source_account_id [%d], input_mailbox_id [%d], mail_ids[%p], number_of_mails [%d], transaction[%d], err_code[%p]", input_source_account_id, input_mailbox_id, mail_ids, number_of_mails, transaction, err_code);
int ret = false, i, cur_conditional_clause = 0;
int error = EMAIL_ERROR_NONE;
int target_account_id;
- char sql_query_string[QUERY_SIZE] = {0, }, conditional_clause[QUERY_SIZE] = {0, };
+ int conditional_clause_len = 0;
+ char *sql_query_string = NULL, *conditional_clause = NULL;
emstorage_mailbox_tbl_t *result_mailbox = NULL;
email_mailbox_type_e target_mailbox_type = EMAIL_MAILBOX_TYPE_USER_DEFINED;
char* target_mailbox_name = NULL;
@@ -9515,9 +9789,9 @@ INTERNAL_FUNC int emstorage_move_multiple_mails_on_db(int input_source_account_i
return false;
}
- sqlite3 *local_db_handle = emstorage_get_db_connection();
+ sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name);
- if ((error = emstorage_get_mailbox_by_id(input_mailbox_id, &result_mailbox)) != EMAIL_ERROR_NONE || !result_mailbox) {
+ if ((error = emstorage_get_mailbox_by_id(multi_user_name, input_mailbox_id, &result_mailbox)) != EMAIL_ERROR_NONE || !result_mailbox) {
EM_DEBUG_EXCEPTION("emstorage_get_mailbox_by_id failed. [%d]", error);
if (err_code != NULL)
*err_code = error;
@@ -9536,21 +9810,33 @@ INTERNAL_FUNC int emstorage_move_multiple_mails_on_db(int input_source_account_i
target_account_id = result_mailbox->account_id;
emstorage_free_mailbox(&result_mailbox, 1, NULL);
- cur_conditional_clause = SNPRINTF(conditional_clause, QUERY_SIZE, "WHERE mail_id in (");
+ conditional_clause_len = (sizeof(char) * 8 * number_of_mails) + 512;
+ conditional_clause = em_malloc(conditional_clause_len);
+ if (conditional_clause == NULL) {
+ EM_DEBUG_EXCEPTION("em_malloc failed");
+ error = EMAIL_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+ cur_conditional_clause = SNPRINTF(conditional_clause, conditional_clause_len, "WHERE mail_id in (");
for(i = 0; i < number_of_mails; i++)
- cur_conditional_clause += SNPRINTF_OFFSET(conditional_clause, cur_conditional_clause, QUERY_SIZE, "%d,", mail_ids[i]);
+ cur_conditional_clause += SNPRINTF_OFFSET(conditional_clause, cur_conditional_clause, conditional_clause_len, "%d,", mail_ids[i]);
/* prevent 34415 */
char *last_comma = rindex(conditional_clause, ',');
if(last_comma) *last_comma = ')'; /* replace , with ) */
- EMSTORAGE_START_WRITE_TRANSACTION(transaction, error);
+ EMSTORAGE_START_WRITE_TRANSACTION(multi_user_name, transaction, error);
/* Updating a mail_tbl */
- memset(sql_query_string, 0x00, QUERY_SIZE);
- SNPRINTF(sql_query_string, QUERY_SIZE, "UPDATE mail_tbl SET mailbox_type = %d, mailbox_id = %d, account_id = %d %s", target_mailbox_type, input_mailbox_id, target_account_id, conditional_clause);
+ sql_query_string = em_malloc(conditional_clause_len);
+ if (sql_query_string == NULL) {
+ EM_DEBUG_EXCEPTION("em_malloc failed");
+ error = EMAIL_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+ SNPRINTF(sql_query_string, conditional_clause_len, "UPDATE mail_tbl SET mailbox_type = %d, mailbox_id = %d, account_id = %d %s", target_mailbox_type, input_mailbox_id, target_account_id, conditional_clause);
EM_DEBUG_LOG_SEC("Query [%s]", sql_query_string);
error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string);
@@ -9560,8 +9846,8 @@ INTERNAL_FUNC int emstorage_move_multiple_mails_on_db(int input_source_account_i
}
/* Updating a mail_attachment_tbl */
- memset(sql_query_string, 0x00, QUERY_SIZE);
- SNPRINTF(sql_query_string, QUERY_SIZE, "UPDATE mail_attachment_tbl SET mailbox_id = '%d', account_id = %d %s", input_mailbox_id, target_account_id, conditional_clause);
+ memset(sql_query_string, 0x00, conditional_clause_len);
+ SNPRINTF(sql_query_string, conditional_clause_len, "UPDATE mail_attachment_tbl SET mailbox_id = '%d', account_id = %d %s", input_mailbox_id, target_account_id, conditional_clause);
EM_DEBUG_LOG_SEC("Query [%s]", sql_query_string);
error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string);
if (error != EMAIL_ERROR_NONE) {
@@ -9570,8 +9856,8 @@ INTERNAL_FUNC int emstorage_move_multiple_mails_on_db(int input_source_account_i
}
/* Updating a mail_meeting_tbl */
- memset(sql_query_string, 0x00, QUERY_SIZE);
- SNPRINTF(sql_query_string, QUERY_SIZE, "UPDATE mail_meeting_tbl SET mailbox_id = %d, account_id = %d %s", input_mailbox_id, target_account_id, conditional_clause);
+ memset(sql_query_string, 0x00, conditional_clause_len);
+ SNPRINTF(sql_query_string, conditional_clause_len, "UPDATE mail_meeting_tbl SET mailbox_id = %d, account_id = %d %s", input_mailbox_id, target_account_id, conditional_clause);
EM_DEBUG_LOG_SEC("Query [%s]", sql_query_string);
error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string);
if (error != EMAIL_ERROR_NONE) {
@@ -9581,8 +9867,8 @@ INTERNAL_FUNC int emstorage_move_multiple_mails_on_db(int input_source_account_i
#ifdef __FEATURE_BODY_SEARCH__
/* Updating mail_text_tbl */
- memset(sql_query_string, 0x00, QUERY_SIZE);
- SNPRINTF(sql_query_string, QUERY_SIZE, "UPDATE mail_text_tbl SET mailbox_id = %d, account_id = %d %s", input_mailbox_id, target_account_id, conditional_clause);
+ memset(sql_query_string, 0x00, conditional_clause_len);
+ SNPRINTF(sql_query_string, conditional_clause_len, "UPDATE mail_text_tbl SET mailbox_id = %d, account_id = %d %s", input_mailbox_id, target_account_id, conditional_clause);
EM_DEBUG_LOG_SEC("Query [%s]", sql_query_string);
error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string);
if (error != EMAIL_ERROR_NONE) {
@@ -9592,18 +9878,18 @@ INTERNAL_FUNC int emstorage_move_multiple_mails_on_db(int input_source_account_i
#endif
/* Updating a mail_read_mail_uid_tbl */
- memset(conditional_clause, 0x00, QUERY_SIZE);
- cur_conditional_clause = SNPRINTF(conditional_clause, QUERY_SIZE, "WHERE local_uid in (");
+ memset(conditional_clause, 0x00, conditional_clause_len);
+ cur_conditional_clause = SNPRINTF(conditional_clause, conditional_clause_len, "WHERE local_uid in (");
for(i = 0; i < number_of_mails; i++)
- cur_conditional_clause += SNPRINTF_OFFSET(conditional_clause, cur_conditional_clause, QUERY_SIZE, "%d,", mail_ids[i]);
+ cur_conditional_clause += SNPRINTF_OFFSET(conditional_clause, cur_conditional_clause, conditional_clause_len, "%d,", mail_ids[i]);
/* prevent 34415 */
last_comma = rindex(conditional_clause, ',');
if(last_comma) *last_comma = ')'; /* replace , with ) */
- memset(sql_query_string, 0x00, QUERY_SIZE);
- SNPRINTF(sql_query_string, QUERY_SIZE, "UPDATE mail_read_mail_uid_tbl SET mailbox_name = '%s', mailbox_id = %d, account_id = %d %s", target_mailbox_name, input_mailbox_id, target_account_id, conditional_clause);
+ memset(sql_query_string, 0x00, conditional_clause_len);
+ SNPRINTF(sql_query_string, conditional_clause_len, "UPDATE mail_read_mail_uid_tbl SET mailbox_name = '%s', mailbox_id = %d, account_id = %d %s", target_mailbox_name, input_mailbox_id, target_account_id, conditional_clause);
EM_DEBUG_LOG_SEC("Query [%s]", sql_query_string);
error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string);
if (error != EMAIL_ERROR_NONE) {
@@ -9614,9 +9900,11 @@ INTERNAL_FUNC int emstorage_move_multiple_mails_on_db(int input_source_account_i
ret = true;
FINISH_OFF:
- EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
+ EMSTORAGE_FINISH_WRITE_TRANSACTION(multi_user_name, transaction, ret, error);
EM_SAFE_FREE(target_mailbox_name);
+ EM_SAFE_FREE(conditional_clause);
+ EM_SAFE_FREE(sql_query_string);
if (err_code != NULL)
*err_code = error;
@@ -9625,7 +9913,7 @@ FINISH_OFF:
return ret;
}
-INTERNAL_FUNC int emstorage_delete_mail(int mail_id, int from_server, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_delete_mail(char *multi_user_name, int mail_id, int from_server, int transaction, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("mail_id[%d], transaction[%d], err_code[%p]", mail_id, transaction, err_code);
@@ -9639,8 +9927,8 @@ INTERNAL_FUNC int emstorage_delete_mail(int mail_id, int from_server, int transa
int ret = false;
int error = EMAIL_ERROR_NONE;
char sql_query_string[QUERY_SIZE] = {0, };
- sqlite3 *local_db_handle = emstorage_get_db_connection();
- EMSTORAGE_START_WRITE_TRANSACTION(transaction, error);
+ sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name);
+ EMSTORAGE_START_WRITE_TRANSACTION(multi_user_name, transaction, error);
memset(sql_query_string, 0x00, sizeof(sql_query_string));
@@ -9655,7 +9943,7 @@ INTERNAL_FUNC int emstorage_delete_mail(int mail_id, int from_server, int transa
ret = true;
FINISH_OFF:
- EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
+ EMSTORAGE_FINISH_WRITE_TRANSACTION(multi_user_name, transaction, ret, error);
if (err_code != NULL)
*err_code = error;
@@ -9664,13 +9952,14 @@ FINISH_OFF:
return ret;
}
-INTERNAL_FUNC int emstorage_delete_multiple_mails(int mail_ids[], int number_of_mails, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_delete_multiple_mails(char *multi_user_name, int mail_ids[], int number_of_mails, int transaction, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("mail_ids[%p], number_of_mails [%d], transaction[%d], err_code[%p]", mail_ids, number_of_mails, transaction, err_code);
int ret = false, i, cur_sql_query_string = 0;
int error = EMAIL_ERROR_NONE;
- char sql_query_string[QUERY_SIZE] = {0, };
+ int query_size = 0;
+ char *sql_query_string = NULL;
if (!mail_ids) {
EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
@@ -9679,17 +9968,25 @@ INTERNAL_FUNC int emstorage_delete_multiple_mails(int mail_ids[], int number_of_
return false;
}
- sqlite3 *local_db_handle = emstorage_get_db_connection();
- EMSTORAGE_START_WRITE_TRANSACTION(transaction, error);
+ sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name);
+ EMSTORAGE_START_WRITE_TRANSACTION(multi_user_name, transaction, error);
+
+ query_size = (sizeof(char) * 8 * number_of_mails) + 512;
+ sql_query_string = em_malloc(query_size);
+ if (sql_query_string == NULL) {
+ EM_DEBUG_EXCEPTION("em_malloc failed");
+ error = EMAIL_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
- cur_sql_query_string = SNPRINTF(sql_query_string, sizeof(sql_query_string), "DELETE FROM mail_tbl WHERE mail_id in (");
+ cur_sql_query_string = SNPRINTF(sql_query_string, query_size, "DELETE FROM mail_tbl WHERE mail_id in (");
for(i = 0; i < number_of_mails; i++)
- cur_sql_query_string += SNPRINTF_OFFSET(sql_query_string, cur_sql_query_string, QUERY_SIZE, "%d,", mail_ids[i]);
+ cur_sql_query_string += SNPRINTF_OFFSET(sql_query_string, cur_sql_query_string, query_size, "%d,", mail_ids[i]);
/* prevent 34414 */
char *last_comma = rindex(sql_query_string, ',');
- if (last_comma) *last_comma = ')'; /* replace , with ) */
+ if (last_comma != NULL) *last_comma = ')'; /* replace , with ) */
EM_DEBUG_LOG_SEC("Query [%s]", sql_query_string);
error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string);
@@ -9700,10 +9997,10 @@ INTERNAL_FUNC int emstorage_delete_multiple_mails(int mail_ids[], int number_of_
#ifdef __FEATURE_BODY_SEARCH__
/* delete mail_text from mail_text_tbl */
- cur_sql_query_string = SNPRINTF(sql_query_string, sizeof(sql_query_string), "DELETE FROM mail_text_tbl WHERE mail_id in (");
+ cur_sql_query_string = SNPRINTF(sql_query_string, query_size, "DELETE FROM mail_text_tbl WHERE mail_id in (");
for(i = 0; i < number_of_mails; i++)
- cur_sql_query_string += SNPRINTF_OFFSET(sql_query_string, cur_sql_query_string, QUERY_SIZE, "%d,", mail_ids[i]);
+ cur_sql_query_string += SNPRINTF_OFFSET(sql_query_string, cur_sql_query_string, query_size, "%d,", mail_ids[i]);
last_comma = rindex(sql_query_string, ',');
*last_comma = ')'; /* replace , with ) */
@@ -9719,8 +10016,9 @@ INTERNAL_FUNC int emstorage_delete_multiple_mails(int mail_ids[], int number_of_
ret = true;
FINISH_OFF:
- EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
+ EMSTORAGE_FINISH_WRITE_TRANSACTION(multi_user_name, transaction, ret, error);
+ EM_SAFE_FREE(sql_query_string);
if (err_code != NULL)
*err_code = error;
@@ -9728,7 +10026,7 @@ FINISH_OFF:
return ret;
}
-INTERNAL_FUNC int emstorage_delete_mail_by_account(int account_id, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_delete_mail_by_account(char *multi_user_name, int account_id, int transaction, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("account_id[%d], transaction[%d], err_code[%p]", account_id, transaction, err_code);
@@ -9744,8 +10042,8 @@ INTERNAL_FUNC int emstorage_delete_mail_by_account(int account_id, int transacti
int error = EMAIL_ERROR_NONE;
char sql_query_string[QUERY_SIZE] = {0, };
- sqlite3 *local_db_handle = emstorage_get_db_connection();
- EMSTORAGE_START_WRITE_TRANSACTION(transaction, error);
+ sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name);
+ EMSTORAGE_START_WRITE_TRANSACTION(multi_user_name, transaction, error);
SNPRINTF(sql_query_string, sizeof(sql_query_string), "DELETE FROM mail_tbl WHERE account_id = %d", account_id);
EM_DEBUG_LOG_SEC("Query [%s]", sql_query_string);
@@ -9796,7 +10094,7 @@ INTERNAL_FUNC int emstorage_delete_mail_by_account(int account_id, int transacti
ret = true;
FINISH_OFF:
- EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
+ EMSTORAGE_FINISH_WRITE_TRANSACTION(multi_user_name, transaction, ret, error);
if (error == EMAIL_ERROR_NONE) {
if (!emcore_notify_storage_event (NOTI_MAIL_DELETE_WITH_ACCOUNT, account_id, 0 , NULL, 0))
@@ -9810,7 +10108,7 @@ FINISH_OFF:
return ret;
}
-INTERNAL_FUNC int emstorage_delete_mail_by_mailbox(emstorage_mailbox_tbl_t *mailbox, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_delete_mail_by_mailbox(char *multi_user_name, emstorage_mailbox_tbl_t *mailbox, int transaction, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("mailbox[%p], transaction[%d], err_code[%p]", mailbox, transaction, err_code);
@@ -9824,8 +10122,8 @@ INTERNAL_FUNC int emstorage_delete_mail_by_mailbox(emstorage_mailbox_tbl_t *mail
int ret = false;
int error = EMAIL_ERROR_NONE;
char sql_query_string[QUERY_SIZE] = {0, };
- sqlite3 *local_db_handle = emstorage_get_db_connection();
- EMSTORAGE_START_WRITE_TRANSACTION(transaction, error);
+ sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name);
+ EMSTORAGE_START_WRITE_TRANSACTION(multi_user_name, transaction, error);
if (strcmp(mailbox->mailbox_name, EMAIL_SEARCH_RESULT_MAILBOX_NAME) == 0) {
SNPRINTF(sql_query_string, sizeof(sql_query_string), "DELETE FROM mail_tbl WHERE account_id = %d AND mailbox_type = %d", mailbox->account_id, mailbox->mailbox_type);
@@ -9876,7 +10174,7 @@ INTERNAL_FUNC int emstorage_delete_mail_by_mailbox(emstorage_mailbox_tbl_t *mail
ret = true;
FINISH_OFF:
- EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
+ EMSTORAGE_FINISH_WRITE_TRANSACTION(multi_user_name, transaction, ret, error);
if (error == EMAIL_ERROR_NONE) {
if (!emcore_notify_storage_event(NOTI_MAIL_DELETE_ALL, mailbox->account_id, mailbox->mailbox_id , mailbox->mailbox_name, 0))
@@ -9928,6 +10226,7 @@ INTERNAL_FUNC int emstorage_free_mail(emstorage_mail_tbl_t** mail_list, int coun
EM_SAFE_FREE(p->default_charset);
EM_SAFE_FREE(p->pgp_password);
EM_SAFE_FREE(p->eas_data);
+ EM_SAFE_FREE(p->user_name);
}
EM_SAFE_FREE(*mail_list);
}
@@ -9963,8 +10262,7 @@ INTERNAL_FUNC void emstorage_free_mail_text(emstorage_mail_text_tbl_t** mail_tex
}
#endif
-
-INTERNAL_FUNC int emstorage_get_attachment_count(int mail_id, int *count, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_get_attachment_count(char *multi_user_name, int mail_id, int *count, int transaction, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("mail_id[%d], count[%p], transaction[%d], err_code[%p]", mail_id, count, transaction, err_code);
@@ -9979,7 +10277,7 @@ INTERNAL_FUNC int emstorage_get_attachment_count(int mail_id, int *count, int tr
int error = EMAIL_ERROR_NONE;
char sql_query_string[QUERY_SIZE] = {0, };
- sqlite3 *local_db_handle = emstorage_get_db_connection();
+ sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name);
EMSTORAGE_START_READ_TRANSACTION(transaction);
SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT COUNT(*) FROM mail_attachment_tbl WHERE mail_id = %d", mail_id);
@@ -10005,7 +10303,7 @@ FINISH_OFF:
return ret;
}
-INTERNAL_FUNC int emstorage_get_attachment_list(int input_mail_id, int input_transaction, emstorage_attachment_tbl_t** output_attachment_list, int *output_attachment_count)
+INTERNAL_FUNC int emstorage_get_attachment_list(char *multi_user_name, int input_mail_id, int input_transaction, emstorage_attachment_tbl_t** output_attachment_list, int *output_attachment_count)
{
EM_DEBUG_FUNC_BEGIN("input_mail_id[%d], input_transaction[%d], output_attachment_list[%p], output_attachment_count[%p]", input_mail_id, input_transaction, output_attachment_list, output_attachment_count);
@@ -10021,7 +10319,7 @@ INTERNAL_FUNC int emstorage_get_attachment_list(int input_mail_id, int input_tra
char sql_query_string[QUERY_SIZE] = {0, };
emstorage_attachment_tbl_t* p_data_tbl = NULL;
DB_STMT hStmt = NULL;
- sqlite3 *local_db_handle = emstorage_get_db_connection();
+ sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name);
EMSTORAGE_START_READ_TRANSACTION(input_transaction);
SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT COUNT(*) FROM mail_attachment_tbl WHERE mail_id = %d", input_mail_id);
@@ -10102,7 +10400,7 @@ FINISH_OFF:
return error;
}
-INTERNAL_FUNC int emstorage_get_attachment(int attachment_id, emstorage_attachment_tbl_t** attachment, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_get_attachment(char *multi_user_name, int attachment_id, emstorage_attachment_tbl_t **attachment, int transaction, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("attachment_id[%d], attachment[%p], transaction[%d], err_code[%p]", attachment_id, attachment, transaction, err_code);
@@ -10118,7 +10416,7 @@ INTERNAL_FUNC int emstorage_get_attachment(int attachment_id, emstorage_attachme
int error = EMAIL_ERROR_NONE;
char sql_query_string[QUERY_SIZE] = {0, };
- sqlite3 *local_db_handle = emstorage_get_db_connection();
+ sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name);
EMSTORAGE_START_READ_TRANSACTION(transaction);
SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT * FROM mail_attachment_tbl WHERE attachment_id = %d", attachment_id);
@@ -10190,7 +10488,7 @@ FINISH_OFF:
return ret;
}
-INTERNAL_FUNC int emstorage_get_attachment_nth(int mail_id, int nth, emstorage_attachment_tbl_t** attachment_tbl, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_get_attachment_nth(char *multi_user_name, int mail_id, int nth, emstorage_attachment_tbl_t **attachment_tbl, int transaction, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("mail_id[%d], nth[%d], attachment_tbl[%p], transaction[%d], err_code[%p]", mail_id, nth, attachment_tbl, transaction, err_code);
@@ -10208,7 +10506,7 @@ INTERNAL_FUNC int emstorage_get_attachment_nth(int mail_id, int nth, emstorage_a
int error = EMAIL_ERROR_NONE;
char sql_query_string[QUERY_SIZE] = {0, };
- sqlite3 *local_db_handle = emstorage_get_db_connection();
+ sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name);
EMSTORAGE_START_READ_TRANSACTION(transaction);
SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT * FROM mail_attachment_tbl WHERE mail_id = %d ORDER BY attachment_id LIMIT %d, 1", mail_id, (nth - 1));
@@ -10282,7 +10580,7 @@ FINISH_OFF:
return ret;
}
-INTERNAL_FUNC int emstorage_get_attachment_by_attachment_path(char *attachment_path, emstorage_attachment_tbl_t** attachment, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_get_attachment_by_attachment_path(char *multi_user_name, char *attachment_path, emstorage_attachment_tbl_t **attachment, int transaction, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("attachment_path[%p], attachment[%p], transaction[%d], err_code[%p]", attachment_path, attachment, transaction, err_code);
@@ -10298,7 +10596,7 @@ INTERNAL_FUNC int emstorage_get_attachment_by_attachment_path(char *attachment_p
int error = EMAIL_ERROR_NONE;
char sql_query_string[QUERY_SIZE] = {0, };
- sqlite3 *local_db_handle = emstorage_get_db_connection();
+ sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name);
EMSTORAGE_START_READ_TRANSACTION(transaction);
SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT * FROM mail_attachment_tbl WHERE attachment_path = '%s'", attachment_path);
@@ -10370,7 +10668,7 @@ FINISH_OFF:
return ret;
}
-INTERNAL_FUNC int emstorage_change_attachment_field(int mail_id, email_mail_change_type_t type, emstorage_attachment_tbl_t* attachment, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_change_attachment_field(char *multi_user_name, int mail_id, email_mail_change_type_t type, emstorage_attachment_tbl_t *attachment, int transaction, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("mail_id[%d], type[%d], attachment[%p], transaction[%d], err_code[%p]", mail_id, type, attachment, transaction, err_code);
@@ -10388,9 +10686,9 @@ INTERNAL_FUNC int emstorage_change_attachment_field(int mail_id, email_mail_chan
int i = 0;
- sqlite3 *local_db_handle = emstorage_get_db_connection();
+ sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name);
- EMSTORAGE_START_WRITE_TRANSACTION(transaction, error);
+ EMSTORAGE_START_WRITE_TRANSACTION(multi_user_name, transaction, error);
switch (type) {
case UPDATE_MAILBOX:
@@ -10454,7 +10752,7 @@ INTERNAL_FUNC int emstorage_change_attachment_field(int mail_id, email_mail_chan
FINISH_OFF:
- EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
+ EMSTORAGE_FINISH_WRITE_TRANSACTION(multi_user_name, transaction, ret, error);
if (hStmt != NULL) {
rc = sqlite3_finalize(hStmt);
@@ -10470,8 +10768,7 @@ FINISH_OFF:
return ret;
}
-
-INTERNAL_FUNC int emstorage_rename_mailbox(int input_mailbox_id, char *input_new_mailbox_name, char *input_new_mailbox_alias, void *input_eas_data, int input_eas_data_length, int input_transaction)
+INTERNAL_FUNC int emstorage_rename_mailbox(char *multi_user_name, int input_mailbox_id, char *input_new_mailbox_name, char *input_new_mailbox_alias, void *input_eas_data, int input_eas_data_length, int input_transaction)
{
EM_DEBUG_FUNC_BEGIN("input_mailbox_id[%d] input_new_mailbox_name[%p] input_new_mailbox_alias[%p] input_eas_data[%p] input_eas_data_length[%d] input_transaction[%d]", input_mailbox_id, input_new_mailbox_name, input_new_mailbox_alias, input_eas_data, input_eas_data_length, input_transaction);
@@ -10504,9 +10801,9 @@ INTERNAL_FUNC int emstorage_rename_mailbox(int input_mailbox_id, char *input_new
replaced_alias = strdup(input_new_mailbox_alias);
}
- local_db_handle = emstorage_get_db_connection();
+ local_db_handle = emstorage_get_db_connection(multi_user_name);
- if ((error = emstorage_get_mailbox_by_id(input_mailbox_id, &old_mailbox_data)) != EMAIL_ERROR_NONE) {
+ if ((error = emstorage_get_mailbox_by_id(multi_user_name, input_mailbox_id, &old_mailbox_data)) != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("emstorage_get_mailbox_by_id failed [%d]", error);
EM_SAFE_FREE (replaced_mailbox_name);
EM_SAFE_FREE (replaced_alias);
@@ -10521,7 +10818,7 @@ INTERNAL_FUNC int emstorage_rename_mailbox(int input_mailbox_id, char *input_new
account_id = old_mailbox_data->account_id;
- EMSTORAGE_START_WRITE_TRANSACTION(input_transaction, error);
+ EMSTORAGE_START_WRITE_TRANSACTION(multi_user_name, input_transaction, error);
if(input_eas_data && input_eas_data_length > 0) {
SNPRINTF(sql_query_string, sizeof(sql_query_string),
@@ -10573,7 +10870,7 @@ INTERNAL_FUNC int emstorage_rename_mailbox(int input_mailbox_id, char *input_new
ret = true;
FINISH_OFF:
- EMSTORAGE_FINISH_WRITE_TRANSACTION(input_transaction, ret, error);
+ EMSTORAGE_FINISH_WRITE_TRANSACTION(multi_user_name, input_transaction, ret, error);
if (error == EMAIL_ERROR_NONE) {
if (!emcore_notify_storage_event (NOTI_MAILBOX_RENAME, account_id, input_mailbox_id, input_new_mailbox_name, 0))
EM_DEBUG_EXCEPTION ("emcore_notify_storage_event Failed [ NOTI_MAILBOX_RENAME ] >>>> ");
@@ -10601,7 +10898,7 @@ FINISH_OFF:
return error;
}
-INTERNAL_FUNC int emstorage_get_new_attachment_no(int *attachment_no, int *err_code)
+INTERNAL_FUNC int emstorage_get_new_attachment_no(char *multi_user_name, int *attachment_no, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("attachment_no [%p], err_code[%p]", attachment_no, err_code);
int rc, ret = false;
@@ -10618,7 +10915,7 @@ INTERNAL_FUNC int emstorage_get_new_attachment_no(int *attachment_no, int *err_c
*attachment_no = -1;
- sqlite3 *local_db_handle = emstorage_get_db_connection();
+ sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name);
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql, &result, NULL, NULL, NULL), rc);
@@ -10645,7 +10942,7 @@ FINISH_OFF:
return ret;
}
-INTERNAL_FUNC int emstorage_add_attachment(emstorage_attachment_tbl_t* attachment_tbl, int iscopy, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_add_attachment(char *multi_user_name, emstorage_attachment_tbl_t *attachment_tbl, int iscopy, int transaction, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("attachment_tbl[%p], iscopy[%d], transaction[%d], err_code[%p]", attachment_tbl, iscopy, transaction, err_code);
@@ -10656,7 +10953,7 @@ INTERNAL_FUNC int emstorage_add_attachment(emstorage_attachment_tbl_t* attachmen
char sql_query_string[QUERY_SIZE] = {0, };
DB_STMT hStmt = NULL;
- sqlite3 *local_db_handle = emstorage_get_db_connection();
+ sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name);
if (!attachment_tbl) {
EM_DEBUG_EXCEPTION("attachment_tbl[%p], iscopy[%d]", attachment_tbl, iscopy);
@@ -10665,7 +10962,7 @@ INTERNAL_FUNC int emstorage_add_attachment(emstorage_attachment_tbl_t* attachmen
return false;
}
- EMSTORAGE_START_WRITE_TRANSACTION(transaction, error);
+ EMSTORAGE_START_WRITE_TRANSACTION(multi_user_name, transaction, error);
sql = "SELECT max(rowid) FROM mail_attachment_tbl;";
@@ -10740,7 +11037,7 @@ INTERNAL_FUNC int emstorage_add_attachment(emstorage_attachment_tbl_t* attachmen
ret = true;
FINISH_OFF:
- EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
+ EMSTORAGE_FINISH_WRITE_TRANSACTION(multi_user_name, transaction, ret, error);
if (hStmt != NULL) {
rc = sqlite3_finalize(hStmt);
@@ -10757,7 +11054,7 @@ FINISH_OFF:
return ret;
}
-INTERNAL_FUNC int emstorage_update_attachment(emstorage_attachment_tbl_t* attachment_tbl, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_update_attachment(char *multi_user_name, emstorage_attachment_tbl_t *attachment_tbl, int transaction, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("attachment_tbl[%p], transaction[%d], err_code[%p]", attachment_tbl, transaction, err_code);
@@ -10773,9 +11070,9 @@ INTERNAL_FUNC int emstorage_update_attachment(emstorage_attachment_tbl_t* attach
return false;
}
- sqlite3 *local_db_handle = emstorage_get_db_connection();
+ sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name);
- EMSTORAGE_START_WRITE_TRANSACTION(transaction, error);
+ EMSTORAGE_START_WRITE_TRANSACTION(multi_user_name, transaction, error);
SNPRINTF(sql_query_string, sizeof(sql_query_string),
"UPDATE mail_attachment_tbl SET "
@@ -10830,7 +11127,7 @@ INTERNAL_FUNC int emstorage_update_attachment(emstorage_attachment_tbl_t* attach
ret = true;
FINISH_OFF:
- EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
+ EMSTORAGE_FINISH_WRITE_TRANSACTION(multi_user_name, transaction, ret, error);
if (hStmt != NULL) {
rc = sqlite3_finalize(hStmt);
if (rc != SQLITE_OK) {
@@ -10846,7 +11143,7 @@ FINISH_OFF:
return ret;
}
-INTERNAL_FUNC int emstorage_delete_attachment_on_db(int attachment_id, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_delete_attachment_on_db(char *multi_user_name, int attachment_id, int transaction, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("attachment_id[%d], transaction[%d], err_code[%p]", attachment_id, transaction, err_code);
@@ -10860,9 +11157,9 @@ INTERNAL_FUNC int emstorage_delete_attachment_on_db(int attachment_id, int trans
int ret = false;
int error = EMAIL_ERROR_NONE;
char sql_query_string[QUERY_SIZE] = {0, };
- sqlite3 *local_db_handle = emstorage_get_db_connection();
+ sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name);
- EMSTORAGE_START_WRITE_TRANSACTION(transaction, error);
+ EMSTORAGE_START_WRITE_TRANSACTION(multi_user_name, transaction, error);
SNPRINTF(sql_query_string, sizeof(sql_query_string), "DELETE FROM mail_attachment_tbl WHERE attachment_id = %d", attachment_id);
@@ -10875,7 +11172,7 @@ INTERNAL_FUNC int emstorage_delete_attachment_on_db(int attachment_id, int trans
ret = true;
FINISH_OFF:
- EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
+ EMSTORAGE_FINISH_WRITE_TRANSACTION(multi_user_name, transaction, ret, error);
if (err_code)
*err_code = error;
@@ -10884,7 +11181,7 @@ FINISH_OFF:
return ret;
}
-INTERNAL_FUNC int emstorage_delete_all_attachments_of_mail(int mail_id, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_delete_all_attachments_of_mail(char *multi_user_name, int mail_id, int transaction, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("mail_id[%d], transaction[%d], err_code[%p]", mail_id, transaction, err_code);
int ret = false;
@@ -10899,9 +11196,9 @@ INTERNAL_FUNC int emstorage_delete_all_attachments_of_mail(int mail_id, int tran
return false;
}
- local_db_handle = emstorage_get_db_connection();
+ local_db_handle = emstorage_get_db_connection(multi_user_name);
- EMSTORAGE_START_WRITE_TRANSACTION(transaction, error);
+ EMSTORAGE_START_WRITE_TRANSACTION(multi_user_name, transaction, error);
SNPRINTF(sql_query_string, sizeof(sql_query_string), "DELETE FROM mail_attachment_tbl WHERE mail_id = %d", mail_id);
error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string);
@@ -10913,7 +11210,7 @@ INTERNAL_FUNC int emstorage_delete_all_attachments_of_mail(int mail_id, int tran
ret = true;
FINISH_OFF:
- EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
+ EMSTORAGE_FINISH_WRITE_TRANSACTION(multi_user_name, transaction, ret, error);
if (err_code)
*err_code = error;
@@ -10922,7 +11219,7 @@ FINISH_OFF:
return ret;
}
-INTERNAL_FUNC int emstorage_delete_attachment_all_on_db(int account_id, char *mailbox, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_delete_attachment_all_on_db(char *multi_user_name, int account_id, char *mailbox, int transaction, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("account_id[%d], mailbox[%p], transaction[%d], err_code[%p]", account_id, mailbox, transaction, err_code);
@@ -10930,9 +11227,9 @@ INTERNAL_FUNC int emstorage_delete_attachment_all_on_db(int account_id, char *ma
int ret = false;
char sql_query_string[QUERY_SIZE] = {0, };
char *replaced_mailbox = NULL;
- sqlite3 *local_db_handle = emstorage_get_db_connection();
+ sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name);
- EMSTORAGE_START_WRITE_TRANSACTION(transaction, error);
+ EMSTORAGE_START_WRITE_TRANSACTION(multi_user_name, transaction, error);
SNPRINTF(sql_query_string, sizeof(sql_query_string), "DELETE FROM mail_attachment_tbl");
@@ -10959,7 +11256,7 @@ INTERNAL_FUNC int emstorage_delete_attachment_all_on_db(int account_id, char *ma
ret = true;
FINISH_OFF:
- EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
+ EMSTORAGE_FINISH_WRITE_TRANSACTION(multi_user_name, transaction, ret, error);
if (err_code != NULL)
*err_code = error;
@@ -11003,16 +11300,15 @@ INTERNAL_FUNC int emstorage_free_attachment(emstorage_attachment_tbl_t** attachm
return true;
}
-
-
-INTERNAL_FUNC int emstorage_begin_transaction(void *d1, void *d2, int *err_code)
+INTERNAL_FUNC int emstorage_begin_transaction(char *multi_user_name, void *d1, void *d2, int *err_code)
{
EM_PROFILE_BEGIN(emStorageBeginTransaction);
int ret = true;
- _timedlock_shm_mutex(&mapped_for_db_lock, 2);
+ _timedlock_shm_mutex(mapped_for_db_lock, 2);
+
+ sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name);
- sqlite3 *local_db_handle = emstorage_get_db_connection();
int rc;
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, "BEGIN immediate;", NULL, NULL, NULL), rc);
EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {ret = false; },
@@ -11027,13 +11323,13 @@ INTERNAL_FUNC int emstorage_begin_transaction(void *d1, void *d2, int *err_code)
return ret;
}
-INTERNAL_FUNC int emstorage_commit_transaction(void *d1, void *d2, int *err_code)
+INTERNAL_FUNC int emstorage_commit_transaction(char *multi_user_name, void *d1, void *d2, int *err_code)
{
EM_DEBUG_FUNC_BEGIN();
int ret = true;
int rc;
- sqlite3 *local_db_handle = emstorage_get_db_connection();
+ sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name);
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, "END;", NULL, NULL, NULL), rc);
EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {ret = false; }, ("SQL(END) exec error:%d -%s", rc, sqlite3_errmsg(local_db_handle)));
@@ -11041,18 +11337,18 @@ INTERNAL_FUNC int emstorage_commit_transaction(void *d1, void *d2, int *err_code
if (ret == false && err_code != NULL)
*err_code = EMAIL_ERROR_DB_FAILURE;
- _unlockshm_mutex(&mapped_for_db_lock);
+ _unlockshm_mutex(mapped_for_db_lock);
EM_DEBUG_FUNC_END("ret [%d]", ret);
return ret;
}
-INTERNAL_FUNC int emstorage_rollback_transaction(void *d1, void *d2, int *err_code)
+INTERNAL_FUNC int emstorage_rollback_transaction(char *multi_user_name, void *d1, void *d2, int *err_code)
{
EM_DEBUG_FUNC_BEGIN();
int ret = true;
- sqlite3 *local_db_handle = emstorage_get_db_connection();
int rc;
+ sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name);
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, "ROLLBACK;", NULL, NULL, NULL), rc);
EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {ret = false; },
@@ -11061,13 +11357,13 @@ INTERNAL_FUNC int emstorage_rollback_transaction(void *d1, void *d2, int *err_co
if (ret == false && err_code != NULL)
*err_code = EMAIL_ERROR_DB_FAILURE;
- _unlockshm_mutex(&mapped_for_db_lock);
+ _unlockshm_mutex(mapped_for_db_lock);
EM_DEBUG_FUNC_END("ret [%d]", ret);
return ret;
}
-INTERNAL_FUNC int emstorage_is_mailbox_full(int account_id, email_mailbox_t *mailbox, int *result, int *err_code)
+INTERNAL_FUNC int emstorage_is_mailbox_full(char *multi_user_name, int account_id, email_mailbox_t *mailbox, int *result, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("account_id[%d], mailbox[%p], result[%p], err_code[%p]", account_id, mailbox, result, err_code);
@@ -11085,7 +11381,7 @@ INTERNAL_FUNC int emstorage_is_mailbox_full(int account_id, email_mailbox_t *mai
int error = EMAIL_ERROR_NONE;
int mail_count = 0;
- if (!emstorage_get_mail_count(account_id, mailbox->mailbox_id, &mail_count, NULL, true, &error)) {
+ if (!emstorage_get_mail_count(multi_user_name, account_id, mailbox->mailbox_id, &mail_count, NULL, true, &error)) {
EM_DEBUG_EXCEPTION("emstorage_get_mail_count failed [%d]", error);
goto FINISH_OFF;
}
@@ -11110,7 +11406,7 @@ FINISH_OFF:
return ret;
}
-INTERNAL_FUNC int emstorage_clear_mail_data(int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_clear_mail_data(char *multi_user_name, int transaction, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("transaction[%d], err_code[%p]", transaction, err_code);
@@ -11119,8 +11415,9 @@ INTERNAL_FUNC int emstorage_clear_mail_data(int transaction, int *err_code)
char sql_query_string[QUERY_SIZE] = {0, };
const email_db_object_t* tables = _g_db_tables;
const email_db_object_t* indexes = _g_db_indexes;
- sqlite3 *local_db_handle = emstorage_get_db_connection();
- EMSTORAGE_START_WRITE_TRANSACTION(transaction, error);
+
+ sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name);
+ EMSTORAGE_START_WRITE_TRANSACTION(multi_user_name, transaction, error);
if (!emstorage_delete_dir(MAILHOME, &error)) {
EM_DEBUG_EXCEPTION(" emstorage_delete_dir failed - %d", error);
@@ -11130,6 +11427,7 @@ INTERNAL_FUNC int emstorage_clear_mail_data(int transaction, int *err_code)
mkdir(MAILHOME, DIRECTORY_PERMISSION);
mkdir(MAILTEMP, DIRECTORY_PERMISSION);
+ chmod(MAILTEMP, 0777);
/* first clear index. */
while (indexes->object_name) {
@@ -11159,7 +11457,7 @@ INTERNAL_FUNC int emstorage_clear_mail_data(int transaction, int *err_code)
ret = true;
FINISH_OFF:
- EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
+ EMSTORAGE_FINISH_WRITE_TRANSACTION(multi_user_name, transaction, ret, error);
if (err_code != NULL)
*err_code = error;
@@ -11192,9 +11490,10 @@ INTERNAL_FUNC char *emstorage_make_directory_path_from_file_path(char *file_name
return result;
}
-INTERNAL_FUNC int emstorage_get_save_name(int account_id, int mail_id, int atch_id, char *fname, char *name_buf, int maxlen, int *err_code)
+INTERNAL_FUNC int emstorage_get_save_name(char *multi_user_name, int account_id, int mail_id, int atch_id,
+ char *fname, char *move_buf, char *path_buf, int maxlen, int *err_code)
{
- EM_DEBUG_FUNC_BEGIN_SEC("account_id[%d], mail_id[%d], atch_id[%d], fname[%s], name_buf[%p], err_code[%p]", account_id, mail_id, atch_id, fname, name_buf, err_code);
+ EM_DEBUG_FUNC_BEGIN_SEC("account_id[%d], mail_id[%d], atch_id[%d], fname[%s], move_buf[%p], path_buf[%p], err_code[%p]", account_id, mail_id, atch_id, fname, move_buf, path_buf, err_code);
EM_PROFILE_BEGIN(profile_emstorage_get_save_name);
int ret = false;
@@ -11202,21 +11501,22 @@ INTERNAL_FUNC int emstorage_get_save_name(int account_id, int mail_id, int atch_
char *dir_name = NULL;
char create_dir[1024]={0};
char *temp_file = NULL;
+ char *prefix_path = NULL;
- if (!name_buf || account_id < FIRST_ACCOUNT_ID || mail_id < 0 || atch_id < 0) {
- EM_DEBUG_EXCEPTION(" account_id[%d], mail_id[%d], atch_id[%d], fname[%p], name_buf[%p]", account_id, mail_id, atch_id, fname, name_buf);
+ if (!move_buf || !path_buf || account_id < FIRST_ACCOUNT_ID || mail_id < 0 || atch_id < 0) {
+ EM_DEBUG_EXCEPTION(" account_id[%d], mail_id[%d], atch_id[%d], fname[%p], move_buf[%p], path_buf[%p]", account_id, mail_id, atch_id, fname, move_buf, path_buf);
error = EMAIL_ERROR_INVALID_PARAM;
goto FINISH_OFF;
}
- sprintf(name_buf, "%s", MAILHOME);
- sprintf(name_buf+EM_SAFE_STRLEN(name_buf), "%s%d", DIR_SEPERATOR, account_id);
+ sprintf(path_buf, "%s", MAILHOME);
+ sprintf(path_buf+EM_SAFE_STRLEN(path_buf), "%s%d", DIR_SEPERATOR, account_id);
if (mail_id > 0)
- sprintf(name_buf+EM_SAFE_STRLEN(name_buf), "%s%d", DIR_SEPERATOR, mail_id);
+ sprintf(path_buf+EM_SAFE_STRLEN(path_buf), "%s%d", DIR_SEPERATOR, mail_id);
if (atch_id > 0)
- sprintf(name_buf+EM_SAFE_STRLEN(name_buf), "%s%d", DIR_SEPERATOR, atch_id);
+ sprintf(path_buf+EM_SAFE_STRLEN(path_buf), "%s%d", DIR_SEPERATOR, atch_id);
if (fname) {
temp_file = EM_SAFE_STRDUP(fname);
@@ -11226,7 +11526,7 @@ INTERNAL_FUNC int emstorage_get_save_name(int account_id, int mail_id, int atch_
}
if (dir_name) {
- snprintf(create_dir, sizeof(create_dir), "%s%s%s", name_buf, DIR_SEPERATOR, dir_name);
+ snprintf(create_dir, sizeof(create_dir), "%s%s%s", path_buf, DIR_SEPERATOR, dir_name);
EM_DEBUG_LOG(">>>>> DIR PATH [%s]", create_dir);
mkdir(create_dir, DIRECTORY_PERMISSION);
EM_SAFE_FREE(dir_name);
@@ -11234,9 +11534,9 @@ INTERNAL_FUNC int emstorage_get_save_name(int account_id, int mail_id, int atch_
if (fname) {
EM_DEBUG_LOG_DEV(">>>>> fname [%s]", fname);
- if (EM_SAFE_STRLEN(fname) + EM_SAFE_STRLEN(name_buf) + strlen(DIR_SEPERATOR) > maxlen - 1) {
+ if (EM_SAFE_STRLEN(fname) + EM_SAFE_STRLEN(path_buf) + strlen(DIR_SEPERATOR) > maxlen - 1) {
char *modified_name = NULL;
- int remain_len = (maxlen - 1) - EM_SAFE_STRLEN(name_buf) - strlen(DIR_SEPERATOR);
+ int remain_len = (maxlen - 1) - EM_SAFE_STRLEN(path_buf) - strlen(DIR_SEPERATOR);
if (remain_len <= 0) {
error = EMAIL_ERROR_MAX_EXCEEDED;
@@ -11254,7 +11554,7 @@ INTERNAL_FUNC int emstorage_get_save_name(int account_id, int mail_id, int atch_
goto FINISH_OFF;
}
- sprintf(name_buf+EM_SAFE_STRLEN(name_buf), "%s%s", DIR_SEPERATOR, modified_name);
+ sprintf(path_buf+EM_SAFE_STRLEN(path_buf), "%s%s", DIR_SEPERATOR, modified_name);
EM_DEBUG_LOG(">>>>> Modified fname [%s]", modified_name);
EM_SAFE_FREE(modified_name);
} else {
@@ -11267,21 +11567,36 @@ INTERNAL_FUNC int emstorage_get_save_name(int account_id, int mail_id, int atch_
goto FINISH_OFF;
}
- sprintf(name_buf+EM_SAFE_STRLEN(name_buf), "%s%s", DIR_SEPERATOR, modified_name);
+ sprintf(path_buf+EM_SAFE_STRLEN(path_buf), "%s%s", DIR_SEPERATOR, modified_name);
EM_DEBUG_LOG(">>>>> Modified fname [%s]", modified_name);
EM_SAFE_FREE(modified_name);
} else {
- sprintf(name_buf+EM_SAFE_STRLEN(name_buf), "%s%s", DIR_SEPERATOR, fname);
+ sprintf(path_buf+EM_SAFE_STRLEN(path_buf), "%s%s", DIR_SEPERATOR, fname);
}
}
}
- EM_DEBUG_LOG_SEC(">>>>> name_buf [%s]", name_buf);
+ EM_DEBUG_LOG_SEC(">>>>> path_buf [%s]", path_buf);
+
+ if (EM_SAFE_STRLEN(multi_user_name) > 0) {
+ error = emcore_get_container_path(multi_user_name, &prefix_path);
+ if (error != EMAIL_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("emcore_get_container_path failed : [%d]", error);
+ goto FINISH_OFF;
+ }
+ sprintf(move_buf, "%s/%s", prefix_path, path_buf);
+ EM_DEBUG_LOG("move_buf : [%s]", move_buf);
+ } else {
+ sprintf(move_buf, "%s", path_buf);
+ EM_DEBUG_LOG("move_buf : [%s]", move_buf);
+ }
ret = true;
FINISH_OFF:
+
EM_SAFE_FREE(temp_file);
+ EM_SAFE_FREE(prefix_path);
if (err_code != NULL)
*err_code = error;
@@ -11291,7 +11606,7 @@ FINISH_OFF:
return ret;
}
-INTERNAL_FUNC int emstorage_get_dele_name(int account_id, int mail_id, int atch_id, char *fname, char *name_buf, int *err_code)
+INTERNAL_FUNC int emstorage_get_dele_name(char *multi_user_name, int account_id, int mail_id, int atch_id, char *fname, char *name_buf, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("account_id[%d], mail_id[%d], atch_id[%d], fname[%p], name_buf[%p], err_code[%p]", account_id, mail_id, atch_id, fname, name_buf, err_code);
@@ -11321,7 +11636,7 @@ FINISH_OFF:
return true;
}
-INTERNAL_FUNC int emstorage_create_dir(int account_id, int mail_id, int atch_id, int *err_code)
+INTERNAL_FUNC int emstorage_create_dir(char *multi_user_name, int account_id, int mail_id, int atch_id, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("account_id[%d], mail_id[%d], atch_id[%d], err_code[%p]", account_id, mail_id, atch_id, err_code);
EM_PROFILE_BEGIN(profile_emcore_save_create_dir);
@@ -11329,10 +11644,27 @@ INTERNAL_FUNC int emstorage_create_dir(int account_id, int mail_id, int atch_id,
int error = EMAIL_ERROR_NONE;
char buf[512];
struct stat sbuf;
+ char *prefix_path = NULL;
char errno_buf[ERRNO_BUF_SIZE] = {0};
+ memset(buf, 0x00, sizeof(buf));
+
+ if (EM_SAFE_STRLEN(multi_user_name) > 0) {
+ error = emcore_get_container_path(multi_user_name, &prefix_path);
+ if (error != EMAIL_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("emcore_get_container_path failed : [%d]", error);
+ goto FINISH_OFF;
+ }
+ } else {
+ prefix_path = strdup("");
+ }
+
if (account_id >= FIRST_ACCOUNT_ID) {
- SNPRINTF(buf, sizeof(buf), "%s%s%d", MAILHOME, DIR_SEPERATOR, account_id);
+ SNPRINTF(buf, sizeof(buf), "%s%s%s%s%d", prefix_path,
+ DIR_SEPERATOR,
+ MAILHOME,
+ DIR_SEPERATOR,
+ account_id);
if (stat(buf, &sbuf) == 0) {
if ((sbuf.st_mode & S_IFMT) != S_IFDIR) {
@@ -11350,35 +11682,50 @@ INTERNAL_FUNC int emstorage_create_dir(int account_id, int mail_id, int atch_id,
error = EMAIL_ERROR_OUT_OF_MEMORY;
goto FINISH_OFF;
}
+
+ if (account_id == EML_FOLDER) {
+ chmod(buf, 0777);
+ }
}
}
if (mail_id > 0) {
+ int space_left_in_buffer = sizeof(buf) - EM_SAFE_STRLEN(buf);
+
if (account_id < FIRST_ACCOUNT_ID) {
EM_DEBUG_EXCEPTION("account_id[%d], mail_id[%d], atch_id[%d]", account_id, mail_id, atch_id);
error = EMAIL_ERROR_INVALID_PARAM;
goto FINISH_OFF;
}
- SNPRINTF(buf+EM_SAFE_STRLEN(buf), sizeof(buf)-(EM_SAFE_STRLEN(buf)+1), "%s%d", DIR_SEPERATOR, mail_id);
+ if (space_left_in_buffer + 10 > sizeof(buf)) {
+ EM_DEBUG_EXCEPTION("Buffer overflowed");
+ error = EMAIL_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ SNPRINTF(buf+EM_SAFE_STRLEN(buf), space_left_in_buffer, "%s%d", DIR_SEPERATOR, mail_id);
if (stat(buf, &sbuf) == 0) {
if ((sbuf.st_mode & S_IFMT) != S_IFDIR) {
EM_DEBUG_EXCEPTION(" a object which isn't directory aleady exists");
-
error = EMAIL_ERROR_SYSTEM_FAILURE;
goto FINISH_OFF;
}
}
else {
if (mkdir(buf, DIRECTORY_PERMISSION) != 0) {
- EM_DEBUG_EXCEPTION(" mkdir failed [%s]", buf);
- EM_DEBUG_EXCEPTION("mkdir failed: %s", strerror(errno));
+ EM_DEBUG_EXCEPTION("mkdir failed [%s]", buf);
+ EM_DEBUG_EXCEPTION("mkdir failed [%d][%s]", errno, EM_STRERROR(errno_buf));
error = EMAIL_ERROR_SYSTEM_FAILURE;
if(errno == 28)
error = EMAIL_ERROR_OUT_OF_MEMORY;
goto FINISH_OFF;
}
+
+ if (account_id == EML_FOLDER) {
+ chmod(buf, 0777);
+ }
}
}
@@ -11408,12 +11755,19 @@ INTERNAL_FUNC int emstorage_create_dir(int account_id, int mail_id, int atch_id,
error = EMAIL_ERROR_OUT_OF_MEMORY;
goto FINISH_OFF;
}
+
+ if (account_id == EML_FOLDER) {
+ chmod(buf, 0777);
+ }
}
}
ret = true;
FINISH_OFF:
+
+ EM_SAFE_FREE(prefix_path);
+
if (err_code != NULL)
*err_code = error;
@@ -11450,50 +11804,50 @@ INTERNAL_FUNC int emstorage_copy_file(char *src_file, char *dst_file, int sync_s
goto FINISH_OFF;
}
- error = em_open(src_file, O_RDONLY, 0, &fp_src);
- if (error != EMAIL_ERROR_NONE) {
- EM_DEBUG_EXCEPTION(">>>> Source Fail em_open %s Failed: %d", src_file, error);
- goto FINISH_OFF;
- }
+ error = em_open(src_file, O_RDONLY, 0, &fp_src);
+ if (error != EMAIL_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION(">>>> Source Fail em_open %s Failed: %d", src_file, error);
+ goto FINISH_OFF;
+ }
- error = em_open(dst_file, O_CREAT | O_WRONLY | O_TRUNC, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH, &fp_dst); /*prevent 24474*/
- if (error != EMAIL_ERROR_NONE) {
- EM_DEBUG_EXCEPTION(">>>> Destination Fail em_open %s: %d", dst_file, error);
- goto FINISH_OFF;
- }
+ error = em_open(dst_file, O_CREAT | O_WRONLY | O_TRUNC, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH, &fp_dst); /*prevent 24474*/
+ if (error != EMAIL_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION(">>>> Destination Fail em_open %s: %d", dst_file, error);
+ goto FINISH_OFF;
+ }
- memset(buf, 0x00, FILE_MAX_BUFFER_SIZE);
-
- while ((nread = read(fp_src, buf, FILE_MAX_BUFFER_SIZE)) > 0) {
- if (nread > 0 && nread <= FILE_MAX_BUFFER_SIZE) {
- EM_DEBUG_LOG("Nread Value [%d]", nread);
- char *buf_ptr;
- ssize_t byte_written = 0;
- size_t remain_byte = nread;
- buf_ptr = buf;
- errno = 0;
-
- while(remain_byte > 0 && buf_ptr && errno == 0) {
- byte_written = write(fp_dst, buf_ptr, remain_byte);
-
- if (byte_written < 0) {
- /* interrupted by a signal */
- if (errno == EINTR) {
- errno = 0;
- continue;
- }
-
- EM_DEBUG_EXCEPTION("fwrite failed: %s", EM_STRERROR(errno_buf));
- error = EMAIL_ERROR_UNKNOWN;
- goto FINISH_OFF;
- }
- EM_DEBUG_LOG("NWRITTEN [%d]", byte_written);
- remain_byte -= byte_written;
- buf_ptr += byte_written;
- }
- }
+ memset(buf, 0x00, FILE_MAX_BUFFER_SIZE);
+
+ while ((nread = read(fp_src, buf, FILE_MAX_BUFFER_SIZE)) > 0) {
+ if (nread > 0 && nread <= FILE_MAX_BUFFER_SIZE) {
+ EM_DEBUG_LOG("Nread Value [%d]", nread);
+ char *buf_ptr;
+ ssize_t byte_written = 0;
+ size_t remain_byte = nread;
+ buf_ptr = buf;
+ errno = 0;
+
+ while(remain_byte > 0 && buf_ptr && errno == 0) {
+ byte_written = write(fp_dst, buf_ptr, remain_byte);
- memset(buf, 0x00, FILE_MAX_BUFFER_SIZE);
+ if (byte_written < 0) {
+ /* interrupted by a signal */
+ if (errno == EINTR) {
+ errno = 0;
+ continue;
+ }
+
+ EM_DEBUG_EXCEPTION("fwrite failed: %s", EM_STRERROR(errno_buf));
+ error = EMAIL_ERROR_UNKNOWN;
+ goto FINISH_OFF;
+ }
+ EM_DEBUG_LOG("NWRITTEN [%d]", byte_written);
+ remain_byte -= byte_written;
+ buf_ptr += byte_written;
+ }
+ }
+
+ memset(buf, 0x00, FILE_MAX_BUFFER_SIZE);
}
ret = true;
@@ -11526,6 +11880,7 @@ INTERNAL_FUNC void emstorage_create_dir_if_delete()
mkdir(EMAILPATH, DIRECTORY_PERMISSION);
mkdir(MAILHOME, DIRECTORY_PERMISSION);
mkdir(MAILTEMP, DIRECTORY_PERMISSION);
+ chmod(MAILTEMP, 0777);
EM_DEBUG_FUNC_END();
}
@@ -11916,7 +12271,7 @@ INTERNAL_FUNC int emstorage_delete_dir(char *src_dir, int *err_code)
}
/* faizan.h@samsung.com */
-INTERNAL_FUNC int emstorage_update_server_uid(char *old_server_uid, char *new_server_uid, int *err_code)
+INTERNAL_FUNC int emstorage_update_server_uid(char *multi_user_name, char *old_server_uid, char *new_server_uid, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("new_server_uid[%s], old_server_uid[%s]", new_server_uid, old_server_uid);
int ret = false;
@@ -11931,9 +12286,9 @@ INTERNAL_FUNC int emstorage_update_server_uid(char *old_server_uid, char *new_se
return false;
}
- sqlite3 *local_db_handle = emstorage_get_db_connection();
+ sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name);
- EMSTORAGE_START_WRITE_TRANSACTION(transaction, error);
+ EMSTORAGE_START_WRITE_TRANSACTION(multi_user_name, transaction, error);
SNPRINTF(sql_query_string, sizeof(sql_query_string),
"UPDATE mail_tbl SET server_mail_id=\'%s\' WHERE server_mail_id=%s ", new_server_uid, old_server_uid);
@@ -11947,7 +12302,7 @@ INTERNAL_FUNC int emstorage_update_server_uid(char *old_server_uid, char *new_se
ret = true;
FINISH_OFF:
- EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
+ EMSTORAGE_FINISH_WRITE_TRANSACTION(multi_user_name, transaction, ret, error);
if (err_code != NULL)
*err_code = error;
@@ -11957,7 +12312,7 @@ FINISH_OFF:
}
-INTERNAL_FUNC int emstorage_update_read_mail_uid(int mail_id, char *new_server_uid, char *mbox_name, int *err_code)
+INTERNAL_FUNC int emstorage_update_read_mail_uid(char *multi_user_name, int mail_id, char *new_server_uid, char *mbox_name, int *err_code)
{
EM_DEBUG_FUNC_BEGIN_SEC("mail_id[%d], new_server_uid[%s], mbox_name[%s]", mail_id, new_server_uid, mbox_name);
@@ -11973,8 +12328,8 @@ INTERNAL_FUNC int emstorage_update_read_mail_uid(int mail_id, char *new_server_u
return false;
}
- sqlite3 *local_db_handle = emstorage_get_db_connection();
- EMSTORAGE_START_WRITE_TRANSACTION(transaction, error);
+ sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name);
+ EMSTORAGE_START_WRITE_TRANSACTION(multi_user_name, transaction, error);
SNPRINTF(sql_query_string, sizeof(sql_query_string),
@@ -11990,7 +12345,7 @@ INTERNAL_FUNC int emstorage_update_read_mail_uid(int mail_id, char *new_server_u
FINISH_OFF:
- EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
+ EMSTORAGE_FINISH_WRITE_TRANSACTION(multi_user_name, transaction, ret, error);
if (err_code != NULL)
*err_code = error;
@@ -12000,7 +12355,7 @@ FINISH_OFF:
}
-INTERNAL_FUNC int emstorage_update_save_status(int account_id, int *err_code)
+INTERNAL_FUNC int emstorage_update_save_status(char *multi_user_name, int account_id, int *err_code)
{
EM_DEBUG_FUNC_BEGIN();
@@ -12009,8 +12364,9 @@ INTERNAL_FUNC int emstorage_update_save_status(int account_id, int *err_code)
int error = EMAIL_ERROR_NONE;
char sql_query_string[QUERY_SIZE] = {0,};
- sqlite3 *local_db_handle = emstorage_get_db_connection();
- EMSTORAGE_START_WRITE_TRANSACTION(transaction, error);
+ sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name);
+
+ EMSTORAGE_START_WRITE_TRANSACTION(multi_user_name, transaction, error);
memset(sql_query_string, 0x00, sizeof(sql_query_string));
@@ -12028,7 +12384,7 @@ INTERNAL_FUNC int emstorage_update_save_status(int account_id, int *err_code)
ret = true;
FINISH_OFF:
- EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
+ EMSTORAGE_FINISH_WRITE_TRANSACTION(multi_user_name, transaction, ret, error);
if (err_code != NULL)
*err_code = error;
@@ -12038,7 +12394,7 @@ FINISH_OFF:
}
-int emstorage_get_unread_mailid(int account_id, int vip_mode, int **mail_ids, int *mail_number, int *err_code)
+int emstorage_get_unread_mailid(char *multi_user_name, int account_id, int vip_mode, int **mail_ids, int *mail_number, int *err_code)
{
EM_DEBUG_FUNC_BEGIN();
@@ -12062,7 +12418,7 @@ int emstorage_get_unread_mailid(int account_id, int vip_mode, int **mail_ids, in
char temp_query_string[QUERY_SIZE] = {0,};
char sql_select_query_string[QUERY_SIZE] = {0, };
- sqlite3 *local_db_handle = emstorage_get_db_connection();
+ sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name);
EMSTORAGE_START_READ_TRANSACTION(transaction);
memset(sql_query_string, 0x00, sizeof(sql_query_string));
@@ -12117,8 +12473,7 @@ FINISH_OFF:
EMSTORAGE_FINISH_READ_TRANSACTION(transaction);
- sqlite3_db_release_memory(local_db_handle);
-
+// sqlite3_db_release_memory(local_db_handle);
if (ret == true) {
if (mail_ids != NULL)
@@ -12255,8 +12610,7 @@ FINISH_OFF:
return ret;
}
-
-INTERNAL_FUNC int emstorage_test(int mail_id, int account_id, char *full_address_to, char *full_address_cc, char *full_address_bcc, int *err_code)
+INTERNAL_FUNC int emstorage_test(char *multi_user_name, int mail_id, int account_id, char *full_address_to, char *full_address_cc, char *full_address_bcc, int *err_code)
{
DB_STMT hStmt = NULL;
int ret = false;
@@ -12322,9 +12676,9 @@ INTERNAL_FUNC int emstorage_test(int mail_id, int account_id, char *full_address
")");
int transaction = true;
- sqlite3 *local_db_handle = emstorage_get_db_connection();
+ sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name);
- EMSTORAGE_START_WRITE_TRANSACTION(transaction, error);
+ EMSTORAGE_START_WRITE_TRANSACTION(multi_user_name, transaction, error);
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc);
@@ -12394,7 +12748,7 @@ INTERNAL_FUNC int emstorage_test(int mail_id, int account_id, char *full_address
ret = true;
FINISH_OFF:
- EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
+ EMSTORAGE_FINISH_WRITE_TRANSACTION(multi_user_name, transaction, ret, error);
if (hStmt != NULL) {
rc = sqlite3_finalize(hStmt);
if (rc != SQLITE_OK) {
@@ -12418,10 +12772,17 @@ INTERNAL_FUNC int emstorage_get_max_mail_count()
#define STRIPPED_SUBJECT_BUFFER_SIZE 4086
-INTERNAL_FUNC int emstorage_get_thread_id_of_thread_mails(emstorage_mail_tbl_t *mail_tbl, int *thread_id, int *result_latest_mail_id_in_thread, int *thread_item_count)
+INTERNAL_FUNC int emstorage_get_thread_id_of_thread_mails(char *multi_user_name,
+ emstorage_mail_tbl_t *mail_tbl,
+ int *thread_id,
+ int *result_latest_mail_id_in_thread,
+ int *thread_item_count)
{
- EM_DEBUG_FUNC_BEGIN("mail_tbl [%p], thread_id [%p], result_latest_mail_id_in_thread [%p], thread_item_count [%p]", mail_tbl, thread_id, result_latest_mail_id_in_thread, thread_item_count);
+ EM_DEBUG_FUNC_BEGIN("mail_tbl [%p], thread_id [%p], "
+ "result_latest_mail_id_in_thread [%p], thread_item_count [%p]",
+ mail_tbl, thread_id, result_latest_mail_id_in_thread, thread_item_count);
EM_PROFILE_BEGIN(profile_emstorage_get_thread_id_of_thread_mails);
+
int rc = 0, query_size = 0, query_size_account = 0;
int account_id = 0;
int err_code = EMAIL_ERROR_NONE;
@@ -12434,9 +12795,10 @@ INTERNAL_FUNC int emstorage_get_thread_id_of_thread_mails(emstorage_mail_tbl_t *
char *sql_format_order_by = " ORDER BY date_time DESC ";
char **result = NULL;
char stripped_subject[STRIPPED_SUBJECT_BUFFER_SIZE];
- sqlite3 *local_db_handle = emstorage_get_db_connection();
- EM_DEBUG_LOG_SEC("subject: [%p], mail_id: [%d]", subject, mail_tbl->mail_id);
+ sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name);
+
+ EM_DEBUG_LOG("subject: [%p], mail_id: [%d]", subject, mail_tbl->mail_id);
EM_IF_NULL_RETURN_VALUE(mail_tbl, EMAIL_ERROR_INVALID_PARAM);
EM_IF_NULL_RETURN_VALUE(thread_id, EMAIL_ERROR_INVALID_PARAM);
@@ -12454,7 +12816,9 @@ INTERNAL_FUNC int emstorage_get_thread_id_of_thread_mails(emstorage_mail_tbl_t *
goto FINISH_OFF;
}
- if (em_find_pos_stripped_subject_for_thread_view(subject, stripped_subject, STRIPPED_SUBJECT_BUFFER_SIZE) != EMAIL_ERROR_NONE) {
+ if (em_find_pos_stripped_subject_for_thread_view(subject,
+ stripped_subject,
+ STRIPPED_SUBJECT_BUFFER_SIZE) != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("em_find_pos_stripped_subject_for_thread_view is failed");
err_code = EMAIL_ERROR_UNKNOWN;
result_thread_id = -1;
@@ -12463,12 +12827,13 @@ INTERNAL_FUNC int emstorage_get_thread_id_of_thread_mails(emstorage_mail_tbl_t *
EM_DEBUG_LOG_SEC("stripped_subject: [%s]", stripped_subject);
- if (EM_SAFE_STRLEN(stripped_subject) < 2) {
+ if (EM_SAFE_STRLEN(stripped_subject) == 0) {
result_thread_id = -1;
goto FINISH_OFF;
}
- EM_DEBUG_LOG_SEC("em_find_pos_stripped_subject_for_thread_view returns[len = %d] = %s", EM_SAFE_STRLEN(stripped_subject), stripped_subject);
+ EM_DEBUG_LOG_SEC("em_find_pos_stripped_subject_for_thread_view returns[len = %d] = %s",
+ EM_SAFE_STRLEN(stripped_subject), stripped_subject);
if (account_id > 0) {
query_size_account = 3 + EM_SAFE_STRLEN(sql_format_account);
@@ -12540,7 +12905,7 @@ FINISH_OFF:
return err_code;
}
-INTERNAL_FUNC int emstorage_get_thread_id_from_mailbox(int account_id, int mailbox_id, char *mail_subject, int *thread_id, int *thread_item_count)
+INTERNAL_FUNC int emstorage_get_thread_id_from_mailbox(char *multi_user_name, int account_id, int mailbox_id, char *mail_subject, int *thread_id, int *thread_item_count)
{
EM_DEBUG_FUNC_BEGIN("mailbox_id [%d], subject [%p], thread_id [%p], thread_item_count [%p]", mailbox_id, mail_subject, thread_id, thread_item_count);
EM_PROFILE_BEGIN(profile_emstorage_get_thread_id_of_thread_mails);
@@ -12558,7 +12923,7 @@ INTERNAL_FUNC int emstorage_get_thread_id_from_mailbox(int account_id, int mailb
char *sql_format_order_by = " ORDER BY date_time DESC ";
char **result = NULL;
char stripped_subject[STRIPPED_SUBJECT_BUFFER_SIZE];
- sqlite3 *local_db_handle = emstorage_get_db_connection();
+ sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name);
EM_IF_NULL_RETURN_VALUE(mail_subject, EMAIL_ERROR_INVALID_PARAM);
EM_IF_NULL_RETURN_VALUE(thread_id, EMAIL_ERROR_INVALID_PARAM);
@@ -12573,7 +12938,7 @@ INTERNAL_FUNC int emstorage_get_thread_id_from_mailbox(int account_id, int mailb
goto FINISH_OFF;
}
- if (EM_SAFE_STRLEN(stripped_subject) < 2) {
+ if (EM_SAFE_STRLEN(stripped_subject) == 0) {
result_thread_id = -1;
goto FINISH_OFF;
}
@@ -12641,8 +13006,7 @@ FINISH_OFF:
return err_code;
}
-
-INTERNAL_FUNC int emstorage_get_thread_information(int thread_id, emstorage_mail_tbl_t** mail_tbl, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_get_thread_information(char *multi_user_name, int thread_id, emstorage_mail_tbl_t** mail_tbl, int transaction, int *err_code)
{
EM_DEBUG_FUNC_BEGIN();
@@ -12656,7 +13020,7 @@ INTERNAL_FUNC int emstorage_get_thread_information(int thread_id, emstorage_mail
SNPRINTF(conditional_clause, QUERY_SIZE, "WHERE thread_id = %d AND thread_item_count > 0", thread_id);
EM_DEBUG_LOG("conditional_clause [%s]", conditional_clause);
- if(!emstorage_query_mail_tbl(conditional_clause, transaction, &p_data_tbl, &count, &error)) {
+ if(!emstorage_query_mail_tbl(multi_user_name, conditional_clause, transaction, &p_data_tbl, &count, &error)) {
EM_DEBUG_EXCEPTION("emstorage_query_mail_tbl failed [%d]", error);
goto FINISH_OFF;
}
@@ -12679,8 +13043,7 @@ FINISH_OFF:
return ret;
}
-
-INTERNAL_FUNC int emstorage_get_sender_list(int account_id, int mailbox_id, int search_type, const char *search_value, email_sort_type_t sorting, email_sender_list_t** sender_list, int *sender_count, int *err_code)
+INTERNAL_FUNC int emstorage_get_sender_list(char *multi_user_name, int account_id, int mailbox_id, int search_type, const char *search_value, email_sort_type_t sorting, email_sender_list_t** sender_list, int *sender_count, int *err_code)
{
EM_DEBUG_FUNC_BEGIN_SEC("account_id [%d], mailbox_id [%d], search_type [%d], search_value [%p], sorting [%d], sender_list[%p], sender_count[%p] err_code[%p]"
, account_id , mailbox_id , search_type , search_value , sorting , sender_list, sender_count, err_code);
@@ -12700,7 +13063,7 @@ INTERNAL_FUNC int emstorage_get_sender_list(int account_id, int mailbox_id, int
email_sender_list_t *p_sender_list = NULL;
char sql_query_string[QUERY_SIZE] = {0, };
char **result = NULL;
- sqlite3 *local_db_handle = emstorage_get_db_connection();
+ sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name);
SNPRINTF(sql_query_string, sizeof(sql_query_string),
"SELECT email_address_sender, alias_sender, COUNT(email_address_sender), SUM(flags_seen_field = 1) "
@@ -12884,7 +13247,7 @@ INTERNAL_FUNC int emstorage_free_address_info_list(email_address_info_list_t **a
}
#ifdef __FEATURE_PARTIAL_BODY_DOWNLOAD__
-INTERNAL_FUNC int emstorage_add_pbd_activity(email_event_partial_body_thd* local_activity, int *activity_id, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_add_pbd_activity(char *multi_user_name, email_event_partial_body_thd* local_activity, int *activity_id, int transaction, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("local_activity[%p], activity_id[%p], transaction[%d], err_code[%p]", local_activity, activity_id, transaction, err_code);
@@ -12902,8 +13265,9 @@ INTERNAL_FUNC int emstorage_add_pbd_activity(email_event_partial_body_thd* local
char sql_query_string[QUERY_SIZE] = {0, };
DB_STMT hStmt = NULL;
- sqlite3 *local_db_handle = emstorage_get_db_connection();
- EMSTORAGE_START_WRITE_TRANSACTION(transaction, error);
+ sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name);
+
+ EMSTORAGE_START_WRITE_TRANSACTION(multi_user_name, transaction, error);
memset(sql_query_string, 0x00, sizeof(sql_query_string));
SNPRINTF(sql_query_string, sizeof(sql_query_string),
"INSERT INTO mail_partial_body_activity_tbl VALUES "
@@ -12915,6 +13279,7 @@ INTERNAL_FUNC int emstorage_add_pbd_activity(email_event_partial_body_thd* local
",?" /* Activity type*/
",?" /* Mailbox ID*/
",?" /* Mailbox name*/
+ ",?" /* Multi User Name */
") ");
char *sql = "SELECT max(rowid) FROM mail_partial_body_activity_tbl;";
@@ -12945,7 +13310,6 @@ INTERNAL_FUNC int emstorage_add_pbd_activity(email_event_partial_body_thd* local
("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
-
_bind_stmt_field_data_int(hStmt, i++, local_activity->account_id);
_bind_stmt_field_data_int(hStmt, i++, local_activity->mail_id);
_bind_stmt_field_data_int(hStmt, i++, local_activity->server_mail_id);
@@ -12953,6 +13317,7 @@ INTERNAL_FUNC int emstorage_add_pbd_activity(email_event_partial_body_thd* local
_bind_stmt_field_data_int(hStmt, i++, local_activity->activity_type);
_bind_stmt_field_data_int(hStmt, i++, local_activity->mailbox_id);
_bind_stmt_field_data_string(hStmt, i++ , (char *)local_activity->mailbox_name, 0, 3999);
+ _bind_stmt_field_data_string(hStmt, i++ , (char *)local_activity->multi_user_name, 0, MAX_USER_NAME_LENGTH);
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
@@ -12965,7 +13330,7 @@ INTERNAL_FUNC int emstorage_add_pbd_activity(email_event_partial_body_thd* local
ret = true;
FINISH_OFF:
- EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
+ EMSTORAGE_FINISH_WRITE_TRANSACTION(multi_user_name, transaction, ret, error);
if (hStmt != NULL) {
rc = sqlite3_finalize(hStmt);
hStmt = NULL;
@@ -12982,8 +13347,7 @@ FINISH_OFF:
return ret;
}
-
-INTERNAL_FUNC int emstorage_get_pbd_mailbox_list(int account_id, int **mailbox_list, int *count, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_get_pbd_mailbox_list(char *multi_user_name, int account_id, int **mailbox_list, int *count, int transaction, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("account_id[%d], mailbox_list[%p], count[%p] err_code[%p]", account_id, mailbox_list, count, err_code);
@@ -13002,8 +13366,7 @@ INTERNAL_FUNC int emstorage_get_pbd_mailbox_list(int account_id, int **mailbox_l
DB_STMT hStmt = NULL;
char sql_query_string[QUERY_SIZE] = {0, };
- sqlite3 *local_db_handle = emstorage_get_db_connection();
-
+ sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name);
EMSTORAGE_START_READ_TRANSACTION(transaction);
memset(sql_query_string, 0x00, sizeof(sql_query_string));
@@ -13086,8 +13449,7 @@ FINISH_OFF:
return ret;
}
-
-INTERNAL_FUNC int emstorage_get_pbd_account_list(int **account_list, int *count, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_get_pbd_account_list(char *multi_user_name, int **account_list, int *count, int transaction, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("account_list[%p], count[%p] err_code[%p]", account_list, count, err_code);
@@ -13106,7 +13468,8 @@ INTERNAL_FUNC int emstorage_get_pbd_account_list(int **account_list, int *count,
int *result_account_list = NULL;
DB_STMT hStmt = NULL;
char sql_query_string[QUERY_SIZE] = {0, };
- sqlite3 *local_db_handle = emstorage_get_db_connection();
+
+ sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name);
EMSTORAGE_START_READ_TRANSACTION(transaction);
@@ -13185,9 +13548,7 @@ FINISH_OFF:
return ret;
}
-
-
-INTERNAL_FUNC int emstorage_get_pbd_activity_data(int account_id, int input_mailbox_id, email_event_partial_body_thd** event_start, int *count, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_get_pbd_activity_data(char *multi_user_name, int account_id, int input_mailbox_id, email_event_partial_body_thd** event_start, int *count, int transaction, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("account_id[%d], event_start[%p], err_code[%p]", account_id, event_start, err_code);
@@ -13208,7 +13569,7 @@ INTERNAL_FUNC int emstorage_get_pbd_activity_data(int account_id, int input_mail
email_event_partial_body_thd* event_list = NULL;
char sql_query_string[QUERY_SIZE] = {0, };
- sqlite3 *local_db_handle = emstorage_get_db_connection();
+ sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name);
EMSTORAGE_START_READ_TRANSACTION(transaction);
@@ -13266,6 +13627,7 @@ INTERNAL_FUNC int emstorage_get_pbd_activity_data(int account_id, int input_mail
_get_stmt_field_data_int(hStmt, &(event_list[i].activity_type), ACTIVITY_TYPE_IDX_IN_MAIL_PARTIAL_BODY_ACTIVITY_TBL);
_get_stmt_field_data_int(hStmt, &(event_list[i].mailbox_id), MAILBOX_ID_IDX_IN_MAIL_PARTIAL_BODY_ACTIVITY_TBL);
_get_stmt_field_data_string(hStmt, &(event_list[i].mailbox_name), 0, MAILBOX_NAME_IDX_IN_MAIL_PARTIAL_BODY_ACTIVITY_TBL);
+ _get_stmt_field_data_string(hStmt, &(event_list[i].multi_user_name), 0, MULTI_USER_NAME_IDX_IN_MAIL_PARTIAL_BODY_ACTIVITY_TBL);
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
/* EM_DEBUG_LOG("In emstorage_get_pbd_activity_data() loop, After sqlite3_step(), , i = %d, rc = %d.", i, rc); */
@@ -13305,9 +13667,7 @@ FINISH_OFF:
return ret;
}
-
-
-INTERNAL_FUNC int emstorage_delete_pbd_activity(int account_id, int mail_id, int activity_id, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_delete_pbd_activity(char *multi_user_name, int account_id, int mail_id, int activity_id, int transaction, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("account_id[%d], mail_id[%d] , activity_id[%d], transaction[%d], err_code[%p]", account_id, mail_id, activity_id, transaction, err_code);
@@ -13324,9 +13684,9 @@ INTERNAL_FUNC int emstorage_delete_pbd_activity(int account_id, int mail_id, int
int ret = false;
int error = EMAIL_ERROR_NONE;
char sql_query_string[QUERY_SIZE] = {0, };
- sqlite3 *local_db_handle = emstorage_get_db_connection();
+ sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name);
- EMSTORAGE_START_WRITE_TRANSACTION(transaction, error);
+ EMSTORAGE_START_WRITE_TRANSACTION(multi_user_name, transaction, error);
memset(sql_query_string, 0x00, sizeof(sql_query_string));
if (activity_id == 0)
@@ -13353,7 +13713,7 @@ INTERNAL_FUNC int emstorage_delete_pbd_activity(int account_id, int mail_id, int
ret = true;
FINISH_OFF:
- EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
+ EMSTORAGE_FINISH_WRITE_TRANSACTION(multi_user_name, transaction, ret, error);
if (err_code != NULL)
*err_code = error;
@@ -13362,7 +13722,7 @@ FINISH_OFF:
return ret;
}
-INTERNAL_FUNC int emstorage_get_mailbox_pbd_activity_count(int account_id, int input_mailbox_id, int *activity_count, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_get_mailbox_pbd_activity_count(char *multi_user_name, int account_id, int input_mailbox_id, int *activity_count, int transaction, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("account_id[%d], activity_count[%p], err_code[%p]", account_id, activity_count, err_code);
@@ -13379,7 +13739,7 @@ INTERNAL_FUNC int emstorage_get_mailbox_pbd_activity_count(int account_id, int i
DB_STMT hStmt = NULL;
- sqlite3 *local_db_handle = emstorage_get_db_connection();
+ sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name);
EMSTORAGE_START_READ_TRANSACTION(transaction);
memset(sql_query_string, 0x00, sizeof(sql_query_string));
@@ -13425,8 +13785,7 @@ FINISH_OFF:
return ret;
}
-
-INTERNAL_FUNC int emstorage_get_pbd_activity_count(int *activity_count, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_get_pbd_activity_count(char *multi_user_name, int *activity_count, int transaction, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("activity_count[%p], err_code[%p]", activity_count, err_code);
@@ -13442,7 +13801,7 @@ INTERNAL_FUNC int emstorage_get_pbd_activity_count(int *activity_count, int tran
DB_STMT hStmt = NULL;
char sql_query_string[QUERY_SIZE] = {0, };
- sqlite3 *local_db_handle = emstorage_get_db_connection();
+ sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name);
EMSTORAGE_START_READ_TRANSACTION(transaction);
memset(sql_query_string, 0x00, sizeof(sql_query_string));
@@ -13451,13 +13810,11 @@ INTERNAL_FUNC int emstorage_get_pbd_activity_count(int *activity_count, int tran
EM_DEBUG_LOG_DEV(" Query [%s]", sql_query_string);
-
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc);
EM_DEBUG_LOG_DEV (" before sqlite3_prepare hStmt = %p", hStmt);
EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
-
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
EM_DEBUG_DB_EXEC((rc != SQLITE_ROW), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("sqlite3_step fail:%d", rc));
@@ -13488,7 +13845,7 @@ FINISH_OFF:
return ret;
}
-INTERNAL_FUNC int emstorage_delete_full_pbd_activity_data(int account_id, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_delete_full_pbd_activity_data(char *multi_user_name, int account_id, int transaction, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("account_id[%d], transaction[%d], err_code[%p]", account_id, transaction, err_code);
if (account_id < FIRST_ACCOUNT_ID) {
@@ -13502,8 +13859,10 @@ INTERNAL_FUNC int emstorage_delete_full_pbd_activity_data(int account_id, int tr
int ret = false;
int error = EMAIL_ERROR_NONE;
char sql_query_string[QUERY_SIZE] = {0, };
- sqlite3 *local_db_handle = emstorage_get_db_connection();
- EMSTORAGE_START_WRITE_TRANSACTION(transaction, error);
+
+ sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name);
+
+ EMSTORAGE_START_WRITE_TRANSACTION(multi_user_name, transaction, error);
memset(sql_query_string, 0x00, sizeof(sql_query_string));
SNPRINTF(sql_query_string, sizeof(sql_query_string), "DELETE FROM mail_partial_body_activity_tbl WHERE account_id = %d", account_id);
@@ -13525,7 +13884,8 @@ INTERNAL_FUNC int emstorage_delete_full_pbd_activity_data(int account_id, int tr
ret = true;
FINISH_OFF:
- EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
+
+ EMSTORAGE_FINISH_WRITE_TRANSACTION(multi_user_name, transaction, ret, error);
if (err_code != NULL)
*err_code = error;
@@ -13537,7 +13897,7 @@ FINISH_OFF:
/*Himanshu[h.gahlaut]-> Added below API to update mail_partial_body_activity_tbl
if a mail is moved before its partial body is downloaded.Currently not used but should be used if mail move from server is enabled*/
-INTERNAL_FUNC int emstorage_update_pbd_activity(char *old_server_uid, char *new_server_uid, char *mbox_name, int *err_code)
+INTERNAL_FUNC int emstorage_update_pbd_activity(char *multi_user_name, char *old_server_uid, char *new_server_uid, char *mbox_name, int *err_code)
{
EM_DEBUG_FUNC_BEGIN_SEC("old_server_uid[%s], new_server_uid[%s], mbox_name[%s]", old_server_uid, new_server_uid, mbox_name);
@@ -13553,9 +13913,9 @@ INTERNAL_FUNC int emstorage_update_pbd_activity(char *old_server_uid, char *new_
return false;
}
- sqlite3 *local_db_handle = emstorage_get_db_connection();
+ sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name);
- EMSTORAGE_START_WRITE_TRANSACTION(transaction, error);
+ EMSTORAGE_START_WRITE_TRANSACTION(multi_user_name, transaction, error);
memset(sql_query_string, 0x00, sizeof(sql_query_string));
SNPRINTF(sql_query_string, sizeof(sql_query_string),
"UPDATE mail_partial_body_activity_tbl SET server_mail_id = %s , mailbox_name=\'%s\' WHERE server_mail_id = %s ", new_server_uid, mbox_name, old_server_uid);
@@ -13575,7 +13935,7 @@ INTERNAL_FUNC int emstorage_update_pbd_activity(char *old_server_uid, char *new_
ret = true;
FINISH_OFF:
- EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
+ EMSTORAGE_FINISH_WRITE_TRANSACTION(multi_user_name, transaction, ret, error);
if (err_code != NULL)
*err_code = error;
@@ -13631,8 +13991,7 @@ FINISH_OFF:
#ifdef __FEATURE_BULK_DELETE_MOVE_UPDATE_REQUEST_OPTI__
-
-INTERNAL_FUNC int emstorage_update_read_mail_uid_by_server_uid(char *old_server_uid, char *new_server_uid, char *mbox_name, int *err_code)
+INTERNAL_FUNC int emstorage_update_read_mail_uid_by_server_uid(char *multi_user_name, char *old_server_uid, char *new_server_uid, char *mbox_name, int *err_code)
{
EM_DEBUG_FUNC_BEGIN();
int rc = -1;
@@ -13651,8 +14010,8 @@ INTERNAL_FUNC int emstorage_update_read_mail_uid_by_server_uid(char *old_server_
EM_DEBUG_LOG_SEC("old_server_uid[%s], new_server_uid[%s], mbox_name[%s]", old_server_uid, new_server_uid, mbox_name);
- sqlite3 *local_db_handle = emstorage_get_db_connection();
- EMSTORAGE_START_WRITE_TRANSACTION(transaction, error);
+ sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name);
+ EMSTORAGE_START_WRITE_TRANSACTION(multi_user_name, transaction, error);
SNPRINTF(sql_query_string, sizeof(sql_query_string),
@@ -13676,7 +14035,7 @@ INTERNAL_FUNC int emstorage_update_read_mail_uid_by_server_uid(char *old_server_
ret = true;
FINISH_OFF:
- EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
+ EMSTORAGE_FINISH_WRITE_TRANSACTION(multi_user_name, transaction, ret, error);
if (err_code != NULL)
*err_code = error;
@@ -13701,8 +14060,7 @@ FINISH_OFF:
* SELECT local_uid, s_uid from mail_read_mail_uid_tbl where local_uid in (12, 13, 56, 78);
* @return This function returns true on success or false on failure.
*/
-
-INTERNAL_FUNC int emstorage_get_id_set_from_mail_ids(char *mail_ids, email_id_set_t** idset, int *id_set_count, int *err_code)
+INTERNAL_FUNC int emstorage_get_id_set_from_mail_ids(char *multi_user_name, char *mail_ids, email_id_set_t** idset, int *id_set_count, int *err_code)
{
EM_DEBUG_FUNC_BEGIN();
EM_PROFILE_BEGIN(EmStorageGetIdSetFromMailIds);
@@ -13728,7 +14086,7 @@ INTERNAL_FUNC int emstorage_get_id_set_from_mail_ids(char *mail_ids, email_id_se
return false;
}
- sqlite3 *local_db_handle = emstorage_get_db_connection();
+ sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name);
SNPRINTF(sql_query_string, space_left_in_query_buffer, "SELECT local_uid, server_uid FROM mail_read_mail_uid_tbl WHERE local_uid in (%s) ORDER BY server_uid", mail_ids);
@@ -13798,14 +14156,14 @@ FINISH_OFF:
#endif
-INTERNAL_FUNC int emstorage_delete_triggers_from_lucene()
+INTERNAL_FUNC int emstorage_delete_triggers_from_lucene(char *multi_user_name)
{
EM_DEBUG_FUNC_BEGIN();
int ret = true, transaction = true;
int error = EMAIL_ERROR_NONE;
char sql_query_string[QUERY_SIZE] = {0, };
- sqlite3 *local_db_handle = emstorage_get_db_connection();
- EMSTORAGE_START_WRITE_TRANSACTION(transaction, error);
+ sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name);
+ EMSTORAGE_START_WRITE_TRANSACTION(multi_user_name, transaction, error);
SNPRINTF(sql_query_string, sizeof(sql_query_string), "DROP TRIGGER triggerDelete;");
error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string);
@@ -13831,13 +14189,13 @@ INTERNAL_FUNC int emstorage_delete_triggers_from_lucene()
ret = true;
FINISH_OFF:
- EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
+ EMSTORAGE_FINISH_WRITE_TRANSACTION(multi_user_name, transaction, ret, error);
EM_DEBUG_FUNC_END("ret [%d]", ret);
return ret;
}
-INTERNAL_FUNC int emstorage_update_tag_id(int old_filter_id, int new_filter_id, int *err_code)
+INTERNAL_FUNC int emstorage_update_tag_id(char *multi_user_name, int old_filter_id, int new_filter_id, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("new_filter_id[%d], old_filter_id[%d]", new_filter_id, old_filter_id);
int ret = false;
@@ -13852,9 +14210,9 @@ INTERNAL_FUNC int emstorage_update_tag_id(int old_filter_id, int new_filter_id,
return false;
}
- sqlite3 *local_db_handle = emstorage_get_db_connection();
+ sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name);
- EMSTORAGE_START_WRITE_TRANSACTION(transaction, error);
+ EMSTORAGE_START_WRITE_TRANSACTION(multi_user_name, transaction, error);
SNPRINTF(sql_query_string, sizeof(sql_query_string),
"UPDATE mail_tbl SET tag_id=%d WHERE tag_id=%d ", new_filter_id, old_filter_id);
@@ -13868,7 +14226,7 @@ INTERNAL_FUNC int emstorage_update_tag_id(int old_filter_id, int new_filter_id,
ret = true;
FINISH_OFF:
- EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
+ EMSTORAGE_FINISH_WRITE_TRANSACTION(multi_user_name, transaction, ret, error);
if (err_code != NULL)
*err_code = error;
@@ -13877,7 +14235,7 @@ FINISH_OFF:
return ret;
}
-INTERNAL_FUNC int emstorage_filter_mails_by_rule(int account_id, int dest_mailbox_id, int dest_mailbox_type, int reset, emstorage_rule_tbl_t *rule, int ** filtered_mail_id_list, int *count_of_mails, int *err_code)
+INTERNAL_FUNC int emstorage_filter_mails_by_rule(char *multi_user_name, int account_id, int dest_mailbox_id, int dest_mailbox_type, int reset, emstorage_rule_tbl_t *rule, int ** filtered_mail_id_list, int *count_of_mails, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("account_id[%d], dest_mailbox_id[%d] rule[%p], filtered_mail_id_list[%p], count_of_mails[%p], err_code[%p]", account_id, dest_mailbox_id, rule, filtered_mail_id_list, count_of_mails, err_code);
@@ -13894,7 +14252,7 @@ INTERNAL_FUNC int emstorage_filter_mails_by_rule(int account_id, int dest_mailbo
int tag_id = rule->rule_id;
char **result = NULL, *where_pararaph = NULL;
char sql_query_string[QUERY_SIZE] = {0, };
- sqlite3 *local_db_handle = emstorage_get_db_connection();
+ sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name);
SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT mail_id FROM mail_tbl ");
@@ -14045,8 +14403,7 @@ FINISH_OFF:
}
#define EMAIL_SLOT_UNIT 25
-
-INTERNAL_FUNC int emstorage_set_mail_slot_size(int account_id, int mailbox_id, int new_slot_size, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_set_mail_slot_size(char *multi_user_name, int account_id, int mailbox_id, int new_slot_size, int transaction, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("account_id[%d], mailbox_id[%p] new_slot_size[%d], err_code[%p]", account_id, mailbox_id, new_slot_size, err_code);
int ret = false, err = EMAIL_ERROR_NONE;
@@ -14054,9 +14411,9 @@ INTERNAL_FUNC int emstorage_set_mail_slot_size(int account_id, int mailbox_id, i
char *where_pararaph = NULL;
char sql_query_string[QUERY_SIZE] = {0, };
int and = 0;
- sqlite3 *local_db_handle = emstorage_get_db_connection();
+ sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name);
- EMSTORAGE_START_WRITE_TRANSACTION(transaction, err);
+ EMSTORAGE_START_WRITE_TRANSACTION(multi_user_name, transaction, err);
if (new_slot_size > 0)
SNPRINTF(sql_query_string, sizeof(sql_query_string), "UPDATE mail_box_tbl SET mail_slot_size = %d ", new_slot_size);
@@ -14094,7 +14451,7 @@ INTERNAL_FUNC int emstorage_set_mail_slot_size(int account_id, int mailbox_id, i
SNPRINTF(where_pararaph + EM_SAFE_STRLEN(where_pararaph), where_pararaph_length - EM_SAFE_STRLEN(where_pararaph), " %s total_mail_count_on_server > mail_slot_size ", (and ? "AND" : "WHERE"));
if (strlen(sql_query_string) + EM_SAFE_STRLEN(where_pararaph) < QUERY_SIZE) /* prevent 34363 */
- strncat(sql_query_string, where_pararaph, EM_SAFE_STRLEN(where_pararaph));
+ strcat(sql_query_string, where_pararaph);
else {
EM_DEBUG_EXCEPTION("Query buffer overflowed !!!");
err = EMAIL_ERROR_OUT_OF_MEMORY;
@@ -14111,7 +14468,7 @@ INTERNAL_FUNC int emstorage_set_mail_slot_size(int account_id, int mailbox_id, i
ret = true;
FINISH_OFF:
- EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, err);
+ EMSTORAGE_FINISH_WRITE_TRANSACTION(multi_user_name, transaction, ret, err);
EM_SAFE_FREE(where_pararaph);
@@ -14122,7 +14479,7 @@ FINISH_OFF:
return ret;
}
-INTERNAL_FUNC int emstorage_add_meeting_request(int account_id, int input_mailbox_id, email_meeting_request_t* meeting_req, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_add_meeting_request(char *multi_user_name, int account_id, int input_mailbox_id, email_meeting_request_t* meeting_req, int transaction, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("account_id[%d], input_mailbox_id[%d], meeting_req[%p], transaction[%d], err_code[%p]", account_id, input_mailbox_id, meeting_req, transaction, err_code);
@@ -14144,8 +14501,8 @@ INTERNAL_FUNC int emstorage_add_meeting_request(int account_id, int input_mailbo
int col_index = 0;
time_t temp_unix_time = 0;
- sqlite3 *local_db_handle = emstorage_get_db_connection();
- EMSTORAGE_START_WRITE_TRANSACTION(transaction, error);
+ sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name);
+ EMSTORAGE_START_WRITE_TRANSACTION(multi_user_name, transaction, error);
SNPRINTF(sql_query_string, sizeof(sql_query_string),
"INSERT INTO mail_meeting_tbl VALUES "
@@ -14227,7 +14584,7 @@ INTERNAL_FUNC int emstorage_add_meeting_request(int account_id, int input_mailbo
ret = true;
FINISH_OFF:
- EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
+ EMSTORAGE_FINISH_WRITE_TRANSACTION(multi_user_name, transaction, ret, error);
if (hStmt != NULL) {
rc = sqlite3_finalize(hStmt);
if (rc != SQLITE_OK) {
@@ -14243,7 +14600,7 @@ FINISH_OFF:
return ret;
}
-INTERNAL_FUNC int emstorage_query_meeting_request(const char *conditional_clause, email_meeting_request_t **output_meeting_req, int *output_result_count, int transaction)
+INTERNAL_FUNC int emstorage_query_meeting_request(char *multi_user_name, const char *conditional_clause, email_meeting_request_t **output_meeting_req, int *output_result_count, int transaction)
{
EM_DEBUG_FUNC_BEGIN("conditional_clause[%s] output_meeting_req[%p] output_result_count[%p] transaction[%d]", conditional_clause, output_meeting_req, output_result_count, transaction);
@@ -14268,7 +14625,7 @@ INTERNAL_FUNC int emstorage_query_meeting_request(const char *conditional_clause
col_index = _field_count_of_table[CREATE_TABLE_MAIL_MEETING_TBL];
EM_DEBUG_LOG("col_index [%d]", col_index);
- local_db_handle = emstorage_get_db_connection();
+ local_db_handle = emstorage_get_db_connection(multi_user_name);
EMSTORAGE_START_READ_TRANSACTION(transaction);
@@ -14319,10 +14676,10 @@ INTERNAL_FUNC int emstorage_query_meeting_request(const char *conditional_clause
FINISH_OFF:
- if (result)
+ if(result)
sqlite3_free_table(result);
- if (err == EMAIL_ERROR_NONE) {
+ if (err == EMAIL_ERROR_NONE) {
if (p_temp_meeting_req)
*output_meeting_req = p_temp_meeting_req;
*output_result_count = count;
@@ -14332,14 +14689,13 @@ FINISH_OFF:
EMSTORAGE_FINISH_READ_TRANSACTION(transaction);
- if (local_db_handle)
- sqlite3_db_release_memory(local_db_handle);
+// sqlite3_db_release_memory(local_db_handle);
EM_DEBUG_FUNC_END("err [%d]", err);
return err;
}
-INTERNAL_FUNC int emstorage_get_meeting_request(int mail_id, email_meeting_request_t ** meeting_req, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_get_meeting_request(char *multi_user_name, int mail_id, email_meeting_request_t ** meeting_req, int transaction, int *err_code)
{
EM_DEBUG_FUNC_BEGIN();
@@ -14354,7 +14710,7 @@ INTERNAL_FUNC int emstorage_get_meeting_request(int mail_id, email_meeting_reque
SNPRINTF(conditional_clause, QUERY_SIZE, " WHERE mail_id = %d", mail_id);
EM_DEBUG_LOG("conditional_clause [%s]", conditional_clause);
- if((error = emstorage_query_meeting_request(conditional_clause, meeting_req, &count, transaction)) != EMAIL_ERROR_NONE) {
+ if((error = emstorage_query_meeting_request(multi_user_name, conditional_clause, meeting_req, &count, transaction)) != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("emstorage_query_meeting_request failed. [%d]", error);
goto FINISH_OFF;
}
@@ -14383,8 +14739,7 @@ FINISH_OFF:
return ret;
}
-
-INTERNAL_FUNC int emstorage_update_meeting_request(email_meeting_request_t* meeting_req, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_update_meeting_request(char *multi_user_name, email_meeting_request_t* meeting_req, int transaction, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("meeting_req[%p], transaction[%d], err_code[%p]", meeting_req, transaction, err_code);
@@ -14402,8 +14757,8 @@ INTERNAL_FUNC int emstorage_update_meeting_request(email_meeting_request_t* meet
return false;
}
- sqlite3 *local_db_handle = emstorage_get_db_connection();
- EMSTORAGE_START_WRITE_TRANSACTION(transaction, error);
+ sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name);
+ EMSTORAGE_START_WRITE_TRANSACTION(multi_user_name, transaction, error);
memset(sql_query_string, 0x00, sizeof(sql_query_string));
SNPRINTF(sql_query_string, sizeof(sql_query_string),
@@ -14473,7 +14828,7 @@ INTERNAL_FUNC int emstorage_update_meeting_request(email_meeting_request_t* meet
FINISH_OFF:
- EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
+ EMSTORAGE_FINISH_WRITE_TRANSACTION(multi_user_name, transaction, ret, error);
if (hStmt != NULL) {
rc = sqlite3_finalize(hStmt);
@@ -14490,7 +14845,7 @@ FINISH_OFF:
return ret;
}
-INTERNAL_FUNC int emstorage_delete_meeting_request(int account_id, int mail_id, int input_mailbox_id, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_delete_meeting_request(char *multi_user_name, int account_id, int mail_id, int input_mailbox_id, int transaction, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("account_id[%d], mail_id[%d], input_mailbox_id[%d], transaction[%d], err_code[%p]", account_id, mail_id, input_mailbox_id, transaction, err_code);
@@ -14507,8 +14862,8 @@ INTERNAL_FUNC int emstorage_delete_meeting_request(int account_id, int mail_id,
int and = false;
char sql_query_string[QUERY_SIZE] = {0, };
- sqlite3 *local_db_handle = emstorage_get_db_connection();
- EMSTORAGE_START_WRITE_TRANSACTION(transaction, error);
+ sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name);
+ EMSTORAGE_START_WRITE_TRANSACTION(multi_user_name, transaction, error);
SNPRINTF(sql_query_string, sizeof(sql_query_string), "DELETE FROM mail_meeting_tbl ");
@@ -14533,7 +14888,7 @@ INTERNAL_FUNC int emstorage_delete_meeting_request(int account_id, int mail_id,
ret = true;
FINISH_OFF:
- EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
+ EMSTORAGE_FINISH_WRITE_TRANSACTION(multi_user_name, transaction, ret, error);
if (err_code)
*err_code = error;
@@ -14555,8 +14910,7 @@ INTERNAL_FUNC void emstorage_free_meeting_request(email_meeting_request_t *meeti
EM_DEBUG_FUNC_END();
}
-
-INTERNAL_FUNC int emstorage_get_overflowed_mail_id_list(int account_id, int input_mailbox_id, int input_mailbox_type, int mail_slot_size, int **mail_id_list, int *mail_id_count, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_get_overflowed_mail_id_list(char *multi_user_name, int account_id, int input_mailbox_id, int mail_slot_size, int **mail_id_list, int *mail_id_count, int transaction, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("account_id [%d], input_mailbox_id [%d], mail_slot_size [%d], mail_id_list [%p], mail_id_count [%p], transaction [%d], err_code [%p]", account_id, input_mailbox_id, mail_slot_size, mail_id_list, mail_id_count, transaction, err_code);
EM_PROFILE_BEGIN(profile_emstorage_get_overflowed_mail_id_list);
@@ -14575,11 +14929,11 @@ INTERNAL_FUNC int emstorage_get_overflowed_mail_id_list(int account_id, int inpu
return false;
}
- SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT mail_id FROM mail_tbl WHERE account_id = %d AND mailbox_id = %d AND mailbox_type = %d ORDER BY date_time DESC LIMIT %d, 10000", account_id, input_mailbox_id, input_mailbox_type, mail_slot_size);
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT mail_id FROM mail_tbl WHERE account_id = %d AND mailbox_id = %d ORDER BY date_time DESC LIMIT %d, 10000", account_id, input_mailbox_id, mail_slot_size);
EM_DEBUG_LOG_SEC("query[%s].", sql_query_string);
- sqlite3 *local_db_handle = emstorage_get_db_connection();
+ sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name);
EMSTORAGE_START_READ_TRANSACTION(transaction);
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, &result_mail_id_count, 0, NULL), rc);
@@ -14634,8 +14988,7 @@ FINISH_OFF:
return ret;
}
-
-INTERNAL_FUNC int emstorage_get_thread_id_by_mail_id(int mail_id, int *thread_id, int *err_code)
+INTERNAL_FUNC int emstorage_get_thread_id_by_mail_id(char *multi_user_name, int mail_id, int *thread_id, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("mail_id[%d], thread_id[%p], err_code[%p]", mail_id, thread_id, err_code);
@@ -14652,7 +15005,7 @@ INTERNAL_FUNC int emstorage_get_thread_id_by_mail_id(int mail_id, int *thread_id
return false;
}
- sqlite3 *local_db_handle = emstorage_get_db_connection();
+ sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name);
memset(sql_query_string, 0, QUERY_SIZE);
SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT thread_id FROM mail_tbl WHERE mail_id = %d", mail_id);
@@ -14685,9 +15038,22 @@ FINISH_OFF:
return ret;
}
-INTERNAL_FUNC int emstorage_update_latest_thread_mail(int account_id, int mailbox_id, int thread_id, int *updated_thread_id, int latest_mail_id, int thread_item_count, int noti_type, int transaction, int *err_code)
-{
- EM_DEBUG_FUNC_BEGIN("account_id [%d], mailbox_id [%d], thread_id[%d], updated_thread_id[%p], latest_mail_id [%d], thread_item_count[%d], err_code[%p]", account_id, mailbox_id, thread_id, updated_thread_id, latest_mail_id, thread_item_count, err_code);
+INTERNAL_FUNC int emstorage_update_latest_thread_mail(char *multi_user_name,
+ int account_id,
+ int mailbox_id,
+ int mailbox_type,
+ int thread_id,
+ int *updated_thread_id,
+ int latest_mail_id,
+ int thread_item_count,
+ int noti_type,
+ int transaction,
+ int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("account_id [%d], mailbox_id [%d], thread_id[%d], updated_thread_id[%p], "
+ "latest_mail_id [%d], thread_item_count[%d], err_code[%p]",
+ account_id, mailbox_id, thread_id, updated_thread_id,
+ latest_mail_id, thread_item_count, err_code);
int rc = -1, ret = false;
int err = EMAIL_ERROR_NONE;
@@ -14702,7 +15068,7 @@ INTERNAL_FUNC int emstorage_update_latest_thread_mail(int account_id, int mailbo
return false;
}
- sqlite3 *local_db_handle = emstorage_get_db_connection();
+ sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name);
if (thread_item_count == 0 && latest_mail_id == 0) {
memset(sql_query_string, 0, QUERY_SIZE);
@@ -14731,10 +15097,9 @@ INTERNAL_FUNC int emstorage_update_latest_thread_mail(int account_id, int mailbo
sqlite3_free_table(result);
}
- EMSTORAGE_START_WRITE_TRANSACTION(transaction, err);
+ EMSTORAGE_START_WRITE_TRANSACTION(multi_user_name, transaction, err);
- if (thread_item_count < 0)
- {
+ if (thread_item_count < 0) {
memset(sql_query_string, 0, QUERY_SIZE);
SNPRINTF(sql_query_string, sizeof(sql_query_string), "UPDATE mail_tbl SET thread_item_count = 0 WHERE account_id = %d AND thread_id = %d", account_id, thread_id);
EM_DEBUG_LOG_SEC("query[%s]", sql_query_string);
@@ -14776,7 +15141,7 @@ INTERNAL_FUNC int emstorage_update_latest_thread_mail(int account_id, int mailbo
ret = true;
FINISH_OFF:
- EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, err);
+ EMSTORAGE_FINISH_WRITE_TRANSACTION(multi_user_name, transaction, ret, err);
if (thread_id != latest_mail_id)
{
@@ -14811,7 +15176,7 @@ FINISH_OFF:
return ret;
}
-INTERNAL_FUNC int emstorage_update_thread_id_of_mail(int account_id, int mailbox_id, int mail_id, int thread_id, int thread_item_count, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_update_thread_id_of_mail(char *multi_user_name, int account_id, int mailbox_id, int mail_id, int thread_id, int thread_item_count, int transaction, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("account_id [%d], mailbox_id [%d], mail_id[%d], thread_id[%d], thread_item_count[%d], err_code[%p]", account_id, mailbox_id, mail_id, thread_id, thread_item_count, err_code);
@@ -14826,9 +15191,9 @@ INTERNAL_FUNC int emstorage_update_thread_id_of_mail(int account_id, int mailbox
return false;
}
- sqlite3 *local_db_handle = emstorage_get_db_connection();
+ sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name);
- EMSTORAGE_START_WRITE_TRANSACTION(transaction, err);
+ EMSTORAGE_START_WRITE_TRANSACTION(multi_user_name, transaction, err);
memset(sql_query_string, 0, QUERY_SIZE);
SNPRINTF(sql_query_string, sizeof(sql_query_string), "UPDATE mail_tbl SET thread_item_count = %d, thread_id = %d WHERE account_id = %d AND mail_id = %d", thread_item_count, thread_id, account_id, mail_id);
@@ -14841,7 +15206,7 @@ INTERNAL_FUNC int emstorage_update_thread_id_of_mail(int account_id, int mailbox
ret = true;
FINISH_OFF:
- EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, err);
+ EMSTORAGE_FINISH_WRITE_TRANSACTION(multi_user_name, transaction, ret, err);
if (err_code != NULL)
*err_code = err;
@@ -14850,12 +15215,6 @@ FINISH_OFF:
return ret;
}
-
-INTERNAL_FUNC void emstorage_flush_db_cache()
-{
- /* sqlite3_release_memory(-1); */
-}
-
#ifdef __FEATURE_LOCAL_ACTIVITY__
/**
* emstorage_add_activity - Add Email Local activity during OFFLINE mode
@@ -14880,10 +15239,11 @@ INTERNAL_FUNC int emstorage_add_activity(emstorage_activity_tbl_t* local_activit
return false;
}
- sqlite3 *local_db_handle = emstorage_get_db_connection();
- memset(sql_query_string, 0x00 , sizeof(sql_query_string));
- EMSTORAGE_START_WRITE_TRANSACTION(transaction, error);
+ sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name);
+ EMSTORAGE_START_WRITE_TRANSACTION(multi_user_name, transaction, error);
+
+ memset(sql_query_string, 0x00 , sizeof(sql_query_string));
SNPRINTF(sql_query_string, sizeof(sql_query_string), "INSERT INTO mail_local_activity_tbl VALUES (?, ?, ?, ?, ?, ?, ?)");
EM_DEBUG_LOG(">>>>> ACTIVITY ID [ %d ] ", local_activity->activity_id);
@@ -14922,7 +15282,7 @@ INTERNAL_FUNC int emstorage_add_activity(emstorage_activity_tbl_t* local_activit
ret = true;
FINISH_OFF:
- EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
+ EMSTORAGE_FINISH_WRITE_TRANSACTION(multi_user_name, transaction, ret, error);
if (hStmt != NULL) {
rc = sqlite3_finalize(hStmt);
@@ -14966,7 +15326,7 @@ INTERNAL_FUNC int emstorage_get_activity(int account_id, int activityid, emstora
return false;
}
- sqlite3 *local_db_handle = emstorage_get_db_connection();
+ sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name);
EMSTORAGE_START_READ_TRANSACTION(transaction);
@@ -15078,7 +15438,7 @@ INTERNAL_FUNC int emstorage_get_next_activity_id(int *activity_id, int *err_code
return false;
}
- sqlite3 *local_db_handle = emstorage_get_db_connection();
+ sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name);
/* increase unique id */
@@ -15110,7 +15470,7 @@ INTERNAL_FUNC int emstorage_get_next_activity_id(int *activity_id, int *err_code
}
-INTERNAL_FUNC int emstorage_get_activity_id_list(int account_id, int ** activity_id_list, int *activity_id_count, int lowest_activity_type, int highest_activity_type, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_get_activity_id_list(char *multi_user_name, int account_id, int ** activity_id_list, int *activity_id_count, int lowest_activity_type, int highest_activity_type, int transaction, int *err_code)
{
EM_DEBUG_FUNC_BEGIN();
@@ -15130,7 +15490,7 @@ INTERNAL_FUNC int emstorage_get_activity_id_list(int account_id, int ** activity
int *activity_ids = NULL;
int col_index = 0;
char **result = NULL;
- sqlite3 *local_db_handle = emstorage_get_db_connection();
+ sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name);
EMSTORAGE_START_READ_TRANSACTION(transaction);
memset(sql_query_string, 0x00, sizeof(sql_query_string));
@@ -15237,8 +15597,8 @@ INTERNAL_FUNC int emstorage_delete_local_activity(emstorage_activity_tbl_t* loca
int query_and = 0;
int query_where = 0;
char sql_query_string[8192] = { 0x00, };
- sqlite3 *local_db_handle = emstorage_get_db_connection();
- EMSTORAGE_START_WRITE_TRANSACTION(transaction, error);
+ sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name);
+ EMSTORAGE_START_WRITE_TRANSACTION(multi_user_name, transaction, error);
memset(sql_query_string, 0x00, sizeof(sql_query_string));
@@ -15299,7 +15659,7 @@ INTERNAL_FUNC int emstorage_delete_local_activity(emstorage_activity_tbl_t* loca
ret = true;
FINISH_OFF:
- EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
+ EMSTORAGE_FINISH_WRITE_TRANSACTION(multi_user_name, transaction, ret, error);
if (hStmt != NULL) {
rc = sqlite3_finalize(hStmt);
@@ -15542,6 +15902,7 @@ static int _make_filter_rule_string(email_list_filter_rule_t *input_list_filter_
mod_field_name_string = em_malloc(sizeof(char) * length_field_name);
if (mod_field_name_string == NULL) {
EM_DEBUG_EXCEPTION("em_malloc failed");
+ EM_SAFE_FREE(temp_field_name_string);
ret = EMAIL_ERROR_OUT_OF_MEMORY;
goto FINISH_OFF;
}
@@ -15549,6 +15910,7 @@ static int _make_filter_rule_string(email_list_filter_rule_t *input_list_filter_
mod_value_string = em_malloc(sizeof(char) * length_value);
if (mod_value_string == NULL) {
EM_DEBUG_EXCEPTION("em_malloc failed");
+ EM_SAFE_FREE(temp_field_name_string);
ret = EMAIL_ERROR_OUT_OF_MEMORY;
goto FINISH_OFF;
}
@@ -15606,7 +15968,7 @@ FINISH_OFF:
return ret;
}
-static int _make_filter_attach_rule_string(email_list_filter_rule_attach_t *input_list_filter_rule, char **output_string)
+static int _make_filter_attach_rule_string(char *multi_user_name, email_list_filter_rule_attach_t *input_list_filter_rule, char **output_string)
{
EM_DEBUG_FUNC_BEGIN("input_list_filter_rule [%p], output_string [%p]", input_list_filter_rule, output_string);
@@ -15649,7 +16011,8 @@ static int _make_filter_attach_rule_string(email_list_filter_rule_attach_t *inpu
goto FINISH_OFF;
}
- local_db_handle = emstorage_get_db_connection();
+ local_db_handle = emstorage_get_db_connection(multi_user_name);
+
EMSTORAGE_START_READ_TRANSACTION(true);
SNPRINTF(sql_query_string, QUERY_SIZE, "SELECT mail_id FROM mail_attachment_tbl %s", result_rule_string);
@@ -15683,7 +16046,7 @@ static int _make_filter_attach_rule_string(email_list_filter_rule_attach_t *inpu
sqlite3_free_table(result);
EMSTORAGE_FINISH_READ_TRANSACTION(true);
- sqlite3_db_release_memory(local_db_handle);
+// sqlite3_db_release_memory(local_db_handle);
query_size = (10 * count) + strlen("mail_id IN ( ) ");
@@ -15711,7 +16074,7 @@ FINISH_OFF:
return error;
}
-static int _make_filter_fts_rule_string(email_list_filter_rule_fts_t *input_list_filter_rule, char **output_string)
+static int _make_filter_fts_rule_string(char *multi_user_name, email_list_filter_rule_fts_t *input_list_filter_rule, char **output_string)
{
EM_DEBUG_FUNC_BEGIN("input_list_filter_rule [%p], output_string [%p]", input_list_filter_rule, output_string);
char *field_name_string = NULL;
@@ -15752,7 +16115,8 @@ static int _make_filter_fts_rule_string(email_list_filter_rule_fts_t *input_list
goto FINISH_OFF;
}
- local_db_handle = emstorage_get_db_connection();
+ local_db_handle = emstorage_get_db_connection(multi_user_name);
+
EMSTORAGE_START_READ_TRANSACTION(true);
SNPRINTF(sql_query_string, QUERY_SIZE, "SELECT mail_id FROM mail_text_tbl %s", result_rule_string);
@@ -15787,7 +16151,7 @@ static int _make_filter_fts_rule_string(email_list_filter_rule_fts_t *input_list
sqlite3_free_table(result);
EMSTORAGE_FINISH_READ_TRANSACTION(true);
- sqlite3_db_release_memory(local_db_handle);
+// sqlite3_db_release_memory(local_db_handle);
query_size = (10 * count) + strlen("mail_id IN ( ) ");
@@ -15814,7 +16178,7 @@ FINISH_OFF:
return error;
}
-static int _make_order_rule_string(email_list_sorting_rule_t *input_sorting_rule, char **output_string) {
+static int _make_order_rule_string(char *multi_user_name, email_list_sorting_rule_t *input_sorting_rule, char **output_string) {
EM_DEBUG_FUNC_BEGIN("input_sorting_rule [%p], output_string [%p]", input_sorting_rule, output_string);
char result_rule_string[QUERY_SIZE] = { 0 , };
@@ -15828,10 +16192,11 @@ static int _make_order_rule_string(email_list_sorting_rule_t *input_sorting_rule
char *tmp_str2 = NULL;
char query_per_account[QUERY_SIZE] = { 0 , };
- if (input_sorting_rule->force_boolean_check)
+ if(input_sorting_rule->force_boolean_check) {
SNPRINTF(result_rule_string, QUERY_SIZE, "%s = 0 ", emcore_get_mail_field_name_by_attribute_type(input_sorting_rule->target_attribute));
+ }
else
- SNPRINTF(result_rule_string, QUERY_SIZE, "%s", emcore_get_mail_field_name_by_attribute_type(input_sorting_rule->target_attribute));
+ EM_SAFE_STRCPY(result_rule_string, emcore_get_mail_field_name_by_attribute_type(input_sorting_rule->target_attribute));
switch (input_sorting_rule->sort_order) {
case EMAIL_SORT_ORDER_ASCEND :
@@ -15867,7 +16232,7 @@ static int _make_order_rule_string(email_list_sorting_rule_t *input_sorting_rule
break;
case EMAIL_SORT_ORDER_TO_CCBCC_ALL :
- if (!emstorage_get_account_list(&count, &account_tbl_array, true, false, NULL)) {
+ if (!emstorage_get_account_list(multi_user_name, &count, &account_tbl_array, true, false, NULL)) {
EM_DEBUG_EXCEPTION("emstorage_get_account_list failed");
goto FINISH_OFF;
}
@@ -15935,7 +16300,7 @@ FINISH_OFF:
return ret;
}
-INTERNAL_FUNC int emstorage_write_conditional_clause_for_getting_mail_list(email_list_filter_t *input_filter_list, int input_filter_count, email_list_sorting_rule_t *input_sorting_rule_list, int input_sorting_rule_count, int input_start_index, int input_limit_count, char **output_conditional_clause)
+INTERNAL_FUNC int emstorage_write_conditional_clause_for_getting_mail_list(char *multi_user_name, email_list_filter_t *input_filter_list, int input_filter_count, email_list_sorting_rule_t *input_sorting_rule_list, int input_sorting_rule_count, int input_start_index, int input_limit_count, char **output_conditional_clause)
{
EM_DEBUG_FUNC_BEGIN("input_filter_list [%p], input_filter_count[%d], input_sorting_rule_list[%p], input_sorting_rule_count [%d], input_start_index [%d], input_limit_count [%d], output_conditional_clause [%p]", input_filter_list, input_filter_count, input_sorting_rule_list, input_sorting_rule_count, input_start_index, input_limit_count, output_conditional_clause);
int ret = EMAIL_ERROR_NONE;
@@ -15970,12 +16335,12 @@ INTERNAL_FUNC int emstorage_write_conditional_clause_for_getting_mail_list(email
case EMAIL_LIST_FILTER_ITEM_RULE_FTS :
EM_DEBUG_LOG_DEV("[%d]list_filter_item_type is EMAIL_LIST_FILTER_ITEM_RULE_FTS", i);
- _make_filter_fts_rule_string(&(input_filter_list[i].list_filter_item.rule_fts), &result_string_for_a_item);
+ _make_filter_fts_rule_string(multi_user_name, &(input_filter_list[i].list_filter_item.rule_fts), &result_string_for_a_item);
break;
case EMAIL_LIST_FILTER_ITEM_RULE_ATTACH :
EM_DEBUG_LOG_DEV("[%d]list_filter_item_type is EMAIL_LIST_FILTER_ITEM_RULE_ATTACH", i);
- _make_filter_attach_rule_string(&(input_filter_list[i].list_filter_item.rule_attach), &result_string_for_a_item);
+ _make_filter_attach_rule_string(multi_user_name, &(input_filter_list[i].list_filter_item.rule_attach), &result_string_for_a_item);
break;
case EMAIL_LIST_FILTER_ITEM_OPERATOR :
@@ -16030,7 +16395,7 @@ INTERNAL_FUNC int emstorage_write_conditional_clause_for_getting_mail_list(email
strcat(conditional_clause_string, "ORDER BY ");
for ( i = 0; i < input_sorting_rule_count; i++) {
- if( (ret = _make_order_rule_string(&input_sorting_rule_list[i], &result_string_for_a_item)) != EMAIL_ERROR_NONE) {
+ if( (ret = _make_order_rule_string(multi_user_name, &input_sorting_rule_list[i], &result_string_for_a_item)) != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("_make_order_rule_string failed. [%d]", ret);
goto FINISH_OFF;
}
@@ -16105,7 +16470,7 @@ INTERNAL_FUNC int emstorage_free_list_filter(email_list_filter_t **input_filter_
return err;
}
-INTERNAL_FUNC int emstorage_add_certificate(emstorage_certificate_tbl_t *certificate, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_add_certificate(char *multi_user_name, emstorage_certificate_tbl_t *certificate, int transaction, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("certificate:[%p], transaction:[%d], err_code:[%p]", certificate, transaction, err_code);
@@ -16124,9 +16489,10 @@ INTERNAL_FUNC int emstorage_add_certificate(emstorage_certificate_tbl_t *certifi
#ifdef __FEATURE_SUPPORT_PRIVATE_CERTIFICATE__
char cert_password_file_name[MAX_PW_FILE_NAME_LENGTH];
#endif
- sqlite3 *local_db_handle = emstorage_get_db_connection();
- EMSTORAGE_START_WRITE_TRANSACTION(transaction, error);
+ sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name);
+
+ EMSTORAGE_START_WRITE_TRANSACTION(multi_user_name, transaction, error);
char *sql = "SELECT max(rowid) FROM mail_certificate_tbl;";
char **result = NULL;
@@ -16193,7 +16559,7 @@ INTERNAL_FUNC int emstorage_add_certificate(emstorage_certificate_tbl_t *certifi
ret = true;
FINISH_OFF:
- EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
+ EMSTORAGE_FINISH_WRITE_TRANSACTION(multi_user_name, transaction, ret, error);
if (hStmt != NULL) {
rc = sqlite3_finalize(hStmt);
if (rc != SQLITE_OK) {
@@ -16253,7 +16619,7 @@ FINISH_OFF:
return ret;
}
-INTERNAL_FUNC int emstorage_get_certificate_list(int *select_num, emstorage_certificate_tbl_t **certificate_list, int transaction, int with_password, int *err_code)
+INTERNAL_FUNC int emstorage_get_certificate_list(char *multi_user_name, int *select_num, emstorage_certificate_tbl_t **certificate_list, int transaction, int with_password, int *err_code)
{
EM_DEBUG_FUNC_BEGIN();
@@ -16270,7 +16636,7 @@ INTERNAL_FUNC int emstorage_get_certificate_list(int *select_num, emstorage_cert
return false;
}
- sqlite3 *local_db_handle = emstorage_get_db_connection();
+ sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name);
EMSTORAGE_START_READ_TRANSACTION(transaction);
char sql_query_string[QUERY_SIZE] = {0, };
@@ -16390,7 +16756,7 @@ FINISH_OFF:
return ret;
}
-INTERNAL_FUNC int emstorage_get_certificate_by_email_address(char *email_address, emstorage_certificate_tbl_t **certificate, int transaction, int with_password, int *err_code)
+INTERNAL_FUNC int emstorage_get_certificate_by_email_address(char *multi_user_name, char *email_address, emstorage_certificate_tbl_t **certificate, int transaction, int with_password, int *err_code)
{
EM_DEBUG_FUNC_BEGIN_SEC("email_address[%s], certificate[%p], transaction[%d], err_code[%p]", email_address, certificate, transaction, err_code);
@@ -16411,7 +16777,8 @@ INTERNAL_FUNC int emstorage_get_certificate_by_email_address(char *email_address
#ifdef __FEATURE_SUPPORT_PRIVATE_CERTIFICATE__
char cert_password_file_name[MAX_PW_FILE_NAME_LENGTH];
#endif
- sqlite3 *local_db_handle = emstorage_get_db_connection();
+
+ sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name);
EMSTORAGE_START_READ_TRANSACTION(transaction);
/* Make query string */
@@ -16498,7 +16865,7 @@ FINISH_OFF:
return ret;
}
-INTERNAL_FUNC int emstorage_get_certificate_by_index(int index, emstorage_certificate_tbl_t **certificate, int transaction, int with_password, int *err_code)
+INTERNAL_FUNC int emstorage_get_certificate_by_index(char *multi_user_name, int index, emstorage_certificate_tbl_t **certificate, int transaction, int with_password, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("index[%d], certificate[%p], transaction[%d], err_code[%p]", index, certificate, transaction, err_code);
@@ -16519,7 +16886,8 @@ INTERNAL_FUNC int emstorage_get_certificate_by_index(int index, emstorage_certif
#ifdef __FEATURE_SUPPORT_PRIVATE_CERTIFICATE__
char cert_password_file_name[MAX_PW_FILE_NAME_LENGTH];
#endif
- sqlite3 *local_db_handle = emstorage_get_db_connection();
+
+ sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name);
EMSTORAGE_START_READ_TRANSACTION(transaction);
/* Make query string */
@@ -16607,7 +16975,7 @@ FINISH_OFF:
return ret;
}
-INTERNAL_FUNC int emstorage_delete_certificate(int certificate_id, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_delete_certificate(char *multi_user_name, int certificate_id, int transaction, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("certificate_id[%d], transaction[%d], err_code[%p]", certificate_id, transaction, err_code);
@@ -16620,8 +16988,8 @@ INTERNAL_FUNC int emstorage_delete_certificate(int certificate_id, int transacti
int rc = -1, ret = false;
int error = EMAIL_ERROR_NONE;
- sqlite3 *local_db_handle = emstorage_get_db_connection();
- EMSTORAGE_START_WRITE_TRANSACTION(transaction, error);
+ sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name);
+ EMSTORAGE_START_WRITE_TRANSACTION(multi_user_name, transaction, error);
/* TODO : delete password files - file names can be obtained from db or a rule that makes a name */
char sql_query_string[QUERY_SIZE] = {0, };
@@ -16653,7 +17021,7 @@ INTERNAL_FUNC int emstorage_delete_certificate(int certificate_id, int transacti
ret = true;
FINISH_OFF:
- EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
+ EMSTORAGE_FINISH_WRITE_TRANSACTION(multi_user_name, transaction, ret, error);
if (err_code != NULL)
*err_code = error;
@@ -16662,7 +17030,7 @@ FINISH_OFF:
return ret;
}
-INTERNAL_FUNC int emstorage_update_certificate(int certificate_id, emstorage_certificate_tbl_t *certificate, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_update_certificate(char *multi_user_name, int certificate_id, emstorage_certificate_tbl_t *certificate, int transaction, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("certificate_id[%d], certificate[%p], transaction[%d], err_code[%p]", certificate_id, certificate, transaction, err_code);
@@ -16681,8 +17049,9 @@ INTERNAL_FUNC int emstorage_update_certificate(int certificate_id, emstorage_cer
#ifdef __FEATURE_SUPPORT_PRIVATE_CERTIFICATE__
char cert_password_file_name[MAX_PW_FILE_NAME_LENGTH];
#endif
- sqlite3 *local_db_handle = emstorage_get_db_connection();
- EMSTORAGE_START_WRITE_TRANSACTION(transaction, error);
+
+ sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name);
+ EMSTORAGE_START_WRITE_TRANSACTION(multi_user_name, transaction, error);
SNPRINTF(sql_query_string, sizeof(sql_query_string),
"UPDATE mail_certificate_tbl SET"
@@ -16734,7 +17103,7 @@ INTERNAL_FUNC int emstorage_update_certificate(int certificate_id, emstorage_cer
ret = true;
FINISH_OFF:
- EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
+ EMSTORAGE_FINISH_WRITE_TRANSACTION(multi_user_name, transaction, ret, error);
if (hStmt != NULL) {
rc = sqlite3_finalize(hStmt);
@@ -16757,7 +17126,7 @@ FINISH_OFF:
}
/* Tasks --------------------------------------------------------------------------*/
-INTERNAL_FUNC int emstorage_add_task(email_task_type_t input_task_type, email_task_priority_t input_task_priority, char *input_task_parameter, int input_task_parameter_length, int input_transaction, int *output_task_id)
+INTERNAL_FUNC int emstorage_add_task(char *multi_user_name, email_task_type_t input_task_type, email_task_priority_t input_task_priority, char *input_task_parameter, int input_task_parameter_length, int input_transaction, int *output_task_id)
{
EM_DEBUG_FUNC_BEGIN("input_task_type [%d] input_task_priority[%p], input_task_parameter[%p] input_task_parameter_length[%d] input_transaction[%d] output_task_id[%p]", input_task_type, input_task_priority, input_task_parameter, input_task_parameter_length, input_transaction, output_task_id);
int ret = 0;
@@ -16776,8 +17145,8 @@ INTERNAL_FUNC int emstorage_add_task(email_task_type_t input_task_type, email_ta
return EMAIL_ERROR_INVALID_PARAM;
}
- local_db_handle = emstorage_get_db_connection();
- EMSTORAGE_START_WRITE_TRANSACTION(input_transaction, err);
+ local_db_handle = emstorage_get_db_connection(multi_user_name);
+ EMSTORAGE_START_WRITE_TRANSACTION(multi_user_name, input_transaction, err);
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql, &result, NULL, NULL, NULL), rc);
EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {err = EMAIL_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
@@ -16830,7 +17199,7 @@ INTERNAL_FUNC int emstorage_add_task(email_task_type_t input_task_type, email_ta
ret = (err == EMAIL_ERROR_NONE);
FINISH_OFF:
- EMSTORAGE_FINISH_WRITE_TRANSACTION(input_transaction, ret, err);
+ EMSTORAGE_FINISH_WRITE_TRANSACTION(multi_user_name, input_transaction, ret, err);
if (hStmt != NULL) {
rc = sqlite3_finalize(hStmt);
@@ -16844,7 +17213,7 @@ FINISH_OFF:
return err;
}
-INTERNAL_FUNC int emstorage_delete_task(int task_id, int transaction)
+INTERNAL_FUNC int emstorage_delete_task(char *multi_user_name, int task_id, int transaction)
{
EM_DEBUG_FUNC_BEGIN("task_id[%d], transaction[%d]", task_id, transaction);
int ret = false;
@@ -16858,9 +17227,9 @@ INTERNAL_FUNC int emstorage_delete_task(int task_id, int transaction)
return EMAIL_ERROR_INVALID_PARAM;
}
- local_db_handle = emstorage_get_db_connection();
+ local_db_handle = emstorage_get_db_connection(multi_user_name);
- EMSTORAGE_START_WRITE_TRANSACTION(transaction, err);
+ EMSTORAGE_START_WRITE_TRANSACTION(multi_user_name, transaction, err);
SNPRINTF(sql_query_string, sizeof(sql_query_string), "DELETE FROM mail_task_tbl WHERE task_id = %d", task_id);
err = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string);
@@ -16872,20 +17241,21 @@ INTERNAL_FUNC int emstorage_delete_task(int task_id, int transaction)
ret = true;
FINISH_OFF:
- EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, err);
+ EMSTORAGE_FINISH_WRITE_TRANSACTION(multi_user_name, transaction, ret, err);
EM_DEBUG_FUNC_END("err [%d]", err);
return err;
}
-INTERNAL_FUNC int emstorage_update_task_status(int task_id, email_task_status_type_t task_status, int transaction)
+INTERNAL_FUNC int emstorage_update_task_status(char *multi_user_name, int task_id, email_task_status_type_t task_status, int transaction)
{
EM_DEBUG_FUNC_BEGIN("task_id[%d] task_status[%d] transaction[%d]", task_id, task_status, transaction);
int ret = false;
int err = EMAIL_ERROR_NONE;
char sql_query_string[QUERY_SIZE] = {0, };
- sqlite3 *local_db_handle = emstorage_get_db_connection();
- EMSTORAGE_START_WRITE_TRANSACTION(transaction, err);
+
+ sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name);
+ EMSTORAGE_START_WRITE_TRANSACTION(multi_user_name, transaction, err);
SNPRINTF(sql_query_string, sizeof(sql_query_string),
"UPDATE mail_task_tbl SET"
@@ -16902,15 +17272,21 @@ INTERNAL_FUNC int emstorage_update_task_status(int task_id, email_task_status_ty
ret = true;
FINISH_OFF:
- EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, err);
+ EMSTORAGE_FINISH_WRITE_TRANSACTION(multi_user_name, transaction, ret, err);
EM_DEBUG_FUNC_END("err [%d]", err);
return err;
}
-INTERNAL_FUNC int emstorage_query_task(const char *input_conditional_clause, const char *input_ordering_clause, email_task_t **output_task_list, int *output_task_count)
+INTERNAL_FUNC int emstorage_query_task(char *multi_user_name,
+ const char *input_conditional_clause,
+ const char *input_ordering_clause,
+ email_task_t **output_task_list,
+ int *output_task_count)
{
- EM_DEBUG_FUNC_BEGIN("input_conditional_clause[%p], input_ordering_clause [%p], output_task_list[%p], output_task_count[%d]", input_conditional_clause, input_ordering_clause, output_task_list, output_task_count);
+ EM_DEBUG_FUNC_BEGIN("input_conditional_clause[%p], input_ordering_clause [%p], "
+ "output_task_list[%p], output_task_count[%d]",
+ input_conditional_clause, input_ordering_clause, output_task_list, output_task_count);
int i = 0, count = 0, rc = -1;
int cur_query = 0;
int field_index = 0;
@@ -16925,9 +17301,10 @@ INTERNAL_FUNC int emstorage_query_task(const char *input_conditional_clause, con
EM_IF_NULL_RETURN_VALUE(input_conditional_clause, false);
EM_IF_NULL_RETURN_VALUE(output_task_count, false);
- local_db_handle = emstorage_get_db_connection();
+ local_db_handle = emstorage_get_db_connection(multi_user_name);
- SNPRINTF_OFFSET(sql_query_string, cur_query, QUERY_SIZE, "SELECT COUNT(*) FROM mail_task_tbl %s", input_conditional_clause);
+ SNPRINTF_OFFSET(sql_query_string, cur_query, QUERY_SIZE,
+ "SELECT COUNT(*) FROM mail_task_tbl %s", input_conditional_clause);
EM_DEBUG_LOG_SEC("emstorage_query_mail_list : query[%s].", sql_query_string);
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, NULL, NULL, NULL), rc);
@@ -16945,7 +17322,8 @@ INTERNAL_FUNC int emstorage_query_task(const char *input_conditional_clause, con
goto FINISH_OFF;
}
- SNPRINTF_OFFSET(sql_query_string, cur_query, QUERY_SIZE, "SELECT %s FROM mail_task_tbl %s %s", field_list, input_conditional_clause, input_ordering_clause);
+ SNPRINTF_OFFSET(sql_query_string, cur_query, QUERY_SIZE,
+ "SELECT %s FROM mail_task_tbl %s %s", field_list, input_conditional_clause, input_ordering_clause);
EM_DEBUG_LOG_SEC("emstorage_query_mail_list : query[%s].", sql_query_string);
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc);
@@ -16958,7 +17336,7 @@ INTERNAL_FUNC int emstorage_query_task(const char *input_conditional_clause, con
EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {err = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("sqlite3_step fail:%d", rc));
- if (rc == SQLITE_DONE) {
+ if (rc == SQLITE_DONE) {
EM_DEBUG_EXCEPTION("no task found...");
err = EMAIL_ERROR_TASK_NOT_FOUND;
count = 0;
@@ -16989,17 +17367,20 @@ INTERNAL_FUNC int emstorage_query_task(const char *input_conditional_clause, con
}
FINISH_OFF:
+
if (err == EMAIL_ERROR_NONE) {
if (output_task_list)
*output_task_list = task_item_from_tbl;
*output_task_count = count;
+ } else {
+ if (task_item_from_tbl) {
+ for (i = 0; i < count; i++)
+ EM_SAFE_FREE(task_item_from_tbl[i].task_parameter);
+
+ free(task_item_from_tbl);
+ }
}
- else {
- for (i = 0; i < count; i++) {
- EM_SAFE_FREE(task_item_from_tbl[i].task_parameter);
- }
- EM_SAFE_FREE(task_item_from_tbl);
- }
+
if (hStmt != NULL) {
rc = sqlite3_finalize(hStmt);
hStmt = NULL;
@@ -17009,12 +17390,11 @@ FINISH_OFF:
}
}
-
EM_DEBUG_FUNC_END("err [%d]", err);
return err;
}
-INTERNAL_FUNC int emstorage_check_and_update_server_uid_by_message_id(int account_id, email_mailbox_type_e input_mailbox_type, char *message_id, char *server_uid, int *mail_id)
+INTERNAL_FUNC int emstorage_check_and_update_server_uid_by_message_id(char *multi_user_name, int account_id, email_mailbox_type_e input_mailbox_type, char *message_id, char *server_uid, int *mail_id)
{
EM_DEBUG_FUNC_BEGIN("account_id:[%d], mailbox_type:[%d], message_id:[%s], server_uid:[%s]", account_id, input_mailbox_type, message_id, server_uid);
int err = EMAIL_ERROR_NONE;
@@ -17032,7 +17412,7 @@ INTERNAL_FUNC int emstorage_check_and_update_server_uid_by_message_id(int accoun
char *where_pararaph = NULL;
char sql_query_string[QUERY_SIZE] = {0, };
char **result = NULL;
- sqlite3 *local_db_handle = emstorage_get_db_connection();
+ sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name);
SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT mail_id from mail_tbl ");
@@ -17098,7 +17478,7 @@ FINISH_OFF:
/* Tasks --------------------------------------------------------------------------*/
#ifdef __FEATURE_WIFI_AUTO_DOWNLOAD__
-INTERNAL_FUNC int emstorage_add_auto_download_activity(email_event_auto_download *local_activity, int *activity_id, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_add_auto_download_activity(char *multi_user_name, email_event_auto_download *local_activity, int *activity_id, int transaction, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("local_activity[%p], activity_id[%p], transaction[%d], err_code[%p]", local_activity, activity_id, transaction, err_code);
@@ -17116,8 +17496,10 @@ INTERNAL_FUNC int emstorage_add_auto_download_activity(email_event_auto_download
char sql_query_string[QUERY_SIZE] = {0, };
DB_STMT hStmt = NULL;
- sqlite3 *local_db_handle = emstorage_get_db_connection();
- EMSTORAGE_START_WRITE_TRANSACTION(transaction, error);
+
+ sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name);
+ EMSTORAGE_START_WRITE_TRANSACTION(multi_user_name, transaction, error);
+
memset(sql_query_string, 0x00, sizeof(sql_query_string));
SNPRINTF(sql_query_string, sizeof(sql_query_string),
"INSERT INTO mail_auto_download_activity_tbl VALUES "
@@ -17128,6 +17510,7 @@ INTERNAL_FUNC int emstorage_add_auto_download_activity(email_event_auto_download
",?" /* Local Mail ID */
",?" /* Server mail ID */
",?" /* Mailbox ID*/
+ ",?" /* Multi USER NAME */
") ");
char *sql = "SELECT max(rowid) FROM mail_auto_download_activity_tbl;";
@@ -17164,6 +17547,7 @@ INTERNAL_FUNC int emstorage_add_auto_download_activity(email_event_auto_download
_bind_stmt_field_data_int(hStmt, i++, local_activity->mail_id);
_bind_stmt_field_data_int(hStmt, i++, local_activity->server_mail_id);
_bind_stmt_field_data_int(hStmt, i++, local_activity->mailbox_id);
+ _bind_stmt_field_data_string(hStmt, i++, (char *)local_activity->multi_user_name, 0, MAX_USER_NAME_LENGTH);
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
@@ -17176,7 +17560,7 @@ INTERNAL_FUNC int emstorage_add_auto_download_activity(email_event_auto_download
ret = true;
FINISH_OFF:
- EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
+ EMSTORAGE_FINISH_WRITE_TRANSACTION(multi_user_name, transaction, ret, error);
if (hStmt != NULL) {
rc = sqlite3_finalize(hStmt);
hStmt = NULL;
@@ -17194,7 +17578,7 @@ FINISH_OFF:
}
-INTERNAL_FUNC int emstorage_delete_auto_download_activity(int account_id, int mail_id, int activity_id, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_delete_auto_download_activity(char *multi_user_name, int account_id, int mail_id, int activity_id, int transaction, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("account_id[%d], mail_id[%d] , activity_id[%d], transaction[%d], err_code[%p]", account_id, mail_id, activity_id, transaction, err_code);
@@ -17210,9 +17594,9 @@ INTERNAL_FUNC int emstorage_delete_auto_download_activity(int account_id, int ma
int ret = false;
int error = EMAIL_ERROR_NONE;
char sql_query_string[QUERY_SIZE] = {0, };
- sqlite3 *local_db_handle = emstorage_get_db_connection();
+ sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name);
- EMSTORAGE_START_WRITE_TRANSACTION(transaction, error);
+ EMSTORAGE_START_WRITE_TRANSACTION(multi_user_name, transaction, error);
memset(sql_query_string, 0x00, sizeof(sql_query_string));
if (activity_id == 0)
@@ -17239,7 +17623,7 @@ INTERNAL_FUNC int emstorage_delete_auto_download_activity(int account_id, int ma
ret = true;
FINISH_OFF:
- EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
+ EMSTORAGE_FINISH_WRITE_TRANSACTION(multi_user_name, transaction, ret, error);
if (err_code != NULL)
*err_code = error;
@@ -17248,8 +17632,7 @@ FINISH_OFF:
return ret;
}
-
-INTERNAL_FUNC int emstorage_delete_all_auto_download_activity(int account_id, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_delete_all_auto_download_activity(char *multi_user_name, int account_id, int transaction, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("account_id[%d], transaction[%d], err_code[%p]", account_id, transaction, err_code);
@@ -17264,8 +17647,10 @@ INTERNAL_FUNC int emstorage_delete_all_auto_download_activity(int account_id, in
int ret = false;
int error = EMAIL_ERROR_NONE;
char sql_query_string[QUERY_SIZE] = {0, };
- sqlite3 *local_db_handle = emstorage_get_db_connection();
- EMSTORAGE_START_WRITE_TRANSACTION(transaction, error);
+
+ sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name);
+
+ EMSTORAGE_START_WRITE_TRANSACTION(multi_user_name, transaction, error);
memset(sql_query_string, 0x00, sizeof(sql_query_string));
SNPRINTF(sql_query_string, sizeof(sql_query_string), "DELETE FROM mail_auto_download_activity_tbl WHERE account_id = %d", account_id);
@@ -17287,7 +17672,7 @@ INTERNAL_FUNC int emstorage_delete_all_auto_download_activity(int account_id, in
ret = true;
FINISH_OFF:
- EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
+ EMSTORAGE_FINISH_WRITE_TRANSACTION(multi_user_name, transaction, ret, error);
if (err_code != NULL)
*err_code = error;
@@ -17297,7 +17682,7 @@ FINISH_OFF:
}
-INTERNAL_FUNC int emstorage_delete_auto_download_activity_by_mailbox(int account_id, int mailbox_id, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_delete_auto_download_activity_by_mailbox(char *multi_user_name, int account_id, int mailbox_id, int transaction, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("account_id[%d], mailbox_id[%d], transaction[%d], err_code[%p]", account_id, mailbox_id, transaction, err_code);
@@ -17312,8 +17697,10 @@ INTERNAL_FUNC int emstorage_delete_auto_download_activity_by_mailbox(int account
int ret = false;
int error = EMAIL_ERROR_NONE;
char sql_query_string[QUERY_SIZE] = {0, };
- sqlite3 *local_db_handle = emstorage_get_db_connection();
- EMSTORAGE_START_WRITE_TRANSACTION(transaction, error);
+
+ sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name);
+
+ EMSTORAGE_START_WRITE_TRANSACTION(multi_user_name, transaction, error);
memset(sql_query_string, 0x00, sizeof(sql_query_string));
SNPRINTF(sql_query_string, sizeof(sql_query_string), "DELETE FROM mail_auto_download_activity_tbl WHERE account_id = %d AND mailbox_id = %d", account_id, mailbox_id);
@@ -17335,7 +17722,7 @@ INTERNAL_FUNC int emstorage_delete_auto_download_activity_by_mailbox(int account
ret = true;
FINISH_OFF:
- EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
+ EMSTORAGE_FINISH_WRITE_TRANSACTION(multi_user_name, transaction, ret, error);
if (err_code != NULL)
*err_code = error;
@@ -17345,7 +17732,7 @@ FINISH_OFF:
}
-INTERNAL_FUNC int emstorage_get_auto_download_activity(int account_id, int input_mailbox_id, email_event_auto_download **event_start, int *count, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_get_auto_download_activity(char *multi_user_name, int account_id, int input_mailbox_id, email_event_auto_download **event_start, int *count, int transaction, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("account_id[%d], event_start[%p], err_code[%p]", account_id, event_start, err_code);
@@ -17366,7 +17753,7 @@ INTERNAL_FUNC int emstorage_get_auto_download_activity(int account_id, int input
email_event_auto_download *event_list = NULL;
char sql_query_string[QUERY_SIZE] = {0, };
- sqlite3 *local_db_handle = emstorage_get_db_connection();
+ sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name);
EMSTORAGE_START_READ_TRANSACTION(transaction);
@@ -17458,7 +17845,7 @@ FINISH_OFF:
}
-INTERNAL_FUNC int emstorage_get_auto_download_activity_count(int *activity_count, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_get_auto_download_activity_count(char *multi_user_name, int *activity_count, int transaction, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("activity_count[%p], err_code[%p]", activity_count, err_code);
@@ -17475,7 +17862,7 @@ INTERNAL_FUNC int emstorage_get_auto_download_activity_count(int *activity_count
DB_STMT hStmt = NULL;
char sql_query_string[QUERY_SIZE] = {0, };
- sqlite3 *local_db_handle = emstorage_get_db_connection();
+ sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name);
EMSTORAGE_START_READ_TRANSACTION(transaction);
memset(sql_query_string, 0x00, sizeof(sql_query_string));
@@ -17521,7 +17908,7 @@ FINISH_OFF:
}
-INTERNAL_FUNC int emstorage_get_auto_download_account_list(int **account_list, int *count, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_get_auto_download_account_list(char *multi_user_name, int **account_list, int *count, int transaction, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("account_list[%p], count[%p] err_code[%p]", account_list, count, err_code);
@@ -17540,7 +17927,7 @@ INTERNAL_FUNC int emstorage_get_auto_download_account_list(int **account_list, i
int *result_account_list = NULL;
DB_STMT hStmt = NULL;
char sql_query_string[QUERY_SIZE] = {0, };
- sqlite3 *local_db_handle = emstorage_get_db_connection();
+ sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name);
EMSTORAGE_START_READ_TRANSACTION(transaction);
@@ -17619,7 +18006,7 @@ FINISH_OFF:
}
-INTERNAL_FUNC int emstorage_get_auto_download_mailbox_list(int account_id, int **mailbox_list, int *count, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_get_auto_download_mailbox_list(char *multi_user_name, int account_id, int **mailbox_list, int *count, int transaction, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("account_id[%d], mailbox_list[%p], count[%p] err_code[%p]", account_id, mailbox_list, count, err_code);
@@ -17638,7 +18025,7 @@ INTERNAL_FUNC int emstorage_get_auto_download_mailbox_list(int account_id, int *
DB_STMT hStmt = NULL;
char sql_query_string[QUERY_SIZE] = {0, };
- sqlite3 *local_db_handle = emstorage_get_db_connection();
+ sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name);
EMSTORAGE_START_READ_TRANSACTION(transaction);
@@ -17721,7 +18108,7 @@ FINISH_OFF:
}
-INTERNAL_FUNC int emstorage_get_auto_download_activity_count_by_mailbox(int account_id, int input_mailbox_id, int *activity_count, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_get_auto_download_activity_count_by_mailbox(char *multi_user_name, int account_id, int input_mailbox_id, int *activity_count, int transaction, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("account_id[%d], activity_count[%p], err_code[%p]", account_id, activity_count, err_code);
@@ -17737,7 +18124,8 @@ INTERNAL_FUNC int emstorage_get_auto_download_activity_count_by_mailbox(int acco
int error = EMAIL_ERROR_NONE;
char sql_query_string[QUERY_SIZE] = {0, };
DB_STMT hStmt = NULL;
- sqlite3 *local_db_handle = emstorage_get_db_connection();
+
+ sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name);
EMSTORAGE_START_READ_TRANSACTION(transaction);
memset(sql_query_string, 0x00, sizeof(sql_query_string));
@@ -17781,7 +18169,7 @@ FINISH_OFF:
}
-INTERNAL_FUNC int emstorage_update_auto_download_activity(char *old_server_uid, char *new_server_uid, char *mailbox_name, int mailbox_id, int *err_code)
+INTERNAL_FUNC int emstorage_update_auto_download_activity(char *multi_user_name, char *old_server_uid, char *new_server_uid, char *mailbox_name, int mailbox_id, int *err_code)
{
EM_DEBUG_FUNC_BEGIN_SEC("old_server_uid[%s], new_server_uid[%s], mailbox_id[%d]", old_server_uid, new_server_uid, mailbox_id);
@@ -17796,9 +18184,9 @@ INTERNAL_FUNC int emstorage_update_auto_download_activity(char *old_server_uid,
return false;
}
- sqlite3 *local_db_handle = emstorage_get_db_connection();
+ sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name);
- EMSTORAGE_START_WRITE_TRANSACTION(transaction, error);
+ EMSTORAGE_START_WRITE_TRANSACTION(multi_user_name, transaction, error);
memset(sql_query_string, 0x00, sizeof(sql_query_string));
if (mailbox_id > 0)
@@ -17824,7 +18212,7 @@ INTERNAL_FUNC int emstorage_update_auto_download_activity(char *old_server_uid,
FINISH_OFF:
- EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
+ EMSTORAGE_FINISH_WRITE_TRANSACTION(multi_user_name, transaction, ret, error);
if (err_code != NULL)
*err_code = error;
@@ -17893,7 +18281,7 @@ FINISH_OFF:
return 0;
}
-static int emstorage_get_column_information_from_table(const char *input_table_name, GList **output_column_info)
+static int emstorage_get_column_information_from_table(char *multi_user_name, const char *input_table_name, GList **output_column_info)
{
EM_DEBUG_FUNC_BEGIN("input_table_name[%p] output_column_info[%p]", input_table_name, output_column_info);
int err = EMAIL_ERROR_NONE;
@@ -17901,7 +18289,7 @@ static int emstorage_get_column_information_from_table(const char *input_table_n
char *error_message_from_sqlite = NULL;
char sql_query_string[QUERY_SIZE] = {0, };
GList *new_list = NULL;
- sqlite3 *local_db_handle = emstorage_get_db_connection();
+ sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name);
SNPRINTF(sql_query_string, QUERY_SIZE, "pragma table_info(%s);", input_table_name);
@@ -17921,7 +18309,7 @@ static int emstorage_get_column_information_from_table(const char *input_table_n
return err;
}
-static int emstorage_create_renamed_table(char **input_full_query, int input_query_index, char *input_source_table_name, char *input_new_table_name)
+static int emstorage_create_renamed_table(char *multi_user_name, char **input_full_query, int input_query_index, char *input_source_table_name, char *input_new_table_name)
{
EM_DEBUG_FUNC_BEGIN("input_full_query [%p] input_query_index[%d] input_source_table_name[%p] input_new_table_name[%p]", input_full_query, input_query_index, input_source_table_name, input_new_table_name);
int error = EMAIL_ERROR_NONE;
@@ -17935,7 +18323,7 @@ static int emstorage_create_renamed_table(char **input_full_query, int input_qu
goto FINISH_OFF;
}
- local_db_handle = emstorage_get_db_connection();
+ local_db_handle = emstorage_get_db_connection(multi_user_name);
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, "BEGIN;", NULL, NULL, NULL), rc);
EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {goto FINISH_OFF; }, ("SQL(BEGIN EXCLUSIVE) exec fail:%d -%s", rc, sqlite3_errmsg(local_db_handle)));
@@ -17959,7 +18347,7 @@ FINISH_OFF:
return error;
}
-static int emstorage_add_column(char *input_table_name, email_column_info_t *input_new_column)
+static int emstorage_add_column(char *multi_user_name, char *input_table_name, email_column_info_t *input_new_column)
{
EM_DEBUG_FUNC_BEGIN("input_table_name[%p] input_new_column[%p]", input_table_name, input_new_column);
int error = EMAIL_ERROR_NONE;
@@ -17973,7 +18361,7 @@ static int emstorage_add_column(char *input_table_name, email_column_info_t *inp
goto FINISH_OFF;
}
- local_db_handle = emstorage_get_db_connection();
+ local_db_handle = emstorage_get_db_connection(multi_user_name);
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, "BEGIN;", NULL, NULL, NULL), rc);
EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {goto FINISH_OFF; }, ("SQL(BEGIN EXCLUSIVE) exec fail:%d -%s", rc, sqlite3_errmsg(local_db_handle)));
@@ -17992,7 +18380,7 @@ FINISH_OFF:
return error;
}
-static int emstorage_drop_table(char *input_table_name)
+static int emstorage_drop_table(char *multi_user_name, char *input_table_name)
{
EM_DEBUG_FUNC_BEGIN("input_table_name[%p]", input_table_name);
int error = EMAIL_ERROR_NONE;
@@ -18006,7 +18394,7 @@ static int emstorage_drop_table(char *input_table_name)
goto FINISH_OFF;
}
- local_db_handle = emstorage_get_db_connection();
+ local_db_handle = emstorage_get_db_connection(multi_user_name);
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, "BEGIN;", NULL, NULL, NULL), rc);
EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {goto FINISH_OFF; }, ("SQL(BEGIN EXCLUSIVE) exec fail:%d -%s", rc, sqlite3_errmsg(local_db_handle)));
@@ -18037,7 +18425,7 @@ gint glist_compare_column_name(gconstpointer old_column_info, gconstpointer new_
return EM_SAFE_STRCMP((char*)left_one->column_name, (char*)right_one->column_name);
}
-INTERNAL_FUNC int emstorage_update_db_table_schema()
+INTERNAL_FUNC int emstorage_update_db_table_schema(char *multi_user_name)
{
EM_DEBUG_FUNC_BEGIN();
int i = 0;
@@ -18100,15 +18488,15 @@ INTERNAL_FUNC int emstorage_update_db_table_schema()
EM_DEBUG_LOG("table [%s] new_table [%s]", table_names[i][0], table_names[i][1]);
if (EM_SAFE_STRLEN(table_names[i][0]) && EM_SAFE_STRLEN(table_names[i][1])) {
/* Check existing of _new table */
- emstorage_drop_table(table_names[i][1]);
- error = emstorage_create_renamed_table(create_table_query, i, table_names[i][0], table_names[i][1]);
+ emstorage_drop_table(multi_user_name, table_names[i][1]);
+ error = emstorage_create_renamed_table(multi_user_name, create_table_query, i, table_names[i][0], table_names[i][1]);
if (error != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("emstorage_create_renamed_table failed [%d]", error);
goto FINISH_OFF;
}
- emstorage_get_column_information_from_table(table_names[i][0], &column_list_of_old_table);
- emstorage_get_column_information_from_table(table_names[i][1], &column_list_of_new_table);
+ emstorage_get_column_information_from_table(multi_user_name, table_names[i][0], &column_list_of_old_table);
+ emstorage_get_column_information_from_table(multi_user_name, table_names[i][1], &column_list_of_new_table);
/* Compare fields and add new field */
for (j = 0; j < g_list_length(column_list_of_new_table); j++) {
@@ -18116,11 +18504,11 @@ INTERNAL_FUNC int emstorage_update_db_table_schema()
found_data = g_list_find_custom(column_list_of_old_table, (gconstpointer)new_column_info, glist_compare_column_name);
if (found_data == NULL) {
/* add new field*/
- emstorage_add_column(table_names[i][0], new_column_info);
+ emstorage_add_column(multi_user_name, table_names[i][0], new_column_info);
}
}
- emstorage_drop_table(table_names[i][1]);
+ emstorage_drop_table(multi_user_name, table_names[i][1]);
}
else
EM_DEBUG_LOG("Skipped");
@@ -18162,8 +18550,6 @@ FINISH_OFF:
EM_DEBUG_FUNC_END("error [%d]", error);
return error;
}
-
-
#endif /* __FEATURE_UPDATE_DB_TABLE_SCHEMA__ */
/*EOF*/
diff --git a/email-core/email-storage/include/email-storage.h b/email-core/email-storage/include/email-storage.h
index 679f537..bef9c21 100755
--- a/email-core/email-storage/include/email-storage.h
+++ b/email-core/email-storage/include/email-storage.h
@@ -55,6 +55,8 @@ extern "C"
#define MAX_INTEGER_LENGTH 5 /* 32767 -> 5 bytes */
#define FILE_MAX_BUFFER_SIZE 16 * 1024 /* 16 Kbyte */
+#define DB_STMT sqlite3_stmt *
+
typedef struct
{
int mail_id;
@@ -131,6 +133,9 @@ typedef struct
char *certificate_path; /* Sepeifies the certificate path of private*/
email_cipher_type cipher_type; /* Sepeifies the encryption algorithm*/
email_digest_type digest_type; /* Sepeifies the digest algorithm*/
+
+ /* Multi user and KNOX options */
+ char *user_name; /* Specifies the container name */
} emstorage_account_tbl_t;
typedef struct
@@ -267,6 +272,7 @@ typedef struct
int eas_data_length;
char *eas_data;
char *pgp_password;
+ char *user_name;
} emstorage_mail_tbl_t;
/* mail_attachment_tbl entity */
@@ -362,7 +368,7 @@ INTERNAL_FUNC int emstorage_shm_file_init(const char *shm_file_name);
* em_db_open
* description : open db and register busy handler
*/
-INTERNAL_FUNC int em_db_open(sqlite3 **sqlite_handle, int *err_code);
+INTERNAL_FUNC int em_db_open(char *db_file_path, sqlite3 **sqlite_handle, int *err_code);
/*
* emstorage_db_open
@@ -371,7 +377,7 @@ INTERNAL_FUNC int em_db_open(sqlite3 **sqlite_handle, int *err_code);
* arguments :
* return :
*/
-INTERNAL_FUNC sqlite3* emstorage_db_open(int *err_code);
+INTERNAL_FUNC sqlite3* emstorage_db_open(char *multi_user_name, int *err_code);
/*
* emstorage_db_close
@@ -380,7 +386,7 @@ INTERNAL_FUNC sqlite3* emstorage_db_open(int *err_code);
* arguments :
* return :
*/
-INTERNAL_FUNC int emstorage_db_close(int *err_code);
+INTERNAL_FUNC int emstorage_db_close(char *multi_user_name, int *err_code);
/*
* emstorage_open
@@ -389,7 +395,7 @@ INTERNAL_FUNC int emstorage_db_close(int *err_code);
* arguments :
* return :
*/
-INTERNAL_FUNC int emstorage_open(int *err_code);
+INTERNAL_FUNC int emstorage_open(char *multi_user_name, int *err_code);
/*
* emstorage_close
@@ -407,8 +413,7 @@ INTERNAL_FUNC int emstorage_close(int *err_code);
* arguments :
* return :
*/
-INTERNAL_FUNC int emstorage_create_table(emstorage_create_db_type_t type, int *err_code);
-
+INTERNAL_FUNC int emstorage_create_table(char *multi_user_name, emstorage_create_db_type_t type, int *err_code);
INTERNAL_FUNC int emstorage_initialize_field_count();
@@ -421,8 +426,7 @@ INTERNAL_FUNC int emstorage_initialize_field_count();
* @remarks N/A
* @return This function returns true if there is no duplicated account. returns false and set error code if there are duplicated accounts or error
*/
-INTERNAL_FUNC int emstorage_check_duplicated_account(email_account_t *account, int transaction, int *err_code);
-
+INTERNAL_FUNC int emstorage_check_duplicated_account(char *multi_user_name, email_account_t *account, int transaction, int *err_code);
/**
* Get number of accounts from account table.
@@ -432,7 +436,7 @@ INTERNAL_FUNC int emstorage_check_duplicated_account(email_account_t *account, i
* @remarks N/A
* @return This function returns 0 on success or error code on failure.
*/
-INTERNAL_FUNC int emstorage_get_account_count(int *count, int transaction, int *err_code);
+INTERNAL_FUNC int emstorage_get_account_count(char *multi_user_name, int *count, int transaction, int *err_code);
/**
* Get account from account table.
@@ -444,7 +448,7 @@ INTERNAL_FUNC int emstorage_get_account_count(int *count, int transaction, int *
* @remarks N/A
* @return This function returns 0 on success or error code on failure.
*/
-INTERNAL_FUNC int emstorage_get_account_list(int *select_num, emstorage_account_tbl_t **account_list, int transaction, int with_password, int *err_code);
+INTERNAL_FUNC int emstorage_get_account_list(char *multi_user_name, int *select_num, emstorage_account_tbl_t **account_list, int transaction, int with_password, int *err_code);
/*
* emstorage_get_account_by_name
@@ -459,9 +463,7 @@ INTERNAL_FUNC int emstorage_get_account_list(int *select_num, emstorage_account_
* return :
*/
/* sowmya.kr, 281209 Adding signature to options in email_account_t changes */
-
-INTERNAL_FUNC int emstorage_get_account_by_id(int account_id, int pulloption, emstorage_account_tbl_t **account, int transaction, int *err_code);
-
+INTERNAL_FUNC int emstorage_get_account_by_id(char *multi_user_name, int account_id, int pulloption, emstorage_account_tbl_t **account, int transaction, int *err_code);
/*
* emstorage_get_password_length_of_account
@@ -473,9 +475,9 @@ INTERNAL_FUNC int emstorage_get_account_by_id(int account_id, int pulloption, em
* return :
*/
-INTERNAL_FUNC int emstorage_get_password_length_of_account(int account_id, int password_type, int *password_length, int* err_code);
+INTERNAL_FUNC int emstorage_get_password_length_of_account(char *multi_user_name, int account_id, int password_type, int *password_length, int* err_code);
-INTERNAL_FUNC int emstorage_update_account_password(int input_account_id, char *input_incoming_server_password, char *input_outgoing_server_password);
+INTERNAL_FUNC int emstorage_update_account_password(char *multi_user_name, int input_account_id, char *input_incoming_server_password, char *input_outgoing_server_password);
/*
* emstorage_update_account
@@ -486,11 +488,9 @@ INTERNAL_FUNC int emstorage_update_account_password(int input_account_id, char *
* account : buffer to hold selected account
* return :
*/
-INTERNAL_FUNC int emstorage_update_account(int account_id, emstorage_account_tbl_t *account, int transaction, int *err_code);
-
-
-INTERNAL_FUNC int emstorage_set_field_of_accounts_with_integer_value(int account_id, char *field_name, int value, int transaction);
+INTERNAL_FUNC int emstorage_update_account(char *multi_user_name, int account_id, emstorage_account_tbl_t *account, int transaction, int *err_code);
+INTERNAL_FUNC int emstorage_set_field_of_accounts_with_integer_value(char *multi_user_name, int account_id, char *field_name, int value, int transaction);
/*
* emstorage_get_sync_status_of_account
*
@@ -500,8 +500,7 @@ INTERNAL_FUNC int emstorage_set_field_of_accounts_with_integer_value(int account
* result_sync_status : sync status value
* return :
*/
-
-INTERNAL_FUNC int emstorage_get_sync_status_of_account(int account_id, int *result_sync_status,int *err_code);
+INTERNAL_FUNC int emstorage_get_sync_status_of_account(char *multi_user_name, int account_id, int *result_sync_status,int *err_code);
/*
* emstorage_update_sync_status_of_account
@@ -513,8 +512,8 @@ INTERNAL_FUNC int emstorage_get_sync_status_of_account(int account_id, int *resu
* sync_status : sync status value
* return :
*/
+INTERNAL_FUNC int emstorage_update_sync_status_of_account(char *multi_user_name, int account_id, email_set_type_t set_operator, int sync_status, int transaction, int *err_code);
-INTERNAL_FUNC int emstorage_update_sync_status_of_account(int account_id, email_set_type_t set_operator, int sync_status, int transaction, int *err_code);
/*
* emstorage_add_account
@@ -523,7 +522,7 @@ INTERNAL_FUNC int emstorage_update_sync_status_of_account(int account_id, email_
* arguments :
* return :
*/
-INTERNAL_FUNC int emstorage_add_account(emstorage_account_tbl_t *account, int transaction, int *err_code);
+INTERNAL_FUNC int emstorage_add_account(char *multi_user_name, emstorage_account_tbl_t *account, int transaction, int *err_code);
/*
* emstorage_delete_account
@@ -534,7 +533,7 @@ INTERNAL_FUNC int emstorage_add_account(emstorage_account_tbl_t *account, int tr
* account_id : account id to be deteted
* return :
*/
-INTERNAL_FUNC int emstorage_delete_account(int account_id, int transaction, int *err_code);
+INTERNAL_FUNC int emstorage_delete_account(char *multi_user_name, int account_id, int transaction, int *err_code);
/*
* emstorage_free_account
@@ -559,7 +558,7 @@ INTERNAL_FUNC int emstorage_free_account(emstorage_account_tbl_t **account_list,
* count : number of accounts
* return :
*/
-INTERNAL_FUNC int emstorage_get_mailbox_count(int account_id, int local_yn, int *count, int transaction, int *err_code);
+INTERNAL_FUNC int emstorage_get_mailbox_count(char *multi_user_name, int account_id, int local_yn, int *count, int transaction, int *err_code);
/*
* emstorage_get_mailbox
@@ -574,7 +573,7 @@ INTERNAL_FUNC int emstorage_get_mailbox_count(int account_id, int local_yn, int
* this buffer must be free after it has been used.
* return :
*/
-INTERNAL_FUNC int emstorage_get_mailbox_list(int account_id, int local_yn, email_mailbox_sort_type_t sort_type, int *select_num, emstorage_mailbox_tbl_t **mailbox_list, int transaction, int *err_code);
+INTERNAL_FUNC int emstorage_get_mailbox_list(char *multi_user_name, int account_id, int local_yn, email_mailbox_sort_type_t sort_type, int *select_num, emstorage_mailbox_tbl_t **mailbox_list, int transaction, int *err_code);
/*
* emstorage_get_child_mailbox_list
@@ -588,9 +587,7 @@ INTERNAL_FUNC int emstorage_get_mailbox_list(int account_id, int local_yn, email
* mailbox_list - out : list of mailboxes
* err_code - out : error code, if any
*/
-
-
-INTERNAL_FUNC int emstorage_get_child_mailbox_list(int account_id, char *parent_mailbox_name, int *select_num, emstorage_mailbox_tbl_t **mailbox_list, int transaction, int *err_code);
+INTERNAL_FUNC int emstorage_get_child_mailbox_list(char *multi_user_name, int account_id, char *parent_mailbox_name, int *select_num, emstorage_mailbox_tbl_t **mailbox_list, int transaction, int *err_code);
/*
* emstorage_get_mailbox_by_name
@@ -603,15 +600,23 @@ INTERNAL_FUNC int emstorage_get_child_mailbox_list(int account_id, char *parent_
* this buffer must be free after it has been used.
* return :
*/
-INTERNAL_FUNC int emstorage_get_mailbox_by_name(int account_id, int local_yn, char *mailbox_name, emstorage_mailbox_tbl_t **mailbox, int transaction, int *err_code);
-INTERNAL_FUNC int emstorage_get_mailbox_by_mailbox_type(int account_id, email_mailbox_type_e mailbox_type, emstorage_mailbox_tbl_t **mailbox, int transaction, int *err_code);
-INTERNAL_FUNC int emstorage_get_mailbox_by_id(int input_mailbox_id, emstorage_mailbox_tbl_t** output_mailbox);
-INTERNAL_FUNC int emstorage_get_mailbox_by_keyword(int account_id, char *keyword, emstorage_mailbox_tbl_t** result_mailbox, int * result_count, int transaction, int *err_code);
-INTERNAL_FUNC int emstorage_get_mailbox_list_ex(int account_id, int local_yn, int with_count, int *select_num, emstorage_mailbox_tbl_t **mailbox_list, int transaction, int *err_code);
-INTERNAL_FUNC int emstorage_get_mailbox_id_by_mailbox_type(int account_id, email_mailbox_type_e mailbox_type, int *mailbox_id, int transaction, int *err_code);
-INTERNAL_FUNC int emstorage_get_mailbox_name_by_mailbox_type(int account_id, email_mailbox_type_e mailbox_type, char **mailbox_name, int transaction, int *err_code);
-INTERNAL_FUNC int emstorage_update_mailbox_modifiable_yn(int account_id, int local_yn, char *mailbox_name, int modifiable_yn, int transaction, int *err_code);
-INTERNAL_FUNC int emstorage_update_mailbox_total_count(int account_id, int input_mailbox_id, int total_count_on_server, int transaction, int *err_code);
+INTERNAL_FUNC int emstorage_get_mailbox_by_name(char *multi_user_name, int account_id, int local_yn, char *mailbox_name, emstorage_mailbox_tbl_t **mailbox, int transaction, int *err_code);
+
+INTERNAL_FUNC int emstorage_get_mailbox_by_mailbox_type(char *multi_user_name, int account_id, email_mailbox_type_e mailbox_type, emstorage_mailbox_tbl_t **mailbox, int transaction, int *err_code);
+
+INTERNAL_FUNC int emstorage_get_mailbox_by_id(char *multi_user_name, int input_mailbox_id, emstorage_mailbox_tbl_t** output_mailbox);
+
+INTERNAL_FUNC int emstorage_get_mailbox_by_keyword(char *multi_user_name, int account_id, char *keyword, emstorage_mailbox_tbl_t** result_mailbox, int * result_count, int transaction, int *err_code);
+
+INTERNAL_FUNC int emstorage_get_mailbox_list_ex(char *multi_user_name, int account_id, int local_yn, int with_count, int *select_num, emstorage_mailbox_tbl_t **mailbox_list, int transaction, int *err_code);
+
+INTERNAL_FUNC int emstorage_get_mailbox_id_by_mailbox_type(char *multi_user_name, int account_id, email_mailbox_type_e mailbox_type, int *mailbox_id, int transaction, int *err_code);
+
+INTERNAL_FUNC int emstorage_get_mailbox_name_by_mailbox_type(char *multi_user_name, int account_id, email_mailbox_type_e mailbox_type, char **mailbox_name, int transaction, int *err_code);
+
+INTERNAL_FUNC int emstorage_update_mailbox_modifiable_yn(char *multi_user_name, int account_id, int local_yn, char *mailbox_name, int modifiable_yn, int transaction, int *err_code);
+
+INTERNAL_FUNC int emstorage_update_mailbox_total_count(char *multi_user_name, int account_id, int input_mailbox_id, int total_count_on_server, int transaction, int *err_code);
/*
@@ -624,7 +629,7 @@ INTERNAL_FUNC int emstorage_update_mailbox_total_count(int account_id, int input
* mailbox : buffer to hold selected local mailbox
* return :
*/
-INTERNAL_FUNC int emstorage_update_mailbox(int account_id, int local_yn, int input_mailbox_id, emstorage_mailbox_tbl_t *mailbox, int transaction, int *err_code);
+INTERNAL_FUNC int emstorage_update_mailbox(char *multi_user_name, int account_id, int local_yn, int input_mailbox_id, emstorage_mailbox_tbl_t *mailbox, int transaction, int *err_code);
/*
* emstorage_update_mailbox_type
@@ -633,7 +638,7 @@ INTERNAL_FUNC int emstorage_update_mailbox(int account_id, int local_yn, int inp
* arguments :
* return :
*/
-INTERNAL_FUNC int emstorage_update_mailbox_type(int account_id, int local_yn, int input_mailbox_id, email_mailbox_type_e new_mailbox_type, int transaction, int *err_code);
+INTERNAL_FUNC int emstorage_update_mailbox_type(char *multi_user_name, int account_id, int local_yn, int input_mailbox_id, email_mailbox_type_e new_mailbox_type, int transaction, int *err_code);
/*
* emstorage_set_local_mailbox
@@ -642,9 +647,9 @@ INTERNAL_FUNC int emstorage_update_mailbox_type(int account_id, int local_yn, in
* arguments :
* return :
*/
-INTERNAL_FUNC int emstorage_set_local_mailbox(int input_mailbox_id, int input_is_local_mailbox, int transaction);
+INTERNAL_FUNC int emstorage_set_local_mailbox(char *multi_user_name, int input_mailbox_id, int input_is_local_mailbox, int transaction);
-INTERNAL_FUNC int emstorage_set_field_of_mailbox_with_integer_value(int input_account_id, int *input_mailbox_id_array, int input_mailbox_id_count, char *input_field_name, int input_value, int transaction);
+INTERNAL_FUNC int emstorage_set_field_of_mailbox_with_integer_value(char *multi_user_name, int input_account_id, int *input_mailbox_id_array, int input_mailbox_id_count, char *input_field_name, int input_value, int transaction);
/*
* emstorage_add_mailbox
@@ -653,7 +658,7 @@ INTERNAL_FUNC int emstorage_set_field_of_mailbox_with_integer_value(int input_ac
* arguments :
* return :
*/
-INTERNAL_FUNC int emstorage_add_mailbox(emstorage_mailbox_tbl_t *mailbox, int transaction, int *err_code);
+INTERNAL_FUNC int emstorage_add_mailbox(char *multi_user_name, emstorage_mailbox_tbl_t *mailbox, int transaction, int *err_code);
/*
* emstorage_delete_mailbox
@@ -664,15 +669,19 @@ INTERNAL_FUNC int emstorage_add_mailbox(emstorage_mailbox_tbl_t *mailbox, int tr
* mailbox_name : mailbox name of record to be deteted
* return :
*/
-INTERNAL_FUNC int emstorage_delete_mailbox(int account_id, int local_yn, int input_mailbox_id, int transaction, int *err_code);
+INTERNAL_FUNC int emstorage_delete_mailbox(char *multi_user_name, int account_id, int local_yn, int input_mailbox_id, int transaction, int *err_code);
+
+INTERNAL_FUNC int emstorage_rename_mailbox(char *multi_user_name, int input_mailbox_id, char *input_new_mailbox_name, char *input_new_mailbox_alias, void *input_eas_data, int input_eas_data_length, int input_transaction);
+
+INTERNAL_FUNC int emstorage_get_overflowed_mail_id_list(char *multi_user_name, int account_id, int input_mailbox_id, int mail_slot_size, int **mail_id_list, int *mail_id_count, int transaction, int *err_code);
+
+INTERNAL_FUNC int emstorage_set_mail_slot_size(char *multi_user_name, int account_id, int mailbox_id, int new_slot_size, int transaction, int *err_code);
+
+INTERNAL_FUNC int emstorage_set_all_mailbox_modifiable_yn(char *multi_user_name, int account_id, int modifiable_yn, int transaction, int *err_code);
-INTERNAL_FUNC int emstorage_rename_mailbox(int input_mailbox_id, char *input_new_mailbox_name, char *input_new_mailbox_alias, void *input_eas_data, int input_eas_data_length, int input_transaction);
-INTERNAL_FUNC int emstorage_get_overflowed_mail_id_list(int account_id, int input_mailbox_id, int input_mailbox_type, int mail_slot_size, int **mail_id_list, int *mail_id_count, int transaction, int *err_code);
-INTERNAL_FUNC int emstorage_set_mail_slot_size(int account_id, int mailbox_id, int new_slot_size, int transaction, int *err_code);
+INTERNAL_FUNC int emstorage_get_mailbox_by_modifiable_yn(char *multi_user_name, int account_id, int modifiable_yn, int *select_num, emstorage_mailbox_tbl_t **mailbox_list, int transaction, int *err_code);
-INTERNAL_FUNC int emstorage_set_all_mailbox_modifiable_yn(int account_id, int modifiable_yn, int transaction, int *err_code);
-INTERNAL_FUNC int emstorage_get_mailbox_by_modifiable_yn(int account_id, int modifiable_yn, int *select_num, emstorage_mailbox_tbl_t **mailbox_list, int transaction, int *err_code);
-INTERNAL_FUNC int emstorage_stamp_last_sync_time_of_mailbox(int input_mailbox_id, int input_transaction);
+INTERNAL_FUNC int emstorage_stamp_last_sync_time_of_mailbox(char *multi_user_name, int input_mailbox_id, int input_transaction);
/*
* emstorage_free_mailbox
@@ -687,10 +696,7 @@ INTERNAL_FUNC int emstorage_free_mailbox(emstorage_mailbox_tbl_t **mailbox_list,
/************** Read Mail UID Management ******************/
-
-
-
-INTERNAL_FUNC int emstorage_get_count_read_mail_uid(int account_id, char *mailbox_name, int *count, int transaction, int *err_code);
+INTERNAL_FUNC int emstorage_get_count_read_mail_uid(char *multi_user_name, int account_id, char *mailbox_name, int *count, int transaction, int *err_code);
/*
@@ -704,7 +710,7 @@ INTERNAL_FUNC int emstorage_get_count_read_mail_uid(int account_id, char *mailbo
* exist : variable to hold checking result. (0 : not exist, 1 : exist)
* return :
*/
-INTERNAL_FUNC int emstorage_check_read_mail_uid(int account_id, char *mailbox_name, char *uid, int *exist, int transaction, int *err_code);
+INTERNAL_FUNC int emstorage_check_read_mail_uid(char *multi_user_name, int account_id, char *mailbox_name, char *uid, int *exist, int transaction, int *err_code);
/*
* emstorage_get_read_mail_size
@@ -719,9 +725,9 @@ INTERNAL_FUNC int emstorage_check_read_mail_uid(int account_id, char *mailbox_na
* read_mail_uid : variable to hold read mail uid information
* return :
*/
-INTERNAL_FUNC int emstorage_get_downloaded_list(int account_id, int mailbox_id, emstorage_read_mail_uid_tbl_t **read_mail_uid, int *count, int transaction, int *err_code);
+INTERNAL_FUNC int emstorage_get_downloaded_list(char *multi_user_name, int account_id, int mailbox_id, emstorage_read_mail_uid_tbl_t **read_mail_uid, int *count, int transaction, int *err_code);
-INTERNAL_FUNC int emstorage_get_downloaded_mail(int mail_id, emstorage_mail_tbl_t **mail, int transaction, int *err_code);
+INTERNAL_FUNC int emstorage_get_downloaded_mail(char *multi_user_name, int mail_id, emstorage_mail_tbl_t **mail, int transaction, int *err_code);
/*
* emstorage_get_read_mail_size
@@ -734,7 +740,7 @@ INTERNAL_FUNC int emstorage_get_downloaded_mail(int mail_id, emstorage_mail_tbl_
* size : variable to hold mail size
* return :
*/
-INTERNAL_FUNC int emstorage_get_downloaded_mail_size(int account_id, char *local_mbox, int local_uid, char *mailbox_name, char *uid, int *mail_size, int transaction, int *err_code);
+INTERNAL_FUNC int emstorage_get_downloaded_mail_size(char *multi_user_name, int account_id, char *local_mbox, int local_uid, char *mailbox_name, char *uid, int *mail_size, int transaction, int *err_code);
/*
* emstorage_add_downloaded_mail
@@ -743,7 +749,7 @@ INTERNAL_FUNC int emstorage_get_downloaded_mail_size(int account_id, char *local
* arguments :
* return :
*/
-INTERNAL_FUNC int emstorage_add_downloaded_mail(emstorage_read_mail_uid_tbl_t *read_mail_uid, int transaction, int *err_code);
+INTERNAL_FUNC int emstorage_add_downloaded_mail(char *multi_user_name, emstorage_read_mail_uid_tbl_t *read_mail_uid, int transaction, int *err_code);
#ifdef __FEATURE_BODY_SEARCH__
/*
@@ -753,7 +759,7 @@ INTERNAL_FUNC int emstorage_add_downloaded_mail(emstorage_read_mail_uid_tbl_t *r
* arguments :
* return :
*/
-INTERNAL_FUNC int emstorage_add_mail_text(emstorage_mail_text_tbl_t* mail_text, int transaction, int *err_code);
+INTERNAL_FUNC int emstorage_add_mail_text(char *multi_user_name, emstorage_mail_text_tbl_t* mail_text, int transaction, int *err_code);
#endif
/*
@@ -763,7 +769,7 @@ INTERNAL_FUNC int emstorage_add_mail_text(emstorage_mail_text_tbl_t* mail_text,
* arguments :
* return :
*/
-INTERNAL_FUNC int emstorage_change_read_mail_uid(int account_id, int local_mailbox_id, int local_uid, char *mailbox_name, char *uid,
+INTERNAL_FUNC int emstorage_change_read_mail_uid(char *multi_user_name, int account_id, int local_mailbox_id, int local_uid, char *mailbox_name, char *uid,
emstorage_read_mail_uid_tbl_t *read_mail_uid, int transaction, int *err_code);
/*
@@ -773,10 +779,9 @@ INTERNAL_FUNC int emstorage_change_read_mail_uid(int account_id, int local_mailb
* arguments :
* return :
*/
-INTERNAL_FUNC int emstorage_remove_downloaded_mail(int account_id, char *mailbox_name, char *uid, int transaction, int *err_code);
-
+INTERNAL_FUNC int emstorage_remove_downloaded_mail(char *multi_user_name, int account_id, char *mailbox_name, char *uid, int transaction, int *err_code);
-INTERNAL_FUNC int emstorage_update_read_mail_uid(int mail_id, char *new_server_uid, char *mbox_name, int *err_code);
+INTERNAL_FUNC int emstorage_update_read_mail_uid(char *multi_user_name, int mail_id, char *new_server_uid, char *mbox_name, int *err_code);
/*
* free memroy
@@ -796,7 +801,7 @@ INTERNAL_FUNC int emstorage_free_read_mail_uid(emstorage_read_mail_uid_tbl_t **r
* count : number of accounts
* return :
*/
-INTERNAL_FUNC int emstorage_get_rule_count_by_account_id(int account_id, int *count, int transaction, int *err_code);
+INTERNAL_FUNC int emstorage_get_rule_count_by_account_id(char *multi_user_name, int account_id, int *count, int transaction, int *err_code);
/*
* emstorage_get_rule
@@ -810,7 +815,7 @@ INTERNAL_FUNC int emstorage_get_rule_count_by_account_id(int account_id, int *co
* is_completed : is completed ?
* return :
*/
-INTERNAL_FUNC int emstorage_get_rule(int account_id, int type, int start_idx, int *select_num, int *is_completed, emstorage_rule_tbl_t **rule_list, int transaction, int *err_code);
+INTERNAL_FUNC int emstorage_get_rule(char *multi_user_name, int account_id, int type, int start_idx, int *select_num, int *is_completed, emstorage_rule_tbl_t **rule_list, int transaction, int *err_code);
/*
* emstorage_get_rule
@@ -819,7 +824,7 @@ INTERNAL_FUNC int emstorage_get_rule(int account_id, int type, int start_idx, in
* arguments :
* return :
*/
-INTERNAL_FUNC int emstorage_get_rule_by_id(int rule_id, emstorage_rule_tbl_t **rule, int transaction, int *err_code);
+INTERNAL_FUNC int emstorage_get_rule_by_id(char *multi_user_name, int rule_id, emstorage_rule_tbl_t **rule, int transaction, int *err_code);
/*
* emstorage_change_rule
@@ -831,7 +836,7 @@ INTERNAL_FUNC int emstorage_get_rule_by_id(int rule_id, emstorage_rule_tbl_t **r
* rule : buffer to hold selected rule
* return :
*/
-INTERNAL_FUNC int emstorage_change_rule(int rule_id, emstorage_rule_tbl_t *rule, int transaction, int *err_code);
+INTERNAL_FUNC int emstorage_change_rule(char *multi_user_name, int rule_id, emstorage_rule_tbl_t *rule, int transaction, int *err_code);
/*
* emstorage_find_rule
@@ -840,7 +845,7 @@ INTERNAL_FUNC int emstorage_change_rule(int rule_id, emstorage_rule_tbl_t *rule,
* arguments :
* return :
*/
-INTERNAL_FUNC int emstorage_find_rule(emstorage_rule_tbl_t *rule, int transaction, int *err_code);
+INTERNAL_FUNC int emstorage_find_rule(char *multi_user_name, emstorage_rule_tbl_t *rule, int transaction, int *err_code);
/*
* emstorage_add_rule
@@ -849,7 +854,7 @@ INTERNAL_FUNC int emstorage_find_rule(emstorage_rule_tbl_t *rule, int transactio
* arguments :
* return :
*/
-INTERNAL_FUNC int emstorage_add_rule(emstorage_rule_tbl_t *rule, int transaction, int *err_code);
+INTERNAL_FUNC int emstorage_add_rule(char *multi_user_name, emstorage_rule_tbl_t *rule, int transaction, int *err_code);
/*
* emstorage_delete_rule
@@ -860,7 +865,7 @@ INTERNAL_FUNC int emstorage_add_rule(emstorage_rule_tbl_t *rule, int transaction
* rule : rule to be deteted
* return :
*/
-INTERNAL_FUNC int emstorage_delete_rule(int rule_id, int transaction, int *err_code);
+INTERNAL_FUNC int emstorage_delete_rule(char *multi_user_name, int rule_id, int transaction, int *err_code);
/*
* emstorage_free_rule
@@ -884,7 +889,7 @@ INTERNAL_FUNC int emstorage_free_rule(emstorage_rule_tbl_t **rule_list, int coun
* unseen : unseen mail count
* return :
*/
-INTERNAL_FUNC int emstorage_get_mail_count(int account_id, int mailbox_id, int *total, int *unseen, int transaction, int *err_code);
+INTERNAL_FUNC int emstorage_get_mail_count(char *multi_user_name, int account_id, int mailbox_id, int *total, int *unseen, int transaction, int *err_code);
/*
* emstorage_get_mail_by_id
@@ -895,7 +900,7 @@ INTERNAL_FUNC int emstorage_get_mail_count(int account_id, int mailbox_id, int *
* mail : double pointer to hold mail
* return :
*/
-INTERNAL_FUNC int emstorage_get_mail_by_id(int mail_id, emstorage_mail_tbl_t **mail, int transaction, int *err_code);
+INTERNAL_FUNC int emstorage_get_mail_by_id(char *multi_user_name, int mail_id, emstorage_mail_tbl_t **mail, int transaction, int *err_code);
#ifdef __FEATURE_BODY_SEARCH__
/*
@@ -907,7 +912,7 @@ INTERNAL_FUNC int emstorage_get_mail_by_id(int mail_id, emstorage_mail_tbl_t **m
* mail_text : double pointer to hold mail_text
* return :
*/
-INTERNAL_FUNC int emstorage_get_mail_text_by_id(int mail_id, emstorage_mail_text_tbl_t **mail_text, int transaction, int *err_code);
+INTERNAL_FUNC int emstorage_get_mail_text_by_id(char *multi_user_name, int mail_id, emstorage_mail_text_tbl_t **mail_text, int transaction, int *err_code);
#endif
/*
@@ -921,7 +926,7 @@ INTERNAL_FUNC int emstorage_get_mail_text_by_id(int mail_id, emstorage_mail_text
* mail : double pointer to hold mail
* return :
*/
-INTERNAL_FUNC int emstorage_get_mail_field_by_id(int mail_id, int type, emstorage_mail_tbl_t **mail, int transaction, int *err_code);
+INTERNAL_FUNC int emstorage_get_mail_field_by_id(char *multi_user_name, int mail_id, int type, emstorage_mail_tbl_t **mail, int transaction, int *err_code);
/*
* emstorage_get_mail_field_by_multiple_mail_id
@@ -936,35 +941,37 @@ INTERNAL_FUNC int emstorage_get_mail_field_by_id(int mail_id, int type, emstorag
* err_code :
* return :
*/
-INTERNAL_FUNC int emstorage_get_mail_field_by_multiple_mail_id(int mail_ids[], int number_of_mails, int type, emstorage_mail_tbl_t** mail, int transaction, int *err_code);
+INTERNAL_FUNC int emstorage_get_mail_field_by_multiple_mail_id(char *multi_user_name, int mail_ids[], int number_of_mails, int type, emstorage_mail_tbl_t** mail, int transaction, int *err_code);
/*
* emstorage_query_mail_count
*
* description : query mail count
*/
-INTERNAL_FUNC int emstorage_query_mail_count(const char *input_conditional_clause, int input_transaction, int *output_total_mail_count, int *output_unseen_mail_count);
-
+INTERNAL_FUNC int emstorage_query_mail_count(char *multi_user_name, const char *input_conditional_clause, int input_transaction, int *output_total_mail_count, int *output_unseen_mail_count);
/*
* emstorage_query_mail_list
*
* description : query mail id list
*/
-INTERNAL_FUNC int emstorage_query_mail_id_list(const char *input_conditional_clause, int input_transaction, int **output_mail_id_list, int *output_mail_id_count);
+INTERNAL_FUNC int emstorage_query_mail_id_list(char *multi_user_name, const char *input_conditional_clause, int input_transaction, int **output_mail_id_list, int *output_mail_id_count);
+
/*
* emstorage_query_mail_list
*
* description : query mail list information
*/
-INTERNAL_FUNC int emstorage_query_mail_list(const char *conditional_clause, int transaction, email_mail_list_item_t** result_mail_list, int *result_count, int *err_code);
+INTERNAL_FUNC int emstorage_query_mail_list(char *multi_user_name, const char *conditional_clause, int transaction, email_mail_list_item_t** result_mail_list, int *result_count, int *err_code);
+
/*
* emstorage_query_mail_tbl
*
* description : query mail table information
*/
-INTERNAL_FUNC int emstorage_query_mail_tbl(const char *conditional_clause, int transaction, emstorage_mail_tbl_t** result_mail_tbl, int *result_count, int *err_code);
+INTERNAL_FUNC int emstorage_query_mail_tbl(char *multi_user_name, const char *conditional_clause, int transaction, emstorage_mail_tbl_t** result_mail_tbl, int *result_count, int *err_code);
+
#ifdef __FEATURE_BODY_SEARCH__
/*
@@ -972,7 +979,7 @@ INTERNAL_FUNC int emstorage_query_mail_tbl(const char *conditional_clause, int t
*
* description : query mail_text table information
*/
-INTERNAL_FUNC int emstorage_query_mail_text_tbl(const char *conditional_clause, int transaction, emstorage_mail_text_tbl_t** result_mail_text_tbl, int *result_count, int *err_code);
+INTERNAL_FUNC int emstorage_query_mail_text_tbl(char *multi_user_name, const char *conditional_clause, int transaction, emstorage_mail_text_tbl_t** result_mail_text_tbl, int *result_count, int *err_code);
#endif
/*
@@ -980,26 +987,34 @@ INTERNAL_FUNC int emstorage_query_mail_text_tbl(const char *conditional_clause,
*
* description : query mail box table information
*/
-
-INTERNAL_FUNC int emstorage_query_mailbox_tbl(const char *input_conditional_clause, const char *input_ordering_clause, int input_get_mail_count, int input_transaction, emstorage_mailbox_tbl_t **output_mailbox_list, int *output_mailbox_count);
+INTERNAL_FUNC int emstorage_query_mailbox_tbl(char *multi_user_name, const char *input_conditional_clause, const char *input_ordering_clause, int input_get_mail_count, int input_transaction, emstorage_mailbox_tbl_t **output_mailbox_list, int *output_mailbox_count);
/*
* emstorage_get_mail_list
*
* description : search mail list information
*/
+INTERNAL_FUNC int emstorage_get_mail_list(char *multi_user_name, int account_id, int mailbox_id, email_email_address_list_t* addr_list, int thread_id, int start_index, int limit_count, int search_type, const char *search_value, email_sort_type_t sorting, int transaction, email_mail_list_item_t** mail_list, int *result_count, int *err_code);
-INTERNAL_FUNC int emstorage_get_mail_list(int account_id, int mailbox_id, email_email_address_list_t* addr_list, int thread_id, int start_index, int limit_count, int search_type, const char *search_value, email_sort_type_t sorting, int transaction, email_mail_list_item_t** mail_list, int *result_count, int *err_code);
/*
* emstorage_get_mails
*
* description : search mail list information
*/
-INTERNAL_FUNC int emstorage_get_mails(int account_id, int mailbox_id, email_email_address_list_t* addr_list, int thread_id, int start_index, int limit_count, email_sort_type_t sorting, int transaction, emstorage_mail_tbl_t** mail_list, int *result_count, int *err_code);
-INTERNAL_FUNC int emstorage_get_searched_mail_list(int account_id, int mailbox_id, int thread_id, int search_type, const char *search_value, int start_index, int limit_count, email_sort_type_t sorting, int transaction, email_mail_list_item_t **mail_list, int *result_count, int *err_code);
-INTERNAL_FUNC int emstorage_get_maildata_by_servermailid(int account_id, char *server_mail_id, emstorage_mail_tbl_t **mail, int transaction, int *err_code);
-INTERNAL_FUNC int emstorage_get_unread_mailid(int account_id, int vip_mode, int **mail_ids, int *mail_number, int *err_code);
-INTERNAL_FUNC int emstorage_update_save_status(int account_id, int *err_code);
+INTERNAL_FUNC int emstorage_get_mails(char *multi_user_name, int account_id, int mailbox_id, email_email_address_list_t* addr_list, int thread_id, int start_index, int limit_count, email_sort_type_t sorting, int transaction, emstorage_mail_tbl_t** mail_list, int *result_count, int *err_code);
+
+INTERNAL_FUNC int emstorage_get_searched_mail_list(char *multi_user_name, int account_id, int mailbox_id, int thread_id, int search_type, const char *search_value, int start_index, int limit_count, email_sort_type_t sorting, int transaction, email_mail_list_item_t **mail_list, int *result_count, int *err_code);
+
+INTERNAL_FUNC int emstorage_get_maildata_by_servermailid(char *multi_user_name,
+ char *server_mail_id,
+ int mailbox_id,
+ emstorage_mail_tbl_t **mail,
+ int transaction,
+ int *err_code);
+
+INTERNAL_FUNC int emstorage_get_unread_mailid(char *multi_user_name, int account_id, int vip_mode, int **mail_ids, int *mail_number, int *err_code);
+
+INTERNAL_FUNC int emstorage_update_save_status(char *multi_user_name, int account_id, int *err_code);
/**
@@ -1014,7 +1029,15 @@ INTERNAL_FUNC int emstorage_update_save_status(int account_id, int *err_code);
* @remarks N/A
* @return This function returns 0 on success or error code on failure.
*/
-INTERNAL_FUNC int emstorage_mail_search_start(emstorage_search_filter_t *search, int account_id, int mailbox_id, int sorting, int *search_handle, int *searched, int transaction, int *err_code);
+INTERNAL_FUNC int emstorage_mail_search_start(char *multi_user_name,
+ emstorage_search_filter_t *search,
+ int account_id,
+ int mailbox_id,
+ int sorting,
+ DB_STMT *search_handle,
+ int *searched,
+ int transaction,
+ int *err_code);
/*
* emstorage_mail_search_result
@@ -1025,7 +1048,11 @@ INTERNAL_FUNC int emstorage_mail_search_start(emstorage_search_filter_t *search,
* mail : double pointer to hold mail
* return :
*/
-INTERNAL_FUNC int emstorage_mail_search_result(int search_handle, emstorage_mail_field_type_t type, void **data, int transaction, int *err_code);
+INTERNAL_FUNC int emstorage_mail_search_result(DB_STMT search_handle,
+ emstorage_mail_field_type_t type,
+ void **data,
+ int transaction,
+ int *err_code);
/*
* emstorage_mail_search_end
@@ -1035,9 +1062,7 @@ INTERNAL_FUNC int emstorage_mail_search_result(int search_handle, emstorage_mail
* search_handle : handle to be finished
* return :
*/
-INTERNAL_FUNC int emstorage_mail_search_end(int search_handle, int transaction, int *err_code);
-
-
+INTERNAL_FUNC int emstorage_mail_search_end(DB_STMT search_handle, int transaction, int *err_code);
/*
* emstorage_set_field_of_mails_with_integer_value
@@ -1051,7 +1076,7 @@ INTERNAL_FUNC int emstorage_mail_search_end(int search_handle, int transaction,
* value : specified value
* return :
*/
-INTERNAL_FUNC int emstorage_set_field_of_mails_with_integer_value(int account_id, int mail_ids[], int mail_ids_count, char *field_name, int value, int transaction, int *err_code);
+INTERNAL_FUNC int emstorage_set_field_of_mails_with_integer_value(char *multi_user_name, int account_id, int mail_ids[], int mail_ids_count, char *field_name, int value, int transaction, int *err_code);
#ifdef __FEATURE_BODY_SEARCH__
/*
@@ -1063,7 +1088,7 @@ INTERNAL_FUNC int emstorage_set_field_of_mails_with_integer_value(int account_id
* mail_text : mail_text pointer
* return :
*/
-INTERNAL_FUNC int emstorage_change_mail_text_field(int mail_id, emstorage_mail_text_tbl_t* mail_text, int transaction, int *err_code);
+INTERNAL_FUNC int emstorage_change_mail_text_field(char *multi_user_name, int mail_id, emstorage_mail_text_tbl_t* mail_text, int transaction, int *err_code);
#endif
/*
@@ -1076,7 +1101,7 @@ INTERNAL_FUNC int emstorage_change_mail_text_field(int mail_id, emstorage_mail_t
* mail : mail pointer
* return :
*/
-INTERNAL_FUNC int emstorage_change_mail_field(int mail_id, email_mail_change_type_t type, emstorage_mail_tbl_t *mail, int transaction, int *err_code);
+INTERNAL_FUNC int emstorage_change_mail_field(char *multi_user_name, int mail_id, email_mail_change_type_t type, emstorage_mail_tbl_t *mail, int transaction, int *err_code);
/*
* emstorage_increase_mail_id
@@ -1096,11 +1121,13 @@ INTERNAL_FUNC int emstorage_change_mail_field(int mail_id, email_mail_change_typ
* mail : mail pointer
* return :
*/
-INTERNAL_FUNC int emstorage_change_mail(int mail_id, emstorage_mail_tbl_t *mail, int transaction, int *err_code);
-INTERNAL_FUNC int emstorage_clean_save_status(int save_status, int *err_code);
-INTERNAL_FUNC int emstorage_update_server_uid(char *old_server_uid, char *new_server_uid, int *err_code);
+INTERNAL_FUNC int emstorage_change_mail(char *multi_user_name, int mail_id, emstorage_mail_tbl_t *mail, int transaction, int *err_code);
+
+INTERNAL_FUNC int emstorage_clean_save_status(char *multi_user_name, int save_status, int *err_code);
+
+INTERNAL_FUNC int emstorage_update_server_uid(char *multi_user_name, char *old_server_uid, char *new_server_uid, int *err_code);
-INTERNAL_FUNC int emstorage_increase_mail_id(int *mail_id, int transaction, int *err_code);
+INTERNAL_FUNC int emstorage_increase_mail_id(char *multi_user_name, int *mail_id, int transaction, int *err_code);
/*
* emstorage_add_mail
@@ -1111,7 +1138,7 @@ INTERNAL_FUNC int emstorage_increase_mail_id(int *mail_id, int transaction, int
* get_id : must get uinque id in function
* return :
*/
-INTERNAL_FUNC int emstorage_add_mail(emstorage_mail_tbl_t *mail, int get_id, int transaction, int *err_code);
+INTERNAL_FUNC int emstorage_add_mail(char *multi_user_name, emstorage_mail_tbl_t *mail, int get_id, int transaction, int *err_code);
/*
* emstorage_move_multiple_mails_on_db
@@ -1126,7 +1153,7 @@ INTERNAL_FUNC int emstorage_add_mail(emstorage_mail_tbl_t *mail, int get_id, int
* err_code :
* return :
*/
-INTERNAL_FUNC int emstorage_move_multiple_mails_on_db(int account_id, int input_mailbox_id, int mail_ids[], int number_of_mails, int transaction, int *err_code);
+INTERNAL_FUNC int emstorage_move_multiple_mails_on_db(char *multi_user_name, int account_id, int input_mailbox_id, int mail_ids[], int number_of_mails, int transaction, int *err_code);
/*
* emstorage_delete_mail
@@ -1137,7 +1164,7 @@ INTERNAL_FUNC int emstorage_move_multiple_mails_on_db(int account_id, int input_
* from_server : delete mail on server.
* return :
*/
-INTERNAL_FUNC int emstorage_delete_mail(int mail_id, int from_server, int transaction, int *err_code);
+INTERNAL_FUNC int emstorage_delete_mail(char *multi_user_name, int mail_id, int from_server, int transaction, int *err_code);
/*
* emstorage_delete_mail_by_account
@@ -1147,7 +1174,7 @@ INTERNAL_FUNC int emstorage_delete_mail(int mail_id, int from_server, int transa
* account_id : account id.
* return :
*/
-INTERNAL_FUNC int emstorage_delete_mail_by_account(int account_id, int transaction, int *err_code);
+INTERNAL_FUNC int emstorage_delete_mail_by_account(char *multi_user_name, int account_id, int transaction, int *err_code);
/*
* emstorage_delete_mail_by_mailbox
@@ -1157,7 +1184,7 @@ INTERNAL_FUNC int emstorage_delete_mail_by_account(int account_id, int transacti
* mailbox : mailbox
* return :
*/
-INTERNAL_FUNC int emstorage_delete_mail_by_mailbox(emstorage_mailbox_tbl_t *mailbox, int transaction, int *err_code);
+INTERNAL_FUNC int emstorage_delete_mail_by_mailbox(char *multi_user_name, emstorage_mailbox_tbl_t *mailbox, int transaction, int *err_code);
/*
* emstorage_delete_multiple_mails
@@ -1170,7 +1197,7 @@ INTERNAL_FUNC int emstorage_delete_mail_by_mailbox(emstorage_mailbox_tbl_t *mail
* err_code :
* return :
*/
-INTERNAL_FUNC int emstorage_delete_multiple_mails(int mail_ids[], int number_of_mails, int transaction, int *err_code);
+INTERNAL_FUNC int emstorage_delete_multiple_mails(char *multi_user_name, int mail_ids[], int number_of_mails, int transaction, int *err_code);
/*
* emstorage_free_mail
@@ -1206,13 +1233,13 @@ INTERNAL_FUNC void emstorage_free_mail_text(emstorage_mail_text_tbl_t** mail_tex
* attachment : double pointer to hold attachment data
* return :
*/
-INTERNAL_FUNC int emstorage_get_attachment_count(int mail_id, int *count, int transaction, int *err_code);
+INTERNAL_FUNC int emstorage_get_attachment_count(char *multi_user_name, int mail_id, int *count, int transaction, int *err_code);
/*
* emstorage_get_attachment_list
*
* description : get attachment list from attachment table
- * arguments :
+ * arguments :
* input_mail_id : mail id
* input_transaction : transaction option
* attachment_list : result attachment list
@@ -1220,7 +1247,7 @@ INTERNAL_FUNC int emstorage_get_attachment_count(int mail_id, int *count, int tr
* return : This function returns EMAIL_ERROR_NONE on success or error code (refer to EMAIL_ERROR__XXX) on failure.
*
*/
-INTERNAL_FUNC int emstorage_get_attachment_list(int input_mail_id, int input_transaction, emstorage_attachment_tbl_t** output_attachment_list, int *output_attachment_count);
+INTERNAL_FUNC int emstorage_get_attachment_list(char *multi_user_name, int input_mail_id, int input_transaction, emstorage_attachment_tbl_t** output_attachment_list, int *output_attachment_count);
/*
@@ -1232,7 +1259,7 @@ INTERNAL_FUNC int emstorage_get_attachment_list(int input_mail_id, int input_tra
* attachment : double pointer to hold attachment data
* return :
*/
-INTERNAL_FUNC int emstorage_get_attachment(int attachment_id, emstorage_attachment_tbl_t **attachment, int transaction, int *err_code);
+INTERNAL_FUNC int emstorage_get_attachment(char *multi_user_name, int attachment_id, emstorage_attachment_tbl_t **attachment, int transaction, int *err_code);
/*
* emstorage_get_attachment
@@ -1244,7 +1271,7 @@ INTERNAL_FUNC int emstorage_get_attachment(int attachment_id, emstorage_attachme
* attachment : double pointer to hold attachment data
* return :
*/
-INTERNAL_FUNC int emstorage_get_attachment_nth(int mail_id, int nth, emstorage_attachment_tbl_t **attachment, int transaction, int *err_code);
+INTERNAL_FUNC int emstorage_get_attachment_nth(char *multi_user_name, int mail_id, int nth, emstorage_attachment_tbl_t **attachment, int transaction, int *err_code);
/*
* emstorage_get_attachment
@@ -1255,7 +1282,7 @@ INTERNAL_FUNC int emstorage_get_attachment_nth(int mail_id, int nth, emstorage_a
* attachment : double pointer to hold attachment data
* return :
*/
-INTERNAL_FUNC int emstorage_get_attachment_by_attachment_path(char *attachment_path, emstorage_attachment_tbl_t **attachment, int transaction, int *err_code);
+INTERNAL_FUNC int emstorage_get_attachment_by_attachment_path(char *multi_user_name, char *attachment_path, emstorage_attachment_tbl_t **attachment, int transaction, int *err_code);
/*
* emstorage_change_attachment_field
@@ -1267,7 +1294,7 @@ INTERNAL_FUNC int emstorage_get_attachment_by_attachment_path(char *attachment_p
* mail : mail pointer
* return :
*/
-INTERNAL_FUNC int emstorage_change_attachment_field(int mail_id, email_mail_change_type_t type, emstorage_attachment_tbl_t *attachment, int transaction, int *err_code);
+INTERNAL_FUNC int emstorage_change_attachment_field(char *multi_user_name, int mail_id, email_mail_change_type_t type, emstorage_attachment_tbl_t *attachment, int transaction, int *err_code);
/* Get new attachment id */
/*
@@ -1278,8 +1305,7 @@ INTERNAL_FUNC int emstorage_change_attachment_field(int mail_id, email_mail_chan
* attachment_no : attachment id pointer
* return :
*/
-
-INTERNAL_FUNC int emstorage_get_new_attachment_no(int *attachment_no, int *err_code);
+INTERNAL_FUNC int emstorage_get_new_attachment_no(char *multi_user_name, int *attachment_no, int *err_code);
/* insert attachment to mail attachment table */
/*
@@ -1290,10 +1316,9 @@ INTERNAL_FUNC int emstorage_get_new_attachment_no(int *attachment_no, int *err_c
* attachment : attachment pointer
* return :
*/
-INTERNAL_FUNC int emstorage_add_attachment(emstorage_attachment_tbl_t *attachment, int iscopy, int transaction, int *err_code);
+INTERNAL_FUNC int emstorage_add_attachment(char *multi_user_name, emstorage_attachment_tbl_t *attachment, int iscopy, int transaction, int *err_code);
-
-INTERNAL_FUNC int emstorage_update_attachment(emstorage_attachment_tbl_t *attachment, int transaction, int *err_code);
+INTERNAL_FUNC int emstorage_update_attachment(char *multi_user_name, emstorage_attachment_tbl_t *attachment, int transaction, int *err_code);
/* delete a mail from mail table */
/*
@@ -1304,9 +1329,9 @@ INTERNAL_FUNC int emstorage_update_attachment(emstorage_attachment_tbl_t *attach
* attachment_id : attachment id
* return :
*/
-INTERNAL_FUNC int emstorage_delete_attachment_on_db(int attachment_id, int transaction, int *err_code);
+INTERNAL_FUNC int emstorage_delete_attachment_on_db(char *multi_user_name, int attachment_id, int transaction, int *err_code);
-INTERNAL_FUNC int emstorage_delete_all_attachments_of_mail(int mail_id, int transaction, int *err_code);
+INTERNAL_FUNC int emstorage_delete_all_attachments_of_mail(char *multi_user_name, int mail_id, int transaction, int *err_code);
/*
* emstorage_delete_attachment_all_on_db
@@ -1317,7 +1342,7 @@ INTERNAL_FUNC int emstorage_delete_all_attachments_of_mail(int mail_id, int tran
* mailbox : mail box
* return :
*/
-INTERNAL_FUNC int emstorage_delete_attachment_all_on_db(int account_id, char *mailbox, int transaction, int *err_code);
+INTERNAL_FUNC int emstorage_delete_attachment_all_on_db(char *multi_user_name, int account_id, char *mailbox, int transaction, int *err_code);
/*
* emstorage_free_attachment
@@ -1330,7 +1355,7 @@ INTERNAL_FUNC int emstorage_delete_attachment_all_on_db(int account_id, char *ma
*/
INTERNAL_FUNC int emstorage_free_attachment(emstorage_attachment_tbl_t **attachment_list, int count, int *err_code);
-INTERNAL_FUNC int emstorage_is_mailbox_full(int account_id, email_mailbox_t *mailbox, int *result, int *err_code);
+INTERNAL_FUNC int emstorage_is_mailbox_full(char *multi_user_name, int account_id, email_mailbox_t *mailbox, int *result, int *err_code);
INTERNAL_FUNC int emstorage_get_max_mail_count();
@@ -1345,8 +1370,7 @@ INTERNAL_FUNC int emstorage_mail_get_total_diskspace_usage(unsigned long *total_
* @remarks emstorage_commit_transaction or emstorage_commit_transaction must be called after this function.
* @return This function returns 0 on success or error code on failure.
*/
-
-INTERNAL_FUNC int emstorage_begin_transaction(void *d1, void *d2, int *err_code);
+INTERNAL_FUNC int emstorage_begin_transaction(char *multi_user_name, void *d1, void *d2, int *err_code);
/**
* commit a transaction.
@@ -1356,7 +1380,7 @@ INTERNAL_FUNC int emstorage_begin_transaction(void *d1, void *d2, int *err_code)
* @remarks N/A
* @return This function returns 0 on success or error code on failure.
*/
-INTERNAL_FUNC int emstorage_commit_transaction(void *d1, void *d2, int *err_code);
+INTERNAL_FUNC int emstorage_commit_transaction(char *multi_user_name, void *d1, void *d2, int *err_code);
/**
* rollback db.
@@ -1366,7 +1390,7 @@ INTERNAL_FUNC int emstorage_commit_transaction(void *d1, void *d2, int *err_code
* @remarks N/A
* @return This function returns 0 on success or error code on failure.
*/
-INTERNAL_FUNC int emstorage_rollback_transaction(void *d1, void *d2, int *err_code);
+INTERNAL_FUNC int emstorage_rollback_transaction(char *multi_user_name, void *d1, void *d2, int *err_code);
/**
* clear mail data from db.
@@ -1376,8 +1400,7 @@ INTERNAL_FUNC int emstorage_rollback_transaction(void *d1, void *d2, int *err_co
* @remarks N/A
* @return This function returns 0 on success or error code on failure.
*/
-
-INTERNAL_FUNC int emstorage_clear_mail_data(int transaction, int *err_code);
+INTERNAL_FUNC int emstorage_clear_mail_data(char *multi_user_name, int transaction, int *err_code);
INTERNAL_FUNC char *emstorage_make_directory_path_from_file_path(char *file_name);
@@ -1394,7 +1417,7 @@ INTERNAL_FUNC char *emstorage_make_directory_path_from_file_path(char *file_name
* name_buf : buffer to hold file name. (MAX : 512Bytes)
* return :
*/
-INTERNAL_FUNC int emstorage_get_save_name(int account_id, int mail_id, int atch_id, char *fname, char *name_buf, int maxlen, int *err_code);
+INTERNAL_FUNC int emstorage_get_save_name(char *multi_user_name, int account_id, int mail_id, int atch_id, char *fname, char *move_buf, char *path_buf, int maxlen, int *err_code);
/*
* emstorage_get_dele_name
@@ -1408,7 +1431,7 @@ INTERNAL_FUNC int emstorage_get_save_name(int account_id, int mail_id, int atch_
* name_buf : buffer to hold file name. (MAX : 512Bytes)
* return :
*/
-INTERNAL_FUNC int emstorage_get_dele_name(int account_id, int mail_id, int atch_id, char *fname, char *name_buf, int *err_code);
+INTERNAL_FUNC int emstorage_get_dele_name(char *multi_user_name, int account_id, int mail_id, int atch_id, char *fname, char *name_buf, int *err_code);
/*
* emstorage_create_dir
@@ -1419,7 +1442,7 @@ INTERNAL_FUNC int emstorage_get_dele_name(int account_id, int mail_id, int atch_
* no : attachment no.
* return :
*/
-INTERNAL_FUNC int emstorage_create_dir(int account_id, int mail_id, int atch_id, int *err_code);
+INTERNAL_FUNC int emstorage_create_dir(char *multi_user_name, int account_id, int mail_id, int atch_id, int *err_code);
/*
* emstorage_copy_file
@@ -1466,18 +1489,36 @@ INTERNAL_FUNC int emstorage_delete_dir(char *src_dir, int *err_code);
INTERNAL_FUNC void emstorage_flush_db_cache();
-INTERNAL_FUNC int emstorage_test(int mail_id, int account_id, char *full_address_to, char *full_address_cc, char *full_address_bcc, int *err_code);
-INTERNAL_FUNC int emstorage_get_sender_list(int account_id, int mailbox_id, int search_type, const char *search_value, email_sort_type_t sorting, email_sender_list_t** sender_list, int *sender_count, int *err_code);
+INTERNAL_FUNC int emstorage_test(char *multi_user_name, int mail_id, int account_id, char *full_address_to, char *full_address_cc, char *full_address_bcc, int *err_code);
+
+INTERNAL_FUNC int emstorage_get_sender_list(char *multi_user_name, int account_id, int mailbox_id, int search_type, const char *search_value, email_sort_type_t sorting, email_sender_list_t** sender_list, int *sender_count, int *err_code);
+
INTERNAL_FUNC int emstorage_free_sender_list(email_sender_list_t **sender_list, int count);
/* Handling Thread mail */
-INTERNAL_FUNC int emstorage_get_thread_information(int thread_id, emstorage_mail_tbl_t **mail_table_data, int transaction, int *err_code);
-INTERNAL_FUNC int emstorage_get_thread_id_of_thread_mails(emstorage_mail_tbl_t *mail_table_data, int *thread_id, int *result_latest_mail_id_in_thread, int *thread_item_count);
-INTERNAL_FUNC int emstorage_get_thread_id_by_mail_id(int mail_id, int *thread_id, int *err_code);
-INTERNAL_FUNC int emstorage_update_latest_thread_mail(int account_id, int mailbox_id, int thread_id, int *updated_thread_id, int latest_mail_id, int thread_item_count, int noti_type, int transaction, int *err_code);
-INTERNAL_FUNC int emstorage_get_thread_id_from_mailbox(int account_id, int mailbox_id, char *mail_subject, int *thread_id, int *thread_item_count);
-INTERNAL_FUNC int emstorage_update_thread_id_of_mail(int account_id, int mailbox_id, int mail_id, int thread_id, int thread_item_count, int transaction, int *err_code);
+INTERNAL_FUNC int emstorage_get_thread_information(char *multi_user_name, int thread_id, emstorage_mail_tbl_t **mail_table_data, int transaction, int *err_code);
+
+INTERNAL_FUNC int emstorage_get_thread_id_of_thread_mails(char *multi_user_name, emstorage_mail_tbl_t *mail_table_data, int *thread_id, int *result_latest_mail_id_in_thread, int *thread_item_count);
+
+INTERNAL_FUNC int emstorage_get_thread_id_by_mail_id(char *multi_user_name, int mail_id, int *thread_id, int *err_code);
+
+INTERNAL_FUNC int emstorage_update_latest_thread_mail(char *multi_user_name,
+ int account_id,
+ int mailbox_id,
+ int mailbox_type,
+ int thread_id,
+ int *updated_thread_id,
+ int latest_mail_id,
+ int thread_item_count,
+ int noti_type,
+ int transaction,
+ int *err_code);
+
+INTERNAL_FUNC int emstorage_get_thread_id_from_mailbox(char *multi_user_name, int account_id, int mailbox_id, char *mail_subject, int *thread_id, int *thread_item_count);
+
+INTERNAL_FUNC int emstorage_update_thread_id_of_mail(char *multi_user_name, int account_id, int mailbox_id, int mail_id, int thread_id, int thread_item_count, int transaction, int *err_code);
+
#ifdef __FEATURE_PARTIAL_BODY_DOWNLOAD__
#define BULK_PARTIAL_BODY_DOWNLOAD_COUNT 10
@@ -1490,18 +1531,27 @@ enum
ACTIVITY_TYPE_IDX_IN_MAIL_PARTIAL_BODY_ACTIVITY_TBL,
MAILBOX_ID_IDX_IN_MAIL_PARTIAL_BODY_ACTIVITY_TBL,
MAILBOX_NAME_IDX_IN_MAIL_PARTIAL_BODY_ACTIVITY_TBL,
+ MULTI_USER_NAME_IDX_IN_MAIL_PARTIAL_BODY_ACTIVITY_TBL
};
+INTERNAL_FUNC int emstorage_get_pbd_activity_data(char *multi_user_name, int account_id, int input_mailbox_id, email_event_partial_body_thd** event_start, int *count, int transaction, int *err_code);
+
+INTERNAL_FUNC int emstorage_add_pbd_activity(char *multi_user_name, email_event_partial_body_thd *local_activity, int *activity_id, int transaction, int *err_code);
+
+INTERNAL_FUNC int emstorage_get_pbd_mailbox_list(char *multi_user_name, int account_id, int **mailbox_list, int *count, int transaction, int *err_code);
+
+INTERNAL_FUNC int emstorage_get_pbd_account_list(char *multi_user_name, int **account_list, int *count, int transaction, int *err_code);
+
+INTERNAL_FUNC int emstorage_get_pbd_activity_count(char *multi_user_name, int *activity_id_count, int transaction, int *err_code);
+
+INTERNAL_FUNC int emstorage_delete_full_pbd_activity_data(char *multi_user_name, int account_id, int transaction, int *err_code);
+
+INTERNAL_FUNC int emstorage_delete_pbd_activity(char *multi_user_name, int account_id, int mail_id, int activity_id, int transaction, int *err_code);
+
+INTERNAL_FUNC int emstorage_get_mailbox_pbd_activity_count(char *multi_user_name, int account_id, int input_mailbox_id, int *activity_count, int transaction, int *err_code);
+
+INTERNAL_FUNC int emstorage_update_pbd_activity(char *multi_user_name, char *old_server_uid, char *new_server_uid, char *mbox_name, int *err_code);
-INTERNAL_FUNC int emstorage_get_pbd_activity_data(int account_id, int input_mailbox_id, email_event_partial_body_thd** event_start, int *count, int transaction, int *err_code);
-INTERNAL_FUNC int emstorage_add_pbd_activity(email_event_partial_body_thd *local_activity, int *activity_id, int transaction, int *err_code);
-INTERNAL_FUNC int emstorage_get_pbd_mailbox_list(int account_id, int **mailbox_list, int *count, int transaction, int *err_code);
-INTERNAL_FUNC int emstorage_get_pbd_account_list(int **account_list, int *count, int transaction, int *err_code);
-INTERNAL_FUNC int emstorage_get_pbd_activity_count(int *activity_id_count, int transaction, int *err_code);
-INTERNAL_FUNC int emstorage_delete_full_pbd_activity_data(int account_id, int transaction, int *err_code);
-INTERNAL_FUNC int emstorage_delete_pbd_activity(int account_id, int mail_id, int activity_id, int transaction, int *err_code);
-INTERNAL_FUNC int emstorage_get_mailbox_pbd_activity_count(int account_id, int input_mailbox_id, int *activity_count, int transaction, int *err_code);
-INTERNAL_FUNC int emstorage_update_pbd_activity(char *old_server_uid, char *new_server_uid, char *mbox_name, int *err_code);
INTERNAL_FUNC int emstorage_create_file(char *buf, size_t file_size, char *dst_file, int *err_code);
#endif
@@ -1511,7 +1561,7 @@ INTERNAL_FUNC int emstorage_free_address_info_list(email_address_info_list_t *
INTERNAL_FUNC void emstorage_create_dir_if_delete();
#ifdef __FEATURE_BULK_DELETE_MOVE_UPDATE_REQUEST_OPTI__
-INTERNAL_FUNC int emstorage_update_read_mail_uid_by_server_uid(char *old_server_uid, char *new_server_uid, char *mbox_name, int *err_code);
+INTERNAL_FUNC int emstorage_update_read_mail_uid_by_server_uid(char *multi_user_name, char *old_server_uid, char *new_server_uid, char *mbox_name, int *err_code);
/**
* @fn emstorage_get_id_set_from_mail_ids(int mail_ids[], int mail_id_count, email_id_set_t **server_uids, int *id_set_count, int *err_code);
@@ -1527,8 +1577,7 @@ INTERNAL_FUNC int emstorage_update_read_mail_uid_by_server_uid(char *old_server_
* SELECT local_uid, server_uid from mail_read_mail_uid_tbl where local_uid in (12, 13, 56, 78);
* @return This function returns true on success or false on failure.
*/
-
-INTERNAL_FUNC int emstorage_get_id_set_from_mail_ids(char *mail_ids, email_id_set_t **idset, int *id_set_count, int *err_code);
+INTERNAL_FUNC int emstorage_get_id_set_from_mail_ids(char *multi_user_name, char *mail_ids, email_id_set_t **idset, int *id_set_count, int *err_code);
#endif
@@ -1549,17 +1598,24 @@ INTERNAL_FUNC int emstorage_get_id_set_from_mail_ids(char *mail_ids, email_id_se
* @remarks
* @return This function returns true on success or false on failure.
*/
-INTERNAL_FUNC int emstorage_filter_mails_by_rule(int account_id, int dest_mailbox_id, int dest_mailbox_type, int reset, emstorage_rule_tbl_t *rule, int **filtered_mail_id_list, int *count_of_mails, int *err_code);
+INTERNAL_FUNC int emstorage_filter_mails_by_rule(char *multi_user_name, int account_id, int dest_mailbox_id, int dest_mailbox_type, int reset, emstorage_rule_tbl_t *rule, int **filtered_mail_id_list, int *count_of_mails, int *err_code);
+
+INTERNAL_FUNC int emstorage_update_tag_id(char *multi_user_name, int old_filter_id, int new_filter_id, int *err_code);
+
+INTERNAL_FUNC int emstorage_add_meeting_request(char *multi_user_name, int account_id, int input_mailbox_id, email_meeting_request_t *meeting_req, int transaction, int *err_code);
+
+INTERNAL_FUNC int emstorage_query_meeting_request(char *multi_user_name, const char *conditional_clause, email_meeting_request_t **output_meeting_req, int *output_result_count, int transaction);
+
+INTERNAL_FUNC int emstorage_get_meeting_request(char *multi_user_name, int mail_id, email_meeting_request_t **meeting_req, int transaction, int *err_code);
+
+INTERNAL_FUNC int emstorage_update_meeting_request(char *multi_user_name, email_meeting_request_t *meeting_req, int transaction, int *err_code);
+
+INTERNAL_FUNC int emstorage_delete_meeting_request(char *multi_user_name, int account_id, int mail_id, int input_mailbox_id, int transaction, int *err_code);
-INTERNAL_FUNC int emstorage_update_tag_id(int old_filter_id, int new_filter_id, int *err_code);
-INTERNAL_FUNC int emstorage_add_meeting_request(int account_id, int input_mailbox_id, email_meeting_request_t *meeting_req, int transaction, int *err_code);
-INTERNAL_FUNC int emstorage_query_meeting_request(const char *conditional_clause, email_meeting_request_t **output_meeting_req, int *output_result_count, int transaction);
-INTERNAL_FUNC int emstorage_get_meeting_request(int mail_id, email_meeting_request_t **meeting_req, int transaction, int *err_code);
-INTERNAL_FUNC int emstorage_update_meeting_request(email_meeting_request_t *meeting_req, int transaction, int *err_code);
-INTERNAL_FUNC int emstorage_delete_meeting_request(int account_id, int mail_id, int input_mailbox_id, int transaction, int *err_code);
INTERNAL_FUNC void emstorage_free_meeting_request(email_meeting_request_t *meeting_req);
-INTERNAL_FUNC int emstorage_write_conditional_clause_for_getting_mail_list(email_list_filter_t *input_filter_list, int input_filter_count, email_list_sorting_rule_t *input_sorting_rule_list, int input_sorting_rule_count, int input_start_index, int input_limit_count, char **output_conditional_clause);
+INTERNAL_FUNC int emstorage_write_conditional_clause_for_getting_mail_list(char *multi_user_name, email_list_filter_t *input_filter_list, int input_filter_count, email_list_sorting_rule_t *input_sorting_rule_list, int input_sorting_rule_count, int input_start_index, int input_limit_count, char **output_conditional_clause);
+
INTERNAL_FUNC int emstorage_free_list_filter(email_list_filter_t **input_filter_list, int input_filter_count);
#ifdef __FEATURE_LOCAL_ACTIVITY__
@@ -1616,45 +1672,45 @@ INTERNAL_FUNC int emstorage_free_activity_id_list(int *activity_id_list, int *er
#endif
-INTERNAL_FUNC int emstorage_add_certificate(emstorage_certificate_tbl_t *certificate, int transaction, int *err_code);
+INTERNAL_FUNC int emstorage_add_certificate(char *multi_user_name, emstorage_certificate_tbl_t *certificate, int transaction, int *err_code);
INTERNAL_FUNC int emstorage_free_certificate(emstorage_certificate_tbl_t **certificate_list, int count, int *err_code);
-INTERNAL_FUNC int emstorage_get_certificate_list(int *select_num, emstorage_certificate_tbl_t **certificate_list, int transaction, int with_password, int *err_code);
+INTERNAL_FUNC int emstorage_get_certificate_list(char *multi_user_name, int *select_num, emstorage_certificate_tbl_t **certificate_list, int transaction, int with_password, int *err_code);
-INTERNAL_FUNC int emstorage_get_certificate_by_email_address(char *email_address, emstorage_certificate_tbl_t **certificate, int transaction, int with_password, int *err_code);
+INTERNAL_FUNC int emstorage_get_certificate_by_email_address(char *multi_user_name, char *email_address, emstorage_certificate_tbl_t **certificate, int transaction, int with_password, int *err_code);
-INTERNAL_FUNC int emstorage_get_certificate_by_index(int index, emstorage_certificate_tbl_t **certificate, int transaction, int with_password, int *err_code);
+INTERNAL_FUNC int emstorage_get_certificate_by_index(char *multi_user_name, int index, emstorage_certificate_tbl_t **certificate, int transaction, int with_password, int *err_code);
-INTERNAL_FUNC int emstorage_delete_certificate(int index, int transaction, int *err_code);
+INTERNAL_FUNC int emstorage_delete_certificate(char *multi_user_name, int index, int transaction, int *err_code);
/* task begin */
-INTERNAL_FUNC int emstorage_add_task(email_task_type_t input_task_type, email_task_priority_t input_task_priority, char *input_task_parameter, int input_task_parameter_length, int input_transaction, int *output_task_id);
+INTERNAL_FUNC int emstorage_add_task(char *multi_user_name, email_task_type_t input_task_type, email_task_priority_t input_task_priority, char *input_task_parameter, int input_task_parameter_length, int input_transaction, int *output_task_id);
-INTERNAL_FUNC int emstorage_delete_task(int task_id, int transaction);
+INTERNAL_FUNC int emstorage_delete_task(char *multi_user_name, int task_id, int transaction);
-INTERNAL_FUNC int emstorage_update_task_status(int task_id, email_task_status_type_t task_status, int transaction);
+INTERNAL_FUNC int emstorage_update_task_status(char *multi_user_name, int task_id, email_task_status_type_t task_status, int transaction);
-INTERNAL_FUNC int emstorage_query_task(const char *input_conditional_clause, const char *input_ordering_clause, email_task_t **output_task_list, int *output_task_count);
+INTERNAL_FUNC int emstorage_query_task(char *multi_user_name, const char *input_conditional_clause, const char *input_ordering_clause, email_task_t **output_task_list, int *output_task_count);
/* task end*/
-INTERNAL_FUNC int emstorage_check_and_update_server_uid_by_message_id(int account_id, email_mailbox_type_e input_mailbox_type, char *message_id, char *server_uid, int *searched_mail_id);
+INTERNAL_FUNC int emstorage_check_and_update_server_uid_by_message_id(char *multi_user_name, int account_id, email_mailbox_type_e input_mailbox_type, char *message_id, char *server_uid, int *searched_mail_id);
#ifdef __FEATURE_WIFI_AUTO_DOWNLOAD__
-INTERNAL_FUNC int emstorage_add_auto_download_activity(email_event_auto_download *local_activity, int *activity_id, int transaction, int *err_code);
-INTERNAL_FUNC int emstorage_delete_auto_download_activity(int account_id, int mail_id, int activity_id, int transaction, int *err_code);
-INTERNAL_FUNC int emstorage_delete_all_auto_download_activity(int account_id, int transaction, int *err_code);
-INTERNAL_FUNC int emstorage_delete_auto_download_activity_by_mailbox(int account_id, int mailbox_id, int transaction, int *err_code);
-INTERNAL_FUNC int emstorage_get_auto_download_activity(int account_id, int input_mailbox_id, email_event_auto_download **event_start, int *count, int transaction, int *err_code);
-INTERNAL_FUNC int emstorage_get_auto_download_activity_count(int *activity_count, int transaction, int *err_code);
-INTERNAL_FUNC int emstorage_get_auto_download_account_list(int **account_list, int *count, int transaction, int *err_code);
-INTERNAL_FUNC int emstorage_get_auto_download_mailbox_list(int account_id, int **mailbox_list, int *count, int transaction, int *err_code);
-INTERNAL_FUNC int emstorage_get_auto_download_activity_count_by_mailbox(int account_id, int input_mailbox_id, int *activity_count, int transaction, int *err_code);
-INTERNAL_FUNC int emstorage_update_auto_download_activity(char *old_server_uid, char *new_server_uid, char *mailbox_name, int mailbox_id, int *err_code);
+INTERNAL_FUNC int emstorage_add_auto_download_activity(char *multi_user_name, email_event_auto_download *local_activity, int *activity_id, int transaction, int *err_code);
+INTERNAL_FUNC int emstorage_delete_auto_download_activity(char *multi_user_name, int account_id, int mail_id, int activity_id, int transaction, int *err_code);
+INTERNAL_FUNC int emstorage_delete_all_auto_download_activity(char *multi_user_name, int account_id, int transaction, int *err_code);
+INTERNAL_FUNC int emstorage_delete_auto_download_activity_by_mailbox(char *multi_user_name, int account_id, int mailbox_id, int transaction, int *err_code);
+INTERNAL_FUNC int emstorage_get_auto_download_activity(char *multi_user_name, int account_id, int input_mailbox_id, email_event_auto_download **event_start, int *count, int transaction, int *err_code);
+INTERNAL_FUNC int emstorage_get_auto_download_activity_count(char *multi_user_name, int *activity_count, int transaction, int *err_code);
+INTERNAL_FUNC int emstorage_get_auto_download_account_list(char *multi_user_name, int **account_list, int *count, int transaction, int *err_code);
+INTERNAL_FUNC int emstorage_get_auto_download_mailbox_list(char *multi_user_name, int account_id, int **mailbox_list, int *count, int transaction, int *err_code);
+INTERNAL_FUNC int emstorage_get_auto_download_activity_count_by_mailbox(char *multi_user_name, int account_id, int input_mailbox_id, int *activity_count, int transaction, int *err_code);
+INTERNAL_FUNC int emstorage_update_auto_download_activity(char *multi_user_name, char *old_server_uid, char *new_server_uid, char *mailbox_name, int mailbox_id, int *err_code);
#endif
#ifdef __FEATURE_UPDATE_DB_TABLE_SCHEMA__
-INTERNAL_FUNC int emstorage_update_db_table_schema();
+INTERNAL_FUNC int emstorage_update_db_table_schema(char *multi_user_name);
#endif /* __FEATURE_UPDATE_DB_TABLE_SCHEMA__ */
#ifdef __cplusplus
diff --git a/email-core/include/email-core-account.h b/email-core/include/email-core-account.h
index 3636eba..befaffb 100755
--- a/email-core/include/email-core-account.h
+++ b/email-core/include/email-core-account.h
@@ -40,13 +40,13 @@ extern "C"
{
#endif /* __cplusplus */
-INTERNAL_FUNC int emcore_validate_account(int account_id, int handle, int *err_code);
+INTERNAL_FUNC int emcore_validate_account(char *multi_user_name, int account_id, int handle, int *err_code);
-INTERNAL_FUNC int emcore_validate_account_with_account_info(email_account_t *account, email_event_type_t event_type, char **output_imap_cap_string, int event_handle, int *err_code);
+INTERNAL_FUNC int emcore_validate_account_with_account_info(char *multi_user_name, email_account_t *account, email_event_type_t event_type, char **output_imap_cap_string, int event_handle, int *err_code);
-INTERNAL_FUNC int emcore_create_account(email_account_t *account, int add_account_to_account_svc, int *err_code);
+INTERNAL_FUNC int emcore_create_account(char *multi_user_name, email_account_t *account, int add_account_to_account_svc, int *err_code);
-INTERNAL_FUNC int emcore_delete_account(int account_id, int input_delete_from_account_svc, int *err_code);
+INTERNAL_FUNC int emcore_delete_account(char *multi_user_name, int account_id, int input_delete_from_account_svc, int *err_code);
INTERNAL_FUNC int emcore_free_account_list(email_account_t **account_list, int count, int *err_code);
@@ -56,31 +56,31 @@ INTERNAL_FUNC void emcore_free_account(email_account_t *account_list);
INTERNAL_FUNC void emcore_duplicate_account(const email_account_t *account, email_account_t **account_dup, int *err_code);
-INTERNAL_FUNC int emcore_init_account_reference();
+INTERNAL_FUNC email_account_t *emcore_get_account_reference(char *multi_user_name, int account_id, int with_password);
-INTERNAL_FUNC int emcore_add_account_reference(email_account_t *account);
+INTERNAL_FUNC int emcore_get_account_reference_list(char *multi_user_name, email_account_t **account_list, int *count);
-INTERNAL_FUNC int emcore_free_account_reference();
+INTERNAL_FUNC int emcore_query_server_info(const char* domain_name, email_server_info_t **result_server_info);
-INTERNAL_FUNC email_account_t *emcore_get_account_reference(int account_id);
+INTERNAL_FUNC void emcore_cleanup_query_server_info(void);
-INTERNAL_FUNC int emcore_get_account_reference_list(email_account_t **account_list, int *count, int *err_code);
+INTERNAL_FUNC int emcore_free_server_info(email_server_info_t **target_server_info);
-INTERNAL_FUNC int emcore_save_default_account_id(int input_account_id);
+INTERNAL_FUNC int emcore_save_default_account_id(char *multi_user_name, int input_account_id);
-INTERNAL_FUNC int emcore_load_default_account_id(int *output_account_id);
+INTERNAL_FUNC int emcore_load_default_account_id(char *multi_user_name, int *output_account_id);
-INTERNAL_FUNC int emcore_recover_from_secured_storage_failure();
+INTERNAL_FUNC int emcore_recover_from_secured_storage_failure(char *multi_user_name);
-INTERNAL_FUNC int emcore_update_sync_status_of_account(int input_account_id, email_set_type_t input_set_operator, int input_sync_status);
+INTERNAL_FUNC int emcore_update_sync_status_of_account(char *multi_user_name, int input_account_id, email_set_type_t input_set_operator, int input_sync_status);
-INTERNAL_FUNC int emcore_refresh_xoauth2_access_token(int input_account_id);
+INTERNAL_FUNC int emcore_refresh_xoauth2_access_token(char *multi_user_name, int input_account_id);
#ifdef __FEATURE_BACKUP_ACCOUNT__
-INTERNAL_FUNC int emcore_backup_accounts(const char *file_path, int *error_code);
+INTERNAL_FUNC int emcore_backup_accounts(char *multi_user_name, const char *file_path, int *error_code);
-INTERNAL_FUNC int emcore_restore_accounts(const char *file_path);
+INTERNAL_FUNC int emcore_restore_accounts(char *multi_user_name, const char *file_path);
#endif /* __FEATURE_BACKUP_ACCOUNT_ */
#ifdef __cplusplus
diff --git a/email-core/include/email-core-alarm.h b/email-core/include/email-core-alarm.h
index df2ce6c..d78f2bc 100755
--- a/email-core/include/email-core-alarm.h
+++ b/email-core/include/email-core-alarm.h
@@ -47,11 +47,12 @@ typedef struct _email_alarm_data_t {
int reference_id;
time_t trigger_at_time;
int (*alarm_callback)(struct _email_alarm_data_t*, void *);
+ char *multi_user_name;
void *user_data;
} email_alarm_data_t;
-INTERNAL_FUNC int emcore_add_alarm(time_t input_trigger_at_time, email_alarm_class_t input_class_id, int input_reference_id, int (*input_alarm_callback)(email_alarm_data_t*, void *), void *input_user_data);
+INTERNAL_FUNC int emcore_add_alarm(char *multi_user_name, time_t input_trigger_at_time, email_alarm_class_t input_class_id, int input_reference_id, int (*input_alarm_callback)(email_alarm_data_t*, void *), void *input_user_data);
INTERNAL_FUNC int emcore_delete_alram_data_from_alarm_data_list(email_alarm_data_t *input_alarm_data);
INTERNAL_FUNC int emcore_delete_alram_data_by_reference_id(email_alarm_class_t input_class_id, int input_reference_id);
diff --git a/email-core/include/email-core-auto-download.h b/email-core/include/email-core-auto-download.h
index 268b571..d4b863d 100755
--- a/email-core/include/email-core-auto-download.h
+++ b/email-core/include/email-core-auto-download.h
@@ -35,6 +35,7 @@ typedef struct auto_download_t
int mail_id;
unsigned long server_mail_id;
int mailbox_id;
+ char *multi_user_name;
} email_event_auto_download;
INTERNAL_FUNC int emcore_start_auto_download_loop(int *err_code);
@@ -46,9 +47,9 @@ INTERNAL_FUNC int emcore_is_auto_download_queue_empty(void);
INTERNAL_FUNC int emcore_is_auto_download_queue_full(void);
INTERNAL_FUNC int emcore_clear_auto_download_queue(void);
-INTERNAL_FUNC int emcore_insert_auto_download_job(int account_id, int mailbox_id, int mail_id, int auto_download_on, char *uid, int *err_code);
+INTERNAL_FUNC int emcore_insert_auto_download_job(char *multi_user_name, int account_id, int mailbox_id, int mail_id, int auto_download_on, char *uid, int *err_code);
INTERNAL_FUNC int emcore_insert_auto_download_activity(email_event_auto_download *local_activity, int *activity_id, int *err_code);
-INTERNAL_FUNC int emcore_delete_auto_download_activity(int account_id, int mail_id, int activity_id, int *err_code);
+INTERNAL_FUNC int emcore_delete_auto_download_activity(char *multi_user_name, int account_id, int mail_id, int activity_id, int *err_code);
#endif
#ifdef __cplusplus
diff --git a/email-core/include/email-core-cert.h b/email-core/include/email-core-cert.h
index c0732f7..1257fb7 100755
--- a/email-core/include/email-core-cert.h
+++ b/email-core/include/email-core-cert.h
@@ -39,9 +39,9 @@
#include "email-utilities.h"
#include "email-types.h"
-INTERNAL_FUNC int emcore_add_public_certificate(char *public_cert_path, char *save_name, int *err_code);
+INTERNAL_FUNC int emcore_add_public_certificate(char *multi_user_name, char *public_cert_path, char *save_name, int *err_code);
-INTERNAL_FUNC int emcore_delete_public_certificate(char *email_address, int *err_code);
+INTERNAL_FUNC int emcore_delete_public_certificate(char *multi_user_name, char *email_address, int *err_code);
INTERNAL_FUNC int emcore_verify_signature(char *p7s_file_path, char *mime_entity, int *validity, int *err_code);
diff --git a/email-core/include/email-core-container.h b/email-core/include/email-core-container.h
new file mode 100644
index 0000000..663b1f6
--- /dev/null
+++ b/email-core/include/email-core-container.h
@@ -0,0 +1,45 @@
+/*
+* email-service
+*
+* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+*
+* Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com>
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*
+*/
+
+/**
+ *
+ * This file contains functionality related to KNOX
+ * to interact with email-service.
+ * @file email-core-container.c
+ * @author
+ * @version 0.1
+ * @brief This file contains functionality to provide KNOX support in email-service.
+ */
+
+#include <glib.h>
+#include "email-internal-types.h"
+
+INTERNAL_FUNC void emcore_create_container();
+INTERNAL_FUNC void emcore_destroy_container();
+INTERNAL_FUNC void emcore_bind_vsm_context();
+INTERNAL_FUNC int emcore_get_container_path(char *multi_user_name, char **container_path);
+INTERNAL_FUNC int emcore_get_user_name(int pid, char **multi_user_name);
+INTERNAL_FUNC int emcore_lookup_zone_by_name(char *user_name);
+INTERNAL_FUNC void emcore_set_declare_link(const char *file_path);
+INTERNAL_FUNC int emcore_get_zone_name_list(GList **output_name_list);
+INTERNAL_FUNC int emcore_get_canonicalize_path(char *db_path, char **output_path);
+INTERNAL_FUNC int emcore_set_join_zone(char *multi_user_name, void **join_zone);
+INTERNAL_FUNC void emcore_unset_join_zone(void *join_zone);
diff --git a/email-core/include/email-core-event.h b/email-core/include/email-core-event.h
index 43a8ec2..006107e 100755
--- a/email-core/include/email-core-event.h
+++ b/email-core/include/email-core-event.h
@@ -58,7 +58,7 @@ INTERNAL_FUNC int emcore_check_send_mail_thread_status(void);
INTERNAL_FUNC void emcore_get_event_queue_status(int *on_sending, int *on_receiving);
INTERNAL_FUNC int emcore_insert_event_for_sending_mails(email_event_t *event_data, int *handle, int *err_code);
INTERNAL_FUNC int emcore_get_receiving_event_queue(email_event_t **event_queue, int *event_count, int *err);
-INTERNAL_FUNC int emcore_cancel_all_threads_of_an_account(int account_id);
+INTERNAL_FUNC int emcore_cancel_all_threads_of_an_account(char *multi_user_name, int account_id);
INTERNAL_FUNC int emcore_free_event(email_event_t *event_data);
INTERNAL_FUNC int emcore_get_task_information(email_task_information_t **output_task_information, int *output_task_information_count);
diff --git a/email-core/include/email-core-gmime.h b/email-core/include/email-core-gmime.h
index e542b3c..bb0a130 100644
--- a/email-core/include/email-core-gmime.h
+++ b/email-core/include/email-core-gmime.h
@@ -71,6 +71,11 @@ INTERNAL_FUNC int emcore_gmime_fetch_imap_attachment_section(MAILSTREAM *stream,
INTERNAL_FUNC int emcore_gmime_check_filename_duplication(char *source_filename, struct _m_content_info *cnt_info);
INTERNAL_FUNC char *emcore_gmime_get_modified_filename_in_duplication(char *source_filename);
INTERNAL_FUNC char *emcore_gmime_get_encoding_to_utf8(const char *text);
+INTERNAL_FUNC char *emcore_gmime_get_decoding_text(const char *text);
+INTERNAL_FUNC void emcore_gmime_get_mime_entity_cb(GMimeObject *parent, GMimeObject *part, gpointer user_data);
+INTERNAL_FUNC char *emcore_gmime_get_mime_entity_signed_message(GMimeObject *multipart);
+INTERNAL_FUNC char *emcore_gmime_get_mime_entity(int fd);
+
#ifdef __cplusplus
}
#endif /* __cplusplus */
diff --git a/email-core/include/email-core-imap-mailbox.h b/email-core/include/email-core-imap-mailbox.h
index 58c557d..585cf8b 100755
--- a/email-core/include/email-core-imap-mailbox.h
+++ b/email-core/include/email-core-imap-mailbox.h
@@ -33,7 +33,6 @@
#ifndef __EMAIL_CORE_IMAP_MAILBOX_H__
#define __EMAIL_CORE_IMAP_MAILBOX_H__
-
#ifdef __cplusplus
extern "C"
{
@@ -50,7 +49,7 @@ extern "C"
* @remarks N/A
* @return This function returns true on success or false on failure.
*/
-INTERNAL_FUNC int emcore_sync_mailbox_list(int account_id, char *mailbox, int event_handle, int *err_code);
+INTERNAL_FUNC int emcore_sync_mailbox_list(char *multi_user_name, int account_id, char *mailbox, int event_handle, int *err_code);
/**
* Download mailbox list from imap server.
@@ -64,12 +63,12 @@ INTERNAL_FUNC int emcore_sync_mailbox_list(int account_id, char *mailbox, int ev
* @return This function returns true on success or false on failure.
*/
INTERNAL_FUNC int emcore_download_mailbox_list(void *mail_stream, char *mailbox, email_internal_mailbox_t **mailbox_list, int *count, int *err_code);
-INTERNAL_FUNC int emcore_delete_imap_mailbox(int input_mailbox_id, int *err_code);
-INTERNAL_FUNC int emcore_create_imap_mailbox(email_mailbox_t *mailbox, int *err_code);
-INTERNAL_FUNC int emcore_rename_mailbox_on_imap_server(int input_account_id, int input_mailbox_id, char *input_old_mailbox_path, char *input_new_mailbox_path, int handle_to_be_published);
-INTERNAL_FUNC int emcore_set_mail_slot_size(int account_id, int mailbox_id, int new_slot_size, int *err_code);
-INTERNAL_FUNC int emcore_remove_overflowed_mails(emstorage_mailbox_tbl_t *intput_mailbox_tbl, int *err_code);
-INTERNAL_FUNC int emcore_get_default_mail_slot_count(int input_account_id, int *output_count);
+INTERNAL_FUNC int emcore_delete_imap_mailbox(char *multi_user_name, int input_mailbox_id, int *err_code);
+INTERNAL_FUNC int emcore_create_imap_mailbox(char *multi_user_name, email_mailbox_t *mailbox, int *err_code);
+INTERNAL_FUNC int emcore_rename_mailbox_on_imap_server(char *multi_user_name, int input_account_id, int input_mailbox_id, char *input_old_mailbox_path, char *input_new_mailbox_path, int handle_to_be_published);
+INTERNAL_FUNC int emcore_set_mail_slot_size(char *multi_user_name, int account_id, int mailbox_id, int new_slot_size, int *err_code);
+INTERNAL_FUNC int emcore_remove_overflowed_mails(char *multi_user_name, emstorage_mailbox_tbl_t *intput_mailbox_tbl, int *err_code);
+INTERNAL_FUNC int emcore_get_default_mail_slot_count(char *multi_user_name, int input_account_id, int *output_count);
#ifdef __FEATURE_IMAP_QUOTA__
INTERNAL_FUNC int emcore_register_quota_callback();
diff --git a/email-core/include/email-core-mail.h b/email-core/include/email-core-mail.h
index 83fb206..78312db 100755
--- a/email-core/include/email-core-mail.h
+++ b/email-core/include/email-core-mail.h
@@ -217,6 +217,7 @@ struct _m_content_info
int total_body_size;
int total_attachment_size;
int attachment_only;
+ int content_type; /* 1 : signed */
char *sections;
struct text_data
@@ -227,6 +228,7 @@ struct _m_content_info
int html_save_status;
char *html; /* body html text */
char *html_charset; /* charset of html text */
+ char *mime_entity;
} text;
struct attachment_info *file;
@@ -243,33 +245,6 @@ typedef enum {
} pop3_cmd_t;
/**
- * Download email body from server.
- *
- * @param[in] mail_stream Specifies the mail_stream.
- * @param[in] mailbox Specifies the mailbox to contain account ID.
- * @param[in] mail_id Specifies the mail ID.
- * @param[in] callback Specifies the callback function for retrieving download status.
- * @param[in] with_attach Specifies the flag for downloading attachments.
- * @param[in] limited_size Specifies the size to be downloaded.
- * @param[out] err_code Specifies the error code returned.
- * @remarks In POP3 case, body and attachment are downloaded in this function.
- * In IMAP case, body and attachment list are downloaded and
- * attachments must be downloaded in emcore_download_attachment.
- * @return This function returns true on success or false on failure.
- */
-
-INTERNAL_FUNC int emcore_download_body_multi_sections_bulk ( void *mail_stream,
- int account_id,
- int mail_id,
- int verbose,
- int with_attach,
- int limited_size,
- int event_handle,
- int cancellable,
- int *err_code);
-
-
-/**
* Download a email nth-attachment from server.
*
* @param[in] mailbox Specifies the mailbox to contain account ID.
@@ -281,50 +256,49 @@ INTERNAL_FUNC int emcore_download_body_multi_sections_bulk ( void *mail_stream,
* @remarks This function is used for only IMAP mail.
* @return This function returns true on success or false on failure.
*/
-INTERNAL_FUNC int emcore_download_attachment (int acconut_id, int mail_id, int nth, int cancellable, int event_handle, int *err_code);
-INTERNAL_FUNC int emcore_add_attachment(int mail_id, email_attachment_data_t *attachment, int *err_code); /* TODO : Remove duplicated function */
-INTERNAL_FUNC int emcore_add_attachment_data(int input_mail_id, email_attachment_data_t *input_attachment_data); /* TODO : Remove duplicated function */
-INTERNAL_FUNC int emcore_delete_mail_attachment(int attachment_id, int *err_code);
-INTERNAL_FUNC int emcore_get_attachment_info(int attachment_id, email_attachment_data_t **attachment, int *err_code);
-INTERNAL_FUNC int emcore_get_attachment_data_list(int input_mail_id, email_attachment_data_t **output_attachment_data, int *output_attachment_count);
+INTERNAL_FUNC int emcore_add_attachment(char *multi_user_name, int mail_id, email_attachment_data_t *attachment, int *err_code); /* TODO : Remove duplicated function */
+INTERNAL_FUNC int emcore_add_attachment_data(char *multi_user_name, int input_mail_id, email_attachment_data_t *input_attachment_data); /* TODO : Remove duplicated function */
+INTERNAL_FUNC int emcore_delete_mail_attachment(char *multi_user_name, int attachment_id, int *err_code);
+INTERNAL_FUNC int emcore_get_attachment_info(char *multi_user_name, int attachment_id, email_attachment_data_t **attachment, int *err_code);
+INTERNAL_FUNC int emcore_get_attachment_data_list(char *multi_user_name, int input_mail_id, email_attachment_data_t **output_attachment_data, int *output_attachment_count);
INTERNAL_FUNC int emcore_free_attachment_data(email_attachment_data_t **attachment_data_list, int attachment_data_count, int *err_code);
-INTERNAL_FUNC int emcore_gmime_download_attachment(int mail_id, int nth,
+INTERNAL_FUNC int emcore_gmime_download_attachment(char *multi_user_name, int mail_id, int nth,
int cancellable, int event_handle, int auto_download, int *err_code);
-INTERNAL_FUNC int emcore_gmime_download_body_sections(void *mail_stream,
+INTERNAL_FUNC int emcore_gmime_download_body_sections(char *multi_user_name, void *mail_stream,
int account_id, int mail_id, int with_attach, int limited_size,
int event_handle, int cancellable, int auto_download, int *err_code);
-INTERNAL_FUNC int emcore_move_mail(int mail_ids[], int num, int dst_mailbox_id, int noti_param_1, int noti_param_2, int *err_code);
+INTERNAL_FUNC int emcore_move_mail(char *multi_user_name, int mail_ids[], int num, int dst_mailbox_id, int noti_param_1, int noti_param_2, int *err_code);
#ifdef __FEATURE_PARTIAL_BODY_DOWNLOAD__
INTERNAL_FUNC int emcore_insert_pbd_activity(email_event_partial_body_thd *local_activity, int *activity_id, int *err_code) ;
-INTERNAL_FUNC int emcore_delete_pbd_activity(int account_id, int mail_id, int activity_id, int *err_code);
+INTERNAL_FUNC int emcore_delete_pbd_activity(char *multi_user_name, int account_id, int mail_id, int activity_id, int *err_code);
#endif
-INTERNAL_FUNC int emcore_get_mail_contact_info(email_mail_contact_info_t *contact_info, char *full_address, int *err_code);
-INTERNAL_FUNC int emcore_get_mail_contact_info_with_update(email_mail_contact_info_t *contact_info, char *full_address, int mail_id, int *err_code);
+INTERNAL_FUNC int emcore_get_mail_contact_info(char *multi_user_name, email_mail_contact_info_t *contact_info, char *full_address, int *err_code);
+INTERNAL_FUNC int emcore_get_mail_contact_info_with_update(char *multi_user_name, email_mail_contact_info_t *contact_info, char *full_address, int mail_id, int *err_code);
INTERNAL_FUNC int emcore_free_contact_info(email_mail_contact_info_t *contact_info, int *err_code);
-INTERNAL_FUNC int emcore_sync_contact_info(int mail_id, int *err_code);
-INTERNAL_FUNC GList *emcore_get_recipients_list(GList *old_recipients_list, char *full_address, int *err_code);
-INTERNAL_FUNC int emcore_get_mail_address_info_list(int mail_id, email_address_info_list_t **address_info_list, int *err_code);
+INTERNAL_FUNC int emcore_sync_contact_info(char *multi_user_name, int mail_id, int *err_code);
+INTERNAL_FUNC GList *emcore_get_recipients_list(char *multi_user_name, GList *old_recipients_list, char *full_address, int *err_code);
+INTERNAL_FUNC int emcore_get_mail_address_info_list(char *multi_user_name, int mail_id, email_address_info_list_t **address_info_list, int *err_code);
-INTERNAL_FUNC int emcore_set_sent_contacts_log(emstorage_mail_tbl_t *input_mail_data);
-INTERNAL_FUNC int emcore_set_received_contacts_log(emstorage_mail_tbl_t *input_mail_data);
-INTERNAL_FUNC int emcore_delete_contacts_log(int input_account_id);
+INTERNAL_FUNC int emcore_set_sent_contacts_log(char *multi_user_name, emstorage_mail_tbl_t *input_mail_data);
+INTERNAL_FUNC int emcore_set_received_contacts_log(char *multi_user_name, emstorage_mail_tbl_t *input_mail_data);
+INTERNAL_FUNC int emcore_delete_contacts_log(char *multi_user_name, int input_account_id);
-INTERNAL_FUNC int emcore_get_mail_display_name(char *email_address, char **contact_display_name);
-INTERNAL_FUNC int emcore_get_mail_display_name_internal (char *email_address, char **contact_display_name);
-INTERNAL_FUNC int emcore_get_mail_data(int input_mail_id, email_mail_data_t **output_mail_data);
+INTERNAL_FUNC int emcore_get_mail_display_name(char *multi_user_name, char *email_address, char **contact_display_name);
+INTERNAL_FUNC int emcore_get_mail_display_name_internal(char *multi_user_name, char *email_address, char **contact_display_name);
+INTERNAL_FUNC int emcore_get_mail_data(char *multi_user_name, int input_mail_id, email_mail_data_t **output_mail_data);
-INTERNAL_FUNC int emcore_update_mail(email_mail_data_t *input_mail_data, email_attachment_data_t *input_attachment_data_list, int input_attachment_count, email_meeting_request_t* input_meeting_request, int sync_server);
+INTERNAL_FUNC int emcore_update_mail(char *multi_user_name, email_mail_data_t *input_mail_data, email_attachment_data_t *input_attachment_data_list, int input_attachment_count, email_meeting_request_t* input_meeting_request, int sync_server);
-INTERNAL_FUNC int emcore_delete_mails_from_local_storage(int account_id, int *mail_ids, int num, int noti_param_1, int noti_param_2, int *err_code);
+INTERNAL_FUNC int emcore_delete_mails_from_local_storage(char *multi_user_name, int account_id, int *mail_ids, int num, int noti_param_1, int noti_param_2, int *err_code);
INTERNAL_FUNC int emcore_get_mail_msgno_by_uid(email_account_t *account, email_internal_mailbox_t *mailbox, char *uid, int *msgno, int *err_code);
-INTERNAL_FUNC int emcore_expunge_mails_deleted_flagged_from_local_storage(int input_mailbox_id);
-INTERNAL_FUNC int emcore_expunge_mails_deleted_flagged_from_remote_server(int input_account_id, int input_mailbox_id);
+INTERNAL_FUNC int emcore_expunge_mails_deleted_flagged_from_local_storage(char *multi_user_name, int input_mailbox_id);
+INTERNAL_FUNC int emcore_expunge_mails_deleted_flagged_from_remote_server(char *multi_user_name, int input_account_id, int input_mailbox_id);
/**
* Delete mails.
@@ -340,7 +314,7 @@ INTERNAL_FUNC int emcore_expunge_mails_deleted_flagged_from_remote_server(int in
* @remarks N/A
* @return This function returns true on success or false on failure.
*/
-INTERNAL_FUNC int emcore_delete_mail(int account_id, int mail_id[], int num, int from_server, int noti_param_1, int noti_param_2, int *err_code);
+INTERNAL_FUNC int emcore_delete_mail(char *multi_user_name, int account_id, int mail_id[], int num, int from_server, int noti_param_1, int noti_param_2, int *err_code);
/**
* Delete mails.
@@ -351,38 +325,62 @@ INTERNAL_FUNC int emcore_delete_mail(int account_id, int mail_id[], int num, int
* @remarks N/A
* @return This function returns true on success or false on failure.
*/
-INTERNAL_FUNC int emcore_delete_all_mails_of_acount(int input_account_id);
-INTERNAL_FUNC int emcore_delete_all_mails_of_mailbox(int input_account_id, int input_mailbox_id, int input_from_server, int *err_code);
+INTERNAL_FUNC int emcore_delete_all_mails_of_acount(char *multi_user_name, int input_account_id);
+INTERNAL_FUNC int emcore_delete_all_mails_of_mailbox(char *multi_user_name,
+ int input_account_id,
+ int input_mailbox_id,
+ int input_mailbox_type,
+ int input_from_server,
+ int *err_code);
INTERNAL_FUNC void emcore_free_mail_data_list(email_mail_data_t **mail_list, int count);
INTERNAL_FUNC void emcore_free_mail_data(email_mail_data_t *mail);
INTERNAL_FUNC void emcore_free_content_info(struct _m_content_info *cnt_info);
INTERNAL_FUNC void emcore_free_attachment_info(struct attachment_info *attchment);
-INTERNAL_FUNC int emcore_move_mail_on_server(int account_id, int src_mailbox_id, int mail_ids[], int num, char *dest_mailbox, int *error_code);
+INTERNAL_FUNC int emcore_move_mail_on_server(char *multi_user_name, int account_id, int src_mailbox_id, int mail_ids[], int num, char *dest_mailbox, int *error_code);
INTERNAL_FUNC int emcore_move_mail_on_server_by_server_mail_id(void *mail_stream, char *server_mail_id, char *dest_mailbox_name);
-INTERNAL_FUNC int emcore_move_mail_to_another_account(int input_mail_id, int input_source_mailbox_id, int input_target_mailbox_id, int input_task_id);
-INTERNAL_FUNC int emcore_sync_flag_with_server(int mail_id, int event_handle, int *err_code);
-INTERNAL_FUNC int emcore_sync_seen_flag_with_server(int mail_ids[], int num, int event_handle, int *err_code);
+INTERNAL_FUNC int emcore_move_mail_to_another_account(char *multi_user_name, int input_mail_id, int input_source_mailbox_id, int input_target_mailbox_id, int input_task_id);
+INTERNAL_FUNC int emcore_sync_flag_with_server(char *multi_user_name, int mail_id, int event_handle, int *err_code);
+INTERNAL_FUNC int emcore_sync_seen_flag_with_server(char *multi_user_name, int mail_ids[], int num, int event_handle, int *err_code);
-INTERNAL_FUNC int emcore_set_flags_field(int account_id, int mail_ids[], int num, email_flags_field_type field_type, int value, int *err_code);
-INTERNAL_FUNC char* emcore_convert_mutf7_to_utf8(char *mailbox_name);
+INTERNAL_FUNC int emcore_set_flags_field(char *multi_user_name, int account_id, int mail_ids[], int num, email_flags_field_type field_type, int value, int *err_code);
INTERNAL_FUNC int emcore_convert_string_to_structure(const char *encoded_string, void **struct_var, email_convert_struct_type_e type);
-INTERNAL_FUNC int emcore_save_mail_file(int account_id, int mail_id, int attachment_id, char *src_file_path, char *file_name, char *full_path, int max_path_len, int *err_code);
+INTERNAL_FUNC int emcore_save_mail_file(char *multi_user_name, int account_id, int mail_id, int attachment_id, char *src_file_path, char *file_name, char *full_path, char *virtual_path, int *err_code);
#ifdef __FEATURE_BULK_DELETE_MOVE_UPDATE_REQUEST_OPTI__
-INTERNAL_FUNC int emcore_sync_flags_field_with_server(int mail_ids[], int num, email_flags_field_type field_type, int value, int *err_code);
-INTERNAL_FUNC int emcore_move_mail_on_server_ex(int account_id, int src_mailbox_id, int mail_ids[], int num, int dest_mailbox_id, int *error_code);
+INTERNAL_FUNC int emcore_sync_flags_field_with_server(char *multi_user_name, int mail_ids[], int num, email_flags_field_type field_type, int value, int *err_code);
+INTERNAL_FUNC int emcore_move_mail_on_server_ex(char *multi_user_name, int account_id, int src_mailbox_id, int mail_ids[], int num, int dest_mailbox_id, int *error_code);
#endif
#ifdef __ATTACHMENT_OPTI__
INTERNAL_FUNC int emcore_download_attachment_bulk(/*email_mailbox_t *mailbox, */ int account_id, int mail_id, char *nth, int event_handle, int *err_code);
#endif
-INTERNAL_FUNC int emcore_mail_filter_by_rule(email_rule_t *filter_info, int *err_code);
-INTERNAL_FUNC int emcore_add_rule(email_rule_t *filter_info);
-INTERNAL_FUNC int emcore_update_rule(int filter_id, email_rule_t *filter_info);
-INTERNAL_FUNC int emcore_delete_rule(int filter_id);
+INTERNAL_FUNC int emcore_mail_filter_by_rule(char *multi_user_name, email_rule_t *filter_info, int *err_code);
+INTERNAL_FUNC int emcore_add_rule(char *multi_user_name, email_rule_t *filter_info);
+INTERNAL_FUNC int emcore_update_rule(char *multi_user_name, int filter_id, email_rule_t *filter_info);
+INTERNAL_FUNC int emcore_delete_rule(char *multi_user_name, int filter_id);
+
+/**
+ * Search the mails on server
+ *
+ * @param[in] account_id Specifies the id of account
+ * @param[in] mailbox_id Specifies the id of mailbox
+ * @param[in] input_search_filter Specifies the filter list for searching field
+ * @param[in] input_search_filter_count Specifies the filter count
+ * @param[in] cancellable Specifies the cancellable
+ * @param[in] handle Specifies the handle for searching mails
+ * @remarks N/A
+ * @return EMAIL_ERROR_NONE on success or an error code (refer to EMAIL_ERROR_XXX) on failure
+ */
+INTERNAL_FUNC int emcore_search_on_server(char *multi_user_name,
+ int account_id,
+ int mailbox_id,
+ email_search_filter_t *input_search_filter,
+ int input_search_filter_count,
+ int cancellable,
+ int event_handle);
#ifdef __cplusplus
}
#endif /* __cplusplus */
diff --git a/email-core/include/email-core-mailbox-sync.h b/email-core/include/email-core-mailbox-sync.h
index 9383257..52d4165 100755
--- a/email-core/include/email-core-mailbox-sync.h
+++ b/email-core/include/email-core-mailbox-sync.h
@@ -77,12 +77,12 @@ int imap4_mailbox_get_uids(MAILSTREAM *stream, char *input_target_uid_string, em
int emcore_check_rule(const char *input_full_address_from, const char *input_subject, emstorage_rule_tbl_t *rule, int rule_len, int *priority_sender, int *blocked, int *err_code);
-INTERNAL_FUNC int emcore_make_mail_tbl_data_from_envelope(int account_id, MAILSTREAM *mail_stream, ENVELOPE *input_envelope, emcore_uid_list *input_uid_elem, emstorage_mail_tbl_t **output_mail_tbl_data, int *err_code);
+INTERNAL_FUNC int emcore_make_mail_tbl_data_from_envelope(char *multi_user_name, int account_id, MAILSTREAM *mail_stream, ENVELOPE *input_envelope, emcore_uid_list *input_uid_elem, emstorage_mail_tbl_t **output_mail_tbl_data, int *err_code);
-INTERNAL_FUNC int emcore_add_mail_to_mailbox(emstorage_mailbox_tbl_t *input_maibox_data, emstorage_mail_tbl_t *input_new_mail_tbl_data, int *output_mail_id, int *output_thread_id);
+INTERNAL_FUNC int emcore_add_mail_to_mailbox(char *multi_user_name, emstorage_mailbox_tbl_t *input_maibox_data, emstorage_mail_tbl_t *input_new_mail_tbl_data, int *output_mail_id, int *output_thread_id);
#ifdef __FEATURE_BODY_SEARCH__
-int emcore_add_mail_text(emstorage_mailbox_tbl_t *input_maibox_data, emstorage_mail_tbl_t *input_new_mail_tbl_data, char *stripped_text, int *err_code);
+int emcore_add_mail_text(char *multi_user_name, emstorage_mailbox_tbl_t *input_maibox_data, emstorage_mail_tbl_t *input_new_mail_tbl_data, char *stripped_text, int *err_code);
#endif
/**
@@ -96,7 +96,8 @@ int emcore_add_mail_text(emstorage_mailbox_tbl_t *input_maibox_data, emstorage_m
* @remarks N/A
* @return This function returns true on success or false on failure.
*/
-INTERNAL_FUNC int emcore_sync_header (emstorage_mailbox_tbl_t *input_mailbox_tbl,
+INTERNAL_FUNC int emcore_sync_header (char *multi_user_name,
+ emstorage_mailbox_tbl_t *input_mailbox_tbl,
void **stream,
emcore_uid_list **input_uid_list,
int *mail_count,
@@ -126,7 +127,7 @@ typedef enum
* @remarks N/A
* @return This function returns true on success or false on failure.
*/
-int emcore_download_uid_all (MAILSTREAM *mail_stream, email_internal_mailbox_t *mailbox, emcore_uid_list **uid_list,
+int emcore_download_uid_all (char *multi_user_name, MAILSTREAM *mail_stream, email_internal_mailbox_t *mailbox, emcore_uid_list **uid_list,
int *total, emstorage_read_mail_uid_tbl_t *read_mail_uids, int count,
emcore_get_uids_for_delete_t for_delete, int *err_code);
@@ -142,7 +143,7 @@ int emcore_download_uid_all (MAILSTREAM *mail_stream, email_internal_mailbox_t *
* @remarks N/A
* @return This function returns true on success or false on failure.
*/
-int emcore_download_imap_msgno(email_internal_mailbox_t *mailbox, char *uid, int *msgno, int *err_code);
+int emcore_download_imap_msgno(char *multi_user_name, email_internal_mailbox_t *mailbox, char *uid, int *msgno, int *err_code);
/**
* Get a message number to be related to uid.
@@ -177,12 +178,26 @@ int emcore_get_uid(emcore_uid_list *uid_list, int msgno, char **uid, int *err_co
*/
int emcore_free_uids(emcore_uid_list *uid_list, int *err_code);
-INTERNAL_FUNC char *emcore_guess_charset(char *source_string);
-INTERNAL_FUNC int emcore_sync_mail_from_client_to_server(int mail_id);
-INTERNAL_FUNC int emcore_update_attachment_except_inline(struct _m_content_info *cnt_info, int account_id, int mail_id, int mailbox_id, int *output_total_attachment_size, int *output_attachment_count, int *output_inline_attachment_count);
+INTERNAL_FUNC int emcore_sync_mail_from_client_to_server(char *multi_user_name, int mail_id);
+INTERNAL_FUNC int emcore_update_attachment_except_inline(char *multi_user_name,
+ struct _m_content_info *cnt_info,
+ int account_id,
+ int mail_id,
+ int mailbox_id,
+ int *output_total_attachment_size,
+ int *output_attachment_count,
+ int *output_inline_attachment_count);
#ifdef __FEATURE_PARTIAL_BODY_DOWNLOAD__
-INTERNAL_FUNC int emcore_download_bulk_partial_mail_body(MAILSTREAM *stream, email_event_partial_body_thd *pbd_event, int count, int *error);
+INTERNAL_FUNC int emcore_download_bulk_partial_mail_body(MAILSTREAM *stream,
+ email_event_partial_body_thd *pbd_event,
+ int count,
+ int *error);
+
+INTERNAL_FUNC int emcore_initiate_pbd(char *multi_user_name, MAILSTREAM *stream,
+ int account_id, int mail_id, char *uid,
+ int input_mailbox_id, char *input_mailbox_name,
+ int *err_code);
#endif /* __FEATURE_PARTIAL_BODY_DOWNLOAD__ */
diff --git a/email-core/include/email-core-mailbox.h b/email-core/include/email-core-mailbox.h
index 6d9babc..3b8aea7 100755
--- a/email-core/include/email-core-mailbox.h
+++ b/email-core/include/email-core-mailbox.h
@@ -53,8 +53,8 @@ INTERNAL_FUNC int emcore_remove_connection_info(int account_id);
#endif /* __FEATURE_KEEP_CONNECTION__ */
/* in SMTP case, path argument must be (ENCODED_PATH_SMTP) */
/* ex) emcore_connect_to_remote_mailbox(xxx, (char *)ENCODED_PATH_SMTP, xxx, xxx); */
-INTERNAL_FUNC int emcore_connect_to_remote_mailbox_with_account_info(email_account_t *ref_account, int input_mailbox_id, void **mail_stream, int *err_code);
-INTERNAL_FUNC int emcore_connect_to_remote_mailbox(int account_id, int input_mailbox_id, void **mail_stream, int *err_code);
+INTERNAL_FUNC int emcore_connect_to_remote_mailbox_with_account_info(char *multi_user_name, email_account_t *ref_account, int input_mailbox_id, void **mail_stream, int *err_code);
+INTERNAL_FUNC int emcore_connect_to_remote_mailbox(char *multi_user_name, int account_id, int input_mailbox_id, void **mail_stream, int *err_code);
INTERNAL_FUNC int emcore_close_mailbox(int account_id, void *mail_stream);
#ifdef __FEATURE_KEEP_CONNECTION__
INTERNAL_FUNC void emcore_close_mailbox_receiving_stream();
@@ -62,18 +62,18 @@ INTERNAL_FUNC void emcore_close_mailbox_partial_body_stream();
INTERNAL_FUNC void emcore_reset_streams();
#endif
-INTERNAL_FUNC int emcore_get_mailbox_list_to_be_sync(int account_id, email_mailbox_t **mailbox_list, int *p_count, int *err_code);
-INTERNAL_FUNC int emcore_get_mailbox_list(int account_id, email_mailbox_t **mailbox_list, int *p_count, int *err_code);
-INTERNAL_FUNC int emcore_get_mail_count(email_mailbox_t *mailbox, int *total, int *unseen, int *err_code);
-INTERNAL_FUNC int emcore_create_mailbox(email_mailbox_t *new_mailbox, int on_server, int server_type, int slot_size, int *err_code);
-INTERNAL_FUNC int emcore_delete_mailbox(int input_mailbox_id, int input_on_server, int input_recursive);
-INTERNAL_FUNC int emcore_delete_mailbox_ex(int input_account_id, int *input_mailbox_id_array, int input_mailbox_id_count, int input_on_server, int input_recursive);
-INTERNAL_FUNC int emcore_delete_mailbox_all(email_mailbox_t *mailbox, int *err_code);
-INTERNAL_FUNC int emcore_rename_mailbox(int input_mailbox_id, char *input_new_mailbox_name, char *input_new_mailbox_alias, void *input_eas_data, int input_eas_data_length, int input_on_server, int input_recursive, int handle_to_be_published);
+INTERNAL_FUNC int emcore_get_mailbox_list_to_be_sync(char *multi_user_name, int account_id, email_mailbox_t **mailbox_list, int *p_count, int *err_code);
+INTERNAL_FUNC int emcore_get_mailbox_list(char *multi_user_name, int account_id, email_mailbox_t **mailbox_list, int *p_count, int *err_code);
+INTERNAL_FUNC int emcore_get_mail_count(char *multi_user_name, email_mailbox_t *mailbox, int *total, int *unseen, int *err_code);
+INTERNAL_FUNC int emcore_create_mailbox(char *multi_user_name, email_mailbox_t *new_mailbox, int on_server, int server_type, int slot_size, int *err_code);
+INTERNAL_FUNC int emcore_delete_mailbox(char *multi_user_name, int input_mailbox_id, int input_on_server, int input_recursive);
+INTERNAL_FUNC int emcore_delete_mailbox_ex(char *multi_user_name, int input_account_id, int *input_mailbox_id_array, int input_mailbox_id_count, int input_on_server, int input_recursive);
+INTERNAL_FUNC int emcore_delete_mailbox_all(char *multi_user_name, email_mailbox_t *mailbox, int *err_code);
+INTERNAL_FUNC int emcore_rename_mailbox(char *multi_user_name, int input_mailbox_id, char *input_new_mailbox_name, char *input_new_mailbox_alias, void *input_eas_data, int input_eas_data_length, int input_on_server, int input_recursive, int handle_to_be_published);
INTERNAL_FUNC int emcore_save_local_activity_sync(int account_id, int *err_code);
INTERNAL_FUNC int emcore_send_mail_event(email_mailbox_t *mailbox, int mail_id , int *err_code);
-INTERNAL_FUNC int emcore_partial_body_thd_local_activity_sync(int *is_event_inserted, int *err_code);
-INTERNAL_FUNC int emcore_get_mailbox_by_type(int account_id, email_mailbox_type_e mailbox_type, email_mailbox_t *spam_mailbox, int *err_code);
+INTERNAL_FUNC int emcore_partial_body_thd_local_activity_sync(char *multi_user_name, int *is_event_inserted, int *err_code);
+INTERNAL_FUNC int emcore_get_mailbox_by_type(char *multi_user_name, int account_id, email_mailbox_type_e mailbox_type, email_mailbox_t *spam_mailbox, int *err_code);
INTERNAL_FUNC void emcore_free_mailbox_list(email_mailbox_t **mailbox_list, int count);
INTERNAL_FUNC void emcore_free_mailbox(email_mailbox_t *mailbox);
@@ -82,7 +82,7 @@ INTERNAL_FUNC int emcore_free_internal_mailbox(email_internal_mailbox_t **mailb
INTERNAL_FUNC void emcore_close_recv_stream_list (void);
-INTERNAL_FUNC MAILSTREAM** emcore_get_recv_stream (int account_id, int mailbox_id, int *error);
+INTERNAL_FUNC MAILSTREAM** emcore_get_recv_stream (char *multi_user_name, int account_id, int mailbox_id, int *error);
#ifdef __FEATURE_LOCAL_ACTIVITY__
INTERNAL_FUNC int emcore_local_activity_sync(int account_id, int *err_code);
diff --git a/email-core/include/email-core-mime.h b/email-core/include/email-core-mime.h
index 0cbee55..05a2601 100755
--- a/email-core/include/email-core-mime.h
+++ b/email-core/include/email-core-mime.h
@@ -41,20 +41,18 @@ extern "C" {
#endif /* __cplusplus */
char *emcore_get_line_from_file(void *stream, char *buf, int size, int *err_code);
-int emcore_parse_mime(void *stream, int is_file, struct _m_content_info *cnt_info, int *err_code);
char *emcore_mime_get_save_file_name(int *err_code);
char *emcore_mime_get_line_from_sock(void *stream, char *buf, int size, int *err_code);
INTERNAL_FUNC int emcore_get_content_type_from_mime_string(char *input_mime_string, char **output_content_type);
INTERNAL_FUNC int emcore_get_content_type_from_mail_bodystruct(BODY *input_body, int input_buffer_length, char *output_content_type);
INTERNAL_FUNC int emcore_get_attribute_value_of_body_part(PARAMETER *input_param, char *atribute_name, char *output_value, int output_buffer_length, int with_rfc2047_text, int *err_code);
-INTERNAL_FUNC int emcore_get_body_part_list_full(MAILSTREAM *stream, int msg_uid, int account_id, int mail_id, BODY *body, struct _m_content_info *cnt_info, int *err_code, PARTLIST * section_list, int event_handle);
INTERNAL_FUNC int emcore_get_body(MAILSTREAM *stream, int account_id, int mail_id, int msg_uid, BODY *body, char *part_body_type, struct _m_content_info *cnt_info, int *err_code);
INTERNAL_FUNC int emcore_get_body_structure(MAILSTREAM *stream, int msg_uid, BODY **body, int *err_code);
INTERNAL_FUNC char *emcore_decode_rfc2047_text(char *rfc2047_text, int *err_code);
INTERNAL_FUNC int emcore_decode_body_text(char *enc_buf, int enc_len, int enc_type, int *dec_len, int *err_code);
INTERNAL_FUNC int emcore_set_fetch_body_section(BODY *body, int enable_inline_list, int *total_mail_size, int *total_body_size, int *err_code);
INTERNAL_FUNC int emcore_parse_mime_file_to_mail(char *eml_file_path, email_mail_data_t **output_mail_data, email_attachment_data_t **output_attachment_data, int *output_attachment_count, int *err_code);
-INTERNAL_FUNC int emcore_delete_parsed_data(email_mail_data_t *input_mail_data, int *err_code);
+INTERNAL_FUNC int emcore_delete_parsed_data(char *multi_user_name, email_mail_data_t *input_mail_data, int *err_code);
INTERNAL_FUNC int emcore_get_mime_entity(char *mime_path, char **mime_entity, int *err_code);
INTERNAL_FUNC int emcore_get_utf8_address(char **dest, ADDRESS *address, int *err_code);
INTERNAL_FUNC int emcore_get_digest_type(char *micalg_value);
diff --git a/email-core/include/email-core-smime.h b/email-core/include/email-core-smime.h
index 0c95e92..547f0fa 100755
--- a/email-core/include/email-core-smime.h
+++ b/email-core/include/email-core-smime.h
@@ -39,15 +39,15 @@
INTERNAL_FUNC int emcore_smime_set_signed_message(char *certificate, char *mime_entity, email_digest_type digest_type, char **file_path, int *err_code);
-INTERNAL_FUNC int emcore_smime_set_encrypt_message(char *other_certificate_list, char *mime_entity, email_cipher_type cipher_type, char **file_path, int *err_code);
+INTERNAL_FUNC int emcore_smime_set_encrypt_message(char *multi_user_name, char *other_certificate_list, char *mime_entity, email_cipher_type cipher_type, char **file_path, int *err_code);
-INTERNAL_FUNC int emcore_smime_set_signed_and_encrypt_message(char *recipient_list, char *certificate, char *mime_entity, email_cipher_type cipher_type, email_digest_type digest_type, char **file_path, int *err_code);
+INTERNAL_FUNC int emcore_smime_set_signed_and_encrypt_message(char *multi_user_name, char *recipient_list, char *certificate, char *mime_entity, email_cipher_type cipher_type, email_digest_type digest_type, char **file_path, int *err_code);
INTERNAL_FUNC int emcore_smime_verify_signed_message(char *signed_message, char *ca_file, char *ca_path, int *verify);
INTERNAL_FUNC int emcore_smime_get_decrypt_message(char *encrypt_message, char *from_address, char **decrypt_message, int *err_code);
-INTERNAL_FUNC int emcore_convert_mail_data_to_smime_data(emstorage_account_tbl_t *account_tbl_item, email_mail_data_t *input_mail_data, email_attachment_data_t *input_attachment_data_list, int input_attachment_count, email_mail_data_t **output_mail_data, email_attachment_data_t **output_attachment_data_list, int *output_attachment_count);
+INTERNAL_FUNC int emcore_convert_mail_data_to_smime_data(char *multi_user_name, emstorage_account_tbl_t *account_tbl_item, email_mail_data_t *input_mail_data, email_attachment_data_t *input_attachment_data_list, int input_attachment_count, email_mail_data_t **output_mail_data, email_attachment_data_t **output_attachment_data_list, int *output_attachment_count);
INTERNAL_FUNC void emcore_init_openssl_library();
INTERNAL_FUNC void emcore_clean_openssl_library();
diff --git a/email-core/include/email-core-smtp.h b/email-core/include/email-core-smtp.h
index b0dafc5..0e6f8f6 100755
--- a/email-core/include/email-core-smtp.h
+++ b/email-core/include/email-core-smtp.h
@@ -42,31 +42,31 @@ extern "C"
#include "c-client.h"
#include "email-internal-types.h"
-INTERNAL_FUNC int emcore_send_mail(int mail_id, int *err_code);
+INTERNAL_FUNC int emcore_send_mail(char *multi_user_name, int mail_id, int *err_code);
-INTERNAL_FUNC int emcore_send_saved_mail(int account_id, char *mailbox, int *err_code);
+INTERNAL_FUNC int emcore_send_saved_mail(char *multi_user_name, int account_id, char *mailbox, int *err_code);
-INTERNAL_FUNC int emcore_send_mail_with_downloading_attachment_of_original_mail(int input_mail_id);
+INTERNAL_FUNC int emcore_send_mail_with_downloading_attachment_of_original_mail(char *multi_user_name, int input_mail_id);
-INTERNAL_FUNC int emcore_schedule_sending_mail(int input_mail_id, time_t input_time_to_send);
+INTERNAL_FUNC int emcore_schedule_sending_mail(char *multi_user_name, int input_mail_id, time_t input_time_to_send);
-INTERNAL_FUNC int emcore_make_rfc822_file_from_mail(emstorage_mail_tbl_t *input_mail_tbl_data, emstorage_attachment_tbl_t *input_attachment_tbl_t, int input_attachment_count, ENVELOPE **env, char **file_path, email_option_t *sending_option, int *err_code);
+INTERNAL_FUNC int emcore_make_rfc822_file_from_mail(char *multi_user_name, emstorage_mail_tbl_t *input_mail_tbl_data, emstorage_attachment_tbl_t *input_attachment_tbl_t, int input_attachment_count, ENVELOPE **env, char **file_path, email_option_t *sending_option, int *err_code);
-INTERNAL_FUNC int emcore_make_rfc822_file(email_mail_data_t *input_mail_tbl_data, email_attachment_data_t *input_attachment_tbl, int input_attachment_count, int mime_entity_status, char **file_path, int *err_code);
+INTERNAL_FUNC int emcore_make_rfc822_file(char *multi_user_name, email_mail_data_t *input_mail_tbl_data, email_attachment_data_t *input_attachment_tbl, int input_attachment_count, int mime_entity_status, char **file_path, int *err_code);
-INTERNAL_FUNC int emcore_add_mail(email_mail_data_t *input_mail_data, email_attachment_data_t *input_attachment_data_list, int input_attachment_count, email_meeting_request_t *input_meeting_request, int input_from_eas, int move_flag);
+INTERNAL_FUNC int emcore_add_mail(char *multi_user_name, email_mail_data_t *input_mail_data, email_attachment_data_t *input_attachment_data_list, int input_attachment_count, email_meeting_request_t *input_meeting_request, int input_from_eas, int move_flag);
-INTERNAL_FUNC int emcore_add_read_receipt(int input_read_mail_id, int *output_receipt_mail_id);
+INTERNAL_FUNC int emcore_add_read_receipt(char *multi_user_name, int input_read_mail_id, int *output_receipt_mail_id);
-INTERNAL_FUNC int emcore_add_meeting_request(int account_id, int input_mailbox_id, email_meeting_request_t *meeting_req, int *err_code);
+INTERNAL_FUNC int emcore_add_meeting_request(char *multi_user_name, int account_id, int input_mailbox_id, email_meeting_request_t *meeting_req, int *err_code);
-INTERNAL_FUNC int emcore_create_alarm_for_auto_resend(int input_alarm_interval_in_second);
+INTERNAL_FUNC int emcore_create_alarm_for_auto_resend(char *multi_user_name, int input_alarm_interval_in_second);
-INTERNAL_FUNC int emcore_query_mail_size_limit(int account_id, int handle, int *err_code);
+INTERNAL_FUNC int emcore_query_mail_size_limit(char *multi_user_name, int account_id, int handle, int *err_code);
INTERNAL_FUNC void emcore_close_smtp_stream_list (void);
-INTERNAL_FUNC SENDSTREAM** emcore_get_smtp_stream (int account_id, int *error);
+INTERNAL_FUNC SENDSTREAM** emcore_get_smtp_stream (char *multi_user_name, int account_id, int *error);
#ifdef __cplusplus
}
diff --git a/email-core/include/email-core-task-manager.h b/email-core/include/email-core-task-manager.h
index 19d97a4..c792ef2 100755
--- a/email-core/include/email-core-task-manager.h
+++ b/email-core/include/email-core-task-manager.h
@@ -38,12 +38,12 @@ INTERNAL_FUNC int emcore_free_task_handler_array();
INTERNAL_FUNC int emcore_encode_task_parameter(email_task_type_t input_task_type, void *input_task_parameter_struct, char **output_byte_stream, int *output_stream_size);
INTERNAL_FUNC int emcore_decode_task_parameter(email_task_type_t input_task_type, char *input_byte_stream, int input_stream_size, void **output_task_parameter_struct);
-INTERNAL_FUNC int emcore_add_task_to_task_table(email_task_type_t input_task_type, email_task_priority_t input_task_priority, char *input_task_parameter, int input_task_parameter_length, int *output_task_id);
-INTERNAL_FUNC int emcore_remove_task_from_task_table(int input_task_id);
+INTERNAL_FUNC int emcore_add_task_to_task_table(char *multi_user_name, email_task_type_t input_task_type, email_task_priority_t input_task_priority, char *input_task_parameter, int input_task_parameter_length, int *output_task_id);
+INTERNAL_FUNC int emcore_remove_task_from_task_table(char *multi_user_name, int input_task_id);
INTERNAL_FUNC int emcore_get_active_task_by_thread_id(thread_t input_thread_id, email_active_task_t **output_active_task);
INTERNAL_FUNC void* emcore_default_async_task_handler(void *intput_param);
-INTERNAL_FUNC void* emcore_default_sync_task_handler(void *intput_param);
+INTERNAL_FUNC int emcore_default_sync_task_handler(void *intput_param);
INTERNAL_FUNC int emcore_start_task_manager_loop();
INTERNAL_FUNC int emcore_stop_task_manager_loop();
diff --git a/email-core/include/email-core-tasks.h b/email-core/include/email-core-tasks.h
index 0c4c092..dde99ef 100755
--- a/email-core/include/email-core-tasks.h
+++ b/email-core/include/email-core-tasks.h
@@ -63,6 +63,7 @@ typedef struct
int target_mailbox_id;
int mail_id_count;
int *mail_id_array;
+ char *multi_user_name;
} task_parameter_EMAIL_ASYNC_TASK_MOVE_MAILS_TO_MAILBOX_OF_ANOTHER_ACCOUNT;
DECLARE_CONVERTER_FOR_TASK_PARAMETER(EMAIL_ASYNC_TASK_MOVE_MAILS_TO_MAILBOX_OF_ANOTHER_ACCOUNT);
@@ -76,6 +77,7 @@ typedef struct
int mailbox_id_count;
int *mailbox_id_array;
int on_server;
+ char *multi_user_name;
} task_parameter_EMAIL_ASYNC_TASK_DELETE_MAILBOX_EX;
DECLARE_CONVERTER_FOR_TASK_PARAMETER(EMAIL_ASYNC_TASK_DELETE_MAILBOX_EX);
@@ -85,6 +87,7 @@ INTERNAL_FUNC void* task_handler_EMAIL_ASYNC_TASK_DELETE_MAILBOX_EX(void *input_
typedef struct
{
int mail_id;
+ char *multi_user_name;
} task_parameter_EMAIL_ASYNC_TASK_SEND_MAIL_WITH_DOWNLOADING_ATTACHMENT_OF_ORIGINAL_MAIL;
DECLARE_CONVERTER_FOR_TASK_PARAMETER(EMAIL_ASYNC_TASK_SEND_MAIL_WITH_DOWNLOADING_ATTACHMENT_OF_ORIGINAL_MAIL);
@@ -93,6 +96,7 @@ INTERNAL_FUNC void* task_handler_EMAIL_ASYNC_TASK_SEND_MAIL_WITH_DOWNLOADING_ATT
/* to handle EMAIL_SYNC_TASK_SCHEDULE_SENDING_MAIL */
typedef struct
{
+ char *multi_user_name;
int mail_id;
time_t scheduled_time;
} task_parameter_EMAIL_SYNC_TASK_SCHEDULE_SENDING_MAIL;
@@ -109,6 +113,7 @@ typedef struct
email_mail_attribute_type attribute_type;
int value_length;
email_mail_attribute_value_t value;
+ char *multi_user_name;
} task_parameter_EMAIL_SYNC_TASK_UPDATE_ATTRIBUTE;
DECLARE_CONVERTER_FOR_TASK_PARAMETER(EMAIL_SYNC_TASK_UPDATE_ATTRIBUTE);
diff --git a/email-core/include/email-core-utils.h b/email-core/include/email-core-utils.h
index 3e8e53d..03dd486 100755
--- a/email-core/include/email-core-utils.h
+++ b/email-core/include/email-core-utils.h
@@ -54,29 +54,29 @@ char* emcore_get_alias_of_mailbox(const char *mailbox_path);
/* Parse the Mailbox Path and get the Account Email address */
INTERNAL_FUNC int emcore_get_temp_file_name(char **filename, int *err_code);
-int emcore_get_long_encoded_path(int account_id, char *path, int delimiter, char **long_enc_path, int *err_code);
+int emcore_get_long_encoded_path(char *multi_user_name, int account_id, char *path, int delimiter, char **long_enc_path, int *err_code);
int emcore_get_encoded_mailbox_name(char *name, char **enc_name, int *err_code);
int emcore_get_file_name(char *path, char **filename, int *err_code);
INTERNAL_FUNC int emcore_get_file_size(char *path, int *size, int *err_code);
int emcore_get_actual_mail_size(char *pBodyPlane, char *pBodyHtml, struct attachment_info *pAttachment, int *error_code);
-int emcore_calc_mail_size(email_mail_data_t *mail_data_src, email_attachment_data_t *attachment_data_src, int attachment_count, int *error_code);
+int emcore_calc_mail_size(char *multi_user_name, email_mail_data_t *mail_data_src, email_attachment_data_t *attachment_data_src, int attachment_count, int *error_code);
int emcore_get_address_count(char *addr_str, int *to_num, int *err_code);
INTERNAL_FUNC int emcore_is_storage_full();
-int emcore_get_long_encoded_path_with_account_info(email_account_t *account, char *path, int delimiter, char **long_enc_path, int *err_code);
-void emcore_fill_address_information_of_mail_tbl(emstorage_mail_tbl_t *mail_data);
+int emcore_get_long_encoded_path_with_account_info(char *multi_user_name, email_account_t *account, char *path, int delimiter, char **long_enc_path, int *err_code);
+void emcore_fill_address_information_of_mail_tbl(char *multi_user_name, emstorage_mail_tbl_t *mail_data);
INTERNAL_FUNC char* emcore_get_mail_field_name_by_attribute_type(email_mail_attribute_type input_attribute_type);
INTERNAL_FUNC int emcore_get_attribute_type_by_mail_field_name(char *input_mail_field_name, email_mail_attribute_type *output_mail_attribute_type);
INTERNAL_FUNC int emcore_get_mail_attribute_value_type(email_mail_attribute_type input_attribute_type, email_mail_attribute_value_type *output_value_type);
-INTERNAL_FUNC int emcore_get_preview_text_from_file(const char *input_plain_path, const char *input_html_path, int input_preview_buffer_length, char **output_preview_buffer);
+INTERNAL_FUNC int emcore_get_preview_text_from_file(char *multi_user_name, const char *input_plain_path, const char *input_html_path, int input_preview_buffer_length, char **output_preview_buffer);
#ifdef __FEATURE_BODY_SEARCH__
-INTERNAL_FUNC int emcore_strip_mail_body_from_file(emstorage_mail_tbl_t *mail, char **stripped_text, int *err_code);
+INTERNAL_FUNC int emcore_strip_mail_body_from_file(char *multi_user_name, emstorage_mail_tbl_t *mail, char **stripped_text, int *err_code);
#endif
INTERNAL_FUNC int emcore_get_first_address(const char *full_address, char **alias, char **address);
INTERNAL_FUNC int reg_replace (char *input_source_text, char *input_old_pattern_string, char *input_new_string);
-INTERNAL_FUNC int reg_replace_new (char **input_source_text, char *input_old_pattern_string, char *input_new_string);
+INTERNAL_FUNC char *reg_replace_new (char *input_source_text, char *input_old_pattern_string, char *input_new_string);
int emcore_strip_HTML_tag(const char *input_html_file_path, char *encoding_type, char *output_result_buffer, int input_result_buffer_legnth);
int emcore_send_noti_for_new_mail(int account_id, char *mailbox_name, char *subject, char *from, char *uid, char *datetime);
int emcore_make_attachment_file_name_with_extension(char *source_file_name, char *sub_type, char *result_file_name, int result_file_name_buffer_length, int *err_code);
@@ -86,16 +86,16 @@ INTERNAL_FUNC int emcore_get_empty_session(email_session_t **session);
INTERNAL_FUNC int emcore_clear_session(email_session_t *session);
INTERNAL_FUNC int emcore_get_current_session(email_session_t **session);
-INTERNAL_FUNC int emcore_get_mail_count_by_query(int account_id, int mailbox_type, int priority_sender, int *total_mail, int *unread_mail, int *err_code);
+INTERNAL_FUNC int emcore_get_mail_count_by_query(char *multi_user_name, int account_id, int mailbox_type, int priority_sender, int *total_mail, int *unread_mail, int *err_code);
INTERNAL_FUNC int emcore_check_drm_file(char *path, int *err_code);
INTERNAL_FUNC int emcore_check_drm_is_ringtone(char *ringtone_path, int *err_code);
INTERNAL_FUNC void emcore_display_unread_in_badge(void *data);
-INTERNAL_FUNC int emcore_display_badge_count(int count);
+INTERNAL_FUNC int emcore_display_badge_count(char *multi_user_name, int count);
INTERNAL_FUNC int emcore_set_network_error(int err_code);
-INTERNAL_FUNC int emcore_calc_next_time_to_sync(int input_account_id, time_t input_current_time, time_t *output_time);
+INTERNAL_FUNC int emcore_calc_next_time_to_sync(char *multi_user_name, int input_account_id, time_t input_current_time, time_t *output_time);
/* Transaction Handling */
INTERNAL_FUNC int emcore_add_transaction_info(int mail_id , int handle , int *err_code);
@@ -104,20 +104,18 @@ INTERNAL_FUNC int emcore_delete_transaction_info_by_mailId(int mail_id);
/* For notification bar */
INTERNAL_FUNC int emcore_update_notification_for_unread_mail(int account_id);
-INTERNAL_FUNC int emcore_clear_notifications(int account_id);
+INTERNAL_FUNC int emcore_clear_notifications(char *multi_user_name, int account_id);
//INTERNAL_FUNC int emcore_add_notification_for_unread_mail(emstorage_mail_tbl_t *input_mail_tbl_data);
-INTERNAL_FUNC int emcore_add_notification(int account_id, int mail_id, int unread_mail_count, int vip_unread_mail_count, int input_play_alert_tone, int sending_error, unsigned long display);
-INTERNAL_FUNC int emcore_add_notification_for_send(int account_id, int mail_id, email_action_t action, int sending_error, unsigned long display);
+INTERNAL_FUNC int emcore_add_notification(char *multi_user_name, int account_id, int mail_id, int unread_mail_count, int vip_unread_mail_count, int input_play_alert_tone, int sending_error, unsigned long display);
+INTERNAL_FUNC int emcore_add_notification_for_send(char *multi_user_name, int account_id, int mail_id, email_action_t action, int sending_error, unsigned long display);
INTERNAL_FUNC void emcore_update_notification_for_send(int account_id, int mail_id, double progress);
INTERNAL_FUNC int emcore_delete_notification_for_read_mail(int mail_id);
-INTERNAL_FUNC int emcore_delete_notification_by_account(int account_id, int with_noti_tray);
-INTERNAL_FUNC void emcore_set_flash_noti();
+INTERNAL_FUNC int emcore_delete_notification_by_account(char *multi_user_name, int account_id, int with_noti_tray);
+INTERNAL_FUNC int emcore_show_user_message(char *multi_user_name, int id, email_action_t action, int error);
-INTERNAL_FUNC int emcore_show_user_message(int id, email_action_t action, int error);
-
-INTERNAL_FUNC int emcore_connect_contacts_service();
-INTERNAL_FUNC int emcore_disconnect_contacts_service();
+INTERNAL_FUNC int emcore_connect_contacts_service(char *multi_user_name);
+INTERNAL_FUNC int emcore_disconnect_contacts_service(char *multi_user_name);
#ifdef __FEATURE_BULK_DELETE_MOVE_UPDATE_REQUEST_OPTI__
@@ -215,15 +213,17 @@ INTERNAL_FUNC int emcore_search_string_from_file(char *file_path, char *search_s
INTERNAL_FUNC int emcore_load_query_from_file(char *file_path, char ***query_array, int *array_len);
-INTERNAL_FUNC int emcore_start_driving_mode(int mail_id);
+#ifdef __FEATURE_DRIVING_MODE__
+INTERNAL_FUNC int emcore_start_driving_mode(char *multi_user_name, int mail_id);
+#endif /* __FEATURE_DRIVING_MODE__ */
#ifdef __FEATURE_BLOCKING_MODE__
INTERNAL_FUNC bool emcore_init_blocking_mode_status();
INTERNAL_FUNC void emcore_set_blocking_mode_of_setting(int input_blocking_mode_of_setting);
INTERNAL_FUNC int emcore_get_blocking_mode_status();
INTERNAL_FUNC void emcore_set_blocking_mode_status(int blocking_mode);
-INTERNAL_FUNC int emcore_check_blocking_mode(char *sender_address, int *blocking_status);
-INTERNAL_FUNC int emcore_check_blocking_mode_internal (char *sender_address, int *blocking_status);
+INTERNAL_FUNC int emcore_check_blocking_mode(char *multi_user_name, char *sender_address, int *blocking_status);
+INTERNAL_FUNC int emcore_check_blocking_mode_internal (char *multi_user_name, char *sender_address, int *blocking_status);
#endif /* __FEATURE_BLOCKING_MODE__ */
INTERNAL_FUNC char *emcore_set_mime_entity(char *mime_path);
@@ -231,13 +231,20 @@ INTERNAL_FUNC int emcore_get_content_from_file(char *filename, char **contents,
INTERNAL_FUNC int emcore_set_content_to_file(const char *contents, char *dest_path, int length);
#ifdef __FEATURE_UPDATE_DB_TABLE_SCHEMA__
-INTERNAL_FUNC int emcore_update_db_table_schema();
+INTERNAL_FUNC int emcore_update_db_table_schema(char *multi_user_name);
#endif /* #ifdef __FEATURE_UPDATE_DB_TABLE_SCHEMA__ */
INTERNAL_FUNC int emcore_unescape_from_url(char *input_url, char **output_url);
INTERNAL_FUNC char *__em_get_month_in_string(int month);
INTERNAL_FUNC int emcore_make_date_string_for_search(time_t input_time, char *output_date_string);
INTERNAL_FUNC int emcore_make_uid_range_string(emcore_uid_list *uid_list, int total, char **output_uid_range_string);
+#ifdef __FEATURE_DBUS_CALL_STATUS__
+INTERNAL_FUNC int emcore_init_dbus_call_status();
+INTERNAL_FUNC void emcore_shutdown_dbus_call_status();
+INTERNAL_FUNC int emcore_get_call_status();
+#endif /* __FEATURE_DBUS_CALL_STATUS__ */
+
+INTERNAL_FUNC char* emcore_convert_mutf7_to_utf8(char *mailbox_name);
#ifdef __cplusplus
}
#endif /* __cplusplus */