Fixed the invalid casting and remove the flash noti 78/47378/1 accepted/tizen/mobile/20150903.053541 accepted/tizen/tv/20150903.053655 accepted/tizen/wearable/20150903.053757 submit/tizen/20150903.041655
authorSunghyun Kwon <sh0701.kwon@samsung.com>
Thu, 3 Sep 2015 02:28:41 +0000 (11:28 +0900)
committerSunghyun Kwon <sh0701.kwon@samsung.com>
Thu, 3 Sep 2015 02:28:41 +0000 (11:28 +0900)
Change-Id: Icb826abd987e4751cf8f473219e597e56009e2e2

17 files changed:
email-common-use/email-convert.c
email-common-use/email-utilities.c
email-core/email-core-key-manager.c
email-core/email-core-smtp.c
email-core/email-core-task-manager.c
email-core/email-core-tasks.c
email-core/email-core-utils.c
email-core/email-storage/email-storage.c
email-core/email-storage/include/email-storage.h
email-core/include/email-core-mail.h
email-core/include/email-core-task-manager.h
email-core/include/email-core-utils.h
email-daemon/email-daemon-etc.c
email-daemon/email-daemon-mail.c
email-daemon/main.c
email-ipc/include/email-ipc.h
utilities/test-application/testapp-mail.c

index e48c02f..8299cd5 100755 (executable)
@@ -1236,7 +1236,7 @@ INTERNAL_FUNC void em_convert_byte_stream_to_rule(char *stream, int stream_len,
        converted_fmt = convert_format(EMAIL_RULE_FMT);
        if (converted_fmt == NULL) {
                EM_DEBUG_EXCEPTION("converting failed");
-               return NULL;
+               return;
        }
 
        tn = tpl_map(converted_fmt, rule);
@@ -1326,7 +1326,7 @@ INTERNAL_FUNC void em_convert_byte_stream_to_meeting_req(char *stream, int strea
        converted_fmt = convert_format(EMAIL_MEETING_REQUEST_FMT);
        if (converted_fmt == NULL) {
                EM_DEBUG_EXCEPTION("converting failed");
-               return NULL;
+               return;
        }
 
        tn = tpl_map(converted_fmt,
index 770aa85..9c86fb5 100755 (executable)
@@ -112,10 +112,10 @@ INTERNAL_FUNC char *em_trim_right(char *str)
        if (!str) return NULL;
 
        p = str+EM_SAFE_STRLEN(str)-1;
-       while (((int)p >= (int)str) && (*p == ' ' || *p == '\t' || *p == LF || *p == CR))
+       while ((p >= str) && (*p == ' ' || *p == '\t' || *p == LF || *p == CR))
                *p --= '\0';
 
-       if ((int) p < (int)str)
+       if (p < str)
                return NULL;
 
        return str;
index aed326b..ddd9ed5 100644 (file)
@@ -124,7 +124,7 @@ INTERNAL_FUNC int emcore_get_password_in_key_manager(char *data_name, char **sto
 FINISH_OFF:
 
        if (stored_data) {
-               if (email_data) *stored_data = g_strndup(email_data->data, email_data->size);
+               if (email_data) *stored_data = g_strndup((const gchar *)email_data->data, email_data->size);
        }
 
        if (email_data)
index 91f9d23..449bb32 100755 (executable)
@@ -2090,7 +2090,7 @@ INTERNAL_FUNC int emcore_send_saved_mail(char *multi_user_name, int account_id,
        int err2 = EMAIL_ERROR_NONE;
        int status = EMAIL_SEND_FAIL;
        int *mail_ids = NULL;
-       int handle = 0;
+       DB_STMT handle;
        int i = 0;
        int total = 0;
        int attachment_tbl_count = 0;
@@ -4485,7 +4485,8 @@ INTERNAL_FUNC int emcore_schedule_sending_mail(char *multi_user_name, int input_
        }
 
 FINISH_OFF:
-       if(mail_data)
+
+       if (mail_data)
                emstorage_free_mail(&mail_data, 1, NULL);
 
        EM_DEBUG_FUNC_END("err [%d]", err);
index 776ce33..2d2bc0a 100755 (executable)
-/*\r
-*  email-service\r
-*\r
-* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.\r
-*\r
-* Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com>\r
-*\r
-* Licensed under the Apache License, Version 2.0 (the "License");\r
-* you may not use this file except in compliance with the License.\r
-* You may obtain a copy of the License at\r
-*\r
-* http://www.apache.org/licenses/LICENSE-2.0\r
-*\r
-* Unless required by applicable law or agreed to in writing, software\r
-* distributed under the License is distributed on an "AS IS" BASIS,\r
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
-* See the License for the specific language governing permissions and\r
-* limitations under the License.\r
-*\r
-*/\r
-\r
-/*\r
- * email-core-task-manager.c\r
- *\r
- *  Created on: 2012. 11. 1.\r
- *      Author: kyuho.jo@samsung.com\r
- */\r
-\r
-#include <stdio.h>\r
-#include <stdlib.h>\r
-#include <pthread.h>\r
-#include <dbus/dbus.h>\r
-\r
-#include "email-internal-types.h"\r
-#include "email-utilities.h"\r
-#include "email-core-tasks.h"\r
-#include "email-core-task-manager.h"\r
-#include "email-core-signal.h"\r
-#include "email-core-global.h"\r
-#include "email-core-utils.h"\r
-#include "email-debug-log.h"\r
-\r
-/* TODO : implement a function for removing a task from task pool */\r
-/* TODO : after fetching a task from DB, update status of the task. */\r
-\r
-\r
-#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)\r
-\r
-/*- variables - begin --------------------------------------------------------*/\r
-static pthread_cond_t  _task_available_signal   = PTHREAD_COND_INITIALIZER;\r
-static pthread_mutex_t _task_available_lock     = PTHREAD_MUTEX_INITIALIZER;\r
-static pthread_mutex_t _task_manager_loop_lock  = PTHREAD_MUTEX_INITIALIZER;\r
-static pthread_mutex_t _active_task_pool_lock   = PTHREAD_MUTEX_INITIALIZER;\r
-\r
-static email_active_task_t _active_task_pool[MAX_ACTIVE_TASK];\r
-static thread_t            _thread_task_manager_loop;\r
-static int                 _task_manager_loop_availability = 1;\r
-/*- variables - end ----------------------------------------------------------*/\r
-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);\r
-static int emcore_remove_task_from_active_task_pool(int input_task_id);\r
-static int emcore_find_available_slot_in_active_task_pool(int *result_index);\r
-static int emcore_update_task_status_on_task_table(char *multi_user_name, int input_task_id, email_task_status_type_t task_status);\r
-static int emcore_get_task_handler_reference(email_task_type_t input_task_type, email_task_handler_t **output_task_handler);\r
-\r
-/*- task handlers helpers - begin --------------------------------------------*/\r
-static int emcore_initialize_async_task_handler(email_task_t *input_task)\r
-{\r
-       EM_DEBUG_FUNC_BEGIN("input_task [%p]", input_task);\r
-       int err = EMAIL_ERROR_NONE;\r
-\r
-       if(input_task == NULL) {\r
-               EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");\r
-               err = EMAIL_ERROR_INVALID_PARAM;\r
-               goto FINISH_OFF;\r
-       }\r
-\r
-       /* insert task to _active_task_pool */\r
-       emcore_insert_task_to_active_task_pool(input_task->active_task_id\r
-                       , input_task->task_id\r
-                       , input_task->task_type\r
-                       , THREAD_SELF());\r
-\r
-       /* send notification for 'task start */\r
-       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) {\r
-               EM_DEBUG_EXCEPTION("emcore_send_task_status_signal failed [%d]", err);\r
-               goto FINISH_OFF;\r
-       }\r
-\r
-FINISH_OFF:\r
-\r
-       EM_DEBUG_FUNC_END("err [%d]", err);\r
-       return err;\r
-}\r
-\r
-static int emcore_finalize_async_task_handler(email_task_t *input_task, int input_error_code)\r
-{\r
-       EM_DEBUG_FUNC_BEGIN("input_task [%p] input_error_code [%d]",input_task ,input_error_code);\r
-       int err = EMAIL_ERROR_NONE;\r
-       email_task_status_type_t task_status = EMAIL_TASK_STATUS_FINISHED;\r
-\r
-       if(input_task == NULL) {\r
-               EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");\r
-               err = EMAIL_ERROR_INVALID_PARAM;\r
-               goto FINISH_OFF;\r
-       }\r
-\r
-       if(input_error_code != EMAIL_ERROR_NONE) {\r
-               task_status = EMAIL_TASK_STATUS_FAILED;\r
-       }\r
-\r
-       /* remove task from task table */\r
-       if( (err = emcore_remove_task_from_task_table(NULL, input_task->task_id)) != EMAIL_ERROR_NONE) {\r
-               EM_DEBUG_EXCEPTION("emcore_remove_task_from_active_task_pool failed [%d]", err);\r
-               goto FINISH_OFF;\r
-       }\r
-\r
-       /* remove task id from active task id array */\r
-       if( (err = emcore_remove_task_from_active_task_pool(input_task->task_id)) != EMAIL_ERROR_NONE) {\r
-               EM_DEBUG_EXCEPTION("emcore_remove_task_from_active_task_pool failed [%d]", err);\r
-               goto FINISH_OFF;\r
-       }\r
-\r
-       /* send signal for 'task finish or failure */\r
-       if( (err = emcore_send_task_status_signal(input_task->task_type, input_task->task_id, task_status, input_error_code, 0)) != EMAIL_ERROR_NONE) {\r
-               EM_DEBUG_EXCEPTION("emcore_send_task_status_signal failed [%d]", err);\r
-               goto FINISH_OFF;\r
-       }\r
-\r
-       ENTER_CRITICAL_SECTION(_task_available_lock);\r
-       WAKE_CONDITION_VARIABLE(_task_available_signal);\r
-       LEAVE_CRITICAL_SECTION(_task_available_lock);\r
-\r
-FINISH_OFF:\r
-       EM_DEBUG_FUNC_END("err [%d]", err);\r
-       return err;\r
-}\r
-\r
-INTERNAL_FUNC void* emcore_default_async_task_handler(void *input_param)\r
-{\r
-       EM_DEBUG_FUNC_BEGIN("intput_param [%p]", input_param);\r
-       int err = EMAIL_ERROR_NONE;\r
-       email_task_t *task = input_param;\r
-       email_task_handler_t *task_handler = NULL;\r
-       void *decoded_task_parameter = NULL;\r
-\r
-       if((err = emcore_initialize_async_task_handler(task)) != EMAIL_ERROR_NONE) {\r
-               EM_DEBUG_EXCEPTION("emcore_initialize_async_task_handler failed. [%d]", err);\r
-               goto FINISH_OFF;\r
-       }\r
-\r
-       /* create a thread to do this task */\r
-       if((err = emcore_get_task_handler_reference(task->task_type, &task_handler)) != EMAIL_ERROR_NONE) {\r
-               EM_DEBUG_LOG("emcore_get_task_handler_reference returns [%d]", err);\r
-       }\r
-       else {\r
-               /* Decode parameter */\r
-               emcore_decode_task_parameter(task->task_type, task->task_parameter, task->task_parameter_length, &decoded_task_parameter);\r
-               task_handler->task_handler_function(decoded_task_parameter);\r
-       }\r
-\r
-FINISH_OFF:\r
-       emcore_finalize_async_task_handler(task, err);\r
-\r
-       EM_SAFE_FREE(decoded_task_parameter);\r
-\r
-       EM_DEBUG_FUNC_END("err [%d]", err);\r
-       return NULL;\r
-}\r
-\r
-INTERNAL_FUNC void* emcore_default_sync_task_handler(void *intput_param)\r
-{\r
-       EM_DEBUG_FUNC_BEGIN("intput_param [%p]", intput_param);\r
-       int err = EMAIL_ERROR_NONE;\r
-       email_task_t *task = intput_param;\r
-       email_task_handler_t *task_handler = NULL;\r
-       void *decoded_task_parameter = NULL;\r
-\r
-       /* create a thread to do this task */\r
-       if((err = emcore_get_task_handler_reference(task->task_type, &task_handler)) != EMAIL_ERROR_NONE) {\r
-               EM_DEBUG_LOG("emcore_get_task_handler_reference returns [%d]", err);\r
-       }\r
-       else {\r
-               /* Decode parameter */\r
-               emcore_decode_task_parameter(task->task_type, task->task_parameter, task->task_parameter_length, &decoded_task_parameter);\r
-               err = (int)task_handler->task_handler_function(decoded_task_parameter);\r
-       }\r
-\r
-       EM_DEBUG_FUNC_END("err [%d]", err);\r
-       return (void*)err;\r
-}\r
-/*- task handlers helpers - end   --------------------------------------------*/\r
-\r
-int                   _task_handler_array_size;\r
-email_task_handler_t **_task_handler_array;\r
-\r
-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**))\r
-{\r
-       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);\r
-       int err = EMAIL_ERROR_NONE;\r
-       email_task_handler_t *new_task_handler = NULL;\r
-\r
-       new_task_handler = malloc(sizeof(email_task_handler_t));\r
-\r
-       if (new_task_handler == NULL) {\r
-               err = EMAIL_ERROR_OUT_OF_MEMORY;\r
-               EM_DEBUG_EXCEPTION("EMAIL_ERROR_OUT_OF_MEMORY");\r
-               goto FINISH_OFF;\r
-       }\r
-\r
-       new_task_handler->task_type              = input_task_type;\r
-       new_task_handler->task_handler_function  = input_task_handler;\r
-       new_task_handler->task_parameter_encoder = input_task_parameter_encoder;\r
-       new_task_handler->task_parameter_decoder = input_task_parameter_decoder;\r
-\r
-       _task_handler_array_size++;\r
-\r
-       if (_task_handler_array) {\r
-               _task_handler_array = realloc(_task_handler_array, sizeof(email_task_handler_t*) * _task_handler_array_size);\r
-       }\r
-       else {\r
-               _task_handler_array = malloc(sizeof(email_task_handler_t*) * _task_handler_array_size);\r
-       }\r
-\r
-       if (_task_handler_array == NULL) {\r
-               err = EMAIL_ERROR_OUT_OF_MEMORY;\r
-        EM_SAFE_FREE(new_task_handler);\r
-               goto FINISH_OFF;\r
-       }\r
-\r
-       _task_handler_array[_task_handler_array_size - 1] = new_task_handler;\r
-\r
-FINISH_OFF:\r
-\r
-       EM_DEBUG_FUNC_END("err [%d]", err);\r
-       return err;\r
-}\r
-\r
-INTERNAL_FUNC int emcore_init_task_handler_array()\r
-{\r
-       EM_DEBUG_FUNC_BEGIN();\r
-\r
-       if (_task_handler_array == NULL) {\r
-               _task_handler_array = NULL;\r
-               _task_handler_array_size = 0;\r
-\r
-               REGISTER_TASK_BINDER(EMAIL_ASYNC_TASK_MOVE_MAILS_TO_MAILBOX_OF_ANOTHER_ACCOUNT);\r
-               REGISTER_TASK_BINDER(EMAIL_ASYNC_TASK_DELETE_MAILBOX_EX);\r
-               REGISTER_TASK_BINDER(EMAIL_ASYNC_TASK_SEND_MAIL_WITH_DOWNLOADING_ATTACHMENT_OF_ORIGINAL_MAIL);\r
-               REGISTER_TASK_BINDER(EMAIL_SYNC_TASK_SCHEDULE_SENDING_MAIL);\r
-               REGISTER_TASK_BINDER(EMAIL_SYNC_TASK_UPDATE_ATTRIBUTE);\r
-       }\r
-\r
-       EM_DEBUG_FUNC_END();\r
-       return EMAIL_ERROR_NONE;\r
-}\r
-\r
-INTERNAL_FUNC int emcore_free_task_handler_array()\r
-{\r
-       EM_DEBUG_FUNC_BEGIN();\r
-\r
-       int i = 0;\r
-\r
-       for(i = 0; i < _task_handler_array_size; i++) {\r
-               EM_SAFE_FREE (_task_handler_array[i]);\r
-       }\r
-\r
-       EM_SAFE_FREE (_task_handler_array);\r
-       _task_handler_array_size = 0;\r
-\r
-       EM_DEBUG_FUNC_END();\r
-       return EMAIL_ERROR_NONE;\r
-}\r
-\r
-static int emcore_get_task_handler_reference(email_task_type_t input_task_type, email_task_handler_t **output_task_handler)\r
-{\r
-       EM_DEBUG_FUNC_BEGIN("input_task_type [%d] output_task_handler [%p]", input_task_type, output_task_handler);\r
-       int i = 0;\r
-       int err = EMAIL_ERROR_NONE;\r
-\r
-       if (output_task_handler == NULL) {\r
-               EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");\r
-               err = EMAIL_ERROR_INVALID_PARAM;\r
-               goto FINISH_OFF;\r
-       }\r
-\r
-       *output_task_handler = NULL;\r
-       for (i = 0; i < _task_handler_array_size; i++) {\r
-               if (_task_handler_array[i]->task_type == input_task_type) {\r
-                       *output_task_handler = _task_handler_array[i];\r
-                       break;\r
-               }\r
-       }\r
-\r
-       if (*output_task_handler == NULL) {\r
-               EM_DEBUG_EXCEPTION("EMAIL_ERROR_TASK_BINDER_NOT_FOUND");\r
-               err = EMAIL_ERROR_TASK_BINDER_NOT_FOUND;\r
-               goto FINISH_OFF;\r
-       }\r
-\r
-FINISH_OFF:\r
-       EM_DEBUG_FUNC_END("err [%d]", err);\r
-       return err;\r
-}\r
-\r
-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)\r
-{\r
-       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);\r
-       int err = EMAIL_ERROR_NONE;\r
-       email_task_handler_t *task_handler = NULL;\r
-       int (*task_parameter_encoder)(void*, char**, int*);\r
-\r
-       if (input_task_parameter_struct == NULL || output_byte_stream == NULL || output_stream_size == NULL) {\r
-               EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");\r
-               err = EMAIL_ERROR_INVALID_PARAM;\r
-               goto FINISH_OFF;\r
-       }\r
-\r
-       if ((err = emcore_get_task_handler_reference(input_task_type, &task_handler)) != EMAIL_ERROR_NONE) {\r
-               EM_DEBUG_EXCEPTION("emcore_get_task_handler_reference failed [%d]", err);\r
-               goto FINISH_OFF;\r
-       }\r
-\r
-       task_parameter_encoder = task_handler->task_parameter_encoder;\r
-\r
-       if ((err = task_parameter_encoder(input_task_parameter_struct, output_byte_stream, output_stream_size)) != EMAIL_ERROR_NONE) {\r
-               EM_DEBUG_EXCEPTION("task_parameter_encoder failed [%d]", err);\r
-               goto FINISH_OFF;\r
-       }\r
-\r
-FINISH_OFF:\r
-       EM_DEBUG_FUNC_END("err [%d]", err);\r
-       return err;\r
-}\r
-\r
-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)\r
-{\r
-       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);\r
-       int err = EMAIL_ERROR_NONE;\r
-       email_task_handler_t *task_handler = NULL;\r
-       int (*task_parameter_decoder)(char*, int, void**);\r
-\r
-       if (input_byte_stream == NULL || output_task_parameter_struct == NULL) {\r
-               EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");\r
-               err = EMAIL_ERROR_INVALID_PARAM;\r
-               goto FINISH_OFF;\r
-       }\r
-\r
-       if ((err = emcore_get_task_handler_reference(input_task_type, &task_handler)) != EMAIL_ERROR_NONE) {\r
-               EM_DEBUG_EXCEPTION("emcore_get_task_handler_reference failed [%d]", err);\r
-               goto FINISH_OFF;\r
-       }\r
-\r
-       task_parameter_decoder = task_handler->task_parameter_decoder;\r
-\r
+/*
+*  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_SAFE_FREE(decoded_task_parameter);
+
+       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_SAFE_FREE(decoded_task_parameter);
+
+       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);\r
-               goto FINISH_OFF;\r
-       }\r
-\r
-FINISH_OFF:\r
-       EM_DEBUG_FUNC_END("err [%d]", err);\r
-       return err;\r
-}\r
-\r
-int emcore_fetch_task_from_task_pool(email_task_t **output_task)\r
-{\r
-       EM_DEBUG_FUNC_BEGIN("output_task [%p]", output_task);\r
-       int err = EMAIL_ERROR_NONE;\r
-       int output_task_count;\r
-\r
+               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);\r
-               goto FINISH_OFF;\r
-       }\r
-\r
-FINISH_OFF:\r
-\r
-       EM_DEBUG_FUNC_END("err [%d]", err);\r
-       return err;\r
-}\r
-\r
-\r
-/*-Task manager loop - begin -------------------------------------------------------------*/\r
-\r
-\r
-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)\r
-{\r
-       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);\r
-       int err = EMAIL_ERROR_NONE;\r
-\r
-       ENTER_CRITICAL_SECTION(_active_task_pool_lock);\r
-       _active_task_pool[input_task_slot_index].task_id    = input_task_id;\r
-       _active_task_pool[input_task_slot_index].task_type  = input_task_type;\r
-       _active_task_pool[input_task_slot_index].thread_id  = input_thread_id;\r
-       LEAVE_CRITICAL_SECTION(_active_task_pool_lock);\r
-\r
-       EM_DEBUG_LOG("_active_task_pool[%d].task_id [%d]", input_task_slot_index, _active_task_pool[input_task_slot_index].task_id);\r
-\r
-       EM_DEBUG_FUNC_END("err [%d]", err);\r
-       return err;\r
-}\r
-\r
-static int emcore_remove_task_from_active_task_pool(int input_task_id)\r
-{\r
-       EM_DEBUG_FUNC_BEGIN(" input_task_id [%d]", input_task_id);\r
-       int err = EMAIL_ERROR_NONE;\r
-       int i = 0;\r
-\r
-       ENTER_CRITICAL_SECTION(_active_task_pool_lock);\r
-       for(i = 0; i < MAX_ACTIVE_TASK; i++) {\r
-               if(_active_task_pool[i].task_id == input_task_id) {\r
-                       _active_task_pool[i].task_id    = 0;\r
-                       _active_task_pool[i].task_type  = 0;\r
-                       _active_task_pool[i].thread_id  = 0;\r
-                       break;\r
-               }\r
-       }\r
-       LEAVE_CRITICAL_SECTION(_active_task_pool_lock);\r
-\r
-       if(i >= MAX_ACTIVE_TASK) {\r
-               EM_DEBUG_LOG("couldn't find proper task in active task pool [%d]", input_task_id);\r
-               err = EMAIL_ERROR_TASK_NOT_FOUND;\r
-       }\r
-\r
-       EM_DEBUG_FUNC_END("err [%d]", err);\r
-       return err;\r
-}\r
-\r
-INTERNAL_FUNC int emcore_get_active_task_by_thread_id(thread_t input_thread_id, email_active_task_t **output_active_task)\r
-{\r
-       EM_DEBUG_FUNC_BEGIN(" input_thread_id [%d] output_active_task [%p]", input_thread_id, output_active_task);\r
-       int err = EMAIL_ERROR_NONE;\r
-       int i = 0;\r
-\r
-       if (output_active_task == NULL) {\r
-               EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");\r
-               err = EMAIL_ERROR_INVALID_PARAM;\r
-               goto FINISH_OFF;\r
-       }\r
-\r
-       for(i = 0; i < MAX_ACTIVE_TASK; i++) {\r
-               if(_active_task_pool[i].thread_id == input_thread_id) {\r
-                       *output_active_task = _active_task_pool + i;\r
-                       break;\r
-               }\r
-       }\r
-\r
-       if(i >= MAX_ACTIVE_TASK) {\r
-               EM_DEBUG_LOG("couldn't find proper task in active task pool [%d]", input_thread_id);\r
-               err = EMAIL_ERROR_TASK_NOT_FOUND;\r
-       }\r
-\r
-FINISH_OFF:\r
-\r
-       EM_DEBUG_FUNC_END("err [%d]", err);\r
-       return err;\r
-}\r
-\r
-\r
-static int emcore_find_available_slot_in_active_task_pool(int *result_index)\r
-{\r
-       EM_DEBUG_FUNC_BEGIN("result_index [%p]", result_index);\r
-       int i = 0;\r
-       int err = EMAIL_ERROR_NONE;\r
-\r
-       if (result_index == NULL) {\r
-               EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");\r
-               err = EMAIL_ERROR_INVALID_PARAM;\r
-               goto FINISH_OFF;\r
-       }\r
-\r
-       ENTER_CRITICAL_SECTION(_active_task_pool_lock);\r
-       for(i = 0; i < MAX_ACTIVE_TASK; i++) {\r
-               if(_active_task_pool[i].task_id == 0) {\r
-                       break;\r
-               }\r
-       }\r
-\r
-       if(i >= MAX_ACTIVE_TASK) {\r
-               EM_DEBUG_EXCEPTION("There is no available task slot");\r
-               err = EMAIL_NO_AVAILABLE_TASK_SLOT;\r
-       }\r
-       else {\r
-               _active_task_pool[i].task_id = -1;\r
-               *result_index = i;\r
-       }\r
-       LEAVE_CRITICAL_SECTION(_active_task_pool_lock);\r
-\r
-FINISH_OFF :\r
-       EM_DEBUG_FUNC_END("err [%d]", err);\r
-       return err;\r
-}\r
-\r
-void* thread_func_task_manager_loop(void *arg)\r
-{\r
-       EM_DEBUG_FUNC_BEGIN();\r
-       int err = EMAIL_ERROR_NONE;\r
-       int thread_error;\r
-       int available_slot_index = 0;\r
-       email_task_t *new_task = NULL;\r
-\r
-       /* while loop */\r
-       while (_task_manager_loop_availability) {\r
-               /* fetch task from DB */\r
-               if( ((err = emcore_fetch_task_from_task_pool(&new_task)) == EMAIL_ERROR_NONE) &&\r
-                       ((err = emcore_find_available_slot_in_active_task_pool(&available_slot_index)) == EMAIL_ERROR_NONE)     ) {\r
-\r
-                       /* update task status as STARTED */\r
-                       if((err = emcore_update_task_status_on_task_table(NULL, new_task->task_id, EMAIL_TASK_STATUS_STARTED)) != EMAIL_ERROR_NONE) {\r
-                               EM_DEBUG_EXCEPTION("emcore_update_task_status_on_task_table failed [%d]", err);\r
-                       }\r
-                       new_task->active_task_id = available_slot_index;\r
-\r
-                       /* create a thread to do this task */\r
-                       THREAD_CREATE(new_task->thread_id, emcore_default_async_task_handler, new_task, thread_error);\r
-                       EM_DEBUG_LOG("pthread_create returns [%d]", thread_error);\r
-\r
-                       /* new_task and task_parameter will be free in task handler. */\r
+               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);
-               }\r
-               else {\r
-                       /* If there is no task or no available slot, sleep until someone wake you up. */\r
-                       /* Wake up case 1 : by emcore_add_task_to_task_table */\r
-                       /* Wake up case 2 : when some task terminated */\r
-                       ENTER_CRITICAL_SECTION(_task_available_lock);\r
-                       SLEEP_CONDITION_VARIABLE(_task_available_signal, _task_available_lock);\r
-                       LEAVE_CRITICAL_SECTION(_task_available_lock);\r
-                       EM_DEBUG_LOG("thread_func_task_manager_loop wake up!");\r
-               }\r
-       }\r
-\r
-       EM_DEBUG_FUNC_END();\r
-       return NULL;\r
-}\r
-\r
-INTERNAL_FUNC int emcore_start_task_manager_loop()\r
-{\r
-    EM_DEBUG_FUNC_BEGIN();\r
-       int thread_error;\r
-       int err = EMAIL_ERROR_NONE;\r
-\r
-       memset(&_active_task_pool, 0, sizeof(email_active_task_t) * MAX_ACTIVE_TASK);\r
-\r
-       if (_thread_task_manager_loop) {\r
-               EM_DEBUG_EXCEPTION("service thread is already running...");\r
-               err = EMAIL_ERROR_ALREADY_INITIALIZED;\r
-               goto FINISH_OFF;\r
-       }\r
-\r
-       _task_manager_loop_availability = 10;\r
-\r
-    /* create thread */\r
-       THREAD_CREATE(_thread_task_manager_loop, thread_func_task_manager_loop, NULL, thread_error);\r
-\r
-       if (thread_error != 0) {\r
-        EM_DEBUG_EXCEPTION("cannot create thread [%d]", thread_error);\r
-        err = EMAIL_ERROR_SYSTEM_FAILURE;\r
-        goto FINISH_OFF;\r
-    }\r
-\r
-FINISH_OFF :\r
-       EM_DEBUG_FUNC_END("err [%d]", err);\r
-    return err;\r
-}\r
-\r
-INTERNAL_FUNC int emcore_stop_task_manager_loop()\r
-{\r
-       EM_DEBUG_FUNC_BEGIN();\r
-\r
-       int err = EMAIL_ERROR_NONE;\r
-\r
-       if (!_thread_task_manager_loop) {\r
-               EM_DEBUG_LOG("_thread_task_manager_loop is NULL ");\r
-               err = EMAIL_ERROR_UNKNOWN;\r
-               return err;\r
-       }\r
-\r
-       /* TODO : cancel tasks */\r
-\r
-       /* stop event_data loop */\r
-       _task_manager_loop_availability = 0;\r
-\r
-       ENTER_CRITICAL_SECTION(_task_manager_loop_lock);\r
-       WAKE_CONDITION_VARIABLE(_task_available_signal);\r
-       LEAVE_CRITICAL_SECTION(_task_manager_loop_lock);\r
-\r
-       /* wait for thread finished */\r
-       THREAD_JOIN(_thread_task_manager_loop);\r
-\r
-       _thread_task_manager_loop = 0;\r
-\r
-       DELETE_CRITICAL_SECTION(_task_manager_loop_lock);\r
-       DELETE_CONDITION_VARIABLE(_task_available_signal);\r
-\r
-       /* Free _active_task_pool */\r
-\r
-       //FINISH_OFF :\r
-\r
-       EM_DEBUG_FUNC_END("err [%d]", err);\r
-       return err;\r
-}\r
-\r
-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)\r
-{\r
-       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);\r
-       int err = EMAIL_ERROR_NONE;\r
-\r
-       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) {\r
-               EM_DEBUG_EXCEPTION("emstorage_add_task failed [%d]", err);\r
-               goto FINISH_OFF;\r
-       }\r
-\r
-       ENTER_CRITICAL_SECTION(_task_available_lock);\r
-       WAKE_CONDITION_VARIABLE(_task_available_signal);\r
-       LEAVE_CRITICAL_SECTION(_task_available_lock);\r
-\r
-FINISH_OFF:\r
-       EM_DEBUG_FUNC_END("err [%d]", err);\r
-       return err;\r
-}\r
-\r
-INTERNAL_FUNC int emcore_remove_task_from_task_table(char *multi_user_name, int input_task_id)\r
-{\r
-       EM_DEBUG_FUNC_BEGIN("input_task_id [%d]", input_task_id);\r
-       int err = EMAIL_ERROR_NONE;\r
-\r
-       if((err = emstorage_delete_task(multi_user_name, input_task_id, true)) != EMAIL_ERROR_NONE) {\r
-               EM_DEBUG_EXCEPTION("emstorage_delete_task failed [%d]", err);\r
-               goto FINISH_OFF;\r
-       }\r
-\r
-FINISH_OFF:\r
-       EM_DEBUG_FUNC_END("err [%d]", err);\r
-       return err;\r
-}\r
-\r
-static int emcore_update_task_status_on_task_table(char *multi_user_name, int input_task_id, email_task_status_type_t task_status)\r
-{\r
-       EM_DEBUG_FUNC_BEGIN("input_task_id [%d] task_status [%d]", input_task_id, task_status);\r
-       int err = EMAIL_ERROR_NONE;\r
-\r
-       if((err = emstorage_update_task_status(multi_user_name, input_task_id, task_status, true)) != EMAIL_ERROR_NONE) {\r
-               EM_DEBUG_EXCEPTION("emstorage_update_task_status failed [%d]", err);\r
-               goto FINISH_OFF;\r
-       }\r
-\r
-FINISH_OFF:\r
-       EM_DEBUG_FUNC_END("err [%d]", err);\r
-       return err;\r
-}\r
-\r
-/*-Task manager loop - end-------------------------------------------------------------*/\r
+               }
+               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-------------------------------------------------------------*/
index 2f6f209..065154d 100755 (executable)
-/*\r
-*  email-service\r
-*\r
-* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.\r
-*\r
-* Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com>\r
-*\r
-* Licensed under the Apache License, Version 2.0 (the "License");\r
-* you may not use this file except in compliance with the License.\r
-* You may obtain a copy of the License at\r
-*\r
-* http://www.apache.org/licenses/LICENSE-2.0\r
-*\r
-* Unless required by applicable law or agreed to in writing, software\r
-* distributed under the License is distributed on an "AS IS" BASIS,\r
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
-* See the License for the specific language governing permissions and\r
-* limitations under the License.\r
-*\r
-*/\r
-/*\r
- * email-tasks.c\r
- *\r
- *  Created on: 2012. 11. 5.\r
- *      Author: kyuho.jo@samsung.com\r
- */\r
-#include <stdlib.h>\r
-#include <stdio.h>\r
-#include <string.h>\r
-\r
-\r
-#include "email-debug-log.h"\r
-#include "email-utilities.h"\r
-#include "email-internal-types.h"\r
-#include "email-core-tasks.h"\r
-#include "email-core-task-manager.h"\r
-#include "email-core-mail.h"\r
-#include "email-core-smtp.h"\r
-#include "email-core-mailbox-sync.h"\r
-#include "email-core-signal.h"\r
-#include "email-core-utils.h"\r
-#include "tpl.h"\r
-\r
-/*-------------------------------------------------------------------------------------------*/\r
-/* to handle EMAIL_ASYNC_TASK_MOVE_MAILS_TO_MAILBOX_OF_ANOTHER_ACCOUNT */\r
-#define task_parameter_format_EMAIL_ASYNC_TASK_MOVE_MAILS_TO_MAILBOX_OF_ANOTHER_ACCOUNT "iiiB"\r
-\r
-INTERNAL_FUNC int email_encode_task_parameter_EMAIL_ASYNC_TASK_MOVE_MAILS_TO_MAILBOX_OF_ANOTHER_ACCOUNT(void *input_task_parameter_struct, char **output_byte_stream, int *output_stream_size)\r
-{\r
-       EM_DEBUG_FUNC_BEGIN("input_task_parameter_struct [%p] output_byte_stream [%p] output_stream_size [%p]", input_task_parameter_struct, output_byte_stream, output_stream_size);\r
-\r
-       int err = EMAIL_ERROR_NONE;\r
-       task_parameter_EMAIL_ASYNC_TASK_MOVE_MAILS_TO_MAILBOX_OF_ANOTHER_ACCOUNT *task_parameter = input_task_parameter_struct;\r
-       tpl_bin tb;\r
-       tpl_node *tn = NULL;\r
-       void  *result_data = NULL;\r
-       size_t result_data_length = 0;\r
-\r
-       if (task_parameter == NULL || output_byte_stream == NULL || output_stream_size == NULL) {\r
-               EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");\r
-               err = EMAIL_ERROR_INVALID_PARAM;\r
-               goto FINISH_OFF;\r
-       }\r
-\r
-       tn = tpl_map(task_parameter_format_EMAIL_ASYNC_TASK_MOVE_MAILS_TO_MAILBOX_OF_ANOTHER_ACCOUNT\r
-                       , &task_parameter->source_mailbox_id\r
-                       , &task_parameter->target_mailbox_id\r
-                       , &task_parameter->mail_id_count\r
-                       , &tb);\r
+/*
+*  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-tasks.c
+ *
+ *  Created on: 2012. 11. 5.
+ *      Author: kyuho.jo@samsung.com
+ */
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+
+#include "email-debug-log.h"
+#include "email-utilities.h"
+#include "email-internal-types.h"
+#include "email-core-tasks.h"
+#include "email-core-task-manager.h"
+#include "email-core-mail.h"
+#include "email-core-smtp.h"
+#include "email-core-mailbox-sync.h"
+#include "email-core-signal.h"
+#include "email-core-utils.h"
+#include "tpl.h"
+
+/*-------------------------------------------------------------------------------------------*/
+/* to handle EMAIL_ASYNC_TASK_MOVE_MAILS_TO_MAILBOX_OF_ANOTHER_ACCOUNT */
+#define task_parameter_format_EMAIL_ASYNC_TASK_MOVE_MAILS_TO_MAILBOX_OF_ANOTHER_ACCOUNT "iiiB"
+
+INTERNAL_FUNC int email_encode_task_parameter_EMAIL_ASYNC_TASK_MOVE_MAILS_TO_MAILBOX_OF_ANOTHER_ACCOUNT(void *input_task_parameter_struct, char **output_byte_stream, int *output_stream_size)
+{
+       EM_DEBUG_FUNC_BEGIN("input_task_parameter_struct [%p] output_byte_stream [%p] output_stream_size [%p]", input_task_parameter_struct, output_byte_stream, output_stream_size);
+
+       int err = EMAIL_ERROR_NONE;
+       task_parameter_EMAIL_ASYNC_TASK_MOVE_MAILS_TO_MAILBOX_OF_ANOTHER_ACCOUNT *task_parameter = input_task_parameter_struct;
+       tpl_bin tb;
+       tpl_node *tn = NULL;
+       void  *result_data = NULL;
+       size_t result_data_length = 0;
+
+       if (task_parameter == NULL || output_byte_stream == NULL || output_stream_size == NULL) {
+               EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
+               err = EMAIL_ERROR_INVALID_PARAM;
+               goto FINISH_OFF;
+       }
+
+       tn = tpl_map(task_parameter_format_EMAIL_ASYNC_TASK_MOVE_MAILS_TO_MAILBOX_OF_ANOTHER_ACCOUNT
+                       , &task_parameter->source_mailbox_id
+                       , &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;\r
-       tb.addr = task_parameter->mail_id_array;\r
-       tpl_pack(tn, 0);\r
-       tpl_dump(tn, TPL_MEM, &result_data, &result_data_length);\r
-       tpl_free(tn);\r
-\r
-       *output_byte_stream = result_data;\r
-       *output_stream_size = result_data_length;\r
-\r
-FINISH_OFF:\r
-\r
-       EM_DEBUG_FUNC_END("err [%d]", err);\r
-       return err;\r
-}\r
-\r
-INTERNAL_FUNC int email_decode_task_parameter_EMAIL_ASYNC_TASK_MOVE_MAILS_TO_MAILBOX_OF_ANOTHER_ACCOUNT(char *input_byte_stream, int input_stream_size, void **output_task_parameter_struct)\r
-{\r
-       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);\r
-       int err = EMAIL_ERROR_NONE;\r
-       tpl_bin tb;\r
-       tpl_node *tn = NULL;\r
-       task_parameter_EMAIL_ASYNC_TASK_MOVE_MAILS_TO_MAILBOX_OF_ANOTHER_ACCOUNT *task_parameter = NULL;\r
-\r
-       if (input_byte_stream == NULL || input_stream_size == 0 || output_task_parameter_struct == NULL) {\r
-               EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");\r
-               err = EMAIL_ERROR_INVALID_PARAM;\r
-               goto FINISH_OFF;\r
-       }\r
-\r
-       task_parameter = em_malloc(sizeof(task_parameter_EMAIL_ASYNC_TASK_MOVE_MAILS_TO_MAILBOX_OF_ANOTHER_ACCOUNT));\r
+       tb.sz   = sizeof(int) * task_parameter->mail_id_count;
+       tb.addr = task_parameter->mail_id_array;
+       tpl_pack(tn, 0);
+       tpl_dump(tn, TPL_MEM, &result_data, &result_data_length);
+       tpl_free(tn);
+
+       *output_byte_stream = result_data;
+       *output_stream_size = result_data_length;
+
+FINISH_OFF:
+
+       EM_DEBUG_FUNC_END("err [%d]", err);
+       return err;
+}
+
+INTERNAL_FUNC int email_decode_task_parameter_EMAIL_ASYNC_TASK_MOVE_MAILS_TO_MAILBOX_OF_ANOTHER_ACCOUNT(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);
+       int err = EMAIL_ERROR_NONE;
+       tpl_bin tb;
+       tpl_node *tn = NULL;
+       task_parameter_EMAIL_ASYNC_TASK_MOVE_MAILS_TO_MAILBOX_OF_ANOTHER_ACCOUNT *task_parameter = NULL;
+
+       if (input_byte_stream == NULL || input_stream_size == 0 || output_task_parameter_struct == NULL) {
+               EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
+               err = EMAIL_ERROR_INVALID_PARAM;
+               goto FINISH_OFF;
+       }
+
+       task_parameter = em_malloc(sizeof(task_parameter_EMAIL_ASYNC_TASK_MOVE_MAILS_TO_MAILBOX_OF_ANOTHER_ACCOUNT));
        if (task_parameter == NULL) {
-               EM_DEBUG_EXCEPTION("EMAIL_ERROR_OUT_OF_MEMORY");\r
-               err = EMAIL_ERROR_OUT_OF_MEMORY;\r
-               goto FINISH_OFF;\r
-       }\r
-\r
-       tn = tpl_map(task_parameter_format_EMAIL_ASYNC_TASK_MOVE_MAILS_TO_MAILBOX_OF_ANOTHER_ACCOUNT\r
-                               , &task_parameter->source_mailbox_id\r
-                               , &task_parameter->target_mailbox_id\r
-                               , &task_parameter->mail_id_count\r
-                               , &tb);\r
+               EM_DEBUG_EXCEPTION("EMAIL_ERROR_OUT_OF_MEMORY");
+               err = EMAIL_ERROR_OUT_OF_MEMORY;
+               goto FINISH_OFF;
+       }
+
+       tn = tpl_map(task_parameter_format_EMAIL_ASYNC_TASK_MOVE_MAILS_TO_MAILBOX_OF_ANOTHER_ACCOUNT
+                               , &task_parameter->source_mailbox_id
+                               , &task_parameter->target_mailbox_id
+                               , &task_parameter->mail_id_count
+                               , &tb);
        if (tn == NULL) {
                EM_DEBUG_EXCEPTION("tpl_map failed");
                EM_SAFE_FREE(task_parameter);
@@ -121,127 +121,127 @@ INTERNAL_FUNC int email_decode_task_parameter_EMAIL_ASYNC_TASK_MOVE_MAILS_TO_MAI
                goto FINISH_OFF;
        }
 
-       tpl_load(tn, TPL_MEM, input_byte_stream, input_stream_size);\r
-       tpl_unpack(tn, 0);\r
-       if(task_parameter->mail_id_count <= 0 || tb.addr == NULL) {\r
-               EM_DEBUG_LOG("No mail id list. mail_id_count[%d] addr[%p]", task_parameter->mail_id_count, tb.addr);\r
-       }\r
-       else {\r
-               task_parameter->mail_id_array = tb.addr;\r
-       }\r
-\r
-       *output_task_parameter_struct = task_parameter;\r
-\r
-FINISH_OFF:\r
-\r
-       if(tn)\r
-               tpl_free(tn);\r
-\r
-       EM_DEBUG_FUNC_END("err [%d]", err);\r
-       return err;\r
-}\r
-\r
-INTERNAL_FUNC void* task_handler_EMAIL_ASYNC_TASK_MOVE_MAILS_TO_MAILBOX_OF_ANOTHER_ACCOUNT(void *input_param)\r
-{\r
-       EM_DEBUG_FUNC_BEGIN("input_param [%p]", input_param);\r
-       int err = EMAIL_ERROR_NONE;\r
-       int err_for_signal = EMAIL_ERROR_NONE;\r
-       int i = 0;\r
-       int task_id = THREAD_SELF();\r
-       task_parameter_EMAIL_ASYNC_TASK_MOVE_MAILS_TO_MAILBOX_OF_ANOTHER_ACCOUNT *task_param = input_param;\r
-\r
-       for(i = 0; i < task_param->mail_id_count; i++) {\r
-               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) {\r
-                       EM_DEBUG_EXCEPTION("emcore_move_mail_to_another_account failed [%d]", err);\r
-                       goto FINISH_OFF;\r
-               }\r
-\r
-               /* Send progress signal */\r
-               if((err_for_signal = emcore_send_task_status_signal(EMAIL_ASYNC_TASK_MOVE_MAILS_TO_MAILBOX_OF_ANOTHER_ACCOUNT, task_id, EMAIL_TASK_STATUS_IN_PROGRESS, i, task_param->mail_id_count)) != EMAIL_ERROR_NONE)\r
-                       EM_DEBUG_LOG("emcore_send_task_status_signal failed [%d]", err_for_signal);\r
-       }\r
-\r
-FINISH_OFF:\r
-       /* Free task parameter */\r
-       EM_SAFE_FREE(task_param->mail_id_array);\r
-       EM_SAFE_FREE(task_param);\r
-\r
-       EM_DEBUG_FUNC_END("err [%d]", err);\r
-       return NULL;\r
-}\r
-/*-------------------------------------------------------------------------------------------*/\r
-/* to handle EMAIL_ASYNC_TASK_DELETE_MAILBOX_EX */\r
-#define task_parameter_format_EMAIL_ASYNC_TASK_DELETE_MAILBOX_EX "iiBi"\r
-\r
-INTERNAL_FUNC int email_encode_task_parameter_EMAIL_ASYNC_TASK_DELETE_MAILBOX_EX(void *input_task_parameter_struct, char **output_byte_stream, int *output_stream_size)\r
-{\r
-       EM_DEBUG_FUNC_BEGIN("input_task_parameter_struct [%p] output_byte_stream [%p] output_stream_size [%p]", input_task_parameter_struct, output_byte_stream, output_stream_size);\r
-\r
-       int err = EMAIL_ERROR_NONE;\r
-       task_parameter_EMAIL_ASYNC_TASK_DELETE_MAILBOX_EX *task_parameter = input_task_parameter_struct;\r
-       tpl_bin tb;\r
-       tpl_node *tn = NULL;\r
-       void  *result_data = NULL;\r
-       size_t result_data_length = 0;\r
-\r
-       if (task_parameter == NULL || output_byte_stream == NULL || output_stream_size == NULL) {\r
-               EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");\r
-               err = EMAIL_ERROR_INVALID_PARAM;\r
-               goto FINISH_OFF;\r
-       }\r
-\r
-       tn = tpl_map(task_parameter_format_EMAIL_ASYNC_TASK_DELETE_MAILBOX_EX\r
-                       , &task_parameter->account_id\r
-                       , &task_parameter->mailbox_id_count\r
-                       , &tb\r
-                       , &task_parameter->on_server);\r
+       tpl_load(tn, TPL_MEM, input_byte_stream, input_stream_size);
+       tpl_unpack(tn, 0);
+       if(task_parameter->mail_id_count <= 0 || tb.addr == NULL) {
+               EM_DEBUG_LOG("No mail id list. mail_id_count[%d] addr[%p]", task_parameter->mail_id_count, tb.addr);
+       }
+       else {
+               task_parameter->mail_id_array = tb.addr;
+       }
+
+       *output_task_parameter_struct = task_parameter;
+
+FINISH_OFF:
+
+       if(tn)
+               tpl_free(tn);
+
+       EM_DEBUG_FUNC_END("err [%d]", err);
+       return err;
+}
+
+INTERNAL_FUNC void* task_handler_EMAIL_ASYNC_TASK_MOVE_MAILS_TO_MAILBOX_OF_ANOTHER_ACCOUNT(void *input_param)
+{
+       EM_DEBUG_FUNC_BEGIN("input_param [%p]", input_param);
+       int err = EMAIL_ERROR_NONE;
+       int err_for_signal = EMAIL_ERROR_NONE;
+       int i = 0;
+       int task_id = THREAD_SELF();
+       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->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;
+               }
+
+               /* Send progress signal */
+               if((err_for_signal = emcore_send_task_status_signal(EMAIL_ASYNC_TASK_MOVE_MAILS_TO_MAILBOX_OF_ANOTHER_ACCOUNT, task_id, EMAIL_TASK_STATUS_IN_PROGRESS, i, task_param->mail_id_count)) != EMAIL_ERROR_NONE)
+                       EM_DEBUG_LOG("emcore_send_task_status_signal failed [%d]", err_for_signal);
+       }
+
+FINISH_OFF:
+       /* Free task parameter */
+       EM_SAFE_FREE(task_param->mail_id_array);
+       EM_SAFE_FREE(task_param);
+
+       EM_DEBUG_FUNC_END("err [%d]", err);
+       return NULL;
+}
+/*-------------------------------------------------------------------------------------------*/
+/* to handle EMAIL_ASYNC_TASK_DELETE_MAILBOX_EX */
+#define task_parameter_format_EMAIL_ASYNC_TASK_DELETE_MAILBOX_EX "iiBi"
+
+INTERNAL_FUNC int email_encode_task_parameter_EMAIL_ASYNC_TASK_DELETE_MAILBOX_EX(void *input_task_parameter_struct, char **output_byte_stream, int *output_stream_size)
+{
+       EM_DEBUG_FUNC_BEGIN("input_task_parameter_struct [%p] output_byte_stream [%p] output_stream_size [%p]", input_task_parameter_struct, output_byte_stream, output_stream_size);
+
+       int err = EMAIL_ERROR_NONE;
+       task_parameter_EMAIL_ASYNC_TASK_DELETE_MAILBOX_EX *task_parameter = input_task_parameter_struct;
+       tpl_bin tb;
+       tpl_node *tn = NULL;
+       void  *result_data = NULL;
+       size_t result_data_length = 0;
+
+       if (task_parameter == NULL || output_byte_stream == NULL || output_stream_size == NULL) {
+               EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
+               err = EMAIL_ERROR_INVALID_PARAM;
+               goto FINISH_OFF;
+       }
+
+       tn = tpl_map(task_parameter_format_EMAIL_ASYNC_TASK_DELETE_MAILBOX_EX
+                       , &task_parameter->account_id
+                       , &task_parameter->mailbox_id_count
+                       , &tb
+                       , &task_parameter->on_server);
        if (tn == NULL) {
                EM_DEBUG_EXCEPTION("tpl_map failed");
                err = EMAIL_ERROR_SYSTEM_FAILURE;
                goto FINISH_OFF;
        }
 
-       tb.sz   = sizeof(int) * task_parameter->mailbox_id_count;\r
-       tb.addr = task_parameter->mailbox_id_array;\r
-       tpl_pack(tn, 0);\r
-       tpl_dump(tn, TPL_MEM, &result_data, &result_data_length);\r
-       tpl_free(tn);\r
-\r
-       *output_byte_stream = result_data;\r
-       *output_stream_size = result_data_length;\r
-\r
-FINISH_OFF:\r
-\r
-       EM_DEBUG_FUNC_END("err [%d]", err);\r
-       return err;\r
-}\r
-\r
-INTERNAL_FUNC int email_decode_task_parameter_EMAIL_ASYNC_TASK_DELETE_MAILBOX_EX(char *input_byte_stream, int input_stream_size, void **output_task_parameter_struct)\r
-{\r
-       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);\r
-       int err = EMAIL_ERROR_NONE;\r
-       tpl_bin tb;\r
-       tpl_node *tn = NULL;\r
-       task_parameter_EMAIL_ASYNC_TASK_DELETE_MAILBOX_EX *task_parameter = NULL;\r
-\r
-       if (input_byte_stream == NULL || input_stream_size == 0 || output_task_parameter_struct == NULL) {\r
-               EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");\r
-               err = EMAIL_ERROR_INVALID_PARAM;\r
-               goto FINISH_OFF;\r
-       }\r
-\r
-       task_parameter = em_malloc(sizeof(task_parameter_EMAIL_ASYNC_TASK_DELETE_MAILBOX_EX));\r
-       if(task_parameter == NULL) {\r
-               EM_DEBUG_EXCEPTION("EMAIL_ERROR_OUT_OF_MEMORY");\r
-               err = EMAIL_ERROR_OUT_OF_MEMORY;\r
-               goto FINISH_OFF;\r
-       }\r
-\r
-       tn = tpl_map(task_parameter_format_EMAIL_ASYNC_TASK_DELETE_MAILBOX_EX\r
-                               , &task_parameter->account_id\r
-                               , &task_parameter->mailbox_id_count\r
-                               , &tb\r
-                               , &task_parameter->on_server);\r
+       tb.sz   = sizeof(int) * task_parameter->mailbox_id_count;
+       tb.addr = task_parameter->mailbox_id_array;
+       tpl_pack(tn, 0);
+       tpl_dump(tn, TPL_MEM, &result_data, &result_data_length);
+       tpl_free(tn);
+
+       *output_byte_stream = result_data;
+       *output_stream_size = result_data_length;
+
+FINISH_OFF:
+
+       EM_DEBUG_FUNC_END("err [%d]", err);
+       return err;
+}
+
+INTERNAL_FUNC int email_decode_task_parameter_EMAIL_ASYNC_TASK_DELETE_MAILBOX_EX(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);
+       int err = EMAIL_ERROR_NONE;
+       tpl_bin tb;
+       tpl_node *tn = NULL;
+       task_parameter_EMAIL_ASYNC_TASK_DELETE_MAILBOX_EX *task_parameter = NULL;
+
+       if (input_byte_stream == NULL || input_stream_size == 0 || output_task_parameter_struct == NULL) {
+               EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
+               err = EMAIL_ERROR_INVALID_PARAM;
+               goto FINISH_OFF;
+       }
+
+       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;
+               goto FINISH_OFF;
+       }
+
+       tn = tpl_map(task_parameter_format_EMAIL_ASYNC_TASK_DELETE_MAILBOX_EX
+                               , &task_parameter->account_id
+                               , &task_parameter->mailbox_id_count
+                               , &tb
+                               , &task_parameter->on_server);
        if (tn == NULL) {
                EM_DEBUG_EXCEPTION("tpl_map failed");
                EM_SAFE_FREE(task_parameter);
@@ -249,93 +249,93 @@ INTERNAL_FUNC int email_decode_task_parameter_EMAIL_ASYNC_TASK_DELETE_MAILBOX_EX
                goto FINISH_OFF;
        }
 
-       tpl_load(tn, TPL_MEM, input_byte_stream, input_stream_size);\r
-       tpl_unpack(tn, 0);\r
-       if(task_parameter->mailbox_id_count <= 0 || tb.addr == NULL) {\r
-               EM_DEBUG_LOG("No mail id list. mail_id_count[%d] addr[%p]", task_parameter->mailbox_id_count, tb.addr);\r
-       }\r
-       else {\r
-               task_parameter->mailbox_id_array = tb.addr;\r
-       }\r
-\r
-       *output_task_parameter_struct = task_parameter;\r
-\r
-FINISH_OFF:\r
-\r
-       if(tn)\r
-               tpl_free(tn);\r
-\r
-       EM_DEBUG_FUNC_END("err [%d]", err);\r
-       return err;\r
-}\r
-\r
-INTERNAL_FUNC void* task_handler_EMAIL_ASYNC_TASK_DELETE_MAILBOX_EX(void *input_param)\r
-{\r
-       return NULL;\r
-}\r
-/*-------------------------------------------------------------------------------------------*/\r
-/* to handle EMAIL_ASYNC_TASK_SEND_MAIL_WITH_DOWNLOADING_ATTACHMENT_OF_ORIGINAL_MAIL */\r
-#define task_parameter_format_EMAIL_ASYNC_TASK_SEND_MAIL_WITH_DOWNLOADING_ATTACHMENT_OF_ORIGINAL_MAIL "i"\r
-\r
-INTERNAL_FUNC int email_encode_task_parameter_EMAIL_ASYNC_TASK_SEND_MAIL_WITH_DOWNLOADING_ATTACHMENT_OF_ORIGINAL_MAIL(void *input_task_parameter_struct, char **output_byte_stream, int *output_stream_size)\r
-{\r
-       EM_DEBUG_FUNC_BEGIN("input_task_parameter_struct [%p] output_byte_stream [%p] output_stream_size [%p]", input_task_parameter_struct, output_byte_stream, output_stream_size);\r
-\r
-       int err = EMAIL_ERROR_NONE;\r
-       task_parameter_EMAIL_ASYNC_TASK_SEND_MAIL_WITH_DOWNLOADING_ATTACHMENT_OF_ORIGINAL_MAIL *task_parameter = input_task_parameter_struct;\r
-       tpl_node *tn = NULL;\r
-       void  *result_data = NULL;\r
-       size_t result_data_length = 0;\r
-\r
-       if (task_parameter == NULL || output_byte_stream == NULL || output_stream_size == NULL) {\r
-               EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");\r
-               err = EMAIL_ERROR_INVALID_PARAM;\r
-               goto FINISH_OFF;\r
-       }\r
-\r
-       tn = tpl_map(task_parameter_format_EMAIL_ASYNC_TASK_SEND_MAIL_WITH_DOWNLOADING_ATTACHMENT_OF_ORIGINAL_MAIL\r
-                       , &task_parameter->mail_id);\r
+       tpl_load(tn, TPL_MEM, input_byte_stream, input_stream_size);
+       tpl_unpack(tn, 0);
+       if(task_parameter->mailbox_id_count <= 0 || tb.addr == NULL) {
+               EM_DEBUG_LOG("No mail id list. mail_id_count[%d] addr[%p]", task_parameter->mailbox_id_count, tb.addr);
+       }
+       else {
+               task_parameter->mailbox_id_array = tb.addr;
+       }
+
+       *output_task_parameter_struct = task_parameter;
+
+FINISH_OFF:
+
+       if(tn)
+               tpl_free(tn);
+
+       EM_DEBUG_FUNC_END("err [%d]", err);
+       return err;
+}
+
+INTERNAL_FUNC void* task_handler_EMAIL_ASYNC_TASK_DELETE_MAILBOX_EX(void *input_param)
+{
+       return NULL;
+}
+/*-------------------------------------------------------------------------------------------*/
+/* to handle EMAIL_ASYNC_TASK_SEND_MAIL_WITH_DOWNLOADING_ATTACHMENT_OF_ORIGINAL_MAIL */
+#define task_parameter_format_EMAIL_ASYNC_TASK_SEND_MAIL_WITH_DOWNLOADING_ATTACHMENT_OF_ORIGINAL_MAIL "i"
+
+INTERNAL_FUNC int email_encode_task_parameter_EMAIL_ASYNC_TASK_SEND_MAIL_WITH_DOWNLOADING_ATTACHMENT_OF_ORIGINAL_MAIL(void *input_task_parameter_struct, char **output_byte_stream, int *output_stream_size)
+{
+       EM_DEBUG_FUNC_BEGIN("input_task_parameter_struct [%p] output_byte_stream [%p] output_stream_size [%p]", input_task_parameter_struct, output_byte_stream, output_stream_size);
+
+       int err = EMAIL_ERROR_NONE;
+       task_parameter_EMAIL_ASYNC_TASK_SEND_MAIL_WITH_DOWNLOADING_ATTACHMENT_OF_ORIGINAL_MAIL *task_parameter = input_task_parameter_struct;
+       tpl_node *tn = NULL;
+       void  *result_data = NULL;
+       size_t result_data_length = 0;
+
+       if (task_parameter == NULL || output_byte_stream == NULL || output_stream_size == NULL) {
+               EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
+               err = EMAIL_ERROR_INVALID_PARAM;
+               goto FINISH_OFF;
+       }
+
+       tn = tpl_map(task_parameter_format_EMAIL_ASYNC_TASK_SEND_MAIL_WITH_DOWNLOADING_ATTACHMENT_OF_ORIGINAL_MAIL
+                       , &task_parameter->mail_id);
        if (tn == NULL) {
                EM_DEBUG_EXCEPTION("tpl_map failed");
                err = EMAIL_ERROR_SYSTEM_FAILURE;
                goto FINISH_OFF;
        }
 
-       tpl_pack(tn, 0);\r
-       tpl_dump(tn, TPL_MEM, &result_data, &result_data_length);\r
-       tpl_free(tn);\r
-\r
-       *output_byte_stream = result_data;\r
-       *output_stream_size = result_data_length;\r
-\r
-FINISH_OFF:\r
-\r
-       EM_DEBUG_FUNC_END("err [%d]", err);\r
-       return err;\r
-}\r
-\r
-INTERNAL_FUNC int email_decode_task_parameter_EMAIL_ASYNC_TASK_SEND_MAIL_WITH_DOWNLOADING_ATTACHMENT_OF_ORIGINAL_MAIL(char *input_byte_stream, int input_stream_size, void **output_task_parameter_struct)\r
-{\r
-       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);\r
-       int err = EMAIL_ERROR_NONE;\r
-       tpl_node *tn = NULL;\r
-       task_parameter_EMAIL_ASYNC_TASK_SEND_MAIL_WITH_DOWNLOADING_ATTACHMENT_OF_ORIGINAL_MAIL *task_parameter = NULL;\r
-\r
-       if (input_byte_stream == NULL || input_stream_size == 0 || output_task_parameter_struct == NULL) {\r
-               EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");\r
-               err = EMAIL_ERROR_INVALID_PARAM;\r
-               goto FINISH_OFF;\r
-       }\r
-\r
-       task_parameter = em_malloc(sizeof(task_parameter_EMAIL_ASYNC_TASK_SEND_MAIL_WITH_DOWNLOADING_ATTACHMENT_OF_ORIGINAL_MAIL));\r
+       tpl_pack(tn, 0);
+       tpl_dump(tn, TPL_MEM, &result_data, &result_data_length);
+       tpl_free(tn);
+
+       *output_byte_stream = result_data;
+       *output_stream_size = result_data_length;
+
+FINISH_OFF:
+
+       EM_DEBUG_FUNC_END("err [%d]", err);
+       return err;
+}
+
+INTERNAL_FUNC int email_decode_task_parameter_EMAIL_ASYNC_TASK_SEND_MAIL_WITH_DOWNLOADING_ATTACHMENT_OF_ORIGINAL_MAIL(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);
+       int err = EMAIL_ERROR_NONE;
+       tpl_node *tn = NULL;
+       task_parameter_EMAIL_ASYNC_TASK_SEND_MAIL_WITH_DOWNLOADING_ATTACHMENT_OF_ORIGINAL_MAIL *task_parameter = NULL;
+
+       if (input_byte_stream == NULL || input_stream_size == 0 || output_task_parameter_struct == NULL) {
+               EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
+               err = EMAIL_ERROR_INVALID_PARAM;
+               goto FINISH_OFF;
+       }
+
+       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");\r
-               err = EMAIL_ERROR_OUT_OF_MEMORY;\r
-               goto FINISH_OFF;\r
-       }\r
-\r
-       tn = tpl_map(task_parameter_format_EMAIL_ASYNC_TASK_SEND_MAIL_WITH_DOWNLOADING_ATTACHMENT_OF_ORIGINAL_MAIL\r
-                               , &task_parameter->mail_id);\r
+               EM_DEBUG_EXCEPTION("EMAIL_ERROR_OUT_OF_MEMORY");
+               err = EMAIL_ERROR_OUT_OF_MEMORY;
+               goto FINISH_OFF;
+       }
+
+       tn = tpl_map(task_parameter_format_EMAIL_ASYNC_TASK_SEND_MAIL_WITH_DOWNLOADING_ATTACHMENT_OF_ORIGINAL_MAIL
+                               , &task_parameter->mail_id);
        if (tn == NULL) {
                EM_DEBUG_EXCEPTION("tpl_map failed");
                EM_SAFE_FREE(task_parameter);
@@ -343,87 +343,87 @@ INTERNAL_FUNC int email_decode_task_parameter_EMAIL_ASYNC_TASK_SEND_MAIL_WITH_DO
                goto FINISH_OFF;
        }
 
-       tpl_load(tn, TPL_MEM, input_byte_stream, input_stream_size);\r
-       tpl_unpack(tn, 0);\r
-\r
-       *output_task_parameter_struct = task_parameter;\r
-\r
-FINISH_OFF:\r
-\r
-       if(tn)\r
-               tpl_free(tn);\r
-\r
-       EM_DEBUG_FUNC_END("err [%d]", err);\r
-       return err;\r
-}\r
-\r
-INTERNAL_FUNC void* task_handler_EMAIL_ASYNC_TASK_SEND_MAIL_WITH_DOWNLOADING_ATTACHMENT_OF_ORIGINAL_MAIL(void *input_param)\r
-{\r
-       return NULL;\r
-}\r
-/*-------------------------------------------------------------------------------------------*/\r
-/* to handle EMAIL_SYNC_TASK_SCHEDULE_SENDING_MAIL */\r
-#define task_parameter_format_EMAIL_SYNC_TASK_SCHEDULE_SENDING_MAIL "ii"\r
-\r
-INTERNAL_FUNC int email_encode_task_parameter_EMAIL_SYNC_TASK_SCHEDULE_SENDING_MAIL(void *input_task_parameter_struct, char **output_byte_stream, int *output_stream_size)\r
-{\r
-       EM_DEBUG_FUNC_BEGIN("input_task_parameter_struct [%p] output_byte_stream [%p] output_stream_size [%p]", input_task_parameter_struct, output_byte_stream, output_stream_size);\r
-\r
-       int err = EMAIL_ERROR_NONE;\r
-       task_parameter_EMAIL_SYNC_TASK_SCHEDULE_SENDING_MAIL *task_parameter = input_task_parameter_struct;\r
-       tpl_node *tn = NULL;\r
-       void  *result_data = NULL;\r
-       size_t result_data_length = 0;\r
-\r
-       if (task_parameter == NULL || output_byte_stream == NULL || output_stream_size == NULL) {\r
-               EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");\r
-               err = EMAIL_ERROR_INVALID_PARAM;\r
-               goto FINISH_OFF;\r
-       }\r
-\r
-       tn = tpl_map(task_parameter_format_EMAIL_SYNC_TASK_SCHEDULE_SENDING_MAIL\r
-                       , &task_parameter->mail_id, &task_parameter->scheduled_time);\r
+       tpl_load(tn, TPL_MEM, input_byte_stream, input_stream_size);
+       tpl_unpack(tn, 0);
+
+       *output_task_parameter_struct = task_parameter;
+
+FINISH_OFF:
+
+       if(tn)
+               tpl_free(tn);
+
+       EM_DEBUG_FUNC_END("err [%d]", err);
+       return err;
+}
+
+INTERNAL_FUNC void* task_handler_EMAIL_ASYNC_TASK_SEND_MAIL_WITH_DOWNLOADING_ATTACHMENT_OF_ORIGINAL_MAIL(void *input_param)
+{
+       return NULL;
+}
+/*-------------------------------------------------------------------------------------------*/
+/* to handle EMAIL_SYNC_TASK_SCHEDULE_SENDING_MAIL */
+#define task_parameter_format_EMAIL_SYNC_TASK_SCHEDULE_SENDING_MAIL "ii"
+
+INTERNAL_FUNC int email_encode_task_parameter_EMAIL_SYNC_TASK_SCHEDULE_SENDING_MAIL(void *input_task_parameter_struct, char **output_byte_stream, int *output_stream_size)
+{
+       EM_DEBUG_FUNC_BEGIN("input_task_parameter_struct [%p] output_byte_stream [%p] output_stream_size [%p]", input_task_parameter_struct, output_byte_stream, output_stream_size);
+
+       int err = EMAIL_ERROR_NONE;
+       task_parameter_EMAIL_SYNC_TASK_SCHEDULE_SENDING_MAIL *task_parameter = input_task_parameter_struct;
+       tpl_node *tn = NULL;
+       void  *result_data = NULL;
+       size_t result_data_length = 0;
+
+       if (task_parameter == NULL || output_byte_stream == NULL || output_stream_size == NULL) {
+               EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
+               err = EMAIL_ERROR_INVALID_PARAM;
+               goto FINISH_OFF;
+       }
+
+       tn = tpl_map(task_parameter_format_EMAIL_SYNC_TASK_SCHEDULE_SENDING_MAIL
+                       , &task_parameter->mail_id, &task_parameter->scheduled_time);
        if (tn == NULL) {
                EM_DEBUG_EXCEPTION("tpl_map failed");
                err = EMAIL_ERROR_SYSTEM_FAILURE;
                goto FINISH_OFF;
        }
 
-       tpl_pack(tn, 0);\r
-       tpl_dump(tn, TPL_MEM, &result_data, &result_data_length);\r
-       tpl_free(tn);\r
-\r
-       *output_byte_stream = result_data;\r
-       *output_stream_size = result_data_length;\r
-\r
-FINISH_OFF:\r
-\r
-       EM_DEBUG_FUNC_END("err [%d]", err);\r
-       return err;\r
-}\r
-\r
-INTERNAL_FUNC int email_decode_task_parameter_EMAIL_SYNC_TASK_SCHEDULE_SENDING_MAIL(char *input_byte_stream, int input_stream_size, void **output_task_parameter_struct)\r
-{\r
-       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);\r
-       int err = EMAIL_ERROR_NONE;\r
-       tpl_node *tn = NULL;\r
-       task_parameter_EMAIL_SYNC_TASK_SCHEDULE_SENDING_MAIL *task_parameter = NULL;\r
-\r
-       if (input_byte_stream == NULL || input_stream_size == 0 || output_task_parameter_struct == NULL) {\r
-               EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");\r
-               err = EMAIL_ERROR_INVALID_PARAM;\r
-               goto FINISH_OFF;\r
-       }\r
-\r
-       task_parameter = em_malloc(sizeof(task_parameter_EMAIL_SYNC_TASK_SCHEDULE_SENDING_MAIL));\r
-       if(task_parameter == NULL) {\r
-               EM_DEBUG_EXCEPTION("EMAIL_ERROR_OUT_OF_MEMORY");\r
-               err = EMAIL_ERROR_OUT_OF_MEMORY;\r
-               goto FINISH_OFF;\r
-       }\r
-\r
-       tn = tpl_map(task_parameter_format_EMAIL_SYNC_TASK_SCHEDULE_SENDING_MAIL\r
-                               , &task_parameter->mail_id, &task_parameter->scheduled_time);\r
+       tpl_pack(tn, 0);
+       tpl_dump(tn, TPL_MEM, &result_data, &result_data_length);
+       tpl_free(tn);
+
+       *output_byte_stream = result_data;
+       *output_stream_size = result_data_length;
+
+FINISH_OFF:
+
+       EM_DEBUG_FUNC_END("err [%d]", err);
+       return err;
+}
+
+INTERNAL_FUNC int email_decode_task_parameter_EMAIL_SYNC_TASK_SCHEDULE_SENDING_MAIL(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);
+       int err = EMAIL_ERROR_NONE;
+       tpl_node *tn = NULL;
+       task_parameter_EMAIL_SYNC_TASK_SCHEDULE_SENDING_MAIL *task_parameter = NULL;
+
+       if (input_byte_stream == NULL || input_stream_size == 0 || output_task_parameter_struct == NULL) {
+               EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
+               err = EMAIL_ERROR_INVALID_PARAM;
+               goto FINISH_OFF;
+       }
+
+       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;
+               goto FINISH_OFF;
+       }
+
+       tn = tpl_map(task_parameter_format_EMAIL_SYNC_TASK_SCHEDULE_SENDING_MAIL
+                               , &task_parameter->mail_id, &task_parameter->scheduled_time);
        if (tn == NULL) {
                EM_DEBUG_EXCEPTION("tpl_map failed");
                EM_SAFE_FREE(task_parameter);
@@ -431,268 +431,308 @@ INTERNAL_FUNC int email_decode_task_parameter_EMAIL_SYNC_TASK_SCHEDULE_SENDING_M
                goto FINISH_OFF;
        }
 
-       tpl_load(tn, TPL_MEM, input_byte_stream, input_stream_size);\r
-       tpl_unpack(tn, 0);\r
-\r
-       *output_task_parameter_struct = task_parameter;\r
-\r
-FINISH_OFF:\r
-\r
-       if(tn)\r
-               tpl_free(tn);\r
-\r
-       EM_DEBUG_FUNC_END("err [%d]", err);\r
-       return err;\r
-}\r
-\r
-INTERNAL_FUNC void* task_handler_EMAIL_SYNC_TASK_SCHEDULE_SENDING_MAIL(void *input_param)\r
-{\r
-       EM_DEBUG_FUNC_BEGIN("input_param [%p]", input_param);\r
-       int err = EMAIL_ERROR_NONE;\r
-       task_parameter_EMAIL_SYNC_TASK_SCHEDULE_SENDING_MAIL *task_param = input_param;\r
-\r
-       if((err = emcore_schedule_sending_mail(task_param->multi_user_name, task_param->mail_id, task_param->scheduled_time)) != EMAIL_ERROR_NONE) {\r
-               EM_DEBUG_EXCEPTION("emcore_schedule_sending_mail [%d]", err);\r
-               err = EMAIL_ERROR_OUT_OF_MEMORY;\r
-               goto FINISH_OFF;\r
-       }\r
-\r
-FINISH_OFF:\r
-\r
+       tpl_load(tn, TPL_MEM, input_byte_stream, input_stream_size);
+       tpl_unpack(tn, 0);
+
+       *output_task_parameter_struct = task_parameter;
+
+FINISH_OFF:
+
+       if(tn)
+               tpl_free(tn);
+
+       EM_DEBUG_FUNC_END("err [%d]", err);
+       return err;
+}
+
+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->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 ();\r
-       EM_DEBUG_FUNC_END("err [%d]", err);\r
-       return (void*)err;\r
-}\r
-/*-------------------------------------------------------------------------------------------*/\r
-/* to handle EMAIL_SYNC_TASK_UPDATE_ATTRIBUTE */\r
-#define task_parameter_format_EMAIL_SYNC_TASK_UPDATE_ATTRIBUTE "iiBiiB"\r
-\r
-INTERNAL_FUNC int email_encode_task_parameter_EMAIL_SYNC_TASK_UPDATE_ATTRIBUTE(void *input_task_parameter_struct, char **output_byte_stream, int *output_stream_size)\r
-{\r
-       EM_DEBUG_FUNC_BEGIN("input_task_parameter_struct [%p] output_byte_stream [%p] output_stream_size [%p]", input_task_parameter_struct, output_byte_stream, output_stream_size);\r
-\r
-       int err = EMAIL_ERROR_NONE;\r
-       task_parameter_EMAIL_SYNC_TASK_UPDATE_ATTRIBUTE *task_parameter = input_task_parameter_struct;\r
-       email_mail_attribute_value_type attribute_value_type = EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_NONE;\r
-       tpl_bin tb_mail_id_array;\r
-       tpl_bin tb_value;\r
-       tpl_node *tn = NULL;\r
-       void  *result_data = NULL;\r
-       size_t result_data_length = 0;\r
-\r
-       if (task_parameter == NULL || output_byte_stream == NULL || output_stream_size == NULL) {\r
-               EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");\r
-               err = EMAIL_ERROR_INVALID_PARAM;\r
-               goto FINISH_OFF;\r
-       }\r
-\r
-       if ((err = emcore_get_mail_attribute_value_type(task_parameter->attribute_type, &attribute_value_type)) != EMAIL_ERROR_NONE) {\r
-               EM_DEBUG_EXCEPTION("emcore_get_mail_attribute_value_type failed [%d]", err);\r
-               goto FINISH_OFF;\r
-       }\r
-\r
-       tn = tpl_map(task_parameter_format_EMAIL_SYNC_TASK_UPDATE_ATTRIBUTE\r
-                               , &task_parameter->account_id\r
-                               , &task_parameter->mail_id_count\r
-                               , &tb_mail_id_array\r
-                               , &task_parameter->attribute_type\r
-                               , &task_parameter->value_length\r
-                               , &tb_value);\r
+       emcore_close_smtp_stream_list();
+       EM_DEBUG_FUNC_END("err [%d]", err);
+
+       return (void *)return_err;
+}
+/*-------------------------------------------------------------------------------------------*/
+/* to handle EMAIL_SYNC_TASK_UPDATE_ATTRIBUTE */
+#define task_parameter_format_EMAIL_SYNC_TASK_UPDATE_ATTRIBUTE "iiBiiB"
+
+INTERNAL_FUNC int email_encode_task_parameter_EMAIL_SYNC_TASK_UPDATE_ATTRIBUTE(void *input_task_parameter_struct, char **output_byte_stream, int *output_stream_size)
+{
+       EM_DEBUG_FUNC_BEGIN("input_task_parameter_struct [%p] output_byte_stream [%p] output_stream_size [%p]", input_task_parameter_struct, output_byte_stream, output_stream_size);
+
+       int err = EMAIL_ERROR_NONE;
+       task_parameter_EMAIL_SYNC_TASK_UPDATE_ATTRIBUTE *task_parameter = input_task_parameter_struct;
+       email_mail_attribute_value_type attribute_value_type = EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_NONE;
+       tpl_bin tb_mail_id_array;
+       tpl_bin tb_value;
+       tpl_node *tn = NULL;
+       void  *result_data = NULL;
+       size_t result_data_length = 0;
+
+       if (task_parameter == 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_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;
+       }
+
+       tn = tpl_map(task_parameter_format_EMAIL_SYNC_TASK_UPDATE_ATTRIBUTE
+                               , &task_parameter->account_id
+                               , &task_parameter->mail_id_count
+                               , &tb_mail_id_array
+                               , &task_parameter->attribute_type
+                               , &task_parameter->value_length
+                               , &tb_value);
        if (tn == NULL) {
                EM_DEBUG_EXCEPTION("tpl_map failed");
                err = EMAIL_ERROR_SYSTEM_FAILURE;
                goto FINISH_OFF;
        }
-\r
-       tb_mail_id_array.sz   = sizeof(int) * task_parameter->mail_id_count;\r
-       tb_mail_id_array.addr = task_parameter->mail_id_array;\r
-\r
-       switch(attribute_value_type) {\r
-               case EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_INTEGER :\r
-                       task_parameter->value_length = 4;\r
-                       tb_value.sz                  = task_parameter->value_length;\r
-                       tb_value.addr                = &task_parameter->value.integer_type_value;\r
-                       break;\r
-               case EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_STRING :\r
-                       task_parameter->value_length = EM_SAFE_STRLEN(task_parameter->value.string_type_value);\r
-                       tb_value.sz                  = task_parameter->value_length;\r
-                       tb_value.addr                = task_parameter->value.string_type_value;\r
-                       break;\r
-               case EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_TIME :\r
-                       task_parameter->value_length = 4;\r
-                       tb_value.sz                  = task_parameter->value_length;\r
-                       tb_value.addr                = &task_parameter->value.datetime_type_value;\r
-                       break;\r
-               case EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_NONE :\r
-               default :\r
-                       EM_DEBUG_EXCEPTION("invalid attribute value type [%d]", attribute_value_type);\r
-                       err = EMAIL_ERROR_INVALID_PARAM;\r
-                       goto FINISH_OFF;\r
-       }\r
-\r
-       tpl_pack(tn, 0);\r
-       tpl_dump(tn, TPL_MEM, &result_data, &result_data_length);\r
-\r
-       *output_byte_stream = result_data;\r
-       *output_stream_size = result_data_length;\r
-\r
-FINISH_OFF:\r
-\r
-       if(tn)\r
-               tpl_free(tn);\r
-\r
-       EM_DEBUG_FUNC_END("err [%d]", err);\r
-       return EMAIL_ERROR_NONE;\r
-}\r
-\r
-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)\r
-{\r
-       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);\r
-       int err = EMAIL_ERROR_NONE;\r
-       tpl_node *tn = NULL;\r
-       tpl_bin tb_mail_id_array;\r
-       tpl_bin tb_value;\r
-       task_parameter_EMAIL_SYNC_TASK_UPDATE_ATTRIBUTE *task_parameter = NULL;\r
-       email_mail_attribute_value_type attribute_value_type = EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_NONE;\r
-\r
-       if (input_byte_stream == NULL || input_stream_size == 0 || output_task_parameter_struct == NULL) {\r
-               EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");\r
-               err = EMAIL_ERROR_INVALID_PARAM;\r
-               goto FINISH_OFF;\r
-       }\r
-\r
-       task_parameter = em_malloc(sizeof(task_parameter_EMAIL_SYNC_TASK_UPDATE_ATTRIBUTE));\r
-\r
-       if(task_parameter == NULL) {\r
-               EM_DEBUG_EXCEPTION("EMAIL_ERROR_OUT_OF_MEMORY");\r
-               err = EMAIL_ERROR_OUT_OF_MEMORY;\r
-               goto FINISH_OFF;\r
-       }\r
-\r
-       tn = tpl_map(task_parameter_format_EMAIL_SYNC_TASK_UPDATE_ATTRIBUTE\r
-                       , &task_parameter->account_id\r
-                       , &task_parameter->mail_id_count\r
-                       , &tb_mail_id_array\r
-                       , &task_parameter->attribute_type\r
-                       , &task_parameter->value_length\r
-                       , &tb_value);\r
+
+       tb_mail_id_array.sz   = sizeof(int) * task_parameter->mail_id_count;
+       tb_mail_id_array.addr = task_parameter->mail_id_array;
+
+       switch(attribute_value_type) {
+               case EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_INTEGER :
+                       task_parameter->value_length = 4;
+                       tb_value.sz                  = task_parameter->value_length;
+                       tb_value.addr                = &task_parameter->value.integer_type_value;
+                       break;
+               case EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_STRING :
+                       task_parameter->value_length = EM_SAFE_STRLEN(task_parameter->value.string_type_value);
+                       tb_value.sz                  = task_parameter->value_length;
+                       tb_value.addr                = task_parameter->value.string_type_value;
+                       break;
+               case EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_TIME :
+                       task_parameter->value_length = 4;
+                       tb_value.sz                  = task_parameter->value_length;
+                       tb_value.addr                = &task_parameter->value.datetime_type_value;
+                       break;
+               case EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_NONE :
+               default :
+                       EM_DEBUG_EXCEPTION("invalid attribute value type [%d]", attribute_value_type);
+                       err = EMAIL_ERROR_INVALID_PARAM;
+                       goto FINISH_OFF;
+       }
+
+       tpl_pack(tn, 0);
+       tpl_dump(tn, TPL_MEM, &result_data, &result_data_length);
+
+       *output_byte_stream = result_data;
+       *output_stream_size = result_data_length;
+
+FINISH_OFF:
+
+       if(tn)
+               tpl_free(tn);
+
+       EM_DEBUG_FUNC_END("err [%d]", err);
+       return EMAIL_ERROR_NONE;
+}
+
+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);
+       int err = EMAIL_ERROR_NONE;
+       tpl_node *tn = NULL;
+       tpl_bin tb_mail_id_array;
+       tpl_bin tb_value;
+       task_parameter_EMAIL_SYNC_TASK_UPDATE_ATTRIBUTE *task_parameter = NULL;
+       email_mail_attribute_value_type attribute_value_type = EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_NONE;
+
+       if (input_byte_stream == NULL || input_stream_size == 0 || output_task_parameter_struct == NULL) {
+               EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
+               err = EMAIL_ERROR_INVALID_PARAM;
+               goto FINISH_OFF;
+       }
+
+       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;
+               goto FINISH_OFF;
+       }
+
+       tn = tpl_map(task_parameter_format_EMAIL_SYNC_TASK_UPDATE_ATTRIBUTE
+                       , &task_parameter->account_id
+                       , &task_parameter->mail_id_count
+                       , &tb_mail_id_array
+                       , &task_parameter->attribute_type
+                       , &task_parameter->value_length
+                       , &tb_value);
        if (tn == NULL) {
                EM_DEBUG_EXCEPTION("tpl_map failed");
                err = EMAIL_ERROR_SYSTEM_FAILURE;
                goto FINISH_OFF;
        }
-\r
-       tpl_load(tn, TPL_MEM, input_byte_stream, input_stream_size);\r
-       tpl_unpack(tn, 0);\r
-\r
-       if(task_parameter->mail_id_count <= 0 || tb_mail_id_array.addr == NULL) {\r
-               EM_DEBUG_LOG("No mail id list. mail_id_count[%d] addr[%p]", task_parameter->mail_id_count, tb_mail_id_array.addr);\r
-       }\r
-       else {\r
-               task_parameter->mail_id_array = tb_mail_id_array.addr;\r
-       }\r
-\r
-       if(tb_value.addr) {\r
-               if ((err = emcore_get_mail_attribute_value_type(task_parameter->attribute_type, &attribute_value_type)) != EMAIL_ERROR_NONE) {\r
-                       EM_DEBUG_EXCEPTION("emcore_get_mail_attribute_value_type failed [%d]", err);\r
-                       goto FINISH_OFF;\r
-               }\r
-\r
-               switch(attribute_value_type) {\r
-                       case EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_INTEGER :\r
-                               memcpy(&task_parameter->value.integer_type_value, tb_value.addr, tb_value.sz);\r
-                               break;\r
-                       case EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_STRING :\r
-                               task_parameter->value.string_type_value = em_malloc(tb_value.sz + 1);\r
-                               if(task_parameter->value.string_type_value == NULL) {\r
-                                       EM_DEBUG_EXCEPTION("EMAIL_ERROR_OUT_OF_MEMORY");\r
-                                       err = EMAIL_ERROR_OUT_OF_MEMORY;\r
-                                       goto FINISH_OFF;\r
-                               }\r
-                               memcpy(&task_parameter->value.string_type_value, tb_value.addr, tb_value.sz);\r
-                               break;\r
-                       case EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_TIME :\r
-                               memcpy(&task_parameter->value.datetime_type_value, tb_value.addr, tb_value.sz);\r
-                               break;\r
-                       case EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_NONE :\r
-                       default :\r
-                               EM_DEBUG_EXCEPTION("invalid attribute value type [%d]", attribute_value_type);\r
-                               err = EMAIL_ERROR_INVALID_PARAM;\r
-                               goto FINISH_OFF;\r
-               }\r
-       }\r
-\r
-       *output_task_parameter_struct = task_parameter;\r
-\r
-FINISH_OFF:\r
-\r
-       if(tn)\r
-               tpl_free(tn);\r
-\r
-       EM_DEBUG_FUNC_END("err [%d]", err);\r
-       return EMAIL_ERROR_NONE;\r
-}\r
-\r
-INTERNAL_FUNC void* task_handler_EMAIL_SYNC_TASK_UPDATE_ATTRIBUTE(void *input_param)\r
-{\r
-       EM_DEBUG_FUNC_BEGIN("input_param [%p]", input_param);\r
-       if(!input_param) { /*prevent 43681*/\r
-               EM_DEBUG_EXCEPTION("NULL parameter");           \r
-               return NULL;\r
-       }\r
-\r
-       int err = EMAIL_ERROR_NONE;\r
-       char *field_name = NULL;\r
-       task_parameter_EMAIL_SYNC_TASK_UPDATE_ATTRIBUTE *task_param = input_param;\r
-       email_mail_attribute_value_type attribute_value_type = EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_NONE; /*prevent 43700*/\r
-\r
-       if((field_name = emcore_get_mail_field_name_by_attribute_type(task_param->attribute_type)) == NULL) {\r
-               EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");\r
-               err = EMAIL_ERROR_INVALID_PARAM;\r
-               goto FINISH_OFF;\r
-       }\r
-\r
-       if((err = emcore_get_mail_attribute_value_type(task_param->attribute_type, &attribute_value_type)) != EMAIL_ERROR_NONE) {\r
-               EM_DEBUG_EXCEPTION("emcore_get_mail_attribute_value_type failed [%d]", err);\r
-               goto FINISH_OFF;\r
-       }\r
-\r
-       switch(attribute_value_type) {\r
-               case EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_INTEGER :\r
-                       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)) {\r
-                               EM_DEBUG_EXCEPTION("emstorage_set_field_of_mails_with_integer_value failed [%d]", err);\r
-                               goto FINISH_OFF;\r
-                       }\r
-                       break;\r
-               case EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_STRING :\r
-                       err = EMAIL_ERROR_NOT_SUPPORTED;\r
-                       EM_DEBUG_LOG("EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_STRING is not supported");\r
-                       break;\r
-               case EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_TIME :\r
-                       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)) {\r
-                               EM_DEBUG_EXCEPTION("emstorage_set_field_of_mails_with_integer_value failed [%d]", err);\r
-                               goto FINISH_OFF;\r
-                       }\r
-                       break;\r
-               case EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_NONE :\r
-               default :\r
-                       EM_DEBUG_LOG("EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_NONE or default");\r
-                       err = EMAIL_ERROR_INVALID_PARAM;\r
-                       break;\r
-       }\r
-\r
-FINISH_OFF:\r
-\r
-       EM_SAFE_FREE(task_param->multi_user_name);\r
-       EM_SAFE_FREE(task_param->mail_id_array);\r
-       if (attribute_value_type == EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_STRING) {\r
-               EM_SAFE_FREE(task_param->value.string_type_value);\r
-       }\r
-\r
-       EM_SAFE_FREE (task_param);\r
-\r
-       EM_DEBUG_FUNC_END("err [%d]", err);\r
-       return (void*)err;\r
-}\r
-/*-------------------------------------------------------------------------------------------*/\r
+
+       tpl_load(tn, TPL_MEM, input_byte_stream, input_stream_size);
+       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);
+       }
+       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) {
+                       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 :
+                               memcpy(&task_parameter->value.integer_type_value, tb_value.addr, tb_value.sz);
+                               break;
+                       case EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_STRING :
+                               task_parameter->value.string_type_value = em_malloc(tb_value.sz + 1);
+                               if(task_parameter->value.string_type_value == NULL) {
+                                       EM_DEBUG_EXCEPTION("EMAIL_ERROR_OUT_OF_MEMORY");
+                                       err = EMAIL_ERROR_OUT_OF_MEMORY;
+                                       goto FINISH_OFF;
+                               }
+                               memcpy(&task_parameter->value.string_type_value, tb_value.addr, tb_value.sz);
+                               break;
+                       case EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_TIME :
+                               memcpy(&task_parameter->value.datetime_type_value, tb_value.addr, tb_value.sz);
+                               break;
+                       case EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_NONE :
+                       default :
+                               EM_DEBUG_EXCEPTION("invalid attribute value type [%d]", attribute_value_type);
+                               err = EMAIL_ERROR_INVALID_PARAM;
+                               goto FINISH_OFF;
+               }
+       }
+
+       *output_task_parameter_struct = task_parameter;
+
+FINISH_OFF:
+
+       if(tn)
+               tpl_free(tn);
+
+       EM_DEBUG_FUNC_END("err [%d]", err);
+       return EMAIL_ERROR_NONE;
+}
+
+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*/
+               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) {
+               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) {
+               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->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;
+                       }
+                       break;
+               case EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_STRING :
+                       err = EMAIL_ERROR_NOT_SUPPORTED;
+                       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->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;
+                       }
+                       break;
+               case EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_NONE :
+               default :
+                       EM_DEBUG_LOG("EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_NONE or default");
+                       err = EMAIL_ERROR_INVALID_PARAM;
+                       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);
+       }
+
+       EM_SAFE_FREE (task_param);
+
+       EM_DEBUG_FUNC_END("err [%d]", err);
+       
+       return (void *)return_err;
+}
+/*-------------------------------------------------------------------------------------------*/
index e58f53f..f2573f4 100755 (executable)
@@ -2464,8 +2464,8 @@ int emcore_strip_mail_body_from_file(char *multi_user_name, emstorage_mail_tbl_t
     char *prefix_path = NULL;
     char real_html_path[255] = {0};
     char real_plain_path[255] = {0};
-       unsigned int byte_read = 0;
-       unsigned int byte_written = 0;
+       gsize byte_read = 0;
+       gsize byte_written = 0;
        GError *glib_error = NULL;
        FILE *fp_plain = NULL;
        struct stat  st_buf;
@@ -2581,7 +2581,7 @@ int emcore_strip_mail_body_from_file(char *multi_user_name, emstorage_mail_tbl_t
                                }
                                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);
@@ -2624,8 +2624,8 @@ int emcore_get_preview_text_from_file(char *multi_user_name, const char *input_p
        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;
@@ -2633,8 +2633,8 @@ int emcore_get_preview_text_from_file(char *multi_user_name, const char *input_p
        FILE        *fp_plain = NULL;
        GError      *glib_error = NULL;
        struct stat  st_buf;
-    char *prefix_path = NULL;
-    char real_file_path[255] = {0};
+    char        *prefix_path = NULL;
+    char         real_file_path[255] = {0};
 
        if (!output_preview_buffer) {
                EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
@@ -2735,7 +2735,7 @@ int emcore_get_preview_text_from_file(char *multi_user_name, const char *input_p
                                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)) {
@@ -2743,7 +2743,7 @@ int emcore_get_preview_text_from_file(char *multi_user_name, const char *input_p
                                }
                                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;
@@ -5225,33 +5225,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;
-       }
-
-#ifdef __FEATURE_FEEDBACK_TYPE_LED_ENABLE__
-       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);
-       }
-#endif /* __FEATURE_FEEDBACK_TYPE_LED_ENABLE__ */
-
-       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);
index c2ce544..b2060c6 100755 (executable)
 #include "email-core-container.h"
 #include "email-core-key-manager.h"
 
-#define DB_STMT sqlite3_stmt *
-
 #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="
 
@@ -8325,9 +8322,20 @@ FINISH_OFF:
 }
 #endif
 
-INTERNAL_FUNC int emstorage_mail_search_start(char *multi_user_name, 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)
@@ -8409,7 +8417,7 @@ INTERNAL_FUNC int emstorage_mail_search_start(char *multi_user_name, emstorage_s
 
 FINISH_OFF:
        if (ret == true)  {
-               *search_handle = (int)hStmt;
+               *search_handle = hStmt;
                *searched = mail_count;
                EM_DEBUG_LOG("mail_count [%d]", mail_count);
        }
@@ -8432,7 +8440,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);
 
@@ -8445,7 +8453,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;
 
@@ -8581,7 +8589,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);
 
@@ -8594,8 +8602,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)  {
index 1708379..63c36bc 100755 (executable)
@@ -56,6 +56,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;
@@ -1023,7 +1025,15 @@ INTERNAL_FUNC int emstorage_update_save_status(char *multi_user_name, int accoun
  * @remarks N/A
  * @return This function returns 0 on success or error code on failure.
  */
-INTERNAL_FUNC int emstorage_mail_search_start(char *multi_user_name, 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
@@ -1034,7 +1044,11 @@ INTERNAL_FUNC int emstorage_mail_search_start(char *multi_user_name, emstorage_s
  *    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
@@ -1044,7 +1058,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
index 52b41d1..73c1b69 100755 (executable)
@@ -340,6 +340,7 @@ INTERNAL_FUNC int   emcore_sync_flag_with_server(char *multi_user_name, int mail
 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(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 char* emcore_convert_mutf7_to_utf8(char *mailbox_name); 
 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(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);
 
index 4f7279f..c792ef2 100755 (executable)
@@ -43,7 +43,7 @@ INTERNAL_FUNC int  emcore_remove_task_from_task_table(char *multi_user_name, int
 INTERNAL_FUNC int  emcore_get_active_task_by_thread_id(thread_t input_thread_id, email_active_task_t **output_active_task);\r
 \r
 INTERNAL_FUNC void* emcore_default_async_task_handler(void *intput_param);\r
-INTERNAL_FUNC void* emcore_default_sync_task_handler(void *intput_param);\r
+INTERNAL_FUNC int emcore_default_sync_task_handler(void *intput_param);\r
 \r
 INTERNAL_FUNC int  emcore_start_task_manager_loop();\r
 INTERNAL_FUNC int  emcore_stop_task_manager_loop();\r
index 3a6573f..b9c5cb8 100755 (executable)
@@ -111,8 +111,6 @@ INTERNAL_FUNC int emcore_add_notification_for_send(char *multi_user_name, int ac
 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(char *multi_user_name, int account_id, int with_noti_tray);
-INTERNAL_FUNC void emcore_set_flash_noti();
-
 
 INTERNAL_FUNC int emcore_show_user_message(char *multi_user_name, int id, email_action_t action, int error);
 
index a3861a0..e4a98fc 100755 (executable)
@@ -463,8 +463,6 @@ INTERNAL_FUNC int emdaemon_finalize_sync(char *multi_user_name, int account_id,
                        EM_DEBUG_LOG("The email app is topmost");
                } else {
 
-                       /* LED feature */
-//                     emcore_set_flash_noti();
 
                        if ((err = emcore_add_notification(multi_user_name, account_id, 0, unread_mail_count, vip_unread_mail_count, 1, EMAIL_ERROR_NONE, NOTIFICATION_DISPLAY_APP_ALL)) != EMAIL_ERROR_NONE)
                                EM_DEBUG_EXCEPTION("emcore_add_notification failed : [%d]", err);
index aa2d318..cc7ef17 100755 (executable)
@@ -587,7 +587,7 @@ void* thread_func_to_delete_mail(void *thread_argument)
        int  account_id = 0;
        int  from_server = 0;
        int  noti_param_2 = 0;
-       int handle = 0;
+       int  handle = 0;
        char *multi_user_name = NULL;
        email_event_t *event_data = (email_event_t*)thread_argument;
 
@@ -597,15 +597,17 @@ void* thread_func_to_delete_mail(void *thread_argument)
        from_server        = event_data->event_param_data_5;
        multi_user_name    = event_data->multi_user_name;
 
-       if (!emcore_delete_mail(multi_user_name, account_id, mail_id_list, mail_id_count, EMAIL_DELETE_LOCALLY, EMAIL_DELETED_BY_COMMAND, noti_param_2, &err)) {
-               EM_DEBUG_EXCEPTION(" emcore_delete_mail failed [%d]", err);
+       if (!emcore_delete_mail(multi_user_name, account_id, mail_id_list, 
+                                                       mail_id_count, EMAIL_DELETE_LOCALLY, 
+                                                       EMAIL_DELETED_BY_COMMAND, noti_param_2, &err)) {
+               EM_DEBUG_EXCEPTION("emcore_delete_mail failed [%d]", err);
                emcore_free_event(event_data); /* prevent 17922 */
                EM_SAFE_FREE(event_data);
                goto FINISH_OFF;
        }
 
        if (from_server == EMAIL_DELETE_LOCAL_AND_SERVER || from_server == EMAIL_DELETE_FROM_SERVER) {
-               if (!emcore_insert_event(event_data, (int*)handle, &err)) {
+               if (!emcore_insert_event(event_data, &handle, &err)) {
                        EM_DEBUG_EXCEPTION("emcore_insert_event failed [%d]", err);
 /*                     if (from_server != EMAIL_DELETE_LOCAL_AND_SERVER && from_server != EMAIL_DELETE_FROM_SERVER) {
                                EM_SAFE_FREE(event_data->event_param_data_3);
@@ -756,7 +758,8 @@ int emdaemon_delete_mail_all(char *multi_user_name, int input_mailbox_id, int in
                }
 
 #ifdef __FEATURE_LOCAL_ACTIVITY__
-               int i, total = 0 , search_handle = 0;
+               int i, total = 0;
+               DB_STMT search_handle = 0;
                int *mail_ids = NULL;
                emstorage_activity_tbl_t new_activity;
                int activityid = 0;
index 783d05a..035f495 100755 (executable)
@@ -3368,7 +3368,12 @@ void stb_handle_task(int task_type, HIPC_API a_hAPI)
 
        if(is_async_task) {
                /* add async task */
-               if((err = emcore_add_task_to_task_table(NULL, task_type, EMAIL_TASK_PRIORITY_MID, task_parameter, task_parameter_length, &task_id)) != EMAIL_ERROR_NONE) {
+               if((err = emcore_add_task_to_task_table(NULL, 
+                                                                                               task_type, 
+                                                                                               EMAIL_TASK_PRIORITY_MID, 
+                                                                                               task_parameter, 
+                                                                                               task_parameter_length, 
+                                                                                               &task_id)) != EMAIL_ERROR_NONE) {
                        EM_DEBUG_EXCEPTION("emcore_add_task_to_task_pool failed [%d]", err);
                        goto FINISH_OFF;
                }
@@ -3383,7 +3388,7 @@ void stb_handle_task(int task_type, HIPC_API a_hAPI)
                sync_task.task_parameter        = task_parameter;
                sync_task.task_parameter_length = task_parameter_length;
 
-               if((err = (int)emcore_default_sync_task_handler(&sync_task)) != EMAIL_ERROR_NONE) {
+               if((err = emcore_default_sync_task_handler(&sync_task)) != EMAIL_ERROR_NONE) {
                        EM_DEBUG_EXCEPTION("emcore_default_sync_task_handler failed [%d]", err);
                        goto FINISH_OFF;
                }
index 3fb55aa..0a574b9 100755 (executable)
@@ -73,6 +73,7 @@ EXPORT_API void emipc_destroy_email_api(HIPC_API input_api_handle);
 
 EXPORT_API long emipc_get_api_id(HIPC_API input_api_handle);
 EXPORT_API long emipc_get_app_id(HIPC_API input_api_handle);
+EXPORT_API long emipc_get_response_id(HIPC_API input_api_handle);
 
 EXPORT_API bool emipc_add_parameter(HIPC_API api, EPARAMETER_DIRECTION direction, void *data, int data_length);
 EXPORT_API bool emipc_add_dynamic_parameter(HIPC_API api, EPARAMETER_DIRECTION direction, void *data, int data_length);
index af15c2a..32219c3 100755 (executable)
@@ -45,8 +45,8 @@
 #include "email-core-utils.h"
 #include "email-core-mime.h"
 
-#define MAIL_TEMP_BODY "/tmp/utf-8"
-#define HTML_TEMP_BODY "/tmp/utf-8.htm"
+#define MAIL_TEMP_BODY "/tmp/utf8"
+#define HTML_TEMP_BODY "/tmp/utf8.htm"
 
 /*
 static void testapp_test_print_sorting_menu()