summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKibum Kim <kb0929.kim@samsung.com>2012-02-27 21:15:52 +0900
committerKibum Kim <kb0929.kim@samsung.com>2012-02-27 21:15:52 +0900
commit4c73c3e1e4085d17f8f9cfe0ec4c41bc9e0cb826 (patch)
treef86bd5ef488a8497efc5022d4f614cd0bba133d4
downloademail-service-4c73c3e1e4085d17f8f9cfe0ec4c41bc9e0cb826.tar.gz
email-service-4c73c3e1e4085d17f8f9cfe0ec4c41bc9e0cb826.tar.bz2
email-service-4c73c3e1e4085d17f8f9cfe0ec4c41bc9e0cb826.zip
tizen beta release
-rwxr-xr-xAUTHORS2
-rwxr-xr-xCMakeLists.txt68
-rwxr-xr-xCommon/CMakeLists.txt50
-rwxr-xr-xCommon/Msg_Convert.c1637
-rwxr-xr-xCommon/include/Msg_Convert.h93
-rw-r--r--LICENSE206
-rwxr-xr-xMAPI/CMakeLists.txt78
-rwxr-xr-xMAPI/Emf_Mapi_Account.c665
-rwxr-xr-xMAPI/Emf_Mapi_Init.c132
-rwxr-xr-xMAPI/Emf_Mapi_Mailbox.c546
-rwxr-xr-xMAPI/Emf_Mapi_Message.c3316
-rwxr-xr-xMAPI/Emf_Mapi_Network.c1486
-rwxr-xr-xMAPI/Emf_Mapi_Rule.c234
-rwxr-xr-xMAPI/Emf_Mapi_Types.c2088
-rwxr-xr-xMAPI/include/Emf_Mapi.h155
-rwxr-xr-xMAPI/include/Emf_Mapi_Account.h389
-rwxr-xr-xMAPI/include/Emf_Mapi_Init.h174
-rwxr-xr-xMAPI/include/Emf_Mapi_Mailbox.h326
-rwxr-xr-xMAPI/include/Emf_Mapi_Message.h2341
-rwxr-xr-xMAPI/include/Emf_Mapi_Network.h454
-rwxr-xr-xMAPI/include/Emf_Mapi_Rule.h218
-rwxr-xr-xMAPI/include/Emf_Mapi_Types.h873
-rwxr-xr-xSLP_EmailService_PG.h1312
-rwxr-xr-xcl.sh1
-rw-r--r--config/.email-service.dbbin0 -> 20480 bytes
-rw-r--r--config/.email-service.db-journalbin0 -> 4640 bytes
-rwxr-xr-xdbuild.sh2
-rwxr-xr-xdebian/changelog7
-rwxr-xr-xdebian/compat1
-rwxr-xr-xdebian/control32
-rwxr-xr-xdebian/copyright15
-rwxr-xr-xdebian/dirs2
-rwxr-xr-xdebian/docs0
-rwxr-xr-xdebian/email-service-0.install4
-rwxr-xr-xdebian/email-service-0.postinst487
-rwxr-xr-xdebian/email-service-dev.install2
-rw-r--r--debian/email-service-tools.install4
-rw-r--r--debian/email-service-tools.postinst65
-rwxr-xr-xdebian/rules146
-rwxr-xr-xemail-core/CMakeLists.txt171
-rwxr-xr-xemail-core/em-core-account.c1107
-rwxr-xr-xemail-core/em-core-api.c239
-rwxr-xr-xemail-core/em-core-event.c3701
-rwxr-xr-xemail-core/em-core-global.c53
-rwxr-xr-xemail-core/em-core-imap-idle.c648
-rwxr-xr-xemail-core/em-core-imap-mailbox.c1193
-rwxr-xr-xemail-core/em-core-mailbox-sync.c4007
-rwxr-xr-xemail-core/em-core-mailbox.c1168
-rwxr-xr-xemail-core/em-core-mesg.c7057
-rwxr-xr-xemail-core/em-core-mime.c4719
-rwxr-xr-xemail-core/em-core-mm-callbacks.c412
-rwxr-xr-xemail-core/em-core-smtp.c3646
-rwxr-xr-xemail-core/em-core-sound.c759
-rwxr-xr-xemail-core/em-core-timer.c110
-rwxr-xr-xemail-core/em-core-utils.c3183
-rwxr-xr-xemail-core/em-network/em-network.c487
-rwxr-xr-xemail-core/em-network/include/em-network.h48
-rwxr-xr-xemail-core/em-storage/em-storage-noti.c79
-rwxr-xr-xemail-core/em-storage/em-storage.c14242
-rwxr-xr-xemail-core/em-storage/include/em-storage.h1539
-rwxr-xr-xemail-core/include/em-core-account.h83
-rwxr-xr-xemail-core/include/em-core-api.h59
-rwxr-xr-xemail-core/include/em-core-event.h96
-rwxr-xr-xemail-core/include/em-core-global.h56
-rwxr-xr-xemail-core/include/em-core-imap-idle.h132
-rwxr-xr-xemail-core/include/em-core-imap-mailbox.h79
-rwxr-xr-xemail-core/include/em-core-mailbox-sync.h179
-rwxr-xr-xemail-core/include/em-core-mailbox.h91
-rwxr-xr-xemail-core/include/em-core-mesg.h232
-rwxr-xr-xemail-core/include/em-core-mime.h58
-rwxr-xr-xemail-core/include/em-core-smtp.h66
-rwxr-xr-xemail-core/include/em-core-sound-conflict.h20
-rwxr-xr-xemail-core/include/em-core-sound.h71
-rwxr-xr-xemail-core/include/em-core-timer.h52
-rwxr-xr-xemail-core/include/em-core-types.h320
-rwxr-xr-xemail-core/include/em-core-utils.h217
-rwxr-xr-xemail-engine/CMakeLists.txt58
-rwxr-xr-xemail-engine/emf-account.c698
-rwxr-xr-xemail-engine/emf-auto-poll.c480
-rwxr-xr-xemail-engine/emf-emn-noti.c47
-rwxr-xr-xemail-engine/emf-emn.c612
-rwxr-xr-xemail-engine/emf-etc.c219
-rwxr-xr-xemail-engine/emf-global.c38
-rwxr-xr-xemail-engine/emf-init.c333
-rwxr-xr-xemail-engine/emf-mail.c2124
-rwxr-xr-xemail-engine/emf-mailbox.c585
-rwxr-xr-xemail-engine/main.c3593
-rwxr-xr-xemail-service.pc.in9
-rwxr-xr-xemf-emn-storage/emf-emn-storage.c177
-rwxr-xr-ximage/email_image001.pngbin0 -> 80326 bytes
-rwxr-xr-ximage/email_image002.pngbin0 -> 101921 bytes
-rwxr-xr-ximage/email_image003.pngbin0 -> 77298 bytes
-rwxr-xr-ximage/email_image004.pngbin0 -> 11254 bytes
-rwxr-xr-ximage/email_image005.pngbin0 -> 9633 bytes
-rwxr-xr-ximage/email_image006.pngbin0 -> 16121 bytes
-rwxr-xr-ximage/email_image007.pngbin0 -> 17091 bytes
-rwxr-xr-ximage/email_image008.pngbin0 -> 21336 bytes
-rwxr-xr-ximage/email_image009.pngbin0 -> 9238 bytes
-rwxr-xr-ximage/email_image010.pngbin0 -> 12014 bytes
-rwxr-xr-ximage/email_image011.pngbin0 -> 5528 bytes
-rwxr-xr-ximage/email_image012.pngbin0 -> 44859 bytes
-rw-r--r--include/.gitignore2
-rwxr-xr-xinclude/emf-account.h52
-rwxr-xr-xinclude/emf-auto-poll.h62
-rwxr-xr-xinclude/emf-dbglog.h228
-rwxr-xr-xinclude/emf-emn-noti.h69
-rwxr-xr-xinclude/emf-emn-storage.h83
-rwxr-xr-xinclude/emf-emn.h88
-rwxr-xr-xinclude/emf-global.h54
-rwxr-xr-xinclude/emf-init.h46
-rwxr-xr-xinclude/emf-mutex.h79
-rwxr-xr-xinclude/emf-types.h1445
-rwxr-xr-xinclude/emflib.h837
-rwxr-xr-xipc/CMakeLists.txt78
-rwxr-xr-xipc/api/include/ipc-api-info.h259
-rwxr-xr-xipc/api/include/ipc-param-list.h67
-rwxr-xr-xipc/api/include/ipc-param.h43
-rwxr-xr-xipc/api/ipc-api-info.cpp150
-rwxr-xr-xipc/api/ipc-param-list.cpp201
-rwxr-xr-xipc/api/ipc-param.cpp67
-rwxr-xr-xipc/common/cm-list.cpp113
-rwxr-xr-xipc/common/cm-sys-msg-queue.cpp127
-rwxr-xr-xipc/common/include/cm-list.h49
-rwxr-xr-xipc/common/include/cm-sys-msg-queue.h62
-rwxr-xr-xipc/include/ipc-library-build.h33
-rwxr-xr-xipc/include/ipc-library.h87
-rwxr-xr-xipc/ipc-library-api.cpp139
-rwxr-xr-xipc/ipc-library-build.cpp28
-rwxr-xr-xipc/ipc-library-proxy.cpp80
-rwxr-xr-xipc/ipc-library-stub.cpp52
-rwxr-xr-xipc/proxy/include/ipc-callback-info.h48
-rwxr-xr-xipc/proxy/include/ipc-proxy-main.h66
-rwxr-xr-xipc/proxy/include/ipc-proxy-socket.h48
-rwxr-xr-xipc/proxy/ipc-callback-info.cpp52
-rwxr-xr-xipc/proxy/ipc-proxy-main.cpp199
-rwxr-xr-xipc/proxy/ipc-proxy-socket.cpp161
-rwxr-xr-xipc/socket/include/ipc-socket.h89
-rwxr-xr-xipc/socket/ipc-socket.cpp353
-rwxr-xr-xipc/stub/include/ipc-queue.h64
-rwxr-xr-xipc/stub/include/ipc-response-info.h46
-rwxr-xr-xipc/stub/include/ipc-stub-main.h61
-rwxr-xr-xipc/stub/include/ipc-stub-socket.h60
-rwxr-xr-xipc/stub/include/ipc-task-manager.h60
-rwxr-xr-xipc/stub/include/ipc-task.h49
-rwxr-xr-xipc/stub/ipc-queue.cpp114
-rwxr-xr-xipc/stub/ipc-response-info.cpp52
-rwxr-xr-xipc/stub/ipc-stub-main.cpp191
-rwxr-xr-xipc/stub/ipc-stub-socket.cpp208
-rwxr-xr-xipc/stub/ipc-task-manager.cpp171
-rwxr-xr-xipc/stub/ipc-task.cpp88
-rw-r--r--packaging/email-service.spec574
-rwxr-xr-xpo/CMakeLists.txt28
-rwxr-xr-xpo/POTFILES.in46
-rwxr-xr-xpo/de_DE.po465
-rwxr-xr-xpo/el_GR.po465
-rwxr-xr-xpo/email.pot1546
-rwxr-xr-xpo/en.po465
-rwxr-xr-xpo/es_ES.po465
-rwxr-xr-xpo/fr_FR.po465
-rwxr-xr-xpo/it_IT.po465
-rwxr-xr-xpo/ja_JP.po465
-rwxr-xr-xpo/ko_KR.po465
-rwxr-xr-xpo/nl_NL.po465
-rwxr-xr-xpo/pt_PT.po465
-rwxr-xr-xpo/ru_RU.po465
-rwxr-xr-xpo/tr_TR.po465
-rwxr-xr-xpo/update-po.sh58
-rwxr-xr-xpo/zh_CN.po465
-rwxr-xr-xpo/zh_HK.po465
-rwxr-xr-xpo/zh_TW.po465
-rwxr-xr-xutilities/CMakeLists.txt56
-rwxr-xr-xutilities/email-service-test-application/email-service-test-application/emf-test-account.c624
-rwxr-xr-xutilities/email-service-test-application/email-service-test-application/emf-test-mailbox.c359
-rwxr-xr-xutilities/email-service-test-application/email-service-test-application/emf-test-main.c199
-rwxr-xr-xutilities/email-service-test-application/email-service-test-application/emf-test-message.c2653
-rwxr-xr-xutilities/email-service-test-application/email-service-test-application/emf-test-others.c448
-rwxr-xr-xutilities/email-service-test-application/email-service-test-application/emf-test-rule.c245
-rwxr-xr-xutilities/email-service-test-application/email-service-test-application/emf-test-thread.c134
-rwxr-xr-xutilities/email-service-test-application/email-service-test-application/emf-test-utility.c228
-rwxr-xr-xutilities/email-service-test-application/email-service-test-application/include/emf-test-account.h29
-rwxr-xr-xutilities/email-service-test-application/email-service-test-application/include/emf-test-mailbox.h28
-rwxr-xr-xutilities/email-service-test-application/email-service-test-application/include/emf-test-message.h35
-rwxr-xr-xutilities/email-service-test-application/email-service-test-application/include/emf-test-others.h31
-rwxr-xr-xutilities/email-service-test-application/email-service-test-application/include/emf-test-rule.h31
-rwxr-xr-xutilities/email-service-test-application/email-service-test-application/include/emf-test-thread.h34
-rwxr-xr-xutilities/email-service-test-application/email-service-test-application/include/emf-test-utility.h47
186 files changed, 98231 insertions, 0 deletions
diff --git a/AUTHORS b/AUTHORS
new file mode 100755
index 0000000..2df2807
--- /dev/null
+++ b/AUTHORS
@@ -0,0 +1,2 @@
+Kyuho Jo <kyuho.jo@samsung.com>
+Sunghyun Kwon <sh0701.kwon@samsung.com>
diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100755
index 0000000..123b582
--- /dev/null
+++ b/CMakeLists.txt
@@ -0,0 +1,68 @@
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+PROJECT(email-service)
+
+SET(CMAKE_SKIP_BUILD_RPATH TRUE)
+SET(VERSION_MAJOR 1)
+SET(VERSION "${VERSION_MAJOR}.1.0")
+
+IF("${CMAKE_BUILD_TYPE}" STREQUAL "")
+ SET(CMAKE_BUILD_TYPE "Debug")
+ENDIF("${CMAKE_BUILD_TYPE}" STREQUAL "")
+
+MESSAGE("")
+MESSAGE(">>> current directory: ${CMAKE_CURRENT_SOURCE_DIR}")
+MESSAGE(">>> Build type: ${CMAKE_BUILD_TYPE}")
+
+
+##########################################################
+# Define BASE LIB
+##########################################################
+ADD_SUBDIRECTORY(Common)
+
+#########################################################
+# Define IPC
+##########################################################
+ADD_SUBDIRECTORY(ipc)
+
+##########################################################
+# Define STORAGE, NETWORK, CORE lib
+##########################################################
+
+ADD_SUBDIRECTORY(email-core)
+
+##########################################################
+# Define Email API
+##########################################################
+
+ADD_SUBDIRECTORY(MAPI)
+
+##########################################################
+# Define Execute File
+##########################################################
+
+ADD_SUBDIRECTORY(email-engine)
+
+##########################################################
+# Define Test App
+##########################################################
+
+ADD_SUBDIRECTORY(utilities)
+
+##########################################################
+# Define locale
+##########################################################
+
+ADD_SUBDIRECTORY(po)
+
+##########################################################
+# Define Install Files
+##########################################################
+
+CONFIGURE_FILE(email-service.pc.in email-service.pc @ONLY)
+INSTALL(FILES ${CMAKE_BINARY_DIR}/email-service.pc DESTINATION lib/pkgconfig)
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/config/.email-service.db DESTINATION /opt/dbspace)
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/config/.email-service.db-journal DESTINATION /opt/dbspace)
+
+#SET(RC_LOCAL_SCRIPT email-service)
+#INSTALL(PROGRAMS ${RC_LOCAL_SCRIPT} DESTINATION /etc/rc.d/init.d)
+
diff --git a/Common/CMakeLists.txt b/Common/CMakeLists.txt
new file mode 100755
index 0000000..72ed455
--- /dev/null
+++ b/Common/CMakeLists.txt
@@ -0,0 +1,50 @@
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+PROJECT(email-base)
+
+SET(CMAKE_SKIP_BUILD_RPATH TRUE)
+
+IF("${CMAKE_BUILD_TYPE}" STREQUAL "")
+ SET(CMAKE_BUILD_TYPE "Debug")
+ENDIF("${CMAKE_BUILD_TYPE}" STREQUAL "")
+
+MESSAGE("")
+MESSAGE(">>> current directory: ${CMAKE_CURRENT_SOURCE_DIR}")
+MESSAGE(">>> Build type: ${CMAKE_BUILD_TYPE}")
+
+SET(VISIBILITY "-DEXPORT_API=\"__attribute__((visibility(\\\"default\\\")))\"")
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${VISIBILITY} -fvisibility=hidden")
+
+SET(BASE-LIB "email-base")
+SET(BASE-SRCS
+ ${CMAKE_SOURCE_DIR}/Common/Msg_Convert.c
+)
+
+INCLUDE_DIRECTORIES(
+ ${CMAKE_SOURCE_DIR}/include
+ ${CMAKE_SOURCE_DIR}/Common/include/
+ ${CMAKE_SOURCE_DIR}/email-core/include/
+ ${CMAKE_SOURCE_DIR}/email-core/em-storage/include/
+)
+
+INCLUDE(FindPkgConfig)
+pkg_check_modules(base_pkgs REQUIRED glib-2.0 dlog contacts-service)
+
+FOREACH(flag ${base_pkgs_CFLAGS})
+ SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
+#message(">>>[${BASE-LIB}] extra_cflags ${EXTRA_CFLAGS}")
+#message(">>>[${BASE-LIB}] base_pkgs_cflags ${base_pkgs_CFLAGS}")
+#message(">>>[${BASE-LIB}] result ${CMAKE_C_FLAGS}")
+
+SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed")
+
+ADD_LIBRARY(${BASE-LIB} SHARED ${BASE-SRCS})
+TARGET_LINK_LIBRARIES(${BASE-LIB} ${base_pkgs_LDFLAGS})
+SET_TARGET_PROPERTIES(${BASE-LIB} PROPERTIES SOVERSION ${VERSION_MAJOR})
+SET_TARGET_PROPERTIES(${BASE-LIB} PROPERTIES VERSION ${VERSION})
+
+#INSTALL(TARGETS ${BASE-LIB} LIBRARY DESTINATION lib)
+INSTALL(TARGETS ${BASE-LIB} DESTINATION lib COMPONENT RuntimeLibraries)
+
diff --git a/Common/Msg_Convert.c b/Common/Msg_Convert.c
new file mode 100755
index 0000000..9112417
--- /dev/null
+++ b/Common/Msg_Convert.c
@@ -0,0 +1,1637 @@
+/*
+* email-service
+*
+* Copyright (c) 2000 - 2011 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.
+*
+*/
+
+#include<stdlib.h>
+#include<stdio.h>
+#include "string.h"
+#include "emflib.h"
+#include "Msg_Convert.h"
+#include "em-core-mesg.h"
+#include "emf-dbglog.h"
+#include "em-storage.h"
+
+
+#define fSEEN 0x1
+#define fDELETED 0x2
+#define fFLAGGED 0x4
+#define fANSWERED 0x8
+#define fOLD 0x10
+#define fDRAFT 0x20
+#define fATTACHMENT 0x40
+#define fFORWARD 0x80
+
+EXPORT_API int em_convert_mail_flag_to_int(emf_mail_flag_t flag, int *i_flag, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("i_flag[%p], err_code[%p]", i_flag, err_code);
+
+ if (!i_flag) {
+ if (err_code != NULL)
+ *err_code = EMF_ERROR_INVALID_PARAM;
+ return false;
+
+ }
+
+ *i_flag =
+ (flag.seen ? fSEEN : 0) |
+ (flag.deleted ? fDELETED : 0) |
+ (flag.flagged ? fFLAGGED : 0) |
+ (flag.answered ? fANSWERED : 0) |
+ (flag.recent ? fOLD : 0) |
+ (flag.draft ? fDRAFT : 0) |
+ (flag.has_attachment ? fATTACHMENT : 0) |
+ (flag.forwarded ? fFORWARD : 0) ;
+
+ EM_DEBUG_FUNC_END();
+ return true;
+}
+
+EXPORT_API int em_convert_mail_int_to_flag(int i_flag, emf_mail_flag_t* flag, int* err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("i_flag[0x%02x], flag[%p], err_code[%p]", i_flag, flag, err_code);
+
+ if (!flag) {
+ EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
+ if (err_code != NULL)
+ *err_code = EMF_ERROR_INVALID_PARAM;
+ return false;
+ }
+
+ flag->seen = (i_flag & fSEEN ? 1 : 0);
+ flag->deleted = (i_flag & fDELETED ? 1 : 0);
+ flag->flagged = (i_flag & fFLAGGED ? 1 : 0);
+ flag->answered = (i_flag & fANSWERED ? 1 : 0);
+ flag->recent = (i_flag & fOLD ? 1 : 0);
+ flag->draft = (i_flag & fDRAFT ? 1 : 0);
+ flag->has_attachment = (i_flag & fATTACHMENT ? 1 : 0);
+ flag->forwarded = (i_flag & fFORWARD ? 1 : 0);
+
+ EM_DEBUG_FUNC_END("FLAGS : seen[%d], deleted[%d], flagged[%d], answered[%d], recent[%d], draft[%d], has_attachment[%d], forwarded[%d]",
+ flag->seen, flag->deleted, flag->flagged, flag->answered, flag->recent, flag->draft, flag->has_attachment, flag->forwarded);
+
+ return true;
+}
+
+EXPORT_API int em_convert_mail_tbl_to_mail_status(emf_mail_tbl_t *mail_tbl_data, int *result_mail_status, int* err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("mail_tbl_data[%p], result_mail_status [%p], err_code[%p]", mail_tbl_data, result_mail_status, err_code);
+ int ret = false, error_code = EMF_ERROR_NONE;
+ int has_attachment = 0;
+
+ if(!mail_tbl_data || !result_mail_status) {
+ EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
+ error_code = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ has_attachment = (mail_tbl_data->attachment_count > mail_tbl_data->inline_content_count) ? 1 : 0;
+
+ *result_mail_status = (mail_tbl_data->flags_seen_field ? fSEEN : 0) |
+ (mail_tbl_data->flags_deleted_field ? fDELETED : 0) |
+ (mail_tbl_data->flags_flagged_field ? fFLAGGED : 0) |
+ (mail_tbl_data->flags_answered_field ? fANSWERED : 0) |
+ (mail_tbl_data->flags_recent_field ? fOLD : 0) |
+ (mail_tbl_data->flags_draft_field ? fDRAFT : 0) |
+ (has_attachment ? fATTACHMENT : 0) |
+ (mail_tbl_data->flags_forwarded_field ? fFORWARD : 0);
+
+ ret = true;
+FINISH_OFF:
+ if (err_code != NULL)
+ *err_code = error_code;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+ }
+
+EXPORT_API int em_convert_mail_status_to_mail_tbl(int mail_status, emf_mail_tbl_t *result_mail_tbl_data, int* err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("mail_status[%d], result_mail_tbl_data [%p], err_code[%p]", mail_status, result_mail_tbl_data, err_code);
+ int ret = false, error_code = EMF_ERROR_NONE;
+
+ if(!result_mail_tbl_data) {
+ EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
+ error_code = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ result_mail_tbl_data->flags_seen_field = (mail_status & fSEEN ? 1 : 0);
+ result_mail_tbl_data->flags_deleted_field = (mail_status & fDELETED ? 1 : 0);
+ result_mail_tbl_data->flags_flagged_field = (mail_status & fFLAGGED ? 1 : 0);
+ result_mail_tbl_data->flags_answered_field = (mail_status & fANSWERED ? 1 : 0);
+ result_mail_tbl_data->flags_recent_field = (mail_status & fOLD ? 1 : 0);
+ result_mail_tbl_data->flags_draft_field = (mail_status & fDRAFT ? 1 : 0);
+ result_mail_tbl_data->flags_forwarded_field = (mail_status & fFORWARD ? 1 : 0);
+
+ ret = true;
+FINISH_OFF:
+ if (err_code != NULL)
+ *err_code = error_code;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+EXPORT_API int em_convert_mail_tbl_to_mail_flag(emf_mail_tbl_t *mail_tbl_data, emf_mail_flag_t *result_flag, int* err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("mail_tbl_data[%p], result_flag [%p], err_code[%p]", mail_tbl_data, result_flag, err_code);
+ int ret = false, error_code = EMF_ERROR_NONE;
+
+ if(!mail_tbl_data || !result_flag) {
+ EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
+ error_code = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ result_flag->seen = mail_tbl_data->flags_seen_field;
+ result_flag->deleted = mail_tbl_data->flags_deleted_field;
+ result_flag->flagged = mail_tbl_data->flags_flagged_field;
+ result_flag->answered = mail_tbl_data->flags_answered_field;
+ result_flag->recent = mail_tbl_data->flags_recent_field;
+ result_flag->draft = mail_tbl_data->flags_draft_field;
+ result_flag->has_attachment = (mail_tbl_data->attachment_count > mail_tbl_data->inline_content_count) ? 1 : 0;
+ result_flag->forwarded = mail_tbl_data->flags_forwarded_field;
+
+ ret = true;
+FINISH_OFF:
+ if (err_code != NULL)
+ *err_code = error_code;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+EXPORT_API int em_convert_mail_flag_to_mail_tbl(emf_mail_flag_t *flag, emf_mail_tbl_t *result_mail_tbl_data, int* err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("flag[%p], result_mail_tbl_data [%p], err_code[%p]", flag, result_mail_tbl_data, err_code);
+ int ret = false, error_code = EMF_ERROR_NONE;
+
+ if(!flag || !result_mail_tbl_data) {
+ EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
+ error_code = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ result_mail_tbl_data->flags_seen_field = flag->seen;
+ result_mail_tbl_data->flags_deleted_field = flag->deleted;
+ result_mail_tbl_data->flags_flagged_field = flag->flagged;
+ result_mail_tbl_data->flags_answered_field = flag->answered;
+ result_mail_tbl_data->flags_recent_field = flag->recent;
+ result_mail_tbl_data->flags_draft_field = flag->draft;
+ result_mail_tbl_data->flags_forwarded_field = flag->forwarded;
+
+ ret = true;
+FINISH_OFF:
+ if (err_code != NULL)
+ *err_code = error_code;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+
+EXPORT_API int em_convert_account_to_account_tbl(emf_account_t *account, emf_mail_account_tbl_t *account_tbl)
+{
+ EM_DEBUG_FUNC_BEGIN("account[%p], account_tbl[%p]", account, account_tbl);
+ int ret = 1;
+
+ account_tbl->account_bind_type = account->account_bind_type;
+ account_tbl->account_name = EM_SAFE_STRDUP(account->account_name);
+ account_tbl->receiving_server_type = account->receiving_server_type;
+ account_tbl->receiving_server_addr = EM_SAFE_STRDUP(account->receiving_server_addr);
+ account_tbl->email_addr = EM_SAFE_STRDUP(account->email_addr);
+ account_tbl->user_name = EM_SAFE_STRDUP(account->user_name);
+ account_tbl->password = EM_SAFE_STRDUP(account->password);
+ account_tbl->retrieval_mode = account->retrieval_mode;
+ account_tbl->port_num = account->port_num;
+ account_tbl->use_security = account->use_security;
+ account_tbl->sending_server_type = account->sending_server_type;
+ account_tbl->sending_server_addr = EM_SAFE_STRDUP(account->sending_server_addr);
+ account_tbl->sending_port_num = account->sending_port_num;
+ account_tbl->sending_auth = account->sending_auth;
+ account_tbl->sending_security = account->sending_security;
+ account_tbl->sending_user = EM_SAFE_STRDUP(account->sending_user);
+ account_tbl->sending_password = EM_SAFE_STRDUP(account->sending_password);
+ account_tbl->display_name = EM_SAFE_STRDUP(account->display_name);
+ account_tbl->reply_to_addr = EM_SAFE_STRDUP(account->reply_to_addr);
+ account_tbl->return_addr = EM_SAFE_STRDUP(account->return_addr);
+ account_tbl->account_id = account->account_id;
+ account_tbl->keep_on_server = account->keep_on_server;
+ account_tbl->flag1 = account->flag1;
+ account_tbl->flag2 = account->flag2;
+ account_tbl->pop_before_smtp = account->pop_before_smtp;
+ account_tbl->apop = account_tbl->apop;
+ account_tbl->logo_icon_path = EM_SAFE_STRDUP(account->logo_icon_path);
+ account_tbl->preset_account = account->preset_account;
+ account_tbl->options.priority = account->options.priority;
+ account_tbl->options.keep_local_copy = account->options.keep_local_copy;
+ account_tbl->options.req_delivery_receipt = account->options.req_delivery_receipt;
+ account_tbl->options.req_read_receipt = account->options.req_read_receipt;
+ account_tbl->options.download_limit = account->options.download_limit;
+ account_tbl->options.block_address = account->options.block_address;
+ account_tbl->options.block_subject = account->options.block_subject;
+ account_tbl->options.display_name_from = EM_SAFE_STRDUP(account->options.display_name_from);
+ account_tbl->options.reply_with_body = account->options.reply_with_body;
+ account_tbl->options.forward_with_files = account->options.forward_with_files;
+ account_tbl->options.add_myname_card = account->options.add_myname_card;
+ account_tbl->options.add_signature = account->options.add_signature;
+ account_tbl->options.signature = EM_SAFE_STRDUP(account->options.signature);
+ account_tbl->options.add_my_address_to_bcc = account->options.add_my_address_to_bcc;
+ account_tbl->target_storage = account->target_storage;
+ account_tbl->check_interval = account->check_interval;
+ account_tbl->my_account_id = account->my_account_id;
+ account_tbl->index_color = account->index_color;
+
+ EM_DEBUG_FUNC_END();
+ return ret;
+}
+
+EXPORT_API int em_convert_account_tbl_to_account(emf_mail_account_tbl_t *account_tbl, emf_account_t *account)
+{
+ EM_DEBUG_FUNC_BEGIN("account_tbl[%p], account[%p]", account_tbl, account);
+ int ret = 1;
+
+ account->account_bind_type = account_tbl->account_bind_type;
+ account->account_name = EM_SAFE_STRDUP(account_tbl->account_name);
+ account->receiving_server_type = account_tbl->receiving_server_type;
+ account->receiving_server_addr = EM_SAFE_STRDUP(account_tbl->receiving_server_addr);
+ account->email_addr = EM_SAFE_STRDUP(account_tbl->email_addr);
+ account->user_name = EM_SAFE_STRDUP(account_tbl->user_name);
+ account->password = EM_SAFE_STRDUP(account_tbl->password);
+ account->retrieval_mode = account_tbl->retrieval_mode;
+ account->port_num = account_tbl->port_num;
+ account->use_security = account_tbl->use_security;
+ account->sending_server_type = account_tbl->sending_server_type;
+ account->sending_server_addr = EM_SAFE_STRDUP(account_tbl->sending_server_addr);
+ account->sending_port_num = account_tbl->sending_port_num;
+ account->sending_auth = account_tbl->sending_auth;
+ account->sending_security = account_tbl->sending_security;
+ account->sending_user = EM_SAFE_STRDUP(account_tbl->sending_user);
+ account->sending_password = EM_SAFE_STRDUP(account_tbl->sending_password);
+ account->display_name = EM_SAFE_STRDUP(account_tbl->display_name);
+ account->reply_to_addr = EM_SAFE_STRDUP(account_tbl->reply_to_addr);
+ account->return_addr = EM_SAFE_STRDUP(account_tbl->return_addr);
+ account->account_id = account_tbl->account_id;
+ account->keep_on_server = account_tbl->keep_on_server;
+ account->flag1 = account_tbl->flag1;
+ account->flag2 = account_tbl->flag2;
+ account->pop_before_smtp = account_tbl->pop_before_smtp;
+ account->apop = account_tbl->apop;
+ account->logo_icon_path = EM_SAFE_STRDUP(account_tbl->logo_icon_path);
+ account->preset_account = account_tbl->preset_account;
+ account->options.priority = account_tbl->options.priority;
+ account->options.keep_local_copy = account_tbl->options.keep_local_copy;
+ account->options.req_delivery_receipt = account_tbl->options.req_delivery_receipt;
+ account->options.req_read_receipt = account_tbl->options.req_read_receipt;
+ account->options.download_limit = account_tbl->options.download_limit;
+ account->options.block_address = account_tbl->options.block_address;
+ account->options.block_subject = account_tbl->options.block_subject;
+ account->options.display_name_from = EM_SAFE_STRDUP(account_tbl->options.display_name_from);
+ account->options.reply_with_body = account_tbl->options.reply_with_body;
+ account->options.forward_with_files = account_tbl->options.forward_with_files;
+ account->options.add_myname_card = account_tbl->options.add_myname_card;
+ account->options.add_signature = account_tbl->options.add_signature;
+ account->options.signature = EM_SAFE_STRDUP(account_tbl->options.signature);
+ account->options.add_my_address_to_bcc = account_tbl->options.add_my_address_to_bcc;
+ account->target_storage = account_tbl->target_storage;
+ account->check_interval = account_tbl->check_interval;
+ account->my_account_id = account_tbl->my_account_id;
+ account->index_color = account_tbl->index_color;
+
+ EM_DEBUG_FUNC_END();
+ return ret;
+}
+
+
+EXPORT_API int em_convert_mail_tbl_to_mail(emf_mail_tbl_t *mail_table_data, emf_mail_t *mail_data)
+{
+ EM_DEBUG_FUNC_BEGIN("mail_table_data[%p], mail_data[%p]", mail_table_data, mail_data);
+ int ret = 1, err_code = EMF_ERROR_NONE;
+
+ if (!mail_table_data || !mail_data) {
+ EM_DEBUG_EXCEPTION("Invalid parameter");
+ return 0;
+ }
+
+ if (mail_data->info)
+ em_core_mail_info_free(&(mail_data->info), 1, NULL);
+
+ if (mail_data->head)
+ em_core_mail_head_free(&(mail_data->head), 1, NULL);
+
+ if (mail_data->body)
+ em_core_mail_body_free(&(mail_data->body), 1, NULL);
+
+ if (!em_core_mail_get_info_from_mail_tbl(&(mail_data->info), mail_table_data, &err_code)) {
+ EM_DEBUG_EXCEPTION("em_core_mail_get_info_from_mail_tbl failed [%d]", err_code);
+ return 0;
+ }
+
+ if (!em_core_mail_get_header_from_mail_tbl(&(mail_data->head), mail_table_data, &err_code)) {
+ EM_DEBUG_EXCEPTION("em_core_mail_get_header_from_mail_tbl failed [%d]", err_code);
+ return 0;
+ }
+
+ if (!em_core_mail_get_body_from_mail_tbl(&(mail_data->body), mail_table_data, &err_code)) {
+ EM_DEBUG_EXCEPTION("em_core_mail_get_header_from_mail_tbl failed [%d]", err_code);
+ return 0;
+ }
+
+ EM_DEBUG_FUNC_END();
+ return ret;
+}
+
+EXPORT_API int em_convert_mail_tbl_to_mail_data(emf_mail_tbl_t *mail_table_data, int item_count, emf_mail_data_t **mail_data, int *error)
+{
+ EM_DEBUG_FUNC_BEGIN("mail_table_data[%p], item_count [%d], mail_data[%p]", mail_table_data, item_count, mail_data);
+ int i, ret = false, err_code = EMF_ERROR_NONE;
+ emf_mail_data_t *temp_mail_data = NULL;
+
+ if (!mail_table_data || !mail_data || !item_count) {
+ EM_DEBUG_EXCEPTION("Invalid parameter");
+ err_code = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ temp_mail_data = em_core_malloc(sizeof(emf_mail_data_t) * item_count);
+
+ if(!temp_mail_data) {
+ EM_DEBUG_EXCEPTION("em_core_malloc failed");
+ err_code = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ for(i = 0; i < item_count; i++) {
+ temp_mail_data[i].mail_id = mail_table_data[i].mail_id;
+ temp_mail_data[i].account_id = mail_table_data[i].account_id;
+ temp_mail_data[i].mailbox_name = EM_SAFE_STRDUP(mail_table_data[i].mailbox_name);
+ temp_mail_data[i].mailbox_type = mail_table_data[i].mailbox_type;
+ temp_mail_data[i].subject = EM_SAFE_STRDUP(mail_table_data[i].subject);
+ temp_mail_data[i].datetime = EM_SAFE_STRDUP(mail_table_data[i].datetime);
+ temp_mail_data[i].server_mail_status = mail_table_data[i].server_mail_status;
+ temp_mail_data[i].server_mailbox_name = EM_SAFE_STRDUP(mail_table_data[i].server_mailbox_name);
+ temp_mail_data[i].server_mail_id = EM_SAFE_STRDUP(mail_table_data[i].server_mail_id);
+ temp_mail_data[i].message_id = EM_SAFE_STRDUP(mail_table_data[i].message_id);
+ temp_mail_data[i].full_address_from = EM_SAFE_STRDUP(mail_table_data[i].full_address_from);
+ temp_mail_data[i].full_address_reply = EM_SAFE_STRDUP(mail_table_data[i].full_address_reply);
+ temp_mail_data[i].full_address_to = EM_SAFE_STRDUP(mail_table_data[i].full_address_to);
+ temp_mail_data[i].full_address_cc = EM_SAFE_STRDUP(mail_table_data[i].full_address_cc);
+ temp_mail_data[i].full_address_bcc = EM_SAFE_STRDUP(mail_table_data[i].full_address_bcc);
+ temp_mail_data[i].full_address_return = EM_SAFE_STRDUP(mail_table_data[i].full_address_return);
+ temp_mail_data[i].email_address_sender = EM_SAFE_STRDUP(mail_table_data[i].email_address_sender);
+ temp_mail_data[i].email_address_recipient = EM_SAFE_STRDUP(mail_table_data[i].email_address_recipient);
+ temp_mail_data[i].alias_sender = EM_SAFE_STRDUP(mail_table_data[i].alias_sender);
+ temp_mail_data[i].alias_recipient = EM_SAFE_STRDUP(mail_table_data[i].alias_recipient);
+ temp_mail_data[i].body_download_status = mail_table_data[i].body_download_status;
+ temp_mail_data[i].file_path_plain = EM_SAFE_STRDUP(mail_table_data[i].file_path_plain);
+ temp_mail_data[i].file_path_html = EM_SAFE_STRDUP(mail_table_data[i].file_path_html);
+ temp_mail_data[i].mail_size = mail_table_data[i].mail_size;
+ temp_mail_data[i].flags_seen_field = mail_table_data[i].flags_seen_field;
+ temp_mail_data[i].flags_deleted_field = mail_table_data[i].flags_deleted_field;
+ temp_mail_data[i].flags_flagged_field = mail_table_data[i].flags_flagged_field;
+ temp_mail_data[i].flags_answered_field = mail_table_data[i].flags_answered_field;
+ temp_mail_data[i].flags_recent_field = mail_table_data[i].flags_recent_field;
+ temp_mail_data[i].flags_draft_field = mail_table_data[i].flags_draft_field;
+ temp_mail_data[i].flags_forwarded_field = mail_table_data[i].flags_forwarded_field;
+ temp_mail_data[i].DRM_status = mail_table_data[i].DRM_status;
+ temp_mail_data[i].priority = mail_table_data[i].priority;
+ temp_mail_data[i].save_status = mail_table_data[i].save_status;
+ temp_mail_data[i].lock_status = mail_table_data[i].lock_status;
+ temp_mail_data[i].report_status = mail_table_data[i].report_status;
+ temp_mail_data[i].attachment_count = mail_table_data[i].attachment_count;
+ temp_mail_data[i].inline_content_count = mail_table_data[i].inline_content_count;
+ temp_mail_data[i].thread_id = mail_table_data[i].thread_id;
+ temp_mail_data[i].thread_item_count = mail_table_data[i].thread_item_count;
+ temp_mail_data[i].preview_text = EM_SAFE_STRDUP(mail_table_data[i].preview_text);
+ temp_mail_data[i].meeting_request_status = mail_table_data[i].meeting_request_status;
+ }
+
+ *mail_data = temp_mail_data;
+
+ ret = true;
+FINISH_OFF:
+
+ if(error)
+ *error = err_code;
+
+ EM_DEBUG_FUNC_END();
+ return ret;
+}
+
+EXPORT_API int em_convert_mail_data_to_mail_tbl(emf_mail_data_t *mail_data, int item_count, emf_mail_tbl_t **mail_table_data, int *error)
+{
+ EM_DEBUG_FUNC_BEGIN("mail_data[%p], item_count [%d], mail_table_data[%p]", mail_data, item_count, mail_table_data);
+ int i, ret = false, err_code = EMF_ERROR_NONE;
+ emf_mail_tbl_t *temp_mail_tbl = NULL;
+
+ if (!mail_data || !mail_table_data || !item_count) {
+ EM_DEBUG_EXCEPTION("Invalid parameter");
+ err_code = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ temp_mail_tbl = em_core_malloc(sizeof(emf_mail_tbl_t) * item_count);
+
+ if(!temp_mail_tbl) {
+ EM_DEBUG_EXCEPTION("em_core_malloc failed");
+ err_code = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ for(i = 0; i < item_count; i++) {
+ temp_mail_tbl[i].mail_id = mail_data[i].mail_id;
+ temp_mail_tbl[i].account_id = mail_data[i].account_id;
+ temp_mail_tbl[i].mailbox_name = EM_SAFE_STRDUP(mail_data[i].mailbox_name);
+ temp_mail_tbl[i].mailbox_type = mail_data[i].mailbox_type;
+ temp_mail_tbl[i].subject = EM_SAFE_STRDUP(mail_data[i].subject);
+ temp_mail_tbl[i].datetime = EM_SAFE_STRDUP(mail_data[i].datetime);
+ temp_mail_tbl[i].server_mail_status = mail_data[i].server_mail_status;
+ temp_mail_tbl[i].server_mailbox_name = EM_SAFE_STRDUP(mail_data[i].server_mailbox_name);
+ temp_mail_tbl[i].server_mail_id = EM_SAFE_STRDUP(mail_data[i].server_mail_id);
+ temp_mail_tbl[i].message_id = EM_SAFE_STRDUP(mail_data[i].message_id);
+ temp_mail_tbl[i].full_address_from = EM_SAFE_STRDUP(mail_data[i].full_address_from);
+ temp_mail_tbl[i].full_address_reply = EM_SAFE_STRDUP(mail_data[i].full_address_reply);
+ temp_mail_tbl[i].full_address_to = EM_SAFE_STRDUP(mail_data[i].full_address_to);
+ temp_mail_tbl[i].full_address_cc = EM_SAFE_STRDUP(mail_data[i].full_address_cc);
+ temp_mail_tbl[i].full_address_bcc = EM_SAFE_STRDUP(mail_data[i].full_address_bcc);
+ temp_mail_tbl[i].full_address_return = EM_SAFE_STRDUP(mail_data[i].full_address_return);
+ temp_mail_tbl[i].email_address_sender = EM_SAFE_STRDUP(mail_data[i].email_address_sender);
+ temp_mail_tbl[i].email_address_recipient = EM_SAFE_STRDUP(mail_data[i].email_address_recipient);
+ temp_mail_tbl[i].alias_sender = EM_SAFE_STRDUP(mail_data[i].alias_sender);
+ temp_mail_tbl[i].alias_recipient = EM_SAFE_STRDUP(mail_data[i].alias_recipient);
+ temp_mail_tbl[i].body_download_status = mail_data[i].body_download_status;
+ temp_mail_tbl[i].file_path_plain = EM_SAFE_STRDUP(mail_data[i].file_path_plain);
+ temp_mail_tbl[i].file_path_html = EM_SAFE_STRDUP(mail_data[i].file_path_html);
+ temp_mail_tbl[i].mail_size = mail_data[i].mail_size;
+ temp_mail_tbl[i].flags_seen_field = mail_data[i].flags_seen_field;
+ temp_mail_tbl[i].flags_deleted_field = mail_data[i].flags_deleted_field;
+ temp_mail_tbl[i].flags_flagged_field = mail_data[i].flags_flagged_field;
+ temp_mail_tbl[i].flags_answered_field = mail_data[i].flags_answered_field;
+ temp_mail_tbl[i].flags_recent_field = mail_data[i].flags_recent_field;
+ temp_mail_tbl[i].flags_draft_field = mail_data[i].flags_draft_field;
+ temp_mail_tbl[i].flags_forwarded_field = mail_data[i].flags_forwarded_field;
+ temp_mail_tbl[i].DRM_status = mail_data[i].DRM_status;
+ temp_mail_tbl[i].priority = mail_data[i].priority;
+ temp_mail_tbl[i].save_status = mail_data[i].save_status;
+ temp_mail_tbl[i].lock_status = mail_data[i].lock_status;
+ temp_mail_tbl[i].report_status = mail_data[i].report_status;
+ temp_mail_tbl[i].attachment_count = mail_data[i].attachment_count;
+ temp_mail_tbl[i].inline_content_count = mail_data[i].inline_content_count;
+ temp_mail_tbl[i].thread_id = mail_data[i].thread_id;
+ temp_mail_tbl[i].thread_item_count = mail_data[i].thread_item_count;
+ temp_mail_tbl[i].preview_text = EM_SAFE_STRDUP(mail_data[i].preview_text);
+ temp_mail_tbl[i].meeting_request_status = mail_data[i].meeting_request_status;
+ }
+
+ *mail_table_data = temp_mail_tbl;
+
+ ret = true;
+FINISH_OFF:
+
+ if(error)
+ *error = err_code;
+
+ EM_DEBUG_FUNC_END();
+ return ret;
+
+}
+
+
+EXPORT_API int em_convert_string_to_datetime(char *datetime_str/* YYYYMMDDHHMMSS */, emf_datetime_t* datetime, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("datetime_str[%s], datetime[%p], err_code[%p]", datetime_str, datetime, err_code);
+
+ char buf[16];
+
+ if (!datetime_str || !datetime) {
+ EM_DEBUG_EXCEPTION("datetime_str[%p], datetime[%p]", datetime_str, datetime);
+ if (err_code != NULL)
+ *err_code = EMF_ERROR_INVALID_PARAM;
+ return false;
+ }
+
+ memset(buf, 0x00, sizeof(buf));
+ SNPRINTF(buf, sizeof(buf), "%.4s", datetime_str);
+ datetime->year = atoi(buf);
+ EM_DEBUG_LOG("datetime->year[%d]", datetime->year);
+ memset(buf, 0x00, sizeof(buf));
+ SNPRINTF(buf, sizeof(buf), "%.2s", datetime_str + 4);
+ datetime->month = atoi(buf);
+
+ memset(buf, 0x00, sizeof(buf));
+ SNPRINTF(buf, sizeof(buf), "%.2s", datetime_str + 6);
+ datetime->day = atoi(buf);
+
+ memset(buf, 0x00, sizeof(buf));
+ SNPRINTF(buf, sizeof(buf), "%.2s", datetime_str + 8);
+ datetime->hour = atoi(buf);
+
+ memset(buf, 0x00, sizeof(buf));
+ SNPRINTF(buf, sizeof(buf), "%.2s", datetime_str + 10);
+ datetime->minute = atoi(buf);
+
+ memset(buf, 0x00, sizeof(buf));
+ SNPRINTF(buf, sizeof(buf), "%.2s", datetime_str + 12);
+ datetime->second = atoi(buf);
+
+ if (err_code != NULL)
+ *err_code = EMF_ERROR_NONE;
+ EM_DEBUG_FUNC_END();
+ return true;
+}
+
+EXPORT_API int em_convert_datetime_to_string(emf_datetime_t *input_datetime, char **output_datetime_str, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("input_datetime[%s], output_datetime_str[%p], err_code[%p]", input_datetime, output_datetime_str, err_code);
+ char temp_buffer[20] = { 0, };
+
+ if (!input_datetime || !output_datetime_str) {
+ EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
+ if (err_code != NULL)
+ *err_code = EMF_ERROR_INVALID_PARAM;
+ return false;
+ }
+
+ SNPRINTF(temp_buffer, sizeof(temp_buffer), "%04d%02d%02d%02d%02d%02d",
+ input_datetime->year, input_datetime->month, input_datetime->day, input_datetime->hour, input_datetime->minute, input_datetime->second);
+
+ *output_datetime_str = EM_SAFE_STRDUP(temp_buffer);
+
+ if (err_code != NULL)
+ *err_code = EMF_ERROR_NONE;
+
+ EM_DEBUG_FUNC_END();
+ return true;
+}
+
+static char* append_sized_data_to_stream(char *input_stream, int *input_output_stream_length, char *input_sized_data, int input_data_size)
+{
+ EM_DEBUG_FUNC_BEGIN("input_stream [%p], input_output_stream_length [%p], input_sized_data [%p], input_data_size [%d]", input_stream, input_output_stream_length, input_sized_data, input_data_size);
+ char *new_stream = NULL;
+ int source_stream_length = 0;
+
+ if( !input_output_stream_length || input_data_size == 0 || input_sized_data == NULL||
+ (input_stream != NULL && *input_output_stream_length == 0) || (input_stream == NULL && *input_output_stream_length != 0) ) {
+ EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
+ return NULL;
+ }
+
+ source_stream_length = *input_output_stream_length;
+
+ new_stream = (char*)em_core_malloc((source_stream_length) * sizeof(char) + input_data_size);
+
+ if(!new_stream) {
+ EM_DEBUG_EXCEPTION("EMF_ERROR_OUT_OF_MEMORY");
+ return NULL;
+ }
+
+ if(input_stream != NULL)
+ memcpy(new_stream, input_stream, source_stream_length * sizeof(char));
+
+ memcpy(new_stream + source_stream_length, input_sized_data, input_data_size);
+
+ *input_output_stream_length = source_stream_length + input_data_size;
+
+ EM_SAFE_FREE(input_stream);
+ EM_DEBUG_FUNC_END("*input_output_stream_length [%d]", *input_output_stream_length);
+ return new_stream;
+}
+
+static char* append_string_to_stream(char *input_stream, int *input_output_stream_length, char *input_source_string)
+{
+ EM_DEBUG_FUNC_BEGIN("input_stream [%p], input_output_stream_length [%p] input_source_string[%p]", input_stream, input_output_stream_length, input_source_string);
+ char *new_stream = NULL;
+ int data_length = 0;
+ int source_stream_length = 0;
+
+ if( !input_output_stream_length || (input_stream != NULL && *input_output_stream_length == 0) || (input_stream == NULL && *input_output_stream_length != 0)) {
+ EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
+ return NULL;
+ }
+
+ source_stream_length = *input_output_stream_length;
+
+ if(input_source_string != NULL)
+ data_length = EM_SAFE_STRLEN(input_source_string);
+
+ new_stream = (char*)em_core_malloc((source_stream_length + data_length) * sizeof(char) + sizeof(int));
+
+ if(!new_stream) {
+ EM_DEBUG_EXCEPTION("EMF_ERROR_OUT_OF_MEMORY");
+ return NULL;
+ }
+
+ if(input_stream != NULL)
+ memcpy(new_stream, input_stream, source_stream_length * sizeof(char));
+
+ memcpy(new_stream + source_stream_length, (char*)&data_length, sizeof(int));
+
+ if(input_source_string)
+ memcpy(new_stream + source_stream_length + sizeof(int), input_source_string, data_length);
+
+ *input_output_stream_length = source_stream_length + sizeof(int) + data_length;
+
+ EM_SAFE_FREE(input_stream);
+ EM_DEBUG_FUNC_END("*input_output_stream_length [%d]", *input_output_stream_length);
+ return new_stream;
+}
+
+static int fetch_sized_data_from_stream(char *input_stream, int *input_output_stream_offset, int input_data_size, char *output_data)
+{
+ EM_DEBUG_FUNC_BEGIN("input_stream [%p], input_output_stream_offset [%p] input_data_size [%d], output_data[%p]", input_stream, input_output_stream_offset, input_data_size, output_data);
+ int stream_offset = 0;
+
+ if( !input_stream || !input_output_stream_offset || !input_data_size || !output_data) {
+ EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
+ return EMF_ERROR_INVALID_PARAM;
+ }
+
+ stream_offset = *input_output_stream_offset;
+
+ memcpy(output_data, input_stream + stream_offset, input_data_size);
+ stream_offset += input_data_size;
+
+ *input_output_stream_offset = stream_offset;
+
+ EM_DEBUG_FUNC_END("stream_offset [%d]", stream_offset);
+ return EMF_ERROR_NONE;
+}
+
+static int fetch_string_from_stream(char *input_stream, int *input_output_stream_offset, char **output_string)
+{
+ EM_DEBUG_FUNC_BEGIN("input_stream [%p], input_output_stream_offset [%p] output_string[%p]", input_stream, input_output_stream_offset, output_string);
+ int string_length = 0;
+ int stream_offset = 0;
+ char *result_string = NULL;
+
+ if( !input_stream || !input_output_stream_offset || !output_string) {
+ EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
+ return EMF_ERROR_INVALID_PARAM;
+ }
+
+ stream_offset = *input_output_stream_offset;
+ /*
+ EM_DEBUG_LOG("stream_offset [%d]", stream_offset);
+ */
+
+ memcpy(&string_length, input_stream + stream_offset, sizeof(int));
+ stream_offset += sizeof(int);
+
+ /*
+ EM_DEBUG_LOG("string_length [%d]", string_length);
+ */
+
+ if(string_length != 0) {
+ result_string = (char*)em_core_malloc(string_length + 1);
+ if(result_string) {
+ memcpy(result_string, input_stream + stream_offset, string_length);
+ stream_offset += string_length;
+ }
+ }
+ /*
+ if(result_string)
+ EM_DEBUG_LOG("result_string [%s]", result_string);
+ */
+
+ *output_string = result_string;
+ *input_output_stream_offset = stream_offset;
+
+ EM_DEBUG_FUNC_END("stream_offset [%d]", stream_offset);
+ return EMF_ERROR_NONE;
+}
+
+EXPORT_API char* em_convert_account_to_byte_stream(emf_account_t* input_account, int *output_stream_size)
+{
+ EM_DEBUG_FUNC_BEGIN("input_account [%p], output_stream_size [%p]", input_account, output_stream_size);
+ char *result_stream = NULL;
+ int stream_size = 0;
+
+ EM_IF_NULL_RETURN_VALUE(input_account, NULL);
+
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_account->account_bind_type), sizeof(int));
+ result_stream = append_string_to_stream(result_stream, &stream_size, input_account->account_name);
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_account->receiving_server_type), sizeof(int));
+ result_stream = append_string_to_stream(result_stream, &stream_size, input_account->receiving_server_addr);
+ result_stream = append_string_to_stream(result_stream, &stream_size, input_account->email_addr);
+ result_stream = append_string_to_stream(result_stream, &stream_size, input_account->user_name);
+ result_stream = append_string_to_stream(result_stream, &stream_size, input_account->password);
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_account->retrieval_mode), sizeof(int));
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_account->port_num), sizeof(int));
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_account->use_security), sizeof(int));
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_account->sending_server_type), sizeof(int));
+ result_stream = append_string_to_stream(result_stream, &stream_size, input_account->sending_server_addr);
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_account->sending_port_num), sizeof(int));
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_account->sending_auth), sizeof(int));
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_account->sending_security), sizeof(int));
+ result_stream = append_string_to_stream(result_stream, &stream_size, input_account->sending_user);
+ result_stream = append_string_to_stream(result_stream, &stream_size, input_account->sending_password);
+ result_stream = append_string_to_stream(result_stream, &stream_size, input_account->display_name);
+ result_stream = append_string_to_stream(result_stream, &stream_size, input_account->reply_to_addr);
+ result_stream = append_string_to_stream(result_stream, &stream_size, input_account->return_addr);
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_account->account_id), sizeof(int));
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_account->keep_on_server), sizeof(int));
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_account->flag1), sizeof(int));
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_account->flag2), sizeof(int));
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_account->pop_before_smtp), sizeof(int));
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_account->apop), sizeof(int));
+ result_stream = append_string_to_stream(result_stream, &stream_size, input_account->logo_icon_path);
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_account->preset_account), sizeof(int));
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_account->options.priority), sizeof(int));
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_account->options.keep_local_copy), sizeof(int));
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_account->options.req_delivery_receipt), sizeof(int));
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_account->options.req_read_receipt), sizeof(int));
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_account->options.download_limit), sizeof(int));
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_account->options.block_address), sizeof(int));
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_account->options.block_subject), sizeof(int));
+ result_stream = append_string_to_stream(result_stream, &stream_size, input_account->options.display_name_from);
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_account->options.reply_with_body), sizeof(int));
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_account->options.forward_with_files), sizeof(int));
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_account->options.add_myname_card), sizeof(int));
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_account->options.add_signature), sizeof(int));
+ result_stream = append_string_to_stream(result_stream, &stream_size, input_account->options.signature);
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_account->options.add_my_address_to_bcc), sizeof(int));
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_account->target_storage), sizeof(int));
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_account->check_interval), sizeof(int));
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_account->my_account_id), sizeof(int));
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_account->index_color), sizeof(int));
+
+ *output_stream_size = stream_size;
+
+ EM_DEBUG_FUNC_END("stream_size [%d]", stream_size);
+ return result_stream;
+}
+
+
+EXPORT_API void em_convert_byte_stream_to_account(char *input_stream, emf_account_t *output_account)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int stream_offset = 0;
+
+ EM_NULL_CHECK_FOR_VOID(input_stream);
+ EM_NULL_CHECK_FOR_VOID(output_account);
+
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&output_account->account_bind_type);
+ fetch_string_from_stream(input_stream, &stream_offset, &output_account->account_name);
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&output_account->receiving_server_type);
+ fetch_string_from_stream(input_stream, &stream_offset, &output_account->receiving_server_addr);
+ fetch_string_from_stream(input_stream, &stream_offset, &output_account->email_addr);
+ fetch_string_from_stream(input_stream, &stream_offset, &output_account->user_name);
+ fetch_string_from_stream(input_stream, &stream_offset, &output_account->password);
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&output_account->retrieval_mode);
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&output_account->port_num);
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&output_account->use_security);
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&output_account->sending_server_type);
+ fetch_string_from_stream(input_stream, &stream_offset, &output_account->sending_server_addr);
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&output_account->sending_port_num);
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&output_account->sending_auth);
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&output_account->sending_security);
+ fetch_string_from_stream(input_stream, &stream_offset, &output_account->sending_user);
+ fetch_string_from_stream(input_stream, &stream_offset, &output_account->sending_password);
+ fetch_string_from_stream(input_stream, &stream_offset, &output_account->display_name);
+ fetch_string_from_stream(input_stream, &stream_offset, &output_account->reply_to_addr);
+ fetch_string_from_stream(input_stream, &stream_offset, &output_account->return_addr);
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&output_account->account_id);
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&output_account->keep_on_server);
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&output_account->flag1);
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&output_account->flag2);
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&output_account->pop_before_smtp);
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&output_account->apop);
+ fetch_string_from_stream(input_stream, &stream_offset, &output_account->logo_icon_path);
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&output_account->preset_account);
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&output_account->options.priority);
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&output_account->options.keep_local_copy);
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&output_account->options.req_delivery_receipt);
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&output_account->options.req_read_receipt);
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&output_account->options.download_limit);
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&output_account->options.block_address);
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&output_account->options.block_subject);
+ fetch_string_from_stream(input_stream, &stream_offset, &output_account->options.display_name_from);
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&output_account->options.reply_with_body);
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&output_account->options.forward_with_files);
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&output_account->options.add_myname_card);
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&output_account->options.add_signature);
+ fetch_string_from_stream(input_stream, &stream_offset, &output_account->options.signature);
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&output_account->options.add_my_address_to_bcc);
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&output_account->target_storage);
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&output_account->check_interval);
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&output_account->my_account_id);
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&output_account->index_color);
+
+ EM_DEBUG_FUNC_END();
+}
+
+
+EXPORT_API char* em_convert_mail_head_to_byte_stream(emf_mail_head_t *input_mail_head, int *output_stream_size)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ char *result_stream = NULL;
+ int stream_size = 0;
+
+ EM_IF_NULL_RETURN_VALUE(input_mail_head, NULL);
+ EM_IF_NULL_RETURN_VALUE(output_stream_size, NULL);
+
+ result_stream = append_string_to_stream(result_stream, &stream_size, input_mail_head->mid);
+ result_stream = append_string_to_stream(result_stream, &stream_size, input_mail_head->subject);
+ result_stream = append_string_to_stream(result_stream, &stream_size, input_mail_head->to);
+ result_stream = append_string_to_stream(result_stream, &stream_size, input_mail_head->from);
+ result_stream = append_string_to_stream(result_stream, &stream_size, input_mail_head->cc);
+ result_stream = append_string_to_stream(result_stream, &stream_size, input_mail_head->bcc);
+ result_stream = append_string_to_stream(result_stream, &stream_size, input_mail_head->reply_to);
+ result_stream = append_string_to_stream(result_stream, &stream_size, input_mail_head->return_path);
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&input_mail_head->datetime.year, sizeof(unsigned short));
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&input_mail_head->datetime.month, sizeof(unsigned short));
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&input_mail_head->datetime.day, sizeof(unsigned short));
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&input_mail_head->datetime.hour, sizeof(unsigned short));
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&input_mail_head->datetime.minute, sizeof(unsigned short));
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&input_mail_head->datetime.second, sizeof(unsigned short));
+ result_stream = append_string_to_stream(result_stream, &stream_size, input_mail_head->from_contact_name);
+ result_stream = append_string_to_stream(result_stream, &stream_size, input_mail_head->to_contact_name);
+ result_stream = append_string_to_stream(result_stream, &stream_size, input_mail_head->cc_contact_name);
+ result_stream = append_string_to_stream(result_stream, &stream_size, input_mail_head->bcc_contact_name);
+ result_stream = append_string_to_stream(result_stream, &stream_size, input_mail_head->previewBodyText);
+
+ *output_stream_size = stream_size;
+
+ EM_DEBUG_FUNC_END();
+ return result_stream;
+}
+
+EXPORT_API void em_convert_byte_stream_to_mail_head(char *input_stream, emf_mail_head_t *output_mail_head)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int stream_offset = 0;
+
+ EM_NULL_CHECK_FOR_VOID(input_stream);
+ EM_NULL_CHECK_FOR_VOID(output_mail_head);
+
+ fetch_string_from_stream(input_stream, &stream_offset, &output_mail_head->mid);
+ fetch_string_from_stream(input_stream, &stream_offset, &output_mail_head->subject);
+ fetch_string_from_stream(input_stream, &stream_offset, &output_mail_head->to);
+ fetch_string_from_stream(input_stream, &stream_offset, &output_mail_head->from);
+ fetch_string_from_stream(input_stream, &stream_offset, &output_mail_head->cc);
+ fetch_string_from_stream(input_stream, &stream_offset, &output_mail_head->bcc);
+ fetch_string_from_stream(input_stream, &stream_offset, &output_mail_head->reply_to);
+ fetch_string_from_stream(input_stream, &stream_offset, &output_mail_head->return_path);
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(unsigned short), (char*)&output_mail_head->datetime.year);
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(unsigned short), (char*)&output_mail_head->datetime.month);
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(unsigned short), (char*)&output_mail_head->datetime.day);
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(unsigned short), (char*)&output_mail_head->datetime.hour);
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(unsigned short), (char*)&output_mail_head->datetime.minute);
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(unsigned short), (char*)&output_mail_head->datetime.second);
+ fetch_string_from_stream(input_stream, &stream_offset, &output_mail_head->from_contact_name);
+ fetch_string_from_stream(input_stream, &stream_offset, &output_mail_head->to_contact_name);
+ fetch_string_from_stream(input_stream, &stream_offset, &output_mail_head->cc_contact_name);
+ fetch_string_from_stream(input_stream, &stream_offset, &output_mail_head->bcc_contact_name);
+ fetch_string_from_stream(input_stream, &stream_offset, &output_mail_head->previewBodyText);
+
+ EM_DEBUG_FUNC_END();
+}
+
+
+EXPORT_API char* em_convert_mail_body_to_byte_stream(emf_mail_body_t* input_mail_body, int* output_stream_size)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ char *result_stream = NULL;
+ int stream_size = 0;
+ emf_attachment_info_t *temp_attachment_info = NULL;
+
+ EM_IF_NULL_RETURN_VALUE(input_mail_body, NULL);
+ EM_IF_NULL_RETURN_VALUE(output_stream_size, NULL);
+
+ result_stream = append_string_to_stream(result_stream, &stream_size, input_mail_body->plain);
+ result_stream = append_string_to_stream(result_stream, &stream_size, input_mail_body->plain_charset);
+ result_stream = append_string_to_stream(result_stream, &stream_size, input_mail_body->html);
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&input_mail_body->attachment_num, sizeof(int));
+
+ temp_attachment_info = input_mail_body->attachment;
+
+ while(temp_attachment_info) {
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&temp_attachment_info->inline_content, sizeof(int));
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&temp_attachment_info->attachment_id, sizeof(int));
+ result_stream = append_string_to_stream(result_stream, &stream_size, temp_attachment_info->name);
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&temp_attachment_info->size, sizeof(int));
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&temp_attachment_info->downloaded, sizeof(int));
+ result_stream = append_string_to_stream(result_stream, &stream_size, temp_attachment_info->savename);
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&temp_attachment_info->drm, sizeof(int));
+ temp_attachment_info = temp_attachment_info->next;
+ }
+
+ *output_stream_size = stream_size;
+
+ EM_DEBUG_FUNC_END();
+ return result_stream;
+}
+
+
+EXPORT_API void em_convert_byte_stream_to_mail_body(char* input_stream, emf_mail_body_t* output_mail_body)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ int stream_offset = 0;
+ int i = 0;
+ emf_attachment_info_t *temp_attachment_info = NULL;
+ emf_attachment_info_t *temp_attachment_info_cursor = NULL;
+
+ EM_NULL_CHECK_FOR_VOID(input_stream);
+ EM_NULL_CHECK_FOR_VOID(output_mail_body);
+
+ fetch_string_from_stream(input_stream, &stream_offset, &output_mail_body->plain);
+ fetch_string_from_stream(input_stream, &stream_offset, &output_mail_body->plain_charset);
+ fetch_string_from_stream(input_stream, &stream_offset, &output_mail_body->html);
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&output_mail_body->attachment_num);
+
+ if(output_mail_body->attachment_num <= 0)
+ output_mail_body->attachment = NULL;
+
+ for(i = 0; i < output_mail_body->attachment_num; i++) {
+
+ temp_attachment_info = (emf_attachment_info_t*)malloc(sizeof(emf_attachment_info_t));
+
+ if(!temp_attachment_info) {
+ EM_DEBUG_EXCEPTION("EMF_ERROR_OUT_OF_MEMORY");
+ return;
+ }
+
+ if(i == 0)
+ output_mail_body->attachment = temp_attachment_info_cursor = temp_attachment_info;
+ else {
+ temp_attachment_info_cursor->next = temp_attachment_info;
+ temp_attachment_info_cursor = temp_attachment_info;
+ }
+
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&temp_attachment_info->inline_content);
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&temp_attachment_info->attachment_id);
+ fetch_string_from_stream(input_stream, &stream_offset, &temp_attachment_info->name);
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&temp_attachment_info->size);
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&temp_attachment_info->downloaded);
+ fetch_string_from_stream(input_stream, &stream_offset, &temp_attachment_info->savename);
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&temp_attachment_info->drm);
+
+ temp_attachment_info->next = NULL;
+ }
+
+ EM_DEBUG_FUNC_END();
+}
+
+
+EXPORT_API char* em_convert_attachment_info_to_byte_stream(emf_attachment_info_t *input_attachment_info, int *output_stream_size)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ char *result_stream = NULL;
+ int stream_size = 0;
+
+ EM_IF_NULL_RETURN_VALUE(input_attachment_info, NULL);
+ EM_IF_NULL_RETURN_VALUE(output_stream_size, NULL);
+
+ while(input_attachment_info) {
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&input_attachment_info->inline_content, sizeof(int));
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&input_attachment_info->attachment_id, sizeof(int));
+ result_stream = append_string_to_stream(result_stream, &stream_size, input_attachment_info->name);
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&input_attachment_info->size, sizeof(int));
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&input_attachment_info->downloaded, sizeof(int));
+ result_stream = append_string_to_stream(result_stream, &stream_size, input_attachment_info->savename);
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&input_attachment_info->drm, sizeof(int));
+
+ input_attachment_info = input_attachment_info->next;
+ }
+
+ *output_stream_size = stream_size;
+
+ EM_DEBUG_FUNC_END();
+ return result_stream;
+}
+
+EXPORT_API void em_convert_byte_stream_to_attachment_info(char *input_stream, int attachment_count, emf_attachment_info_t **output_attachment_info)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ int i = 0;
+ int stream_offset = 0;
+ emf_attachment_info_t *temp_attachment_info = NULL;
+ emf_attachment_info_t *current_attachment_info = NULL;
+
+ EM_NULL_CHECK_FOR_VOID(input_stream);
+
+ for(i = 0; i < attachment_count; i++) {
+ temp_attachment_info = (emf_attachment_info_t*)malloc(sizeof(emf_attachment_info_t));
+
+ if(i == 0)
+ *output_attachment_info = current_attachment_info = temp_attachment_info;
+ else {
+ current_attachment_info->next = temp_attachment_info;
+ current_attachment_info = temp_attachment_info;
+ }
+
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&temp_attachment_info->inline_content);
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&temp_attachment_info->attachment_id);
+ fetch_string_from_stream(input_stream, &stream_offset, &temp_attachment_info->name);
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&temp_attachment_info->size);
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&temp_attachment_info->downloaded);
+ fetch_string_from_stream(input_stream, &stream_offset, &temp_attachment_info->savename);
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&temp_attachment_info->drm);
+
+ temp_attachment_info->next = NULL;
+ }
+
+ EM_DEBUG_FUNC_END();
+}
+
+EXPORT_API char* em_convert_mail_data_to_byte_stream(emf_mail_data_t *input_mail_data, int input_mail_data_count, int *output_stream_size)
+{
+ EM_DEBUG_FUNC_BEGIN("input_mail_data [%p], input_mail_data_count[%d], output_stream_size[%p]", input_mail_data, input_mail_data_count, output_stream_size);
+
+ char *result_stream = NULL;
+ int stream_size = 0;
+ int i = 0;
+
+ EM_IF_NULL_RETURN_VALUE(input_mail_data, NULL);
+ EM_IF_NULL_RETURN_VALUE(output_stream_size, NULL);
+
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&input_mail_data_count, sizeof(int));
+
+ for(i = 0; i < input_mail_data_count; i++) {
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_mail_data[i].mail_id), sizeof(int));
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_mail_data[i].account_id), sizeof(int));
+ result_stream = append_string_to_stream(result_stream, &stream_size, input_mail_data[i].mailbox_name);
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_mail_data[i].mailbox_type), sizeof(int));
+ result_stream = append_string_to_stream(result_stream, &stream_size, input_mail_data[i].subject);
+ result_stream = append_string_to_stream(result_stream, &stream_size, input_mail_data[i].datetime);
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_mail_data[i].server_mail_status), sizeof(int));
+ result_stream = append_string_to_stream(result_stream, &stream_size, input_mail_data[i].server_mailbox_name);
+ result_stream = append_string_to_stream(result_stream, &stream_size, input_mail_data[i].server_mail_id);
+ result_stream = append_string_to_stream(result_stream, &stream_size, input_mail_data[i].message_id);
+ result_stream = append_string_to_stream(result_stream, &stream_size, input_mail_data[i].full_address_from);
+ result_stream = append_string_to_stream(result_stream, &stream_size, input_mail_data[i].full_address_reply);
+ result_stream = append_string_to_stream(result_stream, &stream_size, input_mail_data[i].full_address_to);
+ result_stream = append_string_to_stream(result_stream, &stream_size, input_mail_data[i].full_address_cc);
+ result_stream = append_string_to_stream(result_stream, &stream_size, input_mail_data[i].full_address_bcc);
+ result_stream = append_string_to_stream(result_stream, &stream_size, input_mail_data[i].full_address_return);
+ result_stream = append_string_to_stream(result_stream, &stream_size, input_mail_data[i].email_address_sender);
+ result_stream = append_string_to_stream(result_stream, &stream_size, input_mail_data[i].email_address_recipient);
+ result_stream = append_string_to_stream(result_stream, &stream_size, input_mail_data[i].alias_sender);
+ result_stream = append_string_to_stream(result_stream, &stream_size, input_mail_data[i].alias_recipient);
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_mail_data[i].body_download_status), sizeof(int));
+ result_stream = append_string_to_stream(result_stream, &stream_size, input_mail_data[i].file_path_plain);
+ result_stream = append_string_to_stream(result_stream, &stream_size, input_mail_data[i].file_path_html);
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_mail_data[i].mail_size), sizeof(int));
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_mail_data[i].flags_seen_field), sizeof(char));
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_mail_data[i].flags_deleted_field), sizeof(char));
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_mail_data[i].flags_flagged_field), sizeof(char));
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_mail_data[i].flags_answered_field), sizeof(char));
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_mail_data[i].flags_recent_field), sizeof(char));
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_mail_data[i].flags_draft_field), sizeof(char));
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_mail_data[i].flags_forwarded_field), sizeof(char));
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_mail_data[i].DRM_status), sizeof(int));
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_mail_data[i].priority), sizeof(int));
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_mail_data[i].save_status), sizeof(int));
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_mail_data[i].lock_status), sizeof(int));
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_mail_data[i].report_status), sizeof(int));
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_mail_data[i].attachment_count), sizeof(int));
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_mail_data[i].inline_content_count), sizeof(int));
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_mail_data[i].thread_id), sizeof(int));
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_mail_data[i].thread_item_count), sizeof(int));
+ result_stream = append_string_to_stream(result_stream, &stream_size, input_mail_data[i].preview_text);
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_mail_data[i].meeting_request_status), sizeof(int));
+ }
+
+ *output_stream_size = stream_size;
+
+ EM_DEBUG_FUNC_END("stream_size [%d]", stream_size);
+ return result_stream;
+}
+
+EXPORT_API void em_convert_byte_stream_to_mail_data(char *input_stream, emf_mail_data_t **output_mail_data, int *output_mail_data_count)
+{
+ EM_DEBUG_FUNC_BEGIN("input_stream [%p], output_mail_data[%p], output_mail_data_count[%p]", input_stream, output_mail_data, output_mail_data_count);
+
+ int stream_offset = 0;
+ int i = 0;
+
+ EM_NULL_CHECK_FOR_VOID(input_stream);
+ EM_NULL_CHECK_FOR_VOID(output_mail_data);
+ EM_NULL_CHECK_FOR_VOID(output_mail_data_count);
+
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)output_mail_data_count);
+
+ EM_DEBUG_LOG("*output_mail_data_count [%d]", *output_mail_data_count);
+
+ if(output_mail_data_count <= 0) {
+ EM_DEBUG_EXCEPTION("no mail data.");
+ return;
+ }
+
+ *output_mail_data = (emf_mail_data_t*)em_core_malloc(sizeof(emf_mail_data_t) * (*output_mail_data_count));
+
+ if(!*output_mail_data) {
+ EM_DEBUG_EXCEPTION("em_core_malloc failed");
+ return;
+ }
+
+ for(i = 0; i < *output_mail_data_count; i++) {
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&(*output_mail_data)[i].mail_id);
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&(*output_mail_data)[i].account_id);
+ fetch_string_from_stream(input_stream, &stream_offset, &(*output_mail_data)[i].mailbox_name);
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&(*output_mail_data)[i].mailbox_type);
+ fetch_string_from_stream(input_stream, &stream_offset, &(*output_mail_data)[i].subject);
+ fetch_string_from_stream(input_stream, &stream_offset, &(*output_mail_data)[i].datetime);
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&(*output_mail_data)[i].server_mail_status);
+ fetch_string_from_stream(input_stream, &stream_offset, &(*output_mail_data)[i].server_mailbox_name);
+ fetch_string_from_stream(input_stream, &stream_offset, &(*output_mail_data)[i].server_mail_id);
+ fetch_string_from_stream(input_stream, &stream_offset, &(*output_mail_data)[i].message_id);
+ fetch_string_from_stream(input_stream, &stream_offset, &(*output_mail_data)[i].full_address_from);
+ fetch_string_from_stream(input_stream, &stream_offset, &(*output_mail_data)[i].full_address_reply);
+ fetch_string_from_stream(input_stream, &stream_offset, &(*output_mail_data)[i].full_address_to);
+ fetch_string_from_stream(input_stream, &stream_offset, &(*output_mail_data)[i].full_address_cc);
+ fetch_string_from_stream(input_stream, &stream_offset, &(*output_mail_data)[i].full_address_bcc);
+ fetch_string_from_stream(input_stream, &stream_offset, &(*output_mail_data)[i].full_address_return);
+ fetch_string_from_stream(input_stream, &stream_offset, &(*output_mail_data)[i].email_address_sender);
+ fetch_string_from_stream(input_stream, &stream_offset, &(*output_mail_data)[i].email_address_recipient);
+ fetch_string_from_stream(input_stream, &stream_offset, &(*output_mail_data)[i].alias_sender);
+ fetch_string_from_stream(input_stream, &stream_offset, &(*output_mail_data)[i].alias_recipient);
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&(*output_mail_data)[i].body_download_status);
+ fetch_string_from_stream(input_stream, &stream_offset, &(*output_mail_data)[i].file_path_plain);
+ fetch_string_from_stream(input_stream, &stream_offset, &(*output_mail_data)[i].file_path_html);
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&(*output_mail_data)[i].mail_size);
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(char), (char*)&(*output_mail_data)[i].flags_seen_field);
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(char), (char*)&(*output_mail_data)[i].flags_deleted_field);
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(char), (char*)&(*output_mail_data)[i].flags_flagged_field);
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(char), (char*)&(*output_mail_data)[i].flags_answered_field);
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(char), (char*)&(*output_mail_data)[i].flags_recent_field);
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(char), (char*)&(*output_mail_data)[i].flags_draft_field);
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(char), (char*)&(*output_mail_data)[i].flags_forwarded_field);
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&(*output_mail_data)[i].DRM_status);
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&(*output_mail_data)[i].priority);
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&(*output_mail_data)[i].save_status);
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&(*output_mail_data)[i].lock_status);
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&(*output_mail_data)[i].report_status);
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&(*output_mail_data)[i].attachment_count);
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&(*output_mail_data)[i].inline_content_count);
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&(*output_mail_data)[i].thread_id);
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&(*output_mail_data)[i].thread_item_count);
+ fetch_string_from_stream(input_stream, &stream_offset, &(*output_mail_data)[i].preview_text);
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&(*output_mail_data)[i].meeting_request_status);
+ }
+
+ EM_DEBUG_FUNC_END();
+}
+
+EXPORT_API char* em_convert_attachment_data_to_byte_stream(emf_attachment_data_t *input_attachment_data, int input_attachment_count, int* output_stream_size)
+{
+ EM_DEBUG_FUNC_BEGIN("input_attachment_data [%p], input_attachment_count [%d], output_stream_size [%p]", input_attachment_data, input_attachment_count, output_stream_size);
+
+ char *result_stream = NULL;
+ int stream_size = 0;
+ int i = 0;
+
+ if(input_attachment_count > 0)
+ EM_IF_NULL_RETURN_VALUE(input_attachment_data, NULL);
+ EM_IF_NULL_RETURN_VALUE(output_stream_size, NULL);
+
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&input_attachment_count, sizeof(int));
+
+ for(i = 0; i < input_attachment_count; i++) {
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&input_attachment_data[i].attachment_id, sizeof(int));
+ result_stream = append_string_to_stream(result_stream, &stream_size, input_attachment_data[i].attachment_name);
+ result_stream = append_string_to_stream(result_stream, &stream_size, input_attachment_data[i].attachment_path);
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&input_attachment_data[i].attachment_size, sizeof(int));
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&input_attachment_data[i].mail_id, sizeof(int));
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&input_attachment_data[i].account_id, sizeof(int));
+ result_stream = append_string_to_stream(result_stream, &stream_size, input_attachment_data[i].mailbox_name);
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&input_attachment_data[i].save_status, sizeof(int));
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&input_attachment_data[i].drm_status, sizeof(int));
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&input_attachment_data[i].inline_content_status,sizeof(int));
+ }
+
+ *output_stream_size = stream_size;
+
+ EM_DEBUG_FUNC_END("stream_size [%d]", stream_size);
+ return result_stream;
+}
+
+EXPORT_API void em_convert_byte_stream_to_attachment_data(char *input_stream, emf_attachment_data_t **output_attachment_data, int *output_attachment_count)
+{
+ EM_DEBUG_FUNC_BEGIN("input_stream [%p], output_attachment_data[%p]", input_stream, output_attachment_data);
+
+ int stream_offset = 0;
+ int i = 0;
+
+ EM_NULL_CHECK_FOR_VOID(input_stream);
+ EM_NULL_CHECK_FOR_VOID(output_attachment_data);
+ EM_NULL_CHECK_FOR_VOID(output_attachment_count);
+
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)output_attachment_count);
+
+ EM_DEBUG_LOG("*output_attachment_count [%d]", *output_attachment_count);
+
+ if(output_attachment_count <= 0) {
+ EM_DEBUG_EXCEPTION("no attachment data.");
+ return;
+ }
+
+ *output_attachment_data = (emf_attachment_data_t*)em_core_malloc(sizeof(emf_attachment_data_t) * (*output_attachment_count));
+
+ if(!*output_attachment_data) {
+ EM_DEBUG_EXCEPTION("em_core_malloc failed");
+ return;
+ }
+
+ for(i = 0; i < *output_attachment_count; i++) {
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&((*output_attachment_data)[i].attachment_id));
+ fetch_string_from_stream(input_stream, &stream_offset, &(*output_attachment_data)[i].attachment_name);
+ fetch_string_from_stream(input_stream, &stream_offset, &(*output_attachment_data)[i].attachment_path);
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&((*output_attachment_data)[i].attachment_size));
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&((*output_attachment_data)[i].mail_id));
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&((*output_attachment_data)[i].account_id));
+ fetch_string_from_stream(input_stream, &stream_offset, &(*output_attachment_data)[i].mailbox_name);
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&((*output_attachment_data)[i].save_status));
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&((*output_attachment_data)[i].drm_status));
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&((*output_attachment_data)[i].inline_content_status));
+ }
+
+ EM_DEBUG_FUNC_END();
+}
+
+
+
+EXPORT_API char* em_convert_mailbox_to_byte_stream(emf_mailbox_t *input_mailbox_data, int *output_stream_size)
+{
+ EM_DEBUG_FUNC_BEGIN("input_mailbox_data [%p], output_stream_size [%p]", input_mailbox_data, output_stream_size);
+
+ char *result_stream = NULL;
+ int stream_size = 0;
+
+ EM_IF_NULL_RETURN_VALUE(input_mailbox_data, NULL);
+ EM_IF_NULL_RETURN_VALUE(output_stream_size, NULL);
+
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_mailbox_data->mailbox_id), sizeof(int));
+ result_stream = append_string_to_stream(result_stream, &stream_size, input_mailbox_data->name);
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_mailbox_data->mailbox_type), sizeof(int));
+ result_stream = append_string_to_stream(result_stream, &stream_size, input_mailbox_data->alias);
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_mailbox_data->unread_count), sizeof(int));
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_mailbox_data->total_mail_count_on_local), sizeof(int));
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_mailbox_data->total_mail_count_on_server), sizeof(int));
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_mailbox_data->hold_connection), sizeof(int));
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_mailbox_data->local), sizeof(int));
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_mailbox_data->synchronous), sizeof(int));
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_mailbox_data->account_id), sizeof(int));
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_mailbox_data->user_data), sizeof(int));
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_mailbox_data->mail_stream), sizeof(int));
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_mailbox_data->has_archived_mails), sizeof(int));
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_mailbox_data->mail_slot_size), sizeof(int));
+ result_stream = append_string_to_stream(result_stream, &stream_size, input_mailbox_data->account_name);
+
+ *output_stream_size = stream_size;
+
+ EM_DEBUG_FUNC_END();
+
+ return result_stream;
+}
+
+
+EXPORT_API void em_convert_byte_stream_to_mailbox(char *input_stream, emf_mailbox_t *output_mailbox_data)
+{
+ EM_DEBUG_FUNC_BEGIN("input_stream [%p], output_mailbox_data [%p]", input_stream, output_mailbox_data);
+ int stream_offset = 0;
+
+ EM_NULL_CHECK_FOR_VOID(input_stream);
+ EM_NULL_CHECK_FOR_VOID(output_mailbox_data);
+
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&(output_mailbox_data->mailbox_id));
+ fetch_string_from_stream(input_stream, &stream_offset, &output_mailbox_data->name);
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&(output_mailbox_data->mailbox_type));
+ fetch_string_from_stream(input_stream, &stream_offset, &output_mailbox_data->alias);
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&(output_mailbox_data->unread_count));
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&(output_mailbox_data->total_mail_count_on_local));
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&(output_mailbox_data->total_mail_count_on_server));
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&(output_mailbox_data->hold_connection));
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&(output_mailbox_data->local));
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&(output_mailbox_data->synchronous));
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&(output_mailbox_data->account_id));
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&(output_mailbox_data->user_data));
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&(output_mailbox_data->mail_stream));
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&(output_mailbox_data->has_archived_mails));
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&(output_mailbox_data->mail_slot_size));
+ fetch_string_from_stream(input_stream, &stream_offset, &output_mailbox_data->account_name);
+ EM_DEBUG_FUNC_END();
+}
+
+
+EXPORT_API char* em_convert_mail_info_to_byte_stream(emf_mail_info_t *input_mail_info, int *output_stream_size)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ char *result_stream = NULL;
+ int stream_size = 0;
+ int mail_flag = 0;
+ int extra_flag_field = 0;
+
+ EM_IF_NULL_RETURN_VALUE(input_mail_info, NULL);
+ EM_IF_NULL_RETURN_VALUE(output_stream_size, NULL);
+
+ em_convert_mail_flag_to_int(input_mail_info->flags, &mail_flag, NULL);
+
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_mail_info->account_id), sizeof(int));
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_mail_info->uid), sizeof(int));
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_mail_info->rfc822_size), sizeof(int));
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_mail_info->body_downloaded), sizeof(int));
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(mail_flag), sizeof(int));
+ extra_flag_field = input_mail_info->extra_flags.priority;
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&extra_flag_field, sizeof(int));
+ extra_flag_field = input_mail_info->extra_flags.status;
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&extra_flag_field, sizeof(int));
+ extra_flag_field = input_mail_info->extra_flags.noti;
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&extra_flag_field, sizeof(int));
+ extra_flag_field = input_mail_info->extra_flags.lock;
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&extra_flag_field, sizeof(int));
+ extra_flag_field = input_mail_info->extra_flags.report;
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&extra_flag_field, sizeof(int));
+ extra_flag_field = input_mail_info->extra_flags.drm;
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&extra_flag_field, sizeof(int));
+ extra_flag_field = input_mail_info->extra_flags.text_download_yn;
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&extra_flag_field, sizeof(int));
+ result_stream = append_string_to_stream(result_stream, &stream_size, input_mail_info->sid);
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_mail_info->is_meeting_request), sizeof(int));
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_mail_info->thread_id), sizeof(int));
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_mail_info->thread_item_count), sizeof(int));
+
+ *output_stream_size = stream_size;
+
+ EM_DEBUG_FUNC_END();
+ return result_stream;
+}
+
+
+EXPORT_API void em_convert_byte_stream_to_mail_info(char *input_stream, emf_mail_info_t *output_mail_info)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ int stream_offset = 0;
+ int mail_flag = 0;
+ int extra_flag_field = 0;
+
+ EM_NULL_CHECK_FOR_VOID(input_stream);
+ EM_NULL_CHECK_FOR_VOID(output_mail_info);
+
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&(output_mail_info->account_id));
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&(output_mail_info->uid));
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&(output_mail_info->rfc822_size));
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&(output_mail_info->body_downloaded));
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&(mail_flag));
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&extra_flag_field);
+ output_mail_info->extra_flags.priority = extra_flag_field;
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&extra_flag_field);
+ output_mail_info->extra_flags.status = extra_flag_field;
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&extra_flag_field);
+ output_mail_info->extra_flags.noti = extra_flag_field;
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&extra_flag_field);
+ output_mail_info->extra_flags.lock = extra_flag_field;
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&extra_flag_field);
+ output_mail_info->extra_flags.report = extra_flag_field;
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&extra_flag_field);
+ output_mail_info->extra_flags.drm = extra_flag_field;
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&extra_flag_field);
+ output_mail_info->extra_flags.text_download_yn = extra_flag_field;
+ fetch_string_from_stream(input_stream, &stream_offset, &output_mail_info->sid);
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&(output_mail_info->is_meeting_request));
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&(output_mail_info->thread_id));
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&(output_mail_info->thread_item_count));
+
+
+ if (!em_convert_mail_int_to_flag(mail_flag, &(output_mail_info->flags), NULL))
+ EM_DEBUG_LOG(" INVALID FLAG PARAM ");
+
+ EM_DEBUG_FUNC_END();
+}
+
+EXPORT_API char* em_convert_option_to_byte_stream(emf_option_t* input_option, int* output_stream_size)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ char *result_stream = NULL;
+ int stream_size = 0;
+
+ EM_IF_NULL_RETURN_VALUE(input_option, NULL);
+
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_option->priority), sizeof(int));
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_option->keep_local_copy), sizeof(int));
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_option->req_delivery_receipt), sizeof(int));
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_option->req_read_receipt), sizeof(int));
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_option->download_limit), sizeof(int));
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_option->block_address), sizeof(int));
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_option->block_subject), sizeof(int));
+ result_stream = append_string_to_stream(result_stream, &stream_size, input_option->display_name_from);
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_option->reply_with_body), sizeof(int));
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_option->forward_with_files), sizeof(int));
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_option->add_myname_card), sizeof(int));
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_option->add_signature), sizeof(int));
+ result_stream = append_string_to_stream(result_stream, &stream_size, input_option->signature);
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_option->add_my_address_to_bcc), sizeof(int));
+ *output_stream_size = stream_size;
+
+ EM_DEBUG_FUNC_END();
+ return result_stream;
+
+}
+
+EXPORT_API void em_convert_byte_stream_to_option(char *input_stream, emf_option_t *output_option)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int stream_offset = 0;
+
+ EM_NULL_CHECK_FOR_VOID(input_stream);
+
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&(output_option->priority));
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&(output_option->keep_local_copy));
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&(output_option->req_delivery_receipt));
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&(output_option->req_read_receipt));
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&(output_option->download_limit));
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&(output_option->block_address));
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&(output_option->block_subject));
+ fetch_string_from_stream(input_stream, &stream_offset, &output_option->display_name_from);
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&(output_option->reply_with_body));
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&(output_option->forward_with_files));
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&(output_option->add_myname_card));
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&(output_option->add_signature));
+ fetch_string_from_stream(input_stream, &stream_offset, &output_option->signature);
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&(output_option->add_my_address_to_bcc));
+
+ EM_DEBUG_FUNC_END();
+}
+
+EXPORT_API char* em_convert_rule_to_byte_stream(emf_rule_t *input_rule, int *output_stream_size)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ char *result_stream = NULL;
+ int stream_size = 0;
+
+ EM_IF_NULL_RETURN_VALUE(input_rule, NULL);
+ EM_IF_NULL_RETURN_VALUE(output_stream_size, NULL);
+
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_rule->account_id), sizeof(int));
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_rule->filter_id), sizeof(int));
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_rule->type), sizeof(int));
+ result_stream = append_string_to_stream(result_stream, &stream_size, input_rule->value);
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_rule->faction), sizeof(int));
+ result_stream = append_string_to_stream(result_stream, &stream_size, input_rule->mailbox);
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_rule->flag1), sizeof(int));
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_rule->flag2), sizeof(int));
+
+ *output_stream_size = stream_size;
+
+ EM_DEBUG_FUNC_END();
+ return result_stream;
+}
+
+EXPORT_API void em_convert_byte_stream_to_rule(char *input_stream, emf_rule_t *output_rule)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int stream_offset = 0;
+
+ EM_NULL_CHECK_FOR_VOID(input_stream);
+ EM_NULL_CHECK_FOR_VOID(output_rule);
+
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&(output_rule->account_id));
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&(output_rule->filter_id));
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&(output_rule->type));
+ fetch_string_from_stream(input_stream, &stream_offset, &output_rule->value);
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&(output_rule->faction));
+ fetch_string_from_stream(input_stream, &stream_offset, &output_rule->mailbox);
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&(output_rule->flag1));
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&(output_rule->flag2));
+
+ EM_DEBUG_FUNC_END();
+}
+
+EXPORT_API char* em_convert_extra_flags_to_byte_stream(emf_extra_flag_t input_extra_flag, int *output_stream_size)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ char *result_stream = NULL;
+ int stream_size = 0;
+ int extra_flag_field = 0;
+
+ EM_IF_NULL_RETURN_VALUE(output_stream_size, NULL);
+
+ extra_flag_field = input_extra_flag.priority;
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&extra_flag_field, sizeof(int));
+ extra_flag_field = input_extra_flag.status;
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&extra_flag_field, sizeof(int));
+ extra_flag_field = input_extra_flag.noti;
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&extra_flag_field, sizeof(int));
+ extra_flag_field = input_extra_flag.lock;
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&extra_flag_field, sizeof(int));
+ extra_flag_field = input_extra_flag.report;
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&extra_flag_field, sizeof(int));
+ extra_flag_field = input_extra_flag.drm;
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&extra_flag_field, sizeof(int));
+ extra_flag_field = input_extra_flag.text_download_yn;
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&extra_flag_field, sizeof(int));
+
+ *output_stream_size = stream_size;
+
+ EM_DEBUG_FUNC_END();
+
+ return result_stream;
+}
+
+EXPORT_API void em_convert_byte_stream_to_extra_flags(char *input_stream, emf_extra_flag_t *output_extra_flag)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ int stream_offset = 0;
+ int extra_flag_field = 0;
+
+ EM_NULL_CHECK_FOR_VOID(input_stream);
+ EM_NULL_CHECK_FOR_VOID(output_extra_flag);
+
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&extra_flag_field);
+ output_extra_flag->priority = extra_flag_field;
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&extra_flag_field);
+ output_extra_flag->status = extra_flag_field;
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&extra_flag_field);
+ output_extra_flag->noti = extra_flag_field;
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&extra_flag_field);
+ output_extra_flag->lock = extra_flag_field;
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&extra_flag_field);
+ output_extra_flag->report = extra_flag_field;
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&extra_flag_field);
+ output_extra_flag->drm = extra_flag_field;
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&extra_flag_field);
+ output_extra_flag->text_download_yn = extra_flag_field;
+
+ EM_DEBUG_FUNC_END();
+}
+
+EXPORT_API char* em_convert_meeting_req_to_byte_stream(emf_meeting_request_t *input_meeting_req, int *output_stream_size)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ char *result_stream = NULL;
+ int stream_size = 0;
+
+ EM_IF_NULL_RETURN_VALUE(input_meeting_req, NULL);
+
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_meeting_req->mail_id), sizeof(int));
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_meeting_req->meeting_response), sizeof(int));
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_meeting_req->start_time), sizeof(struct tm));
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_meeting_req->end_time), sizeof(struct tm));
+ result_stream = append_string_to_stream(result_stream, &stream_size, input_meeting_req->location);
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&input_meeting_req->global_object_id, MEETING_REQ_OBJECT_ID_LENGTH);
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_meeting_req->time_zone.offset_from_GMT), sizeof(int));
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&input_meeting_req->time_zone.standard_name, 32);
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_meeting_req->time_zone.standard_time_start_date), sizeof(struct tm));
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_meeting_req->time_zone.standard_bias), sizeof(int));
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&input_meeting_req->time_zone.daylight_name, 32);
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_meeting_req->time_zone.daylight_time_start_date), sizeof(struct tm));
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_meeting_req->time_zone.daylight_bias), sizeof(int));
+
+ *output_stream_size = stream_size;
+
+ EM_DEBUG_FUNC_END();
+ return result_stream;
+}
+
+
+EXPORT_API void em_convert_byte_stream_to_meeting_req(char *input_stream, emf_meeting_request_t *output_meeting_req)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int stream_offset = 0;
+
+ EM_NULL_CHECK_FOR_VOID(input_stream);
+ EM_NULL_CHECK_FOR_VOID(output_meeting_req);
+
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&(output_meeting_req->mail_id));
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&(output_meeting_req->meeting_response));
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(struct tm), (char*)&(output_meeting_req->start_time));
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(struct tm), (char*)&(output_meeting_req->end_time));
+ fetch_string_from_stream(input_stream, &stream_offset, &output_meeting_req->location);
+ fetch_sized_data_from_stream(input_stream, &stream_offset, MEETING_REQ_OBJECT_ID_LENGTH, output_meeting_req->global_object_id);
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&(output_meeting_req->time_zone.offset_from_GMT));
+ fetch_sized_data_from_stream(input_stream, &stream_offset, 32, output_meeting_req->time_zone.standard_name);
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(struct tm), (char*)&(output_meeting_req->time_zone.standard_time_start_date));
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&(output_meeting_req->time_zone.standard_bias));
+ fetch_sized_data_from_stream(input_stream, &stream_offset, 32, output_meeting_req->time_zone.daylight_name);
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(struct tm), (char*)&(output_meeting_req->time_zone.daylight_time_start_date));
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&(output_meeting_req->time_zone.daylight_bias));
+
+ EM_DEBUG_FUNC_END();
+}
+
diff --git a/Common/include/Msg_Convert.h b/Common/include/Msg_Convert.h
new file mode 100755
index 0000000..3edc269
--- /dev/null
+++ b/Common/include/Msg_Convert.h
@@ -0,0 +1,93 @@
+/*
+* email-service
+*
+* Copyright (c) 2000 - 2011 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.
+*
+*/
+
+
+#include "emflib.h"
+#include <time.h>
+#include "emf-dbglog.h"
+#include "em-storage.h"
+
+/* Account */
+EXPORT_API char* em_convert_account_to_byte_stream(emf_account_t* account, int* nStreamSize);
+EXPORT_API void em_convert_byte_stream_to_account(char* pAccountStream, emf_account_t* account);
+EXPORT_API int em_convert_account_to_account_tbl(emf_account_t *account, emf_mail_account_tbl_t *account_tbl);
+EXPORT_API int em_convert_account_tbl_to_account(emf_mail_account_tbl_t *account_tbl, emf_account_t *account);
+
+
+/* Mail */
+EXPORT_API char* em_convert_mail_to_byte_stream(emf_mail_t* mail, int* nStreamSize);
+EXPORT_API void em_convert_byte_stream_to_mail(char* pStream, emf_mail_t* mail);
+
+EXPORT_API char* em_convert_mail_head_to_byte_stream(emf_mail_head_t* mail_head, int* nStreamSize);
+EXPORT_API void em_convert_byte_stream_to_mail_head(char* pStream, emf_mail_head_t* mail_head);
+
+EXPORT_API char* em_convert_mail_body_to_byte_stream(emf_mail_body_t* mail_body, int* nStreamSize);
+EXPORT_API void em_convert_byte_stream_to_mail_body(char* pStream, emf_mail_body_t* mail_body);
+
+EXPORT_API char* em_convert_mail_info_to_byte_stream(emf_mail_info_t* mail_info, int* nStreamSize);
+EXPORT_API void em_convert_byte_stream_to_mail_info(char* pStream, emf_mail_info_t* mail_info);
+
+EXPORT_API char* em_convert_mail_data_to_byte_stream(emf_mail_data_t *input_mail_data, int intput_mail_data_count, int *output_stream_size);
+EXPORT_API void em_convert_byte_stream_to_mail_data(char *intput_stream, emf_mail_data_t **output_mail_data, int *output_mail_data_count);
+
+EXPORT_API int em_convert_mail_tbl_to_mail(emf_mail_tbl_t *mail_table_data, emf_mail_t *mail_data);
+
+EXPORT_API int em_convert_mail_tbl_to_mail_data(emf_mail_tbl_t *mail_table_data, int item_count, emf_mail_data_t **mail_data, int *error);
+EXPORT_API int em_convert_mail_data_to_mail_tbl(emf_mail_data_t *mail_data, int item_count, emf_mail_tbl_t **mail_table_data, int *error);
+
+/* Attachment */
+EXPORT_API char* em_convert_attachment_data_to_byte_stream(emf_attachment_data_t *input_attachment_data, int intput_attachment_count, int* output_stream_size);
+EXPORT_API void em_convert_byte_stream_to_attachment_data(char *intput_stream, emf_attachment_data_t **output_attachment_data, int *output_attachment_count);
+
+EXPORT_API char* em_convert_attachment_info_to_byte_stream(emf_attachment_info_t* mail_atch, int* nStreamSize);
+EXPORT_API void em_convert_byte_stream_to_attachment_info(char* pStream, int attachment_num, emf_attachment_info_t** mail_atch);
+
+
+/* Mailbox */
+EXPORT_API char* em_convert_mailbox_to_byte_stream(emf_mailbox_t* pMailbox, int* nStreamSize);
+EXPORT_API void em_convert_byte_stream_to_mailbox(char* pStream, emf_mailbox_t* pMailbox);
+
+
+/* Rule */
+EXPORT_API char* em_convert_rule_to_byte_stream(emf_rule_t* pRule, int* nStreamSize);
+EXPORT_API void em_convert_byte_stream_to_rule(char* pStream, emf_rule_t* pMailbox);
+
+/* Sending options */
+EXPORT_API char* em_convert_option_to_byte_stream(emf_option_t* pOption, int* nStreamSize);
+EXPORT_API void em_convert_byte_stream_to_option(char* pStream, emf_option_t* pOption);
+
+EXPORT_API int em_convert_string_to_datetime(char *datetime_str, emf_datetime_t *datetime, int *err_code);
+EXPORT_API int em_convert_datetime_to_string(emf_datetime_t *input_datetime, char **output_datetime_str, int *err_code);
+
+
+EXPORT_API char* em_convert_extra_flags_to_byte_stream(emf_extra_flag_t new_flag, int* StreamSize);
+EXPORT_API void em_convert_byte_stream_to_extra_flags(char* pStream, emf_extra_flag_t* new_flag);
+
+EXPORT_API char* em_convert_meeting_req_to_byte_stream(emf_meeting_request_t* meeting_req, int* nStreamSize);
+EXPORT_API void em_convert_byte_stream_to_meeting_req(char* pStream, emf_meeting_request_t* meeting_req);
+
+EXPORT_API int em_convert_mail_flag_to_int(emf_mail_flag_t flag, int* i_flag, int* err_code);
+EXPORT_API int em_convert_mail_int_to_flag(int i_flag, emf_mail_flag_t* flag, int* err_code);
+EXPORT_API int em_convert_mail_status_to_mail_tbl(int mail_status, emf_mail_tbl_t *result_mail_tbl_data, int* err_code);
+EXPORT_API int em_convert_mail_tbl_to_mail_status(emf_mail_tbl_t *mail_tbl_data, int *result_mail_status, int* err_code);
+EXPORT_API int em_convert_mail_tbl_to_mail_flag(emf_mail_tbl_t *mail_tbl_data, emf_mail_flag_t *result_flag, int* err_code);
+EXPORT_API int em_convert_mail_flag_to_mail_tbl(emf_mail_flag_t *flag, emf_mail_tbl_t *result_mail_tbl_data, int* err_code);
+
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..f94008a
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,206 @@
+Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ 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.
+
+
+
diff --git a/MAPI/CMakeLists.txt b/MAPI/CMakeLists.txt
new file mode 100755
index 0000000..f27ab32
--- /dev/null
+++ b/MAPI/CMakeLists.txt
@@ -0,0 +1,78 @@
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+PROJECT(email-api)
+
+SET(CMAKE_SKIP_BUILD_RPATH TRUE)
+
+IF("${CMAKE_BUILD_TYPE}" STREQUAL "")
+ SET(CMAKE_BUILD_TYPE "Debug")
+ENDIF("${CMAKE_BUILD_TYPE}" STREQUAL "")
+
+MESSAGE("")
+MESSAGE(">>> current directory: ${CMAKE_CURRENT_SOURCE_DIR}")
+MESSAGE(">>> Build type: ${CMAKE_BUILD_TYPE}")
+
+
+SET(VISIBILITY "-DEXPORT_API=\"__attribute__((visibility(\\\"default\\\")))\"")
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${VISIBILITY} -fvisibility=hidden")
+
+##########################################################
+# Define Email API
+##########################################################
+
+SET(API-LIB "email-api")
+SET(API-SRCS
+ ${CMAKE_SOURCE_DIR}/MAPI/Emf_Mapi_Account.c
+ ${CMAKE_SOURCE_DIR}/MAPI/Emf_Mapi_Message.c
+ ${CMAKE_SOURCE_DIR}/MAPI/Emf_Mapi_Network.c
+ ${CMAKE_SOURCE_DIR}/MAPI/Emf_Mapi_Rule.c
+ ${CMAKE_SOURCE_DIR}/MAPI/Emf_Mapi_Mailbox.c
+ ${CMAKE_SOURCE_DIR}/MAPI/Emf_Mapi_Types.c
+ ${CMAKE_SOURCE_DIR}/MAPI/Emf_Mapi_Init.c
+)
+
+INCLUDE_DIRECTORIES(
+ ${CMAKE_SOURCE_DIR}/include
+ ${CMAKE_SOURCE_DIR}/ipc/include
+ ${CMAKE_SOURCE_DIR}/MAPI/include
+ ${CMAKE_SOURCE_DIR}/email-core/em-storage/include
+ ${CMAKE_SOURCE_DIR}/ipc/socket/include
+ ${CMAKE_SOURCE_DIR}/Common/include
+ ${CMAKE_SOURCE_DIR}/email-core/include
+)
+
+INCLUDE(FindPkgConfig)
+pkg_check_modules(api_pkgs REQUIRED glib-2.0 dlog dbus-1 vconf heynoti db-util contacts-service uw-imap-toolkit)
+
+FOREACH(flag ${api_pkgs_CFLAGS})
+ SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
+
+SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed")
+
+ADD_LIBRARY(${API-LIB} SHARED ${API-SRCS})
+
+TARGET_LINK_LIBRARIES(${API-LIB} ${api_pkgs_LDFLAGS} email-ipc email-storage email-core email-base email-network)
+#${NETWORK-LIB} ${CORE-LIB} ${STORAGE-LIB} ${IPC-LIB} ${BASE-LIB})
+
+SET_TARGET_PROPERTIES(${API-LIB} PROPERTIES SOVERSION ${VERSION_MAJOR})
+SET_TARGET_PROPERTIES(${API-LIB} PROPERTIES VERSION ${VERSION})
+
+#INSTALL(TARGETS ${API-LIB} LIBRARY DESTINATION lib)
+INSTALL(TARGETS ${API-LIB} DESTINATION lib COMPONENT RuntimeLibraries)
+
+SET(MAPI-HEADERS
+ ${CMAKE_SOURCE_DIR}/MAPI/include/Emf_Mapi.h
+ ${CMAKE_SOURCE_DIR}/MAPI/include/Emf_Mapi_Account.h
+ ${CMAKE_SOURCE_DIR}/MAPI/include/Emf_Mapi_Message.h
+ ${CMAKE_SOURCE_DIR}/MAPI/include/Emf_Mapi_Mailbox.h
+ ${CMAKE_SOURCE_DIR}/MAPI/include/Emf_Mapi_Rule.h
+ ${CMAKE_SOURCE_DIR}/MAPI/include/Emf_Mapi_Init.h
+ ${CMAKE_SOURCE_DIR}/MAPI/include/Emf_Mapi_Types.h
+ ${CMAKE_SOURCE_DIR}/MAPI/include/Emf_Mapi_Network.h
+ ${CMAKE_SOURCE_DIR}/include/emf-types.h
+)
+
+INSTALL(FILES ${MAPI-HEADERS} DESTINATION include/email-service)
+
diff --git a/MAPI/Emf_Mapi_Account.c b/MAPI/Emf_Mapi_Account.c
new file mode 100755
index 0000000..4db5232
--- /dev/null
+++ b/MAPI/Emf_Mapi_Account.c
@@ -0,0 +1,665 @@
+/*
+* email-service
+*
+* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+*
+* Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com>
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*
+*/
+
+
+/**
+ *
+ * This file contains the data structures and interfaces needed for application,
+ * to interact with Email Engine.
+ * @file Emf_Mapi_Account.c
+ * @brief This file contains the data structures and interfaces of Account related Functionality provided by
+ * Email Engine .
+ */
+
+#include <Emf_Mapi.h>
+#include "string.h"
+#include "Msg_Convert.h"
+#include "Emf_Mapi_Account.h"
+#include "em-storage.h"
+#include "em-core-mesg.h"
+#include "em-core-account.h"
+#include "em-core-utils.h"
+#include "ipc-library.h"
+
+/* API - Adds the Email Account */
+EXPORT_API int email_add_account(emf_account_t* account)
+{
+ EM_DEBUG_FUNC_BEGIN("account[%p]", account);
+ char* local_account_stream = NULL;
+ int ret = -1;
+ int size = 0;
+ int account_id;
+ int err = EMF_ERROR_NONE;
+
+ if ( !account ) {
+ EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
+ return EMF_ERROR_INVALID_PARAM;
+ }
+
+ HIPC_API hAPI = ipcEmailAPI_Create(_EMAIL_API_ADD_ACCOUNT);
+
+ EM_IF_NULL_RETURN_VALUE(hAPI, EMF_ERROR_NULL_VALUE);
+
+ local_account_stream = em_convert_account_to_byte_stream(account, &size);
+
+ EM_PROXY_IF_NULL_RETURN_VALUE(local_account_stream, hAPI, EMF_ERROR_NULL_VALUE);
+
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, local_account_stream, size))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed");
+
+ EM_DEBUG_LOG("APPID[%d], APIID [%d]", ipcEmailAPI_GetAPPID(hAPI), ipcEmailAPI_GetAPIID(hAPI));
+
+ if(!ipcEmailProxy_ExecuteAPI(hAPI)) {
+ EM_DEBUG_EXCEPTION("ipcEmailProxy_ExecuteAPI failed");
+ EM_SAFE_FREE(local_account_stream);
+ EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMF_ERROR_IPC_SOCKET_FAILURE);
+ }
+
+ ret = *(int*)ipcEmailAPI_GetParameter(hAPI, ePARAMETER_OUT, 0);
+ if(ret == 1) {
+ account_id = *(int*)ipcEmailAPI_GetParameter(hAPI, ePARAMETER_OUT, 1);
+ EM_DEBUG_LOG("APPID[%d], APIID [%d]", ipcEmailAPI_GetAPPID(hAPI), ipcEmailAPI_GetAPIID(hAPI));
+ account->account_id = account_id;
+ } else { /* get error code */
+ err = *(int*)ipcEmailAPI_GetParameter(hAPI, ePARAMETER_OUT, 1);
+ }
+
+ ipcEmailAPI_Destroy(hAPI);
+ hAPI = NULL;
+
+ EM_SAFE_FREE(local_account_stream);
+ EM_DEBUG_FUNC_END("RETURN VALUE [%d], ERROR CODE [%d]", ret, err);
+ return err;
+}
+
+
+EXPORT_API int email_free_account(emf_account_t** account_list, int count)
+{
+ EM_DEBUG_FUNC_BEGIN("account_list[%p], count[%d]", account_list, count);
+
+ /* default variable */
+ int err = EMF_ERROR_NONE;
+
+ if (count > 0) {
+ if (!account_list || !*account_list) {
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+ emf_account_t* p = *account_list;
+ int i;
+
+ for (i = 0; i < count; i++) {
+ EM_SAFE_FREE(p[i].account_name);
+ EM_SAFE_FREE(p[i].receiving_server_addr);
+ EM_SAFE_FREE(p[i].email_addr);
+ EM_SAFE_FREE(p[i].user_name);
+ EM_SAFE_FREE(p[i].password);
+ EM_SAFE_FREE(p[i].sending_server_addr);
+ EM_SAFE_FREE(p[i].sending_user);
+ EM_SAFE_FREE(p[i].sending_password);
+ EM_SAFE_FREE(p[i].display_name);
+ EM_SAFE_FREE(p[i].reply_to_addr);
+ EM_SAFE_FREE(p[i].return_addr);
+ EM_SAFE_FREE(p[i].logo_icon_path);
+ EM_SAFE_FREE(p[i].options.display_name_from);
+ EM_SAFE_FREE(p[i].options.signature);
+ }
+ free(p); *account_list = NULL;
+ }
+
+FINISH_OFF:
+ EM_DEBUG_FUNC_END("ERROR CODE [%d]", err);
+ return err;
+}
+
+
+/* API - Delete the Email Account */
+EXPORT_API int email_delete_account(int account_id)
+{
+ EM_DEBUG_FUNC_BEGIN("account_id[%d]", account_id);
+
+ int ret = 0;
+ int err = EMF_ERROR_NONE;
+
+ if (account_id < 0 || account_id == 0) {
+ EM_DEBUG_EXCEPTION(" account_id[%d]", account_id);
+ err = EMF_ERROR_INVALID_PARAM;
+ return err;
+ }
+
+ HIPC_API hAPI = ipcEmailAPI_Create(_EMAIL_API_DELETE_ACCOUNT);
+
+ EM_IF_NULL_RETURN_VALUE(hAPI, EMF_ERROR_NULL_VALUE);
+
+ /* account_id */
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, (char*)&account_id, sizeof(int)))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter account_id failed ");
+
+ if(!ipcEmailProxy_ExecuteAPI(hAPI)) {
+ EM_DEBUG_EXCEPTION("ipcEmailProxy_ExecuteAPI failed ");
+ EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMF_ERROR_IPC_SOCKET_FAILURE);
+ }
+
+ ret = *(int*)ipcEmailAPI_GetParameter(hAPI, ePARAMETER_OUT, 0);
+ if(0==ret) { /* get error code */
+ err = *(int*)ipcEmailAPI_GetParameter(hAPI, ePARAMETER_OUT, 1);
+ }
+ ipcEmailAPI_Destroy(hAPI);
+
+ hAPI = NULL;
+ EM_DEBUG_FUNC_END("RETURN VALUE [%d], ERROR CODE [%d]", ret, err);
+ return err;
+}
+
+/* API - Update the Email Account */
+EXPORT_API int email_update_account(int account_id, emf_account_t* new_account)
+{
+ EM_DEBUG_FUNC_BEGIN("account_id[%d], new_account[%p]", account_id, new_account);
+
+ int ret = 0;
+ int size = 0;
+ int err = EMF_ERROR_NONE;
+ int with_validation = false, *result_from_ipc = NULL;
+ char* new_account_stream = NULL;
+
+ if ((account_id <= 0) || !new_account || (with_validation != false && with_validation != true)) {
+ EM_DEBUG_EXCEPTION("account_id[%d], new_account[%p], with_validation[%d]", account_id, new_account, with_validation);
+ err = EMF_ERROR_INVALID_PARAM;
+ return err;
+ }
+
+ HIPC_API hAPI = ipcEmailAPI_Create(_EMAIL_API_UPDATE_ACCOUNT);
+
+ EM_IF_NULL_RETURN_VALUE(hAPI, EMF_ERROR_NULL_VALUE);
+
+ /* account_id */
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, (char*)&account_id, sizeof(int)))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter account_id failed ");
+
+ /* new_account */
+ new_account_stream = em_convert_account_to_byte_stream(new_account, &size);
+
+ EM_PROXY_IF_NULL_RETURN_VALUE(new_account_stream, hAPI, EMF_ERROR_NULL_VALUE);
+
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, new_account_stream, size))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter new_account failed ");
+
+ /* with_validation */
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, (char*)&with_validation, sizeof(int)))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter with_validation failed ");
+
+ if(!ipcEmailProxy_ExecuteAPI(hAPI)) {
+ EM_DEBUG_EXCEPTION("ipcEmailProxy_ExecuteAPI failed");
+ /* Prevent defect 18624 */
+ EM_SAFE_FREE(new_account_stream);
+ EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMF_ERROR_IPC_SOCKET_FAILURE);
+ }
+
+ result_from_ipc = (int*)ipcEmailAPI_GetParameter(hAPI, ePARAMETER_OUT, 0);
+
+ if(!result_from_ipc) {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_GetParameter fail ");
+ err = EMF_ERROR_IPC_CRASH;
+ goto FINISH_OFF;
+ }
+
+ ret = *result_from_ipc;
+
+ if(ret == 0) { /* get error code */
+ result_from_ipc = (int*)ipcEmailAPI_GetParameter(hAPI, ePARAMETER_OUT, 1);
+ if(!result_from_ipc) {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_GetParameter fail ");
+ err = EMF_ERROR_IPC_CRASH;
+ goto FINISH_OFF;
+ }
+
+ err = *result_from_ipc;
+ }
+
+FINISH_OFF:
+
+ ipcEmailAPI_Destroy(hAPI);
+ hAPI = NULL;
+
+ EM_SAFE_FREE(new_account_stream);
+ EM_DEBUG_FUNC_END("RETURN VALUE [%d], ERROR CODE [%d]", ret, err);
+ return err;
+}
+
+/* API - Update the Email Account */
+EXPORT_API int email_update_account_with_validation(int account_id, emf_account_t* new_account)
+{
+ EM_DEBUG_FUNC_BEGIN("account_id[%d], new_account[%p]", account_id, new_account);
+
+ int ret = 0;
+ int size = 0;
+ int err = EMF_ERROR_NONE;
+ int with_validation = true;
+ char* new_account_stream = NULL;
+
+ if ((account_id <= 0) || !new_account || (with_validation != false && with_validation != true)) {
+ EM_DEBUG_EXCEPTION(" account_id[%d], new_account[%p], with_validation[%d]", account_id, new_account, with_validation);
+ err = EMF_ERROR_INVALID_PARAM;
+ return err;
+ }
+
+ HIPC_API hAPI = ipcEmailAPI_Create(_EMAIL_API_UPDATE_ACCOUNT);
+
+ EM_IF_NULL_RETURN_VALUE(hAPI, EMF_ERROR_NULL_VALUE);
+
+ /* account_id */
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, (char*)&account_id, sizeof(int)))
+ EM_DEBUG_EXCEPTION("email_update_account--ipcEmailAPI_AddParameter account_id failed ");
+
+ /* new_account */
+ new_account_stream = em_convert_account_to_byte_stream(new_account, &size);
+
+ EM_PROXY_IF_NULL_RETURN_VALUE(new_account_stream, hAPI, EMF_ERROR_NULL_VALUE);
+
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, new_account_stream, size))
+ EM_DEBUG_EXCEPTION("email_update_account--ipcEmailAPI_AddParameter new_account failed ");
+
+ /* with_validation */
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, (char*)&with_validation, sizeof(int)))
+ EM_DEBUG_EXCEPTION("email_update_account--ipcEmailAPI_AddParameter with_validation failed ");
+
+
+ if(!ipcEmailProxy_ExecuteAPI(hAPI)) {
+ EM_DEBUG_EXCEPTION("email_update_account--ipcEmailProxy_ExecuteAPI failed ");
+ /* Prevent defect 18624 */
+ EM_SAFE_FREE(new_account_stream);
+ EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMF_ERROR_IPC_SOCKET_FAILURE);
+ }
+
+ ret = *(int*)ipcEmailAPI_GetParameter(hAPI, ePARAMETER_OUT, 0);
+ if(ret == 0) { /* get error code */
+ err = *(int*)ipcEmailAPI_GetParameter(hAPI, ePARAMETER_OUT, 1);
+ }
+
+ ipcEmailAPI_Destroy(hAPI);
+ hAPI = NULL;
+
+ EM_SAFE_FREE(new_account_stream);
+ EM_DEBUG_FUNC_END("RETURN VALUE [%d], ERROR CODE [%d]", ret, err);
+ return err;
+
+
+}
+
+
+/* API - Get the account Information based on the account ID */
+EXPORT_API int email_get_account(int account_id, int pulloption, emf_account_t** account)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int ret = 0;
+ int err = EMF_ERROR_NONE;
+ emf_mail_account_tbl_t *account_tbl = NULL;
+
+ EM_IF_NULL_RETURN_VALUE(account_id, EMF_ERROR_INVALID_PARAM);
+ EM_IF_NULL_RETURN_VALUE(account, EMF_ERROR_INVALID_PARAM);
+
+ if (pulloption == GET_FULL_DATA)
+ pulloption = EMF_ACC_GET_OPT_FULL_DATA;
+
+ if (pulloption & EMF_ACC_GET_OPT_PASSWORD) {
+ pulloption = pulloption & (~(EMF_ACC_GET_OPT_PASSWORD)); /* disable password -Can't obtain password by MAPI */
+ EM_DEBUG_LOG("change pulloption : disable password");
+ }
+
+ if (!em_storage_get_account_by_id(account_id, pulloption, &account_tbl, true, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_get_account_by_id failed - %d", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+
+ *account = em_core_malloc(sizeof(emf_account_t));
+ if (!*account) {
+ EM_DEBUG_EXCEPTION("allocation failed [%d]", err);
+ goto FINISH_OFF;
+ }
+ memset((void*)*account, 0, sizeof(emf_account_t));
+ em_convert_account_tbl_to_account(account_tbl, *account);
+
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ ret = true;
+
+FINISH_OFF:
+ if (account_tbl)
+ em_storage_free_account(&account_tbl, 1, NULL);
+
+ EM_DEBUG_FUNC_END();
+ return err;
+}
+
+EXPORT_API int email_get_account_list(emf_account_t** account_list, int* count)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ int err = EMF_ERROR_NONE, i = 0;
+ emf_mail_account_tbl_t *temp_account_tbl = NULL;
+
+ EM_IF_NULL_RETURN_VALUE(account_list, EMF_ERROR_INVALID_PARAM);
+ EM_IF_NULL_RETURN_VALUE(count, EMF_ERROR_INVALID_PARAM);
+
+ if (!em_storage_get_account_list(count, &temp_account_tbl , true, false, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_get_account_list failed [%d]", err);
+
+ goto FINISH_OFF;
+ }
+
+ if(temp_account_tbl && (*count) > 0) {
+ *account_list = em_core_malloc(sizeof(emf_account_t) * (*count));
+ if(!*account_list) {
+ EM_DEBUG_EXCEPTION("allocation failed [%d]", err);
+ goto FINISH_OFF;
+ }
+ memset((void*)*account_list, 0, sizeof(emf_account_t) * (*count));
+ for(i = 0; i < (*count); i++)
+ em_convert_account_tbl_to_account(temp_account_tbl + i, (*account_list) + i);
+ }
+
+FINISH_OFF:
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+
+ if(temp_account_tbl)
+ em_storage_free_account(&temp_account_tbl, (*count), NULL);
+ EM_DEBUG_FUNC_END("err[%d]", err);
+ return err;
+
+}
+
+EXPORT_API int email_validate_account(int account_id, unsigned* handle)
+{
+ EM_DEBUG_FUNC_BEGIN("account_id[%d], handle[%p]", account_id, handle);
+
+ int ret = 0;
+ int err = EMF_ERROR_NONE;
+ if (account_id <= 0) {
+ EM_DEBUG_EXCEPTION("account_id[%d]", account_id);
+ err = EMF_ERROR_INVALID_PARAM;
+ return err;
+ }
+
+ HIPC_API hAPI = ipcEmailAPI_Create(_EMAIL_API_VALIDATE_ACCOUNT);
+
+ EM_IF_NULL_RETURN_VALUE(hAPI, EMF_ERROR_NULL_VALUE);
+
+ /* account_id */
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, (char*)&account_id, sizeof(int)))
+ EM_DEBUG_EXCEPTION(" ipcEmailAPI_AddParameter account_id failed ");
+
+ if(!ipcEmailProxy_ExecuteAPI(hAPI)) {
+ EM_DEBUG_EXCEPTION(" ipcEmailProxy_ExecuteAPI failed ");
+ EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMF_ERROR_IPC_SOCKET_FAILURE);
+ }
+
+ ret = *(int*)ipcEmailAPI_GetParameter(hAPI, ePARAMETER_OUT, 0); /* return */
+ err = *(int*)ipcEmailAPI_GetParameter(hAPI, ePARAMETER_OUT, 1); /* error code */
+
+ if(handle)
+ *handle = *(int*)ipcEmailAPI_GetParameter(hAPI, ePARAMETER_OUT, 2);
+
+ ipcEmailAPI_Destroy(hAPI);
+
+ hAPI = NULL;
+ EM_DEBUG_FUNC_END("err[%d]", err);
+ return err;
+
+}
+
+
+EXPORT_API int email_add_account_with_validation(emf_account_t* account, unsigned* handle)
+{
+ EM_DEBUG_FUNC_BEGIN("account[%p]", account);
+ char* local_account_stream = NULL;
+ int ret = -1;
+ int size = 0;
+ int handle_inst = 0;
+ int err = EMF_ERROR_NONE;
+
+ EM_IF_NULL_RETURN_VALUE(account, false);
+
+ if(em_storage_check_duplicated_account(account, true, &err) == false) {
+ EM_DEBUG_EXCEPTION("em_storage_check_duplicated_account failed (%d) ", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ return err;
+ }
+
+ HIPC_API hAPI = ipcEmailAPI_Create(_EMAIL_API_ADD_ACCOUNT_WITH_VALIDATION);
+
+ EM_IF_NULL_RETURN_VALUE(hAPI, EMF_ERROR_NULL_VALUE);
+
+ EM_DEBUG_LOG("Before em_convert_account_to_byte_stream");
+ local_account_stream = em_convert_account_to_byte_stream(account, &size);
+
+ EM_PROXY_IF_NULL_RETURN_VALUE(local_account_stream, hAPI, EMF_ERROR_NULL_VALUE);
+
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, local_account_stream, size))
+ EM_DEBUG_EXCEPTION(" ipcEmailAPI_AddParameter failed ");
+
+ if(!ipcEmailProxy_ExecuteAPI(hAPI)) {
+ EM_DEBUG_EXCEPTION(" ipcEmailProxy_ExecuteAPI failed ");
+ EM_SAFE_FREE(local_account_stream);
+ EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMF_ERROR_IPC_SOCKET_FAILURE);
+ }
+
+ ret = *(int*)ipcEmailAPI_GetParameter(hAPI, ePARAMETER_OUT, 0);
+ if(ret == 1) {
+ handle_inst = *(int*)ipcEmailAPI_GetParameter(hAPI, ePARAMETER_OUT, 1);
+ if(handle)
+ *handle = handle_inst;
+ } else { /* get error code */
+ err = *(int*)ipcEmailAPI_GetParameter(hAPI, ePARAMETER_OUT, 1);
+ }
+
+ ipcEmailAPI_Destroy(hAPI);
+ hAPI = NULL;
+
+ EM_SAFE_FREE(local_account_stream);
+ EM_DEBUG_FUNC_END("err[%d]", err);
+ return err;
+}
+
+
+EXPORT_API int email_backup_accounts_into_secure_storage(const char *file_name)
+{
+ EM_DEBUG_FUNC_BEGIN("file_name[%s]", file_name);
+ int ret = 0;
+ int err = EMF_ERROR_NONE;
+
+ if (!file_name) {
+ EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
+ err = EMF_ERROR_INVALID_PARAM;
+ return err;
+ }
+
+ HIPC_API hAPI = ipcEmailAPI_Create(_EMAIL_API_BACKUP_ACCOUNTS);
+
+ EM_IF_NULL_RETURN_VALUE(hAPI, EMF_ERROR_NULL_VALUE);
+
+ /* file_name */
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, (char*)file_name, strlen(file_name)))
+ EM_DEBUG_EXCEPTION(" ipcEmailAPI_AddParameter account_id failed ");
+
+ if(!ipcEmailProxy_ExecuteAPI(hAPI)) {
+ EM_DEBUG_EXCEPTION(" ipcEmailProxy_ExecuteAPI failed ");
+ EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMF_ERROR_IPC_SOCKET_FAILURE);
+ }
+
+ ret = *(int*)ipcEmailAPI_GetParameter(hAPI, ePARAMETER_OUT, 0);
+
+ if(0 == ret) { /* get error code */
+ err = *(int*)ipcEmailAPI_GetParameter(hAPI, ePARAMETER_OUT, 1);
+ }
+
+ ipcEmailAPI_Destroy(hAPI);
+
+ hAPI = NULL;
+ EM_DEBUG_FUNC_END("err[%d]", err);
+ return err;
+}
+
+EXPORT_API int email_restore_accounts_from_secure_storage(const char * file_name)
+{
+ EM_DEBUG_FUNC_BEGIN("file_name[%s]", file_name);
+ int ret = 0;
+ int err = EMF_ERROR_NONE;
+
+ if (!file_name) {
+ EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
+ err = EMF_ERROR_INVALID_PARAM;
+ return err;
+ }
+
+ HIPC_API hAPI = ipcEmailAPI_Create(_EMAIL_API_RESTORE_ACCOUNTS);
+
+ EM_IF_NULL_RETURN_VALUE(hAPI, EMF_ERROR_NULL_VALUE);
+
+ /* file_name */
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, (char*)file_name, strlen(file_name)))
+ EM_DEBUG_EXCEPTION(" ipcEmailAPI_AddParameter account_id failed ");
+
+ if(!ipcEmailProxy_ExecuteAPI(hAPI)) {
+ EM_DEBUG_EXCEPTION(" ipcEmailProxy_ExecuteAPI failed ");
+ EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMF_ERROR_IPC_SOCKET_FAILURE);
+ }
+
+ ret = *(int*)ipcEmailAPI_GetParameter(hAPI, ePARAMETER_OUT, 0);
+
+ if(0==ret) { /* get error code */
+ err = *(int*)ipcEmailAPI_GetParameter(hAPI, ePARAMETER_OUT, 1);
+ }
+
+ ipcEmailAPI_Destroy(hAPI);
+
+ hAPI = NULL;
+ EM_DEBUG_FUNC_END("err[%d]", err);
+ return err;
+}
+
+EXPORT_API int email_get_password_length_of_account(const int account_id, int *password_length)
+{
+ EM_DEBUG_FUNC_BEGIN("account_id[%d], password_length[%p]", account_id, password_length);
+ int ret = 0;
+ int err = EMF_ERROR_NONE;
+
+ if (account_id <= 0 || password_length == NULL) {
+ EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
+ err = EMF_ERROR_INVALID_PARAM;
+ return err;
+ }
+
+ HIPC_API hAPI = ipcEmailAPI_Create(_EMAIL_API_GET_PASSWORD_LENGTH_OF_ACCOUNT);
+
+ EM_IF_NULL_RETURN_VALUE(hAPI, EMF_ERROR_NULL_VALUE);
+
+ /* account_id */
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, (char*)&account_id, sizeof(int)))
+ EM_DEBUG_EXCEPTION(" ipcEmailAPI_AddParameter account_id failed ");
+
+ if(!ipcEmailProxy_ExecuteAPI(hAPI)) {
+ EM_DEBUG_EXCEPTION(" ipcEmailProxy_ExecuteAPI failed ");
+ EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMF_ERROR_IPC_SOCKET_FAILURE);
+ }
+
+ ret = *(int*)ipcEmailAPI_GetParameter(hAPI, ePARAMETER_OUT, 0); /* return */
+ err = *(int*)ipcEmailAPI_GetParameter(hAPI, ePARAMETER_OUT, 1); /* error code */
+
+ *password_length = *(int*)ipcEmailAPI_GetParameter(hAPI, ePARAMETER_OUT, 2);
+
+ ipcEmailAPI_Destroy(hAPI);
+
+ hAPI = NULL;
+ EM_DEBUG_FUNC_END("*password_length[%d]", *password_length);
+ return err;
+}
+
+EXPORT_API int email_update_notification_bar(int account_id)
+{
+ EM_DEBUG_FUNC_BEGIN("account_id [%d]", account_id);
+ int err = EMF_ERROR_NONE, *return_value = NULL;
+
+ if (account_id == 0) {
+ EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
+ err = EMF_ERROR_INVALID_PARAM;
+ return err;
+ }
+
+ HIPC_API hAPI = ipcEmailAPI_Create(_EMAIL_API_UPDATE_NOTIFICATION_BAR_FOR_UNREAD_MAIL);
+
+ EM_IF_NULL_RETURN_VALUE(hAPI, EMF_ERROR_NULL_VALUE);
+
+ /* account_id */
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, (char*)&account_id, sizeof(int)))
+ EM_DEBUG_EXCEPTION(" ipcEmailAPI_AddParameter account_id failed");
+
+ if(!ipcEmailProxy_ExecuteAPI(hAPI)) {
+ EM_DEBUG_EXCEPTION(" ipcEmailProxy_ExecuteAPI failed ");
+ EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMF_ERROR_IPC_SOCKET_FAILURE);
+ }
+
+ return_value = (int*)ipcEmailAPI_GetParameter(hAPI, ePARAMETER_OUT, 0); /* error code */;
+ if(return_value)
+ err = *return_value;
+
+ ipcEmailAPI_Destroy(hAPI);
+
+ hAPI = NULL;
+ EM_DEBUG_FUNC_END("ret[%d]", err);
+ return err;
+}
+
+
+EXPORT_API int email_clear_all_notification_bar()
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int ret = 0;
+ int err = EMF_ERROR_NONE;
+
+ ret = em_core_clear_all_notifications();
+
+ EM_DEBUG_FUNC_END("ret[%d]", ret);
+ return err;
+}
+
+EXPORT_API int email_save_default_account_id(int input_account_id)
+{
+ EM_DEBUG_FUNC_BEGIN("input_account_id [%d]", input_account_id);
+ int ret = 0;
+ int err = EMF_ERROR_NONE;
+
+ ret = em_core_save_default_account_id(input_account_id);
+
+ EM_DEBUG_FUNC_END("ret[%d]", ret);
+ return err;
+}
+
+EXPORT_API int email_load_default_account_id(int *output_account_id)
+{
+ EM_DEBUG_FUNC_BEGIN("output_account_id [%p]", output_account_id);
+ int ret = 0;
+ int err = EMF_ERROR_NONE;
+
+ ret = em_core_load_default_account_id(output_account_id);
+
+ EM_DEBUG_FUNC_END("ret[%d]", ret);
+ return err;
+} \ No newline at end of file
diff --git a/MAPI/Emf_Mapi_Init.c b/MAPI/Emf_Mapi_Init.c
new file mode 100755
index 0000000..2f1805e
--- /dev/null
+++ b/MAPI/Emf_Mapi_Init.c
@@ -0,0 +1,132 @@
+/*
+* email-service
+*
+* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+*
+* Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com>
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*
+*/
+
+
+
+/**
+ *
+ * This file contains the data structures and interfaces needed for application,
+ * to interact with Email Engine.
+ * @file Emf_Mapi_Init.c
+ * @brief This file contains the data structures and interfaces of Email FW intialization related Functionality provided by
+ * Email Engine .
+ */
+
+#include <Emf_Mapi.h>
+#include "string.h"
+#include "Msg_Convert.h"
+#include "em-storage.h"
+#include "ipc-library.h"
+#include <sqlite3.h>
+
+
+EXPORT_API int email_open_db(void)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int error = EMF_ERROR_NONE;
+
+ if (em_storage_db_open(&error) == NULL)
+ EM_DEBUG_EXCEPTION("em_storage_db_open failed [%d]", error);
+ error = em_storage_get_emf_error_from_em_storage_error(error);
+
+ EM_DEBUG_FUNC_END("error [%d]", error);
+
+ return error;
+}
+
+EXPORT_API int email_close_db(void)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int error = EMF_ERROR_NONE;
+
+ if ( !em_storage_db_close(&error))
+ EM_DEBUG_EXCEPTION("em_storage_db_close failed [%d]", error);
+ error = em_storage_get_emf_error_from_em_storage_error(error);
+ EM_DEBUG_FUNC_END("error [%d]", error);
+ return error;
+}
+
+
+EXPORT_API int email_service_begin(void)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int ret = -1;
+
+ signal(SIGPIPE, SIG_IGN); /* to ignore signal 13(SIGPIPE) */
+
+ ret = ipcEmailProxy_Initialize();
+ if (ret != EMF_ERROR_NONE)
+ EM_DEBUG_FUNC_END("err[%d]", ret);
+
+ return ret;
+}
+
+
+EXPORT_API int email_service_end(void)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int ret = -1;
+
+ ret = ipcEmailProxy_Finalize();
+ if (ret != EMF_ERROR_NONE)
+ EM_DEBUG_FUNC_END("err[%d]", ret);
+
+ return ret;
+}
+
+/* API - Exposed to External Application- core team.Creates all Email DB tables [ EXTERNAL] */
+
+
+EXPORT_API int email_init_storage(void)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int error = EMF_ERROR_NONE;
+
+ if (!em_storage_create_table(EMF_CREATE_DB_CHECK, &error)) {
+ EM_DEBUG_EXCEPTION("\t em_storage_create_table failed - %d\n", error);
+ }
+ error = em_storage_get_emf_error_from_em_storage_error(error);
+ EM_DEBUG_FUNC_END("error[%d]", error);
+ return error;
+}
+
+EXPORT_API int email_ping_service(void)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int error = EMF_ERROR_NONE;
+ HIPC_API hAPI = ipcEmailAPI_Create(_EMAIL_API_PING_SERVICE);
+
+ EM_IF_NULL_RETURN_VALUE(hAPI, EMF_ERROR_NULL_VALUE);
+
+ if(!ipcEmailProxy_ExecuteAPI(hAPI)) {
+ EM_DEBUG_EXCEPTION(" email_ping_service -- ipcEmailProxy_ExecuteAPIFail \n ");
+ EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMF_ERROR_IPC_SOCKET_FAILURE);
+ }
+
+ error = *(int*)ipcEmailAPI_GetParameter(hAPI, ePARAMETER_OUT, 0);
+
+ ipcEmailAPI_Destroy(hAPI);
+
+ hAPI = NULL;
+
+ EM_DEBUG_FUNC_END("err[%d]", error);
+ return error;
+}
diff --git a/MAPI/Emf_Mapi_Mailbox.c b/MAPI/Emf_Mapi_Mailbox.c
new file mode 100755
index 0000000..7d28d51
--- /dev/null
+++ b/MAPI/Emf_Mapi_Mailbox.c
@@ -0,0 +1,546 @@
+/*
+* email-service
+*
+* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+*
+* Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com>
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*
+*/
+
+
+
+/**
+ *
+ * This file contains the data structures and interfaces needed for application,
+ * to interact with Email Engine.
+ * @file Emf_Mapi_Folder.c
+ * @brief This file contains the data structures and interfaces of mailbox related Functionality provided by
+ * Email Engine .
+ */
+
+#include <Emf_Mapi.h>
+#include "string.h"
+#include "Msg_Convert.h"
+#include "em-storage.h"
+#include "ipc-library.h"
+#include "db-util.h"
+
+/* API - Create a mailbox */
+
+EXPORT_API int email_add_mailbox(emf_mailbox_t* new_mailbox, int on_server, unsigned* handle)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ char* local_mailbox_stream = NULL;
+ int size = 0;
+ int err = EMF_ERROR_NONE;
+ EM_IF_NULL_RETURN_VALUE(new_mailbox, EMF_ERROR_INVALID_PARAM);
+
+ HIPC_API hAPI = ipcEmailAPI_Create(_EMAIL_API_ADD_MAILBOX);
+
+ EM_IF_NULL_RETURN_VALUE(hAPI, EMF_ERROR_NULL_VALUE);
+
+ local_mailbox_stream = em_convert_mailbox_to_byte_stream(new_mailbox, &size);
+
+ EM_PROXY_IF_NULL_RETURN_VALUE(local_mailbox_stream, hAPI, EMF_ERROR_NULL_VALUE);
+
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, local_mailbox_stream, size))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed");
+ EM_SAFE_FREE(local_mailbox_stream);
+
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, &on_server, sizeof(int)))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed");
+
+ if(!ipcEmailProxy_ExecuteAPI(hAPI)) {
+ EM_DEBUG_EXCEPTION("ipcEmailProxy_ExecuteAPI failed");
+ EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMF_ERROR_IPC_SOCKET_FAILURE);
+ }
+
+ err = *(int*)ipcEmailAPI_GetParameter(hAPI, ePARAMETER_OUT, 0);
+ EM_DEBUG_LOG(" >>>>> error VALUE [%d]", err);
+
+ if(handle) {
+ *handle = *(int*)ipcEmailAPI_GetParameter(hAPI, ePARAMETER_OUT, 1);
+ EM_DEBUG_LOG(" >>>>> Handle [%d]", *handle);
+ }
+
+
+ ipcEmailAPI_Destroy(hAPI);
+ hAPI = NULL;
+ EM_DEBUG_FUNC_END("err [%d]", err);
+ return err;
+}
+
+
+/* API - Delete a mailbox */
+
+EXPORT_API int email_delete_mailbox(emf_mailbox_t* mailbox, int on_server, unsigned* handle)
+{
+ EM_DEBUG_FUNC_BEGIN("mailbox[%p]", mailbox);
+
+ char* local_mailbox_stream = NULL;
+ int err = EMF_ERROR_NONE;
+ int size = 0;
+
+ EM_IF_NULL_RETURN_VALUE(mailbox, EMF_ERROR_INVALID_PARAM);
+ EM_IF_NULL_RETURN_VALUE(mailbox->account_id, EMF_ERROR_INVALID_PARAM) ;
+
+ HIPC_API hAPI = ipcEmailAPI_Create(_EMAIL_API_DELETE_MAILBOX);
+
+ EM_IF_NULL_RETURN_VALUE(hAPI, EMF_ERROR_NULL_VALUE);
+
+ local_mailbox_stream = em_convert_mailbox_to_byte_stream(mailbox, &size);
+
+ EM_PROXY_IF_NULL_RETURN_VALUE(local_mailbox_stream, hAPI, EMF_ERROR_NULL_VALUE);
+
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, local_mailbox_stream, size))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed");
+ EM_SAFE_FREE(local_mailbox_stream);
+
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, &on_server, sizeof(int)))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed");
+
+
+ if(!ipcEmailProxy_ExecuteAPI(hAPI)) {
+ EM_DEBUG_EXCEPTION("ipcEmailProxy_ExecuteAPI failed");
+ EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMF_ERROR_IPC_SOCKET_FAILURE);
+ }
+
+ err = *(int*)ipcEmailAPI_GetParameter(hAPI, ePARAMETER_OUT, 0);
+ EM_DEBUG_LOG("error VALUE [%d]", err);
+
+ if(handle) {
+ *handle = *(int*)ipcEmailAPI_GetParameter(hAPI, ePARAMETER_OUT, 1);
+ EM_DEBUG_LOG("Handle [%d]", handle);
+ }
+
+ ipcEmailAPI_Destroy(hAPI);
+ hAPI = NULL;
+ EM_DEBUG_FUNC_END("err [%d]", err);
+ return err;
+}
+
+/* API - Update a mailbox */
+
+
+EXPORT_API int email_update_mailbox(emf_mailbox_t* old_mailbox, emf_mailbox_t* new_mailbox)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ char* local_mailbox_stream = NULL;
+ int err = EMF_ERROR_NONE;
+ int size = 0;
+ int on_server = 0;
+ EM_DEBUG_LOG(" old_mailbox[%p], new_mailbox[%p]", old_mailbox, new_mailbox);
+
+ EM_IF_NULL_RETURN_VALUE(old_mailbox, EMF_ERROR_INVALID_PARAM);
+ EM_IF_NULL_RETURN_VALUE(old_mailbox->account_id, EMF_ERROR_INVALID_PARAM);
+ EM_IF_NULL_RETURN_VALUE(new_mailbox, EMF_ERROR_INVALID_PARAM);
+ EM_IF_ACCOUNT_ID_NULL(new_mailbox->account_id, EMF_ERROR_INVALID_PARAM);
+
+ HIPC_API hAPI = ipcEmailAPI_Create(_EMAIL_API_UPDATE_MAILBOX);
+
+ EM_IF_NULL_RETURN_VALUE(hAPI, EMF_ERROR_NULL_VALUE);
+
+
+ local_mailbox_stream = em_convert_mailbox_to_byte_stream(old_mailbox, &size);
+
+ EM_PROXY_IF_NULL_RETURN_VALUE(local_mailbox_stream, hAPI, EMF_ERROR_NULL_VALUE);
+
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, local_mailbox_stream, size))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed");
+ EM_SAFE_FREE(local_mailbox_stream);
+
+ local_mailbox_stream = em_convert_mailbox_to_byte_stream(new_mailbox, &size);
+
+ EM_PROXY_IF_NULL_RETURN_VALUE(local_mailbox_stream, hAPI, EMF_ERROR_NULL_VALUE);
+
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, local_mailbox_stream, size))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed");
+ EM_SAFE_FREE(local_mailbox_stream);
+
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, &on_server, sizeof(int)))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed");
+
+ if(!ipcEmailProxy_ExecuteAPI(hAPI)) {
+ EM_DEBUG_EXCEPTION("ipcEmailProxy_ExecuteAPI failed");
+ EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMF_ERROR_IPC_SOCKET_FAILURE);
+ } else {
+ err = *(int*)ipcEmailAPI_GetParameter(hAPI, ePARAMETER_OUT, 0);
+
+ EM_DEBUG_LOG("error VALUE [%d]", err);
+ ipcEmailAPI_Destroy(hAPI);
+ hAPI = NULL;
+ }
+ EM_DEBUG_FUNC_END("err [%d]", err);
+ return err;
+}
+
+
+EXPORT_API int email_get_sync_mailbox_list(int account_id, emf_mailbox_t** mailbox_list, int* count)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int counter = 0;
+ emf_mailbox_tbl_t* mailbox = NULL;
+ int err = EMF_ERROR_NONE ;
+
+ EM_IF_NULL_RETURN_VALUE(mailbox_list, EMF_ERROR_INVALID_PARAM);
+ EM_IF_ACCOUNT_ID_NULL(account_id, EMF_ERROR_INVALID_PARAM);
+ EM_IF_NULL_RETURN_VALUE(count, EMF_ERROR_INVALID_PARAM);
+
+ if (!em_storage_get_mailbox(account_id, 0, EMAIL_MAILBOX_SORT_BY_NAME_ASC, &counter, &mailbox, true, &err)) { /* TODO: confirm me */
+ EM_DEBUG_EXCEPTION("em_storage_get_mailbox failed [%d]", err);
+
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ } else
+ err = EMF_ERROR_NONE;
+
+ if (counter > 0) {
+ if (!(*mailbox_list = em_core_malloc(sizeof(emf_mailbox_t) * counter))) {
+ EM_DEBUG_EXCEPTION("malloc failed...");
+ err= EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+ } else
+ *mailbox_list = NULL;
+
+ *count = counter;
+
+ FINISH_OFF:
+ if (mailbox != NULL)
+ em_storage_free_mailbox(&mailbox, counter, NULL);
+ EM_DEBUG_FUNC_END("err [%d]", err);
+ return err;
+}
+
+
+EXPORT_API int email_get_mailbox_list(int account_id, int mailbox_sync_type, emf_mailbox_t** mailbox_list, int* count)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ int mailbox_count = 0;
+ emf_mailbox_tbl_t* mailbox_tbl_list = NULL;
+ int err =EMF_ERROR_NONE;
+ int i;
+
+ EM_IF_NULL_RETURN_VALUE(mailbox_list, EMF_ERROR_INVALID_PARAM);
+ EM_IF_ACCOUNT_ID_NULL(account_id, EMF_ERROR_INVALID_PARAM);
+ EM_IF_NULL_RETURN_VALUE(count, EMF_ERROR_INVALID_PARAM);
+
+ if (!em_storage_get_mailbox(account_id, mailbox_sync_type, EMAIL_MAILBOX_SORT_BY_NAME_ASC, &mailbox_count, &mailbox_tbl_list, true, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_get_mailbox failed [%d]", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ } else
+ err = EMF_ERROR_NONE;
+
+ if (mailbox_count > 0) {
+ if (!(*mailbox_list = em_core_malloc(sizeof(emf_mailbox_t) * mailbox_count))) {
+ EM_DEBUG_EXCEPTION("malloc failed for mailbox_list");
+ err= EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ for (i = 0; i < mailbox_count; i++) {
+ (*mailbox_list)[i].mailbox_id = mailbox_tbl_list[i].mailbox_id;
+ (*mailbox_list)[i].account_id = account_id;
+ (*mailbox_list)[i].name = mailbox_tbl_list[i].mailbox_name;
+ mailbox_tbl_list[i].mailbox_name = NULL;
+ (*mailbox_list)[i].alias = mailbox_tbl_list[i].alias;
+ mailbox_tbl_list[i].alias = NULL;
+ (*mailbox_list)[i].local = mailbox_tbl_list[i].local_yn;
+ (*mailbox_list)[i].mailbox_type = mailbox_tbl_list[i].mailbox_type;
+ (*mailbox_list)[i].synchronous = mailbox_tbl_list[i].sync_with_server_yn;
+ (*mailbox_list)[i].unread_count = mailbox_tbl_list[i].unread_count;
+ (*mailbox_list)[i].total_mail_count_on_local = mailbox_tbl_list[i].total_mail_count_on_local;
+ (*mailbox_list)[i].total_mail_count_on_server = mailbox_tbl_list[i].total_mail_count_on_server;
+ (*mailbox_list)[i].has_archived_mails = mailbox_tbl_list[i].has_archived_mails;
+ (*mailbox_list)[i].mail_slot_size = mailbox_tbl_list[i].mail_slot_size;
+ }
+ } else
+ *mailbox_list = NULL;
+
+ *count = mailbox_count;
+
+FINISH_OFF:
+ if (mailbox_tbl_list != NULL)
+ em_storage_free_mailbox(&mailbox_tbl_list, mailbox_count, NULL);
+
+ EM_DEBUG_FUNC_END("err [%d]", err);
+ return err;
+}
+
+
+
+EXPORT_API int email_get_mailbox_list_ex(int account_id, int mailbox_sync_type, int with_count, emf_mailbox_t** mailbox_list, int* count)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ int mailbox_count = 0;
+ emf_mailbox_tbl_t* mailbox_tbl_list = NULL;
+ int err =EMF_ERROR_NONE;
+ int i;
+
+ EM_IF_NULL_RETURN_VALUE(mailbox_list, EMF_ERROR_INVALID_PARAM);
+ EM_IF_ACCOUNT_ID_NULL(account_id, EMF_ERROR_INVALID_PARAM);
+ EM_IF_NULL_RETURN_VALUE(count, EMF_ERROR_INVALID_PARAM);
+
+ if (!em_storage_get_mailbox_ex(account_id, mailbox_sync_type, with_count, &mailbox_count, &mailbox_tbl_list, true, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_get_mailbox_ex failed [%d]", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ } else
+ err = EMF_ERROR_NONE;
+
+ if (mailbox_count > 0) {
+ if (!(*mailbox_list = em_core_malloc(sizeof(emf_mailbox_t) * mailbox_count))) {
+ EM_DEBUG_EXCEPTION("malloc failed for mailbox_list");
+ err= EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ for (i = 0; i < mailbox_count; i++) {
+ (*mailbox_list)[i].mailbox_id = mailbox_tbl_list[i].mailbox_id;
+ (*mailbox_list)[i].account_id = account_id;
+ (*mailbox_list)[i].name = mailbox_tbl_list[i].mailbox_name;
+ mailbox_tbl_list[i].mailbox_name = NULL;
+ (*mailbox_list)[i].alias = mailbox_tbl_list[i].alias;
+ mailbox_tbl_list[i].alias = NULL;
+ (*mailbox_list)[i].local = mailbox_tbl_list[i].local_yn;
+ (*mailbox_list)[i].mailbox_type = mailbox_tbl_list[i].mailbox_type;
+ (*mailbox_list)[i].synchronous = mailbox_tbl_list[i].sync_with_server_yn;
+ (*mailbox_list)[i].unread_count = mailbox_tbl_list[i].unread_count;
+ (*mailbox_list)[i].total_mail_count_on_local = mailbox_tbl_list[i].total_mail_count_on_local;
+ (*mailbox_list)[i].total_mail_count_on_server = mailbox_tbl_list[i].total_mail_count_on_server;
+ (*mailbox_list)[i].has_archived_mails = mailbox_tbl_list[i].has_archived_mails;
+ (*mailbox_list)[i].mail_slot_size = mailbox_tbl_list[i].mail_slot_size;
+ }
+ } else
+ *mailbox_list = NULL;
+
+ if ( count )
+ *count = mailbox_count;
+
+FINISH_OFF:
+ if (mailbox_tbl_list != NULL)
+ em_storage_free_mailbox(&mailbox_tbl_list, mailbox_count, NULL);
+
+ EM_DEBUG_FUNC_END("err [%d]", err);
+ return err;
+}
+
+
+EXPORT_API int email_get_mailbox_by_name(int account_id, const char *pMailboxName, emf_mailbox_t **pMailbox)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ int err = EMF_ERROR_NONE;
+ emf_mailbox_t* curr_mailbox = NULL;
+ emf_mailbox_tbl_t* local_mailbox = NULL;
+
+ EM_IF_NULL_RETURN_VALUE(pMailbox, EMF_ERROR_INVALID_PARAM);
+ if(!pMailboxName)
+ return EMF_ERROR_INVALID_PARAM;
+
+ if (!em_storage_get_mailbox_by_name(account_id, -1, (char*)pMailboxName, &local_mailbox, true, &err)) /* Warning removal changes */ {
+ if (err == EM_STORAGE_ERROR_MAILBOX_NOT_FOUND)
+ err = EMF_ERROR_MAILBOX_NOT_FOUND; else if (err == EM_STORAGE_ERROR_INVALID_PARAM)
+ err = EMF_ERROR_INVALID_PARAM; else if (err == EM_STORAGE_ERROR_OUT_OF_MEMORY)
+ err = EMF_ERROR_OUT_OF_MEMORY; else if (err == EM_STORAGE_ERROR_DB_FAILURE)
+ err = EMF_ERROR_DB_FAILURE; else
+ err = EMF_ERROR_UNKNOWN;
+
+ return err;
+ } else {
+ curr_mailbox = em_core_malloc(sizeof(emf_mailbox_t));
+ memset(curr_mailbox, 0x00, sizeof(emf_mailbox_t));
+
+ curr_mailbox->account_id = local_mailbox->account_id;
+ if(local_mailbox->mailbox_name)
+ curr_mailbox->name = strdup(local_mailbox->mailbox_name);
+ curr_mailbox->local = local_mailbox->local_yn;
+ if(local_mailbox->alias)
+ curr_mailbox->alias= strdup(local_mailbox->alias);
+ curr_mailbox->synchronous = local_mailbox->sync_with_server_yn;
+ curr_mailbox->mailbox_type = local_mailbox->mailbox_type;
+ curr_mailbox->unread_count = local_mailbox->unread_count;
+ curr_mailbox->total_mail_count_on_local= local_mailbox->total_mail_count_on_local;
+ curr_mailbox->total_mail_count_on_server= local_mailbox->total_mail_count_on_server;
+ curr_mailbox->has_archived_mails = local_mailbox->has_archived_mails;
+ curr_mailbox->mail_slot_size = local_mailbox->mail_slot_size;
+ }
+
+ *pMailbox = curr_mailbox;
+
+ em_storage_free_mailbox(&local_mailbox, 1, &err);
+ EM_DEBUG_FUNC_END("err [%d]", err);
+ return err;
+}
+
+
+EXPORT_API int email_get_child_mailbox_list(int account_id, const char *parent_mailbox, emf_mailbox_t** mailbox_list, int* count)
+{
+ EM_DEBUG_FUNC_BEGIN("account_id[%d], parent_mailbox[%p], mailbox_list[%p], count[%p]", account_id, parent_mailbox, mailbox_list, count);
+
+ int err = EMF_ERROR_NONE;
+ int counter = 0;
+ emf_mailbox_tbl_t* mailbox_tbl = NULL;
+ int i =0;
+
+ EM_IF_NULL_RETURN_VALUE(account_id, EMF_ERROR_INVALID_PARAM);
+ EM_IF_NULL_RETURN_VALUE(mailbox_list, EMF_ERROR_INVALID_PARAM);
+ EM_IF_NULL_RETURN_VALUE(count, EMF_ERROR_INVALID_PARAM);
+
+ *mailbox_list = NULL;
+ *count = 0;
+
+ if (!em_storage_get_child_mailbox_list(account_id,(char*)parent_mailbox, &counter, &mailbox_tbl, true, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_get_child_mailbox_list failed[%d]", err);
+
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ } else
+ err = EMF_ERROR_NONE;
+
+ if (counter > 0) {
+ if (!(*mailbox_list = em_core_malloc(sizeof(emf_mailbox_t) * counter))) {
+ EM_DEBUG_EXCEPTION("malloc failed for mailbox_list");
+
+ err= EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ memset(*mailbox_list, 0x00, (sizeof(emf_mailbox_t) * counter));
+
+ for (i = 0; i < counter; i++) {
+ (*mailbox_list)[i].mailbox_id = mailbox_tbl[i].mailbox_id;
+ (*mailbox_list)[i].account_id = account_id;
+ (*mailbox_list)[i].name = mailbox_tbl[i].mailbox_name; mailbox_tbl[i].mailbox_name = NULL;
+ (*mailbox_list)[i].alias = mailbox_tbl[i].alias; mailbox_tbl[i].alias = NULL;
+ (*mailbox_list)[i].local = mailbox_tbl[i].local_yn;
+ (*mailbox_list)[i].mailbox_type = mailbox_tbl[i].mailbox_type;
+ (*mailbox_list)[i].synchronous = mailbox_tbl[i].sync_with_server_yn;
+ (*mailbox_list)[i].unread_count = mailbox_tbl[i].unread_count;
+ (*mailbox_list)[i].total_mail_count_on_local = mailbox_tbl[i].total_mail_count_on_local;
+ (*mailbox_list)[i].total_mail_count_on_server = mailbox_tbl[i].total_mail_count_on_server;
+ (*mailbox_list)[i].has_archived_mails = mailbox_tbl[i].has_archived_mails;
+ (*mailbox_list)[i].mail_slot_size = mailbox_tbl[i].mail_slot_size;
+ }
+ } else
+ *mailbox_list = NULL;
+
+ *count = counter;
+
+FINISH_OFF:
+ if (mailbox_tbl != NULL)
+ em_storage_free_mailbox(&mailbox_tbl, counter, NULL);
+ EM_DEBUG_FUNC_END("err [%d]", err);
+ return err;
+}
+
+/* sowmya.kr, 05-Apr-2010, new MAPI*/
+
+EXPORT_API int email_get_mailbox_by_mailbox_type(int account_id, emf_mailbox_type_e mailbox_type, emf_mailbox_t** mailbox)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ int err = EMF_ERROR_NONE;
+ emf_mailbox_t* curr_mailbox = NULL;
+ emf_mailbox_tbl_t* local_mailbox = NULL;
+
+ EM_IF_NULL_RETURN_VALUE(mailbox, EMF_ERROR_INVALID_PARAM);
+ EM_IF_NULL_RETURN_VALUE(account_id, EMF_ERROR_INVALID_PARAM) ;
+
+
+ if(mailbox_type < EMF_MAILBOX_TYPE_INBOX || mailbox_type > EMF_MAILBOX_TYPE_ALL_EMAILS)
+ return EMF_ERROR_INVALID_PARAM;
+ if (!em_storage_get_mailbox_by_mailbox_type(account_id, mailbox_type, &local_mailbox, true, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_get_mailbox_by_mailbox_type failed [%d]", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ } else {
+ err = EMF_ERROR_NONE;
+ curr_mailbox = em_core_malloc(sizeof(emf_mailbox_t));
+ memset(curr_mailbox, 0x00, sizeof(emf_mailbox_t));
+
+ curr_mailbox->account_id = local_mailbox->account_id;
+ if(local_mailbox->mailbox_name)
+ curr_mailbox->name = strdup(local_mailbox->mailbox_name);
+ curr_mailbox->local = local_mailbox->local_yn;
+ if(local_mailbox->alias)
+ curr_mailbox->alias= strdup(local_mailbox->alias);
+ curr_mailbox->synchronous = 1;
+ curr_mailbox->mailbox_type = local_mailbox->mailbox_type;
+ curr_mailbox->unread_count = local_mailbox->unread_count;
+ curr_mailbox->total_mail_count_on_local = local_mailbox->total_mail_count_on_local;
+ curr_mailbox->total_mail_count_on_server = local_mailbox->total_mail_count_on_server;
+ curr_mailbox->has_archived_mails = local_mailbox->has_archived_mails;
+ curr_mailbox->mail_slot_size = local_mailbox->mail_slot_size;
+ }
+
+ *mailbox = curr_mailbox;
+FINISH_OFF:
+
+ if(local_mailbox)
+ em_storage_free_mailbox(&local_mailbox, 1, NULL);
+ EM_DEBUG_FUNC_END("err [%d]", err);
+ return err;
+}
+
+EXPORT_API int email_set_mail_slot_size(int account_id, char* mailbox_name, int new_slot_size/*, unsigned* handle*/)
+{
+ EM_DEBUG_FUNC_BEGIN("account_id[%d], mailbox_name[%p], new_slot_size[%d]", account_id, mailbox_name, new_slot_size);
+
+ int err = EMF_ERROR_NONE, *handle = NULL;
+
+ if(new_slot_size < 0) {
+ EM_DEBUG_EXCEPTION("new_slot_size should be greater than 0 or should be equal to 0");
+ return EMF_ERROR_INVALID_PARAM;
+ }
+
+ HIPC_API hAPI = ipcEmailAPI_Create(_EMAIL_API_SET_MAIL_SLOT_SIZE);
+
+ EM_IF_NULL_RETURN_VALUE(hAPI, EMF_ERROR_NULL_VALUE);
+
+ if (hAPI) {
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, &account_id, sizeof(int)))
+ EM_DEBUG_EXCEPTION(" ipcEmailAPI_AddParameter for account_id failed");
+
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, &new_slot_size, sizeof(int)))
+ EM_DEBUG_EXCEPTION(" ipcEmailAPI_AddParameter for new_slot_size failed");
+
+ if(mailbox_name) {
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, mailbox_name, strlen(mailbox_name) ))
+ EM_DEBUG_EXCEPTION(" ipcEmailAPI_AddParameter for mailbox_name failed");
+ }
+
+ if(!ipcEmailProxy_ExecuteAPI(hAPI)) {
+ EM_DEBUG_EXCEPTION("ipcEmailProxy_ExecuteAPI failed");
+ EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMF_ERROR_IPC_SOCKET_FAILURE);
+ } else {
+ err = *(int*)ipcEmailAPI_GetParameter(hAPI, ePARAMETER_OUT, 0);
+ EM_DEBUG_LOG("email_set_mail_slot_size error VALUE [%d]", err);
+ if(handle) {
+ *handle = *(int*)ipcEmailAPI_GetParameter(hAPI, ePARAMETER_OUT, 1);
+ EM_DEBUG_LOG("email_set_mail_slot_size handle VALUE [%d]", handle);
+ }
+ ipcEmailAPI_Destroy(hAPI);
+ hAPI = NULL;
+ }
+ }
+ EM_DEBUG_FUNC_END("err [%d]", err);
+ return err;
+}
diff --git a/MAPI/Emf_Mapi_Message.c b/MAPI/Emf_Mapi_Message.c
new file mode 100755
index 0000000..931fc30
--- /dev/null
+++ b/MAPI/Emf_Mapi_Message.c
@@ -0,0 +1,3316 @@
+/*
+* email-service
+*
+* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+*
+* Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com>
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*
+*/
+
+
+
+/**
+ *
+ * This file contains the data structures and interfaces needed for application,
+ * to interact with Email Engine.
+ * @file Emf_Mapi_Message.c
+ * @brief This file contains the data structures and interfaces of Message related Functionality provided by
+ * Email Engine .
+ */
+
+#include <stdlib.h>
+#include <time.h>
+#include <string.h>
+#include "Emf_Mapi.h"
+#include "ipc-library.h"
+#include "Msg_Convert.h"
+#include "em-core-mesg.h"
+#include "em-core-smtp.h"
+#include "em-storage.h"
+#include "db-util.h"
+
+#define DIR_SEPERATOR_CH '/'
+
+#define _DIRECT_TO_DB
+
+
+EXPORT_API int email_add_message(emf_mail_t* mail, emf_mailbox_t* mailbox, int from_composer)
+{
+ EM_DEBUG_FUNC_BEGIN("mail[%p], mailbox[%p], from_composer [%d]", mail, mailbox, from_composer);
+
+ EM_IF_NULL_RETURN_VALUE(mail, EMF_ERROR_INVALID_PARAM);
+ EM_IF_NULL_RETURN_VALUE(mail->head, EMF_ERROR_INVALID_PARAM);
+ EM_IF_NULL_RETURN_VALUE(mail->info, EMF_ERROR_INVALID_PARAM);
+ EM_IF_NULL_RETURN_VALUE(mail->body, EMF_ERROR_INVALID_PARAM);
+ EM_IF_NULL_RETURN_VALUE(mailbox, EMF_ERROR_INVALID_PARAM);
+ EM_IF_NULL_RETURN_VALUE(mailbox->name, EMF_ERROR_INVALID_PARAM);
+ EM_IF_ACCOUNT_ID_NULL(mail->info->account_id, EMF_ERROR_INVALID_PARAM);
+ EM_IF_ACCOUNT_ID_NULL(mailbox->account_id, EMF_ERROR_INVALID_PARAM);
+
+ int err = EMF_ERROR_NONE, size = 0;
+ char* mail_head_stream = NULL, *mail_body_stream = NULL, *mail_info_stream = NULL, *mailbox_stream = NULL;
+ void *return_from_ipc = NULL;
+ HIPC_API hAPI = NULL;
+
+ if(from_composer) {
+ hAPI = ipcEmailAPI_Create(_EMAIL_API_ADD_MAIL_OLD);
+
+ if(!hAPI) {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_Create failed");
+ err = EMF_ERROR_NULL_VALUE;
+ goto FINISH_OFF;
+ }
+
+ /* Head */
+ mail_head_stream = em_convert_mail_head_to_byte_stream(mail->head, &size);
+
+ if(!mail_head_stream) {
+ EM_DEBUG_EXCEPTION("em_convert_mail_head_to_byte_stream failed");
+ err = EMF_ERROR_NULL_VALUE;
+ goto FINISH_OFF;
+ }
+
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, mail_head_stream, size)) {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter for head failed");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ /* Body */
+ mail_body_stream = em_convert_mail_body_to_byte_stream(mail->body, &size);
+
+ if(!mail_body_stream) {
+ EM_DEBUG_EXCEPTION("em_convert_mail_body_to_byte_stream failed");
+ err = EMF_ERROR_NULL_VALUE;
+ goto FINISH_OFF;
+ }
+
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, mail_body_stream, size)) {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter for body failed");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ /* Info */
+ mail_info_stream = em_convert_mail_info_to_byte_stream(mail->info, &size);
+
+ if(!mail_info_stream) {
+ EM_DEBUG_EXCEPTION("em_convert_mail_info_to_byte_stream failed");
+ err = EMF_ERROR_NULL_VALUE;
+ goto FINISH_OFF;
+ }
+
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, mail_info_stream, size)) {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter for info failed");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ /* Mailbox */
+ mailbox_stream = em_convert_mailbox_to_byte_stream(mailbox, &size);
+
+ if(!mailbox_stream) {
+ EM_DEBUG_EXCEPTION("em_convert_mailbox_to_byte_stream failed");
+ err = EMF_ERROR_NULL_VALUE;
+ goto FINISH_OFF;
+ }
+
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, mailbox_stream, size)) {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter mailbox Fail");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+
+ /* from_composer */
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, (char*)&from_composer, sizeof(int))) {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter from_composer Failed");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ /* Execute API */
+ if(!ipcEmailProxy_ExecuteAPI(hAPI)) {
+ EM_DEBUG_EXCEPTION("ipcEmailProxy_ExecuteAPI failed");
+ err = EMF_ERROR_IPC_SOCKET_FAILURE;
+ goto FINISH_OFF;
+ }
+
+ return_from_ipc = ipcEmailAPI_GetParameter(hAPI, ePARAMETER_OUT, 0);
+
+ if(return_from_ipc)
+ err = *(int*)return_from_ipc;
+ else {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_GetParameter failed");
+ err = EMF_ERROR_IPC_SOCKET_FAILURE;
+ goto FINISH_OFF;
+ }
+
+ if(err == EMF_ERROR_NONE) {
+ return_from_ipc = ipcEmailAPI_GetParameter(hAPI, ePARAMETER_OUT, 1);
+ if(return_from_ipc)
+ mail->info->uid = *(int*)return_from_ipc;
+ else{
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_GetParameter failed");
+ err = EMF_ERROR_IPC_SOCKET_FAILURE;
+ goto FINISH_OFF;
+ }
+ }
+ }
+ else {
+ if(!em_core_mail_save(mailbox->account_id, mailbox->name, mail, NULL, from_composer, &err)) {
+ EM_DEBUG_EXCEPTION("em_core_mail_save failed [%d]", err);
+ goto FINISH_OFF;
+ }
+ }
+
+FINISH_OFF:
+ if(hAPI)
+ ipcEmailAPI_Destroy(hAPI);
+
+ EM_SAFE_FREE(mail_head_stream);
+ EM_SAFE_FREE(mail_body_stream);
+ EM_SAFE_FREE(mail_info_stream);
+ EM_SAFE_FREE(mailbox_stream);
+
+ EM_DEBUG_FUNC_END("err [%d]", err);
+ return err;
+
+}
+
+EXPORT_API int email_add_mail(emf_mail_data_t *input_mail_data, emf_attachment_data_t *input_attachment_data_list, int input_attachment_count, emf_meeting_request_t* input_meeting_request, int input_sync_server)
+{
+ EM_DEBUG_FUNC_BEGIN("input_mail_data[%p], input_attachment_data_list[%p], input_attachment_count [%d], input_meeting_request [%p], input_sync_server [%d]", input_mail_data, input_attachment_data_list, input_attachment_count, input_meeting_request, input_sync_server);
+
+ EM_IF_NULL_RETURN_VALUE(input_mail_data, EMF_ERROR_INVALID_PARAM);
+ EM_IF_NULL_RETURN_VALUE(input_mail_data->account_id, EMF_ERROR_INVALID_PARAM);
+ EM_IF_NULL_RETURN_VALUE(input_mail_data->mailbox_name, EMF_ERROR_INVALID_PARAM);
+
+ if(input_attachment_count > 0 && !input_attachment_data_list) {
+ EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
+ return EMF_ERROR_INVALID_PARAM;
+ }
+
+ int err = EMF_ERROR_NONE;
+ int size = 0;
+ char *mail_data_stream = NULL;
+ char *attachment_data_list_stream = NULL;
+ char *meeting_request_stream = NULL;
+ void *return_from_ipc = NULL;
+ HIPC_API hAPI = NULL;
+
+ if(input_sync_server) {
+ hAPI = ipcEmailAPI_Create(_EMAIL_API_ADD_MAIL);
+
+ if(!hAPI) {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_Create failed");
+ err = EMF_ERROR_NULL_VALUE;
+ goto FINISH_OFF;
+ }
+
+ /* emf_mail_data_t */
+ mail_data_stream = em_convert_mail_data_to_byte_stream(input_mail_data, 1, &size);
+
+ if(!mail_data_stream) {
+ EM_DEBUG_EXCEPTION("em_convert_mail_data_to_byte_stream failed");
+ err = EMF_ERROR_NULL_VALUE;
+ goto FINISH_OFF;
+ }
+
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, mail_data_stream, size)) {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter for head failed");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ /* emf_attachment_data_t */
+ attachment_data_list_stream = em_convert_attachment_data_to_byte_stream(input_attachment_data_list, input_attachment_count, &size);
+
+ if(!attachment_data_list_stream) {
+ EM_DEBUG_EXCEPTION("em_convert_attachment_data_to_byte_stream failed");
+ err = EMF_ERROR_NULL_VALUE;
+ goto FINISH_OFF;
+ }
+
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, attachment_data_list_stream, size)) {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ /* emf_meeting_request_t */
+ if ( input_mail_data->meeting_request_status != EMF_MAIL_TYPE_NORMAL ) {
+ meeting_request_stream = em_convert_meeting_req_to_byte_stream(input_meeting_request, &size);
+
+ if(!meeting_request_stream) {
+ EM_DEBUG_EXCEPTION("em_convert_meeting_req_to_byte_stream failed");
+ err = EMF_ERROR_NULL_VALUE;
+ goto FINISH_OFF;
+ }
+
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, meeting_request_stream, size)) {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+ }
+
+ /* sync server */
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, (char*)&input_sync_server, sizeof(int))) {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ /* Execute API */
+ if(!ipcEmailProxy_ExecuteAPI(hAPI)) {
+ EM_DEBUG_EXCEPTION("ipcEmailProxy_ExecuteAPI failed");
+ err = EMF_ERROR_IPC_SOCKET_FAILURE;
+ goto FINISH_OFF;
+ }
+
+ return_from_ipc = ipcEmailAPI_GetParameter(hAPI, ePARAMETER_OUT, 0);
+
+ if(return_from_ipc)
+ err = *(int*)return_from_ipc;
+ else {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_GetParameter failed");
+ err = EMF_ERROR_IPC_SOCKET_FAILURE;
+ goto FINISH_OFF;
+ }
+
+ if(err == EMF_ERROR_NONE) {
+ return_from_ipc = ipcEmailAPI_GetParameter(hAPI, ePARAMETER_OUT, 1); /* result mail_id */
+ if(return_from_ipc) {
+ input_mail_data->mail_id = *(int*)return_from_ipc;
+ }
+ else{
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_GetParameter failed");
+ err = EMF_ERROR_IPC_SOCKET_FAILURE;
+ goto FINISH_OFF;
+ }
+ return_from_ipc = ipcEmailAPI_GetParameter(hAPI, ePARAMETER_OUT, 2); /* result thread_id */
+ if(return_from_ipc) {
+ input_mail_data->thread_id = *(int*)return_from_ipc;
+ }
+ else{
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_GetParameter failed");
+ err = EMF_ERROR_IPC_SOCKET_FAILURE;
+ goto FINISH_OFF;
+ }
+ }
+ }
+ else {
+ if((err = em_core_add_mail(input_mail_data, input_attachment_data_list, input_attachment_count, input_meeting_request, input_sync_server)) != EMF_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("em_core_add_mail failed [%d]", err);
+ goto FINISH_OFF;
+ }
+ }
+
+FINISH_OFF:
+ if(hAPI)
+ ipcEmailAPI_Destroy(hAPI);
+
+ EM_SAFE_FREE(mail_data_stream);
+ EM_SAFE_FREE(attachment_data_list_stream);
+
+ EM_DEBUG_FUNC_END("err [%d]", err);
+ return err;
+
+}
+
+int email_create_db_full()
+{
+ int mailbox_index, mail_index, mailbox_count, mail_slot_size;
+ emf_mail_tbl_t mail_table_data = {0};
+ emf_mailbox_t *mailbox_list = NULL;
+ int err = EMF_ERROR_NONE;
+
+ if ( (err = email_open_db()) != EMF_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("email_open_db failed [%d]", err);
+ return err;
+ }
+
+ mail_table_data.subject = (char*) em_core_malloc(50);
+ mail_table_data.full_address_from = strdup("<dummy_from@nowhere.com>");
+ mail_table_data.full_address_to = strdup("<dummy_to@nowhere.com>");
+ mail_table_data.account_id =1;
+ mail_table_data.mailbox_name = (char*) em_core_malloc(250);
+
+ if( (err = email_get_mailbox_list_ex(1, -1, 0, &mailbox_list, &mailbox_count)) < EMF_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("email_get_mailbox_list_ex failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ for(mailbox_index = 0; mailbox_index < mailbox_count; mailbox_index++) {
+ mail_slot_size= mailbox_list[mailbox_index].mail_slot_size;
+ for(mail_index = 0; mail_index < mail_slot_size; mail_index++) {
+ sprintf(mail_table_data.subject, "Subject #%d",mail_index);
+ strncpy(mail_table_data.mailbox_name, mailbox_list[mailbox_index].name, 250 - 1);
+ mail_table_data.mailbox_type = mailbox_list[mailbox_index].mailbox_type;
+ if( !em_storage_add_mail(&mail_table_data, 1, true, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_add_mail failed [%d]",err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+ }
+ }
+
+FINISH_OFF:
+ if ( (err = email_close_db()) != EMF_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("email_close_db failed [%d]", err);
+ }
+
+ if(mailbox_list)
+ email_free_mailbox(&mailbox_list, mailbox_count);
+
+ EM_SAFE_FREE(mail_table_data.subject);
+ EM_SAFE_FREE(mail_table_data.mailbox_name);
+ EM_SAFE_FREE(mail_table_data.full_address_from);
+ EM_SAFE_FREE(mail_table_data.full_address_to);
+
+ return err;
+}
+
+EXPORT_API int email_update_message( int mail_id, emf_mail_t* mail)
+{
+ EM_DEBUG_FUNC_BEGIN("mail_id[%d], mali[%p]", mail_id, mail);
+
+ int size = 0;
+ int ret = 0;
+ int err = EMF_ERROR_NONE;
+ void *retrun_from_ipc = NULL;
+ char* mail_head_stream = NULL;
+ char* mail_body_stream = NULL;
+ char* mail_info_stream = NULL;
+ HIPC_API hAPI = NULL;
+
+ EM_IF_NULL_RETURN_VALUE(mail, EMF_ERROR_INVALID_PARAM);
+ EM_IF_NULL_RETURN_VALUE(mail->head, EMF_ERROR_INVALID_PARAM);
+ EM_IF_NULL_RETURN_VALUE(mail->info, EMF_ERROR_INVALID_PARAM);
+
+ if ( mail_id <= 0 ) {
+ EM_DEBUG_EXCEPTION("Invalid Param : mail_id[%d]", mail_id);
+ return EMF_ERROR_INVALID_PARAM;
+ }
+ EM_IF_ACCOUNT_ID_NULL(mail->info->account_id, EMF_ERROR_INVALID_PARAM);
+
+ hAPI = ipcEmailAPI_Create(_EMAIL_API_UPDATE_MAIL_OLD);
+
+ if(!hAPI) {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_Create failed");
+ err = EMF_ERROR_NULL_VALUE;
+ goto FINISH_OFF;
+ }
+
+ /* mail_id */
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, (char*)&mail_id, sizeof(int))) {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ /* Head */
+ mail_head_stream = em_convert_mail_head_to_byte_stream(mail->head, &size);
+ if(!mail_head_stream) {
+ EM_DEBUG_EXCEPTION("em_convert_mail_head_to_byte_stream failed");
+ err = EMF_ERROR_NULL_VALUE;
+ goto FINISH_OFF;
+ }
+
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, mail_head_stream, size)) {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ /* Body */
+ mail_body_stream = em_convert_mail_body_to_byte_stream(mail->body, &size);
+
+ if (!mail_body_stream ) {
+ int dummy_body = 0;
+ EM_DEBUG_LOG(" Mail body is NULL. Add dummy data(4 bytes)");
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, (char*)&dummy_body, sizeof(int))) {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+ }
+ else {
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, mail_body_stream, size)) {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+ }
+
+ /* Info */
+ mail_info_stream = em_convert_mail_info_to_byte_stream(mail->info, &size);
+
+ if (!mail_info_stream ) {
+ EM_DEBUG_EXCEPTION("em_convert_mail_info_to_byte_stream failed");
+ err = EMF_ERROR_NULL_VALUE;
+ goto FINISH_OFF;
+ }
+
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, mail_info_stream, size)) {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ if(!ipcEmailProxy_ExecuteAPI(hAPI)) {
+ EM_DEBUG_EXCEPTION("ipcEmailProxy_ExecuteAPI failed");
+ err = EMF_ERROR_IPC_SOCKET_FAILURE;
+ goto FINISH_OFF;
+ }
+
+ retrun_from_ipc = ipcEmailAPI_GetParameter(hAPI, ePARAMETER_OUT, 0);
+
+ if(retrun_from_ipc) {
+ ret = *(int*)retrun_from_ipc;
+ if ( ret != 1 ) {
+ retrun_from_ipc = ipcEmailAPI_GetParameter(hAPI, ePARAMETER_OUT, 1);
+ if(retrun_from_ipc) {
+ err = *(int*)retrun_from_ipc;
+ }
+ else {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_GetParameter failed");
+ err = EMF_ERROR_IPC_SOCKET_FAILURE;
+ goto FINISH_OFF;
+ }
+ }
+ }
+ else {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_GetParameter failed");
+ err = EMF_ERROR_IPC_SOCKET_FAILURE;
+ goto FINISH_OFF;
+ }
+
+
+FINISH_OFF:
+ EM_SAFE_FREE(mail_head_stream);
+ EM_SAFE_FREE(mail_body_stream);
+ EM_SAFE_FREE(mail_info_stream);
+
+ if(hAPI)
+ ipcEmailAPI_Destroy(hAPI);
+
+ EM_DEBUG_FUNC_END("err [%d] , ERROR CODE : %d", ret, err);
+ return err;
+
+}
+EXPORT_API int email_update_mail(emf_mail_data_t *input_mail_data, emf_attachment_data_t *input_attachment_data_list, int input_attachment_count, emf_meeting_request_t* input_meeting_request, int input_sync_server)
+{
+ EM_DEBUG_FUNC_BEGIN("input_mail_data[%p], input_attachment_data_list[%p], input_attachment_count [%d], input_meeting_request [%p], input_sync_server [%d]", input_mail_data, input_attachment_data_list, input_attachment_count, input_meeting_request, input_sync_server);
+
+ EM_IF_NULL_RETURN_VALUE(input_mail_data, EMF_ERROR_INVALID_PARAM);
+ EM_IF_NULL_RETURN_VALUE(input_mail_data->account_id, EMF_ERROR_INVALID_PARAM);
+ EM_IF_NULL_RETURN_VALUE(input_mail_data->mailbox_name, EMF_ERROR_INVALID_PARAM);
+
+ if(input_attachment_count > 0 && !input_attachment_data_list) {
+ EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
+ return EMF_ERROR_INVALID_PARAM;
+ }
+
+ int err = EMF_ERROR_NONE;
+ int size = 0;
+ char *mail_data_stream = NULL;
+ char *attachment_data_list_stream = NULL;
+ char *meeting_request_stream = NULL;
+ void *return_from_ipc = NULL;
+ HIPC_API hAPI = NULL;
+
+ if(input_sync_server) {
+ hAPI = ipcEmailAPI_Create(_EMAIL_API_UPDATE_MAIL);
+
+ if(!hAPI) {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_Create failed");
+ err = EMF_ERROR_NULL_VALUE;
+ goto FINISH_OFF;
+ }
+
+ /* emf_mail_data_t */
+ mail_data_stream = em_convert_mail_data_to_byte_stream(input_mail_data, 1, &size);
+
+ if(!mail_data_stream) {
+ EM_DEBUG_EXCEPTION("em_convert_mail_data_to_byte_stream failed");
+ err = EMF_ERROR_NULL_VALUE;
+ goto FINISH_OFF;
+ }
+
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, mail_data_stream, size)) {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter for head failed");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ /* emf_attachment_data_t */
+ attachment_data_list_stream = em_convert_attachment_data_to_byte_stream(input_attachment_data_list, input_attachment_count, &size);
+
+ if(!attachment_data_list_stream) {
+ EM_DEBUG_EXCEPTION("em_convert_attachment_data_to_byte_stream failed");
+ err = EMF_ERROR_NULL_VALUE;
+ goto FINISH_OFF;
+ }
+
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, attachment_data_list_stream, size)) {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ /* emf_meeting_request_t */
+ if ( input_mail_data->meeting_request_status != EMF_MAIL_TYPE_NORMAL ) {
+ meeting_request_stream = em_convert_meeting_req_to_byte_stream(input_meeting_request, &size);
+
+ if(!meeting_request_stream) {
+ EM_DEBUG_EXCEPTION("em_convert_meeting_req_to_byte_stream failed");
+ err = EMF_ERROR_NULL_VALUE;
+ goto FINISH_OFF;
+ }
+
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, meeting_request_stream, size)) {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+ }
+
+ /* sync_server */
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, (char*)&input_sync_server, sizeof(int))) {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ /* Execute API */
+ if(!ipcEmailProxy_ExecuteAPI(hAPI)) {
+ EM_DEBUG_EXCEPTION("ipcEmailProxy_ExecuteAPI failed");
+ err = EMF_ERROR_IPC_SOCKET_FAILURE;
+ goto FINISH_OFF;
+ }
+
+ return_from_ipc = ipcEmailAPI_GetParameter(hAPI, ePARAMETER_OUT, 0);
+
+ if(return_from_ipc)
+ err = *(int*)return_from_ipc;
+ else {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_GetParameter failed");
+ err = EMF_ERROR_IPC_SOCKET_FAILURE;
+ goto FINISH_OFF;
+ }
+
+ if(err == EMF_ERROR_NONE) {
+ return_from_ipc = ipcEmailAPI_GetParameter(hAPI, ePARAMETER_OUT, 1); /* result mail_id */
+ if(return_from_ipc) {
+ input_mail_data->mail_id = *(int*)return_from_ipc;
+ }
+ else{
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_GetParameter failed");
+ err = EMF_ERROR_IPC_SOCKET_FAILURE;
+ goto FINISH_OFF;
+ }
+ return_from_ipc = ipcEmailAPI_GetParameter(hAPI, ePARAMETER_OUT, 2); /* result thread_id */
+ if(return_from_ipc) {
+ input_mail_data->thread_id = *(int*)return_from_ipc;
+ }
+ else{
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_GetParameter failed");
+ err = EMF_ERROR_IPC_SOCKET_FAILURE;
+ goto FINISH_OFF;
+ }
+ }
+ }
+ else {
+ if( (err = em_core_update_mail(input_mail_data, input_attachment_data_list, input_attachment_count, input_meeting_request, input_sync_server)) != EMF_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("em_core_update_mail failed [%d]", err);
+ goto FINISH_OFF;
+ }
+ }
+
+FINISH_OFF:
+ if(hAPI)
+ ipcEmailAPI_Destroy(hAPI);
+
+ EM_SAFE_FREE(mail_data_stream);
+ EM_SAFE_FREE(attachment_data_list_stream);
+
+ EM_DEBUG_FUNC_END("err [%d]", err);
+ return err;
+
+}
+
+EXPORT_API int email_clear_mail_data()
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int err = EMF_ERROR_NONE;
+
+ HIPC_API hAPI = ipcEmailAPI_Create(_EMAIL_API_CLEAR_DATA);
+
+ EM_IF_NULL_RETURN_VALUE(hAPI, EMF_ERROR_NULL_VALUE);
+
+ if(!ipcEmailProxy_ExecuteAPI(hAPI)) {
+ EM_DEBUG_EXCEPTION("ipcEmailProxy_ExecuteAPI Fail");
+ EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMF_ERROR_IPC_SOCKET_FAILURE);
+ }
+ err = *(int*)ipcEmailAPI_GetParameter(hAPI, ePARAMETER_OUT, 0);
+
+ if(hAPI)
+ ipcEmailAPI_Destroy(hAPI);
+
+ EM_DEBUG_FUNC_END("err [%d]", err);
+ return err;
+}
+
+
+EXPORT_API int email_count_message(emf_mailbox_t* mailbox, int* total, int* unseen)
+{
+ EM_DEBUG_FUNC_BEGIN("mailbox[%p], total[%p], unseen[%p]", mailbox, total, unseen);
+
+ int total_count = 0;
+ int unread = 0;
+ int err = EMF_ERROR_NONE;
+
+ EM_IF_NULL_RETURN_VALUE(mailbox, EMF_ERROR_INVALID_PARAM);
+ EM_IF_NULL_RETURN_VALUE(total, EMF_ERROR_INVALID_PARAM);
+ EM_IF_NULL_RETURN_VALUE(unseen, EMF_ERROR_INVALID_PARAM);
+
+ if (!em_storage_get_mail_count(mailbox->account_id, mailbox->name, &total_count, &unread, true, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_get_mail_count Failed");
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ } else {
+ *total = total_count;
+ *unseen = unread;
+ }
+ EM_DEBUG_FUNC_END("err [%d]", err);
+ return err;
+}
+
+
+
+
+EXPORT_API int email_count_message_all_mailboxes(emf_mailbox_t* mailbox, int* total, int* unseen)
+{
+ EM_DEBUG_FUNC_BEGIN("mailbox[%p], total[%p], unseen[%p]", mailbox, total, unseen);
+
+ int total_count = 0;
+ int unread = 0;
+ int err = EMF_ERROR_NONE;
+
+ EM_IF_NULL_RETURN_VALUE(mailbox, EMF_ERROR_INVALID_PARAM);
+ EM_IF_NULL_RETURN_VALUE(total, EMF_ERROR_INVALID_PARAM);
+ EM_IF_NULL_RETURN_VALUE(unseen, EMF_ERROR_INVALID_PARAM);
+ EM_IF_ACCOUNT_ID_NULL(mailbox->account_id, EMF_ERROR_INVALID_PARAM);
+
+ if (!em_storage_get_mail_count(mailbox->account_id, NULL, &total_count, &unread, true, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_get_mail_count Failed");
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ } else {
+ *total = total_count;
+ *unseen = unread;
+ }
+ EM_DEBUG_FUNC_END("err [%d]", err);
+ return err;
+}
+
+
+
+EXPORT_API int email_delete_message(emf_mailbox_t* mailbox, int *mail_ids, int num, int from_server)
+{
+ EM_DEBUG_FUNC_BEGIN("mailbox[%p], mail_id[%p], num[%d], from_server[%d]", mailbox, mail_ids, num, from_server);
+
+ char* mailbox_stream = NULL;
+ int size = 0;
+ void *return_from_ipc = NULL;
+ int err = EMF_ERROR_NONE;
+ HIPC_API hAPI = NULL;
+
+ EM_IF_NULL_RETURN_VALUE(mailbox, EMF_ERROR_INVALID_PARAM);
+ EM_IF_NULL_RETURN_VALUE(mail_ids, EMF_ERROR_INVALID_PARAM);
+ EM_IF_ACCOUNT_ID_NULL(mailbox->account_id, EMF_ERROR_INVALID_PARAM);
+
+ if (num <= 0) {
+ EM_DEBUG_EXCEPTION("num = %d", num);
+ err = EMF_ERROR_INVALID_PARAM;
+ return err;
+ }
+
+ hAPI = ipcEmailAPI_Create(_EMAIL_API_DELETE_MAIL);
+
+ if(!hAPI) {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_Create failed");
+ err = EMF_ERROR_NULL_VALUE;
+ goto FINISH_OFF;
+ }
+
+ /* mailbox */
+ mailbox_stream = em_convert_mailbox_to_byte_stream(mailbox, &size);
+
+ if(!mailbox_stream) {
+ EM_DEBUG_EXCEPTION("em_convert_mailbox_to_byte_stream failed");
+ err = EMF_ERROR_NULL_VALUE;
+ goto FINISH_OFF;
+ }
+
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, mailbox_stream, size)) {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ /* Number of mail_ids */
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, (char*)&num, sizeof(int))) {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ /* set of mail_ids */
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, (char*)mail_ids, num * sizeof(int))) {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ /* from-server */
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, (char*)&from_server, sizeof(int))) {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ if(!ipcEmailProxy_ExecuteAPI(hAPI)) {
+ EM_DEBUG_EXCEPTION("ipcEmailProxy_ExecuteAPI failed");
+ err = EMF_ERROR_IPC_SOCKET_FAILURE;
+ goto FINISH_OFF;
+ }
+
+ return_from_ipc = ipcEmailAPI_GetParameter(hAPI, ePARAMETER_OUT, 0);
+
+ if(return_from_ipc) {
+ err = *(int*)return_from_ipc;
+ }
+ else {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_GetParameter failed");
+ err = EMF_ERROR_IPC_SOCKET_FAILURE;
+ goto FINISH_OFF;
+ }
+
+FINISH_OFF:
+ if(hAPI)
+ ipcEmailAPI_Destroy(hAPI);
+
+ EM_SAFE_FREE(mailbox_stream);
+
+ EM_DEBUG_FUNC_END("err [%d]", err);
+ return err;
+}
+
+
+EXPORT_API int email_delete_all_message_in_mailbox(emf_mailbox_t* mailbox, int from_server)
+{
+ EM_DEBUG_FUNC_BEGIN("mailbox[%p], from_server[%d]", mailbox, from_server);
+
+ char* mailbox_stream = NULL;
+ int size = 0;
+ int err = EMF_ERROR_NONE;
+ void *return_from_ipc = NULL;
+ HIPC_API hAPI = NULL;
+
+ EM_IF_NULL_RETURN_VALUE(mailbox, EMF_ERROR_INVALID_PARAM);
+ EM_IF_ACCOUNT_ID_NULL(mailbox->account_id, EMF_ERROR_INVALID_PARAM);
+
+ hAPI =ipcEmailAPI_Create(_EMAIL_API_DELETE_ALL_MAIL);
+
+ if(!hAPI) {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_Create failed");
+ err = EMF_ERROR_NULL_VALUE;
+ goto FINISH_OFF;
+ }
+
+ mailbox_stream = em_convert_mailbox_to_byte_stream(mailbox, &size);
+
+ if(!mailbox_stream) {
+ EM_DEBUG_EXCEPTION("em_convert_mailbox_to_byte_stream failed");
+ err = EMF_ERROR_NULL_VALUE;
+ goto FINISH_OFF;
+ }
+
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, mailbox_stream, size)) {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, (char*)&from_server, sizeof(int))){
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ if(!ipcEmailProxy_ExecuteAPI(hAPI)) {
+ EM_DEBUG_EXCEPTION("ipcEmailProxy_ExecuteAPI failed");
+ err = EMF_ERROR_IPC_SOCKET_FAILURE;
+ goto FINISH_OFF;
+ }
+
+ return_from_ipc = ipcEmailAPI_GetParameter(hAPI, ePARAMETER_OUT, 0);
+ if(return_from_ipc) {
+ err = *(int*)return_from_ipc;
+ }
+ else {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_GetParameter failed");
+ err = EMF_ERROR_IPC_SOCKET_FAILURE;
+ goto FINISH_OFF;
+ }
+
+FINISH_OFF:
+
+ if(hAPI)
+ ipcEmailAPI_Destroy(hAPI);
+
+ EM_SAFE_FREE(mailbox_stream);
+
+ EM_DEBUG_FUNC_END("err [%d]", err);
+ return err;
+}
+
+
+
+EXPORT_API int email_add_attachment( emf_mailbox_t* mailbox, int mail_id, emf_attachment_info_t* attachment)
+{
+ EM_DEBUG_FUNC_BEGIN("mailbox[%p], mail_id[%d], attachment[%p]", mailbox, mail_id, attachment);
+ int err = EMF_ERROR_NONE;
+ char* mailbox_stream = NULL;
+ char* pAttchStream = NULL;
+ int size = 0;
+ void *return_from_ipc = NULL;
+ HIPC_API hAPI = NULL;
+
+ EM_IF_NULL_RETURN_VALUE(mailbox, EMF_ERROR_INVALID_PARAM);
+ EM_IF_NULL_RETURN_VALUE(mail_id, EMF_ERROR_INVALID_PARAM);
+ EM_IF_NULL_RETURN_VALUE(attachment, EMF_ERROR_INVALID_PARAM);
+ EM_IF_ACCOUNT_ID_NULL(mailbox->account_id, EMF_ERROR_INVALID_PARAM);
+
+ hAPI = ipcEmailAPI_Create(_EMAIL_API_ADD_ATTACHMENT);
+
+ if(!hAPI) {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_Create failed");
+ err = EMF_ERROR_NULL_VALUE;
+ goto FINISH_OFF;
+ }
+
+ /* Mailbox */
+ mailbox_stream = em_convert_mailbox_to_byte_stream(mailbox, &size);
+
+ if(!mailbox_stream) {
+ EM_DEBUG_EXCEPTION("em_convert_mailbox_to_byte_stream failed");
+ err = EMF_ERROR_NULL_VALUE;
+ goto FINISH_OFF;
+ }
+
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, mailbox_stream, size)) {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ /* mail_id */
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, (char*)&mail_id, sizeof(int))) {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ /* Attachment */
+ pAttchStream = em_convert_attachment_info_to_byte_stream(attachment, &size);
+
+ if(!pAttchStream) {
+ EM_DEBUG_EXCEPTION("em_convert_attachment_info_to_byte_stream failed");
+ err = EMF_ERROR_NULL_VALUE;
+ goto FINISH_OFF;
+ }
+
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, pAttchStream, size)){
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ /* Execute API */
+ if(!ipcEmailProxy_ExecuteAPI(hAPI)) {
+ EM_DEBUG_EXCEPTION("ipcEmailProxy_ExecuteAPI failed");
+ err = EMF_ERROR_IPC_SOCKET_FAILURE;
+ goto FINISH_OFF;
+ }
+
+ return_from_ipc = ipcEmailAPI_GetParameter(hAPI, ePARAMETER_OUT, 0);
+ if(return_from_ipc) {
+ err = *(int*)return_from_ipc;
+ }
+ else {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_GetParameter failed");
+ err = EMF_ERROR_IPC_SOCKET_FAILURE;
+ goto FINISH_OFF;
+ }
+
+ if(EMF_ERROR_NONE == err) {
+ return_from_ipc = ipcEmailAPI_GetParameter(hAPI, ePARAMETER_OUT, 1);
+ if(return_from_ipc) {
+ attachment->attachment_id = *(int*)return_from_ipc;
+ }
+ else {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_GetParameter failed");
+ err = EMF_ERROR_IPC_SOCKET_FAILURE;
+ goto FINISH_OFF;
+ }
+ }
+
+FINISH_OFF:
+ EM_SAFE_FREE(mailbox_stream);
+ EM_SAFE_FREE(pAttchStream);
+
+ if(hAPI)
+ ipcEmailAPI_Destroy(hAPI);
+
+ EM_DEBUG_FUNC_END("err [%d]", err);
+ return err;
+ }
+
+
+EXPORT_API int email_delete_attachment(emf_mailbox_t * mailbox, int mail_id, const char *attachment_id)
+{
+ EM_DEBUG_FUNC_BEGIN("mailbox[%p], mail_id[%d], attachment_id[%s]", mailbox, mail_id, attachment_id);
+ int err = EMF_ERROR_NONE;
+ char* mailbox_stream = NULL;
+ int size = 0;
+ void *return_from_ipc = NULL;
+ HIPC_API hAPI = NULL;
+
+ EM_IF_NULL_RETURN_VALUE(mailbox, EMF_ERROR_INVALID_PARAM);
+ EM_IF_NULL_RETURN_VALUE(mail_id, EMF_ERROR_INVALID_PARAM);
+ EM_IF_NULL_RETURN_VALUE(attachment_id, EMF_ERROR_INVALID_PARAM);
+
+ hAPI = ipcEmailAPI_Create(_EMAIL_API_DELETE_ATTACHMENT);
+
+ if(!hAPI) {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_Create failed");
+ err = EMF_ERROR_NULL_VALUE;
+ goto FINISH_OFF;
+ }
+
+ /* Mailbox */
+ mailbox_stream = em_convert_mailbox_to_byte_stream(mailbox, &size);
+
+ if(!mailbox_stream) {
+ EM_DEBUG_EXCEPTION("em_convert_mailbox_to_byte_stream failed");
+ err = EMF_ERROR_NULL_VALUE;
+ goto FINISH_OFF;
+ }
+
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, mailbox_stream, size)) {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ /* mail_id */
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, (char*)&mail_id, sizeof(int))) {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ /* attachment_id */
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, (char*)attachment_id, strlen(attachment_id))) {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ /* Execute API */
+ if(!ipcEmailProxy_ExecuteAPI(hAPI)) {
+ EM_DEBUG_EXCEPTION("ipcEmailProxy_ExecuteAPI failed");
+ err = EMF_ERROR_IPC_SOCKET_FAILURE;
+ goto FINISH_OFF;
+ }
+
+ return_from_ipc = ipcEmailAPI_GetParameter(hAPI, ePARAMETER_OUT, 0);
+ if(return_from_ipc) {
+ err = *(int*)return_from_ipc;
+ }
+ else {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_GetParameter failed");
+ err = EMF_ERROR_IPC_SOCKET_FAILURE;
+ goto FINISH_OFF;
+ }
+
+FINISH_OFF:
+ if(hAPI)
+ ipcEmailAPI_Destroy(hAPI);
+
+ EM_SAFE_FREE(mailbox_stream);
+
+ return err;
+}
+
+/* -----------------------------------------------------------
+ Mail Search API
+ -----------------------------------------------------------*/
+
+EXPORT_API int email_query_mails(char *conditional_clause_string, emf_mail_data_t** mail_list, int *result_count)
+{
+ EM_DEBUG_FUNC_BEGIN("conditional_clause_string [%s], mail_list [%p], result_count [%p]", conditional_clause_string, mail_list, result_count);
+
+ int err = EMF_ERROR_NONE;
+ emf_mail_tbl_t *result_mail_tbl;
+
+ EM_IF_NULL_RETURN_VALUE(result_count, EMF_ERROR_INVALID_PARAM);
+ EM_IF_NULL_RETURN_VALUE(conditional_clause_string, EMF_ERROR_INVALID_PARAM);
+
+ if (!em_storage_query_mail_tbl(conditional_clause_string, true, &result_mail_tbl, result_count, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_query_mail_list failed [%d]", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+
+ if(!em_convert_mail_tbl_to_mail_data(result_mail_tbl, *result_count, mail_list, &err)) {
+ EM_DEBUG_EXCEPTION("em_convert_mail_tbl_to_mail_data failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+FINISH_OFF:
+ if(result_mail_tbl && !em_storage_free_mail(&result_mail_tbl, *result_count, &err))
+ EM_DEBUG_EXCEPTION("em_storage_free_mail failed [%d]", err);
+
+ EM_DEBUG_FUNC_END("err [%d]", err);
+ return err;
+}
+
+EXPORT_API int email_query_message_ex(char *conditional_clause_string, emf_mail_list_item_t** mail_list, int *result_count)
+{
+ EM_DEBUG_FUNC_BEGIN("conditional_clause_string [%s], mail_list [%p], result_count [%p]", conditional_clause_string, mail_list, result_count);
+
+ int err = EMF_ERROR_NONE;
+
+ EM_IF_NULL_RETURN_VALUE(result_count, EMF_ERROR_INVALID_PARAM);
+ EM_IF_NULL_RETURN_VALUE(conditional_clause_string, EMF_ERROR_INVALID_PARAM);
+
+ if (!em_storage_query_mail_list(conditional_clause_string, true, mail_list, result_count, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_query_mail_list failed [%d]", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+
+FINISH_OFF:
+ EM_DEBUG_FUNC_END("err [%d]", err);
+ return err;
+}
+
+
+/* -----------------------------------------------------------
+ Mail Get Info API
+ -----------------------------------------------------------*/
+EXPORT_API int email_get_info(emf_mailbox_t* mailbox, int mail_id, emf_mail_info_t** info)
+{
+ EM_DEBUG_FUNC_BEGIN("mailbox[%p], mail_id[%d], info[%p]", mailbox, mail_id, info);
+
+ int err = EMF_ERROR_NONE;
+
+ EM_IF_NULL_RETURN_VALUE(mailbox, EMF_ERROR_INVALID_PARAM);
+ EM_IF_NULL_RETURN_VALUE(info, EMF_ERROR_INVALID_PARAM);
+
+ if (mail_id <=0) {
+ EM_DEBUG_EXCEPTION("Invalid Mail ID [%d]", mail_id);
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ if (!em_core_mail_get_info(mail_id, info, &err)) {
+ EM_DEBUG_EXCEPTION("em_core_mail_get_info failed [%d", err);
+ goto FINISH_OFF;
+ }
+
+FINISH_OFF:
+ EM_DEBUG_FUNC_END("err [%d]", err);
+ return err;
+}
+
+
+EXPORT_API int email_free_mail_info(emf_mail_info_t** info_list, int count)
+{
+ EM_DEBUG_FUNC_BEGIN("info_list[%p], count[%d]", info_list, count);
+
+ int err = EMF_ERROR_NONE;
+
+ if(count > 0) {
+ if (!info_list || !*info_list) {
+ EM_DEBUG_EXCEPTION("info_list[%p]", info_list);
+ return EMF_ERROR_INVALID_PARAM;
+ }
+
+ emf_mail_info_t* p = *info_list;
+ int i = 0;
+
+ for (; i < count; i++) {
+ EM_SAFE_FREE(p[i].sid);
+ }
+
+ EM_SAFE_FREE(p);
+ *info_list = NULL;
+ }
+ EM_DEBUG_FUNC_END("err [%d]", err);
+ return err;
+
+}
+
+
+
+
+EXPORT_API int email_get_header_info(emf_mailbox_t* mailbox, int mail_id, emf_mail_head_t** head)
+{
+ EM_DEBUG_FUNC_BEGIN("mailbox[%p], mail_id[%d], head[%p]", mailbox, mail_id, head);
+
+ int err = EMF_ERROR_NONE;
+
+ EM_IF_NULL_RETURN_VALUE(mailbox, EMF_ERROR_INVALID_PARAM);
+ EM_IF_NULL_RETURN_VALUE(mail_id, EMF_ERROR_INVALID_PARAM);
+
+ if (!em_core_mail_get_header(mail_id, head, &err) || !head) {
+ EM_DEBUG_EXCEPTION("em_core_mail_get_mail failed [%d]", err);
+ return err;
+ }
+ EM_DEBUG_FUNC_END("err [%d]", err);
+ return err;
+ }
+
+
+
+EXPORT_API int email_free_header_info(emf_mail_head_t** head_list, int count)
+{
+ EM_DEBUG_FUNC_BEGIN("head_list[%p], count[%d]", head_list, count);
+
+ int err = EMF_ERROR_NONE;
+
+ if(count > 0) {
+ if (!head_list || !*head_list) {
+ EM_DEBUG_EXCEPTION("head_list[%p], count[%d]", head_list, count);
+ err = EMF_ERROR_INVALID_PARAM;
+ return err;
+ }
+
+ emf_mail_head_t* p = *head_list;
+ int i=0;
+ if (p) {
+ for (; i < count; i++) {
+ EM_SAFE_FREE(p[i].mid);
+ EM_SAFE_FREE(p[i].subject);
+ EM_SAFE_FREE(p[i].to);
+ EM_SAFE_FREE(p[i].from);
+ EM_SAFE_FREE(p[i].cc);
+ EM_SAFE_FREE(p[i].bcc);
+ EM_SAFE_FREE(p[i].reply_to);
+ EM_SAFE_FREE(p[i].return_path);
+ }
+
+ EM_SAFE_FREE(p);
+ *head_list = NULL;
+ }
+ }
+ EM_DEBUG_FUNC_END("err [%d]", err);
+ return err;
+}
+
+
+EXPORT_API int email_get_body_info(emf_mailbox_t* mailbox, int mail_id, emf_mail_body_t** body)
+{
+ EM_DEBUG_FUNC_BEGIN("mailbox[%p], mail_id[%d], body[%p]", mailbox, mail_id, body);
+ char* mailbox_stream = NULL;
+ char* pBodyStream = NULL;
+ emf_mail_body_t* pBody = NULL;
+ int nSize =0;
+ void *return_from_ipc = NULL;
+ int err = EMF_ERROR_NONE;
+ int size = 0;
+
+ EM_IF_NULL_RETURN_VALUE(mailbox, EMF_ERROR_INVALID_PARAM);
+ EM_IF_NULL_RETURN_VALUE(mail_id, EMF_ERROR_INVALID_PARAM);
+ EM_IF_NULL_RETURN_VALUE(body, EMF_ERROR_INVALID_PARAM);
+ EM_IF_ACCOUNT_ID_NULL(mailbox->account_id, EMF_ERROR_INVALID_PARAM);
+
+ HIPC_API hAPI = ipcEmailAPI_Create(_EMAIL_API_GET_BODY_INFO);
+
+ EM_IF_NULL_RETURN_VALUE(hAPI, EMF_ERROR_NULL_VALUE);
+
+ /* Mailbox */
+ mailbox_stream = em_convert_mailbox_to_byte_stream(mailbox, &size);
+
+ if(!mailbox_stream) {
+ EM_DEBUG_EXCEPTION("em_convert_mailbox_to_byte_stream failed");
+ err = EMF_ERROR_NULL_VALUE;
+ goto FINISH_OFF;
+ }
+
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, mailbox_stream, size)) {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ /* mail_id */
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, (char*)&mail_id, sizeof(int))) {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ /* Execute API */
+ if(!ipcEmailProxy_ExecuteAPI(hAPI)) {
+ EM_DEBUG_EXCEPTION("ipcEmailProxy_ExecuteAPI failed");
+ err = EMF_ERROR_IPC_SOCKET_FAILURE;
+ goto FINISH_OFF;
+ }
+
+ return_from_ipc = ipcEmailAPI_GetParameter(hAPI, ePARAMETER_OUT, 0);
+ if(return_from_ipc) {
+ err = *(int*)return_from_ipc;
+ }
+ else {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_GetParameter failed");
+ err = EMF_ERROR_IPC_SOCKET_FAILURE;
+ goto FINISH_OFF;
+ }
+
+ if(EMF_ERROR_NONE == err) {
+ nSize = ipcEmailAPI_GetParameterLength(hAPI, ePARAMETER_OUT, 1);
+
+ if(nSize > 0) {
+ pBodyStream = (char*)em_core_malloc(nSize + 1);
+ if(!pBodyStream) {
+ EM_DEBUG_EXCEPTION("em_core_malloc failed");
+ err = EMF_ERROR_NULL_VALUE;
+ goto FINISH_OFF;
+ }
+
+ return_from_ipc = ipcEmailAPI_GetParameter(hAPI, ePARAMETER_OUT, 1);
+
+ if(!return_from_ipc) {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_GetParameter failed");
+ err = EMF_ERROR_NULL_VALUE;
+ goto FINISH_OFF;
+ }
+
+ memcpy(pBodyStream, return_from_ipc, nSize);
+
+ /* Memory is not yet allocated for info */
+ pBody = (emf_mail_body_t*)em_core_malloc(sizeof(emf_mail_body_t));
+ if(!pBody) {
+ EM_DEBUG_EXCEPTION("em_core_malloc failed");
+ err = EMF_ERROR_NULL_VALUE;
+ goto FINISH_OFF;
+ }
+ em_convert_byte_stream_to_mail_body(pBodyStream, pBody);
+ }
+
+ if(!pBody) {
+ EM_DEBUG_EXCEPTION("EMF_ERROR_NULL_VALUE");
+ err = EMF_ERROR_NULL_VALUE;
+ goto FINISH_OFF;
+ }
+
+ *body = pBody;
+ }
+
+FINISH_OFF:
+ EM_SAFE_FREE(pBodyStream);
+ EM_SAFE_FREE(mailbox_stream);
+
+ if(hAPI)
+ ipcEmailAPI_Destroy(hAPI);
+
+ EM_DEBUG_FUNC_END("err [%d]", err);
+ return err;
+}
+
+
+
+EXPORT_API int email_free_body_info(emf_mail_body_t** body_list, int count)
+{
+ EM_DEBUG_FUNC_BEGIN("body_list[%p], count[%d]", body_list, count);
+ int err = EMF_ERROR_NONE;
+
+ if( count <= 0 ) {
+ EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
+ return EMF_ERROR_INVALID_PARAM;
+ }
+
+ if (!body_list || !*body_list) {
+ EM_DEBUG_EXCEPTION("body_list[%p]", body_list);
+ err = EMF_ERROR_INVALID_PARAM;
+ return err;
+ }
+
+ emf_mail_body_t* p = *body_list;
+ int i = 0;
+
+ for (; i < count; i++) {
+ EM_SAFE_FREE(p[i].plain);
+ EM_SAFE_FREE(p[i].html);
+ if (p[i].attachment)
+ email_free_attachment_info(&p[i].attachment);
+ }
+
+ EM_SAFE_FREE(p); *body_list = NULL;
+
+ EM_DEBUG_FUNC_END("err [%d]", err);
+ return err;
+
+}
+
+
+EXPORT_API int email_get_attachment_info(emf_mailbox_t* mailbox, int mail_id, const char* attachment_id, emf_attachment_info_t** attachment)
+{
+ EM_DEBUG_FUNC_BEGIN("mailbox[%p], mail_id[%d], attachment_id[%s], attachment[%p]", mailbox, mail_id, attachment_id, attachment);
+
+ int err = EMF_ERROR_NONE;
+ int size = 0;
+ int nSize = 0;
+ char* mailbox_stream = NULL;
+ char* pAttchStream = NULL;
+ emf_attachment_info_t* pAttch = NULL;
+ void *return_from_ipc = NULL;
+
+ EM_IF_NULL_RETURN_VALUE(mailbox, EMF_ERROR_INVALID_PARAM);
+ EM_IF_NULL_RETURN_VALUE(mail_id, EMF_ERROR_INVALID_PARAM);
+ EM_IF_NULL_RETURN_VALUE(attachment_id, EMF_ERROR_INVALID_PARAM);
+ EM_IF_NULL_RETURN_VALUE(attachment, EMF_ERROR_INVALID_PARAM);
+ EM_IF_ACCOUNT_ID_NULL(mailbox->account_id, EMF_ERROR_INVALID_PARAM);
+
+ HIPC_API hAPI = ipcEmailAPI_Create(_EMAIL_API_GET_ATTACHMENT);
+
+ EM_IF_NULL_RETURN_VALUE(hAPI, EMF_ERROR_NULL_VALUE);
+
+ /* Mailbox */
+ mailbox_stream = em_convert_mailbox_to_byte_stream(mailbox, &size);
+
+ if(!mailbox_stream) {
+ EM_DEBUG_EXCEPTION("em_convert_mailbox_to_byte_stream failed");
+ err = EMF_ERROR_NULL_VALUE;
+ goto FINISH_OFF;
+ }
+
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, mailbox_stream, size)) {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ /* mail_id */
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, (char*)&mail_id, sizeof(int))) {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+
+ /* attachment_id */
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, (char*)attachment_id, strlen(attachment_id))) {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ /* Execute API */
+ if(!ipcEmailProxy_ExecuteAPI(hAPI)) {
+ EM_DEBUG_EXCEPTION("ipcEmailProxy_ExecuteAPI failed");
+ err = EMF_ERROR_IPC_SOCKET_FAILURE;
+ goto FINISH_OFF;
+ }
+
+ return_from_ipc = ipcEmailAPI_GetParameter(hAPI, ePARAMETER_OUT, 0);
+ if(return_from_ipc) {
+ err = *(int*)return_from_ipc;
+ }
+ else {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_GetParameter failed");
+ err = EMF_ERROR_IPC_SOCKET_FAILURE;
+ goto FINISH_OFF;
+ }
+
+ if(EMF_ERROR_NONE == err) {
+ nSize = ipcEmailAPI_GetParameterLength(hAPI, ePARAMETER_OUT, 1);
+ if(nSize > 0) {
+ pAttchStream = (char*)em_core_malloc(nSize+1);
+
+ if(!pAttchStream) {
+ EM_DEBUG_EXCEPTION("em_core_malloc failed");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ return_from_ipc = ipcEmailAPI_GetParameter(hAPI, ePARAMETER_OUT, 1);
+
+ if(!return_from_ipc) {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_GetParameter failed");
+ err = EMF_ERROR_NULL_VALUE;
+ goto FINISH_OFF;
+ }
+
+ memcpy(pAttchStream, return_from_ipc, nSize);
+ em_convert_byte_stream_to_attachment_info(pAttchStream, 1, &pAttch);
+ }
+
+ if(!pAttch) {
+ EM_DEBUG_EXCEPTION("EMF_ERROR_NULL_VALUE");
+ err = EMF_ERROR_NULL_VALUE;
+ goto FINISH_OFF;
+ }
+
+ *attachment = pAttch;
+ }
+
+FINISH_OFF:
+ EM_SAFE_FREE(pAttchStream);
+
+ if(hAPI)
+ ipcEmailAPI_Destroy(hAPI);
+
+ EM_DEBUG_FUNC_END("err [%d]", err);
+ return err;
+
+}
+
+EXPORT_API int email_get_attachment_data_list(int input_mail_id, emf_attachment_data_t **output_attachment_data, int *output_attachment_count)
+{
+ EM_DEBUG_FUNC_BEGIN("input_mail_id[%d], output_attachment_data[%p], output_attachment_count[%p]", input_mail_id, output_attachment_data, output_attachment_count);
+ int err = EMF_ERROR_NONE;
+
+ if((err = em_core_get_attachment_data_list(input_mail_id, output_attachment_data, output_attachment_count)) != EMF_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("em_core_get_attachment_data_list failed [%d]", err);
+ }
+
+ EM_DEBUG_FUNC_END("err [%d]", err);
+ return err;
+}
+
+EXPORT_API int email_free_attachment_info(emf_attachment_info_t** atch_info)
+{
+ EM_DEBUG_FUNC_BEGIN("atch_info[%p]", atch_info);
+
+ int err = EMF_ERROR_NONE;
+
+ if (!atch_info || !*atch_info)
+ return EMF_ERROR_INVALID_PARAM;
+
+ emf_attachment_info_t* p = *atch_info;
+ emf_attachment_info_t* t;
+
+ while (p) {
+ EM_SAFE_FREE(p->name);
+ EM_SAFE_FREE(p->savename);
+ t = p->next;
+ EM_SAFE_FREE(p);
+ p = t;
+ }
+ EM_DEBUG_FUNC_END("err [%d]", err);
+ return err;
+}
+
+EXPORT_API int email_free_attachment_data(emf_attachment_data_t **attachment_data_list, int attachment_data_count)
+{
+ EM_DEBUG_FUNC_BEGIN("attachment_data_list[%p], attachment_data_count[%d]", attachment_data_list, attachment_data_count);
+
+ int err = EMF_ERROR_NONE;
+
+ em_core_free_attachment_data(attachment_data_list, attachment_data_count, &err);
+
+ EM_DEBUG_FUNC_END("err [%d]", err);
+ return err;
+}
+
+
+EXPORT_API int email_get_mails(int account_id , const char *mailbox_name, int thread_id, int start_index, int limit_count, emf_sort_type_t sorting, emf_mail_data_t** mail_list, int* result_count)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ int err = EMF_ERROR_NONE;
+ emf_mail_tbl_t *mail_tbl_list = NULL;
+ EM_IF_NULL_RETURN_VALUE(result_count, EMF_ERROR_INVALID_PARAM);
+
+ if( account_id < ALL_ACCOUNT) {
+ EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
+ err = EMF_ERROR_INVALID_PARAM ;
+ goto FINISH_OFF;
+ }
+
+ if (!em_storage_get_mails(account_id, (char*)mailbox_name, NULL, thread_id, start_index, limit_count, sorting, true, &mail_tbl_list, result_count, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_get_mails failed [%d]", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+
+ if(!em_convert_mail_tbl_to_mail_data(mail_tbl_list, *result_count, mail_list, &err)) {
+ EM_DEBUG_EXCEPTION("em_convert_mail_tbl_to_mail_data failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+FINISH_OFF:
+ if(mail_tbl_list && !em_storage_free_mail(&mail_tbl_list, *result_count, &err))
+ EM_DEBUG_EXCEPTION("em_storage_free_mail failed [%d]", err);
+
+ EM_DEBUG_FUNC_END("err [%d]", err);
+ return err;
+}
+
+EXPORT_API int email_get_mail_list_ex(int account_id , const char *mailbox_name, int thread_id, int start_index, int limit_count, emf_sort_type_t sorting, emf_mail_list_item_t** mail_list, int* result_count)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ int err = EMF_ERROR_NONE;
+
+ EM_IF_NULL_RETURN_VALUE(result_count, EMF_ERROR_INVALID_PARAM);
+
+ if( account_id < ALL_ACCOUNT) {
+ EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
+ return EMF_ERROR_INVALID_PARAM;
+ }
+
+ if (!em_storage_get_mail_list(account_id, (char*) mailbox_name, NULL, thread_id, start_index, limit_count, 0, NULL, sorting, true, mail_list, result_count, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_get_mail_list failed [%d]", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+
+FINISH_OFF:
+ EM_DEBUG_FUNC_END("err [%d]", err);
+ return err;
+}
+
+EXPORT_API int email_find_mail (int account_id , const char *mailbox_name, int thread_id,
+ int search_type, char *search_value, int start_index, int limit_count,
+ emf_sort_type_t sorting, emf_mail_list_item_t** mail_list, int* result_count)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ int err = EMF_ERROR_NONE;
+ int search_num = 0;
+ emf_mail_list_item_t* mail_list_item = NULL;
+
+ EM_IF_NULL_RETURN_VALUE(mail_list, EMF_ERROR_INVALID_PARAM);
+ EM_IF_NULL_RETURN_VALUE(result_count, EMF_ERROR_INVALID_PARAM);
+ EM_IF_NULL_RETURN_VALUE(search_value, EMF_ERROR_INVALID_PARAM);
+
+ switch ( search_type ) {
+ case EMF_SEARCH_FILTER_SUBJECT:
+ case EMF_SEARCH_FILTER_SENDER:
+ case EMF_SEARCH_FILTER_RECIPIENT:
+ case EMF_SEARCH_FILTER_ALL:
+ break;
+ default:
+ EM_DEBUG_EXCEPTION("Invalid search filter type[%d]", search_type);
+ err = EMF_ERROR_INVALID_PARAM;
+ return err;
+ }
+
+ if (!em_storage_get_searched_mail_list(account_id, (char*)mailbox_name, thread_id, search_type, search_value, start_index, limit_count, sorting, true, &mail_list_item, &search_num, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_search_mails -- Failed [%d]", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+
+ *mail_list = mail_list_item;
+ *result_count = search_num;
+
+FINISH_OFF:
+ EM_DEBUG_FUNC_END("err [%d]", err);
+ return err;
+}
+
+EXPORT_API int email_get_mail_by_address(int account_id , const char *mailbox_name, emf_email_address_list_t* addr_list,
+ int start_index, int limit_count, int search_type, const char *search_value, emf_sort_type_t sorting, emf_mail_list_item_t** mail_list, int* result_count)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int err = EMF_ERROR_NONE;
+
+ emf_mail_list_item_t* mail_list_item = NULL;
+
+ EM_IF_NULL_RETURN_VALUE(mail_list, EMF_ERROR_INVALID_PARAM);
+ EM_IF_NULL_RETURN_VALUE(result_count, EMF_ERROR_INVALID_PARAM);
+
+ if( account_id < ALL_ACCOUNT) {
+ EM_DEBUG_EXCEPTION("Invalid account id param");
+ err = EMF_ERROR_INVALID_PARAM ;
+ return err;
+ }
+
+ if (!em_storage_get_mail_list(account_id, (char*)mailbox_name, addr_list, EMF_LIST_TYPE_NORMAL, start_index, limit_count, search_type, search_value, sorting, true, &mail_list_item, result_count, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_get_mail_list failed [%d]", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+
+ *mail_list = mail_list_item;
+
+FINISH_OFF:
+ EM_DEBUG_FUNC_END("err [%d]", err);
+ return err;
+}
+
+EXPORT_API int email_get_thread_information_by_thread_id(int thread_id, emf_mail_data_t** thread_info)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int err = EMF_ERROR_NONE;
+ emf_mail_tbl_t *mail_table_data = NULL;
+
+ EM_IF_NULL_RETURN_VALUE(thread_info, EMF_ERROR_INVALID_PARAM);
+
+ if (!em_storage_get_thread_information(thread_id, &mail_table_data , true, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_get_thread_information failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ if(!em_convert_mail_tbl_to_mail_data(mail_table_data, 1, thread_info, &err)) {
+ EM_DEBUG_EXCEPTION("em_convert_mail_tbl_to_mail_data failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+FINISH_OFF:
+
+ if(mail_table_data && !em_storage_free_mail(&mail_table_data, 1, &err))
+ EM_DEBUG_EXCEPTION("em_storage_free_mail failed [%d]", err);
+
+ EM_DEBUG_FUNC_END("err [%d]", err);
+ return err;
+}
+
+EXPORT_API int email_get_thread_information_ex(int thread_id, emf_mail_list_item_t** thread_info)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int err = EMF_ERROR_NONE;
+ emf_mail_tbl_t *mail_table_data = NULL;
+ emf_mail_list_item_t *temp_thread_info = NULL;
+
+ EM_IF_NULL_RETURN_VALUE(thread_info, EMF_ERROR_INVALID_PARAM);
+
+ if (!em_storage_get_thread_information(thread_id, &mail_table_data , true, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_get_thread_information -- failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ temp_thread_info = em_core_malloc(sizeof(emf_mail_list_item_t));
+
+ if(!temp_thread_info) {
+ EM_DEBUG_EXCEPTION("em_core_malloc failed");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ EM_SAFE_STRNCPY(temp_thread_info->mailbox_name , mail_table_data->mailbox_name, STRING_LENGTH_FOR_DISPLAY);
+ EM_SAFE_STRNCPY(temp_thread_info->from , mail_table_data->full_address_from, STRING_LENGTH_FOR_DISPLAY);
+ EM_SAFE_STRNCPY(temp_thread_info->from_email_address , mail_table_data->email_address_sender, MAX_EMAIL_ADDRESS_LENGTH);
+ EM_SAFE_STRNCPY(temp_thread_info->recipients , mail_table_data->email_address_recipient, STRING_LENGTH_FOR_DISPLAY);
+ EM_SAFE_STRNCPY(temp_thread_info->subject , mail_table_data->subject, STRING_LENGTH_FOR_DISPLAY);
+ EM_SAFE_STRNCPY(temp_thread_info->datetime , mail_table_data->datetime, MAX_DATETIME_STRING_LENGTH);
+ EM_SAFE_STRNCPY(temp_thread_info->previewBodyText , mail_table_data->preview_text, MAX_PREVIEW_TEXT_LENGTH);
+ temp_thread_info->mail_id = mail_table_data->mail_id;
+ temp_thread_info->account_id = mail_table_data->account_id;
+ temp_thread_info->is_text_downloaded = mail_table_data->body_download_status;
+ temp_thread_info->flags_seen_field = mail_table_data->flags_seen_field;
+ temp_thread_info->priority = mail_table_data->priority;
+ temp_thread_info->save_status = mail_table_data->save_status;
+ temp_thread_info->is_locked = mail_table_data->lock_status;
+ temp_thread_info->is_report_mail = mail_table_data->report_status;
+ temp_thread_info->has_attachment = mail_table_data->attachment_count;
+ temp_thread_info->has_drm_attachment = mail_table_data->DRM_status;
+ temp_thread_info->thread_id = mail_table_data->thread_id;
+ temp_thread_info->thread_item_count = mail_table_data->thread_item_count;
+ temp_thread_info->is_meeting_request = mail_table_data->meeting_request_status;
+
+ *thread_info = temp_thread_info;
+
+FINISH_OFF:
+
+ if(mail_table_data)
+ em_storage_free_mail(&mail_table_data, 1, NULL);
+
+ EM_DEBUG_FUNC_END("err [%d]", err);
+ return err;
+}
+
+EXPORT_API int email_get_mail(emf_mailbox_t* mailbox, int mail_id, emf_mail_t** mail)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int err = EMF_ERROR_NONE;
+
+ if (!em_core_mail_get_mail(mail_id, mail, &err) || !mail)
+ EM_DEBUG_EXCEPTION("em_core_mail_get_mail failed [%d]", err);
+ EM_DEBUG_FUNC_END("err [%d]", err);
+ return err;
+}
+
+EXPORT_API int email_get_mail_data(int input_mail_id, emf_mail_data_t **output_mail_data)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int err = EMF_ERROR_NONE;
+
+ if ( ((err = em_core_get_mail_data(input_mail_id, output_mail_data)) != EMF_ERROR_NONE) || !output_mail_data)
+ EM_DEBUG_EXCEPTION("em_core_get_mail_data failed [%d]", err);
+
+ EM_DEBUG_FUNC_END("err [%d]", err);
+ return err;
+}
+
+
+/* -----------------------------------------------------------
+ Mail Flag API
+ -----------------------------------------------------------*/
+EXPORT_API int email_modify_mail_flag(int mail_id, emf_mail_flag_t new_flag, int onserver)
+{
+ EM_DEBUG_FUNC_BEGIN("mail_id[%d], on_server [ %d] ", mail_id, onserver);
+
+ int err = EMF_ERROR_NONE;
+ void *return_from_ipc = NULL;
+ int i_flag, sticky = 0;
+
+ if ( mail_id <= 0 || (onserver != 0 && onserver != 1) ) {
+ EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
+ return EMF_ERROR_INVALID_PARAM;
+ }
+
+ HIPC_API hAPI = ipcEmailAPI_Create(_EMAIL_API_MODIFY_MAIL_FLAG);
+
+ if(!hAPI) {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_Create failed");
+ err = EMF_ERROR_NULL_VALUE;
+ goto FINISH_OFF;
+ }
+
+ /* Mail ID */
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, &(mail_id), sizeof(int))) {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ /* new_flag */
+ if(!em_convert_mail_flag_to_int(new_flag, &i_flag, &err)) {
+ EM_DEBUG_EXCEPTION("em_convert_mail_flag_to_int failed ");
+ goto FINISH_OFF;
+ }
+
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, &(i_flag), sizeof(int))) {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ sticky = new_flag.sticky;
+
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, &(sticky), sizeof(int))) {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ /* onserver */
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, &(onserver), sizeof(int))) {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+
+ /* Execute API */
+ if(!ipcEmailProxy_ExecuteAPI(hAPI)) {
+ EM_DEBUG_EXCEPTION("ipcEmailProxy_ExecuteAPI failed");
+ err = EMF_ERROR_IPC_SOCKET_FAILURE;
+ goto FINISH_OFF;
+ }
+
+ return_from_ipc = ipcEmailAPI_GetParameter(hAPI, ePARAMETER_OUT, 0);
+
+ if(return_from_ipc) {
+ err = *(int*)return_from_ipc;
+ }
+ else {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_GetParameter failed");
+ err = EMF_ERROR_IPC_SOCKET_FAILURE;
+ goto FINISH_OFF;
+ }
+
+FINISH_OFF:
+ if(hAPI)
+ ipcEmailAPI_Destroy(hAPI);
+
+ EM_DEBUG_FUNC_END("err [%d]", err);
+ return err;
+}
+
+
+
+
+EXPORT_API int email_modify_seen_flag(int *mail_ids, int num, int seen_flag, int onserver)
+{
+ EM_DEBUG_FUNC_BEGIN("mail_ids[%p], num[%d],seen_flag[%d], on_server [ %d]", mail_ids, num, seen_flag, onserver);
+ EM_DEBUG_FUNC_END("EMF_ERROR_NOT_IMPLEMENTED");
+ return EMF_ERROR_NOT_IMPLEMENTED;
+}
+
+EXPORT_API int email_set_flags_field(int account_id, int *mail_ids, int num, emf_flags_field_type field_type, int value, int onserver)
+{
+ EM_DEBUG_FUNC_BEGIN("account_id [%d], mail_ids[%p], num[%d], field_type [%d], seen_flag[%d], on_server [ %d]", account_id, mail_ids, num, field_type, value, onserver);
+
+ int err = EMF_ERROR_NONE;
+ void *return_from_ipc = NULL;
+
+ EM_IF_NULL_RETURN_VALUE(mail_ids, EMF_ERROR_INVALID_PARAM);
+ if (account_id == 0 || num <= 0 || (onserver != 0 && onserver != 1)) {
+ EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
+ return EMF_ERROR_INVALID_PARAM;
+ }
+
+ HIPC_API hAPI = ipcEmailAPI_Create(_EMAIL_API_SET_FLAGS_FIELD);
+
+ if(!hAPI) {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_Create failed");
+ err = EMF_ERROR_NULL_VALUE;
+ goto FINISH_OFF;
+ }
+
+ /* account_id*/
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, (char*)&account_id, sizeof(int))) {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ /* Number of mail_ids */
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, (char*)&num, sizeof(int))) {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ /* set of mail_ids */
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, (char*)mail_ids, num * sizeof(int))) {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ /* field_type */
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, (char*)&field_type, sizeof(int))) {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ /* value */
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, (char*)&value, sizeof(int))) {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ /* onserver */
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, &(onserver), sizeof(int))) {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ /* Execute API */
+ if(!ipcEmailProxy_ExecuteAPI(hAPI)) {
+ EM_DEBUG_EXCEPTION("ipcEmailProxy_ExecuteAPI failed");
+ err = EMF_ERROR_IPC_SOCKET_FAILURE;
+ goto FINISH_OFF;
+ }
+
+ return_from_ipc = ipcEmailAPI_GetParameter(hAPI, ePARAMETER_OUT, 0);
+
+ if(return_from_ipc) {
+ err = *(int*)return_from_ipc;
+ }
+ else {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_GetParameter failed");
+ err = EMF_ERROR_IPC_SOCKET_FAILURE;
+ goto FINISH_OFF;
+ }
+
+FINISH_OFF:
+ if(hAPI)
+ ipcEmailAPI_Destroy(hAPI);
+
+ EM_DEBUG_FUNC_END("err [%d]", err);
+ return err;
+}
+
+EXPORT_API int email_modify_extra_mail_flag(int mail_id, emf_extra_flag_t new_flag)
+{
+ EM_DEBUG_FUNC_BEGIN("mail_id[%d]", mail_id);
+
+ int size = 0;
+ int err = EMF_ERROR_NONE;
+ char* pMailExtraFlagsStream = NULL;
+ void *return_from_ipc = NULL;
+
+ EM_IF_NULL_RETURN_VALUE(mail_id, EMF_ERROR_INVALID_PARAM);
+
+ pMailExtraFlagsStream = em_convert_extra_flags_to_byte_stream(new_flag, &size);
+
+ HIPC_API hAPI = ipcEmailAPI_Create(_EMAIL_API_MODIFY_MAIL_EXTRA_FLAG);
+
+ if(!hAPI) {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_Create failed");
+ err = EMF_ERROR_NULL_VALUE;
+ goto FINISH_OFF;
+ }
+
+ /* Mail ID */
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, &(mail_id), sizeof(int))) {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed ");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+ /* Flag */
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, pMailExtraFlagsStream, size)) {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed ");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ /* Execute API */
+ if(!ipcEmailProxy_ExecuteAPI(hAPI)) {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed");
+ err = EMF_ERROR_IPC_SOCKET_FAILURE;
+ goto FINISH_OFF;
+ }
+
+ return_from_ipc = ipcEmailAPI_GetParameter(hAPI, ePARAMETER_OUT, 0);
+
+ if(return_from_ipc) {
+ err = *(int*)return_from_ipc;
+ }
+ else {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_GetParameter failed");
+ err = EMF_ERROR_IPC_SOCKET_FAILURE;
+ goto FINISH_OFF;
+ }
+
+FINISH_OFF:
+ ipcEmailAPI_Destroy(hAPI);
+ EM_SAFE_FREE(pMailExtraFlagsStream);
+
+ EM_DEBUG_FUNC_END("err [%d]", err);
+ return err;
+
+}
+
+
+
+/* -----------------------------------------------------------
+ Mail Move API
+ -----------------------------------------------------------*/
+EXPORT_API int email_move_mail_to_mailbox(int *mail_ids, int num, emf_mailbox_t* mailbox)
+{
+ EM_DEBUG_FUNC_BEGIN("mail_ids[%p], num [%d], mailbox[%p]", mail_ids, num, mailbox);
+
+ int size = 0;
+ char* mailbox_stream = NULL;
+ int err = EMF_ERROR_NONE;
+ HIPC_API hAPI = NULL;
+ void *return_from_ipc = NULL;
+
+ EM_IF_NULL_RETURN_VALUE(mailbox, EMF_ERROR_INVALID_PARAM);
+ EM_IF_NULL_RETURN_VALUE(mail_ids, EMF_ERROR_INVALID_PARAM);
+ EM_IF_ACCOUNT_ID_NULL(mailbox->account_id, EMF_ERROR_INVALID_PARAM);
+
+ if (num <= 0) {
+ EM_DEBUG_LOG("num = %d", num);
+ err = EMF_ERROR_INVALID_PARAM;
+ return err;
+ }
+
+ hAPI = ipcEmailAPI_Create(_EMAIL_API_MOVE_MAIL);
+
+ if(!hAPI) {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_Create failed");
+ err = EMF_ERROR_NULL_VALUE;
+ goto FINISH_OFF;
+ }
+
+ /* Number of mail_ids */
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, (char*)&num, sizeof(int))) {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ /* set of mail_ids */
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, (char*)mail_ids, num * sizeof(int))) {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ /* Mailbox */
+ mailbox_stream = em_convert_mailbox_to_byte_stream(mailbox, &size);
+
+ if(!mailbox_stream) {
+ EM_DEBUG_EXCEPTION("em_convert_mailbox_to_byte_stream failed");
+ err = EMF_ERROR_NULL_VALUE;
+ goto FINISH_OFF;
+ }
+
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, mailbox_stream, size)) {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ /* Execute API */
+ if(!ipcEmailProxy_ExecuteAPI(hAPI)) {
+ EM_DEBUG_EXCEPTION("ipcEmailProxy_ExecuteAPI failed");
+ err = EMF_ERROR_IPC_SOCKET_FAILURE;
+ goto FINISH_OFF;
+ }
+
+ return_from_ipc = ipcEmailAPI_GetParameter(hAPI, ePARAMETER_OUT, 0);
+ if(return_from_ipc) {
+ err = *(int*)return_from_ipc;
+ }
+ else {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_GetParameter failed");
+ err = EMF_ERROR_IPC_SOCKET_FAILURE;
+ goto FINISH_OFF;
+ }
+
+FINISH_OFF:
+ EM_SAFE_FREE(mailbox_stream);
+
+ if(hAPI)
+ ipcEmailAPI_Destroy(hAPI);
+
+ EM_DEBUG_FUNC_END("err [%d]", err);
+ return err;
+}
+
+
+EXPORT_API int email_move_all_mails_to_mailbox(emf_mailbox_t* src_mailbox, emf_mailbox_t* new_mailbox)
+{
+ EM_DEBUG_FUNC_BEGIN("src_mailbox[%p] , new_mailbox[%p]", src_mailbox, new_mailbox);
+
+ int size = 0;
+ int err = EMF_ERROR_NONE;
+ char *dest_mailbox_stream = NULL;
+ char *source_mailbox_stream = NULL;
+ HIPC_API hAPI = NULL;
+ void *return_from_ipc = NULL;
+
+ EM_IF_NULL_RETURN_VALUE(src_mailbox, EMF_ERROR_INVALID_PARAM);
+ EM_IF_NULL_RETURN_VALUE(new_mailbox, EMF_ERROR_INVALID_PARAM);
+ EM_IF_ACCOUNT_ID_NULL(new_mailbox->account_id, EMF_ERROR_INVALID_PARAM);
+ EM_IF_ACCOUNT_ID_NULL(src_mailbox->account_id, EMF_ERROR_INVALID_PARAM);
+
+ hAPI = ipcEmailAPI_Create(_EMAIL_API_MOVE_ALL_MAIL);
+
+ if(!hAPI) {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_Create failed");
+ err = EMF_ERROR_NULL_VALUE;
+ goto FINISH_OFF;
+ }
+
+ /* Src Mailbox Information */
+ source_mailbox_stream = em_convert_mailbox_to_byte_stream(src_mailbox, &size);
+
+ if(!source_mailbox_stream) {
+ EM_DEBUG_EXCEPTION("em_convert_mailbox_to_byte_stream failed");
+ err = EMF_ERROR_NULL_VALUE;
+ goto FINISH_OFF;
+ }
+
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, source_mailbox_stream, size)) {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ size = 0;
+
+ /* Dst Mailbox Information */
+ dest_mailbox_stream = em_convert_mailbox_to_byte_stream(new_mailbox, &size);
+
+ if(!dest_mailbox_stream) {
+ EM_DEBUG_EXCEPTION("em_convert_mailbox_to_byte_stream failed");
+ err = EMF_ERROR_NULL_VALUE;
+ goto FINISH_OFF;
+ }
+
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, dest_mailbox_stream, size)) {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ /* Execute API */
+ if(!ipcEmailProxy_ExecuteAPI(hAPI)) {
+ EM_DEBUG_EXCEPTION("ipcEmailProxy_ExecuteAPI failed");
+ err = EMF_ERROR_IPC_SOCKET_FAILURE;
+ goto FINISH_OFF;
+ }
+
+ return_from_ipc = ipcEmailAPI_GetParameter(hAPI, ePARAMETER_OUT, 0);
+ if(return_from_ipc) {
+ err = *(int*)return_from_ipc;
+ }
+ else {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_GetParameter failed");
+ err = EMF_ERROR_IPC_SOCKET_FAILURE;
+ goto FINISH_OFF;
+ }
+
+FINISH_OFF:
+ EM_SAFE_FREE(source_mailbox_stream);
+ EM_SAFE_FREE(dest_mailbox_stream);
+
+ if(hAPI)
+ ipcEmailAPI_Destroy(hAPI);
+
+ EM_DEBUG_FUNC_END("err [%d]", err);
+ return err;
+}
+
+
+
+EXPORT_API int email_count_message_with_draft_flag(emf_mailbox_t* mailbox, int* total)
+{
+ EM_DEBUG_FUNC_BEGIN("mailbox[%p], total[%p]", mailbox, total);
+
+ int err = EMF_ERROR_NONE;
+ int total_count = 0;
+
+ EM_IF_NULL_RETURN_VALUE(mailbox, EMF_ERROR_INVALID_PARAM);
+ EM_IF_NULL_RETURN_VALUE(total, EMF_ERROR_INVALID_PARAM);
+
+ if (!em_storage_get_mail_count_with_draft_flag(mailbox->account_id, mailbox->name, &total_count, false, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_get_mail_count Failed");
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ } else {
+ *total = total_count;
+ }
+ EM_DEBUG_FUNC_END("err [%d]", err);
+ return err;
+}
+
+
+EXPORT_API int email_count_message_on_sending(emf_mailbox_t* mailbox, int* total)
+{
+ EM_DEBUG_FUNC_BEGIN("mailbox[%p], total[%p]", mailbox, total);
+ int err = EMF_ERROR_NONE;
+ int total_count = 0;
+
+
+ EM_IF_NULL_RETURN_VALUE(mailbox, EMF_ERROR_INVALID_PARAM);
+ EM_IF_NULL_RETURN_VALUE(total, EMF_ERROR_INVALID_PARAM);
+
+ if (!em_storage_get_mail_count_on_sending(mailbox->account_id, mailbox->name, &total_count, false, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_get_mail_count Failed");
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ } else
+ *total = total_count;
+ EM_DEBUG_FUNC_END("err [%d]", err);
+ return err;
+}
+
+/**
+
+ * @open
+ * @fn email_get_mail_flag(int account_id, int mail_id, emf_mail_flag_t* mail_flag)
+ * @brief Get the Mail Flag information based on the account id and Mail Id.
+ *
+ * @param[in] account_id Specifies the Account ID
+ * @param[in] mail_id Specifies the Mail id for which Flag details need to be fetched
+ * @param[in/out] mail_flag Specifies the Pointer to the structure emf_mail_flag_t.
+ * @remarks N/A
+ * @return True on Success, False on Failure.
+ */
+EXPORT_API int email_get_mail_flag(int account_id, int mail_id, emf_mail_flag_t* mail_flag)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ int err = EMF_ERROR_NONE;
+
+ if (account_id < FIRST_ACCOUNT_ID|| mail_id < 1 || mail_flag == NULL) {
+ EM_DEBUG_EXCEPTION("Invalid Param");
+ err = EMF_ERROR_INVALID_PARAM ;
+ goto FINISH_OFF;
+ }
+
+ /* Fetch the flag Information */
+ if (!em_core_fetch_flags(account_id, mail_id, mail_flag, &err)) {
+ EM_DEBUG_EXCEPTION("em_core_fetch_flags Failed [%d]", err);
+ goto FINISH_OFF;
+ }
+FINISH_OFF:
+ EM_DEBUG_FUNC_END("err [%d]", err);
+ return err;
+
+}
+
+
+
+EXPORT_API int email_free_mailbox(emf_mailbox_t** mailbox_list, int count)
+{
+ EM_DEBUG_FUNC_BEGIN("mailbox_list[%p], count[%d]", mailbox_list, count);
+ int err = EMF_ERROR_NONE;
+
+ if (count <= 0 || !mailbox_list || !*mailbox_list) {
+ EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ emf_mailbox_t *p = *mailbox_list;
+ int i;
+
+ for (i = 0; i < count; i++) {
+ EM_SAFE_FREE(p[i].name);
+ EM_SAFE_FREE(p[i].alias);
+ EM_SAFE_FREE(p[i].account_name);
+ }
+
+ EM_SAFE_FREE(p);
+ *mailbox_list = NULL;
+
+FINISH_OFF:
+ EM_DEBUG_FUNC_END("err [%d]", err);
+ return err;
+
+}
+
+
+EXPORT_API int email_free_mail(emf_mail_t** mail_list, int count)
+{
+ EM_DEBUG_FUNC_BEGIN("mail_list[%p], count[%d]", mail_list, count);
+ int err = EMF_ERROR_NONE;
+
+ if (count <= 0 || !mail_list || !*mail_list) {
+ EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
+ err = EMF_ERROR_INVALID_PARAM;
+ return err;
+ }
+
+ emf_mail_t* p = *mail_list;
+ int i = 0;
+
+ for (; i < count; i++) {
+ if (p[i].info)
+ em_core_mail_info_free(&p[i].info, 1, NULL);
+
+ if (p[i].head)
+ em_core_mail_head_free(&p[i].head, 1, NULL);
+
+ if (p[i].body)
+ em_core_mail_body_free(&p[i].body, 1, NULL);
+ }
+
+ EM_SAFE_FREE(p);
+ *mail_list = NULL;
+
+ EM_DEBUG_FUNC_END("err [%d]", err);
+ return err;
+}
+
+EXPORT_API int email_free_mail_data(emf_mail_data_t** mail_list, int count)
+{
+ EM_DEBUG_FUNC_BEGIN("mail_list[%p], count[%d]", mail_list, count);
+ int err = EMF_ERROR_NONE;
+ em_core_free_mail_data(mail_list, count, &err);
+ EM_DEBUG_FUNC_END("err [%d]", err);
+ return err;
+}
+
+/* Convert Modified UTF-7 mailbox name to UTF-8 */
+/* returns modified UTF-8 Name if success else NULL */
+
+EXPORT_API int email_cancel_send_mail( int mail_id)
+{
+ EM_DEBUG_FUNC_BEGIN("Mail ID [ %d]", mail_id);
+ EM_IF_NULL_RETURN_VALUE(mail_id, EMF_ERROR_INVALID_PARAM);
+
+ int err = EMF_ERROR_NONE;
+ int account_id = 0;
+ emf_mail_t* mail = NULL;
+ void *return_from_ipc = NULL;
+ HIPC_API hAPI = NULL;
+
+
+ if (!em_core_mail_get_mail(mail_id, &mail, &err)) {
+ EM_DEBUG_EXCEPTION("em_core_mail_get_mail failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ if (!mail || !mail->info) {
+ EM_DEBUG_EXCEPTION("mail or mail->info is null");
+ err = EMF_ERROR_NULL_VALUE;
+ goto FINISH_OFF;
+ }
+#ifdef __FEATURE_PROGRESS_IN_OUTBOX__
+ account_id = mail->info->account_id;
+#else
+ /* h.gahlaut@samsung.com: Moved this code from email_cancel_send_mail API to email-service engine*/
+
+ if (mail->info->extra_flags.status == EMF_MAIL_STATUS_SEND_CANCELED) {
+ EM_DEBUG_LOG(" EMF_MAIL_STATUS_SEND_CANCELED Already set for Mail ID [%d] ", mail_id);
+ goto FINISH_OFF;
+ } else {
+ mail->info->extra_flags.status = EMF_MAIL_STATUS_SEND_CANCELED;
+ account_id = mail->info->account_id;
+ }
+
+ if(!em_core_mail_modify_extra_flag(mail_id, mail->info->extra_flags, &err)) {
+ EM_DEBUG_EXCEPTION("Failed to modify extra flag [%d]",err);
+ goto FINISH_OFF;
+ }
+#endif
+
+ hAPI = ipcEmailAPI_Create(_EMAIL_API_SEND_MAIL_CANCEL_JOB);
+
+ if(!hAPI) {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_Create failed");
+ err = EMF_ERROR_NULL_VALUE;
+ goto FINISH_OFF;
+ }
+
+ /* Account_id */
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, &account_id, sizeof(int))) {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ /* Mail ID */
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, &(mail_id), sizeof(int))) {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ /* Execute API */
+ if(!ipcEmailProxy_ExecuteAPI(hAPI)) {
+ EM_DEBUG_EXCEPTION("ipcEmailProxy_ExecuteAPI failed");
+ err = EMF_ERROR_IPC_SOCKET_FAILURE;
+ goto FINISH_OFF;
+ }
+
+ return_from_ipc = ipcEmailAPI_GetParameter(hAPI, ePARAMETER_OUT, 0);
+
+ if(return_from_ipc) {
+ err = *(int*)return_from_ipc;
+ }
+ else {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_GetParameter failed");
+ err = EMF_ERROR_IPC_SOCKET_FAILURE;
+ goto FINISH_OFF;
+ }
+
+FINISH_OFF:
+ if(hAPI)
+ ipcEmailAPI_Destroy(hAPI);
+
+ if (!em_core_mail_free(&mail, 1, &err))
+ EM_DEBUG_EXCEPTION("em_core_mail_free Failed [%d ] ", err);
+
+ EM_DEBUG_FUNC_END("err [%d]", err);
+ return err;
+
+}
+/**
+ * EmfSendCancel - Callback function for cm popup. We set the status as EMF_MAIL_STATUS_NONE
+ *
+ **/
+
+
+EXPORT_API int email_retry_send_mail( int mail_id, int timeout_in_sec)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ int err = EMF_ERROR_NONE;
+ void *return_from_ipc = NULL;
+
+ EM_IF_NULL_RETURN_VALUE(mail_id, EMF_ERROR_INVALID_PARAM);
+ if( timeout_in_sec < 0 ) {
+ EM_DEBUG_EXCEPTION("Invalid timeout_in_sec");
+ err = EMF_ERROR_INVALID_PARAM;
+ return err;
+ }
+
+ HIPC_API hAPI = ipcEmailAPI_Create(_EMAIL_API_SEND_RETRY);
+
+ if(!hAPI) {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_Create failed");
+ err = EMF_ERROR_NULL_VALUE;
+ goto FINISH_OFF;
+ }
+
+ /* Mail ID */
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, &(mail_id), sizeof(int))) {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ /* timeout */
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, &(timeout_in_sec), sizeof(int))) {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ /* Execute API */
+ if(!ipcEmailProxy_ExecuteAPI(hAPI)) {
+ EM_DEBUG_EXCEPTION("ipcEmailProxy_ExecuteAPI failed");
+ err = EMF_ERROR_IPC_SOCKET_FAILURE;
+ goto FINISH_OFF;
+ }
+
+ return_from_ipc = ipcEmailAPI_GetParameter(hAPI, ePARAMETER_OUT, 0);
+
+ if(return_from_ipc) {
+ err = *(int*)return_from_ipc;
+ }
+ else {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_GetParameter failed");
+ err = EMF_ERROR_IPC_SOCKET_FAILURE;
+ goto FINISH_OFF;
+ }
+
+FINISH_OFF:
+ if(hAPI)
+ ipcEmailAPI_Destroy(hAPI);
+
+ EM_DEBUG_FUNC_END("err [%d]", err);
+ return err;
+
+ }
+
+EXPORT_API int email_get_mailbox_name_by_mail_id(int mail_id, char **pMailbox_name)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ int err = EMF_ERROR_NONE;
+ char* mailbox_name = NULL;
+ emf_mail_tbl_t* mail_table_data = NULL;
+
+ if(mail_id <= 0) {
+ EM_DEBUG_EXCEPTION("mail_id is not valid");
+ err= EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+ EM_IF_NULL_RETURN_VALUE(pMailbox_name, EMF_ERROR_INVALID_PARAM);
+
+ if(!em_storage_get_mail_by_id(mail_id, &mail_table_data, true, &err)) {
+ EM_DEBUG_EXCEPTION("Failed to get mail by mail_id [%d]", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+
+ if(mail_table_data->mailbox_name)
+ mailbox_name = strdup(mail_table_data->mailbox_name);
+
+ *pMailbox_name = mailbox_name;
+
+FINISH_OFF:
+ if(mail_table_data) {
+ em_storage_free_mail(&mail_table_data, 1, &err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ }
+ EM_DEBUG_FUNC_END("err [%d]", err);
+ return err;
+}
+
+
+EXPORT_API int email_get_latest_unread_mail_id(int account_id, int *pMailID)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ int err = EMF_ERROR_NONE;
+
+ if( (!pMailID) ||(account_id <= 0 && account_id != -1)) {
+ err = EMF_ERROR_INVALID_PARAM;
+ return err;
+ }
+ if(!em_storage_get_latest_unread_mailid(account_id,pMailID, &err)) {
+ EM_DEBUG_LOG("em_storage_get_latest_unread_mailid - failed");
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ }
+ EM_DEBUG_FUNC_END("err [%d]", err);
+ return err;
+}
+
+EXPORT_API int email_get_max_mail_count(int *Count)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int err = EMF_ERROR_NONE;
+ EM_IF_NULL_RETURN_VALUE(Count, EMF_ERROR_INVALID_PARAM);
+ *Count = em_storage_get_max_mail_count();
+ EM_DEBUG_FUNC_END("err [%d]", err);
+ return err;
+}
+
+
+
+/* for setting application,disk usage of email in KB */
+EXPORT_API int email_get_disk_space_usage(unsigned long *total_size)
+{
+ EM_DEBUG_FUNC_BEGIN("total_size[%p]", total_size);
+ int err = EMF_ERROR_NONE;
+
+ EM_IF_NULL_RETURN_VALUE(total_size, EMF_ERROR_INVALID_PARAM);
+
+ if (!em_storage_mail_get_total_diskspace_usage(total_size,true,&err)) {
+ EM_DEBUG_EXCEPTION("em_storage_mail_get_total_diskspace_usage failed [%d]", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+FINISH_OFF :
+ EM_DEBUG_FUNC_END("err [%d]", err);
+ return err;
+}
+
+EXPORT_API int email_get_recipients_list(int account_id, const char *mailbox_name, emf_sender_list_t **recipients_list)
+{
+ EM_DEBUG_FUNC_BEGIN("recipients_list[%p]", recipients_list);
+
+ int number_of_mails, index;
+ int number_of_recipients;
+ int ret=0, err = 0;
+
+ emf_sender_list_t *temp_recipients_list = NULL;
+ emf_sender_list_t *p_recipients_list = NULL;
+ GList *addr_list = NULL, *temp_addr_list = NULL;
+ emf_mail_tbl_t *mail_table_data = NULL;
+
+ if (!em_storage_get_mails(account_id, (char*)mailbox_name, NULL, EMF_LIST_TYPE_NORMAL, -1, -1, EMF_SORT_SENDER_HIGH, true, &mail_table_data, &number_of_mails, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_get_mails failed");
+ ret = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+
+ for (index = 0; index < number_of_mails; index++) {
+ addr_list = em_core_get_recipients_list(addr_list, mail_table_data[index].full_address_to, &err);
+ addr_list = em_core_get_recipients_list(addr_list, mail_table_data[index].full_address_cc, &err);
+ addr_list = em_core_get_recipients_list(addr_list, mail_table_data[index].full_address_bcc, &err);
+ }
+
+ number_of_recipients = g_list_length(addr_list);
+
+ p_recipients_list = (emf_sender_list_t *)malloc(sizeof(emf_sender_list_t) * number_of_recipients);
+ if (p_recipients_list == NULL) {
+ EM_DEBUG_EXCEPTION("malloc for emf_sender_list_t failed...");
+ err = EM_STORAGE_ERROR_OUT_OF_MEMORY;
+ ret = err;
+ goto FINISH_OFF;
+ }
+ memset(p_recipients_list, 0x00, sizeof(emf_sender_list_t) * number_of_recipients);
+
+ temp_addr_list = g_list_first(addr_list);
+ index = 0;
+ while (temp_addr_list != NULL) {
+ temp_recipients_list = (emf_sender_list_t *)temp_addr_list->data;
+ p_recipients_list[index].address = temp_recipients_list->address;
+ p_recipients_list[index].display_name = temp_recipients_list->display_name;
+ p_recipients_list[index].total_count = temp_recipients_list->total_count + 1;
+ EM_DEBUG_LOG("address[%s], display_name[%s], total_count[%d]", p_recipients_list[index].address, p_recipients_list[index].display_name, p_recipients_list[index].total_count);
+ temp_addr_list = g_list_next(temp_addr_list);
+ index++;
+ }
+
+ ret = true;
+FINISH_OFF:
+ if (ret == true && recipients_list)
+ *recipients_list = p_recipients_list; else if (p_recipients_list != NULL) {
+ email_free_sender_list(&p_recipients_list, number_of_recipients);
+ }
+
+ EM_DEBUG_FUNC_END();
+ return ret;
+}
+
+EXPORT_API int email_get_sender_list(int account_id, const char *mailbox_name, int search_type, const char *search_value, emf_sort_type_t sorting, emf_sender_list_t** sender_list, int *sender_count)
+{
+ EM_DEBUG_FUNC_BEGIN("sender_list[%p],sender_count[%p], sorting[%d]", sender_list, sender_count, sorting);
+
+ int err = EMF_ERROR_NONE;
+
+ emf_sender_list_t *temp_sender_list = NULL;
+
+ EM_IF_NULL_RETURN_VALUE(sender_list, EMF_ERROR_INVALID_PARAM);
+ EM_IF_NULL_RETURN_VALUE(sender_count, EMF_ERROR_INVALID_PARAM);
+ if( account_id < ALL_ACCOUNT) {
+ EM_DEBUG_EXCEPTION(" Invalid Account Id Param ");
+ err = EMF_ERROR_INVALID_PARAM ;
+ return err;
+ }
+
+ if ( !em_storage_get_sender_list(account_id, mailbox_name, search_type, search_value, sorting, &temp_sender_list, sender_count, &err) ) {
+ EM_DEBUG_EXCEPTION("em_storage_get_sender_list failed [%d]", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+
+ if ( sender_list )
+ *sender_list = temp_sender_list;
+
+FINISH_OFF:
+ EM_DEBUG_FUNC_END("err [%d]", err);
+ return err;
+}
+
+EXPORT_API int email_get_sender_list_ex(int account_id, const char *mailbox_name, int start_index, int limit_count, emf_sort_type_t sorting, emf_sender_list_t** sender_list, int *sender_count)
+{
+ return EMF_ERROR_NONE;
+}
+
+EXPORT_API int email_free_sender_list(emf_sender_list_t **sender_list, int count)
+{
+ EM_DEBUG_FUNC_BEGIN("sender_list[%p], count[%d]", sender_list, count);
+
+ int err = EMF_ERROR_NONE;
+
+ if (count > 0) {
+ if (!sender_list || !*sender_list) {
+ EM_DEBUG_EXCEPTION("sender_list[%p], count[%d]", sender_list, count);
+ err = EMF_ERROR_INVALID_PARAM;
+ return err;
+ }
+
+ emf_sender_list_t* p = *sender_list;
+ int i = 0;
+
+ for (; i < count; i++) {
+ EM_SAFE_FREE(p[i].address);
+ EM_SAFE_FREE(p[i].display_name);
+ }
+
+ EM_SAFE_FREE(p);
+ *sender_list = NULL;
+ }
+ EM_DEBUG_FUNC_END("err [%d]", err);
+ return err;
+}
+
+EXPORT_API int email_get_address_info_list(int mail_id, emf_address_info_list_t** address_info_list)
+{
+ EM_DEBUG_FUNC_BEGIN("mail_id[%d], address_info_list[%p]", mail_id, address_info_list);
+
+ int err = EMF_ERROR_NONE;
+
+ emf_address_info_list_t *temp_address_info_list = NULL;
+
+ EM_IF_NULL_RETURN_VALUE(address_info_list, EMF_ERROR_INVALID_PARAM);
+ if( mail_id <= 0) {
+ EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
+ err = EMF_ERROR_INVALID_PARAM ;
+ return err;
+ }
+
+ if ( !em_core_mail_get_address_info_list(mail_id, &temp_address_info_list, &err) ) {
+ EM_DEBUG_EXCEPTION("em_core_mail_get_address_info_list failed [%d]", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+
+ if ( address_info_list ) {
+ *address_info_list = temp_address_info_list;
+ temp_address_info_list = NULL;
+ }
+
+FINISH_OFF:
+ if ( temp_address_info_list )
+ em_storage_free_address_info_list(&temp_address_info_list);
+ EM_DEBUG_FUNC_END("err [%d]", err);
+ return err;
+}
+
+EXPORT_API int email_free_address_info_list(emf_address_info_list_t **address_info_list)
+{
+ EM_DEBUG_FUNC_BEGIN("address_info_list[%p]", address_info_list);
+
+ int err = EMF_ERROR_NONE;
+
+ if ( (err = em_storage_free_address_info_list(address_info_list)) != EMF_ERROR_NONE ) {
+ EM_DEBUG_EXCEPTION("address_info_list[%p] free failed.", address_info_list);
+ }
+ EM_DEBUG_FUNC_END("err [%d]", err);
+ return err;
+}
+
+EXPORT_API int email_get_structure(const char*encoded_string, void **struct_var, emf_convert_struct_type_e type)
+{
+ EM_DEBUG_FUNC_BEGIN("encoded_string[%s], struct_var[%p], type[%d]", encoded_string, struct_var, type);
+
+ int err = EMF_ERROR_NONE;
+ void * temp_struct = NULL;
+
+ EM_IF_NULL_RETURN_VALUE(encoded_string, EMF_ERROR_INVALID_PARAM);
+ EM_IF_NULL_RETURN_VALUE(struct_var, EMF_ERROR_INVALID_PARAM);
+
+ if ( (err = em_core_convert_string_to_structure((char*)encoded_string, &temp_struct, type)) != EMF_ERROR_NONE ) {
+ EM_DEBUG_EXCEPTION("em_core_convert_string_to_structure failed[%d]", err);
+ goto FINISH_OFF;
+ }
+
+ if ( struct_var )
+ *struct_var = temp_struct;
+
+FINISH_OFF:
+ EM_DEBUG_FUNC_END("err [%d]", err);
+ return err;
+}
+
+EXPORT_API int email_add_message_with_meeting_request(emf_mail_t* mail, emf_mailbox_t* mailbox, emf_meeting_request_t* meeting_req, int from_composer)
+{
+ EM_DEBUG_FUNC_BEGIN("mail[%p], mailbox[%p], from_composer [%d]", mail, mailbox, from_composer);
+
+ EM_IF_NULL_RETURN_VALUE(mail, EMF_ERROR_INVALID_PARAM);
+ EM_IF_NULL_RETURN_VALUE(mail->head, EMF_ERROR_INVALID_PARAM);
+ EM_IF_NULL_RETURN_VALUE(mail->info, EMF_ERROR_INVALID_PARAM);
+ EM_IF_NULL_RETURN_VALUE(mail->body, EMF_ERROR_INVALID_PARAM);
+ EM_IF_NULL_RETURN_VALUE(mailbox, EMF_ERROR_INVALID_PARAM);
+ EM_IF_ACCOUNT_ID_NULL(mail->info->account_id, EMF_ERROR_INVALID_PARAM);
+ if ( mail->info->is_meeting_request == EMF_MAIL_TYPE_MEETING_REQUEST
+ || mail->info->is_meeting_request == EMF_MAIL_TYPE_MEETING_RESPONSE
+ || mail->info->is_meeting_request == EMF_MAIL_TYPE_MEETING_ORIGINATINGREQUEST) {
+ EM_IF_NULL_RETURN_VALUE(meeting_req, EMF_ERROR_INVALID_PARAM);
+ }
+
+ int err = EMF_ERROR_NONE, size = 0;
+ char *mail_head_stream = NULL, *mail_body_stream = NULL, *mail_info_stream = NULL, *mailbox_stream = NULL;
+ char *meeting_request_stream = NULL;
+ void *return_from_ipc = NULL;
+ HIPC_API hAPI = NULL;
+
+ if( from_composer ) {
+ hAPI = ipcEmailAPI_Create(_EMAIL_API_ADD_MAIL_OLD);
+
+ if(!hAPI) {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_Create failed");
+ err = EMF_ERROR_NULL_VALUE;
+ goto FINISH_OFF;
+ }
+
+ /* Head */
+ mail_head_stream = em_convert_mail_head_to_byte_stream(mail->head, &size);
+
+ if(!mail_head_stream) {
+ EM_DEBUG_EXCEPTION("em_convert_mail_head_to_byte_stream failed");
+ err = EMF_ERROR_NULL_VALUE;
+ goto FINISH_OFF;
+ }
+
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, mail_head_stream, size)) {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter for head failed");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ /* Body */
+ mail_body_stream = em_convert_mail_body_to_byte_stream(mail->body, &size);
+
+ if(!mail_body_stream) {
+ EM_DEBUG_EXCEPTION("em_convert_mail_body_to_byte_stream failed");
+ err = EMF_ERROR_NULL_VALUE;
+ goto FINISH_OFF;
+ }
+
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, mail_body_stream, size)) {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter for body failed");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ /* Info */
+ mail_info_stream = em_convert_mail_info_to_byte_stream(mail->info, &size);
+
+ if(!mail_info_stream) {
+ EM_DEBUG_EXCEPTION("em_convert_mail_info_to_byte_stream failed");
+ err = EMF_ERROR_NULL_VALUE;
+ goto FINISH_OFF;
+ }
+
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, mail_info_stream, size)) {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter for info failed");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ /* Mailbox */
+ mailbox_stream = em_convert_mailbox_to_byte_stream(mailbox, &size);
+
+ if(!mailbox_stream) {
+ EM_DEBUG_EXCEPTION("em_convert_mailbox_to_byte_stream failed");
+ err = EMF_ERROR_NULL_VALUE;
+ goto FINISH_OFF;
+ }
+
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, mailbox_stream, size)) {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter mailbox Fail");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+
+ /* from_composer */
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, (char*)&from_composer, sizeof(int))) {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter from_composer Failed");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ /* meeting_req */
+ if ( mail->info->is_meeting_request != EMF_MAIL_TYPE_NORMAL ) {
+ meeting_request_stream = em_convert_meeting_req_to_byte_stream(meeting_req, &size);
+
+ if(!meeting_request_stream) {
+ EM_DEBUG_EXCEPTION("em_convert_meeting_req_to_byte_stream failed");
+ err = EMF_ERROR_NULL_VALUE;
+ goto FINISH_OFF;
+ }
+
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, meeting_request_stream, size)) {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+ }
+
+ /* Execute API */
+ if(!ipcEmailProxy_ExecuteAPI(hAPI)) {
+ EM_DEBUG_EXCEPTION("ipcEmailProxy_ExecuteAPI failed");
+ err = EMF_ERROR_IPC_SOCKET_FAILURE;
+ goto FINISH_OFF;
+ }
+
+ return_from_ipc = ipcEmailAPI_GetParameter(hAPI, ePARAMETER_OUT, 0);
+
+ if(return_from_ipc)
+ err = *(int*)return_from_ipc;
+ else {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_GetParameter failed");
+ err = EMF_ERROR_IPC_SOCKET_FAILURE;
+ goto FINISH_OFF;
+ }
+
+ if(err == EMF_ERROR_NONE) {
+ return_from_ipc = ipcEmailAPI_GetParameter(hAPI, ePARAMETER_OUT, 1);
+ if(return_from_ipc)
+ mail->info->uid = *(int*)return_from_ipc;
+ else{
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_GetParameter failed");
+ err = EMF_ERROR_IPC_SOCKET_FAILURE;
+ goto FINISH_OFF;
+ }
+ }
+
+ if(err == EMF_ERROR_NONE)
+ mail->info->uid = *(int*)ipcEmailAPI_GetParameter(hAPI, ePARAMETER_OUT, 1);
+ }
+ else {
+ if (!em_core_mail_save(mailbox->account_id, mailbox->name, mail, meeting_req, from_composer, &err)) {
+ EM_DEBUG_EXCEPTION("em_core_mail_save failed [%d]", err);
+ goto FINISH_OFF;
+ }
+ }
+
+FINISH_OFF:
+ if(hAPI)
+ ipcEmailAPI_Destroy(hAPI);
+
+ EM_SAFE_FREE(mail_head_stream);
+ EM_SAFE_FREE(mail_body_stream);
+ EM_SAFE_FREE(mail_info_stream);
+ EM_SAFE_FREE(mailbox_stream);
+ EM_SAFE_FREE(meeting_request_stream);
+
+ EM_DEBUG_FUNC_END("err [%d]", err);
+ return err;
+
+}
+
+EXPORT_API int email_get_meeting_request(int mail_id, emf_meeting_request_t **meeting_req)
+{
+ EM_DEBUG_FUNC_BEGIN("mail_id[%d],meeting_req[%p]", mail_id, meeting_req);
+
+ int err = EMF_ERROR_NONE;
+
+ emf_meeting_request_t *temp_meeting_req = NULL;
+
+ EM_IF_NULL_RETURN_VALUE(meeting_req, EMF_ERROR_INVALID_PARAM);
+ if( mail_id <= 0 ) {
+ EM_DEBUG_EXCEPTION(" Invalid Mail Id Param ");
+ err = EMF_ERROR_INVALID_PARAM ;
+ return err;
+ }
+
+ if ( !em_storage_get_meeting_request(mail_id, &temp_meeting_req, 1, &err) ) {
+ EM_DEBUG_EXCEPTION("em_storage_get_meeting_request -- Failed [%d]", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+
+ if ( meeting_req )
+ *meeting_req = temp_meeting_req;
+
+FINISH_OFF:
+ EM_DEBUG_FUNC_END("err [%d]", err);
+ return err;
+}
+
+
+EXPORT_API int email_update_message_with_meeting_request(int mail_id, emf_mail_t* mail, emf_meeting_request_t* meeting_req)
+{
+ EM_DEBUG_FUNC_BEGIN("mail_id[%d], mali[%p]", mail_id, mail);
+
+ int size = 0;
+ int ret = 0;
+ int err = EMF_ERROR_NONE;
+ void *retrun_from_ipc = NULL;
+ char* mail_head_stream = NULL;
+ char* mail_body_stream = NULL;
+ char* mail_info_stream = NULL;
+ char* pMeeting_request_stream = NULL;
+ HIPC_API hAPI = NULL;
+
+ EM_IF_NULL_RETURN_VALUE(mail, EMF_ERROR_INVALID_PARAM);
+ EM_IF_NULL_RETURN_VALUE(mail->head, EMF_ERROR_INVALID_PARAM);
+ EM_IF_NULL_RETURN_VALUE(mail->info, EMF_ERROR_INVALID_PARAM);
+ EM_IF_NULL_RETURN_VALUE(mail_id, EMF_ERROR_INVALID_PARAM);
+ EM_IF_ACCOUNT_ID_NULL(mail->info->account_id, EMF_ERROR_INVALID_PARAM);
+ if ( mail->info->is_meeting_request == EMF_MAIL_TYPE_MEETING_REQUEST
+ || mail->info->is_meeting_request == EMF_MAIL_TYPE_MEETING_RESPONSE
+ || mail->info->is_meeting_request == EMF_MAIL_TYPE_MEETING_ORIGINATINGREQUEST) {
+ EM_IF_NULL_RETURN_VALUE(meeting_req, EMF_ERROR_INVALID_PARAM);
+ }
+
+ hAPI = ipcEmailAPI_Create(_EMAIL_API_UPDATE_MAIL_OLD);
+
+ if(!hAPI) {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_Create failed");
+ err = EMF_ERROR_NULL_VALUE;
+ goto FINISH_OFF;
+ }
+
+ /* mail_id */
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, (char*)&mail_id, sizeof(int))) {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ /* Head */
+ mail_head_stream = em_convert_mail_head_to_byte_stream(mail->head, &size);
+ if(!mail_head_stream) {
+ EM_DEBUG_EXCEPTION("em_convert_mail_head_to_byte_stream failed");
+ err = EMF_ERROR_NULL_VALUE;
+ goto FINISH_OFF;
+ }
+
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, mail_head_stream, size)) {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ /* Body */
+ mail_body_stream = em_convert_mail_body_to_byte_stream(mail->body, &size);
+
+ if (!mail_body_stream ) {
+ int dummy_body = 0;
+ EM_DEBUG_LOG(" Mail body is NULL. Add dummy data(4 bytes)");
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, (char*)&dummy_body, sizeof(int))) {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+ }
+ else {
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, mail_body_stream, size)) {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+ }
+
+ /* Info */
+ mail_info_stream = em_convert_mail_info_to_byte_stream(mail->info, &size);
+
+ if (!mail_info_stream ) {
+ EM_DEBUG_EXCEPTION("em_convert_mail_info_to_byte_stream failed");
+ err = EMF_ERROR_NULL_VALUE;
+ goto FINISH_OFF;
+ }
+
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, mail_info_stream, size)) {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ /* meeting_req */
+ if ( mail->info->is_meeting_request != EMF_MAIL_TYPE_NORMAL ) {
+ pMeeting_request_stream = em_convert_meeting_req_to_byte_stream(meeting_req, &size);
+
+ if(!pMeeting_request_stream) {
+ EM_DEBUG_EXCEPTION("em_convert_meeting_req_to_byte_stream failed");
+ err = EMF_ERROR_NULL_VALUE;
+ goto FINISH_OFF;
+ }
+
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, pMeeting_request_stream, size)) {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+ }
+
+ if(!ipcEmailProxy_ExecuteAPI(hAPI)) {
+ EM_DEBUG_EXCEPTION("ipcEmailProxy_ExecuteAPI failed");
+ err = EMF_ERROR_IPC_SOCKET_FAILURE;
+ goto FINISH_OFF;
+ }
+
+ retrun_from_ipc = ipcEmailAPI_GetParameter(hAPI, ePARAMETER_OUT, 0);
+
+ if(retrun_from_ipc) {
+ ret = *(int*)retrun_from_ipc;
+ if ( ret != 1 ) {
+ retrun_from_ipc = ipcEmailAPI_GetParameter(hAPI, ePARAMETER_OUT, 1);
+ if(retrun_from_ipc) {
+ err = *(int*)retrun_from_ipc;
+ }
+ else {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_GetParameter failed");
+ err = EMF_ERROR_IPC_SOCKET_FAILURE;
+ goto FINISH_OFF;
+ }
+ }
+ }
+ else {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_GetParameter failed");
+ err = EMF_ERROR_IPC_SOCKET_FAILURE;
+ goto FINISH_OFF;
+ }
+FINISH_OFF:
+ EM_SAFE_FREE(mail_head_stream);
+ EM_SAFE_FREE(mail_body_stream);
+ EM_SAFE_FREE(mail_info_stream);
+ EM_SAFE_FREE(pMeeting_request_stream);
+
+ if(hAPI)
+ ipcEmailAPI_Destroy(hAPI);
+
+ EM_DEBUG_FUNC_END("ret [%d], err [%d]", ret, err);
+ return err;
+}
+
+EXPORT_API int email_free_meeting_request(emf_meeting_request_t** meeting_req, int count)
+{
+ EM_DEBUG_FUNC_BEGIN("meeting_req[%p], count[%d]", meeting_req, count);
+
+ int err = EMF_ERROR_NONE;
+
+ em_storage_free_meeting_request(meeting_req, count, &err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ EM_DEBUG_FUNC_END("err [%d]", err);
+ return err;
+}
+
+EXPORT_API int email_move_thread_to_mailbox(int thread_id, char *target_mailbox_name, int move_always_flag)
+{
+ EM_DEBUG_FUNC_BEGIN("thread_id[%d], target_mailbox_name[%p], move_always_flag[%d]", thread_id, target_mailbox_name, move_always_flag);
+ int err = EMF_ERROR_NONE;
+ void *return_from_ipc = NULL;
+
+ EM_IF_NULL_RETURN_VALUE(target_mailbox_name, EMF_ERROR_INVALID_PARAM);
+
+ HIPC_API hAPI = ipcEmailAPI_Create(_EMAIL_API_MOVE_THREAD_TO_MAILBOX);
+
+ if(!hAPI) {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_Create failed");
+ err = EMF_ERROR_NULL_VALUE;
+ goto FINISH_OFF;
+ }
+
+ /* thread_id */
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, (char*)&thread_id, sizeof(int))){
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ /* target mailbox information */
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, target_mailbox_name, strlen(target_mailbox_name))){
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ /* move_always_flag */
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, (char*)&move_always_flag, sizeof(int))){
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ /* Execute API */
+ if(!ipcEmailProxy_ExecuteAPI(hAPI)) {
+ EM_DEBUG_EXCEPTION("ipcEmailProxy_ExecuteAPI failed");
+ err = EMF_ERROR_IPC_SOCKET_FAILURE;
+ goto FINISH_OFF;
+ }
+
+ return_from_ipc = ipcEmailAPI_GetParameter(hAPI, ePARAMETER_OUT, 0);
+
+ if(return_from_ipc) {
+ err = *(int*)return_from_ipc;
+ }
+ else {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_GetParameter failed");
+ err = EMF_ERROR_IPC_SOCKET_FAILURE;
+ goto FINISH_OFF;
+ }
+
+FINISH_OFF:
+ if(hAPI)
+ ipcEmailAPI_Destroy(hAPI);
+
+ EM_DEBUG_FUNC_END("err [%d]", err);
+ return err;
+}
+
+EXPORT_API int email_delete_thread(int thread_id, int delete_always_flag)
+{
+ EM_DEBUG_FUNC_BEGIN("thread_id[%d], delete_always_flag[%d]", thread_id, delete_always_flag);
+ int err = EMF_ERROR_NONE;
+ void *return_from_ipc = NULL;
+ HIPC_API hAPI = ipcEmailAPI_Create(_EMAIL_API_DELETE_THREAD);
+
+ if(!hAPI) {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_Create failed");
+ err = EMF_ERROR_NULL_VALUE;
+ goto FINISH_OFF;
+ }
+
+ /* thread_id */
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, (char*)&thread_id, sizeof(int))){
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ /* delete_always_flag */
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, (char*)&delete_always_flag, sizeof(int))){
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ /* Execute API */
+ if(!ipcEmailProxy_ExecuteAPI(hAPI)) {
+ EM_DEBUG_EXCEPTION("ipcEmailProxy_ExecuteAPI failed");
+ err = EMF_ERROR_IPC_SOCKET_FAILURE;
+ goto FINISH_OFF;
+ }
+
+ return_from_ipc = ipcEmailAPI_GetParameter(hAPI, ePARAMETER_OUT, 0);
+
+ if(return_from_ipc) {
+ err = *(int*)return_from_ipc;
+ }
+ else {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_GetParameter failed");
+ err = EMF_ERROR_IPC_SOCKET_FAILURE;
+ goto FINISH_OFF;
+ }
+
+FINISH_OFF:
+ if(hAPI)
+ ipcEmailAPI_Destroy(hAPI);
+
+ EM_DEBUG_FUNC_END("err [%d]", err);
+ return err;
+}
+
+EXPORT_API int email_modify_seen_flag_of_thread(int thread_id, int seen_flag, int on_server)
+{
+ EM_DEBUG_FUNC_BEGIN("thread_id[%d], seen_flag[%d], on_server[%d]", thread_id, seen_flag, on_server);
+ int err = EMF_ERROR_NONE;
+ void *return_from_ipc = NULL;
+ HIPC_API hAPI = ipcEmailAPI_Create(_EMAIL_API_MODIFY_SEEN_FLAG_OF_THREAD);
+
+ if(!hAPI) {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_Create failed");
+ err = EMF_ERROR_NULL_VALUE;
+ goto FINISH_OFF;
+ }
+
+ /* thread_id */
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, (char*)&thread_id, sizeof(int))) {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ /* seen_flag */
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, (char*)&seen_flag, sizeof(int))) {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ /* on_server */
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, (char*)&on_server, sizeof(int))) {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ /* Execute API */
+ if(!ipcEmailProxy_ExecuteAPI(hAPI)) {
+ EM_DEBUG_EXCEPTION("ipcEmailProxy_ExecuteAPI failed");
+ err = EMF_ERROR_IPC_SOCKET_FAILURE;
+ goto FINISH_OFF;
+ }
+
+ return_from_ipc = ipcEmailAPI_GetParameter(hAPI, ePARAMETER_OUT, 0);
+
+ if(return_from_ipc) {
+ err = *(int*)return_from_ipc;
+ }
+ else {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_GetParameter failed");
+ err = EMF_ERROR_IPC_SOCKET_FAILURE;
+ goto FINISH_OFF;
+ }
+
+FINISH_OFF:
+ if(hAPI)
+ ipcEmailAPI_Destroy(hAPI);
+ EM_DEBUG_FUNC_END("err [%d]", err);
+ return err;
+}
+
diff --git a/MAPI/Emf_Mapi_Network.c b/MAPI/Emf_Mapi_Network.c
new file mode 100755
index 0000000..658ab0e
--- /dev/null
+++ b/MAPI/Emf_Mapi_Network.c
@@ -0,0 +1,1486 @@
+/*
+* email-service
+*
+* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+*
+* Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com>
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*
+*/
+
+
+
+/**
+ *
+ * This file contains the data structures and interfaces needed for application,
+ * to interact with Email Engine.
+ * @file Emf_Mapi_Network.c
+ * @brief This file contains the data structures and interfaces of Network related Functionality provided by
+ * Email Engine .
+ */
+
+#include <Emf_Mapi.h>
+#include "string.h"
+#include "Msg_Convert.h"
+#include "Emf_Mapi_Mailbox.h"
+#include "emf-types.h"
+#include "ipc-library.h"
+#include "em-storage.h"
+
+#ifdef __FEATURE_SUPPORT_ACTIVE_SYNC__
+#include <vconf.h>
+#include <dbus/dbus.h>
+#endif /* __FEATURE_SUPPORT_ACTIVE_SYNC__ */
+
+#ifdef __FEATURE_SUPPORT_ACTIVE_SYNC__
+
+
+#define ACTIVE_SYNC_HANDLE_INIT_VALUE (-1)
+#define ACTIVE_SYNC_HANDLE_BOUNDARY (-100000000)
+
+
+static int email_get_account_server_type_by_account_id(int account_id, emf_account_server_t* account_server_type, int flag, int *error)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ emf_account_t *account=NULL;
+ int ret = false;
+ int err= EMF_ERROR_NONE;
+
+ if (account_server_type == NULL ) {
+ EM_DEBUG_EXCEPTION("account_server_type is NULL");
+ err = EMF_ERROR_INVALID_PARAM;
+ ret = false;
+ goto FINISH_OFF;
+ }
+
+ if( (err = email_get_account(account_id,WITHOUT_OPTION,&account)) < 0) {
+ EM_DEBUG_EXCEPTION ("email_get_account failed [%d] ", err);
+ ret = false;
+ goto FINISH_OFF;
+ }
+
+ if ( flag == false ) { /* sending server */
+ *account_server_type = account->sending_server_type;
+ } else if ( flag == true ) { /* receiving server */
+ *account_server_type = account->receiving_server_type;
+ }
+
+ ret = true;
+
+FINISH_OFF:
+ if ( account != NULL ) {
+ email_free_account(&account, 1);
+ }
+ if ( error != NULL ) {
+ *error = err;
+ }
+
+ return ret;
+}
+
+static int email_get_handle_for_activesync(int *handle, int *error)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ static int next_handle = 0;
+ int ret = false;
+ int err= EMF_ERROR_NONE;
+
+ if ( handle == NULL ) {
+ EM_DEBUG_EXCEPTION("email_get_handle_for_activesync failed : handle is NULL");
+ ret = false;
+ goto FINISH_OFF;
+ }
+
+ if ( vconf_get_int(VCONFKEY_EMAIL_SERVICE_ACTIVE_SYNC_HANDLE, &next_handle) != 0 ) {
+ EM_DEBUG_EXCEPTION("vconf_get_int failed");
+
+ if ( next_handle != 0 ) {
+ ret = false;
+ err = EMF_ERROR_GCONF_FAILURE;
+ goto FINISH_OFF;
+ }
+ }
+ EM_DEBUG_LOG(">>>>>> VCONFKEY_EMAIL_SERVICE_ACTIVE_SYNC_HANDLE : get lastest handle[%d]", next_handle);
+
+ /* set the value of the handle for active sync */
+ next_handle--;
+ if ( next_handle < ACTIVE_SYNC_HANDLE_BOUNDARY ) {
+ next_handle = ACTIVE_SYNC_HANDLE_INIT_VALUE;
+ }
+ if ( vconf_set_int(VCONFKEY_EMAIL_SERVICE_ACTIVE_SYNC_HANDLE, next_handle) != 0) {
+ EM_DEBUG_EXCEPTION("vconf_set_int failed");
+
+ ret = false;
+ err = EMF_ERROR_GCONF_FAILURE;
+ goto FINISH_OFF;
+ }
+ ret = true;
+ *handle = next_handle;
+ EM_DEBUG_LOG(">>>>>> return next handle[%d]", *handle);
+
+FINISH_OFF:
+ if ( error != NULL ) {
+ *error = err;
+ }
+
+ return ret;
+}
+
+static int email_send_notification_to_active_sync_engine(int subType, ASNotiData *data)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ DBusConnection *connection;
+ DBusMessage *signal = NULL;
+ DBusError error;
+ const char *nullString = "";
+
+ EM_DEBUG_LOG("Active Sync noti subType : [%d]", subType);
+
+ dbus_error_init (&error);
+ connection = dbus_bus_get(DBUS_BUS_SYSTEM, &error);
+
+ if(connection == NULL)
+ goto FINISH_OFF;
+
+ signal = dbus_message_new_signal("/User/Email/ActiveSync", EMF_ACTIVE_SYNC_NOTI, "email");
+
+ dbus_message_append_args(signal, DBUS_TYPE_INT32, &subType, DBUS_TYPE_INVALID);
+ switch ( subType ) {
+ case ACTIVE_SYNC_NOTI_SEND_MAIL:
+ EM_DEBUG_LOG("handle:[%d]", data->send_mail.handle);
+ EM_DEBUG_LOG("account_id:[%d]", data->send_mail.account_id);
+ EM_DEBUG_LOG("mailbox_name:[%s]", data->send_mail.mailbox_name);
+ EM_DEBUG_LOG("mail_id:[%d]", data->send_mail.mail_id);
+ EM_DEBUG_LOG("options.priority:[%d]", data->send_mail.options.priority);
+ EM_DEBUG_LOG("options.keep_local_copy:[%d]", data->send_mail.options.keep_local_copy);
+ EM_DEBUG_LOG("options.req_delivery_receipt:[%d]", data->send_mail.options.req_delivery_receipt);
+ EM_DEBUG_LOG("options.req_read_receipt:[%d]", data->send_mail.options.req_read_receipt);
+ /* download_limit, block_address, block_subject might not be needed */
+ EM_DEBUG_LOG("options.download_limit:[%d]", data->send_mail.options.download_limit);
+ EM_DEBUG_LOG("options.block_address:[%d]", data->send_mail.options.block_address);
+ EM_DEBUG_LOG("options.block_subject:[%d]", data->send_mail.options.block_subject);
+ EM_DEBUG_LOG("options.display_name_from:[%s]", data->send_mail.options.display_name_from);
+ EM_DEBUG_LOG("options.reply_with_body:[%d]", data->send_mail.options.reply_with_body);
+ EM_DEBUG_LOG("options.forward_with_files:[%d]", data->send_mail.options.forward_with_files);
+ EM_DEBUG_LOG("options.add_myname_card:[%d]", data->send_mail.options.add_myname_card);
+ EM_DEBUG_LOG("options.add_signature:[%d]", data->send_mail.options.add_signature);
+ EM_DEBUG_LOG("options.signature:[%s]", data->send_mail.options.signature);
+
+ dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->send_mail.handle), DBUS_TYPE_INVALID);
+ dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->send_mail.account_id), DBUS_TYPE_INVALID);
+ if ( data->send_mail.mailbox_name == NULL )
+ dbus_message_append_args(signal, DBUS_TYPE_STRING, &(nullString), DBUS_TYPE_INVALID); else
+ dbus_message_append_args(signal, DBUS_TYPE_STRING, &(data->send_mail.mailbox_name), DBUS_TYPE_INVALID);
+ dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->send_mail.mail_id), DBUS_TYPE_INVALID);
+ dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->send_mail.options.priority), DBUS_TYPE_INVALID);
+ dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->send_mail.options.keep_local_copy), DBUS_TYPE_INVALID);
+ dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->send_mail.options.req_delivery_receipt), DBUS_TYPE_INVALID);
+ dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->send_mail.options.req_read_receipt), DBUS_TYPE_INVALID);
+ if ( data->send_mail.options.display_name_from == NULL )
+ dbus_message_append_args(signal, DBUS_TYPE_STRING, &(nullString), DBUS_TYPE_INVALID); else
+ dbus_message_append_args(signal, DBUS_TYPE_STRING, &(data->send_mail.options.display_name_from), DBUS_TYPE_INVALID);
+
+ dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->send_mail.options.reply_with_body), DBUS_TYPE_INVALID);
+ dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->send_mail.options.forward_with_files), DBUS_TYPE_INVALID);
+ dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->send_mail.options.add_myname_card), DBUS_TYPE_INVALID);
+ dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->send_mail.options.add_signature), DBUS_TYPE_INVALID);
+ if ( data->send_mail.options.signature == NULL )
+ dbus_message_append_args(signal, DBUS_TYPE_STRING, &(nullString), DBUS_TYPE_INVALID); else
+ dbus_message_append_args(signal, DBUS_TYPE_STRING, &(data->send_mail.options.signature), DBUS_TYPE_INVALID);
+
+ break;
+ case ACTIVE_SYNC_NOTI_SEND_SAVED: /* publish a send notification to ASE (active sync engine) */
+ EM_DEBUG_EXCEPTION("Not support yet : subType[ACTIVE_SYNC_NOTI_SEND_SAVED]", subType);
+ break;
+ case ACTIVE_SYNC_NOTI_SEND_REPORT:
+ EM_DEBUG_EXCEPTION("Not support yet : subType[ACTIVE_SYNC_NOTI_SEND_REPORT]", subType);
+ break;
+ case ACTIVE_SYNC_NOTI_SYNC_HEADER:
+ EM_DEBUG_LOG("handle:[%d]", data->sync_header.handle);
+ EM_DEBUG_LOG("account_id:[%d]", data->sync_header.account_id);
+ EM_DEBUG_LOG("mailbox_name:[%s]", data->sync_header.mailbox_name);
+
+ dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->sync_header.handle ), DBUS_TYPE_INVALID);
+ dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->sync_header.account_id ), DBUS_TYPE_INVALID);
+ if ( data->sync_header.mailbox_name == NULL )
+ dbus_message_append_args(signal, DBUS_TYPE_STRING, &(nullString), DBUS_TYPE_INVALID); else
+ dbus_message_append_args(signal, DBUS_TYPE_STRING, &(data->sync_header.mailbox_name), DBUS_TYPE_INVALID);
+
+ break;
+ case ACTIVE_SYNC_NOTI_DOWNLOAD_BODY: /* publish a download body notification to ASE */
+ EM_DEBUG_LOG("handle:[%d]", data->download_body.handle);
+ EM_DEBUG_LOG("account_id:[%d]", data->download_body.account_id);
+ EM_DEBUG_LOG("mail_id:[%d]", data->download_body.mail_id);
+ EM_DEBUG_LOG("with_attachment:[%d]", data->download_body.with_attachment);
+
+ dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->download_body.handle ), DBUS_TYPE_INVALID);
+ dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->download_body.account_id ), DBUS_TYPE_INVALID);
+ dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->download_body.mail_id ), DBUS_TYPE_INVALID);
+ dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->download_body.with_attachment ), DBUS_TYPE_INVALID);
+ break;
+ case ACTIVE_SYNC_NOTI_DOWNLOAD_ATTACHMENT:
+ EM_DEBUG_LOG("handle:[%d]", data->download_attachment.handle);
+ EM_DEBUG_LOG("account_id:[%d]", data->download_attachment.account_id );
+ EM_DEBUG_LOG("mail_id:[%d]", data->download_attachment.mail_id);
+ EM_DEBUG_LOG("with_attachment:[%s]", data->download_attachment.attachment_order );
+
+ dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->download_attachment.handle ), DBUS_TYPE_INVALID);
+ dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->download_attachment.account_id ), DBUS_TYPE_INVALID);
+ dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->download_attachment.mail_id ), DBUS_TYPE_INVALID);
+ if ( data->download_attachment.attachment_order == NULL )
+ dbus_message_append_args(signal, DBUS_TYPE_STRING, &(nullString), DBUS_TYPE_INVALID); else
+ dbus_message_append_args(signal, DBUS_TYPE_STRING, &(data->download_attachment.attachment_order), DBUS_TYPE_INVALID);
+ break;
+ case ACTIVE_SYNC_NOTI_VALIDATE_ACCOUNT:
+ EM_DEBUG_EXCEPTION("Not support yet : subType[ACTIVE_SYNC_NOTI_VALIDATE_ACCOUNT]", subType);
+ break;
+ case ACTIVE_SYNC_NOTI_CANCEL_JOB:
+ EM_DEBUG_LOG("account_id:[%d]", data->cancel_job.account_id );
+ EM_DEBUG_LOG("handle to cancel:[%d]", data->cancel_job.handle);
+
+ dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->cancel_job.account_id ), DBUS_TYPE_INVALID);
+ dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->cancel_job.handle ), DBUS_TYPE_INVALID);
+ break;
+ case ACTIVE_SYNC_NOTI_SEARCH_ON_SERVER:
+ break;
+ default:
+ EM_DEBUG_EXCEPTION("Invalid Notification type of Active Sync : subType[%d]", subType);
+ return FAILURE;
+ }
+
+ if(!dbus_connection_send (connection, signal, NULL)) {
+ EM_DEBUG_EXCEPTION("dbus_connection_send is failed");
+ return FAILURE;
+ } else
+ EM_DEBUG_LOG("dbus_connection_send is successful");
+
+ dbus_connection_flush(connection);
+
+FINISH_OFF:
+
+ if(signal)
+ dbus_message_unref(signal);
+
+ EM_DEBUG_FUNC_END();
+ return true;
+}
+#endif /* __FEATURE_SUPPORT_ACTIVE_SYNC__ */
+
+
+EXPORT_API int email_send_mail( emf_mailbox_t* mailbox, int mail_id, emf_option_t* sending_option, unsigned* handle)
+{
+ EM_DEBUG_FUNC_BEGIN("mailbox[%p], mail_id[%d], sending_option[%p], handle[%p]", mailbox, mail_id, sending_option, handle);
+
+ char* mailbox_stream = NULL;
+ char* pSendingOption = NULL;
+ int size = 0;
+ int err = EMF_ERROR_NONE;
+
+ EM_IF_NULL_RETURN_VALUE(mailbox, EMF_ERROR_INVALID_PARAM);
+ EM_IF_NULL_RETURN_VALUE(mailbox->name, EMF_ERROR_INVALID_PARAM);
+ EM_IF_ACCOUNT_ID_NULL(mailbox->account_id, EMF_ERROR_INVALID_PARAM);
+
+ EM_DEBUG_LOG("Account ID [ %d],mailbox->name[%s], mailbox->account_id[%d] ", mailbox->account_id, mailbox->name, mailbox->account_id);
+
+#ifdef __FEATURE_SUPPORT_ACTIVE_SYNC__
+ emf_account_server_t account_server_type;
+ HIPC_API hAPI = NULL;
+ ASNotiData as_noti_data;
+ memset(&as_noti_data, 0x00, sizeof(ASNotiData));
+
+ /* check account bind type and branch off */
+ if ( email_get_account_server_type_by_account_id(mailbox->account_id, &account_server_type, false, &err) == false ) {
+ EM_DEBUG_EXCEPTION("email_get_account_server_type_by_account_id failed[%d]", err);
+ err = EMF_ERROR_ACTIVE_SYNC_NOTI_FAILURE;
+ goto FINISH_OFF;
+ }
+
+ if ( account_server_type == EMF_SERVER_TYPE_ACTIVE_SYNC ) {
+ int as_handle;
+ if ( email_get_handle_for_activesync(&as_handle, &err) == false ) {
+ EM_DEBUG_EXCEPTION("email_get_handle_for_activesync failed[%d].", err);
+ err = EMF_ERROR_ACTIVE_SYNC_NOTI_FAILURE;
+ goto FINISH_OFF;
+ }
+
+ /* noti to active sync */
+ as_noti_data.send_mail.handle = as_handle;
+ as_noti_data.send_mail.account_id = mailbox->account_id;
+ as_noti_data.send_mail.mailbox_name = strdup(mailbox->name);
+ as_noti_data.send_mail.mail_id = mail_id;
+
+ memcpy(&as_noti_data.send_mail.options, sending_option, sizeof(emf_option_t));
+
+ if ( email_send_notification_to_active_sync_engine(ACTIVE_SYNC_NOTI_SEND_MAIL, &as_noti_data) == false) {
+ EM_DEBUG_EXCEPTION("email_send_notification_to_active_sync_engine failed.");
+ err = EMF_ERROR_ACTIVE_SYNC_NOTI_FAILURE;
+ goto FINISH_OFF;
+ }
+
+ if(handle)
+ *handle = as_handle;
+ } else {
+ hAPI = ipcEmailAPI_Create(_EMAIL_API_SEND_MAIL);
+
+ EM_IF_NULL_RETURN_VALUE(hAPI, EMF_ERROR_NULL_VALUE);
+
+ /* Mailbox */
+ mailbox_stream = em_convert_mailbox_to_byte_stream(mailbox, &size);
+
+ EM_PROXY_IF_NULL_RETURN_VALUE(mailbox_stream, hAPI, EMF_ERROR_NULL_VALUE);
+
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, mailbox_stream, size)){
+ EM_DEBUG_EXCEPTION("email_send_mail--Add Param mailbox Fail");
+ EM_SAFE_FREE(mailbox_stream);
+ EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMF_ERROR_NULL_VALUE);
+ }
+
+ /* mail_id */
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, (char*)&mail_id, sizeof(int))){
+ EM_DEBUG_EXCEPTION("email_send_mail--Add Param mail_id Fail");
+ EM_SAFE_FREE(mailbox_stream);
+ EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMF_ERROR_NULL_VALUE);
+ }
+
+ /* sending options */
+ pSendingOption = em_convert_option_to_byte_stream(sending_option, &size);
+
+ if ( NULL == pSendingOption) {
+ EM_SAFE_FREE(mailbox_stream);
+ EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMF_ERROR_NULL_VALUE);
+ }
+
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, pSendingOption, size)){
+ EM_DEBUG_EXCEPTION("email_send_mail--Add Param Sending_Option Fail ");
+ EM_SAFE_FREE(mailbox_stream);
+ EM_SAFE_FREE(pSendingOption);
+ EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMF_ERROR_NULL_VALUE);
+ }
+
+ if(!ipcEmailProxy_ExecuteAPI(hAPI)) {
+ EM_DEBUG_EXCEPTION("email_send_mail--ipcEmailProxy_ExecuteAPI Fail ");
+ EM_SAFE_FREE(pSendingOption);
+ EM_SAFE_FREE(mailbox_stream);
+ EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMF_ERROR_IPC_CRASH);
+ }
+
+ err = *((int*)ipcEmailAPI_GetParameter(hAPI, ePARAMETER_OUT, 0));
+ if (err == EMF_ERROR_NONE)
+ {
+ if(handle)
+ *handle = *(unsigned int*)ipcEmailAPI_GetParameter(hAPI, ePARAMETER_OUT, 1);
+ }
+ }
+
+FINISH_OFF:
+ ipcEmailAPI_Destroy(hAPI);
+ hAPI = (HIPC_API)NULL;
+ EM_SAFE_FREE(pSendingOption);
+ EM_SAFE_FREE(mailbox_stream);
+ EM_SAFE_FREE(as_noti_data.send_mail.mailbox_name);
+#else /* __FEATURE_SUPPORT_ACTIVE_SYNC__ */
+ HIPC_API hAPI = ipcEmailAPI_Create(_EMAIL_API_SEND_MAIL);
+
+ EM_IF_NULL_RETURN_VALUE(hAPI, EMF_ERROR_NULL_VALUE);
+
+ /* Mailbox */
+ mailbox_stream = em_convert_mailbox_to_byte_stream(mailbox, &size);
+
+ EM_PROXY_IF_NULL_RETURN_VALUE(mailbox_stream, hAPI, EMF_ERROR_NULL_VALUE);
+
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, mailbox_stream, size)){
+ EM_DEBUG_EXCEPTION("Add Param mailbox Fail ");
+ EM_SAFE_FREE(mailbox_stream);
+ EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMF_ERROR_NULL_VALUE);
+ }
+
+ /* mail_id */
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, (char*)&mail_id, sizeof(int))){
+ EM_DEBUG_EXCEPTION("Add Param mail_id Fail ");
+ EM_SAFE_FREE(mailbox_stream);
+ EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMF_ERROR_NULL_VALUE);
+ }
+
+ /* sending options */
+ pSendingOption = em_convert_option_to_byte_stream(sending_option, &size);
+
+ if ( NULL == pSendingOption)
+ EM_SAFE_FREE(mailbox_stream);
+ EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMF_ERROR_NULL_VALUE);
+ }
+
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, pSendingOption, size)){
+ EM_DEBUG_EXCEPTION("Add Param Sending_Option Fail ");
+ EM_SAFE_FREE(mailbox_stream);
+ EM_SAFE_FREE(pSendingOption);
+ EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMF_ERROR_NULL_VALUE);
+ }
+
+ if(!ipcEmailProxy_ExecuteAPI(hAPI, NULL)) {
+ EM_DEBUG_EXCEPTION("ipcEmailProxy_ExecuteAPI Fail ");
+ EM_SAFE_FREE(pSendingOption);
+ EM_SAFE_FREE(mailbox_stream);
+ EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMF_ERROR_NULL_VALUE);
+ }
+
+ err = *(int*)ipcEmailAPI_GetParameter(hAPI, ePARAMETER_OUT, 0);
+ if (err == EMF_ERROR_NONE)
+ {
+ if(handle)
+ handle = *(unsigned int*)ipcEmailAPI_GetParameter(hAPI, ePARAMETER_OUT, 1); /* Warning removal changes */
+ }
+
+ EM_DEBUG_LOG(" >>>>>> ERROR CODE : %d ", err);
+
+ ipcEmailAPI_Destroy(hAPI);
+ hAPI = NULL;
+ EM_SAFE_FREE(pSendingOption);
+ EM_SAFE_FREE(mailbox_stream);
+#endif /* __FEATURE_SUPPORT_ACTIVE_SYNC__ */
+ EM_DEBUG_FUNC_END("err [%d]", err);
+ return err;
+}
+
+EXPORT_API int email_send_saved(int account_id, emf_option_t* sending_option, unsigned* handle)
+{
+ EM_DEBUG_FUNC_BEGIN("account_id[%d], sending_option[%p], handle[%p]", account_id, sending_option, handle);
+
+ char* pOptionStream = NULL;
+ int err = EMF_ERROR_NONE;
+ int size = 0;
+
+ EM_IF_NULL_RETURN_VALUE(account_id, EMF_ERROR_INVALID_PARAM);
+ EM_IF_NULL_RETURN_VALUE(sending_option, EMF_ERROR_INVALID_PARAM);
+ EM_IF_ACCOUNT_ID_NULL(account_id, EMF_ERROR_INVALID_PARAM);
+
+ HIPC_API hAPI = ipcEmailAPI_Create(_EMAIL_API_MAIL_SEND_SAVED);
+
+ EM_IF_NULL_RETURN_VALUE(hAPI, EMF_ERROR_NULL_VALUE);
+
+ /* Account ID */
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, &(account_id), sizeof(int)))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter account_id Fail");
+
+ /* Sending Option */
+ pOptionStream = em_convert_option_to_byte_stream(sending_option, &size);
+
+ EM_PROXY_IF_NULL_RETURN_VALUE(pOptionStream, hAPI, EMF_ERROR_NULL_VALUE);
+
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, pOptionStream, size))
+ EM_DEBUG_EXCEPTION("Add Param sending option Fail");
+
+ /* Execute API */
+ if(!ipcEmailProxy_ExecuteAPI(hAPI)) {
+ EM_DEBUG_EXCEPTION("ipcEmailProxy_ExecuteAPIFail");
+ EM_SAFE_FREE(pOptionStream);
+ EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMF_ERROR_IPC_SOCKET_FAILURE);
+ }
+
+ err = *(int*)ipcEmailAPI_GetParameter(hAPI, ePARAMETER_OUT, 0);
+ ipcEmailAPI_Destroy(hAPI);
+
+ hAPI = NULL;
+ EM_SAFE_FREE(pOptionStream);
+
+ EM_DEBUG_FUNC_END("err [%d]", err);
+ return err;
+}
+
+EXPORT_API int email_send_report(emf_mail_t* mail, unsigned* handle)
+{
+ EM_DEBUG_FUNC_BEGIN("mail[%p], handle[%p]", mail, handle);
+
+ char* pMailHeadStream = NULL;
+ char* pMailBodyStream = NULL;
+ char* pMailInfoStream = NULL;
+ int size = 0;
+ int err = EMF_ERROR_NONE;
+
+ if (!mail || !mail->info || mail->info->account_id <= 0 || !mail->head ||
+ !mail->head->from || !mail->head->mid) {
+ if (mail != NULL) {
+ if (mail->info != NULL) {
+ if (mail->head != NULL)
+ EM_DEBUG_LOG("mail->info->account_id[%d], mail->head->from[%p], mail->head->mid[%p]", mail->info->account_id, mail->head->from, mail->head->mid); else
+ EM_DEBUG_LOG("mail->info->account_id[%d], mail->head[%p]", mail->info->account_id, mail->head);
+ } else {
+ if (mail->head != NULL)
+ EM_DEBUG_LOG("mail->info[%p], mail->head->from[%p], mail->head->mid[%p]", mail->info, mail->head->from, mail->head->mid); else
+ EM_DEBUG_LOG("mail->info[%p], mail->head[%p]", mail->info, mail->head);
+ }
+ } else
+ EM_DEBUG_LOG("mail[%p]", mail);
+
+ err = EMF_ERROR_INVALID_MAIL;
+ EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_MAIL");
+ EM_DEBUG_FUNC_END("err [%d]", err);
+ return err;
+ }
+
+ HIPC_API hAPI = ipcEmailAPI_Create(_EMAIL_API_MAIL_SEND_REPORT);
+
+ EM_IF_NULL_RETURN_VALUE(hAPI, EMF_ERROR_NULL_VALUE);
+
+ /* Head */
+ pMailHeadStream = em_convert_mail_head_to_byte_stream(mail->head, &size);
+
+ EM_PROXY_IF_NULL_RETURN_VALUE(pMailHeadStream, hAPI, EMF_ERROR_NULL_VALUE);
+
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, pMailHeadStream, size))
+ EM_DEBUG_EXCEPTION("Add Param mail head Fail ");
+
+ /* Body */
+ pMailBodyStream = em_convert_mail_body_to_byte_stream(mail->body, &size);
+
+ if(NULL == pMailBodyStream) {
+ EM_SAFE_FREE(pMailHeadStream);
+ EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMF_ERROR_NULL_VALUE);
+ }
+
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, pMailBodyStream, size))
+ EM_DEBUG_EXCEPTION("Add Param mail body Fail ");
+
+ /* Info */
+ pMailInfoStream = em_convert_mail_info_to_byte_stream(mail->info, &size);
+
+ /* EM_PROXY_IF_NULL_RETURN_VALUE(pMailInfoStream, hAPI, EMF_ERROR_NULL_VALUE); */
+ if(NULL == pMailInfoStream) {
+ EM_SAFE_FREE(pMailHeadStream);
+ EM_SAFE_FREE(pMailBodyStream);
+ EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMF_ERROR_NULL_VALUE);
+ }
+
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, pMailInfoStream, size))
+ EM_DEBUG_EXCEPTION("Add Param mail body Fail");
+
+ /* Execute API */
+ if(!ipcEmailProxy_ExecuteAPI(hAPI)) {
+ EM_DEBUG_EXCEPTION("ipcEmailProxy_ExecuteAPIFail");
+ EM_SAFE_FREE(pMailInfoStream);
+ EM_SAFE_FREE(pMailBodyStream);
+ EM_SAFE_FREE(pMailHeadStream);
+ EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMF_ERROR_IPC_SOCKET_FAILURE);
+ }
+
+ err = *(int*)ipcEmailAPI_GetParameter(hAPI, ePARAMETER_OUT, 0);
+
+ EM_SAFE_FREE(pMailHeadStream);
+ EM_SAFE_FREE(pMailBodyStream);
+ EM_SAFE_FREE(pMailInfoStream);
+
+ ipcEmailAPI_Destroy(hAPI);
+
+ hAPI = NULL;
+
+ EM_DEBUG_FUNC_END("err [%d]", err);
+ return err;
+}
+
+EXPORT_API int email_sync_local_activity(int account_id)
+{
+ EM_DEBUG_FUNC_BEGIN("account_id[%d]", account_id);
+
+ int err = EMF_ERROR_NONE;
+
+ if (account_id < 0 || account_id == 0) {
+ EM_DEBUG_EXCEPTION("account_id[%d]", account_id);
+
+ return EMF_ERROR_INVALID_PARAM;
+ }
+
+ HIPC_API hAPI = ipcEmailAPI_Create(_EMAIL_API_SYNC_LOCAL_ACTIVITY);
+
+ EM_IF_NULL_RETURN_VALUE(hAPI, EMF_ERROR_NULL_VALUE);
+
+ /* account_id */
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, (char*)&account_id, sizeof(int)))
+ EM_DEBUG_EXCEPTION("Add Param account_id Fail");
+
+ if(!ipcEmailProxy_ExecuteAPI(hAPI)) {
+ EM_DEBUG_EXCEPTION("ipcEmailProxy_ExecuteAPIFail");
+ EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMF_ERROR_IPC_SOCKET_FAILURE);
+ }
+
+ err = *(int*)ipcEmailAPI_GetParameter(hAPI, ePARAMETER_OUT, 0);
+
+ ipcEmailAPI_Destroy(hAPI);
+
+ hAPI = NULL;
+ EM_DEBUG_FUNC_END("err [%d]", err);
+ return err;
+}
+
+int EmfMailboxSyncHeader(emf_mailbox_t* mailbox, unsigned* handle, int* err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("mailbox[%p], handle[%p], err_code[%p]", mailbox, handle, err_code);
+ int err = EMF_ERROR_NONE;
+
+ err = email_sync_header(mailbox,handle);
+
+ if (err_code != NULL)
+ *err_code = err;
+
+ return (err >= 0);
+}
+
+EXPORT_API int email_sync_header(emf_mailbox_t* mailbox, unsigned* handle)
+{
+ EM_DEBUG_FUNC_BEGIN("mailbox[%p], handle[%p]", mailbox, handle);
+ char* mailbox_stream = NULL;
+ int err = EMF_ERROR_NONE;
+ int size = 0;
+ /* int total_count = 0; */
+
+ EM_IF_NULL_RETURN_VALUE(mailbox, EMF_ERROR_INVALID_PARAM);
+ EM_IF_ACCOUNT_ID_NULL(mailbox->account_id, EMF_ERROR_INVALID_PARAM);
+
+#ifdef __FEATURE_SUPPORT_ACTIVE_SYNC__
+ emf_account_server_t account_server_type;
+ HIPC_API hAPI = NULL;
+ ASNotiData as_noti_data;
+ memset(&as_noti_data, 0x00, sizeof(ASNotiData));
+
+ /* 2010/02/12 ch715.lee : check account bind type and branch off */
+ if ( email_get_account_server_type_by_account_id(mailbox->account_id, &account_server_type, true, &err) == false ) {
+ EM_DEBUG_EXCEPTION("email_get_account_server_type_by_account_id failed[%d]", err);
+ goto FINISH_OFF;
+ }
+
+ if ( account_server_type == EMF_SERVER_TYPE_ACTIVE_SYNC ) {
+ int as_handle;
+ if ( email_get_handle_for_activesync(&as_handle, &err) == false ) {
+ EM_DEBUG_EXCEPTION("email_get_handle_for_activesync failed[%d].", err);
+ goto FINISH_OFF;
+ }
+
+ /* noti to active sync */
+ as_noti_data.sync_header.handle = as_handle;
+ as_noti_data.sync_header.account_id = mailbox->account_id;
+ /* In case that Mailbox is NULL, SYNC ALL MAILBOX */
+ as_noti_data.sync_header.mailbox_name = (mailbox && mailbox->name) ? strdup(mailbox->name) : NULL;
+
+ if ( email_send_notification_to_active_sync_engine(ACTIVE_SYNC_NOTI_SYNC_HEADER, &as_noti_data) == false) {
+ EM_DEBUG_EXCEPTION("email_send_notification_to_active_sync_engine failed.");
+ err = EMF_ERROR_ACTIVE_SYNC_NOTI_FAILURE;
+ goto FINISH_OFF;
+ }
+
+ if(handle)
+ *handle = as_handle;
+
+ }
+ else {
+ hAPI = ipcEmailAPI_Create(_EMAIL_API_SYNC_HEADER);
+
+ EM_IF_NULL_RETURN_VALUE(hAPI, EMF_ERROR_NULL_VALUE);
+
+ mailbox_stream = em_convert_mailbox_to_byte_stream(mailbox, &size);
+
+ EM_PROXY_IF_NULL_RETURN_VALUE(mailbox_stream, hAPI, EMF_ERROR_NULL_VALUE);
+
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, mailbox_stream, size))
+ EM_DEBUG_EXCEPTION("Add Param mail head Fail ");
+
+ if(!ipcEmailProxy_ExecuteAPI(hAPI)) {
+ EM_DEBUG_EXCEPTION("ipcEmailProxy_ExecuteAPIFail ");
+ EM_SAFE_FREE(mailbox_stream);
+ EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMF_ERROR_IPC_SOCKET_FAILURE);
+ }
+
+ err = *(int*)ipcEmailAPI_GetParameter(hAPI, ePARAMETER_OUT, 0);
+
+ if (err != EMF_ERROR_NONE)
+ goto FINISH_OFF;
+
+ if(handle)
+ *handle = *(int*)ipcEmailAPI_GetParameter(hAPI, ePARAMETER_OUT, 1);
+ }
+
+FINISH_OFF:
+ ipcEmailAPI_Destroy(hAPI);
+ hAPI = NULL;
+ EM_SAFE_FREE(mailbox_stream);
+ EM_SAFE_FREE(as_noti_data.sync_header.mailbox_name);
+#else /* __FEATURE_SUPPORT_ACTIVE_SYNC__ */
+ HIPC_API hAPI = ipcEmailAPI_Create(_EMAIL_API_SYNC_HEADER);
+
+ EM_IF_NULL_RETURN_VALUE(hAPI, EMF_ERROR_NULL_VALUE);
+
+ mailbox_stream = em_convert_mailbox_to_byte_stream(mailbox, &size);
+
+ EM_PROXY_IF_NULL_RETURN_VALUE(mailbox_stream, hAPI, EMF_ERROR_NULL_VALUE);
+
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, mailbox_stream, size))
+ EM_DEBUG_EXCEPTION("Add Param mail head Fail ");
+
+ if(!ipcEmailProxy_ExecuteAPI(hAPI)) {
+ EM_DEBUG_EXCEPTION("ipcEmailProxy_ExecuteAPIFail ");
+ EM_SAFE_FREE(mailbox_stream);
+ EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMF_ERROR_NULL_VALUE);
+ }
+
+ err = *(int*)ipcEmailAPI_GetParameter(hAPI, ePARAMETER_OUT, 0);
+
+ EM_DEBUG_LOG(" >>>>>> RETURN VALUE : %d ", err);
+
+ if (err != EMF_ERROR_NONE)
+ goto FINISH_OFF;
+
+ if(handle)
+ *handle = *(int*)ipcEmailAPI_GetParameter(hAPI, ePARAMETER_OUT, 1);
+FINISH_OFF:
+ ipcEmailAPI_Destroy(hAPI);
+ hAPI = NULL;
+ EM_SAFE_FREE(mailbox_stream);
+#endif /* __FEATURE_SUPPORT_ACTIVE_SYNC__ */
+
+ EM_DEBUG_FUNC_END("err [%d]", err);
+ return err;
+}
+
+
+EXPORT_API int email_sync_header_for_all_account(unsigned* handle)
+{
+ EM_DEBUG_FUNC_BEGIN("handle[%p]", handle);
+ char* mailbox_stream = NULL;
+ emf_mailbox_t mailbox;
+ int err = EMF_ERROR_NONE;
+ int size = 0;
+ HIPC_API hAPI = NULL;
+ int return_handle;
+#ifdef __FEATURE_SUPPORT_ACTIVE_SYNC__
+ ASNotiData as_noti_data;
+ int i, account_count = 0;
+ emf_mail_account_tbl_t *account_tbl_array = NULL;
+ int as_err;
+#endif
+
+ hAPI = ipcEmailAPI_Create(_EMAIL_API_SYNC_HEADER);
+
+ EM_IF_NULL_RETURN_VALUE(hAPI, EMF_ERROR_NULL_VALUE);
+
+ mailbox.account_id = ALL_ACCOUNT;
+ mailbox.name = NULL;
+ mailbox.alias = NULL;
+ mailbox.account_name = NULL;
+
+ mailbox_stream = em_convert_mailbox_to_byte_stream(&mailbox, &size);
+
+ EM_PROXY_IF_NULL_RETURN_VALUE(mailbox_stream, hAPI, EMF_ERROR_NULL_VALUE);
+
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, mailbox_stream, size))
+ EM_DEBUG_EXCEPTION("Add Param mail head Fail ");
+
+ if(!ipcEmailProxy_ExecuteAPI(hAPI)) {
+ EM_DEBUG_EXCEPTION("ipcEmailProxy_ExecuteAPIFail ");
+ EM_SAFE_FREE(mailbox_stream);
+ EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMF_ERROR_IPC_SOCKET_FAILURE);
+ }
+
+ err = *(int*)ipcEmailAPI_GetParameter(hAPI, ePARAMETER_OUT, 0);
+
+ if (err != EMF_ERROR_NONE)
+ goto FINISH_OFF;
+
+ return_handle = *(int*)ipcEmailAPI_GetParameter(hAPI, ePARAMETER_OUT, 1);
+
+#ifdef __FEATURE_SUPPORT_ACTIVE_SYNC__
+ memset(&as_noti_data, 0x00, sizeof(ASNotiData));
+
+ /* Get all accounts for sending notification to active sync engine. */
+ if (!em_storage_get_account_list(&account_count, &account_tbl_array , true, false, &as_err)) {
+ EM_DEBUG_EXCEPTION("email_get_account_list-- Failed [ %d ] ", as_err);
+ err = em_storage_get_emf_error_from_em_storage_error(as_err);
+ goto FINISH_OFF;
+ }
+
+ for(i = 0; i < account_count; i++) {
+ if ( account_tbl_array[i].receiving_server_type == EMF_SERVER_TYPE_ACTIVE_SYNC ) {
+ /* use returned handle value for a active sync handle */
+ /* int as_handle; */
+ /*
+ if ( email_get_handle_for_activesync(&as_handle, &err) == false ) {
+ EM_DEBUG_EXCEPTION("email_get_handle_for_activesync failed[%d].", err);
+ goto FINISH_OFF;
+ }
+ */
+
+ /* noti to active sync */
+ as_noti_data.sync_header.handle = return_handle;
+ as_noti_data.sync_header.account_id = account_tbl_array[i].account_id;
+ /* In case that Mailbox is NULL, SYNC ALL MAILBOX */
+ as_noti_data.sync_header.mailbox_name = NULL;
+
+ if ( email_send_notification_to_active_sync_engine(ACTIVE_SYNC_NOTI_SYNC_HEADER, &as_noti_data) == false) {
+ EM_DEBUG_EXCEPTION("email_send_notification_to_active_sync_engine failed.");
+ err = EMF_ERROR_ACTIVE_SYNC_NOTI_FAILURE;
+ goto FINISH_OFF;
+ }
+ }
+ }
+#endif /* __FEATURE_SUPPORT_ACTIVE_SYNC__ */
+
+
+ if(handle)
+ *handle = return_handle;
+
+FINISH_OFF:
+
+ ipcEmailAPI_Destroy(hAPI);
+ hAPI = NULL;
+ EM_SAFE_FREE(mailbox_stream);
+ if ( account_tbl_array )
+ em_storage_free_account(&account_tbl_array, account_count, NULL);
+
+ EM_DEBUG_FUNC_END("err [%d]", err);
+ return err;
+}
+
+EXPORT_API int email_download_body(emf_mailbox_t* mailbox, int mail_id, int with_attachment, unsigned* handle)
+{
+ EM_DEBUG_FUNC_BEGIN("mailbox[%p], mail_id[%d],with_attachment[%d]", mailbox, mail_id, with_attachment);
+ char* mailbox_stream = NULL;
+ int err = EMF_ERROR_NONE;
+ int size = 0;
+
+ EM_IF_NULL_RETURN_VALUE(mailbox, EMF_ERROR_INVALID_PARAM);
+ EM_IF_NULL_RETURN_VALUE(mail_id, EMF_ERROR_INVALID_PARAM);
+ EM_IF_ACCOUNT_ID_NULL(mailbox->account_id, EMF_ERROR_INVALID_PARAM);
+
+#ifdef __FEATURE_SUPPORT_ACTIVE_SYNC__
+ emf_account_server_t account_server_type;
+ HIPC_API hAPI = NULL;
+ ASNotiData as_noti_data;
+ memset(&as_noti_data, 0x00, sizeof(ASNotiData));
+
+ /* 2010/02/12 ch715.lee : check account bind type and branch off */
+ if ( email_get_account_server_type_by_account_id(mailbox->account_id, &account_server_type, true, &err) == false ) {
+ EM_DEBUG_EXCEPTION("email_get_account_server_type_by_account_id failed[%d]", err);
+ goto FINISH_OFF;
+ }
+
+ if ( account_server_type == EMF_SERVER_TYPE_ACTIVE_SYNC ) {
+ int as_handle;
+ if ( email_get_handle_for_activesync(&as_handle, &err) == false ) {
+ EM_DEBUG_EXCEPTION("email_get_handle_for_activesync failed[%d].", err);
+ goto FINISH_OFF;
+ }
+
+ /* noti to active sync */
+ as_noti_data.download_body.handle = as_handle;
+ as_noti_data.download_body.account_id = mailbox->account_id;
+ as_noti_data.download_body.mail_id = mail_id;
+ as_noti_data.download_body.with_attachment = with_attachment;
+
+ if ( email_send_notification_to_active_sync_engine(ACTIVE_SYNC_NOTI_DOWNLOAD_BODY, &as_noti_data) == false) {
+ EM_DEBUG_EXCEPTION("email_send_notification_to_active_sync_engine failed.");
+ err = EMF_ERROR_ACTIVE_SYNC_NOTI_FAILURE;
+ goto FINISH_OFF;
+ }
+
+ if(handle)
+ *handle = as_handle;
+ } else {
+ hAPI = ipcEmailAPI_Create(_EMAIL_API_DOWNLOAD_BODY);
+
+ EM_IF_NULL_RETURN_VALUE(hAPI, EMF_ERROR_NULL_VALUE);
+
+ mailbox_stream = em_convert_mailbox_to_byte_stream(mailbox, &size);
+
+ EM_PROXY_IF_NULL_RETURN_VALUE(mailbox_stream, hAPI, EMF_ERROR_NULL_VALUE);
+
+ /* MailBox Information */
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, mailbox_stream, size))
+ EM_DEBUG_EXCEPTION("Add Param mail head Fail ");
+
+ /* Mail Id */
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, (char*)&mail_id, sizeof(int)))
+ EM_DEBUG_EXCEPTION("Add Param mail head Fail ");
+
+ /* with_attachment */
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, (char*)&with_attachment, sizeof(int)))
+ EM_DEBUG_EXCEPTION("Add Param mail head Fail ");
+
+ if(!ipcEmailProxy_ExecuteAPI(hAPI)) {
+ EM_DEBUG_EXCEPTION("ipcEmailProxy_ExecuteAPIFail ");
+ EM_SAFE_FREE(mailbox_stream);
+ EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMF_ERROR_IPC_SOCKET_FAILURE);
+ }
+
+ err = *(int*)ipcEmailAPI_GetParameter(hAPI, ePARAMETER_OUT, 0);
+ if (err != EMF_ERROR_NONE)
+ goto FINISH_OFF;
+
+ if(handle)
+ {
+ *handle = *(int*)ipcEmailAPI_GetParameter(hAPI, ePARAMETER_OUT, 1);
+ EM_DEBUG_LOG(" >>>>>>>>>>>>>>>>>>> RETURN VALUE : %d handle %d", err, *handle);
+
+ }
+ }
+
+FINISH_OFF:
+ ipcEmailAPI_Destroy(hAPI);
+ hAPI = NULL;
+ EM_SAFE_FREE(mailbox_stream);
+#else /* __FEATURE_SUPPORT_ACTIVE_SYNC__ */
+ HIPC_API hAPI = ipcEmailAPI_Create(_EMAIL_API_DOWNLOAD_BODY);
+
+ EM_IF_NULL_RETURN_VALUE(hAPI, EMF_ERROR_NULL_VALUE);
+
+ mailbox_stream = em_convert_mailbox_to_byte_stream(mailbox, &size);
+
+ EM_PROXY_IF_NULL_RETURN_VALUE(mailbox_stream, hAPI, EMF_ERROR_NULL_VALUE);
+
+ /* MailBox Information */
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, mailbox_stream, size))
+ EM_DEBUG_EXCEPTION("Add Param mail head Fail ");
+
+ /* Mail Id */
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, (char*)&mail_id, size))
+ EM_DEBUG_EXCEPTION("Add Param mail head Fail ");
+
+ /* with_attachment */
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, (char*)&with_attachment, size))
+ EM_DEBUG_EXCEPTION("Add Param mail head Fail ");
+
+ if(!ipcEmailProxy_ExecuteAPI(hAPI)) {
+ EM_DEBUG_EXCEPTION("ipcEmailProxy_ExecuteAPIFail ");
+ EM_SAFE_FREE(mailbox_stream);
+ EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMF_ERROR_IPC_SOCKET_FAILURE);
+ }
+
+ err = *(int*)ipcEmailAPI_GetParameter(hAPI, ePARAMETER_OUT, 0);
+ if (err != EMF_ERROR_NONE)
+ goto FINISH_OFF;
+
+ /* Download handle - 17-Apr-07 */
+ if(handle) {
+ *handle = *(int*)ipcEmailAPI_GetParameter(hAPI, ePARAMETER_OUT, 1);
+ EM_DEBUG_LOG(" >>>>>>>>>>>>>>>>>>> RETURN VALUE : %d handle %d", err, *handle);
+
+ }
+FINISH_OFF:
+
+ ipcEmailAPI_Destroy(hAPI);
+ hAPI = NULL;
+ EM_SAFE_FREE(mailbox_stream);
+
+#endif /* __FEATURE_SUPPORT_ACTIVE_SYNC__ */
+
+ EM_DEBUG_FUNC_END("err [%d]", err);
+ return err;
+
+}
+
+
+
+
+
+/* API - Downloads the Email Attachment Information [ INTERNAL ] */
+
+EXPORT_API int email_download_attachment(emf_mailbox_t* mailbox,int mail_id, const char* nth,unsigned* handle)
+{
+ EM_DEBUG_FUNC_BEGIN("mailbox[%p], mail_id[%d], nth[%p], handle[%p]", mailbox, mail_id, nth, handle);
+ char* mailbox_stream = NULL;
+ int err = EMF_ERROR_NONE;
+ int size = 0;
+
+ EM_IF_NULL_RETURN_VALUE(mailbox, EMF_ERROR_INVALID_PARAM);
+ EM_IF_NULL_RETURN_VALUE(mail_id, EMF_ERROR_INVALID_PARAM);
+ EM_IF_ACCOUNT_ID_NULL(mailbox->account_id, EMF_ERROR_INVALID_PARAM);
+ /* EM_IF_NULL_RETURN_VALUE(nth, EMF_ERROR_INVALID_PARAM); */
+
+#ifdef __FEATURE_SUPPORT_ACTIVE_SYNC__
+ emf_account_server_t account_server_type;
+ HIPC_API hAPI = NULL;
+ ASNotiData as_noti_data;
+ memset(&as_noti_data, 0x00, sizeof(ASNotiData));
+
+ if ( email_get_account_server_type_by_account_id(mailbox->account_id, &account_server_type, true, &err) == false ) {
+ EM_DEBUG_EXCEPTION("email_get_account_server_type_by_account_id failed[%d]", err);
+ goto FINISH_OFF;
+ }
+
+ if ( account_server_type == EMF_SERVER_TYPE_ACTIVE_SYNC ) {
+ int as_handle;
+ if ( email_get_handle_for_activesync(&as_handle, &err) == false ) {
+ EM_DEBUG_EXCEPTION("email_get_handle_for_activesync failed[%d].", err);
+ goto FINISH_OFF;
+ }
+
+ /* noti to active sync */
+ as_noti_data.download_attachment.handle = as_handle;
+ as_noti_data.download_attachment.account_id = mailbox->account_id;
+ as_noti_data.download_attachment.mail_id = mail_id;
+ as_noti_data.download_attachment.attachment_order = strdup(nth);
+ if ( email_send_notification_to_active_sync_engine(ACTIVE_SYNC_NOTI_DOWNLOAD_ATTACHMENT, &as_noti_data) == false) {
+ EM_DEBUG_EXCEPTION("email_send_notification_to_active_sync_engine failed.");
+ err = EMF_ERROR_ACTIVE_SYNC_NOTI_FAILURE;
+ goto FINISH_OFF;
+ }
+
+ if(handle)
+ *handle = as_handle;
+ } else {
+ hAPI = ipcEmailAPI_Create(_EMAIL_API_DOWNLOAD_ATTACHMENT);
+
+ EM_IF_NULL_RETURN_VALUE(hAPI, EMF_ERROR_NULL_VALUE);
+
+ /* Mailbox */
+ mailbox_stream = em_convert_mailbox_to_byte_stream(mailbox, &size);
+
+ EM_PROXY_IF_NULL_RETURN_VALUE(mailbox_stream, hAPI, EMF_ERROR_NULL_VALUE);
+
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, mailbox_stream, size))
+ EM_DEBUG_EXCEPTION("Add Param mailbox Fail ");
+
+ /* Mail ID */
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, &(mail_id), sizeof(int)))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter mail_id Fail ");
+
+ /* nth */
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, (char*) nth, sizeof(nth)))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter mail_id Fail ");
+
+ /* Execute API */
+ if(!ipcEmailProxy_ExecuteAPI(hAPI)) {
+ EM_DEBUG_EXCEPTION("ipcEmailProxy_ExecuteAPIFail ");
+ EM_SAFE_FREE(mailbox_stream);
+ EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMF_ERROR_IPC_SOCKET_FAILURE);
+ }
+
+ err = *(int*)ipcEmailAPI_GetParameter(hAPI, ePARAMETER_OUT, 0);
+ if (err != EMF_ERROR_NONE)
+ goto FINISH_OFF;
+
+ if(handle)
+ *handle = *(int*)ipcEmailAPI_GetParameter(hAPI, ePARAMETER_OUT, 1);
+
+ }
+
+FINISH_OFF:
+ ipcEmailAPI_Destroy(hAPI);
+ hAPI = NULL;
+ EM_SAFE_FREE(mailbox_stream);
+ EM_SAFE_FREE(as_noti_data.download_attachment.attachment_order);
+#else /* __FEATURE_SUPPORT_ACTIVE_SYNC__ */
+ HIPC_API hAPI = ipcEmailAPI_Create(_EMAIL_API_DOWNLOAD_ATTACHMENT);
+
+ EM_IF_NULL_RETURN_VALUE(hAPI, EMF_ERROR_NULL_VALUE);
+
+ /* Mailbox */
+ mailbox_stream = em_convert_mailbox_to_byte_stream(mailbox, &size);
+
+ EM_PROXY_IF_NULL_RETURN_VALUE(mailbox_stream, hAPI, EMF_ERROR_NULL_VALUE);
+
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, mailbox_stream, size))
+ EM_DEBUG_EXCEPTION("EmfDownloadAttachment--Add Param mailbox Fail ");
+
+ /* Mail ID */
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, &(mail_id), sizeof(int)))
+ EM_DEBUG_EXCEPTION(" EmfDownloadAttachment ipcEmailAPI_AddParameter mail_idFail ");
+
+ /* nth */
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, nth, sizeof(nth)))
+ EM_DEBUG_EXCEPTION(" EmfDownloadAttachment ipcEmailAPI_AddParameter mail_idFail ");
+
+ /* Execute API */
+ if(!ipcEmailProxy_ExecuteAPI(hAPI)) {
+ EM_DEBUG_EXCEPTION("EmfDownloadAttachment--ipcEmailProxy_ExecuteAPIFail ");
+ EM_SAFE_FREE(mailbox_stream);
+ EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMF_ERROR_IPC_SOCKET_FAILURE);
+ }
+
+ err = *(int*)ipcEmailAPI_GetParameter(hAPI, ePARAMETER_OUT, 0);
+
+ EM_DEBUG_LOG(" >>>>> EmfDownloadAttachment RETURN VALUE : %d ", err);
+
+ if (err != EMF_ERROR_NONE)
+ goto FINISH_OFF;
+
+ if(handle)
+ *handle = *(int*)ipcEmailAPI_GetParameter(hAPI, ePARAMETER_OUT, 1);
+
+ /* Prevent defect 36700 */
+ /* EM_DEBUG_LOG(" >>>>> Handle_proxy : %d ", *handle); */
+FINISH_OFF:
+ ipcEmailAPI_Destroy(hAPI);
+ hAPI = NULL;
+ EM_SAFE_FREE(mailbox_stream);
+#endif /* __FEATURE_SUPPORT_ACTIVE_SYNC__ */
+
+ EM_DEBUG_FUNC_END("err [%d]", err);
+ return err;
+
+}
+
+
+EXPORT_API int email_cancel_job(int account_id, int handle)
+{
+ EM_DEBUG_FUNC_BEGIN("account_id [%d], handle [%d]", account_id, handle);
+ int err = EMF_ERROR_NONE;
+
+ if(account_id < 0)
+ return EMF_ERROR_INVALID_PARAM;
+#ifdef __FEATURE_SUPPORT_ACTIVE_SYNC__
+ emf_account_server_t account_server_type;
+ HIPC_API hAPI = NULL;
+ ASNotiData as_noti_data;
+ emf_mail_account_tbl_t *account_list = NULL;
+ int i, account_count = 0;
+ void *return_from_ipc = NULL;
+
+ if ( account_id == ALL_ACCOUNT ) { /* this means that job is executed with all account */
+ /* Get all accounts for sending notification to active sync engine. */
+ if (!em_storage_get_account_list(&account_count, &account_list , true, false, &err)) {
+ EM_DEBUG_EXCEPTION("email_get_account_list-- Failed [ %d ] ", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+
+ for(i = 0; i < account_count; i++) {
+ if ( email_get_account_server_type_by_account_id(account_list[i].account_id, &account_server_type, true, &err) == false ) {
+ EM_DEBUG_EXCEPTION("email_get_account_server_type_by_account_id failed[%d]", err);
+ goto FINISH_OFF;
+ }
+
+ if ( account_server_type == EMF_SERVER_TYPE_ACTIVE_SYNC ) {
+ memset(&as_noti_data, 0x00, sizeof(ASNotiData));
+ as_noti_data.cancel_job.account_id = account_list[i].account_id;
+ as_noti_data.cancel_job.handle = handle;
+
+ if ( email_send_notification_to_active_sync_engine(ACTIVE_SYNC_NOTI_CANCEL_JOB, &as_noti_data) == false) {
+ EM_DEBUG_EXCEPTION("email_send_notification_to_active_sync_engine failed.");
+ err = EMF_ERROR_ACTIVE_SYNC_NOTI_FAILURE;
+ goto FINISH_OFF;
+ }
+ }
+ }
+
+ /* request canceling to stub */
+ hAPI = ipcEmailAPI_Create(_EMAIL_API_CANCEL_JOB);
+
+ EM_IF_NULL_RETURN_VALUE(hAPI, EMF_ERROR_NULL_VALUE);
+
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, &account_id, sizeof(int))) /* account_id == 0 */
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter account_id Fail ");
+
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, &handle, sizeof(int)))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter handle Fail ");
+
+ /* Execute API */
+ if(ipcEmailProxy_ExecuteAPI(hAPI) < 0) {
+ EM_DEBUG_EXCEPTION("ipcEmailProxy_ExecuteAPIFail ");
+ EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMF_ERROR_IPC_SOCKET_FAILURE);
+ }
+
+ return_from_ipc = ipcEmailAPI_GetParameter(hAPI, ePARAMETER_OUT, 0);
+ if (return_from_ipc) {
+ err = *(int *)return_from_ipc;
+ }
+
+ ipcEmailAPI_Destroy(hAPI);
+ hAPI = NULL;
+ }
+ else {
+ if ( email_get_account_server_type_by_account_id(account_id, &account_server_type, true, &err) == false ) {
+ EM_DEBUG_EXCEPTION("email_get_account_server_type_by_account_id failed[%d]", err);
+ goto FINISH_OFF;
+ }
+
+ if ( account_server_type == EMF_SERVER_TYPE_ACTIVE_SYNC ) {
+ memset(&as_noti_data, 0x00, sizeof(ASNotiData));
+ as_noti_data.cancel_job.account_id = account_id;
+ as_noti_data.cancel_job.handle = handle;
+
+ if ( email_send_notification_to_active_sync_engine(ACTIVE_SYNC_NOTI_CANCEL_JOB, &as_noti_data) == false) {
+ EM_DEBUG_EXCEPTION("email_send_notification_to_active_sync_engine failed.");
+ err = EMF_ERROR_ACTIVE_SYNC_NOTI_FAILURE;
+ goto FINISH_OFF;
+ }
+ } else {
+ hAPI = ipcEmailAPI_Create(_EMAIL_API_CANCEL_JOB);
+
+ EM_IF_NULL_RETURN_VALUE(hAPI, EMF_ERROR_NULL_VALUE);
+
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, &account_id, sizeof(int)))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter account_id Fail ");
+
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, &handle, sizeof(int)))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter handle Fail ");
+
+ /* Execute API */
+ if(ipcEmailProxy_ExecuteAPI(hAPI) < 0) {
+ EM_DEBUG_EXCEPTION("ipcEmailProxy_ExecuteAPIFail ");
+ EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMF_ERROR_IPC_SOCKET_FAILURE);
+ }
+
+ return_from_ipc = ipcEmailAPI_GetParameter(hAPI, ePARAMETER_OUT, 0);
+ if (return_from_ipc) {
+ err = *(int *)return_from_ipc;
+ }
+
+ ipcEmailAPI_Destroy(hAPI);
+ hAPI = NULL;
+
+ }
+ }
+
+FINISH_OFF:
+ ipcEmailAPI_Destroy(hAPI);
+ hAPI = NULL;
+ if ( account_list )
+ em_storage_free_account(&account_list, account_count, NULL);
+
+#else /* __FEATURE_SUPPORT_ACTIVE_SYNC__ */
+ HIPC_API hAPI = ipcEmailAPI_Create(_EMAIL_API_CANCEL_JOB);
+
+ EM_IF_NULL_RETURN_VALUE(hAPI, EMF_ERROR_NULL_VALUE);
+
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, &account_id, sizeof(int)))
+ EM_DEBUG_EXCEPTION(" EmfCancelJob ipcEmailAPI_AddParameter account_id Fail ");
+
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, &handle, sizeof(int)))
+ EM_DEBUG_EXCEPTION(" EmfCancelJob ipcEmailAPI_AddParameter handle Fail ");
+
+ /* Execute API */
+ if(!ipcEmailProxy_ExecuteAPI(hAPI)) {
+ EM_DEBUG_EXCEPTION("ipcEmailProxy_ExecuteAPI Fail");
+ EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMF_ERROR_IPC_SOCKET_FAILURE);
+ }
+
+ err = *(int*)ipcEmailAPI_GetParameter(hAPI, ePARAMETER_OUT, 0);
+
+ EM_DEBUG_LOG(" >>>>> EmfCancelJob RETURN VALUE : %d ", err);
+
+ ipcEmailAPI_Destroy(hAPI);
+ hAPI = NULL;
+#endif /* __FEATURE_SUPPORT_ACTIVE_SYNC__ */
+
+ EM_DEBUG_FUNC_END("err [%d]", err);
+ return err;
+}
+
+
+
+EXPORT_API int email_get_pending_job(emf_action_t action, int account_id, int mail_id, emf_event_status_type_t * status)
+{
+ EM_DEBUG_FUNC_BEGIN("action[%d], account_id[%d], mail_id[%d], status[%p]", action, account_id, mail_id, status);
+
+ int err = EMF_ERROR_NONE;
+
+ EM_IF_ACCOUNT_ID_NULL(account_id, EMF_ERROR_NULL_VALUE);
+
+ HIPC_API hAPI = ipcEmailAPI_Create(_EMAIL_API_GET_PENDING_JOB);
+
+ EM_IF_NULL_RETURN_VALUE(hAPI, EMF_ERROR_NULL_VALUE);
+
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, &action, sizeof(int)))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter action Fail ");
+
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, &account_id, sizeof(int)))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter account_id Fail ");
+
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, &mail_id, sizeof(int)))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter account_id Fail ");
+
+ /* Execute API */
+ if(!ipcEmailProxy_ExecuteAPI(hAPI)) {
+ EM_DEBUG_EXCEPTION("ipcEmailProxy_ExecuteAPI Fail ");
+ EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMF_ERROR_IPC_SOCKET_FAILURE);
+ }
+
+ err = *(int*)ipcEmailAPI_GetParameter(hAPI, ePARAMETER_OUT, 0);
+
+ if(status) {
+ *status = *(int*)ipcEmailAPI_GetParameter(hAPI, ePARAMETER_OUT, 1);
+ EM_DEBUG_LOG("status : %d ", *status);
+ }
+
+ ipcEmailAPI_Destroy(hAPI);
+ hAPI = NULL;
+
+ EM_DEBUG_FUNC_END("err [%d]", err);
+ return err;
+
+}
+
+
+
+EXPORT_API int email_get_network_status(int* on_sending, int* on_receiving)
+{
+ EM_DEBUG_FUNC_BEGIN("on_sending[%p], on_receiving[%p]", on_sending, on_receiving);
+ int err = EMF_ERROR_NONE;
+
+ HIPC_API hAPI = ipcEmailAPI_Create(_EMAIL_API_NETWORK_GET_STATUS);
+
+ EM_IF_NULL_RETURN_VALUE(hAPI, EMF_ERROR_NULL_VALUE);
+
+ /* Execute API */
+ if(!ipcEmailProxy_ExecuteAPI(hAPI)) {
+ EM_DEBUG_EXCEPTION("ipcEmailProxy_ExecuteAPI Fail");
+ ipcEmailAPI_Destroy(hAPI);
+ hAPI = NULL;
+ err = EMF_ERROR_IPC_SOCKET_FAILURE ;
+ EM_DEBUG_FUNC_END("err [%d]", err); return err;
+ }
+
+ if(on_sending)
+ *on_sending = *(int*)ipcEmailAPI_GetParameter(hAPI, ePARAMETER_OUT, 0);
+ if(on_receiving)
+ *on_receiving = *(int*)ipcEmailAPI_GetParameter(hAPI, ePARAMETER_OUT, 1);
+
+ ipcEmailAPI_Destroy(hAPI);
+ hAPI = NULL;
+ EM_DEBUG_FUNC_END("err [%d]", err);
+ return err;
+}
+
+EXPORT_API int email_get_imap_mailbox_list(int account_id, const char* mailbox, unsigned* handle)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ int err = EMF_ERROR_NONE;
+
+ if(account_id <= 0 || !mailbox) {
+ EM_DEBUG_LOG("invalid parameters");
+ return EMF_ERROR_INVALID_PARAM;
+ }
+
+ HIPC_API hAPI = ipcEmailAPI_Create(_EMAIL_API_GET_IMAP_MAILBOX_LIST);
+
+ /* account_id */
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, (char*)&account_id, sizeof(int))) {
+ EM_DEBUG_LOG("Add Param account_id Fail ");
+ EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMF_ERROR_NULL_VALUE);
+ }
+
+ if(!ipcEmailProxy_ExecuteAPI(hAPI)) {
+ EM_DEBUG_LOG("ipcProxy_ExecuteAsyncAPI Fail");
+ EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMF_ERROR_IPC_SOCKET_FAILURE);
+ }
+
+ err = *(int*)ipcEmailAPI_GetParameter(hAPI, ePARAMETER_OUT, 0);
+ if(handle)
+ *handle = *(int*)ipcEmailAPI_GetParameter(hAPI, ePARAMETER_OUT, 1);
+
+ ipcEmailAPI_Destroy(hAPI);
+ hAPI = NULL;
+
+ EM_DEBUG_FUNC_END("err [%d]", err);
+ return err;
+}
+
+EXPORT_API int email_find_mail_on_server(int input_account_id, const char *input_mailbox_name, int input_search_type, char *input_search_value, unsigned *output_handle)
+{
+ EM_DEBUG_FUNC_BEGIN("input_account_id [%d], input_mailbox_name [%p], input_search_type [%d], input_search_value [%p], output_handle [%p]", input_account_id, input_mailbox_name, input_search_type, input_search_value, output_handle);
+
+ int err = EMF_ERROR_NONE;
+ HIPC_API hAPI = NULL;
+
+ EM_IF_NULL_RETURN_VALUE(input_account_id, EMF_ERROR_INVALID_PARAM);
+ EM_IF_NULL_RETURN_VALUE(input_mailbox_name, EMF_ERROR_INVALID_PARAM);
+ EM_IF_NULL_RETURN_VALUE(input_search_value, EMF_ERROR_INVALID_PARAM);
+
+ switch ( input_search_type ) {
+ case EMF_SEARCH_FILTER_SUBJECT:
+ case EMF_SEARCH_FILTER_SENDER:
+ case EMF_SEARCH_FILTER_RECIPIENT:
+ case EMF_SEARCH_FILTER_ALL:
+ break;
+ default:
+ EM_DEBUG_EXCEPTION("Invalid search filter type[%d]", input_search_type);
+ err = EMF_ERROR_INVALID_PARAM;
+ return err;
+ }
+
+#ifdef __FEATURE_SUPPORT_ACTIVE_SYNC__
+ emf_account_server_t account_server_type = EMF_SERVER_TYPE_NONE;
+ ASNotiData as_noti_data;
+
+ memset(&as_noti_data, 0, sizeof(ASNotiData)); /* initialization of union members */
+
+ if ( email_get_account_server_type_by_account_id(input_account_id, &account_server_type, true, &err) == false ) {
+ EM_DEBUG_EXCEPTION("email_get_account_server_type_by_account_id failed[%d]", err);
+ goto FINISH_OFF;
+ }
+
+ if ( account_server_type == EMF_SERVER_TYPE_ACTIVE_SYNC ) {
+ int as_handle;
+ if ( email_get_handle_for_activesync(&as_handle, &err) == false ) {
+ EM_DEBUG_EXCEPTION("email_get_handle_for_activesync failed[%d].", err);
+ goto FINISH_OFF;
+ }
+
+ /* noti to active sync */
+ as_noti_data.find_mail_on_server.handle = as_handle;
+ as_noti_data.find_mail_on_server.account_id = input_account_id;
+ as_noti_data.find_mail_on_server.mailbox_name = EM_SAFE_STRDUP(input_mailbox_name);
+ as_noti_data.find_mail_on_server.search_type = input_search_type;
+ as_noti_data.find_mail_on_server.search_value = EM_SAFE_STRDUP(input_search_value);
+
+ if ( email_send_notification_to_active_sync_engine(ACTIVE_SYNC_NOTI_SEARCH_ON_SERVER, &as_noti_data) == false) {
+ EM_DEBUG_EXCEPTION("email_send_notification_to_active_sync_engine failed.");
+ err = EMF_ERROR_ACTIVE_SYNC_NOTI_FAILURE;
+ goto FINISH_OFF;
+ }
+
+ if(output_handle)
+ *output_handle = as_handle;
+ }
+ else
+#endif /* __FEATURE_SUPPORT_ACTIVE_SYNC__ */
+ {
+ hAPI = ipcEmailAPI_Create(_EMAIL_API_FIND_MAIL_ON_SERVER);
+
+ EM_IF_NULL_RETURN_VALUE(hAPI, EMF_ERROR_NULL_VALUE);
+
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, (void*)&input_account_id, sizeof(int)))
+ EM_DEBUG_EXCEPTION("Add Param mail head Fail ");
+
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, (void*)input_mailbox_name, strlen(input_mailbox_name)))
+ EM_DEBUG_EXCEPTION("Add Param mail head Fail ");
+
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, (void*)&input_search_type, sizeof(int)))
+ EM_DEBUG_EXCEPTION("Add Param mail head Fail ");
+
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, (void*)input_search_value, strlen(input_search_value)))
+ EM_DEBUG_EXCEPTION("Add Param mail head Fail ");
+
+ if(!ipcEmailProxy_ExecuteAPI(hAPI)) {
+ EM_DEBUG_EXCEPTION("ipcEmailProxy_ExecuteAPI failed");
+ EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMF_ERROR_IPC_SOCKET_FAILURE);
+ }
+
+ err = *(int*)ipcEmailAPI_GetParameter(hAPI, ePARAMETER_OUT, 0);
+
+ if (err != EMF_ERROR_NONE)
+ goto FINISH_OFF;
+
+ if(output_handle)
+ *output_handle = *(int*)ipcEmailAPI_GetParameter(hAPI, ePARAMETER_OUT, 1);
+ }
+
+FINISH_OFF:
+ if(hAPI) {
+ ipcEmailAPI_Destroy(hAPI);
+ hAPI = NULL;
+ }
+
+ EM_DEBUG_FUNC_END("err [%d]", err);
+ return err;
+}
diff --git a/MAPI/Emf_Mapi_Rule.c b/MAPI/Emf_Mapi_Rule.c
new file mode 100755
index 0000000..9299b6d
--- /dev/null
+++ b/MAPI/Emf_Mapi_Rule.c
@@ -0,0 +1,234 @@
+/*
+* email-service
+*
+* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+*
+* Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com>
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*
+*/
+
+
+
+/**
+ *
+ * This file contains the data structures and interfaces needed for application,
+ * to interact with Email Engine.
+ * @file Emf_Mapi_Rule.c
+ * @brief This file contains the data structures and interfaces of Rule related Functionality provided by
+ * Email Engine .
+ */
+
+#include <Emf_Mapi.h>
+#include "string.h"
+#include "Msg_Convert.h"
+#include "em-storage.h"
+#include "ipc-library.h"
+
+EXPORT_API int email_get_rule(int filter_id, emf_rule_t** filtering_set)
+{
+ EM_DEBUG_FUNC_BEGIN("filter_id[%d], filtering_set[%p]", filter_id, filtering_set);
+
+ int err = 0;
+
+ EM_IF_NULL_RETURN_VALUE(filtering_set, EMF_ERROR_INVALID_PARAM);
+ EM_IF_NULL_RETURN_VALUE(filter_id, EMF_ERROR_INVALID_PARAM);
+
+ if (!em_storage_get_rule_by_id(0, filter_id, (emf_mail_rule_tbl_t**)filtering_set, true, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_get_rule_by_id failed [%d]", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ } else
+ err = EMF_ERROR_NONE;
+
+FINISH_OFF:
+ EM_DEBUG_FUNC_END("error value [%d]", err);
+ return err;
+}
+
+
+EXPORT_API int email_get_rule_list(emf_rule_t** filtering_set, int* count)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ int err = EMF_ERROR_NONE;
+ int is_completed = 0;
+
+ EM_IF_NULL_RETURN_VALUE(filtering_set, EMF_ERROR_INVALID_PARAM);
+ EM_IF_NULL_RETURN_VALUE(count, EMF_ERROR_INVALID_PARAM);
+
+ *count = 1000;
+
+ if (!em_storage_get_rule(0, 0, 0, count, &is_completed, (emf_mail_rule_tbl_t**)filtering_set, true, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_get_rule failed [%d]", err);
+
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ } else
+ err = EMF_ERROR_NONE;
+
+
+FINISH_OFF:
+
+ return err;
+
+}
+
+EXPORT_API int email_add_rule(emf_rule_t* filtering_set)
+{
+ EM_DEBUG_FUNC_BEGIN("filtering_set[%p]", filtering_set);
+
+ int size = 0;
+ int err = EMF_ERROR_NONE;
+ char* pRuleStream = NULL;
+
+ EM_IF_NULL_RETURN_VALUE(filtering_set, EMF_ERROR_INVALID_PARAM);
+
+ HIPC_API hAPI = ipcEmailAPI_Create(_EMAIL_API_ADD_RULE);
+
+ EM_IF_NULL_RETURN_VALUE(hAPI, EMF_ERROR_NULL_VALUE);
+
+ pRuleStream = em_convert_rule_to_byte_stream(filtering_set, &size);
+
+ EM_PROXY_IF_NULL_RETURN_VALUE(pRuleStream, hAPI, EMF_ERROR_NULL_VALUE);
+
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, pRuleStream, size)) {
+ EM_DEBUG_EXCEPTION("Add Param Failed");
+ EM_SAFE_FREE(pRuleStream);
+ EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMF_ERROR_NULL_VALUE);
+ }
+
+ if(!ipcEmailProxy_ExecuteAPI(hAPI)) {
+ EM_DEBUG_EXCEPTION("ipcEmailProxy_ExecuteAPI Failed");
+ EM_SAFE_FREE(pRuleStream);
+ EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMF_ERROR_IPC_SOCKET_FAILURE);
+ }
+
+ err = *(int*)ipcEmailAPI_GetParameter(hAPI, ePARAMETER_OUT, 0);
+ EM_SAFE_FREE(pRuleStream);
+ ipcEmailAPI_Destroy(hAPI);
+ hAPI = NULL;
+ EM_DEBUG_FUNC_END("error value [%d]", err);
+ return err;
+}
+
+
+
+EXPORT_API int email_update_rule(int filter_id, emf_rule_t* new_set)
+{
+ EM_DEBUG_FUNC_BEGIN("filter_id[%d], new_set[%p]", filter_id, new_set);
+
+ int size = 0;
+ char* pFilterStream = NULL;
+ int err = EMF_ERROR_NONE;
+
+ EM_IF_NULL_RETURN_VALUE(filter_id, EMF_ERROR_INVALID_PARAM);
+ EM_IF_NULL_RETURN_VALUE(new_set, EMF_ERROR_INVALID_PARAM);
+
+ HIPC_API hAPI = ipcEmailAPI_Create(_EMAIL_API_UPDATE_RULE);
+
+ EM_IF_NULL_RETURN_VALUE(hAPI, EMF_ERROR_NULL_VALUE);
+
+ /* filter_id */
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, (char*)&filter_id, sizeof(int))) {
+ EM_DEBUG_EXCEPTION("Add Param filter_id Failed");
+ EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMF_ERROR_NULL_VALUE);
+ }
+
+ /* new_set */
+ pFilterStream = em_convert_rule_to_byte_stream(new_set, &size);
+
+ if(NULL == pFilterStream) {
+ EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMF_ERROR_NULL_VALUE);
+ }
+
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, pFilterStream, size)){
+ EM_DEBUG_EXCEPTION("Add Param new_set Failed");
+ EM_SAFE_FREE(pFilterStream);
+ EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMF_ERROR_NULL_VALUE);
+ }
+
+ if(!ipcEmailProxy_ExecuteAPI(hAPI)) {
+ EM_DEBUG_EXCEPTION("ipcEmailProxy_ExecuteAPI Failed");
+ EM_SAFE_FREE(pFilterStream);
+ EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMF_ERROR_IPC_SOCKET_FAILURE);
+ }
+
+ err = *(int*)ipcEmailAPI_GetParameter(hAPI, ePARAMETER_OUT, 0);
+
+ EM_SAFE_FREE(pFilterStream);
+ ipcEmailAPI_Destroy(hAPI);
+
+ hAPI = NULL;
+ EM_DEBUG_FUNC_END("error value [%d]", err);
+ return err;
+}
+
+
+
+
+EXPORT_API int email_delete_rule(int filter_id)
+{
+ EM_DEBUG_FUNC_BEGIN("filter_id[%d]", filter_id);
+
+ int err = EMF_ERROR_NONE;
+
+ EM_IF_NULL_RETURN_VALUE(filter_id, EMF_ERROR_INVALID_PARAM);
+
+ HIPC_API hAPI = ipcEmailAPI_Create(_EMAIL_API_DELETE_RULE);
+
+ EM_IF_NULL_RETURN_VALUE(hAPI, EMF_ERROR_NULL_VALUE);
+
+ /* filter_id */
+ if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, (char*)&filter_id, sizeof(int)))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed");
+
+
+ if(!ipcEmailProxy_ExecuteAPI(hAPI)) {
+ EM_DEBUG_EXCEPTION("ipcEmailProxy_ExecuteAPI failed");
+ EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMF_ERROR_IPC_SOCKET_FAILURE);
+ }
+
+ err = *(int*)ipcEmailAPI_GetParameter(hAPI, ePARAMETER_OUT, 0);
+ ipcEmailAPI_Destroy(hAPI);
+
+ hAPI = NULL;
+ EM_DEBUG_FUNC_END("error value [%d]", err);
+ return err;
+}
+
+EXPORT_API int email_free_rule (emf_rule_t** filtering_set, int count)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int err = EMF_ERROR_NONE, i;
+
+ EM_IF_NULL_RETURN_VALUE(filtering_set, EMF_ERROR_INVALID_PARAM);
+ EM_IF_NULL_RETURN_VALUE(count, EMF_ERROR_INVALID_PARAM);
+
+ if (count > 0) {
+ emf_rule_t* p = *filtering_set;
+
+ for (i = 0; i < count; i++) {
+ EM_SAFE_FREE(p[i].value);
+ EM_SAFE_FREE(p[i].mailbox);
+ }
+
+ EM_SAFE_FREE(p); *filtering_set = NULL;
+ }
+
+ EM_DEBUG_FUNC_END("error value [%d]", err);
+ return err;
+}
+
+
diff --git a/MAPI/Emf_Mapi_Types.c b/MAPI/Emf_Mapi_Types.c
new file mode 100755
index 0000000..c0da215
--- /dev/null
+++ b/MAPI/Emf_Mapi_Types.c
@@ -0,0 +1,2088 @@
+/*
+* email-service
+*
+* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+*
+* Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com>
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*
+*/
+
+
+
+/**
+ *
+ * This file contains the data structures and interfaces needed for application,
+ * to interact with Email Engine.
+ * @file Emf_Mapi_Types.c
+ * @author Kyuho Jo ( kyuho.jo@samsung.com )
+ * @version 0.1
+ * @brief This file contains interfaces for using data structures of email-service .
+ */
+
+#include <Emf_Mapi.h>
+#include <emf-types.h>
+
+
+EXPORT_API int email_get_info_from_mail(emf_mail_t *mail, emf_mail_info_t **info)
+{
+ if(!mail || !info)
+ return EMF_ERROR_INVALID_PARAM;
+
+ *info = mail->info;
+
+ return EMF_ERROR_NONE;
+}
+
+EXPORT_API int email_set_info_to_mail(emf_mail_t *mail, emf_mail_info_t *info)
+{
+ if(!mail || !info)
+ return EMF_ERROR_INVALID_PARAM;
+
+ mail->info = info;
+
+ return EMF_ERROR_NONE;
+}
+
+EXPORT_API int email_get_head_from_mail(emf_mail_t *mail, emf_mail_head_t **head)
+{
+ if(!mail || !head)
+ return EMF_ERROR_INVALID_PARAM;
+
+ *head = mail->head;
+
+ return EMF_ERROR_NONE;
+}
+
+EXPORT_API int email_set_head_to_mail(emf_mail_t *mail, emf_mail_head_t *head)
+{
+ if(!mail || !head)
+ return EMF_ERROR_INVALID_PARAM;
+
+ mail->head = head;
+
+ return EMF_ERROR_NONE;
+}
+
+EXPORT_API int email_get_body_from_mail(emf_mail_t *mail, emf_mail_body_t **body)
+{
+ if(!mail || !body)
+ return EMF_ERROR_INVALID_PARAM;
+
+ *body = mail->body;
+
+ return EMF_ERROR_NONE;
+}
+
+EXPORT_API int email_set_body_to_mail(emf_mail_t *mail, emf_mail_body_t *body)
+{
+ if(!mail || !body)
+ return EMF_ERROR_INVALID_PARAM;
+
+ mail->body = body;
+
+ return EMF_ERROR_NONE;
+}
+
+
+/* emf_mail_info_t ------------------------------------------------------------ */
+
+EXPORT_API int email_get_account_id_from_info(emf_mail_info_t *info, int *account_id)
+{
+ if(!info || !account_id)
+ return EMF_ERROR_INVALID_PARAM;
+
+ *account_id = info->account_id;
+
+ return EMF_ERROR_NONE;
+}
+
+EXPORT_API int email_set_account_id_to_info(emf_mail_info_t *info, int account_id)
+{
+ if(!info)
+ return EMF_ERROR_INVALID_PARAM;
+
+ info->account_id = account_id;
+
+ return EMF_ERROR_NONE;
+}
+
+EXPORT_API int email_get_uid_from_info(emf_mail_info_t *info, int *uid)
+{
+ if(!info || !uid)
+ return EMF_ERROR_INVALID_PARAM;
+
+ *uid = info->uid;
+
+ return EMF_ERROR_NONE;
+}
+
+EXPORT_API int email_set_uid_to_info(emf_mail_info_t *info, int uid)
+{
+ if(!info)
+ return EMF_ERROR_INVALID_PARAM;
+
+ info->uid = uid;
+
+ return EMF_ERROR_NONE;
+}
+
+EXPORT_API int email_get_rfc822_size_from_info(emf_mail_info_t *info, int *rfc822_size)
+{
+ if(!info || !rfc822_size)
+ return EMF_ERROR_INVALID_PARAM;
+
+ *rfc822_size = info->rfc822_size;
+
+ return EMF_ERROR_NONE;
+}
+
+EXPORT_API int email_set_rfc822_size_to_info(emf_mail_info_t *info, int rfc822_size)
+{
+ if(!info)
+ return EMF_ERROR_INVALID_PARAM;
+
+ info->rfc822_size = rfc822_size;
+
+ return EMF_ERROR_NONE;
+}
+
+EXPORT_API int email_get_body_downloaded_from_info(emf_mail_info_t *info, int *body_downloaded)
+{
+ if(!info || !body_downloaded)
+ return EMF_ERROR_INVALID_PARAM;
+
+ *body_downloaded = info->body_downloaded;
+
+ return EMF_ERROR_NONE;
+}
+
+EXPORT_API int email_set_body_downloaded_to_info(emf_mail_info_t *info, int body_downloaded)
+{
+ if(!info)
+ return EMF_ERROR_INVALID_PARAM;
+
+ info->body_downloaded = body_downloaded;
+
+ return EMF_ERROR_NONE;
+}
+
+EXPORT_API int email_get_flags_from_info(emf_mail_info_t *info, emf_mail_flag_t *flags)
+{
+ if(!info || !flags)
+ return EMF_ERROR_INVALID_PARAM;
+
+ *flags = info->flags;
+
+ return EMF_ERROR_NONE;
+}
+
+EXPORT_API int email_set_flags_to_info(emf_mail_info_t *info, emf_mail_flag_t flags)
+{
+ if(!info)
+ return EMF_ERROR_INVALID_PARAM;
+
+ info->flags = flags;
+
+ return EMF_ERROR_NONE;
+}
+
+EXPORT_API int email_get_extra_flags_from_info(emf_mail_info_t *info, emf_extra_flag_t *extra_flags)
+{
+ if(!info || !extra_flags)
+ return EMF_ERROR_INVALID_PARAM;
+
+ *extra_flags = info->extra_flags;
+
+ return EMF_ERROR_NONE;
+}
+
+EXPORT_API int email_set_extra_flags_to_info(emf_mail_info_t *info, emf_extra_flag_t extra_flags)
+{
+ if(!info)
+ return EMF_ERROR_INVALID_PARAM;
+
+ info->extra_flags = extra_flags;
+
+ return EMF_ERROR_NONE;
+}
+
+EXPORT_API int email_get_sid_from_info(emf_mail_info_t *info, char **sid)
+{
+ if(!info || !sid)
+ return EMF_ERROR_INVALID_PARAM;
+
+ *sid = info->sid;
+
+ return EMF_ERROR_NONE;
+}
+
+EXPORT_API int email_set_sid_to_info(emf_mail_info_t *info, char *sid)
+{
+ if(!info)
+ return EMF_ERROR_INVALID_PARAM;
+
+ info->sid = sid;
+
+ return EMF_ERROR_NONE;
+}
+
+/* emf_mail_head_t ------------------------------------------------------------ */
+
+EXPORT_API int email_get_mid_from_head(emf_mail_head_t *head, char **mid)
+{
+ if(!head || !mid)
+ return EMF_ERROR_INVALID_PARAM;
+
+ *mid = head->mid;
+
+ return EMF_ERROR_NONE;
+}
+
+EXPORT_API int email_set_mid_to_head(emf_mail_head_t *head, char *mid)
+{
+ if(!head)
+ return EMF_ERROR_INVALID_PARAM;
+
+ head->mid = mid;
+
+ return EMF_ERROR_NONE;
+}
+
+EXPORT_API int email_get_subject_from_head(emf_mail_head_t *head, char **subject)
+{
+ if(!head || !subject)
+ return EMF_ERROR_INVALID_PARAM;
+
+ *subject = head->subject;
+
+ return EMF_ERROR_NONE;
+}
+
+EXPORT_API int email_set_subject_to_head(emf_mail_head_t *head, char *subject)
+{
+ if(!head)
+ return EMF_ERROR_INVALID_PARAM;
+
+ head->subject = subject;
+
+ return EMF_ERROR_NONE;
+}
+
+EXPORT_API int email_get_to_from_head(emf_mail_head_t *head, char **to)
+{
+ if(!head || !to)
+ return EMF_ERROR_INVALID_PARAM;
+
+ *to = head->to;
+
+ return EMF_ERROR_NONE;
+}
+
+EXPORT_API int email_set_to_to_head(emf_mail_head_t *head, char *to)
+{
+ if(!head)
+ return EMF_ERROR_INVALID_PARAM;
+
+ head->to = to;
+
+ return EMF_ERROR_NONE;
+}
+
+EXPORT_API int email_get_from_from_head(emf_mail_head_t *head, char **from)
+{
+ if(!head || !from)
+ return EMF_ERROR_INVALID_PARAM;
+
+ *from = head->from;
+
+ return EMF_ERROR_NONE;
+}
+
+EXPORT_API int email_set_from_to_head(emf_mail_head_t *head, char *from)
+{
+ if(!head)
+ return EMF_ERROR_INVALID_PARAM;
+
+ head->from = from;
+
+ return EMF_ERROR_NONE;
+}
+
+EXPORT_API int email_get_cc_from_head(emf_mail_head_t *head, char **cc)
+{
+ if(!head || !cc)
+ return EMF_ERROR_INVALID_PARAM;
+
+ *cc = head->cc;
+
+ return EMF_ERROR_NONE;
+}
+
+EXPORT_API int email_set_cc_to_head(emf_mail_head_t *head, char *cc)
+{
+ if(!head)
+ return EMF_ERROR_INVALID_PARAM;
+
+ head->cc = cc;
+
+ return EMF_ERROR_NONE;
+}
+
+EXPORT_API int email_get_bcc_from_head(emf_mail_head_t *head, char **bcc)
+{
+ if(!head || !bcc)
+ return EMF_ERROR_INVALID_PARAM;
+
+ *bcc = head->bcc;
+
+ return EMF_ERROR_NONE;
+}
+
+EXPORT_API int email_set_bcc_to_head(emf_mail_head_t *head, char *bcc)
+{
+ if(!head)
+ return EMF_ERROR_INVALID_PARAM;
+
+ head->bcc = bcc;
+
+ return EMF_ERROR_NONE;
+}
+
+EXPORT_API int email_get_reply_from_head(emf_mail_head_t *head, char **reply)
+{
+ if(!head || !reply)
+ return EMF_ERROR_INVALID_PARAM;
+
+ *reply = head->reply_to;
+
+ return EMF_ERROR_NONE;
+}
+
+EXPORT_API int email_set_reply_to_head(emf_mail_head_t *head, char *reply)
+{
+ if(!head)
+ return EMF_ERROR_INVALID_PARAM;
+
+ head->reply_to = reply;
+
+ return EMF_ERROR_NONE;
+}
+
+EXPORT_API int email_get_return_path_from_head(emf_mail_head_t *head, char **return_path)
+{
+ if(!head || !return_path)
+ return EMF_ERROR_INVALID_PARAM;
+
+ *return_path = head->return_path;
+
+ return EMF_ERROR_NONE;
+}
+
+EXPORT_API int email_set_return_path_to_head(emf_mail_head_t *head, char *return_path)
+{
+ if(!head)
+ return EMF_ERROR_INVALID_PARAM;
+
+ head->return_path = return_path;
+
+ return EMF_ERROR_NONE;
+}
+
+EXPORT_API int email_get_datetime_from_head(emf_mail_head_t *head, emf_datetime_t *datetime)
+{
+ if(!head || !datetime)
+ return EMF_ERROR_INVALID_PARAM;
+
+ *datetime = head->datetime;
+
+ return EMF_ERROR_NONE;
+}
+
+EXPORT_API int email_set_datetime_to_head(emf_mail_head_t *head, emf_datetime_t datetime)
+{
+ if(!head)
+ return EMF_ERROR_INVALID_PARAM;
+
+ head->datetime = datetime;
+
+ return EMF_ERROR_NONE;
+}
+
+EXPORT_API int email_get_from_contact_name_from_head(emf_mail_head_t *head, char **from_contact_name)
+{
+ if(!head || !from_contact_name)
+ return EMF_ERROR_INVALID_PARAM;
+
+ *from_contact_name = head->from_contact_name;
+
+ return EMF_ERROR_NONE;
+}
+
+EXPORT_API int email_set_from_contact_name_to_head(emf_mail_head_t *head, char *from_contact_name)
+{
+ if(!head)
+ return EMF_ERROR_INVALID_PARAM;
+
+ head->from_contact_name = from_contact_name;
+
+ return EMF_ERROR_NONE;
+}
+
+EXPORT_API int email_get_to_contact_name_from_head(emf_mail_head_t *head, char **to_contact_name)
+{
+ if(!head || !to_contact_name)
+ return EMF_ERROR_INVALID_PARAM;
+
+ *to_contact_name = head->to_contact_name;
+
+ return EMF_ERROR_NONE;
+}
+
+EXPORT_API int email_set_to_contact_name_to_head(emf_mail_head_t *head, char *to_contact_name)
+{
+ if(!head)
+ return EMF_ERROR_INVALID_PARAM;
+
+ head->to_contact_name = to_contact_name;
+
+ return EMF_ERROR_NONE;
+}
+
+EXPORT_API int email_get_cc_contact_name_from_head(emf_mail_head_t *head, char **cc_contact_name)
+{
+ if(!head || !cc_contact_name)
+ return EMF_ERROR_INVALID_PARAM;
+
+ *cc_contact_name = head->cc_contact_name;
+
+ return EMF_ERROR_NONE;
+}
+
+EXPORT_API int email_set_cc_contact_name_to_head(emf_mail_head_t *head, char *cc_contact_name)
+{
+ if(!head)
+ return EMF_ERROR_INVALID_PARAM;
+
+ head->cc_contact_name = cc_contact_name;
+
+ return EMF_ERROR_NONE;
+}
+
+EXPORT_API int email_get_bcc_contact_name_from_head(emf_mail_head_t *head, char **bcc_contact_name)
+{
+ if(!head || !bcc_contact_name)
+ return EMF_ERROR_INVALID_PARAM;
+
+ *bcc_contact_name = head->bcc_contact_name;
+
+ return EMF_ERROR_NONE;
+}
+
+EXPORT_API int email_set_bcc_contact_name_to_head(emf_mail_head_t *head, char *bcc_contact_name)
+{
+ if(!head)
+ return EMF_ERROR_INVALID_PARAM;
+
+ head->bcc_contact_name = bcc_contact_name;
+
+ return EMF_ERROR_NONE;
+}
+
+EXPORT_API int email_get_preview_body_text_from_head(emf_mail_head_t *head, char **preview_body_text)
+{
+ if(!head || !preview_body_text)
+ return EMF_ERROR_INVALID_PARAM;
+
+ *preview_body_text = head->previewBodyText;
+
+ return EMF_ERROR_NONE;
+}
+
+EXPORT_API int email_set_preview_body_text_to_head(emf_mail_head_t *head, char *preview_body_text)
+{
+ if(!head)
+ return EMF_ERROR_INVALID_PARAM;
+
+ head->previewBodyText = preview_body_text;
+
+ return EMF_ERROR_NONE;
+}
+
+/* emf_mail_body_t ------------------------------------------------------------ */
+
+EXPORT_API int email_get_plain_from_body(emf_mail_body_t *body, char **plain)
+{
+ if(!body || !plain)
+ return EMF_ERROR_INVALID_PARAM;
+
+ *plain = body->plain;
+
+ return EMF_ERROR_NONE;
+}
+
+EXPORT_API int email_set_plain_to_body(emf_mail_body_t *body, char *plain)
+{
+ if(!body)
+ return EMF_ERROR_INVALID_PARAM;
+
+ body->plain = plain;
+
+ return EMF_ERROR_NONE;
+}
+
+EXPORT_API int email_get_plain_charset_from_body(emf_mail_body_t *body, char **plain_charset)
+{
+ if(!body || !plain_charset)
+ return EMF_ERROR_INVALID_PARAM;
+
+ *plain_charset = body->plain_charset;
+
+ return EMF_ERROR_NONE;
+}
+
+EXPORT_API int email_set_plain_charset_to_body(emf_mail_body_t *body, char *plain_charset)
+{
+ if(!body)
+ return EMF_ERROR_INVALID_PARAM;
+
+ body->plain_charset = plain_charset;
+
+ return EMF_ERROR_NONE;
+}
+
+EXPORT_API int email_get_html_from_body(emf_mail_body_t *body, char **html)
+{
+ if(!body || !html)
+ return EMF_ERROR_INVALID_PARAM;
+
+ *html = body->html;
+
+ return EMF_ERROR_NONE;
+}
+
+EXPORT_API int email_set_html_to_body(emf_mail_body_t *body, char *html)
+{
+ if(!body)
+ return EMF_ERROR_INVALID_PARAM;
+
+ body->html = html;
+
+ return EMF_ERROR_NONE;
+}
+
+EXPORT_API int email_get_attachment_num_from_body(emf_mail_body_t *body, int *attachment_num)
+{
+ if(!body || !attachment_num)
+ return EMF_ERROR_INVALID_PARAM;
+
+ *attachment_num = body->attachment_num;
+
+ return EMF_ERROR_NONE;
+}
+
+EXPORT_API int email_set_attachment_num_to_body(emf_mail_body_t *body, int attachment_num)
+{
+ if(!body)
+ return EMF_ERROR_INVALID_PARAM;
+
+ body->attachment_num = attachment_num;
+
+ return EMF_ERROR_NONE;
+}
+
+EXPORT_API int email_get_attachment_from_body(emf_mail_body_t *body, emf_attachment_info_t **attachment)
+{
+ if(!body || !attachment)
+ return EMF_ERROR_INVALID_PARAM;
+
+ *attachment = body->attachment;
+
+ return EMF_ERROR_NONE;
+}
+
+EXPORT_API int email_set_attachment_to_body(emf_mail_body_t *body, emf_attachment_info_t *attachment)
+{
+ if(!body)
+ return EMF_ERROR_INVALID_PARAM;
+
+ body->attachment = attachment;
+
+ return EMF_ERROR_NONE;
+}
+
+/* emf_account_t -------------------------------------------------------------- */
+
+int email_get_account_bind_type_from_account(emf_account_t *account, emf_account_bind_t account_bind_type)
+{
+ if(!account)
+ return EMF_ERROR_INVALID_PARAM;
+
+ account_bind_type = account->account_bind_type;
+
+ return EMF_ERROR_NONE;
+}
+
+int email_set_account_bind_type_to_account(emf_account_t *account, emf_account_bind_t account_bind_type)
+{
+ if(!account)
+ return EMF_ERROR_INVALID_PARAM;
+
+ account->account_bind_type = account_bind_type;
+
+ return EMF_ERROR_NONE;
+}
+
+int email_get_account_name_from_account(emf_account_t *account, char **account_name)
+{
+ if(!account)
+ return EMF_ERROR_INVALID_PARAM;
+
+ *account_name = account->account_name;
+
+
+ return EMF_ERROR_NONE;
+}
+
+int email_set_account_name_to_account(emf_account_t *account, char *account_name)
+{
+ if(!account)
+ return EMF_ERROR_INVALID_PARAM;
+
+ account->account_name = account_name;
+
+ return EMF_ERROR_NONE;
+}
+
+int email_get_receiving_server_type_from_account(emf_account_t *account, emf_account_server_t *receiving_server_type)
+{
+ if(!account)
+ return EMF_ERROR_INVALID_PARAM;
+
+ *receiving_server_type = account->receiving_server_type;
+
+ return EMF_ERROR_NONE;
+}
+
+int email_set_receiving_server_type_to_account(emf_account_t *account, emf_account_server_t receiving_server_type)
+{
+ if(!account)
+ return EMF_ERROR_INVALID_PARAM;
+
+ account->receiving_server_type = receiving_server_type;
+
+
+ return EMF_ERROR_NONE;
+}
+
+int email_get_receiving_server_addr_from_account(emf_account_t *account, char **receiving_server_addr)
+{
+ if(!account)
+ return EMF_ERROR_INVALID_PARAM;
+
+ *receiving_server_addr = account->receiving_server_addr;
+
+ return EMF_ERROR_NONE;
+}
+
+int email_set_receiving_server_addr_to_account(emf_account_t *account, char *receiving_server_addr)
+{
+ if(!account)
+ return EMF_ERROR_INVALID_PARAM;
+
+ account->receiving_server_addr = receiving_server_addr;
+
+ return EMF_ERROR_NONE;
+}
+
+int email_get_email_addr_from_account(emf_account_t *account, char **email_addr)
+{
+ if(!account)
+ return EMF_ERROR_INVALID_PARAM;
+
+ *email_addr = account->email_addr;
+
+ return EMF_ERROR_NONE;
+}
+
+int email_set_email_addr_to_account(emf_account_t *account, char *email_addr)
+{
+ if(!account)
+ return EMF_ERROR_INVALID_PARAM;
+
+ account->email_addr = email_addr;
+
+ return EMF_ERROR_NONE;
+}
+
+int email_get_user_name_from_account(emf_account_t *account, char **user_name)
+{
+ if(!account)
+ return EMF_ERROR_INVALID_PARAM;
+
+ *user_name = account->user_name;
+
+ return EMF_ERROR_NONE;
+}
+
+int email_set_user_name_to_account(emf_account_t *account, char *user_name)
+{
+ if(!account)
+ return EMF_ERROR_INVALID_PARAM;
+
+ account->user_name = user_name;
+
+ return EMF_ERROR_NONE;
+}
+
+int email_get_password_from_account(emf_account_t *account, char **password)
+{
+ if(!account)
+ return EMF_ERROR_INVALID_PARAM;
+
+ *password = account->password;
+
+ return EMF_ERROR_NONE;
+}
+
+int email_set_password_to_account(emf_account_t *account, char *password)
+{
+ if(!account)
+ return EMF_ERROR_INVALID_PARAM;
+
+ account->password = password;
+
+ return EMF_ERROR_NONE;
+}
+
+int email_get_retrieval_mode_from_account(emf_account_t *account, emf_imap4_retrieval_mode_t *retrieval_mode)
+{
+ if(!account)
+ return EMF_ERROR_INVALID_PARAM;
+
+ *retrieval_mode = account->retrieval_mode;
+
+ return EMF_ERROR_NONE;
+}
+
+int email_set_retrieval_mode_to_account(emf_account_t *account, emf_imap4_retrieval_mode_t retrieval_mode)
+{
+ if(!account)
+ return EMF_ERROR_INVALID_PARAM;
+
+ account->retrieval_mode = retrieval_mode;
+
+ return EMF_ERROR_NONE;
+}
+
+int email_get_port_num_from_account(emf_account_t *account, int *port_num)
+{
+ if(!account)
+ return EMF_ERROR_INVALID_PARAM;
+
+ *port_num = account->port_num;
+
+ return EMF_ERROR_NONE;
+}
+
+
+int email_set_port_num_to_account(emf_account_t *account, int port_num)
+{
+ if(!account)
+ return EMF_ERROR_INVALID_PARAM;
+
+ account->port_num = port_num;
+
+ return EMF_ERROR_NONE;
+}
+
+int email_get_use_security_from_account(emf_account_t *account, int *use_security)
+{
+ if(!account)
+ return EMF_ERROR_INVALID_PARAM;
+
+ *use_security = account->use_security;
+
+ return EMF_ERROR_NONE;
+}
+
+int email_set_use_security_to_account(emf_account_t *account, int use_security)
+{
+ if(!account)
+ return EMF_ERROR_INVALID_PARAM;
+
+ account->use_security = use_security;
+
+ return EMF_ERROR_NONE;
+}
+
+int email_get_sending_server_type_from_account(emf_account_t *account, emf_account_server_t*sending_server_type)
+{
+ if(!account)
+ return EMF_ERROR_INVALID_PARAM;
+
+ *sending_server_type = account->sending_server_type;
+
+ return EMF_ERROR_NONE;
+}
+
+int email_set_sending_server_type_to_account(emf_account_t *account, emf_account_server_t sending_server_type)
+{
+ if(!account)
+ return EMF_ERROR_INVALID_PARAM;
+
+ account->sending_server_type = sending_server_type;
+
+
+ return EMF_ERROR_NONE;
+}
+
+int email_get_sending_server_addr_from_account(emf_account_t *account, char **sending_server_addr)
+{
+ if(!account)
+ return EMF_ERROR_INVALID_PARAM;
+
+ *sending_server_addr = account->sending_server_addr;
+
+ return EMF_ERROR_NONE;
+}
+
+int email_set_sending_server_addr_to_account(emf_account_t *account, char *sending_server_addr)
+{
+ if(!account)
+ return EMF_ERROR_INVALID_PARAM;
+
+ account->sending_server_addr = sending_server_addr;
+
+ return EMF_ERROR_NONE;
+}
+
+int email_get_sending_port_num_from_account(emf_account_t *account, int *sending_port_num)
+{
+ if(!account)
+ return EMF_ERROR_INVALID_PARAM;
+
+ *sending_port_num = account->sending_port_num;
+
+ return EMF_ERROR_NONE;
+}
+
+int email_set_sending_port_num_to_account(emf_account_t *account, int sending_port_num)
+{
+ if(!account)
+ return EMF_ERROR_INVALID_PARAM;
+
+ account->sending_port_num = sending_port_num;
+
+ return EMF_ERROR_NONE;
+}
+
+int email_get_sending_auth_from_account(emf_account_t *account, int *sending_auth)
+{
+ if(!account)
+ return EMF_ERROR_INVALID_PARAM;
+
+ *sending_auth = account->sending_auth;
+
+ return EMF_ERROR_NONE;
+}
+
+int email_set_sending_auth_to_account(emf_account_t *account, int sending_auth)
+{
+ if(!account)
+ return EMF_ERROR_INVALID_PARAM;
+
+ account->sending_auth = sending_auth;
+
+ return EMF_ERROR_NONE;
+}
+
+int email_get_sending_security_from_account(emf_account_t *account, int *sending_security)
+{
+ if(!account)
+ return EMF_ERROR_INVALID_PARAM;
+
+ *sending_security = account->sending_security;
+
+ return EMF_ERROR_NONE;
+}
+
+int email_set_sending_security_to_account(emf_account_t *account, int sending_security)
+{
+ if(!account)
+ return EMF_ERROR_INVALID_PARAM;
+
+ account->sending_security = sending_security;
+
+ return EMF_ERROR_NONE;
+}
+
+int email_get_sending_user_from_account(emf_account_t *account, char **sending_user)
+{
+ if(!account)
+ return EMF_ERROR_INVALID_PARAM;
+
+ *sending_user = account->sending_user;
+
+ return EMF_ERROR_NONE;
+}
+
+int email_set_sending_user_to_account(emf_account_t *account, char *sending_user)
+{
+ if(!account)
+ return EMF_ERROR_INVALID_PARAM;
+
+ account->sending_user = sending_user;
+
+ return EMF_ERROR_NONE;
+}
+
+int email_get_sending_password_from_account(emf_account_t *account, char **sending_password)
+{
+ if(!account)
+ return EMF_ERROR_INVALID_PARAM;
+
+ *sending_password = account->sending_password;
+
+ return EMF_ERROR_NONE;
+}
+
+int email_set_sending_password_to_account(emf_account_t *account, char *sending_password)
+{
+ if(!account)
+ return EMF_ERROR_INVALID_PARAM;
+
+ account->sending_password = sending_password;
+
+ return EMF_ERROR_NONE;
+}
+
+int email_get_display_name_from_account(emf_account_t *account, char **display_name)
+{
+ if(!account)
+ return EMF_ERROR_INVALID_PARAM;
+
+ *display_name = account->display_name;
+
+ return EMF_ERROR_NONE;
+}
+
+int email_set_display_name_to_account(emf_account_t *account, char *display_name)
+{
+ if(!account)
+ return EMF_ERROR_INVALID_PARAM;
+
+ account->display_name = display_name;
+
+ return EMF_ERROR_NONE;
+}
+
+int email_get_reply_to_addr_from_account(emf_account_t *account, char **reply_to_addr)
+{
+ if(!account)
+ return EMF_ERROR_INVALID_PARAM;
+
+ *reply_to_addr = account->reply_to_addr;
+
+ return EMF_ERROR_NONE;
+}
+
+int email_set_reply_to_addr_to_account(emf_account_t *account, char *reply_to_addr)
+{
+ if(!account)
+ return EMF_ERROR_INVALID_PARAM;
+
+ account->reply_to_addr = reply_to_addr;
+
+ return EMF_ERROR_NONE;
+}
+
+int email_get_return_addr_from_account(emf_account_t *account, char **return_addr)
+{
+ if(!account)
+ return EMF_ERROR_INVALID_PARAM;
+
+ *return_addr = account->return_addr;
+
+ return EMF_ERROR_NONE;
+}
+
+
+int email_set_return_addr_to_account(emf_account_t *account, char *return_addr)
+{
+ if(!account)
+ return EMF_ERROR_INVALID_PARAM;
+
+ account->return_addr = return_addr;
+
+ return EMF_ERROR_NONE;
+}
+
+int email_get_account_id_from_account(emf_account_t *account, int *account_id)
+{
+ if(!account)
+ return EMF_ERROR_INVALID_PARAM;
+
+ *account_id = account->account_id;
+
+ return EMF_ERROR_NONE;
+}
+
+int email_set_account_id_to_account(emf_account_t *account, int account_id)
+{
+ if(!account)
+ return EMF_ERROR_INVALID_PARAM;
+
+ account->account_id = account_id;
+
+ return EMF_ERROR_NONE;
+}
+
+int email_get_keep_on_server_from_account(emf_account_t *account, int *keep_on_server)
+{
+ if(!account)
+ return EMF_ERROR_INVALID_PARAM;
+
+ *keep_on_server = account->keep_on_server;
+
+ return EMF_ERROR_NONE;
+}
+
+int email_set_keep_on_server_to_account(emf_account_t *account, int keep_on_server)
+{
+ if(!account)
+ return EMF_ERROR_INVALID_PARAM;
+
+ account->keep_on_server = keep_on_server;
+
+ return EMF_ERROR_NONE;
+}
+
+int email_get_flag1_from_account(emf_account_t *account, int *flag1)
+{
+ if(!account)
+ return EMF_ERROR_INVALID_PARAM;
+
+ *flag1 = account->flag1;
+
+ return EMF_ERROR_NONE;
+}
+
+
+int email_set_flag1_to_account(emf_account_t *account, int flag1)
+{
+ if(!account)
+ return EMF_ERROR_INVALID_PARAM;
+
+ account->flag1 = flag1;
+
+ return EMF_ERROR_NONE;
+}
+
+int email_get_flag2_from_account(emf_account_t *account, int *flag2)
+{
+ if(!account)
+ return EMF_ERROR_INVALID_PARAM;
+
+ *flag2 = account->flag2;
+
+ return EMF_ERROR_NONE;
+}
+
+
+int email_set_flag2_to_account(emf_account_t *account, int flag2)
+{
+ if(!account)
+ return EMF_ERROR_INVALID_PARAM;
+
+ account->flag2 = flag2;
+
+
+ return EMF_ERROR_NONE;
+}
+
+int email_get_pop_before_smtp_from_account(emf_account_t *account, int *pop_before_smtp)
+{
+ if(!account)
+ return EMF_ERROR_INVALID_PARAM;
+
+ *pop_before_smtp = account->pop_before_smtp;
+
+ return EMF_ERROR_NONE;
+}
+
+
+int email_set_pop_before_smtp_to_account(emf_account_t *account, int pop_before_smtp)
+{
+ if(!account)
+ return EMF_ERROR_INVALID_PARAM;
+
+ account->pop_before_smtp = pop_before_smtp;
+
+ return EMF_ERROR_NONE;
+}
+
+int email_get_apop_from_account(emf_account_t *account, int *apop)
+{
+ if(!account)
+ return EMF_ERROR_INVALID_PARAM;
+
+ *apop = account->apop;
+
+ return EMF_ERROR_NONE;
+}
+
+int email_set_apop_to_account(emf_account_t *account, int apop)
+{
+ if(!account)
+ return EMF_ERROR_INVALID_PARAM;
+
+ account->apop = apop;
+
+ return EMF_ERROR_NONE;
+}
+
+int email_get_logo_icon_path_from_account(emf_account_t *account, char **logo_icon_path)
+{
+ if(!account)
+ return EMF_ERROR_INVALID_PARAM;
+
+ *logo_icon_path = account->logo_icon_path;
+
+ return EMF_ERROR_NONE;
+}
+
+
+int email_set_logo_icon_path_to_account(emf_account_t *account, char *logo_icon_path)
+{
+ if(!account)
+ return EMF_ERROR_INVALID_PARAM;
+
+ account->logo_icon_path = logo_icon_path;
+
+ return EMF_ERROR_NONE;
+}
+
+int email_get_preset_account_from_account(emf_account_t *account, int *preset_account)
+{
+ if(!account)
+ return EMF_ERROR_INVALID_PARAM;
+
+ *preset_account = account->preset_account;
+
+ return EMF_ERROR_NONE;
+}
+
+int email_set_preset_account_to_account(emf_account_t *account, int preset_account)
+{
+ if(!account)
+ return EMF_ERROR_INVALID_PARAM;
+
+ account->preset_account = preset_account;
+
+ return EMF_ERROR_NONE;
+}
+
+int email_get_options_from_account(emf_account_t *account, emf_option_t **options)
+{
+ if(!account)
+ return EMF_ERROR_INVALID_PARAM;
+
+ *options = &account->options;
+
+ return EMF_ERROR_NONE;
+}
+
+int email_set_options_to_account(emf_account_t *account, emf_option_t *options)
+{
+ if(!account)
+ return EMF_ERROR_INVALID_PARAM;
+
+ account->options = *options;
+
+ return EMF_ERROR_NONE;
+}
+
+int email_get_target_storage_from_account(emf_account_t *account, int *target_storage)
+{
+ if(!account)
+ return EMF_ERROR_INVALID_PARAM;
+
+ *target_storage = account->target_storage;
+
+ return EMF_ERROR_NONE;
+}
+
+int email_set_target_storage_to_account(emf_account_t *account, int target_storage)
+{
+ if(!account)
+ return EMF_ERROR_INVALID_PARAM;
+
+ account->target_storage = target_storage;
+
+ return EMF_ERROR_NONE;
+}
+
+int email_get_check_interval_from_account(emf_account_t *account, int *check_interval)
+{
+ if(!account)
+ return EMF_ERROR_INVALID_PARAM;
+
+ *check_interval = account->check_interval;
+
+ return EMF_ERROR_NONE;
+}
+
+int email_set_check_interval_to_account(emf_account_t *account, int check_interval)
+{
+ if(!account)
+ return EMF_ERROR_INVALID_PARAM;
+
+ account->check_interval = check_interval;
+
+ return EMF_ERROR_NONE;
+}
+
+/* emf_mailbox_t--------------------------------------------------------------- */
+
+int email_get_name_from_mailbox(emf_mailbox_t *mailbox, char **name)
+{
+ if(!mailbox)
+ return EMF_ERROR_INVALID_PARAM;
+
+ *name = mailbox->name;
+
+ return EMF_ERROR_NONE;
+}
+
+int email_set_name_to_mailbox(emf_mailbox_t *mailbox, char *name)
+{
+ if(!mailbox)
+ return EMF_ERROR_INVALID_PARAM;
+
+ mailbox->name = name;
+
+ return EMF_ERROR_NONE;
+}
+
+int email_get_mailbox_type_from_mailbox(emf_mailbox_t *mailbox, emf_mailbox_type_e mailbox_type)
+{
+ if(!mailbox)
+ return EMF_ERROR_INVALID_PARAM;
+
+ mailbox_type = mailbox->mailbox_type;
+
+ return EMF_ERROR_NONE;
+}
+
+int email_set_mailbox_type_to_mailbox(emf_mailbox_t *mailbox, emf_mailbox_type_e mailbox_type)
+{
+ if(!mailbox)
+ return EMF_ERROR_INVALID_PARAM;
+
+ mailbox->mailbox_type = mailbox_type;
+
+ return EMF_ERROR_NONE;
+}
+
+int email_get_alias_from_mailbox(emf_mailbox_t *mailbox, char **alias)
+{
+ if(!mailbox)
+ return EMF_ERROR_INVALID_PARAM;
+
+ *alias = mailbox->alias;
+
+ return EMF_ERROR_NONE;
+}
+
+int email_set_alias_to_mailbox(emf_mailbox_t *mailbox, char *alias)
+{
+ if(!mailbox)
+ return EMF_ERROR_INVALID_PARAM;
+
+ mailbox->alias = alias;
+
+ return EMF_ERROR_NONE;
+}
+
+int email_get_unread_count_from_mailbox(emf_mailbox_t *mailbox, int *unread_count)
+{
+ if(!mailbox)
+ return EMF_ERROR_INVALID_PARAM;
+
+ *unread_count = mailbox->unread_count;
+
+ return EMF_ERROR_NONE;
+}
+
+int email_set_unread_count_to_mailbox(emf_mailbox_t *mailbox, int unread_count)
+{
+ if(!mailbox)
+ return EMF_ERROR_INVALID_PARAM;
+
+ mailbox->unread_count = unread_count;
+
+ return EMF_ERROR_NONE;
+}
+
+int email_get_hold_connection_from_mailbox(emf_mailbox_t *mailbox, int *hold_connection)
+{
+ if(!mailbox)
+ return EMF_ERROR_INVALID_PARAM;
+
+ *hold_connection = mailbox->hold_connection;
+
+ return EMF_ERROR_NONE;
+}
+
+int email_set_hold_connection_to_mailbox(emf_mailbox_t *mailbox, int hold_connection)
+{
+ if(!mailbox)
+ return EMF_ERROR_INVALID_PARAM;
+
+ mailbox->hold_connection = hold_connection;
+
+ return EMF_ERROR_NONE;
+}
+
+int email_get_local_from_mailbox(emf_mailbox_t *mailbox, int *local)
+{
+ if(!mailbox)
+ return EMF_ERROR_INVALID_PARAM;
+
+ *local = mailbox->local;
+
+ return EMF_ERROR_NONE;
+}
+
+int email_set_local_to_mailbox(emf_mailbox_t *mailbox, int local)
+{
+ if(!mailbox)
+ return EMF_ERROR_INVALID_PARAM;
+
+ mailbox->local = local;
+
+ return EMF_ERROR_NONE;
+}
+
+int email_get_synchronous_from_mailbox(emf_mailbox_t *mailbox, int *synchronous)
+{
+ if(!mailbox)
+ return EMF_ERROR_INVALID_PARAM;
+
+ *synchronous = mailbox->synchronous;
+
+ return EMF_ERROR_NONE;
+}
+
+int email_set_synchronous_to_mailbox(emf_mailbox_t *mailbox, int synchronous)
+{
+ if(!mailbox)
+ return EMF_ERROR_INVALID_PARAM;
+
+ mailbox->synchronous = synchronous;
+
+ return EMF_ERROR_NONE;
+}
+
+int email_get_account_id_from_mailbox(emf_mailbox_t *mailbox, int *account_id)
+{
+ if(!mailbox)
+ return EMF_ERROR_INVALID_PARAM;
+
+ *account_id = mailbox->account_id;
+
+ return EMF_ERROR_NONE;
+}
+
+int email_set_account_id_to_mailbox(emf_mailbox_t *mailbox, int account_id)
+{
+ if(!mailbox)
+ return EMF_ERROR_INVALID_PARAM;
+
+ mailbox->account_id = account_id;
+
+ return EMF_ERROR_NONE;
+}
+
+int email_get_user_data_from_mailbox(emf_mailbox_t *mailbox, void **user_data)
+{
+ if(!mailbox)
+ return EMF_ERROR_INVALID_PARAM;
+
+ *user_data = mailbox->user_data;
+
+ return EMF_ERROR_NONE;
+}
+
+int email_set_user_data_to_mailbox(emf_mailbox_t *mailbox, void *user_data)
+{
+ if(!mailbox)
+ return EMF_ERROR_INVALID_PARAM;
+
+ mailbox->user_data = user_data;
+
+ return EMF_ERROR_NONE;
+}
+
+int email_get_mail_stream_from_mailbox(emf_mailbox_t *mailbox, void **mail_stream)
+{
+ if(!mailbox)
+ return EMF_ERROR_INVALID_PARAM;
+
+ *mail_stream = mailbox->mail_stream;
+
+ return EMF_ERROR_NONE;
+}
+
+int email_set_mail_stream_to_mailbox(emf_mailbox_t *mailbox, void *mail_stream)
+{
+ if(!mailbox)
+ return EMF_ERROR_INVALID_PARAM;
+
+ mailbox->mail_stream = mail_stream;
+
+ return EMF_ERROR_NONE;
+}
+
+int email_get_has_archived_mails_from_mailbox(emf_mailbox_t *mailbox, int *has_archived_mails)
+{
+ if(!mailbox)
+ return EMF_ERROR_INVALID_PARAM;
+
+ *has_archived_mails = mailbox->has_archived_mails;
+
+ return EMF_ERROR_NONE;
+}
+
+int email_set_has_archived_mails_to_mailbox(emf_mailbox_t *mailbox, int has_archived_mails)
+{
+ if(!mailbox)
+ return EMF_ERROR_INVALID_PARAM;
+
+ mailbox->has_archived_mails = has_archived_mails;
+
+ return EMF_ERROR_NONE;
+}
+
+int email_get_account_name_from_mailbox(emf_mailbox_t *mailbox, char **account_name)
+{
+ if(!mailbox)
+ return EMF_ERROR_INVALID_PARAM;
+
+ *account_name = mailbox->account_name;
+
+ return EMF_ERROR_NONE;
+}
+
+int email_set_account_name_to_mailbox(emf_mailbox_t *mailbox, char *account_name)
+{
+ if(!mailbox)
+ return EMF_ERROR_INVALID_PARAM;
+
+ mailbox->account_name= account_name;
+
+ return EMF_ERROR_NONE;
+}
+
+int email_get_next_from_mailbox(emf_mailbox_t *mailbox, emf_mailbox_t **next)
+{
+ if(!mailbox)
+ return EMF_ERROR_INVALID_PARAM;
+
+ *next = mailbox->next;
+
+ return EMF_ERROR_NONE;
+}
+
+int email_set_next_to_mailbox(emf_mailbox_t *mailbox, emf_mailbox_t *next)
+{
+ if(!mailbox)
+ return EMF_ERROR_INVALID_PARAM;
+
+ mailbox->next= next;
+
+ return EMF_ERROR_NONE;
+}
+
+
+/* emf_attachment_info_t------------------------------------------------------- */
+
+int email_get_inline_content_from_attachment_info(emf_attachment_info_t *attachment_info, int *inline_content)
+{
+ if(!attachment_info)
+ return EMF_ERROR_INVALID_PARAM;
+
+ *inline_content = attachment_info->inline_content;
+
+ return EMF_ERROR_NONE;
+}
+
+int email_set_inline_content_to_attachment_info(emf_attachment_info_t *attachment_info, int inline_content)
+{
+ if(!attachment_info)
+ return EMF_ERROR_INVALID_PARAM;
+
+ attachment_info->inline_content= inline_content;
+
+ return EMF_ERROR_NONE;
+}
+
+int email_get_attachment_id_from_attachment_info(emf_attachment_info_t *attachment_info, int *attachment_id)
+{
+ if(!attachment_info)
+ return EMF_ERROR_INVALID_PARAM;
+
+ *attachment_id = attachment_info->attachment_id;
+
+ return EMF_ERROR_NONE;
+}
+
+int email_set_attachment_id_to_attachment_info(emf_attachment_info_t *attachment_info, int attachment_id)
+{
+ if(!attachment_info)
+ return EMF_ERROR_INVALID_PARAM;
+
+ attachment_info->attachment_id= attachment_id;
+
+ return EMF_ERROR_NONE;
+}
+
+int email_get_name_from_attachment_info(emf_attachment_info_t *attachment_info, char **name)
+{
+ if(!attachment_info)
+ return EMF_ERROR_INVALID_PARAM;
+
+ *name = attachment_info->name;
+
+ return EMF_ERROR_NONE;
+}
+
+int email_set_name_to_attachment_info(emf_attachment_info_t *attachment_info, char *name)
+{
+ if(!attachment_info)
+ return EMF_ERROR_INVALID_PARAM;
+
+ attachment_info->name= name;
+
+ return EMF_ERROR_NONE;
+}
+
+int email_get_size_from_attachment_info(emf_attachment_info_t *attachment_info, int *size)
+{
+ if(!attachment_info)
+ return EMF_ERROR_INVALID_PARAM;
+
+ *size = attachment_info->size;
+
+ return EMF_ERROR_NONE;
+}
+
+int email_set_size_to_attachment_info(emf_attachment_info_t *attachment_info, int size)
+{
+ if(!attachment_info)
+ return EMF_ERROR_INVALID_PARAM;
+
+ attachment_info->size= size;
+
+ return EMF_ERROR_NONE;
+}
+
+int email_get_downloaded_from_attachment_info(emf_attachment_info_t *attachment_info, int *downloaded)
+{
+ if(!attachment_info)
+ return EMF_ERROR_INVALID_PARAM;
+
+ *downloaded = attachment_info->downloaded;
+
+ return EMF_ERROR_NONE;
+}
+
+int email_set_downloaded_to_attachment_info(emf_attachment_info_t *attachment_info, int downloaded)
+{
+ if(!attachment_info)
+ return EMF_ERROR_INVALID_PARAM;
+
+ attachment_info->downloaded= downloaded;
+
+ return EMF_ERROR_NONE;
+}
+
+int email_get_savename_from_attachment_info(emf_attachment_info_t *attachment_info, char **savename)
+{
+ if(!attachment_info)
+ return EMF_ERROR_INVALID_PARAM;
+
+ *savename = attachment_info->savename;
+
+ return EMF_ERROR_NONE;
+}
+
+int email_set_savename_to_attachment_info(emf_attachment_info_t *attachment_info, char *savename)
+{
+ if(!attachment_info)
+ return EMF_ERROR_INVALID_PARAM;
+
+ attachment_info->savename= savename;
+
+ return EMF_ERROR_NONE;
+}
+
+int email_get_drm_from_attachment_info(emf_attachment_info_t *attachment_info, int *drm)
+{
+ if(!attachment_info)
+ return EMF_ERROR_INVALID_PARAM;
+
+ *drm = attachment_info->drm;
+
+ return EMF_ERROR_NONE;
+}
+
+int email_set_drm_to_attachment_info(emf_attachment_info_t *attachment_info, int drm)
+{
+ if(!attachment_info)
+ return EMF_ERROR_INVALID_PARAM;
+
+ attachment_info->drm= drm;
+
+ return EMF_ERROR_NONE;
+}
+
+int email_get_next_from_attachment_info(emf_attachment_info_t *attachment_info, emf_attachment_info_t **next)
+{
+ if(!attachment_info)
+ return EMF_ERROR_INVALID_PARAM;
+
+ *next = attachment_info->next;
+
+ return EMF_ERROR_NONE;
+}
+
+int email_set_next_to_attachment_info(emf_attachment_info_t *attachment_info, emf_attachment_info_t *next)
+{
+ if(!attachment_info)
+ return EMF_ERROR_INVALID_PARAM;
+
+ attachment_info->next= next;
+
+ return EMF_ERROR_NONE;
+}
+
+/* emf_option_t---------------------------------------------------------------- */
+
+int email_get_priority_from_option(emf_option_t *option, int *priority)
+{
+ if(!option)
+ return EMF_ERROR_INVALID_PARAM;
+
+ *priority = option->priority;
+
+ return EMF_ERROR_NONE;
+}
+
+int email_set_priority_to_option(emf_option_t *option, int priority)
+{
+ if(!option)
+ return EMF_ERROR_INVALID_PARAM;
+
+ option->priority= priority;
+
+ return EMF_ERROR_NONE;
+}
+
+int email_get_keep_local_copy_from_option(emf_option_t *option, int *keep_local_copy)
+{
+ if(!option)
+ return EMF_ERROR_INVALID_PARAM;
+
+ *keep_local_copy = option->keep_local_copy;
+
+
+ return EMF_ERROR_NONE;
+}
+
+int email_set_keep_local_copy_to_option(emf_option_t *option, int keep_local_copy)
+{
+ if(!option)
+ return EMF_ERROR_INVALID_PARAM;
+
+ option->keep_local_copy= keep_local_copy;
+
+ return EMF_ERROR_NONE;
+}
+
+int email_get_req_delivery_receipt_from_option(emf_option_t *option, int *req_delivery_receipt)
+{
+ if(!option)
+ return EMF_ERROR_INVALID_PARAM;
+
+ *req_delivery_receipt = option->req_delivery_receipt;
+
+ return EMF_ERROR_NONE;
+}
+
+int email_set_req_delivery_receipt_to_option(emf_option_t *option, int req_delivery_receipt)
+{
+ if(!option)
+ return EMF_ERROR_INVALID_PARAM;
+
+ option->req_delivery_receipt= req_delivery_receipt;
+
+ return EMF_ERROR_NONE;
+}
+
+int email_get_req_read_receipt_from_option(emf_option_t *option, int *req_read_receipt)
+{
+ if(!option)
+ return EMF_ERROR_INVALID_PARAM;
+
+ *req_read_receipt = option->req_read_receipt;
+
+ return EMF_ERROR_NONE;
+}
+
+int email_set_req_read_receipt_to_option(emf_option_t *option, int req_read_receipt)
+{
+ if(!option)
+ return EMF_ERROR_INVALID_PARAM;
+
+ option->req_read_receipt = req_read_receipt;
+
+ return EMF_ERROR_NONE;
+}
+
+int email_get_download_limit_from_option(emf_option_t *option, int *download_limit)
+{
+ if(!option)
+ return EMF_ERROR_INVALID_PARAM;
+
+ *download_limit = option->download_limit;
+
+ return EMF_ERROR_NONE;
+}
+
+int email_set_download_limit_to_option(emf_option_t *option, int download_limit)
+{
+ if(!option)
+ return EMF_ERROR_INVALID_PARAM;
+
+ option->download_limit = download_limit;
+
+
+ return EMF_ERROR_NONE;
+}
+
+int email_get_block_address_from_option(emf_option_t *option, int *block_address)
+{
+ if(!option)
+ return EMF_ERROR_INVALID_PARAM;
+
+ *block_address = option->block_address;
+
+ return EMF_ERROR_NONE;
+}
+
+int email_set_block_address_to_option(emf_option_t *option, int block_address)
+{
+ if(!option)
+ return EMF_ERROR_INVALID_PARAM;
+
+ option->block_address = block_address;
+
+ return EMF_ERROR_NONE;
+}
+
+int email_get_block_subject_from_option(emf_option_t *option, int *block_subject)
+{
+ if(!option)
+ return EMF_ERROR_INVALID_PARAM;
+
+ *block_subject = option->block_subject;
+
+ return EMF_ERROR_NONE;
+}
+
+int email_set_block_subject_to_option(emf_option_t *option, int block_subject)
+{
+ if(!option)
+ return EMF_ERROR_INVALID_PARAM;
+
+ option->block_subject = block_subject;
+
+ return EMF_ERROR_NONE;
+}
+
+int email_get_display_name_from_from_option(emf_option_t *option, char **display_name_from)
+{
+ if(!option)
+ return EMF_ERROR_INVALID_PARAM;
+
+ *display_name_from = option->display_name_from;
+
+ return EMF_ERROR_NONE;
+}
+
+int email_set_display_name_from_to_option(emf_option_t *option, char *display_name_from)
+{
+ if(!option)
+ return EMF_ERROR_INVALID_PARAM;
+
+ option->display_name_from = display_name_from;
+
+ return EMF_ERROR_NONE;
+}
+
+int email_get_reply_with_body_from_option(emf_option_t *option, int *reply_with_body)
+{
+ if(!option)
+ return EMF_ERROR_INVALID_PARAM;
+
+ *reply_with_body = option->reply_with_body;
+
+ return EMF_ERROR_NONE;
+}
+
+int email_set_reply_with_body_to_option(emf_option_t *option, int reply_with_body)
+{
+ if(!option)
+ return EMF_ERROR_INVALID_PARAM;
+
+ option->reply_with_body = reply_with_body;
+
+ return EMF_ERROR_NONE;
+}
+
+int email_get_forward_with_files_from_option(emf_option_t *option, int *forward_with_files)
+{
+ if(!option)
+ return EMF_ERROR_INVALID_PARAM;
+
+ *forward_with_files = option->forward_with_files;
+
+ return EMF_ERROR_NONE;
+}
+
+int email_set_forward_with_files_to_option(emf_option_t *option, int forward_with_files)
+{
+ if(!option)
+ return EMF_ERROR_INVALID_PARAM;
+
+ option->forward_with_files = forward_with_files;
+
+ return EMF_ERROR_NONE;
+}
+
+int email_get_add_myname_card_from_option(emf_option_t *option, int *add_myname_card)
+{
+ if(!option)
+ return EMF_ERROR_INVALID_PARAM;
+
+ *add_myname_card = option->add_myname_card;
+
+ return EMF_ERROR_NONE;
+}
+
+int email_set_add_myname_card_to_option(emf_option_t *option, int add_myname_card)
+{
+ if(!option)
+ return EMF_ERROR_INVALID_PARAM;
+
+ option->add_myname_card = add_myname_card;
+
+ return EMF_ERROR_NONE;
+}
+
+int email_get_add_signature_from_option(emf_option_t *option, int *add_signature)
+{
+ if(!option)
+ return EMF_ERROR_INVALID_PARAM;
+
+ *add_signature = option->add_signature;
+
+ return EMF_ERROR_NONE;
+}
+
+int email_set_add_signature_to_option(emf_option_t *option, int add_signature)
+{
+ if(!option)
+ return EMF_ERROR_INVALID_PARAM;
+
+ option->add_signature = add_signature;
+
+ return EMF_ERROR_NONE;
+}
+
+int email_get_signature_from_option(emf_option_t *option, char **signature)
+{
+ if(!option)
+ return EMF_ERROR_INVALID_PARAM;
+
+ *signature = option->signature;
+
+ return EMF_ERROR_NONE;
+}
+
+int email_set_signature_to_option(emf_option_t *option, char *signature)
+{
+ if(!option)
+ return EMF_ERROR_INVALID_PARAM;
+
+ option->signature = signature;
+
+ return EMF_ERROR_NONE;
+}
+
+/* emf_rule_t------------------------------------------------------------------- */
+int email_get_account_id_from_rule(emf_rule_t *rule, int *account_id)
+{
+ if(!rule)
+ return EMF_ERROR_INVALID_PARAM;
+
+ *account_id = rule->account_id;
+
+ return EMF_ERROR_NONE;
+}
+
+int email_set_account_id_to_rule(emf_rule_t *rule, int account_id)
+{
+ if(!rule)
+ return EMF_ERROR_INVALID_PARAM;
+
+ rule->account_id = account_id;
+
+ return EMF_ERROR_NONE;
+}
+
+int email_get_filter_id_from_rule(emf_rule_t *rule, int *filter_id)
+{
+ if(!rule)
+ return EMF_ERROR_INVALID_PARAM;
+
+ *filter_id = rule->filter_id;
+
+ return EMF_ERROR_NONE;
+}
+
+int email_set_filter_id_to_rule(emf_rule_t *rule, int filter_id)
+{
+ if(!rule)
+ return EMF_ERROR_INVALID_PARAM;
+
+ rule->filter_id = filter_id;
+
+ return EMF_ERROR_NONE;
+}
+
+int email_get_type_from_rule(emf_rule_t *rule, emf_rule_type_t type)
+{
+ if(!rule)
+ return EMF_ERROR_INVALID_PARAM;
+
+ type = rule->type;
+
+ return EMF_ERROR_NONE;
+}
+
+int email_set_type_to_rule(emf_rule_t *rule, emf_rule_type_t type)
+{
+ if(!rule)
+ return EMF_ERROR_INVALID_PARAM;
+
+ rule->type = type;
+
+ return EMF_ERROR_NONE;
+}
+
+int email_get_value_from_rule(emf_rule_t *rule, char **value)
+{
+ if(!rule)
+ return EMF_ERROR_INVALID_PARAM;
+
+ *value = rule->value;
+
+ return EMF_ERROR_NONE;
+}
+
+int email_set_value_to_rule(emf_rule_t *rule, char *value)
+{
+ if(!rule)
+ return EMF_ERROR_INVALID_PARAM;
+
+ rule->value = value;
+
+ return EMF_ERROR_NONE;
+}
+
+int email_get_action_from_rule(emf_rule_t *rule, emf_rule_action_t action)
+{
+ if(!rule)
+ return EMF_ERROR_INVALID_PARAM;
+
+ action = rule->faction;
+
+ return EMF_ERROR_NONE;
+}
+
+int email_set_action_to_rule(emf_rule_t *rule, emf_rule_action_t action)
+{
+ if(!rule)
+ return EMF_ERROR_INVALID_PARAM;
+
+ rule->faction = action;
+
+ return EMF_ERROR_NONE;
+}
+
+int email_get_flag1_from_rule(emf_rule_t *rule, int *flag1)
+{
+ if(!rule)
+ return EMF_ERROR_INVALID_PARAM;
+
+ *flag1 = rule->flag1;
+
+ return EMF_ERROR_NONE;
+}
+
+int email_set_flag1_to_rule(emf_rule_t *rule, int flag1)
+{
+ if(!rule)
+ return EMF_ERROR_INVALID_PARAM;
+
+ rule->flag1 = flag1;
+
+ return EMF_ERROR_NONE;
+}
+
+int email_get_flag2_from_rule(emf_rule_t *rule, int *flag2)
+{
+ if(!rule)
+ return EMF_ERROR_INVALID_PARAM;
+
+ *flag2 = rule->flag2;
+
+ return EMF_ERROR_NONE;
+}
+
+int email_set_flag2_to_rule(emf_rule_t *rule, int flag2)
+{
+ if(!rule)
+ return EMF_ERROR_INVALID_PARAM;
+
+ rule->flag2 = flag2;
+
+ return EMF_ERROR_NONE;
+}
+
+
+
diff --git a/MAPI/include/Emf_Mapi.h b/MAPI/include/Emf_Mapi.h
new file mode 100755
index 0000000..414678b
--- /dev/null
+++ b/MAPI/include/Emf_Mapi.h
@@ -0,0 +1,155 @@
+/*
+* email-service
+*
+* Copyright (c) 2000 - 2011 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.
+*
+*/
+
+
+#ifndef __EMF_MAPI_H__
+#define __EMF_MAPI_H__
+
+#include <stdio.h>
+#include <stdlib.h>
+#include "Emf_Mapi_Account.h"
+#include "Emf_Mapi_Message.h"
+#include "Emf_Mapi_Rule.h"
+#include "Emf_Mapi_Mailbox.h"
+#include "Emf_Mapi_Network.h"
+#include "Emf_Mapi_Init.h"
+
+/**
+* @defgroup EMAIL_FRAMEWORK Email Service
+* @{
+*/
+
+/**
+* @{
+*/
+
+/**
+ *
+ * This file contains the data structures and interfaces needed for application,
+ * to interact with Email Engine.
+ * @file Emf_Mapi.h
+ * @author Kyuho Jo <kyuho.jo@samsung.com>
+ * @author Sunghyun Kwon <sh0701.kwon@samsung.com>
+ * @version 0.1
+ * @brief This file contains the data structures and interfaces provided by
+ * Email Engine.
+ */
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+
+
+enum {
+ //Account
+ _EMAIL_API_ADD_ACCOUNT = 0x01000000,
+ _EMAIL_API_DELETE_ACCOUNT = 0x01000001,
+ _EMAIL_API_UPDATE_ACCOUNT = 0x01000002,
+ _EMAIL_API_GET_ACCOUNT = 0x01000003,
+ _EMAIL_API_GET_ACCOUNT_LIST = 0x01000005,
+ _EMAIL_API_GET_MAILBOX_COUNT = 0x01000007,
+ _EMAIL_API_VALIDATE_ACCOUNT = 0x01000008,
+ _EMAIL_API_ADD_ACCOUNT_WITH_VALIDATION = 0x01000009,
+ _EMAIL_API_BACKUP_ACCOUNTS = 0x0100000A,
+ _EMAIL_API_RESTORE_ACCOUNTS = 0x0100000B,
+ _EMAIL_API_GET_PASSWORD_LENGTH_OF_ACCOUNT = 0x0100000C,
+
+ //Message
+ _EMAIL_API_ADD_MAIL_OLD = 0x01100000, /* Deprecated */
+ _EMAIL_API_GET_MAIL = 0x01100001,
+ _EMAIL_API_DELETE_MAIL = 0x01100002,
+ _EMAIL_API_UPDATE_MAIL_OLD = 0x01100003, /* Deprecated */
+ _EMAIL_API_DELETE_ALL_MAIL = 0x01100004,
+ _EMAIL_API_GET_MAILBOX_LIST = 0x01100006,
+ _EMAIL_API_GET_SUBMAILBOX_LIST = 0x01100007,
+ _EMAIL_API_CLEAR_DATA = 0x01100009,
+ _EMAIL_API_MOVE_MAIL = 0x0110000A,
+ _EMAIL_API_MOVE_ALL_MAIL = 0x0110000B,
+ _EMAIL_API_ADD_ATTACHMENT = 0x0110000C,
+ _EMAIL_API_GET_ATTACHMENT = 0x0110000D,
+ _EMAIL_API_DELETE_ATTACHMENT = 0x0110000E,
+ _EMAIL_API_MODIFY_MAIL_FLAG = 0x0110000F,
+ _EMAIL_API_MODIFY_SEEN_MAIL_FLAG = 0x01100010, /* Deprecated */
+ _EMAIL_API_MODIFY_MAIL_EXTRA_FLAG = 0x01100011,
+ _EMAIL_API_GET_INFO = 0x01100012,
+ _EMAIL_API_GET_HEADER_INFO = 0x01100013,
+ _EMAIL_API_GET_BODY_INFO = 0x01100014,
+ _EMAIL_API_SET_FLAGS_FIELD = 0x01100016,
+ _EMAIL_API_ADD_MAIL = 0x01100017,
+ _EMAIL_API_UPDATE_MAIL = 0x01100018,
+
+ // Thread
+ _EMAIL_API_MOVE_THREAD_TO_MAILBOX = 0x01110000,
+ _EMAIL_API_DELETE_THREAD = 0x01110001,
+ _EMAIL_API_MODIFY_SEEN_FLAG_OF_THREAD = 0x01110002,
+
+ //mailbox
+ _EMAIL_API_ADD_MAILBOX = 0x01200000,
+ _EMAIL_API_DELETE_MAILBOX = 0x01200001,
+ _EMAIL_API_UPDATE_MAILBOX = 0x01200002,
+ _EMAIL_API_SET_MAIL_SLOT_SIZE = 0x01200007,
+
+ //Network
+ _EMAIL_API_SEND_MAIL = 0x01300000,
+ _EMAIL_API_SYNC_HEADER = 0x01300001,
+ _EMAIL_API_DOWNLOAD_BODY = 0x01300002,
+ _EMAIL_API_DOWNLOAD_ATTACHMENT = 0x01300003,
+ _EMAIL_API_NETWORK_GET_STATUS = 0x01300004,
+ _EMAIL_API_MAIL_SEND_SAVED = 0x01300005,
+ _EMAIL_API_MAIL_SEND_REPORT = 0x01300006,
+ _EMAIL_API_DELETE_EMAIL = 0x01300007,
+ _EMAIL_API_DELETE_EMAIL_ALL = 0x01300008,
+ _EMAIL_API_GET_IMAP_MAILBOX_LIST = 0x01300015,
+ _EMAIL_API_SEND_MAIL_CANCEL_JOB = 0x01300017,
+ _EMAIL_API_FIND_MAIL_ON_SERVER = 0x01300019,
+
+ //Rule
+ _EMAIL_API_ADD_RULE = 0x01400000,
+ _EMAIL_API_GET_RULE = 0x01400001,
+ _EMAIL_API_GET_RULE_LIST = 0x01400002,
+ _EMAIL_API_FIND_RULE = 0x01400003,
+ _EMAIL_API_DELETE_RULE = 0x01400004,
+ _EMAIL_API_UPDATE_RULE = 0x01400005,
+ _EMAIL_API_CANCEL_JOB = 0x01400006,
+ _EMAIL_API_GET_PENDING_JOB = 0x01400007,
+ _EMAIL_API_SEND_RETRY = 0x01400008,
+ _EMAIL_API_UPDATE_ACTIVITY = 0x01400009,
+ _EMAIL_API_SYNC_LOCAL_ACTIVITY = 0x0140000A,
+ _EMAIL_API_PRINT_RECEIVING_EVENT_QUEUE = 0x0140000B,
+
+ //Etc
+ _EMAIL_API_PING_SERVICE = 0x01500000,
+ _EMAIL_API_UPDATE_NOTIFICATION_BAR_FOR_UNREAD_MAIL = 0x01500001,
+};
+
+#ifdef __cplusplus
+}
+#endif
+
+/**
+* @} @}
+*/
+
+#endif /* __EMAIL_MAPI_H__ */
+
+
diff --git a/MAPI/include/Emf_Mapi_Account.h b/MAPI/include/Emf_Mapi_Account.h
new file mode 100755
index 0000000..f9d64b3
--- /dev/null
+++ b/MAPI/include/Emf_Mapi_Account.h
@@ -0,0 +1,389 @@
+/*
+* email-service
+*
+* Copyright (c) 2000 - 2011 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.
+*
+*/
+
+
+#ifndef __EMF_MAPI_ACCOUNT_H__
+#define __EMF_MAPI_ACCOUNT_H__
+
+#include "emf-types.h"
+
+/**
+* @defgroup EMAIL_FRAMEWORK Email Service
+* @{
+*/
+
+
+/**
+* @ingroup EMAIL_FRAMEWORK
+* @defgroup EMAIL_MAPI_ACCOUNT Email Account API
+* @{
+*/
+
+/**
+ *
+ * This file contains the data structures and interfaces needed for application,
+ * to interact with Email Engine.
+ * @file Emf_Mapi_Account.h
+ * @author Kyuho Jo <kyuho.jo@samsung.com>
+ * @author Sunghyun Kwon <sh0701.kwon@samsung.com>
+ * @version 0.1
+ * @brief This file contains the data structures and interfaces of Accounts provided by
+ * Email Engine .
+ *
+* @{
+
+* @code
+* #include "emf_mapi_account.h"
+* bool
+* other_app_invoke_uniform_api_sample(int* error_code)
+* {
+* emf_account_t *account = NULL;
+* emf_account_t *new_account = NULL;
+*
+* account = malloc(sizeof(emf_account_t));
+* memset(account, 0x00, sizeof(emf_account_t));
+*
+* account->account_bind_type = 1;
+* account->retrieval_mode = 1;
+* account->use_security = 1;
+* account->sending_server_type = EMF_SERVER_TYPE_SMTP;
+* account->sending_port_num = EMF_SMTP_PORT;
+* account->sending_auth = 1;
+* account->flag1 = 2;
+* account->account_bind_type = 1;
+* account->account_name = strdup("gmail");
+* account->display_name = strdup("Tom");
+* account->email_addr = strdup("tom@gmail.com");
+* account->reply_to_addr = strdup("tom@gmail.com");
+* account->return_addr = strdup("tom@gmail.com");
+* account->receiving_server_type = EMF_SERVER_TYPE_POP3;
+* account->receiving_server_addr = strdup("pop3.gmail.com");
+* account->port_num = 995;
+* account->use_security = 1;
+* account->retrieval_mode = EMF_IMAP4_RETRIEVAL_MODE_ALL;
+* account->user_name = strdup("tom");
+* account->password = strdup("password");
+* account->sending_server_type = EMF_SERVER_TYPE_SMTP;
+* account->sending_server_addr = strdup("smtp.gmail.com");
+* account->sending_port_num = 587;
+* account->sending_security = 0x02;
+* account->sending_auth = 1;
+* account->sending_user = strdup("tom@gmail.com");
+* account->sending_password = strdup("password");
+* account->pop_before_smtp = 0;
+* account->apop = 0;
+* account->flag1 = 2;
+* account->flag2 = 1;
+* account->preset_account = 1;
+* account->logo_icon_path = strdup("Logo Icon Path");
+* account->target_storage = 0;
+* account->options.priority = 3;
+* account->options.keep_local_copy = 0;
+* account->options.req_delivery_receipt = 0;
+* account->options.req_read_receipt = 0;
+* account->options.download_limit = 0;
+* account->options.block_address = 0;
+* account->options.block_subject = 0;
+* account->options.display_name_from = strdup("Display name from");
+* account->options.reply_with_body = 0;
+* account->options.forward_with_files = 0;
+* account->options.add_myname_card = 0;
+* account->options.add_signature = 0;
+* account->options.signature= strdup("Signature");
+* account->check_interval = 0;
+* // Add account
+* if(EMF_ERROR_NONE != email_add_account(account))
+* //failure
+* //else
+* {
+* //success
+* if(account_id)
+* *account_id = account->account_id;
+* }
+* if(EMF_ERROR_NONE != email_validate_account(account_id,&account_handle))
+* //failure
+* else
+* //success
+* if(EMF_ERROR_NONE != email_delete_account(account_id))
+* //failure
+* else
+* //success
+* new_account = malloc(sizeof(emf_account_t));
+* memset(new_account, 0x00, sizeof(emf_account_t));
+* new_account->flag1 = 1;
+* new_account->account_name = strdup("samsung001");
+* new_account->display_name = strdup("Tom001");
+* new_account->options.keep_local_copy = 1;
+* new_account->check_interval = 55;
+* // Update account
+* if(EMF_ERROR_NONE != email_update_account(acount_id,new_account))
+* //failure
+* else
+* //success
+* // Get account
+* if(EMF_ERROR_NONE != email_get_account(account_id,GET_FULL_DATA,&account))
+* //failure
+* else
+* //success
+* // Get list of accounts
+* if(EMF_ERROR_NONE != email_get_account_list(&account_list,&count))
+* //failure
+* else
+* //success
+* // free account
+* email_free_account(&account, 1);
+* }
+ *
+ * @endcode
+ * @}
+ */
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+/**
+ * @open
+ * @fn email_add_account(emf_account_t* account)
+ * @brief Create a new email account.This function is invoked when user wants to add new email account
+ *
+ * @param[in] account Specifies the structure pointer of account.
+ * @exception none
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @see emf_account_t
+ * @remarks N/A
+ */
+EXPORT_API int email_add_account(emf_account_t* account);
+
+/**
+ * @open
+ * @fn email_delete_account(int account_id)
+ * @brief Delete a email account.This function is invoked when user wants to delete an existing email account
+ *
+ * @param[in] account_id Specifies the account ID.
+ * @exception #EMF_ERROR_INVALID_PARAM -Invalid argument
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @see
+ * @remarks N/A
+ */
+EXPORT_API int email_delete_account(int account_id);
+
+/**
+ * @open
+ * @fn email_update_account(int account_id, emf_account_t* new_account)
+ * @brief Change the information of a email account.This function is getting invoked when user wants to change some information of existing email account.
+ *
+ * @param[in] account_id Specifies the orignal account ID.
+ * @param[in] new_account Specifies the information of new account.
+ * @param[in] with_validation If this is 1, email-service will validate the account before updating. If this is 0, email-service will update the account without validation.
+ * @exception #EMF_ERROR_INVALID_PARAM -Invalid argument
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @see emf_account_t
+ * @remarks N/A
+ */
+EXPORT_API int email_update_account(int account_id, emf_account_t* new_account);
+
+/**
+ * @open
+ * @fn email_update_account_with_validation(int account_id, emf_account_t* new_account)
+ * @brief Change the information of a email account.This function is getting invoked when user wants to change some information of existing email account.
+ *
+ * @param[in] account_id Specifies the orignal account ID.
+ * @param[in] new_account Specifies the information of new account.
+ * @param[in] with_validation If this is 1, email-service will validate the account before updating. If this is 0, email-service will update the account without validation.
+ * @exception #EMF_ERROR_INVALID_PARAM -Invalid argument
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @see emf_account_t
+ * @remarks N/A
+ */
+EXPORT_API int email_update_account_with_validation(int account_id, emf_account_t* new_account);
+
+/**
+ * @open
+ * @fn email_get_account(int account_id, int pulloption, emf_account_t** account)
+ * @brief Get an email account by ID. This function is getting invoked when user wants to get the account informantion based on account id and option (GET_FULL_DATA/WITHOUT_OPTION/ONLY_OPTION).<br>
+ * Memory for account information will be allocated to 3rd param(account). The allocated memory should be freed by email_free_account().
+ *
+ * @param[in] account_id Specifies the account ID.This function is invoked when user
+ * @param[in] pulloption Option to specify to get full details or partial, see definition of EMF_ACC_GET_OPT_XXX
+ * @param[out] account The returned account is saved here.
+ * @exception #EMF_ERR_INVALID_PARAM -Invalid argument
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @see emf_account_t
+ * @remarks N/A
+ */
+
+EXPORT_API int email_get_account(int account_id, int pulloption, emf_account_t** account);
+
+/**
+ * @open
+ * @fn email_get_account_list(emf_account_t** account_list, int* count);
+ * @brief Get Account List.This function is getting invoked when user wants to get all account information based on the count of accounts provided by user.<br>
+ * Memory for account information will be allocated to 3rd param(account). The allocated memory should be freed by email_free_account().
+ *
+ * @param[in] account_list Specifies the structure pointer of account.
+ * @param[out] count Specifies the count of accounts.
+ * @exception #EMF_ERR_INVALID_PARAM -Invalid argument
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @see emf_account_t
+ * @remarks N/A
+ */
+EXPORT_API int email_get_account_list(emf_account_t** account_list, int* count);
+
+ /**
+ * @open
+ * @fn email_free_account(emf_account_t** account_list, int count);
+ * @brief Free allocated memory.This function is getting invoked when user wants to delete all account information.
+ *
+ * @param[in] account_list Specifies the structure pointer of account.
+ * @param[out] count Specifies the count of accounts.
+ * @exception #EMF_ERR_INVALID_PARAM -Invalid argument
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @see emf_account_t
+ * @remarks N/A
+ */
+EXPORT_API int email_free_account(emf_account_t** account_list, int count);
+
+
+/**
+ * @open
+ * @fn email_validate_account(int account_id, unsigned* handle)
+ * @brief Validate account.This function is getting invoked after adding one account to validate it.If account is not validated then user should retry once again to add the account .
+ *
+ * @param[in] account_id Specifies the account Id to validate.
+ * @param[out] handle Specifies the sending handle.
+ * @remarks N/A
+ * @exception #EMF_ERR_INVALID_PARAM -Invalid argument
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @see none
+ * @remarks N/A
+ */
+EXPORT_API int email_validate_account(int account_id, unsigned* handle);
+
+/**
+ * @open
+ * @fn email_add_account_with_validation(emf_account_t* account, unsigned* handle)
+ * @brief Add an account when the account is validated. This function is getting invoked when user want to validate an account. If account is not validated then user should retry once again to add the account.<br>
+ * Validation is executed without saving an account to DB
+ *
+ * @param[in] account Specifies the structure pointer of account.
+ * @param[out] handle Specifies the sending handle.
+ * @remarks N/A
+ * @return This function returns true on success or false on failure.
+ */
+EXPORT_API int email_add_account_with_validation(emf_account_t* account, unsigned* handle);
+
+
+/**
+ * @open
+ * @fn email_backup_accounts_into_secure_storage(const char *file_name)
+ * @brief Back up information of all accounts into secure storage.
+ * This function is getting invoked when user want to backup account information safely.
+ *
+ * @param[in] file_name Specifies the file name in secure storage
+ * @remarks N/A
+ * @return This function returns true on success or false on failure.
+ */
+EXPORT_API int email_backup_accounts_into_secure_storage(const char *file_name);
+
+/**
+ * @open
+ * @fn email_restore_accounts_from_secure_storage(const char *file_name)
+ * @brief Restore accounts from stored file in secure storage.
+ * This function is getting invoked when user want to restore accounts.
+ *
+ * @param[in] file_name Specifies the file name in secure storage
+ * @remarks N/A
+ * @return This function returns true on success or false on failure.
+ */
+EXPORT_API int email_restore_accounts_from_secure_storage(const char * file_name);
+
+/**
+ * @open
+ * @fn email_get_password_length_of_account(const int account_id, int *password_length)
+ * @brief Get password length of an account.
+ * This function is getting invoked when user want to know the length of an account.
+ *
+ * @param[in] account_id Specifies the account id
+ * @param[out] handle Specifies the password length.
+ * @remarks N/A
+ * @return This function returns true on success or false on failure.
+ */
+EXPORT_API int email_get_password_length_of_account(const int account_id, int *password_length);
+
+/**
+ * @open
+ * @fn email_update_notification_bar(int account_id)
+ * @brief Update notifications on notification bar.
+ * This function is getting invoked when user want to update notification bar.
+ *
+ * @param[in] account_id Specifies the id of account.
+ * @remarks N/A
+ * @return This function returns true on success or false on failure.
+ */
+EXPORT_API int email_update_notification_bar(int account_id);
+
+/**
+ * @open
+ * @fn email_clear_all_notification_bar()
+ * @brief Clear all notification on notification bar.
+ * This function is getting invoked when user want to clear notification bar.
+ *
+ * @remarks N/A
+ * @return This function returns true on success or false on failure.
+ */
+EXPORT_API int email_clear_all_notification_bar();
+
+
+/**
+ * @open
+ * @fn email_save_default_account_id()
+ * @brief Save default account id to vconf storage.
+ * This function is getting invoked when user want to save default account id.
+ *
+ * @remarks N/A
+ * @return This function returns true on success or false on failure.
+ */
+EXPORT_API int email_save_default_account_id(int input_account_id);
+
+/**
+ * @open
+ * @fn email_load_default_account_id()
+ * @brief Load default account id to vconf storage.
+ * This function is getting invoked when user want to load default account id.
+ *
+ * @remarks N/A
+ * @return This function returns true on success or false on failure.
+ */
+EXPORT_API int email_load_default_account_id(int *output_account_id);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+/**
+* @} @}
+*/
+
+#endif /* __EMF_MAPI_ACCOUNT_H__ */
+
+
diff --git a/MAPI/include/Emf_Mapi_Init.h b/MAPI/include/Emf_Mapi_Init.h
new file mode 100755
index 0000000..719af1e
--- /dev/null
+++ b/MAPI/include/Emf_Mapi_Init.h
@@ -0,0 +1,174 @@
+/*
+* email-service
+*
+* Copyright (c) 2000 - 2011 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.
+*
+*/
+
+
+#ifndef __EMF_MAPI_INTI_H__
+#define __EMF_MAPI_INTI_H__
+
+#include "emf-types.h"
+
+/**
+* @defgroup EMAIL_FRAMEWORK Email Service
+* @{
+*/
+
+
+/**
+* @ingroup EMAIL_FRAMEWORK
+* @defgroup EMAIL_MAPI_INIT Email Initialization API
+* @{
+*/
+
+/**
+ *
+ * This file contains the data structures and interfaces needed for application,
+ * to interact with Email Engine.
+ * @file Emf_Mapi_Init.h
+ * @author Kyuho Jo <kyuho.jo@samsung.com>
+ * @author Sunghyun Kwon <sh0701.kwon@samsung.com>
+ * @version 0.1
+ * @brief This file contains the data structures and interfaces of Email FW Initialization provided by
+ * Email Engine .
+ *@{
+ *@code
+ *
+ * #include "emf_mapi_init.h"
+ *
+ * bool
+ * other_app_invoke_uniform_api_sample(int* error_code)
+ * {
+ * int err = EMF_ERROR_NONE;
+ *
+ * // Open connections to Email Engine and DB
+ * // The connections will be maintain throughout application's execution
+ * if(EMF_ERROR_NONE == email_service_begin())
+ * {
+ * If(EMF_ERROR_NONE != email_open_db())
+ * {
+ * return false;
+ * }
+ *
+ * // Execute email_init_storage() if and only if there is no db file.
+ * // This fuction will create db file and tables for email service
+ * If(EMF_ERROR_NONE !=email_init_storage())
+ * {
+ * return false;
+ * }
+ * }
+ *
+ * ......
+ *
+ * // Work with calling MAPI functions
+ *
+ * ......
+ *
+ * // Close the connections to Email Engine and DB after all email job is finished. (ex. close an email application)
+ * // DO NOT have to call these funtions until the connections is not needed any more.
+ * err =email_close_db();
+ * err =email_service_end();
+ * }
+ *
+ * @endcode
+ * @}
+ */
+
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+/**
+
+ * @open
+ * @fn email_init_storage(void)
+ * @brief Create all table for email. Exposed to External Application- core team.Creates all Email DB tables [ EXTERNAL]
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure
+ * @exception none
+ * @see none
+ * @remarks N/A
+ */
+EXPORT_API int email_init_storage(void);
+
+/**
+
+ * @open
+ * @fn email_open_db(void)
+ * @brief This function Open the email DB and register busy handler
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @exception none
+ * @see none
+ * @remarks N/A
+ */
+EXPORT_API int email_open_db(void);
+
+
+/**
+
+ * @open
+ * @fn email_close_db(void)
+ * @brief This function closes the connection of the email DB
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @exception none
+ * @see none
+ * @remarks N/A
+ */
+EXPORT_API int email_close_db(void);
+
+/**
+
+ * @open
+ * @fn email_service_begin(void)
+ * @brief Does the IPC Proxy Initialization by the Application which used the Email FW API's
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @exception none
+ * @see none
+ * @remarks N/A
+ */
+EXPORT_API int email_service_begin(void);
+
+/**
+
+ * @open
+ * @fn email_service_end(void)
+ * @brief This function does the IPC Proxy Finaization by the Application which used the Email FW API's
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @exception none
+ * @see none
+ * @remarks N/A
+ */
+EXPORT_API int email_service_end(void);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+/**
+* @} @}
+*/
+
+
+#endif /* __EMF_MAPI_INTI_H__ */
diff --git a/MAPI/include/Emf_Mapi_Mailbox.h b/MAPI/include/Emf_Mapi_Mailbox.h
new file mode 100755
index 0000000..ba08dc4
--- /dev/null
+++ b/MAPI/include/Emf_Mapi_Mailbox.h
@@ -0,0 +1,326 @@
+/*
+* email-service
+*
+* Copyright (c) 2000 - 2011 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.
+*
+*/
+
+
+#ifndef __EMF_MAPI_FOLDER_H__ /* mailbox */
+#define __EMF_MAPI_FOLDER_H__
+
+#include "emf-types.h"
+
+/**
+* @defgroup EMAIL_FRAMEWORK Email Service
+* @{
+*/
+
+
+/**
+* @ingroup EMAIL_FRAMEWORK
+* @defgroup EMAIL_MAPI_FOLDER Email mailbox(Mailbox) API
+* @{
+*/
+
+/**
+ *
+ * This file contains the data structures and interfaces needed for application,
+ * to interact with Email Engine.
+ * @file Emf_Mapi_Folder.h
+ * @author Kyuho Jo <kyuho.jo@samsung.com>
+ * @author Sunghyun Kwon <sh0701.kwon@samsung.com>
+ * @version 0.1
+ * @brief This file contains the data structures and interfaces of mailbox [mailbox] provided by
+ * Email Engine .
+ * @{
+ * @code
+ *
+ * #include "emf_mapi_folder.h"
+ *
+ * bool
+ * other_app_invoke_uniform_api_sample(int *error_code)
+ * {
+ * emf_mailbox_t mbox;
+ * emf_mailbox_t *new_mailbox =NULL;
+ * emf_mailbox_t *mailbox_list = NULL;
+ * int count = 0;
+ * int mailbox_type;
+ * unsigned handle = 0;
+ * char *pMaiboxName;
+ * char *pParentMailbox;
+ *
+ * memset(&mbox,0x00,sizeof(emf_mailbox_t));
+ * mbox.name = strdup("test");
+ * mbox.alias = strdup("Personal");
+ * mbox.account_id = 1;
+ * printf("Enter local_yn(1/0)");
+ * scanf("%d",&local_yn);
+ * mbox.local=local_yn;
+ * mbox.mailbox_type = 7;
+ *
+ * //create new mailbox
+ *
+ * if(EMF_ERR_NONE != email_add_mailbox(&mbox,local_yn,&handle))
+ * printf("email_add_mailbox failed\n");
+ * else
+ * printf("email_add_mailbox success");
+ *
+ * //update mailbox
+ * new_mailbox = malloc(sizeof(emf_mailbox_t));
+ * memset(new_mailbox,0x00,sizeof(emf_mailbox_t));
+ *
+ * new_mailbox->name = strdup("PersonalUse");
+ *
+ * if(EMF_ERROR_NONE != email_update_mailbox(&mbox,new_mailbox))
+ * printf("email_update_mailbox failed\n");
+ * else
+ * printf("email_update_mailbox success\n");
+ * //delete mailbox
+ *
+ * if(EMF_ERROR_NONE != email_delete_mailbox(mbox,local_yn,&handle))
+ * printf("email_delete_mailbox failed\n");
+ * else
+ * printf("email_delete_mailbox success\n");
+ *
+ * //free mailbox
+ * email_free_mailbox("new_mailbox,1");
+ *
+ * //Get mailbox list
+ * if(EMF_ERROR_NONE != email_get_mailbox_list(account_id,local_yn,&mailbox_list,&count))
+ * //failure
+ * else
+ * //success
+ *
+ * //Get mailbox by name
+ * pMailboxName = strdup("test");
+ * if(EMF_ERROR_NONE != email_get_mailbox_by_name(account_id,pMailboxName,&mailbox_list))
+ * //failure
+ * else
+ * //success
+ *
+ * //Get child mailbox list
+ * pParentMailbox = strdup("test");
+ * if(EMF_ERROR_NONE != email_get_child_mailbox_list(account_id, paerent_mailbox,&mailbox_list,&count))
+ * //failure
+ * else
+ * //success
+ *
+ * //Get mailbox by mailbox_type
+ * printf("Enter mailbox_type\n");
+ * scanf("%d",&mailbox_type);
+ * if(EMF_ERROR_NONE != email_get_mailbox_by_mailbox_type(account_id,mailbox_type,&mailbox_list))
+ * //failure
+ * else
+ * //success
+ *
+ * }
+ *
+ * @endcode
+ * @}
+ */
+
+
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif /* __cplusplus */
+
+
+/**
+
+ * @open
+ * @fn EXPORT_API int email_add_mailbox(emf_mailbox_t* new_mailbox, int on_server, unsigned* handle)
+ * @brief Create a new mailbox or mailbox.This function is invoked when user wants to create a new mailbox for the specified account.
+ * If On_server is true then it will create the mailbox on server as well as in local also.
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code(refer to EMF_ERROR_XXX) on failure.
+ * @param[in] new_mailbox Specifies the pointer of creating mailbox information.
+* @param[in] on_server Specifies the creating mailbox information on server.
+ * @param[out] handle Specifies the sending handle.
+ * @exception none
+ * @see emf_mailbox_t
+ * @remarks N/A
+ */
+EXPORT_API int email_add_mailbox(emf_mailbox_t* new_mailbox, int on_server, unsigned* handle);
+
+
+/**
+
+ * @open
+ * @fn EXPORT_API int email_delete_mailbox(emf_mailbox_t* mailbox, int on_server, unsigned* handle)
+ * @brief Delete a mailbox or mailbox.This function deletes the existing mailbox for specified account based on the option on_server.
+ * If the on_server is true then it deletes mailbox from server as well as locally.
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code(refer to EMF_ERROR_XXX) on failure.
+ * @param[in] mailbox Specifies the pointer of deleting mailbox information.
+ * @param[in] on_server Specifies the creating mailbox information on server.
+ * @param[out] handle Specifies the sending handle.
+ * @exception #EMF_ERROR_INVALID_PARAM -Invaid argument
+ * @see emf_mailbox_t
+ * @remarks N/A
+ */
+EXPORT_API int email_delete_mailbox(emf_mailbox_t* mailbox, int on_server, unsigned* handle);
+
+
+/**
+
+ * @fn EXPORT_API int email_update_mailbox(emf_mailbox_t* old_mailbox, emf_mailbox_t* new_mailbox)
+ * @brief Change mailbox or mailbox information.This function is invoked when user wants to change the existing mail box information.
+ * This supports ONLY updating mailbox_type in local db. This can be used to match a specific mail box and a specific mailbox_type.
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code(refer to EMF_ERROR_XXX) on failure.
+ * @param[in] old_mailbox Specifies the information of previous mailbox. <br>mandatory field : account_id, name
+ * @param[in] new_mailbox Specifies the information of new mailbox. <br
+ * @exception #EMF_ERROR_INVALID_PARAM -Invaid argument
+ * @see emf_mailbox_t, emf_mailbox_type_e
+ * @remarks N/A
+ */
+EXPORT_API int email_update_mailbox(emf_mailbox_t* old_mailbox, emf_mailbox_t* new_mailbox);
+
+EXPORT_API int email_get_sync_mailbox_list(int account_id, emf_mailbox_t** mailbox_list, int* count) DEPRECATED;
+
+
+/**
+
+ * @open
+ * @fn email_get_mailbox_list(int account_id, int mailbox_sync_type, emf_mailbox_t** mailbox_list, int* count)
+ * @brief Get all mailboxes from account.
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code(refer to EMF_ERROR_XXX) on failure.
+ * @param[in] account_id Specifies the account ID.
+ * @param[in] mailbox_sync_type Specifies the sync type.
+ * @param[out] mailbox_list Specifies the pointer of mailbox structure pointer.(possibly NULL)
+ * @param[out] count The mailbox count is saved here.(possibly 0)
+ * @exception none
+ * @see emf_mailbox_t
+
+ * @code
+ * #include "Emf_Mapi_Message.h"
+ * bool
+ * _api_sample_get_mailbox_list()
+ * {
+ * int account_id =0,count = 0;
+ * int mailbox_sync_type;
+ * int error_code = EMF_ERROR_NONE;
+ * emf_mailbox_t *mailbox_list=NULL;
+ *
+ * printf("\n > Enter account id: ");
+ * scanf("%d", &account_id);
+ * printf("\n > Enter mailbox_sync_type: ");
+ * scanf("%d", &mailbox_sync_type);
+ *
+ * if((EMF_ERROR_NONE != email_get_mailbox_list(account_id, mailbox_sync_type, &mailbox_list, &count)))
+ * {
+ * printf(" Error\n");
+ * }
+ * else
+ * {
+ * printf("Success\n");
+ * email_free_mailbox(&mailbox_list,count);
+ * }
+ * }
+ * @endcode
+ * @remarks N/A
+ */
+EXPORT_API int email_get_mailbox_list(int account_id, int mailbox_sync_type, emf_mailbox_t** mailbox_list, int* count);
+
+EXPORT_API int email_get_mailbox_list_ex(int account_id, int mailbox_sync_type, int with_count, emf_mailbox_t** mailbox_list, int* count);
+
+/**
+
+ * @open
+ * @fn EXPORT_API int email_get_mailbox_by_name(int account_id, const char *pMailboxName, emf_mailbox_t **pMailbox);
+ * @brief Get the mailbox information by name.This function gets the mailbox by given mailbox name for a specified account.
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code(refer to EMF_ERROR_XXX) on failure.
+ * @param[in] account_id Specifies the information of account Id.
+ * @param[in] pMailboxName Specifies the mailbox name.
+ * @param[out] pMailbox Specifies the information of mailbox
+ * @exception none
+ * @see emf_mailbox_t
+ * @remarks N/A
+ */
+
+EXPORT_API int email_get_mailbox_by_name(int account_id, const char *pMailboxName, emf_mailbox_t **pMailbox);
+
+// Belows are for A Project
+
+/**
+
+ * @open
+ * @fn email_get_child_mailbox_list(int account_id, char *parent_mailbox, emf_mailbox_t** mailbox_list, int* count)
+ * @brief Get all sub mailboxes for given parent mailbox.This function gives all the child mailbox list for a given parent mailbox for specified account.
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code(refer to EMF_ERROR_XXX) on failure.
+ * @param[in] account_id Specifies the account ID.
+ * @param[in] parent_mailbox Specifies the parent mailbox
+ * @param[out] mailbox_list Specifies the pointer of mailbox structure pointer.(possibly NULL)
+ * @param[out] count The mailbox count
+ * @exception #EMF_ERROR_INVALID_PARAM -Invalid argument
+ * @see emf_mailbox_t
+ * @remarks N/A
+ * @return This function returns true on success or false on failure.
+ */
+EXPORT_API int email_get_child_mailbox_list(int account_id, const char *parent_mailbox, emf_mailbox_t** mailbox_list, int* count);
+
+
+/**
+ * @open
+ * @fn email_get_mailbox_by_mailbox_type(int account_id, emf_mailbox_type_e mailbox_type, emf_mailbox_t** mailbox)
+ * @brief Get mailbox by mailbox_type.This function is invoked when user wants to know the mailbox information by mailbox_type for the given account.
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code(refer to EMF_ERROR_XXX) on failure.
+ * @param[in] account_id Specifies the account ID.
+ * @param[in] mailbox_type Specifies the mailbox type.
+ * @param[out] mailbox Specifies the pointer of mailbox structure pointer.(possibly NULL)
+ * @exception none
+ * @see emf_mailbox_t
+ * @remarks N/A
+ */
+EXPORT_API int email_get_mailbox_by_mailbox_type(int account_id, emf_mailbox_type_e mailbox_type, emf_mailbox_t** mailbox);
+
+/**
+ * @open
+ * @fn email_set_mail_slot_size(int account_id, char* mailbox_name, int new_slot_size, unsigned* handle)
+ * @brief Set mail slot size.This function is invoked when user wants to set the size of mail slot.
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code(refer to EMF_ERROR_XXX) on failure.
+ * @param[in] account_id Specifies the account ID.
+ * @param[in] mailbox_name Specifies the mailbox name.
+ * @param[in] new_slot_size Specifies the mail slot size.
+ * @exception none
+ * @see emf_mailbox_t
+ * @remarks N/A
+ */
+EXPORT_API int email_set_mail_slot_size(int account_id, char* mailbox_name, int new_slot_size/*, unsigned* handle*/);
+
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+/**
+* @} @}
+*/
+
+
+
+#endif /* __EMF_MAPI_FOLDER_H__ */
+
+
diff --git a/MAPI/include/Emf_Mapi_Message.h b/MAPI/include/Emf_Mapi_Message.h
new file mode 100755
index 0000000..f8d1f50
--- /dev/null
+++ b/MAPI/include/Emf_Mapi_Message.h
@@ -0,0 +1,2341 @@
+/*
+* email-service
+*
+* Copyright (c) 2000 - 2011 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.
+*
+*/
+
+
+#ifndef __EMF_MAPI_MESSAGE_H__
+#define __EMF_MAPI_MESSAGE_H__
+
+#include "emf-types.h"
+
+#include <time.h>
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
+/**
+* @defgroup EMAIL_FRAMEWORK Email Service
+* @{
+*/
+
+
+/**
+* @ingroup EMAIL_FRAMEWORK
+* @defgroup EMAIL_MAPI_MESSAGE Email Message API
+* @{
+*/
+
+/**
+ *
+ * This file contains the data structures and interfaces needed for application,
+ * to interact with Email Engine.
+ * @file Emf_Mapi_Message.h
+ * @author Kyuho Jo <kyuho.jo@samsung.com>
+ * @author Sunghyun Kwon <sh0701.kwon@samsung.com>
+ * @version 0.1
+ * @brief This file contains the data structures and interfaces of Messages provided by
+ * Email Engine .
+ */
+
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+
+/* email_add_message will be deprecated */
+EXPORT_API int email_add_message(emf_mail_t* mail, emf_mailbox_t* mailbox, int from_composer);
+
+/**
+ * @open
+ * @fn email_add_mail(emf_mail_data_t *input_mail_data, emf_attachment_data_t *input_attachment_data_list, int input_attachment_count, emf_meeting_request_t* input_meeting_request, int input_sync_server)
+ * @brief Save a mail. This function is invoked when user wants to add a mail.
+ * If the option sync_server is 1 then this will save the message on server as well as on locally.
+ * If the receiving_server_type is EMF_SERVER_TYPE_POP3 then sync_server value will be 0
+ * If the receiving_server_type is EMF_SERVER_TYPE_IMAP4 then sync_server value will be 1/0
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @param[in] input_mail_data Specifies the saving mail.
+ * @param[in] input_attachment_data_list Specifies the mailbox structure for saving email.
+ * @param[in] input_attachment_count Specifies if the mail comes from composer.
+ * @param[in] input_meeting_request Specifies if the mail comes from composer.
+ * @param[in] input_sync_server Specifies if the mail will be saved on server.
+
+ * @exception none
+ * @see emf_mail_t and emf_mailbox_t
+ * @remarks N/A
+ * @code
+ * #include "Emf_Mapi_Message.h"
+ * int _test_add_mail ()
+ * {
+ * int i = 0;
+ * int account_id = 0;
+ * int sync_server = 0;
+ * int attachment_count = 0;
+ * int err = EMF_ERROR_NONE;
+ * char arg[50] = { 0 , };
+ * char *body_file_path = "/opt/data/email/.emfdata/tmp/mail.txt";
+ * emf_mailbox_t *mailbox_data = NULL;
+ * emf_mail_data_t *test_mail_data = NULL;
+ * emf_attachment_data_t *attachment_data = NULL;
+ * emf_meeting_request_t *meeting_req = NULL;
+ * FILE *body_file;
+ *
+ * printf("\n > Enter account id : ");
+ * scanf("%d", &account_id);
+ *
+ *
+ * memset(arg, 0x00, 50);
+ * printf("\n > Enter mailbox name : ");
+ * scanf("%s", arg);
+ *
+ * email_get_mailbox_by_name(account_id, arg, &mailbox_data);
+ *
+ * test_mail_data = malloc(sizeof(emf_mail_data_t));
+ * memset(test_mail_data, 0x00, sizeof(emf_mail_data_t));
+ *
+ * printf("\n Sync server? [0/1]> ");
+ * scanf("%d", &sync_server);
+ *
+ * test_mail_data->account_id = account_id;
+ * test_mail_data->save_status = 1;
+ * test_mail_data->flags_seen_field = 1;
+ * test_mail_data->file_path_plain = strdup(body_file_path);
+ * test_mail_data->mailbox_name = strdup(mailbox_data->name);
+ * test_mail_data->mailbox_type = mailbox_data->mailbox_type;
+ * test_mail_data->full_address_from = strdup("<test1@test.com>");
+ * test_mail_data->full_address_to = strdup("<test2@test.com>");
+ * test_mail_data->full_address_cc = strdup("<test3@test.com>");
+ * test_mail_data->full_address_bcc = strdup("<test4@test.com>");
+ * test_mail_data->subject = strdup("Meeting request mail");
+ *
+ * body_file = fopen(body_file_path, "w");
+ *
+ * for(i = 0; i < 500; i++)
+ * fprintf(body_file, "X2 X2 X2 X2 X2 X2 X2");
+ * fflush(body_file);
+ * fclose(body_file);
+ *
+ * printf(" > Attach file? [0/1] : ");
+ * scanf("%d",&attachment_count);
+ *
+ * if ( attachment_count ) {
+ * memset(arg, 0x00, 50);
+ * printf("\n > Enter attachment name : ");
+ * scanf("%s", arg);
+ *
+ * attachment_data = malloc(sizeof(emf_attachment_data_t));
+ *
+ * attachment_data->attachment_name = strdup(arg);
+ *
+ * memset(arg, 0x00, 50);
+ * printf("\n > Enter attachment absolute path : ");
+ * scanf("%s",arg);
+ *
+ * attachment_data->attachment_path = strdup(arg);
+ * attachment_data->save_status = 1;
+ * test_mail_data->attachment_count = attachment_count;
+ * }
+ *
+ * printf("\n > Meeting Request? [0: no, 1: yes (request from server), 2: yes (response from local)]");
+ * scanf("%d", &(test_mail_data->meeting_request_status));
+ *
+ * if ( test_mail_data->meeting_request_status == 1
+ * || test_mail_data->meeting_request_status == 2 ) {
+ * time_t current_time;
+ * meeting_req = malloc(sizeof(emf_meeting_request_t));
+ * memset(meeting_req, 0x00, sizeof(emf_meeting_request_t));
+ *
+ * meeting_req->meeting_response = 1;
+ * current_time = time(NULL);
+ * gmtime_r(&current_time, &(meeting_req->start_time));
+ * gmtime_r(&current_time, &(meeting_req->end_time));
+ * meeting_req->location = malloc(strlen("Seoul") + 1);
+ * memset(meeting_req->location, 0x00, strlen("Seoul") + 1);
+ * strcpy(meeting_req->location, "Seoul");
+ * strcpy(meeting_req->global_object_id, "abcdef12345");
+ *
+ * meeting_req->time_zone.offset_from_GMT = 9;
+ * strcpy(meeting_req->time_zone.standard_name, "STANDARD_NAME");
+ * gmtime_r(&current_time, &(meeting_req->time_zone.standard_time_start_date));
+ * meeting_req->time_zone.standard_bias = 3;
+ *
+ * strcpy(meeting_req->time_zone.daylight_name, "DAYLIGHT_NAME");
+ * gmtime_r(&current_time, &(meeting_req->time_zone.daylight_time_start_date));
+ * meeting_req->time_zone.daylight_bias = 7;
+ *
+ * }
+ *
+ * if((err = email_add_mail(test_mail_data, attachment_data, attachment_count, meeting_req, sync_server)) != EMF_ERROR_NONE)
+ * printf("email_add_mail failed. [%d]\n", err);
+ * else
+ * printf("email_add_mail success.\n");
+ *
+ * if(attachment_data)
+ * email_free_attachment_data(&attachment_data, attachment_count);
+ *
+ * if(meeting_req)
+ * email_free_meeting_request(&meeting_req, 1);
+ *
+ * email_free_mail_data(&test_mail_data, 1);
+ * email_free_mailbox(&mailbox_data, 1);
+ *
+ * printf("saved mail id = [%d]\n", test_mail_data->mail_id);
+ *
+ * return 0;
+ * }
+ * @endcode
+ */
+EXPORT_API int email_add_mail(emf_mail_data_t *input_mail_data, emf_attachment_data_t *input_attachment_data_list, int input_attachment_count, emf_meeting_request_t* input_meeting_request, int input_sync_server);
+
+
+/* email_update_message will be deprecated */
+EXPORT_API int email_update_message( int mail_id, emf_mail_t* mail);
+
+/**
+ * @open
+ * @fn email_update_mail(emf_mail_data_t *input_mail_data, emf_attachment_data_t *input_attachment_data_list, int input_attachment_count, emf_meeting_request_t* input_meeting_request, int input_from_composer)
+ * @brief Update a existing email information. This function is invoked when user wants to change some existing email information with new email information.
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @param[in] input_mail_data Specifies the mail ID.
+ * @param[in] input_attachment_data_list Specifies the pointer of attachment data.
+ * @param[in] input_attachment_count Specifies the number of attachment data.
+ * @param[in] input_meeting_request Specifies the meeting request data.
+ * @param[in] input_sync_server Specifies whether sync server.
+
+ * @exception none
+ * @see emf_mail_t
+ * @code
+ * #include "Emf_Mapi_Message.h"
+ * int email_test_update_mail()
+ * {
+ * int mail_id = 0;
+ * int err = EMF_ERROR_NONE;
+ * int test_attachment_data_count = 0;
+ * char arg[50];
+ * emf_mail_data_t *test_mail_data = NULL;
+ * emf_attachment_data_t *test_attachment_data_list = NULL;
+ * emf_meeting_request_t *meeting_req = NULL;
+ *
+ * printf("\n > Enter mail id : ");
+ * scanf("%d", &mail_id);
+ *
+ * email_get_mail_data(mail_id, &test_mail_data);
+ *
+ * printf("\n > Enter Subject: ");
+ * scanf("%s", arg);
+ *
+ * test_mail_data->subject= strdup(arg);
+ *
+ *
+ *
+ * if (test_mail_data->attachment_count > 0) {
+ * if ( (err = email_get_attachment_data_list(mail_id, &test_attachment_data_list, &test_attachment_data_count)) != EMF_ERROR_NONE ) {
+ * printf("email_get_meeting_request() failed [%d]\n", err);
+ * return -1;
+ * }
+ * }
+ *
+ * if ( test_mail_data->meeting_request_status == EMF_MAIL_TYPE_MEETING_REQUEST
+ * || test_mail_data->meeting_request_status == EMF_MAIL_TYPE_MEETING_RESPONSE
+ * || test_mail_data->meeting_request_status == EMF_MAIL_TYPE_MEETING_ORIGINATINGREQUEST) {
+ *
+ * if ( (err = email_get_meeting_request(mail_id, &meeting_req)) != EMF_ERROR_NONE ) {
+ * printf("email_get_meeting_request() failed [%d]\n", err);
+ * return -1;
+ * }
+ *
+ * printf("\n > Enter meeting response: ");
+ * scanf("%d", (int*)&(meeting_req->meeting_response));
+ * }
+ *
+ * if ( (err = email_update_mail(test_mail_data, test_attachment_data_list, test_attachment_data_count, meeting_req, 0)) != EMF_ERROR_NONE)
+ * printf("email_update_mail failed.[%d]\n", err);
+ * else
+ * printf("email_update_mail success\n");
+ *
+ * if(test_mail_data)
+ * email_free_mail_data(&test_mail_data, 1);
+ *
+ * if(test_attachment_data_list)
+ * email_free_attachment_data(&test_attachment_data_list, test_attachment_data_count);
+ *
+ * if(meeting_req)
+ * email_free_meeting_request(&meeting_req, 1);
+ *
+ * return 0;
+ * }
+
+ * @endcode
+ * @remarks N/A
+ */
+EXPORT_API int email_update_mail(emf_mail_data_t *input_mail_data, emf_attachment_data_t *input_attachment_data_list, int input_attachment_count, emf_meeting_request_t* input_meeting_request, int input_sync_server);
+
+/**
+
+ * @open
+ * @fn email_count_message(emf_mailbox_t* mailbox, int* total, int* unseen)
+ * @brief Get mail count from mailbox.This function is invoked when user wants to know how many toatl mails and out of that
+ * how many unseen mails are there in a given mailbox.
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @param[in] mailbox Specifies the pointer of mailbox structure.
+ * @param[out] total Total email count is saved here.
+ * @param[out] unseen Unread email count is saved here.
+ * @exception none
+ * @see emf_mailbox_t
+
+ * @code
+ * #include "Emf_Mapi_Message.h"
+ * bool
+ * _api_sample_count_message()
+ * {
+ * emf_mailbox_t mailbox;
+ * int account_id = 0;
+ * int total = 0;
+ * int unseen = 0;
+ *
+ * memset(&mailbox, 0x00, sizeof(emf_mailbox_t));
+ * printf("\n > Enter account_id (0 means all accounts) : ");
+ * scanf("%d", &account_id);
+ * if(account_id == 0)
+ * {
+ * mailbox.name = NULL;
+ * }
+ * else
+ * {
+ * printf("\n > Enter maibox name: ");
+ * mailbox.name = strdup("SENTBOX");
+ * }
+ * mailbox.account_id = account_id;
+ * if(EMF_ERROR_NONE == email_count_message(&mailbox, &total, &unseen))
+ * printf("\n Total: %d, Unseen: %d \n", total, unseen);
+ * }
+ * @endcode
+ * @remarks N/A
+ */
+EXPORT_API int email_count_message(emf_mailbox_t* mailbox, int* total, int* unseen);
+
+
+/**
+ * @open
+ * @fn email_delete_message(emf_mailbox_t* mailbox, int *mail_ids, int num, int from_server)
+ * @brief Delete a mail or multiple mails.Based on from_server value this function will delte a mail or multiple mails from server or loaclly.
+ * @param[in] mailbox Reserved.
+ * If the receiving_server_type is EMF_SERVER_TYPE_POP3 then from_server value will be 0
+ * If the receiving_server_type is EMF_SERVER_TYPE_IMAP4 then from_server value will be 1/0
+ *
+ * @param[in] mail_ids[] Specifies the arrary of mail id.
+ * @param[in] num Specifies the number of mail id.
+ * @param[in] from_server Specifies whether mails are deleted from server.
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @exception none
+ * @see emf_mailbox_t
+ * @code
+ * #include "Emf_Mapi_Message.h"
+ * bool
+ * _api_sample_delete_all_messages_in_mailbox()
+ * {
+ * int count, i, mail_id=0, account_id =0;
+ * emf_mailbox_t mbox = {0};
+ * emf_mail_body_t *body = NULL;
+ *
+ * printf("\n > Enter Account_id: ");
+ * scanf("%d",&account_id);
+ * printf("\n > Enter Mail_id: ");
+ * scanf("%d",&mail_id);
+ * printf("\n > Enter Mailbox name: ");
+ * mbox.account_id = account_id;
+ * mbox.name = strdup("INBOX");
+ * if(EMF_ERROR_NONE == email_delete_message(&mbox, &mail_id, 1, 1))
+ * printf("\n email_delete_message success");
+ * else
+ * printf("\n email_delete_message failed");
+ * }
+ * @endcode
+ * @remarks N/A
+ */
+EXPORT_API int email_delete_message(emf_mailbox_t* mailbox, int *mail_ids, int num, int from_server);
+
+
+/**
+
+ * @open
+ * @fn email_delete_all_message_in_mailbox(emf_mailbox_t* mailbox, int from_server)
+ * @brief Delete all mail from a mailbox.
+ * If the receiving_server_type is EMF_SERVER_TYPE_POP3 then from_server value will be 0
+ * If the receiving_server_type is EMF_SERVER_TYPE_IMAP4 then from_server value will be 1/0
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @param[in] mailbox Specifies the structure of mailbox.
+ * @param[in] from_server Specifies whether mails are also deleted from server.
+ * @exception none
+ * @see emf_mailbox_t
+
+ * @code
+ * #include "Emf_Mapi_Message.h"
+ * bool
+ * _api_sample_delete_all_messages_in_mailbox()
+ * {
+ * int count, account_id =0;
+ * emf_mailbox_t mbox = {0};
+ *
+ * printf("\n > Enter Account_id: ");
+ * scanf("%d",&account_id);
+ * printf("\n > Enter Mailbox name: ");
+ * mbox.account_id = account_id;
+ * mbox.name = strdup("INBOX");
+ *
+ * if (EMF_ERROR_NONE != email_delete_all_message_in_mailbox(&mbox, 0))
+ * printf("email_delete_all_message_in_mailbox failed");
+ * else
+ * printf("email_delete_all_message_in_mailbox Success");
+ * }
+ * @endcode
+ * @remarks N/A
+ */
+EXPORT_API int email_delete_all_message_in_mailbox(emf_mailbox_t* mailbox,
+ int from_server);
+
+
+
+/**
+ * @open
+ * @fn email_clear_mail_data()
+ * @brief delete email data from storage. This API will be used by the Settings Application
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @exception none
+ * @see none
+
+ * @code
+ * #include "Emf_Mapi_Message.h"
+ * bool
+ * _api_sample_clear_mail_data()
+ * {
+ * if(EMF_ERROR_NONE == email_clear_mail_data())
+ * //success
+ * else
+ * //failure
+ *
+ * }
+ * @endcode
+ * @remarks N/A
+ */
+EXPORT_API int email_clear_mail_data();
+
+
+/**
+ * @open
+ * @fn email_add_attachment( emf_mailbox_t* mailbox, int mail_id, emf_attachment_info_t* attachment)
+ * @brief Append a attachment to email.This function is invoked when user wants to add attachment to existing mail.
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @param[in] mail_id Specifies the mail ID.
+ * @param[in] attachment Specifies the structure of attachment.
+ * @exception none
+ * @see emf_mailbox_t and emf_attachment_info_t
+
+ * @code
+ * #include "Emf_Mapi_Message.h"
+ * bool
+ * _api_sample_mail_add_attachment()
+ * {
+ * int account_id = 0;
+ * int mail_id = 0;
+ * emf_mailbox_t mbox;
+ * emf_attachment_info_t attachment;
+ *
+ * printf("\n > Enter Mail Id: ");
+ * scanf("%d", &mail_id);
+ * printf("\n > Enter Account_id: ");
+ * scanf("%d",&account_id);
+ * memset(&mbox, 0x00, sizeof(emf_attachment_info_t));
+ * mbox.account_id = account_id;
+ * mbox.name = strdup("INBOX");
+ * memset(&attachment, 0x00, sizeof(emf_attachment_info_t));
+ * printf("\n > Enter attachment name: ");
+ * attachment.name = strdup("Test");
+ * printf("\n > Enter attachment absolute path: ");
+ * attachment.savename = strdup("/tmp/test.txt");
+ * attachment.next = NULL;
+ * if(EMF_ERROR_NONE != email_add_attachment( &mbox, mail_id, &attachment))
+ * printf("email_add_attachment failed\n");
+ * else
+ * printf(email_add_attachment success\n");
+ * }
+ * @endcode
+ * @remarks N/A
+ */
+EXPORT_API int email_add_attachment( emf_mailbox_t* mailbox, int mail_id, emf_attachment_info_t* attachment);
+
+
+/**
+ * @open
+ * @fn email_delete_attachment(emf_mailbox_t * mailbox, int mail_id, const char * attachment_id)
+ * @brief delete a attachment from email.This function is invoked when user wants to delete a attachment from existing mailbased on mail Id and attachment Id
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @param[in] mailbox Specifies the structure of mailbox.
+ * @param[in] mail_id Specifies the mail ID.
+ * @param[in] attachment_id Specifies the attachment id.
+ * @exception none
+ * @see emf_mailbox_t
+ * @code
+ * #include "Emf_Mapi_Message.h"
+ * bool
+ * _api_sample_mail_delete_attachment()
+ * {
+ * int account_id = 0;
+ * int mail_id = 0;
+ * char *attchment_id;
+ * emf_mailbox_t mbox;
+ *
+ * mail_id = 1; // mail id in the DB
+ * mbox.account_id = 1; // account id in the DB
+ * mbox.name = strdup("INBOX"); // mailbox name
+ * attachment_id = strdup("1"); // the first attachment item in a attachment list
+ *
+ * if(EMF_ERROR_NONE != email_delete_attachment(&mbox,mail_id,attachment_id))
+ * //failure
+ * else
+ * //success
+ * }
+ * @endcode
+ * @remarks N/A
+ */
+EXPORT_API int email_delete_attachment(emf_mailbox_t * mailbox, int mail_id, const char * attachment_id);
+
+
+/* -----------------------------------------------------------
+ Mail Search API
+ -----------------------------------------------------------*/
+
+/**
+
+ * @open
+ * @fn email_query_mails(char *conditional_clause_string, emf_mail_data_t** mail_list, int *result_count)
+ * @brief Query the mail list information from DB based on the mailbox name.
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @param[in] conditional_clause_string Specifies the where clause string.
+ * @param[in/out] mail_list Specifies the pointer to the structure emf_mail_data_t.
+ * @param[in/out] result_count Specifies the number of mails returned.
+ * @exception None
+ * @see emf_mail_list_item_t
+
+ * @code
+ * #include "Emf_Mapi_Message.h"
+ * bool
+ * _api_sample_query_mail()
+ * {
+ * emf_mail_data_t *mail_list = NULL;
+ * char conditional_clause_string[500];
+ * int result_count = 0;
+ *
+ * memset(mailbox_name, 0x00, 10);
+ * printf("\n > Enter where clause: ");
+ * scanf("%s", conditional_clause_string);
+ *
+ *
+ * if (EMF_ERROR_NONE != email_query_mails(conditional_clause_string, &mail_list, &result_count))
+ * printf("email_query_message_ex failed \n");
+ * else {
+ * printf("Success\n");
+ * //do something
+ * free(mail_list);
+ * }
+ *
+ * }
+ * @endcode
+ * @remarks N/A
+ */
+EXPORT_API int email_query_mails(char *conditional_clause_string, emf_mail_data_t** mail_list, int *result_count);
+
+/**
+
+ * @open
+ * @fn email_query_message_ex(char *conditional_clause_string, emf_mail_list_item_t** mail_list, int *result_count)
+ * @brief Query the mail list information from DB based on the mailbox name.
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @param[in] conditional_clause_string Specifies the where clause string.
+ * @param[in/out] mail_list Specifies the pointer to the structure emf_mail_list_item_t.
+ * @param[in/out] result_count Specifies the number of mails returned.
+ * @exception None
+ * @see emf_mail_list_item_t
+
+ * @code
+ * #include "Emf_Mapi_Message.h"
+ * bool
+ * _api_sample_query_mail()
+ * {
+ * emf_mail_list_item_t *mail_list = NULL;
+ * char conditional_clause_string[500];
+ * int result_count = 0;
+ *
+ * memset(mailbox_name, 0x00, 10);
+ * printf("\n > Enter where clause: ");
+ * scanf("%s", conditional_clause_string);
+ *
+ *
+ * if (EMF_ERROR_NONE != email_query_message_ex(conditional_clause_string, &mail_list, &result_count))
+ * printf("email_query_message_ex failed \n");
+ * else {
+ * printf("Success\n");
+ * //do something
+ * free(mail_list);
+ * }
+ *
+ * }
+ * @endcode
+ * @remarks N/A
+ */
+EXPORT_API int email_query_message_ex(char *conditional_clause_string, emf_mail_list_item_t** mail_list, int *result_count);
+
+
+/* -----------------------------------------------------------
+ Mail Get Info API
+ -----------------------------------------------------------*/
+/**
+
+ * @open
+ * @fn email_get_info(emf_mailbox_t* mailbox, int mail_id, emf_mail_info_t** info)
+ * @brief Get a mail info.This function is invoked when user wants to know the basic inforamtion of a mail
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @param[in] mailbox Reserved.
+ * @param[in] mail_id Specifies the mail ID.
+ * @param[out] info The returned body of mail is saved here.
+ * @exception none
+ * @see emf_mailbox_t
+
+ * @code
+ * #include "Emf_Mapi_Message.h"
+ * bool
+ * _api_sample_mail_get_info()
+ * {
+ * emf_mailbox_t mailbox;
+ * emf_mail_info_t *mail_info = NULL;
+ * int mail_id = 0,account_id = 0;
+ * int err = EMF_ERROR_NONE;
+ *
+ * memset(&mailbox, 0x00, sizeof(emf_mailbox_t));
+ *
+ * printf("\n > Enter Mail Id: ");
+ * scanf("%d", &mail_id);
+ * printf("\n > Enter account Id: ");
+ * scanf("%d", &account_id);
+ * mailbox.account_id = account_id;
+ * if (EMF_ERROR_NONE != email_get_info(&mailbox, mail_id, &mail_info))
+ * printf("email_get_info failed\n");
+ * else
+ * {
+ * printf("email_get_info SUCCESS\n");
+ * //do something
+ * email_free_mail_info(&mail_info,1);
+ * }
+ *
+ * }
+ * @endcode
+ *
+ * @remarks N/A
+ */
+EXPORT_API int email_get_info(emf_mailbox_t* mailbox, int mail_id, emf_mail_info_t** info);
+
+
+/**
+
+ * @open
+ * @fn email_free_mail_info(emf_mail_info_t** info_list, int count)
+ * @brief Free allocated memroy for email infoes.
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @param[in] info_list Specifies the pointer of mail info structures.
+ * @param[in] count Specifies the number of mail infoes.
+ * @exception none
+ * @see emf_mail_info_t
+
+ * @code
+ * #include "Emf_Mapi_Message.h"
+ * bool
+ * _api_sample_free_mail_info()
+ * {
+ * emf_mailbox_t mailbox;
+ * emf_mail_info_t *mail_info = NULL;
+ * int mail_id = 0,account_id = 0;
+ * int err = EMF_ERROR_NONE;
+ *
+ * memset(&mailbox, 0x00, sizeof(emf_mailbox_t));
+ *
+ * printf("\n > Enter Mail Id: ");
+ * scanf("%d", &mail_id);
+ * printf("\n > Enter account Id: ");
+ * scanf("%d", &account_id);
+ * mailbox.account_id = account_id;
+ * if (EMF_ERROR_NONE != email_get_info(&mailbox, mail_id, &mail_info))
+ * printf("email_get_info failed\n");
+ * else
+ * {
+ * printf("email_get_info SUCCESS\n");
+ * //do something
+ * email_free_mail_info(&mail_info,1);
+ * }
+ * }
+ * @endcode
+ * @remarks N/A
+ */
+EXPORT_API int email_free_mail_info(emf_mail_info_t** info_list, int count);
+
+
+/**
+
+ * @open
+ * @fn email_get_header_info(emf_mailbox_t* mailbox, int mail_id, emf_mail_head_t** head)
+ * @brief Get a mail head.This function is invoked when user wants to get the header information of mail.
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @param[in] mailbox Reserved.
+ * @param[in] mail_id Specifies the mail ID.
+ * @param[out] head The returned info of mail is saved here.
+ * @exception none
+ * @see emf_mailbox_t and emf_mail_head_t
+
+ * @code
+ * #include "Emf_Mapi_Message.h"
+ * bool
+ * _api_sample_mail_get_header_info()
+ * {
+ * emf_mailbox_t mailbox;
+ * emf_mail_head_t *mail_head = NULL;
+ * int mail_id = 0,account_id = 0;
+ * int err = EMF_ERROR_NONE;
+ *
+ * memset(&mailbox, 0x00, sizeof(emf_mailbox_t));
+ *
+ * printf("\n > Enter Mail Id: ");
+ * scanf("%d", &mail_id);
+ * printf("\n > Enter account Id: ");
+ * scanf("%d", &account_id);
+ * mailbox.account_id = account_id;
+ * if (EMF_ERROR_NONE != email_get_header_info(&mailbox, mail_id, &mail_head))
+ * printf("email_get_header_info failed\n");
+ * else
+ * {
+ * printf("email_get_header_info SUCCESS\n");
+ * //do something
+ * email_free_header_info(&mail_header,1);
+ * }
+ * }
+ * @endcode
+ * @remarks N/A
+ */
+EXPORT_API int email_get_header_info(emf_mailbox_t* mailbox, int mail_id, emf_mail_head_t** head);
+
+
+/**
+
+ * @open
+ * @fn email_free_header_info(emf_mail_head_t** head_list, int count)
+ * @brief Free allocated memroy for email headers.
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @param[in] head_list Specifies the pointer of mail head structure list.
+ * @param[in] count Specifies the number of mail heads.
+ * @exception none
+ * @see emf_mail_head_t
+
+ * @code
+ * #include "Emf_Mapi_Message.h"
+ * bool
+ * _api_sample_mail_free_header_info()
+ * {
+ * emf_mailbox_t mailbox;
+ * emf_mail_head_t *mail_head = NULL;
+ * int mail_id = 0,account_id = 0;
+ * int err = EMF_ERROR_NONE;
+ *
+ * memset(&mailbox, 0x00, sizeof(emf_mailbox_t));
+ *
+ * printf("\n > Enter Mail Id: ");
+ * scanf("%d", &mail_id);
+ * printf("\n > Enter account Id: ");
+ * scanf("%d", &account_id);
+ * mailbox.account_id = account_id;
+ * if (EMF_ERROR_NONE != email_get_header_info(&mailbox, mail_id, &mail_head))
+ * printf("email_get_header_info failed\n");
+ * else
+ * {
+ * printf("email_get_header_info SUCCESS\n");
+ * //do something
+ * email_free_header_info(&mail_header,1);
+ * }
+ * }
+ * @endcode
+ * @remarks N/A
+ */
+EXPORT_API int email_free_header_info(emf_mail_head_t** head_list, int count);
+
+
+
+/**
+
+ * @open
+ * @fn email_get_body_info(emf_mailbox_t* mailbox, int mail_id, emf_mail_body_t** body)
+ * @brief Get a mail body.This function is invoked when user wants to get email body information.
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @param[in] mailbox Reserved.
+ * @param[in] mail_id Specifies the mail ID.
+ * @param[out] body The returned body of mail is saved here.
+ * @exception none
+ * @see emf_mailbox_t and emf_mail_body_t
+
+ * @code
+ * #include "Emf_Mapi_Message.h"
+ * bool
+ * _api_sample_mail_get_body_info()
+ * {
+ * emf_mailbox_t mailbox;
+ * emf_mail_body_t *mail_body = NULL;
+ * int mail_id = 0,account_id = 0;
+ * int err = EMF_ERROR_NONE;
+ *
+ * memset(&mailbox, 0x00, sizeof(emf_mailbox_t));
+ *
+ * printf("\n > Enter Mail Id: ");
+ * scanf("%d", &mail_id);
+ * printf("\n > Enter account Id: ");
+ * scanf("%d", &account_id);
+ * mailbox.account_id = account_id;
+ * if (EMF_ERROR_NONE != email_get_body_info(&mailbox, mail_id, &mail_body))
+ * printf("email_get_body_info failed\n");
+ * else
+ * {
+ * printf("email_get_body_info SUCCESS\n");
+ * //do something
+ * email_free_body_info(&mail_body,1);
+ * }
+ * }
+ * @endcode
+ * @remarks N/A
+ */
+EXPORT_API int email_get_body_info(emf_mailbox_t* mailbox, int mail_id, emf_mail_body_t** body);
+
+
+
+/**
+
+ * @open
+ * @fn email_free_body_info(emf_mail_body_t** body_list, int count)
+ * @brief Free allocated memroy for email bodies.
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @param[in] body_list Specifies the pointer of mail body structures.
+ * @param[in] count Specifies the number of mail bodies.
+ * @exception none
+ * @see emf_mail_body_t
+
+ * @code
+ * #include "Emf_Mapi_Message.h"
+ * bool
+ * _api_sample_mail_free_body_info()
+ * {
+ * emf_mailbox_t mailbox;
+ * emf_mail_body_t *mail_body = NULL;
+ * int mail_id = 0,account_id = 0;
+ * int err = EMF_ERROR_NONE;
+ *
+ * memset(&mailbox, 0x00, sizeof(emf_mailbox_t));
+ *
+ * printf("\n > Enter Mail Id: ");
+ * scanf("%d", &mail_id);
+ * printf("\n > Enter account Id: ");
+ * scanf("%d", &account_id);
+ * mailbox.account_id = account_id;
+ * if (EMF_ERROR_NONE != email_get_body_info(&mailbox, mail_id, &mail_body))
+ * printf("email_get_body_info failed\n");
+ * else
+ * {
+ * printf("email_get_body_info SUCCESS\n");
+ * //do something
+ * email_free_body_info(&mail_body,1);
+ * }
+ * }
+ * @endcode
+ * @remarks N/A
+ */
+EXPORT_API int email_free_body_info(emf_mail_body_t** body_list, int count);
+
+
+
+/**
+
+ * @open
+ * @fn email_get_attachment_info(emf_mailbox_t* mailbox, int mail_id, const char* attachment_id, emf_attachment_info_t** attachment)
+ * @brief Get a mail attachment.This function is invoked when user wants to get the attachment information based on attachment id for the specified mail Id.
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @param[in] mailbox Reserved.
+ * @param[in] mail_id Specifies the mail ID.
+ * @param[in] attachment_id Specifies the buffer that a attachment ID been saved.
+ * @param[out] attachment The returned attachment is save here.
+ * @exception none
+ * @see emf_mailbox_t and emf_mail_attachment_info_t
+
+ * @code
+ * #include "Emf_Mapi_Message.h"
+ * bool
+ * _api_sample_mail_get_attachment_info()
+ * {
+ * emf_mailbox_t mailbox;
+ * emf_mail_attachment_info_t *mail_attach_info = NULL;
+ * int mail_id = 0,account_id = 0;
+ * char arg[10];
+ * int err = EMF_ERROR_NONE;
+ *
+ * memset(&mailbox, 0x00, sizeof(emf_mailbox_t));
+ *
+ * printf("\n > Enter Mail Id: ");
+ * scanf("%d", &mail_id);
+ * printf("\n > Enter account Id: ");
+ * scanf("%d", &account_id);
+ * printf("> attachment Id\n");
+ * scanf("%s",arg);
+ * mailbox.account_id = account_id;
+ * if (EMF_ERROR_NONE != email_get_attachment_info(&mailbox, mail_id, &mail_attach_info))
+ * printf("email_get_attachment_info failed\n");
+ * else
+ * {
+ * printf("email_get_attachment_info SUCCESS\n");
+ * //do something
+ * email_free_attachment_info(&mail_attach_info,1);
+ * }
+ * }
+ * @endcode
+ * @remarks N/A
+ */
+EXPORT_API int email_get_attachment_info(emf_mailbox_t* mailbox, int mail_id, const char* attachment_id, emf_attachment_info_t** attachment);
+
+EXPORT_API int email_get_attachment_data_list(int input_mail_id, emf_attachment_data_t **output_attachment_data, int *output_attachment_count);
+
+/**
+
+ * @open
+ * @fn email_free_attachment_info(emf_attachment_info_t** atch_info)
+ * @brief Free allocated memroy for email attachment.
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @param[in] atch_info Specifies the pointer of mail attachment structure pointer.
+ * @exception none
+ * @see emf_mail_attachment_info_t
+
+ * @code
+ * #include "Emf_Mapi_Message.h"
+ * bool
+ * _api_sample_mail_free_attachment_info()
+ * {
+ * emf_mailbox_t mailbox;
+ * emf_mail_attachment_info_t *mail_attach_info = NULL;
+ * int mail_id = 0,account_id = 0;
+ * char arg[10];
+ * int err = EMF_ERROR_NONE;
+ *
+ * memset(&mailbox, 0x00, sizeof(emf_mailbox_t));
+ *
+ * printf("\n > Enter Mail Id: ");
+ * scanf("%d", &mail_id);
+ * printf("\n > Enter account Id: ");
+ * scanf("%d", &account_id);
+ * printf("> attachment Id\n");
+ * scanf("%s",arg);
+ * mailbox.account_id = account_id;
+ * if (EMF_ERROR_NONE != email_get_attachment_info(&mailbox, mail_id, &mail_attach_info))
+ * printf("email_get_attachment_info failed\n");
+ * else
+ * {
+ * printf("email_get_attachment_info SUCCESS\n");
+ * //do something
+ * email_free_attachment_info(&mail_attach_info,1);
+ * }
+ * }
+ * @endcode
+ * @remarks N/A
+ */
+EXPORT_API int email_free_attachment_info(emf_attachment_info_t** atch_info);
+
+EXPORT_API int email_free_attachment_data(emf_attachment_data_t **attachment_data_list, int attachment_data_count);
+
+
+/**
+
+ * @open
+ * @fn email_get_mail(emf_mailbox_t* mailbox, int mail_id, emf_mail_t** mail)
+ * @brief Get a mail from mailbox.This function is invoked when user wants to get a mail based on mail Id existing in DB.
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @param[in] mailbox Reserved.
+ * @param[in] mail_id Specifies the mail ID.
+ * @param[out] mail The returned mail is save here.
+ * @exception none
+ * @see emf_mailbox_t and emf_mail_t
+
+ * @code
+ * #include "Emf_Mapi_Message.h"
+ * bool
+ * _api_sample_get_mail_()
+ * {
+ * emf_mailbox_t mailbox;
+ * emf_mail_t *mail = NULL;
+ * int mail_id = 0 ;
+ * int err = EMF_ERROR_NONE;
+ *
+ * memset(&mailbox, 0x00, sizeof(emf_mailbox_t));
+ *
+ * printf("\n > Enter Mail Id: ");
+ * scanf("%d", &mail_id);
+ *
+ * if (EMF_ERROR_NONE != email_get_mail(&mailbox, mail_id, &mail))
+ * printf("email_get_mail failed\n");
+ * else
+ * {
+ * printf("email_get_mail SUCCESS\n");
+ * //do something
+ * email_free_mail(&mail,1);
+ * }
+ * }
+ * @endcode
+ * @remarks N/A
+ */
+EXPORT_API int email_get_mail(emf_mailbox_t* mailbox, int mail_id, emf_mail_t** mail);
+
+
+/**
+
+ * @open
+ * @fn email_get_mail_data(int input_mail_id, emf_mail_data_t **output_mail_data)
+ * @brief Get a mail by its mail id. This function is invoked when user wants to get a mail based on mail id existing in DB.
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @param[in] input_mail_id specifies the mail id.
+ * @param[out] output_mail_data The returned mail is save here.
+ * @exception none
+ * @see emf_mail_data_t
+
+ * @code
+ * #include "Emf_Mapi_Message.h"
+ * bool
+ * _api_sample_get_mail_data()
+ * {
+ * emf_mail_data_t *mail = NULL;
+ * int mail_id = 0 ;
+ * int err = EMF_ERROR_NONE;
+ *
+ * printf("\n > Enter mail id: ");
+ * scanf("%d", &mail_id);
+ *
+ * if (EMF_ERROR_NONE != email_get_mail_data(mail_id, &mail))
+ * printf("email_get_mail_data failed\n");
+ * else
+ * {
+ * printf("email_get_mail_data SUCCESS\n");
+ * //do something
+ * email_free_mail_data(&mail,1);
+ * }
+ * }
+ * @endcode
+ * @remarks N/A
+ */
+
+EXPORT_API int email_get_mail_data(int input_mail_id, emf_mail_data_t **output_mail_data);
+
+
+/* -----------------------------------------------------------
+ Mail Flag API
+ -----------------------------------------------------------*/
+
+/**
+
+ * @open
+ * @fn email_modify_mail_flag(int mail_id, emf_mail_flag_t new_flag, int onserver)
+ * @brief Change email flag.[ Seen,Deleted,flagged,answered,recent,draft,has_attachment,reserved_1]
+ * If the receiving_server_type is EMF_SERVER_TYPE_POP3 then from_server value will be 0
+ * If the receiving_server_type is EMF_SERVER_TYPE_IMAP4 then from_server value will be 1/0
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @param[in] mail_id Specifies the mail ID.
+ * @param[in] new_flag Specifies the new email flag.
+ * @param[in] onserver Specifies whether mail Flag updation in server
+ * @exception none
+ * @see emf_mail_flag_t
+
+ * @code
+ * #include "Emf_Mapi_Message.h"
+ * bool
+ * _api_sample_modify_mail_flag()
+ * {
+ * emf_mail_flag_t newflag;
+ * int mail_id = 0;
+ * int err = EMF_ERROR_NONE;
+ *
+ * memset(&newflag, 0x00, sizeof(emf_mail_flag_t));
+ * newflag.seen = 1;
+ * newflag.answered = 0;
+ * newflag.sticky = 1;
+ *
+ * printf("\n > Enter Mail Id: ");
+ * scanf("%d", &mail_id);
+ * if (EMF_ERROR_NONE != email_modify_mail_flag(mail_id, newflag, 1))
+ * printf("email_modify_mail_flag failed\n");
+ * else
+ * {
+ * printf("email_modify_mail_flag SUCCESS\n");
+ * //do something
+ *
+ * }
+ * }
+ * @endcode
+ * @remarks N/A
+ */
+EXPORT_API int email_modify_mail_flag(int mail_id, emf_mail_flag_t new_flag, int onserver);
+
+
+/* email_modify_seen_flag would be replaced with email_set_flags_field */
+EXPORT_API int email_modify_seen_flag(int *mail_ids, int num, int seen_flag, int onserver) DEPRECATED;
+
+/**
+ * @open
+ * @fn email_set_flags_field(int *mail_ids, int num, emf_flags_field_type field_type, int value, int onserver)
+ * @brief Change email flags field.
+ * If the receiving_server_type is EMF_SERVER_TYPE_POP3 then from_server value will be 0
+ * If the receiving_server_type is EMF_SERVER_TYPE_IMAP4 then from_server value will be 1/0
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @param[in] account_id Specifies account ID.
+ * @param[in] mail_ids Specifies the array of mail ID.
+ * @param[in] num Specifies the number of mail ID.
+ * @param[in] field_type Specifies the field type what you want to set. Refer emf_flags_field_type.
+ * @param[in] value Specifies the value what you want to set.
+ * @param[in] onserver Specifies whether mail Flag updation in server
+ * @exception none
+ * @see none
+ * @code
+ * #include "Emf_Mapi_Message.h"
+ * bool
+ * _api_sample_set_flags_field()
+ * {
+ * int mail_id = 0;
+ * int err = EMF_ERROR_NONE;
+ *
+ * printf("\n > Enter Mail Id: ");
+ * scanf("%d", &mail_id);
+ * if (EMF_ERROR_NONE != email_set_flags_field(&mail_id, EMFF_LAGS_SEEN_FIELD, 1, 0))
+ * printf("email_set_flags_field failed\n");
+ * else
+ * {
+ * printf("email_set_flags_field SUCCESS\n");
+ * //do something
+ * }
+ * }
+ * @endcode
+ * @remarks N/A
+ */
+
+EXPORT_API int email_set_flags_field(int account_id, int *mail_ids, int num, emf_flags_field_type field_type, int value, int onserver);
+
+/**
+
+ * @open
+ * @fn email_modify_extra_mail_flag(int mail_id, emf_extra_flag_t new_flag)
+ * @brief Change email extra flag.[priority,Delivery report status, Drm, Protection etc]
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @param[in] mail_id Specifies the mail ID.
+ * @param[in] new_flag Specifies the new email extra flag.
+ * @exception none
+ * @see emf_extra_flag_t
+
+ * @code
+ * #include "Emf_Mapi_Message.h"
+ * bool
+ * _api_sample_modify_extra_mail_flag()
+ * {
+ * emf_extra_flag_t newflag;
+ * int mail_id = 0;
+ * int err = EMF_ERROR_NONE;
+ *
+ * memset(&newflag, 0x00, sizeof(emf_extra_flag_t));
+ *
+ * printf("\n > Enter Mail Id: ");
+ * scanf("%d", &mail_id);
+ *
+ * if(EMF_ERROR_NONE != email_modify_extra_mail_flag(mail_id, newflag))
+ * printf("email_modify_extra_mail_flag failed");
+ * else
+ * printf("email_modify_extra_mail_flag success");
+ *
+ * }
+ * @endcode
+ * @remarks N/A
+ */
+EXPORT_API int email_modify_extra_mail_flag(int mail_id, emf_extra_flag_t new_flag);
+
+
+
+/* -----------------------------------------------------------
+ Mail Move API
+ -----------------------------------------------------------*/
+
+/**
+ * @open
+ * @fn email_move_mail_to_mailbox(int *mail_ids, int num, emf_mailbox_t* new_mailbox)
+ * @brief Move a email to another mailbox.
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @param[in] mail_id Specifies the array of mail ID.
+ * @param[in] num Specifies the count of mail IDs.
+ * @param[in] new_mailbox Specifies the mailbox structure for moving email.
+ * @exception none
+ * @see emf_mailbox_t
+
+ * @code
+ * #include "Emf_Mapi_Message.h"
+ * bool
+ * _api_sample_move_mail_to_mailbox()
+ * {
+ * int mail_id = 1;
+ * int account_id =0;
+ * emf_mailbox_t mbox;
+ * char arg[10];
+ * int err = EMF_ERROR_NONE;
+ * int i = 0;
+ *
+ * printf("\n > Enter Account_id: ");
+ * scanf("%d",&account_id);
+ *
+ * memset(&mbox, 0x00, sizeof(emf_mailbox_t));
+ *
+ * mbox.account_id = account_id;
+ * mbox.name = strdup("Test");
+ * if(EMF_ERROR_NONE == email_move_mail_to_mailbox(mail_id, 1, &mbox))
+ * printf("Success\n");
+ *
+ * }
+ * @endcode
+ * @remarks N/A
+ */
+EXPORT_API int email_move_mail_to_mailbox(int *mail_ids, int num, emf_mailbox_t* new_mailbox);
+
+
+/**
+
+ * @open
+ * @fn email_move_all_mails_to_mailbox(emf_mailbox_t* src_mailbox, emf_mailbox_t* new_mailbox)
+ * @brief Move all email to another mailbox.
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @param[in] src_mailbox Specifies the source mailbox structure for moving email.
+ * @param[in] new_mailbox Specifies the destination mailbox structure for moving email.
+ * @exception none
+ * @see emf_mailbox_t
+
+ * @code
+ * #include "Emf_Mapi_Message.h"
+ * bool
+ * _api_sample_move_all_mails_to_mailbox()
+ * {
+ * emf_mailbox_t src_mailbox;
+ * emf_mailbox_t dest_mailbox;
+ * int total_count;
+ * int err = EMF_ERROR_NONE;
+ * char temp[128];
+ *
+ * memset(&src_mailbox, 0x00, sizeof(emf_mailbox_t));
+ * memset(&dest_mailbox, 0x00, sizeof(emf_mailbox_t));
+ *
+ * // input mailbox information : need account_id and name (src & dest)
+ * printf("src mail account id(0: All account)> ");
+ * scanf("%d", &src_mailbox.account_id);
+ * printf("src mailbox_name(0 : NULL)> ");
+ * src_mailbox = strdup("INBOX");
+ * // Destination mailbox
+ * printf("dest mail account id> ");
+ * scanf("%d", &dest_mailbox.account_id);
+ * printf("dest_mailbox_name(0 : NULL)> ");
+ * dest_mailbox = strdup("INBOX");
+ *
+ * ( EMF_ERROR_NONE == email_move_all_mails_to_mailbox(&src_mailbox, &dest_mailbox))
+ * {
+ * printf(" fail email_move_all_mails_to_mailbox: \n");
+ * }
+ * else
+ * //success
+ * if ( src_mailbox)
+ * {
+ * free(src_mailbox);
+ * }
+ * if ( dest_mailbox )
+ * {
+ * free(dest_mailbox);
+ * }
+ * }
+ * @endcode
+ * @remarks N/A
+ */
+EXPORT_API int email_move_all_mails_to_mailbox(emf_mailbox_t* src_mailbox, emf_mailbox_t* new_mailbox);
+
+
+/**
+
+ * @open
+ * @fn email_count_message_with_draft_flag(emf_mailbox_t* mailbox, int* total)
+ * @brief Get mail count from mailbox having draft flag.
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @param[in] mailbox Specifies the pointer of mailbox structure.
+ * @param[out] total Total email count is saved with draft flag enabled.
+ * @exception none
+ * @see emf_mailbox_t
+
+ * @code
+ * #include "Emf_Mapi_Message.h"
+ * bool
+ * _api_sample_count_message_with_draft_flag()
+ * {
+ * emf_mailbox_t mailbox;
+ * int total_count;
+ * int err = EMF_ERROR_NONE;
+ *
+ * memset(&mailbox, 0x00, sizeof(emf_mailbox_t));
+ * // input mailbox information : need account_id and name
+ * printf("mail account id(0: All account)> ");
+ * scanf("%d", &mailbox.account_id);
+ * mailbox.name = strdup("Inbox");
+ * if ( EMF_ERROR_NONE != email_count_message_with_draft_flag(&mailbox, &total_count))
+ * {
+ * printf(" fail email_count_message_with_draft_flag:\n);
+ * }
+ * else
+ * {
+ * printf(" success email_count_message_with_draft_flag:\n);
+ * }
+ * if ( mailbox.name )
+ * {
+ * free(mailbox.name);
+ * }
+ * }
+ * @endcode
+ * @remarks N/A
+ */
+EXPORT_API int email_count_message_with_draft_flag(emf_mailbox_t* mailbox, int* total);
+
+
+/**
+
+ * @open
+ * @fn email_count_message_on_sending(emf_mailbox_t* mailbox, int* total)
+ * @brief Get the number of mails which are being sent in specific mailbox.This function gives the list of mails having on sending status for a given mailbox.
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @param[in] mailbox Specifies the pointer of mailbox structure.
+ * @param[out] total Total email count is saved with draft flag enabled.
+ * @exception none
+ * @see emf_mailbox_t
+
+ * @code
+ * #include "Emf_Mapi_Message.h"
+ * bool
+ * _api_sample_count_message_on_sending()
+ * {
+ * emf_mailbox_t mailbox;
+ * int total_count;
+ * int err = EMF_ERROR_NONE;
+ *
+ * memset(&mailbox, 0x00, sizeof(emf_mailbox_t));
+ * // input mailbox information : need account_id and name
+ * printf("mail account id(0: All account)> ");
+ * scanf("%d", &mailbox.account_id);
+ * mailbox.name = strdup("Draft");
+ * if (EMF_ERROR_NONE != email_count_message_on_sending(&mailbox, &total_count))
+ * {
+ * printf(" fail email_count_message_on_sending: \n");
+ * }
+ * else
+ * {
+ * printf(" success email_count_message_on_sending:\n");
+ * }
+ * if ( mailbox.name )
+ * {
+ * free(mailbox.name);
+ * }
+ * }
+ * @endcode
+ * @remarks N/A
+ */
+EXPORT_API int email_count_message_on_sending(emf_mailbox_t* mailbox, int* total);
+
+/**
+
+ * @open
+ * @fn email_free_mailbox(emf_mailbox_t** mailbox_list, int count)
+ * @brief Free allocated memory for mailbox information.
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @param[in] mailbox_list Specifies the pointer for searching mailbox structure pointer.
+ * @param[in] count Specifies the count of mailboxes.
+ * @exception none
+ * @see emf_mailbox_t
+
+ * @code
+ * #include "Emf_Mapi_Message.h"
+ * bool
+ * _api_sample_free_mailbox_info()
+ * {
+ * emf_mailbox_t *mailbox;
+ *
+ * //fill the mailbox structure
+ * //count - number of mailbox structure user want to free
+ * if(EMF_ERROR_NONE == email_free_mailbox(&mailbox,count))
+ * //success
+ * else
+ * //failure
+ *
+ * }
+ * @endcode
+ * @remarks N/A
+ */
+
+EXPORT_API int email_free_mailbox(emf_mailbox_t** mailbox_list, int count);
+
+
+/**
+
+ * @open
+ * @fn email_free_mail(emf_mail_t** mail_list, int count)
+ * @brief Free allocated memroy for emails.
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @param[in] mail_list Specifies the pointer of mail structure pointer.
+ * @param[in] count Specifies the count of mails.
+ * @exception none
+ * @see emf_mail_t
+
+ * @code
+ * #include "Emf_Mapi_Message.h"
+ * bool
+ * _api_sample_free_mail()
+ * {
+ * emf_mail_t *mail;
+ *
+ * //fill the mail structure
+ * //count - number of mail structure user want to free
+ * if(EMF_ERROR_NONE == email_free_mail(&mail,count))
+ * //success
+ * else
+ * //failure
+ *
+ * }
+ * @endcode
+ * @remarks N/A
+ */
+
+EXPORT_API int email_free_mail(emf_mail_t** mail_list, int count);
+
+/**
+
+ * @open
+ * @fn email_free_mail_data(emf_mail_data_t** mail_list, int count)
+ * @brief Free allocated memroy for emails.
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @param[in] mail_list Specifies the pointer of mail structure pointer.
+ * @param[in] count Specifies the count of mails.
+ * @exception none
+ * @see emf_mail_data_t
+
+ * @code
+ * #include "Emf_Mapi_Message.h"
+ * bool
+ * _api_sample_free_mail()
+ * {
+ * emf_mail_data_t *mail;
+ *
+ * //fill the mail structure
+ * //count - number of mail structure user want to free
+ * if(EMF_ERROR_NONE == email_free_mail_data(&mail,count))
+ * //success
+ * else
+ * //failure
+ *
+ * }
+ * @endcode
+ * @remarks N/A
+ */
+EXPORT_API int email_free_mail_data(emf_mail_data_t** mail_list, int count);
+
+/**
+
+ * @open
+ * @fn email_get_mails(int account_id , const char *mailbox_name, int thread_id, int start_index, int limit_count, emf_sort_type_t sorting, emf_mail_data_t** mail_list, int* result_count)
+ * @brief Get the Mail List information from DB based on the mailbox name.
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @param[in] account_id Specifies the account ID
+ * @param[in] mailbox_name Specifies the mailbox name
+ * @param[in] thread_id Specifies the thread id. It can be EMF_LIST_TYPE_THREAD, EMF_LIST_TYPE_NORMAL or thread id.
+ * @param[in] start_index Specifies start index for LIMIT clause of SQL query.
+ * @param[in] limit_count Specifies limit count for LIMIT clause of SQL query.
+ * @param[in] sorting Specifies the sorting type.
+ * @param[in/out] mail_list Specifies the pointer to the structure emf_mail_data_t.
+ * @param[in/out] result_count Specifies the number of mails returned.
+ * @exception none
+ * @see emf_mail_data_t
+
+ * @code
+ * #include "Emf_Mapi_Message.h"
+ * bool
+ * _api_sample_get_mail()
+ * {
+ * emf_mail_data_t *mail_list = NULL;
+ * char mailbox_name[50];
+ * int result_count = 0;
+ * int account_id = 0;
+ * int err_code = EMF_ERROR_NONE;
+ *
+ * memset(mailbox_name, 0x00, 10);
+ * printf("\n > Enter Mailbox name: ");
+ * scanf("%s", mailbox_name);
+ *
+ * printf("\n > Enter Account_id: ");
+ * scanf("%d",&account_id);
+ *
+ * if (EMF_ERROR_NONE != email_get_mails(account_id, mailbox_name, EMF_LIST_TYPE_NORMAL, 0, 100, EMF_SORT_DATETIME_HIGH, &mail_list, &result_count)) {
+ * printf("email_get_mails failed \n");
+ * }
+ * else {
+ * printf("Success\n");
+ * //do something
+ * free(mail_list);
+ * }
+ *
+ * }
+ * @endcode
+ * @remarks N/A
+ */
+
+EXPORT_API int email_get_mails(int account_id , const char *mailbox_name, int thread_id, int start_index, int limit_count, emf_sort_type_t sorting, emf_mail_data_t** mail_list, int* result_count);
+
+/**
+
+ * @open
+ * @fn email_get_mail_list_ex(int account_id , const char *mailbox_name, int thread_id, int start_index, int limit_count, emf_sort_type_t sorting, emf_mail_list_item_t** mail_list, int* result_count)
+ * @brief Get the Mail List information from DB based on the mailbox name.
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @param[in] account_id Specifies the account ID
+ * @param[in] mailbox_name Specifies the mailbox name
+ * @param[in] thread_id Specifies the thread id. It can be EMF_LIST_TYPE_THREAD, EMF_LIST_TYPE_NORMAL or thread id.
+ * @param[in] start_index Specifies start index for LIMIT clause of SQL query.
+ * @param[in] limit_count Specifies limit count for LIMIT clause of SQL query.
+ * @param[in] sorting Specifies the sorting type.
+ * @param[in/out] mail_list Specifies the pointer to the structure emf_mail_list_item_t.
+ * @param[in/out] result_count Specifies the number of mails returned.
+ * @exception none
+ * @see emf_mail_list_item_t
+
+ * @code
+ * #include "Emf_Mapi_Message.h"
+ * bool
+ * _api_sample_get_mail()
+ * {
+ * emf_mail_list_item_t *mail_list = NULL;
+ * char mailbox_name[50];
+ * int result_count = 0;
+ * int account_id = 0;
+ * int err_code = EMF_ERROR_NONE;
+ *
+ * memset(mailbox_name, 0x00, 10);
+ * printf("\n > Enter Mailbox name: ");
+ * scanf("%s", mailbox_name);
+ *
+ * printf("\n > Enter Account_id: ");
+ * scanf("%d",&account_id);
+ *
+ * if (EMF_ERROR_NONE != email_get_mail_list_ex(account_id, mailbox_name, EMF_LIST_TYPE_NORMAL, 0, 100, EMF_SORT_DATETIME_HIGH, &mail_list, &result_count))
+ * {
+ * printf("email_get_mail_list failed \n");
+ * }
+ * else
+ * {
+ * printf("Success\n");
+ * //do something
+ * free(mail_list);
+ * }
+ *
+ * }
+ * @endcode
+ * @remarks N/A
+ */
+EXPORT_API int email_get_mail_list_ex(int account_id , const char *mailbox_name, int thread_id, int start_index, int limit_count, emf_sort_type_t sorting, emf_mail_list_item_t** mail_list, int* result_count);
+
+/**
+ * @open
+ * @fn email_find_mail(int account_id , const char *mailbox_name, int thread_id,
+ int search_type, char *search_value, int start_index, int limit_count, emf_sort_type_t sorting, emf_mail_list_item_t** mail_list, int* result_count)
+ * @brief Get the Searched Mail List information from the DB based on the mailbox name account_id, type and value of searching.
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @param[in] account_id Specifies the Account ID
+ * @param[in] mailbox_name Specifies the Mailbox Name
+ * @param[in] thread_id Specifies the thread_id. If thread_id = EMF_LIST_TYPE_NORMAL, search a mail without regarding thread. The case of thread_id > 0 is for getting mail list of specific thread.
+ * @param[in] search_type Specifies the searching type(EMF_SEARCH_FILTER_SUBJECT, EMF_SEARCH_FILTER_SENDER, EMF_SEARCH_FILTER_RECIPIENT, EMF_SEARCH_FILTER_ALL)
+ * @param[in] search_value Specifies the value to use for searching. (ex : Subject, email address, display name)
+ * @param[in] start_index Specifies the first mail index of searched mail. This function will return mails whose index in the result list are from start_index to start_index + limit_count. The first start index is 0.
+ * @param[in] limit_count Specifies the max number of returned mails.
+ * @param[in] sorting Specifies the sorting order. see emf_sort_type_t
+ * @param[in/out] mail_list Specifies the Pointer to the structure emf_mail_list_item_t.
+ * @param[in/out] result_count Specifies the Number of searched Mails
+ * @exception none
+ * @see emf_sort_type_t, emf_mail_list_item_t
+ * @code
+ * @endcode
+ * @remarks N/A
+ */
+EXPORT_API int email_find_mail(int account_id , const char *mailbox_name, int thread_id,
+ int search_type, char *search_value,
+ int start_index, int limit_count, emf_sort_type_t sorting, emf_mail_list_item_t** mail_list, int* result_count);
+
+/**
+ * @open
+ * @fn email_get_mail_by_address(int account_id , const char *mailbox_name, emf_email_address_list_t* addr_list,
+ int start_index, int limit_count, emf_sort_type_t sorting, emf_mail_list_item_t** mail_list, int* result_count)
+ * @brief Get the Mail List information from the DB based on the mailbox name account_id and sender address.
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @param[in] account_id Specifies the Account ID
+ * @param[in] mailbox_name Specifies the Mailbox Name
+ * @param[in] addr_list Specifies the addresses of senders. see emf_email_address_list_t
+ * @param[in] start_index Specifies the first mail index of searched mail. This function will return mails whose index in the result list are from start_index to start_index + limit_count
+ * @param[in] limit_count Specifies the max number of returned mails.
+ * @param[in] search_type Specifies the search type.
+ * @param[in] search_value Specifies the search value.
+ * @param[in] sorting Specifies the sorting order. see emf_sort_type_t
+ * @param[in/out] mail_list Specifies the Pointer to the structure emf_mail_list_item_t.
+ * @param[in/out] result_count Specifies the Number of searched Mails
+ * @exception none
+ * @see emf_email_address_list_t, emf_sort_type_t, emf_mail_list_item_t
+ * @code
+ * @endcode
+ * @remarks N/A
+ */
+EXPORT_API int email_get_mail_by_address(int account_id , const char *mailbox_name, emf_email_address_list_t* addr_list,
+ int start_index, int limit_count, int search_type, const char *search_value, emf_sort_type_t sorting, emf_mail_list_item_t** mail_list, int* result_count);
+
+/**
+ * @open
+ * @fn email_get_thread_information_by_thread_id(int thread_id, emf_mail_data_t** thread_info)
+ * @brief Get the thread information for specific thread from DB based on the mailbox name.
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @param[in] thread_id Specifies the thread_id
+ * @param[in/out] thread_info Specifies the Pointer to the structure emf_mail_data_t.
+ * @exception none
+ * @see emf_mail_data_t
+
+ * @code
+ * #include "Emf_Mapi_Message.h"
+ * bool
+ * _api_sample_get_thread_information()
+ * {
+ * emf_mail_data_t *thread_info = NULL;
+ * int thread_id = 0;
+ * int err_code = EMF_ERROR_NONE;
+ *
+ * printf("\n > Enter thread_id: ");
+ * scanf("%d",&thread_id);
+ *
+ * if ( EMF_ERROR_NONE != email_get_thread_information_by_thread_id(thread_id, &thread_info))
+ * {
+ * printf("email_get_thread_information_by_thread_id failed :\n"); *
+ * }
+ * else
+ * {
+ * printf("Success\n");
+ * //do something
+ * }
+ *
+ * }
+ * @endcode
+ * @remarks N/A
+ */
+
+
+EXPORT_API int email_get_thread_information_by_thread_id(int thread_id, emf_mail_data_t** thread_info);
+
+/**
+ * @open
+ * @fn email_get_thread_information_ex(int thread_id, emf_mail_list_item_t** thread_info)
+ * @brief Get the Mail List information for specific thread from DB based on the mailbox name.
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @param[in] thread_id Specifies the thread_id
+ * @param[in/out] thread_info Specifies the Pointer to the structure emf_mail_list_item_t.
+ * @exception none
+ * @see emf_mail_list_item_t
+
+ * @code
+ * #include "Emf_Mapi_Message.h"
+ * bool
+ * _api_sample_get_thread_information_ex()
+ * {
+ * emf_mail_list_item_t *thread_info = NULL;
+ * int thread_id = 0;
+ * int err_code = EMF_ERROR_NONE;
+ *
+ * printf("\n > Enter thread_id: ");
+ * scanf("%d",&thread_id);
+ *
+ * if ( EMF_ERROR_NONE != email_get_thread_information_ex(thread_id, &thread_info))
+ * {
+ * printf("email_get_mail_list_of_thread failed :\n"); *
+ * }
+ * else
+ * {
+ * printf("Success\n");
+ * //do something
+ * }
+ *
+ * }
+ * @endcode
+ * @remarks N/A
+ */
+EXPORT_API int email_get_thread_information_ex(int thread_id, emf_mail_list_item_t** thread_info);
+
+/**
+ * @open
+ * @fn email_get_mail_flag(int account_id, int mail_id, emf_mail_flag_t* mail_flag)
+ * @brief Get the Mail Flag information based on the account id and Mail Id.
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @param[in] account_id Specifies the Account ID
+ * @param[in] mail_id Specifies the Mail id for which Flag details need to be fetched
+ * @param[in/out] mail_flag Specifies the Pointer to the structure emf_mail_flag_t.
+ * @exception none
+ * @see emf_mail_flag_t
+
+ * @code
+ * #include "Emf_Mapi_Message.h"
+ * bool
+ * _api_sample_get_mail_flag()
+ * {
+ * emf_mail_flag_t *mail_flag = NULL;
+ * int account_id = 0;
+ * int mail_id = 0;
+ * int err_code = EMF_ERROR_NONE;
+ *
+ * printf("\n > Enter account_id: ");
+ * scanf("%d",&account_id);
+ * printf("\n > Enter mail_id: ");
+ * scanf("%d",&mail_id);
+ *
+ * if ( EMF_ERROR_NONE != email_get_mail_flag(account_id,mail_id, &mail_flag))
+ * {
+ * printf("email_get_mail_flag failed :\n");
+ * }
+ * else
+ * {
+ * printf("Success\n");
+ * //do something
+ * }
+ *
+ * }
+ * @endcode
+ * @remarks N/A
+ */
+EXPORT_API int email_get_mail_flag(int account_id, int mail_id, emf_mail_flag_t* mail_flag);
+
+/**
+
+ * @open
+ * @fn email_retry_send_mail( int mail_id, int timeout_in_sec)
+ * @brief Retry mail send
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @param[in] mail_id Specifies the mail id for the mail to resend
+ * @param[in] timeout_in_sec Specifies the timeout value in seconds
+ * @exception none
+ * @see none
+
+ * @code
+ * #include "Emf_Mapi_Message.h"
+ * bool
+ * _api_sample_retry_send_mail()
+ * {
+ * int mail_id = 1;
+ * int timeout_in_sec = 2;
+ *
+ * if(EMF_ERROR_NONE == email_retry_send_mail(mail_id,timeout_in_sec))
+ * //success
+ * else
+ * //failure
+ *
+ * }
+ * @endcode
+ * @remarks N/A
+ */
+EXPORT_API int email_retry_send_mail( int mail_id, int timeout_in_sec);
+
+
+/**
+
+ * @open
+ * @fn email_create_db_full()
+ * @brief Create DB full
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @exception none
+ * @see none
+
+ * @code
+ * #include "Emf_Mapi_Message.h"
+ * bool
+ * _api_sample_create_db_full()
+ * {
+ *
+ * if(EMF_ERROR_NONE == email_create_db_full())
+ * //success
+ * else
+ * //failure
+ *
+ * }
+ * @endcode
+ * @remarks N/A
+ */
+
+EXPORT_API int email_create_db_full();
+
+/**
+
+ * @open
+ * @fn email_get_mailbox_name_by_mail_id(int mail_id, char **pMailbox_name)
+ * @brief get mailBox naem by mailID
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @param[in] mail_id Specifies the mailID
+ * @param[out] pMailbox_name Specifies the mailbox name
+ * @exception none
+ * @see none
+
+ * @code
+ * #include "Emf_Mapi_Message.h"
+ * bool
+ * _api_sample_get_mailbox_name_by_mail_id()
+ * {
+ * char *mailbox_name =NULL;
+ * int mail_id = 10;
+ *
+ *
+ * if(EMF_ERROR_NONE == email_get_mailbox_name_by_mail_id(mail_id,&mailbox_name))
+ * //success
+ * else
+ * //failure
+ *
+ * }
+ * @endcode
+ * @remarks N/A
+ */
+
+EXPORT_API int email_get_mailbox_name_by_mail_id(int mail_id, char **pMailbox_name);
+
+/**
+
+ * @open
+ * @fn email_cancel_send_mail( int mail_id)
+ * @brief Callback function for cm popup. We set the status as EMF_MAIL_STATUS_SEND_CANCELED
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @param[in] mail_id Specifies the mailID
+ * @exception none
+ * @see none
+
+ * @code
+ * #include "Emf_Mapi_Message.h"
+ * bool
+ * _api_sample_cancel_send_mail()
+ * {
+ * int mail_id = 10;
+ *
+ *
+ * if(EMF_ERROR_NONE == email_cancel_send_mail(mail_id,))
+ * //success
+ * else
+ * //failure
+ *
+ * }
+ * @endcode
+ * @remarks N/A
+ */
+EXPORT_API int email_cancel_send_mail( int mail_id) ;
+
+
+/**
+
+ * @open
+ * @fn email_count_message_all_mailboxes(emf_mailbox_t* mailbox, int* total, int* unseen)
+ * @brief Get the Total count and Unread count of all mailboxes
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @param[in] mailbox Specifies the mailbox structure
+ * @param[out] total Specifies the total count
+ * @param[out] seen Specifies the unseen mail count
+ * @exception none
+ * @see emf_mailbox_t
+
+ * @code
+ * #include "Emf_Mapi_Message.h"
+ * bool
+ * _api_sample_count_message_all_mailboxes()
+ * {
+ * emf_mailbox_t mailbox;
+ * int total =0;
+ * int unseen = 0;
+ *
+ * memset(&mailbox,0x00,sizeof(emf_mailbox_t));
+ * mailbox.account_id = 0;
+ * mailbox.name = strdup("INBOX");
+ *
+ * if(EMF_ERROR_NONE == email_count_message_all_mailboxes(&mailbox,&total,&unseen))
+ * //success
+ * else
+ * //failure
+ *
+ * }
+ * @endcode
+ * @remarks N/A
+ */
+
+EXPORT_API int email_count_message_all_mailboxes(emf_mailbox_t* mailbox, int* total, int* unseen);
+
+
+/* sowmya.kr@samsung.com, 01282010 - Changes to get latest unread mail id for given account */
+/**
+
+ * @open
+ * @fn email_get_latest_unread_mail_id(int account_id, int *pMailID)
+ * @brief Gets the latest unread MailId for given account. If account_id passed is -1, returns latest unread mail Id.
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @param[in] account_id Specifies the account id for which latest unread mail has to be fetched
+ * @param[out] pMailID Specifies the latest unread mail
+ * @exception none
+ * @see none
+
+ * @code
+ * #include "Emf_Mapi_Message.h"
+ * bool
+ * _api_sample_get_latest_unread_mail_id()
+ * {
+ * int mail_id = 0,account_id = 0;
+ * int err = EMF_ERROR_NONE;
+ *
+ *
+ * printf("Enter account Id to get latest unread mail Id,<-1 to get latest irrespective of account id> ");
+ * scanf("%d", &account_id);
+ *
+ *
+ * if ( EMF_ERROR_NONE != email_get_latest_unread_mail_id(account_id, &mail_id) )
+ * {
+ * printf(" fail email_get_latest_unread_mail_id: err[%d]\n", err);
+ * }
+ * else
+ * {
+ * printf(" success email_get_latest_unread_mail_id: Latest unread mail id : %d\n", mail_id);
+ * }
+ * }
+ * @endcode
+ * @remarks N/A
+ */
+EXPORT_API int email_get_latest_unread_mail_id(int account_id, int *pMailID);
+
+
+/*------------------------------------------------------------------*/
+/* sowmya.kr@samsung.com 01152010, Changes for Backup Email feature */
+/* Backup Email feature is disabled */
+/*
+int EmfBackupToMailFile(int mail_id, int* err_code);
+
+int EmfGetBackupMailHeaderInfo(char *backup_mail_filePath, emf_mail_head_t** head,int* err_code);
+
+int EmfGetBackupMail(char *backup_mail_filePath,emf_mail_t** mail, int* err_code);
+
+int EmfDeleteBackupMail(char *backup_mail_filePath, int* err_code);
+*/
+/* Changes for Backup Email feature */
+/*------------------------------------------------------------------*/
+
+/**
+ * @open
+ * @fn email_get_max_mail_count(int *Count)
+ * @brief Gets the max count of mails which can be supported by email-service
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @param[out] Count max count of mails which can be supported by email-service
+ * @exception none
+
+ * @code
+ * #include "Emf_Mapi_Message.h"
+ * bool
+ * _api_sample_get_max_mail_count()
+ * {
+ * int max_count = -1;
+ *
+ * if(EMF_ERROR_NONE == email_get_max_mail_count(&max_count))
+ * printf("\n\t>>>>> email_get_max_mail_count() return [%d]\n\n", max_count);
+ * }
+ * @endcode
+ * @remarks N/A
+ */
+EXPORT_API int email_get_max_mail_count(int *Count);
+
+
+ /**
+ * @open
+ * @fn email_get_disk_space_usage(unsigned long *total_size)
+ * @brief Gets the total disk usage of emails in KB.
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @param[out] total_size total disk usage of emails
+ * @exception none
+
+ * @code
+ * #include "Emf_Mapi_Message.h"
+ * bool
+ * _api_sample_get_disk_space_usage()
+ * {
+ * unsigned long total_size = 0;
+ *
+ * if ( EMF_ERROR_NONE != email_get_disk_space_usage(&total_size))
+ * printf("email_get_disk_space_usage failed err : %d\n",err_code);
+ * else
+ * printf("email_get_disk_space_usage SUCCESS, total disk usage in KB : %ld \n", total_size);
+ * }
+ * @endcode
+ * @remarks N/A
+ */
+EXPORT_API int email_get_disk_space_usage(unsigned long *total_size);
+
+
+EXPORT_API int email_get_recipients_list(int account_id, const char *mailbox_name, emf_sender_list_t **sender_list);
+/**
+ * @open
+ * @fn email_get_sender_list(int account_id, const char *mailbox_name, int search_type, char *search_value, emf_sort_type_t sorting, emf_sender_list_t** sender_list, int *sender_count)
+ * @brief Get the sender list with the total number of sender's mails and the number of sender's unread mails.
+ * This is used to show email address and display name of each sender with the number of mails (unread and total).
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @param[in] account_id Specifies the account id to get the list. If this is 0, a sender list of "All Account" will be returned.
+ * @param[in] mailbox_name Specifies the mailbox name to get the list. If this is NULL, a sender list of "All Mailbox" will be returned.
+ * @param[in] search_type Specifies the search type
+ * @param[in] search_value Specifies the search value
+ * @param[in] sorting Specifies the sorting order.
+ * @param[out] sender_list Specifies the Pointer to the structure emf_sender_list_t. Memory for a new sender list will be allocated to this. Call email_free_sender_list() to free the memory allocated to this.
+ * @param[out] sender_count Specifies the number of senders in a sender list.
+ * @exception none
+ * @see emf_sort_type_t, emf_sender_list_t, email_free_sender_list()
+ * @code
+ * #include "Emf_Mapi_Message.h"
+ * bool
+ * _api_sample_get_sender_list()
+ * {
+ * emf_sender_list_t *sender_list = NULL;
+ * int sender_count = 0;
+ * int account_id = 0;
+ * int sorting = 0;
+ * int err_code = EMF_ERROR_NONE;
+ *
+ * account_id = 0; // For All accounts
+ * mailbox_name = NULL; // For All mail boxes
+ * sorting = EMF_SORT_DATETIME_HIGH;
+ *
+ *
+ * if ( EMF_ERROR_NONE != (err_code = email_get_sender_list(account_id, mailbox_name, EMF_SEARCH_FILTER_NONE, NULL, sorting, &sender_list, &sender_count)) )
+ * {
+ * printf("email_get_sender_list failed :\n"); *
+ * return false;
+ * }
+ * else
+ * {
+ * printf("Success\n");
+ * //do something
+ * }
+ *
+ * // Free sender list
+ * if ( sender_list )
+ * {
+ * email_free_sender_list(&sender_list, sender_count);
+ * }
+ * }
+ * @endcode
+ * @remarks N/A
+ */
+EXPORT_API int email_get_sender_list(int account_id, const char *mailbox_name, int search_type, const char *search_value, emf_sort_type_t sorting, emf_sender_list_t** sender_list, int *sender_count);
+
+/**
+ * @open
+ * @fn email_get_sender_list_ex(int account_id, const char *mailbox_name, int start_index, int limit_count, emf_sort_type_t sorting, emf_sender_list_t** sender_list, int *sender_count)
+ * @brief Get the sender list with the total number of sender's mails and the number of sender's unread mails.
+ * This is used to show email address and display name of each sender with the number of mails (unread and total).
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @param[in] account_id Specifies the account id to get the list. If this is 0, a sender list of "All Account" will be returned.
+ * @param[in] mailbox_name Specifies the mailbox name to get the list. If this is NULL, a sender list of "All Mailbox" will be returned.
+ * @param[in] start_index Specifies the start index in the sender list. This function will return a partial sender list from start_index to (start_index + limit_count - 1) in the sender list. negative value means "from the first sender". start_index is zero-based value.
+ * @param[in] limit_count Specifies the max number of sender list. negative value means "All senders from the start_index in sender list"
+ * @param[in] sorting Specifies the sorting order.
+ * @param[out] sender_list Specifies the Pointer to the structure emf_sender_list_t. Memory for a new sender list will be allocated to this. Call email_free_sender_list() to free the memory allocated to this.
+ * @param[out] sender_count Specifies the number of senders in a sender list.
+ * @exception none
+ * @see emf_sort_type_t, emf_sender_list_t, email_free_sender_list()
+ * @code
+ * #include "Emf_Mapi_Message.h"
+ * bool
+ * _api_sample_get_sender_list()
+ * {
+ * emf_sender_list_t *sender_list = NULL;
+ * int sender_count = 0;
+ * int account_id = 0;
+ * int start_index = 10; // from the 11th sender in sender list
+ * int limit_count = 5; // to the (11 + 5)th sender in sender list
+ * int sorting = 0;
+ * int err_code = EMF_ERROR_NONE;
+ *
+ * account_id = 0; // For All accounts
+ * mailbox_name = NULL; // For All mail boxes
+ * sorting = EMF_SORT_DATETIME_HIGH;
+ *
+ *
+ * if ( EMF_ERROR_NONE != (err_code = email_get_sender_list_ex(account_id, mailbox_name, start_index, limit_count, sorting, &sender_list, &sender_count)) )
+ * {
+ * printf("email_get_sender_list_ex failed :\n"); *
+ * return false;
+ * }
+ * else
+ * {
+ * printf("Success\n");
+ * //do something
+ * }
+ *
+ * // Free sender list
+ * if ( sender_list )
+ * {
+ * email_free_sender_list(&sender_list, sender_count);
+ * }
+ * }
+ * @endcode
+ * @remarks N/A
+ */
+EXPORT_API int email_get_sender_list_ex(int account_id, const char *mailbox_name, int start_index, int limit_count, emf_sort_type_t sorting, emf_sender_list_t** sender_list, int *sender_count);
+
+
+/**
+ * @open
+ * @fn email_free_sender_list(emf_sender_list_t **sender_list, int count)
+ * @brief Free the sender list allocated by email_get_sender_list(). This function will free the memory which is allocated to sender_list itself.
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @param[in] sender_list Specifies the Pointer to the structure emf_sender_list_t to be freed.
+ * @param[in] count Specifies the number of senders in a sender list.
+ * @exception none
+ * @see emf_sender_list_t, email_get_sender_list()
+ */
+EXPORT_API int email_free_sender_list(emf_sender_list_t **sender_list, int count);
+
+
+/**
+ * @open
+ * @fn email_get_address_info_list(int mail_id, emf_address_info_list_t** address_info_list)
+ * @brief Get the address info list. The address info list contains from, to, cc, bcc addresses and their display name, contact id and etc. (see emf_address_info_list_t)
+ * Each GList (from, to, cc, bcc) is the list of emf_address_info_t data.
+ * "data" variable of GList structure contains emf_address_info_t data. <br>
+ * To get emf_address_info_t data from GList, Use type casting from GList node.
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @param[in] mail_id Specifies the mail id to get the list.
+ * @param[out] address_info_list Specifies the Pointer to the structure emf_address_info_list_t. Memory for a new address info list will be allocated to this. Call email_free_address_info_list() to free the memory allocated to this.
+ * @exception none
+ * @see emf_address_info_list_t, emf_address_info_t, email_free_address_info_list()
+ * @code
+ * #include "Emf_Mapi_Message.h"
+ * bool
+ * _api_sample_get_address_info_list()
+ * {
+ * emf_address_info_list_t *p_address_info_list= NULL;
+ * emf_address_info_t *p_address_info = NULL;
+ * int mai_id;
+ * int err_code = EMF_ERROR_NONE;
+ *
+ * mail_id = 1;
+ *
+ * if ( EMF_ERROR_NONE != (err_code = email_get_address_info_list(mail_id, &p_address_info_list)) )
+ * {
+ * printf("email_get_address_info_list failed :\n"); *
+ * return false;
+ * }
+ * else
+ * {
+ * printf("Success\n");
+ * //do something with p_address_info_list
+ * GList *list = p_address_info_list->from;
+ * GList *node = g_list_first(list);
+ * while ( node != NULL )
+ * {
+ * p_address_info = (emf_address_info_t*)node->data;
+ * printf("%d, %s, %s, %d\n", p_address_info->address_type, p_address_info->address, p_address_info->display_name, p_address_info->contact_id);
+ *
+ * node = g_list_next(node);
+ * }
+ * }
+ *
+ * // Free sender list
+ * if ( p_address_info_list )
+ * {
+ * email_free_address_info_list(&p_address_info_list);
+ * }
+ * }
+ * @endcode
+ * @remarks N/A
+ */
+EXPORT_API int email_get_address_info_list(int mail_id, emf_address_info_list_t** address_info_list);
+
+/**
+ * @open
+ * @fn email_free_address_info_list(emf_address_info_list_t **address_info_list)
+ * @brief Free the address info list allocated by email_get_address_info_list(). This function will free the memory which is allocated to address_info_list itself.
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @param[in] address_info_list Specifies the Pointer to the structure emf_address_info_list_t to be freed.
+ * @exception none
+ * @see emf_address_info_list_t, email_get_address_info_list()
+ */
+EXPORT_API int email_free_address_info_list(emf_address_info_list_t **address_info_list);
+
+/**
+ * @open
+ * @fn email_get_structure(const char*encoded_string, void **struct_var, emf_convert_struct_type_e type)
+ * @brief This function returns the structure of the type which is indicated by 'type' variable. This function will allocate new memory to 'struct_var' for structure.<br>
+ * Some notifications such as NOTI_DOWNLOAD_NEW_MAIL are published with string parameter. The string contains various values that might be divided by delimiter.<br>
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @param[in] encoded_string Specifies the Pointer to the string from notification.
+ * @param[out] struct_var Specifies the Pointer to the structure to be returned. If success, new memory for structure will be allocated.
+ * @param[in] type Specifies the converting type. see emf_convert_struct_type_e
+ * @exception none
+ * @see emf_convert_struct_type_e
+ */
+EXPORT_API int email_get_structure(const char*encoded_string, void **struct_var, emf_convert_struct_type_e type);
+
+
+/**
+ * @open
+ * @fn email_add_message_with_meeting_request(emf_mail_t* mail, emf_mailbox_t* mailbox, emf_meeting_request_t* meeting_req, int from_composer)
+ * @brief Save a mail with meeting request information to specific mail box.
+ * This function is invoked when user wants to add a composed mail to a specified mailbox. <br>
+ * If the mail is composed by an user, the option (from_composer) is 1. Otherwise 0. <br>
+ * When info->is_meeting_request in the first parameter("mail") is 0 (EMF_MAIL_TYPE_NORMAL), meeting_req will be ignored. and this function will work the same as email_add_message().
+ * When info->is_meeting_request in the first parameter("mail") is (EMF_MAIL_TYPE_MEETING_REQUEST or EMF_MAIL_TYPE_MEETING_RESPONSE),
+ * The third parameter("meeting_req") shouldn't be NULL.
+ *
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @param[in] mail Specifies the saving mail.
+ * @param[in] mailbox Specifies the mailbox structure for saving email.
+ * @param[in] meeting_req Specifies the structure for meeting request information.
+ * @param[in] from_composer Specifies if the mail comes from composer.
+ * @exception none
+ * @see emf_mail_t, emf_mailbox_t, emf_meeting_request_t, email_add_message(), email_get_meeting_request(), email_update_message_with_meeting_request(), email_free_meeting_request()
+ * @remarks N/A
+ */
+
+EXPORT_API int email_add_message_with_meeting_request(emf_mail_t* mail, emf_mailbox_t* mailbox, emf_meeting_request_t* meeting_req, int from_composer);
+
+/**
+ * @open
+ * @fn email_get_meeting_request(int mail_id, emf_meeting_request_t **meeting_req)
+ * @brief Get the information of meeting request. The information of meeting request is based on Mail Id. <br>
+ * The information of meeting request is corresponding to only one mail.
+ * For this reason, the information of meeting request can be added by using email_add_message_with_meeting_request() with a matched mail information.
+ *
+ * @return This function returns EMF_ERROR_NONE on success. This function returns EMF_ERROR_DATA_NOT_FOUND if there isn't a matched mail. Otherwise it returns error code (refer to EMF_ERROR_XXX) on failure.
+ * @param[in] mail_id Specifies the Mail id for which meeting request details need to be fetched
+ * @param[in/out] meeting_req Specifies the Pointer to the structure emf_meeting_request_t.
+ * @exception none
+ * @see emf_meeting_request_t
+ */
+EXPORT_API int email_get_meeting_request(int mail_id, emf_meeting_request_t **meeting_req);
+
+/**
+ * @open
+ * @fn email_update_message_with_meeting_request(int mail_id, emf_mail_t* mail, emf_meeting_request_t* meeting_req)
+ * @brief Update a existing email information. This function is invoked when user wants to change some existing email information with new email information. <br>
+ * When info->is_meeting_request in the second parameter("mail") is 0 (EMF_MAIL_TYPE_NORMAL), meeting_req will be ignored. and this function will work the same as email_update_message().
+ * When info->is_meeting_request in the second parameter("mail") is (EMF_MAIL_TYPE_MEETING_REQUEST or EMF_MAIL_TYPE_MEETING_RESPONSE),
+ * The third parameter("meeting_req") shouldn't be NULL.
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @param[in] mail_id Specifies the mail ID.
+ * @param[in] mail Specifies the pointer of mail structure.
+ * @param[in] meeting_req Specifies the pointer of meeting request structure(emf_meeting_request_t).
+ *
+ * @exception none
+ * @see emf_mail_t, emf_meeting_request_t, email_add_message_with_meeting_request()
+ */
+EXPORT_API int email_update_message_with_meeting_request(int mail_id, emf_mail_t* mail, emf_meeting_request_t* meeting_req);
+
+/**
+ * @open
+ * @fn email_free_meeting_request(emf_meeting_request_t** meeting_req, int count)
+ * @brief Free the meeting request allocated by email_get_meeting_request() or alloacted to add. This function will free the memory which is allocated to meeting_req (= *meeting_req) itself.
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @param[in] emf_meeting_request_t Specifies the Pointer to the structure emf_meeting_request_t to be freed.
+ * @param[in] count Specifies the number of elements in meeting_req array. this is usually 1.
+ * @exception none
+ * @see emf_meeting_request_t, email_get_meeting_request()
+ */
+EXPORT_API int email_free_meeting_request(emf_meeting_request_t** meeting_req, int count);
+
+EXPORT_API int email_move_thread_to_mailbox(int thread_id, char *target_mailbox_name, int move_always_flag);
+
+EXPORT_API int email_delete_thread(int thread_id, int delete_always_flag);
+
+EXPORT_API int email_modify_seen_flag_of_thread(int thread_id, int seen_flag, int on_server);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+/**
+* @} @}
+*/
+
+
+#endif /* __EMF_MAPI_MESSAGE_H__ */
diff --git a/MAPI/include/Emf_Mapi_Network.h b/MAPI/include/Emf_Mapi_Network.h
new file mode 100755
index 0000000..db95892
--- /dev/null
+++ b/MAPI/include/Emf_Mapi_Network.h
@@ -0,0 +1,454 @@
+/*
+* email-service
+*
+* Copyright (c) 2000 - 2011 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.
+*
+*/
+
+
+#ifndef __EMF_MAPI_NETWORK_H__
+#define __EMF_MAPI_NETWORK_H__
+
+#include "emf-types.h"
+
+/**
+* @defgroup EMAIL_FRAMEWORK Email Service
+* @{
+*/
+
+/**
+* @ingroup EMAIL_FRAMEWORK
+* @defgroup EMAIL_MAPI_NETWORK Email Network API
+* @{
+*/
+
+/**
+ *
+ * This file contains the data structures and interfaces needed for application,
+ * to interact with Email Engine.
+ * @file Emf_Mapi_Network.h
+ * @author Kyuho Jo <kyuho.jo@samsung.com>
+ * @author Sunghyun Kwon <sh0701.kwon@samsung.com>
+ * @version 0.1
+ * @brief This file contains the data structures and interfaces of Network related Functionality provided by
+ * Email Engine .
+ *
+ * @{
+
+ * @code
+
+ * #include "Emf_Mapi_Network.h"
+ *
+ * bool
+ * other_app_invoke_uniform_api_sample(int* error_code)
+ * {
+ *
+ * // Send a mail
+ * emf_mailbox_t mbox;
+ * emf_mail_t *mail = NULL;
+ * emf_mail_head_t *head =NULL;
+ * emf_mail_body_t *body =NULL;
+ * emf_attachment_info_t attachment;
+ * emf_option_t option;
+ * int account_id = 1;
+ * int err = EMF_ERROR_NONE;
+ * int mail_id = 1;
+ * char arg[50]; //Input attachment number need to be download
+ * emf_event_status_type_t status;
+ * int action = -1;
+ * int on_sending = 0;
+ * int on_receiving = 0;
+ *
+ * mail =( emf_mail_t *)malloc(sizeof(emf_mail_t));
+ * head =( emf_mail_head_t *)malloc(sizeof(emf_mail_head_t));
+ * body =( emf_mail_body_t *)malloc(sizeof(emf_mail_body_t));
+ * mail->info =( emf_mail_info_t*) malloc(sizeof(emf_mail_info_t));
+ * memset(mail->info, 0x00, sizeof(emf_mail_info_t));
+ *
+ * memset(&mbox, 0x00, sizeof(emf_mailbox_t));
+ * memset(&option, 0x00, sizeof(emf_option_t));
+ * memset(mail, 0x00, sizeof(emf_mail_t));
+ * memset(head, 0x00, sizeof(emf_mail_head_t));
+ * memset(body, 0x00, sizeof(emf_mail_body_t));
+ * memset(&attachment, 0x00, sizeof(emf_attachment_info_t));
+ *
+ * option.keep_local_copy = 1;
+ *
+ * mbox.account_id = account_id;
+ * mbox.name = strdup("OUTBOX");
+ * head->to=strdup("test@test.com");
+ * head->subject =strdup("test");
+ * body->plain = strdup("/tmp/mail.txt");
+ *
+ * mail->info->account_id = account_id;
+ * mail->info->flags.draft = 1;
+ * mail->body = body;
+ * mail->head = head;
+ *
+ * attachment.name = strdup("attach");
+ * attachment.savename = strdup("/tmp/mail.txt");
+ * attachment.next = NULL;
+ * mail->body->attachment = &attachment;
+ * mail->body->attachment_num = 1;
+ * if(EMF_ERROR_NONE == email_add_message(mail,&mbox,1))
+ * {
+ * if(EMF_ERROR_NONE == email_send_mail(&mbox, mail->info->uid,&option,&handle))
+ * //success
+ * else
+ * //failure
+ * }
+ *
+ * // Download header of new emails from mail server
+ * unsigned handle = 0;
+ *
+ * memset(&mbox, 0x00, sizeof(emf_mailbox_t));
+ *
+ * mbox.account_id = account_id;
+ * mbox.name = strdup("INBOX");
+ * if(EMF_ERROR_NONE == email_sync_header (&mbox,&handle))
+ * //success
+ * else
+ * //failure
+ *
+ * //Sync mail header for all accounts
+ * if(EMF_ERROR_NONE == email_sync_header_for_all_account(&handle))
+ * //success
+ * else
+ * //failure
+ *
+ * //Download email body from server
+ *
+ * memset(&mbox, 0x00, sizeof(emf_mailbox_t));
+ * mbox.account_id = account_id;
+ * mbox.name = strdup("INBOX");
+ * if(EMF_ERROR_NONE == email_download_body (&mbox,mail_id,0,&handle))
+ * //success
+ * else
+ * //failure
+ *
+ * //Download a email nth-attachment from server
+ * prinf("Enter attachment number\n");
+ * scanf("%s",arg);
+ * memset(&mbox, 0x00, sizeof(emf_mailbox_t));
+ * mbox.name = strdup("INBOX");
+ * mbox.account_id = account_id;
+ * if(EMF_ERROR_NONE == email_download_attachment(&mailbox,mail_id,arg,&handle))
+ * //success
+ * else
+ * //failure
+ *
+ * //Cancel job
+ * if(EMF_ERROR_NONE == email_cancel_job(account_id,handle))//canceling download email nth attachment from server job.
+ * //so this handle contains the value return by the email_download_attachment()
+ * //success
+ * else
+ * //failure
+ * //Get pending job listfor an account
+ *
+ * printf( " Enter Action \n SEND_MAIL = 0 \n SYNC_HEADER = 1 \n" \
+ * " DOWNLOAD_BODY,= 2 \n DOWNLOAD_ATTACHMENT = 3 \n" \
+ * " DELETE_MAIL = 4 \n SEARCH_MAIL = 5 \n SAVE_MAIL = 6 \n" \
+ * " NUM = 7 \n");
+ * scanf("%d",&action);
+ * if(EMF_ERROR_NONE == email_get_pending_job(action,account_id,mail_id,&status))
+ * //success
+ * else
+ * //error
+ *
+ * //Get Network status
+ * if(EMF_ERROR_NONE == email_get_network_status(&sending,&receiving))
+ * //success
+ * else
+ * //failure
+ *
+ * //Send read report
+ * if(EMF_ERROR_NONE == email_send_report(mail ,&handle))
+ * //success
+ * else
+ * //failure
+ * //Save and send
+ *
+ * mbox.account_id = account_id;
+ * mbox.name = strdup("DRAFTBOX");
+ *
+ * if(EMF_ERROR_NONE == email_add_message(mail,&mbox,1))
+ * {
+ * if(EMF_ERROR_NONE == email_send_saved(account_id,&option,&handle))
+ * //success
+ * else
+ * //failure
+ * }
+ * //Get Imap mailbox list
+ * printf("\n > Enter server name:\n");
+ * scanf("%s",arg);
+ * if(EMF_ERROR_NONE == email_get_imap_mailbox_list(account_id , arg , &handle))
+ * //success
+ * else
+ * //failure
+ *
+ * //sync local activity
+ * if(EMF_ERROR_NONE == email_sync_local_activity(account_id))
+ * //success
+ * else
+ * //failure
+ * }
+ *
+ * @endcode
+ * @}
+
+ */
+
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+/**
+ * @open
+ * @fn email_send_mail( emf_mailbox_t* mailbox, int mail_id, emf_option_t* sending_option, unsigned* handle)
+ * @brief Send a mail.This function is invoked when user wants to send a composed mail.
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @param[in] mailbox Specifies the mailbox to consist a sending email.
+ * @param[in] mail_id Specifies the mail ID.
+ * @param[in] sending_option Specifies the sending option.
+ * @param[out] handle Specifies the sending handle.
+ * @exception none
+ * @see emf_mailbox_t and emf_option_t
+ * @remarks N/A
+ */
+EXPORT_API int email_send_mail( emf_mailbox_t* mailbox,
+ int mail_id,
+ emf_option_t* sending_option,
+ unsigned* handle);
+
+
+/**
+ * @open
+ * @fn email_sync_header(emf_mailbox_t* mailbox, unsigned* handle)
+ * @brief Download header of new emails from mail server.This function is invoked when user wants to download only header of new mails.
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @param[in] mailbox Specifies the structure of mailbox.
+ * @param[out] handle Specifies the handle for stopping downloading.
+ * @exception none
+ * @see emf_mailbox_t
+ * @remarks N/A
+ */
+EXPORT_API int email_sync_header(emf_mailbox_t* mailbox, unsigned* handle);
+
+
+/**
+ * @open
+ * @fn email_sync_header_for_all_account(unsigned* handle)
+ * @brief Download header of new emails from mail server for all emails.This function is invoked when user wants to download header of new mails for all accounts.
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @param[out] handle Specifies the handle for stopping downloading.
+ * @exception none
+ * @see none
+ * @remarks N/A
+ */
+EXPORT_API int email_sync_header_for_all_account(unsigned* handle);
+
+
+/**
+ * @open
+ * @fn email_download_body(emf_mailbox_t* mailbox, int mail_id, int with_attachment, unsigned* handle)
+ * @brief Download email body from server.This function is invoked when user wants to download email body with/without attachment based on the option with_attachment
+ * from the server.
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @param[in] mailbox Specifies the structure of mailbox.
+ * @param[in] mail_id Specifies the mail ID.
+ * @param[in] with_attachment Specifies the whether attachment is there or not.
+ * @param[out] handle Specifies the handle for stopping downloading.
+ * @exception none
+ * @see emf_mailbox_t
+ * @remarks N/A
+ */
+EXPORT_API int email_download_body(emf_mailbox_t* mailbox, int mail_id, int with_attachment, unsigned* handle);
+
+
+
+
+
+
+/**
+ * @open
+ * @fn email_download_attachment(emf_mailbox_t* mailbox, int mail_id, char* nth, unsigned* handle);
+ * @brief Download a email nth-attachment from server.This function is invoked if user wants to download only specific attachment of a mail whose body is already downloaded.
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @param[in] mailbox Reserved.
+ * @param[in] mail_id Specifies the mail ID.
+ * @param[in] nth Specifies the buffer that a attachment number been saved. the minimum number is "1".
+ * @param[out] handle Specifies the handle for stopping downloading.
+ * @exception none
+ * @see emf_mailbox_t
+ * @remarks N/A
+ */
+EXPORT_API int email_download_attachment(emf_mailbox_t* mailbox,
+ int mail_id,
+ const char* nth,
+ unsigned* handle);
+
+
+/**
+ * @open
+ * @fn email_cancel_job(int account_id, int handle);
+ * @brief cancel the ongoing job.This function is invoked if user wants to cancel any ongoing job of a specified account.
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @param[in] account_id Specifies the account ID.
+ * @param[in] handle Specifies the handle for stopping the operation.
+ * @exception none
+ * @see none
+ * @remarks N/A
+ */
+
+EXPORT_API int email_cancel_job(int account_id, int handle);
+
+
+/**
+ * @open
+ * @fn email_get_pending_job(emf_action_t action, int account_id, int mail_id, emf_event_status_type_t * status);
+ * @brief get pending job list.This function is invoked if user wants to get the pending job list with status information .
+ * Based on action item of a mail is for a specific account this will give all pending job list.
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @param[in] account_id Specifies the action of the job.
+ * @param[in] account_id Specifies the account ID.
+ * @param[in] mail_id Specifies the mail ID.
+ * @param[out]status Specifies the status of the job.
+ * @exception none
+ * @see emf_action_t and emf_event_status_type_t
+ * @remarks N/A
+ */
+EXPORT_API int email_get_pending_job(emf_action_t action, int account_id, int mail_id, emf_event_status_type_t * status);
+
+
+/**
+ * @open
+ * @fn email_get_network_status(int* on_sending, int* on_receiving)
+ * @brief This function gives the current network status.This gives the information to the user whether sending operation is in progress or receiving operation.
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @param[out] on_sending True if sending is in progress.
+ * @param[out] on_receiving True if receivng is in progress.
+ * @exception none
+ * @see none
+ * @remarks N/A
+ */
+EXPORT_API int email_get_network_status(int* on_sending, int* on_receiving);
+
+
+/**
+ * @open
+ * @fn email_send_report(emf_mail_t* mail, unsigned* handle)
+ * @brief Send a read receipt mail.This function is invoked when user receives a mail with read report enable and wants to send a read report for the same.
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @param[in] mail Specifies the mail to been read.
+ * @param[out] handle Specifies the handle for stopping sending.
+ * @exception none
+ * @see emf_mail_t
+ * @remarks N/A
+ */
+EXPORT_API int email_send_report(emf_mail_t* mail, unsigned* handle);
+
+
+/**
+ * @open
+ * @fn email_send_saved(int account_id, emf_option_t* sending_option, unsigned* handle)
+ * @brief Send all mails to been saved in Offline-mode.This function is invoked when user wants to send an email and after saving it.
+ * This will save the email in draft mailbox and then sends.
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @param[in] account_id Specifies the account ID.
+ * @param[in] sending_option Specifies the sending option.
+ * @param[out] handle Specifies the handle for stopping sending.
+ * @exception none
+ * @see emf_option_t
+ * @remarks N/A
+ */
+EXPORT_API int email_send_saved(int account_id, emf_option_t* sending_option, unsigned* handle);
+
+
+EXPORT_API int email_download_mail_from_server(emf_mailbox_t * mailbox, const char * server_mail_id, unsigned* handle) DEPRECATED;
+
+
+/**
+ * @open
+ * @fn email_get_imap_mailbox_list(int account_id, char* mailbox, unsigned* handle)
+ * @brief fetch all the mailbox names from server and store the non-existing mailboxes in DB.This function is invoked when user wants to download all server mailboxes from IMAP server
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @param[in] account_id Specifies the account ID.
+ * @param[in] mailbox Specifies the mailbox name.
+ * @param[out] handle Specifies the handle for stopping Network operation.
+ * @exception none
+ * @see none
+ * @remarks N/A
+ */
+EXPORT_API int email_get_imap_mailbox_list(int account_id, const char* mailbox, unsigned* handle);
+
+
+
+/**
+ * @open
+ * @fn email_sync_local_activity(int account_id)
+ * @brief sync local activity
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @param[in] account_id Specifies the account ID.
+ * @exception none
+ * @see none
+ * @remarks N/A
+ */
+EXPORT_API int email_sync_local_activity(int account_id);
+
+
+/**
+ * @open
+ * @fn email_find_mail_on_server(int account_id, const char *mailbox_name, int search_type, char *search_value)
+ * @brief Search the mails on server.
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @param[in] account_id Specifies the Account ID
+ * @param[in] mailbox_name Specifies the Mailbox Name
+ * @param[in] search_type Specifies the searching type(EMF_SEARCH_FILTER_SUBJECT, EMF_SEARCH_FILTER_SENDER, EMF_SEARCH_FILTER_RECIPIENT, EMF_SEARCH_FILTER_ALL)
+ * @param[in] search_value Specifies the value to use for searching. (ex : Subject, email address, display name)
+ * @exception none
+ * @see
+ * @code
+ * @endcode
+ * @remarks N/A
+ */
+EXPORT_API int email_find_mail_on_server(int input_account_id, const char *input_mailbox_name, int input_search_type, char *input_search_value, unsigned *output_handle);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+/**
+* @}
+*/
+
+
+#endif /* __EMF_MAPI_NETWORK_H__ */
diff --git a/MAPI/include/Emf_Mapi_Rule.h b/MAPI/include/Emf_Mapi_Rule.h
new file mode 100755
index 0000000..2accc6b
--- /dev/null
+++ b/MAPI/include/Emf_Mapi_Rule.h
@@ -0,0 +1,218 @@
+/*
+* email-service
+*
+* Copyright (c) 2000 - 2011 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.
+*
+*/
+
+
+#ifndef __EMF_MAPI_RULE_H__
+#define __EMF_MAPI_RULE_H__
+
+#include "emf-types.h"
+
+/**
+* @defgroup EMAIL_FRAMEWORK Email Service
+* @{
+*/
+
+/**
+* @ingroup EMAIL_FRAMEWORK
+* @defgroup EMAIL_MAPI_RULE Email Rule API
+* @{
+*/
+
+ /**
+ *
+ * This file contains the data structures and interfaces needed for application,
+ * to interact with Email Engine.
+ * @file Emf_Mapi_Rule.h
+ * @author Kyuho Jo <kyuho.jo@samsung.com>
+ * @author Sunghyun Kwon <sh0701.kwon@samsung.com>
+ * @version 0.1
+ * @brief This file contains the data structures and interfaces of Rule related Functionality provided by
+ * Email Engine .
+ * @{
+
+ * @code
+ * #include "Emf_Mapi_Rule.h"
+ * bool
+ * other_app_invoke_uniform_api_sample(int* error_code)
+ * {
+ * int err = EMF_ERROR_NONE;
+ * emf_rule_t* rule = NULL;
+ * int filter_id = 1;
+ * int count = 0;
+ *
+ * // Get a information of filtering
+ * printf("Enter filter Id:\n");
+ * scanf("%d",&filter_id);
+ *
+ * if(EMF_ERROR_NONE == email_get_rule (filter_id,&rule))
+ * //success
+ * else
+ * //failure
+ *
+ * // Get all filterings
+ * if(EMF_ERROR_NONE == email_get_rule_list(&rule,&count))
+ * //success
+ * else
+ * //failure
+ *
+ *
+ * // Add a filter information
+ * if(EMF_ERROR_NONE == email_add_rule (rule))
+ * //success
+ * else
+ * //failure
+ * err = email_free_rule (&rule,1);
+ *
+ * // Change a filter information
+ * if(EMF_ERROR_NONE == email_update_rule (filter_id,rule))
+ * //success
+ * else
+ * //failure
+ * err = email_free_rule (&rule,1);
+ *
+ * // Delete a filter information
+ * printf("Enter filter Id:\n");
+ * scanf("%d",&filter_id);
+ *
+ * if(EMF_ERROR_NONE == email_delete_rule (filter_id))
+ * //success
+ * else
+ * //failure
+ *
+ * // Free allocated memory
+ * if(EMF_ERROR_NONE == email_free_rule (&rule,1))
+ * //success
+ * else
+ * //failure
+ *
+ * }
+ *
+ * @endcode
+ * @}
+ */
+
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+/**
+
+ * @open
+ * @fn email_get_rule(int filter_id, emf_rule_t** filtering_set)
+ * @brief Get a information of filtering.
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure
+ * @param[in] filter_id Specifies the filter ID.
+ * @param[out] filtering_set The returned information of filter are saved here.
+ * @exception #EMF_ERROR-INVALID_PARAM -Invalid argument
+ * @see emf_rule_t
+ * @remarks N/A
+ */
+EXPORT_API int email_get_rule(int filter_id, emf_rule_t** filtering_set);
+
+/**
+
+ * @open
+ * @fn email_get_rule_list(emf_rule_t** filtering_set, int* count)
+ * @brief Get all filterings.This function gives all the filter rules already set before by user.
+ * This will provide total number of filter rules available and information of all rules.
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure
+ * @param[out] filtering_set The returned filterings are saved here.(possibly NULL)
+ * @param[out] count The count of returned filters is saved here.(possibly 0)
+ * @exception #EMF_ERROR-INVALID_PARAM -Invalid argument
+ * @see emf_rule_t
+ * @remarks N/A
+ */
+EXPORT_API int email_get_rule_list(emf_rule_t** filtering_set, int* count);
+
+/**
+
+ * @open
+ * @fn email_add_rule(emf_rule_t* filtering_set)
+ * @brief Add a filter information.This function is invoked if user wants to add a new filter rule.
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @param[in] filtering_set Specifies the pointer of adding filter structure.
+ * @exception #EMF_ERROR-INVALID_PARAM -Invalid argument
+ * @see emf_rule_t
+ * @remarks N/A
+ */
+EXPORT_API int email_add_rule(emf_rule_t* filtering_set);
+
+/**
+
+ * @open
+ * @fn email_update_rule(int filter_id, emf_rule_t* new_set)
+ * @brief Change a filter information.This function will update the existing filter rule with new information.
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @param[in] filter_id Specifies the original filter ID.
+ * @param[in] new_set Specifies the information of new filter.
+ * @exception #EMF_ERROR-INVALID_PARAM -Invalid argument
+ * @see emf_rule_t
+ * @remarks N/A
+ */
+EXPORT_API int email_update_rule(int filter_id, emf_rule_t* new_set);
+
+/**
+
+ * @open
+ * @fn email_delete_rule(int filter_id)
+ * @brief Delete a filter information.This function will delete the exsting filter information by specified filter Id.
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure
+ * @param[in] filter_id Specifies the filter ID.
+ * @exception #EMF_ERROR-INVALID_PARAM -Invalid argument
+ * @see none
+ * @remarks N/A
+ */
+EXPORT_API int email_delete_rule(int filter_id);
+
+
+
+/**
+
+ * @open
+ * @fn email_free_rule (emf_rule_t** filtering_set, int count)
+ * @brief Free allocated memory.
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure
+ * @param[in] filtering_set Specifies the pointer of pointer of filter structure for memory free.
+ * @param[in] count Specifies the count of filter.
+ * @exception #EMF_ERROR-INVALID_PARAM -Invalid argument
+ * @see emf_rule_t
+ * @remarks N/A
+ */
+EXPORT_API int email_free_rule (emf_rule_t** filtering_set, int count);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+/**
+* @} @}
+*/
+
+
+#endif /* __EMF_MAPI_RULE_H__ */
diff --git a/MAPI/include/Emf_Mapi_Types.h b/MAPI/include/Emf_Mapi_Types.h
new file mode 100755
index 0000000..52bb148
--- /dev/null
+++ b/MAPI/include/Emf_Mapi_Types.h
@@ -0,0 +1,873 @@
+/*
+* email-service
+*
+* Copyright (c) 2000 - 2011 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.
+*
+*/
+
+
+#ifndef __EMF_MAPI_TYPES_H__
+#define __EMF_MAPI_TYPES_H__
+
+#include "emf-types.h"
+
+/**
+* @defgroup EMAIL_FRAMEWORK Email Service
+* @{
+*/
+
+/**
+* @ingroup EMAIL_FRAMEWORK
+* @defgroup EMAIL_MAPI_TYPES Email Types API
+* @{
+*/
+
+
+/**
+ *
+ * This file contains the data structures and interfaces needed for application,
+ * to interact with Email Engine.
+ * @file Emf_Mapi_Types.h
+ * @author Kyuho Jo <kyuho.jo@samsung.com>
+ * @author Sunghyun Kwon <sh0701.kwon@samsung.com>
+ * @version 0.1
+ * @brief This file contains interfaces for using data structures of email-service .
+ */
+
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+
+// emf_mail_t ------------------------------------------------------------------
+/**
+ * @open
+ * @fn email_get_info_from_mail(emf_mail_t *mail, emf_mail_info_t **info)
+ * @brief Gets the object of emf_mail_info_t. If mail is NULL, this returns EMF_ERROR_INVALID_PARAM. <br>
+ * This function doesn't allocate new memory for info object, but just returns the pointer to the emf_mail_info_t object in mail object.
+ * The info objet will be freed together with mail , when mail is freed by calling email_free_mail()
+ * So don't free info object itself if it is the object in mail object.
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @param[in] mail Specifies the pointer to emf_mail_t. This contains emf_mail_info_t object.
+ * @param[out] info Specifies the pointer to emf_mail_info_t. The info will point the info object in emf_mail_t(mail)
+ * @exception none
+ * @see emf_mail_t, emf_mail_info_t
+ */
+EXPORT_API int email_get_info_from_mail(emf_mail_t *mail, emf_mail_info_t **info) DEPRECATED;
+
+/**
+ * @open
+ * @fn email_set_info_to_mail(emf_mail_t *mail, emf_mail_info_t *info)
+ * @brief Sets the object of emf_mail_info_t to emf_mail_obejct(mail). If mail is NULL, this returns EMF_ERROR_INVALID_PARAM.
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @param[in] mail Specifies the pointer to emf_mail_t.
+ * @param[in] info Specifies the pointer to emf_mail_info_t.
+ * @exception none
+ * @see emf_mail_t, emf_mail_info_t
+ */
+EXPORT_API int email_set_info_to_mail(emf_mail_t *mail, emf_mail_info_t *info) DEPRECATED;
+
+/**
+ * @open
+ * @fn email_get_head_from_mail(emf_mail_t *mail, emf_mail_head_t **head)
+ * @brief Gets the object of emf_mail_head_t. If mail is NULL, this returns EMF_ERROR_INVALID_PARAM. <br>
+ * This function doesn't allocate new memory for head object, but just returns the pointer to the emf_mail_head_t object in mail object.
+ * The head objet will be freed together with mail , when mail is freed by calling email_free_mail()
+ * So don't free head object if it is the object in mail object.
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @param[in] mail Specifies the pointer to emf_mail_t. This contains emf_mail_head_t object.
+ * @param[out] head Specifies the pointer to emf_mail_head_t. This will point the head object in emf_mail_t(mail).
+ * @exception none
+ * @see emf_mail_t, emf_mail_head_t
+ */
+EXPORT_API int email_get_head_from_mail(emf_mail_t *mail, emf_mail_head_t **head) DEPRECATED;
+
+/**
+ * @open
+ * @fn email_set_head_to_mail(emf_mail_t *mail, emf_mail_head_t *head)
+ * @brief Sets the object of emf_mail_head_t to emf_mail_obejct(mail). If mail is NULL, this returns EMF_ERROR_INVALID_PARAM.
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @param[in] mail Specifies the pointer to emf_mail_t.
+ * @param[in] head Specifies the pointer to emf_mail_head_t.
+ * @exception none
+ * @see emf_mail_t, emf_mail_head_t
+ */
+EXPORT_API int email_set_head_to_mail(emf_mail_t *mail, emf_mail_head_t *head) DEPRECATED;
+
+/**
+ * @open
+ * @fn email_get_body_from_mail(emf_mail_t *mail, emf_mail_body_t **body)
+ * @brief Gets the object of emf_mail_body_t. If mail is NULL, this returns EMF_ERROR_INVALID_PARAM. <br>
+ * This function doesn't allocate new memory for emf_mail_body_t object, but just returns the pointer to the emf_mail_body_t object in mail object.
+ * The body objet will be freed together with mail , when mail is freed by calling email_free_mail()
+ * So don't free body object if it is the object in mail object.
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @param[in] mail Specifies the pointer to emf_mail_t. This contains emf_mail_body_t object.
+ * @param[out] body Specifies the pointer to emf_mail_body_t. This will point the object in emf_mail_t(mail)
+ * @exception none
+ * @see emf_mail_t, emf_mail_body_t
+ */
+EXPORT_API int email_get_body_from_mail(emf_mail_t *mail, emf_mail_body_t **body) DEPRECATED;
+
+/**
+ * @open
+ * @fn email_set_body_to_mail(emf_mail_t *mail, emf_mail_body_t *body)
+ * @brief Sets the object of emf_mail_body_t to emf_mail_obejct(mail). If mail is NULL, this returns EMF_ERROR_INVALID_PARAM.
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @param[in] mail Specifies the pointer to emf_mail_t.
+ * @param[in] body Specifies the pointer to emf_mail_body_t.
+ * @exception none
+ * @see emf_mail_t, emf_mail_head_t
+ */
+EXPORT_API int email_set_body_to_mail(emf_mail_t *mail, emf_mail_body_t *body) DEPRECATED;
+
+// emf_mail_info_t -------------------------------------------------------------
+/**
+ * @open
+ * @fn email_get_account_id_from_info(emf_mail_info_t *info, int *account_id)
+ * @brief Gets account id from the info object . If info is NULL, this returns EMF_ERROR_INVALID_PARAM. <br>
+ * This function doesn't allocate new memory for account id. but just returns account id in info object.
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @param[in] info Specifies the pointer to emf_mail_info_t.
+ * @param[out] account_id Specifies the pointer to the memory to save account id
+ * @exception none
+ * @see emf_mail_info_t
+ */
+EXPORT_API int email_get_account_id_from_info(emf_mail_info_t *info, int *account_id) DEPRECATED;
+
+/**
+ * @open
+ * @fn email_set_account_id_to_info(emf_mail_info_t *info, int account_id)
+ * @brief Sets account id to emf_mail_info_t(info). If info is NULL, this returns EMF_ERROR_INVALID_PARAM.
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @param[in] info Specifies the pointer to emf_mail_info_t.
+ * @param[in] account_id Specifies the account id.
+ * @exception none
+ * @see emf_mail_info_t
+ */
+EXPORT_API int email_set_account_id_to_info(emf_mail_info_t *info, int account_id) DEPRECATED;
+
+/**
+ * @open
+ * @fn email_get_uid_from_info(emf_mail_info_t *info, int *uid)
+ * @brief Gets uid from the info object . If info is NULL, this returns EMF_ERROR_INVALID_PARAM. <br>
+ * This function doesn't allocate new memory for uid, but just returns uid in info object.
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @param[in] info Specifies the pointer to emf_mail_info_t.
+ * @param[out] uid Specifies the pointer to the memory to save uid
+ * @exception none
+ * @see emf_mail_info_t
+ */
+EXPORT_API int email_get_uid_from_info(emf_mail_info_t *info, int *uid) DEPRECATED;
+
+/**
+ * @open
+ * @fn email_set_uid_to_info(emf_mail_info_t *info, int uid)
+ * @brief Sets uid to emf_mail_info_t(info). If info is NULL, this returns EMF_ERROR_INVALID_PARAM.
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @param[in] info Specifies the pointer to emf_mail_info_t.
+ * @param[in] uid Specifies the uid.
+ * @exception none
+ * @see emf_mail_info_t
+ */
+EXPORT_API int email_set_uid_to_info(emf_mail_info_t *info, int uid) DEPRECATED;
+
+/**
+ * @open
+ * @fn email_get_rfc822_size_from_info(emf_mail_info_t *info, int *rfc822_size)
+ * @brief Gets rfc822 size from the info object . If info is NULL, this returns EMF_ERROR_INVALID_PARAM. <br>
+ * This function doesn't allocate new memory for rfc822 size, but just returns rfc822 size in info object.
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @param[in] info Specifies the pointer to emf_mail_info_t.
+ * @param[out] rfc822_size Specifies the pointer to the memory to save rfc822 size
+ * @exception none
+ * @see emf_mail_info_t
+ */
+EXPORT_API int email_get_rfc822_size_from_info(emf_mail_info_t *info, int *rfc822_size) DEPRECATED;
+
+/**
+ * @open
+ * @fn email_set_rfc822_size_to_info(emf_mail_info_t *info, int rfc822_size)
+ * @brief Sets rfc822 size to emf_mail_info_t(info). If info is NULL, this returns EMF_ERROR_INVALID_PARAM.
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @param[in] info Specifies the pointer to emf_mail_info_t.
+ * @param[in] rfc822_size Specifies a rfc822 size.
+ * @exception none
+ * @see emf_mail_info_t
+ */
+EXPORT_API int email_set_rfc822_size_to_info(emf_mail_info_t *info, int rfc822_size) DEPRECATED;
+
+/**
+ * @open
+ * @fn email_get_body_downloaded_from_info(emf_mail_info_t *info, int *body_downloaded)
+ * @brief Gets whether body is downloaded from the info object . If info is NULL, this returns EMF_ERROR_INVALID_PARAM. <br>
+ * This function doesn't allocate new memory for body_downloaded, but just returns whether body is downloaded in info object.
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @param[in] info Specifies the pointer to emf_mail_info_t.
+ * @param[out] body_downloaded Specifies the pointer to the memory to save whether body is downlaoded.
+ * @exception none
+ * @see emf_mail_info_t
+ */
+EXPORT_API int email_get_body_downloaded_from_info(emf_mail_info_t *info, int *body_downloaded) DEPRECATED;
+
+/**
+ * @open
+ * @fn email_set_body_downloaded_to_info(emf_mail_info_t *info, int body_downloaded)
+ * @brief Sets the field which shows whether body is downloaded to emf_mail_info_t(info). If info is NULL, this returns EMF_ERROR_INVALID_PARAM.
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @param[in] info Specifies the pointer to emf_mail_info_t.
+ * @param[in] body_downloaded Specifies whether body is downloaded (0:no, 1:yes)
+ * @exception none
+ * @see emf_mail_info_t
+ */
+EXPORT_API int email_set_body_downloaded_to_info(emf_mail_info_t *info, int body_downloaded) DEPRECATED;
+
+/**
+ * @open
+ * @fn email_get_flags_from_info(emf_mail_info_t *info, emf_mail_flag_t flags)
+ * @brief Gets flags from the info object . If info is NULL, this returns EMF_ERROR_INVALID_PARAM. <br>
+ * This function doesn't allocate new memory for flags, but just returns flags in info object.
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @param[in] info Specifies the pointer to emf_mail_info_t.
+ * @param[out] flags Specifies the pointer to the memory to save flags
+ * @exception none
+ * @see emf_mail_info_t, emf_mail_flag_t
+ */
+EXPORT_API int email_get_flags_from_info(emf_mail_info_t *info, emf_mail_flag_t *flags) DEPRECATED;
+
+
+/**
+ * @open
+ * @fn email_set_flags_to_info(emf_mail_info_t *info, emf_mail_flag_t flags)
+ * @brief Sets flags to emf_mail_info_t(info). If info is NULL, this returns EMF_ERROR_INVALID_PARAM.
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @param[in] info Specifies the pointer to emf_mail_info_t.
+ * @param[in] flags Specifies the flags.
+ * @exception none
+ * @see emf_mail_info_t, emf_mail_flag_t
+ */
+EXPORT_API int email_set_flags_to_info(emf_mail_info_t *info, emf_mail_flag_t flags) DEPRECATED;
+
+/**
+ * @open
+ * @fn email_get_extra_flags_from_info(emf_mail_info_t *info, emf_extra_flag_t extra_flags)
+ * @brief Gets extra flags from the info object . If info is NULL, this returns EMF_ERROR_INVALID_PARAM. <br>
+ * This function doesn't allocate new memory for extra flags, but just returns extra flags in info object.
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @param[in] info Specifies the pointer to emf_mail_info_t.
+ * @param[out] extra_flags Specifies the pointer to the memory to save extra_flags
+ * @exception none
+ * @see emf_mail_info_t, emf_extra_flag_t
+ */
+EXPORT_API int email_get_extra_flags_from_info(emf_mail_info_t *info, emf_extra_flag_t extra_flags) DEPRECATED;
+
+/**
+ * @open
+ * @fn email_set_extra_flags_to_info(emf_mail_info_t *info, emf_extra_flag_t extra_flags)
+ * @brief Sets extra flags to emf_mail_info_t(info). If info is NULL, this returns EMF_ERROR_INVALID_PARAM.
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @param[in] info Specifies the pointer to emf_mail_info_t.
+ * @param[in] extra_flags Specifies the extra flags.
+ * @exception none
+ * @see emf_mail_info_t, emf_extra_flag_t
+ */
+EXPORT_API int email_set_extra_flags_to_info(emf_mail_info_t *info, emf_extra_flag_t extra_flags) DEPRECATED;
+
+/**
+ * @open
+ * @fn email_get_sid_from_info(emf_mail_info_t *info, char **sid)
+ * @brief Gets sid(the email's UID on server) from the info object . If info is NULL, this returns EMF_ERROR_INVALID_PARAM. <br>
+ * This function doesn't allocate new memory for sid, but just returns sid in info object.
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @param[in] info Specifies the pointer to emf_mail_info_t.
+ * @param[out] sid Specifies the pointer to the memory to save sid
+ * @exception none
+ * @see emf_mail_info_t
+ */
+EXPORT_API int email_get_sid_from_info(emf_mail_info_t *info, char **sid) DEPRECATED;
+
+/**
+ * @open
+ * @fn email_set_extra_flags_to_info(emf_mail_info_t *info, emf_extra_flag_t extra_flags)
+ * @brief Sets sid(the email's UID on server) to emf_mail_info_t(info). If info is NULL, this returns EMF_ERROR_INVALID_PARAM.
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @param[in] info Specifies the pointer to emf_mail_info_t.
+ * @param[in] sid Specifies the extra flags.
+ * @exception none
+ * @see emf_mail_info_t
+ */
+EXPORT_API int email_set_sid_to_info(emf_mail_info_t *info, char *sid) DEPRECATED;
+
+
+// emf_mail_head_t -------------------------------------------------------------
+/**
+ * @open
+ * @fn email_get_mid_from_head(emf_mail_head_t *head, char **mid)
+ * @brief Gets mid(the message ID) from the head object . If head is NULL, this returns EMF_ERROR_INVALID_PARAM. <br>
+ * This function doesn't allocate new memory for mid but just returns mid in head object.
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @param[in] head Specifies the pointer to emf_mail_head_t.
+ * @param[out] mid Specifies the pointer to the memory to save mid
+ * @exception none
+ * @see emf_mail_head_t
+ */
+EXPORT_API int email_get_mid_from_head(emf_mail_head_t *head, char **mid) DEPRECATED;
+
+/**
+ * @open
+ * @fn email_set_mid_to_head(emf_mail_head_t *head, char *mid)
+ * @brief Sets mid(the message ID) to emf_mail_head_t(head). If head is NULL, this returns EMF_ERROR_INVALID_PARAM.
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @param[in] head Specifies the pointer to emf_mail_head_t.
+ * @param[in] mid Specifies the mid(the message ID).
+ * @exception none
+ * @see emf_mail_head_t
+ */
+EXPORT_API int email_set_mid_to_head(emf_mail_head_t *head, char *mid) DEPRECATED;
+
+/**
+ * @open
+ * @fn email_get_subject_from_head(emf_mail_head_t *head, char **subject)
+ * @brief Gets subject of a mail from the head object . If head is NULL, this returns EMF_ERROR_INVALID_PARAM. <br>
+ * This function doesn't allocate new memory for subject but just returns subject in head object.
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @param[in] head Specifies the pointer to emf_mail_head_t.
+ * @param[out] subject Specifies the pointer to the memory to save subject
+ * @exception none
+ * @see emf_mail_head_t
+ */
+EXPORT_API int email_get_subject_from_head(emf_mail_head_t *head, char **subject) DEPRECATED;
+
+/**
+ * @open
+ * @fn email_set_subject_to_head(emf_mail_head_t *head, char *subject)
+ * @brief Sets subject of a mail to emf_mail_head_t(head). If head is NULL, this returns EMF_ERROR_INVALID_PARAM.
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @param[in] head Specifies the pointer to emf_mail_head_t.
+ * @param[in] subject Specifies the subject.
+ * @exception none
+ * @see emf_mail_head_t
+ */
+EXPORT_API int email_set_subject_to_head(emf_mail_head_t *head, char *subject) DEPRECATED;
+
+/**
+ * @open
+ * @fn email_get_to_from_head(emf_mail_head_t *head, char **to)
+ * @brief Gets to field of a mail from the head object . If head is NULL, this returns EMF_ERROR_INVALID_PARAM. <br>
+ * This function doesn't allocate new memory for to field but just returns to field in head object.
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @param[in] head Specifies the pointer to emf_mail_head_t.
+ * @param[out] to Specifies the pointer to the memory to save to field
+ * @exception none
+ * @see emf_mail_head_t
+ */
+EXPORT_API int email_get_to_from_head(emf_mail_head_t *head, char **to) DEPRECATED;
+
+/**
+ * @open
+ * @fn email_set_to_to_head(emf_mail_head_t *head, char *to)
+ * @brief Sets to field of a mail to emf_mail_head_t(head). If head is NULL, this returns EMF_ERROR_INVALID_PARAM.
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @param[in] head Specifies the pointer to emf_mail_head_t.
+ * @param[in] to Specifies the to field of a mail.
+ * @exception none
+ * @see emf_mail_head_t
+ */
+EXPORT_API int email_set_to_to_head(emf_mail_head_t *head, char *to) DEPRECATED;
+
+/**
+ * @open
+ * @fn email_get_from_from_head(emf_mail_head_t *head, char **from)
+ * @brief Gets from field of a mail from the head object . If head is NULL, this returns EMF_ERROR_INVALID_PARAM. <br>
+ * This function doesn't allocate new memory for from field but just returns from field in head object.
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @param[in] head Specifies the pointer to emf_mail_head_t.
+ * @param[out] from Specifies the pointer to the memory to save from field
+ * @exception none
+ * @see emf_mail_head_t
+ */
+EXPORT_API int email_get_from_from_head(emf_mail_head_t *head, char **from) DEPRECATED;
+
+/**
+ * @open
+ * @fn email_set_from_to_head(emf_mail_head_t *head, char *from)
+ * @brief Sets from field of a mail to emf_mail_head_t(head). If head is NULL, this returns EMF_ERROR_INVALID_PARAM.
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @param[in] head Specifies the pointer to emf_mail_head_t.
+ * @param[in] from Specifies the from field of a mail.
+ * @exception none
+ * @see emf_mail_head_t
+ */
+EXPORT_API int email_set_from_to_head(emf_mail_head_t *head, char *from) DEPRECATED;
+
+/**
+ * @open
+ * @fn email_get_cc_from_head(emf_mail_head_t *head, char **cc)
+ * @brief Gets cc field of a mail from the head object . If head is NULL, this returns EMF_ERROR_INVALID_PARAM. <br>
+ * This function doesn't allocate new memory for cc field but just returns cc field in head object.
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @param[in] head Specifies the pointer to emf_mail_head_t.
+ * @param[out] cc Specifies the pointer to the memory to save cc field
+ * @exception none
+ * @see emf_mail_head_t
+ */
+EXPORT_API int email_get_cc_from_head(emf_mail_head_t *head, char **cc) DEPRECATED;
+
+/**
+ * @open
+ * @fn email_set_cc_to_head(emf_mail_head_t *head, char *cc)
+ * @brief Sets cc field of a mail to emf_mail_head_t(head). If head is NULL, this returns EMF_ERROR_INVALID_PARAM.
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @param[in] head Specifies the pointer to emf_mail_head_t.
+ * @param[in] cc Specifies the cc field of a mail.
+ * @exception none
+ * @see emf_mail_head_t
+ */
+EXPORT_API int email_set_cc_to_head(emf_mail_head_t *head, char *cc) DEPRECATED;
+
+/**
+ * @open
+ * @fn email_get_bcc_from_head(emf_mail_head_t *head, char **bcc)
+ * @brief Gets bcc field of a mail from the head object . If head is NULL, this returns EMF_ERROR_INVALID_PARAM. <br>
+ * This function doesn't allocate new memory for bcc field but just returns bcc field in head object.
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @param[in] head Specifies the pointer to emf_mail_head_t.
+ * @param[out] bcc Specifies the pointer to the memory to save bcc field
+ * @exception none
+ * @see emf_mail_head_t
+ */
+EXPORT_API int email_get_bcc_from_head(emf_mail_head_t *head, char **bcc) DEPRECATED;
+
+/**
+ * @open
+ * @fn email_set_bcc_to_head(emf_mail_head_t *head, char *bcc)
+ * @brief Sets bcc field of a mail to emf_mail_head_t(head). If head is NULL, this returns EMF_ERROR_INVALID_PARAM.
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @param[in] head Specifies the pointer to emf_mail_head_t.
+ * @param[in] bcc Specifies the bcc field of a mail.
+ * @exception none
+ * @see emf_mail_head_t
+ */
+EXPORT_API int email_set_bcc_to_head(emf_mail_head_t *head, char *bcc) DEPRECATED;
+
+/**
+ * @open
+ * @fn email_get_reply_from_head(emf_mail_head_t *head, char **reply)
+ * @brief Gets a reply address of a mail from the head object . If head is NULL, this returns EMF_ERROR_INVALID_PARAM. <br>
+ * This function doesn't allocate new memory for a reply address but just returns a reply address in head object.
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @param[in] head Specifies the pointer to emf_mail_head_t.
+ * @param[out] reply Specifies the pointer to the memory to save a reply address
+ * @exception none
+ * @see emf_mail_head_t
+ */
+EXPORT_API int email_get_reply_from_head(emf_mail_head_t *head, char **reply) DEPRECATED;
+
+/**
+ * @open
+ * @fn email_set_reply_to_head(emf_mail_head_t *head, char *reply)
+ * @brief Sets a reply address of a mail to emf_mail_head_t(head). If head is NULL, this returns EMF_ERROR_INVALID_PARAM.
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @param[in] head Specifies the pointer to emf_mail_head_t.
+ * @param[in] reply Specifies the reply address of a mail.
+ * @exception none
+ * @see emf_mail_head_t
+ */
+EXPORT_API int email_set_reply_to_head(emf_mail_head_t *head, char *reply) DEPRECATED;
+
+/**
+ * @open
+ * @fn email_get_return_path_from_head(emf_mail_head_t *head, char **return_path)
+ * @brief Gets a return path of a mail from the head object . If head is NULL, this returns EMF_ERROR_INVALID_PARAM. <br>
+ * This function doesn't allocate new memory for a return path but just returns a return path in head object.
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @param[in] head Specifies the pointer to emf_mail_head_t.
+ * @param[out] return_path Specifies the pointer to the memory to save a return path
+ * @exception none
+ * @see emf_mail_head_t
+ */
+EXPORT_API int email_get_return_path_from_head(emf_mail_head_t *head, char **return_path) DEPRECATED;
+
+/**
+ * @open
+ * @fn email_set_return_path_to_head(emf_mail_head_t *head, char *return_path)
+ * @brief Sets a return path of a mail to emf_mail_head_t(head). If head is NULL, this returns EMF_ERROR_INVALID_PARAM.
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @param[in] head Specifies the pointer to emf_mail_head_t.
+ * @param[in] return_path Specifies the return path of a mail.
+ * @exception none
+ * @see emf_mail_head_t
+ */
+EXPORT_API int email_set_return_path_to_head(emf_mail_head_t *head, char *return_path) DEPRECATED;
+
+/**
+ * @open
+ * @fn email_get_datetime_from_head(emf_mail_head_t *head, emf_datetime_t *datetime)
+ * @brief Gets datetime of a mail from the head object . If head is NULL, this returns EMF_ERROR_INVALID_PARAM. <br>
+ * This function doesn't allocate new memory for datetime but just returns datetime in head object.
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @param[in] head Specifies the pointer to emf_mail_head_t.
+ * @param[out] datetime Specifies the pointer to the memory to save datetime
+ * @exception none
+ * @see emf_mail_head_t, emf_datetime_t
+ */
+EXPORT_API int email_get_datetime_from_head(emf_mail_head_t *head, emf_datetime_t *datetime) DEPRECATED;
+
+/**
+ * @open
+ * @fn email_set_datetime_to_head(emf_mail_head_t *head, emf_datetime_t datetime)
+ * @brief Sets datetime to emf_mail_head_t(head). If head is NULL, this returns EMF_ERROR_INVALID_PARAM.
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @param[in] head Specifies the pointer to emf_mail_head_t.
+ * @param[in] datetime Specifies the datetime of a mail.
+ * @exception none
+ * @see emf_mail_head_t, emf_datetime_t
+ */
+EXPORT_API int email_set_datetime_to_head(emf_mail_head_t *head, emf_datetime_t datetime) DEPRECATED;
+
+/**
+ * @open
+ * @fn email_get_from_contact_name_from_head(emf_mail_head_t *head, char **from_contact_name)
+ * @brief Gets contact names of from address of a mail from the head object . If head is NULL, this returns EMF_ERROR_INVALID_PARAM. <br>
+ * This function doesn't allocate new memory for contact names but just returns contact names in head object.
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @param[in] head Specifies the pointer to emf_mail_head_t.
+ * @param[out] from_contact_name Specifies the pointer to the memory to save contact names
+ * @exception none
+ * @see emf_mail_head_t
+ */
+EXPORT_API int email_get_from_contact_name_from_head(emf_mail_head_t *head, char **from_contact_name) DEPRECATED;
+
+/**
+ * @open
+ * @fn email_set_from_contact_name_to_head(emf_mail_head_t *head, char *from_contact_name)
+ * @brief Sets contact names of from address of a mail to emf_mail_head_t(head). If head is NULL, this returns EMF_ERROR_INVALID_PARAM.
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @param[in] head Specifies the pointer to emf_mail_head_t.
+ * @param[in] from_contact_name Specifies the contact names
+ * @exception none
+ * @see emf_mail_head_t
+ */
+EXPORT_API int email_set_from_contact_name_to_head(emf_mail_head_t *head, char *from_contact_name) DEPRECATED;
+
+/**
+ * @open
+ * @fn email_get_to_contact_name_from_head(emf_mail_head_t *head, char **to_contact_name)
+ * @brief Gets contact names of to addresses of a mail from the head object . If head is NULL, this returns EMF_ERROR_INVALID_PARAM. <br>
+ * This function doesn't allocate new memory for contact names but just returns contact names in head object.
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @param[in] head Specifies the pointer to emf_mail_head_t.
+ * @param[out] to_contact_name Specifies the pointer to the memory to save contact names
+ * @exception none
+ * @see emf_mail_head_t
+ */
+EXPORT_API int email_get_to_contact_name_from_head(emf_mail_head_t *head, char **to_contact_name) DEPRECATED;
+
+/**
+ * @open
+ * @fn email_set_to_contact_name_to_head(emf_mail_head_t *head, char *to_contact_name)
+ * @brief Sets contact names of to address of a mail to emf_mail_head_t(head). If head is NULL, this returns EMF_ERROR_INVALID_PARAM.
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @param[in] head Specifies the pointer to emf_mail_head_t.
+ * @param[in] to_contact_name Specifies the contact names
+ * @exception none
+ * @see emf_mail_head_t
+ */
+EXPORT_API int email_set_to_contact_name_to_head(emf_mail_head_t *head, char *to_contact_name) DEPRECATED;
+
+/**
+ * @open
+ * @fn email_get_cc_contact_name_from_head(emf_mail_head_t *head, char **cc_contact_name)
+ * @brief Gets contact names of cc addresses of a mail from the head object . If head is NULL, this returns EMF_ERROR_INVALID_PARAM. <br>
+ * This function doesn't allocate new memory for contact names but just returns contact names in head object.
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @param[in] head Specifies the pointer to emf_mail_head_t.
+ * @param[out] cc_contact_name Specifies the pointer to the memory to save contact names
+ * @exception none
+ * @see emf_mail_head_t
+ */
+EXPORT_API int email_get_cc_contact_name_from_head(emf_mail_head_t *head, char **cc_contact_name) DEPRECATED;
+
+/**
+ * @open
+ * @fn email_set_cc_contact_name_to_head(emf_mail_head_t *head, char *cc_contact_name)
+ * @brief Sets contact names of cc addresses of a mail to emf_mail_head_t(head). If head is NULL, this returns EMF_ERROR_INVALID_PARAM.
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @param[in] head Specifies the pointer to emf_mail_head_t.
+ * @param[in] cc_contact_name Specifies the contact names
+ * @exception none
+ * @see emf_mail_head_t
+ */
+EXPORT_API int email_set_cc_contact_name_to_head(emf_mail_head_t *head, char *cc_contact_name) DEPRECATED;
+
+/**
+ * @open
+ * @fn email_get_bcc_contact_name_from_head(emf_mail_head_t *head, char **bcc_contact_name)
+ * @brief Gets contact names of bcc address of a mail from the head object . If head is NULL, this returns EMF_ERROR_INVALID_PARAM. <br>
+ * This function doesn't allocate new memory for contact names but just returns contact names in head object.
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @param[in] head Specifies the pointer to emf_mail_head_t.
+ * @param[out] from_contact_name Specifies the pointer to the memory to save contact names
+ * @exception none
+ * @see emf_mail_head_t
+ */
+EXPORT_API int email_get_bcc_contact_name_from_head(emf_mail_head_t *head, char **bcc_contact_name) DEPRECATED;
+
+/**
+ * @open
+ * @fn email_set_bcc_contact_name_to_head(emf_mail_head_t *head, char *bcc_contact_name)
+ * @brief Sets contact names of bcc addresses of a mail to emf_mail_head_t(head). If head is NULL, this returns EMF_ERROR_INVALID_PARAM.
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @param[in] head Specifies the pointer to emf_mail_head_t.
+ * @param[in] bcc_contact_name Specifies the contact names
+ * @exception none
+ * @see emf_mail_head_t
+ */
+EXPORT_API int email_set_bcc_contact_name_to_head(emf_mail_head_t *head, char *bcc_contact_name) DEPRECATED;
+
+/**
+ * @open
+ * @fn email_get_preview_body_text_from_head(emf_mail_head_t *head, char **preview_body_text)
+ * @brief Gets preview body text of a mail from the head object . If head is NULL, this returns EMF_ERROR_INVALID_PARAM. <br>
+ * This function doesn't allocate new memory for preview text but just returns preview text in head object.
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @param[in] head Specifies the pointer to emf_mail_head_t.
+ * @param[out] preview_body_text Specifies the pointer to the memory to save text
+ * @exception none
+ * @see emf_mail_head_t
+ */
+EXPORT_API int email_get_preview_body_text_from_head(emf_mail_head_t *head, char **preview_body_text) DEPRECATED;
+
+/**
+ * @open
+ * @fn email_set_preview_body_text_to_head(emf_mail_head_t *head, char *preview_body_text)
+ * @brief Sets preview body text of a mail to emf_mail_head_t(head). If head is NULL, this returns EMF_ERROR_INVALID_PARAM.
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @param[in] head Specifies the pointer to emf_mail_head_t.
+ * @param[in] preview_body_text Specifies the preview body text
+ * @exception none
+ * @see emf_mail_head_t
+ */
+EXPORT_API int email_set_preview_body_text_to_head(emf_mail_head_t *head, char *preview_body_text) DEPRECATED;
+
+
+// emf_mail_body_t -------------------------------------------------------------
+/**
+ * @open
+ * @fn email_get_plain_from_body(emf_mail_body_t *body, char **plain)
+ * @brief Gets the absolute path of file to contain email body (Plain Text) from the body object . If body is NULL, this returns EMF_ERROR_INVALID_PARAM. <br>
+ * This function doesn't allocate new memory for the path but just returns the path in body object.<br>
+ * If the body doesn't have a plain text file, *plain will point NULL.
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @param[in] body Specifies the pointer to emf_mail_body_t.
+ * @param[out] plain Specifies the pointer to the memory to save the path of plain text file
+ * @exception none
+ * @see emf_mail_body_t
+ */
+EXPORT_API int email_get_plain_from_body(emf_mail_body_t *body, char **plain) DEPRECATED;
+
+/**
+ * @open
+ * @fn email_set_plain_to_body(emf_mail_body_t *body, char *plain)
+ * @brief Sets the absolute path of file to contain email body (Plain Text) to emf_mail_body_t(body). If head is NULL, this returns EMF_ERROR_INVALID_PARAM.
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @param[in] body Specifies the pointer to emf_mail_body_t.
+ * @param[in] plain Specifies the path of plain text file
+ * @exception none
+ * @see emf_mail_body_t
+ */
+EXPORT_API int email_set_plain_to_body(emf_mail_body_t *body, char *plain) DEPRECATED;
+
+
+/**
+ * @open
+ * @fn email_get_plain_charset_from_body(emf_mail_body_t *body, char **plain_charset)
+ * @brief Gets a character set of plain text from the body object . If body is NULL, this returns EMF_ERROR_INVALID_PARAM. <br>
+ * This function doesn't allocate new memory for a character set of plain, but just returns the character set in body object.
+ * If the body doesn't have a plain text file, *plain_charset will point NULL.
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @param[in] body Specifies the pointer to emf_mail_body_t.
+ * @param[out] plain_charset Specifies the pointer to the memory to save a character set of plain text
+ * @exception none
+ * @see emf_mail_body_t
+ */
+EXPORT_API int email_get_plain_charset_from_body(emf_mail_body_t *body, char **plain_charset) DEPRECATED;
+
+/**
+ * @open
+ * @fn email_set_plain_charset_to_body(emf_mail_body_t *body, char *plain_charset)
+ * @brief Sets a character set of plain text to emf_mail_body_t(body). If head is NULL, this returns EMF_ERROR_INVALID_PARAM.
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @param[in] body Specifies the pointer to emf_mail_body_t.
+ * @param[in] plain_charset Specifies the character set of plain text
+ * @exception none
+ * @see emf_mail_body_t
+ */
+EXPORT_API int email_set_plain_charset_to_body(emf_mail_body_t *body, char *plain_charset) DEPRECATED;
+
+
+/**
+ * @open
+ * @fn email_get_html_from_body(emf_mail_body_t *body, char **html)
+ * @brief Gets the absolute path of file to contain email body (HTML) from the body object . If body is NULL, this returns EMF_ERROR_INVALID_PARAM. <br>
+ * This function doesn't allocate new memory for the path but just returns the path in body object.<br>
+ * If the body doesn't have a html file, *html will point NULL.
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @param[in] body Specifies the pointer to emf_mail_body_t.
+ * @param[out] html Specifies the pointer to the memory to save the path of html file
+ * @exception none
+ * @see emf_mail_body_t
+ */
+EXPORT_API int email_get_html_from_body(emf_mail_body_t *body, char **html) DEPRECATED;
+
+/**
+ * @open
+ * @fn email_set_html_to_body(emf_mail_body_t *body, char *html)
+ * @brief Sets the absolute path of file to contain email body (HTML) to emf_mail_body_t(body). If head is NULL, this returns EMF_ERROR_INVALID_PARAM.
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @param[in] body Specifies the pointer to emf_mail_body_t.
+ * @param[in] html Specifies the path of html file
+ * @exception none
+ * @see emf_mail_body_t
+ */
+EXPORT_API int email_set_html_to_body(emf_mail_body_t *body, char *html) DEPRECATED;
+
+
+/**
+ * @open
+ * @fn email_get_attachment_num_from_body(emf_mail_body_t *body, int *attachment_num)
+ * @brief Gets the number of attachments from the body object . If body is NULL, this returns EMF_ERROR_INVALID_PARAM. <br>
+ * This function doesn't allocate new memory for the attachment_num, but just returns the number of attachments in body object.
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @param[in] body Specifies the pointer to emf_mail_body_t.
+ * @param[out] attachment_num Specifies the pointer to the memory to save the number of attachments
+ * @exception none
+ * @see emf_mail_body_t
+ */
+EXPORT_API int email_get_attachment_num_from_body(emf_mail_body_t *body, int *attachment_num) DEPRECATED;
+
+/**
+ * @open
+ * @fn email_set_attachment_num_to_body(emf_mail_body_t *body, int attachment_num)
+ * @brief Sets the number of attachments to emf_mail_body_t(body). If head is NULL, this returns EMF_ERROR_INVALID_PARAM.
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @param[in] body Specifies the pointer to emf_mail_body_t.
+ * @param[in] attachment_num Specifies the number of attachments
+ * @exception none
+ * @see emf_mail_body_t
+ */
+EXPORT_API int email_set_attachment_num_to_body(emf_mail_body_t *body, int attachment_num) DEPRECATED;
+
+
+/**
+ * @open
+ * @fn email_get_attachment_from_body(emf_mail_body_t *body, emf_attachment_info_t **attachment)
+ * @brief Gets the structure of attachment information from the body object . If body is NULL, this returns EMF_ERROR_INVALID_PARAM. <br>
+ * This function doesn't allocate new memory for the attachment information, but just returns attachment information in body object.
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @param[in] body Specifies the pointer to emf_mail_body_t.
+ * @param[out] attachment_num Specifies the pointer to the memory to save attachment structure
+ * @exception none
+ * @see emf_mail_body_t, emf_attachment_info_t
+ */
+EXPORT_API int email_get_attachment_from_body(emf_mail_body_t *body, emf_attachment_info_t **attachment) DEPRECATED;
+
+/**
+ * @open
+ * @fn email_set_attachment_to_body(emf_mail_body_t *body, emf_attachment_info_t *attachment)
+ * @brief Sets the structure of attachment information to emf_mail_body_t(body). If head is NULL, this returns EMF_ERROR_INVALID_PARAM.
+ *
+ * @return This function returns EMF_ERROR_NONE on success or error code (refer to EMF_ERROR_XXX) on failure.
+ * @param[in] body Specifies the pointer to emf_mail_body_t.
+ * @param[in] attachment Specifies the attachment structure
+ * @exception none
+ * @see emf_mail_body_t
+ */
+EXPORT_API int email_set_attachment_to_body(emf_mail_body_t *body, emf_attachment_info_t *attachment) DEPRECATED;
+
+
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+/**
+* @} @}
+*/
+
+
+#endif /* __EMF_MAPI_RULE_H__ */
+
diff --git a/SLP_EmailService_PG.h b/SLP_EmailService_PG.h
new file mode 100755
index 0000000..4394176
--- /dev/null
+++ b/SLP_EmailService_PG.h
@@ -0,0 +1,1312 @@
+/**
+ *
+ * @ingroup TIZEN_PG
+ * @defgroup EMAILSVC Email Service
+@{
+<h1 class="pg">Introduction</h1>
+ <h2 class="pg">Overview </h2>
+Electronic mail, most commonly abbreviated email or e-mail, is a method of exchanging digital messages. E-mail systems are based on a store-and-forward model in which e-mail server computer systems accept, forward, deliver and store messages on behalf of users, who only need to connect to the e-mail infrastructure, typically an e-mail server, with a network-enabled device for the duration of message submission or retrieval.
+
+ <h2 class="pg">Purpose of Programming Guide</h2>
+This document is mainly aimed at the core functionality of the Email Service. The EMail Service component is implemented to provide EMail service to applications that make use of EMail Engine. Email Engine provides functionality for the user like composing mail, saving mail, sending mail, and creating user mailbox according to the settings. Mobile subscribers can use the Email Engine to perform storage opearations such as save, update, get, delete and transport operations such as send, download and other email operations.
+
+This programming guide is prepared for application developers who will use the email-service. It contains:
+- List of features offered by email-service
+- Information on How to use APIs provided by the email-service
+- Examples
+
+ <h2 class="pg">Target Domain / Application</h2>
+The Email Service Layer can be utilized by any component in the application layer which allow the end user to perform the email related operations such as save, send, download email message and others.
+
+For Example, the Email Service APIs shall be invoked by
+@li Multimedia application when user opts to send media file through email
+@li Email application when user tries to send an email message
+
+ <h2 class="pg">Terminology & Acronyms</h2>
+<table>
+<tr><th>Terminology</th><th>Description</th></tr>
+<tr><td>Email </td><td>Electronic mail</td></tr>
+<tr><td>IMAP</td><td>Internet Message Access Protocol</td></tr>
+<tr><td>SMTP</td><td>Simple mail transfer protocol for sending mails</td></tr>
+<tr><td>POP3</td><td>Post office protocol for receiving mails</td></tr>
+<tr><td>RFC822</td><td>Describes mail header, to address, cc, bcc etc. formats and decoding and encoding standards. </td></tr>
+<tr><td>OMA </td><td>Open Moblie Alliance</td></tr>
+</table>
+
+
+@}
+
+@defgroup Email_Architecture 1. Email Service Architecture
+@ingroup EMAILSVC
+@{
+<h1 class="pg">Email-service Architecture</h1>
+ <h2 class="pg">System Architecture</h2>
+@image html email_image001.png
+
+ <h2 class="pg">Process Architecture</h2>
+@image html email_image002.png email-service Process view
+
+@image html email_image003.png email-service Process architecture
+
+Whenever an application wants to use email-service, it will call APIs from Email MAPI layer. Email MAPI layer APIs will internally call APIs provided by email framework module.
+@}
+
+@defgroup Email_Feature 2. Email Service Feature
+@ingroup EMAILSVC
+@{
+<h1 class="pg">Email-service Features</h1>
+<table>
+<tr><th>Feature </th><th>API Reference</th></tr>
+<tr><td>Account Operation</td>
+<td>
+@n email_add_account()
+@n email_delete_account()
+@n email_update_account()
+@n email_get_account()
+@n email_get_account_list()
+@n email_free_account()
+@n email_validate_account()
+</td></tr>
+
+<tr><td>mailbox Operation </td>
+<td>
+@n email_add_mailbox()
+@n email_delete_mailbox()
+@n email_update_mailbox()
+@n email_get_mailbox_list()
+@n email_get_mailbox_by_name()
+@n email_get_child_mailbox_list()
+@n email_get_mailbox_by_mailbox_type()
+</td></tr>
+
+<tr><td>Message Operation </td>
+<td>
+@n email_add_message()
+@n email_update_message()
+@n email_count_message()
+@n email_delete_message()
+@n email_delete_all_message_in_mailbox()
+@n email_clear_mail_data()
+@n email_add_attachment()
+@n email_delete_attachment()
+@n email_get_info()
+@n email_free_mail_info()
+@n email_get_header_info()
+@n email_free_header_info()
+@n email_get_body_info()
+@n email_free_body_info()
+@n email_get_attachment_info()
+@n email_free_attachment_info()
+@n email_get_mail()
+@n email_modify_mail_flag()
+@n email_modify_seen_flag()
+@n email_modify_extra_mail_flag()
+@n email_move_mail_to_mailbox()
+@n email_move_all_mails_to_mailbox()
+@n email_count_message_with_draft_flag()
+@n email_count_message_on_sending()
+@n email_get_mailbox_list()
+@n email_free_mailbox()
+@n email_free_mail()
+@n email_get_mail_flag()
+@n email_free_mail_list()
+@n email_release_mail()
+@n email_retry_send_mail()
+@n email_create_db_full()
+@n email_get_mailbox_name_by_mail_id()
+@n email_cancel_send_mail()
+@n email_count_message_all_mailboxes()
+@n email_get_latest_unread_mail_id()
+@n email_get_max_mail_count()
+@n email_get_disk_space_usage()
+</td></tr>
+
+<tr><td>Network Operation </td>
+<td>
+@n email_send_mail()
+@n email_sync_header()
+@n email_download_body()
+@n email_download_attachment()
+@n email_cancel_job()
+@n email_get_pending_job()
+@n email_get_network_status()
+@n email_send_report()
+@n email_send_saved()
+@n email_get_imap_mailbox_list()
+@n email_sync_local_activity()
+</td></tr>
+
+<tr><td>Rule Operation </td>
+<td>
+@n email_get_rule()
+@n email_get_rule_list()
+@n email_add_rule()
+@n email_update_rule()
+@n email_delete_rule()
+@n email_free_rule()
+</td></tr>
+
+<tr><td>Control Operation </td>
+<td>
+@n email_init_storage()
+@n email_open_db()
+@n email_close_db()
+@n email_service_begin()
+@n email_service_end()
+</td></tr>
+</table>
+@}
+
+
+
+@defgroup Use_Case1_account Account Operation
+@ingroup EMAIL_USECASES
+@{
+ <h2 class="pg">Account Operation </h2>
+Account Operations are a set of operations to manage email accounts like add, update, delete or get account related details.
+
+Structure:
+emf_account_t
+<table>
+<tr><td>API</td>
+<td>Return Value / Exceptions</td></tr>
+
+<tr><td>int email_add_account(emf_account_t* account)</td>
+<td>Returns EMF_ERROR_NONE on success or negative value on failure@n Remarks: - Memory for param emf_account_t* account should be allocated and deallocated by Application</td></tr>
+
+<tr><td>int email_delete_account(int account_id) </td>
+<td>Returns EMF_ERROR_NONE on success or negative value on failure</td></tr>
+
+<tr><td>int email_update_account(int account_id , emf_account_t* new_account) </td>
+<td>Returns EMF_ERROR_NONE on success or negative value on failure@n Remarks: - Memory for param emf_account_t* new_account should be allocated and deallocated by Application</td></tr>
+
+<tr><td>int email_get_account(int account_id, int pulloption, emf_account_t** account) </td>
+<td>Returns EMF_ERROR_NONE on success or negative value on failure@n Remarks: - Memory allocation for param account will happen in email_get_account (). To free this memory, application should call email_free_account ()</td></tr>
+
+<tr><td>int email_get_account_list(emf_account_t** account_list, int* count) </td>
+<td>Returns EMF_ERROR_NONE on success or negative value on failure@n Remarks: Memory allocation for param ccount_list will happen in email_get_account_list (). To free this memory, application should call email_free_account () </td></tr>
+
+<tr><td>int email_free_account(emf_account_t** account_list, int count) </td>
+<td>Returns EMF_ERROR_NONE on success or negative value on failure</td></tr>
+
+<tr><td>int email_validate_account(int account_id, unsigned* handle)</td>
+<td>Returns EMF_ERROR_NONE on success or negative value on failure</td></tr>
+</table>
+
+<b>Sample Code</b>
+@li Add account
+@code
+/* Add account */
+
+/* Assign values for new account */
+emf_account_t *account = NULL;
+
+account = malloc(sizeof(emf_account_t));
+memset(account, 0x00, sizeof(emf_account_t));
+
+account->account_bind_type = 1;
+account->retrieval_mode = 1;
+account->use_security = 1;
+account->sending_server_type = EMF_SERVER_TYPE_SMTP;
+account->sending_port_num = EMF_SMTP_PORT;
+account->sending_auth = 1;
+account->flag1 = 2;
+account->account_bind_type = 1;
+account->account_name = strdup("gmail");
+account->display_name = strdup("Tom");
+account->email_addr = strdup("tom@gmail.com");
+account->reply_to_addr = strdup("tom@gmail.com");
+account->return_addr = strdup("tom@gmail.com");
+account->receiving_server_type = EMF_SERVER_TYPE_POP3;
+account->receiving_server_addr = strdup("pop3.gmail.com");
+account->port_num = 995;
+account->use_security = 1;
+account->retrieval_mode = EMF_IMAP4_RETRIEVAL_MODE_ALL;
+account->user_name = strdup("tom");
+account->password = strdup("tioimi");
+account->sending_server_type = EMF_SERVER_TYPE_SMTP;
+account->sending_server_addr = strdup("smtp.gmail.com");
+account->sending_port_num = 587;
+account->sending_security = 0x02;
+account->sending_auth = 1;
+account->sending_user = strdup("tom@gmail.com");
+account->sending_password = strdup("tioimi");
+account->pop_before_smtp = 0;
+account->apop = 0;
+account->flag1 = 2;
+account->flag2 = 1;
+account->preset_account = 1;
+account->logo_icon_path = strdup("Logo Icon Path");
+account->target_storage = 0;
+account->options.priority = 3;
+account->options.keep_local_copy = 0;
+account->options.req_delivery_receipt = 0;
+account->options.req_read_receipt = 0;
+account->options.download_limit = 0;
+account->options.block_address = 0;
+account->options.block_subject = 0;
+account->options.display_name_from = strdup("Display name from");
+account->options.reply_with_body = 0;
+account->options.forward_with_files = 0;
+account->options.add_myname_card = 0;
+account->options.add_signature = 0;
+account->options.signature= strdup("Signature");
+account->check_interval = 0;
+
+if(EMF_ERROR_NONE != email_add_account(account))
+ /* failure */
+else
+{
+ /* success */
+ if(account_id)
+ *account_id = account->account_id; /* Use this returned account id when calling APIs which need it */
+}
+
+/* free account */
+email_free_account(&account, 1);
+
+@endcode
+
+@li Get account
+@code
+/* Get account */
+
+emf_account_t *account = NULL;
+int account_id = 1; /* account id to be gotten */
+
+if(EMF_ERROR_NONE != email_get_account(account_id,GET_FULL_DATA,&account))
+ /* failure */
+else
+ /* success */
+
+/* free account */
+email_free_account(&account, 1);
+
+@endcode
+
+@li Update account
+@code
+/* Update account */
+
+emf_account_t *new_account = NULL;
+int account_id = 1; /* account id to be updated */
+
+/* Get account to be updated */
+if(EMF_ERROR_NONE != email_get_account(account_id,GET_FULL_DATA,&new_account))
+ /* failure */
+else
+ /* success */
+
+/* Set the new values */
+new_account->flag1 = 1;
+new_account->account_name = strdup("gmail");
+new_account->display_name = strdup("Tom001");
+new_account->options.keep_local_copy = 1;
+new_account->check_interval = 55;
+
+if(EMF_ERROR_NONE != email_update_account(account_id,new_account))
+ /* failure */
+else
+ /* success */
+
+/* free account */
+email_free_account(&new_account, 1);
+
+@endcode
+
+@li Delete account
+@code
+/* Delete account */
+
+int account_id = 1; /* account id to be deleted */
+
+if(EMF_ERROR_NONE != email_delete_account(account_id))
+ /* failure */
+else
+ /* success */
+
+@endcode
+
+
+@li Get list of accounts
+@code
+/* Get list of accounts */
+
+emf_account_t *account_list = NULL;
+int count = 0;
+int i;
+
+if(EMF_ERROR_NONE != email_get_account_list(&account_list,&count))
+ /* failure */
+else
+{
+ /* success */
+ for ( i = 0; i < count; i++ )
+ {
+ /* Do something with each account */
+ printf("account id : %d\n", account_list[i].account_id);
+ }
+}
+
+/* free account */
+email_free_account(&account_list,count);
+
+@endcode
+
+@li Validate account - try to connect to server
+@code
+/* Validate account - try to connect to server */
+unsigned account_handle = 0;
+int account_id = 1;
+
+if(EMF_ERROR_NONE != email_validate_account(account_id,&account_handle))
+ /* failure */
+else
+ /* success */
+@endcode
+
+<b>Flow Diagram</b>
+@image html email_image004.png
+@}
+
+@defgroup Use_Case2_folder mailbox Operation
+@ingroup EMAIL_USECASES
+@{
+ <h2 class="pg">mailbox Operation </h2>
+mailbox Operations are a set of operations to manage email mailboxes like add, update, delete or get mailbox related details.
+
+Structure:
+emf_mailbox_t
+
+<table>
+<tr><td>API</td><td>Return Value / Exceptions</td></tr>
+
+<tr><td>int email_add_mailbox(emf_mailbox_t* new_mailbox, int on_server, unsigned* handle) </td>
+<td>Returns EMF_ERROR_NONE on success or negative value on failure@n Remarks: - Memory for param emf_mailbox_t* new_mailbox should be allocated and deallocated by Application </td></tr>
+
+<tr><td>int email_delete_mailbox(emf_mailbox_t* mailbox, int on_server, unsigned* handle) </td>
+<td>Returns EMF_ERROR_NONE on success or negative value on failure@n Remarks: - Memory for param emf_mailbox_t* mailbox should be allocated and deallocated by Application</td></tr>
+
+<tr><td>int email_update_mailbox(emf_mailbox_t*old_mailbox, emf_mailbox_t* new_mailbox)</td>
+<td>Returns EMF_ERROR_NONE on success or negative value on failure@n Remarks: - Memory for params emf_mailbox_t* old_mailbox and emf_mailbox_t* new_mailbox should be allocated and deallocated by Application</td></tr>
+
+<tr><td>int email_get_mailbox_list(int account_id, int local_yn, emf_mailbox_t** mailbox_list, int* count)</td>
+<td>Returns EMF_ERROR_NONE on success or negative value on failure@n Remarks: - Memory allocation for param mailbox_list will happen in email_get_mailbox_list (). To free this memory application should call email_free_mailbox</td></tr>
+
+<tr><td>int email_get_mailbox_by_name(int account_id, const char *pMailboxName, emf_mailbox_t **pMailbox)</td>
+<td>Returns EMF_ERROR_NONE on success or negative value on failure@n Remarks: - Memory allocation for param pMailbox will happen in email_get_mailbox_by_name (). To free this memory application should call email_free_mailbox</td></tr>
+
+<tr><td>int email_get_child_mailbox_list(int account_id, const char *parent_mailbox, emf_mailbox_t** mailbox_list, int* count)</td>
+<td>Returns EMF_ERROR_NONE on success or negative value on failure@n Remarks: - Memory allocation for param mailbox_list will happen in email_get_child_mailbox_list (). To free this memory application should call email_free_mailbox</td></tr>
+
+<tr><td>int email_get_mailbox_by_mailbox_type(int account_id, emf_mailbox_type_e mailbox_type, emf_mailbox_t** mailbox)</td>
+<td>Returns EMF_ERROR_NONE on success or negative value on failure@n Remarks: - Memory allocation for param mailbox_list will happen in email_get_mailbox_by_mailbox_type (). To free this memory application should call email_free_mailbox</td></tr>
+</table>
+
+<b>Sample Code</b>
+
+@li Create new mailbox
+@code
+emf_mailbox_t *mailbox = NULL, *new_mailbox = NULL;
+unsigned handle = 0;
+int on_server = 0;
+
+mailbox = malloc(sizeof(emf_mailbox_t));
+memset(mailbox, 0x00, sizeof(emf_mailbox_t));
+
+mailbox->name = strdup("Personal");
+mailbox->alias = strdup("selfuse");
+mailbox->account_id = 1;
+mailbox->local = on_server;
+mailbox->mailbox_type = 7;
+
+/* create new mailbox */
+if(EMF_ERROR_NONE != email_add_mailbox(mailbox,on_server,&handle))
+ /* failure */
+else
+ /* success */
+
+@endcode
+
+
+@li Update and Delete mailbox
+@code
+emf_mailbox_t *mailbox = NULL, *new_mailbox = NULL;
+int on_server = 0;
+unsigned handle = 0;
+
+new_mailbox = malloc(sizeof(emf_mailbox_t));
+memset(new_mailbox, 0x00, sizeof(emf_mailbox_t));
+
+new_mailbox->name = strdup("Personal001");
+
+/* update mailbox */
+if(EMF_ERROR_NONE != email_update_mailbox(mailbox,new_mailbox))
+ /* failure */
+else
+ /* success */
+
+/* delete mailbox */
+if(EMF_ERROR_NONE != email_delete_mailbox(mailbox,on_server,&handle))
+ /* failure */
+else
+ /* success */
+
+email_free_mailbox(&mailbox, 1);
+email_free_mailbox(&new_mailbox, 1);
+
+@endcode
+
+@li Get list of mailboxes
+@code
+int account_id = 1;
+int local_yn = 0;
+emf_mailbox_t* mailbox_list = NULL;
+int count = 0;
+
+/*get list of mailboxes */
+if(EMF_ERROR_NONE != email_get_mailbox_list(account_id, local_yn, &mailbox_list, &count))
+ /* failure */
+else
+{
+ /* success */
+ email_free_mailbox(&mailbox_list,count);
+}
+@endcode
+
+<b>Flow Diagram</b>
+@image html email_image005.png
+@}
+
+@defgroup Use_Case3_message Message Operation
+@ingroup EMAIL_USECASES
+@{
+ <h2 class="pg">Message Operation </h2>
+Message Operations are a set of operations to manage email messages like add, update, delete or get message related details.
+
+Structure:
+emf_mail_t
+<table>
+<tr><td>API</td>
+<td>Return Value / Exceptions</td></tr>
+
+<tr><td>int email_add_message(emf_mail_t* mail, emf_mailbox_t* mailbox, int with_server) </td>
+<td>Returns EMF_ERROR_NONE on success or negative value on failure@n Remarks: - Memory for params emf_mail_t* mail and emf_mailbox_t* mailbox should be allocated and deallocated by Application</td></tr>
+
+<tr><td>int email_update_message(int mail_id, emf_mail_t* mail) </td>
+<td>Returns EMF_ERROR_NONE on success or negative value on failure@n Remarks: - Memory for param emf_mail_t* mail should be allocated and deallocated by Application</td></tr>
+
+<tr><td>int email_count_message(emf_mailbox_t* mailbox, int* total, int* unseen) </td>
+<td>Returns EMF_ERROR_NONE on success or negative value on failure@n Remarks: - Memory for param emf_mailbox_t* mailbox should be allocated and deallocated by Application</td></tr>
+
+<tr><td>int email_delete_message(emf_mailbox_t* mailbox, int *mail_ids, int num, int from_server) </td>
+<td>Returns EMF_ERROR_NONE on success or negative value on failure@n Remarks: - Memory for params int *mail_ids and mf_mailbox_t* mailbox should be allocated and deallocated by Application</td></tr>
+
+<tr><td>int email_delete_all_message_in_mailbox(emf_mailbox_t* mailbox, int from_server) </td>
+<td>Returns EMF_ERROR_NONE on success or negative value on failure@n Remarks: - Memory for param mf_mailbox_t* mailbox should be allocated and deallocated by Application</td></tr>
+
+<tr><td>int email_clear_mail_data() </td>
+<td>Returns EMF_ERROR_NONE on success or negative value on failure</td></tr>
+
+<tr><td>int email_add_attachment(emf_mailbox_t* mailbox, int mail_id, emf_attachment_info_t* attachment)</td>
+<td>Returns EMF_ERROR_NONE on success or negative value on failure@n Remarks: - Memory for param mf_mailbox_t* mailbox and mf_attachment_info_t* attachment hould be allocated and deallocated by Application</td></tr>
+
+<tr><td>int email_delete_attachment(emf_mailbox_t * mailbox, int mail_id, const char * attachment_id)</td>
+<td>Returns EMF_ERROR_NONE on success or negative value on failure@n Remarks: - Memory for param emf_mailbox_t* mailbox should be allocated and deallocated by Application</td></tr>
+
+<tr><td>int email_get_info(emf_mailbox_t* mailbox, int mail_id, emf_mail_info_t** info) </td>
+<td>Returns EMF_ERROR_NONE on success or negative value on failure.@n Remarks:
+-# Memory for param emf_mailbox_t* mailbox should be allocated and deallocated by Application
+-# Memory allocation for param emf_mail_info_t** info will happen in email_get_info (). To free this memory application should call email_free_mail_info () </td></tr>
+
+<tr><td>int email_free_mail_info(emf_mail_info_t** info_list, int count) </td>
+<td>Returns EMF_ERROR_NONE on success or negative value on failure.</td></tr>
+
+<tr><td>int email_get_header_info(emf_mailbox_t* mailbox, int mail_id, emf_mail_head_t** head) </td>
+<td>Returns EMF_ERROR_NONE on success or negative value on failure.@n Remarks:
+-# Memory for param emf_mailbox_t* mailbox should be allocated and deallocated by Application
+-# Memory allocation for param emf_mail_head_t** head will happen in email_get_header_info (). To free this memory, application should call email_free_header_info () </td></tr>
+
+<tr><td>int email_free_header_info(emf_mail_head_t** head_list, int count) </td>
+<td>Returns EMF_ERROR_NONE on success or negative value on failure.</td></tr>
+
+<tr><td>int email_get_body_info(emf_mailbox_t* mailbox, int mail_id ,emf_mail_body_t** body) </td>
+<td>Returns EMF_ERROR_NONE on success or negative value on failure.@n Remarks:
+-# Memory for param emf_mailbox_t* mailbox should be allocated and deallocated by Application
+-# Memory allocation for param emf_mail_body_t** body will happen in email_get_body_info (). To free this memory, application should call email_free_body_info () </td></tr>
+
+<tr><td>int email_free_body_info(emf_mail_body_t** body_list, int count) </td>
+<td>Returns EMF_ERROR_NONE on success or negative value on failure.</td></tr>
+
+<tr><td>int email_get_attachment_info(emf_mailbox_t* mailbox, int mail_id, const char* attachment_id, emf_attachment_info_t** attachment)</td>
+<td>Returns EMF_ERROR_NONE on success or negative value on failure.@n Remarks:
+-# Memory for param emf_mailbox_t* mailbox should be allocated and deallocated by Application
+-# Memory allocation for param emf_attachment_info_t** attachment will happen in email_get_attachment_info (). To free this memory, application should call email_free_attachment_info () </td></tr>
+
+<tr><td>int email_free_attachment_info(emf_attachment_info_t** atch_info) </td>
+<td>Returns EMF_ERROR_NONE on success or negative value on failure.</td></tr>
+
+<tr><td>int email_get_mail(emf_mailbox_t* mailbox, int mail_id, emf_mail_t** mail) </td>
+<td>Returns EMF_ERROR_NONE on success or negative value on failure.@n Remarks:
+-# Memory for param emf_mailbox_t* mailbox should be allocated and deallocated by Application
+-# Memory allocation for param emf_mail_t** mail will happen in email_get_mail (). To free this memory, application should call email_free_mail () </td></tr>
+
+<tr><td>int email_modify_mail_flag(int mail_id, emf_mail_flag_t new_flag, int onserver) </td>
+<td>Returns EMF_ERROR_NONE on success or negative value on failure.</td></tr>
+
+<tr><td>int email_modify_seen_flag(int *mail_ids, int num, int seen_flag, int onserver) </td>
+<td>Returns EMF_ERROR_NONE on success or negative value on failure@n Remarks: - Memory for param int *mail_ids should be allocated and deallocated by Application</td></tr>
+
+<tr><td>int email_modify_extra_mail_flag(int mail_id, emf_extra_flag_t new_flag) </td>
+<td>Returns EMF_ERROR_NONE on success or negative value on failure</td></tr>
+
+<tr><td>int email_move_mail_to_mailbox(int *mail_ids, int num, emf_mailbox_t* new_mailbox) </td>
+<td>Returns EMF_ERROR_NONE on success or negative value on failure@n Remarks: - Memory for params int *mail_ids and emf_mailbox_t* new_mailbox should be allocated and deallocated by Application</td></tr>
+
+<tr><td>int email_move_all_mails_to_mailbox(emf_mailbox_t* src_mailbox, emf_mailbox_t* new_mailbox) </td>
+<td>Returns EMF_ERROR_NONE on success or negative value on failure@n Remarks: - Memory for params emf_mailbox_t* src_mailbox and emf_mailbox_t* new_mailbox should be allocated and deallocated by Application</td></tr>
+
+<tr><td>int email_count_message_with_draft_flag(emf_mailbox_t* mailbox, int* total) </td>
+<td>Returns EMF_ERROR_NONE on success or negative value on failure@n Remarks: - Memory for param emf_mailbox_t* mailbox should be allocated and deallocated by Application</td></tr>
+
+<tr><td>int email_count_message_on_sending(emf_mailbox_t* mailbox, int* total) </td>
+<td>Returns EMF_ERROR_NONE on success or negative value on failure@n Remarks: - Memory for param emf_mailbox_t* mailbox should be allocated and deallocated by Application</td></tr>
+
+<tr><td>int email_get_mailbox_list(int account_id, emf_mailbox_t** mailbox_list, int* count ) </td>
+<td>Returns EMF_ERROR_NONE on success or negative value on failure@n Remarks: - Memory allocation for param emf_mailbox_t** mailbox_list will happen in email_get_mailbox_list (). To free this memory, application should call email_free_mailbox ()</td></tr>
+
+<tr><td>int email_free_mailbox(emf_mailbox_t** mailbox_list, int count) </td>
+<td>Returns EMF_ERROR_NONE on success or negative value on failure</td></tr>
+
+<tr><td>int email_free_mail(emf_mail_t** mail_list, int count) </td>
+<td>Returns EMF_ERROR_NONE on success or negative value on failure</td></tr>
+
+<tr><td>int email_get_mail_flag(int account_id, int mail_id, emf_mail_flag_t* mail_flag) </td>
+<td>Returns EMF_ERROR_NONE on success or negative value on failure</td></tr>
+
+<tr><td>int email_retry_send_mail( int mail_id, int timeout_in_sec) </td>
+<td>Returns EMF_ERROR_NONE on success or negative value on failure</td></tr>
+
+<tr><td>int email_create_db_full()</td>
+<td>Returns EMF_ERROR_NONE on success or negative value on failure</td></tr>
+
+<tr><td>int email_get_mailbox_name_by_mail_id(int mail_id, char **pMailbox_name)</td>
+<td>Returns EMF_ERROR_NONE on success or negative value on failure</td></tr>
+
+<tr><td>int email_cancel_send_mail( int mail_id) </td>
+<td>Returns EMF_ERROR_NONE on success or negative value on failure</td></tr>
+
+<tr><td>int email_count_message_all_mailboxes(emf_mailbox_t* mailbox, int* total, int* unseen) </td>
+<td>Returns EMF_ERROR_NONE on success or negative value on failure</td></tr>
+
+<tr><td>int email_get_latest_unread_mail_id(int account_id, int *pMailID) </td>
+<td>Returns EMF_ERROR_NONE on success or negative value on failure</td></tr>
+
+<tr><td>int email_get_max_mail_count(int *Count) </td>
+<td>Returns EMF_ERROR_NONE on success or negative value on failure</td></tr>
+
+<tr><td>int email_get_disk_space_usage(unsigned long *total_size)</td>
+<td>Returns EMF_ERROR_NONE on success or negative value on failure</td></tr>
+</table>
+
+<b>Sample Code</b>
+
+@li Add, Update, Count and Delete message
+@code
+emf_mailbox_t *mailbox = NULL;
+emf_mail_t *mail = NULL;
+int on_server = 0, account_id = 0, mail_id = 0;
+char *pFilePath = "/tmp/mail.txt";
+
+/* Fill mail data to save */
+mailbox = malloc(sizeof(emf_mailbox_t));
+memset(mailbox, 0x00, sizeof(emf_mailbox_t));
+
+mail = malloc(sizeof(emf_mail_t));
+memset(mail, 0x00, sizeof(emf_mail_t));
+
+mail->info = malloc(sizeof(emf_mail_info_t));
+memset(mail->info, 0x00, sizeof(emf_mail_info_t));
+mail->info->account_id = /*account_id*/;
+
+mail->head = malloc(sizeof(emf_mail_head_t));
+memset(mail->head, 0x00, sizeof(emf_mail_head_t));
+
+mail->body = malloc(sizeof(emf_mail_body_t));
+memset(mail->body, 0x00, sizeof(emf_mail_body_t));
+
+mail->head->to = strdup("\"ActiveSync8\" <ActiveSync8@test.local>");
+mail->head->cc = strdup("bapina@gawab.com");
+mail->head->bcc= strdup("<tom@gmail.com>");
+mail->head->subject = strdup("save.mailbox...");
+
+mail->body->plain = strdup(pFilePath);
+
+mailbox->name = strdup("DRAFT");
+mailbox->account_id = account_id;
+
+/* Add message */
+if(EMF_ERROR_NONE != email_add_message(mail, mailbox, on_server))
+ /* failure */
+else
+{
+ /* success */
+ mail_id = mail->info->uid;
+}
+
+/* Update message */
+/* variable 'mail' should be filled with data on DB. */
+/* And change values you want to update. */
+mail->head->subject = strdup("save.mailbox again...");
+
+if(EMF_ERROR_NONE != email_update_message(mail_id,mail))
+ /* failure */
+else
+ /* success */
+
+/* Count message */
+int total = 0, unseen = 0;
+
+/* Get the total number of mails and the number of unseen mails */
+if(EMF_ERROR_NONE != email_count_message(mailbox,&total,&unseen))
+ /* failure */
+else
+ /* success */
+
+/* Delete message */
+int *mail_ids, num = 0;
+
+if(EMF_ERROR_NONE != email_delete_message(mailbox,mail_ids,num,on_server))
+ /* failure */
+else
+ /* success */
+@endcode
+
+@li Delete all message in a specific mailbox
+@code
+/* Delete all message in mailbox */
+emf_mailbox_t *mailbox = NULL;
+int on_server = 0;
+
+mailbox = malloc(sizeof(emf_mailbox_t));
+memset(mailbox, 0x00, sizeof(emf_mailbox_t));
+
+mailbox->account_id = 1;
+mailbox->name = strdup("INBOX");
+
+if( EMF_ERROR_NONE != email_delete_all_message_in_mailbox(mailbox, on_server))
+ /* failure */
+else
+
+ /* success */
+@endcode
+
+
+@li Clear all messages
+@code
+/* clear mail data */
+if(EMF_ERROR_NONE != email_clear_mail_data())
+ /* failure */
+else
+ /* success */
+@endcode
+
+@li Get mail information : information, header, body, mail
+@code
+emf_mailbox_t *mailbox = NULL;
+emf_mail_info_t *mail_info = NULL;
+int mail_id = 1, account_id = 1; /* mail id and its account id to be gotten */
+
+mailbox = malloc(sizeof(emf_mailbox_t));
+memset(mailbox, 0x00, sizeof(emf_mailbox_t));
+
+/* Get mail info */
+mailbox->account_id = account_id;
+
+if ( EMF_ERROR_NONE != email_get_info(mailbox, mail_id, &mail_info))
+ /* failure */
+else
+ /* success */
+
+/* free mail info */
+email_free_mail_info(&mail_info,1);
+
+/* Get mail header info */
+emf_mail_head_t *head = NULL;
+
+mailbox->account_id = account_id;
+
+if(EMF_ERROR_NONE != email_get_header_info(mailbox,mail_id,&head))
+ /* failure */
+else
+ /* success */
+
+/* free mail header info */
+email_free_header_info(&head,1);
+
+/* Get mail body info */
+emf_mail_body_t *head = NULL;
+
+mailbox->account_id = account_id;
+
+if(EMF_ERROR_NONE != email_get_body_info(mailbox,mail_id,&body))
+ /* failure */
+else
+ /* success */
+
+/* free mail body info */
+email_free_body_info(&body,1);
+
+/* Get mail info*/
+emf_mail_t *mail = NULL;
+int mail_id = 0;
+
+if(EMF_ERROR_NONE != email_get_mail(mailbox,mail_id,&mail))
+ /* failure */
+else
+ /* success */
+
+/* free mail body info */
+email_free_mail(&mail,1);
+
+/* free mailbox*/
+email_free_mailbox(&mailbox,1);
+
+@endcode
+
+
+
+@li Modify flag
+@code
+emf_mail_flag_t newflag = {0};
+int mail_id = 0;
+int on_server = 0;
+
+/* Modify mail flag*/
+if(EMF_ERROR_NONE != email_modify_mail_flag(mail_id,newflag,on_server))
+ /* failure */
+else
+ /* success */
+
+int mail_ids[] = {1, 2};
+int num = 2;
+int seen_flag = 0;
+int on_server = 0;
+
+/* Modify seen flag*/
+if(EMF_ERROR_NONE != email_modify_seen_flag(mail_ids, num, seen_flag,on_server))
+ /* failure */
+else
+ /* success */
+
+/* Modify extra flag*/
+int mail_id = 1;
+if(EMF_ERROR_NONE != email_modify_extra_mail_flag(mail_id, newflag))
+ /* failure */
+else
+ /* success */
+@endcode
+
+
+@li Move mail
+@code
+int mail_id[],account_id = 1;
+emf_mailbox_t *mailbox = NULL;
+char *mailbox_name = "INBOX";
+
+mailbox = malloc(sizeof(emf_mailbox_t));
+memset(mailbox, 0x00, sizeof(emf_mailbox_t));
+
+mailbox->account_id = account_id;
+mailbox->name = mailbox_name;
+
+/* Move mail to given mailbox*/
+if(EMF_ERROR_NONE != email_move_mail_to_mailbox(/*mail_id*/,/*num*/,mailbox))
+ /* failure */
+else
+ /* success */
+
+/* free mailbox*/
+email_free_mailbox(&mailbox,1);
+
+emf_mailbox_t *src_mailbox = NULL,*dest_mailbox = NULL;
+int src_account_id = 0, dest_account_id = 0;
+char * src_mailbox_name = NULL, *dest_mailbox_name = NULL;
+
+src_mailbox = malloc(sizeof(emf_mailbox_t));
+memset(src_mailbox, 0x00, sizeof(emf_mailbox_t));
+
+dest_mailbox = malloc(sizeof(emf_mailbox_t));
+memset(dest_mailbox, 0x00, sizeof(emf_mailbox_t));
+
+src_mailbox->account_id = /*src_account_id*/;
+src_mailbox->name = /*src_mailbox_name*/
+
+dest_mailbox->account_id = /*dest_account_id*/;
+dest_mailbox->name = /*dest_mailbox_name*/
+
+/*move all mails to given mailbox*/
+if(EMF_ERROR_NONE != email_move_all_mails_to_mailbox(src_mailbox,dest_mailbox))
+ /* failure */
+else
+ /* success */
+
+/* free mailbox*/
+email_free_mailbox(&src_mailbox,1);
+email_free_mailbox(&dest_mailbox,1);
+
+int account_id = 0, total = 0;
+emf_mailbox_t *mailbox = NULL;
+char *mailbox_name = NULL;
+
+mailbox = malloc(sizeof(emf_mailbox_t));
+memset(mailbox, 0x00, sizeof(emf_mailbox_t));
+
+mailbox->account_id = /*account_id*/;
+mailbox->name = /*mailbox_name*/
+
+/*count of draft msgs*/
+if(EMF_ERROR_NONE != email_count_message_with_draft_flag(mailbox,&total))
+ /* failure */
+else
+ /* success */
+
+/* free mailbox*/
+email_free_mailbox(&mailbox,1);
+@endcode
+
+@li Count of msgs sent from given folde
+@code
+int account_id = 0, total = 0;
+emf_mailbox_t *mailbox = NULL;
+char *mailbox_name = NULL;
+
+mailbox = malloc(sizeof(emf_mailbox_t));
+memset(mailbox, 0x00, sizeof(emf_mailbox_t));
+
+mailbox->account_id = /*account_id*/;
+mailbox->name = /*mailbox_name*/
+
+/*count of msgs sent from given mailbox*/
+if(EMF_ERROR_NONE != email_count_message_on_sending(mailbox,&total))
+ /* failure */
+else
+ /* success */
+
+/* free mailbox*/
+email_free_mailbox(&mailbox,1);
+
+@endcode
+
+
+@li Get mailbox list
+@code
+
+emf_mailbox_t* mailbox_list = NULL;
+int account_id = 1, count = 0;
+
+/* Get mailbox list*/
+if(EMF_ERROR_NONE != email_get_mailbox_list(account_id,&mailbox_list,&count))
+ /* failure */
+else
+ /* success */
+
+/* free mailbox list*/
+email_free_mailbox(&mailbox,count);
+@endcode
+
+
+@li Get mailBox name by mailID
+@code
+/* Get mailBox name by mailID*/
+int mail_id = 1;
+char *pMailbox_name=strdup("INBOX");
+err = email_get_mailbox_name_by_mail_id(mail_id,&pMailbox_name);
+
+free(pMailbox_name);
+
+@endcode
+
+
+@li Cancel sending mail
+@code
+
+/* email_cancel_send_mail*/
+int mail_id = 1; /* mail id of a mail which is on sending */
+err = email_cancel_send_mail(mail_id);
+
+@endcode
+
+
+
+@li Get the Total count and Unread count of all mailboxes
+@code
+/* Get the Total count and Unread count of all mailboxes */
+emf_mailbox_t* mailbox = NULL;
+int account_id = 1, total = 0, unseen = 0;
+char *mailbox_name = NULL;
+
+mailbox = malloc(sizeof(emf_mailbox_t));
+memset(mailbox, 0x00, sizeof(emf_mailbox_t));
+
+mailbox->account_id = /*account_id*/;
+mailbox->name = /*mailbox_name*/
+
+err = email_count_message_all_mailboxes(mailbox,&total,&unseen);
+
+@endcode
+
+<b>Flow Diagram</b>s
+@image html email_image006.png
+
+@image html email_image007.png
+
+@image html email_image008.png
+@}
+
+@defgroup Use_Case4_network Network Operation
+@ingroup EMAIL_USECASES
+@{
+ <h2 class="pg">Network Operation </h2>
+Network Operations are a set of operations to manage email send, receive and cancel related details.
+
+Structure:
+emf_option_t
+<table>
+<tr><td>API</td>
+<td>Return Value / Exceptions</td></tr>
+
+<tr><td>int email_send_mail( emf_mailbox_t* mailbox, int mail_id, emf_option_t* sending_option, unsigned* handle)</td>
+<td>Returns EMF_ERROR_NONE on success or negative value on failure@n Remarks:
+-# Memory allocation and de-allocation for input param is to be done by application.</td></tr>
+
+<tr><td>int email_sync_header(emf_mailbox_t* mailbox, unsigned* handle)</td>
+<td>Returns EMF_ERROR_NONE on success or negative value on failure@n Remarks:
+-# Memory allocation and de-allocation for input param is to be done by application.</td></tr>
+
+<tr><td>int email_download_body(emf_mailbox_t* mailbox, int mail_id, int with_attachment, unsigned* handle) </td>
+<td>Returns EMF_ERROR_NONE on success or negative value on failure@n Remarks:
+-# Memory allocation and de-allocation for input param is to be done by application.</td></tr>
+
+<tr><td>int email_download_attachment(emf_mailbox_t* mailbox, int mail_id, const char* nth, unsigned* handle)</td>
+<td>Returns EMF_ERROR_NONE on success or negative value on failure.</td></tr>
+
+<tr><td>int email_cancel_job(int account_id, int handle)</td>
+<td>Returns EMF_ERROR_NONE on success or negative value on failure.</td></tr>
+
+<tr><td>int email_get_pending_job(emf_action_t action, int account_id, int mail_id, emf_event_status_type_t * status)</td>
+<td>Returns EMF_ERROR_NONE on success or negative value on failure.</td></tr>
+
+<tr><td>void email_get_network_status(int* on_sending, int* on_receiving) </td>
+<td>Returns EMF_ERROR_NONE on success or negative value on failure</td></tr>
+
+<tr><td>int email_send_report(emf_mail_t* mail, unsigned* handle) </td>
+<td>Returns EMF_ERROR_NONE on success or negative value on failure@n Remarks:
+-# Memory allocation and de-allocation for input param is to be done by application.</td></tr>
+
+<tr><td>int email_send_saved(int account_id, emf_option_t* sending_option, unsigned* handle)</td>
+<td>Returns EMF_ERROR_NONE on success or negative value on failure@n Remarks:
+-# Memory allocation and de-allocation for input param is to be done by application.</td></tr>
+
+<tr><td>int email_get_imap_mailbox_list(int account_id, const char* mailbox, unsigned* handle)</td>
+<td>Returns EMF_ERROR_NONE on success or negative value on failure.</td></tr>
+
+<tr><td>int email_sync_local_activity(int account_id)</td>
+<td>Returns EMF_ERROR_NONE on success or negative value on failure.</td></tr>
+</table>
+
+<b>Sample Code</b>
+@li Send a mail
+@code
+/* Send a mail */
+emf_mailbox_t mbox;
+emf_mail_t *mail = NULL;
+emf_mail_head_t *head =NULL;
+emf_mail_body_t *body =NULL;
+emf_attachment_info_t attachment;
+emf_option_t option;
+int account_id = 1;
+int err = EMF_ERROR_NONE;
+
+mail =( emf_mail_t *)malloc(sizeof(emf_mail_t));
+head =( emf_mail_head_t *)malloc(sizeof(emf_mail_head_t));
+body =( emf_mail_body_t *)malloc(sizeof(emf_mail_body_t));
+mail->info =( emf_mail_info_t*) malloc(sizeof(emf_mail_info_t));
+memset(mail->info, 0x00, sizeof(emf_mail_info_t));
+
+memset(&mbox, 0x00, sizeof(emf_mailbox_t));
+memset(&option, 0x00, sizeof(emf_option_t));
+memset(mail, 0x00, sizeof(emf_mail_t));
+memset(head, 0x00, sizeof(emf_mail_head_t));
+memset(body, 0x00, sizeof(emf_mail_body_t));
+memset(&attachment, 0x00, sizeof(emf_attachment_info_t));
+
+option.keep_local_copy = 1;
+mbox.account_id = account_id;
+mbox.name = strdup("OUTBOX");
+head->to=strdup("test@test.com";
+head->subject =strdup("test");
+body->plain = strdup("/tmp/mail.txt");
+mail->info->account_id = account_id;
+mail->info->flags.draft = 1;
+mail->body = body;
+mail->head = head;
+attachment.name = strdup("attach");
+attachment.savename = strdup("tmp/mail.txt");
+attachment.next = NULL;
+mail->body->attachment = &attachment;
+mail->body->attachment_num = 1;
+if(EMF_ERROR_NONE == email_add_message(mail,&mbox,1))
+{
+ err= email_send_mail(&mbox, mail->info->uid,&option,&handle);
+}
+@endcode
+
+@li Download header of new emails from mail server
+@code
+/* Download header of new emails from mail server*/
+emf_mailbox_t mbox;
+int account_id = 1;
+int err = EMF_ERROR_NONE;
+unsigned handle = 0;
+
+memset(&mbox, 0x00, sizeof(emf_mailbox_t));
+
+mbox.account_id = account_id;
+mbox.name = strdup("INBOX");
+err = email_sync_header (&mbox,&handle);
+@endcode
+
+
+@li Download email body from server
+@code
+
+/*Download email body from server*/
+emf_mailbox_t mbox;
+int mail_id = 1;
+int account_id = 1;
+int handle = 0;
+int err = EMF_ERROR_NONE;
+
+memset(&mailbox, 0x00, sizeof(emf_mailbox_t));
+mbox.account_id = account_id;
+mbox.name = strdup("INBOX");
+err= email_download_body (&mbox,mail_id,0,&handle);
+
+@li Download a email nth-attachment from server
+@code
+/*Download a email nth-attachment from server*/
+emf_mailbox_t mailbox;
+int mail_id = 1;
+int account_id = 1;
+char arg[50]; /* Input attachment number need to be download */
+unsigned handle = 0;
+int err = EMF_ERROR_NONE;
+
+memset(&mailbox, 0x00, sizeof(emf_mailbox_t));
+mailbox.name = "INBOX";
+mailbox.account_id = account_id;
+err=email_download_attachment(&mailbox,mail_id,arg,&handle);
+@endcode
+
+<b>Flow Diagram</b>
+@image html email_image009.png
+@}
+
+@defgroup Use_Case5_rule Rule Operation
+@ingroup EMAIL_USECASES
+@{
+ <h2 class="pg">Rule Operation</h2>
+Rule Operations are a set of operations to manage email rules like add, get, delete or update rule related details.
+
+Structure:
+emf_rule_t
+<table>
+<tr><td>API</td>
+<td>Return Value / Exceptions</td></tr>
+
+<tr><td>int email_get_rule(int filter_id, emf_rule_t** filtering_set)</td>
+<td>Returns EMF_ERROR_NONE on success or negative value on failure@n Remarks:
+-# Memory allocation for the param emf_rule_t** filtering_set will be done in this api.
+-# De-allocation is to be done by application.</td></tr>
+
+<tr><td>int email_get_rule_list(emf_rule_t** filtering_set, int* count)</td>
+<td>Returns EMF_ERROR_NONE on success or negative value on failure@n Remarks:
+-# Memory allocation for the param emf_rule_t** filtering_set will be done in this api.
+-# De-allocation is to be done by application.</td></tr>
+
+<tr><td>int email_add_rule(emf_rule_t* filtering_set) </td>
+<td>Returns EMF_ERROR_NONE on success or negative value on failure@n Remarks:
+-# Memory allocation and de-allocation is to be done by application.
+-# Use email_free_rule to free allocated memory.</td></tr>
+
+<tr><td>int email_update_rule(int filter_id, emf_rule_t* new_set) </td>
+<td>Returns EMF_ERROR_NONE on success or negative value on failure@n Remarks:
+-# Memory allocation and de-allocation is to be done by application.</td></tr>
+-# Use email_free_rule to free allocated memory.
+
+<tr><td>int email_delete_rule(int filter_id)</td>
+<td>Returns EMF_ERROR_NONE on success or negative value on failure.</td></tr>
+
+<tr><td>int email_free_rule(emf_rule_t** filtering_set, int count)</td>
+<td>Returns EMF_ERROR_NONE on success or negative value on failure</td></tr>
+</table>
+
+<b>Sample Code</b>
+@li Filter Operation
+@code
+int err = EMF_ERROR_NONE;
+emf_rule_t* rule = NULL;
+int filter_id = 1;
+
+/* Get a information of filtering*/
+err = email_get_rule (filter_id,&rule);
+err = email_free_rule (&rule,1);
+
+/* Get all filterings */
+int count = 0;
+err = email_get_rule_list(&rule,&count);
+
+
+/* Add a filter information */
+err = email_add_rule (rule);
+err = email_free_rule (&rule,1);
+
+/* Change a filter information */
+err = email_update_rule (filter_id,rule);
+err = email_free_rule (&rule,1);
+
+/* Delete a filter information*/
+err = email_delete_rule (filter_id);
+
+/* Free allocated memory */
+err = email_free_rule (&rule,1);
+@endcode
+
+<b>Flow Diagram</b>
+@image html email_image010.png
+@}
+
+@defgroup Use_Case6_control Control Operation
+@ingroup EMAIL_USECASES
+@{
+ <h2 class="pg">Control Operation</h2>
+Control Operations are a set of operations to manage Email MAPI Layer initialization.
+The Application which will use the MAPIs MUST initialize IPC proxy and conntect to Email FW database before calling other APIs.
+And it MUST finalize IPC proxy and disconnect to the DB if the application doesn't use APIs.
+
+<table>
+<tr><td>API</td>
+<td>Return Value / Exceptions</td></tr>
+
+<tr><td>int email_init_storage(void)</td>
+<td>Returns EMF_ERROR_NONE on success or negative value on failure</td></tr>
+
+<tr><td>int email_open_db(void)</td>
+<td>Returns EMF_ERROR_NONE on success or negative value on failure
+@n Remarks:
+@n Application should call email_close_db once db operation is over</td></tr>
+
+<tr><td>int email_close_db(void)</td>
+<td>Returns EMF_ERROR_NONE on success or negative value on failure
+@n Remarks: -
+@n This API should be called only if email_open_db () is called.</td></tr>
+
+<tr><td>int email_service_begin(void)</td>
+<td>Returns EMF_ERROR_NONE on success or negative value on failure</td></tr>
+
+<tr><td>int email_service_end(void)</td>
+<td>Returns EMF_ERROR_NONE on success or negative value on failure
+@n Remarks:
+@n This API should be called only if email_service_begin () is called.</td></tr>
+</table>
+
+<b>Sample Code</b>
+@li Initialize and Finalize Email MAPI Layer
+@code
+int err = EMF_ERROR_NONE;
+
+/* Initialize Email MAPI Layer before calling other MAPIs */
+if(EMF_ERROR_NONE == email_service_begin())
+{
+ if(EMF_ERROR_NONE != email_open_db())
+ {
+ return false;
+ }
+ if(EMF_ERROR_NONE != email_init_storage())
+ {
+ return false;
+ }
+}
+
+/* Call other MAPIs */
+
+......
+
+/* Finalize Email MAPI Layer when finishing application */
+err = email_close_db();
+err = email_service_end();
+@endcode
+
+<b>Flow Diagram</b>
+@image html email_image011.png
+@}
+
+@addtogroup Email_Feature
+@{
+<h1 class="pg">System Configuration</h1>
+ <h2 class="pg">Files to be included</h2>
+Emf_Mapi.h
+@n Emf_Mapi_Types.h
+
+ <h2 class="pg">System Initialization and De-Initialization</h2>
+email_service_begin is used to initialize email-service at boot time.
+@n email_service_end is used to deinitialize email-service at shutdown.
+@n These two are separate executables.
+
+ <h2 class="pg">Variable Configuration</h2>
+NA
+
+ <h2 class="pg">Build Environment</h2>
+If the Application wants to use email-service Module, make sure that the following package should be included in the Makefile.
+
+email-service-dev
+
+ <h2 class="pg">Runtime Environment</h2>
+NA
+@}
+
+@defgroup EMAL_Appendix 4. Reference
+@ingroup EMAILSVC
+@{
+<h1 class="pg">Appendix</h1>
+ <h2 class="pg">Email</h2>
+@image html email_image012.png
+
+- Alice composed a message using MUA (Mail User Agent). Alice enters the e-mail address of her correspondent, and hits the "send" button.
+- MUA format the message using MIME and uses Simple mail Transfer Protocol to send the message to local MTA (Mail Transfer Agent) i,e smtp.a.org run by Alices ISP (Internet Service provider).
+- The MTA looks at the destination address provided in the SMTP protocol i,e bob@b.org. An Internet e-mail address is a string of the form localpart@exampledomain. The part before the @ sign is the local part of the address, often the username of the recipient, and the part after the @ sign is a domain name. The MTA resolves a domain name to determine the fully qualified domain name of the mail exchange server in the Domain Name System (DNS).
+- The DNS Server for the b.org domain, ns.b.org, responds with an MX Records listing the mail exchange servers for that domain, in this case mx.b.org, a server run by Bob's ISP.
+- smtp.a.org sends the message to mx.b.org using SMTP, which delivers it to the mailbox of the user bob.
+- Bob presses the "get mail" button in his MUA, which picks up the message using the Post Office Protocol (POP3).
+
+ <h2 class="pg">RFC</h2>
+-# RFC 2821-SMTP(Simple Mail Transfer Protocol)
+-# RFC 1939-POP3(Post Office Protocol)
+-# RFC 3501-IMAP4(Internate message protocol)
+@}
+
+*/
+
+/**
+* @defgroup EMAILSVC
+ @{
+* @defgroup EMAIL_USECASES 3. API Description
+*
+@{
+<h1 class="pg">API Description</h1>
+This section describes APIs and shows the example of using them.
+@}
+ @}
+*/
+
diff --git a/cl.sh b/cl.sh
new file mode 100755
index 0000000..2a0afdd
--- /dev/null
+++ b/cl.sh
@@ -0,0 +1 @@
+fakeroot debian/rules clean
diff --git a/config/.email-service.db b/config/.email-service.db
new file mode 100644
index 0000000..b6a4d7c
--- /dev/null
+++ b/config/.email-service.db
Binary files differ
diff --git a/config/.email-service.db-journal b/config/.email-service.db-journal
new file mode 100644
index 0000000..56022b7
--- /dev/null
+++ b/config/.email-service.db-journal
Binary files differ
diff --git a/dbuild.sh b/dbuild.sh
new file mode 100755
index 0000000..9753e52
--- /dev/null
+++ b/dbuild.sh
@@ -0,0 +1,2 @@
+dpkg-buildpackage -sa -rfakeroot -I.git
+#dpkg -i ../email-service-0_0.1.0-1_armel.deb ../email-service-dev_0.1.0-1_armel.deb
diff --git a/debian/changelog b/debian/changelog
new file mode 100755
index 0000000..3b755d1
--- /dev/null
+++ b/debian/changelog
@@ -0,0 +1,7 @@
+email-service (0.3.6-4) unstable; urgency=low
+
+ * New API function 'email_find_mail_on_server'
+ * Git : slp/pkgs/e/email-service
+ * Tag : email-service_0.3.6-4
+
+ -- Kyuho Jo <kyuho.jo@samsung.com> Wed, 08 Feb 2012 21:13:33 +0900
diff --git a/debian/compat b/debian/compat
new file mode 100755
index 0000000..7ed6ff8
--- /dev/null
+++ b/debian/compat
@@ -0,0 +1 @@
+5
diff --git a/debian/control b/debian/control
new file mode 100755
index 0000000..7b80c16
--- /dev/null
+++ b/debian/control
@@ -0,0 +1,32 @@
+Source: email-service
+Section: main/libs
+Priority: extra
+Maintainer: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com>, Sang-Hun Chung <sanghun.chung@samsung.com>
+Uploaders: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com>, Sang-Hun Chung <sanghun.chung@samsung.com>, Changseok Oh <seok.oh@samsung.com>
+Build-Depends: debhelper (>= 5), libglib2.0-dev, libdbus-1-dev, libdbus-glib-1-dev, libslp-db-util-dev, libxml2-dev, libwbxml2-dev, libssl-dev, drm-service-dev, libslp-pm-dev, libuw-imap-toolkit-dev, openssl, dlog-dev, libslp-setting-dev, libcontacts-service-dev, libheynoti-dev, libss-client-dev, libalarm-dev, libaccounts-svc-dev, libdevman-dev, libmm-player-dev, libmm-session-dev, libnotification-dev, libeina-dev, libcurl-dev
+Standards-Version: 3.7.2
+Homepage: N/A
+
+Package: email-service-dev
+XB-Public-Package: yes
+XB-Generate-Docs: yes
+Section: main/libdevel
+Architecture: any
+Depends: ${shlibs:Depends}, ${misc:Depends}, email-service-0 (= ${Source-Version})
+Description: E-mail Framework Middleware Development package
+ email-service-dev
+
+Package: email-service-0
+Section: main/libs
+Architecture: any
+Depends: ${shlibs:Depends}, ${misc:Depends}, libuw-imap-toolkit-0
+Description: E-mail Framework Middleware Development package
+ email-service-0
+
+Package: email-service-dbg
+Section: debug
+Architecture: any
+Depends: ${shlibs:Depends}, ${misc:Depends}, email-service-0 (= ${Source-Version})
+Description: Debug for use with email-service
+ email-service-dbg : for debug
+
diff --git a/debian/copyright b/debian/copyright
new file mode 100755
index 0000000..4479dae
--- /dev/null
+++ b/debian/copyright
@@ -0,0 +1,15 @@
+Copyright (c) 2000 - 2011 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.
diff --git a/debian/dirs b/debian/dirs
new file mode 100755
index 0000000..ca882bb
--- /dev/null
+++ b/debian/dirs
@@ -0,0 +1,2 @@
+usr/bin
+usr/sbin
diff --git a/debian/docs b/debian/docs
new file mode 100755
index 0000000..e69de29
--- /dev/null
+++ b/debian/docs
diff --git a/debian/email-service-0.install b/debian/email-service-0.install
new file mode 100755
index 0000000..3f74411
--- /dev/null
+++ b/debian/email-service-0.install
@@ -0,0 +1,4 @@
+/usr/lib/*.so
+/usr/lib/*.so.*
+/usr/bin/email-service
+/opt/apps/email-service/*
diff --git a/debian/email-service-0.postinst b/debian/email-service-0.postinst
new file mode 100755
index 0000000..10eff1c
--- /dev/null
+++ b/debian/email-service-0.postinst
@@ -0,0 +1,487 @@
+#!/bin/sh
+
+#################################################################
+# Add preset account information
+#################################################################
+echo "[EMAIL-SERVICE] Start adding preset account information..."
+
+#################################################################
+# Email Settings
+#################################################################
+
+if [ ${USER} = "root" ]
+then
+
+ ## Setting
+ # Sending
+ vconftool set -g 5000 -t bool db/Services/Email/Sending/KeepCopy "1"
+ vconftool set -g 5000 -t bool db/Services/Email/Sending/SendMeCopy "1"
+ vconftool set -g 5000 -t bool db/Services/Email/Sending/ReqDeliveryRep "0"
+ vconftool set -g 5000 -t bool db/Services/Email/Sending/ReqReadRep "0"
+ vconftool set -g 5000 -t int db/Services/Email/Sending/Priority "1"
+ vconftool set -g 5000 -t string db/Services/Email/Sending/ActiveAccount ""
+ vconftool set -g 5000 -t bool db/Services/Email/Sending/IncBodyReply "1"
+ vconftool set -g 5000 -t bool db/Services/Email/Sending/IncAttachFwd "1"
+ # Receiving
+ vconftool set -g 5000 -t int db/Services/Email/Receiving/AutoPoll "0"
+ vconftool set -g 5000 -t int db/Services/Email/Receiving/PollTime "0"
+ vconftool set -g 5000 -t int db/Services/Email/Receiving/SendReadRep "2"
+ vconftool set -g 5000 -t int db/Services/Email/Receiving/Reclimit "0"
+ vconftool set -g 5000 -t int db/Services/Email/Receiving/FetchOption "0"
+ vconftool set -g 5000 -t bool db/Services/Email/Receiving/KeepServer "1"
+ vconftool set -g 5000 -t int db/Services/Email/Receiving/ServDelOption "1"
+
+ vconftool set -g 5000 -t int db/Services/Email/NbAccount "6"
+
+ ## Accounts
+
+ # Gmail
+ vconftool set -g 5000 -t string db/Services/Email/1/General/NetworkName "default"
+ vconftool set -g 5000 -t string db/Services/Email/1/General/AccountName "Gmail"
+ vconftool set -g 5000 -t string db/Services/Email/1/General/EmailAddr ""
+ vconftool set -g 5000 -t string db/Services/Email/1/General/UserId ""
+ vconftool set -g 5000 -t string db/Services/Email/1/General/Password ""
+ vconftool set -g 5000 -t string db/Services/Email/1/General/LoginType "username_type"
+
+ # MailboxType : pop3(0), imap4(1) -> pop3(1), imap4(2) in email-service
+ vconftool set -g 5000 -t int db/Services/Email/1/Incoming/MailboxType "1"
+ vconftool set -g 5000 -t string db/Services/Email/1/Incoming/ServAddr "imap.gmail.com"
+ vconftool set -g 5000 -t int db/Services/Email/1/Incoming/Port "993"
+ vconftool set -g 5000 -t int db/Services/Email/1/Incoming/Secure "1"
+ vconftool set -g 5000 -t bool db/Services/Email/1/Incoming/Apop "0"
+ vconftool set -g 5000 -t bool db/Services/Email/1/Incoming/AutoEmailSync "0"
+ vconftool set -g 5000 -t bool db/Services/Email/1/Incoming/IncludeAttach "0"
+ vconftool set -g 5000 -t int db/Services/Email/1/Incoming/ImapFetchOpt "1"
+
+ vconftool set -g 5000 -t string db/Services/Email/1/Outgoing/ServAddr "smtp.gmail.com"
+ vconftool set -g 5000 -t int db/Services/Email/1/Outgoing/Port "465"
+ vconftool set -g 5000 -t bool db/Services/Email/1/Outgoing/SmtpAuth "0"
+ vconftool set -g 5000 -t int db/Services/Email/1/Outgoing/Secure "1"
+ vconftool set -g 5000 -t bool db/Services/Email/1/Outgoing/SameIdPwd "1"
+ vconftool set -g 5000 -t bool db/Services/Email/1/Outgoing/PopBeforeSmtp "0"
+
+ # Hotmail
+ vconftool set -g 5000 -t string db/Services/Email/2/General/NetworkName "default"
+ vconftool set -g 5000 -t string db/Services/Email/2/General/AccountName "Hotmail"
+ vconftool set -g 5000 -t string db/Services/Email/2/General/EmailAddr ""
+ vconftool set -g 5000 -t string db/Services/Email/2/General/UserId ""
+ vconftool set -g 5000 -t string db/Services/Email/2/General/Password ""
+ vconftool set -g 5000 -t string db/Services/Email/2/General/LoginType "username_type"
+
+ # MailboxType : pop3(0), imap4(1) -> pop3(1), imap4(2) in email-service
+ vconftool set -g 5000 -t int db/Services/Email/2/Incoming/MailboxType "0"
+ vconftool set -g 5000 -t string db/Services/Email/2/Incoming/ServAddr "pop3.live.com"
+ vconftool set -g 5000 -t int db/Services/Email/2/Incoming/Port "995"
+ vconftool set -g 5000 -t int db/Services/Email/2/Incoming/Secure "1"
+ vconftool set -g 5000 -t bool db/Services/Email/2/Incoming/Apop "0"
+ vconftool set -g 5000 -t bool db/Services/Email/2/Incoming/AutoEmailSync "0"
+ vconftool set -g 5000 -t bool db/Services/Email/2/Incoming/IncludeAttach "0"
+ vconftool set -g 5000 -t int db/Services/Email/2/Incoming/ImapFetchOpt "1"
+
+ vconftool set -g 5000 -t string db/Services/Email/2/Outgoing/ServAddr "smtp.live.com"
+ vconftool set -g 5000 -t int db/Services/Email/2/Outgoing/Port "587"
+ vconftool set -g 5000 -t bool db/Services/Email/2/Outgoing/SmtpAuth "0"
+ vconftool set -g 5000 -t int db/Services/Email/2/Outgoing/Secure "2"
+ vconftool set -g 5000 -t bool db/Services/Email/2/Outgoing/SameIdPwd "1"
+ vconftool set -g 5000 -t bool db/Services/Email/2/Outgoing/PopBeforeSmtp "0"
+
+ # AOL
+ vconftool set -g 5000 -t string db/Services/Email/3/General/NetworkName "default"
+ vconftool set -g 5000 -t string db/Services/Email/3/General/AccountName "AOL"
+ vconftool set -g 5000 -t string db/Services/Email/3/General/EmailAddr ""
+ vconftool set -g 5000 -t string db/Services/Email/3/General/UserId ""
+ vconftool set -g 5000 -t string db/Services/Email/3/General/Password ""
+ vconftool set -g 5000 -t string db/Services/Email/3/General/LoginType "username_type"
+
+ # MailboxType : pop3(0), imap4(1) -> pop3(1), imap4(2) in email-service
+ vconftool set -g 5000 -t int db/Services/Email/3/Incoming/MailboxType "1"
+ vconftool set -g 5000 -t string db/Services/Email/3/Incoming/ServAddr "imap.aol.com"
+ vconftool set -g 5000 -t int db/Services/Email/3/Incoming/Port "143"
+ vconftool set -g 5000 -t int db/Services/Email/3/Incoming/Secure "0"
+ vconftool set -g 5000 -t bool db/Services/Email/3/Incoming/Apop "0"
+ vconftool set -g 5000 -t bool db/Services/Email/3/Incoming/AutoEmailSync "0"
+ vconftool set -g 5000 -t bool db/Services/Email/3/Incoming/IncludeAttach "0"
+ vconftool set -g 5000 -t int db/Services/Email/3/Incoming/ImapFetchOpt "0"
+
+ vconftool set -g 5000 -t string db/Services/Email/3/Outgoing/ServAddr "smtp.aol.com"
+ vconftool set -g 5000 -t int db/Services/Email/3/Outgoing/Port "587"
+ vconftool set -g 5000 -t bool db/Services/Email/3/Outgoing/SmtpAuth "0"
+ vconftool set -g 5000 -t int db/Services/Email/3/Outgoing/Secure "0"
+ vconftool set -g 5000 -t bool db/Services/Email/3/Outgoing/SameIdPwd "1"
+ vconftool set -g 5000 -t bool db/Services/Email/3/Outgoing/PopBeforeSmtp "0"
+
+ # Yahoo
+ vconftool set -g 5000 -t string db/Services/Email/6/General/NetworkName "default"
+ vconftool set -g 5000 -t string db/Services/Email/6/General/AccountName "Yahoomail"
+ vconftool set -g 5000 -t string db/Services/Email/6/General/EmailAddr ""
+ vconftool set -g 5000 -t string db/Services/Email/6/General/UserId ""
+ vconftool set -g 5000 -t string db/Services/Email/6/General/Password ""
+ vconftool set -g 5000 -t string db/Services/Email/6/General/LoginType "username_type"
+
+ # MailboxType : pop3(0), imap4(1) -> pop3(1), imap4(2) in email-service
+ vconftool set -g 5000 -t int db/Services/Email/6/Incoming/MailboxType "0"
+ vconftool set -g 5000 -t string db/Services/Email/6/Incoming/ServAddr "pop.mail.yahoo.co.kr"
+ vconftool set -g 5000 -t int db/Services/Email/6/Incoming/Port "995"
+ vconftool set -g 5000 -t int db/Services/Email/6/Incoming/Secure "1"
+ vconftool set -g 5000 -t bool db/Services/Email/6/Incoming/Apop "0"
+ vconftool set -g 5000 -t bool db/Services/Email/6/Incoming/AutoEmailSync "0"
+ vconftool set -g 5000 -t bool db/Services/Email/6/Incoming/IncludeAttach "0"
+ vconftool set -g 5000 -t int db/Services/Email/6/Incoming/ImapFetchOpt "1"
+
+ vconftool set -g 5000 -t string db/Services/Email/6/Outgoing/ServAddr "smtp.mail.yahoo.co.kr"
+ vconftool set -g 5000 -t int db/Services/Email/6/Outgoing/Port "465"
+ vconftool set -g 5000 -t bool db/Services/Email/6/Outgoing/SmtpAuth "0"
+ vconftool set -g 5000 -t int db/Services/Email/6/Outgoing/Secure "1"
+ vconftool set -g 5000 -t bool db/Services/Email/6/Outgoing/SameIdPwd "1"
+ vconftool set -g 5000 -t bool db/Services/Email/6/Outgoing/PopBeforeSmtp "0"
+
+fi
+
+
+################################################################################################
+
+if [ ${USER} = "root" ]
+then
+
+vconftool set -t string db/email/preset_account/aol/sending_address "smtp.aol.com"
+vconftool set -t int db/email/preset_account/aol/sending_port "587"
+vconftool set -t int db/email/preset_account/aol/sending_ssl "0"
+vconftool set -t int db/email/preset_account/aol/receiving_type "2"
+vconftool set -t string db/email/preset_account/aol/receiving_address "imap.aol.com"
+vconftool set -t int db/email/preset_account/aol/receiving_port "143"
+vconftool set -t int db/email/preset_account/aol/receiving_ssl "0"
+
+vconftool set -t string db/email/preset_account/gmail/sending_address "smtp.gmail.com"
+vconftool set -t int db/email/preset_account/gmail/sending_port "465"
+vconftool set -t int db/email/preset_account/gmail/sending_ssl "1"
+vconftool set -t int db/email/preset_account/gmail/receiving_type "2"
+# for POP3 server
+#vconftool set -t string db/email/preset_account/gmail/receiving_address "pop.gmail.com"
+#vconftool set -t int db/email/preset_account/gmail/receiving_port "995"
+# for IMAP4 server
+vconftool set -t string db/email/preset_account/gmail/receiving_address "imap.gmail.com"
+vconftool set -t int db/email/preset_account/gmail/receiving_port "993"
+vconftool set -t int db/email/preset_account/gmail/receiving_ssl "1"
+
+vconftool set -t string db/email/preset_account/yahoo/sending_address "smtp.mail.yahoo.co.kr"
+vconftool set -t int db/email/preset_account/yahoo/sending_port "465"
+vconftool set -t int db/email/preset_account/yahoo/sending_ssl "1"
+vconftool set -t int db/email/preset_account/yahoo/receiving_type "1"
+vconftool set -t string db/email/preset_account/yahoo/receiving_address "pop.mail.yahoo.co.kr"
+vconftool set -t int db/email/preset_account/yahoo/receiving_port "995"
+vconftool set -t int db/email/preset_account/yahoo/receiving_ssl "1"
+
+vconftool set -t string db/email/preset_account/hotmail/sending_address "smtp.live.com"
+vconftool set -t int db/email/preset_account/hotmail/sending_port "587"
+vconftool set -t int db/email/preset_account/hotmail/sending_ssl "2"
+vconftool set -t int db/email/preset_account/hotmail/receiving_type "1"
+vconftool set -t string db/email/preset_account/hotmail/receiving_address "pop3.live.com"
+vconftool set -t int db/email/preset_account/hotmail/receiving_port "995"
+vconftool set -t int db/email/preset_account/hotmail/receiving_ssl "1"
+
+# for Active Sync - Let email app create this key
+#vconftool set -t int db/email_handle/active_sync_handle "0"
+
+# for contact sync - sync from the first contact change
+vconftool set -t int db/email/last_sync_time "0"
+
+# for contact sync - sync from the first contact change
+vconftool set -t int db/email/slot_size "100"
+
+# for badge
+vconftool set -t int db/badge/org.tizen.email "0"
+
+fi
+
+echo "[EMAIL-SERVICE] Finish adding preset account information"
+
+
+#################################################################
+# Set executin script
+#################################################################
+echo "[EMAIL-SERVICE] Set executing script ..."
+EMAIL_SERVICE_EXEC_SCRIPT=/etc/rc.d/init.d/email-service
+EMAIL_SERVICE_BOOT_SCRIPT=/etc/rc.d/rc3.d/S70email-service
+EMAIL_SERVICE_FASTBOOT_SCRIPT=/etc/rc.d/rc5.d/S70email-service
+echo '#!/bin/sh' > ${EMAIL_SERVICE_EXEC_SCRIPT}
+echo '/usr/bin/email-service &' >> ${EMAIL_SERVICE_EXEC_SCRIPT}
+chmod 755 ${EMAIL_SERVICE_EXEC_SCRIPT}
+rm -rf ${EMAIL_SERVICE_BOOT_SCRIPT}
+rm -rf ${EMAIL_SERVICE_FASTBOOT_SCRIPT}
+ln -s ${EMAIL_SERVICE_EXEC_SCRIPT} ${EMAIL_SERVICE_BOOT_SCRIPT}
+ln -s ${EMAIL_SERVICE_EXEC_SCRIPT} ${EMAIL_SERVICE_FASTBOOT_SCRIPT}
+echo "[EMAIL-SERVICE] Finish executing script ..."
+
+#################################################################
+# Create DB file and tables.
+#################################################################
+echo "[EMAIL-SERVICE] Creating Email Tables ..."
+sqlite3 /opt/dbspace/.email-service.db 'PRAGMA journal_mode = PERSIST;
+CREATE TABLE mail_account_tbl
+(
+ account_bind_type INTEGER,
+ account_name VARCHAR(51),
+ receiving_server_type INTEGER,
+ receiving_server_addr VARCHAR(51),
+ email_addr VARCHAR(129),
+ user_name VARCHAR(51),
+ password VARCHAR(51),
+ retrieval_mode INTEGER,
+ port_num INTEGER,
+ use_security INTEGER,
+ sending_server_type INTEGER,
+ sending_server_addr VARCHAR(51),
+ sending_port_num INTEGER,
+ sending_auth INTEGER,
+ sending_security INTEGER,
+ sending_user VARCHAR(51),
+ sending_password VARCHAR(51),
+ display_name VARCHAR(31),
+ reply_to_addr VARCHAR(129),
+ return_addr VARCHAR(129),
+ account_id INTEGER PRIMARY KEY,
+ keep_on_server INTEGER,
+ flag1 INTEGER,
+ flag2 INTEGER,
+ pop_before_smtp INTEGER,
+ apop INTEGER,
+ logo_icon_path VARCHAR(256),
+ preset_account INTEGER,
+ target_storage INTEGER,
+ check_interval INTEGER,
+ priority INTEGER,
+ keep_local_copy INTEGER,
+ req_delivery_receipt INTEGER,
+ req_read_receipt INTEGER,
+ download_limit INTEGER,
+ block_address INTEGER,
+ block_subject INTEGER,
+ display_name_from VARCHAR(256),
+ reply_with_body INTEGER,
+ forward_with_files INTEGER,
+ add_myname_card INTEGER,
+ add_signature INTEGER,
+ signature VARCHAR(256),
+ add_my_address_to_bcc INTEGER,
+ my_account_id INTEGER,
+ index_color INTEGER,
+ sync_status INTEGER
+);
+
+CREATE TABLE mail_attachment_tbl
+(
+ attachment_id INTEGER PRIMARY KEY,
+ attachment_name VARCHAR(257),
+ attachment_path VARCHAR(257),
+ attachment_size INTEGER,
+ mail_id INTEGER,
+ account_id INTEGER,
+ mailbox_name VARCHAR(129),
+ file_yn INTEGER,
+ flag1 INTEGER,
+ flag2 INTEGER,
+ flag3 INTEGER
+);
+
+CREATE TABLE mail_box_tbl
+(
+ mailbox_id INTEGER,
+ account_id INTEGER,
+ local_yn INTEGER,
+ mailbox_name VARCHAR(256),
+ mailbox_type INTEGER,
+ alias VARCHAR(256),
+ sync_with_server_yn INTEGER,
+ modifiable_yn INTEGER,
+ total_mail_count_on_server INTEGER,
+ has_archived_mails INTEGER,
+ mail_slot_size INTEGER
+);
+CREATE TABLE mail_read_mail_uid_tbl
+(
+ account_id INTEGER ,
+ local_mbox VARCHAR(129) ,
+ local_uid INTEGER ,
+ mailbox_name VARCHAR(129) ,
+ s_uid VARCHAR(129) ,
+ data1 INTEGER ,
+ data2 VARCHAR(257) ,
+ flag INTEGER ,
+ idx_num INTEGER PRIMARY KEY
+);
+CREATE TABLE mail_rule_tbl
+(
+ account_id INTEGER ,
+ rule_id INTEGER PRIMARY KEY,
+ type INTEGER ,
+ value VARCHAR(257) ,
+ action_type INTEGER ,
+ dest_mailbox VARCHAR(129),
+ flag1 INTEGER ,
+ flag2 INTEGER
+);
+CREATE TABLE mail_tbl
+(
+ mail_id INTEGER PRIMARY_KEY,
+ account_id INTEGER,
+ mailbox_name VARCHAR(129),
+ mailbox_type INTEGER,
+ subject UCS2TEXT,
+ date_time VARCHAR(129),
+ server_mail_status INTEGER,
+ server_mailbox_name VARCHAR(129),
+ server_mail_id VARCHAR(129),
+ message_id VARCHAR(257),
+ full_address_from UCS2TEXT,
+ full_address_reply UCS2TEXT,
+ full_address_to UCS2TEXT,
+ full_address_cc UCS2TEXT,
+ full_address_bcc UCS2TEXT,
+ full_address_return UCS2TEXT,
+ email_address_sender UCS2TEXT collation user1,
+ email_address_recipient UCS2TEXT collation user1,
+ alias_sender UCS2TEXT,
+ alias_recipient UCS2TEXT,
+ body_download_status INTEGER,
+ file_path_plain VARCHAR(257),
+ file_path_html VARCHAR(257),
+ mail_size INTEGER,
+ flags_seen_field BOOLEAN,
+ flags_deleted_field BOOLEAN,
+ flags_flagged_field BOOLEAN,
+ flags_answered_field BOOLEAN,
+ flags_recent_field BOOLEAN,
+ flags_draft_field BOOLEAN,
+ flags_forwarded_field BOOLEAN,
+ DRM_status INTEGER,
+ priority INTEGER,
+ save_status INTEGER,
+ lock_status INTEGER,
+ report_status INTEGER,
+ attachment_count INTEGER,
+ inline_content_count INTEGER,
+ thread_id INTEGER,
+ thread_item_count INTEGER,
+ preview_text UCS2TEXT,
+ meeting_request_status INTEGER,
+ FOREIGN KEY(account_id) REFERENCES mail_account_tbl(account_id)
+);
+CREATE TABLE mail_meeting_tbl
+(
+ mail_id INTEGER PRIMARY KEY,
+ account_id INTEGER,
+ mailbox_name UCS2TEXT ,
+ meeting_response INTEGER,
+ start_time INTEGER,
+ end_time INTEGER,
+ location UCS2TEXT ,
+ global_object_id UCS2TEXT ,
+ offset INTEGER,
+ standard_name UCS2TEXT ,
+ standard_time_start_date INTEGER,
+ standard_bias INTEGER,
+ daylight_name UCS2TEXT ,
+ daylight_time_start_date INTEGER,
+ daylight_bias INTEGER
+);
+CREATE TABLE mail_local_activity_tbl
+(
+ activity_id INTEGER,
+ account_id INTEGER,
+ mail_id INTEGER,
+ activity_type INTEGER,
+ server_mailid VARCHAR(129),
+ src_mbox VARCHAR(129),
+ dest_mbox VARCHAR(129)
+);
+
+
+CREATE UNIQUE INDEX mail_account_idx1 ON mail_account_tbl (account_bind_type, account_id);
+CREATE UNIQUE INDEX mail_attachment_idx1 ON mail_attachment_tbl (mail_id, attachment_id);
+CREATE UNIQUE INDEX mail_box_idx1 ON mail_box_tbl (account_id, local_yn, mailbox_name);
+CREATE UNIQUE INDEX mail_idx1 ON mail_tbl (mail_id, account_id);
+CREATE UNIQUE INDEX mail_read_mail_uid_idx1 ON mail_read_mail_uid_tbl (account_id, local_mbox, local_uid, mailbox_name, s_uid);
+CREATE UNIQUE INDEX mail_meeting_idx1 ON mail_meeting_tbl (mail_id);
+CREATE INDEX mail_idx_date_time ON mail_tbl (date_time);
+CREATE INDEX mail_idx_thread_item_count ON mail_tbl (thread_item_count);
+'
+
+echo "[EMAIL-SERVICE] Finish Creating Email Tables."
+
+
+#################################################################
+# Change file permission
+#################################################################
+#echo "[EMAIL-SERVICE] Start setting permission ..."
+# 1. libraries
+#chmod 644 /usr/lib/libemail-ipc.so.0.0.0
+#chmod 644 /usr/lib/libemail-core.so.0.0.0
+#chmod 644 /usr/lib/libemail-emn-storage.so.0.0.0
+#chmod 644 /usr/lib/libemail-base.so.0.0.0
+#chmod 644 /usr/lib/libem-storage.so.0.0.0
+#chmod 644 /usr/lib/libem-network.so.0.0.0
+#chmod 644 /usr/lib/libemail-mapi.so.0.0.0
+#chmod 644 /usr/lib/libem-storage.so
+#chmod 644 /usr/lib/libemail-base.so.0
+#chmod 644 /usr/lib/libem-network.so.0
+#chmod 644 /usr/lib/libemail-core.so.0
+#chmod 644 /usr/lib/libemail-emn-storage.so
+#chmod 644 /usr/lib/libemail-ipc.so
+#chmod 644 /usr/lib/libemail-mapi.so.0
+#chmod 644 /usr/lib/libem-storage.so.0
+#chmod 644 /usr/lib/libem-network.so
+#chmod 644 /usr/lib/libemail-ipc.so.0
+#chmod 644 /usr/lib/libemail-core.so
+#chmod 644 /usr/lib/libemail-base.so
+#chmod 644 /usr/lib/libemail-mapi.so
+#chmod 644 /usr/lib/libemail-emn-storage.so.0
+
+# 2. executables
+#chmod 700 /usr/bin/email-service_initDB
+#chmod 700 /usr/bin/email-service
+
+# 3. DB files
+chmod 644 /opt/dbspace/.email-service.db
+chmod 644 /opt/dbspace/.email-service.db-journal
+
+
+#################################################################
+# Change file owner
+#################################################################
+#echo "[EMAIL-SERVICE] Start setting owner ..."
+
+ # 1. libraries
+# chown root:root /usr/lib/libemail-ipc.so.0.0.0
+# chown root:root /usr/lib/libemail-core.so.0.0.0
+# chown root:root /usr/lib/libemail-emn-storage.so.0.0.0
+# chown root:root /usr/lib/libemail-base.so.0.0.0
+# chown root:root /usr/lib/libem-storage.so.0.0.0
+# chown root:root /usr/lib/libem-network.so.0.0.0
+# chown root:root /usr/lib/libemail-mapi.so.0.0.0
+# chown root:root /usr/lib/libem-storage.so
+# chown root:root /usr/lib/libemail-base.so.0
+# chown root:root /usr/lib/libem-network.so.0
+# chown root:root /usr/lib/libemail-core.so.0
+# chown root:root /usr/lib/libemail-emn-storage.so
+# chown root:root /usr/lib/libemail-ipc.so
+# chown root:root /usr/lib/libemail-mapi.so.0
+# chown root:root /usr/lib/libem-storage.so.0
+# chown root:root /usr/lib/libem-network.so
+# chown root:root /usr/lib/libemail-ipc.so.0
+# chown root:root /usr/lib/libemail-core.so
+# chown root:root /usr/lib/libemail-base.so
+# chown root:root /usr/lib/libemail-mapi.so
+# chown root:root /usr/lib/libemail-emn-storage.so.0
+
+ # 2. executables
+# chown root:root /usr/bin/email-service_initDB
+# chown root:root /usr/bin/email-service
+
+ # 3. DB files
+if [ ${USER} = "root" ]
+then
+ chown root:root /opt/dbspace/.email-service.db
+ chown root:root /opt/dbspace/.email-service.db-journal
+fi
+
+exit 0
diff --git a/debian/email-service-dev.install b/debian/email-service-dev.install
new file mode 100755
index 0000000..deb9940
--- /dev/null
+++ b/debian/email-service-dev.install
@@ -0,0 +1,2 @@
+usr/include/*
+usr/lib/pkgconfig/*
diff --git a/debian/email-service-tools.install b/debian/email-service-tools.install
new file mode 100644
index 0000000..a35587c
--- /dev/null
+++ b/debian/email-service-tools.install
@@ -0,0 +1,4 @@
+#/usr/bin/email-test-app
+#/opt/etc/email-service/*
+#/opt/dbspace/.email-service.db
+#/opt/dbspace/.email-service.db-journal
diff --git a/debian/email-service-tools.postinst b/debian/email-service-tools.postinst
new file mode 100644
index 0000000..1672378
--- /dev/null
+++ b/debian/email-service-tools.postinst
@@ -0,0 +1,65 @@
+#!/bin/sh
+
+#################################################################
+# Copy db file to /opt/dbspace
+#################################################################
+
+echo "[EMAIL-SERVICE] Setting db permission & owner."
+
+if [ ${USER} = "root" ]
+then
+ chown :6006 /opt/dbspace/.email-service.db
+ chmod 660 /opt/dbspace/.email-service.db
+ chown :6006 /opt/dbspace/.email-service.db-journal
+ chmod 660 /opt/dbspace/.email-service.db-journal
+else
+ echo "[EMAIL-SERVICE] Can't change owner. USER is not root."
+fi
+echo "[EMAIL-SERVICE] Finish setting and owner."
+
+
+#echo "[EMAIL-SERVICE] Start copying db file to /opt/dbspace ..."
+#DB_PATH=/opt/dbspace/
+#if test ! -d ${DB_PATH}
+#then
+# mkdir /opt/dbspace
+# echo "[EMAIL-SERVICE] Copy Error!!! There is not '${DB_PATH}'!!"
+#else
+# if test ! -s "${DB_PATH}/.email-service.db"
+# then
+# echo "[EMAIL-SERVICE] .email-service.db is copied to ${DB_PATH}"
+# cp /usr/share/email-service/.email-service.db ${DB_PATH}
+# cp /usr/share/email-service/.email-service.db-journal ${DB_PATH}
+ # change mod and owner
+# chown :6006 /opt/dbspace/.email-service.db
+# chmod 660 /opt/dbspace/.email-service.db
+# chown :6006 /opt/dbspace/.email-service.db-journal
+# chmod 660 /opt/dbspace/.email-service.db-journal
+# else
+# echo "[EMAIL-SERVICE] .email-service.db already exists."
+# fi
+#fi
+#echo "[EMAIL-SERVICE] Finish copying db file. "
+
+#echo "[EMAIL-TEST-APP] Start setting permission ..."
+# 1. executables
+#chmod 700 /usr/bin/email_test_app
+
+#echo "[EMAIL-TEST-APP] Finish setting permission."
+
+# 3. resources
+
+
+#################################################################
+# Change file owner
+#################################################################
+#echo "[EMAIL-TEST-APP] Start setting owner ..."
+#if [ ${USER} == "root" ]
+#then
+ # 1. executables
+# chown root:root /usr/bin/email_test_app
+#else
+# echo "[EMAIL-TEST-APP] Can't change owner. USER is not root."
+#fi
+#echo "[EMAIL-TEST-APP] Finish setting and owner."
+
diff --git a/debian/rules b/debian/rules
new file mode 100755
index 0000000..e773968
--- /dev/null
+++ b/debian/rules
@@ -0,0 +1,146 @@
+#!/usr/bin/make -f
+# -*- makefile -*-
+# Sample debian/rules that uses debhelper.
+# This file was originally written by Joey Hess and Craig Small.
+# As a special exception, when this file is copied by dh-make into a
+# dh-make output file, you may use that output file without restriction.
+# This special exception was added by Craig Small in version 0.37 of dh-make.
+
+# Uncomment this to turn on verbose mode.
+#export DH_VERBOSE=1
+
+
+# These are used for cross-compiling and for saving the configure script
+# from having to guess our platform (since we know it already)
+DEB_HOST_GNU_TYPE ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
+DEB_BUILD_GNU_TYPE ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)
+
+CFLAGS ?=
+CXXFLAGS ?=
+LDFLAGS ?=
+PREFIX ?= /usr
+DATADIR ?= /opt
+
+ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
+ CFLAGS += -O2
+ CXXFLAGS += -O2
+else
+ CFLAGS += -O0
+ CXXFLAGS += -O0
+endif
+
+CFLAGS += -fPIC -Wall -g -fvisibility=hidden
+CXXFLAGS += -fPIC -Wall -g -fvisibility=hidden
+LDFLAGS += -Wl,--hash-style=both
+
+LDFLAGS += -Wl,--rpath=$(PREFIX)/lib -Wl,--as-needed
+
+CMAKE_TMP_DIR = $(CURDIR)/cmake_tmp
+
+configure: configure-stamp
+configure-stamp:
+ dh_testdir
+ # Add here commands to configure the package.
+
+ mkdir -p $(CMAKE_TMP_DIR);
+ cd $(CMAKE_TMP_DIR); CFLAGS="$(CFLAGS)" CXXFLAGS="$(CXXFLAGS)" LDFLAGS="$(LDFLAGS)" cmake .. -DCMAKE_INSTALL_PREFIX=$(PREFIX)
+ touch configure-stamp
+
+build: build-stamp
+
+build-stamp: configure-stamp
+ dh_testdir
+
+ # Add here commands to compile the package.
+ cd $(CMAKE_TMP_DIR) && $(MAKE)
+
+ for f in `find $(CURDIR)/debian/ -name "*.in"`; do \
+ cat $$f > $${f%.in}; \
+ sed -i -e "s#@PREFIX@#$(PREFIX)#g" $${f%.in}; \
+ sed -i -e "s#@DATADIR@#$(DATADIR)#g" $${f%.in}; \
+ done
+
+ # Make .db file
+ #$(CMAKE_TMP_DIR)/utilities/email-service_initDB create 0 $(CMAKE_TMP_DIR)/utilities
+
+ touch $@
+
+
+clean:
+ dh_testdir
+ dh_testroot
+ rm -f build-stamp configure-stamp
+
+ # Add here commands to clean up after the build process.
+ -$(MAKE) clean
+ rm -rf CMakeCache.txt
+ rm -rf CMakeFiles
+ rm -rf cmake_install.cmake
+ rm -rf Makefile
+ rm -rf install_manifest.txt
+ rm -rf *.so
+ rm -rf $(CMAKE_TMP_DIR)
+
+ for f in `find $(CURDIR)/debian/ -name "*.in"`; do \
+ rm -f $${f%.in}; \
+ done
+
+ # Delete .db file
+ rm -f .*.db .*.db-journal
+ # Delete auto created files
+ rm -f Makefile.in aclocal.m4 configure config.sub config.guess config.h.in depcomp ltmain.sh missing install-sh
+
+ dh_clean
+
+install: build
+ dh_testdir
+ dh_testroot
+ dh_clean -k
+ dh_installdirs
+
+ # Add here commands to install the package into debian/mm-log.
+ cd $(CMAKE_TMP_DIR) && $(MAKE) DESTDIR=$(CURDIR)/debian/tmp install
+ mkdir -p $(CURDIR)/debian/tmp/opt/dbspace
+ #cp $(CMAKE_TMP_DIR)/utilities/.email-service.db $(CURDIR)/debian/tmp/opt/dbspace
+ #cp $(CMAKE_TMP_DIR)/utilities/.email-service.db-journal $(CURDIR)/debian/tmp/opt/dbspace
+
+
+# Build architecture-independent files here.
+binary-indep: build install
+# We have nothing to do by default.
+
+# Build architecture-dependent files here.
+binary-arch: build install
+ dh_testdir
+ dh_testroot
+ dh_installchangelogs
+ dh_installdocs
+ dh_installexamples
+ dh_install --sourcedir=debian/tmp
+# dh_installmenu
+# dh_installdebconf
+# dh_installlogrotate
+# dh_installemacsen
+# dh_installpam
+# dh_installmime
+# dh_python
+# dh_installinit
+# dh_installcron
+# dh_installinfo
+ dh_installman
+ dh_link
+# dh_strip
+ dh_strip --dbg-package=email-service-dbg
+ dh_compress
+ dh_fixperms
+# dh_perl
+ dh_makeshlibs
+ dh_installdeb
+ dh_shlibdeps
+ dh_gencontrol
+ dh_md5sums
+ dh_builddeb
+
+binary: binary-indep binary-arch
+.PHONY: build clean binary-indep binary-arch binary install
+
diff --git a/email-core/CMakeLists.txt b/email-core/CMakeLists.txt
new file mode 100755
index 0000000..fb8dfe6
--- /dev/null
+++ b/email-core/CMakeLists.txt
@@ -0,0 +1,171 @@
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+PROJECT(email-storage)
+
+SET(CMAKE_SKIP_BUILD_RPATH TRUE)
+
+IF("${CMAKE_BUILD_TYPE}" STREQUAL "")
+ SET(CMAKE_BUILD_TYPE "Debug")
+ENDIF("${CMAKE_BUILD_TYPE}" STREQUAL "")
+
+MESSAGE("")
+MESSAGE(">>> current directory: ${CMAKE_CURRENT_SOURCE_DIR}")
+MESSAGE(">>> Build type: ${CMAKE_BUILD_TYPE}")
+
+
+SET(VISIBILITY "-DEXPORT_API=\"__attribute__((visibility(\\\"default\\\")))\"")
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${VISIBILITY} -fvisibility=hidden")
+
+##########################################################
+# Define STORAGE lib
+##########################################################
+
+SET(STORAGE-LIB "email-storage")
+SET(STORAGE-SRCS
+ ./em-storage/em-storage-noti.c
+ ./em-storage/em-storage.c
+ ${CMAKE_SOURCE_DIR}/emf-emn-storage/emf-emn-storage.c
+)
+
+INCLUDE_DIRECTORIES(
+ ${CMAKE_ROOT_DIR}/include/common/include
+ ${CMAKE_ROOT_DIR}/include
+ ${CMAKE_SOURCE_DIR}/include
+ ${CMAKE_SOURCE_DIR}/em-storage/include
+)
+
+
+INCLUDE(FindPkgConfig)
+pkg_check_modules(storage_pkgs REQUIRED drm-service glib-2.0 dlog db-util openssl vconf secure-storage dbus-1 contacts-service)
+
+set(EXTRA_CFLAGS "")
+FOREACH(flag ${storage_pkgs_CFLAGS})
+ SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
+
+#message(">>> extra_cflags ${EXTRA_CFLAGS}")
+#message(">>> result ${CMAKE_C_FLAGS}")
+
+
+SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed")
+
+ADD_LIBRARY(${STORAGE-LIB} SHARED ${STORAGE-SRCS})
+TARGET_LINK_LIBRARIES(${STORAGE-LIB} ${storage_LDFLAGS} ${BASE-LIB} ss-client)
+SET_TARGET_PROPERTIES(${STORAGE-LIB} PROPERTIES SOVERSION ${VERSION_MAJOR})
+SET_TARGET_PROPERTIES(${STORAGE-LIB} PROPERTIES VERSION ${VERSION})
+
+#INSTALL(TARGETS ${STORAGE-LIB} LIBRARY DESTINATION lib)
+INSTALL(TARGETS ${STORAGE-LIB} DESTINATION lib COMPONENT RuntimeLibraries)
+
+
+##########################################################
+# Define network lib
+##########################################################
+
+SET(NETWORK-LIB "email-network")
+SET(NETWORK-SRCS
+ ./em-network/em-network.c
+)
+
+INCLUDE_DIRECTORIES(
+ ${CMAKE_SOURCE_DIR}/include/common/include
+ ${CMAKE_SOURCE_DIR}/include
+ ${CMAKE_SOURCE_DIR}/email-core/include
+ ${CMAKE_SOURCE_DIR}/email-core/em-storage/include
+)
+
+INCLUDE(FindPkgConfig)
+pkg_check_modules(network_pkgs REQUIRED glib-2.0 uw-imap-toolkit dbus-1 vconf dlog openssl)
+
+FOREACH(flag ${network_pkgs_CFLAGS})
+ SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+#message(">> net extra raw: ${core_proxy_pkgs_CFLAGS}")
+
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
+
+SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed")
+
+ADD_LIBRARY(${NETWORK-LIB} SHARED ${NETWORK-SRCS})
+TARGET_LINK_LIBRARIES(${NETWORK-LIB} ${network_pkgs_LDFLAGS} ${BASE-LIB} ${STORAGE-LIB} dl)
+SET_TARGET_PROPERTIES(${NETWORK-LIB} PROPERTIES SOVERSION ${VERSION_MAJOR})
+SET_TARGET_PROPERTIES(${NETWORK-LIB} PROPERTIES VERSION ${VERSION})
+
+INSTALL(TARGETS ${NETWORK-LIB} DESTINATION lib COMPONENT RuntimeLibraries)
+
+##########################################################
+# Define Core lib
+##########################################################
+
+SET(CORE-LIB "email-core")
+SET(CORE-SRCS
+ ${CMAKE_SOURCE_DIR}/email-core/em-core-event.c
+ ${CMAKE_SOURCE_DIR}/email-core/em-core-imap-mailbox.c
+ ${CMAKE_SOURCE_DIR}/email-core/em-core-mailbox.c
+ ${CMAKE_SOURCE_DIR}/email-core/em-core-mailbox-sync.c
+ ${CMAKE_SOURCE_DIR}/email-core/em-core-mesg.c
+ ${CMAKE_SOURCE_DIR}/email-core/em-core-mm-callbacks.c
+ ${CMAKE_SOURCE_DIR}/email-core/em-core-utils.c
+ ${CMAKE_SOURCE_DIR}/email-core/em-core-api.c
+ ${CMAKE_SOURCE_DIR}/email-core/em-core-smtp.c
+ ${CMAKE_SOURCE_DIR}/email-core/em-core-timer.c
+ ${CMAKE_SOURCE_DIR}/email-core/em-core-imap-idle.c
+ ${CMAKE_SOURCE_DIR}/email-core/em-core-global.c
+ ${CMAKE_SOURCE_DIR}/email-core/em-core-account.c
+ ${CMAKE_SOURCE_DIR}/email-core/em-core-mime.c
+ ${CMAKE_SOURCE_DIR}/email-core/em-core-sound.c
+)
+
+INCLUDE_DIRECTORIES(
+ ${CMAKE_SOURCE_DIR}/include/common/include
+ ${CMAKE_SOURCE_DIR}/include/
+ ${CMAKE_SOURCE_DIR}/email-core/em-storage/include
+ ${CMAKE_SOURCE_DIR}/email-core/include
+ ${CMAKE_SOURCE_DIR}/Common/include
+ ${CMAKE_SOURCE_DIR}/email-core/em-network/include
+)
+
+
+INCLUDE(FindPkgConfig)
+pkg_check_modules(core_pkgs REQUIRED glib-2.0 drm-service dlog dbus-1 gthread-2.0 uw-imap-toolkit vconf contacts-service secure-storage openssl accounts-svc mm-player mm-session devman_haptic alarm-service notification libcurl libxml-2.0)
+
+set(EXTRA_CFLAGS "")
+FOREACH(flag ${core_pkgs_CFLAGS})
+ SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
+
+#message(">> core extra raw: ${core_pkgs_CFLAGS}")
+#message(">> core extra : ${EXTRA_CFLAGS}")
+#message(">> core result: ${CMAKE_C_FLAGS}")
+
+ADD_DEFINITIONS("-DCREATEPROTO=unixproto")
+ADD_DEFINITIONS("-DEMPTYPROTO=unixproto")
+ADD_DEFINITIONS("-DMAILSPOOL=\"/var/spool/mail\"")
+ADD_DEFINITIONS("-DANONYMOUSHOME=\"/var/spool/mail/anonymous\"")
+ADD_DEFINITIONS("-DACTIVEFILE=\"/var/lib/news/active\"")
+ADD_DEFINITIONS("-DNEWSSPOOL=\"/var/spool/news\"")
+ADD_DEFINITIONS("-DRSHPATH=\"/usr/bin/rsh\"")
+ADD_DEFINITIONS("-DMD5ENABLE=\"/etc/cram-md5.pwd\"")
+ADD_DEFINITIONS("-DSSL_CERT_DIRECTORY=\"/opt/etc/ssl/certs\"")
+ADD_DEFINITIONS("-DSSL_KEY_DIRECTORY=\"/opt/etc/ssl/certs\"")
+ADD_DEFINITIONS("-DCHUNKSIZE=65536")
+ADD_DEFINITIONS("-DLOCKPGM=\"\"")
+ADD_DEFINITIONS("-DLOCKPGM1=\"/usr/libexec/mlock\"")
+ADD_DEFINITIONS("-DLOCKPGM2=\"/usr/sbin/mlock\"")
+ADD_DEFINITIONS("-DLOCKPGM3=\"/usr/etc/mlock\"")
+SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed")
+
+ADD_LIBRARY(${CORE-LIB} SHARED ${CORE-SRCS})
+
+TARGET_LINK_LIBRARIES(${CORE-LIB} ${core_pkgs_LDFLAGS} ${STORAGE-LIB} ${NETWORK-LIB})
+
+SET_TARGET_PROPERTIES(${CORE-LIB} PROPERTIES SOVERSION ${VERSION_MAJOR})
+SET_TARGET_PROPERTIES(${CORE-LIB} PROPERTIES VERSION ${VERSION})
+
+INSTALL(TARGETS ${CORE-LIB} DESTINATION lib COMPONENT RuntimeLibraries)
+
+
diff --git a/email-core/em-core-account.c b/email-core/em-core-account.c
new file mode 100755
index 0000000..cfb7ee3
--- /dev/null
+++ b/email-core/em-core-account.c
@@ -0,0 +1,1107 @@
+/*
+* email-service
+*
+* Copyright (c) 2000 - 2011 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.
+*
+*/
+
+
+/******************************************************************************
+ * File : em-core-account.c
+ * Desc : Account Management
+ *
+ * Auth : Kyuho Jo
+ *
+ * History :
+ * 2010.08.25 : created
+ *****************************************************************************/
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+#include <sys/types.h>
+#include <vconf.h>
+
+#include "Msg_Convert.h"
+#include "emf-types.h"
+#include "emflib.h"
+#include "emf-dbglog.h"
+#include "em-storage.h"
+#include "em-network.h"
+#include "em-core-utils.h"
+#include "em-core-event.h"
+#include "em-core-global.h"
+#include "em-core-account.h"
+#include "em-core-mailbox.h"
+#include "em-core-imap-mailbox.h"
+
+#ifdef __FEATURE_USING_MY_ACCOUNT__
+#include "account.h"
+#endif /* FEATURE_USING_MY_ACCOUN */
+
+char *g_default_mbox_alias[MAILBOX_COUNT] =
+{
+ EMF_INBOX_DISPLAY_NAME,
+ EMF_DRAFTBOX_DISPLAY_NAME,
+ EMF_OUTBOX_DISPLAY_NAME,
+ EMF_SENTBOX_DISPLAY_NAME,
+ EMF_TRASH_DISPLAY_NAME,
+ EMF_SPAMBOX_DISPLAY_NAME,
+};
+
+char *g_default_mbox_name[MAILBOX_COUNT] =
+{
+ EMF_INBOX_NAME,
+ EMF_DRAFTBOX_NAME,
+ EMF_OUTBOX_NAME,
+ EMF_SENTBOX_NAME,
+ EMF_TRASH_DISPLAY_NAME,
+ EMF_SPAMBOX_NAME,
+};
+
+emf_mailbox_type_e g_default_mbox_type[MAILBOX_COUNT] =
+{
+ EMF_MAILBOX_TYPE_INBOX,
+ EMF_MAILBOX_TYPE_DRAFT,
+ EMF_MAILBOX_TYPE_OUTBOX,
+ EMF_MAILBOX_TYPE_SENTBOX,
+ EMF_MAILBOX_TYPE_TRASH,
+ EMF_MAILBOX_TYPE_SPAMBOX,
+};
+
+EXPORT_API emf_account_t* em_core_get_account_reference(int account_id)
+{
+ EM_DEBUG_FUNC_BEGIN("account_id[%d]", account_id);
+ EM_PROFILE_BEGIN(profile_em_core_get_account_reference);
+ emf_account_list_t **p;
+
+ if (account_id == NEW_ACCOUNT_ID)
+ return em_core_account_get_new_account_ref();
+
+ if (account_id > 0) {
+ p = &g_account_list;
+ while (*p) {
+ if ((*p)->account->account_id == account_id)
+ return ((*p)->account);
+ p = &(*p)->next;
+ }
+
+ /* refresh and check once agai */
+ if (em_core_refresh_account_reference() == true) {
+ p = &g_account_list;
+ while (*p) {
+ if ((*p)->account->account_id == account_id)
+ return ((*p)->account);
+
+ p = &(*p)->next;
+ }
+ }
+ }
+
+ EM_PROFILE_END(profile_em_core_get_account_reference);
+ EM_DEBUG_FUNC_END();
+ return NULL;
+}
+
+
+EXPORT_API int em_core_account_validate_with_account_info(emf_account_t *account, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("account[%p], err_code[%p], receiving_server_addr [%s]", account, err_code, account->receiving_server_addr);
+
+ int ret = false;
+ int err = EMF_ERROR_NONE;
+ emf_session_t *session = NULL;
+ SENDSTREAM *stream = NULL;
+ MAILSTREAM *tmp_stream = NULL;
+
+ if (!em_core_check_thread_status()) {
+ err = EMF_ERROR_CANCELLED;
+ goto FINISH_OFF;
+ }
+
+ if (!em_core_check_network_status(&err)) {
+ EM_DEBUG_EXCEPTION("em_core_check_network_status failed [%d]", err);
+ goto FINISH_OFF;
+ }
+ EM_DEBUG_LOG("Network available");
+
+ if (!em_core_check_thread_status()) {
+ err = EMF_ERROR_CANCELLED;
+ goto FINISH_OFF;
+ }
+
+ if (!em_core_get_empty_session(&session)) {
+ EM_DEBUG_EXCEPTION("em_core_get_empty_session failed...");
+ err = EMF_ERROR_SESSION_NOT_FOUND;
+ goto FINISH_OFF;
+ }
+
+#ifdef _SMTP_ACCOUNT_VALIDATION_
+ /* validate connection for smt */
+ EM_DEBUG_LOG(" >>>>>>>>>> Validate connection for SMTP");
+
+ if (!em_core_check_thread_status()) {
+ err = EMF_ERROR_CANCELLED;
+ goto FINISH_OFF;
+ }
+ if (!em_core_mailbox_open_with_account_info(account, (char *)ENCODED_PATH_SMTP, (void **)&stream, &err) || !stream) {
+ EM_DEBUG_EXCEPTION("\t em_core_mailbox_open failed 1 - %d", err);
+ if (EMF_ERROR_AUTHENTICATE == err || EMF_ERROR_LOGIN_FAILURE == err) { /* wrong password or etc */
+ EM_DEBUG_EXCEPTION("\t em_core_mailbox_open failed : Login or Authentication fail 1- %d", err);
+ goto FINISH_OFF;
+ }
+
+ if (account->sending_security == 0x01) /* 0x01 == ss */ {
+ /* retry with tl */
+ EM_DEBUG_LOG(" >>>>>>>>>> Retry with TLS");
+ account->sending_security = 0x02; /* 0x02 == tl */
+ if (!em_core_check_thread_status()) {
+ err = EMF_ERROR_CANCELLED;
+ goto FINISH_OFF;
+ }
+
+ if (!em_core_mailbox_open_with_account_info(account, (char *)ENCODED_PATH_SMTP, (void **)&stream, &err) || !stream) {
+ EM_DEBUG_EXCEPTION("\t em_core_mailbox_open failed 2 - %d", err);
+ if (EMF_ERROR_AUTHENTICATE == err || EMF_ERROR_LOGIN_FAILURE == err) { /* wrong password or etc */
+ EM_DEBUG_EXCEPTION("\t em_core_mailbox_open failed : Login or Authentication fail 2 - %d", err);
+ }
+ else if (EMF_ERROR_CONNECTION_FAILURE != err) {
+ err = EMF_ERROR_VALIDATE_ACCOUNT;
+ }
+ account->sending_security = 0x01; /* restore to the previous value */
+ goto FINISH_OFF;
+ }
+
+ if (!em_core_check_thread_status()) {
+ err = EMF_ERROR_CANCELLED;
+ goto FINISH_OFF;
+ }
+
+ /* save sending_security = 0x02 (tls) to the d */
+ if (!em_storage_update_account(account_id, (emf_mail_account_tbl_t *)account, true, &err)) {
+ EM_DEBUG_EXCEPTION("\t em_storage_update_account failed - %d", err);
+ account->sending_security = 0x01; /* restore to the previous value */
+ err = EMF_ERROR_VALIDATE_ACCOUNT;
+ goto FINISH_OFF;
+ }
+ }
+ else {
+ if (EMF_ERROR_CONNECTION_FAILURE != err)
+ err = EMF_ERROR_VALIDATE_ACCOUNT;
+ goto FINISH_OFF;
+ }
+ }
+#endif
+
+ /* validate connection for pop3/ima */
+ EM_DEBUG_LOG("Validate connection for POP3/IMAP4");
+ if (EMF_ERROR_NONE == err) {
+ if (!em_core_check_thread_status()) {
+ err = EMF_ERROR_CANCELLED;
+ goto FINISH_OFF;
+ }
+
+ if (!em_core_mailbox_open_with_account_info(account, NULL, (void **)&tmp_stream, &err) || !tmp_stream)
+ {
+ EM_DEBUG_EXCEPTION("em_core_mailbox_open failed - %d", err);
+ if (EMF_ERROR_AUTHENTICATE == err || EMF_ERROR_LOGIN_FAILURE == err) { /* wrong password or etc */
+ EM_DEBUG_EXCEPTION("em_core_mailbox_open failed : Login or Authentication fail - %d", err);
+ }
+ else if (EMF_ERROR_CONNECTION_FAILURE != err) {
+ /* err = EMF_ERROR_VALIDATE_ACCOUNT */
+ }
+ goto FINISH_OFF;
+ }
+ }
+
+ if (!em_core_check_thread_status()) {
+ if (!em_core_account_delete(account->account_id, NULL))
+ EM_DEBUG_EXCEPTION("emf_account_delete failed [%d]", account->account_id);
+ err = EMF_ERROR_CANCELLED;
+ goto FINISH_OFF;
+ }
+
+ ret = true;
+ err = EMF_SUCCESS_VALIDATE_ACCOUNT;
+
+FINISH_OFF:
+ if (stream)
+ smtp_close(stream);
+
+ if (tmp_stream)
+ em_core_mailbox_close(0 , tmp_stream);
+
+ if (err_code != NULL)
+ *err_code = err;
+ em_core_clear_session(session);
+
+ EM_DEBUG_FUNC_END();
+
+ return ret;
+}
+
+
+EXPORT_API int em_core_account_validate(int account_id, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("account_id[%d], err_code[%p]", account_id, err_code);
+
+ int err = EMF_ERROR_NONE, ret = false;
+ emf_account_t *ref_account = NULL;
+
+
+ if (account_id <= 0)
+ {
+ EM_DEBUG_EXCEPTION("account_id[%p]", account_id);
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ ref_account = em_core_get_account_reference(account_id);
+
+ if (ref_account && em_core_account_validate_with_account_info(ref_account, &err) == false) {
+ EM_DEBUG_EXCEPTION("em_core_account_validate_with_account_info failed (%d)", err);
+ goto FINISH_OFF;
+ }
+
+ ret = true;
+
+FINISH_OFF:
+
+ if (err_code)
+ *err_code = err;
+
+ EM_DEBUG_FUNC_END();
+
+ return ret;
+}
+
+EXPORT_API int em_core_account_delete(int account_id, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("account_id[%d], err_code[%p]", account_id, err_code);
+
+ /* default variabl */
+ int ret = false;
+ int err = EMF_ERROR_NONE;
+
+ if (account_id < FIRST_ACCOUNT_ID) {
+ EM_DEBUG_EXCEPTION("account_id[%d]", account_id);
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+#ifdef __LOCAL_ACTIVITY__
+ /* Delete all local activities of previous account */
+ emf_activity_tbl_t activity;
+ memset(&activity, 0x00, sizeof(emf_activity_tbl_t));
+ activity.account_id = account_id;
+
+ if (!em_core_activity_delete(&activity, &err)) {
+ EM_DEBUG_LOG("\t em_core_activity_delete failed - %d", err);
+
+ goto FINISH_OFF;
+ }
+#endif
+
+#ifdef __FEATURE_PARTIAL_BODY_DOWNLOAD__
+ if (false == em_core_clear_partial_body_thd_event_que(&err))
+ EM_DEBUG_EXCEPTION(" em_core_clear_partial_body_thd_event_que [%d]", err);
+
+ if (false == em_storage_delete_full_pbd_activity_data(account_id, true, &err))
+ EM_DEBUG_EXCEPTION("em_storage_delete_full_pbd_activity_data failed [%d]", err);
+
+#endif
+
+#ifdef __FEATURE_USING_MY_ACCOUNT__
+ {
+ int error_code;
+ emf_account_t *account_to_be_deleted;
+
+ account_to_be_deleted = em_core_get_account_reference(account_id);
+ if (account_to_be_deleted && account_to_be_deleted->receiving_server_type != EMF_SERVER_TYPE_ACTIVE_SYNC) {
+ EM_DEBUG_LOG("Calling account_svc_delete with my_account_id[%d]", account_to_be_deleted->my_account_id);
+ error_code = account_connect();
+ EM_DEBUG_LOG("account_connect returns [%d]", error_code);
+ account_delete_from_db_by_id(account_to_be_deleted->my_account_id);
+ error_code = account_disconnect();
+ EM_DEBUG_LOG("account_disconnect returns [%d]", error_code);
+ }
+ }
+#endif
+ if (em_core_cancel_all_threads_of_an_account(account_id) < EMF_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("There are some remaining jobs. I couldn't stop them.");
+ err = EMF_ERROR_CANNOT_STOP_THREAD;
+ goto FINISH_OFF;
+ }
+
+ emf_mailbox_t mbox;
+
+ /* BEGIN TRANSACTION; */
+ em_storage_begin_transaction(NULL, NULL, NULL);
+
+ if (!em_storage_delete_account(account_id, false, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_delete_account failed - %d", err);
+ goto FINISH_OFF;
+ }
+
+#ifdef __FEATURE_KEEP_CONNECTION__
+ /* em_core_reset_streams(); */
+ em_core_remove_connection_info(account_id);
+#endif
+
+ mbox.account_id = account_id;
+ mbox.name = NULL;
+
+ if (!em_core_mail_delete_all(&mbox, 0, &err)) {
+ EM_DEBUG_EXCEPTION("em_core_mail_delete_all failed - %d", err);
+ goto FINISH_OFF;
+ }
+
+ /* delete all mailboxe */
+ if (!em_storage_delete_mailbox(account_id, -1, NULL, false, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_delete_mailbox failed - %d", err);
+ goto FINISH_OFF;
+ }
+
+ /* delete local imap sync mailbox from imap mailbox tabl */
+ if (!em_storage_remove_downloaded_mail(account_id, NULL, NULL, false, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_remove_downloaded_mail failed - %d", err);
+ goto FINISH_OFF;
+ }
+
+ em_core_check_unread_mail();
+ em_core_delete_notification_by_account(account_id);
+ em_core_refresh_account_reference();
+
+ ret = true;
+
+FINISH_OFF:
+ if (ret == true) { /* COMMIT TRANSACTION; */
+ if (em_storage_commit_transaction(NULL, NULL, NULL) == false) {
+ err = em_storage_get_emf_error_from_em_storage_error(EM_STORAGE_ERROR_DB_FAILURE);
+ ret = false;
+ }
+ if (!em_storage_notify_storage_event(NOTI_ACCOUNT_DELETE, account_id, 0, NULL, 0))
+ EM_DEBUG_EXCEPTION(" em_storage_notify_storage_event[ NOTI_ACCOUNT_DELETE] : Notification Failed >>> ");
+
+ }
+ else { /* ROLLBACK TRANSACTION; */
+ if (em_storage_rollback_transaction(NULL, NULL, NULL) == false)
+ err = em_storage_get_emf_error_from_em_storage_error(EM_STORAGE_ERROR_DB_FAILURE);
+ if (!em_storage_notify_storage_event(NOTI_ACCOUNT_DELETE_FAIL, account_id, err, NULL, 0))
+ EM_DEBUG_EXCEPTION(" em_storage_notify_storage_event[ NOTI_ACCOUNT_DELETE] : Notification Failed >>> ");
+ }
+
+ if (err_code)
+ *err_code = err;
+
+ EM_DEBUG_FUNC_END();
+
+ return ret;
+}
+
+EXPORT_API int em_core_account_create(emf_account_t *account, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("account[%p], err_code[%p]", account, err_code);
+
+ int ret = false;
+ int err = EMF_ERROR_NONE;
+ int i, count = 0, is_preset_IMAP_account = false;
+ emf_mailbox_t local_mailbox = {0};
+ emf_mail_account_tbl_t *temp_account_tbl = NULL;
+
+ if (!account) {
+ EM_DEBUG_EXCEPTION("account[%p]", account);
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ if (!em_storage_get_account_count(&count, true, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_get_account_count failed - %d", err);
+ goto FINISH_OFF;
+ }
+
+
+ if (count >= EMF_ACCOUNT_MAX) {
+ EM_DEBUG_EXCEPTION("too many accounts...");
+ err = EMF_ERROR_ACCOUNT_MAX_COUNT;
+ goto FINISH_OFF;
+ }
+
+ account->account_id = 0;
+
+ /* check for email address validation */
+ EM_DEBUG_LOG("account->email_addr[%s]", account->email_addr);
+ if (account->email_addr) {
+ if (!em_core_verify_email_address(account->email_addr, true, &err)) {
+ err = EMF_ERROR_INVALID_ADDRESS;
+ EM_DEBUG_EXCEPTION("Invalid Email Address");
+ goto FINISH_OFF;
+ }
+ }
+
+#ifdef __FEATURE_USING_MY_ACCOUNT__
+ if (account->receiving_server_type != EMF_SERVER_TYPE_ACTIVE_SYNC) {
+ int account_svc_id = 0;
+ int error_code;
+ account_h account_handle = NULL;
+
+ error_code = account_connect();
+ error_code = account_create(&account_handle);
+
+ if(error_code != ACCOUNT_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("account_create failed [%d]", error_code);
+ err = error_code;
+ goto FINISH_OFF;
+ }
+
+ account_set_user_name(account_handle, account->user_name);
+ account_set_domain_name(account_handle, account->account_name);
+ account_set_email_address(account_handle, account->email_addr);
+ account_set_source(account_handle, "EMAIL");
+ account_set_package_name(account_handle, "email-setting-efl");
+ account_set_capability(account_handle , ACCOUNT_CAPABILITY_EMAIL, ACCOUNT_CAPABILITY_ENABLED);
+ if (account->logo_icon_path)
+ account_set_icon_path(account_handle, account->logo_icon_path);
+ error_code = account_insert_to_db(account_handle, &account_svc_id);
+
+ if (error_code != ACCOUNT_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("account_insert_to_db failed [%d]", error_code);
+ err = error_code;
+ goto FINISH_OFF;
+ }
+
+ account->my_account_id = account_svc_id;
+
+ EM_DEBUG_LOG("account_insert_to_db succeed");
+
+ account_disconnect();
+ }
+#endif /* __FEATURE_USING_MY_ACCOUNT__ */
+
+ temp_account_tbl = em_core_malloc(sizeof(emf_mail_account_tbl_t));
+ if (!temp_account_tbl) {
+ EM_DEBUG_EXCEPTION("allocation failed [%d]", err);
+ goto FINISH_OFF;
+ }
+ em_convert_account_to_account_tbl(account, temp_account_tbl);
+
+ if (!em_storage_add_account(temp_account_tbl, true, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_add_account failed - %d", err);
+ goto FINISH_OFF;
+ }
+ account->account_id = temp_account_tbl->account_id;
+ is_preset_IMAP_account = ((account->receiving_server_type == EMF_SERVER_TYPE_IMAP4)) ? true : false;/* && (account->preset_account)) ? true : false */
+
+ EM_DEBUG_LOG("is_preset_IMAP_account : %d", is_preset_IMAP_account);
+
+ if ((account->receiving_server_type != EMF_SERVER_TYPE_ACTIVE_SYNC) && (!is_preset_IMAP_account)) {
+ /* 1. create default local mailbox
+ * (Inbox, Draft, Outbox, Sentbox) */
+ for (i = 0; i < MAILBOX_COUNT; i++) {
+ EM_DEBUG_LOG("g_default_mbox_name [%d/%d] is [%s]", i, MAILBOX_COUNT, g_default_mbox_name[i]);
+ local_mailbox.account_id = temp_account_tbl->account_id;
+ local_mailbox.name = g_default_mbox_name[i];
+ local_mailbox.mailbox_type = g_default_mbox_type[i];
+ if (local_mailbox.mailbox_type == EMF_MAILBOX_TYPE_INBOX) {
+ local_mailbox.local = EMF_MAILBOX_FROM_SERVER;
+ local_mailbox.synchronous = 1;
+ }
+ else {
+ local_mailbox.local = EMF_MAILBOX_FROM_LOCAL;
+ local_mailbox.synchronous = 0;
+ }
+ local_mailbox.alias = g_default_mbox_alias[i];
+ em_core_mailbox_get_default_mail_slot_count(&local_mailbox.mail_slot_size, NULL);
+
+ if (!em_core_mailbox_create(&local_mailbox, 0, &err)) {
+ EM_DEBUG_EXCEPTION("em_core_mailbox_create failed - %d", err);
+ goto FINISH_OFF;
+ }
+
+ }
+ }
+
+
+
+ ret = true;
+
+FINISH_OFF:
+ if (temp_account_tbl)
+ em_storage_free_account(&temp_account_tbl, 1, NULL);
+
+ if (ret == false && account != NULL) {
+ if (!em_core_account_delete(account->account_id, NULL))
+ EM_DEBUG_EXCEPTION("emf_account_delete Failed [%d]", account->account_id);
+ }
+
+ if (err_code)
+ *err_code = err;
+
+ EM_DEBUG_FUNC_END("Return value [%d]", ret);
+ return ret;
+}
+
+
+EXPORT_API int em_core_init_account_reference()
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ int ret = false;
+ int err = EMF_ERROR_NONE;
+
+ emf_account_list_t *account_list = NULL;
+ emf_account_list_t **p = NULL;
+ emf_account_t *account = NULL;
+ emf_mail_account_tbl_t *account_tbl_array = NULL;
+ int count = 0;
+ int i = 0;
+
+ if (!g_account_retrieved) {
+ count = 1000;
+ if (!em_storage_get_account_list(&count, &account_tbl_array, true, true, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_get_account_list failed - %d", err);
+ goto FINISH_OFF;
+ }
+
+ for (p = &account_list, i = 0; i < count; i++) {
+ account = malloc(sizeof(emf_account_t));
+ if (!account) {
+ EM_DEBUG_EXCEPTION("malloc failed...");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ em_convert_account_tbl_to_account(account_tbl_array + i, account);
+
+ /* memcpy(account, accounts + i, sizeof(emf_account_t)) */
+ /* memset(accounts + i, 0x00, sizeof(emf_account_t)) */
+
+ (*p) = malloc(sizeof(emf_account_list_t));
+ if (!(*p)) {
+ EM_DEBUG_EXCEPTION("malloc failed...");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ memset((*p), 0x00, sizeof(emf_account_list_t));
+
+ (*p)->account = account;
+
+ p = &(*p)->next;
+ }
+ if (g_account_num)
+ em_core_free_account_reference();
+ g_account_retrieved = 1;
+ g_account_num = count;
+ g_account_list = account_list;
+ }
+
+ ret = true;
+
+FINISH_OFF:
+ if (account_tbl_array != NULL)
+ em_storage_free_account(&account_tbl_array, count, NULL);
+
+ if (!ret) {
+ g_account_list = account_list;
+ em_core_free_account_reference();
+ }
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+EXPORT_API int em_core_refresh_account_reference()
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ if (g_account_retrieved && g_account_num)
+ em_core_free_account_reference();
+
+ g_account_retrieved = 0;
+ g_account_num = 0;
+ g_account_list = NULL;
+
+ if (!em_core_init_account_reference()) {
+ EM_DEBUG_EXCEPTION("em_core_init_account_reference failed...");
+ return false;
+ }
+ EM_DEBUG_FUNC_END();
+ return true;
+}
+
+EXPORT_API int em_core_free_account_reference()
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ emf_account_list_t *p = g_account_list, *p_next;
+ while (p) {
+ em_core_account_free(&p->account, 1, NULL);
+
+ p_next = p->next;
+ free(p);
+ p = p_next;
+ }
+
+ g_account_retrieved = 0;
+ g_account_num = 0;
+ g_account_list = NULL;
+ EM_DEBUG_FUNC_END();
+ return true;
+}
+
+EXPORT_API int em_core_account_free(emf_account_t **account_list, int count, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("account_list[%p], count[%d], err_code[%p]", account_list, count, err_code);
+
+ /* default variabl */
+ int ret = false;
+ int err = EMF_ERROR_NONE;
+
+ if (count > 0) {
+ if (!account_list || !*account_list) {
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ emf_account_t *p = *account_list;
+ int i;
+
+ for (i = 0; i < count; i++) {
+ EM_SAFE_FREE(p[i].account_name);
+ EM_SAFE_FREE(p[i].receiving_server_addr);
+ EM_SAFE_FREE(p[i].email_addr);
+ EM_SAFE_FREE(p[i].user_name);
+ EM_SAFE_FREE(p[i].password);
+ EM_SAFE_FREE(p[i].sending_server_addr);
+ EM_SAFE_FREE(p[i].sending_user);
+ EM_SAFE_FREE(p[i].sending_password);
+ EM_SAFE_FREE(p[i].display_name);
+ EM_SAFE_FREE(p[i].reply_to_addr);
+ EM_SAFE_FREE(p[i].return_addr);
+ EM_SAFE_FREE(p[i].logo_icon_path);
+ EM_SAFE_FREE(p[i].options.display_name_from);
+ EM_SAFE_FREE(p[i].options.signature);
+ }
+
+ EM_SAFE_FREE(p); *account_list = NULL;
+ }
+
+ ret = true;
+
+FINISH_OFF:
+ if (err_code)
+ *err_code = err;
+ EM_DEBUG_FUNC_END();
+ return ret;
+}
+
+
+EXPORT_API int em_core_account_get_list_refer(emf_account_t **account_list, int *count, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("account_list[%p], count[%p], err_code[%p]", account_list, count, err_code);
+ int i, countOfAccounts = 0;
+ int ret = false;
+ int err = EMF_ERROR_NONE;
+ emf_account_t *accountRef;
+ emf_account_list_t *p;
+
+ if (!account_list || !count) {
+ EM_DEBUG_EXCEPTION("account_list[%p], count[%p]", account_list, count);
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ p = g_account_list;
+
+ while (p) {
+ countOfAccounts++;
+ p = p->next;
+ }
+
+ EM_DEBUG_LOG("Result count[%d]", countOfAccounts);
+ *count = countOfAccounts;
+
+ if (countOfAccounts > 0) {
+ *account_list = malloc(sizeof(emf_account_t) * countOfAccounts);
+ if (!*account_list) {
+ EM_DEBUG_LOG("malloc failed...");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+ }
+
+ p = g_account_list;
+ for (i = 0; i < countOfAccounts; i++) {
+ accountRef = (*account_list) + i;
+ memcpy(accountRef, p->account , sizeof(emf_account_t));
+ p = p->next;
+ }
+
+ for (i = 0; i < countOfAccounts; i++) {
+ accountRef = (*account_list) + i;
+ EM_DEBUG_LOG("Result account id[%d], name[%s]", accountRef->account_id, accountRef->account_name);
+ }
+
+ ret = true;
+
+FINISH_OFF:
+ if (ret == false) {
+ if (account_list) /* Warn! this is not *account_list. Just account_list */
+ EM_SAFE_FREE(*account_list);
+ }
+
+ if (err_code != NULL)
+ *err_code = err;
+ EM_DEBUG_FUNC_END();
+ return ret;
+}
+
+
+#ifdef __FEATURE_BACKUP_ACCOUNT__
+#include <ss_manager.h>
+
+static int append_data_into_buffer(char **target_buffer, int *target_buffer_lenth, char *input_data, int input_data_length, int *error_code)
+{
+ EM_DEBUG_FUNC_BEGIN("target_buffer [%p], target_buffer_lenth [%p], input_data [%p], input_data_length[%d]", target_buffer, target_buffer_lenth, input_data, input_data_length);
+ int local_error_code = EMF_ERROR_NONE, ret_code = false;
+
+ if (!target_buffer || !target_buffer_lenth || !input_data) {
+ EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
+ local_error_code = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ if (*target_buffer_lenth > 0 && input_data_length) {
+ EM_DEBUG_LOG("*target_buffer_lenth [%d]", *target_buffer_lenth);
+ *target_buffer = realloc(*target_buffer, (*target_buffer_lenth) + input_data_length);
+ if (!*target_buffer) {
+ EM_DEBUG_EXCEPTION("realloc failed");
+ local_error_code = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+ memcpy(*target_buffer + (*target_buffer_lenth), input_data, input_data_length);
+ *target_buffer_lenth += input_data_length;
+ EM_DEBUG_LOG("*target_buffer_lenth [%d] input_data_length [%d]", *target_buffer_lenth, input_data_length);
+ }
+ else {
+ EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
+ local_error_code = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ ret_code = true;
+
+FINISH_OFF:
+
+ if (error_code)
+ *error_code = local_error_code;
+ EM_DEBUG_FUNC_END("ret_code [%d]", ret_code);
+
+ return ret_code;
+}
+
+
+static int em_core_write_account_into_buffer(char **target_buffer, int *target_buffer_lenth, emf_mail_account_tbl_t *account_tbl_ptr, int *error_code)
+{
+ EM_DEBUG_FUNC_BEGIN("target_buffer [%p], target_buffer_lenth [%p], account_tbl_ptr [%p], error_code [%p]", target_buffer, target_buffer_lenth, account_tbl_ptr, error_code);
+ int local_error_code = EMF_ERROR_NONE, ret_code = false, stream_length = 0;
+ emf_account_t *temp_account = NULL;
+ char *byte_stream = NULL;
+
+ temp_account = em_core_malloc(sizeof(emf_account_t));
+ memset(temp_account, 0, sizeof(emf_account_t));
+
+ if (em_convert_account_tbl_to_account(account_tbl_ptr, temp_account)) {
+ byte_stream = em_convert_account_to_byte_stream(temp_account, &stream_length);
+ EM_DEBUG_LOG("stream_length [%d]", stream_length);
+ /* EM_DEBUG_LOG("password [%s]", temp_account->password) */
+
+ if (byte_stream) {
+ if (!append_data_into_buffer(target_buffer, target_buffer_lenth, (char *)&stream_length, sizeof(int), &local_error_code)) {
+ EM_DEBUG_EXCEPTION("append_data_into_buffer failed");
+ goto FINISH_OFF;
+ }
+ EM_DEBUG_LOG("append_data_into_buffer succeed for stream_length");
+
+ if (!append_data_into_buffer(target_buffer, target_buffer_lenth, byte_stream, stream_length, &local_error_code)) {
+ EM_DEBUG_EXCEPTION("append_data_into_buffer failed");
+ goto FINISH_OFF;
+ }
+ EM_DEBUG_LOG("append_data_into_buffer succeed for byte_stream");
+ }
+ }
+ else {
+ EM_DEBUG_EXCEPTION("em_convert_account_tbl_to_account failed");
+ local_error_code = EM_STORAGE_ERROR_SYSTEM_FAILURE;
+ goto FINISH_OFF;
+ }
+
+ ret_code = true;
+FINISH_OFF:
+ if (temp_account)
+ em_core_account_free(&temp_account, 1, NULL);
+ if (error_code)
+ *error_code = local_error_code;
+
+ EM_SAFE_FREE(byte_stream);
+
+ EM_DEBUG_FUNC_END("ret_code [%d]", ret_code);
+ return ret_code;
+}
+
+EXPORT_API int em_core_backup_accounts(const char *file_path, int *error_code)
+{
+ EM_DEBUG_FUNC_BEGIN("file_path [%s], error_code [%p]", file_path, error_code);
+ int local_error_code = EMF_ERROR_NONE, local_error_code_2 = EMF_ERROR_NONE, ret_code = false;
+ int select_num, i, target_buff_length = 0;
+ char *target_buffer = NULL;
+ emf_mail_account_tbl_t *account_list = NULL;
+
+ if (!file_path) {
+ local_error_code = EMF_ERROR_INVALID_PARAM;
+ EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
+ goto FINISH_OFF;
+ }
+
+ select_num = 1000;
+
+ if (!em_storage_get_account_list(&select_num, &account_list, true, true, &local_error_code)) {
+ EM_DEBUG_EXCEPTION("em_storage_get_account_list failed [%d]", local_error_code);
+ goto FINISH_OFF;
+ }
+
+ EM_DEBUG_LOG("select_num [%d]", select_num);
+
+ if (account_list) {
+ target_buffer = malloc(sizeof(int));
+ if (!target_buffer) {
+ EM_DEBUG_EXCEPTION("malloc failed");
+ local_error_code = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ memcpy(target_buffer, (char *)&select_num, sizeof(int));
+ target_buff_length = sizeof(int);
+
+ for (i = 0; i < select_num; i++) {
+ if (!em_core_write_account_into_buffer(&target_buffer, &target_buff_length, account_list + i, &local_error_code)) {
+ EM_DEBUG_EXCEPTION("em_core_write_account_into_buffer failed [%d]", local_error_code);
+ goto FINISH_OFF;
+ }
+ }
+
+ EM_DEBUG_LOG("target_buff_length [%d]", target_buff_length);
+
+ ssm_delete_file(file_path, SSM_FLAG_SECRET_OPERATION, NULL);
+
+ if (ssm_write_buffer(target_buffer, target_buff_length, file_path, SSM_FLAG_SECRET_OPERATION, NULL) < 0) {
+ EM_DEBUG_EXCEPTION("ssm_write_buffer failed [%d]", local_error_code);
+ local_error_code = EM_STORAGE_ERROR_SYSTEM_FAILURE;
+ goto FINISH_OFF;
+ }
+
+ }
+
+ ret_code = true;
+FINISH_OFF:
+
+ EM_SAFE_FREE(target_buffer);
+ if (account_list)
+ em_storage_free_account(&account_list, select_num, &local_error_code_2);
+
+ if (error_code)
+ *error_code = local_error_code;
+
+ EM_DEBUG_FUNC_END("ret_code [%d]", ret_code);
+ return ret_code;
+}
+
+EXPORT_API int em_core_restore_accounts(const char *file_path, int *error_code)
+{
+ EM_DEBUG_FUNC_BEGIN("file_path [%s], error_code [%p]", file_path, error_code);
+ int local_error_code = EMF_ERROR_NONE, ret_code = false, buffer_length = 0, read_length = 0;
+ int account_count = 0, i = 0, account_stream_length = 0;
+ char *temp_buffer = NULL, *account_stream = NULL, *buffer_ptr = NULL;
+ emf_account_t *temp_account = NULL, *account_list = NULL;
+
+ ssm_file_info_t sfi;
+
+ if (!file_path) {
+ local_error_code = EMF_ERROR_INVALID_PARAM;
+ EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
+ goto FINISH_OFF;
+ }
+
+ if (em_core_account_get_list_refer(&account_list, &account_count, &ret_code)) {
+ for (i = 0; i < account_count; i++) {
+ if (!em_core_account_delete(account_list[i].account_id, &ret_code)) {
+ local_error_code = EMF_ERROR_INVALID_ACCOUNT;
+ EM_DEBUG_EXCEPTION("em_core_account_delete failed");
+ goto FINISH_OFF;
+ }
+ }
+ }
+
+ if (ssm_getinfo(file_path, &sfi, SSM_FLAG_SECRET_OPERATION, NULL) < 0) {
+ EM_DEBUG_EXCEPTION("ssm_getinfo() failed.");
+ ret_code = EM_STORAGE_ERROR_SYSTEM_FAILURE;
+ goto FINISH_OFF;
+ }
+
+ buffer_length = sfi.originSize;
+ EM_DEBUG_LOG("account buffer_length[%d]", buffer_length);
+ if ((temp_buffer = (char *)em_core_malloc(buffer_length + 1)) == NULL) {
+ EM_DEBUG_EXCEPTION("em_core_malloc failed...");
+ ret_code = EM_STORAGE_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ if (ssm_read(file_path, temp_buffer, buffer_length, (size_t *)&read_length, SSM_FLAG_SECRET_OPERATION, NULL) < 0) {
+ EM_DEBUG_EXCEPTION("ssm_read() failed.");
+ ret_code = EM_STORAGE_ERROR_SYSTEM_FAILURE;
+ goto FINISH_OFF;
+ }
+
+ EM_DEBUG_LOG("read_length[%d]", read_length);
+
+ if (buffer_length == read_length) {
+ memcpy((void *)&account_count, temp_buffer, sizeof(int));
+ buffer_ptr = temp_buffer + sizeof(int);
+
+ EM_DEBUG_LOG("account_count[%d]", account_count);
+
+ for (i = 0; i < account_count; i++) {
+ memcpy((void *)&account_stream_length, buffer_ptr, sizeof(int));
+ buffer_ptr += sizeof(int);
+ EM_DEBUG_LOG("account_stream_length [%d]", account_stream_length);
+ if (account_stream_length) {
+ account_stream = em_core_malloc(account_stream_length);
+ if (!account_stream) {
+ EM_DEBUG_EXCEPTION("em_core_malloc() failed.");
+ ret_code = EMF_ERROR_OUT_OF_MEMORY ;
+ goto FINISH_OFF;
+ }
+ memcpy(account_stream, buffer_ptr, account_stream_length);
+
+ temp_account = em_core_malloc(sizeof(emf_account_t));
+
+ if (!temp_account) {
+ EM_DEBUG_EXCEPTION("em_core_malloc() failed.");
+ ret_code = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ em_convert_byte_stream_to_account(account_stream, temp_account);
+ EM_SAFE_FREE(account_stream);
+
+ if (!em_core_account_create(temp_account, &ret_code)) {
+ EM_DEBUG_EXCEPTION("em_core_account_create() failed.");
+ goto FINISH_OFF;
+ }
+
+ em_core_account_free(&temp_account, 1, &ret_code);
+ temp_account = NULL;
+ }
+ buffer_ptr += account_stream_length;
+ account_stream_length = 0;
+ }
+ } else {
+ EM_DEBUG_EXCEPTION("ssm_read() failed.");
+ ret_code = EMF_ERROR_SYSTEM_FAILURE;
+ goto FINISH_OFF;
+ }
+ ret_code = true;
+FINISH_OFF:
+ if (temp_account)
+ em_core_account_free(&temp_account, 1, NULL);
+ EM_SAFE_FREE(account_stream);
+ EM_SAFE_FREE(temp_buffer);
+
+ EM_DEBUG_FUNC_END("ret_code [%d]", ret_code);
+ return ret_code;
+}
+
+#endif /* __FEATURE_BACKUP_ACCOUNT_ */
+
+EXPORT_API int em_core_query_server_info(const char* domain_name, emf_server_info_t **result_server_info)
+{
+ EM_DEBUG_FUNC_BEGIN("domain_name [%s], result_server_info [%p]", domain_name, result_server_info);
+ int ret_code = EMF_ERROR_NONE;
+
+
+ EM_DEBUG_FUNC_END("ret_code [%d]", ret_code);
+ return ret_code;
+}
+
+
+EXPORT_API int em_core_free_server_info(emf_server_info_t **target_server_info)
+{
+ EM_DEBUG_FUNC_BEGIN("result_server_info [%p]", target_server_info);
+ int i, ret_code = EMF_ERROR_NONE;
+ emf_server_info_t *server_info = NULL;
+
+ if(target_server_info && *target_server_info) {
+ server_info = *target_server_info;
+ EM_SAFE_FREE(server_info->service_name);
+ for(i = 0; i < server_info->protocol_conf_count; i++) {
+ EM_SAFE_FREE(server_info->protocol_config_array[i].server_addr);
+ }
+ EM_SAFE_FREE(server_info->protocol_config_array);
+ EM_SAFE_FREE(server_info);
+ }
+ EM_DEBUG_FUNC_END("ret_code [%d]", ret_code);
+ return ret_code;
+}
+
+EXPORT_API int em_core_save_default_account_id(int input_account_id)
+{
+ EM_DEBUG_FUNC_BEGIN("account_id [%d]", input_account_id);
+ int ret_code = EMF_ERROR_NONE, result_value = 0;
+
+ result_value = vconf_set_int(VCONF_KEY_DEFAULT_ACCOUNT_ID, input_account_id);
+ if (result_value < 0) {
+ EM_DEBUG_EXCEPTION("vconf_set_int failed [%d]", result_value);
+ ret_code = EMF_ERROR_SYSTEM_FAILURE;
+ }
+
+ EM_DEBUG_FUNC_END("ret_code [%d]", ret_code);
+ return ret_code;
+}
+
+EXPORT_API int em_core_load_default_account_id(int *output_account_id)
+{
+ EM_DEBUG_FUNC_BEGIN("account_id [%p]", output_account_id);
+ int ret_code = EMF_ERROR_NONE, result_value = 0;
+
+ if (output_account_id == NULL) {
+ ret_code = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ result_value = vconf_get_int(VCONF_KEY_DEFAULT_ACCOUNT_ID, output_account_id);
+
+ if (result_value < 0) {
+ EM_DEBUG_EXCEPTION("vconf_get_int() failed [%d]", result_value);
+ ret_code = EMF_ERROR_SYSTEM_FAILURE;
+ *output_account_id = 0;
+ }
+
+FINISH_OFF:
+
+ EM_DEBUG_FUNC_END("ret_code [%d]", ret_code);
+ return ret_code;
+}
diff --git a/email-core/em-core-api.c b/email-core/em-core-api.c
new file mode 100755
index 0000000..4dfef10
--- /dev/null
+++ b/email-core/em-core-api.c
@@ -0,0 +1,239 @@
+/*
+* email-service
+*
+* Copyright (c) 2000 - 2011 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.
+*
+*/
+
+
+/******************************************************************************
+ * File : em-core-api.h
+ * Desc : Mail Engine API
+ *
+ * Auth :
+ *
+ * History :
+ * 2006.08.16 : created
+ *****************************************************************************/
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+#include "c-client.h"
+#include "em-core-global.h"
+#include "em-network.h"
+#include "em-core-event.h"
+#include "em-core-mailbox.h"
+#include "em-core-utils.h"
+#include "emf-dbglog.h"
+
+extern void *
+pop3_parameters(long function, void *value);
+extern void *
+imap_parameters(long function, void *value);
+
+/*
+ * encoding base64
+ */
+int em_core_encode_base64(char *src, unsigned long src_len, char **enc, unsigned long* enc_len, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ unsigned char *content;
+ int ret = true, err = EMF_ERROR_NONE;
+
+ if (err_code != NULL) {
+ *err_code = EMF_ERROR_NONE;
+ }
+
+ content = rfc822_binary(src, src_len, enc_len);
+
+ if (content)
+ *enc = (char *)content;
+ else {
+ err = EMF_ERROR_UNKNOWN;
+ ret = false;
+ }
+
+ if (err_code)
+ *err_code = err;
+
+ EM_DEBUG_FUNC_END();
+ return ret;
+}
+
+/*
+ * decoding quoted-printable
+ */
+int em_core_decode_quotedprintable(unsigned char *enc_text, unsigned long enc_len, char **dec_text, unsigned long* dec_len, int *err_code)
+{
+ unsigned char *text = enc_text;
+ unsigned long size = enc_len;
+ unsigned char *content;
+ int ret = true, err = EMF_ERROR_NONE;
+
+ if (err_code != NULL) {
+ *err_code = EMF_ERROR_NONE;
+ }
+
+ EM_DEBUG_FUNC_BEGIN();
+
+ content = rfc822_qprint(text, size, dec_len);
+
+ if (content)
+ *dec_text = (char *)content;
+ else
+ {
+ err = EMF_ERROR_UNKNOWN;
+ ret = false;
+ }
+
+ if (err_code)
+ *err_code = err;
+
+ return ret;
+}
+
+/*
+ * decoding base64
+ */
+int em_core_decode_base64(unsigned char *enc_text, unsigned long enc_len, char **dec_text, unsigned long* dec_len, int *err_code)
+{
+ unsigned char *text = enc_text;
+ unsigned long size = enc_len;
+ unsigned char *content;
+ int ret = true, err = EMF_ERROR_NONE;
+
+ if (err_code != NULL) {
+ *err_code = EMF_ERROR_NONE;
+ }
+
+ EM_DEBUG_FUNC_BEGIN();
+
+ content = rfc822_base64(text, size, dec_len);
+ if (content)
+ *dec_text = (char *)content;
+ else
+ {
+ err = EMF_ERROR_UNKNOWN;
+ ret = false;
+ }
+
+ if (err_code)
+ *err_code = err;
+
+ return ret;
+}
+
+/**
+ * em_core_get_logout_status - Get the logout status
+ **/
+EXPORT_API void
+em_core_get_logout_status(int *status)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int logout_status = 0;
+ *status = logout_status;
+ EM_DEBUG_LOG("em_core_get_logout_status is not implemented");
+ EM_DEBUG_FUNC_END("status [%d]", logout_status);
+}
+
+
+/**
+ * em_core_set_logout_status - Set the logout status
+ **/
+EXPORT_API void
+em_core_set_logout_status(int status)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ EM_DEBUG_LOG("em_core_set_logout_status is not implemented");
+ EM_DEBUG_FUNC_END("status [%d] ", status);
+}
+
+#define EM_BATTERY_RECOVER_TEMP 6
+#define EM_BATTERY_ONLINE 1
+int _check_charger_status(int *charging_status, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("err_code[%p] ", err_code);
+
+ int ret = false;
+ int err = EMF_ERROR_NONE;
+ int ps_value = 0;
+
+ *charging_status = ps_value;
+
+ ret = true;
+
+ if (err_code != NULL)
+ *err_code = err;
+ EM_DEBUG_FUNC_END();
+ return ret;
+}
+
+EXPORT_API
+int em_low_battery_noti_init()
+{
+ EM_DEBUG_FUNC_BEGIN();
+ EM_DEBUG_LOG("Not implemented");
+ EM_DEBUG_FUNC_END();
+ return 0;
+}
+
+/* initialize mail core */
+EXPORT_API int em_core_init(int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ if (err_code != NULL) {
+ *err_code = EMF_ERROR_NONE;
+ }
+
+ mail_link(&imapdriver); /* link in the imap driver */
+ mail_link(&pop3driver); /* link in the pop3 driver */
+
+ mail_link(&unixdriver); /* link in the unix driver */
+ mail_link(&dummydriver); /* link in the dummy driver */
+
+ ssl_onceonlyinit();
+
+ auth_link(&auth_md5); /* link in the md5 authenticator */
+ auth_link(&auth_pla); /* link in the pla authenticator */
+ auth_link(&auth_log); /* link in the log authenticator */
+
+ /* Disabled to authenticate with plain text */
+ mail_parameters(NIL, SET_DISABLEPLAINTEXT, (void *) 2);
+
+ /* Set max trials for login */
+ imap_parameters(SET_MAXLOGINTRIALS, (void *)1);
+ pop3_parameters(SET_MAXLOGINTRIALS, (void *)1);
+ smtp_parameters(SET_MAXLOGINTRIALS, (void *)1);
+
+ mail_parameters(NIL, SET_SSLCERTIFICATEQUERY, (void *)em_core_ssl_cert_query_cb);
+ mail_parameters(NIL, SET_SSLCAPATH, (void *)SSL_CERT_DIRECTORY);
+
+ /* Set time out in second */
+ mail_parameters(NIL, SET_OPENTIMEOUT , (void *)50);
+ mail_parameters(NIL, SET_READTIMEOUT , (void *)180);
+ mail_parameters(NIL, SET_WRITETIMEOUT , (void *)180);
+ mail_parameters(NIL, SET_CLOSETIMEOUT , (void *)30);
+
+ if (err_code)
+ *err_code = EMF_ERROR_NONE;
+
+ return true;
+}
+
diff --git a/email-core/em-core-event.c b/email-core/em-core-event.c
new file mode 100755
index 0000000..57f720d
--- /dev/null
+++ b/email-core/em-core-event.c
@@ -0,0 +1,3701 @@
+/*
+* email-service
+*
+* Copyright (c) 2000 - 2011 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.
+*
+*/
+
+
+
+/******************************************************************************
+ * File : em-core-event_data.h
+ * Desc : Mail Engine Event
+ *
+ * Auth :
+ *
+ * History :
+ * 2006.08.16 : created
+ *****************************************************************************/
+#include <stdio.h>
+#include <glib.h>
+#include <malloc.h>
+#include <vconf.h>
+
+#include <signal.h>
+#include <contacts-svc.h>
+#include "Msg_Convert.h"
+#include "c-client.h"
+#include "em-storage.h"
+#include "em-network.h"
+#include "emf-auto-poll.h"
+#include "em-core-global.h"
+#include "em-core-account.h"
+#include "em-core-event.h"
+#include "em-core-utils.h"
+#include "em-core-mailbox.h"
+#include "em-core-imap-mailbox.h"
+#include "em-core-mesg.h"
+#include "em-core-mailbox-sync.h"
+#include "em-core-smtp.h"
+#include "em-core-utils.h"
+#include "em-core-sound.h"
+#include "emf-dbglog.h"
+
+
+#ifdef __FEATURE_PARTIAL_BODY_DOWNLOAD__
+
+/*[h.gahlaut] - All static variable declaration for partial body download thread are done here */
+
+#define TOTAL_PARTIAL_BODY_EVENTS 100
+
+static emf_event_partial_body_thd g_partial_body_thd_event_que[TOTAL_PARTIAL_BODY_EVENTS];
+
+static int g_partial_body_thd_next_event_idx = 0; /* Index of Next Event to be processed in the queue*/
+static int g_partial_body_thd_loop = 1; /* Variable to make a continuos while loop */
+static int g_partial_body_thd_queue_empty = true; /* Variable to determine if event queue is empty.True means empty*/
+static int g_partial_body_thd_queue_full = false; /* Variable to determine if event queue is full. True means full*/
+static int g_pb_thd_local_activity_continue = true; /* Variable to control local activity sync */
+int g_pbd_thd_state = false; /* false : thread is sleeping , true : thread is working */
+
+#ifdef __FEATURE_USE_PTHREAD__
+static pthread_mutex_t _partial_body_thd_event_queue_lock = PTHREAD_MUTEX_INITIALIZER; /* Mutex to protect event queue */
+static pthread_cond_t _partial_body_thd_cond = PTHREAD_COND_INITIALIZER; /* Condition variable on which partial body thread is waiting */
+thread_t g_partial_body_thd ; /* Determines if thread is created or not. Non Null means thread is created */
+#else /* __FEATURE_USE_PTHREAD__ */
+static GMutex *_partial_body_thd_event_queue_lock = NULL; /* Mutex to protect event queue */
+static GCond *_partial_body_thd_cond = NULL; /* Condition variable on which partial body thread is waiting */
+thread_t g_partial_body_thd = NULL; /* Determines if thread is created or not. Non Null means thread is created */
+#endif /* __FEATURE_USE_PTHREAD__ */
+
+emf_event_partial_body_thd g_partial_body_bulk_dwd_que[BULK_PARTIAL_BODY_DOWNLOAD_COUNT];
+static int g_partial_body_bulk_dwd_next_event_idx = 0; /* Index of Next Event to be processed in the queue*/
+static int g_partial_body_bulk_dwd_queue_empty = true;
+
+#ifdef __FEATURE_USE_PTHREAD__
+static pthread_mutex_t _state_variables_lock;
+#else /* __FEATURE_USE_PTHREAD__ */
+static GMutex *_state_variables_lock = NULL; /*Mutex for maintaining credibility of state variable */
+#endif /* __FEATURE_USE_PTHREAD__ */
+
+
+/*[h.gahlaut] - All static function declaration for partial body download thread are done here */
+
+static int em_core_retrieve_partial_body_thread_event(emf_event_partial_body_thd *partial_body_thd_event, int *error_code);
+static int em_core_copy_partial_body_thd_event(emf_event_partial_body_thd *src, emf_event_partial_body_thd *dest, int *error_code);
+static void em_core_pb_thd_set_local_activity_continue(int flag);
+static int em_core_set_pbd_thd_state(int flag);
+static int em_core_clear_bulk_pbd_que(int *err_code);
+int em_core_mail_partial_body_download(emf_event_partial_body_thd *pbd_event, int *error_code);
+
+#endif
+
+#ifdef ENABLE_IMAP_IDLE_THREAD
+extern int g_imap_idle_thread_alive;
+extern int imap_idle_thread;
+#endif /* ENABLE_IMAP_IDLE_THREAD */
+EXPORT_API int g_client_count = 0;
+EXPORT_API int g_client_run = 0 ;
+
+#ifdef __LOCAL_ACTIVITY__
+EXPORT_API int g_local_activity_run = 0;
+EXPORT_API int g_save_local_activity_run = 0;
+#endif
+
+
+#define EVENT_QUEUE_MAX 32
+
+typedef struct EVENT_CALLBACK_ELEM
+{
+ emf_event_callback callback;
+ void *event_data;
+ struct EVENT_CALLBACK_ELEM *next;
+} EVENT_CALLBACK_LIST;
+
+#ifdef __FEATURE_USE_PTHREAD__
+static pthread_mutex_t _event_available_lock = PTHREAD_MUTEX_INITIALIZER;
+static pthread_cond_t _event_available_signal = PTHREAD_COND_INITIALIZER;
+static pthread_mutex_t *_event_queue_lock = NULL;
+static pthread_mutex_t *_event_callback_table_lock = NULL;
+#else /* __FEATURE_USE_PTHREAD__ */
+static GMutex *_event_available_lock = NULL;
+static GCond *_event_available_signal = NULL;
+static GStaticRecMutex _event_queue_lock;
+static GStaticRecMutex _event_callback_table_lock;
+#endif /* __FEATURE_USE_PTHREAD__ */
+static EVENT_CALLBACK_LIST *_event_callback_table[EMF_ACTION_NUM]; /* array of singly-linked list for event callbacks */
+
+void *thread_func_branch_command(void *arg);
+
+
+static emf_event_t g_event_que[EVENT_QUEUE_MAX];
+
+int send_thread_run = 0;
+int recv_thread_run = 0;
+
+#ifdef __FEATURE_USE_PTHREAD__
+static pthread_mutex_t _send_event_available_lock = PTHREAD_MUTEX_INITIALIZER;
+static pthread_mutex_t *_send_event_queue_lock = NULL; /* MUST BE "recursive" */
+static pthread_cond_t _send_event_available_signal = PTHREAD_COND_INITIALIZER;
+static thread_t g_send_srv_thread;
+static thread_t g_srv_thread;
+#else /* __FEATURE_USE_PTHREAD__ */
+static GMutex *_send_event_available_lock = NULL;
+static GStaticRecMutex _send_event_queue_lock; /* MUST BE "recursive" */
+static GCond *_send_event_available_signal = NULL;
+static thread_t g_send_srv_thread = NULL;
+static thread_t g_srv_thread = NULL;
+#endif /* __FEATURE_USE_PTHREAD__ */
+
+
+static emf_event_t g_send_event_que[EVENT_QUEUE_MAX];
+static int g_send_event_que_idx = 1;
+static int g_send_event_loop = 1;
+static int g_send_active_que = 0;
+static int g_event_que_idx = 1;
+static int g_event_loop = 1;
+static int g_active_que = 0;
+static int g_sending_busy_cnt = 0;
+static int g_receiving_busy_cnt = 0;
+
+
+EXPORT_API int em_core_get_current_thread_type()
+{
+ EM_DEBUG_FUNC_BEGIN();
+ thread_t thread_id = THREAD_SELF();
+ int thread_type = -1;
+
+ if (thread_id == g_srv_thread)
+ thread_type = _SERVICE_THREAD_TYPE_RECEIVING;
+ else if (thread_id == g_send_srv_thread)
+ thread_type = _SERVICE_THREAD_TYPE_SENDING;
+#ifdef __FEATURE_PARTIAL_BODY_DOWNLOAD__
+ else if (thread_id == g_partial_body_thd)
+ thread_type = _SERVICE_THREAD_TYPE_PBD;
+#endif
+ EM_DEBUG_FUNC_END("thread_type [%d]", thread_type);
+ return thread_type;
+}
+
+static int is_gdk_lock_needed()
+{
+ if (g_event_loop) {
+ return (THREAD_SELF() == g_srv_thread);
+ }
+ return false;
+}
+
+EXPORT_API int em_core_get_pending_event(emf_action_t action, int account_id, int mail_id, emf_event_status_type_t *status)
+{
+ EM_DEBUG_FUNC_BEGIN("action[%d], account_id[%d], mail_id[%d]", action, account_id, mail_id);
+
+ int found = false;
+ int i;
+
+ ENTER_RECURSIVE_CRITICAL_SECTION(_event_queue_lock);
+
+ for (i = 1; i < EVENT_QUEUE_MAX; i++) {
+ switch (g_event_que[i].type) {
+ case EMF_EVENT_SEND_MAIL:
+ case EMF_EVENT_SEND_MAIL_SAVED:
+ if (action == EMF_ACTION_SEND_MAIL && account_id == g_event_que[i].account_id && mail_id == g_event_que[i].event_param_data_4) {
+ found = true;
+ goto EXIT;
+ }
+ break;
+ case EMF_EVENT_SAVE_MAIL:
+ if (action == EMF_ACTION_SAVE_MAIL && account_id == g_event_que[i].account_id && mail_id == g_event_que[i].event_param_data_4) {
+ found = true;
+ goto EXIT;
+ }
+ break;
+
+ case EMF_EVENT_SYNC_HEADER:
+ if (action == EMF_ACTION_SYNC_HEADER && account_id == g_event_que[i].account_id) {
+ found = true;
+ goto EXIT;
+ }
+ break;
+
+ case EMF_EVENT_SYNC_HEADER_OMA:
+ if (action == EMF_ACTION_SYNC_HEADER_OMA && account_id == g_event_que[i].account_id) {
+ found = true;
+ goto EXIT;
+ }
+ break;
+
+ case EMF_EVENT_DOWNLOAD_BODY:
+ if (action == EMF_ACTION_DOWNLOAD_BODY && account_id == g_event_que[i].account_id && mail_id == g_event_que[i].event_param_data_4) {
+ found = true;
+ goto EXIT;
+ }
+ break;
+ case EMF_EVENT_SYNC_MAIL_FLAG_TO_SERVER:
+ if (action == EMF_ACTION_SYNC_MAIL_FLAG_TO_SERVER && account_id == g_event_que[i].account_id && mail_id == g_event_que[i].event_param_data_4) {
+ found = true;
+ goto EXIT;
+ }
+ break;
+ case EMF_EVENT_SYNC_FLAGS_FIELD_TO_SERVER:
+ if (action == EMF_ACTION_SYNC_FLAGS_FIELD_TO_SERVER && account_id == g_event_que[i].account_id && mail_id == g_event_que[i].event_param_data_4) {
+ found = true;
+ goto EXIT;
+ }
+ break;
+ case EMF_EVENT_DOWNLOAD_ATTACHMENT:
+ if (action == EMF_ACTION_DOWNLOAD_ATTACHMENT && account_id == g_event_que[i].account_id && mail_id == g_event_que[i].event_param_data_4) {
+ found = true;
+ goto EXIT;
+ }
+ break;
+ case EMF_EVENT_DELETE_MAIL:
+ case EMF_EVENT_DELETE_MAIL_ALL:
+ if (action == EMF_ACTION_DELETE_MAIL && account_id == g_event_que[i].account_id) {
+ found = true;
+ goto EXIT;
+ }
+ break;
+
+ case EMF_EVENT_CREATE_MAILBOX:
+ if (action == EMF_ACTION_CREATE_MAILBOX && account_id == g_event_que[i].account_id) {
+ found = true;
+ goto EXIT;
+ }
+ break;
+
+ case EMF_EVENT_DELETE_MAILBOX:
+ if (action == EMF_ACTION_DELETE_MAILBOX && account_id == g_event_que[i].account_id) {
+ found = true;
+ goto EXIT;
+ }
+ break;
+
+ case EMF_EVENT_MOVE_MAIL:
+ if (action == EMF_ACTION_MOVE_MAIL && account_id == g_event_que[i].account_id && mail_id == g_event_que[i].event_param_data_4) {
+ found = true;
+ goto EXIT;
+ }
+ break;
+
+ case EMF_EVENT_VALIDATE_ACCOUNT:
+ if (action == EMF_ACTION_VALIDATE_ACCOUNT && account_id == g_event_que[i].account_id) {
+ found = true;
+ goto EXIT;
+ }
+ break;
+
+ case EMF_EVENT_VALIDATE_AND_UPDATE_ACCOUNT:
+ if (action == EMF_ACTION_VALIDATE_AND_UPDATE_ACCOUNT && account_id == 0) {
+ found = true;
+ goto EXIT;
+ }
+ break;
+
+ case EMF_EVENT_VALIDATE_AND_CREATE_ACCOUNT:
+ if (action == EMF_ACTION_VALIDATE_AND_CREATE_ACCOUNT && account_id == 0) {
+ found = true;
+ goto EXIT;
+ }
+ break;
+
+ case EMF_EVENT_UPDATE_MAIL_OLD:
+ case EMF_EVENT_UPDATE_MAIL:
+ if (action == EMF_ACTION_UPDATE_MAIL) {
+ found = true;
+ goto EXIT;
+ }
+ break;
+
+ case EMF_EVENT_SET_MAIL_SLOT_SIZE:
+ if (action == EMF_ACTION_SET_MAIL_SLOT_SIZE) {
+ found = true;
+ goto EXIT;
+ }
+ break;
+
+ default:
+ break;
+ }
+ }
+
+EXIT:
+ LEAVE_RECURSIVE_CRITICAL_SECTION(_event_queue_lock);
+
+ if (found) {
+ if (status)
+ *status = g_event_que[i].status;
+
+ return i;
+ }
+
+ return FAILURE;
+}
+
+EXPORT_API void em_core_get_event_queue_status(int *on_sending, int *on_receiving)
+{
+ if (on_sending != NULL)
+ *on_sending = g_sending_busy_cnt;
+
+ if (on_receiving != NULL)
+ *on_receiving = g_receiving_busy_cnt;
+}
+
+static void _sending_busy_ref(void)
+{
+ g_sending_busy_cnt++;
+}
+
+static void _sending_busy_unref(void)
+{
+ g_sending_busy_cnt--;
+}
+
+static void _receiving_busy_ref(void)
+{
+ g_receiving_busy_cnt++;
+}
+
+static void _receiving_busy_unref(void)
+{
+ g_receiving_busy_cnt--;
+}
+
+static void waiting_status_notify(emf_event_t *event_data, int queue_idx)
+{
+ EM_DEBUG_FUNC_BEGIN("event_data[%p], queue_idx[%d]", event_data, queue_idx);
+
+ int account_id = event_data->account_id;
+ int mail_id = event_data->event_param_data_4; /* NOT ALWAYS */
+
+ switch (event_data->type) {
+ case EMF_EVENT_SEND_MAIL:
+ em_core_execute_event_callback(EMF_ACTION_SEND_MAIL, 0, 0, EMF_SEND_WAITING, account_id, mail_id, queue_idx, EMF_ERROR_NONE);
+ break;
+
+ case EMF_EVENT_SYNC_HEADER:
+ em_core_execute_event_callback(EMF_ACTION_SYNC_HEADER, 0, 0, EMF_LIST_WAITING, account_id, 0, queue_idx, EMF_ERROR_NONE);
+ break;
+
+ case EMF_EVENT_SYNC_HEADER_OMA:
+ em_core_execute_event_callback(EMF_ACTION_SYNC_HEADER_OMA, 0, 0, EMF_LIST_WAITING, account_id, 0, queue_idx, EMF_ERROR_NONE);
+ break;
+
+ case EMF_EVENT_DOWNLOAD_BODY:
+ em_core_execute_event_callback(EMF_ACTION_DOWNLOAD_BODY, 0, 0, EMF_DOWNLOAD_WAITING, account_id, mail_id, queue_idx, EMF_ERROR_NONE);
+ break;
+
+#ifdef __FEATURE_SYNC_CLIENT_TO_SERVER__
+ case EMF_EVENT_SYNC_MAIL_FLAG_TO_SERVER:
+ em_core_execute_event_callback(EMF_ACTION_SYNC_MAIL_FLAG_TO_SERVER, 0, 0, EMF_SYNC_WAITING, account_id, mail_id, queue_idx, EMF_ERROR_NONE);
+ break;
+#endif
+
+ case EMF_EVENT_DOWNLOAD_ATTACHMENT:
+ em_core_execute_event_callback(EMF_ACTION_DOWNLOAD_ATTACHMENT, 0, 0, EMF_DOWNLOAD_WAITING, account_id, mail_id, queue_idx, EMF_ERROR_NONE);
+ break;
+
+ case EMF_EVENT_DELETE_MAIL:
+ case EMF_EVENT_DELETE_MAIL_ALL:
+ em_core_execute_event_callback(EMF_ACTION_DELETE_MAIL, 0, 0, EMF_DELETE_WAITING, account_id, 0, queue_idx, EMF_ERROR_NONE);
+ break;
+
+ case EMF_EVENT_VALIDATE_ACCOUNT:
+ em_core_execute_event_callback(EMF_ACTION_VALIDATE_ACCOUNT, 0, 0, EMF_VALIDATE_ACCOUNT_WAITING, account_id, 0, queue_idx, EMF_ERROR_NONE);
+ break;
+
+ case EMF_EVENT_VALIDATE_AND_CREATE_ACCOUNT:
+ em_core_execute_event_callback(EMF_ACTION_VALIDATE_AND_CREATE_ACCOUNT, 0, 0, EMF_VALIDATE_ACCOUNT_WAITING, account_id, 0, queue_idx, EMF_ERROR_NONE);
+ break;
+
+ case EMF_EVENT_MOVE_MAIL:
+ em_core_execute_event_callback(EMF_ACTION_MOVE_MAIL, 0, 0, EMF_LIST_WAITING, account_id, 0, queue_idx, EMF_ERROR_NONE);
+ break;
+
+ case EMF_EVENT_CREATE_MAILBOX:
+ em_core_execute_event_callback(EMF_ACTION_CREATE_MAILBOX, 0, 0, EMF_LIST_WAITING, account_id, 0, queue_idx, EMF_ERROR_NONE);
+ break;
+
+ case EMF_EVENT_VALIDATE_AND_UPDATE_ACCOUNT:
+ em_core_execute_event_callback(EMF_ACTION_VALIDATE_AND_UPDATE_ACCOUNT, 0, 0, EMF_VALIDATE_ACCOUNT_WAITING, account_id, 0, queue_idx, EMF_ERROR_NONE);
+ break;
+
+ case EMF_EVENT_UPDATE_MAIL_OLD:
+ case EMF_EVENT_UPDATE_MAIL:
+ break;
+
+ case EMF_EVENT_SET_MAIL_SLOT_SIZE:
+ em_core_execute_event_callback(EMF_ACTION_SET_MAIL_SLOT_SIZE, 0, 0, EMF_SET_SLOT_SIZE_WAITING, account_id, 0, queue_idx, EMF_ERROR_NONE);
+ break;
+ default:
+ break;
+ }
+ EM_DEBUG_FUNC_END();
+}
+
+static void fail_status_notify(emf_event_t *event_data, int error)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int account_id, mail_id;
+
+ if(!event_data) {
+ EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
+ return;
+ }
+ account_id = event_data->account_id;
+ mail_id = event_data->event_param_data_4;
+
+ EM_DEBUG_LOG("account_id[%d], mail_id[%d], error[%d]", account_id, mail_id, error);
+
+ switch (event_data->type) {
+ case EMF_EVENT_SEND_MAIL:
+ /* case EMF_EVENT_SEND_MAIL_SAVED: */
+ /* em_core_execute_event_callback(EMF_ACTION_SEND_MAIL, 0, 0, EMF_SEND_FAIL, account_id, mail_id, -1, error); */
+ em_core_show_popup(mail_id, EMF_ACTION_SEND_MAIL, error);
+ break;
+
+ case EMF_EVENT_SYNC_HEADER:
+ em_core_execute_event_callback(EMF_ACTION_SYNC_HEADER, 0, 0, EMF_LIST_FAIL, account_id, 0, -1, error);
+ em_core_show_popup(account_id, EMF_ACTION_SYNC_HEADER, error);
+ break;
+
+ case EMF_EVENT_DOWNLOAD_BODY:
+ em_core_execute_event_callback(EMF_ACTION_DOWNLOAD_BODY, 0, 0, EMF_DOWNLOAD_FAIL, account_id, mail_id, -1, error);
+ em_core_show_popup(account_id, EMF_ACTION_DOWNLOAD_BODY, error);
+ break;
+
+ case EMF_EVENT_DOWNLOAD_ATTACHMENT:
+ em_core_execute_event_callback(EMF_ACTION_DOWNLOAD_ATTACHMENT, 0, 0, EMF_DOWNLOAD_FAIL, account_id, mail_id, -1, error);
+ em_core_show_popup(account_id, EMF_ACTION_DOWNLOAD_ATTACHMENT, error);
+ break;
+
+ case EMF_EVENT_DELETE_MAIL:
+ case EMF_EVENT_DELETE_MAIL_ALL:
+ em_core_execute_event_callback(EMF_ACTION_DELETE_MAIL, 0, 0, EMF_DELETE_FAIL, account_id, 0, -1, error);
+ em_core_show_popup(account_id, EMF_ACTION_DELETE_MAIL, error);
+ break;
+
+ case EMF_EVENT_VALIDATE_ACCOUNT:
+ em_core_execute_event_callback(EMF_ACTION_VALIDATE_ACCOUNT, 0, 0, EMF_VALIDATE_ACCOUNT_FAIL, account_id, 0, -1, error);
+ em_core_show_popup(account_id, EMF_ACTION_VALIDATE_ACCOUNT, error);
+ break;
+
+ case EMF_EVENT_VALIDATE_AND_CREATE_ACCOUNT:
+ em_core_execute_event_callback(EMF_ACTION_VALIDATE_AND_CREATE_ACCOUNT, 0, 0, EMF_VALIDATE_ACCOUNT_FAIL, account_id, 0, -1, error);
+ em_core_show_popup(account_id, EMF_ACTION_VALIDATE_AND_CREATE_ACCOUNT, error);
+ break;
+
+ case EMF_EVENT_CREATE_MAILBOX:
+ em_core_execute_event_callback(EMF_ACTION_CREATE_MAILBOX, 0, 0, EMF_LIST_FAIL, account_id, 0, -1, error);
+ em_core_show_popup(account_id, EMF_ACTION_CREATE_MAILBOX, error);
+ break;
+ case EMF_EVENT_DELETE_MAILBOX:
+ em_core_execute_event_callback(EMF_ACTION_DELETE_MAILBOX, 0, 0, EMF_LIST_FAIL, account_id, 0, -1, error);
+ em_core_show_popup(account_id, EMF_ACTION_DELETE_MAILBOX, error);
+ break;
+
+ case EMF_EVENT_VALIDATE_AND_UPDATE_ACCOUNT:
+ em_core_execute_event_callback(EMF_ACTION_VALIDATE_AND_UPDATE_ACCOUNT, 0, 0, EMF_VALIDATE_ACCOUNT_FAIL, account_id, 0, -1, error);
+ em_core_show_popup(account_id, EMF_ACTION_VALIDATE_AND_UPDATE_ACCOUNT, error);
+ break;
+
+ case EMF_EVENT_SET_MAIL_SLOT_SIZE:
+ em_core_execute_event_callback(EMF_ACTION_SET_MAIL_SLOT_SIZE, 0, 0, EMF_SET_SLOT_SIZE_FAIL, account_id, 0, -1, EMF_ERROR_NONE);
+ break;
+
+ case EMF_EVENT_UPDATE_MAIL_OLD:
+ case EMF_EVENT_UPDATE_MAIL:
+ break;
+
+ default:
+ break;
+ }
+ EM_DEBUG_FUNC_END();
+}
+
+
+static void em_core_initialize_event_callback_table()
+{
+ ENTER_RECURSIVE_CRITICAL_SECTION(_event_callback_table_lock);
+
+ int i;
+
+ for (i = 0; i < EMF_ACTION_NUM; i++)
+ _event_callback_table[i] = NULL;
+
+ LEAVE_RECURSIVE_CRITICAL_SECTION(_event_callback_table_lock);
+}
+
+int em_core_register_event_callback(emf_action_t action, emf_event_callback callback, void *event_data)
+{
+ EM_DEBUG_FUNC_BEGIN("action[%d], callback[%p], event_data[%p]", action, callback, event_data);
+
+ if (callback == NULL)
+ return false;
+
+ int ret = false;
+
+ ENTER_RECURSIVE_CRITICAL_SECTION(_event_callback_table_lock);
+
+ EVENT_CALLBACK_LIST *node = _event_callback_table[action];
+
+ while (node != NULL) {
+ if (node->callback == callback && node->event_data == event_data) /* already registered */
+ goto EXIT;
+
+ node = node->next;
+ }
+
+ /* not found, so keep going */
+
+ node = malloc(sizeof(EVENT_CALLBACK_LIST));
+
+ if (node == NULL) /* not enough memory */
+ goto EXIT;
+
+ node->callback = callback;
+ node->event_data = event_data;
+ node->next = _event_callback_table[action];
+
+ _event_callback_table[action] = node;
+
+ ret = true;
+
+EXIT :
+ LEAVE_RECURSIVE_CRITICAL_SECTION(_event_callback_table_lock);
+ EM_DEBUG_FUNC_END();
+ return ret;
+}
+
+int em_core_unregister_event_callback(emf_action_t action, emf_event_callback callback)
+{
+ EM_DEBUG_FUNC_BEGIN("action[%d], callback[%p]", action, callback);
+
+ if (callback == NULL)
+ return false;
+
+ int ret = false;
+
+ ENTER_RECURSIVE_CRITICAL_SECTION(_event_callback_table_lock);
+
+ EVENT_CALLBACK_LIST *prev = NULL;
+ EVENT_CALLBACK_LIST *node = _event_callback_table[action];
+
+ while (node != NULL) {
+ if (node->callback == callback) {
+ if (prev != NULL)
+ prev->next = node->next;
+ else
+ _event_callback_table[action] = node->next;
+
+ free(node);
+
+ ret = true;
+ break;
+ }
+
+ prev = node;
+ node = node->next;
+ }
+
+ LEAVE_RECURSIVE_CRITICAL_SECTION(_event_callback_table_lock);
+ EM_DEBUG_FUNC_END();
+ return ret;
+}
+
+void em_core_execute_event_callback(emf_action_t action, int total, int done, int status, int account_id, int mail_id, int handle, int error)
+{
+ EM_DEBUG_FUNC_BEGIN("action[%d], total[%d], done[%d], status[%d], account_id[%d], mail_id[%d], handle[%d], error[%d]", action, total, done, status, account_id, mail_id, handle, error);
+
+ int lock_needed = 0;
+ lock_needed = is_gdk_lock_needed();
+
+ if (lock_needed) {
+ /* Todo : g_thread_yield */
+ }
+
+ ENTER_RECURSIVE_CRITICAL_SECTION(_event_callback_table_lock);
+
+ EVENT_CALLBACK_LIST *node = _event_callback_table[action];
+
+ while (node != NULL) {
+ if (node->callback != NULL)
+ node->callback(total, done, status, account_id, mail_id, (handle == -1 ? em_core_get_active_queue_idx() : handle), node->event_data, error);
+ node = node->next;
+ }
+
+ LEAVE_RECURSIVE_CRITICAL_SECTION(_event_callback_table_lock);
+
+ if (lock_needed) {
+ }
+ EM_DEBUG_FUNC_END();
+}
+
+/* insert a event to event queue */
+EXPORT_API int em_core_insert_event(emf_event_t *event_data, int *handle, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("event_data[%p], handle[%p], err_code[%p]", event_data, handle, err_code);
+
+ if (!event_data) {
+ EM_DEBUG_EXCEPTION("Invalid Parameter");
+ if (err_code != NULL)
+ *err_code = EMF_ERROR_INVALID_PARAM;
+ return false;
+ }
+
+ if (!g_srv_thread) {
+ EM_DEBUG_EXCEPTION("email-service is not ready");
+ if (err_code != NULL)
+ *err_code = EMF_ERROR_LOAD_ENGINE_FAILURE;
+ return false;
+ }
+
+ int ret = true;
+ int error = EMF_ERROR_NONE;
+
+ ENTER_RECURSIVE_CRITICAL_SECTION(_event_queue_lock);
+
+ if (!g_event_que[g_event_que_idx].type) { /* if current buffer has not event, insert event data to current buffer */
+ EM_DEBUG_LOG("Current buffer has not a event. [%d]", g_event_que_idx);
+ memcpy(g_event_que+g_event_que_idx, event_data, sizeof(emf_event_t));
+ g_event_que[g_event_que_idx].status = EMF_EVENT_STATUS_WAIT;
+ waiting_status_notify(event_data, g_event_que_idx);
+ if (handle)
+ *handle = g_event_que_idx;
+ }
+ else { /* if current buffer has event, find the empty buffer */
+ EM_DEBUG_LOG("Current buffer has a event. [%d]", g_event_que_idx);
+ int i, j = g_event_que_idx + 1;
+
+ for (i = 1; i < EVENT_QUEUE_MAX; i++, j++) {
+ if (j >= EVENT_QUEUE_MAX)
+ j = 1;
+
+ if (!g_event_que[j].type)
+ break;
+ }
+
+ if (i < EVENT_QUEUE_MAX) {
+ EM_DEBUG_LOG("I found available buffer. [%d]", g_event_que + j);
+ memcpy(g_event_que+j, event_data, sizeof(emf_event_t));
+ g_event_que[j].status = EMF_EVENT_STATUS_WAIT;
+ waiting_status_notify(event_data, j);
+
+ if (handle)
+ *handle = j;
+ }
+ else {
+ EM_DEBUG_EXCEPTION("event que is full...");
+ error = EMF_ERROR_EVENT_QUEUE_FULL;
+ ret = false;
+ }
+ }
+
+ LEAVE_RECURSIVE_CRITICAL_SECTION(_event_queue_lock);
+
+ if (ret == true) {
+ event_data->event_param_data_1 = NULL; /* MUST BE - to prevent double-free */
+
+ switch (event_data->type) {
+ case EMF_EVENT_SEND_MAIL:
+ case EMF_EVENT_SEND_MAIL_SAVED:
+ _sending_busy_ref();
+ break;
+
+ case EMF_EVENT_SYNC_HEADER:
+ case EMF_EVENT_SAVE_MAIL:
+ case EMF_EVENT_DOWNLOAD_BODY:
+ case EMF_EVENT_DOWNLOAD_ATTACHMENT:
+ case EMF_EVENT_SYNC_MAIL_FLAG_TO_SERVER:
+ case EMF_EVENT_SYNC_FLAGS_FIELD_TO_SERVER:
+ case EMF_EVENT_ISSUE_IDLE:
+ case EMF_EVENT_SYNC_IMAP_MAILBOX:
+ case EMF_EVENT_VALIDATE_ACCOUNT:
+ case EMF_EVENT_VALIDATE_AND_CREATE_ACCOUNT:
+ case EMF_EVENT_MOVE_MAIL:
+ case EMF_EVENT_DELETE_MAIL:
+ case EMF_EVENT_DELETE_MAIL_ALL:
+ case EMF_EVENT_SYNC_HEADER_OMA:
+ case EMF_EVENT_CREATE_MAILBOX:
+ case EMF_EVENT_DELETE_MAILBOX:
+ case EMF_EVENT_VALIDATE_AND_UPDATE_ACCOUNT:
+ case EMF_EVENT_SET_MAIL_SLOT_SIZE:
+ case EMF_EVENT_UPDATE_MAIL_OLD:
+ case EMF_EVENT_UPDATE_MAIL:
+ _receiving_busy_ref();
+ break;
+ default:
+ break;
+ }
+
+ ENTER_CRITICAL_SECTION(_event_available_lock);
+ WAKE_CONDITION_VARIABLE(_event_available_signal);
+ LEAVE_CRITICAL_SECTION(_event_available_lock);
+ }
+
+#ifdef __FEATURE_PARTIAL_BODY_DOWNLOAD__
+ {
+ int is_local_activity_event_inserted = false;
+
+ if (false == em_core_partial_body_thd_local_activity_sync(&is_local_activity_event_inserted, &error))
+ EM_DEBUG_EXCEPTION("em_core_partial_body_thd_local_activity_sync failed [%d]", error);
+ else {
+ if (true == is_local_activity_event_inserted)
+ em_core_pb_thd_set_local_activity_continue(false);
+ }
+ }
+#endif
+
+ if (err_code != NULL)
+ *err_code = error;
+
+ EM_DEBUG_LOG("Finish with [%d]", ret);
+ return ret;
+}
+
+/* get a event from event_data queue */
+static int em_core_retrieve_event(emf_event_t *event_data, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("event_data[%p], err_code[%p]", event_data, err_code);
+
+ int ret = false;
+ int error = EMF_ERROR_NONE;
+
+ ENTER_RECURSIVE_CRITICAL_SECTION(_event_queue_lock);
+
+ /* get a event_data if this queue is not empty */
+ if (g_event_que[g_event_que_idx].type) {
+ memcpy(event_data, g_event_que+g_event_que_idx, sizeof(emf_event_t));
+
+ if (event_data->status != EMF_EVENT_STATUS_WAIT) { /* EMF_EVENT_STATUS_CANCELED */
+ memset(g_event_que+g_event_que_idx, 0x00, sizeof(emf_event_t));
+ g_active_que = 0;
+ }
+ else {
+ EM_DEBUG_LINE;
+ g_event_que[g_event_que_idx].status = EMF_EVENT_STATUS_STARTED;
+ g_active_que = g_event_que_idx;
+ ret = true;
+ }
+
+ if (++g_event_que_idx >= EVENT_QUEUE_MAX)
+ g_event_que_idx = 1;
+
+ EM_DEBUG_LOG("g_event_que[%d].type [%d]", g_active_que, g_event_que[g_active_que].type);
+ }
+ else {
+ g_active_que = 0;
+ error = EMF_ERROR_EVENT_QUEUE_EMPTY;
+ }
+
+ LEAVE_RECURSIVE_CRITICAL_SECTION(_event_queue_lock);
+
+ if (err_code != NULL)
+ *err_code = error;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+/* check that event_data loop is continuous */
+static int em_core_event_loop_continue()
+{
+ return g_event_loop;
+}
+
+
+
+EXPORT_API int em_core_insert_send_event(emf_event_t *event_data, int *handle, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("event_data[%p], handle[%p], err_code[%p]", event_data, handle, err_code);
+
+ if (!event_data) {
+ EM_DEBUG_EXCEPTION("\t event_data[%p], handle[%p]", event_data, handle);
+
+ if (err_code != NULL)
+ *err_code = EMF_ERROR_INVALID_PARAM;
+ return false;
+ }
+
+ int ret = true;
+ int error = EMF_ERROR_NONE;
+
+ ENTER_RECURSIVE_CRITICAL_SECTION(_send_event_queue_lock);
+
+ if (!g_send_event_que[g_send_event_que_idx].type) {
+ /* if current buffer has not event_data, insert event_data data to current buffer */
+ EM_DEBUG_LOG("Current buffer has not a event_data. [%d]", g_send_event_que_idx);
+ memcpy(g_send_event_que+g_send_event_que_idx, event_data, sizeof(emf_event_t));
+
+ g_send_event_que[g_send_event_que_idx].status = EMF_EVENT_STATUS_WAIT;
+
+ if (handle)
+ *handle = g_send_event_que_idx;
+ }
+ else {
+ /* if current buffer has event_data, find the empty buffer */
+ EM_DEBUG_LOG("Current buffer has a event_data. [%d]", g_send_event_que_idx);
+ int i, j = g_send_event_que_idx + 1;
+
+ for (i = 1; i < EVENT_QUEUE_MAX; i++, j++) {
+ if (j >= EVENT_QUEUE_MAX)
+ j = 1;
+
+ if (!g_send_event_que[j].type)
+ break;
+ }
+
+ if (i < EVENT_QUEUE_MAX) {
+ EM_DEBUG_LOG("I found available buffer. [%d]", j);
+ memcpy(g_send_event_que+j, event_data, sizeof(emf_event_t));
+ g_send_event_que[j].status = EMF_EVENT_STATUS_WAIT;
+ if (handle) *handle = j;
+ }
+ else {
+ EM_DEBUG_EXCEPTION("event_data queue is full...");
+ error = EMF_ERROR_EVENT_QUEUE_FULL;
+ ret = false;
+ }
+ }
+
+ LEAVE_RECURSIVE_CRITICAL_SECTION(_send_event_queue_lock);
+
+ if (ret == true) {
+ ENTER_CRITICAL_SECTION(_send_event_available_lock);
+ WAKE_CONDITION_VARIABLE(_send_event_available_signal);
+ LEAVE_CRITICAL_SECTION(_send_event_available_lock);
+ }
+
+ if (handle)
+ EM_DEBUG_LOG("em_core_insert_send_event-handle[%d]", *handle);
+
+ if (err_code != NULL)
+ *err_code = error;
+
+ /* EM_DEBUG_FUNC_BEGIN(); */
+ return ret;
+}
+
+
+static int em_core_retrieve_send_event(emf_event_t *event_data, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ int ret = false;
+ int error = EMF_ERROR_NONE;
+
+ ENTER_RECURSIVE_CRITICAL_SECTION(_send_event_queue_lock);
+/* get a event_data if this queue is not empty */
+ if (g_send_event_que[g_send_event_que_idx].type) {
+ memcpy(event_data, g_send_event_que+g_send_event_que_idx, sizeof(emf_event_t));
+
+ if (event_data->status != EMF_EVENT_STATUS_WAIT) {
+ memset(g_send_event_que+g_send_event_que_idx, 0x00, sizeof(emf_event_t));
+ g_send_active_que = 0;
+ }
+ else {
+ g_send_event_que[g_send_event_que_idx].status = EMF_EVENT_STATUS_STARTED;
+ EM_DEBUG_LOG("g_send_event_que_idx[%d]", g_send_event_que_idx);
+ g_send_active_que = g_send_event_que_idx;
+
+ ret = true;
+ }
+
+ if (++g_send_event_que_idx >= EVENT_QUEUE_MAX)
+ g_send_event_que_idx = 1;
+
+ EM_DEBUG_LOG("\t g_send_event_que[%d].type = %d", g_send_active_que, g_send_event_que[g_send_active_que].type);
+ }
+ else {
+ EM_DEBUG_LOG("\t send event_data queue is empty...");
+ g_send_active_que = 0;
+ error = EMF_ERROR_EVENT_QUEUE_EMPTY;
+ }
+
+ LEAVE_RECURSIVE_CRITICAL_SECTION(_send_event_queue_lock);
+
+ if (err_code != NULL)
+ *err_code = error;
+
+ return ret;
+}
+
+
+void*
+send_event_handler(void *arg)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int err = EMF_ERROR_NONE;
+ emf_event_t event_data;
+ emf_session_t *session = NULL;
+
+ if (!em_storage_open(&err)) {
+ EM_DEBUG_EXCEPTION("\t em_storage_open falied - %d", err);
+ return NULL;
+ }
+
+ while (g_send_event_loop) {
+ if (!em_core_get_empty_session(&session))
+ EM_DEBUG_EXCEPTION("\t SEND THREAD em_core_get_empty_session failed...");
+
+ if (!em_core_retrieve_send_event(&event_data, NULL)) {
+ EM_DEBUG_LOG(">>>> waiting for send event_data>>>>>>>>>");
+#ifdef __LOCAL_ACTIVITY__
+ if (send_thread_run && g_save_local_activity_run) {
+ emf_mail_account_tbl_t *account_list = NULL;
+ int count = 0, i;
+ if (!em_storage_get_account_list(&count, &account_list, true, true, &err)) {
+ EM_DEBUG_LOG("\t em_storage_get_account_list failed - %d", err);
+ }
+ else {
+ for (i = 0; i < count; i++) {
+ if (em_core_save_local_activity_sync(account_list[i].account_id, &err)) {
+ EM_DEBUG_LOG("Found local activity...!");
+ EM_DEBUG_LOG("Resetting g_save_local_activity_run ");
+ g_save_local_activity_run = 0;
+ em_core_clear_session(session);
+ }
+ }
+
+ em_storage_free_account(&account_list, count, &err);
+
+ if (!g_save_local_activity_run) {
+ continue;
+ }
+ }
+ }
+#endif
+ send_thread_run = 0;
+
+ ENTER_CRITICAL_SECTION(_send_event_available_lock);
+ SLEEP_CONDITION_VARIABLE(_send_event_available_signal, _send_event_available_lock);
+ LEAVE_CRITICAL_SECTION(_send_event_available_lock);
+ }
+ else {
+ EM_DEBUG_LOG(">>>>>>>>>>>>>>Got SEND event_data>>>>>>>>>>>>>>>>");
+ send_thread_run = 1;
+ g_client_run = 1;
+ emf_option_t *option = NULL;
+
+ if (!em_core_check_network_status( &err)) {
+ EM_DEBUG_EXCEPTION("em_core_check_network_status failed [%d]", err);
+
+ if (event_data.type != EMF_EVENT_SAVE_MAIL) {
+ em_core_show_popup(event_data.event_param_data_4, EMF_ACTION_SEND_MAIL, err);
+ if (!em_storage_notify_network_event(NOTI_SEND_FAIL, event_data.account_id, NULL , event_data.event_param_data_4, err))
+ EM_DEBUG_EXCEPTION(" em_storage_notify_network_event [ NOTI_SEND_FAIL] Failed >>>> ");
+ }
+ goto FINISH_OFF;
+ }
+
+ switch (event_data.type) {
+
+ case EMF_EVENT_SAVE_MAIL:
+ em_storage_dimming_on_off(false, NULL);
+#ifdef __FEATURE_SYNC_CLIENT_TO_SERVER__
+ if (!em_core_mail_sync_from_client_to_server(event_data.account_id, event_data.event_param_data_4, &err))
+ EM_DEBUG_EXCEPTION("em_core_mail_sync_from_client_to_server failed - %d", err);
+#endif
+ em_storage_dimming_on_off(true, NULL);
+ break;
+
+ case EMF_EVENT_SEND_MAIL:
+ em_storage_dimming_on_off(false, NULL);
+ option = (emf_option_t *)event_data.event_param_data_1;
+
+ if (!em_core_mail_send(event_data.account_id, event_data.event_param_data_3, event_data.event_param_data_4, option, &err))
+ EM_DEBUG_EXCEPTION("em_core_mail_send failed [%d]", err);
+
+ if (option)
+ EM_SAFE_FREE(option->display_name_from);
+ em_storage_dimming_on_off(true, NULL);
+ break;
+
+ case EMF_EVENT_SEND_MAIL_SAVED: /* send mails to been saved in offline-mode */
+ em_storage_dimming_on_off(false, NULL);
+
+ emf_option_t *option = (emf_option_t *)event_data.event_param_data_1;
+
+ if (!em_core_mail_send_saved(event_data.account_id, event_data.event_param_data_3, option, &err))
+ EM_DEBUG_EXCEPTION("em_core_mail_send_saved failed - %d", err);
+
+ if (option)
+ EM_SAFE_FREE(option->display_name_from);
+
+ em_storage_dimming_on_off(true, NULL);
+ break;
+#ifdef __LOCAL_ACTIVITY__
+
+ case EMF_EVENT_LOCAL_ACTIVITY: {
+ em_storage_dimming_on_off(false, NULL);
+ emf_activity_tbl_t *local_activity = NULL;
+ int activity_id_count = 0;
+ int activity_chunk_count = 0;
+ int *activity_id_list = NULL;
+ int i = 0;
+
+ if (false == em_storage_get_activity_id_list(event_data.account_id, &activity_id_list, &activity_id_count, ACTIVITY_SAVEMAIL, ACTIVITY_DELETEMAIL_SEND, true, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_get_activity_id_list failed [%d]", err);
+ }
+ else {
+ for (i = 0; i < activity_id_count; ++i) {
+ if ((false == em_storage_get_activity(event_data.account_id, activity_id_list[i], &local_activity, &activity_chunk_count, true, &err)) || (NULL == local_activity) || (0 == activity_chunk_count)) {
+ EM_DEBUG_EXCEPTION(" em_storage_get_activity Failed [ %d] or local_activity is NULL [%p] or activity_chunk_count is 0[%d]", err, local_activity, activity_chunk_count);
+ }
+ else {
+ EM_DEBUG_LOG("Found local activity type - %d", local_activity[0].activity_type);
+ switch (local_activity[0].activity_type) {
+ case ACTIVITY_SAVEMAIL: {
+ if (!em_core_mail_sync_from_client_to_server(event_data.account_id, local_activity[0].mail_id, &err)) {
+ EM_DEBUG_EXCEPTION("em_core_mail_sync_from_client_to_server failed - %d ", err);
+ }
+ }
+ break;
+
+ case ACTIVITY_DELETEMAIL_SEND: /* New Activity Type Added for Race Condition and Crash Fix */ {
+ if (!em_core_mail_delete(local_activity[0].account_id,
+ &local_activity[0].mail_id,
+ EMF_DELETE_FOR_SEND_THREAD,
+ true,
+ EMF_DELETED_BY_COMMAND,
+ false,
+ &err)) {
+ EM_DEBUG_LOG("\t em_core_mail_delete failed - %d", err);
+ }
+ }
+ break;
+
+ default: {
+ EM_DEBUG_LOG(">>>> No such Local Activity Handled by this thread [ %d ] >>> ", local_activity[0].activity_type);
+ }
+ break;
+ }
+
+ em_storage_free_local_activity(&local_activity, activity_chunk_count, NULL);
+
+ if (g_save_local_activity_run == 1) {
+ EM_DEBUG_LOG(" Network event_data found.. Local sync Stopped..! ");
+ break;
+ }
+ }
+
+ }
+ if (false == em_storage_free_activity_id_list(activity_id_list, &err)) {
+ EM_DEBUG_LOG("em_storage_free_activity_id_list failed");
+ }
+ }
+
+ em_storage_dimming_on_off(true, NULL);
+ }
+ break;
+#endif /* __LOCAL_ACTIVITY__ */
+ default:
+ EM_DEBUG_LOG("Others not supported by Send Thread..! ");
+ break;
+
+ }
+
+ ENTER_RECURSIVE_CRITICAL_SECTION(_send_event_queue_lock);
+
+ memset(g_send_event_que+g_send_active_que, 0x00, sizeof(emf_event_t));
+
+ LEAVE_RECURSIVE_CRITICAL_SECTION(_send_event_queue_lock);
+
+FINISH_OFF:
+ ;
+ }
+ em_core_clear_session(session);
+ }
+
+ if (!em_storage_close(&err))
+ EM_DEBUG_EXCEPTION("em_storage_close falied [%d]", err);
+
+ EM_DEBUG_FUNC_END();
+ return NULL;
+}
+
+
+int event_handler_EMF_EVENT_SYNC_HEADER(int input_account_id, char *input_mailbox_name, int handle_to_be_published, int *error)
+{
+ EM_DEBUG_FUNC_BEGIN("input_account_id [%d], input_mailbox_name [%p], handle_to_be_published [%d], error[%p]", input_account_id, input_mailbox_name, handle_to_be_published, error);
+
+ int err = EMF_ERROR_NONE, sync_type = 0, ret = false;
+ int mailbox_count = 0, account_count = 0;
+ int counter, account_index;
+ int unread = 0, total_unread = 0;
+ em_core_uid_list *uid_list = NULL;
+ emf_mail_account_tbl_t *account_tbl_array = NULL;
+ emf_mailbox_tbl_t *mailbox_tbl_target = NULL, *mailbox_tbl_spam = NULL, *mailbox_tbl_list = NULL;
+#ifndef __FEATURE_KEEP_CONNECTION__
+ MAILSTREAM *stream = NULL;
+#endif
+
+ if (input_mailbox_name == NULL)
+ sync_type = EMF_SYNC_ALL_MAILBOX;
+ else {
+ if (!em_storage_get_mailbox_by_name(input_account_id, -1, input_mailbox_name, &mailbox_tbl_target, true, &err) || !mailbox_tbl_target) {
+ EM_DEBUG_EXCEPTION("em_storage_get_mailbox_by_name failed [%d]", err);
+ goto FINISH_OFF;
+ }
+ }
+
+ if (!em_storage_notify_network_event(NOTI_DOWNLOAD_START, input_account_id, input_mailbox_name, handle_to_be_published, 0))
+ EM_DEBUG_EXCEPTION(" em_storage_notify_network_event [ NOTI_DOWNLOAD_START] Failed >>>> ");
+
+ if (!em_core_check_network_status(&err)) {
+ EM_DEBUG_EXCEPTION("em_core_check_network_status failed [%d]", err);
+
+ if (!em_storage_notify_network_event(NOTI_DOWNLOAD_FAIL, input_account_id, input_mailbox_name, handle_to_be_published, err))
+ EM_DEBUG_EXCEPTION(" em_storage_notify_network_event [ NOTI_DOWNLOAD_FAIL] Failed >>>> ");
+ }
+ else {
+ if (sync_type != EMF_SYNC_ALL_MAILBOX) { /* Sync only particular mailbox */
+
+ if (!em_storage_update_sync_status_of_account(input_account_id, SET_TYPE_SET, SYNC_STATUS_SYNCING, true, &err))
+ EM_DEBUG_EXCEPTION("em_storage_update_sync_status_of_account failed [%d]", err);
+
+ if (!em_storage_get_mailbox_by_mailbox_type(input_account_id, EMF_MAILBOX_TYPE_SPAMBOX, &mailbox_tbl_spam, false, &err)) {
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ EM_DEBUG_LOG("em_storage_get_mailbox_by_mailbox_type failed [%d]", err);
+ }
+
+ if (!em_core_mailbox_sync_header(mailbox_tbl_target, mailbox_tbl_spam, NULL, &uid_list, &unread, &err)) {
+ EM_DEBUG_EXCEPTION("em_core_mailbox_sync_header failed [%d]", err);
+ if (!em_storage_notify_network_event(NOTI_DOWNLOAD_FAIL, mailbox_tbl_target->account_id, mailbox_tbl_target->mailbox_name, handle_to_be_published, err))
+ EM_DEBUG_EXCEPTION(" em_storage_notify_network_event [NOTI_DOWNLOAD_FAIL] Failed >>>> ");
+ }
+ else {
+ EM_DEBUG_LOG("em_core_mailbox_sync_header succeeded [%d]", err);
+ if (!em_storage_notify_network_event(NOTI_DOWNLOAD_FINISH, mailbox_tbl_target->account_id, mailbox_tbl_target->mailbox_name, handle_to_be_published, 0))
+ EM_DEBUG_EXCEPTION("em_storage_notify_network_event [NOTI_DOWNLOAD_FINISH] Failed >>>> ");
+ }
+
+ total_unread = total_unread + unread;
+
+ if (total_unread > 0 && !em_storage_update_sync_status_of_account(input_account_id, SET_TYPE_UNION, SYNC_STATUS_HAVE_NEW_MAILS, true, &err))
+ EM_DEBUG_EXCEPTION("em_storage_update_sync_status_of_account failed [%d]", err);
+
+ if (!em_core_finalize_sync(input_account_id, &err))
+ EM_DEBUG_EXCEPTION("em_core_finalize_sync failed [%d]", err);
+ }
+ else /* All Foder */ {
+ EM_DEBUG_LOG(">>>> SYNC ALL MAILBOX ");
+ /* Sync of all mailbox */
+
+ if (input_account_id == ALL_ACCOUNT) {
+ if (!em_storage_update_sync_status_of_account(ALL_ACCOUNT, SET_TYPE_SET, SYNC_STATUS_SYNCING, true, &err))
+ EM_DEBUG_EXCEPTION("em_storage_update_sync_status_of_account failed [%d]", err);
+
+ if (!em_storage_get_account_list(&account_count, &account_tbl_array , true, false, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_get_account_list failed [ %d ] ", err);
+ em_storage_get_emf_error_from_em_storage_error(err);
+ if (!em_storage_notify_network_event(NOTI_DOWNLOAD_FAIL, input_account_id, NULL, handle_to_be_published, err))
+ EM_DEBUG_EXCEPTION(" em_storage_notify_network_event [ NOTI_DOWNLOAD_FAIL] Failed >>>> ");
+ goto FINISH_OFF;
+ }
+ }
+ else {
+ EM_DEBUG_LOG("Sync all mailbox of an account[%d].", input_account_id);
+
+ if (!em_storage_update_sync_status_of_account(input_account_id, SET_TYPE_SET, SYNC_STATUS_SYNCING, true, &err))
+ EM_DEBUG_EXCEPTION("em_storage_update_sync_status_of_account failed [%d]", err);
+
+ if (!em_storage_get_account_by_id(input_account_id, EMF_ACC_GET_OPT_DEFAULT, &account_tbl_array, true, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_get_account_by_id failed [ %d ] ", err);
+ em_storage_get_emf_error_from_em_storage_error(err);
+ if (!em_storage_notify_network_event(NOTI_DOWNLOAD_FAIL, input_account_id, input_mailbox_name, handle_to_be_published, err))
+ EM_DEBUG_EXCEPTION(" em_storage_notify_network_event [ NOTI_DOWNLOAD_FAIL] Failed >>>> ");
+ goto FINISH_OFF;
+ }
+ account_count = 1;
+ }
+
+ for (account_index = 0 ; account_index < account_count; account_index++) {
+ if (account_tbl_array[account_index].receiving_server_type == EMF_SERVER_TYPE_ACTIVE_SYNC) {
+ EM_DEBUG_LOG("account[%d] is for ActiveSync. Skip ", account_index);
+ continue;
+ }
+
+
+ if (!em_storage_get_mailbox(account_tbl_array[account_index].account_id, 0, EMAIL_MAILBOX_SORT_BY_TYPE_ASC, &mailbox_count, &mailbox_tbl_list, true, &err) || mailbox_count <= 0) {
+ EM_DEBUG_EXCEPTION("em_storage_get_mailbox failed [%d]", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ if (!em_storage_notify_network_event(NOTI_DOWNLOAD_FAIL, account_tbl_array[account_index].account_id, input_mailbox_name, handle_to_be_published, err))
+ EM_DEBUG_EXCEPTION(" em_storage_notify_network_event [ NOTI_DOWNLOAD_FAIL] Failed >>>> ");
+ goto FINISH_OFF;
+ }
+
+ EM_DEBUG_LOG("em_core_mailbox_get_list_to_be_sync returns [%d] mailboxes", mailbox_count);
+
+ if(mailbox_tbl_spam) {
+ if (!em_storage_free_mailbox(&mailbox_tbl_spam, 1, &err)) {
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ EM_DEBUG_EXCEPTION("em_storage_free_mailbox failed [%d]", err);
+ }
+ mailbox_tbl_spam = NULL;
+ }
+
+ if (!em_storage_get_mailbox_by_mailbox_type(account_tbl_array[account_index].account_id, EMF_MAILBOX_TYPE_SPAMBOX, &mailbox_tbl_spam, false, &err)) {
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ EM_DEBUG_LOG("em_storage_get_mailbox_by_mailbox_type failed [%d]", err);
+ }
+
+ if (mailbox_count > 0) {
+#ifndef __FEATURE_KEEP_CONNECTION__
+ if (account_tbl_array[account_index].receiving_server_type == EMF_SERVER_TYPE_IMAP4) {
+ if (!em_core_mailbox_open(account_tbl_array[account_index].account_id, mailbox_tbl_list[0].mailbox_name, (void **)&stream, &err)) {
+ EM_DEBUG_EXCEPTION("em_core_mailbox_open failed [%d]", err);
+ if (err == EMF_ERROR_LOGIN_FAILURE)
+ EM_DEBUG_EXCEPTION("EMF_ERROR_LOGIN_FAILURE ");
+ /* continue; */
+ if (!em_storage_notify_network_event(NOTI_DOWNLOAD_FAIL, account_tbl_array[account_index].account_id, mailbox_tbl_list[0].mailbox_name, handle_to_be_published, err))
+ EM_DEBUG_EXCEPTION(" em_storage_notify_network_event [NOTI_DOWNLOAD_FAIL] Failed >>>> ");
+ goto FINISH_OFF;
+ }
+ EM_DEBUG_LOG("em_core_mailbox_open returns [%d] : ", err);
+ }
+ else
+ stream = NULL;
+#endif
+ }
+
+ for (counter = 0; counter < mailbox_count; counter++) {
+ if ( mailbox_tbl_list[counter].mailbox_type == EMF_MAILBOX_TYPE_ALL_EMAILS
+ || mailbox_tbl_list[counter].mailbox_type == EMF_MAILBOX_TYPE_TRASH
+ /*|| mailbox_tbl_list[counter].mailbox_type == EMF_MAILBOX_TYPE_SPAMBOX */)
+ EM_DEBUG_LOG("Skipped for all emails or trash");
+ else if ((mailbox_tbl_list[counter].sync_with_server_yn)) {
+ EM_DEBUG_LOG("..........syncing %s mailbox......", mailbox_tbl_list[counter].mailbox_name);
+#ifdef __FEATURE_KEEP_CONNECTION__
+ if (!em_core_mailbox_sync_header((mailbox_tbl_list + counter) , mailbox_tbl_spam, NULL, &uid_list, &unread, &err)) {
+#else /* __FEATURE_KEEP_CONNECTION__ */
+ if (!em_core_mailbox_sync_header((mailbox_tbl_list + counter) , mailbox_tbl_spam, (void *)stream, &uid_list, &unread, &err)) {
+#endif /* __FEATURE_KEEP_CONNECTION__ */
+ EM_DEBUG_EXCEPTION("em_core_mailbox_sync_header for %s failed [%d]", mailbox_tbl_list[counter].mailbox_name, err);
+
+#ifndef __FEATURE_KEEP_CONNECTION__
+ if (err == EMF_ERROR_CONNECTION_BROKEN || err == EMF_ERROR_NO_SUCH_HOST || err == EMF_ERROR_SOCKET_FAILURE)
+ stream = NULL; /* Don't retry to connect for broken connection. It might cause crash. */
+#endif /* __FEATURE_KEEP_CONNECTION__ */
+ if (!em_storage_notify_network_event(NOTI_DOWNLOAD_FAIL, account_tbl_array[account_index].account_id, mailbox_tbl_list[counter].mailbox_name, handle_to_be_published, err))
+ EM_DEBUG_EXCEPTION(" em_storage_notify_network_event [ NOTI_DOWNLOAD_FAIL] Failed >>>> ");
+
+ goto FINISH_OFF;
+ }
+ }
+ total_unread += unread;
+ }
+
+ EM_DEBUG_LOG("Sync for account_id(%d) is completed....!", account_tbl_array[account_index].account_id);
+ if (!em_storage_notify_network_event(NOTI_DOWNLOAD_FINISH, account_tbl_array[account_index].account_id, NULL, handle_to_be_published, 0))
+ EM_DEBUG_EXCEPTION(" em_storage_notify_network_event [ NOTI_DOWNLOAD_FINISH] Failed >>>> ");
+
+ if (total_unread > 0 && !em_storage_update_sync_status_of_account(account_tbl_array[account_index].account_id, SET_TYPE_UNION, SYNC_STATUS_HAVE_NEW_MAILS, true, &err))
+ EM_DEBUG_EXCEPTION("em_storage_update_sync_status_of_account failed [%d]", err);
+
+ if (!em_core_finalize_sync(account_tbl_array[account_index].account_id, &err))
+ EM_DEBUG_EXCEPTION("em_core_finalize_sync failed [%d]", err);
+#ifndef __FEATURE_KEEP_CONNECTION__
+ if (stream) {
+ em_core_mailbox_close(0, stream);
+ stream = NULL;
+ }
+#endif
+ if (mailbox_tbl_list) {
+ em_storage_free_mailbox(&mailbox_tbl_list, mailbox_count, NULL);
+ mailbox_tbl_list = NULL;
+ mailbox_count = 0;
+ }
+ }
+ }
+
+ ret = true;
+
+FINISH_OFF:
+
+ if(ret == false) {
+ }
+
+#ifndef __FEATURE_KEEP_CONNECTION__
+ if (stream)
+ em_core_mailbox_close(0, stream);
+#endif
+ if(mailbox_tbl_target)
+ em_storage_free_mailbox(&mailbox_tbl_target, 1, NULL);
+
+ if (mailbox_tbl_list)
+ em_storage_free_mailbox(&mailbox_tbl_list, mailbox_count, NULL);
+
+ if (account_tbl_array)
+ em_storage_free_account(&account_tbl_array, account_count, NULL);
+ }
+
+ EM_DEBUG_FUNC_END();
+ return ret;
+}
+
+int event_handler_EMF_EVENT_VALIDATE_AND_CREATE_ACCOUNT(emf_account_t *account, int handle_to_be_published, int *error)
+{
+ EM_DEBUG_FUNC_BEGIN("account [%p]", account);
+ int err, ret = false;
+
+ if(!account) {
+ EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ EM_DEBUG_LOG("receiving_server_addr : %s", account->receiving_server_addr);
+
+ if (!em_core_check_network_status(&err)) {
+ EM_DEBUG_EXCEPTION("em_core_check_network_status failed [%d]", err);
+
+ if (!em_storage_notify_network_event(NOTI_VALIDATE_AND_CREATE_ACCOUNT_FAIL, account->account_id, NULL, handle_to_be_published, err))
+ EM_DEBUG_EXCEPTION(" em_storage_notify_network_event [ NOTI_VALIDATE_ACCOUNT_FAIL] Failed >>>> ");
+ goto FINISH_OFF;
+ }
+ else {
+ EM_DEBUG_LOG("receiving_server_addr : %s", account->receiving_server_addr);
+
+ if (!em_core_account_validate_with_account_info(account, &err)) {
+ EM_DEBUG_EXCEPTION("em_core_account_validate_with_account_info failed err : %d", err);
+ if (err == EMF_ERROR_CANCELLED) {
+ EM_DEBUG_EXCEPTION(" notify : NOTI_VALIDATE_AND_CREATE_ACCOUNT_CANCEL ");
+ if (!em_storage_notify_network_event(NOTI_VALIDATE_AND_CREATE_ACCOUNT_CANCEL, account->account_id, NULL, handle_to_be_published, err))
+ EM_DEBUG_EXCEPTION(" em_storage_notify_network_event [ NOTI_VALIDATE_AND_CREATE_ACCOUNT_CANCEL] Failed");
+ goto FINISH_OFF;
+ }
+ else
+ goto FINISH_OFF;
+ }
+ else {
+ if (em_core_account_create(account, &err) == false) {
+ EM_DEBUG_EXCEPTION(" emf_account_create failed - %d", err);
+ goto FINISH_OFF;
+ }
+
+ em_core_refresh_account_reference();
+
+ if ((EMF_SERVER_TYPE_IMAP4 == account->receiving_server_type)) {
+ if (!em_core_mailbox_sync_mailbox_list(account->account_id, "", &err)) {
+ EM_DEBUG_EXCEPTION("em_core_mailbox_get_list_to_be_sync falied [%d]", err);
+ /* delete account whose mailbox couldn't be obtained from server */
+ em_core_account_delete(account->account_id, NULL);
+ goto FINISH_OFF;
+ }
+
+ }
+
+ EM_DEBUG_EXCEPTION("validating and creating an account are succeeded for account id [%d] err [%d]", account->account_id, err);
+ if (!em_storage_notify_network_event(NOTI_VALIDATE_AND_CREATE_ACCOUNT_FINISH, account->account_id, NULL, handle_to_be_published, err))
+ EM_DEBUG_EXCEPTION("em_storage_notify_network_event [ NOTI_VALIDATE_ACCOUNT_FINISH] Success");
+ }
+ }
+
+ ret = true;
+
+FINISH_OFF:
+
+ if (ret == false && err != EMF_ERROR_CANCELLED) {
+ if (!em_storage_notify_network_event(NOTI_VALIDATE_AND_CREATE_ACCOUNT_FAIL, account->account_id, NULL, handle_to_be_published, err))
+ EM_DEBUG_EXCEPTION(" em_storage_notify_network_event [ NOTI_VALIDATE_AND_CREATE_ACCOUNT_FAIL] Failed");
+ }
+ if (error)
+ *error = err;
+
+ EM_DEBUG_FUNC_END();
+ return ret;
+}
+
+int event_handler_EMF_EVENT_VALIDATE_AND_UPDATE_ACCOUNT(int account_id, emf_account_t *new_account_info, int handle_to_be_published, int *error)
+{
+ EM_DEBUG_FUNC_BEGIN("account_id [%d], new_account_info [%p]", account_id, new_account_info);
+ int err, ret = false;
+ emf_mail_account_tbl_t *old_account_tbl = NULL, *new_account_tbl = NULL;
+
+ if (!new_account_info) {
+ EM_DEBUG_EXCEPTION("Invalid Parameter");
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ if (!em_core_check_network_status(&err)) {
+ EM_DEBUG_EXCEPTION("em_core_check_network_status failed [%d]", err);
+
+ if (!em_storage_notify_network_event(NOTI_VALIDATE_AND_UPDATE_ACCOUNT_FAIL, new_account_info->account_id, NULL, handle_to_be_published, err))
+ EM_DEBUG_EXCEPTION("em_storage_notify_network_event [ NOTI_VALIDATE_AND_UPDATE_ACCOUNT_FAIL] Failed >>>> ");
+ goto FINISH_OFF;
+ }
+ else {
+ EM_DEBUG_LOG("receiving_server_addr : %s", new_account_info->receiving_server_addr);
+
+ if (!em_core_account_validate_with_account_info(new_account_info, &err)) {
+ EM_DEBUG_EXCEPTION("\t em_core_account_validate_with_account_info failed err : %d", err);
+ if (err == EMF_ERROR_CANCELLED) {
+ EM_DEBUG_EXCEPTION(" notify : NOTI_VALIDATE_AND_CREATE_ACCOUNT_CANCEL ");
+ if (!em_storage_notify_network_event(NOTI_VALIDATE_AND_UPDATE_ACCOUNT_CANCEL, new_account_info->account_id, NULL, handle_to_be_published, err))
+ EM_DEBUG_EXCEPTION(" em_storage_notify_network_event [ NOTI_VALIDATE_AND_UPDATE_ACCOUNT_CANCEL] Failed");
+ goto FINISH_OFF;
+ }
+ else {
+ goto FINISH_OFF;
+ }
+ }
+ else {
+ if (!em_storage_get_account_by_id(account_id, WITHOUT_OPTION, &old_account_tbl, true, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_get_account_by_id failed [%d]", err);
+ /* goto FINISH_OFF; */
+ }
+
+ new_account_tbl = em_core_malloc(sizeof(emf_mail_account_tbl_t));
+ if (!new_account_tbl) {
+ EM_DEBUG_EXCEPTION("allocation failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ em_convert_account_to_account_tbl(new_account_info, new_account_tbl);
+
+ if (em_storage_update_account(account_id, new_account_tbl, true, &err)) {
+ em_core_refresh_account_reference();
+ }
+
+ EM_DEBUG_EXCEPTION("validating and updating an account are succeeded for account id [%d], err [%d]", new_account_info->account_id, err);
+ if (!em_storage_notify_network_event(NOTI_VALIDATE_AND_UPDATE_ACCOUNT_FINISH, new_account_info->account_id, NULL, handle_to_be_published, err))
+ EM_DEBUG_EXCEPTION(" em_storage_notify_network_event [NOTI_VALIDATE_AND_UPDATE_ACCOUNT_FINISH] Success");
+ }
+ }
+
+ ret = true;
+
+FINISH_OFF:
+ if (old_account_tbl)
+ em_storage_free_account(&old_account_tbl, 1, NULL);
+ if (new_account_tbl)
+ em_storage_free_account(&new_account_tbl, 1, NULL);
+
+ if (ret == false && err != EMF_ERROR_CANCELLED) {
+ if (!em_storage_notify_network_event(NOTI_VALIDATE_AND_UPDATE_ACCOUNT_FAIL, new_account_info->account_id, NULL, handle_to_be_published, err))
+ EM_DEBUG_EXCEPTION(" em_storage_notify_network_event [ NOTI_VALIDATE_AND_CREATE_ACCOUNT_FAIL] Failed");
+ }
+
+ if (error)
+ *error = err;
+
+ EM_DEBUG_FUNC_END();
+ return ret;
+}
+
+int event_handler_EMF_EVENT_SET_MAIL_SLOT_SIZE(int account_id, char *mailbox_name, int new_slot_size, int handle_to_be_published, int *error)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ em_core_mailbox_set_mail_slot_size(account_id, mailbox_name, new_slot_size, error);
+
+ EM_DEBUG_FUNC_END();
+ return true;
+}
+
+
+#ifdef __LOCAL_ACTIVITY__
+int event_handler_EMF_EVENT_LOCAL_ACTIVITY(int account_id, int *error)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ int err = EMF_ERROR_NONE;
+ emf_mailbox_t mailbox;
+ emf_activity_tbl_t *local_activity = NULL;
+ int activity_id_count = 0;
+ int activity_chunk_count = 0;
+ int *activity_id_list = NULL;
+ int i = 0;
+
+ if (!em_core_check_network_status(&err))
+ EM_DEBUG_EXCEPTION("em_core_check_network_status failed [%d]", err);
+ else {
+ if (false == em_storage_get_activity_id_list(account_id, &activity_id_list, &activity_id_count, ACTIVITY_DELETEMAIL, ACTIVITY_COPYMAIL, true, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_get_activity_id_list failed [%d]", err);
+ }
+ else {
+ for (i = 0; i < activity_id_count; ++i) {
+ if ((false == em_storage_get_activity(account_id , activity_id_list[i], &local_activity, &activity_chunk_count, true, &err)) || (NULL == local_activity) || (0 == activity_chunk_count))
+ EM_DEBUG_EXCEPTION(" em_storage_get_activity Failed [ %d] or local_activity is NULL [%p] or activity_chunk_count is 0[%d]", err, local_activity, activity_chunk_count);
+ else {
+ EM_DEBUG_LOG("Found local activity type - %d", local_activity[0].activity_type);
+ switch (local_activity[0].activity_type) {
+ case ACTIVITY_MODIFYFLAG: {
+ if (em_core_mail_sync_flag_with_server(local_activity[0].mail_id , &err)) {
+ if (!em_core_activity_delete(&local_activity[0], &err))
+ EM_DEBUG_EXCEPTION(">>>>>>Local Activity [ACTIVITY_MODIFYFLAG] [%d] ", err);
+ }
+ }
+ break;
+
+ case ACTIVITY_DELETEMAIL:
+ case ACTIVITY_MOVEMAIL:
+ case ACTIVITY_MODIFYSEENFLAG:
+ case ACTIVITY_COPYMAIL: {
+
+ int j = 0, k = 0;
+ int total_mail_ids = activity_chunk_count;
+
+ int *mail_id_list = NULL;
+
+ mail_id_list = (int *)em_core_malloc(sizeof(int) * total_mail_ids);
+
+ if (NULL == mail_id_list) {
+ EM_DEBUG_EXCEPTION("malloc failed... ");
+ break;
+ }
+
+ do {
+
+ for (j = 0; j < BULK_OPERATION_COUNT && (k < total_mail_ids); ++j, ++k)
+ mail_id_list[j] = local_activity[k].mail_id;
+
+ switch (local_activity[k-1].activity_type) {
+ case ACTIVITY_DELETEMAIL: {
+ if (!em_core_mail_delete(local_activity[k-1].account_id,
+ mail_id_list,
+ j,
+ EMF_DELETE_LOCAL_AND_SERVER,
+ EMF_DELETED_BY_COMMAND,
+ false,
+ &err))
+ EM_DEBUG_LOG("\t em_core_mail_delete failed - %d", err);
+ }
+ break;
+
+ case ACTIVITY_MOVEMAIL: {
+ if (!em_core_mail_move_from_server_ex(local_activity[k-1].account_id ,
+ local_activity[k-1].src_mbox,
+ mail_id_list,
+ j,
+ local_activity[k-1].dest_mbox,
+ &err))
+ EM_DEBUG_LOG("\t em_core_mail_move_from_server_ex failed - %d", err);
+ }
+ break;
+ case ACTIVITY_MODIFYSEENFLAG: {
+ int seen_flag = atoi(local_activity[0].src_mbox);
+ if (!em_core_mail_sync_seen_flag_with_server_ex(mail_id_list, j , seen_flag , &err)) /* local_activity[0].src_mbox points to the seen flag */
+ EM_DEBUG_EXCEPTION("\t em_core_mail_sync_seen_flag_with_server_ex failed - %d", err);
+ }
+ break;
+ }
+
+ } while (k < total_mail_ids);
+
+ EM_SAFE_FREE(mail_id_list);
+ }
+
+ break;
+
+ default:
+ EM_DEBUG_LOG(">>>> No such Local Activity Handled by this thread [ %d ] >>> ", local_activity[0].activity_type);
+ break;
+ }
+
+ em_storage_free_local_activity(&local_activity, activity_chunk_count, NULL);
+
+ if (g_local_activity_run == 1) {
+ EM_DEBUG_LOG(" Network event_data found.. Local sync Stopped..! ");
+ break;
+ }
+ }
+ }
+ }
+ }
+ if (activity_id_list) {
+ if (false == em_storage_free_activity_id_list(activity_id_list, &err))
+ EM_DEBUG_EXCEPTION("em_storage_free_activity_id_list failed");
+ }
+
+ if (error)
+ *error = err;
+
+ EM_DEBUG_FUNC_END();
+
+ return true;
+}
+#endif /* __LOCAL_ACTIVITY__ */
+
+int event_handler_EMF_EVENT_DOWNLOAD_BODY(int account_id, char *mailbox_name, int mail_id, int option, int handle_to_be_published, int *error)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ int err = EMF_ERROR_NONE;
+ emf_mailbox_t mailbox;
+
+ memset(&mailbox, 0x00, sizeof(mailbox));
+ mailbox.account_id = account_id;
+ mailbox.name = mailbox_name;
+
+ if (!em_core_check_network_status(&err)) {
+ EM_DEBUG_EXCEPTION("em_core_check_network_status failed [%d]", err);
+
+ em_storage_notify_network_event(NOTI_DOWNLOAD_BODY_FAIL, mail_id, NULL, handle_to_be_published, err);
+ }
+ else {
+ if (!em_core_mail_download_body_multi_sections_bulk(NULL,
+ mailbox.account_id,
+ mail_id,
+ option >> 1, /* 0 : silent, 1 : verbose */
+ option & 0x01, /* 0 : without attachments, 1 : with attachments */
+ NO_LIMITATION,
+ handle_to_be_published,
+ &err))
+ EM_DEBUG_EXCEPTION("em_core_mail_download_body_multi_sections_bulk failed - %d", err);
+ }
+
+ if (error)
+ *error = err;
+
+ EM_DEBUG_FUNC_END();
+ return true;
+}
+
+int event_handler_EMF_EVENT_DOWNLOAD_ATTACHMENT(int account_id, char *mailbox_name, int mail_id, char *attachment_no, int handle_to_be_published, int *error)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ int err = EMF_ERROR_NONE;
+ emf_mailbox_t mailbox;
+
+ EM_DEBUG_LOG("attachment_no is %d", atoi(attachment_no));
+
+ if (!em_core_check_network_status(&err)) {
+ EM_DEBUG_EXCEPTION("em_core_check_network_status failed [%d]", err);
+ em_storage_notify_network_event(NOTI_DOWNLOAD_ATTACH_FAIL, mail_id, NULL, atoi(attachment_no), err);
+ }
+ else {
+ memset(&mailbox, 0x00, sizeof(mailbox));
+ mailbox.account_id = account_id;
+ mailbox.name = mailbox_name;
+
+#ifdef __ATTACHMENT_OPTI__
+ if (!em_core_mail_download_attachment_bulk(mailbox.account_id, mail_id, (char *)attachment_no, &err))
+ EM_DEBUG_EXCEPTION("\t em_core_mail_download_attachment failed - %d", err);
+#else
+ if (!em_core_mail_download_attachment(mailbox.account_id, mail_id, (char *)attachment_no, &err))
+ EM_DEBUG_EXCEPTION("\t em_core_mail_download_attachment failed - %d", err);
+#endif
+ }
+
+ if (error)
+ *error = err;
+
+ EM_DEBUG_FUNC_END();
+ return true;
+}
+
+int event_handler_EMF_EVENT_SYNC_FLAGS_FIELD_TO_SERVER(int mail_ids[], int num, emf_flags_field_type field_type, int value, int *error)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ int err = EMF_ERROR_NONE;
+
+ if (!em_core_check_network_status(&err))
+ EM_DEBUG_EXCEPTION("dnet_init failed [%d]", err);
+ else if (!em_core_mail_sync_flags_field_with_server(mail_ids, num, field_type, value, &err))
+ EM_DEBUG_EXCEPTION("em_core_mail_sync_flags_field_with_server failed [%d]", err);
+
+ if (error)
+ *error = err;
+
+ EM_DEBUG_FUNC_END();
+ return true;
+}
+
+int event_handler_EMF_EVENT_VALIDATE_ACCOUNT(int account_id, int handle_to_be_published, int *error)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ int err = EMF_ERROR_NONE;
+
+ if (!em_core_check_network_status(&err)) {
+ EM_DEBUG_EXCEPTION("em_core_check_network_status failed [%d]", err);
+
+ if (!em_storage_notify_network_event(NOTI_VALIDATE_ACCOUNT_FAIL, account_id, NULL, handle_to_be_published, err))
+ EM_DEBUG_EXCEPTION("em_storage_notify_network_event [ NOTI_VALIDATE_ACCOUNT_FAIL] Failed >>>>");
+ }
+ else {
+
+ if (!em_core_account_validate(account_id, &err)) {
+ EM_DEBUG_EXCEPTION("em_core_account_validate failed account id : %d err : %d", account_id, err);
+
+ if (err == EMF_ERROR_CANCELLED) {
+ EM_DEBUG_EXCEPTION("notify : NOTI_VALIDATE_ACCOUNT_CANCEL ");
+ if (!em_storage_notify_network_event(NOTI_VALIDATE_ACCOUNT_CANCEL, account_id, NULL, handle_to_be_published, err))
+ EM_DEBUG_EXCEPTION(" em_storage_notify_network_event [ NOTI_VALIDATE_ACCOUNT_CANCEL] Failed >>>> ");
+ }
+ else {
+ if (!em_storage_notify_network_event(NOTI_VALIDATE_ACCOUNT_FAIL, account_id, NULL, handle_to_be_published, err))
+ EM_DEBUG_EXCEPTION("em_storage_notify_network_event [ NOTI_VALIDATE_ACCOUNT_FAIL] Failed >>>> ");
+ }
+ }
+ else {
+ emf_account_t *account_ref;
+ account_ref = em_core_get_account_reference(account_id);
+
+ if (account_ref) {
+ EM_DEBUG_LOG("account_ref->receiving_server_type[%d]", account_ref->receiving_server_type);
+ EM_DEBUG_LOG("account_ref->preset_account[%d]", account_ref->preset_account);
+ if ((EMF_SERVER_TYPE_IMAP4 == account_ref->receiving_server_type) && (account_ref->preset_account)) {
+ if (!em_core_check_thread_status())
+ err = EMF_ERROR_CANCELLED;
+ else if (!em_core_mailbox_sync_mailbox_list(account_id, "", &err))
+ EM_DEBUG_EXCEPTION("\t em_core_mailbox_get_list_to_be_sync falied - %d", err);
+ }
+
+ if (err > 0) {
+ EM_DEBUG_EXCEPTION("em_core_account_validate succeeded account id : %d err : %d", account_id, err);
+ if (!em_storage_notify_network_event(NOTI_VALIDATE_ACCOUNT_FINISH, account_id, NULL, handle_to_be_published, err))
+ EM_DEBUG_EXCEPTION("em_storage_notify_network_event [ NOTI_VALIDATE_ACCOUNT_FINISH] Success >>>>");
+ }
+ }
+ }
+ }
+
+ if (error)
+ *error = err;
+
+ EM_DEBUG_FUNC_END();
+ return true;
+}
+
+int event_handler_EMF_EVENT_UPDATE_MAIL_OLD(int mail_id, emf_mail_t *mail, emf_meeting_request_t *meeting_req, int handle_to_be_published, int *error)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int err = EMF_ERROR_NONE;
+
+ if (!em_core_mail_update_old(mail_id, mail, meeting_req, &err))
+ EM_DEBUG_EXCEPTION("em_core_mail_update_old failed [%d]", err);
+ em_core_mail_free(&mail, 1, NULL);
+ EM_SAFE_FREE(meeting_req);
+
+ if (error)
+ *error = err;
+
+ EM_DEBUG_FUNC_END();
+ return true;
+}
+
+int event_handler_EMF_EVENT_UPDATE_MAIL(emf_mail_data_t *input_mail_data, emf_attachment_data_t *input_attachment_data_list, int input_attachment_count, emf_meeting_request_t* input_meeting_request, int input_sync_server, int handle_to_be_published)
+{
+ EM_DEBUG_FUNC_BEGIN("input_mail_data[%p], input_attachment_data_list[%p], input_attachment_count[%d], input_meeting_request[%p], input_sync_server[%d]", input_mail_data, input_attachment_data_list, input_attachment_count, input_meeting_request, input_sync_server);
+ int err = EMF_ERROR_NONE;
+
+ if ( (err = em_core_update_mail(input_mail_data, input_attachment_data_list, input_attachment_count, input_meeting_request, input_sync_server)) != EMF_ERROR_NONE)
+ EM_DEBUG_EXCEPTION("em_core_update_mail failed [%d]", err);
+
+ if(input_mail_data)
+ em_core_free_mail_data(&input_mail_data, 1, NULL);
+
+ if(input_attachment_data_list)
+ em_core_free_attachment_data(&input_attachment_data_list, input_attachment_count, NULL);
+
+ if(input_meeting_request)
+ em_storage_free_meeting_request(&input_meeting_request, 1, NULL);
+
+ EM_DEBUG_FUNC_END("err [%d", err);
+ return err;
+}
+
+int event_handler_EMF_EVENT_MOVE_MAIL(int account_id, char *srt_mailbox_name, int *mail_ids, int mail_id_count, char *dest_mailbox_name, int handle_to_be_published, int *error)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int err = EMF_ERROR_NONE, ret = false;
+ emf_mailbox_t dest_mailbox;
+ emf_account_t *account_ref = NULL;
+
+ if (!(account_ref = em_core_get_account_reference(account_id))) {
+ EM_DEBUG_EXCEPTION("em_core_get_account_reference failed [%d]", account_id);
+ err = EMF_ERROR_INVALID_ACCOUNT;
+ goto FINISH_OFF;
+ }
+
+ memset(&dest_mailbox, 0, sizeof(emf_mailbox_t));
+ dest_mailbox.name = dest_mailbox_name;
+
+ /* Remove mail local */
+ /*
+ if (!em_core_mail_move(mail_ids, mail_id_count, dest_mailbox.name, EMF_MOVED_BY_COMMAND, 0, &err)) {
+ EM_DEBUG_EXCEPTION("em_core_mail_move failed [%d]", err);
+ goto FINISH_OFF;
+ }
+ */
+
+ if (account_ref->receiving_server_type == EMF_SERVER_TYPE_IMAP4) {
+ /* Remove mail on server */
+ if (!em_core_check_network_status(&err))
+ EM_DEBUG_EXCEPTION("em_core_check_network_status failed [%d]", err);
+ else {
+#ifdef __FEATURE_BULK_DELETE_MOVE_UPDATE_REQUEST_OPTI__
+ if (!em_core_mail_move_from_server_ex(account_id , srt_mailbox_name, mail_ids, mail_id_count, dest_mailbox_name, &err))
+ EM_DEBUG_EXCEPTION("em_core_mail_move_from_server_ex failed - %d", err);
+#else
+ if (!em_core_mail_move_from_server(account_id , srt_mailbox_name, mail_ids, mail_id_count, dest_mailbox_name, &err))
+ EM_DEBUG_EXCEPTION("\t em_core_mail_move_from_server failed - %d", err);
+#endif
+ }
+ }
+
+ ret = true;
+FINISH_OFF:
+
+ if (error)
+ *error = err;
+
+ EM_DEBUG_FUNC_END();
+ return ret;
+}
+
+int event_handler_EMF_EVENT_DELETE_MAILBOX(int account_id, char *mailbox_name, int on_server, int handle_to_be_published, int *error)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int err = EMF_ERROR_NONE;
+ emf_mailbox_t mailbox;
+
+ memset(&mailbox, 0x00, sizeof(mailbox));
+ mailbox.account_id = account_id;
+ mailbox.name = mailbox_name;
+
+ if (!em_core_check_network_status(&err))
+ EM_DEBUG_EXCEPTION("em_core_check_network_status failed [%d]", err);
+ else {
+ if (!em_core_mailbox_delete(&mailbox, on_server, &err))
+ EM_DEBUG_LOG("em_core_mailbox_delete failed - %d", err);
+ }
+
+ if (error)
+ *error = err;
+
+ EM_DEBUG_FUNC_END();
+ return true;
+}
+
+int event_handler_EMF_EVENT_CREATE_MAILBOX(int account_id, char *mailbox_name, char *mailbox_alias, int mailbox_type, int on_server, int handle_to_be_published, int *error)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int err = EMF_ERROR_NONE;
+ emf_mailbox_t mailbox;
+
+ memset(&mailbox, 0x00, sizeof(mailbox));
+
+ mailbox.account_id = account_id;
+ mailbox.name = mailbox_name;
+ mailbox.alias = mailbox_alias;
+ mailbox.mailbox_type = mailbox_type;
+
+ if (!em_core_check_network_status(&err)) {
+ EM_DEBUG_EXCEPTION("em_core_check_network_status failed [%d]", err);
+ }
+ else {
+ if (!em_core_mailbox_create(&mailbox, on_server, &err))
+ EM_DEBUG_EXCEPTION("em_core_mailbox_create failed - %d", err);
+ }
+
+
+ if (error)
+ *error = err;
+
+ EM_DEBUG_FUNC_END();
+ return true;
+}
+
+int event_handler_EMF_EVENT_SYNC_MAIL_FLAG_TO_SERVER(int mail_id, int *error)
+{
+ EM_DEBUG_FUNC_BEGIN("mail_id [%d], error [%p]", mail_id, error);
+
+ int err = EMF_ERROR_NONE;
+
+ if (!em_core_check_network_status(&err))
+ EM_DEBUG_EXCEPTION("em_core_check_network_status failed [%d]", err);
+ else {
+ if (!em_core_mail_sync_flag_with_server(mail_id, &err))
+ EM_DEBUG_EXCEPTION("em_core_mail_sync_flag_with_server failed [%d]", err);
+#ifdef __LOCAL_ACTIVITY__
+ else {
+ emf_activity_tbl_t new_activity;
+ memset(&new_activity, 0x00, sizeof(emf_activity_tbl_t));
+ new_activity.activity_type = ACTIVITY_MODIFYFLAG;
+ new_activity.account_id = event_data.account_id;
+ new_activity.mail_id = event_data.event_param_data_4;
+ new_activity.dest_mbox = NULL;
+ new_activity.server_mailid = NULL;
+ new_activity.src_mbox = NULL;
+
+ if (!em_core_activity_delete(&new_activity, &err))
+ EM_DEBUG_EXCEPTION(">>>>>>Local Activity [ACTIVITY_MODIFYFLAG] [%d] ", err);
+ }
+#endif /* __LOCAL_ACTIVITY__ */
+ }
+
+ if (error)
+ *error = err;
+
+ EM_DEBUG_FUNC_END();
+ return true;
+}
+
+int event_handler_EMF_EVENT_DELETE_MAIL_ALL(int account_id, char *mailbox_name, int with_server, int *error)
+{
+ EM_DEBUG_FUNC_BEGIN("account_id [%d], mailbox_name [%p], with_server [%d], error [%p]", account_id, mailbox_name, with_server, error);
+ int err = EMF_ERROR_NONE;
+ emf_mailbox_t temp_mailbox = { 0 };
+
+ temp_mailbox.account_id = account_id;
+ temp_mailbox.name = mailbox_name;
+
+ if (!em_core_mail_delete_all(&temp_mailbox, with_server, &err))
+ EM_DEBUG_EXCEPTION("em_core_mail_delete_all failed [%d]", err);
+
+ if (error)
+ *error = err;
+
+ EM_DEBUG_FUNC_END("err [%d]", err);
+ return true;
+}
+
+int event_handler_EMF_EVENT_DELETE_MAIL(int account_id, int *mail_id_list, int mail_id_count, char *mailbox_name, int *error)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int mail_id = 0, err = EMF_ERROR_NONE, ret = false;
+ emf_account_t *account_ref = NULL;
+
+ if (!(account_ref = em_core_get_account_reference(account_id))) {
+ EM_DEBUG_EXCEPTION("em_core_get_account_reference failed [%d]", account_id);
+ err = EMF_ERROR_INVALID_ACCOUNT;
+ goto FINISH_OFF;
+ }
+
+ if (account_ref->receiving_server_type == EMF_SERVER_TYPE_IMAP4) {
+ if (!em_core_check_network_status(&err)) {
+ EM_DEBUG_EXCEPTION("em_core_check_network_status failed [%d]", err);
+
+ if (!em_storage_notify_network_event(NOTI_MAIL_DELETE_ON_SERVER_FAIL, account_id, mailbox_name, mail_id, err))
+ EM_DEBUG_EXCEPTION(" em_storage_notify_network_event [NOTI_MAIL_DELETE_ON_SERVER_FAIL] Failed");
+
+ }
+ else if (!em_core_mail_delete(account_id, mail_id_list, mail_id_count, EMF_DELETE_LOCAL_AND_SERVER, EMF_DELETED_BY_COMMAND, false, &err)) {
+ EM_DEBUG_EXCEPTION("em_core_mail_delete failed [%d]", err);
+
+ if (!em_storage_notify_network_event(NOTI_MAIL_DELETE_ON_SERVER_FAIL, account_id, mailbox_name, mail_id, err))
+ EM_DEBUG_EXCEPTION("em_storage_notify_network_event [NOTI_MAIL_DELETE_ON_SERVER_FAIL] Failed");
+ }
+ }
+
+ ret = true;
+FINISH_OFF:
+
+ if (error)
+ *error = err;
+
+ EM_DEBUG_FUNC_END();
+ return ret;
+}
+
+int event_hanlder_EMF_EVENT_SYNC_HEADER_OMA(int account_id, char *maibox_name, int *error)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int err = EMF_ERROR_NONE;
+
+ if (!em_core_check_network_status(&err)) {
+ EM_DEBUG_EXCEPTION("em_core_check_network_status failed [%d]", err);
+ if (!em_storage_notify_network_event(NOTI_DOWNLOAD_FAIL, account_id, maibox_name, 0, err))
+ EM_DEBUG_EXCEPTION("em_storage_notify_network_event [NOTI_DOWNLOAD_FAIL] Failed");
+ }
+ else {
+ EM_DEBUG_LOG("Sync of all mailbox");
+ if (!em_core_mailbox_sync_mailbox_list(account_id, "", &err))
+ EM_DEBUG_EXCEPTION("em_core_mailbox_sync_mailbox_list failed [%d]", err);
+ }
+
+ if (error)
+ *error = err;
+
+ EM_DEBUG_FUNC_END();
+ return true;
+}
+
+void* thread_func_branch_command(void *arg)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ int err = EMF_ERROR_NONE, is_storage_full = false, noti_id;
+ emf_event_t event_data;
+ emf_session_t *session = NULL;
+ int handle_to_be_published = 0;
+
+ if (!em_storage_open(&err)) {
+ EM_DEBUG_EXCEPTION("em_storage_open falied [%d]", err);
+ return false;
+ }
+
+ /* check that event_data loop is continuous */
+ while (em_core_event_loop_continue()) {
+ if (!em_core_get_empty_session(&session))
+ EM_DEBUG_EXCEPTION("em_core_get_empty_session failed...");
+
+ /* get a event_data from event_data queue */
+ if (!em_core_retrieve_event(&event_data, NULL)) { /* no event_data pending */
+ EM_DEBUG_LOG("For handle g_event_que[g_event_que_idx].type [%d], g_event_que_idx [%d]", g_event_que[g_event_que_idx].type, g_event_que_idx);
+#ifdef ENABLE_IMAP_IDLE_THREAD
+ if ( !em_core_check_network_status(&err)) {
+ EM_DEBUG_LOG(">>>> Data Networking ON ");
+ if (g_client_run) {
+ if (g_imap_idle_thread_alive) {
+ /* em_core_imap_idle_thread_kill(NULL); */
+ /* em_core_imap_idle_thread_create(NULL); */
+ }
+ else {
+ if (!send_thread_run)
+ em_core_imap_idle_thread_create(event_data.account_id, NULL);
+ }
+ }
+ }
+#endif /* ENABLE_IMAP_IDLE_THREAD */
+#ifdef __LOCAL_ACTIVITY__
+ /* Local activity sync */
+ if (g_client_run && g_local_activity_run) {
+ emf_mail_account_tbl_t *account_list = NULL;
+ int count = 0, i;
+ if (!em_storage_get_account_list(&count, &account_list, true, true, &err))
+ EM_DEBUG_EXCEPTION("em_storage_get_account_list failed [%d]", err);
+ else {
+ for (i = 0; i < count; i++) {
+ if (em_core_local_activity_sync(account_list[i].account_id, &err)) {
+ EM_DEBUG_LOG("Found local activity...!");
+ EM_DEBUG_LOG("Resetting g_local_activity_run ");
+ g_local_activity_run = 0;
+ em_core_clear_session(session);
+ }
+ }
+
+ em_storage_free_account(&account_list, count, &err);
+
+ if (!g_local_activity_run)
+ continue;
+ }
+ }
+#endif
+
+ recv_thread_run = 0;
+
+ ENTER_CRITICAL_SECTION(_event_available_lock);
+ SLEEP_CONDITION_VARIABLE(_event_available_signal, _event_available_lock);
+ EM_DEBUG_LOG("Wake up by _event_available_signal");
+ LEAVE_CRITICAL_SECTION(_event_available_lock);
+ }
+ else {
+ EM_DEBUG_LOG(">>>>>>>>>>>>>>> Got event_data !!! <<<<<<<<<<<<<<<");
+ EM_DEBUG_LOG("For handle g_event_que_idx - %d", g_event_que_idx);
+
+ if (g_event_que_idx == 1)
+ handle_to_be_published = 31;
+ else
+ handle_to_be_published = g_event_que_idx - 1 ;
+
+ EM_DEBUG_LOG("Handle to be Published [%d]", handle_to_be_published);
+ recv_thread_run = 1;
+ g_client_run = 1;
+
+ /* Handling storage full */
+ is_storage_full = false;
+ if (event_data.type == EMF_EVENT_SYNC_HEADER || event_data.type == EMF_EVENT_SYNC_HEADER_OMA ||
+ event_data.type == EMF_EVENT_DOWNLOAD_BODY || event_data.type == EMF_EVENT_DOWNLOAD_ATTACHMENT) {
+ if (em_core_is_storage_full(&err) == true) {
+ EM_DEBUG_EXCEPTION("Storage is full");
+ switch (event_data.type) {
+ case EMF_EVENT_SYNC_HEADER:
+ case EMF_EVENT_SYNC_HEADER_OMA:
+ noti_id = NOTI_DOWNLOAD_FAIL;
+ break;
+ case EMF_EVENT_DOWNLOAD_BODY:
+ noti_id = NOTI_DOWNLOAD_BODY_FAIL;
+ break;
+ case EMF_EVENT_DOWNLOAD_ATTACHMENT:
+ noti_id = NOTI_DOWNLOAD_ATTACH_FAIL;
+ break;
+ default:
+ break;
+ }
+
+ if (!em_storage_notify_network_event(noti_id, event_data.account_id, NULL, handle_to_be_published, err))
+ EM_DEBUG_EXCEPTION(" em_storage_notify_network_event [NOTI_DOWNLOAD_FAIL] Failed >>>> ");
+ is_storage_full = true;
+ }
+ }
+
+ em_storage_dimming_on_off(false, NULL);
+
+ switch (event_data.type) {
+ case EMF_EVENT_SYNC_IMAP_MAILBOX: /* get imap mailbox list */
+ if (!em_core_check_network_status(&err))
+ EM_DEBUG_EXCEPTION("em_core_check_network_status failed [%d]", err);
+ else {
+ if (!em_core_mailbox_sync_mailbox_list(event_data.account_id, event_data.event_param_data_3, &err))
+ EM_DEBUG_EXCEPTION("em_core_mailbox_sync_mailbox_list failed [%d]", err);
+ }
+ EM_SAFE_FREE(event_data.event_param_data_3);
+ break;
+
+ case EMF_EVENT_SYNC_HEADER: /* synchronize mail header */
+ if (is_storage_full == false)
+ event_handler_EMF_EVENT_SYNC_HEADER(event_data.account_id, event_data.event_param_data_1, handle_to_be_published, &err);
+ EM_SAFE_FREE(event_data.event_param_data_1);
+ break;
+
+ case EMF_EVENT_SYNC_HEADER_OMA: /* synchronize mail header for OMA */
+ if (is_storage_full == false)
+ event_hanlder_EMF_EVENT_SYNC_HEADER_OMA(event_data.account_id, event_data.event_param_data_1, &err);
+ EM_SAFE_FREE(event_data.event_param_data_1);
+ break;
+
+ case EMF_EVENT_DOWNLOAD_BODY: /* download mail body */
+ if (is_storage_full == false)
+ event_handler_EMF_EVENT_DOWNLOAD_BODY(event_data.account_id, event_data.event_param_data_1, (int)event_data.event_param_data_4, (int)event_data.event_param_data_3, handle_to_be_published, &err);
+ event_data.event_param_data_3 = NULL; /* MUST BE */
+ EM_SAFE_FREE(event_data.event_param_data_1);
+ break;
+
+ case EMF_EVENT_DOWNLOAD_ATTACHMENT: /* download attachment */
+ if (is_storage_full == false)
+ event_handler_EMF_EVENT_DOWNLOAD_ATTACHMENT(event_data.account_id, event_data.event_param_data_1, (int)event_data.event_param_data_4, event_data.event_param_data_3, handle_to_be_published, &err);
+ EM_SAFE_FREE(event_data.event_param_data_3);
+ break;
+
+ case EMF_EVENT_SYNC_FLAGS_FIELD_TO_SERVER: /* Sync flags field */
+ event_handler_EMF_EVENT_SYNC_FLAGS_FIELD_TO_SERVER((int*)event_data.event_param_data_3, event_data.event_param_data_4 , event_data.event_param_data_5, event_data.event_param_data_6, &err);
+ EM_SAFE_FREE(event_data.event_param_data_3);
+ break;
+
+ case EMF_EVENT_DELETE_MAIL: /* delete mails */
+ event_handler_EMF_EVENT_DELETE_MAIL(event_data.account_id, (int *)event_data.event_param_data_3, event_data.event_param_data_4, event_data.event_param_data_1, &err);
+ EM_SAFE_FREE(event_data.event_param_data_1);
+ EM_SAFE_FREE(event_data.event_param_data_3);
+ break;
+
+ case EMF_EVENT_DELETE_MAIL_ALL: /* delete all mails */
+ event_handler_EMF_EVENT_DELETE_MAIL_ALL((int)event_data.account_id, (char *)event_data.event_param_data_1, (int)event_data.event_param_data_4, &err);
+ EM_SAFE_FREE(event_data.event_param_data_1);
+ break;
+#ifdef __FEATURE_SYNC_CLIENT_TO_SERVER__
+ case EMF_EVENT_SYNC_MAIL_FLAG_TO_SERVER:
+ event_handler_EMF_EVENT_SYNC_MAIL_FLAG_TO_SERVER((int)event_data.event_param_data_4, &err);
+ break;
+#endif
+
+ case EMF_EVENT_CREATE_MAILBOX:
+ event_handler_EMF_EVENT_CREATE_MAILBOX(event_data.account_id, event_data.event_param_data_1, event_data.event_param_data_2, GPOINTER_TO_INT(event_data.event_param_data_3), event_data.event_param_data_4, handle_to_be_published, &err);
+ EM_SAFE_FREE(event_data.event_param_data_1);
+ EM_SAFE_FREE(event_data.event_param_data_2);
+ break;
+
+ case EMF_EVENT_DELETE_MAILBOX:
+ event_handler_EMF_EVENT_DELETE_MAILBOX(event_data.account_id, event_data.event_param_data_1, event_data.event_param_data_4, handle_to_be_published, &err);
+ EM_SAFE_FREE(event_data.event_param_data_1);
+ break;
+
+ case EMF_EVENT_MOVE_MAIL:
+ event_handler_EMF_EVENT_MOVE_MAIL(event_data.account_id, event_data.event_param_data_2, (int *)event_data.event_param_data_3, event_data.event_param_data_4, event_data.event_param_data_1, handle_to_be_published, &err);
+
+ EM_SAFE_FREE(event_data.event_param_data_1);
+ EM_SAFE_FREE(event_data.event_param_data_2);
+ EM_SAFE_FREE(event_data.event_param_data_3);
+ break;
+
+ case EMF_EVENT_VALIDATE_ACCOUNT:
+ event_handler_EMF_EVENT_VALIDATE_ACCOUNT(event_data.account_id, handle_to_be_published, &err);
+ break;
+
+ case EMF_EVENT_VALIDATE_AND_CREATE_ACCOUNT:
+ event_handler_EMF_EVENT_VALIDATE_AND_CREATE_ACCOUNT(em_core_account_get_new_account_ref(), handle_to_be_published, &err);
+ break;
+
+ case EMF_EVENT_VALIDATE_AND_UPDATE_ACCOUNT: {
+ emf_account_t *pAccount = (emf_account_t *)event_data.event_param_data_1;
+ event_handler_EMF_EVENT_VALIDATE_AND_UPDATE_ACCOUNT(event_data.account_id, pAccount, handle_to_be_published, &err);
+ em_core_account_free(&pAccount, 1, NULL);
+ }
+ break;
+
+ case EMF_EVENT_UPDATE_MAIL_OLD:
+ event_handler_EMF_EVENT_UPDATE_MAIL_OLD((int)event_data.event_param_data_4, (emf_mail_t *)event_data.event_param_data_1, (emf_meeting_request_t *)event_data.event_param_data_2, handle_to_be_published, &err);
+ event_data.event_param_data_1 = NULL;
+ event_data.event_param_data_2 = NULL;
+ break;
+
+ case EMF_EVENT_UPDATE_MAIL:
+ event_handler_EMF_EVENT_UPDATE_MAIL((emf_mail_data_t*)event_data.event_param_data_1, (emf_attachment_data_t*)event_data.event_param_data_2, event_data.event_param_data_4, (emf_meeting_request_t*)event_data.event_param_data_3, event_data.event_param_data_5, handle_to_be_published);
+
+ event_data.event_param_data_1 = NULL;
+ event_data.event_param_data_2 = NULL;
+ event_data.event_param_data_3 = NULL;
+ break;
+
+ case EMF_EVENT_SET_MAIL_SLOT_SIZE:
+ event_handler_EMF_EVENT_SET_MAIL_SLOT_SIZE(event_data.account_id, event_data.event_param_data_3, event_data.event_param_data_4, handle_to_be_published, &err);
+ EM_SAFE_FREE(event_data.event_param_data_3);
+ break;
+
+#ifdef __LOCAL_ACTIVITY__
+ case EMF_EVENT_LOCAL_ACTIVITY:
+ event_handler_EMF_EVENT_LOCAL_ACTIVITY(event_data.account_id, &err);
+ break;
+#endif /* __LOCAL_ACTIVITY__*/
+
+ default:
+ break;
+ }
+
+ em_storage_dimming_on_off(true, NULL);
+ em_core_flush_memory();
+
+ switch (event_data.type) {
+ case EMF_EVENT_SEND_MAIL:
+ case EMF_EVENT_SEND_MAIL_SAVED:
+ _sending_busy_unref();
+ break;
+
+ case EMF_EVENT_SYNC_HEADER:
+ case EMF_EVENT_SYNC_HEADER_OMA:
+ case EMF_EVENT_DOWNLOAD_BODY:
+ case EMF_EVENT_DOWNLOAD_ATTACHMENT:
+ case EMF_EVENT_SYNC_MAIL_FLAG_TO_SERVER:
+ case EMF_EVENT_SYNC_FLAGS_FIELD_TO_SERVER:
+ case EMF_EVENT_DELETE_MAIL:
+ case EMF_EVENT_DELETE_MAIL_ALL:
+ case EMF_EVENT_VALIDATE_ACCOUNT:
+ case EMF_EVENT_SYNC_IMAP_MAILBOX:
+ case EMF_EVENT_MOVE_MAIL:
+ case EMF_EVENT_CREATE_MAILBOX:
+ case EMF_EVENT_DELETE_MAILBOX:
+ case EMF_EVENT_SET_MAIL_SLOT_SIZE:
+ _receiving_busy_unref();
+ break;
+
+ default:
+ break;
+ }
+
+ event_data.type = 0;
+
+ ENTER_RECURSIVE_CRITICAL_SECTION(_event_queue_lock);
+ memset(g_event_que+g_active_que, 0x00, sizeof(emf_event_t));
+ LEAVE_RECURSIVE_CRITICAL_SECTION(_event_queue_lock);
+ }
+
+ em_core_clear_session(session);
+ }
+
+ if (!em_storage_close(&err))
+ EM_DEBUG_EXCEPTION("em_storage_close falied [%d]", err);
+
+ EM_DEBUG_FUNC_END();
+ return SUCCESS;
+}
+/*Send event_data loop*/
+EXPORT_API int em_core_send_event_loop_start(int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int thread_error = -1;
+
+ if (err_code != NULL)
+ *err_code = EMF_ERROR_NONE;
+
+ memset(&g_send_event_que, 0x00, sizeof(g_send_event_que));
+
+ if (g_send_srv_thread) {
+ EM_DEBUG_EXCEPTION("\t send service thread is already running...");
+ if (err_code != NULL)
+ *err_code = EMF_ERROR_UNKNOWN;
+ return true;
+ }
+
+ g_send_event_que_idx = 1;
+ g_send_event_loop = 1;
+ g_send_active_que = 0;
+
+ /* initialize lock */
+ /* INITIALIZE_CRITICAL_SECTION(_send_event_available_lock); */
+ INITIALIZE_RECURSIVE_CRITICAL_SECTION(_send_event_queue_lock);
+ INITIALIZE_CONDITION_VARIABLE(_send_event_available_signal);
+
+ /* create thread */
+ THREAD_CREATE_JOINABLE(g_send_srv_thread, send_event_handler, thread_error);
+
+ if (thread_error != 0) {
+ EM_DEBUG_EXCEPTION("cannot make thread...");
+ if (err_code != NULL)
+ *err_code = EMF_ERROR_UNKNOWN;
+ return FAILURE;
+ }
+
+ if (err_code != NULL)
+ *err_code = EMF_ERROR_NONE;
+ EM_DEBUG_FUNC_END();
+ return SUCCESS;
+}
+
+/* finish api event_data loop */
+EXPORT_API int em_core_send_event_loop_stop(int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ if (err_code != NULL)
+ *err_code = EMF_ERROR_NONE;
+
+ if (!g_send_srv_thread) {
+ if (err_code != NULL)
+ *err_code = EMF_ERROR_UNKNOWN;
+ return false;
+ }
+
+ /* stop event_data loop */
+ g_send_event_loop = 0;
+
+ em_core_cancel_send_mail_thread(g_send_active_que, NULL, err_code);
+ ENTER_CRITICAL_SECTION(_send_event_available_lock);
+ WAKE_CONDITION_VARIABLE(_send_event_available_signal); /* MUST BE HERE */
+ LEAVE_CRITICAL_SECTION(_send_event_available_lock);
+
+ /* wait for thread finished */
+ THREAD_JOIN(g_send_srv_thread);
+
+ g_send_srv_thread = 0;
+
+ DELETE_RECURSIVE_CRITICAL_SECTION(_send_event_queue_lock);
+ DELETE_CRITICAL_SECTION(_send_event_available_lock);
+ DELETE_CONDITION_VARIABLE(_send_event_available_signal);
+
+ g_send_event_que_idx = 1;
+ g_send_active_que = 0;
+
+ if (err_code != NULL)
+ *err_code = EMF_ERROR_NONE;
+
+ return true;
+}
+
+/* start api event_data loop */
+EXPORT_API int em_core_event_loop_start(int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int thread_error;
+
+ if (err_code != NULL)
+ *err_code = EMF_ERROR_NONE;
+
+ memset(&g_event_que, 0x00, sizeof(g_event_que));
+
+ if (g_srv_thread) {
+ EM_DEBUG_EXCEPTION("service thread is already running...");
+ if (err_code != NULL)
+ *err_code = EMF_ERROR_UNKNOWN;
+ return true;
+ }
+
+ g_event_que_idx = 1;
+ g_event_loop = 1;
+ g_active_que = 0;
+
+ /* initialize lock */
+ INITIALIZE_RECURSIVE_CRITICAL_SECTION(_event_queue_lock);
+ INITIALIZE_RECURSIVE_CRITICAL_SECTION(_event_callback_table_lock);
+
+ em_core_initialize_event_callback_table();
+
+ /* create thread */
+ THREAD_CREATE(g_srv_thread, thread_func_branch_command, NULL, thread_error);
+
+ if (thread_error != 0) {
+ EM_DEBUG_EXCEPTION("cannot create thread");
+ if (err_code != NULL)
+ *err_code = EMF_ERROR_SYSTEM_FAILURE;
+ return FAILURE;
+ }
+
+ if (err_code != NULL)
+ *err_code = EMF_ERROR_NONE;
+
+ return false;
+}
+
+/* finish api event_data loop */
+EXPORT_API int em_core_event_loop_stop(int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ if (err_code != NULL)
+ *err_code = EMF_ERROR_NONE;
+
+ if (!g_srv_thread) {
+ if (err_code != NULL)
+ *err_code = EMF_ERROR_UNKNOWN;
+ return false;
+ }
+
+ /* stop event_data loop */
+ g_event_loop = 0;
+
+ /* pthread_kill(g_srv_thread, SIGINT); */
+ em_core_cancel_thread(g_active_que, NULL, err_code);
+
+ ENTER_CRITICAL_SECTION(_event_available_lock);
+ WAKE_CONDITION_VARIABLE(_event_available_signal);
+ LEAVE_CRITICAL_SECTION(_event_available_lock);
+
+ /* wait for thread finished */
+ THREAD_JOIN(g_srv_thread);
+
+ g_srv_thread = 0;
+
+ DELETE_RECURSIVE_CRITICAL_SECTION(_event_queue_lock);
+ DELETE_CRITICAL_SECTION(_event_available_lock);
+ DELETE_CONDITION_VARIABLE(_event_available_signal);
+ DELETE_RECURSIVE_CRITICAL_SECTION(_event_callback_table_lock);
+
+ g_event_que_idx = 1;
+ g_active_que = 0;
+
+ if (err_code != NULL)
+ *err_code = EMF_ERROR_NONE;
+ EM_DEBUG_FUNC_END();
+ return true;
+}
+
+
+int em_core_get_active_queue_idx()
+{
+ return g_send_active_que;
+}
+
+/* check thread status
+* 0 : stop job 1 : continue job
+*/
+EXPORT_API int em_core_check_thread_status()
+{
+ if (g_active_que <= 0)
+ return true;
+
+ return (g_event_que[g_active_que].status == EMF_EVENT_STATUS_STARTED);
+}
+
+/* cancel a job */
+EXPORT_API int em_core_cancel_thread(int handle, void *arg, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("handle[%d], arg[%p], err_code[%p]", handle, arg, err_code);
+
+ int ret = false;
+ int err = EMF_ERROR_NONE;
+
+ if (handle <= 0 || handle > (EVENT_QUEUE_MAX - 1)) {
+ EM_DEBUG_EXCEPTION("handle[%d], arg[%p]", handle, arg);
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ ENTER_RECURSIVE_CRITICAL_SECTION(_event_queue_lock);
+
+ EM_DEBUG_LOG("status[%d], type[%d], handle[%d]", g_event_que[handle].status, g_event_que[handle].type, handle);
+
+ if (g_event_que[handle].status == EMF_EVENT_STATUS_WAIT) {
+ fail_status_notify(&g_event_que[handle], EMF_ERROR_CANCELLED);
+
+ switch (g_event_que[handle].type) {
+ case EMF_EVENT_SEND_MAIL:
+ case EMF_EVENT_SEND_MAIL_SAVED:
+ EM_DEBUG_LOG("EMF_EVENT_SEND_MAIL or EMF_EVENT_SEND_MAIL_SAVED");
+ _sending_busy_unref();
+ if (!em_storage_notify_network_event(NOTI_SEND_CANCEL, g_event_que[handle].account_id, NULL , g_event_que[handle].event_param_data_4, err))
+ EM_DEBUG_EXCEPTION(" em_storage_notify_network_event [ NOTI_SEND_CANCEL] Failed >>>> ");
+ break;
+ case EMF_EVENT_DOWNLOAD_BODY:
+ EM_DEBUG_LOG("EMF_EVENT_DOWNLOAD_BODY");
+ _receiving_busy_unref();
+ if (!em_storage_notify_network_event(NOTI_DOWNLOAD_BODY_CANCEL, g_event_que[handle].account_id, NULL , g_event_que[handle].event_param_data_4, err))
+ EM_DEBUG_EXCEPTION(" em_storage_notify_network_event [ NOTI_SEND_CANCEL] Failed >>>> ");
+ break;
+
+ case EMF_EVENT_SYNC_HEADER:
+ case EMF_EVENT_SYNC_HEADER_OMA:
+ case EMF_EVENT_DOWNLOAD_ATTACHMENT:
+ case EMF_EVENT_SYNC_MAIL_FLAG_TO_SERVER:
+ case EMF_EVENT_SYNC_FLAGS_FIELD_TO_SERVER:
+ EM_DEBUG_LOG("EMF_EVENT_SYNC_HEADER, EMF_EVENT_DOWNLOAD_ATTACHMENT");
+ _receiving_busy_unref();
+ break;
+
+ case EMF_EVENT_VALIDATE_ACCOUNT:
+ EM_DEBUG_LOG(" validate account waiting : cancel acc id : %d", g_event_que[handle].account_id);
+ _receiving_busy_unref();
+ if (!em_storage_notify_network_event(NOTI_VALIDATE_ACCOUNT_CANCEL, g_event_que[handle].account_id, NULL , g_event_que[handle].event_param_data_4, err))
+ EM_DEBUG_EXCEPTION(" em_storage_notify_network_event [ NOTI_VALIDATE_ACCOUNT_CANCEL] Failed >>>> ");
+ break;
+
+ case EMF_EVENT_DELETE_MAIL:
+ case EMF_EVENT_DELETE_MAIL_ALL:
+ case EMF_EVENT_SYNC_IMAP_MAILBOX:
+ case EMF_EVENT_MOVE_MAIL:
+ case EMF_EVENT_CREATE_MAILBOX:
+ case EMF_EVENT_DELETE_MAILBOX:
+ case EMF_EVENT_SET_MAIL_SLOT_SIZE:
+ EM_DEBUG_LOG("EMF_EVENT_DELETE_MAIL, EMF_EVENT_SYNC_IMAP_MAILBOX");
+ _receiving_busy_unref();
+ break;
+ default:
+ break;
+ }
+ }
+
+ memset(g_event_que+handle, 0x00, sizeof(emf_event_t));
+ g_event_que[handle].status = EMF_EVENT_STATUS_CANCELED;
+
+ LEAVE_RECURSIVE_CRITICAL_SECTION(_event_queue_lock);
+
+ ret = true;
+
+FINISH_OFF:
+ if (err_code != NULL)
+ *err_code = err;
+ EM_DEBUG_FUNC_END();
+ return ret;
+}
+
+EXPORT_API int em_core_cancel_all_threads_of_an_account(int account_id)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int error_code = EMF_ERROR_NONE;
+ int i, event_count = EVENT_QUEUE_MAX, exit_flag = 0, sleep_count = 0;
+
+ for (i = 0 ; i < event_count; i++) {
+ if (g_event_que[i].type && g_event_que[i].status != EMF_EVENT_STATUS_UNUSED) {
+ EM_DEBUG_LOG("There is a live thread. %d", i);
+ if (g_event_que[i].account_id == account_id || g_event_que[i].account_id == ALL_ACCOUNT) {
+ EM_DEBUG_LOG("And it is for account %d", g_event_que[i].account_id);
+ em_core_cancel_thread(i, NULL, &error_code);
+ }
+ }
+ }
+
+ while (exit_flag == 0 && sleep_count < 30) {
+ EM_DEBUG_LOG("Sleeping...");
+ usleep(100000);
+ EM_DEBUG_LOG("Wake up!");
+ sleep_count++;
+ exit_flag = 1;
+ for (i = 0 ; i < event_count; i++) {
+ if (g_event_que[i].type && g_event_que[i].status != EMF_EVENT_STATUS_UNUSED) {
+ EM_DEBUG_LOG("There is still a live thread. %d", i);
+ if (g_event_que[i].account_id == account_id || g_event_que[i].account_id == ALL_ACCOUNT) {
+ EM_DEBUG_LOG("And it is for account %d. So, I should sleep for a while.", g_event_que[i].account_id);
+ exit_flag = 0;
+ }
+ }
+ }
+ }
+
+ EM_DEBUG_LOG("Sleep count %d", sleep_count);
+
+ if (sleep_count >= 30)
+ error_code = EMF_ERROR_CANNOT_STOP_THREAD;
+ else
+ error_code = EMF_ERROR_NONE;
+ EM_DEBUG_FUNC_END();
+ return error_code;
+}
+
+/* check thread status
+* 0 : stop job 1 : continue job
+*/
+EXPORT_API int em_core_check_send_mail_thread_status()
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ if (g_send_active_que <= 0)
+ return true;
+ EM_DEBUG_LOG("g_send_event_que[g_send_active_que[%d]].status[%d]", g_send_active_que, g_send_event_que[g_send_active_que].status);
+ EM_DEBUG_FUNC_END();
+ return (g_send_event_que[g_send_active_que].status == EMF_EVENT_STATUS_STARTED);
+}
+
+
+/* cancel send mail job */
+EXPORT_API int em_core_cancel_send_mail_thread(int handle, void *arg, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("handle[%d], arg[%p], err_code[%p]", handle, arg, err_code);
+
+ int ret = false;
+ int err = EMF_ERROR_NONE;
+
+ if (handle <= 0 || handle > (EVENT_QUEUE_MAX - 1)) {
+ EM_DEBUG_EXCEPTION("handle[%d], arg[%p]", handle, arg);
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ ENTER_RECURSIVE_CRITICAL_SECTION(_send_event_queue_lock);
+
+ EM_DEBUG_LOG("event_data.status[%d], handle[%d]", g_send_event_que[handle].status, handle);
+
+ if (g_send_event_que[handle].status == EMF_EVENT_STATUS_WAIT) {
+ fail_status_notify(&g_send_event_que[handle], EMF_ERROR_CANCELLED);
+
+ switch (g_send_event_que[handle].type) {
+ case EMF_EVENT_SEND_MAIL:
+ case EMF_EVENT_SEND_MAIL_SAVED:
+ _sending_busy_unref();
+ g_send_event_que[handle].status = EMF_EVENT_STATUS_CANCELED;
+ if (!em_storage_notify_network_event(NOTI_SEND_CANCEL, g_send_event_que[handle].account_id, NULL , g_send_event_que[handle].event_param_data_4, err))
+ EM_DEBUG_EXCEPTION(" em_storage_notify_network_event [ NOTI_SEND_CANCEL] Failed >>>> ");
+ break;
+ default:
+ break;
+ }
+ }
+
+ EM_DEBUG_LOG("send_mail_cancel");
+ memset(g_send_event_que+handle, 0x00, sizeof(emf_event_t));
+ g_send_event_que[handle].status = EMF_EVENT_STATUS_CANCELED;
+
+ EM_DEBUG_LOG("event_data.status[%d], handle[%d]", g_send_event_que[handle].status, handle);
+
+
+ LEAVE_RECURSIVE_CRITICAL_SECTION(_send_event_queue_lock);
+
+ ret = true;
+
+FINISH_OFF:
+ if (err_code != NULL)
+ *err_code = err;
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+
+EXPORT_API int em_core_get_receiving_event_queue(emf_event_t **event_queue, int *event_active_queue, int *err)
+{
+ if (event_queue == NULL || event_active_queue == NULL) {
+ EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM event_queue[%p] event_active_queue[%p]", event_queue, event_active_queue);
+
+ if (err)
+ *err = EMF_ERROR_INVALID_PARAM;
+
+ return false;
+ }
+
+ *event_queue = g_event_que;
+ *event_active_queue = g_active_que;
+
+ return true;
+}
+
+EXPORT_API int em_core_free_event(emf_event_t *event_data)
+{
+ EM_DEBUG_FUNC_BEGIN("event_data [%p]", event_data);
+
+ if(event_data) {
+ EM_SAFE_FREE(event_data->event_param_data_1);
+ EM_SAFE_FREE(event_data->event_param_data_2);
+ EM_SAFE_FREE(event_data->event_param_data_3);
+ }
+
+ EM_DEBUG_FUNC_END();
+ return true;
+}
+
+#ifdef _CONTACT_SUBSCRIBE_CHANGE_
+static int g_last_sync_time = 0;
+
+EXPORT_API int em_core_init_last_sync_time(void)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ return em_core_get_last_sync_time();
+}
+
+EXPORT_API int em_core_set_last_sync_time(int sync_time)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int ret;
+
+ if (sync_time == 0)
+ g_last_sync_time = time(NULL);
+ else
+ g_last_sync_time = sync_time;
+
+ ret = vconf_set_int(VCONF_KEY_LAST_SYNC_TIME, g_last_sync_time);
+ if (ret != 0) {
+ EM_DEBUG_EXCEPTION("vconf_set_int() Failed(%d)", ret);
+ }
+
+ return g_last_sync_time;
+}
+
+EXPORT_API int em_core_get_last_sync_time(void)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int ret;
+ if (g_last_sync_time == 0) {
+ ret = vconf_get_int(VCONF_KEY_LAST_SYNC_TIME, &g_last_sync_time);
+ if (ret < 0) {
+ EM_DEBUG_EXCEPTION("vconf_get_int() Failed(%d)", ret);
+ g_last_sync_time = 0;
+ }
+ }
+
+ return g_last_sync_time;
+}
+
+EXPORT_API int em_core_contact_sync_handler()
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ int ret = false;
+ int contact_ret;
+ int err = EMF_ERROR_NONE;
+ CTSiter iter;
+ int type;
+ int change_time;
+ int created_time;
+
+ int contact_index;
+ char *display_name = NULL;
+ CTSstruct *contact = NULL;
+ CTSvalue *base = NULL;
+ CTSvalue *row_info = NULL;
+ CTSvalue *contact_name_value = NULL;
+ GSList *email_list = NULL;
+
+ int last_sync_time = em_core_get_last_sync_time();
+
+ EM_DEBUG_LOG("last_sync_time[%d]", last_sync_time);
+
+ if (em_storage_begin_transaction(NULL, NULL, &err) == false) {
+ EM_DEBUG_EXCEPTION("em_storage_begin_transaction() error[%d]", err);
+ goto FINISH_OFF;
+ }
+
+ if ((err = contacts_svc_get_updated_contacts(0, last_sync_time, &iter)) != CTS_SUCCESS) {
+ EM_DEBUG_EXCEPTION("contacts_svc_get_updated_contacts() error[%d]", err);
+ goto FINISH_OFF;
+ }
+ contact_ret = contacts_svc_iter_next(iter);
+ while (CTS_SUCCESS == contact_ret) {
+ contact = NULL;
+ base = NULL;
+ row_info = NULL;
+ contact_name_value = NULL;
+ email_list = NULL;
+
+ if ((row_info = contacts_svc_iter_get_info(iter)) == NULL) {
+ EM_DEBUG_EXCEPTION("contacts_svc_iter_get_info() failed.");
+ }
+ else { /* sync */
+ contact_index = contacts_svc_value_get_int(row_info, CTS_LIST_CHANGE_ID_INT);
+ type = contacts_svc_value_get_int(row_info, CTS_LIST_CHANGE_TYPE_INT);
+ change_time = contacts_svc_value_get_int(row_info, CTS_LIST_CHANGE_TIME_INT);
+ EM_DEBUG_LOG("Change ID[%d] Type[%d], change_time[%d]", contact_index, type, change_time);
+
+ switch (type) {
+ case CTS_OPERATION_INSERTED:
+ case CTS_OPERATION_UPDATED:
+ EM_DEBUG_LOG("CTS_OPERATION_INSERTED or CTS_OPERATION_TYPE_UPDATED: [%d]", type);
+ if ((err = contacts_svc_get_contact(contact_index, &contact)) < 0) {
+ EM_DEBUG_LOG("contacts_svc_get_contact() failed. err[%d]", err);
+ contacts_svc_iter_remove(iter);
+ goto FINISH_OFF;
+ }
+ if ((err = contacts_svc_struct_get_value(contact, CTS_CF_BASE_INFO_VALUE, &base)) < 0) {
+ EM_DEBUG_LOG("contacts_svc_struct_get_value() failed. CTS_CF_BASE_INFO_VALUE : err[%d]", err);
+ contacts_svc_iter_remove(iter);
+ goto FINISH_OFF;
+ }
+ created_time = contacts_svc_value_get_int(base, CTS_BASE_VAL_CREATED_TIME_INT);
+
+ if ((err = contacts_svc_struct_get_value(contact, CTS_CF_NAME_VALUE, &contact_name_value)) < 0) {
+ EM_DEBUG_LOG("contacts_svc_struct_get_value() failed. CTS_CF_NAME_VALUE err[%d]", err);
+ contacts_svc_iter_remove(iter);
+ goto FINISH_OFF;
+ }
+ em_core_mail_get_display_name(contact_name_value, &display_name);
+
+ err = contacts_svc_struct_get_list(contact, CTS_CF_EMAIL_LIST, &email_list);
+ if (err == CTS_ERR_NO_DATA) {
+ EM_DEBUG_LOG("contacts_svc_struct_get_list() : NO EMAIL LIST");
+ break;
+ }
+ else if (err < 0) {
+ EM_DEBUG_LOG("contacts_svc_struct_get_list() failed. err[%d]", err);
+ contacts_svc_iter_remove(iter);
+ goto FINISH_OFF;
+ }
+
+ /* contact id, display name, email list */
+ /* if (created_time >= last_sync_time) */
+ if (type == CTS_OPERATION_INSERTED) {
+ EM_DEBUG_LOG("Contact Added Time : %d", change_time);
+ if (em_storage_contact_sync_insert(contact_index, display_name, email_list, &err) == false) {
+ EM_DEBUG_LOG("em_storage_contact_sync_insert() failed. err[%d]", err);
+ contacts_svc_iter_remove(iter);
+ goto FINISH_OFF;
+ }
+ }
+ else if (type == CTS_OPERATION_UPDATED) {
+ EM_DEBUG_LOG("Contact Updated Time : %d", change_time);
+ if (em_storage_contact_sync_update(contact_index, display_name, email_list, &err) == false) {
+ EM_DEBUG_LOG("em_storage_contact_sync_update() failed. err[%d]", err);
+ contacts_svc_iter_remove(iter);
+ goto FINISH_OFF;
+ }
+ }
+ contacts_svc_struct_free(contact);
+ contact = NULL;
+ EM_SAFE_FREE(display_name);
+ break;
+ case CTS_OPERATION_DELETED:
+ EM_DEBUG_LOG("CTS_OPERATION_TYPE_DELETED");
+ if (em_storage_contact_sync_delete(contact_index, &err) == false) {
+ EM_DEBUG_LOG("em_storage_contact_sync_delete() failed. err[%d]", err);
+ contacts_svc_iter_remove(iter);
+ goto FINISH_OFF;
+ }
+ break;
+ default:
+ EM_DEBUG_EXCEPTION("Unknown CTS OPERATION [%d]", type);
+ break;
+ }
+ }
+
+ /* Next changing */
+ contacts_svc_value_free(row_info);
+ row_info = NULL;
+ contact_ret = contacts_svc_iter_next(iter);
+ }
+
+ ret = true;
+FINISH_OFF:
+ if (ret == true) {
+ if (em_storage_commit_transaction(NULL, NULL, NULL) == false)
+ ret = false;
+ else
+ em_core_set_last_sync_time(change_time); /* save changed time */
+ }
+ else {
+ em_storage_rollback_transaction(NULL, NULL, NULL);
+ }
+
+ if (row_info != NULL)
+ contacts_svc_value_free(row_info);
+ if (contact != NULL)
+ contacts_svc_struct_free(contact);
+
+ return ret;
+}
+
+#endif /* _CONTACT_SUBSCRIBE_CHANGE_ */
+
+
+
+#ifdef __FEATURE_KEEP_CONNECTION__
+
+EXPORT_API unsigned int em_core_get_receiving_thd_id()
+{
+ return (unsigned int)g_srv_thread;
+}
+
+#endif /* __FEATURE_KEEP_CONNECTION__ */
+
+
+
+#ifdef __FEATURE_PARTIAL_BODY_DOWNLOAD__
+
+EXPORT_API int em_core_get_pbd_thd_state()
+{
+ int pbd_thd_state = false;
+ ENTER_CRITICAL_SECTION(_state_variables_lock);
+ pbd_thd_state = g_pbd_thd_state;
+ LEAVE_CRITICAL_SECTION(_state_variables_lock);
+ return pbd_thd_state;
+}
+
+static int em_core_set_pbd_thd_state(int flag)
+{
+ ENTER_CRITICAL_SECTION(_state_variables_lock);
+ g_pbd_thd_state = flag;
+ LEAVE_CRITICAL_SECTION(_state_variables_lock);
+
+ return g_pbd_thd_state;
+}
+
+EXPORT_API unsigned int em_core_get_partial_body_thd_id()
+{
+ EM_DEBUG_FUNC_BEGIN();
+ EM_DEBUG_FUNC_END();
+ return (unsigned int)g_partial_body_thd;
+}
+
+static int em_core_clear_bulk_pbd_que(int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ int ret = true;
+ int error = EMF_ERROR_NONE;
+ int i = 0;
+
+ for (i = 0; i < BULK_PARTIAL_BODY_DOWNLOAD_COUNT; ++i) {
+ if (g_partial_body_bulk_dwd_que[i].event_type) {
+ if (false == em_core_free_partial_body_thd_event(g_partial_body_bulk_dwd_que + i, &error)) {
+ EM_DEBUG_EXCEPTION("em_core_free_partial_body_thd_event_cell failed [%d]", error);
+ ret = false;
+ break;
+ }
+ }
+ }
+
+ if (NULL != err_code)
+ *err_code = error;
+ EM_DEBUG_FUNC_END();
+ return ret;
+}
+
+static void em_core_pb_thd_set_local_activity_continue(int flag)
+{
+ EM_DEBUG_FUNC_BEGIN("flag [%d]", flag);
+
+ ENTER_CRITICAL_SECTION(_partial_body_thd_event_queue_lock);
+
+ g_pb_thd_local_activity_continue = flag;
+
+ if (true == flag) {
+ WAKE_CONDITION_VARIABLE(_partial_body_thd_cond);
+ }
+
+ LEAVE_CRITICAL_SECTION(_partial_body_thd_event_queue_lock);
+ EM_DEBUG_FUNC_END();
+}
+
+static
+int em_core_pb_thd_can_local_activity_continue()
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ int ret = false;
+
+ ENTER_CRITICAL_SECTION(_partial_body_thd_event_queue_lock);
+
+ ret = g_pb_thd_local_activity_continue;
+
+ LEAVE_CRITICAL_SECTION(_partial_body_thd_event_queue_lock);
+ EM_DEBUG_FUNC_END();
+ return ret;
+
+}
+
+EXPORT_API int em_core_clear_partial_body_thd_event_que(int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ int ret = true;
+ int error = EMF_ERROR_NONE;
+ int i = 0;
+
+ ENTER_CRITICAL_SECTION(_partial_body_thd_event_queue_lock);
+
+ if (true == g_partial_body_thd_queue_empty) {
+ EM_DEBUG_LOG(" Partial Body Thread Event Queue Already empty ");
+ }
+ else {
+ for (i = 0; i < TOTAL_PARTIAL_BODY_EVENTS; ++i) {
+ if (g_partial_body_thd_event_que[i].event_type) {
+ if (false == em_core_free_partial_body_thd_event(g_partial_body_thd_event_que + i, &error)) {
+ EM_DEBUG_EXCEPTION("em_core_free_partial_body_thd_event_cell failed [%d]", error);
+ ret = false;
+ break;
+ }
+ }
+ }
+
+ g_partial_body_thd_queue_empty = true;
+ g_partial_body_thd_queue_full = false;
+ }
+ LEAVE_CRITICAL_SECTION(_partial_body_thd_event_queue_lock);
+
+ if (NULL != err_code)
+ *err_code = error;
+ EM_DEBUG_FUNC_END();
+ return ret;
+}
+
+EXPORT_API int em_core_is_partial_body_thd_que_empty()
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ int ret = false;
+
+ ENTER_CRITICAL_SECTION(_partial_body_thd_event_queue_lock);
+
+ ret = g_partial_body_thd_queue_empty;
+
+ LEAVE_CRITICAL_SECTION(_partial_body_thd_event_queue_lock);
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+EXPORT_API int em_core_is_partial_body_thd_que_full()
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ int ret = false;
+
+ ENTER_CRITICAL_SECTION(_partial_body_thd_event_queue_lock);
+
+ ret = g_partial_body_thd_queue_full;
+
+ LEAVE_CRITICAL_SECTION(_partial_body_thd_event_queue_lock);
+ EM_DEBUG_FUNC_END();
+ return ret;
+}
+
+/*
+Himanshu[h.gahalut] : If either src pointer or dest pointer points to a cell of global partial body thread event_data queue,
+then em_core_copy_partial_body_thd_event API should only be called from a portion of code which is protected
+through _partial_body_thd_event_queue_lock mutex.
+
+No mutex is used inside this API so that we can also use it to copy partial body events which are not a part of global event_data queue
+
+Precautions :
+
+_partial_body_thd_event_queue_lock mutex should never be used inside this API otherwise it will be a deadlock.
+Also never call any function from this API which uses _partial_body_thd_event_queue_lock mutex.
+
+*/
+
+static int em_core_copy_partial_body_thd_event(emf_event_partial_body_thd *src, emf_event_partial_body_thd *dest, int *error_code)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int error = EMF_ERROR_NONE;
+ int ret = false;
+
+ if (NULL == src || NULL == dest) {
+ EM_DEBUG_LOG(" Invalid Parameter src [%p] dest [%p]", src, dest);
+ error = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ dest->account_id = src->account_id;
+ dest->mail_id = src->mail_id;
+ dest->server_mail_id = src->server_mail_id;
+ dest->activity_id = src->activity_id;
+ dest->mailbox_name = EM_SAFE_STRDUP(src->mailbox_name);
+ dest->activity_type = src->activity_type;
+ dest->event_type = src->event_type;
+
+ EM_DEBUG_LOG("dest->account_id[%d], dest->mail_id[%d], dest->server_mail_id [%lu]", dest->account_id, dest->mail_id , dest->server_mail_id);
+
+ ret = true;
+
+ FINISH_OFF:
+
+ if (NULL != error_code)
+ *error_code = error;
+
+ return ret;
+
+}
+
+/*
+Himanshu[h.gahalut] : If em_core_free_partial_body_thd_event_cell API is used to free a cell of partial body thread event_data queue,
+it should only be called from a portion of code which is protected through _partial_body_thd_event_queue_lock mutex.
+
+No mutex is used inside this API so that we can also use it to free partial body events which are not a part of global event_data queue
+
+Precautions :
+
+_partial_body_thd_event_queue_lock mutex should never be used inside this API otherwise it will be a deadlock.
+Also never call any function from this API which uses _partial_body_thd_event_queue_lock mutex.
+
+*/
+
+EXPORT_API int em_core_free_partial_body_thd_event(emf_event_partial_body_thd *partial_body_thd_event, int *error_code)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ if (NULL == partial_body_thd_event) {
+ *error_code = EMF_ERROR_INVALID_PARAM;
+ return false;
+ }
+
+ emf_event_partial_body_thd *pbd_event = partial_body_thd_event;
+
+ /*Free character pointers in event_data cell */
+ EM_SAFE_FREE(pbd_event->mailbox_name);
+ memset(pbd_event, 0x00, sizeof(emf_event_partial_body_thd));
+ EM_DEBUG_FUNC_END();
+ return true;
+}
+
+EXPORT_API int em_core_insert_partial_body_thread_event(emf_event_partial_body_thd *partial_body_thd_event, int *error_code)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ if (NULL == partial_body_thd_event) {
+ EM_DEBUG_EXCEPTION("\t partial_body_thd_event [%p] ", partial_body_thd_event);
+
+ if (error_code != NULL) {
+ *error_code = EMF_ERROR_INVALID_PARAM;
+ }
+ return false;
+ }
+
+ int ret = false;
+ int error = EMF_ERROR_NONE;
+ int empty_cell_index = -1;
+ int index = 0;
+ int count = 0;
+
+ ENTER_CRITICAL_SECTION(_partial_body_thd_event_queue_lock);
+
+ /* find a cell in queue which is empty */
+
+ for (count = 0, index = g_partial_body_thd_next_event_idx; count < TOTAL_PARTIAL_BODY_EVENTS;) {
+ if (g_partial_body_thd_event_que[index].event_type) {
+ ++index;
+ ++count;
+
+ if (index == TOTAL_PARTIAL_BODY_EVENTS) {
+ index = 0;
+ }
+ }
+ else {
+ /*Found empty Cell*/
+
+ empty_cell_index = index;
+ break;
+ }
+ }
+
+ if (-1 != empty_cell_index) {
+ if (false == em_core_copy_partial_body_thd_event(partial_body_thd_event, g_partial_body_thd_event_que+empty_cell_index , &error)) {
+ EM_DEBUG_LOG("em_core_copy_partial_body_thd_event failed [%d]", error);
+ }
+ else {
+ g_partial_body_thd_queue_empty = false;
+
+ if (count == (TOTAL_PARTIAL_BODY_EVENTS - 1)) {
+ /*This is the last event_data inserted in queue after its insertion, queue is full */
+ g_partial_body_thd_queue_full = true;
+
+ }
+
+ WAKE_CONDITION_VARIABLE(_partial_body_thd_cond);
+
+ ret = true;
+ }
+ }
+ else {
+ EM_DEBUG_LOG(" partial body thread event_data queue is full ");
+ error = EMF_ERROR_EVENT_QUEUE_FULL;
+
+ g_partial_body_thd_queue_full = true;
+ g_partial_body_thd_queue_empty = false;
+
+ }
+
+ LEAVE_CRITICAL_SECTION(_partial_body_thd_event_queue_lock);
+
+ if (NULL != error_code) {
+ *error_code = error;
+ }
+
+ return ret;
+
+}
+
+/* h.gahlaut : Return true only if event_data is retrieved successfully */
+
+static int em_core_retrieve_partial_body_thread_event(emf_event_partial_body_thd *partial_body_thd_event, int *error_code)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ int ret = false;
+ int error = EMF_ERROR_NONE;
+ int index = 0;
+
+ /* Lock Mutex to protect event_data queue and associated global variables variables*/
+
+ ENTER_CRITICAL_SECTION(_partial_body_thd_event_queue_lock);
+
+ index = g_partial_body_thd_next_event_idx;
+
+ if (0 == g_partial_body_thd_event_que[index].event_type) {
+ error = EMF_ERROR_EVENT_QUEUE_EMPTY;
+ g_partial_body_thd_queue_empty = true;
+ g_partial_body_thd_queue_full = false;
+ }
+ else {
+ /*Copy the event_data from queue to return it and free the event_data in queue */
+ if (false == em_core_copy_partial_body_thd_event(g_partial_body_thd_event_que + index, partial_body_thd_event, &error))
+ EM_DEBUG_EXCEPTION("em_core_copy_partial_body_thd_event failed [%d]", error);
+ else {
+ if (false == em_core_free_partial_body_thd_event(g_partial_body_thd_event_que + index, &error))
+ EM_DEBUG_EXCEPTION("em_core_free_partial_body_thd_event_cell failed [%d]", error);
+ else {
+
+ g_partial_body_thd_queue_full = false;
+ g_partial_body_thd_next_event_idx = ++index;
+
+ if (g_partial_body_thd_next_event_idx == TOTAL_PARTIAL_BODY_EVENTS)
+ g_partial_body_thd_next_event_idx = 0;
+
+ /* If the event_data retrieved was the only event_data present in queue,
+ we need to set g_partial_body_thd_queue_empty to true
+ */
+
+ if (0 == g_partial_body_thd_event_que[g_partial_body_thd_next_event_idx].event_type) {
+ g_partial_body_thd_queue_empty = true;
+ }
+
+ ret = true;
+ }
+ }
+ }
+
+ /* Unlock Mutex */
+
+ LEAVE_CRITICAL_SECTION(_partial_body_thd_event_queue_lock);
+
+ if (error_code)
+ *error_code = error;
+
+ return ret;
+
+}
+
+gpointer partial_body_download_thread(gpointer data)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ int err = EMF_ERROR_NONE;
+ emf_session_t *session = NULL;
+ emf_event_partial_body_thd partial_body_thd_event;
+
+ EM_DEBUG_LOG(" ************ PB THREAD ID IS ALIVE. ID IS [%d] ********************" , THREAD_SELF());
+
+ /* Open connection with DB */
+
+ if (false == em_storage_open(&err)) {
+ EM_DEBUG_EXCEPTION("em_storage_open failed [%d]", err);
+ return false;
+ }
+
+ /* Start the continuous loop */
+
+ while (g_partial_body_thd_loop) {
+ /* Get an empty session */
+ /* TODO : Mutex should be used in session APIs */
+
+ if (false == em_core_get_empty_session(&session))
+ EM_DEBUG_EXCEPTION("em_core_get_empty_session failed...");
+ else { /* Get and Event from the Partial Body thread Event Queue */
+ memset(&partial_body_thd_event, 0x00, sizeof(emf_event_partial_body_thd));
+
+ if (false == em_core_retrieve_partial_body_thread_event(&partial_body_thd_event, &err)) {
+ if (EMF_ERROR_EVENT_QUEUE_EMPTY != err)
+ EM_DEBUG_EXCEPTION("em_core_retrieve_partial_body_thread_event failed [%d]", err);
+ else {
+ EM_DEBUG_LOG(" partial body thread event_data queue is empty.");
+
+ /* Flush the que before starting local activity sync to clear the events in queue which are less than 10 in count */
+ if (!g_partial_body_bulk_dwd_queue_empty) {
+ partial_body_thd_event.event_type = 0;
+ partial_body_thd_event.account_id = g_partial_body_bulk_dwd_que[0].account_id;
+ partial_body_thd_event.mailbox_name = EM_SAFE_STRDUP(g_partial_body_bulk_dwd_que[0].mailbox_name);
+
+ if (false == em_core_mail_partial_body_download(&partial_body_thd_event, &err))
+ EM_DEBUG_EXCEPTION("em_core_mail_partial_body_download from event_data queue failed [%d]", err);
+
+ em_core_pb_thd_set_local_activity_continue(true);
+ }
+
+ if (true == em_core_pb_thd_can_local_activity_continue()) {
+ /*Check for local Activities */
+ int is_local_activity_event_inserted = false;
+
+ if (false == em_core_partial_body_thd_local_activity_sync(&is_local_activity_event_inserted, &err)) {
+ EM_DEBUG_EXCEPTION("em_core_partial_body_thd_local_activity_sync failed [%d]", err);
+ }
+ else {
+ if (true == is_local_activity_event_inserted) {
+ em_core_pb_thd_set_local_activity_continue(false);
+
+ em_core_clear_session(session);
+ continue;
+ }
+ }
+ }
+
+ EM_DEBUG_LOG(" Partial Body Thread is going to sleep");
+
+ em_core_set_pbd_thd_state(false);
+
+ ENTER_CRITICAL_SECTION(_partial_body_thd_event_queue_lock);
+ SLEEP_CONDITION_VARIABLE(_partial_body_thd_cond, _partial_body_thd_event_queue_lock);
+ LEAVE_CRITICAL_SECTION(_partial_body_thd_event_queue_lock);
+
+ EM_DEBUG_LOG(" Partial Body Thread wakes up ");
+
+ em_core_set_pbd_thd_state(true);
+ }
+
+ }
+ else {
+ EM_DEBUG_LOG(" Event Received from Partial Body Event Queue ");
+
+ /* Since all events are network operations dnet init and sleep control is
+ done before entering switch block*/
+
+ em_storage_dimming_on_off(false, NULL);
+
+ if (!em_core_check_network_status( &err)) {
+ EM_DEBUG_EXCEPTION("em_core_check_network_status failed [%d]", err);;
+ }
+ else {
+ /* Process events */
+ EM_DEBUG_LOG("partial_body_thd_event.account_id[%d]", partial_body_thd_event.account_id);
+
+ switch (partial_body_thd_event.event_type) {
+ case EMF_EVENT_BULK_PARTIAL_BODY_DOWNLOAD: {
+ if (false == em_core_mail_partial_body_download(&partial_body_thd_event, &err)) {
+ EM_DEBUG_EXCEPTION("em_core_mail_partial_body_download from event_data queue failed [%d]", err);
+ }
+ break;
+ }
+ case EMF_EVENT_LOCAL_ACTIVITY_SYNC_BULK_PBD: {
+ partial_body_thd_event.event_type = 0;
+
+ /* Both the checks below make sure that before starting local activity there is no new/pending event_data in
+ * g_partial_body_thd_event_que and g_partial_body_bulk_dwd_que */
+ if (false == em_core_is_partial_body_thd_que_empty())
+ break;
+ if (!g_partial_body_bulk_dwd_queue_empty)
+ break;
+
+ if (false == em_core_mail_partial_body_download(&partial_body_thd_event, &err))
+ EM_DEBUG_EXCEPTION("em_core_mail_partial_body_download from activity table failed [%d]", err);
+ break;
+ }
+ default:
+ EM_DEBUG_EXCEPTION(" Warning : Default case entered. This should not happen ");
+ break;
+ }
+ }
+
+ if (false == em_core_free_partial_body_thd_event(&partial_body_thd_event, &err))
+ EM_DEBUG_EXCEPTION("em_core_free_partial_body_thd_event_cell failed [%d]", err);
+
+ em_storage_dimming_on_off(true, NULL);
+ }
+
+ em_core_clear_session(session);
+ }
+ }
+
+ /* If something is added to end thread in future for any case then if thread is holding any resources
+ define a function em_core_partial_body_thd_loop_stop to release resources and call it
+ here to end thread */
+ return SUCCESS;
+}
+
+EXPORT_API int em_core_partial_body_thread_loop_start(int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ int i = 0, thread_error = -1;
+
+ /* Clear Partial Body Event Queue*/
+ memset(&g_partial_body_thd_event_que, 0x00, sizeof(g_partial_body_thd_event_que));
+
+ for (i = 0; i < TOTAL_PARTIAL_BODY_EVENTS; ++i)
+ g_partial_body_thd_event_que[i].mailbox_name = NULL;
+
+ if (g_partial_body_thd) {
+ EM_DEBUG_EXCEPTION("partial body thread is already running...");
+ if (err_code != NULL)
+ *err_code = EMF_ERROR_UNKNOWN;
+
+ return true;
+ }
+
+ g_partial_body_thd_next_event_idx = 0;
+ g_partial_body_thd_loop = 1;
+ g_partial_body_thd_queue_empty = true;
+ g_partial_body_thd_queue_full = false;
+
+ INITIALIZE_CONDITION_VARIABLE(_partial_body_thd_cond);
+
+ /* create thread */
+ /* THREAD_CREATE_JOINABLE(g_partial_body_thd, partial_body_download_thread, thread_error); */
+ THREAD_CREATE(g_partial_body_thd, partial_body_download_thread, NULL, thread_error);
+
+ if (thread_error != 0) {
+ EM_DEBUG_EXCEPTION("cannot make thread...");
+ if (err_code != NULL)
+ *err_code = EMF_ERROR_UNKNOWN;
+ return FAILURE;
+ }
+
+ if (err_code != NULL)
+ *err_code = EMF_ERROR_NONE;
+
+ return false;
+
+}
+
+/*Function to flush the bulk partial body download queue [santosh.br@samsung.com]*/
+static int em_core_partial_body_bulk_flush(int *error_code)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int error = EMF_ERROR_NONE;
+ int ret = false;
+ MAILSTREAM *stream = NULL;
+ void *tmp_stream = NULL;
+
+ if (!em_core_mailbox_open(g_partial_body_bulk_dwd_que[0].account_id, g_partial_body_bulk_dwd_que[0].mailbox_name, (void **)&tmp_stream, &error) || (NULL == tmp_stream)) {
+ EM_DEBUG_EXCEPTION("em_core_mailbox_open failed [%d]", error);
+ goto FINISH_OFF;
+ }
+ stream = (MAILSTREAM *)tmp_stream;
+
+ /* Call bulk download here */
+ if (false == em_core_bulk_partial_mailbody_download(stream, g_partial_body_bulk_dwd_que, g_partial_body_bulk_dwd_next_event_idx, &error)) {
+ EM_DEBUG_EXCEPTION(" em_core_bulk_partial_mailbody_download failed.. [%d]", error);
+ goto FINISH_OFF;
+ }
+
+ ret = true;
+FINISH_OFF:
+
+ em_core_mailbox_close(0, stream);
+ stream = NULL;
+
+ g_partial_body_bulk_dwd_next_event_idx = 0;
+ g_partial_body_bulk_dwd_queue_empty = true;
+
+ if (false == em_core_clear_bulk_pbd_que(&error))
+ EM_DEBUG_EXCEPTION("em_core_clear_bulk_pbd_que failed [%d]", error);
+
+ if (NULL != error_code)
+ *error_code = error;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+
+/* Function to pass UID list and Data for bulk partial body download [santosh.br@samsung.com]/[h.gahlaut@samsung.com] */
+EXPORT_API int em_core_mail_partial_body_download(emf_event_partial_body_thd *pbd_event, int *error_code)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int error = EMF_ERROR_NONE;
+ int num_activity = 0;
+ int ret = false;
+ int count = 0;
+ int i = 0, m = 0;
+ MAILSTREAM *stream = NULL;
+ void *tmp_stream = NULL;
+ emf_event_partial_body_thd *activity_data_list = NULL;
+ char **mailbox_list = NULL;
+
+ if (NULL == pbd_event)
+ {
+ EM_DEBUG_EXCEPTION("Invalid Parameter pbd_event [%p] ", pbd_event);
+
+ error = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ /*Check if the event_data is to flush the event_data que array */
+ if (EMF_EVENT_BULK_PARTIAL_BODY_DOWNLOAD == pbd_event->event_type) {
+ EM_DEBUG_LOG("pbd_event->event_type is EMF_EVENT_BULK_PARTIAL_BODY_DOWNLOAD");
+ /*Check if the mailbox name and account id for this event_data is same as the mailbox name and account id for earlier events saved in download que array
+ then append this event_data also to download que array */
+ if ((NULL != g_partial_body_bulk_dwd_que[0].mailbox_name) && (0 == strncmp(g_partial_body_bulk_dwd_que[0].mailbox_name, pbd_event->mailbox_name, strlen(g_partial_body_bulk_dwd_que[0].mailbox_name))) && \
+ (g_partial_body_bulk_dwd_que[0].account_id == pbd_event->account_id)) {
+ EM_DEBUG_LOG("Event is for the same mailbox and same account as the already present events in download que");
+ EM_DEBUG_LOG("Check if the download que reached its limit. If yes then first flush the que.");
+ if (g_partial_body_bulk_dwd_next_event_idx == BULK_PARTIAL_BODY_DOWNLOAD_COUNT) {
+ if (false == em_core_partial_body_bulk_flush(&error)) {
+ EM_DEBUG_EXCEPTION("Partial Body thread em_core_partial_body_bulk_flush failed - %d", error);
+ goto FINISH_OFF;
+ }
+ }
+ }
+ else {
+ EM_DEBUG_LOG("Event is not for the same mailbox and same account as the already present events in download que");
+ EM_DEBUG_LOG("Flush the current que if not empty");
+ EM_DEBUG_LOG("g_partial_body_bulk_dwd_queue_empty [%d]", g_partial_body_bulk_dwd_queue_empty);
+ if (!g_partial_body_bulk_dwd_queue_empty) {
+ if (false == em_core_partial_body_bulk_flush(&error)) {
+ EM_DEBUG_EXCEPTION("Partial Body thread em_core_partial_body_bulk_flush failed - %d", error);
+ goto FINISH_OFF;
+ }
+ }
+ }
+ /*Add the event_data to the download que array */
+ if (false == em_core_copy_partial_body_thd_event(pbd_event, g_partial_body_bulk_dwd_que+(g_partial_body_bulk_dwd_next_event_idx), &error))
+ EM_DEBUG_EXCEPTION("\t Partial Body thread em_core_copy_partial_body_thd_event failed - %d", error);
+ else {
+ g_partial_body_bulk_dwd_queue_empty = false;
+ g_partial_body_bulk_dwd_next_event_idx++;
+ EM_DEBUG_LOG("g_partial_body_bulk_dwd_next_event_idx [%d]", g_partial_body_bulk_dwd_next_event_idx);
+ }
+ }
+ else if (pbd_event->activity_type) {
+ int *account_list = NULL;
+ int account_count = 0;
+
+ EM_DEBUG_LOG("Event is coming from local activity.");
+ /* Get all the accounts for which local activities are pending */
+ if (false == em_storage_get_pbd_account_list(&account_list, &account_count, false, &error)) {
+ EM_DEBUG_EXCEPTION(" em_storage_get_mailbox_list failed.. [%d]", error);
+ error = EMF_ERROR_MAILBOX_NOT_FOUND;
+ goto FINISH_OFF;
+ }
+
+ for (m = 0; m < account_count; ++m) {
+ /* Get the mailbox list for the account to start bulk partial body fetch for mails in each mailbox of accounts one by one*/
+ if (false == em_storage_get_pbd_mailbox_list(account_list[m], &mailbox_list, &count, false, &error)) {
+ EM_DEBUG_EXCEPTION(" em_storage_get_mailbox_list failed.. [%d]", error);
+ error = EMF_ERROR_MAILBOX_NOT_FOUND;
+ goto FINISH_OFF;
+ }
+
+ for (i = 0; i < count; i++) {
+ int k = 0;
+ int activity_count = 0;
+
+ if (!em_core_mailbox_open(account_list[m], mailbox_list[i], (void **)&tmp_stream, &error)) {
+ EM_DEBUG_EXCEPTION("em_core_mailbox_open failed [%d]", error);
+ stream = NULL;
+ goto FINISH_OFF;
+ }
+
+ stream = (MAILSTREAM *)tmp_stream;
+
+ if (false == em_storage_get_mailbox_pbd_activity_count(account_list[m], mailbox_list[i], &activity_count, false, &error)) {
+ EM_DEBUG_EXCEPTION(" em_storage_get_mailbox_pbd_activity_count failed.. [%d]", error);
+ continue;
+ }
+
+ if (activity_count > 0) {
+ int temp_error = EMF_ERROR_NONE;
+ int j = 0;
+ int iter = 0;
+ int remainder = 0;
+ int num = BULK_PARTIAL_BODY_DOWNLOAD_COUNT;
+ int index = 0;
+
+ if (false == em_storage_get_pbd_activity_data(account_list[j], mailbox_list[i], &activity_data_list, &num_activity, false, &error))
+ EM_DEBUG_EXCEPTION(" em_storage_get_pbd_activity_data failed.. [%d]", error);
+
+ if (NULL == activity_data_list) {
+ EM_DEBUG_EXCEPTION(" activity_data_list is null..");
+ continue;
+ }
+
+ remainder = num_activity%BULK_PARTIAL_BODY_DOWNLOAD_COUNT;
+ iter = num_activity/BULK_PARTIAL_BODY_DOWNLOAD_COUNT + ((num_activity%BULK_PARTIAL_BODY_DOWNLOAD_COUNT) ? 1 : 0);
+
+ for (j = 0; j < iter; j++) {
+ if ((iter == (j+1)) && (remainder != 0))
+ num = remainder;
+
+ /*Call bulk download here */
+ if (false == em_core_bulk_partial_mailbody_download(stream, activity_data_list+index, num, &error)) {
+ EM_DEBUG_EXCEPTION(" em_core_bulk_partial_mailbody_download failed.. [%d]", error);
+ temp_error = EMF_ERROR_NO_RESPONSE;
+ }
+
+ for (k = 0; k < num; k++) {
+ if (activity_data_list[index + k].activity_type)
+ em_core_free_partial_body_thd_event(activity_data_list + index + k, &error);
+ else
+ break;
+ }
+ index += num;
+
+ if (false == em_core_is_partial_body_thd_que_empty()) {
+ ret = true;
+ goto FINISH_OFF; /* Stop Local Activity Sync */
+ }
+ if (EMF_ERROR_NO_RESPONSE == temp_error) {
+ temp_error = EMF_ERROR_NONE;
+ break;
+ }
+ }
+ }
+ }
+ em_core_mailbox_close(0, stream);
+ stream = NULL;
+ tmp_stream = NULL;
+ }
+
+ /* After completing one cycle of local activity sync ,
+ local activity continue variable should be set to false. */
+
+ em_core_pb_thd_set_local_activity_continue(false);
+ }
+ else /* Event-type is 0 which means Event is to flush the que when no more events are present in g_partial_body_thd_event_que */ {
+ /*Check if events have arrived in g_partial_body_thd_event_que */
+ if (false == em_core_is_partial_body_thd_que_empty()) {
+ EM_DEBUG_LOG("em_core_is_partial_body_thd_que_empty retured true");
+ ret = true;
+ goto FINISH_OFF; /* Stop Local Activity Sync */
+ }
+ if (false == em_core_partial_body_bulk_flush(&error)) {
+ EM_DEBUG_EXCEPTION("\t Partial Body thread em_core_partial_body_bulk_flush failed - %d", error);
+ goto FINISH_OFF;
+ }
+ }
+
+ ret = true;
+
+FINISH_OFF:
+
+ if (mailbox_list) {
+ for (i = 0; i < count; i++)
+ EM_SAFE_FREE(mailbox_list[i]);
+ EM_SAFE_FREE(mailbox_list);
+ }
+
+ if (activity_data_list) {
+ for (i = 0; i < num_activity; i++) {
+ if (activity_data_list[i].activity_type)
+ em_core_free_partial_body_thd_event(activity_data_list + i, &error);
+ else
+ break;
+ }
+ }
+
+ em_core_mailbox_close(0, stream);
+ stream = NULL;
+
+ if (NULL != error_code)
+ *error_code = error;
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+#endif /* __FEATURE_PARTIAL_BODY_DOWNLOAD__ */
diff --git a/email-core/em-core-global.c b/email-core/em-core-global.c
new file mode 100755
index 0000000..b4d522f
--- /dev/null
+++ b/email-core/em-core-global.c
@@ -0,0 +1,53 @@
+/*
+* email-service
+*
+* Copyright (c) 2000 - 2011 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.
+*
+*/
+
+
+
+/******************************************************************************
+ * File : em-core-global.c
+ * Desc : Mail Engine Global
+ *
+ * Auth : Kyuho Jo
+ *
+ * History :
+ * 2010.08.25 : created
+ *****************************************************************************/
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "emf-types.h"
+
+
+
+emf_account_t g_new_account;
+emf_account_list_t *g_account_list = NULL;
+int g_account_num = 0;
+int g_account_retrieved = 0;
+
+EXPORT_API emf_account_t *em_core_account_get_new_account_ref()
+{
+ return &g_new_account;
+}
+
+
+
+
+
diff --git a/email-core/em-core-imap-idle.c b/email-core/em-core-imap-idle.c
new file mode 100755
index 0000000..2d06c9a
--- /dev/null
+++ b/email-core/em-core-imap-idle.c
@@ -0,0 +1,648 @@
+/*
+* email-service
+*
+* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+*
+* Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com>
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*
+*/
+
+/**
+ *
+ * This file contains functinality related to IMAP IDLE.
+ * to interact with Email Engine.
+ * @file em_core-imap-idle.c
+ * @author
+ * @version 0.1
+ * @brief This file contains functionality to provide IMAP IDLE support in email-service.
+ */
+
+#include <em-core-types.h>
+
+#ifdef _FEATURE_IMAP_IDLE
+#include <pthread.h>
+#include <glib.h>
+#include <openssl/ssl.h>
+#include "c-client.h"
+#include "lnx_inc.h"
+#include "em-core-imap-idle.h"
+#include "emf-dbglog.h"
+#include "em-storage.h"
+#include "em-network.h"
+#include "em-core-utils.h"
+#include "em-core-mailbox.h"
+#include "em-core-event.h"
+#include "em-core-account.h"
+
+static int idle_pipe[2] = {0, 0};
+
+static int wait_on_pipe(int *pipe_fd)
+{
+ fd_set rfds;
+ fd_set wfds;
+ struct timeval timeout_value;
+ int ret_value;
+
+ FD_ZERO(&rfds);
+ FD_ZERO(&wfds);
+ FD_SET(pipe_fd[0], &rfds);
+
+ EM_DEBUG_LOG("wait...till dnet fills some data in pipe - %d", pipe_fd[0]);
+
+ /* timeout_value.tv_sec = 10; */ /* 10 seconds. */
+ timeout_value.tv_sec = 180; /* 160 + a seconds. */
+ timeout_value.tv_usec = 0;
+ EM_DEBUG_LOG("wait_on_pipe() : timeout_value (%d) sec, (%d) usec", timeout_value.tv_sec, timeout_value.tv_usec);
+
+ ret_value = select(pipe_fd[0]+1, &rfds, &wfds, NULL, &timeout_value);
+
+ switch (ret_value){
+ case 0:
+ EM_DEBUG_LOG("wait_on_pipe() : select timer expired!!! ");
+ break;
+ case -1:
+ EM_DEBUG_LOG("wait_on_pipe() : There is an error on calling select. ");
+ break;
+ default:
+ EM_DEBUG_LOG("wait_on_pipe() : got response from DNET. ");
+ break;
+ }
+
+ return ret_value;
+}
+
+static int read_from_pipe(int *pipe_fd)
+{
+ int activation = 0;
+
+ read(pipe_fd[0], &activation, sizeof(int));
+
+ return activation;
+}
+
+static void write_to_pipe(int *pipe_fd, int result)
+{
+ write(pipe_fd[1], (char *)&result, sizeof(int));
+}
+
+
+static void _idle_thread_cm_evt_cb(const NetEventInfo_t *event)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ /* This callback will be called when any event is recd from datacom */
+
+ switch (event->Event) {
+ /* Response from Datacom for PDP Activation Request */
+ case NET_EVENT_OPEN_RSP:
+ if (event->Error == NET_ERR_NONE) { /* Successful PDP Activation */
+ EM_DEBUG_LOG("\t IMAP IDLE Successful PDP Activation");
+
+ NetDevInfo_t devInfo;
+ memset(&devInfo, 0x00, sizeof(devInfo));
+
+ if (net_get_device_info(&devInfo) != NET_ERR_NONE)
+ EM_DEBUG_EXCEPTION("\t net_get_device_info failed - %d", event->Error);
+ write_to_pipe(idle_pipe, 1);
+ }
+ else { /* PDP Activation failure */
+ EM_DEBUG_EXCEPTION("\t PDP Activation Failure %d", event->Error);
+ write_to_pipe(idle_pipe, 0);
+ }
+ break;
+
+ /* Response from Datacom for PDP Dectivation Request */
+ case NET_EVENT_CLOSE_RSP:
+ if (event->Error == NET_ERR_NONE) { /* Successful PDP Dectivation */
+ EM_DEBUG_LOG("\t Successful PDP DeActivation");
+
+ write_to_pipe(idle_pipe, 1);
+ }
+ else { /* PDP Dectivation failure */
+ EM_DEBUG_EXCEPTION("\t PDP DeActivation Failure %d", event->Error);
+
+ if (event->Error == NET_ERR_TRANSPORT)
+ {
+ /* TODO : add a process to deal an error */
+ /* NetCMGetTransportError(&err_code); */
+ }
+
+ write_to_pipe(idle_pipe, 0);
+ }
+ break;
+
+ case NET_EVENT_CLOSE_IND:
+ EM_DEBUG_LOG("NET_EVENT_CLOSE_IND recieved");
+ break;
+
+ case NET_EVENT_KILL_RSP:
+ break;
+
+ case NET_EVENT_SUSPEND_IND:
+ /* TODO */
+ /* think over what can we do... */
+ break;
+
+ case NET_EVENT_RESUME_IND:
+ /* TODO */
+ /* think over what can we do... */
+ break;
+
+ default:
+ break;
+ }
+}
+
+
+/*Definitions copied temperorily from ssl_unix.c */
+#define SSLBUFLEN 8192
+
+typedef struct ssl_stream {
+ TCPSTREAM *tcpstream; /* TCP stream */
+ SSL_CTX *context; /* SSL context */
+ SSL *con; /* SSL connection */
+ int ictr; /* input counter */
+ char *iptr; /* input pointer */
+ char ibuf[SSLBUFLEN]; /* input buffer */
+} SSLSTREAM;
+/*Definitions copied temperorily from ssl_unix.c - end*/
+
+thread_t imap_idle_thread = NULL;
+int g_imap_idle_thread_alive = 0;
+
+
+int em_core_imap_idle_thread_create(int accountID, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int ret = false;
+ int thread_error = -1;
+
+#ifdef ENABLE_IMAP_IDLE_THREAD
+
+ g_imap_idle_thread_alive = 1;
+ THREAD_CREATE(imap_idle_thread, em_core_imap_idle_run, NULL, thread_error);
+ if (thread_error != 0)
+ {
+ EM_DEBUG_EXCEPTION("cannot make IMAP IDLE thread...");
+ if (err_code != NULL)
+ *err_code = EMF_ERROR_UNKNOWN;
+ g_imap_idle_thread_alive = 0;
+ goto FINISH_OFF;
+ }
+
+ ret = true;
+FINISH_OFF:
+
+#else /* ENABLE_IMAP_IDLE_THREAD */
+ EM_DEBUG_LOG(">>>>>>>> DISABLED IMAP IDLE THREAD");
+#endif /* ENABLE_IMAP_IDLE_THREAD */
+
+ return ret;
+}
+
+/*
+Need to identify various scenarios where thread needs to be killed
+1. After the timer set to 10 min expires.
+2. When No sim, thread is created and em_core_check_network_status() fails.
+*/
+int em_core_imap_idle_thread_kill(int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int ret = true;
+ int err = EMF_ERROR_NONE;
+
+ EM_DEBUG_LOG(">>>>>>>>>>>>killing thread>>>>>>>>>");
+
+ /* kill the thread */
+ EM_DEBUG_LOG(">>>>>>>>>Before g_thread_exit");
+ g_imap_idle_thread_alive = 0;
+ EM_DEBUG_LOG(">>>>>>>>>After g_thread_exit");
+
+ EM_DEBUG_LOG(">>>>>>>>>>>>>>>>>> Making imap idle NULL>>>>>>>>>>>>>>>>>");
+ imap_idle_thread = NULL;
+ EM_DEBUG_LOG(">>>>>>>>>>>>>>>>>> killed IMAP IDLE >>>>>>>>>>>>>>>>>");
+ if (err_code)
+ *err_code = err;
+ return ret;
+}
+
+
+
+int em_core_imap_idle_run(int accountID)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ char *mailbox_list[3]; /* Temperory - To be modified to char ***/
+ int mailbox_num = 0;
+ emf_mailbox_t *mail_box_list = NULL;
+ emf_mailbox_t *curr_mailbox = NULL;
+ emf_mailbox_t *prev_mailbox = NULL;
+ int counter = 0;
+ emf_mailbox_tbl_t *local_mailbox = NULL;
+ int err = EMF_ERROR_NONE;
+ int flag = true;
+ int num = 0;
+ emf_session_t *session = NULL;
+ int ret = false;
+
+ if ( !em_core_check_network_status(&err)) {
+ EM_DEBUG_EXCEPTION("em_core_check_network_status failed [%d]", err);
+ return ret;
+ }
+ /* Connect to DB */
+ if (!em_storage_open(&err)) {
+ EM_DEBUG_EXCEPTION("\t em_storage_open falied - %d", err);
+ goto FINISH_OFF;
+ }
+
+ if (!em_core_get_empty_session(&session))
+ EM_DEBUG_EXCEPTION("\t em_core_get_empty_session failed...");
+
+ /* get the list of mailbox name on which IDLE notifications are required. */
+ /* currently all INBOXES of all accounts need to be notified */
+ /* Dependent on GetMyIdentities for account names */
+
+ /* For testing - mailbox_num and mailbox_list are hardcoded here */
+ mailbox_num = 1;
+ mailbox_list[0] = EM_SAFE_STRDUP("INBOX");
+
+ /* make a list of mailboxes IDLING */
+ for (counter = 0; counter < mailbox_num; counter++){
+ EM_DEBUG_EXCEPTION(">>>> em_core_imap_idle_run 4 ");
+ if (!em_storage_get_mailbox_by_name(accountID, 0, mailbox_list[counter], &local_mailbox, true, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_get_mailbox_by_name failed - %d", err);
+ }
+
+ else {
+ curr_mailbox = em_core_malloc(sizeof(emf_mailbox_t));
+
+ curr_mailbox->account_id = local_mailbox->account_id;
+ curr_mailbox->name = EM_SAFE_STRDUP(local_mailbox->mailbox_name);
+ curr_mailbox->local = local_mailbox->local_yn;
+ if (!em_core_imap_idle_connect_and_idle_on_mailbox(curr_mailbox, &err)) {
+ EM_DEBUG_EXCEPTION("em_core_imap_idle_connect_and_idle_on_mailbox failed - %d", err);
+ em_core_mailbox_free(&curr_mailbox, 1, NULL);
+ }
+ else {
+ if (flag) {
+ mail_box_list = curr_mailbox;
+ prev_mailbox = curr_mailbox;
+ flag = false;
+ num++;
+ }
+
+ else {
+ prev_mailbox->next = curr_mailbox;
+ prev_mailbox = curr_mailbox;
+ num++;
+ }
+
+ }
+
+ }
+ if (local_mailbox != NULL)
+ em_storage_free_mailbox(&local_mailbox, 1, NULL);
+
+ }
+
+ em_core_clear_session(session);
+
+ em_core_imap_idle_loop_start(mail_box_list, num, NULL);
+
+ EM_DEBUG_EXCEPTION("IMAP IDLE ");
+
+ ret = true;
+FINISH_OFF:
+ if (!em_storage_close(&err)) {
+ EM_DEBUG_EXCEPTION("\t em_storage_close falied - %d", err);
+ }
+
+ return ret;
+
+}
+
+int em_core_imap_idle_loop_start(emf_mailbox_t *mailbox_list, int num, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ fd_set readfds;
+ int maxfd = 0;
+ int err = EMF_ERROR_NONE;
+ int counter = 0;
+ int select_result = 0;
+ int ret = false;
+ emf_mailbox_t *temp = NULL;
+ struct timeval timeout;
+
+ EM_DEBUG_EXCEPTION(">>>>>>> em_core_imap_idle_loop_start start ");
+ if (!mailbox_list || !num) {
+ EM_DEBUG_EXCEPTION("\t mailbox_list[%p], num[%d]", mailbox_list, num);
+
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ /* set timeout value to 10min */
+ timeout.tv_sec = 10 * 60;
+ timeout.tv_usec = 0;
+
+ /* IMAP IDLE LOOP */
+ while (1){
+ EM_DEBUG_EXCEPTION(">>>>>>>>>>>IDLING>>>>>>>>>>>>");
+ FD_ZERO(&readfds);
+ temp = mailbox_list;
+ for (counter = 0; counter < num; counter++) {
+ FD_SET(temp->hold_connection, &readfds);
+ if (temp->hold_connection > maxfd)
+ maxfd = temp->hold_connection;
+ temp = temp->next;
+ }
+ maxfd++;
+ temp = mailbox_list;
+
+ select_result = select(maxfd, &readfds, NULL, NULL, &timeout);
+
+ if (select_result > 0) /* Data coming on some socket */ {
+ EM_DEBUG_EXCEPTION(">>>> Data Coming from Socket ");
+ for (counter = 0; counter < num; counter++) {
+ if (temp && FD_ISSET(temp->hold_connection, &readfds)) {
+ if (!em_core_imap_idle_parse_response_stream(temp, &err)) {
+ EM_DEBUG_EXCEPTION(">>>> em_core_imap_idle_loop_start 6 ");
+ em_core_mailbox_close(temp->account_id, temp->mail_stream);
+ EM_DEBUG_EXCEPTION(">>>> em_core_imap_idle_loop_start 7 ");
+ goto FINISH_OFF;
+ }
+ break; /* break for now - check if it is possible to get data on two sockets - shasikala.p */
+ }
+ temp = temp->next;
+ }
+ }
+
+ else if (select_result == 0) /* Timeout occured */ {
+ EM_DEBUG_EXCEPTION(">>>> em_core_imap_idle_loop_start 8 ");
+ IMAPLOCAL *imap_local = NULL;
+ char cmd[128], tag[32];
+ char *p = NULL;
+ /* send DONE Command */
+ /* free all data here */
+ for (counter = 0; counter < num; counter++) {
+ EM_DEBUG_LOG(">>>> em_core_imap_idle_loop_start 9 ");
+ if (temp && temp->mail_stream) {
+ imap_local = ((MAILSTREAM *)temp->mail_stream)->local;
+
+ sprintf(tag, "%08lx", 0xffffffff & (((MAILSTREAM *)temp->mail_stream)->gensym++));
+ sprintf(cmd, "%s DONE\015\012", tag);
+
+ if (!imap_local->netstream || !net_sout(imap_local->netstream, cmd, (int)strlen(cmd)))
+ {
+ EM_DEBUG_EXCEPTION("network error - failed to DONE on Mailbox - %s ", temp->name);
+ }
+ else {
+ while (imap_local->netstream) {
+ p = net_getline(imap_local->netstream);
+ EM_DEBUG_EXCEPTION("p =[%s]", p);
+ em_core_mailbox_close(temp->account_id, temp->mail_stream);
+ break;
+ }
+ }
+ }
+
+ temp = temp->next;
+ }
+
+
+ /* kill idle thread */
+ em_core_imap_idle_thread_kill(&err);
+ break;
+ }
+
+ else {
+ /*
+ might happen that a socket desciptor passed to select got closed
+ chack which got closed and make hold_connection 0
+ */
+ EM_DEBUG_EXCEPTION(">>>>>> socket desciptor error : No Data ");
+ break;
+ }
+
+ select_result = 0;
+ }
+
+ ret = true;
+
+ EM_DEBUG_LOG(">>>> em_core_imap_idle_loop_start 17 ");
+FINISH_OFF:
+ if (err_code)
+ *err_code = err;
+ EM_DEBUG_EXCEPTION(">>>>>>> em_core_imap_idle_loop_start End ");
+ return ret;
+}
+
+
+int em_core_imap_idle_insert_sync_event(emf_mailbox_t *mailbox, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ int ret = false;
+ int err = EMF_ERROR_NONE;
+ int handle;
+
+ if (!mailbox || mailbox->account_id <= 0) {
+ EM_DEBUG_LOG("\t mailbox[%p]", mailbox);
+
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+ emf_event_t event_data;
+ memset(&event_data, 0x00, sizeof(emf_event_t));
+
+ event_data.type = EMF_EVENT_SYNC_HEADER;
+ event_data.event_param_data_1 = mailbox ? EM_SAFE_STRDUP(mailbox->name) : NULL;
+ event_data.event_param_data_3 = NULL;
+ event_data.account_id = mailbox->account_id;
+
+ if (!em_core_insert_event(&event_data, &handle, &err)) {
+ EM_DEBUG_LOG("\t em_core_insert_event falied - %d", err);
+
+ /* err = EMF_ERROR_DB_FAILURE; */
+ goto FINISH_OFF;
+ }
+
+ ret = true;
+FINISH_OFF:
+ if (err_code)
+ *err_code = err;
+
+ return ret;
+}
+
+/* connects to given mailbox. send idle and returns socket id */
+int em_core_imap_idle_connect_and_idle_on_mailbox(emf_mailbox_t *mailbox, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ void *mail_stream = NULL;
+ char cmd[128], tag[32], *p;
+ int socket_id = 0;
+ int ret = 0;
+ int err = EMF_ERROR_NONE;
+ emf_account_t *ref_account = NULL;
+
+ /* NULL param check */
+ if (!mailbox) {
+ EM_DEBUG_EXCEPTION("\t mailbox[%p]", mailbox);
+ if (err_code)
+ *err_code = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ ref_account = em_core_get_account_reference(mailbox->account_id);
+ if (!ref_account) {
+ EM_DEBUG_EXCEPTION("\t em_core_get_account_reference failed - %d", mailbox->account_id);
+
+ err = EMF_ERROR_INVALID_ACCOUNT;
+ goto FINISH_OFF;
+ }
+
+ /* Open connection to mailbox */
+ if (!em_core_mailbox_open(mailbox->account_id, mailbox->name, (void **)&mail_stream, &err) || !mail_stream) {
+ EM_DEBUG_EXCEPTION("\t em_core_mailbox_open failed - %d", err);
+ if (err_code)
+ *err_code = err;
+ goto FINISH_OFF;
+ }
+
+ IMAPLOCAL *imap_local = ((MAILSTREAM *)mail_stream)->local;
+ NETSTREAM *net_stream = imap_local->netstream;
+
+ /* check if ssl option is enabled on this account - shasikala.p */
+ TCPSTREAM *tcp_stream = NULL;
+ if (ref_account->use_security){
+ SSLSTREAM *ssl_stream = net_stream->stream;
+ tcp_stream = ssl_stream->tcpstream;
+ }
+ else{
+ tcp_stream = net_stream->stream;
+ }
+
+ /* Get Socket ID */
+ socket_id = ((TCPSTREAM *)tcp_stream)->tcpsi;
+
+ sprintf(tag, "%08lx", 0xffffffff & (((MAILSTREAM *)mail_stream)->gensym++));
+ sprintf(cmd, "%s IDLE\015\012", tag);
+
+ /* Send IDLE command */
+ if (!imap_local->netstream || !net_sout(imap_local->netstream, cmd, (int)strlen(cmd)))
+ {
+ EM_DEBUG_EXCEPTION("network error - failed to IDLE on Mailbox - %s ", mailbox->name);
+ if (err_code)
+ *err_code = EMF_ERROR_IMAP4_IDLE_FAILURE;
+ goto FINISH_OFF;
+ }
+
+ /* Get the response for IDLE command */
+ while (imap_local->netstream){
+ p = net_getline(imap_local->netstream);
+ EM_DEBUG_LOG("p =[%s]", p);
+ if (!strncmp(p, "+", 1)) {
+ ret = 1;
+ break;
+ }
+ else if (!strncmp(p, "*", 1)) {
+ EM_SAFE_FREE(p);
+ continue;
+ }
+ else {
+ ret = 0;
+ break;
+ }
+ }
+ EM_SAFE_FREE(p); /* Prevent Defect - 18815 */
+
+FINISH_OFF:
+
+ if (ret) /* IMAP IDLE - SUCCESS */{
+ mailbox->mail_stream = mail_stream;
+ mailbox->hold_connection = socket_id; /* holds connection continuosly on the given socket_id */
+ }
+ else
+ if (mail_stream) em_core_mailbox_close(mailbox->account_id, mail_stream);
+ return ret;
+}
+
+
+int em_core_imap_idle_parse_response_stream(emf_mailbox_t *mailbox, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int err = EMF_ERROR_NONE;
+ char *p = NULL;
+ int ret = false;
+
+ /* NULL PARAM CHECK */
+ if (!mailbox) {
+ EM_DEBUG_EXCEPTION("\t mailbox[%p]", mailbox);
+ if (err_code)
+ *err_code = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ IMAPLOCAL *imap_local = NULL;
+
+ if (!mailbox->mail_stream){
+ EM_DEBUG_EXCEPTION("mail_stream is NULL");
+ goto FINISH_OFF;
+ }
+
+ imap_local = ((MAILSTREAM *)mailbox->mail_stream)->local;
+
+ if (!imap_local){
+ EM_DEBUG_EXCEPTION("imap_local is NULL");
+ goto FINISH_OFF;
+ }
+
+
+ while (imap_local->netstream){
+ p = net_getline(imap_local->netstream);
+ if (p && !strncmp(p, "*", 1)) {
+ EM_DEBUG_LOG("p is [%s]", p);
+ if (p+1 && p+2 && p+3 && p+4 && !strncmp(p+2, "BYE", 3)) {
+ EM_DEBUG_LOG("BYE connection from server");
+
+ EM_SAFE_FREE(p);
+ goto FINISH_OFF;
+ }
+ else {
+ if (!em_core_imap_idle_insert_sync_event(mailbox, &err))
+ EM_DEBUG_EXCEPTION("Syncing mailbox %s failed with err_code - %d", mailbox->name, err);
+ EM_SAFE_FREE(p);
+ break;
+ }
+
+
+ }
+ else if (p && (!strncmp(p, "+", 1))) {
+ /* Bad response from server */
+ EM_DEBUG_LOG("p is [%s]", p);
+ EM_SAFE_FREE(p);
+ break;
+ }
+ else {
+ EM_DEBUG_LOG("In else part");
+ break;
+ }
+ }
+
+ ret = true;
+FINISH_OFF:
+ return ret;
+}
+#endif /* _FEATURE_IMAP_IDLE */
diff --git a/email-core/em-core-imap-mailbox.c b/email-core/em-core-imap-mailbox.c
new file mode 100755
index 0000000..2cef70e
--- /dev/null
+++ b/email-core/em-core-imap-mailbox.c
@@ -0,0 +1,1193 @@
+/*
+* email-service
+*
+* Copyright (c) 2000 - 2011 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.
+*
+*/
+
+
+
+/******************************************************************************
+ * File : em-core-imap_folder.c
+ * Desc : Mail IMAP mailbox
+ *
+ * Auth :
+ *
+ * History :
+ * 2006.08.01 : created
+ *****************************************************************************/
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <vconf.h>
+#include "em-core-global.h"
+#include "em-core-utils.h"
+#include "c-client.h"
+#include "em-storage.h"
+#include "em-core-event.h"
+#include "em-core-mailbox.h"
+#include "em-core-imap-mailbox.h"
+#include "em-core-mailbox-sync.h"
+#include "em-core-account.h"
+#include "lnx_inc.h"
+
+#include "emf-dbglog.h"
+
+EXPORT_API int em_core_mailbox_get_default_mail_slot_count(int *output_count, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ EM_DEBUG_LOG("output_count[%p], err_code[%p]", output_count, err_code);
+
+ int err = EMF_ERROR_NONE;
+ int mail_slot_count;
+ int ret = false, ret2;
+
+ if (output_count == NULL) {
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ ret2 = vconf_get_int(VCONF_KEY_DEFAULT_SLOT_SIZE, &mail_slot_count);
+
+ if (ret2 < 0) {
+ EM_DEBUG_EXCEPTION("vconf_get_int() Failed(%d)", ret2);
+ mail_slot_count = 100;
+ }
+
+ ret = true;
+
+FINISH_OFF:
+
+ if (output_count)
+ *output_count = mail_slot_count;
+
+ if (err_code)
+ *err_code = err;
+
+ return ret;
+
+}
+
+
+EXPORT_API int em_core_mailbox_remove_overflowed_mails(emf_mailbox_tbl_t *intput_mailbox_tbl, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("intput_mailbox_tbl[%p], err_code[%p]", intput_mailbox_tbl, err_code);
+
+ int ret = false;
+ int *mail_id_list = NULL, mail_id_list_count = 0;
+ int err = EMF_ERROR_NONE;
+ emf_account_t *account_ref = NULL;
+
+ if (!intput_mailbox_tbl || intput_mailbox_tbl->account_id < 1) {
+ if (intput_mailbox_tbl)
+ EM_DEBUG_EXCEPTION("Invalid Parameter. intput_mailbox_tbl->account_id [%d]", intput_mailbox_tbl->account_id);
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ account_ref = em_core_get_account_reference(intput_mailbox_tbl->account_id);
+ if (account_ref) {
+ if (account_ref->receiving_server_type == EMF_SERVER_TYPE_ACTIVE_SYNC) {
+ EM_DEBUG_LOG("ActiveSync Account didn't support mail slot");
+ err = EMF_ERROR_NOT_SUPPORTED;
+ goto FINISH_OFF;
+ }
+ }
+
+ if (!em_storage_get_overflowed_mail_id_list(intput_mailbox_tbl->account_id, intput_mailbox_tbl->mailbox_name, intput_mailbox_tbl->mail_slot_size, &mail_id_list, &mail_id_list_count, true, &err)) {
+ if (err == EM_STORAGE_ERROR_MAIL_NOT_FOUND) {
+ EM_DEBUG_LOG("There are enough slot in intput_mailbox_tbl [%s]", intput_mailbox_tbl->mailbox_name);
+ err = EMF_ERROR_NONE;
+ ret = true;
+ }
+ else
+ EM_DEBUG_EXCEPTION("em_storage_get_overflowed_mail_id_list failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ if (mail_id_list) {
+ if (!em_core_mail_delete(intput_mailbox_tbl->account_id, mail_id_list, mail_id_list_count, false, EMF_DELETED_BY_OVERFLOW, false, &err)) {
+ EM_DEBUG_EXCEPTION("em_core_mail_delete failed [%d]", err);
+ goto FINISH_OFF;
+ }
+ }
+
+ ret = true;
+FINISH_OFF:
+ EM_SAFE_FREE(mail_id_list);
+
+ if (err_code)
+ *err_code = err;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+
+EXPORT_API int em_core_mailbox_set_mail_slot_size(int account_id, char *mailbox_name, int new_slot_size, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ EM_DEBUG_LOG("account_id [%d], mailbox_name[%p], err_code[%p]", account_id, mailbox_name, err_code);
+
+ int ret = false, err = EMF_ERROR_NONE;
+ int i, mailbox_count = 0;
+ emf_account_t *account_ref = NULL;
+ emf_mailbox_tbl_t *mailbox_tbl_list = NULL;
+
+ if (account_id > ALL_ACCOUNT) {
+ account_ref = em_core_get_account_reference(account_id);
+ if (account_ref && account_ref->receiving_server_type == EMF_SERVER_TYPE_ACTIVE_SYNC) {
+ EM_DEBUG_LOG("ActiveSync account didn't support mail slot");
+ ret = true;
+ goto FINISH_OFF;
+ }
+ else if (!account_ref) {
+ EM_DEBUG_EXCEPTION("em_core_get_account_reference failed");
+ goto FINISH_OFF;
+ }
+ }
+
+ if (!em_storage_set_mail_slot_size(account_id, mailbox_name, new_slot_size, true, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_set_mail_slot_size failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ if (mailbox_name) {
+ mailbox_count = 1;
+ if (new_slot_size > 0) {
+ mailbox_tbl_list = em_core_malloc(sizeof(emf_mailbox_tbl_t) * mailbox_count);
+ if(!mailbox_tbl_list) {
+ EM_DEBUG_EXCEPTION("em_core_malloc failed");
+ goto FINISH_OFF;
+ }
+ mailbox_tbl_list->account_id = account_id;
+ mailbox_tbl_list->mailbox_name = EM_SAFE_STRDUP(mailbox_name);
+ mailbox_tbl_list->mail_slot_size = new_slot_size;
+ }
+ else { /* read information from DB */
+ if (!em_storage_get_mailbox_by_name(account_id, EMF_MAILBOX_ALL, mailbox_name, &mailbox_tbl_list, true, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_get_mailbox failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ }
+ }
+ else {
+ if (!em_storage_get_mailbox(account_id, EMF_MAILBOX_ALL, EMAIL_MAILBOX_SORT_BY_NAME_ASC, &mailbox_count, &mailbox_tbl_list, true, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_get_mailbox failed [%d]", err);
+ goto FINISH_OFF;
+ }
+ }
+
+ for (i = 0; i < mailbox_count; i++) {
+ if (!em_core_mailbox_remove_overflowed_mails(mailbox_tbl_list + i, &err)) {
+ if (err == EM_STORAGE_ERROR_MAIL_NOT_FOUND || err == EMF_ERROR_NOT_SUPPORTED)
+ err = EMF_ERROR_NONE;
+ else
+ EM_DEBUG_EXCEPTION("em_core_mailbox_remove_overflowed_mails failed [%d]", err);
+ }
+ }
+
+
+
+ ret = true;
+FINISH_OFF:
+
+ if (mailbox_tbl_list)
+ em_storage_free_mailbox(&mailbox_tbl_list, mailbox_count, NULL);
+
+
+ if (err_code)
+ *err_code = err;
+ return ret;
+}
+
+
+static int em_core_get_mailbox_connection_path(int account_id, char *mailbox_name, char **path, int *err_code)
+{
+ emf_account_t *ref_account = NULL;
+ size_t path_len = 0;
+
+
+ ref_account = em_core_get_account_reference(account_id);
+ if (!ref_account) {
+ EM_DEBUG_EXCEPTION("em_core_get_account_reference failed");
+ return 0;
+ }
+
+ path_len = strlen(ref_account->receiving_server_addr) +
+ (mailbox_name ? strlen(mailbox_name) : 0) + 50;
+
+ *path = em_core_malloc(path_len);/* strlen(ref_account->receiving_server_addr) + */
+ /* (mailbox_name ? strlen(mailbox_name) : 0) + 20); */
+ if (!*path)
+ return 0;
+ memset(*path, 0x00, path_len);
+ /* 1. server address / server type */
+
+ if (ref_account->receiving_server_type == EMF_SERVER_TYPE_POP3) {
+ SNPRINTF(*path + 1, path_len-1, "%s:%d/pop", ref_account->receiving_server_addr, ref_account->port_num);
+ }
+ else {
+ SNPRINTF(*path + 1, path_len-1, "%s:%d/imap", ref_account->receiving_server_addr, ref_account->port_num);
+ }
+
+ /* 2. set tls option if security connection */
+/* if (ref_account->use_security) strncat(*path + 1, "/tls", path_len-(strlen(*path)-1)); */
+ if (ref_account->use_security & 0x01) {
+ strncat(*path + 1, "/ssl", path_len-(strlen(*path)-1));
+ }
+ if (ref_account->use_security & 0x02)
+ strncat(*path + 1, "/tls", path_len-(strlen(*path)-1));
+ else
+ strncat(*path + 1, "/notls", path_len-(strlen(*path)-1));
+
+ /* 3. re-format mailbox name (ex:"{mai.test.com:143/imap} or {mai.test.com:143/imap/tls}"} */
+ strncat(*path + 1, "}", path_len-strlen(*path)-1);
+ **path = '{';
+
+ if (mailbox_name) strncat(*path, mailbox_name, path_len-strlen(*path)-1);
+
+ return 1;
+}
+
+EXPORT_API int em_core_mailbox_sync_mailbox_list(int account_id, char *mailbox_name, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("account_id[%d], mailbox_name[%p], err_code[%p]", account_id, mailbox_name, err_code);
+
+ int ret = false;
+ int err = EMF_ERROR_NONE;
+ int status = EMF_DOWNLOAD_FAIL;
+
+ MAILSTREAM *stream = NULL;
+ emf_mailbox_t *mailbox_list = NULL;
+ emf_account_t *ref_account = NULL;
+ void *tmp_stream = NULL;
+ char *mbox_path = NULL;
+ int i = 0, count = 0, counter = 0, mailbox_type_list[EMF_MAILBOX_TYPE_ALL_EMAILS + 1] = {-1, -1, -1, -1, -1, -1, -1, -1};
+ char *mailbox_name_for_mailbox_type = NULL;
+
+
+ if (err_code)
+ *err_code = EMF_ERROR_NONE;
+
+ if (!em_core_check_thread_status()) {
+ err = EMF_ERROR_CANCELLED;
+ goto FINISH_OFF;
+ }
+
+ ref_account = em_core_get_account_reference(account_id);
+ if (!ref_account) {
+ EM_DEBUG_EXCEPTION("em_core_get_account_reference failed - %d", account_id);
+ err = EMF_ERROR_INVALID_ACCOUNT;
+ goto FINISH_OFF;
+ }
+
+ /* if not imap4 mail, return */
+ if (ref_account->account_bind_type != EMF_BIND_TYPE_EM_CORE || ref_account->receiving_server_type != EMF_SERVER_TYPE_IMAP4) {
+ EM_DEBUG_EXCEPTION("unsupported account...");
+ err = EMF_ERROR_INVALID_ACCOUNT;
+ goto FINISH_OFF;
+ }
+
+ /* get mail server path */
+ /* mbox_path is not used. the below func might be unnecessary */
+ if (!em_core_get_mailbox_connection_path(account_id, NULL, &mbox_path, &err) || !mbox_path) {
+ EM_DEBUG_EXCEPTION("em_core_get_mailbox_connection_path - %d", err);
+ goto FINISH_OFF;
+ }
+
+
+ if (!em_core_check_thread_status()) {
+ err = EMF_ERROR_CANCELLED;
+ goto FINISH_OFF;
+ }
+
+ stream = NULL;
+ if (!em_core_mailbox_open(account_id, NULL, (void **)&tmp_stream, &err) || !tmp_stream) {
+ EM_DEBUG_EXCEPTION("em_core_mailbox_open failed - %d", err);
+
+ if (err == EMF_ERROR_CONNECTION_BROKEN)
+ err = EMF_ERROR_CANCELLED;
+ else
+ err = EMF_ERROR_CONNECTION_FAILURE;
+
+ status = EMF_DOWNLOAD_CONNECTION_FAIL;
+ goto FINISH_OFF;
+ }
+
+ EM_SAFE_FREE(mbox_path);
+
+ stream = (MAILSTREAM *)tmp_stream;
+
+ if (!em_core_check_thread_status()) {
+ err = EMF_ERROR_CANCELLED;
+ goto FINISH_OFF;
+ }
+
+ /* download mailbox list */
+ if (!em_core_mailbox_download_mailbox_list(stream, mailbox_name, &mailbox_list, &count, &err)) {
+ EM_DEBUG_EXCEPTION("em_core_mailbox_download_mailbox_list failed - %d", err);
+ goto FINISH_OFF;
+ }
+
+ if (!em_core_check_thread_status()) {
+ err = EMF_ERROR_CANCELLED;
+ goto FINISH_OFF;
+ }
+
+ for (i = 0; i < count; i++) {
+ if (!em_core_check_thread_status()) {
+ EM_DEBUG_LOG("em_core_check_thread_status - cancelled");
+ err = EMF_ERROR_CANCELLED;
+ goto FINISH_OFF;
+ }
+ if (mailbox_list[i].name) {
+ EM_DEBUG_LOG("mailbox name - %s", mailbox_list[i].name);
+ em_core_mailbox_get_default_mail_slot_count(&(mailbox_list[i].mail_slot_size), NULL);
+ em_core_bind_mailbox_type(mailbox_list + i);
+
+ if (mailbox_list[i].mailbox_type <= EMF_MAILBOX_TYPE_ALL_EMAILS) { /* if result mailbox type is duplicated, */
+ if (mailbox_type_list[mailbox_list[i].mailbox_type] != -1) {
+ EM_DEBUG_LOG("Mailbox type [%d] of [%s] is duplicated", mailbox_list[i].mailbox_type, mailbox_list[i].name);
+ mailbox_list[i].mailbox_type = EMF_MAILBOX_TYPE_USER_DEFINED; /* ignore latest one */
+ }
+ else
+ mailbox_type_list[mailbox_list[i].mailbox_type] = i;
+ }
+
+ EM_DEBUG_LOG("mailbox type [%d]", mailbox_list[i].mailbox_type);
+ if(!em_core_mailbox_set_sync_imap_mailbox(mailbox_list + i, 1, &err)) {
+ EM_DEBUG_EXCEPTION("em_core_mailbox_set_sync_imap_mailbox failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ }
+ }
+
+
+ for (counter = EMF_MAILBOX_TYPE_INBOX; counter <= EMF_MAILBOX_TYPE_OUTBOX; counter++) {
+ /* if (!em_storage_get_mailboxname_by_mailbox_type(account_id, counter, &mailbox_name_for_mailbox_type, false, &err)) */
+ if (mailbox_type_list[counter] == -1) {
+ /* EM_DEBUG_EXCEPTION("em_storage_get_mailboxname_by_mailbox_type failed - %d", err); */
+ /* if (EM_STORAGE_ERROR_MAILBOX_NOT_FOUND == err) */
+ /* { */
+ emf_mailbox_tbl_t mailbox_tbl;
+
+ memset(&mailbox_tbl, 0x00, sizeof(mailbox_tbl));
+
+ mailbox_tbl.account_id = account_id;
+ mailbox_tbl.mailbox_id = 0;
+ mailbox_tbl.local_yn = 1;
+ mailbox_tbl.mailbox_type = counter;
+ mailbox_tbl.sync_with_server_yn = 1;
+ mailbox_tbl.modifiable_yn = 1;
+ mailbox_tbl.total_mail_count_on_server = 0;
+ em_core_mailbox_get_default_mail_slot_count(&mailbox_tbl.mail_slot_size, NULL);
+
+ switch (counter) {
+ case EMF_MAILBOX_TYPE_SENTBOX:
+ mailbox_tbl.mailbox_name = EMF_SENTBOX_NAME;
+ mailbox_tbl.alias = EMF_SENTBOX_DISPLAY_NAME;
+ break;
+
+ case EMF_MAILBOX_TYPE_TRASH:
+ mailbox_tbl.mailbox_name = EMF_TRASH_NAME;
+ mailbox_tbl.alias = EMF_TRASH_DISPLAY_NAME;
+ break;
+
+ case EMF_MAILBOX_TYPE_DRAFT:
+ mailbox_tbl.mailbox_name = EMF_DRAFTBOX_NAME;
+ mailbox_tbl.alias = EMF_DRAFTBOX_DISPLAY_NAME;
+ break;
+
+ case EMF_MAILBOX_TYPE_SPAMBOX:
+ mailbox_tbl.mailbox_name = EMF_SPAMBOX_NAME;
+ mailbox_tbl.alias = EMF_SPAMBOX_DISPLAY_NAME;
+ break;
+
+ case EMF_MAILBOX_TYPE_OUTBOX:
+ mailbox_tbl.mailbox_name = EMF_OUTBOX_NAME;
+ mailbox_tbl.alias = EMF_OUTBOX_DISPLAY_NAME;
+ break;
+
+ default:
+ mailbox_tbl.mailbox_name = EMF_INBOX_NAME;
+ mailbox_tbl.alias = EMF_INBOX_DISPLAY_NAME;
+ break;
+ }
+
+ if (!em_storage_add_mailbox(&mailbox_tbl, true, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_add_mailbox failed - %d", err);
+
+ if (err == EM_STORAGE_ERROR_DB_IS_FULL)
+ err = EMF_ERROR_MAIL_MEMORY_FULL;
+ else if (err == EM_STORAGE_ERROR_INVALID_PARAM)
+ err = EMF_ERROR_INVALID_PARAM;
+ else if (err == EM_STORAGE_ERROR_OUT_OF_MEMORY)
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ else if (err == EM_STORAGE_ERROR_DB_FAILURE)
+ err = EMF_ERROR_DB_FAILURE;
+ else
+ err = EMF_ERROR_UNKNOWN;
+ goto FINISH_OFF;
+ }
+
+ /* } */
+ /* else */
+ /* { */
+ /* err = em_storage_get_emf_error_from_em_storage_error(err); */
+ /* goto FINISH_OFF; */
+ /* } */
+
+ }
+ EM_SAFE_FREE(mailbox_name_for_mailbox_type);
+ }
+
+ emf_mailbox_tbl_t *local_mailbox_list = NULL;
+ int select_num = 0;
+ i = 0;
+ emf_mailbox_t mailbox;
+
+ if (em_storage_get_mailbox_by_modifiable_yn(account_id, 0 /* modifiable_yn */, &select_num, &local_mailbox_list, true, &err)) {
+ if (select_num > 0) {
+ for (i = 0; i < select_num; i++) {
+ EM_DEBUG_LOG(">>> MailBox needs to be Deleted[ %s ] ", local_mailbox_list[i].mailbox_name);
+ mailbox.account_id = local_mailbox_list[i].account_id;
+ mailbox.name = local_mailbox_list[i].mailbox_name;
+ if (!em_core_mailbox_delete_all(&mailbox, &err)) {
+ EM_DEBUG_EXCEPTION(" em_core_mailbox_delete_all of Mailbox [%s] Failed ", mailbox.name);
+ em_storage_free_mailbox(&local_mailbox_list, select_num, NULL);
+ local_mailbox_list = NULL;
+ goto FINISH_OFF;
+ }
+ }
+ em_storage_free_mailbox(&local_mailbox_list, select_num, NULL);
+ local_mailbox_list = NULL;
+ }
+ }
+
+ if (!em_storage_set_all_mailbox_modifiable_yn(account_id, 0, true, &err)) {
+ EM_DEBUG_EXCEPTION(" >>>> em_storage_set_all_mailbox_modifiable_yn Failed [ %d ]", err);
+ goto FINISH_OFF;
+ }
+
+ if (!em_core_check_thread_status()) {
+ err = EMF_ERROR_CANCELLED;
+ goto FINISH_OFF;
+ }
+
+ for (i = 0; i < count; i++)
+ mailbox_list[i].account_id = account_id;
+
+
+ ret = true;
+
+FINISH_OFF:
+ EM_SAFE_FREE(mailbox_name_for_mailbox_type);
+ EM_SAFE_FREE(mbox_path);
+
+ if (stream)
+ em_core_mailbox_close(account_id, stream);
+
+ if (mailbox_list)
+ em_core_mailbox_free(&mailbox_list, count, NULL);
+
+ if (err_code != NULL)
+ *err_code = err;
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+int em_core_mailbox_download_mailbox_list(void *mail_stream,
+ char *mailbox,
+ emf_mailbox_t **mailbox_list,
+ int *count,
+ int *err_code)
+{
+ MAILSTREAM *stream = mail_stream;
+ emf_callback_holder_t holder;
+ char *pattern = NULL;
+ char *reference = NULL;
+ int err = EMF_ERROR_NONE;
+ int ret = false;
+
+ EM_DEBUG_FUNC_BEGIN();
+
+ if (err_code) {
+ *err_code = EMF_ERROR_NONE;
+ }
+
+ if (!stream || !mailbox_list || !count) {
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ memset(&holder, 0x00, sizeof(holder));
+
+ /* reference (ex : "{mail.test.com}", "{mail.test.com}inbox") */
+ if (mailbox) {
+ char *s = NULL;
+ reference = em_core_malloc(strlen(stream->original_mailbox) + strlen(mailbox) + 1);
+ if (reference) {
+ strncpy(reference, stream->original_mailbox, (size_t)strlen(stream->original_mailbox));
+ if ((s = strchr(reference, '}')))
+ *(++s) = '\0';
+ strcat(reference, mailbox);
+ }
+ }
+ else
+ reference = EM_SAFE_STRDUP(stream->original_mailbox);
+
+ pattern = "*";
+ stream->sparep = &holder;
+
+ /* imap command : tag LIST reference * */
+ mail_list(stream, reference, pattern);
+
+ stream->sparep = NULL;
+
+ EM_SAFE_FREE(reference);
+
+ *count = holder.num;
+ *mailbox_list = (emf_mailbox_t *)holder.data;
+
+ ret = true;
+
+FINISH_OFF:
+ if (err_code) *err_code = err;
+
+ return ret;
+}
+
+/* description
+ * check whether this imap mailbox is synchronous mailbox
+ * arguments
+ * mailbox : imap mailbox to be checked
+ * synchronous : boolean variable to be synchronous (1 : sync 0 : non-sync)
+ * return
+ * succeed : 1
+ * fail : 0
+ */
+int em_core_mailbox_check_sync_imap_mailbox(emf_mailbox_t *mailbox, int *synchronous, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ EM_DEBUG_LOG("\t mailbox[%p], synchronous[%p], err_code[%p]", mailbox, synchronous, err_code);
+
+ if (err_code) {
+ *err_code = EMF_ERROR_NONE;
+ }
+
+ if (!mailbox || !synchronous) {
+ EM_DEBUG_EXCEPTION("\t mailbox[%p], synchronous[%p]", mailbox, synchronous);
+
+ if (err_code != NULL)
+ *err_code = EMF_ERROR_INVALID_PARAM;
+ return false;
+ }
+
+ int ret = false;
+ int err = EMF_ERROR_NONE;
+ emf_mailbox_tbl_t *imap_mailbox_tbl = NULL;
+
+ if (!em_storage_get_mailbox_by_name(mailbox->account_id, 0, mailbox->name, &imap_mailbox_tbl, true, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_get_mailbox_by_name failed - %d", err);
+
+ if (err == EM_STORAGE_ERROR_MAILBOX_NOT_FOUND)
+ err = EMF_ERROR_MAILBOX_NOT_FOUND;
+ else if (err == EM_STORAGE_ERROR_INVALID_PARAM)
+ err = EMF_ERROR_INVALID_PARAM;
+ else if (err == EM_STORAGE_ERROR_OUT_OF_MEMORY)
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ else if (err == EM_STORAGE_ERROR_DB_FAILURE)
+ err = EMF_ERROR_DB_FAILURE;
+ else
+ err = EMF_ERROR_UNKNOWN;
+ goto FINISH_OFF;
+ }
+
+ *synchronous = imap_mailbox_tbl ? 1 : 0;
+
+ ret = true;
+
+FINISH_OFF:
+ if (imap_mailbox_tbl != NULL)
+ em_storage_free_mailbox(&imap_mailbox_tbl, 1, NULL);
+
+ if (err_code != NULL)
+ *err_code = err;
+
+ return ret;
+}
+
+
+/* description
+ * set sync imap mailbox
+ * arguments
+ * mailbox_list : imap mailbox to be synced
+ * syncronous : 0-sync 1 : non-sync
+ * return
+ * succeed : 1
+ * fail : 0
+ */
+
+int em_core_mailbox_set_sync_imap_mailbox(emf_mailbox_t *mailbox, int synchronous, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("mailbox[%p], synchronous[%d], err_code[%p]", mailbox, synchronous, err_code);
+
+ if (!mailbox) {
+ EM_DEBUG_EXCEPTION("mailbox[%p], synchronous[%d]", mailbox, synchronous);
+ if (err_code != NULL)
+ *err_code = EMF_ERROR_INVALID_PARAM;
+ return false;
+ }
+
+ int ret = false;
+ int err = EMF_ERROR_NONE;
+ emf_mailbox_tbl_t *imap_mailbox_tbl_item = NULL;
+ em_core_uid_list *uid_list = NULL;
+ emf_mail_read_mail_uid_tbl_t *downloaded_uids = NULL;
+ MAILSTREAM *stream = mailbox->mail_stream;
+ int mailbox_renamed = 0;
+ int j = 0;
+ int i = 0;
+ int temp = 0;
+ IMAPLOCAL *imap_local = NULL;
+ char cmd[128], tag[32], *p;
+
+ if (synchronous) {
+ /* if synchcronous, insert imap mailbox to db */
+ if (em_storage_get_mailbox_by_name(mailbox->account_id, 0, mailbox->name, &imap_mailbox_tbl_item, true, &err)) {
+ /* mailbox already exists */
+ /* mailbox Found, Do set the modifiable_yn = 1 */
+ EM_DEBUG_LOG("mailbox already exists and setting modifiable_yn to 1");
+ if (!em_storage_update_mailbox_modifiable_yn(mailbox->account_id, 0, mailbox->name, 1, true, &err)) {
+ EM_DEBUG_EXCEPTION(" em_storage_update_mailbox_modifiable_yn Failed [ %d ] ", err);
+ if (err == EM_STORAGE_ERROR_INVALID_PARAM)
+ err = EMF_ERROR_INVALID_PARAM;
+ else if (err == EM_STORAGE_ERROR_OUT_OF_MEMORY)
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ else if (err == EM_STORAGE_ERROR_DB_FAILURE)
+ err = EMF_ERROR_DB_FAILURE;
+ else
+ err = EMF_ERROR_UNKNOWN;
+ goto JOB_ERROR;
+ }
+ }
+ else {
+ if (err != EM_STORAGE_ERROR_MAILBOX_NOT_FOUND) {
+ EM_DEBUG_EXCEPTION(">>>>.>>>>>Getting mailbox failed>>>>>>>>>>>>>>");
+ /* This is error scenario so finish the job */
+ if (err == EM_STORAGE_ERROR_INVALID_PARAM)
+ err = EMF_ERROR_INVALID_PARAM;
+ else if (err == EM_STORAGE_ERROR_OUT_OF_MEMORY)
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ else if (err == EM_STORAGE_ERROR_DB_FAILURE)
+ err = EMF_ERROR_DB_FAILURE;
+ else
+ err = EMF_ERROR_UNKNOWN;
+ goto JOB_ERROR;
+ }
+ else {
+ /* This is not error scenario - mailbox is either new/renamed mailbox and needs to be added/modfied in DB */
+ /* Now check if mailbox is renamed */
+ EM_DEBUG_LOG(">>>>>>>>>>>>>>>>>>>>>>>MAILBOX NEW OR RENAMED");
+ if (stream) {
+ imap_local = ((MAILSTREAM *)stream)->local;
+ EM_DEBUG_LINE;
+ sprintf(tag, "%08lx", 0xffffffff & (((MAILSTREAM *)stream)->gensym++));
+ EM_DEBUG_LINE;
+ sprintf(cmd, "%s SELECT %s\015\012", tag, mailbox->name);
+ EM_DEBUG_LINE;
+
+ }
+
+ /* select the mailbox and get its UID */
+ if (!imap_local || !imap_local->netstream || !net_sout(imap_local->netstream, cmd, (int)strlen(cmd))) {
+ EM_DEBUG_EXCEPTION("network error - failed to IDLE on Mailbox [%s]", mailbox->name);
+ /*
+ err = EMF_ERROR_CONNECTION_BROKEN;
+ if(imap_local)
+ imap_local->netstream = NULL;
+ mailbox->mail_stream = NULL;
+ goto JOB_ERROR;
+ */
+ }
+ else {
+ EM_DEBUG_LOG("Get response for select call");
+ while (imap_local->netstream) {
+ p = net_getline(imap_local->netstream);
+ EM_DEBUG_LOG("p =[%s]", p);
+ if (!strncmp(p, "+", 1)) {
+ ret = 1;
+ break;
+ }
+ else if (!strncmp(p, "*", 1)) {
+ EM_SAFE_FREE(p);
+ continue;
+ }
+ else {
+ ret = 0;
+ break;
+ }
+ }
+ EM_SAFE_FREE(p);
+ EM_DEBUG_LINE;
+ /* check if OK or BAD response comes. */
+ /* if response is OK the try getting UID list. */
+ if (!strncmp((char *)imap_local->reply.key, "OK", strlen("OK"))) {
+ EM_DEBUG_LOG(">>>>>>>>>>Select success on %s mailbox", mailbox->name);
+ if (!imap4_mailbox_get_uids(stream, &uid_list, &err)) {
+ EM_DEBUG_EXCEPTION("imap4_mailbox_get_uids failed - %d", err);
+ EM_SAFE_FREE(uid_list);
+ }
+ else {
+ if (!em_storage_get_downloaded_list(mailbox->account_id, NULL, &downloaded_uids, &j, true, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_get_downloaded_list failed [%d]", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ downloaded_uids = NULL;
+ }
+ else /* Prevent Defect - 28497 */ {
+ em_core_uid_list *uid_elem = uid_list;
+ em_core_uid_list *next_uid_elem = NULL;
+ if (uid_elem) {
+ for (i = j; (i > 0 && !mailbox_renamed); i--) {
+ if (uid_elem) {
+ next_uid_elem = uid_elem->next;
+ if (uid_elem->uid && downloaded_uids[i - 1].s_uid && !strcmp(uid_elem->uid, downloaded_uids[i - 1].s_uid)) {
+ temp = i-1;
+ mailbox_renamed = 1;
+ break;
+ }
+ EM_SAFE_FREE(uid_elem->uid);
+ uid_elem = next_uid_elem;
+ }
+ }
+ }
+ }
+ }
+ } /* mailbox selected */
+ }
+
+ if (mailbox_renamed) /* renamed mailbox */ {
+ EM_DEBUG_LOG("downloaded_uids[temp].mailbox_name [%s]", downloaded_uids[temp].mailbox_name);
+ /* Do a mailbox rename in the DB */
+ if (!em_storage_modify_mailbox_of_mails(downloaded_uids[temp].mailbox_name, mailbox->name, true, &err))
+ EM_DEBUG_EXCEPTION(" em_storage_modify_mailbox_of_mails Failed [%d]", err);
+
+ mailbox_renamed = 0;
+
+ emf_mailbox_tbl_t mailbox_tbl;
+ mailbox_tbl.account_id = mailbox->account_id;
+ mailbox_tbl.local_yn = 0;
+ mailbox_tbl.mailbox_name = mailbox->name;
+ mailbox_tbl.mailbox_type = mailbox->mailbox_type;
+
+ /* Get the Alias Name after parsing the Full mailbox Path */
+ mailbox->alias = em_core_get_alias_of_mailbox((const char *)mailbox->name);
+
+ if (mailbox->alias)
+ EM_DEBUG_LOG("mailbox->alias [%s] ", mailbox->alias);
+
+ mailbox_tbl.alias = mailbox->alias;
+ mailbox_tbl.sync_with_server_yn = 0;
+ mailbox_tbl.modifiable_yn = 1;
+ mailbox_tbl.total_mail_count_on_server = 0;
+
+ /* if non synchronous, delete imap mailbox from db */
+ if (!em_storage_update_mailbox(mailbox->account_id, 0, downloaded_uids[temp].mailbox_name, &mailbox_tbl, true, &err)) {
+ EM_DEBUG_EXCEPTION(" em_storage_update_mailbox Failed [ %d ] ", err);
+ if (err == EM_STORAGE_ERROR_INVALID_PARAM)
+ err = EMF_ERROR_INVALID_PARAM;
+ else if (err == EM_STORAGE_ERROR_OUT_OF_MEMORY)
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ else if (err == EM_STORAGE_ERROR_DB_FAILURE)
+ err = EMF_ERROR_DB_FAILURE;
+ else
+ err = EMF_ERROR_UNKNOWN;
+ goto JOB_ERROR;
+ }
+
+ }
+ else /* Its a Fresh Mailbox */ {
+ emf_mailbox_tbl_t mailbox_tbl;
+ mailbox_tbl.mailbox_id = mailbox->mailbox_id;
+ mailbox_tbl.account_id = mailbox->account_id;
+ mailbox_tbl.local_yn = 0;
+ mailbox_tbl.mailbox_type = mailbox->mailbox_type;
+ mailbox_tbl.mailbox_name = mailbox->name;
+ mailbox_tbl.mail_slot_size = mailbox->mail_slot_size;
+
+ /* Get the Alias Name after Parsing the Full mailbox Path */
+ mailbox->alias = em_core_get_alias_of_mailbox((const char *)mailbox->name);
+
+ if (mailbox->alias) {
+ EM_DEBUG_LOG("mailbox->alias [%s] ", mailbox->alias);
+
+ mailbox_tbl.alias = mailbox->alias;
+ mailbox_tbl.sync_with_server_yn = 1;
+ mailbox_tbl.modifiable_yn = 1;
+ mailbox_tbl.total_mail_count_on_server = 0;
+
+ EM_DEBUG_LOG("mailbox_tbl.mailbox_type - %d", mailbox_tbl.mailbox_type);
+
+ if (!em_storage_add_mailbox(&mailbox_tbl, true, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_add_mailbox failed - %d", err);
+
+ if (err == EM_STORAGE_ERROR_DB_IS_FULL)
+ err = EMF_ERROR_MAIL_MEMORY_FULL;
+ else if (err == EM_STORAGE_ERROR_INVALID_PARAM)
+ err = EMF_ERROR_INVALID_PARAM;
+ else if (err == EM_STORAGE_ERROR_OUT_OF_MEMORY)
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ else if (err == EM_STORAGE_ERROR_DB_FAILURE)
+ err = EMF_ERROR_DB_FAILURE;
+ else
+ err = EMF_ERROR_UNKNOWN;
+ goto JOB_ERROR;
+ }
+ }
+ }
+ }
+ }
+ }
+
+ /* set sync db mailbox */
+ mailbox->synchronous = synchronous;
+
+ ret = true;
+
+JOB_ERROR:
+
+ if (downloaded_uids)
+ em_storage_free_read_mail_uid(&downloaded_uids, j, NULL);
+
+ if (imap_mailbox_tbl_item)
+ em_storage_free_mailbox(&imap_mailbox_tbl_item, 1, NULL);
+
+ if (err_code)
+ *err_code = err;
+
+ return ret;
+}
+
+/* description
+ * create a new imap mailbox
+ * arguments
+ * new_mailbox : imap mailbox to be created
+ * return
+ * succeed : 1
+ * fail : 0
+ */
+EXPORT_API int em_core_mailbox_create_imap_mailbox(emf_mailbox_t *mailbox, int *err_code)
+{
+ MAILSTREAM *stream = NULL;
+ char *long_enc_path = NULL;
+ void *tmp_stream = NULL;
+ int ret = false;
+ int err = EMF_ERROR_NONE;
+
+ EM_DEBUG_FUNC_BEGIN();
+
+ if (err_code) {
+ *err_code = EMF_ERROR_NONE;
+ }
+
+ if (!mailbox)
+ {
+ err = EMF_ERROR_INVALID_PARAM;
+ goto JOB_ERROR;
+ }
+
+ /* connect mail server */
+ stream = NULL;
+ if (!em_core_mailbox_open(mailbox->account_id, NULL, (void **)&tmp_stream, NULL))
+ {
+ err = EMF_ERROR_CONNECTION_FAILURE;
+ goto JOB_ERROR;
+ }
+
+ stream = (MAILSTREAM *)tmp_stream;
+
+ /* encode mailbox name by UTF7, and rename to full path (ex : {mail.test.com}child_mailbox) */
+ if (!em_core_get_long_encoded_path(mailbox->account_id, mailbox->name, '/', &long_enc_path, err_code))
+ {
+ err = EMF_ERROR_UNKNOWN;
+ goto JOB_ERROR;
+ }
+
+ /* create mailbox */
+ if (!mail_create(stream, long_enc_path))
+ {
+ err = EMF_ERROR_UNKNOWN;
+ goto JOB_ERROR;
+ }
+
+ em_core_mailbox_close(0, stream);
+ stream = NULL;
+
+ EM_SAFE_FREE(long_enc_path);
+
+ ret = true;
+
+JOB_ERROR:
+ if (stream)
+ {
+ em_core_mailbox_close(0, stream);
+ stream = NULL;
+ }
+
+ EM_SAFE_FREE(long_enc_path);
+
+ if (err_code)
+ *err_code = err;
+
+ return ret;
+}
+
+
+/* description
+ * delete a imap mailbox
+ * arguments
+ * mailbox : mailbox to be deleted
+ * return
+ * succeed : 1
+ * fail : 0
+ */
+EXPORT_API int em_core_mailbox_delete_imap_mailbox(emf_mailbox_t *mailbox, int *err_code)
+{
+ MAILSTREAM *stream = NULL;
+ char *long_enc_path = NULL;
+ emf_account_t *ref_account = NULL;
+ void *tmp_stream = NULL;
+ int ret = false;
+ int err = EMF_ERROR_NONE;
+
+ EM_DEBUG_FUNC_BEGIN();
+
+ if (err_code) {
+ *err_code = EMF_ERROR_NONE;
+ }
+
+ if (!mailbox)
+ {
+ err = EMF_ERROR_INVALID_PARAM;
+ goto JOB_ERROR;
+ }
+
+ ref_account = em_core_get_account_reference(mailbox->account_id);
+ if (!ref_account)
+ {
+ err = EMF_ERROR_INVALID_PARAM;
+ goto JOB_ERROR;
+ }
+
+ /* if not imap4 mail, return */
+ if (ref_account->account_bind_type != EMF_BIND_TYPE_EM_CORE ||
+ ref_account->receiving_server_type != EMF_SERVER_TYPE_IMAP4)
+ {
+ err = EMF_ERROR_INVALID_PARAM;
+ goto JOB_ERROR;
+ }
+
+ /* connect mail server */
+ stream = NULL;
+ if (!em_core_mailbox_open(ref_account->account_id, NULL, (void **)&tmp_stream, NULL))
+ {
+ err = EMF_ERROR_CONNECTION_FAILURE;
+ goto JOB_ERROR;
+ }
+
+ stream = (MAILSTREAM *)tmp_stream;
+
+ /* encode mailbox name by UTF7, and rename to full path (ex : {mail.test.com}child_mailbox) */
+ if (!em_core_get_long_encoded_path(mailbox->account_id, mailbox->name, '/', &long_enc_path, err_code))
+ {
+ err = EMF_ERROR_UNKNOWN;
+ goto JOB_ERROR;
+ }
+
+ /* delete mailbox */
+ if (!mail_delete(stream, long_enc_path))
+ {
+ err = EMF_ERROR_UNKNOWN;
+ goto JOB_ERROR;
+ }
+
+ em_core_mailbox_close(0, stream);
+ stream = NULL;
+
+ EM_SAFE_FREE(long_enc_path);
+
+ /* if deleted imap mailbox is synchronous mailbox, delete db imap mailbox from db */
+ if (!em_storage_delete_mailbox(ref_account->account_id, 0, mailbox->name, true, &err)) {
+ EM_DEBUG_EXCEPTION("\t em_storage_delete_mailbox failed - %d", err);
+
+ if (err == EM_STORAGE_ERROR_MAILBOX_NOT_FOUND)
+ err = EMF_ERROR_MAILBOX_NOT_FOUND;
+ else if (err == EM_STORAGE_ERROR_INVALID_PARAM)
+ err = EMF_ERROR_INVALID_PARAM;
+ else if (err == EM_STORAGE_ERROR_OUT_OF_MEMORY)
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ else if (err == EM_STORAGE_ERROR_DB_FAILURE)
+ err = EMF_ERROR_DB_FAILURE;
+ else
+ err = EMF_ERROR_UNKNOWN;
+ goto JOB_ERROR;
+ }
+
+ ret = true;
+
+JOB_ERROR:
+ if (stream)
+ {
+ em_core_mailbox_close(0, stream);
+ stream = NULL;
+ }
+
+ EM_SAFE_FREE(long_enc_path);
+
+ if (err_code)
+ *err_code = err;
+
+ return ret;
+}
+
+
+/* description
+ * change imap mailbox name
+ * arguments
+ * old_mailbox : previous mailbox
+ * new_mailbox : renamed mailbox
+ * return
+ * succeed : 1
+ * fail : 0
+ */
+EXPORT_API int em_core_mailbox_modify_imap_mailbox(emf_mailbox_t *old_mailbox, emf_mailbox_t *new_mailbox, int *err_code)
+{
+ MAILSTREAM *stream = NULL;
+ char *long_enc_path = NULL;
+ char *long_enc_path_new = NULL;
+ emf_mailbox_tbl_t imap_mailbox_tbl_item;
+ emf_account_t *ref_account = NULL;
+ void *tmp_stream = NULL;
+ int ret = false;
+ int err = EMF_ERROR_NONE;
+
+ EM_DEBUG_FUNC_BEGIN();
+
+ if (err_code) {
+ *err_code = EMF_ERROR_NONE;
+ }
+
+ if (!old_mailbox || !new_mailbox)
+ {
+ err = EMF_ERROR_INVALID_PARAM;
+ goto JOB_ERROR;
+ }
+
+ ref_account = em_core_get_account_reference(old_mailbox->account_id);
+ if (!ref_account)
+ {
+ err = EMF_ERROR_INVALID_PARAM;
+ goto JOB_ERROR;
+ }
+
+ if (!em_core_get_account_reference(new_mailbox->account_id))
+ {
+ err = EMF_ERROR_INVALID_PARAM;
+ goto JOB_ERROR;
+ }
+
+ /* if not imap4 mail, return */
+ if (ref_account->account_bind_type != EMF_BIND_TYPE_EM_CORE ||
+ ref_account->receiving_server_type != EMF_SERVER_TYPE_IMAP4)
+ {
+ err = EMF_ERROR_INVALID_PARAM;
+ goto JOB_ERROR;
+ }
+
+ /* connect mail server */
+ stream = NULL;
+ if (!em_core_mailbox_open(ref_account->account_id, NULL, (void **)&tmp_stream, NULL))
+ {
+ err = EMF_ERROR_CONNECTION_FAILURE;
+ goto JOB_ERROR;
+ }
+
+ stream = (MAILSTREAM *)tmp_stream;
+
+ /* encode mailbox name by UTF7, and rename to full path (ex : {mail.test.com}child_mailbox) */
+ if (!em_core_get_long_encoded_path(old_mailbox->account_id, old_mailbox->name, '/', &long_enc_path, err_code))
+ {
+ err = EMF_ERROR_UNKNOWN;
+ goto JOB_ERROR;
+ }
+
+ /* encode mailbox name by UTF7, and rename to full path (ex : {mail.test.com}child_mailbox) */
+ if (!em_core_get_long_encoded_path(new_mailbox->account_id, new_mailbox->name, '/', &long_enc_path_new, err_code))
+ {
+ err = EMF_ERROR_UNKNOWN;
+ goto JOB_ERROR;
+ }
+
+ /* rename mailbox */
+ if (!mail_rename(stream, long_enc_path, long_enc_path_new))
+ {
+ err = EMF_ERROR_UNKNOWN;
+ goto JOB_ERROR;
+ }
+
+ EM_SAFE_FREE(long_enc_path);
+ EM_SAFE_FREE(long_enc_path_new);
+
+ em_core_mailbox_close(0, stream);
+ stream = NULL;
+
+ imap_mailbox_tbl_item.alias = NULL;
+ imap_mailbox_tbl_item.mailbox_name = new_mailbox->name;
+ imap_mailbox_tbl_item.modifiable_yn = 1;
+
+ /* if modified imap mailbox is synchronous mailbox, update mailbox name from imap mailbox table */
+ if (!em_storage_update_mailbox(ref_account->account_id, 0, old_mailbox->name, &imap_mailbox_tbl_item, true, &err))
+ {
+ EM_DEBUG_EXCEPTION("em_storage_update_mailbox failed - %d", err);
+ if (err == EM_STORAGE_ERROR_DB_IS_FULL)
+ err = EMF_ERROR_MAIL_MEMORY_FULL;
+ else
+ err = EMF_ERROR_DB_FAILURE;
+ goto JOB_ERROR;
+ }
+
+ ret = true;
+
+JOB_ERROR:
+ EM_SAFE_FREE(long_enc_path);
+ EM_SAFE_FREE(long_enc_path_new);
+
+ if (stream)
+ {
+ em_core_mailbox_close(0, stream);
+ stream = NULL;
+ }
+
+ if (err_code)
+ *err_code = err;
+
+ return ret;
+}
diff --git a/email-core/em-core-mailbox-sync.c b/email-core/em-core-mailbox-sync.c
new file mode 100755
index 0000000..8918044
--- /dev/null
+++ b/email-core/em-core-mailbox-sync.c
@@ -0,0 +1,4007 @@
+/*
+* email-service
+*
+* Copyright (c) 2000 - 2011 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.
+*
+*/
+
+
+/******************************************************************************
+ * File : em-core-mailbox_sync.c
+ * Desc : Mail Header Sync
+ *
+ * Auth :
+ *****************************************************************************/
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+
+#include "em-core-types.h"
+
+#include "c-client.h"
+#include "lnx_inc.h"
+
+#include "Msg_Convert.h"
+#include "em-core-mailbox-sync.h"
+#include "em-core-global.h"
+#include "em-core-imap-mailbox.h"
+#include "em-core-event.h"
+#include "em-core-mailbox.h"
+#include "em-core-mesg.h"
+#include "em-core-mime.h"
+#include "em-core-utils.h"
+#include "em-core-smtp.h"
+#include "em-core-account.h"
+#include "em-storage.h"
+#include "flstring.h"
+#include "emf-dbglog.h"
+
+#define MAX_CHARSET_VALUE 256
+
+static char g_append_uid_rsp[129]; /* added for getting server response */
+
+extern void imap_parse_body_structure (MAILSTREAM *stream, BODY *body, unsigned char **txtptr, IMAPPARSEDREPLY *reply);
+
+#ifdef __FEATURE_PARTIAL_BODY_DOWNLOAD__
+static emf_partial_buffer *em_core_get_response_from_server (NETSTREAM *nstream, char *tag, IMAPPARSEDREPLY **reply);
+static int em_core_initiate_pbd(MAILSTREAM *stream, int account_id, int mail_id, char *uid, char *mailbox, int *err_code);
+#endif
+
+#ifdef __FEATURE_SYNC_CLIENT_TO_SERVER__
+static char g_append_uid_rsp[129]; /* added for getting server response */
+#endif
+
+
+int pop3_mail_calc_rfc822_size(MAILSTREAM *stream, int msgno, int *size, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ int ret = false;
+ int err = EMF_ERROR_NONE;
+
+ POP3LOCAL *pop3local = NULL;
+ char command[16];
+ char *response = NULL;
+
+ if (!stream || !size) {
+ EM_DEBUG_EXCEPTION(" stream[%p], msgno[%d], size[%p]\n", stream, msgno, size);
+
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ if (!(pop3local = stream->local) || !pop3local->netstream) {
+ err = EMF_ERROR_INVALID_STREAM;
+ goto FINISH_OFF;
+ }
+
+ memset(command, 0x00, sizeof(command));
+
+ SNPRINTF(command, sizeof(command), "LIST %d\015\012", msgno);
+
+ /* EM_DEBUG_LOG(" [POP3] >>> %s", command); */
+
+ /* send command : get rfc822 size by msgno */
+ if (!net_sout(pop3local->netstream, command, (int)strlen(command))) {
+ EM_DEBUG_EXCEPTION(" net_sout failed...");
+
+ err = EMF_ERROR_INVALID_RESPONSE;
+ goto FINISH_OFF;
+ }
+
+ /* receive response */
+ if (!(response = net_getline(pop3local->netstream))) {
+ err = EMF_ERROR_CONNECTION_BROKEN; /* EMF_ERROR_UNKNOWN; */
+ goto FINISH_OFF;
+ }
+
+ /* EM_DEBUG_LOG(" [POP3] <<< %s", response); */
+
+ if (*response == '+') { /* "+ OK" */
+ char *p = NULL;
+
+ if (!(p = strchr(response + strlen("+OK "), ' '))) {
+ err = EMF_ERROR_INVALID_RESPONSE;
+ goto FINISH_OFF;
+ }
+
+ *size = atoi(p + 1);
+ }
+ else if (*response == '-') { /* "- ERR" */
+ err = EMF_ERROR_POP3_LIST_FAILURE;
+ goto FINISH_OFF;
+ }
+ else {
+ err = EMF_ERROR_INVALID_RESPONSE;
+ goto FINISH_OFF;
+ }
+
+ ret = true;
+
+FINISH_OFF:
+ EM_SAFE_FREE(response);
+
+ if (err_code != NULL)
+ *err_code = err;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+int imap4_mail_calc_rfc822_size(MAILSTREAM *stream, int msgno, int *size, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ int ret = false;
+ int err = EMF_ERROR_NONE;
+
+ IMAPLOCAL *imaplocal = NULL;
+ char tag[32], command[128];
+ char *response = NULL;
+
+ if (!stream || !size) {
+ EM_DEBUG_EXCEPTION("stream[%p], msgno[%d], size[%p]", stream, msgno, size);
+
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ if (!(imaplocal = stream->local) || !imaplocal->netstream) {
+ err = EMF_ERROR_INVALID_STREAM;
+ goto FINISH_OFF;
+ }
+
+ memset(tag, 0x00, sizeof(tag));
+ memset(command, 0x00, sizeof(command));
+
+ SNPRINTF(tag, sizeof(tag), "%08lx", 0xffffffff & (stream->gensym++));
+ SNPRINTF(command, sizeof(command), "%s FETCH %d RFC822.SIZE\015\012", tag, msgno);
+
+ /* EM_DEBUG_LOG(" [IMAP4] >>> %s", command); */
+
+ /* send command : get rfc822 size by msgno */
+ if (!net_sout(imaplocal->netstream, command, (int)strlen(command))) {
+ EM_DEBUG_EXCEPTION(" net_sout failed...");
+
+ err = EMF_ERROR_INVALID_RESPONSE;
+ goto FINISH_OFF;
+ }
+
+ while (imaplocal->netstream) {
+ char *s = NULL;
+ char *t = NULL;
+
+ /* receive response */
+ if (!(response = net_getline(imaplocal->netstream)))
+ break;
+
+ /* EM_DEBUG_LOG(" [IMAP4] <<< %s", response); */
+
+ if (!strncmp(response, tag, strlen(tag))) {
+ if (!strncmp(response + strlen(tag) + 1, "OK", 2)) {
+ EM_SAFE_FREE(response);
+ break;
+ }
+ else { /* 'NO' or 'BAD' */
+ err = EMF_ERROR_IMAP4_FETCH_SIZE_FAILURE; /* EMF_ERROR_INVALID_RESPONSE; */
+ goto FINISH_OFF;
+ }
+ }
+ else { /* untagged response */
+ if (*response == '*') {
+ if (!(t = strstr(response, "FETCH (RFC822.SIZE "))) {
+ EM_SAFE_FREE(response);
+ continue;
+ }
+
+ s = t + strlen("FETCH (RFC822.SIZE ");
+
+ if (!(t = strchr(s, ' '))) {
+ err = EMF_ERROR_INVALID_RESPONSE;
+ goto FINISH_OFF;
+ }
+
+ *t = '\0';
+
+ *size = atoi(s);
+ }
+ }
+
+ EM_SAFE_FREE(response);
+ }
+
+ ret = true;
+
+FINISH_OFF:
+ EM_SAFE_FREE(response);
+
+ if (err_code != NULL)
+ *err_code = err;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+int pop3_mailbox_get_uids(MAILSTREAM *stream, em_core_uid_list** uid_list, int *err_code)
+{
+ EM_PROFILE_BEGIN(pop3MailboxGetuid);
+ EM_DEBUG_FUNC_BEGIN("stream[%p], uid_list[%p], err_code[%p]", stream, uid_list, err_code);
+
+ int ret = false;
+ int err = EMF_ERROR_NONE;
+
+ POP3LOCAL *pop3local = NULL;
+ char command[64];
+ char *response = NULL;
+ em_core_uid_list *uid_elem = NULL;
+
+ if (!stream || !uid_list) {
+ EM_DEBUG_EXCEPTION("stream[%p], uid_list[%p]n", stream, uid_list);
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ if (!(pop3local = stream->local) || !pop3local->netstream) {
+ EM_DEBUG_EXCEPTION("invalid POP3 stream detected...");
+ err = EMF_ERROR_INVALID_STREAM;
+ goto FINISH_OFF;
+ }
+
+ memset(command, 0x00, sizeof(command));
+
+ SNPRINTF(command, sizeof(command), "UIDL\015\012");
+
+#ifdef FEATURE_CORE_DEBUG
+ EM_DEBUG_LOG(" [POP3] >>> [%s]", command);
+#endif
+
+ /* send command : get msgno/uid for all message */
+ if (!net_sout(pop3local->netstream, command, (int)strlen(command))) {
+ EM_DEBUG_EXCEPTION("net_sout failed...");
+ err = EMF_ERROR_CONNECTION_BROKEN; /* EMF_ERROR_UNKNOWN; */
+ goto FINISH_OFF;
+ }
+
+ *uid_list = NULL;
+
+ while (pop3local->netstream) {
+ char *p = NULL;
+
+ /* receive response */
+ if (!(response = net_getline(pop3local->netstream))) {
+ EM_DEBUG_EXCEPTION("net_getline failed...");
+ err = EMF_ERROR_INVALID_RESPONSE;
+ goto FINISH_OFF;
+ }
+
+#ifdef FEATURE_CORE_DEBUG
+ EM_DEBUG_LOG(" [POP3] <<< [%s]", response);
+#endif
+
+ if (*response == '-') { /* "-ERR" */
+ err = EMF_ERROR_POP3_UIDL_FAILURE; /* EMF_ERROR_INVALID_RESPONSE; */
+ goto FINISH_OFF;
+ }
+
+ if (*response == '+') { /* "+OK" */
+ free(response); response = NULL;
+ continue;
+ }
+
+ if (*response == '.') {
+ free(response); response = NULL;
+ break;
+ }
+
+ if ((p = strchr(response, ' '))) {
+ *p = '\0';
+
+ if (!(uid_elem = em_core_malloc(sizeof(em_core_uid_list)))) {
+ EM_DEBUG_EXCEPTION("malloc failed...");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ uid_elem->msgno = atoi(response);
+ uid_elem->uid = EM_SAFE_STRDUP(p + 1);
+
+ if (*uid_list != NULL)
+ uid_elem->next = *uid_list; /* prepend new data to table */
+
+ *uid_list = uid_elem;
+ }
+ else {
+ err = EMF_ERROR_INVALID_RESPONSE;
+ goto FINISH_OFF;
+ }
+
+ free(response); response = NULL;
+ }
+
+ ret = true;
+
+FINISH_OFF:
+ if (response != NULL)
+ free(response);
+
+ if (err_code != NULL)
+ *err_code = err;
+
+ EM_PROFILE_END(pop3MailboxGetuid);
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+int imap4_mailbox_get_uids(MAILSTREAM *stream, em_core_uid_list** uid_list, int *err_code)
+{
+ EM_PROFILE_BEGIN(ImapMailboxGetUids);
+ EM_DEBUG_FUNC_BEGIN("stream[%p], uid_list[%p], err_code[%p]", stream, uid_list, err_code);
+
+ int ret = false;
+ int err = EMF_ERROR_NONE;
+
+ IMAPLOCAL *imaplocal = NULL;
+ char tag[16], command[64];
+ char *response = NULL;
+ em_core_uid_list *uid_elem = NULL;
+
+ if (!stream || !uid_list) {
+ EM_DEBUG_EXCEPTION("stream[%p], uid_list[%p]", stream, uid_list);
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ if (!(imaplocal = stream->local) || !imaplocal->netstream) {
+ EM_DEBUG_EXCEPTION("invalid IMAP4 stream detected...");
+ err = EMF_ERROR_INVALID_PARAM; /* EMF_ERROR_UNKNOWN */
+ goto FINISH_OFF;
+ }
+
+ if (stream->nmsgs == 0){
+ err = EMF_ERROR_MAIL_NOT_FOUND_ON_SERVER;
+ goto FINISH_OFF;
+ }
+ memset(tag, 0x00, sizeof(tag));
+ memset(command, 0x00, sizeof(command));
+
+ SNPRINTF(tag, sizeof(tag), "%08lx", 0xffffffff & (stream->gensym++));
+ SNPRINTF(command, sizeof(command), "%s FETCH 1:* (FLAGS UID)\015\012", tag); /* TODO : confirm me */
+ EM_DEBUG_LOG("COMMAND [%s] \n", command);
+#ifdef FEATURE_CORE_DEBUG
+ EM_DEBUG_LOG(" [IMAP4] >>> [%s]", command);
+#endif
+
+ /* send command : get msgno/uid for all message */
+ if (!net_sout(imaplocal->netstream, command, (int)strlen(command))) {
+ EM_DEBUG_EXCEPTION(" net_sout failed...\n");
+ err = EMF_ERROR_CONNECTION_BROKEN;
+ goto FINISH_OFF;
+ }
+
+ *uid_list = NULL;
+
+ while (imaplocal->netstream) {
+ char *p = NULL;
+ char *s = NULL;
+ int seen = 0;
+ int forwarded = 0;
+ int draft = 0;
+ /* receive response */
+ if (!(response = net_getline(imaplocal->netstream))) {
+ EM_DEBUG_EXCEPTION("net_getline failed...");
+ err = EMF_ERROR_INVALID_RESPONSE;
+ goto FINISH_OFF;
+ }
+
+#ifdef FEATURE_CORE_DEBUG
+ EM_DEBUG_LOG(" [IMAP4] <<< [%s]", response);
+#endif
+
+ if (!strncmp(response, tag, strlen(tag))) {
+ if (!strncmp(response + strlen(tag) + 1, "OK", 2)) {
+ free(response); response = NULL;
+ break;
+ }
+ else { /* 'NO' or 'BAD' */
+ err = EMF_ERROR_IMAP4_FETCH_UID_FAILURE; /* EMF_ERROR_INVALID_RESPONSE; */
+ goto FINISH_OFF;
+ }
+ }
+
+ if ((p = strstr(response, " FETCH ("))) {
+ if (!strstr(p, "\\Deleted")) { /* undeleted only */
+ *p = '\0'; p += strlen(" FETCH ");
+
+ seen = strstr(p, "\\Seen") ? 1 : 0;
+ draft = strstr(p, "\\Draft") ? 1 : 0;
+ forwarded = strstr(p, "$Forwarded") ? 1 : 0;
+
+ if ((p = strstr(p, "UID "))) {
+ s = p + strlen("UID ");
+
+ while (isdigit(*s))
+ s++;
+
+ *s = '\0';
+
+ if (!(uid_elem = em_core_malloc(sizeof(em_core_uid_list)))) {
+ EM_DEBUG_EXCEPTION("em_core_malloc failed...");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ uid_elem->msgno = atoi(response + strlen("* "));
+ uid_elem->uid = EM_SAFE_STRDUP(p + strlen("UID "));
+ uid_elem->flag.seen = seen;
+ uid_elem->flag.draft = draft;
+ uid_elem->flag.forwarded = forwarded;
+ if (*uid_list != NULL)
+ uid_elem->next = *uid_list; /* prepend new data to list */
+
+ *uid_list = uid_elem;
+ }
+ else {
+ err = EMF_ERROR_INVALID_RESPONSE;
+ goto FINISH_OFF;
+ }
+ }
+ }
+ else {
+ err = EMF_ERROR_INVALID_RESPONSE;
+ goto FINISH_OFF;
+ }
+
+ EM_SAFE_FREE(response);;
+ }
+
+ ret = true;
+
+FINISH_OFF:
+ EM_SAFE_FREE(response);
+
+ if (err_code != NULL)
+ *err_code = err;
+
+ EM_PROFILE_END(ImapMailboxGetUids);
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+static char *__em_get_month_in_string(int month)
+{
+ EM_DEBUG_FUNC_BEGIN("month [%d]", month);
+
+ char *mon = NULL;
+
+ switch (month){
+ case 0:
+ mon = EM_SAFE_STRDUP("jan");
+ break;
+ case 1:
+ mon = EM_SAFE_STRDUP("feb");
+ break;
+ case 2:
+ mon = EM_SAFE_STRDUP("mar");
+ break;
+ case 3:
+ mon = EM_SAFE_STRDUP("apr");
+ break;
+ case 4:
+ mon = EM_SAFE_STRDUP("may");
+ break;
+ case 5:
+ mon = EM_SAFE_STRDUP("jun");
+ break;
+ case 6:
+ mon = EM_SAFE_STRDUP("jul");
+ break;
+ case 7:
+ mon = EM_SAFE_STRDUP("aug");
+ break;
+ case 8:
+ mon = EM_SAFE_STRDUP("sep");
+ break;
+ case 9:
+ mon = EM_SAFE_STRDUP("oct");
+ break;
+ case 10:
+ mon = EM_SAFE_STRDUP("nov");
+ break;
+ case 11:
+ mon = EM_SAFE_STRDUP("dec");
+ break;
+ }
+ return mon;
+}
+
+int imap4_mailbox_get_uids_by_timestamp(MAILSTREAM *stream, em_core_uid_list** uid_list, int *err_code)
+{
+ EM_PROFILE_BEGIN(emCoreMailboxuidsbystamp);
+ EM_DEBUG_FUNC_BEGIN("stream[%p], uid_list[%p], err_code[%p]", stream, uid_list, err_code);
+
+ int ret = false;
+ int err = EMF_ERROR_NONE;
+
+ IMAPLOCAL *imaplocal = NULL;
+ char tag[16], command[64];
+ char *response = NULL;
+ em_core_uid_list *uid_elem = NULL;
+ char delims[] = " ";
+ char *result = NULL;
+
+ struct tm *timeinfo = NULL;
+ time_t RawTime = 0;
+ time_t week_before_RawTime = 0;
+ char date_string[16];
+ char *mon = NULL;
+
+ if (!stream || !uid_list) {
+ EM_DEBUG_EXCEPTION(" stream[%p], uid_list[%p]", stream, uid_list);
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ if (!(imaplocal = stream->local) || !imaplocal->netstream) {
+ EM_DEBUG_EXCEPTION(" invalid IMAP4 stream detected...");
+ err = EMF_ERROR_INVALID_PARAM; /* EMF_ERROR_UNKNOWN */
+ goto FINISH_OFF;
+ }
+
+ /* Fetch the System time and Retrieve the a Week before time */
+ /* tzset(); */
+ time(&RawTime);
+
+ EM_DEBUG_LOG("RawTime Info [%lu]", RawTime);
+
+ timeinfo = localtime (&RawTime);
+
+ EM_DEBUG_LOG(">>>>>Current TIme %d %d %d %d %d %d", 1900+timeinfo->tm_year, timeinfo->tm_mon+1, timeinfo->tm_mday);
+
+ week_before_RawTime = RawTime - 604800;
+
+ /* Reading the current timeinfo */
+ timeinfo = localtime (&week_before_RawTime);
+
+ EM_DEBUG_LOG(">>>>>Mobile Date a Week before %d %d %d %d %d %d", 1900 + timeinfo->tm_year, timeinfo->tm_mon+1, timeinfo->tm_mday);
+
+ memset(&date_string, 0x00, 16);
+
+ mon = __em_get_month_in_string(timeinfo->tm_mon);
+
+ if (mon){
+ snprintf(date_string, 16, "%d-%s-%04d", timeinfo->tm_mday, mon, 1900 + timeinfo->tm_year);
+ EM_DEBUG_LOG("DATE IS [ %s ] ", date_string);
+ EM_SAFE_FREE(mon);
+ }
+
+ memset(tag, 0x00, sizeof(tag));
+ memset(command, 0x00, sizeof(command));
+
+ SNPRINTF(tag, sizeof(tag), "%08lx", 0xffffffff & (stream->gensym++));
+
+ /* SNPRINTF(command, sizeof(command), "%s UID SEARCH 1:* SINCE 17-Aug-2009\015\012", tag, date_string); */ /* TODO : confirm me */
+
+ SNPRINTF(command, sizeof(command), "%s UID SEARCH 1:* SINCE %s\015\012", tag, date_string); /* TODO : confirm me */
+
+ EM_DEBUG_LOG("COMMAND [%s] ", command);
+
+
+#ifdef FEATURE_CORE_DEBUG
+ EM_DEBUG_LOG(" [IMAP4] >>> [%s]", command);
+#endif
+
+ /* send command : get msgno/uid for all message */
+ if (!net_sout(imaplocal->netstream, command, (int)strlen(command))) {
+ EM_DEBUG_EXCEPTION(" net_sout failed...");
+ err = EMF_ERROR_CONNECTION_BROKEN; /* EMF_ERROR_UNKNOWN */
+ goto FINISH_OFF;
+ }
+
+ *uid_list = NULL;
+
+ while (imaplocal->netstream) {
+ char *p = NULL;
+ /* receive response */
+ if (!(response = net_getline(imaplocal->netstream))) {
+ EM_DEBUG_EXCEPTION(" net_getline failed...");
+ err = EMF_ERROR_INVALID_RESPONSE; /* EMF_ERROR_UNKNOWN; */
+ goto FINISH_OFF;
+ }
+#ifdef FEATURE_CORE_DEBUG
+ EM_DEBUG_LOG(" [IMAP4] <<< [%s]", response);
+#endif
+
+ if (!strncmp(response, tag, strlen(tag))) {
+ if (!strncmp(response + strlen(tag) + 1, "OK", 2)) {
+ free(response); response = NULL;
+ break;
+ }
+ else { /* 'NO' or 'BAD' */
+ err = EMF_ERROR_IMAP4_FETCH_UID_FAILURE; /* EMF_ERROR_INVALID_RESPONSE; */
+ goto FINISH_OFF;
+ }
+ }
+
+ if ((p = strstr(response, " SEARCH "))){
+ *p = '\0'; p += strlen(" SEARCH ");
+
+ result = strtok(p, delims);
+
+ while (result != NULL)
+ {
+ EM_DEBUG_LOG("UID VALUE DEEP is [%s]", result);
+
+ if (!(uid_elem = em_core_malloc(sizeof(em_core_uid_list)))) {
+ EM_DEBUG_EXCEPTION(" malloc failed...");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ uid_elem->uid = EM_SAFE_STRDUP(result);
+
+ if (*uid_list != NULL)
+ uid_elem->next = *uid_list;
+ *uid_list = uid_elem;
+ result = strtok(NULL, delims);
+ }
+
+ EM_SAFE_FREE(response);
+ return 1;
+ }
+ else {
+ err = EMF_ERROR_INVALID_RESPONSE;
+ goto FINISH_OFF;
+ }
+
+ free(response); response = NULL;
+ }
+
+ ret = true;
+
+FINISH_OFF:
+ if (response != NULL)
+ free(response);
+
+ if (err_code != NULL)
+ *err_code = err;
+ EM_PROFILE_END(emCoreMailboxuidsbystamp);
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+#define PARSE_BUFFER_LENGTH 4096
+static int em_core_mailbox_parse_header(char *rfc822_header, int *req_read_receipt, int *priority, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("rfc822_header[%p], req_read_receipt[%p], priority[%p], err_code[%p]", rfc822_header, req_read_receipt, priority, err_code);
+
+ if (!rfc822_header || !priority)
+ return false;
+
+ if (err_code)
+ *err_code = EMF_ERROR_NONE;
+
+ EM_PROFILE_BEGIN(emCoreMailboxParseHeader);
+
+ /* char *buf = NULL; */
+ char buf[PARSE_BUFFER_LENGTH];
+ int len, i, j;
+ /* int buf_length = strlen(rfc822_header)+1; */
+
+ EM_DEBUG_LOG("Buffer length [%d]", PARSE_BUFFER_LENGTH);
+ /*
+ buf = (char *) malloc(sizeof(char) * (buf_length));
+
+ if (!buf) {
+ EM_DEBUG_EXCEPTION("buf is NULL");
+ return false;
+ }
+ */
+ *priority = 3;
+
+ memset(buf, 0x00, PARSE_BUFFER_LENGTH);
+
+ for (len = strlen(rfc822_header), i = 0, j = 0; i < len; i++) {
+ if (rfc822_header[i] == CR && rfc822_header[i+1] == LF){
+ if (j + 3 < PARSE_BUFFER_LENGTH) /* '3' include CR LF NULL */
+ strncpy(buf + j, CRLF_STRING, PARSE_BUFFER_LENGTH - (j + 2)); /* '3' include CR LF */
+ else
+ EM_DEBUG_EXCEPTION("buf is too small.");
+
+ i++;
+ j = 0;
+
+ /* parsing data */
+ em_core_upper_string(buf);
+
+ /* message-id */
+/* if (buf[0] == 'M' && buf[3] == 'S' && buf[6] == 'E' && buf[7] == '-' && buf[8] == 'I') { */
+/* buf[strlen(buf)-2] = '\0'; */
+/* if (buf[12]) *message_id = EM_SAFE_STRDUP(buf+12); */
+/* memset(buf, 0x00, sizeof(buf)); */
+/* continue; */
+/* } */
+
+ /* disposition_notification_to */
+ if (buf[0] == 'D' && buf[11] == '-' && buf[12] == 'N' && buf[24] == '-' && buf[25] == 'T') {
+ if (req_read_receipt)
+ *req_read_receipt = 1;
+ memset(buf, 0x00, PARSE_BUFFER_LENGTH);
+ continue;
+ }
+
+ /* x-priority */
+ if (buf[0] == 'X' && buf[2] == 'P' && buf[9] == 'Y'){
+ size_t len_2 = strlen(buf);
+ if (len_2 >= 12){
+ buf[len_2 - 2] = '\0';
+ *priority = atoi(buf + 11);
+ memset(buf, 0x00, PARSE_BUFFER_LENGTH);
+ continue;
+ }
+ }
+
+ /* x-msmail-priority */
+ if (buf[0] == 'X' && buf[2] == 'M' && buf[9] == 'P' && buf[16] == 'Y'){
+ if (strstr(buf, "HIGH"))
+ *priority = 1;
+ if (strstr(buf, "NORMAL"))
+ *priority = 3;
+ if (strstr(buf, "LOW"))
+ *priority = 5;
+ memset(buf, 0x00, PARSE_BUFFER_LENGTH);
+ continue;
+ }
+
+ memset(buf, 0x00, PARSE_BUFFER_LENGTH);
+ continue;
+ }
+
+ if (j + 1 < PARSE_BUFFER_LENGTH)
+ buf[j++] = rfc822_header[i];
+ else
+ EM_DEBUG_EXCEPTION("buf is too small.");
+ }
+
+ /*
+ EM_SAFE_FREE(buf);
+ */
+ EM_PROFILE_END(emCoreMailboxParseHeader);
+
+ if (err_code)
+ *err_code = EMF_ERROR_NONE;
+
+ return true;
+}
+
+
+static int em_core_mail_get_extra_info(MAILSTREAM *stream, int msgno, int *req_read_receipt, int *priority, int *err_code)
+{
+ EM_PROFILE_BEGIN(emCoreMailGetExtraInfo);
+ EM_DEBUG_FUNC_BEGIN("stream[%p], msgno[%d], req_read_receipt[%p], priority[%p], err_code[%p]", stream, msgno, req_read_receipt, priority, err_code);
+
+ int ret = false;
+ int err = EMF_ERROR_NONE;
+ char *rfc822_header = NULL;
+ unsigned long len = 0;
+
+ EM_PROFILE_BEGIN(MaiFetchHeader);
+#ifdef __FEATURE_HEADER_OPTIMIZATION__
+ /* Check if header already available in cache */
+ if (stream && stream->cache && stream->cache[msgno-1]->private.msg.header.text.data){
+ EM_DEBUG_LOG("I found the header in stream->cache!!");
+ rfc822_header = (char *) stream->cache[msgno-1]->private.msg.header.text.data;
+ }
+ else{
+ EM_DEBUG_LOG("I couldn't find the header. I'll fetch the header from server again.");
+ if (stream)
+ rfc822_header = mail_fetch_header(stream, msgno, NULL, NULL, &len, FT_PEEK);
+ }
+
+#else
+ rfc822_header = mail_fetch_header(stream, msgno, NULL, NULL, &len, FT_PEEK);
+#endif
+ EM_PROFILE_END(MaiFetchHeader);
+
+ if (!rfc822_header || !*rfc822_header) {
+ EM_DEBUG_EXCEPTION("mail_fetch_header failed...");
+ err = EMF_ERROR_IMAP4_FETCH_UID_FAILURE; /* EMF_ERROR_UNKNOWN; */
+ goto FINISH_OFF;
+ }
+
+ if (!em_core_mailbox_parse_header(rfc822_header, req_read_receipt, priority, &err)) {
+ EM_DEBUG_EXCEPTION("em_core_mailbox_parse_header falied - %d", err);
+ goto FINISH_OFF;
+ }
+ ret = true;
+
+FINISH_OFF:
+
+ if (err_code != NULL)
+ *err_code = err;
+
+ EM_PROFILE_END(emCoreMailGetExtraInfo);
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+static int em_core_mailbox_get_uids_to_download(MAILSTREAM *stream, emf_account_t *account, emf_mailbox_tbl_t *input_mailbox_tbl, int limit_count, em_core_uid_list** uid_list, int *uids, int retrieve_mode , int *err_code)
+{
+ EM_PROFILE_BEGIN(emCoreGetUidsDownload);
+ EM_DEBUG_FUNC_BEGIN("account[%p], input_mailbox_tbl[%p], limit_count[%d], uid_list[%p], err_code[%p]", account, input_mailbox_tbl, limit_count, uid_list, err_code);
+
+ int ret = false;
+ int err = EMF_ERROR_NONE;
+
+ emf_mail_read_mail_uid_tbl_t *downloaded_uids = NULL;
+ emf_mail_info_t *mail_info = NULL;
+ int i = 0, j = 0, uid_count = 0, uid_to_be_downloaded_count = 0;
+ em_core_uid_list *uid_elem = NULL;
+ em_core_uid_list *head_uid_elem = NULL, *end = NULL;
+ em_core_uid_list *next_uid_elem = NULL;
+ emf_mail_tbl_t *mail = NULL;
+
+ if (!account || !input_mailbox_tbl || !uid_list) {
+ EM_DEBUG_EXCEPTION("account[%p], input_mailbox_tbl[%p], uid_list[%p]", account, input_mailbox_tbl, uid_list);
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ *uid_list = NULL;
+
+ if (account->receiving_server_type == EMF_SERVER_TYPE_POP3) {
+ if (!pop3_mailbox_get_uids(stream, uid_list, &err)) {
+ EM_DEBUG_EXCEPTION("pop3_mailbox_get_uids failed - %d", err);
+ goto FINISH_OFF;
+ }
+ }
+ else { /* EMF_SERVER_TYPE_IMAP4 */
+ /* sowmya.kr commented , since imap4_mailbox_get_uids_by_timestamp will fetch mails since last week and not all mails */
+
+ EM_DEBUG_LOG("calling imap4_mailbox_get_uids");
+ if (!imap4_mailbox_get_uids(stream, uid_list, &err)) {
+ EM_DEBUG_EXCEPTION("imap4_mailbox_get_uids failed [%d]", err);
+ if (err != EMF_ERROR_MAIL_NOT_FOUND_ON_SERVER)
+ goto FINISH_OFF;
+ }
+ }
+
+ if (!em_storage_get_downloaded_list(input_mailbox_tbl->account_id, input_mailbox_tbl->mailbox_name, &downloaded_uids, &j, true, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_get_downloaded_list failed [%d]", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+ EM_DEBUG_LOG("Number of Mails in Downloaded Table [%d]", j);
+
+ uid_elem = *uid_list;
+ uid_count = 0;
+
+ if(!uid_elem) { /* If there is no mail in the input_mailbox_tbl, remove all mails in the input_mailbox_tbl */
+ for (i = 0; i < j; i++) {
+ downloaded_uids[i].reserved = 0;
+ }
+ }
+
+ EM_PROFILE_BEGIN(emCoreGetUidsDownloadWhilwLoop);
+
+ while (uid_elem) {
+ next_uid_elem = uid_elem->next;
+
+ if ((account->retrieval_mode == EMF_IMAP4_RETRIEVAL_MODE_NEW) && (uid_elem->flag.seen != 0)){ /* already seen */
+ if (uid_elem->uid)
+ free(uid_elem->uid);
+
+ free(uid_elem);
+ }
+ else {
+ int to_be_downloaded = 1;
+
+ if (limit_count > 0 && uid_count >= limit_count){
+ /* EM_DEBUG_LOG("hit the limit[%d] for [%s]", limit_count, uid_elem->uid); */
+ to_be_downloaded = 0;
+ }
+ else{
+ for (i = j; i > 0; i--) {
+ if (downloaded_uids[i - 1].reserved == 0 && !strcmp(uid_elem->uid, downloaded_uids[i - 1].s_uid)) {
+ downloaded_uids[i - 1].reserved = uid_elem->flag.seen ? 2 : 1;
+ to_be_downloaded = 0;
+ break;
+ }
+ }
+ }
+
+ /* EM_DEBUG_LOG("Is uid[%s] going to be downloded ? [%d]", uid_elem->uid, to_be_downloaded); */
+
+ if (to_be_downloaded) {
+ if (retrieve_mode == EMF_SYNC_OLDEST_MAILS_FIRST){
+ uid_elem->next = head_uid_elem;
+ head_uid_elem = uid_elem;
+ }
+ else{ /* if retrieve_mode is EMF_SYNC_LATEST_MAILS_FIRST, add uid elem to end so that latest mails are in front of list */
+ if (head_uid_elem == NULL){
+ uid_elem->next = head_uid_elem;
+ head_uid_elem = uid_elem;
+ end = head_uid_elem;
+ }
+ else{
+ end->next = uid_elem;
+ uid_elem->next = NULL;
+ end = uid_elem;
+ }
+ }
+ uid_to_be_downloaded_count++;
+
+ }
+ else {
+ if (uid_elem->uid)
+ free(uid_elem->uid);
+ free(uid_elem);
+ }
+
+ uid_count++;
+ }
+
+ uid_elem = next_uid_elem;
+ }
+
+ EM_PROFILE_END(emCoreGetUidsDownloadWhilwLoop);
+ EM_PROFILE_BEGIN(emCoreGetUidsDownloadForLoop);
+
+ for (i = 0; i < j; i++) {
+ /* EM_DEBUG_LOG("input_mailbox_tbl[%s] reserved[%d]", input_mailbox_tbl->name, downloaded_uids[i].reserved); */
+ if (downloaded_uids[i].reserved == 0) { /* deleted on server */
+ if (!em_storage_get_maildata_by_servermailid(input_mailbox_tbl->account_id, downloaded_uids[i].s_uid, &mail, true, &err)){
+ EM_DEBUG_EXCEPTION("em_storage_get_maildata_by_servermailid for uid[%s] Failed [%d] \n ", downloaded_uids[i].s_uid, err);
+ if (err == EM_STORAGE_ERROR_MAIL_NOT_FOUND){
+ continue;
+ }
+ }
+
+ if (account->receiving_server_type == EMF_SERVER_TYPE_IMAP4) {
+ if (!em_core_mail_delete_from_local(input_mailbox_tbl->account_id, &(mail->mail_id), 1, EMF_DELETED_FROM_SERVER, false, &err)) {
+ EM_DEBUG_EXCEPTION("em_core_mail_delete_from_local falied - %d", err);
+ goto FINISH_OFF;
+ }
+ /* em_core_delete_notification_for_read_mail(mail->mail_id); */
+ em_core_check_unread_mail();
+ }
+
+ if (!em_storage_remove_downloaded_mail(input_mailbox_tbl->account_id, input_mailbox_tbl->mailbox_name, downloaded_uids[i].s_uid, true, &err)) { /* remove uid from uid list */
+ EM_DEBUG_EXCEPTION("em_storage_remove_downloaded_mail failed - %d", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ /* goto FINISH_OFF; */
+ }
+
+ }
+ else if (account->receiving_server_type == EMF_SERVER_TYPE_IMAP4 && downloaded_uids[i].reserved == 1) {
+ /* unseen on server */
+ if (!em_core_mail_get_info(downloaded_uids[i].local_uid, &mail_info, &err)){
+ EM_DEBUG_EXCEPTION("em_core_mail_get_info failed for [%d] - [%d]", downloaded_uids[i].local_uid, err);
+ continue;
+ }
+
+ if (mail_info) {
+ if (mail_info->body_downloaded && mail_info->flags.seen){
+ EM_DEBUG_LOG("Set flag as seen on server");
+ mail_setflag_full(stream, downloaded_uids[i].s_uid, "\\Seen", ST_UID);
+ }
+ em_core_mail_info_free(&mail_info, 1, NULL);
+ mail_info = NULL;
+ }
+
+ }
+ }
+ EM_PROFILE_END(emCoreGetUidsDownloadForLoop);
+
+ *uid_list = head_uid_elem;
+ *uids = uid_to_be_downloaded_count;
+
+ ret = true;
+
+FINISH_OFF:
+ if (ret == false){
+ if (head_uid_elem)
+ em_core_mailbox_free_uids(head_uid_elem, NULL);
+ }
+
+ if (mail_info != NULL)
+ em_core_mail_info_free(&mail_info, 1, NULL);
+
+ if (downloaded_uids != NULL)
+ em_storage_free_read_mail_uid(&downloaded_uids, j, NULL);
+
+ if (mail != NULL)
+ em_storage_free_mail(&mail, 1, NULL);
+
+ if (err_code != NULL)
+ *err_code = err;
+
+ EM_PROFILE_END(emCoreGetUidsDownload);
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+/* insert received mail UID to read mail uid table */
+static int em_core_mailbox_add_read_mail_uid(emf_mailbox_tbl_t *input_maibox_data, char *server_mailbox_name, int mail_id, char *uid, int rfc822_size, int rule_id, int *err_code)
+{
+ EM_PROFILE_BEGIN(emCoreMailboxAddReadMailUid);
+ EM_DEBUG_FUNC_BEGIN("input_maibox_data[%p], server_mailbox_name[%s], uid[%s], rfc822_size[%d], rule_id[%d], err_code[%p]", input_maibox_data, server_mailbox_name, uid, rfc822_size, rule_id, err_code);
+
+ int ret = false;
+ int err = EMF_ERROR_NONE;
+
+ emf_mail_read_mail_uid_tbl_t read_mail_uid = { 0 };
+ char *mailbox_name = NULL;
+
+ if (!input_maibox_data || !uid) {
+ EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ read_mail_uid.account_id = input_maibox_data->account_id;
+
+ if (!(input_maibox_data->mailbox_name) || !(server_mailbox_name)){
+ if (!em_storage_get_mailboxname_by_mailbox_type(input_maibox_data->account_id, EMF_MAILBOX_TYPE_INBOX, &mailbox_name, false, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_get_mailboxname_by_mailbox_type failed [%d]", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+ }
+
+ if (input_maibox_data->mailbox_name)
+ read_mail_uid.local_mbox = input_maibox_data->mailbox_name;
+ else
+ read_mail_uid.local_mbox = mailbox_name;
+
+ read_mail_uid.local_uid = mail_id;
+ EM_DEBUG_LOG("MAIL ID [%d] LOCAL_UID [%d]", mail_id, read_mail_uid.local_uid);
+
+ if (server_mailbox_name)
+ read_mail_uid.mailbox_name = server_mailbox_name;
+ else
+ read_mail_uid.mailbox_name = mailbox_name;
+
+ read_mail_uid.s_uid = uid;
+ read_mail_uid.data1 = rfc822_size;
+ read_mail_uid.flag = rule_id;
+
+ if (!em_storage_add_downloaded_mail(&read_mail_uid, false, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_add_downloaded_mail failed [%d]", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+
+ ret = true;
+
+FINISH_OFF:
+ EM_SAFE_FREE(mailbox_name);
+
+ if (err_code)
+ *err_code = err;
+
+ EM_PROFILE_END(emCoreMailboxAddReadMailUid);
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+static int em_core_mail_add_header(MAILSTREAM *mail_stream, emf_mailbox_tbl_t *input_maibox_data, emf_mail_head_t *head, int to_num, em_core_uid_list *uid_elem, int *mail_id, int *result_thread_id, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("mail_stream [%p], input_maibox_data[%p], head[%p], to_num[%d], uid_elem[%p], mail_id[%p], err_code[%p]", mail_stream, input_maibox_data, head, to_num, uid_elem, mail_id, err_code);
+
+ int ret = false, err = EMF_ERROR_NONE;
+ int req_read_receipt = 0;
+ int priority = 0;
+ int thread_id = -1, thread_item_count = 0, latest_mail_id_in_thread = -1;
+ char datetime[16] = { 0, };
+ MESSAGECACHE *elt = NULL;
+ emf_mail_tbl_t mail_table_data = {0};
+
+ if (!input_maibox_data || !mail_stream || !head || !uid_elem) {
+ EM_DEBUG_EXCEPTION("Invalid Parameter");
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ if (!(elt = mail_elt(mail_stream, uid_elem->msgno))) {
+ EM_DEBUG_EXCEPTION("mail_elt failed...");
+ err = EMF_ERROR_UNKNOWN;
+ goto FINISH_OFF;
+ }
+
+ if (!em_core_mail_get_extra_info(mail_stream, uid_elem->msgno, &req_read_receipt, &priority, &err)) {
+ EM_DEBUG_EXCEPTION("em_core_mail_get_extra_info failed - %d", err);
+ goto FINISH_OFF;
+ }
+
+ SNPRINTF(datetime, sizeof(datetime), "%04d%02d%02d%02d%02d%02d", BASEYEAR + elt->year, elt->month, elt->day, elt->hours, elt->minutes, elt->seconds);
+
+ head->datetime.year = elt->year;
+ head->datetime.month = elt->month;
+ head->datetime.day = elt->day;
+ head->datetime.hour = elt->hours;
+ head->datetime.minute = elt->minutes;
+ head->datetime.second = elt->seconds;
+
+ mail_table_data.account_id = input_maibox_data->account_id;
+ mail_table_data.mailbox_name = input_maibox_data->mailbox_name;
+ mail_table_data.mailbox_type = input_maibox_data->mailbox_type;
+ mail_table_data.subject = head->subject;
+ mail_table_data.datetime = EM_SAFE_STRDUP(datetime);
+ mail_table_data.server_mail_status = 1;
+ mail_table_data.server_mail_id = uid_elem->uid;
+ mail_table_data.message_id = head->mid;
+ mail_table_data.full_address_from = head->from;
+ mail_table_data.full_address_to = head->to;
+ mail_table_data.full_address_cc = head->cc;
+ mail_table_data.full_address_bcc = head->bcc;
+ mail_table_data.full_address_reply = head->reply_to;
+ mail_table_data.full_address_return = head->return_path;
+ mail_table_data.mail_size = elt->rfc822_size;
+ mail_table_data.flags_seen_field = uid_elem->flag.seen;
+ mail_table_data.flags_deleted_field = elt->deleted;
+ mail_table_data.flags_flagged_field = elt->flagged;
+ mail_table_data.flags_answered_field = elt->answered;
+ mail_table_data.flags_recent_field = elt->recent;
+ mail_table_data.flags_draft_field = elt->draft;
+ mail_table_data.flags_forwarded_field = uid_elem->flag.forwarded;
+ mail_table_data.priority = priority;
+ mail_table_data.report_status = (req_read_receipt ? 3 : 0);
+ mail_table_data.attachment_count = 0;
+
+ em_core_fill_address_information_of_mail_tbl(&mail_table_data);
+
+ em_storage_begin_transaction(NULL, NULL, NULL);
+
+ /* Get the Mail_id */
+ if (!em_storage_increase_mail_id(&(mail_table_data.mail_id), false, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_increase_mail_id failed [%d]", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+
+ if (em_storage_get_thread_id_of_thread_mails(&mail_table_data, &thread_id, &latest_mail_id_in_thread, &thread_item_count) != EMF_ERROR_NONE)
+ EM_DEBUG_LOG(" em_storage_get_thread_id_of_thread_mails is failed.");
+
+ if (thread_id == -1){
+ mail_table_data.thread_id = mail_table_data.mail_id;
+ mail_table_data.thread_item_count = thread_item_count = 1;
+ }
+ else {
+ mail_table_data.thread_id = thread_id;
+ thread_item_count++;
+ }
+
+ if (result_thread_id)
+ *result_thread_id = mail_table_data.thread_id;
+
+ EM_DEBUG_LOG("mail_table_data.mail_id [%d]", mail_table_data.mail_id);
+ EM_DEBUG_LOG("mail_table_data.thread_id [%d]", mail_table_data.thread_id);
+
+ if (!em_storage_add_mail(&mail_table_data, 0, false, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_add_mail failed [%d]", err);
+ em_storage_rollback_transaction(NULL, NULL, NULL);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+
+ if (thread_item_count > 1){
+ if (!em_storage_update_latest_thread_mail(mail_table_data.account_id, mail_table_data.thread_id, 0, 0, false, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_update_latest_thread_mail failed [%d]", err);
+ em_storage_rollback_transaction(NULL, NULL, NULL);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+ }
+
+ if (mail_id != NULL)
+ *mail_id = mail_table_data.mail_id;
+
+ if (!em_core_mailbox_add_read_mail_uid(input_maibox_data, input_maibox_data->mailbox_name, mail_table_data.mail_id, uid_elem->uid, mail_table_data.mail_size, 0, &err)) {
+ EM_DEBUG_EXCEPTION("em_core_mailbox_add_read_mail_uid failed [%d]", err);
+ em_storage_rollback_transaction(NULL, NULL, NULL);
+ goto FINISH_OFF;
+ }
+
+ em_storage_commit_transaction(NULL, NULL, NULL);
+ ret = true;
+
+FINISH_OFF:
+
+ EM_SAFE_FREE(mail_table_data.datetime);
+ EM_SAFE_FREE(mail_table_data.email_address_sender);
+ EM_SAFE_FREE(mail_table_data.alias_sender);
+ EM_SAFE_FREE(mail_table_data.email_address_recipient);
+ EM_SAFE_FREE(mail_table_data.alias_recipient);
+
+ if (err_code != NULL)
+ *err_code = err;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+int em_core_mail_check_rule(emf_mail_head_t *head, emf_mail_rule_tbl_t *rule, int rule_len, int *matched, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("head [%p], rule [%p], rule_len [%d], matched [%p], err_code [%p]", head, rule, rule_len, matched, err_code);
+
+ int ret = false, err = EMF_ERROR_NONE, i;
+ size_t len = 0;
+ char *src = NULL; /* string which will be compared with rules */
+ char *from_address = NULL;
+ ADDRESS *addr = NULL;
+
+ if (!matched || !head || !head->from || !head->subject) {
+ EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ *matched = -1;
+
+ for (i = 0; i < rule_len; i++) {
+ if (!(rule + i)) {
+ EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ EM_DEBUG_LOG("rule[%d].flag1(rule id[%d]) is %d", i, rule[i].rule_id, rule[i].flag1);
+
+ if (rule[i].flag1){
+ /* 'ON' */
+ EM_DEBUG_LOG("rule[%d].flag2(rule id[%d]) is %d", i, rule[i].rule_id, rule[i].flag2);
+ switch (rule[i].type) {
+ case EMF_FILTER_FROM:
+ if (from_address == NULL) {
+ from_address = EM_SAFE_STRDUP(head->from);
+ rfc822_parse_adrlist(&addr, from_address, NULL);
+ if(addr) {
+ EM_DEBUG_LOG("rule : head->from[%s], addr->mailbox[%s], addr->host[%s]", head->from, addr->mailbox, addr->host);
+ EM_SAFE_FREE(from_address);
+
+ if (addr->mailbox)
+ len = strlen(addr->mailbox);
+ if (addr->host)
+ len += strlen(addr->host);
+ len += 2;
+
+ if (!(from_address = em_core_malloc(len))) {
+ EM_DEBUG_EXCEPTION("em_core_malloc failed...");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ SNPRINTF(from_address, len, "%s@%s", addr->mailbox, addr->host);
+ }
+ else {
+ EM_DEBUG_EXCEPTION("rfc822_parse_adrlist failed.");
+ err = EMF_ERROR_INVALID_ADDRESS;
+ goto FINISH_OFF;
+ }
+ }
+
+ src = from_address;
+ break;
+ case EMF_FILTER_SUBJECT:
+ src = head->subject;
+ break;
+ case EMF_FILTER_BODY:
+ err = EMF_ERROR_NOT_SUPPORTED;
+ goto FINISH_OFF;
+ break;
+ }
+ EM_DEBUG_LOG("rule src[%s], value[%s]\n", src, rule[i].value);
+
+ if (src && rule[i].value) {
+ if (RULE_TYPE_INCLUDES == rule[i].flag2) {
+ if (strstr(src, rule[i].value)) {
+ *matched = i;
+ break;
+ }
+ }
+ else if (RULE_TYPE_EXACTLY == rule[i].flag2) {
+ if (!strcmp(src, rule[i].value)) {
+ *matched = i;
+ break;
+ }
+ }
+ }
+ }
+ else
+ EM_DEBUG_LOG("Invald src or rule[i].value");
+ }
+ ret = true;
+
+ EM_DEBUG_LOG("i [%d], matched [%d]", i, *matched);
+FINISH_OFF:
+
+ EM_SAFE_FREE(from_address);
+
+ if (addr != NULL)
+ mail_free_address(&addr);
+
+ if (err_code != NULL)
+ *err_code = err;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+static int em_core_get_utf8_address(char **dest, ADDRESS *address, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("dest[%p], address[%p], err_code[%p]", dest, address, err_code);
+
+ if (!dest || !address) {
+ EM_DEBUG_EXCEPTION("dest[%p], address[%p]", dest, address);
+ if (err_code != NULL)
+ *err_code = EMF_ERROR_INVALID_PARAM;
+ return false;
+ }
+
+ int ret = false;
+ int err = EMF_ERROR_NONE;
+
+ gchar *concatenated = NULL;
+ gchar *utf8_address = NULL;
+ gchar *temp = NULL;
+ char *nickname = NULL;
+
+ while (address) {
+ EM_DEBUG_LOG("address->mailbox[%s], address->host[%s]", address->mailbox, address->host);
+ if (!address->mailbox || !address->host) {
+ address = address->next;
+ continue;
+ }
+ EM_DEBUG_LOG("address->mailbox[%p]", address->personal);
+ if (address->personal) {
+ if (!(nickname = em_core_decode_rfc2047_text(address->personal, &err))) {
+ EM_DEBUG_EXCEPTION("em_core_decode_rfc2047_text failed - %d", err);
+ goto FINISH_OFF;
+ }
+ EM_DEBUG_LOG("nickname[%s]", nickname);
+ if (*nickname != '\0')
+ utf8_address = g_strdup_printf("\"%s\" <%s@%s>", nickname, address->mailbox ? address->mailbox : "", address->host ? address->host : "");
+ else
+ utf8_address = g_strdup_printf("<%s@%s>", address->mailbox ? address->mailbox : "", address->host ? address->host : "");
+
+ EM_SAFE_FREE(nickname);
+ }
+ else
+ utf8_address = g_strdup_printf("<%s@%s>", address->mailbox ? address->mailbox : "", address->host ? address->host : "");
+
+ EM_DEBUG_LOG("utf8_address[%s]", utf8_address);
+
+ if (concatenated != NULL) {
+ temp = concatenated;
+ concatenated = g_strdup_printf("%s; %s", temp, utf8_address);
+ g_free(temp);
+ }
+ else
+ concatenated = g_strdup(utf8_address);
+
+ g_free(utf8_address);
+ utf8_address = NULL;
+
+ address = address->next;
+ }
+
+ *dest = concatenated;
+
+ ret = true;
+
+FINISH_OFF:
+ EM_SAFE_FREE(nickname);
+ EM_DEBUG_FUNC_END("ret[%d]", ret);
+ return ret;
+}
+
+
+static int em_core_mail_parse_envelope(ENVELOPE *envelope, emf_mail_head_t **head, int *to_num, int *err_code)
+{
+ EM_PROFILE_BEGIN(emCoreParseEnvelope);
+ EM_DEBUG_FUNC_BEGIN("envelope[%p], head[%p], to_num[%p], err_code[%p]", envelope, head, to_num, err_code);
+
+ int ret = false;
+ int err = EMF_ERROR_NONE;
+
+ emf_mail_head_t *p = NULL;
+ int i = 0;
+
+ if (!head) {
+ EM_DEBUG_EXCEPTION("envelope[%p], head[%p], to_num[%p]", envelope, head, to_num);
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ if (!(p = em_core_malloc(sizeof(emf_mail_head_t)))) {
+ EM_DEBUG_EXCEPTION("em_core_malloc failed...");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ if (envelope->subject) {
+ p->subject = em_core_decode_rfc2047_text(envelope->subject, &err);
+ EM_DEBUG_LOG("subject[%s]", p->subject);
+ }
+
+ if (envelope->from) {
+ if (!em_core_get_utf8_address(&p->from, envelope->from, &err)) {
+ EM_DEBUG_EXCEPTION("em_core_get_utf8_address failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ EM_DEBUG_LOG(" head->from[%s]", p->from);
+ }
+
+ if (envelope->to) {
+ /*
+ ADDRESS *addr = NULL;
+
+ for (addr = envelope->to, i = 0; addr != NULL; addr = addr->next, i++)
+ EM_DEBUG_LOG("envelope->personal[%s], mailbox[%s], host[%s]", addr->personal, addr->mailbox, addr->host);
+ */
+
+ EM_DEBUG_LOG("envelope->to");
+ if (!em_core_get_utf8_address(&p->to, envelope->to, &err)) {
+ EM_DEBUG_EXCEPTION("em_core_get_utf8_address failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ EM_DEBUG_LOG("head->to[%s]", p->to);
+ }
+
+ if (envelope->cc) {
+ EM_DEBUG_LOG("envelope->cc");
+ if (!em_core_get_utf8_address(&p->cc, envelope->cc, &err)) {
+ EM_DEBUG_EXCEPTION("em_core_get_utf8_address failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ EM_DEBUG_LOG("head->cc[%s]", p->cc);
+ }
+
+ if (envelope->bcc) {
+ if (!em_core_get_utf8_address(&p->bcc, envelope->bcc, &err)) {
+ EM_DEBUG_EXCEPTION("em_core_get_utf8_address failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ EM_DEBUG_LOG("head->bcc[%s]", p->bcc);
+ }
+
+ if (envelope->reply_to) {
+ if (!em_core_get_utf8_address(&p->reply_to, envelope->reply_to, &err)) {
+ EM_DEBUG_EXCEPTION("em_core_get_utf8_address failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ EM_DEBUG_LOG(" head->reply_to[%s]\n", p->reply_to);
+ }
+
+ if (envelope->return_path) {
+ if (!em_core_get_utf8_address(&p->return_path, envelope->return_path, &err)) {
+ EM_DEBUG_EXCEPTION("em_core_get_utf8_address failed [%d]", err);
+ goto FINISH_OFF;
+ }
+ EM_DEBUG_LOG("head->return_path[%s]", p->return_path);
+ }
+
+ p->mid = EM_SAFE_STRDUP(envelope->message_id);
+
+ *head = p;
+ p = NULL;
+
+ if (to_num != NULL)
+ *to_num = i;
+
+ ret = true;
+
+FINISH_OFF:
+
+ if (ret != true)
+ EM_SAFE_FREE(p);
+
+ if (err_code != NULL)
+ *err_code = err;
+
+ EM_PROFILE_END(emCoreParseEnvelope);
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+EXPORT_API int em_core_mailbox_sync_header(emf_mailbox_tbl_t *input_mailbox_tbl, emf_mailbox_tbl_t *input_mailbox_tbl_spam, void *stream_recycle, em_core_uid_list **input_uid_list, int *unread_mail, int *err_code)
+{
+ EM_PROFILE_BEGIN(emCoreSyncHeader);
+ EM_DEBUG_FUNC_BEGIN("input_mailbox_tbl[%p], input_mailbox_tbl_spam[%p], input_uid_list [%p], err_code[%p]", input_mailbox_tbl, input_mailbox_tbl_spam, input_uid_list, err_code);
+
+ int ret = false;
+ int err = EMF_ERROR_NONE, err_2 = EMF_ERROR_NONE;
+ int status = EMF_LIST_FAIL;
+ int download_limit_count;
+ emf_account_t *account_ref = NULL;
+ emf_mail_rule_tbl_t *rule = NULL;
+ em_core_uid_list *uid_list = NULL;
+ em_core_uid_list *uid_elem = NULL;
+ emf_mail_head_t *head = NULL;
+ ENVELOPE *env = NULL;
+ int account_id = 0, mail_id = 0, rule_len = 1000, total = 0, unread = 0, i = 0, percentage = 0, thread_id = -1;
+ void *stream = NULL;
+ char *uid_range = NULL;
+
+ if (!input_mailbox_tbl) {
+ EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM:input_mailbox_tbl[%p]", input_mailbox_tbl);
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+ account_id = input_mailbox_tbl->account_id;
+ account_ref = em_core_get_account_reference(account_id);
+ if (!account_ref) {
+ EM_DEBUG_EXCEPTION("em_core_get_account_reference failed - %d", account_id);
+ err = EMF_ERROR_INVALID_ACCOUNT;
+ goto FINISH_OFF;
+ }
+
+ FINISH_OFF_IF_CANCELED;
+
+#ifndef __FEATURE_KEEP_CONNECTION__
+ /* h.gahlaut : Recycling of stream is taken care internally in em_core_mailbox_open so no need of this code here */
+ if (stream_recycle)
+ stream = stream_recycle; /* set stream for recycling connection. */
+#endif
+
+ if (!em_core_mailbox_open(account_id, input_mailbox_tbl->mailbox_name, (void **)&stream, &err) || !stream){
+ EM_DEBUG_EXCEPTION("em_core_mailbox_open failed - %d", err);
+ status = EMF_LIST_CONNECTION_FAIL;
+ goto FINISH_OFF;
+ }
+
+ FINISH_OFF_IF_CANCELED;
+
+ /* save total mail count on server to DB */
+ if (!em_storage_update_mailbox_total_count(account_id, input_mailbox_tbl->mailbox_name, ((MAILSTREAM *)stream)->nmsgs, 1, &err)){
+ EM_DEBUG_EXCEPTION("em_storage_update_mailbox_total_count failed [%d]", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+
+ /* if (((MAILSTREAM *)stream)->nmsgs > 0) */
+ {
+ emf_option_t *opt_ref = &account_ref->options;
+ EM_DEBUG_LOG("block_address = %d, block_subject = %d", opt_ref->block_address, opt_ref->block_subject);
+
+ if (opt_ref->block_address || opt_ref->block_subject) {
+ int is_completed = false;
+ int type = 0;
+
+ if (!opt_ref->block_address)
+ type = EMF_FILTER_SUBJECT;
+ else if (!opt_ref->block_subject)
+ type = EMF_FILTER_FROM;
+
+ if (!em_storage_get_rule(ALL_ACCOUNT, type, 0, &rule_len, &is_completed, &rule, true, &err) || !rule)
+ EM_DEBUG_EXCEPTION("em_storage_get_rule failed - %d", err);
+ }
+ download_limit_count = input_mailbox_tbl->mail_slot_size;
+ if (!em_core_mailbox_get_uids_to_download(stream, account_ref, input_mailbox_tbl, download_limit_count, &uid_list, &total, EMF_SYNC_LATEST_MAILS_FIRST, &err)){
+ EM_DEBUG_EXCEPTION("em_core_mailbox_get_uids_to_download failed [%d]", err);
+ uid_list = NULL;
+ goto FINISH_OFF;
+ }
+
+ FINISH_OFF_IF_CANCELED;
+
+ if (input_uid_list && *input_uid_list){
+ em_core_mailbox_free_uids(*input_uid_list, NULL);
+ *input_uid_list = uid_list;
+ }
+ uid_elem = uid_list;
+ i = 0;
+ EM_PROFILE_BEGIN(emCoreSyncHeaderwhileloop);
+
+#ifdef __FEATURE_HEADER_OPTIMIZATION__
+ /* g.shyamakshi@samsung.com : Bulk fetch of headers only if the recieving server type is IMAP */
+
+ EM_DEBUG_LOG("((MAILSTREAM *)stream)->nmsgs [%d]", ((MAILSTREAM *)stream)->nmsgs);
+ EM_DEBUG_LOG("uid_list [%p]", uid_list);
+ if (account_ref->receiving_server_type == EMF_SERVER_TYPE_IMAP4 && uid_list != NULL){
+ em_core_uid_list *uid_list_prev = NULL;
+ em_core_uid_list *uid_list_fast = uid_list;
+ int index = 0;
+ int msg_count = total;
+ int uid_range_size = msg_count * 8 + 1000;
+
+ EM_DEBUG_LOG("memory allocation for uid_range [%d, %d]", msg_count, uid_range_size);
+ uid_range = malloc(sizeof(char) * uid_range_size);
+
+ if (uid_range == NULL){
+ EM_DEBUG_EXCEPTION("memory allocation for uid_range failed");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ uid_list_prev = uid_list_fast;
+
+ if (uid_list_fast->next == NULL){
+ /* Single list entry */
+ snprintf(uid_range, uid_range_size, "%d", atoi(uid_list_fast->uid));
+ }
+ else{
+ /* forming range of uids to be passed */
+ while (uid_list_fast != NULL){
+ /* uid_list_fast = uid_list_fast->next; */
+
+ if ((uid_list_fast->next != NULL) && (((atoi(uid_list_prev->uid)) - (atoi(uid_list_fast->next->uid))) == 1)){
+ index += snprintf(uid_range+index, uid_range_size, "%d", atoi(uid_list_prev->uid));
+
+ uid_list_fast = uid_list_fast->next;
+ uid_list_prev = uid_list_fast;
+
+ /* to make UID range string "abc, XX : YY" */
+ while (uid_list_fast != NULL){
+ if (uid_list_fast->next == NULL)
+ break;
+ if (((atoi(uid_list_prev->uid)) - (atoi(uid_list_fast->next->uid))) == 1){
+ uid_list_fast = uid_list_fast->next;
+ uid_list_prev = uid_list_fast;
+ }
+ else
+ break;
+ }
+ if ((uid_list_fast != NULL) && (uid_list_fast->next != NULL))
+ index += snprintf(uid_range+index, uid_range_size, ":%d,", atoi(uid_list_prev->uid));
+ else
+ index += snprintf(uid_range+index, uid_range_size, ":%d", atoi(uid_list_prev->uid));
+
+ uid_list_fast = uid_list_fast->next;
+ uid_list_prev = uid_list_fast;
+ }
+ else{
+ if (uid_list_fast->next != NULL)
+ index += snprintf(uid_range+index, uid_range_size, "%d,", atoi(uid_list_prev->uid));
+ else
+ index += snprintf(uid_range+index, uid_range_size, "%d", atoi(uid_list_prev->uid));
+ uid_list_fast = uid_list_fast->next;
+ uid_list_prev = uid_list_fast;
+ }
+ }
+ }
+
+ /* h.gahlaut : [Start] */
+ /* Adding this check here to check if application has called cancel job. */
+ /* This checking should be done because fetching 50 headers will take time */
+ FINISH_OFF_IF_CANCELED;
+
+ EM_DEBUG_LOG("index [%d]", index);
+
+ /* h.gahlaut : [End] */
+ uid_elem = uid_list;
+ if (stream && uid_elem){
+ EM_DEBUG_LOG("msgno : %d", uid_elem->msgno);
+ ((MAILSTREAM *)stream)->nmsgs = uid_elem->msgno;
+ }
+ else{
+ EM_DEBUG_LOG("Uid List Null");
+ }
+ EM_DEBUG_LOG("Calling ... mail_fetch_fast. uid_range [%s]", uid_range);
+ mail_fetch_fast(stream, uid_range, FT_UID | FT_PEEK | FT_NEEDENV);
+ EM_SAFE_FREE(uid_range);
+ }
+#endif
+
+ /* h.gahlaut@samsung.com : Clear the event queue of partial body download thread before starting fetching new headers */
+#ifndef __PARTIAL_BODY_FOR_POP3__
+ if (account_ref->receiving_server_type == EMF_SERVER_TYPE_IMAP4){
+#endif /* __PARTIAL_BODY_FOR_POP3__ */
+ /* Partial body download feature is only for IMAP accounts */
+ if (false == em_core_clear_partial_body_thd_event_que(&err))
+ EM_DEBUG_LOG("em_core_clear_partial_body_thd_event_que failed [%d]", err);
+#ifndef __PARTIAL_BODY_FOR_POP3__
+ }
+#endif /* __PARTIAL_BODY_FOR_POP3__ */
+ while (uid_elem) {
+ EM_PROFILE_BEGIN(emCoreSyncHeaderEachMail);
+ EM_DEBUG_LOG("mail_fetchstructure_full : uid_elem->msgno[%d]", uid_elem->msgno);
+
+ env = NULL;
+
+ if (uid_elem->msgno > ((MAILSTREAM *)stream)->nmsgs)
+ EM_DEBUG_EXCEPTION("Warnings! msgno[%d] can't be greater than nmsgs[%d]. It might cause crash.", uid_elem->msgno, ((MAILSTREAM *)stream)->nmsgs);
+ else{
+
+#ifdef __FEATURE_HEADER_OPTIMIZATION__
+ if (account_ref->receiving_server_type == EMF_SERVER_TYPE_IMAP4) /* Fetch env from cache in case of IMAP */
+ env = mail_fetchstructure_full(stream, uid_elem->msgno, NULL, FT_PEEK, 0);
+ else /* Fetch header from network in case of POP */
+ env = mail_fetchstructure_full(stream, uid_elem->msgno, NULL, FT_PEEK, 1);
+#else
+ env = mail_fetchstructure_full(stream, uid_elem->msgno, NULL, FT_PEEK);
+#endif
+ }
+ FINISH_OFF_IF_CANCELED;
+
+ if (env != NULL){
+ int to_num = 0;
+ int matched = -1;
+
+ if (!em_core_mail_parse_envelope(env, &head, &to_num, &err) || !head) {
+ EM_DEBUG_EXCEPTION("em_core_mail_parse_envelope failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ if (rule && input_mailbox_tbl_spam && !em_core_mail_check_rule(head, rule, rule_len, &matched, &err)) {
+ EM_DEBUG_EXCEPTION("em_core_mail_check_rule failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ if (matched >= 0 && input_mailbox_tbl_spam){ /* add filtered mails to SPAMBOX */
+ EM_DEBUG_LOG("mail[%d] added to spambox", mail_id);
+
+ if (!em_core_mail_add_header(stream, input_mailbox_tbl_spam, head, to_num, uid_elem, &mail_id, &thread_id, &err)) {
+ EM_DEBUG_EXCEPTION("em_core_mail_add_header falied [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ if (account_ref->receiving_server_type == EMF_SERVER_TYPE_IMAP4){
+ if (!em_core_mail_move_from_server(account_id, input_mailbox_tbl->mailbox_name, &mail_id, 1, input_mailbox_tbl_spam->mailbox_name, &err)){
+ EM_DEBUG_EXCEPTION("em_core_mail_move_from_server falied [%d]", err);
+ goto FINISH_OFF;
+ }
+ }
+ } else {
+ /* add mails to specified mail box */
+ EM_DEBUG_LOG("mail[%d] moved to input_mailbox_tbl [%s]", mail_id, input_mailbox_tbl->mailbox_name);
+ if (!em_core_mail_add_header(stream, input_mailbox_tbl, head, to_num, uid_elem, &mail_id, &thread_id, &err)) {
+ EM_DEBUG_EXCEPTION("em_core_mail_add_header falied [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ /*h.gahlaut : Start partial body dowload using partial body thread only for IMAP accounts*/
+#ifndef __PARTIAL_BODY_FOR_POP3__
+ if (account_ref->receiving_server_type == EMF_SERVER_TYPE_IMAP4) {
+#endif /* __PARTIAL_BODY_FOR_POP3__ */
+ if (false == em_core_initiate_pbd(stream, account_id, mail_id, uid_elem->uid, input_mailbox_tbl->mailbox_name, &err))
+ EM_DEBUG_LOG("Partial body download initiation failed [%d]", err);
+#ifndef __PARTIAL_BODY_FOR_POP3__
+ }
+#endif /* __PARTIAL_BODY_FOR_POP3__ */
+
+ if (!uid_elem->flag.seen && input_mailbox_tbl->mailbox_type != EMF_MAILBOX_TYPE_SPAMBOX)
+ em_core_add_notification_for_unread_mail_by_mail_header(account_id, mail_id, head);
+
+ FINISH_OFF_IF_CANCELED;
+
+ if (!uid_elem->flag.seen)
+ unread++;
+
+ percentage = ((i+1) * 100) / total ;
+ EM_DEBUG_LOG("Header Percentage Completed [%d] : [%d/%d] mail_id [%d]", percentage, i+1, total, mail_id);
+
+ if (!em_storage_notify_storage_event(NOTI_MAIL_ADD, account_id, mail_id, input_mailbox_tbl->mailbox_name, thread_id))
+ EM_DEBUG_EXCEPTION("em_storage_notify_storage_event [NOTI_MAIL_ADD] failed");
+ }
+
+ /* Release for envelope is not required and it may cause crash. Don't free the memory for envelope here. */
+ /* Envelope data will be freed by garbage collector in mail_close_full */
+ if (head){
+ em_core_mail_head_free(&head, 1, NULL);
+ head = NULL;
+ }
+
+ FINISH_OFF_IF_CANCELED;
+ }
+
+ uid_elem = uid_elem->next;
+ i++;
+ EM_PROFILE_END(emCoreSyncHeaderEachMail);
+ }
+ EM_PROFILE_END(emCoreSyncHeaderwhileloop);
+ }
+
+ *unread_mail = unread;
+ ret = true;
+FINISH_OFF:
+
+ if (!em_core_mailbox_remove_overflowed_mails(input_mailbox_tbl, &err_2))
+ EM_DEBUG_EXCEPTION("em_core_mailbox_remove_overflowed_mails failed - %d", err_2);
+
+ if (head != NULL)
+ em_core_mail_head_free(&head, 1, NULL);
+
+ if (uid_list != NULL){
+ em_core_mailbox_free_uids(uid_list, NULL);
+ /* uid_list point to the same memory with input_mailbox_tbl->user_data. */
+ /* input_mailbox_tbl->user_data should be set NULL if uid_list is freed */
+ *input_uid_list = NULL;
+ }
+
+ EM_SAFE_FREE(uid_range);
+
+ if (rule != NULL)
+ em_storage_free_rule(&rule, rule_len, NULL);
+
+#ifdef __FEATURE_KEEP_CONNECTION__
+ if (stream != NULL) {
+#else /* __FEATURE_KEEP_CONNECTION__ */
+ if (stream != NULL && stream_recycle == NULL) {
+#endif /* __FEATURE_KEEP_CONNECTION__ */
+ em_core_mailbox_close(0, stream);
+ stream = NULL;
+ }
+
+ if (err_code != NULL)
+ *err_code = err;
+
+ EM_PROFILE_END(emCoreSyncHeader);
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+
+em_core_uid_list *__ReverseList(em_core_uid_list *uid_list)
+{
+ em_core_uid_list *temp, *current, *result;
+
+ temp = NULL;
+ result = NULL;
+ current = uid_list;
+
+ while (current != NULL){
+ temp = current->next;
+ current->next = result;
+ result = current;
+ current = temp;
+ }
+ uid_list = result;
+ return uid_list;
+}
+
+
+
+int em_core_mailbox_download_uid_all(emf_mailbox_t *mailbox, em_core_uid_list** uid_list, int *total, emf_mail_read_mail_uid_tbl_t *downloaded_uids, int count, em_core_get_uids_for_delete_t for_delete, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("mailbox[%p], uid_list[%p], total[%p], downloaded_uids[%p], count[%d], for_delete[%d], err_code[%p]", mailbox, uid_list, total, downloaded_uids, count, for_delete, err_code);
+
+ int ret = false;
+ int err = EMF_ERROR_NONE;
+
+ MAILSTREAM *stream = NULL;
+ emf_account_t *ref_account = NULL;
+ em_core_uid_list *uid_elem = NULL;
+ em_core_uid_list *fetch_data_p = NULL;
+ void *tmp_stream = NULL;
+ char cmd[64] = {0x00, };
+ char *p = NULL;
+
+ if (!mailbox || !uid_list) {
+ EM_DEBUG_EXCEPTION("mailbox[%p], uid_list[%p], total[%p], downloaded_uids[%p], count[%d], for_delete[%d]", mailbox, uid_list, total, downloaded_uids, count, for_delete);
+
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ if (!(ref_account = em_core_get_account_reference(mailbox->account_id))) {
+ EM_DEBUG_EXCEPTION("em_core_get_account_reference failed - %d", mailbox->account_id);
+
+ err = EMF_ERROR_INVALID_ACCOUNT;
+ goto FINISH_OFF;
+ }
+
+ if (!mailbox->mail_stream) {
+ if (!em_core_mailbox_open(mailbox->account_id, mailbox->name, (void **)&tmp_stream, &err)){
+ EM_DEBUG_EXCEPTION("em_core_mailbox_open failed...");
+
+ goto FINISH_OFF;
+ }
+
+ stream = (MAILSTREAM *)tmp_stream;
+ }
+ else
+ stream = mailbox->mail_stream;
+
+ if (ref_account->receiving_server_type == EMF_SERVER_TYPE_POP3) { /* POP3 */
+ POP3LOCAL *pop3local = NULL;
+
+ if (!stream || !(pop3local = stream->local) || !pop3local->netstream) {
+ err = EMF_ERROR_INVALID_PARAM; /* EMF_ERROR_UNKNOWN; */
+ goto FINISH_OFF;
+ }
+
+ /* send UIDL */
+ memset(cmd, 0x00, sizeof(cmd));
+
+ SNPRINTF(cmd, sizeof(cmd), "UIDL\015\012");
+
+#ifdef FEATURE_CORE_DEBUG
+ EM_DEBUG_LOG("[POP3] >>> [%s]", cmd);
+#endif
+
+ if (!net_sout(pop3local->netstream, cmd, (int)strlen(cmd))) {
+ EM_DEBUG_EXCEPTION("net_sout failed...");
+
+ err = EMF_ERROR_CONNECTION_BROKEN;
+ goto FINISH_OFF;
+ }
+
+ /* get uid from replied data */
+ while (pop3local->netstream) {
+ char *s = NULL;
+
+ if (!(p = net_getline(pop3local->netstream)))
+ break;
+
+#ifdef FEATURE_CORE_DEBUG
+ EM_DEBUG_LOG(" [POP3] <<< [%s]", p);
+#endif
+
+ /* replied error "-ERR" */
+ if (*p == '-') {
+ err = EMF_ERROR_MAIL_NOT_FOUND;
+ goto FINISH_OFF;
+ }
+
+ /* replied success "+OK" */
+ if (*p == '+') {
+ free(p); p = NULL;
+ continue;
+ }
+
+ /* end of command */
+ if (*p == '.')
+ break;
+
+ /* EM_DEBUG_LOG("UID list [%s]", p); */
+
+ uid_elem = (em_core_uid_list *)malloc(sizeof(em_core_uid_list));
+ if (!uid_elem) {
+ EM_DEBUG_EXCEPTION("malloc falied...");
+
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ memset(uid_elem, 0x00, sizeof(em_core_uid_list));
+
+ /* format : "1 AAA6FHEAAAQrB6c1ymXxty04yks7hcQ7" */
+
+ /* save uid */
+ s = strstr(p, " ");
+ if (s) {
+ *s = '\0';
+ uid_elem->msgno = atoi(p);
+ uid_elem->uid = EM_SAFE_STRDUP(s+1);
+ }
+
+ /* check downloaded_uids */
+ if (downloaded_uids) {
+ int i;
+ for (i = 0; i < count; ++i) {
+ if (!strcmp(uid_elem->uid, downloaded_uids[i].s_uid)) {
+ downloaded_uids[i].flag = 1;
+ break;
+ }
+ }
+ }
+
+ if (*uid_list) { /* TODO : modify me */
+ fetch_data_p = *uid_list;
+
+ while (fetch_data_p->next)
+ fetch_data_p = fetch_data_p->next;
+
+ fetch_data_p->next = uid_elem;
+ }
+ else
+ *uid_list = uid_elem;
+
+ if (total)
+ ++(*total);
+
+ free(p); p = NULL;
+ }
+ }
+ else { /* IMAP */
+ IMAPLOCAL *imaplocal = NULL;
+ char tag[16];
+ char *s = NULL;
+ char *t = NULL;
+
+ if (!stream || !(imaplocal = stream->local) || !imaplocal->netstream) {
+ err = EMF_ERROR_INVALID_PARAM; /* EMF_ERROR_UNKNOWN; */
+ goto FINISH_OFF;
+ }
+
+ /* send FETCH UID */
+ memset(tag, 0x00, sizeof(tag));
+ memset(cmd, 0x00, sizeof(cmd));
+
+ SNPRINTF(tag, sizeof(tag), "%08lx", 0xffffffff & (stream->gensym++));
+ SNPRINTF(cmd, sizeof(cmd), "%s UID FETCH %d:* (FLAGS)\015\012", tag, 1);
+#ifdef FEATURE_CORE_DEBUG
+ EM_DEBUG_LOG("[IMAP] >>> %s", cmd);
+#endif
+ if (!net_sout(imaplocal->netstream, cmd, (int)strlen(cmd))) {
+ EM_DEBUG_EXCEPTION("net_sout failed...");
+
+ err = EMF_ERROR_CONNECTION_BROKEN;
+ goto FINISH_OFF;
+ }
+
+ /* get uid from replied data */
+ while (imaplocal->netstream) {
+ if (!(p = net_getline(imaplocal->netstream)))
+ break;
+
+ /* EM_DEBUG_LOG(" [IMAP] <<< %s", p); */
+
+ /* tagged line - end of command */
+ if (!strncmp(p, tag, strlen(tag)))
+ break;
+
+ /* check that reply is reply to our command */
+ /* format : "* 9 FETCH (UID 68)" */
+ if (!strstr(p, "FETCH (FLAGS")) {
+ free(p); p = NULL;
+ continue;
+ }
+
+ if (for_delete == EM_CORE_GET_UIDS_FOR_NO_DELETE) {
+ if ((ref_account->retrieval_mode == EMF_IMAP4_RETRIEVAL_MODE_NEW) && (strstr(p, "\\Seen"))) {
+ free(p); p = NULL;
+ continue;
+ }
+ }
+
+ uid_elem = (em_core_uid_list *)malloc(sizeof(em_core_uid_list));
+ if (!uid_elem) {
+ EM_DEBUG_EXCEPTION("malloc failed...");
+
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ memset(uid_elem, 0x00, sizeof(em_core_uid_list));
+ /* parse uid, sequence, flags from replied data */
+
+ /* parse uid from replied data */
+ s = p+2;
+ t = strchr(s, ' ');
+
+ if (!t) {
+ err = EMF_ERROR_INVALID_RESPONSE;
+ goto FINISH_OFF;
+ }
+
+ *t = '\0';
+
+ /* save sequence */
+ uid_elem->msgno = atoi(s);
+
+ if (strstr(++t, "\\Deleted"))
+ uid_elem->flag.deleted = 1;
+
+ /* parse uid */
+ s = strstr(++t, "UID ");
+ if (s) {
+ s += strlen("UID ");
+ t = strchr(s, ')');
+
+ if (!t) {
+ err = EMF_ERROR_INVALID_RESPONSE;
+ goto FINISH_OFF;
+ }
+
+ *t = '\0';
+ }
+ else {
+ err = EMF_ERROR_INVALID_RESPONSE;
+ goto FINISH_OFF;
+ }
+
+ /* save uid */
+ uid_elem->uid = EM_SAFE_STRDUP(s);
+
+ /* check downloaded_uids */
+ if (downloaded_uids) {
+ int i;
+ for (i = 0; i < count; ++i) {
+ if (uid_elem->uid && !strcmp(uid_elem->uid, downloaded_uids[i].s_uid)) { /* 20080308 - prevent 25231 : Reverse Null. Pointer "(uid_elem)->uid" dereferenced before NULL check */
+ downloaded_uids[i].flag = 1;
+ free(uid_elem->uid);
+ free(uid_elem); uid_elem = NULL;
+ break;
+ }
+ }
+ }
+
+ if (uid_elem) {
+ if (*uid_list) {
+ fetch_data_p = *uid_list;
+
+ while (fetch_data_p->next)
+ fetch_data_p = fetch_data_p->next;
+
+ fetch_data_p->next = uid_elem;
+ }
+ else {
+ *uid_list = uid_elem;
+ }
+
+ if (total)
+ ++(*total);
+ }
+
+ free(p); p = NULL;
+ }
+ }
+
+ ret = true;
+
+FINISH_OFF:
+ if (uid_elem && ret == false)
+ free(uid_elem);
+
+ if (p)
+ free(p);
+
+ if (mailbox && !mailbox->mail_stream) {
+ em_core_mailbox_close(0, stream);
+ stream = NULL;
+ }
+
+ if (err_code)
+ *err_code = err;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+int em_core_mailbox_download_imap_msgno(emf_mailbox_t *mailbox, char *uid, int *msgno, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("mailbox[%p], uid[%p], msgno[%p], err_code[%p]", mailbox, uid, msgno, err_code);
+
+ int ret = false;
+ int err = EMF_ERROR_NONE;
+ MAILSTREAM *stream = NULL;
+ IMAPLOCAL *imaplocal = NULL;
+ emf_account_t *ref_account = NULL;
+ void *tmp_stream = NULL;
+ char tag[32], cmd[64];
+ char *p = NULL;
+
+ if (!mailbox || !uid) {
+ EM_DEBUG_EXCEPTION("mailbox[%p], uid[%p], msgno[%p]", mailbox, uid, msgno);
+
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ if (!(ref_account = em_core_get_account_reference(mailbox->account_id))) {
+ EM_DEBUG_EXCEPTION("em_core_get_account_reference failed [%d]", mailbox->account_id);
+
+ err = EMF_ERROR_INVALID_ACCOUNT;
+ goto FINISH_OFF;
+ }
+
+ if (ref_account->receiving_server_type != EMF_SERVER_TYPE_IMAP4) {
+ err = EMF_ERROR_INVALID_ACCOUNT; /* EMF_ERROR_INVALID_PARAM; */
+ goto FINISH_OFF;
+ }
+
+ if (!mailbox->mail_stream) {
+ if (!em_core_mailbox_open(mailbox->account_id, mailbox->name, (void **)&tmp_stream, &err)) {
+ EM_DEBUG_EXCEPTION("em_core_mailbox_open failed - %d", err);
+
+ goto FINISH_OFF;
+ }
+
+ stream = (MAILSTREAM *)tmp_stream;
+ }
+ else
+ stream = mailbox->mail_stream;
+
+ if (!stream || !(imaplocal = stream->local) || !imaplocal->netstream) {
+ err = EMF_ERROR_INVALID_PARAM; /* EMF_ERROR_UNKNOWN; */
+ goto FINISH_OFF;
+ }
+
+ /* send SEARCH UID */
+ memset(tag, 0x00, sizeof(tag));
+ memset(cmd, 0x00, sizeof(cmd));
+
+ SNPRINTF(tag, sizeof(tag), "%08lx", 0xffffffff & (stream->gensym++));
+ SNPRINTF(cmd, sizeof(cmd), "%s SEARCH UID %s\015\012", tag, uid);
+
+ if (!net_sout(imaplocal->netstream, cmd, (int)strlen(cmd))) {
+ EM_DEBUG_EXCEPTION("net_sout failed...");
+
+ err = EMF_ERROR_CONNECTION_BROKEN;
+ goto FINISH_OFF;
+ }
+
+ /* get message number from replied data */
+ while (imaplocal->netstream) {
+ if (!(p = net_getline(imaplocal->netstream)))
+ break;
+
+ /* tagged line - end of command */
+ if (!strncmp(p, tag, strlen(tag)))
+ break;
+
+ /* check that reply is reply to our command */
+ /* format : "* SEARCH 68", if not found, "* SEARCH" */
+ if (!strstr(p, "SEARCH ") || (p[9] < '0' || p[9] > '9')) {
+ free(p); p = NULL;
+ continue;
+ }
+
+ if (msgno)
+ *msgno = atoi(p+9);
+
+ free(p); p = NULL;
+
+ ret = true;
+ }
+
+ if (ret != true)
+ err = EMF_ERROR_MAIL_NOT_FOUND;
+
+FINISH_OFF:
+ if (p)
+ free(p);
+
+ if (mailbox && !mailbox->mail_stream){
+ em_core_mailbox_close(0, stream);
+ stream = NULL;
+ }
+
+ if (err_code)
+ *err_code = err;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+int em_core_mailbox_get_msgno(em_core_uid_list *uid_list, char *uid, int *msgno, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("uid_list[%p], uid[%s], msgno[%p], err_code[%p]", uid_list, uid, msgno, err_code);
+
+ int ret = false;
+ int err = EMF_ERROR_MAIL_NOT_FOUND; /* EMF_ERROR_NONE; */
+
+ if (!uid || !msgno || !uid_list) {
+ EM_DEBUG_EXCEPTION("uid_list[%p], uid[%p], msgno[%p]", uid_list, uid, msgno);
+
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ EM_DEBUG_LOG(" >> uid[%s]", uid);
+
+ while (uid_list) {
+ if (!strcmp(uid_list->uid, uid)) {
+ *msgno = uid_list->msgno;
+
+ EM_DEBUG_LOG("*msgno[%d]", *msgno);
+
+ err = EMF_ERROR_NONE;
+
+ ret = true;
+ break;
+ }
+
+ uid_list = uid_list->next;
+ }
+
+FINISH_OFF:
+ if (err_code != NULL)
+ *err_code = err;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+int em_core_mailbox_get_uid(em_core_uid_list *uid_list, int msgno, char **uid, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ int ret = false, err = EMF_ERROR_NONE;
+
+ if (!uid || msgno <= 0 || !uid_list){
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ while (uid_list) {
+ if (uid_list->msgno == msgno) {
+ if (uid) {
+ if (!(*uid = EM_SAFE_STRDUP(uid_list->uid))) {
+ EM_DEBUG_EXCEPTION("strdup failed...");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ ret = true;
+ break;
+ }
+ }
+
+ uid_list = uid_list->next;
+ }
+
+ if (ret != true)
+ err = EMF_ERROR_MAIL_NOT_FOUND;
+
+FINISH_OFF:
+ if (err_code)
+ *err_code = err;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+int em_core_mailbox_free_uids(em_core_uid_list *uid_list, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("uid_list[%p], err_code[%p]", uid_list, err_code);
+
+ int ret = false;
+ int err = EMF_ERROR_NONE;
+ em_core_uid_list *p = NULL;
+
+ if (!uid_list) {
+ EM_DEBUG_EXCEPTION(" uid_list[%p]\n", uid_list);
+
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ while (uid_list) {
+ p = uid_list; uid_list = uid_list->next;
+
+ EM_SAFE_FREE(p->uid);
+
+ free(p);
+ p = NULL;
+ }
+
+ ret = true;
+
+FINISH_OFF:
+ if (err_code)
+ *err_code = err;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+
+#ifdef __FEATURE_SYNC_CLIENT_TO_SERVER__
+/* callback for GET_APPENDUID - shasikala.p */
+void mail_appenduid(char *mailbox, unsigned long uidvalidity, SEARCHSET *set)
+{
+ EM_DEBUG_FUNC_BEGIN("mailbox - %s", mailbox);
+ EM_DEBUG_LOG("UID - %ld", set->first);
+
+ memset(g_append_uid_rsp, 0x00, 129);
+
+ sprintf(g_append_uid_rsp, "%ld", set->first);
+ EM_DEBUG_LOG("append uid - %s", g_append_uid_rsp);
+}
+
+EXPORT_API int em_core_mail_sync_from_client_to_server(int account_id, int mail_id, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("account_id [%d], mail_id [%d], mail_id [%p]", account_id, mail_id, *err_code);
+
+ int err = EMF_ERROR_NONE;
+ int ret = false;
+ int len = 0;
+ int read_size = 0;
+ char *fname = NULL;
+ char *long_enc_path = NULL;
+ char *data = NULL;
+ char set_flags[100] = { 0, };
+ ENVELOPE *envelope = NULL;
+ FILE *fp = NULL;
+ STRING str;
+ MAILSTREAM *stream = NULL;
+ emf_mail_t *mail = NULL;
+ emf_mail_tbl_t *mail_table_data = NULL;
+ emf_mailbox_tbl_t *mailbox_tbl = NULL;
+
+ if (mail_id < 1){
+ EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ /* get a mail from mail table */
+ if (!em_storage_get_mail_by_id(mail_id, &mail_table_data, true, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_get_mail_by_id failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ EM_DEBUG_LOG("mailbox_name [%s]", mail_table_data->mailbox_name);
+ if (!em_storage_get_mailbox_by_name(mail_table_data->account_id, 0, mail_table_data->mailbox_name, &mailbox_tbl, false, &err) || !mailbox_tbl){
+ EM_DEBUG_EXCEPTION("em_storage_get_mailbox_by_name failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ if (mailbox_tbl->sync_with_server_yn == 0) {
+ EM_DEBUG_EXCEPTION("The mailbox [%s] is not on server.", mail_table_data->mailbox_name);
+ err = EMF_ERROR_INVALID_MAILBOX;
+ goto FINISH_OFF;
+ }
+
+ /* get a mail to send */
+ if (!em_core_mail_get_mail(mail_id, &mail, &err)){
+ EM_DEBUG_EXCEPTION(" em_core_mail_get_mail failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ if (!em_core_get_long_encoded_path(mail_table_data->account_id, mail_table_data->mailbox_name, '/', &long_enc_path, &err)) {
+ EM_DEBUG_EXCEPTION(">>em_core_get_long_encoded_path : Failed [%d] ", err);
+ goto FINISH_OFF;
+ }
+
+ if (!long_enc_path) {
+ EM_DEBUG_EXCEPTION(">>long_enc_path : NULL ");
+ goto FINISH_OFF;
+ }
+
+ if (!em_core_mail_get_rfc822(mail, &envelope, &fname, NULL, &err)){
+ EM_DEBUG_EXCEPTION(" em_core_mail_get_rfc822 failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ if (fname){
+ if (!(fp = fopen(fname, "a+")))
+ {
+ EM_DEBUG_EXCEPTION("fopen failed - %s", fname);
+ err = EMF_ERROR_SYSTEM_FAILURE;
+ goto FINISH_OFF;
+ }
+ }
+
+ if (!fp) {
+ EM_DEBUG_EXCEPTION("fp is NULL..!");
+ err = EMF_ERROR_SYSTEM_FAILURE;
+ goto FINISH_OFF;
+ }
+
+ rewind(fp);
+
+ ret = fseek(fp, 0, SEEK_END) == 0 && (len = ftell(fp)) != -1;
+
+ if (fname)
+ EM_DEBUG_LOG("Composed file name [%s] and file size [%d]", fname, len);
+
+ rewind(fp);
+
+ ret = 0;
+ stream = NULL;
+ if (!em_core_mailbox_open(mail_table_data->account_id, NULL, (void **)&stream, &err)){
+ EM_DEBUG_EXCEPTION("em_core_mail_move_from_server failed : Mailbox open[%d]", err);
+ goto FINISH_OFF;
+ }
+
+ /* added for copying server UID to DB */
+ mail_parameters(stream, SET_APPENDUID, mail_appenduid);
+
+ data = (char *)malloc(len + 1);
+ /* copy data from file to data */
+ read_size = fread(data, sizeof (char), len, fp);
+ if (read_size != len){
+ /* read faiil. */
+ EM_DEBUG_EXCEPTION("Read from file failed");
+ }
+
+ INIT(&str, mail_string, data, len);
+
+ sprintf(set_flags, "\\Seen");
+
+ if ((mail->info->flags).seen){
+ if (!mail_append_full(stream, long_enc_path, set_flags, NULL, &str)) {
+ EM_DEBUG_EXCEPTION("mail_append failed -");
+ goto FINISH_OFF;
+ }
+ }
+ else{
+ if (!mail_append_full(stream, long_enc_path, NULL, NULL, &str)) {
+ EM_DEBUG_EXCEPTION("mail_append failed -");
+ goto FINISH_OFF;
+ }
+ }
+
+ /* Update read_mail_uid tbl */
+ if (!em_core_mailbox_add_read_mail_uid(mailbox_tbl, mail_table_data->mailbox_name, mail_table_data->mail_id, g_append_uid_rsp, mail_table_data->mail_size, 0, &err)) {
+ EM_DEBUG_EXCEPTION(" em_core_mailbox_add_read_mail_uid failed [%d]", err);
+ em_storage_rollback_transaction(NULL, NULL, NULL);
+ goto FINISH_OFF;
+ }
+
+ ret = true;
+
+FINISH_OFF:
+
+#ifdef __LOCAL_ACTIVITY__
+ if (ret){
+ emf_activity_tbl_t new_activity;
+ memset(&new_activity, 0x00, sizeof(emf_activity_tbl_t));
+ new_activity.activity_type = ACTIVITY_SAVEMAIL;
+ new_activity.account_id = account_id;
+ new_activity.mail_id = mail_id;
+ new_activity.dest_mbox = NULL;
+ new_activity.server_mailid = NULL;
+ new_activity.src_mbox = NULL;
+
+ if (!em_core_activity_delete(&new_activity, &err)){
+ EM_DEBUG_EXCEPTION(">>>>>>Local Activity [ACTIVITY_SAVEMAIL] [%d] ", err);
+ }
+ }
+#endif /* __LOCAL_ACTIVITY__ */
+
+ EM_SAFE_FREE(data);
+ EM_SAFE_FREE(long_enc_path);
+
+ if (fp)
+ fclose(fp);
+
+ if (envelope)
+ mail_free_envelope(&envelope);
+
+ if (mail)
+ em_core_mail_free(&mail, 1, NULL);
+
+ if (mail_table_data)
+ em_storage_free_mail(&mail_table_data, 1, NULL);
+
+ if (mailbox_tbl)
+ em_storage_free_mailbox(&mailbox_tbl, 1, NULL);
+
+ if (fname) {
+ remove(fname);
+ EM_SAFE_FREE(fname);
+ }
+
+ if (stream){
+ em_core_mailbox_close(0, stream);
+ stream = NULL;
+ }
+
+ if (err_code != NULL)
+ *err_code = err;
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+#endif
+
+#ifdef __FEATURE_PARTIAL_BODY_DOWNLOAD__
+
+static int em_core_initiate_pbd(MAILSTREAM *stream, int account_id, int mail_id, char *uid, char *input_mailbox_name, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("account_id [%d], mail_id[%d], uid[%p], input_mailbox_name[%p]", account_id, mail_id, uid, input_mailbox_name);
+
+ int ret = false;
+ int err = EMF_ERROR_NONE;
+ emf_account_t *account_ref;
+
+ if (account_id < FIRST_ACCOUNT_ID || mail_id < 0 || NULL == uid || NULL == input_mailbox_name){
+ EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ account_ref = em_core_get_account_reference(account_id);
+
+ emf_event_partial_body_thd pbd_event;
+
+ memset(&pbd_event, 0x00, sizeof(emf_event_partial_body_thd));
+
+ pbd_event.account_id = account_id;
+ if (account_ref && account_ref->receiving_server_type == EMF_SERVER_TYPE_POP3)
+ pbd_event.activity_type = ACTIVITY_PARTIAL_BODY_DOWNLOAD_POP3_WAIT;
+ else
+ pbd_event.activity_type = ACTIVITY_PARTIAL_BODY_DOWNLOAD_IMAP4;
+
+ pbd_event.mailbox_name = EM_SAFE_STRDUP(input_mailbox_name);
+ pbd_event.mail_id = mail_id;
+ pbd_event.server_mail_id = strtoul(uid, NULL, 0);
+
+ EM_DEBUG_LOG("input_mailbox_name name [%s]", pbd_event.mailbox_name);
+ EM_DEBUG_LOG("uid [%s]", uid);
+ EM_DEBUG_LOG("pbd_event.account_id[%d], pbd_event.mail_id[%d], pbd_event.server_mail_id [%d]", pbd_event.account_id, pbd_event.mail_id , pbd_event.server_mail_id);
+
+ if (!em_core_insert_pbd_activity(&pbd_event, &pbd_event.activity_id, &err)){
+ EM_DEBUG_EXCEPTION("Inserting Partial Body Download activity failed with error[%d]", err);
+ goto FINISH_OFF;
+ }
+ else{
+ if (false == em_core_is_partial_body_thd_que_full()){
+ /* h.gahaut : Before inserting the event into event queue activity_type should be made 0
+ Because partial body thread differentiates events coming from DB and event queue
+ on the basis of activity_type and event_type fields */
+
+ pbd_event.activity_type = 0;
+ pbd_event.event_type = EMF_EVENT_BULK_PARTIAL_BODY_DOWNLOAD;
+
+ if (!em_core_insert_partial_body_thread_event(&pbd_event, &err)){
+ EM_DEBUG_EXCEPTION("Inserting Partial body thread event failed with error[%d]", err);
+ goto FINISH_OFF;
+ }
+
+ /*h.gahlaut : Partial body thread has created a copy of event for itself so this local event should be freed here*/
+ if (!em_core_free_partial_body_thd_event(&pbd_event, &err))
+ EM_DEBUG_EXCEPTION("Freeing Partial body thread event failed with error[%d]", err);
+ }
+ else{
+ EM_DEBUG_LOG(" Activity inserted only in DB .. Queue is Full");
+ }
+ }
+
+ ret = true;
+
+ FINISH_OFF:
+
+ if (NULL != err_code)
+ *err_code = err;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+#define UID_RANGE_STRING_LENGTH 3000
+#define TEMP_STRING_LENGTH 50
+
+static int em_core_parse_html_part_for_partial_body(char *start_header, char *boundary_string, char *bufsendforparse, char *text_html, int body_size)
+{
+ EM_DEBUG_FUNC_BEGIN("start_header [%s], boundary_string [%s], bufsendforparse [%s], text_html [%s], body_size [%d]", start_header, boundary_string, bufsendforparse, text_html, body_size);
+
+ int err = EMF_ERROR_NONE;
+ int html_uidno = 0;
+ int iEncodingHeader = 0;
+ int enc_type = ENCOTHER, dec_len = 0, html_length = 0;
+ char EncodingHeader[40] = {0};
+ char Encoding[30] = {0};
+ char *pEncodingHeaderEnd = NULL;
+ char *txt_html = NULL;
+ char *pHeaderStart = NULL;
+ char *start = NULL, *end = NULL;
+ char *temp_enc1 = NULL;
+
+ EM_DEBUG_LOG("Content-Type : text/html or message/rfc822 or text/rfc822-headers");
+
+ pHeaderStart = start_header;
+ pHeaderStart = pHeaderStart-2;
+ do{
+ pHeaderStart--;
+ } while (*pHeaderStart != LF && bufsendforparse < pHeaderStart);
+
+ pHeaderStart++;
+
+ memcpy(EncodingHeader, pHeaderStart, 25);
+
+ if (strcasecmp(EncodingHeader, "Content-Transfer-Encoding") == 0){
+ pEncodingHeaderEnd = strstr(pHeaderStart, CRLF_STRING);
+ memcpy(Encoding, pHeaderStart + 27, pEncodingHeaderEnd - (pHeaderStart+27));
+ iEncodingHeader = 1;
+ }
+
+ /* HTML Content found */
+
+ txt_html = start_header;
+ txt_html = strstr(txt_html, CRLF_STRING CRLF_STRING);
+
+ if (txt_html != NULL){
+ txt_html += 4; /* txt_html points at html content */
+ start = txt_html;
+ char multipart_boundary[100] = {0};
+ char *multipart_related_boundry = NULL;
+ char *multipart_related_boundry_end = NULL;
+ if (iEncodingHeader == 1)
+ multipart_related_boundry = pHeaderStart;
+ else
+ multipart_related_boundry = start_header;
+
+ multipart_related_boundry = multipart_related_boundry - 3;
+ multipart_related_boundry_end = multipart_related_boundry;
+
+ while (bufsendforparse < multipart_related_boundry && *multipart_related_boundry != LF && *multipart_related_boundry != NULL_CHAR)
+ multipart_related_boundry -= 1;
+
+ multipart_related_boundry += 1;
+ memcpy(multipart_boundary, multipart_related_boundry, multipart_related_boundry_end - multipart_related_boundry);
+
+ EM_DEBUG_LOG("multipart_boundary [%s], boundary_string [%s]", multipart_boundary, boundary_string);
+
+ if (strcmp(multipart_boundary, boundary_string) == 0)
+ end = strstr(txt_html, boundary_string);
+ else
+ end = strstr(txt_html, multipart_boundary);
+
+ memset(multipart_boundary, 0, strlen(multipart_boundary));
+
+ EM_DEBUG_LOG("end [%p], txt_html [%p]", end, txt_html);
+
+ if (end == NULL) {
+ EM_DEBUG_LOG("HTML body contents exceeds %d Bytes", PARTIAL_BODY_SIZE_IN_BYTES);
+
+ end = txt_html + body_size - (txt_html - bufsendforparse);
+ html_uidno = 1;
+ }
+ else if(end == txt_html) { /* empty multipart */
+ EM_DEBUG_LOG("Emtpy HTML multipart");
+ return false;
+ }
+ else {
+ if ((*(end-2) == CR) && (*(end-1) == LF))
+ end -= 2;
+ else if ((*(end-2) == CR) && (*(end-1) == LF)
+ && (*(end-4) == CR) && (*(end-3) == LF))
+ end -= 4;
+ else
+ EM_DEBUG_EXCEPTION(" Content not per as grammar.");
+ }
+
+ EM_DEBUG_LOG("end [%p], txt_html [%p]", end, txt_html);
+
+ EM_DEBUG_LOG("iEncodingHeader [%d]", iEncodingHeader);
+
+ if (iEncodingHeader == 1){
+ enc_type = ENCOTHER;
+ if (strncasecmp(Encoding, "base64", strlen("base64")) == 0)
+ enc_type = ENCBASE64;
+ else if (strncasecmp(Encoding, "quoted-printable", strlen("quoted-printable")) == 0)
+ enc_type = ENCQUOTEDPRINTABLE;
+
+ EM_DEBUG_LOG("enc_type [%d]", enc_type);
+
+ memcpy(text_html, start, end - txt_html);
+
+ if (em_core_decode_body_text(text_html, end - txt_html, enc_type , &dec_len, &err) < 0)
+ EM_DEBUG_EXCEPTION("em_core_decode_body_text failed [%d]", err);
+ }
+ else if (start_header && ((temp_enc1 = (char *)strcasestr(start_header, "Content-transfer-encoding:")) != NULL) && !(temp_enc1 && temp_enc1 >= end)){
+ if (temp_enc1)
+ start_header = temp_enc1;
+
+ start_header += strlen("Content-Transfer-Encoding:");
+ start_header = em_core_skip_whitespace_without_strdup(start_header);
+
+ if (!start_header)
+ EM_DEBUG_EXCEPTION(" Invalid parsing ");
+ else{
+ enc_type = ENCOTHER;
+ if (strncasecmp(start_header, "base64", strlen("base64")) == 0)
+ enc_type = ENCBASE64;
+ else if (strncasecmp(start_header, "quoted-printable", strlen("quoted-printable")) == 0)
+ enc_type = ENCQUOTEDPRINTABLE;
+
+ EM_DEBUG_LOG("enc_type [%d]", enc_type);
+
+ memcpy(text_html, start, end - txt_html);
+
+ if (em_core_decode_body_text(text_html, end - txt_html, enc_type , &dec_len, &err) < 0)
+ EM_DEBUG_EXCEPTION("em_core_decode_body_text failed [%d]", err);
+ html_length = dec_len;
+ }
+
+ EM_DEBUG_LOG("Decoded length = %d", dec_len);
+ EM_DEBUG_LOG("start - %s", start);
+ }
+ else{
+ memcpy(text_html, start, end-txt_html);
+ html_length = (end-txt_html);
+ }
+
+ /* EM_DEBUG_LOG(" Content-Type: text/html [%s]\n", text_html); */
+ }
+ else
+ EM_DEBUG_EXCEPTION(" Invalid html body content ");
+
+ EM_DEBUG_FUNC_END();
+ return true;
+}
+
+
+
+/*For the following scenario
+*Content-Transfer-Encoding : base64
+*Content-Type : text/plain; charset = "windows-1252"
+*MIME-Version : 1.0
+*Message-ID: <11512468.945901271910226702.JavaMail.weblogic@epml03>
+*/
+
+#define CONTENT_TRANSFER_ENCODING "Content-Transfer-Encoding"
+
+static int em_core_parse_plain_part_for_partial_body(char *header_start_string, char *start_header, char *boundary_string, char *bufsendforparse, char *text_plain, int body_size)
+{
+ EM_DEBUG_FUNC_BEGIN("header_start_string[%s], start_header[%s], boundary_string [%s], bufsendforparse [%s], text_plain [%s]", header_start_string, start_header, boundary_string, bufsendforparse, text_plain);
+ int err = EMF_ERROR_NONE, iEncodingHeader = 0, enc_type = ENCOTHER;
+ int dec_len = 0, strcmpret = -1;
+ char *pHeaderStart = NULL, *pEncodingHeaderEnd = NULL;
+ char EncodingHeader[40] = {0, };
+ char Encoding[30] = {0, };
+ char *temp_text_boundary = NULL;
+ char *start = NULL, *end = NULL, *txt_plain = NULL, *temp_enc1 = NULL;
+
+ EM_DEBUG_LOG("Content-Type : text/plain");
+
+ pHeaderStart = header_start_string;
+ temp_text_boundary = start_header;
+
+ memcpy(EncodingHeader, pHeaderStart, 25);
+
+ if (strcasecmp(EncodingHeader, "Content-Transfer-Encoding") == 0){
+ pEncodingHeaderEnd = strstr(pHeaderStart, CRLF_STRING);
+ memcpy(Encoding, pHeaderStart + 27, pEncodingHeaderEnd - (pHeaderStart + 27));
+ iEncodingHeader = 1;
+ }
+
+ /* Plain text content found */
+
+ txt_plain = start_header;
+ txt_plain = strstr(txt_plain, CRLF_STRING CRLF_STRING);
+
+ if (txt_plain != NULL){
+ txt_plain += strlen(CRLF_STRING CRLF_STRING); /* txt_plain points at plain text content */
+
+ /* Fix is done for mail having "Content-Type: text/plain" but there is no content but having only attachment. */
+
+ strcmpret = strncmp(txt_plain, boundary_string, strlen(boundary_string));
+ if (strcmpret == 0){
+ }
+ else{
+ start = txt_plain;
+ end = strstr(txt_plain, boundary_string);
+
+ if (end == NULL){
+ EM_DEBUG_LOG("Text body contents exceeds %d Bytes", PARTIAL_BODY_SIZE_IN_BYTES);
+ end = txt_plain + body_size - (txt_plain - bufsendforparse);
+ }
+ else{
+ /* EM_DEBUG_LOG("pbd_event[temp_count].partial_body_complete - %d", partial_body_complete); */
+
+ if ((*(end-2) == CR) && (*(end-1) == LF))
+ end -= 2;
+ else if ((*(end-2) == CR) && (*(end-1) == LF)
+ && (*(end-4) == CR) && (*(end-3) == LF))
+ end -= 4;
+ else
+ EM_DEBUG_EXCEPTION(" Content not per as grammar.");
+ }
+
+ if (iEncodingHeader == 1){
+ enc_type = ENCOTHER;
+ if (strncasecmp(Encoding, "base64", strlen("base64")) == 0)
+ enc_type = ENCBASE64;
+ else if (strncasecmp(Encoding, "quoted-printable", strlen("quoted-printable")) == 0)
+ enc_type = ENCQUOTEDPRINTABLE;
+
+ EM_DEBUG_LOG("enc_type [%d]", enc_type);
+
+ memcpy(text_plain, start, end - txt_plain);
+
+ if (em_core_decode_body_text(text_plain, end - txt_plain, enc_type , &dec_len, &err) < 0)
+ EM_DEBUG_EXCEPTION("em_core_decode_body_text failed [%d]", err);
+ }
+ else if (start_header && ((temp_enc1 = (char *)strcasestr(start_header, "Content-transfer-encoding:")) != NULL) && !(temp_enc1 && temp_enc1 >= end)){
+ if (temp_enc1)
+ start_header = temp_enc1;
+
+ start_header += strlen("Content-Transfer-Encoding:");
+ start_header = em_core_skip_whitespace_without_strdup(start_header);
+
+ if (!start_header)
+ EM_DEBUG_EXCEPTION(" Invalid parsing ");
+ else{
+ enc_type = ENCOTHER;
+ if (strncasecmp(start_header, "base64", strlen("base64")) == 0)
+ enc_type = ENCBASE64;
+ else if (strncasecmp(start_header, "quoted-printable", strlen("quoted-printable")) == 0)
+ enc_type = ENCQUOTEDPRINTABLE;
+
+ EM_DEBUG_LOG("enc_type [%d]", enc_type);
+ memcpy(text_plain, start, end - txt_plain);
+ if (em_core_decode_body_text(text_plain, end - txt_plain, enc_type , &dec_len, &err) < 0)
+ EM_DEBUG_EXCEPTION("em_core_decode_body_text failed [%d]", err);
+ }
+
+ EM_DEBUG_LOG("Decoded length = %d", dec_len);
+ /* EM_DEBUG_LOG("start - %s", start); */ /* print raw MIME content. */
+ }
+ else
+ memcpy(text_plain, start, end-txt_plain);
+
+ /* EM_DEBUG_LOG(" Content-type: text/plain [%s]\n", text_plain); */
+ }
+ }
+ else
+ EM_DEBUG_EXCEPTION(" Invalid text body content ");
+
+ EM_DEBUG_FUNC_END();
+ return 1;
+}
+
+
+
+/* Content-Type : IMAGE/octet-stream; name = Default.png */
+/* Content-Transfer-Encoding : BASE64 */
+/* Content-ID: <4b0d6810b17291f9438783a8eb9d5228@email-service> */
+/* Content-Disposition : inline; filename = Default.png */
+
+static int em_core_parse_image_part_for_partial_body(char *header_start_string, char *start_header, char *boundary_string, char *bufsendforparse, emf_image_data *image_data, int body_size)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ int err = EMF_ERROR_NONE;
+ char *multiple_image = NULL;
+ int donot_parse_next_image = 0;
+ char *image_boundary = NULL;
+ char *image_boundary_end = NULL;
+ char temp_image_boundary[256] = {0};
+ int i = 0, ch_image = 0, cidno = 0;
+ int enc_type = ENCOTHER, dec_len = 0, image_length = 0;
+ char *p = header_start_string;
+ char *start = NULL, *end = NULL, *txt_image = NULL;
+ char *temp_image = NULL;
+ char *temp_cid1 = NULL;
+ char *cid_end = NULL;
+ char *temp_enc1 = NULL;
+
+
+ image_boundary = start_header;
+ image_boundary_end = image_boundary - 2;
+ image_boundary = image_boundary - 2;
+
+ EM_DEBUG_LOG("Content-type: image");
+
+ while (*image_boundary != LF)
+ image_boundary--;
+
+ image_boundary++;
+
+ if (image_boundary != NULL && image_boundary_end != NULL)
+ memcpy(temp_image_boundary, image_boundary, image_boundary_end-image_boundary);
+
+ if ((char *)strcasestr((const char *)temp_image_boundary, "Content-type:") == NULL)
+ boundary_string = temp_image_boundary;
+ do {
+ if (multiple_image != NULL){
+ p = multiple_image;
+ start_header = multiple_image;
+ }
+ if ((strcasestr(p, "Content-Disposition: attachment")) || (!strcasestr(p, "Content-ID: <"))){
+ EM_DEBUG_EXCEPTION(" Body has attachment no need to parse ");
+ end = NULL;
+ multiple_image = NULL;
+ }
+ else{ /* HTML Content found */
+ ch_image = 0;
+ cidno = 0;
+ int boundarylen = -1;
+ char *cid = NULL;
+ char *temp_name = NULL;
+
+ memset(image_data[i].image_file_name, 0, 100);
+ txt_image = start_header;
+ temp_image = start_header;
+
+ temp_name = strstr(txt_image, "name=");
+ if (temp_name != NULL){
+ temp_image = temp_name;
+ if (*(temp_image+5) == '"')
+ temp_image = temp_image+5;
+
+ while (*temp_image != CR){
+ temp_image++;
+ memcpy(image_data[i].image_file_name+ch_image, temp_image, 1);
+ ch_image++;
+ }
+
+ if ((*(temp_name+4) == '=') && (*(temp_name+5) == '\"'))
+ image_data[i].image_file_name[ch_image-2] = '\0';
+
+ if ((*(temp_name+4) == '=') && (*(temp_name+5) != '\"'))
+ image_data[i].image_file_name[ch_image-1] = '\0';
+ }
+
+ if (((temp_cid1 = (char *)strcasestr((const char *)start_header, "Content-ID: <")) != NULL)){
+ if (temp_cid1){
+ cid = temp_cid1;
+ temp_image = temp_cid1;
+ }
+
+ cid += 13;
+ cid_end = strstr(temp_image, "\076"); /* 076 == '>' */
+
+ image_data[i].content_id = (char *)em_core_malloc(cid_end-cid+5);
+ if (image_data[i].content_id != NULL){
+ strcpy(image_data[i].content_id, "cid:");
+ memcpy(image_data[i].content_id+4, cid, cid_end-cid);
+ }
+ else
+ EM_DEBUG_EXCEPTION("em_core_malloc() failed");
+
+ if (image_data[i].image_file_name[0] == '\0')
+ memcpy(image_data[i].image_file_name, cid, cid_end - cid);
+ }
+
+ txt_image = strstr(txt_image, CRLF_STRING CRLF_STRING);
+
+ if (txt_image != NULL){
+ txt_image += 4; /* txt_image points at image content */
+ start = txt_image;
+ end = strstr(txt_image, boundary_string);
+
+
+ if (end == NULL){
+ EM_DEBUG_LOG("HTML body contents exceeds %d Bytes", PARTIAL_BODY_SIZE_IN_BYTES);
+ /* end points to end of partial body data */
+ end = txt_image + body_size - (txt_image-bufsendforparse);
+ }
+ else{
+ boundarylen = strlen(boundary_string);
+ end -= 2;
+ }
+
+ if (start_header && ((temp_enc1 = (char *)strcasestr((const char *)start_header, "Content-transfer-encoding:")) != NULL)){
+ if (temp_enc1)
+ start_header = temp_enc1;
+
+ start_header += strlen("Content-Transfer-Encoding:");
+ start_header = em_core_skip_whitespace_without_strdup(start_header);
+
+ if (!start_header)
+ EM_DEBUG_EXCEPTION(" Invalid parsing ");
+ else{
+ enc_type = ENCOTHER;
+ if (strncasecmp(start_header, "base64", strlen("base64")) == 0)
+ enc_type = ENCBASE64;
+ else if (strncasecmp(start_header, "quoted-printable", strlen("quoted-printable")) == 0)
+ enc_type = ENCQUOTEDPRINTABLE;
+
+ EM_DEBUG_LOG("enc_type [%d]", enc_type);
+
+ image_data[i].text_image = (char *)em_core_malloc((end-txt_image)+1);
+ if (image_data[i].text_image){
+ memcpy(image_data[i].text_image, start, end-txt_image);
+ if (em_core_decode_body_text(image_data[i].text_image, end-txt_image, enc_type , &(image_data[i].dec_len), &err) < 0)
+ EM_DEBUG_EXCEPTION("em_core_decode_body_text failed [%d]", err);
+ else
+ image_length = image_data[i].dec_len;
+ }
+ else
+ EM_DEBUG_EXCEPTION("em_core_malloc() failed");
+ }
+
+ EM_DEBUG_LOG("Decoded length [%d]", dec_len);
+ }
+ else{
+ image_data[i].text_image = (char *)em_core_malloc(end-txt_image);
+ if (image_data[i].text_image)
+ memcpy(image_data[i].text_image, start, end - txt_image);
+ else
+ EM_DEBUG_EXCEPTION("em_core_malloc() failed");
+ }
+ }
+ else{
+ donot_parse_next_image = 1;
+ EM_DEBUG_EXCEPTION(" Invalid html body content ");
+ }
+ }
+
+ if (end != NULL) {
+ multiple_image = (char *)strcasestr((const char *)end, "Content-type: image");
+ i++;
+ }
+ } while (multiple_image != NULL && donot_parse_next_image != 1 && (i < IMAGE_DISPLAY_PARTIAL_BODY_COUNT));
+
+ EM_DEBUG_FUNC_END();
+ return 1;
+}
+
+static int em_core_find_boundary_string_of_the_part(const char *whole_string, const char *first_line_of_part, char **result_boundary_string, int *error)
+{
+ EM_DEBUG_FUNC_BEGIN("whole_string[%p], first_line_of_part[%p], result_boundary_string[%p]", whole_string, first_line_of_part, result_boundary_string);
+ int ret = false, err = EMF_ERROR_NONE;
+ char *boundary_cur = NULL, *boundary_end = NULL, *boundary_string = NULL;
+
+ if(!whole_string || !first_line_of_part || !result_boundary_string) {
+ EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ if(first_line_of_part - 2 > whole_string) {
+ boundary_cur = (char*)first_line_of_part - 2; /* 2 means CRLF. */
+ boundary_end = boundary_cur;
+
+ do{
+ boundary_cur--;
+ } while (whole_string < boundary_cur && *boundary_cur != LF && *boundary_cur != NULL_CHAR);
+
+ boundary_cur++;
+
+ if(boundary_end > boundary_cur && boundary_cur > whole_string) {
+ EM_DEBUG_LOG("boundary_end - boundary_cur + 15 [%d]", boundary_end - boundary_cur + 15);
+ boundary_string = em_core_malloc(boundary_end - boundary_cur + 15);
+ if(!boundary_string) {
+ EM_DEBUG_EXCEPTION("em_core_malloc failed");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+ memcpy(boundary_string, boundary_cur, boundary_end - boundary_cur);
+ EM_DEBUG_LOG("boundary_string [%s]", boundary_string);
+ *result_boundary_string = boundary_string;
+ }
+ else {
+ EM_DEBUG_EXCEPTION("There is no string before the part");
+ err = EMF_ERROR_ON_PARSING;
+ goto FINISH_OFF;
+ }
+ }
+ else {
+ EM_DEBUG_EXCEPTION("There is no string before the part");
+ err = EMF_ERROR_ON_PARSING;
+ goto FINISH_OFF;
+ }
+ ret = true;
+FINISH_OFF:
+
+ if(error)
+ *error = err;
+
+ EM_DEBUG_FUNC_END("ret[%d], err[%d]", ret, err);
+ return ret;
+}
+
+#define TAG_LENGTH 16
+#define COMMAND_LENGTH 2000
+EXPORT_API int em_core_bulk_partial_mailbody_download_for_imap(MAILSTREAM *stream, emf_event_partial_body_thd *pbd_event, int item_count, int *error)
+{
+ EM_DEBUG_FUNC_BEGIN("stream [%p], pbd_event [%p], item_count [%d], error [%p]", stream, pbd_event, item_count, error);
+
+ int ret = false, err = EMF_ERROR_NONE;
+ int encoding = 0;
+ int j = 0;
+ int i32_index = 0, temp_string_index = 0;
+ int no_alternative_part_flag = 0;
+ int dec_len = 0, response_buffer_length = 0, mailparselen = 0, image_length = 0, tempmailparselen = 0;
+ int temp_count = 0, total_mail_size = 0, attachment_num, body_size = 0, total_mail_size_except_attach = 0;
+ int total_parsed_len_per_uid = 0, total_parsed_len = 0;
+ unsigned long uidno = 0;
+ char buf[512] = {0, };
+ char text_plain[PARTIAL_BODY_SIZE_IN_BYTES + 1] = {0, };
+ char text_html[PARTIAL_BODY_SIZE_IN_BYTES + 1] = {0, };
+ char temp_text_buf[PARTIAL_BODY_SIZE_IN_BYTES + 1] = {0, };
+ char uid_range_string_to_be_downloaded[UID_RANGE_STRING_LENGTH] = {0, };
+ char imap_tag[TAG_LENGTH] = {0, };
+ char command[COMMAND_LENGTH] = {0, };
+ char *p = NULL, *s = NULL, *decoded_text_buffer = NULL;
+ char *response_buffer = NULL;
+ char *bufsendforparse = NULL;
+ char *start_header = NULL;
+ char *boundary_string = NULL;
+ char *temp_content_type1 = NULL;
+ char *bodystructure_start = NULL, *bodystructure_end = NULL, *body_structure_string = NULL, *moified_body_structure_string = NULL;
+ char *plain_text_file_name_from_content_info = NULL, *html_text_file_name_from_content_info = NULL, *plain_charset_from_content_info = NULL;
+ char temp_string[TEMP_STRING_LENGTH] = {0, };
+ IMAPLOCAL *imaplocal = NULL;
+ IMAPPARSEDREPLY *reply_from_server = NULL;
+ emf_mail_tbl_t *mail = NULL;
+ emf_partial_buffer *imap_response = NULL;
+ BODY *body = NULL;
+ struct _m_content_info *cnt_info = NULL;
+ struct attachment_info *attach_info = NULL;
+ emf_mail_attachment_tbl_t attachment_tbl;
+ emf_event_partial_body_thd *stSectionNo = NULL;
+ emf_image_data image_data[IMAGE_DISPLAY_PARTIAL_BODY_COUNT];
+
+ if (!(stream) || !(imaplocal = stream->local) || !imaplocal->netstream || !pbd_event) {
+ EM_DEBUG_EXCEPTION("invalid parameter");
+ err = EMF_ERROR_INVALID_PARAM;
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+ }
+
+ memset(image_data, 0x00 , sizeof(emf_image_data) * IMAGE_DISPLAY_PARTIAL_BODY_COUNT);
+
+ EM_DEBUG_LOG("Start of em_core_get_section_for_partial_download, item_count = %d ", item_count);
+
+ /* For constructing UID list which is having 10 UID or less at a time */
+ for (j = 0, stSectionNo = pbd_event; (stSectionNo != NULL && j < item_count); j++)
+ {
+ EM_DEBUG_LOG("pbd_event[%d].account_id [%d], mail_id [%d], server_mail_id [%d], activity_id [%d]", \
+ j, stSectionNo[j].account_id, stSectionNo[j].mail_id, stSectionNo[j].server_mail_id, stSectionNo[j].activity_id);
+
+ if (i32_index >= UID_RANGE_STRING_LENGTH){
+ EM_DEBUG_EXCEPTION("String length exceeded its limitation!");
+ goto FINISH_OFF;
+ }
+
+ if (j == item_count - 1)
+ i32_index += SNPRINTF(uid_range_string_to_be_downloaded + i32_index, UID_RANGE_STRING_LENGTH, "%lu", stSectionNo[j].server_mail_id);
+ else
+ i32_index += SNPRINTF(uid_range_string_to_be_downloaded + i32_index, UID_RANGE_STRING_LENGTH, "%lu,", stSectionNo[j].server_mail_id);
+ }
+
+ SNPRINTF(imap_tag, TAG_LENGTH, "%08lx", 0xffffffff & (stream->gensym++));
+ SNPRINTF(command, COMMAND_LENGTH, "%s UID FETCH %s (BODYSTRUCTURE BODY.PEEK[TEXT]<0.15360>)\015\012", imap_tag, uid_range_string_to_be_downloaded);
+
+ mm_dlog(command);
+
+ /* Sending out the IMAP request */
+ if (!net_sout(imaplocal->netstream, command, (int)strlen(command))) {
+ EM_DEBUG_EXCEPTION("net_sout failed...");
+ err = EMF_ERROR_CONNECTION_BROKEN;
+ goto FINISH_OFF;
+ }
+
+ /* responce from the server */
+ imap_response = em_core_get_response_from_server(imaplocal->netstream, imap_tag, &reply_from_server);
+
+ if (!imap_response || !reply_from_server ){
+ EM_DEBUG_EXCEPTION(" Invalid response from em_core_get_response_from_server");
+ goto FINISH_OFF;
+ }
+
+ if (!imap_response->buffer || imap_response->buflen == 0){
+ EM_DEBUG_EXCEPTION(" NULL partial BODY Content ");
+ goto FINISH_OFF;
+ }
+ EM_DEBUG_LOG("imap_response->buffer [%s]",imap_response->buffer);
+ response_buffer = imap_response->buffer;
+ response_buffer_length = imap_response->buflen;
+
+ while (response_buffer && (bodystructure_start = strstr(response_buffer, "BODYSTRUCTURE (")) != NULL){
+ /* if it has BODYSTRUCTURE */
+ EM_DEBUG_LOG("response_buffer [%s]",response_buffer);
+ bodystructure_start = bodystructure_start + strlen("BODYSTRUCTURE");
+ bodystructure_end = strstr(bodystructure_start, "BODY[");
+
+ if (bodystructure_end != NULL){
+ int bodystructure_length = bodystructure_end - bodystructure_start;
+
+ EM_DEBUG_LOG("bodystructure_length [%d]", bodystructure_length);
+
+ if (bodystructure_length > response_buffer_length){
+ EM_DEBUG_EXCEPTION("bodystructure_length[%d] is longer than response_buffer_length[%d]", bodystructure_length, response_buffer_length);
+ err = EMF_ERROR_INVALID_RESPONSE;
+ goto FINISH_OFF;
+ }
+
+ body_structure_string = (char *)em_core_malloc(sizeof(char) * bodystructure_length + 1);
+
+ if (NULL == body_structure_string){
+ EM_DEBUG_EXCEPTION("em_core_malloc failed...!");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ memcpy(body_structure_string, bodystructure_start, bodystructure_length);
+
+ body = mail_newbody();
+
+ if (NULL == body){
+ EM_DEBUG_EXCEPTION("New body creation failed...!");
+ EM_SAFE_FREE(body_structure_string);
+ goto FINISH_OFF;
+ }
+
+ /* Parse body_structure_string to BODY */
+ EM_DEBUG_LOG("body_structure_string [%s]", body_structure_string);
+ /* body_structure_string modified */
+ moified_body_structure_string = em_core_replace_string(body_structure_string, "}\r\n", "} ");
+ if (moified_body_structure_string != NULL) {
+ EM_SAFE_STRNCPY(body_structure_string, moified_body_structure_string, strlen(moified_body_structure_string));
+ EM_DEBUG_LOG("moified_body_structure_string [%s]", moified_body_structure_string);
+ }
+ imap_parse_body_structure (stream, body, (unsigned char **)&body_structure_string, reply_from_server);
+
+ total_mail_size = 0;
+
+ if (em_core_set_fetch_body_section(body, true, &total_mail_size, &err) < 0) {
+ EM_DEBUG_EXCEPTION("em_core_set_fetch_body_section failed - %d", err);
+ goto FINISH_OFF;
+ }
+
+ if (!(cnt_info = em_core_malloc(sizeof(struct _m_content_info)))) {
+ EM_DEBUG_EXCEPTION("em_core_malloc failed...");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ memset(cnt_info, 0, sizeof(struct _m_content_info));
+
+ /* getting content info from body */
+
+ if (em_core_get_body(stream, 0, 0, 0, body, cnt_info, &err) < 0 || !cnt_info) {
+ EM_DEBUG_EXCEPTION("em_core_get_body falied [%d]", err);
+ err = EMF_ERROR_IMAP4_FETCH_UID_FAILURE;
+ goto FINISH_OFF;
+ }
+
+ EM_DEBUG_LOG("Start parsing partial body...");
+
+ int no_html = 0;
+ char *temp_alternative_plain_header = NULL;
+
+ p = (char *)strstr(response_buffer, " {");
+ if (p != NULL){
+ EM_DEBUG_LOG("Getting the body size");
+ p += strlen(" {");
+ s = p;
+
+ temp_string_index = 0;
+ memset(temp_string, 0, TEMP_STRING_LENGTH);
+
+ while (isdigit(*s) && temp_string_index < TEMP_STRING_LENGTH){
+ memcpy(temp_string + temp_string_index, s, 1); /* ! */
+ s++;
+ temp_string_index++;
+ }
+
+ body_size = atoi(temp_string);
+ EM_DEBUG_LOG("body_size [%d]", body_size);
+ }
+ else{
+ body_size = 0;
+ EM_DEBUG_EXCEPTION("Can't find body size from MIME header");
+ /* err = EMF_ERROR_INVALID_RESPONSE; */
+ /* goto FINISH_OFF; */
+ }
+
+ /* Find next line */
+ tempmailparselen = 0;
+ while (tempmailparselen < response_buffer_length && response_buffer[tempmailparselen] != LF)
+ tempmailparselen++;
+ tempmailparselen++;
+
+ if (imap_response->buflen < (total_parsed_len + body_size)){
+ err = EMF_ERROR_CONNECTION_BROKEN;
+ EM_DEBUG_EXCEPTION("EMF_ERROR_CONNECTION_BROKEN : imap_response->buflen [%d], total_parsed_len [%d], body_size [%d]", imap_response->buflen, total_parsed_len, body_size);
+ goto FINISH_OFF;
+ }
+ else {
+ if ((p = strstr(response_buffer, "UID "))) {
+ EM_DEBUG_LOG("getting the UID number");
+ p += strlen("UID ");
+ s = p;
+
+ temp_string_index = 0;
+ memset(temp_string, 0, TEMP_STRING_LENGTH);
+
+ while (isdigit(*s) && temp_string_index < TEMP_STRING_LENGTH){
+ memcpy(temp_string + temp_string_index, s, 1);
+ s++;
+ temp_string_index++;
+ }
+
+ uidno = strtoul(temp_string, NULL, 0);
+ EM_DEBUG_LOG("UID [%d]", uidno);
+
+ for (temp_count = 0; temp_count < BULK_PARTIAL_BODY_DOWNLOAD_COUNT &&
+ pbd_event[temp_count].server_mail_id != uidno && temp_count != item_count; temp_count++)
+ continue;
+
+ if (temp_count >= BULK_PARTIAL_BODY_DOWNLOAD_COUNT){
+ EM_DEBUG_EXCEPTION("Can't find proper server_mail_id");
+ goto FINISH_OFF;
+ }
+
+ EM_SAFE_FREE(plain_text_file_name_from_content_info);
+ EM_SAFE_FREE(html_text_file_name_from_content_info);
+ EM_SAFE_FREE(plain_charset_from_content_info);
+
+ /* partial_body_complete = -1; */ /* Meaningless */
+ /* encoding = -1; */ /* Meaningless */
+
+ plain_text_file_name_from_content_info = EM_SAFE_STRDUP(cnt_info->text.plain);
+ html_text_file_name_from_content_info = EM_SAFE_STRDUP(cnt_info->text.html);
+ plain_charset_from_content_info = EM_SAFE_STRDUP(cnt_info->text.plain_charset);
+
+ EM_DEBUG_LOG("plain_text_file_name_from_content_info [%s]", plain_text_file_name_from_content_info);
+ EM_DEBUG_LOG("html_text_file_name_from_content_info [%s]", html_text_file_name_from_content_info);
+ EM_DEBUG_LOG("plain_charset_from_content_info [%s]", plain_charset_from_content_info);
+
+ encoding = body->encoding;
+
+ if (!em_storage_get_maildata_by_servermailid(pbd_event[temp_count].account_id, temp_string, &mail , true, &err) || !mail){
+ EM_DEBUG_EXCEPTION("em_storage_get_maildata_by_servermailid failed [%d]", err);
+ if (err == EM_STORAGE_ERROR_MAIL_NOT_FOUND || !mail)
+ goto FINISH_OFF;
+ }
+
+ /* Assign calculated mail size */
+ mail->mail_size = total_mail_size;
+ total_mail_size_except_attach = total_mail_size;
+
+ /* Update attachment details except inline content */
+ if (cnt_info->file && cnt_info->file->name){
+ memset(&attachment_tbl, 0x00, sizeof(emf_attachment_info_t));
+
+ attachment_tbl.account_id = pbd_event[temp_count].account_id;
+ attachment_tbl.mail_id = mail->mail_id;
+ attachment_tbl.mailbox_name = pbd_event[temp_count].mailbox_name;
+ attachment_tbl.file_yn = 0;
+
+ for (attachment_num = 1, attach_info = cnt_info->file; attach_info; attach_info = attach_info->next, attachment_num++) {
+ total_mail_size_except_attach -= attach_info->size;
+ attachment_tbl.attachment_size = attach_info->size;
+ attachment_tbl.attachment_path = attach_info->save;
+ attachment_tbl.attachment_name = attach_info->name;
+ attachment_tbl.flag2 = attach_info->drm;
+ attachment_tbl.flag3 = (attach_info->type == 1) ? 1 : 0;
+#ifdef __ATTACHMENT_OPTI__
+ attachment_tbl.encoding = attach_info->encoding;
+ attachment_tbl.section = attach_info->section;
+#endif
+
+ if (attach_info->type == 1) {
+ EM_DEBUG_LOG("Breaking attachment_num [%d] attach_info->type [%d]", attachment_num, attach_info->type);
+ break; /* Inline images at end of list not to be added */
+ }
+
+ EM_DEBUG_LOG("attach_info->type != 1 [%d]", attachment_num);
+
+ mail->attachment_count++;
+ if (!em_storage_add_attachment(&attachment_tbl, 0, false, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_add_attachment failed [%d]", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+
+ }
+ }
+
+ em_core_mime_free_content_info(cnt_info);
+ cnt_info = NULL;
+
+ mail_free_body(&body);
+ body = NULL;
+
+ }
+
+ /* Find next line. */
+ mailparselen = 0;
+
+ while (mailparselen < response_buffer_length && response_buffer[mailparselen] != LF)
+ mailparselen++;
+
+ mailparselen++;
+
+ /* Removed the response header and send the buffer for parsing */
+ response_buffer = response_buffer + mailparselen;
+ response_buffer_length = response_buffer_length - mailparselen;
+
+ bufsendforparse = em_core_malloc(body_size + 1); /* old */
+ /* bufsendforparse = em_core_malloc(response_buffer_length + 1); */ /* new */
+
+ EM_DEBUG_LOG("body_size [%d], response_buffer_length [%d]", body_size, response_buffer_length);
+
+ if (bufsendforparse == NULL){
+ EM_DEBUG_EXCEPTION("Allocation for bufsendforparse failed.");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ memcpy(bufsendforparse, response_buffer, body_size); /* old */
+ bufsendforparse[body_size] = NULL_CHAR; /* old */
+ /* EM_SAFE_STRNCPY(bufsendforparse, response_buffer, response_buffer_length);*/ /* new */
+ /* bufsendforparse[response_buffer_length] = '\0'; */ /* new */
+
+ if (strlen(bufsendforparse) == 0)
+ EM_DEBUG_EXCEPTION(" NULL partial BODY Content ");
+
+ EM_DEBUG_LOG("string bufendforparse :[%s]", bufsendforparse);
+ p = bufsendforparse;
+ EM_DEBUG_LOG("string p :[%s]", p);
+ if (mail && mail->body_download_status == EMF_BODY_DOWNLOAD_STATUS_FULLY_DOWNLOADED) /* No need to save */
+ goto NEXTUIDPARSING;
+
+ if (!strcasestr(p, "Content-Type: text/plain") && !strcasestr(p, "Content-Type: text/html") && !strcasestr(p, "Content-type: image/jpeg")
+ && !strcasestr(p, "Content-Type: image/gif") && !strcasestr(p, "Content-Type: image/bmp")&&(plain_text_file_name_from_content_info || html_text_file_name_from_content_info)){
+ /* Encoded Content-Type: text/html or Content-Type: text/plain */
+ /* No Partial body has No headers with Content-Type: text/html or Content-Type: text/plain */
+
+ EM_DEBUG_LOG("plain_text_file_name_from_content_info [%p] html_text_file_name_from_content_info[%p] ", plain_text_file_name_from_content_info, html_text_file_name_from_content_info);
+ EM_DEBUG_LOG("mbody->encoding [%d] ", encoding);
+
+ if (em_core_decode_body_text(p, strlen(p), encoding , &dec_len, &err) < 0) {
+ EM_DEBUG_EXCEPTION("em_core_decode_body_text failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ decoded_text_buffer = p;
+
+ EM_DEBUG_LOG("Decoded length [%d]", dec_len);
+ /* EM_DEBUG_LOG("p - %s", p); */
+
+ if (dec_len > 0){
+ if (plain_text_file_name_from_content_info){
+ EM_DEBUG_LOG(" plain_text_file_name_from_content_info [%s]", plain_text_file_name_from_content_info);
+ memcpy(text_plain, decoded_text_buffer, dec_len);
+ /* EM_DEBUG_LOG(" Content-Type : text/plain [%s]", text_plain); */
+ }
+
+ if (html_text_file_name_from_content_info){
+ EM_DEBUG_LOG("html_text_file_name_from_content_info [%s]", html_text_file_name_from_content_info);
+ memcpy(text_html, decoded_text_buffer, dec_len);
+ /* EM_DEBUG_LOG(" Content-Type: text/html [%s]", text_html); */
+ }
+ }
+ }
+ else{ /* Partial body has headers with Content-Type: text/html or Content-Type: text/plain */
+ no_alternative_part_flag = 0;
+
+ if (((temp_alternative_plain_header = (char *)strcasestr(p, "Content-type: multipart/alternative")) != NULL)){ /* Found 'alternative' */
+ if (((temp_content_type1 = (char *)strcasestr(p, "Content-type: text/plain")) != NULL)){
+ if (temp_content_type1 < temp_alternative_plain_header) /* This part is text/plain not alternative. */
+ no_html = 1;
+ no_alternative_part_flag = 1;
+ }
+ else{
+ EM_DEBUG_LOG(" Content-type: multipart/alternative ");
+ p = strstr(bufsendforparse, CRLF_STRING CRLF_STRING);
+
+ if (p == NULL)
+ EM_DEBUG_EXCEPTION(" Incorrect parsing ");
+ else{
+ p += strlen(CRLF_STRING CRLF_STRING);
+ boundary_string = p;
+ if (boundary_string[0] == CR){
+ EM_DEBUG_EXCEPTION(" Incorrect Body structure ");
+ goto NEXTUIDPARSING;
+ }
+
+ p = strstr(p, CRLF_STRING);
+
+ if (p == NULL)
+ EM_DEBUG_EXCEPTION(" Invalid parsing ");
+ }
+ }
+ }
+ else
+ no_alternative_part_flag = 1;
+
+ if (no_alternative_part_flag){
+ p = strstr(bufsendforparse, "--");
+
+ boundary_string = p;
+ if (boundary_string == NULL){
+ EM_DEBUG_EXCEPTION("Should not have come here ");
+ goto NEXTUIDPARSING;
+ }
+
+ if (boundary_string[0] == CR){
+ EM_DEBUG_EXCEPTION(" Incorrect Body structure ");
+ goto NEXTUIDPARSING;
+ }
+
+ p = strstr(p, CRLF_STRING);
+ if (p == NULL)
+ EM_DEBUG_EXCEPTION(" Invalid parsing ");
+ }
+
+ /* EM_DEBUG_LOG("p[%s]", p); */
+
+ if (p != NULL){
+ *p = NULL_CHAR; /* Boundary value set */
+ EM_DEBUG_LOG("Boundary value [%s]", boundary_string);
+ p += 2; /* p points to content after boundary_string */
+
+ if (((start_header = (char *)strcasestr(p, "Content-Type: text/html")) != NULL) && (no_html != 1) &&(((char *)strcasestr(p, "Content-Type: message/rfc822")) == NULL) &&
+ (((char *)strcasestr(p, "Content-Type: text/rfc822-headers")) == NULL))
+ em_core_parse_html_part_for_partial_body(start_header, boundary_string, bufsendforparse, text_html, body_size);
+
+ if (((start_header = (char *)strcasestr(p, "Content-Type: text/plain")) != NULL)) {
+ char *internal_boundary_string = NULL;
+ if(!em_core_find_boundary_string_of_the_part(bufsendforparse, start_header, &internal_boundary_string, &err)) {
+ EM_DEBUG_EXCEPTION("internal_boundary_string failed [%d]", err);
+ }
+
+ if(!internal_boundary_string)
+ internal_boundary_string = EM_SAFE_STRDUP(boundary_string);
+
+ em_core_parse_plain_part_for_partial_body(p, start_header, internal_boundary_string, bufsendforparse, text_plain, body_size);
+ EM_SAFE_FREE(internal_boundary_string);
+ }
+
+ if (((start_header = (char *)strcasestr((const char *)p, "Content-type: image/jpeg")) != (char *)NULL) ||
+ ((start_header = (char *)strcasestr((const char *)p, "Content-Type: image/gif")) != (char *)NULL) ||
+ ((start_header = (char *)strcasestr((const char *)p, "Content-Type: image/bmp")) != (char *)NULL))
+ em_core_parse_image_part_for_partial_body(p, start_header, boundary_string, bufsendforparse, image_data, body_size);
+ }
+ }
+
+ /* Updating mail information */
+ memset(buf, 0x00, sizeof(buf));
+
+ if (!em_storage_create_dir(pbd_event[temp_count].account_id, mail->mail_id, 0, &err))
+ EM_DEBUG_EXCEPTION("em_storage_create_dir failed [%d]", err);
+
+ if (!em_storage_get_save_name(pbd_event[temp_count].account_id, mail->mail_id, 0,
+ plain_charset_from_content_info ? plain_charset_from_content_info : "UTF-8", buf, &err))
+ EM_DEBUG_EXCEPTION("em_storage_get_save_name failed [%d]", err);
+
+ if (!em_storage_create_file(text_plain, strlen(text_plain), buf, &err))
+ EM_DEBUG_EXCEPTION("em_storage_create_file failed [%d]", err);
+
+ mail->file_path_plain = EM_SAFE_STRDUP(buf);
+ EM_DEBUG_LOG("mail->file_path_plain [%s]", mail->file_path_plain);
+
+ if (image_data[0].text_image != NULL && image_data[0].text_image[0] != NULL_CHAR){
+ char *result_string_of_replcaing = NULL;
+ char temp_data_html[PARTIAL_BODY_SIZE_IN_BYTES + 1] = {0};
+ int store_file = 0;
+ int content_index = 0;
+
+ memset(buf, 0x00, sizeof(buf));
+ if (text_html[0] != NULL_CHAR)
+ memcpy(temp_data_html, text_html, strlen(text_html));
+ /* EM_SAFE_STRNCPY(temp_data_html, text_html, text_html); */
+
+ do {
+ if (!em_storage_create_dir(pbd_event[temp_count].account_id, mail->mail_id, 0, &err))
+ EM_DEBUG_EXCEPTION("em_storage_create_dir failed [%d]", err);
+
+ if (!em_storage_get_save_name(pbd_event[temp_count].account_id, mail->mail_id, 0, image_data[store_file].image_file_name, buf, &err))
+ EM_DEBUG_EXCEPTION("em_storage_get_save_name failed [%d]", err);
+
+ if (!em_storage_create_file(image_data[store_file].text_image, image_data[store_file].dec_len, buf, &err))
+ EM_DEBUG_EXCEPTION("em_storage_create_file failed [%d]", err);
+
+ if (mail->body_download_status != EMF_BODY_DOWNLOAD_STATUS_PARTIALLY_DOWNLOADED){
+ memset(&attachment_tbl, 0x00, sizeof(emf_mail_attachment_tbl_t));
+ attachment_tbl.mail_id = mail->mail_id;
+ attachment_tbl.account_id = pbd_event[temp_count].account_id;
+ attachment_tbl.mailbox_name = stream->mailbox;
+ attachment_tbl.attachment_name = image_data[store_file].image_file_name;
+ attachment_tbl.attachment_size = image_data[store_file].dec_len;
+ attachment_tbl.attachment_path = buf;
+ attachment_tbl.file_yn = 1;
+ attachment_tbl.flag3 = 1; /* set to 1 for inline image */
+ mail->attachment_count++;
+ mail->inline_content_count++;
+ if (!em_storage_add_attachment (&attachment_tbl, false, false, &err))
+ EM_DEBUG_EXCEPTION("em_storage_add_attachment failed - %d", err);
+ }
+
+ store_file++;
+ } while (image_data[store_file].text_image != NULL && image_data[store_file].text_image[0] != NULL_CHAR && (store_file < IMAGE_DISPLAY_PARTIAL_BODY_COUNT));
+
+ while (image_data[content_index].text_image != NULL && image_data[content_index].text_image[0] != NULL_CHAR &&
+ image_data[content_index].content_id && image_data[content_index].content_id[0] != NULL_CHAR && (content_index < IMAGE_DISPLAY_PARTIAL_BODY_COUNT)){ /* Finding CID in HTML and replacing with image name. */
+ result_string_of_replcaing = em_core_replace_string((char *)temp_data_html, (char *)image_data[content_index].content_id, (char *)image_data[content_index].image_file_name);
+
+ EM_SAFE_STRNCPY(temp_data_html, result_string_of_replcaing, PARTIAL_BODY_SIZE_IN_BYTES);
+ EM_SAFE_FREE(result_string_of_replcaing);
+
+ if (strstr(temp_data_html, image_data[content_index].content_id) != NULL)
+ continue; /* Replace content id on HTML with same file name one more time. */
+
+ EM_SAFE_FREE(image_data[content_index].content_id);
+ EM_SAFE_FREE(image_data[content_index].text_image);
+ memset(image_data[content_index].image_file_name, 0x00, 100);
+ image_data[content_index].dec_len = 0;
+ content_index++;
+ }
+
+ image_length = 0;
+ memset(text_html, 0, PARTIAL_BODY_SIZE_IN_BYTES+1);
+
+ if (temp_data_html[0] != NULL_CHAR)
+ memcpy(text_html, temp_data_html, strlen(temp_data_html));
+ memset(temp_data_html, 0x00, PARTIAL_BODY_SIZE_IN_BYTES+1);
+ }
+
+ if (strlen(text_html) > 0){
+ memset(buf, 0x00, sizeof(buf));
+ char html_body[MAX_CHARSET_VALUE] = {0x00, };
+ if (plain_charset_from_content_info != NULL){
+ if (strlen(plain_charset_from_content_info) < MAX_CHARSET_VALUE)
+ memcpy(html_body, plain_charset_from_content_info, strlen(plain_charset_from_content_info));
+ else
+ memcpy(html_body, "UTF-8", strlen("UTF-8"));
+ }
+ if (html_body[0] != NULL_CHAR)
+ strcat(html_body, HTML_EXTENSION_STRING);
+ else
+ memcpy(html_body, "UTF-8.htm", strlen("UTF-8.htm"));
+
+ if (!em_storage_create_dir(pbd_event[temp_count].account_id, mail->mail_id, 0, &err))
+ EM_DEBUG_EXCEPTION("em_storage_create_dir failed [%d]", err);
+
+ if (!em_storage_get_save_name(pbd_event[temp_count].account_id, mail->mail_id, 0, html_body, buf, &err))
+ EM_DEBUG_EXCEPTION("em_storage_get_save_name failed [%d]", err);
+
+ if (!em_storage_create_file(text_html, strlen(text_html), buf, &err))
+ EM_DEBUG_EXCEPTION("em_storage_create_file failed [%d]", err);
+
+ mail->file_path_html = EM_SAFE_STRDUP(buf);
+
+ }
+
+ mail->body_download_status = (total_mail_size_except_attach < PARTIAL_BODY_SIZE_IN_BYTES) ? 1 : 2;
+ EM_DEBUG_LOG("total_mail_size_except_attach [%d], mail->body_download_status [%d]", total_mail_size_except_attach, mail->body_download_status);
+
+ /* Get preview text */
+ if ( (err = em_core_get_preview_text_from_file(mail->file_path_plain, mail->file_path_html, MAX_PREVIEW_TEXT_LENGTH, &(mail->preview_text))) != EMF_ERROR_NONE)
+ EM_DEBUG_EXCEPTION("em_core_get_preview_text_from_file() failed[%d]", err);
+
+ /* Update body contents */
+ if (!em_storage_change_mail_field(mail->mail_id, UPDATE_PARTIAL_BODY_DOWNLOAD, mail, true, &err))
+ EM_DEBUG_EXCEPTION("em_storage_change_mail_field failed - %d", err);
+
+NEXTUIDPARSING:
+
+ response_buffer = response_buffer + body_size; /* Set pointer for next mail body. */
+
+ /* Find end of body */
+ if ((response_buffer[0] == CR) && (response_buffer[1] == LF)&& (response_buffer[2] == ')')
+ && (response_buffer[3] == CR) && (response_buffer[4] == LF)){
+ response_buffer = response_buffer + 5;
+ total_parsed_len_per_uid = body_size+tempmailparselen + 5;
+ }
+ else if ((response_buffer[0] == ')') && (response_buffer[1] == CR) && (response_buffer[2] == LF)){
+ response_buffer = response_buffer + 3;
+ total_parsed_len_per_uid = body_size+tempmailparselen + 3;
+ }
+ else
+ EM_DEBUG_EXCEPTION("Mail response end could not found, - %c : %c : %c", response_buffer[0], response_buffer[1], response_buffer[2]);
+
+ EM_SAFE_FREE(bufsendforparse);
+
+ memset(text_html, 0, PARTIAL_BODY_SIZE_IN_BYTES+1);
+ memset(text_plain, 0, PARTIAL_BODY_SIZE_IN_BYTES+1);
+ memset(temp_text_buf, 0, PARTIAL_BODY_SIZE_IN_BYTES+1);
+
+ if (mail)
+ em_storage_free_mail(&mail, 1, NULL);
+
+ /* Free the activity for mail id in partial body activity table */
+ if (false == em_core_delete_pbd_activity(pbd_event[temp_count].account_id, pbd_event[temp_count].mail_id, pbd_event[temp_count].activity_id, &err)){
+ EM_DEBUG_EXCEPTION("em_core_delete_pbd_activity failed [%d]", err);
+ goto FINISH_OFF;
+ }
+ }
+
+ total_parsed_len += total_parsed_len_per_uid;
+ }
+ }
+
+ EM_DEBUG_LOG("imap_response buflen is [%d]", imap_response->buflen);
+ ret = true;
+
+FINISH_OFF:
+
+ if (error)
+ *error = err;
+
+ if (true != ret)
+ EM_DEBUG_EXCEPTION("Failed download for the uid list %s", command);
+
+ if(reply_from_server) {
+ EM_SAFE_FREE(reply_from_server->key);
+ EM_SAFE_FREE(reply_from_server->line);
+ EM_SAFE_FREE(reply_from_server->tag);
+ EM_SAFE_FREE(reply_from_server->text);
+ EM_SAFE_FREE(reply_from_server);
+ }
+
+ EM_SAFE_FREE(bufsendforparse);
+ EM_SAFE_FREE(plain_text_file_name_from_content_info);
+ EM_SAFE_FREE(html_text_file_name_from_content_info);
+ EM_SAFE_FREE(plain_charset_from_content_info);
+
+ if (cnt_info)
+ em_core_mime_free_content_info(cnt_info);
+
+ if (body)
+ mail_free_body(&body);
+
+ if (imap_response)
+ EM_SAFE_FREE(imap_response->buffer);
+ EM_SAFE_FREE(imap_response);
+
+ if (mail)
+ em_storage_free_mail(&mail, 1, NULL);
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+EXPORT_API int em_core_bulk_partial_mailbody_download_for_pop3(MAILSTREAM *stream, emf_event_partial_body_thd *pbd_event, int item_count, int *error)
+{
+ EM_DEBUG_FUNC_BEGIN("stream [%p], pbd_event [%p], item_count [%d], error [%p]", stream, pbd_event, item_count, error);
+ int ret = false, err = EMF_ERROR_NONE;
+ int i;
+
+ if (!stream || !pbd_event) {
+ EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ for (i = 0; i < item_count; i++) {
+ EM_DEBUG_LOG("pbd_event[%d].account_id [%d], mail_id [%d], server_mail_id [%d], activity_id [%d]", \
+ i, pbd_event[i].account_id, pbd_event[i].mail_id, pbd_event[i].server_mail_id, pbd_event[i].activity_id);
+
+ if (!em_core_mail_download_body_multi_sections_bulk(stream, pbd_event[i].account_id, pbd_event[i].mail_id, false, false, PARTIAL_BODY_SIZE_IN_BYTES, 0 , &err)){
+ EM_DEBUG_EXCEPTION("em_core_mail_download_body_multi_sections_bulk failed");
+ goto FINISH_OFF;
+ }
+
+ if (false == em_core_delete_pbd_activity(pbd_event[i].account_id, pbd_event[i].mail_id, pbd_event[i].activity_id, &err)){
+ EM_DEBUG_EXCEPTION("em_core_delete_pbd_activity failed [%d]", err);
+ goto FINISH_OFF;
+ }
+ }
+
+ ret = true;
+
+FINISH_OFF:
+ if (error)
+ *error = err;
+
+ EM_DEBUG_FUNC_END("ret [%d] err [%d]", ret, err);
+ return ret;
+}
+
+
+
+EXPORT_API int em_core_bulk_partial_mailbody_download(MAILSTREAM *stream, emf_event_partial_body_thd *pbd_event, int item_count, int *error)
+{
+ EM_DEBUG_FUNC_BEGIN("stream [%p], pbd_event [%p], item_count [%d], error [%p]", stream, pbd_event, item_count, error);
+ int ret = false, err = EMF_ERROR_NONE;
+ emf_account_t *pbd_account = NULL;
+
+ if (!stream || !pbd_event) {
+ EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ pbd_account = em_core_get_account_reference(pbd_event[0].account_id);
+
+ if (pbd_account == NULL){
+ EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_ACCOUNT");
+ err = EMF_ERROR_INVALID_ACCOUNT;
+ goto FINISH_OFF;
+ }
+
+ switch (pbd_account->receiving_server_type){
+ case EMF_SERVER_TYPE_IMAP4:
+ ret = em_core_bulk_partial_mailbody_download_for_imap(stream, pbd_event, item_count, &err);
+ break;
+ case EMF_SERVER_TYPE_POP3:
+ ret = em_core_bulk_partial_mailbody_download_for_pop3(stream, pbd_event, item_count, &err);
+ break;
+ default:
+ err = EMF_ERROR_NOT_SUPPORTED;
+ ret = false;
+ break;
+ }
+
+ ret = true;
+FINISH_OFF:
+ if (error)
+ *error = err;
+
+ EM_DEBUG_FUNC_END("ret [%d] err [%d]", ret, err);
+ return ret;
+}
+
+
+static emf_partial_buffer *em_core_get_response_from_server (NETSTREAM *nstream, char *tag, IMAPPARSEDREPLY **reply)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ if (!nstream || !tag || !reply){
+ EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
+ return NIL;
+ }
+
+ emf_partial_buffer *retPartialBuffer = NULL;
+ IMAPPARSEDREPLY *ret_reply = NULL;
+ char *pline = NULL;
+ int linelen = 0;
+ int bytes_copied = 0;
+ int allocated_buffer_size = (BULK_PARTIAL_BODY_DOWNLOAD_COUNT + 1) * PARTIAL_BODY_SIZE_IN_BYTES ;
+
+ retPartialBuffer = (emf_partial_buffer *)em_core_malloc(sizeof(emf_partial_buffer));
+
+ if (NULL == retPartialBuffer){
+ EM_DEBUG_EXCEPTION("em_core_malloc failed");
+ return NIL;
+ }
+
+ retPartialBuffer->buffer = (char *)em_core_malloc(allocated_buffer_size);
+
+ if (NULL == retPartialBuffer->buffer){
+ EM_DEBUG_EXCEPTION("em_core_malloc failed");
+ EM_SAFE_FREE(retPartialBuffer);
+ return NIL;
+ }
+
+ while (nstream){
+ if (!(pline = net_getline(nstream))) {
+ EM_DEBUG_EXCEPTION("net_getline failed...");
+ EM_SAFE_FREE(retPartialBuffer->buffer);
+ EM_SAFE_FREE(retPartialBuffer);
+
+ return NIL;
+ }
+
+ linelen = strlen(pline);
+ memcpy(retPartialBuffer->buffer + bytes_copied, pline, linelen);
+ bytes_copied += linelen;
+ memcpy(retPartialBuffer->buffer + bytes_copied, CRLF_STRING, 2);
+ bytes_copied += 2;
+
+ if (0 == strncmp(pline, tag, strlen(tag))) {
+
+ ret_reply = em_core_malloc(sizeof(IMAPPARSEDREPLY));
+
+ if (!ret_reply){
+ EM_DEBUG_EXCEPTION("em_core_malloc failed");
+ return NIL;
+ }
+
+ if(reply)
+ *reply = ret_reply;
+
+ if (0 == strncmp(pline + strlen(tag) + 1, "OK", 2)) {
+ ret_reply->line = (unsigned char*)EM_SAFE_STRDUP(tag);
+ ret_reply->tag = (unsigned char*)EM_SAFE_STRDUP(tag);
+ ret_reply->key = (unsigned char*)EM_SAFE_STRDUP("OK");
+ ret_reply->text = (unsigned char*)EM_SAFE_STRDUP("Success");
+ EM_SAFE_FREE(pline);
+ break;
+ }
+ else {
+ EM_DEBUG_EXCEPTION("Tagged Response not OK. IMAP4 Response -> [%s]", pline);
+ ret_reply->line = (unsigned char*)EM_SAFE_STRDUP(tag);
+ ret_reply->tag = (unsigned char*)EM_SAFE_STRDUP(tag);
+ ret_reply->key = (unsigned char*)EM_SAFE_STRDUP("NO");
+ ret_reply->text = (unsigned char*)EM_SAFE_STRDUP("Fail");
+
+ EM_SAFE_FREE(pline);
+ EM_SAFE_FREE(retPartialBuffer->buffer);
+ EM_SAFE_FREE(retPartialBuffer);
+
+ return NIL;
+ }
+
+ EM_DEBUG_LOG("ret_reply->line [%s]", ret_reply->line);
+ EM_DEBUG_LOG("ret_reply->tag [%s]", ret_reply->tag);
+ EM_DEBUG_LOG("ret_reply->key [%s]", ret_reply->key);
+ EM_DEBUG_LOG("ret_reply->text [%s]", ret_reply->text);
+
+ }
+ EM_SAFE_FREE(pline);
+ }
+
+ retPartialBuffer->buflen = strlen(retPartialBuffer->buffer);
+
+ EM_DEBUG_FUNC_END("retPartialBuffer [%p]", retPartialBuffer);
+ return retPartialBuffer;
+}
+
+#endif /* __FEATURE_PARTIAL_BODY_DOWNLOAD__ */
+/* EOF */
diff --git a/email-core/em-core-mailbox.c b/email-core/em-core-mailbox.c
new file mode 100755
index 0000000..712b3be
--- /dev/null
+++ b/email-core/em-core-mailbox.c
@@ -0,0 +1,1168 @@
+/*
+* email-service
+*
+* Copyright (c) 2000 - 2011 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.
+*
+*/
+
+
+/******************************************************************************
+ * File : em-core-mailbox.c
+ * Desc : Local Mailbox Management
+ *
+ * Auth :
+ *
+ *****************************************************************************/
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+#include <sys/types.h>
+#include "emf-types.h"
+#include "emf-dbglog.h"
+#include "em-core-global.h"
+#include "em-core-utils.h"
+#include "em-core-mailbox.h"
+#include "em-core-event.h"
+#include "em-core-mesg.h"
+#include "em-core-imap-mailbox.h"
+#include "em-storage.h"
+#include "em-core-account.h"
+
+#ifdef __FEATURE_KEEP_CONNECTION__
+static void *g_receiving_thd_stream = NULL; /* Stores the recv thd stream for next time reuse */
+static int prev_acc_id_recv_thd = 0; /* Stores the account id for which recv thd stream is open */
+extern int recv_thread_run;
+
+static void *g_partial_body_thd_stream = NULL; /* Stores the pb thd stream for next time reuse */
+static int prev_acc_id_pb_thd = 0; /* Stores the account id for which pb thd stream is open */
+
+__thread emf_connection_info_t *g_connection_info_list = NULL;
+
+#ifdef __FEATURE_USE_PTHREAD__
+static pthread_mutex_t _close_stream_lock = PTHREAD_MUTEX_INITIALIZER; /* Mutex to protect closing stream */
+#else /* __FEATURE_USE_PTHREAD__ */
+static GMutex *_close_stream_lock = NULL; /* Mutex to protect closing stream */
+#endif /* __FEATURE_USE_PTHREAD__ */
+
+#endif /* __FEATURE_KEEP_CONNECTION__ */
+
+
+/* Binding IMAP mailbox with its function */
+static emf_mailbox_type_item_t g_mailbox_type[MAX_MAILBOX_TYPE] = {
+ {EMF_MAILBOX_TYPE_INBOX, "INBOX" },
+ /* Naver */
+ {EMF_MAILBOX_TYPE_INBOX, "Inbox" },
+ {EMF_MAILBOX_TYPE_SENTBOX, "Sent Messages"} ,
+ {EMF_MAILBOX_TYPE_SPAMBOX, "&wqTTOLpUx3zVaA-"} ,
+ {EMF_MAILBOX_TYPE_DRAFT, "Drafts"} ,
+ {EMF_MAILBOX_TYPE_TRASH, "Deleted Messages" } ,
+ /* Google English */
+ {EMF_MAILBOX_TYPE_SENTBOX, "[Gmail]/Sent Mail"} ,
+ {EMF_MAILBOX_TYPE_SPAMBOX, "[Gmail]/Spam"} ,
+ {EMF_MAILBOX_TYPE_DRAFT, "[Gmail]/Drafts"} ,
+ {EMF_MAILBOX_TYPE_TRASH, "[Gmail]/Trash" } ,
+ {EMF_MAILBOX_TYPE_ALL_EMAILS, "[Gmail]/All Mail" } ,
+ /* Google Korean */
+ {EMF_MAILBOX_TYPE_SENTBOX, "[Gmail]/&vPSwuNO4ycDVaA-"} ,
+ {EMF_MAILBOX_TYPE_SPAMBOX, "[Gmail]/&wqTTONVo-" },
+ {EMF_MAILBOX_TYPE_DRAFT, "[Gmail]/&x4TC3Lz0rQDVaA-"} ,
+ {EMF_MAILBOX_TYPE_TRASH, "[Gmail]/&1zTJwNG1-"} ,
+ {EMF_MAILBOX_TYPE_ALL_EMAILS, "[Gmail]/&yATMtLz0rQDVaA-" } ,
+ /* AOL */
+ {EMF_MAILBOX_TYPE_SENTBOX, "Sent"} ,
+ {EMF_MAILBOX_TYPE_SPAMBOX, "Spam" },
+ {EMF_MAILBOX_TYPE_DRAFT, "Drafts"} ,
+ {EMF_MAILBOX_TYPE_TRASH, "Trash"},
+ /* DAUM */
+ {EMF_MAILBOX_TYPE_SPAMBOX, "&wqTTONO4ycDVaA-"},
+ /* ETC */
+ {EMF_MAILBOX_TYPE_SENTBOX, "mail/sent-mail"},
+ {EMF_MAILBOX_TYPE_SPAMBOX, "mail/spam-mail" },
+ {EMF_MAILBOX_TYPE_DRAFT, "mail/saved-drafts"} ,
+ {EMF_MAILBOX_TYPE_TRASH, "mail/mail-trash"},
+};
+
+#ifdef __FEATURE_KEEP_CONNECTION__
+emf_connection_info_t* em_core_get_connection_info_by_account_id(int account_id)
+{
+ EM_DEBUG_FUNC_BEGIN("account_id [%d]", account_id);
+ emf_connection_info_t *connection_info = g_connection_info_list;
+
+ while(connection_info) {
+ if(connection_info->account_id == account_id)
+ break;
+ connection_info = connection_info->next;
+ }
+
+ EM_DEBUG_FUNC_END("connection_info [%p]", connection_info);
+ return connection_info;
+}
+
+int em_core_append_connection_info(emf_connection_info_t *new_connection_info)
+{
+ EM_DEBUG_FUNC_BEGIN("new_connection_info [%p]", new_connection_info);
+ emf_connection_info_t *connection_info = g_connection_info_list;
+
+ if(!new_connection_info) {
+ EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
+ return EMF_ERROR_INVALID_PARAM;
+ }
+
+ if(em_core_get_connection_info_by_account_id(new_connection_info->account_id)) {
+ EM_DEBUG_EXCEPTION("EMF_ERROR_ALREADY_EXISTS");
+ return EMF_ERROR_ALREADY_EXISTS;
+ }
+
+ if(connection_info) {
+ while(connection_info) {
+ if(connection_info->next == NULL) {
+ connection_info->next = new_connection_info;
+ new_connection_info->next = NULL;
+ }
+ connection_info = connection_info->next;
+ }
+ }
+ else {
+ new_connection_info->next = NULL;
+ g_connection_info_list = new_connection_info;
+ }
+
+ EM_DEBUG_FUNC_END("EMF_ERROR_NONE");
+ return EMF_ERROR_NONE;
+}
+
+EXPORT_API int em_core_remove_connection_info(int account_id)
+{
+ EM_DEBUG_FUNC_BEGIN("account_id [%d]", account_id);
+ emf_connection_info_t *connection_info = g_connection_info_list, *prev_connection_info = NULL;
+
+ while(connection_info) {
+ if(connection_info->account_id == account_id) {
+ if(prev_connection_info) {
+ prev_connection_info->next = connection_info->next;
+ }
+ else {
+ g_connection_info_list = connection_info->next;
+ }
+ EM_SAFE_FREE(connection_info);
+ break;
+ }
+ prev_connection_info = connection_info;
+ connection_info = connection_info->next;
+ }
+
+ EM_DEBUG_FUNC_END("");
+ return EMF_ERROR_NONE;
+}
+
+#endif /* __FEATURE_KEEP_CONNECTION__ */
+
+
+/* description
+ * get local mailbox list
+ */
+EXPORT_API int em_core_mailbox_get_list(int account_id, emf_mailbox_t **mailbox_list, int *p_count, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("account_id[%d], mailbox_list[%p], p_count[%p], err_code[%p]", account_id, mailbox_list, p_count, err_code);
+
+ if (account_id <= 0 || !mailbox_list || !p_count) {
+ EM_DEBUG_EXCEPTION("PARAM Failed account_id[%d], mailbox_list[%p], p_count[%p]", account_id, mailbox_list, p_count);
+ if (err_code != NULL)
+ *err_code = EMF_ERROR_INVALID_PARAM;
+ return false;
+ }
+
+ int ret = false;
+ int error = EMF_ERROR_NONE;
+ emf_mailbox_tbl_t *local_mailbox_list = NULL;
+ emf_account_t *ref_account = NULL;
+ int i, count = 512;
+
+ /* get mailbox list from mailbox table */
+
+ if (!(ref_account = em_core_get_account_reference(account_id))) {
+ EM_DEBUG_EXCEPTION(" em_core_get_account_reference failed - %d", account_id);
+ error = EMF_ERROR_INVALID_ACCOUNT;
+ goto FINISH_OFF;
+ }
+
+ if (!em_storage_get_mailbox(ref_account->account_id, EMF_MAILBOX_ALL, EMAIL_MAILBOX_SORT_BY_NAME_ASC, &count, &local_mailbox_list, true, &error)) {
+ EM_DEBUG_EXCEPTION(" em_storage_get_mailbox failed - %d", error);
+ error = em_storage_get_emf_error_from_em_storage_error(error);
+ goto FINISH_OFF;
+ }
+
+ if (count > 0) {
+ if (!(*mailbox_list = em_core_malloc(sizeof(emf_mailbox_t) * count))) {
+ EM_DEBUG_EXCEPTION(" mailloc failed...");
+ error = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ memset(*mailbox_list, 0x00, (sizeof(emf_mailbox_t) * count));
+
+ for (i = 0; i < count; i++) {
+ (*mailbox_list)[i].mailbox_id = local_mailbox_list[i].mailbox_id;
+ (*mailbox_list)[i].account_id = account_id;
+ (*mailbox_list)[i].name = local_mailbox_list[i].mailbox_name; local_mailbox_list[i].mailbox_name = NULL;
+ (*mailbox_list)[i].alias = local_mailbox_list[i].alias; local_mailbox_list[i].alias = NULL;
+ (*mailbox_list)[i].local = local_mailbox_list[i].local_yn;
+ (*mailbox_list)[i].mailbox_type = local_mailbox_list[i].mailbox_type;
+ (*mailbox_list)[i].synchronous = local_mailbox_list[i].sync_with_server_yn;
+ (*mailbox_list)[i].unread_count = local_mailbox_list[i].unread_count;
+ (*mailbox_list)[i].total_mail_count_on_local = local_mailbox_list[i].total_mail_count_on_local;
+ (*mailbox_list)[i].total_mail_count_on_server = local_mailbox_list[i].total_mail_count_on_server;
+ (*mailbox_list)[i].has_archived_mails = local_mailbox_list[i].has_archived_mails;
+ (*mailbox_list)[i].mail_slot_size = local_mailbox_list[i].mail_slot_size;
+ }
+ }
+ else
+ mailbox_list = NULL;
+
+ * p_count = count;
+
+ ret = true;
+
+FINISH_OFF:
+ if (local_mailbox_list != NULL)
+ em_storage_free_mailbox(&local_mailbox_list, count, NULL);
+
+ if (err_code != NULL)
+ *err_code = error;
+
+ EM_DEBUG_FUNC_END();
+ return ret;
+}
+
+/* description
+ * get imap sync mailbox list
+ */
+int em_core_mailbox_get_list_to_be_sync(int account_id, emf_mailbox_t **mailbox_list, int *p_count, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("account_id[%d], mailbox_list[%p], p_count[%p], err_code[%p]", account_id, mailbox_list, p_count, err_code);
+
+ if (account_id <= 0 || !mailbox_list || !p_count) {
+ EM_DEBUG_EXCEPTION(" account_id[%d], mailbox_list[%p], p_count[%p]", account_id, mailbox_list, p_count);
+ if (err_code != NULL)
+ *err_code = EMF_ERROR_INVALID_PARAM;
+ return false;
+ }
+
+ int ret = false;
+ int error = EMF_ERROR_NONE;
+ emf_mailbox_t *tmp_mailbox_list = NULL;
+ emf_mailbox_tbl_t *mailbox_tbl_list = NULL;
+ emf_account_t *ref_account = NULL;
+ int i, count = 512;
+
+ /* get mailbox list from mailbox table */
+ if (!(ref_account = em_core_get_account_reference(account_id))) {
+ EM_DEBUG_EXCEPTION("em_core_get_account_reference failed - %d", account_id);
+ error = EMF_ERROR_INVALID_ACCOUNT;
+ goto FINISH_OFF;
+ }
+
+ if (!em_storage_get_mailbox(ref_account->account_id, 0, EMAIL_MAILBOX_SORT_BY_TYPE_ASC, &count, &mailbox_tbl_list, true, &error)) {
+ EM_DEBUG_EXCEPTION("em_storage_get_mailbox failed - %d", error);
+ error = em_storage_get_emf_error_from_em_storage_error(error);
+ goto FINISH_OFF;
+ }
+
+ if (count > 0) {
+ if (!(tmp_mailbox_list = em_core_malloc(sizeof(emf_mailbox_t) * count))) {
+ EM_DEBUG_EXCEPTION("malloc failed...");
+ error = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ memset(tmp_mailbox_list, 0x00, (sizeof(emf_mailbox_t) * count));
+
+ for (i = 0; i < count; i++) {
+ tmp_mailbox_list[i].mailbox_id = mailbox_tbl_list[i].mailbox_id;
+ tmp_mailbox_list[i].account_id = account_id;
+ tmp_mailbox_list[i].name = mailbox_tbl_list[i].mailbox_name; mailbox_tbl_list[i].mailbox_name = NULL;
+ tmp_mailbox_list[i].mailbox_type = mailbox_tbl_list[i].mailbox_type;
+ tmp_mailbox_list[i].alias = mailbox_tbl_list[i].alias; mailbox_tbl_list[i].alias = NULL;
+ tmp_mailbox_list[i].local = mailbox_tbl_list[i].local_yn;
+ tmp_mailbox_list[i].synchronous = mailbox_tbl_list[i].sync_with_server_yn;
+ tmp_mailbox_list[i].unread_count = mailbox_tbl_list[i].unread_count;
+ tmp_mailbox_list[i].total_mail_count_on_local = mailbox_tbl_list[i].total_mail_count_on_local;
+ tmp_mailbox_list[i].total_mail_count_on_server = mailbox_tbl_list[i].total_mail_count_on_server;
+ tmp_mailbox_list[i].mail_slot_size = mailbox_tbl_list[i].mail_slot_size;
+ }
+ }
+ else
+ tmp_mailbox_list = NULL;
+ *p_count = count;
+ ret = true;
+
+FINISH_OFF:
+
+ *mailbox_list = tmp_mailbox_list;
+
+
+ if (mailbox_tbl_list != NULL)
+ em_storage_free_mailbox(&mailbox_tbl_list, count, NULL);
+
+ if (err_code != NULL)
+ *err_code = error;
+ EM_DEBUG_FUNC_END("error [%d]", error);
+ return ret;
+}
+
+EXPORT_API int em_core_mailbox_get_mail_count(emf_mailbox_t *mailbox, int *total, int *unseen, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("mailbox[%p], total[%p], unseen[%p], err_code[%p]", mailbox, total, unseen, err_code);
+
+ int ret = false;
+ int err = EMF_ERROR_NONE;
+
+ if (!mailbox) {
+ EM_DEBUG_EXCEPTION(" mailbox[%p], total[%p], unseen[%p]", mailbox, total, unseen);
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ if (!em_storage_get_mail_count(mailbox->account_id, mailbox->name, total, unseen, true, &err)) {
+ EM_DEBUG_EXCEPTION(" em_storage_get_mail_count failed - %d", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+
+
+ ret = true;
+
+FINISH_OFF:
+ if (err_code != NULL)
+ *err_code = err;
+
+ return ret;
+}
+
+EXPORT_API int em_core_mailbox_create(emf_mailbox_t *new_mailbox, int on_server, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("new_mailbox[%p], err_code[%p]", new_mailbox, err_code);
+ int ret = false;
+ int err = EMF_ERROR_NONE;
+ emf_mailbox_tbl_t local_mailbox;
+
+ if (new_mailbox == NULL || new_mailbox->name == NULL) {
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ if (on_server) {
+ /* Create a mailbox from Sever */
+ if (!em_core_mailbox_create_imap_mailbox(new_mailbox, &err)) {
+ EM_DEBUG_EXCEPTION(">>>>> mailbox Creation in Server FAILED >>> ");
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+ else
+ EM_DEBUG_LOG(">>>>> mailbox Creation in Server SUCCESS >>> ");
+ }
+
+ memset(&local_mailbox, 0x00, sizeof(emf_mailbox_tbl_t));
+ EM_DEBUG_LOG("box name[%s] local yn[%d] mailbox_type[%d]", new_mailbox->name, local_mailbox.local_yn, new_mailbox->mailbox_type);
+
+ /* add local mailbox into local mailbox table */
+ local_mailbox.mailbox_id = new_mailbox->mailbox_id;
+ local_mailbox.account_id = new_mailbox->account_id;
+ local_mailbox.local_yn = new_mailbox->local;
+ local_mailbox.mailbox_name = new_mailbox->name;
+ local_mailbox.alias = new_mailbox->alias;
+ local_mailbox.sync_with_server_yn = new_mailbox->synchronous;
+ local_mailbox.mailbox_type = new_mailbox->mailbox_type;
+ local_mailbox.unread_count = 0;
+ local_mailbox.total_mail_count_on_local = 0;
+ local_mailbox.total_mail_count_on_server = 0;
+ em_core_mailbox_get_default_mail_slot_count(&local_mailbox.mail_slot_size, NULL);
+
+ if (strncmp(new_mailbox->name, EMF_INBOX_NAME, strlen(EMF_INBOX_NAME)) == 0 ||
+ strncmp(new_mailbox->name, EMF_DRAFTBOX_NAME, strlen(EMF_DRAFTBOX_NAME)) == 0 ||
+ strncmp(new_mailbox->name, EMF_OUTBOX_NAME, strlen(EMF_OUTBOX_NAME)) == 0 ||
+ strncmp(new_mailbox->name, EMF_SENTBOX_NAME, strlen(EMF_SENTBOX_NAME)) == 0)
+ local_mailbox.modifiable_yn = 0; /* can be deleted/modified */
+ else
+ local_mailbox.modifiable_yn = 1;
+
+
+ if (!em_storage_add_mailbox(&local_mailbox, true, &err)) {
+ EM_DEBUG_EXCEPTION(" em_storage_add_mailbox failed - %d", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+ ret = true;
+
+FINISH_OFF:
+ if (err_code)
+ *err_code = err;
+
+ return ret;
+}
+
+EXPORT_API int em_core_mailbox_delete(emf_mailbox_t *mailbox, int on_server, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("mailbox[%p], err_code[%p]", mailbox, err_code);
+
+ int ret = false;
+ int err = EMF_ERROR_NONE;
+
+ if (mailbox == NULL) {
+ EM_DEBUG_EXCEPTION(" mailbox[%p]", mailbox);
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ if (!em_core_mail_delete_all(mailbox, on_server, &err)) {
+ EM_DEBUG_EXCEPTION(" em_core_mail_delete_all failed - %d", err);
+ goto FINISH_OFF;
+ }
+
+ if (on_server) {
+ EM_DEBUG_LOG(">> Delete the mailbox in Sever >>> ");
+ if (!em_core_mailbox_delete_imap_mailbox(mailbox, &err))
+ EM_DEBUG_EXCEPTION(">>> Delete the mailbox in Server : FAILED >>> ");
+ else
+ EM_DEBUG_LOG(">>> Delete the mailbox in Server : SUCCESS >>> ");
+ }
+
+ if (!em_storage_delete_mailbox(mailbox->account_id, -1, mailbox->name, true, &err)) {
+ EM_DEBUG_EXCEPTION(" em_storage_delete_mailbox failed - %d", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+
+ ret = true;
+
+FINISH_OFF:
+ if (err_code != NULL)
+ *err_code = err;
+
+ return ret;
+}
+
+EXPORT_API int em_core_mailbox_delete_all(emf_mailbox_t *mailbox, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ EM_DEBUG_LOG(" mailbox[%p], err_code[%p]", mailbox, err_code);
+
+ int ret = false;
+ int err = EMF_ERROR_NONE;
+
+ if (mailbox == NULL) {
+ EM_DEBUG_EXCEPTION(" mailbox[%p]", mailbox);
+
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ if (!em_core_mail_delete_all(mailbox, 0, /*NULL, */ &err)) {
+ EM_DEBUG_EXCEPTION(" em_core_mail_delete_all failed - %d", err);
+
+ goto FINISH_OFF;
+ }
+
+ if (!em_storage_delete_mailbox(mailbox->account_id, -1, mailbox->name, true, &err)) {
+ EM_DEBUG_EXCEPTION(" em_storage_delete_mailbox failed - %d", err);
+
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+
+ ret = true;
+
+FINISH_OFF:
+ if (err_code != NULL)
+ *err_code = err;
+
+ return ret;
+}
+
+EXPORT_API int em_core_mailbox_update(emf_mailbox_t *old_mailbox, emf_mailbox_t *new_mailbox, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("old_mailbox[%p], new_mailbox[%p], err_code[%p]", old_mailbox, new_mailbox, err_code);
+
+ int ret = false;
+ int err = EMF_ERROR_NONE;
+
+ if (old_mailbox == NULL || new_mailbox == NULL) {
+ EM_DEBUG_EXCEPTION("old_mailbox[%p], new_mailbox[%p]", old_mailbox, new_mailbox);
+
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ emf_mailbox_tbl_t new_mailbox_tbl;
+ memset(&new_mailbox_tbl, 0x00, sizeof(emf_mailbox_tbl_t));
+
+ /* Support only updating mailbox_type */
+ new_mailbox_tbl.mailbox_type = new_mailbox->mailbox_type;
+
+ if (old_mailbox->mailbox_type != new_mailbox_tbl.mailbox_type) {
+ if (!em_storage_update_mailbox_type(old_mailbox->account_id, -1, old_mailbox->name, &new_mailbox_tbl, true, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_update_mailbox failed - %d", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+ }
+
+ new_mailbox_tbl.mailbox_id = old_mailbox->mailbox_id;
+ new_mailbox_tbl.account_id = old_mailbox->account_id;
+ new_mailbox_tbl.mailbox_name = new_mailbox->name;
+ new_mailbox_tbl.mailbox_type = new_mailbox->mailbox_type;
+ new_mailbox_tbl.alias = new_mailbox->alias;
+ new_mailbox_tbl.sync_with_server_yn = new_mailbox->synchronous;
+ new_mailbox_tbl.mail_slot_size = new_mailbox->mail_slot_size;
+ new_mailbox_tbl.total_mail_count_on_server = new_mailbox->total_mail_count_on_server;
+
+ if (!em_storage_update_mailbox(old_mailbox->account_id, -1, old_mailbox->name, &new_mailbox_tbl, true, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_update_mailbox failed - %d", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+
+ if (EM_SAFE_STRCMP(old_mailbox->name, new_mailbox_tbl.mailbox_name) != 0) {
+ if (!em_storage_rename_mailbox(old_mailbox->account_id, old_mailbox->name, new_mailbox_tbl.mailbox_name, true, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_rename_mailbox failed - %d", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+ }
+
+ ret = true;
+
+FINISH_OFF:
+ if (err_code)
+ *err_code = err;
+
+ return ret;
+}
+
+extern int try_auth;
+extern int try_auth_smtp;
+
+extern long smtp_send(SENDSTREAM *stream, char *command, char *args);
+extern long smtp_rcpt(SENDSTREAM *stream, ADDRESS *adr, long* error);
+
+
+EXPORT_API int em_core_mailbox_open_with_account_info(emf_account_t *account, char *mailbox, void **result_stream, int *err_code)
+{
+ EM_PROFILE_BEGIN(emCoreMailboxOpen);
+ EM_DEBUG_FUNC_BEGIN("account[%p], mailbox[%p], mail_stream[%p], err_code[%p]", account, mailbox, result_stream, err_code);
+
+ int ret = false;
+ int error = EMF_ERROR_NONE;
+ emf_session_t *session = NULL;
+ char *mbox_path = NULL;
+ void *reusable_stream = NULL;
+ int is_connection_for = _SERVICE_THREAD_TYPE_NONE;
+
+ if (account == NULL) {
+ EM_DEBUG_EXCEPTION("Invalid Parameter.");
+ error = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ if (!em_core_get_current_session(&session)) {
+ EM_DEBUG_EXCEPTION("em_core_get_current_session failed...");
+ error = EMF_ERROR_SESSION_NOT_FOUND;
+ goto FINISH_OFF;
+ }
+
+ if (mailbox == NULL || (mailbox && strcmp(mailbox, ENCODED_PATH_SMTP) != 0))
+ is_connection_for = _SERVICE_THREAD_TYPE_RECEIVING;
+ else
+ is_connection_for = _SERVICE_THREAD_TYPE_SENDING;
+
+#ifdef __FEATURE_KEEP_CONNECTION__
+ emf_connection_info_t *connection_info = em_core_get_connection_info_by_account_id(account->account_id);
+
+ if(connection_info) {
+ if (is_connection_for == _SERVICE_THREAD_TYPE_RECEIVING) {
+ if(connection_info->receiving_server_stream_status == EMF_STREAM_STATUS_CONNECTED)
+ reusable_stream = connection_info->receiving_server_stream;
+ }
+ else {
+ if(connection_info->sending_server_stream_status == EMF_STREAM_STATUS_CONNECTED)
+ reusable_stream = connection_info->sending_server_stream;
+ }
+ }
+
+ if (reusable_stream != NULL)
+ EM_DEBUG_LOG("Stream reuse desired");
+#else
+ reusable_stream = *result_stream;
+#endif
+
+ session->error = EMF_ERROR_NONE;
+ em_core_set_network_error(EMF_ERROR_NONE); /* set current network error as EMF_ERROR_NONE before network operation */
+
+ if (is_connection_for == _SERVICE_THREAD_TYPE_RECEIVING) {
+ /* open pop3/imap server */
+ MAILSTREAM *mail_stream = NULL;
+
+ if (!em_core_get_long_encoded_path_with_account_info(account, mailbox, '/', &mbox_path, &error)) {
+ EM_DEBUG_EXCEPTION("em_core_get_long_encoded_path failed - %d", error);
+ session->error = error;
+ goto FINISH_OFF;
+ }
+
+ EM_DEBUG_LOG("open mail connection to mbox_path [%s]", mbox_path);
+
+ try_auth = 0; /* ref_account->receiving_auth ? 1 : 0 */
+ session->auth = 0; /* ref_account->receiving_auth ? 1 : 0 */
+
+ if (!(mail_stream = mail_open(reusable_stream, mbox_path, IMAP_2004_LOG))) {
+ EM_DEBUG_EXCEPTION("mail_open failed. session->error[%d], session->network[%d]", session->error, session->network);
+
+ if (session->network != EMF_ERROR_NONE)
+ session->error = session->network;
+ if ((session->error == EMF_ERROR_UNKNOWN) || (session->error == EMF_ERROR_NONE))
+ session->error = EMF_ERROR_CONNECTION_FAILURE;
+
+ error = session->error;
+
+#ifdef __FEATURE_KEEP_CONNECTION__
+ /* Since mail_open failed Reset the global stream pointer as it is a dangling pointer now */
+#endif /* __FEATURE_KEEP_CONNECTION__ */
+ goto FINISH_OFF;
+ }
+ *result_stream = mail_stream;
+ }
+ else {
+ /* open smtp server */
+ SENDSTREAM *send_stream = NULL;
+ char *host_list[2] = {NULL, NULL};
+
+#ifdef __FEATURE_KEEP_CONNECTION__
+ if (reusable_stream != NULL) {
+ int send_ret = 0;
+ /* Check whether connection is avaiable */
+ send_stream = reusable_stream;
+ /*
+ send_ret = smtp_send(send_stream, "RSET", 0);
+
+ if (send_ret != SMTP_RESPONSE_OK) {
+ EM_DEBUG_EXCEPTION("[SMTP] RSET --> [%s]", send_stream->reply);
+ send_stream = NULL;
+ }
+ */
+ }
+#endif
+ if(!send_stream) {
+ if (!em_core_get_long_encoded_path_with_account_info(account, mailbox, 0, &mbox_path, &error)) {
+ EM_DEBUG_EXCEPTION(" em_core_get_long_encoded_path failed - %d", error);
+ session->error = error;
+ goto FINISH_OFF;
+ }
+
+ EM_DEBUG_LOG("open SMTP connection to mbox_path [%s]", mbox_path);
+
+ try_auth_smtp = account->sending_auth ? 1 : 0;
+ session->auth = account->sending_auth ? 1 : 0;
+
+ host_list[0] = mbox_path;
+
+ if (!(send_stream = smtp_open(host_list, 1))) {
+ EM_DEBUG_EXCEPTION("smtp_open failed... : current sending_security[%d] session->error[%d] session->network[%d]", account->sending_security, session->error, session->network);
+ if (session->network != EMF_ERROR_NONE)
+ session->error = session->network;
+ if ((session->error == EMF_ERROR_UNKNOWN) || (session->error == EMF_ERROR_NONE))
+ session->error = EMF_ERROR_CONNECTION_FAILURE;
+
+ error = session->error;
+ goto FINISH_OFF;
+ }
+ }
+ *result_stream = send_stream;
+ }
+
+ ret = true;
+
+FINISH_OFF:
+
+#ifdef __FEATURE_KEEP_CONNECTION__
+ if (ret == true) {
+ if(!connection_info) {
+ connection_info = em_core_malloc(sizeof(emf_connection_info_t));
+ connection_info->account_id = account->account_id;
+ if(!connection_info)
+ EM_DEBUG_EXCEPTION("em_core_malloc for connection_info failed.");
+ else
+ em_core_append_connection_info(connection_info);
+ }
+
+ if(connection_info) {
+ /* connection_info->account_id = account->account_id; */
+ if (is_connection_for == _SERVICE_THREAD_TYPE_RECEIVING) {
+ connection_info->receiving_server_stream = *result_stream;
+ connection_info->receiving_server_stream_status = EMF_STREAM_STATUS_CONNECTED;
+ }
+ else {
+ connection_info->sending_server_stream = *result_stream;
+ connection_info->sending_server_stream_status = EMF_STREAM_STATUS_CONNECTED;
+ }
+ }
+ }
+#endif
+
+ EM_SAFE_FREE(mbox_path);
+ if (err_code != NULL)
+ *err_code = error;
+ EM_PROFILE_END(emCoreMailboxOpen);
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+#ifdef __FEATURE_KEEP_CONNECTION__
+
+/*h.gahlaut@samsung.com : 20-oct-2010*/
+/*Precaution : When Reuse Stream feature is enabled then stream should only be closed using em_core_mailbox_close from email-service code.
+mail_close should not be used directly from anywhere in code.
+em_core_mailbox_close uses mail_close inside it.
+
+mail_close is only used in em_core_mailbox_open and em_core_reset_streams as an exception to above rule*/
+
+EXPORT_API int em_core_mailbox_open(int account_id, char *mailbox, void **mail_stream, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("account_id[%d], mailbox[%p], mail_stream[%p], err_code[%p]", account_id, mailbox, mail_stream, err_code);
+
+ int ret = false;
+ int error = EMF_ERROR_NONE;
+ emf_account_t *ref_account = em_core_get_account_reference(account_id);
+
+ if (!ref_account) {
+ EM_DEBUG_EXCEPTION("em_core_get_account_reference failed - account id[%d]", account_id);
+ error = EMF_ERROR_INVALID_ACCOUNT;
+ goto FINISH_OFF;
+ }
+
+ ret = em_core_mailbox_open_with_account_info(ref_account, mailbox, mail_stream, &error);
+
+FINISH_OFF:
+ if (err_code)
+ *err_code = error;
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+EXPORT_API
+void em_core_close_receiving_stream()
+{
+ EM_DEBUG_FUNC_BEGIN("recv_thread_run [%d]", recv_thread_run);
+ if (!recv_thread_run) {
+ ENTER_CRITICAL_SECTION(_close_stream_lock);
+ mail_close(g_receiving_thd_stream);
+ g_receiving_thd_stream = NULL;
+ prev_acc_id_recv_thd = 0;
+ LEAVE_CRITICAL_SECTION(_close_stream_lock);
+ }
+ EM_DEBUG_FUNC_END();
+}
+
+EXPORT_API
+void em_core_close_partial_body_stream()
+{
+ EM_DEBUG_FUNC_BEGIN();
+ if (false == em_core_get_pbd_thd_state()) {
+ EM_DEBUG_LOG("em_core_get_pbd_thd_state returned false");
+ mail_close(g_partial_body_thd_stream);
+ g_partial_body_thd_stream = NULL;
+ prev_acc_id_pb_thd = 0;
+ }
+ EM_DEBUG_FUNC_END();
+}
+
+/* h.gahlaut@samsung.com : 21-10-2010 -
+em_core_reset_stream() function is used to reset globally stored partial body thread and receiving thread streams
+on account deletion and pdp deactivation */
+
+EXPORT_API
+void em_core_reset_streams()
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ em_core_close_receiving_stream();
+ em_core_close_partial_body_stream();
+
+ EM_DEBUG_FUNC_END();
+ return;
+}
+
+#else /* __FEATURE_KEEP_CONNECTION__ */
+
+EXPORT_API int em_core_mailbox_open(int account_id, char *mailbox, void **mail_stream, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("account_id[%d], mailbox[%p], mail_stream[%p], err_code[%p]", account_id, mailbox, mail_stream, err_code);
+
+ int ret = false;
+ int error = EMF_ERROR_NONE;
+ emf_account_t *ref_account = em_core_get_account_reference(account_id);
+
+ if (!ref_account) {
+ EM_DEBUG_EXCEPTION("em_core_get_account_reference failed - account id[%d]", account_id);
+ error = EMF_ERROR_INVALID_ACCOUNT;
+ goto FINISH_OFF;
+ }
+
+ ret = em_core_mailbox_open_with_account_info(ref_account, mailbox, mail_stream, &error);
+
+FINISH_OFF:
+ if (err_code)
+ *err_code = error;
+
+ return ret;
+}
+#endif /* __FEATURE_KEEP_CONNECTION__ */
+
+EXPORT_API int em_core_mailbox_close(int account_id, void *mail_stream)
+{
+ EM_DEBUG_FUNC_BEGIN("account_id[%d], mail_stream[%p]", account_id, mail_stream);
+
+ if (!mail_stream) {
+ EM_DEBUG_EXCEPTION("Invalid parameter");
+ return false; /* TODO : confirm me */
+ }
+
+#ifdef __FEATURE_KEEP_CONNECTION__
+ thread_t thread_id = THREAD_SELF();
+
+ if (thread_id == (thread_t)em_core_get_receiving_thd_id()) {
+ /* Receiving thread - Dont' Free Reuse feature enabled */
+ }
+ else if (thread_id == (thread_t)em_core_get_partial_body_thd_id()) {
+ /* Partial Body Download thread - Dont' Free Reuse feature enabled */
+ }
+ else {
+ /* Some other thread so free stream */
+ if (g_receiving_thd_stream != mail_stream && g_partial_body_thd_stream != mail_stream)
+ mail_close((MAILSTREAM *)mail_stream);
+ }
+#else
+ mail_close((MAILSTREAM *)mail_stream);
+#endif /* __FEATURE_KEEP_CONNECTION__ */
+ EM_DEBUG_FUNC_END();
+ return true;
+}
+
+EXPORT_API int em_core_mailbox_free(emf_mailbox_t **mailbox_list, int count, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("mailbox_list[%p], count[%d], err_code[%p]", mailbox_list, count, err_code);
+
+ /* default variable */
+ int ret = false;
+ int err = EMF_ERROR_NONE;
+
+ if (count > 0) {
+ if (!mailbox_list || !*mailbox_list) {
+ EM_DEBUG_EXCEPTION(" mailbox_list[%p], count[%d]", mailbox_list, count);
+
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ emf_mailbox_t *p = *mailbox_list;
+ int i;
+
+ /* EM_DEBUG_LOG("before loop"); */
+ for (i = 0; i < count; i++) {
+ /* EM_DEBUG_LOG("p[%d].name [%p]", i, p[i].name); */
+ /* EM_DEBUG_LOG("p[%d].alias [%p]", i, p[i].alias); */
+ EM_SAFE_FREE(p[i].name);
+ EM_SAFE_FREE(p[i].alias);
+ }
+ /* EM_DEBUG_LOG("p [%p]", p); */
+ free(p);
+ *mailbox_list = NULL;
+ }
+
+ ret = true;
+
+FINISH_OFF:
+ if (err_code)
+ *err_code = err;
+ EM_DEBUG_FUNC_END();
+ return ret;
+}
+
+EXPORT_API void
+em_core_bind_mailbox_type(emf_mailbox_t *mailbox_list)
+{
+ EM_DEBUG_FUNC_BEGIN("mailbox_list[%p]", mailbox_list);
+
+ int i = 0;
+ int bIsNotUserMailbox = false;
+ emf_mailbox_type_item_t *pMailboxType1 = NULL ;
+
+ for (i = 0 ; i < MAX_MAILBOX_TYPE ; i++) {
+ pMailboxType1 = g_mailbox_type + i;
+
+ if (pMailboxType1->mailbox_name) {
+ if (0 == strcmp(pMailboxType1->mailbox_name, mailbox_list->name)) {
+ mailbox_list->mailbox_type = pMailboxType1->mailbox_type;
+ EM_DEBUG_LOG("mailbox_list->mailbox_type[%d]", mailbox_list->mailbox_type);
+ bIsNotUserMailbox = true;
+ break;
+ }
+ }
+ }
+
+ if (false == bIsNotUserMailbox)
+ mailbox_list->mailbox_type = EMF_MAILBOX_TYPE_USER_DEFINED;
+
+ EM_DEBUG_FUNC_END();
+}
+
+EXPORT_API int em_core_send_mail_event(emf_mailbox_t *mailbox, int mail_id , int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ int ret = false;
+ int err = EMF_ERROR_NONE;
+ int handle;
+ emf_event_t event_data;
+
+ if (!mailbox || mailbox->account_id <= 0) {
+ EM_DEBUG_LOG(" mailbox[%p]", mailbox);
+
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+ memset(&event_data, 0x00, sizeof(emf_event_t));
+
+ event_data.type = EMF_EVENT_SEND_MAIL;
+ event_data.account_id = mailbox->account_id;
+ event_data.event_param_data_3 = EM_SAFE_STRDUP(mailbox->name);
+ event_data.event_param_data_4 = mail_id;
+ event_data.event_param_data_1 = NULL;
+
+ if (!em_core_insert_send_event(&event_data, &handle, &err)) {
+ EM_DEBUG_LOG(" em_core_insert_event failed - %d", err);
+ goto FINISH_OFF;
+ }
+ em_core_add_transaction_info(mail_id , handle , &err);
+
+ ret = true;
+FINISH_OFF:
+ if (err_code)
+ *err_code = err;
+
+ return ret;
+}
+
+EXPORT_API
+int em_core_partial_body_thd_local_activity_sync(int *is_event_inserted, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int activity_count = 0;
+ int ret = false;
+ int error = EMF_ERROR_NONE;
+
+ if (false == em_storage_get_pbd_activity_count(&activity_count, false, &error)) {
+ EM_DEBUG_LOG("em_storage_get_pbd_activity_count failed [%d]", error);
+ goto FINISH_OFF;
+ }
+
+ if (activity_count > 0) {
+
+ emf_event_partial_body_thd pbd_event;
+
+ /* Carefully initialise the event */
+ memset(&pbd_event, 0x00, sizeof(emf_event_partial_body_thd));
+
+ pbd_event.event_type = EMF_EVENT_LOCAL_ACTIVITY_SYNC_BULK_PBD;
+ pbd_event.activity_type = EMF_EVENT_LOCAL_ACTIVITY_SYNC_BULK_PBD;
+
+ if (false == em_core_insert_partial_body_thread_event(&pbd_event, &error)) {
+ EM_DEBUG_LOG(" em_core_insert_partial_body_thread_event failed [%d]", error);
+ goto FINISH_OFF;
+ }
+ else {
+ /*Not checking for NULL here because is_event_inserted is never NULL. */
+ *is_event_inserted = true;
+ }
+
+ }
+ else {
+ *is_event_inserted = false;
+ }
+
+ ret = true;
+
+ FINISH_OFF:
+
+ if (NULL != err_code) {
+ *err_code = error;
+ }
+
+ return ret;
+}
+
+EXPORT_API
+int em_core_get_mailbox_by_type(int account_id, emf_mailbox_type_e mailbox_type, emf_mailbox_t *result_mailbox, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("account_id [%d], result_mailbox [%p], err_code [%p]", account_id, result_mailbox, err_code);
+ int ret = false, err = EMF_ERROR_NONE;
+ emf_mailbox_tbl_t *mail_box_tbl_spam = NULL;
+
+ if (result_mailbox == NULL) {
+ EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ if (!em_storage_get_mailbox_by_mailbox_type(account_id, mailbox_type, &mail_box_tbl_spam, false, &err)) {
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ EM_DEBUG_LOG("em_storage_get_mailbox_by_mailbox_type failed - %d", err);
+ }
+ else {
+ if (mail_box_tbl_spam) {
+ result_mailbox->mailbox_type = mail_box_tbl_spam->mailbox_type;
+ result_mailbox->name = EM_SAFE_STRDUP(mail_box_tbl_spam->mailbox_name);
+ result_mailbox->account_id = mail_box_tbl_spam->account_id;
+ result_mailbox->mail_slot_size = mail_box_tbl_spam->mail_slot_size;
+ if (!em_storage_free_mailbox(&mail_box_tbl_spam, 1, &err))
+ EM_DEBUG_EXCEPTION(" em_storage_free_mailbox Failed [%d]", err);
+ ret = true;
+ }
+ }
+
+FINISH_OFF:
+ if (err_code)
+ *err_code = err;
+ EM_DEBUG_FUNC_END();
+ return ret;
+}
+
+#ifdef __LOCAL_ACTIVITY__
+EXPORT_API int em_core_local_activity_sync(int account_id, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ EM_DEBUG_LOG(">> account_id [%d], err_code [%p] ", account_id, err_code);
+
+ int *activity_id_list = NULL;
+ int activity_count = 0;
+ int err = 0;
+ int handle = 0;
+ int ret = false;
+ emf_event_t event_data;
+
+
+ memset(&event_data, 0x00, sizeof(emf_event_t));
+
+
+ EM_IF_NULL_RETURN_VALUE(err_code, false);
+
+ if (account_id <= 0) {
+ EM_DEBUG_EXCEPTION(" Invalid Account ID [%d] ", account_id);
+ return false;
+ }
+ EM_DEBUG_LOG(">>> emf_local_activity_sync 3 ");
+
+ if (!em_storage_get_activity_id_list(account_id, &activity_id_list, &activity_count, ACTIVITY_DELETEMAIL, ACTIVITY_COPYMAIL, true, &err)) {
+ EM_DEBUG_LOG(">>> emf_local_activity_sync 4 ");
+ EM_DEBUG_EXCEPTION(" em_storage_get_activity_id_list failed [ %d] ", err);
+ goto FINISH_OFF;
+ }
+ EM_DEBUG_LOG(">>> emf_local_activity_sync 5 ");
+
+ if (activity_count > 0) {
+ event_data.type = EMF_EVENT_LOCAL_ACTIVITY;
+ event_data.account_id = account_id;
+ if (!em_core_insert_event(&event_data, &handle, &err)) {
+ EM_DEBUG_LOG(" em_core_insert_event failed - %d", err);
+ goto FINISH_OFF;
+ }
+
+ ret = true;
+ }
+
+ FINISH_OFF:
+
+ if (activity_id_list)
+ em_storage_free_activity_id_list(activity_id_list, &err);
+
+ if (err_code != NULL)
+ *err_code = err;
+
+ return ret;
+
+}
+
+EXPORT_API int em_core_save_local_activity_sync(int account_id, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ EM_DEBUG_LOG(">> account_id [%d], err_code [%p] ", account_id, err_code);
+
+ emf_activity_tbl_t *local_activity = NULL;
+ int *activity_id_list = NULL;
+ int activity_count = 0;
+ int err = 0;
+ int ret = false;
+ int handle = 0;
+ emf_event_t event_data;
+
+ memset(&event_data, 0x00, sizeof(emf_event_t));
+
+ EM_IF_NULL_RETURN_VALUE(err_code, false);
+
+ if (account_id <= 0) {
+ EM_DEBUG_EXCEPTION(" Invalid Account ID [%d] ", account_id);
+ return false;
+ }
+ EM_DEBUG_LOG(">>> emf_local_activity_sync 3 ");
+
+ if (!em_storage_get_activity_id_list(account_id, &activity_id_list, &activity_count, ACTIVITY_SAVEMAIL, ACTIVITY_DELETEMAIL_SEND, true, &err)) {
+ EM_DEBUG_EXCEPTION(" em_storage_get_activity_id_list [ %d] ", err);
+ goto FINISH_OFF;
+ }
+
+
+ if (activity_count > 0) {
+ event_data.type = EMF_EVENT_LOCAL_ACTIVITY;
+ event_data.account_id = account_id;
+ if (!em_core_insert_send_event(&event_data, &handle, &err)) {
+ EM_DEBUG_LOG(" em_core_insert_event failed - %d", err);
+ goto FINISH_OFF;
+ }
+
+ ret = true;
+ }
+
+
+ FINISH_OFF:
+
+ if (local_activity)
+ em_storage_free_local_activity(&local_activity, activity_count, NULL);
+
+ if (activity_id_list)
+ em_storage_free_activity_id_list(activity_id_list, &err);
+
+ if (err_code != NULL)
+ *err_code = err;
+
+ return ret;
+
+}
+
+#endif
+
diff --git a/email-core/em-core-mesg.c b/email-core/em-core-mesg.c
new file mode 100755
index 0000000..968b16d
--- /dev/null
+++ b/email-core/em-core-mesg.c
@@ -0,0 +1,7057 @@
+/*
+* email-service
+*
+* Copyright (c) 2000 - 2011 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.
+*
+*/
+
+
+
+/******************************************************************************
+ * File : em-core-mesg.c
+ * Desc : Mail Operation
+ *
+ * Auth :
+ *
+ * History :
+ * 2006.08.16 : created
+ *****************************************************************************/
+#undef close
+#include <time.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+#include <fcntl.h>
+
+#include <sys/time.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
+#include <vconf.h>
+#include <contacts-svc.h>
+
+#include "em-core-types.h"
+#include "c-client.h"
+#include "lnx_inc.h"
+#include "em-core-global.h"
+#include "em-core-utils.h"
+#include "em-core-mesg.h"
+#include "em-core-mime.h"
+#include "em-core-mailbox.h"
+#include "em-storage.h"
+#include "em-core-mailbox-sync.h"
+#include "em-core-event.h"
+#include "em-core-account.h"
+
+#include "Msg_Convert.h"
+#include "emf-dbglog.h"
+
+#ifdef __FEATURE_DRM__
+#include <drm-service.h>
+#endif /* __FEATURE_DRM__ */
+
+#define ST_SILENT (long) 0x2 /* don't return results */
+#define ST_SET (long) 0x4 /* set vs. clear */
+
+static char g_new_server_uid[129];
+
+bool only_body_download = false;
+
+int multi_part_body_size = 0;
+int is_multi_part_body_download_all = 0;
+int _pop3_receiving_mail_id = 0;
+int _pop3_received_body_size = 0;
+int _pop3_last_notified_body_size = 0;
+int _pop3_total_body_size = 0;
+
+int _imap4_received_body_size = 0;
+int _imap4_last_notified_body_size = 0;
+int _imap4_total_body_size = 0;
+int _imap4_download_noti_interval_value = 0;
+
+BODY **g_inline_list = NULL ;
+int g_inline_count = 0;
+
+static int em_core_mail_delete_from_server(emf_account_t *account, emf_mailbox_t *mailbox, int msgno, int *err_code);
+static int em_core_mail_cmd_read_mail_pop3(void *stream, int msgno, int limited_size, int *downloded_size, int *total_body_size, int *err_code);
+static void em_core_mail_fill_attachment(emf_attachment_info_t *atch , emf_mail_attachment_tbl_t *attachment_tbl);
+
+extern long pop3_send (MAILSTREAM *stream, char *command, char *args);
+
+
+#ifdef FEATURE_CORE_DEBUG
+static char *_getType(int type)
+{
+ switch (type) {
+ case 0: return "TYPETEXT";
+ case 1: return "TYPEMULTIPART";
+ case 2: return "TYPEMESSAGE";
+ case 3: return "TYPEAPPLICATION";
+ case 4: return "TYPEAUDIO";
+ case 5: return "TYPEVIDEO";
+ case 6: return "TYPEMODEL";
+ case 7: return "TYPEOTHER";
+ }
+ return g_strdup_printf("%d", type);
+}
+
+static char *_getEncoding(int encoding)
+{
+ switch (encoding) {
+ case 0: return "ENC7BIT";
+ case 1: return "ENC8BIT";
+ case 2: return "ENCBINARY";
+ case 3: return "ENCBASE64";
+ case 4: return "ENCQUOTEDPRINTABLE";
+ case 5: return "ENCOTHER";
+ }
+ return g_strdup_printf("%d", encoding);
+}
+
+static void _print_parameter(PARAMETER *param)
+{
+ while (param != NULL) {
+ EM_DEBUG_EXCEPTION("param->attribute[%s]", param->attribute);
+ EM_DEBUG_EXCEPTION("param->value[%s]", param->value);
+
+ param = param->next;
+ }
+}
+
+static void _print_stringlist(STRINGLIST *stringlist)
+{
+ while (stringlist != NULL) {
+ EM_DEBUG_LOG("stringlist->text.data[%s]", stringlist->text.data);
+ EM_DEBUG_LOG("stringlist->text.size[%ld]", stringlist->text.size);
+
+ stringlist = stringlist->next;
+ }
+}
+
+static void _print_body(BODY *body, int recursive)
+{
+ EM_DEBUG_LOG(" ========================================================== ");
+
+ if (body != NULL) {
+ EM_DEBUG_LOG("body->type[%s]", _getType(body->type));
+ EM_DEBUG_LOG("body->encoding[%s]", _getEncoding(body->encoding));
+ EM_DEBUG_LOG("body->subtype[%s]", body->subtype);
+
+ EM_DEBUG_LOG("body->parameter[%p]", body->parameter);
+
+ _print_parameter(body->parameter);
+
+ EM_DEBUG_LOG("body->id[%s]", body->id);
+ EM_DEBUG_LOG("body->description[%s]", body->description);
+
+ EM_DEBUG_LOG("body->disposition.type[%s]", body->disposition.type);
+ EM_DEBUG_LOG("body->disposition.parameter[%p]", body->disposition.parameter);
+
+ _print_parameter(body->disposition.parameter);
+
+ EM_DEBUG_LOG("body->language[%p]", body->language);
+
+ _print_stringlist(body->language);
+
+ EM_DEBUG_LOG("body->location[%s]", body->location);
+
+ EM_DEBUG_LOG("body->mime.offset[%ld]", body->mime.offset);
+ EM_DEBUG_LOG("body->mime.text.data[%s]", body->mime.text.data);
+ EM_DEBUG_LOG("body->mime.text.size[%ld]", body->mime.text.size);
+
+ EM_DEBUG_LOG("body->contents.offset[%ld]", body->contents.offset);
+ EM_DEBUG_LOG("body->contents.text.data[%p]", body->contents.text.data);
+ EM_DEBUG_LOG("body->contents.text.size[%ld]", body->contents.text.size);
+
+ EM_DEBUG_LOG("body->nested.part[%p]", body->nested.part);
+
+ EM_DEBUG_LOG("body->size.lines[%ld]", body->size.lines);
+ EM_DEBUG_LOG("body->size.bytes[%ld]", body->size.bytes);
+
+ EM_DEBUG_LOG("body->md5[%s]", body->md5);
+ EM_DEBUG_LOG("body->sparep[%p]", body->sparep);
+
+ if (recursive) {
+ PART *part = body->nested.part;
+
+ while (part != NULL) {
+ _print_body(&(part->body), recursive);
+ part = part->next;
+ }
+ }
+ }
+
+ EM_DEBUG_LOG(" ========================================================== ");
+}
+#endif /* FEATURE_CORE_DEBUG */
+
+
+static int pop3_mail_delete(MAILSTREAM *stream, int msgno, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("stream[%p], msgno[%d], err_code[%p]", stream, msgno, err_code);
+
+ int ret = false;
+ int err = EMF_ERROR_NONE;
+
+ POP3LOCAL *pop3local = NULL;
+ char cmd[64];
+ char *p = NULL;
+
+ if (!stream) {
+ EM_DEBUG_EXCEPTION("stream[%p]", stream);
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ if (!(pop3local = stream->local) || !pop3local->netstream) {
+ EM_DEBUG_EXCEPTION("invalid POP3 stream detected...");
+ err = EMF_ERROR_UNKNOWN;
+ goto FINISH_OFF;
+ }
+
+ memset(cmd, 0x00, sizeof(cmd));
+
+ SNPRINTF(cmd, sizeof(cmd), "DELE %d\015\012", msgno);
+
+#ifdef FEATURE_CORE_DEBUG
+ EM_DEBUG_LOG("[POP3] >>> %s", cmd);
+#endif
+
+ /* send command : delete specified mail */
+ if (!net_sout(pop3local->netstream, cmd, (int)strlen(cmd))) {
+ EM_DEBUG_EXCEPTION("net_sout failed...");
+ err = EMF_ERROR_CONNECTION_BROKEN; /* EMF_ERROR_UNKNOWN; */
+ goto FINISH_OFF;
+ }
+
+ /* receive response */
+ if (!(p = net_getline(pop3local->netstream))) {
+ EM_DEBUG_EXCEPTION("net_getline failed...");
+ err = EMF_ERROR_INVALID_RESPONSE;
+ goto FINISH_OFF;
+ }
+
+#ifdef FEATURE_CORE_DEBUG
+ EM_DEBUG_LOG("[POP3] <<< %s", p);
+#endif
+
+ if (*p == '-') { /* '-ERR' */
+ err = EMF_ERROR_POP3_DELE_FAILURE; /* EMF_ERROR_MAIL_NOT_FOUND_ON_SERVER; */
+ goto FINISH_OFF;
+ }
+
+ if (*p != '+') { /* '+OK' ... */
+ err = EMF_ERROR_INVALID_RESPONSE;
+ goto FINISH_OFF;
+ }
+
+ ret = true;
+
+FINISH_OFF:
+ if (p)
+ free(p);
+
+ if (err_code)
+ *err_code = err;
+
+ return ret;
+}
+
+#ifdef __FEATURE_BULK_DELETE_MOVE_UPDATE_REQUEST_OPTI__
+
+static void em_core_mail_copyuid_ex(MAILSTREAM *stream, char *mailbox, unsigned long uidvalidity, SEARCHSET *sourceset, SEARCHSET *destset)
+{
+
+ EM_DEBUG_FUNC_BEGIN();
+
+ int index = -1;
+ int i = 0;
+ int err = EMF_ERROR_NONE;
+
+ unsigned long first_uid = 0;
+ unsigned long last_uid = 0;
+
+ unsigned long *old_server_uid = NULL;
+ unsigned long *new_server_uid = NULL;
+ int count = 0;
+ SEARCHSET *temp = sourceset;
+
+ char old_server_uid_char[129];
+ char new_server_uid_char[129];
+
+ if (NULL == sourceset || NULL == destset) {
+ /*
+ sourceset will be NULL when the sequence of UIDs sent to server for mail move operation has all invalid old server uids
+ if sourceset is NULL then corresponding dest set will be NULL
+ */
+
+ EM_DEBUG_LOG("em_core_mail_copyuid_ex failed : Invalid Parameters--> sourceset[%p] , destset[%p]", sourceset, destset);
+ return;
+ }
+
+ /* To get count of mails actually moved */
+
+ while (temp) {
+ if (temp->first > 0) {
+ first_uid = temp->first;
+
+ count++;
+
+ if (temp->last > 0) {
+ last_uid = temp->last;
+
+ while (first_uid < last_uid) {
+ first_uid++;
+ count++;
+ }
+ }
+ }
+
+ temp = temp->next;
+ }
+
+
+
+
+ EM_DEBUG_LOG("Count of mails copied [%d]", count);
+ old_server_uid = em_core_malloc(count * sizeof(unsigned long));
+ new_server_uid = em_core_malloc(count * sizeof(unsigned long));
+
+ /* While loop below will collect all old server uid from sourceset into old_server_uid array */
+
+ while (sourceset) {
+ if (sourceset->first > 0) {
+ first_uid = sourceset->first;
+
+ index++;
+ old_server_uid[index] = first_uid;
+
+ if (sourceset->last > 0) {
+ last_uid = sourceset->last;
+
+ while (first_uid < last_uid) {
+ first_uid++;
+ index++;
+
+ old_server_uid[index] = first_uid;
+ }
+ }
+ }
+
+ sourceset = sourceset->next;
+ }
+
+ /* While loop below will collect all new server uid from destset into new_server_uid array */
+
+ index = -1;
+ first_uid = last_uid = 0;
+
+ while (destset) {
+ if (destset->first > 0) {
+ first_uid = destset->first;
+
+ index++;
+ new_server_uid[index] = first_uid;
+
+ if (destset->last > 0) {
+ last_uid = destset->last;
+
+ while (first_uid < last_uid) {
+ first_uid++;
+ index++;
+
+ new_server_uid[index] = first_uid;
+ }
+ }
+ }
+
+ destset = destset->next;
+ }
+
+ /* For loop below updates mail_tbl and mail_read_mail_uid_tbl with new server uids*/
+
+ for (i = 0; i <= index; ++i) {
+
+ memset(old_server_uid_char, 0x00, sizeof(old_server_uid_char));
+ sprintf(old_server_uid_char, "%ld", old_server_uid[i]);
+
+ EM_DEBUG_LOG("Old Server Uid Char[%s]", old_server_uid_char);
+
+ memset(new_server_uid_char, 0x00, sizeof(new_server_uid_char));
+ sprintf(new_server_uid_char, "%ld", new_server_uid[i]);
+
+ EM_DEBUG_LOG("New Server Uid Char[%s]", new_server_uid_char);
+
+ if (!em_storage_update_server_uid(old_server_uid_char, new_server_uid_char, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_update_server_uid failed...[%d]", err);
+ }
+
+ if (!em_storage_update_read_mail_uid_by_server_uid(old_server_uid_char, new_server_uid_char, mailbox, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_update_read_mail_uid_by_server_uid failed... [%d]", err);
+ }
+
+#ifdef __FEATURE_PARTIAL_BODY_DOWNLOAD__
+
+ if (false == em_storage_update_pbd_activity(old_server_uid_char, new_server_uid_char, mailbox, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_update_pbd_activity failed... [%d]", err);
+ }
+
+#endif
+ }
+
+ EM_SAFE_FREE(old_server_uid);
+ EM_SAFE_FREE(new_server_uid);
+
+}
+
+
+EXPORT_API int em_core_mail_move_from_server_ex(int account_id, char *src_mailbox, int mail_ids[], int num, char *dest_mailbox, int *error_code)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ MAILSTREAM *stream = NULL;
+ int err_code = EMF_ERROR_NONE;
+ emf_account_t *ref_account = NULL;
+ int ret = false;
+ int i = 0;
+ emf_id_set_t *id_set = NULL;
+ int id_set_count = 0;
+
+ emf_uid_range_set *uid_range_set = NULL;
+ int len_of_each_range = 0;
+
+ emf_uid_range_set *uid_range_node = NULL;
+
+ char **string_list = NULL;
+ int string_count = 0;
+
+ if (num <= 0 || account_id <= 0 || NULL == src_mailbox || NULL == dest_mailbox || NULL == mail_ids) {
+ if (error_code != NULL) {
+ *error_code = EMF_ERROR_INVALID_PARAM;
+ }
+ EM_DEBUG_LOG("Invalid Parameters- num[%d], account_id[%d], src_mailbox[%p], dest_mailbox[%p], mail_ids[%p]", num, account_id, src_mailbox, dest_mailbox, mail_ids);
+ return false;
+ }
+
+ ref_account = em_core_get_account_reference(account_id);
+
+ if (NULL == ref_account) {
+ EM_DEBUG_EXCEPTION(" em_core_get_account_reference failed[%d]", account_id);
+
+ *error_code = EMF_ERROR_INVALID_ACCOUNT;
+ goto FINISH_OFF;
+ }
+
+
+ if (ref_account->receiving_server_type != EMF_SERVER_TYPE_IMAP4) {
+ *error_code = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+
+ if (!em_core_mailbox_open(account_id, src_mailbox, (void **)&stream, &err_code)) {
+ EM_DEBUG_EXCEPTION("em_core_mailbox_open failed[%d]", err_code);
+
+ goto FINISH_OFF;
+ }
+
+ if (NULL != stream) {
+ mail_parameters(stream, SET_COPYUID, em_core_mail_copyuid_ex);
+ EM_DEBUG_LOG("calling mail_copy_full FODLER MAIL COPY ");
+ /* [h.gahlaut] Break the set of mail_ids into comma separated strings of given length */
+ /* Length is decided on the basis of remaining keywords in the Query to be formed later on in em_storage_get_id_set_from_mail_ids */
+ /* Here about 90 bytes are required for fixed keywords in the query-> SELECT local_uid, s_uid from mail_read_mail_uid_tbl where local_uid in (....) ORDER by s_uid */
+ /* So length of comma separated strings which will be filled in (.....) in above query can be maximum QUERY_SIZE - 90 */
+
+ if (false == em_core_form_comma_separated_strings(mail_ids, num, QUERY_SIZE - 90, &string_list, &string_count, &err_code)) {
+ EM_DEBUG_EXCEPTION("em_core_form_comma_separated_strings failed [%d]", err_code);
+ goto FINISH_OFF;
+ }
+
+ /* Now execute one by one each comma separated string of mail_ids */
+
+ for (i = 0; i < string_count; ++i) {
+ /* Get the set of mail_ds and corresponding server_mail_ids sorted by server mail ids in ascending order */
+
+ if (false == em_storage_get_id_set_from_mail_ids(string_list[i], &id_set, &id_set_count, &err_code)) {
+ EM_DEBUG_EXCEPTION("em_storage_get_id_set_from_mail_ids failed [%d]", err_code);
+ goto FINISH_OFF;
+ }
+
+ /* Convert the sorted sequence of server mail ids to range sequences of given length. A range sequence will be like A : B, C, D: E, H */
+
+ len_of_each_range = MAX_IMAP_COMMAND_LENGTH - 40; /* 1000 is the maximum length allowed RFC 2683. 40 is left for keywords and tag. */
+
+ if (false == em_core_convert_to_uid_range_set(id_set, id_set_count, &uid_range_set, len_of_each_range, &err_code)) {
+ EM_DEBUG_EXCEPTION("em_core_convert_to_uid_range_set failed [%d]", err_code);
+ goto FINISH_OFF;
+ }
+
+ uid_range_node = uid_range_set;
+
+ while (uid_range_node != NULL) {
+ /* Remove comma from end of uid_range */
+ uid_range_node->uid_range[strlen(uid_range_node->uid_range) - 1] = '\0';
+ EM_DEBUG_LOG("uid_range_node->uid_range - %s", uid_range_node->uid_range);
+ if (!mail_copy_full(stream, uid_range_node->uid_range, dest_mailbox, CP_UID | CP_MOVE)) {
+ EM_DEBUG_EXCEPTION("em_core_mail_move_from_server_ex : Mail cannot be moved failed");
+ EM_DEBUG_EXCEPTION("Mail MOVE failed ");
+ goto FINISH_OFF;
+ }
+ else if (!mail_expunge_full(stream, uid_range_node->uid_range, EX_UID)) {
+ EM_DEBUG_EXCEPTION("em_core_mail_move_from_server_ex : Mail cannot be expunged after move. failed!");
+ EM_DEBUG_EXCEPTION("Mail Expunge after move failed ");
+ goto FINISH_OFF;
+ }
+ else {
+ EM_DEBUG_LOG("Mail MOVE SUCCESS ");
+ }
+
+ uid_range_node = uid_range_node->next;
+ }
+
+ em_core_free_uid_range_set(&uid_range_set);
+
+ EM_SAFE_FREE(id_set);
+
+ id_set_count = 0;
+ }
+
+ }
+ else {
+ EM_DEBUG_EXCEPTION(">>>> STREAM DATA IS NULL >>> ");
+ goto FINISH_OFF;
+ }
+
+
+ ret = true;
+
+FINISH_OFF:
+ em_core_mailbox_close(0, stream);
+ stream = NULL;
+
+#ifdef __LOCAL_ACTIVITY__
+ if (ret || ref_account->receiving_server_type != EMF_SERVER_TYPE_IMAP4) /* Delete local activity for POP3 mails and successful move operation in IMAP */ {
+ emf_activity_tbl_t new_activity;
+ for (i = 0; i<num ; i++) {
+ memset(&new_activity, 0x00, sizeof(emf_activity_tbl_t));
+ new_activity.activity_type = ACTIVITY_MOVEMAIL;
+ new_activity.account_id = account_id;
+ new_activity.mail_id = mail_ids[i];
+ new_activity.src_mbox = src_mailbox;
+ new_activity.dest_mbox = dest_mailbox;
+
+ if (!em_core_activity_delete(&new_activity, &err_code)) {
+ EM_DEBUG_EXCEPTION(">>>>>>Local Activity ACTIVITY_MOVEMAIL [%d] ", err_code);
+ }
+ }
+
+ }
+#endif
+
+ if (error_code != NULL) {
+ *error_code = err_code;
+ }
+
+ return ret;
+}
+
+#ifdef __LOCAL_ACTIVITY__
+int imap4_mail_delete_ex(emf_mailbox_t *mailbox, int mail_ids[], int num, int from_server, int *err_code)
+#else
+int imap4_mail_delete_ex(emf_mailbox_t *mailbox, int mail_ids[], int num, int *err_code)
+#endif
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ int ret = false;
+ int err = EMF_ERROR_NONE;
+
+ IMAPLOCAL *imaplocal = NULL;
+ char *p = NULL;
+ MAILSTREAM *stream = NULL;
+ char tag[MAX_TAG_SIZE];
+ char cmd[MAX_IMAP_COMMAND_LENGTH];
+ emf_id_set_t *id_set = NULL;
+ int id_set_count = 0;
+ int i = 0;
+ emf_uid_range_set *uid_range_set = NULL;
+ int len_of_each_range = 0;
+ emf_uid_range_set *uid_range_node = NULL;
+ char **string_list = NULL;
+ int string_count = 0;
+ int delete_success = false;
+
+ if (num <= 0 || !mail_ids || !mailbox) {
+ EM_DEBUG_EXCEPTION(" Invalid parameter ");
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ stream = mailbox->mail_stream;
+ if (!stream) {
+ EM_DEBUG_EXCEPTION(" Stream is NULL ");
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+
+ }
+
+ /* [h.gahlaut] Break the set of mail_ids into comma separated strings of given length */
+ /* Length is decided on the basis of remaining keywords in the Query to be formed later on in em_storage_get_id_set_from_mail_ids */
+ /* Here about 90 bytes are required for fixed keywords in the query-> SELECT local_uid, s_uid from mail_read_mail_uid_tbl where local_uid in (....) ORDER by s_uid */
+ /* So length of comma separated strings which will be filled in (.....) in above query can be maximum QUERY_SIZE - 90 */
+
+ if (false == em_core_form_comma_separated_strings(mail_ids, num, QUERY_SIZE - 90, &string_list, &string_count, &err)) {
+ EM_DEBUG_EXCEPTION("em_core_form_comma_separated_strings failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ /* Now execute one by one each comma separated string of mail_ids */
+
+ for (i = 0; i < string_count; ++i) {
+ /* Get the set of mail_ds and corresponding server_mail_ids sorted by server mail ids in ascending order */
+
+ if (false == em_storage_get_id_set_from_mail_ids(string_list[i], &id_set, &id_set_count, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_get_id_set_from_mail_ids failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ /* Convert the sorted sequence of server mail ids to range sequences of given length. A range sequence will be like A : B, C, D: E, H */
+
+ len_of_each_range = MAX_IMAP_COMMAND_LENGTH - 40; /* 1000 is the maximum length allowed RFC 2683. 40 is left for keywords and tag. */
+
+ if (false == em_core_convert_to_uid_range_set(id_set, id_set_count, &uid_range_set, len_of_each_range, &err)) {
+ EM_DEBUG_EXCEPTION("em_core_convert_to_uid_range_set failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ uid_range_node = uid_range_set;
+
+ while (uid_range_node != NULL) {
+ /* Remove comma from end of uid_range */
+
+ uid_range_node->uid_range[strlen(uid_range_node->uid_range) - 1] = '\0';
+
+ if (!(imaplocal = stream->local) || !imaplocal->netstream) {
+ EM_DEBUG_EXCEPTION("invalid IMAP4 stream detected...");
+
+ err = EMF_ERROR_CONNECTION_BROKEN;
+ goto FINISH_OFF;
+ }
+
+ memset(tag, 0x00, sizeof(tag));
+ memset(cmd, 0x00, sizeof(cmd));
+
+ SNPRINTF(tag, sizeof(tag), "%08lx", 0xffffffff & (stream->gensym++));
+ SNPRINTF(cmd, sizeof(cmd), "%s UID STORE %s +FLAGS (\\Deleted)\015\012", tag, uid_range_node->uid_range);
+
+ EM_DEBUG_LOG("[IMAP4] >>> %s", cmd);
+
+
+ /* send command : set deleted flag */
+ if (!net_sout(imaplocal->netstream, cmd, (int)strlen(cmd))) {
+ EM_DEBUG_EXCEPTION("net_sout failed...");
+
+ err = EMF_ERROR_CONNECTION_BROKEN; /* EMF_ERROR_UNKNOWN */
+ goto FINISH_OFF;
+ }
+
+
+ while (imaplocal->netstream) {
+ /* receive response */
+ if (!(p = net_getline(imaplocal->netstream))) {
+ EM_DEBUG_EXCEPTION("net_getline failed...");
+
+ err = EMF_ERROR_INVALID_RESPONSE; /* EMF_ERROR_UNKNOWN; */
+ goto FINISH_OFF;
+ }
+
+
+ EM_DEBUG_LOG("[IMAP4] <<< %s", p);
+
+ /* To confirm - Commented out as FETCH response does not contain the tag - may be a problem for common stream in email-service*/
+ /* Success case - delete all local activity and entry from mail_read_mail_uid_tbl
+ if (strstr(p, "FETCH") != NULL) {
+ EM_DEBUG_LOG(" FETCH Response recieved ");
+ delete_success = true;
+ EM_SAFE_FREE(p);
+ break;
+ }
+ */
+
+
+ if (!strncmp(p, tag, strlen(tag))) {
+ if (!strncmp(p + strlen(tag) + 1, "OK", 2)) {
+ /*Error scenario delete all local activity and entry from mail_read_mail_uid_tbl */
+ EM_DEBUG_LOG(" OK Response recieved ");
+ delete_success = true;
+ EM_SAFE_FREE(p);
+ break;
+ }
+ else {
+ /* 'NO' or 'BAD' */
+ delete_success = false;
+ err = EMF_ERROR_IMAP4_STORE_FAILURE; /* EMF_ERROR_INVALID_RESPONSE; */
+ goto FINISH_OFF;
+ }
+ }
+
+ EM_SAFE_FREE(p);
+ }
+
+ memset(tag, 0x00, sizeof(tag));
+ memset(cmd, 0x00, sizeof(cmd));
+
+ EM_DEBUG_LOG("Calling Expunge");
+
+ SNPRINTF(tag, sizeof(tag), "%08lx", 0xffffffff & (stream->gensym++));
+ SNPRINTF(cmd, sizeof(cmd), "%s EXPUNGE\015\012", tag);
+
+ EM_DEBUG_LOG("[IMAP4] >>> %s", cmd);
+
+ /* send command : EXPUNGE */
+ if (!net_sout(imaplocal->netstream, cmd, (int)strlen(cmd))) {
+ EM_DEBUG_EXCEPTION("net_sout failed...");
+
+ err = EMF_ERROR_CONNECTION_BROKEN;
+ goto FINISH_OFF;
+ }
+
+ while (imaplocal->netstream) {
+ /* receive response */
+ if (!(p = net_getline(imaplocal->netstream))) {
+ EM_DEBUG_EXCEPTION("net_getline failed...");
+
+ err = EMF_ERROR_INVALID_RESPONSE; /* EMF_ERROR_UNKNOWN; */
+ goto FINISH_OFF;
+ }
+
+ EM_DEBUG_LOG("[IMAP4] <<< %s", p);
+
+ if (!strncmp(p, tag, strlen(tag))) {
+ if (!strncmp(p + strlen(tag) + 1, "OK", 2)) {
+#ifdef __LOCAL_ACTIVITY__
+ int index = 0;
+ emf_mail_tbl_t **mail = NULL;
+
+ mail = (emf_mail_tbl_t **) em_core_malloc(num * sizeof(emf_mail_tbl_t *));
+ if (!mail) {
+ EM_DEBUG_EXCEPTION("em_core_malloc failed");
+ err = EMF_ERROR_UNKNOWN;
+ goto FINISH_OFF;
+ }
+
+ if (delete_success) {
+ for (index = 0 ; index < num; index++) {
+ if (!em_storage_get_downloaded_mail(mail_ids[index], &mail[index], false, &err)) {
+ EM_DEBUG_LOG("em_storage_get_uid_by_mail_id failed [%d]", err);
+
+ if (err == EM_STORAGE_ERROR_MAIL_NOT_FOUND) {
+ EM_DEBUG_LOG("EMF_ERROR_MAIL_NOT_FOUND_ON_SERVER : ");
+ continue;
+ }
+ }
+
+ if (mail[index]) {
+ /* Clear entry from mail_read_mail_uid_tbl */
+ if (mail[index]->server_mail_id != NULL) {
+ if (!em_storage_remove_downloaded_mail(mailbox->account_id, mailbox->name, mail[index]->server_mail_id, true, &err)) {
+ EM_DEBUG_LOG("em_storage_remove_downloaded_mail falied [%d]", err);
+ }
+ }
+
+ /* Delete local activity */
+ emf_activity_tbl_t new_activity;
+ memset(&new_activity, 0x00, sizeof(emf_activity_tbl_t));
+ if (from_server == EMF_DELETE_FOR_SEND_THREAD) {
+ new_activity.activity_type = ACTIVITY_DELETEMAIL_SEND;
+ EM_DEBUG_LOG("from_server == EMF_DELETE_FOR_SEND_THREAD ");
+ }
+ else {
+ new_activity.activity_type = ACTIVITY_DELETEMAIL;
+ }
+
+ new_activity.mail_id = mail[index]->mail_id;
+ new_activity.server_mailid = NULL;
+ new_activity.src_mbox = NULL;
+ new_activity.dest_mbox = NULL;
+
+ if (!em_core_activity_delete(&new_activity, &err)) {
+ EM_DEBUG_EXCEPTION(" em_core_activity_delete failed - %d ", err);
+ }
+ }
+ else {
+ /* Fix for crash seen while deleting Outbox mails which are moved to Trash. Outbox mails do not have server mail id and are not updated in mail_read_mail_uid_tbl.
+ * So there is no need of deleting entry in mail_read_mail_uid_tbl. However local activity has to be deleted.
+ */
+ /* Delete local activity */
+ emf_activity_tbl_t new_activity;
+ memset(&new_activity, 0x00, sizeof(emf_activity_tbl_t));
+ new_activity.activity_type = ACTIVITY_DELETEMAIL;
+ new_activity.mail_id = mail_ids[index]; /* valid mail id passed for outbox mails*/
+ new_activity.server_mailid = NULL;
+ new_activity.src_mbox = NULL;
+ new_activity.dest_mbox = NULL;
+
+ if (!em_core_activity_delete(&new_activity, &err)) {
+ EM_DEBUG_EXCEPTION(" em_core_activity_delete failed - %d ", err);
+ }
+ }
+ }
+
+ for (index = 0; index < num; index++) {
+ if (!em_storage_free_mail(&mail[index], 1, &err)) {
+ EM_DEBUG_EXCEPTION(" em_storage_free_mail [%d]", err);
+ }
+ }
+
+ EM_SAFE_FREE(mail);
+ }
+
+#endif
+ EM_SAFE_FREE(p);
+ break;
+ }
+ else { /* 'NO' or 'BAD' */
+ err = EMF_ERROR_IMAP4_EXPUNGE_FAILURE; /* EMF_ERROR_INVALID_RESPONSE; */
+ goto FINISH_OFF;
+ }
+ }
+
+ EM_SAFE_FREE(p);
+ }
+ uid_range_node = uid_range_node->next;
+ }
+
+ em_core_free_uid_range_set(&uid_range_set);
+
+ EM_SAFE_FREE(id_set);
+
+ id_set_count = 0;
+ }
+
+ ret = true;
+
+FINISH_OFF:
+ EM_SAFE_FREE(p);
+
+ em_core_free_comma_separated_strings(&string_list, &string_count);
+
+ if (false == ret) {
+ em_core_free_uid_range_set(&uid_range_set);
+ }
+
+ if (err_code) {
+ *err_code = err;
+ }
+
+ return ret;
+
+}
+
+#endif
+
+static int imap4_mail_delete(MAILSTREAM *stream, int msgno, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("stream[%p], msgno[%d], err_code[%p]", stream, msgno, err_code);
+
+ int ret = false;
+ int err = EMF_ERROR_NONE;
+
+ IMAPLOCAL *imaplocal = NULL;
+ char tag[16], cmd[64];
+ char *p = NULL;
+
+ if (!(imaplocal = stream->local) || !imaplocal->netstream) {
+ EM_DEBUG_EXCEPTION("invalid IMAP4 stream detected...");
+
+ err = EMF_ERROR_INVALID_PARAM; /* EMF_ERROR_UNKNOWN */
+ goto FINISH_OFF;
+ }
+
+ memset(tag, 0x00, sizeof(tag));
+ memset(cmd, 0x00, sizeof(cmd));
+
+ SNPRINTF(tag, sizeof(tag), "%08lx", 0xffffffff & (stream->gensym++));
+ SNPRINTF(cmd, sizeof(cmd), "%s STORE %d +FLAGS.SILENT (\\Deleted)\015\012", tag, msgno);
+
+#ifdef FEATURE_CORE_DEBUG
+ EM_DEBUG_LOG("[IMAP4] >>> %s", cmd);
+#endif
+
+ /* send command : set deleted flag */
+ if (!net_sout(imaplocal->netstream, cmd, (int)strlen(cmd))) {
+ EM_DEBUG_EXCEPTION("net_sout failed...");
+
+ err = EMF_ERROR_CONNECTION_BROKEN; /* EMF_ERROR_UNKNOWN */
+ goto FINISH_OFF;
+ }
+
+ while (imaplocal->netstream) {
+ /* receive response */
+ if (!(p = net_getline(imaplocal->netstream))) {
+ EM_DEBUG_EXCEPTION("net_getline failed...");
+
+ err = EMF_ERROR_INVALID_RESPONSE; /* EMF_ERROR_UNKNOWN; */
+ goto FINISH_OFF;
+ }
+
+#ifdef FEATURE_CORE_DEBUG
+ EM_DEBUG_LOG("[IMAP4] <<< %s", p);
+#endif
+ if (!strncmp(p, tag, strlen(tag))) {
+ if (!strncmp(p + strlen(tag) + 1, "OK", 2)) {
+ EM_SAFE_FREE(p);
+ break;
+ }
+ else { /* 'NO' or 'BAD' */
+ err = EMF_ERROR_IMAP4_STORE_FAILURE; /* EMF_ERROR_INVALID_RESPONSE; */
+ goto FINISH_OFF;
+ }
+ }
+
+ EM_SAFE_FREE(p);
+ }
+
+ memset(tag, 0x00, sizeof(tag));
+ memset(cmd, 0x00, sizeof(cmd));
+
+ SNPRINTF(tag, sizeof(tag), "%08lx", 0xffffffff & (stream->gensym++));
+ SNPRINTF(cmd, sizeof(cmd), "%s EXPUNGE\015\012", tag);
+
+#ifdef FEATURE_CORE_DEBUG
+ EM_DEBUG_LOG("[IMAP4] >>> %s", cmd);
+#endif
+
+ /* send command : delete flaged mail */
+ if (!net_sout(imaplocal->netstream, cmd, (int)strlen(cmd))) {
+ EM_DEBUG_EXCEPTION("net_sout failed...");
+
+ err = EMF_ERROR_CONNECTION_BROKEN;
+ goto FINISH_OFF;
+ }
+
+ while (imaplocal->netstream) {
+ /* receive response */
+ if (!(p = net_getline(imaplocal->netstream))) {
+ EM_DEBUG_EXCEPTION("net_getline failed...");
+
+ err = EMF_ERROR_INVALID_RESPONSE; /* EMF_ERROR_UNKNOWN; */
+ goto FINISH_OFF;
+ }
+
+#ifdef FEATURE_CORE_DEBUG
+ EM_DEBUG_LOG("[IMAP4] <<< %s", p);
+#endif
+
+ if (!strncmp(p, tag, strlen(tag))) {
+ if (!strncmp(p + strlen(tag) + 1, "OK", 2)) {
+ EM_SAFE_FREE(p);
+ break;
+ }
+ else { /* 'NO' or 'BAD' */
+ err = EMF_ERROR_IMAP4_EXPUNGE_FAILURE; /* EMF_ERROR_INVALID_RESPONSE; */
+ goto FINISH_OFF;
+ }
+ }
+
+ EM_SAFE_FREE(p);
+ }
+
+ ret = true;
+
+FINISH_OFF:
+ EM_SAFE_FREE(p);
+
+ if (err_code)
+ *err_code = err;
+
+ return ret;
+}
+
+typedef enum {
+ IMAP4_CMD_EXPUNGE
+} imap4_cmd_t;
+
+static int imap4_send_command(MAILSTREAM *stream, imap4_cmd_t cmd_type, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("stream[%p], cmd_type[%d], err_code[%p]", stream, cmd_type, err_code);
+
+ int ret = false;
+ int err = EMF_ERROR_NONE;
+
+ IMAPLOCAL *imaplocal = NULL;
+ char tag[16], cmd[64];
+ char *p = NULL;
+
+ if (!(imaplocal = stream->local) || !imaplocal->netstream) {
+ EM_DEBUG_EXCEPTION("invalid IMAP4 stream detected...");
+
+ err = EMF_ERROR_INVALID_PARAM; /* EMF_ERROR_UNKNOWN */
+ goto FINISH_OFF;
+ }
+
+ memset(tag, 0x00, sizeof(tag));
+ memset(cmd, 0x00, sizeof(cmd));
+
+ SNPRINTF(tag, sizeof(tag), "%08lx", 0xffffffff & (stream->gensym++));
+ SNPRINTF(cmd, sizeof(cmd), "%s EXPUNGE\015\012", tag);
+
+#ifdef FEATURE_CORE_DEBUG
+ EM_DEBUG_LOG("[IMAP4] >>> %s", cmd);
+#endif
+
+ /* send command : delete flaged mail */
+ if (!net_sout(imaplocal->netstream, cmd, (int)strlen(cmd))) {
+ EM_DEBUG_EXCEPTION("net_sout failed...");
+
+ err = EMF_ERROR_CONNECTION_BROKEN;
+ goto FINISH_OFF;
+ }
+
+ while (imaplocal->netstream) {
+ /* receive response */
+ if (!(p = net_getline(imaplocal->netstream))) {
+ EM_DEBUG_EXCEPTION("net_getline failed...");
+
+ err = EMF_ERROR_INVALID_RESPONSE; /* EMF_ERROR_UNKNOWN; */
+ goto FINISH_OFF;
+ }
+
+#ifdef FEATURE_CORE_DEBUG
+ EM_DEBUG_LOG("[IMAP4] <<< %s", p);
+#endif
+
+ if (!strncmp(p, tag, strlen(tag))) {
+ if (!strncmp(p + strlen(tag) + 1, "OK", 2)) {
+ EM_SAFE_FREE(p);
+ break;
+ }
+ else { /* 'NO' or 'BAD' */
+ err = EMF_ERROR_IMAP4_EXPUNGE_FAILURE; /* EMF_ERROR_INVALID_RESPONSE; */
+ goto FINISH_OFF;
+ }
+ }
+
+ EM_SAFE_FREE(p);
+ }
+
+ ret = true;
+
+FINISH_OFF:
+ EM_SAFE_FREE(p);
+
+ if (err_code)
+ *err_code = err;
+
+ return ret;
+}
+
+
+
+/* description
+ * get mail header from local mailbox
+ * arguments
+ * mailbox : message no
+ * header : buffer to hold header information
+ * return
+ * succeed : 1
+ * fail : 0
+ */
+int em_core_mail_get_header(/*emf_mailbox_t *mailbox, */ int mail_id, emf_mail_head_t **header, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("mail_id[%d], header[%p], err_code[%p]", mail_id, header, err_code);
+
+ if (!mail_id || !header) {
+ EM_DEBUG_EXCEPTION("mail_id[%d], header[%p]", mail_id, header);
+ if (err_code != NULL)
+ *err_code = EMF_ERROR_INVALID_PARAM;
+ return false;
+ }
+
+ int ret = false;
+ int err = EMF_ERROR_NONE;
+
+ emf_mail_head_t *p = NULL;
+ emf_mail_tbl_t *mail = NULL;
+
+ *header = NULL;
+
+ /* get mail from mail table */
+ if (!em_storage_get_mail_by_id(mail_id, &mail, true, &err) || !mail) {
+ EM_DEBUG_EXCEPTION("em_storage_get_mail_by_id failed [%d]", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+
+ if (!em_core_mail_get_header_from_mail_tbl(&p, mail, &err)) {
+ EM_DEBUG_EXCEPTION("em_core_mail_get_header_from_mail_tbl failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ *header = p;
+
+ ret = true;
+
+FINISH_OFF:
+ if (ret == false && p != NULL)
+ em_core_mail_head_free(&p, 1, NULL);
+
+ if (mail != NULL)
+ em_storage_free_mail(&mail, 1, NULL);
+
+ if (err_code != NULL)
+ *err_code = err;
+
+ return ret;
+}
+EXPORT_API int em_core_mail_get_header_from_mail_tbl(emf_mail_head_t **header, emf_mail_tbl_t *mail , int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("mail[%p], header[%p], err_code[%p]", mail, header, err_code);
+
+ if (!mail || !header) {
+ EM_DEBUG_EXCEPTION("mail[%p], header[%p]", mail, header);
+ if (err_code != NULL)
+ *err_code = EMF_ERROR_INVALID_PARAM;
+ return false;
+ }
+
+ int ret = false;
+ int err = EMF_ERROR_NONE;
+
+ emf_mail_head_t *p = NULL;
+
+ if (!(p = em_core_malloc(sizeof(emf_mail_head_t)))) {
+ EM_DEBUG_EXCEPTION("malloc failed...");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ memset(p, 0x00, sizeof(emf_mail_head_t));
+
+ p->subject = mail->subject; mail->subject = NULL;
+ p->mid = mail->message_id; mail->message_id = NULL;
+ p->to_contact_name = NULL;
+ p->from_contact_name = NULL;
+ p->cc_contact_name = NULL;
+ p->bcc_contact_name = NULL;
+
+ EM_DEBUG_LOG("to_contact_name [%s]", p->to_contact_name);
+ EM_DEBUG_LOG("from_contact_name [%s]", p->from_contact_name);
+
+ p->from = mail->full_address_from; mail->full_address_from = NULL;
+ p->to = mail->full_address_to; mail->full_address_to = NULL;
+ p->cc = mail->full_address_cc; mail->full_address_cc = NULL;
+ p->bcc = mail->full_address_bcc; mail->full_address_bcc = NULL;
+ p->reply_to = mail->full_address_reply; mail->full_address_reply = NULL;
+ p->return_path = mail->full_address_return; mail->full_address_return = NULL;
+ p->previewBodyText = mail->preview_text; mail->preview_text = NULL;
+
+ /* mail received time */
+ if (!em_convert_string_to_datetime(mail->datetime, &p->datetime, &err)) {
+ EM_DEBUG_EXCEPTION("em_convert_string_to_datetime failed [%d]", err);
+ /* goto FINISH_OFF; */
+ }
+ ret = true;
+
+FINISH_OFF:
+ if (ret == true)
+ *header = p;
+ else if (p != NULL)
+ em_core_mail_head_free(&p, 1, NULL);
+
+ if (err_code != NULL)
+ *err_code = err;
+
+ return ret;
+}
+
+int em_core_mail_get_contact_info(emf_mail_contact_info_t *contact_info, char *full_address, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("contact_info[%p], full_address[%s], err_code[%p]", contact_info, full_address, err_code);
+
+ int ret = false;
+ int err = EMF_ERROR_NONE;
+
+ if (!em_core_mail_get_contact_info_with_update(contact_info, full_address, 0, &err))
+ EM_DEBUG_EXCEPTION("em_core_mail_get_contact_info_with_update failed [%d]", err);
+ else
+ ret = true;
+
+ if (err_code != NULL)
+ *err_code = err;
+
+ return ret;
+}
+
+EXPORT_API int em_core_mail_get_display_name(CTSvalue *contact_name_value, char **contact_display_name)
+{
+ EM_DEBUG_FUNC_BEGIN("contact_name_value[%p], contact_display_name[%p]", contact_name_value, contact_display_name);
+ char *display = NULL;
+ const char *first = contacts_svc_value_get_str(contact_name_value, CTS_NAME_VAL_FIRST_STR);
+ const char *last = contacts_svc_value_get_str(contact_name_value, CTS_NAME_VAL_LAST_STR);
+
+ EM_DEBUG_LOG(">>>>>> first[%s] last[%s]", first, last);
+ if (first != NULL && last != NULL) {
+ /* if (CTS_ORDER_NAME_FIRSTLAST == contacts_svc_get_name_order()) */
+ if (CTS_ORDER_NAME_FIRSTLAST == contacts_svc_get_order(CTS_ORDER_OF_DISPLAY))
+ display = g_strconcat(first, " ", last, NULL);
+ else
+ display = g_strconcat(last, " ", first, NULL);
+
+ }
+ else if (first != NULL || last != NULL) {
+ if (first != NULL)
+ display = (char *)EM_SAFE_STRDUP(first);
+ else
+ display = (char *)EM_SAFE_STRDUP(last);
+ }
+ else
+ display = g_strdup(contacts_svc_value_get_str(contact_name_value, CTS_NAME_VAL_DISPLAY_STR));
+
+ if (contact_display_name != NULL)
+ *contact_display_name = display;
+
+ return true;
+}
+
+int em_core_mail_get_contact_info_with_update(emf_mail_contact_info_t *contact_info, char *full_address, int mail_id, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("contact_info[%p], full_address[%s], mail_id[%d], err_code[%p]", contact_info, full_address, mail_id, err_code);
+
+ int ret = false;
+ int err = EMF_ERROR_NONE;
+
+ ADDRESS *addr = NULL;
+ char *address = NULL;
+ char *temp_emailaddr = NULL;
+ int start_text_ascii = 2;
+ int end_text_ascii = 3;
+
+ char *alias = NULL;
+ int is_searched = false;
+ int address_length = 0;
+
+ if (!contact_info) {
+ EM_DEBUG_EXCEPTION("contact_info[%p]", contact_info);
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ if (!full_address) {
+ full_address = "";
+ address_length = 0;
+ temp_emailaddr = NULL;
+ }
+ else {
+ address_length = 2 * strlen(full_address);
+ temp_emailaddr = (char *)calloc(1, address_length);
+ }
+
+ em_core_skip_whitespace(full_address , &address);
+ EM_DEBUG_LOG("address[address][%s]", address);
+
+
+ /* ',' -> "%2C" */
+ gchar **tokens = g_strsplit(address, ", ", -1);
+ char *p = g_strjoinv("%2C", tokens);
+ int i = 0;
+
+ g_strfreev(tokens);
+
+ /* ';' -> ',' */
+ while (p && p[i] != '\0')
+ {
+ if (p[i] == ';')
+ p[i] = ',';
+ i++;
+ }
+ EM_DEBUG_LOG(" 2 converted address %s ", p);
+
+ rfc822_parse_adrlist(&addr, p, NULL);
+
+ EM_SAFE_FREE(p);
+ EM_DEBUG_LOG(" 3 full_address %s ", full_address);
+
+ if (!addr) {
+ EM_DEBUG_EXCEPTION("rfc822_parse_adrlist failed...");
+
+ err = EMF_ERROR_INVALID_ADDRESS;
+ goto FINISH_OFF;
+ }
+
+ CTSstruct *contact = NULL;
+ CTSvalue *contact_name_value = NULL;
+ int contact_index = -1;
+ char *contact_display_name = NULL;
+ char *contact_display_name_from_contact_info = NULL;
+ int contact_display_name_len = 0;
+
+ /* char **/
+ char *email_address = NULL;
+ int contact_name_buffer_size = address_length;
+ int contact_name_len = 0;
+ char *contact_name = (char *)calloc(1, contact_name_buffer_size);
+ char temp_string[1024];
+
+ int is_saved = 0;
+
+ if (!contact_name) {
+ EM_DEBUG_EXCEPTION("Memory allocation error!");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ memset(contact_name, 0x00, contact_name_buffer_size);
+
+ while (addr != NULL) {
+ if (addr->mailbox && addr->host) {
+ if (!strncmp(addr->mailbox , "UNEXPECTED_DATA_AFTER_ADDRESS", strlen("UNEXPECTED_DATA_AFTER_ADDRESS")) || !strncmp(addr->mailbox , "INVALID_ADDRESS", strlen("INVALID_ADDRESS")) || !strncmp(addr->host , ".SYNTAX-ERROR.", strlen(".SYNTAX-ERROR.")))
+ {
+ EM_DEBUG_LOG("Invalid address ");
+ addr = addr->next;
+ continue;
+ }
+ }
+ else {
+ EM_DEBUG_LOG("Error in parsing..! ");
+ addr = addr->next;
+ continue;
+ }
+
+ EM_SAFE_FREE(email_address);
+ email_address = g_strdup_printf("%s@%s", addr->mailbox ? addr->mailbox : "", addr->host ? addr->host : "");
+
+ EM_DEBUG_LOG(" addr->personal[%s]", addr->personal);
+ EM_DEBUG_LOG(" email_address[%s]", email_address);
+
+ is_searched = false;
+ EM_DEBUG_LOG(" >>>>> em_core_mail_get_contact_info - 10");
+
+ err = contacts_svc_find_contact_by(CTS_FIND_BY_EMAIL, email_address);
+ if (err > CTS_SUCCESS) {
+ contact_index = err;
+ if ((err = contacts_svc_get_contact(contact_index, &contact)) == CTS_SUCCESS) {
+ /* get contact name */
+ if (contacts_svc_struct_get_value(contact, CTS_CF_NAME_VALUE, &contact_name_value) == CTS_SUCCESS) { /* set contact display name name */
+ contact_info->contact_id = contact_index; /* NOTE : This is valid only if there is only one address. */
+ em_core_mail_get_display_name(contact_name_value, &contact_display_name_from_contact_info);
+
+ contact_display_name = contact_display_name_from_contact_info;
+
+
+ EM_DEBUG_LOG(">>> contact_index[%d]", contact_index);
+ EM_DEBUG_LOG(">>> contact_name[%s]", contact_display_name);
+
+ /* Make display name string */
+ if (contact_display_name != NULL) {
+ is_searched = true;
+
+ if (mail_id == 0 || (contact_name_len == 0)) { /* save only the first address information - 09-SEP-2010 */
+ contact_display_name_len = strlen(contact_display_name);
+ if (contact_name_len + contact_display_name_len >= contact_name_buffer_size) { /* re-alloc memory */
+ char *temp = contact_name;
+ contact_name_buffer_size += contact_name_buffer_size;
+ contact_name = (char *)calloc(1, contact_name_buffer_size);
+ if (contact_name == NULL) {
+ EM_DEBUG_EXCEPTION("Memory allocation failed.");
+ EM_SAFE_FREE(temp);
+ goto FINISH_OFF;
+ }
+ snprintf(contact_name, contact_name_buffer_size, "%s", temp);
+ EM_SAFE_FREE(temp);
+ }
+
+ /* snprintf(temp_string, sizeof(temp_string), "%c%d%c%s <%s>%c", start_text_ascii, contact_index, start_text_ascii, contact_display_name, email_address, end_text_ascii); */
+ if (addr->next == NULL) {
+ snprintf(temp_string, sizeof(temp_string), "\"%s\" <%s>", contact_display_name, email_address);
+ }
+ else {
+ snprintf(temp_string, sizeof(temp_string), "\"%s\" <%s>, ", contact_display_name, email_address);
+ }
+
+ contact_display_name_len = strlen(temp_string);
+ if (contact_name_len + contact_display_name_len >= contact_name_buffer_size) { /* re-alloc memory */
+ char *temp = contact_name;
+ contact_name_buffer_size += contact_name_buffer_size;
+ contact_name = (char *)calloc(1, contact_name_buffer_size);
+ if (contact_name == NULL) {
+ EM_DEBUG_EXCEPTION("Memory allocation failed.");
+ EM_SAFE_FREE(temp);
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+ snprintf(contact_name, contact_name_buffer_size, "%s", temp);
+ EM_SAFE_FREE(temp);
+ }
+ snprintf(contact_name + contact_name_len, contact_name_buffer_size - contact_name_len, "%s", temp_string);
+ contact_name_len += contact_display_name_len;
+ EM_DEBUG_LOG("new contact_name >>>>> %s ", contact_name);
+ }
+ }
+ }
+ else {
+ EM_DEBUG_LOG("contacts_svc_struct_get_value error[%d]", err);
+ }
+ }
+ else {
+ EM_DEBUG_LOG("contacts_svc_get_contact error [%d]", err);
+ }
+ }
+ else {
+ EM_DEBUG_LOG("contacts_svc_find_contact_by - Not found contact record(if err is 203) or error [%d]", err);
+ }
+
+ /* if contact doesn't exist, use alias or email address as display name */
+ if (addr->personal != NULL) {
+ /* "%2C" -> ',' */
+ tokens = g_strsplit(addr->personal, "%2C", -1);
+
+ EM_SAFE_FREE(addr->personal);
+
+ addr->personal = g_strjoinv(", ", tokens);
+
+ g_strfreev(tokens);
+ /* contact_info->contact_name = EM_SAFE_STRDUP(addr->personal); */
+ alias = addr->personal;
+ }
+ else {
+ /* alias = addr->mailbox ? addr->mailbox : ""; */
+ alias = email_address;
+ }
+ contact_info->alias = EM_SAFE_STRDUP(alias);
+
+ if (!is_searched) {
+ contact_display_name = alias;
+ contact_info->contact_id = -1; /* NOTE : This is valid only if there is only one address. */
+ contact_info->storage_type = -1;
+
+ /* Make display name string */
+ EM_DEBUG_LOG("contact_display_name : [%s]", contact_display_name);
+ EM_DEBUG_LOG("email_address : [%s]", email_address);
+
+ /* if mail_id is 0, return only contact info without saving contact info to DB */
+ if (mail_id == 0 || (contact_name_len == 0)) { /* save only the first address information - 09-SEP-2010 */
+ /* snprintf(temp_string, sizeof(temp_string), "%c%d%c%s <%s>%c", start_text_ascii, contact_index, start_text_ascii, contact_display_name, email_address, end_text_ascii); */
+ if (addr->next == NULL) {
+ snprintf(temp_string, sizeof(temp_string), "\"%s\" <%s>", contact_display_name, email_address);
+ }
+ else {
+ snprintf(temp_string, sizeof(temp_string), "\"%s\" <%s>, ", contact_display_name, email_address);
+ }
+ EM_DEBUG_LOG("temp_string[%s]", temp_string);
+
+ contact_display_name_len = strlen(temp_string);
+ if (contact_name_len + contact_display_name_len >= contact_name_buffer_size) { /* re-alloc memory */
+ char *temp = contact_name;
+ contact_name_buffer_size += contact_name_buffer_size;
+ contact_name = (char *)calloc(1, contact_name_buffer_size);
+ if (contact_name == NULL) {
+ EM_DEBUG_EXCEPTION("Memory allocation failed.");
+ EM_SAFE_FREE(temp);
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+ snprintf(contact_name, contact_name_buffer_size, "%s", temp);
+ EM_SAFE_FREE(temp);
+ }
+
+ snprintf(contact_name + contact_name_len, contact_name_buffer_size - contact_name_len, "%s", temp_string);
+ contact_name_len += contact_display_name_len;
+ EM_DEBUG_LOG("new contact_name >>>>> %s ", contact_name);
+ }
+ }
+
+ if (temp_emailaddr && email_address) {
+ if (mail_id == 0) { /* if mail_id is 0, return only contact info without saving contact info to DB */
+ /* snprintf(temp_emailaddr, 400, "%s", contact_info->email_address); */
+ EM_SAFE_STRCAT(temp_emailaddr, email_address);
+ if (addr->next != NULL)
+ EM_SAFE_STRCAT(temp_emailaddr, ", ");
+ EM_DEBUG_LOG(">>>> TEMP EMail Address [ %s ] ", temp_emailaddr);
+ }
+ else { /* save only the first address information - 09-SEP-2010 */
+ if (is_saved == 0) {
+ is_saved = 1;
+ /* snprintf(temp_emailaddr, 400, "%s", contact_info->email_address); */
+ EM_SAFE_STRCAT(temp_emailaddr, email_address);
+ /*
+ if (addr->next != NULL)
+ EM_SAFE_STRCAT(temp_emailaddr, ", ");
+ */
+ EM_DEBUG_LOG(">>>> TEMP EMail Address [ %s ] ", temp_emailaddr);
+ }
+ }
+ }
+
+ if (contact != NULL) {
+ contacts_svc_struct_free(contact);
+ contact = NULL;
+ }
+ EM_SAFE_FREE(contact_display_name_from_contact_info);
+ /* next address */
+ addr = addr->next;
+ } /* while (addr != NULL) */
+
+ if (temp_emailaddr) {
+ EM_DEBUG_LOG(">>>> TEMPEMAIL ADDR [ %s ] ", temp_emailaddr);
+ contact_info->email_address = temp_emailaddr;
+ temp_emailaddr = NULL;
+ }
+
+ if (contact_name != NULL) {
+ contact_info->contact_name = g_strdup(contact_name);
+ }
+ else {
+ contact_info->contact_name = g_strdup_printf("%c%d%c%s%c", start_text_ascii, 0, start_text_ascii, full_address, end_text_ascii);
+ contact_info->contact_id = -1;
+ }
+
+ ret = true;
+
+FINISH_OFF:
+
+ if (contact != NULL)
+ contacts_svc_struct_free(contact);
+ EM_SAFE_FREE(email_address);
+ EM_SAFE_FREE(address);
+ EM_SAFE_FREE(temp_emailaddr);
+ EM_SAFE_FREE(contact_name);
+ EM_SAFE_FREE(contact_display_name_from_contact_info);
+
+ if (err_code != NULL)
+ *err_code = err;
+
+ return ret;
+}
+
+int em_core_mail_free_contact_info(emf_mail_contact_info_t *contact_info, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("contact_info[%p], err_code[%p]", contact_info, err_code);
+
+ int ret = false;
+ int err = EMF_ERROR_NONE;
+
+ if (!contact_info) {
+ EM_DEBUG_EXCEPTION("contact_info[%p]", contact_info);
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ EM_SAFE_FREE(contact_info->contact_name);
+ EM_SAFE_FREE(contact_info->email_address);
+ EM_SAFE_FREE(contact_info->alias);
+
+ contact_info->storage_type = -1;
+ contact_info->contact_id = -1;
+
+ ret = true;
+
+FINISH_OFF:
+ if (err_code != NULL)
+ *err_code = err;
+ EM_DEBUG_FUNC_END();
+ return ret;
+}
+
+int em_core_mail_contact_sync(int mail_id, int *err_code)
+{
+ EM_PROFILE_BEGIN(emCoreMailContactSync);
+ EM_DEBUG_FUNC_BEGIN();
+
+ int ret = false;
+ int err = EMF_ERROR_NONE;
+
+ emf_mail_tbl_t *mail = NULL;
+
+ emf_mail_contact_info_t contact_info_from;
+ emf_mail_contact_info_t contact_info_to;
+ emf_mail_contact_info_t contact_info_cc;
+ emf_mail_contact_info_t contact_info_bcc;
+
+ EM_DEBUG_LOG("mail_id[%d], err_code[%p]", mail_id, err_code);
+
+ memset(&contact_info_from, 0x00, sizeof(emf_mail_contact_info_t));
+ memset(&contact_info_to, 0x00, sizeof(emf_mail_contact_info_t));
+ memset(&contact_info_cc, 0x00, sizeof(emf_mail_contact_info_t));
+ memset(&contact_info_bcc, 0x00, sizeof(emf_mail_contact_info_t));
+
+ if (!em_storage_get_mail_by_id(mail_id, &mail, true, &err) || !mail) {
+ EM_DEBUG_EXCEPTION("em_storage_get_mail_by_id failed [%d]", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+
+ if (mail->full_address_from != NULL) {
+ if (!em_core_mail_get_contact_info_with_update(&contact_info_from, mail->full_address_from, mail_id, &err)) {
+ EM_DEBUG_EXCEPTION("em_core_mail_get_contact_info failed [%d]", err);
+ }
+ }
+
+ if (mail->full_address_to != NULL) {
+ if (!em_core_mail_get_contact_info_with_update(&contact_info_to, mail->full_address_to, mail_id, &err)) {
+ EM_DEBUG_EXCEPTION("em_core_mail_get_contact_info failed [%d]", err);
+ }
+ }
+
+ if (mail->full_address_cc != NULL) {
+ if (!em_core_mail_get_contact_info_with_update(&contact_info_cc, mail->full_address_cc, mail_id, &err)) {
+ EM_DEBUG_EXCEPTION("em_core_mail_get_contact_info failed [%d]", err);
+ }
+ }
+
+ if (mail->full_address_bcc != NULL) {
+ if (!em_core_mail_get_contact_info_with_update(&contact_info_bcc, mail->full_address_bcc, mail_id, &err)) {
+ EM_DEBUG_EXCEPTION("em_core_mail_get_contact_info failed [%d]", err);
+ }
+ }
+
+ EM_SAFE_FREE(mail->email_address_sender);
+ mail->email_address_sender = contact_info_from.email_address;
+ contact_info_from.contact_name = NULL;
+ contact_info_from.email_address = NULL;
+ EM_SAFE_FREE(mail->email_address_recipient);
+ if (mail->full_address_to != NULL) {
+ mail->email_address_recipient = contact_info_to.email_address;
+ contact_info_to.contact_name = NULL;
+ contact_info_to.email_address = NULL;
+ }
+ else if (mail->full_address_cc != NULL) {
+ mail->email_address_recipient = contact_info_cc.email_address;
+ contact_info_cc.contact_name = NULL;
+ contact_info_cc.email_address = NULL;
+ }
+ else if (mail->full_address_bcc != NULL) {
+ mail->email_address_recipient = contact_info_bcc.email_address;
+ contact_info_bcc.contact_name = NULL;
+ contact_info_bcc.email_address = NULL;
+ }
+
+ /* Update DB */
+ if (!em_storage_change_mail_field(mail_id, UPDATE_ALL_CONTACT_INFO, mail, false, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_change_mail_field failed [%d]", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+
+ ret = true;
+
+FINISH_OFF:
+ if (mail != NULL)
+ em_storage_free_mail(&mail, 1, NULL);
+
+ em_core_mail_free_contact_info(&contact_info_from, NULL);
+ em_core_mail_free_contact_info(&contact_info_to, NULL);
+ em_core_mail_free_contact_info(&contact_info_cc, NULL);
+ em_core_mail_free_contact_info(&contact_info_bcc, NULL);
+
+ if (err_code != NULL)
+ *err_code = err;
+
+ EM_PROFILE_END(emCoreMailContactSync);
+ return ret;
+}
+
+/* 1. parsing : alias and address */
+/* 2. sync with contact */
+/* 3. make glist of address info */
+static int em_core_sync_address_info(emf_address_type_t address_type, char *full_address, GList **address_info_list, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("address type[%d], address_info_list[%p], full_address[%p]", address_type, address_info_list, full_address);
+
+ int ret = false;
+ int error = EMF_ERROR_NONE;
+ int contact_index = -1;
+ int is_search = false;
+ char *alias = NULL;
+ char *address = NULL;
+ char *contact_display_name_from_contact_info = NULL;
+ char email_address[MAX_EMAIL_ADDRESS_LENGTH];
+ emf_address_info_t *p_address_info = NULL;
+ ADDRESS *addr = NULL;
+ CTSstruct *contact = NULL;
+ CTSvalue *contact_name_value = NULL;
+
+ if (full_address == NULL || address_info_list == NULL) {
+ EM_DEBUG_EXCEPTION("Invalid param : full_address or address_info_list is NULL");
+ error = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ /* Parsing */
+ address = EM_SAFE_STRDUP(full_address);
+
+ /* ',' -> "%2C" */
+ gchar **tokens = g_strsplit(address, ", ", -1);
+ char *p = g_strjoinv("%2C", tokens);
+ int i = 0;
+
+ g_strfreev(tokens);
+
+ /* ';' -> ',' */
+ while (p && p[i] != '\0') {
+ if (p[i] == ';')
+ p[i] = ',';
+ i++;
+ }
+
+ rfc822_parse_adrlist(&addr, p, NULL);
+
+ EM_SAFE_FREE(p);
+
+ if (!addr) {
+ EM_DEBUG_EXCEPTION("rfc822_parse_adrlist failed...");
+ error = EM_STORAGE_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ /* Get a contact name */
+ while (addr != NULL) {
+ if (addr->mailbox && addr->host) {
+ if (!strcmp(addr->mailbox , "UNEXPECTED_DATA_AFTER_ADDRESS") || !strcmp(addr->mailbox , "INVALID_ADDRESS") || !strcmp(addr->host , ".SYNTAX-ERROR."))
+ {
+ EM_DEBUG_LOG("Invalid address ");
+ addr = addr->next;
+ continue;
+ }
+ }
+ else {
+ EM_DEBUG_LOG("Error in parsing..! ");
+ addr = addr->next;
+ continue;
+ }
+
+ /* set display name */
+ /* 1) contact name */
+ /* 2) alias (if a alias in an original mail doesn't exist, this field is set with email address */
+ /* 3) email address */
+
+ if (!(p_address_info = (emf_address_info_t *)malloc(sizeof(emf_address_info_t)))) {
+ EM_DEBUG_EXCEPTION("malloc failed...");
+ error = EM_STORAGE_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+ memset(p_address_info, 0x00, sizeof(emf_address_info_t));
+
+ SNPRINTF(email_address, MAX_EMAIL_ADDRESS_LENGTH, "%s@%s", addr->mailbox ? addr->mailbox : "", addr->host ? addr->host : "");
+
+ EM_DEBUG_LOG("Search a contact : address[%s]", email_address);
+
+ is_search = false;
+
+ error = contacts_svc_find_contact_by(CTS_FIND_BY_EMAIL, email_address);
+ if (error > CTS_SUCCESS) {
+ contact_index = error;
+ if ((error = contacts_svc_get_contact(contact_index, &contact)) == CTS_SUCCESS) {
+ /* get contact name */
+ if (contacts_svc_struct_get_value(contact, CTS_CF_NAME_VALUE, &contact_name_value) == CTS_SUCCESS) { /* set contact display name name */
+ em_core_mail_get_display_name(contact_name_value, &contact_display_name_from_contact_info);
+ EM_DEBUG_LOG(">>> contact index[%d]", contact_index);
+ EM_DEBUG_LOG(">>> contact display name[%s]", contact_display_name_from_contact_info);
+
+ is_search = true;
+ }
+ else
+ EM_DEBUG_EXCEPTION("contacts_svc_struct_get_value error[%d]", error);
+ }
+ else
+ EM_DEBUG_EXCEPTION("contacts_svc_get_contact error [%d]", error);
+ }
+ else
+ EM_DEBUG_EXCEPTION("contacts_svc_find_contact_by - Not found contact record(if err is -203) or error [%d]", error);
+
+ if (is_search == true) {
+ p_address_info->contact_id = contact_index;
+ p_address_info->storage_type = -1;
+ p_address_info->display_name = contact_display_name_from_contact_info;
+ EM_DEBUG_LOG("display_name from contact[%s]", p_address_info->display_name);
+ }
+ else {
+ /* if contact doesn't exist, use alias or email address as display name */
+ if (addr->personal != NULL) {
+ /* "%2C" -> ',' */
+ tokens = g_strsplit(addr->personal, "%2C", -1);
+
+ EM_SAFE_FREE(addr->personal);
+
+ addr->personal = g_strjoinv(", ", tokens);
+
+ g_strfreev(tokens);
+ alias = addr->personal;
+ }
+ else {
+ alias = NULL;
+ }
+ p_address_info->contact_id = -1;
+ p_address_info->storage_type = -1;
+ /* Use an alias or an email address as a display name */
+ if (alias == NULL)
+ p_address_info->display_name = EM_SAFE_STRDUP(email_address);
+ else
+ p_address_info->display_name = EM_SAFE_STRDUP(alias);
+
+ EM_DEBUG_LOG("display_name from email [%s]", p_address_info->display_name);
+ }
+
+ p_address_info->address = EM_SAFE_STRDUP(email_address);
+ p_address_info->address_type = address_type;
+
+ EM_DEBUG_LOG("email address[%s]", p_address_info->address);
+
+ *address_info_list = g_list_append(*address_info_list, p_address_info);
+ p_address_info = NULL;
+
+ EM_DEBUG_LOG("after append");
+
+ alias = NULL;
+ if (contact != NULL) {
+ contacts_svc_struct_free(contact);
+ contact = NULL;
+ }
+
+ EM_DEBUG_LOG("next address[%p]", addr->next);
+
+ /* next address */
+ addr = addr->next;
+ }
+
+ ret = true;
+
+FINISH_OFF:
+ if (contact != NULL)
+ contacts_svc_struct_free(contact);
+
+ EM_SAFE_FREE(address);
+
+ if (err_code != NULL)
+ *err_code = error;
+ EM_DEBUG_FUNC_END();
+ return ret;
+}
+
+static gint address_compare(gconstpointer a, gconstpointer b)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ emf_sender_list_t *recipients_list1 = (emf_sender_list_t *)a;
+ emf_sender_list_t *recipients_list2 = (emf_sender_list_t *)b;
+
+ EM_DEBUG_FUNC_END();
+ return strcmp(recipients_list1->address, recipients_list2->address);
+}
+
+EXPORT_API GList *em_core_get_recipients_list(GList *old_recipients_list, char *full_address, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ int i = 0, err;
+ int contact_index = -1;
+ int is_search = false;
+
+ char *address = NULL;
+ char email_address[MAX_EMAIL_ADDRESS_LENGTH];
+ char *display_name = NULL;
+ char *alias = NULL;
+ ADDRESS *addr = NULL;
+ CTSstruct *contact = NULL;
+ CTSvalue *contact_name_value = NULL;
+ GList *new_recipients_list = old_recipients_list;
+ GList *recipients_list;
+
+ emf_sender_list_t *temp_recipients_list = NULL;
+ emf_sender_list_t *old_recipients_list_t = NULL;
+
+ if (full_address == NULL || strlen(full_address) == 0) {
+ EM_DEBUG_EXCEPTION("Invalid param : full_address NULL or empty");
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ address = EM_SAFE_STRDUP(full_address);
+
+ gchar **tokens = g_strsplit(address, ", ", -1);
+ char *p = g_strjoinv("%2C", tokens);
+
+ g_strfreev(tokens);
+
+ while (p && p[i] != '\0') {
+ if (p[i] == ';')
+ p[i] = ',';
+ i++;
+ }
+
+ rfc822_parse_adrlist(&addr, p, NULL);
+
+ EM_SAFE_FREE(p);
+
+ if (!addr) {
+ EM_DEBUG_EXCEPTION("rfc822_parse_adrlist failed...");
+ err = EM_STORAGE_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ while (addr != NULL) {
+ if (addr->mailbox && addr->host) {
+ if (!strcmp(addr->mailbox , "UNEXPECTED_DATA_AFTER_ADDRESS") || !strcmp(addr->mailbox , "INVALID_ADDRESS") || !strcmp(addr->host , ".SYNTAX-ERROR.")) {
+ EM_DEBUG_LOG("Invalid address ");
+ addr = addr->next;
+ continue;
+ }
+ } else {
+ EM_DEBUG_LOG("Error in parsing..! ");
+ addr = addr->next;
+ continue;
+ }
+
+ temp_recipients_list = g_new0(emf_sender_list_t, 1);
+
+ SNPRINTF(email_address, MAX_EMAIL_ADDRESS_LENGTH, "%s@%s", addr->mailbox ? addr->mailbox : "", addr->host ? addr->host : "");
+
+ EM_DEBUG_LOG("Search a contact : address[%s]", email_address);
+
+ err = contacts_svc_find_contact_by(CTS_FIND_BY_EMAIL, email_address);
+ if (err > CTS_SUCCESS) {
+ contact_index = err;
+ if ((err = contacts_svc_get_contact(contact_index, &contact)) == CTS_SUCCESS) {
+ if (contacts_svc_struct_get_value(contact, CTS_CF_NAME_VALUE, &contact_name_value) == CTS_SUCCESS) {
+ em_core_mail_get_display_name(contact_name_value, &display_name);
+ EM_DEBUG_LOG(">>> contact index[%d]", contact_index);
+ EM_DEBUG_LOG(">>> contact display name[%s]", display_name);
+
+ is_search = true;
+ } else {
+ EM_DEBUG_LOG("contacts_svc_struct_get_value error[%d]", err);
+ }
+ } else {
+ EM_DEBUG_LOG("contacts_svc_get_contact error [%d]", err);
+ }
+ } else {
+ EM_DEBUG_LOG("contacts_svc_find_contact_by - Not found contact record(if err is -203) or error [%d]", err);
+ }
+
+ if (is_search) {
+ temp_recipients_list->display_name = display_name;
+ EM_DEBUG_LOG("display_name from contact[%s]", temp_recipients_list->display_name);
+ } else {
+ if (addr->personal != NULL) {
+ tokens = g_strsplit(addr->personal, "%2C", -1);
+ EM_SAFE_FREE(addr->personal);
+ addr->personal = g_strjoinv(", ", tokens);
+ g_strfreev(tokens);
+ alias = addr->personal;
+ } else {
+ alias = NULL;
+ }
+
+ if (alias == NULL)
+ temp_recipients_list->display_name = EM_SAFE_STRDUP(email_address);
+ else
+ temp_recipients_list->display_name = EM_SAFE_STRDUP(alias);
+
+ EM_DEBUG_LOG("display_name from contact[%s]", temp_recipients_list->display_name);
+ }
+
+ temp_recipients_list->address = EM_SAFE_STRDUP(email_address);
+ EM_DEBUG_LOG("email address[%s]", temp_recipients_list->address);
+
+ EM_SAFE_FREE(display_name);
+ if (contact != NULL) {
+ contacts_svc_struct_free(contact);
+ contact = NULL;
+ }
+ EM_DEBUG_LOG("next address[%p]", addr->next);
+
+ recipients_list = g_list_first(new_recipients_list);
+ while (recipients_list != NULL) {
+ old_recipients_list_t = (emf_sender_list_t *)recipients_list->data;
+ if (!strcmp(old_recipients_list_t->address, temp_recipients_list->address)) {
+ old_recipients_list_t->total_count = old_recipients_list_t->total_count + 1;
+ if (temp_recipients_list != NULL)
+ g_free(temp_recipients_list);
+
+ goto FINISH_OFF;
+ }
+ recipients_list = g_list_next(recipients_list);
+ }
+
+ new_recipients_list = g_list_insert_sorted(new_recipients_list, temp_recipients_list, address_compare);
+
+ temp_recipients_list = NULL;
+
+ alias = NULL;
+ if (contact != NULL) {
+ contacts_svc_struct_free(contact);
+ contact = NULL;
+ }
+ addr = addr->next;
+ }
+
+FINISH_OFF:
+
+ if (contact != NULL)
+ contacts_svc_struct_free(contact);
+
+ EM_SAFE_FREE(address);
+
+ if (err_code != NULL)
+ *err_code = err;
+
+ EM_DEBUG_FUNC_END();
+ return new_recipients_list;
+}
+
+EXPORT_API int em_core_mail_get_address_info_list(int mail_id, emf_address_info_list_t **address_info_list, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("mail_id[%d], address_info_list[%p]", mail_id, address_info_list);
+
+ int ret = false, err = EMF_ERROR_NONE;
+ int failed = true;
+ int contact_error;
+
+ emf_mail_tbl_t *mail = NULL;
+ emf_address_info_list_t *p_address_info_list = NULL;
+
+ if (mail_id <= 0 || !address_info_list) {
+ EM_DEBUG_EXCEPTION("mail_id[%d], address_info_list[%p]", mail_id, address_info_list);
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ /* get mail from mail table */
+ if (!em_storage_get_mail_by_id(mail_id, &mail, true, &err) || !mail) {
+ EM_DEBUG_EXCEPTION("em_storage_get_mail_by_id failed [%d]", err);
+
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+
+ if (!(p_address_info_list = (emf_address_info_list_t *)malloc(sizeof(emf_address_info_list_t)))) {
+ EM_DEBUG_EXCEPTION("malloc failed...");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+ memset(p_address_info_list, 0x00, sizeof(emf_address_info_list_t));
+
+ if ((contact_error = contacts_svc_connect()) == CTS_SUCCESS) {
+ EM_DEBUG_LOG("Open Contact Service Success");
+ }
+ else {
+ EM_DEBUG_EXCEPTION("contact_db_service_connect failed [%d]", contact_error);
+ err = EMF_ERROR_DB_FAILURE;
+ goto FINISH_OFF;
+ }
+
+ if (em_core_sync_address_info(EMF_ADDRESS_TYPE_FROM, mail->full_address_from, &p_address_info_list->from, &err))
+ failed = false;
+ if (em_core_sync_address_info(EMF_ADDRESS_TYPE_TO, mail->full_address_to, &p_address_info_list->to, &err))
+ failed = false;
+ if (em_core_sync_address_info(EMF_ADDRESS_TYPE_CC, mail->full_address_cc, &p_address_info_list->cc, &err))
+ failed = false;
+ if (em_core_sync_address_info(EMF_ADDRESS_TYPE_BCC, mail->full_address_bcc, &p_address_info_list->bcc, &err))
+ failed = false;
+
+ if ((contact_error = contacts_svc_disconnect()) == CTS_SUCCESS)
+ EM_DEBUG_LOG("Close Contact Service Success");
+ else
+ EM_DEBUG_EXCEPTION("Close Contact Service Fail [%d]", contact_error);
+
+ if (failed == false)
+ ret = true;
+
+FINISH_OFF:
+ if (ret == true)
+ *address_info_list = p_address_info_list;
+ else if (p_address_info_list != NULL)
+ em_storage_free_address_info_list(&p_address_info_list);
+
+ if (!mail)
+ em_storage_free_mail(&mail, 1, NULL);
+
+ if (err_code != NULL)
+ *err_code = err;
+
+ EM_DEBUG_FUNC_END();
+ return ret;
+}
+
+
+
+/* description
+ * get mail header from local mailbox
+ * arguments
+ * mailbox : message no
+ * header : buffer to hold header information
+ * return
+ * succeed : 1
+ * fail : 0
+ */
+int em_core_mail_get_info(int mail_id, emf_mail_info_t **info, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("mail_id[%d], info[%p], err_code[%p]", mail_id, info, err_code);
+
+ int ret = false;
+ int error = EMF_ERROR_NONE;
+
+ emf_mail_info_t *temp_mail_info = NULL;
+ emf_mail_tbl_t *mail = NULL;
+
+ if (!mail_id || !info) {
+ EM_DEBUG_EXCEPTION("mail_id[%d], info[%p]", mail_id, info);
+ error = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ /* get mail from mail table */
+ if (!em_storage_get_mail_by_id(mail_id, &mail, true, &error) || !mail) {
+ EM_DEBUG_EXCEPTION("em_storage_get_mail_by_id failed [%d]", error);
+ error = em_storage_get_emf_error_from_em_storage_error(error);
+ goto FINISH_OFF;
+ }
+
+ if (!em_core_mail_get_info_from_mail_tbl(&temp_mail_info, mail, &error)) {
+ EM_DEBUG_EXCEPTION("em_core_mail_get_info_from_mail_tbl failed [%d]", error);
+ goto FINISH_OFF;
+ }
+
+ ret = true;
+
+FINISH_OFF:
+ if (ret == true)
+ *info = temp_mail_info;
+ else if (temp_mail_info != NULL)
+ em_core_mail_info_free(&temp_mail_info, 1, NULL);
+
+ if (mail != NULL)
+ em_storage_free_mail(&mail, 1, NULL);
+
+ if (err_code != NULL)
+ *err_code = error;
+ EM_DEBUG_FUNC_END();
+ return ret;
+}
+
+EXPORT_API int em_core_mail_get_info_from_mail_tbl(emf_mail_info_t **pp_mail_info, emf_mail_tbl_t *mail_tbl_data , int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("pp_mail_info[%p], mail_tbl_data[%p], err_code[%p]", pp_mail_info, mail_tbl_data, err_code);
+
+ int ret = false;
+ int error = EMF_ERROR_NONE;
+ emf_mail_info_t *p = NULL;
+
+ if (!pp_mail_info || !mail_tbl_data) {
+ EM_DEBUG_EXCEPTION("pp_mail_info[%p], mail_tbl_data[%p]", pp_mail_info, mail_tbl_data);
+ error = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ /* memory allocate */
+ if (!(p = em_core_malloc(sizeof(emf_mail_info_t)))) {
+ EM_DEBUG_EXCEPTION("em_core_malloc failed...");
+ error = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ p->account_id = mail_tbl_data->account_id;
+ p->uid = mail_tbl_data->mail_id;
+ p->sid = EM_SAFE_STRDUP(mail_tbl_data->server_mail_id);
+
+ /* mail_tbl_data download status */
+ if (mail_tbl_data->server_mail_status == 0 || mail_tbl_data->body_download_status == EMF_BODY_DOWNLOAD_STATUS_FULLY_DOWNLOADED) {
+ p->body_downloaded = EMF_BODY_DOWNLOAD_STATUS_FULLY_DOWNLOADED;
+ p->extra_flags.text_download_yn = EMF_BODY_DOWNLOAD_STATUS_FULLY_DOWNLOADED;
+ }
+#ifdef __FEATURE_PARTIAL_BODY_DOWNLOAD__
+ else if (mail_tbl_data->body_download_status == EMF_BODY_DOWNLOAD_STATUS_PARTIALLY_DOWNLOADED) {
+ p->body_downloaded = EMF_BODY_DOWNLOAD_STATUS_PARTIALLY_DOWNLOADED;
+ p->extra_flags.text_download_yn = EMF_BODY_DOWNLOAD_STATUS_PARTIALLY_DOWNLOADED;
+ }
+#endif
+ else {
+ p->body_downloaded = EMF_BODY_DOWNLOAD_STATUS_NONE;
+ p->extra_flags.text_download_yn = EMF_BODY_DOWNLOAD_STATUS_NONE;
+ }
+
+ /* mail_tbl_data rfc822.size */
+ p->rfc822_size = mail_tbl_data->mail_size;
+
+ /* mail_tbl_data flags */
+ if (!em_convert_mail_tbl_to_mail_flag(mail_tbl_data, &p->flags, &error)) {
+ EM_DEBUG_EXCEPTION("em_convert_mail_tbl_to_mail_flag failed [%d]", error);
+ goto FINISH_OFF;
+ }
+
+ /* mail_tbl_data extra flag */
+ p->extra_flags.lock = mail_tbl_data->lock_status;
+ p->extra_flags.priority = mail_tbl_data->priority;
+ p->extra_flags.report = mail_tbl_data->report_status;
+ p->extra_flags.status = mail_tbl_data->save_status;
+ p->flags.sticky = mail_tbl_data->lock_status;
+ p->extra_flags.drm = mail_tbl_data->DRM_status;
+ p->is_meeting_request = mail_tbl_data->meeting_request_status;
+ ret = true;
+
+FINISH_OFF:
+ if (ret == true)
+ *pp_mail_info = p;
+ else if (p != NULL)
+ em_core_mail_info_free(&p, 1, NULL);
+
+ if (err_code != NULL)
+ *err_code = error;
+ EM_DEBUG_FUNC_END();
+ return ret;
+}
+
+/* description
+ * get a mail body from local mailbox
+ * mail body contain body text and attachment list.
+ * arguments
+ * mailbox : mail box
+ * msgno : mail no
+ * mail : [out] double pointer to hold mail data. (mail info, mail header, mail body text and attachment list)
+ * return
+ * succeed : 1
+ * fail : 0
+ */
+EXPORT_API int em_core_mail_get_mail(int mail_id, emf_mail_t **mail, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("mail_id[%d], mail[%p], err_code[%p]", mail_id, mail, err_code);
+
+ int ret = false;
+ int error = EMF_ERROR_NONE;
+
+ emf_mail_t *p = NULL;
+
+ if (!mail_id || !mail) {
+ EM_DEBUG_EXCEPTION("mail_id[%d], mail[%p]", mail_id, mail);
+ error = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ /* memory allocate */
+ if (!(p = em_core_malloc(sizeof(emf_mail_t)))) {
+ EM_DEBUG_EXCEPTION("malloc falied...");
+ error = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+ memset(p, 0x00, sizeof(emf_mail_t));
+
+ /* get mail info */
+ if (!em_core_mail_get_info(mail_id, &p->info, &error)) {
+ EM_DEBUG_EXCEPTION("em_core_mail_get_info failed [%d]", error);
+ goto FINISH_OFF;
+ }
+
+ /* get mail header */
+ if (!em_core_mail_get_header(mail_id, &p->head, &error)) {
+ EM_DEBUG_EXCEPTION("em_core_mail_get_header failed [%d]", error);
+ goto FINISH_OFF;
+ }
+
+ /* if body downloaded, get mail body */
+ EM_DEBUG_LOG("p->info->body_downloaded [%d]", p->info->body_downloaded);
+
+ /* if (p->info->body_downloaded) { */
+ if (!em_core_mail_get_body(mail_id, &p->body, &error)) {
+ EM_DEBUG_EXCEPTION("em_core_mail_get_body failed [%d]", error);
+ goto FINISH_OFF;
+ }
+ /* } */
+
+ ret = true;
+
+FINISH_OFF:
+ if (ret == true)
+ *mail = p;
+ else if (p != NULL)
+ em_core_mail_free(&p, 1, NULL);
+
+ if (err_code != NULL)
+ *err_code = error;
+ EM_DEBUG_FUNC_END();
+ return ret;
+}
+
+/* description
+ * get a mail data
+ * arguments
+ * input_mail_id : [in] mail id
+ * output_mail_data : [out] double pointer to hold mail data.
+ * return
+ * succeed : EMF_ERROR_NONE
+ * fail : error code
+ */
+EXPORT_API int em_core_get_mail_data(int input_mail_id, emf_mail_data_t **output_mail_data)
+{
+ EM_DEBUG_FUNC_BEGIN("input_mail_id[%d], output_mail_data[%p]", input_mail_id, output_mail_data);
+
+ int error = EMF_ERROR_NONE;
+ int result_mail_count = 0;
+ char conditional_clause_string[QUERY_SIZE] = { 0, };
+ emf_mail_tbl_t *result_mail_tbl = NULL;
+
+ if (input_mail_id == 0 || !output_mail_data) {
+ EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
+ error = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ SNPRINTF(conditional_clause_string, QUERY_SIZE, "WHERE mail_id = %d", input_mail_id);
+
+ if(!em_storage_query_mail_tbl(conditional_clause_string, true, &result_mail_tbl, &result_mail_count, &error)) {
+ EM_DEBUG_EXCEPTION("em_storage_query_mail_tbl falied [%d]", error);
+ goto FINISH_OFF;
+ }
+
+ if(!em_convert_mail_tbl_to_mail_data(result_mail_tbl, 1, output_mail_data, &error)) {
+ EM_DEBUG_EXCEPTION("em_convert_mail_tbl_to_mail_data falied [%d]", error);
+ goto FINISH_OFF;
+ }
+
+FINISH_OFF:
+ if (result_mail_tbl)
+ em_storage_free_mail(&result_mail_tbl, result_mail_count, NULL);
+
+ EM_DEBUG_FUNC_END("error [%d]", error);
+ return error;
+}
+
+
+/* internal function */
+void
+em_core_free_body_sharep(void **p)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ EM_SAFE_FREE(*p);
+ EM_DEBUG_FUNC_END();
+}
+
+/* description
+ * get mail rfc822 size
+ * arguments
+ * mailbox : mailbox name
+ * msgno : mail sequence
+ * size : out body size
+ * return
+ * succeed : 1
+ * fail : 0
+ */
+EXPORT_API int em_core_mail_get_size(/*emf_mailbox_t *mailbox, */ int mail_id, int *mail_size, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("mail_id[%d], mail_size[%p], err_code[%p]", mail_id, mail_size, err_code);
+
+ int ret = false;
+ int err = EMF_ERROR_NONE;
+ emf_mail_tbl_t *mail = NULL;
+
+ if (mail_size == NULL) {
+ EM_DEBUG_EXCEPTION("mail_id[%d], mail_size[%p]", mail_id, mail_size);
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ /* get mail from mail table */
+ if (!em_storage_get_mail_by_id(mail_id, &mail, true, &err) || !mail) {
+ EM_DEBUG_EXCEPTION("em_storage_get_mail failed [%d]", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+
+ *mail_size = mail->mail_size;
+
+ ret = true;
+
+FINISH_OFF:
+ if (mail != NULL)
+ em_storage_free_mail(&mail, 1, NULL);
+
+ if (err_code != NULL)
+ *err_code = err;
+ EM_DEBUG_FUNC_END();
+ return ret;
+}
+
+/**
+ * description
+ * get mail body from local mailbox.
+ * if no body in local mailbox, return error.
+ * arguments
+ * mailbox : server mailbox
+ * mail_id : mai id to be downloaded
+ * callback : function callback. if NULL, ignored.
+ * return
+ * succeed : 1
+ * fail : 0
+ */
+EXPORT_API int em_core_mail_get_body(int mail_id, emf_mail_body_t **body, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("mail_id[%d], body[%p], err_code[%p]", mail_id, body, err_code);
+
+ int ret = false;
+ int err = EMF_ERROR_NONE;
+ int count = EMF_ATTACHMENT_MAX_COUNT;
+ emf_mail_body_t *p_body = NULL;
+ emf_mail_tbl_t *mail = NULL;
+ emf_mail_attachment_tbl_t *attachment_tbl_list = NULL;
+
+ /* get mail from mail table */
+ if (!em_storage_get_mail_by_id(mail_id, &mail, true, &err) || !mail) {
+ EM_DEBUG_EXCEPTION("em_storage_get_mail_by_id failed [%d]", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+
+ EM_DEBUG_LOG("file_path_plain [%s]", mail->file_path_plain);
+
+ /*
+ if (!mail->body_download_status) {
+ EM_DEBUG_EXCEPTION("This mail body is not received.");
+ *body = NULL;
+ em_storage_free_mail(&mail, 1, NULL);
+ return true;
+ }
+ */
+
+ em_core_mail_get_body_from_mail_tbl(&p_body, mail, NULL);
+
+ /* retrieve attachment info */
+ if ( (err = em_storage_get_attachment_list(mail_id, true, &attachment_tbl_list, &count)) != EM_STORAGE_ERROR_NONE ){
+ EM_DEBUG_EXCEPTION("em_storage_get_attachment_list failed [%d]", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+ else if (count) {
+ emf_attachment_info_t **atch = &p_body->attachment;
+ int i;
+
+ EM_DEBUG_LOG("attchment count %d", count);
+ for (i = 0; i < count; i++) {
+ *atch = em_core_malloc(sizeof(emf_attachment_info_t));
+ if (!(*atch)) {
+ EM_DEBUG_EXCEPTION("malloc failed...");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+ em_core_mail_fill_attachment(*atch, &attachment_tbl_list[i]);
+ atch = &(*atch)->next;
+ }
+ }
+
+ p_body->attachment_num = count;
+
+ ret = true;
+
+FINISH_OFF:
+ if (ret == true)
+ *body = p_body;
+ else if (p_body != NULL)
+ em_core_mail_body_free(&p_body, 1, NULL);
+
+ if (attachment_tbl_list != NULL)
+ em_storage_free_attachment(&attachment_tbl_list, count, NULL);
+
+ if (mail != NULL)
+ em_storage_free_mail(&mail, 1, NULL);
+
+ if (err_code != NULL)
+ *err_code = err;
+ EM_DEBUG_FUNC_END();
+ return ret;
+}
+
+EXPORT_API int em_core_mail_get_body_from_mail_tbl(emf_mail_body_t **p_body, emf_mail_tbl_t *mail, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int ret = 0, err = EMF_ERROR_NONE;
+ emf_mail_body_t *temp_body = NULL;
+
+ if (!p_body || !mail) {
+ EM_DEBUG_EXCEPTION("Invalid parameter");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ temp_body = em_core_malloc(sizeof(emf_mail_body_t));
+
+ if (!temp_body) {
+ EM_DEBUG_EXCEPTION("em_core_malloc failed...");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ temp_body->plain = EM_SAFE_STRDUP(mail->file_path_plain);
+ temp_body->html = EM_SAFE_STRDUP(mail->file_path_html);
+
+ if (mail->file_path_plain && mail->file_path_plain[0] != NULL_CHAR)
+ temp_body->plain_charset = g_path_get_basename(mail->file_path_plain);
+ else
+ temp_body->plain_charset = NULL;
+
+ EM_DEBUG_LOG("temp_body->plain_charset [%s]", temp_body->plain_charset);
+
+ *p_body = temp_body;
+
+ ret = 1;
+FINISH_OFF:
+
+ if (err_code)
+ *err_code = err;
+
+ EM_DEBUG_FUNC_END();
+ return ret;
+}
+
+static void
+em_core_mail_fill_attachment(emf_attachment_info_t *atch , emf_mail_attachment_tbl_t *attachment_tbl)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ if (!atch || !attachment_tbl)
+ return;
+
+ atch->attachment_id = attachment_tbl->attachment_id;
+ atch->size = attachment_tbl->attachment_size;
+ atch->name = EM_SAFE_STRDUP(attachment_tbl->attachment_name);
+ atch->downloaded = attachment_tbl->file_yn ? 1 : 0;
+ atch->savename = EM_SAFE_STRDUP(attachment_tbl->attachment_path);
+ atch->drm = attachment_tbl->flag2;
+ atch->inline_content = attachment_tbl->flag3;
+
+ EM_DEBUG_FUNC_END();
+}
+
+int em_core_check_drm(emf_mail_attachment_tbl_t *attachment)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int ret = 0;
+#ifdef __FEATURE_DRM__
+ drm_dcf_info_t fileInfo;
+
+ if (attachment == NULL)
+ return ret;
+
+ if (drm_svc_is_drm_file (attachment->attachment_path)) {
+ if (drm_svc_get_dcf_file_info (attachment->attachment_path, &fileInfo) == DRM_RESULT_SUCCESS) {
+ attachment->flag2 = 0;
+ EM_DEBUG_LOG ("fileInfo is [%d]", fileInfo.method);
+ if (fileInfo.method != DRM_METHOD_UNDEFINED) {
+ attachment->flag2 = fileInfo.method;
+ ret = 1;
+ }
+ }
+ }
+ else {
+ EM_DEBUG_LOG("not DRM file %s", attachment->attachment_path);
+ attachment->flag2 = 0;
+ ret = 0;
+ }
+#endif
+ EM_DEBUG_FUNC_END();
+ return ret;
+}
+
+
+/* description
+ * get mail attachment from local mailbox
+ * arguments
+ * mailbox : server mailbox
+ * mail_id : mai id to own attachment
+ * attachment : the number string to be downloaded
+ * callback : function callback. if NULL, ignored.
+ * return
+ * succeed : 1
+ * fail : 0
+ */
+EXPORT_API int em_core_mail_get_attachment(int mail_id, char *attachment_id_string, emf_attachment_info_t **attachment, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("mail_id[%d], attachment_id_string[%p], attachment[%p], err_code[%p]", mail_id, attachment_id_string, attachment, err_code);
+
+ if (attachment == NULL || attachment_id_string == NULL) {
+ EM_DEBUG_EXCEPTION("mail_id[%d], attachment_id_string[%p], attachment[%p]", mail_id, attachment_id_string, attachment);
+ if (err_code != NULL)
+ *err_code = EMF_ERROR_INVALID_PARAM;
+ return false;
+ }
+
+ int ret = false;
+ int err = EMF_ERROR_NONE;
+ emf_mail_attachment_tbl_t *attachment_tbl = NULL;
+ int attachment_id = atoi(attachment_id_string);
+
+ /* get attachment from attachment tbl */
+ if (!em_storage_get_attachment(mail_id, attachment_id, &attachment_tbl, true, &err) || !attachment_tbl) {
+ EM_DEBUG_EXCEPTION("em_storage_get_attachment failed [%d]", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+
+ *attachment = em_core_malloc(sizeof(emf_attachment_info_t));
+ if (!*attachment) {
+ EM_DEBUG_EXCEPTION("malloc failed...");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ (*attachment)->attachment_id = attachment_id;
+ (*attachment)->name = attachment_tbl->attachment_name; attachment_tbl->attachment_name = NULL;
+ (*attachment)->size = attachment_tbl->attachment_size;
+ (*attachment)->downloaded = attachment_tbl->file_yn;
+ (*attachment)->savename = attachment_tbl->attachment_path; attachment_tbl->attachment_path = NULL;
+ (*attachment)->drm = attachment_tbl->flag2;
+ (*attachment)->inline_content = attachment_tbl->flag3;
+ (*attachment)->next = NULL;
+
+ ret = true;
+
+FINISH_OFF:
+ if (attachment_tbl)
+ em_storage_free_attachment(&attachment_tbl, 1, NULL);
+
+ if (err_code)
+ *err_code = err;
+
+ return ret;
+}
+
+/* description
+ * get mail attachment
+ * arguments
+ * input_mail_id : mail id to own attachment
+ * output_attachment_data : result attahchment data
+ * output_attachment_count : result attahchment count
+ * return
+ * succeed : EMF_ERROR_NONE
+ * fail : error code
+ */
+EXPORT_API int em_core_get_attachment_data_list(int input_mail_id, emf_attachment_data_t **output_attachment_data, int *output_attachment_count)
+{
+ EM_DEBUG_FUNC_BEGIN("input_mail_id[%d], output_attachment_data[%p], output_attachment_count[%p]", input_mail_id, output_attachment_data, output_attachment_count);
+
+ if (input_mail_id == 0|| output_attachment_data == NULL || output_attachment_count == NULL) {
+ EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
+ return EMF_ERROR_INVALID_PARAM;
+ }
+
+ int i = 0;
+ int err = EMF_ERROR_NONE;
+ int attachment_tbl_count = 0;
+ emf_mail_attachment_tbl_t *attachment_tbl_list = NULL;
+ emf_attachment_data_t *temp_attachment_data = NULL;
+
+ /* get attachment from attachment tbl */
+ if ( (err = em_storage_get_attachment_list(input_mail_id, true, &attachment_tbl_list, &attachment_tbl_count)) != EM_STORAGE_ERROR_NONE ){
+ EM_DEBUG_EXCEPTION("em_storage_get_attachment_list failed [%d]", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+
+ if (attachment_tbl_count) {
+ EM_DEBUG_LOG("attchment count %d", attachment_tbl_count);
+
+ *output_attachment_data = em_core_malloc(sizeof(emf_attachment_data_t) * attachment_tbl_count);
+
+ if(*output_attachment_data == NULL) {
+ EM_DEBUG_EXCEPTION("em_core_malloc failed");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ for (i = 0; i < attachment_tbl_count; i++) {
+ temp_attachment_data = (*output_attachment_data) + i;
+
+ temp_attachment_data->attachment_id = attachment_tbl_list[i].attachment_id;
+ temp_attachment_data->attachment_name = attachment_tbl_list[i].attachment_name; attachment_tbl_list[i].attachment_name = NULL;
+ temp_attachment_data->attachment_path = attachment_tbl_list[i].attachment_path; attachment_tbl_list[i].attachment_path = NULL;
+ temp_attachment_data->attachment_size = attachment_tbl_list[i].attachment_size;
+ temp_attachment_data->mail_id = attachment_tbl_list[i].mail_id;
+ temp_attachment_data->account_id = attachment_tbl_list[i].account_id;
+ temp_attachment_data->mailbox_name = attachment_tbl_list[i].mailbox_name; attachment_tbl_list[i].mailbox_name = NULL;
+ temp_attachment_data->save_status = attachment_tbl_list[i].file_yn;
+ temp_attachment_data->drm_status = attachment_tbl_list[i].flag2;
+ temp_attachment_data->inline_content_status = attachment_tbl_list[i].flag3;
+ }
+ }
+
+FINISH_OFF:
+
+ *output_attachment_count = attachment_tbl_count;
+
+ if (attachment_tbl_list)
+ em_storage_free_attachment(&attachment_tbl_list, attachment_tbl_count, NULL);
+
+ return err;
+}
+
+
+EXPORT_API int em_core_mail_download_attachment(int account_id, int mail_id, char *nth, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("account_id[%d], mail_id[%d], nth[%p], err_code[%p]", account_id, mail_id, nth, err_code);
+
+ int attachment_no = 0;
+ int err = EMF_ERROR_NONE;
+
+ if (mail_id < 1 || !nth) {
+ EM_DEBUG_EXCEPTION("mail_id[%d], nth[%p]", mail_id, nth);
+ err = EMF_ERROR_INVALID_PARAM;
+
+ if (err_code != NULL)
+ *err_code = err;
+
+ if (nth)
+ attachment_no = atoi(nth);
+
+ em_storage_notify_network_event(NOTI_DOWNLOAD_ATTACH_FAIL, mail_id, 0, attachment_no, err);
+ return false;
+ }
+
+ int ret = false;
+ int status = EMF_DOWNLOAD_FAIL;
+ MAILSTREAM *stream = NULL;
+ BODY *mbody = NULL;
+ emf_mail_tbl_t *mail = NULL;
+ emf_mail_attachment_tbl_t *attachment = NULL;
+ struct attachment_info *ai = NULL;
+ struct _m_content_info *cnt_info = NULL;
+ void *tmp_stream = NULL;
+ char *s_uid = NULL, *server_mbox = NULL, buf[1024];
+ int msg_no = 0;
+ emf_mail_attachment_tbl_t *attachment_list = NULL;
+ int current_attachment_no = 0;
+ int attachment_count_to_be_downloaded = 0; /* how many attachments should be downloaded */
+ int i = 0;
+
+ if (!em_core_check_thread_status()) {
+ err = EMF_ERROR_CANCELLED;
+ goto FINISH_OFF;
+ }
+
+ only_body_download = false;
+
+ /* get mail from mail table. */
+ if (!em_storage_get_mail_by_id(mail_id, &mail, true, &err) || !mail) {
+ EM_DEBUG_EXCEPTION("em_storage_get_mail_by_id failed [%d]", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+
+ if (!mail->server_mail_status) {
+ EM_DEBUG_EXCEPTION("not synchronous mail...");
+ err = EMF_ERROR_INVALID_MAIL;
+ goto FINISH_OFF;
+ }
+
+ attachment_no = atoi(nth);
+ if (attachment_no == 0) { /* download all attachments, nth starts from 1, not zero */
+ /* get attachment list from db */
+ attachment_count_to_be_downloaded = EMF_ATTACHMENT_MAX_COUNT;
+ if ( (err = em_storage_get_attachment_list(mail_id, true, &attachment_list, &attachment_count_to_be_downloaded)) != EM_STORAGE_ERROR_NONE ){
+ EM_DEBUG_EXCEPTION("em_storage_get_attachment_list failed [%d]", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+ }
+ else { /* download only nth attachment */
+ attachment_count_to_be_downloaded = 1;
+ if (!em_storage_get_attachment_nth(mail_id, attachment_no, &attachment_list, true, &err) || !attachment_list) {
+ EM_DEBUG_EXCEPTION("em_storage_get_attachment_nth failed [%d]", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+ }
+
+ if (!em_core_check_thread_status()) {
+ err = EMF_ERROR_CANCELLED;
+ goto FINISH_OFF;
+ }
+
+ account_id = mail->account_id;
+ s_uid = EM_SAFE_STRDUP(mail->server_mail_id);
+ server_mbox = EM_SAFE_STRDUP(mail->mailbox_name);
+
+ /* open mail server. */
+ if (!em_core_mailbox_open(account_id, server_mbox, (void **)&tmp_stream, &err) || !tmp_stream) {
+ EM_DEBUG_EXCEPTION("em_core_mailbox_open failed [%d]", err);
+ status = EMF_DOWNLOAD_CONNECTION_FAIL;
+ goto FINISH_OFF;
+ }
+
+ stream = (MAILSTREAM *)tmp_stream;
+
+ for (i = 0; i < attachment_count_to_be_downloaded; i++) {
+ EM_DEBUG_LOG(" >>>>>> Attachment Downloading [%d / %d] start", i + 1, attachment_count_to_be_downloaded);
+
+ attachment = attachment_list + i;
+ if (attachment_no == 0) /* download all attachments, nth starts from 1, not zero */
+ current_attachment_no = i + 1; /* attachment no */
+ else /* download only nth attachment */
+ current_attachment_no = attachment_no; /* attachment no */
+
+ if (!em_core_check_thread_status()) {
+ err = EMF_ERROR_CANCELLED;
+ goto FINISH_OFF;
+ }
+
+ if (!(cnt_info = em_core_malloc(sizeof(struct _m_content_info)))) {
+ EM_DEBUG_EXCEPTION("malloc failed...");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ cnt_info->grab_type = GRAB_TYPE_ATTACHMENT; /* attachment */
+ cnt_info->file_no = current_attachment_no; /* attachment no */
+
+#ifdef CHANGE_HTML_BODY_TO_ATTACHMENT
+ /* text/html be changed to attachment, this isn't real attachment in RFC822. */
+ if (html_changed) cnt_info->file_no--;
+#endif
+
+ /* set sparep(member of BODY) memory free function. */
+ mail_parameters(stream, SET_FREEBODYSPAREP, em_core_free_body_sharep);
+
+ if (!em_core_check_thread_status()) {
+ err = EMF_ERROR_CANCELLED;
+ goto FINISH_OFF;
+ }
+
+ msg_no = atoi(s_uid);
+
+ /* get body structure. */
+ /* don't free mbody because mbody is freed in closing mail_stream. */
+ if ((!stream) || em_core_get_body_structure(stream, msg_no, &mbody, &err) < 0) {
+ EM_DEBUG_EXCEPTION("em_core_get_body_structure failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ if (!em_core_check_thread_status()) {
+ err = EMF_ERROR_CANCELLED;
+ goto FINISH_OFF;
+ }
+
+ /* set body fetch section. */
+ if (em_core_set_fetch_body_section(mbody, false, NULL, &err) < 0) {
+ EM_DEBUG_EXCEPTION("em_core_set_fetch_body_section failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ /* download attachment. */
+ _imap4_received_body_size = 0;
+ _imap4_last_notified_body_size = 0;
+ _imap4_total_body_size = 0; /* This will be assigned in imap_mail_write_body_to_file() */
+ _imap4_download_noti_interval_value = 0; /* This will be assigned in imap_mail_write_body_to_file() */
+
+ EM_DEBUG_LOG("cnt_info->file_no[%d], current_attachment_no[%d]", cnt_info->file_no, current_attachment_no);
+ if (em_core_get_body(stream, account_id, mail_id, msg_no, mbody, cnt_info, &err) < 0) {
+ EM_DEBUG_EXCEPTION("em_core_get_body failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ if (!em_core_check_thread_status()) {
+ err = EMF_ERROR_CANCELLED;
+ goto FINISH_OFF;
+ }
+
+ /* select target attachment information. */
+ for (ai = cnt_info->file ; ai; ai = ai->next) {
+ if (ai->name)
+ EM_DEBUG_LOG("[in loop] %s, %d", ai->name, cnt_info->file_no);
+
+ if (--cnt_info->file_no == 0)
+ break;
+ }
+
+ EM_DEBUG_LOG("cnt_info->file_no = %d, ai = %p", cnt_info->file_no, ai);
+
+ if (cnt_info->file_no == 0 && ai) {
+ /* rename temporary file to real file. */
+ if (!em_storage_create_dir(account_id, mail_id, current_attachment_no, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_create_dir failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ if (!em_storage_get_save_name(account_id, mail_id, current_attachment_no, ai->name, buf, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_get_save_name failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ if (!em_storage_move_file(ai->save, buf, false, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_move_file failed [%d]", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+
+ EM_SAFE_FREE(ai->save);
+
+ EM_DEBUG_LOG("ai->size [%d]", ai->size);
+ attachment->attachment_size = ai->size;
+ attachment->attachment_path = EM_SAFE_STRDUP(buf);
+
+ /* update attachment information. */
+ if (!em_storage_change_attachment_field(mail_id, UPDATE_SAVENAME, attachment, true, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_change_attachment_field failed [%d]", err);
+ /* delete created file. */
+ remove(buf);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+
+#ifdef __FEATURE_DRM__
+ if (em_core_check_drm(attachment)) { /* has drm attachment ? */
+ if (drm_svc_register_file(attachment->attachment_path) == DRM_RESULT_SUCCESS)
+ EM_DEBUG_LOG("drm_svc_register_file success");
+ else
+ EM_DEBUG_EXCEPTION("drm_svc_register_file fail");
+ mail->DRM_status = attachment->flag2;
+ }
+#endif /* __FEATURE_DRM__ */
+ }
+ else {
+ EM_DEBUG_EXCEPTION("invalid attachment sequence...");
+ err = EMF_ERROR_INVALID_ATTACHMENT;
+ goto FINISH_OFF;
+ }
+
+ if (cnt_info) {
+ em_core_mime_free_content_info(cnt_info);
+ cnt_info = NULL;
+ }
+ EM_DEBUG_LOG(" >>>>>> Attachment Downloading [%d / %d] completed", i+1, attachment_count_to_be_downloaded);
+ }
+
+ if (stream) {
+ em_core_mailbox_close(0, stream);
+ stream = NULL;
+ }
+
+ ret = true;
+
+FINISH_OFF:
+ if (stream)
+ em_core_mailbox_close(account_id, stream);
+ if (attachment_list)
+ em_storage_free_attachment(&attachment_list, attachment_count_to_be_downloaded, NULL);
+ if (cnt_info)
+ em_core_mime_free_content_info(cnt_info);
+ if (mail)
+ em_storage_free_mail(&mail, 1, NULL);
+
+ EM_SAFE_FREE(s_uid);
+ EM_SAFE_FREE(server_mbox);
+
+ if (ret == true)
+ em_storage_notify_network_event(NOTI_DOWNLOAD_ATTACH_FINISH, mail_id, NULL, attachment_no, 0);
+ else
+ em_storage_notify_network_event(NOTI_DOWNLOAD_ATTACH_FAIL, mail_id, NULL, attachment_no, err);
+
+ if (err_code != NULL)
+ *err_code = err;
+
+ EM_DEBUG_FUNC_END();
+ return ret;
+}
+
+#ifdef __ATTACHMENT_OPTI__
+EXPORT_API int em_core_mail_download_attachment_bulk(int account_id, int mail_id, char *nth, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("account_id[%d], mail_id[%d], nth[%p], err_code[%p]", account_id, mail_id, nth, err_code);
+
+ int attachment_no = 0;
+ int err = EMF_ERROR_NONE; /* Prevent Defect - 25093 */
+ int ret = false;
+ int status = EMF_DOWNLOAD_FAIL;
+ MAILSTREAM *stream = NULL;
+ emf_mail_tbl_t *mail = NULL;
+ emf_mail_attachment_tbl_t *attachment = NULL;
+ void *tmp_stream = NULL;
+ char *s_uid = NULL, *server_mbox = NULL, buf[512];
+ emf_mail_attachment_tbl_t *attachment_list = NULL;
+ int current_attachment_no = 0;
+ int attachment_count_to_be_downloaded = 0; /* how many attachments should be downloaded */
+ int i = 0;
+ char *savefile = NULL;
+ int dec_len = 0;
+ int uid = 0;
+#ifdef SUPPORT_EXTERNAL_MEMORY
+ int iActualSize = 0;
+ int is_add = 0;
+ char dirName[512];
+ int bIs_empty = 0;
+ int bIs_full = 0;
+ int bIsAdd_to_mmc = false;
+ int is_on_mmc = false;
+ emf_file_list *pFileListMMc = NULL;
+ emf_file_list *pFileList = NULL;
+#endif /* SUPPORT_EXTERNAL_MEMORY */
+
+
+ memset(buf, 0x00, 512);
+ /* CID FIX 31230 */
+ if (mail_id < 1 || !nth) {
+ EM_DEBUG_EXCEPTION("account_id[%d], mail_id[%d], nth[%p]", account_id, mail_id, nth);
+
+ err = EMF_ERROR_INVALID_PARAM;
+
+ if (err_code != NULL)
+ *err_code = err;
+
+ if (nth)
+ attachment_no = atoi(nth);
+
+ em_storage_notify_network_event(NOTI_DOWNLOAD_ATTACH_FAIL, mail_id, 0, attachment_no, err); /* 090525, kwangryul.baek */
+
+ return false;
+ }
+
+ if (!em_core_check_thread_status()) {
+ err = EMF_ERROR_CANCELLED;
+ goto FINISH_OFF;
+ }
+ only_body_download = false;
+
+ attachment_no = atoi(nth);
+
+ if (attachment_no == 0) {
+ /* download all attachments, nth starts from 1, not zero */
+ /* get attachment list from db */
+ attachment_count_to_be_downloaded = EMF_ATTACHMENT_MAX_COUNT;
+ if ( (err = em_storage_get_attachment_list(mail_id, true, &attachment_list, &attachment_count_to_be_downloaded)) != EM_STORAGE_ERROR_NONE || !attachment_list){
+ EM_DEBUG_EXCEPTION("em_storage_get_attachment_list failed [%d]", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+ }
+ else { /* download only nth attachment */
+ attachment_count_to_be_downloaded = 1;
+ if (!em_storage_get_attachment_nth(mail_id, attachment_no, &attachment_list, true, &err) || !attachment_list) {
+ EM_DEBUG_EXCEPTION("em_storage_get_attachment_nth failed [%d]", err);
+
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+ }
+
+
+ if (!em_core_check_thread_status()) {
+ err = EMF_ERROR_CANCELLED;
+ goto FINISH_OFF;
+ }
+
+
+ /* get mail from mail table. */
+ if (!em_storage_get_mail_by_id(mail_id, &mail, true, &err) || !mail) {
+ EM_DEBUG_EXCEPTION("em_storage_get_mail_by_id failed [%d]", err);
+
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+
+ /* if (!mail->server_mail_yn || !mail->text_download_yn) {*/ /* faizan.h@samsung.com */
+
+ if (!em_core_check_thread_status()) {
+ err = EMF_ERROR_CANCELLED;
+ goto FINISH_OFF;
+ }
+
+ account_id = mail->account_id;
+ s_uid = EM_SAFE_STRDUP(mail->server_mail_id); mail->server_mail_id = NULL;
+ server_mbox = EM_SAFE_STRDUP(mail->mailbox); mail->server_mailbox_name = NULL;
+
+
+
+ /* open mail server. */
+ if (!em_core_mailbox_open(account_id, server_mbox, (void **)&tmp_stream, &err) || !tmp_stream) {
+ EM_DEBUG_EXCEPTION("em_core_mailbox_open failed [%d]", err);
+
+ status = EMF_DOWNLOAD_CONNECTION_FAIL;
+ goto FINISH_OFF;
+ }
+
+ stream = (MAILSTREAM *)tmp_stream;
+
+
+ if (!em_core_check_thread_status()) {
+ err = EMF_ERROR_CANCELLED;
+ goto FINISH_OFF;
+ }
+
+
+ for (i = 0; i < attachment_count_to_be_downloaded; i++) {
+ EM_DEBUG_LOG(" >>>>>> Attachment Downloading [%d / %d] start", i+1, attachment_count_to_be_downloaded);
+
+ attachment = attachment_list + i;
+ if (attachment_no == 0) {
+ /* download all attachments, nth starts from 1, not zero */
+ current_attachment_no = i + 1; /* attachment no */
+ }
+ else {
+ /* download only nth attachment */
+ current_attachment_no = attachment_no; /* attachment no */
+ }
+
+ if (!em_core_check_thread_status()) {
+ err = EMF_ERROR_CANCELLED;
+ goto FINISH_OFF;
+ }
+
+ _imap4_received_body_size = 0;
+ _imap4_last_notified_body_size = 0;
+ _imap4_total_body_size = 0; /* This will be assigned in imap_mail_write_body_to_file() */
+ _imap4_download_noti_interval_value = 0; /* This will be assigned in imap_mail_write_body_to_file() */
+
+
+ EM_SAFE_FREE(savefile);
+ if (!em_core_get_temp_file_name(&savefile, &err)) {
+ EM_DEBUG_EXCEPTION("em_core_get_temp_file_name failed [%d]", err);
+
+ if (err_code != NULL)
+ *err_code = err;
+ goto FINISH_OFF;
+ }
+
+ if (s_uid)
+ uid = atoi(s_uid);
+
+ EM_DEBUG_LOG("uid [%d]", uid);
+
+ if (!imap_mail_write_body_to_file(stream, account_id, mail_id, attachment_no, savefile, uid , attachment->section, attachment->encoding, &dec_len, NULL, &err)) {
+ EM_DEBUG_EXCEPTION("imap_mail_write_body_to_file failed [%d]", err);
+ if (err_code != NULL)
+ *err_code = err;
+ goto FINISH_OFF;
+ }
+
+#ifdef SUPPORT_EXTERNAL_MEMORY
+ iActualSize = em_core_get_actual_mail_size (cnt_info->text.plain , cnt_info->text.html, cnt_info->file , &err);
+ if (!em_storage_mail_check_free_space(iActualSize, &bIs_full, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_mail_check_free_space failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ if (bIs_full) {
+ /* If external memory not present, return error */
+ if (PS_MMC_REMOVED == em_storage_get_mmc_status()) {
+ err = EMF_ERROR_MAIL_MEMORY_FULL;
+ goto FINISH_OFF;
+ }
+ bIsAdd_to_mmc = true;
+ }
+#endif /* SUPPORT_EXTERNAL_MEMORY */
+
+ if (!em_storage_create_dir(account_id, mail_id, attachment_no, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_create_dir failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ if (!em_storage_get_save_name(account_id, mail_id, attachment_no, attachment->name, buf, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_get_save_name failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ if (!em_storage_move_file(savefile, buf, false, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_move_file failed [%d]", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+
+ attachment->attachment = EM_SAFE_STRDUP(buf);
+ /* update attachment information. */
+ if (!em_storage_change_attachment_field(mail_id, UPDATE_SAVENAME, attachment, true, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_change_attachment_field failed [%d]", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+
+#ifdef __FEATURE_DRM__
+ if (em_core_check_drm(attachment)) {
+ /* is drm */
+ if (drm_svc_register_file(attachment->attachment) == DRM_RESULT_SUCCESS)
+ EM_DEBUG_LOG("drm_svc_register_file success");
+ else
+ EM_DEBUG_EXCEPTION("drm_svc_register_file fail");
+ mail->flag3 = attachment->flag2;
+ }
+#endif /* __FEATURE_DRM__ */
+
+ if (!em_core_check_thread_status()) {
+ err = EMF_ERROR_CANCELLED;
+ goto FINISH_OFF;
+ }
+
+ EM_DEBUG_LOG(" >>>>>> Attachment Downloading [%d / %d] completed", i+1, attachment_count_to_be_downloaded);
+ }
+
+ ret = true;
+
+ FINISH_OFF:
+
+ EM_SAFE_FREE(savefile);
+
+ em_core_mailbox_close(0, stream);
+ stream = NULL;
+
+ if (attachment_list)
+ em_storage_free_attachment(&attachment_list, attachment_count_to_be_downloaded, NULL);
+
+ if (mail)
+ em_storage_free_mail(&mail, 1, NULL);
+
+ if (s_uid)
+ free(s_uid);
+
+ if (server_mbox)
+ free(server_mbox);server_mbox = NULL;
+
+ if (ret == true)
+ em_storage_notify_network_event(NOTI_DOWNLOAD_ATTACH_FINISH, mail_id, NULL, attachment_no, 0);
+ else if (err != EMF_ERROR_CANCELLED)
+ em_storage_notify_network_event(NOTI_DOWNLOAD_ATTACH_FAIL, mail_id, NULL, attachment_no, err);
+
+ if (err_code != NULL)
+ *err_code = err;
+
+ return ret;
+}
+#endif
+
+
+EXPORT_API int em_core_mail_download_body_multi_sections_bulk(void *mail_stream, int account_id, int mail_id, int verbose, int with_attach, int limited_size, int event_handle , int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("mail_stream[%p], account_id[%d], mail_id[%d], verbose[%d], with_attach[%d], event_handle [ %d ] ", mail_stream, account_id, mail_id, verbose, with_attach, event_handle);
+
+ int ret = false;
+ int err = EMF_ERROR_NONE;
+ int status = EMF_DOWNLOAD_FAIL;
+ int pop3_body_size = 0;
+ int pop3_downloaded_size = 0;
+ MAILSTREAM *stream = NULL;
+ BODY *mbody = NULL;
+ PARTLIST *section_list = NULL;
+ emf_mailbox_t mbox = { 0 };
+ emf_mail_tbl_t *mail = NULL;
+ emf_mail_attachment_tbl_t attachment = {0, 0, NULL, };
+ emf_account_t *ref_account = NULL;
+ struct attachment_info *ai = NULL;
+ struct _m_content_info *cnt_info = NULL;
+ void *tmp_stream = NULL;
+ char *s_uid = NULL, *server_mbox = NULL, buf[512];
+ int msgno = 0, attachment_num = 1, local_attachment_count = 0, local_inline_content_count = 0;
+ int iActualSize = 0;
+ char html_body[MAX_PATH] = {0, };
+ em_core_uid_list *uid_list = NULL;
+ char *mailbox_name = NULL;
+#ifdef CHANGE_HTML_BODY_TO_ATTACHMENT
+ int html_changed = 0;
+#endif
+
+ if (mail_id < 1) {
+ EM_DEBUG_EXCEPTION("mail_stream[%p], account_id[%d], mail_id[%d], verbose[%d], with_attach[%d]", mail_stream, account_id, mail_id, verbose, with_attach);
+ err = EMF_ERROR_INVALID_PARAM;
+
+ if (err_code != NULL)
+ *err_code = err;
+
+ em_storage_notify_network_event(NOTI_DOWNLOAD_BODY_FAIL, mail_id, NULL, event_handle, err);
+ return false;
+ }
+
+ FINISH_OFF_IF_CANCELED;
+
+ only_body_download = true;
+
+ if (!em_storage_get_mail_by_id(mail_id, &mail, true, &err) || !mail) {
+ EM_DEBUG_EXCEPTION("em_storage_get_mail_by_id failed [%d]", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+
+ if (mail->mailbox_name)
+ mailbox_name = EM_SAFE_STRDUP(mail->mailbox_name);
+
+ if (1 == mail->body_download_status) {
+ EM_DEBUG_EXCEPTION("not synchronous mail...");
+ err = EMF_ERROR_INVALID_MAIL;
+ goto FINISH_OFF;
+ }
+
+ account_id = mail->account_id;
+ s_uid = mail->server_mail_id;
+ server_mbox = mail->server_mailbox_name;
+ mail->server_mail_id = NULL;
+ mail->server_mailbox_name = NULL;
+
+ attachment.account_id = mail->account_id;
+ attachment.mail_id = mail->mail_id;
+ attachment.mailbox_name = mail->mailbox_name; mail->mailbox_name = NULL;
+ attachment.file_yn = 0;
+
+ em_storage_free_mail(&mail, 1, NULL);
+ mail = NULL;
+
+ if (!(ref_account = em_core_get_account_reference(account_id))) {
+ EM_DEBUG_EXCEPTION("em_core_get_account_reference failed [%d]", account_id);
+ err = EMF_ERROR_INVALID_ACCOUNT;
+ goto FINISH_OFF;
+ }
+
+ FINISH_OFF_IF_CANCELED;
+
+ /* open mail server. */
+ if (!mail_stream) {
+ if (!em_core_mailbox_open(account_id, mailbox_name, (void **)&tmp_stream, &err) || !tmp_stream) {
+ EM_DEBUG_EXCEPTION("em_core_mailbox_open failed [%d]", err);
+ status = EMF_DOWNLOAD_CONNECTION_FAIL;
+ goto FINISH_OFF;
+ }
+ stream = (MAILSTREAM *)tmp_stream;
+ }
+ else
+ stream = (MAILSTREAM *)mail_stream;
+
+ free(server_mbox); server_mbox = NULL;
+
+
+ FINISH_OFF_IF_CANCELED;
+
+ if (!(cnt_info = em_core_malloc(sizeof(struct _m_content_info)))) {
+ EM_DEBUG_EXCEPTION("em_core_malloc failed...");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ if (ref_account->receiving_server_type == EMF_SERVER_TYPE_POP3) { /* POP3 */
+ /* in POP3 case, both text and attachment are downloaded in this call. */
+ cnt_info->grab_type = GRAB_TYPE_TEXT | GRAB_TYPE_ATTACHMENT;
+ attachment.file_yn = 1; /* all attachments should be downloaded in the case of POP3 */
+
+ mbox.account_id = account_id;
+ mbox.mail_stream = stream;
+
+ /* download all uids from server. */
+ if (!em_core_mailbox_download_uid_all(&mbox, &uid_list, NULL, NULL, 0, EM_CORE_GET_UIDS_FOR_NO_DELETE, &err)) {
+ EM_DEBUG_EXCEPTION("em_core_mailbox_download_uid_all failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ /* get mesg number to be related to last download mail from uid list file */
+ if (!em_core_mailbox_get_msgno(uid_list, s_uid, &msgno, &err)) {
+ EM_DEBUG_EXCEPTION("em_core_mailbox_get_msgno failed [%d]", err);
+ err = EMF_ERROR_MAIL_NOT_FOUND_ON_SERVER;
+ goto FINISH_OFF;
+ }
+
+ free(s_uid); s_uid = NULL;
+
+ if (!em_core_check_thread_status()) {
+ err = EMF_ERROR_CANCELLED;
+ goto FINISH_OFF;
+ }
+
+ _pop3_received_body_size = 0;
+ _pop3_total_body_size = 0;
+ _pop3_last_notified_body_size = 0;
+ _pop3_receiving_mail_id = mail_id;
+
+ /* send read mail commnad. */
+ if (!em_core_mail_cmd_read_mail_pop3(stream, msgno, limited_size, &pop3_downloaded_size, &pop3_body_size, &err))
+ /* if (!em_core_mail_cmd_read_mail_pop3(stream, msgno, PARTIAL_BODY_SIZE_IN_BYTES, &pop3_downloaded_size, &pop3_body_size, &err)) */ {
+ EM_DEBUG_EXCEPTION("em_core_mail_cmd_read_mail_pop3 failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ _pop3_total_body_size = pop3_body_size;
+
+ if (!em_storage_notify_network_event(NOTI_DOWNLOAD_BODY_START, mail_id, "dummy-file", _pop3_total_body_size, 0))
+ EM_DEBUG_EXCEPTION(" em_storage_notify_network_event [ NOTI_DOWNLOAD_BODY_START] failed >>>> ");
+ else
+ EM_DEBUG_LOG("NOTI_DOWNLOAD_BODY_START notified (%d / %d)", 0, _pop3_total_body_size);
+
+ FINISH_OFF_IF_CANCELED;
+
+ /* save message into tempfile */
+ /* parsing mime from stream. */
+
+ if (!em_core_mime_parse_mime(stream, 0, cnt_info, &err)) {
+ EM_DEBUG_EXCEPTION("em_core_mime_parse_mime failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ FINISH_OFF_IF_CANCELED;
+ }
+ else { /* in IMAP case, both text and attachment list are downloaded in this call. */
+ /* if (ref_account->flag1 == 2) *//* This flag is just for downloading mailbox.(sync header), don't be used when retrieve body. */
+ if (with_attach > 0)
+ cnt_info->grab_type = GRAB_TYPE_TEXT | GRAB_TYPE_ATTACHMENT;
+ else
+ cnt_info->grab_type = GRAB_TYPE_TEXT;
+
+ int uid = atoi(s_uid);
+
+ free(s_uid); s_uid = NULL;
+
+ /* set sparep(member of BODY) memory free function */
+ mail_parameters(stream, SET_FREEBODYSPAREP, em_core_free_body_sharep);
+
+ /* get body strucutre. */
+ /* don't free mbody because mbody is freed in closing mail_stream. */
+ if (em_core_get_body_structure(stream, uid, &mbody, &err) < 0 || (mbody == NULL)) {
+ EM_DEBUG_EXCEPTION("em_core_get_body_structure failed [%d]", err);
+ err = EMF_ERROR_MAIL_NOT_FOUND_ON_SERVER;
+ goto FINISH_OFF;
+ }
+
+ FINISH_OFF_IF_CANCELED;
+
+ if (mbody->type == TYPEMULTIPART) {
+ EM_DEBUG_LOG(">>> check multipart body size to download : only_body_download[%d]", only_body_download);
+ PART *part_child = mbody->nested.part;
+ int counter = 0;
+
+ char filename[MAX_PATH+1] = {0, };
+ int is_attachment = 0;
+ while (part_child) {
+ BODY *body = &(part_child->body);
+ if (only_body_download == true) {
+ if (((body->id) && strlen(body->id) > 1) || (body->location))
+ is_attachment = 0;
+ else if (body->disposition.type) { /* "attachment" or "inline" or etc... */
+ PARAMETER *param = body->disposition.parameter;
+
+ while (param) {
+ EM_DEBUG_LOG("param->attribute [%s], param->value [%s]", param->attribute, param->value);
+
+ if (!strcasecmp(param->attribute, "filename")) { /* attribute is "filename" */
+ strncpy(filename, param->value, MAX_PATH);
+ EM_DEBUG_LOG(">>>>> FILENAME [%s] ", filename);
+ break;
+ }
+ param = param->next;
+ }
+
+ is_attachment = 1;
+
+ if (!*filename) { /* it may be report msg */
+ if (body->disposition.type[0] == 'i' || body->disposition.type[0] == 'I')
+ is_attachment = 0;
+ }
+ }
+
+ if (is_attachment == 0) {
+ EM_DEBUG_LOG("%d : body->size.bytes[%ld]", counter+1, body->size.bytes);
+ multi_part_body_size = multi_part_body_size + body->size.bytes;
+ }
+ }
+ else { /* download all */
+ EM_DEBUG_LOG("%d : body->size.bytes[%ld]", counter+1, body->size.bytes);
+ multi_part_body_size = multi_part_body_size + body->size.bytes;
+ }
+ part_child = part_child->next;
+ counter++;
+ }
+ }
+
+ /* set body fetch section. */
+ if (em_core_set_fetch_body_section(mbody, true, &iActualSize, &err) < 0) {
+ EM_DEBUG_EXCEPTION("em_core_set_fetch_body_section failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ EM_DEBUG_LOG("iActualSize [%d]", iActualSize);
+ multi_part_body_size = iActualSize;
+
+ _imap4_received_body_size = 0;
+ _imap4_last_notified_body_size = 0;
+ if (multi_part_body_size > 0) { /* download multiparts */
+ _imap4_total_body_size = multi_part_body_size;
+ _imap4_download_noti_interval_value = DOWNLOAD_NOTI_INTERVAL_PERCENT * multi_part_body_size / 100;
+ }
+ else { /* download only one body part */
+ _imap4_total_body_size = 0; /* This will be assigned in imap_mail_write_body_to_file() */
+ _imap4_download_noti_interval_value = 0; /* This will be assigned in imap_mail_write_body_to_file() */
+ }
+
+ /* save message into tempfile */
+ /* download body text and get attachment list. */
+ if (em_core_get_body_part_list_full(stream, uid, account_id, mail_id, mbody, cnt_info, &err, section_list, event_handle) < 0) {
+ EM_DEBUG_EXCEPTION("em_core_get_body falied [%d]", err);
+ goto FINISH_OFF;
+ }
+ FINISH_OFF_IF_CANCELED;
+ }
+
+
+ if (false == em_storage_get_mail_by_id(mail_id, &mail, true, &err)) {
+ EM_DEBUG_EXCEPTION(" em_storage_get_mail_by_id failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ if (cnt_info->text.plain) {
+ EM_DEBUG_LOG("cnt_info->text.plain [%s]", cnt_info->text.plain);
+
+ if (!em_storage_create_dir(account_id, mail_id, 0, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_create_dir failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+
+ if (!em_storage_get_save_name(account_id, mail_id, 0, cnt_info->text.plain_charset ? cnt_info->text.plain_charset : "UTF-8", buf, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_get_save_name failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ if (!em_storage_move_file(cnt_info->text.plain, buf, false, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_move_file failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ mail->file_path_plain = EM_SAFE_STRDUP(buf);
+ EM_DEBUG_LOG("> mail->file_path_plain [%s]", mail->file_path_plain);
+ }
+
+ if (cnt_info->text.html) {
+ if (!em_storage_create_dir(account_id, mail_id, 0, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_create_dir failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ if (cnt_info->text.plain_charset != NULL) {
+ memcpy(html_body, cnt_info->text.plain_charset, strlen(cnt_info->text.plain_charset));
+ strcat(html_body, HTML_EXTENSION_STRING);
+ }
+ else {
+ memcpy(html_body, "UTF-8.htm", strlen("UTF-8.htm"));
+ }
+ if (!em_storage_get_save_name(account_id, mail_id, 0, html_body, buf, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_get_save_name failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ if (!em_storage_move_file(cnt_info->text.html, buf, false, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_move_file failed [%d]", err);
+ goto FINISH_OFF;
+ }
+ mail->file_path_html = EM_SAFE_STRDUP(buf);
+ }
+
+ if (ref_account->receiving_server_type == EMF_SERVER_TYPE_POP3 && limited_size != NO_LIMITATION && limited_size < pop3_body_size)
+ mail->body_download_status = EMF_BODY_DOWNLOAD_STATUS_PARTIALLY_DOWNLOADED;
+ else
+ mail->body_download_status = EMF_BODY_DOWNLOAD_STATUS_FULLY_DOWNLOADED;
+
+#ifdef CHANGE_HTML_BODY_TO_ATTACHMENT
+ if (html_changed) mail->flag2 = 1;
+#endif
+
+ FINISH_OFF_IF_CANCELED;
+
+ for (ai = cnt_info->file; ai; ai = ai->next, attachment_num++) {
+ attachment.attachment_id = attachment_num;
+ attachment.attachment_size = ai->size;
+ attachment.attachment_path = ai->save;
+ attachment.attachment_name = ai->name;
+ attachment.flag1 = ai->drm;
+ attachment.flag3 = ai->type == 1;
+ attachment.file_yn = 0;
+
+ EM_DEBUG_LOG("attachment.attachment_id[%d]", attachment.attachment_id);
+ EM_DEBUG_LOG("attachment.attachment_size[%d]", attachment.attachment_size);
+ EM_DEBUG_LOG("attachment.attachment_path[%s]", attachment.attachment_path);
+ EM_DEBUG_LOG("attachment.attachment_name[%s]", attachment.attachment_name);
+ EM_DEBUG_LOG("attachment.flag1[%d]", attachment.flag1);
+ EM_DEBUG_LOG("attachment.flag3[%d]", attachment.flag3);
+ EM_DEBUG_LOG("ai->save [%d]", ai->save);
+#ifdef __ATTACHMENT_OPTI__
+ attachment.encoding = ai->encoding;
+ attachment.section = ai->section;
+#endif
+
+ if (ai->type == 1)
+ local_inline_content_count++;
+ local_attachment_count++;
+
+ if (ai->save) {
+ /* in POP3 case, rename temporary file to real file. */
+ attachment.file_yn = 1;
+ if (ai->type == 1) { /* it is inline content */
+ if (!em_storage_create_dir(account_id, mail_id, 0, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_create_dir failed [%d]", err);
+ goto FINISH_OFF;
+ }
+ if (!em_storage_get_save_name(account_id, mail_id, 0, attachment.attachment_name, buf, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_get_save_name failed [%d]", err);
+ goto FINISH_OFF;
+ }
+ }
+ else {
+ if (!em_storage_create_dir(account_id, mail_id, attachment_num, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_create_dir failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ if (!em_storage_get_save_name(account_id, mail_id, attachment_num, attachment.attachment_name, buf, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_get_save_name failed [%d]", err);
+ goto FINISH_OFF;
+ }
+ }
+
+ if (!em_storage_move_file(ai->save, buf, false, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_move_file failed [%d]", err);
+
+ /* delete all created files. */
+ if (!em_storage_get_save_name(account_id, mail_id, 0, NULL, buf, NULL)) {
+ EM_DEBUG_EXCEPTION("em_storage_get_save_name failed...");
+ /* goto FINISH_OFF; */
+ }
+
+ if (!em_storage_delete_dir(buf, NULL)) {
+ EM_DEBUG_EXCEPTION("em_storage_delete_dir failed...");
+ /* goto FINISH_OFF; */
+ }
+
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+
+ free(ai->save); ai->save = EM_SAFE_STRDUP(buf);
+
+ attachment.attachment_path = ai->save;
+
+#ifdef __FEATURE_DRM__
+ if (em_core_check_drm(&attachment)) { /* is drm */
+ if (!drm_svc_register_file(attachment.attachment_path))
+ EM_DEBUG_EXCEPTION("drm_svc_register_file fail");
+ mail->DRM_status = attachment.flag2;
+ }
+#endif/* __FEATURE_DRM__ */
+ }
+
+#ifdef __FEATURE_PARTIAL_BODY_DOWNLOAD__
+ /* Information : Attachment info already saved if partial body is dowloaded. */
+ if (ai->type) { /* Get attachment details */
+ emf_mail_attachment_tbl_t *attch_info = NULL;
+
+ if (!em_storage_get_attachment_nth(mail_id, attachment.attachment_id, &attch_info, true, &err) || !attch_info) {
+ EM_DEBUG_EXCEPTION("em_storage_get_attachment_nth failed [%d]", err);
+ if (err == EM_STORAGE_ERROR_ATTACHMENT_NOT_FOUND) { /* save only attachment file. */
+ if (!em_storage_add_attachment(&attachment, 0, false, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_add_attachment failed [%d]", err);
+ if (attch_info)
+ em_storage_free_attachment(&attch_info, 1, NULL);
+ /* delete all created files. */
+ if (!em_storage_get_save_name(account_id, mail_id, 0, NULL, buf, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_get_save_name failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ if (!em_storage_delete_dir(buf, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_delete_dir failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ /* ROLLBACK TRANSACTION; */
+ em_storage_rollback_transaction(NULL, NULL, NULL);
+
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+ }
+ }
+ else {
+ EM_DEBUG_LOG("Attachment info already exists...!");
+ /* Update attachment size */
+ EM_DEBUG_LOG("attachment_size [%d], ai->size [%d]", attch_info->attachment_size, ai->size);
+ attch_info->attachment_size = ai->size;
+ if (!em_storage_update_attachment(attch_info, true, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_update_attachment failed [%d]", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+ }
+
+ if (attch_info)
+ em_storage_free_attachment(&attch_info, 1, NULL);
+ }
+
+#else
+
+ if (ai->type) {
+ mail->attachment_yn = 1;
+ /* save only attachment file. */
+ if (!em_storage_add_attachment(&attachment, 0, false, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_add_attachment failed [%d]", err);
+ if (bIsAdd_to_mmc) {
+ if (attachment.attachment) {
+ }
+ }
+ else {
+ /* delete all created files. */
+ if (!em_storage_get_save_name(account_id, mail_id, 0, NULL, buf, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_get_save_name failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ if (!em_storage_delete_dir(buf, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_delete_dir failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ /* ROLLBACK TRANSACTION; */
+ em_storage_rollback_transaction(NULL, NULL, NULL);
+
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+ }
+ }
+#endif /* End of #ifdef __FEATURE_PARTIAL_BODY_DOWNLOAD__ */
+
+ }
+
+ EM_DEBUG_LOG("Check #1");
+
+ mail->attachment_count = local_attachment_count;
+ mail->inline_content_count = local_inline_content_count;
+
+ EM_DEBUG_LOG("Check #2");
+
+ EM_DEBUG_LOG("Mailbox Name [%s]", mailbox_name);
+ mail->mailbox_name = EM_SAFE_STRDUP(mailbox_name); /* fix for mailboox sync fail */
+
+ EM_DEBUG_LOG("Check #3");
+
+ /* change mail's information. */
+ if (!em_storage_change_mail_field(mail_id, APPEND_BODY, mail, false, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_change_mail_field failed [%d]", err);
+ em_storage_rollback_transaction(NULL, NULL, NULL); /* ROLLBACK TRANSACTION; */
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+
+ EM_DEBUG_LOG("cnt_info->text.plain [%s], cnt_info->text.html [%s]", cnt_info->text.plain, cnt_info->text.html);
+
+ /* in pop3 mail case, the mail is deleted from server after being downloaded. */
+ if (ref_account->receiving_server_type == EMF_SERVER_TYPE_POP3) {
+#ifdef DELETE_AFTER_DOWNLOADING
+ char delmsg[24];
+
+ SNPRINTF(delmsg, sizeof(delmsg), "%d", msg_no);
+
+ if (!ref_account->keep_on_server) {
+ if (!em_core_mail_delete_from_server(&mbox, delmsg, &err))
+ EM_DEBUG_EXCEPTION("em_core_mail_delete_from_server failed [%d]", err);
+ }
+#endif
+
+ if (!mail_stream) {
+ if (stream != NULL) {
+ em_core_mailbox_close(0, stream);
+ stream = NULL;
+ }
+ }
+ }
+
+ FINISH_OFF_IF_CANCELED;
+
+ ret = true;
+
+FINISH_OFF:
+
+ if (g_inline_count) {
+ g_inline_count = 0;
+ EM_SAFE_FREE(g_inline_list);
+ }
+
+ multi_part_body_size = 0;
+ _pop3_received_body_size = 0;
+ _pop3_last_notified_body_size = 0;
+ _pop3_total_body_size = 0;
+ _pop3_receiving_mail_id = 0;
+
+ _imap4_received_body_size = 0;
+ _imap4_last_notified_body_size = 0;
+ _imap4_total_body_size = 0;
+ _imap4_download_noti_interval_value = 0;
+
+ if (cnt_info)
+ em_core_mime_free_content_info(cnt_info);
+ if (mail)
+ em_storage_free_mail(&mail, 1, NULL);
+ if (attachment.mailbox_name)
+ free(attachment.mailbox_name);
+ if (server_mbox)
+ free(server_mbox);
+ if (s_uid)
+ free(s_uid);
+
+ multi_part_body_size = 0;
+
+ if (ret == true)
+ em_storage_notify_network_event(NOTI_DOWNLOAD_BODY_FINISH, mail_id, NULL, event_handle, 0);
+ else
+ em_storage_notify_network_event(NOTI_DOWNLOAD_BODY_FAIL, mail_id, NULL, event_handle, err);
+
+ if (mailbox_name)
+ free (mailbox_name);
+
+ if (err_code != NULL)
+ *err_code = err;
+
+ return ret;
+}
+
+
+
+void em_core_mail_copyuid(MAILSTREAM *stream, char *mailbox,
+ unsigned long uidvalidity, SEARCHSET *sourceset,
+ SEARCHSET *destset)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ char old_server_uid[129];
+
+ EM_DEBUG_LOG("mailbox name - %s", mailbox);
+ EM_DEBUG_LOG("first sequence number source- %ld", sourceset->first);
+ EM_DEBUG_LOG("last sequence number last- %ld", sourceset->last);
+ EM_DEBUG_LOG("first sequence number dest - %ld", destset->first);
+ EM_DEBUG_LOG("last sequence number dest- %ld", sourceset->last);
+
+ /* search for server _mail_id with value sourceset->first and update it with destset->first */
+ /* faizan.h@samsung.com */
+ memset(old_server_uid, 0x00, 129);
+ sprintf(old_server_uid, "%ld", sourceset->first);
+ EM_DEBUG_LOG(">>>>> old_server_uid = %s", old_server_uid);
+
+ memset(g_new_server_uid, 0x00, 129);
+ sprintf(g_new_server_uid, "%ld", destset->first);
+ EM_DEBUG_LOG(">>>>> new_server_uid =%s", g_new_server_uid);
+
+ if (!em_storage_update_server_uid(old_server_uid, g_new_server_uid, NULL)) {
+ EM_DEBUG_EXCEPTION("em_storage_update_server_uid falied...");
+ }
+}
+
+int em_core_mail_delete(int account_id, int mail_ids[], int num, int from_server, int noti_param_1, int noti_param_2, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("account_id[%d], mail_ids[%p], num[%d], from_server[%d], noti_param_1 [%d], noti_param_2 [%d], err_code[%p]", account_id, mail_ids, num, from_server, noti_param_1, noti_param_2, err_code);
+
+ int ret = false;
+ int err = EMF_ERROR_NONE;
+ int status = EMF_DELETE_FAIL;
+
+ emf_account_t *account = NULL;
+ emf_mailbox_t mailbox;
+ emf_mail_tbl_t *mail = NULL;
+ void *stream = NULL;
+ int mail_id = 0;
+ int i = 0;
+ int msgno = 0, parameter_string_length = 0;
+ char *parameter_string = NULL, mail_id_string[10];
+ #ifdef __FEATURE_BULK_DELETE_MOVE_UPDATE_REQUEST_OPTI__
+ int bulk_flag = false;
+ #endif
+
+ memset(&mailbox, 0x00, sizeof(emf_mailbox_t));
+
+ if (!account_id || !mail_ids || !num) {
+ EM_DEBUG_EXCEPTION("account_id[%d], mail_ids[%p], num[%d], from_server[%d]", account_id, mail_ids, num, from_server);
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ mail_id = mail_ids[0];
+
+ if (!(account = em_core_get_account_reference(account_id))) {
+ EM_DEBUG_EXCEPTION("em_core_get_account_reference failed [%d]", account_id);
+ err = EMF_ERROR_INVALID_ACCOUNT;
+ goto FINISH_OFF;
+ }
+
+ if (account->receiving_server_type == EMF_SERVER_TYPE_ACTIVE_SYNC)
+ from_server = EMF_DELETE_LOCALLY;
+
+ FINISH_OFF_IF_CANCELED;
+
+ parameter_string_length = sizeof(char) * (num * 8 + 128 /* MAILBOX_LEN_IN_MAIL_TBL */ * 2);
+ parameter_string = malloc(parameter_string_length);
+
+ if (parameter_string == NULL) {
+ EM_DEBUG_EXCEPTION("Memory allocation for mail_id_list_string failed");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ memset(parameter_string, 0, parameter_string_length);
+
+ if (from_server == EMF_DELETE_LOCAL_AND_SERVER || from_server == EMF_DELETE_FOR_SEND_THREAD) { /* server delete */
+ for (i = 0; i < num; i++) {
+ mail_id = mail_ids[i];
+
+ if (!em_storage_get_downloaded_mail(mail_id, &mail, false, &err) || !mail) {
+ EM_DEBUG_EXCEPTION("em_storage_get_uid_by_mail_id failed [%d]", err);
+
+ if (err == EM_STORAGE_ERROR_MAIL_NOT_FOUND) { /* not server mail */
+ /* err = EMF_ERROR_MAIL_NOT_FOUND_ON_SERVER; */
+ continue;
+ }
+ else
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+
+ goto FINISH_OFF;
+ }
+
+ EM_SAFE_FREE(mailbox.user_data);
+
+ if (stream == NULL) {
+ if (!em_core_mailbox_open(account_id, mail->server_mailbox_name , (void **)&stream, &err)) {
+ EM_DEBUG_EXCEPTION("em_core_mailbox_open failed [%d]", err);
+ status = EMF_DELETE_CONNECTION_FAIL;
+ goto FINISH_OFF;
+ }
+
+ mailbox.account_id = account_id;
+ mailbox.name = mail->server_mailbox_name;
+ mailbox.mail_stream = stream;
+
+ FINISH_OFF_IF_CANCELED;
+ }
+
+#ifdef __FEATURE_BULK_DELETE_MOVE_UPDATE_REQUEST_OPTI__
+ if (account->receiving_server_type == EMF_SERVER_TYPE_IMAP4) {
+#ifdef __LOCAL_ACTIVITY__
+ if (!bulk_flag && !imap4_mail_delete_ex(&mailbox, mail_ids, num, from_server, &err)) {
+#else /* __LOCAL_ACTIVITY__ */
+ if (!bulk_flag && !imap4_mail_delete_ex(&mailbox, mail_ids, num, &err)) {
+#endif /* __LOCAL_ACTIVITY__ */
+ EM_DEBUG_EXCEPTION("imap4_mail_delete_ex failed [%d]", err);
+ if (err == EMF_ERROR_IMAP4_STORE_FAILURE)
+ err = EMF_ERROR_MAIL_NOT_FOUND_ON_SERVER;
+ goto FINISH_OFF;
+ }
+ else
+ bulk_flag = true;
+
+ }
+ else if (account->receiving_server_type == EMF_SERVER_TYPE_POP3) {
+ if (!em_core_mail_get_msgno_by_uid(account, &mailbox, mail->server_mail_id, &msgno, &err)) {
+ EM_DEBUG_EXCEPTION("em_core_mail_get_msgno_by_uid faild [%d]", err);
+ if (err == EMF_ERROR_MAIL_NOT_FOUND_ON_SERVER)
+ goto NOT_FOUND_ON_SERVER;
+ else
+ goto FINISH_OFF;
+ }
+
+ FINISH_OFF_IF_CANCELED;
+
+ if (!em_core_mail_delete_from_server(account, &mailbox, msgno, &err)) {
+ EM_DEBUG_EXCEPTION("em_core_mail_delete_from_server falied [%d]", err);
+ goto FINISH_OFF;
+ }
+#ifdef __LOCAL_ACTIVITY__
+ else {
+ /* Remove local activity */
+ emf_activity_tbl_t new_activity;
+ memset(&new_activity, 0x00, sizeof(emf_activity_tbl_t));
+ if (from_server == EMF_DELETE_FOR_SEND_THREAD) {
+ new_activity.activity_type = ACTIVITY_DELETEMAIL_SEND;
+ EM_DEBUG_LOG("from_server == EMF_DELETE_FOR_SEND_THREAD ");
+ }
+ else {
+ new_activity.activity_type = ACTIVITY_DELETEMAIL;
+ }
+
+ new_activity.mail_id = mail->mail_id;
+ new_activity.server_mailid = mail->server_mail_id;
+ new_activity.src_mbox = NULL;
+ new_activity.dest_mbox = NULL;
+
+ if (!em_core_activity_delete(&new_activity, &err)) {
+ EM_DEBUG_EXCEPTION(" em_core_activity_delete failed - %d ", err);
+ }
+
+ /* Fix for issue - Sometimes mail move and immediately followed by mail delete is not reflected on server */
+ if (!em_storage_remove_downloaded_mail(account_id, mail->server_mailbox_name, mail->server_mail_id, true, &err)) {
+ EM_DEBUG_LOG("em_storage_remove_downloaded_mail falied [%d]", err);
+ }
+ }
+
+#endif /* __LOCAL_ACTIVITY__ */
+ }
+#else /* __FEATURE_BULK_DELETE_MOVE_UPDATE_REQUEST_OPTI__ */
+ if (!em_core_mail_get_msgno_by_uid(account, &mailbox, mail->server_mail_id, &msgno, &err)) {
+ EM_DEBUG_LOG("em_core_mail_get_msgno_by_uid faild [%d]", err);
+
+ if (err == EMF_ERROR_MAIL_NOT_FOUND_ON_SERVER) /* Prevent Defect - 9561 */
+ goto NOT_FOUND_ON_SERVER;
+ else
+ goto FINISH_OFF;
+ }
+
+ FINISH_OFF_IF_CANCELED;
+
+ if (!em_core_mail_delete_from_server(account, &mailbox, msgno, &err)) {
+ EM_DEBUG_LOG("em_core_mail_delete_from_server falied [%d]", err);
+
+ goto FINISH_OFF;
+ }
+#endif /* __FEATURE_BULK_DELETE_MOVE_UPDATE_REQUEST_OPTI__ */
+
+ if (!em_storage_remove_downloaded_mail(account_id, mail->server_mailbox_name, mail->server_mail_id, true, &err))
+ EM_DEBUG_LOG("em_storage_remove_downloaded_mail falied [%d]", err);
+
+ /* em_core_delete_notification_for_read_mail(mail_id); */
+
+NOT_FOUND_ON_SERVER:
+ memset(mail_id_string, 0, 10);
+ SNPRINTF(mail_id_string, 10, "%d,", mail_id);
+ strcat(parameter_string, mail_id_string);
+
+ FINISH_OFF_IF_CANCELED;
+
+ em_storage_free_mail(&mail, 1, NULL);
+ }
+ }
+ else if (from_server == EMF_DELETE_LOCALLY) /* Local Delete */ {
+ em_core_mail_delete_from_local(account_id, mail_ids, num, noti_param_1, noti_param_2, err_code);
+ for (i = 0; i < num; i++) {
+ /* em_core_delete_notification_for_read_mail(mail_id); */
+ SNPRINTF(mail_id_string, 10, "%d,", mail_id);
+ strcat(parameter_string, mail_id_string);
+ }
+
+ em_core_check_unread_mail();
+ }
+
+ ret = true;
+
+FINISH_OFF:
+
+ if (stream) {
+ em_core_mailbox_close(0, stream);
+ stream = NULL;
+ }
+
+ if (mailbox.user_data != NULL) {
+ em_core_mailbox_free_uids(mailbox.user_data, NULL);
+ mailbox.user_data = NULL;
+ }
+
+ EM_SAFE_FREE(parameter_string);
+
+ if (mail != NULL)
+ em_storage_free_mail(&mail, 1, NULL);
+
+
+ if (from_server)
+ em_core_show_popup(account_id, EMF_ACTION_DELETE_MAIL, ret == true ? 0 : err);
+
+ if (err_code != NULL)
+ *err_code = err;
+
+ return ret;
+}
+
+
+int em_core_mail_delete_all(emf_mailbox_t *mailbox, int with_server, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("mailbox [%p], with_server [%d], err_code [%p]", mailbox, with_server, err_code);
+
+ int ret = false;
+ int err = EMF_ERROR_NONE;
+ int search_handle = 0;
+ int *mail_ids = NULL;
+ int i = 0;
+ int total = 0;
+ char buf[512] = { 0, };
+
+ if (!mailbox || mailbox->account_id < FIRST_ACCOUNT_ID) {
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ if (mailbox->name != NULL) {
+ /* Delete all mails in specific mailbox */
+ if (!em_storage_mail_search_start(NULL, mailbox->account_id, mailbox->name, 0, &search_handle, &total, true, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_mail_search_start failed [%d]", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+
+ EM_DEBUG_LOG("em_storage_mail_search_start returns [%d]", total);
+
+ if (total > 0) {
+ mail_ids = em_core_malloc(sizeof(int) * total);
+ if (mail_ids == NULL) {
+ EM_DEBUG_EXCEPTION("em_core_malloc failed...");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ for (i = 0; i < total; i++) {
+ if (!em_storage_mail_search_result(search_handle, RETRIEVE_ID, (void**)&mail_ids[i], true, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_mail_search_result failed [%d]", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+ }
+
+ if (!em_core_mail_delete(mailbox->account_id, mail_ids, total, with_server, EMF_DELETED_BY_COMMAND, false, &err)) {
+ EM_DEBUG_EXCEPTION("em_core_mail_delete failed [%d]", err);
+ goto FINISH_OFF;
+ }
+ }
+ }
+ else if (with_server == EMF_DELETE_LOCALLY){
+ /* em_storage_delete_mail_by_account is available only locally */
+ if (!em_storage_delete_mail_by_account(mailbox->account_id, false, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_delete_mail_by_account failed [%d]", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+
+ if (!em_storage_delete_attachment_all_on_db(mailbox->account_id, NULL, false, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_delete_attachment_all_on_db failed [%d]", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+
+ /* delete mail contents from filesystem */
+ if (!em_storage_get_save_name(mailbox->account_id, 0, 0, NULL, buf, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_get_save_name failed [%d]", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+
+ if (!em_storage_delete_dir(buf, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_delete_dir failed [%d]", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ }
+
+ /* delete meeting request */
+ if (!em_storage_delete_meeting_request(mailbox->account_id, 0, NULL, false, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_delete_attachment_all_on_db failed [%d]", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+
+ em_core_check_unread_mail();
+ }
+
+ ret = true;
+
+FINISH_OFF:
+ if (search_handle >= 0) {
+ if (!em_storage_mail_search_end(search_handle, true, &err))
+ EM_DEBUG_EXCEPTION("em_storage_mail_search_end failed [%d]", err);
+ }
+
+ EM_SAFE_FREE(mail_ids);
+ if (err_code != NULL)
+ *err_code = err;
+ EM_DEBUG_FUNC_END("ret [%d], err [%d]", ret, err);
+ return ret;
+}
+
+EXPORT_API int em_core_mail_delete_from_local(int account_id, int *mail_ids, int num, int noti_param_1, int noti_param_2, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("account_id[%d], mail_ids[%p], num [%d], noti_param_1 [%d], noti_param_2 [%d], err_code[%p]", account_id, mail_ids, num, noti_param_1, noti_param_2, num, err_code);
+ int ret = false, err = EMF_ERROR_NONE, i;
+ emf_mail_tbl_t *result_mail_list;
+ char mail_id_string[10], *noti_param_string = NULL, buf[512] = {0, };
+
+ /* Getting mail list by using select mail_id [in] */
+
+ if(!em_storage_get_mail_field_by_multiple_mail_id(mail_ids, num, RETRIEVE_SUMMARY, &result_mail_list, true, &err) || !result_mail_list) {
+ EM_DEBUG_EXCEPTION("em_storage_get_mail_field_by_multiple_mail_id failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ /* Deleting mails by using select mail_id [in] */
+ if(!em_storage_delete_multiple_mails(mail_ids, num, true, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_delete_multiple_mails failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ /* Sending Notification */
+ noti_param_string = em_core_malloc(sizeof(char) * 10 * num);
+
+ if(!noti_param_string) {
+ EM_DEBUG_EXCEPTION("em_core_malloc failed");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ for(i = 0; i < num; i++) {
+ memset(mail_id_string, 0, 10);
+ SNPRINTF(mail_id_string, 10, "%d,", mail_ids[i]);
+ strcat(noti_param_string, mail_id_string);
+ /* can be optimized by appending sub string with directly pointing on string array kyuho.jo 2011-10-07 */
+ }
+
+ if (!em_storage_notify_storage_event(NOTI_MAIL_DELETE, account_id, noti_param_1, noti_param_string, noti_param_2))
+ EM_DEBUG_EXCEPTION(" em_storage_notify_storage_event failed [ NOTI_MAIL_DELETE_FINISH ] >>>> ");
+
+ /* Updating Thread informations */
+ /* Thread information should be updated as soon as possible. */
+ for(i = 0; i < num; i++) {
+ if (result_mail_list[i].thread_item_count > 1) {
+ if (!em_storage_update_latest_thread_mail(account_id, result_mail_list[i].thread_id, 0, 0, false, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_update_latest_thread_mail failed [%d]", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+ }
+ }
+ if (!em_storage_notify_storage_event(NOTI_MAIL_DELETE_FINISH, account_id, noti_param_1, noti_param_string, noti_param_2))
+ EM_DEBUG_EXCEPTION(" em_storage_notify_storage_event failed [ NOTI_MAIL_DELETE_FINISH ] >>>> ");
+
+ for(i = 0; i < num; i++) {
+ /* Deleting attachments */
+ if (!em_storage_delete_attachment_on_db(result_mail_list[i].mail_id, 0, false, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_delete_attachment_on_db failed [%d]", err);
+
+ if (err == EM_STORAGE_ERROR_ATTACHMENT_NOT_FOUND)
+ err = EMF_ERROR_NONE;
+ else
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ }
+
+ /* Deleting Directories */
+ /* delete mail contents from filesystem */
+ if (!em_storage_get_save_name(account_id, result_mail_list[i].mail_id, 0, NULL, buf, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_get_save_name failed [%d]", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+
+ if (!em_storage_delete_dir(buf, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_delete_dir failed [%d]", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ }
+
+ /* Deleting Meeting Request */
+ if (!em_storage_delete_meeting_request(account_id, result_mail_list[i].mail_id, NULL, false, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_delete_meeting_request failed [%d]", err);
+ if (err != EM_STORAGE_ERROR_CONTACT_NOT_FOUND) {
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+ }
+ }
+
+ ret = true;
+
+FINISH_OFF:
+ EM_SAFE_FREE(noti_param_string);
+
+ if (err_code != NULL)
+ *err_code = err;
+
+ EM_DEBUG_FUNC_END();
+ return ret;
+}
+
+int em_core_mail_delete_from_server(emf_account_t *account, emf_mailbox_t *mailbox, int msgno, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("account[%p], mailbox[%p], msgno[%d], err_code[%p]", account, mailbox, msgno, err_code);
+
+ int ret = false;
+ int err = EMF_ERROR_NONE;
+
+ if (!account || !mailbox) {
+ EM_DEBUG_EXCEPTION("account[%p], mailbox[%p], msgno[%d]", account, mailbox, msgno);
+
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ if (account->receiving_server_type == EMF_SERVER_TYPE_POP3) {
+ if (!pop3_mail_delete(mailbox->mail_stream, msgno, &err)) {
+ EM_DEBUG_EXCEPTION("pop3_mail_delete failed [%d]", err);
+
+ if (err == EMF_ERROR_POP3_DELE_FAILURE)
+ err = EMF_ERROR_MAIL_NOT_FOUND_ON_SERVER;
+ goto FINISH_OFF;
+ }
+ }
+ else { /* EMF_SERVER_TYPE_IMAP4 */
+ if (!imap4_mail_delete(mailbox->mail_stream, msgno, &err)) {
+ EM_DEBUG_EXCEPTION("imap4_mail_delete failed [%d]", err);
+
+ if (err == EMF_ERROR_IMAP4_STORE_FAILURE)
+ err = EMF_ERROR_MAIL_NOT_FOUND_ON_SERVER;
+ goto FINISH_OFF;
+ }
+ }
+
+ ret = true;
+
+FINISH_OFF:
+ if (err_code)
+ *err_code = err;
+ EM_DEBUG_FUNC_END();
+ return ret;
+}
+
+EXPORT_API int em_core_mail_get_msgno_by_uid(emf_account_t *account, emf_mailbox_t *mailbox, char *uid, int *msgno, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("account[%p], mailbox[%p], uid[%s], msgno[%p], err_code[%p]", account, mailbox, uid, msgno, err_code);
+
+ int ret = false;
+ int err = EMF_ERROR_NONE;
+
+ em_core_uid_list *uid_list = NULL;
+ em_core_uid_list *pTemp_uid_list = NULL;
+
+ if (!account || !mailbox || !uid || !msgno) {
+ EM_DEBUG_EXCEPTION("account[%p], mailbox[%p], uid[%s], msgno[%p]", account, mailbox, uid, msgno);
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ uid_list = mailbox->user_data;
+
+ if (uid_list == NULL) {
+ if (account->receiving_server_type == EMF_SERVER_TYPE_POP3) {
+ if (!pop3_mailbox_get_uids(mailbox->mail_stream, &uid_list, &err)) {
+ EM_DEBUG_EXCEPTION("pop3_mailbox_get_uids failed [%d]", err);
+ goto FINISH_OFF;
+ }
+ }
+ else { /* EMF_SERVER_TYPE_IMAP4 */
+ if (!imap4_mailbox_get_uids(mailbox->mail_stream, &uid_list, &err)) {
+ EM_DEBUG_EXCEPTION("imap4_mailbox_get_uids failed [%d]", err);
+ goto FINISH_OFF;
+ }
+ }
+ mailbox->user_data = uid_list;
+ }
+ pTemp_uid_list = uid_list;
+ while (uid_list) {
+ if (!strcmp(uid_list->uid, uid)) {
+ *msgno = uid_list->msgno;
+ EM_DEBUG_LOG("uid_list->msgno[%d]", uid_list->msgno);
+ ret = true;
+ goto FINISH_OFF;
+ }
+ EM_DEBUG_LOG("other uid_list->msgno[%d]", uid_list->msgno);
+ uid_list = uid_list->next;
+ }
+
+ err = EMF_ERROR_MAIL_NOT_FOUND_ON_SERVER;
+
+FINISH_OFF:
+ if (err_code != NULL)
+ *err_code = err;
+ uid_list = pTemp_uid_list ;
+ if (uid_list != NULL)
+ em_core_mailbox_free_uids(uid_list, NULL);
+ /* mailbox->user_data and uid_list both point to same memory address, So when uid_list is freed then just set */
+ /* mailbox->user_data to NULL and dont use EM_SAFE_FREE, it will crash : ) */
+ if (mailbox)
+ mailbox->user_data = NULL;
+ EM_DEBUG_FUNC_END();
+ return ret;
+}
+
+/* description
+ * add a attachment to mail.
+ * arguments
+ * mailbox : mail box
+ * mail_id : mail id
+ * attachment : attachment to be added
+ * return
+ * succeed : 1
+ * fail : 0
+ */
+EXPORT_API int em_core_mail_add_attachment(int mail_id, emf_attachment_info_t *attachment, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("mail_id[%d], attachment[%p], err_code[%p]", mail_id, attachment, err_code);
+
+ if (attachment == NULL) {
+ EM_DEBUG_EXCEPTION("mail_id[%d], attachment[%p]", mail_id, attachment);
+ if (err_code)
+ *err_code = EMF_ERROR_INVALID_PARAM;
+ return false;
+ }
+
+ int ret = false, err = EMF_ERROR_NONE;
+ emf_mail_tbl_t *mail_table_data = NULL;
+ int attachment_id = 0;
+
+
+
+ if (!em_storage_get_mail_field_by_id(mail_id, RETRIEVE_SUMMARY, &mail_table_data, true, &err) || !mail_table_data) {
+ EM_DEBUG_EXCEPTION("em_storage_get_mail_field_by_id failed [%d]", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF2;
+ }
+
+ int account_id = mail_table_data->account_id;
+ emf_mail_attachment_tbl_t attachment_tbl;
+
+ memset(&attachment_tbl, 0x00, sizeof(emf_mail_attachment_tbl_t));
+
+ mail_table_data->attachment_count = mail_table_data->attachment_count + 1;
+ attachment_tbl.account_id = mail_table_data->account_id;
+ attachment_tbl.mailbox_name = mail_table_data->mailbox_name;
+ attachment_tbl.mail_id = mail_id;
+ attachment_tbl.attachment_name = attachment->name;
+ attachment_tbl.attachment_size = attachment->size;
+ attachment_tbl.file_yn = attachment->downloaded;
+ attachment_tbl.flag1 = attachment->drm;
+ attachment_tbl.flag3 = attachment->inline_content;
+
+ /* BEGIN TRANSACTION; */
+ em_storage_begin_transaction(NULL, NULL, NULL);
+
+ if (!em_storage_add_attachment(&attachment_tbl, 0, false, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_add_attachment failed [%d]", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+
+ attachment->attachment_id = attachment_tbl.attachment_id;
+
+ if (attachment->savename) {
+ char buf[512];
+
+ if (!attachment->inline_content) {
+ if (!em_storage_create_dir(account_id, mail_id, attachment_tbl.attachment_id, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_create_dir failed [%d]", err);
+ goto FINISH_OFF;
+ }
+ attachment_id = attachment_tbl.attachment_id;
+ }
+
+ if (!em_storage_get_save_name(account_id, mail_id, attachment_id, attachment->name, buf, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_get_save_name failed [%d]", err);
+ goto FINISH_OFF;
+ }
+ attachment_tbl.attachment_path = buf;
+
+ if (!em_storage_change_attachment_field(mail_id, UPDATE_SAVENAME, &attachment_tbl, false, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_change_attachment_field failed [%d]", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+
+ if (!em_storage_change_mail_field(mail_id, APPEND_BODY, mail_table_data, false, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_change_mail_field failed [%d]", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+
+ if (attachment->downloaded) {
+ if (!em_storage_move_file(attachment->savename, buf, false, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_move_file failed [%d]", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+ }
+
+ /* Here only filename is being updated. Since first add is being done there will not be any old files.
+ So no need to check for old files in this update case */
+ if (!em_storage_change_attachment_field(mail_id, UPDATE_SAVENAME, &attachment_tbl, false, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_change_attachment_field failed [%d]", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+
+ EM_SAFE_FREE(attachment->savename);
+ attachment->savename = EM_SAFE_STRDUP(buf);
+ }
+
+ ret = true;
+
+FINISH_OFF:
+ if (ret == true) { /* COMMIT TRANSACTION; */
+ if (em_storage_commit_transaction(NULL, NULL, NULL) == false) {
+ err = em_storage_get_emf_error_from_em_storage_error(EM_STORAGE_ERROR_DB_FAILURE);
+ ret = false;
+ }
+ }
+ else { /* ROLLBACK TRANSACTION; */
+ if (em_storage_rollback_transaction(NULL, NULL, NULL) == false)
+ err = em_storage_get_emf_error_from_em_storage_error(EM_STORAGE_ERROR_DB_FAILURE);
+ }
+
+FINISH_OFF2:
+ if (mail_table_data != NULL)
+ em_storage_free_mail(&mail_table_data, 1, NULL);
+
+ if (err_code)
+ *err_code = err;
+ EM_DEBUG_FUNC_END("err [%d]", err);
+ return ret;
+}
+
+
+EXPORT_API int em_core_mail_add_attachment_data(int input_mail_id, emf_attachment_data_t *input_attachment_data)
+{
+ EM_DEBUG_FUNC_BEGIN("input_mail_id[%d], input_attachment_data[%p]", input_mail_id, input_attachment_data);
+
+ int err = EMF_ERROR_NONE;
+ int attachment_id = 0;
+ char buf[512] = { 0, };
+ emf_mail_tbl_t *mail_table_data = NULL;
+ emf_mail_attachment_tbl_t attachment_tbl = { 0 };
+
+ if (input_attachment_data == NULL) {
+ EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
+ return EMF_ERROR_INVALID_PARAM;
+ }
+
+ if (!em_storage_get_mail_field_by_id(input_mail_id, RETRIEVE_SUMMARY, &mail_table_data, true, &err) || !mail_table_data) {
+ EM_DEBUG_EXCEPTION("em_storage_get_mail_field_by_id failed [%d]", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF2;
+ }
+
+ mail_table_data->attachment_count = mail_table_data->attachment_count + 1;
+
+ attachment_tbl.account_id = mail_table_data->account_id;
+ attachment_tbl.mailbox_name = mail_table_data->mailbox_name;
+ attachment_tbl.mail_id = input_mail_id;
+ attachment_tbl.attachment_name = input_attachment_data->attachment_name;
+ attachment_tbl.attachment_size = input_attachment_data->attachment_size;
+ attachment_tbl.file_yn = input_attachment_data->save_status;
+ attachment_tbl.flag1 = input_attachment_data->drm_status;
+ attachment_tbl.flag3 = input_attachment_data->inline_content_status;
+
+ /* BEGIN TRANSACTION; */
+ em_storage_begin_transaction(NULL, NULL, NULL);
+
+ if (!em_storage_add_attachment(&attachment_tbl, 0, false, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_add_attachment failed [%d]", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+
+ input_attachment_data->attachment_id = attachment_tbl.attachment_id;
+
+ if (input_attachment_data->attachment_path) {
+ if (!input_attachment_data->inline_content_status) {
+ if (!em_storage_create_dir(mail_table_data->account_id, input_mail_id, attachment_tbl.attachment_id, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_create_dir failed [%d]", err);
+ goto FINISH_OFF;
+ }
+ attachment_id = attachment_tbl.attachment_id;
+ }
+
+ if (!em_storage_get_save_name(mail_table_data->account_id, input_mail_id, attachment_id, input_attachment_data->attachment_name, buf, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_get_save_name failed [%d]", err);
+ goto FINISH_OFF;
+ }
+ attachment_tbl.attachment_path = buf;
+
+ if (!em_storage_change_attachment_field(input_mail_id, UPDATE_SAVENAME, &attachment_tbl, false, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_change_attachment_field failed [%d]", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+
+ if (!em_storage_change_mail_field(input_mail_id, APPEND_BODY, mail_table_data, false, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_change_mail_field failed [%d]", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+
+ if (input_attachment_data->save_status) {
+ if (!em_storage_move_file(input_attachment_data->attachment_path, buf, false, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_move_file failed [%d]", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+ }
+
+ /* Here only filename is being updated. Since first add is being done there will not be any old files.
+ So no need to check for old files in this update case */
+ if (!em_storage_change_attachment_field(input_mail_id, UPDATE_SAVENAME, &attachment_tbl, false, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_change_attachment_field failed [%d]", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+
+ EM_SAFE_FREE(input_attachment_data->attachment_path);
+ input_attachment_data->attachment_path = EM_SAFE_STRDUP(buf);
+ }
+
+FINISH_OFF:
+ if (err == EMF_ERROR_NONE) { /* COMMIT TRANSACTION; */
+ if (em_storage_commit_transaction(NULL, NULL, NULL) == false) {
+ err = em_storage_get_emf_error_from_em_storage_error(EM_STORAGE_ERROR_DB_FAILURE);
+ }
+ }
+ else { /* ROLLBACK TRANSACTION; */
+ if (em_storage_rollback_transaction(NULL, NULL, NULL) == false)
+ err = em_storage_get_emf_error_from_em_storage_error(EM_STORAGE_ERROR_DB_FAILURE);
+ }
+
+FINISH_OFF2:
+ if (mail_table_data != NULL)
+ em_storage_free_mail(&mail_table_data, 1, NULL);
+
+ EM_DEBUG_FUNC_END("err [%d]", err);
+ return err;
+}
+
+
+/* description
+ * delete a attachment from mail.
+ * arguments
+ * mailbox : mail box
+ * mail_id : mail id
+ * attachment_id : number string of attachment-id to be deleted
+ * (ex : if attachment id is 2, number stirng will be "2")
+ * return
+ * succeed : 1
+ * fail : 0
+ */
+int em_core_mail_delete_attachment(int mail_id, char *attachment_id_string, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("mail_id[%d], attachment_id_string[%s], err_code[%p]", mail_id, attachment_id_string, err_code);
+
+ if (attachment_id_string == NULL) {
+ EM_DEBUG_EXCEPTION("mail_id[%d], attachment_id[%p]", mail_id, attachment_id_string);
+ if (err_code != NULL)
+ *err_code = EMF_ERROR_INVALID_PARAM;
+ return false;
+ }
+
+ int ret = false;
+ int error = EMF_ERROR_NONE;
+ int attachment_id = atoi(attachment_id_string);
+
+ /* BEGIN TRANSACTION; */
+ em_storage_begin_transaction(NULL, NULL, NULL);
+
+ if (!em_storage_delete_attachment_on_db(mail_id, attachment_id, false, &error)) {
+ EM_DEBUG_EXCEPTION("em_storage_delete_attachment_on_db failed [%d]", error);
+ goto FINISH_OFF;
+ }
+
+ ret = true;
+
+FINISH_OFF:
+ if (ret == true) { /* COMMIT TRANSACTION; */
+ if (em_storage_commit_transaction(NULL, NULL, NULL) == false) {
+ error = em_storage_get_emf_error_from_em_storage_error(EM_STORAGE_ERROR_DB_FAILURE);
+ ret = false;
+ }
+ }
+ else { /* ROLLBACK TRANSACTION; */
+ if (em_storage_rollback_transaction(NULL, NULL, NULL) == false)
+ error = em_storage_get_emf_error_from_em_storage_error(EM_STORAGE_ERROR_DB_FAILURE);
+ }
+
+ if (err_code != NULL)
+ *err_code = error;
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+/* description
+ * update a attachment to mail.
+ * arguments
+ * mailbox : mail box
+ * mail_id : mail id
+ * attachment : attachment to be added
+ * return
+ * succeed : 1
+ * fail : 0
+ */
+static int em_core_mail_update_attachment(int mail_id, emf_attachment_info_t *updated_attachment, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("mail_id[%d], attachment[%p], err_code[%p]", mail_id, updated_attachment, err_code);
+
+ int ret = false, err = EMF_ERROR_NONE;
+ emf_mail_attachment_tbl_t *existing_attachment_info = NULL;
+ emf_mail_attachment_tbl_t attachment_tbl;
+
+ if (updated_attachment == NULL) {
+ EM_DEBUG_EXCEPTION("Invalid Parameter");
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF2;
+ }
+
+ if (!em_storage_get_attachment(mail_id, updated_attachment->attachment_id, &existing_attachment_info, 1, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_get_attachment failed [%d]", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF2;
+ }
+
+ memset(&attachment_tbl, 0x00, sizeof(emf_mail_attachment_tbl_t));
+
+ attachment_tbl.mail_id = mail_id;
+ attachment_tbl.account_id = existing_attachment_info->account_id;
+ attachment_tbl.mailbox_name = existing_attachment_info->mailbox_name;
+ attachment_tbl.attachment_name = updated_attachment->name;
+ attachment_tbl.attachment_size = updated_attachment->size;
+ attachment_tbl.attachment_path = updated_attachment->savename;
+ attachment_tbl.file_yn = updated_attachment->downloaded;
+ attachment_tbl.flag1 = updated_attachment->drm;
+ attachment_tbl.flag3 = updated_attachment->inline_content;
+ attachment_tbl.attachment_id = updated_attachment->attachment_id;
+
+ char buf[512];
+ int attachment_id = 0;
+
+ /* EM_DEBUG_LOG("file is downloaded and different from old one. it should be moved"); */
+
+ if (!updated_attachment->inline_content) {
+ if (!em_storage_create_dir(attachment_tbl.account_id, mail_id, attachment_tbl.attachment_id, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_create_dir failed [%d]", err);
+ goto FINISH_OFF;
+ }
+ attachment_id = attachment_tbl.attachment_id;
+ }
+
+ if (!em_storage_get_save_name(attachment_tbl.account_id, mail_id, attachment_id, updated_attachment->name, buf, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_get_save_name failed [%d]", err);
+ goto FINISH_OFF2;
+ }
+ attachment_tbl.attachment_path = buf;
+
+ EM_DEBUG_LOG("downloaded [%d], savename [%s], attachment_path [%s]", updated_attachment->downloaded, updated_attachment->savename, existing_attachment_info->attachment_path);
+ if (updated_attachment->downloaded && EM_SAFE_STRCMP(updated_attachment->savename, existing_attachment_info->attachment_path) != 0) {
+ if (!em_storage_move_file(updated_attachment->savename, buf, false ,&err)) {
+ EM_DEBUG_EXCEPTION("em_storage_move_file failed [%d]", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF2;
+ }
+ }
+ else
+ EM_DEBUG_LOG("no need to move");
+
+ EM_SAFE_FREE(updated_attachment->savename);
+ updated_attachment->savename = EM_SAFE_STRDUP(buf);
+
+ em_storage_begin_transaction(NULL, NULL, NULL);
+
+ if (!em_storage_update_attachment(&attachment_tbl, false, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_update_attachment failed [%d]", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+
+ ret = true;
+
+FINISH_OFF:
+ if (ret == true) { /* COMMIT TRANSACTION; */
+ if (em_storage_commit_transaction(NULL, NULL, NULL) == false) {
+ err = em_storage_get_emf_error_from_em_storage_error(EM_STORAGE_ERROR_DB_FAILURE);
+ ret = false;
+ }
+ }
+ else { /* ROLLBACK TRANSACTION; */
+ if (em_storage_rollback_transaction(NULL, NULL, NULL) == false)
+ err = em_storage_get_emf_error_from_em_storage_error(EM_STORAGE_ERROR_DB_FAILURE);
+ }
+
+FINISH_OFF2:
+ if (existing_attachment_info)
+ em_storage_free_attachment(&existing_attachment_info, 1, NULL);
+
+ if (err_code)
+ *err_code = err;
+ EM_DEBUG_FUNC_END("err [%d]", err);
+ return ret;
+}
+
+static int em_core_mail_update_attachment_data(int input_mail_id, emf_attachment_data_t *input_attachment_data)
+{
+ EM_DEBUG_FUNC_BEGIN("input_mail_id[%d], input_attachment_data[%p]", input_mail_id, input_attachment_data);
+
+ int err = EMF_ERROR_NONE;
+ int attachment_id = 0;
+ char buf[512] = { 0 , };
+ emf_mail_attachment_tbl_t *existing_attachment_info = NULL;
+ emf_mail_attachment_tbl_t attachment_tbl = { 0 };
+
+ if (input_attachment_data == NULL) {
+ EM_DEBUG_EXCEPTION("Invalid Parameter");
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF2;
+ }
+
+ if (!em_storage_get_attachment(input_mail_id, input_attachment_data->attachment_id, &existing_attachment_info, 1, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_get_attachment failed [%d]", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF2;
+ }
+
+ attachment_tbl.mail_id = input_mail_id;
+ attachment_tbl.account_id = existing_attachment_info->account_id;
+ attachment_tbl.mailbox_name = existing_attachment_info->mailbox_name;
+ attachment_tbl.attachment_name = input_attachment_data->attachment_name;
+ attachment_tbl.attachment_size = input_attachment_data->attachment_size;
+ attachment_tbl.attachment_path = input_attachment_data->attachment_path;
+ attachment_tbl.file_yn = input_attachment_data->save_status;
+ attachment_tbl.flag1 = input_attachment_data->drm_status;
+ attachment_tbl.flag3 = input_attachment_data->inline_content_status;
+ attachment_tbl.attachment_id = input_attachment_data->attachment_id;
+
+ if (!input_attachment_data->inline_content_status) {
+ if (!em_storage_create_dir(attachment_tbl.account_id, input_mail_id, attachment_tbl.attachment_id, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_create_dir failed [%d]", err);
+ goto FINISH_OFF;
+ }
+ attachment_id = attachment_tbl.attachment_id;
+ }
+
+ if (!em_storage_get_save_name(attachment_tbl.account_id, input_mail_id, attachment_id, input_attachment_data->attachment_name, buf, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_get_save_name failed [%d]", err);
+ goto FINISH_OFF2;
+ }
+ attachment_tbl.attachment_path = buf;
+
+ EM_DEBUG_LOG("downloaded [%d], savename [%s], attachment_path [%s]", input_attachment_data->save_status, input_attachment_data->attachment_path, existing_attachment_info->attachment_path);
+ if (input_attachment_data->save_status && EM_SAFE_STRCMP(input_attachment_data->attachment_path, existing_attachment_info->attachment_path) != 0) {
+ if (!em_storage_move_file(input_attachment_data->attachment_path, buf, false ,&err)) {
+ EM_DEBUG_EXCEPTION("em_storage_move_file failed [%d]", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF2;
+ }
+ }
+ else
+ EM_DEBUG_LOG("no need to move");
+
+ EM_SAFE_FREE(input_attachment_data->attachment_path);
+ input_attachment_data->attachment_path = EM_SAFE_STRDUP(buf);
+
+ em_storage_begin_transaction(NULL, NULL, NULL);
+
+ if (!em_storage_update_attachment(&attachment_tbl, false, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_update_attachment failed [%d]", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+
+FINISH_OFF:
+ if (err == EMF_ERROR_NONE) { /* COMMIT TRANSACTION; */
+ if (em_storage_commit_transaction(NULL, NULL, NULL) == false) {
+ err = em_storage_get_emf_error_from_em_storage_error(EM_STORAGE_ERROR_DB_FAILURE);
+ }
+ }
+ else { /* ROLLBACK TRANSACTION; */
+ if (em_storage_rollback_transaction(NULL, NULL, NULL) == false)
+ err = em_storage_get_emf_error_from_em_storage_error(EM_STORAGE_ERROR_DB_FAILURE);
+ }
+
+FINISH_OFF2:
+ if (existing_attachment_info)
+ em_storage_free_attachment(&existing_attachment_info, 1, NULL);
+
+ EM_DEBUG_FUNC_END("err [%d]", err);
+ return err;
+}
+
+
+static int em_core_mail_compare_filename_of_attachment(int mail_id, int attachment_a_id, emf_attachment_info_t *attachment_b_info, int *result, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("mail_id[%d], attachment_a_id[%d], attachment_b_info[%p], result[%p], err_code[%p]", mail_id, attachment_a_id, attachment_b_info, result, err_code);
+
+ EM_IF_NULL_RETURN_VALUE(attachment_b_info, false);
+ EM_IF_NULL_RETURN_VALUE(result, false);
+
+ int err, err_2, ret = false;
+ emf_mail_attachment_tbl_t *attachment_a_tbl = NULL;
+
+ if (!em_storage_get_attachment(mail_id, attachment_a_id, &attachment_a_tbl, 1, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_get_attachment failed [%d]", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+
+ if (attachment_a_tbl->attachment_name && attachment_b_info->savename) {
+ EM_DEBUG_LOG("attachment_a_tbl->attachment_name [%s], ttachment_b_info->name [%s]", attachment_a_tbl->attachment_name, attachment_b_info->name);
+ *result = strcmp(attachment_a_tbl->attachment_name, attachment_b_info->name);
+ }
+
+ ret = true;
+
+FINISH_OFF:
+
+ if (attachment_a_tbl)
+ em_storage_free_attachment(&attachment_a_tbl, 1, &err_2);
+ EM_DEBUG_FUNC_END("*result [%d]", *result);
+ return ret;
+}
+
+static int em_core_mail_compare_filename_of_attachment_data(int input_mail_id, int input_attachment_a_id, emf_attachment_data_t *input_attachment_b_data, int *result)
+{
+ EM_DEBUG_FUNC_BEGIN("input_mail_id[%d], input_attachment_a_id[%d], input_attachment_b_data[%p], result[%p]", input_mail_id, input_attachment_a_id, input_attachment_b_data, result);
+
+ EM_IF_NULL_RETURN_VALUE(input_attachment_b_data, false);
+ EM_IF_NULL_RETURN_VALUE(result, false);
+
+ int err, err_2, ret = EMF_ERROR_NONE;
+ emf_mail_attachment_tbl_t *attachment_a_tbl = NULL;
+
+ if (!em_storage_get_attachment(input_mail_id, input_attachment_a_id, &attachment_a_tbl, 1, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_get_attachment failed [%d]", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+
+ if (attachment_a_tbl->attachment_name && input_attachment_b_data->attachment_name) {
+ EM_DEBUG_LOG("attachment_a_tbl->attachment_name [%s], input_attachment_b_data->name [%s]", attachment_a_tbl->attachment_name, input_attachment_b_data->attachment_name);
+ *result = strcmp(attachment_a_tbl->attachment_name, input_attachment_b_data->attachment_name);
+ }
+
+ ret = true;
+
+FINISH_OFF:
+
+ if (attachment_a_tbl)
+ em_storage_free_attachment(&attachment_a_tbl, 1, &err_2);
+ EM_DEBUG_FUNC_END("*result [%d]", *result);
+ return ret;
+}
+
+
+/* description
+ * copy a mail to mail box
+ * arguments
+ * src_mailbox : source mail box
+ * msgno : mail sequence
+ * dst_mailbox : target mail box
+ * return
+ * succeed : 1
+ * fail : 0
+ */
+EXPORT_API int em_core_mail_copy(int mail_id, emf_mailbox_t *dst_mailbox, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("mail_id[%d], dst_mailbox[%p], err_code[%p]", mail_id, dst_mailbox, err_code);
+
+ int ret = false;
+ int err = EMF_ERROR_NONE;
+ int i;
+ emf_mail_tbl_t *mail = NULL;
+ emf_mail_attachment_tbl_t *atch_list = NULL;
+ char buf[512];
+ int count = EMF_ATTACHMENT_MAX_COUNT;
+ char *mailbox_name = NULL;
+
+ if (!em_storage_get_mail_by_id(mail_id, &mail, true, &err) || !mail) {
+ EM_DEBUG_EXCEPTION("em_storage_get_mail_by_id failed [%d]", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+
+ if ( (err = em_storage_get_attachment_list(mail_id, true, &atch_list, &count)) != EM_STORAGE_ERROR_NONE ){
+ EM_DEBUG_EXCEPTION("em_storage_get_attachment_list failed [%d]", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+
+ /* get increased uid. */
+ if (!em_storage_increase_mail_id(&mail->mail_id, true, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_increase_mail_id failed [%d]", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+
+ /* copy mail body(text) file */
+ if (mail->file_path_plain) {
+ if (!em_storage_create_dir(dst_mailbox->account_id, mail->mail_id, 0, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_create_dir failed [%d]", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+
+ gchar *filename = g_path_get_basename(mail->file_path_plain);
+
+ if (!em_storage_get_save_name(dst_mailbox->account_id, mail->mail_id, 0, filename, buf, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_get_save_name failed [%d]", err);
+ g_free(filename);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+
+ g_free(filename);
+
+ if (!em_storage_copy_file(mail->file_path_plain, buf, false, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_copy_file failed [%d]", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+
+ mail->file_path_plain = EM_SAFE_STRDUP(buf);
+ }
+
+ /* copy mail body(html) file */
+ if (mail->file_path_html) {
+ if (!em_storage_create_dir(dst_mailbox->account_id, mail->mail_id, 0, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_create_dir failed [%d]", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+
+ gchar *filename = g_path_get_basename(mail->file_path_html);
+
+ if (!em_storage_get_save_name(dst_mailbox->account_id, mail->mail_id, 0, filename, buf, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_get_save_name failed [%d]", err);
+ g_free(filename);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+
+ g_free(filename);
+
+ if (!em_storage_copy_file(mail->file_path_html, buf, false, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_copy_file failed [%d]", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+
+ mail->file_path_html = EM_SAFE_STRDUP(buf);
+ }
+
+ /* BEGIN TRANSACTION; */
+ em_storage_begin_transaction(NULL, NULL, NULL);
+
+ /* insert mail data */
+ EM_SAFE_FREE(mail->mailbox_name);
+
+ mail->account_id = dst_mailbox->account_id; /* MUST BE */
+ mail->mailbox_name = EM_SAFE_STRDUP(dst_mailbox->name);
+ mail->mailbox_type = dst_mailbox->mailbox_type;
+
+ if (!em_storage_add_mail(mail, 0, false, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_add_mail failed [%d]", err);
+
+ if (mail->file_path_plain) {
+ if (!em_storage_delete_file(mail->file_path_plain, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_delete_file failed [%d]", err);
+ em_storage_rollback_transaction(NULL, NULL, NULL);
+ goto FINISH_OFF;
+ }
+ }
+ if (mail->file_path_html) {
+ if (!em_storage_delete_file(mail->file_path_html, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_delete_file failed [%d]", err);
+ em_storage_rollback_transaction(NULL, NULL, NULL);
+ goto FINISH_OFF;
+ }
+ }
+
+ /* ROLLBACK TRANSACTION; */
+ em_storage_rollback_transaction(NULL, NULL, NULL);
+
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+
+ /* copy attachment file */
+ for (i = 0; i<count; i++) {
+ if (atch_list[i].attachment_path) {
+ if (!em_storage_create_dir(dst_mailbox->account_id, mail->mail_id, i+1, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_create_dir failed [%d]", err);
+ break;
+ }
+
+ if (!em_storage_get_save_name(dst_mailbox->account_id, mail->mail_id, i+1, atch_list[i].attachment_name, buf, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_get_save_name failed [%d]", err);
+ break;
+ }
+
+ if (!em_storage_copy_file(atch_list[i].attachment_path, buf, false, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_copy_file failed [%d]", err);
+ break;
+ }
+
+ EM_SAFE_FREE(atch_list[i].attachment_path);
+
+ atch_list[i].attachment_path = EM_SAFE_STRDUP(buf);
+ }
+
+ atch_list[i].account_id = dst_mailbox->account_id;
+ atch_list[i].mail_id = mail->mail_id;
+
+ EM_SAFE_FREE(atch_list[i].mailbox_name);
+
+ atch_list[i].mailbox_name = EM_SAFE_STRDUP(mail->mailbox_name);
+
+ if (!em_storage_add_attachment(&atch_list[i], 0, false, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_add_attachment failed [%d]", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ break;
+ }
+ }
+
+ /* in case error happened, delete copied file. */
+ if (i && i != count) {
+ for (;i >= 0; i--) {
+ if (atch_list[i].attachment_path) {
+
+ if (!em_storage_delete_file(atch_list[i].attachment_path, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_delete_file failed [%d]", err);
+ em_storage_rollback_transaction(NULL, NULL, NULL);
+ goto FINISH_OFF;
+ }
+ }
+ }
+
+ if (mail->file_path_plain) {
+ if (!em_storage_delete_file(mail->file_path_plain, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_delete_file failed [%d]", err);
+ em_storage_rollback_transaction(NULL, NULL, NULL);
+ goto FINISH_OFF;
+ }
+ }
+ if (mail->file_path_html) {
+ if (!em_storage_delete_file(mail->file_path_html, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_delete_file failed [%d]", err);
+ em_storage_rollback_transaction(NULL, NULL, NULL);
+ goto FINISH_OFF;
+ }
+ }
+
+ /* ROLLBACK TRANSACTION; */
+ em_storage_rollback_transaction(NULL, NULL, NULL);
+ goto FINISH_OFF;
+ }
+
+ if (em_storage_commit_transaction(NULL, NULL, NULL) == false) {
+ err = em_storage_get_emf_error_from_em_storage_error(EM_STORAGE_ERROR_DB_FAILURE);
+ if (em_storage_rollback_transaction(NULL, NULL, NULL) == false)
+ err = em_storage_get_emf_error_from_em_storage_error(EM_STORAGE_ERROR_DB_FAILURE);
+ goto FINISH_OFF;
+ }
+
+ if (!em_storage_get_mailboxname_by_mailbox_type(dst_mailbox->account_id, EMF_MAILBOX_TYPE_INBOX, &mailbox_name, false, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_get_mailboxname_by_mailbox_type failed [%d]", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+
+ if (!strcmp(dst_mailbox->name, mailbox_name) && !(mail->flags_seen_field))
+ em_core_check_unread_mail();
+
+ ret = true;
+
+FINISH_OFF:
+ if (atch_list != NULL)
+ em_storage_free_attachment(&atch_list, count, NULL);
+
+ if (mail != NULL)
+ em_storage_free_mail(&mail, 1, NULL);
+
+ EM_SAFE_FREE(mailbox_name);
+
+ if (err_code != NULL)
+ *err_code = err;
+ EM_DEBUG_FUNC_END("err [%d]", err);
+ return ret;
+}
+
+/* description
+ * move a mail to mail box
+ * arguments
+ * old_mailbox : previous mail box
+ * msgno : msgno
+ * new_mailbox : target mail box
+ * return
+ * succeed : 1
+ * fail : 0
+ */
+EXPORT_API int em_core_mail_move(int mail_ids[], int mail_ids_count, char *dst_mailbox_name, int noti_param_1, int noti_param_2 ,int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("mail_ids[%p], mail_ids_count[%d], dst_mailbox_name[%s], noti_param [%d], err_code[%p]", mail_ids, mail_ids_count, dst_mailbox_name, noti_param_1, err_code);
+
+ int ret = false;
+ int err = EMF_ERROR_NONE;
+ emf_mail_tbl_t *mail_list = NULL;
+ int account_id = 0;
+ int i = 0, parameter_string_length = 0;
+ char *parameter_string = NULL, mail_id_string[10];
+ emf_mail_attachment_tbl_t attachment;
+
+ if (!dst_mailbox_name && mail_ids_count < 1) {
+ EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ if (!em_storage_get_mail_field_by_multiple_mail_id(mail_ids, mail_ids_count, RETRIEVE_FLAG, &mail_list, true, &err) || !mail_list) {
+ EM_DEBUG_EXCEPTION("em_storage_get_mail_field_by_multiple_mail_id failed [%d]", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+
+ account_id = mail_list[0].account_id;
+
+ if(!em_storage_move_multiple_mails(account_id, dst_mailbox_name, mail_ids, mail_ids_count, true, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_move_multiple_mails failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ /* Sending a notification */
+ parameter_string_length = sizeof(char) * (mail_ids_count * 10 + 128/*MAILBOX_LEN_IN_MAIL_TBL*/ * 2);
+ parameter_string = em_core_malloc(parameter_string_length);
+
+ if (mail_list[0].mailbox_name)
+ SNPRINTF(parameter_string, parameter_string_length, "%s%c%s%c", mail_list[0].mailbox_name, 0x01, dst_mailbox_name , 0x01);
+
+ if (parameter_string == NULL) {
+ EM_DEBUG_EXCEPTION("Memory allocation for mail_id_list_string failed");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ for (i = 0; i < mail_ids_count; i++) {
+ memset(mail_id_string, 0, 10);
+ SNPRINTF(mail_id_string, 10, "%d,", mail_ids[i]);
+ strcat(parameter_string, mail_id_string);
+ }
+
+ EM_DEBUG_LOG("num : [%d], param string : [%s]", mail_ids_count , parameter_string);
+
+ if (!em_storage_notify_storage_event(NOTI_MAIL_MOVE, account_id, noti_param_1, parameter_string, noti_param_2))
+ EM_DEBUG_EXCEPTION(" em_storage_notify_storage_event failed [NOTI_MAIL_MOVE] >>>> ");
+
+ /* Upating thread mail info should be done as soon as possible */
+ attachment.mailbox_name = dst_mailbox_name;
+
+ for (i = 0; i < mail_ids_count; i++) {
+ if (!em_storage_update_latest_thread_mail(account_id, mail_list[i].thread_id, 0, 0, true, &err))
+ EM_DEBUG_EXCEPTION("em_storage_update_latest_thread_mail failed [%d]", err);
+ }
+
+ if (!em_storage_notify_storage_event(NOTI_MAIL_MOVE_FINISH, account_id, noti_param_1, parameter_string, noti_param_2))
+ EM_DEBUG_EXCEPTION(" em_storage_notify_storage_event failed [NOTI_MAIL_MOVE_FINISH] >>>> ");
+
+ em_core_check_unread_mail();
+
+ ret = true;
+
+FINISH_OFF:
+ em_storage_free_mail(&mail_list, mail_ids_count, NULL);
+ EM_SAFE_FREE(parameter_string);
+ if (err_code != NULL)
+ *err_code = err;
+ EM_DEBUG_FUNC_END("err [%d]", err);
+ return ret;
+}
+
+
+EXPORT_API int em_core_mail_move_from_server(int account_id, char *src_mailbox, int mail_ids[], int num, char *dest_mailbox, int *error_code)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ MAILSTREAM *stream = NULL;
+ int err_code = 0;
+ emf_account_t *ref_account = NULL;
+ emf_mail_tbl_t *mail = NULL;
+ int ret = 1;
+ int mail_id = 0;
+ int i = 0;
+
+ mail_id = mail_ids[0];
+
+ ref_account = em_core_get_account_reference(account_id);
+ if (!ref_account) {
+ EM_DEBUG_EXCEPTION("em_core_mail_move_from_server failed : get account reference[%d]", account_id);
+ *error_code = EMF_ERROR_INVALID_ACCOUNT;
+ ret = 0;
+ goto FINISH_OFF;
+ }
+
+ /* if not imap4 mail, return */
+ if (ref_account->account_bind_type != EMF_BIND_TYPE_EM_CORE ||
+ ref_account->receiving_server_type != EMF_SERVER_TYPE_IMAP4) {
+ *error_code = EMF_ERROR_INVALID_PARAM;
+ ret = 0;
+ goto FINISH_OFF;
+ }
+
+ for (i = 0; i < num; i++) {
+ mail_id = mail_ids[i];
+
+ if (!em_storage_get_mail_by_id(mail_id, &mail, false, &err_code) || !mail) {
+ EM_DEBUG_EXCEPTION("em_storage_get_uid_by_mail_id : em_storage_get_downloaded_mail failed [%d]", err_code);
+ mail = NULL;
+ if (err_code == EM_STORAGE_ERROR_MAIL_NOT_FOUND) { /* not server mail */
+ /* err = EMF_ERROR_MAIL_NOT_FOUND_ON_SERVER; */
+ /* continue; */
+ }
+ else {
+ *error_code = em_storage_get_emf_error_from_em_storage_error(err_code);
+ }
+
+ ret = 0;
+ goto FINISH_OFF;
+ }
+
+ if (!em_core_mailbox_open(account_id, src_mailbox, (void **)&stream, &err_code)) /* faizan.h@samsung.com mail_move_fix_07042009 */ {
+ EM_DEBUG_EXCEPTION("em_core_mail_move_from_server failed : Mailbox open[%d]", err_code);
+
+ ret = 0;
+ goto FINISH_OFF;
+ }
+
+ if (stream) {
+ /* set callback for COPY_UID */
+ mail_parameters(stream, SET_COPYUID, em_core_mail_copyuid);
+
+ EM_DEBUG_LOG("calling mail_copy_full FODLER MAIL COPY ");
+
+ if (mail->server_mail_id) {
+ if (!mail_copy_full(stream, mail->server_mail_id, dest_mailbox, CP_UID | CP_MOVE)) {
+ EM_DEBUG_EXCEPTION("em_core_mail_move_from_server : Mail cannot be moved failed");
+ ret = 0;
+ }
+ else {
+ /* send EXPUNGE command */
+ if (!imap4_send_command(stream, IMAP4_CMD_EXPUNGE, &err_code)) {
+ EM_DEBUG_EXCEPTION("imap4_send_command failed [%d]", err_code);
+
+ if (err_code == EMF_ERROR_IMAP4_STORE_FAILURE)
+ err_code = EMF_ERROR_MAIL_NOT_FOUND_ON_SERVER;
+ goto FINISH_OFF;
+ }
+
+ /* faizan.h@samsung.com duplicate copy while sync mailbox issue fixed */
+ EM_DEBUG_LOG(">>>mailbox_name[%s]>>>>>>", mail->mailbox_name);
+ EM_DEBUG_LOG(">>>g_new_server_uid[%s]>>>>>>", g_new_server_uid);
+ EM_DEBUG_LOG(">>>mail_id[%d]>>>>>>", mail_id);
+
+ if (!em_storage_update_read_mail_uid(mail_id, g_new_server_uid, mail->mailbox_name, &err_code)) {
+ EM_DEBUG_EXCEPTION("em_storage_update_read_mail_uid failed [%d]", err_code);
+ goto FINISH_OFF;
+ }
+
+ EM_DEBUG_LOG("Mail MOVE SUCCESS ");
+ }
+ }
+ else
+ EM_DEBUG_EXCEPTION(">>>> Server MAIL ID IS NULL >>>> ");
+ }
+ else {
+ EM_DEBUG_EXCEPTION(">>>> STREAM DATA IS NULL >>> ");
+ ret = 0;
+ goto FINISH_OFF;
+ }
+ }
+
+ /* ret = true; */
+
+FINISH_OFF:
+ if (stream) em_core_mailbox_close(account_id, stream);
+
+ if (mail != NULL)
+ em_storage_free_mail(&mail, 1, NULL);
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+static int em_core_mail_save_file(int account_id, int mail_id, int attachment_id, char *src_file_path, char *file_name, char *full_path, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("account_id[%d], mail_id[%d], attachment_id[%d] , file_name[%p] , full_path[%p] , err_code[%p]", account_id, mail_id, attachment_id, file_name, full_path, err_code);
+
+ int ret = false, err = EMF_ERROR_NONE;
+
+ if (!file_name || !full_path || !src_file_path) {
+ EM_DEBUG_EXCEPTION("Invalid paramter");
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ if (!em_storage_create_dir(account_id, mail_id, attachment_id, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_create_dir failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ if (!em_storage_get_save_name(account_id, mail_id, attachment_id, file_name, full_path, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_get_save_name failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ if (strcmp(src_file_path, full_path) != 0) {
+ if (!em_storage_copy_file(src_file_path, full_path, false, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_copy_file failed [%d]", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+ }
+
+ ret = true;
+
+FINISH_OFF:
+ if (err_code)
+ *err_code = err;
+ return 1;
+}
+
+/* description
+ * update mail information
+ * arguments
+ * mailbox : mail box
+ * mail_id : mail id to be updated
+ * mail : updating mail header, body, flags, extra_flags
+ * return
+ * succeed : 1
+ * fail : 0
+ */
+EXPORT_API int em_core_mail_update_old(int mail_id, emf_mail_t *src_mail, emf_meeting_request_t *src_meeting_req, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("mail_id[%d], mail[%p], err_code[%p]", mail_id, src_mail, err_code);
+
+ int ret = false, err = EMF_ERROR_NONE;
+ int local_attachment_count = 0, local_inline_content_count = 0;
+ emf_mail_tbl_t mail_table_data = {0};
+ emf_attachment_info_t *attachment_info = NULL;
+ char filename_buf[1024] = {0, }, buf_date[512] = {0, };
+ char html_body[MAX_PATH] = {0, };
+
+ if (!mail_id || !src_mail || !src_mail->info || !src_mail->head) {
+ EM_DEBUG_EXCEPTION("Invalid parameter");
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF2;
+ }
+
+ mail_table_data.full_address_from = src_mail->head->from;
+ mail_table_data.full_address_reply = src_mail->head->reply_to;
+ mail_table_data.full_address_to = src_mail->head->to;
+ mail_table_data.full_address_cc = src_mail->head->cc;
+ mail_table_data.full_address_bcc = src_mail->head->bcc;
+ mail_table_data.full_address_return = src_mail->head->return_path;
+ mail_table_data.subject = src_mail->head->subject;
+ mail_table_data.preview_text = src_mail->head->previewBodyText ;
+ mail_table_data.body_download_status = src_mail->info->body_downloaded;
+ mail_table_data.mailbox_name = NULL; /* UPDATE_MAIL type couldn't change mailbox. */
+ mail_table_data.priority = src_mail->info->extra_flags.priority;
+ mail_table_data.report_status = src_mail->info->extra_flags.report;
+ mail_table_data.save_status = src_mail->info->extra_flags.status;
+ mail_table_data.lock_status = src_mail->info->extra_flags.lock;
+ mail_table_data.DRM_status = src_mail->info->extra_flags.drm;
+ mail_table_data.mail_size = src_mail->info->rfc822_size;
+
+ if(mail_table_data.mail_size == 0)
+ mail_table_data.mail_size = em_core_get_mail_size(src_mail, &err);
+
+ if (!mail_table_data.full_address_from) {
+ emf_account_t *ref_account = NULL;
+ if (!(ref_account = em_core_get_account_reference(src_mail->info->account_id))) {
+ EM_DEBUG_EXCEPTION("em_core_get_account_reference failed [%d]", src_mail->info->account_id);
+ err = EMF_ERROR_INVALID_ACCOUNT;
+ goto FINISH_OFF2;
+ }
+ mail_table_data.full_address_from = ref_account->email_addr;
+ }
+
+ if(!em_convert_mail_flag_to_mail_tbl(&(src_mail->info->flags), &mail_table_data, &err)) {
+ EM_DEBUG_EXCEPTION("em_convert_mail_flag_to_mail_tbl failed [%d]", err);
+ goto FINISH_OFF2;
+ }
+
+ if (src_mail->body && src_mail->body->plain) { /* Save plain text body. */
+ if (!em_core_mail_save_file(src_mail->info->account_id, mail_id, 0, src_mail->body->plain, src_mail->body->plain_charset ? src_mail->body->plain_charset : "UTF-8", filename_buf, &err)) {
+ EM_DEBUG_EXCEPTION("em_core_mail_save_file failed [%d]", err);
+ goto FINISH_OFF2;
+ }
+ mail_table_data.file_path_plain = EM_SAFE_STRDUP(filename_buf);
+ }
+ else
+ mail_table_data.file_path_plain = NULL;
+
+ if (src_mail->body && src_mail->body->html) { /* Save HTML text body. */
+ if (src_mail->body->plain_charset != NULL && src_mail->body->plain_charset[0] != '\0') {
+ memcpy(html_body, src_mail->body->plain_charset, strlen(src_mail->body->plain_charset));
+ strcat(html_body, ".htm");
+ }
+ else
+ memcpy(html_body, "UTF-8.htm", strlen("UTF-8.htm"));
+ if (!em_core_mail_save_file(src_mail->info->account_id, mail_id, 0, src_mail->body->html, html_body, filename_buf, &err)) {
+ EM_DEBUG_EXCEPTION("em_core_mail_save_file failed [%d]", err);
+ goto FINISH_OFF2;
+ }
+ mail_table_data.file_path_html = EM_SAFE_STRDUP(filename_buf);
+ }
+ else
+ mail_table_data.file_path_html = NULL;
+
+ if (src_mail->body && src_mail->body->attachment) {
+ int compare_result = 1;
+ char attachment_id[20];
+
+ attachment_info = src_mail->body->attachment;
+ do {
+ if (!em_core_mail_compare_filename_of_attachment(mail_id, attachment_info->attachment_id, attachment_info, &compare_result, &err)) {
+ EM_DEBUG_EXCEPTION("em_core_mail_compare_filename_of_attachment failed [%d]", err);
+ compare_result = 1;
+ }
+
+ if (compare_result == 0) {
+ EM_DEBUG_LOG("file name and attachment id are same, update exising attachment");
+ if (!em_core_mail_update_attachment(mail_id, attachment_info, &err)) {
+ EM_DEBUG_EXCEPTION("em_core_mail_update_attachment failed [%d]", err);
+ goto FINISH_OFF2;
+ }
+ }
+ else {
+ EM_DEBUG_LOG("save names are different");
+ SNPRINTF(attachment_id, sizeof(attachment_id), "%d", attachment_info->attachment_id);
+
+ if(attachment_info->attachment_id > 0) {
+ if (!em_core_mail_delete_attachment(mail_id, attachment_id, &err)) {
+ EM_DEBUG_EXCEPTION("em_core_mail_delete_attachment failed [%d]", err);
+ goto FINISH_OFF2;
+ }
+ }
+
+ if (!em_core_mail_add_attachment(mail_id, attachment_info, &err)) {
+ EM_DEBUG_EXCEPTION("em_core_mail_add_attachment failed [%d]", err);
+ goto FINISH_OFF2;
+ }
+ }
+
+ if (attachment_info->inline_content)
+ local_inline_content_count++;
+ local_attachment_count++;
+ attachment_info = attachment_info->next;
+ }
+ while (attachment_info != NULL);
+ }
+
+ mail_table_data.attachment_count = local_attachment_count;
+ mail_table_data.inline_content_count = local_inline_content_count;
+
+ if (!src_mail->head->datetime.year && !src_mail->head->datetime.month && !src_mail->head->datetime.day) {
+ time_t t = time(NULL);
+ struct tm *p_tm = localtime(&t);
+
+ if (!p_tm) {
+ EM_DEBUG_EXCEPTION("localtime failed...");
+ err = EM_STORAGE_ERROR_SYSTEM_FAILURE;
+ goto FINISH_OFF2;
+ }
+
+ SNPRINTF(buf_date, sizeof(buf_date), "%04d%02d%02d%02d%02d%02d",
+ p_tm->tm_year + 1900,
+ p_tm->tm_mon + 1,
+ p_tm->tm_mday,
+ p_tm->tm_hour,
+ p_tm->tm_min,
+ p_tm->tm_sec);
+ }
+ else {
+ SNPRINTF(buf_date, sizeof(buf_date), "%04d%02d%02d%02d%02d%02d",
+ src_mail->head->datetime.year,
+ src_mail->head->datetime.month,
+ src_mail->head->datetime.day,
+ src_mail->head->datetime.hour,
+ src_mail->head->datetime.minute,
+ src_mail->head->datetime.second);
+ }
+
+ mail_table_data.datetime = buf_date;
+
+ EM_DEBUG_LOG("preview_text[%p]", mail_table_data.preview_text);
+ if (mail_table_data.preview_text == NULL) {
+ if ( (err = em_core_get_preview_text_from_file(mail_table_data.file_path_plain, mail_table_data.file_path_html, MAX_PREVIEW_TEXT_LENGTH, &(mail_table_data.preview_text))) != EMF_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("em_core_get_preview_text_from_file failed[%d]", err);
+ goto FINISH_OFF2;
+ }
+ }
+
+ mail_table_data.meeting_request_status = src_mail->info->is_meeting_request;
+
+ /* BEGIN TRANSACTION; */
+ em_storage_begin_transaction(NULL, NULL, NULL);
+
+ if (!em_storage_change_mail_field(mail_id, UPDATE_MAIL, &mail_table_data, false, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_change_mail_field failed [%d]", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+
+ if (src_mail->info->is_meeting_request == EMF_MAIL_TYPE_MEETING_REQUEST
+ || src_mail->info->is_meeting_request == EMF_MAIL_TYPE_MEETING_RESPONSE
+ || src_mail->info->is_meeting_request == EMF_MAIL_TYPE_MEETING_ORIGINATINGREQUEST) {
+ emf_meeting_request_t *meeting_req = NULL;
+ /* check where there is a meeting request in DB */
+ if (!em_storage_get_meeting_request(mail_id, &meeting_req, false, &err) && err != EM_STORAGE_ERROR_DATA_NOT_FOUND) {
+ EM_DEBUG_EXCEPTION("em_storage_get_meeting_request failed [%d]", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+ EM_SAFE_FREE(meeting_req);
+ if (err == EM_STORAGE_ERROR_DATA_NOT_FOUND) { /* insert */
+ emf_mail_tbl_t *original_mail = NULL;
+
+ if (!em_storage_get_mail_by_id(mail_id, &original_mail, false, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_get_mail_by_id failed [%d]", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+
+ if (original_mail) {
+ if (!em_storage_add_meeting_request(src_mail->info->account_id, original_mail->mailbox_name, src_meeting_req, false, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_add_meeting_request failed [%d]", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+ em_storage_free_mail(&original_mail, 1, NULL);
+ }
+ }
+ else { /* update */
+ if (!em_storage_update_meeting_request(src_meeting_req, false, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_update_meeting_request failed [%d]", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+ }
+ }
+
+ ret = true;
+
+FINISH_OFF:
+ if (ret == true) { /* COMMIT TRANSACTION; */
+ if (em_storage_commit_transaction(NULL, NULL, NULL) == false) {
+ err = em_storage_get_emf_error_from_em_storage_error(EM_STORAGE_ERROR_DB_FAILURE);
+ ret = false;
+ }
+ /* publish a notification : to Active Sync Engine */
+ if (!em_storage_notify_storage_event(NOTI_MAIL_UPDATE, src_mail->info->account_id, mail_id, NULL, UPDATE_MEETING))
+ EM_DEBUG_EXCEPTION(" em_storage_notify_storage_event failed [ NOTI_MAIL_UPDATE : UPDATE_MEETING_RESPONSE ] >>>> ");
+ }
+ else { /* ROLLBACK TRANSACTION; */
+ if (em_storage_rollback_transaction(NULL, NULL, NULL) == false)
+ err = em_storage_get_emf_error_from_em_storage_error(EM_STORAGE_ERROR_DB_FAILURE);
+ }
+
+FINISH_OFF2:
+
+ EM_SAFE_FREE(mail_table_data.file_path_plain);
+ EM_SAFE_FREE(mail_table_data.file_path_html);
+
+ if (err_code != NULL)
+ *err_code = err;
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+
+/* description
+ * update mail information
+ * 'em_core_mail_update_old' will be replaced with this function.
+ */
+EXPORT_API int em_core_update_mail(emf_mail_data_t *input_mail_data, emf_attachment_data_t *input_attachment_data_list, int input_attachment_count, emf_meeting_request_t* input_meeting_request, int input_sync_server)
+{
+ EM_DEBUG_FUNC_BEGIN("input_mail_data[%p], input_attachment_data_list[%p], input_attachment_count[%d], input_meeting_request[%p], input_sync_server[%d]", input_mail_data, input_attachment_data_list, input_attachment_count, input_meeting_request, input_sync_server);
+
+ char filename_buf[1024] = {0, };
+ int i = 0;
+ int err = EMF_ERROR_NONE;
+ int local_inline_content_count = 0;
+ emf_mail_tbl_t *converted_mail_tbl_data = NULL;
+ struct stat st_buf;
+
+
+ if (!input_mail_data || (input_attachment_count && !input_attachment_data_list) || (!input_attachment_count &&input_attachment_data_list)) {
+ EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF2;
+ }
+
+ if(input_sync_server) {
+ if (input_mail_data->file_path_plain) {
+ if (stat(input_mail_data->file_path_plain, &st_buf) < 0) {
+ EM_DEBUG_EXCEPTION("input_mail_data->file_path_plain, stat(\"%s\") failed...", input_mail_data->file_path_plain);
+ err = EMF_ERROR_INVALID_MAIL;
+ goto FINISH_OFF;
+ }
+ }
+
+ if (input_mail_data->file_path_html) {
+ if (stat(input_mail_data->file_path_html, &st_buf) < 0) {
+ EM_DEBUG_EXCEPTION("input_mail_data->file_path_html, stat(\"%s\") failed...", input_mail_data->file_path_html);
+ err = EMF_ERROR_INVALID_MAIL;
+ goto FINISH_OFF;
+ }
+ }
+
+ if (input_attachment_count && input_attachment_data_list) {
+ for (i = 0; i < input_attachment_count; i++) {
+ if (input_attachment_data_list[i].save_status) {
+ if (!input_attachment_data_list[i].attachment_path || stat(input_attachment_data_list[i].attachment_path, &st_buf) < 0) {
+ EM_DEBUG_EXCEPTION("stat(\"%s\") failed...", input_attachment_data_list[i].attachment_path);
+ err = EMF_ERROR_INVALID_ATTACHMENT;
+ goto FINISH_OFF;
+ }
+ }
+ }
+ }
+ }
+
+ if(input_mail_data->mail_size == 0) {
+ em_core_calc_mail_size(input_mail_data, input_attachment_data_list, input_attachment_count, &(input_mail_data->mail_size));
+ }
+
+ if (!input_mail_data->full_address_from) {
+ emf_account_t *ref_account = NULL;
+ if (!(ref_account = em_core_get_account_reference(input_mail_data->account_id))) {
+ EM_DEBUG_EXCEPTION("em_core_get_account_reference failed [%d]", input_mail_data->account_id);
+ err = EMF_ERROR_INVALID_ACCOUNT;
+ goto FINISH_OFF2;
+ }
+ input_mail_data->full_address_from = ref_account->email_addr;
+ }
+
+ if (input_mail_data->file_path_plain) { /* Save plain text body. */
+ if (!em_core_mail_save_file(input_mail_data->account_id, input_mail_data->mail_id, 0, input_mail_data->file_path_plain, "UTF-8", filename_buf, &err)) {
+ EM_DEBUG_EXCEPTION("em_core_mail_save_file failed [%d]", err);
+ goto FINISH_OFF2;
+ }
+ EM_SAFE_FREE(input_mail_data->file_path_plain);
+ input_mail_data->file_path_plain = EM_SAFE_STRDUP(filename_buf);
+ }
+
+ if (input_mail_data->file_path_html) { /* Save HTML text body. */
+ if (!em_core_mail_save_file(input_mail_data->account_id, input_mail_data->mail_id, 0, input_mail_data->file_path_html, "UTF-8.htm", filename_buf, &err)) {
+ EM_DEBUG_EXCEPTION("em_core_mail_save_file failed [%d]", err);
+ goto FINISH_OFF2;
+ }
+ EM_SAFE_FREE(input_mail_data->file_path_html);
+ input_mail_data->file_path_html = EM_SAFE_STRDUP(filename_buf);
+ }
+
+ if (input_attachment_data_list && input_attachment_count) {
+ int i = 0;
+ int compare_result = 1;
+ char attachment_id[20];
+ emf_attachment_data_t *temp_attachment_data = NULL;
+
+ for(i = 0; i < input_attachment_count; i++) {
+ temp_attachment_data = input_attachment_data_list + i;
+ if ( (err = em_core_mail_compare_filename_of_attachment_data(input_mail_data->mail_id, temp_attachment_data->attachment_id, temp_attachment_data, &compare_result)) != EMF_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("em_core_mail_compare_filename_of_attachment failed [%d]", err);
+ compare_result = 1;
+ }
+
+ if (compare_result == 0) {
+ EM_DEBUG_LOG("file name and attachment id are same, update exising attachment");
+ if (!em_core_mail_update_attachment_data(input_mail_data->mail_id, temp_attachment_data)) {
+ EM_DEBUG_EXCEPTION("em_core_mail_update_attachment failed [%d]", err);
+ goto FINISH_OFF2;
+ }
+ }
+ else {
+ EM_DEBUG_LOG("save names are different");
+ SNPRINTF(attachment_id, sizeof(attachment_id), "%d", temp_attachment_data->attachment_id);
+
+ if(temp_attachment_data->attachment_id > 0) {
+ if (!em_core_mail_delete_attachment(input_mail_data->mail_id, attachment_id, &err)) {
+ EM_DEBUG_EXCEPTION("em_core_mail_delete_attachment failed [%d]", err);
+ goto FINISH_OFF2;
+ }
+ }
+
+ if ( (err = em_core_mail_add_attachment_data(input_mail_data->mail_id, temp_attachment_data)) != EMF_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("em_core_mail_add_attachment failed [%d]", err);
+ goto FINISH_OFF2;
+ }
+ }
+
+ if (temp_attachment_data->inline_content_status)
+ local_inline_content_count++;
+ }
+ }
+
+ input_mail_data->attachment_count = input_attachment_count;
+ input_mail_data->inline_content_count = local_inline_content_count;
+
+ if (!input_mail_data->datetime) {
+ /* time isn't set */
+ input_mail_data->datetime = em_core_get_current_time_string(&err);
+ if(!input_mail_data->datetime) {
+ EM_DEBUG_EXCEPTION("em_core_get_current_time_string failed [%d]", err);
+ goto FINISH_OFF;
+ }
+ }
+
+ EM_DEBUG_LOG("preview_text[%p]", input_mail_data->preview_text);
+ if (input_mail_data->preview_text == NULL) {
+ if ( (err =em_core_get_preview_text_from_file(input_mail_data->file_path_plain, input_mail_data->file_path_html, MAX_PREVIEW_TEXT_LENGTH, &(input_mail_data->preview_text))) != EMF_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("em_core_get_preview_text_from_file failed[%d]", err);
+ goto FINISH_OFF2;
+ }
+ }
+
+ if(!em_convert_mail_data_to_mail_tbl(input_mail_data, 1, &converted_mail_tbl_data, &err)) {
+ EM_DEBUG_EXCEPTION("em_convert_mail_data_to_mail_tbl failed[%d]", err);
+ goto FINISH_OFF2;
+ }
+
+ /* BEGIN TRANSACTION; */
+ em_storage_begin_transaction(NULL, NULL, NULL);
+
+ if (!em_storage_change_mail_field(input_mail_data->mail_id, UPDATE_MAIL, converted_mail_tbl_data, false, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_change_mail_field failed [%d]", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+
+ if (input_mail_data->meeting_request_status == EMF_MAIL_TYPE_MEETING_REQUEST
+ || input_mail_data->meeting_request_status == EMF_MAIL_TYPE_MEETING_RESPONSE
+ || input_mail_data->meeting_request_status == EMF_MAIL_TYPE_MEETING_ORIGINATINGREQUEST) {
+ emf_meeting_request_t *meeting_req = NULL;
+ /* check where there is a meeting request in DB */
+ if (!em_storage_get_meeting_request(input_mail_data->mail_id, &meeting_req, false, &err) && err != EM_STORAGE_ERROR_DATA_NOT_FOUND) {
+ EM_DEBUG_EXCEPTION("em_storage_get_meeting_request failed [%d]", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+ EM_SAFE_FREE(meeting_req);
+ if (err == EM_STORAGE_ERROR_DATA_NOT_FOUND) { /* insert */
+ emf_mail_tbl_t *original_mail = NULL;
+
+ if (!em_storage_get_mail_by_id(input_mail_data->mail_id, &original_mail, false, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_get_mail_by_id failed [%d]", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+
+ if (original_mail) {
+ if (!em_storage_add_meeting_request(input_mail_data->account_id, original_mail->mailbox_name, input_meeting_request, false, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_add_meeting_request failed [%d]", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+ em_storage_free_mail(&original_mail, 1, NULL);
+ }
+ }
+ else { /* update */
+ if (!em_storage_update_meeting_request(input_meeting_request, false, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_update_meeting_request failed [%d]", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+ }
+ }
+
+FINISH_OFF:
+ if (err == EMF_ERROR_NONE) {
+ /* COMMIT TRANSACTION; */
+ if (em_storage_commit_transaction(NULL, NULL, NULL) == false) {
+ err = em_storage_get_emf_error_from_em_storage_error(EM_STORAGE_ERROR_DB_FAILURE);
+ }
+
+ if (input_meeting_request && !em_storage_notify_storage_event(NOTI_MAIL_UPDATE, input_mail_data->account_id, input_mail_data->mail_id, NULL, UPDATE_MEETING))
+ EM_DEBUG_EXCEPTION(" em_storage_notify_storage_event failed [ NOTI_MAIL_UPDATE : UPDATE_MEETING_RESPONSE ] >>>> ");
+ }
+ else {
+ /* ROLLBACK TRANSACTION; */
+ if (em_storage_rollback_transaction(NULL, NULL, NULL) == false)
+ err = em_storage_get_emf_error_from_em_storage_error(EM_STORAGE_ERROR_DB_FAILURE);
+ }
+
+FINISH_OFF2:
+ if(converted_mail_tbl_data)
+ em_storage_free_mail(&converted_mail_tbl_data, 1, NULL);
+
+ EM_DEBUG_FUNC_END("err [%d]", err);
+ return err;
+}
+
+EXPORT_API int em_core_fetch_flags(int account_id, int mail_id, emf_mail_flag_t *mail_flag, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ int ret = false;
+ int err = 0;
+ emf_mail_tbl_t *mail = NULL;
+
+ EM_IF_NULL_RETURN_VALUE(mail_flag, false);
+ if (account_id < FIRST_ACCOUNT_ID || mail_id < 1) {
+ EM_DEBUG_EXCEPTION("em_core_fetch_flags : Invalid Param ");
+ goto FINISH_OFF;
+ }
+
+ if (!em_storage_get_mail_field_by_id(mail_id, RETRIEVE_FLAG, &mail, true, &err) || !mail) {
+ EM_DEBUG_EXCEPTION("em_storage_get_mail_field_by_id failed - %d ", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+
+ if (!em_convert_mail_tbl_to_mail_flag(mail, mail_flag, &err)) {
+ EM_DEBUG_EXCEPTION("em_convert_mail_flag_to_int failed - %d ", err);
+ goto FINISH_OFF;
+ }
+
+ ret = true;
+
+FINISH_OFF:
+ if(mail)
+ em_storage_free_mail(&mail, 1, &err);
+
+ if (err_code != NULL)
+ *err_code = err;
+
+ EM_DEBUG_FUNC_END("err [%d]", err);
+ return ret;
+}
+/* description : modify flag of msgno.
+ return 1(success), 0(failure)
+ */
+EXPORT_API int em_core_mail_modify_flag(int mail_id, emf_mail_flag_t new_flag, int sticky_flag, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("mail_id[%d], err_code[%p]", mail_id, err_code);
+
+ int ret = false;
+ int err = EMF_ERROR_NONE;
+ int old_seen, new_seen;
+
+ emf_mail_tbl_t *mail = NULL;
+ emf_mail_flag_t old_flag;
+
+ if (!em_storage_get_mail_field_by_id(mail_id, RETRIEVE_FLAG, &mail, true, &err) || !mail) {
+ EM_DEBUG_EXCEPTION("em_storage_get_mail_field_by_id failed [%d]", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+
+ if (!em_convert_mail_tbl_to_mail_flag(mail, &old_flag, &err)) {
+ EM_DEBUG_EXCEPTION("em_convert_mail_tbl_to_mail_flag failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ old_seen = mail->flags_seen_field;
+ new_seen = new_flag.seen;
+
+ if (!em_convert_mail_flag_to_mail_tbl(&new_flag, mail, &err)) {
+ EM_DEBUG_EXCEPTION("em_convert_mail_flag_to_mail_tbl failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ mail->lock_status = sticky_flag;
+
+ if (!em_storage_change_mail_field(mail_id, UPDATE_FLAG, mail, true, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_change_mail_field failed [%d]", err);
+
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+
+ if (old_seen != new_seen && new_seen == 0)
+ em_core_delete_notification_for_read_mail(mail_id);
+
+ em_core_check_unread_mail();
+
+ ret = true;
+
+FINISH_OFF:
+ if (mail)
+ em_storage_free_mail(&mail, 1, NULL);
+
+ if (err_code)
+ *err_code = err;
+ EM_DEBUG_FUNC_END("err [%d]", err);
+ return ret;
+}
+
+EXPORT_API int em_core_mail_set_flags_field(int account_id, int mail_ids[], int num, emf_flags_field_type field_type, int value, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("account_id [%d], mail_ids[%p], num [%d], field_type [%d], value[%d], err_code[%p]", account_id, mail_ids, num, field_type, value, err_code);
+
+ int ret = false;
+ int err = EMF_ERROR_NONE;
+ char *field_type_name[EMF_FLAGS_FIELD_COUNT] = { "flags_seen_field"
+ , "flags_deleted_field", "flags_flagged_field", "flags_answered_field"
+ , "flags_recent_field", "flags_draft_field", "flags_forwarded_field" };
+
+ if(field_type < 0 || field_type >= EMF_FLAGS_FIELD_COUNT || mail_ids == NULL || num <= 0 || account_id == 0) {
+ EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ if (!em_storage_set_field_of_mails_with_integer_value(account_id, mail_ids, num, field_type_name[field_type], value, true, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_set_field_of_mails_with_integer_value failed [%d]", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+
+ em_core_check_unread_mail();
+
+ ret = true;
+
+FINISH_OFF:
+
+ if (err_code)
+ *err_code = err;
+ EM_DEBUG_FUNC_END("err [%d]", err);
+ return ret;
+}
+
+
+/* description : modify extra flag of msgno.
+ return 0(success), -1(failure)
+ */
+EXPORT_API int em_core_mail_modify_extra_flag(int mail_id, emf_extra_flag_t new_flag, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("mail_id[%d], err_code[%p]", mail_id, err_code);
+
+ int ret = false;
+ int err = EMF_ERROR_NONE;
+ emf_mail_tbl_t mail;
+
+ memset(&mail, 0x00, sizeof(emf_mail_tbl_t));
+
+ mail.mail_id = mail_id;
+ mail.save_status = new_flag.status;
+ mail.lock_status = new_flag.report;
+ mail.lock_status = new_flag.lock;
+ mail.priority = new_flag.priority;
+ mail.DRM_status = new_flag.drm;
+
+ if (!em_storage_change_mail_field(mail_id, UPDATE_EXTRA_FLAG, &mail, false, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_change_mail_field failed [%d]", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+
+ ret = true;
+
+FINISH_OFF:
+ if (err_code != NULL)
+ *err_code = err;
+ EM_DEBUG_FUNC_END("err [%d]", err);
+ return ret;
+}
+
+
+int em_core_mail_cmd_read_mail_pop3(void *stream, int msgno, int limited_size, int *downloded_size, int *result_total_body_size, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("stream[%p], msgno[%d], limited_size[%d], err_code[%p]", stream, msgno, limited_size, err_code);
+
+ int ret = false;
+ int err = EMF_ERROR_NONE;
+ int total_body_size = 0;
+ char command[32];
+ char *response = NULL;
+ POP3LOCAL *pop3local;
+
+ if (!stream || !result_total_body_size) {
+ EM_DEBUG_EXCEPTION("stream[%p], total_body_size[%p]", stream, msgno, result_total_body_size);
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ pop3local = (POP3LOCAL *)(((MAILSTREAM *)stream)->local);
+
+ if (!pop3local || !pop3local->netstream) {
+ err = EMF_ERROR_INVALID_STREAM;
+ goto FINISH_OFF;
+ }
+ memset(command, 0x00, sizeof(command));
+
+ SNPRINTF(command, sizeof(command), "LIST %d\015\012", msgno);
+
+#ifdef FEATURE_CORE_DEBUG
+ EM_DEBUG_LOG("[POP3] >>> [%s]", command);
+#endif
+
+
+ /* send command : LIST [msgno] - to get the size of the mail */
+ if (!net_sout(pop3local->netstream, command, (int)strlen(command))) {
+ EM_DEBUG_EXCEPTION("net_sout failed...");
+
+ err = EMF_ERROR_INVALID_RESPONSE;
+ goto FINISH_OFF;
+ }
+
+ EM_DEBUG_LOG("Sending command success");
+
+ while (pop3local->netstream) {
+ /* receive response */
+ if (!(response = net_getline(pop3local->netstream)))
+ break;
+
+ if (response)
+ EM_DEBUG_LOG("[POP3] <<< %s", response);
+
+ if (*response == '.') {
+ EM_SAFE_FREE(response);
+ break;
+ }
+
+ if (*response == '+') { /* "+ OK" */
+ char *p = NULL;
+
+ if (!(p = strchr(response + strlen("+OK "), ' '))) {
+ err = EMF_ERROR_INVALID_RESPONSE;
+ goto FINISH_OFF;
+ }
+
+ total_body_size = atoi(p + 1);
+ EM_DEBUG_LOG("Body size [%d]", total_body_size);
+
+ if (result_total_body_size) {
+ *result_total_body_size = total_body_size;
+ break;
+ }
+ }
+ else if (*response == '-') { /* "- ERR" */
+ err = EMF_ERROR_INVALID_RESPONSE;
+ goto FINISH_OFF;
+ }
+ else {
+ err = EMF_ERROR_INVALID_RESPONSE;
+ goto FINISH_OFF;
+ }
+
+ EM_SAFE_FREE(response);
+ }
+
+ memset(command, 0x00, sizeof(command));
+
+ if (limited_size && total_body_size > limited_size) {
+ int count_of_line = limited_size / 80;
+ SNPRINTF(command, sizeof(command), "TOP %d %d", msgno, count_of_line);
+ }
+ else
+ SNPRINTF(command, sizeof(command), "RETR %d", msgno);
+
+ EM_DEBUG_LOG("[POP3] >>> %s", command);
+
+ em_core_set_network_error(EMF_ERROR_NONE); /* set current network error as EMF_ERROR_NONE before network operation */
+ /* get mail from mail server */
+ if (!pop3_send((MAILSTREAM *)stream, command, NULL)) {
+ EM_DEBUG_EXCEPTION("pop3_send failed...");
+
+ emf_session_t *session = NULL;
+
+ if (!em_core_get_current_session(&session)) {
+ EM_DEBUG_EXCEPTION("em_core_get_current_session failed...");
+ err = EMF_ERROR_SESSION_NOT_FOUND;
+ goto FINISH_OFF;
+ }
+
+ if (session->network == EMF_ERROR_NONE)
+ err = EMF_ERROR_UNKNOWN;
+ else
+ err = session->network;
+
+ goto FINISH_OFF;
+ }
+
+ ret = true;
+
+FINISH_OFF:
+ EM_SAFE_FREE(response);
+
+ if (err_code != NULL)
+ *err_code = err;
+ EM_DEBUG_FUNC_END("err [%d]", err);
+ return ret;
+}
+
+
+EXPORT_API int em_core_mail_sync_flag_with_server(int mail_id, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("mail_id[%p], err_code[%p]", mail_id, err_code);
+
+ if (mail_id < 1) {
+ if (err_code != NULL)
+ *err_code = EMF_ERROR_INVALID_PARAM;
+ return false;
+ }
+
+ int ret = false;
+ int err = EMF_ERROR_NONE;
+ int status = EMF_DOWNLOAD_FAIL;
+ MAILSTREAM *stream = NULL;
+ emf_mailbox_t mbox = {0};
+ emf_mail_tbl_t *mail = NULL;
+ emf_account_t *ref_account = NULL;
+ int account_id = 0;
+ int msgno = 0;
+ emf_mail_flag_t new_flag = {0};
+ char set_flags[100] = { 0, };
+ char clear_flags[100] = { 0, };
+ char tmp[100] = { 0, };
+
+ if (!em_core_check_thread_status()) {
+ err = EMF_ERROR_CANCELLED;
+ goto FINISH_OFF;
+ }
+
+ if (!em_storage_get_mail_by_id(mail_id, &mail, true, &err) || !mail) {
+ EM_DEBUG_EXCEPTION("em_storage_get_mail_by_id failed [%d]", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+
+ account_id = mail->account_id;
+ em_convert_mail_tbl_to_mail_flag(mail, &new_flag, NULL);
+
+ if (!(ref_account = em_core_get_account_reference(account_id))) {
+ EM_DEBUG_EXCEPTION("em_core_get_account_reference failed [%d]", account_id);
+ err = EMF_ERROR_INVALID_ACCOUNT;
+ goto FINISH_OFF;
+ }
+
+ if (!em_core_check_thread_status()) {
+ err = EMF_ERROR_CANCELLED;
+ goto FINISH_OFF;
+ }
+
+ /* open mail server. */
+ if (!em_core_mailbox_open(account_id, mail->mailbox_name, (void **)&stream, &err) || !stream) {
+ EM_DEBUG_EXCEPTION("em_core_mailbox_open failed [%d]", err);
+ status = EMF_LIST_CONNECTION_FAIL;
+ goto FINISH_OFF;
+ }
+
+
+ if (!em_core_check_thread_status()) {
+ err = EMF_ERROR_CANCELLED;
+ goto FINISH_OFF;
+ }
+
+ mbox.name = mail->mailbox_name;
+ mbox.account_id = account_id;
+ mbox.mail_stream = stream;
+
+ /* download all uids from server. */
+ if (!em_core_mail_get_msgno_by_uid(ref_account, &mbox, mail->server_mail_id, &msgno, &err)) {
+ EM_DEBUG_EXCEPTION("em_core_mail_get_msgno_by_uid failed message_no : %d ", err);
+ goto FINISH_OFF;
+ }
+
+ sprintf (tmp, "%d", msgno);
+
+ if (new_flag.seen)
+ sprintf(set_flags, "\\Seen");
+ else
+ sprintf(clear_flags, "\\Seen");
+
+ if (new_flag.answered)
+ sprintf(set_flags, "%s \\Answered", set_flags);
+ else
+ sprintf(clear_flags, "%s \\Answered", clear_flags);
+
+ if (new_flag.flagged)
+ sprintf(set_flags, "%s \\Flagged", set_flags);
+ else
+ sprintf(clear_flags, "%s \\Flagged", clear_flags);
+
+ if (new_flag.forwarded)
+ sprintf(set_flags, "%s $Forwarded", set_flags);
+ else
+ sprintf(clear_flags, "%s $Forwarded", clear_flags);
+
+ if (strlen(set_flags) > 0) {
+ EM_DEBUG_LOG(">>>> Calling mail_setflag [%s] ", set_flags);
+ mail_flag(stream, tmp, set_flags, ST_SET | ST_SILENT);
+ EM_DEBUG_LOG(">>>> End mail_setflag ");
+ }
+
+ if (strlen(clear_flags) > 0) {
+ EM_DEBUG_LOG(">>>> Calling mail_clearflag [%s]", clear_flags);
+ mail_clearflag(stream, tmp, clear_flags);
+ EM_DEBUG_LOG(">>>> End mail_clearflag ");
+ }
+
+ if (mail->lock_status) {
+ memset(set_flags, 0x00, 100);
+ sprintf(set_flags, "Sticky");
+ if (strlen(set_flags) > 0) {
+ EM_DEBUG_LOG(">>>> Calling mail_setflag [%s]", set_flags);
+ mail_flag(stream, tmp, set_flags, ST_SET | ST_SILENT);
+ EM_DEBUG_LOG(">>>> End mail_setflag ");
+ }
+ }
+
+ EM_DEBUG_LOG(">>>> Returning from em_core_mail_sync_flag_with_server ");
+
+ if (!em_core_check_thread_status()) {
+ err = EMF_ERROR_CANCELLED;
+ goto FINISH_OFF;
+ }
+
+ ret = true;
+
+FINISH_OFF:
+
+ if (stream) em_core_mailbox_close(account_id, stream);
+ if (mail) em_storage_free_mail(&mail, 1, NULL);
+
+ if (err_code != NULL)
+ *err_code = err;
+ EM_DEBUG_FUNC_END("err [%d]", err);
+ return ret;
+}
+
+EXPORT_API int em_core_mail_sync_seen_flag_with_server(int mail_ids[], int num, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("mail_ids[%p], err_code[%p]", mail_ids[0], err_code);
+
+ if (mail_ids[0] < 1) {
+ if (err_code != NULL)
+ *err_code = EMF_ERROR_INVALID_PARAM;
+ return false;
+ }
+
+ int ret = false;
+ int err = EMF_ERROR_NONE;
+ int status = EMF_DOWNLOAD_FAIL;
+ MAILSTREAM *stream = NULL;
+ emf_mailbox_t mbox;
+ emf_mail_tbl_t *mail = NULL;
+ emf_account_t *ref_account = NULL;
+ int account_id = 0;
+ int msgno = 0;
+ emf_mail_flag_t new_flag;
+ char set_flags[100];
+ char clear_flags[100];
+ char tmp[100];
+ int mail_id = 0;
+ int i = 0;
+
+ memset(&mbox, 0x00, sizeof(emf_mailbox_t));
+
+ mail_id = mail_ids[0];
+
+ if (!em_storage_get_mail_by_id(mail_id, &mail, true, &err) || !mail) {
+ EM_DEBUG_EXCEPTION("em_storage_get_mail_by_id failed [%d]", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+
+ account_id = mail->account_id;
+
+ if (!(ref_account = em_core_get_account_reference(account_id))) {
+ EM_DEBUG_EXCEPTION("em_core_get_account_reference failed [%d]", account_id);
+ err = EMF_ERROR_INVALID_ACCOUNT;
+ goto FINISH_OFF;
+ }
+
+ /* open mail server. */
+ if (!em_core_mailbox_open(account_id, mail->mailbox_name, (void **)&stream, &err) || !stream) {
+ EM_DEBUG_EXCEPTION("em_core_mailbox_open failed [%d]", err);
+ status = EMF_LIST_CONNECTION_FAIL;
+ goto FINISH_OFF;
+ }
+
+ mbox.name = mail->mailbox_name;
+ mbox.account_id = account_id;
+ mbox.mail_stream = stream;
+
+ for (i = 0; i < num; i++) {
+ mail_id = mail_ids[i];
+
+ if (!em_core_check_thread_status()) {
+ err = EMF_ERROR_CANCELLED;
+ goto FINISH_OFF;
+ }
+
+ if (!em_storage_get_mail_by_id(mail_id, &mail, true, &err) || !mail) {
+ EM_DEBUG_EXCEPTION("em_storage_get_mail_by_id failed [%d]", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+
+ /* account_id = mail->account_id; */
+ em_convert_mail_tbl_to_mail_flag(mail, &new_flag, NULL);
+
+ if (!em_core_check_thread_status()) {
+ err = EMF_ERROR_CANCELLED;
+ goto FINISH_OFF;
+ }
+
+ /* download message number from server. */
+ if (!em_core_mail_get_msgno_by_uid(ref_account, &mbox, mail->server_mail_id, &msgno, &err)) {
+ EM_DEBUG_LOG("em_core_mail_get_msgno_by_uid failed message_no : %d ", err);
+ goto FINISH_OFF;
+ }
+
+ memset(tmp, 0x00, 100);
+ sprintf (tmp, "%d", msgno);
+
+ memset(set_flags, 0x00, 100);
+ memset(clear_flags, 0x00, 100);
+
+ if (new_flag.seen)
+ sprintf(set_flags, "\\Seen");
+ else
+ sprintf(clear_flags, "\\Seen");
+ EM_DEBUG_LOG("new_flag.seen : %s ", set_flags);
+
+ if (strlen(set_flags) > 0) {
+ EM_DEBUG_LOG(">>>> Calling mail_setflag ");
+ mail_flag(stream, tmp, set_flags, ST_SET | ST_SILENT);
+ EM_DEBUG_LOG(">>>> End mail_setflag ");
+ }
+ else {
+ EM_DEBUG_LOG(">>>> Calling mail_clearflag ");
+ mail_clearflag(stream, tmp, clear_flags);
+ EM_DEBUG_LOG(">>>> End mail_clearflag ");
+ }
+
+ EM_DEBUG_LOG(">>>> Returning from em_core_mail_sync_flag_with_server ");
+
+ if (!em_core_check_thread_status()) {
+ err = EMF_ERROR_CANCELLED;
+ goto FINISH_OFF;
+ }
+ }
+ ret = true;
+
+FINISH_OFF:
+
+ if (stream) em_core_mailbox_close(account_id, stream);
+ if (mail) em_storage_free_mail(&mail, 1, NULL);
+
+ if (err_code != NULL)
+ *err_code = err;
+ EM_DEBUG_FUNC_END("err [%d]", err);
+ return ret;
+}
+
+
+
+EXPORT_API int em_core_mail_info_free(emf_mail_info_t **mail_info_list, int count, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("mail_info_list[%p], count[%d], err_code[%p]", mail_info_list, count, err_code);
+
+ if (count > 0) {
+ if (!mail_info_list || !*mail_info_list) {
+ EM_DEBUG_EXCEPTION("mail_info_list[%p]", mail_info_list);
+ if (err_code != NULL)
+ *err_code = EMF_ERROR_INVALID_PARAM;
+ return false;
+ }
+
+ emf_mail_info_t *p = *mail_info_list;
+ int i = 0;
+
+ for (; i < count; i++)
+ EM_SAFE_FREE(p[i].sid);
+
+ free(p);
+ *mail_info_list = NULL;
+ }
+
+ if (err_code != NULL)
+ *err_code = EMF_ERROR_NONE;
+ EM_DEBUG_FUNC_END();
+ return true;
+}
+
+EXPORT_API int em_core_mail_head_free(emf_mail_head_t **mail_head_list, int count, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("mail_head_list[%p], count[%d], err_code[%p]", mail_head_list, count, err_code);
+ EM_PROFILE_BEGIN(emCoreMailHeadeFree);
+
+ if (count > 0) {
+ if (!mail_head_list || !*mail_head_list) {
+ EM_DEBUG_EXCEPTION("mail_head_list[%p], count[%d]", mail_head_list, count);
+
+ if (err_code != NULL)
+ *err_code = EMF_ERROR_INVALID_PARAM;
+ return false;
+ }
+
+ int i;
+ emf_mail_head_t *p = *mail_head_list;
+
+ for (i = 0; i < count; i++) {
+ EM_SAFE_FREE(p[i].mid);
+ EM_SAFE_FREE(p[i].subject);
+ EM_SAFE_FREE(p[i].to);
+ EM_SAFE_FREE(p[i].from);
+ EM_SAFE_FREE(p[i].cc);
+ EM_SAFE_FREE(p[i].bcc);
+ EM_SAFE_FREE(p[i].reply_to);
+ EM_SAFE_FREE(p[i].return_path);
+ EM_SAFE_FREE(p[i].previewBodyText);
+ }
+
+ free(p); *mail_head_list = NULL;
+ }
+
+ if (err_code != NULL)
+ *err_code = EMF_ERROR_NONE;
+
+ EM_PROFILE_END(emCoreMailHeadeFree);
+ EM_DEBUG_FUNC_END();
+ return true;
+}
+
+EXPORT_API int em_core_mail_body_free(emf_mail_body_t **mail_body_list, int count, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("mail_body_list[%p], count[%d], err_code[%p]", mail_body_list, count, err_code);
+
+ if (count > 0) {
+ if (!mail_body_list || !*mail_body_list) {
+ EM_DEBUG_EXCEPTION("mail_body_list[%p]", mail_body_list);
+ if (err_code != NULL)
+ *err_code = EMF_ERROR_INVALID_PARAM;
+ return false;
+ }
+
+ emf_mail_body_t *p = *mail_body_list;
+ int i = 0;
+
+ for (; i < count; i++) {
+ EM_SAFE_FREE(p[i].plain);
+ EM_SAFE_FREE(p[i].plain_charset);
+ EM_SAFE_FREE(p[i].html);
+ if (p[i].attachment) em_core_mail_attachment_info_free(&p[i].attachment, NULL);
+ }
+
+ free(p); *mail_body_list = NULL;
+ }
+
+ if (err_code != NULL)
+ *err_code = EMF_ERROR_NONE;
+ EM_DEBUG_FUNC_END();
+ return true;
+}
+
+EXPORT_API int em_core_mail_free(emf_mail_t **mail_list, int count, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("mail_list[%p], count[%d], err_code[%p]", mail_list, count, err_code);
+
+ if (count > 0) {
+ if (!mail_list || !*mail_list) {
+ EM_DEBUG_EXCEPTION("mail_list[%p], count[%d]", mail_list, count);
+ if (err_code != NULL)
+ *err_code = EMF_ERROR_INVALID_PARAM;
+ return false;
+ }
+
+ emf_mail_t *p = *mail_list;
+ int i = 0;
+
+ for (; i < count; i++) {
+ if (p[i].info)
+ em_core_mail_info_free(&p[i].info, 1, NULL);
+
+ if (p[i].head)
+ em_core_mail_head_free(&p[i].head, 1, NULL);
+
+ if (p[i].body)
+ em_core_mail_body_free(&p[i].body, 1, NULL);
+ }
+
+ free(p); *mail_list = NULL;
+ }
+
+ if (err_code != NULL)
+ *err_code = EMF_ERROR_NONE;
+ EM_DEBUG_FUNC_END();
+ return true;
+}
+
+EXPORT_API int em_core_free_mail_data(emf_mail_data_t **mail_list, int count, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("mail_list[%p], count[%d]", mail_list, count);
+
+ if (count <= 0 || !mail_list || !*mail_list) {
+ EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
+ if(err_code)
+ *err_code = EMF_ERROR_INVALID_PARAM;
+ return false;
+ }
+
+ emf_mail_data_t* p = *mail_list;
+ int i;
+
+ for (i = 0; i < count; i++) {
+ EM_SAFE_FREE(p[i].mailbox_name);
+ EM_SAFE_FREE(p[i].subject);
+ EM_SAFE_FREE(p[i].datetime);
+ EM_SAFE_FREE(p[i].server_mailbox_name);
+ EM_SAFE_FREE(p[i].server_mail_id);
+ EM_SAFE_FREE(p[i].message_id);
+ EM_SAFE_FREE(p[i].full_address_from);
+ EM_SAFE_FREE(p[i].full_address_reply);
+ EM_SAFE_FREE(p[i].full_address_to);
+ EM_SAFE_FREE(p[i].full_address_cc);
+ EM_SAFE_FREE(p[i].full_address_bcc);
+ EM_SAFE_FREE(p[i].full_address_return);
+ EM_SAFE_FREE(p[i].email_address_sender);
+ EM_SAFE_FREE(p[i].email_address_recipient);
+ EM_SAFE_FREE(p[i].alias_sender);
+ EM_SAFE_FREE(p[i].alias_recipient);
+ EM_SAFE_FREE(p[i].file_path_plain);
+ EM_SAFE_FREE(p[i].file_path_html);
+ EM_SAFE_FREE(p[i].preview_text);
+ }
+
+ EM_SAFE_FREE(p); *mail_list = NULL;
+
+ if(err_code)
+ *err_code = EMF_ERROR_NONE;
+
+ EM_DEBUG_FUNC_END();
+ return true;
+}
+
+
+EXPORT_API int em_core_mail_attachment_info_free(emf_attachment_info_t **atch_info, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("atch_info[%p], err_code[%p]", atch_info, err_code);
+
+ if (!atch_info || !*atch_info) {
+ if (err_code != NULL)
+ *err_code = EMF_ERROR_INVALID_PARAM;
+ return false;
+ }
+
+ emf_attachment_info_t *p = *atch_info;
+ emf_attachment_info_t *t;
+
+ while (p) {
+ EM_SAFE_FREE(p->name);
+ EM_SAFE_FREE(p->savename);
+ t = p->next;
+ free(p); p = NULL;
+ p = t;
+ }
+
+ if (err_code != NULL)
+ *err_code = EMF_ERROR_NONE;
+ EM_DEBUG_FUNC_END();
+ return true;
+}
+
+
+EXPORT_API int em_core_free_attachment_data(emf_attachment_data_t **attachment_data_list, int attachment_data_count, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("attachment_data_list[%p], attachment_data_count [%d], err_code[%p]", attachment_data_list, attachment_data_count, err_code);
+
+ if (!attachment_data_list || !*attachment_data_list) {
+ if (err_code != NULL)
+ *err_code = EMF_ERROR_INVALID_PARAM;
+ return false;
+ }
+
+ emf_attachment_data_t* p = *attachment_data_list;
+ int i = 0;
+
+ for (i = 0; i < attachment_data_count; i++) {
+ EM_SAFE_FREE(p[i].mailbox_name);
+ EM_SAFE_FREE(p[i].attachment_name);
+ EM_SAFE_FREE(p[i].attachment_path);
+ }
+
+ EM_SAFE_FREE(p); *attachment_data_list = NULL;
+
+ if(err_code)
+ *err_code = EMF_ERROR_NONE;
+
+ EM_DEBUG_FUNC_END();
+ return true;
+}
+
+
+
+#ifdef __FEATURE_PARTIAL_BODY_DOWNLOAD__
+
+EXPORT_API int em_core_delete_pbd_activity(int account_id, int mail_id, int activity_id, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("account_id[%d], mail_id[%d], err_code[%p]", account_id, mail_id, err_code);
+
+ if (account_id < FIRST_ACCOUNT_ID || mail_id < 0) {
+ EM_DEBUG_EXCEPTION("account_id[%d], mail_id[%d], err_code[%p]", account_id, mail_id, err_code);
+ if (err_code != NULL)
+ *err_code = EM_STORAGE_ERROR_INVALID_PARAM;
+ return false;
+ }
+
+ int ret = false;
+ int err = EMF_ERROR_NONE;
+
+ em_storage_begin_transaction(NULL, NULL, NULL);
+
+ if (!em_storage_delete_pbd_activity(account_id, mail_id, activity_id, false, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_delete_pbd_activity failed [%d]", err);
+
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+
+ ret = true;
+
+FINISH_OFF:
+ if (ret == true) { /* COMMIT TRANSACTION; */
+ if (em_storage_commit_transaction(NULL, NULL, NULL) == false) {
+ err = em_storage_get_emf_error_from_em_storage_error(EM_STORAGE_ERROR_DB_FAILURE);
+ ret = false;
+ }
+ }
+ else { /* ROLLBACK TRANSACTION; */
+ if (em_storage_rollback_transaction(NULL, NULL, NULL) == false)
+ err = em_storage_get_emf_error_from_em_storage_error(EM_STORAGE_ERROR_DB_FAILURE);
+ }
+
+ if (err_code != NULL)
+ *err_code = err;
+ EM_DEBUG_FUNC_END();
+ return ret;
+}
+
+EXPORT_API int em_core_insert_pbd_activity(emf_event_partial_body_thd *local_activity, int *activity_id, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("local_activity[%p], activity_id[%p], err_code[%p]", local_activity, activity_id, err_code);
+
+ if (!local_activity || !activity_id) {
+ EM_DEBUG_EXCEPTION("local_activity[%p], activity_id[%p] err_code[%p]", local_activity, activity_id, err_code);
+ if (err_code != NULL)
+ *err_code = EM_STORAGE_ERROR_INVALID_PARAM;
+ return false;
+ }
+
+ int ret = false;
+ int err = EMF_ERROR_NONE;
+
+ em_storage_begin_transaction(NULL, NULL, NULL);
+
+ if (!em_storage_add_pbd_activity(local_activity, activity_id, false, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_add_pbd_activity failed [%d]", err);
+
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+
+ ret = true;
+
+FINISH_OFF:
+ if (ret == true) { /* COMMIT TRANSACTION; */
+ if (em_storage_commit_transaction(NULL, NULL, NULL) == false) {
+ err = em_storage_get_emf_error_from_em_storage_error(EM_STORAGE_ERROR_DB_FAILURE);
+ ret = false;
+ }
+ }
+ else { /* ROLLBACK TRANSACTION; */
+ if (em_storage_rollback_transaction(NULL, NULL, NULL) == false)
+ err = em_storage_get_emf_error_from_em_storage_error(EM_STORAGE_ERROR_DB_FAILURE);
+ }
+
+ if (err_code != NULL)
+ *err_code = err;
+ EM_DEBUG_FUNC_END();
+ return ret;
+}
+
+#endif
+
+#ifdef __FEATURE_BULK_DELETE_MOVE_UPDATE_REQUEST_OPTI__
+
+/* API to set or unset a field of flags on server in single IMAP request to server */
+
+EXPORT_API int em_core_mail_sync_flags_field_with_server(int mail_ids[], int num, emf_flags_field_type field_type, int value, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("mail_ids [%p], num [%d], field_type [%d], value [%d], err_code [%p]", mail_ids, num, field_type, value, err_code);
+
+ if (NULL == mail_ids || num <= 0 || field_type < 0 || field_type >= EMF_FLAGS_FIELD_COUNT) {
+ EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
+ if (err_code != NULL) {
+ *err_code = EMF_ERROR_INVALID_PARAM;
+ }
+ return false;
+ }
+
+ MAILSTREAM *stream = NULL;
+ IMAPLOCAL *imaplocal = NULL;
+ char tag[MAX_TAG_SIZE] = {0, };
+ char cmd[MAX_IMAP_COMMAND_LENGTH] = {0, };
+ char *p = NULL;
+ char **string_list = NULL;
+ int ret = false;
+ int err = EMF_ERROR_NONE;
+ int command_success = false;
+ int account_id = 0;
+ int mail_id = 0;
+ int i = 0;
+ int id_set_count = 0;
+ int len_of_each_range = 0;
+ int string_count = 0;
+ emf_account_t *temp_account;
+ emf_id_set_t *id_set = NULL;
+ emf_mail_tbl_t *mail = NULL;
+ emf_uid_range_set *uid_range_set = NULL;
+ emf_uid_range_set *uid_range_node = NULL;
+ char *field_type_name[EMF_FLAGS_FIELD_COUNT] = { "\\Seen"
+ , "\\Deleted", "\\Flagged", "\\Answered"
+ , "\\Recent", "\\Draft", "$Forwarded" };
+
+ mail_id = mail_ids[0];
+
+ if (!em_storage_get_mail_field_by_id(mail_id, RETRIEVE_FLAG, &mail, true, &err) || !mail) /*To DO : This is a existing bug. on mail deletion before this call it will fail always */ {
+ EM_DEBUG_LOG("em_storage_get_mail_by_id failed [%d]", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+
+ account_id = mail[0].account_id;
+
+ temp_account = em_core_get_account_reference(account_id);
+
+ if (!temp_account) {
+ EM_DEBUG_EXCEPTION("em_core_get_account_reference failed [%d]", account_id);
+ err = EMF_ERROR_INVALID_ACCOUNT;
+ goto FINISH_OFF;
+ }
+
+ if (temp_account->receiving_server_type != EMF_SERVER_TYPE_IMAP4) {
+ EM_DEBUG_EXCEPTION("Syncing seen flag is available only for IMAP4 server. The server type [%d]", temp_account->receiving_server_type);
+ err = EMF_ERROR_NOT_SUPPORTED;
+ goto FINISH_OFF;
+ }
+
+ if (!em_core_mailbox_open(account_id, mail->mailbox_name, (void **)&stream, &err) || !stream) {
+ EM_DEBUG_EXCEPTION("em_core_mailbox_open failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ if (false == em_storage_free_mail(&mail, 1, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_free_mail failed - %d ", err);
+ goto FINISH_OFF;
+ }
+
+ /* [h.gahlaut] Break the set of mail_ids into comma separated strings of given length */
+ /* Length is decided on the basis of remaining keywords in the Query to be formed later on in em_storage_get_id_set_from_mail_ids */
+ /* Here about 90 bytes are required for fixed keywords in the query-> SELECT local_uid, s_uid from mail_read_mail_uid_tbl where local_uid in (....) ORDER by s_uid */
+ /* So length of comma separated strings which will be filled in (.....) in above query can be maximum QUERY_SIZE - 90 */
+
+ if (false == em_core_form_comma_separated_strings(mail_ids, num, QUERY_SIZE - 90, &string_list, &string_count, &err)) {
+ EM_DEBUG_EXCEPTION("em_core_form_comma_separated_strings failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ /* Now execute one by one each comma separated string of mail_ids */
+
+ for (i = 0; i < string_count; ++i) {
+ /* Get the set of mail_ds and corresponding server_mail_ids sorted by server mail ids in ascending order */
+
+ if (false == em_storage_get_id_set_from_mail_ids(string_list[i], &id_set, &id_set_count, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_get_id_set_from_mail_ids failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ /* Convert the sorted sequence of server mail ids to range sequences of given length. A range sequence will be like A : B, C, D: E, H */
+
+ len_of_each_range = MAX_IMAP_COMMAND_LENGTH - 40; /* 1000 is the maximum length allowed RFC 2683. 40 is left for keywords and tag. */
+
+ if (false == em_core_convert_to_uid_range_set(id_set, id_set_count, &uid_range_set, len_of_each_range, &err)) {
+ EM_DEBUG_EXCEPTION("em_core_convert_to_uid_range_set failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ uid_range_node = uid_range_set;
+
+ while (uid_range_node != NULL) {
+ /* Remove comma from end of uid_range */
+
+ uid_range_node->uid_range[strlen(uid_range_node->uid_range) - 1] = '\0';
+
+ /* Form the IMAP command */
+
+ SNPRINTF(tag, MAX_TAG_SIZE, "%08lx", 0xffffffff & (stream->gensym++));
+
+ if (value)
+ SNPRINTF(cmd, MAX_IMAP_COMMAND_LENGTH, "%s UID STORE %s +FLAGS (%s)\015\012", tag, uid_range_node->uid_range, field_type_name[field_type]);
+ else
+ SNPRINTF(cmd, MAX_IMAP_COMMAND_LENGTH, "%s UID STORE %s -FLAGS (%s)\015\012", tag, uid_range_node->uid_range, field_type_name[field_type]);
+
+ EM_DEBUG_LOG("[IMAP4] command %s", cmd);
+
+ /* send command */
+
+ if (!(imaplocal = stream->local) || !imaplocal->netstream) {
+ EM_DEBUG_EXCEPTION("invalid IMAP4 stream detected...");
+
+ err = EMF_ERROR_UNKNOWN;
+ goto FINISH_OFF;
+ }
+
+ if (!net_sout(imaplocal->netstream, cmd, (int)strlen(cmd))) {
+ EM_DEBUG_EXCEPTION("net_sout failed...");
+ err = EMF_ERROR_CONNECTION_BROKEN;
+ goto FINISH_OFF;
+ }
+
+ /* Receive Response */
+
+ command_success = false;
+
+ while (imaplocal->netstream) {
+ if (!(p = net_getline(imaplocal->netstream))) {
+ EM_DEBUG_EXCEPTION("net_getline failed...");
+
+ err = EMF_ERROR_INVALID_RESPONSE;
+ goto FINISH_OFF;
+ }
+
+ EM_DEBUG_LOG("[IMAP4 Response ] %s", p);
+
+ if (!strncmp(p, tag, strlen(tag))) {
+ if (!strncmp(p + strlen(tag) + 1, "OK", 2)) {
+ /*Delete all local activities */
+ command_success = true;
+
+ EM_SAFE_FREE(p);
+ break;
+ }
+ else {
+ /* 'NO' or 'BAD' */
+ command_success = false;
+ err = EMF_ERROR_IMAP4_STORE_FAILURE;
+ EM_SAFE_FREE(p);
+ goto FINISH_OFF;
+ }
+ }
+
+ EM_SAFE_FREE(p);
+ }
+
+ uid_range_node = uid_range_node->next;
+ }
+
+ em_core_free_uid_range_set(&uid_range_set);
+
+ EM_SAFE_FREE(id_set);
+
+ id_set_count = 0;
+ }
+
+ ret = true;
+
+FINISH_OFF:
+
+#ifdef __LOCAL_ACTIVITY__
+ if (ret) {
+ emf_activity_tbl_t new_activity;
+ for (i = 0; i<num ; i++) {
+ memset(&new_activity, 0x00, sizeof(emf_activity_tbl_t));
+ new_activity.activity_type = ACTIVITY_MODIFYSEENFLAG;
+ new_activity.account_id = account_id;
+ new_activity.mail_id = mail_ids[i];
+
+ if (!em_core_activity_delete(&new_activity, &err))
+ EM_DEBUG_EXCEPTION("Local Activity ACTIVITY_MOVEMAIL [%d] ", err);
+ }
+
+ }
+#endif
+
+ if (NULL != mail) {
+ if (false == em_storage_free_mail(&mail, 1, &err))
+ EM_DEBUG_EXCEPTION("em_storage_free_mail failed - %d ", err);
+ }
+
+ em_core_free_comma_separated_strings(&string_list, &string_count);
+
+ if (false == ret)
+ em_core_free_uid_range_set(&uid_range_set);
+
+ em_core_mailbox_close(0, stream);
+ stream = NULL;
+
+ if (err_code != NULL)
+ *err_code = err;
+ EM_DEBUG_FUNC_END();
+ return ret;
+
+}
+#endif
+
+EXPORT_API int em_core_mail_filter_by_rule(emf_rule_t *filter_info, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("filter_info[%p], err_code[%p]", filter_info, err_code);
+
+ int ret = false, err = EMF_ERROR_NONE;
+ int account_index, account_count, mail_id_index = 0;
+ emf_account_t *account_ref = NULL, *account_list_ref = NULL;
+ int filtered_mail_id_count = 0, *filtered_mail_id_list = NULL, parameter_string_length = 0;
+ char *parameter_string = NULL, mail_id_string[10] = { 0x00, };
+ emf_mailbox_tbl_t *spam_mailbox = NULL;
+
+ if (!filter_info) {
+ EM_DEBUG_EXCEPTION("filter_info[%p]", filter_info);
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ if (!em_core_account_get_list_refer(&account_list_ref, &account_count, &err)) {
+ EM_DEBUG_EXCEPTION("em_core_account_get_list_refer failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ for (account_index = 0; account_index < account_count; account_index++) {
+ account_ref = account_list_ref + account_index;
+
+ if (!em_storage_get_mailbox_by_mailbox_type(account_ref->account_id, EMF_MAILBOX_TYPE_SPAMBOX, &spam_mailbox, false, &err))
+ EM_DEBUG_EXCEPTION("em_storage_get_mailbox_by_mailbox_type for account_id[%d] failed [%d]", account_ref->account_id, err);
+ else if (spam_mailbox && spam_mailbox->mailbox_name) {
+ if (!em_storage_filter_mails_by_rule(account_ref->account_id, spam_mailbox->mailbox_name, (emf_mail_rule_tbl_t *)filter_info, &filtered_mail_id_list, &filtered_mail_id_count, &err))
+ EM_DEBUG_EXCEPTION("em_storage_filter_mails_by_rule failed [%d]", err);
+ else {
+ if (filtered_mail_id_count) {
+ parameter_string_length = strlen(spam_mailbox->mailbox_name) + 7 + (10 * filtered_mail_id_count);
+ parameter_string = em_core_malloc(sizeof(char) * parameter_string_length);
+
+ if (parameter_string == NULL) {
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ EM_DEBUG_EXCEPTION("em_core_malloc failed for parameter_string");
+ goto FINISH_OFF;
+ }
+
+ SNPRINTF(parameter_string, parameter_string_length, "[NA]%c%s%c", 0x01, spam_mailbox->mailbox_name, 0x01);
+
+ for (mail_id_index = 0; mail_id_index < filtered_mail_id_count; mail_id_index++) {
+ memset(mail_id_string, 0, 10);
+ SNPRINTF(mail_id_string, 10, "%d", filtered_mail_id_list[mail_id_index]);
+ strcat(parameter_string, mail_id_string);
+ strcat(parameter_string, ",");
+ }
+
+ EM_DEBUG_LOG("filtered_mail_id_count [%d]", filtered_mail_id_count);
+ EM_DEBUG_LOG("param string [%s]", parameter_string);
+
+ if (!em_storage_notify_storage_event(NOTI_MAIL_MOVE, account_ref->account_id, 0, parameter_string, 0))
+ EM_DEBUG_EXCEPTION("em_storage_notify_storage_event failed [ NOTI_MAIL_MOVE ] >>>> ");
+
+ EM_SAFE_FREE(filtered_mail_id_list);
+ EM_SAFE_FREE(parameter_string);
+ }
+ }
+ em_storage_free_mailbox(&spam_mailbox, 1, &err);
+ spam_mailbox = NULL;
+ }
+ }
+
+ em_core_check_unread_mail();
+
+ ret = true;
+
+FINISH_OFF:
+ EM_SAFE_FREE(account_list_ref);
+ EM_SAFE_FREE(filtered_mail_id_list);
+ EM_SAFE_FREE(parameter_string);
+
+
+ if (spam_mailbox)
+ em_storage_free_mailbox(&spam_mailbox, 1, &err);
+
+ if (err_code)
+ *err_code = err;
+ EM_DEBUG_FUNC_END();
+ return ret;
+}
diff --git a/email-core/em-core-mime.c b/email-core/em-core-mime.c
new file mode 100755
index 0000000..8e17098
--- /dev/null
+++ b/email-core/em-core-mime.c
@@ -0,0 +1,4719 @@
+/*
+* email-service
+*
+* Copyright (c) 2000 - 2011 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.
+*
+*/
+
+
+
+/* ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ***
+ *File : em-core-mime.c
+ *Desc : MIME Operation
+ *
+ *Auth :
+ *
+ *History :
+ * 2011.04.14 : created
+ ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ***/
+#undef close
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <vconf.h>
+#include <ctype.h>
+#include <sys/stat.h>
+#include <sys/time.h>
+#include "em-core-types.h"
+#include "lnx_inc.h"
+#include "em-core-global.h"
+#include "em-core-utils.h"
+#include "em-core-mesg.h"
+#include "em-core-mime.h"
+#include "em-storage.h"
+#include "em-core-event.h"
+#include "em-core-account.h"
+#include "emf-dbglog.h"
+
+
+#define MIME_MESG_IS_SOCKET
+
+#define MIME_LINE_LEN 1024
+#define BOUNDARY_LEN 256
+
+#define TYPE_TEXT 1
+#define TYPE_IMAGE 2
+#define TYPE_AUDIO 3
+#define TYPE_VIDEO 4
+#define TYPE_APPLICATION 5
+#define TYPE_MULTIPART 6
+#define TYPE_MESSAGE 7
+#define TYPE_UNKNOWN 8
+
+#define TEXT_STR "TEXT"
+#define IMAGE_STR "IMAGE"
+#define AUDIO_STR "AUDIO"
+#define VIDEO_STR "VIDEO"
+#define APPLICATION_STR "APPLICATION"
+#define MULTIPART_STR "MULTIPART"
+#define MESSAGE_STR "MESSAGE"
+
+#define CONTENT_TYPE 1
+#define CONTENT_SUBTYPE 2
+#define CONTENT_ENCODING 3
+#define CONTENT_CHARSET 4
+#define CONTENT_DISPOSITION 5
+#define CONTENT_NAME 6
+#define CONTENT_FILENAME 7
+#define CONTENT_BOUNDARY 8
+#define CONTENT_REPORT_TYPE 9
+#define CONTENT_ID 10
+#define CONTENT_LOCATION 11
+
+#define GRAB_TYPE_TEXT 1 /* retrieve text and attachment name */
+#define GRAB_TYPE_ATTACHMENT 2 /* retrieve only attachmen */
+
+#define SAVE_TYPE_SIZE 1 /* only get content siz */
+#define SAVE_TYPE_BUFFER 2 /* save content to buffe */
+#define SAVE_TYPE_FILE 3 /* save content to temporary fil */
+
+/*
+ MIME Structure Example
+
+ (part 0) multipart/mixed
+ (part 1) multipart/alternative
+ (part 1.1) text/plain <- text message
+ (part 1.2) text/html <- html message
+ (part 2) text/plain <- text attachment
+
+
+ (part 0) multipart/related
+ (part 1) multipart/alternative
+ (part 1.1) text/plain <- text message
+ (part 1.2) text/html <- html message
+ (part 2) image/png <- inline image
+ (part 2) image/png <- inline image
+
+
+ (part 0) multipart/mixed
+ (part 1.1) multipart/related
+ (part 2.1) multipart/alternative
+ (part 3.1) text/plain(body) <- text message
+ (part 3.2) text/html(body) <- html message
+ (part 2.2) image/png(related) <- inline image
+ (part 1.2) image/png(attachment) <- image attachment
+*/
+
+/* Text and Attachment Holde */
+/* struct _m_content_info */
+/* int grab_type; */ /* 1 : text and attachment list */
+ /* 2 : attachmen */
+/* int file_no; */ /* attachment sequence to be downloaded (min : 1 */
+/* struct text_data */
+/* char *plain; */ /* body plain tex */
+/* char *plain_charset */ /* charset of plai */
+/* char *html; */ /* body html tex */
+/* } text */
+
+/* struct attachment_info */
+/* int type; */ /* 1 : inline 2 : attachmen */
+/* char *name; */ /* attachment filenam */
+/* int size; */ /* attachment siz */
+/* char *save; */ /* content saving filenam */
+/* struct attachment_info *next */
+/* } *file */
+/* } */
+
+/* --------------------- MIME Structure --------------------------------- */
+/* MIME Header Parameter (Content-Type, Content-Disposition, ... */
+struct _parameter {
+ char *name; /* parameter name */
+ char *value; /* parameter valu */
+ struct _parameter *next; /* next paramete */
+};
+
+/* Content-Dispositio */
+struct _disposition {
+ char *type; /* "inline" "attachment */
+ struct _parameter *parameter; /* "filename", .. */
+};
+
+/* RFC822 Heade */
+struct _rfc822header {
+ char *return_path; /* error return pat */
+ char *received;
+ char *date;
+ char *from;
+ char *subject;
+ char *sender;
+ char *to;
+ char *cc;
+ char *bcc;
+ char *reply_to;
+ char *priority;
+ char *ms_priority;
+ char *dsp_noti_to;
+ char *others;
+};
+/* MIME Part Header */
+struct _m_part_header {
+ char *type; /* text, image, audio, video, application, multipart, messag */
+ char *subtype; /* plain, html, jpeg, .. */
+ char *encoding; /* encoding typ */
+ struct _parameter *parameter; /* content-type parameter : "boundary" "charset" .. */
+ char *desc; /* descriptio */
+ char *disp_type; /* disposition type : "inline" "attachment", */
+ struct _parameter *disp_parameter; /* disposition parameter : "filename", .. */
+ char *content_id; /* content id : it is inline */
+ char *content_location; /* content location : "inline" location */
+};
+
+/* MIME Message Header */
+struct _m_mesg_header {
+ char *version; /* MIME Versio */
+ struct _m_part_header *part_header; /* MIME Part Heade */
+};
+
+/* MIME Multipart Body linked list */
+typedef struct _m_body _m_body_t;
+struct _m_part{
+ _m_body_t *body; /* part bod */
+ struct _m_part *next; /* the next found par */
+};
+
+/* MIME Multipart Body */
+struct _m_body {
+ struct _m_part_header *part_header; /* MIME Part Heade */
+ struct _m_part nested; /* nested structure if contain multipar */
+ char *text; /* text if not contain multipar */
+ int size; /* text size if not contain multipar */
+ char *holdingfile;
+};
+
+/* MIME Message */
+struct _m_mesg {
+ struct _rfc822header *rfc822header; /* RFC822 Heade */
+ struct _m_mesg_header *header; /* MIME Message Heade */
+ struct _m_part nested; /* nested structure if contain multipar */
+ char *text; /* text if not contain multipar */
+ int size; /* text size if not contain multipar */
+};
+/* ---------------------------------------------------------------------- */
+/* Global variable */
+static bool next_decode_string = false;
+
+
+/* ---------------------------------------------------------------------- */
+/* External variable */
+extern int _pop3_receiving_mail_id;
+extern int _pop3_received_body_size;
+extern int _pop3_last_notified_body_size;
+extern int _pop3_total_body_size;
+
+extern int _imap4_received_body_size;
+extern int _imap4_last_notified_body_size;
+extern int _imap4_total_body_size;
+extern int _imap4_download_noti_interval_value;
+
+extern int multi_part_body_size;
+extern bool only_body_download;
+
+extern BODY **g_inline_list;
+extern int g_inline_count;
+
+/* ---------------------------------------------------------------------- */
+/* Function Declaration */
+
+/* parsing the first header (RFC822 Header and Message Header and Etc... */
+static int em_core_mime_parse_header(void *stream, int is_file, struct _rfc822header **rfcheader, struct _m_mesg_header **header, int *err_code);
+
+/* parsing the first bod */
+static int em_core_mime_parse_body(void *stream, int is_file, struct _m_mesg *mmsg, struct _m_content_info *cnt_info, void *callback, int *err_code);
+
+/* parsing the message part header (CONTENT-... header */
+static int em_core_mime_parse_part_header(void *stream, int is_file, struct _m_part_header **header, int *err_code);
+
+/* parsing the message part by boundar */
+static int em_core_mime_parse_part(void *stream, int is_file, struct _m_part_header *parent_header, struct _m_part *nested, struct _m_content_info *cnt_info, int *end_of_parsing, int *err_code);
+
+/* set RFC822 Header valu */
+static int em_core_mime_set_rfc822_header_value(struct _rfc822header **rfc822header, char *name, char *value, int *err_code);
+
+/* set Message Part Header (Content-... Header */
+static int em_core_mime_set_part_header_value(struct _m_part_header **header, char *name, char *value, int *err_code);
+
+char *em_core_mime_get_content_param(struct _m_body *mbody, char *name, int *err_code);
+
+static int em_core_mime_get_param_from_str(char *str, struct _parameter **param, int *err_code);
+
+static int em_core_mime_add_param_to_list(struct _parameter **param_list, struct _parameter *param, int *err_code);
+
+char *em_core_mime_get_header_value(struct _m_part_header *header, int type, int *err_code);
+
+void em_core_mime_free_param(struct _parameter *param);
+void em_core_mime_free_part_header(struct _m_part_header *header);
+void em_core_mime_free_message_header(struct _m_mesg_header *header);
+void em_core_mime_free_rfc822_header(struct _rfc822header *rfc822header);
+void em_core_mime_free_part(struct _m_part *part);
+void em_core_mime_free_part_body(struct _m_body *body);
+void em_core_mime_free_mime(struct _m_mesg *mmsg);
+char *em_core_mime_get_line_from_sock(void *stream, char *buf, int size, int *err_code);
+char *em_core_mime_trim_left(char *str);
+char *em_core_mime_trim_right(char *str);
+char *em_core_mime_upper_str(char *str);
+char *em_core_mime_get_save_file_name(int *err_code);
+
+/* get content data and save buffer or fil */
+/* mode - 1 : get the only siz */
+/* 2 : save content to buffer (holder is buffer */
+/* 3 : save content to file (holder is file name */
+static int em_core_mime_get_content_data(void *stream,
+ int is_file,
+ int is_text,
+ char *boundary_str,
+ char *content_encoding,
+ int *end_of_parsing,
+ int mode,
+ char **holder,
+ int *size,
+ void *callback,
+ int *err_code);
+/* skip content data to boundary_str or end of fil */
+int em_core_mime_skip_content_data(void *stream,
+ int is_file,
+ char *boundary_str,
+ int *end_of_parsing,
+ int *size,
+ void *callback,
+ int *err_code);
+
+static int em_core_get_file_pointer(BODY *body, char *buf, struct _m_content_info *cnt_info , int *err);
+static PARTLIST *em_core_get_body_full(MAILSTREAM *stream, int msg_uid, BODY *body, struct _m_content_info *cnt_info, int *err_code, PARTLIST *section_list);
+static int em_core_get_body_part_imap_full(MAILSTREAM *stream, int msg_uid, int account_id, int mail_id, PARTLIST *section_list, struct _m_content_info *cnt_info, int *err_code, int event_handle);
+static PARTLIST *em_core_add_node(PARTLIST *section_list, BODY *body);
+static void em_core_free_section_list(PARTLIST *section_list);
+static int em_core_get_section_body_size(char *response, char *section, int *body_size);
+static void parse_file_path_to_filename(char *src_string, char **out_string);
+extern long pop3_reply (MAILSTREAM *stream);
+/* ------------------------------------------------------------------------------------------------- */
+
+
+/* Fix for issue junk characters in mail body */
+char *em_split_file_path(char *str)
+{
+ EM_DEBUG_FUNC_BEGIN("str [%s]", str);
+
+ EM_IF_NULL_RETURN_VALUE(str, NULL);
+
+ char *buf = NULL;
+ char delims[] = "@";
+ char *result = NULL;
+ char *temp_str = NULL;
+ char *content_id = NULL;
+ int buf_length = 0;
+ char *temp_cid_data = NULL;
+ char *temp_cid = NULL;
+ temp_str = EM_SAFE_STRDUP(str);
+ buf_length = strlen(str) + 1024;
+ buf = em_core_malloc(buf_length);
+ content_id = temp_str;
+ temp_cid = strstr(temp_str, "\"");
+
+ if (temp_cid == NULL) {
+ EM_DEBUG_EXCEPTION(">>>> File Path Doesnot contain end line for CID ");
+ next_decode_string = true;
+ EM_SAFE_FREE(buf);
+ return temp_str;
+ }
+ temp_cid_data = em_core_malloc((temp_cid-temp_str)+1);
+ memcpy(temp_cid_data, temp_str, (temp_cid-temp_str));
+
+ if (!strstr(temp_cid_data, delims)) {
+ EM_DEBUG_EXCEPTION(">>>> File Path Doesnot contain @ ");
+ next_decode_string = true;
+ EM_SAFE_FREE(buf);
+ EM_SAFE_FREE(temp_cid_data);
+ return temp_str;
+ }
+ else {
+ result = strstr(temp_str, delims);
+ if (result != NULL) {
+ next_decode_string = false;
+ *result = '\0';
+ result++;
+ EM_DEBUG_LOG("content_id is [ %s ]", content_id);
+
+ if (strcasestr(content_id, ".bmp") || strcasestr(content_id, ".jpeg") || strcasestr(content_id, ".png") ||
+ strcasestr(content_id, ".jpg") || strcasestr(content_id, ".gif"))
+ snprintf(buf+strlen(buf), buf_length - strlen(buf), "%s\"", content_id);
+ else
+ snprintf(buf+strlen(buf), buf_length - strlen(buf), "%s%s", content_id, ".jpeg\"");
+ }
+ else {
+ EM_DEBUG_EXCEPTION(">>>> File Path Doesnot contain end line for CID ");
+ next_decode_string = true;
+ EM_SAFE_FREE(buf);
+ EM_SAFE_FREE(temp_cid_data);
+ return temp_str;
+ }
+ result = strstr(result, "\"");
+ if (result != NULL) {
+ result++;
+ snprintf(buf+strlen(buf), buf_length - strlen(buf), "%s", result);
+ }
+ }
+ EM_SAFE_FREE(temp_str);
+ EM_SAFE_FREE(temp_cid_data);
+ return buf;
+}
+
+
+static char *em_replace_string_with_split_file_path(char *source_string, char *old_string, char *new_string)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ char *buffer = NULL;
+ char *split_str = NULL;
+ char *p = NULL;
+ char *q = NULL;
+ int buf_len = 0;
+
+ EM_IF_NULL_RETURN_VALUE(source_string, NULL);
+ EM_IF_NULL_RETURN_VALUE(old_string, NULL);
+ EM_IF_NULL_RETURN_VALUE(new_string, NULL);
+
+ EM_DEBUG_LOG("source_string [%s] ", source_string);
+ EM_DEBUG_LOG("old_string [%s] ", old_string);
+ EM_DEBUG_LOG("new_string [%s] ", new_string);
+
+ p = strstr(source_string, old_string);
+
+ if (!p) {
+ EM_DEBUG_EXCEPTION("Orig not found in source_string");
+ return NULL;
+ }
+
+ buf_len = strlen(source_string) + 1024;
+ buffer = (char *)em_core_malloc(buf_len);
+
+ if(p - source_string < strlen(source_string) + 1024 + 1) {
+ strncpy(buffer, source_string, p - source_string);
+
+ EM_DEBUG_LOG("BUFFER [%s]", buffer);
+
+ split_str = em_split_file_path(p);
+
+ if (!split_str) {
+ EM_DEBUG_EXCEPTION(">> SPLIT STRING IS NULL ");
+ goto FINISH_OFF;
+ }
+
+ q = strstr(split_str, old_string);
+ if (q) {
+ EM_DEBUG_LOG("Split string [%s]", split_str);
+ snprintf(buffer + strlen(buffer), buf_len - strlen(buffer), "%s%s", new_string, q+strlen(old_string));
+ EM_DEBUG_LOG("BUFFER 1 [%s]", buffer);
+ EM_SAFE_FREE(split_str);
+ EM_DEBUG_FUNC_END("Suceeded");
+ return buffer;
+ }
+ }
+ else {
+ EM_DEBUG_EXCEPTION("Buffer is too small.");
+ EM_SAFE_FREE(buffer);
+ return NULL;
+ }
+
+FINISH_OFF:
+ EM_SAFE_FREE(split_str);
+ EM_SAFE_FREE(buffer);
+
+ EM_DEBUG_FUNC_END("Failed");
+ return NULL;
+
+}
+
+
+int
+em_core_mime_flush_receiving_buffer(void *stream, int is_file, char *boundary_string, char *boundary_end_string, int *end_of_parsing, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("stream[%p], is_file[%d], boundary_string[%s], boundary_end_string[%s], end_of_parsing[%p], err_code[%p]", stream, is_file, boundary_string, boundary_end_string, end_of_parsing, err_code);
+ char buf[MIME_LINE_LEN] = {0, };
+ int local_end_of_parsing = 0;
+
+ if (!stream) {
+ if (err_code)
+ *err_code = EMF_ERROR_INVALID_PARAM;
+ EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
+ return false;
+ }
+
+ while (TRUE) {
+ if (!em_core_check_thread_status()) {
+ if (err_code != NULL)
+ *err_code = EMF_ERROR_CANCELLED;
+ EM_DEBUG_FUNC_END("EMF_ERROR_CANCELLED");
+ return false;
+ }
+
+ if ((is_file == 0 && !em_core_mime_get_line_from_sock(stream, buf, MIME_LINE_LEN, err_code)) ||
+ (is_file == 1 && !em_core_mime_get_line_from_file(stream, buf, MIME_LINE_LEN, err_code))) {
+ EM_DEBUG_EXCEPTION("em_core_mime_get_line_from_sock failed");
+ local_end_of_parsing = 0;
+ break;
+ }
+
+ if (boundary_string && boundary_end_string) {
+ if (!strcmp(buf, boundary_string)) {
+ EM_DEBUG_LOG("found boundary");
+ local_end_of_parsing = 0;
+ break;
+ }
+ else if (!strcmp(buf, boundary_end_string)) {
+ EM_DEBUG_LOG("found boundary_end");
+ local_end_of_parsing = 1;
+ break;
+ }
+ }
+ }
+
+ if (end_of_parsing)
+ *end_of_parsing = local_end_of_parsing;
+
+ EM_DEBUG_FUNC_END();
+ return true;
+}
+
+int em_core_mime_parse_mime(void *stream, int is_file, struct _m_content_info *cnt_info, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("stream[%p], is_file[%d], cnt_info[%p], err_code[%p]", stream, is_file, cnt_info, err_code);
+
+ struct _m_mesg *mmsg = em_core_malloc(sizeof(struct _m_mesg));
+
+ if (!mmsg) return false;
+
+ memset(mmsg, 0x00, sizeof(struct _m_mesg));
+
+ /* 1. parse the first found heade */
+ EM_DEBUG_LOG(">>>>>> 1. parse the first found header");
+ if (!em_core_mime_parse_header(stream, is_file, &mmsg->rfc822header, &mmsg->header, err_code)) {
+ EM_SAFE_FREE(mmsg);
+ return false;
+ }
+
+ if (!em_core_check_thread_status()) {
+ if (err_code != NULL)
+ *err_code = EMF_ERROR_CANCELLED;
+ return false;
+ }
+
+ /* 2. parse bod */
+ EM_DEBUG_LOG(">>>>>> 2. parse body");
+ if (mmsg && mmsg->header && mmsg->header->part_header && mmsg->header->part_header->parameter) {
+ EM_DEBUG_LOG("name[%s]", mmsg->header->part_header->parameter->name);
+ EM_DEBUG_LOG("value[%s]", mmsg->header->part_header->parameter->value);
+ EM_DEBUG_LOG("next : %p", mmsg->header->part_header->parameter->next);
+ }
+
+ if (em_core_mime_parse_body(stream, is_file, mmsg, cnt_info, NULL, err_code)<0) {
+ EM_SAFE_FREE(mmsg);
+ return false;
+ }
+
+ /* 3. free memor */
+ EM_DEBUG_LOG(">>>>>> 3. free memory");
+ if (mmsg && mmsg->header && mmsg->header->part_header && mmsg->header->part_header->parameter) {
+ EM_DEBUG_LOG("name[%s]", mmsg->header->part_header->parameter->name);
+ EM_DEBUG_LOG("value[%s]", mmsg->header->part_header->parameter->value);
+ EM_DEBUG_LOG("next : %p", mmsg->header->part_header->parameter->next);
+ }
+ em_core_mime_free_mime(mmsg);
+ EM_DEBUG_FUNC_END();
+ return true;
+}
+
+int em_core_mime_parse_header(void *stream, int is_file, struct _rfc822header **rfc822header, struct _m_mesg_header **header, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("stream[%p], is_file[%d], rfc822header[%p], header[%p], err_code[%p]", stream, is_file, rfc822header, header, err_code);
+
+ struct _m_mesg_header *tmp_header = NULL;
+ struct _rfc822header *tmp_rfc822header = NULL;
+ char buf[MIME_LINE_LEN] = {0, };
+ char *name = NULL;
+ char *value = NULL;
+ char *pTemp = NULL;
+ int is_longheader;
+
+ if (!em_core_check_thread_status()) {
+ if (err_code != NULL)
+ *err_code = EMF_ERROR_CANCELLED;
+ return false;
+ }
+
+
+ if ((is_file == 0 && !em_core_mime_get_line_from_sock(stream, buf, MIME_LINE_LEN, err_code)) ||
+ (is_file == 1 && !em_core_mime_get_line_from_file(stream, buf, MIME_LINE_LEN, err_code))) {
+ return false;
+ }
+
+ if (!(tmp_header = em_core_malloc(sizeof(struct _m_mesg_header)))) {
+ EM_DEBUG_EXCEPTION("malloc failed...");
+ if (err_code != NULL)
+ *err_code = EMF_ERROR_OUT_OF_MEMORY;
+ return false;
+ }
+
+ if (!em_core_check_thread_status()) {
+ if (err_code != NULL)
+ *err_code = EMF_ERROR_CANCELLED;
+ return false;
+ }
+
+ while (TRUE) {
+ EM_DEBUG_LOG("buf[%s]", buf);
+
+ if (!strncmp(buf, CRLF_STRING, 2))
+ break;
+
+ is_longheader = (buf[0] == ' ' || buf[0] == '\t') ? TRUE : FALSE;
+
+
+ if (!is_longheader) { /* Normal header (format : "Name : Value" or "Name : Value; Parameters" */
+ if (name) {
+ EM_SAFE_FREE(name);
+ }
+
+ /* EM_DEBUG_FUNC_BEGIN() */
+ if ((pTemp = strtok(buf, ":")) == NULL)
+ break;
+
+ name = EM_SAFE_STRDUP(pTemp);
+
+ value = strtok(NULL, CRLF_STRING);
+
+ /* --> 2007-05-16, cy */
+ if (value)
+ if (!*++value)
+ break;
+
+ em_core_mime_upper_str(name);
+ }
+ else { /* Long header */
+ value = strtok(buf, CRLF_STRING);
+ em_core_mime_trim_left(value);
+ }
+
+ /* --> 2007-05-08 by cy */
+ if (!name)
+ break;
+
+ EM_DEBUG_LOG("> name[%s]", name);
+ EM_DEBUG_LOG("> value[%s]", value);
+
+ /* MIME Part Heade */
+ if (memcmp(name, "CONTENT-", 8) == 0 && value) {
+ EM_DEBUG_LINE;
+ em_core_mime_set_part_header_value(&tmp_header->part_header, name, value, err_code);
+
+ if (tmp_header->part_header && tmp_header->part_header->parameter) {
+ EM_DEBUG_LOG("name[%s]", tmp_header->part_header->parameter->name);
+ EM_DEBUG_LOG("value[%s]", tmp_header->part_header->parameter->value);
+ EM_DEBUG_LOG("next : %p", tmp_header->part_header->parameter->next);
+ }
+
+ /* MIME Version Heade */
+ }
+ else if (memcmp(name, "MIME-VERSION", 12) == 0) {
+ /* EM_DEBUG_FUNC_BEGIN() */
+ /* ignored because we need only contents informatio */
+ /* tmp_header->version = EM_SAFE_STRDUP(value) */
+
+ /* RFC822 Heade */
+ }
+ else {
+ /* in socket stream case, ignored because we need only contents informatio */
+ if (is_file == 1)
+ em_core_mime_set_rfc822_header_value(&tmp_rfc822header, name, value, err_code);
+ }
+
+ if (!em_core_check_thread_status()) {
+ if (err_code != NULL)
+ *err_code = EMF_ERROR_CANCELLED;
+ return false;
+ }
+ if ((is_file == 0 && !em_core_mime_get_line_from_sock(stream, buf, MIME_LINE_LEN, err_code)) ||
+ (is_file == 1 && !em_core_mime_get_line_from_file(stream, buf, MIME_LINE_LEN, err_code))) {
+
+ if (tmp_rfc822header)
+ em_core_mime_free_rfc822_header(tmp_rfc822header);
+
+
+ if (tmp_header) {
+ em_core_mime_free_part_header(tmp_header->part_header);
+
+ EM_SAFE_FREE(tmp_header->version);
+ EM_SAFE_FREE(tmp_header);
+ }
+ return false;
+ }
+ }
+
+ *header = tmp_header;
+ *rfc822header = tmp_rfc822header;
+
+ EM_SAFE_FREE(name);
+ EM_DEBUG_FUNC_END();
+ return true;
+}
+
+int em_core_mime_parse_part_header(void *stream, int is_file, struct _m_part_header **header, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("stream[%p], is_file[%d], header[%p], err_code[%p]", stream, is_file, header, err_code);
+
+ struct _m_part_header *tmp_header = NULL;
+ char buf[MIME_LINE_LEN] = {0x00};
+ char *name = NULL;
+ char *value = NULL;
+ char *p = NULL;
+ int is_longheader = false;
+
+ if (!em_core_check_thread_status()) {
+ if (err_code != NULL)
+ *err_code = EMF_ERROR_CANCELLED;
+ return false;
+ }
+
+ if ((is_file == 0 && !em_core_mime_get_line_from_sock(stream, buf, MIME_LINE_LEN, err_code)) ||
+ (is_file == 1 && !em_core_mime_get_line_from_file(stream, buf, MIME_LINE_LEN, err_code)))
+ return false;
+
+ tmp_header = em_core_malloc(sizeof(struct _m_part_header));
+
+ if (!tmp_header) {
+ EM_DEBUG_EXCEPTION("em_core_malloc failed");
+ return false;
+ }
+
+ memset(tmp_header, 0, sizeof(struct _m_part_header));
+
+ while (true) {
+ if (!strncmp(buf, CRLF_STRING, strlen(CRLF_STRING))) break;
+
+ is_longheader = (buf[0] == ' ' || buf[0] == TAB);
+
+ if (!is_longheader) { /* Normal header (format : "Name : Value" or "Name : Value; Parameters" */
+ EM_SAFE_FREE(name);
+ p = strtok(buf , ":");
+
+ if (p) {
+ name = EM_SAFE_STRDUP(p);
+ value = strtok(NULL, CRLF_STRING);
+ em_core_mime_upper_str(name);
+ }
+ }
+ else /* Long header */
+ value = strtok(buf, CRLF_STRING);
+
+ if (!name)
+ break;
+
+ em_core_mime_set_part_header_value(&tmp_header, name, value, err_code);
+
+ if (!em_core_check_thread_status()) {
+ if (err_code != NULL)
+ *err_code = EMF_ERROR_CANCELLED;
+ return false;
+ }
+
+ if ((is_file == 0 && !em_core_mime_get_line_from_sock(stream, buf, MIME_LINE_LEN, err_code)) ||
+ (is_file == 1 && !em_core_mime_get_line_from_file(stream, buf, MIME_LINE_LEN, err_code))) {
+ EM_SAFE_FREE(name);
+ EM_SAFE_FREE(tmp_header);
+
+ return false;
+ }
+ }
+
+ *header = tmp_header;
+
+ EM_SAFE_FREE(name);
+ EM_DEBUG_FUNC_END();
+ return true;
+}
+
+
+int em_core_mime_parse_body(void *stream, int is_file, struct _m_mesg *mmsg, struct _m_content_info *cnt_info, void *callback, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("stream[%p], is_file[%d], mmsg[%p], cnt_info[%p], callback[%p], err_code[%p]", stream, is_file, mmsg, cnt_info, callback, err_code);
+
+ char *content_type = NULL, *content_encoding = NULL, *holder = NULL, *attachment_name, *t = NULL;
+ int type = 0, end_of_parsing = 0, size, local_err_code = EMF_ERROR_NONE;
+
+ if (!em_core_check_thread_status()) {
+ if (err_code != NULL)
+ *err_code = EMF_ERROR_CANCELLED;
+ return false;
+ }
+
+ if (mmsg->header)
+ content_type = em_core_mime_get_header_value(mmsg->header->part_header, CONTENT_TYPE, err_code);
+ if (!content_type)
+ content_type = "TEXT/PLAIN";
+
+ if (mmsg->header)
+ content_encoding = em_core_mime_get_header_value(mmsg->header->part_header, CONTENT_ENCODING, err_code);
+ if (!content_encoding)
+ content_encoding = "7BIT";
+
+ if (strstr(content_type, TEXT_STR)) type = TYPE_TEXT;
+ else if (strstr(content_type, IMAGE_STR)) type = TYPE_IMAGE;
+ else if (strstr(content_type, AUDIO_STR)) type = TYPE_AUDIO;
+ else if (strstr(content_type, VIDEO_STR)) type = TYPE_VIDEO;
+ else if (strstr(content_type, APPLICATION_STR)) type = TYPE_APPLICATION;
+ else if (strstr(content_type, MULTIPART_STR)) type = TYPE_MULTIPART;
+ else if (strstr(content_type, MESSAGE_STR)) type = TYPE_MESSAGE;
+ else type = TYPE_UNKNOWN;
+
+ switch (type) {
+ case TYPE_MULTIPART:
+ if (mmsg->header && !em_core_mime_get_header_value(mmsg->header->part_header, CONTENT_BOUNDARY, err_code)) {
+ EM_DEBUG_FUNC_END("false");
+ return false;
+ }
+
+ if (mmsg->header && !em_core_mime_parse_part(stream, is_file, mmsg->header->part_header, &mmsg->nested, cnt_info, &end_of_parsing, &local_err_code)) {
+ EM_DEBUG_FUNC_END("false");
+ return false;
+ }
+
+ /* after finishing body parsing, make stream empty to get next mail. (get line from sock or file until '.' is read */
+ if (end_of_parsing == true && local_err_code != EMF_ERROR_NO_MORE_DATA)
+ em_core_mime_flush_receiving_buffer(stream, is_file, NULL, NULL, NULL, err_code);
+
+ if (err_code)
+ *err_code = local_err_code;
+
+ break;
+
+ default:
+ attachment_name = NULL;
+
+ if (mmsg->header && em_core_mime_get_header_value(mmsg->header->part_header, CONTENT_DISPOSITION, err_code)) {
+ attachment_name = em_core_mime_get_header_value(mmsg->header->part_header, CONTENT_FILENAME, err_code);
+ /* if (!attachment_name) attachment_name = "unknown" */
+ if (attachment_name) EM_DEBUG_LOG(" attachment = [%s]", attachment_name);
+ }
+
+ if (cnt_info->grab_type & GRAB_TYPE_TEXT) {
+ /* EM_DEBUG_LINE */
+ /* get content data. content data is saved in file */
+ em_core_mime_get_content_data(stream, is_file, true, NULL, content_encoding, &end_of_parsing, SAVE_TYPE_FILE, &holder, &size, NULL, err_code);
+
+ EM_DEBUG_LOG("After em_core_mime_get_content_data");
+
+ if (mmsg->header && mmsg->header->part_header && strstr((t = em_core_mime_get_header_value(mmsg->header->part_header, CONTENT_TYPE, err_code)) ? t : "", "HTML"))
+ cnt_info->text.html = holder;
+ else if (mmsg->header) {
+ char *charset = em_core_mime_get_header_value(mmsg->header->part_header, CONTENT_CHARSET, err_code);
+
+ EM_DEBUG_LOG(">>>> charset [%s]", charset);
+
+ if (!charset || !strncmp(charset, "X-UNKNOWN", strlen("X-UNKNOWN")))
+ cnt_info->text.plain_charset = EM_SAFE_STRDUP("UTF-8");
+ else
+ cnt_info->text.plain_charset = EM_SAFE_STRDUP(charset);
+
+ EM_DEBUG_LOG(">>>> cnt_info->text.plain_charset [%s]", cnt_info->text.plain_charset);
+
+ cnt_info->text.plain = holder;
+
+ EM_DEBUG_LOG(">>>> cnt_info->text.plain [%s]", cnt_info->text.plain);
+ }
+ }
+
+ break;
+ }
+ EM_DEBUG_FUNC_END();
+ return true;
+}
+
+int em_core_mime_parse_part(void *stream, int is_file, struct _m_part_header *parent_header, struct _m_part *nested, struct _m_content_info *cnt_info, int *eop, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("stream[%p], is_file[%d], parent_header[%p], nested[%p], cnt_info[%p], eop[%p], err_code[%p]", stream, is_file, parent_header, nested, cnt_info, eop, err_code);
+
+ struct _m_body *tmp_body = NULL;
+ struct _m_part **p = NULL;
+ char buf[MIME_LINE_LEN] = {0x00, };
+ char boundary[BOUNDARY_LEN] = {0x00, };
+ char boundary_end[BOUNDARY_LEN] = {0x00, };
+ char *boundary_str = NULL;
+ char *content_type = NULL;
+ char *content_encoding = NULL;
+ char *holder = NULL;
+ char *attachment_name = NULL;
+ char *t = NULL;
+ int type = 0;
+ int end_of_parsing = 0;
+ int size = 0, local_err_code = EMF_ERROR_NONE;
+ int is_skip = false;
+ char *pTemp = NULL;
+
+ boundary_str = em_core_mime_get_header_value(parent_header, CONTENT_BOUNDARY, err_code);
+
+ SNPRINTF(boundary, BOUNDARY_LEN, "--%s%s", boundary_str, CRLF_STRING);
+ SNPRINTF(boundary_end, BOUNDARY_LEN, "--%s%s", boundary_str, "--\r\n");
+
+ nested->body = NULL;
+ nested->next = NULL;
+
+ /* goto the first found useful mime dat */
+ EM_DEBUG_LOG("Before first loop");
+ while (true) {
+ if (!em_core_check_thread_status()) {
+ if (err_code != NULL)
+ *err_code = EMF_ERROR_CANCELLED;
+ return false;
+ }
+ if ((is_file == 0 && !em_core_mime_get_line_from_sock(stream, buf, MIME_LINE_LEN, err_code)) ||
+ (is_file == 1 && !em_core_mime_get_line_from_file(stream, buf, MIME_LINE_LEN, err_code))) {
+ EM_DEBUG_EXCEPTION("em_core_mime_get_line_from_sock failed.");
+ if (eop)
+ *eop = true;
+ EM_DEBUG_FUNC_END("false");
+ return false;
+ }
+
+ if (!strcmp(buf, boundary))
+ break;
+ }
+
+ EM_DEBUG_LOG("Before second loop");
+ while (true) {
+ if (!(tmp_body = em_core_malloc(sizeof(struct _m_body)))) {
+ EM_DEBUG_EXCEPTION("em_core_malloc failed.");
+ if (nested->body)
+ em_core_mime_free_part_body(nested->body);
+ if (nested->next)
+ em_core_mime_free_part(nested->next);
+ EM_DEBUG_FUNC_END("false");
+ return false;
+ }
+
+ memset(tmp_body, 0, sizeof(struct _m_body));
+
+ /* parsing MIME Header */
+ if (!em_core_mime_parse_part_header(stream, is_file, &tmp_body->part_header, err_code)) {
+ EM_DEBUG_EXCEPTION("em_core_mime_parse_part_header failed.");
+ if (nested->body)
+ em_core_mime_free_part_body(nested->body);
+ if (nested->next)
+ em_core_mime_free_part(nested->next);
+
+ em_core_mime_free_part_body(tmp_body);
+ return false;
+ }
+
+ content_type = em_core_mime_get_header_value(tmp_body->part_header, CONTENT_TYPE, err_code);
+ if (!content_type)
+ content_type = "TEXT/PLAIN";
+
+ content_encoding = em_core_mime_get_header_value(tmp_body->part_header, CONTENT_ENCODING, err_code);
+ if (!content_encoding)
+ content_encoding = "7BIT";
+
+ if (strstr(content_type, TEXT_STR)) type = TYPE_TEXT;
+ else if (strstr(content_type, IMAGE_STR)) type = TYPE_IMAGE;
+ else if (strstr(content_type, AUDIO_STR)) type = TYPE_AUDIO;
+ else if (strstr(content_type, VIDEO_STR)) type = TYPE_VIDEO;
+ else if (strstr(content_type, APPLICATION_STR)) type = TYPE_APPLICATION;
+ else if (strstr(content_type, MULTIPART_STR)) type = TYPE_MULTIPART;
+ else if (strstr(content_type, MESSAGE_STR)) type = TYPE_MESSAGE;
+ else type = TYPE_UNKNOWN;
+
+ switch (type) {
+ case TYPE_MULTIPART:
+ EM_DEBUG_LOG("TYPE_MULTIPART");
+ if (!em_core_mime_get_header_value(tmp_body->part_header, CONTENT_BOUNDARY, err_code)) {
+ EM_DEBUG_EXCEPTION("em_core_mime_get_header_value failed.");
+ em_core_mime_free_part_body(tmp_body);
+ EM_DEBUG_FUNC_END("false");
+ return false;
+ }
+
+ em_core_mime_parse_part(stream, is_file, tmp_body->part_header, &tmp_body->nested, cnt_info, &end_of_parsing, &local_err_code);
+
+ if (!nested->body)
+ nested->body = tmp_body;
+ else {
+ p = &nested->next;
+
+ while (*p && (*p)->next)
+ *p = (*p)->next;
+
+ if (*p)
+ p = &(*p)->next;
+
+ if (!(*p = em_core_malloc(sizeof(struct _m_part)))) {
+ EM_DEBUG_EXCEPTION("em_core_malloc failed");
+ if (nested->body) em_core_mime_free_part_body(nested->body);
+ if (nested->next) em_core_mime_free_part(nested->next);
+ em_core_mime_free_part_body(tmp_body);
+ EM_DEBUG_FUNC_END("false");
+ return false;
+ }
+
+ (*p)->body = tmp_body;
+ (*p)->next = NULL;
+ }
+
+ if (err_code)
+ *err_code = local_err_code;
+
+ if (end_of_parsing && local_err_code != EMF_ERROR_NO_MORE_DATA) /* working with imap */
+ /* if (!end_of_parsing) */ /* working with pop */ {
+ EM_DEBUG_LOG("Enter flushing socket buffer.");
+ em_core_mime_flush_receiving_buffer(stream, is_file, boundary, boundary_end, &end_of_parsing, err_code);
+ }
+
+ break;
+
+ default:
+ EM_DEBUG_LOG("default");
+ attachment_name = NULL;
+
+ if (type == TYPE_MESSAGE)
+ is_skip = true;
+
+ if (is_skip == true) {
+ if (!em_core_mime_skip_content_data(stream, is_file, boundary_str, &end_of_parsing, &size, NULL, err_code))
+ EM_DEBUG_EXCEPTION("em_core_mime_skip_content_data failed...");
+
+ em_core_mime_free_part_body(tmp_body);
+ EM_DEBUG_LOG_MIME("break");
+ break;
+ }
+
+ /* first check inline content */
+ /* if the content id or content location exis */
+ attachment_name = em_core_mime_get_header_value(tmp_body->part_header, CONTENT_ID, err_code);
+ if (!attachment_name)
+ attachment_name = em_core_mime_get_header_value(tmp_body->part_header, CONTENT_LOCATION, err_code);
+
+ if (!attachment_name) {
+ /* check if the content is attachment */
+ /* if Content-Disposition Header exists, the content is attachment */
+ if (em_core_mime_get_header_value(tmp_body->part_header, CONTENT_DISPOSITION, err_code)) {
+ attachment_name = em_core_mime_get_header_value(tmp_body->part_header, CONTENT_FILENAME, err_code);
+ EM_DEBUG_LOG_MIME(">> attachment = [%s]", attachment_name ? attachment_name : NIL);
+ }
+ }
+
+ if (!em_core_check_thread_status()) {
+ if (err_code != NULL)
+ *err_code = EMF_ERROR_CANCELLED;
+ EM_DEBUG_EXCEPTION("EMF_ERROR_CANCELLED");
+ EM_DEBUG_FUNC_END("false");
+ return false;
+ }
+ /* get content and content informatio */
+ if (!attachment_name) { /* text */
+ /* get content by buffe */
+ EM_DEBUG_LOG_MIME("attachment_name is NULL. It's a text message");
+ em_core_mime_get_content_data(stream, is_file, true, boundary_str, content_encoding, &end_of_parsing, SAVE_TYPE_FILE, &holder, &size, NULL, err_code);
+
+ EM_DEBUG_LOG("After em_core_mime_get_content_data");
+
+ if (cnt_info->grab_type & GRAB_TYPE_TEXT) {
+ if (tmp_body->part_header && strstr((t = em_core_mime_get_header_value(tmp_body->part_header, CONTENT_TYPE, err_code)) ? t : "", "HTML")) {
+ cnt_info->text.html = holder;
+
+ EM_DEBUG_LOG(" cnt_info->text.html [%s]", cnt_info->text.html);
+ }
+ else {
+ char *charset = em_core_mime_get_header_value(tmp_body->part_header, CONTENT_CHARSET, err_code);
+ EM_DEBUG_LOG(" charset [%s]", charset);
+
+ if (!charset || !strncmp(charset, "X-UNKNOWN", strlen("X-UNKNOWN")))
+ cnt_info->text.plain_charset = EM_SAFE_STRDUP("UTF-8");
+ else
+ cnt_info->text.plain_charset = EM_SAFE_STRDUP(charset);
+
+ EM_DEBUG_LOG(" cnt_info->text.plain_charset [%s]", cnt_info->text.plain_charset);
+
+ cnt_info->text.plain = holder;
+
+ EM_DEBUG_LOG(" cnt_info->text.plain [%s]", cnt_info->text.plain);
+ }
+ }
+ else {
+ if (holder) {
+ free(holder);
+ holder = NULL;
+ }
+ }
+ }
+ else { /* attachmen */
+ EM_DEBUG_LOG_MIME("attachment_name is not NULL. It's a attachment");
+ struct attachment_info **file = &cnt_info->file;
+ int i = 1;
+
+ while (*file && (*file)->next) {
+ file = &(*file)->next;
+ i++;
+ }
+
+ if (*file) {
+ file = &(*file)->next;
+ i++;
+ }
+
+ *file = em_core_malloc(sizeof(struct attachment_info));
+ if (*file) {
+ if ((em_core_mime_get_header_value(tmp_body->part_header, CONTENT_ID, err_code)) ||
+ (em_core_mime_get_header_value(tmp_body->part_header, CONTENT_LOCATION, err_code))) { /* this is inline conten */
+ (*file)->type = 1;
+ }
+ else { /* this is attachment conten */
+ (*file)->type = 2;
+ }
+ EM_DEBUG_LOG_MIME("file->type : %d", (*file)->type);
+
+ (*file)->name = cpystr(attachment_name);
+
+ /* check if the current file is target file */
+ if (cnt_info->grab_type & GRAB_TYPE_ATTACHMENT || (*file)->type == 1) {
+ /* get content by fil */
+ EM_DEBUG_LOG_MIME("Trying to get content");
+ em_core_mime_get_content_data(stream, is_file, false, boundary_str, content_encoding, &end_of_parsing, SAVE_TYPE_FILE, &holder, &size, NULL, err_code);
+ (*file)->save = holder;
+ }
+ else {
+ /* only get content siz */
+ EM_DEBUG_LOG_MIME("Pass downloading");
+ em_core_mime_get_content_data(stream, is_file, false, boundary_str, content_encoding, &end_of_parsing, SAVE_TYPE_SIZE, NULL, &size, NULL, err_code);
+ (*file)->save = NULL;
+ }
+
+ if (err_code)
+ EM_DEBUG_LOG("end_of_parsing [%d], err_code [%d]", end_of_parsing, *err_code);
+
+ (*file)->size = size;
+
+ if (strstr(content_type, APPLICATION_STR)) {
+ pTemp = content_type + strlen(APPLICATION_STR);
+
+ if (strcasecmp(pTemp, MIME_SUBTYPE_DRM_OBJECT) == 0)
+ (*file)->drm = EMF_ATTACHMENT_DRM_OBJECT;
+ else if (strcasecmp(pTemp, MIME_SUBTYPE_DRM_RIGHTS) == 0)
+ (*file)->drm = EMF_ATTACHMENT_DRM_RIGHTS;
+ else if (strcasecmp(pTemp, MIME_SUBTYPE_DRM_DCF) == 0)
+ (*file)->drm = EMF_ATTACHMENT_DRM_DCF;
+ }
+ }
+ else {
+ EM_DEBUG_EXCEPTION("em_core_malloc failed...");
+ em_core_mime_free_part_body(tmp_body);
+ EM_DEBUG_FUNC_END("false");
+ return false;
+ }
+ }
+
+ if (!em_core_check_thread_status()) {
+ if (err_code != NULL)
+ *err_code = EMF_ERROR_CANCELLED;
+ EM_DEBUG_EXCEPTION("EMF_ERROR_CANCELLED");
+ EM_DEBUG_FUNC_END("false");
+ return false;
+ }
+
+ if (!nested->body)
+ nested->body = tmp_body;
+ else {
+ p = &nested->next;
+
+ while (*p && (*p)->next)
+ p = &(*p)->next;
+
+ if (*p)
+ p = &(*p)->next;
+
+ if (!(*p = em_core_malloc(sizeof(struct _m_part)))) {
+ EM_DEBUG_EXCEPTION("em_core_malloc failed");
+ if (nested->body) em_core_mime_free_part_body(nested->body);
+ if (nested->next) em_core_mime_free_part(nested->next);
+
+ em_core_mime_free_part_body(tmp_body);
+ EM_DEBUG_FUNC_END("false");
+ return false;
+ }
+
+ (*p)->body = tmp_body;
+ (*p)->next = NULL;
+ }
+
+ break;
+ }
+
+ /* End of parsin */
+ if (end_of_parsing)
+ break;
+ }
+
+ if (eop != NULL)
+ *eop = end_of_parsing;
+
+ EM_DEBUG_FUNC_END("end_of_parsing [%d]", end_of_parsing);
+ return true;
+}
+
+/* set RFC822 Heade */
+int em_core_mime_set_rfc822_header_value(struct _rfc822header **header, char *name, char *value, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("header[%p], name[%s], value[%s], err_code[%p]", header, name, value, err_code);
+
+ char **p = NULL;
+ char *t = NULL;
+
+ /* ? ? ? why return value is 1 */
+ if (!value || !*value) return true;
+
+ if (!*header) {
+ *header = em_core_malloc(sizeof(struct _rfc822header));
+ if (!*header) {
+ EM_DEBUG_EXCEPTION("em_core_malloc failed");
+ return false;
+ }
+ }
+
+ if (name) {
+ em_core_mime_upper_str(name);
+
+ if (strncmp(name, "RETURN-PATH", strlen("RETURN-PATH")) == 0)
+ p = &(*header)->return_path;/* Return-Rat */
+ else if (strncmp(name, "RECEIVED", strlen("RECEIVED")) == 0)
+ p = &(*header)->received; /* Receive */
+ else if (strncmp(name, "REPLY-TO", strlen("REPLY-TO")) == 0)
+ p = &(*header)->reply_to; /* Reply-T */
+ else if (strncmp(name, "DATE", strlen("DATE")) == 0)
+ p = &(*header)->date; /* Dat */
+ else if (strncmp(name, "FROM", strlen("FROM")) == 0)
+ p = &(*header)->from; /* Fro */
+ else if (strncmp(name, "SUBJECT", strlen("SUBJECT")) == 0)
+ p = &(*header)->subject; /* Subjec */
+ else if (strncmp(name, "SENDER", strlen("SENDER")) == 0)
+ p = &(*header)->sender; /* Sende */
+ else if (strncmp(name, "TO", strlen("TO")) == 0)
+ p = &(*header)->to; /* T */
+ else if (strncmp(name, "CC", strlen("CC")) == 0)
+ p = &(*header)->cc; /* C */
+ else if (strncmp(name, "BCC", strlen("BCC")) == 0)
+ p = &(*header)->bcc; /* Bc */
+ else if (strncmp(name, "X-PRIORITY", strlen("X-PRIORITY")) == 0)
+ p = &(*header)->priority; /* Prorit */
+ else if (strncmp(name, "X-MSMAIL-PRIORITY", strlen("X-MSMAIL-PRIORITY")) == 0)
+ p = &(*header)->ms_priority;/* Prorit */
+ else if (strncmp(name, "DISPOSITION-NOTIFICATION-TO", strlen("DISPOSITION-NOTIFICATION-TO")) == 0)
+ p = &(*header)->dsp_noti_to;/* Disposition-Notification-T */
+ else {
+ return false;
+ }
+ }
+
+ if (p) {
+ if (!*p)
+ *p = EM_SAFE_STRDUP(value);
+ else { /* Long Heade */
+ if (!(t = realloc(*p, strlen(*p) + strlen(value)+1)))
+ return false;
+
+ strncat(t, value, strlen(value));
+ *p = t;
+ }
+ }
+
+ return true;
+}
+
+/* set MIME Part Heade */
+int em_core_mime_set_part_header_value(struct _m_part_header **header, char *name, char *value, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("header[%p], name[%s], value[%s], err_code[%p]", header, name, value, err_code);
+
+ if (!name || !value) {
+ EM_DEBUG_EXCEPTION("Invalid parameter");
+ if (err_code != NULL)
+ *err_code = EMF_ERROR_INVALID_PARAM;
+ return false;
+ }
+
+ struct _parameter *p = NULL;
+ char *p_val = NULL;
+
+ if (!*header) {
+ *header = em_core_malloc(sizeof(struct _m_part_header));
+ if (!(*header)) {
+ EM_DEBUG_EXCEPTION("em_core_malloc failed...");
+ return false;
+ }
+ }
+
+ em_core_mime_upper_str(name);
+ em_core_mime_trim_left(value);
+ em_core_mime_trim_right(value);
+
+ if (!em_core_check_thread_status()) {
+ if (err_code != NULL)
+ *err_code = EMF_ERROR_CANCELLED;
+ return false;
+ }
+
+ if (name) {
+ if (strncmp(name, "CONTENT-TYPE", strlen("CONTENT-TYPE")) == 0) {
+ p_val = strtok(value, ";");
+
+ if (p_val) {
+ if (!(*header)->type) { /* Content-Type */
+ em_core_mime_upper_str(p_val);
+ (*header)->type = EM_SAFE_STRDUP(p_val);
+ }
+ else { /* Content-Type Parameter (format : "name =value" */
+ if (em_core_mime_get_param_from_str(p_val, &p, err_code))
+ em_core_mime_add_param_to_list(&((*header)->parameter), p, err_code);
+ }
+
+ /* repeatedly get paramete */
+ while ((p_val = strtok(NULL, ";"))) {
+ if (em_core_mime_get_param_from_str(p_val, &p, err_code))
+ em_core_mime_add_param_to_list(&((*header)->parameter), p, err_code);
+ }
+ }
+ }
+ else if (strncmp(name, "CONTENT-TRANSFER-ENCODING", strlen("CONTENT-TRANSFER-ENCODING")) == 0) {
+ em_core_mime_upper_str(value);
+ (*header)->encoding = EM_SAFE_STRDUP(value);
+ }
+ else if (strncmp(name, "CONTENT-DESCRPTION", strlen("CONTENT-DESCRPTION")) == 0) {
+ em_core_mime_upper_str(value);
+ (*header)->desc = EM_SAFE_STRDUP(value);
+ }
+ else if (strncmp(name, "CONTENT-DISPOSITION", strlen("CONTENT-DISPOSITION")) == 0) {
+ p_val = strtok(value, ";");
+
+ if (p_val) {
+ if (!(*header)->disp_type) { /* Content-Dispositio */
+ em_core_mime_upper_str(p_val);
+ (*header)->disp_type = EM_SAFE_STRDUP(p_val);
+ }
+ else { /* Content-Disposition parameter (format : "name =value" */
+ if (em_core_mime_get_param_from_str(p_val, &p, err_code))
+ em_core_mime_add_param_to_list(&((*header)->disp_parameter), p, err_code);
+ }
+
+ /* repeatedly get paramete */
+ while ((p_val = strtok(NULL, ";"))) {
+ if (em_core_mime_get_param_from_str(p_val, &p, err_code))
+ em_core_mime_add_param_to_list(&((*header)->disp_parameter), p, err_code);
+ }
+ }
+ }
+ else if (strncmp(name, "CONTENT-ID", strlen("CONTENT-ID")) == 0) {
+ size_t len = 0;
+ len = strlen(value);
+ /* em_core_mime_upper_str(value) */
+
+ if ((len) && (value[0] == '<')) {
+ ++value;
+ --len;
+ }
+
+ if ((len > 1) && (value[len-1] == '>'))
+ value[len-1] = '\0';
+
+ (*header)->content_id = EM_SAFE_STRDUP(value);
+ }
+ else if (strncmp(name, "CONTENT-LOCATION", strlen("CONTENT-LOCATION")) == 0)
+ (*header)->content_location = EM_SAFE_STRDUP(value);
+ }
+ EM_DEBUG_FUNC_END();
+ return true;
+}
+
+/* get header parameter from strin */
+int em_core_mime_get_param_from_str(char *str, struct _parameter **param, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("str[%s], param[%p], err_code[%p]", str, param, err_code);
+
+ char *p_name, *p_val, *p;
+
+ *param = NULL;
+
+ /* Parameter Chec */
+ if (!(p = strchr(str, '='))) return false;
+
+ *p = '\0';
+
+ p_name = str;
+ p_val = p+1;
+
+ em_core_mime_trim_left(p_name);
+ em_core_mime_trim_right(p_name);
+
+ if (!*p_name) return false;
+
+ em_core_mime_trim_left(p_val);
+ em_core_mime_trim_right(p_val);
+
+ if (!*p_val) return false;
+
+ if (!(*param = em_core_malloc(sizeof(struct _parameter)))) return false;
+
+ (*param)->next = NULL;
+
+ /* Name se */
+ /* check string lengt */
+ if (strlen(p_name) > 0) {
+ em_core_mime_upper_str(p_name);
+ (*param)->name = EM_SAFE_STRDUP(p_name);
+ }
+
+ if (strlen(p_val) > 0) {
+ if ((p = strchr(p_val, '\"'))) {
+ p_val = p + 1;
+ if (!*p_val) return false;
+ }
+ if ((p = strchr(p_val, '\"')))
+ *p = '\0';
+
+ if (strncmp(p_name, "BOUNDARY", strlen("BOUNDARY")) != 0 && !strstr(p_name, "NAME"))
+ em_core_mime_upper_str(p_val);
+
+ /* = ? ENCODING_TYPE ? B(Q) ? ENCODED_STRING ? */
+ int err = EMF_ERROR_NONE;
+ char *utf8_text = NULL;
+
+ if (!(utf8_text = em_core_decode_rfc2047_text(p_val, &err)))
+ EM_DEBUG_EXCEPTION("em_core_decode_rfc2047_text failed [%d]", err);
+ (*param)->value = utf8_text;
+ }
+ EM_DEBUG_FUNC_END();
+ return true;
+}
+
+/* add a parameter to parameter lis */
+int em_core_mime_add_param_to_list(struct _parameter **param_list, struct _parameter *param, int *err_code)
+{
+ struct _parameter **t = param_list;
+
+ while (*t && (*t)->next)
+ *t = (*t)->next;
+
+ if (*t)
+ (*t)->next = param;
+ else
+ *t = param;
+
+ return true;
+}
+
+/* get header value from MIME Part Heade */
+char *em_core_mime_get_header_value(struct _m_part_header *header, int type, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("header[%p], type[%d], err_code[%p]", header, type, err_code);
+
+ struct _parameter *p = NULL;
+ char *name = NULL;
+
+ if (!header) {
+ EM_DEBUG_EXCEPTION("header[%p], type[%d]", header, type);
+
+ if (err_code != NULL)
+ *err_code = EMF_ERROR_INVALID_PARAM;
+ return NULL;
+ }
+
+ switch (type) {
+ case CONTENT_TYPE:
+ return header->type;
+
+ case CONTENT_SUBTYPE:
+ return header->subtype;
+
+ case CONTENT_ENCODING:
+ return header->encoding;
+
+ case CONTENT_CHARSET:
+ name = "CHARSET";
+ p = header->parameter;
+ break;
+
+ case CONTENT_DISPOSITION:
+ return header->disp_type;
+
+ case CONTENT_NAME:
+ name = "NAME";
+ p = header->parameter;
+ break;
+
+ case CONTENT_FILENAME:
+ name = "FILENAME";
+ p = header->disp_parameter;
+ break;
+
+ case CONTENT_BOUNDARY:
+ name = "BOUNDARY";
+ p = header->parameter;
+ break;
+
+ case CONTENT_REPORT_TYPE:
+ name = "REPORT-TYPE";
+ p = header->parameter;
+ break;
+
+ case CONTENT_ID:
+ return header->content_id;
+
+ case CONTENT_LOCATION:
+ return header->content_location;
+
+ default:
+ return NULL;
+ }
+
+ for (; p; p = p->next) {
+ if (strcmp(p->name, name) == 0)
+ break;
+ }
+
+ if (!p)
+ return NULL;
+ EM_DEBUG_FUNC_END();
+ return p->value;
+}
+
+/*
+ * decode body text (quoted-printable, base64)
+ * enc_type : encoding type (base64/quotedprintable)
+ */
+EXPORT_API int em_core_decode_body_text(char *enc_buf, int enc_len, int enc_type, int *dec_len, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("enc_buf[%p], enc_len[%d], enc_type[%d], dec_len[%p]", enc_buf, enc_len, enc_type, dec_len);
+ unsigned char *content = NULL;
+
+ /* too many called */
+ *dec_len = enc_len;
+
+ switch (enc_type) {
+ case ENCQUOTEDPRINTABLE:
+ EM_DEBUG_LOG("ENCQUOTEDPRINTABLE");
+ content = rfc822_qprint((unsigned char *)enc_buf, (unsigned long)enc_len, (unsigned long *)dec_len);
+ break;
+
+ case ENCBASE64:
+ EM_DEBUG_LOG("ENCBASE64");
+ content = rfc822_base64((unsigned char *)enc_buf, (unsigned long)enc_len, (unsigned long *)dec_len);
+ break;
+
+ case ENC7BIT:
+ case ENC8BIT:
+ case ENCBINARY:
+ case ENCOTHER:
+ default:
+ break;
+ }
+
+ if (content) {
+ if (enc_len < *dec_len) {
+ EM_DEBUG_EXCEPTION("Decoded length is too big to store it");
+ return -1;
+ }
+ memcpy(enc_buf, content, *dec_len);
+ enc_buf[*dec_len] = '\0';
+ EM_SAFE_FREE(content);
+ }
+ EM_DEBUG_FUNC_END();
+ return 0;
+}
+
+/* 1. if boundary is NULL, contnent has not multipart */
+/* 2. if boundary isn't NULL, content is from current line to the next found boundary */
+/* if next found boundary is the other part boundary ("--boundary"), return and set end_of_parsing to 1 */
+/* if next found boundary is the multipart ending boundary ("--boundary--"), return and set end_of_parsing to 0 */
+/* mode - SAVE_TYPE_SIZE : no saving (only hold content size */
+/* SAVE_TYPE_BUFFER : content is saved to buffer (holder is buffer */
+/* SAVE_TYPE_FILE : content is saved to temporary file (holder is file name */
+int em_core_mime_get_content_data(void *stream, int is_file, int is_text, char *boundary_str, char *content_encoding, int *end_of_parsing, int mode, char **holder, int *size, void *callback, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("stream[%p], is_file[%d], boundary_str[%s], content_encoding[%s], end_of_parsing[%p], mode[%d], holder[%p], size[%p], callback[%p], err_code[%p]", stream, is_file, boundary_str, content_encoding, end_of_parsing, mode, holder, size, callback, err_code);
+
+ char buf[MIME_LINE_LEN] = {0x00, };
+ char boundary[BOUNDARY_LEN] = {0x00, };
+ char boundary_end[BOUNDARY_LEN] = {0x00, };
+ char *result_buffer = NULL;
+ int sz = 0, fd = 0, result_buffer_size = 0;;
+ int encoding = ENC7BIT;
+ int dec_len = 0;
+ int error = EMF_ERROR_NONE, ret = false;
+ char *pTemp = NULL;
+
+ if ((mode == SAVE_TYPE_FILE || mode == SAVE_TYPE_BUFFER) && !holder)
+ return false;
+
+ if (holder)
+ *holder = NULL;
+
+ if (size)
+ *size = 0;
+
+ EM_DEBUG_LOG("get content");
+
+ if (content_encoding) {
+ switch (content_encoding[0]) {
+ case 'Q':
+ encoding = ENCQUOTEDPRINTABLE;
+ break; /* qutoed-printabl */
+ case 'B':
+ if (content_encoding[1] == 'A') {
+ encoding = ENCBASE64;
+ break; /* base6 */
+ }
+ if (content_encoding[1] == 'I') {
+ encoding = ENCBINARY;
+ break; /* binar */
+ }
+ case '7':
+ encoding = ENC7BIT;
+ break; /* 7bi */
+ case '8':
+ encoding = ENC8BIT;
+ break; /* 8bi */
+ default:
+ encoding = ENCOTHER;
+ break; /* unknow */
+ }
+ }
+
+ /* saving type is file */
+ if (mode == SAVE_TYPE_FILE) {
+ *holder = em_core_mime_get_save_file_name(err_code);
+
+ EM_DEBUG_LOG("holder[%s]", *holder);
+
+ fd = open(*holder, O_WRONLY|O_CREAT, 0644);
+ if (fd <= 0) {
+ EM_DEBUG_EXCEPTION("holder open failed : holder is a filename that will be saved.");
+ goto FINISH_OFF;
+ }
+ }
+
+ if (boundary_str) {
+ /* if there boundary, this content is from current line to ending boundary */
+ memset(boundary, 0x00, BOUNDARY_LEN);
+ memset(boundary_end, 0x00, BOUNDARY_LEN);
+
+ SNPRINTF(boundary, BOUNDARY_LEN, "--%s%s", boundary_str, CRLF_STRING);
+ SNPRINTF(boundary_end, BOUNDARY_LEN, "--%s%s", boundary_str, "--\r\n");
+ }
+
+ while (TRUE) {
+ if (!em_core_check_thread_status()) {
+ EM_DEBUG_EXCEPTION("EMF_ERROR_CANCELLED");
+ error = EMF_ERROR_CANCELLED;
+ goto FINISH_OFF;
+ }
+
+ if ((is_file == 0 && !em_core_mime_get_line_from_sock(stream, buf, MIME_LINE_LEN, &error)) ||
+ (is_file == 1 && !em_core_mime_get_line_from_file(stream, buf, MIME_LINE_LEN, &error))) {
+ if (error == EMF_ERROR_NO_MORE_DATA)
+ EM_DEBUG_EXCEPTION("End of data");
+ else
+ EM_DEBUG_EXCEPTION("em_core_mime_get_line_from_sock failed");
+ *end_of_parsing = 1;
+
+ ret = true;
+ goto FINISH_OFF;
+ }
+
+ if (boundary_str) {
+ if (!strcmp(buf, boundary)) { /* the other part started. the parsing of other part will be started */
+ *end_of_parsing = 0;
+ ret = true;
+ goto FINISH_OFF;
+ }
+ else if (!strcmp(buf, boundary_end)) { /* if ending boundary, the parsing of other multipart will be started */
+ *end_of_parsing = 1;
+ ret = true;
+ goto FINISH_OFF;
+ }
+ }
+
+ /* parsing string started by '.' in POP3 */
+ if ((buf[0] == '.' && buf[1] == '.') && (encoding == ENCQUOTEDPRINTABLE || encoding == ENC7BIT)) {
+ strncpy(buf, buf+1, MIME_LINE_LEN-1);
+ buf[strlen(buf)] = NULL_CHAR;
+ }
+
+ if (encoding == ENCBASE64) {
+ if (strlen(buf) >= 2)
+ buf[strlen(buf)-2] = NULL_CHAR;
+ }
+ else if (encoding == ENCQUOTEDPRINTABLE) {
+/* if (strcmp(buf, CRLF_STRING) == 0 */
+/* continue */
+ }
+
+ dec_len = strlen(buf);
+
+ if (mode > SAVE_TYPE_SIZE) { /* decode conten */
+ em_core_decode_body_text(buf, dec_len, encoding, &dec_len, err_code);
+
+ if (is_text) {
+ result_buffer = em_core_replace_string(buf, "cid:", "");
+ if (result_buffer)
+ result_buffer_size = strlen(result_buffer);
+ }
+
+ if (result_buffer == NULL) {
+ result_buffer = buf;
+ result_buffer_size = dec_len;
+ }
+
+ if (result_buffer) {
+ if (mode == SAVE_TYPE_BUFFER) { /* save content to buffe */
+ pTemp = realloc(*holder, sz + result_buffer_size + 2);
+ if (!pTemp) {
+ EM_DEBUG_EXCEPTION("realloc failed...");
+ error = EMF_ERROR_OUT_OF_MEMORY;
+
+ EM_SAFE_FREE(*holder);
+ EM_SAFE_FREE(result_buffer);
+ goto FINISH_OFF;
+ }
+ else
+ *holder = pTemp;
+
+ memcpy(*holder + sz, result_buffer, result_buffer_size);
+ (*holder)[sz + strlen(result_buffer) + 1] = NULL_CHAR;
+ }
+ else if (mode == SAVE_TYPE_FILE) { /* save content to fil */
+ if (write(fd, result_buffer, result_buffer_size) != result_buffer_size) {
+ if (is_text && (result_buffer != buf))
+ EM_SAFE_FREE(result_buffer);
+ EM_DEBUG_EXCEPTION("write failed");
+ error = EMF_ERROR_SYSTEM_FAILURE;
+ goto FINISH_OFF;
+ }
+ }
+ if (is_text && (result_buffer != buf))
+ EM_SAFE_FREE(result_buffer);
+ result_buffer = NULL;
+ }
+ }
+ sz += dec_len;
+ }
+
+ ret = true;
+FINISH_OFF:
+ if (err_code != NULL)
+ *err_code = error;
+
+ if (fd > 0)
+ close(fd);
+
+ if (ret) {
+ if (size)
+ *size = sz;
+ }
+
+ EM_DEBUG_FUNC_END("ret [%d], sz [%d]", ret, sz);
+ return ret;
+}
+
+int em_core_mime_skip_content_data(void *stream,
+ int is_file,
+ char *boundary_str,
+ int *end_of_parsing,
+ int *size,
+ void *callback,
+ int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("stream[%p], is_file[%d], boundary_str[%s], end_of_parsing[%p], size[%p], callback[%p], err_code[%p]", stream, is_file, boundary_str, end_of_parsing, size, callback, err_code);
+
+ char buf[MIME_LINE_LEN] = {0x00}, boundary[BOUNDARY_LEN], boundary_end[BOUNDARY_LEN];
+ int sz = 0;
+
+ if (size)
+ *size = 0;
+
+ EM_DEBUG_LOG(">>> skip content <<<<<<<<<<<<<");
+
+ if (!boundary_str) { /* if no boundary, this content is from current line to end of all multipart */
+ while (TRUE) {
+
+ if (!em_core_check_thread_status()) {
+ if (err_code != NULL)
+ *err_code = EMF_ERROR_CANCELLED;
+ return false;
+ }
+ if ((is_file == 0 && !em_core_mime_get_line_from_sock(stream, buf, MIME_LINE_LEN, err_code)) ||
+ (is_file == 1 && !em_core_mime_get_line_from_file(stream, buf, MIME_LINE_LEN, err_code))) {
+ *end_of_parsing = 1;
+ if (size)
+ *size = sz;
+ return false;
+ }
+ sz += strlen(buf);
+ }
+ }
+ else { /* if there boundary, this content is from current line to ending boundary */
+ memset(boundary, 0x00, BOUNDARY_LEN);
+ memset(boundary_end, 0x00, BOUNDARY_LEN);
+
+ SNPRINTF(boundary, BOUNDARY_LEN, "--%s%s", boundary_str, CRLF_STRING);
+ SNPRINTF(boundary_end, BOUNDARY_LEN, "--%s%s", boundary_str, "--\r\n");
+
+ while (TRUE) {
+
+ if (!em_core_check_thread_status()) {
+ if (err_code != NULL)
+ *err_code = EMF_ERROR_CANCELLED;
+ return false;
+ }
+ if ((is_file == 0 && !em_core_mime_get_line_from_sock(stream, buf, MIME_LINE_LEN, err_code)) ||
+ (is_file == 1 && !em_core_mime_get_line_from_file(stream, buf, MIME_LINE_LEN, err_code))) {
+ /* end of fil */
+ *end_of_parsing = 1;
+ if (size)
+ *size = sz;
+ return true;
+ }
+
+ if (!strcmp(buf, boundary)) { /* the other part started. the parsing of other part will be started */
+ *end_of_parsing = 0;
+ if (size)
+ *size = sz;
+ return true;
+ }
+ else if (!strcmp(buf, boundary_end)) { /* if ending boundary, the parsing of other multipart will be started */
+ *end_of_parsing = 1;
+ if (size)
+ *size = sz;
+ return true;
+ }
+
+ sz += strlen(buf);
+ }
+ }
+
+ if (size)
+ *size = sz;
+ EM_DEBUG_FUNC_END();
+ return true;
+}
+
+/* get temporary file nam */
+char *em_core_mime_get_save_file_name(int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ char tempname[512];
+ struct timeval tv;
+
+ gettimeofday(&tv, NULL);
+ srand(tv.tv_usec);
+
+ memset(tempname, 0x00, sizeof(tempname));
+
+ SNPRINTF(tempname, sizeof(tempname), "%s%s%s%s%d", MAILHOME, DIR_SEPERATOR, MAILTEMP, DIR_SEPERATOR, rand());
+ EM_DEBUG_FUNC_END();
+ return EM_SAFE_STRDUP(tempname);
+}
+
+/* get a line from file pointer */
+char *em_core_mime_get_line_from_file(void *stream, char *buf, int size, int *err_code)
+{
+ if (!fgets(buf, size, (FILE *)stream)) {
+ if (feof((FILE *)stream))
+ return NULL;
+ else
+ return NULL;
+ }
+ return buf;
+}
+
+/* get a line from POP3 mail stream */
+/* em_core_mail_cmd_read_mail_pop3 must be called before this function */
+char *em_core_mime_get_line_from_sock(void *stream, char *buf, int size, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("stream[%p], buf[%p]", stream, buf);
+ POP3LOCAL *p_pop3local = NULL;
+
+ if (!stream || !buf) {
+ EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
+ if (err_code != NULL)
+ *err_code = EMF_ERROR_INVALID_PARAM;
+ return NULL;
+ }
+
+ memset(buf, 0x00, size);
+
+ p_pop3local = (POP3LOCAL *)(((MAILSTREAM *)stream)->local);
+ if (!p_pop3local) {
+ EM_DEBUG_EXCEPTION("stream->local[%p]", p_pop3local);
+ if (err_code != NULL)
+ *err_code = EMF_ERROR_INVALID_PARAM;
+ return NULL;
+ }
+
+ if (!pop3_reply((MAILSTREAM *)stream)) { /* if TRUE, check respons */
+ EM_DEBUG_LOG("p_pop3local->response 1[%s]", p_pop3local->response);
+ if (p_pop3local->response) {
+ if (*p_pop3local->response == '.' && strlen(p_pop3local->response) == 1) {
+ free(p_pop3local->response);
+ p_pop3local->response = NULL;
+ if (err_code != NULL)
+ *err_code = EMF_ERROR_NO_MORE_DATA;
+ EM_DEBUG_FUNC_END("end of response");
+ return NULL;
+ }
+ EM_DEBUG_LOG("Not end of response");
+ strncpy(buf, p_pop3local->response, size-1);
+ strncat(buf, CRLF_STRING, size-(strlen(buf) + 1));
+
+ free(p_pop3local->response);
+ p_pop3local->response = NULL;
+
+ goto FINISH_OFF;
+ }
+ }
+
+ EM_DEBUG_LOG("p_pop3local->response 2[%s]", p_pop3local->response);
+ if (p_pop3local->response)
+ {
+ /* if response isn't NULL, check whether this response start with '+' */
+ /* if the first character is '+', return error because this response is normal data */
+ strncpy(buf, p_pop3local->response, size-1);
+ strncat(buf, CRLF_STRING, size-(strlen(buf)+1));
+ free(p_pop3local->response); p_pop3local->response = NULL;
+ goto FINISH_OFF;
+ }
+ else {
+ EM_DEBUG_EXCEPTION("p_pop3local->response is null. network error... ");
+ if (err_code != NULL)
+ *err_code = EMF_ERROR_INVALID_RESPONSE;
+ EM_DEBUG_FUNC_END();
+ return NULL;
+ }
+
+FINISH_OFF:
+ if (buf) {
+ int received_percentage, last_notified_percentage;
+ _pop3_received_body_size += strlen(buf);
+
+ last_notified_percentage = (double)_pop3_last_notified_body_size / (double)_pop3_total_body_size *100.0;
+ received_percentage = (double)_pop3_received_body_size / (double)_pop3_total_body_size *100.0;
+
+ EM_DEBUG_LOG("_pop3_received_body_size = %d, _pop3_total_body_size = %d", _pop3_received_body_size, _pop3_total_body_size);
+ EM_DEBUG_LOG("received_percentage = %d, last_notified_percentage = %d", received_percentage, last_notified_percentage);
+
+ if (received_percentage > last_notified_percentage + 5) {
+ if (!em_storage_notify_network_event(NOTI_DOWNLOAD_BODY_START, _pop3_receiving_mail_id, "dummy-file", _pop3_total_body_size, _pop3_received_body_size))
+ EM_DEBUG_EXCEPTION(" em_storage_notify_network_event [NOTI_DOWNLOAD_BODY_START] Failed >>>> ");
+ else
+ EM_DEBUG_LOG("NOTI_DOWNLOAD_BODY_START notified (%d / %d)", _pop3_received_body_size, _pop3_total_body_size);
+ _pop3_last_notified_body_size = _pop3_received_body_size;
+ }
+ }
+ EM_DEBUG_FUNC_END();
+ return buf;
+}
+
+void em_core_mime_free_param(struct _parameter *param)
+{
+ struct _parameter *t, *p = param;
+ EM_DEBUG_FUNC_BEGIN();
+ while (p) {
+ t = p->next;
+ EM_SAFE_FREE(p->name);
+ EM_SAFE_FREE(p->value);
+ free(p);p = NULL;
+ p = t;
+ }
+ EM_DEBUG_FUNC_END();
+}
+
+void em_core_mime_free_part_header(struct _m_part_header *header)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ if (!header) return ;
+ EM_SAFE_FREE(header->type);
+ if (header->parameter) em_core_mime_free_param(header->parameter);
+ EM_SAFE_FREE(header->subtype);
+ EM_SAFE_FREE(header->encoding);
+ EM_SAFE_FREE(header->desc);
+ EM_SAFE_FREE(header->disp_type);
+ if (header->disp_parameter) em_core_mime_free_param(header->disp_parameter);
+ free(header); header = NULL;
+ EM_DEBUG_FUNC_END();
+}
+
+void em_core_mime_free_message_header(struct _m_mesg_header *header)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ if (!header) return ;
+ EM_SAFE_FREE(header->version);
+ if (header->part_header) em_core_mime_free_part_header(header->part_header);
+ free(header); header = NULL;
+ EM_DEBUG_FUNC_END();
+}
+
+void em_core_mime_free_rfc822_header(struct _rfc822header *header)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ if (!header) return ;
+ EM_SAFE_FREE(header->return_path);
+ EM_SAFE_FREE(header->received);
+ EM_SAFE_FREE(header->reply_to);
+ EM_SAFE_FREE(header->date);
+ EM_SAFE_FREE(header->from);
+ EM_SAFE_FREE(header->subject);
+ EM_SAFE_FREE(header->sender);
+ EM_SAFE_FREE(header->to);
+ EM_SAFE_FREE(header->cc);
+ EM_SAFE_FREE(header->bcc);
+ free(header); header = NULL;
+ EM_DEBUG_FUNC_END();
+}
+
+void em_core_mime_free_part_body(struct _m_body *body)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ if (!body) return ;
+ if (body->part_header) em_core_mime_free_part_header(body->part_header);
+ EM_SAFE_FREE(body->text);
+ if (body->nested.body) em_core_mime_free_part_body(body->nested.body);
+ if (body->nested.next) em_core_mime_free_part(body->nested.next);
+ free(body); body = NULL;
+ EM_DEBUG_FUNC_END();
+}
+
+void em_core_mime_free_part(struct _m_part *part)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ if (!part) return ;
+ if (part->body) em_core_mime_free_part_body(part->body);
+ if (part->next) em_core_mime_free_part(part->next);
+ free(part);part = NULL;
+ EM_DEBUG_FUNC_END();
+}
+
+void em_core_mime_free_mime(struct _m_mesg *mmsg)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ if (!mmsg) return ;
+ if (mmsg->header) em_core_mime_free_message_header(mmsg->header);
+ if (mmsg->rfc822header) em_core_mime_free_rfc822_header(mmsg->rfc822header);
+ if (mmsg->nested.body) em_core_mime_free_part_body(mmsg->nested.body);
+ if (mmsg->nested.next) em_core_mime_free_part(mmsg->nested.next);
+ EM_SAFE_FREE(mmsg->text);
+ free(mmsg); mmsg = NULL;
+ EM_DEBUG_FUNC_END();
+}
+
+void em_core_mime_free_content_info(struct _m_content_info *cnt_info)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ struct attachment_info *p;
+
+ if (!cnt_info) return ;
+ EM_SAFE_FREE(cnt_info->text.plain);
+ EM_SAFE_FREE(cnt_info->text.plain_charset);
+ EM_SAFE_FREE(cnt_info->text.html);
+ while (cnt_info->file) {
+ p = cnt_info->file->next;
+ EM_SAFE_FREE(cnt_info->file->name);
+ EM_SAFE_FREE(cnt_info->file->save);
+ free(cnt_info->file); cnt_info->file = NULL;
+ cnt_info->file = p;
+ }
+ free(cnt_info);cnt_info = NULL;
+ EM_DEBUG_FUNC_END();
+}
+
+/* remove left space, tab, CR, L */
+char *em_core_mime_trim_left(char *str)
+{
+ char *p, *temp_buffer = NULL;
+
+ /* EM_DEBUG_FUNC_BEGIN() */
+ if (!str) return NULL;
+
+ p = str;
+ while (*p && (*p == ' ' || *p == '\t' || *p == LF || *p == CR)) p++;
+
+ if (!*p) return NULL;
+
+ temp_buffer = EM_SAFE_STRDUP(p);
+
+ strncpy(str, temp_buffer, strlen(str));
+ str[strlen(temp_buffer)] = NULL_CHAR;
+
+ EM_SAFE_FREE(temp_buffer);
+
+ return str;
+}
+
+/* remove right space, tab, CR, L */
+char *em_core_mime_trim_right(char *str)
+{
+ char *p;
+
+ /* EM_DEBUG_FUNC_BEGIN() */
+ if (!str) return NULL;
+
+ p = str+strlen(str)-1;
+ while (((int)p >= (int)str) && (*p == ' ' || *p == '\t' || *p == LF || *p == CR))
+ *p --= '\0';
+
+ if ((int) p < (int)str)
+ return NULL;
+
+ return str;
+}
+
+char *em_core_mime_upper_str(char *str)
+{
+ char *p = str;
+ while (*p) {
+ *p = toupper(*p);
+ p++;
+ }
+ return str;
+}
+
+
+/* get body-part in nested part */
+static PARTLIST *em_core_get_allnested_part_full(MAILSTREAM *stream, int msg_uid, BODY *body, struct _m_content_info *cnt_info, int *err_code, PARTLIST *section_list)
+{
+ EM_DEBUG_FUNC_BEGIN("stream[%p], msg_uid[%d], body[%p], cnt_info[%p], err_code[%p]", stream, msg_uid, body, cnt_info, err_code);
+
+ PART *part_child = body->nested.part;
+
+ while (part_child) {
+ section_list = em_core_get_body_full(stream, msg_uid, &part_child->body, cnt_info, err_code, section_list);
+ part_child = part_child->next;
+ }
+
+ return section_list;
+}
+
+/* get body-part in alternative multiple part */
+static PARTLIST *em_core_get_alternative_multi_part_full(MAILSTREAM *stream, int msg_uid, BODY *body, struct _m_content_info *cnt_info, int *err_code, PARTLIST *section_list)
+{
+ EM_DEBUG_FUNC_BEGIN("stream[%p], msg_uid[%d], body[%p], cnt_info[%p], err_code[%p]", stream, msg_uid, body, cnt_info, err_code);
+
+ PART *part_child = body->nested.part;
+
+ /* find the best sub part we can show */
+ while (part_child) {
+ section_list = em_core_get_body_full(stream, msg_uid, &part_child->body, cnt_info, err_code, section_list);
+ part_child = part_child->next;
+ }
+
+ return section_list;
+}
+
+/* get body part in signed multiple part */
+static PARTLIST *em_core_get_signed_multi_part_full(MAILSTREAM *stream, int msg_uid, BODY *body, struct _m_content_info *cnt_info, int *err_code, PARTLIST *section_list)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ EM_DEBUG_LOG("stream[%p], msg_uid[%d], body[%p], cnt_info[%p], err_code[%p]", stream, msg_uid, body, cnt_info, err_code);
+
+ /* "protocol"= "application/pgp-signature */
+ return section_list;
+}
+
+/* get body part in encrypted multiple part */
+static PARTLIST *em_core_get_encrypted_multi_part_full(MAILSTREAM *stream, int msg_uid, BODY *body, struct _m_content_info *cnt_info, int *err_code, PARTLIST *section_list)
+{
+ EM_DEBUG_FUNC_BEGIN("stream[%p], msg_uid[%d], body[%p], cnt_info[%p], err_code[%p]", stream, msg_uid, body, cnt_info, err_code);
+
+ /* "protocol" = "application/pgp-encrypted */
+ return section_list;
+}
+
+/* get body part in multiple part */
+static PARTLIST *em_core_get_multi_part_full(MAILSTREAM *stream, int msg_uid, BODY *body, struct _m_content_info *cnt_info, int *err_code, PARTLIST *section_list)
+{
+ EM_DEBUG_FUNC_BEGIN("stream[%p], msg_uid[%d], body[%p], cnt_info[%p], err_code[%p]", stream, msg_uid, body, cnt_info, err_code);
+
+ switch (body->subtype[0]) {
+ case 'A': /* ALTERNATIV */
+ return section_list = em_core_get_alternative_multi_part_full(stream, msg_uid, body, cnt_info, err_code, section_list);
+
+ case 'S': /* SIGNE */
+ return section_list = em_core_get_signed_multi_part_full(stream, msg_uid, body, cnt_info, err_code, section_list);
+
+ case 'E': /* ENCRYPTE */
+ return section_list = em_core_get_encrypted_multi_part_full(stream, msg_uid, body, cnt_info, err_code, section_list);
+
+ default: /* process all unknown as MIXED (according to the RFC 2047 */
+ return section_list = em_core_get_allnested_part_full(stream, msg_uid, body, cnt_info, err_code, section_list);
+ }
+}
+
+
+PARTLIST *
+em_core_get_body_full(MAILSTREAM *stream, int msg_uid, BODY *body, struct _m_content_info *cnt_info, int *err_code, PARTLIST *section_list)
+{
+ EM_DEBUG_FUNC_BEGIN("stream[%p], msg_uid[%d], body[%p], cnt_info[%p], err_code[%p]", stream, msg_uid, body, cnt_info, err_code);
+
+ if (!stream || !body || !cnt_info) {
+ EM_DEBUG_EXCEPTION("stream[%p], msg_uid[%d], body[%p], cnt_info[%p]", stream, msg_uid, body, cnt_info);
+
+ if (err_code != NULL)
+ *err_code = EMF_ERROR_INVALID_PARAM;
+ return NULL;
+ }
+
+ switch (body->type) {
+ case TYPEMULTIPART:
+ return section_list = em_core_get_multi_part_full(stream, msg_uid, body, cnt_info, err_code, section_list);
+
+ case TYPEMESSAGE:
+ break;
+
+ case TYPETEXT:
+ case TYPEAPPLICATION:
+ case TYPEAUDIO:
+ case TYPEIMAGE:
+ case TYPEVIDEO:
+ case TYPEMODEL:
+ case TYPEOTHER:
+
+ /* Form list of attachment followed by list of inline images */
+ if (body->id || body->location || body->disposition.type) {
+
+ char filename[512] = {0, };
+ struct attachment_info **ai = NULL;
+ struct attachment_info *prev_ai = NULL;
+ struct attachment_info *next_ai = NULL;
+ int i = 0;
+
+ if (em_core_get_file_pointer(body, filename, cnt_info , (int *)NULL) < 0)
+ EM_DEBUG_EXCEPTION("em_core_get_file_pointer failed");
+ else {
+ /* To form list of attachment info - Attachment list followed by inline attachment list */
+ prev_ai = NULL;
+ next_ai = NULL;
+ ai = &cnt_info->file;
+
+ EM_DEBUG_LOG(" ai - %p ", (*ai));
+
+ if (ai != NULL) {
+ /* if ((body->id) || (body->location) */
+ if ((body->id) || (body->location) || ((body->disposition.type != NULL) && ((body->disposition.type[0] == 'i') || (body->disposition.type[0] == 'I')))) {
+ /* For Inline content append to the end */
+ for (i = 1; *ai; ai = &(*ai)->next)
+ i++;
+ }
+ else {
+ /* For attachment - search till Inline content found and insert before inline */
+ for (i = 1; *ai; ai = &(*ai)->next) {
+ if ((*ai)->type == 1) {
+ /* Means inline image */
+ EM_DEBUG_LOG(" Found Inline Content ");
+ next_ai = (*ai);
+ break;
+ }
+ i++;
+ prev_ai = (*ai);
+ }
+ }
+ }
+ if (!(*ai = em_core_malloc(sizeof(struct attachment_info)))) {
+ EM_DEBUG_EXCEPTION("em_core_malloc failed...");
+ }
+ else {
+ if (ai == NULL) {
+ cnt_info->file = (*ai);
+ }
+
+ memset((*ai), 0x00, sizeof(struct attachment_info));
+ if ((body->id) || (body->location) || ((body->disposition.type != NULL) && ((body->disposition.type[0] == 'i') || (body->disposition.type[0] == 'I'))))
+ (*ai)->type = 1;
+ else
+ (*ai)->type = 2;
+
+ (*ai)->name = EM_SAFE_STRDUP(filename);
+ (*ai)->size = body->size.bytes;
+
+#ifdef __ATTACHMENT_OPTI__
+ (*ai)->encoding = body->encoding;
+ if (body->sparep)
+ (*ai)->section = EM_SAFE_STRDUP(body->sparep);
+
+ EM_DEBUG_LOG(" Encoding - %d Section No - %s ", (*ai)->encoding, (*ai)->section);
+#endif
+
+ EM_DEBUG_LOG("Type[%d], Name[%s], Path[%s] ", (*ai)->type, (*ai)->name, (*ai)->save);
+ if (body->type == TYPEAPPLICATION) {
+ if (!strcasecmp(body->subtype, MIME_SUBTYPE_DRM_OBJECT))
+ (*ai)->drm = EMF_ATTACHMENT_DRM_OBJECT;
+ else if (!strcasecmp(body->subtype, MIME_SUBTYPE_DRM_RIGHTS))
+ (*ai)->drm = EMF_ATTACHMENT_DRM_RIGHTS;
+ else if (!strcasecmp(body->subtype, MIME_SUBTYPE_DRM_DCF))
+ (*ai)->drm = EMF_ATTACHMENT_DRM_DCF;
+ else if (!strcasecmp(body->subtype, "pkcs7-mime"))
+ cnt_info->grab_type = cnt_info->grab_type | GRAB_TYPE_ATTACHMENT;
+ }
+
+ if ((*ai)->type != 1 && next_ai != NULL) {
+ /* Means next_ai points to the inline attachment info structure */
+ if (prev_ai == NULL) {
+ /* First node is inline attachment */
+ (*ai)->next = next_ai;
+ cnt_info->file = (*ai);
+ }
+ else {
+ prev_ai->next = (*ai);
+ (*ai)->next = next_ai;
+ }
+ }
+ }
+ }
+
+ }
+
+
+ /* if (cnt_info->grab_type == GRAB_TYPE_ATTACHMENT */
+ if (cnt_info->grab_type & GRAB_TYPE_ATTACHMENT) {
+ if (((body->disposition.type != NULL) && ((body->disposition.type[0] == 'a') || (body->disposition.type[0] == 'A'))) && (cnt_info->file != NULL)) {
+ PARAMETER *param = NULL;
+ char *fn = NULL;
+
+ param = body->parameter;
+
+ while (param) {
+ if (!strcasecmp(param->attribute, "NAME")) {
+ fn = EM_SAFE_STRDUP(param->value);
+ break;
+ }
+ if (!strcasecmp(param->attribute, "FILENAME")) {
+ fn = EM_SAFE_STRDUP(param->value);
+ break;
+ }
+ param = param->next;
+ }
+ if ((fn != NULL)&& (!strcmp(fn, cnt_info->file->name)) && (body->size.bytes == cnt_info->file->size)) /* checks to zero in on particular attachmen */ {
+ section_list = em_core_add_node(section_list, body);
+ if (section_list == NULL) {
+ EM_DEBUG_EXCEPTION("adding node to section list failed");
+ EM_SAFE_FREE(fn);
+ return NULL;
+ }
+ else {
+ EM_SAFE_FREE(fn);
+ return section_list; /* single attachment download, so if a match found break the recursio */
+ }
+ }
+ EM_SAFE_FREE(fn);
+ }
+ }
+ else {
+ /* get a section list which has only plain, html and inline */
+ if (!((body->disposition.type != NULL) && ((body->disposition.type[0] == 'a') || (body->disposition.type[0] == 'A'))))/* if the body not an attachmen */ {
+ section_list = em_core_add_node(section_list, body);
+ if (section_list == NULL) {
+ EM_DEBUG_EXCEPTION("adding node to section list failed");
+ return NULL;
+ }
+ }
+ }
+
+ break;
+
+ default:
+ break;
+ }
+
+ return section_list;
+}
+
+EXPORT_API int em_core_get_body_part_list_full(MAILSTREAM *stream, int msg_uid, int account_id, int mail_id, BODY *body, struct _m_content_info *cnt_info, int *err_code, PARTLIST *section_list, int event_handle)
+{
+ EM_DEBUG_FUNC_BEGIN("stream[%p], msg_uid[%d], body[%p], cnt_info[%p], err_code[%p]", stream, msg_uid, body, cnt_info, err_code);
+
+ if (!stream || !body || !cnt_info) {
+ EM_DEBUG_EXCEPTION("stream[%p], msg_uid[%d], body[%p], cnt_info[%p]", stream, msg_uid, body, cnt_info);
+
+ if (err_code != NULL)
+ *err_code = EMF_ERROR_INVALID_PARAM;
+ return FAILURE;
+ }
+ section_list = em_core_get_body_full(stream, msg_uid, body, cnt_info, err_code, section_list);
+ if (section_list == NULL) /* assumed at least one body part exist */ {
+ EM_DEBUG_EXCEPTION("em_core_get_body_full failed");
+ return FAILURE;
+ }
+ if (em_core_get_body_part_imap_full(stream, msg_uid, account_id, mail_id, section_list, cnt_info, err_code, event_handle)<0) {
+ EM_DEBUG_EXCEPTION("em_core_get_body_part_imap_full failed");
+ em_core_free_section_list(section_list);
+ return FAILURE;
+ }
+ em_core_free_section_list(section_list);
+ return SUCCESS;
+}
+
+static int em_core_write_response_into_file(char *filename, char *write_mode, char *encoded, int encoding_type, char *subtype, int account_id, int mail_id, int *err)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int not_found = true;
+ FILE *fp = NULL;
+ char *decoded = NULL;
+ unsigned long decoded_len = 0;
+ int encoded_len = 0;
+ char *decoded_temp = NULL;
+ PARAMETER *param = NULL;
+ PARAMETER *param1 = NULL;
+ char save_file_name[MAX_PATH+1] = {0, };
+ char html_cid_path[MAX_PATH+1] = {0, };
+ int temp_decoded_len = 0;
+ int inline_support = 0;
+ int error = EMF_ERROR_NONE;
+
+ if (!encoded || !filename || !write_mode) {
+ EM_DEBUG_EXCEPTION("Invalid Param ");
+ error = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+
+ EM_DEBUG_LOG("Encoded buffer length [%d]", strlen(encoded));
+ encoded_len = strlen(encoded);
+
+ EM_DEBUG_LOG("encoding_type [%d]", encoding_type);
+ switch (encoding_type) {
+ case ENCQUOTEDPRINTABLE: {
+ unsigned char *orignal = (unsigned char *)g_strdup_printf("%s\r\n", encoded);
+ decoded = (char *)rfc822_qprint(orignal, encoded_len + 2, &decoded_len);
+ g_free(orignal);
+ break;
+ }
+
+ case ENCBASE64:
+ decoded = (char *)rfc822_base64((unsigned char *)encoded, encoded_len, &decoded_len);
+ break;
+
+ default: {
+ unsigned char *orignal = (unsigned char *)g_strdup_printf("%s\r\n", encoded);
+ memcpy(decoded = malloc(encoded_len + 3), orignal, encoded_len + 3);
+ decoded_len = encoded_len + 2;
+ g_free(orignal);
+ }
+ break;
+ }
+
+ if (decoded != NULL) {
+ EM_DEBUG_LOG("Decoded Length [%d] " , decoded_len);
+
+ if (!(fp = fopen(filename, write_mode))) {
+ EM_DEBUG_EXCEPTION("fopen failed - %s", filename);
+ error = EMF_ERROR_SYSTEM_FAILURE;
+ return false;
+ }
+
+ if (subtype && subtype[0] == 'H') {
+ char body_inline_id[512] = {0};
+
+ while (strstr(decoded, "cid:")) {
+ EM_DEBUG_LOG("Found cid:");
+ not_found = true;
+ if (g_inline_count) {
+ BODY *body_inline = NULL;
+ int inline_count = 0;
+ char *decoded_content_id = NULL;
+ while (inline_count < g_inline_count && g_inline_list[inline_count]) {
+ EM_DEBUG_LOG("inline_count [%d], g_inline_count [%d]", inline_count, g_inline_count);
+ body_inline = g_inline_list[inline_count];
+ param = body_inline->disposition.parameter;
+ param1 = body_inline->parameter;
+
+ memset(body_inline_id, 0x00, 512);
+
+ if (body_inline && body_inline->id && strlen(body_inline->id) > 0) {
+ EM_DEBUG_LOG("body_inline->id - %s", body_inline->id);
+ EM_DEBUG_LOG("param - %p param1 - %p", param, param1);
+ decoded_content_id = strstr(decoded, "cid:");
+
+ if (body_inline->id[0] == '<')
+ memcpy(body_inline_id, body_inline->id + 1, strlen(body_inline->id) - 2);
+ else
+ memcpy(body_inline_id, body_inline->id , strlen(body_inline->id));
+
+ EM_DEBUG_LOG("Inline body_inline_id [%s] ", body_inline_id);
+
+ if ((param || param1) && 0 == strncmp(body_inline_id , decoded_content_id + strlen("cid:"), strlen(body_inline_id))) {
+ EM_DEBUG_LOG(" Inline CID Found ");
+
+ memset(save_file_name, 0x00, MAX_PATH);
+ memset(html_cid_path, 0x00, MAX_PATH);
+
+ /* Finding 'filename' attribute from content inf */
+ em_core_get_file_pointer(body_inline, save_file_name, NULL, &error);
+
+ if (strlen(save_file_name) > 0) {
+ /* Content ID will be replaced with its file name in html */
+ memcpy(html_cid_path, decoded_content_id , strlen("cid:") + strlen(body_inline_id));
+
+ EM_DEBUG_LOG("Replacing %s with %s ", html_cid_path, save_file_name);
+ if ((decoded_temp = em_core_replace_string(decoded, html_cid_path, save_file_name))) {
+ EM_SAFE_FREE(decoded);
+ decoded = decoded_temp;
+ decoded_len = strlen(decoded);
+ EM_DEBUG_LOG("Decoded Length [%d] ", decoded_len);
+ inline_support = 1;
+ not_found = false;
+ /* only_body_download = false */
+ break;
+ }
+ }
+ }
+ }
+ inline_count++;
+ }
+
+ }
+
+
+ if (not_found) {
+ EM_DEBUG_LOG("not_found is true");
+ memset(body_inline_id, 0x00, sizeof(body_inline_id));
+ decoded_temp = em_replace_string_with_split_file_path(decoded, "cid:", body_inline_id);
+ if (decoded_temp) {
+ /* only_body_download = false */
+ /* EM_DEBUG_LOG(">>>> decoded_temp 2 [ %s ] ", decoded_temp) */
+ EM_SAFE_FREE(decoded);
+ decoded = decoded_temp;
+ temp_decoded_len = strlen(body_inline_id);
+ decoded_len = strlen(decoded);
+ EM_DEBUG_LOG("Decoded Length [%d] ", decoded_len);
+ inline_support = 1;
+ }
+ }
+ }
+ }
+
+ EM_DEBUG_LOG("Before fwrite");
+
+ if (decoded_len > 0 && fwrite(decoded, decoded_len, 1, fp) < 0) {
+ EM_DEBUG_EXCEPTION("fwrite(\"%s\") failed...", decoded);
+ EM_DEBUG_EXCEPTION(" Error Occured while writing ");
+ error = EMF_ERROR_SYSTEM_FAILURE;
+ goto FINISH_OFF;
+ }
+
+ }
+ else {
+ EM_DEBUG_EXCEPTION(" Error Occured while decoding ");
+ goto FINISH_OFF;
+ }
+
+FINISH_OFF:
+ if (err)
+ *err = error;
+
+ EM_SAFE_FREE(decoded);
+
+ if (fp != NULL)
+ fclose(fp);
+
+ EM_DEBUG_FUNC_END();
+
+ return true;
+}
+
+
+static BODY *em_core_select_body_structure_from_section_list(PARTLIST *section_list, char *section)
+{
+ PARTLIST *temp = section_list;
+ BODY *body = NULL;
+
+ while (temp != NULL) {
+ body = temp->body;
+ if (!strcmp(section, body->sparep))
+ return body;
+ temp = (PARTLIST *)temp->next;
+ }
+ return body;
+}
+
+
+
+
+static int imap_mail_write_body_to_file(MAILSTREAM *stream, int account_id, int mail_id, int is_attachment, char *filepath, int uid, char *section, int encoding, int *decoded_total, char *section_subtype, int *err_code)
+{
+ EM_PROFILE_BEGIN(imapMailWriteBodyToFile);
+ EM_DEBUG_FUNC_BEGIN("stream[%p], filepath[%s], uid[%d], section[%s], encoding[%d], decoded_total[%p], err_code[%p]", stream, filepath, uid, section, encoding, decoded_total, err_code);
+
+ int ret = false;
+ int err = EMF_ERROR_NONE;
+
+ FILE *fp = NULL;
+ IMAPLOCAL *imaplocal = NULL;
+ char tag[16], command[64];
+ char *response = NULL;
+ char *decoded = NULL;
+ int body_size = 0, total = 0;
+ char *file_id = NULL;
+ char server_uid[129];
+ char *filename = NULL;
+ int server_response_yn = 0;
+ int write_flag = false;
+ char *write_buffer = NULL;
+ unsigned char encoded[DOWNLOAD_MAX_BUFFER_SIZE] = {0, };
+ unsigned char test_buffer[LOCAL_MAX_BUFFER_SIZE] = {0};
+ int flag_first_write = true;
+
+ if (!stream || !filepath || !section) {
+ EM_DEBUG_EXCEPTION("stream[%p], filepath[%s], uid[%d], section[%s], encoding[%d], decoded_total[%p]", stream, filepath, uid, section, encoding, decoded_total);
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ int max_write_buffer_size = 0;
+ if (vconf_get_int("db/email/write_buffer_mode", &max_write_buffer_size) != 0) {
+ EM_DEBUG_EXCEPTION("vconf_get_int failed. So set direct file writing");
+ /* set as default profile typ */
+ max_write_buffer_size = 0;
+ }
+
+ EM_DEBUG_LOG(">>> WRITE BUFFER SIZE : %d KB", max_write_buffer_size);
+ if (max_write_buffer_size > 0) {
+ max_write_buffer_size *= 1024; /* KB -> byte */
+ if (!(write_buffer = em_core_malloc(sizeof(char) *max_write_buffer_size))) {
+ EM_DEBUG_EXCEPTION("em_core_malloc failed...");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+ }
+
+ FINISH_OFF_IF_CANCELED;
+
+ if (!(fp = fopen(filepath, "wb+"))) {
+ EM_DEBUG_EXCEPTION("fopen failed - %s", filepath);
+ err = EMF_ERROR_SYSTEM_FAILURE; /* EMF_ERROR_UNKNOWN */
+ goto FINISH_OFF;
+ }
+
+ imaplocal = stream->local;
+
+ if (!imaplocal->netstream) {
+ EM_DEBUG_EXCEPTION("invalid IMAP4 stream detected... %p", imaplocal->netstream);
+
+ err = EMF_ERROR_INVALID_STREAM;
+ goto FINISH_OFF;
+ }
+
+ EM_DEBUG_LOG(" next_decode_string = false ");
+ next_decode_string = false;
+
+ memset(tag, 0x00, sizeof(tag));
+ memset(command, 0x00, sizeof(command));
+
+ SNPRINTF(tag, sizeof(tag), "%08lx", 0xffffffff & (stream->gensym++));
+ SNPRINTF(command, sizeof(command), "%s UID FETCH %d BODY.PEEK[%s]\015\012", tag, uid, section);
+
+ EM_DEBUG_LOG("[IMAP4] >>> [%s]", command);
+
+ /* send command : get msgno/uid for all messag */
+ if (!net_sout(imaplocal->netstream, command, (int)strlen(command))) {
+ EM_DEBUG_EXCEPTION("net_sout failed...");
+ err = EMF_ERROR_CONNECTION_BROKEN;
+ goto FINISH_OFF;
+ }
+
+ while (imaplocal->netstream) {
+ char *p = NULL;
+ char *s = NULL;
+
+ if (!em_core_check_thread_status()) {
+ EM_DEBUG_LOG("Canceled...");
+ /* Is it realy required ? It might cause crashes.
+ if (imaplocal->netstream)
+ net_close (imaplocal->netstream);
+ */
+ imaplocal->netstream = NULL;
+ err = EMF_ERROR_CANCELLED;
+ goto FINISH_OFF;
+ }
+
+ /* receive respons */
+ if (!(response = net_getline(imaplocal->netstream))) {
+ EM_DEBUG_EXCEPTION("net_getline failed...");
+ err = EMF_ERROR_INVALID_RESPONSE;
+ goto FINISH_OFF;
+ }
+#ifdef FEATURE_CORE_DEBUG
+ EM_DEBUG_LOG("recv[%s]", response);
+#endif
+
+ write_flag = false;
+ if (response[0] == '*' && !server_response_yn) { /* start of respons */
+
+ if ((p = strstr(response, "BODY[")) /* || (p = strstr(s + 1, "BODY["))*/) {
+ server_response_yn = 1;
+ p += strlen("BODY[");
+ s = p;
+
+ while (*s != ']')
+ s++;
+
+ *s = '\0';
+
+ if (strcmp(section, p)) {
+ err = EMF_ERROR_INVALID_RESPONSE;
+ goto FINISH_OFF;
+ }
+
+ if ((p = strstr(s+1, " {"))) {
+ p += strlen(" {");
+ s = p;
+
+ while (isdigit(*s))
+ s++;
+
+ *s = '\0';
+
+ body_size = atoi(p);
+ }
+ else { /* no body length is replied */
+ if ((p = strstr(s+1, " \""))) { /* seek the termination of double quot */
+ char *t = NULL;
+ p += strlen(" \"");
+ if ((t = strstr(p, "\""))) {
+ body_size = t - p;
+ *t = '\0';
+ EM_DEBUG_LOG("Body : start[%p] end[%p] : body[%s]", p, t, p);
+ /* need to decod */
+ EM_SAFE_FREE(response);
+ response = EM_SAFE_STRDUP(p);
+ write_flag = true;
+ }
+ else {
+ err = EMF_ERROR_INVALID_RESPONSE;
+ goto FINISH_OFF;
+ }
+ }
+ else {
+ err = EMF_ERROR_INVALID_RESPONSE;
+ goto FINISH_OFF;
+ }
+ }
+
+ /* sending progress noti to application.
+ 1. mail_id
+ 2. file_id
+ 3. bodysize
+ */
+ parse_file_path_to_filename(filepath, &file_id);
+
+ filename = file_id;
+ sprintf(server_uid, "%d", uid);
+
+ EM_DEBUG_LOG("file_id [%s]", file_id);
+ EM_DEBUG_LOG("filename [%p]-[%s]", filename, filename);
+ EM_DEBUG_LOG("body_size [%d]", body_size);
+ EM_DEBUG_LOG("server_uid [%s]", server_uid);
+ EM_DEBUG_LOG("mail_id [%d]", mail_id);
+
+ if (is_attachment) {
+ EM_DEBUG_LOG("Attachment number [%d]", is_attachment);
+ if (!em_storage_notify_network_event(NOTI_DOWNLOAD_ATTACH_START, mail_id, filename, is_attachment, 0))
+ EM_DEBUG_EXCEPTION(" em_storage_notify_network_event [ NOTI_DOWNLOAD_ATTACH_START] Failed >>>> ");
+ _imap4_download_noti_interval_value = body_size *DOWNLOAD_NOTI_INTERVAL_PERCENT / 100;
+ _imap4_total_body_size = body_size;
+ }
+ else {
+ if (multi_part_body_size) {
+ EM_DEBUG_LOG("Multipart body size is [%d]", multi_part_body_size);
+ if (!em_storage_notify_network_event(NOTI_DOWNLOAD_MULTIPART_BODY, mail_id, filename, multi_part_body_size, 0))
+ EM_DEBUG_EXCEPTION(" em_storage_notify_network_event [ NOTI_DOWNLOAD_BODY_START] Failed >>>> ");
+ _imap4_download_noti_interval_value = multi_part_body_size *DOWNLOAD_NOTI_INTERVAL_PERCENT / 100;
+ /* _imap4_total_body_size should be set before calling this functio */
+ /* _imap4_total_body_size */
+ }
+ else {
+ if (!em_storage_notify_network_event(NOTI_DOWNLOAD_BODY_START, mail_id, filename, body_size, 0))
+ EM_DEBUG_EXCEPTION(" em_storage_notify_network_event [ NOTI_DOWNLOAD_BODY_START] Failed >>>>");
+ _imap4_download_noti_interval_value = body_size *DOWNLOAD_NOTI_INTERVAL_PERCENT / 100;
+ _imap4_total_body_size = body_size;
+ }
+ }
+ if (_imap4_download_noti_interval_value > DOWNLOAD_NOTI_INTERVAL_SIZE) {
+ _imap4_download_noti_interval_value = DOWNLOAD_NOTI_INTERVAL_SIZE;
+ }
+ if (body_size < DOWNLOAD_MAX_BUFFER_SIZE) {
+ if (net_getbuffer (imaplocal->netstream, (long)body_size, (char *)encoded) <= 0) {
+ EM_DEBUG_EXCEPTION("net_getbuffer failed...");
+ err = EMF_ERROR_NO_RESPONSE;
+ goto FINISH_OFF;
+ }
+
+ if (!em_core_write_response_into_file(filepath, "wb+", (char *)encoded, encoding, section_subtype, account_id, mail_id, &err)) {
+ EM_DEBUG_EXCEPTION("write_response_into_file failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ total = strlen((char *)encoded);
+ EM_DEBUG_LOG("total = %d", total);
+ EM_DEBUG_LOG("write_response_into_file successful %s.....", filename);
+
+ if (((_imap4_last_notified_body_size + _imap4_download_noti_interval_value) <= _imap4_received_body_size)
+ || (_imap4_received_body_size >= _imap4_total_body_size)) /* 100 */ {
+ /* In some situation, total_encoded_len includes the length of dummy bytes. So it might be greater than body_size */
+ int gap = 0;
+ if (total > body_size)
+ gap = total - body_size;
+ _imap4_received_body_size -= gap;
+ _imap4_last_notified_body_size = _imap4_received_body_size;
+
+ EM_DEBUG_LOG("DOWNLOADING STATUS NOTIFY : Encoded[%d] / [%d] = %d %% Completed. -- Total Decoded[%d]", total, body_size, 100*total/body_size, total);
+ EM_DEBUG_LOG("DOWNLOADING STATUS NOTIFY : Total[%d] / [%d] = %d %% Completed.", _imap4_received_body_size, _imap4_total_body_size, 100*_imap4_received_body_size/_imap4_total_body_size);
+
+ if (is_attachment) {
+ if (!em_storage_notify_network_event(NOTI_DOWNLOAD_ATTACH_START, mail_id, filename, is_attachment, 100 *_imap4_received_body_size / _imap4_total_body_size))
+ EM_DEBUG_EXCEPTION(" em_storage_notify_network_event [ NOTI_DOWNLOAD_ATTACH_START] Failed >>>> ");
+ }
+ else {
+ if (multi_part_body_size) {
+ if (!em_storage_notify_network_event(NOTI_DOWNLOAD_MULTIPART_BODY, mail_id, filename, _imap4_total_body_size, _imap4_received_body_size))
+ EM_DEBUG_EXCEPTION(" em_storage_notify_network_event [ NOTI_DOWNLOAD_BODY_START] Failed >>>> ");
+ }
+ else {
+ if (!em_storage_notify_network_event(NOTI_DOWNLOAD_BODY_START, mail_id, filename, _imap4_total_body_size, _imap4_received_body_size))
+ EM_DEBUG_EXCEPTION(" em_storage_notify_network_event [ NOTI_DOWNLOAD_BODY_START] Failed >>>>");
+ }
+ } /* if (is_attachment) .. else .. */
+ }
+ }
+ else {
+ int temp_body_size = body_size;
+ int x = 0;
+
+ if (encoding == ENCBASE64)
+ x = (sizeof(encoded)/78) *78; /* to solve base64 decoding pro */
+ else
+ x = sizeof(encoded)-1;
+
+ memset(test_buffer, 0x00, sizeof(test_buffer));
+ while (temp_body_size && (total <body_size)) {
+
+ memset(test_buffer, 0x00, sizeof(test_buffer));
+ while ((total != body_size) && temp_body_size && ((strlen((char *)test_buffer) + x) < sizeof(test_buffer))) {
+ memset(encoded, 0x00, sizeof(encoded));
+
+ if (net_getbuffer (imaplocal->netstream, (long)x, (char *)encoded) <= 0) {
+ EM_DEBUG_EXCEPTION("net_getbuffer failed...");
+ err = EMF_ERROR_NO_RESPONSE;
+ goto FINISH_OFF;
+ }
+
+ temp_body_size = temp_body_size - x;
+ strncat((char *)test_buffer, (char *)encoded, strlen((char *)encoded));
+ total = total + x;
+ _imap4_received_body_size += strlen((char *)encoded);
+
+ if (temp_body_size/x)
+ x = x;
+ else if (temp_body_size%x)
+ x = temp_body_size%x;
+
+ if (((_imap4_last_notified_body_size + _imap4_download_noti_interval_value) <= _imap4_received_body_size)
+ || (_imap4_received_body_size >= _imap4_total_body_size)) /* 100 */ {
+ /* In some situation, total_encoded_len includes the length of dummy bytes. So it might be greater than body_size */
+ int gap = 0;
+ if (total > body_size)
+ gap = total - body_size;
+ _imap4_received_body_size -= gap;
+ _imap4_last_notified_body_size = _imap4_received_body_size;
+
+ /* EM_DEBUG_LOG("DOWNLOADING STATUS NOTIFY : Encoded[%d] / [%d] = %d %% Completed. -- Total Decoded[%d]", total, body_size, 100*total/body_size, total) */
+ EM_DEBUG_LOG("DOWNLOADING STATUS NOTIFY : Total[%d] / [%d] = %d %% Completed.", _imap4_received_body_size, _imap4_total_body_size, 100*_imap4_received_body_size/_imap4_total_body_size);
+
+ if (is_attachment) {
+ if (!em_storage_notify_network_event(NOTI_DOWNLOAD_ATTACH_START, mail_id, filename, is_attachment, 100 *_imap4_received_body_size / _imap4_total_body_size))
+ EM_DEBUG_EXCEPTION(" em_storage_notify_network_event [ NOTI_DOWNLOAD_ATTACH_START] Failed >>>> ");
+ }
+ else {
+ if (multi_part_body_size) {
+ /* EM_DEBUG_LOG("DOWNLOADING.......... : Multipart body size is [%d]", multi_part_body_size) */
+ if (!em_storage_notify_network_event(NOTI_DOWNLOAD_MULTIPART_BODY, mail_id, filename, _imap4_total_body_size, _imap4_received_body_size))
+ EM_DEBUG_EXCEPTION(" em_storage_notify_network_event [ NOTI_DOWNLOAD_BODY_START] Failed >>>> ");
+ }
+ else {
+ if (!em_storage_notify_network_event(NOTI_DOWNLOAD_BODY_START, mail_id, filename, _imap4_total_body_size, _imap4_received_body_size))
+ EM_DEBUG_EXCEPTION(" em_storage_notify_network_event [ NOTI_DOWNLOAD_BODY_START] Failed >>>>");
+ }
+ } /* if (is_attachment) .. else .. */
+ }
+
+
+ }
+
+ if (flag_first_write == true) {
+ if (!em_core_write_response_into_file(filepath, "wb+", (char *)test_buffer, encoding, section_subtype, account_id, mail_id, &err)) {
+ EM_DEBUG_EXCEPTION("write_response_into_file %s failed [%d]", filepath, err);
+ goto FINISH_OFF;
+ }
+ flag_first_write = false;
+ }
+ else {
+ if (!em_core_write_response_into_file(filepath, "ab+", (char *)test_buffer, encoding, section_subtype, account_id, mail_id, &err)) /* append */ {
+ EM_DEBUG_EXCEPTION("write_response_into_file %s failed [%d]", filepath, err);
+ goto FINISH_OFF;
+ }
+ }
+ EM_DEBUG_LOG("%d has been written", strlen((char *)test_buffer));
+ /* notif */
+ }
+ }
+
+ }
+ else {
+ err = EMF_ERROR_INVALID_RESPONSE;
+ goto FINISH_OFF;
+ }
+
+ }
+ else if (!strncmp(response, tag, strlen(tag))) { /* end of respons */
+ if (!strncmp(response + strlen(tag) + 1, "OK", 2)) {
+ EM_SAFE_FREE(response);
+ }
+ else { /* 'NO' or 'BAD */
+ err = EMF_ERROR_IMAP4_FETCH_UID_FAILURE;
+ goto FINISH_OFF;
+ }
+
+ break;
+ }
+ else if (!strcmp(response, ")")) {
+ /* The end of response which contains body informatio */
+ write_flag = false;
+ }
+
+ } /* while (imaplocal->netstream) */
+
+ if (decoded_total != NULL)
+ *decoded_total = total;
+
+ ret = true;
+
+FINISH_OFF:
+ EM_SAFE_FREE(decoded);
+ EM_SAFE_FREE(response);
+
+ if (fp != NULL)
+ fclose(fp);
+
+ EM_SAFE_FREE(write_buffer);
+
+ if (ret == false) { /* delete temp fil */
+ struct stat temp_file_stat;
+ if (filepath && stat(filepath, &temp_file_stat) == 0)
+ remove(filepath);
+ }
+
+ if (err_code != NULL)
+ *err_code = err;
+
+ EM_PROFILE_END(imapMailWriteBodyToFile);
+
+ return ret;
+}
+
+static int em_core_get_body_part_imap_full(MAILSTREAM *stream, int msg_uid, int account_id, int mail_id, PARTLIST *section_list, struct _m_content_info *cnt_info, int *err_code, int event_handle)
+{
+ EM_DEBUG_FUNC_BEGIN("stream[%p], msg_uid[%d], body[%p], cnt_info[%p], err_code[%p]", stream, msg_uid, section_list, cnt_info, err_code);
+
+ int err = EMF_ERROR_NONE;
+ char sections[IMAP_MAX_COMMAND_LENGTH] = {0};
+ IMAPLOCAL *imaplocal = NULL;
+ char tag[16] = {0}, command[IMAP_MAX_COMMAND_LENGTH] = {0};
+ char section[16] = {0};
+ char *response = NULL;
+ BODY *body = NULL;
+ int server_response_yn = 0;
+ int body_size = 0;
+ char *buf = NULL;
+ char filename[512] = {0, };
+ int return_value = 0 ;
+ int encoding = 0;
+ unsigned char encoded[DOWNLOAD_MAX_BUFFER_SIZE] = {0};
+ unsigned char test_buffer[LOCAL_MAX_BUFFER_SIZE] = {0};
+ struct attachment_info *ai = NULL;
+ int i = 0;
+ int total = 0;
+ int flag_first_write = 1;
+ int imap4_total_body_download_progress = 0, progress = 0;
+
+ if (!(imaplocal = stream->local) || !imaplocal->netstream || !section_list || !cnt_info) {
+ EM_DEBUG_EXCEPTION("invalid IMAP4 stream detected...");
+ err = EMF_ERROR_INVALID_PARAM;
+ return_value = -1;
+ goto FINISH_OFF;
+ }
+ memset(sections, 0x00, sizeof(sections));
+
+ if (section_list != NULL) {
+ PARTLIST *temp = section_list;
+
+ if (cnt_info->grab_type == GRAB_TYPE_ATTACHMENT) /* to download attachmen */ {
+ body = temp->body;
+ if (body->sparep != NULL) {
+ snprintf(sections, sizeof(sections), "BODY.PEEK[%s]", (char *)body->sparep);
+ }
+ else {
+ EM_DEBUG_EXCEPTION("body->sparep can not be null. ");
+ return_value = -1;
+ goto FINISH_OFF;
+
+ }
+ }
+ else {
+ while (temp != NULL) {
+ char t[64] = {0};
+ body = temp->body;
+
+ if ((body->type == TYPETEXT) || (body->id != NULL) || ((body->disposition.type != NULL) && ((body->disposition.type[0] == 'i') || (body->disposition.type[0] == 'I')))) {
+ snprintf(t, sizeof(t), "BODY.PEEK[%s] ", (char *)body->sparep); /* body parts seperated by period */
+ strcat(sections, t);
+ }
+ temp = (PARTLIST *)temp->next;
+ }
+ }
+ }
+
+ if ((strlen(sections) == (sizeof(sections)-1)) || (strlen(sections) == 0)) {
+ EM_DEBUG_EXCEPTION(" Too many body parts or nil. IMAP command may cross 1000bytes.");
+ return_value = -1;
+ goto FINISH_OFF;
+ }
+
+ if (sections[strlen(sections)-1] == ' ') {
+ sections[strlen(sections)-1] = '\0';
+ }
+
+ EM_DEBUG_LOG("sections <%s>", sections);
+
+ memset(tag, 0x00, sizeof(tag));
+ memset(command, 0x00, sizeof(command));
+
+ SNPRINTF(tag, sizeof(tag), "%08lx", 0xffffffff & (stream->gensym++));
+ SNPRINTF(command, sizeof(command), "%s UID FETCH %d (%s)\015\012", tag, msg_uid, sections);
+ EM_DEBUG_LOG("command %s", command);
+
+ if (strlen(command) == (sizeof(command)-1)) {
+ EM_DEBUG_EXCEPTION(" Too many body parts. IMAP command will fail.");
+ return_value = -1;
+ goto FINISH_OFF;
+ }
+
+ /* send command : get msgno/uid for all messag */
+ if (!net_sout(imaplocal->netstream, command, (int)strlen(command))) {
+ EM_DEBUG_EXCEPTION("net_sout failed...");
+ err = EMF_ERROR_CONNECTION_BROKEN;
+ return_value = -1;
+ goto FINISH_OFF;
+ }
+ while (imaplocal->netstream) {
+
+ /* receive respons */
+ if (!(response = net_getline(imaplocal->netstream))) {
+ EM_DEBUG_EXCEPTION("net_getline failed...");
+ err = EMF_ERROR_INVALID_RESPONSE;
+ return_value = -1;
+ goto FINISH_OFF;
+ }
+
+ if (strstr(response, "BODY[")) {
+
+ if (!server_response_yn) /* start of respons */ {
+ if (response[0] != '*') {
+ err = EMF_ERROR_INVALID_RESPONSE;
+ EM_DEBUG_EXCEPTION("Start of response doesn contain *");
+ return_value = -1;
+ goto FINISH_OFF;
+ }
+ server_response_yn = 1;
+ }
+
+ flag_first_write = 1;
+ total = 0;
+ memset(encoded, 0x00, sizeof(encoded));
+
+ if (em_core_get_section_body_size(response, section, &body_size)<0) {
+ EM_DEBUG_EXCEPTION("em_core_get_section_body_size failed [%d]", err);
+ err = EMF_ERROR_INVALID_RESPONSE;
+ return_value = -1;
+ goto FINISH_OFF;
+ }
+ EM_DEBUG_LOG("body_size-%d", body_size);
+
+ if ((body = em_core_select_body_structure_from_section_list(section_list, section)) == NULL)/* get body from seciton_lis */ {
+ EM_DEBUG_EXCEPTION("em_core_select_body_structure_from_section_list failed [%d]", err);
+ err = EMF_ERROR_INVALID_RESPONSE;
+ return_value = -1;
+ goto FINISH_OFF;
+ }
+ encoding = body->encoding;
+
+ /* if (em_core_get_file_pointer(account_id, mail_id, body, buf, cnt_info , err)<0) {
+ EM_DEBUG_EXCEPTION("em_core_get_file_pointer failed [%d]", err);
+ goto FINISH_OFF;
+ }*/
+
+ if (!em_core_get_temp_file_name(&buf, &err)) {
+ EM_DEBUG_EXCEPTION("em_core_get_temp_file_name failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ EM_DEBUG_LOG("buf : %s", buf);
+
+ /* notifying UI start */
+ /* parse_file_path_to_filename(buf, &file_id); */
+
+ /* EM_DEBUG_LOG(">>>> filename - %p >>>>>>", file_id) */
+
+
+ if (body->type == TYPETEXT && body->subtype && (!body->disposition.type || (body->disposition.type && (body->disposition.type[0] == 'i' || body->disposition.type[0] == 'I')))) {
+ if (body->subtype[0] == 'H') {
+ cnt_info->text.html = buf;
+ }
+ else {
+ cnt_info->text.plain = buf;
+ }
+ PARAMETER *param = NULL;
+
+ param = body->parameter;
+
+ while (param) {
+ if (!strcasecmp(param->attribute, "CHARSET")) {
+ cnt_info->text.plain_charset = EM_SAFE_STRDUP(param->value);
+ break;
+ }
+
+ param = param->next;
+ }
+
+ }
+ else if (body->id || body->location || body->disposition.type) {
+
+ if (em_core_get_file_pointer(body, filename, cnt_info , &err)<0) {
+ EM_DEBUG_EXCEPTION("em_core_get_file_pointer failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ /* Search info from attachment list followed by inline attachment list */
+
+ ai = cnt_info->file;
+ EM_DEBUG_LOG(" ai - %p ", (ai));
+
+ /* For Inline content append to the end */
+ for (i = 1; ai; ai = ai->next, i++) {
+ if (ai->save == NULL && (ai->name != NULL && !strcmp(ai->name, filename))) {
+ EM_DEBUG_LOG("Found matching details ");
+ ai->save = buf;
+ }
+
+ }
+
+ }
+
+ FINISH_OFF_IF_CANCELED;
+
+ if (cnt_info->grab_type == GRAB_TYPE_ATTACHMENT) {
+ if (!em_storage_notify_network_event(NOTI_DOWNLOAD_ATTACH_START, mail_id, buf, cnt_info->file_no, 0))
+ EM_DEBUG_EXCEPTION(" em_storage_notify_network_event [ NOTI_DOWNLOAD_ATTACH_START] Failed >>>> ");
+
+ _imap4_download_noti_interval_value = body_size *DOWNLOAD_NOTI_INTERVAL_PERCENT / 100;
+ _imap4_total_body_size = body_size;
+ }
+ else {
+ if (multi_part_body_size) {
+ EM_DEBUG_LOG("Multipart body size is [%d]", multi_part_body_size);
+ if (!em_storage_notify_network_event(NOTI_DOWNLOAD_MULTIPART_BODY, mail_id, buf, multi_part_body_size, 0))
+ EM_DEBUG_EXCEPTION(" em_storage_notify_network_event [ NOTI_DOWNLOAD_BODY_START] Failed >>>> ");
+
+ _imap4_download_noti_interval_value = multi_part_body_size *DOWNLOAD_NOTI_INTERVAL_PERCENT / 100;
+ }
+ else {
+ if (!em_storage_notify_network_event(NOTI_DOWNLOAD_BODY_START, mail_id, buf, body_size, 0))
+ EM_DEBUG_EXCEPTION(" em_storage_notify_network_event [ NOTI_DOWNLOAD_BODY_START] Failed >>>> ");
+
+ _imap4_download_noti_interval_value = body_size *DOWNLOAD_NOTI_INTERVAL_PERCENT / 100;
+ _imap4_total_body_size = body_size;
+ }
+
+ }
+
+ if (_imap4_download_noti_interval_value > DOWNLOAD_NOTI_INTERVAL_SIZE) {
+ _imap4_download_noti_interval_value = DOWNLOAD_NOTI_INTERVAL_SIZE;
+ }
+
+ /* EM_SAFE_FREE(file_id) */
+ /* notifying UI end */
+
+ if (body_size < DOWNLOAD_MAX_BUFFER_SIZE) {
+ if (net_getbuffer (imaplocal->netstream, (long)body_size, (char *)encoded) <= 0) {
+ EM_DEBUG_EXCEPTION("net_getbuffer failed...");
+ err = EMF_ERROR_NO_RESPONSE;
+ return_value = -1;
+ goto FINISH_OFF;
+ }
+ if (!em_core_write_response_into_file(buf, "wb+", (char *)encoded, encoding, body->subtype, account_id, mail_id, &err)) {
+ EM_DEBUG_EXCEPTION("write_response_into_file failed [%d]", err);
+ return_value = -1;
+ goto FINISH_OFF;
+ }
+
+ EM_DEBUG_LOG("total = %d", total);
+ EM_DEBUG_LOG("write_response_into_file successful %s.....", buf);
+
+ total = _imap4_received_body_size = strlen((char *)encoded);
+
+ EM_DEBUG_LOG(" _imap4_last_notified_body_size - %d ", _imap4_last_notified_body_size);
+ EM_DEBUG_LOG(" _imap4_download_noti_interval_value - %d ", _imap4_download_noti_interval_value);
+ EM_DEBUG_LOG(" _imap4_received_body_size - %d ", _imap4_received_body_size);
+ EM_DEBUG_LOG(" _imap4_total_body_size - %d ", _imap4_total_body_size);
+
+ if (((_imap4_last_notified_body_size + _imap4_download_noti_interval_value) <= _imap4_received_body_size)
+ || (_imap4_received_body_size >= _imap4_total_body_size)) /* 100 */ {
+ /* In some situation, total_encoded_len includes the length of dummy bytes. So it might be greater than body_size */
+ int gap = 0;
+
+ if (total > body_size)
+ gap = total - body_size;
+ _imap4_received_body_size -= gap;
+ _imap4_last_notified_body_size = _imap4_received_body_size;
+ if (_imap4_total_body_size)
+ imap4_total_body_download_progress = 100*_imap4_received_body_size/_imap4_total_body_size;
+ else
+ imap4_total_body_download_progress = _imap4_received_body_size;
+
+ EM_DEBUG_LOG("3 : body_size %d", body_size);
+
+ if (body_size)
+ progress = 100*total/body_size;
+ else
+ progress = body_size;
+
+ EM_DEBUG_LOG("DOWNLOADING STATUS NOTIFY : Encoded[%d] / [%d] = %d %% Completed. -- Total Decoded[%d]", total, body_size, progress, total);
+ EM_DEBUG_LOG("DOWNLOADING STATUS NOTIFY : Total[%d] / [%d] = %d %% Completed.", _imap4_received_body_size, _imap4_total_body_size, imap4_total_body_download_progress);
+
+ if (cnt_info->grab_type == GRAB_TYPE_ATTACHMENT) {
+ if (!em_storage_notify_network_event(NOTI_DOWNLOAD_ATTACH_START, mail_id, buf, cnt_info->file_no, imap4_total_body_download_progress))
+ EM_DEBUG_EXCEPTION(" em_storage_notify_network_event [ NOTI_DOWNLOAD_ATTACH_START] Failed >>>> ");
+ }
+ else {
+ if (multi_part_body_size) {
+ /* EM_DEBUG_LOG("DOWNLOADING.......... : Multipart body size is [%d]", multi_part_body_size) */
+ if (!em_storage_notify_network_event(NOTI_DOWNLOAD_MULTIPART_BODY, mail_id, buf, _imap4_total_body_size, _imap4_received_body_size))
+ EM_DEBUG_EXCEPTION(" em_storage_notify_network_event [ NOTI_DOWNLOAD_BODY_START] Failed >>>> ");
+ }
+ else {
+ if (!em_storage_notify_network_event(NOTI_DOWNLOAD_BODY_START, mail_id, buf, _imap4_total_body_size, _imap4_received_body_size))
+ EM_DEBUG_EXCEPTION(" em_storage_notify_network_event [ NOTI_DOWNLOAD_BODY_START] Failed >>>>");
+ }
+ } /* if (is_attachment) .. else .. */
+ }
+
+ EM_DEBUG_LOG("4");
+
+ }
+ else {
+ int temp_body_size = body_size;
+ int x = 0;
+
+ if (encoding == ENCBASE64)
+ x = (sizeof(encoded)/78) *78; /* to solve base64 decoding pro */
+ else
+ x = sizeof(encoded)-1;
+
+ memset(test_buffer, 0x00, sizeof(test_buffer));
+ while (temp_body_size && (total <body_size)) {
+
+ memset(test_buffer, 0x00, sizeof(test_buffer));
+ while ((total != body_size) && temp_body_size && ((strlen((char *)test_buffer) + x) < sizeof(test_buffer))) {
+ memset(encoded, 0x00, sizeof(encoded));
+
+ if (net_getbuffer (imaplocal->netstream, (long)x, (char *)encoded) <= 0) {
+ EM_DEBUG_EXCEPTION("net_getbuffer failed...");
+ err = EMF_ERROR_NO_RESPONSE;
+ return_value = -1;
+ goto FINISH_OFF;
+ }
+
+ temp_body_size = temp_body_size - x;
+ strncat((char *)test_buffer, (char *)encoded, strlen((char *)encoded));
+ total = total + x;
+ _imap4_received_body_size += strlen((char *)encoded);
+
+ EM_DEBUG_LOG("total = %d", total);
+
+ if (temp_body_size/x)
+ x = x;
+ else if (temp_body_size%x)
+ x = temp_body_size%x;
+
+ EM_DEBUG_LOG(" _imap4_last_notified_body_size - %d ", _imap4_last_notified_body_size);
+ EM_DEBUG_LOG(" _imap4_download_noti_interval_value - %d ", _imap4_download_noti_interval_value);
+ EM_DEBUG_LOG(" _imap4_received_body_size - %d ", _imap4_received_body_size);
+ EM_DEBUG_LOG(" _imap4_received_body_size - %d ", _imap4_received_body_size);
+ EM_DEBUG_LOG(" _imap4_total_body_size - %d ", _imap4_total_body_size);
+
+ if (_imap4_total_body_size)
+ imap4_total_body_download_progress = 100*_imap4_received_body_size/_imap4_total_body_size;
+ else
+ imap4_total_body_download_progress = _imap4_received_body_size;
+
+ if (((_imap4_last_notified_body_size + _imap4_download_noti_interval_value) <= _imap4_received_body_size)
+ || (_imap4_received_body_size >= _imap4_total_body_size)) /* 100 */ {
+ /* In some situation, total_encoded_len includes the length of dummy bytes. So it might be greater than body_size */
+ int gap = 0;
+ if (total > body_size)
+ gap = total - body_size;
+ _imap4_received_body_size -= gap;
+ _imap4_last_notified_body_size = _imap4_received_body_size;
+
+ if (body_size)
+ progress = 100*total/body_size;
+ else
+ progress = body_size;
+
+ EM_DEBUG_LOG("DOWNLOADING STATUS NOTIFY : Encoded[%d] / [%d] = %d %% Completed. -- Total Decoded[%d]", total, body_size, progress, total);
+ EM_DEBUG_LOG("DOWNLOADING STATUS NOTIFY : Total[%d] / [%d] = %d %% Completed.", _imap4_received_body_size, _imap4_total_body_size, imap4_total_body_download_progress);
+
+ if (cnt_info->grab_type == GRAB_TYPE_ATTACHMENT) {
+ if (!em_storage_notify_network_event(NOTI_DOWNLOAD_ATTACH_START, mail_id, buf, cnt_info->file_no, imap4_total_body_download_progress))
+ EM_DEBUG_EXCEPTION(" em_storage_notify_network_event [ NOTI_DOWNLOAD_ATTACH_START] Failed >>>> ");
+ }
+ else {
+ if (multi_part_body_size) {
+ /* EM_DEBUG_LOG("DOWNLOADING.......... : Multipart body size is [%d]", multi_part_body_size) */
+ if (!em_storage_notify_network_event(NOTI_DOWNLOAD_MULTIPART_BODY, mail_id, buf, _imap4_total_body_size, _imap4_received_body_size))
+ EM_DEBUG_EXCEPTION(" em_storage_notify_network_event [ NOTI_DOWNLOAD_BODY_START] Failed >>>> ");
+ }
+ else {
+ if (!em_storage_notify_network_event(NOTI_DOWNLOAD_BODY_START, mail_id, buf, _imap4_total_body_size, _imap4_received_body_size))
+ EM_DEBUG_EXCEPTION(" em_storage_notify_network_event [ NOTI_DOWNLOAD_BODY_START] Failed >>>>");
+ }
+ } /* if (is_attachment) .. else .. */
+ }
+ }
+
+ if (flag_first_write == 1) {
+ if (!em_core_write_response_into_file(buf, "wb+", (char *)test_buffer, encoding, body->subtype, account_id, mail_id, &err)) {
+ EM_DEBUG_EXCEPTION("write_response_into_file %s failed [%d]", buf, err);
+ return_value = -1;
+ goto FINISH_OFF;
+ }
+ flag_first_write = 0;
+ }
+ else {
+ if (!em_core_write_response_into_file(buf, "ab+", (char *)test_buffer, encoding, body->subtype, account_id, mail_id, &err)) /* append */ {
+ EM_DEBUG_EXCEPTION("write_response_into_file %s failed [%d]", buf, err);
+ return_value = -1;
+ goto FINISH_OFF;
+ }
+ }
+
+ EM_DEBUG_LOG("%d has been written", strlen((char *)test_buffer));
+
+
+
+ }
+ }
+ EM_DEBUG_LOG("5");
+ }
+ else if (!strncmp(response, tag, strlen(tag))) /* end of respons */ {
+ if (!strncmp(response + strlen(tag) + 1, "OK", 2))
+ EM_SAFE_FREE(response);
+ else /* 'NO' or 'BAD */ {
+ err = EMF_ERROR_IMAP4_FETCH_UID_FAILURE;
+ return_value = -1;
+ goto FINISH_OFF;
+ }
+
+ break;
+ }
+ else if (!strcmp(response, ")")) {
+
+ }
+
+ free(response);
+ response = NULL;
+ }
+
+ return_value = 0;
+
+ FINISH_OFF:
+
+ if (err_code)
+ *err_code = err;
+
+ EM_SAFE_FREE(response);
+
+ return return_value;
+}
+
+static int em_core_get_file_pointer(BODY *body, char *buf, struct _m_content_info *cnt_info , int *err)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ char *decoded_filename = NULL;
+ char attachment_file_name[MAX_PATH] = { 0, };
+ char attachment_file_name_source[MAX_PATH] = {0, };
+ int error = EMF_ERROR_NONE;
+
+ if ((body->type == TYPETEXT) && (body->disposition.type == NULL)) {
+ EM_DEBUG_LOG("body->type == TYPETEXT");
+ if (!cnt_info) {
+ EM_DEBUG_EXCEPTION("But, cnt_info is null");
+ error = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+ if (body->subtype[0] == 'H') {
+ if (cnt_info->text.plain_charset != NULL) {
+ memcpy(buf, cnt_info->text.plain_charset, strlen(cnt_info->text.plain_charset));
+ strcat(buf, HTML_EXTENSION_STRING);
+ }
+ else {
+ memcpy(buf, "UTF-8.htm", strlen("UTF-8.htm"));
+ }
+ cnt_info->text.html = EM_SAFE_STRDUP(buf);
+ }
+ else {
+ PARAMETER *param = body->parameter;
+ char charset_string[512];
+
+ if (em_core_get_attribute_value_of_body_part(param, "CHARSET", charset_string, 512, false, &error)) {
+ cnt_info->text.plain_charset = EM_SAFE_STRDUP(charset_string);
+ memcpy(buf, cnt_info->text.plain_charset, strlen(cnt_info->text.plain_charset));
+ }
+ else
+ memcpy(buf, "UTF-8", strlen("UTF-8"));
+
+ cnt_info->text.plain = EM_SAFE_STRDUP(buf);
+ }
+
+ }
+ else if ((body->id != NULL) || ((body->disposition.type != NULL) && ((body->disposition.type[0] == 'i') || (body->disposition.type[0] == 'I')))) { /* body id is exising or disposition type is Inlin */
+ size_t len = 0;
+ if (body->parameter) /* Get actual name of file */ {
+ PARAMETER *param_body = body->parameter;
+ if (!em_core_get_attribute_value_of_body_part(param_body, "NAME", attachment_file_name_source, MAX_PATH, true, &error))
+ em_core_get_attribute_value_of_body_part(param_body, "CHARSET", attachment_file_name_source, MAX_PATH, true, &error);
+ if (!em_core_make_attachment_file_name_with_extension(attachment_file_name_source, body->subtype, attachment_file_name, MAX_PATH, &error)) {
+ EM_DEBUG_EXCEPTION("em_core_make_attachment_file_name_with_extension failed [%d]", error);
+ goto FINISH_OFF;
+ }
+ }
+ else if (body->disposition.type) {
+ PARAMETER *param_disposition = body->disposition.parameter;
+ EM_DEBUG_LOG("body->disposition.type exist");
+ em_core_get_attribute_value_of_body_part(param_disposition, "filename", attachment_file_name_source, MAX_PATH, true, &error);
+ if (!em_core_make_attachment_file_name_with_extension(attachment_file_name_source, body->subtype, attachment_file_name, MAX_PATH, &error)) {
+ EM_DEBUG_EXCEPTION("em_core_make_attachment_file_name_with_extension failed [%d]", error);
+ goto FINISH_OFF;
+ }
+ }
+ else { /* body id is not null but disposition type is null */
+ if ((body->id[0] == '<'))
+ SNPRINTF(attachment_file_name, MAX_PATH, body->id+1); /* fname = em_parse_filename(body->id + 1 */
+ else
+ SNPRINTF(attachment_file_name, MAX_PATH, body->id); /* fname = em_parse_filename(body->id */
+
+ len = strlen(attachment_file_name);
+
+ if ((len > 1) && (attachment_file_name[len-1] == '>'))
+ attachment_file_name[len - 1] = '\0';
+ decoded_filename = em_core_decode_rfc2047_text(attachment_file_name, &error);
+ }
+ EM_DEBUG_LOG("attachment_file_name [%s]", attachment_file_name);
+ if (decoded_filename != NULL)
+ memcpy(buf, decoded_filename, strlen(decoded_filename));
+ else
+ memcpy(buf, attachment_file_name, strlen(attachment_file_name));
+
+ }
+ else if (body->disposition.type != NULL) { /* disposition type is existing and not inline and body_id is nul */
+ PARAMETER *param = body->parameter;
+ if (!em_core_get_attribute_value_of_body_part(param, "NAME", attachment_file_name, MAX_PATH, true, &error))
+ em_core_get_attribute_value_of_body_part(param, "FILENAME", attachment_file_name, MAX_PATH, true, &error);
+ memcpy(buf, attachment_file_name, strlen(attachment_file_name));
+ }
+
+FINISH_OFF:
+ if (err)
+ *err = error;
+
+ EM_SAFE_FREE(decoded_filename);
+ EM_DEBUG_FUNC_END("buf[%s]", buf);
+ return SUCCESS;
+}
+
+
+static PARTLIST *em_core_add_node(PARTLIST *section_list, BODY *body)
+{
+ PARTLIST *temp = (PARTLIST *)malloc(sizeof(PARTLIST));
+
+ if (temp == NULL) {
+ EM_DEBUG_EXCEPTION("PARTLIST node creation failed");
+ return NULL;
+ }
+ temp->body = body;
+ temp->next = NULL;
+
+ if (section_list == NULL)/* first node in lis */ {
+ section_list = temp;
+ }
+ else/* has min 1 nod */ {
+ PARTLIST *t = section_list;
+ while (t->next != NULL) /* go to last nod */ {
+ t = (PARTLIST *) t->next;
+ }
+ t->next = (PART *)temp;/* I think this should be PARTLIST, but why this is PART */
+/*
+in imap-2007e/c-client/mail.h
+PARTLIST{
+ BODY *body;
+ PART *next;
+};
+*/
+ }
+ return section_list;
+}
+
+
+static void em_core_free_section_list(PARTLIST *section_list)
+{
+ PARTLIST *temp = NULL;
+
+ while (section_list != NULL) {
+ temp = (PARTLIST *)section_list->next;
+ EM_SAFE_FREE(section_list);
+ section_list = temp;
+ }
+}
+
+static int em_core_get_section_body_size(char *response, char *section, int *body_size)
+{
+ char *p = NULL;
+ char *s = NULL;
+ int size = 0;
+ if ((p = strstr(response, "BODY[")) /* || (p = strstr(s + 1, "BODY["))*/) {
+
+ p += strlen("BODY[");
+ s = p;
+
+ while (*s != ']')
+ s++;
+
+ *s = '\0';
+
+ strcpy(section, p);
+
+ /* if (strcmp(section, p)) {
+ err = EMF_ERROR_INVALID_RESPONSE;
+ goto FINISH_OFF;
+ }*/
+ p = strstr(s+1, " {");
+ if (p) {
+ p += strlen(" {");
+ s = p;
+
+ while (isdigit(*s))
+ s++;
+
+ *s = '\0';
+
+ size = atoi(p);
+ *body_size = size;
+
+ /* sending progress noti to application.
+ 1. mail_id
+ 2. file_id
+ 3. bodysize
+ */
+
+ }
+ else {
+ return FAILURE;
+ }
+ }
+ else {
+ return FAILURE;
+ }
+ return SUCCESS;
+}
+
+
+static char *em_parse_filename(char *filename)
+{
+ EM_DEBUG_FUNC_BEGIN("filename [%p] ", filename);
+ if (!filename) {
+ EM_DEBUG_EXCEPTION("filename is NULL ");
+ return NULL;
+ }
+
+ char delims[] = "@";
+ char *result = NULL;
+ static char parsed_filename[512] = {0, };
+
+ memset(parsed_filename, 0x00, 512);
+
+ if (!strstr(filename, delims)) {
+ EM_DEBUG_EXCEPTION("FileName doesnot contain @ ");
+ return NULL;
+ }
+
+ result = strtok(filename, delims);
+
+ if (strcasestr(result, ".bmp") || strcasestr(result, ".jpeg") || strcasestr(result, ".png") || strcasestr(result, ".jpg"))
+ sprintf(parsed_filename + strlen(parsed_filename), "%s", result);
+ else
+ sprintf(parsed_filename + strlen(parsed_filename), "%s%s", result, ".jpeg");
+
+ EM_DEBUG_LOG(">>> FileName [ %s ] ", result);
+
+ EM_DEBUG_FUNC_END("parsed_filename [%s] ", parsed_filename);
+ return parsed_filename;
+ }
+
+
+EXPORT_API int em_core_get_attribute_value_of_body_part(PARAMETER *input_param, char *atribute_name, char *output_value, int output_buffer_length, int with_rfc2047_text, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("input_param [%p], atribute_name [%s], output_buffer_length [%d], with_rfc2047_text [%d]", input_param, atribute_name, output_buffer_length, with_rfc2047_text);
+ PARAMETER *temp_param = input_param;
+ char *decoded_value = NULL, *result_value = NULL;
+ int ret = false, err = EMF_ERROR_NONE;
+
+ if(!output_value) {
+ EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ memset(output_value, 0, output_buffer_length);
+
+ while (temp_param) {
+ if (!strcasecmp(temp_param->attribute, atribute_name)) {
+ EM_DEBUG_LOG("temp_param->value [%s]", temp_param->value);
+ if (temp_param->value) {
+ if (with_rfc2047_text) {
+ decoded_value = em_core_decode_rfc2047_text(temp_param->value, &err);
+ if (decoded_value)
+ result_value = decoded_value;
+ else
+ result_value = decoded_value;
+ }
+ else
+ result_value = temp_param->value;
+ }
+ else {
+ EM_DEBUG_EXCEPTION("EMF_ERROR_DATA_NOT_FOUND");
+ err = EMF_ERROR_DATA_NOT_FOUND;
+ goto FINISH_OFF;
+ }
+ EM_DEBUG_LOG("result_value [%s]", result_value);
+ if(result_value) {
+ if(output_buffer_length > strlen(result_value)) {
+ strncpy(output_value, result_value, output_buffer_length);
+ output_value[strlen(result_value)] = NULL_CHAR;
+ ret = true;
+ }
+ else {
+ EM_DEBUG_EXCEPTION("buffer is too short");
+ err = EMF_ERROR_DATA_TOO_LONG;
+ goto FINISH_OFF;
+ }
+ }
+
+ break;
+ }
+ temp_param = temp_param->next;
+ }
+
+FINISH_OFF:
+ EM_SAFE_FREE(decoded_value);
+
+ if(err_code)
+ *err_code = err;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+
+/*
+ *download body part of imap mail (body-text and attachment)
+ */
+static int em_core_get_body_part_imap(MAILSTREAM *stream, int account_id, int mail_id, int msg_uid, BODY *body, struct _m_content_info *cnt_info, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("stream[%p], msg_uid[%d], body[%p], cnt_info[%p], err_code[%p]", stream, msg_uid, body, cnt_info, err_code);
+
+ int err = EMF_ERROR_NONE, ret = -1;
+ struct attachment_info **ai;
+ struct attachment_info *prev_ai = NULL;
+ struct attachment_info *next_ai = NULL;
+ char *savefile = NULL;
+ char *o_data = NULL;
+ char filename[MAX_PATH + 1] = { 0, };
+ char *decoded_filename = NULL;
+ int is_attachment = 0;
+ int o_data_len = 0;
+ char *filename_temp = NULL;
+ char charset_value_buffer[512] = { 0, };
+/* { is_pb */
+ PART *part = NULL;
+ int dec_len;
+ int i = 0;
+ char *sparep = NULL;
+ unsigned short encode = 0;
+ int section_plain = 0;
+ int section_html = 0;
+ int is_pbd = (account_id == 0 && mail_id == 0) ? true : false;
+/* } is_pb */
+
+ EM_DEBUG_LOG("Grab Type [ %d ] ", cnt_info->grab_type);
+
+ /* unknown type */
+ if (body->type > TYPEOTHER) { /* unknown type */
+ EM_DEBUG_EXCEPTION("Unknown type.");
+ err = EMF_ERROR_NOT_SUPPORTED;
+ goto FINISH_OFF;
+ }
+
+ if (NULL == body->subtype) {
+ EM_DEBUG_LOG("body->subtype is null. "); /* not exceptional case */
+ if (err_code != NULL)
+ *err_code = EMF_ERROR_INVALID_PARAM;
+ return FAILURE;
+ }
+
+ if (is_pbd) {
+ if (!em_core_get_temp_file_name(&o_data, &err) || !o_data) {
+ EM_DEBUG_EXCEPTION("em_core_get_temp_file_name failed [%d]", err);
+ if (err_code != NULL)
+ *err_code = err;
+ return FAILURE;
+ }
+
+
+ if (body->subtype[0] == 'P') { /* Sub type is PLAIN_TEX */
+ if (cnt_info->text.plain != NULL)
+ EM_SAFE_FREE(o_data);
+ }
+
+ if (body->type == TYPETEXT && body->subtype &&
+ (!body->disposition.type || (body->disposition.type && (body->disposition.type[0] == 'i' || body->disposition.type[0] == 'I')))) {
+ if (body->subtype[0] == 'H') /* HTM */
+ cnt_info->text.html = o_data;
+ else
+ cnt_info->text.plain = o_data;
+
+ memset(charset_value_buffer, 0, 512);
+
+ if (em_core_get_attribute_value_of_body_part(body->parameter, "CHARSET", charset_value_buffer, 512, true, &err)) {
+ cnt_info->text.plain_charset = EM_SAFE_STRDUP(charset_value_buffer);
+ EM_DEBUG_LOG(">>>>> CHARSET [%s] ", filename);
+ }
+ }
+ } /* is_pbd */
+
+ if ((body->id) && strlen(body->id) > 1) { /* if Content-ID or Content-Location exists, it is inline contents */
+ EM_DEBUG_LOG("body->id exist");
+ size_t len = 0;
+ /* Get actual name of file - fix for inline images to be stored with actual names and not .jpeg */
+ if (body->parameter) {
+ PARAMETER *param1 = body->parameter;
+ while (param1) {
+ EM_DEBUG_LOG("param1->attribute - %s ", param1->attribute);
+ if (!strcasecmp(param1->attribute, "NAME")) { /* attribute is "NAME" */
+ char *extcheck = NULL;
+
+ if (param1->value) {
+ decoded_filename = em_core_decode_rfc2047_text(param1->value, &err);
+ strncpy(filename, decoded_filename, MAX_PATH);
+ EM_SAFE_FREE(decoded_filename);
+ }
+ EM_DEBUG_LOG(">>>>> FILENAME [%s] ", filename);
+ extcheck = strchr(filename, '.');
+
+ if (extcheck)
+ EM_DEBUG_LOG(">>>> Extension Exist in the Attachment [ %s ] ", extcheck);
+ else /* No extension attached , So add the Extension based on the subtyp */ {
+ if (body->subtype) {
+ strcat(filename, ".");
+ strcat(filename, body->subtype);
+ EM_DEBUG_LOG(">>>>> FILENAME Identified the Extension [%s] ", filename);
+ }
+ else
+ EM_DEBUG_EXCEPTION("UnKnown Extesnsion : _ (");
+
+ }
+
+ break;
+ }
+ param1 = param1->next;
+ }
+
+ }
+ else if (body->disposition.type) {
+ PARAMETER *param = body->disposition.parameter;
+
+ while (param) {
+ EM_DEBUG_LOG(">>>>> body->disposition.parameter->attribute [ %s ] ", param->attribute);
+ EM_DEBUG_LOG(">>>>> body->disposition.parameter->value [ %s ] ", param->value);
+
+ /* attribute is "filename" */
+ if (!strcasecmp(param->attribute, "filename")) {
+ decoded_filename = em_core_decode_rfc2047_text(param->value, &err);
+ strncpy(filename, decoded_filename, MAX_PATH);
+ EM_SAFE_FREE(decoded_filename);
+ EM_DEBUG_LOG(">>>>> FILENAME [%s] ", filename);
+ break;
+ }
+
+ param = param->next;
+ }
+ }
+ else {
+ if ((body->id[0] == '<'))
+ SNPRINTF(filename, MAX_PATH, body->id+1);
+ else
+ SNPRINTF(filename, MAX_PATH, body->id);
+
+ len = strlen(filename);
+
+ if ((len > 1) && (filename[len-1] == '>'))
+ filename[len-1] = '\0';
+ }
+ /* is_attachment = 1; */
+ is_attachment = 0;
+ }
+ else if (body->location) {
+ EM_DEBUG_LOG("body->location exist");
+ is_attachment = 1;
+ decoded_filename = em_core_decode_rfc2047_text(body->location, &err);
+ strncpy(filename, decoded_filename, MAX_PATH);
+ EM_SAFE_FREE(decoded_filename);
+ EM_DEBUG_LOG("body->location [%s]", body->location);
+ }
+ else if (is_pbd && (strncmp(body->subtype, "RFC822", strlen("RFC822")) == 0) && (cnt_info->grab_type == 0 || cnt_info->grab_type & GRAB_TYPE_ATTACHMENT)) {
+ EM_DEBUG_LOG("Beause subtype is RFC822. This is ttachment");
+ is_attachment = 1;
+
+ if (cnt_info->grab_type == 0) {
+ if ((body->nested.msg != NULL) && (body->nested.msg->env != NULL) && (body->nested.msg->env->subject != NULL)) {
+ decoded_filename = em_core_decode_rfc2047_text(body->nested.msg->env->subject, &err);
+ strncpy(filename, decoded_filename, MAX_PATH);
+ EM_SAFE_FREE(decoded_filename);
+ }
+ else
+ strncpy(filename, "Unknown <message/rfc822>", MAX_PATH);
+ }
+ else if (cnt_info->grab_type & GRAB_TYPE_ATTACHMENT) {
+ BODY *temp_body = NULL;
+ if (body->nested.msg->env->subject != NULL) {
+ int i = 0;
+ int subject_count = 0;
+ if (g_str_has_prefix(body->nested.msg->env->subject, "= ? ") && g_str_has_suffix(body->nested.msg->env->subject, " ? = "))
+ strncpy(filename, "unknown", MAX_PATH);
+ else {
+ for (subject_count = 0; body->nested.msg->env->subject[subject_count] != '\0' ; subject_count++) {
+ if (body->nested.msg->env->subject[subject_count] != ':' &&
+ body->nested.msg->env->subject[subject_count] != ';' &&
+ body->nested.msg->env->subject[subject_count] != '*' &&
+ body->nested.msg->env->subject[subject_count] != '?' &&
+ body->nested.msg->env->subject[subject_count] != '\"' &&
+ body->nested.msg->env->subject[subject_count] != '<' &&
+ body->nested.msg->env->subject[subject_count] != '>' &&
+ body->nested.msg->env->subject[subject_count] != '|' &&
+ body->nested.msg->env->subject[subject_count] != '/') {
+ filename[i] = body->nested.msg->env->subject[subject_count];
+ i++;
+ }
+ else
+ continue;
+ }
+ }
+ }
+ else
+ strncpy(filename, "Unknown", MAX_PATH);
+
+ body = ((MESSAGE *)body->nested.msg)->body;
+ part = body->nested.part;
+
+ if ((body->subtype[0] == 'P') || (body->subtype[0] == 'H'))
+ temp_body = body;
+ else if (part != NULL) {
+ temp_body = &(part->body);
+ if ((temp_body->subtype[0] == 'P' || temp_body->subtype[0] == 'H') && part->next != NULL) {
+ part = part->next;
+ temp_body = &(part->body);
+ }
+ }
+
+ if (temp_body) {
+ if (temp_body->subtype[0] == 'P')
+ section_plain = 1;
+ else if (temp_body->subtype[0] == 'H')
+ section_html = 1;
+
+ sparep = temp_body->sparep;
+ encode = temp_body->encoding;
+ }
+
+ }
+ }
+ else if (body->disposition.type) /* if disposition exists, get filename from disposition parameter */ { /* "attachment" or "inline" or etc.. */
+ EM_DEBUG_LOG("body->disposition.type exist");
+ is_attachment = 1;
+
+ if (em_core_get_attribute_value_of_body_part(body->disposition.parameter, "filename", filename, MAX_PATH, true, &err))
+ EM_DEBUG_LOG(">>>>> FILENAME [%s] ", filename);
+
+ if (!*filename) { /* If the part has no filename, it may be report ms */
+ if ((body->disposition.type[0] == 'i' || body->disposition.type[0] == 'I') && body->parameter && body->parameter->attribute && strcasecmp(body->parameter->attribute, "NAME"))
+ is_attachment = 0;
+ else if (body->parameter) /* Fix for the MMS attachment File name as unknown */ {
+ char *extcheck = NULL;
+
+ if (em_core_get_attribute_value_of_body_part(body->parameter, "NAME", filename, MAX_PATH, true, &err))
+ EM_DEBUG_LOG("NAME [%s] ", filename);
+
+ extcheck = strchr(filename, '.');
+
+ if (extcheck)
+ EM_DEBUG_LOG(">>>> Extension Exist in the Attachment [ %s ] ", extcheck);
+ else { /* No extension attached , So add the Extension based on the subtype */
+ if (body->subtype) {
+ if (strlen(filename) + strlen(body->subtype) + 1 < MAX_PATH) {
+ strcat(filename, ".");
+ strcat(filename, body->subtype);
+ }
+ EM_DEBUG_LOG(">>>>> FILENAME Identified the Extension [%s] ", filename);
+ }
+ else
+ EM_DEBUG_EXCEPTION("UnKnown Extesnsion : _ (");
+ }
+
+ }
+ else
+ strncpy(filename, "unknown", MAX_PATH);
+ }
+ else {
+ if ((body->disposition.type[0] == 'i' || body->disposition.type[0] == 'I'))
+ is_attachment = 0;
+ }
+ }
+
+ /* if (!is_pbd) */ {
+ EM_DEBUG_LOG("filename [%s]", filename);
+ if (*filename) {
+ decoded_filename = em_core_decode_rfc2047_text(filename, &err);
+ strncpy(filename, decoded_filename, MAX_PATH);
+ EM_SAFE_FREE(decoded_filename);
+ filename_temp = em_parse_filename(filename);
+ if (filename_temp) {
+ strncpy(filename, filename_temp, MAX_PATH);
+ EM_DEBUG_LOG("filename [%s]", filename);
+ }
+ }
+ }
+ EM_DEBUG_LOG("is_attachment [%d]", is_attachment);
+
+ if (!is_attachment) { /* Text or RFC822 Message */
+ EM_DEBUG_LOG("Multipart is not attachment, body->type = %d", body->type);
+ if ((cnt_info->grab_type & GRAB_TYPE_TEXT) && (body->type == TYPEMESSAGE || body->type == TYPETEXT || body->type == TYPEIMAGE)) {
+ if (is_pbd)
+ return SUCCESS;
+ else { /* fetch body */
+ if (!em_core_get_temp_file_name(&o_data, &err)) {
+ EM_DEBUG_EXCEPTION("em_core_get_temp_file_name failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ if (!imap_mail_write_body_to_file(stream, account_id, mail_id, 0, o_data, msg_uid, body->sparep, body->encoding, &o_data_len, body->subtype, &err)) {
+ EM_DEBUG_EXCEPTION("imap_mail_write_body_to_file failed [%d]", err);
+ goto FINISH_OFF;
+ }
+ }
+ }
+
+ switch (body->type) {
+ case TYPETEXT:
+ EM_DEBUG_LOG("TYPETEXT");
+ if (body->subtype[0] == 'H')
+ cnt_info->text.html = o_data;
+ else {
+ cnt_info->text.plain = o_data;
+ memset(charset_value_buffer, 0, 512);
+ if (em_core_get_attribute_value_of_body_part(body->parameter, "CHARSET", charset_value_buffer, 512, true, &err))
+ cnt_info->text.plain_charset = EM_SAFE_STRDUP(charset_value_buffer);
+ }
+ break;
+ case TYPEIMAGE:
+ case TYPEAPPLICATION:
+ /* Inline Content - suspect of crash on partial body download */
+ if (!is_pbd) {
+ EM_DEBUG_LOG("TYPEIMAGE or TYPEAPPLICATION : inline content");
+ ai = &(cnt_info->file);
+
+ dec_len = body->size.bytes;
+ if ((cnt_info->grab_type & GRAB_TYPE_ATTACHMENT) &&
+ (cnt_info->grab_type & GRAB_TYPE_TEXT)) { /* it is 'download all */
+ only_body_download = false;
+ cnt_info->file_no = 1;
+ }
+
+ /* add attachment info to content info */
+ if (!(*ai = em_core_malloc(sizeof(struct attachment_info)))) {
+ EM_DEBUG_EXCEPTION("em_core_malloc failed...");
+ if (err_code != NULL)
+ *err_code = EMF_ERROR_OUT_OF_MEMORY;
+ return FAILURE;
+ }
+
+ memset(*ai, 0, sizeof(struct attachment_info));
+
+ if (((body->id) || (body->location)) && body->type == TYPEIMAGE)
+ (*ai)->type = 1; /* inline */
+ else
+ (*ai)->type = 2; /* attachment */
+
+ (*ai)->name = EM_SAFE_STRDUP(filename);
+ (*ai)->size = body->size.bytes;
+ (*ai)->save = o_data;
+ EM_DEBUG_LOG("file->name[%s], file->size[%d], file->save[%s], file->content_id[%s]", cnt_info->file->name, cnt_info->file->size, cnt_info->file->save);
+#ifdef __ATTACHMENT_OPTI__
+ (*ai)->encoding = body->encoding;
+ if (body->sparep)
+ (*ai)->section = EM_SAFE_STRDUP(body->sparep);
+
+ EM_DEBUG_LOG(" Encoding - %d Section No - %s ", (*ai)->encoding, (*ai)->section);
+#endif
+ /*
+ if (prev_ai == NULL) {
+ (*ai)->next = NULL;
+ cnt_info->file = (*ai);
+ }
+ else {
+ prev_ai->next = (*ai);
+ (*ai)->next = NULL;
+ }
+ */
+ }
+ break;
+
+ case TYPEMESSAGE: /* RFC822 Message */
+ EM_DEBUG_EXCEPTION("MESSAGE/RFC822");
+ err = EMF_ERROR_NOT_SUPPORTED;
+ goto FINISH_OFF;
+
+ default:
+ EM_DEBUG_EXCEPTION("Unknown type. body->type [%d]", body->type);
+ err = EMF_ERROR_NOT_SUPPORTED;
+ goto FINISH_OFF;
+ }
+
+ stream->text.data = NULL; /* ? ? ? ? ? ? ? ? */
+ }
+ else { /* Attachment */
+ prev_ai = NULL;
+ next_ai = NULL;
+ ai = &cnt_info->file;
+ EM_DEBUG_LOG(" ai - %p ", (*ai));
+
+ if ((body->id) || (body->location)) {
+ /* For Inline content append to the end */
+ for (i = 1; *ai; ai = &(*ai)->next)
+ i++;
+ }
+ else { /* For attachment - search till Inline content found and insert before inline */
+ for (i = 1; *ai; ai = &(*ai)->next) {
+ if ((*ai)->type == 1) {
+ /* Means inline image */
+ EM_DEBUG_LOG("Found Inline Content ");
+ next_ai = (*ai);
+ break;
+ }
+ i++;
+ prev_ai = (*ai);
+ }
+ }
+
+ EM_DEBUG_LOG("i - %d next_ai - %p prev_ai - %p", i, next_ai, prev_ai);
+
+ if ((cnt_info->grab_type & GRAB_TYPE_ATTACHMENT) &&
+ (cnt_info->grab_type & GRAB_TYPE_TEXT)) { /* it is 'download all */
+ EM_DEBUG_LOG("Download All");
+ only_body_download = false;
+ cnt_info->file_no = 1;
+ i = 1;
+ }
+ /* meaningless code */
+ dec_len = body->size.bytes;
+
+ if (body->id)
+ EM_DEBUG_LOG("BODY ID [ %s ]", body->id);
+ else
+ EM_DEBUG_LOG("BODY ID IS NULL");
+
+ EM_DEBUG_LOG("i : %d, cnt_info->file_no : %d", i, cnt_info->file_no);
+
+ if (
+ ((cnt_info->grab_type & GRAB_TYPE_ATTACHMENT) && i == cnt_info->file_no) || /* Is it correct attachment */
+ (((body->id) || (body->location)) && (cnt_info->grab_type & GRAB_TYPE_TEXT)) /* Is it inline contents */
+ ) {
+ /* fetch attachment */
+ EM_DEBUG_LOG("attachment (enc) : %s %ld bytes", filename, body->size.bytes);
+ EM_DEBUG_LOG(">>>>> ONLY BODY DOWNLOAD [ %d ] ", only_body_download);
+
+ if (only_body_download == false) {
+ if (!em_core_get_temp_file_name(&savefile, &err)) {
+ EM_DEBUG_EXCEPTION("em_core_get_temp_file_name failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ if (!is_pbd) {
+ if (!imap_mail_write_body_to_file(stream, account_id, mail_id, cnt_info->file_no, savefile, msg_uid, body->sparep, body->encoding, &dec_len, body->subtype, &err)) {
+ EM_DEBUG_EXCEPTION("imap_mail_write_body_to_file failed [%d]", err);
+ goto FINISH_OFF;
+ }
+ }
+ }
+ }
+
+ EM_DEBUG_LOG("attachment (dec) : %s %d bytes", filename, dec_len);
+
+ /* add attachment info to content inf */
+ if (!(*ai = em_core_malloc(sizeof(struct attachment_info)))) {
+ EM_DEBUG_EXCEPTION("em_core_malloc failed...");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ memset((*ai), 0x00, sizeof(struct attachment_info));
+ if ((body->id) || (body->location))
+ (*ai)->type = 1;
+ else
+ (*ai)->type = 2;
+
+ if (is_pbd) {
+ if (savefile != NULL) {
+ if (section_plain == 1)
+ strcat(filename, ".txt");
+ if (section_html == 1)
+ strcat(filename, ".html");
+ section_plain = 0;
+ section_html = 0;
+ }
+ } /* is_pbd */
+ (*ai)->name = EM_SAFE_STRDUP(filename);
+ (*ai)->size = dec_len;
+ (*ai)->save = savefile;
+
+ #ifdef __ATTACHMENT_OPTI__
+ (*ai)->encoding = body->encoding;
+ if (body->sparep)
+ (*ai)->section = EM_SAFE_STRDUP(body->sparep);
+
+ EM_DEBUG_LOG(" Encoding - %d Section No - %s ", (*ai)->encoding, (*ai)->section);
+ #endif
+ if (body->type == TYPEAPPLICATION) {
+ if (!strcasecmp(body->subtype, MIME_SUBTYPE_DRM_OBJECT))
+ (*ai)->drm = EMF_ATTACHMENT_DRM_OBJECT;
+ else if (!strcasecmp(body->subtype, MIME_SUBTYPE_DRM_RIGHTS))
+ (*ai)->drm = EMF_ATTACHMENT_DRM_RIGHTS;
+ else if (!strcasecmp(body->subtype, MIME_SUBTYPE_DRM_DCF))
+ (*ai)->drm = EMF_ATTACHMENT_DRM_DCF;
+ }
+
+ /* All inline images information are stored at the end of list */
+ if ((*ai)->type != 1 && next_ai != NULL) {
+ /* Means next_ai points to the inline attachment info structure */
+ if (prev_ai == NULL) {
+ /* First node is inline attachment */
+ (*ai)->next = next_ai;
+ cnt_info->file = (*ai);
+ }
+ else {
+ prev_ai->next = (*ai);
+ (*ai)->next = next_ai;
+ }
+ }
+ }
+
+ ret = 0;
+FINISH_OFF:
+ if (err_code)
+ *err_code = err;
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+/* get body-part in nested part */
+
+static int em_core_get_allnested_part(MAILSTREAM *stream, int account_id, int mail_id, int msg_uid, BODY *body, struct _m_content_info *cnt_info, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("stream[%p], msg_uid[%d], body[%p], cnt_info[%p], err_code[%p]", stream, msg_uid, body, cnt_info, err_code);
+ PART *part_child = body->nested.part;
+
+ while (part_child) {
+ if (em_core_get_body(stream, account_id, mail_id, msg_uid, &part_child->body, cnt_info, err_code) < 0)
+ return FAILURE;
+
+ part_child = part_child->next;
+ }
+
+ EM_DEBUG_FUNC_END();
+ return SUCCESS;
+}
+
+/* get body-part in alternative multiple part */
+static int em_core_get_alternative_multi_part(MAILSTREAM *stream, int account_id, int mail_id, int msg_uid, BODY *body, struct _m_content_info *cnt_info, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("stream[%p], msg_uid[%d], body[%p], cnt_info[%p], err_code[%p]", stream, msg_uid, body, cnt_info, err_code);
+
+ PART *part_child = body->nested.part;
+
+ /* find the best sub part we can show */
+ while (part_child) {
+ if (em_core_get_body(stream, account_id, mail_id, msg_uid, &part_child->body, cnt_info, err_code) < 0)
+ return FAILURE;
+
+ part_child = part_child->next;
+ }
+ EM_DEBUG_FUNC_END();
+ return SUCCESS;
+}
+
+/* get body part in signed multiple part */
+static int em_core_get_signed_multi_part(MAILSTREAM *stream, int account_id, int mail_id, int msg_uid, BODY *body, struct _m_content_info *cnt_info, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("stream[%p], msg_uid[%d], body[%p], cnt_info[%p], err_code[%p]", stream, msg_uid, body, cnt_info, err_code);
+ EM_DEBUG_FUNC_END();
+ return SUCCESS;
+}
+
+/* get body part in encrypted multiple part */
+static int em_core_get_encrypted_multi_part(MAILSTREAM *stream, int account_id, int mail_id, int msg_uid, BODY *body, struct _m_content_info *cnt_info, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("stream[%p], msg_uid[%d], body[%p], cnt_info[%p], err_code[%p]", stream, msg_uid, body, cnt_info, err_code);
+ EM_DEBUG_FUNC_END();
+ return SUCCESS;
+}
+
+/* get body part in multiple part */
+static int em_core_get_multi_part(MAILSTREAM *stream, int account_id, int mail_id, int msg_uid, BODY *body, struct _m_content_info *cnt_info, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("stream[%p], msg_uid[%d], body[%p], cnt_info[%p], err_code[%p]", stream, msg_uid, body, cnt_info, err_code);
+
+ if (!body) {
+ EM_DEBUG_EXCEPTION("Invalid Parameter.");
+ if (err_code)
+ *err_code = EMF_ERROR_INVALID_PARAM;
+ return FAILURE;
+ }
+
+ switch (body->subtype[0]) {
+ case 'A': /* ALTERNATIVE */
+ EM_DEBUG_LOG("body->subtype[0] = ALTERNATIVE");
+ return em_core_get_alternative_multi_part(stream, account_id, mail_id, msg_uid, body, cnt_info, err_code);
+
+ case 'S': /* SIGNED */
+ EM_DEBUG_LOG("body->subtype[0] = SIGNED");
+ return em_core_get_signed_multi_part(stream, account_id, mail_id, msg_uid, body, cnt_info, err_code);
+
+ case 'E': /* ENCRYPTED */
+ EM_DEBUG_LOG("body->subtype[0] = ENCRYPTED");
+ return em_core_get_encrypted_multi_part(stream, account_id, mail_id, msg_uid, body, cnt_info, err_code);
+
+ default: /* process all unknown as MIXED (according to the RFC 2047) */
+ EM_DEBUG_LOG("body->subtype[0] = [%c].", body->subtype[0]);
+ return em_core_get_allnested_part(stream, account_id, mail_id, msg_uid, body, cnt_info, err_code);
+ }
+
+ if (body->id)
+ EM_DEBUG_LOG("em_core_get_multi_part BODY ID [%s].", body->id);
+ else
+ EM_DEBUG_LOG("em_core_get_multi_part BODY ID NULL.");
+ EM_DEBUG_FUNC_END();
+ return SUCCESS;
+}
+
+/* get body data by body structure */
+/* if POP3, ignored */
+EXPORT_API int em_core_get_body(MAILSTREAM *stream, int account_id, int mail_id, int msg_uid, BODY *body, struct _m_content_info *cnt_info, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("stream[%p], msg_uid[%d], body[%p], cnt_info[%p], err_code[%p]", stream, msg_uid, body, cnt_info, err_code);
+
+ if (!stream || !body || !cnt_info) {
+ EM_DEBUG_EXCEPTION("Invalid parameter");
+
+ if (err_code != NULL)
+ *err_code = EMF_ERROR_INVALID_PARAM;
+ return FAILURE;
+ }
+
+ EM_DEBUG_LOG("body->type [%d]", body->type);
+
+ switch (body->type) {
+ case TYPEMULTIPART:
+ return em_core_get_multi_part(stream, account_id, mail_id, msg_uid, body, cnt_info, err_code);
+
+ case TYPEMESSAGE: /* not support */
+ if (strcasecmp(body->subtype, "RFC822") == 0)
+ return em_core_get_body_part_imap(stream, account_id, mail_id, msg_uid, body, cnt_info, err_code);
+ break;
+
+ case TYPETEXT:
+ case TYPEAPPLICATION:
+ case TYPEAUDIO:
+ case TYPEIMAGE:
+ case TYPEVIDEO:
+ case TYPEMODEL:
+ case TYPEOTHER:
+ /* exactly, get a pure body part (text and attachment */
+ return em_core_get_body_part_imap(stream, account_id, mail_id, msg_uid, body, cnt_info, err_code);
+
+ default:
+ break;
+ }
+ EM_DEBUG_FUNC_END();
+ return SUCCESS;
+}
+
+/* get body structure */
+EXPORT_API int em_core_get_body_structure(MAILSTREAM *stream, int msg_uid, BODY **body, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("stream[%p], msg_uid[%d], body[%p], err_code[%p]", stream, msg_uid, body, err_code);
+
+ EM_IF_NULL_RETURN_VALUE(stream, false);
+ EM_IF_NULL_RETURN_VALUE(body, false);
+
+#ifdef __FEATURE_HEADER_OPTIMIZATION__
+ ENVELOPE *env = mail_fetch_structure(stream, msg_uid, body, FT_UID | FT_PEEK | FT_NOLOOKAHEAD, 1);
+#else
+ ENVELOPE *env = mail_fetch_structure(stream, msg_uid, body, FT_UID | FT_PEEK | FT_NOLOOKAHEAD);
+#endif
+ if (!env) {
+ if (err_code)
+ *err_code = EMF_ERROR_MAIL_NOT_FOUND_ON_SERVER;
+ EM_DEBUG_EXCEPTION("mail_fetch_structure failed");
+ return FAILURE;
+ }
+
+#ifdef FEATURE_CORE_DEBUG
+ _print_body(*body, true); /* shasikala.p@partner.samsung.co */
+#endif
+ EM_DEBUG_FUNC_END();
+ return SUCCESS;
+}
+
+int em_core_set_fetch_part_section(BODY *body, char *section_pfx, int section_subno, int enable_inline_list, int *total_mail_size, int *err_code);
+
+/* set body section to be fetched */
+EXPORT_API int em_core_set_fetch_body_section(BODY *body, int enable_inline_list, int *total_mail_size, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("body[%p], err_code[%p]", body, err_code);
+
+ if (!body) {
+ EM_DEBUG_EXCEPTION("body [%p]", body);
+ if (err_code != NULL)
+ *err_code = EMF_ERROR_INVALID_PARAM;
+ return FAILURE;
+ }
+
+ body->id = cpystr("1"); /* top level bod */
+
+ g_inline_count = 0;
+ EM_SAFE_FREE(g_inline_list);
+ em_core_set_fetch_part_section(body, (char *)NULL, 0, enable_inline_list, total_mail_size, err_code);
+
+ if (body->id && body)
+ EM_DEBUG_LOG(">>>>> FILE NAME [ %s ] ", body->id);
+ else
+ EM_DEBUG_LOG(">>>>> BODY NULL ", body->id);
+
+ EM_DEBUG_FUNC_END();
+ return SUCCESS;
+}
+
+/* set part section of body to be fetched */
+int em_core_set_fetch_part_section(BODY *body, char *section_pfx, int section_subno, int enable_inline_list, int *total_mail_size, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("body[%p], section_pfx[%s], section_subno[%d], err_code[%p]", body, section_pfx, section_subno, err_code);
+
+ PART *part = NULL;
+ char section[64] = {0x00, };
+
+ /* multipart doesn't have a row to itself */
+ if (body->type == TYPEMULTIPART) {
+ /* if not first time, extend prefix */
+ if (section_pfx) {
+ SNPRINTF(section, sizeof(section), "%s%d.", section_pfx, ++section_subno);
+ }
+ else {
+ section[0] = '\0';
+ }
+
+ for (section_subno = 0, part = body->nested.part; part; part = part->next)
+ em_core_set_fetch_part_section(&part->body, section, section_subno++, enable_inline_list, total_mail_size, err_code);
+ }
+ else {
+ if (!section_pfx) /* dummy prefix if top level */
+ section_pfx = "";
+
+ SNPRINTF(section, sizeof(section), "%s%d", section_pfx, ++section_subno);
+
+ if (enable_inline_list && ((body->disposition.type && (body->disposition.type[0] == 'i' || body->disposition.type[0] == 'I')) ||
+ (!body->disposition.type && body->id))) {
+ BODY **temp = NULL;
+ temp = realloc(g_inline_list, sizeof(BODY *) *(g_inline_count + 1));
+ if (NULL != temp) {
+ memset(temp+g_inline_count, 0x00, sizeof(BODY *));
+ g_inline_list = temp;
+ g_inline_list[g_inline_count] = body;
+ g_inline_count++;
+ temp = NULL;
+ }
+ else {
+ EM_DEBUG_EXCEPTION("realloc fails");
+ }
+
+ EM_DEBUG_LOG("Update g_inline_list with inline count [%d]", g_inline_count);
+ }
+
+ /* if ((total_mail_size != NULL) && !(body->disposition.type && (body->disposition.type[0] == 'a' || body->disposition.type[0] == 'A')) */
+ if (total_mail_size != NULL) {
+ *total_mail_size = *total_mail_size + (int)body->size.bytes;
+ EM_DEBUG_LOG("body->size.bytes [%d]", body->size.bytes);
+ }
+
+ /* encapsulated message ? */
+ if ((body->type == TYPEMESSAGE) && !strcasecmp(body->subtype, "RFC822") && (body = ((MESSAGE *)body->nested.msg)->body)) {
+ if (body->type == TYPEMULTIPART) {
+ section[0] = '\0';
+ em_core_set_fetch_part_section(body, section, section_subno-1, enable_inline_list, total_mail_size, err_code);
+ }
+ else { /* build encapsulation prefi */
+ SNPRINTF(section, sizeof(section), "%s%d.", section_pfx, section_subno);
+ em_core_set_fetch_part_section(body, section, 0, enable_inline_list, total_mail_size, err_code);
+ }
+ }
+ else {
+ /* set body section */
+ if (body)
+ body->sparep = cpystr(section);
+ }
+ }
+ EM_DEBUG_FUNC_END();
+ return SUCCESS;
+}
+
+
+static void parse_file_path_to_filename(char *src_string, char **out_string)
+{
+ char *token = NULL;
+ char *filepath = NULL;
+ char *str = NULL;
+ char *prev1 = NULL;
+ char *prev2 = NULL;
+
+ filepath = EM_SAFE_STRDUP(src_string);
+ token = strtok_r(filepath, "/", &str);
+
+ do {
+ prev2 = prev1;
+ prev1 = token;
+ } while ((token = strtok_r(NULL , "/", &str)));
+
+ *out_string = EM_SAFE_STRDUP(prev1);
+ EM_SAFE_FREE(filepath);
+}
+
+static char *em_core_decode_rfc2047_word(char *encoded_word, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("encoded_word[%s], err_code[%p]", encoded_word, err_code);
+
+ int err = EMF_ERROR_NONE;
+ int base64_encoded = false, length = 0;
+ SIZEDTEXT src = { NULL, 0 };
+ SIZEDTEXT dst = { NULL, 0 };
+ gchar *charset = NULL, *encoded_text = NULL;
+ char *decoded_text = NULL, *decoded_word = NULL;
+ char *current = NULL, *start = NULL, *end = NULL;
+ char *buffer = (char*) em_core_malloc(strlen(encoded_word) * 2 + 1);
+
+ if (buffer == NULL) {
+ EM_DEBUG_EXCEPTION("Memory allocation fail");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ strcpy(buffer, "");
+
+ /* encoding format : =?charset?encoding?encoded-text ?= */
+ /* charset : UTF-8, EUC-KR, ... */
+ /* encoding : b/B (BASE64), q/Q (QUOTED-PRINTABLE) */
+ current = encoded_word;
+
+ while (*current != NULL_CHAR) {
+ /* search next */
+ start = strstr(current, "=?"); /* start of encoding */
+ end = strstr(current, "?="); /* end of encoding */
+
+#ifdef FEATURE_CORE_DEBUG
+ EM_DEBUG_LOG("current[%p][%s], start[%p][%s], end[%p][%s]", current, current, start, start, end, end);
+#endif
+ if (start != NULL) {
+ if (current != start) { /* copy the string between current and start to buffer */
+ strncat(buffer, current, start - current);
+ current = start;
+#ifdef FEATURE_CORE_DEBUG
+ EM_DEBUG_LOG("1 - Buffer[%s]", buffer);
+#endif
+ }
+
+ if (end) { /* decode text between start and end */
+ char *p = strstr(start, "?b?");
+
+ if (p || (p = strstr(start, "?B?"))) /* BASE64 */
+ base64_encoded = true;
+ else {
+ p = strstr(start, "?q?");
+
+ if (p || (p = strstr(start, "?Q?"))) /* QUOTED-PRINTABLE */
+ base64_encoded = false;
+ else {
+ EM_DEBUG_EXCEPTION("unknown encoding found...");
+
+ err = EMF_ERROR_UNKNOWN;
+ goto FINISH_OFF;
+ }
+ }
+
+ if (base64_encoded) { /* BASE64 */
+ charset = g_strndup(start + 2, p - (start + 2));
+ encoded_text = g_strndup(p + 3, end - (p + 3));
+ }
+ else { /* QUOTED-PRINTABLE */
+ charset = g_strndup(start + 2, p - (start + 2));
+ if (*(p+3) == '=') { /* encoded text might start with '='. ex) '?Q?=E0' */
+ end = strstr(p+3, "?="); /* find new end flag */
+ if (end) {
+ encoded_text = g_strndup(p + 3, end - (p + 3));
+ }
+ else { /* end flag is not found */
+ EM_DEBUG_EXCEPTION("em_core_decode_rfc2047_word decoding error : '?=' is not found...");
+
+ err = EMF_ERROR_UNKNOWN;
+ goto FINISH_OFF;
+ }
+ }
+ else {
+ encoded_text = g_strndup(p + 3, end - (p + 3));
+ }
+ }
+
+#ifdef FEATURE_CORE_DEBUG
+ EM_DEBUG_LOG("\t >>>>>>>>>>>>>>> CHARSET[%s]", charset);
+ EM_DEBUG_LOG("\t >>>>>>>>>>>>>>> ENCODED_TEXT[%s]", encoded_text);
+#endif
+
+ unsigned long len = 0;
+ if (encoded_text != NULL) {
+ if (base64_encoded == true) {
+ if (!(decoded_text = (char *)rfc822_base64((unsigned char *)encoded_text, strlen(encoded_text), &len))) {
+ EM_DEBUG_EXCEPTION("rfc822_base64 falied...");
+ goto FINISH_OFF;
+ }
+ }
+ else {
+ g_strdelimit(encoded_text, "_", ' ');
+
+ if (!(decoded_text = (char *)rfc822_qprint((unsigned char *)encoded_text, strlen(encoded_text), &len))) {
+ EM_DEBUG_EXCEPTION("rfc822_base64 falied...");
+ goto FINISH_OFF;
+ }
+ }
+
+ src.data = (unsigned char *)decoded_text;
+ src.size = strlen(decoded_text);
+
+ if (!utf8_text(&src, charset, &dst, 0)) {
+ EM_DEBUG_EXCEPTION("utf8_text falied...");
+ strncat(buffer, (char *)src.data, src.size); /* Eventhough failed to decode, downloading should go on. Kyuho Jo */
+ }
+ else
+ strncat(buffer, (char *)dst.data, dst.size);
+#ifdef FEATURE_CORE_DEBUG
+ EM_DEBUG_LOG("2 - Buffer[%s]", buffer);
+#endif
+
+ /* free all of the temp variables */
+ if (dst.data != NULL && dst.data != src.data)
+ EM_SAFE_FREE(dst.data);
+
+ EM_SAFE_FREE(decoded_text);
+
+ g_free(encoded_text);
+ encoded_text = NULL;
+ }
+ if (charset != NULL) {
+ g_free(charset);
+ charset = NULL;
+ }
+
+ current = end + 2; /* skip '?=' */
+ }
+ else {
+ /* unencoded text */
+ length = strlen(start);
+ strncat(buffer, start, length);
+ current = start + length;
+#ifdef FEATURE_CORE_DEBUG
+ EM_DEBUG_LOG("3 - Buffer[%s]", buffer);
+#endif
+ }
+ }
+ else {
+ /* unencoded text */
+ length = strlen(current);
+ strncat(buffer, current, length);
+ current = current + length;
+#ifdef FEATURE_CORE_DEBUG
+ EM_DEBUG_LOG("4 - Buffer[%s]", buffer);
+#endif
+ }
+ }
+
+ decoded_word = EM_SAFE_STRDUP(buffer);
+
+#ifdef FEATURE_CORE_DEBUG
+ EM_DEBUG_LOG(">>>>>>>>>>>>>>> DECODED_WORD[%s]", decoded_word);
+#endif
+
+FINISH_OFF:
+ if (dst.data != NULL && dst.data != src.data)
+ EM_SAFE_FREE(dst.data);
+ EM_SAFE_FREE(decoded_text);
+ EM_SAFE_FREE(buffer);
+
+ if (encoded_text != NULL)
+ g_free(encoded_text);
+ if (charset != NULL)
+ g_free(charset);
+
+ if (err_code != NULL)
+ *err_code = err;
+
+ EM_DEBUG_FUNC_END();
+ return decoded_word;
+}
+
+EXPORT_API char *em_core_decode_rfc2047_text(char *rfc2047_text, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("rfc2047_text[%s], err_code[%p]", rfc2047_text, err_code);
+
+ int ret = false;
+ int err = EMF_ERROR_NONE;
+
+ if (!rfc2047_text) {
+ EM_DEBUG_EXCEPTION("rfc2047_text[%p]", rfc2047_text);
+ if (err_code != NULL)
+ *err_code = EMF_ERROR_INVALID_PARAM;
+ return NULL;
+ }
+
+ char *text = NULL;
+
+ gchar **encoded_words = g_strsplit_set(rfc2047_text, " \t\r\n", -1);
+ gchar **decoded_words = g_new0(char *, g_strv_length(encoded_words) + 1);
+
+ /* EM_DEBUG_LOG("g_strv_length(encoded_words) [%d]", g_strv_length(encoded_words)); */
+
+ if (encoded_words != NULL) {
+ int i = 0;
+
+ while (encoded_words[i] != NULL) {
+ if (!(decoded_words[i] = em_core_decode_rfc2047_word(encoded_words[i], &err))) {
+ EM_DEBUG_EXCEPTION("em_core_decode_rfc2047_word falied [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ i++;
+ }
+ text = g_strjoinv(" ", decoded_words);
+ }
+ else
+ text = EM_SAFE_STRDUP(rfc2047_text);
+
+ /* Exceptional ... EUC-KR handling */ {
+ gsize bytes_read, bytes_written;
+ GError *glib_error = NULL;
+ int i = 0, has_special_character = 0;
+ char *utf8_encoded_string = NULL;
+
+ while(text[i]) {
+ if(text[i++] & 0x80) {
+ has_special_character = 1;
+ break;
+ }
+ }
+ EM_DEBUG_LOG("has_special_character [%d]", has_special_character);
+
+ if(has_special_character) /* It might be euc-kr. It should be encoded as UTF-8 */ {
+ utf8_encoded_string = (char*)g_convert (text, -1, "UTF-8", "EUC-KR", &bytes_read, &bytes_written, &glib_error);
+ if(utf8_encoded_string) {
+ EM_DEBUG_LOG("utf8_encoded_string [%s]", utf8_encoded_string);
+ EM_SAFE_FREE(text);
+ text = EM_SAFE_STRDUP(utf8_encoded_string);
+ }
+ else
+ EM_DEBUG_EXCEPTION("g_convert failed");
+ }
+ }
+
+#ifdef FEATURE_CORE_DEBUG
+ EM_DEBUG_LOG(">>>>>>>>>>>>>>>>> TEXT[%s]", text);
+#endif /* FEATURE_CORE_DEBUG */
+
+ ret = true;
+
+FINISH_OFF:
+ g_strfreev(decoded_words);
+ g_strfreev(encoded_words);
+
+ if (err_code != NULL)
+ *err_code = err;
+ EM_DEBUG_FUNC_END();
+ return text;
+}
diff --git a/email-core/em-core-mm-callbacks.c b/email-core/em-core-mm-callbacks.c
new file mode 100755
index 0000000..ec3a7e4
--- /dev/null
+++ b/email-core/em-core-mm-callbacks.c
@@ -0,0 +1,412 @@
+/*
+* email-service
+*
+* Copyright (c) 2000 - 2011 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.
+*
+*/
+
+
+/******************************************************************************
+ * File : em-core-mm_callbacks.c
+ * Desc : mm_callbacks for IMAP-2004g
+ *
+ * Auth :
+ *
+ * History :
+ * 2006.08.22 : created
+ *****************************************************************************/
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "em-core-types.h"
+#include "c-client.h"
+#include "em-core-global.h"
+#include "em-core-utils.h"
+#include "emf-dbglog.h"
+#include "em-core-mailbox.h"
+#include "em-core-account.h"
+
+static void mm_get_error(char *string, int *err_code);
+
+/*
+ * callback mm_lsub
+ * get subscribed mailbox list
+ */
+EXPORT_API void mm_lsub(MAILSTREAM *stream, int delimiter, char *mailbox, long attributes)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ emf_callback_holder_t *p_holder = (emf_callback_holder_t *)stream->sparep;
+ emf_mailbox_t *p, *p_old = p_holder->data;
+ int count = p_holder->num;
+ char *s, *enc_path;
+
+ /* memory allocation */
+ p = realloc(p_old, sizeof(emf_mailbox_t) * (count + 1));
+ if (!p) return ;
+
+ /* uw-imap mailbox name format (ex : "{mail.test.com...}inbox" or "{mail.test.com...}anybox/anysubbox") */
+ enc_path = strchr(mailbox, '}');
+ if (enc_path)
+ enc_path += 1;
+ else {
+ em_core_mailbox_free(&p, count+1, NULL);
+ return ;
+ }
+
+ /* Convert UTF7 mailbox name to UTF8 mailbox name */
+
+ /* convert directory delimiter to '/' */
+ for (s = enc_path; *s; s++) {
+ if (*s == (char)delimiter) {
+ *s = '/';
+ }
+ }
+
+ /* coyp string */
+ p[count].name = cpystr(enc_path);
+ p[count].alias = cpystr(enc_path);
+ p[count].local = 0;
+ p[count].account_id = stream->spare8;
+
+
+ p_holder->data = p;
+ p_holder->num++;
+
+ /* ignore attributes */
+/* if (attributes & latt_noinferiors) fputs (", no inferiors", fp_log); */
+/* if (attributes & latt_noselect) fputs (", no select", fp_log); */
+/* if (attributes & latt_marked) fputs (", marked", fp_log); */
+/* if (attributes & latt_unmarked) fputs (", unmarked", fp_log); */
+ EM_DEBUG_FUNC_END();
+}
+
+
+/*
+ * callback mm_lsub
+ * get mailbox list
+ */
+EXPORT_API void mm_list(MAILSTREAM *stream, int delimiter, char *mailbox, long attributes)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ emf_callback_holder_t *p_holder = (emf_callback_holder_t *)stream->sparep;
+ emf_mailbox_t *p, *p_old = p_holder->data;
+ int count = p_holder->num;
+ char *s, *enc_path;
+
+ /* memory allocation */
+ p = realloc(p_old, sizeof(emf_mailbox_t) * (count + 1));
+ if (!p) return ;
+
+ /* uw-imap mailbox name format (ex : "{mail.test.com...}inbox" or "{mail.test.com...}anybox/anysubbox") */
+ enc_path = strchr(mailbox, '}');
+ if (enc_path)
+ enc_path += 1;
+ else {
+ em_core_mailbox_free(&p, count+1, NULL);
+ return ;
+ }
+
+ /* convert directory delimiter to '/' */
+ for (s = enc_path;*s;s++)
+ if (*s == (char)delimiter)
+ *s = '/';
+
+ /* coyp string */
+ memset(p + count, 0x00, sizeof(emf_mailbox_t));
+ p[count].name = cpystr(enc_path);
+ p[count].alias = cpystr(enc_path);
+ p[count].local = 0;
+ EM_DEBUG_LOG("mm_list account_id %d", stream->spare8);
+
+ char *tmp = NULL;
+ /* in mailbox name parse n get user = %d - which is account_id */
+ tmp = strstr(mailbox, "user=");
+ if (tmp) {
+ tmp = tmp+5;
+ for (s = tmp; *s != '/'; s++);
+ *s = '\0';
+ p[count].account_id = atoi(tmp);
+ }
+ EM_DEBUG_LOG("mm_list account_id1 %d ", p[count].account_id);
+ EM_DEBUG_LOG("mm_list mailbox name r %s ", p[count].name);
+ p_holder->data = p;
+ p_holder->num++;
+
+ /* ignore attributes */
+ EM_DEBUG_FUNC_END();
+}
+
+
+/*
+ * callback mm_status
+ * get mailbox status
+ */
+EXPORT_API void mm_status(MAILSTREAM *stream, char *mailbox, MAILSTATUS* status)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ emf_callback_holder_t *p = stream->sparep;
+
+ EM_DEBUG_FUNC_BEGIN();
+ if (status->flags & SA_MESSAGES)
+ p->num = status->messages;
+ if (status->flags & SA_UNSEEN)
+ p->data = (void *)status->unseen;
+ EM_DEBUG_FUNC_END();
+}
+
+/* callback mm_login
+ * get user_name and password
+ */
+
+EXPORT_API void mm_login(NETMBX *mb, char *user, char *pwd, long trial)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int account_id;
+ emf_account_t *ref_account;
+ char *username = NULL;
+ char *password = NULL;
+
+ if (!mb->user[0]) {
+ EM_DEBUG_EXCEPTION("invalid account_id...");
+ return;
+ }
+
+ account_id = atoi(mb->user);
+
+ ref_account = em_core_get_account_reference(account_id);
+
+ if (!ref_account) {
+ EM_DEBUG_EXCEPTION("em_core_get_account_reference failed");
+ return;
+ }
+
+ if (ref_account->user_name == NULL) {
+ EM_DEBUG_EXCEPTION("invalid user_name...");
+ return;
+ }
+ username = EM_SAFE_STRDUP(ref_account->user_name);
+
+ if (ref_account->password == NULL) {
+ EM_SAFE_FREE(username);
+ EM_DEBUG_EXCEPTION("invalid password...");
+ return;
+ }
+
+ password = EM_SAFE_STRDUP(ref_account->password);
+
+ if (username && password && strlen(username) > 0 && strlen(password) > 0) {
+ strcpy(user, username);
+ strcpy(pwd, password);
+ }
+ else
+ EM_DEBUG_EXCEPTION("User Information is NULL || strlen is 0 ");
+
+ EM_SAFE_FREE(username);
+ EM_SAFE_FREE(password);
+
+ EM_DEBUG_FUNC_END();
+}
+
+
+EXPORT_API void mm_dlog(char *string)
+{
+#ifdef FEATURE_CORE_DEBUG
+ EM_DEBUG_LOG("IMAP_TOOLKIT_DLOG [%s]", string);
+ /* Write into debug file
+ FILE *fp_dlog = NULL;
+ fp_dlog = fopen("/opt/data/email/.emfdata/core_debug", "a");
+ if(fp_dlog) {
+ fprintf(fp_dlog, "%s\n", string);
+ fclose(fp_dlog);
+ }
+ */
+#endif
+}
+
+EXPORT_API void mm_log(char *string, long errflg)
+{
+ /* EM_DEBUG_FUNC_BEGIN(); */
+
+ switch ((short)errflg) {
+ case NIL:
+ EM_DEBUG_LOG("IMAP_TOOLKIT_LOG NIL [%s]", string);
+ break;
+
+ case WARN:
+ EM_DEBUG_LOG("IMAP_TOOLKIT_LOG WARN [%s]", string);
+ break;
+
+ case PARSE:
+ EM_DEBUG_LOG("IMAP_TOOLKIT_LOG PARSE [%s]", string);
+ break;
+
+ case BYE:
+ EM_DEBUG_LOG("IMAP_TOOLKIT_LOG BYE [%s]", string);
+ break;
+
+ case TCPDEBUG:
+ EM_DEBUG_LOG("IMAP_TOOLKIT_LOG TCPDEBUG [%s]", string);
+ break;
+
+ case ERROR: {
+ emf_session_t *session = NULL;
+
+ EM_DEBUG_EXCEPTION("IMAP_TOOLKIT_LOG ERROR [%s]", string);
+
+ em_core_get_current_session(&session);
+
+ if (session) {
+ mm_get_error(string, &session->error);
+ EM_DEBUG_EXCEPTION("IMAP_TOOLKIT_LOG ERROR [%d]", session->error);
+ }
+
+ /* Handling exceptional case of connection failures. */
+ /*
+ if (string) {
+ if (strstr(string, "15 minute") != 0) {
+ if (session)
+ session->error = EMF_ERROR_LOGIN_ALLOWED_EVERY_15_MINS;
+ }
+ else if (strstr(string, "Too many login failures") == 0) {
+ if (session)
+ session->error = EMF_ERROR_TOO_MANY_LOGIN_FAILURE;
+ }
+ }
+ */
+
+ break;
+ }
+ }
+}
+
+EXPORT_API void mm_searched(MAILSTREAM *stream, unsigned long number)
+{
+ EM_DEBUG_FUNC_BEGIN("stream [%p], number [%d]", stream, number);
+ EM_DEBUG_FUNC_END();
+}
+
+EXPORT_API void mm_exists(MAILSTREAM *stream, unsigned long number)
+{
+ EM_DEBUG_FUNC_BEGIN("stream [%p], number [%d]", stream, number);
+ EM_DEBUG_FUNC_END();
+}
+
+EXPORT_API void mm_expunged(MAILSTREAM *stream, unsigned long number)
+{
+ EM_DEBUG_FUNC_BEGIN("stream [%p], number [%d]", stream, number);
+ EM_DEBUG_FUNC_END();
+}
+
+EXPORT_API void mm_flags(MAILSTREAM *stream, unsigned long number)
+{
+ EM_DEBUG_FUNC_BEGIN("stream [%p], number [%d]", stream, number);
+ EM_DEBUG_FUNC_END();
+}
+
+EXPORT_API void mm_notify(MAILSTREAM *stream, char *string, long errflg)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ mm_log(string, errflg);
+ EM_DEBUG_FUNC_END();
+}
+
+EXPORT_API void mm_critical(MAILSTREAM *stream)
+{
+ EM_DEBUG_FUNC_BEGIN("stream [%p]", stream);
+ EM_DEBUG_FUNC_END();
+}
+
+EXPORT_API void mm_nocritical(MAILSTREAM *stream)
+{
+ EM_DEBUG_FUNC_BEGIN("stream [%p]", stream);
+ EM_DEBUG_FUNC_END();
+}
+
+EXPORT_API long mm_diskerror(MAILSTREAM *stream, long errcode, long serious)
+{
+ EM_DEBUG_FUNC_BEGIN("stream [%p] errcode[%d] serious[%d]", stream, errcode, serious);
+#if UNIXLIKE
+ kill(getpid(), SIGSTOP);
+#else
+ abort();
+#endif
+ EM_DEBUG_FUNC_END();
+ return NIL;
+}
+
+EXPORT_API void mm_fatal(char *string)
+{
+ EM_DEBUG_EXCEPTION("%s", string);
+}
+
+EXPORT_API void mm_get_error(char *string, int *err_code)
+{
+ if (!string || !err_code)
+ return ;
+
+ EM_DEBUG_LOG("string [%s]", string);
+
+ if (strstr(string, "login failure") || strstr(string, "Login aborted") || strstr(string, "Can't login"))
+ *err_code = EMF_ERROR_LOGIN_FAILURE;
+ else if (strstr(string, "Scan not valid"))
+ *err_code = EMF_ERROR_MAILBOX_FAILURE;
+ else if (strstr(string, "Authentication cancelled"))
+ *err_code = EMF_ERROR_AUTHENTICATE;
+ else if (strstr(string, "authuser"))
+ *err_code = EMF_ERROR_AUTH_NOT_SUPPORTED;
+ else if (strstr(string, "negotiate TLS"))
+ *err_code = EMF_ERROR_CANNOT_NEGOTIATE_TLS;
+ else if (strstr(string, "TLS/SSL failure"))
+ *err_code = EMF_ERROR_TLS_SSL_FAILURE;
+ else if (strstr(string, "STARTLS"))
+ *err_code = EMF_ERROR_STARTLS;
+ else if (strstr(string, "TLS unavailable"))
+ *err_code = EMF_ERROR_TLS_NOT_SUPPORTED;
+ else if (strstr(string, "Can't access"))
+ *err_code = EMF_ERROR_APPEND_FAILURE;
+ else if (strstr(string, "Can not authenticate"))
+ *err_code = EMF_ERROR_AUTHENTICATE;
+ else if (strstr(string, "Unexpected IMAP response") || strstr(string, "hello"))
+ *err_code = EMF_ERROR_INVALID_RESPONSE;
+ else if (strstr(string, "NOTIMAP4REV1"))
+ *err_code = EMF_ERROR_COMMAND_NOT_SUPPORTED;
+ else if (strstr(string, "Anonymous"))
+ *err_code = EMF_ERROR_ANNONYM_NOT_SUPPORTED;
+ else if (strstr(string, "connection broken"))
+ *err_code = EMF_ERROR_CONNECTION_BROKEN;
+ else if (strstr(string, "SMTP greeting"))
+ *err_code = EMF_ERROR_NO_RESPONSE;
+ else if (strstr(string, "ESMTP failure"))
+ *err_code = EMF_ERROR_SMTP_SEND_FAILURE;
+ else if (strstr(string, "socket") || strstr(string, "Socket"))
+ *err_code = EMF_ERROR_SOCKET_FAILURE;
+ else if (strstr(string, "connect to") || strstr(string, "Connection failed"))
+ *err_code = EMF_ERROR_CONNECTION_FAILURE;
+ else if (strstr(string, "Certificate failure"))
+ *err_code = EMF_ERROR_CERTIFICATE_FAILURE;
+ else if (strstr(string, "ESMTP failure"))
+ *err_code = EMF_ERROR_INVALID_PARAM;
+ else if (strstr(string, "No such host"))
+ *err_code = EMF_ERROR_NO_SUCH_HOST;
+ else if (strstr(string, "host") || strstr(string, "Host"))
+ *err_code = EMF_ERROR_INVALID_SERVER;
+ else if (strstr(string, "SELECT failed"))
+ *err_code = EMF_ERROR_MAILBOX_NOT_FOUND;
+ else
+ *err_code = EMF_ERROR_UNKNOWN;
+}
+/* EOF */
diff --git a/email-core/em-core-smtp.c b/email-core/em-core-smtp.c
new file mode 100755
index 0000000..de370ef
--- /dev/null
+++ b/email-core/em-core-smtp.c
@@ -0,0 +1,3646 @@
+/*
+* email-service
+*
+* Copyright (c) 2000 - 2011 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.
+*
+*/
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <fcntl.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <time.h>
+#include "em-core-types.h"
+#include "c-client.h"
+#include "em-core-global.h"
+#include "em-core-utils.h"
+#include "em-storage.h"
+#include "em-core-api.h"
+#include "em-core-smtp.h"
+#include "em-core-event.h"
+#include "em-core-mailbox.h"
+#include "em-core-mesg.h"
+#include "em-core-mime.h"
+#include "em-core-account.h"
+#include "em-core-imap-mailbox.h"
+#include "em-core-mailbox-sync.h"
+#include "Msg_Convert.h"
+
+
+#include <unistd.h>
+#include "emf-dbglog.h"
+
+
+/* Functions from uw-imap-toolkit */
+/* extern void *fs_get(size_t size); */
+extern void rfc822_date(char *date);
+extern long smtp_soutr(void *stream, char *s);
+extern long smtp_send(SENDSTREAM *stream, char *command, char *args);
+extern long smtp_rcpt(SENDSTREAM *stream, ADDRESS *adr, long* error);
+
+#ifdef __FEATURE_SEND_OPTMIZATION__
+extern long smtp_soutr_test(void *stream, char *s);
+#endif
+
+
+static int em_core_mail_get_report_body(ENVELOPE *envelope, BODY **multipart_body, int *err_code);
+static int em_core_mail_send_smtp(SENDSTREAM *stream, ENVELOPE *env, char *data_file, int account_id, int mail_id, int *err_code);
+
+void mail_send_notify(emf_send_status_t status, int total, int sent, int account_id, int mail_id, int err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("status[%d], total[%d], sent[%d], account_id[%d], mail_id[%d], err_code[%d]", status, total, sent, account_id, mail_id, err_code);
+
+ switch (status) {
+ case EMF_SEND_CONNECTION_FAIL:
+ case EMF_SEND_FINISH:
+ case EMF_SEND_FAIL:
+ break;
+
+ case EMF_SEND_PROGRESS:
+ default:
+ break;
+ }
+ em_core_execute_event_callback(EMF_ACTION_SEND_MAIL, total, sent, status, account_id, mail_id, -1, err_code);
+ EM_DEBUG_FUNC_END();
+}
+
+/* ------ rfc822 handle ---------------------------------------------------*/
+long buf_flush(void *stream, char *string)
+{
+ EM_DEBUG_FUNC_BEGIN("stream[%p], string[%s]", stream, string);
+ EM_DEBUG_FUNC_END();
+ return 1;
+}
+
+
+#define RFC822_READ_BLOCK_SIZE 1024
+#define RFC822_STRING_BUFFER_SIZE 1536
+
+static char *em_core_find_img_tag(char *source_string)
+{
+ EM_DEBUG_FUNC_BEGIN("source_string[%p]", source_string);
+
+ int cur = 0, string_length;
+ if (!source_string)
+ return false;
+
+ string_length = strlen(source_string);
+
+ for (cur = 0; cur < string_length; cur++) {
+ if (source_string[cur] == 'I' || source_string[cur] == 'i') {
+ cur++;
+ if (source_string[cur] == 'M' || source_string[cur] == 'm') {
+ cur++;
+ if (source_string[cur] == 'G' || source_string[cur] == 'g') {
+ EM_DEBUG_FUNC_END("%s", source_string + cur - 2);
+ return source_string + cur - 2;
+ }
+ }
+ }
+ }
+ EM_DEBUG_FUNC_END("Can't find");
+ return NULL;
+}
+
+#define CONTENT_ID_BUFFER_SIZE 512
+static char *em_core_replace_inline_image_path_with_content_id(char *source_string, BODY *html_body, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("source_string[%p], html_body[%p], err_code[%p]", source_string, html_body, err_code);
+
+ int err = EMF_ERROR_NONE;
+ char content_id_buffer[CONTENT_ID_BUFFER_SIZE], file_name_buffer[512], new_string[512], *result_string = NULL, *input_string = NULL;
+ BODY *cur_body = NULL;
+ PART *cur_part = NULL;
+
+ if (!source_string || !html_body) {
+ EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ input_string = EM_SAFE_STRDUP(source_string);
+
+ cur_part = html_body->nested.part;
+
+ while (cur_part) {
+ cur_body = &(cur_part->body);
+ if (cur_body) {
+ EM_DEBUG_LOG("Has body. id[%s]", cur_body->disposition.type);
+ if (cur_body->disposition.type && cur_body->disposition.type[0] == 'i') { /* Is inline content? */
+ EM_DEBUG_LOG("Has inline content");
+ memset(content_id_buffer, 0, CONTENT_ID_BUFFER_SIZE);
+ if (cur_body->id) {
+ EM_SAFE_STRNCPY(content_id_buffer, cur_body->id + 1, CONTENT_ID_BUFFER_SIZE - 1); /* Removing <, > */
+ content_id_buffer[strlen(content_id_buffer) - 1] = NULL_CHAR;
+ /* if (em_core_get_attribute_value_of_body_part(cur_body->parameter, "name", file_name_buffer, CONTENT_ID_BUFFER_SIZE, false, &err)) { */
+ if (em_core_get_attribute_value_of_body_part(cur_body->parameter, "name", file_name_buffer, CONTENT_ID_BUFFER_SIZE, true, &err)) {
+ EM_DEBUG_LOG("Content-ID[%s], filename[%s]", content_id_buffer, file_name_buffer);
+ SNPRINTF(new_string, CONTENT_ID_BUFFER_SIZE, "cid:%s", content_id_buffer);
+ result_string = em_core_replace_string(input_string, file_name_buffer, new_string);
+ if (input_string)
+ EM_SAFE_FREE(input_string);
+ }
+ }
+ }
+ }
+ if (result_string)
+ input_string = result_string;
+ cur_part = cur_part->next;
+ }
+
+ if (input_string)
+ result_string = EM_SAFE_STRDUP(input_string);
+FINISH_OFF:
+
+ EM_SAFE_FREE(input_string);
+ if (err_code)
+ *err_code = err;
+
+ EM_DEBUG_FUNC_END("ret[%s]", result_string);
+ return result_string;
+}
+
+static int em_core_write_rfc822_body(BODY *body, BODY *html_body, FILE *fp, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("body[%p], html_body[%p], fp[%p], err_code[%p]", body, html_body, fp, err_code);
+
+ PARAMETER *param = NULL;
+ PART *part = NULL;
+ char *p = NULL, *bndry = NULL, buf[1025], *replaced_string = NULL;
+ int fd, nread, nwrite, error = EMF_ERROR_NONE;
+
+ switch (body->type) {
+ case TYPEMULTIPART:
+ EM_DEBUG_LOG("body->type = TYPEMULTIPART");
+ part = body->nested.part;
+
+ for (param = body->parameter; param; param = param->next) {
+ if (strcasecmp(param->attribute, "BOUNDARY") == 0) {
+ bndry = param->value;
+ break;
+ }
+ }
+
+ do {
+ p = buf; p[0] = '\0';
+
+ rfc822_write_body_header(&p, &part->body);
+
+ fprintf(fp, "--%s"CRLF_STRING, bndry);
+ fprintf(fp, "%s"CRLF_STRING, buf);
+
+ em_core_write_rfc822_body(&part->body, html_body, fp, err_code);
+ } while ((part = part->next));
+
+ fprintf(fp, "--%s--"CRLF_STRING, bndry);
+ break;
+
+ default: {
+ EM_DEBUG_LOG("body->type is not TYPEMULTIPART");
+
+ char *file_path = body->sparep;
+ char buf[RFC822_STRING_BUFFER_SIZE + 1] = { 0, }, *img_tag_pos = NULL;
+ unsigned long len;
+
+ p = NULL;
+
+ if (!file_path || strlen(file_path) == 0) {
+ EM_DEBUG_LOG("There is no file path");
+ switch (body->encoding) {
+ case 0:
+ break;
+ default:
+ p = cpystr((const char *)body->contents.text.data);
+ len = body->contents.text.size;
+ break;
+ }
+
+ if (p) {
+ EM_DEBUG_LOG("p[%s]", p);
+ fprintf(fp, "%s"CRLF_STRING CRLF_STRING, p);
+ EM_SAFE_FREE(p);
+ }
+
+ EM_SAFE_FREE(body->sparep);
+ EM_DEBUG_FUNC_END();
+ return true;
+ }
+
+ EM_DEBUG_LOG("Opening a file[%s]", file_path);
+ fd = open(file_path, O_RDONLY);
+
+ if (fd < 0) {
+ EM_DEBUG_EXCEPTION("open(\"%s\") failed...", file_path);
+ return false;
+ }
+
+ while (1) {
+ nread = read(fd, buf, (body->encoding == ENCBASE64 ? 57 : RFC822_READ_BLOCK_SIZE - 2));
+
+ if (nread < 0) {
+ close(fd);
+ return false;
+ }
+
+ if (nread == 0) {
+ close(fd);
+ break;
+ }
+
+ p = NULL;
+ len = nread;
+
+ /* EM_DEBUG_LOG("body->type[%d], body->subtype[%c]", body->type, body->subtype[0]); */
+ if (body->type == TYPETEXT && (body->subtype && (body->subtype[0] == 'H' || body->subtype[0] == 'h'))) {
+ EM_DEBUG_LOG("HTML Part");
+ img_tag_pos = em_core_find_img_tag(buf);
+
+ if (img_tag_pos) {
+ replaced_string = em_core_replace_inline_image_path_with_content_id(buf, html_body, &error);
+ if (replaced_string) {
+ EM_DEBUG_LOG("em_core_replace_inline_image_path_with_content_id succeeded");
+ strcpy(buf, replaced_string);
+ nread = len = strlen(buf);
+ EM_DEBUG_LOG("buf[%s], nread[%d], len[%d]", buf, nread, len);
+ }
+ else
+ EM_DEBUG_LOG("em_core_replace_inline_image_path_with_content_id failed[%d]", error);
+ }
+ }
+
+ switch (body->encoding) {
+ case ENCQUOTEDPRINTABLE:
+ p = (char *)rfc822_8bit((unsigned char *)buf, (unsigned long)nread, (unsigned long *)&len);
+ break;
+ case ENCBASE64:
+ p = (char *)rfc822_binary((void *)buf, (unsigned long)nread, (unsigned long *)&len);
+ break;
+ default:
+ buf[len] = '\0';
+ break;
+ }
+
+
+ nwrite = fprintf(fp, "%s", (p ? p : buf));
+
+ if (nwrite != len) {
+ fclose(fp);
+ close(fd);
+ EM_SAFE_FREE(p);
+ EM_DEBUG_EXCEPTION("fprintf failed nwrite[%d], len[%d]", nwrite, len);
+ return false;
+ }
+ EM_SAFE_FREE(p);
+ }
+
+ if (body->encoding == ENCQUOTEDPRINTABLE || body->encoding == ENCBASE64)
+ fprintf(fp, CRLF_STRING);
+
+ fprintf(fp, CRLF_STRING);
+
+ if (body->sparep) {
+ free(body->sparep);
+ body->sparep = NULL;
+ }
+
+ break;
+ } /* default: */
+ }
+ EM_DEBUG_FUNC_END();
+ return true;
+}
+
+static int em_core_write_rfc822(ENVELOPE *env, BODY *body, BODY *html_body, emf_extra_flag_t flag, char **data, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("env[%p], body[%p], data[%p], err_code[%p]", env, body, data, err_code);
+
+ int ret = false;
+ int error = EMF_ERROR_NONE;
+
+ FILE *fp = NULL;
+ char *fname = NULL;
+ char *p = NULL;
+ size_t p_len = 0;
+
+ if (!env || !data) {
+ EM_DEBUG_EXCEPTION("Invalid Parameters");
+ error = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ srand(time(NULL));
+
+ rfc822_encode_body_7bit(env, body); /* if contents.text.data isn't NULL, the data will be encoded. */
+
+ /* FIXME : create memory map for this file */
+ p_len = (env->subject ? strlen(env->subject) : 0) + 8192;
+
+ if (!(p = em_core_malloc(p_len))) { /* (env->subject ? strlen(env->subject) : 0) + 8192))) */
+ EM_DEBUG_EXCEPTION(" malloc failed...");
+ error = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+
+ RFC822BUFFER buf;
+
+ /* write at start of buffer */
+ buf.end = (buf.beg = buf.cur = p) + p_len - 1;
+ /* buf.f = NIL; */
+ buf.f = buf_flush;
+ buf.s = NIL;
+
+ /* rfc822_output_header(&buf, env, body, NIL, T); */ /* including BCC */
+ rfc822_output_header(&buf, env, body, NIL, NIL); /* Excluding BCC */
+
+ *buf.cur = '\0'; /* tie off buffer */
+ {
+ gchar **tokens = g_strsplit(p, "CHARSET=X-UNKNOWN", 2);
+
+ if (g_strv_length(tokens) > 1) {
+ gchar *charset;
+
+ if (body->sparep) {
+ charset = g_path_get_basename(body->sparep);
+ char *pHtml = NULL;
+ if (charset != NULL) {
+ if ((pHtml = strstr(charset, ".htm")) != NULL)
+ charset[pHtml-charset] = '\0';
+ }
+
+ SNPRINTF(p, p_len, "%sCHARSET=%s%s", tokens[0], charset, tokens[1]);
+ g_free(charset);
+ }
+ else
+ EM_DEBUG_EXCEPTION("body->sparep is NULL");
+ }
+
+ g_strfreev(tokens);
+ } {
+ gchar **tokens = g_strsplit(p, "To: undisclosed recipients: ;\015\012", 2);
+ if (g_strv_length(tokens) > 1)
+ SNPRINTF(p, p_len, "%s%s", tokens[0], tokens[1]);
+ g_strfreev(tokens);
+ }
+
+
+ EM_DEBUG_LOG(" =============================================================================== "
+ LF_STRING"%s"LF_STRING
+ " =============================================================================== ", p);
+
+ if (strlen(p) > 2)
+ *(p + strlen(p) - 2) = '\0';
+
+
+ if (flag.report) {
+ char buf[512] = {0x00, };
+ switch (flag.report) {
+ case EMF_MAIL_REPORT_DSN: /* DSN (delivery status) */
+ /* change content-type */
+ /* Content-Type: multipart/report; */
+ /* report-type= delivery-status; */
+ /* boundary="----=_NextPart_000_004F_01C76EFF.54275C50" */
+ break;
+
+ case EMF_MAIL_REPORT_MDN: /* MDN (read receipt) */
+ /* Content-Type: multipart/report; */
+ /* report-type= disposition-notification; */
+ /* boundary="----=_NextPart_000_004F_01C76EFF.54275C50" */
+ break;
+
+ case EMF_MAIL_REPORT_REQUEST: /* require read status */
+ rfc822_address(buf, env->from);
+ if (strlen(buf))
+ SNPRINTF(p + strlen(p), p_len-(strlen(p)), "Disposition-Notification-To: %s"CRLF_STRING, buf);
+ break;
+
+ default:
+ break;
+ }
+ }
+
+ if (flag.priority) { /* priority (1:high 3:normal 5:low) */
+ SNPRINTF(p + strlen(p), p_len-(strlen(p)), "X-Priority: %d"CRLF_STRING, flag.priority);
+
+ switch (flag.priority) {
+ case EMF_MAIL_PRIORITY_HIGH:
+ SNPRINTF(p + strlen(p), p_len-(strlen(p)), "X-MSMail-Priority: HIgh"CRLF_STRING);
+ break;
+ case EMF_MAIL_PRIORITY_NORMAL:
+ SNPRINTF(p + strlen(p), p_len-(strlen(p)), "X-MSMail-Priority: Normal"CRLF_STRING);
+ break;
+ case EMF_MAIL_PRIORITY_LOW:
+ SNPRINTF(p + strlen(p), p_len-(strlen(p)), "X-MSMail-Priority: Low"CRLF_STRING);
+ break;
+ }
+ }
+
+ SNPRINTF(p + strlen(p), p_len-(strlen(p)), CRLF_STRING);
+
+ if (!em_core_get_temp_file_name(&fname, &error)) {
+ EM_DEBUG_EXCEPTION(" em_core_get_temp_file_name failed[%d]", error);
+ goto FINISH_OFF;
+ }
+
+ if (!(fp = fopen(fname, "w+"))) {
+ EM_DEBUG_EXCEPTION("fopen failed[%s]", fname);
+ error = EMF_ERROR_SYSTEM_FAILURE;
+ goto FINISH_OFF;
+ }
+
+ fprintf(fp, "%s", p);
+
+ if (body) {
+ if (!em_core_write_rfc822_body(body, html_body, fp, &error)) {
+ EM_DEBUG_EXCEPTION("em_core_write_rfc822_body failed[%d]", error);
+ goto FINISH_OFF;
+ }
+ }
+
+ ret = true;
+
+
+FINISH_OFF:
+ if (fp != NULL)
+ fclose(fp);
+
+#ifdef USE_SYNC_LOG_FILE
+ em_storage_copy_file(fname, "/tmp/phone2pc.eml", false, NULL);
+#endif
+
+ if (ret == true)
+ *data = fname;
+ else if (fname != NULL) {
+ remove(fname);
+ EM_SAFE_FREE(fname);
+ }
+
+ EM_SAFE_FREE(p);
+
+ if (err_code != NULL)
+ *err_code = error;
+ EM_DEBUG_FUNC_END();
+ return ret;
+}
+
+static int em_core_set_current_time_to_mail_header(emf_mail_head_t *head, int *err)
+{
+ EM_DEBUG_FUNC_BEGIN("head[%p], err [%p]", head, err);
+
+ int err_code = EMF_ERROR_NONE, ret = false;
+ time_t t = time(NULL);
+ struct tm *p_tm = NULL;
+
+ if(!head) {
+ EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
+ err_code = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ p_tm = gmtime(&t);
+
+ if (!p_tm) {
+ EM_DEBUG_EXCEPTION("localtime failed...");
+ err_code = EMF_ERROR_SYSTEM_FAILURE;
+ goto FINISH_OFF;
+ }
+
+ head->datetime.year = p_tm->tm_year + 1900;
+ head->datetime.month = p_tm->tm_mon + 1;
+ head->datetime.day = p_tm->tm_mday;
+ head->datetime.hour = p_tm->tm_hour;
+ head->datetime.minute = p_tm->tm_min;
+ head->datetime.second = p_tm->tm_sec;
+
+ ret = true;
+
+FINISH_OFF:
+
+ if(err)
+ *err = err_code;
+
+ EM_DEBUG_FUNC_END();
+ return ret;
+}
+
+
+
+EXPORT_API int em_core_mail_save(int account_id, char *mailbox_name, emf_mail_t *mail_src, emf_meeting_request_t *meeting_req, int from_composer, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("account_id[%d], mailbox_name[%p], mail_src[%p], from_composer[%d], err_code[%p]", account_id, mailbox_name, mail_src, from_composer, err_code);
+
+ int ret = false, err = EMF_ERROR_NONE;
+ int attachment_id = 0, mail_id = 0, thread_id = -1, thread_item_count = 0, latest_mail_id_in_thread = -1;
+ int rule_len, rule_matched = -1, local_attachment_count = 0, local_inline_content_count = 0;
+ char *ext = NULL, *mailbox_name_spam = NULL, *mailbox_name_target = NULL;
+ char name_buf[MAX_PATH] = {0x00, }, html_body[MAX_PATH] = {0x00, };
+ char datetime[DATETIME_LENGTH] = { 0, };
+ emf_mail_tbl_t *mail_table_data = NULL;
+ emf_mailbox_tbl_t *mailbox_tbl_data = NULL;
+ emf_attachment_info_t *atch = NULL;
+ emf_mail_account_tbl_t *account_tbl_item = NULL;
+ emf_mail_rule_tbl_t *rule = NULL;
+ emf_mail_attachment_tbl_t attachment_tbl = { 0 };
+ struct stat st_buf = { 0 };
+
+ /* Validating parameters */
+
+ if (!account_id || !mailbox_name || !mail_src || !mail_src->info || !mail_src->head) {
+ EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ if (!em_storage_get_account_by_id(account_id, EMF_ACC_GET_OPT_DEFAULT | EMF_ACC_GET_OPT_OPTIONS, &account_tbl_item, true, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_get_account_by_id failed. account_id[%d] err[%d]", account_id, err);
+ err = EMF_ERROR_INVALID_ACCOUNT;
+ goto FINISH_OFF;
+ }
+
+ if (from_composer) {
+ if (!mail_src->head->from)
+ mail_src->head->from = EM_SAFE_STRDUP(account_tbl_item->email_addr);
+
+ /* check for email_address validation */
+ if (!em_core_verify_email_address_of_mail_header(mail_src->head, false, &err)) {
+ EM_DEBUG_EXCEPTION("em_core_verify_email_address_of_mail_header failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ if (mail_src->info->extra_flags.report == EMF_MAIL_REPORT_MDN) {
+ /* check read-report mail */
+ if(!mail_src->head->to) { /* A report mail should have 'to' address */
+ EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+ /* Create report mail body */
+ if (!em_core_mail_get_rfc822(mail_src, NULL, NULL, NULL, &err)) {
+ EM_DEBUG_EXCEPTION("em_core_mail_get_rfc822 failed [%d]", err);
+ goto FINISH_OFF;
+ }
+ }
+
+ mailbox_name_target = EM_SAFE_STRDUP(mailbox_name);
+ }
+ else { /* For Spam handling */
+ emf_option_t *opt = &account_tbl_item->options;
+ EM_DEBUG_LOG("block_address [%d], block_subject [%d]", opt->block_address, opt->block_subject);
+
+ if (opt->block_address || opt->block_subject) {
+ int is_completed = false;
+ int type = 0;
+
+ if (!opt->block_address)
+ type = EMF_FILTER_SUBJECT;
+ else if (!opt->block_subject)
+ type = EMF_FILTER_FROM;
+
+ if (!em_storage_get_rule(ALL_ACCOUNT, type, 0, &rule_len, &is_completed, &rule, true, &err) || !rule)
+ EM_DEBUG_LOG("No proper rules. em_storage_get_rule returnes [%d]", err);
+ }
+
+ if (rule) {
+ if (!em_storage_get_mailboxname_by_mailbox_type(account_id, EMF_MAILBOX_TYPE_SPAMBOX, &mailbox_name_spam, false, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_get_mailboxname_by_mailbox_type failed [%d]", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ mailbox_name_spam = NULL;
+ }
+
+ if (mailbox_name_spam && !em_core_mail_check_rule(mail_src->head, rule, rule_len, &rule_matched, &err)) {
+ EM_DEBUG_EXCEPTION("em_core_mail_check_rule failed [%d]", err);
+ goto FINISH_OFF;
+ }
+ }
+
+ if (rule_matched >= 0 && mailbox_name_spam)
+ mailbox_name_target = EM_SAFE_STRDUP(mailbox_name_spam);
+ else
+ mailbox_name_target = EM_SAFE_STRDUP(mailbox_name);
+ }
+
+ if (!em_storage_get_mailbox_by_name(account_id, -1, mailbox_name_target, (emf_mailbox_tbl_t **)&mailbox_tbl_data, false, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_get_mailboxname_by_mailbox_type failed [%d]", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+
+ if (!em_storage_increase_mail_id(&mail_id, true, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_increase_mail_id failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ mail_table_data = (emf_mail_tbl_t *)em_core_malloc(sizeof(emf_mail_tbl_t));
+
+ if(!mail_table_data) {
+ EM_DEBUG_EXCEPTION("em_core_malloc failed");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ mail_table_data->account_id = account_id;
+ mail_table_data->mail_id = mail_id;
+ mail_table_data->mailbox_name = EM_SAFE_STRDUP(mailbox_name_target);
+ mail_table_data->mail_size = mail_src->info->rfc822_size;
+ mail_table_data->server_mail_status = !from_composer;
+ mail_table_data->server_mail_id = EM_SAFE_STRDUP(mail_src->info->sid);
+ mail_table_data->full_address_from = EM_SAFE_STRDUP(mail_src->head->from);
+ mail_table_data->full_address_to = EM_SAFE_STRDUP(mail_src->head->to);
+ mail_table_data->full_address_cc = EM_SAFE_STRDUP(mail_src->head->cc);
+ mail_table_data->full_address_bcc = EM_SAFE_STRDUP(mail_src->head->bcc);
+ mail_table_data->full_address_reply = EM_SAFE_STRDUP(mail_src->head->reply_to);
+ mail_table_data->full_address_return = EM_SAFE_STRDUP(mail_src->head->return_path);
+ mail_table_data->subject = EM_SAFE_STRDUP(mail_src->head->subject);
+ mail_table_data->body_download_status = mail_src->info->extra_flags.text_download_yn;
+ mail_table_data->mailbox_type = mailbox_tbl_data->mailbox_type;
+
+ em_core_fill_address_information_of_mail_tbl(mail_table_data);
+
+ EM_DEBUG_LOG("mail_table_data->mail_size [%d]", mail_table_data->mail_size);
+ if(mail_table_data->mail_size == 0)
+ mail_table_data->mail_size = em_core_get_mail_size(mail_src, &err); /* Getting file size before file moved. */
+
+ if (mail_src->body) {
+ if (from_composer || mail_table_data->body_download_status) {
+ if (!em_storage_create_dir(account_id, mail_id, 0, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_create_dir failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ if (mail_src->body->plain) {
+ EM_DEBUG_LOG("mail_src->body->plain [%s]", mail_src->body->plain);
+ if (!em_storage_get_save_name(account_id, mail_id, 0, mail_src->body->plain_charset ? mail_src->body->plain_charset : "UTF-8", name_buf, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_get_save_name failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ if (!em_storage_move_file(mail_src->body->plain, name_buf, from_composer, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_move_file failed [%d]", err);
+ goto FINISH_OFF;
+ }
+ if (mail_table_data->body_download_status == 0)
+ mail_table_data->body_download_status = 1;
+ mail_table_data->file_path_plain = EM_SAFE_STRDUP(name_buf);
+ EM_SAFE_FREE(mail_src->body->plain);
+ mail_src->body->plain = EM_SAFE_STRDUP(name_buf);
+ }
+
+ if (mail_src->body->html) {
+ EM_DEBUG_LOG("mail_src->body->html [%s]", mail_src->body->html);
+ if (mail_src->body->plain_charset != NULL && mail_src->body->plain_charset[0] != NULL_CHAR) {
+ memcpy(html_body, mail_src->body->plain_charset, strlen(mail_src->body->plain_charset));
+ strcat(html_body, ".htm");
+ }
+ else {
+ memcpy(html_body, "UTF-8.htm", strlen("UTF-8.htm"));
+ }
+
+ if (!em_storage_get_save_name(account_id, mail_id, 0, html_body, name_buf, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_get_save_name failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ if (!em_storage_move_file(mail_src->body->html, name_buf, from_composer, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_move_file failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ if (mail_table_data->body_download_status == EMF_BODY_DOWNLOAD_STATUS_NONE)
+ mail_table_data->body_download_status = EMF_BODY_DOWNLOAD_STATUS_FULLY_DOWNLOADED;
+
+ mail_table_data->file_path_html = EM_SAFE_STRDUP(name_buf);
+ EM_SAFE_FREE(mail_src->body->html);
+ mail_src->body->html = EM_SAFE_STRDUP(name_buf);
+ }
+ }
+ }
+
+
+ if (!mail_src->head->datetime.year && !mail_src->head->datetime.month && !mail_src->head->datetime.day) {
+ /* time isn't set */
+ if(!em_core_set_current_time_to_mail_header(mail_src->head, &err)) {
+ EM_DEBUG_EXCEPTION("em_core_set_current_time_to_mail_header failed [%d]", err);
+ goto FINISH_OFF;
+ }
+ }
+
+ SNPRINTF(datetime, sizeof(datetime), "%04d%02d%02d%02d%02d%02d",
+ mail_src->head->datetime.year, mail_src->head->datetime.month, mail_src->head->datetime.day, mail_src->head->datetime.hour, mail_src->head->datetime.minute, mail_src->head->datetime.second);
+
+ mail_table_data->datetime = EM_SAFE_STRDUP(datetime);
+ mail_table_data->message_id = EM_SAFE_STRDUP(mail_src->head->mid);
+
+ if (mail_src->info) {
+ mail_src->info->flags.draft = 1;
+ if(!em_convert_mail_flag_to_mail_tbl(&(mail_src->info->flags), mail_table_data, &err)) {
+ EM_DEBUG_EXCEPTION("em_convert_mail_flag_to_mail_tbl failed [%d]", err);
+ goto FINISH_OFF;
+ }
+ mail_table_data->priority = mail_src->info->extra_flags.priority;
+ mail_table_data->lock_status = mail_src->info->extra_flags.lock;
+ mail_table_data->report_status = mail_src->info->extra_flags.report;
+ }
+ mail_table_data->save_status = EMF_MAIL_STATUS_SAVED;
+
+ mail_id = mail_table_data->mail_id;
+ mail_src->info->uid = mail_id;
+
+ mail_table_data->meeting_request_status = mail_src->info->is_meeting_request;
+
+ if(mail_src->info->thread_id == 0) {
+ if (em_storage_get_thread_id_of_thread_mails(mail_table_data, &thread_id, &latest_mail_id_in_thread, &thread_item_count) != EMF_ERROR_NONE)
+ EM_DEBUG_LOG(" em_storage_get_thread_id_of_thread_mails is failed");
+
+ if (thread_id == -1) {
+ mail_table_data->thread_id = mail_id;
+ mail_table_data->thread_item_count = thread_item_count = 1;
+ }
+ else {
+ mail_table_data->thread_id = thread_id;
+ thread_item_count++;
+ }
+ }
+ else {
+ mail_table_data->thread_id = mail_src->info->thread_id;
+ thread_item_count = 2;
+ }
+
+ /* Getting attachment count */
+ if (mail_src->body)
+ atch = mail_src->body->attachment;
+ while (atch) {
+ if (atch->inline_content)
+ local_inline_content_count++;
+ local_attachment_count++;
+ atch = atch->next;
+ }
+
+ mail_table_data->inline_content_count = local_inline_content_count;
+ mail_table_data->attachment_count = local_attachment_count;
+
+ EM_DEBUG_LOG("inline_content_count [%d]", local_inline_content_count);
+ EM_DEBUG_LOG("attachment_count [%d]", local_attachment_count);
+
+ EM_DEBUG_LOG("preview_text[%p]", mail_table_data->preview_text);
+ if (mail_table_data->preview_text == NULL) {
+ if ( (err = em_core_get_preview_text_from_file(mail_table_data->file_path_plain, mail_table_data->file_path_html, MAX_PREVIEW_TEXT_LENGTH, &(mail_table_data->preview_text))) != EMF_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("em_core_get_preview_text_from_file failed[%d]", err);
+ goto FINISH_OFF;
+ }
+ }
+
+ em_storage_begin_transaction(NULL, NULL, NULL);
+
+ /* insert mail to mail table */
+ if (!em_storage_add_mail(mail_table_data, 0, false, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_add_mail failed [%d]", err);
+ /* ROLLBACK TRANSACTION; */
+ em_storage_rollback_transaction(NULL, NULL, NULL);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+
+ EM_DEBUG_LOG("thread_item_count [%d]", thread_item_count);
+ if (thread_item_count > 1) {
+ if (!em_storage_update_latest_thread_mail(mail_table_data->account_id, mail_table_data->thread_id, 0, 0, false, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_update_latest_thread_mail failed [%d]", err);
+ em_storage_rollback_transaction(NULL, NULL, NULL);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+ }
+
+ /* Insert attachment information to DB */
+ if (mail_src->body)
+ atch = mail_src->body->attachment;
+ EM_DEBUG_LOG("atch [%p]", atch);
+ while (atch) {
+ if (from_composer && stat(atch->savename, &st_buf) < 0) {
+ atch = atch->next;
+ continue;
+ }
+
+ if (!atch->inline_content) {
+ if (!em_storage_get_new_attachment_no(&attachment_id, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_get_new_attachment_no failed [%d]", err);
+ em_storage_rollback_transaction(NULL, NULL, NULL);
+ goto FINISH_OFF;
+ }
+ }
+
+ if (!em_storage_create_dir(account_id, mail_id, atch->inline_content ? 0 : attachment_id, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_create_dir failed [%d]", err);
+ em_storage_rollback_transaction(NULL, NULL, NULL);
+ goto FINISH_OFF;
+ }
+
+ if (!em_storage_get_save_name(account_id, mail_id, atch->inline_content ? 0 : attachment_id, atch->name, name_buf, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_get_save_name failed [%d]", err);
+ em_storage_rollback_transaction(NULL, NULL, NULL);
+ goto FINISH_OFF;
+ }
+
+ if (from_composer || atch->downloaded) {
+ if (!em_storage_copy_file(atch->savename, name_buf, from_composer, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_copy_file failed [%d]", err);
+ em_storage_rollback_transaction(NULL, NULL, NULL);
+ goto FINISH_OFF;
+ }
+
+ if ((ext = strrchr(atch->name, '.'))) {
+ if (!strncmp(ext, ".vcs", strlen(".vcs")))
+ remove(atch->savename);
+ else if (!strncmp(ext, ".vcf", strlen(".vcf")))
+ remove(atch->savename);
+ else if (!strncmp(ext, ".vnt", strlen(".vnt")))
+ remove(atch->savename);
+ }
+ }
+
+ memset(&attachment_tbl, 0x00, sizeof(emf_mail_attachment_tbl_t));
+
+ attachment_tbl.mail_id = mail_id;
+ attachment_tbl.account_id = account_id;
+ attachment_tbl.mailbox_name = mailbox_name_target;
+ attachment_tbl.file_yn = atch->downloaded;
+ attachment_tbl.flag2 = mail_src->body->attachment->drm;
+ attachment_tbl.attachment_name = atch->name;
+ attachment_tbl.attachment_path = name_buf;
+ attachment_tbl.flag3 = atch->inline_content;
+ if (from_composer)
+ attachment_tbl.attachment_size = st_buf.st_size;
+ else
+ attachment_tbl.attachment_size = atch->size;
+
+ if (!em_storage_add_attachment(&attachment_tbl, 0, false, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_add_attachment failed [%d]", err);
+ em_storage_rollback_transaction(NULL, NULL, NULL);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+ atch->attachment_id = attachment_tbl.attachment_id;
+ atch = atch->next;
+ }
+
+ /* Insert Meeting request to DB */
+ if (mail_src->info->is_meeting_request == EMF_MAIL_TYPE_MEETING_REQUEST
+ || mail_src->info->is_meeting_request == EMF_MAIL_TYPE_MEETING_RESPONSE
+ || mail_src->info->is_meeting_request == EMF_MAIL_TYPE_MEETING_ORIGINATINGREQUEST) {
+ EM_DEBUG_LOG("This mail has the meeting request");
+ meeting_req->mail_id = mail_id;
+ if (!em_storage_add_meeting_request(account_id, mailbox_name_target, meeting_req, false, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_add_meeting_request failed [%d]", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+ }
+
+ em_storage_commit_transaction(NULL, NULL, NULL);
+
+ if (!em_storage_notify_storage_event(NOTI_MAIL_ADD, account_id, mail_id, mailbox_name_target, mail_table_data->thread_id))
+ EM_DEBUG_LOG("em_storage_notify_storage_event [NOTI_MAIL_ADD] failed.");
+
+ if (account_tbl_item->receiving_server_type != EMF_SERVER_TYPE_ACTIVE_SYNC) {
+ if (!em_core_mailbox_remove_overflowed_mails(mailbox_tbl_data, &err)) {
+ if (err == EM_STORAGE_ERROR_MAIL_NOT_FOUND || err == EMF_ERROR_NOT_SUPPORTED)
+ err = EMF_ERROR_NONE;
+ else
+ EM_DEBUG_LOG("em_core_mailbox_remove_overflowed_mails failed [%d]", err);
+ }
+ }
+
+ if ( !from_composer && (mail_src->info->flags.seen == 0)
+ && mail_table_data->mailbox_type != EMF_MAILBOX_TYPE_TRASH
+ && mail_table_data->mailbox_type != EMF_MAILBOX_TYPE_SPAMBOX) { /* 0x01 fSeen */
+ if (!em_storage_update_sync_status_of_account(account_id, SET_TYPE_SET, SYNC_STATUS_SYNCING | SYNC_STATUS_HAVE_NEW_MAILS, true, &err))
+ EM_DEBUG_LOG("em_storage_update_sync_status_of_account failed [%d]", err);
+ em_core_add_notification_for_unread_mail_by_mail_header(account_id, mail_id, mail_src->head);
+ em_core_check_unread_mail();
+ }
+
+ ret = true;
+
+FINISH_OFF:
+ if (mail_table_data)
+ em_storage_free_mail(&mail_table_data, 1, NULL);
+
+ if (account_tbl_item)
+ em_storage_free_account(&account_tbl_item, 1, NULL);
+
+ if (mailbox_tbl_data)
+ em_storage_free_mailbox(&mailbox_tbl_data, 1, NULL);
+
+ EM_SAFE_FREE(mailbox_name_spam);
+ EM_SAFE_FREE(mailbox_name_target);
+
+ if (err_code)
+ *err_code = err;
+
+ EM_DEBUG_FUNC_END();
+ return ret;
+}
+
+
+EXPORT_API int em_core_add_mail(emf_mail_data_t *input_mail_data, emf_attachment_data_t *input_attachment_data_list, int input_attachment_count, emf_meeting_request_t *input_meeting_request, int input_sync_server)
+{
+ EM_DEBUG_FUNC_BEGIN("input_mail_data[%p], input_attachment_data_list [%p], input_attachment_count [%d], input_meeting_request [%p], input_sync_server[%d]", input_mail_data, input_attachment_data_list, input_attachment_count, input_meeting_request, input_sync_server);
+
+ int err = EMF_ERROR_NONE;
+ int attachment_id = 0, thread_id = -1, thread_item_count = 0, latest_mail_id_in_thread = -1;
+ int i = 0, rule_len, rule_matched = -1, local_attachment_count = 0, local_inline_content_count = 0;
+ char *ext = NULL, *mailbox_name_spam = NULL, *mailbox_name_target = NULL;
+ char name_buf[MAX_PATH] = {0x00, }, html_body[MAX_PATH] = {0x00, };
+ emf_mail_tbl_t *converted_mail_tbl = NULL;
+ emf_mailbox_tbl_t *mailbox_tbl = NULL;
+ emf_mail_attachment_tbl_t attachment_tbl = { 0 };
+ emf_mail_account_tbl_t *account_tbl_item = NULL;
+ emf_mail_rule_tbl_t *rule = NULL;
+ struct stat st_buf = { 0 };
+
+ /* Validating parameters */
+
+ if (!input_mail_data || !(input_mail_data->account_id) || !(input_mail_data->mailbox_name)) {
+ EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ if (!em_storage_get_account_by_id(input_mail_data->account_id, EMF_ACC_GET_OPT_DEFAULT | EMF_ACC_GET_OPT_OPTIONS, &account_tbl_item, true, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_get_account_by_id failed. account_id[%d] err[%d]", input_mail_data->account_id, err);
+ err = EMF_ERROR_INVALID_ACCOUNT;
+ goto FINISH_OFF;
+ }
+
+ if(input_sync_server) {
+ if (input_mail_data->file_path_plain) {
+ if (stat(input_mail_data->file_path_plain, &st_buf) < 0) {
+ EM_DEBUG_EXCEPTION("input_mail_data->file_path_plain, stat(\"%s\") failed...", input_mail_data->file_path_plain);
+ err = EMF_ERROR_INVALID_MAIL;
+ goto FINISH_OFF;
+ }
+ }
+
+ if (input_mail_data->file_path_html) {
+ if (stat(input_mail_data->file_path_html, &st_buf) < 0) {
+ EM_DEBUG_EXCEPTION("input_mail_data->file_path_html, stat(\"%s\") failed...", input_mail_data->file_path_html);
+ err = EMF_ERROR_INVALID_MAIL;
+ goto FINISH_OFF;
+ }
+ }
+
+ if (input_attachment_count && input_attachment_data_list) {
+ for (i = 0; i < input_attachment_count; i++) {
+ if (input_attachment_data_list[i].save_status) {
+ if (!input_attachment_data_list[i].attachment_path || stat(input_attachment_data_list[i].attachment_path, &st_buf) < 0) {
+ EM_DEBUG_EXCEPTION("stat(\"%s\") failed...", input_attachment_data_list[i].attachment_path);
+ err = EMF_ERROR_INVALID_ATTACHMENT;
+ goto FINISH_OFF;
+ }
+ }
+ }
+ }
+ }
+
+ if (input_sync_server) {
+ if (!input_mail_data->full_address_from)
+ input_mail_data->full_address_from = EM_SAFE_STRDUP(account_tbl_item->email_addr);
+
+ /* check for email_address validation */
+ if (!em_core_verify_email_address_of_mail_data(input_mail_data, false, &err)) {
+ EM_DEBUG_EXCEPTION("em_core_verify_email_address_of_mail_data failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ if (input_mail_data->report_status == EMF_MAIL_REPORT_MDN) {
+ /* check read-report mail */
+ if(!input_mail_data->full_address_to) { /* A report mail should have 'to' address */
+ EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+ /* Create report mail body */
+ /*
+ if (!em_core_mail_get_rfc822(mail_src, NULL, NULL, NULL, &err)) {
+ EM_DEBUG_EXCEPTION("em_core_mail_get_rfc822 failed [%d]", err);
+ goto FINISH_OFF;
+ }
+ */
+ }
+
+ mailbox_name_target = EM_SAFE_STRDUP(input_mail_data->mailbox_name);
+ }
+ else { /* For Spam handling */
+ emf_option_t *opt = &account_tbl_item->options;
+ EM_DEBUG_LOG("block_address [%d], block_subject [%d]", opt->block_address, opt->block_subject);
+
+ if (opt->block_address || opt->block_subject) {
+ int is_completed = false;
+ int type = 0;
+
+ if (!opt->block_address)
+ type = EMF_FILTER_SUBJECT;
+ else if (!opt->block_subject)
+ type = EMF_FILTER_FROM;
+
+ if (!em_storage_get_rule(ALL_ACCOUNT, type, 0, &rule_len, &is_completed, &rule, true, &err) || !rule)
+ EM_DEBUG_LOG("No proper rules. em_storage_get_rule returns [%d]", err);
+ }
+
+ if (rule) {
+ if (!em_storage_get_mailboxname_by_mailbox_type(input_mail_data->account_id, EMF_MAILBOX_TYPE_SPAMBOX, &mailbox_name_spam, false, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_get_mailboxname_by_mailbox_type failed [%d]", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ mailbox_name_spam = NULL;
+ }
+
+ /*
+ if (mailbox_name_spam && !em_core_mail_check_rule(mail_src->head, rule, rule_len, &rule_matched, &err)) {
+ EM_DEBUG_EXCEPTION("em_core_mail_check_rule failed [%d]", err);
+ goto FINISH_OFF;
+ }
+ */
+ }
+
+ if (rule_matched >= 0 && mailbox_name_spam)
+ mailbox_name_target = EM_SAFE_STRDUP(mailbox_name_spam);
+ else
+ mailbox_name_target = EM_SAFE_STRDUP(input_mail_data->mailbox_name);
+ }
+
+ if (!em_storage_get_mailbox_by_name(input_mail_data->account_id, -1, mailbox_name_target, (emf_mailbox_tbl_t **)&mailbox_tbl, false, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_get_mailboxname_by_mailbox_type failed [%d]", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+
+ if (!em_storage_increase_mail_id(&input_mail_data->mail_id, true, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_increase_mail_id failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ EM_DEBUG_LOG("input_mail_data->mail_size [%d]", input_mail_data->mail_size);
+
+ if(input_mail_data->mail_size == 0)
+ em_core_calc_mail_size(input_mail_data, input_attachment_data_list, input_attachment_count, &(input_mail_data->mail_size)); /* Getting file size before file moved. */
+
+ if (input_sync_server || input_mail_data->body_download_status) {
+ if (!em_storage_create_dir(input_mail_data->account_id, input_mail_data->mail_id, 0, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_create_dir failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ if (input_mail_data->file_path_plain) {
+ EM_DEBUG_LOG("input_mail_data->file_path_plain [%s]", input_mail_data->file_path_plain);
+ /* if (!em_storage_get_save_name(account_id, mail_id, 0, input_mail_data->body->plain_charset ? input_mail_data->body->plain_charset : "UTF-8", name_buf, &err)) {*/
+ if (!em_storage_get_save_name(input_mail_data->account_id, input_mail_data->mail_id, 0, "UTF-8", name_buf, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_get_save_name failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ if (!em_storage_move_file(input_mail_data->file_path_plain, name_buf, input_sync_server, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_move_file failed [%d]", err);
+ goto FINISH_OFF;
+ }
+ if (input_mail_data->body_download_status == EMF_BODY_DOWNLOAD_STATUS_NONE)
+ input_mail_data->body_download_status = EMF_BODY_DOWNLOAD_STATUS_FULLY_DOWNLOADED;
+
+ EM_SAFE_FREE(input_mail_data->file_path_plain);
+ input_mail_data->file_path_plain = EM_SAFE_STRDUP(name_buf);
+ }
+
+ if (input_mail_data->file_path_html) {
+ EM_DEBUG_LOG("input_mail_data->file_path_html [%s]", input_mail_data->file_path_html);
+ memcpy(html_body, "UTF-8.htm", strlen("UTF-8.htm"));
+
+ if (!em_storage_get_save_name(input_mail_data->account_id, input_mail_data->mail_id, 0, html_body, name_buf, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_get_save_name failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ if (!em_storage_move_file(input_mail_data->file_path_html, name_buf, input_sync_server, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_move_file failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ if (input_mail_data->body_download_status == EMF_BODY_DOWNLOAD_STATUS_NONE)
+ input_mail_data->body_download_status = EMF_BODY_DOWNLOAD_STATUS_FULLY_DOWNLOADED;
+
+ EM_SAFE_FREE(input_mail_data->file_path_html);
+ input_mail_data->file_path_html = EM_SAFE_STRDUP(name_buf);
+ }
+ }
+
+
+ if (!input_mail_data->datetime) {
+ /* time isn't set */
+ input_mail_data->datetime = em_core_get_current_time_string(&err);
+ if(!input_mail_data->datetime) {
+ EM_DEBUG_EXCEPTION("em_core_get_current_time_string failed [%d]", err);
+ goto FINISH_OFF;
+ }
+ }
+
+ EM_SAFE_FREE(input_mail_data->mailbox_name);
+
+ input_mail_data->mailbox_name = EM_SAFE_STRDUP(mailbox_name_target);
+ input_mail_data->mailbox_type = mailbox_tbl->mailbox_type;
+ input_mail_data->server_mail_status = !input_sync_server;
+ input_mail_data->save_status = EMF_MAIL_STATUS_SAVED;
+
+ /* Getting attachment count */
+ for (i = 0; i < input_attachment_count; i++) {
+ if (input_attachment_data_list[i].inline_content_status== 1)
+ local_inline_content_count++;
+ local_attachment_count++;
+ }
+
+ input_mail_data->inline_content_count = local_inline_content_count;
+ input_mail_data->attachment_count = local_attachment_count;
+
+ EM_DEBUG_LOG("inline_content_count [%d]", local_inline_content_count);
+ EM_DEBUG_LOG("input_attachment_count [%d]", local_attachment_count);
+
+ EM_DEBUG_LOG("preview_text[%p]", input_mail_data->preview_text);
+ if (input_mail_data->preview_text == NULL) {
+ if ( (err = em_core_get_preview_text_from_file(input_mail_data->file_path_plain, input_mail_data->file_path_html, MAX_PREVIEW_TEXT_LENGTH, &(input_mail_data->preview_text))) != EMF_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("em_core_get_preview_text_from_file failed[%d]", err);
+ goto FINISH_OFF;
+ }
+ }
+
+ if (!em_convert_mail_data_to_mail_tbl(input_mail_data, 1, &converted_mail_tbl, &err)) {
+ EM_DEBUG_EXCEPTION("em_convert_mail_data_to_mail_tbl failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ /* Fill address information */
+ em_core_fill_address_information_of_mail_tbl(converted_mail_tbl);
+
+ /* Fill thread id */
+ if(input_mail_data->thread_id == 0) {
+ if (em_storage_get_thread_id_of_thread_mails(converted_mail_tbl, &thread_id, &latest_mail_id_in_thread, &thread_item_count) != EMF_ERROR_NONE)
+ EM_DEBUG_LOG(" em_storage_get_thread_id_of_thread_mails is failed");
+
+ if (thread_id == -1) {
+ converted_mail_tbl->thread_id = input_mail_data->mail_id;
+ converted_mail_tbl->thread_item_count = thread_item_count = 1;
+ }
+ else {
+ converted_mail_tbl->thread_id = thread_id;
+ thread_item_count++;
+ }
+ }
+ else {
+ thread_item_count = 2;
+ }
+
+ em_storage_begin_transaction(NULL, NULL, NULL);
+
+ /* insert mail to mail table */
+ if (!em_storage_add_mail(converted_mail_tbl, 0, false, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_add_mail failed [%d]", err);
+ /* ROLLBACK TRANSACTION; */
+ em_storage_rollback_transaction(NULL, NULL, NULL);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+
+ /* Update thread information */
+ EM_DEBUG_LOG("thread_item_count [%d]", thread_item_count);
+
+ if (thread_item_count > 1) {
+ if (!em_storage_update_latest_thread_mail(input_mail_data->account_id, converted_mail_tbl->thread_id, 0, 0, false, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_update_latest_thread_mail failed [%d]", err);
+ em_storage_rollback_transaction(NULL, NULL, NULL);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+ }
+
+ /* Insert attachment information to DB */
+
+ for (i = 0; i < input_attachment_count; i++) {
+ if (input_attachment_data_list[i].attachment_size == 0) {
+ /* set attachment size */
+ if(input_attachment_data_list[i].attachment_path && stat(input_attachment_data_list[i].attachment_path, &st_buf) < 0)
+ input_attachment_data_list[i].attachment_size = st_buf.st_size;
+ }
+
+ if (!input_attachment_data_list[i].inline_content_status) {
+ if (!em_storage_get_new_attachment_no(&attachment_id, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_get_new_attachment_no failed [%d]", err);
+ em_storage_rollback_transaction(NULL, NULL, NULL);
+ goto FINISH_OFF;
+ }
+ }
+
+ if (!em_storage_create_dir(input_mail_data->account_id, input_mail_data->mail_id, input_attachment_data_list[i].inline_content_status ? 0 : attachment_id, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_create_dir failed [%d]", err);
+ em_storage_rollback_transaction(NULL, NULL, NULL);
+ goto FINISH_OFF;
+ }
+
+ if (!em_storage_get_save_name(input_mail_data->account_id, input_mail_data->mail_id, input_attachment_data_list[i].inline_content_status ? 0 : attachment_id, input_attachment_data_list[i].attachment_name, name_buf, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_get_save_name failed [%d]", err);
+ em_storage_rollback_transaction(NULL, NULL, NULL);
+ goto FINISH_OFF;
+ }
+
+ if (input_sync_server || input_attachment_data_list[i].save_status) {
+ if (!em_storage_copy_file(input_attachment_data_list[i].attachment_path, name_buf, input_sync_server, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_copy_file failed [%d]", err);
+ em_storage_rollback_transaction(NULL, NULL, NULL);
+ goto FINISH_OFF;
+ }
+
+ if ((ext = strrchr(input_attachment_data_list[i].attachment_name, '.'))) {
+ if (!strncmp(ext, ".vcs", strlen(".vcs")))
+ remove(input_attachment_data_list[i].attachment_path);
+ else if (!strncmp(ext, ".vcf", strlen(".vcf")))
+ remove(input_attachment_data_list[i].attachment_path);
+ else if (!strncmp(ext, ".vnt", strlen(".vnt")))
+ remove(input_attachment_data_list[i].attachment_path);
+ }
+ }
+
+ memset(&attachment_tbl, 0, sizeof(emf_mail_attachment_tbl_t));
+ attachment_tbl.attachment_name = input_attachment_data_list[i].attachment_name;
+ attachment_tbl.attachment_path = name_buf;
+ attachment_tbl.attachment_size = input_attachment_data_list[i].attachment_size;
+ attachment_tbl.mail_id = input_mail_data->mail_id;
+ attachment_tbl.account_id = input_mail_data->account_id;
+ attachment_tbl.mailbox_name = input_mail_data->mailbox_name;
+ attachment_tbl.file_yn = input_attachment_data_list[i].save_status;
+ attachment_tbl.flag2 = input_attachment_data_list[i].drm_status;
+ attachment_tbl.flag3 = input_attachment_data_list[i].inline_content_status;
+
+ if (!em_storage_add_attachment(&attachment_tbl, 0, false, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_add_attachment failed [%d]", err);
+ em_storage_rollback_transaction(NULL, NULL, NULL);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+ input_attachment_data_list[i].attachment_id = attachment_tbl.attachment_id;
+ }
+
+ /* Insert Meeting request to DB */
+ if (input_mail_data->meeting_request_status == EMF_MAIL_TYPE_MEETING_REQUEST
+ || input_mail_data->meeting_request_status == EMF_MAIL_TYPE_MEETING_RESPONSE
+ || input_mail_data->meeting_request_status == EMF_MAIL_TYPE_MEETING_ORIGINATINGREQUEST) {
+ EM_DEBUG_LOG("This mail has the meeting request");
+ input_meeting_request->mail_id = input_mail_data->mail_id;
+ if (!em_storage_add_meeting_request(input_mail_data->account_id, mailbox_name_target, input_meeting_request, false, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_add_meeting_request failed [%d]", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+ }
+
+ em_storage_commit_transaction(NULL, NULL, NULL);
+
+ if (!em_storage_notify_storage_event(NOTI_MAIL_ADD, converted_mail_tbl->account_id, converted_mail_tbl->mail_id, mailbox_name_target, converted_mail_tbl->thread_id))
+ EM_DEBUG_LOG("em_storage_notify_storage_event [NOTI_MAIL_ADD] failed.");
+
+ if (account_tbl_item->receiving_server_type != EMF_SERVER_TYPE_ACTIVE_SYNC) {
+ if (!em_core_mailbox_remove_overflowed_mails(mailbox_tbl, &err)) {
+ if (err == EM_STORAGE_ERROR_MAIL_NOT_FOUND || err == EMF_ERROR_NOT_SUPPORTED)
+ err = EMF_ERROR_NONE;
+ else
+ EM_DEBUG_LOG("em_core_mailbox_remove_overflowed_mails failed [%d]", err);
+ }
+ }
+
+ if ( !input_sync_server && (input_mail_data->flags_seen_field == 0)
+ && input_mail_data->mailbox_type != EMF_MAILBOX_TYPE_TRASH
+ && input_mail_data->mailbox_type != EMF_MAILBOX_TYPE_SPAMBOX) {
+ if (!em_storage_update_sync_status_of_account(input_mail_data->account_id, SET_TYPE_SET, SYNC_STATUS_SYNCING | SYNC_STATUS_HAVE_NEW_MAILS, true, &err))
+ EM_DEBUG_LOG("em_storage_update_sync_status_of_account failed [%d]", err);
+ em_core_add_notification_for_unread_mail(input_mail_data);
+ em_core_check_unread_mail();
+ }
+
+FINISH_OFF:
+ if (account_tbl_item)
+ em_storage_free_account(&account_tbl_item, 1, NULL);
+
+ if (mailbox_tbl)
+ em_storage_free_mailbox(&mailbox_tbl, 1, NULL);
+
+ if (converted_mail_tbl)
+ em_storage_free_mail(&converted_mail_tbl, 1, NULL);
+
+ EM_SAFE_FREE(mailbox_name_spam);
+ EM_SAFE_FREE(mailbox_name_target);
+
+ EM_DEBUG_FUNC_END();
+ return err;
+}
+
+EXPORT_API int
+em_core_mail_add_meeting_request(int account_id, char *mailbox_name, emf_meeting_request_t *meeting_req, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("account_id[%d], mailbox_name[%s], meeting_req[%p], err_code[%p]", account_id, mailbox_name, meeting_req, err_code);
+ int ret = false;
+ int err = EMF_ERROR_NONE;
+
+ if (!meeting_req || meeting_req->mail_id <= 0) {
+ if (meeting_req)
+ EM_DEBUG_EXCEPTION("mail_id[%d]", meeting_req->mail_id);
+
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ if (!em_storage_add_meeting_request(account_id, mailbox_name, meeting_req, 1, &err)) {
+ EM_DEBUG_EXCEPTION(" em_storage_add_meeting_request failed [%d]", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+
+ ret = true;
+
+FINISH_OFF:
+
+ if (err_code)
+ *err_code = err;
+
+ EM_DEBUG_FUNC_END();
+ return ret;
+}
+
+/* send a message (not saved) */
+EXPORT_API int em_core_mail_send(int account_id, char *input_mailbox_name, int mail_id, emf_option_t *sending_option, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("account_id[%d], input_mailbox_name[%s], mail_id[%d], sending_option[%p], err_code[%p]", account_id, input_mailbox_name, mail_id, sending_option, err_code);
+ EM_PROFILE_BEGIN(profile_em_core_mail_send);
+ int ret = false;
+ int err = EMF_ERROR_NONE, err2 = EMF_ERROR_NONE;
+ int status = EMF_SEND_FAIL;
+
+ SENDSTREAM *stream = NULL;
+ ENVELOPE *envelope = NULL;
+ sslstart_t stls = NULL;
+ emf_mail_t *mail = NULL;
+ emf_account_t *ref_account = NULL;
+ emf_option_t *opt = NULL;
+ emf_mailbox_t dest_mbox = {0};
+ void *tmp_stream = NULL;
+ char *fpath = NULL;
+ int sent_box = 0;
+ char *mailbox_name = NULL;
+
+ if (!account_id || !mail_id) {
+ EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ if (!(ref_account = em_core_get_account_reference(account_id))) {
+ EM_DEBUG_EXCEPTION("em_core_get_account_reference failed [%d]", account_id);
+ err = EMF_ERROR_INVALID_ACCOUNT;
+ goto FINISH_OFF;
+ }
+
+ /* get mail to send */
+ if (!em_core_mail_get_mail(mail_id, &mail, &err)) {
+ EM_DEBUG_EXCEPTION("em_core_mail_get_mail failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ if (!em_core_check_send_mail_thread_status()) {
+ EM_DEBUG_EXCEPTION("em_core_check_send_mail_thread_status failed...");
+ err = EMF_ERROR_CANCELLED;
+ goto FINISH_OFF;
+ }
+
+ if ((!mail->head->to) && (!mail->head->cc) && (!mail->head->bcc)) {
+ err = EMF_ERROR_NO_RECIPIENT;
+ EM_DEBUG_EXCEPTION("No Recipient information [%d]", err);
+ goto FINISH_OFF;
+ }
+ else {
+ if (!em_core_verify_email_address_of_mail_header(mail->head, false, &err)) {
+ err = EMF_ERROR_INVALID_ADDRESS;
+ EM_DEBUG_EXCEPTION("em_core_verify_email_address_of_mail_header failed [%d]", err);
+ goto FINISH_OFF;
+ }
+ }
+
+ if (mail->info)
+ mail->info->account_id = account_id;
+
+ if (!em_core_check_send_mail_thread_status()) {
+ EM_DEBUG_EXCEPTION("em_core_check_send_mail_thread_status failed...");
+ err = EMF_ERROR_CANCELLED;
+ goto FINISH_OFF;
+ }
+
+ if (sending_option != NULL)
+ opt = sending_option;
+ else
+ opt = em_core_get_option(&err);
+
+
+ /*Update status flag to DB*/
+
+ /* get rfc822 data */
+ if (!em_core_mail_get_rfc822(mail, &envelope, &fpath, opt, &err)) {
+ EM_DEBUG_EXCEPTION("em_core_mail_get_rfc822 failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ if (!envelope || (!envelope->to && !envelope->cc && !envelope->bcc)) {
+ EM_DEBUG_EXCEPTION(" no recipients found...");
+
+ err = EMF_ERROR_NO_RECIPIENT;
+ goto FINISH_OFF;
+ }
+
+ /* if there is no security option, unset security. */
+ if (!ref_account->sending_security) {
+ stls = (sslstart_t)mail_parameters(NULL, GET_SSLSTART, NULL);
+ mail_parameters(NULL, SET_SSLSTART, NULL);
+ }
+
+ if (!em_core_check_send_mail_thread_status()) {
+ EM_DEBUG_EXCEPTION("em_core_check_send_mail_thread_status failed...");
+ err = EMF_ERROR_CANCELLED;
+ goto FINISH_OFF;
+ }
+
+ if (ref_account->pop_before_smtp != FALSE) {
+ if (!em_core_mailbox_open(account_id, NULL, (void **)&tmp_stream, &err)) {
+ EM_DEBUG_EXCEPTION(" POP before SMTP Authentication failed [%d]", err);
+ status = EMF_LIST_CONNECTION_FAIL;
+ if (err == EMF_ERROR_CONNECTION_BROKEN)
+ err = EMF_ERROR_CANCELLED;
+ goto FINISH_OFF;
+ }
+ }
+
+
+ if (!em_storage_get_mailboxname_by_mailbox_type(account_id, EMF_MAILBOX_TYPE_DRAFT, &mailbox_name, false, &err)) {
+ EM_DEBUG_EXCEPTION(" em_storage_get_mailboxname_by_mailbox_type failed [%d]", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+
+ if (!em_core_mailbox_open(account_id, (char *)ENCODED_PATH_SMTP, (void **)&tmp_stream, &err)) {
+ EM_DEBUG_EXCEPTION(" em_core_mailbox_open failed [%d]", err);
+
+ if (err == EMF_ERROR_CONNECTION_BROKEN)
+ err = EMF_ERROR_CANCELLED;
+
+ status = EMF_SEND_CONNECTION_FAIL;
+ goto FINISH_OFF;
+ }
+
+ stream = (SENDSTREAM *)tmp_stream;
+
+ if (!em_core_check_send_mail_thread_status()) {
+ EM_DEBUG_EXCEPTION(" em_core_check_send_mail_thread_status failed...");
+ err = EMF_ERROR_CANCELLED;
+ goto FINISH_OFF;
+ }
+
+ /* set request of delivery status. */
+ if (opt->req_delivery_receipt == EMF_OPTION_REQ_DELIVERY_RECEIPT_ON) {
+ stream->protocol.esmtp.dsn.want = 1;
+ stream->protocol.esmtp.dsn.full = 0;
+ stream->protocol.esmtp.dsn.notify.failure = 1;
+ stream->protocol.esmtp.dsn.notify.success = 1;
+ EM_DEBUG_LOG("opt->req_delivery_receipt == EMF_OPTION_REQ_DELIVERY_RECEIPT_ON");
+ }
+
+ mail->info->extra_flags.status = EMF_MAIL_STATUS_SENDING;
+
+ /*Update status flag to DB*/
+ if (!em_core_mail_modify_extra_flag(mail_id, mail->info->extra_flags, &err))
+ EM_DEBUG_EXCEPTION("Failed to modify extra flag [%d]", err);
+
+ /* send mail to server. */
+ if (!em_core_mail_send_smtp(stream, envelope, fpath, account_id, mail_id, &err)) {
+ EM_DEBUG_EXCEPTION(" em_core_mail_send_smtp failed [%d]", err);
+
+
+#ifndef __FEATURE_MOVE_TO_OUTBOX_FIRST__
+ EM_SAFE_FREE(mailbox_name);
+ if (!em_storage_get_mailboxname_by_mailbox_type(account_id, EMF_MAILBOX_TYPE_OUTBOX, &mailbox_name, false, &err)) {
+ EM_DEBUG_EXCEPTION(" em_storage_get_mailboxname_by_mailbox_type failed [%d]", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+ dest_mbox.name = mailbox_name;
+ dest_mbox.account_id = account_id;
+
+ /* unsent mail is moved to 'OUTBOX'. */
+ if (!em_core_mail_move(&mail_id, 1, dest_mbox.name, EMF_MOVED_BY_COMMAND, 0, NULL))
+ EM_DEBUG_EXCEPTION(" em_core_mail_move falied...");
+#endif
+
+
+ goto FINISH_OFF;
+ }
+
+ /* sent mail is moved to 'SENT' box or deleted. */
+ if (opt->keep_local_copy) {
+ EM_SAFE_FREE(mailbox_name);
+
+ if (!em_storage_get_mailboxname_by_mailbox_type(account_id, EMF_MAILBOX_TYPE_SENTBOX, &mailbox_name, false, &err)) {
+ EM_DEBUG_EXCEPTION(" em_storage_get_mailboxname_by_mailbox_type failed [%d]", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+ dest_mbox.name = mailbox_name;
+ dest_mbox.account_id = account_id;
+
+ if (!em_core_mail_move(&mail_id, 1, dest_mbox.name, EMF_MOVED_AFTER_SENDING, 0, &err))
+ EM_DEBUG_EXCEPTION(" em_core_mail_move falied [%d]", err);
+#ifdef __FEATURE_SYNC_CLIENT_TO_SERVER__
+#ifdef __LOCAL_ACTIVITY__
+ else if (ref_account->receiving_server_type == EMF_SERVER_TYPE_IMAP4) /* To be synced to Sent box only IMAP not for POP */ {
+
+ emf_activity_tbl_t new_activity;
+ int activityid = 0;
+
+ if (false == em_core_get_next_activity_id(&activityid, &err)) {
+ EM_DEBUG_EXCEPTION(" em_core_get_next_activity_id Failed [%d] ", err);
+ }
+
+ memset(&new_activity, 0x00, sizeof(emf_activity_tbl_t));
+ new_activity.activity_id = activityid;
+ new_activity.server_mailid = NULL;
+ new_activity.account_id = account_id;
+ new_activity.mail_id = mail_id;
+ new_activity.activity_type = ACTIVITY_SAVEMAIL;
+ new_activity.dest_mbox = NULL;
+ new_activity.src_mbox = NULL;
+
+ if (!em_core_activity_add(&new_activity, &err)) {
+ EM_DEBUG_EXCEPTION(" em_core_activity_add Failed [%d] ", err);
+ }
+
+ if (!em_core_mail_move_from_server(dest_mbox.account_id, mailbox_name, &mail_id, 1, dest_mbox.name, &err)) {
+ EM_DEBUG_EXCEPTION(" em_core_mail_move_from_server falied [%d]", err);
+ }
+ else {
+ /* Remove ACTIVITY_SAVEMAIL activity */
+ new_activity.activity_id = activityid;
+ new_activity.activity_type = ACTIVITY_SAVEMAIL;
+ new_activity.account_id = account_id;
+ new_activity.mail_id = mail_id;
+ new_activity.dest_mbox = NULL;
+ new_activity.server_mailid = NULL;
+ new_activity.src_mbox = NULL;
+
+ if (!em_core_activity_delete(&new_activity, &err)) {
+ EM_DEBUG_EXCEPTION(">>>>>>Local Activity [ACTIVITY_SAVEMAIL] [%d] ", err);
+ }
+ }
+ sent_box = 1;
+ }
+#endif
+#endif
+
+ /* On Successful Mail sent remove the Draft flag */
+ emf_mail_flag_t update_flag;
+ if (mail->info)
+ memcpy(&update_flag, &(mail->info->flags), sizeof(emf_mail_flag_t));
+ else
+ memset(&update_flag, 0x00, sizeof(emf_mail_flag_t));
+ update_flag.draft = 0;
+ int sticky_flag = 1;
+ if (!em_core_mail_modify_flag(mail_id, update_flag, sticky_flag, &err))
+ EM_DEBUG_EXCEPTION(" Flag Modification Failed [ %d] ", err);
+ sent_box = 1;
+ }
+ else {
+ if (!em_core_mail_delete(account_id, &mail_id, 1, 0, EMF_DELETED_AFTER_SENDING, false, &err))
+ EM_DEBUG_EXCEPTION(" em_core_mail_delete failed [%d]", err);
+ }
+
+ /*Update status flag to DB*/
+ mail->info->extra_flags.status = EMF_MAIL_STATUS_SENT;
+ if (!em_core_mail_modify_extra_flag(mail_id, mail->info->extra_flags, &err))
+ EM_DEBUG_EXCEPTION("Failed to modify extra flag [%d]", err);
+ /*Update status flag to DB*/
+ if (!em_core_delete_transaction_info_by_mailId(mail_id))
+ EM_DEBUG_EXCEPTION(" em_core_delete_transaction_info_by_mailId failed for mail_id[%d]", mail_id);
+
+ ret = true;
+
+FINISH_OFF:
+ if (ret == false && err != EMF_ERROR_INVALID_PARAM && mail) {
+ if (err != EMF_ERROR_CANCELLED) {
+ mail->info->extra_flags.status = EMF_MAIL_STATUS_SEND_FAILURE;
+ if (!em_core_mail_modify_extra_flag(mail_id, mail->info->extra_flags, &err2))
+ EM_DEBUG_EXCEPTION("Failed to modify extra flag [%d]", err2);
+ }
+ else {
+ if (EMF_MAIL_STATUS_SEND_CANCELED == mail->info->extra_flags.status)
+ EM_DEBUG_LOG("EMF_MAIL_STATUS_SEND_CANCELED Already set for ");
+ else {
+ mail->info->extra_flags.status = EMF_MAIL_STATUS_SEND_CANCELED;
+ if (!em_core_mail_modify_extra_flag(mail_id, mail->info->extra_flags, &err2))
+ EM_DEBUG_EXCEPTION("Failed to modify extra flag [%d]", err2);
+ }
+ }
+ }
+
+#ifndef __FEATURE_KEEP_CONNECTION__
+ if (stream)
+ smtp_close(stream);
+#endif /* __FEATURE_KEEP_CONNECTION__ */
+ if (stls)
+ mail_parameters(NULL, SET_SSLSTART, (void *)stls);
+ if (mail)
+ em_core_mail_free(&mail, 1, NULL);
+ if (envelope)
+ mail_free_envelope(&envelope);
+
+ if (fpath) {
+ EM_DEBUG_LOG("REMOVE TEMP FILE : %s", fpath);
+ remove(fpath);
+ free(fpath);
+ }
+
+ if (ret == true) {
+ if (!em_storage_notify_network_event(NOTI_SEND_FINISH, account_id, NULL, mail_id, 0))
+ EM_DEBUG_EXCEPTION("em_storage_notify_network_event [NOTI_SEND_FINISH] Failed");
+ }
+ else {
+ if (!em_storage_notify_network_event(NOTI_SEND_FAIL, account_id, NULL, mail_id, err))
+ EM_DEBUG_EXCEPTION("em_storage_notify_network_event [NOTI_SEND_FAIL] Failed");
+ em_core_show_popup(mail_id, EMF_ACTION_SEND_MAIL, err);
+ }
+
+ EM_SAFE_FREE(mailbox_name);
+
+ if (err_code != NULL)
+ *err_code = err;
+ EM_PROFILE_END(profile_em_core_mail_send);
+ EM_DEBUG_FUNC_END("ret [%d], err [%d]", ret, err);
+ return ret;
+}
+
+/* send a saved message */
+EXPORT_API int em_core_mail_send_saved(int account_id, char *input_mailbox_name, emf_option_t *sending_option, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("account_id[%d], input_mailbox_name[%p], sending_option[%p], err_code[%p]", account_id, input_mailbox_name, sending_option, err_code);
+
+ int ret = false;
+ int err = EMF_ERROR_NONE;
+ int status = EMF_SEND_FAIL;
+
+ SENDSTREAM *stream = NULL;
+ ENVELOPE *envelope = NULL;
+ emf_mailbox_t dest_mbox = {0};
+ emf_mail_t *mail = NULL;
+ emf_account_t *ref_account = NULL;
+ emf_mail_tbl_t mail_table_data = {0};
+ emf_option_t *opt = NULL;
+ sslstart_t stls = NULL;
+ void *tmp_stream = NULL;
+ void *p = NULL;
+ char *fpath = NULL;
+ int mail_id = 0;
+ int handle = 0;
+ int i = 0;
+ int total = 0;
+ char *mailbox_name = NULL;
+
+ if (!account_id || !input_mailbox_name) {
+ EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ mail_send_notify(EMF_SEND_PREPARE, 0, 0, account_id, mail_id, err);
+
+ if (!(ref_account = em_core_get_account_reference(account_id))) {
+ EM_DEBUG_EXCEPTION("em_core_get_account_reference failed [%d]", account_id);
+ err = EMF_ERROR_INVALID_ACCOUNT;
+ goto FINISH_OFF;
+ }
+
+ FINISH_OFF_IF_CANCELED;
+
+ if (sending_option)
+ opt = sending_option;
+ else
+ opt = em_core_get_option(&err);
+
+ /* search mail. */
+ if (!em_storage_mail_search_start(NULL, account_id, input_mailbox_name, 0, &handle, &total, true, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_mail_search_start failed [%d]", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+
+ while (i++ < total) {
+ FINISH_OFF_IF_CANCELED;
+
+ p = NULL;
+ if (!em_storage_mail_search_result(handle, RETRIEVE_ID, (void **)&p, true, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_mail_search_result failed [%d]", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+
+ mail_id = (int)p;
+
+ if (!em_core_mail_get_mail(mail_id, &mail, &err)) {
+ EM_DEBUG_EXCEPTION("em_core_mail_get_mail failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ /* check for email_address validation */
+ if (!em_core_verify_email_address_of_mail_header(mail->head, false, &err)) {
+ EM_DEBUG_EXCEPTION("em_core_verify_email_address_of_mail_header failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ /* check that this mail was saved in offline-mode. */
+ if (mail->info->extra_flags.status != EMF_MAIL_STATUS_SAVED_OFFLINE) {
+ EM_DEBUG_EXCEPTION(" mail was not saved in offline mode...");
+ em_core_mail_free(&mail, 1, &err); mail = NULL;
+ continue;
+ }
+
+ if(!em_convert_mail_flag_to_mail_tbl(&(mail->info->flags), &mail_table_data, &err)) {
+ EM_DEBUG_EXCEPTION("em_convert_mail_flag_to_mail_tbl failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ mail_table_data.save_status = mail->info->extra_flags.status;
+ mail_table_data.lock_status = mail->info->extra_flags.lock;
+ mail_table_data.priority = mail->info->extra_flags.priority;
+ mail_table_data.report_status = mail->info->extra_flags.report;
+
+ mail->info->extra_flags.status = EMF_MAIL_STATUS_SENDING;
+
+ if (!em_core_mail_get_rfc822(mail, &envelope, &fpath, opt, &err)) {
+ EM_DEBUG_EXCEPTION("em_core_mail_get_rfc822 falied [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ FINISH_OFF_IF_CANCELED;
+
+ /* connect mail server. */
+ if (!stream) {
+ /* if there no security option, unset security. */
+ if (!ref_account->sending_security) {
+ stls = (sslstart_t)mail_parameters(NULL, GET_SSLSTART, NULL);
+ mail_parameters(NULL, SET_SSLSTART, NULL);
+ }
+
+ stream = NULL;
+ if (!em_core_mailbox_open(account_id, (char *)ENCODED_PATH_SMTP, &tmp_stream, &err) || !tmp_stream) {
+ EM_DEBUG_EXCEPTION("em_core_mailbox_open failed [%d]", err);
+
+ if (err == EMF_ERROR_CONNECTION_BROKEN)
+ err = EMF_ERROR_CANCELLED;
+
+ status = EMF_SEND_CONNECTION_FAIL;
+ goto FINISH_OFF;
+ }
+
+ stream = (SENDSTREAM *)tmp_stream;
+
+ FINISH_OFF_IF_CANCELED;
+
+ mail_send_notify(EMF_SEND_CONNECTION_SUCCEED, 0, 0, account_id, mail_id, err);
+
+ /* reqest of delivery status. */
+ if (opt && opt->req_delivery_receipt == EMF_OPTION_REQ_DELIVERY_RECEIPT_ON) {
+ stream->protocol.esmtp.dsn.want = 1;
+ stream->protocol.esmtp.dsn.full = 0;
+ stream->protocol.esmtp.dsn.notify.failure = 1;
+ stream->protocol.esmtp.dsn.notify.success = 1;
+ }
+
+ mail_send_notify(EMF_SEND_START, 0, 0, account_id, mail_id, err);
+ }
+
+ mail_table_data.save_status = EMF_MAIL_STATUS_SENDING;
+
+ /* update mail status to sending. */
+ if (!em_storage_change_mail_field(mail_id, UPDATE_EXTRA_FLAG, &mail_table_data, true, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_change_mail_field failed [%d]", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+
+ if (!em_core_mail_send_smtp(stream, envelope, fpath, account_id, mail_id, &err)) {
+ EM_DEBUG_EXCEPTION("em_core_mail_send_smtp failed [%d]", err);
+
+ mail_table_data.save_status = EMF_MAIL_STATUS_SEND_FAILURE;
+
+ /* update mail status to failure. */
+ if (!em_storage_change_mail_field(mail_id, UPDATE_EXTRA_FLAG, &mail_table_data, true, &err))
+ EM_DEBUG_EXCEPTION("em_storage_change_mail_field failed [%d]", err);
+
+ if (!em_storage_get_mailboxname_by_mailbox_type(account_id, EMF_MAILBOX_TYPE_OUTBOX, &mailbox_name, false, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_get_mailboxname_by_mailbox_type failed [%d]", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+ dest_mbox.name = mailbox_name;
+ dest_mbox.account_id = account_id;
+
+ em_core_mail_move(&mail_id, 1, dest_mbox.name, EMF_MOVED_AFTER_SENDING, 0, NULL);
+
+ goto FINISH_OFF;
+ }
+
+ mail_table_data.save_status = EMF_MAIL_STATUS_SENT;
+
+ /* update mail status to sent mail. */
+ if (!em_storage_change_mail_field(mail_id, UPDATE_EXTRA_FLAG, &mail_table_data, true, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_change_mail_field failed [%d]", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+
+ /* sent mail is moved to 'SENT' box or deleted. */
+ if (opt->keep_local_copy) {
+ EM_SAFE_FREE(mailbox_name);
+ if (!em_storage_get_mailboxname_by_mailbox_type(account_id, EMF_MAILBOX_TYPE_SENTBOX, &mailbox_name, false, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_get_mailboxname_by_mailbox_type failed [%d]", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+ dest_mbox.name = mailbox_name;
+ dest_mbox.account_id = account_id;
+
+ if (!em_core_mail_move(&mail_id, 1, dest_mbox.name, EMF_MOVED_AFTER_SENDING, 0, &err))
+ EM_DEBUG_EXCEPTION("em_core_mail_move falied [%d]", err);
+ }
+ else {
+ if (!em_core_mail_delete(account_id, &mail_id, 1, 0, EMF_DELETED_AFTER_SENDING, false, &err))
+ EM_DEBUG_EXCEPTION("em_core_mail_delete falied [%d]", err);
+ }
+
+ em_core_mail_free(&mail, 1, NULL); mail = NULL;
+ mail_free_envelope(&envelope); envelope = NULL;
+
+ if (fpath) {
+ remove(fpath);
+ EM_SAFE_FREE(fpath);
+ }
+ }
+
+
+ ret = true;
+
+FINISH_OFF:
+ if (stream)
+ smtp_close(stream);
+
+ if (stls)
+ mail_parameters(NIL, SET_SSLSTART, (void *)stls);
+
+ if (envelope)
+ mail_free_envelope(&envelope);
+
+ if (handle) {
+ if (!em_storage_mail_search_end(handle, true, &err))
+ EM_DEBUG_EXCEPTION("em_storage_mail_search_end failed [%d]", err);
+ }
+
+ if (mail)
+ em_core_mail_free(&mail, 1, NULL);
+
+ if (fpath) {
+ remove(fpath);
+ EM_SAFE_FREE(fpath);
+ }
+
+ EM_SAFE_FREE(mailbox_name);
+
+ if (ret == true)
+ mail_send_notify(EMF_SEND_FINISH, 0, 0, account_id, mail_id, err);
+ else {
+ mail_send_notify(status, 0, 0, account_id, mail_id, err);
+ em_core_show_popup(account_id, EMF_ACTION_SEND_MAIL, err);
+ }
+
+ if (err_code != NULL)
+ *err_code = err;
+
+ return ret;
+}
+
+static int em_core_mail_send_smtp(SENDSTREAM *stream, ENVELOPE *env, char *data_file, int account_id, int mail_id, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("stream[%p], env[%p], data_file[%s], account_id[%d], mail_id[%d], err_code[%p]", stream, env, data_file, account_id, mail_id, err_code);
+ EM_PROFILE_BEGIN(profile_em_core_mail_send_smtp);
+
+ int ret = false;
+ int err = EMF_ERROR_NONE;
+ int recipients = 0;
+ long total = 0, sent = 0, send_ret = 0, send_err = 0, sent_percent = 0, last_sent_percent = 0;
+ char buf[2048] = { 0, };
+ emf_account_t *ref_account = NULL;
+ FILE *fp = NULL;
+
+ if (!env || !env->from || (!env->to && !env->cc && !env->bcc)) {
+ if (env != NULL)
+ EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ if (!env->from->mailbox || !env->from->host) {
+ EM_DEBUG_EXCEPTION("env->from->mailbox[%p], env->from->host[%p]", env->from->mailbox, env->from->host);
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ if (!(ref_account = em_core_get_account_reference(account_id))) {
+ EM_DEBUG_EXCEPTION("em_core_get_account_reference failed [%d]", account_id);
+ err = EMF_ERROR_INVALID_ACCOUNT;
+ goto FINISH_OFF;
+ }
+
+ EM_DEBUG_LOG("Modifying - MAIL FROM ");
+ if (ref_account->email_addr == NULL) {
+ EM_DEBUG_LOG("ref_account->email_addr is null!!");
+ SNPRINTF(buf, sizeof(buf), "FROM:<%s@%s>", env->from->mailbox, env->from->host);
+ }
+ else
+ SNPRINTF(buf, sizeof(buf), "FROM:<%s>", ref_account->email_addr);
+
+ /* set DSN for ESMTP */
+ if (stream->protocol.esmtp.ok) {
+ if (stream->protocol.esmtp.eightbit.ok && stream->protocol.esmtp.eightbit.want)
+ strncat (buf, " BODY=8BITMIME", sizeof(buf)-(strlen(buf)+1));
+
+ if (stream->protocol.esmtp.dsn.ok && stream->protocol.esmtp.dsn.want) {
+ EM_DEBUG_LOG("stream->protocol.esmtp.dsn.want is required");
+ strncat (buf, stream->protocol.esmtp.dsn.full ? " RET=FULL" : " RET=HDRS", sizeof(buf)-strlen(buf)-1);
+ if (stream->protocol.esmtp.dsn.envid)
+ SNPRINTF (buf + strlen (buf), sizeof(buf)-(strlen(buf)), " ENVID=%.100s", stream->protocol.esmtp.dsn.envid);
+ }
+ else
+ EM_DEBUG_LOG("stream->protocol.esmtp.dsn.want is not required");
+ }
+
+ EM_PROFILE_BEGIN(profile_prepare_and_head);
+ send_ret = smtp_send(stream, "RSET", 0);
+ EM_DEBUG_LOG("[SMTP] RSET --------> %s", stream->reply);
+
+ if (send_ret != SMTP_RESPONSE_OK) {
+ err = send_ret;
+ goto FINISH_OFF;
+ }
+
+ send_ret = smtp_send(stream, "MAIL", buf);
+ EM_DEBUG_LOG("[SMTP] MAIL %s --------> %s", buf, stream->reply);
+
+ switch (send_ret) {
+ case SMTP_RESPONSE_OK:
+ break;
+
+ case SMTP_RESPONSE_WANT_AUTH :
+ case SMTP_RESPONSE_WANT_AUTH2:
+ EM_DEBUG_EXCEPTION("SMTP error : authentication required...");
+ err = EMF_ERROR_AUTHENTICATE;
+ goto FINISH_OFF;
+
+ case SMTP_RESPONSE_UNAVAIL:
+ EM_DEBUG_EXCEPTION("SMTP error : mailbox unavailable...");
+ err = EMF_ERROR_MAILBOX_FAILURE;
+ goto FINISH_OFF;
+
+ default:
+ err = send_ret;
+ goto FINISH_OFF;
+ }
+
+ if (env->to) {
+ send_ret = smtp_rcpt(stream, env->to, &send_err);
+ EM_DEBUG_LOG("[SMTP] RCPT TO : <%s@%s> ... --------> %s", env->to->mailbox, env->to->host, env->to->error ? env->to->error : stream->reply);
+ if (send_ret) {
+ err = stream->replycode;
+ goto FINISH_OFF;
+ }
+
+ if (!send_err)
+ recipients++;
+ }
+
+ if (env->cc) {
+ send_ret = smtp_rcpt(stream, env->cc, &send_err);
+ EM_DEBUG_LOG("[SMTP] RCPT TO : <%s@%s> ... --------> %s", env->cc->mailbox, env->cc->host, env->cc->error ? env->cc->error : stream->reply);
+ if (send_ret) {
+ err = stream->replycode;
+ goto FINISH_OFF;
+ }
+
+ if (!send_err)
+ recipients++;
+ }
+
+ if (env->bcc) {
+ send_ret = smtp_rcpt(stream, env->bcc, &send_err);
+ EM_DEBUG_LOG("[SMTP] RCPT TO : <%s@%s> ... --------> %s", env->bcc->mailbox, env->bcc->host, env->bcc->error ? env->bcc->error : stream->reply);
+ if (send_ret) {
+ err = stream->replycode;
+ goto FINISH_OFF;
+ }
+
+ if (!send_err)
+ recipients++;
+ }
+
+
+ if (send_err) {
+ EM_DEBUG_EXCEPTION("One or more recipients failed...");
+ err = EMF_ERROR_INVALID_ADDRESS;
+ }
+
+ if (!recipients) {
+ EM_DEBUG_EXCEPTION("No valid recipients...");
+
+ switch (stream->replycode) {
+ case SMTP_RESPONSE_UNAVAIL:
+ case SMTP_RESPONSE_WANT_AUTH :
+ case SMTP_RESPONSE_WANT_AUTH2:
+ err = EMF_ERROR_AUTH_REQUIRED;
+ break;
+
+ default:
+ err = EMF_ERROR_INVALID_ADDRESS;
+ break;
+ }
+ goto FINISH_OFF;
+ }
+
+ send_ret = smtp_send(stream, "DATA", 0);
+ EM_DEBUG_LOG("[SMTP] DATA --------> %s", stream->reply);
+ EM_PROFILE_END(profile_prepare_and_head);
+
+ if (send_ret != SMTP_RESPONSE_READY) {
+ err = send_ret;
+ goto FINISH_OFF;
+ }
+
+ if (data_file) {
+ EM_PROFILE_BEGIN(profile_open_file);
+ if (!(fp = fopen(data_file, "r+"))) {
+ EM_DEBUG_EXCEPTION("fopen(\"%s\") failed...", data_file);
+ err = EMF_ERROR_SYSTEM_FAILURE;
+ goto FINISH_OFF;
+ }
+ EM_PROFILE_END(profile_open_file);
+
+
+#ifdef __FEATURE_SEND_OPTMIZATION__
+ {
+ char *data = NULL;
+ int read_size, allocSize, dataSize, gMaxAllocSize = 40960; /* 40KB */
+
+ fseek(fp, 0, SEEK_END);
+ total = ftell(fp);
+ fseek(fp, 0, SEEK_SET);
+ EM_DEBUG_LOG("total size [%d]", total);
+
+ if (total < gMaxAllocSize)
+ allocSize = total + 1;
+ else
+ allocSize = gMaxAllocSize;
+
+ EM_PROFILE_BEGIN(profile_allocation);
+ /* Allocate a buffer of max 2MB to read from file */
+ data = (char *)em_core_malloc(allocSize);
+ allocSize--;
+ EM_PROFILE_END(profile_allocation);
+
+ if (NULL == data) {
+ err = EMF_ERROR_SMTP_SEND_FAILURE;
+ goto FINISH_OFF;
+ }
+
+ while (total) {
+ if (total < allocSize)
+ dataSize = total;
+ else
+ dataSize = allocSize;
+
+ memset(data, 0x0, dataSize+1);
+ read_size = fread(data, sizeof (char), dataSize, fp);
+
+ if (read_size != dataSize) {
+ /* read fail. */
+ EM_SAFE_FREE(data);
+ EM_DEBUG_EXCEPTION("Read from file failed");
+ err = EMF_ERROR_SMTP_SEND_FAILURE;
+ goto FINISH_OFF;
+ }
+ sent += read_size;
+
+ EM_DEBUG_LOG("before smtp_soutr_test");
+ if (!(send_ret = smtp_soutr_test(stream->netstream, data))) {
+ EM_SAFE_FREE(data);
+ EM_DEBUG_EXCEPTION("Failed to send the data ");
+ err = EMF_ERROR_SMTP_SEND_FAILURE;
+ goto FINISH_OFF;
+ }
+ else {
+ sent_percent = (int) ((double)sent / (double)total * 100.0);
+ if (last_sent_percent + 5 <= sent_percent) {
+ if (!em_storage_notify_network_event(NOTI_SEND_START, account_id, NULL, mail_id, sent_percent))
+ EM_DEBUG_EXCEPTION("em_storage_notify_network_event [NOTI_SEND_START] Failed >>>>");
+ last_sent_percent = sent_percent;
+ }
+ EM_DEBUG_LOG("Sent data Successfully. sent[%d] total[%d]", sent, total);
+ }
+ total -= dataSize;
+ }
+
+ EM_SAFE_FREE(data);
+ }
+#else
+ fseek(fp, 0, SEEK_END);
+ total = ftell(fp);
+ fseek(fp, 0, SEEK_SET);
+
+ while (fgets(buf, 1024, fp)) {
+#ifdef FEATURE_SEND_DATA_DEBUG
+ EM_DEBUG_LOG("%s", buf);
+#endif
+ sent += strlen(buf);
+
+ if (!(send_ret = smtp_soutr(stream->netstream, buf)))
+ break;
+ /* Sending Progress Notification */
+ sent_percent = (int) ((double)sent / (double)total * 100.0);
+ if (last_sent_percent + 5 <= sent_percent) {
+ /* Disabled Temporary
+ if (!em_storage_notify_network_event(NOTI_SEND_START, account_id, NULL, mail_id, sent_percent))
+ EM_DEBUG_EXCEPTION(" em_storage_notify_network_event [NOTI_SEND_START] Failed >>>>");
+ */
+ last_sent_percent = sent_percent;
+ }
+ }
+
+#endif
+ if (!send_ret) {
+ EM_DEBUG_EXCEPTION("smtp_soutr failed - %ld", send_ret);
+ err = EMF_ERROR_SMTP_SEND_FAILURE;
+ goto FINISH_OFF;
+ }
+ }
+
+ send_ret = smtp_send(stream, ".", 0);
+ EM_DEBUG_LOG("[SMTP] . --------> %s", stream->reply);
+
+ if (send_ret != SMTP_RESPONSE_OK) {
+ err = send_ret;
+ goto FINISH_OFF;
+ }
+
+ ret = true;
+
+FINISH_OFF:
+ if (ret == false)
+ smtp_send(stream, "RSET", 0);
+
+ if (err_code)
+ *err_code = err;
+
+ if (fp)
+ fclose(fp);
+ EM_PROFILE_END(profile_em_core_mail_send_smtp);
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+/* ------ rfc822 handle --------------------------------------------------- */
+#define RANDOM_NUMBER_LENGTH 35
+
+char *em_core_generate_content_id_string(const char *hostname, int *err)
+{
+ EM_DEBUG_FUNC_BEGIN("hostname[%p]", hostname);
+
+ if (!hostname) {
+ EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
+ if (err)
+ *err = EMF_ERROR_INVALID_PARAM;
+ return NULL;
+ }
+
+ int cid_length = RANDOM_NUMBER_LENGTH + strlen(hostname) + 2, random_number_1, random_number_2, random_number_3, random_number_4;
+ char *cid_string = NULL;
+
+ cid_string = malloc(cid_length);
+
+ if (!cid_string) {
+ if (err)
+ *err = EMF_ERROR_OUT_OF_MEMORY;
+ return NULL;
+ }
+
+ memset(cid_string, 0, cid_length);
+
+ srand(time(NULL) + rand());
+ random_number_1 = rand() * rand();
+ random_number_2 = rand() * rand();
+ random_number_3 = rand() * rand();
+ random_number_4 = rand() * rand();
+
+ SNPRINTF(cid_string, cid_length, "<%08x%08x%08x%08x@%s>", random_number_1, random_number_2, random_number_3, random_number_4, hostname);
+
+ if (err)
+ *err = EMF_ERROR_NONE;
+
+ EM_DEBUG_FUNC_END("cid_string [%s]", cid_string);
+ return cid_string;
+}
+
+
+/* ------ attach_part ----------------------------------------------------- */
+/* data : if filename NULL, content data. */
+/* else absolute path of file to be attached. */
+/* data_len : length of data. if filename not NULL, ignored. */
+/* file_name : attahcment name. */
+static int attach_part(BODY *body, const unsigned char *data, int data_len, char *filename, char *content_sub_type, int is_inline, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("body[%p], data[%s], data_len[%d], filename[%s], content_sub_type[%s], err_code[%p]", body, data, data_len, filename, content_sub_type, err_code);
+
+ int ret = false;
+ int error = EMF_ERROR_NONE;
+ int has_special_character = 0;
+ int base64_file_name_length = 0;
+ int i= 0;
+ gsize bytes_read;
+ gsize bytes_written;
+ char *encoded_file_name = NULL;
+ char *extension = NULL;
+ char *base64_file_name = NULL;
+ char *result_file_name = NULL;
+ char content_disposition[100] = { 0, };
+ PARAMETER *last_param = NULL;
+ PARAMETER *param = NULL;
+ PART *last_part = NULL;
+ PART *part = NULL;
+ SIZEDTEXT source_text;
+ GError *glib_error = NULL;
+ CHARSET *result_charset = NULL;
+
+ if (!body) {
+ EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
+ error = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ if (body->nested.part) {
+ last_part = body->nested.part;
+
+ if (last_part != NULL) {
+ while (last_part->next)
+ last_part = last_part->next;
+ }
+ }
+
+ /* PART */
+ part = mail_newbody_part();
+ if (part == NULL) {
+ EM_DEBUG_EXCEPTION("mail_newbody_part failed...");
+ error = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ part->next = NULL;
+
+ if (last_part)
+ last_part->next = part;
+ else
+ body->nested.part = part;
+
+ last_part = part;
+
+ /* set data.. */
+ /* content_data = (unsigned char *)fs_get(data_len + 1); */
+ /* memcpy(content_data, data, data_len); */
+ /* content_data[data_len] = 0; */
+
+ /* part->body.contents.text.data = content_data; */
+ /* part->body.contents.text.size = data_len; */
+
+ if (filename) { /* attachment */
+ source_text.data = (unsigned char*)filename;
+ source_text.size = strlen(filename);
+
+ result_charset = (CHARSET*)utf8_infercharset(&source_text);
+
+ if(result_charset) {
+ EM_DEBUG_LOG("return_charset->name [%s]", result_charset->name);
+ encoded_file_name = (char*)g_convert (filename, -1, "UTF-8", result_charset->name, &bytes_read, &bytes_written, &glib_error);
+ }
+ else {
+ i = 0;
+ while(filename[i]) {
+ if(filename[i++] & 0x80) {
+ has_special_character = 1;
+ break;
+ }
+ }
+ EM_DEBUG_LOG("has_special_character [%d]", has_special_character);
+ if(has_special_character)
+ encoded_file_name = (char*)g_convert (filename, -1, "UTF-8", "EUC-KR", &bytes_read, &bytes_written, &glib_error);
+ }
+
+ EM_DEBUG_LOG("encoded_file_name [%s]", encoded_file_name);
+
+ if(encoded_file_name == NULL)
+ encoded_file_name = strdup(filename);
+
+ if(!em_core_encode_base64(encoded_file_name, strlen(encoded_file_name), &base64_file_name, (unsigned long*)&base64_file_name_length, &error)) {
+ EM_DEBUG_EXCEPTION("em_core_encode_base64 failed. error [%d]", error);
+ goto FINISH_OFF;
+ }
+
+ result_file_name = em_core_replace_string(base64_file_name, "\015\012", "");
+
+ EM_DEBUG_LOG("base64_file_name_length [%d]", base64_file_name_length);
+
+ if(result_file_name) {
+ EM_SAFE_FREE(encoded_file_name);
+ encoded_file_name = em_core_malloc(strlen(result_file_name) + 15);
+ if(!encoded_file_name) {
+ EM_DEBUG_EXCEPTION("em_core_malloc failed.");
+ goto FINISH_OFF;
+ }
+ snprintf(encoded_file_name, strlen(result_file_name) + 15, "=?UTF-8?B?%s?=", result_file_name);
+ EM_DEBUG_LOG("encoded_file_name [%s]", encoded_file_name);
+ }
+
+ extension = em_core_get_extension_from_file_path(filename, NULL);
+
+ part->body.type = em_core_get_content_type(extension, NULL);
+ if(part->body.type == TYPEIMAGE)
+ part->body.subtype = strdup(extension);
+ else
+ part->body.subtype = cpystr("octet-stream");
+
+ part->body.encoding = ENCBINARY;
+ part->body.size.bytes = data_len;
+
+ if (data)
+ part->body.sparep = EM_SAFE_STRDUP((char *)data); /* file path */
+ else
+ part->body.sparep = NULL;
+
+ SNPRINTF(content_disposition, sizeof(content_disposition), "%s", "attachment");
+
+ part->body.disposition.type = cpystr(content_disposition);
+
+ /* BODY PARAMETER */
+ /* another parameter or get parameter-list from this function-parameter */
+ param = mail_newbody_parameter();
+ if (param == NULL) {
+ EM_DEBUG_EXCEPTION("mail_newbody_parameter failed...");
+ error = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ param->attribute = cpystr("name");
+ param->value = cpystr(encoded_file_name);
+ param->next = NULL;
+ last_param = param;
+ last_part->body.parameter = last_param;
+
+ if (is_inline) {
+ /* CONTENT-ID */
+ part->body.id = em_core_generate_content_id_string("com.samsung.slp.email", &error);
+ part->body.type = TYPEIMAGE;
+ /* EM_SAFE_FREE(part->body.subtype); */
+ /* part->body.subtype = EM_SAFE_STRDUP(content_sub_type); */
+ }
+
+ /* DISPOSITION PARAMETER */
+ param = mail_newbody_parameter();
+ if (param == NULL) {
+ EM_DEBUG_EXCEPTION("mail_newbody_parameter failed...");
+ error = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ param->attribute = cpystr("filename");
+ param->value = cpystr(encoded_file_name);
+ param->next = NULL;
+ last_param = param;
+ last_part->body.disposition.parameter = last_param;
+
+ if (is_inline)
+ last_part->body.disposition.type = EM_SAFE_STRDUP("inline");
+ }
+ else {
+ /* text body (plain/html) */
+ part->body.type = TYPETEXT;
+
+ part->body.size.bytes = data_len;
+ if (data)
+ part->body.sparep = EM_SAFE_STRDUP((char *)data); /* file path */
+ else
+ part->body.sparep = NULL;
+
+
+ if (!content_sub_type) {
+ /* Plain text body */
+ part->body.encoding = ENC8BIT;
+ part->body.subtype = cpystr("plain");
+ last_param = part->body.parameter;
+
+ if (last_param != NULL) {
+ while (last_param->next)
+ last_param = last_param->next;
+ }
+
+ param = mail_newbody_parameter();
+
+ if (param == NULL) {
+ EM_DEBUG_EXCEPTION("mail_newbody_parameter failed...");
+ error = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ param->attribute = cpystr("CHARSET");
+
+ if (data != NULL) {
+ gchar *extract_charset_plain = g_path_get_basename((const gchar *)data);
+ if (extract_charset_plain != NULL && extract_charset_plain[0] != '\0')
+ param->value = cpystr(extract_charset_plain);
+ g_free(extract_charset_plain);
+ }
+ else
+ param->value = cpystr("UTF-8");
+
+ if(!param->value)
+ param->value = cpystr("UTF-8");
+
+ param->next = NULL;
+
+ if (last_param != NULL)
+ last_param->next = param;
+ else
+ part->body.parameter = param;
+ }
+ else {
+ /* HTML text body */
+ part->body.encoding = ENC8BIT;
+ part->body.subtype = cpystr(content_sub_type);
+
+ last_param = part->body.parameter;
+
+ if (last_param != NULL) {
+ while (last_param->next)
+ last_param = last_param->next;
+ }
+
+ param = mail_newbody_parameter();
+
+ if (param == NULL) {
+ EM_DEBUG_EXCEPTION("mail_newbody_parameter failed...");
+ error = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ param->attribute = cpystr("CHARSET");
+
+ char *pHtml = NULL;
+ if (data != NULL) {
+ gchar *extract_charset = g_path_get_basename((const gchar *)data);
+ if (extract_charset != NULL) {
+ if ((pHtml = strstr(extract_charset, ".htm")) != NULL) {
+ extract_charset[pHtml-extract_charset] = '\0';
+ param->value = cpystr(extract_charset);
+ }
+ }
+
+ if(!param->value)
+ param->value = cpystr("UTF-8");
+
+ EM_SAFE_FREE(extract_charset);
+ }
+ else
+ param->value = cpystr("UTF-8");
+ param->next = NULL;
+
+ if (last_param != NULL)
+ last_param->next = param;
+ else
+ part->body.parameter = param;
+ }
+
+ /* NOTE : need to require this code. */
+ /* sprintf(content_disposition, "%s\0", "inline"); */
+ if (is_inline) {
+ SNPRINTF(content_disposition, sizeof(content_disposition), "%s", "inline");
+ part->body.disposition.type = cpystr(content_disposition);
+ }
+ }
+
+ ret = true;
+
+FINISH_OFF:
+ EM_SAFE_FREE(encoded_file_name);
+ EM_SAFE_FREE(base64_file_name);
+ if (err_code != NULL)
+ *err_code = error;
+ EM_DEBUG_FUNC_END();
+ return ret;
+}
+
+static PART *attach_mutipart_with_sub_type(BODY *parent_body, char *sub_type, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("parent_body[%p], sub_type [%s], err_code[%p]", parent_body, sub_type, err_code);
+
+ int error = EMF_ERROR_NONE;
+
+ PART *tail_part_cur = NULL;
+ PART *new_part = NULL;
+
+ if (!parent_body || !sub_type) {
+ EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
+ error = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ if (parent_body->nested.part) {
+ tail_part_cur = parent_body->nested.part;
+
+ if (tail_part_cur != NULL) {
+ while (tail_part_cur->next)
+ tail_part_cur = tail_part_cur->next;
+ }
+ }
+
+ new_part = mail_newbody_part();
+
+ if (new_part == NULL) {
+ EM_DEBUG_EXCEPTION("EMF_ERROR_OUT_OF_MEMORY");
+ error = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+
+ }
+
+ new_part->next = NULL;
+ new_part->body.type = TYPEMULTIPART;
+ new_part->body.subtype = EM_SAFE_STRDUP(sub_type);
+
+ if (tail_part_cur)
+ tail_part_cur->next = new_part;
+ else
+ parent_body->nested.part = new_part;
+
+FINISH_OFF:
+
+ if (err_code)
+ *err_code = error;
+
+ EM_DEBUG_FUNC_END();
+
+ return new_part;
+}
+
+static int attach_attachment_to_body(BODY **multipart_body, BODY *text_body, emf_attachment_info_t *atch, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("multipart_body[%p], text_body[%p], atch[%p], err_code[%p]", multipart_body, text_body, atch, err_code);
+
+ int ret = false;
+ int error = EMF_ERROR_NONE;
+ BODY *frame_body = NULL;
+ /* make multipart body(multipart frame_body..) .. that has not content.. */
+
+ if (!multipart_body || !text_body || !atch) {
+ EM_DEBUG_EXCEPTION(" multipart_body[%p], text_body[%p], atch[%p]", multipart_body, text_body, atch);
+ error = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ frame_body = mail_newbody();
+ if (frame_body == NULL) {
+ EM_DEBUG_EXCEPTION("mail_newbody failed...");
+ error = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ frame_body->type = TYPEMULTIPART;
+ frame_body->contents.text.data = NULL;
+ frame_body->contents.text.size = 0;
+ frame_body->size.bytes = 0;
+
+ /* insert original text_body to frame_body.. */
+ if (!attach_part(frame_body, text_body->sparep, 0, NULL, NULL, false, &error)) {
+ EM_DEBUG_EXCEPTION(" attach_part failed [%d]", error);
+ goto FINISH_OFF;
+ }
+
+ /* insert files.. */
+ emf_attachment_info_t *p = atch;
+ char *name = NULL;
+ struct stat st_buf;
+
+ while (p) {
+ EM_DEBUG_LOG("insert files - attachment id[%d]", p->attachment_id);
+ if (stat(p->savename, &st_buf) == 0) {
+ if (!p->name) {
+ if (!em_core_get_file_name(p->savename, &name, &error)) {
+ EM_DEBUG_EXCEPTION("em_core_get_file_name failed [%d]", error);
+ goto FINISH_OFF;
+ }
+ }
+ else
+ name = p->name;
+
+ if (!attach_part(frame_body, (unsigned char *)p->savename, 0, name, NULL, false, &error)) {
+ EM_DEBUG_EXCEPTION("attach_part failed [%d]", error);
+ goto FINISH_OFF;
+ }
+ }
+
+ p = p->next;
+ }
+
+ ret = true;
+
+FINISH_OFF:
+ if (ret == true)
+ *multipart_body = frame_body;
+ else if (frame_body != NULL)
+ mail_free_body(&frame_body);
+
+ if (err_code != NULL)
+ *err_code = error;
+ EM_DEBUG_FUNC_END();
+ return ret;
+}
+
+static char *em_core_encode_rfc2047_text(char *utf8_text, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("utf8_text[%s], err_code[%p]", utf8_text, err_code);
+
+ if (utf8_text == NULL) {
+ if (err_code != NULL)
+ *err_code = EMF_ERROR_INVALID_PARAM;
+ return NULL;
+ }
+
+ gsize len = strlen(utf8_text);
+
+ EM_DEBUG_FUNC_END();
+
+ if (len > 0)
+ return g_strdup_printf("=?UTF-8?B?%s?=", g_base64_encode((const guchar *)utf8_text, len));
+ else
+ return EM_SAFE_STRDUP("");
+}
+
+static void em_core_encode_rfc2047_address(ADDRESS *address, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("address[%p], err_code[%p]", address, err_code);
+
+ while (address) {
+ if (address->personal) {
+ char *rfc2047_personal = em_core_encode_rfc2047_text(address->personal, err_code);
+ EM_SAFE_FREE(address->personal);
+ address->personal = rfc2047_personal;
+ }
+ address = address->next;
+ }
+ EM_DEBUG_FUNC_END();
+}
+
+#define DATE_STR_LENGTH 100
+/* Description : send mail to network(and save to sent-mailbox) or draft-mailbox, */
+/* Parameters : */
+/* mail : */
+/* is_draft : this mail is draft mail. */
+/* file_path : path of file that rfc822 data will be written to. */
+EXPORT_API int em_core_mail_get_rfc822(emf_mail_t *mail, ENVELOPE **env, char **file_path, emf_option_t *sending_option, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("mail[%p], env[%p], file_path[%p], sending_option[%p], err_code[%p]", mail, env, file_path, sending_option, err_code);
+
+ int ret = false;
+ int error = EMF_ERROR_NONE;
+
+ ENVELOPE *envelope = NULL;
+ BODY *text_body = NULL, *html_body = NULL;
+ BODY *root_body = NULL;
+ PART *part_for_html = NULL, *part_for_text = NULL;
+ emf_extra_flag_t extra_flag;
+ char *fname = NULL;
+ int is_incomplete = 0;
+ emf_account_t *ref_account = NULL;
+ char *pAdd = NULL;
+
+ if (!mail || !mail->info || !mail->head) {
+ if (mail != NULL)
+ EM_DEBUG_EXCEPTION("mail->info[%p], mail->head[%p]", mail->info, mail->head);
+
+ error = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ if (mail->info->extra_flags.report != EMF_MAIL_REPORT_MDN && !mail->body) {
+ EM_DEBUG_EXCEPTION("mail->body[%p]", mail->body);
+ error = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+
+ ref_account = em_core_get_account_reference(mail->info->account_id);
+ if (!ref_account) {
+ EM_DEBUG_EXCEPTION("em_core_get_account_reference failed [%d]", mail->info->account_id);
+ error = EMF_ERROR_INVALID_ACCOUNT;
+ goto FINISH_OFF;
+ }
+
+ if (!(envelope = mail_newenvelope())) {
+ EM_DEBUG_EXCEPTION("mail_newenvelope failed...");
+ error = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ is_incomplete = mail->info->flags.draft || (mail->info->extra_flags.status == EMF_MAIL_STATUS_SENDING);/* 4 */
+
+ if (is_incomplete) {
+ if (ref_account->email_addr && ref_account->email_addr[0] != '\0') {
+ char *p = cpystr(ref_account->email_addr);
+
+ if (p == NULL) {
+ EM_DEBUG_EXCEPTION("cpystr failed...");
+ error = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ EM_DEBUG_LOG("Assign envelop->from");
+ if (mail->head && mail->head->from) {
+ char *pAdd = NULL ;
+ em_core_skip_whitespace(mail->head->from , &pAdd);
+ EM_DEBUG_LOG("address[pAdd][%s]", pAdd);
+
+ rfc822_parse_adrlist(&envelope->from, pAdd, ref_account->sending_server_addr);
+ EM_SAFE_FREE(pAdd);
+ pAdd = NULL ;
+ }
+ else
+ envelope->from = rfc822_parse_mailbox(&p, NULL);
+
+
+ EM_SAFE_FREE(p);
+ if (!envelope->from) {
+ EM_DEBUG_EXCEPTION("rfc822_parse_mailbox failed...");
+
+ error = EMF_ERROR_INVALID_ADDRESS;
+ goto FINISH_OFF;
+ }
+ else {
+
+ if (envelope->from->personal == NULL) {
+ if (sending_option && sending_option->display_name_from && sending_option->display_name_from[0] != '\0')
+ envelope->from->personal = cpystr(sending_option->display_name_from);
+ else
+ envelope->from->personal = (ref_account->display_name && ref_account->display_name[0] != '\0') ? cpystr(ref_account->display_name) : NULL;
+ }
+ }
+ }
+
+ if (ref_account->return_addr && ref_account->return_addr[0] != '\0') {
+ char *p = cpystr(ref_account->return_addr);
+
+ if (p == NULL) {
+ EM_DEBUG_EXCEPTION("cpystr failed...");
+
+ error = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+ envelope->return_path = rfc822_parse_mailbox(&p, NULL);
+ EM_SAFE_FREE(p);
+ }
+ }
+ else {
+ if (!mail->head->from || !mail->head->to) {
+ EM_DEBUG_EXCEPTION("mail->head->from[%p], mail->head->to[%p]", mail->head->from, mail->head->to);
+ error = EMF_ERROR_INVALID_MAIL;
+ goto FINISH_OFF;
+ }
+
+ int i, j;
+
+ if (mail->head->from) {
+ for (i = 0, j = strlen(mail->head->from); i < j; i++) {
+ if (mail->head->from[i] == ';')
+ mail->head->from[i] = ',';
+ }
+ }
+
+ if (mail->head->return_path) {
+ for (i = 0, j = strlen(mail->head->return_path); i < j; i++) {
+ if (mail->head->return_path[i] == ';')
+ mail->head->return_path[i] = ',';
+ }
+ }
+ em_core_skip_whitespace(mail->head->from , &pAdd);
+ EM_DEBUG_LOG("address[pAdd][%s]", pAdd);
+
+ rfc822_parse_adrlist(&envelope->from, pAdd, ref_account->sending_server_addr);
+ EM_SAFE_FREE(pAdd);
+ pAdd = NULL ;
+
+ em_core_skip_whitespace(mail->head->return_path , &pAdd);
+ EM_DEBUG_LOG("address[pAdd][%s]", pAdd);
+
+ rfc822_parse_adrlist(&envelope->return_path, pAdd, ref_account->sending_server_addr);
+ EM_SAFE_FREE(pAdd);
+ pAdd = NULL ;
+ }
+
+ {
+ int i, j;
+
+ if (mail->head->to) {
+ for (i = 0, j = strlen(mail->head->to); i < j; i++) {
+ if (mail->head->to[i] == ';')
+ mail->head->to[i] = ',';
+ }
+ }
+
+ if (mail->head->cc) {
+ for (i = 0, j = strlen(mail->head->cc); i < j; i++) {
+ if (mail->head->cc[i] == ';')
+ mail->head->cc[i] = ',';
+ }
+ }
+
+ if (mail->head->bcc) {
+ for (i = 0, j = strlen(mail->head->bcc); i < j; i++) {
+ if (mail->head->bcc[i] == ';')
+ mail->head->bcc[i] = ',';
+ }
+ }
+ }
+
+ em_core_skip_whitespace(mail->head->to , &pAdd);
+ EM_DEBUG_LOG("address[pAdd][%s]", pAdd);
+
+ rfc822_parse_adrlist(&envelope->to, pAdd, ref_account->sending_server_addr);
+ EM_SAFE_FREE(pAdd);
+ pAdd = NULL ;
+
+ EM_DEBUG_LOG("address[mail->head->cc][%s]", mail->head->cc);
+ em_core_skip_whitespace(mail->head->cc , &pAdd);
+ EM_DEBUG_LOG("address[pAdd][%s]", pAdd);
+
+ rfc822_parse_adrlist(&envelope->cc, pAdd, ref_account->sending_server_addr);
+ EM_SAFE_FREE(pAdd);
+ pAdd = NULL ;
+
+ em_core_skip_whitespace(mail->head->bcc , &pAdd);
+ rfc822_parse_adrlist(&envelope->bcc, pAdd, ref_account->sending_server_addr);
+ EM_SAFE_FREE(pAdd);
+ pAdd = NULL ;
+
+ em_core_encode_rfc2047_address(envelope->return_path, &error);
+ em_core_encode_rfc2047_address(envelope->from, &error);
+ em_core_encode_rfc2047_address(envelope->sender, &error);
+ em_core_encode_rfc2047_address(envelope->reply_to, &error);
+ em_core_encode_rfc2047_address(envelope->to, &error);
+ em_core_encode_rfc2047_address(envelope->cc, &error);
+ em_core_encode_rfc2047_address(envelope->bcc, &error);
+
+ if (mail->head->subject)
+ envelope->subject = em_core_encode_rfc2047_text(mail->head->subject, &error);
+
+ char date_str[DATE_STR_LENGTH + 1] = { 0, };
+
+ rfc822_date(date_str);
+
+ if (!is_incomplete) {
+ struct tm tm1;
+
+ /* modified by stonyroot - prevent issue */
+ memset(&tm1, 0x00, sizeof(tm1));
+
+ tm1.tm_year = mail->head->datetime.year - 1900;
+ tm1.tm_mon = mail->head->datetime.month - 1;
+ tm1.tm_mday = mail->head->datetime.day;
+ tm1.tm_hour = mail->head->datetime.hour;
+ tm1.tm_min = mail->head->datetime.minute;
+ tm1.tm_sec = mail->head->datetime.second;
+
+ /* tzset(); */
+ time_t t = mktime(&tm1);
+
+ char buf[256] = {0, };
+
+ if (localtime(&t))
+ strftime(buf, 128, "%a, %e %b %Y %H : %M : %S ", localtime(&t));
+ else
+ strftime(buf, 128, "%a, %e %b %Y %H : %M : %S ", (const struct tm *)&tm1);
+ /* append last 5byes("+0900") */
+ strncat(buf, date_str + (strlen(date_str) - 5), DATE_STR_LENGTH);
+ strncpy(date_str, buf, DATE_STR_LENGTH);
+ }
+
+ envelope->date = (unsigned char *)cpystr((const char *)date_str);
+
+ memcpy(&extra_flag, &mail->info->extra_flags, sizeof(emf_extra_flag_t));
+
+ /* check report mail */
+ if (mail->info->extra_flags.report != EMF_MAIL_REPORT_MDN) {
+ /* Non-report mail */
+ EM_DEBUG_LOG("mail->body->plain[%s]", mail->body->plain);
+ EM_DEBUG_LOG("mail->body->html[%s]", mail->body->html);
+ EM_DEBUG_LOG("mail->body->attachment_num[%d]", mail->body->attachment_num);
+
+
+ if ((mail->body->attachment_num > 0) || (mail->body->plain && mail->body->html)) {
+ EM_DEBUG_LOG("attachment_num : %d", mail->body->attachment_num);
+ root_body = mail_newbody();
+
+ if (root_body == NULL) {
+ EM_DEBUG_EXCEPTION("mail_newbody failed...");
+ error = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ root_body->type = TYPEMULTIPART;
+ root_body->subtype = EM_SAFE_STRDUP("MIXED");
+ root_body->contents.text.data = NULL;
+ root_body->contents.text.size = 0;
+ root_body->size.bytes = 0;
+
+ part_for_text = attach_mutipart_with_sub_type(root_body, "ALTERNATIVE", &error);
+
+ if (!part_for_text) {
+ EM_DEBUG_EXCEPTION("attach_mutipart_with_sub_type [part_for_text] failed [%d]", error);
+ goto FINISH_OFF;
+ }
+
+ text_body = &part_for_text->body;
+
+ if (mail->body->plain && strlen(mail->body->plain) > 0) {
+ EM_DEBUG_LOG("body->plain[%s]", mail->body->plain);
+ if (!attach_part(text_body, (unsigned char *)mail->body->plain, 0, NULL, NULL, false, &error)) {
+ EM_DEBUG_EXCEPTION("attach_part failed [%d]", error);
+ goto FINISH_OFF;
+ }
+ }
+
+ if (mail->body->html && strlen(mail->body->html) > 0) {
+ EM_DEBUG_LOG("body->html[%s]", mail->body->html);
+
+ part_for_html = attach_mutipart_with_sub_type(text_body, "RELATED", &error);
+ if (!part_for_html) {
+ EM_DEBUG_EXCEPTION("attach_mutipart_with_sub_type [part_for_html] failed [%d]", error);
+ goto FINISH_OFF;
+ }
+
+ if (!attach_part(&(part_for_html->body) , (unsigned char *)mail->body->html, 0, NULL, "html", false, &error)) {
+ EM_DEBUG_EXCEPTION("attach_part failed [%d]", error);
+ goto FINISH_OFF;
+ }
+ /*
+ if (mail->body->plain) {
+ EM_SAFE_FREE(part_for_text->subtype);
+ part_for_text->subtype = EM_SAFE_STRDUP("ALTERNATIVE");
+ }
+ */
+ }
+
+ if (mail->body->attachment) {
+ emf_attachment_info_t *atch = mail->body->attachment;
+ char *name = NULL;
+ BODY *body_to_attach = NULL;
+ struct stat st_buf;
+
+ do {
+ EM_DEBUG_LOG("atch->savename[%s], atch->name[%s]", atch->savename, atch->name);
+ if (stat(atch->savename, &st_buf) == 0) {
+ EM_DEBUG_LOG("atch->name[%s]", atch->name);
+ if (!atch->name) {
+ if (!em_core_get_file_name(atch->savename, &name, &error)) {
+ EM_DEBUG_EXCEPTION("em_core_get_file_name failed [%d]", error);
+ goto TRY_NEXT;
+ }
+ }
+ else
+ name = atch->name;
+ EM_DEBUG_LOG("name[%s]", name);
+
+ if (atch->inline_content && part_for_html)
+ body_to_attach = &(part_for_html->body);
+ else
+ body_to_attach = root_body;
+
+ if (!attach_part(body_to_attach, (unsigned char *)atch->savename, 0, name, NULL, atch->inline_content, &error)) {
+ EM_DEBUG_EXCEPTION("attach_part failed [%d]", error);
+ goto TRY_NEXT;
+ }
+ }
+
+TRY_NEXT:
+ atch = atch->next;
+ }
+ while (atch);
+ }
+ text_body = NULL;
+ }
+ else {
+ text_body = mail_newbody();
+
+ if (text_body == NULL) {
+ EM_DEBUG_EXCEPTION("mail_newbody failed...");
+
+ error = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ text_body->type = TYPETEXT;
+ text_body->encoding = ENC8BIT;
+ if (mail->body->plain || mail->body->html)
+ text_body->sparep = EM_SAFE_STRDUP(mail->body->plain ? mail->body->plain : mail->body->html);
+ else
+ text_body->sparep = NULL;
+
+ if (mail->body->html != NULL && mail->body->html[0] != '\0')
+ text_body->subtype = EM_SAFE_STRDUP("html");
+ if (text_body->sparep)
+ text_body->size.bytes = strlen(text_body->sparep);
+ else
+ text_body->size.bytes = 0;
+ }
+ }
+ else { /* Report mail */
+ EM_DEBUG_LOG("REPORT MAIL");
+ envelope->references = cpystr(mail->head->mid);
+
+ if (em_core_mail_get_report_body(envelope, &root_body, &error)) {
+ if (!mail->body) {
+ mail->body = em_core_malloc(sizeof(emf_mail_body_t));
+ if (!mail->body) {
+ EM_DEBUG_EXCEPTION("malloc failed...");
+ error = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ mail->body->plain = EM_SAFE_STRDUP(root_body->nested.part->body.sparep);
+ mail->body->attachment_num = 1;
+
+ mail->body->attachment = em_core_malloc(sizeof(emf_attachment_info_t));
+ if (!mail->body->attachment) {
+ EM_DEBUG_EXCEPTION("malloc failed...");
+ EM_SAFE_FREE(mail->body->plain);
+ error = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ mail->body->attachment->downloaded = 1;
+ mail->body->attachment->savename = EM_SAFE_STRDUP(root_body->nested.part->next->body.sparep);
+
+ char *p = NULL;
+
+ if (!em_core_get_file_name(mail->body->attachment->savename, &p, &error)) {
+ EM_DEBUG_EXCEPTION("em_core_get_file_name failed [%d]", error);
+ goto FINISH_OFF;
+ }
+
+ mail->body->attachment->name = cpystr(p);
+ }
+ }
+
+ }
+
+ if (file_path) {
+ EM_DEBUG_LOG("write rfc822 : file_path[%s]", file_path);
+
+ if (part_for_html)
+ html_body = &(part_for_html->body);
+
+ if (!em_core_write_rfc822(envelope, root_body ? root_body : text_body, html_body, extra_flag, &fname, &error)) {
+ EM_DEBUG_EXCEPTION("em_core_write_rfc822 failed [%d]", error);
+ goto FINISH_OFF;
+ }
+
+ *file_path = fname;
+ }
+
+ ret = true;
+
+FINISH_OFF:
+ if ((ret == true) && (env != NULL))
+ *env = envelope;
+ else if (envelope != NULL)
+ mail_free_envelope(&envelope);
+
+ if (text_body != NULL)
+ mail_free_body(&text_body);
+
+ if (root_body != NULL)
+ mail_free_body(&root_body);
+
+ if (err_code != NULL)
+ *err_code = error;
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+static int em_core_mail_get_report_body(ENVELOPE *envelope, BODY **multipart_body, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("envelope[%p], mulitpart_body[%p], err_code[%p]", envelope, multipart_body, err_code);
+
+ int ret = false;
+ int err = EMF_ERROR_NONE;
+
+ BODY *m_body = NULL;
+ BODY *p_body = NULL;
+ BODY *text_body = NULL;
+ PARAMETER *param = NULL;
+ emf_attachment_info_t atch;
+ FILE *fp = NULL;
+ char *fname = NULL;
+ char buf[512] = {0x00, };
+ int sz = 0;
+
+ if (!envelope || !multipart_body) {
+ EM_DEBUG_EXCEPTION(" envelope[%p], mulitpart_body[%p]", envelope, multipart_body);
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ if (!(text_body = mail_newbody())) {
+ EM_DEBUG_EXCEPTION(" mail_newbody failed...");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ if (!em_core_get_temp_file_name(&fname, &err)) {
+ EM_DEBUG_EXCEPTION(" em_core_get_temp_file_name failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ if (!(fp = fopen(fname, "wb+"))) {
+ EM_DEBUG_EXCEPTION(" fopen failed - %s", fname);
+ err = EMF_ERROR_SYSTEM_FAILURE; /* EMF_ERROR_UNKNOWN; */
+ goto FINISH_OFF;
+ }
+
+ if (!envelope->from || !envelope->from->mailbox || !envelope->from->host) {
+ if (!envelope->from)
+ EM_DEBUG_EXCEPTION(" envelope->from[%p]", envelope->from);
+ else
+ EM_DEBUG_LOG(" envelope->from->mailbox[%p], envelope->from->host[%p]", envelope->from->mailbox, envelope->from->host);
+
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ if (envelope->from->personal)
+ SNPRINTF(buf, sizeof(buf), "%s <%s@%s>", envelope->from->personal, envelope->from->mailbox, envelope->from->host);
+ else
+ SNPRINTF(buf, sizeof(buf), "%s@%s", envelope->from->mailbox, envelope->from->host);
+
+ fprintf(fp, "Your message has been read by %s"CRLF_STRING, buf);
+ fprintf(fp, "Date : %s", envelope->date);
+
+ fclose(fp); fp = NULL;
+
+ if (!em_core_get_file_size(fname, &sz, &err)) {
+ EM_DEBUG_EXCEPTION(" em_core_get_file_size failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ text_body->type = TYPETEXT;
+ text_body->encoding = ENC8BIT;
+ text_body->sparep = fname;
+ text_body->size.bytes = (unsigned long)sz;
+
+ if (!em_core_get_temp_file_name(&fname, &err)) {
+ EM_DEBUG_EXCEPTION(" em_core_get_temp_file_name failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ if (!(fp = fopen(fname, "wb+"))) {
+ EM_DEBUG_EXCEPTION(" fopen failed - %s", fname);
+ err = EMF_ERROR_SYSTEM_FAILURE; /* EMF_ERROR_UNKNOWN; */
+ goto FINISH_OFF;
+ }
+
+ if (!envelope->references) {
+ EM_DEBUG_EXCEPTION(" envelope->references[%p]", envelope->references);
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ fprintf(fp, "Final-Recipient : rfc822;%s@%s\r", envelope->from->mailbox, envelope->from->host);
+ fprintf(fp, "Original-Message-ID: %s\r", envelope->references);
+ fprintf(fp, "Disposition : manual-action/MDN-sent-manually; displayed");
+
+ fclose(fp); fp = NULL;
+
+ memset(&atch, 0x00, sizeof(atch));
+
+ atch.savename = fname;
+
+ if (!em_core_get_file_size(fname, &atch.size, &err)) {
+ EM_DEBUG_EXCEPTION(" em_core_get_file_size failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ if (!attach_attachment_to_body(&m_body, text_body, &atch, &err)) {
+ EM_DEBUG_EXCEPTION(" attach_attachment_to_body failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ text_body->contents.text.data = NULL;
+
+ /* change mail header */
+
+ /* set content-type to multipart/report */
+ m_body->subtype = EM_SAFE_STRDUP("report");
+
+ /* set report-type parameter in content-type */
+ param = em_core_malloc(sizeof(PARAMETER));
+ if (!param) {
+ EM_DEBUG_EXCEPTION(" malloc failed...");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ param->attribute = EM_SAFE_STRDUP("report-type");
+ param->value = EM_SAFE_STRDUP("disposition-notification");
+ param->next = m_body->parameter;
+
+ m_body->parameter = param;
+
+ /* change body-header */
+
+ p_body = &m_body->nested.part->next->body;
+
+ /* set content-type to message/disposition-notification */
+ p_body->type = TYPEMESSAGE;
+ p_body->encoding = ENC7BIT;
+
+ EM_SAFE_FREE(p_body->subtype);
+
+ p_body->subtype = EM_SAFE_STRDUP("disposition-notification");
+
+ /* set parameter */
+ mail_free_body_parameter(&p_body->parameter);
+ mail_free_body_parameter(&p_body->disposition.parameter);
+
+ EM_SAFE_FREE(p_body->disposition.type);
+
+ p_body->disposition.type = EM_SAFE_STRDUP("inline");
+
+ ret = true;
+
+FINISH_OFF:
+ if ((ret == true) && (multipart_body != NULL))
+ *multipart_body = m_body;
+ else if (m_body != NULL)
+ mail_free_body(&m_body);
+
+ if (text_body != NULL)
+ mail_free_body(&text_body);
+
+ if (fp != NULL)
+ fclose(fp);
+
+ EM_SAFE_FREE(fname);
+
+ if (err_code != NULL)
+ *err_code = err;
+
+ return ret;
+}
+
+EXPORT_API int em_core_get_body_buff(char *file_path, char **buff)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ FILE *r_fp = NULL;
+ int read_size = 0;
+ int ret = false;
+ char *read_buff = NULL;
+
+
+ if (file_path)
+ r_fp = fopen(file_path, "r");
+
+ if (!r_fp) {
+ EM_DEBUG_EXCEPTION(" Filename %s failed to open", file_path);
+ goto FINISH_OFF;
+ }
+
+
+ struct stat stbuf;
+ stat(file_path, &stbuf);
+ EM_DEBUG_LOG(" File Size [ %d ] ", stbuf.st_size);
+ read_buff = calloc(1, (stbuf.st_size+ 1));
+ read_size = fread(read_buff, 1, stbuf.st_size, r_fp);
+ read_buff[stbuf.st_size] = '\0';
+
+ if (ferror(r_fp)) {
+ EM_DEBUG_EXCEPTION("file read failed - %s", file_path);
+ EM_SAFE_FREE(read_buff);
+ goto FINISH_OFF;
+ }
+
+
+ ret = true;
+ *buff = read_buff;
+
+ FINISH_OFF:
+ if (r_fp) /* Prevent Defect - 17424 */
+ fclose(r_fp);
+
+ return ret;
+}
+
+EXPORT_API int em_core_mail_get_envelope_body_struct(emf_mail_t *mail,
+ ENVELOPE **env,
+ BODY **text_body,
+ BODY **multipart_body,
+ int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("mail[%p], env[%p], text_body[%p], multipart_body[%p], err_code[%p]", mail, env, text_body, multipart_body, err_code);
+
+ int ret = false;
+ int error = EMF_ERROR_NONE;
+ ENVELOPE *envelope = NULL;
+ BODY *txt_body = NULL;
+ BODY *multi_part_body = NULL;
+ emf_extra_flag_t extra_flag;
+ int is_incomplete = 0;
+ emf_account_t *ref_account = NULL;
+ char *pAdd = NULL ;
+
+ if (!mail || !mail->info || !mail->head || !mail->body) {
+ EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
+ error = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ ref_account = em_core_get_account_reference(mail->info->account_id);
+
+ if (!ref_account) {
+ EM_DEBUG_EXCEPTION(" em_core_get_account_reference failed [%d]", mail->info->account_id);
+ error = EMF_ERROR_INVALID_ACCOUNT;
+ goto FINISH_OFF;
+ }
+
+ if (!(envelope = mail_newenvelope())) {
+ EM_DEBUG_EXCEPTION(" mail_newenvelope failed...");
+ error = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ EM_DEBUG_LOG(" mail_newenvelope created...");
+ is_incomplete = mail->info->flags.draft || mail->info->extra_flags.status == EMF_MAIL_STATUS_SENDING;/* 4; */
+ if (is_incomplete) {
+ if (ref_account->email_addr) {
+ char *p = EM_SAFE_STRDUP(ref_account->email_addr);
+
+ envelope->from = rfc822_parse_mailbox(&p, NULL);
+ /* mailbox = user id; host = mail-server-addr; */
+ if (!envelope->from) {
+ EM_DEBUG_EXCEPTION("rfc822_parse_mailbox failed...");
+ error = EMF_ERROR_INVALID_ADDRESS;
+ goto FINISH_OFF;
+ }
+ else {
+ envelope->from->personal = ref_account->display_name ? cpystr(ref_account->display_name) : NULL;
+ }
+ }
+
+ if (ref_account->return_addr) {
+ char *p = EM_SAFE_STRDUP(ref_account->return_addr);
+ envelope->return_path = rfc822_parse_mailbox(&p, NULL);
+ }
+ }
+ else {
+ if (!mail->head->from || !mail->head->to) {
+ EM_DEBUG_EXCEPTION(" mail->head->from[%p], mail->head->to[%p]", mail->head->from, mail->head->to);
+ error = EMF_ERROR_INVALID_MAIL;
+ goto FINISH_OFF;
+ }
+
+ em_core_skip_whitespace(mail->head->from , &pAdd);
+ EM_DEBUG_LOG("address[pAdd][%s]", pAdd);
+
+ rfc822_parse_adrlist(&envelope->from, pAdd, ref_account->sending_server_addr);
+ EM_SAFE_FREE(pAdd);
+ pAdd = NULL ;
+
+ em_core_skip_whitespace(mail->head->return_path , &pAdd);
+ EM_DEBUG_LOG("address[pAdd][%s]", pAdd);
+ rfc822_parse_adrlist(&envelope->return_path, pAdd, ref_account->sending_server_addr);
+ EM_SAFE_FREE(pAdd);
+ pAdd = NULL ;
+ }
+
+ {
+ int i, j;
+
+ if (mail->head->to) {
+ for (i = 0, j = strlen(mail->head->to); i < j; i++) {
+ if (mail->head->to[i] == ';')
+ mail->head->to[i] = ',';
+ }
+ }
+
+ if (mail->head->cc) {
+ for (i = 0, j = strlen(mail->head->cc); i < j; i++) {
+ if (mail->head->cc[i] == ';')
+ mail->head->cc[i] = ',';
+ }
+ }
+
+ if (mail->head->bcc) {
+ for (i = 0, j = strlen(mail->head->bcc); i < j; i++) {
+ if (mail->head->bcc[i] == ';')
+ mail->head->bcc[i] = ',';
+ }
+ }
+ }
+
+ em_core_skip_whitespace(mail->head->to , &pAdd);
+ EM_DEBUG_LOG("address[pAdd][%s]", pAdd);
+
+ rfc822_parse_adrlist(&envelope->to, pAdd, ref_account->sending_server_addr);
+ EM_SAFE_FREE(pAdd);
+ pAdd = NULL ;
+
+ em_core_skip_whitespace(mail->head->cc , &pAdd);
+
+ rfc822_parse_adrlist(&envelope->cc, pAdd, ref_account->sending_server_addr);
+ EM_SAFE_FREE(pAdd);
+ pAdd = NULL ;
+
+ em_core_skip_whitespace(mail->head->bcc , &pAdd);
+ EM_DEBUG_LOG("address[pAdd][%s]", pAdd);
+ rfc822_parse_adrlist(&envelope->bcc, pAdd, ref_account->sending_server_addr);
+ EM_SAFE_FREE(pAdd);
+ pAdd = NULL ;
+ em_core_encode_rfc2047_address(envelope->return_path, &error);
+ em_core_encode_rfc2047_address(envelope->from, &error);
+ em_core_encode_rfc2047_address(envelope->sender, &error);
+ em_core_encode_rfc2047_address(envelope->reply_to, &error);
+ em_core_encode_rfc2047_address(envelope->to, &error);
+ em_core_encode_rfc2047_address(envelope->cc, &error);
+ em_core_encode_rfc2047_address(envelope->bcc, &error);
+
+
+ if (mail->head->subject)
+ envelope->subject = em_core_encode_rfc2047_text(mail->head->subject, &error);
+
+ char date_str[DATE_STR_LENGTH] = { 0, };
+
+ rfc822_date(date_str);
+
+ if (!is_incomplete) {
+ struct tm tm1;
+
+ /* modified by stonyroot - prevent issue */
+ memset(&tm1, 0x00, sizeof(tm1));
+
+ tm1.tm_year = mail->head->datetime.year - 1900;
+ tm1.tm_mon = mail->head->datetime.month - 1;
+ tm1.tm_mday = mail->head->datetime.day;
+ tm1.tm_hour = mail->head->datetime.hour;
+ tm1.tm_min = mail->head->datetime.minute;
+ tm1.tm_sec = mail->head->datetime.second;
+
+ /* tzset(); */
+ time_t t = mktime(&tm1);
+
+ char buf[256] = {0x00, };
+
+ if (localtime(&t))
+ strftime(buf, 128, "%a, %e %b %Y %H : %M : %S ", localtime(&t));
+ else
+ strftime(buf, 128, "%a, %e %b %Y %H : %M : %S ", (const struct tm *)&tm1);
+
+ /* append last 5byes("+0900") */
+ strncat(buf, date_str + (strlen(date_str) - 5), sizeof(buf) - 1);
+ strncpy(date_str, buf, DATE_STR_LENGTH - 1);
+ }
+
+ envelope->date = (unsigned char *)cpystr((const char *)date_str);
+
+ memcpy(&extra_flag, &mail->info->extra_flags, sizeof(emf_extra_flag_t));
+
+ /* check report mail */
+ if (mail->info->extra_flags.report != EMF_MAIL_REPORT_MDN) {
+ txt_body = mail_newbody();
+ if (txt_body == NULL) {
+ EM_DEBUG_EXCEPTION(" mail_newbody failed...");
+
+ error = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ txt_body->type = TYPETEXT;
+ txt_body->encoding = ENC8BIT;
+ if (mail->body && mail->body->plain) {
+ if (mail->body->plain)
+ txt_body->sparep = EM_SAFE_STRDUP(mail->body->plain);
+ else
+ txt_body->sparep = NULL;
+
+ txt_body->size.bytes = (int)strlen(mail->body->plain);
+ }
+
+ if (mail->body) {
+ if (mail->body->attachment) {
+ if (!attach_attachment_to_body(&multi_part_body, txt_body, mail->body->attachment, &error)) {
+ EM_DEBUG_EXCEPTION("attach_attachment_to_body failed [%d]", error);
+ goto FINISH_OFF;
+ }
+ }
+ }
+ }
+ else { /* Report mail */
+ if (mail->head || mail->head->mid)
+ envelope->references = cpystr(mail->head->mid);
+ if (em_core_mail_get_report_body(envelope, &multi_part_body, &error)) {
+ if (!mail->body) {
+ mail->body = em_core_malloc(sizeof(emf_mail_body_t));
+ if (!mail->body) {
+ EM_DEBUG_EXCEPTION("malloc failed...");
+
+ error = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ mail->body->plain = EM_SAFE_STRDUP(multi_part_body->nested.part->body.sparep);
+ mail->body->attachment_num = 1;
+
+ mail->body->attachment = em_core_malloc(sizeof(emf_attachment_info_t));
+ if (!mail->body->attachment) {
+ EM_DEBUG_EXCEPTION("malloc failed...");
+
+ EM_SAFE_FREE(mail->body->plain);
+ error = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ mail->body->attachment->downloaded = 1;
+ mail->body->attachment->savename = EM_SAFE_STRDUP(multi_part_body->nested.part->next->body.sparep);
+
+ char *p = NULL;
+ if (!em_core_get_file_name(mail->body->attachment->savename, &p, &error)) {
+ EM_DEBUG_EXCEPTION("em_core_get_file_name failed [%d]", error);
+
+ goto FINISH_OFF;
+ }
+
+ mail->body->attachment->name = cpystr(p);
+ }
+ }
+ }
+ ret = true;
+
+FINISH_OFF:
+ if (ret == true) {
+ if (env != NULL)
+ *env = envelope;
+ if (txt_body != NULL)
+ *text_body = txt_body;
+ if (multi_part_body != NULL)
+ *multipart_body = multi_part_body;
+ }
+ else {
+ if (envelope != NULL)
+ mail_free_envelope(&envelope);
+ if (txt_body != NULL)
+ mail_free_body(&txt_body);
+ if (multi_part_body != NULL)
+ mail_free_body(&multi_part_body);
+ }
+
+ if (err_code != NULL)
+ *err_code = error;
+ return ret;
+}
diff --git a/email-core/em-core-sound.c b/email-core/em-core-sound.c
new file mode 100755
index 0000000..5bd2553
--- /dev/null
+++ b/email-core/em-core-sound.c
@@ -0,0 +1,759 @@
+/*
+* email-service
+*
+* Copyright (c) 2000 - 2011 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.
+*
+*/
+
+
+#include <stdlib.h>
+#include "emf-dbglog.h"
+#include "em-storage.h"
+#include "em-core-mailbox.h"
+#include "em-core-sound.h"
+
+static MMHandleType email_mmhandle = MM_PLAYER_STATE_NONE;
+static alarm_id_t email_alarm_id = 0;
+static int email_vibe_handle = 0;
+
+static char *filename;
+alarm_entry_t *alarm_info = NULL;
+
+#ifdef __FEATURE_USE_PTHREAD__
+static pthread_mutex_t sound_mutex = PTHREAD_MUTEX_INITIALIZER;
+static pthread_cond_t sound_condition = PTHREAD_COND_INITIALIZER;
+static pthread_mutex_t mmhandle_mutex = PTHREAD_MUTEX_INITIALIZER;
+static thread_t g_alert_thread;
+#else /* _USE_PTHREAD */
+static GMutex *_sound_event_available_lock = NULL;
+static GCond *_sound_event_available_signal = NULL;
+static pthread_mutex_t mmhandle_mutex = NULL;
+static thread_t g_alert_thread;
+#endif /* _USE_PTHREAD */
+
+int em_core_alert_sound_init()
+{
+ int ret = MM_ERROR_NONE;
+ if ((ret = mm_session_init(MM_SESSION_TYPE_NOTIFY)) != MM_ERROR_NONE)
+ EM_DEBUG_EXCEPTION("mm_session_int failed");
+
+ return ret;
+}
+
+int em_core_alert_alarm_init()
+{
+ int ret = ALARMMGR_RESULT_SUCCESS;
+
+ ret = alarmmgr_init("email-service-0");
+ if (ret != 0)
+ EM_DEBUG_EXCEPTION("alarmmgr_init failed : [%d]", ret);
+
+ return ret;
+}
+
+int em_core_alert_sound_filepath_init()
+{
+ filename = (char *)em_core_malloc(MAX_LENGTH);
+ if (filename == NULL) {
+ EM_DEBUG_EXCEPTION("Memory malloc error");
+ return false;
+ }
+
+ memset(filename, 0, MAX_LENGTH);
+
+ return true;
+}
+int em_core_alert_vibe_init()
+{
+ email_vibe_handle = device_haptic_open(DEV_IDX_0, 0);
+ if (!email_vibe_handle) {
+ EM_DEBUG_EXCEPTION("device_haptic_open failed");
+ return false;
+ }
+
+ return true;
+}
+
+void em_core_noti_key_changed_cb(keynode_t *key_node, void *data)
+{
+ int ret = 0;
+
+ switch (vconf_keynode_get_type(key_node)) {
+ case VCONF_TYPE_INT:
+ ret = alarmmgr_remove_alarm(email_alarm_id);
+ if (ret != ALARMMGR_RESULT_SUCCESS) {
+ EM_DEBUG_EXCEPTION("delete of alarm id failed");
+ }
+ em_core_set_repetition_alarm(vconf_keynode_get_int(key_node));
+ break;
+ case VCONF_TYPE_STRING:
+ filename = vconf_keynode_get_str(key_node);
+ break;
+ default:
+ EM_DEBUG_EXCEPTION("Invalid key type");
+ break;
+ }
+ return;
+}
+
+bool em_core_noti_init(void *data)
+{
+ struct appdata *ap = data;
+
+ if (vconf_notify_key_changed(VCONFKEY_SETAPPL_NOTI_EMAIL_ALERT_REP_TYPE_INT, em_core_noti_key_changed_cb, ap) < 0) {
+ EM_DEBUG_EXCEPTION("Register failed : alert type");
+ return false;
+ }
+
+ if (vconf_notify_key_changed(VCONFKEY_SETAPPL_NOTI_EMAIL_RINGTONE_PATH_STR, em_core_noti_key_changed_cb, ap) < 0) {
+ EM_DEBUG_EXCEPTION("Register failed : Ringtone path");
+ return false;
+ }
+
+ return true;
+}
+
+int em_core_alert_init()
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ int err = 0;
+
+ if (!em_core_alert_sound_filepath_init()) {
+ EM_DEBUG_EXCEPTION("em_core_alert_sound_filepath_init failed");
+ return false;
+ }
+
+ if ((err = em_core_alert_sound_init()) != MM_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("em_core_alert_sound_init failed : [%d]", err);
+ return false;
+ }
+
+ if ((err = em_core_alert_alarm_init()) != ALARMMGR_RESULT_SUCCESS) {
+ EM_DEBUG_EXCEPTION("em_core_alert_alarm_init failed : [%d]", err);
+ return false;
+ }
+
+ if (!em_core_alert_vibe_init()) {
+ EM_DEBUG_EXCEPTION("em_core_alert_vibe_init failed");
+ return false;
+ }
+
+ if (!em_core_noti_init(NULL)) {
+ EM_DEBUG_EXCEPTION("em_core_noti_init failed");
+ return false;
+ }
+
+ EM_DEBUG_FUNC_END();
+ return true;
+}
+
+bool em_core_set_mp_filepath(const char *key)
+{
+ filename = vconf_get_str(key);
+ if (filename == NULL)
+ return false;
+
+ return true;
+}
+
+int em_core_mp_player_state_cb(int message, void *param, void *user_param)
+{
+ switch (message)
+ {
+ case MM_MESSAGE_ERROR:
+ EM_DEBUG_LOG("Error is happened.");
+ if (email_mmhandle) {
+ em_core_sound_mp_player_destory();
+ }
+ break;
+ case MM_MESSAGE_BEGIN_OF_STREAM:
+ EM_DEBUG_LOG("Play is started.");
+ break;
+ case MM_MESSAGE_END_OF_STREAM:
+ EM_DEBUG_LOG("End of stream.");
+ ENTER_CRITICAL_SECTION(mmhandle_mutex);
+ if (email_mmhandle)
+ {
+ em_core_sound_mp_player_stop();
+ em_core_sound_mp_player_destory();
+ }
+ LEAVE_CRITICAL_SECTION(mmhandle_mutex);
+ break;
+ default:
+ EM_DEBUG_LOG("Message = %d", message);
+ break;
+ }
+ return 1;
+}
+
+bool em_core_sound_mp_player_create()
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int err = 0;
+
+ if ((err = mm_player_create(&email_mmhandle)) != MM_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("mm_player create fail [%d]", err);
+ return false;
+ }
+ EM_DEBUG_FUNC_END();
+ return true;
+}
+
+bool em_core_vibration_create()
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ email_vibe_handle = device_haptic_open(DEV_IDX_0, 0);
+
+ if (email_vibe_handle < 0) {
+ EM_DEBUG_EXCEPTION("vibration create failed");
+ return false;
+ }
+ EM_DEBUG_FUNC_END();
+ return true;
+}
+
+bool em_core_alarm_create()
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ alarm_info = alarmmgr_create_alarm();
+
+ if (alarm_info == NULL) {
+ EM_DEBUG_EXCEPTION("alarm create failed");
+ return false;
+ }
+
+ EM_DEBUG_FUNC_END();
+ return true;
+}
+
+bool em_core_alarm_destory()
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ int ret;
+ ret = alarmmgr_free_alarm(alarm_info);
+
+ if (ret != ALARMMGR_RESULT_SUCCESS) {
+ EM_DEBUG_EXCEPTION("alarm free failed");
+ return false;
+ }
+
+ EM_DEBUG_FUNC_END();
+ return true;
+}
+
+bool em_core_alert_create()
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ /* Create the alarm handle */
+ if (!em_core_alarm_create()) {
+ EM_DEBUG_EXCEPTION("em_core_alarm_create failed.");
+ return false;
+ }
+
+ /* Set the music file in alert */
+ if (!em_core_set_mp_filepath(VCONFKEY_SETAPPL_NOTI_EMAIL_RINGTONE_PATH_STR))
+ if (!em_core_set_mp_filepath(VCONFKEY_SETAPPL_DEFAULT_NOTI_EMAIL_RINGTONE_PATH_STR)) {
+ EM_DEBUG_EXCEPTION("em_core_set_mp_filepath failed.");
+ return false;
+ }
+
+ EM_DEBUG_FUNC_END();
+ return true;
+}
+
+bool em_core_alert_destory()
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int ret = 0;
+
+ /* Destroy the music player handle */
+ if (!em_core_sound_mp_player_destory()) {
+ EM_DEBUG_EXCEPTION("em_core_sound_mp_player_destory fail");
+ return false;
+ }
+
+ /* Destroy the vibration handle */
+ if (!em_core_vibration_destory()) {
+ EM_DEBUG_EXCEPTION("em_core_vibration_destory fail");
+ return false;
+ }
+
+ /* Destroy the alarm handle */
+ ret = alarmmgr_free_alarm(alarm_info);
+ if (ret != ALARMMGR_RESULT_SUCCESS) {
+ EM_DEBUG_EXCEPTION("alarmmgr_free_alarm fail");
+ return false;
+ }
+
+ /* Set the music file in alert */
+ EM_SAFE_FREE(filename);
+
+ EM_DEBUG_FUNC_END();
+ return true;
+}
+
+gboolean mp_player_timeout_cb(void *data)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ ENTER_CRITICAL_SECTION(mmhandle_mutex);
+ if (email_mmhandle == MM_PLAYER_STATE_PLAYING)
+ {
+ em_core_sound_mp_player_stop();
+ em_core_sound_mp_player_destory();
+ }
+ LEAVE_CRITICAL_SECTION(mmhandle_mutex);
+
+ EM_DEBUG_FUNC_END();
+ return false;
+}
+
+gboolean vibration_timeout_cb(void *data)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ em_core_vibration_stop();
+ em_core_vibration_destory();
+
+ EM_DEBUG_FUNC_END();
+ return false;
+}
+
+bool em_core_vibration_start(int haptic_level)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int ret = 0;
+ int vibPattern = EFFCTVIBE_NOTIFICATION;
+
+ if (haptic_level == 0) {
+ EM_DEBUG_LOG("The level of haptic is zero");
+ return true;
+ }
+
+ ret = device_haptic_play_pattern(email_vibe_handle, vibPattern, HAPTIC_TEST_ITERATION, haptic_level);
+
+ if (ret != 0) {
+ EM_DEBUG_EXCEPTION("Fail to play haptic : [%d]", ret);
+ return false;
+ }
+
+ if ((ret = g_timeout_add(TIMER, (GSourceFunc) vibration_timeout_cb, NULL) <= 0))
+ {
+ EM_DEBUG_EXCEPTION("play_alert - Failed to start timer [%d]", ret);
+ return false;
+ }
+
+ EM_DEBUG_FUNC_END();
+ return true;
+}
+
+int em_core_vibration_stop()
+{
+ int err = MM_ERROR_NONE;
+ if ((err = device_haptic_stop_play(email_vibe_handle)) != 0)
+ EM_DEBUG_EXCEPTION("Fail to stop haptic : [%d]", err);
+
+ return err;
+}
+
+int em_core_vibration_destory()
+{
+ int err = MM_ERROR_NONE;
+ if ((err = device_haptic_close(email_vibe_handle)) != 0)
+ EM_DEBUG_EXCEPTION("Fail to close haptic : [%d]", err);
+
+ return err;
+}
+int em_core_sound_mp_player_start(char *filepath)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ int err = MM_ERROR_NONE;
+
+/*
+ int volume = -1;
+
+
+ if ((err = vconf_get_int(VCONFKEY_SETAPPL_NOTI_SOUND_VOLUME_INT, &volume)) == -1)
+ {
+ EM_DEBUG_LOG("vconf_get_int failed \n");
+ return err;
+ }
+*/
+ mm_player_set_message_callback(email_mmhandle, em_core_mp_player_state_cb, (void *)email_mmhandle);
+
+ EM_DEBUG_LOG("Before mm_player_set_attribute filepath = %s", filepath);
+ if ((err = mm_player_set_attribute(email_mmhandle, NULL, "sound_volume_type", MM_SOUND_VOLUME_TYPE_NOTIFICATION, "profile_uri", filepath, strlen(filepath), NULL)) != MM_ERROR_NONE)
+ {
+ EM_DEBUG_EXCEPTION("mm_player_set_attribute faile [ %d ] ", err);
+ return err;
+ }
+
+ EM_DEBUG_LOG("After mm_player_set_attribute");
+
+ if ((err = mm_player_realize(email_mmhandle)) != MM_ERROR_NONE)
+ {
+ EM_DEBUG_EXCEPTION("mm_player_realize fail [%d]", err);
+ return err;
+ }
+
+ if ((err = mm_player_start(email_mmhandle)) != MM_ERROR_NONE)
+ {
+ EM_DEBUG_EXCEPTION("mm_player_start fail [%d]", err);
+ return err;
+ }
+
+ if ((err = g_timeout_add(TIMER, (GSourceFunc)mp_player_timeout_cb, NULL) <= 0))
+ {
+ EM_DEBUG_EXCEPTION("g_timeout_add - Failed to start timer");
+ return err;
+ }
+
+ EM_DEBUG_FUNC_END();
+ return err;
+}
+
+int em_core_sound_mp_player_stop()
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ int err = MM_ERROR_NONE;
+
+ if ((err = mm_player_stop(email_mmhandle)) != MM_ERROR_NONE)
+ {
+ EM_DEBUG_EXCEPTION("mm_player_stop fail [%d]", err);
+ return err;
+ }
+
+ if ((err = mm_player_unrealize(email_mmhandle)) != MM_ERROR_NONE)
+ {
+ EM_DEBUG_EXCEPTION("mm_player_unrealize [%d]", err);
+ return err;
+ }
+
+ EM_DEBUG_FUNC_END();
+ return err;
+}
+
+bool em_core_sound_mp_player_destory()
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ int err = MM_ERROR_NONE;
+
+ if ((err = mm_player_destroy(email_mmhandle)) != MM_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("mm_player_destory [%d]", err);
+ return false;
+ }
+
+ EM_DEBUG_FUNC_END();
+ return true;
+}
+
+int get_vconf_data(int key, int *return_value)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int err = -1, value = 0;
+
+ switch (key)
+ {
+ case EMAIL_SOUND_STATUS:
+ err = vconf_get_bool(VCONFKEY_SETAPPL_SOUND_STATUS_BOOL, &value);
+ EM_DEBUG_LOG("EMAIL_SOUND_STATUS[%d]", value);
+ break;
+ case EMAIL_VIBE_STATUS:
+ err = vconf_get_bool(VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL, &value);
+ EM_DEBUG_LOG("EMAIL_VIBRATION_STATUS[%d]", value);
+ break;
+ case EMAIL_ALERT_REP_TYPE:
+ err = vconf_get_int(VCONFKEY_SETAPPL_NOTI_EMAIL_ALERT_REP_TYPE_INT, &value);
+ EM_DEBUG_LOG("EMAIL_ALERT_REP_TYPE[%d]", value);
+ break;
+ case EMAIL_ALERT_VOLUME:
+ err = vconf_get_int(VCONFKEY_SETAPPL_NOTI_SOUND_VOLUME_INT, &value);
+ EM_DEBUG_LOG("EMAIL_ALERT_VOLUME[%d]", value);
+ break;
+ case EMAIL_ALERT_VIBE_STENGTH:
+ err = vconf_get_int(VCONFKEY_SETAPPL_NOTI_VIBRATION_LEVEL_INT, &value);
+ EM_DEBUG_LOG("EMAIL_ALERT_VIBE_STENGTH[%d]", value);
+ break;
+ default:
+ {
+ EM_DEBUG_LOG("Uuknown request\n");
+ return false;
+ }
+ }
+
+ if (err == -1)
+ {
+ EM_DEBUG_LOG("Vconf_get_int failed\n");
+ return false;
+ }
+
+ *return_value = value;
+ EM_DEBUG_FUNC_END();
+ return true;
+}
+
+int em_core_get_alert_type()
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int sound_status = 0, vibe_status = 0;
+ int err;
+ int alert_type = -1;
+
+ if (!(err = get_vconf_data(EMAIL_SOUND_STATUS, &sound_status)))
+ {
+ EM_DEBUG_EXCEPTION("Don't get sound status");
+ return err;
+ }
+
+ if (!(err = get_vconf_data(EMAIL_VIBE_STATUS, &vibe_status)))
+ {
+ EM_DEBUG_EXCEPTION("Don't get vibration status");
+ return err;
+ }
+
+ if (sound_status && vibe_status)
+ alert_type = EMAIL_ALERT_TYPE_MELODY_AND_VIB;
+ else if (sound_status)
+ alert_type = EMAIL_ALERT_TYPE_MELODY;
+ else if (vibe_status)
+ alert_type = EMAIL_ALERT_TYPE_VIB;
+ else
+ alert_type = EMAIL_ALERT_TYPE_MUTE;
+
+ return alert_type;
+}
+
+
+EXPORT_API int em_core_alert_loop_start(int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ int thread_error;
+
+ if (err_code != NULL)
+ *err_code = EMF_ERROR_NONE;
+
+ if (g_alert_thread)
+ {
+ EM_DEBUG_EXCEPTION("Alert service is already running...");
+ if (err_code != NULL)
+ *err_code = EMF_ERROR_UNKNOWN;
+
+ return 1;
+ }
+
+ THREAD_CREATE(g_alert_thread, start_alert_thread, NULL, thread_error);
+ if (thread_error != 0)
+ {
+ EM_DEBUG_EXCEPTION("Cannot create alert thread");
+ if (err_code != NULL)
+ *err_code = EMF_ERROR_SYSTEM_FAILURE;
+
+ return -1;
+ }
+
+ if (err_code != NULL)
+ *err_code = EMF_ERROR_NONE;
+
+ return 0;
+}
+
+int em_core_alarm_timeout_cb(int timer_id, void *user_parm)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ int err = EMF_ERROR_NONE;
+ int total_unread_count = 0;
+ int total_mail_count = 0;
+ emf_mailbox_t mailbox;
+
+ memset(&mailbox, 0x00, sizeof(emf_mailbox_t));
+
+ mailbox.account_id = ALL_ACCOUNT;
+ mailbox.name = NULL;
+
+ if (!em_core_mailbox_get_mail_count(&mailbox, &total_mail_count, &total_unread_count, &err)) {
+ EM_DEBUG_EXCEPTION("em_core_mailbox_get_mail_count failed - %d\n", err);
+ return false;
+ }
+
+ EM_DEBUG_LOG(">>>> total_unread_count : [%d]\n", total_unread_count);
+
+ if (total_unread_count) {
+ start_alert();
+ }
+
+ EM_DEBUG_FUNC_END();
+ return true;
+}
+
+bool set_alarm(int repetition_time)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ int ret = 0;
+ alarm_date_t alarm_date;
+ time_t current_time;
+ struct tm current_tm;
+
+ time(&current_time);
+ localtime_r(&current_time, &current_tm);
+
+ alarm_date.year = 0;
+ alarm_date.month = 0;
+ alarm_date.day = 0;
+
+ EM_DEBUG_LOG("Current time : [%d]-[%d]-[%d]", current_tm.tm_hour, current_tm.tm_min, current_tm.tm_sec);
+
+ if (current_tm.tm_min + repetition_time < 60) {
+ alarm_date.hour = current_tm.tm_hour;
+ alarm_date.min = current_tm.tm_min + repetition_time;
+ } else {
+ if (current_tm.tm_hour < 12) {
+ alarm_date.hour = current_tm.tm_hour + 1;
+ } else {
+ alarm_date.hour = (current_tm.tm_hour + 1) % 12;
+ }
+
+ alarm_date.min = (current_tm.tm_min + repetition_time) % 60;
+ }
+
+ alarm_date.sec = current_tm.tm_sec;
+
+ alarmmgr_set_time(alarm_info, alarm_date);
+ alarmmgr_set_repeat_mode(alarm_info, ALARM_REPEAT_MODE_ONCE, 0);
+ alarmmgr_set_type(alarm_info, ALARM_TYPE_VOLATILE);
+ alarmmgr_add_alarm_with_localtime(alarm_info, NULL, &email_alarm_id);
+
+ ret = alarmmgr_set_cb(em_core_alarm_timeout_cb, NULL);
+
+ if (ret != 0) {
+ EM_DEBUG_EXCEPTION("Failed : alarmmgr_set_cb() -> error[%d]", ret);
+ return false;
+ }
+
+ EM_DEBUG_LOG("Alarm time : [%d]-[%d]-[%d]-[%d]-[%d]-[%d]", alarm_date.year, alarm_date.month, alarm_date.day, alarm_date.hour, alarm_date.min, alarm_date.sec);
+ EM_DEBUG_FUNC_END();
+ return true;
+}
+
+void em_core_set_repetition_alarm(int repetition)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ int repetition_time = 0;
+
+ switch (repetition) {
+ case EMAIL_GCONF_VALUE_REPEAT_NONE:
+ repetition_time = 0;
+ break;
+ case EMAIL_GCONF_VALUE_REPEAT_2MINS:
+ repetition_time = 2;
+ break;
+ case EMAIL_GCONF_VALUE_REPEAT_5MINS:
+ repetition_time = 5;
+ break;
+ case EMAIL_GCONF_VALUE_REPEAT_10MINS:
+ repetition_time = 10;
+ break;
+ default:
+ EM_DEBUG_EXCEPTION("Invalid repetition time");
+ return;
+ }
+
+ EM_DEBUG_LOG("repetition time is %d", repetition_time);
+
+ if (repetition_time > 0) {
+ set_alarm(repetition_time);
+ }
+
+ EM_DEBUG_FUNC_END();
+}
+
+void *start_alert_thread(void *arg)
+{
+ EM_DEBUG_FUNC_END();
+
+ int err = 0;
+ int level = 0;
+
+ if (!em_core_alert_init())
+ {
+ EM_DEBUG_EXCEPTION("Error : em_core_alert_init failed");
+ return 0;
+ }
+
+
+ while (1) {
+ if (!em_core_alert_create()) {
+ EM_DEBUG_EXCEPTION("Error : em_core_alert_create failed");
+ return 0;
+ }
+
+ err = get_vconf_data(EMAIL_ALERT_REP_TYPE, &level);
+ em_core_set_repetition_alarm(level);
+
+ ENTER_CRITICAL_SECTION(sound_mutex);
+ SLEEP_CONDITION_VARIABLE(sound_condition , sound_mutex);
+
+ err = get_vconf_data(EMAIL_ALERT_VIBE_STENGTH, &level);
+
+ switch (em_core_get_alert_type())
+ {
+ case EMAIL_ALERT_TYPE_MELODY:
+ em_core_sound_mp_player_create();
+ em_core_sound_mp_player_start(filename);
+ break;
+ case EMAIL_ALERT_TYPE_VIB:
+ em_core_vibration_create();
+ em_core_vibration_start(level);
+ break;
+ case EMAIL_ALERT_TYPE_MELODY_AND_VIB:
+ em_core_vibration_create();
+ em_core_vibration_start(level);
+ em_core_sound_mp_player_create();
+ em_core_sound_mp_player_start(filename);
+ break;
+ case EMAIL_ALERT_TYPE_MUTE:
+ EM_DEBUG_LOG("Alert type is mute!!");
+ break;
+ default:
+ EM_DEBUG_EXCEPTION("alert type is strange");
+ em_core_alert_destory();
+ break;
+ }
+ LEAVE_CRITICAL_SECTION(sound_mutex);
+
+ em_core_alarm_destory();
+ }
+ return 0;
+}
+
+EXPORT_API void start_alert()
+{
+ ENTER_CRITICAL_SECTION(sound_mutex);
+ WAKE_CONDITION_VARIABLE(sound_condition);
+ LEAVE_CRITICAL_SECTION(sound_mutex);
+}
diff --git a/email-core/em-core-timer.c b/email-core/em-core-timer.c
new file mode 100755
index 0000000..add3a4f
--- /dev/null
+++ b/email-core/em-core-timer.c
@@ -0,0 +1,110 @@
+/*
+* email-service
+*
+* Copyright (c) 2000 - 2011 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.
+*
+*/
+
+
+#include <stdlib.h>
+#include <string.h>
+#include <sys/time.h>
+#include <signal.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <time.h>
+#include <errno.h>
+#include <sys/signal.h>
+/* #include <pthread.h> */
+#include <sys/timeb.h>
+#include "em-core-timer.h"
+#include "emf-dbglog.h"
+#include <dbus/dbus-glib.h>
+
+
+typedef struct
+{
+ EMF_TIMER_CALLBACK user_callback_function;
+ void *callback_user_data;
+ int time_id;
+}em_timer_callback_data;
+
+
+EXPORT_API int
+em_core_timer_ex_callback(void *a_pData)
+{
+ EM_DEBUG_LOG("[em_core_timer_ex_callback] enter\n");
+ void *pUserData = NULL;
+
+
+ g_thread_init(NULL);
+ dbus_g_thread_init ();
+
+ em_timer_callback_data *pTimerData = (em_timer_callback_data *)a_pData;
+ if (pTimerData != NULL)
+ {
+ EMF_TIMER_CALLBACK pfn_UserCB = pTimerData->user_callback_function;
+ pUserData = pTimerData->callback_user_data;
+ if (pUserData)
+ EM_DEBUG_LOG("em_core_timer_ex_callback >>> data : %s", (char *)pTimerData->callback_user_data);
+ EM_SAFE_FREE(pTimerData);
+ pfn_UserCB(pUserData);
+ }
+
+
+ g_thread_init(NULL);
+ dbus_g_thread_init ();
+
+ EM_DEBUG_LOG("[em_core_timer_ex_callback] leave\n");
+
+ if (pUserData)
+ return 0;
+ else
+ return 1;
+}
+
+
+
+EXPORT_API int
+em_core_set_timer_ex(long a_nSetTimeValue, EMF_TIMER_CALLBACK a_pCallBack, void *a_pData)
+{
+ EM_DEBUG_LOG("em_core_set_timer_ex %d", a_nSetTimeValue);
+ em_timer_callback_data *pTimerData = NULL;
+ pTimerData = malloc(sizeof(em_timer_callback_data));
+ char *data = NULL;
+ if (!pTimerData)
+ return -1;
+ memset(pTimerData, 0x00, sizeof(em_timer_callback_data));
+ if (a_pData)
+ EM_DEBUG_LOG("em_core_set_timer_ex >>> data : %s", (char *)a_pData);
+
+ pTimerData->user_callback_function = a_pCallBack;
+ if (a_pData) {
+ data = (char *) a_pData;
+ pTimerData->callback_user_data = EM_SAFE_STRDUP(data);
+ }
+ pTimerData->time_id = g_timeout_add(a_nSetTimeValue, em_core_timer_ex_callback, pTimerData);
+ return pTimerData->time_id;
+}
+
+EXPORT_API void
+em_core_kill_timer_ex(int a_nTimerID)
+{
+ EM_DEBUG_LOG("[em_core_kill_timer_ex] a_nTimerID %d", a_nTimerID);
+ g_source_remove(a_nTimerID);
+}
+
diff --git a/email-core/em-core-utils.c b/email-core/em-core-utils.c
new file mode 100755
index 0000000..823781e
--- /dev/null
+++ b/email-core/em-core-utils.c
@@ -0,0 +1,3183 @@
+/*
+* email-service
+*
+* Copyright (c) 2000 - 2011 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.
+*
+*/
+
+
+/******************************************************************************
+ * File: em-core-utils.c
+ * Desc: Mail Utils
+ *
+ * Auth:
+ *
+ * History:
+ * 2006.08.16 : created
+ *****************************************************************************/
+#include <glib.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+#include <errno.h>
+#include <stdio.h>
+#include <dlfcn.h>
+#include <sys/time.h>
+#include <unistd.h>
+#include <sys/stat.h>
+#include <sys/vfs.h>
+#include <vconf.h>
+#include <regex.h>
+#include <malloc.h>
+
+#include <contacts-svc.h>
+#include <notification.h>
+
+#include "emf-types.h"
+#include "em-core-global.h"
+#include "em-core-utils.h"
+#include "emf-dbglog.h"
+#include "em-core-mesg.h"
+#include "em-core-event.h"
+#include "em-core-mailbox.h"
+#include "em-core-account.h"
+#include "em-core-mailbox-sync.h"
+#include "em-core-mime.h"
+#include "em-core-sound.h"
+#include "Msg_Convert.h"
+
+#define LED_TIMEOUT_SECS 12
+#define G_DISPLAY_LENGTH 256
+
+#define DIR_SEPERATOR_CH '/'
+#define EMAIL_CH_QUOT '"'
+#define EMAIL_CH_BRACKET_S '<'
+#define EMAIL_CH_BRACKET_E '>'
+#define EMAIL_CH_COMMA ','
+#define EMAIL_CH_SEMICOLON ';'
+#define EMAIL_CH_ROUND_BRACKET_S '('
+#define EMAIL_CH_ROUND_BRACKET_E ')'
+#define EMAIL_CH_SQUARE_BRACKET_S '['
+#define EMAIL_CH_SQUARE_BRACKET_E ']'
+#define EMAIL_CH_SPACE ' '
+
+static char _g_display[G_DISPLAY_LENGTH];
+
+
+typedef struct _em_transaction_info_type_t {
+ int mail_id;
+ int handle;
+ struct _em_transaction_info_type_t *next;
+
+} em_transaction_info_type_t;
+
+em_transaction_info_type_t *g_transaction_info_list;
+
+static emf_option_t g_mail_option =
+{
+ 0, /* priority */
+ 1, /* keep_local_copy */
+ 0, /* req_delivery_receipt */
+ 0, /* req_read_receipt */
+ 0, /* download_limit */
+ 0, /* block_address */
+ 0, /* block_subject */
+ NULL, /* diplay name */
+};
+
+static emf_session_t g_session_list[SESSION_MAX] = { {0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0},};
+
+
+typedef struct em_core_account_list_t em_core_account_list_t;
+struct em_core_account_list_t {
+ emf_account_t *account;
+ em_core_account_list_t *next;
+};
+
+static em_core_account_list_t **g_account_reference = NULL;
+
+EXPORT_API
+char *em_core_convert_mutf7_to_utf8(char *mailbox_name)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ return (char *)(utf8_from_mutf7((unsigned char *)mailbox_name));
+}
+
+EXPORT_API int em_core_set_account_reference(em_core_account_list_t **account_list, int account_num, int *err_code)
+{
+ g_account_reference = (em_core_account_list_t **)account_list;
+ return 1;
+}
+
+emf_option_t *em_core_get_option(int *err_code)
+{
+ if (err_code != NULL)
+ *err_code = EMF_ERROR_NONE;
+
+ return &g_mail_option;
+}
+
+EXPORT_API int em_core_set_option(emf_option_t *opt, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("opt[%p], err_code[%p]", opt, err_code);
+
+ int err = EMF_ERROR_NONE;
+
+ if (!opt) {
+ EM_DEBUG_EXCEPTION("opt[%p]", opt);
+
+ if (err_code != NULL)
+ *err_code = EMF_ERROR_INVALID_PARAM;
+ return false;
+ }
+
+ memset(_g_display, 0, G_DISPLAY_LENGTH);
+ memcpy(&g_mail_option, opt, sizeof(g_mail_option));
+
+ if (opt->display_name_from && opt->display_name_from[0] != '\0') {
+ strncpy(_g_display, opt->display_name_from, G_DISPLAY_LENGTH - 1);
+ g_mail_option.display_name_from = _g_display;
+ }
+ else
+ g_mail_option.display_name_from = NULL;
+
+ if (err_code != NULL)
+ *err_code = err;
+
+ return true;
+}
+
+
+
+
+
+/* in smtp case, path argument must be ENCODED_PATH_SMTP */
+int em_core_get_long_encoded_path_with_account_info(emf_account_t *account, char *path, int delimiter, char **long_enc_path, int *err_code)
+{
+ EM_PROFILE_BEGIN(emCorelongEncodedpath);
+ EM_DEBUG_FUNC_BEGIN("account[%p], path[%s], delimiter[%d], long_enc_path[%p], err_code[%p]", account, path, delimiter, long_enc_path, err_code);
+
+ int ret = false;
+ int error = EMF_ERROR_NONE;
+ char *p = NULL;
+
+ size_t long_enc_path_len = 0;
+
+ if (path == NULL || (path && strncmp(path, ENCODED_PATH_SMTP, strlen(ENCODED_PATH_SMTP)) != 0)) { /* imap or pop3 */
+ EM_DEBUG_LOG("account->receiving_server_addr[%p]", account->receiving_server_addr);
+ EM_DEBUG_LOG("account->receiving_server_addr[%s]", account->receiving_server_addr);
+
+ if (!account->receiving_server_addr) {
+ EM_DEBUG_EXCEPTION("account->receiving_server_addr is null");
+ error = EMF_ERROR_INVALID_ACCOUNT;
+ goto FINISH_OFF;
+ }
+
+ long_enc_path_len = strlen(account->receiving_server_addr) + (path ? strlen(path) : 0) + 64;
+
+ *long_enc_path = em_core_malloc(long_enc_path_len);
+ if (!*long_enc_path) {
+ EM_DEBUG_EXCEPTION("malloc failed...");
+ error = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ p = *long_enc_path;
+
+ /* ex:"{mai.test.com:143/imap} or {mai.test.com:143/imap/tls}my-mailbox" */
+
+ SNPRINTF(p, long_enc_path_len, "{%s:%d/%s/user=%d",
+ account->receiving_server_addr,
+ account->port_num,
+ account->receiving_server_type == EMF_SERVER_TYPE_POP3 ? "pop3" : "imap", account->account_id);
+
+ if (account->use_security & 0x01) {
+ strncat(p, "/ssl", long_enc_path_len-(strlen(p)+1));
+ /* strcat(p, "/tryssl"); */
+ }
+
+ /* Currently, receiving servers doesn't require tls.
+ if (account->use_security & 0x02)
+ strncat(p, "/tls", long_enc_path_len-(strlen(p)+1));
+ else
+ strncat(p, "/notls", long_enc_path_len-(strlen(p)+1));
+ */
+
+ if (account->apop) {
+ EM_DEBUG_LOG("em_core_get_long_encoded_path - apop - %d", account->apop);
+ strncat(p, "/apop", long_enc_path_len-(strlen(p)+1));
+ EM_DEBUG_LOG("long_enc_path - %s", p);
+ }
+ }
+ else { /* smtp */
+ long_enc_path_len = strlen(account->sending_server_addr) + 64;
+
+ *long_enc_path = em_core_malloc(strlen(account->sending_server_addr) + 64);
+ if (!*long_enc_path) {
+ EM_DEBUG_EXCEPTION("\t malloc failed...\n");
+
+ error = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ p = *long_enc_path;
+
+ /* ex:"mail.test.com:25/smtp" */
+
+ SNPRINTF(p, long_enc_path_len, "%s:%d/%s",
+ account->sending_server_addr,
+ account->sending_port_num,
+ "smtp");
+
+ if (account->sending_auth) {
+ SNPRINTF(p + strlen(p), long_enc_path_len-(strlen(p)), "/user=%d", account->account_id);
+ }
+
+ if (account->sending_security & 0x01) {
+ strncat(p, "/ssl", long_enc_path_len-(strlen(p)+1));
+ /* strcat(p, "/tryssl"); */
+ }
+ if (account->sending_security & 0x02)
+ strncat(p, "/tls", long_enc_path_len-(strlen(p)+1));
+ else
+ strncat(p, "/notls", long_enc_path_len-(strlen(p)+1));
+ }
+
+ if (path == NULL || (path && strncmp(path, ENCODED_PATH_SMTP, strlen(ENCODED_PATH_SMTP)) != 0)) {
+ strncat(p, "}", long_enc_path_len-(strlen(p)+1));
+
+ if (path != NULL) {
+ char *enc_name = NULL;
+
+ if (!em_core_get_encoded_mailbox_name(path, &enc_name, &error)) {
+ EM_DEBUG_EXCEPTION("em_core_get_encoded_mailbox_name failed - %d", error);
+ *long_enc_path = NULL;
+ goto FINISH_OFF;
+ }
+
+ if (enc_name) {
+ strncat(p, enc_name, long_enc_path_len-(strlen(p)+1));
+ EM_SAFE_FREE(enc_name);
+ }
+ }
+ }
+
+ ret = true;
+
+FINISH_OFF:
+ if (ret != true)
+ EM_SAFE_FREE(p);
+
+ if (err_code != NULL)
+ *err_code = error;
+ EM_PROFILE_END(emCorelongEncodedpath);
+ return ret;
+}
+
+int em_core_get_long_encoded_path(int account_id, char *path, int delimiter, char **long_enc_path, int *err_code)
+{
+ EM_PROFILE_BEGIN(emCorelongEncodedpath);
+ EM_DEBUG_FUNC_BEGIN("account_id[%d], delimiter[%d], long_enc_path[%p], err_code[%p]", account_id, delimiter, long_enc_path, err_code);
+
+ int ret = false;
+ int error = EMF_ERROR_NONE;
+
+ emf_account_t *ref_account = em_core_get_account_reference(account_id);
+ if (!ref_account) {
+ EM_DEBUG_EXCEPTION("em_core_get_account_reference failed [%d]", account_id);
+ error = EMF_ERROR_INVALID_ACCOUNT;
+ goto FINISH_OFF;
+ }
+
+ if (em_core_get_long_encoded_path_with_account_info(ref_account, path, delimiter, long_enc_path, &error) == false) {
+ EM_DEBUG_EXCEPTION("em_core_get_long_encoded_path_with_account_info failed [%d]", error);
+ goto FINISH_OFF;
+ }
+
+ ret = true;
+
+FINISH_OFF:
+ if (err_code != NULL)
+ *err_code = error;
+ EM_PROFILE_END(emCorelongEncodedpath);
+ return ret;
+}
+
+int em_core_upper_path(char *path)
+{
+ int i = 0, is_utf7 = 0, len = path ? (int)strlen(path) : -1;
+ for (; i < len; i++) {
+ if (path[i] == '&' || path[i] == 5) {
+ is_utf7 = 1;
+ }
+ else {
+ if (is_utf7) {
+ if (path[i] == '-') is_utf7 = 0;
+ }
+ else {
+ path[i] = toupper(path[i]);
+ }
+ }
+ }
+
+ return 1;
+}
+
+int em_core_get_encoded_mailbox_name(char *name, char **enc_name, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("name[%s], enc_name[%p], err_code[%p]", name, enc_name, err_code);
+
+ if (!name || !enc_name) {
+ if (err_code != NULL)
+ *err_code = EMF_ERROR_INVALID_PARAM;
+ EM_DEBUG_FUNC_END();
+ return false;
+ }
+
+ /* encoding mailbox name (Charset->UTF8->UTF7) */
+
+ *enc_name = em_core_malloc(strlen(name)+1);
+ if (*enc_name == NULL) {
+ EM_DEBUG_EXCEPTION("malloc failed...");
+ if (err_code != NULL)
+ *err_code = EMF_ERROR_OUT_OF_MEMORY;
+ EM_DEBUG_FUNC_END();
+ return false;
+ }
+
+ strcpy(*enc_name, name);
+
+ if (err_code != NULL)
+ *err_code = EMF_ERROR_NONE;
+
+ EM_DEBUG_FUNC_END();
+ return true;
+}
+
+int em_core_upper_string(char *str)
+{
+ int i = str ? (int)strlen(str) : -1;
+ for (; i >= 0; i--)
+ str[i] = toupper(str[i]);
+ return 1;
+}
+
+int em_core_get_temp_file_name(char **filename, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("filename[%p], err_code[%p]", filename, err_code);
+
+ int ret = false;
+ int error = EMF_ERROR_NONE;
+
+ if (filename == NULL) {
+ EM_DEBUG_EXCEPTION("\t filename[%p]\n", filename);
+ error = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ char tempname[512] = {0x00, };
+ struct timeval tv;
+
+
+ gettimeofday(&tv, NULL);
+ srand(tv.tv_usec);
+
+ /* Create Directory If deleted by user*/
+ em_storage_create_dir_if_delete();
+
+ SNPRINTF(tempname, sizeof(tempname), "%s%c%s%c%d", MAILHOME, DIR_SEPERATOR_CH, MAILTEMP, DIR_SEPERATOR_CH, rand());
+
+ char *p = EM_SAFE_STRDUP(tempname);
+ if (p == NULL) {
+ EM_DEBUG_EXCEPTION("\t strdup failed...\n");
+ error = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ *filename = p;
+
+ ret = true;
+
+FINISH_OFF:
+ if (err_code != NULL)
+ *err_code = error;
+ EM_DEBUG_FUNC_END();
+ return ret;
+}
+
+int em_core_get_file_name(char *path, char **filename, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("path[%s], filename[%p], err_code[%p]", path, filename, err_code);
+
+ int ret = false;
+ int error = EMF_ERROR_NONE;
+
+ if (!path || !filename) {
+ EM_DEBUG_EXCEPTION("path[%p], filename[%p]", path, filename);
+
+ error = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ int i = (int)strlen(path);
+
+ /* get filename */
+ for (; i >= 0; i--)
+ if (path[i] == DIR_SEPERATOR_CH)
+ break;
+
+ *filename = path + i + 1;
+
+ ret = true;
+
+FINISH_OFF:
+ if (err_code != NULL)
+ *err_code = error;
+ EM_DEBUG_FUNC_END();
+ return ret;
+}
+
+int em_core_get_file_size(char *path, int *size, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("path[%s], size[%p], err_code[%p]", path, size, err_code);
+
+ int ret = false;
+ int error = EMF_ERROR_NONE;
+
+ if ((path == NULL) || (size == NULL)) {
+ EM_DEBUG_EXCEPTION("\t path[%p], size[%p]\n", path, size);
+
+ error = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ struct stat st_buf;
+
+ if (stat(path, &st_buf) < 0) {
+ EM_DEBUG_EXCEPTION("\t stat failed - %s\n", path);
+
+ error = EMF_ERROR_SYSTEM_FAILURE;
+ goto FINISH_OFF;
+ }
+
+ *size = st_buf.st_size;
+
+ ret = true;
+
+FINISH_OFF:
+ if (err_code != NULL)
+ *err_code = error;
+ EM_DEBUG_FUNC_END();
+ return ret;
+}
+
+void* em_core_malloc(unsigned len)
+{
+ /* EM_DEBUG_LOG("Memory allocation size[%d] bytes", len); */
+ void *p = NULL;
+
+ if (len <= 0) {
+ EM_DEBUG_EXCEPTION("len should be positive.[%d]", len);
+ return NULL;
+ }
+
+ p = malloc(len);
+
+ if (p)
+ memset(p, 0x00, len);
+ else
+ EM_DEBUG_EXCEPTION("malloc failed");
+ return p;
+}
+
+EXPORT_API char* em_core_replace_string(char *source_string, char *old_string, char *new_string)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ char *result_buffer = NULL;
+ char *p = NULL;
+ int buffer_length = 0;
+
+ EM_IF_NULL_RETURN_VALUE(source_string, NULL);
+ EM_IF_NULL_RETURN_VALUE(old_string, NULL);
+ EM_IF_NULL_RETURN_VALUE(new_string, NULL);
+
+ p = strstr(source_string, old_string);
+
+ if (p == NULL) {
+ EM_DEBUG_EXCEPTION("old_string not found in source_string");
+ EM_DEBUG_FUNC_END("return NULL");
+ return NULL;
+ }
+
+ EM_DEBUG_LOG("p[%s] ", p); /* temp */
+ buffer_length = strlen(source_string) + 1024;
+ EM_DEBUG_LOG("buffer_length[%d] ", buffer_length); /* temp */
+ result_buffer = (char *)em_core_malloc(buffer_length);
+
+ if (!result_buffer) {
+ EM_DEBUG_EXCEPTION("em_core_malloc failed");
+ return NULL;
+ }
+
+ strncpy(result_buffer, source_string, p - source_string);
+ snprintf(result_buffer + strlen(result_buffer), buffer_length - strlen(result_buffer), "%s%s", new_string, p + strlen(old_string));
+
+ EM_DEBUG_FUNC_END("result_buffer[%s]", result_buffer);
+ return result_buffer;
+}
+
+static int _em_core_check_host(char *host)
+{
+ if (!host)
+ return 0;
+ return strncmp(host, ".SYNTAX-ERROR.", strlen(".SYNTAX-ERROR."));
+}
+
+void em_core_skip_whitespace(char *addr_str, char **pAddr)
+{
+ EM_DEBUG_FUNC_BEGIN("addr_str[%p]", addr_str);
+
+ if (!addr_str)
+ return ;
+ char *str = addr_str;
+ char ptr[strlen(str)+1] ;
+ int i, j = 0;
+
+ str = addr_str ;
+ for (i = 0; str[i] != NULL_CHAR ; i++) {
+ if (str[i] != SPACE && str[i] != TAB && str[i] != CR && str[i] != LF)
+ ptr[j++] = str[i];
+ }
+ ptr[j] = NULL_CHAR;
+
+ *pAddr = EM_SAFE_STRDUP(ptr);
+ EM_DEBUG_FUNC_END("ptr[%s]", ptr);
+}
+
+EXPORT_API char* em_core_skip_whitespace_without_strdup(char *source_string)
+{
+ EM_DEBUG_FUNC_BEGIN("source_string[%p]", source_string);
+
+ if (!source_string)
+ return NULL;
+ int i;
+
+ for (i = 0; source_string[i] != NULL_CHAR ; i++) {
+ if (source_string[i] != SPACE) /* || source_string[i] != TAB || source_string[i] != CR || source_string[i] || LF) */
+ break;
+ }
+
+ EM_DEBUG_FUNC_END("i[%d]", i);
+ return source_string + i;
+}
+
+int em_core_get_address_count(char *addr_str, int *count, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("addr_str[%s], count[%p], err_code[%p]", addr_str, count, err_code);
+
+ int ret = false;
+ int error = EMF_ERROR_NONE;
+
+ ADDRESS *addr = NULL;
+ ADDRESS *p_addr = NULL;
+ int i = 0, j;
+ char *p = NULL;
+
+
+ if (!count) {
+ EM_DEBUG_EXCEPTION("addr_str[%s], count[%p]", addr_str, count);
+ error = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ if (addr_str != NULL) {
+ em_core_skip_whitespace(addr_str, &p);
+ EM_DEBUG_LOG("em_core_skip_whitespace[p][%s]", p);
+
+
+ for (i = 0, j = strlen(p); i < j; i++)
+ if (p[i] == ';') p[i] = ',';
+ rfc822_parse_adrlist(&addr, p, NULL);
+ EM_SAFE_FREE(p);
+
+
+ for (p_addr = addr, i = 0; p_addr; p_addr = p_addr->next, i++) {
+ if (p_addr->mailbox && p_addr->host) {
+ if (!strncmp(p_addr->mailbox, "UNEXPECTED_DATA_AFTER_ADDRESS", strlen("UNEXPECTED_DATA_AFTER_ADDRESS")) || !strncmp(p_addr->mailbox, "INVALID_ADDRESS", strlen("INVALID_ADDRESS")) || !strncmp(p_addr->host, ".SYNTAX-ERROR.", strlen(".SYNTAX-ERROR."))) {
+ EM_DEBUG_LOG("Invalid address ");
+ continue;
+ }
+ }
+ if ((!p_addr->mailbox) || (_em_core_check_host(p_addr->host) == 0)) {
+ EM_DEBUG_EXCEPTION("\t invalid address : mailbox[%s], host[%s]\n", p_addr->mailbox, p_addr->host);
+
+ error = EMF_ERROR_INVALID_ADDRESS;
+ /* goto FINISH_OFF; */
+ }
+ }
+ }
+
+ *count = i;
+ if (error != EMF_ERROR_INVALID_ADDRESS)
+ ret = true;
+
+FINISH_OFF:
+ if (addr)
+ mail_free_address(&addr);
+
+ if (err_code != NULL)
+ *err_code = error;
+ EM_DEBUG_FUNC_END();
+ return ret;
+}
+
+EXPORT_API int em_core_set_network_error(int err_code)
+{
+ emf_session_t *session = NULL;
+
+ EM_DEBUG_FUNC_BEGIN();
+
+ em_core_get_current_session(&session);
+
+ if (!session)
+ return false;
+
+ session->network = err_code;
+ EM_DEBUG_FUNC_END();
+ return true;
+}
+
+int em_core_get_empty_session(emf_session_t **session)
+{
+ EM_DEBUG_FUNC_BEGIN("session[%p]", session);
+
+ /* lock()... */
+
+ int i;
+
+ for (i = 0; i < SESSION_MAX; i++) {
+ if (!g_session_list[i].status) {
+ memset(g_session_list+i, 0x00, sizeof(emf_session_t));
+ g_session_list[i].tid = GPOINTER_TO_INT(THREAD_SELF());
+ g_session_list[i].status = true;
+ break;
+ }
+ }
+
+ /* unlock()... */
+
+ if (session != NULL)
+ *session = (i != SESSION_MAX) ? &g_session_list[i] : NULL;
+ EM_DEBUG_FUNC_END();
+ return (i != SESSION_MAX) ? true : false;
+}
+
+int em_core_clear_session(emf_session_t *session)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ if (session)
+ memset(session, 0x00, sizeof(emf_session_t));
+ EM_DEBUG_FUNC_END();
+ return true;
+}
+
+int em_core_get_current_session(emf_session_t **session)
+{
+ EM_DEBUG_FUNC_BEGIN("session[%p]", session);
+
+ int i;
+
+ for (i = 0; i < SESSION_MAX; i++) {
+ if (g_session_list[i].tid == GPOINTER_TO_INT(THREAD_SELF())) {
+ if (session)
+ *session = g_session_list + i;
+
+ break;
+ }
+ }
+
+ if (session)
+ *session = (i != SESSION_MAX) ? g_session_list + i : NULL;
+ EM_DEBUG_FUNC_END();
+ return (i != SESSION_MAX) ? true : false;
+}
+
+int em_core_check_unread_mail()
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ int ret = false;
+ int err = EMF_ERROR_NONE;
+ int total_unread_count = 0;
+ int total_mail_count = 0;
+ emf_mailbox_t mailbox;
+
+ memset(&mailbox, 0x00, sizeof(emf_mailbox_t));
+
+ /* ALL_ACCOUNT used, so not calling em_storage_get_mailboxname_by_mailbox_type to get mailbox name */
+ mailbox.account_id = ALL_ACCOUNT;
+ mailbox.name = NULL;
+
+ if (!em_core_mailbox_get_mail_count(&mailbox, &total_mail_count, &total_unread_count, &err)) {
+ EM_DEBUG_EXCEPTION("em_core_mailbox_get_mail_count failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ EM_DEBUG_LOG("total_unread_count [%d]", total_unread_count);
+
+ /* set unread count to badge */
+ if ( vconf_set_int(VCONF_KEY_UNREAD_MAIL_COUNT, total_unread_count) != 0 ) {
+ EM_DEBUG_EXCEPTION("vconf_set_int failed");
+ err = EMF_ERROR_GCONF_FAILURE;
+ goto FINISH_OFF;
+ }
+
+ EM_DEBUG_LOG("db/badge/com.samsung.email - set[%d]", total_unread_count);
+
+ ret = true;
+FINISH_OFF:
+
+ return ret;
+}
+
+int em_core_add_notification(int account_id, int mail_id, char *title, char *content, time_t log_time)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int ret = true;
+
+ EM_DEBUG_FUNC_END();
+ return ret;
+}
+
+int em_core_show_popup(int id, emf_action_t action, int error)
+{
+ EM_DEBUG_FUNC_BEGIN("id[%d], action[%d], error[%d]", id, action, error);
+
+ int ret = false;
+ time_t log_time = 0;
+ struct tm *log_time_tm;
+
+ time(&log_time);
+ log_time_tm = localtime(&log_time);
+ log_time = mktime(log_time_tm);
+
+ EM_DEBUG_LOG("sec[%d], min[%d], hour[%d], day[%d], month[%d], year[%d]" ,log_time_tm->tm_sec, log_time_tm->tm_min, log_time_tm->tm_hour, log_time_tm->tm_mday, log_time_tm->tm_mon, log_time_tm->tm_year);
+#ifdef __FEATURE_PROGRESS_IN_OUTBOX__
+ if (action == EMF_ACTION_SEND_MAIL && error != EMF_ERROR_CANCELLED) {
+ /* In case email is cancelled using cancel button in Outbox there is no need to show Cancel/Retry Pop up */
+#else
+ if (action == EMF_ACTION_SEND_MAIL) {
+#endif
+ emf_mail_tbl_t *mail_table_data = NULL;
+
+ if (error == 0) /* error 0 means 'this is not error' */
+ return true;
+
+ if (id <= 0) {
+ EM_DEBUG_LOG("Invalid mail_id");
+ return false;
+ }
+
+ if (!em_storage_get_mail_by_id(id, &mail_table_data, true, NULL)) {
+ EM_DEBUG_LOG("Mail not found");
+ return false;
+ }
+
+ if (!em_core_add_notification(mail_table_data->account_id + 1000, id, "Failed to send mail", mail_table_data->subject, log_time)) {
+ EM_DEBUG_EXCEPTION("em_core_notification_set error");
+ return false;
+ }
+
+ if (!em_storage_free_mail(&mail_table_data, 1, NULL))
+ EM_DEBUG_EXCEPTION("em_storage_free_mail Failed");
+
+ ret = true;
+ }
+ EM_DEBUG_FUNC_END();
+ return ret;
+}
+
+
+/* storage space handling - 210709 */
+int em_core_get_storage_status(void)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int storage_status = 0, nError = 0;
+
+ g_type_init();
+
+#ifdef STORAGE_STATUS
+ nError = vconf_get_int(PS_KEY_SYSTEM_STORAGE_MOVI_STATUS,
+ &storage_status);
+#endif /* STORAGE_STATUS */
+
+ if (nError == -1) {
+ EM_DEBUG_EXCEPTION("vconf_get_int Failed");
+ return false;
+ }
+ EM_DEBUG_FUNC_END();
+ return storage_status;
+}
+
+int em_core_is_storage_full(int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ int ret = false;
+ int err = EMF_ERROR_NONE;
+ struct statfs buf = {0};
+
+ if (statfs(DATA_PATH, &buf) == -1) {
+ EM_DEBUG_EXCEPTION("statfs(\"%s\") failed - %d", DATA_PATH, errno);
+ err = EMF_ERROR_SYSTEM_FAILURE; /* lEMF_ERROR_UNKNOWN; */
+ goto FINISH_OFF;
+ }
+ else {
+ long i_free = (buf.f_bfree * buf.f_bsize) / (1024 * 1024);
+ EM_DEBUG_LOG("f_bfree[%d] f_bsize[%d]", buf.f_bfree, buf.f_bsize);
+ EM_DEBUG_LOG("Free space of storage is[%ld] MB.", i_free);
+ if (i_free < EM_STORAGE_LIMITATION_FREE_SPACE)
+ err = EMF_ERROR_MAIL_MEMORY_FULL;
+ }
+
+ if (err == EMF_ERROR_MAIL_MEMORY_FULL)
+ ret = true;
+
+FINISH_OFF:
+ if (err_code != NULL)
+ *err_code = err;
+ EM_DEBUG_FUNC_END("ret[%d]", ret);
+ return ret;
+}
+
+int em_core_get_mail_size(emf_mail_t *mail_src, int *error_code)
+{
+ EM_DEBUG_FUNC_BEGIN("mail_src[%p], err_code[%p]", mail_src, error_code);
+ EM_PROFILE_BEGIN(profile_em_core_get_mail_size);
+
+ emf_attachment_info_t *atch = NULL;
+ struct stat st_buf;
+ int mail_size = 0; /* size of the plain text body and attachments */
+ int err = EMF_ERROR_NONE;
+
+ if (!mail_src || !mail_src->body) {
+ if (mail_src) {
+ if (mail_src->body)
+ EM_DEBUG_LOG("mail_src[%p], mail_src->body[%p], mail_src->body->plain[%p]", mail_src, mail_src->body, mail_src->body->plain);
+ else
+ EM_DEBUG_LOG(" mail_src[%p], mail_src->body[%p]", mail_src, mail_src->body);
+ }
+ else
+ EM_DEBUG_LOG("mail_src[%p]", mail_src);
+
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ mail_size = 0;
+ if (mail_src->body->plain != NULL) {
+ if (stat(mail_src->body->plain, &st_buf) < 0) {
+ EM_DEBUG_EXCEPTION("mail_src->body->plain stat(\"%s\") failed...", mail_src->body->plain);
+ err = EMF_ERROR_INVALID_MAIL;
+ goto FINISH_OFF;
+ }
+
+ mail_size += st_buf.st_size;
+
+ }
+
+ if (mail_src->body->html != NULL) {
+ if (stat(mail_src->body->html, &st_buf) < 0) {
+ EM_DEBUG_EXCEPTION("mail_src->body->html stat(\"%s\") failed...", mail_src->body->html);
+ err = EMF_ERROR_INVALID_MAIL;
+ goto FINISH_OFF;
+ }
+
+ mail_size += st_buf.st_size;
+ }
+
+ atch = mail_src->body->attachment;
+
+ while (atch) {
+ if (stat(atch->savename, &st_buf) < 0) {
+ EM_DEBUG_EXCEPTION("stat(\"%s\") failed...", atch->savename);
+ err = EMF_ERROR_INVALID_MAIL; /* EMF_ERROR_INVALID_PATH; */
+ goto FINISH_OFF;
+ }
+
+ mail_size += st_buf.st_size;
+ atch = atch->next;
+ }
+
+
+FINISH_OFF:
+ if (error_code)
+ *error_code = err;
+ EM_PROFILE_END(profile_em_core_get_mail_size);
+ EM_DEBUG_FUNC_END();
+ return (err == EMF_ERROR_NONE ? mail_size : 0);
+}
+
+
+int em_core_calc_mail_size(emf_mail_data_t *input_mail_data, emf_attachment_data_t *input_attachment_data_list, int input_attachment_count, int *output_size)
+{
+ EM_DEBUG_FUNC_BEGIN("input_mail_data[%p], input_attachment_data_list[%p], input_attachment_count[%d], output_size[%p]", input_mail_data, input_attachment_data_list, input_attachment_count, output_size);
+
+ struct stat st_buf;
+ int mail_size = 0; /* size of the plain text body and attachments */
+ int err = EMF_ERROR_NONE;
+ int i = 0;
+
+ if (!input_mail_data || (input_attachment_count && !input_attachment_data_list) || (!input_attachment_count &&input_attachment_data_list) || !output_size) {
+ EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ if (input_mail_data->file_path_plain != NULL) {
+ if (stat(input_mail_data->file_path_plain, &st_buf) < 0) {
+ EM_DEBUG_EXCEPTION("input_mail_data->file_path_plain : stat(\"%s\") failed...", input_mail_data->file_path_plain);
+ err = EMF_ERROR_INVALID_MAIL;
+ goto FINISH_OFF;
+ }
+
+ mail_size += st_buf.st_size;
+
+ }
+
+ if (input_mail_data->file_path_html != NULL) {
+ if (stat(input_mail_data->file_path_html, &st_buf) < 0) {
+ EM_DEBUG_EXCEPTION("input_mail_data->file_path_html : stat(\"%s\") failed...", input_mail_data->file_path_html);
+ err = EMF_ERROR_INVALID_MAIL;
+ goto FINISH_OFF;
+ }
+
+ mail_size += st_buf.st_size;
+ }
+
+ for(i = 0; i < input_attachment_count; i++) {
+ if (stat(input_attachment_data_list[i].attachment_path, &st_buf) < 0) {
+ EM_DEBUG_EXCEPTION("stat(\"%s\") failed...", input_attachment_data_list[i].attachment_path);
+ err = EMF_ERROR_INVALID_MAIL;
+ goto FINISH_OFF;
+ }
+ mail_size += st_buf.st_size;
+ }
+
+ *output_size = mail_size;
+
+FINISH_OFF:
+
+ EM_DEBUG_FUNC_END("mail_size [%d]", mail_size);
+ return err;
+}
+
+
+int em_storage_get_emf_error_from_em_storage_error(int error)
+{
+ switch (error) {
+ case EM_STORAGE_ERROR_NONE:
+ return EMF_ERROR_NONE;
+
+ case EM_STORAGE_ERROR_INVALID_PARAM:
+ return EMF_ERROR_INVALID_PARAM;
+
+ case EM_STORAGE_ERROR_ACCOUNT_NOT_FOUND:
+ return EMF_ERROR_ACCOUNT_NOT_FOUND;
+
+ case EM_STORAGE_ERROR_MAIL_NOT_FOUND:
+ return EMF_ERROR_MAIL_NOT_FOUND;
+
+ case EM_STORAGE_ERROR_MAILBOX_NOT_FOUND:
+ return EMF_ERROR_MAILBOX_NOT_FOUND;
+
+ case EM_STORAGE_ERROR_ATTACHMENT_NOT_FOUND:
+ return EMF_ERROR_ATTACHMENT_NOT_FOUND;
+
+ case EM_STORAGE_ERROR_CONTACT_NOT_FOUND:
+ return EMF_ERROR_CONTACT_NOT_FOUND;
+
+ case EM_STORAGE_ERROR_FILE_NOT_FOUND:
+ return EMF_ERROR_FILE_NOT_FOUND;
+
+ case EM_STORAGE_ERROR_DATA_NOT_FOUND:
+ return EMF_ERROR_DATA_NOT_FOUND;
+
+ case EM_STORAGE_ERROR_NO_MORE_DATA:
+ return EMF_ERROR_NO_MORE_DATA;
+
+ case EM_STORAGE_ERROR_DATA_TOO_LONG:
+ return EMF_ERROR_DATA_TOO_LONG;
+
+ case EM_STORAGE_ERROR_DATA_TOO_SMALL:
+ return EMF_ERROR_DATA_TOO_SMALL;
+
+ case EM_STORAGE_ERROR_OUT_OF_MEMORY:
+ return EMF_ERROR_OUT_OF_MEMORY;
+
+ case EM_STORAGE_ERROR_CONNECTION_FAILURE:
+ return EMF_ERROR_CONNECTION_FAILURE;
+
+ case EM_STORAGE_ERROR_SYSTEM_FAILURE:
+ return EMF_ERROR_SYSTEM_FAILURE;
+
+ case EM_STORAGE_ERROR_RULE_NOT_FOUND:
+ return EMF_ERROR_FILTER_NOT_FOUND;
+
+ case EM_STORAGE_ERROR_DB_IS_FULL:
+ return EMF_ERROR_MAIL_MEMORY_FULL;
+
+ case EM_STORAGE_ERROR_DB_FAILURE:
+ return EMF_ERROR_DB_FAILURE;
+
+ case EM_STORAGE_ERROR_MAIL_MAX_COUNT:
+ return EMF_ERROR_MAIL_MAX_COUNT;
+
+ case EM_STORAGE_ERROR_MMC_NOT_FOUND:
+ return EMF_ERROR_NO_MMC_INSERTED;
+
+ case EM_STORAGE_ERROR_ALREADY_EXISTS:
+ return EMF_ERROR_ALREADY_EXISTS;
+
+ case EM_STORAGE_ERROR_UNKNOWN:
+ default:
+ return EMF_ERROR_UNKNOWN;
+ }
+
+ return EMF_ERROR_UNKNOWN;
+}
+
+
+/* parse the Full mailbox Path and Get the Alias Name of the Mailbox */
+char *em_core_get_alias_of_mailbox(const char *mailbox_path)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ EM_IF_NULL_RETURN_VALUE(mailbox_path, NULL);
+
+ guint index = 0;
+ gchar **token_list = NULL;
+ gchar *mailbox = NULL, *name = NULL;
+ char *converted_name;
+
+
+ mailbox = g_strdup(mailbox_path);
+ token_list = g_strsplit_set(mailbox, "/", -1);
+
+ if (mailbox)
+ g_free(mailbox);
+
+ while (token_list[index] != NULL)
+ index++;
+
+ name = g_strdup(token_list[index - 1]);
+ g_strfreev(token_list);
+
+ converted_name = em_core_convert_mutf7_to_utf8(name);
+
+ if (name)
+ g_free(name);
+
+ EM_DEBUG_FUNC_END();
+ return converted_name;
+}
+
+EXPORT_API int em_core_open_contact_db_library(void)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int err;
+ int ret = false;
+
+ if ((err = contacts_svc_connect()) == CTS_SUCCESS)
+ EM_DEBUG_LOG("Open Contact Service Success");
+ else {
+ EM_DEBUG_EXCEPTION("contact_db_service_connect failed - %d", err);
+ return false;
+ }
+ ret = true;
+
+ EM_DEBUG_FUNC_END();
+ return ret;
+
+}
+
+EXPORT_API void em_core_close_contact_db_library()
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int err;
+
+ if ((err = contacts_svc_disconnect()) == CTS_SUCCESS)
+ EM_DEBUG_LOG("Close Contact Service Success");
+ else
+ EM_DEBUG_EXCEPTION("Close Contact Service Fail[%d]", err);
+ EM_DEBUG_FUNC_END();
+ return;
+}
+
+#define EMAIL_ACCOUNT_RGEX "([a-z0-9!#$%&'*+/=?^_`{|}~-]+.)*[a-z0-9!#$%&'*+/=?^_`{|}~-]+"
+#define EMAIL_DOMAIN_RGEX "([a-z0-9!#$%&'*+/=?^_`{|}~-]+.)+[a-z0-9!#$%&'*+/=?^_`{|}~-]+"
+
+#define EMAIL_ADDR_RGEX "[[:space:]]*<"EMAIL_ACCOUNT_RGEX"@"EMAIL_DOMAIN_RGEX">[[:space:]]*"
+#define EMAIL_ALIAS_RGEX "([[:space:]]*\"[^\"]*\")?"EMAIL_ADDR_RGEX
+#define EMAIL_ALIAS_LIST_RGEX "^("EMAIL_ALIAS_RGEX"[;,])*"EMAIL_ALIAS_RGEX"[;,]?[[:space:]]*$"
+
+#define EMAIL_ADDR_WITHOUT_BRACKET_RGEX "[[:space:]]*"EMAIL_ACCOUNT_RGEX"@"EMAIL_DOMAIN_RGEX"[[:space:]]*"
+#define EMAIL_ALIAS_WITHOUT_BRACKET_RGEX "([[:space:]]*\"[^\"]*\")?"EMAIL_ADDR_WITHOUT_BRACKET_RGEX
+#define EMAIL_ALIAS_LIST_WITHOUT_BRACKET_RGEX "("EMAIL_ALIAS_WITHOUT_BRACKET_RGEX"[;,])*"EMAIL_ADDR_WITHOUT_BRACKET_RGEX"[;,]?[[:space:]]*$"
+
+EXPORT_API int em_core_verify_email_address(char *address, int without_bracket, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("address[%s] without_bracket[%d]", address, without_bracket);
+
+ /* this following code verfies the email alias string using reg. exp. */
+ regex_t alias_list_regex = {0};
+ int ret = false, error = EMF_ERROR_NONE;
+ char *reg_rule = NULL;
+
+ if(!address || strlen(address) == 0) {
+ EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
+ if (err_code)
+ *err_code = EMF_ERROR_INVALID_PARAM;
+ return false;
+ }
+
+ if(without_bracket)
+ reg_rule = EMAIL_ALIAS_LIST_WITHOUT_BRACKET_RGEX;
+ else
+ reg_rule = EMAIL_ALIAS_LIST_RGEX;
+
+ if (regcomp(&alias_list_regex, reg_rule, REG_ICASE | REG_EXTENDED)) {
+ EM_DEBUG_EXCEPTION("email alias regex unrecognized");
+ if (err_code)
+ *err_code = EMF_ERROR_UNKNOWN;
+ return false;
+ }
+
+ int alias_len = strlen(address) + 1;
+ regmatch_t pmatch[alias_len];
+
+ bzero(pmatch, alias_len);
+
+ if (regexec(&alias_list_regex, address, alias_len, pmatch, 0) == REG_NOMATCH)
+ EM_DEBUG_LOG("failed :[%s]", address);
+ else {
+ EM_DEBUG_LOG("success :[%s]", address);
+ ret = true;
+ }
+
+ regfree(&alias_list_regex);
+
+ if (err_code)
+ *err_code = error;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+EXPORT_API int em_core_verify_email_address_of_mail_header(emf_mail_head_t *mail_header, int without_bracket, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("mail_header[%p] without_bracket[%d]", mail_header, without_bracket);
+ char *address_array[4] = { mail_header->to, mail_header->cc, mail_header->bcc, mail_header->from};
+ int ret = false, err = EMF_ERROR_NONE, i;
+
+ /* check for email_address validation */
+ for (i = 0; i < 4; i++) {
+ if (address_array[i] && address_array[i][0] != 0) {
+ if (!em_core_verify_email_address(address_array[i] , without_bracket, &err)) {
+ err = EMF_ERROR_INVALID_ADDRESS;
+ EM_DEBUG_EXCEPTION("Invalid Email Address [%d][%s]", i, address_array[i]);
+ goto FINISH_OFF;
+ }
+ }
+ }
+ ret = true;
+FINISH_OFF:
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+EXPORT_API int em_core_verify_email_address_of_mail_data(emf_mail_data_t *mail_data, int without_bracket, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("mail_data[%p] without_bracket[%d]", mail_data, without_bracket);
+ char *address_array[4] = { mail_data->full_address_from, mail_data->full_address_to, mail_data->full_address_cc, mail_data->full_address_bcc};
+ int ret = false, err = EMF_ERROR_NONE, i;
+
+ /* check for email_address validation */
+ for (i = 0; i < 4; i++) {
+ if (address_array[i] && address_array[i][0] != 0) {
+ if (!em_core_verify_email_address(address_array[i] , without_bracket, &err)) {
+ err = EMF_ERROR_INVALID_ADDRESS;
+ EM_DEBUG_EXCEPTION("Invalid Email Address [%d][%s]", i, address_array[i]);
+ goto FINISH_OFF;
+ }
+ }
+ }
+ ret = true;
+FINISH_OFF:
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+EXPORT_API int em_core_get_server_time(void *mail_stream, int account_id, char *uid, int msgno, time_t *log_time, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ int ret_code = false;
+ int err = EMF_ERROR_NONE;
+ emf_account_t *account = NULL;
+ emf_mailbox_t mailbox = { 0 };
+ MESSAGECACHE *elt = NULL;
+ char datetime[DATETIME_LENGTH] = { 0, };
+ emf_datetime_t date = { 0 };
+ struct tm tm1 = { 0 };
+ time_t t = time(NULL);
+
+
+ if (!mail_stream || (!uid && msgno < 1)) {
+ EM_DEBUG_EXCEPTION("Param is NULL");
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ mailbox.account_id = account_id;
+ mailbox.mail_stream = mail_stream;
+
+ if (!(account = em_core_get_account_reference(account_id))) {
+ EM_DEBUG_EXCEPTION("em_core_get_account_reference failed - %d", account_id);
+ err = EMF_ERROR_INVALID_ACCOUNT;
+ goto FINISH_OFF;
+ }
+ if (msgno < 1) { /* get msgno from server */
+ if (!em_core_mail_get_msgno_by_uid(account, &mailbox, uid, &msgno, &err)) {
+ EM_DEBUG_EXCEPTION("em_core_mail_get_msgno_by_uid failed message_no : %d ", err);
+ goto FINISH_OFF;
+ }
+ }
+ if (!(elt = mail_elt(mailbox.mail_stream, msgno))) {
+ EM_DEBUG_EXCEPTION("mail_elt failed...");
+ err = EMF_ERROR_UNKNOWN;
+ goto FINISH_OFF;
+ }
+ SNPRINTF(datetime, sizeof(datetime), "%04d%02d%02d%02d%02d%02d",
+ BASEYEAR + elt->year, elt->month, elt->day, elt->hours, elt->minutes, elt->seconds);
+
+ EM_DEBUG_LOG("datetime[%s]", datetime);
+
+ if (!em_convert_string_to_datetime(datetime, &date, &err))
+ EM_DEBUG_EXCEPTION("em_convert_string_to_datetime failed - %d", err);
+
+ tm1.tm_year = date.year - 1900;
+ tm1.tm_mon = date.month - 1;
+ tm1.tm_mday = date.day;
+ tm1.tm_hour = date.hour;
+ tm1.tm_min = date.minute;
+ tm1.tm_sec = date.second;
+ t = mktime(&tm1);
+
+ *log_time = t;
+ ret_code = true;
+
+FINISH_OFF:
+
+ if (err_code)
+ *err_code = err;
+
+ EM_DEBUG_FUNC_END();
+ return ret_code;
+}
+
+static int em_core_get_first_address(const char *full_address, char **alias, char **address)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ if (full_address == NULL || alias == NULL || address == NULL){
+ EM_DEBUG_EXCEPTION("Invalid Param : full_address[%p], alias[%p], address[%p]", full_address, alias, address);
+ return false;
+ }
+
+ char *s = NULL;
+ char *alias_start = NULL;
+ char *alias_end = NULL;
+ char *alias_cursor = NULL;
+ char *address_start = NULL;
+ char *address_end = NULL;
+ char *first_address = NULL;
+
+ if (full_address){
+ s = (char *)strchr((char *)full_address, ';');
+ if (s == NULL)
+ first_address = strdup(full_address); /* only one address */
+ else
+ first_address = strndup(full_address, s - full_address); /* over two addresses */
+
+ /* get alias */
+ *alias = NULL;
+ if ((alias_start = (char *)strchr((char *)first_address, '\"'))){
+ alias_start++;
+ alias_cursor = alias_start;
+ while ((alias_cursor = (char *)strchr((char *)(alias_cursor), '\"'))){
+ alias_end = alias_cursor;
+ alias_cursor++;
+ if (*alias_cursor == 0)
+ break;
+ }
+ if (alias_end) { /* there is "alias" */
+ *alias = strndup(alias_start, alias_end - alias_start);
+ EM_DEBUG_LOG("alias [%s]", *alias);
+ }
+ }
+
+ /* get address */
+ *address = NULL;
+ if (alias_end == NULL)
+ s = first_address;
+ else
+ s = alias_end+1;
+ if ((address_start = (char *)strchr((char *)s, '<'))){
+ address_start++;
+ if ((address_end = (char *)strchr((char *)address_start, '>')))
+ *address = strndup(address_start, address_end - address_start); /* (alias) <(addr)> ... */
+ else
+ *address = strdup(s);
+ }
+ else
+ *address = strdup(s); /* (addr) ; ... : no alias */
+ }
+
+ EM_SAFE_FREE(first_address);
+ EM_DEBUG_FUNC_END();
+ return true;
+}
+
+EXPORT_API void em_core_fill_address_information_of_mail_tbl(emf_mail_tbl_t *mail_data)
+{
+ EM_DEBUG_FUNC_BEGIN("mail_data [%p]", mail_data);
+
+ char *first_alias = NULL;
+ char *first_address = NULL;
+ char *recipient = NULL;
+
+ /* sender alias & address */
+ if (em_core_get_first_address(mail_data->full_address_from, &first_alias, &first_address) == true) {
+ if (first_alias == NULL) {
+ mail_data->alias_sender = EM_SAFE_STRDUP(first_address);
+ }
+ else {
+ mail_data->alias_sender = first_alias;
+ first_alias = NULL;
+ }
+ mail_data->email_address_sender = first_address;
+ first_address = NULL;
+ }
+
+ /* recipient alias & address */
+ if (mail_data->full_address_to != NULL)
+ recipient = mail_data->full_address_to;
+ else if (mail_data->full_address_cc != NULL)
+ recipient = mail_data->full_address_cc;
+ else if (mail_data->full_address_bcc != NULL)
+ recipient = mail_data->full_address_bcc;
+
+ if (em_core_get_first_address(recipient, &first_alias, &first_address) == true) {
+ if (first_alias == NULL)
+ mail_data->alias_recipient = EM_SAFE_STRDUP(first_address);
+ else
+ mail_data->alias_recipient = first_alias;
+
+ mail_data->email_address_recipient = first_address;
+ }
+ EM_DEBUG_FUNC_END();
+}
+
+
+EXPORT_API int em_core_get_preview_text_from_file(const char *input_plain_path, const char *input_html_path, int input_preview_buffer_length, char **output_preview_buffer)
+{
+ EM_DEBUG_FUNC_BEGIN("input_plain_path[%p], input_html_path[%p], input_preview_buffer_length [%d], output_preview_buffer[%p]", input_plain_path, input_html_path, input_preview_buffer_length, output_preview_buffer);
+
+ int err = EMF_ERROR_NONE;
+ unsigned int byte_read = 0;
+ unsigned int byte_written = 0;
+ int result_strlen = 0;
+ int local_preview_buffer_length = 0;
+ char *local_preview_text = NULL;
+ char *encoding_type = NULL;
+ char *utf8_encoded_string = NULL;
+ FILE *fp = NULL;
+ GError *glib_error = NULL;
+ struct stat st_buf;
+
+ if (!output_preview_buffer) {
+ EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ local_preview_buffer_length = input_preview_buffer_length * 2;
+
+ if (input_html_path != NULL) {
+ /* get preview text from html file */
+ if( (err = em_core_get_encoding_type_from_file_path(input_html_path, &encoding_type)) != EMF_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("em_core_get_encoding_type_from_file_path failed [%s]", err);
+ goto FINISH_OFF;
+ }
+
+ if (stat(input_html_path, &st_buf) < 0) {
+ EM_DEBUG_EXCEPTION("stat(\"%s\") failed...", input_html_path);
+ err = EMF_ERROR_INVALID_MAIL;
+ goto FINISH_OFF;
+ }
+
+ if (!(fp = fopen(input_html_path, "r"))) {
+ EM_DEBUG_EXCEPTION("fopen failed [%s]", input_html_path);
+ err = EMF_ERROR_SYSTEM_FAILURE;
+ goto FINISH_OFF;
+ }
+
+ if (!(local_preview_text = (char*)em_core_malloc(sizeof(char) * (st_buf.st_size + 1)))) {
+ EM_DEBUG_EXCEPTION("em_core_malloc failed");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ byte_read = fread(local_preview_text, sizeof(char), st_buf.st_size, fp);
+
+ if (ferror(fp)) {
+ EM_DEBUG_EXCEPTION("fread failed [%s]", input_plain_path);
+ err = EMF_ERROR_SYSTEM_FAILURE;
+ goto FINISH_OFF;
+ }
+
+ if ( (err = em_core_strip_HTML(local_preview_text)) != EMF_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("em_core_strip_HTML failed");
+ goto FINISH_OFF;
+ }
+
+ result_strlen = EM_SAFE_STRLEN(local_preview_text);
+ }
+
+ if (local_preview_text == NULL && input_plain_path != NULL) {
+ /* get preview text from plain text file */
+ if( (err = em_core_get_encoding_type_from_file_path(input_plain_path, &encoding_type)) != EMF_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("em_core_get_encoding_type_from_file_path failed [%s]", err);
+ goto FINISH_OFF;
+ }
+
+ if (!(fp = fopen(input_plain_path, "r"))) {
+ EM_DEBUG_EXCEPTION("fopen failed [%s]", input_plain_path);
+ err = EMF_ERROR_SYSTEM_FAILURE;
+ goto FINISH_OFF;
+ }
+
+ if (!(local_preview_text = (char*)em_core_malloc(sizeof(char) * local_preview_buffer_length))) {
+ EM_DEBUG_EXCEPTION("em_core_malloc failed");
+ goto FINISH_OFF;
+ }
+
+ byte_read = fread(local_preview_text, sizeof(char), local_preview_buffer_length - 1, fp);
+
+ if (ferror(fp)) {
+ EM_DEBUG_EXCEPTION("fread failed [%s]", input_plain_path);
+ err = EMF_ERROR_SYSTEM_FAILURE;
+ goto FINISH_OFF;
+ }
+ result_strlen = byte_read;
+ }
+
+
+ if(local_preview_text) {
+ if(encoding_type && strcasecmp(encoding_type, "UTF-8") != 0) {
+ EM_DEBUG_LOG("encoding_type [%s]", encoding_type);
+ utf8_encoded_string = (char*)g_convert (local_preview_text, -1, "UTF-8", encoding_type, &byte_read, &byte_written, &glib_error);
+
+ if(utf8_encoded_string) {
+ EM_SAFE_FREE(local_preview_text);
+ local_preview_text = utf8_encoded_string;
+ }
+ else
+ EM_DEBUG_EXCEPTION("g_convert failed");
+ }
+
+ if (!(*output_preview_buffer = (char*)em_core_malloc(sizeof(char) * (result_strlen + 1)))) {
+ EM_DEBUG_EXCEPTION("em_core_malloc failed");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ EM_SAFE_STRNCPY(*output_preview_buffer, local_preview_text, result_strlen);
+ /* EM_DEBUG_LOG("local_preview_text[%s], byte_read[%d], result_strlen[%d]", local_preview_text, byte_read, result_strlen); */
+ }
+
+FINISH_OFF:
+
+ EM_SAFE_FREE(local_preview_text);
+ EM_SAFE_FREE(encoding_type);
+
+ if (fp != NULL)
+ fclose(fp);
+
+ EM_DEBUG_FUNC_END("err [%d]", err);
+ return err;
+}
+
+EXPORT_API int em_core_add_transaction_info(int mail_id, int handle , int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("mail_id[%d], handle[%d]", mail_id, handle);
+
+ int ret = false;
+ int err = EMF_ERROR_NONE ;
+ em_transaction_info_type_t *pTransinfo = NULL ;
+ em_transaction_info_type_t *pTemp = NULL;
+
+ EM_DEBUG_LOG("g_transaction_info_list[%p]", g_transaction_info_list);
+ pTransinfo = g_transaction_info_list ;
+
+ if (!(pTemp = em_core_malloc(sizeof(em_transaction_info_type_t)))) {
+ EM_DEBUG_EXCEPTION("malloc failed...");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+ pTemp->mail_id = mail_id ;
+ pTemp->handle = handle;
+
+ if (!pTransinfo) {
+ pTransinfo = pTemp ;
+ g_transaction_info_list = pTransinfo ;
+ }
+ else {
+ while (pTransinfo->next)
+ pTransinfo = pTransinfo->next;
+ pTransinfo->next = pTemp;
+ }
+ ret = true ;
+
+FINISH_OFF:
+
+ if (err_code)
+ *err_code = err;
+ EM_DEBUG_FUNC_END("g_transaction_info_list[%p]", g_transaction_info_list);
+ return ret;
+}
+
+EXPORT_API int em_core_get_handle_by_mailId_from_transaction_info(int mail_id, int *pHandle)
+{
+ EM_DEBUG_FUNC_BEGIN("mail_id[%d], handle[%p]", mail_id, pHandle);
+
+ int ret = false;
+ em_transaction_info_type_t *pTransinfo = NULL ;
+
+ if (g_transaction_info_list == NULL) {
+ EM_DEBUG_EXCEPTION("g_transaction_info_list NULL");
+ return false;
+ }
+ pTransinfo = g_transaction_info_list;
+
+ do {
+ EM_DEBUG_LOG("pTransinfo->mail_id[%d]", pTransinfo->mail_id);
+ if (pTransinfo->mail_id == mail_id) {
+ *pHandle = pTransinfo->handle;
+ ret = true;
+ EM_DEBUG_LOG("*pHandle[%d]", *pHandle);
+ break;
+ }
+ else
+ pTransinfo = pTransinfo->next ;
+ }while (pTransinfo);
+ EM_DEBUG_FUNC_END();
+ return ret;
+}
+
+EXPORT_API int em_core_delete_transaction_info_by_mailId(int mail_id )
+{
+ EM_DEBUG_FUNC_BEGIN("mail_id[%d]", mail_id);
+
+ em_transaction_info_type_t *pTransinfo ;
+ em_transaction_info_type_t *pTemp = NULL;
+
+ if (g_transaction_info_list == NULL) {
+ EM_DEBUG_EXCEPTION("g_transaction_info_list NULL");
+ return false;
+ }
+ pTransinfo = g_transaction_info_list;
+
+ EM_DEBUG_LOG("pTransinfo[%p]", pTransinfo);
+
+ do {
+ EM_DEBUG_LOG("pTransinfo->mail_id[%d]", pTransinfo->mail_id);
+ if (pTransinfo->mail_id == mail_id) {
+ pTemp = pTransinfo->next ;
+ if (!pTemp) {
+ EM_SAFE_FREE(pTransinfo) ;
+ g_transaction_info_list = NULL;
+ }
+ else {
+ pTransinfo->mail_id = pTransinfo->next->mail_id;
+ pTransinfo->handle = pTransinfo->next->handle ;
+ pTransinfo->next = pTransinfo->next->next;
+
+ EM_SAFE_FREE(pTemp);
+ }
+ break;
+ }
+ else {
+ pTransinfo = pTransinfo->next ;
+ }
+
+ }while (pTransinfo);
+ EM_DEBUG_FUNC_END();
+ return true;
+}
+
+
+#include <regex.h>
+
+int reg_replace (char *input_source_text, char *input_old_pattern_string, char *input_new_string)
+{
+ EM_DEBUG_FUNC_BEGIN("input_source_text [%p], input_old_pattern_string [%p], input_new_string [%p]", input_source_text, input_old_pattern_string, input_new_string);
+ int error_code = EMF_ERROR_NONE;
+ char *pos = NULL;
+ int so, n, nmatch, source_text_length, n_count = 1;
+ regmatch_t *pmatch = NULL;
+ regex_t reg_pattern;
+
+ if(!input_source_text || !input_old_pattern_string || !input_new_string) {
+ EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
+ error_code = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ source_text_length = strlen(input_source_text);
+
+ regcomp(&reg_pattern, input_old_pattern_string, REG_ICASE);
+
+ nmatch = reg_pattern.re_nsub + 1;
+
+ EM_DEBUG_LOG("nmatch [%d]", nmatch);
+
+ if(nmatch < 1) {
+ EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_DATA");
+ error_code = EMF_ERROR_INVALID_DATA;
+ goto FINISH_OFF;
+ }
+
+ pmatch = (regmatch_t*)em_core_malloc(sizeof(regmatch_t) * nmatch);
+
+ if(pmatch == NULL) {
+ EM_DEBUG_EXCEPTION("EMF_ERROR_OUT_OF_MEMORY");
+ error_code = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ for (pos = input_new_string; *pos ; pos++) {
+ if (*pos == '\\' && *(pos + 1) > '0' && *(pos + 1) <= '9') {
+
+ so = pmatch[*(pos + 1) - 48].rm_so;
+ n = pmatch[*(pos + 1) - 48].rm_eo - so;
+
+ EM_DEBUG_LOG("so [%d], n [%d]", so, n);
+
+ if (so < 0 || strlen (input_new_string) + n - 1 > source_text_length)
+ break;
+
+ memmove (pos + n, pos + 2, strlen (pos) - 1);
+ memmove (pos, input_source_text + so, n);
+ pos = pos + n - 2;
+ }
+ }
+
+ for (pos = input_source_text; !regexec (&reg_pattern, pos, 1, pmatch, 0);) {
+ n = pmatch[0].rm_eo - pmatch[0].rm_so;
+ pos += pmatch[0].rm_so;
+
+ memmove (pos + strlen (input_new_string), pos + n, strlen (pos) - n + 1);
+ memmove (pos, input_new_string, strlen (input_new_string));
+ pos += strlen (input_new_string);
+ n_count++;
+ }
+
+FINISH_OFF:
+
+ EM_SAFE_FREE(pmatch);
+ regfree (&reg_pattern);
+
+ EM_DEBUG_FUNC_END("error_code [%d]", error_code);
+ return error_code;
+}
+
+
+EXPORT_API int em_core_strip_HTML(char *source_string)
+{
+ EM_DEBUG_FUNC_BEGIN("source_string [%p]", source_string);
+
+ int result = EMF_ERROR_NONE;
+
+ reg_replace(source_string, CR_STRING, "");
+ reg_replace(source_string, LF_STRING, "");
+ reg_replace(source_string, TAB_STRING, "");
+ reg_replace(source_string, "<head[^>]*>", "<head>"); /* "<()*head([^>])*>", "<head>" */
+ reg_replace(source_string, "<*/head>", "</head>"); /* "(<()*(/)()*head()*>)", "</head>" */
+ reg_replace(source_string, "<head>.*</head>", ""); /* "(<head>).*(</head>)", "" */
+
+ reg_replace(source_string, "<*/p>", LF_STRING);
+
+ /* "<[^>]*>", " */
+ reg_replace(source_string, "<[^>]*>", "");
+
+
+ /* "&bull;", " * */
+ /* reg_replace(source_string, "&bull;", " * "); */
+
+ /* "&lsaquo;", "< */
+ /* reg_replace(source_string, "&lsaquo;", "<"); */
+
+ /* "&rsaquo;", "> */
+ /* reg_replace(source_string, "&rsaquo;", ">"); */
+
+ /* "&trade;", "(tm) */
+ /* reg_replace(source_string, "&trade;", "(tm)"); */
+
+ /* "&frasl;", "/ */
+ /* reg_replace(source_string, "&frasl;", "/"); */
+
+ /* "&lt;", "< */
+ reg_replace(source_string, "&lt;", "<");
+
+ /* "&gt;", "> */
+ reg_replace(source_string, "&gt;", ">");
+
+ /* "&copy;", "(c) */
+ /* reg_replace(source_string, "&copy;", "(c)"); */
+
+ /* "&quot;", "\' */
+ reg_replace(source_string, "&quot;", "\'");
+
+ /* "&nbsp;", " */
+ reg_replace(source_string, "&nbsp;", " ");
+
+ reg_replace(source_string, "\n\n", "");
+ reg_replace(source_string, " ", "");
+
+ EM_DEBUG_FUNC_END();
+
+ return result;
+}
+
+#define MAX_NOTI_STRING_LENGTH 8096
+
+EXPORT_API int em_core_convert_structure_to_string(void *struct_var, char **encoded_string, emf_convert_struct_type_e type)
+{
+ EM_DEBUG_FUNC_BEGIN("Struct type[%d]", type);
+
+ char *buf = NULL;
+ char delimiter[] = {0x01, 0x00};
+ int error_code = EMF_ERROR_NONE;
+
+ buf = (char *) malloc(MAX_NOTI_STRING_LENGTH * sizeof(char));
+ if (NULL == buf) {
+ error_code = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+ switch (type) {
+ case EMF_CONVERT_STRUCT_TYPE_MAIL_LIST_ITEM: {
+ emf_mail_list_item_t *item = (emf_mail_list_item_t *)struct_var;
+ SNPRINTF(buf, MAX_NOTI_STRING_LENGTH,
+ "%d%c" /* int mail_id ; */
+ "%d%c" /* int account_id ; */
+ "%s%c" /* char mailbox_name[STRING_LENGTH_FOR_DISPLAY] ; */
+ "%s%c" /* char from[STRING_LENGTH_FOR_DISPLAY] ; */
+ "%s%c" /* char from_email_address[MAX_EMAIL_ADDRESS_LENGTH]; */
+ "%s%c" /* char recipients[STRING_LENGTH_FOR_DISPLAY] ; */
+ "%s%c" /* char subject[STRING_LENGTH_FOR_DISPLAY] ; */
+ "%d%c" /* int is_text_downloaded ; */
+ "%s%c" /* char datetime[MAX_DATETIME_STRING_LENGTH] ; */
+ "%d%c" /* int flags_seen_field ; */
+ "%d%c" /* int priority ; */
+ "%d%c" /* int save_status ; */
+ "%d%c" /* int is_locked ; */
+ "%d%c" /* int is_report_mail ; */
+ "%d%c" /* int recipients_count ; */
+ "%d%c" /* int has_attachment ; */
+ "%d%c" /* int has_drm_attachment ; */
+ "%s%c" /* char previewBodyText[MAX_PREVIEW_TEXT_LENGTH] ; */
+ "%d%c" /* int thread_id ; */
+ "%d%c", /* int thread_item_count ; */
+
+ item->mail_id, delimiter[0],
+ item->account_id, delimiter[0],
+ item->mailbox_name, delimiter[0],
+ item->from, delimiter[0],
+ item->from_email_address, delimiter[0],
+ item->recipients, delimiter[0],
+ item->subject, delimiter[0],
+ item->is_text_downloaded, delimiter[0],
+ item->datetime, delimiter[0],
+ item->flags_seen_field, delimiter[0],
+ item->priority, delimiter[0],
+ item->save_status, delimiter[0],
+ item->is_locked, delimiter[0],
+ item->is_report_mail, delimiter[0],
+ item->recipients_count, delimiter[0],
+ item->has_attachment, delimiter[0],
+ item->has_drm_attachment, delimiter[0],
+ item->previewBodyText, delimiter[0],
+ item->thread_id, delimiter[0],
+ item->thread_item_count, delimiter[0]
+ );
+ }
+ break;
+ }
+
+FINISH_OFF:
+ if (encoded_string)
+ *encoded_string = buf;
+ EM_DEBUG_FUNC_END("Struct -> String:[%s]\n", buf);
+ return error_code;
+}
+
+EXPORT_API int em_core_convert_string_to_structure(const char *encoded_string, void **struct_var, emf_convert_struct_type_e type)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ int ret = false;
+ void *temp_struct = NULL;
+ char *buff = NULL;
+ char *current_pos = NULL;
+ char *found_pos = NULL;
+ char delimiter[] = {0x01, 0x00};
+ int error_code = EMF_ERROR_NONE;
+
+ EM_DEBUG_LOG("Struct Type[%d], String:[%s]", type, encoded_string);
+
+ buff = (char *)EM_SAFE_STRDUP(encoded_string);
+ if (NULL == buff) {
+ error_code = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ switch (type) {
+ case EMF_CONVERT_STRUCT_TYPE_MAIL_LIST_ITEM: {
+ emf_mail_list_item_t *item = (emf_mail_list_item_t *)malloc(sizeof(emf_mail_list_item_t));
+ if (NULL == item) {
+ error_code = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+ temp_struct = (void *)item;
+
+ current_pos = buff;
+
+ /* mail_id */
+ found_pos = strstr(current_pos, delimiter);
+ if (NULL == found_pos) {
+ error_code = EMF_ERROR_INVALID_DATA;
+ goto FINISH_OFF;
+ }
+ *found_pos = NULL_CHAR;
+ item->mail_id = atoi(current_pos);
+ EM_DEBUG_LOG("mail_id[%d]", item->mail_id);
+ current_pos = found_pos + 1;
+
+ /* account_id */
+ found_pos = strstr(current_pos, delimiter);
+ if (NULL == found_pos) {
+ error_code = EMF_ERROR_INVALID_DATA;
+ goto FINISH_OFF;
+ }
+ *found_pos = NULL_CHAR;
+ item->account_id = atoi(current_pos);
+ EM_DEBUG_LOG("account_id[%d]", item->account_id);
+ current_pos = found_pos + 1;
+
+ /* mailbox_name */
+ found_pos = strstr(current_pos, delimiter);
+ if (NULL == found_pos) {
+ error_code = EMF_ERROR_INVALID_DATA;
+ goto FINISH_OFF;
+ }
+ *found_pos = NULL_CHAR;
+ strncpy(item->mailbox_name, current_pos, STRING_LENGTH_FOR_DISPLAY-1);
+ EM_DEBUG_LOG("mailbox_name[%s]", item->mailbox_name);
+ current_pos = found_pos + 1;
+
+ /* from */
+ found_pos = strstr(current_pos, delimiter);
+ if (NULL == found_pos) {
+ error_code = EMF_ERROR_INVALID_DATA;
+ goto FINISH_OFF;
+ }
+ *found_pos = NULL_CHAR;
+ strncpy(item->from, current_pos, STRING_LENGTH_FOR_DISPLAY-1);
+ EM_DEBUG_LOG("from[%s]", item->from);
+ current_pos = found_pos + 1;
+
+ /* from_email_address */
+ found_pos = strstr(current_pos, delimiter);
+ if (NULL == found_pos) {
+ error_code = EMF_ERROR_INVALID_DATA;
+ goto FINISH_OFF;
+ }
+ *found_pos = NULL_CHAR;
+ strncpy(item->from_email_address, current_pos, STRING_LENGTH_FOR_DISPLAY-1);
+ EM_DEBUG_LOG("from_email_address[%s]", item->from_email_address);
+ current_pos = found_pos + 1;
+
+ /* recipients */
+ found_pos = strstr(current_pos, delimiter);
+ if (NULL == found_pos) {
+ error_code = EMF_ERROR_INVALID_DATA;
+ goto FINISH_OFF;
+ }
+ *found_pos = NULL_CHAR;
+ strncpy(item->recipients, current_pos, STRING_LENGTH_FOR_DISPLAY-1);
+ EM_DEBUG_LOG("recipients[%s]", item->recipients);
+ current_pos = found_pos + 1;
+
+ /* subject */
+ found_pos = strstr(current_pos, delimiter);
+ if (NULL == found_pos) {
+ error_code = EMF_ERROR_INVALID_DATA;
+ goto FINISH_OFF;
+ }
+ *found_pos = NULL_CHAR;
+ strncpy(item->subject, current_pos, STRING_LENGTH_FOR_DISPLAY-1);
+ EM_DEBUG_LOG("subject[%s]", item->subject);
+ current_pos = found_pos + 1;
+
+ /* is_text_downloaded */
+ found_pos = strstr(current_pos, delimiter);
+ if (NULL == found_pos) {
+ error_code = EMF_ERROR_INVALID_DATA;
+ goto FINISH_OFF;
+ }
+ *found_pos = NULL_CHAR;
+ item->is_text_downloaded = atoi(current_pos);
+ EM_DEBUG_LOG("is_text_downloaded[%d]", item->is_text_downloaded);
+ current_pos = found_pos + 1;
+
+ /* datatime */
+ found_pos = strstr(current_pos, delimiter);
+ if (NULL == found_pos) {
+ error_code = EMF_ERROR_INVALID_DATA;
+ goto FINISH_OFF;
+ }
+ *found_pos = NULL_CHAR;
+ strncpy(item->datetime, current_pos, MAX_DATETIME_STRING_LENGTH-1);
+ EM_DEBUG_LOG("datetime[%s]", item->datetime);
+ current_pos = found_pos + 1;
+
+ /* flags_seen_field */
+ found_pos = strstr(current_pos, delimiter);
+ if (NULL == found_pos) {
+ error_code = EMF_ERROR_INVALID_DATA;
+ goto FINISH_OFF;
+ }
+ *found_pos = NULL_CHAR;
+ item->flags_seen_field = atoi(current_pos);
+ EM_DEBUG_LOG("flags_seen_field[%d]", item->flags_seen_field);
+ current_pos = found_pos + 1;
+
+ /* priority */
+ found_pos = strstr(current_pos, delimiter);
+ if (NULL == found_pos) {
+ error_code = EMF_ERROR_INVALID_DATA;
+ goto FINISH_OFF;
+ }
+ *found_pos = NULL_CHAR;
+ item->priority = atoi(current_pos);
+ EM_DEBUG_LOG("priority[%d]", item->priority);
+ current_pos = found_pos + 1;
+
+ /* save_status */
+ found_pos = strstr(current_pos, delimiter);
+ if (NULL == found_pos) {
+ error_code = EMF_ERROR_INVALID_DATA;
+ goto FINISH_OFF;
+ }
+ *found_pos = NULL_CHAR;
+ item->save_status = atoi(current_pos);
+ EM_DEBUG_LOG("save_status[%d]", item->save_status);
+ current_pos = found_pos + 1;
+
+ /* is_locked */
+ found_pos = strstr(current_pos, delimiter);
+ if (NULL == found_pos) {
+ error_code = EMF_ERROR_INVALID_DATA;
+ goto FINISH_OFF;
+ }
+ *found_pos = NULL_CHAR;
+ item->is_locked = atoi(current_pos);
+ EM_DEBUG_LOG("is_locked[%d]", item->is_locked);
+ current_pos = found_pos + 1;
+
+ /* is_report_mail */
+ found_pos = strstr(current_pos, delimiter);
+ if (NULL == found_pos) {
+ error_code = EMF_ERROR_INVALID_DATA;
+ goto FINISH_OFF;
+ }
+ *found_pos = NULL_CHAR;
+ item->is_report_mail = atoi(current_pos);
+ EM_DEBUG_LOG("is_report_mail[%d]", item->is_report_mail);
+ current_pos = found_pos + 1;
+
+ /* recipients_count */
+ found_pos = strstr(current_pos, delimiter);
+ if (NULL == found_pos) {
+ error_code = EMF_ERROR_INVALID_DATA;
+ goto FINISH_OFF;
+ }
+ *found_pos = NULL_CHAR;
+ item->recipients_count = atoi(current_pos);
+ EM_DEBUG_LOG("is_report_mail[%d]", item->recipients_count);
+ current_pos = found_pos + 1;
+
+ /* has_attachment */
+ found_pos = strstr(current_pos, delimiter);
+ if (NULL == found_pos) {
+ error_code = EMF_ERROR_INVALID_DATA;
+ goto FINISH_OFF;
+ }
+ *found_pos = NULL_CHAR;
+ item->has_attachment = atoi(current_pos);
+ EM_DEBUG_LOG("has_attachment[%d]", item->has_attachment);
+ current_pos = found_pos + 1;
+
+ /* has_drm_attachment */
+ found_pos = strstr(current_pos, delimiter);
+ if (NULL == found_pos) {
+ error_code = EMF_ERROR_INVALID_DATA;
+ goto FINISH_OFF;
+ }
+ *found_pos = NULL_CHAR;
+ item->has_drm_attachment = atoi(current_pos);
+ EM_DEBUG_LOG("has_drm_attachment[%d]", item->has_drm_attachment);
+ current_pos = found_pos + 1;
+
+ /* previewBodyText */
+ found_pos = strstr(current_pos, delimiter);
+ if (NULL == found_pos) {
+ error_code = EMF_ERROR_INVALID_DATA;
+ goto FINISH_OFF;
+ }
+ *found_pos = NULL_CHAR;
+ strncpy(item->previewBodyText, current_pos, MAX_PREVIEW_TEXT_LENGTH-1);
+ EM_DEBUG_LOG("previewBodyText[%s]", item->previewBodyText);
+ current_pos = found_pos + 1;
+
+ /* thread_id */
+ found_pos = strstr(current_pos, delimiter);
+ if (NULL == found_pos) {
+ error_code = EMF_ERROR_INVALID_DATA;
+ goto FINISH_OFF;
+ }
+ *found_pos = NULL_CHAR;
+ item->thread_id = atoi(current_pos);
+ EM_DEBUG_LOG("thread_id[%d]", item->thread_id);
+ current_pos = found_pos + 1;
+
+ /* thread_item_count - the last item */
+ item->thread_item_count = atoi(current_pos);
+ EM_DEBUG_LOG("thread_item_count[%d]", item->thread_item_count);
+
+ }
+ break;
+
+ default:
+ EM_DEBUG_EXCEPTION("Unknown structure type");
+ break;
+ }
+
+ ret = true;
+
+FINISH_OFF:
+ EM_SAFE_FREE(buff);
+ if (ret == true) {
+ if (struct_var)
+ *struct_var = temp_struct;
+ }
+ else {
+ switch (type) {
+ case EMF_CONVERT_STRUCT_TYPE_MAIL_LIST_ITEM:
+ EM_SAFE_FREE(temp_struct);
+ break;
+ default:
+ break;
+ }
+ }
+ EM_DEBUG_FUNC_END();
+ return error_code;
+}
+
+
+/* em_core_send_noti_for_new_mail is not used currently because DBUS could not send very long message.*/
+/* But I think it can be used to notify incomming new mail for replacing NOTI_MAIL_ADD with some modification(uid should be replaced with mail_id). */
+/* This notification is including addtional information comparing NOTI_MAIL_ADD. */
+/* By this change, email application will be able to add email item without additional DB query. */
+/* It might improve performance of sync email. */
+/* kyuho.jo 2010-09-07 */
+
+EXPORT_API int em_core_send_noti_for_new_mail(int account_id, char *mailbox_name, char *subject, char *from, char *uid, char *datetime)
+{
+ EM_DEBUG_FUNC_BEGIN("mailbox_name(%s) subject(%s), from(%s), uid(%s), datetime(%s)", mailbox_name, subject, from, uid, datetime);
+ int error_code = EMF_ERROR_NONE;
+ char *param_string = NULL;
+
+ if (mailbox_name == NULL || subject == NULL || from == NULL || uid == NULL || datetime == NULL) {
+ error_code = EMF_ERROR_INVALID_PARAM;
+ EM_DEBUG_EXCEPTION("Invalid parameter, mailbox_name(%p), subject(%p), from(%p), uid(%p), datetime(%p)", mailbox_name, subject, from, uid, datetime);
+ goto FINISH_OFF;
+ }
+
+ param_string = malloc(strlen(mailbox_name) + strlen(subject) + strlen(from) + strlen(uid) + strlen(datetime) + 5);
+
+ if (param_string == NULL) {
+ error_code = EMF_ERROR_OUT_OF_MEMORY;
+ EM_DEBUG_EXCEPTION("Memory allocation for 'param_string' is failed");
+ goto FINISH_OFF;
+ }
+
+ memset(param_string, 0x00, sizeof(param_string));
+ /* TODO: account_name, thread_id */
+ /* uid -> mail_id */
+ SNPRINTF(param_string, sizeof(param_string), "%s%c%s%c%s%c%s%c%s", mailbox_name, 0x01, subject, 0x01, from, 0x01, uid, 0x01, datetime);
+
+ if (em_storage_notify_network_event(NOTI_DOWNLOAD_NEW_MAIL, account_id, param_string, 0, 0) == 0) { /* failed */
+ error_code = EMF_ERROR_UNKNOWN;
+ EM_DEBUG_EXCEPTION("em_storage_notify_network_event is failed");
+ goto FINISH_OFF;
+ }
+
+FINISH_OFF:
+ if (param_string)
+ free(param_string);
+ EM_DEBUG_FUNC_END();
+ return error_code;
+}
+
+
+EXPORT_API
+int em_core_find_tag_for_thread_view(char *subject, int *result)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int error_code = EMF_ERROR_NONE;
+ char *copy_of_subject = NULL;
+
+ EM_IF_NULL_RETURN_VALUE(subject, EMF_ERROR_INVALID_PARAM);
+ EM_IF_NULL_RETURN_VALUE(result, EMF_ERROR_INVALID_PARAM);
+
+ *result = FALSE;
+
+ copy_of_subject = EM_SAFE_STRDUP(subject);
+
+ if (copy_of_subject == NULL) {
+ EM_DEBUG_EXCEPTION("strdup is failed \n");
+ goto FINISH_OFF;
+ }
+
+ em_core_upper_string(copy_of_subject);
+ EM_DEBUG_LOG("em_core_upper_string result : %s\n", copy_of_subject);
+
+ if (strstr(copy_of_subject, "RE:") == NULL) {
+ if (strstr(copy_of_subject, "FWD:") == NULL) {
+ if (strstr(copy_of_subject, "FW:") != NULL)
+ *result = TRUE;
+ }
+ else
+ *result = TRUE;
+ }
+ else
+ *result = TRUE;
+
+FINISH_OFF:
+ EM_SAFE_FREE(copy_of_subject);
+
+ EM_DEBUG_FUNC_END("result : %d", *result);
+
+ return error_code;
+}
+
+
+EXPORT_API
+int em_core_find_pos_stripped_subject_for_thread_view(char *subject, char *stripped_subject)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int error_code = EMF_ERROR_NONE;
+ int gap;
+ char *copy_of_subject = NULL, *curpos = NULL, *result;
+
+ EM_IF_NULL_RETURN_VALUE(subject, EMF_ERROR_INVALID_PARAM);
+ EM_IF_NULL_RETURN_VALUE(stripped_subject, EMF_ERROR_INVALID_PARAM);
+
+ copy_of_subject = EM_SAFE_STRDUP(subject);
+
+ if (copy_of_subject == NULL) {
+ EM_DEBUG_EXCEPTION("strdup is failed");
+ goto FINISH_OFF;
+ }
+
+ em_core_upper_string(copy_of_subject);
+ curpos = copy_of_subject;
+
+ EM_DEBUG_LOG("em_core_upper_string result : %s", copy_of_subject);
+
+ while ((result = strstr(curpos, "RE:")) != NULL) {
+ curpos = result + 3;
+ EM_DEBUG_LOG("RE result : %s", curpos);
+ }
+
+ while ((result = strstr(curpos, "FWD:")) != NULL) {
+ curpos = result + 4;
+ EM_DEBUG_LOG("FWD result : %s", curpos);
+ }
+
+ while ((result = strstr(curpos, "FW:")) != NULL) {
+ curpos = result + 3;
+ EM_DEBUG_LOG("FW result : %s", curpos);
+ }
+
+ while (curpos != NULL && *curpos == ' ') {
+ curpos++;
+ }
+
+ gap = curpos - copy_of_subject;
+
+ strcpy(stripped_subject, subject + gap);
+
+FINISH_OFF:
+ EM_SAFE_FREE(copy_of_subject);
+
+ if (error_code == EMF_ERROR_NONE && stripped_subject)
+ EM_DEBUG_LOG("result[%s]", stripped_subject);
+
+ EM_DEBUG_FUNC_END("error_code[%d]", error_code);
+ return error_code;
+}
+
+#define MAX_TITLE_LENGTH 1024
+EXPORT_API int em_core_update_notification_for_unread_mail(int account_id)
+{
+ EM_DEBUG_FUNC_BEGIN("account_id[%d]", account_id);
+ int error_code = EMF_ERROR_NONE;
+ notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
+
+ if((noti_err = notification_update(NULL)) != NOTIFICATION_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("notification_update failed");
+ goto FINISH_OFF;
+ }
+
+FINISH_OFF:
+
+ EM_DEBUG_FUNC_END("return [%d]", error_code);
+ return error_code;
+}
+
+EXPORT_API int em_core_finalize_sync(int account_id, int *error)
+{
+ EM_DEBUG_FUNC_BEGIN("account_id [%d], error [%p]", account_id, error);
+ int err = EMF_ERROR_NONE, ret = true, result_sync_status = SYNC_STATUS_FINISHED;
+ emf_mail_account_tbl_t *account_tbl = NULL;
+
+ if (!em_storage_update_sync_status_of_account(account_id, SET_TYPE_MINUS, SYNC_STATUS_SYNCING, true, &err))
+ EM_DEBUG_EXCEPTION("em_storage_update_sync_status_of_account failed [%d]", err);
+
+ if (!em_storage_get_sync_status_of_account(ALL_ACCOUNT, &result_sync_status, &err))
+ EM_DEBUG_EXCEPTION("em_storage_get_sync_status_of_account failed [%d]", err);
+
+ if ( result_sync_status == SYNC_STATUS_HAVE_NEW_MAILS) {
+ if (!em_core_update_notification_for_unread_mail(ALL_ACCOUNT))
+ EM_DEBUG_EXCEPTION("em_core_update_notification_for_unread_mail failed");
+ em_core_check_unread_mail();
+ /* Temp.. exception for EAS */
+ if(account_id >= FIRST_ACCOUNT_ID)
+ em_storage_get_account_by_id(account_id, EMF_ACC_GET_OPT_DEFAULT, &account_tbl, true, &err);
+ if(account_tbl && account_tbl->receiving_server_type != EMF_SERVER_TYPE_ACTIVE_SYNC)
+ start_alert();
+ }
+
+ EM_DEBUG_FUNC_END();
+ return ret;
+}
+
+EXPORT_API int em_core_clear_all_notifications()
+{
+ int account_count = 0, i;
+ emf_mail_account_tbl_t *account_list;
+ int error_code = EMF_ERROR_NONE;
+
+ if(!em_storage_get_account_list(&account_count, &account_list, true, false, &error_code)) {
+ EM_DEBUG_EXCEPTION("em_storage_get_account_list failed");
+ goto FINISH_OFF;
+ }
+
+ for(i = 0; i < account_count; i++) {
+ em_core_delete_notification_by_account(account_list[i].account_id);
+ }
+
+FINISH_OFF:
+ if(account_count) {
+ em_storage_free_account(&account_list, account_count, NULL);
+ }
+
+ EM_DEBUG_FUNC_END("return[%d]", error_code);
+ return error_code;
+}
+
+EXPORT_API int em_core_add_notification_for_unread_mail_by_mail_header(int account_id, int mail_id, emf_mail_head_t *mail_header)
+{
+ EM_DEBUG_FUNC_BEGIN("mail_id[%d], mail_header[%p]", mail_id, mail_header);
+ EM_PROFILE_BEGIN(profile_em_core_add_notification_for_unread_mail);
+
+ int error_code = EMF_ERROR_NONE;
+ struct tm log_time_tm;
+ time_t log_time = 0;
+
+ if (mail_header == NULL) {
+ EM_DEBUG_EXCEPTION("mail_header is NULL");
+ error_code = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ memset(&log_time_tm, 0, sizeof(struct tm));
+
+ log_time_tm.tm_sec = mail_header->datetime.second;
+ log_time_tm.tm_min = mail_header->datetime.minute;
+ log_time_tm.tm_hour = mail_header->datetime.hour;
+ log_time_tm.tm_mday = mail_header->datetime.day;
+ log_time_tm.tm_mon = mail_header->datetime.month;
+ log_time_tm.tm_year = mail_header->datetime.year + 70;
+
+ EM_DEBUG_LOG("sec[%d], min[%d], hour[%d], day[%d], month[%d], year[%d]"
+ , log_time_tm.tm_sec, log_time_tm.tm_min, log_time_tm.tm_hour, log_time_tm.tm_mday, log_time_tm.tm_mon, log_time_tm.tm_year);
+
+ log_time = mktime(&log_time_tm);
+
+ EM_DEBUG_LOG("log_time[%d]", log_time);
+
+ if (!em_core_add_notification(account_id, mail_id, mail_header->from, mail_header->subject, log_time)) {
+ EM_DEBUG_EXCEPTION("Failed the em_core_fill_notification_set");
+ goto FINISH_OFF;
+ }
+FINISH_OFF:
+
+ EM_PROFILE_END(profile_em_core_add_notification_for_unread_mail);
+ EM_DEBUG_FUNC_END("return[%d]", error_code);
+ return error_code;
+}
+
+EXPORT_API int em_core_add_notification_for_unread_mail(emf_mail_data_t *input_mail_data)
+{
+ EM_DEBUG_FUNC_BEGIN("input_mail_data[%p]", input_mail_data);
+
+ int error_code = EMF_ERROR_NONE;
+ struct tm log_time_tm = { 0 };
+ time_t log_time = 0;
+ emf_datetime_t datetime_data = { 0 };
+
+ if (input_mail_data == NULL) {
+ EM_DEBUG_EXCEPTION("input_mail_data is NULL");
+ error_code = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ if(!em_convert_string_to_datetime(input_mail_data->datetime, &datetime_data, &error_code)) {
+ EM_DEBUG_EXCEPTION("em_convert_string_to_datetime failed");
+ goto FINISH_OFF;
+ }
+
+ log_time_tm.tm_sec = datetime_data.second;
+ log_time_tm.tm_min = datetime_data.minute;
+ log_time_tm.tm_hour = datetime_data.hour;
+ log_time_tm.tm_mday = datetime_data.day;
+ log_time_tm.tm_mon = datetime_data.month;
+ log_time_tm.tm_year = datetime_data.year + 70;
+
+ EM_DEBUG_LOG("sec[%d], min[%d], hour[%d], day[%d], month[%d], year[%d]"
+ , log_time_tm.tm_sec, log_time_tm.tm_min, log_time_tm.tm_hour, log_time_tm.tm_mday, log_time_tm.tm_mon, log_time_tm.tm_year);
+
+ log_time = mktime(&log_time_tm);
+
+ EM_DEBUG_LOG("log_time[%d]", log_time);
+
+ if (!em_core_add_notification(input_mail_data->account_id, input_mail_data->mail_id, input_mail_data->full_address_from, input_mail_data->subject, log_time)) {
+ EM_DEBUG_EXCEPTION("em_core_add_notification failed");
+ goto FINISH_OFF;
+ }
+FINISH_OFF:
+
+ EM_DEBUG_FUNC_END("return[%d]", error_code);
+ return error_code;
+}
+
+
+EXPORT_API int em_core_delete_notification_for_read_mail(int mail_id)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int error_code = EMF_ERROR_NONE;
+ EM_DEBUG_FUNC_END();
+ return error_code;
+}
+
+#define EAS_EXECUTABLE_PATH "/usr/bin/eas-engine"
+
+EXPORT_API int em_core_delete_notification_by_account(int account_id)
+{
+ EM_DEBUG_FUNC_BEGIN("account_id [%d]", account_id);
+ int error_code = EMF_ERROR_NONE;
+ EM_DEBUG_FUNC_END();
+ return error_code;
+}
+
+#ifdef __FEATURE_BULK_DELETE_MOVE_UPDATE_REQUEST_OPTI__
+
+/**
+ * @fn em_core_convert_to_uid_range_set(emf_id_set_t* id_set, int id_set_count, emf_uid_range_set **uid_range_set, int range_len, int *err_code)
+ * Prepare a linked list of uid ranges with each node having a uid_range and lowest and highest uid in it.
+ *
+ *@author h.gahlaut@samsung.com
+ * @param[in] id_set Specifies the array of mail_id and corresponding server_mail_id sorted by server_mail_ids in ascending order
+ * @param[in] id_set_count Specifies the no. of cells in id_set array i.e. no. of sets of mail_ids and server_mail_ids
+ * @param[in] range_len Specifies the maximum length of string of range allowed.
+ * @param[out] uid_range_set Returns the uid_ranges formed in the form of a linked list with head stored in uid_range_set pointer
+ * @param[out] err_code Returns the error code.
+ * @remarks An example of a uid_range formed is 2:6,8,10,14:15,89,
+ * While using it the caller should remove the ending, (comma)
+ * @return This function returns true on success or false on failure.
+ */
+
+EXPORT_API int em_core_convert_to_uid_range_set(emf_id_set_t *id_set, int id_set_count, emf_uid_range_set **uid_range_set, int range_len, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ int ret = false;
+ int error = EM_STORAGE_ERROR_NONE;
+
+ if (NULL == id_set || id_set_count <= 0 || NULL == uid_range_set) {
+ EM_DEBUG_EXCEPTION(" Invalid Parameter id_set[%p] id_set_count[%d] uid_range_set[%p]", id_set, id_set_count, uid_range_set);
+ error = EM_STORAGE_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ int i = 0;
+ unsigned long current_uid = 0;
+ unsigned long first_uid = 0;
+ unsigned long last_uid = 0;
+ const int max_subset_string_size = MAX_SUBSET_STRING_SIZE;
+ char subset_string[MAX_SUBSET_STRING_SIZE] = {0,};
+ emf_uid_range_set *current_node = NULL; /* current_node denotes the current node under processing in the linked list of uid_range_set that is to be formed*/
+
+ if (range_len < (max_subset_string_size + 1)) /* 1 for ending NULL character */ {
+ EM_DEBUG_EXCEPTION(" Invalid Parameter range_len[%d]", range_len);
+ error = EM_STORAGE_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ EM_DEBUG_LOG("id set count[%d] range_len[%d]", id_set_count, range_len);
+
+ do {
+ first_uid = last_uid = current_uid = id_set[i].server_mail_id;
+ /* Start subset string by putting first server mail id in it from id_set*/
+ memset(subset_string, 0x00, max_subset_string_size);
+ SNPRINTF(subset_string, max_subset_string_size, "%lu", first_uid);
+ ++i;
+
+ /* Check if only one server mail id was left in id_set */
+ if (i >= id_set_count) {
+ /* No more server mail id left in id_set */
+ if (false == em_core_append_subset_string_to_uid_range(subset_string, &current_node, uid_range_set, range_len, first_uid, last_uid)) {
+ EM_DEBUG_EXCEPTION("em_core_append_subset_string_to_uid_range failed");
+ goto FINISH_OFF;
+ }
+ break;
+ }
+ else {
+ /* More server mail id are present in id_set. Find out if first:last_uid is to be formed or only first_uid will be subset string */
+ do {
+ current_uid = id_set[i].server_mail_id;
+ if (current_uid == (last_uid + 1)) {
+ last_uid = current_uid;
+ ++i;
+ }
+ else {
+ memset(subset_string, 0x00, max_subset_string_size);
+ if (first_uid != last_uid) /* Form subset string by first_uid:last_uid */
+ SNPRINTF(subset_string, max_subset_string_size, "%lu:%lu", first_uid, last_uid);
+ else /* Form subset string by first_uid */
+ SNPRINTF(subset_string, max_subset_string_size, "%lu", first_uid);
+
+ if (false == em_core_append_subset_string_to_uid_range(subset_string, &current_node, uid_range_set, range_len, first_uid, last_uid)) {
+ EM_DEBUG_EXCEPTION("em_core_append_subset_string_to_uid_range failed");
+ goto FINISH_OFF;
+ }
+ /* To Start formation of new subset string break out of inner loop */
+ break;
+ }
+
+ } while (i < id_set_count);
+
+ /* Flow comes here in two cases :
+ 1. id_set ended and has continuous numbers at end of id_set so form subset string by first_uid:last_uid . in this case last_uid == current_uid
+ 2. due to break statement */
+
+ if (last_uid == current_uid) {
+ /* Case 1 */
+
+ memset(subset_string, 0x00, max_subset_string_size);
+ SNPRINTF(subset_string, max_subset_string_size, "%lu:%lu", first_uid, last_uid);
+
+ if (false == em_core_append_subset_string_to_uid_range(subset_string, &current_node, uid_range_set, range_len, first_uid, last_uid)) {
+ EM_DEBUG_EXCEPTION("em_core_append_subset_string_to_uid_range failed");
+ goto FINISH_OFF;
+ }
+ }
+ else {
+ /* Case 2: Do Nothing */
+ }
+
+ }
+ } while (i < id_set_count);
+
+ ret = true;
+
+FINISH_OFF:
+ if (NULL != err_code)
+ *err_code = error;
+ EM_DEBUG_FUNC_END();
+ return ret;
+
+}
+
+/**
+ * @fn em_core_append_subset_string_to_uid_range(char *subset_string, emf_uid_range_set **uid_range_set, int range_len, unsigned long luid, unsigned long huid)
+ * Appends the subset_string to uid range if the uid range has not exceeded maximum length(range_len), otherwise creates a new node in linked list of uid range set
+ * and stores the subset_string in its uid_range. Also sets the lowest and highest uids for the corresponsing uid_range
+ *
+ * @author h.gahlaut@samsung.com
+ * @param[in] subset_string Specifies the subset string to be appended. A subset string can be like X:Y or X where X and Y are uids.
+ * @param[in] range_len Specifies the maximum length of range string allowed.
+ * @param[in] luid Specifies the lowest uid in subset string
+ * @param[in] huid Specifies the highest uid in subset string
+ * @param[out] uid_range_set Returns the uid_ranges formed in the form of a linked list with head stored in uid_range_set pointer
+ * @param[out] err_code Returns the error code.
+ * @remarks
+ * @return This function returns true on success or false on failure.
+ */
+
+int em_core_append_subset_string_to_uid_range(char *subset_string, emf_uid_range_set **current_node_adr, emf_uid_range_set **uid_range_set, int range_len, unsigned long luid, unsigned long huid)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ emf_uid_range_set *current_node = NULL;
+
+ if (NULL == (*uid_range_set)) {
+ /*This happens only once when list creation starts. Head Node is allocated */
+ current_node = (emf_uid_range_set *)em_core_malloc(sizeof(emf_uid_range_set));
+ if (NULL == current_node) {
+ EM_DEBUG_EXCEPTION("em_core_malloc failed");
+ return false;
+ }
+
+ current_node->uid_range = (char *)em_core_malloc(range_len);
+
+ if (NULL == current_node->uid_range) {
+ EM_DEBUG_EXCEPTION("em_core_malloc failed");
+ EM_SAFE_FREE(current_node);
+ return false;
+ }
+
+ SNPRINTF(current_node->uid_range, range_len, "%s,", subset_string);
+
+ current_node->lowest_uid = luid;
+ current_node->highest_uid = huid;
+ (*uid_range_set) = current_node;
+
+ (*current_node_adr) = current_node;
+
+ }
+ else {
+ /* Apart from first call to this function flow will always come here */
+ current_node = (*current_node_adr);
+ int len_sub_string = strlen(subset_string);
+ int space_left_in_buffer = range_len - strlen(current_node->uid_range);
+
+ if ((len_sub_string + 1 + 1) <= space_left_in_buffer) /* 1 for comma + 1 for ending null character */ {
+ SNPRINTF(current_node->uid_range + strlen(current_node->uid_range), space_left_in_buffer, "%s,", subset_string);
+ current_node->highest_uid = huid;
+ }
+ else {
+ /* No more space left in uid_range string.If continued on it, it will exceeded max size of range_len */
+ /* Allocate new node in Uid Range set */
+ emf_uid_range_set *new_node = NULL;
+
+ new_node = (emf_uid_range_set *)em_core_malloc(sizeof(emf_uid_range_set));
+
+ if (NULL == new_node) {
+ EM_DEBUG_EXCEPTION("em_core_malloc failed");
+ return false;
+ }
+
+ /* Allocate uid_range of new node */
+
+ new_node->uid_range = (char *)em_core_malloc(range_len);
+
+ if (NULL == new_node->uid_range) {
+ EM_DEBUG_EXCEPTION("em_core_malloc failed");
+ EM_SAFE_FREE(new_node);
+ return false;
+ }
+
+ SNPRINTF(new_node->uid_range, range_len, "%s, ", subset_string);
+
+ new_node->lowest_uid = luid;
+ new_node->highest_uid = huid;
+
+ current_node->next = new_node;
+
+ (*current_node_adr) = new_node;
+ }
+ }
+ EM_DEBUG_FUNC_END();
+ return true;
+}
+
+/**
+ * void em_core_free_uid_range_set(emf_uid_range_set **uid_range_head)
+ * Frees the linked list of uid ranges
+ *
+ * @author h.gahlaut@samsung.com
+ * @param[in] uid_range_head Head pointer of linked list of uid ranges
+ * @remarks
+ * @return This function does not return anything.
+ */
+
+EXPORT_API
+void em_core_free_uid_range_set(emf_uid_range_set **uid_range_set)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ emf_uid_range_set *current_node = NULL;
+ emf_uid_range_set *uid_range_head = NULL;
+
+ current_node = uid_range_head = (*uid_range_set); /* Make the current node and head ptr point to starting of uid_range_set */
+
+ while (current_node) {
+ uid_range_head = current_node->next; /* Move the head ptr to next node*/
+
+ EM_SAFE_FREE(current_node->uid_range);
+ EM_SAFE_FREE(current_node); /* Free the current node */
+
+ current_node = uid_range_head; /* Make the current node point to head ptr */
+ }
+
+ (*uid_range_set) = NULL;
+ EM_DEBUG_FUNC_END();
+}
+
+
+/**
+ * @fn em_core_form_comma_separated_strings(int numbers[], int num_count, int max_string_len, char *** strings, int *string_count, int *err_code)
+ * Forms comma separated strings of a give max_string_len from an array of numbers
+ *
+ * @author h.gahlaut@samsung.com
+ * @param[in] numbers Specifies the array of numbers to be converted into comma separated strings.
+ * @param[in] num_count Specifies the count of numbers in numbers array.
+ * @param[in] max_string_len Specifies the maximum length of comma separated strings that are to be formed.
+ * @param[out] strings Returns the base address of a double dimension array which stores the strings.
+ * @param[out] string_count Returns the number of strings formed.
+ * @param[out] err_code Returns the error code.
+ * @remarks If Input to the function is five numbers like 2755 2754 2748 2749 2750 and a given max_string_len is 20.
+ * Then this function will form two comma separated strings as follows -
+ * "2755, 2754, 2748"
+ * "2749, 2750"
+ * @return This function returns true on success or false on failure.
+ */
+
+EXPORT_API int em_core_form_comma_separated_strings(int numbers[], int num_count, int max_string_len, char *** strings, int *string_count, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ int error = EM_STORAGE_ERROR_NONE;
+ int ret = false;
+
+ char **string_list = NULL;
+ int num_of_strings = 0;
+ int i = 0;
+ int j =0;
+ char num[MAX_INTEGER_LENGTH + 1] = {0, };
+ int num_len = 0;
+ int space_in_buffer = 0;
+ int len_of_string_formed = 0;
+
+ if (NULL == numbers || num_count <= 0 || \
+ max_string_len < (MAX_INTEGER_LENGTH + 2)|| NULL == strings || NULL == string_count) /* 32767, is the highest integer possible in string.This requires 7 bytes of storage in character type array (1 byte for ending NULL and 1 byte for ending comma) so max_string_len should not be less than worst case possible. */ {
+ EM_DEBUG_EXCEPTION("Invalid Parameter numbers[%p] num_count [%d] max_string_len [%d] strings [%p] string_count[%p]", \
+ numbers, num_count, max_string_len, strings, string_count);
+ error = EM_STORAGE_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ EM_DEBUG_LOG("num_count [%d] max_string_len [%d]", num_count, max_string_len);
+
+ string_list = em_core_malloc(sizeof(char *));
+
+ if (NULL == string_list) {
+ EM_DEBUG_EXCEPTION("em_core_malloc failed ");
+ goto FINISH_OFF;
+ }
+
+ string_list[num_of_strings] = em_core_malloc(max_string_len);
+
+ if (NULL == string_list[num_of_strings]) {
+ EM_DEBUG_EXCEPTION("em_core_malloc failed ");
+ goto FINISH_OFF;
+ }
+
+ ++num_of_strings;
+ space_in_buffer = max_string_len;
+
+ for (j = 0; j < num_count;++j) {
+ memset(num, 0x00, MAX_INTEGER_LENGTH + 1);
+ SNPRINTF(num, MAX_INTEGER_LENGTH + 1, "%d", numbers[j]);
+
+ num_len = strlen(num);
+
+ len_of_string_formed = strlen(string_list[num_of_strings - 1]);
+
+ space_in_buffer = max_string_len - len_of_string_formed ;
+
+ if (space_in_buffer >= (num_len+1+1)) /* 1 for comma and 1 for ending NULL */ {
+ SNPRINTF(string_list[num_of_strings - 1] + len_of_string_formed, max_string_len, "%d,", numbers[j]);
+ }
+ else { /* Removing comma at end of string */
+ string_list[num_of_strings - 1][len_of_string_formed-1] = '\0';
+ char **temp = NULL;
+ temp = (char **)realloc(string_list, sizeof(char *) * (num_of_strings + 1)); /* Allocate new buffer to store a pointer to a new string */
+
+ if (NULL == temp) {
+ EM_DEBUG_EXCEPTION("realloc failed");
+ goto FINISH_OFF;
+ }
+
+ memset(temp + num_of_strings, 0X00, sizeof(char *));
+
+ string_list = temp;
+ temp = NULL;
+ string_list[num_of_strings] = em_core_malloc(max_string_len);/* Allocate new buffer to store the string */
+
+ if (NULL == string_list[num_of_strings]) {
+ EM_DEBUG_EXCEPTION(" em_core_malloc failed ");
+ goto FINISH_OFF;
+ }
+ ++num_of_strings;
+ SNPRINTF(string_list[num_of_strings - 1] , max_string_len, "%d,", numbers[j]);/* Start making new string */
+ }
+ }
+
+ /* Removing comma at end of string */
+ len_of_string_formed = strlen(string_list[num_of_strings - 1]);
+ string_list[num_of_strings - 1][len_of_string_formed-1] = '\0';
+ ret = true;
+
+FINISH_OFF:
+
+ if (false == ret)
+ em_core_free_comma_separated_strings(&string_list, &num_of_strings);
+
+ if (true == ret) {
+ for (i = 0; i < num_of_strings;++i)
+ EM_DEBUG_LOG("%s", string_list[i]);
+ *strings = string_list;
+ *string_count = num_of_strings;
+ }
+
+
+ if (NULL != err_code)
+ *err_code = error;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+/**
+ * @fn em_core_free_comma_separated_strings(char *** string_list, int *string_count)
+ * Frees the double dimensional array of strings.
+ *
+ * @author h.gahlaut@samsung.com
+ * @param[in] uid_range_head Address of base address of double dimensional array of strings.
+ * @param[in] string_count Address of variable holding the count of strings.
+ * @remarks
+ * @return This function does not return anything.
+ */
+EXPORT_API void em_core_free_comma_separated_strings(char *** string_list, int *string_count)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int i = 0;
+ char **str_list = NULL;
+ int count = 0;
+
+ if (NULL != string_list) {
+ str_list = *string_list;
+
+ if (0 != *string_count) {
+ count = *string_count;
+ for (i = 0; i < count; ++i)
+ EM_SAFE_FREE(str_list[i]);
+ }
+
+ EM_SAFE_FREE(str_list);
+ *string_list = NULL; /* This makes the pointer to be freed as NULL in calling function and saves it from being a dangling pointer for sometime in calling function */
+ *string_count = 0;
+ }
+ EM_DEBUG_FUNC_END();
+}
+
+
+#endif
+
+
+#include <sys/mman.h>
+
+/* #define GETSP() ({ unsigned int sp; asm volatile ("mov %0, sp " : "=r"(sp)); sp;}) */
+#define BUF_SIZE 256
+#define PAGE_SIZE (1 << 12)
+#define _ALIGN_UP(addr, size) (((addr)+((size)-1))&(~((size)-1)))
+#define _ALIGN_DOWN(addr, size) ((addr)&(~((size)-1)))
+#define PAGE_ALIGN(addr) _ALIGN_DOWN(addr, PAGE_SIZE)
+
+int stack_trim(void)
+{
+ /*
+ char buf[BUF_SIZE];
+ FILE *file;
+ unsigned int stacktop;
+ int found = 0;
+ unsigned int sp;
+
+ asm volatile ("mov %0, sp " : "=r"(sp));
+
+ sprintf(buf, "/proc/%d/maps", getpid());
+ file = fopen(buf, "r");
+ while (fgets(buf, BUF_SIZE, file) != NULL) {
+ if (strstr(buf, "[stack]")) {
+ found = 1;
+ break;
+ }
+ }
+
+ fclose(file);
+
+ if (found) {
+ sscanf(buf, "%x-", &stacktop);
+ if (madvise((void *)PAGE_ALIGN(stacktop), PAGE_ALIGN(sp)-stacktop, MADV_DONTNEED) < 0)
+ perror("stack madvise fail");
+ }
+ */
+ return 1;
+}
+
+
+EXPORT_API void em_core_flush_memory()
+{
+ EM_DEBUG_FUNC_BEGIN();
+ /* flush memory in heap */
+ malloc_trim(0);
+
+ /* flush memory in stack */
+ stack_trim();
+
+ /* flush memory for sqlite */
+ em_storage_flush_db_cache();
+ EM_DEBUG_FUNC_END();
+}
+
+EXPORT_API int em_core_make_attachment_file_name_with_extension(char *source_file_name, char *sub_type, char *result_file_name, int result_file_name_buffer_length, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("source_file_name[%s], sub_type[%s], result_file_name_buffer_length[%d] ", source_file_name, sub_type, result_file_name_buffer_length);
+ int ret = false, err = EMF_ERROR_NONE;
+ char *extcheck = NULL;
+ char attachment_file_name[MAX_PATH + 1] = { 0, };
+
+ if (!source_file_name || !result_file_name) {
+ EM_DEBUG_EXCEPTION("Invalid Parameter");
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ strncpy(attachment_file_name, source_file_name, MAX_PATH);
+ extcheck = strchr(attachment_file_name, '.');
+
+ if (extcheck)
+ EM_DEBUG_LOG("Extension Exist in the Attachment [%s] ", extcheck);
+ else { /* No extension attached, So add the Extension based on the subtype */
+ if (sub_type) {
+ strcat(attachment_file_name, ".");
+ strcat(attachment_file_name, sub_type);
+ EM_DEBUG_LOG("attachment_file_name with extension[%s] ", attachment_file_name);
+ }
+ else
+ EM_DEBUG_LOG("UnKnown Extesnsion");
+
+ }
+ memset(result_file_name, 0 , result_file_name_buffer_length);
+ EM_SAFE_STRNCPY(result_file_name, attachment_file_name, result_file_name_buffer_length - 1);
+ EM_DEBUG_LOG("*result_file_name[%s]", result_file_name);
+ ret = true;
+
+FINISH_OFF:
+ if (err_code)
+ *err_code = err;
+ EM_DEBUG_FUNC_END();
+ return ret;
+}
+
+EXPORT_API char *em_core_get_extension_from_file_path(char *source_file_path, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("source_file_path[%s]", source_file_path);
+ int err = EMF_ERROR_NONE, pos_on_string = 0;
+ char *extension = NULL;
+
+ if (!source_file_path) {
+ EM_DEBUG_EXCEPTION("Invalid Parameter");
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ pos_on_string = strlen(source_file_path) - 1;
+
+ while(pos_on_string > 0 && source_file_path[pos_on_string--] != '.') ;
+
+ if(pos_on_string > 0)
+ extension = source_file_path + pos_on_string + 2;
+
+ EM_DEBUG_LOG("*extension [%s] pos_on_string [%d]", extension, pos_on_string);
+
+FINISH_OFF:
+ if (err_code)
+ *err_code = err;
+ EM_DEBUG_FUNC_END();
+ return extension;
+}
+
+EXPORT_API int em_core_get_encoding_type_from_file_path(const char *input_file_path, char **output_encoding_type)
+{
+ EM_DEBUG_FUNC_BEGIN("input_file_path[%d], output_encoding_type[%p]", input_file_path, output_encoding_type);
+ int err = EMF_ERROR_NONE;
+ int pos_of_filename = 0;
+ int pos_of_dot = 0;
+ int enf_of_string = 0;
+ int result_string_length = 0;
+ char *filename = NULL;
+ char *result_encoding_type = NULL;
+
+ if (!input_file_path || !output_encoding_type) {
+ EM_DEBUG_EXCEPTION("Invalid Parameter");
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ enf_of_string = pos_of_filename = strlen(input_file_path) - 1;
+
+ while(pos_of_filename >= 0 && input_file_path[pos_of_filename--] != '/') {
+ if(input_file_path[pos_of_filename] == '.')
+ pos_of_dot = pos_of_filename;
+ }
+
+ if(pos_of_filename != 0)
+ pos_of_filename += 2;
+
+ filename = (char*)input_file_path + pos_of_filename;
+
+ if(pos_of_dot != 0 && pos_of_dot > pos_of_filename)
+ result_string_length = pos_of_dot - pos_of_filename;
+ else
+ result_string_length = enf_of_string - pos_of_filename;
+
+ EM_DEBUG_LOG("pos_of_dot [%d], pos_of_filename [%d], enf_of_string[%d],result_string_length [%d]", pos_of_dot, pos_of_filename, enf_of_string, result_string_length);
+
+ if( !(result_encoding_type = em_core_malloc(sizeof(char) * (result_string_length + 1))) ) {
+ EM_DEBUG_EXCEPTION("EMF_ERROR_OUT_OF_MEMORY");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ memcpy(result_encoding_type, input_file_path + pos_of_filename, result_string_length);
+
+ EM_DEBUG_LOG("*result_encoding_type [%s]", result_encoding_type);
+
+ *output_encoding_type = result_encoding_type;
+
+FINISH_OFF:
+ EM_DEBUG_FUNC_END("err [%d]", err);
+ return err;
+}
+
+
+EXPORT_API int em_core_get_content_type(const char *extension_string, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("extension_string[%s]", extension_string);
+ int i = 0, err = EMF_ERROR_NONE, result_content_type = TYPEAPPLICATION;
+ char *image_extension[] = { "jpeg", "jpg", "png", "gif", "bmp", "pic", "agif", "tif", "wbmp" , NULL};
+
+ if (!extension_string) {
+ EM_DEBUG_EXCEPTION("Invalid Parameter");
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ while(image_extension[i]) {
+ EM_DEBUG_LOG("image_extension[%d] [%s]", i, image_extension[i]);
+ if(strcasecmp(image_extension[i], extension_string) == 0) {
+ result_content_type = TYPEIMAGE;
+ break;
+ }
+ i++;
+ }
+
+FINISH_OFF:
+ if (err_code)
+ *err_code = err;
+ EM_DEBUG_FUNC_END();
+ return result_content_type;
+}
+
+#define DATE_TIME_STRING_LEGNTH 14
+
+EXPORT_API char* em_core_get_current_time_string(int *err)
+{
+ EM_DEBUG_FUNC_BEGIN("err [%p]", err);
+
+ int err_code = EMF_ERROR_NONE;
+ time_t t = time(NULL);
+ struct tm *p_tm = NULL;
+ char *result_date_time = NULL;
+
+ p_tm = gmtime(&t);
+
+ if (!p_tm) {
+ EM_DEBUG_EXCEPTION("localtime failed...");
+ err_code = EMF_ERROR_SYSTEM_FAILURE;
+ goto FINISH_OFF;
+ }
+
+ result_date_time = em_core_malloc(DATE_TIME_STRING_LEGNTH + 1);
+
+ SNPRINTF(result_date_time, DATE_TIME_STRING_LEGNTH + 1, "%04d%02d%02d%02d%02d%02d",
+ p_tm->tm_year + 1900, p_tm->tm_mon + 1, p_tm->tm_mday,
+ p_tm->tm_hour, p_tm->tm_min, p_tm->tm_sec);
+
+ EM_DEBUG_LOG("result_date_time [%s]", result_date_time);
+FINISH_OFF:
+
+ if(err)
+ *err = err_code;
+
+ EM_DEBUG_FUNC_END();
+ return result_date_time;
+}
+
+
+#ifdef __LOCAL_ACTIVITY__
+EXPORT_API int em_core_activity_add(emf_activity_tbl_t *new_activity, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ EM_DEBUG_LOG("\t new_activity[%p], err_code[%p]", new_activity, err_code);
+
+ /* default variable */
+ int ret = false;
+ int err = EMF_ERROR_NONE;
+
+ if (!new_activity) {
+ EM_DEBUG_LOG("\t new_activity[%p]\n", new_activity);
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+ if (!em_storage_add_activity(new_activity, false, &err)) {
+ EM_DEBUG_LOG("\t em_storage_add_activity falied - %d\n", err);
+
+ goto FINISH_OFF;
+ }
+ ret = true;
+
+FINISH_OFF:
+ if (err_code)
+ *err_code = err;
+
+ return ret;
+}
+
+EXPORT_API int em_core_activity_delete(emf_activity_tbl_t *activity, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ EM_DEBUG_LOG("\t new_activity[%p], err_code[%p]", activity, err_code);
+
+ /* default variable */
+ int ret = false;
+ int err = EMF_ERROR_NONE;
+ if (!activity) {
+ EM_DEBUG_LOG("\t new_activity[%p]\n", activity);
+
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+ if (!em_storage_delete_local_activity(activity, true, &err)) {
+ EM_DEBUG_LOG("\t em_storage_delete_local_activity falied - %d\n", err);
+
+ goto FINISH_OFF;
+ }
+ ret = true;
+
+FINISH_OFF:
+ if (err_code)
+ *err_code = err;
+
+ return ret;
+}
+
+EXPORT_API int em_core_get_next_activity_id(int *activity_id, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ int ret = false;
+ int err = EMF_ERROR_NONE;
+
+ if (NULL == activity_id)
+ {
+ EM_DEBUG_EXCEPTION("\t activity_id[%p]", activity_id);
+
+ err = EM_STORAGE_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ if (false == em_storage_get_next_activity_id(activity_id, &err)) {
+ EM_DEBUG_LOG("\t em_storage_get_next_activity_id failed - %d\n", err);
+ goto FINISH_OFF;
+ }
+
+ ret = true;
+
+ FINISH_OFF:
+ if (NULL != err_code) {
+ *err_code = err;
+ }
+
+ return ret;
+
+}
+
+#endif /* __LOCAL_ACTIVITY__ */
+
+
+
+/* EOF */
diff --git a/email-core/em-network/em-network.c b/email-core/em-network/em-network.c
new file mode 100755
index 0000000..f967064
--- /dev/null
+++ b/email-core/em-network/em-network.c
@@ -0,0 +1,487 @@
+/*
+* email-service
+*
+* Copyright (c) 2000 - 2011 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.
+*
+*/
+
+
+
+/******************************************************************************
+ * File: em-network.c
+ * Desc: Data network interface
+ *
+ * Auth:
+ *
+ * History:
+ * 2006.11.17 : created
+ *****************************************************************************/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/stat.h>
+#include <signal.h>
+#include <netdb.h>
+#include <string.h>
+#include <unistd.h>
+#include <errno.h>
+#include <em-storage.h>
+#include <vconf.h>
+#include "glib.h"
+
+#include "lnx_inc.h"
+#include "utf8aux.h"
+#include "c-client.h"
+#include "emflib.h"
+#include "emf-dbglog.h"
+#include "emf-types.h"
+#include "em-core-utils.h"
+#include "em-core-mailbox.h"
+
+#ifdef __FEATURE_PARTIAL_BODY_DOWNLOAD__
+#include "em-core-event.h"
+#endif
+
+/* em_core_get_network_status - Get the data network status from vconf */
+static int em_core_get_network_status(int *network_status)
+{
+ EM_DEBUG_FUNC_BEGIN("network_status [%p]", network_status);
+
+ int value = 0;
+
+ if(!network_status) {
+ EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
+ return EMF_ERROR_INVALID_PARAM;
+ }
+
+ if (vconf_get_int(VCONFKEY_NETWORK_STATUS, &value)) {
+ EM_DEBUG_EXCEPTION("Failed vconf_get_int [VCONFKEY_NETWORK_STATUS]");
+ return EMF_ERROR_SYSTEM_FAILURE;
+ }
+
+ *network_status = value;
+
+ EM_DEBUG_FUNC_END("network_status [%d]", value);
+ return EMF_ERROR_NONE;
+}
+
+/* Check code for SIM status */
+static int em_core_get_sim_status(int *sim_status)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int value;
+
+ if(!sim_status) {
+ EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
+ return EMF_ERROR_INVALID_PARAM;
+ }
+
+ if (vconf_get_int(VCONFKEY_TELEPHONY_SIM_SLOT, &value) != 0) {
+ EM_DEBUG_EXCEPTION("Failed vconf_get_int [VCONFKEY_TELEPHONY_SIM_SLOT]");
+ return EMF_ERROR_SYSTEM_FAILURE;
+ }
+
+ *sim_status = value;
+
+ EM_DEBUG_FUNC_END("status[%d]", value);
+ return EMF_ERROR_NONE;
+}
+
+static int em_core_get_wifi_status(int *wifi_status)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ int value;
+
+ if(!wifi_status) {
+ EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
+ return EMF_ERROR_INVALID_PARAM;
+ }
+
+ if (vconf_get_int(VCONFKEY_WIFI_STATE, &value) != 0) {
+ EM_DEBUG_EXCEPTION("vconf_get_int failed");
+ return EMF_ERROR_SYSTEM_FAILURE;
+ }
+
+ *wifi_status = value;
+
+ EM_DEBUG_FUNC_END("status[%d]", *wifi_status);
+ return EMF_ERROR_NONE;
+}
+
+
+EXPORT_API int em_core_check_network_status(int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int network_status = 0;
+ int sim_status = VCONFKEY_TELEPHONY_SIM_UNKNOWN;
+ int wifi_status = 0;
+ int err = EMF_ERROR_NONE;
+ int ret = false;
+
+ if ( (err = em_core_get_network_status(&network_status)) != EMF_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("em_core_get_network_status failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ if(network_status == 0) {
+ if ( (err = em_core_get_sim_status(&sim_status)) != EMF_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("em_core_get_sim_status failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ if (sim_status != VCONFKEY_TELEPHONY_SIM_INSERTED) {
+ EM_DEBUG_LOG("EMF_ERROR_NO_SIM_INSERTED");
+ if ( (err = em_core_get_wifi_status(&wifi_status)) != EMF_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("em_core_get_wifi_status failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ if (wifi_status == 0) {
+ EM_DEBUG_EXCEPTION("Furthermore, WIFI is off");
+ err = EMF_ERROR_NO_SIM_INSERTED;
+ goto FINISH_OFF;
+ }
+ }
+ EM_DEBUG_EXCEPTION("EMF_ERROR_NETWORK_NOT_AVAILABLE");
+ err = EMF_ERROR_NETWORK_NOT_AVAILABLE;
+ goto FINISH_OFF;
+ }
+
+ EM_DEBUG_LOG("Data Network Mode is ON");
+ ret = true;
+
+FINISH_OFF:
+
+ em_core_set_network_error(err);
+
+ if (err_code)
+ *err_code = err;
+
+ EM_DEBUG_FUNC_END();
+
+ return ret;
+}
+
+EXPORT_API long em_core_ssl_cert_query_cb(char *reason, char *host, char *cert)
+{
+ EM_DEBUG_FUNC_BEGIN("reason[%s], host[%s], cert[%s]", reason, host, cert);
+ int ret = 1;
+
+ /* FIXME : add user interface for Accept or Reject */
+ /* 1:Accept - ignore this certificate error */
+ /* 0:Reject - stop ssl connection */
+ ret = 1;
+
+ EM_DEBUG_FUNC_END("ret[%s]", ret ? "ignore error" : "stop connection");
+ return ret;
+}
+
+/* ------ socket read/write handle ---------------------------------------- */
+int _g_canceled = 0;
+/* TCPSTREAM = SENDSTREAM->netstream->stream; socket-id = TCPSTREAM->tcpsi, tcpso; */
+/* sockid_in = ((TCPSTREAM*)send_stream->netstream->stream)->tcpsi; */
+/* sockid_out = ((TCPSTREAM*)send_stream->netstream->stream)->tcpso; */
+
+EXPORT_API long tcp_getbuffer_lnx(TCPSTREAM *stream, unsigned long size, char *s)
+{
+ struct timeval tmout;
+ fd_set readfds;
+ int nleave, nread, sret, sockid, maxfd;
+ char *p = s;
+ int max_timeout = 0;
+ sockid = stream->tcpsi;
+ maxfd = sockid + 1;
+/* EM_DEBUG_LOG("start sockid %d", sockid); */
+ if (sockid < 0) return 0;
+
+ if (stream->ictr > 0) {
+ int copy_sz;
+ if (stream->ictr >= size) {
+ memcpy(p, stream->iptr, size);
+ copy_sz = size;
+ }
+ else {
+ memcpy(p, stream->iptr, stream->ictr);
+ copy_sz = stream->ictr;
+ }
+ p += copy_sz;
+ nleave = size - copy_sz;
+ stream->iptr += copy_sz;
+ stream->ictr -= copy_sz;
+
+ if (nleave <= 0) {
+ *p = '\0';
+ /* EM_DEBUG_LOG("end"); */
+ return 1;
+ }
+ }
+ else {
+ nleave = size;
+ }
+
+ while (nleave > 0) {
+#ifdef TEST_CANCEL_JOB
+ if (!em_core_check_thread_status()) {
+ EM_DEBUG_EXCEPTION("thread canceled");
+ tcp_abort(stream);
+ goto JOB_CANCEL;
+ }
+#endif
+ /* if (_g_canceled){ */
+ /* EM_DEBUG_LOG1("thread canceled\n"); */
+ /* tcp_abort(stream); */
+ /* return 0; */
+ /* } */
+
+ tmout.tv_usec = 0;
+ tmout.tv_sec = 1;
+ FD_ZERO(&readfds);
+ FD_SET(sockid, &readfds);
+
+ sret = select(maxfd, &readfds, NULL, NULL, &tmout);
+ if (sret < 0) {
+ EM_DEBUG_EXCEPTION("select error[%d]\n", errno);
+ tcp_abort(stream);
+ return 0;
+ }
+ else if (!sret) {
+ if (max_timeout >= 5) {
+ EM_DEBUG_EXCEPTION("max select timeout %d", max_timeout);
+ em_core_set_network_error(EMF_ERROR_NO_RESPONSE);
+ return 0;
+ }
+ EM_DEBUG_EXCEPTION("%d select timeout", max_timeout);
+ ++max_timeout;
+ continue;
+ }
+
+ nread = read(sockid, p, nleave);
+ if (nread < 0) {
+ EM_DEBUG_EXCEPTION("socket read error");
+/* if (errno == EINTR) continue; */
+ tcp_abort(stream);
+ return 0;
+ }
+
+ if (!nread) {
+ EM_DEBUG_EXCEPTION("socket read no data");
+ tcp_abort(stream);
+ return 0;
+ }
+
+ p += nread;
+ nleave -= nread;
+ }
+
+ *p = '\0';
+
+ if (_g_canceled) {
+ EM_DEBUG_EXCEPTION("thread canceled");
+ tcp_abort(stream);
+ return 0;
+ }
+
+ return 1;
+/* EM_DEBUG_LOG("end"); */
+#ifdef TEST_CANCEL_JOB
+JOB_CANCEL:
+ return 0;
+#endif
+}
+
+long tcp_getdata_lnx(TCPSTREAM *stream)
+{
+ struct timeval tmout;
+ fd_set readfds;
+ int nread, sret, sockid, maxfd;
+ int max_timeout = 0;
+
+ sockid = stream->tcpsi;
+ maxfd = sockid + 1;
+
+ /* EM_DEBUG_LOG("start sockid %d", sockid); */
+ if (sockid < 0) return false;
+
+ while (stream->ictr < 1) {
+#ifdef TEST_CANCEL_JOB
+ if (!em_core_check_thread_status()) {
+ EM_DEBUG_EXCEPTION("thread canceled...");
+ tcp_abort(stream);
+ goto JOB_CANCEL;
+ }
+#endif
+
+ /* if (_g_canceled){ */
+ /* EM_DEBUG_LOG1("thread canceled\n"); */
+ /* tcp_abort(stream); */
+ /* return 0; */
+ /* } */
+
+ tmout.tv_usec = 0;/* 1000*10; */
+ tmout.tv_sec = 1;
+
+ FD_ZERO(&readfds);
+ FD_SET(sockid, &readfds);
+
+ sret = select(maxfd, &readfds, NULL, NULL, &tmout);
+
+ if (sret < 0) {
+ EM_DEBUG_LOG("select error[%d]", errno);
+
+ tcp_abort(stream);
+ return false;
+ }
+ else if (!sret) {
+ if (max_timeout >= 50) {
+ EM_DEBUG_EXCEPTION("max select timeout %d", max_timeout);
+
+ em_core_set_network_error(EMF_ERROR_NO_RESPONSE);
+ return false;
+ }
+
+ EM_DEBUG_EXCEPTION("%d select timeout", max_timeout);
+
+ ++max_timeout;
+ continue;
+ }
+
+ if ((nread = read(sockid, stream->ibuf, BUFLEN)) < 0) {
+ EM_DEBUG_EXCEPTION("socket read failed...");
+
+ em_core_set_network_error(EMF_ERROR_SOCKET_FAILURE);
+
+ /* if (errno == EINTR) contine; */
+ tcp_abort(stream);
+ return false;
+ }
+
+ if (!nread) {
+ EM_DEBUG_EXCEPTION("socket read no data...");
+
+ em_core_set_network_error(EMF_ERROR_INVALID_RESPONSE);
+
+ tcp_abort(stream);
+ return false;
+ }
+
+ stream->ictr = nread;
+ stream->iptr = stream->ibuf;
+ }
+
+ if (_g_canceled) {
+ EM_DEBUG_EXCEPTION("\t thread canceled...\n");
+
+ tcp_abort(stream);
+ return false;
+ }
+
+ /* EM_DEBUG_LOG("end"); */
+ return true;
+
+#ifdef TEST_CANCEL_JOB
+JOB_CANCEL:
+ return false;
+#endif
+}
+
+EXPORT_API long tcp_sout_lnx(TCPSTREAM *stream, char *string, unsigned long size)
+{
+ struct timeval tmout;
+ fd_set writefds;
+ int sret, nwrite, maxfd, sockid;
+ int max_timeout = 0;
+
+ sockid = stream->tcpso;
+ maxfd = sockid + 1;
+/* EM_DEBUG_LOG("start sockid %d", sockid); */
+ if (sockid < 0) return 0;
+
+ while (size > 0) {
+#ifdef TEST_CANCEL_JOB
+ if (!em_core_check_thread_status()) {
+ EM_DEBUG_EXCEPTION("thread canceled");
+ tcp_abort(stream);
+ goto JOB_CANCEL;
+ }
+#endif
+ /* if (_g_canceled){ */
+ /* EM_DEBUG_LOG1("thread canceled"); */
+ /* tcp_abort(stream); */
+ /* return 0; */
+ /* } */
+
+ tmout.tv_usec = 0;
+ tmout.tv_sec = 1;
+ FD_ZERO(&writefds);
+ FD_SET(sockid, &writefds);
+
+ sret = select(maxfd, NULL, &writefds, NULL, &tmout);
+ if (sret < 0) {
+ EM_DEBUG_LOG("select error[%d]", errno);
+ tcp_abort(stream);
+ return 0;
+ }
+ else if (!sret) {
+ if (max_timeout >= 50) {
+ EM_DEBUG_EXCEPTION("max select timeout %d", max_timeout);
+ em_core_set_network_error(EMF_ERROR_NO_RESPONSE);
+ return 0;
+ }
+ EM_DEBUG_EXCEPTION("%d select timeout", max_timeout);
+ ++max_timeout;
+ continue;
+ }
+
+ if (!(nwrite = write(sockid, string, size)) < 0) {
+ EM_DEBUG_EXCEPTION("socket write error");
+/* if (errno == EINTR) continue; */
+ tcp_abort(stream);
+ return 0;
+ }
+
+ if (!nwrite) {
+ EM_DEBUG_EXCEPTION("socket write no data");
+ tcp_abort(stream);
+ return 0;
+ }
+
+ string += nwrite;
+ size -= nwrite;
+ }
+
+ if (_g_canceled) {
+ EM_DEBUG_EXCEPTION("thread canceled");
+ tcp_abort(stream);
+ return 0;
+ }
+/* EM_DEBUG_LOG("end"); */
+ return 1;
+
+#ifdef TEST_CANCEL_JOB
+JOB_CANCEL:
+ return 0;
+#endif
+}
+
+EXPORT_API long tcp_soutr_lnx(TCPSTREAM *stream, char *string)
+{
+ return tcp_sout_lnx(stream, string, strlen(string));
+}
+
diff --git a/email-core/em-network/include/em-network.h b/email-core/em-network/include/em-network.h
new file mode 100755
index 0000000..abdbe03
--- /dev/null
+++ b/email-core/em-network/include/em-network.h
@@ -0,0 +1,48 @@
+/*
+* email-service
+*
+* Copyright (c) 2000 - 2011 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.
+*
+*/
+
+/******************************************************************************
+ * File : em-network.h
+ * Desc :
+ *
+ * Auth :
+ *
+ * History :
+ * 2011.12.16 : created
+ *****************************************************************************/
+#ifndef __EM_NETWORK_H__
+#define __EM_NETWORK_H__
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif /* __cplusplus */
+
+#include "emf-types.h"
+
+EXPORT_API long em_core_ssl_cert_query_cb(char *reason, char *host, char *cert);
+EXPORT_API int em_core_check_network_status(int *err_code);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif
diff --git a/email-core/em-storage/em-storage-noti.c b/email-core/em-storage/em-storage-noti.c
new file mode 100755
index 0000000..52eceaa
--- /dev/null
+++ b/email-core/em-storage/em-storage-noti.c
@@ -0,0 +1,79 @@
+/*
+* email-service
+*
+* Copyright (c) 2000 - 2011 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.
+*
+*/
+
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <time.h>
+#include <sys/types.h>
+
+#ifdef USE_POWERMGMT
+#include <App-manager.h>
+#endif
+
+#include "em-storage.h"
+#include "emf-dbglog.h"
+
+#define EMAIL_SERVICE_GCONF_DIR "/Services/email-service"
+#define EMAIL_SERVICE_GCONF_MAIL_FULL "mail-full"
+
+
+#ifdef BACKUP_LCD_DIMMING_STATUS
+static GConfValue *g_gconf_backup_value = NULL;
+#endif
+
+
+
+#ifdef USE_POWERMGMT
+EXPORT_API int em_storage_power_management(int *error_code)
+{
+ EM_DEBUG_FUNC_BEGIN("err_code[%p]", error_code);
+ int err = EM_STORAGE_ERROR_NONE;
+ int inst_id = 0;
+
+ app_get_current_inst_id(&inst_id, &err);
+
+ if (AppMgrAppCommand(inst_id, APP_COMMAND_POWER_MGR, APPMGR_SET_PWRMGR_SYS_RUN_STATUS) < 0) {
+ EM_DEBUG_EXCEPTION("APPMGR_SET_PWRMGR_SYS_RUN_STATUS Failed");
+ return false;
+ }
+ EM_DEBUG_FUNC_END("APPMGR_SET_PWRMGR_SYS_RUN_STATUS Success");
+
+
+ return true;
+}
+#endif
+
+EXPORT_API int em_storage_sleep_on_off(int on, int *error_code)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ return true;
+}
+
+EXPORT_API int em_storage_dimming_on_off(int on, int *error_code)
+{
+ EM_DEBUG_FUNC_BEGIN("on[%d], err_code[%p]", on, error_code);
+
+ em_storage_sleep_on_off(on, error_code);
+
+ return true;
+}
diff --git a/email-core/em-storage/em-storage.c b/email-core/em-storage/em-storage.c
new file mode 100755
index 0000000..39bb296
--- /dev/null
+++ b/email-core/em-storage/em-storage.c
@@ -0,0 +1,14242 @@
+/*
+* email-service
+*
+* Copyright (c) 2000 - 2011 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.
+*
+*/
+
+
+/******************************************************************************
+ * File: em_storage.c
+ * Desc: EMail Framework Storage Library on Sqlite3
+ *
+ * Auth:
+ *
+ * History:
+ * 2007.03.02 : created
+ *****************************************************************************/
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <time.h>
+#include <sys/types.h>
+#include <sys/time.h>
+#include <sys/wait.h>
+#include <glib.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <errno.h>
+#include <dirent.h>
+#include <vconf.h>
+#include <sys/mman.h>
+#include <ss_manager.h>
+#include <fcntl.h>
+#include <dbus/dbus.h>
+#include <db-util.h>
+#include "em-core-utils.h"
+#include <pthread.h>
+#include "em-storage.h"
+#include "emf-dbglog.h"
+#include "emf-types.h"
+
+#define DB_STMT sqlite3_stmt *
+
+#define SETTING_MEMORY_TEMP_FILE_PATH "/tmp/email_tmp_file"
+
+#define EMF_STORAGE_CHANGE_NOTI "User.Email.StorageChange"
+#define EMF_NETOWRK_CHANGE_NOTI "User.Email.NetworkStatus"
+
+#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="
+
+#ifndef true
+#define true 1
+#define false 0
+#endif
+
+#define FLAG_SEEN 0x01
+#define FLAG_DELETED 0x02
+#define FLAG_FLAGGED 0x04
+#define FLAG_ANSWERED 0x08
+#define FLAG_OLD 0x10
+#define FLAG_DRAFT 0x20
+
+#undef close
+
+#define ACCOUNT_NAME_LEN_IN_MAIL_ACCOUNT_TBL 50
+#define RECEIVING_SERVER_ADDR_LEN_IN_MAIL_ACCOUNT_TBL 50
+#define EMAIL_ADDR_LEN_IN_MAIL_ACCOUNT_TBL 128
+#define USER_NAME_LEN_IN_MAIL_ACCOUNT_TBL 50
+#define PASSWORD_LEN_IN_MAIL_ACCOUNT_TBL 50
+#define SENDING_SERVER_ADDR_LEN_IN_MAIL_ACCOUNT_TBL 50
+#define SENDING_USER_LEN_IN_MAIL_ACCOUNT_TBL 50
+#define SENDING_PASSWORD_LEN_IN_MAIL_ACCOUNT_TBL 50
+#define DISPLAY_NAME_LEN_IN_MAIL_ACCOUNT_TBL 30
+#define REPLY_TO_ADDR_LEN_IN_MAIL_ACCOUNT_TBL 128
+#define RETURN_ADDR_LEN_IN_MAIL_ACCOUNT_TBL 128
+#define LOGO_ICON_PATH_LEN_IN_MAIL_ACCOUNT_TBL 256
+#define DISPLAY_NAME_FROM_LEN_IN_MAIL_ACCOUNT_TBL 256
+#define SIGNATURE_LEN_IN_MAIL_ACCOUNT_TBL 256
+#define MAILBOX_NAME_LEN_IN_MAIL_BOX_TBL 128
+#define ALIAS_LEN_IN_MAIL_BOX_TBL 128
+#define LOCAL_MBOX_LEN_IN_MAIL_READ_MAIL_UID_TBL 128
+#define MAILBOX_NAME_LEN_IN_MAIL_READ_MAIL_UID_TBL 128
+#define S_UID_LEN_IN_MAIL_READ_MAIL_UID_TBL 128
+#define DATA2_LEN_IN_MAIL_READ_MAIL_UID_TBL 256
+#define VALUE_LEN_IN_MAIL_RULE_TBL 256
+#define DEST_MAILBOX_LEN_IN_MAIL_RULE_TBL 128
+#define MAILBOX_NAME_LEN_IN_MAIL_ATTACHMENT_TBL 128
+#define ATTACHMENT_PATH_LEN_IN_MAIL_ATTACHMENT_TBL 256
+#define ATTACHMENT_NAME_LEN_IN_MAIL_ATTACHMENT_TBL 256
+#define CONTENT_ID_LEN_IN_MAIL_ATTACHMENT_TBL 256
+#define MAILBOX_LEN_IN_MAIL_TBL 128
+#define SERVER_MAILBOX_LEN_IN_MAIL_TBL 128
+#define SERVER_MAIL_ID_LEN_IN_MAIL_TBL 128
+#define FROM_LEN_IN_MAIL_TBL 256
+#define SENDER_LEN_IN_MAIL_TBL 256
+#define REPLY_TO_LEN_IN_MAIL_TBL 256
+#define TO_LEN_IN_MAIL_TBL 3999
+#define CC_LEN_IN_MAIL_TBL 3999
+#define BCC_LEN_IN_MAIL_TBL 3999
+#define RETURN_PATH_LEN_IN_MAIL_TBL 3999
+#define SUBJECT_LEN_IN_MAIL_TBL 1027
+#define THREAD_TOPIC_LEN_IN_MAIL_TBL 256
+#define TEXT_1_LEN_IN_MAIL_TBL 256
+#define TEXT_2_LEN_IN_MAIL_TBL 256
+#define DATETIME_LEN_IN_MAIL_TBL 128
+#define MESSAGE_ID_LEN_IN_MAIL_TBL 256
+#define FROM_CONTACT_NAME_LEN_IN_MAIL_TBL 3999
+#define FROM_EMAIL_ADDRESS_LEN_IN_MAIL_TBL 3999
+#define TO_CONTACT_NAME_LEN_IN_MAIL_TBL 3999
+#define TO_EMAIL_ADDRESS_LEN_IN_MAIL_TBL 3999
+#define MAILBOX_LEN_IN_MAIL_MEETING_TBL 128
+#define LOCATION_LEN_IN_MAIL_MEETING_TBL 1024
+#define GLOBAL_OBJECT_ID_LEN_IN_MAIL_MEETING_TBL 128
+#define STANDARD_NAME_LEN_IN_MAIL_MEETING_TBL 32
+#define DAYLIGHT_NAME_LEN_IN_MAIL_MEETING_TBL 32
+#define PREVIEWBODY_LEN_IN_MAIL_TBL 512
+
+/* this define is used for query to change data (delete, insert, update) */
+#define EM_STORAGE_START_WRITE_TRANSACTION(transaction_flag, error_code) \
+ if (transaction_flag)\
+ {\
+ em_storage_shm_mutex_timedlock(&mapped_for_db_lock, 2);\
+ if (em_storage_begin_transaction(NULL, NULL, &error_code) == false) \
+ {\
+ EM_DEBUG_EXCEPTION("em_storage_begin_transaction() error[%d]", error_code);\
+ goto FINISH_OFF;\
+ }\
+ }
+
+/* this define is used for query to change data (delete, insert, update) */
+#define EM_STORAGE_FINISH_WRITE_TRANSACTION(transaction_flag, result_code, error_code) \
+ if (transaction_flag)\
+ {\
+ if (result_code == true)\
+ {\
+ if (em_storage_commit_transaction(NULL, NULL, NULL) == false)\
+ {\
+ error_code = EM_STORAGE_ERROR_DB_FAILURE;\
+ result_code = false;\
+ }\
+ }\
+ else\
+ {\
+ if (em_storage_rollback_transaction(NULL, NULL, NULL) == false)\
+ error_code = EM_STORAGE_ERROR_DB_FAILURE;\
+ }\
+ em_storage_shm_mutex_unlock(&mapped_for_db_lock);\
+ }
+
+/* this define is used for query to read (select) */
+#define EM_STORAGE_START_READ_TRANSACTION(transaction_flag) \
+ if (transaction_flag)\
+ {\
+ /*em_storage_shm_mutex_timedlock(&mapped_for_db_lock, 2);*/\
+ }
+
+/* this define is used for query to read (select) */
+#define EM_STORAGE_FINISH_READ_TRANSACTION(transaction_flag) \
+ if (transaction_flag)\
+ {\
+ /*em_storage_shm_mutex_unlock(&mapped_for_db_lock);*/\
+ }
+
+/* for safety DB operation */
+static char g_db_path[248] = {0x00, };
+
+
+#ifdef __FEATURE_USE_PTHREAD__
+static pthread_mutex_t _transactionBeginLock = PTHREAD_MUTEX_INITIALIZER;
+static pthread_mutex_t _transactionEndLock = PTHREAD_MUTEX_INITIALIZER;
+static pthread_mutex_t _dbus_noti_lock = PTHREAD_MUTEX_INITIALIZER;
+static pthread_mutex_t _db_handle_lock = PTHREAD_MUTEX_INITIALIZER;
+#else /* __FEATURE_USE_PTHREAD__ */
+static GMutex *_transactionBeginLock = NULL;
+static GMutex *_transactionEndLock = NULL;
+static GMutex *_dbus_noti_lock = NULL;
+static GMutex *_db_handle_lock = NULL;
+#endif /* __FEATURE_USE_PTHREAD__ */
+
+#define _MULTIPLE_DB_HANDLE
+
+#ifdef _MULTIPLE_DB_HANDLE
+
+#define _DISCONNECT_DB /* db_util_close(_db_handle); */
+
+typedef struct
+{
+#ifdef __FEATURE_USE_PTHREAD__
+ pthread_t thread_id;
+#else
+ /* TODO : must write codes for g_thread */
+#endif
+ sqlite3 *db_handle;
+} db_handle_t;
+
+#define MAX_DB_CLIENT 100
+
+/* static int _db_handle_count = 0; */
+db_handle_t _db_handle_list[MAX_DB_CLIENT] = {{0, 0}, };
+
+sqlite3 *em_storage_get_db_handle()
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int i;
+ pthread_t current_thread_id = THREAD_SELF();
+ sqlite3 *result_db_handle = NULL;
+
+ ENTER_CRITICAL_SECTION(_db_handle_lock);
+ for (i = 0; i < MAX_DB_CLIENT; i++)
+ {
+ if (pthread_equal(current_thread_id, _db_handle_list[i].thread_id))
+ {
+ EM_DEBUG_LOG("found db handle at [%d]", i);
+ result_db_handle = _db_handle_list[i].db_handle;
+ break;
+ }
+ }
+ LEAVE_CRITICAL_SECTION(_db_handle_lock);
+
+ if (!result_db_handle)
+ EM_DEBUG_EXCEPTION("Can't find proper handle for [%d]", current_thread_id);
+
+ EM_DEBUG_FUNC_END();
+ return result_db_handle;
+}
+
+int em_storage_set_db_handle(sqlite3 *db_handle)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int i, error_code = EMF_ERROR_MAX_EXCEEDED;
+ pthread_t current_thread_id = THREAD_SELF();
+
+ ENTER_CRITICAL_SECTION(_db_handle_lock);
+ for (i = 0; i < MAX_DB_CLIENT; i++) {
+ if (_db_handle_list[i].thread_id == 0) {
+ _db_handle_list[i].thread_id = current_thread_id;
+ _db_handle_list[i].db_handle = db_handle;
+ EM_DEBUG_LOG("current_thread_id [%d], index [%d]", current_thread_id, i);
+ error_code = EMF_ERROR_NONE;
+ break;
+ }
+ }
+ LEAVE_CRITICAL_SECTION(_db_handle_lock);
+
+ if (error_code == EMF_ERROR_MAX_EXCEEDED)
+ EM_DEBUG_EXCEPTION("Exceeded the limitation of db client. Can't find empty slot in _db_handle_list.");
+
+ EM_DEBUG_FUNC_END("error_code [%d]", error_code);
+ return error_code;
+}
+
+int em_storage_remove_db_handle()
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int i, error_code = EMF_ERROR_MAX_EXCEEDED;
+ ENTER_CRITICAL_SECTION(_db_handle_lock);
+ for (i = 0; i < MAX_DB_CLIENT; i++)
+ {
+ if (_db_handle_list[i].thread_id == THREAD_SELF())
+ {
+ _db_handle_list[i].thread_id = 0;
+ _db_handle_list[i].db_handle = NULL;
+ EM_DEBUG_LOG("index [%d]", i);
+ error_code = EMF_ERROR_NONE;
+ break;
+ }
+ }
+ LEAVE_CRITICAL_SECTION(_db_handle_lock);
+
+ if (error_code == EMF_ERROR_MAX_EXCEEDED)
+ EM_DEBUG_EXCEPTION("Can't find proper thread_id");
+
+ EM_DEBUG_FUNC_END("error_code [%d]", error_code);
+ return error_code;
+}
+
+
+int em_storage_reset_db_handle_list()
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int i;
+
+ ENTER_CRITICAL_SECTION(_db_handle_lock);
+ for (i = 0; i < MAX_DB_CLIENT; i++)
+ {
+ _db_handle_list[i].thread_id = 0;
+ _db_handle_list[i].db_handle = NULL;
+ }
+ LEAVE_CRITICAL_SECTION(_db_handle_lock)
+
+ EM_DEBUG_FUNC_END();
+ return EMF_ERROR_NONE;
+}
+
+sqlite3 *em_storage_get_db_connection()
+{
+ sqlite3 *tmp_db_handle = em_storage_get_db_handle();
+ if (NULL == tmp_db_handle)
+ tmp_db_handle = em_storage_db_open(NULL);
+ return tmp_db_handle;
+}
+
+
+#else /* _MULTIPLE_DB_HANDLE */
+#define _DISCONNECT_DB /* db_util_close(_db_handle); */
+
+sqlite3 *_db_handle = NULL;
+
+sqlite3 *em_storage_get_db_connection()
+{
+ if (NULL == _db_handle)
+ em_storage_db_open(NULL);
+ return _db_handle;
+}
+#endif /* _MULTIPLE_DB_HANDLE */
+
+/* ------------------------------------------------------------------------------ */
+/* Mutex using shared memory */
+typedef struct
+{
+ pthread_mutex_t mutex;
+ int data;
+} mmapped_t;
+
+mmapped_t *mapped_for_db_lock = NULL;
+int shm_fd_for_db_lock = 0;
+
+#ifdef __FEATURE_USE_SHARED_MUTEX_FOR_GENERATING_MAIL_ID__
+mmapped_t *mapped_for_generating_mail_id = NULL;
+int shm_fd_for_generating_mail_id = 0;
+#endif /* __FEATURE_USE_SHARED_MUTEX_FOR_GENERATING_MAIL_ID__ */
+
+#ifdef __FEATURE_USE_SHARED_MUTEX_FOR_PROTECTED_FUNC_CALL__
+#define EM_STORAGE_PROTECTED_FUNC_CALL(function_call, return_value) \
+ { em_storage_shm_mutex_timedlock(&mapped_for_db_lock, 2); return_value = function_call; em_storage_shm_mutex_unlock(&mapped_for_db_lock); }
+#else /* __FEATURE_USE_SHARED_MUTEX_FOR_PROTECTED_FUNC_CALL__ */
+#define EM_STORAGE_PROTECTED_FUNC_CALL(function_call, return_value) \
+ { return_value = function_call; }
+#endif /* __FEATURE_USE_SHARED_MUTEX_FOR_PROTECTED_FUNC_CALL__ */
+
+EXPORT_API int em_storage_shm_file_init(const char *shm_file_name)
+{
+ EM_DEBUG_FUNC_BEGIN("shm_file_name [%p]", shm_file_name);
+
+ if(!shm_file_name) {
+ EM_DEBUG_EXCEPTION("EM_STORAGE_ERROR_INVALID_PARAM");
+ return EM_STORAGE_ERROR_INVALID_PARAM;
+ }
+
+ int fd = shm_open(shm_file_name, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP); /* note: permission is not working */
+
+ if (fd > 0) {
+ fchmod(fd, 0666);
+ EM_DEBUG_LOG("** Create SHM FILE **");
+ if (ftruncate(fd, sizeof(mmapped_t)) != 0) {
+ EM_DEBUG_EXCEPTION("ftruncate failed: %s", strerror(errno));
+ return EM_STORAGE_ERROR_SYSTEM_FAILURE;
+ }
+
+ mmapped_t *m = (mmapped_t *)mmap(NULL, sizeof(mmapped_t), PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
+ if (m == MAP_FAILED) {
+ EM_DEBUG_EXCEPTION("mmap failed: %s", strerror(errno));
+ return EM_STORAGE_ERROR_SYSTEM_FAILURE;
+ }
+
+ m->data = 0;
+
+ pthread_mutexattr_t mattr;
+ pthread_mutexattr_init(&mattr);
+ pthread_mutexattr_setpshared(&mattr, PTHREAD_PROCESS_SHARED);
+ pthread_mutexattr_setrobust_np(&mattr, PTHREAD_MUTEX_ROBUST_NP);
+ pthread_mutex_init(&(m->mutex), &mattr);
+ pthread_mutexattr_destroy(&mattr);
+ }
+ else {
+ EM_DEBUG_EXCEPTION("shm_open failed: %s", strerror(errno));
+ return EM_STORAGE_ERROR_SYSTEM_FAILURE;
+ }
+ close(fd);
+ EM_DEBUG_FUNC_END();
+ return EM_STORAGE_ERROR_NONE;
+}
+
+int em_storage_shm_file_destroy(const char *shm_file_name)
+{
+ EM_DEBUG_FUNC_BEGIN("shm_file_name [%p]", shm_file_name);
+ if(!shm_file_name) {
+ EM_DEBUG_EXCEPTION("EM_STORAGE_ERROR_INVALID_PARAM");
+ return EM_STORAGE_ERROR_INVALID_PARAM;
+ }
+
+ if (shm_unlink(shm_file_name) != 0)
+ EM_DEBUG_EXCEPTION("shm_unlink failed: %s", strerror(errno));
+ EM_DEBUG_FUNC_END();
+ return EM_STORAGE_ERROR_NONE;
+}
+
+static int em_storage_shm_mutex_init(const char *shm_file_name, int *param_shm_fd, mmapped_t **param_mapped)
+{
+ EM_DEBUG_FUNC_BEGIN("shm_file_name [%p] param_shm_fd [%p], param_mapped [%p]", shm_file_name, param_shm_fd, param_mapped);
+
+ if(!shm_file_name || !param_shm_fd || !param_mapped) {
+ EM_DEBUG_EXCEPTION("EM_STORAGE_ERROR_INVALID_PARAM");
+ return EM_STORAGE_ERROR_INVALID_PARAM;
+ }
+
+ if (!(*param_mapped)) {
+ EM_DEBUG_LOG("** mapping begin **");
+
+ if (!(*param_shm_fd)) { /* open shm_file_name at first. Otherwise, the num of files in /proc/pid/fd will be increasing */
+ *param_shm_fd = shm_open(shm_file_name, O_RDWR, 0);
+ if ((*param_shm_fd) == -1) {
+ EM_DEBUG_EXCEPTION("FAIL: shm_open(): %s", strerror(errno));
+ return EM_STORAGE_ERROR_SYSTEM_FAILURE;
+ }
+ }
+ mmapped_t *tmp = (mmapped_t *)mmap(NULL, sizeof(mmapped_t), PROT_READ|PROT_WRITE, MAP_SHARED, (*param_shm_fd), 0);
+
+ if (tmp == MAP_FAILED) {
+ EM_DEBUG_EXCEPTION("mmap failed: %s", strerror(errno));
+ return EM_STORAGE_ERROR_SYSTEM_FAILURE;
+ }
+ *param_mapped = tmp;
+ }
+
+ EM_DEBUG_FUNC_END();
+ return EM_STORAGE_ERROR_NONE;
+}
+
+static int em_storage_shm_mutex_timedlock(mmapped_t **param_mapped, int sec)
+{
+ EM_DEBUG_FUNC_BEGIN("param_mapped [%p], sec [%d]", param_mapped, sec);
+
+ if(!param_mapped) {
+ EM_DEBUG_EXCEPTION("EM_STORAGE_ERROR_INVALID_PARAM");
+ return EM_STORAGE_ERROR_INVALID_PARAM;
+ }
+
+ struct timespec abs_time;
+ clock_gettime(CLOCK_REALTIME, &abs_time);
+ abs_time.tv_sec += sec;
+
+ int err = pthread_mutex_timedlock(&((*param_mapped)->mutex), &abs_time);
+
+ if (err == EOWNERDEAD) {
+ err = pthread_mutex_consistent_np(&((*param_mapped)->mutex));
+ EM_DEBUG_EXCEPTION("Previous owner is dead with lock. Fix mutex : %s", EM_STRERROR(err));
+ }
+ else if (err != 0) {
+ EM_DEBUG_EXCEPTION("ERROR : %s", EM_STRERROR(err));
+ return err;
+ }
+
+ EM_DEBUG_FUNC_END();
+ return EM_STORAGE_ERROR_NONE;
+}
+
+void em_storage_shm_mutex_unlock(mmapped_t **param_mapped)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ pthread_mutex_unlock(&((*param_mapped)->mutex));
+ EM_DEBUG_FUNC_END();
+}
+/* ------------------------------------------------------------------------------ */
+
+
+static int _open_counter = 0;
+static int g_transaction = false;
+
+static int em_storage_get_password_file_name(int account_id, char *recv_password_file_name, char *send_password_file_name);
+static int em_storage_read_password_ss(char *file_name, char **password);
+
+
+typedef struct {
+ const char *object_name;
+ unsigned int data_flag;
+} emf_db_object_t;
+
+static const emf_db_object_t _g_db_tables[] =
+{
+ { "mail_read_mail_uid_tbl", 1},
+ { "mail_tbl", 1},
+ { "mail_attachment_tbl", 1},
+ { NULL, 0},
+};
+
+static const emf_db_object_t _g_db_indexes[] =
+{
+ { "mail_read_mail_uid_idx1", 1},
+ { "mail_idx1", 1},
+ { "mail_attachment_idx1", 1},
+ { NULL, 1},
+};
+
+enum
+{
+ CREATE_TABLE_MAIL_ACCOUNT_TBL,
+ CREATE_TABLE_MAIL_BOX_TBL,
+ CREATE_TABLE_MAIL_READ_MAIL_UID_TBL,
+ CREATE_TABLE_MAIL_RULE_TBL,
+ CREATE_TABLE_MAIL_TBL,
+ CREATE_TABLE_MAIL_ATTACHMENT_TBL,
+#ifdef __FEATURE_PARTIAL_BODY_DOWNLOAD__
+ CREATE_TABLE_MAIL_PARTIAL_BODY_ACTIVITY_TBL,
+#endif
+ CREATE_TABLE_MAIL_MEETING_TBL,
+#ifdef __LOCAL_ACTIVITY__
+ CREATE_TABLE_MAIL_LOCAL_ACTIVITY_TBL,
+#endif
+ CREATE_TABLE_MAX,
+};
+
+enum
+{
+ DATA1_IDX_IN_MAIL_ACTIVITY_TBL = 0,
+ TRANSTYPE_IDX_IN_MAIL_ACTIVITY_TBL,
+ FLAG_IDX_IN_MAIL_ACTIVITY_TBL,
+};
+
+
+enum
+{
+ ACCOUNT_BIND_TYPE_IDX_IN_MAIL_ACCOUNT_TBL = 0,
+ ACCOUNT_NAME_IDX_IN_MAIL_ACCOUNT_TBL,
+ RECEIVING_SERVER_TYPE_TYPE_IDX_IN_MAIL_ACCOUNT_TBL,
+ RECEIVING_SERVER_ADDR_IDX_IN_MAIL_ACCOUNT_TBL,
+ EMAIL_ADDR_IDX_IN_MAIL_ACCOUNT_TBL,
+ USER_NAME_IDX_IN_MAIL_ACCOUNT_TBL,
+ PASSWORD_IDX_IN_MAIL_ACCOUNT_TBL,
+ RETRIEVAL_MODE_IDX_IN_MAIL_ACCOUNT_TBL,
+ PORT_NUM_IDX_IN_MAIL_ACCOUNT_TBL,
+ USE_SECURITY_IDX_IN_MAIL_ACCOUNT_TBL,
+ SENDING_SERVER_TYPE_IDX_IN_MAIL_ACCOUNT_TBL,
+ SENDING_SERVER_ADDR_IDX_IN_MAIL_ACCOUNT_TBL,
+ SENDING_PORT_NUM_IDX_IN_MAIL_ACCOUNT_TBL,
+ SENDING_AUTH_IDX_IN_MAIL_ACCOUNT_TBL,
+ SENDING_SECURITY_IDX_IN_MAIL_ACCOUNT_TBL,
+ SENDING_USER_IDX_IN_MAIL_ACCOUNT_TBL,
+ SENDING_PASSWORD_IDX_IN_MAIL_ACCOUNT_TBL,
+ DISPLAY_NAME_IDX_IN_MAIL_ACCOUNT_TBL,
+ REPLY_TO_ADDR_IDX_IN_MAIL_ACCOUNT_TBL,
+ RETURN_ADDR_IDX_IN_MAIL_ACCOUNT_TBL,
+ ACCOUNT_ID_IDX_IN_MAIL_ACCOUNT_TBL,
+ KEEP_ON_SERVER_IDX_IN_MAIL_ACCOUNT_TBL,
+ FLAG1_IDX_IN_MAIL_ACCOUNT_TBL,
+ FLAG2_IDX_IN_MAIL_ACCOUNT_TBL,
+ POP_BEFORE_SMTP_IDX_IN_MAIL_ACCOUNT_TBL,
+ APOP_IDX_IN_MAIL_ACCOUNT_TBL,
+ LOGO_ICON_PATH_IDX_IN_MAIL_ACCOUNT_TBL,
+ PRESET_ACCOUNT_IDX_IN_MAIL_ACCOUNT_TBL,
+ TARGET_STORAGE_IDX_IN_MAIL_ACCOUNT_TBL,
+ CHECK_INTERVAL_IDX_IN_MAIL_ACCOUNT_TBL,
+ PRIORITY_IDX_IN_MAIL_ACCOUNT_TBL,
+ KEEP_LOCAL_COPY_IDX_IN_MAIL_ACCOUNT_TBL,
+ REQ_DELIVERY_RECEIPT_IDX_IN_MAIL_ACCOUNT_TBL,
+ REQ_READ_RECEIPT_IDX_IN_MAIL_ACCOUNT_TBL,
+ DOWNLOAD_LIMIT_IDX_IN_MAIL_ACCOUNT_TBL,
+ BLOCK_ADDRESS_IDX_IN_MAIL_ACCOUNT_TBL,
+ BLOCK_SUBJECT_IDX_IN_MAIL_ACCOUNT_TBL,
+ DISPLAY_NAME_FROM_IDX_IN_MAIL_ACCOUNT_TBL,
+ REPLY_WITH_BODY_IDX_IN_MAIL_ACCOUNT_TBL,
+ FORWARD_WITH_FILES_IDX_IN_MAIL_ACCOUNT_TBL,
+ ADD_MYNAME_CARD_IDX_IN_MAIL_ACCOUNT_TBL,
+ ADD_SIGNATURE_IDX_IN_MAIL_ACCOUNT_TBL,
+ SIGNATURE_IDX_IN_MAIL_ACCOUNT_TBL,
+ ADD_MY_ADDRESS_TO_BCC_IDX_IN_MAIL_ACCOUNT_TBL,
+ MY_ACCOUNT_ID_IDX_IN_MAIL_ACCOUNT_TBL,
+ INDEX_COLOR_IDX_IN_MAIL_ACCOUNT_TBL,
+ SYNC_STATUS_IDX_IN_MAIL_ACCOUNT_TBL,
+};
+
+enum
+{
+ TO_RECIPIENT = 0,
+ CC_RECIPIENT,
+ BCC_RECIPIENT,
+};
+enum
+{
+ ACCOUNT_ID_IDX_IN_MAIL_BOX_TBL = 0,
+ LOCAL_YN_IDX_IN_MAIL_BOX_TBL,
+ MAILBOX_NAME_IDX_IN_MAIL_BOX_TBL,
+ MAILBOX_TYPE_IDX_IN_MAIL_BOX_TBL,
+ ALIAS_IDX_IN_MAIL_BOX_TBL,
+ SYNC_WITH_SERVER_YN_IDX_IN_MAIL_BOX_TBL,
+ MODIFIABLE_YN_IDX_IN_MAIL_BOX_TBL,
+ TOTAL_MAIL_COUNT_ON_SERVER_IDX_IN_MAIL_BOX_TBL,
+ ARCHIVE_IDX_IN_MAIL_BOX_TBL,
+ MAIL_SLOT_SIZE_IDX_IN_MAIL_BOX_TBL,
+};
+
+enum
+{
+ ACCOUNT_ID_IDX_IN_MAIL_READ_MAIL_UID_TBL = 0,
+ LOCAL_MBOX_IDX_IN_MAIL_READ_MAIL_UID_TBL,
+ LOCAL_UID_IDX_IN_MAIL_READ_MAIL_UID_TBL,
+ MAILBOX_NAME_IDX_IN_MAIL_READ_MAIL_UID_TBL,
+ S_UID_IDX_IN_MAIL_READ_MAIL_UID_TBL,
+ DATA1_IDX_IN_MAIL_READ_MAIL_UID_TBL,
+ DATA2_IDX_IN_MAIL_READ_MAIL_UID_TBL,
+ FLAG_IDX_IN_MAIL_READ_MAIL_UID_TBL,
+ IDX_NUM_IDX_IN_MAIL_READ_MAIL_UID_TBL, /* unused */
+};
+
+enum
+{
+ ACCOUNT_ID_IDX_IN_MAIL_RULE_TBL = 0,
+ RULE_ID_IDX_IN_MAIL_RULE_TBL,
+ TYPE_IDX_IN_MAIL_RULE_TBL,
+ VALUE_IDX_IN_MAIL_RULE_TBL,
+ ACTION_TYPE_IDX_IN_MAIL_RULE_TBL,
+ DEST_MAILBOX_IDX_IN_MAIL_RULE_TBL,
+ FLAG1_IDX_IN_MAIL_RULE_TBL,
+ FLAG2_IDX_IN_MAIL_RULE_TBL,
+};
+
+enum
+{
+ MAIL_ID_IDX_IN_MAIL_TBL = 0,
+ ACCOUNT_ID_IDX_IN_MAIL_TBL,
+ MAILBOX_NAME_IDX_IN_MAIL_TBL,
+ MAILBOX_TYPE_IDX_IN_MAIL_TBL,
+ SUBJECT_IDX_IN_MAIL_TBL,
+ DATETIME_IDX_IN_MAIL_TBL,
+ SERVER_MAIL_STATUS_IDX_IN_MAIL_TBL,
+ SERVER_MAILBOX_NAME_IDX_IN_MAIL_TBL,
+ SERVER_MAIL_ID_IDX_IN_MAIL_TBL,
+ MESSAGE_ID_IDX_IN_MAIL_TBL,
+ FULL_ADDRESS_FROM_IDX_IN_MAIL_TBL,
+ FULL_ADDRESS_REPLY_IDX_IN_MAIL_TBL,
+ FULL_ADDRESS_TO_IDX_IN_MAIL_TBL,
+ FULL_ADDRESS_CC_IDX_IN_MAIL_TBL,
+ FULL_ADDRESS_BCC_IDX_IN_MAIL_TBL,
+ FULL_ADDRESS_RETURN_IDX_IN_MAIL_TBL,
+ EMAIL_ADDRESS_SENDER_IDX_IN_MAIL_TBL,
+ EMAIL_ADDRESS_RECIPIENT_IDX_IN_MAIL_TBL,
+ ALIAS_SENDER_IDX_IN_MAIL_TBL,
+ ALIAS_RECIPIENT_IDX_IN_MAIL_TBL,
+ BODY_DOWNLOAD_STATUS_IDX_IN_MAIL_TBL,
+ FILE_PATH_PLAIN_IDX_IN_MAIL_TBL,
+ FILE_PATH_HTML_IDX_IN_MAIL_TBL,
+ MAIL_SIZE_IDX_IN_MAIL_TBL,
+ FLAGS_SEEN_FIELD_IDX_IN_MAIL_TBL,
+ FLAGS_DELETED_FIELD_IDX_IN_MAIL_TBL,
+ FLAGS_FLAGGED_FIELD_IDX_IN_MAIL_TBL,
+ FLAGS_ANSWERED_FIELD_IDX_IN_MAIL_TBL,
+ FLAGS_RECENT_FIELD_IDX_IN_MAIL_TBL,
+ FLAGS_DRAFT_FIELD_IDX_IN_MAIL_TBL,
+ FLAGS_FORWARDED_FIELD_IDX_IN_MAIL_TBL,
+ DRM_STATUS_IDX_IN_MAIL_TBL,
+ PRIORITY_IDX_IN_MAIL_TBL,
+ SAVE_STATUS_IDX_IN_MAIL_TBL,
+ LOCK_STATUS_IDX_IN_MAIL_TBL,
+ REPORT_STATUS_IDX_IN_MAIL_TBL,
+ ATTACHMENT_COUNT_IDX_IN_MAIL_TBL,
+ INLINE_CONTENT_COUNT_IDX_IN_MAIL_TBL,
+ THREAD_ID_IDX_IN_MAIL_TBL,
+ THREAD_ITEM_COUNT_IDX_IN_MAIL_TBL,
+ PREVIEW_TEXT_IDX_IN_MAIL_TBL,
+ MEETING_REQUEST_STATUS_IDX_IN_MAIL_TBL,
+ FIELD_COUNT_OF_EMF_MAIL_TBL, /* End of mail_tbl */
+};
+
+enum
+{
+ ATTACHMENT_ID_IDX_IN_MAIL_ATTACHMENT_TBL = 0,
+ ATTACHMENT_NAME_IDX_IN_MAIL_ATTACHMENT_TBL,
+ ATTACHMENT_PATH_IDX_IN_MAIL_ATTACHMENT_TBL,
+ ATTACHMENT_SIZE_IDX_IN_MAIL_ATTACHMENT_TBL,
+ MAIL_ID_IDX_IN_MAIL_ATTACHMENT_TBL,
+ ACCOUNT_ID_IDX_IN_MAIL_ATTACHMENT_TBL,
+ MAILBOX_NAME_IDX_IN_MAIL_ATTACHMENT_TBL,
+ FILE_YN_IDX_IN_MAIL_ATTACHMENT_TBL,
+ FLAG1_IDX_IN_MAIL_ATTACHMENT_TBL,
+ FLAG2_IDX_IN_MAIL_ATTACHMENT_TBL,
+ FLAG3_IDX_IN_MAIL_ATTACHMENT_TBL,
+#ifdef __ATTACHMENT_OPTI__
+ ENCODING_IDX_IN_MAIL_ATTACHMENT_TBL,
+ SECTION_IDX_IN_MAIL_ATTACHMENT_TBL,
+#endif
+};
+
+enum {
+ IDX_IDX_IN_MAIL_CONTACT_SYNC_TBL = 0,
+#ifndef USE_SIMPLE_CONTACT_SYNC_ATTRIBUTES
+ MAIL_ID_IDX_IN_MAIL_CONTACT_SYNC_TBL,
+ ACCOUNT_ID_IDX_IN_MAIL_CONTACT_SYNC_TBL,
+ ADDRESS_TYPE_IDX_IN_MAIL_CONTACT_SYNC_TBL,
+ ADDRESS_IDX_IDX_IN_MAIL_CONTACT_SYNC_TBL,
+#endif
+ ADDRESS_IDX_IN_MAIL_CONTACT_SYNC_TBL,
+ CONTACT_ID_IDX_IN_MAIL_CONTACT_SYNC_TBL,
+ STORAGE_TYPE_IDX_IN_MAIL_CONTACT_SYNC_TBL,
+ CONTACT_NAME_IDX_IN_MAIL_CONTACT_SYNC_TBL,
+#ifndef USE_SIMPLE_CONTACT_SYNC_ATTRIBUTES
+ DISPLAY_NAME_IDX_IN_MAIL_CONTACT_SYNC_TBL,
+ FLAG1_IDX_IN_MAIL_CONTACT_SYNC_TBL,
+#endif
+};
+
+/* sowmya.kr 03032010, changes for get list of mails for given addr list */
+typedef struct _em_mail_id_list {
+ int mail_id;
+ struct _em_mail_id_list *next;
+} em_mail_id_list;
+
+static char *g_test_query[] = {
+ /* 1. select mail_account_tbl */
+ "SELECT"
+ " account_bind_type, "
+ " account_name, "
+ " receiving_server_type, "
+ " receiving_server_addr, "
+ " email_addr, "
+ " user_name, "
+ " password, "
+ " retrieval_mode, "
+ " port_num, "
+ " use_security, "
+ " sending_server_type, "
+ " sending_server_addr, "
+ " sending_port_num, "
+ " sending_auth, "
+ " sending_security, "
+ " sending_user, "
+ " sending_password, "
+ " display_name, "
+ " reply_to_addr, "
+ " return_addr, "
+ " account_id, "
+ " keep_on_server, "
+ " flag1, "
+ " flag2, "
+ " pop_before_smtp, "
+ " apop"
+ ", logo_icon_path, "
+ " preset_account, "
+ " target_storage, "
+ " check_interval, "
+ " priority, "
+ " keep_local_copy, "
+ " req_delivery_receipt, "
+ " req_read_receipt, "
+ " download_limit, "
+ " block_address, "
+ " block_subject, "
+ " display_name_from, "
+ " reply_with_body, "
+ " forward_with_files, "
+ " add_myname_card, "
+ " add_signature, "
+ " signature"
+ ", add_my_address_to_bcc"
+ ", my_account_id "
+ ", index_color "
+ ", sync_status "
+ " FROM mail_account_tbl",
+ /* 2. select mail_box_tbl */
+ "SELECT "
+ " mailbox_id, "
+ " account_id, "
+ " local_yn, "
+ " mailbox_name, "
+ " mailbox_type, "
+ " alias, "
+ " sync_with_server_yn, "
+ " modifiable_yn, "
+ " total_mail_count_on_server, "
+ " has_archived_mails, "
+ " mail_slot_size "
+ " FROM mail_box_tbl ",
+ /* 3. select mail_read_mail_uid_tbl */
+ "SELECT "
+ " account_id, "
+ " local_mbox, "
+ " local_uid, "
+ " mailbox_name, "
+ " s_uid, "
+ " data1 , "
+ " data2, "
+ " flag, "
+ " idx_num "
+ " FROM mail_read_mail_uid_tbl ",
+ /* 4. select mail_rule_tbl */
+ "SELECT "
+ " account_id, "
+ " rule_id, "
+ " type, "
+ " value, "
+ " action_type, "
+ " dest_mailbox, "
+ " flag1, "
+ " flag2 "
+ " FROM mail_rule_tbl ",
+ /* 5. select mail_tbl */
+ "SELECT"
+ " mail_id, "
+ " account_id, "
+ " mailbox_name, "
+ " mailbox_type, "
+ " subject, "
+ " date_time, "
+ " server_mail_status, "
+ " server_mailbox_name, "
+ " server_mail_id, "
+ " message_id, "
+ " full_address_from, "
+ " full_address_reply, "
+ " full_address_to, "
+ " full_address_cc, "
+ " full_address_bcc, "
+ " full_address_return, "
+ " email_address_sender, "
+ " email_address_recipient, "
+ " alias_sender, "
+ " alias_recipient, "
+ " body_download_status, "
+ " file_path_plain, "
+ " file_path_html, "
+ " mail_size, "
+ " flags_seen_field ,"
+ " flags_deleted_field ,"
+ " flags_flagged_field ,"
+ " flags_answered_field ,"
+ " flags_recent_field ,"
+ " flags_draft_field ,"
+ " flags_forwarded_field,"
+ " DRM_status, "
+ " priority, "
+ " save_status, "
+ " lock_status, "
+ " report_status, "
+ " attachment_count, "
+ " inline_content_count, "
+ " thread_id, "
+ " thread_item_count, "
+ " preview_text"
+ " meeting_request_status, "
+ " FROM mail_tbl",
+ /* 6. select mail_attachment_tbl */
+ "SELECT "
+ " attachment_id, "
+ " attachment_name, "
+ " attachment_path, "
+ " attachment_size, "
+ " mail_id, "
+ " account_id, "
+ " mailbox_name, "
+ " file_yn, "
+ " flag1, "
+ " flag2, "
+ " flag3 "
+ " FROM mail_attachment_tbl ",
+
+#ifdef __FEATURE_PARTIAL_BODY_DOWNLOAD__
+ "SELECT "
+ " account_id, "
+ " mail_id, "
+ " server_mail_id, "
+ " activity_id, "
+ " activity_type, "
+ " mailbox_name "
+ " FROM mail_partial_body_activity_tbl ",
+#endif
+
+ "SELECT "
+ " mail_id, "
+ " account_id, "
+ " mailbox_name, "
+ " meeting_response, "
+ " start_time, "
+ " end_time, "
+ " location, "
+ " global_object_id, "
+ " offset, "
+ " standard_name, "
+ " standard_time_start_date, "
+ " standard_bias, "
+ " daylight_name, "
+ " daylight_time_start_date, "
+ " daylight_bias "
+ " FROM mail_meeting_tbl ",
+
+#ifdef __LOCAL_ACTIVITY__
+ "SELECT "
+ " activity_id, "
+ " account_id, "
+ " mail_id, "
+ " activity_type, "
+ " server_mailid, "
+ " src_mbox , "
+ " dest_mbox "
+ " FROM mail_local_activity_tbl ",
+#endif
+ NULL,
+};
+
+
+/* ----------- Notification Changes ----------- */
+typedef enum
+{
+ _NOTI_TYPE_STORAGE,
+ _NOTI_TYPE_NETWORK
+} enotitype_t;
+
+
+EXPORT_API int em_storage_send_noti(enotitype_t notiType, int subType, int data1, int data2, char *data3, int data4)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ EM_PROFILE_BEGIN(profile_em_storage_send_noti);
+
+ int ret = 0;
+ DBusConnection *connection;
+ DBusMessage *signal = NULL;
+ DBusError dbus_error;
+ dbus_uint32_t error;
+ const char *nullString = "";
+
+ ENTER_CRITICAL_SECTION(_dbus_noti_lock);
+
+ dbus_error_init (&dbus_error);
+ connection = dbus_bus_get(DBUS_BUS_SYSTEM, &dbus_error);
+
+ if (connection == NULL) {
+ EM_DEBUG_LOG("dbus_bus_get is failed");
+ goto FINISH_OFF;
+ }
+
+ if (notiType == _NOTI_TYPE_STORAGE) {
+ signal = dbus_message_new_signal("/User/Email/StorageChange", EMF_STORAGE_CHANGE_NOTI, "email");
+
+ if (signal == NULL) {
+ EM_DEBUG_EXCEPTION("dbus_message_new_signal is failed");
+ goto FINISH_OFF;
+ }
+ EM_DEBUG_LOG("/User/Email/StorageChange Signal is created by dbus_message_new_signal");
+
+ dbus_message_append_args(signal, DBUS_TYPE_INT32, &subType, DBUS_TYPE_INVALID);
+ dbus_message_append_args(signal, DBUS_TYPE_INT32, &data1, DBUS_TYPE_INVALID);
+ dbus_message_append_args(signal, DBUS_TYPE_INT32, &data2, DBUS_TYPE_INVALID);
+ if (data3 == NULL)
+ dbus_message_append_args(signal, DBUS_TYPE_STRING, &nullString, DBUS_TYPE_INVALID);
+ else
+ dbus_message_append_args(signal, DBUS_TYPE_STRING, &data3, DBUS_TYPE_INVALID);
+ dbus_message_append_args(signal, DBUS_TYPE_INT32, &data4, DBUS_TYPE_INVALID);
+ }
+ else if (notiType == _NOTI_TYPE_NETWORK) {
+ signal = dbus_message_new_signal("/User/Email/NetworkStatus", EMF_NETOWRK_CHANGE_NOTI, "email");
+
+ if (signal == NULL) {
+ EM_DEBUG_EXCEPTION("dbus_message_new_signal is failed");
+ goto FINISH_OFF;
+ }
+
+ EM_DEBUG_LOG("/User/Email/NetworkStatus Signal is created by dbus_message_new_signal");
+
+ dbus_message_append_args(signal, DBUS_TYPE_INT32, &subType, DBUS_TYPE_INVALID);
+ dbus_message_append_args(signal, DBUS_TYPE_INT32, &data1, DBUS_TYPE_INVALID);
+ if (data3 == NULL)
+ dbus_message_append_args(signal, DBUS_TYPE_STRING, &nullString, DBUS_TYPE_INVALID);
+ else
+ dbus_message_append_args(signal, DBUS_TYPE_STRING, &data3, DBUS_TYPE_INVALID);
+ dbus_message_append_args(signal, DBUS_TYPE_INT32, &data2, DBUS_TYPE_INVALID);
+ dbus_message_append_args(signal, DBUS_TYPE_INT32, &data4, DBUS_TYPE_INVALID);
+ }
+ else {
+ EM_DEBUG_EXCEPTION("Wrong notification type [%d]", notiType);
+ error = EMF_ERROR_IPC_CRASH;
+ goto FINISH_OFF;
+ }
+
+ if (!dbus_connection_send(connection, signal, &error)) {
+ EM_DEBUG_LOG("dbus_connection_send is failed [%d]", error);
+ }
+ else {
+ EM_DEBUG_LOG("dbus_connection_send is successful");
+ ret = 1;
+ }
+
+/* EM_DEBUG_LOG("Before dbus_connection_flush"); */
+/* dbus_connection_flush(connection); */
+/* EM_DEBUG_LOG("After dbus_connection_flush"); */
+
+ ret = true;
+FINISH_OFF:
+ if (signal)
+ dbus_message_unref(signal);
+
+ LEAVE_CRITICAL_SECTION(_dbus_noti_lock);
+ EM_PROFILE_END(profile_em_storage_send_noti);
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+
+EXPORT_API int em_storage_notify_storage_event(emf_noti_on_storage_event transaction_type, int data1, int data2 , char *data3, int data4)
+{
+ EM_DEBUG_FUNC_BEGIN("transaction_type[%d], data1[%d], data2[%d], data3[%p], data4[%d]", transaction_type, data1, data2, data3, data4);
+ return em_storage_send_noti(_NOTI_TYPE_STORAGE, (int)transaction_type, data1, data2, data3, data4);
+}
+
+EXPORT_API int em_storage_notify_network_event(emf_noti_on_network_event status_type, int data1, char *data2, int data3, int data4)
+{
+ EM_DEBUG_FUNC_BEGIN("status_type[%d], data1[%d], data2[%p], data3[%d], data4[%d]", status_type, data1, data2, data3, data4);
+ return em_storage_send_noti(_NOTI_TYPE_NETWORK, (int)status_type, data1, data3, data2, data4);
+}
+
+/* ----------- Notification Changes End----------- */
+static int _getTableFieldDataChar(char **table, char *buf, int index)
+{
+ if ((table == NULL) || (buf == NULL) || (index < 0)) {
+ EM_DEBUG_EXCEPTION("table[%p], buf[%p], index[%d]", table, buf, index);
+ return false;
+ }
+
+ if (table[index] != NULL) {
+ *buf = (char)atoi(table[index]);
+ return true;
+ }
+
+ /* EM_DEBUG_LOG("Empty field. Set as zero"); */
+
+ *buf = 0;
+ return false;
+}
+
+static int _getTableFieldDataInt(char **table, int *buf, int index)
+{
+ if ((table == NULL) || (buf == NULL) || (index < 0)) {
+ EM_DEBUG_EXCEPTION("table[%p], buf[%p], index[%d]", table, buf, index);
+ return false;
+ }
+
+ if (table[index] != NULL) {
+ *buf = atoi(table[index]);
+ return true;
+ }
+
+ /* EM_DEBUG_LOG("Empty field. Set as zero"); */
+
+ *buf = 0;
+ return false;
+}
+
+static int _getTableFieldDataString(char **table, char **buf, int ucs2, int index)
+{
+ int ret = false;
+
+ if ((table == NULL) || (buf == NULL) || (index < 0)) {
+ EM_DEBUG_EXCEPTION("table[%p], buf[%p], index[%d]", table, buf, index);
+ return false;
+ }
+
+ char *pTemp = table[index];
+ int sLen = 0;
+ if (pTemp == NULL)
+ *buf = NULL;
+ else {
+ sLen = strlen(pTemp);
+ if(sLen) {
+ *buf = (char *) em_core_malloc(sLen + 1);
+ if (*buf == NULL) {
+ EM_DEBUG_EXCEPTION("malloc is failed");
+ goto FINISH_OFF;
+ }
+ strncpy(*buf, pTemp, sLen);
+ }
+ else
+ *buf = NULL;
+ }
+#ifdef _PRINT_STORAGE_LOG_
+ if (*buf)
+ EM_DEBUG_LOG("_getTableFieldDataString - buf[%s], index[%d]", *buf, index);
+ else
+ EM_DEBUG_LOG("_getTableFieldDataString - No string got ");
+#endif
+ ret = true;
+FINISH_OFF:
+
+ return ret;
+}
+
+static int
+_getTableFieldDataStringWithoutAllocation(char **table, char *buf, int buffer_size, int ucs2, int index)
+{
+ if ((table == NULL) || (buf == NULL) || (index < 0)) {
+ EM_DEBUG_EXCEPTION(" table[%p], buf[%p], index[%d]", table, buf, index);
+ return false;
+ }
+
+ char *pTemp = table[index];
+ if (pTemp == NULL)
+ buf = NULL;
+ else {
+ memset(buf, 0, buffer_size);
+ strncpy(buf, pTemp, buffer_size - 1);
+ }
+#ifdef _PRINT_STORAGE_LOG_
+ if (buf)
+ EM_DEBUG_LOG("_getTableFieldDataString - buf[%s], index[%d]", buf, index);
+ else
+ EM_DEBUG_LOG("_getTableFieldDataString - No string got ");
+#endif
+
+ return true;
+}
+
+static int _getStmtFieldDataChar(DB_STMT hStmt, char *buf, int index)
+{
+ if ((hStmt == NULL) || (buf == NULL) || (index < 0)) {
+ EM_DEBUG_EXCEPTION("buf[%p], index[%d]", buf, index);
+ return false;
+ }
+
+ if (sqlite3_column_text(hStmt, index) != NULL) {
+ *buf = (char)sqlite3_column_int(hStmt, index);
+#ifdef _PRINT_STORAGE_LOG_
+ EM_DEBUG_LOG("_getStmtFieldDataInt [%d]", *buf);
+#endif
+ return true;
+ }
+
+ EM_DEBUG_LOG("sqlite3_column_int fail. index [%d]", index);
+
+ return false;
+}
+
+static int _getStmtFieldDataInt(DB_STMT hStmt, int *buf, int index)
+{
+ if ((hStmt == NULL) || (buf == NULL) || (index < 0)) {
+ EM_DEBUG_EXCEPTION("buf[%p], index[%d]", buf, index);
+ return false;
+ }
+
+ if (sqlite3_column_text(hStmt, index) != NULL) {
+ *buf = sqlite3_column_int(hStmt, index);
+#ifdef _PRINT_STORAGE_LOG_
+ EM_DEBUG_LOG("_getStmtFieldDataInt [%d]", *buf);
+#endif
+ return true;
+ }
+
+ EM_DEBUG_LOG("sqlite3_column_int fail. index [%d]", index);
+
+ return false;
+}
+
+static int _getStmtFieldDataString(DB_STMT hStmt, char **buf, int ucs2, int index)
+{
+ if ((hStmt < 0) || (buf == NULL) || (index < 0)) {
+ EM_DEBUG_EXCEPTION("hStmt[%d], buf[%p], index[%d]", hStmt, buf, index);
+ return false;
+ }
+
+ int sLen = 0;
+ sLen = sqlite3_column_bytes(hStmt, index);
+
+#ifdef _PRINT_STORAGE_LOG_
+ EM_DEBUG_LOG("_getStmtFieldDataString sqlite3_column_bytes sLen[%d]", sLen);
+#endif
+
+ if (sLen > 0) {
+ *buf = (char *) em_core_malloc(sLen + 1);
+ strncpy(*buf, (char *)sqlite3_column_text(hStmt, index), sLen);
+ }
+ else
+ *buf = NULL;
+
+#ifdef _PRINT_STORAGE_LOG_
+ if (*buf)
+ EM_DEBUG_LOG("buf[%s], index[%d]", *buf, index);
+ else
+ EM_DEBUG_LOG("_getStmtFieldDataString - No string got");
+#endif
+
+ return false;
+}
+
+static int _getStmtFieldDataStringWithoutAllocation(DB_STMT hStmt, char *buf, int buffer_size, int ucs2, int index)
+{
+ if ((hStmt < 0) || (buf == NULL) || (index < 0)) {
+ EM_DEBUG_EXCEPTION("hStmt[%d], buf[%p], buffer_size[%d], index[%d]", hStmt, buf, buffer_size, index);
+ return false;
+ }
+
+ int sLen = 0;
+ sLen = sqlite3_column_bytes(hStmt, index);
+
+#ifdef _PRINT_STORAGE_LOG_
+ EM_DEBUG_LOG("_getStmtFieldDataStringWithoutAllocation sqlite3_column_bytes sLen[%d]", sLen);
+#endif
+
+ if (sLen > 0) {
+ memset(buf, 0, buffer_size);
+ strncpy(buf, (char *)sqlite3_column_text(hStmt, index), buffer_size - 1);
+ }
+ else
+ strcpy(buf, "");
+
+#ifdef _PRINT_STORAGE_LOG_
+ EM_DEBUG_LOG("buf[%s], index[%d]", buf, index);
+#endif
+
+ return false;
+}
+
+static int _bindStmtFieldDataChar(DB_STMT hStmt, int index, char value)
+{
+ if ((hStmt == NULL) || (index < 0)) {
+ EM_DEBUG_EXCEPTION("index[%d]", index);
+ return false;
+ }
+
+ int ret = sqlite3_bind_int(hStmt, index+1, (int)value);
+
+ if (ret != SQLITE_OK) {
+ EM_DEBUG_EXCEPTION("sqlite3_bind_int fail - %d", ret);
+ return false;
+ }
+
+ return true;
+}
+
+static int _bindStmtFieldDataInt(DB_STMT hStmt, int index, int value)
+{
+ if ((hStmt == NULL) || (index < 0)) {
+ EM_DEBUG_EXCEPTION("index[%d]", index);
+ return false;
+ }
+
+ int ret = sqlite3_bind_int(hStmt, index+1, value);
+
+ if (ret != SQLITE_OK) {
+ EM_DEBUG_EXCEPTION("sqlite3_bind_int fail - %d", ret);
+ return false;
+ }
+
+ return true;
+}
+
+static int _bindStmtFieldDataString(DB_STMT hStmt, int index, char *value, int ucs2, int max_len)
+{
+ if ((hStmt == NULL) || (index < 0)) {
+ EM_DEBUG_EXCEPTION("index[%d], max_len[%d]", index, max_len);
+ return false;
+ }
+
+#ifdef _PRINT_STORAGE_LOG_
+ EM_DEBUG_LOG("hStmt = %p, index = %d, max_len = %d, value = [%s]", hStmt, index, max_len, value);
+#endif
+
+ int ret = 0;
+ if (value != NULL)
+ ret = sqlite3_bind_text(hStmt, index+1, value, -1, SQLITE_STATIC);
+ else
+ ret = sqlite3_bind_text(hStmt, index+1, "", -1, NULL);
+
+ if (ret != SQLITE_OK) {
+ EM_DEBUG_EXCEPTION("sqlite3_bind_text fail [%d]", ret);
+ return false;
+ }
+ return true;
+}
+
+static int _emf_delete_temp_file(const char *path)
+{
+ EM_DEBUG_FUNC_BEGIN("path[%p]", path);
+
+ DIR *dp = NULL;
+ struct dirent *entry = NULL;
+
+ char buf[1024] = {0x00, };
+
+ if ((dp = opendir(path)) == NULL) {
+ EM_DEBUG_EXCEPTION("opendir(\"%s\") failed...", path);
+ return false;
+ }
+
+ while ((entry = readdir(dp)) != NULL) {
+ SNPRINTF(buf, sizeof(buf), "%s/%s", path, entry->d_name);
+ remove(buf);
+ }
+
+ closedir(dp);
+ EM_DEBUG_FUNC_END();
+ return true;
+}
+
+char *cpy_str(char *src)
+{
+ char *p = NULL;
+
+ if (src) {
+ if (!(p = em_core_malloc((int)strlen(src) + 1))) {
+ EM_DEBUG_EXCEPTION("mailoc failed...");
+ return NULL;
+ }
+ strncpy(p, src, strlen(src));
+ }
+
+ return p;
+}
+
+static void _em_storage_close_once(void)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ DELETE_CRITICAL_SECTION(_transactionBeginLock);
+ DELETE_CRITICAL_SECTION(_transactionEndLock);
+
+ EM_DEBUG_FUNC_END();
+}
+
+EXPORT_API int em_storage_close(int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ int ret = false;
+ int error = EM_STORAGE_ERROR_NONE;
+
+ em_storage_db_close(&error);
+
+ if (--_open_counter == 0)
+ _em_storage_close_once();
+
+ ret = true;
+
+ if (err_code != NULL)
+ *err_code = error;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+static void *_em_storage_open_once(int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ int error = EM_STORAGE_ERROR_NONE;
+
+ mkdir(EMAILPATH, DIRECTORY_PERMISSION);
+ mkdir(DATA_PATH, DIRECTORY_PERMISSION);
+
+ mkdir(MAILHOME, DIRECTORY_PERMISSION);
+
+ SNPRINTF(g_db_path, sizeof(g_db_path), "%s/%s", MAILHOME, MAILTEMP);
+ mkdir(g_db_path, DIRECTORY_PERMISSION);
+
+ _emf_delete_temp_file(g_db_path);
+
+ g_transaction = false;
+
+ if (!em_storage_create_table(EMF_CREATE_DB_NORMAL, &error)) {
+ EM_DEBUG_EXCEPTION(" em_storage_create_table failed - %d", error);
+ goto FINISH_OFF;
+ }
+
+FINISH_OFF:
+ if (err_code != NULL)
+ *err_code = error;
+
+
+ return NULL;
+}
+
+ /* pData : a parameter which is registered when busy handler is registerd */
+ /* count : retry count */
+#define EMF_STORAGE_MAX_RETRY_COUNT 20
+static int
+em_busy_handler(void *pData, int count)
+{
+ EM_DEBUG_LOG("Busy Handler Called!!: [%d]", count);
+ usleep(200000); /* sleep time when SQLITE_LOCK */
+
+ /* retry will be stopped if busy handler return 0 */
+ return EMF_STORAGE_MAX_RETRY_COUNT - count;
+}
+
+static int
+em_storage_delete_all_files_and_directories(int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ int error = EM_STORAGE_ERROR_NONE;
+ int ret = false;
+
+ if (!em_storage_delete_file(EMAIL_SERVICE_DB_FILE_PATH, &error)) {
+ if (error != EM_STORAGE_ERROR_FILE_NOT_FOUND) {
+ EM_DEBUG_EXCEPTION("remove failed - %s", EMAIL_SERVICE_DB_FILE_PATH);
+ goto FINISH_OFF;
+ }
+ }
+
+ if (!em_storage_delete_dir(MAILHOME, &error)) {
+ EM_DEBUG_EXCEPTION("em_storage_delete_dir failed");
+ goto FINISH_OFF;
+ }
+
+ ret = true;
+
+FINISH_OFF:
+ if (err_code)
+ *err_code = error;
+ EM_DEBUG_FUNC_END();
+ return ret;
+}
+
+static int
+em_storage_recovery_from_malformed_db_file(int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ int error = EM_STORAGE_ERROR_NONE;
+ int ret = false;
+
+ /* Delete all files and directories */
+ if (!em_storage_delete_all_files_and_directories(&error)) {
+ EM_DEBUG_EXCEPTION("em_storage_delete_all_files_and_directories failed [%d]", error);
+ goto FINISH_OFF;
+ }
+
+ /* Delete all accounts on MyAccount */
+
+ /* Delete all managed connection to DB */
+ em_storage_reset_db_handle_list();
+
+ ret = true;
+
+FINISH_OFF:
+ if (err_code)
+ *err_code = error;
+ EM_DEBUG_FUNC_END();
+ return ret;
+}
+
+
+EXPORT_API int em_db_open(sqlite3 **sqlite_handle, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int rc = 0;
+ int error = EM_STORAGE_ERROR_NONE;
+ int ret = false;
+
+ EM_DEBUG_LOG("*sqlite_handle[%p]", *sqlite_handle);
+
+ if (NULL == *sqlite_handle) {
+ /* db open */
+ EM_DEBUG_LOG("Open DB");
+ EM_STORAGE_PROTECTED_FUNC_CALL(db_util_open(EMAIL_SERVICE_DB_FILE_PATH, sqlite_handle, DB_UTIL_REGISTER_HOOK_METHOD), rc);
+ if (SQLITE_OK != rc) {
+ EM_DEBUG_EXCEPTION("db_util_open fail:%d -%s", rc, sqlite3_errmsg(*sqlite_handle));
+ error = EM_STORAGE_ERROR_DB_FAILURE;
+ db_util_close(*sqlite_handle);
+ *sqlite_handle = NULL;
+
+ if (SQLITE_CORRUPT == rc) /* SQLITE_CORRUPT : The database disk image is malformed */ {/* Recovery DB file */
+ EM_DEBUG_LOG("The database disk image is malformed. Trying to remove and create database disk image and directories");
+ if (!em_storage_recovery_from_malformed_db_file(&error)) {
+ EM_DEBUG_EXCEPTION("em_storage_recovery_from_malformed_db_file failed [%d]", error);
+ goto FINISH_OFF;
+ }
+
+ EM_DEBUG_LOG("Open DB again");
+ EM_STORAGE_PROTECTED_FUNC_CALL(db_util_open(EMAIL_SERVICE_DB_FILE_PATH, sqlite_handle, DB_UTIL_REGISTER_HOOK_METHOD), rc);
+ if (SQLITE_OK != rc) {
+ EM_DEBUG_EXCEPTION("db_util_open fail:%d -%s", rc, sqlite3_errmsg(*sqlite_handle));
+ error = EM_STORAGE_ERROR_DB_FAILURE;
+ db_util_close(*sqlite_handle);
+ *sqlite_handle = NULL;
+ }
+ }
+ else
+ goto FINISH_OFF;
+ }
+ EM_DEBUG_LOG(">>>>> DB Handle : *sqlite_handle[%p]", *sqlite_handle);
+
+ /* register busy handler */
+ EM_DEBUG_LOG(">>>>> Register busy handler.....");
+ rc = sqlite3_busy_handler(*sqlite_handle, em_busy_handler, NULL); /* Busy Handler registration, NULL is a parameter which will be passed to handler */
+ if (SQLITE_OK != rc) {
+ EM_DEBUG_EXCEPTION("sqlite3_busy_handler fail:%d -%s", rc, sqlite3_errmsg(*sqlite_handle));
+ error = EM_STORAGE_ERROR_DB_FAILURE;
+ db_util_close(*sqlite_handle);
+ *sqlite_handle = NULL;
+ goto FINISH_OFF;
+ }
+ }
+ else {
+ EM_DEBUG_LOG(">>>>> DB Already Opened......");
+ }
+
+ ret = true;
+
+FINISH_OFF:
+ if (err_code != NULL)
+ *err_code = error;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+EXPORT_API sqlite3* em_storage_db_open(int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN();
+#ifdef _MULTIPLE_DB_HANDLE
+ sqlite3 *_db_handle = NULL;
+#endif
+
+ int error = EM_STORAGE_ERROR_NONE;
+
+ em_storage_shm_mutex_init(SHM_FILE_FOR_DB_LOCK, &shm_fd_for_db_lock, &mapped_for_db_lock);
+
+#ifdef __FEATURE_USE_SHARED_MUTEX_FOR_GENERATING_MAIL_ID__
+ em_storage_shm_mutex_init(SHM_FILE_FOR_MAIL_ID_LOCK, &shm_fd_for_generating_mail_id, &mapped_for_generating_mail_id);
+#endif /*__FEATURE_USE_SHARED_MUTEX_FOR_GENERATING_MAIL_ID__ */
+
+ if (!em_db_open(&_db_handle, &error)) {
+ EM_DEBUG_EXCEPTION("em_db_open failed[%d]", error);
+ goto FINISH_OFF;
+ }
+
+#ifdef _MULTIPLE_DB_HANDLE
+ em_storage_set_db_handle(_db_handle);
+#endif
+
+FINISH_OFF:
+ if (err_code != NULL)
+ *err_code = error;
+
+ EM_DEBUG_FUNC_END("ret [%p]", _db_handle);
+ return _db_handle;
+}
+
+EXPORT_API int em_storage_db_close(int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN();
+#ifdef _MULTIPLE_DB_HANDLE
+ sqlite3 *_db_handle = em_storage_get_db_handle();
+#endif
+
+ int error = EM_STORAGE_ERROR_NONE;
+ int ret = false;
+
+ DELETE_CRITICAL_SECTION(_transactionBeginLock);
+ DELETE_CRITICAL_SECTION(_transactionEndLock);
+ DELETE_CRITICAL_SECTION(_dbus_noti_lock);
+
+ if (_db_handle) {
+ ret = db_util_close(_db_handle);
+
+ if (ret != SQLITE_OK) {
+ EM_DEBUG_EXCEPTION(" db_util_close fail - %d", ret);
+ error = EM_STORAGE_ERROR_DB_FAILURE;
+ ret = false;
+ goto FINISH_OFF;
+ }
+#ifdef _MULTIPLE_DB_HANDLE
+ em_storage_remove_db_handle();
+#endif
+ _db_handle = NULL;
+ }
+
+ ret = true;
+
+FINISH_OFF:
+ if (err_code != NULL)
+ *err_code = error;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+
+EXPORT_API int em_storage_open(int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ int ret = false;
+ int error = EM_STORAGE_ERROR_NONE;
+
+ int retValue;
+
+ retValue = mkdir(DB_PATH, DIRECTORY_PERMISSION);
+
+ EM_DEBUG_LOG("mkdir return- %d", retValue);
+ EM_DEBUG_LOG("em_storage_open - before db_util_open - pid = %d", getpid());
+
+ if (em_storage_db_open(&error) == NULL) {
+ EM_DEBUG_EXCEPTION("em_storage_db_open failed[%d]", error);
+ goto FINISH_OFF;
+ }
+
+
+ if (_open_counter++ == 0)
+ _em_storage_open_once(&error);
+
+ ret = true;
+
+FINISH_OFF:
+ if (err_code != NULL)
+ *err_code = error;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+
+EXPORT_API int em_storage_create_table(emf_create_db_t type, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ int error = EM_STORAGE_ERROR_NONE;
+ int rc = -1, ret = false;
+ char sql_query_string[QUERY_SIZE] = {0, };
+ char *create_table_query[] =
+{
+ /* 1. create mail_account_tbl */
+ "CREATE TABLE mail_account_tbl \n"
+ "(\n"
+ " account_bind_type INTEGER \n"
+ ", account_name VARCHAR(51) \n"
+ ", receiving_server_type INTEGER \n"
+ ", receiving_server_addr VARCHAR(51) \n"
+ ", email_addr VARCHAR(129) \n"
+ ", user_name VARCHAR(51) \n"
+ ", password VARCHAR(51) \n"
+ ", retrieval_mode INTEGER \n"
+ ", port_num INTEGER \n"
+ ", use_security INTEGER \n"
+ ", sending_server_type INTEGER \n"
+ ", sending_server_addr VARCHAR(51) \n"
+ ", sending_port_num INTEGER \n"
+ ", sending_auth INTEGER \n"
+ ", sending_security INTEGER \n"
+ ", sending_user VARCHAR(51) \n"
+ ", sending_password VARCHAR(51) \n"
+ ", display_name VARCHAR(31) \n"
+ ", reply_to_addr VARCHAR(129) \n"
+ ", return_addr VARCHAR(129) \n"
+ ", account_id INTEGER PRIMARY KEY \n"
+ ", keep_on_server INTEGER \n"
+ ", flag1 INTEGER \n"
+ ", flag2 INTEGER \n"
+ ", pop_before_smtp INTEGER \n" /* POP before SMTP authentication */
+ ", apop INTEGER \n" /* APOP authentication */
+ ", logo_icon_path VARCHAR(256) \n" /* Receiving Option : Account logo icon */
+ ", preset_account INTEGER \n" /* Receiving Option : Preset account or not */
+ ", target_storage INTEGER \n" /* Receiving Option : Specifies the targetStorage. 0 is phone, 1 is MMC */
+ ", check_interval INTEGER \n" /* Receiving Option : Specifies the check interval. Unit is minute */
+ ", priority INTEGER \n" /* Sending Option : Specifies the prority. 1=high 3=normal 5=low */
+ ", keep_local_copy INTEGER \n" /* Sending Option : */
+ ", req_delivery_receipt INTEGER \n" /* Sending Option : */
+ ", req_read_receipt INTEGER \n" /* Sending Option : */
+ ", download_limit INTEGER \n" /* Sending Option : */
+ ", block_address INTEGER \n" /* Sending Option : */
+ ", block_subject INTEGER \n" /* Sending Option : */
+ ", display_name_from VARCHAR(256) \n" /* Sending Option : */
+ ", reply_with_body INTEGER \n" /* Sending Option : */
+ ", forward_with_files INTEGER \n" /* Sending Option : */
+ ", add_myname_card INTEGER \n" /* Sending Option : */
+ ", add_signature INTEGER \n" /* Sending Option : */
+ ", signature VARCHAR(256) \n" /* Sending Option : */
+ ", add_my_address_to_bcc INTEGER \n" /* Sending Option : */
+ ", my_account_id INTEGER \n" /* My Account Id */
+ ", index_color INTEGER \n" /* Index color */
+ ", sync_status INTEGER \n" /* Sync Status */
+ ");",
+ /* 2. create mail_box_tbl */
+ "CREATE TABLE mail_box_tbl \n"
+ "(\n"
+ " mailbox_id INTEGER \n"
+ ", account_id INTEGER \n"
+ ", local_yn INTEGER \n"
+ ", mailbox_name VARCHAR(256) \n"
+ ", mailbox_type INTEGER \n"
+ ", alias VARCHAR(256) \n"
+ ", sync_with_server_yn INTEGER \n"
+ ", modifiable_yn INTEGER \n"
+ ", total_mail_count_on_server INTEGER \n"
+ ", has_archived_mails INTEGER \n"
+ ", mail_slot_size INTEGER \n"
+ "); \n ",
+
+ /* 3. create mail_read_mail_uid_tbl */
+ "CREATE TABLE mail_read_mail_uid_tbl \n"
+ "(\n"
+ " account_id INTEGER \n"
+ ", local_mbox VARCHAR(129) \n"
+ ", local_uid INTEGER \n"
+ ", mailbox_name VARCHAR(256) \n"
+ ", s_uid VARCHAR(129) \n"
+ ", data1 INTEGER \n"
+ ", data2 VARCHAR(257) \n"
+ ", flag INTEGER \n"
+ ", idx_num INTEGER PRIMARY KEY \n"
+ "); \n",
+ /* 4. create mail_rule_tbl */
+ "CREATE TABLE mail_rule_tbl \n"
+ "(\n"
+ " account_id INTEGER \n"
+ ", rule_id INTEGER PRIMARY KEY\n"
+ ", type INTEGER \n"
+ ", value VARCHAR(257) \n"
+ ", action_type INTEGER \n"
+ ", dest_mailbox VARCHAR(129) \n"
+ ", flag1 INTEGER \n"
+ ", flag2 INTEGER \n"
+ "); \n ",
+ /* 5. create mail_tbl */
+ "CREATE TABLE mail_tbl \n"
+ "(\n"
+ " mail_id INTEGER PRIMARY KEY \n"
+ ", account_id INTEGER \n"
+ ", mailbox_name VARCHAR(129) \n"
+ ", mailbox_type INTEGER \n"
+ ", subject UCS2TEXT\ n"
+ ", date_time VARCHAR(129) \n" /* type change to int or datetime. */
+ ", server_mail_status INTEGER \n"
+ ", server_mailbox_name VARCHAR(129) \n"
+ ", server_mail_id VARCHAR(129) \n"
+ ", message_id VARCHAR(257) \n"
+ ", full_address_from UCS2TEXT \n"
+ ", full_address_reply UCS2TEXT \n"
+ ", full_address_to UCS2TEXT \n"
+ ", full_address_cc UCS2TEXT \n"
+ ", full_address_bcc UCS2TEXT \n"
+ ", full_address_return UCS2TEXT \n"
+ ", email_address_sender UCS2TEXT collation user1 \n"
+ ", email_address_recipient UCS2TEXT collation user1 \n"
+ ", alias_sender UCS2TEXT \n"
+ ", alias_recipient UCS2TEXT \n"
+ ", body_download_status INTEGER \n"
+ ", file_path_plain VARCHAR(257) \n"
+ ", file_path_html VARCHAR(257) \n"
+ ", mail_size INTEGER \n"
+ ", flags_seen_field BOOLEAN \n"
+ ", flags_deleted_field BOOLEAN \n"
+ ", flags_flagged_field BOOLEAN \n"
+ ", flags_answered_field BOOLEAN \n"
+ ", flags_recent_field BOOLEAN \n"
+ ", flags_draft_field BOOLEAN \n"
+ ", flags_forwarded_field BOOLEAN \n"
+ ", DRM_status INTEGER \n"
+ ", priority INTEGER \n"
+ ", save_status INTEGER \n"
+ ", lock_status INTEGER \n"
+ ", report_status INTEGER \n"
+ ", attachment_count INTEGER \n"
+ ", inline_content_count INTEGER \n"
+ ", thread_id INTEGER \n"
+ ", thread_item_count INTEGER \n"
+ ", preview_text UCS2TEXT \n"
+ ", meeting_request_status INTEGER \n"
+ ", FOREIGN KEY(account_id) REFERENCES mail_account_tbl(account_id) \n"
+ "); \n ",
+
+ /* 6. create mail_attachment_tbl */
+ "CREATE TABLE mail_attachment_tbl \n"
+ "(\n"
+ " attachment_id INTEGER PRIMARY KEY"
+ ", attachment_name VARCHAR(257) \n"
+ ", attachment_path VARCHAR(257) \n"
+ ", attachment_size INTEGER \n"
+ ", mail_id INTEGER \n"
+ ", account_id INTEGER \n"
+ ", mailbox_name VARCHAR(129) \n"
+ ", file_yn INTEGER \n"
+ ", flag1 INTEGER \n"
+ ", flag2 INTEGER \n"
+ ", flag3 INTEGER \n"
+#ifdef __ATTACHMENT_OPTI__
+ ", encoding INTEGER \n"
+ ", section varchar(257) \n"
+#endif
+ "); \n ",
+
+#ifdef __FEATURE_PARTIAL_BODY_DOWNLOAD__
+
+ "CREATE TABLE mail_partial_body_activity_tbl \n"
+ "( \n"
+ " account_id INTEGER \n"
+ ", mail_id INTEGER \n"
+ ", server_mail_id INTEGER \n"
+ ", activity_id INTEGER PRIMARY KEY \n"
+ ", activity_type INTEGER \n"
+ ", mailbox_name VARCHAR(4000) \n"
+ "); \n ",
+#endif
+
+ "CREATE TABLE mail_meeting_tbl \n"
+ "(\n"
+ " mail_id INTEGER PRIMARY KEY \n"
+ ", account_id INTEGER \n"
+ ", mailbox_name UCS2TEXT \n"
+ ", meeting_response INTEGER \n"
+ ", start_time INTEGER \n"
+ ", end_time INTEGER \n"
+ ", location UCS2TEXT \n"
+ ", global_object_id UCS2TEXT \n"
+ ", offset INTEGER \n"
+ ", standard_name UCS2TEXT \n"
+ ", standard_time_start_date INTEGER \n"
+ ", standard_bias INTEGER \n"
+ ", daylight_name UCS2TEXT \n"
+ ", daylight_time_start_date INTEGER \n"
+ ", daylight_bias INTEGER \n"
+ "); \n ",
+
+#ifdef __LOCAL_ACTIVITY__
+ "CREATE TABLE mail_local_activity_tbl \n"
+ "( \n"
+ " activity_id INTEGER \n"
+ ", account_id INTEGER \n"
+ ", mail_id INTEGER \n"
+ ", activity_type INTEGER \n"
+ ", server_mailid VARCHAR(129) \n"
+ ", src_mbox VARCHAR(129) \n"
+ ", dest_mbox VARCHAR(129) \n"
+ "); \n ",
+#endif
+ NULL,
+};
+
+ sqlite3 *local_db_handle = em_storage_get_db_connection();
+
+ EM_DEBUG_LOG("local_db_handle = %p.", local_db_handle);
+
+ char *sql;
+ char **result;
+
+ sql = "SELECT count(name) FROM sqlite_master WHERE name='mail_account_tbl';";
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql, &result, NULL, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {goto FINISH_OFF; },
+ ("SQL(%s) sqlite3_get_table fail:%d -%s", sql, rc, sqlite3_errmsg(local_db_handle)));
+
+ EM_DEBUG_LOG("em_storage_create_table - result[1] = %s %c", result[1], result[1]);
+
+ if (atoi(result[1]) < 1) {
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, "BEGIN;", NULL, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {goto FINISH_OFF; },
+ ("SQL(BEGIN EXCLUSIVE) exec fail:%d -%s", rc, sqlite3_errmsg(local_db_handle)));
+
+ EM_DEBUG_LOG("CREATE TABLE mail_account_tbl");
+
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), create_table_query[CREATE_TABLE_MAIL_ACCOUNT_TBL]);
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; }, ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ /* create mail_account_tbl unique index */
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), "CREATE UNIQUE INDEX mail_account_idx1 ON mail_account_tbl (account_bind_type, account_id)");
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; }, ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, "END;", NULL, NULL, NULL), rc);
+
+ } /* mail_account_tbl */
+ else if (type == EMF_CREATE_DB_CHECK) {
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, g_test_query[CREATE_TABLE_MAIL_ACCOUNT_TBL], NULL, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; }, ("SQL(%s) exec fail:%d -%s", g_test_query[CREATE_TABLE_MAIL_ACCOUNT_TBL], rc, sqlite3_errmsg(local_db_handle)));
+ }
+
+ sqlite3_free_table(result);
+
+
+ /* 2. create mail_box_tbl */
+ sql = "SELECT count(name) FROM sqlite_master WHERE name='mail_box_tbl';";
+ /* rc = sqlite3_get_table(local_db_handle, sql, &result, NULL, NULL, NULL); */
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql, &result, NULL, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {goto FINISH_OFF; },
+ ("SQL(%s) sqlite3_get_table fail:%d -%s", sql, rc, sqlite3_errmsg(local_db_handle)));
+
+ if (atoi(result[1]) < 1) {
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, "BEGIN;", NULL, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {goto FINISH_OFF; },
+ ("SQL(BEGIN EXCLUSIVE) exec fail:%d -%s", rc, sqlite3_errmsg(local_db_handle)));
+
+ EM_DEBUG_LOG("CREATE TABLE mail_box_tbl");
+
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), create_table_query[CREATE_TABLE_MAIL_BOX_TBL]);
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ /* create mail_local_mailbox_tbl unique index */
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), "CREATE UNIQUE INDEX mail_box_idx1 ON mail_box_tbl (account_id, local_yn, mailbox_name)");
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, "END;", NULL, NULL, NULL), rc);
+
+ } /* mail_box_tbl */
+ else if (type == EMF_CREATE_DB_CHECK) {
+ rc = sqlite3_exec(local_db_handle, g_test_query[CREATE_TABLE_MAIL_BOX_TBL], NULL, NULL, NULL);
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) exec fail:%d -%s", g_test_query[CREATE_TABLE_MAIL_BOX_TBL], rc, sqlite3_errmsg(local_db_handle)));
+ }
+ sqlite3_free_table(result);
+
+ /* 3. create mail_read_mail_uid_tbl */
+ sql = "SELECT count(name) FROM sqlite_master WHERE name='mail_read_mail_uid_tbl';";
+ /* rc = sqlite3_get_table(local_db_handle, sql, &result, NULL, NULL, NULL); */
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql, &result, NULL, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {goto FINISH_OFF; },
+ ("SQL(%s) sqlite3_get_table fail:%d -%s", sql, rc, sqlite3_errmsg(local_db_handle)));
+
+
+ if (atoi(result[1]) < 1) {
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, "BEGIN;", NULL, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {goto FINISH_OFF; },
+ ("SQL(BEGIN EXCLUSIVE) exec fail:%d -%s", rc, sqlite3_errmsg(local_db_handle)));
+
+ EM_DEBUG_LOG("CREATE TABLE mail_read_mail_uid_tbl");
+
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), create_table_query[CREATE_TABLE_MAIL_READ_MAIL_UID_TBL]);
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ /* create mail_read_mail_uid_tbl unique index */
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), "CREATE UNIQUE INDEX mail_read_mail_uid_idx1 ON mail_read_mail_uid_tbl (account_id, local_mbox, local_uid, mailbox_name, s_uid)");
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, "END;", NULL, NULL, NULL), rc);
+
+ } /* mail_read_mail_uid_tbl */
+ else if (type == EMF_CREATE_DB_CHECK) {
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, g_test_query[CREATE_TABLE_MAIL_READ_MAIL_UID_TBL], NULL, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) exec fail:%d -%s", g_test_query[CREATE_TABLE_MAIL_READ_MAIL_UID_TBL], rc, sqlite3_errmsg(local_db_handle)));
+ }
+ sqlite3_free_table(result);
+
+
+ /* 4. create mail_rule_tbl */
+ sql = "SELECT count(name) FROM sqlite_master WHERE name='mail_rule_tbl';";
+ /* rc = sqlite3_get_table(local_db_handle, sql, &result, NULL, NULL, NULL); */
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql, &result, NULL, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {goto FINISH_OFF; },
+ ("SQL(%s) sqlite3_get_table fail:%d -%s", sql, rc, sqlite3_errmsg(local_db_handle)));
+
+ if (atoi(result[1]) < 1) {
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, "BEGIN;", NULL, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {goto FINISH_OFF; },
+ ("SQL(BEGIN EXCLUSIVE) exec fail:%d -%s", rc, sqlite3_errmsg(local_db_handle)));
+
+ EM_DEBUG_LOG("CREATE TABLE mail_rule_tbl");
+
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), create_table_query[CREATE_TABLE_MAIL_RULE_TBL]);
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, "END;", NULL, NULL, NULL), rc);
+
+ } /* mail_rule_tbl */
+ else if (type == EMF_CREATE_DB_CHECK) {
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, g_test_query[CREATE_TABLE_MAIL_RULE_TBL], NULL, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) exec fail:%d -%s", g_test_query[CREATE_TABLE_MAIL_RULE_TBL], rc, sqlite3_errmsg(local_db_handle)));
+ }
+ sqlite3_free_table(result);
+
+
+ /* 5. create mail_tbl */
+ sql = "SELECT count(name) FROM sqlite_master WHERE name='mail_tbl';";
+ /* rc = sqlite3_get_table(local_db_handle, sql, &result, NULL, NULL, NULL); */
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql, &result, NULL, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {goto FINISH_OFF; },
+ ("SQL(%s) sqlite3_get_table fail:%d -%s", sql, rc, sqlite3_errmsg(local_db_handle)));
+
+ if (atoi(result[1]) < 1) {
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, "BEGIN;", NULL, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {goto FINISH_OFF; },
+ ("SQL(BEGIN EXCLUSIVE) exec fail:%d -%s", rc, sqlite3_errmsg(local_db_handle)));
+ EM_DEBUG_LOG("CREATE TABLE mail_tbl");
+
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), create_table_query[CREATE_TABLE_MAIL_TBL]);
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ /* create mail_tbl unique index */
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), "CREATE UNIQUE INDEX mail_idx1 ON mail_tbl (mail_id, account_id)");
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ /* create mail_tbl index for date_time */
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), "CREATE INDEX mail_idx_date_time ON mail_tbl (date_time)");
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ /* create mail_tbl index for thread_item_count */
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), "CREATE INDEX mail_idx_thread_mail_count ON mail_tbl (thread_item_count)");
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, "END;", NULL, NULL, NULL), rc);
+
+ /* just one time call */
+/* EFTSInitFTSIndex(FTS_EMAIL_IDX); */
+ } /* mail_tbl */
+ else if (type == EMF_CREATE_DB_CHECK) {
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, g_test_query[CREATE_TABLE_MAIL_TBL], NULL, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) exec fail:%d -%s", g_test_query[CREATE_TABLE_MAIL_TBL], rc, sqlite3_errmsg(local_db_handle)));
+ }
+ sqlite3_free_table(result);
+
+
+ /* 6. create mail_attachment_tbl */
+ sql = "SELECT count(name) FROM sqlite_master WHERE name='mail_attachment_tbl';";
+ /* rc = sqlite3_get_table(local_db_handle, sql, &result, NULL, NULL, NULL); */
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql, &result, NULL, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {goto FINISH_OFF; },
+ ("SQL(%s) sqlite3_get_table fail:%d -%s", sql, rc, sqlite3_errmsg(local_db_handle)));
+
+ if (atoi(result[1]) < 1) {
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, "BEGIN;", NULL, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {goto FINISH_OFF; },
+ ("SQL(BEGIN EXCLUSIVE) exec fail:%d -%s", rc, sqlite3_errmsg(local_db_handle)));
+ EM_DEBUG_LOG("CREATE TABLE mail_attachment_tbl");
+
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), create_table_query[CREATE_TABLE_MAIL_ATTACHMENT_TBL]);
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ /* create mail_attachment_tbl unique index */
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), "CREATE UNIQUE INDEX mail_attachment_idx1 ON mail_attachment_tbl (mail_id, attachment_id) ");
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, "END;", NULL, NULL, NULL), rc);
+
+ } /* mail_attachment_tbl */
+ else if (type == EMF_CREATE_DB_CHECK) {
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, g_test_query[CREATE_TABLE_MAIL_ATTACHMENT_TBL], NULL, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) exec fail:%d -%s", g_test_query[CREATE_TABLE_MAIL_ATTACHMENT_TBL], rc, sqlite3_errmsg(local_db_handle)));
+ }
+ sqlite3_free_table(result);
+
+#ifdef __FEATURE_PARTIAL_BODY_DOWNLOAD__
+
+ sql = "SELECT count(name) FROM sqlite_master WHERE name='mail_partial_body_activity_tbl';";
+ /* rc = sqlite3_get_table(local_db_handle, sql, &result, NULL, NULL, NULL); */
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql, &result, NULL, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {goto FINISH_OFF; },
+ ("SQL(%s) sqlite3_get_table fail:%d -%s", sql, rc, sqlite3_errmsg(local_db_handle)));
+
+ if (atoi(result[1]) < 1) {
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, "BEGIN;", NULL, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {goto FINISH_OFF; },
+ ("SQL(BEGIN EXCLUSIVE) exec fail:%d -%s", rc, sqlite3_errmsg(local_db_handle)));
+
+ EM_DEBUG_LOG("CREATE TABLE mail_partial_body_activity_tbl");
+
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), create_table_query[CREATE_TABLE_MAIL_PARTIAL_BODY_ACTIVITY_TBL]);
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, "END;", NULL, NULL, NULL), rc);
+
+ } /* mail_rule_tbl */
+ else if (type == EMF_CREATE_DB_CHECK) {
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, g_test_query[CREATE_TABLE_MAIL_PARTIAL_BODY_ACTIVITY_TBL], NULL, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) exec fail:%d -%s", g_test_query[CREATE_TABLE_MAIL_PARTIAL_BODY_ACTIVITY_TBL], rc, sqlite3_errmsg(local_db_handle)));
+ }
+ sqlite3_free_table(result);
+
+#endif /* __FEATURE_PARTIAL_BODY_DOWNLOAD__ */
+
+ /* create mail_meeting_tbl */
+ sql = "SELECT count(name) FROM sqlite_master WHERE name='mail_meeting_tbl';";
+ /* rc = sqlite3_get_table(local_db_handle, sql, &result, NULL, NULL, NULL); */
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql, &result, NULL, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {goto FINISH_OFF; },
+ ("SQL(%s) sqlite3_get_table fail:%d -%s", sql, rc, sqlite3_errmsg(local_db_handle)));
+
+ if (atoi(result[1]) < 1) {
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, "BEGIN;", NULL, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {goto FINISH_OFF; },
+ ("SQL(BEGIN EXCLUSIVE) exec fail:%d -%s", rc, sqlite3_errmsg(local_db_handle)));
+
+ EM_DEBUG_LOG("CREATE TABLE mail_meeting_tbl");
+
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), create_table_query[CREATE_TABLE_MAIL_MEETING_TBL]);
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), "CREATE UNIQUE INDEX mail_meeting_idx1 ON mail_meeting_tbl (mail_id)");
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, "END;", NULL, NULL, NULL), rc);
+
+ } /* mail_contact_sync_tbl */
+ else if (type == EMF_CREATE_DB_CHECK) {
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, g_test_query[CREATE_TABLE_MAIL_MEETING_TBL], NULL, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) exec fail:%d -%s", g_test_query[CREATE_TABLE_MAIL_MEETING_TBL], rc, sqlite3_errmsg(local_db_handle)));
+ }
+ sqlite3_free_table(result);
+
+#ifdef __LOCAL_ACTIVITY__
+
+ sql = "SELECT count(name) FROM sqlite_master WHERE name='mail_local_activity_tbl';";
+ /* rc = sqlite3_get_table(local_db_handle, sql, &result, NULL, NULL, NULL); */
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql, &result, NULL, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {goto FINISH_OFF; },
+ ("SQL(%s) sqlite3_get_table fail:%d -%s", sql, rc, sqlite3_errmsg(local_db_handle)));
+
+ if (atoi(result[1]) < 1) {
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, "BEGIN;", NULL, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {goto FINISH_OFF; },
+ ("SQL(BEGIN EXCLUSIVE) exec fail:%d -%s", rc, sqlite3_errmsg(local_db_handle)));
+
+ EM_DEBUG_LOG(" CREATE TABLE mail_local_activity_tbl");
+
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), create_table_query[CREATE_TABLE_MAIL_LOCAL_ACTIVITY_TBL]);
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, "END;", NULL, NULL, NULL), rc);
+
+ } /* mail_rule_tbl */
+ else if (type == EMF_CREATE_DB_CHECK) {
+ rc = sqlite3_exec(local_db_handle, g_test_query[CREATE_TABLE_MAIL_LOCAL_ACTIVITY_TBL], NULL, NULL, NULL);
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, g_test_query[CREATE_TABLE_MAIL_LOCAL_ACTIVITY_TBL], NULL, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) exec fail:%d -%s", g_test_query[CREATE_TABLE_MAIL_LOCAL_ACTIVITY_TBL], rc, sqlite3_errmsg(local_db_handle)));
+ }
+ sqlite3_free_table(result);
+
+#endif /* __LOCAL_ACTIVITY__ */
+
+ ret = true;
+
+FINISH_OFF:
+ if (ret == true) {
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, "END;", NULL, NULL, NULL), rc);
+ }
+ else {
+ /* sqlite3_exec(local_db_handle, "rollback", NULL, NULL, NULL); */
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, "rollback", NULL, NULL, NULL), rc);
+ }
+
+ _DISCONNECT_DB;
+
+ if (err_code != NULL)
+ *err_code = error;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+/* Query series --------------------------------------------------------------*/
+
+EXPORT_API int em_storage_query_mail_list(const char *conditional_clause, int transaction, emf_mail_list_item_t** result_mail_list, int *result_count, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ EM_PROFILE_BEGIN(em_storage_query_mail_list_func);
+
+ int i = 0, count = 0, rc = -1, to_get_count = (result_mail_list)?0:1;
+ int local_inline_content_count = 0, local_attachment_count = 0;
+ int cur_query = 0, base_count = 0, col_index;
+ int ret = false, error = EM_STORAGE_ERROR_NONE;
+ emf_mail_list_item_t *mail_list_item_from_tbl = NULL;
+ char **result = NULL, sql_query_string[QUERY_SIZE] = {0, };
+ char *field_list = "mail_id, account_id, mailbox_name, full_address_from, email_address_sender, full_address_to, subject, body_download_status, flags_seen_field, flags_deleted_field, flags_flagged_field, flags_answered_field, flags_recent_field, flags_draft_field, flags_forwarded_field, DRM_status, priority, save_status, lock_status, attachment_count, inline_content_count, date_time, preview_text, thread_id, thread_item_count, meeting_request_status ";
+ sqlite3 *local_db_handle = em_storage_get_db_connection();
+
+ EM_IF_NULL_RETURN_VALUE(conditional_clause, false);
+ EM_IF_NULL_RETURN_VALUE(result_count, false);
+
+ EM_STORAGE_START_READ_TRANSACTION(transaction);
+
+ /* select clause */
+ if (to_get_count) /* count only */
+ cur_query += SNPRINTF_OFFSET(sql_query_string, cur_query, QUERY_SIZE, "SELECT count(*) FROM mail_tbl");
+ else /* mail list in plain form */
+ cur_query += SNPRINTF_OFFSET(sql_query_string, cur_query, QUERY_SIZE, "SELECT %s FROM mail_tbl ", field_list);
+
+ cur_query += SNPRINTF_OFFSET(sql_query_string, cur_query, QUERY_SIZE, conditional_clause);
+
+ EM_DEBUG_LOG("em_storage_query_mail_list : query[%s].", sql_query_string);
+
+ /* performing query */
+ EM_PROFILE_BEGIN(em_storage_query_mail_list_performing_query);
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, &count, 0, NULL), rc);
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc && -1 != rc), {error = EM_STORAGE_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+ ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+ EM_PROFILE_END(em_storage_query_mail_list_performing_query);
+
+ if (!base_count)
+ base_count = ({ int i=0; char *tmp = field_list; for (i=0; tmp && *(tmp + 1); tmp = index(tmp + 1, ','), i++); i; });
+
+ col_index = base_count;
+
+ EM_DEBUG_LOG("base_count [%d]", base_count);
+
+ if (to_get_count) {
+ /* to get mail count */
+ count = atoi(result[1]);
+ EM_DEBUG_LOG("There are [%d] mails.", count);
+ }
+ else {
+ /* to get mail list */
+ if (!count) {
+ EM_DEBUG_EXCEPTION("No mail found...");
+ ret = false;
+ error= EM_STORAGE_ERROR_MAIL_NOT_FOUND;
+ goto FINISH_OFF;
+ }
+
+ EM_DEBUG_LOG("There are [%d] mails.", count);
+ if (!(mail_list_item_from_tbl = (emf_mail_list_item_t*)em_core_malloc(sizeof(emf_mail_list_item_t) * count))) {
+ EM_DEBUG_EXCEPTION("malloc for mail_list_item_from_tbl failed...");
+ error = EM_STORAGE_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ EM_PROFILE_BEGIN(em_storage_query_mail_list_loop);
+ EM_DEBUG_LOG(">>>> DATA ASSIGN START >> ");
+ for (i = 0; i < count; i++) {
+ _getTableFieldDataInt(result, &(mail_list_item_from_tbl[i].mail_id), col_index++);
+ _getTableFieldDataInt(result, &(mail_list_item_from_tbl[i].account_id), col_index++);
+ _getTableFieldDataStringWithoutAllocation(result, mail_list_item_from_tbl[i].mailbox_name, STRING_LENGTH_FOR_DISPLAY, 1, col_index++);
+ _getTableFieldDataStringWithoutAllocation(result, mail_list_item_from_tbl[i].from, STRING_LENGTH_FOR_DISPLAY, 1, col_index++);
+ _getTableFieldDataStringWithoutAllocation(result, mail_list_item_from_tbl[i].from_email_address, MAX_EMAIL_ADDRESS_LENGTH, 1, col_index++);
+ _getTableFieldDataStringWithoutAllocation(result, mail_list_item_from_tbl[i].recipients, STRING_LENGTH_FOR_DISPLAY, 1, col_index++);
+ _getTableFieldDataStringWithoutAllocation(result, mail_list_item_from_tbl[i].subject, STRING_LENGTH_FOR_DISPLAY, 1, col_index++);
+ _getTableFieldDataInt(result, &(mail_list_item_from_tbl[i].is_text_downloaded), col_index++);
+ _getTableFieldDataChar(result, &(mail_list_item_from_tbl[i].flags_seen_field), col_index++);
+ _getTableFieldDataChar(result, &(mail_list_item_from_tbl[i].flags_deleted_field), col_index++);
+ _getTableFieldDataChar(result, &(mail_list_item_from_tbl[i].flags_flagged_field), col_index++);
+ _getTableFieldDataChar(result, &(mail_list_item_from_tbl[i].flags_answered_field), col_index++);
+ _getTableFieldDataChar(result, &(mail_list_item_from_tbl[i].flags_recent_field), col_index++);
+ _getTableFieldDataChar(result, &(mail_list_item_from_tbl[i].flags_draft_field), col_index++);
+ _getTableFieldDataChar(result, &(mail_list_item_from_tbl[i].flags_forwarded_field), col_index++);
+ _getTableFieldDataInt(result, &(mail_list_item_from_tbl[i].has_drm_attachment), col_index++);
+ _getTableFieldDataInt(result, &(mail_list_item_from_tbl[i].priority), col_index++);
+ _getTableFieldDataInt(result, &(mail_list_item_from_tbl[i].save_status), col_index++);
+ _getTableFieldDataInt(result, &(mail_list_item_from_tbl[i].is_locked), col_index++);
+ _getTableFieldDataInt(result, &local_attachment_count, col_index++);
+ _getTableFieldDataInt(result, &local_inline_content_count, col_index++);
+ _getTableFieldDataStringWithoutAllocation(result, mail_list_item_from_tbl[i].datetime, MAX_DATETIME_STRING_LENGTH, 0, col_index++);
+ _getTableFieldDataStringWithoutAllocation(result, mail_list_item_from_tbl[i].previewBodyText, MAX_PREVIEW_TEXT_LENGTH, 1, col_index++);
+ _getTableFieldDataInt(result, &(mail_list_item_from_tbl[i].thread_id), col_index++);
+ _getTableFieldDataInt(result, &(mail_list_item_from_tbl[i].thread_item_count), col_index++);
+ _getTableFieldDataInt(result, &(mail_list_item_from_tbl[i].is_meeting_request), col_index++);
+ mail_list_item_from_tbl[i].has_attachment = ((local_attachment_count - local_inline_content_count)>0)?1:0;
+ }
+ EM_DEBUG_LOG(">>>> DATA ASSIGN END [count : %d] >> ", count);
+ EM_PROFILE_END(em_storage_query_mail_list_loop);
+ }
+
+ sqlite3_free_table(result);
+ result = NULL;
+ ret = true;
+
+FINISH_OFF:
+ EM_DEBUG_LOG("COUNT [%d]", count);
+
+ if (to_get_count)
+ *result_count = count;
+ else {
+ if (ret == true) {
+ if (result_mail_list)
+ *result_mail_list = mail_list_item_from_tbl;
+ *result_count = count;
+ }
+ else
+ EM_SAFE_FREE(mail_list_item_from_tbl);
+ }
+
+ EM_STORAGE_FINISH_READ_TRANSACTION(transaction);
+ _DISCONNECT_DB;
+
+ if (err_code != NULL)
+ *err_code = error;
+
+ EM_PROFILE_END(em_storage_query_mail_list_func);
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+
+EXPORT_API int em_storage_query_mail_tbl(const char *conditional_clause, int transaction, emf_mail_tbl_t** result_mail_tbl, int *result_count, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("conditional_clause[%s], result_mail_tbl[%p], result_count [%p], transaction[%d], err_code[%p]", conditional_clause, result_mail_tbl, result_count, transaction, err_code);
+
+ if (!conditional_clause) {
+ EM_DEBUG_EXCEPTION("EM_STORAGE_ERROR_INVALID_PARAM");
+
+ if (err_code != NULL)
+ *err_code = EM_STORAGE_ERROR_INVALID_PARAM;
+ return false;
+ }
+
+ int i, col_index = FIELD_COUNT_OF_EMF_MAIL_TBL, rc, ret = false, count;
+ int error = EM_STORAGE_ERROR_NONE;
+ char **result = NULL, sql_query_string[QUERY_SIZE] = {0, };
+ emf_mail_tbl_t* p_data_tbl = NULL;
+ sqlite3 *local_db_handle = em_storage_get_db_connection();
+
+ EM_STORAGE_START_READ_TRANSACTION(transaction);
+
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT * FROM mail_tbl %s", conditional_clause);
+
+ EM_DEBUG_LOG("Query [%s]", sql_query_string);
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, &count, 0, NULL), rc);
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc && -1 != rc), {error = EM_STORAGE_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+ ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ if (!count) {
+ EM_DEBUG_EXCEPTION("No mail found...");
+ ret = false;
+ error= EM_STORAGE_ERROR_MAIL_NOT_FOUND;
+ goto FINISH_OFF;
+ }
+
+ EM_DEBUG_LOG("There are [%d] mails.", count);
+ if (!(p_data_tbl = (emf_mail_tbl_t*)em_core_malloc(sizeof(emf_mail_tbl_t) * count))) {
+ EM_DEBUG_EXCEPTION("malloc for emf_mail_tbl_t failed...");
+ error = EM_STORAGE_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ EM_DEBUG_LOG(">>>> DATA ASSIGN START >> ");
+ for (i = 0; i < count; i++) {
+ _getTableFieldDataInt(result, &(p_data_tbl[i].mail_id), col_index++);
+ _getTableFieldDataInt(result, &(p_data_tbl[i].account_id), col_index++);
+ _getTableFieldDataString(result, &(p_data_tbl[i].mailbox_name), 0, col_index++);
+ _getTableFieldDataInt(result, &(p_data_tbl[i].mailbox_type), col_index++);
+ _getTableFieldDataString(result, &(p_data_tbl[i].subject), 1, col_index++);
+ _getTableFieldDataString(result, &(p_data_tbl[i].datetime), 0, col_index++);
+ _getTableFieldDataInt(result, &(p_data_tbl[i].server_mail_status), col_index++);
+ _getTableFieldDataString(result, &(p_data_tbl[i].server_mailbox_name), 0, col_index++);
+ _getTableFieldDataString(result, &(p_data_tbl[i].server_mail_id), 0, col_index++);
+ _getTableFieldDataString(result, &(p_data_tbl[i].message_id), 0, col_index++);
+ _getTableFieldDataString(result, &(p_data_tbl[i].full_address_from), 1, col_index++);
+ _getTableFieldDataString(result, &(p_data_tbl[i].full_address_reply), 1, col_index++);
+ _getTableFieldDataString(result, &(p_data_tbl[i].full_address_to), 1, col_index++);
+ _getTableFieldDataString(result, &(p_data_tbl[i].full_address_cc), 1, col_index++);
+ _getTableFieldDataString(result, &(p_data_tbl[i].full_address_bcc), 1, col_index++);
+ _getTableFieldDataString(result, &(p_data_tbl[i].full_address_return), 1, col_index++);
+ _getTableFieldDataString(result, &(p_data_tbl[i].email_address_sender), 1, col_index++);
+ _getTableFieldDataString(result, &(p_data_tbl[i].email_address_recipient), 1, col_index++);
+ _getTableFieldDataString(result, &(p_data_tbl[i].alias_sender), 1, col_index++);
+ _getTableFieldDataString(result, &(p_data_tbl[i].alias_recipient), 1, col_index++);
+ _getTableFieldDataInt(result, &(p_data_tbl[i].body_download_status), col_index++);
+ _getTableFieldDataString(result, &(p_data_tbl[i].file_path_plain), 0, col_index++);
+ _getTableFieldDataString(result, &(p_data_tbl[i].file_path_html), 0, col_index++);
+ _getTableFieldDataInt(result, &(p_data_tbl[i].mail_size), col_index++);
+ _getTableFieldDataChar(result, &(p_data_tbl[i].flags_seen_field), col_index++);
+ _getTableFieldDataChar(result, &(p_data_tbl[i].flags_deleted_field), col_index++);
+ _getTableFieldDataChar(result, &(p_data_tbl[i].flags_flagged_field), col_index++);
+ _getTableFieldDataChar(result, &(p_data_tbl[i].flags_answered_field), col_index++);
+ _getTableFieldDataChar(result, &(p_data_tbl[i].flags_recent_field), col_index++);
+ _getTableFieldDataChar(result, &(p_data_tbl[i].flags_draft_field), col_index++);
+ _getTableFieldDataChar(result, &(p_data_tbl[i].flags_forwarded_field), col_index++);
+ _getTableFieldDataInt(result, &(p_data_tbl[i].DRM_status), col_index++);
+ _getTableFieldDataInt(result, &(p_data_tbl[i].priority), col_index++);
+ _getTableFieldDataInt(result, &(p_data_tbl[i].save_status), col_index++);
+ _getTableFieldDataInt(result, &(p_data_tbl[i].lock_status), col_index++);
+ _getTableFieldDataInt(result, &(p_data_tbl[i].report_status), col_index++);
+ _getTableFieldDataInt(result, &(p_data_tbl[i].attachment_count), col_index++);
+ _getTableFieldDataInt(result, &(p_data_tbl[i].inline_content_count), col_index++);
+ _getTableFieldDataInt(result, &(p_data_tbl[i].thread_id), col_index++);
+ _getTableFieldDataInt(result, &(p_data_tbl[i].thread_item_count), col_index++);
+ _getTableFieldDataString(result, &(p_data_tbl[i].preview_text), 1, col_index++);
+ _getTableFieldDataInt(result, &(p_data_tbl[i].meeting_request_status), col_index++);
+ /* check real body file... */
+ if (p_data_tbl[i].body_download_status) {
+ struct stat buf;
+
+ if (p_data_tbl[i].file_path_html && strlen(p_data_tbl[i].file_path_html) > 0) {
+ if (stat(p_data_tbl[i].file_path_html, &buf) == -1) {
+ EM_DEBUG_LINE;
+ p_data_tbl[i].body_download_status = 0;
+ }
+ }
+ else if (p_data_tbl[i].file_path_plain && strlen(p_data_tbl[i].file_path_plain) > 0) {
+ if (stat(p_data_tbl[i].file_path_plain, &buf) == -1){
+ EM_DEBUG_LINE;
+ p_data_tbl[i].body_download_status = 0;
+ }
+ }
+ else
+ p_data_tbl[i].body_download_status = 0;
+ }
+ }
+
+ ret = true;
+
+FINISH_OFF:
+ if(result)
+ sqlite3_free_table(result);
+
+ if (ret == true) {
+ if (result_mail_tbl)
+ *result_mail_tbl = p_data_tbl;
+ *result_count = count;
+ }
+ else
+ EM_SAFE_FREE(p_data_tbl);
+
+ EM_STORAGE_FINISH_READ_TRANSACTION(transaction);
+ _DISCONNECT_DB;
+
+ if (err_code != NULL)
+ *err_code = error;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+
+/* Query series --------------------------------------------------------------*/
+
+EXPORT_API int em_storage_check_duplicated_account(emf_account_t* account, int transaction, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ if (!account) {
+ if (err_code != NULL)
+ *err_code = EM_STORAGE_ERROR_INVALID_PARAM;
+ return false;
+ }
+
+ int rc = -1, ret = false;
+ int error = EM_STORAGE_ERROR_NONE;
+ char **result;
+ int count;
+ char sql_query_string[QUERY_SIZE] = {0, };
+
+ sqlite3 *local_db_handle = em_storage_get_db_connection();
+ EM_STORAGE_START_READ_TRANSACTION(transaction);
+
+ SNPRINTF(sql_query_string, sizeof(sql_query_string),
+ "SELECT COUNT(*) FROM mail_account_tbl "
+ " WHERE "
+ " email_addr = '%s' AND "
+ " user_name = '%s' AND "
+ " receiving_server_type = %d AND "
+ " receiving_server_addr = '%s' AND "
+ " sending_user = '%s' AND "
+ " sending_server_type = %d AND "
+ " sending_server_addr = '%s'; ",
+ account->email_addr,
+ account->user_name, account->receiving_server_type, account->receiving_server_addr,
+ account->sending_user, account->sending_server_type, account->sending_server_addr
+ );
+ EM_DEBUG_LOG("Query[%s]", sql_query_string);
+ /* rc = sqlite3_get_table(local_db_handle, sql_query_string, &result, NULL, NULL, NULL); */
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, NULL, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EM_STORAGE_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+ ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ count = atoi(result[1]);
+ sqlite3_free_table(result);
+
+ EM_DEBUG_LOG("Count of Duplicated Account Information: [%d]", count);
+
+ if (count == 0) { /* not duplicated account */
+ ret = true;
+ EM_DEBUG_LOG("NOT duplicated account: email_addr[%s]", account->email_addr);
+ }
+ else { /* duplicated account */
+ ret = false;
+ EM_DEBUG_LOG("The same account already exists. Duplicated account: email_addr[%s]", account->email_addr);
+ error = EM_STORAGE_ERROR_ALREADY_EXISTS;
+ }
+
+FINISH_OFF:
+
+ EM_STORAGE_FINISH_READ_TRANSACTION(transaction);
+ _DISCONNECT_DB;
+
+ if (err_code != NULL)
+ *err_code = error;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+
+}
+
+EXPORT_API int em_storage_get_account_count(int *count, int transaction, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ if (!count) {
+ if (err_code != NULL)
+ *err_code = EM_STORAGE_ERROR_INVALID_PARAM;
+ return false;
+ }
+
+ int rc = -1, ret = false;
+ int error = EM_STORAGE_ERROR_NONE;
+
+ DB_STMT hStmt = NULL;
+ char sql_query_string[QUERY_SIZE] = {0, };
+ char err_msg[1024];
+
+ sqlite3 *local_db_handle = em_storage_get_db_connection();
+ EM_STORAGE_START_READ_TRANSACTION(transaction);
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT COUNT(*) FROM mail_account_tbl");
+ EM_DEBUG_LOG("SQL STMT [ %s ]", sql_query_string);
+ /* rc = sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL); */
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
+ EM_DEBUG_LOG("Before sqlite3_prepare hStmt = %p", hStmt);
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ /* rc = sqlite3_step(hStmt); */
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
+ EM_DEBUG_DB_EXEC((rc != SQLITE_ROW), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("sqlite3_step fail:%d", rc));
+
+ *count = sqlite3_column_int(hStmt, 0);
+
+ ret = true;
+
+FINISH_OFF:
+
+ if (hStmt != NULL) {
+ EM_DEBUG_LOG("Before sqlite3_finalize hStmt = %p", hStmt);
+
+ rc = sqlite3_finalize(hStmt);
+ hStmt=NULL;
+ if (rc != SQLITE_OK) {
+ EM_DEBUG_EXCEPTION("sqlite3_finalize failed - %d: %s", rc, err_msg);
+ error = EM_STORAGE_ERROR_DB_FAILURE;
+ }
+ EM_DEBUG_LOG("sqlite3_finalize- %d", rc);
+ }
+
+ EM_STORAGE_FINISH_READ_TRANSACTION(transaction);
+ _DISCONNECT_DB;
+
+ if (err_code != NULL)
+ *err_code = error;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+
+EXPORT_API int em_storage_get_account_list(int *select_num, emf_mail_account_tbl_t** account_list, int transaction, int with_password, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ int i = 0, count = 0, rc = -1, ret = false;
+ int error = EM_STORAGE_ERROR_NONE;
+ emf_mail_account_tbl_t *p_data_tbl = NULL;
+
+ DB_STMT hStmt = NULL;
+
+ if (!select_num || !account_list) {
+ EM_DEBUG_EXCEPTION("select_num[%p], account_list[%p]", select_num, account_list);
+ if (err_code != NULL)
+ *err_code = EM_STORAGE_ERROR_INVALID_PARAM;
+ return false;
+ }
+
+ sqlite3 *local_db_handle = em_storage_get_db_connection();
+ EM_STORAGE_START_READ_TRANSACTION(transaction);
+
+ char sql_query_string[QUERY_SIZE] = {0, };
+ char *sql = "SELECT count(*) FROM mail_account_tbl;";
+ char **result;
+
+ /* rc = sqlite3_get_table(local_db_handle, sql, &result, NULL, NULL, NULL); */
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql, &result, NULL, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EM_STORAGE_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+ ("SQL(%s) sqlite3_get_table fail:%d -%s", sql, rc, sqlite3_errmsg(local_db_handle)));
+
+ count = atoi(result[1]);
+ sqlite3_free_table(result);
+
+ if (!count) {
+ EM_DEBUG_EXCEPTION("no account found...");
+ error = EM_STORAGE_ERROR_ACCOUNT_NOT_FOUND;
+ ret = true;
+ goto FINISH_OFF;
+ }
+ EM_DEBUG_LOG("count = %d", rc);
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT * FROM mail_account_tbl ORDER BY account_id");
+
+ /* rc = sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL); */
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
+
+ EM_DEBUG_LOG("After sqlite3_prepare_v2 hStmt = %p", hStmt);
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ /* rc = sqlite3_step(hStmt); */
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
+ EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("sqlite3_step fail:%d", rc));
+ if (rc == SQLITE_DONE) {
+ EM_DEBUG_EXCEPTION("no account found...");
+
+ error = EM_STORAGE_ERROR_ACCOUNT_NOT_FOUND;
+ count = 0;
+ ret = true;
+ goto FINISH_OFF;
+ }
+
+ if (!(p_data_tbl = (emf_mail_account_tbl_t*)malloc(sizeof(emf_mail_account_tbl_t) * count))) {
+ EM_DEBUG_EXCEPTION("malloc failed...");
+ error = EM_STORAGE_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+ memset(p_data_tbl, 0x00, sizeof(emf_mail_account_tbl_t) * count);
+ for (i = 0; i < count; i++) {
+ /* get recordset */
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl[i].account_bind_type), ACCOUNT_BIND_TYPE_IDX_IN_MAIL_ACCOUNT_TBL);
+ _getStmtFieldDataString(hStmt, &(p_data_tbl[i].account_name), 0, ACCOUNT_NAME_IDX_IN_MAIL_ACCOUNT_TBL);
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl[i].receiving_server_type), RECEIVING_SERVER_TYPE_TYPE_IDX_IN_MAIL_ACCOUNT_TBL);
+ _getStmtFieldDataString(hStmt, &(p_data_tbl[i].receiving_server_addr), 0, RECEIVING_SERVER_ADDR_IDX_IN_MAIL_ACCOUNT_TBL);
+ _getStmtFieldDataString(hStmt, &(p_data_tbl[i].email_addr), 0, EMAIL_ADDR_IDX_IN_MAIL_ACCOUNT_TBL);
+ _getStmtFieldDataString(hStmt, &(p_data_tbl[i].user_name), 0, USER_NAME_IDX_IN_MAIL_ACCOUNT_TBL);
+ _getStmtFieldDataString(hStmt, &(p_data_tbl[i].password), 0, PASSWORD_IDX_IN_MAIL_ACCOUNT_TBL);
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl[i].retrieval_mode), RETRIEVAL_MODE_IDX_IN_MAIL_ACCOUNT_TBL);
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl[i].port_num), PORT_NUM_IDX_IN_MAIL_ACCOUNT_TBL);
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl[i].use_security), USE_SECURITY_IDX_IN_MAIL_ACCOUNT_TBL);
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl[i].sending_server_type), SENDING_SERVER_TYPE_IDX_IN_MAIL_ACCOUNT_TBL);
+ _getStmtFieldDataString(hStmt, &(p_data_tbl[i].sending_server_addr), 0, SENDING_SERVER_ADDR_IDX_IN_MAIL_ACCOUNT_TBL);
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl[i].sending_port_num), SENDING_PORT_NUM_IDX_IN_MAIL_ACCOUNT_TBL);
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl[i].sending_auth), SENDING_AUTH_IDX_IN_MAIL_ACCOUNT_TBL);
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl[i].sending_security), SENDING_SECURITY_IDX_IN_MAIL_ACCOUNT_TBL);
+ _getStmtFieldDataString(hStmt, &(p_data_tbl[i].sending_user), 0, SENDING_USER_IDX_IN_MAIL_ACCOUNT_TBL);
+ _getStmtFieldDataString(hStmt, &(p_data_tbl[i].sending_password), 0, SENDING_PASSWORD_IDX_IN_MAIL_ACCOUNT_TBL);
+ _getStmtFieldDataString(hStmt, &(p_data_tbl[i].display_name), 0, DISPLAY_NAME_IDX_IN_MAIL_ACCOUNT_TBL);
+ _getStmtFieldDataString(hStmt, &(p_data_tbl[i].reply_to_addr), 0, REPLY_TO_ADDR_IDX_IN_MAIL_ACCOUNT_TBL);
+ _getStmtFieldDataString(hStmt, &(p_data_tbl[i].return_addr), 0, RETURN_ADDR_IDX_IN_MAIL_ACCOUNT_TBL);
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl[i].account_id), ACCOUNT_ID_IDX_IN_MAIL_ACCOUNT_TBL);
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl[i].keep_on_server), KEEP_ON_SERVER_IDX_IN_MAIL_ACCOUNT_TBL);
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl[i].flag1), FLAG1_IDX_IN_MAIL_ACCOUNT_TBL);
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl[i].flag2), FLAG2_IDX_IN_MAIL_ACCOUNT_TBL);
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl[i].pop_before_smtp), POP_BEFORE_SMTP_IDX_IN_MAIL_ACCOUNT_TBL);
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl[i].apop), APOP_IDX_IN_MAIL_ACCOUNT_TBL);
+ _getStmtFieldDataString(hStmt, &(p_data_tbl[i].logo_icon_path), 0, LOGO_ICON_PATH_IDX_IN_MAIL_ACCOUNT_TBL);
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl[i].preset_account), PRESET_ACCOUNT_IDX_IN_MAIL_ACCOUNT_TBL);
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl[i].target_storage), TARGET_STORAGE_IDX_IN_MAIL_ACCOUNT_TBL);
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl[i].check_interval), CHECK_INTERVAL_IDX_IN_MAIL_ACCOUNT_TBL);
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl[i].options.priority), PRIORITY_IDX_IN_MAIL_ACCOUNT_TBL);
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl[i].options.keep_local_copy), KEEP_LOCAL_COPY_IDX_IN_MAIL_ACCOUNT_TBL);
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl[i].options.req_delivery_receipt), REQ_DELIVERY_RECEIPT_IDX_IN_MAIL_ACCOUNT_TBL);
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl[i].options.req_read_receipt), REQ_READ_RECEIPT_IDX_IN_MAIL_ACCOUNT_TBL);
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl[i].options.download_limit), DOWNLOAD_LIMIT_IDX_IN_MAIL_ACCOUNT_TBL);
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl[i].options.block_address), BLOCK_ADDRESS_IDX_IN_MAIL_ACCOUNT_TBL);
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl[i].options.block_subject), BLOCK_SUBJECT_IDX_IN_MAIL_ACCOUNT_TBL);
+ _getStmtFieldDataString(hStmt, &(p_data_tbl[i].options.display_name_from), 0, DISPLAY_NAME_FROM_IDX_IN_MAIL_ACCOUNT_TBL);
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl[i].options.reply_with_body), REPLY_WITH_BODY_IDX_IN_MAIL_ACCOUNT_TBL);
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl[i].options.forward_with_files), FORWARD_WITH_FILES_IDX_IN_MAIL_ACCOUNT_TBL);
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl[i].options.add_myname_card), ADD_MYNAME_CARD_IDX_IN_MAIL_ACCOUNT_TBL);
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl[i].options.add_signature), ADD_SIGNATURE_IDX_IN_MAIL_ACCOUNT_TBL);
+ _getStmtFieldDataString(hStmt, &(p_data_tbl[i].options.signature), 0, SIGNATURE_IDX_IN_MAIL_ACCOUNT_TBL);
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl[i].options.add_my_address_to_bcc), ADD_MY_ADDRESS_TO_BCC_IDX_IN_MAIL_ACCOUNT_TBL);
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl[i].my_account_id), MY_ACCOUNT_ID_IDX_IN_MAIL_ACCOUNT_TBL);
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl[i].index_color), INDEX_COLOR_IDX_IN_MAIL_ACCOUNT_TBL);
+ if (with_password == true) {
+ /* get password from the secure storage */
+ char recv_password_file_name[MAX_PW_FILE_NAME_LENGTH];/* = p_data_tbl[i].password; */
+ char send_password_file_name[MAX_PW_FILE_NAME_LENGTH];;/* = p_data_tbl[i].sending_password; */
+
+ EM_SAFE_FREE(p_data_tbl[i].password);
+ EM_SAFE_FREE(p_data_tbl[i].sending_password);
+
+ /* get password file name */
+ if ((error = em_storage_get_password_file_name(p_data_tbl[i].account_id, recv_password_file_name, send_password_file_name)) != EM_STORAGE_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("em_storage_get_password_file_name failed.");
+ goto FINISH_OFF;
+ }
+
+ /* read password from secure storage */
+ if ((error = em_storage_read_password_ss(recv_password_file_name, &(p_data_tbl[i].password))) < 0 ) {
+ EM_DEBUG_EXCEPTION("em_storage_read_password_ss() failed...");
+ goto FINISH_OFF;
+ }
+ EM_DEBUG_LOG("recv_password_file_name[%s], password[%s]", recv_password_file_name, p_data_tbl[i].password);
+
+ if ((error = em_storage_read_password_ss(send_password_file_name, &(p_data_tbl[i].sending_password))) < 0) {
+ EM_DEBUG_EXCEPTION("em_storage_read_password_ss() failed...");
+ goto FINISH_OFF;
+ }
+ EM_DEBUG_LOG("send_password_file_name[%s], password[%s]", send_password_file_name, p_data_tbl[i].sending_password);
+ }
+
+ /* rc = sqlite3_step(hStmt); */
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
+ EM_DEBUG_LOG("after sqlite3_step(), i = %d, rc = %d.", i, rc);
+ EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("sqlite3_step fail:%d", rc));
+ }
+
+ ret = true;
+
+FINISH_OFF:
+ if (ret == true) {
+ *account_list = p_data_tbl;
+ *select_num = count;
+ EM_DEBUG_LOG("COUNT : %d", count);
+ }
+ else if (p_data_tbl != NULL)
+ em_storage_free_account(&p_data_tbl, count, NULL);
+ if (hStmt != NULL) {
+ EM_DEBUG_LOG("Before sqlite3_finalize hStmt = %p", hStmt);
+
+ rc = sqlite3_finalize(hStmt);
+ hStmt = NULL;
+ if (rc != SQLITE_OK) {
+ EM_DEBUG_EXCEPTION("sqlite3_finalize failed - %d", rc);
+ error = EM_STORAGE_ERROR_DB_FAILURE;
+ }
+ }
+
+ EM_STORAGE_FINISH_READ_TRANSACTION(transaction);
+ _DISCONNECT_DB;
+
+ if (err_code != NULL)
+ *err_code = error;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+
+EXPORT_API int em_storage_get_maildata_by_servermailid(int account_id, char *server_mail_id, emf_mail_tbl_t** mail, int transaction, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("account_id [%d], server_mail_id[%s], mail[%p], transaction[%d], err_code[%p]", account_id, server_mail_id, mail, transaction, err_code);
+
+ int ret = false, error = EM_STORAGE_ERROR_NONE, result_count;
+ char conditional_clause[QUERY_SIZE] = {0, };
+ emf_mail_tbl_t* p_data_tbl = NULL;
+
+ if (!server_mail_id || !mail) {
+ EM_DEBUG_EXCEPTION("EM_STORAGE_ERROR_INVALID_PARAM");
+ error = EM_STORAGE_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ if (account_id == ALL_ACCOUNT)
+ SNPRINTF(conditional_clause, QUERY_SIZE, "WHERE UPPER(server_mail_id) =UPPER('%s')", server_mail_id);
+ else
+ SNPRINTF(conditional_clause, QUERY_SIZE, "WHERE UPPER(server_mail_id) =UPPER('%s') AND account_id = %d", server_mail_id, account_id);
+
+ EM_DEBUG_LOG("conditional_clause [%s]", conditional_clause);
+
+ if(!em_storage_query_mail_tbl(conditional_clause, transaction, &p_data_tbl, &result_count, &error)) {
+ EM_DEBUG_EXCEPTION("em_storage_query_mail_tbl failed [%d]", error);
+ goto FINISH_OFF;
+ }
+
+ ret = true;
+
+FINISH_OFF:
+ if (ret == true)
+ *mail = p_data_tbl;
+
+ if (err_code != NULL)
+ *err_code = error;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+
+static int em_storage_write_conditional_clause_for_getting_mail_list(int account_id, const char *mailbox_name, emf_email_address_list_t* addr_list, int thread_id, int start_index, int limit_count, int search_type, const char *search_value, emf_sort_type_t sorting, char *conditional_clause_string, int buffer_size, int *err_code)
+{
+ int cur_clause = 0, conditional_clause_count = 0, i = 0;
+
+ if (account_id < ALL_ACCOUNT) {
+ EM_DEBUG_EXCEPTION("Invalid account_id [%d]", account_id);
+ EM_RETURN_ERR_CODE(err_code, EM_STORAGE_ERROR_INVALID_PARAM, false);
+ }
+
+ /* where clause */
+ if (account_id == ALL_ACCOUNT) {
+ cur_clause += (conditional_clause_count++ == 0)?
+ SNPRINTF_OFFSET(conditional_clause_string, cur_clause, buffer_size - cur_clause, " WHERE mailbox_type not in (3, 5, 7)"):
+ SNPRINTF_OFFSET(conditional_clause_string, cur_clause, buffer_size - cur_clause, " AND mailbox_type not in (3, 5, 7)");
+ }
+ else {
+ cur_clause += (conditional_clause_count++ == 0)?
+ SNPRINTF_OFFSET(conditional_clause_string, cur_clause, buffer_size - cur_clause, " WHERE account_id = %d", account_id):
+ SNPRINTF_OFFSET(conditional_clause_string, cur_clause, buffer_size - cur_clause, " AND account_id = %d", account_id);
+ }
+
+ if (mailbox_name) {
+ cur_clause += (conditional_clause_count++ == 0)?
+ SNPRINTF_OFFSET(conditional_clause_string, cur_clause, buffer_size - cur_clause, " WHERE UPPER(mailbox_name) = UPPER('%s')", mailbox_name):
+ SNPRINTF_OFFSET(conditional_clause_string, cur_clause, buffer_size - cur_clause, " AND UPPER(mailbox_name) = UPPER('%s')", mailbox_name);
+ }
+ else if(account_id != ALL_ACCOUNT) {
+ cur_clause += (conditional_clause_count++ == 0)?
+ SNPRINTF_OFFSET(conditional_clause_string, cur_clause, buffer_size - cur_clause, " WHERE mailbox_type not in (3, 5, 7)"):
+ SNPRINTF_OFFSET(conditional_clause_string, cur_clause, buffer_size - cur_clause, " AND mailbox_type not in (3, 5, 7)");
+ }
+
+ if (thread_id > 0) {
+ cur_clause += (conditional_clause_count++ == 0)?
+ SNPRINTF_OFFSET(conditional_clause_string, cur_clause, buffer_size - cur_clause, " WHERE thread_id = %d ", thread_id):
+ SNPRINTF_OFFSET(conditional_clause_string, cur_clause, buffer_size - cur_clause, " AND thread_id = %d ", thread_id);
+ }
+ else if (thread_id == EMF_LIST_TYPE_THREAD) {
+ cur_clause += (conditional_clause_count++ == 0)?
+ SNPRINTF_OFFSET(conditional_clause_string, cur_clause, buffer_size - cur_clause, " WHERE thread_item_count > 0"):
+ SNPRINTF_OFFSET(conditional_clause_string, cur_clause, buffer_size - cur_clause, " AND thread_item_count > 0");
+ }
+ else if (thread_id == EMF_LIST_TYPE_LOCAL) {
+ cur_clause += (conditional_clause_count++ == 0)?
+ SNPRINTF_OFFSET(conditional_clause_string, cur_clause, buffer_size - cur_clause, " WHERE server_mail_status = 0"):
+ SNPRINTF_OFFSET(conditional_clause_string, cur_clause, buffer_size - cur_clause, " AND server_mail_status = 0");
+ }
+ else if (thread_id == EMF_LIST_TYPE_UNREAD) {
+ cur_clause += (conditional_clause_count++ == 0)?
+ SNPRINTF_OFFSET(conditional_clause_string, cur_clause, buffer_size - cur_clause, " WHERE flags_seen_field == 0"):
+ SNPRINTF_OFFSET(conditional_clause_string, cur_clause, buffer_size - cur_clause, " AND flags_seen_field == 0");
+ }
+
+ /* EM_DEBUG_LOG("where clause added [%s]", conditional_clause_string); */
+ if (addr_list && addr_list->address_count > 0) {
+ if (!addr_list->address_type) {
+ cur_clause += (conditional_clause_count++ == 0)?
+ SNPRINTF_OFFSET(conditional_clause_string, cur_clause, buffer_size - cur_clause, " WHERE email_address_sender IN(\"%s\"", addr_list->address_list[0]):
+ SNPRINTF_OFFSET(conditional_clause_string, cur_clause, buffer_size - cur_clause, " AND email_address_sender IN(\"%s\"", addr_list->address_list[0]);
+
+ for (i = 1; i < addr_list->address_count; i++)
+ cur_clause += SNPRINTF_OFFSET(conditional_clause_string, cur_clause, buffer_size - cur_clause, ",\"%s\"", addr_list->address_list[i]);
+
+ cur_clause += SNPRINTF_OFFSET(conditional_clause_string, cur_clause, buffer_size - cur_clause, ")");
+ } else {
+ cur_clause += (conditional_clause_count++ == 0)?
+ SNPRINTF_OFFSET(conditional_clause_string, cur_clause, buffer_size - cur_clause, " WHERE full_address_to IN(\"%s\") or full_address_cc IN(\"%s\"", addr_list->address_list[0], addr_list->address_list[0]):
+ SNPRINTF_OFFSET(conditional_clause_string, cur_clause, buffer_size - cur_clause, " AND full_address_to IN(\"%s\") or full_address_cc IN(\"%s\"", addr_list->address_list[0], addr_list->address_list[0]);
+
+ for (i = 1; i < addr_list->address_count; i++)
+ cur_clause += SNPRINTF_OFFSET(conditional_clause_string, cur_clause, buffer_size - cur_clause, ",\"%s\"", addr_list->address_list[i]);
+
+ cur_clause += SNPRINTF_OFFSET(conditional_clause_string, cur_clause, buffer_size - cur_clause, ")");
+ }
+ }
+
+ if (search_value) {
+ switch (search_type) {
+ case EMF_SEARCH_FILTER_SUBJECT:
+ cur_clause += SNPRINTF_OFFSET(conditional_clause_string, cur_clause, buffer_size - cur_clause,
+ " %s (UPPER(subject) LIKE UPPER(\'%%%%%s%%%%\')) ", conditional_clause_count++ ? "AND" : "WHERE", search_value);
+ break;
+ case EMF_SEARCH_FILTER_SENDER:
+ cur_clause += SNPRINTF_OFFSET(conditional_clause_string, cur_clause, buffer_size - cur_clause,
+ " %s ((UPPER(full_address_from) LIKE UPPER(\'%%%%%s%%%%\')) "
+ ") ", conditional_clause_count++ ? "AND" : "WHERE", search_value);
+ break;
+ case EMF_SEARCH_FILTER_RECIPIENT:
+ cur_clause += SNPRINTF_OFFSET(conditional_clause_string, cur_clause, buffer_size - cur_clause,
+ " %s ((UPPER(full_address_to) LIKE UPPER(\'%%%%%s%%%%\')) "
+ " OR (UPPER(full_address_cc) LIKE UPPER(\'%%%%%s%%%%\')) "
+ " OR (UPPER(full_address_bcc) LIKE UPPER(\'%%%%%s%%%%\')) "
+ ") ", conditional_clause_count++ ? "AND" : "WHERE", search_value, search_value, search_value);
+ break;
+ case EMF_SEARCH_FILTER_ALL:
+ cur_clause += SNPRINTF_OFFSET(conditional_clause_string, cur_clause, buffer_size - cur_clause,
+ " %s (UPPER(subject) LIKE UPPER(\'%%%%%s%%%%\') "
+ " OR (((UPPER(full_address_from) LIKE UPPER(\'%%%%%s%%%%\')) "
+ " OR (UPPER(full_address_to) LIKE UPPER(\'%%%%%s%%%%\')) "
+ " OR (UPPER(full_address_cc) LIKE UPPER(\'%%%%%s%%%%\')) "
+ " OR (UPPER(full_address_bcc) LIKE UPPER(\'%%%%%s%%%%\')) "
+ " ) "
+ " )"
+ ")", conditional_clause_count++ ? "AND" : "WHERE", search_value, search_value, search_value, search_value, search_value);
+ break;
+ }
+ }
+
+ /* EM_DEBUG_LOG("where clause [%s]", conditional_clause_string); */
+ static char sorting_str[][50] = {
+ " ORDER BY date_time DESC", /* case EMF_SORT_DATETIME_HIGH: */
+ " ORDER BY date_time ASC", /* case EMF_SORT_DATETIME_LOW: */
+ " ORDER BY full_address_from DESC, date_time DESC", /* case EMF_SORT_SENDER_HIGH: */
+ " ORDER BY full_address_from ASC, date_time DESC", /* case EMF_SORT_SENDER_LOW: */
+ " ORDER BY full_address_to DESC, date_time DESC", /* case EMF_SORT_RCPT_HIGH: */
+ " ORDER BY full_address_to ASC, date_time DESC", /* case EMF_SORT_RCPT_LOW: */
+ " ORDER BY subject DESC, date_time DESC", /* case EMF_SORT_SUBJECT_HIGH: */
+ " ORDER BY subject ASC, date_time DESC", /* case EMF_SORT_SUBJECT_LOW: */
+ " ORDER BY priority DESC, date_time DESC", /* case EMF_SORT_PRIORITY_HIGH: */
+ " ORDER BY priority ASC, date_time DESC", /* case EMF_SORT_PRIORITY_LOW: */
+ " ORDER BY attachment_count DESC, date_time DESC", /* case EMF_SORT_ATTACHMENT_HIGH: */
+ " ORDER BY attachment_count ASC, date_time DESC", /* case EMF_SORT_ATTACHMENT_LOW: */
+ " ORDER BY lock_status DESC, date_time DESC", /* case EMF_SORT_FAVORITE_HIGH: */
+ " ORDER BY lock_status ASC, date_time DESC", /* case EMF_SORT_FAVORITE_LOW: */
+ " ORDER BY mailbox_name DESC, date_time DESC", /* case EMF_SORT_MAILBOX_NAME_HIGH: */
+ " ORDER BY mailbox_name ASC, date_time DESC" /* case EMF_SORT_MAILBOX_NAME_LOW: */
+ };
+
+ if (sorting < EMF_SORT_END && sorting >= 0)
+ cur_clause += SNPRINTF_OFFSET(conditional_clause_string, cur_clause, buffer_size, " %s", sorting_str[sorting]);
+ else
+ EM_DEBUG_LOG(" Invalid Sorting order ");
+
+ /* limit clause */
+ if (start_index != -1 && limit_count != -1)
+ cur_clause += SNPRINTF_OFFSET(conditional_clause_string, cur_clause, buffer_size, " LIMIT %d, %d", start_index, limit_count);
+
+ return true;
+}
+
+
+/**
+ * em_storage_get_mail_list - Get the mail list information.
+ *
+ *
+ */
+EXPORT_API int em_storage_get_mail_list(int account_id, const char *mailbox_name, emf_email_address_list_t* addr_list, int thread_id, int start_index, int limit_count, int search_type, const char *search_value, emf_sort_type_t sorting, int transaction, emf_mail_list_item_t** mail_list, int *result_count, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ EM_PROFILE_BEGIN(em_storage_get_mail_list_func);
+
+ int ret = false, error = EM_STORAGE_ERROR_NONE;
+ char conditional_clause_string[QUERY_SIZE] = { 0, };
+
+ if (account_id < ALL_ACCOUNT) {
+ EM_DEBUG_EXCEPTION("Invalid account_id [%d]", account_id);
+ EM_RETURN_ERR_CODE(err_code, EM_STORAGE_ERROR_INVALID_PARAM, false);
+ }
+ EM_IF_NULL_RETURN_VALUE(result_count, false);
+
+ em_storage_write_conditional_clause_for_getting_mail_list(account_id, mailbox_name, addr_list, thread_id, start_index, limit_count, search_type, search_value, sorting, conditional_clause_string, QUERY_SIZE, &error);
+
+ EM_DEBUG_LOG("conditional_clause_string[%s].", conditional_clause_string);
+
+ if(!em_storage_query_mail_list(conditional_clause_string, transaction, mail_list, result_count, &error)) {
+ EM_DEBUG_EXCEPTION("em_storage_query_mail_list [%d]", error);
+ goto FINISH_OFF;
+ }
+
+ ret = true;
+
+FINISH_OFF:
+ if (err_code != NULL)
+ *err_code = error;
+
+ EM_PROFILE_END(em_storage_get_mail_list_func);
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+
+/**
+ * em_storage_get_mails - Get the Mail list information based on mailbox_name name
+ *
+ *
+ */
+EXPORT_API int em_storage_get_mails(int account_id, const char *mailbox_name, emf_email_address_list_t* addr_list, int thread_id, int start_index, int limit_count, emf_sort_type_t sorting, int transaction, emf_mail_tbl_t** mail_list, int *result_count, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ EM_PROFILE_BEGIN(emStorageGetMails);
+
+ int count = 0, ret = false, error = EM_STORAGE_ERROR_NONE;
+ emf_mail_tbl_t *p_data_tbl = NULL;
+ char conditional_clause_string[QUERY_SIZE] = {0, };
+
+ EM_IF_NULL_RETURN_VALUE(mail_list, false);
+ EM_IF_NULL_RETURN_VALUE(result_count, false);
+
+ if (!result_count || !mail_list || account_id < ALL_ACCOUNT) {
+ EM_DEBUG_EXCEPTION("EM_STORAGE_ERROR_INVALID_PARAM");
+ if (err_code != NULL)
+ *err_code = EM_STORAGE_ERROR_INVALID_PARAM;
+ return false;
+ }
+
+ em_storage_write_conditional_clause_for_getting_mail_list(account_id, mailbox_name, addr_list, thread_id, start_index, limit_count, 0, NULL, sorting, conditional_clause_string, QUERY_SIZE, &error);
+
+ EM_DEBUG_LOG("conditional_clause_string [%s]", conditional_clause_string);
+
+ if(!em_storage_query_mail_tbl(conditional_clause_string, transaction, &p_data_tbl, &count, &error)) {
+ EM_DEBUG_EXCEPTION("em_storage_query_mail_tbl failed [%d]", error);
+ goto FINISH_OFF;
+ }
+
+ ret = true;
+
+FINISH_OFF:
+ if (ret == true) {
+ *mail_list = p_data_tbl;
+ *result_count = count;
+ EM_DEBUG_LOG("COUNT : %d", count);
+ }
+ else if (p_data_tbl != NULL)
+ em_storage_free_mail(&p_data_tbl, count, NULL);
+
+ if (err_code != NULL)
+ *err_code = error;
+
+ EM_PROFILE_END(emStorageGetMails);
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+
+
+/**
+ * em_storage_get_searched_mail_list - Get the mail list information after filtering
+ *
+ *
+ */
+EXPORT_API int em_storage_get_searched_mail_list(int account_id, const char *mailbox_name, int thread_id, int search_type, const char *search_value, int start_index, int limit_count, emf_sort_type_t sorting, int transaction, emf_mail_list_item_t** mail_list, int *result_count, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ int ret = false, error = EM_STORAGE_ERROR_NONE;
+ char conditional_clause[QUERY_SIZE] = {0, };
+
+ EM_IF_NULL_RETURN_VALUE(mail_list, false);
+ EM_IF_NULL_RETURN_VALUE(result_count, false);
+
+ if (!result_count || !mail_list || account_id < ALL_ACCOUNT) {
+ EM_DEBUG_EXCEPTION("select_num[%p], Mail_list[%p]", result_count, mail_list);
+ error = EM_STORAGE_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ em_storage_write_conditional_clause_for_getting_mail_list(account_id, mailbox_name, NULL, thread_id, start_index, limit_count, search_type, search_value, sorting, conditional_clause, QUERY_SIZE, &error);
+
+ EM_DEBUG_LOG("conditional_clause[%s]", conditional_clause);
+
+ if(!em_storage_query_mail_list(conditional_clause, transaction, mail_list, result_count, &error)) {
+ EM_DEBUG_EXCEPTION("em_storage_query_mail_list [%d]", error);
+ goto FINISH_OFF;
+ }
+
+ ret = true;
+
+FINISH_OFF:
+ EM_DEBUG_LOG("em_storage_get_searched_mail_list finish off");
+
+ if (err_code != NULL)
+ *err_code = error;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+
+static int em_storage_get_password_file_name(int account_id, char *recv_password_file_name, char *send_password_file_name)
+{
+ EM_DEBUG_FUNC_BEGIN("account_id[%d]", account_id);
+
+ if (account_id <= 0 || !recv_password_file_name || !send_password_file_name) {
+ EM_DEBUG_EXCEPTION("Invalid parameter");
+ return EM_STORAGE_ERROR_INVALID_PARAM;
+ }
+
+ sprintf(recv_password_file_name, ".email_account_%d_recv", account_id);
+ sprintf(send_password_file_name, ".email_account_%d_send", account_id);
+ EM_DEBUG_FUNC_END();
+ return EM_STORAGE_ERROR_NONE;
+}
+
+static int em_storage_read_password_ss(char *file_name, char **password)
+{
+ EM_DEBUG_FUNC_BEGIN("file_name[%s], password[%p]", file_name, password);
+
+ if (!file_name || !password) {
+ EM_DEBUG_EXCEPTION("Invalid Parameter");
+ return EM_STORAGE_ERROR_INVALID_PARAM;
+ }
+
+ size_t buf_len = 0, read_len = 0;
+ ssm_file_info_t sfi;
+ char *temp_password = NULL;
+ int ret = EM_STORAGE_ERROR_NONE;
+
+ if (ssm_getinfo(file_name, &sfi, SSM_FLAG_SECRET_OPERATION, NULL) < 0) {
+ EM_DEBUG_EXCEPTION("ssm_getinfo() failed.");
+ ret = EM_STORAGE_ERROR_SYSTEM_FAILURE;
+ goto FINISH_OFF;
+ }
+
+ buf_len = sfi.originSize;
+ EM_DEBUG_LOG("password buf_len[%d]", buf_len);
+ if ((temp_password = (char *)malloc(buf_len + 1)) == NULL) {
+ EM_DEBUG_EXCEPTION("malloc failed...");
+
+ ret = EM_STORAGE_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+ memset(temp_password, 0x00, buf_len + 1);
+
+ if (ssm_read(file_name, temp_password, buf_len, &read_len, SSM_FLAG_SECRET_OPERATION, NULL) < 0) {
+ EM_DEBUG_EXCEPTION("ssm_read() failed.");
+ ret = EM_STORAGE_ERROR_SYSTEM_FAILURE;
+ goto FINISH_OFF;
+ }
+
+ EM_DEBUG_LOG("password_file_name[%s], password[%s], originSize[%d], read len[%d]", file_name, temp_password, sfi.originSize, read_len);
+
+ *password = temp_password;
+ temp_password = NULL;
+
+FINISH_OFF:
+ EM_SAFE_FREE(temp_password);
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+
+EXPORT_API int em_storage_get_account_by_id(int account_id, int pulloption, emf_mail_account_tbl_t **account, int transaction, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("account_id[%d], pulloption[%d], account[%p], transaction[%d], err_code[%p]", account_id, pulloption, account, transaction, err_code);
+
+ if (!account) {
+ EM_DEBUG_EXCEPTION("account_id[%d], account[%p]", account_id, account);
+ if (err_code != NULL)
+ *err_code = EM_STORAGE_ERROR_INVALID_PARAM;
+ return false;
+ }
+
+ int ret = false;
+ int error = EM_STORAGE_ERROR_NONE;
+ emf_mail_account_tbl_t* p_data_tbl = NULL;
+ DB_STMT hStmt = NULL;
+ char sql_query_string[QUERY_SIZE] = {0, };
+ int rc = -1;
+ int sql_len = 0;
+ char recv_password_file_name[MAX_PW_FILE_NAME_LENGTH];
+ char send_password_file_name[MAX_PW_FILE_NAME_LENGTH];
+
+ sqlite3 *local_db_handle = em_storage_get_db_connection();
+ EM_STORAGE_START_READ_TRANSACTION(transaction);
+
+ /* Make query string */
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT ");
+ sql_len = strlen(sql_query_string);
+
+ if (pulloption & EMF_ACC_GET_OPT_DEFAULT) {
+ SNPRINTF(sql_query_string + sql_len, sizeof(sql_query_string) - sql_len, "account_bind_type, receiving_server_type, receiving_server_addr, email_addr, user_name, \
+ retrieval_mode, port_num, use_security, sending_server_type, sending_server_addr, sending_port_num, sending_auth, sending_security, sending_user, \
+ display_name, reply_to_addr, return_addr, account_id, keep_on_server, flag1, flag2, pop_before_smtp, apop, logo_icon_path, preset_account, target_storage, check_interval, index_color, sync_status, ");
+ sql_len = strlen(sql_query_string);
+ }
+
+ if (pulloption & EMF_ACC_GET_OPT_ACCOUNT_NAME) {
+ SNPRINTF(sql_query_string + sql_len, sizeof(sql_query_string) - sql_len, " account_name, ");
+ sql_len = strlen(sql_query_string);
+ }
+
+ /* get from secure storage, not from db */
+ if (pulloption & EMF_ACC_GET_OPT_OPTIONS) {
+ SNPRINTF(sql_query_string + sql_len, sizeof(sql_query_string) - sql_len, " priority, keep_local_copy, req_delivery_receipt, req_read_receipt, download_limit, block_address, block_subject, display_name_from, \
+ reply_with_body, forward_with_files, add_myname_card, add_signature, signature, add_my_address_to_bcc, my_account_id, ");
+ sql_len = strlen(sql_query_string);
+ }
+ /* dummy value, FROM WHERE clause */
+ SNPRINTF(sql_query_string + sql_len, sizeof(sql_query_string) - sql_len, "0 FROM mail_account_tbl WHERE account_id = %d", account_id);
+
+ /* FROM clause */
+ EM_DEBUG_LOG("query = [%s]", sql_query_string);
+
+ /* execute a sql and count rows */
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
+ EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("sqlite3_step fail:%d", rc));
+
+ if (rc == SQLITE_DONE) {
+ EM_DEBUG_EXCEPTION("no matched account found...");
+ error = EM_STORAGE_ERROR_ACCOUNT_NOT_FOUND;
+ goto FINISH_OFF;
+ }
+
+ /* Assign query result to structure */
+ if (!(p_data_tbl = (emf_mail_account_tbl_t *)malloc(sizeof(emf_mail_account_tbl_t) * 1))) {
+ EM_DEBUG_EXCEPTION("malloc failed...");
+ error = EM_STORAGE_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ memset(p_data_tbl, 0x00, sizeof(emf_mail_account_tbl_t) * 1);
+ int col_index = 0;
+
+ if (pulloption & EMF_ACC_GET_OPT_DEFAULT) {
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl->account_bind_type), col_index++);
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl->receiving_server_type), col_index++);
+ _getStmtFieldDataString(hStmt, &(p_data_tbl->receiving_server_addr), 0, col_index++);
+ _getStmtFieldDataString(hStmt, &(p_data_tbl->email_addr), 0, col_index++);
+ _getStmtFieldDataString(hStmt, &(p_data_tbl->user_name), 0, col_index++);
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl->retrieval_mode), col_index++);
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl->port_num), col_index++);
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl->use_security), col_index++);
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl->sending_server_type), col_index++);
+ _getStmtFieldDataString(hStmt, &(p_data_tbl->sending_server_addr), 0, col_index++);
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl->sending_port_num), col_index++);
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl->sending_auth), col_index++);
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl->sending_security), col_index++);
+ _getStmtFieldDataString(hStmt, &(p_data_tbl->sending_user), 0, col_index++);
+ _getStmtFieldDataString(hStmt, &(p_data_tbl->display_name), 0, col_index++);
+ _getStmtFieldDataString(hStmt, &(p_data_tbl->reply_to_addr), 0, col_index++);
+ _getStmtFieldDataString(hStmt, &(p_data_tbl->return_addr), 0, col_index++);
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl->account_id), col_index++);
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl->keep_on_server), col_index++);
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl->flag1), col_index++);
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl->flag2), col_index++);
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl->pop_before_smtp), col_index++);
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl->apop), col_index++);
+ _getStmtFieldDataString(hStmt, &(p_data_tbl->logo_icon_path), 0, col_index++);
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl->preset_account), col_index++);
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl->target_storage), col_index++);
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl->check_interval), col_index++);
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl->index_color), col_index++);
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl->sync_status), col_index++);
+ }
+
+ if (pulloption & EMF_ACC_GET_OPT_ACCOUNT_NAME)
+ _getStmtFieldDataString(hStmt, &(p_data_tbl->account_name), 0, col_index++);
+
+ if (pulloption & EMF_ACC_GET_OPT_PASSWORD) {
+ /* get password file name */
+ if ((error = em_storage_get_password_file_name(p_data_tbl->account_id, recv_password_file_name, send_password_file_name)) != EM_STORAGE_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("em_storage_get_password_file_name failed.");
+ goto FINISH_OFF;
+ }
+
+ /* read password from secure storage */
+ if ((error = em_storage_read_password_ss(recv_password_file_name, &(p_data_tbl->password))) < 0) {
+ EM_DEBUG_EXCEPTION(" em_storage_read_password_ss() failed...");
+ goto FINISH_OFF;
+ }
+ EM_DEBUG_LOG("recv_password_file_name[%s], password[%s]", recv_password_file_name, p_data_tbl->password);
+
+ if ((error = em_storage_read_password_ss(send_password_file_name, &(p_data_tbl->sending_password))) < 0) {
+ EM_DEBUG_EXCEPTION(" em_storage_read_password_ss() failed...");
+ goto FINISH_OFF;
+ }
+ EM_DEBUG_LOG("send_password_file_name[%s], password[%s]", send_password_file_name, p_data_tbl->sending_password);
+ }
+
+ if (pulloption & EMF_ACC_GET_OPT_OPTIONS) {
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl->options.priority), col_index++);
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl->options.keep_local_copy), col_index++);
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl->options.req_delivery_receipt), col_index++);
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl->options.req_read_receipt), col_index++);
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl->options.download_limit), col_index++);
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl->options.block_address), col_index++);
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl->options.block_subject), col_index++);
+ _getStmtFieldDataString(hStmt, &(p_data_tbl->options.display_name_from), 0, col_index++);
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl->options.reply_with_body), col_index++);
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl->options.forward_with_files), col_index++);
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl->options.add_myname_card), col_index++);
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl->options.add_signature), col_index++);
+ _getStmtFieldDataString(hStmt, &(p_data_tbl->options.signature), 0, col_index++);
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl->options.add_my_address_to_bcc), col_index++);
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl->my_account_id), col_index++);
+ }
+
+ ret = true;
+
+FINISH_OFF:
+ if (ret == true)
+ *account = p_data_tbl;
+ else {
+ if (p_data_tbl)
+ em_storage_free_account((emf_mail_account_tbl_t **)&p_data_tbl, 1, NULL);
+ }
+ if (hStmt != NULL) {
+ rc = sqlite3_finalize(hStmt);
+ if (rc != SQLITE_OK) {
+ EM_DEBUG_EXCEPTION("sqlite3_finalize failed - %d", rc);
+ error = EM_STORAGE_ERROR_DB_FAILURE;
+ }
+ }
+
+ EM_STORAGE_FINISH_READ_TRANSACTION(transaction);
+ _DISCONNECT_DB;
+
+ if (err_code != NULL)
+ *err_code = error;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+EXPORT_API int em_storage_get_password_length_of_account(int account_id, int *password_length, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("account_id[%d], password_length[%p], err_code[%p]", account_id, password_length, err_code);
+
+ if (account_id <= 0 || password_length == NULL) {
+ EM_DEBUG_EXCEPTION("EM_STORAGE_ERROR_INVALID_PARAM");
+ if (err_code != NULL)
+ *err_code = EM_STORAGE_ERROR_INVALID_PARAM;
+ return false;
+ }
+
+ int ret = false;
+ int error = EM_STORAGE_ERROR_NONE;
+ char recv_password_file_name[MAX_PW_FILE_NAME_LENGTH];
+ char send_password_file_name[MAX_PW_FILE_NAME_LENGTH];
+ char *temp_password = NULL;
+
+
+ /* get password file name */
+ if ((error = em_storage_get_password_file_name(account_id, recv_password_file_name, send_password_file_name)) != EM_STORAGE_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("em_storage_get_password_file_name failed.");
+ goto FINISH_OFF;
+ }
+
+ /* read password from secure storage */
+ if ((error = em_storage_read_password_ss(recv_password_file_name, &temp_password)) < 0 || !temp_password) {
+ EM_DEBUG_EXCEPTION(" em_storage_read_password_ss() failed...");
+ goto FINISH_OFF;
+ }
+
+ *password_length = strlen(temp_password);
+
+ EM_DEBUG_LOG("recv_password_file_name[%s], *password_length[%d]", recv_password_file_name, *password_length);
+
+ ret = true;
+
+FINISH_OFF:
+ EM_SAFE_FREE(temp_password);
+
+ if (err_code != NULL)
+ *err_code = error;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+EXPORT_API int em_storage_update_account(int account_id, emf_mail_account_tbl_t* account, int transaction, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("account_id[%d], account[%p], transaction[%d], err_code[%p]", account_id, account, transaction, err_code);
+
+ if (account_id < FIRST_ACCOUNT_ID || !account) {
+ EM_DEBUG_EXCEPTION("EM_STORAGE_ERROR_INVALID_PARAM");
+ if (err_code != NULL)
+ *err_code = EM_STORAGE_ERROR_INVALID_PARAM;
+ return false;
+ }
+
+ int error = EM_STORAGE_ERROR_NONE;
+ int rc, ret = false;
+
+ DB_STMT hStmt = NULL;
+ char sql_query_string[QUERY_SIZE] = {0, };
+ char recv_password_file_name[MAX_PW_FILE_NAME_LENGTH];
+ char send_password_file_name[MAX_PW_FILE_NAME_LENGTH];
+
+ sqlite3 *local_db_handle = em_storage_get_db_connection();
+ EM_STORAGE_START_WRITE_TRANSACTION(transaction, error);
+
+ SNPRINTF(sql_query_string, sizeof(sql_query_string),
+ "UPDATE mail_account_tbl SET"
+ " account_bind_type = ?"
+ ", account_name = ?"
+ ", receiving_server_type = ?"
+ ", receiving_server_addr = ?"
+ ", email_addr = ?"
+ ", user_name = ?"
+ ", retrieval_mode = ?"
+ ", port_num = ?"
+ ", use_security = ?"
+ ", sending_server_type = ?"
+ ", sending_server_addr = ?"
+ ", sending_port_num = ?"
+ ", sending_auth = ?"
+ ", sending_security = ?"
+ ", sending_user = ?"
+ ", display_name = ?"
+ ", reply_to_addr = ?"
+ ", return_addr = ?"
+ ", keep_on_server = ?"
+ ", flag1 = ?"
+ ", flag2 = ?"
+ ", pop_before_smtp = ?" /* POP before SMTP authentication */
+ ", apop = ?" /* APOP authentication */
+ ", logo_icon_path = ?" /* Receving Option : Account logo icon */
+ ", preset_account = ?" /* Receving Option : Preset account or not */
+ ", target_storage = ?" /* Receving Option : Specifies the targetStorage. 0 is phone, 1 is MMC */
+ ", check_interval = ?" /* Receving Option : Specifies the check interval. Unit is minute */
+ ", priority = ?" /* Sending Option : Specifies the prority. 1=high 3=normal 5=low */
+ ", keep_local_copy = ?" /* Sending Option : */
+ ", req_delivery_receipt = ?" /* Sending Option : */
+ ", req_read_receipt = ?" /* Sending Option : */
+ ", download_limit = ?" /* Sending Option : */
+ ", block_address = ?" /* Sending Option : */
+ ", block_subject = ?" /* Sending Option : */
+ ", display_name_from = ?" /* Sending Option : */
+ ", reply_with_body = ?" /* Sending Option : */
+ ", forward_with_files = ?" /* Sending Option : */
+ ", add_myname_card = ?" /* Sending Option : */
+ ", add_signature = ?" /* Sending Option : */
+ ", signature = ?" /* Sending Option : */
+ ", add_my_address_to_bcc = ?" /* Sending Option : */
+ ", my_account_id = ?" /* Support 'My Account' */
+ ", index_color = ?" /* Index color */
+ ", sync_status = ?" /* Sync Status */
+ " WHERE account_id = ?");
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
+ EM_DEBUG_LOG("After sqlite3_prepare hStmt = %p", hStmt);
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ int i = 0;
+
+ _bindStmtFieldDataInt(hStmt, i++, account->account_bind_type);
+ _bindStmtFieldDataString(hStmt, i++, (char *)account->account_name, 0, ACCOUNT_NAME_LEN_IN_MAIL_ACCOUNT_TBL);
+ _bindStmtFieldDataInt(hStmt, i++, account->receiving_server_type);
+ _bindStmtFieldDataString(hStmt, i++, (char *)account->receiving_server_addr, 0, RECEIVING_SERVER_ADDR_LEN_IN_MAIL_ACCOUNT_TBL);
+ _bindStmtFieldDataString(hStmt, i++, (char *)account->email_addr, 0, EMAIL_ADDR_LEN_IN_MAIL_ACCOUNT_TBL);
+ _bindStmtFieldDataString(hStmt, i++, (char *)account->user_name, 0, USER_NAME_LEN_IN_MAIL_ACCOUNT_TBL);
+ _bindStmtFieldDataInt(hStmt, i++, account->retrieval_mode);
+ _bindStmtFieldDataInt(hStmt, i++, account->port_num);
+ _bindStmtFieldDataInt(hStmt, i++, account->use_security);
+ _bindStmtFieldDataInt(hStmt, i++, account->sending_server_type);
+ _bindStmtFieldDataString(hStmt, i++, (char *)account->sending_server_addr, 0, SENDING_SERVER_ADDR_LEN_IN_MAIL_ACCOUNT_TBL);
+ _bindStmtFieldDataInt(hStmt, i++, account->sending_port_num);
+ _bindStmtFieldDataInt(hStmt, i++, account->sending_auth);
+ _bindStmtFieldDataInt(hStmt, i++, account->sending_security);
+ _bindStmtFieldDataString(hStmt, i++, (char *)account->sending_user, 0, SENDING_USER_LEN_IN_MAIL_ACCOUNT_TBL);
+ _bindStmtFieldDataString(hStmt, i++, (char *)account->display_name, 0, DISPLAY_NAME_LEN_IN_MAIL_ACCOUNT_TBL);
+ _bindStmtFieldDataString(hStmt, i++, (char *)account->reply_to_addr, 0, REPLY_TO_ADDR_LEN_IN_MAIL_ACCOUNT_TBL);
+ _bindStmtFieldDataString(hStmt, i++, (char *)account->return_addr, 0, RETURN_ADDR_LEN_IN_MAIL_ACCOUNT_TBL);
+ _bindStmtFieldDataInt(hStmt, i++, account->keep_on_server);
+ _bindStmtFieldDataInt(hStmt, i++, account->flag1);
+ _bindStmtFieldDataInt(hStmt, i++, account->flag2);
+ _bindStmtFieldDataInt(hStmt, i++, account->pop_before_smtp);
+ _bindStmtFieldDataInt(hStmt, i++, account->apop);
+ _bindStmtFieldDataString(hStmt, i++, account->logo_icon_path, 0, LOGO_ICON_PATH_LEN_IN_MAIL_ACCOUNT_TBL);
+ _bindStmtFieldDataInt(hStmt, i++, account->preset_account);
+ _bindStmtFieldDataInt(hStmt, i++, account->target_storage);
+ _bindStmtFieldDataInt(hStmt, i++, account->check_interval);
+ _bindStmtFieldDataInt(hStmt, i++, account->options.priority);
+ _bindStmtFieldDataInt(hStmt, i++, account->options.keep_local_copy);
+ _bindStmtFieldDataInt(hStmt, i++, account->options.req_delivery_receipt);
+ _bindStmtFieldDataInt(hStmt, i++, account->options.req_read_receipt);
+ _bindStmtFieldDataInt(hStmt, i++, account->options.download_limit);
+ _bindStmtFieldDataInt(hStmt, i++, account->options.block_address);
+ _bindStmtFieldDataInt(hStmt, i++, account->options.block_subject);
+ _bindStmtFieldDataString(hStmt, i++, account->options.display_name_from, 0, DISPLAY_NAME_FROM_LEN_IN_MAIL_ACCOUNT_TBL);
+ _bindStmtFieldDataInt(hStmt, i++, account->options.reply_with_body);
+ _bindStmtFieldDataInt(hStmt, i++, account->options.forward_with_files);
+ _bindStmtFieldDataInt(hStmt, i++, account->options.add_myname_card);
+ _bindStmtFieldDataInt(hStmt, i++, account->options.add_signature);
+ _bindStmtFieldDataString(hStmt, i++, account->options.signature, 0, SIGNATURE_LEN_IN_MAIL_ACCOUNT_TBL);
+ if (account->options.add_my_address_to_bcc != 0)
+ account->options.add_my_address_to_bcc = 1;
+ _bindStmtFieldDataInt(hStmt, i++, account->options.add_my_address_to_bcc);
+ _bindStmtFieldDataInt(hStmt, i++, account->my_account_id);
+ _bindStmtFieldDataInt(hStmt, i++, account->index_color);
+ _bindStmtFieldDataInt(hStmt, i++, account->sync_status);
+ _bindStmtFieldDataInt(hStmt, i++, account_id);
+
+ /* rc = sqlite3_step(hStmt); */
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
+ EM_DEBUG_DB_EXEC((SQLITE_FULL == rc), {error = EM_STORAGE_ERROR_DB_IS_FULL;goto FINISH_OFF; },
+ ("sqlite3_step fail:%d", rc));
+ EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("sqlite3_step fail:%d", rc));
+
+ /* validate account existence */
+ rc = sqlite3_changes(local_db_handle);
+ if (rc == 0) {
+ EM_DEBUG_EXCEPTION(" no matched account found...");
+
+ error = EM_STORAGE_ERROR_ACCOUNT_NOT_FOUND;
+ goto FINISH_OFF;
+ }
+
+ /* get password file name */
+ if ((error = em_storage_get_password_file_name(account_id, recv_password_file_name, send_password_file_name)) != EM_STORAGE_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("em_storage_get_password_file_name failed.");
+ goto FINISH_OFF;
+ }
+
+ /* save passwords to the secure storage */
+ EM_DEBUG_LOG("save to the secure storage : recv_file[%s], recv_pass[%s], send_file[%s], send_pass[%s]", recv_password_file_name, account->password, send_password_file_name, account->sending_password);
+ if (account->password && (strlen(account->password) > 0)) {
+ if (ssm_write_buffer(account->password, strlen(account->password), recv_password_file_name, SSM_FLAG_SECRET_OPERATION, NULL) < 0) {
+ EM_DEBUG_EXCEPTION(" ssm_write_buffer failed -recv password : file[%s]", recv_password_file_name);
+ error = EM_STORAGE_ERROR_SYSTEM_FAILURE;
+ goto FINISH_OFF;
+ }
+ }
+
+ if (account->sending_password && (strlen(account->sending_password) > 0)) {
+ if (ssm_write_buffer(account->sending_password, strlen(account->sending_password), send_password_file_name, SSM_FLAG_SECRET_OPERATION, NULL) < 0) {
+ EM_DEBUG_EXCEPTION(" ssm_write_buffer failed -send password : file[%s]", send_password_file_name);
+ error = EM_STORAGE_ERROR_SYSTEM_FAILURE;
+ goto FINISH_OFF;
+ }
+ }
+
+ if (!em_storage_notify_storage_event(NOTI_ACCOUNT_UPDATE, account->account_id, 0, NULL, 0))
+ EM_DEBUG_EXCEPTION(" em_storage_notify_storage_event[ NOTI_ACCOUNT_UPDATE] : Notification Failed >>> ");
+ ret = true;
+
+FINISH_OFF:
+
+ if (hStmt != NULL) {
+ EM_DEBUG_LOG(" Before sqlite3_finalize hStmt = %p", hStmt);
+
+ rc = sqlite3_finalize(hStmt);
+ if (rc != SQLITE_OK) {
+ EM_DEBUG_LOG(" sqlite3_finalize failed - %d", rc);
+ error = EM_STORAGE_ERROR_DB_FAILURE;
+ }
+ }
+
+ EM_STORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
+
+ _DISCONNECT_DB;
+
+ if (err_code != NULL)
+ *err_code = error;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+EXPORT_API int em_storage_get_sync_status_of_account(int account_id, int *result_sync_status,int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("account_id[%d], result_sync_status [%p], err_code[%p]", account_id, result_sync_status, err_code);
+
+ if(!result_sync_status) {
+ EM_DEBUG_EXCEPTION("EM_STORAGE_ERROR_INVALID_PARAM");
+ if (err_code != NULL)
+ *err_code = EM_STORAGE_ERROR_INVALID_PARAM;
+ return false;
+ }
+
+ int error = EM_STORAGE_ERROR_NONE, rc, ret = false, sync_status, count, i, col_index;
+ char sql_query_string[QUERY_SIZE] = {0, };
+ char **result = NULL;
+ sqlite3 *local_db_handle = em_storage_get_db_connection();
+
+ if(account_id)
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT sync_status FROM mail_account_tbl WHERE account_id = %d", account_id);
+ else
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT sync_status FROM mail_account_tbl");
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, &count, 0, NULL), rc);
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc && -1 != rc), {error = EM_STORAGE_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+ ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ if (!count) {
+ EM_DEBUG_EXCEPTION("no matched account found...");
+ error = EM_STORAGE_ERROR_ACCOUNT_NOT_FOUND;
+ goto FINISH_OFF;
+ }
+
+ col_index = 1;
+ *result_sync_status = 0;
+
+ for(i = 0; i < count; i++) {
+ _getTableFieldDataInt(result, &sync_status, col_index++);
+ *result_sync_status |= sync_status;
+ }
+
+ EM_DEBUG_LOG("sync_status [%d]", sync_status);
+
+ sqlite3_free_table(result);
+
+ ret = true;
+
+FINISH_OFF:
+
+ _DISCONNECT_DB;
+
+ if (err_code != NULL)
+ *err_code = error;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+EXPORT_API int em_storage_update_sync_status_of_account(int account_id, emf_set_type_t set_operator, int sync_status, int transaction, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("account_id[%d], set_operator[%d], sync_status [%d], transaction[%d], err_code[%p]", account_id, set_operator, sync_status, transaction, err_code);
+
+ int error = EM_STORAGE_ERROR_NONE, rc, ret = false, set_value = sync_status, result_sync_status;
+ char sql_query_string[QUERY_SIZE] = {0, };
+ sqlite3 *local_db_handle = em_storage_get_db_connection();
+
+ if(set_operator != SET_TYPE_SET && account_id) {
+ if(!em_storage_get_sync_status_of_account(account_id, &result_sync_status, &error)) {
+ EM_DEBUG_EXCEPTION("em_storage_get_sync_status_of_account failed [%d]", error);
+ goto FINISH_OFF;
+ }
+ switch(set_operator) {
+ case SET_TYPE_UNION :
+ set_value = result_sync_status | set_value;
+ break;
+ case SET_TYPE_MINUS :
+ set_value = result_sync_status & (~set_value);
+ break;
+ default:
+ EM_DEBUG_EXCEPTION("EMF_ERROR_NOT_SUPPORTED [%d]", set_operator);
+ error = EMF_ERROR_NOT_SUPPORTED;
+ break;
+ }
+ EM_DEBUG_LOG("set_value [%d]", set_value);
+ }
+
+ EM_STORAGE_START_WRITE_TRANSACTION(transaction, error);
+
+ if(account_id)
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), "UPDATE mail_account_tbl SET sync_status = %d WHERE account_id = %d", set_value, account_id);
+ else
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), "UPDATE mail_account_tbl SET sync_status = %d WHERE receiving_server_type <> 5", set_value);
+
+ EM_DEBUG_LOG("sql_query_string [%s]", sql_query_string);
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ rc = sqlite3_changes(local_db_handle);
+
+ if (rc == 0) {
+ EM_DEBUG_EXCEPTION("no matched account found...");
+ error = EM_STORAGE_ERROR_ACCOUNT_NOT_FOUND;
+ goto FINISH_OFF;
+ }
+
+ if (!em_storage_notify_storage_event(NOTI_ACCOUNT_UPDATE_SYNC_STATUS, account_id, 0, NULL, 0))
+ EM_DEBUG_EXCEPTION("em_storage_notify_storage_event[NOTI_ACCOUNT_UPDATE_SYNC_STATUS] : Notification failed");
+ ret = true;
+
+FINISH_OFF:
+
+ EM_STORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
+
+ _DISCONNECT_DB;
+
+ if (err_code != NULL)
+ *err_code = error;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+EXPORT_API int em_storage_add_account(emf_mail_account_tbl_t* account, int transaction, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("account[%p], transaction[%d], err_code[%p]", account, transaction, err_code);
+
+ if (!account) {
+ EM_DEBUG_EXCEPTION("account[%p], transaction[%d], err_code[%p]", account, transaction, err_code);
+ if (err_code != NULL)
+ *err_code = EM_STORAGE_ERROR_INVALID_PARAM;
+ return false;
+ }
+
+ int rc = -1, ret = false;
+ int error = EM_STORAGE_ERROR_NONE;
+ DB_STMT hStmt = NULL;
+ char sql_query_string[QUERY_SIZE] = {0, };
+ char recv_password_file_name[MAX_PW_FILE_NAME_LENGTH];
+ char send_password_file_name[MAX_PW_FILE_NAME_LENGTH];
+
+ sqlite3 *local_db_handle = em_storage_get_db_connection();
+
+ EM_STORAGE_START_WRITE_TRANSACTION(transaction, error);
+
+ char *sql = "SELECT max(rowid) FROM mail_account_tbl;";
+ char **result = NULL;
+
+ /* rc = sqlite3_get_table(local_db_handle, sql, &result, NULL, NULL, NULL); */
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql, &result, NULL, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EM_STORAGE_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+ ("SQL(%s) sqlite3_get_table fail:%d -%s", sql, rc, sqlite3_errmsg(local_db_handle)));
+
+ if (NULL==result[1]) rc = 1;
+ else rc = atoi(result[1])+1;
+ sqlite3_free_table(result);
+ result = NULL;
+
+ account->account_id = rc;
+
+ if ((error = em_storage_get_password_file_name(account->account_id, recv_password_file_name, send_password_file_name)) != EM_STORAGE_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("em_storage_get_password_file_name failed.");
+ goto FINISH_OFF;
+ }
+
+ EM_DEBUG_LOG(" >>>> ACCOUNT_ID [ %d ] ", account->account_id);
+ SNPRINTF(sql_query_string, sizeof(sql_query_string),
+ "INSERT INTO mail_account_tbl VALUES "
+ "( "
+ " ? "
+ " , ? "
+ " , ? "
+ " , ? "
+ " , ? "
+ " , ? "
+ " , ? " /* password - for receving */
+ " , ? "
+ " , ? "
+ " , ? "
+ " , ? "
+ " , ? "
+ " , ? "
+ " , ? "
+ " , ? "
+ " , ? "
+ " , ? " /* sending_password */
+ " , ? "
+ " , ? "
+ " , ? "
+ " , ? "
+ " , ? "
+ " , ? "
+ " , ? "
+ " , ? " /* POP before SMTP authentication */
+ " , ? " /* APOP Authentication */
+ " , ? "
+ " , ? "
+ " , ? "
+ " , ? "
+ " , ? "
+ " , ? "
+ " , ? "
+ " , ? "
+ " , ? "
+ " , ? "
+ " , ? "
+ " , ? "
+ " , ? "
+ " , ? "
+ " , ? "
+ " , ? "
+ " , ? "
+ " , ? " /* add full_address_bcc */
+ " , ? " /* my account id */
+ " , ? " /* index_color */
+ " , ? " /* Sync Status */
+ ") ");
+
+
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ EM_DEBUG_LOG(">>>> SQL STMT [ %s ] ", sql_query_string);
+ _bindStmtFieldDataInt(hStmt, ACCOUNT_BIND_TYPE_IDX_IN_MAIL_ACCOUNT_TBL, account->account_bind_type);
+ _bindStmtFieldDataString(hStmt, ACCOUNT_NAME_IDX_IN_MAIL_ACCOUNT_TBL, (char *)account->account_name, 0, ACCOUNT_NAME_LEN_IN_MAIL_ACCOUNT_TBL);
+ _bindStmtFieldDataInt(hStmt, RECEIVING_SERVER_TYPE_TYPE_IDX_IN_MAIL_ACCOUNT_TBL, account->receiving_server_type);
+ _bindStmtFieldDataString(hStmt, RECEIVING_SERVER_ADDR_IDX_IN_MAIL_ACCOUNT_TBL, (char *)account->receiving_server_addr, 0, RECEIVING_SERVER_ADDR_LEN_IN_MAIL_ACCOUNT_TBL);
+ _bindStmtFieldDataString(hStmt, EMAIL_ADDR_IDX_IN_MAIL_ACCOUNT_TBL, (char *)account->email_addr, 0, EMAIL_ADDR_LEN_IN_MAIL_ACCOUNT_TBL);
+ _bindStmtFieldDataString(hStmt, USER_NAME_IDX_IN_MAIL_ACCOUNT_TBL, (char *)account->user_name, 0, USER_NAME_LEN_IN_MAIL_ACCOUNT_TBL);
+ _bindStmtFieldDataString(hStmt, PASSWORD_IDX_IN_MAIL_ACCOUNT_TBL, (char *)"", 0, PASSWORD_LEN_IN_MAIL_ACCOUNT_TBL);
+ _bindStmtFieldDataInt(hStmt, RETRIEVAL_MODE_IDX_IN_MAIL_ACCOUNT_TBL, account->retrieval_mode);
+ _bindStmtFieldDataInt(hStmt, PORT_NUM_IDX_IN_MAIL_ACCOUNT_TBL, account->port_num);
+ _bindStmtFieldDataInt(hStmt, USE_SECURITY_IDX_IN_MAIL_ACCOUNT_TBL, account->use_security);
+ _bindStmtFieldDataInt(hStmt, SENDING_SERVER_TYPE_IDX_IN_MAIL_ACCOUNT_TBL, account->sending_server_type);
+ _bindStmtFieldDataString(hStmt, SENDING_SERVER_ADDR_IDX_IN_MAIL_ACCOUNT_TBL, (char *)account->sending_server_addr, 0, SENDING_SERVER_ADDR_LEN_IN_MAIL_ACCOUNT_TBL);
+ _bindStmtFieldDataInt(hStmt, SENDING_PORT_NUM_IDX_IN_MAIL_ACCOUNT_TBL, account->sending_port_num);
+ _bindStmtFieldDataInt(hStmt, SENDING_AUTH_IDX_IN_MAIL_ACCOUNT_TBL, account->sending_auth);
+ _bindStmtFieldDataInt(hStmt, SENDING_SECURITY_IDX_IN_MAIL_ACCOUNT_TBL, account->sending_security);
+ _bindStmtFieldDataString(hStmt, SENDING_USER_IDX_IN_MAIL_ACCOUNT_TBL, (char *)account->sending_user, 0, SENDING_USER_LEN_IN_MAIL_ACCOUNT_TBL);
+ _bindStmtFieldDataString(hStmt, SENDING_PASSWORD_IDX_IN_MAIL_ACCOUNT_TBL, (char *)"", 0, SENDING_PASSWORD_LEN_IN_MAIL_ACCOUNT_TBL);
+ _bindStmtFieldDataString(hStmt, DISPLAY_NAME_IDX_IN_MAIL_ACCOUNT_TBL, (char *)account->display_name, 0, DISPLAY_NAME_LEN_IN_MAIL_ACCOUNT_TBL);
+ _bindStmtFieldDataString(hStmt, REPLY_TO_ADDR_IDX_IN_MAIL_ACCOUNT_TBL, (char *)account->reply_to_addr, 0, REPLY_TO_ADDR_LEN_IN_MAIL_ACCOUNT_TBL);
+ _bindStmtFieldDataString(hStmt, RETURN_ADDR_IDX_IN_MAIL_ACCOUNT_TBL, (char *)account->return_addr, 0, RETURN_ADDR_LEN_IN_MAIL_ACCOUNT_TBL);
+ _bindStmtFieldDataInt(hStmt, ACCOUNT_ID_IDX_IN_MAIL_ACCOUNT_TBL, account->account_id);
+ _bindStmtFieldDataInt(hStmt, KEEP_ON_SERVER_IDX_IN_MAIL_ACCOUNT_TBL, account->keep_on_server);
+ _bindStmtFieldDataInt(hStmt, FLAG1_IDX_IN_MAIL_ACCOUNT_TBL, account->flag1);
+ _bindStmtFieldDataInt(hStmt, FLAG2_IDX_IN_MAIL_ACCOUNT_TBL, account->flag2);
+ _bindStmtFieldDataInt(hStmt, POP_BEFORE_SMTP_IDX_IN_MAIL_ACCOUNT_TBL, account->pop_before_smtp); /* POP before SMTP authentication [deepam.p@siso.com] */
+ _bindStmtFieldDataInt(hStmt, APOP_IDX_IN_MAIL_ACCOUNT_TBL, account->apop); /* APOP Support [deepam.p@siso.com] */
+ _bindStmtFieldDataString(hStmt, LOGO_ICON_PATH_IDX_IN_MAIL_ACCOUNT_TBL, account->logo_icon_path, 0, LOGO_ICON_PATH_LEN_IN_MAIL_ACCOUNT_TBL);
+ _bindStmtFieldDataInt(hStmt, PRESET_ACCOUNT_IDX_IN_MAIL_ACCOUNT_TBL, account->preset_account);
+ _bindStmtFieldDataInt(hStmt, TARGET_STORAGE_IDX_IN_MAIL_ACCOUNT_TBL, account->target_storage);
+ _bindStmtFieldDataInt(hStmt, CHECK_INTERVAL_IDX_IN_MAIL_ACCOUNT_TBL, account->check_interval);
+ _bindStmtFieldDataInt(hStmt, PRIORITY_IDX_IN_MAIL_ACCOUNT_TBL, account->options.priority);
+ _bindStmtFieldDataInt(hStmt, KEEP_LOCAL_COPY_IDX_IN_MAIL_ACCOUNT_TBL, account->options.keep_local_copy);
+ _bindStmtFieldDataInt(hStmt, REQ_DELIVERY_RECEIPT_IDX_IN_MAIL_ACCOUNT_TBL, account->options.req_delivery_receipt);
+ _bindStmtFieldDataInt(hStmt, REQ_READ_RECEIPT_IDX_IN_MAIL_ACCOUNT_TBL, account->options.req_read_receipt);
+ _bindStmtFieldDataInt(hStmt, DOWNLOAD_LIMIT_IDX_IN_MAIL_ACCOUNT_TBL, account->options.download_limit);
+ _bindStmtFieldDataInt(hStmt, BLOCK_ADDRESS_IDX_IN_MAIL_ACCOUNT_TBL, account->options.block_address);
+ _bindStmtFieldDataInt(hStmt, BLOCK_SUBJECT_IDX_IN_MAIL_ACCOUNT_TBL, account->options.block_subject);
+ _bindStmtFieldDataString(hStmt, DISPLAY_NAME_FROM_IDX_IN_MAIL_ACCOUNT_TBL, account->options.display_name_from, 0, DISPLAY_NAME_FROM_LEN_IN_MAIL_ACCOUNT_TBL);
+ _bindStmtFieldDataInt(hStmt, REPLY_WITH_BODY_IDX_IN_MAIL_ACCOUNT_TBL, account->options.reply_with_body);
+ _bindStmtFieldDataInt(hStmt, FORWARD_WITH_FILES_IDX_IN_MAIL_ACCOUNT_TBL, account->options.forward_with_files);
+ _bindStmtFieldDataInt(hStmt, ADD_MYNAME_CARD_IDX_IN_MAIL_ACCOUNT_TBL, account->options.add_myname_card);
+ _bindStmtFieldDataInt(hStmt, ADD_SIGNATURE_IDX_IN_MAIL_ACCOUNT_TBL, account->options.add_signature);
+ _bindStmtFieldDataString(hStmt, SIGNATURE_IDX_IN_MAIL_ACCOUNT_TBL, account->options.signature, 0, SIGNATURE_LEN_IN_MAIL_ACCOUNT_TBL);
+ if (account->options.add_my_address_to_bcc != 0)
+ account->options.add_my_address_to_bcc = 1;
+ _bindStmtFieldDataInt(hStmt, ADD_MY_ADDRESS_TO_BCC_IDX_IN_MAIL_ACCOUNT_TBL, account->options.add_my_address_to_bcc);
+ _bindStmtFieldDataInt(hStmt, MY_ACCOUNT_ID_IDX_IN_MAIL_ACCOUNT_TBL, account->my_account_id);
+ _bindStmtFieldDataInt(hStmt, INDEX_COLOR_IDX_IN_MAIL_ACCOUNT_TBL, account->index_color);
+ _bindStmtFieldDataInt(hStmt, SYNC_STATUS_IDX_IN_MAIL_ACCOUNT_TBL, account->sync_status);
+
+ /* rc = sqlite3_step(hStmt); */
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
+
+ EM_DEBUG_DB_EXEC((rc == SQLITE_FULL), {error = EM_STORAGE_ERROR_DB_IS_FULL;goto FINISH_OFF; },
+ ("sqlite3_step fail:%d", rc));
+ EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("sqlite3_step fail:%d, errmsg = %s.", rc, sqlite3_errmsg(local_db_handle)));
+
+
+ /* save passwords to the secure storage */
+ EM_DEBUG_LOG("save to the secure storage : recv_file[%s], recv_pass[%s], send_file[%s], send_pass[%s]", recv_password_file_name, account->password, send_password_file_name, account->sending_password);
+ if (ssm_write_buffer(account->password, strlen(account->password), recv_password_file_name, SSM_FLAG_SECRET_OPERATION, NULL) < 0) {
+ EM_DEBUG_EXCEPTION("ssm_write_buffer failed - recv password : file[%s]", recv_password_file_name);
+ error = EM_STORAGE_ERROR_SYSTEM_FAILURE;
+ goto FINISH_OFF;
+ }
+ if (ssm_write_buffer(account->sending_password, strlen(account->sending_password), send_password_file_name, SSM_FLAG_SECRET_OPERATION, NULL) < 0) {
+ EM_DEBUG_EXCEPTION("ssm_write_buffer failed - send password : file[%s]", send_password_file_name);
+ error = EM_STORAGE_ERROR_SYSTEM_FAILURE;
+ goto FINISH_OFF;
+ }
+
+ if (!em_storage_notify_storage_event(NOTI_ACCOUNT_ADD, account->account_id, 0, NULL, 0))
+ EM_DEBUG_EXCEPTION("em_storage_notify_storage_event[NOTI_ACCOUNT_ADD] : Notification failed");
+ ret = true;
+
+FINISH_OFF:
+
+ if (hStmt != NULL) {
+ rc = sqlite3_finalize(hStmt);
+ if (rc != SQLITE_OK) {
+ EM_DEBUG_LOG("sqlite3_finalize failed - %d", rc);
+ error = EM_STORAGE_ERROR_DB_FAILURE;
+ }
+ }
+ else
+ EM_DEBUG_LOG("hStmt is NULL!!!");
+
+ EM_STORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
+ _DISCONNECT_DB;
+
+ if (err_code != NULL)
+ *err_code = error;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+
+EXPORT_API int em_storage_delete_account(int account_id, int transaction, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("account_id[%d], transaction[%d], err_code[%p]", account_id, transaction, err_code);
+
+ if (account_id < FIRST_ACCOUNT_ID) {
+ EM_DEBUG_EXCEPTION(" account_id[%d]", account_id);
+
+ if (err_code != NULL)
+ *err_code = EM_STORAGE_ERROR_INVALID_PARAM;
+ return false;
+ }
+
+ int rc = -1, ret = false;
+ int error = EM_STORAGE_ERROR_NONE;
+ sqlite3 *local_db_handle = em_storage_get_db_connection();
+ EM_STORAGE_START_WRITE_TRANSACTION(transaction, error);
+
+ /* TODO : delete password files - file names can be obtained from db or a rule that makes a name */
+ DB_STMT hStmt = NULL;
+ char sql_query_string[QUERY_SIZE] = {0, };
+ char recv_password_file_name[MAX_PW_FILE_NAME_LENGTH];
+ char send_password_file_name[MAX_PW_FILE_NAME_LENGTH];
+
+/*
+ memset(sql_query_string, 0x00, sizeof(sql_query_string));
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT password, sending_password FROM mail_account_tbl WHERE account_id = %d", account_id);
+ EM_DEBUG_LOG("query = [%s]", sql_query_string);
+
+ execute a sql and count rows
+ rc = sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL);
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ rc = sqlite3_step(hStmt);
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
+ EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("sqlite3_step fail:%d", rc));
+
+ if (rc == SQLITE_DONE) {
+ EM_DEBUG_LOG(" no matched account found...");
+
+ error = EM_STORAGE_ERROR_ACCOUNT_NOT_FOUND;
+ goto FINISH_OFF;
+ }
+ _getStmtFieldDataString(hStmt, &(recv_password_file_name), 0, 0);
+ _getStmtFieldDataString(hStmt, &(send_password_file_name), 0, 1);
+*/
+ /* get password file name */
+ if ((error = em_storage_get_password_file_name(account_id, recv_password_file_name, send_password_file_name)) != EM_STORAGE_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("em_storage_get_password_file_name failed.");
+ goto FINISH_OFF;
+ }
+
+ /* delete from db */
+ memset(sql_query_string, 0x00, sizeof(sql_query_string));
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), "DELETE FROM mail_account_tbl WHERE account_id = %d", account_id);
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC((rc == SQLITE_FULL), {error = EM_STORAGE_ERROR_DB_IS_FULL;goto FINISH_OFF; },
+ ("sqlite3_exec fail:%d", rc));
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ /* validate account existence */
+ rc = sqlite3_changes(local_db_handle);
+ if (rc == 0) {
+ EM_DEBUG_EXCEPTION(" no matched account found...");
+ error = EM_STORAGE_ERROR_ACCOUNT_NOT_FOUND;
+ goto FINISH_OFF;
+ }
+
+ /* delete from secure storage */
+ if (ssm_delete_file(recv_password_file_name, SSM_FLAG_SECRET_OPERATION, NULL) < 0) {
+ EM_DEBUG_EXCEPTION(" ssm_delete_file failed -recv password : file[%s]", recv_password_file_name);
+ error = EM_STORAGE_ERROR_SYSTEM_FAILURE;
+ goto FINISH_OFF;
+ }
+ if (ssm_delete_file(send_password_file_name, SSM_FLAG_SECRET_OPERATION, NULL) < 0) {
+ EM_DEBUG_EXCEPTION(" ssm_delete_file failed -send password : file[%s]", send_password_file_name);
+ error = EM_STORAGE_ERROR_SYSTEM_FAILURE;
+ goto FINISH_OFF;
+ }
+ ret = true;
+
+FINISH_OFF:
+
+ if (hStmt != NULL) {
+ rc = sqlite3_finalize(hStmt);
+ if (rc != SQLITE_OK) {
+ EM_DEBUG_LOG(" sqlite3_finalize failed - %d", rc);
+ error = EM_STORAGE_ERROR_DB_FAILURE;
+ }
+ }
+
+ EM_STORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
+ _DISCONNECT_DB;
+
+ if (err_code != NULL)
+ *err_code = error;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+
+EXPORT_API int em_storage_free_account(emf_mail_account_tbl_t** account_list, int count, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("account_list[%p], count[%d], err_code[%p]", account_list, count, err_code);
+
+ int ret = false;
+ int error = EM_STORAGE_ERROR_NONE;
+
+ if (count > 0) {
+ if (!account_list || !*account_list) {
+ EM_DEBUG_EXCEPTION("account_list[%p], count[%d]", account_list, count);
+ error = EM_STORAGE_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ emf_mail_account_tbl_t* p = *account_list;
+ int i = 0;
+
+ for (; i < count; i++) {
+ EM_SAFE_FREE(p[i].account_name);
+ EM_SAFE_FREE(p[i].receiving_server_addr);
+ EM_SAFE_FREE(p[i].email_addr);
+ EM_SAFE_FREE(p[i].user_name);
+ EM_SAFE_FREE(p[i].password);
+ EM_SAFE_FREE(p[i].sending_server_addr);
+ EM_SAFE_FREE(p[i].sending_user);
+ EM_SAFE_FREE(p[i].sending_password);
+ EM_SAFE_FREE(p[i].display_name);
+ EM_SAFE_FREE(p[i].reply_to_addr);
+ EM_SAFE_FREE(p[i].return_addr);
+ EM_SAFE_FREE(p[i].logo_icon_path);
+ EM_SAFE_FREE(p[i].options.display_name_from);
+ EM_SAFE_FREE(p[i].options.signature);
+ }
+
+ EM_SAFE_FREE(p);
+ *account_list = NULL;
+ }
+
+ ret = true;
+
+FINISH_OFF:
+ if (err_code != NULL)
+ *err_code = error;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+EXPORT_API int em_storage_get_mailbox_count(int account_id, int local_yn, int *count, int transaction, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("account_id[%d], local_yn[%d], count[%p], transaction[%d], err_code[%p]", account_id, local_yn, count, transaction, err_code);
+
+ if ((account_id < FIRST_ACCOUNT_ID) || (count == NULL)) {
+ EM_DEBUG_EXCEPTION(" account_list[%d], local_yn[%d], count[%p]", account_id, local_yn, count);
+
+ if (err_code != NULL)
+ *err_code = EM_STORAGE_ERROR_INVALID_PARAM;
+ return false;
+ }
+
+ int rc = -1, ret = false;
+ int error = EM_STORAGE_ERROR_NONE;
+ char sql_query_string[QUERY_SIZE] = {0, };
+
+ sqlite3 *local_db_handle = em_storage_get_db_connection();
+ EM_STORAGE_START_READ_TRANSACTION(transaction);
+
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT COUNT(*) FROM mail_box_tbl WHERE account_id = %d AND local_yn = %d", account_id, local_yn);
+
+ char **result;
+ /* rc = sqlite3_get_table(local_db_handle, sql_query_string, &result, NULL, NULL, NULL); */
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, NULL, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EM_STORAGE_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+ ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ *count = atoi(result[1]);
+ sqlite3_free_table(result);
+
+
+ ret = true;
+
+FINISH_OFF:
+
+ EM_STORAGE_FINISH_READ_TRANSACTION(transaction);
+ _DISCONNECT_DB;
+
+ if (err_code != NULL)
+ *err_code = error;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+EXPORT_API int em_storage_get_mailbox(int account_id, int local_yn, email_mailbox_sort_type_t sort_type, int *select_num, emf_mailbox_tbl_t** mailbox_list, int transaction, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("account_id[%d], local_yn[%d], select_num[%p], mailbox_list[%p], transaction[%d], err_code[%p]", account_id, local_yn, select_num, mailbox_list, transaction, err_code);
+
+ if (!select_num || !mailbox_list) {
+ EM_DEBUG_EXCEPTION("Invalid parameters");
+
+ if (err_code != NULL)
+ *err_code = EM_STORAGE_ERROR_INVALID_PARAM;
+
+ return false;
+ }
+
+ int i = 0, rc, count = 0, ret = false, col_index;
+ int error = EM_STORAGE_ERROR_NONE;
+ emf_mailbox_tbl_t* p_data_tbl = NULL;
+ char **result;
+ DB_STMT hStmt = NULL;
+ char sql_query_string[QUERY_SIZE] = {0, };
+ char *fields = "mailbox_id, account_id, local_yn, mailbox_name, mailbox_type, alias, sync_with_server_yn, modifiable_yn, total_mail_count_on_server, has_archived_mails, mail_slot_size ";
+
+ sqlite3 *local_db_handle = em_storage_get_db_connection();
+ EM_STORAGE_START_READ_TRANSACTION(transaction);
+
+ if (account_id == ALL_ACCOUNT) {
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT %s FROM mail_box_tbl ", fields);
+ if (local_yn == EMF_MAILBOX_FROM_SERVER || local_yn == EMF_MAILBOX_FROM_LOCAL)
+ SNPRINTF(sql_query_string + strlen(sql_query_string), sizeof(sql_query_string)-(strlen(sql_query_string)+1), " WHERE local_yn = %d ", local_yn);
+ }
+ else {
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT %s FROM mail_box_tbl WHERE account_id = %d ", fields, account_id);
+ if (local_yn == EMF_MAILBOX_FROM_SERVER || local_yn == EMF_MAILBOX_FROM_LOCAL)
+ SNPRINTF(sql_query_string + strlen(sql_query_string), sizeof(sql_query_string)-(strlen(sql_query_string)+1), " AND local_yn = %d ", local_yn);
+ }
+
+ switch (sort_type) {
+ case EMAIL_MAILBOX_SORT_BY_NAME_ASC :
+ SNPRINTF(sql_query_string + strlen(sql_query_string), sizeof(sql_query_string)-(strlen(sql_query_string)+1), " ORDER BY mailbox_name ASC");
+ break;
+
+ case EMAIL_MAILBOX_SORT_BY_NAME_DSC :
+ SNPRINTF(sql_query_string + strlen(sql_query_string), sizeof(sql_query_string)-(strlen(sql_query_string)+1), " ORDER BY mailbox_name DESC");
+ break;
+
+ case EMAIL_MAILBOX_SORT_BY_TYPE_ASC :
+ SNPRINTF(sql_query_string + strlen(sql_query_string), sizeof(sql_query_string)-(strlen(sql_query_string)+1), " ORDER BY mailbox_type ASC");
+ break;
+
+ case EMAIL_MAILBOX_SORT_BY_TYPE_DSC :
+ SNPRINTF(sql_query_string + strlen(sql_query_string), sizeof(sql_query_string)-(strlen(sql_query_string)+1), " ORDER BY mailbox_type DEC");
+ break;
+ }
+
+ EM_DEBUG_LOG("em_storage_get_mailbox : query[%s]", sql_query_string);
+
+
+ /* rc = sqlite3_get_table(local_db_handle, sql_query_string, &result, &count, NULL, NULL); */
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, &count, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EM_STORAGE_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+ ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)))
+
+ if (!(p_data_tbl = (emf_mailbox_tbl_t*)malloc(sizeof(emf_mailbox_tbl_t) * count))) {
+ EM_DEBUG_EXCEPTION(" malloc failed...");
+
+ error = EM_STORAGE_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ memset(p_data_tbl, 0x00, sizeof(emf_mailbox_tbl_t)*count);
+
+ col_index = 11;
+
+ for (i = 0; i < count; i++) {
+ _getTableFieldDataInt(result, &(p_data_tbl[i].mailbox_id), col_index++);
+ _getTableFieldDataInt(result, &(p_data_tbl[i].account_id), col_index++);
+ _getTableFieldDataInt(result, &(p_data_tbl[i].local_yn), col_index++);
+ _getTableFieldDataString(result, &(p_data_tbl[i].mailbox_name), 0, col_index++);
+ _getTableFieldDataInt(result, (int *)&(p_data_tbl[i].mailbox_type), col_index++);
+ _getTableFieldDataString(result, &(p_data_tbl[i].alias), 0, col_index++);
+ _getTableFieldDataInt(result, &(p_data_tbl[i].sync_with_server_yn), col_index++);
+ _getTableFieldDataInt(result, &(p_data_tbl[i].modifiable_yn), col_index++);
+ _getTableFieldDataInt(result, &(p_data_tbl[i].total_mail_count_on_server), col_index++);
+ _getTableFieldDataInt(result, &(p_data_tbl[i].has_archived_mails), col_index++);
+ _getTableFieldDataInt(result, &(p_data_tbl[i].mail_slot_size), col_index++);
+ }
+
+ ret = true;
+
+FINISH_OFF:
+ if (result)
+ sqlite3_free_table(result);
+
+ if (ret == true) {
+ *mailbox_list = p_data_tbl;
+ *select_num = count;
+ EM_DEBUG_LOG("Mailbox Count [ %d]", count);
+ }
+ else if (p_data_tbl != NULL)
+ em_storage_free_mailbox(&p_data_tbl, count, NULL);
+
+ if (hStmt != NULL) {
+ rc = sqlite3_finalize(hStmt);
+ if (rc != SQLITE_OK) {
+ EM_DEBUG_LOG(" sqlite3_finalize failed - %d", rc);
+
+ error = EM_STORAGE_ERROR_DB_FAILURE;
+ }
+ }
+
+ EM_STORAGE_FINISH_READ_TRANSACTION(transaction);
+ _DISCONNECT_DB;
+
+ if (err_code != NULL)
+ *err_code = error;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+
+EXPORT_API int em_storage_get_mailbox_ex(int account_id, int local_yn, int with_count, int *select_num, emf_mailbox_tbl_t** mailbox_list, int transaction, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("account_id[%d], local_yn[%d], select_num[%p], mailbox_list[%p], transaction[%d], err_code[%p]", account_id, local_yn, select_num, mailbox_list, transaction, err_code);
+
+ if (!select_num || !mailbox_list) {
+ EM_DEBUG_EXCEPTION("Invalid parameters");
+
+ if (err_code != NULL)
+ *err_code = EM_STORAGE_ERROR_INVALID_PARAM;
+
+ return false;
+ }
+
+ int i = 0;
+ int rc;
+ int count = 0;
+ int ret = false;
+ int col_index;
+ int error = EM_STORAGE_ERROR_NONE;
+ emf_mailbox_tbl_t* p_data_tbl = NULL;
+ char **result;
+ DB_STMT hStmt = NULL;
+ char sql_query_string[QUERY_SIZE] = {0, };
+ char *fields = "MBT.mailbox_id, MBT.account_id, local_yn, MBT.mailbox_name, MBT.mailbox_type, alias, sync_with_server_yn, modifiable_yn, total_mail_count_on_server, has_archived_mails, mail_slot_size ";
+ int add = 0;
+ int read_count = 0;
+ int total_count = 0;
+
+ sqlite3 *local_db_handle = em_storage_get_db_connection();
+ EM_STORAGE_START_READ_TRANSACTION(transaction);
+
+ add = 0;
+ if (with_count == 0) { /* without count */
+ col_index = 11;
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT %s FROM mail_box_tbl AS MBT", fields);
+ if (account_id > ALL_ACCOUNT) {
+ add = 1;
+ SNPRINTF(sql_query_string + strlen(sql_query_string), sizeof(sql_query_string)-(strlen(sql_query_string)+1), " WHERE account_id = %d ", account_id);
+ }
+ }
+ else { /* with read count and total count */
+ col_index = 13;
+ if (account_id > ALL_ACCOUNT) {
+ add = 1;
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT %s, total, read FROM mail_box_tbl AS MBT LEFT OUTER JOIN (SELECT mailbox_name, count(mail_id) AS total, SUM(flags_seen_field) AS read FROM mail_tbl WHERE account_id = %d GROUP BY mailbox_name) AS MT ON MBT.mailbox_name = MT.mailbox_name WHERE account_id = %d ", fields, account_id, account_id);
+ }
+ else {
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT %s, total, read FROM mail_box_tbl AS MBT LEFT OUTER JOIN (SELECT mailbox_name, count(mail_id) AS total, SUM(flags_seen_field) AS read FROM mail_tbl GROUP BY mailbox_name) AS MT ON MBT.mailbox_name = MT.mailbox_name ", fields);
+ }
+ }
+
+ if (local_yn == EMF_MAILBOX_FROM_SERVER || local_yn == EMF_MAILBOX_FROM_LOCAL) {
+ SNPRINTF(sql_query_string + strlen(sql_query_string), sizeof(sql_query_string)-(strlen(sql_query_string)+1), " %s local_yn = %d ", (add ? "WHERE" : "AND"), local_yn);
+ }
+
+ SNPRINTF(sql_query_string + strlen(sql_query_string), sizeof(sql_query_string)-(strlen(sql_query_string)+1), " ORDER BY MBT.mailbox_name ");
+ EM_DEBUG_LOG("query[%s]", sql_query_string);
+
+
+ /* rc = sqlite3_get_table(local_db_handle, sql_query_string, &result, &count, NULL, NULL); */
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, &count, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EM_STORAGE_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+ ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)))
+
+ EM_DEBUG_LOG("result count [%d]", count);
+
+ if (!(p_data_tbl = (emf_mailbox_tbl_t*)malloc(sizeof(emf_mailbox_tbl_t) * count))) {
+ EM_DEBUG_EXCEPTION("malloc failed...");
+ error = EM_STORAGE_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ memset(p_data_tbl, 0x00, sizeof(emf_mailbox_tbl_t)*count);
+
+ for (i = 0; i < count; i++) {
+ _getTableFieldDataInt(result, &(p_data_tbl[i].mailbox_id), col_index++);
+ _getTableFieldDataInt(result, &(p_data_tbl[i].account_id), col_index++);
+ _getTableFieldDataInt(result, &(p_data_tbl[i].local_yn), col_index++);
+ _getTableFieldDataString(result, &(p_data_tbl[i].mailbox_name), 0, col_index++);
+ _getTableFieldDataInt(result, (int *)&(p_data_tbl[i].mailbox_type), col_index++);
+ _getTableFieldDataString(result, &(p_data_tbl[i].alias), 0, col_index++);
+ _getTableFieldDataInt(result, &(p_data_tbl[i].sync_with_server_yn), col_index++);
+ _getTableFieldDataInt(result, &(p_data_tbl[i].modifiable_yn), col_index++);
+ _getTableFieldDataInt(result, &(p_data_tbl[i].total_mail_count_on_server), col_index++);
+ _getTableFieldDataInt(result, &(p_data_tbl[i].has_archived_mails), col_index++);
+ _getTableFieldDataInt(result, &(p_data_tbl[i].mail_slot_size), col_index++);
+
+ if (with_count == 1) {
+ _getTableFieldDataInt(result, &(total_count), col_index++);
+ p_data_tbl[i].total_mail_count_on_local = total_count;
+ _getTableFieldDataInt(result, &(read_count), col_index++);
+ p_data_tbl[i].unread_count = total_count - read_count; /* return unread count, NOT */
+ }
+ /*
+ EM_DEBUG_LOG("[%d]", i);
+ EM_DEBUG_LOG("p_data_tbl[%d].mailbox_id[%d]", i, p_data_tbl[i].mailbox_id);
+ EM_DEBUG_LOG("p_data_tbl[%d].account_id[%d]", i, p_data_tbl[i].account_id);
+ EM_DEBUG_LOG("p_data_tbl[%d].local_yn[%d]", i, p_data_tbl[i].local_yn);
+ EM_DEBUG_LOG("p_data_tbl[%d].mailbox_name[%s]", i, p_data_tbl[i].mailbox_name);
+ EM_DEBUG_LOG("p_data_tbl[%d].mailbox_type[%d]", i, p_data_tbl[i].mailbox_type);
+ EM_DEBUG_LOG("p_data_tbl[%d].alias[%s]", i, p_data_tbl[i].alias);
+ EM_DEBUG_LOG("p_data_tbl[%d].sync_with_server_yn[%d]", i, p_data_tbl[i].sync_with_server_yn);
+ EM_DEBUG_LOG("p_data_tbl[%d].modifiable_yn[%d]", i, p_data_tbl[i].modifiable_yn);
+ EM_DEBUG_LOG("p_data_tbl[%d].has_archived_mails[%d]", i, p_data_tbl[i].has_archived_mails);
+ EM_DEBUG_LOG("p_data_tbl[%d].mail_slot_size[%d]", i, p_data_tbl[i].mail_slot_size);
+ EM_DEBUG_LOG("p_data_tbl[%d].unread_count[%d]", i, p_data_tbl[i].unread_count);
+ EM_DEBUG_LOG("p_data_tbl[%d].total_mail_count_on_local[%d]", i, p_data_tbl[i].total_mail_count_on_local);
+ EM_DEBUG_LOG("p_data_tbl[%d].total_mail_count_on_server[%d]", i, p_data_tbl[i].total_mail_count_on_server);
+ */
+ }
+
+ ret = true;
+
+FINISH_OFF:
+ if (result)
+ sqlite3_free_table(result);
+
+ if (ret == true) {
+ *mailbox_list = p_data_tbl;
+ *select_num = count;
+ EM_DEBUG_LOG("Mailbox Count [ %d]", count);
+ }
+ else if (p_data_tbl != NULL)
+ em_storage_free_mailbox(&p_data_tbl, count, NULL);
+
+ if (hStmt != NULL) {
+ rc = sqlite3_finalize(hStmt);
+ if (rc != SQLITE_OK) {
+ EM_DEBUG_LOG(" sqlite3_finalize failed - %d", rc);
+
+ error = EM_STORAGE_ERROR_DB_FAILURE;
+ }
+ }
+
+ EM_STORAGE_FINISH_READ_TRANSACTION(transaction);
+ _DISCONNECT_DB;
+
+ if (err_code != NULL)
+ *err_code = error;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+EXPORT_API int em_storage_get_child_mailbox_list(int account_id, char *parent_mailbox_name, int *select_num, emf_mailbox_tbl_t** mailbox_list, int transaction, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("account_id[%d], parent_mailbox_name[%p], select_num[%p], mailbox_list[%p], transaction[%d], err_code[%p]", account_id, parent_mailbox_name, select_num, mailbox_list, transaction, err_code);
+ if (account_id < FIRST_ACCOUNT_ID || !select_num || !mailbox_list) {
+ EM_DEBUG_EXCEPTION("account_id[%d], parent_mailbox_name[%p], select_num[%p], mailbox_list[%p]", account_id, parent_mailbox_name, select_num, mailbox_list);
+
+ if (err_code != NULL)
+ *err_code = EM_STORAGE_ERROR_INVALID_PARAM;
+ return false;
+ }
+
+ int i = 0, rc, count = 0, ret = false, col_index;
+ int error = EM_STORAGE_ERROR_NONE;
+ emf_mailbox_tbl_t* p_data_tbl = NULL;
+ char **result;
+ char sql_query_string[QUERY_SIZE] = {0, };
+ char *fields = "mailbox_id, account_id, local_yn, mailbox_name, mailbox_type, alias, sync_with_server_yn, modifiable_yn, total_mail_count_on_server, has_archived_mails, mail_slot_size ";
+
+ sqlite3 *local_db_handle = em_storage_get_db_connection();
+ EM_STORAGE_START_READ_TRANSACTION(transaction);
+
+ if (parent_mailbox_name)
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT %s FROM mail_box_tbl WHERE account_id = %d AND UPPER(mailbox_name) LIKE UPPER('%s/%%') ORDER BY mailbox_name", fields, account_id, parent_mailbox_name);
+ else
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT %s FROM mail_box_tbl WHERE account_id = %d AND (mailbox_name NOT LIKE '%%/%%') ORDER BY mailbox_name", fields, account_id);
+
+ EM_DEBUG_LOG("query : %s", sql_query_string);
+
+ /* rc = sqlite3_get_table(local_db_handle, sql_query_string, &result, &count, NULL, NULL); */
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, &count, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EM_STORAGE_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+ ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+
+ if (!(p_data_tbl = (emf_mailbox_tbl_t*)malloc(sizeof(emf_mailbox_tbl_t) * count))) {
+ EM_DEBUG_EXCEPTION(" malloc failed...");
+ error = EM_STORAGE_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ memset(p_data_tbl, 0x00, sizeof(emf_mailbox_tbl_t)*count);
+ col_index = 11;
+
+ for (i = 0; i < count; i++) {
+ _getTableFieldDataInt(result, &(p_data_tbl[i].mailbox_id), col_index++);
+ _getTableFieldDataInt(result, &(p_data_tbl[i].account_id), col_index++);
+ _getTableFieldDataInt(result, &(p_data_tbl[i].local_yn), col_index++);
+ _getTableFieldDataString(result, &(p_data_tbl[i].mailbox_name), 0, col_index++);
+ _getTableFieldDataInt(result, (int *)&(p_data_tbl[i].mailbox_type), col_index++);
+ _getTableFieldDataString(result, &(p_data_tbl[i].alias), 0, col_index++);
+ _getTableFieldDataInt(result, &(p_data_tbl[i].sync_with_server_yn), col_index++);
+ _getTableFieldDataInt(result, &(p_data_tbl[i].modifiable_yn), col_index++);
+ _getTableFieldDataInt(result, &(p_data_tbl[i].total_mail_count_on_server), col_index++);
+ _getTableFieldDataInt(result, &(p_data_tbl[i].has_archived_mails), col_index++);
+ _getTableFieldDataInt(result, &(p_data_tbl[i].mail_slot_size), col_index++);
+ }
+
+ if (result)
+ sqlite3_free_table(result);
+
+ ret = true;
+
+FINISH_OFF:
+ if (ret == true) {
+ *mailbox_list = p_data_tbl;
+ *select_num = count;
+ EM_DEBUG_LOG(" Mailbox Count [ %d] ", count);
+ }
+ else if (p_data_tbl != NULL)
+ em_storage_free_mailbox(&p_data_tbl, count, NULL);
+
+ EM_STORAGE_FINISH_READ_TRANSACTION(transaction);
+ _DISCONNECT_DB;
+
+ if (err_code != NULL)
+ *err_code = error;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+EXPORT_API int em_storage_get_mailbox_by_modifiable_yn(int account_id, int local_yn, int *select_num, emf_mailbox_tbl_t** mailbox_list, int transaction, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("account_id[%d], local_yn[%d], select_num[%p], mailbox_list[%p], transaction[%d], err_code[%p]", account_id, local_yn, select_num, mailbox_list, transaction, err_code);
+ if (account_id < FIRST_ACCOUNT_ID || !select_num || !mailbox_list) {
+ EM_DEBUG_EXCEPTION("\account_id[%d], local_yn[%d], select_num[%p], mailbox_list[%p]", account_id, local_yn, select_num, mailbox_list);
+
+ if (err_code != NULL)
+ *err_code = EM_STORAGE_ERROR_INVALID_PARAM;
+ return false;
+ }
+
+ int i = 0, rc, count = 0, ret = false;
+ int error = EM_STORAGE_ERROR_NONE;
+ emf_mailbox_tbl_t* p_data_tbl = NULL;
+ DB_STMT hStmt = NULL;
+ char sql_query_string[QUERY_SIZE] = {0, };
+ char *fields = "mailbox_id, account_id, local_yn, mailbox_name, mailbox_type, alias, sync_with_server_yn, modifiable_yn, total_mail_count_on_server, has_archived_mails, mail_slot_size ";
+
+ sqlite3 *local_db_handle = em_storage_get_db_connection();
+ EM_STORAGE_START_READ_TRANSACTION(transaction);
+
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT %s FROM mail_box_tbl WHERE account_id = %d AND modifiable_yn = 0 ORDER BY mailbox_name", fields, account_id);
+ EM_DEBUG_LOG("sql[%s]", sql_query_string);
+
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ /* rc = sqlite3_step(hStmt); */
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
+ EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("sqlite3_step fail:%d", rc));
+
+ char **result;
+ /* rc = sqlite3_get_table(local_db_handle, sql_query_string, &result, &count, NULL, NULL); */
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, &count, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EM_STORAGE_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+ ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ sqlite3_free_table(result);
+ if (count == 0) {
+ EM_DEBUG_EXCEPTION(" no mailbox_name found...");
+
+ ret = true;
+ goto FINISH_OFF;
+ }
+
+ if (!(p_data_tbl = (emf_mailbox_tbl_t*)malloc(sizeof(emf_mailbox_tbl_t) * count))) {
+ EM_DEBUG_EXCEPTION(" malloc failed...");
+
+ error = EM_STORAGE_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ memset(p_data_tbl, 0x00, sizeof(emf_mailbox_tbl_t)*count);
+
+ int col_index = 0;
+ for (i = 0; i < count; i++) {
+ col_index = 0;
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl[i].mailbox_id), col_index++);
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl[i].account_id), col_index++);
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl[i].local_yn), col_index++);
+ _getStmtFieldDataString(hStmt, &(p_data_tbl[i].mailbox_name), 0, col_index++);
+ _getStmtFieldDataInt(hStmt, (int *)&(p_data_tbl[i].mailbox_type), col_index++);
+ _getStmtFieldDataString(hStmt, &(p_data_tbl[i].alias), 0, col_index++);
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl[i].sync_with_server_yn), col_index++);
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl[i].modifiable_yn), col_index++);
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl[i].total_mail_count_on_server), col_index++);
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl[i].has_archived_mails), col_index++);
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl[i].mail_slot_size), col_index++);
+
+ /* rc = sqlite3_step(hStmt); */
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
+ EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("sqlite3_step fail:%d", rc));
+ }
+
+ ret = true;
+
+FINISH_OFF:
+ if (ret == true) {
+ *mailbox_list = p_data_tbl;
+ *select_num = count;
+ EM_DEBUG_LOG("Mailbox Count[%d]", count);
+ }
+ else if (p_data_tbl != NULL)
+ em_storage_free_mailbox(&p_data_tbl, count, NULL);
+
+ if (hStmt != NULL) {
+ EM_DEBUG_LOG("Before sqlite3_finalize hStmt = %p", hStmt);
+
+ rc = sqlite3_finalize(hStmt);
+ if (rc != SQLITE_OK) {
+ EM_DEBUG_EXCEPTION("sqlite3_finalize failed - %d", rc);
+ error = EM_STORAGE_ERROR_DB_FAILURE;
+ }
+ }
+ EM_STORAGE_FINISH_READ_TRANSACTION(transaction);
+ _DISCONNECT_DB;
+
+ if (err_code != NULL)
+ *err_code = error;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+
+
+EXPORT_API int em_storage_get_mailbox_by_name(int account_id, int local_yn, char *mailbox_name, emf_mailbox_tbl_t** result_mailbox, int transaction, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("account_id[%d], local_yn[%d], mailbox_name[%s], result_mailbox[%p], transaction[%d], err_code[%p]", account_id, local_yn, mailbox_name, result_mailbox, transaction, err_code);
+ EM_PROFILE_BEGIN(profile_em_storage_get_mailbox_by_name);
+
+ if (account_id < FIRST_ACCOUNT_ID || !mailbox_name || !result_mailbox) {
+ EM_DEBUG_EXCEPTION(" account_id[%d], local_yn[%d], mailbox_name[%s], result_mailbox[%p]", account_id, local_yn, mailbox_name, result_mailbox);
+
+ if (err_code != NULL)
+ *err_code = EM_STORAGE_ERROR_INVALID_PARAM;
+ return false;
+ }
+
+ int rc, ret = false;
+ int error = EM_STORAGE_ERROR_NONE;
+ emf_mailbox_tbl_t* p_data_tbl = NULL;
+
+ DB_STMT hStmt = NULL;
+ char sql_query_string[QUERY_SIZE] = {0, };
+ char *fields = "mailbox_id, account_id, local_yn, mailbox_name, mailbox_type, alias, sync_with_server_yn, modifiable_yn, total_mail_count_on_server, has_archived_mails, mail_slot_size ";
+
+ sqlite3 *local_db_handle = em_storage_get_db_connection();
+ EM_STORAGE_START_READ_TRANSACTION(transaction);
+
+ if (local_yn == -1)
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT %s FROM mail_box_tbl WHERE account_id = %d AND mailbox_name = '%s'", fields, account_id, mailbox_name);
+ else
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT %s FROM mail_box_tbl WHERE account_id = %d AND local_yn = %d AND mailbox_name = '%s'", fields, account_id, local_yn, mailbox_name);
+
+ EM_DEBUG_LOG("query = [%s]", sql_query_string);
+
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+ /* rc = sqlite3_step(hStmt); */
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
+ EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("sqlite3_step fail:%d", rc));
+
+ if (rc == SQLITE_DONE) {
+ EM_DEBUG_EXCEPTION("no matched mailbox_name found...");
+ error = EM_STORAGE_ERROR_MAILBOX_NOT_FOUND;
+ goto FINISH_OFF;
+ }
+
+ if (!(p_data_tbl = (emf_mailbox_tbl_t*)malloc(sizeof(emf_mailbox_tbl_t)))) {
+ EM_DEBUG_EXCEPTION("malloc failed...");
+ error = EM_STORAGE_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ memset(p_data_tbl, 0x00, sizeof(emf_mailbox_tbl_t));
+ int col_index = 0;
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl->mailbox_id), col_index++);
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl->account_id), col_index++);
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl->local_yn), col_index++);
+ _getStmtFieldDataString(hStmt, &(p_data_tbl->mailbox_name), 0, col_index++);
+ _getStmtFieldDataInt(hStmt, (int *)&(p_data_tbl->mailbox_type), col_index++);
+ _getStmtFieldDataString(hStmt, &(p_data_tbl->alias), 0, col_index++);
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl->sync_with_server_yn), col_index++);
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl->modifiable_yn), col_index++);
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl->total_mail_count_on_server), col_index++);
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl->has_archived_mails), col_index++);
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl->mail_slot_size), col_index++);
+
+ ret = true;
+
+FINISH_OFF:
+ if (ret == true)
+ *result_mailbox = p_data_tbl;
+ else if (p_data_tbl != NULL)
+ em_storage_free_mailbox(&p_data_tbl, 1, NULL);
+
+ if (hStmt != NULL) {
+ rc = sqlite3_finalize(hStmt);
+ if (rc != SQLITE_OK) {
+ EM_DEBUG_EXCEPTION(" sqlite3_finalize failed - %d", rc);
+ error = EM_STORAGE_ERROR_DB_FAILURE;
+ }
+ }
+
+ EM_STORAGE_FINISH_READ_TRANSACTION(transaction);
+ _DISCONNECT_DB;
+
+ if (err_code != NULL)
+ *err_code = error;
+
+ EM_PROFILE_END(profile_em_storage_get_mailbox_by_name);
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+
+EXPORT_API int em_storage_get_mailbox_by_mailbox_type(int account_id, emf_mailbox_type_e mailbox_type, emf_mailbox_tbl_t** mailbox_name, int transaction, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("account_id[%d], mailbox_type[%d], mailbox_name[%p], transaction[%d], err_code[%p]", account_id, mailbox_type, mailbox_name, transaction, err_code);
+
+ if (account_id < FIRST_ACCOUNT_ID || (mailbox_type < EMF_MAILBOX_TYPE_INBOX || mailbox_type > EMF_MAILBOX_TYPE_ALL_EMAILS) || !mailbox_name) {
+
+ EM_DEBUG_EXCEPTION(" account_id[%d], mailbox_type[%d], mailbox_name[%p]", account_id, mailbox_type, mailbox_name);
+
+ if (err_code != NULL)
+ *err_code = EM_STORAGE_ERROR_INVALID_PARAM;
+ return false;
+ }
+
+ int rc, ret = false;
+ int error = EM_STORAGE_ERROR_NONE;
+ emf_mailbox_tbl_t *p_data_tbl = NULL;
+ emf_mail_account_tbl_t *account = NULL;
+ DB_STMT hStmt = NULL;
+ char sql_query_string[QUERY_SIZE] = {0,};
+ char *fields = "mailbox_id, account_id, local_yn, mailbox_name, mailbox_type, alias, sync_with_server_yn, modifiable_yn, total_mail_count_on_server, has_archived_mails, mail_slot_size ";
+
+ sqlite3 *local_db_handle = em_storage_get_db_connection();
+ EM_STORAGE_START_READ_TRANSACTION(transaction);
+
+ /* validate account */
+ /* Check whether the account exists. */
+ if (!em_storage_get_account_by_id(account_id, EMF_ACC_GET_OPT_ACCOUNT_NAME, &account, true, &error) || !account) {
+ EM_DEBUG_EXCEPTION(" em_storage_get_account_by_id failed - %d", error);
+ goto FINISH_OFF;
+ }
+
+ if (account)
+ em_storage_free_account(&account, 1, NULL);
+
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT %s FROM mail_box_tbl WHERE account_id = %d AND mailbox_type = %d ", fields, account_id, mailbox_type);
+
+ EM_DEBUG_LOG("query = [%s]", sql_query_string);
+
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EM_STORAGE_ERROR_DB_FAILURE; goto FINISH_OFF; }, ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ /* rc = sqlite3_step(hStmt); */
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
+ EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EM_STORAGE_ERROR_DB_FAILURE; goto FINISH_OFF; }, ("sqlite3_step fail:%d", rc));
+
+ if (rc == SQLITE_DONE) {
+ EM_DEBUG_EXCEPTION(" no matched mailbox_name found...");
+ error = EM_STORAGE_ERROR_MAILBOX_NOT_FOUND;
+ goto FINISH_OFF;
+ }
+
+
+ if (!(p_data_tbl = (emf_mailbox_tbl_t*)malloc(sizeof(emf_mailbox_tbl_t)))) {
+ EM_DEBUG_EXCEPTION(" malloc failed...");
+ error = EM_STORAGE_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ memset(p_data_tbl, 0x00, sizeof(emf_mailbox_tbl_t));
+
+ int col_index = 0;
+
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl->mailbox_id), col_index++);
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl->account_id), col_index++);
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl->local_yn), col_index++);
+ _getStmtFieldDataString(hStmt, &(p_data_tbl->mailbox_name), 0, col_index++);
+ _getStmtFieldDataInt(hStmt, (int *)&(p_data_tbl->mailbox_type), col_index++);
+ _getStmtFieldDataString(hStmt, &(p_data_tbl->alias), 0, col_index++);
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl->sync_with_server_yn), col_index++);
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl->modifiable_yn), col_index++);
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl->total_mail_count_on_server), col_index++);
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl->has_archived_mails), col_index++);
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl->mail_slot_size), col_index++);
+
+ ret = true;
+
+FINISH_OFF:
+ if (ret == true)
+ *mailbox_name = p_data_tbl;
+ else if (p_data_tbl != NULL)
+ em_storage_free_mailbox(&p_data_tbl, 1, NULL);
+
+ if (hStmt != NULL) {
+ rc = sqlite3_finalize(hStmt);
+ if (rc != SQLITE_OK) {
+ EM_DEBUG_EXCEPTION("sqlite3_finalize failed - %d", rc);
+ error = EM_STORAGE_ERROR_DB_FAILURE;
+ }
+ }
+
+ EM_STORAGE_FINISH_READ_TRANSACTION(transaction);
+ _DISCONNECT_DB;
+
+ if (err_code != NULL)
+ *err_code = error;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+EXPORT_API int em_storage_get_mailboxname_by_mailbox_type(int account_id, emf_mailbox_type_e mailbox_type, char **mailbox_name, int transaction, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("account_id[%d], mailbox_type[%d], mailbox_name[%p], transaction[%d], err_code[%p]", account_id, mailbox_type, mailbox_name, transaction, err_code);
+ if (account_id < FIRST_ACCOUNT_ID || (mailbox_type < EMF_MAILBOX_TYPE_INBOX || mailbox_type > EMF_MAILBOX_TYPE_ALL_EMAILS) || !mailbox_name) {
+ EM_DEBUG_EXCEPTION("account_id[%d], mailbox_type[%d], mailbox_name[%p]", account_id, mailbox_type, mailbox_name);
+ if (err_code != NULL)
+ *err_code = EM_STORAGE_ERROR_INVALID_PARAM;
+ return false;
+ }
+
+ int rc, ret = false;
+ int error = EM_STORAGE_ERROR_NONE;
+ char *p_mailbox = NULL;
+ emf_mail_account_tbl_t* account = NULL;
+ DB_STMT hStmt = NULL;
+ char sql_query_string[QUERY_SIZE] = {0, };
+
+ sqlite3 *local_db_handle = em_storage_get_db_connection();
+ EM_STORAGE_START_READ_TRANSACTION(transaction);
+
+ /* Check whether the account exists. */
+ if (!em_storage_get_account_by_id(account_id, EMF_ACC_GET_OPT_ACCOUNT_NAME, &account, true, &error) || !account) {
+ EM_DEBUG_EXCEPTION("em_storage_get_account_by_id failed - %d", error);
+ goto FINISH_OFF;
+ }
+
+ if (account )
+ em_storage_free_account(&account, 1, NULL);
+
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT mailbox_name FROM mail_box_tbl WHERE account_id = %d AND mailbox_type = %d ", account_id, mailbox_type);
+
+ EM_DEBUG_LOG("query = [%s]", sql_query_string);
+
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
+
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ /* rc = sqlite3_step(hStmt); */
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
+ EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("sqlite3_step fail:%d", rc));
+
+ if (rc == SQLITE_DONE) {
+ EM_DEBUG_EXCEPTION("no matched mailbox_name found...");
+ error = EM_STORAGE_ERROR_MAILBOX_NOT_FOUND;
+ goto FINISH_OFF;
+ }
+
+ _getStmtFieldDataString(hStmt, &(p_mailbox), 0, 0);
+
+ ret = true;
+
+FINISH_OFF:
+ if (ret == true)
+ *mailbox_name = p_mailbox;
+ else
+ EM_SAFE_FREE(p_mailbox);
+
+ if (hStmt != NULL) {
+ rc = sqlite3_finalize(hStmt);
+ if (rc != SQLITE_OK) {
+ EM_DEBUG_EXCEPTION(" sqlite3_finalize failed - %d", rc);
+ error = EM_STORAGE_ERROR_DB_FAILURE;
+ }
+ }
+
+ EM_STORAGE_FINISH_READ_TRANSACTION(transaction);
+ _DISCONNECT_DB;
+
+ if (err_code != NULL)
+ *err_code = error;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+EXPORT_API int em_storage_update_mailbox_modifiable_yn(int account_id, int local_yn, char *mailbox_name, int modifiable_yn, int transaction, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("account_id [%d], local_yn [%d], mailbox_name [%p], modifiable_yn [%d], transaction [%d], err_code [%p]", account_id, local_yn, mailbox_name, modifiable_yn, transaction, err_code);
+ int rc, ret = false;
+ int error = EM_STORAGE_ERROR_NONE;
+ char sql_query_string[QUERY_SIZE] = {0, };
+
+ sqlite3 *local_db_handle = em_storage_get_db_connection();
+
+ EM_STORAGE_START_WRITE_TRANSACTION(transaction, error);
+
+ SNPRINTF(sql_query_string, sizeof(sql_query_string),
+ "UPDATE mail_box_tbl SET"
+ " modifiable_yn = %d"
+ " WHERE account_id = %d"
+ " AND local_yn = %d"
+ " AND mailbox_name = '%s'"
+ , modifiable_yn
+ , account_id
+ , local_yn
+ , mailbox_name);
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ ret = true;
+
+FINISH_OFF:
+ EM_STORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
+ _DISCONNECT_DB;
+
+ if (err_code != NULL)
+ *err_code = error;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+
+}
+
+
+EXPORT_API int em_storage_update_mailbox_total_count(int account_id, char *mailbox_name, int total_count_on_server, int transaction, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("account_id[%d], mailbox_name[%p], total_count_on_server[%d], transaction[%d], err_code[%p]", account_id, mailbox_name, total_count_on_server, transaction, err_code);
+ int rc, ret = false;
+ int error = EM_STORAGE_ERROR_NONE;
+ char sql_query_string[QUERY_SIZE] = {0, };
+
+ if (account_id <= 0 || !mailbox_name) {
+ EM_DEBUG_EXCEPTION("account_id[%d], mailbox_name[%p]", account_id, mailbox_name);
+
+ if (err_code != NULL)
+ *err_code = EM_STORAGE_ERROR_INVALID_PARAM;
+ return false;
+ }
+ sqlite3 *local_db_handle = em_storage_get_db_connection();
+
+ EM_STORAGE_START_WRITE_TRANSACTION(transaction, error);
+
+ SNPRINTF(sql_query_string, sizeof(sql_query_string),
+ "UPDATE mail_box_tbl SET"
+ " total_mail_count_on_server = %d"
+ " WHERE account_id = %d"
+ " AND mailbox_name = '%s'"
+ , total_count_on_server
+ , account_id
+ , mailbox_name);
+ EM_DEBUG_LOG("query[%s]", sql_query_string);
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ ret = true;
+
+FINISH_OFF:
+ EM_STORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
+ _DISCONNECT_DB;
+
+ if (err_code != NULL)
+ *err_code = error;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+
+}
+
+
+EXPORT_API int em_storage_update_mailbox(int account_id, int local_yn, char *mailbox_name, emf_mailbox_tbl_t* result_mailbox, int transaction, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("account_id[%d], local_yn[%d], mailbox_name[%s], result_mailbox[%p], transaction[%d], err_code[%p]", account_id, local_yn, mailbox_name, result_mailbox, transaction, err_code);
+
+ if (account_id < FIRST_ACCOUNT_ID || !mailbox_name || !result_mailbox) {
+ EM_DEBUG_EXCEPTION(" account_id[%d], local_yn[%d], mailbox_name[%s], result_mailbox[%p]", account_id, local_yn, mailbox_name, result_mailbox);
+
+ if (err_code != NULL)
+ *err_code = EM_STORAGE_ERROR_INVALID_PARAM;
+ return false;
+ }
+
+ int rc, ret = false;
+ int error = EM_STORAGE_ERROR_NONE;
+ char sql_query_string[QUERY_SIZE] = {0, };
+ DB_STMT hStmt = NULL;
+ int i = 0;
+
+ sqlite3 *local_db_handle = em_storage_get_db_connection();
+ EM_STORAGE_START_WRITE_TRANSACTION(transaction, error);
+
+ if (local_yn != -1) {
+ SNPRINTF(sql_query_string, sizeof(sql_query_string),
+ "UPDATE mail_box_tbl SET"
+ " mailbox_id = ?"
+ ", mailbox_name = ?"
+ ", mailbox_type = ?"
+ ", alias = ?"
+ ", sync_with_server_yn = ?"
+ ", modifiable_yn= ?"
+ ", mail_slot_size= ?"
+ ", total_mail_count_on_server = ?"
+ " WHERE account_id = %d"
+ " AND local_yn = %d"
+ " AND mailbox_name = '%s'"
+ , account_id
+ , local_yn
+ , mailbox_name);
+ }
+ else {
+ SNPRINTF(sql_query_string, sizeof(sql_query_string),
+ "UPDATE mail_box_tbl SET"
+ " mailbox_id = ?"
+ ", mailbox_name = ?"
+ ", mailbox_type = ?"
+ ", alias = ?"
+ ", sync_with_server_yn = ?"
+ ", modifiable_yn= ?"
+ ", mail_slot_size= ?"
+ ", total_mail_count_on_server = ?"
+ " WHERE account_id = %d"
+ " AND mailbox_name = '%s'"
+ , account_id
+ , mailbox_name);
+ }
+
+
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ _bindStmtFieldDataInt(hStmt, i++, result_mailbox->mailbox_id);
+ _bindStmtFieldDataString(hStmt, i++, (char *)result_mailbox->mailbox_name ? result_mailbox->mailbox_name : "", 0, MAILBOX_NAME_LEN_IN_MAIL_READ_MAIL_UID_TBL);
+ _bindStmtFieldDataInt(hStmt, i++, result_mailbox->mailbox_type);
+ _bindStmtFieldDataString(hStmt, i++, (char *)result_mailbox->alias ? result_mailbox->alias : "", 0, ALIAS_LEN_IN_MAIL_BOX_TBL);
+ _bindStmtFieldDataInt(hStmt, i++, result_mailbox->sync_with_server_yn);
+ _bindStmtFieldDataInt(hStmt, i++, result_mailbox->modifiable_yn);
+ _bindStmtFieldDataInt(hStmt, i++, result_mailbox->mail_slot_size);
+ _bindStmtFieldDataInt(hStmt, i++, result_mailbox->total_mail_count_on_server);
+
+ /* rc = sqlite3_step(hStmt); */
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
+ EM_DEBUG_DB_EXEC((rc == SQLITE_FULL), {error = EM_STORAGE_ERROR_DB_IS_FULL;goto FINISH_OFF; },
+ ("sqlite3_step fail:%d", rc));
+ EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("sqlite3_step fail:%d", rc));
+
+ ret = true;
+
+FINISH_OFF:
+ EM_STORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
+ _DISCONNECT_DB;
+
+ if (hStmt != NULL) {
+ rc = sqlite3_finalize(hStmt);
+ if (rc != SQLITE_OK) {
+ EM_DEBUG_EXCEPTION(" sqlite3_finalize failed - %d", rc);
+ error = EM_STORAGE_ERROR_DB_FAILURE;
+ }
+ }
+
+ if (err_code != NULL)
+ *err_code = error;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+
+EXPORT_API int em_storage_update_mailbox_type(int account_id, int local_yn, char *mailbox_name, emf_mailbox_tbl_t* target_mailbox, int transaction, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("account_id[%d], local_yn[%d], mailbox_name[%s], target_mailbox[%p], transaction[%d], err_code[%p]", account_id, local_yn, mailbox_name, target_mailbox, transaction, err_code);
+
+ if (account_id < FIRST_ACCOUNT_ID || !mailbox_name || !target_mailbox) {
+ EM_DEBUG_EXCEPTION(" account_id[%d], local_yn[%d], mailbox_name[%s], target_mailbox[%p]", account_id, local_yn, mailbox_name, target_mailbox);
+
+ if (err_code != NULL)
+ *err_code = EM_STORAGE_ERROR_INVALID_PARAM;
+ return false;
+ }
+
+ int rc, ret = false;
+ int error = EM_STORAGE_ERROR_NONE;
+ char sql_query_string[QUERY_SIZE] = {0, };
+
+ sqlite3 *local_db_handle = em_storage_get_db_connection();
+ EM_STORAGE_START_WRITE_TRANSACTION(transaction, error);
+
+ EM_DEBUG_LOG("em_storage_update_mailbox_type");
+
+ DB_STMT hStmt = NULL;
+ int i = 0;
+
+ /* Update mail_box_tbl */
+ if (local_yn != -1) {
+ SNPRINTF(sql_query_string, sizeof(sql_query_string),
+ "UPDATE mail_box_tbl SET"
+ " mailbox_type = ?"
+ " WHERE account_id = %d"
+ " AND local_yn = %d"
+ " AND mailbox_name = '%s'"
+ , account_id
+ , local_yn
+ , mailbox_name);
+ }
+ else {
+ SNPRINTF(sql_query_string, sizeof(sql_query_string),
+ "UPDATE mail_box_tbl SET"
+ " mailbox_type = ?"
+ " WHERE account_id = %d"
+ " AND mailbox_name = '%s'"
+ , account_id
+ , mailbox_name);
+ }
+
+ EM_DEBUG_LOG("SQL(%s)", sql_query_string);
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ _bindStmtFieldDataInt(hStmt, i++, target_mailbox->mailbox_type);
+
+ /* rc = sqlite3_step(hStmt); */
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
+ EM_DEBUG_DB_EXEC((rc == SQLITE_FULL), {error = EM_STORAGE_ERROR_DB_IS_FULL;goto FINISH_OFF; },
+ ("sqlite3_step fail:%d", rc));
+ EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("sqlite3_step fail:%d", rc));
+
+ if (hStmt != NULL) {
+ rc = sqlite3_finalize(hStmt);
+ if (rc != SQLITE_OK) {
+ EM_DEBUG_EXCEPTION(" sqlite3_finalize failed - %d", rc);
+ error = EM_STORAGE_ERROR_DB_FAILURE;
+ }
+ hStmt = NULL;
+ }
+
+ /* Update mail_tbl */
+ i = 0;
+ SNPRINTF(sql_query_string, sizeof(sql_query_string),
+ "UPDATE mail_tbl SET"
+ " mailbox_type = ?"
+ " WHERE account_id = %d"
+ " AND mailbox_name = '%s'"
+ , account_id
+ , mailbox_name);
+
+ EM_DEBUG_LOG("SQL[%s]", sql_query_string);
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ _bindStmtFieldDataInt(hStmt, i++, target_mailbox->mailbox_type);
+
+ /* rc = sqlite3_step(hStmt); */
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
+ EM_DEBUG_DB_EXEC((rc == SQLITE_FULL), {error = EM_STORAGE_ERROR_DB_IS_FULL;goto FINISH_OFF; },
+ ("sqlite3_step fail:%d", rc));
+ EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("sqlite3_step fail:%d", rc));
+
+ ret = true;
+
+FINISH_OFF:
+ EM_STORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
+ _DISCONNECT_DB;
+
+ if (hStmt != NULL) {
+ rc = sqlite3_finalize(hStmt);
+ if (rc != SQLITE_OK) {
+ EM_DEBUG_EXCEPTION(" sqlite3_finalize failed - %d", rc);
+ error = EM_STORAGE_ERROR_DB_FAILURE;
+ }
+ }
+
+ if (err_code != NULL)
+ *err_code = error;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+
+EXPORT_API int em_storage_add_mailbox(emf_mailbox_tbl_t* mailbox_name, int transaction, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("mailbox_name[%p], transaction[%d], err_code[%p]", mailbox_name, transaction, err_code);
+
+ if (!mailbox_name) {
+ if (err_code != NULL)
+ *err_code = EM_STORAGE_ERROR_INVALID_PARAM;
+ return false;
+ }
+
+ int rc, ret = false;
+ int error = EM_STORAGE_ERROR_NONE;
+ DB_STMT hStmt = NULL;
+ char sql_query_string[QUERY_SIZE] = {0,};
+
+ sqlite3 *local_db_handle = em_storage_get_db_connection();
+ EM_STORAGE_START_WRITE_TRANSACTION(transaction, error);
+
+ SNPRINTF(sql_query_string, sizeof(sql_query_string),
+ "INSERT INTO mail_box_tbl VALUES "
+ "( ?" /* mailbox_id */
+ ", ?" /* account_id */
+ ", ?" /* local_yn */
+ ", ?" /* mailbox_name */
+ ", ?" /* mailbox_type */
+ ", ?" /* alias */
+ ", ?" /* sync_with_server_yn */
+ ", ?" /* modifiable_yn */
+ ", ?" /* total_mail_count_on_server */
+ ", ?" /* has_archived_mails */
+ ", ? )");/* mail_slot_size */
+
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
+ EM_DEBUG_LOG("After sqlite3_prepare hStmt = %p", hStmt);
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ int col_index = 0;
+
+ _bindStmtFieldDataInt(hStmt, col_index++, mailbox_name->mailbox_id);
+ _bindStmtFieldDataInt(hStmt, col_index++, mailbox_name->account_id);
+ _bindStmtFieldDataInt(hStmt, col_index++, mailbox_name->local_yn);
+ _bindStmtFieldDataString(hStmt, col_index++, (char *)mailbox_name->mailbox_name, 0, MAILBOX_NAME_LEN_IN_MAIL_BOX_TBL);
+ _bindStmtFieldDataInt(hStmt, col_index++, mailbox_name->mailbox_type);
+ _bindStmtFieldDataString(hStmt, col_index++, (char *)mailbox_name->alias, 0, ALIAS_LEN_IN_MAIL_BOX_TBL);
+ _bindStmtFieldDataInt(hStmt, col_index++, mailbox_name->sync_with_server_yn);
+ _bindStmtFieldDataInt(hStmt, col_index++, mailbox_name->modifiable_yn);
+ _bindStmtFieldDataInt(hStmt, col_index++, mailbox_name->total_mail_count_on_server);
+ _bindStmtFieldDataInt(hStmt, col_index++, 0);
+ _bindStmtFieldDataInt(hStmt, col_index++, mailbox_name->mail_slot_size);
+
+ /* rc = sqlite3_step(hStmt); */
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
+ EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("sqlite3_step fail:%dn", rc));
+
+ if (!em_storage_notify_storage_event(NOTI_MAILBOX_ADD, mailbox_name->account_id, 0, mailbox_name->mailbox_name, 0))
+ EM_DEBUG_EXCEPTION("em_storage_notify_storage_event[ NOTI_MAILBOX_ADD] : Notification Failed");
+ ret = true;
+
+FINISH_OFF:
+ if (hStmt != NULL) {
+ EM_DEBUG_LOG("before sqlite3_finalize hStmt = %p", hStmt);
+
+ rc = sqlite3_finalize(hStmt);
+ if (rc != SQLITE_OK) {
+ EM_DEBUG_EXCEPTION("sqlite3_finalize failed - %d", rc);
+ error = EM_STORAGE_ERROR_DB_FAILURE;
+ }
+ }
+
+ EM_STORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
+ _DISCONNECT_DB;
+
+ if (err_code != NULL)
+ *err_code = error;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+EXPORT_API int em_storage_set_all_mailbox_modifiable_yn(int account_id, int modifiable_yn, int transaction, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("account_id[%d], modifiable_yn[%d], err_code[%p]", account_id, modifiable_yn, err_code);
+
+ if (account_id < FIRST_ACCOUNT_ID) {
+
+ EM_DEBUG_EXCEPTION("account_id[%d]", account_id);
+
+ if (err_code != NULL)
+ *err_code = EM_STORAGE_ERROR_INVALID_PARAM;
+ return false;
+ }
+ int rc, ret = false;
+ int error = EM_STORAGE_ERROR_NONE;
+ char sql_query_string[QUERY_SIZE] = {0,};
+
+ sqlite3 *local_db_handle = em_storage_get_db_connection();
+ EM_STORAGE_START_WRITE_TRANSACTION(transaction, error);
+
+
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), "UPDATE mail_box_tbl SET modifiable_yn = %d WHERE account_id = %d", modifiable_yn, account_id);
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ rc = sqlite3_changes(local_db_handle);
+ if (rc == 0)
+ EM_DEBUG_EXCEPTION("All mailbox_name modifiable_yn set to 0 already");
+
+
+ ret = true;
+
+FINISH_OFF:
+ EM_STORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
+ _DISCONNECT_DB;
+
+ if (err_code != NULL)
+ *err_code = error;
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+
+
+}
+
+EXPORT_API int em_storage_delete_mailbox(int account_id, int local_yn, char *mailbox_name, int transaction, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("account_id[%d], local_yn[%d], mailbox_name[%p], transaction[%d], err_code[%p]", account_id, local_yn, mailbox_name, transaction, err_code);
+
+ if (account_id < FIRST_ACCOUNT_ID) {
+ EM_DEBUG_EXCEPTION(" account_id[%d], local_yn[%d], mailbox_name[%p]", account_id, local_yn, mailbox_name);
+
+ if (err_code != NULL)
+ *err_code = EM_STORAGE_ERROR_INVALID_PARAM;
+ return false;
+ }
+
+ int rc, ret = false;
+ int error = EM_STORAGE_ERROR_NONE;
+ char sql_query_string[QUERY_SIZE] = {0, };
+
+ sqlite3 *local_db_handle = em_storage_get_db_connection();
+ EM_STORAGE_START_WRITE_TRANSACTION(transaction, error);
+
+ if (local_yn == -1)
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), "DELETE FROM mail_box_tbl WHERE account_id = %d ", account_id);
+ else
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), "DELETE FROM mail_box_tbl WHERE account_id = %d AND local_yn = %d ", account_id, local_yn);
+
+ if (mailbox_name) { /* NULL means all mailbox_name */
+ SNPRINTF(sql_query_string + strlen(sql_query_string), sizeof(sql_query_string)-(1+ strlen(sql_query_string)), "AND UPPER(mailbox_name) = UPPER('%s')", mailbox_name);
+ }
+
+ EM_DEBUG_LOG("mailbox sql_query_string [%s]", sql_query_string);
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ rc = sqlite3_changes(local_db_handle);
+ if (rc == 0) {
+ EM_DEBUG_EXCEPTION(" no (matched) mailbox_name found...");
+ error = EM_STORAGE_ERROR_MAILBOX_NOT_FOUND;
+ ret = true;
+ }
+ ret = true;
+
+FINISH_OFF:
+
+ EM_STORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
+ _DISCONNECT_DB;
+
+ if (err_code != NULL)
+ *err_code = error;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+EXPORT_API int em_storage_free_mailbox(emf_mailbox_tbl_t** mailbox_list, int count, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("mailbox_list[%p], count[%d], err_code[%p]", mailbox_list, count, err_code);
+
+ int ret = false;
+ int error = EM_STORAGE_ERROR_NONE;
+
+ if (count > 0) {
+ if (!mailbox_list || !*mailbox_list) {
+ EM_DEBUG_EXCEPTION(" mailbox_list[%p], count[%d]", mailbox_list, count);
+
+ error = EM_STORAGE_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ emf_mailbox_tbl_t* p = *mailbox_list;
+ int i = 0;
+
+ for (; i < count; i++) {
+ EM_SAFE_FREE(p[i].mailbox_name);
+ EM_SAFE_FREE(p[i].alias);
+ }
+
+ EM_SAFE_FREE(p); *mailbox_list = NULL;
+ }
+
+ ret = true;
+
+FINISH_OFF:
+ if (err_code != NULL)
+ *err_code = error;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+EXPORT_API int em_storage_get_count_read_mail_uid(int account_id, char *mailbox_name, int *count, int transaction, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("account_id[%d], mailbox_name[%p], count[%p], transaction[%d], err_code[%p]", account_id, mailbox_name , count, transaction, err_code);
+
+ if (account_id < FIRST_ACCOUNT_ID || !mailbox_name || !count) { /* TODO: confirm me */
+ EM_DEBUG_EXCEPTION(" account_id[%d], mailbox_name[%p], count[%p], exist[%p]", account_id, mailbox_name, count);
+
+ if (err_code != NULL)
+ *err_code = EM_STORAGE_ERROR_INVALID_PARAM;
+ return false;
+ }
+
+ int rc = -1, ret = false;
+ int error = EM_STORAGE_ERROR_NONE;
+ char sql_query_string[QUERY_SIZE] = {0, };
+
+ sqlite3 *local_db_handle = em_storage_get_db_connection();
+ EM_STORAGE_START_READ_TRANSACTION(transaction);
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT COUNT(*) FROM mail_read_mail_uid_tbl WHERE account_id = %d AND mailbox_name = '%s' ", account_id, mailbox_name);
+ EM_DEBUG_LOG(">>> SQL [ %s ] ", sql_query_string);
+
+ char **result;
+ /* rc = sqlite3_get_table(local_db_handle, sql_query_string, &result, NULL, NULL, NULL); */
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, NULL, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EM_STORAGE_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+ ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ *count = atoi(result[1]);
+ sqlite3_free_table(result);
+
+ ret = true;
+
+FINISH_OFF:
+ EM_STORAGE_FINISH_READ_TRANSACTION(transaction);
+ _DISCONNECT_DB;
+
+ if (err_code != NULL)
+ *err_code = error;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+
+
+EXPORT_API int em_storage_check_read_mail_uid(int account_id, char *mailbox_name, char *uid, int *exist, int transaction, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("account_id[%d], mailbox_name[%p], uid[%p], exist[%p], transaction[%d], err_code[%p]", account_id, mailbox_name , uid, exist, transaction, err_code);
+
+ if (account_id < FIRST_ACCOUNT_ID || !uid || !exist) {
+ EM_DEBUG_EXCEPTION(" account_id[%d], mailbox_name[%p], uid[%p], exist[%p]", account_id, mailbox_name , uid, exist);
+
+ if (err_code != NULL)
+ *err_code = EM_STORAGE_ERROR_INVALID_PARAM;
+ return false;
+ }
+
+ int rc = -1, ret = false;
+ int error = EM_STORAGE_ERROR_NONE;
+ char sql_query_string[QUERY_SIZE] = {0, };
+ sqlite3 *local_db_handle = em_storage_get_db_connection();
+ EM_STORAGE_START_READ_TRANSACTION(transaction);
+
+ if (mailbox_name) {
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT COUNT(*) FROM mail_read_mail_uid_tbl WHERE account_id = %d AND mailbox_name = '%s' AND s_uid = '%s' ", account_id, mailbox_name, uid);
+ }
+ else {
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT COUNT(*) FROM mail_read_mail_uid_tbl WHERE account_id = %d AND s_uid = '%s' ", account_id, uid);
+ }
+
+ char **result;
+ /* rc = sqlite3_get_table(local_db_handle, sql_query_string, &result, NULL, NULL, NULL); */
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, NULL, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EM_STORAGE_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+ ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ *exist = atoi(result[1]);
+ sqlite3_free_table(result);
+
+ if (*exist > 0)
+ *exist = 1;
+ else
+ *exist = 0;
+
+ ret = true;
+
+FINISH_OFF:
+ EM_STORAGE_FINISH_READ_TRANSACTION(transaction);
+ _DISCONNECT_DB;
+
+ if (err_code != NULL)
+ *err_code = error;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+EXPORT_API int em_storage_get_downloaded_mail(int mail_id, emf_mail_tbl_t** mail, int transaction, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("mail_id[%d], mail[%p], err_code[%p]", mail_id, mail, err_code);
+
+ if (!mail) {
+ EM_DEBUG_EXCEPTION(" mail_id[%d], mail[%p]", mail_id, mail);
+ if (err_code != NULL)
+ *err_code = EM_STORAGE_ERROR_INVALID_PARAM;
+ return false;
+ }
+
+ int rc, ret = false, temp_rule;
+ int error = EM_STORAGE_ERROR_NONE;
+ DB_STMT hStmt = NULL;
+ char sql_query_string[QUERY_SIZE] = {0, };
+
+ sqlite3 *local_db_handle = em_storage_get_db_connection();
+ EM_STORAGE_START_READ_TRANSACTION(transaction);
+
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT * FROM mail_read_mail_uid_tbl WHERE local_uid = %d", mail_id);
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
+ EM_DEBUG_LOG("sqlite3_prepare hStmt = %p", hStmt);
+
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ /* rc = sqlite3_step(hStmt); */
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
+ EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("sqlite3_step fail:%d", rc));
+
+ *mail = (emf_mail_tbl_t*)malloc(sizeof(emf_mail_tbl_t));
+ if (*mail == NULL) {
+ error = EM_STORAGE_ERROR_OUT_OF_MEMORY;
+ EM_DEBUG_EXCEPTION("Memory allocation for mail failed.");
+ goto FINISH_OFF;
+
+ }
+ memset(*mail, 0x00, sizeof(emf_mail_tbl_t));
+
+ _getStmtFieldDataInt(hStmt, &((*mail)->account_id), ACCOUNT_ID_IDX_IN_MAIL_READ_MAIL_UID_TBL);
+ _getStmtFieldDataString(hStmt, &((*mail)->mailbox_name), 0, LOCAL_MBOX_IDX_IN_MAIL_READ_MAIL_UID_TBL);
+ _getStmtFieldDataInt(hStmt, &((*mail)->mail_id), LOCAL_UID_IDX_IN_MAIL_READ_MAIL_UID_TBL);
+ _getStmtFieldDataString(hStmt, &((*mail)->server_mailbox_name), 0, MAILBOX_NAME_IDX_IN_MAIL_READ_MAIL_UID_TBL);
+ _getStmtFieldDataString(hStmt, &((*mail)->server_mail_id), 0, S_UID_IDX_IN_MAIL_READ_MAIL_UID_TBL);
+ _getStmtFieldDataInt(hStmt, &((*mail)->mail_size), DATA1_IDX_IN_MAIL_READ_MAIL_UID_TBL);
+ _getStmtFieldDataInt(hStmt, &temp_rule, FLAG_IDX_IN_MAIL_READ_MAIL_UID_TBL);
+
+ (*mail)->server_mail_status = 1;
+
+ ret = true;
+
+FINISH_OFF:
+ if (hStmt != NULL) {
+ EM_DEBUG_LOG("before sqlite3_finalize hStmt = %p", hStmt);
+ rc = sqlite3_finalize(hStmt);
+ if (rc != SQLITE_OK) {
+ EM_DEBUG_EXCEPTION(" sqlite3_finalize failed - %d", rc);
+ error = EM_STORAGE_ERROR_DB_FAILURE;
+ }
+ }
+
+ EM_STORAGE_FINISH_READ_TRANSACTION(transaction);
+ _DISCONNECT_DB;
+
+ if (err_code != NULL)
+ *err_code = error;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+EXPORT_API int em_storage_get_downloaded_list(int account_id, char *local_mbox, emf_mail_read_mail_uid_tbl_t** read_mail_uid, int *count, int transaction, int *err_code)
+{
+ EM_PROFILE_BEGIN(emStorageGetDownloadList);
+ EM_DEBUG_FUNC_BEGIN("account_id[%d], local_mbox[%s], read_mail_uid[%p], count[%p], transaction[%d], err_code[%p]", account_id, local_mbox, read_mail_uid, count, transaction, err_code);
+ if (account_id < FIRST_ACCOUNT_ID || !read_mail_uid || !count) {
+ EM_DEBUG_EXCEPTION(" account_id[%d], local_mbox[%s], read_mail_uid[%p], count[%p]", account_id, local_mbox, read_mail_uid, count);
+
+ if (err_code != NULL)
+ *err_code = EM_STORAGE_ERROR_INVALID_PARAM;
+ return false;
+ }
+
+ int rc, ret = false;
+ int error = EM_STORAGE_ERROR_NONE;
+
+ DB_STMT hStmt = NULL;
+ char sql_query_string[QUERY_SIZE] = {0, };
+
+ emf_mail_read_mail_uid_tbl_t* p_data_tbl = NULL;
+ int i = 0;
+
+ sqlite3 *local_db_handle = em_storage_get_db_connection();
+ EM_STORAGE_START_READ_TRANSACTION(transaction);
+
+ if (local_mbox)
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT * FROM mail_read_mail_uid_tbl WHERE account_id = %d AND UPPER(local_mbox) = UPPER('%s')", account_id, local_mbox);
+ else
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT * FROM mail_read_mail_uid_tbl WHERE account_id = %d", account_id);
+
+ EM_DEBUG_LOG(" sql_query_string : %s", sql_query_string);
+
+
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
+ EM_DEBUG_LOG("sqlite3_prepare hStmt = %p", hStmt);
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ /* rc = sqlite3_step(hStmt); */
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
+ EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("sqlite3_step fail:%d", rc));
+
+ char **result;
+ /* rc = sqlite3_get_table(local_db_handle, sql_query_string, &result, count, NULL, NULL); */
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, count, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EM_STORAGE_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+ ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ sqlite3_free_table(result);
+ if (*count == 0) {
+ EM_DEBUG_LOG("No mail found in mail_read_mail_uid_tbl");
+ ret = true;
+ goto FINISH_OFF;
+ }
+
+
+ if (!(p_data_tbl = (emf_mail_read_mail_uid_tbl_t*)malloc(sizeof(emf_mail_read_mail_uid_tbl_t) * *count))) {
+ EM_DEBUG_EXCEPTION(" malloc failed...");
+ error = EM_STORAGE_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ memset(p_data_tbl, 0x00, sizeof(emf_mail_read_mail_uid_tbl_t)* *count);
+
+ for (i = 0; i < *count; ++i) {
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl[i].account_id), ACCOUNT_ID_IDX_IN_MAIL_READ_MAIL_UID_TBL);
+ _getStmtFieldDataString(hStmt, &(p_data_tbl[i].local_mbox), 0, LOCAL_MBOX_IDX_IN_MAIL_READ_MAIL_UID_TBL);
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl[i].local_uid), LOCAL_UID_IDX_IN_MAIL_READ_MAIL_UID_TBL);
+ _getStmtFieldDataString(hStmt, &(p_data_tbl[i].mailbox_name), 0, MAILBOX_NAME_IDX_IN_MAIL_READ_MAIL_UID_TBL);
+ _getStmtFieldDataString(hStmt, &(p_data_tbl[i].s_uid), 0, S_UID_IDX_IN_MAIL_READ_MAIL_UID_TBL);
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl[i].data1), DATA1_IDX_IN_MAIL_READ_MAIL_UID_TBL);
+ _getStmtFieldDataString(hStmt, &(p_data_tbl[i].data2), 0, DATA2_IDX_IN_MAIL_READ_MAIL_UID_TBL);
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl[i].flag), FLAG_IDX_IN_MAIL_READ_MAIL_UID_TBL);
+ /* rc = sqlite3_step(hStmt); */
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
+ EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("sqlite3_step fail:%d", rc));
+ }
+
+ ret = true;
+
+FINISH_OFF:
+ if (ret == true)
+ *read_mail_uid = p_data_tbl;
+ else if (p_data_tbl)
+ em_storage_free_read_mail_uid(&p_data_tbl, *count, NULL);
+
+ if (hStmt != NULL) {
+ EM_DEBUG_LOG(" Before sqlite3_finalize hStmt = %p", hStmt);
+ rc = sqlite3_finalize(hStmt);
+ if (rc != SQLITE_OK) {
+ EM_DEBUG_LOG(" sqlite3_finalize failed - %d", rc);
+
+ error = EM_STORAGE_ERROR_DB_FAILURE;
+ }
+ }
+
+ EM_STORAGE_FINISH_READ_TRANSACTION(transaction);
+ _DISCONNECT_DB;
+
+ if (err_code != NULL)
+ *err_code = error;
+
+ EM_PROFILE_END(emStorageGetDownloadList);
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+EXPORT_API int em_storage_get_downloaded_mail_size(int account_id, char *local_mbox, int local_uid, char *mailbox_name, char *uid, int *mail_size, int transaction, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("account_id[%d], local_mbox[%p], locacal_uid[%d], mailbox_name[%p], uid[%p], mail_size[%p], transaction[%d], err_code[%p]", account_id, local_mbox, local_uid, mailbox_name, uid, mail_size, transaction, err_code);
+
+ if (account_id < FIRST_ACCOUNT_ID || !mail_size) {
+ EM_DEBUG_EXCEPTION(" account_id[%d], local_mbox[%p], locacal_uid[%d], mailbox_name[%p], uid[%p], mail_size[%p]", account_id, local_mbox, local_uid, mailbox_name, uid, mail_size);
+
+ if (err_code != NULL)
+ *err_code = EM_STORAGE_ERROR_INVALID_PARAM;
+ return false;
+ }
+
+ int rc, ret = false;
+ int error = EM_STORAGE_ERROR_NONE;
+ DB_STMT hStmt = NULL;
+ char sql_query_string[QUERY_SIZE] = {0, };
+
+
+ sqlite3 *local_db_handle = em_storage_get_db_connection();
+ EM_STORAGE_START_READ_TRANSACTION(transaction);
+
+ if (mailbox_name) {
+ SNPRINTF(sql_query_string, sizeof(sql_query_string),
+ "SELECT IFNULL(MAX(data1), 0) FROM mail_read_mail_uid_tbl "
+ "WHERE account_id = %d "
+ "AND local_mbox = '%s' "
+ "AND local_uid = %d "
+ "AND mailbox_name = '%s' "
+ "AND s_uid = '%s'",
+ account_id, local_mbox, local_uid, mailbox_name, uid);
+ }
+ else {
+ SNPRINTF(sql_query_string, sizeof(sql_query_string),
+ "SELECT IFNULL(MAX(data1), 0) FROM mail_read_mail_uid_tbl "
+ "WHERE account_id = %d "
+ "AND local_mbox = '%s' "
+ "AND local_uid = %d "
+ "AND s_uid = '%s'",
+ account_id, local_mbox, local_uid, uid);
+ }
+
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ /* rc = sqlite3_step(hStmt); */
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
+ EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("sqlite3_step fail:%d", rc));
+
+ if (rc == SQLITE_DONE) {
+ EM_DEBUG_EXCEPTION(" no matched mail found....");
+ error = EM_STORAGE_ERROR_MAIL_NOT_FOUND;
+ goto FINISH_OFF;
+ }
+
+ _getStmtFieldDataInt(hStmt, mail_size, 0);
+
+ ret = true;
+
+FINISH_OFF:
+ if (hStmt != NULL) {
+ rc = sqlite3_finalize(hStmt);
+ if (rc != SQLITE_OK) {
+ EM_DEBUG_LOG(" sqlite3_finalize failed - %d", rc);
+
+ error = EM_STORAGE_ERROR_DB_FAILURE;
+ }
+ }
+
+ EM_STORAGE_FINISH_READ_TRANSACTION(transaction);
+ _DISCONNECT_DB;
+
+ if (err_code != NULL)
+ *err_code = error;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+EXPORT_API int em_storage_add_downloaded_mail(emf_mail_read_mail_uid_tbl_t* read_mail_uid, int transaction, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("read_mail_uid[%p], transaction[%d], err_code[%p]", read_mail_uid, transaction, err_code);
+
+ if (!read_mail_uid) {
+ EM_DEBUG_EXCEPTION("read_mail_uid[%p]", read_mail_uid);
+ if (err_code != NULL)
+ *err_code = EM_STORAGE_ERROR_INVALID_PARAM;
+ return false;
+ }
+
+ int rc, rc2, ret = false;
+ int error = EM_STORAGE_ERROR_NONE;
+ DB_STMT hStmt = NULL;
+ char sql_query_string[QUERY_SIZE] = {0, };
+
+ sqlite3 *local_db_handle = em_storage_get_db_connection();
+ EM_STORAGE_START_WRITE_TRANSACTION(transaction, error);
+
+ char *sql = "SELECT max(rowid) FROM mail_read_mail_uid_tbl;";
+ char **result = NULL;
+
+ /* rc = sqlite3_get_table(local_db_handle, sql, &result, NULL, NULL, NULL); */
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql, &result, NULL, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EM_STORAGE_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+ ("SQL(%s) sqlite3_get_table fail:%d -%s", sql, rc, sqlite3_errmsg(local_db_handle)));
+
+ if (NULL==result[1]) rc = 1;
+ else rc = atoi(result[1])+1;
+ sqlite3_free_table(result);
+
+ SNPRINTF(sql_query_string, sizeof(sql_query_string),
+ "INSERT INTO mail_read_mail_uid_tbl VALUES "
+ "( ?"
+ ", ?"
+ ", ?"
+ ", ?"
+ ", ?"
+ ", ?"
+ ", ?"
+ ", ?"
+ ", ? )");
+
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc2);
+ if (rc2 != SQLITE_OK) {
+ EM_DEBUG_LOG("sqlite3_prepare hStmt = %p", hStmt);
+ EM_DEBUG_EXCEPTION("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle));
+
+ error = EM_STORAGE_ERROR_DB_FAILURE;
+ goto FINISH_OFF;
+ }
+
+ EM_DEBUG_LOG("account_id VALUE [%d] ", read_mail_uid->account_id);
+ EM_DEBUG_LOG("local_mbox VALUE [%s] ", read_mail_uid->local_mbox);
+ EM_DEBUG_LOG("local_uid VALUE [%d] ", read_mail_uid->local_uid);
+ EM_DEBUG_LOG("mailbox_name VALUE [%s] ", read_mail_uid->mailbox_name);
+ EM_DEBUG_LOG("s_uid VALUE [%s] ", read_mail_uid->s_uid);
+ EM_DEBUG_LOG("data1 VALUE [%d] ", read_mail_uid->data1);
+ EM_DEBUG_LOG("data2 VALUE [%s] ", read_mail_uid->data2);
+ EM_DEBUG_LOG("flag VALUE [%d] ", read_mail_uid->flag);
+ EM_DEBUG_LOG("rc VALUE [%d] ", rc);
+
+ _bindStmtFieldDataInt(hStmt, ACCOUNT_ID_IDX_IN_MAIL_READ_MAIL_UID_TBL, read_mail_uid->account_id);
+ _bindStmtFieldDataString(hStmt, LOCAL_MBOX_IDX_IN_MAIL_READ_MAIL_UID_TBL, (char *)read_mail_uid->local_mbox, 0, LOCAL_MBOX_LEN_IN_MAIL_READ_MAIL_UID_TBL);
+ _bindStmtFieldDataInt(hStmt, LOCAL_UID_IDX_IN_MAIL_READ_MAIL_UID_TBL, read_mail_uid->local_uid);
+ _bindStmtFieldDataString(hStmt, MAILBOX_NAME_IDX_IN_MAIL_READ_MAIL_UID_TBL, (char *)read_mail_uid->mailbox_name, 0, MAILBOX_NAME_LEN_IN_MAIL_READ_MAIL_UID_TBL);
+ _bindStmtFieldDataString(hStmt, S_UID_IDX_IN_MAIL_READ_MAIL_UID_TBL, (char *)read_mail_uid->s_uid, 0, S_UID_LEN_IN_MAIL_READ_MAIL_UID_TBL);
+ _bindStmtFieldDataInt(hStmt, DATA1_IDX_IN_MAIL_READ_MAIL_UID_TBL, read_mail_uid->data1);
+ _bindStmtFieldDataString(hStmt, DATA2_IDX_IN_MAIL_READ_MAIL_UID_TBL, (char *)read_mail_uid->data2, 0, DATA2_LEN_IN_MAIL_READ_MAIL_UID_TBL);
+ _bindStmtFieldDataInt(hStmt, FLAG_IDX_IN_MAIL_READ_MAIL_UID_TBL, read_mail_uid->flag);
+ _bindStmtFieldDataInt(hStmt, IDX_NUM_IDX_IN_MAIL_READ_MAIL_UID_TBL, rc);
+
+ /* rc = sqlite3_step(hStmt); */
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
+ EM_DEBUG_DB_EXEC((rc == SQLITE_FULL), {error = EM_STORAGE_ERROR_DB_IS_FULL;goto FINISH_OFF; },
+ ("sqlite3_step fail:%d", rc));
+ EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("sqlite3_step fail[%d] [%s]", rc, sqlite3_errmsg(local_db_handle)));
+
+
+ ret = true;
+
+FINISH_OFF:
+ if (hStmt != NULL) {
+ EM_DEBUG_LOG(" sqlite3_finalize hStmt = %p", hStmt);
+
+ rc = sqlite3_finalize(hStmt);
+ if (rc != SQLITE_OK) {
+ EM_DEBUG_LOG(" sqlite3_finalize failed - %d", rc);
+ error = EM_STORAGE_ERROR_DB_FAILURE;
+ }
+ }
+
+ EM_STORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
+ _DISCONNECT_DB;
+
+ if (err_code != NULL)
+ *err_code = error;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+EXPORT_API int em_storage_change_read_mail_uid(int account_id, char *local_mbox, int local_uid, char *mailbox_name, char *uid, emf_mail_read_mail_uid_tbl_t* read_mail_uid, int transaction, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("account_id[%d], local_mbox[%p], local_uid[%d], mailbox_name[%p], uid[%p], read_mail_uid[%p], transaction[%d], err_code[%p]", account_id, local_mbox, local_uid, mailbox_name, uid, read_mail_uid, transaction, err_code);
+
+ if (account_id < FIRST_ACCOUNT_ID || !read_mail_uid) {
+ EM_DEBUG_EXCEPTION(" account_id[%d], local_mbox[%p], local_uid[%d], mailbox_name[%p], uid[%p], read_mail_uid[%p]", account_id, local_mbox, local_uid, mailbox_name, uid, read_mail_uid);
+
+ if (err_code != NULL)
+ *err_code = EM_STORAGE_ERROR_INVALID_PARAM;
+ return false;
+ }
+
+ int rc, ret = false;
+ int error = EM_STORAGE_ERROR_NONE;
+ DB_STMT hStmt = NULL;
+ char sql_query_string[QUERY_SIZE] = {0, };
+
+ sqlite3 *local_db_handle = em_storage_get_db_connection();
+
+ EM_STORAGE_START_WRITE_TRANSACTION(transaction, error);
+
+ SNPRINTF(sql_query_string, sizeof(sql_query_string),
+ "UPDATE mail_read_mail_uid_tbl SET"
+ " account_id = ?"
+ ", local_mbox = ?"
+ ", local_uid = ?"
+ ", mailbox_name = ?"
+ ", s_uid = ?"
+ ", data1 = ?"
+ ", data2 = ?"
+ ", flag = ?"
+ " WHERE account_id = ?"
+ " AND local_mbox = ?"
+ " AND local_uid = ?"
+ " AND mailbox_name= ?"
+ " AND s_uid = ?");
+
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
+ EM_DEBUG_LOG("sqlite3_prepare hStmt = %p", hStmt);
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+
+ int i = 0;
+
+ _bindStmtFieldDataInt(hStmt, i++, read_mail_uid->account_id);
+ _bindStmtFieldDataString(hStmt, i++, (char *)read_mail_uid->local_mbox, 0, LOCAL_MBOX_LEN_IN_MAIL_READ_MAIL_UID_TBL);
+ _bindStmtFieldDataInt(hStmt, i++, read_mail_uid->local_uid);
+ _bindStmtFieldDataString(hStmt, i++, (char *)read_mail_uid->mailbox_name, 0, MAILBOX_NAME_LEN_IN_MAIL_READ_MAIL_UID_TBL);
+ _bindStmtFieldDataString(hStmt, i++, (char *)read_mail_uid->s_uid, 0, S_UID_LEN_IN_MAIL_READ_MAIL_UID_TBL);
+ _bindStmtFieldDataInt(hStmt, i++, read_mail_uid->data1);
+ _bindStmtFieldDataString(hStmt, i++, (char *)read_mail_uid->data2, 0, DATA2_LEN_IN_MAIL_READ_MAIL_UID_TBL);
+ _bindStmtFieldDataInt(hStmt, i++, read_mail_uid->flag);
+ _bindStmtFieldDataInt(hStmt, i++, account_id);
+ _bindStmtFieldDataString(hStmt, i++, (char *)local_mbox, 0, LOCAL_MBOX_LEN_IN_MAIL_READ_MAIL_UID_TBL);
+ _bindStmtFieldDataInt(hStmt, i++, local_uid);
+ _bindStmtFieldDataString(hStmt, i++, (char *)mailbox_name, 0, MAILBOX_NAME_LEN_IN_MAIL_READ_MAIL_UID_TBL);
+ _bindStmtFieldDataString(hStmt, i++, (char *)uid, 0, S_UID_LEN_IN_MAIL_READ_MAIL_UID_TBL);
+
+ /* rc = sqlite3_step(hStmt); */
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
+ EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("sqlite3_step fail:%d", rc));
+
+ ret = true;
+
+FINISH_OFF:
+ if (hStmt != NULL) {
+ EM_DEBUG_LOG("sqlite3_finalize hStmt = %p", hStmt);
+
+ rc = sqlite3_finalize(hStmt);
+ if (rc != SQLITE_OK) {
+ EM_DEBUG_LOG(" sqlite3_finalize failed - %d", rc);
+
+ error = EM_STORAGE_ERROR_DB_FAILURE;
+ }
+ }
+
+ EM_STORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
+ _DISCONNECT_DB;
+
+ if (err_code != NULL)
+ *err_code = error;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+EXPORT_API int em_storage_remove_downloaded_mail(int account_id, char *mailbox_name, char *uid, int transaction, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("account_id[%d], mailbox_name[%s], uid[%s], transaction[%d], err_code[%p]", account_id, mailbox_name, uid, transaction, err_code);
+
+ if (account_id < FIRST_ACCOUNT_ID) {
+ EM_DEBUG_EXCEPTION(" account_id[%d], mailbox_name[%s], uid[%s]", account_id, mailbox_name, uid);
+
+ if (err_code != NULL)
+ *err_code = EM_STORAGE_ERROR_INVALID_PARAM;
+ return false;
+ }
+
+ int rc, ret = false;
+ int error = EM_STORAGE_ERROR_NONE;
+ char sql_query_string[QUERY_SIZE] = {0, };
+
+ sqlite3 *local_db_handle = em_storage_get_db_connection();
+
+ EM_STORAGE_START_WRITE_TRANSACTION(transaction, error);
+
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), "DELETE FROM mail_read_mail_uid_tbl WHERE account_id = %d ", account_id);
+
+ if (mailbox_name) { /* NULL means all mailbox_name */
+ SNPRINTF(sql_query_string+strlen(sql_query_string), sizeof(sql_query_string) - (1 + strlen(sql_query_string)), "AND mailbox_name = '%s' ", mailbox_name);
+ }
+
+ if (uid) { /* NULL means all mail */
+ SNPRINTF(sql_query_string+strlen(sql_query_string), sizeof(sql_query_string) - (1 + strlen(sql_query_string)), "AND s_uid='%s' ", uid);
+ }
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+
+ ret = true;
+
+FINISH_OFF:
+
+ EM_STORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
+ _DISCONNECT_DB;
+
+ if (err_code != NULL)
+ *err_code = error;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+EXPORT_API int em_storage_free_read_mail_uid(emf_mail_read_mail_uid_tbl_t** read_mail_uid, int count, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("read_mail_uid[%p], count[%d], err_code[%p]", read_mail_uid, count, err_code);
+
+ int ret = false;
+ int error = EM_STORAGE_ERROR_NONE;
+
+ if (count > 0) {
+ if (!read_mail_uid || !*read_mail_uid) {
+ EM_DEBUG_EXCEPTION(" read_mail_uid[%p], count[%d]", read_mail_uid, count);
+
+ error = EM_STORAGE_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ emf_mail_read_mail_uid_tbl_t* p = *read_mail_uid;
+ int i;
+
+ for (i = 0; i < count; i++) {
+ EM_SAFE_FREE(p[i].local_mbox);
+ EM_SAFE_FREE(p[i].mailbox_name);
+ EM_SAFE_FREE(p[i].s_uid);
+ EM_SAFE_FREE(p[i].data2);
+ }
+
+ EM_SAFE_FREE(p); *read_mail_uid = NULL;
+ }
+
+ ret = true;
+
+FINISH_OFF:
+ if (err_code != NULL)
+ *err_code = error;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+EXPORT_API int em_storage_get_rule_count(int account_id, int *count, int transaction, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("account_id[%d], count[%p], transaction[%d], err_code[%p]", account_id, count, transaction, err_code);
+
+ if (account_id != ALL_ACCOUNT || !count) { /* only global rule supported. */
+ EM_DEBUG_EXCEPTION(" account_id[%d], count[%p]", account_id, count);
+
+ if (err_code != NULL)
+ *err_code = EM_STORAGE_ERROR_INVALID_PARAM;
+ return false;
+ }
+
+ int rc = -1, ret = false;
+ int error = EM_STORAGE_ERROR_NONE;
+ char sql_query_string[QUERY_SIZE] = {0, };
+
+ sqlite3 *local_db_handle = em_storage_get_db_connection();
+ EM_STORAGE_START_READ_TRANSACTION(transaction);
+
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT COUNT(*) FROM mail_rule_tbl WHERE account_id = %d", account_id);
+
+ char **result;
+ /* rc = sqlite3_get_table(local_db_handle, sql_query_string, &result, NULL, NULL, NULL); */
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, NULL, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EM_STORAGE_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+ ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ *count = atoi(result[1]);
+ sqlite3_free_table(result);
+
+ ret = true;
+
+FINISH_OFF:
+ EM_STORAGE_FINISH_READ_TRANSACTION(transaction);
+ _DISCONNECT_DB;
+
+ if (err_code != NULL)
+ *err_code = error;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+EXPORT_API int em_storage_get_rule(int account_id, int type, int start_idx, int *select_num, int *is_completed, emf_mail_rule_tbl_t** rule_list, int transaction, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("account_id[%d], type[%d], start_idx[%d], select_num[%p], is_completed[%p], rule_list[%p], transaction[%d], err_code[%p]", account_id, type, start_idx, select_num, is_completed, rule_list, transaction, err_code);
+
+ if (account_id != ALL_ACCOUNT || !select_num || !is_completed || !rule_list) { /* only global rule supported. */
+ EM_DEBUG_EXCEPTION(" account_id[%d], type[%d], start_idx[%d], select_num[%p], is_completed[%p], rule_list[%p]", account_id, type, start_idx, select_num, is_completed, rule_list);
+
+ if (err_code != NULL)
+ *err_code = EM_STORAGE_ERROR_INVALID_PARAM;
+ return false;
+ }
+
+ int ret = false;
+ int error = EM_STORAGE_ERROR_NONE;
+
+ emf_mail_rule_tbl_t* p_data_tbl = NULL;
+ int i = 0, count = 0;
+ DB_STMT hStmt = NULL;
+ char sql_query_string[QUERY_SIZE] = {0, };
+
+ int rc;
+
+ sqlite3 *local_db_handle = em_storage_get_db_connection();
+ EM_STORAGE_START_READ_TRANSACTION(transaction);
+
+ if (type)
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT * FROM mail_rule_tbl WHERE account_id = %d AND type = %d", account_id, type);
+ else
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT * FROM mail_rule_tbl WHERE account_id = %d ORDER BY type", account_id);
+
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
+ EM_DEBUG_LOG("sqlite3_prepare hStmt = %p", hStmt);
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ /* rc = sqlite3_step(hStmt); */
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
+ EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("sqlite3_step fail:%d", rc));
+
+ char **result;
+ /* rc = sqlite3_get_table(local_db_handle, sql_query_string, &result, &count, NULL, NULL); */
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, &count, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EM_STORAGE_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+ ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ sqlite3_free_table(result);
+
+ if (count == 0) {
+ EM_DEBUG_LOG(" no matched rule found...");
+ ret = true;
+ goto FINISH_OFF;
+ }
+
+
+ if (!(p_data_tbl = (emf_mail_rule_tbl_t*)malloc(sizeof(emf_mail_rule_tbl_t) * count))) {
+ EM_DEBUG_EXCEPTION(" malloc failed...");
+
+ error = EM_STORAGE_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ memset(p_data_tbl, 0x00, sizeof(emf_mail_rule_tbl_t) * count);
+
+ for (i = 0; i < count; i++) {
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl[i].account_id), ACCOUNT_ID_IDX_IN_MAIL_RULE_TBL);
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl[i].rule_id), RULE_ID_IDX_IN_MAIL_RULE_TBL);
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl[i].type), TYPE_IDX_IN_MAIL_RULE_TBL);
+ _getStmtFieldDataString(hStmt, &(p_data_tbl[i].value), 0, VALUE_IDX_IN_MAIL_RULE_TBL);
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl[i].action_type), ACTION_TYPE_IDX_IN_MAIL_RULE_TBL);
+ _getStmtFieldDataString(hStmt, &(p_data_tbl[i].dest_mailbox), 0, DEST_MAILBOX_IDX_IN_MAIL_RULE_TBL);
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl[i].flag1), FLAG1_IDX_IN_MAIL_RULE_TBL);
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl[i].flag2), FLAG2_IDX_IN_MAIL_RULE_TBL);
+ /* rc = sqlite3_step(hStmt); */
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
+ EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("sqlite3_step fail:%d", rc));
+ }
+
+ ret = true;
+
+FINISH_OFF:
+
+ EM_DEBUG_LOG("[%d] rules found.", count);
+
+ if (ret == true) {
+ *rule_list = p_data_tbl;
+ *select_num = count;
+ }
+ else if (p_data_tbl != NULL)
+ em_storage_free_rule(&p_data_tbl, count, NULL); /* CID FIX */
+
+ if (hStmt != NULL) {
+ EM_DEBUG_LOG(" sqlite3_finalize hStmt = %p", hStmt);
+
+ rc = sqlite3_finalize(hStmt);
+ if (rc != SQLITE_OK) {
+ EM_DEBUG_LOG(" sqlite3_finalize failed - %d", rc);
+ error = EM_STORAGE_ERROR_DB_FAILURE;
+ }
+ }
+
+
+ EM_STORAGE_FINISH_READ_TRANSACTION(transaction);
+ _DISCONNECT_DB;
+
+ if (err_code != NULL)
+ *err_code = error;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+EXPORT_API int em_storage_get_rule_by_id(int account_id, int rule_id, emf_mail_rule_tbl_t** rule, int transaction, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("account_id[%d], rule_id[%d], rule[%p], transaction[%d], err_code[%p]", account_id, rule_id, rule, transaction, err_code);
+
+ if (account_id != ALL_ACCOUNT || !rule) {
+ EM_DEBUG_EXCEPTION(" account_id[%d], rule_id[%d], rule[%p]", account_id, rule_id, rule);
+
+ if (err_code != NULL)
+ *err_code = EM_STORAGE_ERROR_INVALID_PARAM;
+ return false;
+ }
+
+ emf_mail_rule_tbl_t* p_data_tbl = NULL;
+ int rc, ret = false;
+ int error = EM_STORAGE_ERROR_NONE;
+
+ DB_STMT hStmt = NULL;
+ char sql_query_string[QUERY_SIZE] = {0, };
+ sqlite3 *local_db_handle = em_storage_get_db_connection();
+ EM_STORAGE_START_READ_TRANSACTION(transaction);
+
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT * FROM mail_rule_tbl WHERE account_id = %d AND rule_id = %d", account_id, rule_id);
+
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ /* rc = sqlite3_step(hStmt); */
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
+ EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("sqlite3_step fail:%d", rc));
+
+ if (rc == SQLITE_DONE) {
+ EM_DEBUG_EXCEPTION(" no matched rule found...");
+ error = EM_STORAGE_ERROR_RULE_NOT_FOUND;
+ goto FINISH_OFF;
+ }
+
+ if (!(p_data_tbl = (emf_mail_rule_tbl_t*)malloc(sizeof(emf_mail_rule_tbl_t)))) {
+ EM_DEBUG_EXCEPTION(" malloc failed...");
+ error = EM_STORAGE_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ memset(p_data_tbl, 0x00, sizeof(emf_mail_rule_tbl_t));
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl->account_id), ACCOUNT_ID_IDX_IN_MAIL_RULE_TBL);
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl->rule_id), RULE_ID_IDX_IN_MAIL_RULE_TBL);
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl->type), TYPE_IDX_IN_MAIL_RULE_TBL);
+ _getStmtFieldDataString(hStmt, &(p_data_tbl->value), 0, VALUE_IDX_IN_MAIL_RULE_TBL);
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl->action_type), ACTION_TYPE_IDX_IN_MAIL_RULE_TBL);
+ _getStmtFieldDataString(hStmt, &(p_data_tbl->dest_mailbox), 0, DEST_MAILBOX_IDX_IN_MAIL_RULE_TBL);
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl->flag1), FLAG1_IDX_IN_MAIL_RULE_TBL);
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl->flag2), FLAG2_IDX_IN_MAIL_RULE_TBL);
+
+ ret = true;
+
+FINISH_OFF:
+ if (ret == true)
+ *rule = p_data_tbl;
+ else if (p_data_tbl != NULL)
+ em_storage_free_rule(&p_data_tbl, 1, NULL);
+
+ if (hStmt != NULL) {
+ EM_DEBUG_LOG(" before sqlite3_finalize hStmt = %p", hStmt);
+
+ rc = sqlite3_finalize(hStmt);
+ if (rc != SQLITE_OK) {
+ EM_DEBUG_LOG(" sqlite3_finalize failed - %d", rc);
+
+ error = EM_STORAGE_ERROR_DB_FAILURE;
+ }
+ }
+
+
+
+ EM_STORAGE_FINISH_READ_TRANSACTION(transaction);
+ _DISCONNECT_DB;
+
+ if (err_code != NULL)
+ *err_code = error;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+EXPORT_API int em_storage_change_rule(int account_id, int rule_id, emf_mail_rule_tbl_t* new_rule, int transaction, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("account_id[%d], rule_id[%d], new_rule[%p], transaction[%d], err_code[%p]", account_id, rule_id, new_rule, transaction, err_code);
+
+ if (account_id != ALL_ACCOUNT || !new_rule) { /* only global rule supported. */
+ EM_DEBUG_EXCEPTION(" account_id[%d], rule_id[%d], new_rule[%p]", account_id, rule_id, new_rule);
+
+ if (err_code != NULL)
+ *err_code = EM_STORAGE_ERROR_INVALID_PARAM;
+ return false;
+ }
+
+ int rc, ret = false;
+ int error = EM_STORAGE_ERROR_NONE;
+
+ DB_STMT hStmt = NULL;
+ char sql_query_string[QUERY_SIZE] = {0, };
+ sqlite3 *local_db_handle = em_storage_get_db_connection();
+ EM_STORAGE_START_WRITE_TRANSACTION(transaction, error);
+
+ SNPRINTF(sql_query_string, sizeof(sql_query_string),
+ "UPDATE mail_rule_tbl SET"
+ " type = ?"
+ ", value = ?"
+ ", action_type = ?"
+ ", dest_mailbox = ?"
+ ", flag1 = ?"
+ ", flag2 = ?"
+ " WHERE account_id = ?"
+ " AND rule_id = ?");
+
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
+ EM_DEBUG_LOG(" Before sqlite3_prepare hStmt = %p", hStmt);
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ int i = 0;
+
+ _bindStmtFieldDataInt(hStmt, i++, new_rule->type);
+ _bindStmtFieldDataString(hStmt, i++, (char *)new_rule->value, 0, VALUE_LEN_IN_MAIL_RULE_TBL);
+ _bindStmtFieldDataInt(hStmt, i++, new_rule->action_type);
+ _bindStmtFieldDataString(hStmt, i++, (char *)new_rule->dest_mailbox, 0, DEST_MAILBOX_LEN_IN_MAIL_RULE_TBL);
+ _bindStmtFieldDataInt(hStmt, i++, new_rule->flag1);
+ _bindStmtFieldDataInt(hStmt, i++, new_rule->flag2);
+ _bindStmtFieldDataInt(hStmt, i++, account_id);
+ _bindStmtFieldDataInt(hStmt, i++, rule_id);
+
+ /* rc = sqlite3_step(hStmt); */
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
+ EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("sqlite3_step fail:%d", rc));
+
+ ret = true;
+
+FINISH_OFF:
+ if (hStmt != NULL) {
+ EM_DEBUG_LOG(" Before sqlite3_finalize hStmt = %p", hStmt);
+
+ rc = sqlite3_finalize(hStmt);
+ if (rc != SQLITE_OK) {
+ EM_DEBUG_LOG(" sqlite3_finalize failed - %d", rc);
+
+ error = EM_STORAGE_ERROR_DB_FAILURE;
+ }
+ }
+
+ EM_STORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
+ _DISCONNECT_DB;
+
+ if (err_code != NULL)
+ *err_code = error;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+EXPORT_API int em_storage_find_rule(emf_mail_rule_tbl_t* rule, int transaction, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("rule[%p], transaction[%d], err_code[%p]", rule, transaction, err_code);
+
+ if (!rule || rule->account_id != ALL_ACCOUNT) { /* only global rule supported. */
+ if (rule != NULL)
+ EM_DEBUG_EXCEPTION(" rule->account_id[%d]", rule->account_id);
+
+ if (err_code != NULL)
+ *err_code = EM_STORAGE_ERROR_INVALID_PARAM;
+ return false;
+ }
+
+ DB_STMT hStmt = NULL;
+ char sql_query_string[QUERY_SIZE] = {0, };
+
+ int error = EM_STORAGE_ERROR_NONE;
+ int rc, ret = false;
+
+ sqlite3 *local_db_handle = em_storage_get_db_connection();
+ EM_STORAGE_START_READ_TRANSACTION(transaction);
+
+ SNPRINTF(sql_query_string, sizeof(sql_query_string),
+ "SELECT rule_id FROM mail_rule_tbl WHERE type = %d AND UPPER(value) = UPPER('%s')",
+ rule->type, rule->value);
+
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ /* rc = sqlite3_step(hStmt); */
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
+ EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("sqlite3_step fail:%d", rc));
+
+ if (rc == SQLITE_DONE) {
+ EM_DEBUG_EXCEPTION(" no matched rule found...");
+ error = EM_STORAGE_ERROR_RULE_NOT_FOUND;
+ goto FINISH_OFF;
+ }
+
+
+ ret = true;
+
+FINISH_OFF:
+ if (hStmt != NULL) {
+ EM_DEBUG_LOG("before sqlite3_finalize hStmt = %p", hStmt);
+
+ rc = sqlite3_finalize(hStmt);
+ if (rc != SQLITE_OK) {
+ EM_DEBUG_EXCEPTION(" sqlite3_finalize failed - %d", rc);
+ error = EM_STORAGE_ERROR_DB_FAILURE;
+ }
+ }
+
+
+ EM_STORAGE_FINISH_READ_TRANSACTION(transaction);
+ _DISCONNECT_DB;
+
+ if (err_code)
+ *err_code = error;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+EXPORT_API int em_storage_add_rule(emf_mail_rule_tbl_t* rule, int transaction, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("rule[%p], transaction[%d], err_code[%p]", rule, transaction, err_code);
+
+ if (!rule || rule->account_id != ALL_ACCOUNT) { /* only global rule supported. */
+ if (rule != NULL)
+ EM_DEBUG_EXCEPTION(" rule->account_id[%d]", rule->account_id);
+
+ if (err_code != NULL)
+ *err_code = EM_STORAGE_ERROR_INVALID_PARAM;
+ return false;
+ }
+
+ int rc, rc_2, ret = false;
+ int error = EM_STORAGE_ERROR_NONE;
+ DB_STMT hStmt = NULL;
+ char sql_query_string[QUERY_SIZE] = {0, };
+
+
+ sqlite3 *local_db_handle = em_storage_get_db_connection();
+
+ EM_STORAGE_START_WRITE_TRANSACTION(transaction, error);
+
+ char *sql;
+ char **result;
+ sql = "SELECT max(rowid) FROM mail_rule_tbl;";
+ /* rc = sqlite3_get_table(local_db_handle, sql, &result, NULL, NULL, NULL); */
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql, &result, NULL, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EM_STORAGE_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+ ("SQL(%s) sqlite3_get_table fail:%d -%s", sql, rc, sqlite3_errmsg(local_db_handle)));
+
+ if (NULL==result[1])
+ rc = 1;
+ else
+ rc = atoi(result[1])+1;
+ sqlite3_free_table(result);
+
+ SNPRINTF(sql_query_string, sizeof(sql_query_string),
+ "INSERT INTO mail_rule_tbl VALUES "
+ "( ?" /* account id */
+ ", ?" /* rule_id */
+ ", ?" /* type */
+ ", ?" /* value */
+ ", ?" /* action_type */
+ ", ?" /* dest_mailbox */
+ ", ?" /* flag1 */
+ ", ?)"); /* flag2 */
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc_2);
+ if (rc_2 != SQLITE_OK) {
+ EM_DEBUG_EXCEPTION("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc_2, sqlite3_errmsg(local_db_handle));
+ error = EM_STORAGE_ERROR_DB_FAILURE;
+ goto FINISH_OFF;
+ }
+
+ _bindStmtFieldDataInt(hStmt, ACCOUNT_ID_IDX_IN_MAIL_RULE_TBL, rule->account_id);
+ _bindStmtFieldDataInt(hStmt, RULE_ID_IDX_IN_MAIL_RULE_TBL, rc);
+ _bindStmtFieldDataInt(hStmt, TYPE_IDX_IN_MAIL_RULE_TBL, rule->type);
+ _bindStmtFieldDataString(hStmt, VALUE_IDX_IN_MAIL_RULE_TBL, (char *)rule->value, 0, VALUE_LEN_IN_MAIL_RULE_TBL);
+ _bindStmtFieldDataInt(hStmt, ACTION_TYPE_IDX_IN_MAIL_RULE_TBL, rule->action_type);
+ _bindStmtFieldDataString(hStmt, DEST_MAILBOX_IDX_IN_MAIL_RULE_TBL, (char *)rule->dest_mailbox, 0, DEST_MAILBOX_LEN_IN_MAIL_RULE_TBL);
+ _bindStmtFieldDataInt(hStmt, FLAG1_IDX_IN_MAIL_RULE_TBL, rule->flag1);
+ _bindStmtFieldDataInt(hStmt, FLAG2_IDX_IN_MAIL_RULE_TBL, rule->flag2);
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
+ EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("sqlite3_step fail:%d", rc));
+
+ ret = true;
+
+FINISH_OFF:
+ if (hStmt != NULL) {
+ EM_DEBUG_LOG(" Before sqlite3_finalize hStmt = %p", hStmt);
+
+ rc = sqlite3_finalize(hStmt);
+ if (rc != SQLITE_OK) {
+ EM_DEBUG_LOG(" sqlite3_finalize failed - %d", rc);
+
+ error = EM_STORAGE_ERROR_DB_FAILURE;
+ }
+ }
+
+ EM_STORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
+ _DISCONNECT_DB;
+
+ if (err_code != NULL)
+ *err_code = error;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+EXPORT_API int em_storage_delete_rule(int account_id, int rule_id, int transaction, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("account_id[%d], rule_id[%d], transaction[%d], err_code[%p]", account_id, rule_id, transaction, err_code);
+
+ if (account_id != ALL_ACCOUNT) { /* only global rule supported. */
+ EM_DEBUG_EXCEPTION(" account_id[%d], rule_id[%d]", account_id, rule_id);
+
+ if (err_code != NULL)
+ *err_code = EM_STORAGE_ERROR_INVALID_PARAM;
+ return false;
+ }
+
+ int rc, ret = false;
+ int error = EM_STORAGE_ERROR_NONE;
+ char sql_query_string[QUERY_SIZE] = {0, };
+
+ sqlite3 *local_db_handle = em_storage_get_db_connection();
+ EM_STORAGE_START_WRITE_TRANSACTION(transaction, error);
+
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), "DELETE FROM mail_rule_tbl WHERE account_id = %d AND rule_id = %d", account_id, rule_id);
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+ rc = sqlite3_changes(local_db_handle);
+ if (rc == 0) {
+ EM_DEBUG_EXCEPTION(" no matched rule found...");
+
+ error = EM_STORAGE_ERROR_RULE_NOT_FOUND;
+ goto FINISH_OFF;
+ }
+
+ ret = true;
+
+FINISH_OFF:
+ EM_STORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
+ _DISCONNECT_DB;
+
+ if (err_code != NULL)
+ *err_code = error;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+EXPORT_API int em_storage_free_rule(emf_mail_rule_tbl_t** rule_list, int count, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("rule_list[%p], conut[%d], err_code[%p]", rule_list, count, err_code);
+
+ int ret = false;
+ int error = EM_STORAGE_ERROR_NONE;
+
+ if (count > 0) {
+ if (!rule_list || !*rule_list) {
+ EM_DEBUG_EXCEPTION(" rule_list[%p], conut[%d]", rule_list, count);
+
+ error = EM_STORAGE_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ emf_mail_rule_tbl_t* p = *rule_list;
+ int i = 0;
+
+ for (; i < count; i++) {
+ EM_SAFE_FREE(p[i].value);
+ EM_SAFE_FREE(p[i].dest_mailbox);
+ }
+
+ EM_SAFE_FREE(p); *rule_list = NULL;
+ }
+
+FINISH_OFF:
+ if (err_code != NULL)
+ *err_code = error;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+EXPORT_API int em_storage_get_mail_count(int account_id, const char *mailbox_name, int *total, int *unseen, int transaction, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("account_id[%d], mailbox_name[%s], total[%p], unseen[%p], transaction[%d], err_code[%p]", account_id, mailbox_name, total, unseen, transaction, err_code);
+
+ if (!total && !unseen) { /* TODO: confirm me */
+ EM_DEBUG_EXCEPTION(" accoun_id[%d], mailbox_name[%s], total[%p], unseen[%p]", account_id, mailbox_name, total, unseen);
+
+ if (err_code != NULL)
+ *err_code = EM_STORAGE_ERROR_INVALID_PARAM;
+ return false;
+ }
+
+ int rc = -1, ret = false;
+ int error = EM_STORAGE_ERROR_NONE;
+ DB_STMT hStmt = NULL;
+ char sql_query_string[QUERY_SIZE] = {0, };
+ char err_msg[1024];
+
+
+ memset(&sql_query_string, 0x00, sizeof(sql_query_string));
+ sqlite3 *local_db_handle = em_storage_get_db_connection();
+ EM_STORAGE_START_READ_TRANSACTION(transaction);
+
+ if (total) {
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT COUNT(*) FROM mail_tbl");
+
+ if (account_id != ALL_ACCOUNT) {
+ SNPRINTF(sql_query_string + strlen(sql_query_string), sizeof(sql_query_string)-(strlen(sql_query_string)+1), " WHERE account_id = %d", account_id);
+ if (mailbox_name)
+ SNPRINTF(sql_query_string + strlen(sql_query_string), sizeof(sql_query_string)-(strlen(sql_query_string)+1), " AND UPPER(mailbox_name) = UPPER('%s')", mailbox_name);
+ }
+ else if (mailbox_name)
+ SNPRINTF(sql_query_string + strlen(sql_query_string), sizeof(sql_query_string)-(strlen(sql_query_string)+1), " WHERE UPPER(mailbox_name) = UPPER('%s')", mailbox_name);
+
+#ifdef USE_GET_RECORD_COUNT_API
+ char **result;
+ /* rc = sqlite3_get_table(local_db_handle, sql_query_string, &result, NULL, NULL, NULL); */
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, NULL, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EM_STORAGE_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF2; },
+ ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ *total = atoi(result[1]);
+ sqlite3_free_table(result);
+#else
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF2; },
+ ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+ /* rc = sqlite3_step(hStmt); */
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
+ EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF2; },
+ ("sqlite3_step fail:%d", rc));
+ _getStmtFieldDataInt(hStmt, total, 0);
+#endif /* USE_GET_RECORD_COUNT_API */
+ }
+
+ if (unseen) {
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT COUNT(*) FROM mail_tbl WHERE flags_seen_field = 0"); /* fSEEN = 0x01 */
+
+ if (account_id != ALL_ACCOUNT)
+ SNPRINTF(sql_query_string + strlen(sql_query_string), sizeof(sql_query_string)-(strlen(sql_query_string)+1), " AND account_id = %d", account_id);
+
+ if (mailbox_name)
+ SNPRINTF(sql_query_string + strlen(sql_query_string), sizeof(sql_query_string)-(strlen(sql_query_string)+1), " AND mailbox_name = '%s'", mailbox_name);
+ else
+ SNPRINTF(sql_query_string + strlen(sql_query_string), sizeof(sql_query_string)-(strlen(sql_query_string)+1), " AND mailbox_type NOT IN (3, 5)");
+
+ char **result;
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, NULL, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EM_STORAGE_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+ ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ *unseen = atoi(result[1]);
+ sqlite3_free_table(result);
+
+ }
+FINISH_OFF:
+ ret = true;
+
+FINISH_OFF2:
+
+#ifndef USE_PREPARED_QUERY_
+ if (hStmt != NULL) {
+ rc = sqlite3_finalize(hStmt);
+ if (rc != SQLITE_OK) {
+ EM_DEBUG_LOG(" EDBStmtClearRow failed - %d: %s", rc, err_msg);
+ error = EM_STORAGE_ERROR_DB_FAILURE;
+ }
+ }
+#endif
+
+ EM_STORAGE_FINISH_READ_TRANSACTION(transaction);
+ _DISCONNECT_DB;
+
+ if (err_code != NULL)
+ *err_code = error;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+EXPORT_API int em_storage_get_mail_field_by_id(int mail_id, int type, emf_mail_tbl_t** mail, int transaction, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("mail_id[%d], type[%d], mail[%p], transaction[%d], err_code[%p]", mail_id, type, mail, transaction, err_code);
+
+ if (mail_id <= 0 || !mail) {
+ EM_DEBUG_EXCEPTION("mail_id[%d], mail[%p]", mail_id, mail);
+ if (err_code != NULL)
+ *err_code = EM_STORAGE_ERROR_INVALID_PARAM;
+ return false;
+ }
+
+ emf_mail_tbl_t* p_data_tbl = (emf_mail_tbl_t*)malloc(sizeof(emf_mail_tbl_t));
+
+ if (p_data_tbl == NULL) {
+ EM_DEBUG_EXCEPTION("malloc failed...");
+ if (err_code != NULL)
+ *err_code = EM_STORAGE_ERROR_OUT_OF_MEMORY;
+ return false;
+ }
+
+ memset(p_data_tbl, 0x00, sizeof(emf_mail_tbl_t));
+ DB_STMT hStmt = NULL;
+ char sql_query_string[QUERY_SIZE] = {0, };
+
+ int rc, ret = false;
+ int error = EM_STORAGE_ERROR_NONE;
+
+ sqlite3 *local_db_handle = em_storage_get_db_connection();
+ EM_STORAGE_START_READ_TRANSACTION(transaction);
+
+ switch (type) {
+ case RETRIEVE_SUMMARY:
+ SNPRINTF(sql_query_string, sizeof(sql_query_string),
+ "SELECT account_id, mail_id, mailbox_name, server_mail_status, server_mailbox_name, server_mail_id, file_path_plain, file_path_html, flags_seen_field, save_status, lock_status, thread_id, thread_item_count FROM mail_tbl WHERE mail_id = %d", mail_id);
+ break;
+
+ case RETRIEVE_FIELDS_FOR_DELETE:
+ SNPRINTF(sql_query_string, sizeof(sql_query_string),
+ "SELECT account_id, mail_id, server_mail_status, server_mailbox_name, server_mail_id FROM mail_tbl WHERE mail_id = %d", mail_id);
+ break;
+
+ case RETRIEVE_ACCOUNT:
+ SNPRINTF(sql_query_string, sizeof(sql_query_string),
+ "SELECT account_id FROM mail_tbl WHERE mail_id = %d", mail_id);
+ break;
+
+ case RETRIEVE_FLAG:
+ SNPRINTF(sql_query_string, sizeof(sql_query_string),
+ "SELECT account_id, mailbox_name, flags_seen_field, thread_id FROM mail_tbl WHERE mail_id = %d", mail_id);
+ break;
+
+ default :
+ EM_DEBUG_EXCEPTION("EM_STORAGE_ERROR_INVALID_PARAM : type [%d]", type);
+ error = EM_STORAGE_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ EM_DEBUG_LOG("Query [%s]", sql_query_string);
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ /* rc = sqlite3_step(hStmt); */
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
+ EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("sqlite3_step fail:%d", rc));
+
+ if (rc == SQLITE_DONE) {
+ EM_DEBUG_EXCEPTION("no matched mail found...");
+ error = EM_STORAGE_ERROR_MAIL_NOT_FOUND;
+ goto FINISH_OFF;
+ }
+ switch (type) {
+ case RETRIEVE_SUMMARY:
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl->account_id), 0);
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl->mail_id), 1);
+ _getStmtFieldDataString(hStmt, &(p_data_tbl->mailbox_name), 0, 2);
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl->server_mail_status), 3);
+ _getStmtFieldDataString(hStmt, &(p_data_tbl->server_mailbox_name), 0, 4);
+ _getStmtFieldDataString(hStmt, &(p_data_tbl->server_mail_id), 0, 5);
+ _getStmtFieldDataString(hStmt, &(p_data_tbl->file_path_plain), 0, 6);
+ _getStmtFieldDataString(hStmt, &(p_data_tbl->file_path_html), 0, 7);
+ _getStmtFieldDataChar(hStmt, &(p_data_tbl->flags_seen_field), 8);
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl->save_status), 9);
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl->lock_status), 10);
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl->thread_id), 11);
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl->thread_item_count), 12);
+ break;
+
+ case RETRIEVE_FIELDS_FOR_DELETE:
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl->account_id), 0);
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl->mail_id), 1);
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl->server_mail_status), 2);
+ _getStmtFieldDataString(hStmt, &(p_data_tbl->server_mailbox_name), 0, 3);
+ _getStmtFieldDataString(hStmt, &(p_data_tbl->server_mail_id), 0, 4);
+ break;
+
+ case RETRIEVE_ACCOUNT:
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl->account_id), 0);
+ break;
+
+ case RETRIEVE_FLAG:
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl->account_id), 0);
+ _getStmtFieldDataString(hStmt, &(p_data_tbl->mailbox_name), 0, 1);
+ _getStmtFieldDataChar(hStmt, &(p_data_tbl->flags_seen_field), 2);
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl->thread_id), 3);
+ break;
+ }
+
+ ret = true;
+
+FINISH_OFF:
+ if (ret == true)
+ *mail = p_data_tbl;
+ else if (p_data_tbl != NULL)
+ em_storage_free_mail(&p_data_tbl, 1, NULL);
+
+ if (hStmt != NULL) {
+ EM_DEBUG_LOG("Before sqlite3_finalize hStmt = %p", hStmt);
+
+ rc = sqlite3_finalize(hStmt);
+ if (rc != SQLITE_OK) {
+ EM_DEBUG_EXCEPTION("sqlite3_finalize failed - %d", rc);
+ error = EM_STORAGE_ERROR_DB_FAILURE;
+ }
+ }
+
+
+ EM_STORAGE_FINISH_READ_TRANSACTION(transaction);
+ _DISCONNECT_DB;
+
+ if (err_code != NULL)
+ *err_code = error;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+EXPORT_API int em_storage_get_mail_field_by_multiple_mail_id(int mail_ids[], int number_of_mails, int type, emf_mail_tbl_t** mail, int transaction, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("mail_ids[%p], number_of_mails [%d], type[%d], mail[%p], transaction[%d], err_code[%p]", mail_ids, number_of_mails, type, mail, transaction, err_code);
+
+ if (number_of_mails <= 0 || !mail_ids) {
+ EM_DEBUG_EXCEPTION("EM_STORAGE_ERROR_INVALID_PARAM");
+ if (err_code != NULL)
+ *err_code = EM_STORAGE_ERROR_INVALID_PARAM;
+ return false;
+ }
+
+ emf_mail_tbl_t* p_data_tbl = (emf_mail_tbl_t*)em_core_malloc(sizeof(emf_mail_tbl_t) * number_of_mails);
+
+ if (p_data_tbl == NULL) {
+ EM_DEBUG_EXCEPTION("malloc failed...");
+ if (err_code != NULL)
+ *err_code = EM_STORAGE_ERROR_OUT_OF_MEMORY;
+ return false;
+ }
+
+ DB_STMT hStmt = NULL;
+ int ret = false;
+ int error = EM_STORAGE_ERROR_NONE;
+ int i = 0, item_count = 0, rc = -1, field_count, col_index, cur_sql_query_string = 0;
+ char **result = NULL;
+ char sql_query_string[QUERY_SIZE] = {0, };
+
+ sqlite3 *local_db_handle = em_storage_get_db_connection();
+ EM_STORAGE_START_READ_TRANSACTION(transaction);
+
+ switch (type) {
+ case RETRIEVE_SUMMARY:
+ cur_sql_query_string = SNPRINTF(sql_query_string, sizeof(sql_query_string),
+ "SELECT account_id, mail_id, mailbox_name, server_mail_status, server_mailbox_name, server_mail_id, file_path_plain, file_path_html, flags_seen_field, save_status, lock_status, thread_id, thread_item_count FROM mail_tbl WHERE mail_id in (");
+ field_count = 13;
+ break;
+
+ case RETRIEVE_FIELDS_FOR_DELETE:
+ cur_sql_query_string = SNPRINTF(sql_query_string, sizeof(sql_query_string),
+ "SELECT account_id, mail_id, server_mail_status, server_mailbox_name, server_mail_id FROM mail_tbl WHERE mail_id in (");
+ field_count = 5;
+ break;
+
+ case RETRIEVE_ACCOUNT:
+ cur_sql_query_string = SNPRINTF(sql_query_string, sizeof(sql_query_string),
+ "SELECT account_id FROM mail_tbl WHERE mail_id in (");
+ field_count = 1;
+ break;
+
+ case RETRIEVE_FLAG:
+ cur_sql_query_string = SNPRINTF(sql_query_string, sizeof(sql_query_string),
+ "SELECT account_id, mailbox_name, flags_seen_field, thread_id FROM mail_tbl WHERE mail_id in (");
+ field_count = 4;
+ break;
+
+ default :
+ EM_DEBUG_EXCEPTION("EM_STORAGE_ERROR_INVALID_PARAM : type [%d]", type);
+ error = EM_STORAGE_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ for(i = 0; i < number_of_mails; i++)
+ cur_sql_query_string += SNPRINTF_OFFSET(sql_query_string, cur_sql_query_string, QUERY_SIZE, "%d,", mail_ids[i]);
+ sql_query_string[strlen(sql_query_string) - 1] = ')';
+
+ EM_DEBUG_LOG("Query [%s], Length [%d]", sql_query_string, strlen(sql_query_string));
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, &item_count, 0, NULL), rc);
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc && -1 != rc), {error = EM_STORAGE_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+ ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ if (rc == SQLITE_DONE) {
+ EM_DEBUG_EXCEPTION("no matched mail found...");
+ error = EM_STORAGE_ERROR_MAIL_NOT_FOUND;
+ goto FINISH_OFF;
+ }
+
+ EM_DEBUG_LOG("item_count [%d]", item_count);
+
+ if(number_of_mails != item_count) {
+ EM_DEBUG_EXCEPTION("Can't find all emails");
+ /* error = EM_STORAGE_ERROR_MAIL_NOT_FOUND;
+ goto FINISH_OFF; */ /* removed temporarily */
+ }
+
+ col_index = field_count;
+
+ for(i = 0; i < item_count; i++) {
+ switch (type) {
+ case RETRIEVE_SUMMARY:
+ _getTableFieldDataInt(result, &(p_data_tbl[i].account_id), col_index++);
+ _getTableFieldDataInt(result, &(p_data_tbl[i].mail_id), col_index++);
+ _getTableFieldDataString(result, &(p_data_tbl[i].mailbox_name), 0, col_index++);
+ _getTableFieldDataInt(result, &(p_data_tbl[i].server_mail_status), col_index++);
+ _getTableFieldDataString(result, &(p_data_tbl[i].server_mailbox_name), 0, col_index++);
+ _getTableFieldDataString(result, &(p_data_tbl[i].server_mail_id), 0, col_index++);
+ _getTableFieldDataString(result, &(p_data_tbl[i].file_path_plain), 0, col_index++);
+ _getTableFieldDataString(result, &(p_data_tbl[i].file_path_html), 0, col_index++);
+ _getTableFieldDataChar(result, &(p_data_tbl[i].flags_seen_field), col_index++);
+ _getTableFieldDataInt(result, &(p_data_tbl[i].save_status), col_index++);
+ _getTableFieldDataInt(result, &(p_data_tbl[i].lock_status), col_index++);
+ _getTableFieldDataInt(result, &(p_data_tbl[i].thread_id), col_index++);
+ _getTableFieldDataInt(result, &(p_data_tbl[i].thread_item_count), col_index++);
+ break;
+
+ case RETRIEVE_FIELDS_FOR_DELETE:
+ _getTableFieldDataInt(result, &(p_data_tbl[i].account_id), col_index++);
+ _getTableFieldDataInt(result, &(p_data_tbl[i].mail_id), col_index++);
+ _getTableFieldDataInt(result, &(p_data_tbl[i].server_mail_status), col_index++);
+ _getTableFieldDataString(result, &(p_data_tbl[i].server_mailbox_name), 0, col_index++);
+ _getTableFieldDataString(result, &(p_data_tbl[i].server_mail_id), 0, col_index++);
+ break;
+
+ case RETRIEVE_ACCOUNT:
+ _getTableFieldDataInt(result, &(p_data_tbl[i].account_id), col_index++);
+ break;
+
+ case RETRIEVE_FLAG:
+ _getTableFieldDataInt(result, &(p_data_tbl[i].account_id), col_index++);
+ _getTableFieldDataString(result, &(p_data_tbl[i].mailbox_name), 0, col_index++);
+ _getTableFieldDataChar(result, &(p_data_tbl[i].flags_seen_field), col_index++);
+ _getTableFieldDataInt(result, &(p_data_tbl[i].thread_id), col_index++);
+ break;
+ }
+ }
+
+ sqlite3_free_table(result);
+
+ ret = true;
+
+FINISH_OFF:
+ if (ret == true)
+ *mail = p_data_tbl;
+ else if (p_data_tbl != NULL)
+ em_storage_free_mail(&p_data_tbl, 1, NULL);
+
+ if (hStmt != NULL) {
+ EM_DEBUG_LOG("Before sqlite3_finalize hStmt = %p", hStmt);
+
+ rc = sqlite3_finalize(hStmt);
+ if (rc != SQLITE_OK) {
+ EM_DEBUG_EXCEPTION("sqlite3_finalize failed - %d", rc);
+ error = EM_STORAGE_ERROR_DB_FAILURE;
+ }
+ }
+
+ EM_STORAGE_FINISH_READ_TRANSACTION(transaction);
+ _DISCONNECT_DB;
+
+ if (err_code != NULL)
+ *err_code = error;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+EXPORT_API int em_storage_get_mail_by_id(int mail_id, emf_mail_tbl_t** mail, int transaction, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("mail_id[%d], mail[%p], transaction[%d], err_code[%p]", mail_id, mail, transaction, err_code);
+
+ if (mail_id <= 0 || !mail) {
+ EM_DEBUG_EXCEPTION("mail_id[%d], mail[%p]", mail_id, mail);
+ if (err_code != NULL)
+ *err_code = EM_STORAGE_ERROR_INVALID_PARAM;
+ return false;
+ }
+
+ int ret = false, error = EM_STORAGE_ERROR_NONE, count;
+ char conditional_clause[QUERY_SIZE] = {0, };
+ emf_mail_tbl_t* p_data_tbl = NULL;
+
+ SNPRINTF(conditional_clause, QUERY_SIZE, "WHERE mail_id = %d", mail_id);
+ EM_DEBUG_LOG("query = [%s]", conditional_clause);
+
+ if(!em_storage_query_mail_tbl(conditional_clause, transaction, &p_data_tbl, &count, &error)) {
+ EM_DEBUG_EXCEPTION("em_storage_query_mail_tbl [%d]", error);
+ goto FINISH_OFF;
+ }
+
+ ret = true;
+
+FINISH_OFF:
+ if (ret == true)
+ *mail = p_data_tbl;
+ else if (p_data_tbl != NULL)
+ em_storage_free_mail(&p_data_tbl, 1, &error);
+
+ if (err_code != NULL)
+ *err_code = error;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+EXPORT_API int em_storage_mail_search_start(emf_mail_search_t* search, int account_id, char *mailbox_name, int sorting, int *search_handle, int *searched, int transaction, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("search[%p], account_id[%d], mailbox_name[%p], sorting[%d], search_handle[%p], searched[%p], transaction[%d], err_code[%p]", search, account_id, mailbox_name, sorting, search_handle, searched, transaction, err_code);
+
+ if (!search_handle || !searched) {
+ if (err_code != NULL)
+ *err_code = EM_STORAGE_ERROR_INVALID_PARAM;
+ EM_DEBUG_EXCEPTION("EM_STORAGE_ERROR_INVALID_PARAM");
+ EM_DEBUG_FUNC_END("false");
+ return false;
+ }
+
+ emf_mail_search_t* p = search;
+ int error = EM_STORAGE_ERROR_NONE;
+ DB_STMT hStmt = NULL;
+ char sql_query_string[QUERY_SIZE] = {0, };
+ int rc, ret = false;
+ int and = false, mail_count = 0;
+
+ sqlite3 *local_db_handle = em_storage_get_db_connection();
+ EM_STORAGE_START_READ_TRANSACTION(transaction);
+
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT * FROM mail_tbl");
+
+ if (account_id != ALL_ACCOUNT) {
+ SNPRINTF(sql_query_string + strlen(sql_query_string), sizeof(sql_query_string)-(strlen(sql_query_string)+1), " WHERE account_id = %d", account_id);
+ and = true;
+ }
+
+ if (mailbox_name) {
+ SNPRINTF(sql_query_string + strlen(sql_query_string), sizeof(sql_query_string)-(strlen(sql_query_string)+1), " %s mailbox_name = '%s'", and ? "AND" : "WHERE", mailbox_name);
+ and = true;
+ }
+
+ while (p) {
+
+ if (p->key_type) {
+ if (!strncmp(p->key_type, "subject", strlen("subject"))) {
+ SNPRINTF(sql_query_string + strlen(sql_query_string), sizeof(sql_query_string)-(strlen(sql_query_string)+1), " %s subject LIKE '%%%%%s%%%%'", and ? "AND" : "WHERE", p->key_value);
+ and = true;
+ }
+ else if (!strncmp(p->key_type, "full_address_from", strlen("full_address_from"))) {
+ SNPRINTF(sql_query_string + strlen(sql_query_string), sizeof(sql_query_string)-(strlen(sql_query_string)+1), " %s full_address_from LIKE '%%%%%s%%%%'", and ? "AND" : "WHERE", p->key_value);
+ and = true;
+ }
+ else if (!strncmp(p->key_type, "full_address_to", strlen("full_address_to"))) {
+ SNPRINTF(sql_query_string + strlen(sql_query_string), sizeof(sql_query_string)-(strlen(sql_query_string)+1), " %s full_address_to LIKE '%%%%%s%%%%'", and ? "AND" : "WHERE", p->key_value);
+ and = true;
+ }
+ else if (!strncmp(p->key_type, "email_address", strlen("email_address"))) {
+ SNPRINTF(sql_query_string + strlen(sql_query_string), sizeof(sql_query_string)-(strlen(sql_query_string)+1), " %s email_address_sender = '%s' OR email_address_recipient = '%s'", and ? "AND" : "WHERE", p->key_value, p->key_value);
+ and = true;
+ }
+ p = p->next;
+ }
+ }
+
+ if (sorting)
+ SNPRINTF(sql_query_string + strlen(sql_query_string), sizeof(sql_query_string)-(strlen(sql_query_string)+1), " ORDER BY date_time");
+
+ EM_DEBUG_LOG("sql_query_string [%s]", sql_query_string);
+
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ /* rc = sqlite3_step(hStmt); */
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
+ EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("sqlite3_step fail:%d", rc));
+
+ char **result;
+ /* rc = sqlite3_get_table(local_db_handle, sql_query_string, &result, NULL, NULL, NULL); */
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, &mail_count, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EM_STORAGE_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+ ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ sqlite3_free_table(result);
+
+ ret = true;
+
+FINISH_OFF:
+ if (ret == true) {
+ *search_handle = (int)hStmt;
+ *searched = mail_count;
+ EM_DEBUG_LOG("mail_count [%d]", mail_count);
+ }
+ else {
+ if (hStmt != NULL) {
+ rc = sqlite3_finalize(hStmt);
+ if (rc != SQLITE_OK) {
+ EM_DEBUG_EXCEPTION("sqlite3_finalize failed - %d", rc);
+ error = EM_STORAGE_ERROR_DB_FAILURE;
+ }
+ }
+
+ EM_STORAGE_FINISH_READ_TRANSACTION(transaction);
+ _DISCONNECT_DB;
+ }
+
+ if (err_code != NULL)
+ *err_code = error;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+EXPORT_API int em_storage_mail_search_result(int search_handle, emf_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);
+
+ if (search_handle < 0 || !data) {
+ EM_DEBUG_EXCEPTION(" search_handle[%d], type[%d], data[%p]", search_handle, type, data);
+
+ if (err_code != NULL)
+ *err_code = EM_STORAGE_ERROR_INVALID_PARAM;
+ return false;
+ }
+
+ emf_mail_tbl_t* p_data_tbl = NULL;
+ DB_STMT hStmt = (DB_STMT)search_handle;
+ int rc, ret = false;
+ int error = EM_STORAGE_ERROR_NONE;
+
+ switch (type) {
+ case RETRIEVE_ID:
+ _getStmtFieldDataInt(hStmt, (int *)data, MAIL_ID_IDX_IN_MAIL_TBL);
+ break;
+
+ case RETRIEVE_ENVELOPE:
+ case RETRIEVE_ALL:
+ if (!(p_data_tbl = em_core_malloc(sizeof(emf_mail_tbl_t)))) {
+ EM_DEBUG_EXCEPTION(" em_core_malloc failed...");
+
+ error = EM_STORAGE_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl->mail_id), MAIL_ID_IDX_IN_MAIL_TBL);
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl->account_id), ACCOUNT_ID_IDX_IN_MAIL_TBL);
+ _getStmtFieldDataString(hStmt, &(p_data_tbl->mailbox_name), 0, MAILBOX_NAME_IDX_IN_MAIL_TBL);
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl->mail_size), MAIL_SIZE_IDX_IN_MAIL_TBL);
+ _getStmtFieldDataString(hStmt, &(p_data_tbl->server_mail_id), 0, SERVER_MAIL_ID_IDX_IN_MAIL_TBL);
+ _getStmtFieldDataString(hStmt, &(p_data_tbl->full_address_from), 1, FULL_ADDRESS_FROM_IDX_IN_MAIL_TBL);
+ _getStmtFieldDataString(hStmt, &(p_data_tbl->full_address_to), 1, FULL_ADDRESS_TO_IDX_IN_MAIL_TBL);
+ _getStmtFieldDataString(hStmt, &(p_data_tbl->subject), 1, SUBJECT_IDX_IN_MAIL_TBL);
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl->body_download_status), BODY_DOWNLOAD_STATUS_IDX_IN_MAIL_TBL);
+ _getStmtFieldDataString(hStmt, &(p_data_tbl->file_path_plain), 0, FILE_PATH_PLAIN_IDX_IN_MAIL_TBL);
+ _getStmtFieldDataString(hStmt, &(p_data_tbl->file_path_html), 0, FILE_PATH_HTML_IDX_IN_MAIL_TBL);
+ _getStmtFieldDataString(hStmt, &(p_data_tbl->datetime), 0, DATETIME_IDX_IN_MAIL_TBL);
+ _getStmtFieldDataChar(hStmt, &(p_data_tbl->flags_seen_field), FLAGS_SEEN_FIELD_IDX_IN_MAIL_TBL);
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl->DRM_status), DRM_STATUS_IDX_IN_MAIL_TBL);
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl->priority), PRIORITY_IDX_IN_MAIL_TBL);
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl->save_status), SAVE_STATUS_IDX_IN_MAIL_TBL);
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl->lock_status), LOCK_STATUS_IDX_IN_MAIL_TBL);
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl->report_status), REPORT_STATUS_IDX_IN_MAIL_TBL);
+ _getStmtFieldDataString(hStmt, &(p_data_tbl->preview_text), 1, PREVIEW_TEXT_IDX_IN_MAIL_TBL);
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl->meeting_request_status), MEETING_REQUEST_STATUS_IDX_IN_MAIL_TBL);
+
+ if (type == RETRIEVE_ALL) {
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl->server_mail_status), SERVER_MAIL_STATUS_IDX_IN_MAIL_TBL);
+ _getStmtFieldDataString(hStmt, &(p_data_tbl->server_mailbox_name), 0, SERVER_MAILBOX_NAME_IDX_IN_MAIL_TBL);
+ _getStmtFieldDataString(hStmt, &(p_data_tbl->full_address_reply), 1, FULL_ADDRESS_REPLY_IDX_IN_MAIL_TBL);
+ _getStmtFieldDataString(hStmt, &(p_data_tbl->full_address_cc), 1, FULL_ADDRESS_CC_IDX_IN_MAIL_TBL);
+ _getStmtFieldDataString(hStmt, &(p_data_tbl->full_address_bcc), 1, FULL_ADDRESS_BCC_IDX_IN_MAIL_TBL);
+ _getStmtFieldDataString(hStmt, &(p_data_tbl->full_address_return), 1, FULL_ADDRESS_RETURN_IDX_IN_MAIL_TBL);
+ _getStmtFieldDataString(hStmt, &(p_data_tbl->message_id), 0, MESSAGE_ID_IDX_IN_MAIL_TBL);
+ _getStmtFieldDataString(hStmt, &(p_data_tbl->email_address_sender), 1, EMAIL_ADDRESS_SENDER_IDX_IN_MAIL_TBL);
+ _getStmtFieldDataString(hStmt, &(p_data_tbl->email_address_recipient), 1, EMAIL_ADDRESS_RECIPIENT_IDX_IN_MAIL_TBL);
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl->attachment_count), ATTACHMENT_COUNT_IDX_IN_MAIL_TBL);
+ _getStmtFieldDataString(hStmt, &(p_data_tbl->preview_text), 1, PREVIEW_TEXT_IDX_IN_MAIL_TBL);
+
+ }
+
+ if (p_data_tbl->body_download_status) {
+ struct stat buf;
+
+ if (p_data_tbl->file_path_html) {
+ if (stat(p_data_tbl->file_path_html, &buf) == -1)
+ p_data_tbl->body_download_status = 0;
+ }
+ else if (p_data_tbl->file_path_plain) {
+ if (stat(p_data_tbl->file_path_plain, &buf) == -1)
+ p_data_tbl->body_download_status = 0;
+ }
+ else
+ p_data_tbl->body_download_status = 0;
+ }
+
+ *((emf_mail_tbl_t**)data) = p_data_tbl;
+ break;
+
+ case RETRIEVE_SUMMARY:
+ if (!(p_data_tbl = malloc(sizeof(emf_mail_tbl_t)))) {
+ EM_DEBUG_EXCEPTION(" malloc failed...");
+
+ error = EM_STORAGE_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ memset(p_data_tbl, 0x00, sizeof(emf_mail_tbl_t));
+
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl->mail_id), MAIL_ID_IDX_IN_MAIL_TBL);
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl->account_id), ACCOUNT_ID_IDX_IN_MAIL_TBL);
+ _getStmtFieldDataString(hStmt, &(p_data_tbl->mailbox_name), 0, MAILBOX_NAME_IDX_IN_MAIL_TBL);
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl->server_mail_status), SERVER_MAIL_STATUS_IDX_IN_MAIL_TBL);
+ _getStmtFieldDataString(hStmt, &(p_data_tbl->server_mailbox_name), 0, SERVER_MAILBOX_NAME_IDX_IN_MAIL_TBL);
+ _getStmtFieldDataString(hStmt, &(p_data_tbl->server_mail_id), 0, SERVER_MAIL_ID_IDX_IN_MAIL_TBL);
+
+ *((emf_mail_tbl_t**)data) = p_data_tbl;
+ break;
+
+ case RETRIEVE_ADDRESS:
+ if (!(p_data_tbl = malloc(sizeof(emf_mail_tbl_t)))) {
+ EM_DEBUG_EXCEPTION(" malloc failed...");
+ error = EM_STORAGE_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ memset(p_data_tbl, 0x00, sizeof(emf_mail_tbl_t));
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl->mail_id), MAIL_ID_IDX_IN_MAIL_TBL);
+ _getStmtFieldDataString(hStmt, &(p_data_tbl->email_address_sender), 1, EMAIL_ADDRESS_SENDER_IDX_IN_MAIL_TBL);
+ _getStmtFieldDataString(hStmt, &(p_data_tbl->email_address_recipient), 1, EMAIL_ADDRESS_RECIPIENT_IDX_IN_MAIL_TBL);
+ *((emf_mail_tbl_t**)data) = p_data_tbl;
+ break;
+
+ default:
+ break;
+ }
+
+ /* rc = sqlite3_step(hStmt); */
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
+ EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("sqlite3_step fail:%d", rc));
+
+ ret = true;
+
+FINISH_OFF:
+
+ if (err_code != NULL)
+ *err_code = error;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+EXPORT_API int em_storage_mail_search_end(int search_handle, int transaction, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("search_handle[%d], transaction[%d], err_code[%p]", search_handle, transaction, err_code);
+
+ int error = EM_STORAGE_ERROR_NONE;
+ int rc, ret = false;
+
+ if (search_handle < 0) {
+ EM_DEBUG_EXCEPTION(" search_handle[%d]", search_handle);
+ error = EM_STORAGE_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ DB_STMT hStmt = (DB_STMT)search_handle;
+
+ EM_DEBUG_LOG(" Before sqlite3_finalize hStmt = %p", hStmt);
+
+ rc = sqlite3_finalize(hStmt);
+ if (rc != SQLITE_OK) {
+ EM_DEBUG_EXCEPTION(" sqlite3_finalize failed - %d", rc);
+ error = EM_STORAGE_ERROR_DB_FAILURE;
+ }
+
+ ret = true;
+
+FINISH_OFF:
+ EM_STORAGE_FINISH_READ_TRANSACTION(transaction);
+ _DISCONNECT_DB;
+
+ if (err_code != NULL)
+ *err_code = error;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+EXPORT_API int em_storage_change_mail(int mail_id, emf_mail_tbl_t* mail, int transaction, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("mail_id[%d], mail[%p], transaction[%d], err_code[%p]", mail_id, mail, transaction, err_code);
+
+ if (mail_id <= 0 || !mail) {
+ EM_DEBUG_EXCEPTION(" mail_id[%d], mail[%p]", mail_id, mail);
+
+ if (err_code != NULL)
+ *err_code = EM_STORAGE_ERROR_INVALID_PARAM;
+ return false;
+ }
+
+ DB_STMT hStmt = NULL;
+ char sql_query_string[QUERY_SIZE] = {0, };
+ int rc = -1;
+ int ret = false;
+ int error = EM_STORAGE_ERROR_NONE;
+
+ sqlite3 *local_db_handle = em_storage_get_db_connection();
+
+ EM_STORAGE_START_WRITE_TRANSACTION(transaction, error);
+
+ SNPRINTF(sql_query_string, sizeof(sql_query_string),
+ "UPDATE mail_tbl SET"
+ " mail_id = ?"
+ ", account_id = ?"
+ ", mailbox_name = ?"
+ ", mail_size = ?"
+ ", server_mail_status = ?"
+ ", server_mailbox_name = ?"
+ ", server_mail_id = ?"
+ ", full_address_from = ?"
+ ", full_address_reply = ?" /* 10 */
+ ", full_address_to = ?"
+ ", full_address_cc = ?"
+ ", full_address_bcc = ?"
+ ", full_address_return = ?"
+ ", subject = ?"
+ ", body_download_status = ?"
+ ", file_path_plain = ?"
+ ", file_path_html = ?"
+ ", date_time = ?"
+ ", flags_seen_field = ?"
+ ", flags_deleted_field = ?"
+ ", flags_flagged_field = ?"
+ ", flags_answered_field = ?"
+ ", flags_recent_field = ?"
+ ", flags_draft_field = ?"
+ ", flags_forwarded_field = ?"
+ ", DRM_status = ?"
+ ", priority = ?"
+ ", save_status = ?"
+ ", lock_status = ?"
+ ", message_id = ?"
+ ", report_status = ?"
+ ", preview_text = ?"
+ " WHERE mail_id = %d AND account_id != 0 "
+ , mail_id);
+
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+
+ int i = 0;
+
+ _bindStmtFieldDataInt(hStmt, i++, mail->mail_id);
+ _bindStmtFieldDataInt(hStmt, i++, mail->account_id);
+ _bindStmtFieldDataString(hStmt, i++, (char *)mail->mailbox_name, 0, MAILBOX_LEN_IN_MAIL_TBL);
+ _bindStmtFieldDataInt(hStmt, i++, mail->mail_size);
+ _bindStmtFieldDataInt(hStmt, i++, mail->server_mail_status);
+ _bindStmtFieldDataString(hStmt, i++, (char *)mail->server_mailbox_name, 0, SERVER_MAILBOX_LEN_IN_MAIL_TBL);
+ _bindStmtFieldDataString(hStmt, i++, (char *)mail->server_mail_id, 0, SERVER_MAIL_ID_LEN_IN_MAIL_TBL);
+ _bindStmtFieldDataString(hStmt, i++, (char *)mail->full_address_from, 1, FROM_LEN_IN_MAIL_TBL);
+ _bindStmtFieldDataString(hStmt, i++, (char *)mail->full_address_reply, 1, REPLY_TO_LEN_IN_MAIL_TBL);
+ _bindStmtFieldDataString(hStmt, i++, (char *)mail->full_address_to, 1, TO_LEN_IN_MAIL_TBL);
+ _bindStmtFieldDataString(hStmt, i++, (char *)mail->full_address_cc, 1, CC_LEN_IN_MAIL_TBL);
+ _bindStmtFieldDataString(hStmt, i++, (char *)mail->full_address_bcc, 1, BCC_LEN_IN_MAIL_TBL);
+ _bindStmtFieldDataString(hStmt, i++, (char *)mail->full_address_return, 1, RETURN_PATH_LEN_IN_MAIL_TBL);
+ _bindStmtFieldDataString(hStmt, i++, (char *)mail->subject, 1, SUBJECT_LEN_IN_MAIL_TBL);
+ _bindStmtFieldDataInt(hStmt, i++, mail->body_download_status);
+ _bindStmtFieldDataString(hStmt, i++, (char *)mail->file_path_plain, 0, TEXT_1_LEN_IN_MAIL_TBL);
+ _bindStmtFieldDataString(hStmt, i++, (char *)mail->file_path_html, 0, TEXT_2_LEN_IN_MAIL_TBL);
+ _bindStmtFieldDataString(hStmt, i++, (char *)mail->datetime, 0, DATETIME_LEN_IN_MAIL_TBL);
+ _bindStmtFieldDataChar(hStmt, i++, mail->flags_seen_field);
+ _bindStmtFieldDataChar(hStmt, i++, mail->flags_deleted_field);
+ _bindStmtFieldDataChar(hStmt, i++, mail->flags_flagged_field);
+ _bindStmtFieldDataChar(hStmt, i++, mail->flags_answered_field);
+ _bindStmtFieldDataChar(hStmt, i++, mail->flags_recent_field);
+ _bindStmtFieldDataChar(hStmt, i++, mail->flags_draft_field);
+ _bindStmtFieldDataChar(hStmt, i++, mail->flags_forwarded_field);
+ _bindStmtFieldDataInt(hStmt, i++, mail->DRM_status);
+ _bindStmtFieldDataInt(hStmt, i++, mail->priority);
+ _bindStmtFieldDataInt(hStmt, i++, mail->save_status);
+ _bindStmtFieldDataInt(hStmt, i++, mail->lock_status);
+ _bindStmtFieldDataString(hStmt, i++, (char *)mail->message_id, 0, MESSAGE_ID_LEN_IN_MAIL_TBL);
+ _bindStmtFieldDataInt(hStmt, i++, mail->report_status);
+ _bindStmtFieldDataString(hStmt, i++, (char *)mail->preview_text, 1, PREVIEWBODY_LEN_IN_MAIL_TBL);
+ /* rc = sqlite3_step(hStmt); */
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
+ EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("sqlite3_step fail:%d", rc));
+
+ rc = sqlite3_changes(local_db_handle);
+ if (rc == 0) {
+ EM_DEBUG_EXCEPTION(" no matched mail found...");
+ error = EM_STORAGE_ERROR_MAIL_NOT_FOUND;
+ goto FINISH_OFF;
+ }
+
+ if (!em_storage_notify_storage_event(NOTI_MAIL_UPDATE, mail->account_id, mail->mail_id, mail->mailbox_name, 0))
+ EM_DEBUG_EXCEPTION(" em_storage_notify_storage_event Failed [ NOTI_MAIL_UPDATE ] >>>> ");
+
+ ret = true;
+
+FINISH_OFF:
+ if (hStmt != NULL) {
+ EM_DEBUG_LOG("Before sqlite3_finalize hStmt = %p", hStmt);
+ rc = sqlite3_finalize(hStmt);
+ if (rc != SQLITE_OK) {
+ EM_DEBUG_EXCEPTION("sqlite3_finalize failed - %d", rc);
+ error = EM_STORAGE_ERROR_DB_FAILURE;
+ }
+ }
+
+ EM_STORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
+ _DISCONNECT_DB;
+
+ if (err_code != NULL)
+ *err_code = error;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+EXPORT_API int em_storage_modify_mailbox_of_mails(char *old_mailbox_name, char *new_mailbox_name, int transaction, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("old_mailbox_name[%p], new_mailbox_name[%p], transaction[%d], err_code[%p]", old_mailbox_name, new_mailbox_name, transaction, err_code);
+
+ if (!old_mailbox_name && !new_mailbox_name) {
+ EM_DEBUG_EXCEPTION(" old_mailbox_name[%p], new_mailbox_name[%p]", old_mailbox_name, new_mailbox_name);
+
+ if (err_code != NULL)
+ *err_code = EM_STORAGE_ERROR_INVALID_PARAM;
+ return false;
+ }
+
+ int rc = -1;
+ int ret = false;
+ int error = EM_STORAGE_ERROR_NONE;
+ char sql_query_string[QUERY_SIZE] = {0, };
+
+ sqlite3 *local_db_handle = em_storage_get_db_connection();
+
+ EM_STORAGE_START_WRITE_TRANSACTION(transaction, error);
+
+ EM_DEBUG_LOG("Old Mailbox Name [ %s ] , New Mailbox name [ %s ] ", old_mailbox_name, new_mailbox_name);
+
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), "UPDATE mail_tbl SET mailbox_name = '%s' WHERE mailbox_name = '%s'", new_mailbox_name, old_mailbox_name);
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ rc = sqlite3_changes(local_db_handle);
+ if (rc == 0) {
+ EM_DEBUG_EXCEPTION(" no matched mail found...");
+
+ error = EM_STORAGE_ERROR_MAIL_NOT_FOUND;
+ goto FINISH_OFF;
+ }
+
+ EM_DEBUG_LOG(" Modification done in mail_read_mail_uid_tbl based on Mailbox name ");
+ /* Modify the mailbox_name name in mail_read_mail_uid_tbl table */
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), "UPDATE mail_read_mail_uid_tbl SET mailbox_name = '%s' WHERE mailbox_name = '%s'", new_mailbox_name, old_mailbox_name);
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ rc = sqlite3_changes(local_db_handle);
+ if (rc == 0) {
+ EM_DEBUG_EXCEPTION(" no matched mail found...");
+ error = EM_STORAGE_ERROR_MAIL_NOT_FOUND;
+ goto FINISH_OFF;
+ }
+
+ if (!em_storage_notify_storage_event(NOTI_MAILBOX_UPDATE, 1, 0, new_mailbox_name, 0))
+ EM_DEBUG_EXCEPTION(" em_storage_notify_storage_event[ NOTI_MAILBOX_UPDATE] : Notification Failed >>> ");
+
+ ret = true;
+
+FINISH_OFF:
+
+ EM_STORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
+ _DISCONNECT_DB;
+
+ if (err_code != NULL)
+ *err_code = error;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+/**
+ * em_storage_clean_save_status(int save_status, int *err_code) - set the all mail status to the set value
+ *
+ *
+ **/
+EXPORT_API int em_storage_clean_save_status(int save_status, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("save_status[%d], err_code[%p]", save_status, err_code);
+
+ EM_IF_NULL_RETURN_VALUE(err_code, false);
+
+ int ret = false;
+ int error = EM_STORAGE_ERROR_NONE;
+ int rc = 0;
+ char sql_query_string[QUERY_SIZE] = {0, };
+ sqlite3 *local_db_handle = em_storage_get_db_connection();
+
+ memset(sql_query_string, 0x00, sizeof(sql_query_string));
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), "UPDATE mail_tbl SET save_status = %d WHERE save_status = %d", save_status, EMF_MAIL_STATUS_SENDING);
+ EM_DEBUG_LOG("Query [%s]", sql_query_string);
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ rc = sqlite3_changes(local_db_handle);
+ if (rc == 0) {
+ EM_DEBUG_LOG(" No Matched Mail Exists ");
+ error = EM_STORAGE_ERROR_MAIL_NOT_FOUND;
+ }
+
+ ret = true;
+
+FINISH_OFF:
+
+ if (err_code != NULL)
+ *err_code = error;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+EXPORT_API int em_storage_set_field_of_mails_with_integer_value(int account_id, int mail_ids[], int mail_ids_count, char *field_name, int value, int transaction, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("account_id [%d], mail_ids[%p], mail_ids_count[%d], field_name[%s], value[%d], transaction[%d], err_code[%p]", account_id, mail_ids, mail_ids_count, field_name, value, transaction, err_code);
+ int i, error, rc, ret = false, cur_mail_id_string = 0, mail_id_string_buffer_length = 0;
+ char sql_query_string[QUERY_SIZE] = {0, }, *mail_id_string_buffer = NULL, *parameter_string = NULL;
+ sqlite3 *local_db_handle = em_storage_get_db_connection();
+
+ if (!mail_ids || !field_name || account_id == 0) {
+ EM_DEBUG_EXCEPTION("EM_STORAGE_ERROR_INVALID_PARAM");
+ if (err_code != NULL)
+ *err_code = EM_STORAGE_ERROR_INVALID_PARAM;
+ return false;
+ }
+
+ /* Generating mail id list string */
+ mail_id_string_buffer_length = MAIL_ID_STRING_LENGTH * mail_ids_count;
+
+ mail_id_string_buffer = em_core_malloc(mail_id_string_buffer_length);
+
+ if(!mail_id_string_buffer) {
+ EM_DEBUG_EXCEPTION("em_core_malloc failed");
+ error = EM_STORAGE_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ for(i = 0; i < mail_ids_count; i++)
+ cur_mail_id_string += SNPRINTF_OFFSET(mail_id_string_buffer, cur_mail_id_string, mail_id_string_buffer_length, "%d,", mail_ids[i]);
+
+ if(strlen(mail_id_string_buffer) > 1)
+ mail_id_string_buffer[strlen(mail_id_string_buffer) - 1] = NULL_CHAR;
+
+ /* Generating notification parameter string */
+ parameter_string = em_core_malloc(mail_id_string_buffer_length + strlen(field_name) + 2);
+
+ if(!parameter_string) {
+ EM_DEBUG_EXCEPTION("em_core_malloc failed");
+ error = EM_STORAGE_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ SNPRINTF(parameter_string, QUERY_SIZE, "%s%c%s", field_name, 0x01, mail_id_string_buffer);
+
+ /* Write query string */
+ SNPRINTF(sql_query_string, QUERY_SIZE, "UPDATE mail_tbl SET %s = %d WHERE mail_id in (%s) AND account_id = %d", field_name, value, mail_id_string_buffer, account_id);
+
+ /* Execute query */
+ EM_STORAGE_START_WRITE_TRANSACTION(transaction, error);
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+ if (sqlite3_changes(local_db_handle) == 0)
+ EM_DEBUG_LOG("no mail matched...");
+
+ ret = true;
+
+FINISH_OFF:
+ EM_STORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
+ _DISCONNECT_DB;
+
+ if (ret && parameter_string && !em_storage_notify_storage_event(NOTI_MAIL_FIELD_UPDATE, account_id, 0, parameter_string, value))
+ EM_DEBUG_EXCEPTION("em_storage_notify_storage_event failed : NOTI_MAIL_FIELD_UPDATE [%s,%d]", field_name, value);
+
+ EM_SAFE_FREE(mail_id_string_buffer);
+ EM_SAFE_FREE(parameter_string);
+
+ if (err_code != NULL)
+ *err_code = error;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+EXPORT_API int em_storage_change_mail_field(int mail_id, emf_mail_change_type_t type, emf_mail_tbl_t* mail, int transaction, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("mail_id[%d], type[%d], mail[%p], transaction[%d], err_code[%p]", mail_id, type, mail, transaction, err_code);
+
+ if (mail_id <= 0 || !mail) {
+ EM_DEBUG_EXCEPTION(" mail_id[%d], type[%d], mail[%p]", mail_id, type, mail);
+ if (err_code != NULL)
+ *err_code = EM_STORAGE_ERROR_INVALID_PARAM;
+ return false;
+ }
+
+ int ret = false;
+ int error = EM_STORAGE_ERROR_NONE;
+ int move_flag = 0;
+ DB_STMT hStmt = NULL;
+ char sql_query_string[QUERY_SIZE] = {0, };
+
+ int rc = 0;
+ int i = 0;
+
+ char *mailbox_name = NULL;
+
+ sqlite3 *local_db_handle = em_storage_get_db_connection();
+ EM_STORAGE_START_WRITE_TRANSACTION(transaction, error);
+
+ switch (type) {
+ case APPEND_BODY:
+ SNPRINTF(sql_query_string, sizeof(sql_query_string),
+ "UPDATE mail_tbl SET"
+ " body_download_status = ?"
+ ", file_path_plain = ?"
+ ", file_path_html = ?"
+ ", flags_seen_field = ?"
+ ", flags_deleted_field = ?"
+ ", flags_flagged_field = ?"
+ ", flags_answered_field = ?"
+ ", flags_recent_field = ?"
+ ", flags_draft_field = ?"
+ ", flags_forwarded_field = ?"
+ ", DRM_status = ?"
+ ", attachment_count = ?"
+ ", preview_text= ?"
+ ", meeting_request_status = ? "
+ " WHERE mail_id = %d AND account_id != 0"
+ , mail_id);
+
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+ i = 0;
+
+ _bindStmtFieldDataInt(hStmt, i++, mail->body_download_status);
+ _bindStmtFieldDataString(hStmt, i++, (char *)mail->file_path_plain, 0, TEXT_1_LEN_IN_MAIL_TBL);
+ _bindStmtFieldDataString(hStmt, i++, (char *)mail->file_path_html, 0, TEXT_2_LEN_IN_MAIL_TBL);
+ _bindStmtFieldDataInt(hStmt, i++, mail->flags_seen_field);
+ _bindStmtFieldDataInt(hStmt, i++, mail->flags_deleted_field);
+ _bindStmtFieldDataInt(hStmt, i++, mail->flags_deleted_field);
+ _bindStmtFieldDataInt(hStmt, i++, mail->flags_flagged_field);
+ _bindStmtFieldDataInt(hStmt, i++, mail->flags_answered_field);
+ _bindStmtFieldDataInt(hStmt, i++, mail->flags_recent_field);
+ _bindStmtFieldDataInt(hStmt, i++, mail->flags_draft_field);
+ _bindStmtFieldDataInt(hStmt, i++, mail->flags_forwarded_field);
+ _bindStmtFieldDataInt(hStmt, i++, mail->DRM_status);
+ _bindStmtFieldDataInt(hStmt, i++, mail->attachment_count);
+ _bindStmtFieldDataString(hStmt, i++, (char *)mail->preview_text, 0, PREVIEWBODY_LEN_IN_MAIL_TBL);
+ _bindStmtFieldDataInt(hStmt, i++, mail->meeting_request_status);
+ break;
+
+ case UPDATE_MAILBOX: {
+ int err;
+ emf_mailbox_tbl_t *mailbox_name;
+
+ if (!em_storage_get_mailbox_by_name(mail->account_id, -1, mail->mailbox_name, &mailbox_name, false, &err)) {
+ EM_DEBUG_EXCEPTION(" em_storage_get_mailbox_by_name failed - %d", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+
+ SNPRINTF(sql_query_string, sizeof(sql_query_string),
+ "UPDATE mail_tbl SET"
+ " mailbox_name = '%s'"
+ ",mailbox_type = '%d'"
+ " WHERE mail_id = %d AND account_id != 0"
+ , mail->mailbox_name ? mail->mailbox_name : ""
+ , mailbox_name->mailbox_type
+ , mail_id);
+ move_flag = 1;
+
+
+ EM_DEBUG_LOG("Query [%s]", sql_query_string);
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+ }
+ break;
+
+ case UPDATE_FLAG:
+ SNPRINTF(sql_query_string, sizeof(sql_query_string),
+ "UPDATE mail_tbl SET"
+ " flags_seen_field = %d"
+ ",flags_deleted_field = %d"
+ ",flags_flagged_field = %d"
+ ",flags_answered_field = %d"
+ ",flags_recent_field = %d"
+ ",flags_draft_field = %d"
+ ",flags_forwarded_field = %d"
+ " WHERE mail_id = %d AND account_id != 0"
+ , mail->flags_seen_field
+ , mail->flags_deleted_field
+ , mail->flags_flagged_field
+ , mail->flags_answered_field
+ , mail->flags_recent_field
+ , mail->flags_draft_field
+ , mail->flags_forwarded_field
+ , mail_id);
+ EM_DEBUG_LOG("Query [%s]", sql_query_string);
+
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ break;
+
+ case UPDATE_EXTRA_FLAG:
+ SNPRINTF(sql_query_string, sizeof(sql_query_string),
+ "UPDATE mail_tbl SET"
+ " priority = %d"
+ ", save_status = %d"
+ ", lock_status = %d"
+ ", report_status = %d"
+ ", DRM_status = %d"
+ " WHERE mail_id = %d AND account_id != 0"
+ , mail->priority
+ , mail->save_status
+ , mail->lock_status
+ , mail->report_status
+ , mail->DRM_status
+ , mail_id);
+ EM_DEBUG_LOG("Query [%s]", sql_query_string);
+
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+ break;
+
+ case UPDATE_STICKY_EXTRA_FLAG:
+ SNPRINTF(sql_query_string, sizeof(sql_query_string),
+ "UPDATE mail_tbl SET"
+ " lock_status = %d"
+ " WHERE mail_id = %d AND account_id != 0"
+ , mail->lock_status
+ , mail_id);
+ EM_DEBUG_LOG("Query [%s]", sql_query_string);
+
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+ break;
+
+ case UPDATE_MAIL:
+ SNPRINTF(sql_query_string, sizeof(sql_query_string),
+ "UPDATE mail_tbl SET"
+ " full_address_from = ?"
+ ", full_address_reply = ?"
+ ", full_address_to = ?"
+ ", full_address_cc = ?"
+ ", full_address_bcc = ?"
+ ", full_address_return = ?"
+ ", subject = ?"
+ ", file_path_plain = ?"
+ ", date_time = ?"
+ ", flags_seen_field = ?"
+ ", flags_deleted_field = ?"
+ ", flags_flagged_field = ?"
+ ", flags_answered_field = ?"
+ ", flags_recent_field = ?"
+ ", flags_draft_field = ?"
+ ", flags_forwarded_field = ?"
+ ", priority = ?"
+ ", save_status = ?"
+ ", lock_status = ?"
+ ", report_status = ?"
+ ", DRM_status = ?"
+ ", file_path_html = ?"
+ ", mail_size = ?"
+ ", preview_text = ?"
+ ", body_download_status = ?"
+ ", attachment_count = ?"
+ ", inline_content_count = ?"
+ ", meeting_request_status = ?"
+ " WHERE mail_id = %d AND account_id != 0"
+ , mail_id);
+
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
+ EM_DEBUG_LOG(" before sqlite3_prepare hStmt = %p", hStmt);
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+ i = 0;
+ _bindStmtFieldDataString(hStmt, i++, (char *)mail->full_address_from, 1, FROM_LEN_IN_MAIL_TBL);
+ _bindStmtFieldDataString(hStmt, i++, (char *)mail->full_address_reply, 1, REPLY_TO_LEN_IN_MAIL_TBL);
+ _bindStmtFieldDataString(hStmt, i++, (char *)mail->full_address_to, 1, TO_LEN_IN_MAIL_TBL);
+ _bindStmtFieldDataString(hStmt, i++, (char *)mail->full_address_cc, 1, CC_LEN_IN_MAIL_TBL);
+ _bindStmtFieldDataString(hStmt, i++, (char *)mail->full_address_bcc, 1, BCC_LEN_IN_MAIL_TBL);
+ _bindStmtFieldDataString(hStmt, i++, (char *)mail->full_address_return, 1, RETURN_PATH_LEN_IN_MAIL_TBL);
+ _bindStmtFieldDataString(hStmt, i++, (char *)mail->subject, 1, SUBJECT_LEN_IN_MAIL_TBL);
+ _bindStmtFieldDataString(hStmt, i++, (char *)mail->file_path_plain, 0, TEXT_1_LEN_IN_MAIL_TBL);
+ _bindStmtFieldDataString(hStmt, i++, (char *)mail->datetime, 0, DATETIME_LEN_IN_MAIL_TBL);
+ _bindStmtFieldDataChar(hStmt, i++, mail->flags_seen_field);
+ _bindStmtFieldDataChar(hStmt, i++, mail->flags_deleted_field);
+ _bindStmtFieldDataChar(hStmt, i++, mail->flags_flagged_field);
+ _bindStmtFieldDataChar(hStmt, i++, mail->flags_answered_field);
+ _bindStmtFieldDataChar(hStmt, i++, mail->flags_recent_field);
+ _bindStmtFieldDataChar(hStmt, i++, mail->flags_draft_field);
+ _bindStmtFieldDataChar(hStmt, i++, mail->flags_forwarded_field);
+ _bindStmtFieldDataInt(hStmt, i++, mail->priority);
+ _bindStmtFieldDataInt(hStmt, i++, mail->save_status);
+ _bindStmtFieldDataInt(hStmt, i++, mail->lock_status);
+ _bindStmtFieldDataInt(hStmt, i++, mail->report_status);
+ _bindStmtFieldDataInt(hStmt, i++, mail->DRM_status);
+ _bindStmtFieldDataString(hStmt, i++, (char *)mail->file_path_html, 0, TEXT_2_LEN_IN_MAIL_TBL);
+ _bindStmtFieldDataInt(hStmt, i++, mail->mail_size);
+ _bindStmtFieldDataString(hStmt, i++, (char *)mail->preview_text, 1, PREVIEWBODY_LEN_IN_MAIL_TBL);
+ _bindStmtFieldDataInt(hStmt, i++, mail->body_download_status);
+ _bindStmtFieldDataInt(hStmt, i++, mail->attachment_count);
+ _bindStmtFieldDataInt(hStmt, i++, mail->inline_content_count);
+ _bindStmtFieldDataInt(hStmt, i++, mail->meeting_request_status);
+ break;
+
+ case UPDATE_DATETIME: {
+ static char buf[16];
+ time_t t = time(NULL);
+
+ struct tm *p_tm = localtime(&t);
+ if (!p_tm) {
+ EM_DEBUG_EXCEPTION(" localtime failed...");
+ error = EM_STORAGE_ERROR_SYSTEM_FAILURE;
+ goto FINISH_OFF;
+ }
+
+ SNPRINTF(buf, sizeof(buf),
+ "%04d%02d%02d%02d%02d%02d",
+ p_tm->tm_year + 1900,
+ p_tm->tm_mon + 1,
+ p_tm->tm_mday,
+ p_tm->tm_hour,
+ p_tm->tm_min,
+ p_tm->tm_sec);
+
+ SNPRINTF(sql_query_string, sizeof(sql_query_string),
+ "UPDATE mail_tbl SET"
+ " date_time = '%s'"
+ " WHERE mail_id = %d AND account_id != 0"
+ , buf
+ , mail_id);
+
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+ break;
+ }
+
+ case UPDATE_FROM_CONTACT_INFO:
+ EM_DEBUG_LOG("NVARCHAR : em_storage_change_mail_field - mail change type is UPDATE_FROM_CONTACT_INFO");
+ SNPRINTF(sql_query_string, sizeof(sql_query_string),
+ "UPDATE mail_tbl SET"
+ " email_address_sender = ?,"
+ " WHERE mail_id = %d",
+ mail_id);
+
+ hStmt = NULL;
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+ i = 0;
+ _bindStmtFieldDataString(hStmt, i++, (char *)mail->email_address_sender, 1, FROM_EMAIL_ADDRESS_LEN_IN_MAIL_TBL);
+ break;
+
+ case UPDATE_TO_CONTACT_INFO:
+ EM_DEBUG_LOG("NVARCHAR : em_storage_change_mail_field - mail change type is UPDATE_TO_CONTACT_INFO");
+ SNPRINTF(sql_query_string, sizeof(sql_query_string),
+ "UPDATE mail_tbl SET"
+ " email_address_recipient = ?,"
+ " WHERE mail_id = %d",
+ mail_id);
+
+ hStmt = NULL;
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+ i = 0;
+ _bindStmtFieldDataString(hStmt, i++, (char *)mail->email_address_recipient, 1, TO_EMAIL_ADDRESS_LEN_IN_MAIL_TBL);
+ break;
+
+ case UPDATE_ALL_CONTACT_INFO:
+ EM_DEBUG_LOG("em_storage_change_mail_field - mail change type is UPDATE_ALL_CONTACT_INFO");
+ SNPRINTF(sql_query_string, sizeof(sql_query_string),
+ "UPDATE mail_tbl SET"
+ " email_address_sender = ?,"
+ " email_address_recipient = ?,"
+ " WHERE mail_id = %d",
+ mail_id);
+
+ hStmt = NULL;
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+ i = 0;
+ _bindStmtFieldDataString(hStmt, i++, (char *)mail->email_address_sender, 1, FROM_EMAIL_ADDRESS_LEN_IN_MAIL_TBL);
+ _bindStmtFieldDataString(hStmt, i++, (char *)mail->email_address_recipient, 1, TO_EMAIL_ADDRESS_LEN_IN_MAIL_TBL);
+ break;
+
+
+#ifdef __FEATURE_PARTIAL_BODY_DOWNLOAD__
+ case UPDATE_PARTIAL_BODY_DOWNLOAD:
+
+ SNPRINTF(sql_query_string, sizeof(sql_query_string),
+ "UPDATE mail_tbl SET"
+ " body_download_status = ?"
+ ", file_path_plain = ?"
+ ", file_path_html = ?"
+ ", attachment_count = ?"
+ ", inline_content_count = ?"
+ ", preview_text= ?"
+ " WHERE mail_id = %d"
+ , mail_id);
+
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+ i = 0;
+
+ _bindStmtFieldDataInt(hStmt, i++, mail->body_download_status);
+ _bindStmtFieldDataString(hStmt, i++, (char *)mail->file_path_plain, 0, TEXT_1_LEN_IN_MAIL_TBL);
+ _bindStmtFieldDataString(hStmt, i++, (char *)mail->file_path_html, 0, TEXT_2_LEN_IN_MAIL_TBL);
+ _bindStmtFieldDataInt(hStmt, i++, mail->attachment_count);
+ _bindStmtFieldDataInt(hStmt, i++, mail->inline_content_count);
+ _bindStmtFieldDataString(hStmt, i++, (char *)mail->preview_text, 0, PREVIEWBODY_LEN_IN_MAIL_TBL);
+
+ break;
+
+#endif
+
+ default:
+ EM_DEBUG_LOG(" type[%d]", type);
+
+ error = EM_STORAGE_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ if (hStmt != NULL) {
+ /* rc = sqlite3_step(hStmt); */
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
+ EM_DEBUG_DB_EXEC((rc == SQLITE_FULL), {error = EM_STORAGE_ERROR_DB_IS_FULL;goto FINISH_OFF; },
+ ("sqlite3_step fail:%d", rc));
+ EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("sqlite3_step fail:%d", rc));
+ rc = sqlite3_changes(local_db_handle);
+ if (rc == 0) {
+ EM_DEBUG_EXCEPTION(" no matched mail found...");
+
+ error = EM_STORAGE_ERROR_MAIL_NOT_FOUND;
+ goto FINISH_OFF;
+ }
+ }
+
+ if (mail->account_id == 0) {
+ emf_mail_tbl_t* mail_for_account = NULL;
+ if (!em_storage_get_mail_field_by_id(mail_id, RETRIEVE_ACCOUNT, &mail_for_account, true, &error) || !mail_for_account) {
+ EM_DEBUG_EXCEPTION(" em_storage_get_mail_field_by_id failed - %d", error);
+/* error = em_storage_get_emf_error_from_em_storage_error(error); */
+ goto FINISH_OFF;
+ }
+ mail->account_id = mail_for_account->account_id;
+ if (mail_for_account)
+ em_storage_free_mail(&mail_for_account, 1, NULL);
+ }
+
+ ret = true;
+
+FINISH_OFF:
+
+ if (hStmt != NULL) {
+ rc = sqlite3_finalize(hStmt);
+ if (rc != SQLITE_OK) {
+ EM_DEBUG_LOG(" sqlite3_finalize failed - %d", rc);
+ error = EM_STORAGE_ERROR_DB_FAILURE;
+ }
+ hStmt = NULL;
+ }
+
+ EM_STORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
+ _DISCONNECT_DB;
+
+ /*h.gahlaut@samsung.com: Moving publication of notification after commiting transaction to DB */
+
+ if (ret == true && move_flag != 1) {
+ if (!em_storage_get_mailboxname_by_mailbox_type(mail->account_id, EMF_MAILBOX_TYPE_SENTBOX, &mailbox_name, false, &error))
+ EM_DEBUG_EXCEPTION(" em_storage_get_mailboxname_by_mailbox_type failed - %d", error);
+
+#ifdef __FEATURE_PROGRESS_IN_OUTBOX__
+
+ if (mail->mailbox_name && mailbox_name) {
+ if (strcmp(mail->mailbox_name, mailbox_name) != 0) {
+ if (!em_storage_notify_storage_event(NOTI_MAIL_UPDATE, mail->account_id, mail_id, mail->mailbox_name, type))
+ EM_DEBUG_EXCEPTION(" em_storage_notify_storage_event Failed [ NOTI_MAIL_UPDATE ] >>>> ");
+ }
+ }
+ else {
+ /* h.gahlaut@samsung.com: Jan 10, 2011 Publishing noti to refresh outbox when email sending status changes */
+ if (!em_storage_notify_storage_event(NOTI_MAIL_UPDATE, mail->account_id, mail_id, NULL, type))
+ EM_DEBUG_EXCEPTION(" em_storage_notify_storage_event Failed [ NOTI_MAIL_UPDATE ] ");
+ }
+
+#else
+
+ if (mail->mailbox_name && strcmp(mail->mailbox_name, mailbox_name) != 0) {
+ if (!em_storage_notify_storage_event(NOTI_MAIL_UPDATE, mail->account_id, mail_id, mail->mailbox_name, type))
+ EM_DEBUG_EXCEPTION(" em_storage_notify_storage_event Failed [ NOTI_MAIL_UPDATE ] >>>> ");
+ }
+
+
+#endif
+
+ }
+
+ EM_SAFE_FREE(mailbox_name);
+
+ if (err_code != NULL)
+ *err_code = error;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+
+EXPORT_API int em_storage_get_mail_count_with_draft_flag(int account_id, const char *mailbox_name, int *total, int transaction, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("account_id[%d], mailbox_name[%s], total[%p], transaction[%d], err_code[%p]", account_id, mailbox_name, total, transaction, err_code);
+
+ if (!total) {
+ EM_DEBUG_EXCEPTION("accoun_id[%d], mailbox_name[%s], total[%p]", account_id, mailbox_name, total);
+ if (err_code != NULL)
+ *err_code = EM_STORAGE_ERROR_INVALID_PARAM;
+ return false;
+ }
+
+ int rc = -1, ret = false;
+ int error = EM_STORAGE_ERROR_NONE;
+ DB_STMT hStmt = NULL;
+ char sql_query_string[QUERY_SIZE] = {0, };
+
+ memset(&sql_query_string, 0x00, sizeof(sql_query_string));
+ sqlite3 *local_db_handle = em_storage_get_db_connection();
+ EM_STORAGE_START_READ_TRANSACTION(transaction);
+
+ if (total) {
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT COUNT(*) FROM mail_tbl WHERE flags_draft_field = 1");
+
+ if (account_id != ALL_ACCOUNT)
+ SNPRINTF(sql_query_string + strlen(sql_query_string), sizeof(sql_query_string)-(strlen(sql_query_string)+1), " AND account_id = %d", account_id);
+
+ if (mailbox_name)
+ SNPRINTF(sql_query_string + strlen(sql_query_string), sizeof(sql_query_string)-(strlen(sql_query_string)+1), " AND mailbox_name = '%s'", mailbox_name);
+
+#ifdef USE_GET_RECORD_COUNT_API
+ EM_DEBUG_LOG("Query : [%s]", sql_query_string);
+ char **result;
+ /* rc = sqlite3_get_table(local_db_handle, sql_query_string, &result, NULL, NULL, NULL); */
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, NULL, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EM_STORAGE_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+ ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ *total = atoi(result[1]);
+ sqlite3_free_table(result);
+#else
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ /* rc = sqlite3_step(hStmt); */
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
+ EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("sqlite3_step fail:%d", rc));
+
+ _getStmtFieldDataInt(hStmt, total, 0);
+#endif /* USE_GET_RECORD_COUNT_API */
+ }
+ ret = true;
+
+FINISH_OFF:
+#ifndef USE_GET_RECORD_COUNT_API
+ if (hStmt != NULL) {
+ rc = sqlite3_finalize(hStmt);
+ if (rc != SQLITE_OK) {
+ EM_DEBUG_LOG(" sqlite3_finalize failed - %d", rc);
+ error = EM_STORAGE_ERROR_DB_FAILURE;
+ }
+ }
+#endif
+
+ EM_STORAGE_FINISH_READ_TRANSACTION(transaction);
+ _DISCONNECT_DB;
+
+ if (err_code != NULL)
+ *err_code = error;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+EXPORT_API int em_storage_get_mail_count_on_sending(int account_id, const char *mailbox_name, int *total, int transaction, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("account_id[%d], mailbox_name[%s], total[%p], transaction[%d], err_code[%p]", account_id, mailbox_name, total, transaction, err_code);
+
+ if (!total) {
+ EM_DEBUG_EXCEPTION(" accoun_id[%d], mailbox_name[%s], total[%p]", account_id, mailbox_name, total);
+ if (err_code != NULL)
+ *err_code = EM_STORAGE_ERROR_INVALID_PARAM;
+ return false;
+ }
+
+ int rc = -1, ret = false;
+ int error = EM_STORAGE_ERROR_NONE;
+ DB_STMT hStmt = NULL;
+ char sql_query_string[QUERY_SIZE] = {0, };
+
+ memset(&sql_query_string, 0x00, sizeof(sql_query_string));
+ sqlite3 *local_db_handle = em_storage_get_db_connection();
+ EM_STORAGE_START_READ_TRANSACTION(transaction);
+
+ if (total) {
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT COUNT(*) FROM mail_tbl WHERE save_status = %d ", EMF_MAIL_STATUS_SENDING);
+
+ if (account_id != ALL_ACCOUNT)
+ SNPRINTF(sql_query_string + strlen(sql_query_string), sizeof(sql_query_string)-(strlen(sql_query_string)+1), " AND account_id = %d", account_id);
+
+ if (mailbox_name)
+ SNPRINTF(sql_query_string + strlen(sql_query_string), sizeof(sql_query_string)-(strlen(sql_query_string)+1), " AND mailbox_name = '%s'", mailbox_name);
+
+#ifdef USE_GET_RECORD_COUNT_API
+ char **result;
+ /* rc = sqlite3_get_table(local_db_handle, sql_query_string, &result, NULL, NULL, NULL); */
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, NULL, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EM_STORAGE_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+ ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ *total = atoi(result[1]);
+ sqlite3_free_table(result);
+#else
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ /* rc = sqlite3_step(hStmt); */
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
+ EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("sqlite3_step fail:%d", rc));
+
+ _getStmtFieldDataInt(hStmt, total, 0);
+#endif /* USE_GET_RECORD_COUNT_API */
+ }
+ ret = true;
+
+FINISH_OFF:
+#ifndef USE_GET_RECORD_COUNT_API
+ if (hStmt != NULL) {
+ rc = sqlite3_finalize(hStmt);
+ if (rc != SQLITE_OK) {
+ EM_DEBUG_LOG(" sqlite3_finalize failed - %d", rc);
+
+ error = EM_STORAGE_ERROR_DB_FAILURE;
+ }
+ }
+#endif
+
+ EM_STORAGE_FINISH_READ_TRANSACTION(transaction);
+ _DISCONNECT_DB;
+
+ if (err_code != NULL)
+ *err_code = error;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+
+}
+
+EXPORT_API int em_storage_increase_mail_id(int *mail_id, int transaction, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("mail_id[%p], transaction[%d], err_code[%p]", mail_id, transaction, err_code);
+
+ int rc, ret = false;
+ int error = EM_STORAGE_ERROR_NONE;
+ int latest_mail_id = 0;
+ sqlite3 *local_db_handle = NULL;
+ char *sql = "SELECT MAX(mail_id) FROM mail_tbl;";
+ char **result = NULL;
+
+#ifdef __FEATURE_USE_SHARED_MUTEX_FOR_GENERATING_MAIL_ID__
+ em_storage_shm_mutex_timedlock(&mapped_for_generating_mail_id, 2);
+#endif /* __FEATURE_USE_SHARED_MUTEX_FOR_GENERATING_MAIL_ID__ */
+
+ ret = vconf_get_int(VCONF_KEY_LATEST_MAIL_ID, &latest_mail_id);
+ if (ret < 0 || latest_mail_id == 0) {
+ EM_DEBUG_LOG("vconf_get_int() failed [%d] or latest_mail_id is zero", ret);
+
+ local_db_handle = em_storage_get_db_connection();
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql, &result, NULL, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EM_STORAGE_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+ ("SQL(%s) sqlite3_get_table fail:%d -%s", sql, rc, sqlite3_errmsg(local_db_handle)));
+ if (NULL == result[1])
+ rc = 1;
+ else
+ rc = atoi(result[1]) + 1;
+
+ sqlite3_free_table(result);
+ latest_mail_id = rc;
+ }
+
+ latest_mail_id++;
+
+ ret = vconf_set_int(VCONF_KEY_LATEST_MAIL_ID, latest_mail_id);
+
+ if (mail_id)
+ *mail_id = latest_mail_id;
+
+#ifdef __FEATURE_USE_SHARED_MUTEX_FOR_GENERATING_MAIL_ID__
+ em_storage_shm_mutex_unlock(&mapped_for_generating_mail_id);
+#endif /* __FEATURE_USE_SHARED_MUTEX_FOR_GENERATING_MAIL_ID__ */
+
+ ret = true;
+
+FINISH_OFF:
+ _DISCONNECT_DB;
+
+ if (err_code != NULL)
+ *err_code = error;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+
+EXPORT_API int em_storage_add_mail(emf_mail_tbl_t* mail_tbl_data, int get_id, int transaction, int *err_code)
+{
+ EM_PROFILE_BEGIN(emStorageMailAdd);
+ EM_DEBUG_FUNC_BEGIN("mail_tbl_data[%p], get_id[%d], transaction[%d], err_code[%p]", mail_tbl_data, get_id, transaction, err_code);
+
+ if (!mail_tbl_data) {
+ EM_DEBUG_EXCEPTION("mail_tbl_data[%p], get_id[%d]", mail_tbl_data, get_id);
+ if (err_code != NULL)
+ *err_code = EM_STORAGE_ERROR_INVALID_PARAM;
+ return false;
+ }
+
+ int rc, ret = false;
+ int error = EM_STORAGE_ERROR_NONE;
+ static char bufDatetime[30] = {0, };
+ DB_STMT hStmt = NULL;
+ char sql_query_string[QUERY_SIZE] = {0, };
+
+ sqlite3 *local_db_handle = em_storage_get_db_connection();
+ EM_STORAGE_START_WRITE_TRANSACTION(transaction, error);
+
+ if (get_id) {
+ /* increase unique id */
+ char *sql = "SELECT max(rowid) FROM mail_tbl;";
+ char **result;
+
+ /* rc = sqlite3_get_table(local_db_handle, sql, &result, NULL, NULL, NULL); */
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql, &result, NULL, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EM_STORAGE_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+ ("SQL(%s) sqlite3_get_table fail:%d -%s", sql, rc, sqlite3_errmsg(local_db_handle)));
+
+ if (NULL==result[1])
+ rc = 1;
+ else
+ rc = atoi(result[1])+1;
+ sqlite3_free_table(result);
+ mail_tbl_data->mail_id = rc;
+ mail_tbl_data->thread_id = mail_tbl_data->mail_id;
+ }
+
+ if (!mail_tbl_data->datetime) {
+ time_t t = time(NULL);
+ struct tm *p_tm = localtime(&t);
+
+ if (p_tm) {
+ SNPRINTF(bufDatetime, sizeof(bufDatetime), "%04d%02d%02d%02d%02d%02d",
+ p_tm->tm_year + 1900,
+ p_tm->tm_mon + 1,
+ p_tm->tm_mday,
+ p_tm->tm_hour,
+ p_tm->tm_min,
+ p_tm->tm_sec);
+ }
+ }
+ else if (strlen(mail_tbl_data->datetime) > 14) {
+ EM_DEBUG_EXCEPTION("WARNING: the given datatime is too big.");
+ memcpy(bufDatetime, mail_tbl_data->datetime, 14);
+ bufDatetime[14] = NULL_CHAR;
+ }
+ else
+ strncpy(bufDatetime, mail_tbl_data->datetime, sizeof(bufDatetime)-1);
+
+ SNPRINTF(sql_query_string, sizeof(sql_query_string),
+ "INSERT INTO mail_tbl VALUES "
+ "( ?" /* mail_id */
+ ", ?" /* account_id */
+ ", ?" /* mailbox_name */
+ ", ?" /* mailbox_type */
+ ", ?" /* subject */
+ ", ?" /* date_time */
+ ", ?" /* server_mail_status */
+ ", ?" /* server_mailbox_name */
+ ", ?" /* server_mail_id */
+ ", ?" /* message_id */
+ ", ?" /* full_address_from */
+ ", ?" /* full_address_reply */
+ ", ?" /* full_address_to */
+ ", ?" /* full_address_cc */
+ ", ?" /* full_address_bcc */
+ ", ?" /* full_address_return */
+ ", ?" /* email_address_sender */
+ ", ?" /* email_address_recipient */
+ ", ?" /* alias_sender */
+ ", ?" /* alias_recipient */
+ ", ?" /* body_download_status */
+ ", ?" /* file_path_plain */
+ ", ?" /* file_path_html */
+ ", ?" /* mail_size */
+ ", ?" /* flags_seen_field */
+ ", ?" /* flags_deleted_field */
+ ", ?" /* flags_flagged_field */
+ ", ?" /* flags_answered_field */
+ ", ?" /* flags_recent_field */
+ ", ?" /* flags_draft_field */
+ ", ?" /* flags_forwarded_field */
+ ", ?" /* DRM_status */
+ ", ?" /* priority */
+ ", ?" /* save_status */
+ ", ?" /* lock_status */
+ ", ?" /* report_status */
+ ", ?" /* attachment_count */
+ ", ?" /* inline_content_count */
+ ", ?" /* thread_id */
+ ", ?" /* thread_item_count */
+ ", ?" /* preview_text */
+ ", ?" /* meeting_request_status */
+ ")");
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ _bindStmtFieldDataInt(hStmt, MAIL_ID_IDX_IN_MAIL_TBL, mail_tbl_data->mail_id);
+ _bindStmtFieldDataInt(hStmt, ACCOUNT_ID_IDX_IN_MAIL_TBL, mail_tbl_data->account_id);
+ _bindStmtFieldDataString(hStmt, MAILBOX_NAME_IDX_IN_MAIL_TBL, (char *)mail_tbl_data->mailbox_name, 0, MAILBOX_LEN_IN_MAIL_TBL);
+ _bindStmtFieldDataInt(hStmt, MAILBOX_TYPE_IDX_IN_MAIL_TBL, mail_tbl_data->mailbox_type);
+ _bindStmtFieldDataString(hStmt, SUBJECT_IDX_IN_MAIL_TBL, (char *)mail_tbl_data->subject, 1, SUBJECT_LEN_IN_MAIL_TBL);
+ _bindStmtFieldDataString(hStmt, DATETIME_IDX_IN_MAIL_TBL, (char *)bufDatetime, 0, DATETIME_LEN_IN_MAIL_TBL);
+ _bindStmtFieldDataInt(hStmt, SERVER_MAIL_STATUS_IDX_IN_MAIL_TBL, mail_tbl_data->server_mail_status);
+ _bindStmtFieldDataString(hStmt, SERVER_MAILBOX_NAME_IDX_IN_MAIL_TBL, (char *)mail_tbl_data->server_mailbox_name, 0, SERVER_MAILBOX_LEN_IN_MAIL_TBL);
+ _bindStmtFieldDataString(hStmt, SERVER_MAIL_ID_IDX_IN_MAIL_TBL, (char *)mail_tbl_data->server_mail_id, 0, SERVER_MAIL_ID_LEN_IN_MAIL_TBL);
+ _bindStmtFieldDataString(hStmt, MESSAGE_ID_IDX_IN_MAIL_TBL, (char *)mail_tbl_data->message_id, 0, MESSAGE_ID_LEN_IN_MAIL_TBL);
+ _bindStmtFieldDataString(hStmt, FULL_ADDRESS_FROM_IDX_IN_MAIL_TBL, (char *)mail_tbl_data->full_address_from, 1, FROM_LEN_IN_MAIL_TBL);
+ _bindStmtFieldDataString(hStmt, FULL_ADDRESS_REPLY_IDX_IN_MAIL_TBL, (char *)mail_tbl_data->full_address_reply, 1, REPLY_TO_LEN_IN_MAIL_TBL);
+ _bindStmtFieldDataString(hStmt, FULL_ADDRESS_TO_IDX_IN_MAIL_TBL, (char *)mail_tbl_data->full_address_to, 1, TO_LEN_IN_MAIL_TBL);
+ _bindStmtFieldDataString(hStmt, FULL_ADDRESS_CC_IDX_IN_MAIL_TBL, (char *)mail_tbl_data->full_address_cc, 1, CC_LEN_IN_MAIL_TBL);
+ _bindStmtFieldDataString(hStmt, FULL_ADDRESS_BCC_IDX_IN_MAIL_TBL, (char *)mail_tbl_data->full_address_bcc, 1, BCC_LEN_IN_MAIL_TBL);
+ _bindStmtFieldDataString(hStmt, FULL_ADDRESS_RETURN_IDX_IN_MAIL_TBL, (char *)mail_tbl_data->full_address_return, 1, RETURN_PATH_LEN_IN_MAIL_TBL);
+ _bindStmtFieldDataString(hStmt, EMAIL_ADDRESS_SENDER_IDX_IN_MAIL_TBL, (char *)mail_tbl_data->email_address_sender, 1, FROM_EMAIL_ADDRESS_LEN_IN_MAIL_TBL);
+ _bindStmtFieldDataString(hStmt, EMAIL_ADDRESS_RECIPIENT_IDX_IN_MAIL_TBL, (char *)mail_tbl_data->email_address_recipient, 1, TO_EMAIL_ADDRESS_LEN_IN_MAIL_TBL);
+ _bindStmtFieldDataString(hStmt, ALIAS_SENDER_IDX_IN_MAIL_TBL, (char *)mail_tbl_data->alias_sender, 1, FROM_CONTACT_NAME_LEN_IN_MAIL_TBL);
+ _bindStmtFieldDataString(hStmt, ALIAS_RECIPIENT_IDX_IN_MAIL_TBL, (char *)mail_tbl_data->alias_recipient, 1, FROM_CONTACT_NAME_LEN_IN_MAIL_TBL);
+ _bindStmtFieldDataInt(hStmt, BODY_DOWNLOAD_STATUS_IDX_IN_MAIL_TBL, mail_tbl_data->body_download_status);
+ _bindStmtFieldDataString(hStmt, FILE_PATH_PLAIN_IDX_IN_MAIL_TBL, (char *)mail_tbl_data->file_path_plain, 0, TEXT_1_LEN_IN_MAIL_TBL);
+ _bindStmtFieldDataString(hStmt, FILE_PATH_HTML_IDX_IN_MAIL_TBL, (char *)mail_tbl_data->file_path_html, 0, TEXT_2_LEN_IN_MAIL_TBL);
+ _bindStmtFieldDataInt(hStmt, MAIL_SIZE_IDX_IN_MAIL_TBL, mail_tbl_data->mail_size);
+ _bindStmtFieldDataInt(hStmt, FLAGS_SEEN_FIELD_IDX_IN_MAIL_TBL, mail_tbl_data->flags_seen_field);
+ _bindStmtFieldDataInt(hStmt, FLAGS_DELETED_FIELD_IDX_IN_MAIL_TBL, mail_tbl_data->flags_deleted_field);
+ _bindStmtFieldDataInt(hStmt, FLAGS_FLAGGED_FIELD_IDX_IN_MAIL_TBL, mail_tbl_data->flags_flagged_field);
+ _bindStmtFieldDataInt(hStmt, FLAGS_ANSWERED_FIELD_IDX_IN_MAIL_TBL, mail_tbl_data->flags_answered_field);
+ _bindStmtFieldDataInt(hStmt, FLAGS_RECENT_FIELD_IDX_IN_MAIL_TBL, mail_tbl_data->flags_recent_field);
+ _bindStmtFieldDataInt(hStmt, FLAGS_DRAFT_FIELD_IDX_IN_MAIL_TBL, mail_tbl_data->flags_draft_field);
+ _bindStmtFieldDataInt(hStmt, FLAGS_FORWARDED_FIELD_IDX_IN_MAIL_TBL, mail_tbl_data->flags_forwarded_field);
+ _bindStmtFieldDataInt(hStmt, DRM_STATUS_IDX_IN_MAIL_TBL, mail_tbl_data->DRM_status);
+ _bindStmtFieldDataInt(hStmt, PRIORITY_IDX_IN_MAIL_TBL, mail_tbl_data->priority);
+ _bindStmtFieldDataInt(hStmt, SAVE_STATUS_IDX_IN_MAIL_TBL, mail_tbl_data->save_status);
+ _bindStmtFieldDataInt(hStmt, LOCK_STATUS_IDX_IN_MAIL_TBL, mail_tbl_data->lock_status);
+ _bindStmtFieldDataInt(hStmt, REPORT_STATUS_IDX_IN_MAIL_TBL, mail_tbl_data->report_status);
+ _bindStmtFieldDataInt(hStmt, ATTACHMENT_COUNT_IDX_IN_MAIL_TBL, mail_tbl_data->attachment_count);
+ _bindStmtFieldDataInt(hStmt, INLINE_CONTENT_COUNT_IDX_IN_MAIL_TBL, mail_tbl_data->inline_content_count);
+ _bindStmtFieldDataInt(hStmt, THREAD_ID_IDX_IN_MAIL_TBL, mail_tbl_data->thread_id);
+ _bindStmtFieldDataInt(hStmt, THREAD_ITEM_COUNT_IDX_IN_MAIL_TBL, mail_tbl_data->thread_item_count);
+ _bindStmtFieldDataString(hStmt, PREVIEW_TEXT_IDX_IN_MAIL_TBL, (char *)mail_tbl_data->preview_text, 1, PREVIEWBODY_LEN_IN_MAIL_TBL);
+ _bindStmtFieldDataInt(hStmt, MEETING_REQUEST_STATUS_IDX_IN_MAIL_TBL, mail_tbl_data->meeting_request_status);
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
+ EM_DEBUG_DB_EXEC((rc == SQLITE_FULL), {error = EM_STORAGE_ERROR_DB_IS_FULL;goto FINISH_OFF; }, ("sqlite3_step fail:%d", rc));
+ EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; }, ("sqlite3_step fail:%d", rc));
+ ret = true;
+
+FINISH_OFF:
+
+ if (hStmt != NULL) {
+ rc = sqlite3_finalize(hStmt);
+ if (rc != SQLITE_OK) {
+ EM_DEBUG_LOG("sqlite3_finalize failed - %d", rc);
+ error = EM_STORAGE_ERROR_DB_FAILURE;
+ }
+ }
+
+ EM_STORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
+ _DISCONNECT_DB;
+
+
+ if (err_code != NULL)
+ *err_code = error;
+
+ EM_PROFILE_END(emStorageMailAdd);
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+EXPORT_API int em_storage_move_multiple_mails(int account_id, char *target_mailbox_name, int mail_ids[], int number_of_mails, int transaction, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("account_id [%d], target_mailbox_name [%s], mail_ids[%p], number_of_mails [%d], transaction[%d], err_code[%p]", account_id, target_mailbox_name, mail_ids, number_of_mails, transaction, err_code);
+
+ int rc, ret = false, i, cur_conditional_clause = 0;
+ int error = EM_STORAGE_ERROR_NONE;
+ char sql_query_string[QUERY_SIZE] = {0, }, conditional_clause[QUERY_SIZE] = {0, };
+ emf_mailbox_tbl_t *result_mailbox = NULL;
+ emf_mailbox_type_e target_mailbox_type = EMF_MAILBOX_TYPE_USER_DEFINED;
+
+ if (!mail_ids || !target_mailbox_name) {
+ EM_DEBUG_EXCEPTION("EM_STORAGE_ERROR_INVALID_PARAM");
+ if (err_code != NULL)
+ *err_code = EM_STORAGE_ERROR_INVALID_PARAM;
+ return false;
+ }
+
+ sqlite3 *local_db_handle = em_storage_get_db_connection();
+
+ if(!em_storage_get_mailbox_by_name(account_id, -1, target_mailbox_name, &result_mailbox, true, &error)) {
+ EM_DEBUG_EXCEPTION("em_storage_get_mailbox_by_name failed [%d]", error);
+ goto FINISH_OFF;
+ }
+
+ if(result_mailbox) {
+ target_mailbox_type = result_mailbox->mailbox_type;
+ em_storage_free_mailbox(&result_mailbox, 1, NULL);
+ }
+
+ cur_conditional_clause = SNPRINTF(conditional_clause, QUERY_SIZE, "WHERE mail_id in (");
+
+ for(i = 0; i < number_of_mails; i++)
+ cur_conditional_clause += SNPRINTF_OFFSET(conditional_clause, cur_conditional_clause, QUERY_SIZE, "%d,", mail_ids[i]);
+
+ conditional_clause[strlen(conditional_clause) - 1] = ')';
+
+ EM_STORAGE_START_WRITE_TRANSACTION(transaction, error);
+
+ /* Updating a mail_tbl */
+
+ memset(sql_query_string, 0x00, QUERY_SIZE);
+ SNPRINTF(sql_query_string, QUERY_SIZE, "UPDATE mail_tbl SET mailbox_name = '%s', mailbox_type = %d %s", target_mailbox_name, target_mailbox_type, conditional_clause);
+ EM_DEBUG_LOG("Query [%s]", sql_query_string);
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {goto FINISH_OFF; },
+ ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ /* Updating a mail_attachment_tbl */
+
+ memset(sql_query_string, 0x00, QUERY_SIZE);
+ SNPRINTF(sql_query_string, QUERY_SIZE, "UPDATE mail_attachment_tbl SET mailbox_name = '%s' %s", target_mailbox_name, conditional_clause);
+ EM_DEBUG_LOG("Query [%s]", sql_query_string);
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {goto FINISH_OFF; },
+ ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ /* Updating a mail_meeting_tbl */
+ memset(sql_query_string, 0x00, QUERY_SIZE);
+ SNPRINTF(sql_query_string, QUERY_SIZE, "UPDATE mail_meeting_tbl SET mailbox_name = '%s' %s", target_mailbox_name, conditional_clause);
+ EM_DEBUG_LOG("Query [%s]", sql_query_string);
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {goto FINISH_OFF; },
+ ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ /* Updating a mail_read_mail_uid_tbl */
+ memset(conditional_clause, 0x00, QUERY_SIZE);
+ cur_conditional_clause = SNPRINTF(conditional_clause, QUERY_SIZE, "WHERE local_uid in (");
+
+ for(i = 0; i < number_of_mails; i++)
+ cur_conditional_clause += SNPRINTF_OFFSET(conditional_clause, cur_conditional_clause, QUERY_SIZE, "%d,", mail_ids[i]);
+
+ conditional_clause[strlen(conditional_clause) - 1] = ')';
+
+ memset(sql_query_string, 0x00, QUERY_SIZE);
+ SNPRINTF(sql_query_string, QUERY_SIZE, "UPDATE mail_read_mail_uid_tbl SET mailbox_name = '%s', local_mbox = '%s' %s", target_mailbox_name, target_mailbox_name, conditional_clause);
+ EM_DEBUG_LOG("Query [%s]", sql_query_string);
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {goto FINISH_OFF; },
+ ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ ret = true;
+
+FINISH_OFF:
+ EM_STORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
+ _DISCONNECT_DB;
+
+ if (err_code != NULL)
+ *err_code = error;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+EXPORT_API int em_storage_delete_mail(int mail_id, int from_server, int transaction, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("mail_id[%d], transaction[%d], err_code[%p]", mail_id, transaction, err_code);
+
+ if (!mail_id) {
+ EM_DEBUG_EXCEPTION("mail_id[%d]", mail_id);
+ if (err_code != NULL)
+ *err_code = EM_STORAGE_ERROR_INVALID_PARAM;
+ return false;
+ }
+
+ int rc, ret = false;
+ int error = EM_STORAGE_ERROR_NONE;
+ char sql_query_string[QUERY_SIZE] = {0, };
+
+ sqlite3 *local_db_handle = em_storage_get_db_connection();
+ EM_STORAGE_START_WRITE_TRANSACTION(transaction, error);
+
+ memset(sql_query_string, 0x00, sizeof(sql_query_string));
+
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), "DELETE FROM mail_tbl WHERE mail_id = %d ", mail_id);
+ EM_DEBUG_LOG("Query [%s]", sql_query_string);
+
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {goto FINISH_OFF; },
+ ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ ret = true;
+
+FINISH_OFF:
+ EM_STORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
+ _DISCONNECT_DB;
+
+ if (err_code != NULL)
+ *err_code = error;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+EXPORT_API int em_storage_delete_multiple_mails(int mail_ids[], int number_of_mails, int transaction, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("mail_ids[%p], number_of_mails [%d], transaction[%d], err_code[%p]", mail_ids, number_of_mails, transaction, err_code);
+
+ int rc, ret = false, i, cur_sql_query_string = 0;
+ int error = EM_STORAGE_ERROR_NONE;
+ char sql_query_string[QUERY_SIZE] = {0, };
+
+ if (!mail_ids) {
+ EM_DEBUG_EXCEPTION("EM_STORAGE_ERROR_INVALID_PARAM");
+ if (err_code != NULL)
+ *err_code = EM_STORAGE_ERROR_INVALID_PARAM;
+ return false;
+ }
+
+ sqlite3 *local_db_handle = em_storage_get_db_connection();
+ EM_STORAGE_START_WRITE_TRANSACTION(transaction, error);
+
+ cur_sql_query_string = SNPRINTF(sql_query_string, sizeof(sql_query_string), "DELETE FROM mail_tbl WHERE mail_id in (");
+
+ for(i = 0; i < number_of_mails; i++)
+ cur_sql_query_string += SNPRINTF_OFFSET(sql_query_string, cur_sql_query_string, QUERY_SIZE, "%d,", mail_ids[i]);
+
+ sql_query_string[strlen(sql_query_string) - 1] = ')';
+
+ EM_DEBUG_LOG("Query [%s]", sql_query_string);
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {goto FINISH_OFF; },
+ ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ ret = true;
+
+FINISH_OFF:
+ EM_STORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
+ _DISCONNECT_DB;
+
+ if (err_code != NULL)
+ *err_code = error;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+EXPORT_API int em_storage_delete_mail_by_account(int account_id, int transaction, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("account_id[%d], transaction[%d], err_code[%p]", account_id, transaction, err_code);
+
+ if (account_id < FIRST_ACCOUNT_ID) {
+ EM_DEBUG_EXCEPTION("account_id[%d]", account_id);
+
+ if (err_code != NULL)
+ *err_code = EM_STORAGE_ERROR_INVALID_PARAM;
+ return false;
+ }
+
+ int rc, ret = false;
+ int error = EM_STORAGE_ERROR_NONE;
+ char sql_query_string[QUERY_SIZE] = {0, };
+
+ sqlite3 *local_db_handle = em_storage_get_db_connection();
+ EM_STORAGE_START_WRITE_TRANSACTION(transaction, error);
+
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), "DELETE FROM mail_tbl WHERE account_id = %d", account_id);
+ EM_DEBUG_LOG("Query [%s]", sql_query_string);
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ rc = sqlite3_changes(local_db_handle);
+ if (rc == 0) {
+ EM_DEBUG_EXCEPTION(" no mail found...");
+ error = EM_STORAGE_ERROR_MAIL_NOT_FOUND;
+ }
+
+ /* Delete all mails mail_read_mail_uid_tbl table based on account id */
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), "DELETE FROM mail_read_mail_uid_tbl WHERE account_id = %d", account_id);
+ EM_DEBUG_LOG("Query [%s]", sql_query_string);
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ rc = sqlite3_changes(local_db_handle);
+ if (rc == 0) {
+ EM_DEBUG_EXCEPTION("no mail found...");
+ error = EM_STORAGE_ERROR_MAIL_NOT_FOUND;
+ }
+
+ if (!em_storage_notify_storage_event(NOTI_MAIL_DELETE_WITH_ACCOUNT, account_id, 0 , NULL, 0))
+ EM_DEBUG_EXCEPTION(" em_storage_notify_storage_event Failed [ NOTI_MAIL_DELETE_ALL ]");
+
+ ret = true;
+
+FINISH_OFF:
+
+ EM_STORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
+ _DISCONNECT_DB;
+
+ if (err_code != NULL)
+ *err_code = error;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+EXPORT_API int em_storage_delete_mail_by_mailbox(int account_id, char *mbox, int transaction, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("account_id[%d], mbox[%p], transaction[%d], err_code[%p]", account_id, mbox, transaction, err_code);
+
+ if (account_id < FIRST_ACCOUNT_ID || !mbox) {
+ EM_DEBUG_EXCEPTION(" account_id[%d], mbox[%p]", account_id, mbox);
+ if (err_code != NULL)
+ *err_code = EM_STORAGE_ERROR_INVALID_PARAM;
+ return false;
+ }
+
+ int rc, ret = false;
+ int error = EM_STORAGE_ERROR_NONE;
+ char sql_query_string[QUERY_SIZE] = {0, };
+
+ sqlite3 *local_db_handle = em_storage_get_db_connection();
+
+ EM_STORAGE_START_WRITE_TRANSACTION(transaction, error);
+
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), "DELETE FROM mail_tbl WHERE account_id = %d AND mailbox_name = '%s'", account_id, mbox);
+ EM_DEBUG_LOG("Query [%s]", sql_query_string);
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+
+ /* Delete Mails from mail_read_mail_uid_tbl */
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), "DELETE FROM mail_read_mail_uid_tbl WHERE account_id = %d AND mailbox_name = '%s'", account_id, mbox);
+ EM_DEBUG_LOG("Query [%s]", sql_query_string);
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ if (!em_storage_notify_storage_event(NOTI_MAIL_DELETE_ALL, account_id, 0 , mbox, 0))
+ EM_DEBUG_EXCEPTION(" em_storage_notify_storage_event Failed [ NOTI_MAIL_DELETE_ALL ] >>>> ");
+
+ ret = true;
+
+FINISH_OFF:
+ EM_STORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
+ _DISCONNECT_DB;
+
+ if (err_code != NULL)
+ *err_code = error;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+EXPORT_API int em_storage_free_mail(emf_mail_tbl_t** mail_list, int count, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("mail_list[%p], count[%d], err_code[%p]", mail_list, count, err_code);
+
+ if (count > 0) {
+ if ((mail_list == NULL) || (*mail_list == NULL)) {
+ EM_DEBUG_EXCEPTION("mail_ilst[%p], count[%d]", mail_list, count);
+
+ if (err_code)
+ *err_code = EM_STORAGE_ERROR_INVALID_PARAM;
+ return false;
+ }
+
+ emf_mail_tbl_t* p = *mail_list;
+ int i = 0;
+
+ for (; i < count; i++, p++) {
+ EM_SAFE_FREE(p->mailbox_name);
+ EM_SAFE_FREE(p->server_mailbox_name);
+ EM_SAFE_FREE(p->server_mail_id);
+ EM_SAFE_FREE(p->full_address_from);
+ EM_SAFE_FREE(p->full_address_reply);
+ EM_SAFE_FREE(p->full_address_to);
+ EM_SAFE_FREE(p->full_address_cc);
+ EM_SAFE_FREE(p->full_address_bcc);
+ EM_SAFE_FREE(p->full_address_return);
+ EM_SAFE_FREE(p->subject);
+ EM_SAFE_FREE(p->file_path_plain);
+ EM_SAFE_FREE(p->file_path_html);
+ EM_SAFE_FREE(p->datetime);
+ EM_SAFE_FREE(p->message_id);
+ EM_SAFE_FREE(p->email_address_sender);
+ EM_SAFE_FREE(p->email_address_recipient);
+ EM_SAFE_FREE(p->preview_text);
+ EM_SAFE_FREE(p->alias_sender);
+ EM_SAFE_FREE(p->alias_recipient);
+ }
+ EM_SAFE_FREE(*mail_list);
+ }
+
+ if (err_code != NULL)
+ *err_code = EM_STORAGE_ERROR_NONE;
+
+ EM_DEBUG_FUNC_END();
+ return true;
+}
+
+EXPORT_API int em_storage_get_attachment_count(int mail_id, int *count, int transaction, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("mail_id[%d], count[%p], transaction[%d], err_code[%p]", mail_id, count, transaction, err_code);
+
+ if (mail_id <= 0 || !count) {
+ EM_DEBUG_EXCEPTION("mail_id[%d], count[%p]", mail_id, count);
+ if (err_code != NULL)
+ *err_code = EM_STORAGE_ERROR_INVALID_PARAM;
+ return false;
+ }
+
+ int rc = -1, ret = false;
+ int error = EM_STORAGE_ERROR_NONE;
+ char sql_query_string[QUERY_SIZE] = {0, };
+
+ sqlite3 *local_db_handle = em_storage_get_db_connection();
+ EM_STORAGE_START_READ_TRANSACTION(transaction);
+
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT COUNT(*) FROM mail_attachment_tbl WHERE mail_id = %d", mail_id);
+
+ char **result;
+ /* rc = sqlite3_get_table(local_db_handle, sql_query_string, &result, NULL, NULL, NULL); */
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, NULL, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EM_STORAGE_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+ ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ *count = atoi(result[1]);
+ sqlite3_free_table(result);
+
+ ret = true;
+
+FINISH_OFF:
+
+ EM_STORAGE_FINISH_READ_TRANSACTION(transaction);
+ _DISCONNECT_DB;
+
+ if (err_code != NULL)
+ *err_code = error;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+EXPORT_API int em_storage_get_attachment_list(int input_mail_id, int input_transaction, emf_mail_attachment_tbl_t** output_attachment_list, int *output_attachment_count)
+{
+ EM_DEBUG_FUNC_BEGIN("input_mail_id[%d], input_transaction[%d], output_attachment_list[%p], output_attachment_count[%p]", input_mail_id, output_attachment_list, input_transaction, output_attachment_count);
+
+ if (input_mail_id <= 0 || !output_attachment_list || !output_attachment_count) {
+ EM_DEBUG_EXCEPTION("EM_STORAGE_ERROR_INVALID_PARAM");
+ return EM_STORAGE_ERROR_INVALID_PARAM;
+ }
+
+ int error = EM_STORAGE_ERROR_NONE;
+ int i = 0;
+ int rc = -1;
+ char **result = NULL;
+ char sql_query_string[QUERY_SIZE] = {0, };
+ emf_mail_attachment_tbl_t* p_data_tbl = NULL;
+ DB_STMT hStmt = NULL;
+ sqlite3 *local_db_handle = em_storage_get_db_connection();
+
+ EM_STORAGE_START_READ_TRANSACTION(input_transaction);
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT COUNT(*) FROM mail_attachment_tbl WHERE mail_id = %d", input_mail_id);
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, NULL, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EM_STORAGE_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+ ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ *output_attachment_count = atoi(result[1]);
+ sqlite3_free_table(result);
+
+ if(*output_attachment_count == 0) {
+ error = EM_STORAGE_ERROR_NONE;
+ goto FINISH_OFF;
+ }
+
+ p_data_tbl = (emf_mail_attachment_tbl_t*)em_core_malloc(sizeof(emf_mail_attachment_tbl_t) * (*output_attachment_count));
+
+ if (!p_data_tbl) {
+ EM_DEBUG_EXCEPTION("em_core_malloc failed...");
+ error = EM_STORAGE_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT * FROM mail_attachment_tbl WHERE mail_id = %d ORDER BY attachment_id", input_mail_id);
+ EM_DEBUG_LOG("sql_query_string [%s]", sql_query_string);
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; }, ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
+ EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; }, ("sqlite3_step fail:%d", rc));
+
+ if (rc == SQLITE_DONE) {
+ EM_DEBUG_EXCEPTION("no matched attachment found...");
+ error = EM_STORAGE_ERROR_ATTACHMENT_NOT_FOUND;
+ goto FINISH_OFF;
+ }
+ for (i = 0; i < *output_attachment_count; i++) {
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl[i].attachment_id), ATTACHMENT_ID_IDX_IN_MAIL_ATTACHMENT_TBL);
+ _getStmtFieldDataString(hStmt, &(p_data_tbl[i].attachment_name), 0, ATTACHMENT_NAME_IDX_IN_MAIL_ATTACHMENT_TBL);
+ _getStmtFieldDataString(hStmt, &(p_data_tbl[i].attachment_path), 0, ATTACHMENT_PATH_IDX_IN_MAIL_ATTACHMENT_TBL);
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl[i].attachment_size), ATTACHMENT_SIZE_IDX_IN_MAIL_ATTACHMENT_TBL);
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl[i].mail_id), MAIL_ID_IDX_IN_MAIL_ATTACHMENT_TBL);
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl[i].account_id), ACCOUNT_ID_IDX_IN_MAIL_ATTACHMENT_TBL);
+ _getStmtFieldDataString(hStmt, &(p_data_tbl[i].mailbox_name), 0, MAILBOX_NAME_IDX_IN_MAIL_ATTACHMENT_TBL);
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl[i].file_yn), FILE_YN_IDX_IN_MAIL_ATTACHMENT_TBL);
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl[i].flag1), FLAG1_IDX_IN_MAIL_ATTACHMENT_TBL);
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl[i].flag2), FLAG2_IDX_IN_MAIL_ATTACHMENT_TBL);
+ _getStmtFieldDataInt(hStmt, &(p_data_tbl[i].flag3), FLAG3_IDX_IN_MAIL_ATTACHMENT_TBL);
+
+ EM_DEBUG_LOG("attachment[%d].attachment_id : %d", i, p_data_tbl[i].attachment_id);
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
+ EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; }, ("sqlite3_step fail:%d", rc));
+ }
+
+FINISH_OFF:
+
+ if (error == EM_STORAGE_ERROR_NONE)
+ *output_attachment_list = p_data_tbl;
+ else if (p_data_tbl != NULL)
+ em_storage_free_attachment(&p_data_tbl, *output_attachment_count, NULL);
+
+ rc = sqlite3_finalize(hStmt);
+
+ if (rc != SQLITE_OK) {
+ EM_DEBUG_EXCEPTION("sqlite3_finalize failed [%d]", rc);
+ error = EM_STORAGE_ERROR_DB_FAILURE;
+ }
+
+ EM_STORAGE_FINISH_READ_TRANSACTION(input_transaction);
+
+ _DISCONNECT_DB;
+
+ EM_DEBUG_FUNC_END("error [%d]", error);
+ return error;
+}
+
+EXPORT_API int em_storage_get_attachment(int mail_id, int attachment_id, emf_mail_attachment_tbl_t** attachment, int transaction, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("mail_id[%d], attachment_id[%d], attachment[%p], transaction[%d], err_code[%p]", mail_id, attachment_id, attachment, transaction, err_code);
+
+ if (mail_id <= 0 || attachment_id <= 0 || !attachment) {
+ EM_DEBUG_EXCEPTION("mail_id[%d], attachment_id[%d], attachment[%p]", mail_id, attachment_id, attachment);
+ if (err_code != NULL)
+ *err_code = EM_STORAGE_ERROR_INVALID_PARAM;
+ return false;
+ }
+
+ emf_mail_attachment_tbl_t* p_data_tbl = NULL;
+ char *p = NULL;
+ int rc, ret = false;
+ int error = EM_STORAGE_ERROR_NONE;
+ char sql_query_string[QUERY_SIZE] = {0, };
+
+ sqlite3 *local_db_handle = em_storage_get_db_connection();
+ EM_STORAGE_START_READ_TRANSACTION(transaction);
+
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT * FROM mail_attachment_tbl WHERE mail_id = %d AND attachment_id = %d", mail_id, attachment_id);
+
+ sqlite3_stmt* hStmt = NULL;
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
+ EM_DEBUG_LOG(" before sqlite3_prepare hStmt = %p", hStmt);
+
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ /* rc = sqlite3_step(hStmt); */
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
+ EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("sqlite3_step fail:%d", rc));
+
+ if (rc == SQLITE_DONE) {
+ EM_DEBUG_EXCEPTION("no matched attachment found...");
+ error = EM_STORAGE_ERROR_ATTACHMENT_NOT_FOUND;
+ goto FINISH_OFF;
+ }
+
+ if (!(p_data_tbl = (emf_mail_attachment_tbl_t*)malloc(sizeof(emf_mail_attachment_tbl_t) * 1))) {
+ EM_DEBUG_EXCEPTION("malloc failed...");
+ error = EM_STORAGE_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ memset(p_data_tbl, 0x00, sizeof(emf_mail_attachment_tbl_t) * 1);
+
+ p_data_tbl->attachment_id = sqlite3_column_int(hStmt, ATTACHMENT_ID_IDX_IN_MAIL_ATTACHMENT_TBL);
+ if ((p = (char *)sqlite3_column_text(hStmt, ATTACHMENT_NAME_IDX_IN_MAIL_ATTACHMENT_TBL)) && (int)strlen(p))
+ p_data_tbl->attachment_name = cpy_str(p);
+ if ((p = (char *)sqlite3_column_text(hStmt, ATTACHMENT_PATH_IDX_IN_MAIL_ATTACHMENT_TBL)) && (int)strlen(p))
+ p_data_tbl->attachment_path = cpy_str(p);
+ p_data_tbl->attachment_size = sqlite3_column_int(hStmt, ATTACHMENT_SIZE_IDX_IN_MAIL_ATTACHMENT_TBL);
+ p_data_tbl->mail_id = sqlite3_column_int(hStmt, MAIL_ID_IDX_IN_MAIL_ATTACHMENT_TBL);
+ p_data_tbl->account_id = sqlite3_column_int(hStmt, ACCOUNT_ID_IDX_IN_MAIL_ATTACHMENT_TBL);
+ if ((p = (char *)sqlite3_column_text(hStmt, MAILBOX_NAME_IDX_IN_MAIL_ATTACHMENT_TBL)) && (int)strlen(p))
+ p_data_tbl->mailbox_name = cpy_str(p);
+ p_data_tbl->file_yn = sqlite3_column_int(hStmt, FILE_YN_IDX_IN_MAIL_ATTACHMENT_TBL);
+ p_data_tbl->flag1 = sqlite3_column_int(hStmt, FLAG1_IDX_IN_MAIL_ATTACHMENT_TBL);
+ p_data_tbl->flag2 = sqlite3_column_int(hStmt, FLAG2_IDX_IN_MAIL_ATTACHMENT_TBL);
+ p_data_tbl->flag3 = sqlite3_column_int(hStmt, FLAG3_IDX_IN_MAIL_ATTACHMENT_TBL);
+
+#ifdef __ATTACHMENT_OPTI__
+ p_data_tbl->encoding = sqlite3_column_int(hStmt, ENCODING_IDX_IN_MAIL_ATTACHMENT_TBL);
+ if ((p = (char *)sqlite3_column_text(hStmt, SECTION_IDX_IN_MAIL_ATTACHMENT_TBL)) && (int)strlen(p))
+ p_data_tbl->section= cpy_str(p);
+#endif
+
+ ret = true;
+
+FINISH_OFF:
+ if (ret == true)
+ *attachment = p_data_tbl;
+
+ if (hStmt != NULL) {
+ EM_DEBUG_LOG("Before sqlite3_finalize hStmt = %p", hStmt);
+
+ rc = sqlite3_finalize(hStmt);
+ if (rc != SQLITE_OK) {
+ EM_DEBUG_EXCEPTION("sqlite3_finalize failed - %d", rc);
+ error = EM_STORAGE_ERROR_DB_FAILURE;
+ }
+ }
+
+ EM_STORAGE_FINISH_READ_TRANSACTION(transaction);
+ _DISCONNECT_DB;
+
+ if (err_code != NULL)
+ *err_code = error;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+EXPORT_API int em_storage_get_attachment_nth(int mail_id, int nth, emf_mail_attachment_tbl_t** attachment_tbl, int transaction, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("mail_id[%d], nth[%d], attachment_tbl[%p], transaction[%d], err_code[%p]", mail_id, nth, attachment_tbl, transaction, err_code);
+
+ if (mail_id <= 0 || nth <= 0 || !attachment_tbl) {
+ EM_DEBUG_EXCEPTION(" mail_id[%d], nth[%d], attachment[%p]", mail_id, nth, attachment_tbl);
+
+ if (err_code != NULL)
+ *err_code = EM_STORAGE_ERROR_INVALID_PARAM;
+ return false;
+ }
+
+ emf_mail_attachment_tbl_t* p_data_tbl = NULL;
+ char *p = NULL;
+ int rc, ret = false;
+ int error = EM_STORAGE_ERROR_NONE;
+ char sql_query_string[QUERY_SIZE] = {0, };
+
+ sqlite3 *local_db_handle = em_storage_get_db_connection();
+ EM_STORAGE_START_READ_TRANSACTION(transaction);
+
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT * FROM mail_attachment_tbl WHERE mail_id = %d ORDER BY attachment_id LIMIT %d, 1", mail_id, (nth - 1));
+ EM_DEBUG_LOG("query = [%s]", sql_query_string);
+
+ DB_STMT hStmt = NULL;
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ /* rc = sqlite3_step(hStmt); */
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
+ EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("sqlite3_step fail:%d", rc));
+
+ if (rc == SQLITE_DONE) {
+ EM_DEBUG_EXCEPTION(" no matched attachment found...");
+ error = EM_STORAGE_ERROR_ATTACHMENT_NOT_FOUND;
+ goto FINISH_OFF;
+ }
+
+ if (!(p_data_tbl = (emf_mail_attachment_tbl_t*)malloc(sizeof(emf_mail_attachment_tbl_t) * 1))) {
+ EM_DEBUG_EXCEPTION(" malloc failed...");
+ error = EM_STORAGE_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ memset(p_data_tbl, 0x00, sizeof(emf_mail_attachment_tbl_t) * 1);
+
+ p_data_tbl->attachment_id = sqlite3_column_int(hStmt, ATTACHMENT_ID_IDX_IN_MAIL_ATTACHMENT_TBL);
+ if ((p = (char *)sqlite3_column_text(hStmt, ATTACHMENT_NAME_IDX_IN_MAIL_ATTACHMENT_TBL)) && (int)strlen(p))
+ p_data_tbl->attachment_name = cpy_str(p);
+ if ((p = (char *)sqlite3_column_text(hStmt, ATTACHMENT_PATH_IDX_IN_MAIL_ATTACHMENT_TBL)) && (int)strlen(p))
+ p_data_tbl->attachment_path = cpy_str(p);
+ p_data_tbl->attachment_size = sqlite3_column_int(hStmt, ATTACHMENT_SIZE_IDX_IN_MAIL_ATTACHMENT_TBL);
+ p_data_tbl->mail_id = sqlite3_column_int(hStmt, MAIL_ID_IDX_IN_MAIL_ATTACHMENT_TBL);
+ p_data_tbl->account_id = sqlite3_column_int(hStmt, ACCOUNT_ID_IDX_IN_MAIL_ATTACHMENT_TBL);
+ if ((p = (char *)sqlite3_column_text(hStmt, MAILBOX_NAME_IDX_IN_MAIL_ATTACHMENT_TBL)) && (int)strlen(p))
+ p_data_tbl->mailbox_name = cpy_str(p);
+ p_data_tbl->file_yn = sqlite3_column_int(hStmt, FILE_YN_IDX_IN_MAIL_ATTACHMENT_TBL);
+ p_data_tbl->flag1 = sqlite3_column_int(hStmt, FLAG1_IDX_IN_MAIL_ATTACHMENT_TBL);
+ p_data_tbl->flag2 = sqlite3_column_int(hStmt, FLAG2_IDX_IN_MAIL_ATTACHMENT_TBL);
+ p_data_tbl->flag3 = sqlite3_column_int(hStmt, FLAG3_IDX_IN_MAIL_ATTACHMENT_TBL);
+
+#ifdef __ATTACHMENT_OPTI__
+ p_data_tbl->encoding = sqlite3_column_int(hStmt, ENCODING_IDX_IN_MAIL_ATTACHMENT_TBL);
+ if ((p = (char *)sqlite3_column_text(hStmt, SECTION_IDX_IN_MAIL_ATTACHMENT_TBL)) && (int)strlen(p))
+ p_data_tbl->section= cpy_str(p);
+#endif
+ ret = true;
+
+FINISH_OFF:
+ if (ret == true)
+ *attachment_tbl = p_data_tbl;
+ else if (p_data_tbl != NULL)
+ em_storage_free_attachment(&p_data_tbl, 1, NULL);
+
+ if (hStmt != NULL) {
+ EM_DEBUG_LOG("before sqlite3_finalize hStmt = %p", hStmt);
+
+ rc = sqlite3_finalize(hStmt);
+ if (rc != SQLITE_OK) {
+ EM_DEBUG_EXCEPTION("sqlite3_finalize failed - %d", rc);
+ error = EM_STORAGE_ERROR_DB_FAILURE;
+ }
+ }
+
+ EM_STORAGE_FINISH_READ_TRANSACTION(transaction);
+ _DISCONNECT_DB;
+
+ if (err_code != NULL)
+ *err_code = error;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+EXPORT_API int em_storage_change_attachment_field(int mail_id, emf_mail_change_type_t type, emf_mail_attachment_tbl_t* attachment, int transaction, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("mail_id[%d], type[%d], attachment[%p], transaction[%d], err_code[%p]", mail_id, type, attachment, transaction, err_code);
+
+ if (mail_id <= 0 || !attachment) {
+ EM_DEBUG_EXCEPTION(" mail_id[%d], type[%d], attachment[%p]", mail_id, type, attachment);
+ if (err_code != NULL)
+ *err_code = EM_STORAGE_ERROR_INVALID_PARAM;
+ return false;;
+ }
+
+ int rc, ret = false;
+ int error = EM_STORAGE_ERROR_NONE;
+ DB_STMT hStmt = NULL;
+ char sql_query_string[QUERY_SIZE] = {0, };
+
+ int i = 0;
+
+ sqlite3 *local_db_handle = em_storage_get_db_connection();
+
+ EM_STORAGE_START_WRITE_TRANSACTION(transaction, error);
+
+ switch (type) {
+ case UPDATE_MAILBOX:
+ EM_DEBUG_LOG("UPDATE_MAILBOX");
+ if (!attachment->mailbox_name) {
+ EM_DEBUG_EXCEPTION(" attachment->mailbox_name[%p]", attachment->mailbox_name);
+ error = EM_STORAGE_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+#ifdef CONVERT_UTF8_TO_UCS2
+ SNPRINTF(sql_query_string, sizeof(sql_query_string),
+ "UPDATE mail_attachment_tbl SET mailbox_name = '%s' WHERE mail_id = %d", attachment->mailbox_name, mail_id);
+#else /* CONVERT_UTF8_TO_UCS2 */
+ SNPRINTF(sql_query_string, sizeof(sql_query_string),
+ "UPDATE mail_attachment_tbl SET mailbox_name = ? WHERE mail_id = %d", mail_id);
+
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
+ EM_DEBUG_LOG(" Before sqlite3_prepare hStmt = %p", hStmt);
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ _bindStmtFieldDataString(hStmt, i++, (char *)attachment->mailbox_name, 0, MAILBOX_NAME_LEN_IN_MAIL_ATTACHMENT_TBL);
+#endif /* CONVERT_UTF8_TO_UCS2 */
+ break;
+
+ case UPDATE_SAVENAME:
+ EM_DEBUG_LOG("UPDATE_SAVENAME");
+ if (!attachment->attachment_path) {
+ EM_DEBUG_EXCEPTION(" attachment->attachment_path[%p]", attachment->attachment_path);
+ error = EM_STORAGE_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+#ifdef CONVERT_UTF8_TO_UCS2
+ SNPRINTF(sql_query_string, sizeof(sql_query_string),
+ "UPDATE mail_attachment_tbl SET"
+ " attachment_size = %d"
+ ", attachment_path = '%s'"
+ ", file_yn = 1"
+ " WHERE mail_id = %d"
+ " AND attachment_id = %d"
+ , attachment->attachment_size
+ , attachment->attachment_path
+ , attachment->mail_id
+ , attachment->attachment_id);
+#else /* CONVERT_UTF8_TO_UCS2 */
+ SNPRINTF(sql_query_string, sizeof(sql_query_string),
+ "UPDATE mail_attachment_tbl SET"
+ " attachment_size = ?"
+ ", file_yn = 1"
+ ", attachment_path = ?"
+ " WHERE mail_id = %d"
+ " AND attachment_id = %d"
+ , attachment->mail_id
+ , attachment->attachment_id);
+
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
+ EM_DEBUG_LOG(" Before sqlite3_prepare hStmt = %p", hStmt);
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ _bindStmtFieldDataInt(hStmt, i++, attachment->attachment_size);
+ _bindStmtFieldDataString(hStmt, i++, (char *)attachment->attachment_path, 0, ATTACHMENT_PATH_LEN_IN_MAIL_ATTACHMENT_TBL);
+#endif /* CONVERT_UTF8_TO_UCS2 */
+ break;
+
+ default:
+ EM_DEBUG_LOG("type[%d]", type);
+ error = EM_STORAGE_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+ EM_DEBUG_LOG("query = [%s]", sql_query_string);
+
+#ifdef CONVERT_UTF8_TO_UCS2
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+#else
+ /* rc = sqlite3_step(hStmt); */
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
+ EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("sqlite3_step fail:%d", rc));
+#endif
+ ret = true;
+
+FINISH_OFF:
+#ifdef CONVERT_UTF8_TO_UCS2
+#else /* CONVERT_UTF8_TO_UCS2 */
+ if (hStmt != NULL) {
+ EM_DEBUG_LOG(" Before sqlite3_finalize hStmt = %p", hStmt);
+ rc = sqlite3_finalize(hStmt);
+ if (rc != SQLITE_OK) {
+ EM_DEBUG_LOG(" sqlite3_finalize failed - %d", rc);
+ error = EM_STORAGE_ERROR_DB_FAILURE;
+ }
+ }
+#endif /* CONVERT_UTF8_TO_UCS2 */
+
+ EM_STORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
+ _DISCONNECT_DB;
+
+ if (err_code != NULL)
+ *err_code = error;
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+
+EXPORT_API int em_storage_rename_mailbox(int account_id, char *old_mailbox_name, char *new_mailbox_name, int transaction, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("account_id[%d], old_mailbox_name[%p], new_mailbox_name[%p], transaction[%d], err_code[%p]", account_id, old_mailbox_name, new_mailbox_name, transaction, err_code);
+
+ if (account_id < FIRST_ACCOUNT_ID ||!old_mailbox_name || !new_mailbox_name) {
+ EM_DEBUG_EXCEPTION("Invalid Parameters");
+ if (err_code != NULL)
+ *err_code = EM_STORAGE_ERROR_INVALID_PARAM;
+ return false;
+ }
+
+ int rc, ret = true;
+ int error = EM_STORAGE_ERROR_NONE;
+ char sql_query_string[QUERY_SIZE] = {0, };
+
+ sqlite3 *local_db_handle = em_storage_get_db_connection();
+
+ EM_STORAGE_START_WRITE_TRANSACTION(transaction, error);
+
+ SNPRINTF(sql_query_string, sizeof(sql_query_string),
+ "UPDATE mail_tbl SET"
+ " mailbox_name = '%s'"
+ " WHERE account_id = %d"
+ " AND mailbox_name = '%s'"
+ , new_mailbox_name
+ , account_id
+ , old_mailbox_name);
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
+
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ if (sqlite3_changes(local_db_handle) == 0)
+ EM_DEBUG_LOG("no mail matched...");
+
+
+ SNPRINTF(sql_query_string, sizeof(sql_query_string),
+ "UPDATE mail_attachment_tbl SET"
+ " mailbox_name = '%s'"
+ " WHERE account_id = %d"
+ " AND mailbox_name = '%s'"
+ , new_mailbox_name
+ , account_id
+ , old_mailbox_name);
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
+
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ if (sqlite3_changes(local_db_handle) == 0)
+ EM_DEBUG_LOG("no attachment matched...");
+
+ SNPRINTF(sql_query_string, sizeof(sql_query_string),
+ "UPDATE mail_meeting_tbl SET"
+ " mailbox_name = '%s'"
+ " WHERE account_id = %d"
+ " AND mailbox_name = '%s'"
+ , new_mailbox_name
+ , account_id
+ , old_mailbox_name);
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
+
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ if (sqlite3_changes(local_db_handle) == 0)
+ EM_DEBUG_LOG("no mail_meeting_tbl matched...");
+
+ ret = true;
+
+FINISH_OFF:
+
+ EM_STORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
+ _DISCONNECT_DB;
+
+ if (err_code != NULL)
+ *err_code = error;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+
+EXPORT_API int em_storage_change_attachment_mbox(int account_id, char *old_mailbox_name, char *new_mailbox_name, int transaction, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("account_id[%d], old_mailbox_name[%p], new_mailbox_name[%p], transaction[%d], err_code[%p]", account_id, old_mailbox_name, new_mailbox_name, transaction, err_code);
+
+ if (account_id < FIRST_ACCOUNT_ID || !old_mailbox_name || !new_mailbox_name) {
+ EM_DEBUG_EXCEPTION(" account_id[%d], old_mailbox_name[%p], new_mailbox_name[%p]", account_id, old_mailbox_name, new_mailbox_name);
+
+ if (err_code != NULL)
+ *err_code = EM_STORAGE_ERROR_INVALID_PARAM;
+ return false;
+ }
+
+ int rc, ret = true;
+ int error = EM_STORAGE_ERROR_NONE;
+ char sql_query_string[QUERY_SIZE] = {0, };
+
+ sqlite3 *local_db_handle = em_storage_get_db_connection();
+
+ EM_STORAGE_START_WRITE_TRANSACTION(transaction, error);
+
+ SNPRINTF(sql_query_string, sizeof(sql_query_string),
+ "UPDATE mail_attachment_tbl SET"
+ " mailbox_name = '%s'"
+ " WHERE account_id = %d"
+ " AND mailbox_name = '%s'"
+ , new_mailbox_name
+ , account_id
+ , old_mailbox_name);
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC((SQLITE_FULL == rc), {error = EM_STORAGE_ERROR_DB_IS_FULL;goto FINISH_OFF; },
+ ("sqlite3_exec fail:%d", rc));
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ rc = sqlite3_changes(local_db_handle);
+ if (rc == 0) {
+ EM_DEBUG_EXCEPTION(" no attachment found...");
+ }
+
+ ret = true;
+
+FINISH_OFF:
+
+ EM_STORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
+ _DISCONNECT_DB;
+
+ if (err_code != NULL)
+ *err_code = error;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+
+EXPORT_API int em_storage_get_new_attachment_no(int *attachment_no, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("attachment_no [%p], err_code[%p]", attachment_no, err_code);
+ int rc, ret = false;
+ int error = EM_STORAGE_ERROR_NONE;
+ char *sql = "SELECT max(rowid) FROM mail_attachment_tbl;";
+ char **result;
+
+ if (!attachment_no) {
+ EM_DEBUG_EXCEPTION("Invalid attachment");
+ error = EM_STORAGE_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ *attachment_no = -1;
+
+ sqlite3 *local_db_handle = em_storage_get_db_connection();
+
+ /* rc = sqlite3_get_table(local_db_handle, sql, &result, NULL, NULL, NULL); */
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql, &result, NULL, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EM_STORAGE_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+ ("SQL(%s) sqlite3_get_table fail:%d -%s", sql, rc, sqlite3_errmsg(local_db_handle)));
+
+ if (NULL == result[1])
+ rc = 1;
+ else
+ rc = atoi(result[1])+1;
+
+ sqlite3_free_table(result);
+
+ *attachment_no = rc;
+ EM_DEBUG_LOG("attachment_no [%d]", *attachment_no);
+ ret = true;
+
+FINISH_OFF:
+ _DISCONNECT_DB;
+
+ if (err_code != NULL)
+ *err_code = error;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+EXPORT_API int em_storage_add_attachment(emf_mail_attachment_tbl_t* attachment_tbl, int iscopy, int transaction, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("attachment_tbl[%p], iscopy[%d], transaction[%d], err_code[%p]", attachment_tbl, iscopy, transaction, err_code);
+
+ char *sql = NULL;
+ char **result;
+ int rc, ret = false;
+ int error = EM_STORAGE_ERROR_NONE;
+ DB_STMT hStmt = NULL;
+ char sql_query_string[QUERY_SIZE] = {0, };
+ sqlite3 *local_db_handle = em_storage_get_db_connection();
+
+ if (!attachment_tbl) {
+ EM_DEBUG_EXCEPTION("attachment_tbl[%p], iscopy[%d]", attachment_tbl, iscopy);
+ if (err_code != NULL)
+ *err_code = EM_STORAGE_ERROR_INVALID_PARAM;
+ return false;
+ }
+
+ EM_STORAGE_START_WRITE_TRANSACTION(transaction, error);
+
+ sql = "SELECT max(rowid) FROM mail_attachment_tbl;";
+ /* rc = sqlite3_get_table(local_db_handle, sql, &result, NULL, NULL, NULL); */
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql, &result, NULL, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EM_STORAGE_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+ ("SQL(%s) sqlite3_get_table fail:%d -%s", sql, rc, sqlite3_errmsg(local_db_handle)));
+
+ if (NULL==result[1]) rc = 1;
+ else rc = atoi(result[1]) + 1;
+ sqlite3_free_table(result);
+
+ attachment_tbl->attachment_id = rc;
+
+ SNPRINTF(sql_query_string, sizeof(sql_query_string),
+ "INSERT INTO mail_attachment_tbl VALUES "
+ "( ?" /* attachment_id */
+ ", ?" /* attachment_name */
+ ", ?" /* attachment_path */
+ ", ?" /* attachment_size */
+ ", ?" /* mail_id */
+ ", ?" /* account_id */
+ ", ?" /* mailbox_name */
+ ", ?" /* file_yn */
+ ", ?" /* flag1 */
+ ", ?" /* flag2 */
+#ifdef __ATTACHMENT_OPTI__
+ ", ?"
+ ", ?"
+#endif
+ ", ? )");/* flag3 */
+
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ _bindStmtFieldDataInt(hStmt, ATTACHMENT_ID_IDX_IN_MAIL_ATTACHMENT_TBL, attachment_tbl->attachment_id);
+ _bindStmtFieldDataString(hStmt, ATTACHMENT_NAME_IDX_IN_MAIL_ATTACHMENT_TBL, (char *)attachment_tbl->attachment_name, 0, ATTACHMENT_NAME_LEN_IN_MAIL_ATTACHMENT_TBL);
+ _bindStmtFieldDataString(hStmt, ATTACHMENT_PATH_IDX_IN_MAIL_ATTACHMENT_TBL, (char *)attachment_tbl->attachment_path, 0, ATTACHMENT_PATH_LEN_IN_MAIL_ATTACHMENT_TBL);
+ _bindStmtFieldDataInt(hStmt, ATTACHMENT_SIZE_IDX_IN_MAIL_ATTACHMENT_TBL, attachment_tbl->attachment_size);
+ _bindStmtFieldDataInt(hStmt, MAIL_ID_IDX_IN_MAIL_ATTACHMENT_TBL, attachment_tbl->mail_id);
+ _bindStmtFieldDataInt(hStmt, ACCOUNT_ID_IDX_IN_MAIL_ATTACHMENT_TBL, attachment_tbl->account_id);
+ _bindStmtFieldDataString(hStmt, MAILBOX_NAME_IDX_IN_MAIL_ATTACHMENT_TBL, (char *)attachment_tbl->mailbox_name, 0, MAILBOX_NAME_LEN_IN_MAIL_ATTACHMENT_TBL);
+ _bindStmtFieldDataInt(hStmt, FILE_YN_IDX_IN_MAIL_ATTACHMENT_TBL, attachment_tbl->file_yn);
+ _bindStmtFieldDataInt(hStmt, FLAG1_IDX_IN_MAIL_ATTACHMENT_TBL, attachment_tbl->flag1);
+ _bindStmtFieldDataInt(hStmt, FLAG2_IDX_IN_MAIL_ATTACHMENT_TBL, attachment_tbl->flag2);
+ _bindStmtFieldDataInt(hStmt, FLAG3_IDX_IN_MAIL_ATTACHMENT_TBL, attachment_tbl->flag3);
+#ifdef __ATTACHMENT_OPTI__
+ _bindStmtFieldDataInt(hStmt, ENCODING_IDX_IN_MAIL_ATTACHMENT_TBL, attachment_tbl->encoding);
+ _bindStmtFieldDataString(hStmt, SECTION_IDX_IN_MAIL_ATTACHMENT_TBL, (char *)attachment_tbl->section, 0, ATTACHMENT_LEN_IN_MAIL_ATTACHMENT_TBL);
+#endif
+
+ /* rc = sqlite3_step(hStmt); */
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
+ EM_DEBUG_DB_EXEC((SQLITE_FULL == rc), {error = EM_STORAGE_ERROR_DB_IS_FULL;goto FINISH_OFF; },
+ ("sqlite3_step fail:%d", rc));
+ EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("sqlite3_step fail:%d", rc));
+/*
+ SNPRINTF(sql_query_string, sizeof(sql_query_string),
+ "UPDATE mail_tbl SET attachment_count = 1 WHERE mail_id = %d", attachment_tbl->mail_id);
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
+
+ EM_DEBUG_DB_EXEC((SQLITE_FULL == rc), {error = EM_STORAGE_ERROR_DB_IS_FULL;goto FINISH_OFF; },
+ ("sqlite3_exec fail:%d", rc));
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+*/
+ rc = sqlite3_changes(local_db_handle);
+ if (rc == 0) {
+ EM_DEBUG_EXCEPTION(" no matched mail found...");
+ error = EM_STORAGE_ERROR_MAIL_NOT_FOUND;
+ goto FINISH_OFF;
+ }
+
+ ret = true;
+
+FINISH_OFF:
+ if (hStmt != NULL) {
+ rc = sqlite3_finalize(hStmt);
+ if (rc != SQLITE_OK) {
+ EM_DEBUG_EXCEPTION(" sqlite3_finalize failed - %d", rc);
+ error = EM_STORAGE_ERROR_DB_FAILURE;
+ }
+ }
+
+ EM_STORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
+ _DISCONNECT_DB;
+
+ if (err_code != NULL)
+ *err_code = error;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+EXPORT_API int em_storage_update_attachment(emf_mail_attachment_tbl_t* attachment_tbl, int transaction, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("attachment_tbl[%p], transaction[%d], err_code[%p]", attachment_tbl, transaction, err_code);
+
+ int rc, ret = false, field_idx = 0;
+ int error = EM_STORAGE_ERROR_NONE;
+ DB_STMT hStmt = NULL;
+ char sql_query_string[QUERY_SIZE] = {0, };
+
+ if (!attachment_tbl) {
+ EM_DEBUG_EXCEPTION(" attachment_tbl[%p] ", attachment_tbl);
+ error = EM_STORAGE_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ sqlite3 *local_db_handle = em_storage_get_db_connection();
+
+ EM_STORAGE_START_WRITE_TRANSACTION(transaction, error);
+
+ SNPRINTF(sql_query_string, sizeof(sql_query_string),
+ "UPDATE mail_attachment_tbl SET "
+ " attachment_name = ?"
+ ", attachment_path = ?"
+ ", attachment_size = ?"
+ ", mail_id = ?"
+ ", account_id = ?"
+ ", mailbox_name = ?"
+ ", file_yn = ?"
+ ", flag1 = ?"
+ ", flag2 = ?"
+ ", flag3 = ? "
+ " WHERE attachment_id = ?;");
+
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
+
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ _bindStmtFieldDataString(hStmt, field_idx++ , (char *)attachment_tbl->attachment_name, 0, ATTACHMENT_NAME_LEN_IN_MAIL_ATTACHMENT_TBL);
+ _bindStmtFieldDataString(hStmt, field_idx++ , (char *)attachment_tbl->attachment_path, 0, ATTACHMENT_PATH_LEN_IN_MAIL_ATTACHMENT_TBL);
+ _bindStmtFieldDataInt(hStmt, field_idx++ , attachment_tbl->attachment_size);
+ _bindStmtFieldDataInt(hStmt, field_idx++ , attachment_tbl->mail_id);
+ _bindStmtFieldDataInt(hStmt, field_idx++ , attachment_tbl->account_id);
+ _bindStmtFieldDataString(hStmt, field_idx++ , (char *)attachment_tbl->mailbox_name, 0, MAILBOX_NAME_LEN_IN_MAIL_ATTACHMENT_TBL);
+ _bindStmtFieldDataInt(hStmt, field_idx++ , attachment_tbl->file_yn);
+ _bindStmtFieldDataInt(hStmt, field_idx++ , attachment_tbl->flag1);
+ _bindStmtFieldDataInt(hStmt, field_idx++ , attachment_tbl->flag2);
+ _bindStmtFieldDataInt(hStmt, field_idx++ , attachment_tbl->flag3);
+ _bindStmtFieldDataInt(hStmt, field_idx++ , attachment_tbl->attachment_id);
+
+ /* rc = sqlite3_step(hStmt); */
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
+ EM_DEBUG_DB_EXEC((SQLITE_FULL == rc), {error = EM_STORAGE_ERROR_DB_IS_FULL;goto FINISH_OFF; },
+ ("sqlite3_step fail:%d", rc));
+ EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("sqlite3_step fail:%d", rc));
+/*
+ SNPRINTF(sql_query_string, sizeof(sql_query_string),
+ "UPDATE mail_tbl SET attachment_count = 1 WHERE mail_id = %d", attachment_tbl->mail_id);
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
+
+ EM_DEBUG_DB_EXEC((SQLITE_FULL == rc), {error = EM_STORAGE_ERROR_DB_IS_FULL;goto FINISH_OFF; },
+ ("sqlite3_exec fail:%d", rc));
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+*/
+ rc = sqlite3_changes(local_db_handle);
+ if (rc == 0) {
+ EM_DEBUG_EXCEPTION(" no matched mail found...");
+ error = EM_STORAGE_ERROR_MAIL_NOT_FOUND;
+ goto FINISH_OFF;
+ }
+
+ ret = true;
+
+FINISH_OFF:
+ if (hStmt != NULL) {
+ rc = sqlite3_finalize(hStmt);
+ if (rc != SQLITE_OK) {
+ EM_DEBUG_EXCEPTION(" sqlite3_finalize failed - %d", rc);
+ error = EM_STORAGE_ERROR_DB_FAILURE;
+ }
+ }
+
+ EM_STORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
+ _DISCONNECT_DB;
+
+ if (err_code != NULL)
+ *err_code = error;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+EXPORT_API int em_storage_delete_attachment_on_db(int mail_id, int attachment_id, int transaction, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("mail_id[%d], attachment_id[%d], transaction[%d], err_code[%p]", mail_id, attachment_id, transaction, err_code);
+
+ if (mail_id < 0 || attachment_id < 0) {
+ EM_DEBUG_EXCEPTION("mail_id[%d], attachment_id[%d]", mail_id, attachment_id);
+ if (err_code != NULL)
+ *err_code = EM_STORAGE_ERROR_INVALID_PARAM;
+ return false;
+ }
+
+ int rc, ret = false;
+ int error = EM_STORAGE_ERROR_NONE;
+ char sql_query_string[QUERY_SIZE] = {0, };
+
+ sqlite3 *local_db_handle = em_storage_get_db_connection();
+
+ EM_STORAGE_START_WRITE_TRANSACTION(transaction, error);
+
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), "DELETE FROM mail_attachment_tbl");
+
+ if (mail_id) /* '0' means all mail */
+ SNPRINTF(sql_query_string + strlen(sql_query_string), sizeof(sql_query_string)-(strlen(sql_query_string)+1), " WHERE mail_id = %d", mail_id);
+ if (attachment_id) /* '0' means all attachment */
+ SNPRINTF(sql_query_string + strlen(sql_query_string), sizeof(sql_query_string)-(strlen(sql_query_string)+1), " AND attachment_id = %d", attachment_id);
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ ret = true;
+
+FINISH_OFF:
+ EM_STORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
+ _DISCONNECT_DB;
+
+ if (err_code)
+ *err_code = error;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+EXPORT_API int em_storage_delete_attachment_all_on_db(int account_id, char *mbox, int transaction, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("account_id[%d], mbox[%p], transaction[%d], err_code[%p]", account_id, mbox, transaction, err_code);
+
+ int error = EM_STORAGE_ERROR_NONE;
+ int rc, ret = false;
+ char sql_query_string[QUERY_SIZE] = {0, };
+
+ sqlite3 *local_db_handle = em_storage_get_db_connection();
+
+ EM_STORAGE_START_WRITE_TRANSACTION(transaction, error);
+
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), "DELETE FROM mail_attachment_tbl");
+
+ if (account_id != ALL_ACCOUNT) /* '0' means all account */
+ SNPRINTF(sql_query_string + strlen(sql_query_string), sizeof(sql_query_string)-(strlen(sql_query_string)+1), " WHERE account_id = %d", account_id);
+
+ if (mbox) /* NULL means all mailbox_name */
+ SNPRINTF(sql_query_string + strlen(sql_query_string), sizeof(sql_query_string)-(strlen(sql_query_string)+1), " %s mailbox_name = '%s'", account_id != ALL_ACCOUNT ? "AND" : "WHERE", mbox);
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ ret = true;
+
+FINISH_OFF:
+ EM_STORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
+ _DISCONNECT_DB;
+
+ if (err_code != NULL)
+ *err_code = error;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+EXPORT_API int em_storage_free_attachment(emf_mail_attachment_tbl_t** attachment_tbl_list, int count, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("attachment_tbl_list[%p], count[%d], err_code[%p]", attachment_tbl_list, count, err_code);
+
+ if (count > 0) {
+ if ((attachment_tbl_list == NULL) || (*attachment_tbl_list == NULL)) {
+ EM_DEBUG_EXCEPTION(" attachment_tbl_list[%p], count[%d]", attachment_tbl_list, count);
+ if (err_code != NULL)
+ *err_code = EM_STORAGE_ERROR_INVALID_PARAM;
+ return false;
+ }
+
+ emf_mail_attachment_tbl_t* p = *attachment_tbl_list;
+ int i;
+
+ for (i = 0; i < count; i++) {
+ EM_SAFE_FREE(p[i].mailbox_name);
+ EM_SAFE_FREE(p[i].attachment_name);
+ EM_SAFE_FREE(p[i].attachment_path);
+#ifdef __ATTACHMENT_OPTI__
+ EM_SAFE_FREE(p[i].section);
+#endif
+ }
+
+ EM_SAFE_FREE(p);
+ *attachment_tbl_list = NULL;
+ }
+
+ if (err_code != NULL)
+ *err_code = EM_STORAGE_ERROR_NONE;
+ EM_DEBUG_FUNC_END();
+ return true;
+}
+
+
+
+EXPORT_API int em_storage_begin_transaction(void *d1, void *d2, int *err_code)
+{
+ EM_PROFILE_BEGIN(emStorageBeginTransaction);
+ int ret = true;
+
+ ENTER_CRITICAL_SECTION(_transactionBeginLock);
+
+ /* wait for the trnasaction authority to be changed. */
+ while (g_transaction) {
+ EM_DEBUG_LOG(">>>>>>>> Wait for the transaction authority to be changed");
+ usleep(50000);
+ }
+
+ /* take the transaction authority. */
+ g_transaction = true;
+
+ LEAVE_CRITICAL_SECTION(_transactionBeginLock);
+
+ sqlite3 *local_db_handle = em_storage_get_db_connection();
+ int rc;
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, "BEGIN immediate;", NULL, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {ret = false; },
+ ("SQL(BEGIN) exec error:%d -%s", rc, sqlite3_errmsg(local_db_handle)));
+ if (ret == false && err_code != NULL)
+ *err_code = EM_STORAGE_ERROR_DB_FAILURE;
+
+ EM_PROFILE_END(emStorageBeginTransaction);
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+EXPORT_API int em_storage_commit_transaction(void *d1, void *d2, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int ret = true;
+ sqlite3 *local_db_handle = em_storage_get_db_connection();
+
+ ENTER_CRITICAL_SECTION(_transactionEndLock);
+
+ int rc;
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, "END;", NULL, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {ret = false; }, ("SQL(END) exec error:%d -%s", rc, sqlite3_errmsg(local_db_handle)));
+ /* release the transaction authority. */
+ g_transaction = false;
+
+ LEAVE_CRITICAL_SECTION(_transactionEndLock);
+ if (ret == false && err_code != NULL)
+ *err_code = EM_STORAGE_ERROR_DB_FAILURE;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+EXPORT_API int em_storage_rollback_transaction(void *d1, void *d2, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int ret = true;
+ sqlite3 *local_db_handle = em_storage_get_db_connection();
+ int rc;
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, "ROLLBACK;", NULL, NULL, NULL), rc);
+
+ ENTER_CRITICAL_SECTION(_transactionEndLock);
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {ret = false; },
+ ("SQL(ROLLBACK) exec error:%d -%s", rc, sqlite3_errmsg(local_db_handle)));
+
+ /* release the transaction authority. */
+ g_transaction = false;
+
+ LEAVE_CRITICAL_SECTION(_transactionEndLock);
+
+ if (ret == false && err_code != NULL)
+ *err_code = EM_STORAGE_ERROR_DB_FAILURE;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+EXPORT_API int em_storage_is_mailbox_full(int account_id, emf_mailbox_t* mailbox_name, int *result, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("account_id[%d], mailbox_name[%p], result[%p], err_code[%p]", account_id, mailbox_name, result, err_code);
+
+ if (account_id < FIRST_ACCOUNT_ID || !mailbox_name || !result) {
+ if (mailbox_name)
+ EM_DEBUG_EXCEPTION("Invalid Parameter. accoun_id[%d], mailbox_name[%p]", account_id, mailbox_name);
+
+ if (err_code != NULL)
+ *err_code = EM_STORAGE_ERROR_INVALID_PARAM;
+
+ return false;
+ }
+
+ int ret = false;
+ int error = EM_STORAGE_ERROR_NONE;
+ int mail_count = 0;
+
+ if (!em_storage_get_mail_count(account_id, mailbox_name->name, &mail_count, NULL, true, &error)) {
+ EM_DEBUG_EXCEPTION("em_storage_get_mail_count failed [%d]", error);
+ goto FINISH_OFF;
+ }
+
+ if (mailbox_name) {
+ EM_DEBUG_LOG("mail_count[%d] mail_slot_size[%d]", mail_count, mailbox_name->mail_slot_size);
+ if (mail_count >= mailbox_name->mail_slot_size)
+ *result = true;
+ else
+ *result = false;
+
+ ret = true;
+ }
+
+ ret = true;
+FINISH_OFF:
+
+ if (err_code != NULL)
+ *err_code = error;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+EXPORT_API int em_storage_clear_mail_data(int transaction, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("transaction[%d], err_code[%p]", transaction, err_code);
+
+ int rc, ret = false;
+ int error = EM_STORAGE_ERROR_NONE;
+ char sql_query_string[QUERY_SIZE] = {0, };
+
+ const emf_db_object_t* tables = _g_db_tables;
+ const emf_db_object_t* indexes = _g_db_indexes;
+ char data_path[256];
+
+ sqlite3 *local_db_handle = em_storage_get_db_connection();
+ EM_STORAGE_START_WRITE_TRANSACTION(transaction, error);
+
+ if (!em_storage_delete_dir(MAILHOME, &error)) {
+ EM_DEBUG_EXCEPTION(" em_storage_delete_dir failed - %d", error);
+
+ goto FINISH_OFF;
+ }
+
+ SNPRINTF(data_path, sizeof(data_path), "%s/%s", MAILHOME, MAILTEMP);
+
+ mkdir(MAILHOME, DIRECTORY_PERMISSION);
+ mkdir(data_path, DIRECTORY_PERMISSION);
+
+ /* first clear index. */
+ while (indexes->object_name) {
+ if (indexes->data_flag) {
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), "DROP index %s", indexes->object_name);
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+ }
+ indexes++;
+ }
+
+ while (tables->object_name) {
+ if (tables->data_flag) {
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), "DROP table %s", tables->object_name);
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+ }
+
+ tables++;
+ }
+ ret = true;
+
+FINISH_OFF:
+ EM_STORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
+ _DISCONNECT_DB;
+
+ if (err_code != NULL)
+ *err_code = error;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+/*======================= DB File Utils =============================================*/
+#include <dirent.h>
+#include <sys/types.h>
+#define DIR_SEPERATOR "/"
+
+char *__em_create_dir_by_file_name(char *file_name)
+{
+ EM_DEBUG_FUNC_BEGIN("Filename [ %p ]", file_name);
+ char delims[] = "/";
+ char *result = NULL;
+
+ result = strtok(file_name, delims);
+
+ if (result)
+ EM_DEBUG_LOG(">>>> Directory_name [ %s ]", result);
+ else
+ EM_DEBUG_LOG(">>>> No Need to create Directory");
+
+ return result;
+}
+
+EXPORT_API int em_storage_get_save_name(int account_id, int mail_id, int atch_id, char *fname, char *name_buf, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("account_id[%d], mail_id[%d], atch_id[%d], fname[%s], name_buf[%p], err_code[%p]", account_id, mail_id, atch_id, fname, name_buf, err_code);
+ EM_PROFILE_BEGIN(profile_em_storage_get_save_name);
+
+ int ret = false;
+ int error = EM_STORAGE_ERROR_NONE;
+ char *dir_name = NULL;
+ char create_dir[1024]={0};
+ char *temp_file = NULL;
+
+ if (!name_buf || account_id < FIRST_ACCOUNT_ID || mail_id < 0 || atch_id < 0) {
+ EM_DEBUG_EXCEPTION(" account_id[%d], mail_id[%d], atch_id[%d], fname[%p], name_buf[%p]", account_id, mail_id, atch_id, fname, name_buf);
+ error = EM_STORAGE_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ sprintf(name_buf, "%s", MAILHOME);
+ sprintf(name_buf+strlen(name_buf), "%s%d", DIR_SEPERATOR, account_id);
+
+ if (mail_id > 0)
+ sprintf(name_buf+strlen(name_buf), "%s%d", DIR_SEPERATOR, mail_id);
+
+ if (atch_id > 0)
+ sprintf(name_buf+strlen(name_buf), "%s%d", DIR_SEPERATOR, atch_id);
+
+ if (fname) {
+ temp_file = EM_SAFE_STRDUP(fname);
+ if (strstr(temp_file, "/")) {
+ dir_name = __em_create_dir_by_file_name(temp_file);
+ }
+ }
+
+ if (dir_name) {
+ sprintf(create_dir, "%s%s%s", name_buf, DIR_SEPERATOR, dir_name);
+ EM_DEBUG_LOG(">>>>> DIR PATH [ %s ]", create_dir);
+ mkdir(create_dir, DIRECTORY_PERMISSION);
+ EM_SAFE_FREE(temp_file);
+ }
+
+
+ if (fname) {
+ EM_DEBUG_LOG(">>>>> fname [ %s ]", fname);
+ sprintf(name_buf+strlen(name_buf), "%s%s", DIR_SEPERATOR, fname);
+ }
+
+
+ EM_DEBUG_LOG(">>>>> name_buf [ %s ]", name_buf);
+
+ ret = true;
+
+FINISH_OFF:
+ EM_SAFE_FREE(temp_file);
+
+ if (err_code != NULL)
+ *err_code = error;
+
+ EM_PROFILE_END(profile_em_storage_get_save_name);
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+EXPORT_API int em_storage_get_dele_name(int account_id, int mail_id, int atch_id, char *fname, char *name_buf, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("account_id[%d], mail_id[%d], atch_id[%d], fname[%p], name_buf[%p], err_code[%p]", account_id, mail_id, atch_id, fname, name_buf, err_code);
+
+ if (!name_buf || account_id < FIRST_ACCOUNT_ID) {
+ EM_DEBUG_EXCEPTION(" account_id[%d], mail_id[%d], atch_id[%d], fname[%p], name_buf[%p]", account_id, mail_id, atch_id, fname, name_buf);
+ if (err_code != NULL)
+ *err_code = EM_STORAGE_ERROR_INVALID_PARAM;
+ return false;
+ }
+
+ sprintf(name_buf+strlen(name_buf), "%s%s%d", MAILHOME, DIR_SEPERATOR, account_id);
+
+ if (mail_id > 0)
+ sprintf(name_buf+strlen(name_buf), "%s%d", DIR_SEPERATOR, mail_id);
+ else
+ goto FINISH_OFF;
+
+ if (atch_id > 0)
+ sprintf(name_buf+strlen(name_buf), "%s%d", DIR_SEPERATOR, atch_id);
+ else
+ goto FINISH_OFF;
+
+FINISH_OFF:
+ sprintf(name_buf+strlen(name_buf), ".DELE");
+
+ EM_DEBUG_FUNC_END();
+ return true;
+}
+
+EXPORT_API int em_storage_create_dir(int account_id, int mail_id, int atch_id, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("account_id[%d], mail_id[%d], atch_id[%d], err_code[%p]", account_id, mail_id, atch_id, err_code);
+ EM_PROFILE_BEGIN(profile_em_core_save_create_dir);
+ int ret = false;
+ int error = EM_STORAGE_ERROR_NONE;
+
+ char buf[512];
+ struct stat sbuf;
+ if (account_id >= FIRST_ACCOUNT_ID) {
+ SNPRINTF(buf, sizeof(buf), "%s%s%d", MAILHOME, DIR_SEPERATOR, account_id);
+
+ if (stat(buf, &sbuf) == 0) {
+ if ((sbuf.st_mode & S_IFMT) != S_IFDIR) {
+ EM_DEBUG_EXCEPTION(" a object which isn't directory aleady exists");
+ error = EM_STORAGE_ERROR_SYSTEM_FAILURE;
+ goto FINISH_OFF;
+ }
+ }
+ else {
+ if (mkdir(buf, DIRECTORY_PERMISSION) != 0) {
+ EM_DEBUG_EXCEPTION(" mkdir failed [%s]", buf);
+ EM_DEBUG_EXCEPTION("mkdir failed l(Errno=%d)][ErrStr=%s]", errno, strerror(errno));
+ error = EM_STORAGE_ERROR_SYSTEM_FAILURE;
+ goto FINISH_OFF;
+ }
+ }
+ }
+
+ if (mail_id > 0) {
+ if (account_id < FIRST_ACCOUNT_ID) {
+ EM_DEBUG_EXCEPTION("account_id[%d], mail_id[%d], atch_id[%d]", account_id, mail_id, atch_id);
+ error = EM_STORAGE_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ SNPRINTF(buf+strlen(buf), sizeof(buf), "%s%d", DIR_SEPERATOR, mail_id);
+
+ if (stat(buf, &sbuf) == 0) {
+ if ((sbuf.st_mode & S_IFMT) != S_IFDIR) {
+ EM_DEBUG_EXCEPTION(" a object which isn't directory aleady exists");
+
+ error = EM_STORAGE_ERROR_SYSTEM_FAILURE;
+ goto FINISH_OFF;
+ }
+ }
+ else {
+ if (mkdir(buf, DIRECTORY_PERMISSION) != 0) {
+ EM_DEBUG_EXCEPTION(" mkdir failed [%s]", buf);
+ EM_DEBUG_EXCEPTION("mkdir failed l (Errno=%d)][ErrStr=%s]", errno, strerror(errno));
+ error = EM_STORAGE_ERROR_SYSTEM_FAILURE;
+ goto FINISH_OFF;
+ }
+ }
+ }
+
+ if (atch_id > 0) {
+ if (account_id < FIRST_ACCOUNT_ID || mail_id <= 0) {
+ EM_DEBUG_EXCEPTION(" account_id[%d], mail_id[%d], atch_id[%d]", account_id, mail_id, atch_id);
+
+ error = EM_STORAGE_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ SNPRINTF(buf+strlen(buf), sizeof(buf)-(strlen(buf)+1), "%s%d", DIR_SEPERATOR, atch_id);
+
+ if (stat(buf, &sbuf) == 0) {
+ if ((sbuf.st_mode & S_IFMT) != S_IFDIR) {
+ EM_DEBUG_EXCEPTION(" a object which isn't directory aleady exists");
+
+ error = EM_STORAGE_ERROR_SYSTEM_FAILURE;
+ goto FINISH_OFF;
+ }
+ }
+ else {
+ if (mkdir(buf, DIRECTORY_PERMISSION) != 0) {
+ EM_DEBUG_EXCEPTION(" mkdir failed [%s]", buf);
+ error = EM_STORAGE_ERROR_SYSTEM_FAILURE;
+ goto FINISH_OFF;
+ }
+ }
+ }
+
+ ret = true;
+
+FINISH_OFF:
+ if (err_code != NULL)
+ *err_code = error;
+
+ EM_PROFILE_END(profile_em_core_save_create_dir);
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+EXPORT_API int em_storage_copy_file(char *src_file, char *dst_file, int sync_status, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("src_file[%s], dst_file[%s], err_code[%p]", src_file, dst_file, err_code);
+ EM_DEBUG_LOG("Using the fsync function");
+ int ret = false;
+ int error = EM_STORAGE_ERROR_NONE;
+ struct stat st_buf;
+
+ int fp_src = 0;
+ int fp_dst = 0;
+ int nread = 0;
+ int nwritten = 0;
+ char *buf = NULL;
+ int buf_size = 0;
+
+ if (!src_file || !dst_file) {
+ EM_DEBUG_EXCEPTION("src_file[%p], dst_file[%p]", src_file, dst_file);
+
+ error = EM_STORAGE_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ if (stat(src_file, &st_buf) < 0) {
+ EM_DEBUG_EXCEPTION("stat(\"%s\") failed...", src_file);
+
+ error = EM_STORAGE_ERROR_SYSTEM_FAILURE; /* EMF_ERROR_INVALID_PATH; */
+ goto FINISH_OFF;
+ }
+
+ buf_size = st_buf.st_size;
+ EM_DEBUG_LOG(">>>> File Size [ %d ]", buf_size);
+ buf = (char *)calloc(1, buf_size+1);
+
+ if (!buf) {
+ EM_DEBUG_EXCEPTION(">>> Memory cannot be allocated");
+ error = EM_STORAGE_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ if (buf) {
+ if (!(fp_src = open(src_file, O_RDONLY))) {
+ EM_DEBUG_EXCEPTION(">>>> Source Fail open %s Failed [ %d ] - Error [ %s ]", src_file, errno, strerror(errno));
+ error = EM_STORAGE_ERROR_SYSTEM_FAILURE;
+ goto FINISH_OFF;
+ }
+
+ if (!(fp_dst = open(dst_file, O_CREAT | O_WRONLY, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH))) {
+ EM_DEBUG_EXCEPTION(">>>> Destination Fail open %s Failed [ %d ] - Error [ %s ]", dst_file, errno, strerror(errno));
+ error = EM_STORAGE_ERROR_SYSTEM_FAILURE;
+ goto FINISH_OFF;
+ }
+
+ while ((nread = read(fp_src, buf, buf_size)) > 0) {
+ if (nread > 0 && nread <= buf_size) {
+ EM_DEBUG_LOG("Nread Value [%d]", nread);
+ if ((nwritten = write(fp_dst, buf, nread)) != nread) {
+ EM_DEBUG_EXCEPTION("fwrite failed...");
+ error = EM_STORAGE_ERROR_UNKNOWN;
+ goto FINISH_OFF;
+ }
+ EM_DEBUG_LOG("NWRITTEN [%d]", nwritten);
+ }
+ }
+ }
+
+ ret = true;
+
+FINISH_OFF:
+ if (fp_src)
+ close(fp_src);
+
+ if (fp_dst) {
+ if (sync_status) {
+ EM_DEBUG_LOG("Before fsync");
+ fsync(fp_dst);
+ }
+ close(fp_dst);
+ }
+ EM_SAFE_FREE(buf);
+ if (nread < 0 || error == EM_STORAGE_ERROR_UNKNOWN)
+ remove(dst_file);
+
+ if (err_code != NULL)
+ *err_code = error;
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+/* create Directory if user has deleted [deepam.p@samsung.com] */
+EXPORT_API void em_storage_create_dir_if_delete()
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ mkdir(EMAILPATH, DIRECTORY_PERMISSION);
+ mkdir(DATA_PATH, DIRECTORY_PERMISSION);
+
+ mkdir(MAILHOME, DIRECTORY_PERMISSION);
+
+ SNPRINTF(g_db_path, sizeof(g_db_path), "%s/%s", MAILHOME, MAILTEMP);
+ mkdir(g_db_path, DIRECTORY_PERMISSION);
+
+ /* _emf_delete_temp_file(g_db_path); */
+ EM_DEBUG_FUNC_END();
+}
+static
+int em_storage_get_temp_file_name(char **filename, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("filename[%p], err_code[%p]", filename, err_code);
+
+ int ret = false;
+ int error = EMF_ERROR_NONE;
+
+ if (filename == NULL) {
+ EM_DEBUG_EXCEPTION(" filename[%p]", filename);
+ error = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ char tempname[512] = {0x00, };
+ struct timeval tv;
+
+ gettimeofday(&tv, NULL);
+ srand(tv.tv_usec);
+
+ SNPRINTF(tempname, sizeof(tempname), "%s%c%s%c%d", MAILHOME, '/', MAILTEMP, '/', rand());
+
+ char *p = EM_SAFE_STRDUP(tempname);
+ if (p == NULL) {
+ EM_DEBUG_EXCEPTION(" strdup failed...");
+ error = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ *filename = p;
+
+ ret = true;
+
+FINISH_OFF:
+ if (err_code != NULL)
+ *err_code = error;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+EXPORT_API int em_storage_add_content_type(char *file_path, char *char_set, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("File path [ %p ] Character Set [ %p ] err_code [ %p]", file_path, char_set, err_code);
+
+ EM_IF_NULL_RETURN_VALUE(file_path, false);
+ EM_IF_NULL_RETURN_VALUE(char_set, false);
+ EM_IF_NULL_RETURN_VALUE(err_code, false);
+
+ char *buf = NULL;
+ char *buf1 = NULL;
+ struct stat st_buf;
+ int buf_size = 0;
+ char *low_char_set = NULL;
+ char *match_str = NULL;
+ int nwritten = 0;
+ int ret = false;
+ int error = EM_STORAGE_ERROR_NONE;
+ int data_count_to_written = 0;
+ char *temp_file_name = NULL;
+ int err = 0;
+
+ FILE* fp_src = NULL;
+ FILE* fp_dest = NULL;
+ int nread = 0;
+
+
+ if (stat(file_path, &st_buf) < 0) {
+ EM_DEBUG_EXCEPTION(" stat(\"%s\") failed...", file_path);
+
+ error = EM_STORAGE_ERROR_SYSTEM_FAILURE; /* EMF_ERROR_INVALID_PATH; */
+ goto FINISH_OFF;
+ }
+
+ buf_size = st_buf.st_size;
+
+ EM_DEBUG_LOG(">>>> File Size [ %d ] ", buf_size);
+
+ buf = (char *)calloc(1, buf_size+1);
+
+ if (!buf) {
+ EM_DEBUG_LOG(">>> Memory cannot be allocated ");
+ goto FINISH_OFF;
+ }
+
+ if (!(fp_src = fopen(file_path, "rb"))) {
+ EM_DEBUG_EXCEPTION(" file_path fopen failed - %s", file_path);
+
+ error = EM_STORAGE_ERROR_SYSTEM_FAILURE;
+ goto FINISH_OFF; /* 20080509 prevent 28806 - forward null */
+ }
+
+ if ((nread = fread(buf, 1, buf_size, fp_src)) > 0) {
+ if (nread > 0 && nread <= buf_size) {
+ EM_DEBUG_LOG(">>>> Nread Value [ %d ] ", nread);
+
+ /**
+ * 1.Add check for whether content type is there.
+ * 2. If not based on the character set, Append it in File
+ **/
+
+ low_char_set = calloc(1, strlen(char_set) + strlen(" \" /></head>") +1);
+
+ strncat(low_char_set, char_set, strlen(char_set));
+
+ EM_DEBUG_LOG(">>>> CHAR SET [ %s ] ", low_char_set);
+
+ strncat(low_char_set, " \" /></head>", strlen(" \" /></head>"));
+
+ EM_DEBUG_LOG(">>> CHARSET [ %s ] ", low_char_set);
+
+ EM_DEBUG_LOG(">>>>em_storage_add_content_type 1 ");
+
+ match_str = strstr(buf, CONTENT_TYPE_DATA);
+ EM_DEBUG_LOG(">>>>em_storage_add_content_type 2 ");
+
+ if (match_str == NULL) {
+ EM_DEBUG_LOG(">>>>em_storage_add_content_type 3 ");
+ if (fp_src !=NULL) {
+ fclose(fp_src);fp_src = NULL;
+ }
+ data_count_to_written = strlen(low_char_set)+strlen(CONTENT_DATA)+1;
+ EM_DEBUG_LOG(">>>>em_storage_add_content_type 4 ");
+ buf1 = (char *)calloc(1, data_count_to_written);
+ EM_DEBUG_LOG(">>>>em_storage_add_content_type 5 ");
+
+ if (buf1) {
+ EM_DEBUG_LOG(">>>>em_storage_add_content_type 6 ");
+ strncat(buf1, CONTENT_DATA, strlen(CONTENT_DATA));
+
+ EM_DEBUG_LOG(">>>>> BUF 1 [ %s ] ", buf1);
+
+ strncat(buf1, low_char_set, strlen(low_char_set));
+
+ EM_DEBUG_LOG(">>>> HTML TAG DATA [ %s ] ", buf1);
+
+
+ /* 1. Create a temporary file name */
+ if (!em_storage_get_temp_file_name(&temp_file_name, &err)) {
+ EM_DEBUG_EXCEPTION(" em_core_get_temp_file_name failed - %d", err);
+ if (err_code != NULL) *err_code = err;
+ EM_SAFE_FREE(temp_file_name);
+ goto FINISH_OFF;
+ }
+ EM_DEBUG_LOG(">>>>>>> TEMP APPEND FILE PATH [ %s ] ", temp_file_name);
+
+ /* Open the Temp file in Append mode */
+ if (!(fp_dest = fopen(temp_file_name, "ab"))) {
+ EM_DEBUG_EXCEPTION(" fopen failed - %s", temp_file_name);
+ error = EM_STORAGE_ERROR_SYSTEM_FAILURE;
+ goto FINISH_OFF; /* 20080509 prevent 28806 - forward null */
+ }
+
+ /* 2. write the Latest data */
+ nwritten = fwrite(buf1, data_count_to_written-1, 1, fp_dest);
+
+ if (nwritten > 0) {
+ EM_DEBUG_LOG(" Latest Data : [%d ] bytes written ", nwritten);
+ nwritten = 0;
+ /* 3. Append old data */
+ nwritten = fwrite(buf, nread-1, 1, fp_dest);
+
+ if (nwritten <= 0) {
+ EM_DEBUG_EXCEPTION(" Error Occured while writing Old data : [%d ] bytes written ", nwritten);
+ error = EM_STORAGE_ERROR_SYSTEM_FAILURE;
+ goto FINISH_OFF;
+ }
+ else {
+ EM_DEBUG_LOG(">>>> OLD data appended [ %d ] ", nwritten);
+
+ if (!em_storage_move_file(temp_file_name, file_path, false, &err)) {
+ EM_DEBUG_EXCEPTION(" em_storage_move_file failed - %d", err);
+ goto FINISH_OFF;
+ }
+ }
+
+ }
+ else {
+ EM_DEBUG_EXCEPTION(" Error Occured while writing New data : [%d ] bytes written ", nwritten);
+ error = EM_STORAGE_ERROR_SYSTEM_FAILURE;
+ goto FINISH_OFF;
+ }
+
+ }
+
+ }
+ EM_DEBUG_LOG(">>>>em_storage_add_content_type 15 ");
+
+
+ }
+ }
+
+ ret = true;
+FINISH_OFF:
+
+ EM_SAFE_FREE(buf);
+ EM_SAFE_FREE(buf1);
+ EM_SAFE_FREE(low_char_set);
+
+ if (fp_src != NULL) {
+ fclose(fp_src);
+ fp_src = NULL;
+ }
+
+ if (fp_dest != NULL) {
+ fclose(fp_dest);
+ fp_dest = NULL;
+ }
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+
+}
+
+EXPORT_API int em_storage_move_file(char *src_file, char *dst_file, int sync_status, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("src_file[%p], dst_file[%p], err_code[%p]", src_file, dst_file, err_code);
+
+ int ret = false;
+ int error = EM_STORAGE_ERROR_NONE;
+
+ if (src_file == NULL || dst_file == NULL) {
+ EM_DEBUG_EXCEPTION("src_file[%p], dst_file[%p]", src_file, dst_file);
+ error = EM_STORAGE_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ EM_DEBUG_LOG("src_file[%s], dst_file[%s]", src_file, dst_file);
+
+ if (strcmp(src_file, dst_file) != 0) {
+ if (rename(src_file, dst_file) != 0) {
+ if (errno == EXDEV) { /* oldpath and newpath are not on the same mounted file system. (Linux permits a file system to be mounted at multiple points, but rename() */
+ /* does not work across different mount points, even if the same file system is mounted on both.) */
+ EM_DEBUG_LOG("oldpath and newpath are not on the same mounted file system.");
+ if (!em_storage_copy_file(src_file, dst_file, sync_status, &error)) {
+ EM_DEBUG_EXCEPTION("em_storage_copy_file failed - %d", error);
+ goto FINISH_OFF;
+ }
+ remove(src_file);
+ EM_DEBUG_LOG("src[%s] removed", src_file);
+
+ }
+ else {
+ if (errno == ENOENT) {
+ struct stat temp_file_stat;
+ if (stat(src_file, &temp_file_stat) < 0)
+ EM_DEBUG_EXCEPTION("no src file found [%s]", src_file);
+ if (stat(dst_file, &temp_file_stat) < 0)
+ EM_DEBUG_EXCEPTION("no dst file found [%s]", src_file);
+
+ EM_DEBUG_EXCEPTION("no file found [%d]", errno);
+ error = EM_STORAGE_ERROR_FILE_NOT_FOUND;
+ goto FINISH_OFF;
+
+ }
+ else {
+ EM_DEBUG_EXCEPTION("rename failed [%d]", errno);
+ error = EM_STORAGE_ERROR_SYSTEM_FAILURE;
+ goto FINISH_OFF;
+ }
+ }
+ }
+ }
+ else {
+ EM_DEBUG_LOG("src[%s] = dst[%d]", src_file, dst_file);
+ }
+
+ ret = true;
+
+FINISH_OFF:
+ if (err_code != NULL)
+ *err_code = error;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+EXPORT_API int em_storage_delete_file(char *src_file, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("src_file[%p], err_code[%p]", src_file, err_code);
+
+ int ret = false;
+ int error = EM_STORAGE_ERROR_NONE;
+
+ if (src_file == NULL) {
+ EM_DEBUG_EXCEPTION(" src_file[%p]", src_file);
+
+ error = EM_STORAGE_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ if (remove(src_file) != 0) {
+ if (errno != ENOENT) {
+ EM_DEBUG_EXCEPTION(" remove failed - %d", errno);
+
+ error = EM_STORAGE_ERROR_SYSTEM_FAILURE;
+ goto FINISH_OFF;
+ }
+ else {
+ EM_DEBUG_EXCEPTION(" no file found...");
+
+ error = EM_STORAGE_ERROR_FILE_NOT_FOUND;
+ }
+ }
+
+ ret = true;
+
+FINISH_OFF:
+ if (err_code != NULL)
+ *err_code = error;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+
+EXPORT_API int em_storage_delete_dir(char *src_dir, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("src_dir[%p], err_code[%p]", src_dir, err_code);
+
+ if (src_dir == NULL) {
+ EM_DEBUG_EXCEPTION(" src_dir[%p]", src_dir);
+
+ if (err_code != NULL)
+ *err_code = EM_STORAGE_ERROR_INVALID_PARAM;
+ return false;
+ }
+
+ int error = EM_STORAGE_ERROR_NONE;
+
+ DIR *dirp;
+ struct dirent *dp;
+ struct stat sbuf;
+ char buf[512];
+
+ dirp = opendir(src_dir);
+
+ if (dirp == NULL) {
+ if (errno == ENOENT) {
+ EM_DEBUG_EXCEPTION("directory[%s] does not exist...", src_dir);
+ if (err_code != NULL)
+ *err_code = EM_STORAGE_ERROR_SYSTEM_FAILURE;
+ return true;
+ }
+ else {
+ EM_DEBUG_EXCEPTION("opendir failed - %d", errno);
+ if (err_code != NULL)
+ *err_code = EM_STORAGE_ERROR_SYSTEM_FAILURE;
+ return false;
+ }
+ }
+
+ while ((dp=readdir(dirp))) {
+ if (strncmp(dp->d_name, ".", strlen(".")) == 0 || strncmp(dp->d_name, "..", strlen("..")) == 0)
+ continue;
+
+ SNPRINTF(buf, sizeof(buf), "%s/%s", src_dir, dp->d_name);
+
+ if (lstat(buf, &sbuf) == 0 || stat(buf, &sbuf) == 0) {
+ /* check directory */
+ if ((sbuf.st_mode & S_IFMT) == S_IFDIR) { /* directory */
+ /* recursive call */
+ if (!em_storage_delete_dir(buf, &error)) {
+ closedir(dirp);
+ if (err_code != NULL)
+ *err_code = error;
+ return false;
+ }
+ }
+ else { /* file */
+ if (remove(buf) < 0) {
+ EM_DEBUG_EXCEPTION("remove failed - %s", buf);
+ closedir(dirp);
+ if (err_code != NULL)
+ *err_code = EM_STORAGE_ERROR_SYSTEM_FAILURE;
+ return false;
+ }
+ }
+ }
+ else
+ EM_DEBUG_EXCEPTION("content does not exist...");
+ }
+
+ closedir(dirp);
+
+ EM_DEBUG_LOG("remove direcotory [%s]", src_dir);
+
+ /* EM_DEBUG_FUNC_BEGIN(); */
+
+ if (remove(src_dir) < 0) {
+ EM_DEBUG_EXCEPTION("remove failed [%s]", src_dir);
+ if (err_code != NULL)
+ *err_code = EM_STORAGE_ERROR_SYSTEM_FAILURE;
+ return false;
+ }
+
+ if (err_code != NULL)
+ *err_code = error;
+
+ return true;
+}
+
+/* faizan.h@samsung.com */
+EXPORT_API int em_storage_update_server_uid(char *old_server_uid, char *new_server_uid, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("new_server_uid[%s], old_server_uid[%s]", new_server_uid, old_server_uid);
+ int rc, ret = false;
+ int error = EM_STORAGE_ERROR_NONE;
+ char sql_query_string[QUERY_SIZE] = {0, };
+
+ int transaction = true;
+
+ if (!old_server_uid || !new_server_uid) {
+ EM_DEBUG_EXCEPTION("Invalid parameters");
+ error = EM_STORAGE_ERROR_INVALID_PARAM;
+ return false;
+ }
+ sqlite3 *local_db_handle = em_storage_get_db_connection();
+
+ EM_STORAGE_START_WRITE_TRANSACTION(transaction, error);
+
+ SNPRINTF(sql_query_string, sizeof(sql_query_string),
+ "UPDATE mail_tbl SET server_mail_id=\'%s\' WHERE server_mail_id=%s ", new_server_uid, old_server_uid);
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
+
+ EM_DEBUG_DB_EXEC((SQLITE_FULL == rc), {error = EM_STORAGE_ERROR_DB_IS_FULL;goto FINISH_OFF; },
+ ("sqlite3_exec fail:%d", rc));
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ ret = true;
+
+FINISH_OFF:
+ EM_STORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
+ _DISCONNECT_DB;
+
+ if (err_code != NULL)
+ *err_code = error;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+
+}
+
+EXPORT_API int em_storage_update_read_mail_uid(int mail_id, char *new_server_uid, char *mbox_name, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("mail_id[%d], new_server_uid[%s], mbox_name[%s]", mail_id, new_server_uid, mbox_name);
+
+ int rc, ret = false;
+ int error = EM_STORAGE_ERROR_NONE;
+ char sql_query_string[QUERY_SIZE] = {0, };
+
+ int transaction = true;
+
+ if (!mail_id || !new_server_uid || !mbox_name) {
+ EM_DEBUG_EXCEPTION("Invalid parameters");
+ error = EM_STORAGE_ERROR_INVALID_PARAM;
+ return false;
+ }
+ sqlite3 *local_db_handle = em_storage_get_db_connection();
+ EM_STORAGE_START_WRITE_TRANSACTION(transaction, error);
+
+
+ SNPRINTF(sql_query_string, sizeof(sql_query_string),
+ "UPDATE mail_read_mail_uid_tbl SET s_uid=\'%s\', local_mbox=\'%s\', mailbox_name=\'%s\' WHERE local_uid=%d ", new_server_uid, mbox_name, mbox_name, mail_id);
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+ ret = true;
+
+FINISH_OFF:
+
+ EM_STORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
+ _DISCONNECT_DB;
+
+ if (err_code != NULL)
+ *err_code = error;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+
+}
+
+
+int em_storage_get_latest_unread_mailid(int account_id, int *mail_id, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ if ((!mail_id) ||(account_id <= 0 && account_id != -1)) {
+ EM_DEBUG_EXCEPTION(" mail_id[%p], account_id[%d] ", mail_id, account_id);
+ if (err_code != NULL)
+ *err_code = EM_STORAGE_ERROR_INVALID_PARAM;
+ return false;
+ }
+
+ int ret = false;
+ int rc = -1;
+ int error = EM_STORAGE_ERROR_NONE;
+ DB_STMT hStmt = NULL;
+ int count = 0;
+ int mailid = 0;
+ int transaction = false;
+ char sql_query_string[QUERY_SIZE] = {0, };
+
+ sqlite3 *local_db_handle = em_storage_get_db_connection();
+ EM_STORAGE_START_READ_TRANSACTION(transaction);
+
+ memset(sql_query_string, 0x00, sizeof(sql_query_string));
+
+ if (account_id == -1)
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT mail_id FROM mail_tbl WHERE flags_seen_field = 0 ORDER BY mail_id DESC");
+ else
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT mail_id FROM mail_tbl WHERE account_id = %d AND flags_seen_field = 0 ORDER BY mail_id DESC", account_id);
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
+ EM_DEBUG_LOG(" sqlite3_prepare hStmt = %p", hStmt);
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
+ EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("sqlite3_step fail:%d", rc));
+
+ char **result;
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, &count, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EM_STORAGE_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+ ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ sqlite3_free_table(result);
+ if (count == 0) {
+ EM_DEBUG_EXCEPTION("no Mails found...");
+ ret = false;
+ error= EM_STORAGE_ERROR_MAIL_NOT_FOUND;
+ goto FINISH_OFF;
+ }
+
+ _getStmtFieldDataInt(hStmt, &mailid, 0);
+
+ ret = true;
+
+FINISH_OFF:
+ if (hStmt != NULL) {
+ EM_DEBUG_LOG("Before sqlite3_finalize hStmt = %p", hStmt);
+
+ rc = sqlite3_finalize(hStmt);
+ if (rc != SQLITE_OK) {
+ EM_DEBUG_EXCEPTION("sqlite3_finalize failed - %d", rc);
+
+ error = EM_STORAGE_ERROR_DB_FAILURE;
+ }
+ }
+ EM_STORAGE_FINISH_READ_TRANSACTION(transaction);
+ _DISCONNECT_DB;
+
+ if (err_code != NULL)
+ *err_code = error;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+int setting_system_command(const char *command)
+
+ {
+ int pid = 0, status = 0;
+ char *const environ[] = { NULL };
+
+ if (command == 0)
+ return 1;
+
+ pid = fork();
+
+ if (pid == -1)
+ return -1;
+
+ if (pid == 0) {
+ char *argv[4];
+
+ argv[0] = "sh";
+ argv[1] = "-c";
+ argv[2] = (char *)command;
+ argv[3] = 0;
+
+ execve("/bin/sh", argv, environ);
+ abort();
+ }
+ do{
+ if (waitpid(pid, &status, 0) == -1) {
+ if (errno != EINTR)
+ return -1;
+ }
+ else {
+ return status;
+ }
+ } while (1);
+
+ return 0;
+}
+
+
+EXPORT_API int em_storage_mail_get_total_diskspace_usage(unsigned long *total_usage, int transaction, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("total_usage[%p], transaction[%d], err_code[%p]", total_usage, transaction, err_code);
+
+ if (!total_usage) {
+ EM_DEBUG_EXCEPTION("total_usage[%p]", total_usage);
+
+ if (err_code != NULL)
+ *err_code = EM_STORAGE_ERROR_INVALID_PARAM;
+ return false;
+ }
+
+ int ret = false;
+ int error = EM_STORAGE_ERROR_NONE;
+ char syscmd[256] = {0};
+ FILE *fp = NULL;
+ unsigned long total_diskusage = 0;
+
+ SNPRINTF(syscmd, sizeof(syscmd), "touch %s", SETTING_MEMORY_TEMP_FILE_PATH);
+ if (setting_system_command(syscmd) == -1) {
+ EM_DEBUG_EXCEPTION("em_storage_mail_get_total_diskspace_usage : [Setting > Memory] System Command [%s] is failed", syscmd);
+
+ error = EM_STORAGE_ERROR_SYSTEM_FAILURE;
+ goto FINISH_OFF;
+ }
+
+ memset(syscmd, 0, sizeof(syscmd));
+ SNPRINTF(syscmd, sizeof(syscmd), "du -hsk %s > %s", EMAILPATH, SETTING_MEMORY_TEMP_FILE_PATH);
+ EM_DEBUG_LOG(" cmd : %s", syscmd);
+ if (setting_system_command(syscmd) == -1) {
+ EM_DEBUG_EXCEPTION("em_storage_mail_get_total_diskspace_usage : Setting > Memory] System Command [%s] is failed", syscmd);
+
+ error = EM_STORAGE_ERROR_SYSTEM_FAILURE;
+ goto FINISH_OFF;
+ }
+
+ fp = fopen(SETTING_MEMORY_TEMP_FILE_PATH, "r");
+ if (fp == NULL) {
+ perror(SETTING_MEMORY_TEMP_FILE_PATH);
+
+ error = EM_STORAGE_ERROR_SYSTEM_FAILURE;
+ goto FINISH_OFF;
+ }
+
+ char line[256] = {0};
+ fgets(line, sizeof(line), fp);
+ total_diskusage = strtoul(line, NULL, 10);
+
+ fclose(fp);
+
+ memset(syscmd, 0, sizeof(syscmd));
+ SNPRINTF(syscmd, sizeof(syscmd), "rm -f %s", SETTING_MEMORY_TEMP_FILE_PATH);
+ if (setting_system_command(syscmd) == -1)
+ {
+ EM_DEBUG_EXCEPTION("em_storage_mail_get_total_diskspace_usage : [Setting > Memory] System Command [%s] is failed", syscmd);
+
+ error = EM_STORAGE_ERROR_SYSTEM_FAILURE;
+ goto FINISH_OFF;
+ }
+
+ EM_DEBUG_LOG("[Setting > Memory] @@@@@ Size of Directory [%s] is %ld KB", EMAILPATH, total_diskusage);
+
+ ret = true;
+
+FINISH_OFF:
+ if (err_code != NULL)
+ *err_code = error;
+
+ if (ret)
+ *total_usage = total_diskusage;
+ else
+ *total_usage = 0;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+
+EXPORT_API int em_storage_test(int mail_id, int account_id, char *full_address_to, char *full_address_cc, char *full_address_bcc, int *err_code)
+{
+ DB_STMT hStmt = NULL;
+ int ret = false;
+ int error = EM_STORAGE_ERROR_NONE;
+ int rc = 0;
+ char sql_query_string[QUERY_SIZE] = {0, };
+
+ SNPRINTF(sql_query_string, sizeof(sql_query_string),
+ "INSERT INTO mail_tbl VALUES "
+ "( ?" /* mail_id */
+ ", ?" /* account_id */
+ ", ?" /* mailbox_name */
+ ", ?" /* mail_size */
+ ", ?" /* server_mail_status */
+ ", ?" /* server_mailbox_name */
+ ", ?" /* server_mail_id */
+ ", ?" /* full_address_from */
+ ", ?" /* full_address_reply */
+ ", ?" /* full_address_to */
+ ", ?" /* full_address_cc */
+ ", ?" /* full_address_bcc */
+ ", ?" /* full_address_return */
+ ", ?" /* subject */
+ ", ?" /* body_download_status */
+ ", ?" /* file_path_plain */
+ ", ?" /* file_path_html */
+ ", ?" /* date_time */
+ ", ?" /* flags_seen_field */
+ ", ?" /* flags_deleted_field */
+ ", ?" /* flags_flagged_field */
+ ", ?" /* flags_answered_field */
+ ", ?" /* flags_recent_field */
+ ", ?" /* flags_draft_field */
+ ", ?" /* flags_forwarded_field */
+ ", ?" /* DRM_status */
+ ", ?" /* priority */
+ ", ?" /* save_status */
+ ", ?" /* lock_status */
+ ", ?" /* message_id */
+ ", ?" /* report_status */
+ ", ?" /* email_address_sender */
+ ", ?" /* email_address_recipient */
+ ", ?" /* attachment_count */
+ ", ?" /* inline_content_count */
+ ", ?" /* preview_text */
+ ", ?" /* thread_id */
+ ", ?" /* mailbox_type */
+ ", ?" /* alias_sender */
+ ", ?" /* alias_recipient */
+ ", ?" /* thread_item_count */
+ ", ?" /* meeting_request_status */
+ ")");
+
+ int transaction = true;
+ sqlite3 *local_db_handle = em_storage_get_db_connection();
+
+ EM_STORAGE_START_WRITE_TRANSACTION(transaction, error);
+
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ _bindStmtFieldDataInt(hStmt, MAIL_ID_IDX_IN_MAIL_TBL, mail_id);
+ _bindStmtFieldDataInt(hStmt, ACCOUNT_ID_IDX_IN_MAIL_TBL, account_id);
+ _bindStmtFieldDataString(hStmt, MAILBOX_NAME_IDX_IN_MAIL_TBL, "OUTBOX", 0, MAILBOX_LEN_IN_MAIL_TBL);
+ _bindStmtFieldDataInt(hStmt, MAILBOX_TYPE_IDX_IN_MAIL_TBL, EMF_MAILBOX_TYPE_OUTBOX);
+ _bindStmtFieldDataString(hStmt, SUBJECT_IDX_IN_MAIL_TBL, "save test - long", 1, SUBJECT_LEN_IN_MAIL_TBL);
+ _bindStmtFieldDataString(hStmt, DATETIME_IDX_IN_MAIL_TBL, "20100316052908", 0, DATETIME_LEN_IN_MAIL_TBL);
+ _bindStmtFieldDataInt(hStmt, SERVER_MAIL_STATUS_IDX_IN_MAIL_TBL, 0);
+ _bindStmtFieldDataString(hStmt, SERVER_MAILBOX_NAME_IDX_IN_MAIL_TBL, "", 0, SERVER_MAILBOX_LEN_IN_MAIL_TBL);
+ _bindStmtFieldDataString(hStmt, SERVER_MAIL_ID_IDX_IN_MAIL_TBL, "", 0, SERVER_MAIL_ID_LEN_IN_MAIL_TBL);
+ _bindStmtFieldDataString(hStmt, MESSAGE_ID_IDX_IN_MAIL_TBL, "", 0, MESSAGE_ID_LEN_IN_MAIL_TBL);
+ _bindStmtFieldDataString(hStmt, FULL_ADDRESS_FROM_IDX_IN_MAIL_TBL, "<test08@streaming.s3glab.net>", 1, FROM_LEN_IN_MAIL_TBL);
+ _bindStmtFieldDataString(hStmt, FULL_ADDRESS_REPLY_IDX_IN_MAIL_TBL, "", 1, REPLY_TO_LEN_IN_MAIL_TBL);
+ _bindStmtFieldDataString(hStmt, FULL_ADDRESS_TO_IDX_IN_MAIL_TBL, full_address_to, 1, TO_LEN_IN_MAIL_TBL);
+ _bindStmtFieldDataString(hStmt, FULL_ADDRESS_CC_IDX_IN_MAIL_TBL, full_address_cc, 1, CC_LEN_IN_MAIL_TBL);
+ _bindStmtFieldDataString(hStmt, FULL_ADDRESS_BCC_IDX_IN_MAIL_TBL, full_address_bcc, 1, BCC_LEN_IN_MAIL_TBL);
+ _bindStmtFieldDataString(hStmt, FULL_ADDRESS_RETURN_IDX_IN_MAIL_TBL, "", 1, RETURN_PATH_LEN_IN_MAIL_TBL);
+ _bindStmtFieldDataString(hStmt, EMAIL_ADDRESS_SENDER_IDX_IN_MAIL_TBL, "<sender_name@sender_host.com>", 1, FROM_EMAIL_ADDRESS_LEN_IN_MAIL_TBL);
+ _bindStmtFieldDataString(hStmt, EMAIL_ADDRESS_RECIPIENT_IDX_IN_MAIL_TBL, "<recipient_name@recipient_host.com>", 1, TO_EMAIL_ADDRESS_LEN_IN_MAIL_TBL);
+ _bindStmtFieldDataString(hStmt, ALIAS_SENDER_IDX_IN_MAIL_TBL, "send_alias", 1, FROM_EMAIL_ADDRESS_LEN_IN_MAIL_TBL);
+ _bindStmtFieldDataString(hStmt, ALIAS_RECIPIENT_IDX_IN_MAIL_TBL, "recipient_alias", 1, TO_EMAIL_ADDRESS_LEN_IN_MAIL_TBL);
+ _bindStmtFieldDataInt(hStmt, BODY_DOWNLOAD_STATUS_IDX_IN_MAIL_TBL, 1);
+ _bindStmtFieldDataString(hStmt, FILE_PATH_PLAIN_IDX_IN_MAIL_TBL, "/opt/system/rsr/email/.emfdata/7/348/UTF-8", 0, TEXT_1_LEN_IN_MAIL_TBL);
+ _bindStmtFieldDataString(hStmt, FILE_PATH_HTML_IDX_IN_MAIL_TBL, "", 0, TEXT_2_LEN_IN_MAIL_TBL);
+ _bindStmtFieldDataInt(hStmt, MAIL_SIZE_IDX_IN_MAIL_TBL, 4);
+ _bindStmtFieldDataChar(hStmt, FLAGS_SEEN_FIELD_IDX_IN_MAIL_TBL, 0);
+ _bindStmtFieldDataChar(hStmt, FLAGS_DELETED_FIELD_IDX_IN_MAIL_TBL, 0);
+ _bindStmtFieldDataChar(hStmt, FLAGS_FLAGGED_FIELD_IDX_IN_MAIL_TBL, 0);
+ _bindStmtFieldDataChar(hStmt, FLAGS_ANSWERED_FIELD_IDX_IN_MAIL_TBL, 0);
+ _bindStmtFieldDataChar(hStmt, FLAGS_RECENT_FIELD_IDX_IN_MAIL_TBL, 0);
+ _bindStmtFieldDataChar(hStmt, FLAGS_DRAFT_FIELD_IDX_IN_MAIL_TBL, 0);
+ _bindStmtFieldDataChar(hStmt, FLAGS_FORWARDED_FIELD_IDX_IN_MAIL_TBL, 0);
+ _bindStmtFieldDataInt(hStmt, DRM_STATUS_IDX_IN_MAIL_TBL, 0);
+ _bindStmtFieldDataInt(hStmt, PRIORITY_IDX_IN_MAIL_TBL, 0);
+ _bindStmtFieldDataInt(hStmt, SAVE_STATUS_IDX_IN_MAIL_TBL, 0);
+ _bindStmtFieldDataInt(hStmt, LOCK_STATUS_IDX_IN_MAIL_TBL, 0);
+ _bindStmtFieldDataInt(hStmt, REPORT_STATUS_IDX_IN_MAIL_TBL, 0);
+ _bindStmtFieldDataInt(hStmt, ATTACHMENT_COUNT_IDX_IN_MAIL_TBL, 0);
+ _bindStmtFieldDataInt(hStmt, INLINE_CONTENT_COUNT_IDX_IN_MAIL_TBL, 0);
+ _bindStmtFieldDataInt(hStmt, ATTACHMENT_COUNT_IDX_IN_MAIL_TBL, 0);
+ _bindStmtFieldDataInt(hStmt, THREAD_ID_IDX_IN_MAIL_TBL, 0);
+ _bindStmtFieldDataInt(hStmt, THREAD_ITEM_COUNT_IDX_IN_MAIL_TBL, 0);
+ _bindStmtFieldDataString(hStmt, PREVIEW_TEXT_IDX_IN_MAIL_TBL, "preview body", 1, PREVIEWBODY_LEN_IN_MAIL_TBL);
+ _bindStmtFieldDataInt(hStmt, MEETING_REQUEST_STATUS_IDX_IN_MAIL_TBL, 0);
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
+ EM_DEBUG_DB_EXEC((rc == SQLITE_FULL), {error = EM_STORAGE_ERROR_DB_IS_FULL;goto FINISH_OFF; },
+ ("sqlite3_step fail:%d", rc));
+ EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("sqlite3_step fail:%d", rc));
+ ret = true;
+FINISH_OFF:
+ if (hStmt != NULL) {
+ rc = sqlite3_finalize(hStmt);
+ if (rc != SQLITE_OK) {
+ EM_DEBUG_LOG("sqlite3_finalize failed - %d", rc);
+
+ error = EM_STORAGE_ERROR_DB_FAILURE;
+ }
+ }
+
+
+ EM_STORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
+ _DISCONNECT_DB;
+
+ if (err_code != NULL)
+ *err_code = error;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+
+EXPORT_API int em_storage_get_max_mail_count()
+{
+ return EM_STORAGE_MAIL_MAX;
+}
+
+EXPORT_API int em_storage_get_thread_id_of_thread_mails(emf_mail_tbl_t *mail_tbl, int *thread_id, int *result_latest_mail_id_in_thread, int *thread_item_count)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ EM_PROFILE_BEGIN(profile_em_storage_get_thread_id_of_thread_mails);
+ int rc = 0, query_size = 0, query_size_account = 0;
+ int account_id;
+ char *mailbox_name = NULL, *subject = NULL, *date_time = NULL;
+ int err_code = EM_STORAGE_ERROR_NONE;
+ char *sql_query_string = NULL, *sql_account = NULL;
+ char *sql_format = "SELECT thread_id, date_time, mail_id FROM mail_tbl WHERE subject like \'%%%q\' AND mailbox_type NOT IN (3, 5, 7)";
+ char *sql_format_account = " AND account_id = %d ";
+ char *sql_format_order_by = " ORDER BY date_time DESC ";
+ char **result = NULL, latest_date_time[18];
+ char stripped_subject[1025];
+ int count = 0, result_thread_id = -1, latest_mail_id_in_thread = -1;
+ sqlite3 *local_db_handle = em_storage_get_db_connection();
+
+ EM_IF_NULL_RETURN_VALUE(mail_tbl, EMF_ERROR_INVALID_PARAM);
+ EM_IF_NULL_RETURN_VALUE(thread_id, EMF_ERROR_INVALID_PARAM);
+ EM_IF_NULL_RETURN_VALUE(result_latest_mail_id_in_thread, EMF_ERROR_INVALID_PARAM);
+ EM_IF_NULL_RETURN_VALUE(thread_item_count, EMF_ERROR_INVALID_PARAM);
+
+ if (mail_tbl->mailbox_type == EMF_MAILBOX_TYPE_TRASH ||
+ mail_tbl->mailbox_type == EMF_MAILBOX_TYPE_SPAMBOX ||
+ mail_tbl->mailbox_type == EMF_MAILBOX_TYPE_ALL_EMAILS) {
+ EM_DEBUG_LOG("the mail in trash, spambox, all email could not be thread mail.");
+ goto FINISH_OFF;
+ }
+
+ account_id = mail_tbl->account_id;
+ mailbox_name = mail_tbl->mailbox_name;
+ subject = mail_tbl->subject;
+ date_time = mail_tbl->datetime;
+
+ memset(latest_date_time, 0, 18);
+
+ EM_DEBUG_LOG("subject : %s", subject);
+
+ if (em_core_find_pos_stripped_subject_for_thread_view(subject, stripped_subject) != EMF_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("em_core_find_pos_stripped_subject_for_thread_view is failed");
+ err_code = EM_STORAGE_ERROR_UNKNOWN;
+ result_thread_id = -1;
+ goto FINISH_OFF;
+ }
+
+ if (strlen(stripped_subject) < 2) {
+ result_thread_id = -1;
+ goto FINISH_OFF;
+ }
+
+ EM_DEBUG_LOG("em_core_find_pos_stripped_subject_for_thread_view returns[len = %d] = %s", strlen(stripped_subject), stripped_subject);
+
+ if (account_id > 0) {
+ query_size_account = 3 + strlen(sql_format_account);
+ sql_account = malloc(query_size_account);
+ if (sql_account == NULL) {
+ EM_DEBUG_EXCEPTION("malloc for sql_account is failed %d", query_size_account);
+ err_code = EM_STORAGE_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+ snprintf(sql_account, query_size_account, sql_format_account, account_id);
+ }
+
+ query_size = strlen(sql_format) + strlen(stripped_subject) + 50 + query_size_account + strlen(sql_format_order_by); /* + query_size_mailbox; */
+
+ sql_query_string = malloc(query_size);
+
+ if (sql_query_string == NULL) {
+ EM_DEBUG_EXCEPTION("malloc for sql is failed %d", query_size);
+ err_code = EM_STORAGE_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ sqlite3_snprintf(query_size, sql_query_string, sql_format, stripped_subject);
+ /* snprintf(sql_query_string, query_size, sql_format, stripped_subject); */
+ if (account_id > 0)
+ strcat(sql_query_string, sql_account);
+
+ strcat(sql_query_string, sql_format_order_by);
+ strcat(sql_query_string, ";");
+
+ EM_DEBUG_LOG("Query : %s", sql_query_string);
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, &count, NULL, NULL), rc);
+
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {err_code = EM_STORAGE_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+ ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ EM_DEBUG_LOG("Result rows count : %d", count);
+
+ if (count == 0)
+ result_thread_id = -1;
+ else {
+ _getTableFieldDataInt(result, &result_thread_id, 3);
+ _getTableFieldDataStringWithoutAllocation(result, (char *)latest_date_time, 18, 1, 4);
+ _getTableFieldDataInt(result, &latest_mail_id_in_thread, 5);
+
+ if (mail_tbl->datetime && strcmp(latest_date_time, mail_tbl->datetime) > 0)
+ *result_latest_mail_id_in_thread = latest_mail_id_in_thread;
+ else
+ *result_latest_mail_id_in_thread = mail_tbl->mail_id;
+ EM_DEBUG_LOG("latest_mail_id_in_thread [%d], mail_id [%d]", latest_mail_id_in_thread, mail_tbl->mail_id);
+ }
+
+FINISH_OFF:
+ *thread_id = result_thread_id;
+ *thread_item_count = count;
+
+ EM_DEBUG_LOG("Result thread id : %d", *thread_id);
+ EM_DEBUG_LOG("Result count : %d", *thread_item_count);
+ EM_DEBUG_LOG("err_code : %d", err_code);
+
+ EM_SAFE_FREE(sql_account);
+ EM_SAFE_FREE(sql_query_string);
+
+ sqlite3_free_table(result);
+
+ EM_PROFILE_END(profile_em_storage_get_thread_id_of_thread_mails);
+
+ return err_code;
+}
+
+
+EXPORT_API int em_storage_get_thread_information(int thread_id, emf_mail_tbl_t** mail_tbl, int transaction, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ int count = 0, ret = false;
+ int error = EM_STORAGE_ERROR_NONE;
+ emf_mail_tbl_t *p_data_tbl = NULL;
+ char conditional_clause[QUERY_SIZE] = {0, };
+
+ EM_IF_NULL_RETURN_VALUE(mail_tbl, false);
+
+ SNPRINTF(conditional_clause, QUERY_SIZE, "WHERE thread_id = %d AND thread_item_count > 0", thread_id);
+ EM_DEBUG_LOG("conditional_clause [%s]", conditional_clause);
+
+ if(!em_storage_query_mail_tbl(conditional_clause, transaction, &p_data_tbl, &count, &error)) {
+ EM_DEBUG_EXCEPTION("em_storage_query_mail_tbl failed [%d]", error);
+ goto FINISH_OFF;
+ }
+
+ if(p_data_tbl)
+ EM_DEBUG_LOG("thread_id : %d, thread_item_count : %d", p_data_tbl[0].thread_id, p_data_tbl[0].thread_item_count);
+
+ ret = true;
+
+FINISH_OFF:
+ if (ret == true)
+ *mail_tbl = p_data_tbl;
+ else if (p_data_tbl != NULL)
+ em_storage_free_mail(&p_data_tbl, 1, NULL);
+
+ if (err_code != NULL)
+ *err_code = error;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+
+EXPORT_API int em_storage_get_sender_list(int account_id, const char *mailbox_name, int search_type, const char *search_value, emf_sort_type_t sorting, emf_sender_list_t** sender_list, int *sender_count, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("account_id [%d], mailbox_name [%p], search_type [%d], search_value [%p], sorting [%d], sender_list[%p], sender_count[%p] err_code[%p]"
+ , account_id , mailbox_name , search_type , search_value , sorting , sender_list, sender_count, err_code);
+
+ if ((!sender_list) ||(!sender_count)) {
+ EM_DEBUG_EXCEPTION("EM_STORAGE_ERROR_INVALID_PARAM");
+ if (err_code != NULL)
+ *err_code = EM_STORAGE_ERROR_INVALID_PARAM;
+ return false;
+ }
+
+ int rc = -1, ret = false;
+ int error = EM_STORAGE_ERROR_NONE;
+ int count = 0;
+ int i, col_index = 0;
+ int read_count = 0;
+ emf_sender_list_t *p_sender_list = NULL;
+ char sql_query_string[QUERY_SIZE] = {0, };
+ char **result = NULL;
+ sqlite3 *local_db_handle = em_storage_get_db_connection();
+
+ SNPRINTF(sql_query_string, sizeof(sql_query_string),
+ "SELECT email_address_sender, alias_sender, COUNT(email_address_sender), SUM(flags_seen_field = 1) "
+ "FROM mail_tbl ");
+
+ /* mailbox_name */
+ if (mailbox_name)
+ SNPRINTF(sql_query_string + strlen(sql_query_string), QUERY_SIZE-(strlen(sql_query_string)+1), " WHERE UPPER(mailbox_name) = UPPER('%s') ", mailbox_name);
+ else /* NULL means all mailbox_name. but except for trash(3), spambox(5), all emails(for GMail, 7) */
+ SNPRINTF(sql_query_string + strlen(sql_query_string), QUERY_SIZE-(strlen(sql_query_string)+1), " WHERE mailbox_type not in (3, 5, 7) ");
+
+ /* account id */
+ /* '0' (ALL_ACCOUNT) means all account */
+ if (account_id > ALL_ACCOUNT)
+ SNPRINTF(sql_query_string + strlen(sql_query_string), QUERY_SIZE-(strlen(sql_query_string)+1), " AND account_id = %d ", account_id);
+
+ if (search_value) {
+ switch (search_type) {
+ case EMF_SEARCH_FILTER_SUBJECT:
+ SNPRINTF(sql_query_string + strlen(sql_query_string), QUERY_SIZE-(strlen(sql_query_string)+1),
+ " AND (UPPER(subject) LIKE UPPER(\'%%%%%s%%%%\')) ", search_value);
+ break;
+ case EMF_SEARCH_FILTER_SENDER:
+ SNPRINTF(sql_query_string + strlen(sql_query_string), QUERY_SIZE-(strlen(sql_query_string)+1),
+ " AND ((UPPER(full_address_from) LIKE UPPER(\'%%%%%s%%%%\')) "
+ ") ", search_value);
+ break;
+ case EMF_SEARCH_FILTER_RECIPIENT:
+ SNPRINTF(sql_query_string + strlen(sql_query_string), QUERY_SIZE-(strlen(sql_query_string)+1),
+ " AND ((UPPER(full_address_to) LIKE UPPER(\'%%%%%s%%%%\')) "
+ " OR (UPPER(full_address_cc) LIKE UPPER(\'%%%%%s%%%%\')) "
+ " OR (UPPER(full_address_bcc) LIKE UPPER(\'%%%%%s%%%%\')) "
+ ") ", search_value, search_value, search_value);
+ break;
+ case EMF_SEARCH_FILTER_ALL:
+ SNPRINTF(sql_query_string + strlen(sql_query_string), QUERY_SIZE-(strlen(sql_query_string)+1),
+ " AND (UPPER(subject) LIKE UPPER(\'%%%%%s%%%%\') "
+ " OR (((UPPER(full_address_from) LIKE UPPER(\'%%%%%s%%%%\')) "
+ " OR (UPPER(full_address_to) LIKE UPPER(\'%%%%%s%%%%\')) "
+ " OR (UPPER(full_address_cc) LIKE UPPER(\'%%%%%s%%%%\')) "
+ " OR (UPPER(full_address_bcc) LIKE UPPER(\'%%%%%s%%%%\')) "
+ " ) "
+ " )"
+ ")", search_value, search_value, search_value, search_value, search_value);
+ break;
+ }
+ }
+
+
+ /* sorting option is not available now. The order of sender list is ascending order by display name */
+ SNPRINTF(sql_query_string + strlen(sql_query_string), sizeof(sql_query_string)-(strlen(sql_query_string)+1),
+ "GROUP BY email_address_sender "
+ "ORDER BY UPPER(alias_sender) ");
+
+ EM_DEBUG_LOG("query[%s]", sql_query_string);
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, &count, 0, NULL), rc);
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc && -1 != rc), {error = EM_STORAGE_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+ ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ EM_DEBUG_LOG("Count of Sender [%d]", count);
+
+ if (!(p_sender_list = (emf_sender_list_t*)em_core_malloc(sizeof(emf_sender_list_t) * count))) {
+ EM_DEBUG_EXCEPTION("em_core_malloc failed...");
+ error = EM_STORAGE_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ col_index = 4;
+
+ EM_DEBUG_LOG(">>>> DATA ASSIGN START >>");
+ for (i = 0; i < count; i++) {
+ _getTableFieldDataString(result, &(p_sender_list[i].address), 1, col_index++);
+ _getTableFieldDataString(result, &(p_sender_list[i].display_name), 1, col_index++);
+ _getTableFieldDataInt(result, &(p_sender_list[i].total_count), col_index++);
+ _getTableFieldDataInt(result, &(read_count), col_index++);
+ p_sender_list[i].unread_count = p_sender_list[i].total_count - read_count; /* unread count = total - read */
+ }
+ EM_DEBUG_LOG(">>>> DATA ASSIGN END [count : %d] >>", count);
+
+ sqlite3_free_table(result);
+ result = NULL;
+
+ ret = true;
+
+FINISH_OFF:
+ if (ret == true) {
+ *sender_list = p_sender_list;
+ *sender_count = count;
+ EM_DEBUG_LOG(">>>> COUNT : %d >>", count);
+ }
+ else if (p_sender_list != NULL)
+ em_storage_free_sender_list(&p_sender_list, count);
+
+ _DISCONNECT_DB;
+
+ if (err_code != NULL)
+ *err_code = error;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+EXPORT_API int em_storage_free_sender_list(emf_sender_list_t **sender_list, int count)
+{
+ EM_DEBUG_FUNC_BEGIN("sender_list[%p], count[%d]", sender_list, count);
+
+ int err = EMF_ERROR_NONE;
+
+ if (count > 0) {
+ if (!sender_list || !*sender_list) {
+ EM_DEBUG_EXCEPTION("sender_list[%p], count[%d]", sender_list, count);
+ err = EMF_ERROR_INVALID_PARAM;
+ return err;
+ }
+
+ emf_sender_list_t* p = *sender_list;
+ int i = 0;
+
+ for (; i < count; i++) {
+ EM_SAFE_FREE(p[i].address);
+ EM_SAFE_FREE(p[i].display_name);
+ }
+
+ EM_SAFE_FREE(p);
+ *sender_list = NULL;
+ }
+
+ return err;
+}
+
+#ifdef _CONTACT_SUBSCRIBE_CHANGE_
+
+#define MAX_BUFFER_LEN 8096
+#define DEBUG_EMAIL
+
+#ifdef DEBUG_EMAIL
+static void em_storage_contact_sync_print_email_list(int contact_id, char *display_name, GSList *email_list)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ int i;
+ GSList *cursor = NULL;
+
+ EM_DEBUG_LOG("====================================================================================");
+ EM_DEBUG_LOG("Contact ID : [%d] Display Name : [%s]", contact_id, display_name);
+ EM_DEBUG_LOG("====================================================================================");
+ EM_DEBUG_LOG(" order email_type email");
+ EM_DEBUG_LOG("====================================================================================");
+ i = 0;
+ for (cursor = email_list; cursor; cursor = g_slist_next(cursor)) {
+ EM_DEBUG_LOG("[%d] [%d] [%-35s]",
+ i,
+ contacts_svc_value_get_int(cursor->data, CTS_EMAIL_VAL_TYPE_INT),
+ contacts_svc_value_get_str(cursor->data, CTS_EMAIL_VAL_ADDR_STR));
+ i++;
+ }
+ EM_DEBUG_LOG("====================================================================================");
+}
+#endif
+
+EXPORT_API int em_storage_contact_sync_insert(int contact_id, char *display_name, GSList *email_list, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ int ret = false;
+
+ int rc = 0;
+ char address_list[MAX_BUFFER_LEN];
+ int address_list_len = 0;
+ int error;
+ int index = 0;
+ int is_first = 1;
+ DB_STMT hStmt = NULL;
+ char sql_query_string[QUERY_SIZE] = {0, };
+ GSList *cursor;
+ const char *email_address = NULL;
+ char *display_name_in_mail_tbl = NULL;
+
+ EM_DEBUG_LOG(" Contact ID : [%d] Display Name : [%s] email_list[%p]", contact_id, display_name, email_list);
+ if (display_name == NULL || email_list == NULL) {
+ EM_DEBUG_LOG(" Input Parameter is NULL");
+ return false;
+ }
+
+#ifdef DEBUG_EMAIL
+ em_storage_contact_sync_print_email_list(contact_id, display_name, email_list);
+#endif
+
+ /* Make address list */
+ cursor = email_list;
+ is_first = 1;
+ address_list_len = 0;
+ for (;cursor; cursor = g_slist_next(cursor)) {
+ email_address = contacts_svc_value_get_str(cursor->data, CTS_EMAIL_VAL_ADDR_STR);
+ if (strlen(email_address) <= 0)
+ continue;
+ if (is_first) {
+ is_first = 0;
+ snprintf(address_list+address_list_len, sizeof(address_list) - (1 + address_list_len), "'%s' ", email_address);
+ address_list_len = strlen(address_list);
+ }
+ else {
+ snprintf(address_list+address_list_len, sizeof(address_list) - (1 + address_list_len), ", '%s' ", email_address);
+ address_list_len = strlen(address_list);
+ }
+ }
+ EM_DEBUG_LOG("address list[%s]", address_list);
+
+ int display_name_in_mail_tbl_len = strlen(display_name) + 4;
+ display_name_in_mail_tbl = (char *) malloc(sizeof(char)*display_name_in_mail_tbl_len);
+ if (display_name_in_mail_tbl == NULL) {
+ EM_DEBUG_EXCEPTION("Out of memory");
+ goto FINISH_OFF;
+ }
+ snprintf(display_name_in_mail_tbl, display_name_in_mail_tbl_len - 1, "\"%s\"", display_name);
+ EM_DEBUG_LOG("display_name_in_mail_tbl[%s]", display_name_in_mail_tbl);
+
+ /* Update mail_tbl : from_contact_name, to_contact_name */
+ memset(sql_query_string, 0x00, sizeof(sql_query_string));
+ snprintf(sql_query_string, sizeof(sql_query_string), "UPDATE mail_tbl SET from_contact_id = %d, from_contact_name = ? WHERE email_address_sender IN ( %s );", contact_id, address_list);
+ EM_DEBUG_LOG(" Query[%s]", sql_query_string);
+
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ index = 0;
+ _bindStmtFieldDataString(hStmt, index++, (char *)display_name_in_mail_tbl, 0, 0);
+
+ /* rc = sqlite3_step(hStmt); */
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
+ EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("sqlite3_step fail:%d", rc));
+
+ if (hStmt != NULL) {
+ rc = sqlite3_finalize(hStmt);
+ if (rc != SQLITE_OK) {
+ EM_DEBUG_LOG(" sqlite3_finalize failed - %d", rc);
+ goto FINISH_OFF;
+ }
+ }
+
+ memset(sql_query_string, 0x00, sizeof(sql_query_string));
+ snprintf(sql_query_string, sizeof(sql_query_string), "UPDATE mail_tbl SET to_contact_id = %d, to_contact_name = ? WHERE email_address_recipient IN ( %s );", contact_id, address_list);
+ EM_DEBUG_LOG(" Query[%s]", sql_query_string);
+
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ index = 0;
+ _bindStmtFieldDataString(hStmt, index++, (char *)display_name_in_mail_tbl, 0, 0);
+
+ /* rc = sqlite3_step(hStmt); */
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
+ EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("sqlite3_step fail:%d", rc));
+
+ if (hStmt != NULL) {
+ rc = sqlite3_finalize(hStmt);
+ if (rc != SQLITE_OK) {
+ EM_DEBUG_LOG(" sqlite3_finalize failed - %d", rc);
+ goto FINISH_OFF;
+ }
+ }
+
+ ret = true;
+FINISH_OFF:
+ EM_SAFE_FREE(display_name_in_mail_tbl);
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+EXPORT_API int em_storage_contact_sync_update(int contact_id, char *display_name, GSList *email_list, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ int ret = false;
+ int rc = 0;
+ char address_list[MAX_BUFFER_LEN];
+ int address_list_len = 0;
+ int error;
+ DB_STMT hStmt = NULL;
+ char sql_query_string[QUERY_SIZE] = {0, };
+ int index = 0;
+ int is_first = 1;
+ int row, col;
+ GSList *cursor;
+ const char *email_address = NULL;
+ char *display_name_in_mail_tbl = NULL;
+
+ EM_DEBUG_LOG(" Contact ID : [%d] Display Name : [%s] email_list[%p]", contact_id, display_name, email_list);
+ if (display_name == NULL || email_list == NULL) {
+ EM_DEBUG_LOG(" Input Parameter is NULL");
+ return false;
+ }
+
+#ifdef DEBUG_EMAIL
+ em_storage_contact_sync_print_email_list(contact_id, display_name, email_list);
+#endif
+
+ /* Make address list */
+ cursor = email_list;
+ is_first = 1;
+ address_list_len = 0;
+ for (;cursor; cursor = g_slist_next(cursor)) {
+ email_address = contacts_svc_value_get_str(cursor->data, CTS_EMAIL_VAL_ADDR_STR);
+ if (strlen(email_address) <= 0)
+ continue;
+ if (is_first) {
+ is_first = 0;
+ snprintf(address_list+address_list_len, sizeof(address_list) - (1 + address_list_len), "'%s' ", email_address);
+ address_list_len = strlen(address_list);
+ }
+ else {
+ snprintf(address_list+address_list_len, sizeof(address_list) - (1 + address_list_len), ", '%s' ", email_address);
+ address_list_len = strlen(address_list);
+ }
+ }
+ EM_DEBUG_LOG("address list[%s]", address_list);
+
+ int display_name_in_mail_tbl_len = strlen(display_name) + 4;
+ display_name_in_mail_tbl = (char *) malloc(sizeof(char)*display_name_in_mail_tbl_len);
+ if (display_name_in_mail_tbl == NULL) {
+ EM_DEBUG_EXCEPTION("Out of memory");
+ goto FINISH_OFF;
+ }
+ snprintf(display_name_in_mail_tbl, display_name_in_mail_tbl_len - 1, "\"%s\"", display_name);
+ EM_DEBUG_LOG("display_name_in_mail_tbl[%s]", display_name_in_mail_tbl);
+
+
+ /* Update mail_tbl : deleted emails full_address_from contact */
+ char **result2 = NULL;
+ memset(sql_query_string, 0x00, sizeof(sql_query_string));
+ snprintf(sql_query_string, sizeof(sql_query_string), "UPDATE mail_tbl SET from_contact_id = -1, from_contact_name = alias_sender "
+ " WHERE from_contact_id = %d "
+ " AND email_address_sender NOT IN ( %s ); ",
+ contact_id, address_list);
+ EM_DEBUG_LOG(" Query[%s]", sql_query_string);
+ rc = sqlite3_get_table(local_db_handle, sql_query_string, &result2, &row, &col, NULL);
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ sqlite3_free_table(result2);
+
+ memset(sql_query_string, 0x00, sizeof(sql_query_string));
+ snprintf(sql_query_string, sizeof(sql_query_string), "UPDATE mail_tbl SET to_contact_id = -1, to_contact_name = alias_recipient "
+ " WHERE to_contact_id = %d "
+ " AND email_address_recipient NOT IN ( %s ); ",
+ contact_id, address_list);
+ EM_DEBUG_LOG(" Query[%s]", sql_query_string);
+ rc = sqlite3_get_table(local_db_handle, sql_query_string, &result2, &row, &col, NULL);
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ sqlite3_free_table(result2);
+
+ /* Update mail_tbl : inserted emails from contact */
+ memset(sql_query_string, 0x00, sizeof(sql_query_string));
+ snprintf(sql_query_string, sizeof(sql_query_string), "UPDATE mail_tbl SET from_contact_name = ?, from_contact_id = %d WHERE email_address_sender IN ( %s ); ",
+ contact_id, address_list);
+ EM_DEBUG_LOG(" Query[%s]", sql_query_string);
+ /* rc = sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL); */
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ index = 0;
+ _bindStmtFieldDataString(hStmt, index++, (char *)display_name_in_mail_tbl, 0, 0);
+
+ /* rc = sqlite3_step(hStmt); */
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
+ EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("sqlite3_step fail:%d", rc));
+
+ if (hStmt != NULL) {
+ rc = sqlite3_finalize(hStmt);
+ if (rc != SQLITE_OK) {
+ EM_DEBUG_LOG(" sqlite3_finalize failed - %d", rc);
+ goto FINISH_OFF;
+ }
+ }
+
+ memset(sql_query_string, 0x00, sizeof(sql_query_string));
+ snprintf(sql_query_string, sizeof(sql_query_string), "UPDATE mail_tbl SET to_contact_name = ?, to_contact_id = %d WHERE email_address_recipient IN ( %s ); ",
+ contact_id, address_list);
+ EM_DEBUG_LOG(" Query[%s]", sql_query_string);
+ /* rc = sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL); */
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ index = 0;
+ _bindStmtFieldDataString(hStmt, index++, (char *)display_name_in_mail_tbl, 0, 0);
+
+ /* rc = sqlite3_step(hStmt); */
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
+ EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("sqlite3_step fail:%d", rc));
+
+ if (hStmt != NULL) {
+ rc = sqlite3_finalize(hStmt);
+ if (rc != SQLITE_OK) {
+ EM_DEBUG_LOG(" sqlite3_finalize failed - %d", rc);
+ goto FINISH_OFF;
+ }
+ }
+
+ ret = true;
+FINISH_OFF:
+ EM_SAFE_FREE(display_name_in_mail_tbl);
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+EXPORT_API int em_storage_contact_sync_delete(int contact_id, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ int rc;
+ int ret = false;
+ sqlite3_stmt* hStmt = NULL;
+ int error;
+ char sql_query_string[QUERY_SIZE] = {0, };
+
+ /* Update mail_tbl : set display name to alias */
+ memset(sql_query_string, 0x00, sizeof(sql_query_string));
+ snprintf(sql_query_string, sizeof(sql_query_string), "UPDATE mail_tbl SET from_contact_id = -1, from_contact_name = alias_sender WHERE from_contact_id = %d", contact_id);
+ EM_DEBUG_LOG(" Query[%s]", sql_query_string);
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ /* rc = sqlite3_step(hStmt); */
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
+ EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("sqlite3_step fail:%d", rc));
+
+ if (hStmt != NULL) { /* finalize and reuse hStmt later */
+ rc = sqlite3_finalize(hStmt);
+ if (rc != SQLITE_OK) {
+ EM_DEBUG_LOG(" sqlite3_finalize failed - %d", rc);
+ }
+ }
+
+ memset(sql_query_string, 0x00, sizeof(sql_query_string));
+ snprintf(sql_query_string, sizeof(sql_query_string), "UPDATE mail_tbl SET to_contact_id = -1, to_contact_name = alias_recipient WHERE to_contact_id = %d", contact_id);
+ EM_DEBUG_LOG(" Query[%s]", sql_query_string);
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ /* rc = sqlite3_step(hStmt); */
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
+ EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("sqlite3_step fail:%d", rc));
+
+ if (hStmt != NULL) { /* finalize and reuse hStmt later */
+ rc = sqlite3_finalize(hStmt);
+ if (rc != SQLITE_OK) {
+ EM_DEBUG_LOG(" sqlite3_finalize failed - %d", rc);
+ }
+ }
+
+ ret = true;
+FINISH_OFF:
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+#endif /* _CONTACT_SUBSCRIBE_CHANGE_ */
+
+
+EXPORT_API int em_storage_free_address_info_list(emf_address_info_list_t **address_info_list)
+{
+ EM_DEBUG_FUNC_BEGIN("address_info_list[%p]", address_info_list);
+
+ int err = EMF_ERROR_NONE;
+ emf_address_info_t *p_address_info = NULL;
+ GList *list = NULL;
+ GList *node = NULL;
+ int i = 0;
+
+ if (!address_info_list || !*address_info_list) {
+ EM_DEBUG_EXCEPTION("address_info_list[%p]", address_info_list);
+ err = EMF_ERROR_INVALID_PARAM;
+ return err;
+ }
+
+ /* delete GLists */
+ for (i = EMF_ADDRESS_TYPE_FROM; i <= EMF_ADDRESS_TYPE_BCC; i++) {
+ switch (i) {
+ case EMF_ADDRESS_TYPE_FROM:
+ list = (*address_info_list)->from;
+ break;
+ case EMF_ADDRESS_TYPE_TO:
+ list = (*address_info_list)->to;
+ break;
+ case EMF_ADDRESS_TYPE_CC:
+ list = (*address_info_list)->cc;
+ break;
+ case EMF_ADDRESS_TYPE_BCC:
+ list = (*address_info_list)->bcc;
+ break;
+ }
+
+ /* delete dynamic-allocated memory for each item */
+ node = g_list_first(list);
+ while (node != NULL) {
+ p_address_info = (emf_address_info_t*)node->data;
+ EM_SAFE_FREE(p_address_info->address);
+ EM_SAFE_FREE(p_address_info->display_name);
+ EM_SAFE_FREE(node->data);
+
+ node = g_list_next(node);
+ }
+ }
+
+ EM_SAFE_FREE(*address_info_list);
+ *address_info_list = NULL;
+
+ EM_DEBUG_FUNC_END("err [%d]", err);
+ return err;
+}
+#ifdef __FEATURE_PARTIAL_BODY_DOWNLOAD__
+
+EXPORT_API int em_storage_add_pbd_activity(emf_event_partial_body_thd* local_activity, int *activity_id, int transaction, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("local_activity[%p], activity_id[%p], transaction[%d], err_code[%p]", local_activity, activity_id, transaction, err_code);
+
+ if (!local_activity || !activity_id) {
+ EM_DEBUG_EXCEPTION("local_activity[%p], transaction[%d], activity_id[%p], err_code[%p]", local_activity, activity_id, transaction, err_code);
+ if (err_code != NULL)
+ *err_code = EM_STORAGE_ERROR_INVALID_PARAM;
+ return false;
+ }
+
+ int rc = -1;
+ int ret = false;
+ int error = EM_STORAGE_ERROR_NONE;
+ int i = 0;
+
+ char sql_query_string[QUERY_SIZE] = {0, };
+ DB_STMT hStmt = NULL;
+ sqlite3 *local_db_handle = em_storage_get_db_connection();
+ EM_STORAGE_START_WRITE_TRANSACTION(transaction, error);
+ memset(sql_query_string, 0x00, sizeof(sql_query_string));
+ SNPRINTF(sql_query_string, sizeof(sql_query_string),
+ "INSERT INTO mail_partial_body_activity_tbl VALUES "
+ "( "
+ "? " /* Account ID */
+ ",?" /* Local Mail ID */
+ ",?" /* Server mail ID */
+ ",?" /* Activity ID */
+ ",?" /* Activity type*/
+ ",?" /* Mailbox name*/
+ ") ");
+
+ char *sql = "SELECT max(rowid) FROM mail_partial_body_activity_tbl;";
+ char **result = NULL;
+
+ /* rc = sqlite3_get_table(local_db_handle, sql, &result, NULL, NULL, NULL); */
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql, &result, NULL, NULL, NULL), rc);
+
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EM_STORAGE_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+ ("SQL(%s) sqlite3_get_table fail:%d -%s", sql, rc, sqlite3_errmsg(local_db_handle)));
+
+ if (NULL==result[1]) rc = 1;
+ else rc = atoi(result[1])+1;
+ sqlite3_free_table(result);
+ result = NULL;
+
+ *activity_id = local_activity->activity_id = rc;
+
+ EM_DEBUG_LOG(">>>>> ACTIVITY ID [ %d ], MAIL ID [ %d ], ACTIVITY TYPE [ %d ], SERVER MAIL ID [ %lu ]", \
+ local_activity->activity_id, local_activity->mail_id, local_activity->activity_type, local_activity->server_mail_id);
+
+ if (local_activity->mailbox_name)
+ EM_DEBUG_LOG(" MAILBOX NAME [ %s ]", local_activity->mailbox_name);
+
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ EM_DEBUG_LOG(">>>> SQL STMT [ %s ]", sql_query_string);
+
+ _bindStmtFieldDataInt(hStmt, i++, local_activity->account_id);
+ _bindStmtFieldDataInt(hStmt, i++, local_activity->mail_id);
+ _bindStmtFieldDataInt(hStmt, i++, local_activity->server_mail_id);
+ _bindStmtFieldDataInt(hStmt, i++, local_activity->activity_id);
+ _bindStmtFieldDataInt(hStmt, i++, local_activity->activity_type);
+ _bindStmtFieldDataString(hStmt, i++ , (char *)local_activity->mailbox_name, 0, 3999);
+
+ /* rc = sqlite3_step(hStmt); */
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
+
+ EM_DEBUG_DB_EXEC((rc == SQLITE_FULL), {error = EM_STORAGE_ERROR_DB_IS_FULL;goto FINISH_OFF; },
+ ("sqlite3_step fail:%d", rc));
+ EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("sqlite3_step fail:%d, errmsg = %s.", rc, sqlite3_errmsg(local_db_handle)));
+
+ ret = true;
+
+FINISH_OFF:
+
+ if (hStmt != NULL) {
+ EM_DEBUG_LOG("Before sqlite3_finalize hStmt = %p", hStmt);
+
+ rc = sqlite3_finalize(hStmt);
+ hStmt = NULL;
+ if (rc != SQLITE_OK) {
+ EM_DEBUG_EXCEPTION("sqlite3_finalize failed - %d", rc);
+ error = EM_STORAGE_ERROR_DB_FAILURE;
+ }
+ }
+
+ EM_STORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
+ _DISCONNECT_DB;
+ if (err_code != NULL)
+ *err_code = error;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+
+EXPORT_API int em_storage_get_pbd_mailbox_list(int account_id, char *** mailbox_list, int *count, int transaction, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("account_id[%d], mailbox_list[%p], count[%p] err_code[%p]", account_id, mailbox_list, count, err_code);
+
+ if (account_id < FIRST_ACCOUNT_ID || NULL == &mailbox_list || NULL == count) {
+ EM_DEBUG_EXCEPTION("account_id[%d], mailbox_list[%p], count[%p] err_code[%p]", account_id, mailbox_list, count, err_code);
+ if (err_code != NULL)
+ *err_code = EM_STORAGE_ERROR_INVALID_PARAM;
+ return false;
+ }
+
+ int ret = false;
+ int error = EM_STORAGE_ERROR_NONE;
+ char **result;
+ int i = 0, rc = -1;
+ char **mbox_list = NULL;
+ DB_STMT hStmt = NULL;
+ char sql_query_string[QUERY_SIZE] = {0, };
+
+ sqlite3 *local_db_handle = em_storage_get_db_connection();
+
+ EM_STORAGE_START_READ_TRANSACTION(transaction);
+
+ memset(sql_query_string, 0x00, sizeof(sql_query_string));
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT count(distinct mailbox_name) FROM mail_partial_body_activity_tbl WHERE account_id = %d order by mailbox_name", account_id);
+
+ /* rc = sqlite3_get_table(local_db_handle, sql_query_string, &result, NULL, NULL, NULL); */
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, NULL, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EM_STORAGE_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+ ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ *count = atoi(result[1]);
+ sqlite3_free_table(result);
+
+ if (!*count) {
+ EM_DEBUG_EXCEPTION(" no mailbox_name found...");
+ error = EM_STORAGE_ERROR_MAILBOX_NOT_FOUND;
+ ret = true;
+ goto FINISH_OFF;
+ }
+ EM_DEBUG_LOG("Mailbox count = %d", *count);
+
+ memset(sql_query_string, 0x00, sizeof(sql_query_string));
+
+ /* SNPRINTF(g_sql_query, sizeof(g_sql_query), "SELECT distinct mailbox_name FROM mail_partial_body_activity_tbl WHERE account_id = %d order by activity_id", account_id); */
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT distinct mailbox_name FROM mail_partial_body_activity_tbl WHERE account_id = %d order by mailbox_name", account_id);
+
+ EM_DEBUG_LOG(" Query [%s]", sql_query_string);
+
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
+
+ EM_DEBUG_LOG(" Bbefore sqlite3_prepare hStmt = %p", hStmt);
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ /* rc = sqlite3_step(hStmt); */
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
+ EM_DEBUG_DB_EXEC((rc != SQLITE_ROW), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("sqlite3_step fail:%d", rc));
+
+ if (NULL == (mbox_list = (char **)em_core_malloc(sizeof(char *) * (*count)))) {
+ EM_DEBUG_EXCEPTION(" em_core_malloc failed...");
+ error = EM_STORAGE_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ memset(mbox_list, 0x00, sizeof(char *) * (*count));
+
+ for (i = 0; i < (*count); i++) {
+ _getStmtFieldDataString(hStmt, &mbox_list[i], 0, ACCOUNT_IDX_MAIL_PARTIAL_BODY_ACTIVITY_TBL);
+ /* rc = sqlite3_step(hStmt); */
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
+ /* EM_DEBUG_LOG("In em_storage_get_pdb_mailbox_list() loop, After sqlite3_step(), , i = %d, rc = %d.", i, rc); */
+ EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("sqlite3_step fail:%d", rc));
+ EM_DEBUG_LOG("mbox_list %s", mbox_list[i]);
+ }
+
+ ret = true;
+
+FINISH_OFF:
+ if (ret == true)
+ *mailbox_list = mbox_list;
+
+ if (hStmt != NULL) {
+ EM_DEBUG_LOG("Before sqlite3_finalize hStmt = %p", hStmt);
+
+ rc = sqlite3_finalize(hStmt);
+ hStmt = NULL;
+ if (rc != SQLITE_OK) {
+ EM_DEBUG_EXCEPTION(" sqlite3_finalize failed - %d", rc);
+ error = EM_STORAGE_ERROR_DB_FAILURE;
+ }
+ }
+
+ EM_STORAGE_FINISH_READ_TRANSACTION(transaction);
+ _DISCONNECT_DB;
+ if (err_code != NULL)
+ *err_code = error;
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+
+EXPORT_API int em_storage_get_pbd_account_list(int **account_list, int *count, int transaction, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("mailbox_list[%p], count[%p] err_code[%p]", account_list, count, err_code);
+
+ if (NULL == &account_list || NULL == count) {
+ EM_DEBUG_EXCEPTION("mailbox_list[%p], count[%p] err_code[%p]", account_list, count, err_code);
+ if (err_code != NULL)
+ *err_code = EM_STORAGE_ERROR_INVALID_PARAM;
+ return false;
+ }
+
+ int ret = false;
+ int error = EM_STORAGE_ERROR_NONE;
+ char *sql;
+ char **result;
+ int i = 0, rc = -1;
+ int *result_account_list = NULL;
+ DB_STMT hStmt = NULL;
+ char sql_query_string[QUERY_SIZE] = {0, };
+
+ sqlite3 *local_db_handle = em_storage_get_db_connection();
+
+ EM_STORAGE_START_READ_TRANSACTION(transaction);
+
+
+ sql = "SELECT count(distinct account_id) FROM mail_partial_body_activity_tbl";
+
+ /* rc = sqlite3_get_table(local_db_handle, sql, &result, NULL, NULL, NULL); */
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql, &result, NULL, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EM_STORAGE_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+ ("SQL(%s) sqlite3_get_table fail:%d -%s", sql, rc, sqlite3_errmsg(local_db_handle)));
+
+ *count = atoi(result[1]);
+ sqlite3_free_table(result);
+
+ if (!*count) {
+ EM_DEBUG_EXCEPTION("no account found...");
+ error = EM_STORAGE_ERROR_MAILBOX_NOT_FOUND;
+ ret = true;
+ goto FINISH_OFF;
+ }
+
+ EM_DEBUG_LOG("Account count [%d]", *count);
+
+ memset(sql_query_string, 0x00, sizeof(sql_query_string));
+
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT distinct account_id FROM mail_partial_body_activity_tbl");
+
+ EM_DEBUG_LOG("Query [%s]", sql_query_string);
+
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
+
+ EM_DEBUG_LOG("Before sqlite3_prepare hStmt = %p", hStmt);
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ /* rc = sqlite3_step(hStmt); */
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
+ EM_DEBUG_DB_EXEC((rc != SQLITE_ROW), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("sqlite3_step fail:%d", rc));
+
+ if (NULL == (result_account_list = (int *)em_core_malloc(sizeof(int) * (*count)))) {
+ EM_DEBUG_EXCEPTION(" em_core_malloc failed...");
+ error = EM_STORAGE_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ memset(result_account_list, 0x00, sizeof(int) * (*count));
+
+ for (i = 0; i < (*count); i++) {
+ _getStmtFieldDataInt(hStmt, result_account_list + i, 0);
+ /* rc = sqlite3_step(hStmt); */
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
+ EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("sqlite3_step fail:%d", rc));
+ EM_DEBUG_LOG("account id -> %d", result_account_list[i]);
+ }
+
+ ret = true;
+
+FINISH_OFF:
+ if (ret == true)
+ *account_list = result_account_list;
+
+ if (hStmt != NULL) {
+ EM_DEBUG_LOG("Before sqlite3_finalize hStmt = %p", hStmt);
+
+ rc = sqlite3_finalize(hStmt);
+ hStmt = NULL;
+ if (rc != SQLITE_OK) {
+ EM_DEBUG_EXCEPTION("sqlite3_finalize failed - %d", rc);
+ error = EM_STORAGE_ERROR_DB_FAILURE;
+ }
+ }
+
+ EM_STORAGE_FINISH_READ_TRANSACTION(transaction);
+ _DISCONNECT_DB;
+ if (err_code != NULL)
+ *err_code = error;
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+
+
+EXPORT_API int em_storage_get_pbd_activity_data(int account_id, char *mailbox_name, emf_event_partial_body_thd** event_start, int *count, int transaction, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("account_id[%d], event_start[%p], err_code[%p]", account_id, event_start, err_code);
+
+ if (account_id < FIRST_ACCOUNT_ID || NULL == event_start || NULL == mailbox_name || NULL == count) {
+ EM_DEBUG_EXCEPTION("account_id[%d], emf_event_partial_body_thd[%p], mailbox_name[%p], count[%p], err_code[%p]", account_id, event_start, mailbox_name, count, err_code);
+
+ if (err_code != NULL)
+ *err_code = EM_STORAGE_ERROR_INVALID_PARAM;
+ return false;
+ }
+
+ int rc = -1;
+ int ret = false;
+ char **result;
+ int error = EM_STORAGE_ERROR_NONE;
+ int i = 0;
+ DB_STMT hStmt = NULL;
+ emf_event_partial_body_thd* event_list = NULL;
+ char sql_query_string[QUERY_SIZE] = {0, };
+
+ sqlite3 *local_db_handle = em_storage_get_db_connection();
+
+ EM_STORAGE_START_READ_TRANSACTION(transaction);
+
+ memset(sql_query_string, 0x00, sizeof(sql_query_string));
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT count(*) FROM mail_partial_body_activity_tbl WHERE account_id = %d AND mailbox_name = '%s' order by activity_id", account_id, mailbox_name);
+
+ /* rc = sqlite3_get_table(local_db_handle, sql_query_string, &result, NULL, NULL, NULL); */
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, NULL, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EM_STORAGE_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+ ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ *count = atoi(result[1]);
+ sqlite3_free_table(result);
+
+ EM_DEBUG_LOG("Query = [%s]", sql_query_string);
+
+ if (!*count) {
+ EM_DEBUG_EXCEPTION("No matched activity found in mail_partial_body_activity_tbl");
+
+ error = EM_STORAGE_ERROR_MAIL_NOT_FOUND;
+ ret = true;
+ goto FINISH_OFF;
+ }
+ EM_DEBUG_LOG("Activity Count = %d", *count);
+
+ memset(sql_query_string, 0x00, sizeof(sql_query_string));
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT * FROM mail_partial_body_activity_tbl WHERE account_id = %d AND mailbox_name = '%s' order by activity_id", account_id, mailbox_name);
+
+ EM_DEBUG_LOG("Query [%s]", sql_query_string);
+
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
+
+ EM_DEBUG_LOG(" Bbefore sqlite3_prepare hStmt = %p", hStmt);
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ /* rc = sqlite3_step(hStmt); */
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
+ EM_DEBUG_DB_EXEC((rc != SQLITE_ROW), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("sqlite3_step fail:%d", rc));
+
+ if (!(event_list = (emf_event_partial_body_thd*)em_core_malloc(sizeof(emf_event_partial_body_thd) * (*count)))) {
+ EM_DEBUG_EXCEPTION("Malloc failed");
+
+ error = EM_STORAGE_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+ memset(event_list, 0x00, sizeof(emf_event_partial_body_thd) * (*count));
+
+ for (i=0; i < (*count); i++) {
+ _getStmtFieldDataInt(hStmt, &(event_list[i].account_id), ACCOUNT_IDX_MAIL_PARTIAL_BODY_ACTIVITY_TBL);
+ _getStmtFieldDataInt(hStmt, &(event_list[i].mail_id), MAIL_IDX_IN_MAIL_PARTIAL_BODY_ACTIVITY_TBL);
+ _getStmtFieldDataInt(hStmt, (int *)&(event_list[i].server_mail_id), SERVER_MAIL_IDX_IN_MAIL_PARTIAL_BODY_ACTIVITY_TBL);
+ _getStmtFieldDataInt(hStmt, &(event_list[i].activity_id), ACTIVITY_IDX_IN_MAIL_PARTIAL_BODY_ACTIVITY_TBL);
+ _getStmtFieldDataInt(hStmt, &(event_list[i].activity_type), ACTIVITY_TYPE_IDX_IN_MAIL_PARTIAL_BODY_ACTIVITY_TBL);
+ _getStmtFieldDataString(hStmt, &(event_list[i].mailbox_name), 0, MAILBOX_NAME_IDX_IN_MAIL_PARTIAL_BODY_ACTIVITY_TBL);
+
+ /* rc = sqlite3_step(hStmt); */
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
+ /* EM_DEBUG_LOG("In em_storage_get_pbd_activity_data() loop, After sqlite3_step(), , i = %d, rc = %d.", i, rc); */
+ EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("sqlite3_step fail:%d", rc));
+
+ event_list[i].event_type = 0;
+ }
+
+ ret = true;
+
+FINISH_OFF:
+ if (true == ret)
+ *event_start = event_list;
+ else {
+ if (event_list) {
+ for (i=0; i < (*count); i++)
+ EM_SAFE_FREE(event_list[i].mailbox_name);
+ EM_SAFE_FREE(event_list);
+ }
+ }
+
+ if (hStmt != NULL) {
+ EM_DEBUG_LOG("Before sqlite3_finalize hStmt = %p", hStmt);
+
+ rc = sqlite3_finalize(hStmt);
+ hStmt = NULL;
+ if (rc != SQLITE_OK) {
+ EM_DEBUG_LOG("sqlite3_finalize failed - %d", rc);
+ error = EM_STORAGE_ERROR_DB_FAILURE;
+ }
+ }
+
+ EM_STORAGE_FINISH_READ_TRANSACTION(transaction);
+ _DISCONNECT_DB;
+ if (err_code != NULL)
+ *err_code = error;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+
+
+EXPORT_API int em_storage_delete_pbd_activity(int account_id, int mail_id, int activity_id, int transaction, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("account_id[%d], mail_id[%d] , activity_id[%d], transaction[%d], err_code[%p]", account_id, mail_id, activity_id, transaction, err_code);
+
+
+ if (account_id < FIRST_ACCOUNT_ID || activity_id < 0 || mail_id <= 0) {
+ EM_DEBUG_EXCEPTION("account_id[%d], mail_id[%d], activity_id[%d], transaction[%d], err_code[%p]", account_id, mail_id, activity_id, transaction, err_code);
+
+ if (err_code != NULL)
+ *err_code = EM_STORAGE_ERROR_INVALID_PARAM;
+ return false;
+ }
+
+ int rc = -1;
+ int ret = false;
+ int error = EM_STORAGE_ERROR_NONE;
+ char sql_query_string[QUERY_SIZE] = {0, };
+
+ sqlite3 *local_db_handle = em_storage_get_db_connection();
+
+ EM_STORAGE_START_WRITE_TRANSACTION(transaction, error);
+ memset(sql_query_string, 0x00, sizeof(sql_query_string));
+
+ if (activity_id == 0)
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), "DELETE FROM mail_partial_body_activity_tbl WHERE account_id = %d AND mail_id = %d", account_id, mail_id);
+ else
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), "DELETE FROM mail_partial_body_activity_tbl WHERE account_id = %d AND activity_id = %d", account_id, activity_id);
+
+ EM_DEBUG_LOG("Query [%s]", sql_query_string);
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC((rc == SQLITE_FULL), {error = EM_STORAGE_ERROR_DB_IS_FULL;goto FINISH_OFF; },
+ ("sqlite3_exec fail:%d", rc));
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ /* validate activity existence */
+ rc = sqlite3_changes(local_db_handle);
+ if (rc == 0) {
+ EM_DEBUG_EXCEPTION("No matching activity found");
+ error = EM_STORAGE_ERROR_DATA_NOT_FOUND;
+ ret = true;
+ goto FINISH_OFF;
+ }
+
+ ret = true;
+
+FINISH_OFF:
+
+ EM_STORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
+
+ _DISCONNECT_DB;
+ if (err_code != NULL)
+ *err_code = error;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+EXPORT_API int em_storage_get_mailbox_pbd_activity_count(int account_id, char *mailbox_name, int *activity_count, int transaction, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("account_id[%d], activity_count[%p], err_code[%p]", account_id, activity_count, err_code);
+
+ if (account_id < FIRST_ACCOUNT_ID || NULL == activity_count || NULL == err_code) {
+ EM_DEBUG_EXCEPTION("account_id[%d], activity_count[%p], err_code[%p]", account_id, activity_count, err_code);
+ if (err_code != NULL)
+ *err_code = EM_STORAGE_ERROR_INVALID_PARAM;
+ return false;
+ }
+ int rc = -1;
+ int ret = false;
+ int error = EM_STORAGE_ERROR_NONE;
+ char sql_query_string[QUERY_SIZE] = {0, };
+
+ DB_STMT hStmt = NULL;
+
+ sqlite3 *local_db_handle = em_storage_get_db_connection();
+
+ EM_STORAGE_START_READ_TRANSACTION(transaction);
+ memset(sql_query_string, 0x00, sizeof(sql_query_string));
+
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT count(*) FROM mail_partial_body_activity_tbl WHERE account_id = %d and mailbox_name = '%s'", account_id, mailbox_name);
+
+ EM_DEBUG_LOG(" Query [%s]", sql_query_string);
+
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
+ EM_DEBUG_LOG("before sqlite3_prepare hStmt = %p", hStmt);
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ /* rc = sqlite3_step(hStmt); */
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
+ EM_DEBUG_DB_EXEC((rc != SQLITE_ROW), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("sqlite3_step fail:%d", rc));
+
+ _getStmtFieldDataInt(hStmt, activity_count, 0);
+
+ EM_DEBUG_LOG("No. of activities in activity table [%d]", *activity_count);
+
+ ret = true;
+
+FINISH_OFF:
+
+ if (hStmt != NULL) {
+ EM_DEBUG_LOG("Before sqlite3_finalize hStmt = %p", hStmt);
+ rc = sqlite3_finalize(hStmt);
+ hStmt=NULL;
+ if (rc != SQLITE_OK) {
+ EM_DEBUG_EXCEPTION("sqlite3_finalize failed - %d", rc);
+ error = EM_STORAGE_ERROR_DB_FAILURE;
+ }
+ EM_DEBUG_LOG("sqlite3_finalize- %d", rc);
+ }
+
+ EM_STORAGE_FINISH_READ_TRANSACTION(transaction);
+ _DISCONNECT_DB;
+
+ if (err_code != NULL)
+ *err_code = error;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+
+EXPORT_API int em_storage_get_pbd_activity_count(int *activity_count, int transaction, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("activity_count[%p], err_code[%p]", activity_count, err_code);
+
+ if (NULL == activity_count || NULL == err_code) {
+ EM_DEBUG_EXCEPTION("activity_count[%p], err_code[%p]", activity_count, err_code);
+ if (err_code != NULL)
+ *err_code = EM_STORAGE_ERROR_INVALID_PARAM;
+ return false;
+ }
+ int rc = -1;
+ int ret = false;
+ int error = EM_STORAGE_ERROR_NONE;
+ DB_STMT hStmt = NULL;
+ char sql_query_string[QUERY_SIZE] = {0, };
+
+ sqlite3 *local_db_handle = em_storage_get_db_connection();
+
+ EM_STORAGE_START_READ_TRANSACTION(transaction);
+ memset(sql_query_string, 0x00, sizeof(sql_query_string));
+
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT count(*) FROM mail_partial_body_activity_tbl;");
+
+ EM_DEBUG_LOG(" Query [%s]", sql_query_string);
+
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
+ EM_DEBUG_LOG(" before sqlite3_prepare hStmt = %p", hStmt);
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ /* rc = sqlite3_step(hStmt); */
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
+ EM_DEBUG_DB_EXEC((rc != SQLITE_ROW), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("sqlite3_step fail:%d", rc));
+
+ _getStmtFieldDataInt(hStmt, activity_count, 0);
+
+ EM_DEBUG_LOG("No. of activities in activity table [%d]", *activity_count);
+
+ ret = true;
+
+FINISH_OFF:
+
+
+ if (hStmt != NULL) {
+ EM_DEBUG_LOG("Before sqlite3_finalize hStmt = %p", hStmt);
+
+ rc = sqlite3_finalize(hStmt);
+ hStmt=NULL;
+ if (rc != SQLITE_OK) {
+ EM_DEBUG_EXCEPTION("sqlite3_finalize failed - %d", rc);
+ error = EM_STORAGE_ERROR_DB_FAILURE;
+ }
+ EM_DEBUG_LOG("sqlite3_finalize- %d", rc);
+ }
+
+ EM_STORAGE_FINISH_READ_TRANSACTION(transaction);
+ _DISCONNECT_DB;
+ if (err_code != NULL)
+ *err_code = error;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+EXPORT_API int em_storage_delete_full_pbd_activity_data(int account_id, int transaction, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("account_id[%d], transaction[%d], err_code[%p]", account_id, transaction, err_code);
+ if (account_id < FIRST_ACCOUNT_ID) {
+ EM_DEBUG_EXCEPTION("account_id[%d], transaction[%d], err_code[%p]", account_id, transaction, err_code);
+ if (err_code != NULL)
+ *err_code = EM_STORAGE_ERROR_INVALID_PARAM;
+ return false;
+ }
+
+ int rc = -1;
+ int ret = false;
+ int error = EM_STORAGE_ERROR_NONE;
+ char sql_query_string[QUERY_SIZE] = {0, };
+
+ sqlite3 *local_db_handle = em_storage_get_db_connection();
+ EM_STORAGE_START_WRITE_TRANSACTION(transaction, error);
+ memset(sql_query_string, 0x00, sizeof(sql_query_string));
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), "DELETE FROM mail_partial_body_activity_tbl WHERE account_id = %d", account_id);
+
+ EM_DEBUG_LOG("Query [%s]", sql_query_string);
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC((rc == SQLITE_FULL), {error = EM_STORAGE_ERROR_DB_IS_FULL;goto FINISH_OFF; },
+ ("sqlite3_exec fail:%d", rc));
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+
+ rc = sqlite3_changes(local_db_handle);
+ if (rc == 0) {
+ EM_DEBUG_EXCEPTION("No matching activities found in mail_partial_body_activity_tbl");
+ error = EM_STORAGE_ERROR_DATA_NOT_FOUND;
+ ret = true;
+ goto FINISH_OFF;
+ }
+
+ ret = true;
+
+FINISH_OFF:
+
+ EM_STORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
+ _DISCONNECT_DB;
+ if (err_code != NULL)
+ *err_code = error;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+/*Himanshu[h.gahlaut]-> Added below API to update mail_partial_body_activity_tbl
+if a mail is moved before its partial body is downloaded.Currently not used but should be used if mail move from server is enabled*/
+
+EXPORT_API int em_storage_update_pbd_activity(char *old_server_uid, char *new_server_uid, char *mbox_name, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("old_server_uid[%s], new_server_uid[%s], mbox_name[%s]", old_server_uid, new_server_uid, mbox_name);
+
+ int rc = -1, ret = false;
+ int error = EM_STORAGE_ERROR_NONE;
+ char sql_query_string[QUERY_SIZE] = {0, };
+
+ int transaction = true;
+
+ if (!old_server_uid || !new_server_uid || !mbox_name) {
+ EM_DEBUG_EXCEPTION("Invalid parameters");
+ error = EM_STORAGE_ERROR_INVALID_PARAM;
+ return false;
+ }
+
+ sqlite3 *local_db_handle = em_storage_get_db_connection();
+ EM_STORAGE_START_WRITE_TRANSACTION(transaction, error);
+ memset(sql_query_string, 0x00, sizeof(sql_query_string));
+ SNPRINTF(sql_query_string, sizeof(sql_query_string),
+ "UPDATE mail_partial_body_activity_tbl SET server_mail_id = %s , mailbox_name=\'%s\' WHERE server_mail_id = %s ", new_server_uid, mbox_name, old_server_uid);
+
+ EM_DEBUG_LOG("Query [%s]", sql_query_string);
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC((rc == SQLITE_FULL), {error = EM_STORAGE_ERROR_DB_IS_FULL;goto FINISH_OFF; },
+ ("sqlite3_exec fail:%d", rc));
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ rc = sqlite3_changes(local_db_handle);
+ if (rc == 0) {
+ EM_DEBUG_EXCEPTION("No matching found in mail_partial_body_activity_tbl");
+ error = EM_STORAGE_ERROR_DATA_NOT_FOUND;
+ goto FINISH_OFF;
+ }
+
+ ret = true;
+
+FINISH_OFF:
+
+ EM_STORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
+ _DISCONNECT_DB;
+ if (err_code != NULL)
+ *err_code = error;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+
+EXPORT_API int em_storage_create_file(char *data_string, size_t file_size, char *dst_file_name, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("file_size[%d] , dst_file_name[%s], err_code[%p]", file_size, dst_file_name, err_code);
+
+ int ret = false;
+ int error = EM_STORAGE_ERROR_NONE;
+
+ FILE* fp_dst = NULL;
+
+ if (!data_string || !dst_file_name) {
+ EM_DEBUG_EXCEPTION("data_string[%p], dst_file_name[%p]", data_string, dst_file_name);
+ error = EM_STORAGE_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ fp_dst = fopen(dst_file_name, "w");
+
+ if (!fp_dst) {
+ EM_DEBUG_EXCEPTION("fopen failed - %s", dst_file_name);
+ if (errno == 28)
+ error = EMF_ERROR_MAIL_MEMORY_FULL;
+ else
+ error = EM_STORAGE_ERROR_SYSTEM_FAILURE;
+ goto FINISH_OFF;
+ }
+
+ if (fwrite(data_string, 1, file_size, fp_dst) < 0) {
+ EM_DEBUG_EXCEPTION("fwrite failed...");
+ error = EM_STORAGE_ERROR_UNKNOWN;
+ goto FINISH_OFF;
+ }
+
+ ret = true;
+
+FINISH_OFF:
+
+ if (fp_dst != NULL)
+ fclose(fp_dst);
+
+ if (err_code != NULL)
+ *err_code = error;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+#endif /* __FEATURE_PARTIAL_BODY_DOWNLOAD__ */
+
+
+
+#ifdef __FEATURE_BULK_DELETE_MOVE_UPDATE_REQUEST_OPTI__
+
+EXPORT_API int em_storage_update_read_mail_uid_by_server_uid(char *old_server_uid, char *new_server_uid, char *mbox_name, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int rc = -1;
+ int ret = false;
+ int error = EM_STORAGE_ERROR_NONE;
+ char sql_query_string[QUERY_SIZE] = {0, };
+
+ int transaction = true;
+
+ if (!old_server_uid || !new_server_uid || !mbox_name) {
+ EM_DEBUG_EXCEPTION("Invalid parameters");
+ error = EM_STORAGE_ERROR_INVALID_PARAM;
+ return false;
+ }
+
+ EM_DEBUG_LOG("old_server_uid[%s], new_server_uid[%s], mbox_name[%s]", old_server_uid, new_server_uid, mbox_name);
+
+ sqlite3 *local_db_handle = em_storage_get_db_connection();
+ EM_STORAGE_START_WRITE_TRANSACTION(transaction, error);
+
+
+ SNPRINTF(sql_query_string, sizeof(sql_query_string),
+ "UPDATE mail_read_mail_uid_tbl SET s_uid=\'%s\' , local_mbox=\'%s\', mailbox_name=\'%s\' WHERE s_uid=%s ", new_server_uid, mbox_name, mbox_name, old_server_uid);
+
+ EM_DEBUG_LOG(" Query [%s]", sql_query_string);
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC((rc == SQLITE_FULL), {error = EM_STORAGE_ERROR_DB_IS_FULL;goto FINISH_OFF; },
+ ("sqlite3_exec fail:%d", rc));
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+
+ rc = sqlite3_changes(local_db_handle);
+ if (rc == 0)
+ {
+ EM_DEBUG_EXCEPTION("No matching found in mail_partial_body_activity_tbl");
+ error = EM_STORAGE_ERROR_DATA_NOT_FOUND;
+ goto FINISH_OFF;
+ }
+
+
+ ret = true;
+
+FINISH_OFF:
+
+ EM_STORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
+ _DISCONNECT_DB;
+
+ if (err_code != NULL)
+ *err_code = error;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+
+}
+
+
+/**
+ * @fn em_storage_get_id_set_from_mail_ids(int mail_ids[], int mail_id_count, emf_id_set_t** server_uids, int *id_set_count, int *err_code);
+ * Prepare an array of mail_id and corresponding server mail id.
+ *
+ *@author h.gahlaut@samsung.com
+ * @param[in] mail_ids Specifies the comma separated string of mail_ids. Maximaum size of string should be less than or equal to (QUERY_SIZE - 88)
+ * where 88 is the length of fixed keywords including ending null character in the QUERY to be formed
+ * @param[out] idset Returns the array of mail_id and corresponding server_mail_id sorted by server_mail_ids
+ * @param[out] id_set_count Returns the no. of cells in idset array i.e. no. of sets of mail_ids and server_mail_ids
+ * @param[out] err_code Returns the error code.
+ * @remarks An Example of Query to be exexuted in this API:
+ * SELECT local_uid, s_uid from mail_read_mail_uid_tbl where local_uid in (12, 13, 56, 78);
+ * @return This function returns true on success or false on failure.
+ */
+
+EXPORT_API int em_storage_get_id_set_from_mail_ids(char *mail_ids, emf_id_set_t** idset, int *id_set_count, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ EM_PROFILE_BEGIN(EmStorageGetIdSetFromMailIds);
+
+ int error = EM_STORAGE_ERROR_NONE;
+ int ret = false;
+ emf_id_set_t* p_id_set = NULL;
+ int count = 0;
+ const int buf_size = QUERY_SIZE;
+ char sql_query_string[QUERY_SIZE] = {0, };
+ int space_left_in_query_buffer = buf_size;
+ int i = 0;
+ int rc = -1;
+ char *server_mail_id = NULL;
+ char **result = NULL;
+ int col_index = 0;
+
+
+ if (NULL == mail_ids || NULL == idset || NULL == id_set_count) {
+ EM_DEBUG_EXCEPTION("Invalid Parameters mail_ids[%p] idset[%p] id_set_count [%p]", mail_ids, idset, id_set_count);
+ error = EM_STORAGE_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ sqlite3 *local_db_handle = em_storage_get_db_connection();
+
+ SNPRINTF(sql_query_string, space_left_in_query_buffer, "SELECT local_uid, s_uid FROM mail_read_mail_uid_tbl WHERE local_uid in (%s) ORDER BY s_uid", mail_ids);
+
+ EM_DEBUG_LOG("SQL Query formed [%s] ", sql_query_string);
+
+ /* rc = sqlite3_get_table(local_db_handle, sql_query_string, &result, &count, 0, NULL); */
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, &count, 0, NULL), rc);
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc && -1 != rc), {error = EM_STORAGE_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+ ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ EM_DEBUG_LOG(" Count of mails [%d ]", count);
+
+ if (count <= 0) {
+ EM_DEBUG_EXCEPTION("Can't find proper mail");
+ error = EM_STORAGE_ERROR_DATA_NOT_FOUND;
+ goto FINISH_OFF;
+ }
+
+
+ if (NULL == (p_id_set = (emf_id_set_t*)em_core_malloc(sizeof(emf_id_set_t) * count))) {
+ EM_DEBUG_EXCEPTION(" em_core_malloc failed...");
+ error = EM_STORAGE_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ col_index = 2;
+
+ EM_PROFILE_BEGIN(EmStorageGetIdSetFromMailIds_Loop);
+ EM_DEBUG_LOG(">>>> DATA ASSIGN START");
+ for (i = 0; i < count; i++) {
+ _getTableFieldDataInt(result, &(p_id_set[i].mail_id), col_index++);
+ _getTableFieldDataString(result, &server_mail_id, 1, col_index++);
+ p_id_set[i].server_mail_id = strtoul(server_mail_id, NULL, 10);
+ EM_SAFE_FREE(server_mail_id);
+ }
+ EM_DEBUG_LOG(">>>> DATA ASSIGN END [count : %d]", count);
+ EM_PROFILE_END(EmStorageGetIdSetFromMailIds_Loop);
+
+ sqlite3_free_table(result);
+ result = NULL;
+
+ ret = true;
+
+ FINISH_OFF:
+
+ if (ret == true) {
+ *idset = p_id_set;
+ *id_set_count = count;
+ EM_DEBUG_LOG(" idset[%p] id_set_count [%d]", *idset, *id_set_count);
+ }
+ else
+ EM_SAFE_FREE(p_id_set);
+
+ _DISCONNECT_DB;
+
+ if (err_code != NULL)
+ *err_code = error;
+
+ EM_PROFILE_END(EmStorageGetIdSetFromMailIds);
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+
+
+#endif
+
+EXPORT_API int em_storage_delete_triggers_from_lucene()
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int rc, ret = true, transaction = true;
+ int error = EM_STORAGE_ERROR_NONE;
+ char sql_query_string[QUERY_SIZE] = {0, };
+
+ sqlite3 *local_db_handle = em_storage_get_db_connection();
+ EM_STORAGE_START_WRITE_TRANSACTION(transaction, error);
+
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), "DROP TRIGGER triggerDelete;");
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), "DROP TRIGGER triggerInsert;");
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), "DROP TRIGGER triggerUpdate;");
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ ret = true;
+
+FINISH_OFF:
+
+ EM_STORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
+
+ _DISCONNECT_DB;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+EXPORT_API int em_storage_filter_mails_by_rule(int account_id, char *dest_mailbox_name, emf_mail_rule_tbl_t *rule, int ** filtered_mail_id_list, int *count_of_mails, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("account_id[%d], dest_mailbox_name[%p] rule[%p], filtered_mail_id_list[%p], count_of_mails[%p], err_code[%p]", account_id, dest_mailbox_name, rule, filtered_mail_id_list, count_of_mails, err_code);
+
+ if ((account_id <= 0) || (!dest_mailbox_name) || (!rule) || (!rule->value)|| (!filtered_mail_id_list) || (!count_of_mails)) {
+ EM_DEBUG_EXCEPTION("Invalid Parameter");
+
+ if (err_code != NULL)
+ *err_code = EM_STORAGE_ERROR_INVALID_PARAM;
+ return false;
+ }
+
+ int rc = -1, ret = false, error = EM_STORAGE_ERROR_NONE;
+ int count = 0, col_index = 0, i = 0, where_pararaph_length = 0, *mail_list = NULL;
+ char **result = NULL, *where_pararaph = NULL;
+ char sql_query_string[QUERY_SIZE] = {0, };
+
+ sqlite3 *local_db_handle = em_storage_get_db_connection();
+
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT mail_id FROM mail_tbl ");
+
+ EM_DEBUG_LOG("rule->value [%s]", rule->value);
+
+ where_pararaph_length = strlen(rule->value) + 100;
+ where_pararaph = malloc(sizeof(char) * where_pararaph_length);
+
+ if (where_pararaph == NULL) {
+ EM_DEBUG_EXCEPTION("malloc failed for where_pararaph.");
+ error = EM_STORAGE_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ memset(where_pararaph, 0, sizeof(char) * where_pararaph_length);
+
+ EM_DEBUG_LOG("rule->type [%d], rule->flag2[%d]", rule->type, rule->flag2);
+
+ if (rule->type == EMF_FILTER_FROM) {
+ if (rule->flag2 == RULE_TYPE_INCLUDES)
+ SNPRINTF(where_pararaph, where_pararaph_length, "WHERE account_id = %d AND mailbox_type NOT in (3,5) AND full_address_from like \'%%%s%%\'", account_id, rule->value);
+ else /* RULE_TYPE_EXACTLY */
+ SNPRINTF(where_pararaph, where_pararaph_length, "WHERE account_id = %d AND mailbox_type NOT in (3,5) AND full_address_from = \'%s\'", account_id, rule->value);
+ }
+ else if (rule->type == EMF_FILTER_SUBJECT) {
+ if (rule->flag2 == RULE_TYPE_INCLUDES)
+ SNPRINTF(where_pararaph, where_pararaph_length, "WHERE account_id = %d AND mailbox_type NOT in (3,5) AND subject like \'%%%s%%\'", account_id, rule->value);
+ else /* RULE_TYPE_EXACTLY */
+ SNPRINTF(where_pararaph, where_pararaph_length, "WHERE account_id = %d AND mailbox_type NOT in (3,5) AND subject = \'%s\'", account_id, rule->value);
+ }
+ else {
+ error = EM_STORAGE_ERROR_INVALID_PARAM;
+ EM_DEBUG_EXCEPTION("rule->type is invald");
+ goto FINISH_OFF;
+ }
+
+ if (strlen(sql_query_string) + strlen(where_pararaph) < QUERY_SIZE)
+ strcat(sql_query_string, where_pararaph);
+
+ EM_DEBUG_LOG("query[%s]", sql_query_string);
+
+ /* rc = sqlite3_get_table(local_db_handle, sql_query_string, &result, &count, 0, NULL); */
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, &count, 0, NULL), rc);
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc && -1 != rc), {error = EM_STORAGE_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+ ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ EM_DEBUG_LOG("Count of mails [%d]", count);
+
+ if (count) {
+ mail_list = malloc(sizeof(int) * count);
+ if (mail_list == NULL) {
+ EM_DEBUG_EXCEPTION("malloc failed for mail_list.");
+ error = EM_STORAGE_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ col_index = 1;
+
+ for (i = 0; i < count; i++)
+ _getTableFieldDataInt(result, &(mail_list[i]), col_index++);
+
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), "UPDATE mail_tbl SET mailbox_name = \'%s\', mailbox_type = 5 ", dest_mailbox_name);
+
+ if (strlen(sql_query_string) + strlen(where_pararaph) < QUERY_SIZE)
+ strcat(sql_query_string, where_pararaph);
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+ }
+
+ *filtered_mail_id_list = mail_list;
+
+ ret = true;
+
+FINISH_OFF:
+
+ sqlite3_free_table(result);
+ result = NULL;
+
+ _DISCONNECT_DB;
+
+ EM_SAFE_FREE(where_pararaph);
+
+ if (ret && count_of_mails)
+ *count_of_mails = count;
+
+ if (err_code != NULL)
+ *err_code = error;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+#define EMF_SLOT_UNIT 25
+
+EXPORT_API int em_storage_set_mail_slot_size(int account_id, char *mailbox_name, int new_slot_size, int transaction, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("account_id[%d], mailbox_name[%p] new_slot_size[%d], err_code[%p]", account_id, mailbox_name, new_slot_size, err_code);
+ int rc = -1, ret = false, err = EM_STORAGE_ERROR_NONE;
+ int where_pararaph_length = 0;
+ char *where_pararaph = NULL;
+ char sql_query_string[QUERY_SIZE] = {0, };
+ int and = 0;
+ sqlite3 *local_db_handle = em_storage_get_db_connection();
+
+ EM_STORAGE_START_WRITE_TRANSACTION(transaction, err);
+
+ if (new_slot_size > 0)
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), "UPDATE mail_box_tbl SET mail_slot_size = %d ", new_slot_size);
+ else if (new_slot_size == 0)
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), "UPDATE mail_box_tbl SET mail_slot_size = mail_slot_size + %d ", EMF_SLOT_UNIT);
+ else
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), "UPDATE mail_box_tbl SET mail_slot_size = mail_slot_size + %d ", new_slot_size * -1);
+
+
+ if (mailbox_name)
+ where_pararaph_length = strlen(mailbox_name) + 80;
+ else
+ where_pararaph_length = 50;
+
+ if (new_slot_size == 0)
+ where_pararaph_length += 70;
+
+ where_pararaph = malloc(sizeof(char) * where_pararaph_length);
+ if (where_pararaph == NULL) {
+ EM_DEBUG_EXCEPTION("Memory allocation failed for where_pararaph");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+ memset(where_pararaph, 0x00, where_pararaph_length);
+
+ if (account_id > ALL_ACCOUNT) {
+ and = 1;
+ if (mailbox_name)
+ SNPRINTF(where_pararaph, where_pararaph_length, "WHERE account_id = %d AND mailbox_name = '%s' ", account_id, mailbox_name);
+ else
+ SNPRINTF(where_pararaph, where_pararaph_length, "WHERE account_id = %d ", account_id);
+ }
+
+ if (new_slot_size == 0)
+ SNPRINTF(where_pararaph + strlen(where_pararaph), where_pararaph_length - strlen(where_pararaph), " %s total_mail_count_on_server > mail_slot_size ", (and ? "AND" : "WHERE"));
+
+ if (strlen(sql_query_string) + strlen(where_pararaph) < QUERY_SIZE)
+ strcat(sql_query_string, where_pararaph);
+ else {
+ EM_DEBUG_EXCEPTION("Query buffer overflowed !!!");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ EM_DEBUG_LOG("query[%s]", sql_query_string);
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {err = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ ret = true;
+
+FINISH_OFF:
+
+ EM_STORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, err);
+
+ _DISCONNECT_DB;
+
+ EM_SAFE_FREE(where_pararaph);
+
+ if (err_code != NULL)
+ *err_code = err;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+EXPORT_API int em_storage_add_meeting_request(int account_id, char *mailbox_name, emf_meeting_request_t* meeting_req, int transaction, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("account_id[%d], mailbox_name[%s], meeting_req[%p], transaction[%d], err_code[%p]", account_id, mailbox_name, meeting_req, transaction, err_code);
+
+ if (!meeting_req || meeting_req->mail_id <= 0) {
+ if (meeting_req)
+ EM_DEBUG_EXCEPTION("mail_id[%]d", meeting_req->mail_id);
+
+ if (err_code != NULL)
+ *err_code = EM_STORAGE_ERROR_INVALID_PARAM;
+
+ return false;
+ }
+
+ int rc = -1;
+ int ret = false;
+ int error = EM_STORAGE_ERROR_NONE;
+ DB_STMT hStmt = NULL;
+ char sql_query_string[QUERY_SIZE] = {0, };
+ int col_index = 0;
+ time_t temp_unix_time = 0;
+
+ sqlite3 *local_db_handle = em_storage_get_db_connection();
+ EM_STORAGE_START_WRITE_TRANSACTION(transaction, error);
+
+ SNPRINTF(sql_query_string, sizeof(sql_query_string),
+ "INSERT INTO mail_meeting_tbl VALUES "
+ "( ?" /* mail_id */
+ ", ?" /* account_id */
+ ", ?" /* mailbox_name */
+ ", ?" /* meeting_response */
+ ", ?" /* start_time */
+ ", ?" /* end_time */
+ ", ?" /* location */
+ ", ?" /* global_object_id */
+ ", ?" /* offset */
+ ", ?" /* standard_name */
+ ", ?" /* standard_time_start_date */
+ ", ?" /* standard_biad */
+ ", ?" /* daylight_name */
+ ", ?" /* daylight_time_start_date */
+ ", ?" /* daylight_bias */
+ " )");
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
+ if (rc != SQLITE_OK) {
+ EM_DEBUG_LOG(" before sqlite3_prepare hStmt = %p", hStmt);
+ EM_DEBUG_EXCEPTION("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle));
+
+ error = EM_STORAGE_ERROR_DB_FAILURE;
+ goto FINISH_OFF;
+ }
+
+ col_index = 0;
+ /*
+ EM_DEBUG_LOG(">>>>> meeting_req->mail_id[%d]", meeting_req->mail_id);
+ EM_DEBUG_LOG(">>>>> account_id[%d]", account_id);
+ EM_DEBUG_LOG(">>>>> mailbox_name[%s]", mailbox_name);
+ EM_DEBUG_LOG(">>>>> meeting_req->meeting_response[%d]", meeting_req->meeting_response);
+ EM_DEBUG_LOG(">>>>> meeting_req->start_time[%s]", asctime(&(meeting_req->start_time)));
+ EM_DEBUG_LOG(">>>>> meeting_req->end_time[%s]", asctime(&(meeting_req->end_time)));
+ EM_DEBUG_LOG(">>>>> meeting_req->location[%s]", meeting_req->location);
+ EM_DEBUG_LOG(">>>>> meeting_req->global_object_id[%s]", meeting_req->global_object_id);
+ EM_DEBUG_LOG(">>>>> meeting_req->time_zone.offset_from_GMT[%d]", meeting_req->time_zone.offset_from_GMT);
+ EM_DEBUG_LOG(">>>>> meeting_req->time_zone.standard_name[%s]", meeting_req->time_zone.standard_name);
+ EM_DEBUG_LOG(">>>>> meeting_req->time_zone.standard_time_start_date[%s]", asctime(&(meeting_req->time_zone.standard_time_start_date)));
+ EM_DEBUG_LOG(">>>>> meeting_req->time_zone.standard_bias[%d]", meeting_req->time_zone.standard_bias);
+ EM_DEBUG_LOG(">>>>> meeting_req->time_zone.daylight_name[%s]", meeting_req->time_zone.daylight_name);
+ EM_DEBUG_LOG(">>>>> meeting_req->time_zone.daylight_time_start_date[%s]", asctime(&(meeting_req->time_zone.daylight_time_start_date)));
+ EM_DEBUG_LOG(">>>>> meeting_req->time_zone.daylight_bias[%d]", meeting_req->time_zone.daylight_bias);
+ */
+ _bindStmtFieldDataInt(hStmt, col_index++, meeting_req->mail_id);
+ _bindStmtFieldDataInt(hStmt, col_index++, account_id);
+ _bindStmtFieldDataString(hStmt, col_index++, (char *)mailbox_name, 0, MAILBOX_LEN_IN_MAIL_MEETING_TBL);
+ _bindStmtFieldDataInt(hStmt, col_index++, meeting_req->meeting_response);
+
+ temp_unix_time = timegm(&(meeting_req->start_time));
+ _bindStmtFieldDataInt(hStmt, col_index++, temp_unix_time);
+ temp_unix_time = timegm(&(meeting_req->end_time));
+ _bindStmtFieldDataInt(hStmt, col_index++, temp_unix_time);
+
+ _bindStmtFieldDataString(hStmt, col_index++, (char *)meeting_req->location, 0, LOCATION_LEN_IN_MAIL_MEETING_TBL);
+ _bindStmtFieldDataString(hStmt, col_index++, (char *)meeting_req->global_object_id, 0, GLOBAL_OBJECT_ID_LEN_IN_MAIL_MEETING_TBL);
+
+ _bindStmtFieldDataInt(hStmt, col_index++, meeting_req->time_zone.offset_from_GMT);
+ _bindStmtFieldDataString(hStmt, col_index++, (char *)meeting_req->time_zone.standard_name, 0, STANDARD_NAME_LEN_IN_MAIL_MEETING_TBL);
+ temp_unix_time = timegm(&(meeting_req->time_zone.standard_time_start_date));
+ _bindStmtFieldDataInt(hStmt, col_index++, temp_unix_time);
+ _bindStmtFieldDataInt(hStmt, col_index++, meeting_req->time_zone.standard_bias);
+
+ _bindStmtFieldDataString(hStmt, col_index++, (char *)meeting_req->time_zone.daylight_name, 0, DAYLIGHT_NAME_LEN_IN_MAIL_MEETING_TBL);
+ temp_unix_time = timegm(&(meeting_req->time_zone.daylight_time_start_date));
+ _bindStmtFieldDataInt(hStmt, col_index++, temp_unix_time);
+ _bindStmtFieldDataInt(hStmt, col_index++, meeting_req->time_zone.daylight_bias);
+
+ /* rc = sqlite3_step(hStmt); */
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
+ EM_DEBUG_DB_EXEC((rc == SQLITE_FULL), {error = EM_STORAGE_ERROR_DB_IS_FULL;goto FINISH_OFF; },
+ ("sqlite3_step fail:%d", rc));
+ EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("sqlite3_step fail:%d", rc));
+
+ ret = true;
+
+FINISH_OFF:
+ if (hStmt != NULL) {
+ EM_DEBUG_LOG("before sqlite3_finalize hStmt = %p", hStmt);
+
+ rc = sqlite3_finalize(hStmt);
+ if (rc != SQLITE_OK) {
+ EM_DEBUG_LOG(" sqlite3_finalize failed - %d", rc);
+ error = EM_STORAGE_ERROR_DB_FAILURE;
+ }
+ }
+
+ EM_STORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
+ _DISCONNECT_DB;
+
+ if (err_code != NULL)
+ *err_code = error;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+EXPORT_API int em_storage_get_meeting_request(int mail_id, emf_meeting_request_t ** meeting_req, int transaction, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ int count = 0;
+ int rc = -1;
+ int ret = false;
+ int error = EM_STORAGE_ERROR_NONE;
+ emf_meeting_request_t *p_temp_meeting_req = NULL;
+ int col_index = 0;
+ time_t temp_unix_time;
+
+ EM_IF_NULL_RETURN_VALUE(meeting_req, false);
+
+ DB_STMT hStmt = NULL;
+ char sql_query_string[QUERY_SIZE] = {0, };
+
+ sqlite3 *local_db_handle = em_storage_get_db_connection();
+ EM_STORAGE_START_READ_TRANSACTION(transaction);
+
+ SNPRINTF(sql_query_string, sizeof(sql_query_string),
+ "SELECT mail_id, meeting_response, start_time, end_time, location, global_object_id, offset, standard_name, standard_time_start_date, standard_bias, daylight_name, daylight_time_start_date, daylight_bias "
+ " FROM mail_meeting_tbl "
+ " WHERE mail_id = %d", mail_id);
+ EM_DEBUG_LOG("sql : %s ", sql_query_string);
+
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
+
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ /* rc = sqlite3_step(hStmt); */
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
+ EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("sqlite3_step fail:%d", rc));
+
+ if (rc == SQLITE_DONE) {
+ EM_DEBUG_EXCEPTION(" no Meeting request found...");
+ count = 0;
+ ret = false;
+ error= EM_STORAGE_ERROR_DATA_NOT_FOUND;
+ goto FINISH_OFF;
+ }
+
+ if (!(p_temp_meeting_req = (emf_meeting_request_t*)malloc(sizeof(emf_meeting_request_t)))) {
+ EM_DEBUG_EXCEPTION(" malloc failed...");
+ error = EM_STORAGE_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ memset(p_temp_meeting_req, 0x00, sizeof(emf_meeting_request_t));
+
+ col_index = 0;
+
+ _getStmtFieldDataInt(hStmt, &(p_temp_meeting_req->mail_id), col_index++);
+ _getStmtFieldDataInt(hStmt, (int *)&(p_temp_meeting_req->meeting_response), col_index++);
+ _getStmtFieldDataInt(hStmt, (int *)(&temp_unix_time), col_index++);
+ gmtime_r(&temp_unix_time, &(p_temp_meeting_req->start_time));
+ _getStmtFieldDataInt(hStmt, (int *)(&temp_unix_time), col_index++);
+ gmtime_r(&temp_unix_time, &(p_temp_meeting_req->end_time));
+ _getStmtFieldDataString(hStmt, &p_temp_meeting_req->location, 1, col_index++);
+ _getStmtFieldDataStringWithoutAllocation(hStmt, p_temp_meeting_req->global_object_id, GLOBAL_OBJECT_ID_LEN_IN_MAIL_MEETING_TBL, 1, col_index++);
+ _getStmtFieldDataInt(hStmt, &(p_temp_meeting_req->time_zone.offset_from_GMT), col_index++);
+
+ _getStmtFieldDataStringWithoutAllocation(hStmt, p_temp_meeting_req->time_zone.standard_name, STANDARD_NAME_LEN_IN_MAIL_MEETING_TBL, 1, col_index++);
+ _getStmtFieldDataInt(hStmt, (int *)(&temp_unix_time), col_index++);
+ gmtime_r(&temp_unix_time, &(p_temp_meeting_req->time_zone.standard_time_start_date));
+ _getStmtFieldDataInt(hStmt, &(p_temp_meeting_req->time_zone.standard_bias), col_index++);
+
+ _getStmtFieldDataStringWithoutAllocation(hStmt, p_temp_meeting_req->time_zone.daylight_name, DAYLIGHT_NAME_LEN_IN_MAIL_MEETING_TBL, 1, col_index++);
+ _getStmtFieldDataInt(hStmt, (int *)(&temp_unix_time), col_index++);
+ gmtime_r(&temp_unix_time, &(p_temp_meeting_req->time_zone.daylight_time_start_date));
+ _getStmtFieldDataInt(hStmt, &(p_temp_meeting_req->time_zone.daylight_bias), col_index++);
+
+ /*
+ EM_DEBUG_LOG(">>>>> meeting_req->mail_id[%d]", p_temp_meeting_req->mail_id);
+ EM_DEBUG_LOG(">>>>> meeting_req->meeting_response[%d]", p_temp_meeting_req->meeting_response);
+ EM_DEBUG_LOG(">>>>> meeting_req->start_time[%s]", asctime(&(p_temp_meeting_req->start_time)));
+ EM_DEBUG_LOG(">>>>> meeting_req->end_time[%s]", asctime(&(p_temp_meeting_req->end_time)));
+ EM_DEBUG_LOG(">>>>> meeting_req->location[%s]", p_temp_meeting_req->location);
+ EM_DEBUG_LOG(">>>>> meeting_req->global_object_id[%s]", p_temp_meeting_req->global_object_id);
+ EM_DEBUG_LOG(">>>>> meeting_req->time_zone.offset_from_GMT[%d]", p_temp_meeting_req->time_zone.offset_from_GMT);
+ EM_DEBUG_LOG(">>>>> meeting_req->time_zone.standard_name[%s]", p_temp_meeting_req->time_zone.standard_name);
+ EM_DEBUG_LOG(">>>>> meeting_req->time_zone.standard_time_start_date[%s]", asctime(&(p_temp_meeting_req->time_zone.standard_time_start_date)));
+ EM_DEBUG_LOG(">>>>> meeting_req->time_zone.standard_bias[%d]", p_temp_meeting_req->time_zone.standard_bias);
+ EM_DEBUG_LOG(">>>>> meeting_req->time_zone.daylight_name[%s]", p_temp_meeting_req->time_zone.daylight_name);
+ EM_DEBUG_LOG(">>>>> meeting_req->time_zone.daylight_time_start_date[%s]", asctime(&(p_temp_meeting_req->time_zone.daylight_time_start_date)));
+ EM_DEBUG_LOG(">>>>> meeting_req->time_zone.daylight_bias[%d]", p_temp_meeting_req->time_zone.daylight_bias);
+ */
+ ret = true;
+
+FINISH_OFF:
+ if (ret == true)
+ *meeting_req = p_temp_meeting_req;
+ else {
+ EM_SAFE_FREE(p_temp_meeting_req);
+ }
+
+ if (hStmt != NULL) {
+ EM_DEBUG_LOG("before sqlite3_finalize hStmt = %p", hStmt);
+
+ rc = sqlite3_finalize(hStmt);
+ hStmt = NULL;
+ if (rc != SQLITE_OK) {
+ EM_DEBUG_EXCEPTION("sqlite3_finalize failed - %d", rc);
+ error = EM_STORAGE_ERROR_DB_FAILURE;
+ }
+ }
+
+ EM_STORAGE_FINISH_READ_TRANSACTION(transaction);
+ _DISCONNECT_DB;
+
+ if (err_code != NULL)
+ *err_code = error;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+
+EXPORT_API int em_storage_update_meeting_request(emf_meeting_request_t* meeting_req, int transaction, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("meeting_req[%p], transaction[%d], err_code[%p]", meeting_req, transaction, err_code);
+
+ int ret = false;
+ int error = EM_STORAGE_ERROR_NONE;
+ int rc;
+ DB_STMT hStmt = NULL;
+ char sql_query_string[QUERY_SIZE] = {0, };
+ time_t temp_unix_time = 0;
+
+ if (!meeting_req) {
+ EM_DEBUG_EXCEPTION("Invalid Parameter!");
+ error = EM_STORAGE_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ sqlite3 *local_db_handle = em_storage_get_db_connection();
+ EM_STORAGE_START_WRITE_TRANSACTION(transaction, error);
+
+ memset(sql_query_string, 0x00, sizeof(sql_query_string));
+ SNPRINTF(sql_query_string, sizeof(sql_query_string),
+ "UPDATE mail_meeting_tbl "
+ "SET "
+ /* " account_id = ?, " // not update here, this can be changed when move or copy */
+ /* " mailbox_name = ?, " // not update here, this can be changed when move or copy */
+ " meeting_response = ?, "
+ " start_time = ?, "
+ " end_time = ?, "
+ " location = ?, "
+ " global_object_id = ?, "
+ " offset = ?, "
+ " standard_name = ?, "
+ " standard_time_start_date = ?, "
+ " standard_bias = ?, "
+ " daylight_name = ?, "
+ " daylight_time_start_date = ?, "
+ " daylight_bias = ? "
+ "WHERE mail_id = %d",
+ meeting_req->mail_id);
+
+ EM_DEBUG_LOG("SQL(%s)", sql_query_string);
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+/*
+ EM_DEBUG_LOG(">>>>> meeting_req->mail_id[%d]", meeting_req->mail_id);
+ EM_DEBUG_LOG(">>>>> meeting_req->meeting_response[%d]", meeting_req->meeting_response);
+ EM_DEBUG_LOG(">>>>> meeting_req->start_time[%s]", asctime(&(meeting_req->start_time)));
+ EM_DEBUG_LOG(">>>>> meeting_req->end_time[%s]", asctime(&(meeting_req->end_time)));
+ EM_DEBUG_LOG(">>>>> meeting_req->location[%s]", meeting_req->location);
+ EM_DEBUG_LOG(">>>>> meeting_req->global_object_id[%s]", meeting_req->global_object_id);
+ EM_DEBUG_LOG(">>>>> meeting_req->time_zone.offset_from_GMT[%d]", meeting_req->time_zone.offset_from_GMT);
+ EM_DEBUG_LOG(">>>>> meeting_req->time_zone.standard_name[%s]", meeting_req->time_zone.standard_name);
+ EM_DEBUG_LOG(">>>>> meeting_req->time_zone.standard_time_start_date[%s]", asctime(&(meeting_req->time_zone.standard_time_start_date)));
+ EM_DEBUG_LOG(">>>>> meeting_req->time_zone.standard_bias[%d]", meeting_req->time_zone.standard_bias);
+ EM_DEBUG_LOG(">>>>> meeting_req->time_zone.daylight_name[%s]", meeting_req->time_zone.daylight_name);
+ EM_DEBUG_LOG(">>>>> meeting_req->time_zone.daylight_time_start_date[%s]", asctime(&(meeting_req->time_zone.daylight_time_start_date)));
+ EM_DEBUG_LOG(">>>>> meeting_req->time_zone.daylight_bias[%d]", meeting_req->time_zone.daylight_bias);
+*/
+ int col_index = 0;
+
+ _bindStmtFieldDataInt(hStmt, col_index++, meeting_req->meeting_response);
+ temp_unix_time = timegm(&(meeting_req->start_time));
+ _bindStmtFieldDataInt(hStmt, col_index++, temp_unix_time);
+ temp_unix_time = timegm(&(meeting_req->end_time));
+ _bindStmtFieldDataInt(hStmt, col_index++, temp_unix_time);
+ _bindStmtFieldDataString(hStmt, col_index++, meeting_req->location, 1, LOCATION_LEN_IN_MAIL_MEETING_TBL);
+ _bindStmtFieldDataString(hStmt, col_index++, meeting_req->global_object_id, 1, GLOBAL_OBJECT_ID_LEN_IN_MAIL_MEETING_TBL);
+ _bindStmtFieldDataInt(hStmt, col_index++, meeting_req->time_zone.offset_from_GMT);
+ _bindStmtFieldDataString(hStmt, col_index++, meeting_req->time_zone.standard_name, 1, STANDARD_NAME_LEN_IN_MAIL_MEETING_TBL);
+ temp_unix_time = timegm(&(meeting_req->time_zone.standard_time_start_date));
+ _bindStmtFieldDataInt(hStmt, col_index++, temp_unix_time);
+ _bindStmtFieldDataInt(hStmt, col_index++, meeting_req->time_zone.standard_bias);
+ _bindStmtFieldDataString(hStmt, col_index++, meeting_req->time_zone.daylight_name, 1, DAYLIGHT_NAME_LEN_IN_MAIL_MEETING_TBL);
+ temp_unix_time = timegm(&(meeting_req->time_zone.daylight_time_start_date));
+ _bindStmtFieldDataInt(hStmt, col_index++, temp_unix_time);
+ _bindStmtFieldDataInt(hStmt, col_index++, meeting_req->time_zone.daylight_bias);
+
+ /* rc = sqlite3_step(hStmt); */
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
+ EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("sqlite3_step fail:%d", rc));
+ ret = true;
+
+
+FINISH_OFF:
+ EM_STORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
+
+ if (hStmt != NULL) {
+ EM_DEBUG_LOG("before sqlite3_finalize hStmt = %p", hStmt);
+
+ rc = sqlite3_finalize(hStmt);
+ if (rc != SQLITE_OK) {
+ EM_DEBUG_EXCEPTION(" sqlite3_finalize failed - %d", rc);
+
+ error = EM_STORAGE_ERROR_DB_FAILURE;
+ }
+ }
+
+ _DISCONNECT_DB;
+
+ if (err_code != NULL)
+ *err_code = error;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+
+EXPORT_API int em_storage_change_meeting_request_field(int account_id, char *mailbox_name, emf_mail_change_type_t type, emf_meeting_request_t* meeting_req, int transaction, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("account_id[%d], mailbox_name[%s], type[%d], meeting_req[%p], transaction[%d], err_code[%p]", account_id, mailbox_name, type, meeting_req, transaction, err_code);
+
+ if (account_id <= 0 || !meeting_req || meeting_req->mail_id <= 0) {
+ if (meeting_req)
+ EM_DEBUG_EXCEPTION("mail_id[%d]", meeting_req->mail_id);
+
+ if (err_code != NULL)
+ *err_code = EM_STORAGE_ERROR_INVALID_PARAM;
+ return false;;
+ }
+
+ int rc;
+ int ret = false;
+ int error = EM_STORAGE_ERROR_NONE;
+ DB_STMT hStmt = NULL;
+ char sql_query_string[QUERY_SIZE] = {0, };
+
+ int col_index = 0;
+
+ sqlite3 *local_db_handle = em_storage_get_db_connection();
+
+ EM_STORAGE_START_WRITE_TRANSACTION(transaction, error);
+
+ switch (type) {
+ case UPDATE_MAILBOX:
+ EM_DEBUG_LOG(">>>>> UPDATE_MAILBOX : Move");
+ if (!mailbox_name) {
+ EM_DEBUG_EXCEPTION(" mailbox_name[%p]", mailbox_name);
+ error = EM_STORAGE_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+ SNPRINTF(sql_query_string, sizeof(sql_query_string),
+ "UPDATE mail_meeting_tbl SET mailbox_name = ? WHERE mail_id = %d", meeting_req->mail_id);
+
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
+ EM_DEBUG_LOG(" Before sqlite3_prepare hStmt = %p", hStmt);
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ _bindStmtFieldDataString(hStmt, col_index++, (char *)mailbox_name, 0, MAILBOX_LEN_IN_MAIL_MEETING_TBL);
+ break;
+
+ default:
+ EM_DEBUG_LOG("type[%d]", type);
+
+ error = EM_STORAGE_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+ EM_DEBUG_LOG("Query = [%s]", sql_query_string);
+
+ /* rc = sqlite3_step(hStmt); */
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
+ EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("sqlite3_step fail:%d", rc));
+
+ ret = true;
+
+FINISH_OFF:
+ if (hStmt != NULL) {
+ EM_DEBUG_LOG(" Before sqlite3_finalize hStmt = %p", hStmt);
+ rc = sqlite3_finalize(hStmt);
+ if (rc != SQLITE_OK) {
+ EM_DEBUG_EXCEPTION(" sqlite3_finalize failed - %d", rc);
+ error = EM_STORAGE_ERROR_DB_FAILURE;
+ }
+ }
+
+ EM_STORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
+ _DISCONNECT_DB;
+
+ if (err_code != NULL)
+ *err_code = error;
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+
+EXPORT_API int em_storage_change_meeting_request_mailbox(int account_id, char *old_mailbox_name, char *new_mailbox_name, int transaction, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("account_id[%d], old_mailbox_name[%p], new_mailbox_name[%p], transaction[%d], err_code[%p]", account_id, old_mailbox_name, new_mailbox_name, transaction, err_code);
+
+ if (account_id < FIRST_ACCOUNT_ID || !old_mailbox_name || !new_mailbox_name) {
+ EM_DEBUG_EXCEPTION("account_id[%d], old_mailbox_name[%p], new_mailbox_name[%p]", account_id, old_mailbox_name, new_mailbox_name);
+
+ if (err_code != NULL)
+ *err_code = EM_STORAGE_ERROR_INVALID_PARAM;
+ return false;
+ }
+
+ int rc;
+ int ret = true;
+ int error = EM_STORAGE_ERROR_NONE;
+ char sql_query_string[QUERY_SIZE] = {0, };
+
+ sqlite3 *local_db_handle = em_storage_get_db_connection();
+
+ EM_STORAGE_START_WRITE_TRANSACTION(transaction, error);
+
+ EM_DEBUG_LOG("Update mailbox_name - searching by mailbox_name name");
+ SNPRINTF(sql_query_string, sizeof(sql_query_string),
+ "UPDATE mail_meeting_tbl SET"
+ " mailbox_name = '%s'"
+ " WHERE account_id = %d"
+ " AND mailbox_name = '%s'"
+ , new_mailbox_name
+ , account_id
+ , old_mailbox_name);
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC((SQLITE_FULL == rc), {error = EM_STORAGE_ERROR_DB_IS_FULL;goto FINISH_OFF; },
+ ("sqlite3_exec fail:%d", rc));
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ rc = sqlite3_changes(local_db_handle);
+ if (rc == 0)
+ EM_DEBUG_EXCEPTION("NO meetring request found...");
+
+ ret = true;
+
+FINISH_OFF:
+
+ EM_STORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
+ _DISCONNECT_DB;
+
+ if (err_code != NULL)
+ *err_code = error;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+
+EXPORT_API int em_storage_delete_meeting_request(int account_id, int mail_id, char *mailbox_name, int transaction, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("account_id[%d], mail_id[%d], mailbox_name[%s], transaction[%d], err_code[%p]", account_id, mail_id, mailbox_name, transaction, err_code);
+
+ if (account_id < ALL_ACCOUNT || mail_id < 0) {
+ EM_DEBUG_EXCEPTION(" account_id[%d], mail_id[%d]", account_id, mail_id);
+
+ if (err_code != NULL)
+ *err_code = EM_STORAGE_ERROR_INVALID_PARAM;
+ return false;
+ }
+
+ int rc;
+ int ret = false;
+ int error = EM_STORAGE_ERROR_NONE;
+ int and = false;
+ char sql_query_string[QUERY_SIZE] = {0, };
+
+ sqlite3 *local_db_handle = em_storage_get_db_connection();
+ EM_STORAGE_START_WRITE_TRANSACTION(transaction, error);
+
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), "DELETE FROM mail_meeting_tbl ");
+
+ if (account_id != ALL_ACCOUNT) { /* NOT '0' means a specific account. '0' means all account */
+ SNPRINTF(sql_query_string + strlen(sql_query_string), sizeof(sql_query_string)-(strlen(sql_query_string)+1), " WHERE account_id = %d", account_id);
+ and = true;
+ }
+ if (mail_id > 0) {
+ SNPRINTF(sql_query_string + strlen(sql_query_string), sizeof(sql_query_string)-(strlen(sql_query_string)+1), " %s mail_id = %d", (and ? "AND" : "WHERE"), mail_id);
+ and = true;
+ }
+ if (mailbox_name) { /* NULL means all mailbox_name */
+ SNPRINTF(sql_query_string + strlen(sql_query_string), sizeof(sql_query_string)-(strlen(sql_query_string)+1), " %s mailbox_name = '%s'", (and ? "AND" : "WHERE"), mailbox_name);
+ }
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ ret = true;
+
+FINISH_OFF:
+ EM_STORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
+ _DISCONNECT_DB;
+
+ if (err_code)
+ *err_code = error;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+EXPORT_API int em_storage_free_meeting_request(emf_meeting_request_t **meeting_req, int count, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("meeting_req[%p], count[%d], err_code[%p]", meeting_req, count, err_code);
+
+ int ret = false;
+ int error = EM_STORAGE_ERROR_NONE;
+ int i = 0;
+ emf_meeting_request_t *cursor;
+
+ if (count > 0) {
+ if (!meeting_req || !*meeting_req) {
+ EM_DEBUG_EXCEPTION("meeting_req[%p], count[%d]", meeting_req, count);
+ error = EM_STORAGE_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ for (i = 0; i < count; i++) {
+ cursor = (*meeting_req) + i;
+ EM_SAFE_FREE(cursor->location);
+ }
+ EM_SAFE_FREE(*meeting_req);
+ }
+
+ ret = true;
+
+FINISH_OFF:
+ if (err_code != NULL)
+ *err_code = error;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+
+}
+
+
+EXPORT_API int em_storage_get_overflowed_mail_id_list(int account_id, char *mailbox_name, int mail_slot_size, int **mail_id_list, int *mail_id_count, int transaction, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("account_id [%d], mailbox_name [%p], mail_slot_size [%d], mail_id_list [%p], mail_id_count [%p], transaction [%d], err_code [%p]", account_id, mailbox_name, mail_slot_size, mail_id_list, mail_id_count, transaction, err_code);
+ EM_PROFILE_BEGIN(profile_em_storage_get_overflowed_mail_id_list);
+ char sql_query_string[QUERY_SIZE] = {0, };
+ char **result = NULL;
+ int rc = -1, ret = false;
+ int error = EM_STORAGE_ERROR_NONE;
+ int counter = 0, col_index = 0;
+ int result_mail_id_count = 0;
+ int *result_mail_id_list = NULL;
+
+ if (!mailbox_name || !mail_id_list || !mail_id_count || account_id < 1) {
+ EM_DEBUG_EXCEPTION("Invalid Parameter");
+ error = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT mail_id FROM mail_tbl WHERE account_id = %d AND mailbox_name = '%s' ORDER BY date_time DESC LIMIT %d, 10000", account_id, mailbox_name, mail_slot_size);
+
+ EM_DEBUG_LOG("query[%s].", sql_query_string);
+
+ sqlite3 *local_db_handle = em_storage_get_db_connection();
+ EM_STORAGE_START_READ_TRANSACTION(transaction);
+
+ /* rc = sqlite3_get_table(local_db_handle, sql_query_string, &result, &result_mail_id_count, 0, NULL); */
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, &result_mail_id_count, 0, NULL), rc);
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc && -1 != rc), {error = EM_STORAGE_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+ ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ if (!result_mail_id_count) {
+ EM_DEBUG_LOG("No mail found...");
+ ret = false;
+ error= EM_STORAGE_ERROR_MAIL_NOT_FOUND;
+ goto FINISH_OFF;
+ }
+
+ EM_DEBUG_LOG("There are [%d] overflowed mails in mailbox_name [%s]", result_mail_id_count, mailbox_name);
+
+ if (!(result_mail_id_list = (int *)malloc(sizeof(int) * result_mail_id_count))) {
+ EM_DEBUG_EXCEPTION("malloc for result_mail_id_list failed...");
+ error = EM_STORAGE_ERROR_OUT_OF_MEMORY;
+ sqlite3_free_table(result);
+ goto FINISH_OFF;
+ }
+
+ memset(result_mail_id_list, 0x00, sizeof(int) * result_mail_id_count);
+
+ col_index = 1;
+
+ for (counter = 0; counter < result_mail_id_count; counter++)
+ _getTableFieldDataInt(result, result_mail_id_list + counter, col_index++);
+
+ ret = true;
+
+FINISH_OFF:
+ EM_DEBUG_LOG("finish off [%d]", ret);
+
+ if (result)
+ sqlite3_free_table(result);
+
+ if (ret == true) {
+ *mail_id_list = result_mail_id_list;
+ *mail_id_count = result_mail_id_count;
+ }
+ else
+ EM_SAFE_FREE(result_mail_id_list);
+
+ EM_STORAGE_FINISH_READ_TRANSACTION(transaction);
+ _DISCONNECT_DB;
+
+ if (err_code != NULL)
+ *err_code = error;
+
+ EM_PROFILE_END(profile_em_storage_get_overflowed_mail_id_list);
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+
+EXPORT_API int em_storage_get_thread_id_by_mail_id(int mail_id, int *thread_id, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("mail_id[%d], thread_id[%p], err_code[%p]", mail_id, thread_id, err_code);
+
+ if (mail_id == 0 || thread_id == NULL) {
+ EM_DEBUG_EXCEPTION("Invalid Parameter");
+ if (err_code != NULL)
+ *err_code = EM_STORAGE_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ int rc = -1, ret = false;
+ int err = EM_STORAGE_ERROR_NONE;
+ char sql_query_string[QUERY_SIZE] = {0, };
+ char **result;
+ int result_count = 0;
+
+ sqlite3 *local_db_handle = em_storage_get_db_connection();
+
+ memset(sql_query_string, 0, QUERY_SIZE);
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT thread_id FROM mail_tbl WHERE mail_id = %d", mail_id);
+
+ /* rc = sqlite3_get_table(local_db_handle, sql_query_string, &result, &result_count, 0, NULL); */
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, &result_count, 0, NULL), rc);
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc && -1 != rc), {err = EM_STORAGE_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+ ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ if (!result_count) {
+ EM_DEBUG_EXCEPTION("No mail found...");
+ ret = false;
+ err= EM_STORAGE_ERROR_MAIL_NOT_FOUND;
+ /* sqlite3_free_table(result); */
+ goto FINISH_OFF;
+ }
+
+ _getTableFieldDataInt(result, thread_id, 1);
+
+ sqlite3_free_table(result);
+
+ ret = true;
+
+FINISH_OFF:
+
+ _DISCONNECT_DB;
+
+ if (err_code != NULL)
+ *err_code = err;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+
+EXPORT_API int em_storage_update_latest_thread_mail(int account_id, int thread_id, int latest_mail_id, int thread_item_count, int transaction, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("account_id [%d], thread_id[%d], latest_mail_id [%d], thread_item_count[%d], err_code[%p]", account_id, thread_id, latest_mail_id, thread_item_count, err_code);
+
+ if (thread_id == 0) {
+ EM_DEBUG_EXCEPTION("Invalid Parameter");
+ if (err_code != NULL)
+ *err_code = EM_STORAGE_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ int rc = -1, ret = false;
+ int err = EM_STORAGE_ERROR_NONE;
+ char sql_query_string[QUERY_SIZE] = {0, };
+ char **result;
+ int result_count = 0;
+
+ sqlite3 *local_db_handle = em_storage_get_db_connection();
+
+ if (thread_item_count == 0 || latest_mail_id == 0) {
+ memset(sql_query_string, 0, QUERY_SIZE);
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT mail_id, count(*) FROM (SELECT account_id, mail_id, thread_id, mailbox_type FROM mail_tbl ORDER BY date_time) WHERE account_id = %d AND thread_id = %d AND mailbox_type NOT in (3,5,7)", account_id, thread_id);
+
+ /* rc = sqlite3_get_table(local_db_handle, sql_query_string, &result, &result_count, 0, NULL); */
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, &result_count, 0, NULL), rc);
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc && -1 != rc), {err = EM_STORAGE_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+ ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+ EM_DEBUG_LOG("result_count[%d]", result_count);
+ if (result_count == 0) {
+ EM_DEBUG_EXCEPTION("No mail found...");
+ ret = false;
+ err= EM_STORAGE_ERROR_MAIL_NOT_FOUND;
+ sqlite3_free_table(result);
+ goto FINISH_OFF;
+ }
+
+ _getTableFieldDataInt(result, &latest_mail_id, 2);
+ _getTableFieldDataInt(result, &thread_item_count, 3);
+
+ EM_DEBUG_LOG("latest_mail_id[%d]", latest_mail_id);
+ EM_DEBUG_LOG("thread_item_count[%d]", thread_item_count);
+
+ sqlite3_free_table(result);
+ }
+
+ EM_STORAGE_START_WRITE_TRANSACTION(transaction, err);
+
+ /* if (thread_item_count > 1) */
+ /* { */
+ memset(sql_query_string, 0, QUERY_SIZE);
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), "UPDATE mail_tbl SET thread_item_count = 0 WHERE account_id = %d AND thread_id = %d", account_id, thread_id);
+ EM_DEBUG_LOG("query[%s]", sql_query_string);
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {err = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+ /* } */
+
+ memset(sql_query_string, 0, QUERY_SIZE);
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), "UPDATE mail_tbl SET thread_item_count = %d WHERE account_id = %d AND mail_id = %d ", thread_item_count, account_id, latest_mail_id);
+ EM_DEBUG_LOG("query[%s]", sql_query_string);
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {err = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ ret = true;
+
+FINISH_OFF:
+
+ EM_STORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, err);
+
+ _DISCONNECT_DB;
+
+ if (err_code != NULL)
+ *err_code = err;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+
+EXPORT_API void
+em_storage_flush_db_cache()
+{
+ sqlite3_release_memory(-1);
+}
+
+#ifdef __LOCAL_ACTIVITY__
+/**
+ * em_storage_add_activity - Add Email Local activity during OFFLINE mode
+ *
+ */
+EXPORT_API int em_storage_add_activity(emf_activity_tbl_t* local_activity, int transaction, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ EM_DEBUG_LOG(" local_activity[%p], transaction[%d], err_code[%p]", local_activity, transaction, err_code);
+
+ int rc = -1, ret = false;
+ int error = EM_STORAGE_ERROR_NONE;
+ DB_STMT hStmt = NULL;
+ char sql_query_string[8192] = { 0x00, };
+ int i = 0;
+
+ if (!local_activity) {
+ EM_DEBUG_EXCEPTION(" local_activity[%p], transaction[%d], err_code[%p]", local_activity, transaction, err_code);
+ if (err_code != NULL)
+ *err_code = EM_STORAGE_ERROR_INVALID_PARAM;
+ return false;
+ }
+
+ sqlite3 *local_db_handle = em_storage_get_db_connection();
+ memset(sql_query_string, 0x00 , sizeof(sql_query_string));
+ EM_STORAGE_START_WRITE_TRANSACTION(transaction, error);
+
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), "INSERT INTO mail_local_activity_tbl VALUES (?, ?, ?, ?, ?, ?, ?)");
+
+ EM_DEBUG_LOG(">>>>> ACTIVITY ID [ %d ] ", local_activity->activity_id);
+ EM_DEBUG_LOG(">>>>> MAIL ID [ %d ] ", local_activity->mail_id);
+ EM_DEBUG_LOG(">>>>> ACCOUNT ID [ %d ] ", local_activity->account_id);
+ EM_DEBUG_LOG(">>>>> ACTIVITY TYPE [ %d ] ", local_activity->activity_type);
+ EM_DEBUG_LOG(">>>>> SERVER MAIL ID [ %s ] ", local_activity->server_mailid);
+ EM_DEBUG_LOG(">>>>> SOURCE MAILBOX [ %s ] ", local_activity->src_mbox);
+ EM_DEBUG_LOG(">>>>> DEST MAILBOX [ %s ] ", local_activity->dest_mbox);
+
+ EM_DEBUG_LOG(">>>> SQL STMT [ %s ] ", sql_query_string);
+
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ EM_DEBUG_LOG(">>>> SQL STMT [ %s ] ", sql_query_string);
+
+
+
+
+ _bindStmtFieldDataInt(hStmt, i++, local_activity->activity_id);
+ _bindStmtFieldDataInt(hStmt, i++, local_activity->account_id);
+ _bindStmtFieldDataInt(hStmt, i++, local_activity->mail_id);
+ _bindStmtFieldDataInt(hStmt, i++, local_activity->activity_type);
+ _bindStmtFieldDataString(hStmt, i++ , (char *)local_activity->server_mailid, 0, SERVER_MAIL_ID_LEN_IN_MAIL_TBL);
+ _bindStmtFieldDataString(hStmt, i++ , (char *)local_activity->src_mbox, 0, MAILBOX_NAME_LEN_IN_MAIL_BOX_TBL);
+ _bindStmtFieldDataString(hStmt, i++ , (char *)local_activity->dest_mbox, 0, MAILBOX_NAME_LEN_IN_MAIL_BOX_TBL);
+
+ /* rc = sqlite3_step(hStmt); */
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
+
+ EM_DEBUG_DB_EXEC((rc == SQLITE_FULL), {error = EM_STORAGE_ERROR_DB_IS_FULL;goto FINISH_OFF; },
+ ("sqlite3_step fail:%d", rc));
+ EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("sqlite3_step fail:%d, errmsg = %s.", rc, sqlite3_errmsg(local_db_handle)));
+
+ ret = true;
+
+FINISH_OFF:
+
+ if (hStmt != NULL) {
+ rc = sqlite3_finalize(hStmt);
+ if (rc != SQLITE_OK) {
+ EM_DEBUG_LOG(" sqlite3_finalize failed - %d", rc);
+
+ error = EM_STORAGE_ERROR_DB_FAILURE;
+ }
+ }
+ else {
+ EM_DEBUG_LOG(" >>>>>>>>>> hStmt is NULL!!!");
+ }
+
+ EM_STORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
+ _DISCONNECT_DB;
+
+
+ if (err_code != NULL)
+ *err_code = error;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+/**
+ * em_storage_get_activity - Get the Local activity Information
+ *
+ *
+ */
+EXPORT_API int em_storage_get_activity(int account_id, int activityid, emf_activity_tbl_t** activity_list, int *select_num, int transaction, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ int i = 0, count = 0, rc = -1, ret = false;
+ int error = EM_STORAGE_ERROR_NONE;
+ emf_activity_tbl_t *p_activity_tbl = NULL;
+ char sql_query_string[1024] = {0x00, };
+ char **result = NULL;
+ int col_index ;
+
+ EM_IF_NULL_RETURN_VALUE(activity_list, false);
+ EM_IF_NULL_RETURN_VALUE(select_num, false);
+
+
+ if (!select_num || !activity_list || account_id <= 0 || activityid < 0) {
+ EM_DEBUG_LOG(" select_num[%p], activity_list[%p] account_id [%d] activityid [%d] ", select_num, activity_list, account_id, activityid);
+ if (err_code != NULL)
+ *err_code = EM_STORAGE_ERROR_INVALID_PARAM;
+ return false;
+ }
+
+ EM_STORAGE_START_READ_TRANSACTION(transaction);
+
+ memset(sql_query_string, 0x00, sizeof(sql_query_string));
+
+ if (activityid == ALL_ACTIVITIES) {
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT * FROM mail_local_activity_tbl WHERE account_id = %d order by activity_id", account_id);
+ }
+ else {
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT * FROM mail_local_activity_tbl WHERE account_id = %d AND activity_id = %d ", account_id, activityid);
+ }
+
+ EM_DEBUG_LOG("Query [%s]", sql_query_string);
+
+
+ /* rc = sqlite3_get_table(local_db_handle, sql_query_string, &result, &count, NULL, NULL); */
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, &count, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EM_STORAGE_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+ ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+
+
+ col_index = 7;
+
+ if (!(p_activity_tbl = (emf_activity_tbl_t*)em_core_malloc(sizeof(emf_activity_tbl_t) * count))) {
+ EM_DEBUG_EXCEPTION(" em_core_malloc failed...");
+ error = EM_STORAGE_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+
+ for (i = 0; i < count; i++) {
+ EM_DEBUG_LOG("result[%d] - %s ", col_index, result[col_index]);
+ if (result[col_index])
+ p_activity_tbl[i].activity_id = atoi(result[col_index++]);
+
+ EM_DEBUG_LOG("result[%d] - %s ", col_index, result[col_index]);
+ if (result[col_index])
+ p_activity_tbl[i].account_id = atoi(result[col_index++]);
+
+ EM_DEBUG_LOG("result[%d] - %s ", col_index, result[col_index]);
+ if (result[col_index])
+ p_activity_tbl[i].mail_id = atoi(result[col_index++]);
+
+ EM_DEBUG_LOG("result[%d] - %s ", col_index, result[col_index]);
+ if (result[col_index])
+ p_activity_tbl[i].activity_type = atoi(result[col_index++]);
+
+
+ EM_DEBUG_LOG("result[%d] - %s ", col_index, result[col_index]);
+ if (result[col_index] && strlen(result[col_index])>0)
+ p_activity_tbl[i].server_mailid = EM_SAFE_STRDUP(result[col_index++]);
+ else
+ col_index++;
+
+ EM_DEBUG_LOG("result[%d] - %s ", col_index, result[col_index]);
+ if (result[col_index] && strlen(result[col_index])>0)
+ p_activity_tbl[i].src_mbox = EM_SAFE_STRDUP(result[col_index++]);
+ else
+ col_index++;
+
+ EM_DEBUG_LOG("result[%d] - %s ", col_index, result[col_index]);
+ if (result[col_index] && strlen(result[col_index])>0)
+ p_activity_tbl[i].dest_mbox = EM_SAFE_STRDUP(result[col_index++]);
+ else
+ col_index++;
+
+ }
+
+ if (result)
+ sqlite3_free_table(result);
+
+ ret = true;
+
+FINISH_OFF:
+
+
+ if (ret == true) {
+ *activity_list = p_activity_tbl;
+ *select_num = count;
+ EM_DEBUG_LOG(">>>> COUNT : %d >> ", count);
+ }
+ else if (p_activity_tbl != NULL) {
+ em_storage_free_local_activity(&p_activity_tbl, count, NULL);
+ }
+
+ EM_STORAGE_FINISH_READ_TRANSACTION(transaction);
+ if (err_code != NULL)
+ *err_code = error;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+
+EXPORT_API int em_storage_get_next_activity_id(int *activity_id, int *err_code)
+{
+
+ EM_DEBUG_FUNC_BEGIN();
+
+ int ret = false;
+ int err = EMF_ERROR_NONE;
+ int rc = -1;
+ char *sql = NULL;
+ char **result = NULL;
+
+ if (NULL == activity_id)
+ {
+ EM_DEBUG_EXCEPTION(" activity_id[%p]", activity_id);
+
+ err = EM_STORAGE_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ /* increase unique id */
+
+ sql = "SELECT max(rowid) FROM mail_local_activity_tbl;";
+
+ /* rc = sqlite3_get_table(local_db_handle, sql, &result, NULL, NULL, NULL); n EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql, &result, NULL, NULL, NULL), rc); */
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {err = EM_STORAGE_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+ ("SQL(%s) sqlite3_get_table fail:%d -%s", sql, rc, sqlite3_errmsg(local_db_handle)));
+
+ if (NULL==result[1])
+ rc = 1;
+ else
+ rc = atoi(result[1])+1;
+
+ *activity_id = rc;
+
+ if (result)
+ sqlite3_free_table(result);
+
+ ret = true;
+
+ FINISH_OFF:
+
+ if (NULL != err_code) {
+ *err_code = err;
+ }
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+
+}
+
+EXPORT_API int em_storage_get_activity_id_list(int account_id, int ** activity_id_list, int *activity_id_count, int lowest_activity_type, int highest_activity_type, int transaction, int *err_code)
+{
+
+ EM_DEBUG_FUNC_BEGIN();
+
+ EM_DEBUG_LOG(" account_id[%d], activity_id_list[%p], activity_id_count[%p] err_code[%p]", account_id, activity_id_list, activity_id_count, err_code);
+
+ if (account_id <= 0|| NULL == activity_id_list || NULL == activity_id_count ||lowest_activity_type <=0 || highest_activity_type <= 0) {
+ if (err_code != NULL)
+ *err_code = EM_STORAGE_ERROR_INVALID_PARAM;
+ return false;
+ }
+
+ int ret = false;
+ int error = EM_STORAGE_ERROR_NONE;
+ int i = 0, rc = -1, count = 0;
+ char sql_query_string[1024] = {0x00, };
+ int *activity_ids = NULL;
+ int col_index = 0;
+ char **result = NULL;
+
+ EM_STORAGE_START_READ_TRANSACTION(transaction);
+
+ memset(sql_query_string, 0x00, sizeof(sql_query_string));
+
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT distinct activity_id FROM mail_local_activity_tbl WHERE account_id = %d AND activity_type >= %d AND activity_type <= %d order by activity_id", account_id, lowest_activity_type, highest_activity_type);
+
+ EM_DEBUG_LOG(" Query [%s]", sql_query_string);
+
+ /* rc = sqlite3_get_table(local_db_handle, sql_query_string, &result, &count, NULL, NULL); */
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, &count, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EM_STORAGE_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+ ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ col_index = 1;
+
+ EM_DEBUG_LOG(" Activity COUNT : %d ... ", count);
+
+ if (NULL == (activity_ids = (int *)em_core_malloc(sizeof(int) * count))) {
+ EM_DEBUG_EXCEPTION(" em_core_malloc failed...");
+ error = EM_STORAGE_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ for (i = 0; i < count; i++) {
+ activity_ids[i] = atoi(result[col_index]);
+ col_index++;
+ EM_DEBUG_LOG("activity_id %d", activity_ids[i]);
+ }
+
+ ret = true;
+
+FINISH_OFF:
+
+
+ if (ret == true) {
+ *activity_id_count = count;
+ *activity_id_list = activity_ids;
+
+ }
+ else if (activity_ids != NULL) /* Prevent defect - 216566 */
+ EM_SAFE_FREE(activity_ids);
+
+
+ EM_STORAGE_FINISH_READ_TRANSACTION(transaction);
+ if (err_code != NULL) {
+ *err_code = error;
+ }
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+EXPORT_API int em_storage_free_activity_id_list(int *activity_id_list, int *error_code)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ int error = EM_STORAGE_ERROR_NONE;
+ int ret = false;
+
+ EM_DEBUG_LOG(" activity_id_list [%p]", activity_id_list);
+
+ if (NULL == activity_id_list) {
+ error = EM_STORAGE_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+ else {
+ free(activity_id_list);
+ activity_id_list = NULL;
+ }
+
+
+ ret= true;
+
+ FINISH_OFF:
+
+ if (NULL != error_code) {
+ *error_code = error;
+ }
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+/**
+ * em_storage_delete_local_activity - Deletes the Local acitivity Generated based on activity_type
+ * or based on server mail id
+ *
+ */
+EXPORT_API int em_storage_delete_local_activity(emf_activity_tbl_t* local_activity, int transaction, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+
+ EM_DEBUG_LOG(" local_activity[%p] ", local_activity);
+
+ if (!local_activity) {
+ EM_DEBUG_EXCEPTION(" local_activity[%p] ", local_activity);
+ if (err_code != NULL)
+ *err_code = EM_STORAGE_ERROR_INVALID_PARAM;
+ return false;
+ }
+
+ int rc = -1, ret = false; /* Prevent_FIX */
+ int err = EM_STORAGE_ERROR_NONE;
+ int query_and = 0;
+ int query_where = 0;
+ char sql_query_string[8192] = { 0x00, };
+ EM_STORAGE_START_WRITE_TRANSACTION(transaction, error);
+
+ memset(sql_query_string, 0x00, sizeof(sql_query_string));
+
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), "DELETE FROM mail_local_activity_tbl ");
+
+ EM_DEBUG_LOG(">>> Query [ %s ] ", sql_query_string);
+
+ if (local_activity->account_id) {
+ SNPRINTF(sql_query_string + strlen(sql_query_string), sizeof(sql_query_string)-(strlen(sql_query_string)+1),
+ " WHERE account_id = %d ", local_activity->account_id);
+ query_and = 1;
+ query_where = 1;
+ }
+
+ if (local_activity->server_mailid) {
+ SNPRINTF(sql_query_string + strlen(sql_query_string), sizeof(sql_query_string)-(strlen(sql_query_string)+1),
+ " %s %s server_mailid = '%s' ", query_where? "": "WHERE", query_and? "AND":"", local_activity->server_mailid);
+ query_and = 1;
+ query_where = 1;
+ }
+
+
+ if (local_activity->mail_id) {
+ EM_DEBUG_LOG(">>>> MAIL ID [ %d ] , ACTIVITY TYPE [%d ]", local_activity->mail_id, local_activity->activity_type);
+
+ SNPRINTF(sql_query_string + strlen(sql_query_string), sizeof(sql_query_string)-(strlen(sql_query_string)+1),
+ " %s %s mail_id = %d ", query_where? "": "WHERE", query_and? "AND":"", local_activity->mail_id);
+
+ query_and = 1;
+ query_where = 1;
+
+ }
+
+ if (local_activity->activity_type > 0) {
+ SNPRINTF(sql_query_string + strlen(sql_query_string), sizeof(sql_query_string)-(strlen(sql_query_string)+1),
+ " %s %s activity_type = %d ", query_where? "": "WHERE", query_and? "AND" : "" , local_activity->activity_type);
+ }
+
+ if (local_activity->activity_id > 0) {
+ SNPRINTF(sql_query_string + strlen(sql_query_string), sizeof(sql_query_string)-(strlen(sql_query_string)+1),
+ " %s %s activity_id = %d ", query_where? "": "WHERE", query_and? "AND" : "" , local_activity->activity_id);
+
+ }
+
+ EM_DEBUG_LOG(">>>>> Query [ %s ] ", sql_query_string);
+
+ EM_STORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {err = EM_STORAGE_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ rc = sqlite3_changes(local_db_handle);
+ if (rc == 0) {
+ EM_DEBUG_EXCEPTION(" no (matched) mailbox_name found...");
+ err = EM_STORAGE_ERROR_MAILBOX_NOT_FOUND;
+ }
+
+ ret = true;
+
+FINISH_OFF:
+ EM_STORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
+ if (err_code != NULL)
+ *err_code = err;
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+/**
+* em_storage_free_local_activity - Free the Local Activity data
+*/
+EXPORT_API int em_storage_free_local_activity(emf_activity_tbl_t **local_activity_list, int count, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ EM_DEBUG_LOG(" local_activity_list[%p], count[%d], err_code[%p]", local_activity_list, count, err_code);
+
+ int ret = false;
+ int error = EM_STORAGE_ERROR_INVALID_PARAM;
+
+ if (count > 0) {
+ if (!local_activity_list || !*local_activity_list) {
+ EM_DEBUG_EXCEPTION(" local_activity_list[%p], count[%d]", local_activity_list, count);
+
+ error = EM_STORAGE_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ emf_activity_tbl_t* p = *local_activity_list;
+ int i = 0;
+ if (p) {
+ for (; i < count; i++) {
+ EM_SAFE_FREE(p[i].dest_mbox);
+ EM_SAFE_FREE(p[i].src_mbox);
+ EM_SAFE_FREE(p[i].server_mailid);
+ }
+
+ free(p); *local_activity_list = NULL;
+ }
+ }
+
+ ret = true;
+
+FINISH_OFF:
+ if (err_code != NULL)
+ *err_code = error;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+
+}
+#endif /* __LOCAL_ACTIVITY__ */
+
+
+/*EOF*/
diff --git a/email-core/em-storage/include/em-storage.h b/email-core/em-storage/include/em-storage.h
new file mode 100755
index 0000000..dd470c6
--- /dev/null
+++ b/email-core/em-storage/include/em-storage.h
@@ -0,0 +1,1539 @@
+/*
+* email-service
+*
+* Copyright (c) 2000 - 2011 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.
+*
+*/
+
+
+/******************************************************************************
+ * File : em-storage.h
+ * Desc : Mail Framework Storage Library Header
+ *
+ * Auth :
+ *
+ * History :
+ * 2006.07.28 : created
+ *****************************************************************************/
+#ifndef __EM_STORAGE_H__
+#define __EM_STORAGE_H__
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif /* __cplusplus */
+
+#define __USE_UNIX98
+#define __USE_GNU
+
+#include "emf-types.h"
+#include "em-core-types.h"
+#include <sqlite3.h>
+
+
+#if !defined(EXPORT_API)
+#define EXPORT_API __attribute__((visibility("default")))
+#endif
+
+
+#define DB_PATH "/opt/dbspace"
+#define EMAIL_SERVICE_DB_FILE_PATH "/opt/dbspace/.email-service.db"
+
+#define EMAILPATH DATA_PATH"/email"
+#define MAILHOME DATA_PATH"/email/.emfdata"
+#define DIRECTORY_PERMISSION 0755
+
+
+#define MAILTEMP "tmp"
+#define FIRST_ACCOUNT_ID 1
+
+
+#ifdef __FEATURE_BULK_DELETE_MOVE_UPDATE_REQUEST_OPTI__
+#define QUERY_SIZE 8192
+#define MAX_INTEGER_LENGTH 5 /* 32767 -> 5 bytes */
+
+typedef struct
+{
+ int mail_id;
+ unsigned long server_mail_id;
+} emf_id_set_t;
+
+#endif /* __FEATURE_BULK_DELETE_MOVE_UPDATE_REQUEST_OPTI__ */
+
+
+typedef struct
+{
+ int account_bind_type;
+ char *account_name;
+ int receiving_server_type;
+ char *receiving_server_addr;
+ char *email_addr;
+ char *user_name;
+ char *password;
+ int retrieval_mode;
+ int port_num;
+ int use_security;
+ int sending_server_type;
+ char *sending_server_addr;
+ int sending_port_num;
+ int sending_auth;
+ int sending_security;
+ char *sending_user;
+ char *sending_password;
+ char *display_name;
+ char *reply_to_addr;
+ char *return_addr;
+ int account_id;
+ int keep_on_server;
+ int flag1; /* Specifies the downloading option 0 is subject only, 1 is text body, 2 is normal. */
+ int flag2;
+ int pop_before_smtp; /* POP before SMTP Authentication */
+ int apop; /* APOP authentication */
+ char *logo_icon_path; /* Account logo icon */
+ int preset_account; /* Preset account or not */
+ emf_option_t options; /* Specifies the Sending options */
+ int target_storage; /* Specifies the targetStorage. 0 is phone, 1 is MMC */
+ int check_interval; /* Specifies the check interval */
+ int my_account_id; /* Specifies accout id of my account */
+ int index_color; /* index color in RGB */
+ int sync_status; /* Sync Status */
+}
+emf_mail_account_tbl_t;
+
+typedef struct
+{
+ int account_id; /* MUST BE '0' : currently, only global rule supported. */
+ int rule_id;
+ int type; /* from/subject/body */
+ char *value;
+ int action_type; /* move/block/delete */
+ char *dest_mailbox; /* destination mailbox */
+ int flag1; /* for rule ON/OFF */
+ int flag2; /* For rule type INCLUDE/Exactly SAME AS */
+}
+emf_mail_rule_tbl_t;
+
+/* mail_box_tbl table entity */
+typedef struct
+{
+ int mailbox_id;
+ int account_id;
+ int local_yn;
+ char *mailbox_name;
+ emf_mailbox_type_e mailbox_type;
+ char *alias;
+ int sync_with_server_yn; /* whether mailbox is a sync IMAP mailbox */
+ int modifiable_yn; /* whether mailbox is able to be deleted/modified */
+ int unread_count; /* Removed. 16-Dec-2010, count unread mails at the moment it is required. not store in the DB */
+ int total_mail_count_on_local; /* Specifies the total number of mails in the mailbox in the local DB. count unread mails at the moment it is required. not store in the DB */
+ int total_mail_count_on_server; /* Specifies the total number of mails in the mailbox in the mail server */
+ int has_archived_mails;
+ int mail_slot_size;
+} emf_mailbox_tbl_t;
+
+/* mail_read_uid_tbl table entity */
+typedef struct
+{
+ int account_id;
+ char *local_mbox;
+ int local_uid;
+ char *mailbox_name; /* server mailbox */
+ char *s_uid; /* uid on server */
+ int data1; /* rfc822 size */
+ char *data2;
+ int flag; /* rule id */
+ int reserved;
+} emf_mail_read_mail_uid_tbl_t;
+
+typedef struct
+{
+ int mail_id;
+ int account_id;
+ char *mailbox_name;
+ int mailbox_type;
+ char *subject;
+ char *datetime; /* YYYYMMDDHHMMSS */
+ int server_mail_status;
+ char *server_mailbox_name;
+ char *server_mail_id;
+ char *message_id;
+ char *full_address_from;
+ char *full_address_reply;
+ char *full_address_to;
+ char *full_address_cc;
+ char *full_address_bcc;
+ char *full_address_return;
+ char *email_address_sender;
+ char *email_address_recipient;
+ char *alias_sender;
+ char *alias_recipient;
+ int body_download_status;
+ char *file_path_plain;
+ char *file_path_html;
+ int mail_size;
+ char flags_seen_field;
+ char flags_deleted_field;
+ char flags_flagged_field;
+ char flags_answered_field;
+ char flags_recent_field;
+ char flags_draft_field;
+ char flags_forwarded_field;
+ int DRM_status;
+ int priority;
+ int save_status;
+ int lock_status;
+ int report_status;
+ int attachment_count;
+ int inline_content_count;
+ int thread_id;
+ int thread_item_count;
+ char *preview_text;
+ int meeting_request_status;
+} emf_mail_tbl_t;
+
+/* mail_attachment_tbl entity */
+typedef struct
+{
+ int attachment_id;
+ char *attachment_name;
+ char *attachment_path;
+ int attachment_size;
+ int mail_id;
+ int account_id;
+ char *mailbox_name;
+ int file_yn;
+ int flag1; /* drm 1 */
+ int flag2; /* drm 2 */
+ int flag3; /* inline content status */
+#ifdef __ATTACHMENT_OPTI__
+ int encoding;
+ char *section;
+#endif
+} emf_mail_attachment_tbl_t;
+
+/* mail_contact_sync_tbl table entity */
+typedef struct
+{
+ char *contact_name;
+ char *email_address[15];
+ int storage_type;
+ int contact_id;
+} emf_mail_contact_sync_tbl_t;
+
+typedef enum {
+ RETRIEVE_ALL = 1, /* mail */
+ RETRIEVE_ENVELOPE, /* mail envelope */
+ RETRIEVE_SUMMARY, /* mail summary */
+ RETRIEVE_FIELDS_FOR_DELETE, /* account_id, mail_id, server_mail_yn, server_mailbox, server_mail_id */
+ RETRIEVE_ACCOUNT, /* account_id */
+ RETRIEVE_FLAG, /* mailbox, flag1, thread_id */
+ RETRIEVE_ID, /* mail_id */
+ RETRIEVE_ADDRESS, /* mail_id, contact_info */
+} emf_mail_field_type_t;
+
+typedef enum {
+ EMF_CONTACT_TYPE_FROM = 1,
+ EMF_CONTACT_TYPE_TO,
+ EMF_CONTACT_TYPE_CC,
+ EMF_CONTACT_TYPE_BCC,
+ EMF_CONTACT_TYPE_REPLY,
+ EMF_CONTACT_TYPE_RETURN,
+} emf_mail_contact_type_t;
+
+typedef struct _emf_mail_search_t {
+ char *key_type;
+ char *key_value;
+ struct _emf_mail_search_t *next;
+}
+emf_mail_search_t;
+
+typedef enum {
+ EMF_CREATE_DB_NORMAL = 0,
+ EMF_CREATE_DB_CHECK,
+}
+emf_create_db_t;
+
+typedef enum {
+ SET_TYPE_SET = 1,
+ SET_TYPE_UNION = 2,
+ SET_TYPE_MINUS = 3,
+ SET_TYPE_INTERSECT = 4 /* Not supported */
+} emf_set_type_t;
+
+
+/*****************************************************************************/
+/* Errors */
+/*****************************************************************************/
+#define EM_STORAGE_ERROR_NONE 1 /* There is no error. */
+#define EM_STORAGE_ERROR_INVALID_PARAM 2001 /* The parameter is invalid. */
+#define EM_STORAGE_ERROR_ACCOUNT_NOT_FOUND 2002 /* The expected account is not found. */
+#define EM_STORAGE_ERROR_MAIL_NOT_FOUND 2003 /* The expected mail is not found. */
+#define EM_STORAGE_ERROR_MAILBOX_NOT_FOUND 2004 /* The expected mailbox is not found. */
+#define EM_STORAGE_ERROR_ATTACHMENT_NOT_FOUND 2005 /* The expected attachment is not found. */
+#define EM_STORAGE_ERROR_RULE_NOT_FOUND 2006 /* The expected rule is not found. */
+#define EM_STORAGE_ERROR_CONTACT_NOT_FOUND 2007 /* The expected contact is not found. */
+#define EM_STORAGE_ERROR_FILE_NOT_FOUND 2008 /* The expected file is not found. */
+#define EM_STORAGE_ERROR_DATA_NOT_FOUND 2009 /* The expected data is not found. */
+#define EM_STORAGE_ERROR_NO_MORE_DATA 2010 /* There is no more data. */
+#define EM_STORAGE_ERROR_DATA_TOO_LONG 2011 /* The data is too long. */
+#define EM_STORAGE_ERROR_DATA_TOO_SMALL 2012 /* The data is too short. */
+#define EM_STORAGE_ERROR_OUT_OF_MEMORY 2013 /* The system is out of memory. */
+#define EM_STORAGE_ERROR_CONNECTION_FAILURE 2014 /* The agent fails to connect to server. */
+#define EM_STORAGE_ERROR_SYSTEM_FAILURE 2015 /* There is a system error. */
+#define EM_STORAGE_ERROR_DB_IS_FULL 2017 /* The db memory is full. */
+#define EM_STORAGE_ERROR_MAIL_MAX_COUNT 2016 /* there is a max count error. */
+#define EM_STORAGE_ERROR_DB_FAILURE 2018 /* EDB operation failure */
+#define EM_STORAGE_ERROR_ALREADY_EXISTS 2019
+#define EM_STORAGE_ERROR_MMC_NOT_FOUND 2020
+#define EM_STORAGE_ERROR_UNKNOWN 8000 /* There is a unknown error. */
+
+/*****************************************************************************
+ etc
+*****************************************************************************/
+#define EM_STORAGE_MAIL_MAX 5000
+#define EM_STORAGE_LIMITATION_FREE_SPACE (5) /* This value is 5MB */
+#define MAX_PW_FILE_NAME_LENGTH 128 /* password file name for secure storage */
+
+#ifdef __LOCAL_ACTIVITY__
+
+typedef enum
+{
+ ACTIVITY_FETCHIMAPFOLDER = 1, /* Fetch Mail server Activity */
+ ACTIVITY_DELETEMAIL, /* Delete Mail Activity */
+ ACTIVITY_MODIFYFLAG, /* Modify Mail flag Activity */
+ ACTIVITY_MODIFYSEENFLAG, /* Modify Mail seen flag Activity */
+ ACTIVITY_MOVEMAIL, /* Move Mail Activity */
+ ACTIVITY_DELETEALLMAIL, /* Delete All Mails activity */
+ ACTIVITY_COPYMAIL, /* Copy Mail Activity */
+ ACTIVITY_SAVEMAIL, /* Save Mail activity */
+ ACTIVITY_DELETEMAIL_SEND, /* New Delete Mail Activity added to be processed by send thread */
+}eActivity_type;
+
+
+/**
+ * emf_activity_tbl_t - Email Local activity Structure
+ *
+ */
+typedef struct
+{
+ int activity_id; /* Activity ID */
+ int account_id; /* Account ID */
+ int mail_id; /* Mail ID */
+ int activity_type; /* Local Activity Type */
+ char *server_mailid; /* Server Mail ID or Mailbox name */
+ char *src_mbox; /* Source Mailbox in case of mail_move */
+ char *dest_mbox; /* Destination Mailbox name in case of Mail move operation */
+
+} emf_activity_tbl_t;
+
+#endif
+
+EXPORT_API int em_storage_shm_file_init(const char *shm_file_name);
+
+
+/************** Database Management ***************/
+/*
+ * em_db_open
+ * description : open db and register busy handler
+ */
+EXPORT_API int em_db_open(sqlite3 **sqlite_handle, int *err_code);
+
+/*
+ * em_storage_db_open
+ *
+ * description : open db and set global variable sqlite_emmb
+ * arguments :
+ * return :
+ */
+EXPORT_API sqlite3* em_storage_db_open(int *err_code);
+
+/*
+ * em_storage_db_close
+ *
+ * description : close db with global variable sqlite_emmb
+ * arguments :
+ * return :
+ */
+EXPORT_API int em_storage_db_close(int *err_code);
+
+/*
+ * em_storage_open
+ *
+ * description : initialize storage manager
+ * arguments :
+ * return :
+ */
+EXPORT_API int em_storage_open(int *err_code);
+
+/*
+ * em_storage_close
+ *
+ * description : cleanup storage manager
+ * arguments :
+ * return :
+ */
+EXPORT_API int em_storage_close(int *err_code);
+
+/*
+ * em_storage_create_table
+ *
+ * description : create account/address table in database.
+ * arguments :
+ * return :
+ */
+EXPORT_API int em_storage_create_table(emf_create_db_t type, int *err_code);
+
+
+/**
+ * Check whether there is the same account information in the db
+ *
+ * @param[in] account account that
+ * @param[in] transaction If the argument is true, engine commits transaction or executes rollback.
+ * @param[out] err_code Error code.
+ * @remarks N/A
+ * @return This function returns true if there is no duplicated account. returns false and set error code if there are duplicated accounts or error
+ */
+EXPORT_API int em_storage_check_duplicated_account(emf_account_t *account, int transaction, int *err_code);
+
+
+/**
+ * Get number of accounts from account table.
+ *
+ * @param[out] count The number of accounts is saved here.
+ * @param[in] transaction If the argument is true, engine commits transaction or executes rollback.
+ * @remarks N/A
+ * @return This function returns 0 on success or error code on failure.
+ */
+EXPORT_API int em_storage_get_account_count(int *count, int transaction, int *err_code);
+
+/**
+ * Get account from account table.
+ *
+ * @param[in, out] select_num Upon entry, the argument contains the number of accounts to select.
+ Upon exit, it is set to the number of accounts to been selected.
+ * @param[out] account_list The selected accounts is saved here. this pointer must be freed after being used.
+ * @param[in] transaction If the argument is true, engine commits transaction or executes rollback.
+ * @remarks N/A
+ * @return This function returns 0 on success or error code on failure.
+ */
+EXPORT_API int em_storage_get_account_list(int *select_num, emf_mail_account_tbl_t **account_list, int transaction, int with_password, int *err_code);
+
+/*
+ * em_storage_get_account_by_name
+ *
+ * description : get account from account table by account name
+ * arguments :
+ * db : database pointer
+ * account_id : account id
+ * pulloption : option to specify fetching full or partial data
+ * account : buffer to hold selected account
+ * this buffer must be free after it has been used.
+ * return :
+ */
+/* sowmya.kr, 281209 Adding signature to options in emf_account_t changes */
+
+EXPORT_API int em_storage_get_account_by_id(int account_id, int pulloption, emf_mail_account_tbl_t **account, int transaction, int *err_code);
+
+
+/*
+ * em_storage_get_password_length_of_account
+ *
+ * description: get password length of account.
+ * arguments:
+ * account_id : account id
+ * password_length : password length
+ * return :
+ */
+
+EXPORT_API int em_storage_get_password_length_of_account(int account_id, int *password_length, int* err_code);
+
+/*
+ * em_storage_update_account
+ *
+ * description : change a account from account table
+ * arguments :
+ * account_id : account id
+ * account : buffer to hold selected account
+ * return :
+ */
+EXPORT_API int em_storage_update_account(int account_id, emf_mail_account_tbl_t *account, int transaction, int *err_code);
+
+/*
+ * em_storage_get_sync_status_of_account
+ *
+ * description : get a sync status field from account table
+ * arguments :
+ * account_id : account id
+ * result_sync_status : sync status value
+ * return :
+ */
+
+EXPORT_API int em_storage_get_sync_status_of_account(int account_id, int *result_sync_status,int *err_code);
+
+/*
+ * em_storage_update_sync_status_of_account
+ *
+ * description : update a sync status field from account table
+ * arguments :
+ * account_id : account id
+ * set_operator : set operater. refer emf_set_type_t
+ * sync_status : sync status value
+ * return :
+ */
+
+EXPORT_API int em_storage_update_sync_status_of_account(int account_id, emf_set_type_t set_operator, int sync_status, int transaction, int *err_code);
+
+/*
+ * em_storage_add_account
+ *
+ * description : add a account to account table
+ * arguments :
+ * return :
+ */
+EXPORT_API int em_storage_add_account(emf_mail_account_tbl_t *account, int transaction, int *err_code);
+
+/*
+ * em_storage_delete_account
+ *
+ * description : delete a account from account table
+ * arguments :
+ * db : database pointer
+ * account_id : account id to be deteted
+ * return :
+ */
+EXPORT_API int em_storage_delete_account(int account_id, int transaction, int *err_code);
+
+/*
+ * em_storage_free_account
+ *
+ * description : free local accout memory
+ * arguments :
+ * account_list : double pointer
+ * count : count of local account
+ * return :
+ */
+EXPORT_API int em_storage_free_account(emf_mail_account_tbl_t **account_list, int count, int *err_code);
+
+
+/************** Mailbox(Local box And Imap mailbox) Management ******************/
+
+/*
+ * em_storage_get_mailbox_count
+ *
+ * description : get number of mailbox from local mailbox table
+ * arguments :
+ * db : database pointer
+ * count : number of accounts
+ * return :
+ */
+EXPORT_API int em_storage_get_mailbox_count(int account_id, int local_yn, int *count, int transaction, int *err_code);
+
+/*
+ * em_storage_get_mailbox
+ *
+ * description : get local mailbox from local mailbox table
+ * arguments :
+ * db : database pointer
+ * sort_type : in - sorting type.
+ * select_num : in - number of selected account
+ * out - number to been selected
+ * mailbox_list : buffer to hold selected account
+ * this buffer must be free after it has been used.
+ * return :
+ */
+EXPORT_API int em_storage_get_mailbox(int account_id, int local_yn, email_mailbox_sort_type_t sort_type, int *select_num, emf_mailbox_tbl_t **mailbox_list, int transaction, int *err_code);
+
+/*
+ * em_storage_get_child_mailbox_list
+ *
+ * description : get child mailbox list from given mailbox
+ * arguments :
+ * account_id : in - account id
+ * parent_mailbox_name : in - parent_mailbox_name to fetch child list
+ * local_yn - in - local mailbox or not
+ * select_num - out : count of mailboxes
+ * mailbox_list - out : list of mailboxes
+ * err_code - out : error code, if any
+ */
+
+
+EXPORT_API int em_storage_get_child_mailbox_list(int account_id, char *parent_mailbox_name, int *select_num, emf_mailbox_tbl_t **mailbox_list, int transaction, int *err_code);
+
+/*
+ * em_storage_get_mailbox_by_name
+ *
+ * description : get local mailbox from local mailbox table by mailbox name
+ * arguments :
+ * db : database pointer
+ * mailbox_name : mailbox name
+ * mailbox : buffer to hold selected local mailbox
+ * this buffer must be free after it has been used.
+ * return :
+ */
+EXPORT_API int em_storage_get_mailbox_by_name(int account_id, int local_yn, char *mailbox_name, emf_mailbox_tbl_t **mailbox, int transaction, int *err_code);
+EXPORT_API int em_storage_get_mailbox_ex(int account_id, int local_yn, int with_count, int *select_num, emf_mailbox_tbl_t **mailbox_list, int transaction, int *err_code);
+EXPORT_API int em_storage_get_mailbox_by_mailbox_type(int account_id, emf_mailbox_type_e mailbox_type, emf_mailbox_tbl_t **mailbox, int transaction, int *err_code);
+EXPORT_API int em_storage_get_mailboxname_by_mailbox_type(int account_id, emf_mailbox_type_e mailbox_type, char **mailbox, int transaction, int *err_code);
+
+EXPORT_API int em_storage_update_mailbox_modifiable_yn(int account_id, int local_yn, char *mailbox_name, int modifiable_yn, int transaction, int *err_code);
+EXPORT_API int em_storage_update_mailbox_total_count(int account_id, char *mailbox_name, int total_count_on_server, int transaction, int *err_code);
+
+
+/*
+ * em_storage_update_mailbox
+ *
+ * description : change a account from account table
+ * arguments :
+ * db : database pointer
+ * mailbox_name : mailbox name
+ * mailbox : buffer to hold selected local mailbox
+ * return :
+ */
+EXPORT_API int em_storage_update_mailbox(int account_id, int local_yn, char *mailbox_name, emf_mailbox_tbl_t *mailbox, int transaction, int *err_code);
+
+/*
+ * em_storage_update_mailbox_type
+ *
+ * description : change a mailbox from mailbox tbl
+ * arguments :
+ * return :
+ */
+EXPORT_API int em_storage_update_mailbox_type(int account_id, int local_yn, char *mailbox_name, emf_mailbox_tbl_t *mailbox, int transaction, int *err_code);
+
+/*
+ * em_storage_add_mailbox
+ *
+ * description : add a local mailbox to local mailbox table
+ * arguments :
+ * return :
+ */
+EXPORT_API int em_storage_add_mailbox(emf_mailbox_tbl_t *mailbox, int transaction, int *err_code);
+
+/*
+ * em_storage_delete_mailbox
+ *
+ * description : delete a local mailbox from local mailbox table
+ * arguments :
+ * db : database pointer
+ * mailbox_name : mailbox name of record to be deteted
+ * return :
+ */
+EXPORT_API int em_storage_delete_mailbox(int account_id, int local_yn, char *mailbox_name, int transaction, int *err_code);
+
+EXPORT_API int em_storage_rename_mailbox(int account_id, char *old_mailbox_name, char *new_mailbox_name, int transaction, int *err_code);
+EXPORT_API int em_storage_get_overflowed_mail_id_list(int account_id, char *mailbox_name, int mail_slot_size, int **mail_id_list, int *mail_id_count, int transaction, int *err_code);
+EXPORT_API int em_storage_set_mail_slot_size(int account_id, char *mailbox_name, int new_slot_size, int transaction, int *err_code);
+
+EXPORT_API int em_storage_set_all_mailbox_modifiable_yn(int account_id, int modifiable_yn, int transaction, int *err_code);
+EXPORT_API int em_storage_get_mailbox_by_modifiable_yn(int account_id, int modifiable_yn, int *select_num, emf_mailbox_tbl_t **mailbox_list, int transaction, int *err_code);
+
+/*
+ * em_storage_free_mailbox
+ *
+ * description : free local mailbox memory
+ * arguments :
+ * mailbox_list : double pointer
+ * count : count of local mailbox
+ * return :
+ */
+EXPORT_API int em_storage_free_mailbox(emf_mailbox_tbl_t **mailbox_list, int count, int *err_code);
+
+
+/************** Read Mail UID Management ******************/
+
+
+
+EXPORT_API int em_storage_get_count_read_mail_uid(int account_id, char *mailbox_name, int *count, int transaction, int *err_code);
+
+
+/*
+ * em_storage_check_read_mail_uid
+ *
+ * description : check that this uid exists in uid table
+ * arguments :
+ * db : database pointer
+ * mailbox_name : mailbox name
+ * s_uid : uid string to be checked
+ * exist : variable to hold checking result. (0 : not exist, 1 : exist)
+ * return :
+ */
+EXPORT_API int em_storage_check_read_mail_uid(int account_id, char *mailbox_name, char *uid, int *exist, int transaction, int *err_code);
+
+/*
+ * em_storage_get_read_mail_size
+ *
+ * description : get mail size from read mail uid
+ * arguments :
+ * db : database pointer
+ * local_mbox : local mailbox name
+ * local_uid : mail uid of local mailbox
+ * mailbox_name : server mailbox name
+ * uid : mail uid string of server mail
+ * read_mail_uid : variable to hold read mail uid information
+ * return :
+ */
+EXPORT_API int em_storage_get_downloaded_list(int account_id, char *local_mbox, emf_mail_read_mail_uid_tbl_t **read_mail_uid, int *count, int transaction, int *err_code);
+
+EXPORT_API int em_storage_get_downloaded_mail(int mail_id, emf_mail_tbl_t **mail, int transaction, int *err_code);
+
+/*
+ * em_storage_get_read_mail_size
+ *
+ * description : get mail size from read mail uid
+ * arguments :
+ * db : database pointer
+ * mailbox_name : mailbox name
+ * s_uid : mail uid string
+ * size : variable to hold mail size
+ * return :
+ */
+EXPORT_API int em_storage_get_downloaded_mail_size(int account_id, char *local_mbox, int local_uid, char *mailbox_name, char *uid, int *mail_size, int transaction, int *err_code);
+
+/*
+ * em_storage_add_downloaded_mail
+ *
+ * description : add read mail uid
+ * arguments :
+ * return :
+ */
+EXPORT_API int em_storage_add_downloaded_mail(emf_mail_read_mail_uid_tbl_t *read_mail_uid, int transaction, int *err_code);
+
+/*
+ * em_storage_change_read_mail_uid
+ *
+ * description : modify read mail uid
+ * arguments :
+ * return :
+ */
+EXPORT_API int em_storage_change_read_mail_uid(int account_id, char *local_mbox, int local_uid, char *mailbox_name, char *uid,
+ emf_mail_read_mail_uid_tbl_t *read_mail_uid, int transaction, int *err_code);
+
+/*
+ * em_storage_remove_downloaded_mail
+ *
+ * description :
+ * arguments :
+ * return :
+ */
+EXPORT_API int em_storage_remove_downloaded_mail(int account_id, char *mailbox_name, char *uid, int transaction, int *err_code);
+
+
+EXPORT_API int em_storage_update_read_mail_uid(int mail_id, char *new_server_uid, char *mbox_name, int *err_code);
+
+/*
+ * free memroy
+ */
+EXPORT_API int em_storage_free_read_mail_uid(emf_mail_read_mail_uid_tbl_t **read_mail_uid, int count, int *err_code);
+
+
+
+/************** Rules(Filtering) Management ******************/
+
+/*
+ * em_storage_get_rule_count
+ *
+ * description : get number of rules from rule table
+ * arguments :
+ * db : database pointer
+ * count : number of accounts
+ * return :
+ */
+EXPORT_API int em_storage_get_rule_count(int account_id, int *count, int transaction, int *err_code);
+
+/*
+ * em_storage_get_rule
+ *
+ * description : get rules from rule table
+ * arguments :
+ * db : database pointer
+ * start_idx : the first index to be selected (min : 0)
+ * select_num : in - number of selected account
+ * out - number to been selected
+ * is_completed : is completed ?
+ * return :
+ */
+EXPORT_API int em_storage_get_rule(int account_id, int type, int start_idx, int *select_num, int *is_completed, emf_mail_rule_tbl_t **rule_list, int transaction, int *err_code);
+
+/*
+ * em_storage_get_rule
+ *
+ * description : get rules from rule table
+ * arguments :
+ * return :
+ */
+EXPORT_API int em_storage_get_rule_by_id(int account_id, int rule_id, emf_mail_rule_tbl_t **rule, int transaction, int *err_code);
+
+/*
+ * em_storage_change_rule
+ *
+ * description : change a account from account table
+ * arguments :
+ * db : database pointer
+ * mailbox_name : mailbox name
+ * rule : buffer to hold selected rule
+ * return :
+ */
+EXPORT_API int em_storage_change_rule(int account_id, int rule_id, emf_mail_rule_tbl_t *rule, int transaction, int *err_code);
+
+/*
+ * em_storage_find_rule
+ *
+ * description : find a rule already exists
+ * arguments :
+ * return :
+ */
+EXPORT_API int em_storage_find_rule(emf_mail_rule_tbl_t *rule, int transaction, int *err_code);
+
+/*
+ * em_storage_add_rule
+ *
+ * description : add a rule to rule table
+ * arguments :
+ * return :
+ */
+EXPORT_API int em_storage_add_rule(emf_mail_rule_tbl_t *rule, int transaction, int *err_code);
+
+/*
+ * em_storage_delete_rule
+ *
+ * description : delete a rule from rule table
+ * arguments :
+ * db : database pointer
+ * rule : rule to be deteted
+ * return :
+ */
+EXPORT_API int em_storage_delete_rule(int account_id, int rule_id, int transaction, int *err_code);
+
+/*
+ * em_storage_free_rule
+ *
+ * description : free rule memory
+ * arguments :
+ * count : count of rule
+ * return :
+ */
+EXPORT_API int em_storage_free_rule(emf_mail_rule_tbl_t **rule_list, int count, int *err_code);
+
+
+EXPORT_API int em_storage_filter_mails_by_rule(int account_id, char *dest_mailbox_name, emf_mail_rule_tbl_t *rule, int **filtered_mail_id_list, int *count_of_mails, int *err_code);
+
+/************** Mail Management ******************/
+
+/*
+ * em_storage_get_mail_count
+ *
+ * description : get mail total and unseen count from mail table
+ * arguments :
+ * total : total count
+ * unseen : unseen mail count
+ * return :
+ */
+EXPORT_API int em_storage_get_mail_count(int account_id, const char *mailbox, int *total, int *unseen, int transaction, int *err_code);
+
+/*
+ * em_storage_get_mail_by_id
+ *
+ * description : get mail from mail table by mail id
+ * arguments :
+ * mail_id : mail id
+ * mail : double pointer to hold mail
+ * return :
+ */
+EXPORT_API int em_storage_get_mail_by_id(int mail_id, emf_mail_tbl_t **mail, int transaction, int *err_code);
+
+/*
+ * em_storage_get_mail
+ *
+ * description : get mail from mail table by mail sequence
+ * arguments :
+ * account_id : account id
+ * mailbox : mailbox name
+ * mail_no : mail sequence number (not mail id)
+ * mail : double pointer to hold mail
+ * return :
+ */
+EXPORT_API int em_storage_get_mail_field_by_id(int mail_id, int type, emf_mail_tbl_t **mail, int transaction, int *err_code);
+
+/*
+ * em_storage_get_mail_field_by_multiple_mail_id
+ *
+ * description :
+ * arguments :
+ * mail_ids :
+ * number_of_mails :
+ * type :
+ * mail :
+ * transaction :
+ * err_code :
+ * return :
+ */
+EXPORT_API int em_storage_get_mail_field_by_multiple_mail_id(int mail_ids[], int number_of_mails, int type, emf_mail_tbl_t** mail, int transaction, int *err_code);
+
+/*
+ * em_storage_query_mail_list
+ *
+ * description : query mail list information
+ */
+EXPORT_API int em_storage_query_mail_list(const char *conditional_clause, int transaction, emf_mail_list_item_t** result_mail_list, int *result_count, int *err_code);
+
+/*
+ * em_storage_query_mail_tbl
+ *
+ * description : query mail table information
+ */
+EXPORT_API int em_storage_query_mail_tbl(const char *conditional_clause, int transaction, emf_mail_tbl_t** result_mail_tbl, int *result_count, int *err_code);
+
+/*
+ * em_storage_get_mail_list
+ *
+ * description : search mail list information
+ */
+EXPORT_API int em_storage_get_mail_list(int account_id, const char *mailbox_name, emf_email_address_list_t* addr_list, int thread_id, int start_index, int limit_count, int search_type, const char *search_value, emf_sort_type_t sorting, int transaction, emf_mail_list_item_t** mail_list, int *result_count, int *err_code);
+/*
+ * em_storage_get_mails
+ *
+ * description : search mail list information
+ */
+EXPORT_API int em_storage_get_mails(int account_id, const char *mailbox_name, emf_email_address_list_t* addr_list, int thread_id, int start_index, int limit_count, emf_sort_type_t sorting, int transaction, emf_mail_tbl_t** mail_list, int *result_count, int *err_code);
+EXPORT_API int em_storage_get_searched_mail_list(int account_id, const char *mailbox_name, int thread_id, int search_type, const char *search_value, int start_index, int limit_count, emf_sort_type_t sorting, int transaction, emf_mail_list_item_t **mail_list, int *result_count, int *err_code);
+EXPORT_API int em_storage_get_maildata_by_servermailid(int account_id, char *server_mail_id, emf_mail_tbl_t **mail, int transaction, int *err_code);
+EXPORT_API int em_storage_get_latest_unread_mailid(int account_id, int *mail_id, int *err_code);
+
+
+/**
+ * Prepare mail search.
+ *
+ * @param[in] search Specifies the searching condition.
+ * @param[in] account_id Specifies the account id. if 0, all accounts.
+ * @param[in] mailbox Specifies the mailbox name. if NULL, all mailboxes.
+ * @param[in] sorting Specifies the sorting condition.
+ * @param[out] search_handle the searching handle is saved here.
+ * @param[out] searched the result count is saved here.
+ * @remarks N/A
+ * @return This function returns 0 on success or error code on failure.
+ */
+EXPORT_API int em_storage_mail_search_start(emf_mail_search_t *search, int account_id, char *mailbox, int sorting, int *search_handle, int *searched, int transaction, int *err_code);
+
+/*
+ * em_storage_mail_search_result
+ *
+ * description : retrieve mail as searching result
+ * arguments :
+ * search_handle : handle to been gotten from em_storage_mail_search_start
+ * mail : double pointer to hold mail
+ * return :
+ */
+EXPORT_API int em_storage_mail_search_result(int search_handle, emf_mail_field_type_t type, void **data, int transaction, int *err_code);
+
+/*
+ * em_storage_mail_search_end
+ *
+ * description : finish searching
+ * arguments :
+ * search_handle : handle to be finished
+ * return :
+ */
+EXPORT_API int em_storage_mail_search_end(int search_handle, int transaction, int *err_code);
+
+
+
+/*
+ * em_storage_set_field_of_mails_with_integer_value
+ *
+ * description : update a filed of mail
+ * arguments :
+ * account_id : Specifies the account id.
+ * mail_ids : mail id list to be changed
+ * mail_ids_count : count of mail list
+ * field_name : specified field name
+ * value : specified value
+ * return :
+ */
+EXPORT_API int em_storage_set_field_of_mails_with_integer_value(int account_id, int mail_ids[], int mail_ids_count, char *field_name, int value, int transaction, int *err_code);
+
+/*
+ * em_storage_change_mail_field
+ *
+ * description : update partial mail data
+ * arguments :
+ * mail_id : mail id
+ * type : changing type
+ * mail : mail pointer
+ * return :
+ */
+EXPORT_API int em_storage_change_mail_field(int mail_id, emf_mail_change_type_t type, emf_mail_tbl_t *mail, int transaction, int *err_code);
+
+/*
+ * em_storage_increase_mail_id
+ *
+ * description : increase unique mail id
+ * arguments :
+ * mail_id : pointer to store the unique id
+ * return :
+ */
+
+/*
+ * em_storage_change_mail
+ *
+ * description : update mail
+ * arguments :
+ * mail_id : mail id to be changed
+ * mail : mail pointer
+ * return :
+ */
+EXPORT_API int em_storage_change_mail(int mail_id, emf_mail_tbl_t *mail, int transaction, int *err_code);
+EXPORT_API int em_storage_clean_save_status(int save_status, int *err_code);
+EXPORT_API int em_storage_update_server_uid(char *old_server_uid, char *new_server_uid, int *err_code);
+EXPORT_API int em_storage_modify_mailbox_of_mails(char *old_mailbox_name, char *new_mailbox_name, int transaction, int *err_code);
+
+EXPORT_API int em_storage_increase_mail_id(int *mail_id, int transaction, int *err_code);
+
+/*
+ * em_storage_add_mail
+ *
+ * description : add a mail to mail table
+ * arguments :
+ * mail : mail pointer to be inserted
+ * get_id : must get uinque id in function
+ * return :
+ */
+EXPORT_API int em_storage_add_mail(emf_mail_tbl_t *mail, int get_id, int transaction, int *err_code);
+
+/*
+ * em_storage_move_multiple_mails
+ *
+ * description :
+ * arguments :
+ * account_id :
+ * target_mailbox_name :
+ * mail_ids :
+ * number_of_mails :
+ * transaction :
+ * err_code :
+ * return :
+ */
+EXPORT_API int em_storage_move_multiple_mails(int account_id, char *target_mailbox_name, int mail_ids[], int number_of_mails, int transaction, int *err_code);
+
+/*
+ * em_storage_delete_mail
+ *
+ * description : delete mail from mail table
+ * arguments :
+ * mail_id : mail id to be deleted. if 0, all mail will be deleted.
+ * from_server : delete mail on server.
+ * return :
+ */
+EXPORT_API int em_storage_delete_mail(int mail_id, int from_server, int transaction, int *err_code);
+
+/*
+ * em_storage_delete_mail_by_account
+ *
+ * description : delete mail from mail table by account id
+ * arguments :
+ * account_id : account id.
+ * return :
+ */
+EXPORT_API int em_storage_delete_mail_by_account(int account_id, int transaction, int *err_code);
+
+/*
+ * em_storage_delete_mail
+ *
+ * description : delete mail from mail table
+ * arguments :
+ * account_id : account id.
+ * mbox : mail box
+ * return :
+ */
+EXPORT_API int em_storage_delete_mail_by_mailbox(int account_id, char *mbox, int transaction, int *err_code);
+
+/*
+ * em_storage_delete_multiple_mails
+ *
+ * description :
+ * arguments :
+ * mail_ids :
+ * number_of_mails :
+ * transaction :
+ * err_code :
+ * return :
+ */
+EXPORT_API int em_storage_delete_multiple_mails(int mail_ids[], int number_of_mails, int transaction, int *err_code);
+
+/*
+ * em_storage_free_mail
+ *
+ * description : free memory
+ * arguments :
+ * mail_list : mail array
+ * count : the number of array element
+ * return :
+ */
+EXPORT_API int em_storage_free_mail(emf_mail_tbl_t **mail_list, int count, int *err_code);
+
+/*
+ * em_storage_get_attachment
+ *
+ * description : get attachment from attachment table
+ * arguments :
+ * mail_id : mail id
+ * no : attachment sequence
+ * attachment : double pointer to hold attachment data
+ * return :
+ */
+EXPORT_API int em_storage_get_attachment_count(int mail_id, int *count, int transaction, int *err_code);
+
+/*
+ * em_storage_get_attachment_list
+ *
+ * description : get attachment list from attachment table
+ * arguments :
+ * input_mail_id : mail id
+ * input_transaction : transaction option
+ * attachment_list : result attachment list
+ * output_attachment_count : result attachment count
+ * return : This function returns EM_STORAGE_ERROR_NONE on success or error code (refer to EM_STORAGE_ERROR__XXX) on failure.
+ *
+ */
+EXPORT_API int em_storage_get_attachment_list(int input_mail_id, int input_transaction, emf_mail_attachment_tbl_t** output_attachment_list, int *output_attachment_count);
+
+
+/*
+ * em_storage_get_attachment
+ *
+ * description : get attachment from attachment table
+ * arguments :
+ * mail_id : mail id
+ * no : attachment id
+ * attachment : double pointer to hold attachment data
+ * return :
+ */
+EXPORT_API int em_storage_get_attachment(int mail_id, int no, emf_mail_attachment_tbl_t **attachment, int transaction, int *err_code);
+
+/*
+ * em_storage_get_attachment
+ *
+ * description : get nth-attachment from attachment table
+ * arguments :
+ * mail_id : mail id
+ * nth : index of the desired attachment (min : 1)
+ * attachment : double pointer to hold attachment data
+ * return :
+ */
+EXPORT_API int em_storage_get_attachment_nth(int mail_id, int nth, emf_mail_attachment_tbl_t **attachment, int transaction, int *err_code);
+
+/*
+ * em_storage_change_attachment_field
+ *
+ * description : update partial mail attachment data
+ * arguments :
+ * mail_id : mail id
+ * type : changing type
+ * mail : mail pointer
+ * return :
+ */
+EXPORT_API int em_storage_change_attachment_field(int mail_id, emf_mail_change_type_t type, emf_mail_attachment_tbl_t *attachment, int transaction, int *err_code);
+
+/*
+ * em_storage_change_attachment_mbox
+ *
+ * description : update mailbox from attahcment table
+ * arguments :
+ * account_id : account id
+ * old_mailbox_name : old mail box
+ * new_mailbox_name : new mail box
+ * return :
+ */
+EXPORT_API int em_storage_change_attachment_mbox(int account_id, char *old_mailbox_name, char *new_mailbox_name, int transaction, int *err_code);
+
+/* Get new attachment id */
+/*
+ * em_storage_get_new_attachment_no
+ *
+ * description : Get new attachment id
+ * arguments :
+ * attachment_no : attachment id pointer
+ * return :
+ */
+
+EXPORT_API int em_storage_get_new_attachment_no(int *attachment_no, int *err_code);
+
+/* insert attachment to mail attachment table */
+/*
+ * em_storage_add_attachment
+ *
+ * description : insert a attachment to attachment table
+ * arguments :
+ * attachment : attachment pointer
+ * return :
+ */
+EXPORT_API int em_storage_add_attachment(emf_mail_attachment_tbl_t *attachment, int iscopy, int transaction, int *err_code);
+
+
+EXPORT_API int em_storage_update_attachment(emf_mail_attachment_tbl_t *attachment, int transaction, int *err_code);
+
+/* delete a mail from mail table */
+/*
+ * em_storage_delete_attachment_on_db
+ *
+ * description : delete attachment from attachment table
+ * arguments :
+ * mail_id : mail id to contain attachment
+ * no : attachment sequence number
+ * return :
+ */
+EXPORT_API int em_storage_delete_attachment_on_db(int mail_id, int no, int transaction, int *err_code);
+
+/*
+ * em_storage_delete_attachment_all_on_db
+ *
+ * description : delete attachment from mail table
+ * arguments :
+ * account_id : account id.
+ * mbox : mail box
+ * return :
+ */
+EXPORT_API int em_storage_delete_attachment_all_on_db(int account_id, char *mbox, int transaction, int *err_code);
+
+/*
+ * em_storage_free_attachment
+ *
+ * description : free memory
+ * arguments :
+ * mail_list : mail array
+ * count : the number of array element
+ * return :
+ */
+EXPORT_API int em_storage_free_attachment(emf_mail_attachment_tbl_t **attachment_list, int count, int *err_code);
+
+/* em_storage_get_mail_count_with_draft_flag - Send number of mails in a mailbox with draft flag enabled */
+EXPORT_API int em_storage_get_mail_count_with_draft_flag(int account_id, const char *mailbox, int *total, int transaction, int *err_code);
+
+/* em_storage_get_mail_count_on_sending - Send number of mails being sent in a mailbox (status == EMF_MAIL_STATUS_SENDING) */
+EXPORT_API int em_storage_get_mail_count_on_sending(int account_id, const char *mailbox, int *total, int transaction, int * err_code);
+
+EXPORT_API int em_storage_is_mailbox_full(int account_id, emf_mailbox_t *mailbox, int *result, int *err_code);
+
+EXPORT_API int em_storage_get_max_mail_count();
+
+EXPORT_API int em_storage_mail_get_total_diskspace_usage(unsigned long *total_usage, int transaction, int *err_code);
+
+
+/**
+ * begin a transaction.
+ *
+ * @param[in] d1 Reserved.
+ * @param[in] d2 Reserved.
+ * @remarks em_storage_commit_transaction or em_storage_commit_transaction must be called after this function.
+ * @return This function returns 0 on success or error code on failure.
+ */
+
+EXPORT_API int em_storage_begin_transaction(void *d1, void *d2, int *err_code);
+
+/**
+ * commit a transaction.
+ *
+ * @param[in] d1 Reserved.
+ * @param[in] d2 Reserved.
+ * @remarks N/A
+ * @return This function returns 0 on success or error code on failure.
+ */
+EXPORT_API int em_storage_commit_transaction(void *d1, void *d2, int *err_code);
+
+/**
+ * rollback db.
+ *
+ * @param[in] d1 Reserved.
+ * @param[in] d2 Reserved.
+ * @remarks N/A
+ * @return This function returns 0 on success or error code on failure.
+ */
+EXPORT_API int em_storage_rollback_transaction(void *d1, void *d2, int *err_code);
+
+/**
+ * clear mail data from db.
+ *
+ * @param[in] transaction
+ * @param[out] err_code
+ * @remarks N/A
+ * @return This function returns 0 on success or error code on failure.
+ */
+
+EXPORT_API int em_storage_clear_mail_data(int transaction, int *err_code);
+
+/*
+ * em_storage_get_save_name
+ *
+ * description : get file name for saving data
+ * arguments :
+ * account_id : account id
+ * mail_id : mail id
+ * atch_id : attachment id
+ * fname : file name
+ * name_buf : buffer to hold file name. (MAX : 512Bytes)
+ * return :
+ */
+EXPORT_API int em_storage_get_save_name(int account_id, int mail_id, int atch_id, char *fname, char *name_buf, int *err_code);
+
+/*
+ * em_storage_get_dele_name
+ *
+ * description : get a name for deleting contents from file system.
+ * arguments :
+ * account_id : account id
+ * mail_id : mail id
+ * atch_id : attachment id
+ * fname : reserved
+ * name_buf : buffer to hold file name. (MAX : 512Bytes)
+ * return :
+ */
+EXPORT_API int em_storage_get_dele_name(int account_id, int mail_id, int atch_id, char *fname, char *name_buf, int *err_code);
+
+/*
+ * em_storage_create_dir
+ *
+ * description : create directory
+ * arguments :
+ * name_buf : buffer to hold file name. (MAX : 512Bytes)
+ * no : attachment no.
+ * return :
+ */
+EXPORT_API int em_storage_create_dir(int account_id, int mail_id, int atch_id, int *err_code);
+
+/*
+ * em_storage_copy_file
+ *
+ * description : copy a attachment file
+ * arguments :
+ * src_file : source file
+ * dst_file : destination file
+ * return :
+ */
+EXPORT_API int em_storage_copy_file(char *src_file, char *dst_file, int sync_file, int *err_code);
+
+/*
+ * em_storage_move_file
+ *
+ * description : move a file
+ * arguments :
+ * src_file : source file
+ * dst_file : destination file
+ * return :
+ */
+EXPORT_API int em_storage_move_file(char *src_file, char *dst_file, int sync_status, int *err_code);
+
+/*
+ * em_storage_move_file
+ *
+ * description : delete a file
+ * arguments :
+ * src_file : file to be deleted
+ * return :
+ */
+EXPORT_API int em_storage_delete_file(char *src_file, int *err_code);
+
+/*
+ * em_storage_delete_dir
+ *
+ * description : delete a directory
+ * arguments :
+ * src_dir : directory to be deleted
+ * return :
+ */
+EXPORT_API int em_storage_delete_dir(char *src_dir, int *err_code);
+
+
+
+EXPORT_API void em_storage_flush_db_cache();
+EXPORT_API int em_storage_test(int mail_id, int account_id, char *full_address_to, char *full_address_cc, char *full_address_bcc, int *err_code);
+
+EXPORT_API int em_storage_sleep_on_off(int on, int *error_code);
+EXPORT_API int em_storage_dimming_on_off(int on, int *error_code);
+#ifdef USE_POWERMGMT
+EXPORT_API int em_storage_power_management(int *error_code);
+#endif
+
+
+
+/**
+ * em_storage_notify_storage_event - Notification for storage related operations
+ *
+ */
+EXPORT_API int em_storage_notify_storage_event(emf_noti_on_storage_event event_type, int data1, int data2 , char *data3, int data4);
+
+/**
+ * em_storage_notify_network_event - Notification for network related operations
+ *
+ */
+EXPORT_API int em_storage_notify_network_event(emf_noti_on_network_event event_type, int data1, char *data2, int data3, int data4);
+EXPORT_API int em_storage_get_sender_list(int account_id, const char *mailbox_name, int search_type, const char *search_value, emf_sort_type_t sorting, emf_sender_list_t** sender_list, int *sender_count, int *err_code);
+EXPORT_API int em_storage_free_sender_list(emf_sender_list_t **sender_list, int count);
+
+/* Handling Thread mail */
+EXPORT_API int em_storage_get_thread_information(int thread_id, emf_mail_tbl_t **mail_table_data, int transaction, int *err_code);
+EXPORT_API int em_storage_get_thread_id_of_thread_mails(emf_mail_tbl_t *mail_table_data, int *thread_id, int *result_latest_mail_id_in_thread, int *thread_item_count);
+EXPORT_API int em_storage_get_thread_id_by_mail_id(int mail_id, int *thread_id, int *err_code);
+EXPORT_API int em_storage_update_latest_thread_mail(int account_id, int thread_id, int latest_mail_id, int thread_item_count, int transaction, int *err_code);
+
+
+#ifdef _CONTACT_SUBSCRIBE_CHANGE_
+EXPORT_API int em_storage_contact_sync_insert(int contact_id, char *display_name, GSList *email_list, int *err_code);
+EXPORT_API int em_storage_contact_sync_update(int contact_id, char *display_name, GSList *email_list, int *err_code);
+EXPORT_API int em_storage_contact_sync_delete(int contact_id, int *err_code);
+#endif
+
+#ifdef __FEATURE_PARTIAL_BODY_DOWNLOAD__
+
+#define BULK_PARTIAL_BODY_DOWNLOAD_COUNT 10
+enum
+{
+ ACCOUNT_IDX_MAIL_PARTIAL_BODY_ACTIVITY_TBL = 0,
+ MAIL_IDX_IN_MAIL_PARTIAL_BODY_ACTIVITY_TBL,
+ SERVER_MAIL_IDX_IN_MAIL_PARTIAL_BODY_ACTIVITY_TBL,
+ ACTIVITY_IDX_IN_MAIL_PARTIAL_BODY_ACTIVITY_TBL,
+ ACTIVITY_TYPE_IDX_IN_MAIL_PARTIAL_BODY_ACTIVITY_TBL,
+ MAILBOX_NAME_IDX_IN_MAIL_PARTIAL_BODY_ACTIVITY_TBL,
+};
+
+
+EXPORT_API int em_storage_get_pbd_activity_data(int account_id, char *mailbox_name, emf_event_partial_body_thd** event_start, int *count, int transaction, int *err_code);
+EXPORT_API int em_storage_add_pbd_activity(emf_event_partial_body_thd *local_activity, int *activity_id, int transaction, int *err_code);
+EXPORT_API int em_storage_get_pbd_mailbox_list(int account_id, char ***mailbox_list, int *count, int transaction, int *err_code);
+EXPORT_API int em_storage_get_pbd_account_list(int **account_list, int *count, int transaction, int *err_code);
+EXPORT_API int em_storage_get_pbd_activity_count(int *activity_id_count, int transaction, int *err_code);
+EXPORT_API int em_storage_delete_full_pbd_activity_data(int account_id, int transaction, int *err_code);
+EXPORT_API int em_storage_delete_pbd_activity(int account_id, int mail_id, int activity_id, int transaction, int *err_code);
+EXPORT_API int em_storage_get_mailbox_pbd_activity_count(int account_id, char *mailbox_name, int *activity_count, int transaction, int *err_code);
+EXPORT_API int em_storage_update_pbd_activity(char *old_server_uid, char *new_server_uid, char *mbox_name, int *err_code);
+EXPORT_API int em_storage_create_file(char *buf, size_t file_size, char *dst_file, int *err_code);
+
+#endif
+
+EXPORT_API int em_storage_free_address_info_list(emf_address_info_list_t **address_info_list);
+
+
+EXPORT_API void em_storage_create_dir_if_delete();
+EXPORT_API int em_storage_get_emf_error_from_em_storage_error(int error);
+
+EXPORT_API void *em_core_malloc(unsigned len);
+
+
+#ifdef __FEATURE_BULK_DELETE_MOVE_UPDATE_REQUEST_OPTI__
+EXPORT_API int em_storage_update_read_mail_uid_by_server_uid(char *old_server_uid, char *new_server_uid, char *mbox_name, int *err_code);
+
+/**
+ * @fn em_storage_get_id_set_from_mail_ids(int mail_ids[], int mail_id_count, emf_id_set_t **server_uids, int *id_set_count, int *err_code);
+ * Prepare an array of mail_id and corresponding server mail id.
+ *
+ *@author h.gahlaut@samsung.com
+ * @param[in] mail_ids Specifies the comma separated string of mail_ids. Maximaum size of string should be less than or equal to (QUERY_SIZE - 88)
+ * where 88 is the length of fixed keywords including ending null character in the QUERY to be formed
+ * @param[out] idset Returns the array of mail_id and corresponding server_mail_id sorted by server_mail_ids in ascending order
+ * @param[out] id_set_count Returns the no. of cells in idset array i.e. no. of sets of mail_ids and server_mail_ids
+ * @param[out] err_code Returns the error code.
+ * @remarks An Example of Query to be exexuted in this API :
+ * SELECT local_uid, s_uid from mail_read_mail_uid_tbl where local_uid in (12, 13, 56, 78);
+ * @return This function returns true on success or false on failure.
+ */
+
+EXPORT_API int em_storage_get_id_set_from_mail_ids(char *mail_ids, emf_id_set_t **idset, int *id_set_count, int *err_code);
+
+#endif
+
+/**
+ * @fn em_storage_filter_mails_by_rule(int account_id, char dest_mailbox_name, emf_rule_t *rule, int **filtered_mail_id_list, int *count_of_mails, int err_code)
+ * Move mails by specified rule for spam filtering.
+ *
+ * @author kyuho.jo@samsung.com
+ * @param[in] account_id Account id of the mails and the mailboxes.
+ * @param[in] dest_mailbox_name Mailbox name of spam mailbox.
+ * @param[in] rule Filtering rule.
+ * @param[out] filtered_mail_id_list Mail id list which are filtered by the rule.
+ * @param[out] count_of_mails Count of mails which are filtered by the rule.
+ * @param[out] err_code Returns the error code.
+
+ * @remarks
+ * @return This function returns true on success or false on failure.
+ */
+
+EXPORT_API int em_storage_add_meeting_request(int account_id, char *mailbox_name, emf_meeting_request_t *meeting_req, int transaction, int *err_code);
+EXPORT_API int em_storage_get_meeting_request(int mail_id, emf_meeting_request_t **meeting_req, int transaction, int *err_code);
+EXPORT_API int em_storage_update_meeting_request(emf_meeting_request_t *meeting_req, int transaction, int *err_code);
+EXPORT_API int em_storage_change_meeting_request_field(int account_id, char *mailbox_name, emf_mail_change_type_t type, emf_meeting_request_t *meeting_req, int transaction, int *err_code);
+EXPORT_API int em_storage_change_meeting_request_mailbox(int account_id, char *old_mailbox_name, char *new_mailbox_name, int transaction, int *err_code);
+EXPORT_API int em_storage_delete_meeting_request(int account_id, int mail_id, char *mailbox_name, int transaction, int *err_code);
+EXPORT_API int em_storage_free_meeting_request(emf_meeting_request_t **meeting_req, int count, int *err_code);
+
+#ifdef __LOCAL_ACTIVITY__
+/*
+*em_storage_get_next_activity_id
+*
+*description : get an activity id for a new activity
+*/
+EXPORT_API int em_storage_get_next_activity_id(int *activity_id, int *err_code);
+
+ /*
+ *em_storage_get_activity_id_list
+ *description : get the list of activity ids
+ *arguments :
+ *return :
+ *
+ */
+ EXPORT_API int em_storage_get_activity_id_list(int account_id, int **activity_id_list, int *activity_count, int lowest_activity_type, int highest_activity_type, int transaction, int*err_code);
+ /*
+ * em_storage_add_activity
+ *
+ * description : add an activity to activity table
+ * arguments :
+ * return :
+ */
+EXPORT_API int em_storage_add_activity(emf_activity_tbl_t *local_activity, int transaction, int *err_code);
+
+/**
+ * em_storage_get_activity - Get the Local activity from the Mail activity table
+ *
+ */
+EXPORT_API int em_storage_get_activity(int account_id, int activity_id, emf_activity_tbl_t **activity_list, int *select_num, int transaction, int *err_code);
+
+/**
+ * em_storage_delete_local_activity - Deletes the Local acitivity Generated based on activity_type
+ * or based on server mail id
+ *
+ */
+EXPORT_API int em_storage_delete_local_activity(emf_activity_tbl_t *local_activity, int transaction, int *err_code);
+
+/**
+ * em_storage_free_local_activity - Free the allocated Activity data
+ *
+ *
+ */
+EXPORT_API int em_storage_free_local_activity(emf_activity_tbl_t **local_activity_list, int count, int *err_code);
+
+/**
+ * em_storage_free_activity_id_list - Free the allocated Activity List data
+ *
+ *
+ */
+EXPORT_API int em_storage_free_activity_id_list(int *activity_id_list, int *error_code);
+
+#endif
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* __EM_STORAGE_H__ */
+/* EOF */
diff --git a/email-core/include/em-core-account.h b/email-core/include/em-core-account.h
new file mode 100755
index 0000000..4cc92a4
--- /dev/null
+++ b/email-core/include/em-core-account.h
@@ -0,0 +1,83 @@
+/*
+* email-service
+*
+* Copyright (c) 2000 - 2011 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.
+*
+*/
+
+
+
+/******************************************************************************
+ * File : em-core-account.h
+ * Desc : Account Management
+ * * Auth :
+ * * History :
+ * 2010.08.25 : created
+ *****************************************************************************/
+#ifndef _EM_CORE_ACCOUNT_H_
+#define _EM_CORE_ACCOUNT_H_
+
+#include "emf-types.h"
+#include "em-core-types.h"
+#include "em-storage.h"
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif /* __cplusplus */
+
+EXPORT_API emf_account_t *em_core_get_account_reference(int account_id);
+
+EXPORT_API int em_core_account_validate(int account_id, int *err_code);
+
+EXPORT_API int em_core_account_delete(int account_id, int *err_code);
+
+EXPORT_API int em_core_account_create(emf_account_t *account, int *err_code);
+
+EXPORT_API int em_core_init_account_reference();
+
+EXPORT_API int em_core_refresh_account_reference();
+
+EXPORT_API int em_core_free_account_reference();
+
+EXPORT_API int em_core_account_free(emf_account_t **account_list, int count, int *err_code);
+
+EXPORT_API int em_core_account_get_list_refer(emf_account_t **account_list, int *count, int *err_code);
+
+EXPORT_API int em_core_account_validate_with_account_info(emf_account_t *account, int *err_code);
+
+EXPORT_API int em_core_query_server_info(const char* domain_name, emf_server_info_t **result_server_info);
+
+EXPORT_API int em_core_free_server_info(emf_server_info_t **target_server_info);
+
+EXPORT_API int em_core_save_default_account_id(int input_account_id);
+
+EXPORT_API int em_core_load_default_account_id(int *output_account_id);
+
+
+#ifdef __FEATURE_BACKUP_ACCOUNT__
+EXPORT_API int em_core_backup_accounts(const char *file_path, int *error_code);
+
+EXPORT_API int em_core_restore_accounts(const char *file_path, int *error_code);
+#endif /* __FEATURE_BACKUP_ACCOUNT_ */
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /*_EM_CORE_ACCOUNT_H_*/
+
diff --git a/email-core/include/em-core-api.h b/email-core/include/em-core-api.h
new file mode 100755
index 0000000..5519058
--- /dev/null
+++ b/email-core/include/em-core-api.h
@@ -0,0 +1,59 @@
+/*
+* email-service
+*
+* Copyright (c) 2000 - 2011 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.
+*
+*/
+
+
+/******************************************************************************
+ * File : em-core-api.h
+ * Desc : Mail Engine API Header
+ *
+ * Auth :
+ *
+ * History :
+ * 2006.08.16 : created
+ *****************************************************************************/
+#ifndef _EM_CORE_API_H_
+#define _EM_CORE_API_H_
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif /* __cplusplus */
+
+
+int em_core_encode_base64(char *src, unsigned long src_len, char **enc, unsigned long* enc_len, int *err_code);
+
+int em_core_decode_quotedprintable(unsigned char *enc_text, unsigned long enc_len, char **dec_text, unsigned long*dec_len, int *err_code);
+
+int em_core_decode_base64(unsigned char *enc_text, unsigned long enc_len, char **dec_text, unsigned long* dec_len, int *err_code);
+
+int em_core_init(int *err_code);
+
+/* em_core_set_logout_status - Set the logout status */
+EXPORT_API void em_core_set_logout_status(int status);
+
+/* em_core_get_logout_status - Get the logout status */
+EXPORT_API void em_core_get_logout_status(int *status);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /*_EM_CORE_API_H_*/
diff --git a/email-core/include/em-core-event.h b/email-core/include/em-core-event.h
new file mode 100755
index 0000000..a60963c
--- /dev/null
+++ b/email-core/include/em-core-event.h
@@ -0,0 +1,96 @@
+/*
+* email-service
+*
+* Copyright (c) 2000 - 2011 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.
+*
+*/
+
+
+/******************************************************************************
+ * File : em-core-event.h
+ * Desc : Mail Engine Event Header
+ *
+ * Auth :
+ *
+ * History :
+ * 2006.08.16 : created
+ *****************************************************************************/
+#ifndef __EM_CORE_EVNET_H__
+#define __EM_CORE_EVNET_H__
+
+#include "emf-types.h"
+#include "em-core-types.h"
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif /* __cplusplus */
+
+
+#if !defined(EXPORT_API)
+#define EXPORT_API __attribute__((visibility("default")))
+#endif
+
+void em_core_execute_event_callback(emf_action_t action, int total, int done, int status, int account_id, int mail_id, int handle, int error);
+int em_core_get_active_queue_idx(void);
+
+EXPORT_API int em_core_get_current_thread_type();
+EXPORT_API int em_core_register_event_callback(emf_action_t action, emf_event_callback callback, void *event_data);
+EXPORT_API int em_core_unregister_event_callback(emf_action_t action, emf_event_callback callback);
+EXPORT_API int em_core_get_pending_event(emf_action_t action, int account_id, int mail_id, emf_event_status_type_t *status);
+EXPORT_API int em_core_event_loop_start(int *err_code);
+EXPORT_API int em_core_event_loop_stop(int *err_code);
+EXPORT_API int em_core_insert_event(emf_event_t *event_data, int *handle, int *err_code);
+EXPORT_API int em_core_cancel_thread(int handle, void *arg, int *err_code);
+EXPORT_API int em_core_send_event_loop_start(int *err_code);
+EXPORT_API int em_core_send_event_loop_stop(int *err_code);
+EXPORT_API int em_core_cancel_send_mail_thread(int handle, void *arg, int *err_code);
+EXPORT_API int em_core_check_thread_status(void);
+EXPORT_API void em_core_get_event_queue_status(int *on_sending, int *on_receiving);
+EXPORT_API int em_core_insert_send_event(emf_event_t *event_data, int *handle, int *err_code);
+EXPORT_API int em_core_get_receiving_event_queue(emf_event_t **event_queue, int *event_count, int *err);
+EXPORT_API int em_core_cancel_all_threads_of_an_account(int account_id);
+EXPORT_API int em_core_free_event(emf_event_t *event_data);
+
+#ifdef _CONTACT_SUBSCRIBE_CHANGE_
+EXPORT_API int em_core_contact_sync_handler();
+EXPORT_API int em_core_init_last_sync_time(void);
+EXPORT_API int em_core_set_last_sync_time(int sync_time);
+EXPORT_API int em_core_get_last_sync_time(void);
+EXPORT_API int em_core_contact_sync_handler();
+#endif
+
+#ifdef __FEATURE_PARTIAL_BODY_DOWNLOAD__
+/* Please contact -> Himanshu [h.gahlaut@samsung.com] for any explanation in code here under this MACRO */
+EXPORT_API int em_core_insert_partial_body_thread_event(emf_event_partial_body_thd *partial_body_thd_event, int *error_code);
+EXPORT_API int em_core_is_partial_body_thd_que_empty();
+EXPORT_API int em_core_is_partial_body_thd_que_full();
+EXPORT_API int em_core_partial_body_thread_loop_start(int *err_code);
+EXPORT_API int em_core_clear_partial_body_thd_event_que(int *err_code);
+EXPORT_API int em_core_free_partial_body_thd_event(emf_event_partial_body_thd *partial_body_thd_event, int *error_code);
+EXPORT_API unsigned int em_core_get_partial_body_thd_id();
+EXPORT_API int em_core_get_pbd_thd_state();
+unsigned int em_core_get_receiving_thd_id();
+#endif
+
+
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif
diff --git a/email-core/include/em-core-global.h b/email-core/include/em-core-global.h
new file mode 100755
index 0000000..c401a25
--- /dev/null
+++ b/email-core/include/em-core-global.h
@@ -0,0 +1,56 @@
+/*
+* email-service
+*
+* Copyright (c) 2000 - 2011 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.
+*
+*/
+
+/******************************************************************************
+ * File : em-core-global.h
+ * Desc : Mail Engine Global Header
+ *
+ * Auth :
+ *
+ * History :
+ * 2006.08.01 : created
+ *****************************************************************************/
+#ifndef __EM_CORE_GLOBAL_H__
+#define __EM_CORE_GLOBAL_H__
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif /* __cplusplus */
+
+#include <glib.h>
+#include "vconf-keys.h"
+#include "emf-types.h"
+
+extern emf_account_list_t *g_account_list;
+extern int g_account_num;
+extern int g_account_retrieved;
+
+EXPORT_API emf_account_t *em_core_account_get_new_account_ref();
+extern char *strcasestr (__const char *__haystack, __const char *__needle) __THROW __attribute_pure__ __nonnull ((1, 2));
+
+extern int pthread_mutexattr_settype (pthread_mutexattr_t *__attr, int __kind) __THROW __nonnull ((1));
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif
diff --git a/email-core/include/em-core-imap-idle.h b/email-core/include/em-core-imap-idle.h
new file mode 100755
index 0000000..0bce49f
--- /dev/null
+++ b/email-core/include/em-core-imap-idle.h
@@ -0,0 +1,132 @@
+/*
+* email-service
+*
+* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+*
+* Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com>
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*
+*/
+
+
+/**
+ *
+ * This file contains functinality related to IMAP IDLE.
+ * @file em-core-imap-idle.h
+ * @author
+ * @version 0.1
+ * @brief This file contains functionality to provide IMAP IDLE support in email-service.
+ */
+
+#include "emflib.h"
+
+
+/**
+
+ * @open
+ * @fn em_core_imap_idle_thread_create(int *err_code)
+ * @brief Creates a thread that listens for IMAP IDLE Notifications.
+ *
+ * @param[out] err_code Specifies the error code returned.
+ * @remarks N/A
+ * @return This function returns true on success or false on failure.
+ */
+
+EXPORT_API int em_core_imap_idle_thread_create(int accountID, int *err_code);
+
+/**
+
+ * @open
+ * @fn em_core_imap_idle_thread_kill(int *err_code)
+ * @brief Kills IMAP IDLE thread
+ *
+ * @param[out] err_code Specifies the error code returned.
+ * @remarks N/A
+ * @return This function returns true on success or false on failure.
+ */
+EXPORT_API int em_core_imap_idle_thread_kill(int *err_code);
+
+
+
+/**
+
+ * @open
+ * @fn em_core_imap_idle_run(int *err_code, int iAccountID)
+ * @brief Make a list of mailboxes to IDLE on, connect to all mailboxes in list and start idle loop
+ *
+ * @param[out] err_code Specifies the error code returned.
+ * @remarks N/A
+ * @return This function returns true on success or false on failure.
+ */
+
+static int em_core_imap_idle_run(int iAccountID);
+
+/**
+
+ * @open
+ * @fn em_core_imap_idle_loop_start(emf_mailbox_t *mailbox_list, int num, int *err_code)
+ * @brief starts a loop which waits on select call. Select call monitors all the socket descriptors in the hold_connection fields of mailbox_list
+ *
+ * @param[in] mailbox_list list of mailboxes
+ * @param[in] num Count of mailboxes in list
+ * @param[out] err_code Specifies the error code returned.
+ * @remarks N/A
+ * @return This function returns true on success or false on failure.
+ */
+static int em_core_imap_idle_loop_start(emf_mailbox_t *mailbox_list, int num, int *err_code);
+
+
+
+/**
+
+ * @open
+ * @fn em_core_imap_idle_loop_start(emf_mailbox_t *mailbox_list, int num, int *err_code)
+ * @brief Creates and inserts an event in event queue for syncing mailbox
+ *
+ * @param[in] mailbox mailbox to be synced.
+ * @param[out] err_code Specifies the error code returned.
+ * @remarks N/A
+ * @return This function returns true on success or false on failure.
+ */
+static int em_core_imap_idle_insert_sync_event(emf_mailbox_t *mailbox, int *err_code);
+
+
+
+/**
+
+ * @open
+ * @fn em_core_imap_idle_connect_and_idle_on_mailbox(emf_mailbox_t *mailbox, int *err_code)
+ * @brief Opens connection to mailbox(selects mailbox) and sends IDLE command
+ *
+ * @param[in] mailbox mailbox to IDLE on.
+ * @param[out] err_code Specifies the error code returned.
+ * @remarks N/A
+ * @return This function returns true on success or false on failure.
+ */
+static int em_core_imap_idle_connect_and_idle_on_mailbox(emf_mailbox_t *mailbox, int *err_code);
+
+
+
+/**
+
+ * @open
+ * @fn em_core_imap_idle_parse_response_stream(emf_mailbox_t *mailbox, int *err_code)
+ * @brief Gets and parsee the IDLE notification coming from network
+ *
+ * @param[in] mailbox mailbox that got IDLE notification.
+ * @param[out] err_code Specifies the error code returned.
+ * @remarks N/A
+ * @return This function returns true on success or false on failure.
+ */
+static int em_core_imap_idle_parse_response_stream(emf_mailbox_t *mailbox, int *err_code);
diff --git a/email-core/include/em-core-imap-mailbox.h b/email-core/include/em-core-imap-mailbox.h
new file mode 100755
index 0000000..c566c92
--- /dev/null
+++ b/email-core/include/em-core-imap-mailbox.h
@@ -0,0 +1,79 @@
+/*
+* email-service
+*
+* Copyright (c) 2000 - 2011 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.
+*
+*/
+
+
+
+/******************************************************************************
+ * File : em-core-imap-mailbox.h
+ * Desc : Mail IMAP mailbox Header
+ *
+ * Auth :
+ *
+ * History :
+ * 2006.08.01 : created
+ *****************************************************************************/
+#ifndef __EM_CORE_IMAP_MAILBOX_H__
+#define __EM_CORE_IMAP_MAILBOX_H__
+
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif /* __cplusplus */
+
+EXPORT_API int em_core_mailbox_check_sync_imap_mailbox(emf_mailbox_t *mailbox, int *synchronous, int *err_code);
+/**
+ * Get mailbox list from imap server.
+ *
+ * @param[in] account_id Specifies the account ID.
+ * @param[in] mailbox Specifies the target mailbox. if NULL, get all mailbox.
+ * @param[in] callback Specifies the callback function for retrieving mailbox list.
+ * @param[out] err_code Specifies the error code returned.
+ * @remarks N/A
+ * @return This function returns true on success or false on failure.
+ */
+EXPORT_API int em_core_mailbox_sync_mailbox_list(int account_id, char *mailbox, int *err_code);
+
+/**
+ * Download mailbox list from imap server.
+ *
+ * @param[in] stream Specifies the internal mail stream.
+ * @param[in] mailbox Specifies the target mailbox. if NULL, get all mailbox.
+ * @param[out] mailbox_list The returned mailbox are saved here.
+ * @param[out] count The count of mailbox is saved here.
+ * @param[out] err_code Specifies the error code returned.
+ * @remarks N/A
+ * @return This function returns true on success or false on failure.
+ */
+EXPORT_API int em_core_mailbox_download_mailbox_list(void *mail_stream, char *mailbox, emf_mailbox_t **mailbox_list, int *count, int *err_code);
+EXPORT_API int em_core_mailbox_delete_imap_mailbox(emf_mailbox_t *mailbox, int *err_code);
+EXPORT_API int em_core_mailbox_create_imap_mailbox(emf_mailbox_t *mailbox, int *err_code);
+EXPORT_API int em_core_mailbox_modify_imap_mailbox(emf_mailbox_t *old_mailbox, emf_mailbox_t *new_mailbox, int *err_code);
+int em_core_mailbox_set_sync_imap_mailbox(emf_mailbox_t *mailbox, int synchronous, int *err_code);
+EXPORT_API int em_core_mailbox_set_mail_slot_size(int account_id, char *mailbox_name, int new_slot_size, int *err_code);
+EXPORT_API int em_core_mailbox_remove_overflowed_mails(emf_mailbox_tbl_t *intput_mailbox_tbl, int *err_code);
+EXPORT_API int em_core_mailbox_get_default_mail_slot_count(int *output_count, int *err_code);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif
diff --git a/email-core/include/em-core-mailbox-sync.h b/email-core/include/em-core-mailbox-sync.h
new file mode 100755
index 0000000..69625e8
--- /dev/null
+++ b/email-core/include/em-core-mailbox-sync.h
@@ -0,0 +1,179 @@
+/*
+* email-service
+*
+* Copyright (c) 2000 - 2011 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.
+*
+*/
+
+
+/******************************************************************************
+ * File : em-core-mailbox_sync.h
+ * Desc : Mail Header Sync Header
+ *
+ * Auth :
+ *
+ * History :
+ * 2006.08.16 : created
+ *****************************************************************************/
+#ifndef __EM_CORE_MAILBOX_SYNC_H__
+#define __EM_CORE_MAILBOX_SYNC_H__
+
+#include "emf-types.h"
+#include "em-storage.h"
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif /* __cplusplus */
+
+#if !defined(EXPORT_API)
+#define EXPORT_API __attribute__((visibility("default")))
+#endif
+
+#ifdef __FEATURE_PARTIAL_BODY_DOWNLOAD__
+
+#define IMAGE_DISPLAY_PARTIAL_BODY_COUNT 30
+typedef struct
+{
+ char image_file_name[100];
+ char *text_image;
+ char *content_id;
+ int dec_len;
+} emf_image_data;
+
+typedef struct
+{
+ char *buffer;
+ int buflen;
+} emf_partial_buffer;
+
+#endif
+
+typedef struct em_core_uid_elem {
+ int msgno;
+ char *uid;
+ emf_mail_flag_t flag;
+ struct em_core_uid_elem *next;
+} em_core_uid_list;
+
+int pop3_mail_calc_rfc822_size(MAILSTREAM *stream, int msgno, int *size, int *err_code);
+int pop3_mailbox_get_uids(MAILSTREAM *stream, em_core_uid_list** uid_list, int *err_code);
+
+int imap4_mail_calc_rfc822_size(MAILSTREAM *stream, int msgno, int *size, int *err_code);
+int imap4_mailbox_get_uids(MAILSTREAM *stream, em_core_uid_list** uid_list, int *err_code);
+
+/**
+ * Download unread all headers from mail server.
+ *
+ * @param[in] input_mailbox_tbl Specifies the mailbox to contain target mailbox name.
+ * if the mailbox name is NULL, headers are downloaded from all synchronous mailbox.
+ * the mailbox name is unused in POP3 case.
+ * @param[in] input_mailbox_tbl_spam Mailbox information of Spambox for filtering blocked mails.
+ * @param[in] stream_recycle Stream to reuse.
+ * @param[out] err_code Specifies the error code returned.
+ * @remarks N/A
+ * @return This function returns true on success or false on failure.
+ */
+EXPORT_API int em_core_mailbox_sync_header(emf_mailbox_tbl_t *input_mailbox_tbl, emf_mailbox_tbl_t *input_mailbox_tbl_spam, void *stream_recycle, em_core_uid_list **input_uid_list, int *unread_mail, int *err_code);
+
+typedef enum
+{
+ EM_CORE_GET_UIDS_FOR_NO_DELETE = 0,
+ EM_CORE_GET_UIDS_FOR_DELETE,
+} em_core_get_uids_for_delete_t;
+/**
+ * Download UID list from mail server.
+ *
+ * @param[in] mailbox Specifies the mailbox to contain target mailbox name.
+ * the mailbox name is unused in POP3 case.
+ * @param[out] uid_list The returned UID list is saved in a memory. this argument points to the list.
+ * @param[out] total Specifies the count of the uid_list.
+ * @param[in] read_mail_uids Specifies the array of the uids have the seen flag.
+ * @param[in] count Specifies the count of read_mail_uids.
+ * @param[in] for_delete Specifies the flag for deleting. (0 = for downloading or retrieving body, 1 = for deleting message)
+ * @param[out] err_code Specifies the error code returned.
+ * @remarks N/A
+ * @return This function returns true on success or false on failure.
+ */
+int em_core_mailbox_download_uid_all(emf_mailbox_t *mailbox,
+ em_core_uid_list **uid_list,
+ int *total,
+ emf_mail_read_mail_uid_tbl_t *read_mail_uids,
+ int count,
+ em_core_get_uids_for_delete_t for_delete,
+ int *err_code);
+
+
+
+/**
+ * Search a UID from mail server. this function is supported for only IMAP account.
+ *
+ * @param[in] mailbox Specifies the mailbox to contain target mailbox name.
+ * @param[in] uid Specifies the mail uid.
+ * @param[out] msgno The message number to be related to uid is saved here.
+ * @param[out] err_code Specifies the error code returned.
+ * @remarks N/A
+ * @return This function returns true on success or false on failure.
+ */
+int em_core_mailbox_download_imap_msgno(emf_mailbox_t *mailbox, char *uid, int *msgno, int *err_code);
+
+/**
+ * Get a message number to be related to uid.
+ *
+ * @param[in] uid_list Specifies the uid list.
+ * @param[in] uid Specifies the mail uid.
+ * @param[out] msgno The message number to be related to uid is saved here.
+ * @param[out] err_code Specifies the error code returned.
+ * @remarks The uid list must be already saved in fpath before this fucntion is called.
+ * @return This function returns true on success or false on failure.
+ */
+int em_core_mailbox_get_msgno(em_core_uid_list *uid_list, char *uid, int *msgno, int *err_code);
+
+/**
+ * Get a uid to be related to a message number.
+ *
+ * @param[in] uid_list Specifies the uid list.
+ * @param[in] msgno Specifies the message number.
+ * @param[out] uid The message uid is saved here.
+ * @param[out] err_code Specifies the error code returned.
+ * @remarks The uid list must be already saved in fpath before this fucntion is called.
+ * @return This function returns true on success or false on failure.
+ */
+int em_core_mailbox_get_uid(em_core_uid_list *uid_list, int msgno, char **uid, int *err_code);
+
+/**
+ * free fetch list.
+ *
+ * @param[in] uid_list Specifies the fetch data.
+ * @param[out] err_code Specifies the error code returned.
+ * @return This function returns true on success or false on failure.
+ */
+int em_core_mailbox_free_uids(em_core_uid_list *uid_list, int *err_code);
+
+EXPORT_API int em_core_mail_sync_from_client_to_server(int account_id, int mail_id, int *err_code);
+EXPORT_API int em_core_mail_check_rule(emf_mail_head_t *head, emf_mail_rule_tbl_t *rule, int rule_len, int *matched, int *err_code);
+
+#ifdef __FEATURE_PARTIAL_BODY_DOWNLOAD__
+EXPORT_API int em_core_bulk_partial_mailbody_download(MAILSTREAM *stream, emf_event_partial_body_thd *pbd_event, int count, int *error);
+#endif /* __FEATURE_PARTIAL_BODY_DOWNLOAD__ */
+
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif
diff --git a/email-core/include/em-core-mailbox.h b/email-core/include/em-core-mailbox.h
new file mode 100755
index 0000000..9c1066d
--- /dev/null
+++ b/email-core/include/em-core-mailbox.h
@@ -0,0 +1,91 @@
+/*
+* email-service
+*
+* Copyright (c) 2000 - 2011 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.
+*
+*/
+
+
+
+/******************************************************************************
+ * File : em-core-mailbox.h
+ * Desc : Local Mailbox Management Header
+ *
+ * Auth :
+ *
+ * History :
+ * 2006.08.16 : created
+ *****************************************************************************/
+#ifndef __EM_CORE_MAILBOX_H__
+#define __EM_CORE_MAILBOX_H__
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif /* __cplusplus */
+
+#include "c-client.h"
+
+#if !defined(EXPORT_API)
+#define EXPORT_API __attribute__((visibility("default")))
+#endif
+
+typedef enum
+{
+ EM_CORE_STREAM_TYPE_RECV = 0,
+ EM_CORE_STREAM_TYPE_SEND,
+} em_core_stream_type_t;
+
+#ifdef __FEATURE_KEEP_CONNECTION__
+EXPORT_API int em_core_remove_connection_info(int account_id);
+#endif /* __FEATURE_KEEP_CONNECTION__ */
+/* in SMTP case, path argument must be (ENCODED_PATH_SMTP) */
+/* ex) em_core_mailbox_open(xxx, (char *)ENCODED_PATH_SMTP, xxx, xxx); */
+EXPORT_API int em_core_mailbox_open_with_account_info(emf_account_t *ref_account, char *mailbox, void **mail_stream, int *err_code);
+EXPORT_API int em_core_mailbox_open(int account_id, char *mailbox, void **mail_stream, int *err_code);
+EXPORT_API int em_core_mailbox_close(int account_id, void *mail_stream);
+#ifdef __FEATURE_KEEP_CONNECTION__
+EXPORT_API void em_core_close_receiving_stream();
+EXPORT_API void em_core_close_partial_body_stream();
+EXPORT_API void em_core_reset_streams();
+#endif
+
+EXPORT_API int em_core_mailbox_get_list_to_be_sync(int account_id, emf_mailbox_t **mailbox_list, int *p_count, int *err_code);
+EXPORT_API int em_core_mailbox_get_list(int account_id, emf_mailbox_t **mailbox_list, int *p_count, int *err_code);
+EXPORT_API int em_core_mailbox_free(emf_mailbox_t **mailbox_list, int count, int *err_code);
+EXPORT_API int em_core_mailbox_get_mail_count(emf_mailbox_t *mailbox, int *total, int *unseen, int *err_code);
+EXPORT_API int em_core_mailbox_create(emf_mailbox_t *new_mailbox, int on_server, int *err_code);
+EXPORT_API int em_core_mailbox_delete(emf_mailbox_t *mailbox, int on_server, int *err_code);
+EXPORT_API int em_core_mailbox_delete_all(emf_mailbox_t *mailbox, int *err_code);
+EXPORT_API int em_core_mailbox_update(emf_mailbox_t *old_mailbox, emf_mailbox_t *new_mailbox, int *err_code);
+EXPORT_API int em_core_save_local_activity_sync(int account_id, int *err_code);
+EXPORT_API void em_core_bind_mailbox_type(emf_mailbox_t *mailbox_list);
+EXPORT_API int em_core_send_mail_event(emf_mailbox_t *mailbox, int mail_id , int *err_code);
+EXPORT_API int em_core_partial_body_thd_local_activity_sync(int *is_event_inserted, int *err_code);
+EXPORT_API int em_core_get_mailbox_by_type(int account_id, emf_mailbox_type_e mailbox_type, emf_mailbox_t *spam_mailbox, int *err_code);
+
+#ifdef __LOCAL_ACTIVITY__
+EXPORT_API int em_core_local_activity_sync(int account_id, int *err_code);
+EXPORT_API int em_core_save_local_activity_sync(int account_id, int *err_code);
+#endif
+
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif
diff --git a/email-core/include/em-core-mesg.h b/email-core/include/em-core-mesg.h
new file mode 100755
index 0000000..b40949a
--- /dev/null
+++ b/email-core/include/em-core-mesg.h
@@ -0,0 +1,232 @@
+/*
+* email-service
+*
+* Copyright (c) 2000 - 2011 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.
+*
+*/
+
+
+/******************************************************************************
+ * File : em-core-mesg.h
+ * Desc : Mail Operation Header
+ *
+ * Auth :
+ *
+ * History :
+ * 2006.08.16 : created
+ *****************************************************************************/
+#ifndef __EM_CORE_MESSAGE_H__
+#define __EM_CORE_MESSAGE_H__
+
+#include "em-storage.h"
+#include <contacts-svc.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+#if !defined(EXPORT_API)
+#define EXPORT_API __attribute__((visibility("default")))
+#endif
+
+#define HTML_EXTENSION_STRING ".htm"
+#define MAX_PATH_HTML 256
+
+#ifdef __FEATURE_BULK_DELETE_MOVE_UPDATE_REQUEST_OPTI__
+
+#define MAX_SUBSET_STRING_SIZE 260
+#define MAX_IMAP_COMMAND_LENGTH 1000
+#define MAX_TAG_SIZE 16
+
+
+typedef struct _emf_uid_range_set
+{
+ char *uid_range;
+ unsigned long lowest_uid;
+ unsigned long highest_uid;
+
+ struct _emf_uid_range_set *next;
+
+} emf_uid_range_set;
+
+#endif
+
+
+struct _m_content_info
+{
+ int grab_type; /* 1 : download text and get attachment names (no saving attachment) - #define GRAB_TYPE_TEXT retrieve text and attachment names */
+ /* 2 : download attachment - #define GRAB_TYPE_ATTACHMENT retrieve only attachment */
+ int file_no; /* attachment no to be download (min : 1) */
+ int report; /* 0 : Non 1 : DSN mail 2 : MDN mail 3 : mail to require MDN */
+
+ struct text_data
+ {
+ char *plain; /* body plain text */
+ char *plain_charset; /* charset of body text */
+ char *html; /* body html text */
+ } text;
+
+ struct attachment_info
+ {
+ int type; /* 1 : inline 2 : attachment */
+ char *name; /* attachment filename */
+ int size; /* attachment size */
+ char *save; /* content saving filename */
+ int drm; /* 0 : none 1 : object 2 : rights 3 : dcf */
+ int drm2; /* 0 : none 1 : FL 2 : CD 3 : SSD 4 : SD */
+#ifdef __ATTACHMENT_OPTI__
+ int encoding; /* encoding */
+ char *section; /* section number */
+#endif
+ struct attachment_info *next;
+ } *file;
+};
+
+
+/**
+ * Download email body from server.
+ *
+ * @param[in] mail_stream Specifies the mail_stream.
+ * @param[in] mailbox Specifies the mailbox to contain account ID.
+ * @param[in] mail_id Specifies the mail ID.
+ * @param[in] callback Specifies the callback function for retrieving download status.
+ * @param[in] with_attach Specifies the flag for downloading attachments.
+ * @param[in] limited_size Specifies the size to be downloaded.
+ * @param[out] err_code Specifies the error code returned.
+ * @remarks In POP3 case, body and attachment are downloaded in this function.
+ * In IMAP case, body and attachment list are downloaded and
+ * attachments must be downloaded in em_core_mail_download_attachment.
+ * @return This function returns true on success or false on failure.
+ */
+
+EXPORT_API int em_core_mail_download_body_multi_sections_bulk(void *mail_stream, int account_id, int mail_id, int verbose, int with_attach, int limited_size, int event_handle , int *err_code);
+
+
+/**
+ * Download a email nth-attachment from server.
+ *
+ * @param[in] mailbox Specifies the mailbox to contain account ID.
+ * @param[in] mail_id Specifies the mail ID.
+ * @param[in] nth Specifies the buffer that a attachment number been saved. the minimum number is "1".
+ * @param[in] callback Specifies the callback function for retrieving download status.
+ * @param[in] handle Specifies the handle for stopping downloading.
+ * @param[out] err_code Specifies the error code returned.
+ * @remarks This function is used for only IMAP mail.
+ * @return This function returns true on success or false on failure.
+ */
+EXPORT_API int em_core_mail_download_attachment(int acconut_id, int mail_id, char *nth, int *err_code);
+
+EXPORT_API int em_core_mail_get_info(int mail_id, emf_mail_info_t **info, int *err_code);
+EXPORT_API int em_core_mail_get_header(int mail_id, emf_mail_head_t **head, int *err_code);
+EXPORT_API int em_core_mail_get_body(int mail_id, emf_mail_body_t **body, int *err_code);
+EXPORT_API int em_core_mail_move(int mail_ids[], int num, char *dst_mailbox_name, int noti_param_1, int noti_param_2, int *err_code);
+EXPORT_API int em_core_mail_add_attachment(int mail_id, emf_attachment_info_t *attachment, int *err_code);
+EXPORT_API int em_core_mail_delete_attachment(int mail_id, char *attachment_id, int *err_code);
+EXPORT_API int em_core_mail_add_attachment_data(int input_mail_id, emf_attachment_data_t *input_attachment_data);
+
+
+#ifdef __FEATURE_PARTIAL_BODY_DOWNLOAD__
+EXPORT_API int em_core_insert_pbd_activity(emf_event_partial_body_thd *local_activity, int *activity_id, int *err_code) ;
+EXPORT_API int em_core_delete_pbd_activity(int account_id, int mail_id, int activity_id, int *err_code);
+#endif
+
+EXPORT_API int em_core_mail_get_contact_info(emf_mail_contact_info_t *contact_info, char *full_address, int *err_code);
+EXPORT_API int em_core_mail_get_contact_info_with_update(emf_mail_contact_info_t *contact_info, char *full_address, int mail_id, int *err_code);
+EXPORT_API int em_core_mail_free_contact_info(emf_mail_contact_info_t *contact_info, int *err_code);
+EXPORT_API int em_core_mail_contact_sync(int mail_id, int *err_code);
+EXPORT_API GList *em_core_get_recipients_list(GList *old_recipients_list, char *full_address, int *err_code);
+EXPORT_API int em_core_mail_get_address_info_list(int mail_id, emf_address_info_list_t **address_info_list, int *err_code);
+EXPORT_API int em_core_mail_get_display_name(CTSvalue *contact_name_value, char **contact_display_name);
+EXPORT_API int em_core_mail_get_mail(int msgno, emf_mail_t **mail, int *err_code);
+EXPORT_API int em_core_get_mail_data(int input_mail_id, emf_mail_data_t **output_mail_data);
+
+EXPORT_API int em_core_mail_update_old(int mail_id, emf_mail_t *src_mail, emf_meeting_request_t *src_meeting_req, int *err_code);
+EXPORT_API int em_core_update_mail(emf_mail_data_t *input_mail_data, emf_attachment_data_t *input_attachment_data_list, int input_attachment_count, emf_meeting_request_t* input_meeting_request, int sync_server);
+
+EXPORT_API int em_core_fetch_flags(int account_id, int mail_id, emf_mail_flag_t *mail_flag, int *err_code);
+EXPORT_API int em_core_mail_delete_from_local(int account_id, int *mail_ids, int num, int noti_param_1, int noti_param_2, int *err_code);
+EXPORT_API int em_core_mail_get_msgno_by_uid(emf_account_t *account, emf_mailbox_t *mailbox, char *uid, int *msgno, int *err_code);
+
+/**
+ * Delete mails.
+ *
+ * @param[in] account_id Specifies the account id.
+ * @param[in] mail_id Specifies the array for mail id.
+ * @param[in] num Specifies the number of id.
+ * @param[in] from_server Specifies whether mails is deleted from server.
+ * @param[in] callback Specifies the callback function for delivering status during deleting.
+ * @param[in] noti_param_1 Specifies the first parameter for notification.
+ * @param[in] noti_param_2 Specifies the second parameter for notification.
+ * @param[out] err_code Specifies the error code returned.
+ * @remarks N/A
+ * @return This function returns true on success or false on failure.
+ */
+EXPORT_API int em_core_mail_delete(int account_id, int mail_id[], int num, int from_server, int noti_param_1, int noti_param_2, int *err_code);
+
+/**
+ * Delete mails.
+ *
+ * @param[in] mailbox Specifies the mailbox. this argument is for account id or mailbox name.
+ * @param[in] with_server Specifies whether mails is also deleted from server.
+ * @param[in] callback Specifies the callback function for delivering status during deleting.
+ * @param[out] err_code Specifies the error code returned.
+ * @remarks N/A
+ * @return This function returns true on success or false on failure.
+ */
+EXPORT_API int em_core_mail_delete_all(emf_mailbox_t *mailbox, int with_server, int *err_code);
+
+EXPORT_API int em_core_mail_info_free(emf_mail_info_t **mail_info_list, int count, int *err_code);
+EXPORT_API int em_core_mail_body_free(emf_mail_body_t **mail_body_list, int count, int *err_code);
+EXPORT_API int em_core_mail_head_free(emf_mail_head_t **mail_head_list, int count, int *err_code);
+EXPORT_API int em_core_mail_free(emf_mail_t **mail_list, int count, int *err_code);
+EXPORT_API int em_core_free_mail_data(emf_mail_data_t **mail_list, int count, int *err_code);
+EXPORT_API void em_core_mime_free_content_info(struct _m_content_info *cnt_info);
+EXPORT_API int em_core_mail_attachment_info_free(emf_attachment_info_t **atch_info, int *err_code);
+EXPORT_API int em_core_free_attachment_data(emf_attachment_data_t **attachment_data_list, int attachment_data_count, int *err_code);
+
+EXPORT_API int em_core_mail_move_from_server(int account_id, char *src_mailbox, int mail_ids[], int num, char *dest_mailbox, int *error_code);
+EXPORT_API int em_core_mail_sync_flag_with_server(int mail_id, int *err_code);
+EXPORT_API int em_core_mail_sync_seen_flag_with_server(int mail_ids[], int num, int *err_code);
+EXPORT_API int em_core_mail_get_attachment(int mail_id, char *attachment_no, emf_attachment_info_t **attachment, int *err_code);
+EXPORT_API int em_core_get_attachment_data_list(int input_mail_id, emf_attachment_data_t **output_attachment_data, int *output_attachment_count);
+EXPORT_API int em_core_mail_modify_extra_flag(int mail_id, emf_extra_flag_t new_flag, int *err_code);
+EXPORT_API int em_core_mail_modify_flag(int mail_id, emf_mail_flag_t new_flag, int sticky_flag, int *err_code);
+EXPORT_API int em_core_mail_get_size(int mail_id, int *mail_size, int *err_code);
+EXPORT_API int em_core_mail_set_flags_field(int account_id, int mail_ids[], int num, emf_flags_field_type field_type, int value, int *err_code);
+EXPORT_API char* em_core_convert_mutf7_to_utf8(char *mailbox_name);
+EXPORT_API int em_core_convert_string_to_structure(const char *encoded_string, void **struct_var, emf_convert_struct_type_e type);
+
+EXPORT_API int em_core_mail_get_info_from_mail_tbl(emf_mail_info_t **pp_mail_info, emf_mail_tbl_t *mail , int *err_code);
+EXPORT_API int em_core_mail_get_header_from_mail_tbl(emf_mail_head_t **header, emf_mail_tbl_t *mail , int *err_code);
+EXPORT_API int em_core_mail_get_body_from_mail_tbl(emf_mail_body_t **p_body, emf_mail_tbl_t *mail, int *err_code);
+
+
+#ifdef __FEATURE_BULK_DELETE_MOVE_UPDATE_REQUEST_OPTI__
+EXPORT_API int em_core_mail_sync_flags_field_with_server(int mail_ids[], int num, emf_flags_field_type field_type, int value, int *err_code);
+EXPORT_API int em_core_mail_move_from_server_ex(int account_id, char *src_mailbox, int mail_ids[], int num, char *dest_mailbox, int *error_code);
+#endif
+
+#ifdef __ATTACHMENT_OPTI__
+EXPORT_API int em_core_mail_download_attachment_bulk(/*emf_mailbox_t *mailbox, */ int account_id, int mail_id, char *nth, int *err_code);
+#endif
+EXPORT_API int em_core_mail_filter_by_rule(emf_rule_t *filter_info, int *err_code);
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif
+/* EOF */
diff --git a/email-core/include/em-core-mime.h b/email-core/include/em-core-mime.h
new file mode 100755
index 0000000..f95fd42
--- /dev/null
+++ b/email-core/include/em-core-mime.h
@@ -0,0 +1,58 @@
+/*
+* email-service
+*
+* Copyright (c) 2000 - 2011 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.
+*
+*/
+
+
+/******************************************************************************
+ * File : em-core-mime.h
+ * Desc : MIME Operation Header
+ *
+ * Auth :
+ *
+ * History :
+ * 2011.04.14 : created
+ *****************************************************************************/
+#ifndef __EM_CORE_MIME_H__
+#define __EM_CORE_MIME_H__
+
+#include "em-core-types.h"
+#include "c-client.h"
+#include "em-storage.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+char *em_core_mime_get_line_from_file(void *stream, char *buf, int size, int *err_code);
+int em_core_mime_parse_mime(void *stream, int is_file, struct _m_content_info *cnt_info, int *err_code);
+EXPORT_API int em_core_get_attribute_value_of_body_part(PARAMETER *input_param, char *atribute_name, char *output_value, int output_buffer_length, int with_rfc2047_text, int *err_code);
+EXPORT_API int em_core_get_body_part_list_full(MAILSTREAM *stream, int msg_uid, int account_id, int mail_id, BODY *body, struct _m_content_info *cnt_info, int *err_code, PARTLIST * section_list, int event_handle);
+EXPORT_API int em_core_get_body(MAILSTREAM *stream, int account_id, int mail_id, int msg_uid, BODY *body, struct _m_content_info *cnt_info, int *err_code);
+EXPORT_API int em_core_get_body_structure(MAILSTREAM *stream, int msg_uid, BODY **body, int *err_code);
+EXPORT_API char *em_core_decode_rfc2047_text(char *rfc2047_text, int *err_code);
+EXPORT_API int em_core_decode_body_text(char *enc_buf, int enc_len, int enc_type, int *dec_len, int *err_code);
+EXPORT_API int em_core_set_fetch_body_section(BODY *body, int enable_inline_list, int *total_mail_size, int *err_code);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif
+/* EOF */
diff --git a/email-core/include/em-core-smtp.h b/email-core/include/em-core-smtp.h
new file mode 100755
index 0000000..e968a77
--- /dev/null
+++ b/email-core/include/em-core-smtp.h
@@ -0,0 +1,66 @@
+/*
+* email-service
+*
+* Copyright (c) 2000 - 2011 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.
+*
+*/
+
+
+
+/******************************************************************************
+ * File : em-core-smtp.h
+ * Desc : Mail SMTP Header
+ *
+ * Auth :
+ *
+ * History :
+ * 2006.08.16 : created
+ *****************************************************************************/
+#ifndef __EM_CORE_SMTP_H__
+#define __EM_CORE_SMTP_H__
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif /* __cplusplus */
+
+/* /#include "emflib.h" */
+#include <stdio.h>
+#include "c-client.h"
+
+#if !defined(EXPORT_API)
+#define EXPORT_API __attribute__((visibility("default")))
+#endif
+
+
+EXPORT_API int em_core_mail_send(int account_id, char *mailbox, int mail_id, emf_option_t *sending_option, int *err_code);
+
+EXPORT_API int em_core_mail_send_saved(int account_id, char *mailbox, emf_option_t *sending_option, int *err_code);
+
+EXPORT_API int em_core_mail_get_rfc822(emf_mail_t *mail, ENVELOPE **env, char **file_path, emf_option_t *sending_option, int *err_code);
+
+EXPORT_API int em_core_mail_save(int account_id, char *mailbox_name, emf_mail_t *mail_src, emf_meeting_request_t *meeting_req, int from_composer, int *err_code);
+
+EXPORT_API int em_core_add_mail(emf_mail_data_t *input_mail_data, emf_attachment_data_t *input_attachment_data_list, int input_attachment_count, emf_meeting_request_t *input_meeting_request, int input_sync_server);
+
+EXPORT_API int em_core_mail_add_meeting_request(int account_id, char *mailbox_name, emf_meeting_request_t *meeting_req, int *err_code);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif
diff --git a/email-core/include/em-core-sound-conflict.h b/email-core/include/em-core-sound-conflict.h
new file mode 100755
index 0000000..a56ea74
--- /dev/null
+++ b/email-core/include/em-core-sound-conflict.h
@@ -0,0 +1,20 @@
+/*
+* email-service
+*
+* Copyright (c) 2000 - 2011 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.
+*
+*/
diff --git a/email-core/include/em-core-sound.h b/email-core/include/em-core-sound.h
new file mode 100755
index 0000000..34fbe1c
--- /dev/null
+++ b/email-core/include/em-core-sound.h
@@ -0,0 +1,71 @@
+/*
+* email-service
+*
+* Copyright (c) 2000 - 2011 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.
+*
+*/
+
+
+#include <vconf-keys.h>
+#include <vconf.h>
+#include <mm_player.h>
+#include <mm_error.h>
+#include <mm_session_private.h>
+#include <devman_haptic.h>
+#include <alarm.h>
+
+#define MAX_LENGTH 255
+#define TIMER 7000
+#define HAPTIC_TEST_ITERATION 1
+
+void em_core_set_repetition_alarm(int repetition);
+int em_core_vibration_destory();
+int em_core_vibration_stop();
+int em_core_sound_mp_player_stop();
+bool em_core_sound_mp_player_destory();
+void *start_alert_thread(void *arg);
+EXPORT_API int em_core_alert_loop_start(int *err_code);
+EXPORT_API void start_alert();
+
+#ifdef Min
+#undef Min
+#endif
+
+typedef enum
+{
+ EMAIL_SOUND_STATUS,
+ EMAIL_VIBE_STATUS,
+ EMAIL_ALERT_REP_TYPE,
+ EMAIL_ALERT_VOLUME,
+ EMAIL_ALERT_VIBE_STENGTH,
+} EMAIL_SETTING_t;
+
+typedef enum
+{
+ EMAIL_ALERT_TYPE_MELODY,
+ EMAIL_ALERT_TYPE_VIB,
+ EMAIL_ALERT_TYPE_MELODY_AND_VIB,
+ EMAIL_ALERT_TYPE_MUTE,
+} EMAIL_ALERT_TYPE;
+
+typedef enum
+{
+ EMAIL_GCONF_VALUE_REPEAT_NONE = 0,
+ EMAIL_GCONF_VALUE_REPEAT_2MINS,
+ EMAIL_GCONF_VALUE_REPEAT_5MINS,
+ EMAIL_GCONF_VALUE_REPEAT_10MINS,
+} EMAIL_ALERT_REPEAT_ALARM;
diff --git a/email-core/include/em-core-timer.h b/email-core/include/em-core-timer.h
new file mode 100755
index 0000000..e64cdbe
--- /dev/null
+++ b/email-core/include/em-core-timer.h
@@ -0,0 +1,52 @@
+/*
+* email-service
+*
+* Copyright (c) 2000 - 2011 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.
+*
+*/
+
+
+
+typedef void (*EMF_TIMER_CALLBACK)(void *a_pData);
+
+/**
+ * Callback for timeout action
+ *
+ * @param[in] a_pData Specifies the data passed to callback.
+ * @return This function returns true for repeat alerts or false for mail resend.
+ */
+EXPORT_API int em_core_timer_ex_callback(void *a_pData);
+
+/**
+ * Set timer
+ *
+ * @param[in] a_nSetTimeValue Specifies the timeout value.
+ * @param[in] a_pCallBack Specifies the Callback to be called on timeout
+ * @param[in] a_pData Specifies the pointer to user data to be passed to Callback.
+ * @remarks N/A
+ * @return This function returns the timer id.
+ */
+EXPORT_API int em_core_set_timer_ex(long a_nSetTimeValue, EMF_TIMER_CALLBACK a_pCallBack, void *a_pData);
+
+/**
+ * Kill timer.
+ *
+ * @param[in] a_nTimerID Specifies the timer id.
+ * @remarks N/A
+ * @return This function returns void.
+ */
+EXPORT_API void em_core_kill_timer_ex(int a_nTimerID);
diff --git a/email-core/include/em-core-types.h b/email-core/include/em-core-types.h
new file mode 100755
index 0000000..a115cc5
--- /dev/null
+++ b/email-core/include/em-core-types.h
@@ -0,0 +1,320 @@
+/*
+* email-service
+*
+* Copyright (c) 2000 - 2011 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.
+*
+*/
+
+
+/******************************************************************************
+ * File : em-core-types.h
+ * Desc : defines data structures and macros
+ *
+ * Auth :
+ *
+ * History :
+ * 2011.04.05 : created
+ *****************************************************************************/
+#ifndef __EM_CORE_TYPES_H__
+#define __EM_CORE_TYPES_H__
+
+#include <pthread.h>
+#include "emf-types.h"
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif /* __cplusplu */
+
+#if !defined(EXPORT_API)
+#define EXPORT_API __attribute__((visibility("default")))
+#endif
+
+/* ----------------------------------------------------------------------------- */
+/* Feature definitions */
+#define __FEATURE_USING_MY_ACCOUNT__
+#define __FEATURE_BACKUP_ACCOUNT__
+#define __FEATURE_MOVE_TO_OUTBOX_FIRST__
+/* #define __FEATURE_PARTIAL_BODY_FOR_POP3__ */
+/* #define __FEATURE_KEEP_CONNECTION__ */
+#define __FEATURE_DRM__
+#define __FEATURE_PARTIAL_BODY_DOWNLOAD__
+#define __FEATURE_HEADER_OPTIMIZATION__
+#define __FEATURE_SEND_OPTMIZATION__
+#define __FEATURE_DOWNLOAD_BODY_ATTACHMENT_OPTIMIZATION__
+#define __FEATURE_BULK_DELETE_MOVE_UPDATE_REQUEST_OPTI__
+#define __FEATURE_SYNC_CLIENT_TO_SERVER__
+#define __FEATURE_PROGRESS_IN_OUTBOX__
+#define __FEATURE_AUTO_POLLING__
+#define __FEATURE_DEBUG_LOG__
+#define __FEATURE_USE_PTHREAD__
+#define __FEATURE_USE_SHARED_MUTEX_FOR_GENERATING_MAIL_ID__
+/* #define __FEATURE_USE_SHARED_MUTEX_FOR_PROTECTED_FUNC_CALL__ */
+#define __FEATURE_SUPPORT_ACTIVE_SYNC__
+
+#define __HEADER_OPTIMIZATION__ /* Will be removed */
+#define __DOWNLOAD_BODY_ATTACHMENT_OPTIMIZATION__ /* Will be removed */
+
+/* ----------------------------------------------------------------------------- */
+/* Macro */
+#ifndef NULL
+#define NULL (char *)0
+#endif
+
+#define SESSION_MAX 5
+#define IMAP_2004_LOG 1
+#define TEXT_SIZE 161
+#define MAILBOX_COUNT 6
+#define PARTIAL_DOWNLOAD_SIZE 1024
+#define PARTIAL_BODY_SIZE_IN_BYTES 15360 /* Partial Body download - 15K */
+#define NO_LIMITATION 0
+#define MAX_MAILBOX_TYPE 100
+#define EMF_SYNC_ALL_MAILBOX 1
+#define EMF_ATTACHMENT_MAX_COUNT 512
+#define DOWNLOAD_MAX_BUFFER_SIZE 8000
+#define LOCAL_MAX_BUFFER_SIZE 1000000
+#define IMAP_MAX_COMMAND_LENGTH 1000
+#define DOWNLOAD_NOTI_INTERVAL_PERCENT 5 /* notify every 5% */
+#define DOWNLOAD_NOTI_INTERVAL_SIZE 51200 /* notify every 50k */
+#define MAX_PATH 4096 /* /usr/src/linux-2.4.20-8/include/linux/limits.h */
+#define DATETIME_LENGTH 16
+#define MAIL_ID_STRING_LENGTH 10
+
+#define DIR_SEPERATOR "/"
+
+#define DATA_PATH "/opt/data"
+#define DB_PATH "/opt/dbspace"
+#define EMAIL_SERVICE_DB_FILE_PATH "/opt/dbspace/.email-service.db"
+
+#define VCONF_KEY_LAST_SYNC_TIME "db/email/last_sync_time"
+#define VCONF_KEY_DEFAULT_SLOT_SIZE "db/email/slot_size"
+#define VCONF_KEY_LATEST_MAIL_ID "db/email/latest_mail_id"
+#define VCONF_KEY_DEFAULT_ACCOUNT_ID "db/email/defaultaccount"
+#define VCONF_KEY_UNREAD_MAIL_COUNT "db/badge/com.samsung.email"
+
+#define MIME_SUBTYPE_DRM_OBJECT "vnd.oma.drm.message"
+#define MIME_SUBTYPE_DRM_RIGHTS "vnd.oma.drm.rights+xml"
+#define MIME_SUBTYPE_DRM_DCF "vnd.oma.drm.dcf"
+
+#define SHM_FILE_FOR_DB_LOCK "/.email_shm_db_lock"
+
+#ifdef __FEATURE_USE_SHARED_MUTEX_FOR_GENERATING_MAIL_ID__
+#define SHM_FILE_FOR_MAIL_ID_LOCK "/.email_shm_mail_id_lock"
+#endif /* __FEATURE_USE_SHARED_MUTEX_FOR_GENERATING_MAIL_ID__ */
+
+#define CR '\r'
+#define LF '\n'
+#define SPACE ' '
+#define TAB '\t'
+#define NULL_CHAR '\0'
+#define TAB_STRING "\t"
+#define CR_STRING "\r"
+#define LF_STRING "\n"
+#define CRLF_STRING "\r\n"
+
+#define SYNC_STATUS_FINISHED 0 /* BIN 00000000 */
+#define SYNC_STATUS_SYNCING 1 /* BIN 00000001 */
+#define SYNC_STATUS_HAVE_NEW_MAILS 2 /* BIN 00000010 */
+
+#define GRAB_TYPE_TEXT 1 /* retrieve text and attachment list */
+#define GRAB_TYPE_ATTACHMENT 2 /* retrieve attachment */
+
+#define SAVE_TYPE_SIZE 1 /* only get content size */
+#define SAVE_TYPE_BUFFER 2 /* save content to buffer */
+#define SAVE_TYPE_FILE 3 /* save content to temporary file */
+
+#define FINISH_OFF_IF_CANCELED if (!em_core_check_thread_status()) { err = EMF_ERROR_CANCELLED; goto FINISH_OFF; }
+#define CHECK_JOB_CANCELED() {if (!em_core_check_thread_status()) goto JOB_CANCEL; }
+
+#define SNPRINTF(buff, size, format, args...) snprintf(buff, size, format, ##args)
+#define SNPRINTF_OFFSET(base_buf, offset, base_size, format, args...) \
+ ({\
+ int _offset = offset;\
+ snprintf(base_buf + _offset, base_size - _offset - 1, format, ##args);\
+ })
+
+#ifdef __FEATURE_USE_PTHREAD__
+#define THREAD_CREATE(tv, func, param, err) { EM_DEBUG_LOG("THREAD_CREATE "#tv); err = pthread_create(&tv, NULL, func, param); }
+#define THREAD_CREATE_JOINABLE(tv, func, err) { pthread_attr_t attr; EM_DEBUG_LOG("THREAD_CREATE_JOINABLE "#tv); \
+ pthread_attr_init(&attr); pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);\
+ err = pthread_create(&tv, &attr, func, NULL); pthread_attr_destroy(&attr); }
+#define THREAD_JOIN(tv) {EM_DEBUG_LOG("THREAD_JOIN "#tv); pthread_join(tv, NULL); }
+#define THREAD_SELF() pthread_self()
+#define THREAD_DETACH(tv) pthread_detach(tv)
+#define INITIALIZE_CRITICAL_SECTION(cs) {EM_DEBUG_LOG("INITIALIZE_CRITICAL_SECTION "#cs); pthread_mutex_init(&cs, NULL); }
+#define ENTER_CRITICAL_SECTION(cs) {EM_DEBUG_LOG("ENTER_CRITICAL_SECTION "#cs); pthread_mutex_lock(&cs); }
+#define TRY_ENTER_CRITICAL_SECTION(cs) {EM_DEBUG_LOG("TRY_ENTER_CRITICAL_SECTION "#cs); pthread_mutex_trylock(&cs); }
+#define LEAVE_CRITICAL_SECTION(cs) {EM_DEBUG_LOG("LEAVE_CRITICAL_SECTION "#cs); pthread_mutex_unlock(&cs); }
+#define DELETE_CRITICAL_SECTION(cs) {EM_DEBUG_LOG("DELETE_CRITICAL_SECTION "#cs); pthread_mutex_destroy(&cs); }
+
+#define INITIALIZE_CONDITION_VARIABLE(cv) {EM_DEBUG_LOG("INITIALIZE_CONDITION_VARIABLE "#cv); pthread_cond_init(&cv, NULL); }
+#define SLEEP_CONDITION_VARIABLE(cv, cs) {EM_DEBUG_LOG("SLEEP_CONDITION_VARIABLE "#cv); pthread_cond_wait(&cv, &cs); }
+#define WAKE_CONDITION_VARIABLE(cv) {EM_DEBUG_LOG("WAKE_CONDITION_VARIABLE "#cv); pthread_cond_signal(&cv); }
+#define DELETE_CONDITION_VARIABLE(cv) {EM_DEBUG_LOG("DELETE_CONDITION_VARIABLE "#cv); pthread_cond_destroy(&cv); }
+
+#define INITIALIZE_RECURSIVE_CRITICAL_SECTION(cs) { EM_DEBUG_LOG("INITIALIZE_RECURSIVE_CRITICAL_SECTION "#cs); \
+ if (cs == NULL) {pthread_mutex_lock(&_send_event_available_lock); pthread_mutexattr_t attr; cs = (pthread_mutex_t *)malloc(sizeof(pthread_mutex_t));\
+ pthread_mutexattr_init(&attr); pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE_NP);\
+ pthread_mutex_init(cs, &attr);pthread_mutexattr_destroy(&attr); pthread_mutex_unlock(&_send_event_available_lock);}}
+#define ENTER_RECURSIVE_CRITICAL_SECTION(cs) {EM_DEBUG_LOG("ENTER_RECURSIVE_CRITICAL_SECTION "#cs); if(cs) pthread_mutex_lock(cs);}
+#define TRY_ENTER_RECURSIVE_CRITICAL_SECTION(cs) {EM_DEBUG_LOG("TRY_ENTER_RECURSIVE_CRITICAL_SECTION "#cs); if(cs) pthread_mutex_trylock(cs);}
+#define LEAVE_RECURSIVE_CRITICAL_SECTION(cs) {EM_DEBUG_LOG("LEAVE_RECURSIVE_CRITICAL_SECTION "#cs); if(cs) pthread_mutex_unlock(cs);}
+#define DELETE_RECURSIVE_CRITICAL_SECTION(cs) {EM_DEBUG_LOG("DELETE_RECURSIVE_CRITICAL_SECTION "#cs); if(cs) pthread_mutex_destroy(cs);}
+typedef pthread_t thread_t;
+#else /* __FEATURE_USE_PTHREAD__ */
+#define THREAD_CREATE(tv, func, param, err) {EM_DEBUG_LOG("THREAD_CREATE "#tv); tv = g_thread_create(func, param, FALSE, NULL); if (tv == NULL) err = -1; else err = 0; }
+#define THREAD_CREATE_JOINABLE(tv, func, err) {EM_DEBUG_LOG("THREAD_CREATE_JOINABLE "#tv); tv = g_thread_create(func, NULL, TRUE, NULL); if (tv == NULL) err = -1; else err = 0; }
+#define THREAD_JOIN(tv) {EM_DEBUG_LOG("THREAD_JOIN "#tv); g_thread_join(tv); }
+#define THREAD_SELF() g_thread_self()
+#define INITIALIZE_CRITICAL_SECTION(cs) {EM_DEBUG_LOG("INITIALIZE_CRITICAL_SECTION "#cs); if (cs == NULL) cs = g_mutex_new(); }
+#define ENTER_CRITICAL_SECTION(cs) {EM_DEBUG_LOG("ENTER_CRITICAL_SECTION "#cs); if (cs) g_mutex_lock(cs); }
+#define TRY_ENTER_CRITICAL_SECTION(cs) {EM_DEBUG_LOG("TRY_ENTER_CRITICAL_SECTION "#cs); if (cs) g_mutex_trylock(cs); }
+#define LEAVE_CRITICAL_SECTION(cs) {EM_DEBUG_LOG("LEAVE_CRITICAL_SECTION "#cs); if (cs) g_mutex_unlock(cs); }
+#define DELETE_CRITICAL_SECTION(cs) {EM_DEBUG_LOG("DELETE_CRITICAL_SECTION "#cs); if (cs) g_mutex_free(cs); cs = NULL; }
+
+#define INITIALIZE_CONDITION_VARIABLE(cv) {EM_DEBUG_LOG("INITIALIZE_CONDITION_VARIABLE "#cv); if (cv == NULL) cv = g_cond_new(); }
+#define SLEEP_CONDITION_VARIABLE(cv, cs) {EM_DEBUG_LOG("SLEEP_CONDITION_VARIABLE "#cv); if (cv) g_cond_wait(cv, cs); }
+#define WAKE_CONDITION_VARIABLE(cv) {EM_DEBUG_LOG("WAKE_CONDITION_VARIABLE "#cv); if (cv) g_cond_signal(cv); }
+#define DELETE_CONDITION_VARIABLE(cv) {EM_DEBUG_LOG("DELETE_CONDITION_VARIABLE "#cv); if (cv) g_cond_free(cv); cv = NULL; }
+
+#define INITIALIZE_RECURSIVE_CRITICAL_SECTION(cs) {EM_DEBUG_LOG("INITIALIZE_RECURSIVE_CRITICAL_SECTION "#cs); g_static_rec_mutex_init(&cs); }
+#define ENTER_RECURSIVE_CRITICAL_SECTION(cs) {EM_DEBUG_LOG("ENTER_RECURSIVE_CRITICAL_SECTION "#cs); g_static_rec_mutex_lock(&cs); }
+#define TRY_ENTER_RECURSIVE_CRITICAL_SECTION(cs) {EM_DEBUG_LOG("TRY_ENTER_RECURSIVE_CRITICAL_SECTION "#cs); g_static_rec_mutex_trylock(&cs); }
+#define LEAVE_RECURSIVE_CRITICAL_SECTION(cs) {EM_DEBUG_LOG("LEAVE_RECURSIVE_CRITICAL_SECTION "#cs); g_static_rec_mutex_unlock(&cs); }
+#define DELETE_RECURSIVE_CRITICAL_SECTION(cs) {EM_DEBUG_LOG("DELETE_RECURSIVE_CRITICAL_SECTION "#cs); g_static_rec_mutex_free(&cs); }
+typedef GThread* thread_t;
+#endif /* __FEATURE_USE_PTHREAD__ */
+
+#define SMTP_RESPONSE_OK 250
+#define SMTP_RESPONSE_READY 354
+#define SMTP_RESPONSE_WANT_AUTH 505
+#define SMTP_RESPONSE_WANT_AUTH2 530
+#define SMTP_RESPONSE_UNAVAIL 550
+/* ----------------------------------------------------------------------------- */
+/* Type */
+typedef enum
+{
+ _SERVICE_THREAD_TYPE_NONE = 0,
+ _SERVICE_THREAD_TYPE_RECEIVING = 1,
+ _SERVICE_THREAD_TYPE_SENDING = 2,
+#ifdef __FEATURE_PARTIAL_BODY_DOWNLOAD__
+ _SERVICE_THREAD_TYPE_PBD = 3,
+#endif /* __FEATURE_PARTIAL_BODY_DOWNLOAD__ */
+} emf_service_thread_type;
+
+
+typedef enum
+{
+ EMF_PROTOCOL_POP3 = 1,
+ EMF_PROTOCOL_IMAP,
+ EMF_PROTOCOL_SMTP,
+ EMF_PROTOCOL_NONE = 0,
+} emf_protocol_type_t;
+
+#ifdef __FEATURE_KEEP_CONNECTION__
+enum
+{
+ EMF_STREAM_STATUS_DISCONNECTED = 0,
+ EMF_STREAM_STATUS_CONNECTED = 1
+} ;
+#endif /* __FEATURE_KEEP_CONNECTION__ */
+
+/* event information */
+typedef struct
+{
+ int account_id; /* in general, account id */
+ emf_event_type_t type;
+ emf_event_status_type_t status;
+ char *event_param_data_1; /* in general, mailbox name (exception in em_core_mail_send, em_core_mail_send_saved it is emf_option_t **/
+ char *event_param_data_2;
+ char *event_param_data_3;
+ int event_param_data_4;
+ int event_param_data_5;
+ int event_param_data_6; /* in general, notification parameter #1 */
+ int event_param_data_7; /* in general, notification parameter #2 */
+} emf_event_t;
+
+
+typedef struct
+{
+ int num;
+ void *data;
+} emf_callback_holder_t;
+
+
+typedef struct emf_search_key_t emf_search_key_t;
+struct emf_search_key_t
+{
+ int type;
+ char *value;
+ emf_search_key_t *next;
+};
+
+typedef struct
+{
+ int tid;
+ emf_protocol_type_t protocol;
+ void *stream;
+ int auth;
+ int network;
+ int error;
+ int status;
+} emf_session_t;
+
+#ifdef __FEATURE_KEEP_CONNECTION__
+
+typedef struct emf_connection_info
+{
+ int account_id;
+ int sending_server_stream_status;
+ void *sending_server_stream;
+ int receiving_server_stream_status;
+ void *receiving_server_stream;
+ struct emf_connection_info *next;
+} emf_connection_info_t;
+#endif /* __FEATURE_KEEP_CONNECTION__ */
+
+typedef void (*emf_event_callback)(int total, int done, int status, int account_id, int mail_id, int handle, void *user_data, int error);
+
+/* ----------------------------------------------------------------------------- */
+/* Please contact Himanshu [h.gahlaut@samsung.com] for any explanation in code here under __FEATURE_PARTIAL_BODY_DOWNLOAD__ MACRO */
+#ifdef __FEATURE_PARTIAL_BODY_DOWNLOAD__
+typedef enum
+{
+ ACTIVITY_PARTIAL_BODY_DOWNLOAD_IMAP4 = 1,
+ ACTIVITY_PARTIAL_BODY_DOWNLOAD_POP3_WAIT,
+ ACTIVITY_PARTIAL_BODY_DOWNLOAD_POP3_ACTIVE
+} emf_pdb_activity_type_e;
+
+typedef struct
+{
+ int account_id;
+ int mail_id;
+ unsigned long server_mail_id;
+ int activity_id;
+ char *mailbox_name;
+ emf_event_type_t event_type; /* Event Type Null means event is created from local activitys */
+ int activity_type; /* Activity Type Null means event is created from event queue */
+
+} emf_event_partial_body_thd;
+#endif /* __FEATURE_PARTIAL_BODY_DOWNLOAD__ */
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* __EM_CORE_TYPES_H_ */
diff --git a/email-core/include/em-core-utils.h b/email-core/include/em-core-utils.h
new file mode 100755
index 0000000..1dda87f
--- /dev/null
+++ b/email-core/include/em-core-utils.h
@@ -0,0 +1,217 @@
+/*
+* email-service
+*
+* Copyright (c) 2000 - 2011 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.
+*
+*/
+
+
+/******************************************************************************
+ * File : em-core-utils.h
+ * Desc : Mail Utils Header
+ *
+ * Auth :
+ *
+ * History :
+ * 2006.08.16 : created
+ *****************************************************************************/
+#ifndef __EM_CORE_UTILS_H__
+#define __EM_CORE_UTILS_H__
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif /* __cplusplus */
+
+#include "emf-types.h"
+#include "em-storage.h"
+#include "em-core-global.h"
+#include "em-core-mesg.h"
+#ifdef __FEATURE_BULK_DELETE_MOVE_UPDATE_REQUEST_OPTI__
+#include "em-core-mesg.h"
+#endif
+
+#if !defined(EXPORT_API)
+#define EXPORT_API __attribute__((visibility("default")))
+#endif
+
+/* This is used for em_core_get_long_encoded_path */
+#define ENCODED_PATH_SMTP "UHDF_ENCODED_PATH_SMTP_EKJD"
+
+typedef int (*emf_get_unread_email_count_cb)(int unread, int *err_code);
+
+/* parse the Full mailbox Path and get the Alias Name of the Mailbox */
+char *em_core_get_alias_of_mailbox(const char *mailbox_path);
+
+/* Parse the Mailbox Path and get the Account Email address */
+EXPORT_API emf_option_t *em_core_get_option(int *err_code);
+EXPORT_API int em_core_set_option(emf_option_t *opt, int *err_code);
+int em_core_upper_path(char *path);
+int em_core_upper_string(char *str);
+int em_core_get_temp_file_name(char **filename, int *err_code);
+int em_core_get_long_encoded_path(int account_id, char *path, int delimiter, char **long_enc_path, int *err_code);
+int em_core_get_encoded_mailbox_name(char *name, char **enc_name, int *err_code);
+int em_core_get_file_name(char *path, char **filename, int *err_code);
+int em_core_get_file_size(char *path, int *size, int *err_code);
+int em_core_get_mail_size(emf_mail_t *mail_src, int *error_code);
+int em_core_calc_mail_size(emf_mail_data_t *mail_data_src, emf_attachment_data_t *attachment_data_src, int attachment_count, int *error_code);
+int em_core_get_actual_mail_size(char *pBodyPlane, char *pBodyHtml, struct attachment_info *pAttachment, int *error_code);
+int em_core_get_address_count(char *addr_str, int *to_num, int *err_code);
+
+void em_core_skip_whitespace(char *addr_str , char **pAddr);
+EXPORT_API char *em_core_skip_whitespace_without_strdup(char *source_string);
+EXPORT_API char* em_core_replace_string(char *source_string, char *old_string, char *new_string);
+EXPORT_API int em_core_set_network_error(int err_code);
+EXPORT_API int em_core_check_unread_mail();
+int em_core_is_storage_full(int *error);
+int em_core_show_popup(int id, emf_action_t action, int error);
+int em_core_get_long_encoded_path_with_account_info(emf_account_t *account, char *path, int delimiter, char **long_enc_path, int *err_code);
+EXPORT_API int em_storage_get_emf_error_from_em_storage_error(int error);
+EXPORT_API int em_core_open_contact_db_library(void);
+EXPORT_API void em_core_close_contact_db_library();
+EXPORT_API void em_core_flush_memory();
+EXPORT_API int em_core_get_server_time(void *mail_stream , int account_id, char *uid, int msgno, time_t *log_time, int *err_code);
+EXPORT_API void em_core_fill_address_information_of_mail_tbl(emf_mail_tbl_t *mail_data);
+EXPORT_API int em_core_add_transaction_info(int mail_id , int handle , int *err_code);
+EXPORT_API int em_core_get_handle_by_mailId_from_transaction_info(int mail_id , int *pHandle);
+EXPORT_API int em_core_delete_transaction_info_by_mailId(int mail_id);
+EXPORT_API int em_core_get_preview_text_from_file(const char *input_plain_path, const char *input_html_path, int input_preview_buffer_length, char **output_preview_buffer);
+EXPORT_API int em_core_strip_HTML(char *source_string);
+EXPORT_API int em_core_send_noti_for_new_mail(int account_id, char *mailbox_name, char *subject, char *from, char *uid, char *datetime);
+EXPORT_API int em_core_find_pos_stripped_subject_for_thread_view(char *subject, char *stripped_subject);
+EXPORT_API int em_core_find_tag_for_thread_view(char *subject, int *result);
+EXPORT_API int em_core_check_send_mail_thread_status();
+EXPORT_API int em_core_make_attachment_file_name_with_extension(char *source_file_name, char *sub_type, char *result_file_name, int result_file_name_buffer_length, int *err_code);
+EXPORT_API char *em_core_get_extension_from_file_path(char *source_file_path, int *err_code);
+EXPORT_API int em_core_get_encoding_type_from_file_path(const char *input_file_path, char **output_encoding_type);
+EXPORT_API int em_core_get_content_type(const char *extension_string, int *err_code);
+EXPORT_API char* em_core_get_current_time_string(int *err_code);
+
+
+/* Session Handling */
+EXPORT_API int em_core_get_empty_session(emf_session_t **session);
+EXPORT_API int em_core_clear_session(emf_session_t *session);
+EXPORT_API int em_core_get_current_session(emf_session_t **session);
+
+/* For notification */
+EXPORT_API int em_core_update_notification_for_unread_mail(int account_id);
+EXPORT_API int em_core_clear_all_notifications();
+EXPORT_API int em_core_add_notification_for_unread_mail_by_mail_header(int account_id, int mail_id, emf_mail_head_t *mail_header);
+EXPORT_API int em_core_add_notification_for_unread_mail(emf_mail_data_t *input_mail_data);
+EXPORT_API int em_core_delete_notification_for_read_mail(int mail_id);
+EXPORT_API int em_core_delete_notification_by_account(int account_id);
+EXPORT_API int em_core_finalize_sync(int account_id, int *error);
+
+EXPORT_API int em_core_verify_email_address(char *address, int without_bracket, int *err_code);
+EXPORT_API int em_core_verify_email_address_of_mail_header(emf_mail_head_t *mail_header, int without_bracket, int *err_code);
+EXPORT_API int em_core_verify_email_address_of_mail_data(emf_mail_data_t *mail_data, int without_bracket, int *err_code);
+
+
+#ifdef __FEATURE_BULK_DELETE_MOVE_UPDATE_REQUEST_OPTI__
+
+/**
+ * @fn em_core_convert_to_uid_range_set(emf_id_set_t *id_set, int id_set_count, emf_uid_range_set **uid_range_set, int range_len, int *err_code)
+ * Prepare a linked list of uid ranges with each node having a uid_range and lowest and highest uid in it.
+ *
+ *@author h.gahlaut@samsung.com
+ * @param[in] id_set Specifies the array of mail_id and corresponding server_mail_id sorted by server_mail_ids in ascending order
+ * @param[in] id_set_count Specifies the no. of cells in id_set array i.e. no. of sets of mail_ids and server_mail_ids
+ * @param[in] range_len Specifies the maximum length of string of range allowed.
+ * @param[out] uid_range_set Returns the uid_ranges formed in the form of a linked list with head stored in uid_range_set pointer
+ * @param[out] err_code Returns the error code.
+ * @remarks An example of a uid_range formed is 2 : 6, 8, 10, 14 : 15, 89,
+ * While using it the caller should remove the ending , (comma)
+ * @return This function returns true on success or false on failure.
+ */
+
+EXPORT_API int em_core_convert_to_uid_range_set(emf_id_set_t *id_set, int id_set_count, emf_uid_range_set **uid_range_set, int range_len, int *err_code);
+
+/**
+ * void em_core_free_uid_range_set(emf_uid_range_set **uid_range_head)
+ * Frees the linked list of uid ranges
+ *
+ * @author h.gahlaut@samsung.com
+ * @param[in] uid_range_head Head pointer of linked list of uid ranges
+ * @remarks
+ * @return This function does not return anything.
+ */
+EXPORT_API void em_core_free_uid_range_set(emf_uid_range_set **uid_range_set);
+
+/**
+ * @fn em_core_append_subset_string_to_uid_range(char *subset_string, emf_uid_range_set **uid_range_set, int range_len, unsigned long luid, unsigned long huid)
+ * Appends the subset_string to uid range if the uid range has not exceeded maximum length(range_len), otherwise creates a new node in linked list of uid range set
+ * and stores the subset_string in its uid_range. Also sets the lowest and highest uids for the corresponsing uid_range
+ *
+ * @author h.gahlaut@samsung.com
+ * @param[in] subset_string Specifies the subset string to be appended. A subset string can be like X : Y or X where X and Y are uids.
+ * @param[in] range_len Specifies the maximum length of range string allowed.
+ * @param[in] luid Specifies the lowest uid in subset string
+ * @param[in] huid Specifies the highest uid in subset string
+ * @param[out] uid_range_set Returns the uid_ranges formed in the form of a linked list with head stored in uid_range_set pointer
+ * @param[out] err_code Returns the error code.
+ * @remarks
+ * @return This function returns true on success or false on failure.
+ */
+
+int em_core_append_subset_string_to_uid_range(char *subset_string, emf_uid_range_set **current_node_adr, emf_uid_range_set **uid_range_set, int range_len, unsigned long luid, unsigned long huid);
+
+/**
+ * @fn em_core_form_comma_separated_strings(int numbers[], int num_count, int max_string_len, char ***strings, int *string_count, int *err_code)
+ * Forms comma separated strings of a give max_string_len from an array of numbers
+ *
+ * @author h.gahlaut@samsung.com
+ * @param[in] numbers Specifies the array of numbers to be converted into comma separated strings.
+ * @param[in] num_count Specifies the count of numbers in numbers array.
+ * @param[in] max_string_len Specifies the maximum length of comma separated strings that are to be formed.
+ * @param[out] strings Returns the base address of a double dimension array which stores the strings.
+ * @param[out] string_count Returns the number of strings formed.
+ * @param[out] err_code Returns the error code.
+ * @remarks If Input to the function is five numbers like 2755 2754 2748 2749 2750 and a given max_string_len is 20.
+ * Then this function will form two comma separated strings as follows -
+ * "2755, 2754, 2748"
+ * "2749, 2750"
+ * @return This function returns true on success or false on failure.
+ */
+EXPORT_API int em_core_form_comma_separated_strings(int numbers[], int num_count, int max_string_len, char ***strings, int *string_count, int *err_code);
+
+/**
+ * @fn em_core_free_comma_separated_strings(char ***string_list, int *string_count)
+ * Frees the double dimensional array of strings.
+ *
+ * @author h.gahlaut@samsung.com
+ * @param[in] uid_range_head Address of base address of double dimensional array of strings.
+ * @param[in] string_count Address of variable holding the count of strings.
+ * @remarks
+ * @return This function does not return anything.
+ */
+
+EXPORT_API void em_core_free_comma_separated_strings(char ***string_list, int *string_count);
+
+#endif
+
+#ifdef __LOCAL_ACTIVITY__
+/* Added to get next activity id sequence */
+EXPORT_API int em_core_get_next_activity_id(int *activity_id, int *err_code);
+EXPORT_API int em_core_activity_add(emf_activity_tbl_t *new_activity, int *err_code);
+EXPORT_API int em_core_activity_delete(emf_activity_tbl_t *activity, int *err_code);
+#endif /* __LOCAL_ACTIVITY__ */
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* __EM_CORE_UTILS_H__ */
diff --git a/email-engine/CMakeLists.txt b/email-engine/CMakeLists.txt
new file mode 100755
index 0000000..3344380
--- /dev/null
+++ b/email-engine/CMakeLists.txt
@@ -0,0 +1,58 @@
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+PROJECT(email-service)
+
+SET(CMAKE_SKIP_BUILD_RPATH TRUE)
+
+IF("${CMAKE_BUILD_TYPE}" STREQUAL "")
+ SET(CMAKE_BUILD_TYPE "Debug")
+ENDIF("${CMAKE_BUILD_TYPE}" STREQUAL "")
+
+MESSAGE("")
+MESSAGE(">>> current directory: ${CMAKE_CURRENT_SOURCE_DIR}")
+MESSAGE(">>> Build type: ${CMAKE_BUILD_TYPE}")
+
+SET(VISIBILITY "-DEXPORT_API=\"__attribute__((visibility(\\\"default\\\")))\"")
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${VISIBILITY} -fvisibility=hidden")
+
+##########################################################
+# Define Execute File
+##########################################################
+
+SET(MAIN-SRCS
+ ${CMAKE_SOURCE_DIR}/email-engine/main.c
+ ${CMAKE_SOURCE_DIR}/email-engine/emf-init.c
+ ${CMAKE_SOURCE_DIR}/email-engine/emf-account.c
+ ${CMAKE_SOURCE_DIR}/email-engine/emf-global.c
+ ${CMAKE_SOURCE_DIR}/email-engine/emf-mail.c
+ ${CMAKE_SOURCE_DIR}/email-engine/emf-mailbox.c
+ ${CMAKE_SOURCE_DIR}/email-engine/emf-etc.c
+ ${CMAKE_SOURCE_DIR}/email-engine/emf-emn-noti.c
+ ${CMAKE_SOURCE_DIR}/email-engine/emf-emn.c
+ ${CMAKE_SOURCE_DIR}/email-engine/emf-auto-poll.c
+)
+
+INCLUDE_DIRECTORIES(
+ ${CMAKE_SOURCE_DIR}/Common/include
+ ${CMAKE_SOURCE_DIR}/ipc/include
+ ${CMAKE_SOURCE_DIR}/MAPI/include
+ ${CMAKE_SOURCE_DIR}/email-core/drivers
+ ${CMAKE_SOURCE_DIR}/email-core/em-storage/include
+ ${CMAKE_SOURCE_DIR}/include
+ ${CMAKE_SOURCE_DIR}/email-core/include
+)
+
+INCLUDE(FindPkgConfig)
+pkg_check_modules(main_pkgs REQUIRED glib-2.0 drm-service dlog dbus-1 gthread-2.0 db-util openssl uw-imap-toolkit vconf contacts-service alarm-service mm-player devman_haptic)
+
+
+FOREACH(flag ${main_pkgs_CFLAGS})
+ SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
+SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed")
+
+ADD_EXECUTABLE(${PROJECT_NAME} ${MAIN-SRCS})
+TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${main_pkgs_LDFLAGS} dl ssl email-core email-storage email-network email-ipc email-base)
+INSTALL(TARGETS ${PROJECT_NAME} DESTINATION bin)
+
diff --git a/email-engine/emf-account.c b/email-engine/emf-account.c
new file mode 100755
index 0000000..ae18c00
--- /dev/null
+++ b/email-engine/emf-account.c
@@ -0,0 +1,698 @@
+/*
+* email-service
+*
+* Copyright (c) 2000 - 2011 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.
+*
+*/
+
+
+/******************************************************************************
+ * File: emf-account.c
+ * Desc: Mail Framework Account
+ *
+ * Auth:
+ *
+ * History:
+ * 2006.08.16 : created
+ *****************************************************************************/
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <vconf.h>
+
+#include "emflib.h"
+#include "em-storage.h"
+#include "emf-global.h"
+#include "c-client.h"
+#include "emf-dbglog.h"
+#include "emf-account.h"
+#include <contacts-svc.h>
+#include "emf-types.h"
+#include "em-core-account.h"
+#include "em-core-event.h"
+#include "em-core-utils.h"
+#include "Msg_Convert.h"
+
+static int emf_refresh_account_reference()
+{
+ EM_DEBUG_FUNC_BEGIN();
+ return em_core_refresh_account_reference();
+}
+
+static int emf_filter_check_filter_id(int account_id, int filter_id, int* err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("account_id[%d], filter_id[%d], err_code[%p]", account_id, filter_id, err_code);
+
+ if (account_id != ALL_ACCOUNT) { /* only global rule supported. */
+ EM_DEBUG_EXCEPTION(" account_id[%d], filter_id[%d]", account_id, filter_id);
+
+ if (err_code != NULL)
+ *err_code = EMF_ERROR_INVALID_PARAM;
+ return false;
+ }
+
+ int ret = false;
+ int err = EMF_ERROR_NONE;
+ emf_mail_rule_tbl_t* filter = NULL;
+
+ if (!em_storage_get_rule_by_id(account_id, filter_id, &filter, true, &err)) {
+ EM_DEBUG_EXCEPTION(" em_storage_get_rule_by_id failed [%d]", err);
+
+ goto FINISH_OFF;
+ }
+
+ ret = true;
+
+FINISH_OFF:
+ if (filter != NULL)
+ em_storage_free_rule(&filter, 1, NULL);
+
+ if (err_code != NULL)
+ *err_code = err;
+ EM_DEBUG_FUNC_END();
+ return ret;
+}
+
+
+EXPORT_API int emf_account_create(emf_account_t* account, int* err_code)
+{
+ int ret = false;
+ int err = EMF_ERROR_NONE;
+
+ switch (account->account_bind_type) {
+ case EMF_BIND_TYPE_DISABLE:
+ case EMF_BIND_TYPE_EM_CORE:
+ if (!em_core_account_create(account, &err)) {
+ EM_DEBUG_EXCEPTION(" em_core_account_add failed [%d]", err);
+ goto FINISH_OFF;
+ }
+ emf_refresh_account_reference();
+ break;
+ default:
+ EM_DEBUG_EXCEPTION(" unknown account bind type...");
+ err = EMF_ERROR_INVALID_ACCOUNT;
+ goto FINISH_OFF;
+ }
+
+ ret = true;
+FINISH_OFF:
+ if (err_code)
+ *err_code = err;
+ EM_DEBUG_FUNC_END();
+ return ret;
+}
+
+
+EXPORT_API int emf_account_delete(int account_id, int* err_code)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int ret;
+
+ ret = em_core_account_delete(account_id, err_code);
+ EM_DEBUG_FUNC_END();
+ return ret;
+}
+
+
+EXPORT_API int emf_account_validate(int account_id, unsigned* handle, int* err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("account_id[%d], handle[%p], err_code[%p]", account_id, handle, err_code);
+
+ int ret = false;
+ int err = EMF_ERROR_NONE;
+
+ if (account_id < 1) {
+ EM_DEBUG_EXCEPTION(" account_id[%d]", account_id);
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ emf_event_t event_data = {0};
+ emf_account_t* ref_account = NULL;
+
+ if (!(ref_account = emf_get_account_reference(account_id))) {
+ EM_DEBUG_EXCEPTION(" emf_get_account_reference failed [%d]", account_id);
+ err = EMF_ERROR_INVALID_ACCOUNT;
+ goto FINISH_OFF;
+ }
+
+ switch (ref_account->account_bind_type) {
+ case EMF_BIND_TYPE_EM_CORE:
+ event_data.type = EMF_EVENT_VALIDATE_ACCOUNT;
+ event_data.event_param_data_1 = NULL;
+ event_data.event_param_data_3 = NULL;
+ event_data.account_id = account_id;
+
+ if (!em_core_insert_event(&event_data, (int*)handle, &err)) {
+ EM_DEBUG_EXCEPTION(" em_core_insert_event falied [%d]", err);
+ goto FINISH_OFF;
+ }
+ break;
+
+ default:
+ EM_DEBUG_EXCEPTION(" unknown account bind type...");
+ err = EMF_ERROR_INVALID_ACCOUNT;
+ goto FINISH_OFF;
+ }
+
+ ret = true;
+
+FINISH_OFF:
+ if (err_code)
+ *err_code = err;
+ EM_DEBUG_FUNC_END();
+ return ret;
+}
+
+
+EXPORT_API int emf_account_validate_and_create(emf_account_t* new_account, unsigned* handle, int* err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("account[%p], handle[%p], err_code[%p]", new_account, handle, err_code);
+
+ int ret = false;
+ int err = EMF_ERROR_NONE;
+ emf_event_t event_data = {0};
+
+ switch (new_account->account_bind_type) {
+ case EMF_BIND_TYPE_EM_CORE:
+ event_data.type = EMF_EVENT_VALIDATE_AND_CREATE_ACCOUNT;
+ event_data.event_param_data_1 = NULL;
+ event_data.event_param_data_3 = NULL;
+ event_data.account_id = NEW_ACCOUNT_ID;
+
+ if (!em_core_insert_event(&event_data, (int*)handle, &err)) {
+ EM_DEBUG_EXCEPTION(" em_core_insert_event falied [%d]", err);
+ goto FINISH_OFF;
+ }
+ break;
+ default:
+ EM_DEBUG_EXCEPTION(" unknown account bind type...");
+ err = EMF_ERROR_INVALID_ACCOUNT;
+ goto FINISH_OFF;
+ }
+
+ ret = true;
+
+FINISH_OFF:
+ if (err_code)
+ *err_code = err;
+ EM_DEBUG_FUNC_END();
+ return ret;
+}
+
+
+EXPORT_API int emf_account_modify(int account_id, emf_account_t* new_account, int* err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("account_id[%d], new_account[%p], err_code[%p]", account_id, new_account, err_code);
+
+ /* default variable */
+ int ret = false;
+ int err = EMF_ERROR_NONE;
+ emf_mail_account_tbl_t *new_account_tbl = NULL;
+
+ if ((account_id <= 0) || !new_account) {
+ EM_DEBUG_EXCEPTION("Invalid Parameters.");
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+ EM_DEBUG_LOG("new_account->email_addr[%s]", new_account->email_addr);
+ if(new_account->email_addr) {
+ if (!em_core_verify_email_address(new_account->email_addr, true, &err)) {
+ err = EMF_ERROR_INVALID_ADDRESS;
+ EM_DEBUG_EXCEPTION("Invalid Email Address");
+ goto FINISH_OFF;
+ }
+ }
+
+ new_account_tbl = em_core_malloc(sizeof(emf_mail_account_tbl_t));
+ if(!new_account_tbl) {
+ EM_DEBUG_EXCEPTION("allocation failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ em_convert_account_to_account_tbl(new_account, new_account_tbl);
+
+ if (!em_storage_update_account(account_id, new_account_tbl, true, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_update_account falied [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ emf_refresh_account_reference();
+
+ ret = true;
+
+FINISH_OFF:
+ if(new_account_tbl)
+ em_storage_free_account(&new_account_tbl, 1, NULL);
+ if (err_code)
+ *err_code = err;
+ EM_DEBUG_FUNC_END();
+ return ret;
+}
+
+EXPORT_API int emf_account_validate_and_update(int old_account_id, emf_account_t* new_account_info, unsigned* handle,int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("account[%d], new_account_info[%p], handle[%p], err_code[%p]", old_account_id, new_account_info, handle, err_code);
+
+ int ret = false;
+ int err = EMF_ERROR_NONE;
+ emf_event_t event_data = {0};
+
+ switch (new_account_info->account_bind_type) {
+ case EMF_BIND_TYPE_EM_CORE:
+ event_data.type = EMF_EVENT_VALIDATE_AND_UPDATE_ACCOUNT;
+ event_data.event_param_data_3 = NULL;
+ event_data.account_id = old_account_id;
+
+ emf_account_t *pAccount = (emf_account_t *)malloc(sizeof(emf_account_t));
+ if (pAccount == NULL) {
+ EM_DEBUG_EXCEPTION(" malloc failed...");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+ memcpy(pAccount, new_account_info, sizeof(emf_account_t));
+ event_data.event_param_data_1 = (char *) pAccount;
+
+ if (!em_core_insert_event(&event_data, (int*)handle, &err)) {
+ EM_DEBUG_EXCEPTION("em_core_insert_event falied [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ break;
+ default:
+ EM_DEBUG_EXCEPTION("unknown account bind type...");
+ err = EMF_ERROR_INVALID_ACCOUNT;
+ goto FINISH_OFF;
+ }
+
+ ret = true;
+
+FINISH_OFF:
+ if (err_code)
+ *err_code = err;
+ EM_DEBUG_FUNC_END();
+ return ret;
+}
+
+
+EXPORT_API int emf_account_get(int account_id, int pulloption, emf_account_t** account, int* err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("account_id[%d], pulloption [%d], account[%p], err_code[%p]", account_id, pulloption, account, err_code);
+
+ /* default variable */
+ int ret = false;
+ int err = EMF_ERROR_NONE;
+ emf_mail_account_tbl_t *account_tbl = NULL;
+
+ if (!account) {
+ EM_DEBUG_EXCEPTION("account_id[%d], account[%p]", account_id, account);
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ if (!em_storage_get_account_by_id(account_id, pulloption, &account_tbl, true, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_get_account_by_id failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ *account = em_core_malloc(sizeof(emf_account_t));
+ if(!*account) {
+ EM_DEBUG_EXCEPTION("allocation failed [%d]", err);
+ goto FINISH_OFF;
+ }
+ em_convert_account_tbl_to_account(account_tbl, *account);
+
+ ret = true;
+
+FINISH_OFF:
+ if(account_tbl)
+ em_storage_free_account(&account_tbl, 1, NULL);
+ if (err_code)
+ *err_code = err;
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+EXPORT_API int emf_account_get_list(emf_account_t** account_list, int* count, int* err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("account_list[%p], count[%p], err_code[%p]", account_list, count, err_code);
+
+ int ret = false, err = EMF_ERROR_NONE, i = 0;
+ emf_mail_account_tbl_t *account_tbl_array = NULL;
+
+ if (!account_list || !count) {
+ EM_DEBUG_EXCEPTION("account_list[%p], count[%p]", account_list, (*count));
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ *count = 1000;
+
+ if (!em_storage_get_account_list(count, &account_tbl_array, true, true, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_get_account_list failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ if(account_tbl_array && (*count) > 0) {
+ *account_list = (emf_account_t*)em_core_malloc(sizeof(emf_account_t) * (*count));
+ if(!*account_list) {
+ EM_DEBUG_EXCEPTION("allocation failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ for(i = 0 ; i < (*count); i++)
+ em_convert_account_tbl_to_account(account_tbl_array + i, (*account_list) + i);
+ }
+
+ ret = true;
+
+FINISH_OFF:
+ if(account_tbl_array)
+ em_storage_free_account(&account_tbl_array, (*count), NULL);
+
+ if (err_code != NULL)
+ *err_code = err;
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+
+EXPORT_API int emf_account_free(emf_account_t** account_list, int count, int* err_code)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ return em_core_account_free(account_list, count, err_code);
+}
+
+
+EXPORT_API int emf_filter_get(int filter_id, emf_rule_t** filter_info, int* err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("filter_id[%d], filter_info[%p], err_code[%p]", filter_id, filter_info, err_code);
+
+ if (!filter_info) {
+ EM_DEBUG_EXCEPTION("filter_id[%d], filter_info[%p]", filter_id, filter_info);
+
+ if (err_code != NULL)
+ *err_code = EMF_ERROR_INVALID_PARAM;
+ return false;
+ }
+
+ /* default variable */
+ int ret = false;
+ int err = EMF_ERROR_NONE;
+
+ if (!em_storage_get_rule_by_id(ALL_ACCOUNT, filter_id, (emf_mail_rule_tbl_t**)filter_info, true, &err)) {
+ EM_DEBUG_EXCEPTION(" em_storage_get_rule_by_id failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ ret = true;
+
+FINISH_OFF:
+ if (err_code)
+ *err_code = err;
+ EM_DEBUG_FUNC_END();
+ return ret;
+}
+
+EXPORT_API int emf_filter_get_list(emf_rule_t** filter_info, int* count, int* err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("filter_info[%p], count[%p], err_code[%p]", filter_info, count, err_code);
+
+ /* default variable */
+ int ret = false;
+ int err = EMF_ERROR_NONE;
+ int is_completed;
+
+ if (!filter_info || !count) {
+ EM_DEBUG_EXCEPTION(" filter_info[%p], count[%p]", filter_info, count);
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ *count = 1000;
+
+ if (!em_storage_get_rule(ALL_ACCOUNT, 0, 0, count, &is_completed, (emf_mail_rule_tbl_t**)filter_info, true, &err)) {
+ EM_DEBUG_EXCEPTION(" em_storage_get_rule failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ ret = true;
+
+FINISH_OFF:
+ if (err_code)
+ *err_code = err;
+ EM_DEBUG_FUNC_END();
+ return ret;
+}
+
+EXPORT_API int emf_filter_find(emf_rule_t* filter_info, int* err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("filter_info[%p], err_code[%p]", filter_info, err_code);
+
+ /* default variable */
+ int ret = false;
+ int err = EMF_ERROR_NONE;
+
+ if (!filter_info) {
+ EM_DEBUG_EXCEPTION(" filter_info[%p]", filter_info);
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ if (filter_info->faction == EMF_FILTER_MOVE && !filter_info->mailbox) {
+ EM_DEBUG_EXCEPTION(" filter_info->faction[%d], filter_info->mailbox[%p]", filter_info->faction, filter_info->mailbox);
+ err = EMF_ERROR_INVALID_FILTER;
+ goto FINISH_OFF;
+ }
+
+ filter_info->account_id = ALL_ACCOUNT; /* MUST BE */
+
+ if (!em_storage_find_rule((emf_mail_rule_tbl_t*)filter_info, true, &err)) {
+ EM_DEBUG_EXCEPTION(" em_storage_find_rule failed [%d]", err);
+ err = EMF_ERROR_FILTER_NOT_FOUND;
+ goto FINISH_OFF;
+ }
+
+ ret = true;
+
+FINISH_OFF:
+ if (err_code)
+ *err_code = err;
+ EM_DEBUG_FUNC_END();
+ return ret;
+}
+
+EXPORT_API int emf_filter_add(emf_rule_t* filter_info, int* err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("filter_info[%p], err_code[%p]", filter_info, err_code);
+
+ /* default variable */
+ int ret = false, err = EMF_ERROR_NONE;
+ if (!filter_info || !(filter_info->value)) {
+ EM_DEBUG_EXCEPTION("filter_info[%p]", filter_info);
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ /*
+ if (filter_info->faction != EMF_FILTER_BLOCK) {
+ EM_DEBUG_EXCEPTION("filter_info->faction[%d] is not supported", filter_info->faction);
+ err = EMF_ERROR_NOT_SUPPORTED;
+ goto FINISH_OFF;
+ }
+
+ if (filter_info->faction == EMF_FILTER_MOVE && !filter_info->mailbox) {
+ EM_DEBUG_EXCEPTION("filter_info->faction[%d], filter_info->mailbox[%p]", filter_info->faction, filter_info->mailbox);
+ err = EMF_ERROR_INVALID_FILTER;
+ goto FINISH_OFF;
+ }
+ */
+
+ filter_info->account_id = ALL_ACCOUNT;
+
+ if (em_storage_find_rule((emf_mail_rule_tbl_t*)filter_info, true, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_find_rule failed [%d]", err);
+ err = EMF_ERROR_ALREADY_EXISTS;
+ goto FINISH_OFF;
+ }
+
+ if (!em_storage_add_rule((emf_mail_rule_tbl_t*)filter_info, true, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_add_rule failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ if (!em_core_mail_filter_by_rule((emf_rule_t*)filter_info, &err)) {
+ EM_DEBUG_EXCEPTION("em_core_mail_filter_by_rule failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ ret = true;
+
+FINISH_OFF:
+
+ if (err_code)
+ *err_code = err;
+ EM_DEBUG_FUNC_END();
+ return ret;
+}
+
+EXPORT_API int emf_filter_change(int filter_id, emf_rule_t* filter_info, int* err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("filter_id[%d], filter_info[%p], err_code[%p]", filter_id, filter_info, err_code);
+
+ /* default variable */
+ int ret = false;
+ int err = EMF_ERROR_NONE;
+
+ if ((filter_id <= 0) || !filter_info) {
+ EM_DEBUG_EXCEPTION("filter_id[%d], filter_info[%p]", filter_id, filter_info);
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ if (!emf_filter_check_filter_id(ALL_ACCOUNT, filter_id, &err)) {
+ EM_DEBUG_EXCEPTION("emf_filter_check_filter_id falied [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ if (!em_storage_change_rule(ALL_ACCOUNT, filter_id, (emf_mail_rule_tbl_t*)filter_info, true, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_change_rule falied [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ ret = true;
+
+FINISH_OFF:
+ if (err_code)
+ *err_code = err;
+ EM_DEBUG_FUNC_END();
+ return ret;
+}
+
+EXPORT_API int emf_filter_delete(int filter_id, int* err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("filter_id[%d, err_code[%p]", filter_id, err_code);
+
+ /* default variable */
+ int ret = false;
+ int err = EMF_ERROR_NONE;
+
+ if (filter_id <= 0) {
+ EM_DEBUG_EXCEPTION(" fliter_id[%d]", filter_id);
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ if (!emf_filter_check_filter_id(ALL_ACCOUNT, filter_id, &err)) {
+ EM_DEBUG_EXCEPTION(" emf_filter_check_filter_id failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ if (!em_storage_delete_rule(ALL_ACCOUNT, filter_id, true, &err)) {
+ EM_DEBUG_EXCEPTION(" em_storage_delete_rule failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ ret = true;
+
+FINISH_OFF:
+ if (err_code)
+ *err_code = err;
+ EM_DEBUG_FUNC_END();
+ return ret;
+}
+
+EXPORT_API int emf_filter_free(emf_rule_t** filter_info, int count, int* err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("filter_info[%p], count[%d], err_code[%p]", filter_info, count, err_code);
+
+ /* default variable */
+ int ret = false;
+ int err = EMF_ERROR_NONE;
+
+ if (count > 0) {
+ if (!filter_info || !*filter_info) {
+ EM_DEBUG_EXCEPTION(" filter_info[%p], count[%d]", filter_info, count);
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ emf_rule_t* p = *filter_info;
+ int i;
+
+ for (i = 0; i < count; i++) {
+ EM_SAFE_FREE(p[i].value);
+ EM_SAFE_FREE(p[i].mailbox);
+ }
+
+ EM_SAFE_FREE(p); *filter_info = NULL;
+ }
+
+ ret = true;
+
+FINISH_OFF:
+ if (err_code)
+ *err_code = err;
+ EM_DEBUG_FUNC_END();
+ return ret;
+}
+
+
+/* ----- internal functions --------------------------------------------*/
+int emf_init_account_reference()
+{
+ EM_DEBUG_FUNC_BEGIN();
+ return em_core_init_account_reference();
+}
+
+emf_account_t* emf_get_account_reference(int account_id)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ return em_core_get_account_reference(account_id);
+}
+
+int emf_free_account_reference()
+{
+ EM_DEBUG_FUNC_BEGIN();
+ return em_core_free_account_reference();
+}
+
+EXPORT_API int emf_account_insert_accountinfo_to_contact(emf_account_t* account)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ if(!account)
+ return false;
+
+ int ret = false;
+ EM_DEBUG_FUNC_END();
+ return ret;
+}
+
+EXPORT_API int emf_account_update_accountinfo_to_contact(emf_account_t* old_account, emf_account_t* new_account)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ if(!old_account || !new_account)
+ return false;
+
+ int ret = false;
+ EM_DEBUG_FUNC_END();
+ return ret;
+}
+
+/* EOF */
diff --git a/email-engine/emf-auto-poll.c b/email-engine/emf-auto-poll.c
new file mode 100755
index 0000000..7c8eadd
--- /dev/null
+++ b/email-engine/emf-auto-poll.c
@@ -0,0 +1,480 @@
+/*
+* email-service
+*
+* Copyright (c) 2000 - 2011 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.
+*
+*/
+
+
+#include "em-core-types.h"
+
+#ifdef __FEATURE_AUTO_POLLING__
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <time.h>
+#include <stdarg.h> /* Needed for the definition of va_list */
+#include <glib.h>
+
+#include "emflib.h"
+
+#include "emf-auto-poll.h"
+#include "emf-types.h"
+#include "emf-dbglog.h"
+#include "em-storage.h"
+
+typedef struct _emf_account_alarm_binder
+{
+ int account_id;
+ alarm_id_t alarm_id;
+ int timer_interval;
+} emf_account_alarm_binder;
+
+/* global list */
+typedef struct _emf_account_alarm_binder_list_t
+{
+ emf_account_alarm_binder account_alarm_binder;
+ struct _emf_account_alarm_binder_list_t *next;
+}emf_account_alarm_binder_list_t;
+
+/* sowmya.kr@samsung.com, 23022010, Implementation of auto-polling feature */
+
+emf_account_alarm_binder_list_t *g_account_alarm_binder_list = NULL;
+
+static int emf_get_polling_alarm_and_timerinterval(int account_id, alarm_id_t *alarm_id, int *timer_interval);
+static int emf_get_polling_account_and_timeinterval(alarm_id_t alarm_id, int *account_id, int *timer_interval);
+static int emf_create_alarm(int alarm_interval, alarm_id_t *p_alarm_id);
+static int add_to_account_alarm_binder_list(emf_account_alarm_binder_list_t *p_account_alarm_binder);
+static int remove_from_account_alarm_binder_list(int account_id);
+static int update_account_alarm_binder_list(int account_id, alarm_id_t alarm_id);
+
+EXPORT_API int emf_add_polling_alarm(int account_id, int alarm_interval)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ if(!account_id || (alarm_interval <= 0)) {
+ EM_DEBUG_EXCEPTION("Invalid param");
+ return false;
+ }
+ EM_DEBUG_EXCEPTION(" emf_add_polling_alarm : account_id [%d]",account_id);
+ if(is_auto_polling_started(account_id)) {
+ EM_DEBUG_EXCEPTION("auto polling already started for account : return");
+ return true;
+ }
+
+ alarm_id_t alarmID = 0;
+ emf_account_alarm_binder_list_t *p_account_alarm_binder = NULL;
+
+ if(!emf_create_alarm(alarm_interval, &alarmID)) {
+ EM_DEBUG_EXCEPTION("emf_create_alarm failed");
+ return false;
+ }
+
+ p_account_alarm_binder = (emf_account_alarm_binder_list_t*)em_core_malloc(sizeof(emf_account_alarm_binder_list_t));
+ if(!p_account_alarm_binder) {
+ EM_DEBUG_EXCEPTION("malloc Failed ");
+ return false;
+ }
+
+ p_account_alarm_binder->account_alarm_binder.account_id = account_id;
+ p_account_alarm_binder->account_alarm_binder.alarm_id = alarmID;
+ p_account_alarm_binder->account_alarm_binder.timer_interval = alarm_interval;
+
+ add_to_account_alarm_binder_list(p_account_alarm_binder);
+
+ return true;
+}
+
+
+EXPORT_API int emf_remove_polling_alarm(int account_id)
+{
+
+ EM_DEBUG_FUNC_BEGIN();
+
+ if(!account_id) {
+ EM_DEBUG_EXCEPTION("Invalid param ");
+ return false;
+ }
+
+ alarm_id_t alarm_id = 0;
+ int a_nErrorCode = 0, retval =0;
+
+ if(!emf_get_polling_alarm_and_timerinterval(account_id,&alarm_id,NULL)) {
+ EM_DEBUG_EXCEPTION("emf_get_polling_alarm_and_timerinterval failed");
+ return false;
+ }
+
+ /* delete alarm */
+ if (alarm_id > 0) {
+ a_nErrorCode = alarmmgr_remove_alarm(alarm_id);
+
+ EM_DEBUG_LOG("ErrorCode :%d, Return Value:%d ",a_nErrorCode,retval);
+
+ if(!retval)
+ return false;
+ }
+
+ /* delete from list */
+ if(!remove_from_account_alarm_binder_list(account_id)) {
+ EM_DEBUG_EXCEPTION("remove_from_account_alarm_binder_list failed");
+ return false;
+ }
+
+ return true;
+}
+
+EXPORT_API int is_auto_polling_started(int account_id)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ if(g_account_alarm_binder_list == NULL) {
+ EM_DEBUG_EXCEPTION("g_account_alarm_binder_list NULL ");
+ return false;
+ }
+
+ emf_account_alarm_binder_list_t *p_temp = g_account_alarm_binder_list;
+ int match_found = false;
+
+ while(p_temp != NULL) {
+ if(p_temp->account_alarm_binder.account_id == account_id) {
+ EM_DEBUG_EXCEPTION("account match found : polling already started");
+ match_found = true;
+ break;
+ }
+ p_temp = p_temp->next;
+ }
+
+ if(!match_found) {
+ EM_DEBUG_EXCEPTION("account match not found : polling not started");
+ return false;
+ }
+ return true;
+}
+EXPORT_API int emf_alarm_polling_cb(alarm_id_t alarm_id, void* user_param)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+/* tzset(); */
+ time_t ct = time(&ct);
+ struct tm* lt = localtime(&ct);
+
+ if (lt) {
+ EM_DEBUG_LOG( "Current Time : [%d-%d-%d %d:%d:%d] ",
+ lt->tm_year + 1900, lt->tm_mon + 1, lt->tm_mday,
+ lt->tm_hour, lt->tm_min, lt->tm_sec);
+ }
+
+
+ emf_mailbox_t mailbox = {0};
+ int account_id = 0, err = EMF_ERROR_NONE, timer_interval =0, alarmID =0,ret = false;
+ char* mailbox_name = NULL;
+
+ if(!emf_get_polling_account_and_timeinterval(alarm_id,&account_id,&timer_interval)) {
+ EM_DEBUG_EXCEPTION("emf_get_polling_account failed");
+ return false;
+ }
+
+ EM_DEBUG_EXCEPTION(" emf_alarm_polling_cb : account_id [%d]",account_id);
+ /* create alarm, for polling */
+ if(!emf_create_alarm(timer_interval,&alarmID)) {
+ EM_DEBUG_EXCEPTION("emf_create_alarm failed");
+ return false;
+ }
+
+ /*update alarm ID in list */
+ /* delete from list */
+ if(!update_account_alarm_binder_list(account_id,alarmID)) {
+ EM_DEBUG_EXCEPTION("update_account_alarm_binder_list failed");
+ return false;
+ }
+
+ memset(&mailbox, 0x00, sizeof(emf_mailbox_t));
+ mailbox.account_id = account_id;
+
+ if (!em_storage_get_mailboxname_by_mailbox_type(mailbox.account_id,EMF_MAILBOX_TYPE_INBOX,&mailbox_name, false, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_get_mailboxname_by_mailbox_type failed [%d]", err);
+
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+ mailbox.name = mailbox_name;
+
+ if (!emf_mailbox_sync_header(&mailbox, NULL, &err)) {
+ EM_DEBUG_EXCEPTION("emf_mailbox_sync_header falied [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ ret = true;
+FINISH_OFF :
+ EM_SAFE_FREE(mailbox_name);
+
+ return ret;
+}
+
+static int emf_get_polling_alarm_and_timerinterval(int account_id, alarm_id_t *alarm_id, int *timer_interval)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ if(!account_id || !alarm_id)
+ return false;
+
+ if(g_account_alarm_binder_list == NULL) {
+ EM_DEBUG_EXCEPTION("g_account_alarm_binder_list NULL ");
+ return false;
+ }
+
+ emf_account_alarm_binder_list_t *p_temp = g_account_alarm_binder_list;
+ int match_found = false;
+
+ while(p_temp != NULL) {
+ if(p_temp->account_alarm_binder.account_id == account_id) {
+ EM_DEBUG_EXCEPTION("account match found ");
+ *alarm_id = p_temp->account_alarm_binder.alarm_id;
+
+ if(timer_interval)
+ *timer_interval = p_temp->account_alarm_binder.timer_interval;
+
+ match_found = true;
+ break;
+ }
+
+ p_temp = p_temp->next;
+ }
+
+ if(!match_found) {
+ EM_DEBUG_EXCEPTION("account match not found ");
+ return false;
+ }
+
+
+ return true;
+}
+
+static int emf_get_polling_account_and_timeinterval(alarm_id_t alarm_id, int *account_id, int *timer_interval)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ if(!alarm_id || !account_id)
+ return false;
+
+ if(g_account_alarm_binder_list == NULL) {
+ EM_DEBUG_EXCEPTION("g_account_alarm_binder_list NULL ");
+ return false;
+ }
+
+ emf_account_alarm_binder_list_t *p_temp = g_account_alarm_binder_list;
+ int match_found = false;
+
+ while(p_temp != NULL) {
+ if(p_temp->account_alarm_binder.alarm_id == alarm_id) {
+ EM_DEBUG_EXCEPTION("aalrm match found ");
+ *account_id = p_temp->account_alarm_binder.account_id;
+
+ if(timer_interval)
+ *timer_interval = p_temp->account_alarm_binder.timer_interval;
+
+ match_found = true;
+ break;
+ }
+
+ p_temp = p_temp->next;
+ }
+
+ if(!match_found) {
+ EM_DEBUG_EXCEPTION("aalrm match not found ");
+ return false;
+ }
+
+ return true;
+}
+
+#define AUTO_POLL_DESTINATION "email-service"
+static int emf_create_alarm(int alarm_interval, alarm_id_t *p_alarm_id)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ /* tzset(); */
+ time_t ct = time(&ct);
+ struct tm* lt = localtime(&ct);
+
+ if (lt) {
+ EM_DEBUG_LOG( "Current Time : [%d-%d-%d %d:%d:%d] ",
+ lt->tm_year + 1900, lt->tm_mon + 1, lt->tm_mday,
+ lt->tm_hour, lt->tm_min, lt->tm_sec);
+ }
+
+ /* alarm_info_t alarm_info = {0}; */
+ int a_nErrorCode = 0;
+ int retval =0;
+
+ if((alarm_interval <= 0) || !p_alarm_id) {
+ EM_DEBUG_EXCEPTION("Invalid param ");
+ return false;
+ }
+
+ /* time_t current_time = {0}; */
+ /* struct tm current_tm = {0}; */
+ int error_code = 0;
+
+ /* Fill alarm info */
+ /* int timeFormat = 0; */ /*0 means 12hrs , 1 means 24hrs*/
+
+ /* TO DO, need to findout header for DBG_MID_MSGPORTING_NORMAL and then we have to use this */
+ /* error_code = vconf_get_int(DBG_MID_MSGPORTING_NORMAL, &timeFormat); */
+
+ a_nErrorCode = alarmmgr_init(AUTO_POLL_DESTINATION);
+ EM_DEBUG_LOG("ErrorCode :%d, Return Value:%d ",a_nErrorCode,retval);
+
+ if(!retval)
+ return false;
+
+ a_nErrorCode = alarmmgr_set_cb(emf_alarm_polling_cb, NULL);
+ EM_DEBUG_LOG("ErrorCode :%d, Return Value:%d ",a_nErrorCode,retval);
+
+ if(!retval)
+ return false;
+
+ error_code = alarmmgr_add_alarm(ALARM_TYPE_VOLATILE, alarm_interval * 60 /*(sec)*/, ALARM_REPEAT_MODE_ONCE, AUTO_POLL_DESTINATION, p_alarm_id);
+
+ EM_DEBUG_LOG("ErrorCode :%d,Return Value :%d ",error_code,retval);
+
+ if(!retval)
+ return false;
+
+ return true;
+}
+
+EXPORT_API int emf_free_account_alarm_binder_list()
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ emf_account_alarm_binder_list_t *p = g_account_alarm_binder_list, *p_next = NULL;
+ int a_nErrorCode = 0;
+
+ /* delete alarm as well */
+ while (p) {
+ /* delete alarm */
+ if (p->account_alarm_binder.alarm_id > 0) {
+ a_nErrorCode = alarmmgr_remove_alarm(p->account_alarm_binder.alarm_id);
+ }
+
+ p_next = p->next;
+ EM_SAFE_FREE(p);
+ p = p_next;
+ }
+
+ g_account_alarm_binder_list = NULL;
+
+ return true;
+}
+
+static int add_to_account_alarm_binder_list(emf_account_alarm_binder_list_t *p_account_alarm_binder)
+{
+ emf_account_alarm_binder_list_t *p_temp = NULL;
+
+ if(!p_account_alarm_binder) {
+ EM_DEBUG_EXCEPTION("Invalid param ");
+ return false;
+ }
+
+ if(g_account_alarm_binder_list == NULL) {
+ g_account_alarm_binder_list = p_account_alarm_binder;
+ p_account_alarm_binder = NULL;
+ }
+ else {
+ p_temp = g_account_alarm_binder_list;
+ while(p_temp->next != NULL)
+ p_temp = p_temp->next;
+
+ p_temp->next = p_account_alarm_binder;
+ p_account_alarm_binder = NULL;
+ }
+
+ return true;
+}
+
+static int remove_from_account_alarm_binder_list(int account_id)
+{
+ emf_account_alarm_binder_list_t *p_temp = g_account_alarm_binder_list, *p_prev = NULL;
+ int match_found = false;
+
+ if(!account_id) {
+ EM_DEBUG_EXCEPTION("Invalid param ");
+ return false;
+ }
+
+ /* first node mattch */
+ if(p_temp->account_alarm_binder.account_id == account_id) {
+ /* match found */
+ match_found = true;
+ g_account_alarm_binder_list = p_temp->next;
+ EM_SAFE_FREE(p_temp);
+ }
+ else {
+ while(p_temp != NULL) {
+ if(p_temp->account_alarm_binder.account_id == account_id) {
+ EM_DEBUG_EXCEPTION("account match found ");
+
+ p_prev->next = p_temp->next;
+ EM_SAFE_FREE(p_temp);
+
+ match_found = true;
+ break;
+ }
+
+ p_prev = p_temp;
+ p_temp = p_temp->next;
+ }
+ }
+
+ if(!match_found)
+ return false;
+
+ return true;
+}
+
+static int update_account_alarm_binder_list(int account_id, alarm_id_t alarm_id)
+{
+ emf_account_alarm_binder_list_t *p_temp = g_account_alarm_binder_list;
+ int match_found = false;
+
+ if( !account_id || !alarm_id) {
+ EM_DEBUG_EXCEPTION("Invalid param ");
+ return false;
+ }
+
+ while(p_temp != NULL) {
+ if(p_temp->account_alarm_binder.account_id == account_id) {
+ EM_DEBUG_EXCEPTION("account match found ");
+ /* update alarm id */
+ p_temp->account_alarm_binder.alarm_id = alarm_id;
+ match_found = true;
+ break;
+ }
+ p_temp = p_temp->next;
+ }
+
+ if(!match_found) {
+ EM_DEBUG_EXCEPTION("account match not found ");
+ return false;
+ }
+
+ return true;
+}
+#endif
+
diff --git a/email-engine/emf-emn-noti.c b/email-engine/emf-emn-noti.c
new file mode 100755
index 0000000..4ef4d4e
--- /dev/null
+++ b/email-engine/emf-emn-noti.c
@@ -0,0 +1,47 @@
+/*
+* email-service
+*
+* Copyright (c) 2000 - 2011 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.
+*
+*/
+
+
+
+#include <vconf.h>
+#include <string.h>
+#include "emflib.h"
+#include "emf-emn-noti.h"
+#include "emf-emn.h"
+#include "emf-dbglog.h"
+#include <glib.h>
+
+int emf_emn_noti_init(void)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ EM_DEBUG_LOG("SUBSCRIE for User.Push.Email SUCCESSS >>> \n");
+
+ return 0;
+}
+
+int emf_emn_noti_quit(gboolean bExtDest)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ return 0;
+}
+
+/* EOF */
diff --git a/email-engine/emf-emn.c b/email-engine/emf-emn.c
new file mode 100755
index 0000000..25ec298
--- /dev/null
+++ b/email-engine/emf-emn.c
@@ -0,0 +1,612 @@
+/*
+* email-service
+*
+* Copyright (c) 2000 - 2011 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.
+*
+*/
+
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <time.h>
+#include <stdarg.h> /* Needed for the definition of va_list */
+#include <glib.h>
+
+#include "emflib.h"
+
+/* #include "emf-emn-storage.h" */
+#include "emf-emn.h"
+
+/* --------------------------------------------------------------------------------*/
+/* ----- WBXML Parsing (2007.06.09) --------------------------------------------------*/
+/* --------------------------------------------------------------------------------*/
+#ifdef USE_OMA_EMN
+
+#include <wbxml.h>
+#include <wbxml_errors.h>
+#include "emf-dbglog.h"
+#include <vconf.h>
+#include "emf-global.h"
+
+typedef struct
+{
+ int account_id;
+ emf_emn_noti_cb callback;
+ void* user_data;
+}
+emf_emn_noti_pack_t;
+
+
+char*
+__emn_get_username(char *account_username);
+static void
+_cb_parser_start_document(void* ctx, WB_LONG charset, const WBXMLLangEntry* lang)
+{
+ EM_DEBUG_LOG("_cb_parser_start_document\n");
+ EM_DEBUG_LOG("Parsing Document:\n\tRoot Element: %s\n\tPublic ID: %s\n\tDTD: %s\n",
+ lang->publicID->xmlRootElt,
+ lang->publicID->xmlPublicID,
+ lang->publicID->xmlDTD);
+}
+
+static void
+_cb_parser_end_document(void* ctx)
+{
+ EM_DEBUG_LOG("_cb_parser_end_document\n");
+}
+
+static void
+_cb_parser_start_element(void* ctx, WBXMLTag* element, WBXMLAttribute** atts, WB_BOOL empty)
+{
+ WB_UTINY* p, **pp = ctx;
+ WB_ULONG j = 0, len = 0;
+ EM_DEBUG_LOG("parse_clb_start_element\n");
+
+ if (strcasecmp((char *)wbxml_tag_get_xml_name(element), "emn") != 0)
+ {
+ EM_DEBUG_LOG("not email notification\n");
+ return ;
+ }
+
+ if (atts == NULL)
+ {
+ EM_DEBUG_LOG("no emn attributes\n");
+ return ;
+ }
+
+ len = strlen((char *)wbxml_tag_get_xml_name(element)) + 1;
+ while (atts[j] != NULL)
+ {
+ len += (strlen((char *)wbxml_attribute_get_xml_name(atts[j])) + strlen((char *)wbxml_attribute_get_xml_value(atts[j])) + 7);
+ j++;
+ }
+ len += 3;
+
+ if (!(p = malloc(sizeof(WB_UTINY) * len + 1)))
+ {
+ return ;
+ }
+
+ EM_DEBUG_LOG("<%s", (char *)wbxml_tag_get_xml_name(element));
+ sprintf((char *)p, "<%s", (char *)wbxml_tag_get_xml_name(element));
+
+ j = 0;
+ while (atts[j] != NULL)
+ {
+ EM_DEBUG_LOG(" %s=\"%s\"", (char *)wbxml_attribute_get_xml_name(atts[j]), (char *)wbxml_attribute_get_xml_value(atts[j]));
+ strcat((char *)p, " ");
+ strcat((char *)p, (char *)wbxml_attribute_get_xml_name(atts[j]));
+ strcat((char *)p, "=");
+ strcat((char *)p, "\"");
+ strcat((char *)p, (char *)wbxml_attribute_get_xml_value(atts[j]));
+ strcat((char *)p, "\"");
+ j++;
+ }
+
+ if (empty)
+ {
+ EM_DEBUG_LOG("/>\n");
+ strcat((char *)p, "/>");
+ }
+ else
+ {
+ EM_DEBUG_LOG(">\n");
+ strcat((char *)p, ">");
+ }
+
+ *pp = p;
+}
+
+static void
+_cb_parser_end_element(void* ctx, WBXMLTag* element, WB_BOOL empty)
+{
+ EM_DEBUG_LOG("parse_clb_end_element\n");
+}
+
+static void
+_cb_parser_characters(void* ctx, WB_UTINY* ch, WB_ULONG start, WB_ULONG length)
+{
+ EM_DEBUG_LOG("_cb_parser_characters\n");
+}
+
+static int _get_addr_from_element(unsigned char* elm,
+ int* type,
+ unsigned char** user_name,
+ unsigned char** host_addr,
+ unsigned char** mbox_name,
+ unsigned char** auth_type)
+{
+ unsigned char* p;
+ unsigned char* s;
+ unsigned char* user = NULL;
+ unsigned char* host = NULL;
+ unsigned char* mbox = NULL;
+ unsigned char* auth = NULL;
+
+ EM_DEBUG_FUNC_BEGIN();
+
+ if (!(p = (unsigned char*)strstr((char *)elm, "mailbox"))) /* add acetrack.20080331.K8.4043 */
+ {
+ EM_DEBUG_EXCEPTION("invalid notification data\n");
+ return 0;
+ }
+
+ p += 9;
+ s = (unsigned char*)strchr((char *)p, '\"');
+ /* 2007-05-08 by acetrack */
+ if (s)
+ *s = '\0';
+
+ switch (p[0])
+ {
+ case 'm':/* mailat (RFC2234) */
+ *type = 1;
+ p += 7;
+ if (!(s = (unsigned char*)strchr((char *)p, '@'))) return 0;
+ *s = '\0';
+ user = (unsigned char*)EM_SAFE_STRDUP((char *)p);
+ s++;
+ host = (unsigned char*)EM_SAFE_STRDUP((char *)s);
+ mbox = NULL;
+ auth = NULL;
+ break;
+
+ case 'p':/* pop3 (RFC2384) */
+ *type = 2;
+ p += 6;
+ if ((s = (unsigned char*)strchr((char *)p, ';')))
+ {
+ *s = '\0';
+ if (strlen((char *)p)) user = (unsigned char*)EM_SAFE_STRDUP((char *)p);
+ p = s + 1;
+ }
+ if ((s = (unsigned char*)strchr((char *)p, '@')))
+ {
+ *s = '\0';
+ if (user || *(p - 3) == '/')
+ {
+ if (strncmp((char *)p, "AUTH=", 5) == 0) auth = (unsigned char*)EM_SAFE_STRDUP((char *)p + 5);
+ }
+ else
+ user = (unsigned char*)EM_SAFE_STRDUP((char *)p);
+ p = s + 1;
+ }
+ if ((s = (unsigned char*)strchr((char *)p, ':')))
+ {
+ *s = '\0';
+ s++;
+ EM_DEBUG_LOG("PORT:%s\n", s);
+ }
+ host = (unsigned char*)EM_SAFE_STRDUP((char *)p);
+ mbox = NULL;
+ break;
+
+ case 'i':/* imap (RFC2192) */
+ *type = 3;
+ p += 7;
+ if ((s = (unsigned char*)strchr((char *)p, ';')))
+ {
+ *s = '\0';
+ if (strlen((char *)p)) user = (unsigned char*)EM_SAFE_STRDUP((char *)p);
+ p = s + 1;
+ }
+ if ((s = (unsigned char*)strchr((char *)p, '@')))
+ {
+ *s = '\0';
+ if (user || *(p - 3) == '/')
+ {
+ if (strncmp((char *)p, "AUTH=", 5) == 0) auth = (unsigned char*)EM_SAFE_STRDUP((char *)p + 5);
+ }
+ else
+ user = (unsigned char*)EM_SAFE_STRDUP((char *)p);
+ p = s + 1;
+ }
+
+ if ((s = (unsigned char *)strchr((char *)p, '/'))) * s = '\0';
+ host = (unsigned char *)EM_SAFE_STRDUP((char *)p);
+ p = s + 1;
+
+ if ((s = (unsigned char*)strchr((char *)p, '?'))) * s = '\0';
+ else if ((s = (unsigned char*)strchr((char *)p, ';'))) * s = '\0';
+ else s = p + strlen((char *)p);
+ if (*(s - 1) == '/') *(s - 1) = '\0';
+
+ if (strlen((char *)p)) mbox =(unsigned char*) EM_SAFE_STRDUP((char *)p);
+ break;
+
+ case 'h': /* not supported */
+ EM_DEBUG_LOG("Http URI is not yet supported\n");
+ return 0;
+
+ default:
+ return 0;
+ }
+
+ *user_name = user;
+ *host_addr = host;
+ *mbox_name = mbox;
+ *auth_type = auth;
+
+ return 1;
+}
+
+static int
+_get_time_from_element(unsigned char* elm,
+ unsigned char** time_stamp)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ unsigned char* p, *s, *stamp = NULL;
+ if (!(p = (unsigned char*)strstr((char *)elm, "timestamp")))
+ {
+ EM_DEBUG_EXCEPTION("invalid notification data\n");
+ return 0;
+ }
+
+ p += 11;
+ s = (unsigned char*)strchr((char *)p, '\"');
+ /* 2007-05-08 by acetrack */
+ if (s)
+ *s = '\0';
+
+ stamp = malloc(15);
+ if (!stamp) /* added acetrack.20080331.K8.4045 */
+ {
+ EM_DEBUG_EXCEPTION("malloc failed");
+ return 0;
+ }
+ memcpy(stamp, p, 4);
+ memcpy(stamp + 4, p + 5, 2);
+ memcpy(stamp + 6, p + 8, 2);
+ memcpy(stamp + 8, p + 11, 2);
+ memcpy(stamp + 10, p + 14, 2);
+ memcpy(stamp + 12, p + 17, 2);
+ stamp[14] = '\0';
+
+ *time_stamp = stamp;
+
+ return 1;
+}
+
+/* <emn mailbox="mailat:user@wapforum.org" timestamp="2002-04-16T06:40:00Z"/> */
+static int _get_data_from_element(unsigned char* elm,
+ int* type,
+ unsigned char** user_name,
+ unsigned char** host_addr,
+ unsigned char** mbox_name,
+ unsigned char** auth_type,
+ unsigned char** time_stamp)
+{
+
+ EM_DEBUG_FUNC_BEGIN();
+ if (!_get_time_from_element(elm, time_stamp))
+ {
+ return 0;
+ }
+
+ /* must call get_addr_from_element after calling _get_time_from_element */
+ if (!_get_addr_from_element(elm, type, user_name, host_addr, mbox_name, auth_type))
+ {
+ EM_SAFE_FREE*time_stamp) /* added acetrack.20080331.K8.4046 */
+ return 0;
+ }
+
+ return 1;
+}
+
+/* Parse the Email address to Get the user Name for the account [deepam.p@samsung.com] */
+char*
+__emn_get_username(char *account_username)
+{
+
+ EM_IF_NULL_RETURN_VALUE(account_username, NULL);
+
+ int index = 0;
+ char **token_list = NULL;
+ char *username = NULL, *name = NULL;
+
+ username = g_strdup(account_username);
+ token_list = g_strsplit_set(username, "@", -1);
+
+ if (username) {
+ g_free(username);
+ }
+
+ if (token_list[index] != NULL)
+ {
+ name = g_strdup(token_list[index]);
+ g_strfreev(token_list); /* MUST BE. */
+ EM_DEBUG_LOG("ACCOUNT USER NAME [%s] \n", name);
+ return name;
+ }
+ else
+ return NULL;
+
+}
+
+/* description
+ * get account from OMA EMN data
+ * arguments
+ * wbxml_b64 : BASE64 encoded data
+ * account_id: id of account to be retrieved from EMN data
+ * mailbox : if mail-box information exists in EMN data, mailbox holds the name of mailbox.
+ * err_code : hold error code
+ * return
+ * succeed : 1
+ * fail : 0
+ */
+static int
+_get_emn_account(unsigned char* wbxml_b64, emf_account_t* account, char** mailbox, int* err_code)
+{
+ EM_DEBUG_LOG("_get_emn_account Enter");
+ WBXMLContentHandler parse_handler = {
+ (WBXMLStartDocumentHandler) _cb_parser_start_document,
+ (WBXMLEndDocumentHandler) _cb_parser_end_document,
+ (WBXMLStartElementHandler) _cb_parser_start_element,
+ (WBXMLEndElementHandler) _cb_parser_end_element,
+ (WBXMLCharactersHandler) _cb_parser_characters,
+ NULL
+ };
+
+ WBXMLParser* wbxml_parser = NULL;
+ WB_UTINY* wbxml = NULL;
+ WB_UTINY* elm = NULL;
+ WB_ULONG wbxml_len = 0;
+ WB_ULONG err_idx = 0;
+ WBXMLError ret = WBXML_OK;
+ emf_account_t* accounts = NULL;
+ unsigned char* user_name = NULL;
+ unsigned char* host_addr = NULL;
+ unsigned char* mbox_name = NULL;
+ unsigned char* auth_type = NULL;
+ unsigned char* time_stamp = NULL;
+ int type = 0;
+ int i = 0;
+ int count = 0;
+ int retr = false;
+ int err = EMF_ERROR_NONE;
+
+ EM_DEBUG_LOG("");
+
+ if (!wbxml_b64 || !account)
+ {
+ EM_DEBUG_EXCEPTION(">>>> Invalid Parameter >>>> \n");
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ wbxml = g_base64_decode((const char*)wbxml_b64, (unsigned int*)&wbxml_len);
+ EM_DEBUG_LOG("wbxml = %p\n", wbxml);
+ EM_DEBUG_LOG("wbxml_len = %d\n", wbxml_len);
+
+ /* create wbxml parser */
+ if (!(wbxml_parser = wbxml_parser_create()))
+ {
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ /* initialize wbxml parser */
+ wbxml_parser_set_user_data(wbxml_parser, (void*)&elm);
+ wbxml_parser_set_content_handler(wbxml_parser, &parse_handler);
+
+ /* parsing wbxml */
+ if ((ret = wbxml_parser_parse(wbxml_parser, wbxml, wbxml_len)) != WBXML_OK)
+ {
+ err_idx = wbxml_parser_get_current_byte_index(wbxml_parser);
+ EM_DEBUG_LOG("Parsing failed at %u - Token %x - %s", err_idx, wbxml[err_idx], wbxml_errors_string(ret));
+
+ err = EMF_ERROR_XML_PARSER_FAILURE;
+ goto FINISH_OFF;
+ }
+ else
+ {
+ EM_DEBUG_LOG("Parsing OK !\n");
+ }
+
+ /* destroy parser */
+ wbxml_parser_destroy(wbxml_parser);
+ wbxml_parser = NULL;
+
+ /* free buffer */
+ wbxml_free(wbxml);
+ wbxml = NULL;
+
+ if (!elm)
+ {
+ EM_DEBUG_EXCEPTION("invalid elements\n");
+
+ err = EMF_ERROR_XML_PARSER_FAILURE;
+ goto FINISH_OFF;
+ }
+
+ EM_DEBUG_LOG("elements = [%s]\n", elm);
+ _get_data_from_element(elm, &type, &user_name, &host_addr, &mbox_name, &auth_type, &time_stamp);
+
+ EM_SAFE_FREE(elm);
+
+ EM_DEBUG_LOG("user_type = [%d]\n", type);
+ EM_DEBUG_LOG("user_name = [%s]\n", (char *)user_name ? (char*)user_name : "NIL");
+ EM_DEBUG_LOG("host_addr = [%s]\n", (char *)host_addr ? (char*)host_addr : "NIL");
+ EM_DEBUG_LOG("mbox_name = [%s]\n", (char *)mbox_name ? (char*)mbox_name : "NIL");
+ EM_DEBUG_LOG("auth_type = [%s]\n", (char *)auth_type ? (char*)auth_type : "NIL");
+ EM_DEBUG_LOG("time_stamp= [%s]\n", (char *)time_stamp? (char*)time_stamp: "NIL");
+
+ if (!emf_account_get_list(&accounts, &count, &err))
+ {
+ EM_DEBUG_EXCEPTION(" emf_account_get_list error");
+ err = EMF_ERROR_DB_FAILURE;
+ goto FINISH_OFF;
+ }
+
+ for (i = 0; i < count; i++)
+ {
+ /* sowmya.kr, 201009, Fix for EMN */
+ char* temp_account_name = NULL;
+ char *s = NULL;
+ /* EM_DEBUG_LOG(">>>> Account Information UserName [ %s ] Email Addr [ %s], Account ID [ %d] >>> \n",accounts[i].user_name,accounts[i].email_addr, accounts[i].account_id); */
+ temp_account_name =(char*) EM_SAFE_STRDUP((char *)accounts[i].user_name);
+
+ if ((s = (char*)strchr((char *)temp_account_name, '@'))) {
+ *s = '\0';
+ EM_SAFE_FREE(accounts[i].user_name);
+ accounts[i].user_name = (char*)EM_SAFE_STRDUP((char *)temp_account_name);
+ }
+ EM_SAFE_FREE(temp_account_name);
+ if (user_name) {
+ if (strcmp(accounts[i].user_name, (char *)user_name) == 0 &&
+ strstr(accounts[i].email_addr, (char *)host_addr)) {
+ EM_DEBUG_LOG(">>>> Account Match >>> \n");
+ if ((type == 1) ||
+ (type == 2 && accounts[i].receiving_server_type == EMF_SERVER_TYPE_POP3) ||
+ (type == 3 && accounts[i].receiving_server_type == EMF_SERVER_TYPE_IMAP4)) {
+ accounts[i].flag2 = type;
+ EM_DEBUG_LOG("found target account id[%d] name[%s]", accounts[i].account_id, accounts[i].user_name);
+ break;
+ }
+ }
+ }
+ }
+
+ if (i >= count) {
+ EM_DEBUG_EXCEPTION("no account was found");
+ err = EMF_ERROR_ACCOUNT_NOT_FOUND;
+ goto FINISH_OFF;
+ }
+ if (account) {
+ account->account_bind_type = accounts[i].account_bind_type;
+ account->account_id = accounts[i].account_id;
+ account->flag2 = accounts[i].flag2;
+ }
+
+ if (mailbox)
+ {
+ *mailbox = mbox_name ? (char *)mbox_name : NULL;
+ mbox_name = NULL;
+ }
+ emf_account_free(&accounts, count, NULL);
+ accounts = NULL;
+
+ retr = true;
+
+FINISH_OFF:
+ if (wbxml) wbxml_free(wbxml);
+ if (wbxml_parser) wbxml_parser_destroy(wbxml_parser);
+ EM_SAFE_FREE(elm);
+ if (accounts) emf_account_free(&accounts, count, NULL);
+ EM_SAFE_FREE(user_name);
+ EM_SAFE_FREE(mbox_name);
+ EM_SAFE_FREE(auth_type);
+ EM_SAFE_FREE(time_stamp);
+ if (err_code) *err_code = err;
+ return retr;
+}
+
+EXPORT_API int emf_emn_handler(unsigned char* wbxml_b64, emf_emn_noti_cb callback, int* err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("wbxml_b64[%p], callback[%p], err_code[%p]", wbxml_b64, callback, err_code);
+
+ int ret = false;
+ int err = EMF_ERROR_NONE;;
+ char* mailbox_name = NULL;
+ emf_mailbox_t mailbox = { 0 };
+ emf_account_t account = { 0 };
+ emf_emn_noti_pack_t* pack = NULL;
+ char* pmailbox = NULL;
+
+ if (!wbxml_b64) {
+ EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ pack = (emf_emn_noti_pack_t*)em_core_malloc(sizeof(emf_emn_noti_pack_t));
+ if (!pack) {
+ EM_DEBUG_EXCEPTION("em_core_malloc failed");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ if (!_get_emn_account(wbxml_b64, &account, &mailbox_name, &err)) {
+ EM_DEBUG_EXCEPTION("_get_emn_account failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ mailbox.account_id = account.account_id;
+
+ if (!em_storage_get_mailboxname_by_mailbox_type(mailbox.account_id,EMF_MAILBOX_TYPE_INBOX,&pmailbox, false, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_get_mailboxname_by_mailbox_type failed [%d", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+
+ if ((account.receiving_server_type == EMF_SERVER_TYPE_IMAP4) && (account.flag2 == 3)) {
+
+ if (!mailbox_name || strncmp(pmailbox, mailbox_name, strlen(pmailbox)) != 0) {
+ EM_DEBUG_EXCEPTION("invalid inbox name [%p]", mailbox_name);
+ err = EMF_ERROR_INVALID_MAILBOX;
+ goto FINISH_OFF;
+ }
+ }
+
+ /* sync header with mail server */
+ mailbox.name = mailbox_tbl->mailbox_name;
+
+ if (!emf_mailbox_sync_header(&mailbox, NULL, &err)) {
+ EM_DEBUG_EXCEPTION("emf_mailbox_sync_header falied [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ ret = true;
+
+FINISH_OFF:
+ if (ret == false)
+ EM_SAFE_FREE(pack);
+
+ EM_SAFE_FREE(pmailbox);
+
+ if (err_code != NULL)
+ *err_code = err;
+
+ return ret;
+}
+
+
+#endif /* USE_OMA_EMN */
+
+/* EOF */
diff --git a/email-engine/emf-etc.c b/email-engine/emf-etc.c
new file mode 100755
index 0000000..b615b12
--- /dev/null
+++ b/email-engine/emf-etc.c
@@ -0,0 +1,219 @@
+/*
+* email-service
+*
+* Copyright (c) 2000 - 2011 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.
+*
+*/
+
+
+
+/******************************************************************************
+ * File: emf-etc.c
+ * Desc: Mail Framework Etc Implementations
+ *
+ * Auth:
+ *
+ * History:
+ * 2006.08.16 : created
+ *****************************************************************************/
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <vconf.h>
+#include "emflib.h"
+#include "emf-account.h"
+#include "emf-dbglog.h"
+#include "emf-global.h"
+#include "em-core-types.h"
+#include "em-core-event.h"
+#include "em-core-utils.h"
+#include "em-storage.h"
+
+
+int emf_register_event_callback(emf_action_t action, emf_event_callback callback, void* event_data)
+{
+ return em_core_register_event_callback(action, callback, event_data);
+}
+
+int emf_unregister_event_callback(emf_action_t action, emf_event_callback callback)
+{
+ return em_core_unregister_event_callback(action, callback);
+}
+
+
+EXPORT_API void emf_get_event_queue_status(int* on_sending, int* on_receiving)
+{
+ em_core_get_event_queue_status(on_sending, on_receiving);
+}
+
+EXPORT_API int emf_get_pending_job(emf_action_t action, int account_id, int mail_id, emf_event_status_type_t* status)
+{
+ EM_DEBUG_FUNC_BEGIN("action[%d], account_id[%d], mail_id[%d]", action, account_id, mail_id);
+
+ return em_core_get_pending_event(action, account_id, mail_id, status);
+}
+
+EXPORT_API int emf_cancel_job(int account_id, int handle, int* err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("account_id[%d], handle[%d], err_code[%p]", account_id, handle, err_code);
+
+ int ret = false;
+ int err = EMF_ERROR_NONE;
+
+
+ if (!em_core_cancel_thread(handle, NULL, &err)) {
+ EM_DEBUG_EXCEPTION("em_core_cancel_thread failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ ret = true;
+
+FINISH_OFF:
+ if (err_code != NULL)
+ *err_code = err;
+ EM_DEBUG_FUNC_END();
+ return ret;
+}
+
+
+EXPORT_API int emf_mail_send_mail_cancel_job(int account_id, int mail_id, int* err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("account_id[%d], mail_id[%d], err_code[%p]", account_id, mail_id, err_code);
+
+ int ret = false;
+ int err = EMF_ERROR_NONE;
+ int handle = 0;
+ emf_account_t* ref_account = NULL;
+
+ if (account_id <= 0) {
+ EM_DEBUG_EXCEPTION("account_id[%d], mail_id[%d]", account_id, mail_id);
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+#ifdef __FEATURE_PROGRESS_IN_OUTBOX__
+
+ /* h.gahlaut@samsung.com: Moved this code from email_cancel_send_mail API to email-service engine
+ since this code has update DB operation which is failing in context of email application process
+ with an sqlite error -> sqlite3_step fail:8 */
+
+ /* which means #define SQLITE_READONLY 8 */ /* Attempt to write a readonly database */
+ emf_mail_t* mail = NULL;
+
+ if (!em_core_mail_get_mail(mail_id, &mail, &err)) {
+ EM_DEBUG_EXCEPTION("em_core_mail_get_mail failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ if (mail && mail->info) {
+ if (mail->info->extra_flags.status == EMF_MAIL_STATUS_SEND_CANCELED) {
+ EM_DEBUG_EXCEPTION(">>>> EMF_MAIL_STATUS_SEND_CANCELED Already set for Mail ID [ %d ]", mail_id);
+ goto FINISH_OFF;
+ }
+ else {
+ mail->info->extra_flags.status = EMF_MAIL_STATUS_SEND_CANCELED;
+
+ if(!em_core_mail_modify_extra_flag(mail_id, mail->info->extra_flags, &err)) {
+ EM_DEBUG_EXCEPTION("Failed to modify extra flag [%d]",err);
+ goto FINISH_OFF;
+ }
+ }
+ }
+
+#endif
+
+ if(!em_core_get_handle_by_mailId_from_transaction_info(mail_id , &handle )) {
+ EM_DEBUG_EXCEPTION("em_core_get_handle_by_mailId_from_transaction_info failed for mail_id[%d]", mail_id);
+ err = EMF_ERROR_HANDLE_NOT_FOUND;
+ goto FINISH_OFF;
+ }
+
+ if (!(ref_account = emf_get_account_reference(account_id))) {
+ EM_DEBUG_EXCEPTION("emf_get_account_reference failed [%d]", account_id);
+ err = EMF_ERROR_INVALID_ACCOUNT;
+ goto FINISH_OFF;
+ }
+
+ switch (ref_account->account_bind_type) {
+ case EMF_BIND_TYPE_EM_CORE :
+ if (!em_core_cancel_send_mail_thread(handle, NULL, &err)) {
+ EM_DEBUG_EXCEPTION("em_core_cancel_send_mail_thread failed [%d]", err);
+ goto FINISH_OFF;
+ }
+ break;
+
+ default:
+ EM_DEBUG_EXCEPTION("unknown account bind type...");
+ err = EMF_ERROR_INVALID_ACCOUNT;
+ goto FINISH_OFF;
+ }
+
+ if(!em_core_delete_transaction_info_by_mailId(mail_id))
+ EM_DEBUG_EXCEPTION("em_core_delete_transaction_info_by_mailId failed for mail_id[%d]", mail_id);
+
+ ret = true;
+
+FINISH_OFF:
+ if(err_code != NULL)
+ *err_code = err;
+
+#ifdef __FEATURE_PROGRESS_IN_OUTBOX__
+ if(!em_core_mail_free(&mail, 1, &err))
+ EM_DEBUG_EXCEPTION("em_core_mail_free Failed [%d ]", err);
+
+#endif
+ EM_DEBUG_FUNC_END();
+ return ret;
+}
+
+
+EXPORT_API int
+emf_clear_mail_data(int* err_code)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ int ret = false;
+ int error = EMF_ERROR_NONE;
+
+ if (emf_init(&error)) {
+ if (!em_storage_clear_mail_data(true, &error))
+ EM_DEBUG_EXCEPTION("em_storage_clear_mail_data failed [%d]", error);
+ }
+ else {
+ EM_DEBUG_EXCEPTION("emf_init failed [%d]", error);
+ if (err_code)
+ *err_code = error;
+ return false;
+ }
+
+ em_core_check_unread_mail();
+
+ ret = true;
+
+ if (!em_storage_create_table(EMF_CREATE_DB_NORMAL, &error))
+ EM_DEBUG_EXCEPTION("em_storage_create_table failed [%d]", error);
+
+ emf_close(&error);
+
+ if (err_code)
+ *err_code = error;
+ EM_DEBUG_FUNC_END();
+ return ret;
+}
+
+
+/* --------------------------------------------------------------------------------*/
diff --git a/email-engine/emf-global.c b/email-engine/emf-global.c
new file mode 100755
index 0000000..2555d09
--- /dev/null
+++ b/email-engine/emf-global.c
@@ -0,0 +1,38 @@
+/*
+* email-service
+*
+* Copyright (c) 2000 - 2011 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.
+*
+*/
+
+
+
+/******************************************************************************
+ * File: emf-global.c
+ * Desc: Mail Framework Global Variable Declaration
+ *
+ * Auth:
+ *
+ * History:
+ * 2006.09.02 : created
+ *****************************************************************************/
+#include "emflib.h"
+#include "c-client.h"
+#include "emf-global.h"
+#include "emf-types.h"
+
+
diff --git a/email-engine/emf-init.c b/email-engine/emf-init.c
new file mode 100755
index 0000000..eb6a1ba
--- /dev/null
+++ b/email-engine/emf-init.c
@@ -0,0 +1,333 @@
+/*
+* email-service
+*
+* Copyright (c) 2000 - 2011 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.
+*
+*/
+
+
+
+/******************************************************************************
+ * File: emf-init.c
+ * Desc: Mail Framework Initialization
+ *
+ * Auth:
+ *
+ * History:
+ * 2006.08.16 : created
+ *****************************************************************************/
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <glib.h>
+#include <glib-object.h>
+#include <vconf.h>
+#include <dbus/dbus.h>
+
+#include "emflib.h"
+#include "em-storage.h"
+#include "emf-global.h"
+#include "emf-dbglog.h"
+#include "emf-account.h"
+#include "emf-auto-poll.h"
+#include "em-core-utils.h"
+#include "em-core-mesg.h"
+#include "em-core-event.h"
+#include "em-core-account.h"
+#include "em-core-mailbox.h"
+#include "em-core-api.h"
+#include "em-core-global.h"
+#include "em-storage.h"
+#include "em-core-sound.h"
+
+
+/* added for Disabling the Pthread flag log */
+
+#ifdef API_TEST
+#include "emf-api-test.h"
+#endif
+
+#ifdef _CONTACT_SUBSCRIBE_CHANGE_
+#include <contacts-svc.h>
+#endif
+
+#include <dlfcn.h>
+#define ENGINE_PATH_EM_CORE "libemail-core.so"
+
+extern int g_client_count ;
+extern int g_client_run;
+
+/* static functions */
+static int _emf_load_engine(emf_engine_type_t type, int* err_code);
+static int _emf_unload_engine(emf_engine_type_t type, int* err_code);
+
+#ifdef _CONTACT_SUBSCRIBE_CHANGE_
+static void _emf_contact_change_cb(void *data)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ /* Run new thread and contact sync */
+ EM_DEBUG_LOG("Contact Changed.");
+ em_core_contact_sync_handler();
+}
+#endif
+
+EXPORT_API int emf_init(int* err_code)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ /* default variable */
+ int ret = false;
+ int err = EMF_ERROR_NONE;
+
+ if (g_client_count > 0) {
+ EM_DEBUG_LOG("Initialization was already done. increased counter=[%d]", g_client_count);
+ g_client_count++;
+ return true;
+ }
+ else
+ EM_DEBUG_LOG("************* start email service build time [%s %s] ************* ", __DATE__, __TIME__);
+
+#ifdef __FEATURE_USE_PTHREAD__
+ dbus_threads_init_default();
+#else /* __FEATURE_USE_PTHREAD__ */
+ if (!g_thread_supported())
+ g_thread_init(NULL);
+ dbus_g_thread_init ();
+#endif /* __FEATURE_USE_PTHREAD__ */
+
+ g_type_init();
+
+
+ em_storage_shm_file_init(SHM_FILE_FOR_DB_LOCK);
+
+#ifdef __FEATURE_USE_SHARED_MUTEX_FOR_GENERATING_MAIL_ID__
+ em_storage_shm_file_init(SHM_FILE_FOR_MAIL_ID_LOCK);
+#endif /* __FEATURE_USE_SHARED_MUTEX_FOR_GENERATING_MAIL_ID__ */
+
+ /* open database */
+ if (!em_storage_open(&err)) {
+ EM_DEBUG_EXCEPTION("em_storage_open failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ if (!em_storage_clean_save_status(EMF_MAIL_STATUS_SAVED, &err))
+ EM_DEBUG_EXCEPTION("em_storage_check_mail_status Failed [%d]", err );
+
+ g_client_count = 0;
+
+ if (!emf_init_account_reference()) {
+ EM_DEBUG_EXCEPTION("emf_init_account_reference fail...");
+ err = EMF_ERROR_DB_FAILURE;
+ goto FINISH_OFF;
+ }
+ EM_DEBUG_LOG("emf_init_account_reference over - g_client_count [%d]", g_client_count);
+
+ if (!_emf_load_engine(EMF_ENGINE_TYPE_EM_CORE, &err)) {
+ EM_DEBUG_EXCEPTION("_emf_load_engine failed [%d]", err);
+
+ /* err = EMF_ERROR_DB_FAILURE; */
+ goto FINISH_OFF;
+ }
+
+ em_core_check_unread_mail();
+
+#ifdef _CONTACT_SUBSCRIBE_CHANGE_
+ em_core_init_last_sync_time();
+ contacts_svc_subscribe_change(CTS_SUBSCRIBE_CONTACT_CHANGE, _emf_contact_change_cb, NULL);
+#endif
+
+ ret = true;
+
+FINISH_OFF:
+ if (ret == true)
+ g_client_count = 1;
+
+ EM_DEBUG_LOG(">>>>>>>>> ret value : %d g_client_count [%d]", ret, g_client_count);
+#ifdef API_TEST
+ emf_api_test_send_mail();
+#endif
+
+ if (err_code)
+ *err_code = err;
+
+ EM_DEBUG_FUNC_END();
+ return ret;
+}
+
+EXPORT_API int emf_close(int* err_code)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ /* default variable */
+ int ret = false;
+ int err = EMF_ERROR_NONE;
+
+ if (g_client_count > 1) {
+ EM_DEBUG_EXCEPTION("engine is still used by application. decreased counter=[%d]", g_client_count);
+
+ g_client_count--;
+
+ /* err = EMF_ERROR_CLOSE_FAILURE; */
+ goto FINISH_OFF;
+ }
+
+ if (!_emf_unload_engine(EMF_ENGINE_TYPE_EM_CORE, &err)) {
+ EM_DEBUG_EXCEPTION("_emf_unload_engine failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ /* free account reference list */
+ emf_free_account_reference();
+
+ /* close database */
+ if (!em_storage_close(&err)) {
+ EM_DEBUG_EXCEPTION("em_storage_close failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ g_client_count = 0;
+
+#ifdef _CONTACT_SUBSCRIBE_CHANGE_
+ contacts_svc_unsubscribe_change(CTS_SUBSCRIBE_CONTACT_CHANGE, _emf_contact_change_cb);
+#endif
+
+#ifdef __FEATURE_AUTO_POLLING__
+ emf_free_account_alarm_binder_list();
+#endif
+
+
+ ret = true;
+
+FINISH_OFF:
+ if (err_code)
+ *err_code = err;
+
+ return ret;
+}
+
+static int _emf_load_engine(emf_engine_type_t type, int* err_code)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ int err = EMF_ERROR_NONE;
+ int ret = false;
+
+ switch (type) {
+ case 1:
+ /* initialize mail core */
+ if (!em_core_init(&err))
+ goto FINISH_OFF;
+
+ if (em_core_event_loop_start(&err) < 0)
+ goto FINISH_OFF;
+
+ if (em_core_send_event_loop_start(&err) < 0)
+ goto FINISH_OFF;
+
+#ifdef __FEATURE_PARTIAL_BODY_DOWNLOAD__
+ if (em_core_partial_body_thread_loop_start(&err) < 0) {
+ EM_DEBUG_EXCEPTION("em_core_partial_body_thread_loop_start failed [%d]",err);
+ goto FINISH_OFF;
+ }
+#endif
+/*
+ if ( em_core_open_contact_db_library() == false )
+ goto FINISH_OFF;
+*/
+ if (em_core_alert_loop_start(&err) < 0)
+ goto FINISH_OFF;
+
+ break;
+
+ default:
+ return false;
+ }
+
+ ret = true;
+
+FINISH_OFF:
+ if (err_code)
+ *err_code = err;
+
+ return ret;
+}
+
+static int _emf_unload_engine(emf_engine_type_t type, int* err_code)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ int ret = false;
+ int err = EMF_ERROR_NONE;
+
+ switch (type) {
+ case EMF_ENGINE_TYPE_EM_CORE:
+ /* finish event loop */
+ em_core_event_loop_stop(&err);
+/*
+ em_core_close_contact_db_library();
+*/
+ ret = true;
+ break;
+
+ default:
+ err = EMF_ERROR_NOT_SUPPORTED;
+ break;
+ }
+
+ if (err_code != NULL)
+ *err_code = err;
+
+ return ret;
+}
+
+#ifdef __FEATURE_AUTO_POLLING__
+EXPORT_API int emf_auto_polling(int* err_code)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ /* default variable */
+ int ret = false, count = 0, i= 0;
+ int err = EMF_ERROR_NONE;
+ emf_mail_account_tbl_t* account_list = NULL;
+
+ /* get account list */
+ if (!em_storage_get_account_list(&count, &account_list, false, false, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_get_account_list failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ for (i = 0; i < count; i++) {
+ /* start auto poll */
+ /* start auto polling, if check_interval not zero */
+ if(account_list[i].check_interval > 0) {
+ if(!emf_add_polling_alarm( account_list[i].account_id,account_list[i].check_interval))
+ EM_DEBUG_EXCEPTION("emf_add_polling_alarm[ NOTI_ACCOUNT_ADD] : start auto poll Failed >>> ");
+ }
+ }
+
+ ret = true;
+FINISH_OFF:
+ if (account_list)
+ em_storage_free_account(&account_list, count, NULL);
+
+ if (err_code != NULL)
+ *err_code = err;
+
+ return ret;
+}
+#endif
+
diff --git a/email-engine/emf-mail.c b/email-engine/emf-mail.c
new file mode 100755
index 0000000..34a8f65
--- /dev/null
+++ b/email-engine/emf-mail.c
@@ -0,0 +1,2124 @@
+/*
+* email-service
+*
+* Copyright (c) 2000 - 2011 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.
+*
+*/
+
+
+
+/******************************************************************************
+ * File: emf-mail.c
+ * Desc: Mail Framework Mail Operation
+ *
+ * Auth:
+ *
+ * History:
+ * 2006.08.16 : created
+ *****************************************************************************/
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <glib.h>
+#include <unistd.h>
+#include <malloc.h>
+
+#include "emflib.h"
+#include "emf-global.h"
+#include "em-core-event.h"
+#include "emf-account.h"
+#include "emf-dbglog.h"
+#include "em-storage.h"
+#include "em-core-account.h"
+#include "em-core-mesg.h"
+#include "em-core-mailbox.h"
+#include "em-core-utils.h"
+#include "em-core-smtp.h"
+#include "em-core-timer.h"
+
+#ifdef __LOCAL_ACTIVITY__
+extern int g_local_activity_run;
+extern int g_save_local_activity_run;
+#endif
+static int emf_mail_check_mail_id(int mail_id, int* err_code);
+
+EXPORT_API int emf_mail_send(emf_mailbox_t* mailbox, int mail_id, emf_option_t* sending_option, unsigned* handle, int* err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("mailbox[%p], mail_id[%d], sending_option[%p], handle[%p], err_code[%p]", mailbox, mail_id, sending_option, handle, err_code);
+
+ int ret = false, err = EMF_ERROR_NONE, err_2 = EMF_ERROR_NONE;
+ int result_handle = 0, account_id = 0;
+ emf_mailbox_t dest_mbox;
+ emf_option_t* option = NULL;
+ emf_event_t event_data;
+ char* mailbox_name = NULL;
+
+ if (!mailbox || !mailbox->name || mailbox->account_id <= 0) {
+ if (mailbox != NULL)
+ EM_DEBUG_EXCEPTION(" mailbox->name[%s], mailbox->account_id[%d]", mailbox->name, mailbox->account_id);
+ if (err_code)
+ *err_code = EMF_ERROR_INVALID_MAILBOX;
+ return false;
+ }
+
+ account_id = mailbox->account_id;
+
+ if (sending_option != NULL) {
+ if (!(option = (emf_option_t*)em_core_malloc(sizeof(emf_option_t)))) {
+ EM_DEBUG_EXCEPTION("em_core_malloc for sending_option failed...");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+ memcpy(option, sending_option, sizeof(emf_option_t));
+ option->display_name_from = EM_SAFE_STRDUP(sending_option->display_name_from);
+ }
+
+ emf_account_t* ref_account = emf_get_account_reference(account_id);
+
+ if (!ref_account) {
+ EM_DEBUG_EXCEPTION("emf_get_account_reference failed [%d]", account_id);
+ err = EMF_ERROR_INVALID_ACCOUNT;
+ goto FINISH_OFF;
+ }
+
+#ifdef __FEATURE_MOVE_TO_OUTBOX_FIRST__
+ if (!em_storage_get_mailboxname_by_mailbox_type(account_id,EMF_MAILBOX_TYPE_OUTBOX,&mailbox_name, false, &err)) {
+ EM_DEBUG_EXCEPTION(" em_storage_get_mailboxname_by_mailbox_type failed [%d]", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+ if (strcmp(mailbox->name, mailbox_name)) {
+ dest_mbox.name = mailbox_name;
+ dest_mbox.account_id = account_id;
+
+ /* mail is moved to 'OUTBOX' first of all. */
+ if (!em_core_mail_move(&mail_id, 1, dest_mbox.name, EMF_MOVED_AFTER_SENDING, 0, &err)) {
+ EM_DEBUG_EXCEPTION("em_core_mail_move falied [%d]", err);
+ goto FINISH_OFF;
+ }
+ }
+#endif /* __FEATURE_MOVE_TO_OUTBOX_FIRST__ */
+
+ if(!em_storage_notify_network_event(NOTI_SEND_START, account_id, NULL, mail_id, 0))
+ EM_DEBUG_EXCEPTION(" em_storage_notify_network_event [ NOTI_SEND_START] Failed >>>> ");
+
+ /* set EMF_MAIL_STATUS_SEND_WAIT status */
+
+ if(!em_storage_set_field_of_mails_with_integer_value(account_id, &mail_id, 1, "save_status", EMF_MAIL_STATUS_SEND_WAIT, true, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_set_field_of_mails_with_integer_value [%d]",err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+
+ switch (ref_account->account_bind_type) {
+ case EMF_BIND_TYPE_EM_CORE:
+ memset(&event_data, 0x00, sizeof(emf_event_t));
+ event_data.type = EMF_EVENT_SEND_MAIL;
+ event_data.account_id = account_id;
+ event_data.event_param_data_1 = (char*)option;
+ event_data.event_param_data_3 = EM_SAFE_STRDUP(mailbox->name);
+ event_data.event_param_data_4 = mail_id;
+
+ if (!em_core_insert_send_event(&event_data, &result_handle, &err)) {
+ EM_DEBUG_EXCEPTION(" em_core_insert_event failed [%d]", err);
+ goto FINISH_OFF;
+ }
+#ifdef __LOCAL_ACTIVITY__
+ EM_DEBUG_LOG("Setting g_save_local_activity_run ");
+ g_save_local_activity_run = 1;
+#endif
+ break;
+
+ default:
+ EM_DEBUG_EXCEPTION("unsupported account binding type...");
+ err = EMF_ERROR_NOT_SUPPORTED;
+ goto FINISH_OFF;
+ }
+
+ if ( handle )
+ *handle = result_handle;
+
+ ret = true;
+
+FINISH_OFF:
+ if (ret == false) {
+ EM_DEBUG_EXCEPTION("emf_mail_send failed [%d]", err);
+
+ if(!em_storage_set_field_of_mails_with_integer_value(account_id, &mail_id, 1, "save_status", EMF_MAIL_STATUS_SAVED, true, &err))
+ EM_DEBUG_EXCEPTION("em_storage_set_field_of_mails_with_integer_value [%d]",err);
+
+ EM_SAFE_FREE(event_data.event_param_data_3);
+
+ if(option != NULL) {
+ EM_SAFE_FREE(option->display_name_from);
+ EM_SAFE_FREE(option);
+ }
+ }
+
+ if(!em_core_add_transaction_info(mail_id , result_handle , &err_2))
+ EM_DEBUG_EXCEPTION("em_core_add_transaction_info failed [%d]", err_2);
+
+ EM_SAFE_FREE(mailbox_name);
+
+ if (err_code != NULL)
+ *err_code = err;
+
+ EM_DEBUG_FUNC_END();
+ return ret;
+}
+
+EXPORT_API int emf_mail_send_saved(int account_id, emf_option_t* sending_option, unsigned* handle, int* err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("account_id[%d], sending_option[%p], handle[%p], err_code[%p]", account_id, sending_option, handle, err_code);
+
+ /* default variable */
+ int ret = false;
+ int err = EMF_ERROR_NONE;
+
+ emf_option_t* option = NULL;
+ emf_event_t event_data;
+ char *mailbox_name = NULL;
+
+ memset(&event_data, 0x00, sizeof(emf_event_t));
+
+ if (account_id <= 0) {
+ EM_DEBUG_EXCEPTION("account_id = %d", account_id);
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ if (sending_option) {
+ option = (emf_option_t*)em_core_malloc(sizeof(emf_option_t));
+ if (!option) {
+ EM_DEBUG_EXCEPTION("em_core_malloc failed...");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ memcpy(option, sending_option, sizeof(emf_option_t));
+ }
+
+ emf_account_t* ref_account = emf_get_account_reference(account_id);
+
+ if (!ref_account) {
+ EM_DEBUG_EXCEPTION("emf_get_account_reference failed [%d]", account_id);
+ err = EMF_ERROR_INVALID_ACCOUNT;
+ goto FINISH_OFF;
+ }
+
+
+ switch (ref_account->account_bind_type) {
+ case EMF_BIND_TYPE_EM_CORE:
+ event_data.type = EMF_EVENT_SEND_MAIL_SAVED;
+
+ if (!em_storage_get_mailboxname_by_mailbox_type(account_id,EMF_MAILBOX_TYPE_OUTBOX,&mailbox_name, false, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_get_mailboxname_by_mailbox_type failed [%d]", err);
+
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+ event_data.event_param_data_3 = EM_SAFE_STRDUP(mailbox_name);
+ event_data.account_id = account_id;
+ event_data.event_param_data_1 = (char*)option;
+
+ if (!em_core_insert_event(&event_data, (int*)handle, &err)) {
+ EM_DEBUG_EXCEPTION("em_core_insert_event failed [%d]", err);
+ goto FINISH_OFF;
+ }
+ break;
+
+ default :
+ EM_DEBUG_EXCEPTION("unknown account bind type...");
+ err = EMF_ERROR_INVALID_ACCOUNT;
+ goto FINISH_OFF;
+ }
+
+ ret = true;
+
+FINISH_OFF:
+ if (ret == false) {
+ EM_SAFE_FREE(event_data.event_param_data_3);
+ EM_SAFE_FREE(option);
+ }
+
+ EM_SAFE_FREE(mailbox_name);
+
+ if (err_code)
+ *err_code = err;
+
+ EM_DEBUG_FUNC_END();
+ return ret;
+}
+
+EXPORT_API int emf_mail_send_report(emf_mail_t* mail, unsigned* handle, int* err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("mail[%p], handle[%p], err_code[%p]", mail, handle, err_code);
+
+ /* default variable */
+ int ret = false;
+ int err = EMF_ERROR_NONE;
+
+ emf_mail_t* tmail = NULL;
+ char* mailbox = NULL;
+ char *mailbox_name = NULL;
+
+ if (!mail || !mail->info || mail->info->account_id <= 0 || !mail->head ||
+ !mail->head->from || !mail->head->mid) {
+ if (mail != NULL) {
+ if (mail->info != NULL) {
+ if (mail->head != NULL)
+ EM_DEBUG_LOG("mail->info->account_id[%d], mail->head->from[%p], mail->head->mid[%p]", mail->info->account_id, mail->head->from, mail->head->mid);
+ else
+ EM_DEBUG_LOG("mail->info->account_id[%d], mail->head[%p]", mail->info->account_id, mail->head);
+ }
+ else {
+ if (mail->head != NULL)
+ EM_DEBUG_LOG("mail->info[%p], mail->head->from[%p], mail->head->mid[%p]", mail->info, mail->head->from, mail->head->mid);
+ else
+ EM_DEBUG_LOG("mail->info[%p], mail->head[%p]", mail->info, mail->head);
+ }
+ }
+ else
+ EM_DEBUG_LOG("mail[%p]", mail);
+
+ err = EMF_ERROR_INVALID_MAIL; /* EMF_ERROR_INVALID_PARAM */
+ goto FINISH_OFF;
+ }
+
+ emf_account_t* ref_account = emf_get_account_reference(mail->info->account_id);
+ if (!ref_account) {
+ EM_DEBUG_EXCEPTION("emf_get_account_reference failed [%d]", mail->info->account_id);
+ err = EMF_ERROR_INVALID_ACCOUNT;
+ goto FINISH_OFF;
+ }
+
+ switch (ref_account->account_bind_type) {
+ case EMF_BIND_TYPE_EM_CORE:
+ tmail = em_core_malloc(sizeof(emf_mail_t));
+ tmail->head = em_core_malloc(sizeof(emf_mail_head_t));
+
+ if (!tmail || !tmail->head) {
+ EM_DEBUG_EXCEPTION("mailloc failed...");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ memset(tmail, 0x00, sizeof(emf_mail_t));
+ memset(tmail->head, 0x00, sizeof(emf_mail_head_t));
+
+ tmail->head->to = EM_SAFE_STRDUP(mail->head->from);
+ tmail->head->mid = EM_SAFE_STRDUP(mail->head->mid);
+
+ if (mail->head->subject) {
+ tmail->head->subject = malloc(strlen(mail->head->subject) + 7);
+ if (!(tmail->head->subject)) {
+ EM_DEBUG_EXCEPTION("mailloc failed...");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ SNPRINTF(tmail->head->subject, strlen(mail->head->subject) + 7 - 1, "Read: %s", mail->head->subject);
+ }
+
+ tmail->info = em_core_malloc(sizeof(emf_mail_info_t));
+ if (!(tmail->info)) {
+ EM_DEBUG_EXCEPTION("mailloc failed...");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ memset(tmail->info, 0x00, sizeof(emf_mail_info_t));
+
+ tmail->info->account_id = mail->info->account_id;
+ tmail->info->flags.draft = 1;
+ tmail->info->extra_flags.status = (unsigned char)EMF_MAIL_STATUS_SENDING;/* 4; */
+ tmail->info->extra_flags.report = (unsigned char)EMF_MAIL_REPORT_MDN;
+
+ if (!em_storage_get_mailboxname_by_mailbox_type(mail->info->account_id,EMF_MAILBOX_TYPE_OUTBOX,&mailbox_name, false, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_get_mailboxname_by_mailbox_type failed [%d]", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+ mailbox = EM_SAFE_STRDUP(mailbox_name);
+
+
+ if (!em_core_mail_save(tmail->info->account_id, mailbox, tmail, NULL, 1, &err)) {
+ EM_DEBUG_EXCEPTION("em_core_mail_save failed [%d]", err);
+ goto FINISH_OFF;
+ }
+ else {
+ emf_event_t event_data = { 0 };
+ event_data.type = EMF_EVENT_SEND_MAIL;
+ event_data.account_id = tmail->info->account_id;
+ event_data.event_param_data_4 = tmail->info->uid;
+ event_data.event_param_data_3 = mailbox;
+ event_data.event_param_data_1 = NULL;
+
+ if (!em_core_insert_event(&event_data,(int*) handle, &err)) {
+ EM_DEBUG_EXCEPTION("em_core_insert_event failed [%d]", err);
+ goto FINISH_OFF;
+ }
+#ifdef __LOCAL_ACTIVITY__
+ EM_DEBUG_LOG("Setting g_save_local_activity_run ");
+ g_save_local_activity_run = 1;
+#endif
+
+ }
+ break;
+
+ default:
+ EM_DEBUG_EXCEPTION("unknown account bind type...");
+ err = EMF_ERROR_INVALID_ACCOUNT;
+ goto FINISH_OFF;
+
+ }
+
+ ret = true;
+
+FINISH_OFF:
+ if (tmail != NULL)
+ em_core_mail_free(&tmail, 1, NULL);
+ if (ret == false)
+ EM_SAFE_FREE(mailbox);
+
+ EM_SAFE_FREE(mailbox_name);
+
+ if (err_code)
+ *err_code = err;
+ EM_DEBUG_FUNC_END();
+ return ret;
+}
+
+EXPORT_API int emf_add_mail(emf_mail_data_t *input_mail_data, emf_attachment_data_t *input_attachment_data_list, int input_attachment_count, emf_meeting_request_t *input_meeting_request, int input_sync_server)
+{
+ EM_DEBUG_FUNC_BEGIN("input_mail_data[%p], input_attachment_data_list[%p], input_attachment_count [%d], input_meeting_req [%p], input_sync_server[%d]", input_mail_data, input_attachment_data_list, input_attachment_count, input_meeting_request, input_sync_server);
+
+ int err = EMF_ERROR_NONE;
+ int handle = 0;
+ emf_event_t event_data = { 0 };
+
+ if (!input_mail_data || input_mail_data->account_id <= 0 ||
+ (input_mail_data->report_status == EMF_MAIL_REPORT_MDN && !input_mail_data->full_address_to)) {
+ EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ emf_account_t* ref_account = emf_get_account_reference(input_mail_data->account_id);
+ if (!ref_account) {
+ EM_DEBUG_LOG(" emf_get_account_reference failed [%d]", input_mail_data->account_id);
+ err = EMF_ERROR_INVALID_ACCOUNT;
+ goto FINISH_OFF;
+ }
+
+ switch (ref_account->account_bind_type) {
+ case EMF_BIND_TYPE_EM_CORE :
+ if ((err = em_core_add_mail(input_mail_data, input_attachment_data_list, input_attachment_count, input_meeting_request, input_sync_server)) != EMF_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("em_core_add_mail failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+#ifdef __FEATURE_SYNC_CLIENT_TO_SERVER__
+ if ( input_sync_server ) {
+ event_data.type = EMF_EVENT_SAVE_MAIL;
+ event_data.account_id = input_mail_data->account_id;
+ event_data.event_param_data_4 = input_mail_data->mail_id;
+
+ if (!em_core_insert_send_event(&event_data, &handle, &err)) {
+ EM_DEBUG_EXCEPTION("em_core_insert_send_event failed [%d]", err);
+ goto FINISH_OFF;
+ }
+ }
+#endif
+ break;
+
+ default:
+ EM_DEBUG_EXCEPTION("unknown account bind type...");
+ err = EMF_ERROR_INVALID_ACCOUNT;
+ goto FINISH_OFF;
+ }
+FINISH_OFF:
+ EM_DEBUG_FUNC_END("err [%d]", err);
+ return err;
+}
+
+EXPORT_API int emf_mail_save_to_mailbox(emf_mail_t* mail, emf_mailbox_t* mailbox, emf_meeting_request_t *meeting_req, int from_composer, int* err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("mail[%p], mailbox[%p], err_code[%p]", mail, mailbox, err_code);
+
+ /* default variable */
+ int ret = false;
+ int err = EMF_ERROR_NONE;
+ struct stat st_buf;
+ emf_event_t event_data;
+ int handle;
+
+ if (!mail || !mail->head || !mail->body || !mailbox || mailbox->account_id <= 0 ||
+ (mail->info && mail->info->extra_flags.report == EMF_MAIL_REPORT_MDN && !mail->head->to)) {
+ EM_DEBUG_EXCEPTION("mail[%p], head[%p], body[%p], mailbox[%p], account_id[%d], info[%p], report[%d], to[%p]",
+ mail, mail ? mail->head : 0, mail ? mail->body : 0, mailbox, mailbox ? mailbox->account_id : 0,
+ mail ? mail->info : 0, mail ? (mail->info?mail->info->extra_flags.report : 0) : 0, mail ? (mail->head ? mail->head->to : 0) : 0);
+
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+#ifdef __LOCAL_ACTIVITY__
+ char *mailbox_name = NULL;
+ if( mailbox->name ) {
+ mailbox_name = EM_SAFE_STRDUP(mailbox->name) ;
+ }
+
+#endif
+
+ if(from_composer) {
+ if (mail->body->plain) {
+ if (stat(mail->body->plain, &st_buf) < 0) {
+ EM_DEBUG_EXCEPTION("mail->body->plain, stat(\"%s\") failed...", mail->body->plain);
+ err = EMF_ERROR_INVALID_MAIL;
+ goto FINISH_OFF;
+ }
+ }
+
+ if (mail->body->html) {
+ if (stat(mail->body->html, &st_buf) < 0) {
+ EM_DEBUG_EXCEPTION("mail->body->html, stat(\"%s\") failed...", mail->body->html);
+
+ err = EMF_ERROR_INVALID_MAIL;
+ goto FINISH_OFF;
+ }
+
+ }
+
+ if (mail->body->attachment) {
+ emf_attachment_info_t* p = mail->body->attachment;
+ while (p) {
+ if(p->downloaded) {
+ if (!p->savename || stat(p->savename, &st_buf) < 0) {
+ EM_DEBUG_EXCEPTION("stat(\"%s\") failed...", p->savename);
+ err = EMF_ERROR_INVALID_ATTACHMENT;
+ goto FINISH_OFF;
+ }
+ }
+ p = p->next;
+ }
+ }
+ }
+
+ emf_account_t* ref_account = emf_get_account_reference(mailbox->account_id);
+ if (!ref_account) {
+ EM_DEBUG_LOG(" emf_get_account_reference failed [%d]", mailbox->account_id);
+ err = EMF_ERROR_INVALID_ACCOUNT; /* EMF_ERROR_ACCOUNT_NOT_FOUND; */
+ goto FINISH_OFF;
+ }
+
+ switch (ref_account->account_bind_type) {
+ case EMF_BIND_TYPE_EM_CORE :
+ if (!em_core_mail_save(mailbox->account_id, mailbox->name, mail, meeting_req, from_composer, &err)) {
+ EM_DEBUG_EXCEPTION("em_core_mail_save failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+
+#ifdef __FEATURE_SYNC_CLIENT_TO_SERVER__ /* Disable temporarily */
+/* if ( from_composer && ref_account->receiving_server_type == EMF_SERVER_TYPE_IMAP4 ) */
+ if ( from_composer && !mailbox->local) /* Not to be considered for Outbox mails which is local mailbox */ {
+ memset(&event_data, 0x00, sizeof(emf_event_t));
+
+ EM_DEBUG_LOG(">>>>> Save to mailbox on a server: MAIL ID [ %d ] >>>>", mail->info->uid);
+
+ event_data.type = EMF_EVENT_SAVE_MAIL;
+ event_data.account_id = mailbox->account_id;
+ event_data.event_param_data_4 = mail->info->uid;
+
+#ifdef __LOCAL_ACTIVITY__
+ emf_activity_tbl_t new_activity;
+ memset( &new_activity, 0x00, sizeof(emf_activity_tbl_t));
+ new_activity.activity_type = ACTIVITY_SAVEMAIL;
+ new_activity.account_id = event_data.account_id;
+ new_activity.mail_id = event_data.event_param_data_4;
+
+ if( mailbox_name ) {
+ new_activity.dest_mbox = mailbox_name ;
+ }
+
+ if (false == em_core_get_next_activity_id(&new_activity.activity_id,&err)) {
+ EM_DEBUG_EXCEPTION(" em_core_get_next_activity_id Failed - %d \n", err);
+ }
+
+ if (!em_core_activity_add(&new_activity, &err)) {
+ EM_DEBUG_EXCEPTION(" em_core_activity_add Failed - %d \n", err);
+ }
+#endif /* __LOCAL_ACTIVITY__ */
+
+ if (!em_core_insert_send_event(&event_data, &handle, &err)) {
+ EM_DEBUG_EXCEPTION("em_core_insert_send_event failed [%d]", err);
+ err = EMF_ERROR_NONE;
+ ret = true;
+ goto FINISH_OFF;
+ }
+#ifdef __LOCAL_ACTIVITY__
+ EM_DEBUG_LOG("Setting g_save_local_activity_run ");
+ g_save_local_activity_run = 1;
+#endif
+ }
+#endif
+ break;
+
+ default:
+ EM_DEBUG_EXCEPTION("unknown account bind type...");
+ err = EMF_ERROR_INVALID_ACCOUNT;
+ goto FINISH_OFF;
+ }/* if with_server */
+
+ ret = true;
+
+FINISH_OFF:
+
+#ifdef __LOCAL_ACTIVITY__
+ EM_SAFE_FREE(mailbox_name);
+#endif
+
+ if (err_code)
+ *err_code = err;
+ EM_DEBUG_FUNC_END();
+ return ret;
+}
+
+EXPORT_API int emf_mail_add_meeting_request(int account_id, char *mailbox_name, emf_meeting_request_t *meeting_req, int* err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("account_id[%d], mailbox_name[%s], meeting_req[%p], err_code[%p]", account_id, mailbox_name, meeting_req, err_code);
+
+ /* default variable */
+ int ret = false;
+ int err = EMF_ERROR_NONE;
+
+ if ( account_id <= 0 || !meeting_req || meeting_req->mail_id <= 0 ) {
+ if(meeting_req)
+ EM_DEBUG_EXCEPTION("mail_id[%d]", meeting_req->mail_id);
+
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ if (!em_core_mail_add_meeting_request(account_id, mailbox_name, meeting_req, &err)) {
+ EM_DEBUG_EXCEPTION(" em_core_mail_save_meeting_request failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ ret = true;
+
+FINISH_OFF:
+ if (err_code)
+ *err_code = err;
+ EM_DEBUG_FUNC_END();
+ return ret;
+}
+
+/* unused API */
+int emf_mail_get_size(emf_mailbox_t* mailbox, int mail_id, int* size, int* err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("mailbox[%p], mail_id[%d], size[%p], err_code[%p]", mailbox, mail_id, size, err_code);
+
+ /* default variable */
+ int ret = false;
+ int err = EMF_ERROR_NONE;
+
+ if (!size) {
+ EM_DEBUG_EXCEPTION("mailbox[%p], mail_id[%d], size[%p]", mailbox, mail_id, size);
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ if (!emf_mail_check_mail_id(mail_id, &err)) {
+ EM_DEBUG_EXCEPTION("emf_mail_check_mail_id failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+
+ if (!em_core_mail_get_size(/*mailbox,*/ mail_id, size, &err)) {
+ EM_DEBUG_EXCEPTION("em_core_mail_get_size failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ ret = true;
+
+FINISH_OFF:
+ if (err_code)
+ *err_code = err;
+ EM_DEBUG_FUNC_END();
+ return ret;
+}
+
+int emf_mail_get_mail(emf_mailbox_t* mailbox, int mail_id, emf_mail_t** mail, int* err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("mailbox[%p], mail_id[%d], mail[%p], err_code[%p]", mailbox, mail_id, mail, err_code);
+
+ /* default variable */
+ int ret = false;
+ int err = EMF_ERROR_NONE;
+
+ if (!mail) {
+ EM_DEBUG_EXCEPTION("mailbox[%p], mail_id[%d], mail[%p]", mailbox, mail_id, mail);
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ if (!emf_mail_check_mail_id(mail_id, &err)) {
+ EM_DEBUG_EXCEPTION("emf_mail_check_mail_id failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ if (!em_core_mail_get_mail(/*mailbox,*/ mail_id, mail, &err) || !mail) {
+ EM_DEBUG_EXCEPTION("em_core_mail_get_mail failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ ret = true;
+
+FINISH_OFF:
+ if (err_code)
+ *err_code = err;
+ EM_DEBUG_FUNC_END();
+ return ret;
+}
+
+EXPORT_API int emf_mail_get_info(emf_mailbox_t* mailbox, int mail_id, emf_mail_info_t** info, int* err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("mailbox[%p], mail_id[%d], info[%p], err_code[%p]", mailbox, mail_id, info, err_code);
+
+ /* default variable */
+ int ret = false;
+ int err = EMF_ERROR_NONE;
+
+ if (!info) {
+ EM_DEBUG_EXCEPTION("mailbox[%p], mail_id[%d], info[%p]", mailbox, mail_id, info);
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ if (!emf_mail_check_mail_id(mail_id, &err)) {
+ EM_DEBUG_EXCEPTION("emf_mail_check_mail_id failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ if (!em_core_mail_get_info(mail_id, info, &err) || !info) {
+ EM_DEBUG_EXCEPTION("em_core_mail_get_info failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ ret = true;
+
+FINISH_OFF:
+ if (err_code)
+ *err_code = err;
+ EM_DEBUG_FUNC_END();
+ return ret;
+}
+
+int emf_mail_get_head(emf_mailbox_t* mailbox, int mail_id, emf_mail_head_t** head, int* err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("mailbox[%p], mail_id[%d], head[%p], err_code[%p]", mailbox, mail_id, head, err_code);
+
+ /* default variable */
+ int ret = false;
+ int err = EMF_ERROR_NONE;
+
+ if (!head) {
+ EM_DEBUG_EXCEPTION("mailbox[%p], mail_id[%d], head[%p]", mailbox, mail_id, head);
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ if (!emf_mail_check_mail_id(mail_id, &err)) {
+ EM_DEBUG_EXCEPTION("emf_mail_check_mail_id failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ if (!em_core_mail_get_header(/*mailbox,*/ mail_id, head, &err) || !head) {
+ EM_DEBUG_EXCEPTION("em_core_mail_get_header failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ ret = true;
+
+FINISH_OFF:
+ if (err_code)
+ *err_code = err;
+
+ return ret;
+}
+
+int emf_mail_get_body(emf_mailbox_t* mailbox, int mail_id, emf_mail_body_t** body, int* err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("mailbox[%p], mail_id[%d], body[%p], err_code[%p]", mailbox, mail_id, body, err_code);
+
+ /* default variable */
+ int ret = false;
+ int err = EMF_ERROR_NONE;
+
+ if (!body) {
+ EM_DEBUG_EXCEPTION("mailbox[%p], mail_id[%d], body[%p]", mailbox, mail_id, body);
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ if (!emf_mail_check_mail_id(mail_id, &err)) {
+ EM_DEBUG_EXCEPTION("emf_mail_check_mail_id failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ if (!em_core_mail_get_body(/*mailbox,*/ mail_id, body, &err) || !body) {
+ EM_DEBUG_EXCEPTION("em_core_mail_get_body failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ ret = true;
+
+FINISH_OFF:
+ if (err_code)
+ *err_code = err;
+ EM_DEBUG_FUNC_END();
+ return ret;
+}
+
+EXPORT_API int emf_mail_download_body(emf_mailbox_t* mailbox, int mail_id, int verbose, int with_attachment, unsigned* handle, int* err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("mailbox[%p], mail_id[%d], verbose[%d], with_attachment[%d], handle[%p], err_code[%p]", mailbox, mail_id, verbose, with_attachment, handle, err_code);
+
+ /* default variable */
+ int ret = false;
+ int err = EMF_ERROR_NONE;
+/* mpNewMail_StopAlertSound(); */
+
+ if (!emf_mail_check_mail_id(mail_id, &err)) {
+ EM_DEBUG_EXCEPTION("emf_mail_check_mail_id failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ emf_event_t event_data;
+
+ memset(&event_data, 0x00, sizeof(emf_event_t));
+
+ event_data.type = EMF_EVENT_DOWNLOAD_BODY;
+ event_data.event_param_data_1 = NULL;
+ event_data.event_param_data_4 = mail_id;
+ event_data.account_id = mailbox->account_id;
+ event_data.event_param_data_3 = GINT_TO_POINTER(verbose << 1 | with_attachment);
+
+ if (!em_core_insert_event(&event_data, (int*)handle, &err)) {
+ EM_DEBUG_EXCEPTION("em_core_insert_event failed [%d]", err);
+ err = EMF_ERROR_DB_FAILURE;
+ goto FINISH_OFF;
+ }
+#ifdef __LOCAL_ACTIVITY__
+ EM_DEBUG_LOG("Setting g_local_activity_run ");
+ g_local_activity_run = 1;
+#endif
+ ret = true;
+
+FINISH_OFF:
+ if (err_code)
+ *err_code = err;
+ EM_DEBUG_FUNC_END();
+ return ret;
+}
+
+int emf_mail_get_attachment(emf_mailbox_t* mailbox, int mail_id, char* attachment_id, emf_attachment_info_t** attachment, int* err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("mailbox[%p], mail_id[%d], attachment_id[%s], attachment[%p], err_code[%p]", mailbox, mail_id, attachment_id, attachment, err_code);
+
+ /* default variable */
+ int ret = false;
+ int err = EMF_ERROR_NONE;
+
+ if (!attachment_id || !attachment) {
+ EM_DEBUG_EXCEPTION("mailbox[%p], mail_id[%d], attachment_id[%p], attachment[%p]\n", mailbox, mail_id, attachment_id, attachment);
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ if (!emf_mail_check_mail_id(mail_id, &err)) {
+ EM_DEBUG_EXCEPTION("emf_mail_check_mail_id failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ if (!em_core_mail_get_attachment(/*mailbox,*/ mail_id, attachment_id, attachment, &err) || !attachment) {
+ EM_DEBUG_EXCEPTION("em_core_mail_get_attachment failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ ret = true;
+
+FINISH_OFF:
+ if (err_code)
+ *err_code = err;
+ EM_DEBUG_FUNC_END();
+ return ret;
+}
+
+int emf_mail_add_attachment(emf_mailbox_t* mailbox, int mail_id, emf_attachment_info_t* attachment, int* err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("mailbox[%p], mail_id[%d], attachment[%p], err_code[%p]", mailbox, mail_id, attachment, err_code);
+
+ /* default variable */
+ int ret = false;
+ int err = EMF_ERROR_NONE;
+
+ if (!attachment) {
+ EM_DEBUG_EXCEPTION(" mailbox[%p], mail_id[%d], attachment[%p]", mailbox, mail_id, attachment);
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ if (!emf_mail_check_mail_id(mail_id, &err)) {
+ EM_DEBUG_EXCEPTION(" emf_mail_check_mail_id failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ if (!em_core_mail_add_attachment(/*mailbox,*/ mail_id, attachment, &err)) {
+ EM_DEBUG_EXCEPTION(" em_core_mail_add_attachment failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ ret = true;
+
+FINISH_OFF:
+ if (err_code)
+ *err_code = err;
+ EM_DEBUG_FUNC_END();
+ return ret;
+}
+
+int emf_mail_delete_attachment(emf_mailbox_t* mailbox, int mail_id, char* attachment_id, int* err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("mailbox[%p], mail_id[%d], attachment_id[%s], err_code[%p]", mailbox, mail_id, attachment_id, err_code);
+
+ /* default variable */
+ int ret = false;
+ int err = EMF_ERROR_NONE;
+
+ if (!attachment_id) {
+ EM_DEBUG_EXCEPTION(" mailbox[%p], mail_id[%d], attachment_id[%p]", mailbox, mail_id, attachment_id);
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ if (!emf_mail_check_mail_id(mail_id, &err)) {
+ EM_DEBUG_EXCEPTION(" emf_mail_check_mail_id failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ if (!em_core_mail_delete_attachment(mail_id, attachment_id, &err)) {
+ EM_DEBUG_EXCEPTION(" em_core_mail_delete_attachment failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ ret = true;
+
+FINISH_OFF:
+ if (err_code)
+ *err_code = err;
+ EM_DEBUG_FUNC_END();
+ return ret;
+}
+
+EXPORT_API int emf_mail_download_attachment(emf_mailbox_t* mailbox, int mail_id, char* attachment, unsigned* handle, int* err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("mailbox[%p], mail_id[%d], attachment[%p], handle[%p], err_code[%p]", mailbox, mail_id, attachment, handle, err_code);
+
+ int ret = false;
+ int err = EMF_ERROR_NONE;
+
+ if (!attachment) {
+ EM_DEBUG_EXCEPTION("attachment[%p] is invalid", attachment);
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ if (!emf_mail_check_mail_id(mail_id, &err)) {
+ EM_DEBUG_EXCEPTION("emf_mail_check_mail_id failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ emf_event_t event_data;
+
+ memset(&event_data, 0x00, sizeof(emf_event_t));
+
+ event_data.type = EMF_EVENT_DOWNLOAD_ATTACHMENT;
+ event_data.event_param_data_1 = NULL;
+ event_data.event_param_data_4 = mail_id;
+ event_data.account_id = mailbox->account_id;
+ event_data.event_param_data_3 = EM_SAFE_STRDUP(attachment);
+
+ if (!em_core_insert_event(&event_data, (int*)handle, &err)) {
+ EM_DEBUG_EXCEPTION("em_core_insert_event failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+#ifdef __LOCAL_ACTIVITY__
+ EM_DEBUG_LOG("Setting g_local_activity_run ");
+ g_local_activity_run = 1;
+#endif
+
+ ret = true;
+
+FINISH_OFF:
+ if (err_code)
+ *err_code = err;
+
+ return ret;
+}
+
+int emf_mail_info_free(emf_mail_info_t** mail_info_list, int count, int* err_code)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ return em_core_mail_info_free(mail_info_list, count, err_code);
+}
+
+int emf_mail_head_free(emf_mail_head_t** mail_head_list, int count, int* err_code)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ return em_core_mail_head_free(mail_head_list, count, err_code);
+}
+
+int emf_mail_body_free(emf_mail_body_t** mail_body_list, int count, int* err_code)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ return em_core_mail_body_free(mail_body_list, count, err_code);
+}
+
+int emf_mail_free(emf_mail_t** mail_list, int count, int* err_code)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ return em_core_mail_free(mail_list, count, err_code);
+}
+
+EXPORT_API int emf_mail_attachment_info_free(emf_attachment_info_t** atch_info, int* err_code)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ return em_core_mail_attachment_info_free(atch_info, err_code);
+}
+
+void* thread_func_to_delete_mail(void *thread_argument)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int *mail_id_list = NULL, mail_id_count, account_id, err;
+ unsigned handle = 0;
+ emf_event_t *event_data = (emf_event_t*)thread_argument;
+
+ account_id = event_data->account_id;
+ mail_id_list = (int*)event_data->event_param_data_3;
+ mail_id_count = event_data->event_param_data_4;
+
+ if (!em_core_mail_delete(account_id, mail_id_list, mail_id_count, EMF_DELETE_LOCALLY, EMF_DELETED_BY_COMMAND, false, &err)) {
+ EM_DEBUG_EXCEPTION(" em_core_mail_delete falied [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ if (!em_core_insert_event(event_data, (int*)handle, &err)) {
+ EM_DEBUG_EXCEPTION("em_core_insert_event failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+FINISH_OFF:
+ /* em_core_free_event(event_data); */ /* all of members will be freed after using in each event handler */
+ EM_SAFE_FREE(event_data);
+
+ EM_DEBUG_FUNC_END();
+ return SUCCESS;
+}
+
+EXPORT_API int emf_mail_delete(int account_id, emf_mailbox_t* mailbox, int mail_ids[], int mail_ids_count, int from_server, unsigned* handle, int* err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("mailbox[%p], mail_ids[%p], mail_ids_count[%d], from_server[%d], handle[%p], err_code[%p]", mailbox, mail_ids, mail_ids_count, from_server, handle, err_code);
+
+ int ret = false;
+ int err = EMF_ERROR_NONE;
+ int* p = NULL, thread_error;
+ emf_event_t *event_data = NULL;
+ emf_account_t *account = NULL;
+ thread_t delete_thread;
+
+ /* mailbox can be NULL for deleting thread mail. */
+ if (mail_ids_count <= 0) {
+ EM_DEBUG_EXCEPTION("mail_ids_count [%d]", mail_ids_count);
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ if (!(account = em_core_get_account_reference(account_id))) {
+ EM_DEBUG_EXCEPTION("em_core_get_account_reference failed [%d]", account_id);
+ err = EMF_ERROR_INVALID_ACCOUNT;
+ goto FINISH_OFF;
+ }
+
+ if ((p = em_core_malloc(sizeof(int) * mail_ids_count)) == NULL) {
+ EM_DEBUG_EXCEPTION("em_core_malloc for p failed...");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ memcpy(p, mail_ids, sizeof(int) * mail_ids_count);
+
+ if ((event_data = em_core_malloc(sizeof(emf_event_t)) ) == NULL) {
+ EM_DEBUG_EXCEPTION("em_core_malloc for event_data failed...");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ event_data->type = EMF_EVENT_DELETE_MAIL;
+ event_data->account_id = account_id;
+ if(mailbox)
+ event_data->event_param_data_1 = mailbox->name;
+ event_data->event_param_data_3 = (char*)p;
+ event_data->event_param_data_4 = mail_ids_count;
+
+ THREAD_CREATE(delete_thread, thread_func_to_delete_mail, (void*)event_data, thread_error);
+ THREAD_DETACH(delete_thread); /* free resources used for new thread */
+ ret = true;
+
+FINISH_OFF:
+ if (ret == false)
+ EM_SAFE_FREE(p);
+
+ if (err_code)
+ *err_code = err;
+
+ return ret;
+}
+
+int emf_mail_delete_all(emf_mailbox_t* mailbox, int with_server, unsigned* handle, int* err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("mailbox[%p], with_server[%d], handle[%p], err_code[%p]", mailbox, with_server, handle, err_code);
+
+ int ret = false;
+ int err = EMF_ERROR_NONE;
+ emf_account_t *ref_account = NULL;
+ emf_event_t event_data = { 0 };
+
+ if (!mailbox || mailbox->account_id <= 0) {
+ EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+ ref_account = emf_get_account_reference(mailbox->account_id);
+
+ if (!ref_account) {
+ EM_DEBUG_EXCEPTION("emf_get_account_reference failed account_id [%d]", mailbox->account_id);
+ err = EMF_ERROR_INVALID_ACCOUNT;
+ goto FINISH_OFF;
+ }
+
+#ifdef __FEATURE_SYNC_CLIENT_TO_SERVER__
+ event_data.type = EMF_EVENT_DELETE_MAIL_ALL;
+ event_data.account_id = mailbox->account_id;
+ event_data.event_param_data_1 = EM_SAFE_STRDUP(mailbox->name);
+ event_data.event_param_data_3 = NULL;
+ event_data.event_param_data_4 = with_server;
+
+ if (!em_core_insert_event(&event_data, (int*)handle, &err)) {
+ EM_DEBUG_EXCEPTION("em_core_insert_event falied [%d]", err);
+ EM_SAFE_FREE(event_data.event_param_data_1);
+ goto FINISH_OFF;
+ }
+
+#ifdef __LOCAL_ACTIVITY__
+ int i, total = 0 , search_handle = 0;
+ int *mail_ids = NULL;
+ emf_activity_tbl_t new_activity;
+ int activityid = 0;
+
+ if (false == em_core_get_next_activity_id(&activityid,&err)) {
+ EM_DEBUG_EXCEPTION(" em_core_get_next_activity_id Failed - %d ", err);
+ }
+
+ if (!em_storage_mail_search_start(NULL, mailbox->account_id, mailbox->name, 0, &search_handle, &total, true, &err)) {
+ EM_DEBUG_EXCEPTION(" em_storage_mail_search_start failed [%d]", err);
+
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+
+ mail_ids = em_core_malloc(sizeof(int) * total);
+ if (mail_ids == NULL) {
+ EM_DEBUG_EXCEPTION(" mailloc failed...");
+
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ for (i = 0; i < total; i++) {
+ if (!em_storage_mail_search_result(search_handle, RETRIEVE_ID, (void**)&mail_ids[i], true, &err)) {
+ EM_DEBUG_EXCEPTION(" em_storage_mail_search_result failed [%d]", err);
+
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ EM_SAFE_FREE(mail_ids);
+ goto FINISH_OFF;
+ }
+
+ new_activity.activity_id = activityid;
+ new_activity.activity_type = ACTIVITY_DELETEMAIL;
+ new_activity.mail_id = mail_ids[i];
+ new_activity.server_mailid = NULL;
+ new_activity.src_mbox = mailbox->name;
+ new_activity.dest_mbox = NULL;
+ new_activity.account_id = mailbox->account_id;
+
+ if (! em_core_activity_add(&new_activity, &err))
+ EM_DEBUG_EXCEPTION(" em_core_activity_add Failed - %d ", err);
+
+ }
+
+ EM_SAFE_FREE(mail_ids);
+
+ EM_DEBUG_LOG("Setting g_local_activity_run ");
+ g_local_activity_run = 1;
+#endif
+
+#endif /* __FEATURE_SYNC_CLIENT_TO_SERVER__ */
+
+ ret = true;
+
+FINISH_OFF:
+ if (err_code)
+ *err_code = err;
+
+ return ret;
+}
+
+
+
+EXPORT_API int emf_mail_move_all_mails(emf_mailbox_t* src_mailbox, emf_mailbox_t* dst_mailbox, int* err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("src_mailbox[%p], dst_mailbox[%p], err_code[%p]", src_mailbox, dst_mailbox, err_code);
+
+ int ret = false;
+ int err = EMF_ERROR_NONE;
+ emf_account_t *ref_account = NULL;
+ emf_mail_list_item_t *mail_list = NULL;
+ int select_num = 0;
+ int *mails = NULL;
+ int i=0;
+ int num =0;
+
+ if (!dst_mailbox || dst_mailbox->account_id <= 0 || !src_mailbox || src_mailbox->account_id <= 0) {
+ EM_DEBUG_EXCEPTION("Invalid Parameter");
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ ref_account = emf_get_account_reference(dst_mailbox->account_id);
+
+ if (!ref_account) {
+ EM_DEBUG_EXCEPTION("emf_get_account_reference failed [%d]", dst_mailbox->account_id);
+ err = EMF_ERROR_INVALID_ACCOUNT;
+ goto FINISH_OFF;
+ }
+
+ if(!em_storage_get_mail_list(src_mailbox->account_id, src_mailbox->name, NULL, EMF_LIST_TYPE_NORMAL, -1, -1, 0, NULL, EMF_SORT_DATETIME_HIGH, false, &mail_list, &select_num, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_get_mail_list failed");
+ goto FINISH_OFF;
+ }
+
+ mails = malloc(sizeof(int) * select_num);
+
+ if( !mails ) {
+ EM_DEBUG_EXCEPTION("Malloc failed...!");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ memset(mails, 0x00, sizeof(int) * select_num);
+
+ for(i = 0 ; i < select_num ; i++) {
+ if( mail_list[i].save_status != EMF_MAIL_STATUS_SENDING ) {
+ mails[num] = mail_list[i].mail_id;
+ num++;
+ }
+ }
+
+ if( num <= 0) {
+ EM_DEBUG_EXCEPTION("can't find avalable mails. num = %d", num);
+ err = EMF_ERROR_MAIL_NOT_FOUND;
+ goto FINISH_OFF;
+ }
+
+ if(!em_core_mail_move(mails, num, dst_mailbox->name, EMF_MOVED_BY_COMMAND, 0, &err)) {
+ EM_DEBUG_EXCEPTION("em_core_mail_move falied [%d]", err);
+ goto FINISH_OFF;
+ }
+
+
+ ret = true;
+
+FINISH_OFF:
+ if (err_code)
+ *err_code = err;
+
+ if(mail_list)
+ EM_SAFE_FREE(mail_list);
+
+ if(mails != NULL )
+ EM_SAFE_FREE(mails);
+
+ return ret;
+}
+
+void* thread_func_to_move_mail(void *thread_argument)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int *mail_ids = NULL, mail_ids_count, noti_param_1, noti_param_2, err;
+ unsigned handle = 0;
+ emf_event_t *event_data = (emf_event_t*)thread_argument;
+ char *dst_mailbox_name = NULL;
+
+ dst_mailbox_name = (char*)event_data->event_param_data_1;
+ mail_ids = (int*)event_data->event_param_data_3;
+ mail_ids_count = event_data->event_param_data_4;
+ noti_param_1 = event_data->event_param_data_6;
+ noti_param_2 = event_data->event_param_data_7;
+
+ if (!em_core_mail_move(mail_ids, mail_ids_count, dst_mailbox_name, noti_param_1, noti_param_2, &err)) {
+ EM_DEBUG_EXCEPTION("em_core_mail_move failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ if (!em_core_insert_event(event_data, (int*)&handle, &err)) {
+ EM_DEBUG_EXCEPTION("em_core_insert_event failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+FINISH_OFF:
+ /* em_core_free_event(event_data); */ /* all of members will be freed after using in each event handler */
+ EM_SAFE_FREE(event_data);
+
+ EM_DEBUG_FUNC_END();
+ return SUCCESS;
+}
+
+EXPORT_API int emf_mail_move(int mail_ids[], int num, emf_mailbox_t* dst_mailbox, int noti_param_1, int noti_param_2, int* err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("mail_ids[%p], num[%d], dst_mailbox[%p], err_code[%p]", mail_ids, num, dst_mailbox, err_code);
+
+ /* default variable */
+ int mail_id = 0, *p = NULL, thread_error;
+ int ret = false, err = EMF_ERROR_NONE;
+ char *src_mailbox_name = NULL;
+ emf_mail_tbl_t* mail_table_data = NULL;
+ emf_account_t* ref_account = NULL;
+ emf_event_t *event_data = NULL;
+ thread_t move_thread;
+
+ if (num <= 0 || !dst_mailbox || dst_mailbox->account_id <= 0) {
+ EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ ref_account = emf_get_account_reference(dst_mailbox->account_id);
+
+ if (!ref_account) {
+ EM_DEBUG_EXCEPTION("emf_get_account_reference failed [%d]", dst_mailbox->account_id);
+ err = EMF_ERROR_INVALID_ACCOUNT;
+ goto FINISH_OFF;
+ }
+
+ /* Getting source mailbox name */
+ mail_id = mail_ids[0];
+
+ if (!em_storage_get_mail_field_by_id(mail_id, RETRIEVE_SUMMARY, &mail_table_data, true, &err) || !mail_table_data) {
+ EM_DEBUG_EXCEPTION("em_storage_get_mail_field_by_id failed [%d]", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+
+ if (src_mailbox_name == NULL)
+ src_mailbox_name = EM_SAFE_STRDUP(mail_table_data->mailbox_name);
+
+ em_storage_free_mail(&mail_table_data, 1, NULL);
+
+ if ((event_data = em_core_malloc(sizeof(emf_event_t)) ) == NULL) {
+ EM_DEBUG_EXCEPTION("em_core_malloc for event_data failed...");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ if ((p = em_core_malloc(sizeof(int) * num)) == NULL) {
+ EM_DEBUG_EXCEPTION("em_core_malloc for p failed...");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ memcpy(p, mail_ids, sizeof(int) * num);
+
+ event_data->account_id = dst_mailbox->account_id;
+ event_data->type = EMF_EVENT_MOVE_MAIL;
+ event_data->event_param_data_1 = EM_SAFE_STRDUP(dst_mailbox->name);
+ event_data->event_param_data_2 = EM_SAFE_STRDUP(src_mailbox_name);
+ event_data->event_param_data_3 = (char*)p;
+ event_data->event_param_data_4 = num;
+ event_data->event_param_data_6 = noti_param_1;
+ event_data->event_param_data_7 = noti_param_2;
+
+#ifdef __LOCAL_ACTIVITY__
+ int i = 0, activityid = 0;
+
+ if (false == em_core_get_next_activity_id(&activityid,&err))
+ EM_DEBUG_EXCEPTION(" em_core_get_next_activity_id Failed - %d ", err);
+
+ for (i =0; i < event_data.event_param_data_4; i++) {
+ emf_activity_tbl_t new_activity;
+ new_activity.activity_id = activityid;
+ new_activity.activity_type = ACTIVITY_MOVEMAIL;
+ new_activity.account_id = event_data.account_id;
+ new_activity.mail_id = mail_ids[i];
+ new_activity.dest_mbox = event_data.event_param_data_1;
+ new_activity.server_mailid = NULL;
+ new_activity.src_mbox = event_data.event_param_data_2;
+
+ if (!em_core_activity_add(&new_activity, &err))
+ EM_DEBUG_EXCEPTION(" em_core_activity_add Failed - %d ", err);
+ }
+#endif /* __LOCAL_ACTIVITY__ */
+ THREAD_CREATE(move_thread, thread_func_to_move_mail, (void*)event_data, thread_error);
+ THREAD_DETACH(move_thread); /* free resources used for new thread */
+ ret = true;
+
+FINISH_OFF:
+
+#ifdef __LOCAL_ACTIVITY__
+ EM_DEBUG_LOG("Setting g_local_activity_run ");
+ g_local_activity_run = 1;
+#endif /* __LOCAL_ACTIVITY__ */
+
+ if (err_code)
+ *err_code = err;
+
+ EM_SAFE_FREE(src_mailbox_name);
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+EXPORT_API int emf_mail_modify_flag(int mail_id, emf_mail_flag_t new_flag, int onserver, int sticky_flag, int* err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("mail_id[%d], new_flag[%d], onserver[%d], sticky_flag[%d], err_code[%p]", mail_id, new_flag, onserver, sticky_flag, err_code);
+
+ /* default variable */
+ int ret = false;
+ int err = EMF_ERROR_NONE;
+
+ if (!em_core_mail_modify_flag(mail_id, new_flag, sticky_flag, &err)) {
+ EM_DEBUG_EXCEPTION(" em_core_mail_modify_flag falled [%d]", err);
+ goto FINISH_OFF;
+ }
+
+#ifdef __FEATURE_SYNC_CLIENT_TO_SERVER__
+ if( onserver == 1) {
+ emf_event_t event_data;
+ unsigned handle = 0;
+ memset(&event_data, 0x00, sizeof(emf_event_t));
+
+ event_data.type = EMF_EVENT_SYNC_MAIL_FLAG_TO_SERVER;
+ event_data.event_param_data_1 = NULL;
+ event_data.event_param_data_4 = mail_id;
+ event_data.account_id = 0;
+#ifdef __LOCAL_ACTIVITY__
+ emf_mail_tbl_t *mail_table_data = NULL;
+ if (!em_storage_get_mail_field_by_id(mail_id, RETRIEVE_SUMMARY, &mail_table_data, false, &err) || !mail_table_data) {
+ EM_DEBUG_LOG(" em_storage_get_mail_field_by_id failed [%d]", err);
+ goto FINISH_OFF;
+ }
+ event_data.account_id = mail_table_data->account_id;
+ em_storage_free_mail(&mail_table_data,1,&err);
+
+ emf_activity_tbl_t new_activity;
+ new_activity.activity_type = ACTIVITY_MODIFYFLAG;
+ new_activity.account_id = event_data.account_id;
+ new_activity.mail_id = event_data.event_param_data_4;
+ new_activity.dest_mbox = NULL;
+ new_activity.server_mailid = NULL;
+ new_activity.src_mbox = NULL;
+
+ if (false == em_core_get_next_activity_id(&new_activity.activity_id,&err)) {
+ EM_DEBUG_EXCEPTION(" em_core_get_next_activity_id Failed - %d \n", err);
+ }
+
+ if (!em_core_activity_add(&new_activity, &err)) {
+ EM_DEBUG_EXCEPTION(" em_core_activity_add [ACTIVITY_MODIFYFLAG] Failed - %d \n", err);
+ }
+
+#endif /* __LOCAL_ACTIVITY__ */
+ if (!em_core_insert_event(&event_data, (int*)&handle, &err)) {
+ EM_DEBUG_EXCEPTION("em_core_insert_event failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+#ifdef __LOCAL_ACTIVITY__
+ EM_DEBUG_LOG("Setting g_local_activity_run ");
+ g_local_activity_run = 1;
+#endif /* __LOCAL_ACTIVITY__ */
+ }
+#endif /* __FEATURE_SYNC_CLIENT_TO_SERVER__ */
+
+ ret = true;
+
+FINISH_OFF:
+ if (err_code)
+ *err_code = err;
+ EM_DEBUG_FUNC_END();
+ return ret;
+}
+
+EXPORT_API int emf_mail_modify_extra_flag(int mail_id, emf_extra_flag_t new_flag, int* err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("mail_id[%d], err_code[%p]", mail_id, err_code);
+
+ int ret = false;
+ int err = EMF_ERROR_NONE;
+
+ if (!emf_mail_check_mail_id(mail_id, &err)) {
+ EM_DEBUG_EXCEPTION("emf_mail_check_mail_id failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ if (!em_core_mail_modify_extra_flag(mail_id, new_flag, &err)) {
+ EM_DEBUG_EXCEPTION("engine_mail_modify_extra_flag failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ ret = true;
+
+FINISH_OFF:
+ if (err_code)
+ *err_code = err;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+ }
+
+EXPORT_API int emf_mail_set_flags_field(int account_id, int mail_ids[], int num, emf_flags_field_type field_type, int value, int onserver, int* err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("mail_ids[%d], num[%d], field_type [%d], value[%d], err_code[%p]", mail_ids[0], num, field_type, value, err_code);
+
+ int ret = false, err = EMF_ERROR_NONE;
+
+ if(account_id <= 0 || !mail_ids || num <= 0) {
+ err = EMF_ERROR_INVALID_PARAM;
+ EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
+ goto FINISH_OFF;
+ }
+
+ if (!em_core_mail_set_flags_field(account_id, mail_ids, num, field_type, value, &err)) {
+ EM_DEBUG_EXCEPTION("em_core_mail_set_flags_field falled [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ if( onserver ) {
+ int *mail_id_array = NULL;
+ emf_event_t event_data = {0};
+ unsigned handle = 0;
+
+ mail_id_array = em_core_malloc(sizeof(int) * num);
+
+ if (mail_id_array == NULL) {
+ EM_DEBUG_EXCEPTION("em_core_malloc failed...");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ memcpy(mail_id_array, mail_ids, sizeof(int) * num);
+
+ event_data.type = EMF_EVENT_SYNC_FLAGS_FIELD_TO_SERVER;
+ event_data.account_id = account_id;
+ event_data.event_param_data_1 = NULL;
+ event_data.event_param_data_3 = (char*)mail_id_array;
+ event_data.event_param_data_4 = num;
+ event_data.event_param_data_5 = field_type;
+ event_data.event_param_data_6 = value;
+
+ if (!em_core_insert_event(&event_data, (int*)&handle, &err)) {
+ EM_DEBUG_LOG("em_core_insert_event failed [%d]", err);
+ goto FINISH_OFF;
+ }
+ }
+
+ ret = true;
+
+FINISH_OFF:
+ if (err_code)
+ *err_code = err;
+ EM_DEBUG_FUNC_END();
+ return ret;
+}
+
+
+
+EXPORT_API int emf_mail_update(int mail_id, emf_mail_t* mail, emf_meeting_request_t *meeting_req, int with_server, int* err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("mail_id[%d], mail[%p], with_server[%d], err_code[%p]", mail_id, mail, with_server, err_code);
+
+ int ret = false;
+ int err = EMF_ERROR_NONE;
+ emf_mail_tbl_t* mail_table_data = NULL;
+ int handle= 0;
+ emf_event_t event_data;
+ char* p_mail = NULL;
+
+ if (!mail || !mail->info) {
+ EM_DEBUG_EXCEPTION("mail_id[%d], mali[%p]", mail_id, mail);
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ if (!emf_mail_check_mail_id(mail_id, &err)) {
+ EM_DEBUG_EXCEPTION("emf_mail_check_mail_id failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ if (mail->body && mail->body->attachment) {
+ emf_attachment_info_t* p = mail->body->attachment;
+ struct stat st_buf;
+
+ while (p) {
+ if(p->downloaded) {
+ if (!p->savename || stat(p->savename, &st_buf) < 0) {
+ EM_DEBUG_EXCEPTION("stat(\"%s\" failed...", p->savename);
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+ }
+ p = p->next;
+ }
+ }
+
+ emf_account_t* ref_account = emf_get_account_reference(mail->info->account_id);
+
+ if (!ref_account) {
+ EM_DEBUG_EXCEPTION("emf_get_account_reference failed [%d]", mail->info->account_id);
+ err = EMF_ERROR_INVALID_ACCOUNT;
+ goto FINISH_OFF;
+ }
+
+ if( with_server && ref_account->receiving_server_type == EMF_SERVER_TYPE_IMAP4) {
+ if (!em_storage_get_mail_field_by_id(mail_id, RETRIEVE_SUMMARY, &mail_table_data, false, &err))
+ EM_DEBUG_LOG("em_storage_get_mail_field_by_id failed [%d]", err);
+
+ p_mail= malloc(sizeof(int));
+ if (p_mail == NULL) {
+ EM_DEBUG_EXCEPTION("malloc failed...");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+ memcpy(p_mail, &mail_id, sizeof(int));
+
+ memset(&event_data, 0x00, sizeof(emf_event_t));
+ event_data.type = EMF_EVENT_DELETE_MAIL;
+ event_data.account_id = mail->info->account_id;
+ event_data.event_param_data_3 = (char*)p_mail;
+ event_data.event_param_data_4 = 1;
+ event_data.event_param_data_1 = EM_SAFE_STRDUP(mail_table_data->mailbox_name);
+
+#ifdef __LOCAL_ACTIVITY__
+ emf_activity_tbl_t new_activity;
+ EM_DEBUG_LOG(" mail_id - %d\n", mail_id);
+ new_activity.activity_type = ACTIVITY_DELETEMAIL_SEND;
+ new_activity.account_id = event_data.account_id;
+ new_activity.mail_id = mail_id;
+ new_activity.server_mailid = NULL;
+ new_activity.src_mbox = EM_SAFE_STRDUP(mail_table_data->mailbox);
+ new_activity.dest_mbox = NULL;
+
+ if (false == em_core_get_next_activity_id(&new_activity.activity_id,&err)) {
+ EM_DEBUG_EXCEPTION(" em_core_get_next_activity_id Failed - %d \n", err);
+ }
+
+ if (! em_core_activity_add(&new_activity, &err))
+ EM_DEBUG_EXCEPTION(" em_core_activity_add Failed - %d \n", err);
+ else
+ EM_SAFE_FREE(new_activity.src_mbox); /* Memory Leak Fix */
+
+#endif /* __LOCAL_ACTIVITY__ */
+ if (!em_core_insert_send_event(&event_data, &handle, &err)) {
+ EM_DEBUG_EXCEPTION("em_core_insert_event failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+#ifdef __LOCAL_ACTIVITY__
+ EM_DEBUG_LOG("Setting g_save_local_activity_run ");
+ g_save_local_activity_run = 1;
+#endif
+ }
+
+ switch (ref_account->account_bind_type) {
+ case EMF_BIND_TYPE_EM_CORE:
+ memset(&event_data, 0x00, sizeof(emf_event_t));
+ event_data.type = EMF_EVENT_UPDATE_MAIL_OLD;
+ event_data.account_id = mail->info->account_id;
+ event_data.event_param_data_3 = NULL;
+ event_data.event_param_data_4 = mail_id;
+ event_data.event_param_data_1 = (char*)mail; /* will be freed in event handler */
+ event_data.event_param_data_2 = (char*)meeting_req; /* will be freed in event handler */
+
+#ifdef __LOCAL_ACTIVITY__
+ if( with_server ) {
+ emf_activity_tbl_t new_activity;
+
+ new_activity.activity_type = ACTIVITY_SAVEMAIL;
+ new_activity.account_id = event_data.account_id;
+ new_activity.mail_id = event_data.event_param_data_4;
+ new_activity.dest_mbox = NULL;
+ new_activity.server_mailid = NULL;
+ new_activity.src_mbox = NULL;
+
+ if (false == em_core_get_next_activity_id(&new_activity.activity_id,&err)) {
+ EM_DEBUG_EXCEPTION(" em_core_get_next_activity_id Failed - %d \n", err);
+ }
+
+ if (!em_core_activity_add(&new_activity, &err)) {
+ EM_DEBUG_EXCEPTION(" em_core_activity_add Failed - %d \n", err);
+ }
+ }
+#endif /* __LOCAL_ACTIVITY__ */
+
+ if (!em_core_insert_event(&event_data, &handle, &err)) {
+ EM_DEBUG_EXCEPTION("em_core_insert_event failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ #ifdef __LOCAL_ACTIVITY__
+ EM_DEBUG_LOG("Setting g_save_local_activity_run ");
+ g_save_local_activity_run = 1;
+ #endif
+
+ break;
+
+ default:
+ EM_DEBUG_EXCEPTION("unknown account bind type...");
+ err = EMF_ERROR_INVALID_ACCOUNT;
+ goto FINISH_OFF;
+ }
+
+ ret = true;
+
+FINISH_OFF:
+ if (err_code)
+ *err_code = err;
+ EM_DEBUG_FUNC_END();
+ return ret;
+}
+
+EXPORT_API int emf_update_mail(emf_mail_data_t *input_mail_data, emf_attachment_data_t *input_attachment_data_list, int input_attachment_count, emf_meeting_request_t *input_meeting_request, int input_sync_server)
+{
+ EM_DEBUG_FUNC_BEGIN("input_mail_data[%p], input_attachment_data_list[%p], input_attachment_count [%d], input_meeting_req [%p], input_sync_server[%d]", input_mail_data, input_attachment_data_list, input_attachment_count, input_meeting_request, input_sync_server);
+
+ int err = EMF_ERROR_NONE;
+ int handle = 0;
+ emf_event_t event_data = { 0 };
+ emf_account_t *ref_account = NULL;
+
+ if (!input_mail_data || input_mail_data->account_id <= 0 || input_mail_data->mail_id == 0 ||
+ (input_mail_data->report_status == EMF_MAIL_REPORT_MDN && !input_mail_data->full_address_to)) {
+ EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ ref_account = emf_get_account_reference(input_mail_data->account_id);
+ if (!ref_account) {
+ EM_DEBUG_LOG(" emf_get_account_reference failed [%d]", input_mail_data->account_id);
+ err = EMF_ERROR_INVALID_ACCOUNT;
+ goto FINISH_OFF;
+ }
+
+ switch (ref_account->account_bind_type) {
+ case EMF_BIND_TYPE_EM_CORE :
+ if ( (err = em_core_update_mail(input_mail_data, input_attachment_data_list, input_attachment_count, input_meeting_request, input_sync_server)) != EMF_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("em_core_update_mail failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+#ifdef __FEATURE_SYNC_CLIENT_TO_SERVER__
+ if ( input_sync_server ) {
+ event_data.type = EMF_EVENT_UPDATE_MAIL;
+ event_data.account_id = input_mail_data->account_id;
+ event_data.event_param_data_1 = (char*)input_mail_data;
+ event_data.event_param_data_2 = (char*)input_attachment_data_list;
+ event_data.event_param_data_3 = (char*)input_meeting_request;
+ event_data.event_param_data_4 = input_attachment_count;
+ event_data.event_param_data_5 = input_sync_server;
+
+ if (!em_core_insert_send_event(&event_data, &handle, &err)) {
+ EM_DEBUG_EXCEPTION("em_core_insert_send_event failed [%d]", err);
+ err = EMF_ERROR_NONE;
+ goto FINISH_OFF;
+ }
+ }
+#endif
+ break;
+
+ default:
+ EM_DEBUG_EXCEPTION("unknown account bind type...");
+ err = EMF_ERROR_INVALID_ACCOUNT;
+ goto FINISH_OFF;
+ }
+
+FINISH_OFF:
+
+ EM_DEBUG_FUNC_END("err [%d]", err);
+ return err;
+}
+
+
+int emf_mail_check_mail_id(int mail_id, int* err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("mail_id[%d], err_code[%p]", mail_id, err_code);
+
+ int ret = false;
+ int err = EMF_ERROR_NONE;
+
+ emf_mail_tbl_t* mail = NULL;
+
+ if (!em_storage_get_mail_field_by_id(mail_id, RETRIEVE_SUMMARY, &mail, true, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_get_mail_field_by_id failed [%d]", err);
+
+ if (err == EM_STORAGE_ERROR_MAIL_NOT_FOUND)
+ err = EMF_ERROR_MAIL_NOT_FOUND;
+ else if (err == EM_STORAGE_ERROR_OUT_OF_MEMORY)
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ else if (err == EM_STORAGE_ERROR_DB_FAILURE)
+ err = EMF_ERROR_DB_FAILURE;
+ else if (err == EM_STORAGE_ERROR_INVALID_PARAM)
+ err = EMF_ERROR_INVALID_PARAM;
+ else
+ err = EMF_ERROR_UNKNOWN;
+
+ goto FINISH_OFF;
+ }
+
+ ret = true;
+
+FINISH_OFF:
+ if (mail != NULL)
+ em_storage_free_mail(&mail, 1, NULL);
+
+ if (err_code != NULL)
+ *err_code = err;
+ EM_DEBUG_FUNC_END();
+ return ret;
+}
+
+
+EXPORT_API int emf_mail_send_retry( int mail_id, int timeout_in_sec, int* err_code)
+{
+ int ret = false;
+ int err = EMF_ERROR_NONE;
+ long nTimerValue = 0;
+ emf_mailbox_t mailbox;
+ emf_mail_t* mail = NULL;
+ emf_mail_tbl_t* mail_table_data = NULL;
+ char mailId[10];
+ emf_option_t opt;
+
+ memset( &opt, 0x00, sizeof(emf_option_t));
+ memset( &mailbox, 0x00, sizeof(emf_mailbox_t));
+ memset(mailId, 0x00, 10);
+
+ if (!emf_mail_check_mail_id(mail_id, &err)) {
+ EM_DEBUG_EXCEPTION("emf_mail_check_mail_id failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ if( ! em_storage_get_mail_by_id(mail_id, &mail_table_data, false, &err) && !mail_table_data) {
+ EM_DEBUG_EXCEPTION("em_storage_get_mail_by_id failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ if (!em_core_mail_get_mail(mail_id, &mail, &err) && !mail) {
+ EM_DEBUG_EXCEPTION("em_core_mail_get_mail failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+
+ mailbox.name = EM_SAFE_STRDUP(mail_table_data->mailbox_name);
+ memcpy(&opt, em_core_get_option(&err), sizeof(emf_mail_t));
+ if( mail && mail->info ) {
+ mailbox.account_id = mail->info->account_id;
+ opt.priority = mail->info->extra_flags.priority;
+ }
+
+ if ( timeout_in_sec == 0 ) {
+ if(!emf_mail_send(&mailbox, mail_id, &opt, NULL, &err)) {
+ EM_DEBUG_EXCEPTION("emf_mail_send failed [%d]", err);
+ goto FINISH_OFF;
+ }
+ }
+ else if ( timeout_in_sec > 0 ) {
+ sprintf(mailId,"%d",mail_id);
+ nTimerValue = timeout_in_sec * 1000;
+ if ( em_core_set_timer_ex(nTimerValue, (EMF_TIMER_CALLBACK) _OnMailSendRetryTimerCB, (void*)mailId) <= 0) {
+ EM_DEBUG_EXCEPTION("emf_mail_send_retry - Failed to start timer");
+ goto FINISH_OFF;
+ }
+ }
+ ret = true;
+FINISH_OFF:
+ if (err_code)
+ *err_code = err;
+ if (mail) em_core_mail_free(&mail, 1, NULL);
+ if(mail_table_data) em_storage_free_mail(&mail_table_data, 1, NULL);
+ EM_SAFE_FREE(mailbox.name);
+
+ return ret;
+}
+
+
+EXPORT_API
+void _OnMailSendRetryTimerCB( void* data )
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int err = EMF_ERROR_NONE;
+ emf_mailbox_t mailbox;
+ emf_mail_t* mail = NULL;
+ emf_mail_tbl_t* mail_table_data = NULL;
+ int mail_id = 0 ;
+ emf_option_t opt;
+
+ memset( &opt, 0x00, sizeof(emf_option_t));
+ memset( &mailbox, 0x00, sizeof(emf_mailbox_t));
+
+ if( !data ) {
+ EM_DEBUG_LOG("Invalid param");
+ goto FINISH_OFF;
+ }
+
+ mail_id = atoi((char*)data);
+
+
+ if (!emf_mail_check_mail_id(mail_id, &err)) {
+ EM_DEBUG_EXCEPTION("emf_mail_check_mail_id failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ if (!em_core_mail_get_mail(mail_id, &mail, &err) && !mail) {
+ EM_DEBUG_EXCEPTION("em_core_mail_get_mail failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ if( ! em_storage_get_mail_by_id(mail_id, &mail_table_data, false, &err) && !mail_table_data) {
+ EM_DEBUG_EXCEPTION("em_storage_get_mail_by_id failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ mailbox.name = EM_SAFE_STRDUP(mail_table_data->mailbox_name);
+ memcpy(&opt, em_core_get_option(&err), sizeof(emf_mail_t));
+
+ if( mail && mail->info ) {
+ opt.priority = mail->info->extra_flags.priority;
+ mailbox.account_id = mail->info->account_id;
+ }
+
+ if(!emf_mail_send(&mailbox, mail_id, &opt, NULL, &err)) {
+ EM_DEBUG_EXCEPTION("emf_mail_send failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+FINISH_OFF:
+ if (mail) em_core_mail_free(&mail, 1, NULL);
+ if(mail_table_data) em_storage_free_mail(&mail_table_data, 1, NULL);
+ EM_SAFE_FREE(mailbox.name);
+
+ EM_DEBUG_FUNC_END();
+ return;
+}
+
+EXPORT_API int emf_mail_move_thread_to_mailbox(int thread_id, char *target_mailbox_name, int move_always_flag, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("thread_id [%d], target_mailbox_name [%p], move_always_flag [%d], err_code [%p]", thread_id, target_mailbox_name, move_always_flag, err_code);
+ int ret = false;
+ int err = EMF_ERROR_NONE;
+ int *mail_id_list = NULL, result_count = 0, i, mailbox_count = 0, account_id;
+ emf_mail_list_item_t *mail_list = NULL;
+ emf_mailbox_t *target_mailbox_list = NULL, *target_mailbox = NULL;
+
+ if (!target_mailbox_name) {
+ EM_DEBUG_EXCEPTION("target_mailbox [%p]", target_mailbox_name);
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ if (!em_storage_get_mail_list(0, NULL, NULL, thread_id, -1, -1, 0, NULL, EMF_SORT_DATETIME_HIGH, true, &mail_list, &result_count, &err) || !mail_list || !result_count) {
+ EM_DEBUG_EXCEPTION("em_storage_get_mail_list failed [%d]", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+
+ mail_id_list = em_core_malloc(sizeof(int) * result_count);
+
+ if (mail_id_list == NULL) {
+ EM_DEBUG_EXCEPTION("em_core_malloc failed...");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ for(i = 0; i < result_count; i++) {
+ mail_id_list[i] = mail_list[i].mail_id;
+ }
+ account_id = mail_list[0].account_id;
+
+
+ if (!em_core_mailbox_get_list(account_id, &target_mailbox_list, &mailbox_count, &err)) {
+ EM_DEBUG_EXCEPTION("em_core_mailbox_get_list failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ for(i = 0; i < mailbox_count; i++) {
+ EM_DEBUG_LOG("%s %s", target_mailbox_list[i].name, target_mailbox_name);
+ if(strcmp(target_mailbox_list[i].name, target_mailbox_name) == 0) {
+ target_mailbox = (target_mailbox_list + i);
+ break;
+ }
+ }
+
+ if(!target_mailbox) {
+ EM_DEBUG_EXCEPTION("couldn't find proper target mailbox.");
+ goto FINISH_OFF;
+ }
+
+ if (!emf_mail_move(mail_id_list, result_count, target_mailbox, EMF_MOVED_BY_MOVING_THREAD, move_always_flag, &err)) {
+ EM_DEBUG_EXCEPTION("emf_mail_move failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ if (!em_storage_notify_storage_event(NOTI_THREAD_MOVE, account_id, thread_id, target_mailbox_name, move_always_flag))
+ EM_DEBUG_EXCEPTION(" em_storage_notify_storage_event Failed [NOTI_MAIL_MOVE] >>>> ");
+
+ ret = true;
+
+FINISH_OFF:
+ if (!em_core_mailbox_free(&target_mailbox_list, mailbox_count, &err))
+ EM_DEBUG_EXCEPTION("target_mailbox_list failed [%d]", err);
+ EM_SAFE_FREE(mail_list);
+ EM_SAFE_FREE(mail_id_list);
+
+ if (err_code)
+ *err_code = err;
+ EM_DEBUG_FUNC_END();
+ return ret;
+}
+
+EXPORT_API int emf_mail_delete_thread(int thread_id, int delete_always_flag, unsigned* handle, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("thread_id [%d], delete_always_flag [%d], err_code [%p]", thread_id, delete_always_flag, err_code);
+ int ret = false;
+ int err = EMF_ERROR_NONE;
+ int account_id, *mail_id_list = NULL, result_count = 0, i;
+ emf_mail_list_item_t *mail_list = NULL;
+
+ if (!em_storage_get_mail_list(0, NULL, NULL, thread_id, -1, -1, 0, NULL, EMF_SORT_MAILBOX_NAME_HIGH, true, &mail_list, &result_count, &err) || !mail_list || !result_count) {
+ EM_DEBUG_EXCEPTION("em_storage_get_mail_list failed [%d]", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+
+ mail_id_list = em_core_malloc(sizeof(int) * result_count);
+
+ if (mail_id_list == NULL) {
+ EM_DEBUG_EXCEPTION("em_core_malloc failed...");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ for(i = 0; i < result_count; i++) {
+ mail_id_list[i] = mail_list[i].mail_id;
+ }
+
+ account_id = mail_list[0].account_id;
+
+ // should remove requiring of mailbox information from this function.
+ // email-service should find mailboxes itself by its mail id.
+ if (!emf_mail_delete(account_id, NULL, mail_id_list, result_count, false, handle, &err)) {
+ EM_DEBUG_EXCEPTION("emf_mail_delete failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ if (!em_storage_notify_storage_event(NOTI_THREAD_DELETE, account_id, thread_id, NULL, delete_always_flag))
+ EM_DEBUG_EXCEPTION(" em_storage_notify_storage_event Failed [NOTI_MAIL_MOVE] >>>> ");
+
+ ret = true;
+
+FINISH_OFF:
+ EM_SAFE_FREE(mail_list);
+ EM_SAFE_FREE(mail_id_list);
+
+ if (err_code)
+ *err_code = err;
+ EM_DEBUG_FUNC_END();
+ return ret;
+}
+
+EXPORT_API int emf_mail_modify_seen_flag_of_thread(int thread_id, int seen_flag, int on_server, unsigned* handle, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("thread_id [%d], seen_flag [%d], on_server [%d], handle [%p], err_code [%p]", thread_id, seen_flag, on_server, handle, err_code);
+ int ret = false;
+ int err = EMF_ERROR_NONE;
+ int account_id, *mail_id_list = NULL, result_count = 0, i;
+ emf_mail_list_item_t *mail_list = NULL;
+
+ if (!em_storage_get_mail_list(0, NULL, NULL, thread_id, -1, -1, 0, NULL, EMF_SORT_MAILBOX_NAME_HIGH, true, &mail_list, &result_count, &err) || !mail_list || !result_count) {
+ EM_DEBUG_EXCEPTION("em_storage_get_mail_list failed [%d]", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+
+ mail_id_list = em_core_malloc(sizeof(int) * result_count);
+
+ if (mail_id_list == NULL) {
+ EM_DEBUG_EXCEPTION("em_core_malloc failed...");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ for(i = 0; i < result_count; i++) {
+ mail_id_list[i] = mail_list[i].mail_id;
+ }
+
+ account_id = mail_list[0].account_id;
+
+ if (!emf_mail_set_flags_field(account_id, mail_id_list, result_count, EMF_FLAGS_SEEN_FIELD, seen_flag, on_server, &err)) {
+ EM_DEBUG_EXCEPTION("emf_mail_set_flags_field failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ if (!em_storage_notify_storage_event(NOTI_THREAD_MODIFY_SEEN_FLAG, account_id, thread_id, NULL, seen_flag))
+ EM_DEBUG_EXCEPTION(" em_storage_notify_storage_event Failed [NOTI_MAIL_MOVE] >>>> ");
+
+ ret = true;
+
+FINISH_OFF:
+ EM_SAFE_FREE(mail_list);
+ EM_SAFE_FREE(mail_id_list);
+
+ if (err_code)
+ *err_code = err;
+ EM_DEBUG_FUNC_END();
+ return ret;
+}
diff --git a/email-engine/emf-mailbox.c b/email-engine/emf-mailbox.c
new file mode 100755
index 0000000..ba75ea3
--- /dev/null
+++ b/email-engine/emf-mailbox.c
@@ -0,0 +1,585 @@
+/*
+* email-service
+*
+* Copyright (c) 2000 - 2011 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.
+*
+*/
+
+
+
+/******************************************************************************
+ * File: emf-mailbox.c
+ * Desc: Mail Framework Mailbox Operation
+ *
+ * Auth:
+ *
+ * History:
+ * 2006.08.16 : created
+ *****************************************************************************/
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "emflib.h"
+#include "emf-global.h"
+#include "em-core-event.h"
+#include "emf-account.h"
+#include "emf-dbglog.h"
+#include "em-core-mailbox.h"
+#include "em-core-global.h"
+#include "em-core-utils.h"
+
+#ifdef __LOCAL_ACTIVITY__
+extern int g_local_activity_run;
+#endif
+
+EXPORT_API int
+emf_mailbox_get_imap_mailbox_list(int account_id, char* mailbox, unsigned* handle, int* err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("account_id[%d] mailbox[%p] err_code[%p]", account_id, mailbox, err_code);
+
+ /* default variable */
+ int ret = false;
+ int err = EMF_ERROR_NONE;
+
+ if (account_id <= 0 ||!mailbox) {
+ EM_DEBUG_EXCEPTION("account_id[%d], mailbox[%p]", account_id, mailbox);
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ emf_account_t* ref_account = emf_get_account_reference(account_id);
+
+ if (!ref_account) {
+ EM_DEBUG_EXCEPTION("emf_get_account_reference failed [%d]", account_id);
+ err = EMF_ERROR_INVALID_ACCOUNT;
+ goto FINISH_OFF;
+ }
+
+ emf_event_t event_data;
+ memset(&event_data, 0x00, sizeof(emf_event_t));
+
+ switch (ref_account->account_bind_type) {
+ case EMF_BIND_TYPE_EM_CORE:
+ event_data.type = EMF_EVENT_SYNC_IMAP_MAILBOX;
+ event_data.account_id = account_id;
+ event_data.event_param_data_3 = EM_SAFE_STRDUP(mailbox);
+
+ if (!em_core_insert_event(&event_data, (int*)handle, &err)) {
+ EM_DEBUG_EXCEPTION("em_core_insert_event failed [%d]", err);
+ goto FINISH_OFF;
+ }
+ break;
+
+ default:
+ EM_DEBUG_EXCEPTION("unknown account bind type...");
+ err = EMF_ERROR_INVALID_ACCOUNT;
+ goto FINISH_OFF;
+ }
+
+ ret = true;
+
+FINISH_OFF:
+ if (err_code)
+ *err_code = err;
+ EM_DEBUG_FUNC_END();
+ return ret;
+}
+
+
+
+
+EXPORT_API int emf_mailbox_get_list(int account_id, emf_mailbox_t** mailbox_list, int* count, int* err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("account_id[%d], mailbox_list[%p], count[%p], err_code[%p]", account_id, mailbox_list, count, err_code);
+
+ int ret = false;
+ int err = EMF_ERROR_NONE;
+
+ if (account_id <= 0 || !mailbox_list || !count) {
+ EM_DEBUG_EXCEPTION("account_id[%d], mailbox_list[%p], count[%p]", account_id, mailbox_list, count);
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ emf_account_t* ref_account = emf_get_account_reference(account_id);
+
+ if (!ref_account) {
+ EM_DEBUG_EXCEPTION("emf_get_account_reference failed [%d]", account_id);
+ err = EMF_ERROR_INVALID_ACCOUNT;
+ goto FINISH_OFF;
+ }
+
+ switch (ref_account->account_bind_type) {
+ case EMF_BIND_TYPE_EM_CORE:
+ if (!em_core_mailbox_get_list(account_id, mailbox_list, count, &err)) {
+ EM_DEBUG_EXCEPTION("em_core_mailbox_get_list failed [%d]", err);
+ goto FINISH_OFF;
+ }
+ break;
+
+ default:
+ EM_DEBUG_EXCEPTION("unknown account bind type...");
+ err = EMF_ERROR_INVALID_ACCOUNT;
+ goto FINISH_OFF;
+ }
+
+ ret = true;
+
+FINISH_OFF:
+ if (err_code)
+ *err_code = err;
+ EM_DEBUG_FUNC_END();
+ return ret;
+}
+
+
+EXPORT_API int emf_mailbox_get_mail_count(emf_mailbox_t* mailbox, int* total, int* unseen, int* err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("mailbox[%p], total[%p], unseen[%p], err_code[%p]", mailbox, total, unseen, err_code);
+
+ /* default variable */
+ int ret = false;
+ int err = EMF_ERROR_NONE;
+
+ if (!mailbox || !total || !unseen) {
+ EM_DEBUG_EXCEPTION("mailbox[%p], total[%p], unseen[%p]", mailbox, total, unseen);
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ emf_account_t* ref_account = emf_get_account_reference(mailbox->account_id);
+ if (ref_account == NULL) {
+ EM_DEBUG_EXCEPTION(" emf_get_account_reference failed [%d]", mailbox->account_id);
+ err = EMF_ERROR_INVALID_ACCOUNT;
+ goto FINISH_OFF;
+ }
+
+ switch (ref_account->account_bind_type) {
+ case EMF_BIND_TYPE_EM_CORE:
+ if (!em_core_mailbox_get_mail_count(mailbox, total, unseen, &err)) {
+ EM_DEBUG_EXCEPTION("em_core_mailbox_get_mail_count failed [%d]", err);
+ goto FINISH_OFF;
+ }
+ break;
+
+ default:
+ EM_DEBUG_EXCEPTION("unknown account bind type...");
+ err = EMF_ERROR_INVALID_ACCOUNT;
+ goto FINISH_OFF;
+ }
+
+ ret = true;
+
+FINISH_OFF:
+ if (err_code)
+ *err_code = err;
+ EM_DEBUG_FUNC_END();
+ return ret;
+}
+
+EXPORT_API int emf_mailbox_create(emf_mailbox_t* new_mailbox, int on_server, unsigned* handle, int* err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("new_mailbox[%p], err_code[%p]", new_mailbox, err_code);
+
+ int ret = false;;
+ int err = EMF_ERROR_NONE;
+
+ if (!new_mailbox || new_mailbox->account_id <= 0 || !new_mailbox->name) {
+ if (new_mailbox != NULL)
+ EM_DEBUG_EXCEPTION("new_mailbox->account_id[%d], new_mailbox->name[%p]", new_mailbox->account_id, new_mailbox->name);
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ emf_account_t* ref_account = emf_get_account_reference(new_mailbox->account_id);
+
+ if (!ref_account) {
+ EM_DEBUG_EXCEPTION("emf_get_account_reference failed [%d]", new_mailbox->account_id);
+ err = EMF_ERROR_INVALID_ACCOUNT;
+ goto FINISH_OFF;
+ }
+
+ emf_event_t event_data;
+ memset(&event_data, 0x00, sizeof(emf_event_t));
+
+ switch (ref_account->account_bind_type) {
+ case EMF_BIND_TYPE_EM_CORE:
+ /* on_server is allowed to be only 0 when server_type is EMF_SERVER_TYPE_ACTIVE_SYNC */
+ if ( ref_account->receiving_server_type == EMF_SERVER_TYPE_ACTIVE_SYNC )
+ on_server = 0;
+
+ if ( on_server ) { /* async */
+ event_data.type = EMF_EVENT_CREATE_MAILBOX;
+ event_data.account_id = new_mailbox->account_id;
+ event_data.event_param_data_1 = EM_SAFE_STRDUP(new_mailbox->name);
+ event_data.event_param_data_2 = EM_SAFE_STRDUP(new_mailbox->alias);
+ event_data.event_param_data_4 = on_server;
+ event_data.event_param_data_3 = GINT_TO_POINTER(new_mailbox->mailbox_type);
+ if(!em_core_insert_event(&event_data, (int*)handle, &err)) {
+ EM_DEBUG_EXCEPTION("em_core_insert_event failed [%d]", err);
+ goto FINISH_OFF;
+ }
+ }
+ else { /* sync */
+ if (!em_core_mailbox_create(new_mailbox, on_server, &err)) {
+ EM_DEBUG_EXCEPTION("em_core_mailbox_create failed [%d]", err);
+ goto FINISH_OFF;
+ }
+ }
+ break;
+
+ default:
+ EM_DEBUG_EXCEPTION("unknown account bind type...");
+
+ err = EMF_ERROR_INVALID_ACCOUNT;
+ goto FINISH_OFF;
+ }
+
+ ret = true;
+
+FINISH_OFF:
+ if (err_code)
+ *err_code = err;
+ EM_DEBUG_FUNC_END();
+ return ret;
+}
+
+
+EXPORT_API int emf_mailbox_update(emf_mailbox_t* old_mailbox, emf_mailbox_t* new_mailbox, int on_server, unsigned* handle, int* err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("old_mailbox[%p], new_mailbox[%p], on_server[%d], handle[%p], err_code[%p]", old_mailbox, new_mailbox, on_server, handle, err_code);
+
+ /* default variable */
+ int ret = false;;
+ int err = EMF_ERROR_NONE;
+
+ if (!old_mailbox || old_mailbox->account_id <= 0 || !old_mailbox->name
+ || !new_mailbox || new_mailbox->account_id <= 0 || !new_mailbox->name) {
+ EM_DEBUG_EXCEPTION("INVALID PARAM");
+ if (old_mailbox != NULL)
+ EM_DEBUG_EXCEPTION("old_mailbox->account_id[%d], old_mailbox->name[%p]", old_mailbox->account_id, old_mailbox->name);
+ if (new_mailbox != NULL)
+ EM_DEBUG_EXCEPTION("new_mailbox->account_id[%d], new_mailbox->name[%p]", new_mailbox->account_id, new_mailbox->name);
+
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ emf_account_t* ref_account = emf_get_account_reference(old_mailbox->account_id);
+
+ if (!ref_account) {
+ EM_DEBUG_EXCEPTION("emf_get_account_reference failed [%d]", old_mailbox->account_id);
+ err = EMF_ERROR_INVALID_ACCOUNT; /* instead of EMF_ERROR_INVALID_PARAM; */
+ goto FINISH_OFF;
+ }
+
+ emf_event_t event_data;
+ memset(&event_data, 0x00, sizeof(emf_event_t));
+
+ switch (ref_account->account_bind_type) {
+ case EMF_BIND_TYPE_EM_CORE:
+ /* Unsupport sync with server */
+ /* on_server is allowed to be only 0 when server_type is EMF_SERVER_TYPE_ACTIVE_SYNC */
+ /*
+ if ( ref_account->receiving_server_type == EMF_SERVER_TYPE_ACTIVE_SYNC ) {
+ on_server = 0;
+ }
+ if ( on_server ) {
+ event_data.type = EMF_EVENT_UPDATE_MAILBOX;
+ event_data.account_id = new_mailbox->account_id;
+ event_data.event_param_data_1 = ;
+ event_data.event_param_data_2 = ;
+ event_data.event_param_data_4 = on_server;
+ event_data.event_param_data_3 = GINT_TO_POINTER(new_mailbox->mailbox_type);
+ if(!em_core_insert_event(&event_data, handle, &err)) {
+ EM_DEBUG_EXCEPTION("em_core_insert_event failed [%d]", err);
+ goto FINISH_OFF;
+ }
+ }
+ else {
+ if (!em_core_mailbox_modify(old_mailbox, new_mailbox, on_server, &err)) {
+ EM_DEBUG_EXCEPTION("em_core_mailbox_create failed [%d]", err);
+ goto FINISH_OFF;
+ }
+ }
+ */
+ /* Update mailbox information only on local db */
+ if (!em_core_mailbox_update(old_mailbox, new_mailbox, &err)) {
+ EM_DEBUG_EXCEPTION("em_core_mailbox_modify failed [%d]", err);
+ goto FINISH_OFF;
+ }
+ break;
+
+ default:
+ EM_DEBUG_EXCEPTION("unknown account bind type...");
+
+ err = EMF_ERROR_INVALID_ACCOUNT;
+ goto FINISH_OFF;
+ }
+
+ ret = true;
+
+FINISH_OFF:
+ if (err_code)
+ *err_code = err;
+ EM_DEBUG_FUNC_END();
+ return ret;
+}
+
+
+
+EXPORT_API int emf_mailbox_delete(emf_mailbox_t* mailbox, int on_server, unsigned* handle, int* err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("mailbox[%p], err_code[%p]", mailbox, err_code);
+
+ /* default variable */
+ int ret = false;
+ int err = EMF_ERROR_NONE;
+
+ if (!mailbox || mailbox->account_id <= 0) {
+ if (mailbox != NULL)
+ EM_DEBUG_EXCEPTION("mailbox->account_id[%d]", mailbox->account_id);
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ emf_account_t* ref_account = emf_get_account_reference(mailbox->account_id);
+
+
+ if (!ref_account) {
+ EM_DEBUG_EXCEPTION("emf_get_account_reference failed [%d]", mailbox->account_id);
+ err = EMF_ERROR_INVALID_ACCOUNT;
+ goto FINISH_OFF;
+ }
+
+ emf_event_t event_data;
+ memset(&event_data, 0x00, sizeof(emf_event_t));
+
+ switch (ref_account->account_bind_type) {
+ case EMF_BIND_TYPE_EM_CORE:
+ /* on_server is allowed to be only 0 when server_type is EMF_SERVER_TYPE_ACTIVE_SYNC */
+ if ( ref_account->receiving_server_type == EMF_SERVER_TYPE_ACTIVE_SYNC ) {
+ on_server = 0;
+ }
+ if ( on_server ) { /* async */
+ event_data.type = EMF_EVENT_DELETE_MAILBOX;
+ event_data.account_id = mailbox->account_id;
+ event_data.event_param_data_1 = EM_SAFE_STRDUP(mailbox->name);
+ event_data.event_param_data_4 = on_server;
+ if(!em_core_insert_event(&event_data, (int*)handle, &err)) {
+ EM_DEBUG_EXCEPTION("em_core_insert_event failed [%d]", err);
+ goto FINISH_OFF;
+ }
+ }
+
+ else {
+ if (!em_core_mailbox_delete(mailbox, on_server, &err)) {
+ EM_DEBUG_EXCEPTION("em_core_mailbox_delete failed [%d]", err);
+ goto FINISH_OFF;
+ }
+ }
+ break;
+
+ default:
+ EM_DEBUG_EXCEPTION("unknown account bind type...");
+ err = EMF_ERROR_INVALID_ACCOUNT;
+ goto FINISH_OFF;
+ }
+
+ ret = true;
+
+FINISH_OFF:
+ if (err_code)
+ *err_code = err;
+ EM_DEBUG_FUNC_END();
+ return ret;
+}
+
+EXPORT_API int
+emf_mailbox_delete_all(emf_mailbox_t* mailbox, int* err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("malibox[%p], err_code[%p]", mailbox, err_code);
+
+ /* default variable */
+ int ret = false;
+ int err = EMF_ERROR_NONE;
+
+ if (!mailbox || mailbox->account_id <= 0) {
+ if (mailbox == NULL)
+ EM_DEBUG_EXCEPTION("malibox->account_id[%d]", mailbox->account_id);
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ emf_account_t* ref_account = emf_get_account_reference(mailbox->account_id);
+
+
+ if (!ref_account) {
+ EM_DEBUG_EXCEPTION("emf_get_account_reference failed [%d]", mailbox->account_id);
+ err = EMF_ERROR_INVALID_ACCOUNT;
+ goto FINISH_OFF;
+ }
+
+ switch (ref_account->account_bind_type) {
+ case EMF_BIND_TYPE_EM_CORE:
+ if (!em_core_mailbox_delete_all(mailbox, &err)) {
+ EM_DEBUG_EXCEPTION("em_core_mailbox_delete_all failed [%d]", err);
+ goto FINISH_OFF;
+ }
+ break;
+
+ default:
+ EM_DEBUG_EXCEPTION("unknown account bind type...");
+ err = EMF_ERROR_INVALID_ACCOUNT;
+ goto FINISH_OFF;
+ }
+
+ ret = true;
+
+FINISH_OFF:
+ if (err_code)
+ *err_code = err;
+ EM_DEBUG_FUNC_END();
+ return ret;
+}
+
+
+
+EXPORT_API int emf_mailbox_free(emf_mailbox_t** mailbox_list, int count, int* err_code)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ return em_core_mailbox_free(mailbox_list, count, err_code);
+}
+
+
+EXPORT_API int emf_mailbox_sync_header(emf_mailbox_t* mailbox, unsigned* handle, int* err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("mailbox[%p], handle[%p], err_code[%p]", mailbox, handle, err_code);
+
+ /* default variable */
+ int ret = false;
+ int err = EMF_ERROR_NONE;
+
+ if (!mailbox ) {
+ EM_DEBUG_EXCEPTION("mailbox[%p]", mailbox);
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+ emf_event_t event_data;
+ emf_account_t* ref_account = NULL;
+
+ memset(&event_data, 0x00, sizeof(emf_event_t));
+
+ if(mailbox->account_id == ALL_ACCOUNT) {
+ EM_DEBUG_LOG(">>>> emf_mailbox_sync_header for all account event_data.event_param_data_4 [%d]", event_data.event_param_data_4);
+ event_data.type = EMF_EVENT_SYNC_HEADER;
+ event_data.event_param_data_1 = mailbox ? EM_SAFE_STRDUP(mailbox->name) : NULL;
+ event_data.event_param_data_3 = NULL;
+ event_data.account_id = mailbox->account_id;
+ /* In case of Mailbox NULL, we need to set arg as EMF_SYNC_ALL_MAILBOX */
+ if (!event_data.event_param_data_1)
+ event_data.event_param_data_4 = EMF_SYNC_ALL_MAILBOX;
+
+ if (!em_core_insert_event(&event_data, (int*)handle, &err)) {
+ EM_DEBUG_EXCEPTION("em_core_insert_event falied [%d]", err);
+ goto FINISH_OFF;
+ }
+ }
+ else {
+
+ if (!(ref_account = emf_get_account_reference(mailbox->account_id))) {
+ EM_DEBUG_EXCEPTION("emf_get_account_reference failed [%d]", mailbox->account_id);
+ err = EMF_ERROR_INVALID_ACCOUNT;
+ goto FINISH_OFF;
+ }
+
+ /* Modified the code to sync all mailbox in a Single Event */
+ switch (ref_account->account_bind_type) {
+ case EMF_BIND_TYPE_EM_CORE:
+ event_data.type = EMF_EVENT_SYNC_HEADER;
+ event_data.event_param_data_1 = mailbox ? EM_SAFE_STRDUP(mailbox->name) : NULL;
+ event_data.event_param_data_3 = NULL;
+ event_data.account_id = mailbox->account_id;
+ /* In case of Mailbox NULL, we need to set arg as EMF_SYNC_ALL_MAILBOX */
+ if (!event_data.event_param_data_1)
+ event_data.event_param_data_4 = EMF_SYNC_ALL_MAILBOX;
+ EM_DEBUG_LOG(">>>> EVENT ARG [ %d ] ", event_data.event_param_data_4);
+
+ if (!em_core_insert_event(&event_data, (int*)handle, &err)) {
+ EM_DEBUG_EXCEPTION("em_core_insert_event falied [%d]", err);
+ goto FINISH_OFF;
+ }
+ break;
+
+ default:
+ EM_DEBUG_EXCEPTION("unknown account bind type...");
+ err = EMF_ERROR_INVALID_ACCOUNT;
+ goto FINISH_OFF;
+ }
+ }
+
+#ifdef __LOCAL_ACTIVITY__
+ EM_DEBUG_LOG("Setting g_local_activity_run ");
+ g_local_activity_run = 1;
+#endif
+
+ ret = true;
+
+FINISH_OFF:
+ if (err_code)
+ *err_code = err;
+ EM_DEBUG_FUNC_END();
+ return ret;
+}
+
+EXPORT_API int
+emf_mailbox_set_mail_slot_size(int account_id, char* mailbox_name, int new_slot_size, unsigned* handle, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("account_id [%d], mailbox_name[%p], handle[%p], err_code[%p]", account_id, mailbox_name, handle, err_code);
+
+ int ret = false;
+ int err = EMF_ERROR_NONE;
+ emf_event_t event_data;
+
+ if(handle == NULL) {
+ EM_DEBUG_EXCEPTION("handle is required");
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ memset(&event_data, 0x00, sizeof(emf_event_t));
+
+ event_data.type = EMF_EVENT_SET_MAIL_SLOT_SIZE;
+ event_data.event_param_data_4 = new_slot_size;
+ event_data.event_param_data_3 = EM_SAFE_STRDUP(mailbox_name);
+ event_data.account_id = account_id;
+
+ if (!em_core_insert_event(&event_data, (int*)handle, &err)) {
+ EM_DEBUG_EXCEPTION("em_core_insert_event falied [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ ret = true;
+
+FINISH_OFF:
+ if (err_code)
+ *err_code = err;
+ EM_DEBUG_FUNC_END();
+ return ret;
+}
+
diff --git a/email-engine/main.c b/email-engine/main.c
new file mode 100755
index 0000000..f7abb94
--- /dev/null
+++ b/email-engine/main.c
@@ -0,0 +1,3593 @@
+/*
+* email-service
+*
+* Copyright (c) 2000 - 2011 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 service Main .c */
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <malloc.h>
+#include <glib.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <heynoti/heynoti.h>
+#include <signal.h>
+#include <time.h>
+
+#include "emflib.h"
+#include "Emf_Mapi.h"
+#include "Msg_Convert.h"
+#include "ipc-library.h"
+#include "emf-dbglog.h"
+#include "emf-auto-poll.h"
+#include "emf-account.h"
+#include "em-core-types.h"
+#include "em-core-account.h"
+#include "em-core-mesg.h"
+#include "em-core-event.h"
+#include "em-core-global.h"
+#include "em-core-mailbox.h"
+#include "em-core-utils.h"
+#include "em-storage.h"
+#include "db-util.h"
+#include "emf-emn-noti.h"
+#include "emf-emn-storage.h"
+
+void stb_account_create(HIPC_API a_hAPI)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int buffer_size = 0;
+ int local_result = 0;
+ char* local_account_stream = NULL;
+ emf_account_t account;
+ int err = EMF_ERROR_NONE;
+
+ buffer_size = ipcEmailAPI_GetParameterLength(a_hAPI, ePARAMETER_IN, 0);
+ EM_DEBUG_LOG("size [%d]", buffer_size);
+
+ if(buffer_size <= 0) {
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ local_account_stream = (char*)em_core_malloc(buffer_size+1);
+ if(!local_account_stream) {
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ memcpy(local_account_stream, ipcEmailAPI_GetParameter(a_hAPI, ePARAMETER_IN, 0), buffer_size);
+ /* Convert account stream to structure */
+ EM_DEBUG_LOG("Before Convert_ByteStream_To_Account");
+ em_convert_byte_stream_to_account(local_account_stream, &account);
+ EM_SAFE_FREE(local_account_stream);
+
+ if (account.account_name)
+ EM_DEBUG_LOG("Account name - %s", account.account_name);
+ if(account.email_addr)
+ EM_DEBUG_LOG("Email Address - %s", account.email_addr);
+
+ if(!emf_account_create(&account, &err)) {
+ EM_DEBUG_EXCEPTION("emf_account_create fail ");
+ goto FINISH_OFF;
+ }
+
+#ifdef __FEATURE_AUTO_POLLING__
+ /* start auto polling, if check_interval not zero */
+ if(account.check_interval > 0) {
+ if(!emf_add_polling_alarm( account.account_id,account.check_interval))
+ EM_DEBUG_EXCEPTION("emf_add_polling_alarm[NOTI_ACCOUNT_ADD] : start auto poll failed >>> ");
+ }
+#endif
+ /* add account details to contact DB */
+ emf_account_insert_accountinfo_to_contact(&account);
+ local_result = 1;
+ if(!ipcEmailAPI_AddParameter(a_hAPI, ePARAMETER_OUT, &local_result, sizeof(int)))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed ");
+
+ EM_DEBUG_LOG("[3] APPID[%d], APIID [%d]", ipcEmailAPI_GetAPPID(a_hAPI), ipcEmailAPI_GetAPIID(a_hAPI));
+ EM_DEBUG_LOG("account id[%d]", account.account_id);
+
+ if(!ipcEmailAPI_AddParameter(a_hAPI, ePARAMETER_OUT, &(account.account_id), sizeof(int)))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed ");
+ if (!ipcEmailStub_ExecuteAPI(a_hAPI))
+ EM_DEBUG_EXCEPTION("ipcEmailStub_ExecuteAPI failed ");
+
+FINISH_OFF:
+ if ( local_result == 0 ) {
+ if(!ipcEmailAPI_AddParameter(a_hAPI, ePARAMETER_OUT, &local_result, sizeof(int)))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed : local_result ");
+ if(!ipcEmailAPI_AddParameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed : err");
+ if (!ipcEmailStub_ExecuteAPI(a_hAPI))
+ EM_DEBUG_EXCEPTION("ipcEmailStub_ExecuteAPI failed ");
+ }
+ EM_DEBUG_FUNC_END();
+}
+
+void stb_account_delete(HIPC_API a_hAPI)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int account_id = 0;
+ int local_result = 0;
+ int err = EMF_ERROR_NONE;
+
+ /* account_id */
+ memcpy(&account_id, ipcEmailAPI_GetParameter(a_hAPI, ePARAMETER_IN, 0), sizeof(int));;
+ if(!emf_account_delete(account_id, &err)) {
+ if(!ipcEmailAPI_AddParameter(a_hAPI, ePARAMETER_OUT, &local_result, sizeof(int)))
+ EM_DEBUG_LOG("ipcEmailAPI_AddParameter failed ");
+ if(!ipcEmailAPI_AddParameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed");
+
+ if (!ipcEmailStub_ExecuteAPI(a_hAPI))
+ EM_DEBUG_EXCEPTION("ipcEmailStub_ExecuteAPI failed ");
+ goto FINISH_OFF;
+ }
+
+#ifdef __FEATURE_AUTO_POLLING__
+ /* stop auto polling for this acount */
+ if(is_auto_polling_started(account_id)) {
+ if(!emf_remove_polling_alarm(account_id))
+ EM_DEBUG_EXCEPTION("emf_remove_polling_alarm[ NOTI_ACCOUNT_DELETE] : remove auto poll failed >>> ");
+ }
+#endif
+ local_result = 1;
+
+ if(!ipcEmailAPI_AddParameter(a_hAPI, ePARAMETER_OUT, &local_result, sizeof(int)))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed ");
+
+ if (!ipcEmailStub_ExecuteAPI(a_hAPI))
+ EM_DEBUG_EXCEPTION("ipcEmailStub_ExecuteAPI failed");
+
+FINISH_OFF:
+
+ EM_DEBUG_FUNC_END();
+}
+
+void stb_account_update(HIPC_API a_hAPI)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int account_id = 0, buffer_size = 0, local_result = 0, with_validation = 0;
+ char* AccountStream = NULL;
+ emf_account_t *new_account_info = NULL;
+ int err = EMF_ERROR_NONE;
+ unsigned int handle = 0;
+
+ /* filter_id */
+ memcpy(&account_id, ipcEmailAPI_GetParameter(a_hAPI, ePARAMETER_IN, 0), sizeof(int));;
+
+ buffer_size = ipcEmailAPI_GetParameterLength(a_hAPI, ePARAMETER_IN, 1);
+ EM_DEBUG_LOG("size [%d]", buffer_size);
+
+ if(buffer_size > 0) {
+ AccountStream = (char*)em_core_malloc(buffer_size+1);
+ if(AccountStream) {
+ memcpy(AccountStream, ipcEmailAPI_GetParameter(a_hAPI, ePARAMETER_IN, 1), buffer_size);
+ /* Convert Byte stream to account structure */
+ EM_DEBUG_LOG("Before Convert_ByteStream_To_account");
+ new_account_info = (emf_account_t*)em_core_malloc(sizeof(emf_account_t));
+
+ if(NULL == new_account_info) {
+ EM_SAFE_FREE(AccountStream);
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+ em_convert_byte_stream_to_account(AccountStream, new_account_info);
+ EM_SAFE_FREE(AccountStream);
+ }
+ else {
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ memcpy(&with_validation, ipcEmailAPI_GetParameter(a_hAPI, ePARAMETER_IN, 2), sizeof(int));
+ }
+
+ if ( NULL == new_account_info ) {
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ emf_account_t *old_account_info = NULL;
+
+ if(!emf_account_get(account_id, GET_FULL_DATA, &old_account_info, &err)) {
+ EM_DEBUG_EXCEPTION("emf_account_get failed ");
+ goto FINISH_OFF;
+ }
+
+ if(new_account_info->password == NULL || (new_account_info->password != NULL && strlen(new_account_info->password) == 0) ) {
+ EM_SAFE_FREE(new_account_info->password);
+ if(old_account_info->password) {
+ new_account_info->password = strdup(old_account_info->password);
+ if(new_account_info->password == NULL) {
+ EM_DEBUG_EXCEPTION("allocation for new_account_info->password failed");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+ }
+ }
+
+ if(new_account_info->sending_password == NULL || (new_account_info->sending_password != NULL && strlen(new_account_info->sending_password) == 0) ) {
+ if(new_account_info->sending_password != NULL)
+ free(new_account_info->sending_password);
+ if(old_account_info->sending_password) {
+ new_account_info->sending_password = strdup(old_account_info->sending_password);
+ if(new_account_info->sending_password == NULL) {
+ EM_DEBUG_EXCEPTION("allocation for new_account_info->sending_password failed");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+ }
+ }
+
+
+ if(with_validation) {
+ emf_account_validate_and_update(account_id, new_account_info, &handle, &err);
+ local_result = 1;
+ }
+ else {
+ if(emf_account_modify(account_id, new_account_info, &err)) {
+#ifdef __FEATURE_AUTO_POLLING__
+ int old_check_interval = old_account_info->check_interval;
+ if( old_check_interval == 0 && new_account_info->check_interval > 0) {
+ if(!emf_add_polling_alarm( account_id,new_account_info->check_interval))
+ EM_DEBUG_EXCEPTION("emf_add_polling_alarm[ CHANGEACCOUNT] : start auto poll failed >>> ");
+
+ }
+ else if( (old_check_interval > 0) && (new_account_info->check_interval == 0)) {
+ if(!emf_remove_polling_alarm(account_id))
+ EM_DEBUG_EXCEPTION("emf_remove_polling_alarm[ CHANGEACCOUNT] : start auto poll failed >>> ");
+ }
+ else if(old_check_interval != new_account_info->check_interval) {
+ if(!emf_remove_polling_alarm(account_id)) {
+ EM_DEBUG_EXCEPTION("emf_remove_polling_alarm[ CHANGEACCOUNT] : start auto poll failed >>> ");
+ goto FINISH_OFF;
+ }
+ if(!emf_add_polling_alarm( account_id,new_account_info->check_interval))
+ EM_DEBUG_EXCEPTION("emf_add_polling_alarm[ CHANGEACCOUNT] : start auto poll failed >>> ");
+ }
+#endif
+ emf_account_update_accountinfo_to_contact(old_account_info,new_account_info);
+ local_result = 1;
+ }
+ else {
+ EM_DEBUG_EXCEPTION("emf_account_modify failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ }
+
+ if(!ipcEmailAPI_AddParameter(a_hAPI, ePARAMETER_OUT, &local_result, sizeof(int)))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter for result failed");
+
+ if(with_validation) {
+ if(!ipcEmailAPI_AddParameter(a_hAPI, ePARAMETER_OUT, &handle, sizeof(int)))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter for handle failed");
+ }
+
+ if (!ipcEmailStub_ExecuteAPI(a_hAPI))
+ EM_DEBUG_EXCEPTION("ipcEmailStub_ExecuteAPI failed");
+
+FINISH_OFF:
+ if ( local_result == 0 ) {
+ if(!ipcEmailAPI_AddParameter(a_hAPI, ePARAMETER_OUT, &local_result, sizeof(int)))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed");
+
+ if(!ipcEmailAPI_AddParameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed");
+
+ if (!ipcEmailStub_ExecuteAPI(a_hAPI))
+ EM_DEBUG_EXCEPTION("ipcEmailStub_ExecuteAPI failed");
+ }
+ EM_SAFE_FREE(new_account_info);
+ EM_SAFE_FREE(old_account_info);
+ EM_DEBUG_FUNC_END();
+}
+
+void stb_account_validate(HIPC_API a_hAPI)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ int account_id = 0;
+ int local_result = 0;
+ int err_code = 0;
+ int handle = 0;
+
+ /* account_id */
+ memcpy(&account_id, ipcEmailAPI_GetParameter(a_hAPI, ePARAMETER_IN, 0), sizeof(int));;
+ local_result = emf_account_validate(account_id, (unsigned*)&handle,&err_code);
+
+ if(!ipcEmailAPI_AddParameter(a_hAPI, ePARAMETER_OUT, &local_result, sizeof(int)))
+ EM_DEBUG_LOG("ipcEmailAPI_AddParameter failed ");
+
+ if(!ipcEmailAPI_AddParameter(a_hAPI, ePARAMETER_OUT, &err_code, sizeof(int)))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed ");
+
+ if(!ipcEmailAPI_AddParameter(a_hAPI, ePARAMETER_OUT, &handle, sizeof(int)))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter result failed ");
+
+ if (!ipcEmailStub_ExecuteAPI(a_hAPI))
+ EM_DEBUG_EXCEPTION("ipcEmailStub_ExecuteAPI failed ");
+
+ EM_DEBUG_FUNC_END();
+}
+
+void stb_account_get_refer(HIPC_API a_hAPI)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int local_result = 0;
+ int account_id = 0;
+ emf_account_t* account = NULL;
+ char* local_stream = NULL;
+ int size = 0;
+
+ EM_DEBUG_LOG("account_id");
+ memcpy(&account_id, ipcEmailAPI_GetParameter(a_hAPI, ePARAMETER_IN, 0), sizeof(int));
+
+ account = emf_get_account_reference(account_id);
+ if(account != NULL) {
+ EM_DEBUG_LOG("emf_get_account_reference success");
+ local_result = 1;
+
+ /* result */
+ if(!ipcEmailAPI_AddParameter(a_hAPI, ePARAMETER_OUT, &local_result, sizeof(int)))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter local_result failed ");
+
+ /* Address */
+ local_stream = em_convert_account_to_byte_stream(account, &size);
+
+ EM_NULL_CHECK_FOR_VOID(local_stream);
+
+ if(!ipcEmailAPI_AddParameter(a_hAPI, ePARAMETER_OUT, local_stream, size))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed");
+
+ if (!ipcEmailStub_ExecuteAPI(a_hAPI)) {
+ EM_DEBUG_EXCEPTION("ipcEmailStub_ExecuteAPI failed");
+ EM_SAFE_FREE(local_stream);
+ return;
+ }
+
+ }
+ else {
+ EM_DEBUG_LOG("emf_get_account_reference failed");
+ if(!ipcEmailAPI_AddParameter(a_hAPI, ePARAMETER_OUT, &local_result, sizeof(int)))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter local_result failed ");
+ if (!ipcEmailStub_ExecuteAPI(a_hAPI)) {
+ EM_DEBUG_EXCEPTION("ipcEmailStub_ExecuteAPI failed ");
+ EM_SAFE_FREE(local_stream);
+ return;
+ }
+ }
+
+ EM_SAFE_FREE(local_stream);
+ EM_DEBUG_FUNC_END();
+}
+
+void stb_account_get_list(HIPC_API a_hAPI)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ int local_result = 0;
+ int counter = 0;
+ char* local_stream = NULL;
+ emf_account_t* account_list;
+ int count;
+ int size = 0;
+ int err = EMF_ERROR_NONE;
+
+ EM_DEBUG_LOG("begin");
+
+ if(emf_account_get_list(&account_list, &count, &err)) {
+ EM_DEBUG_LOG("emf_account_get_list success");
+ local_result = 1;
+ if(!ipcEmailAPI_AddParameter(a_hAPI, ePARAMETER_OUT, &local_result, sizeof(int)))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter local_result failed ");
+
+ EM_DEBUG_LOG("Count [%d]", count);
+ if(!ipcEmailAPI_AddParameter(a_hAPI, ePARAMETER_OUT, &count, sizeof(int)))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter count failed ");
+
+ for(counter=0; counter<count; counter++) {
+ EM_DEBUG_LOG("Name - %s", account_list[counter].account_name);
+
+ local_stream = em_convert_account_to_byte_stream(account_list+counter, &size);
+
+ EM_NULL_CHECK_FOR_VOID(local_stream);
+
+ if(!ipcEmailAPI_AddParameter(a_hAPI, ePARAMETER_OUT, local_stream, size))
+ EM_DEBUG_EXCEPTION("Add Param mailbox failed ");
+
+ size = 0;
+ EM_SAFE_FREE(local_stream);
+ }
+
+ emf_account_free(&account_list, count, NULL);
+ if (!ipcEmailStub_ExecuteAPI(a_hAPI))
+ EM_DEBUG_EXCEPTION("ipcEmailStub_ExecuteAPI failed ");
+ }
+
+ else {
+ EM_DEBUG_LOG("emf_account_get_list failed");
+ if(!ipcEmailAPI_AddParameter(a_hAPI, ePARAMETER_OUT, &local_result, sizeof(int)))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter local_result failed ");
+ if(!ipcEmailAPI_AddParameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed : err");
+ if (!ipcEmailStub_ExecuteAPI(a_hAPI))
+ EM_DEBUG_EXCEPTION("ipcEmailStub_ExecuteAPI failed ");
+ }
+
+ EM_SAFE_FREE(local_stream);
+ EM_DEBUG_FUNC_END();
+}
+
+void stb_modify_mail_flag(HIPC_API a_hAPI)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int err = EMF_ERROR_NONE;
+ int mail_id = 0;
+ int i_flag = 0;
+ int onserver = 0;
+ int sticky_flag = 0;
+ emf_mail_flag_t new_flag = { 0 };
+
+ EM_DEBUG_LOG("mail_id");
+ memcpy(&mail_id, ipcEmailAPI_GetParameter(a_hAPI, ePARAMETER_IN, 0), sizeof(int));
+ EM_DEBUG_LOG("mail_id[%d]", mail_id);
+
+ EM_DEBUG_LOG("i_flag");
+ memcpy(&i_flag, ipcEmailAPI_GetParameter(a_hAPI, ePARAMETER_IN, 1), sizeof(int));
+ EM_DEBUG_LOG("i_flag[%d]", i_flag);
+
+ EM_DEBUG_LOG("Sticky flag");
+ memcpy(&sticky_flag, ipcEmailAPI_GetParameter(a_hAPI, ePARAMETER_IN, 2), sizeof(int));
+ EM_DEBUG_LOG(">>> STICKY flag Value [ %d] ", sticky_flag);
+
+ EM_DEBUG_LOG("onserver");
+ memcpy(&onserver, ipcEmailAPI_GetParameter(a_hAPI, ePARAMETER_IN, 3), sizeof(int));
+ EM_DEBUG_LOG("onserver[%d]", onserver);
+
+ EM_DEBUG_LOG("Flag Change 1>>> ");
+ if(!em_convert_mail_int_to_flag(i_flag, &new_flag, &err)) {
+ EM_DEBUG_EXCEPTION("em_convert_mail_int_to_flag failed");
+ return;
+ }
+ if(emf_mail_modify_flag(mail_id, new_flag, onserver, sticky_flag, &err))
+ EM_DEBUG_LOG("emf_mail_modify_flag - success");
+ if(!ipcEmailAPI_AddParameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter local_result failed ");
+ if (!ipcEmailStub_ExecuteAPI(a_hAPI))
+ EM_DEBUG_EXCEPTION("ipcEmailStub_ExecuteAPI failed ");
+ EM_DEBUG_FUNC_END();
+}
+
+void stb_modify_mail_extra_flag(HIPC_API a_hAPI)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int err = EMF_ERROR_NONE;
+ int mail_id = 0;
+ int buffer_size = 0;
+ emf_extra_flag_t new_flag= { 0 };
+ char* local_stream = NULL;
+
+ EM_DEBUG_LOG("mail_id");
+ memcpy(&mail_id, ipcEmailAPI_GetParameter(a_hAPI, ePARAMETER_IN, 0), sizeof(int));
+
+ EM_DEBUG_LOG("extra_flag");
+ buffer_size = ipcEmailAPI_GetParameterLength(a_hAPI, ePARAMETER_IN, 1);
+
+ if(buffer_size > 0) {
+ local_stream = (char*)em_core_malloc(buffer_size+1);
+ EM_NULL_CHECK_FOR_VOID(local_stream);
+ if(local_stream) {
+ memcpy(local_stream, ipcEmailAPI_GetParameter(a_hAPI, ePARAMETER_IN, 1), buffer_size);
+ em_convert_byte_stream_to_extra_flags(local_stream, &new_flag);
+ EM_SAFE_FREE(local_stream);
+ }
+
+ if(emf_mail_modify_extra_flag(mail_id, new_flag, &err))
+ EM_DEBUG_LOG("emf_mail_modify_extra_flag - success");
+
+ if(!ipcEmailAPI_AddParameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter local_result failed ");
+
+ if (!ipcEmailStub_ExecuteAPI(a_hAPI))
+ EM_DEBUG_EXCEPTION("ipcEmailStub_ExecuteAPI failed ");
+
+ }
+ EM_DEBUG_FUNC_END();
+}
+
+
+void stb_mail_save_to_mailbox(HIPC_API a_hAPI)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int buffer_size = 0;
+ int local_result = 0;
+ char* local_head_stream = NULL;
+ char* local_body_stream = NULL;
+ char* local_info_stream = NULL;
+ char* local_stream = NULL;
+ int from_composer = 0;
+ emf_mail_t *mail = NULL;
+ emf_mailbox_t *mailbox = NULL;
+ int err = EMF_ERROR_NONE;
+ emf_meeting_request_t *meeting_req = NULL;
+
+ EM_DEBUG_LOG("head");
+
+ mail = (emf_mail_t*)em_core_malloc(sizeof(emf_mail_t));
+
+ if(mail == NULL) {
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ buffer_size = ipcEmailAPI_GetParameterLength(a_hAPI, ePARAMETER_IN, 0);
+
+ if(buffer_size > 0) {
+ local_head_stream = (char*)em_core_malloc(buffer_size+1);
+ if(local_head_stream) {
+ memcpy(local_head_stream, ipcEmailAPI_GetParameter(a_hAPI, ePARAMETER_IN, 0), buffer_size);
+ mail->head = (emf_mail_head_t*)em_core_malloc(sizeof(emf_mail_head_t));
+
+ if(NULL == mail->head) {
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+ em_convert_byte_stream_to_mail_head(local_head_stream, mail->head);
+ }
+ else {
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+ }
+
+ EM_DEBUG_LOG("Body - mod");
+ buffer_size = ipcEmailAPI_GetParameterLength(a_hAPI, ePARAMETER_IN, 1);
+
+ if(buffer_size > 0) {
+ local_body_stream = (char*)em_core_malloc(buffer_size+1);
+ if(local_body_stream) {
+ memcpy(local_body_stream, ipcEmailAPI_GetParameter(a_hAPI, ePARAMETER_IN, 1), buffer_size);
+ mail->body = (emf_mail_body_t*)em_core_malloc(sizeof(emf_mail_body_t));
+
+ if(NULL == mail->body) {
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+ em_convert_byte_stream_to_mail_body(local_body_stream, mail->body);
+ }
+ else {
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+ }
+
+ EM_DEBUG_LOG("Info");
+
+ buffer_size = ipcEmailAPI_GetParameterLength(a_hAPI, ePARAMETER_IN, 2);
+
+ if(buffer_size > 0) {
+ local_info_stream = (char*)em_core_malloc(buffer_size+1);
+ if(local_info_stream) {
+ memcpy(local_info_stream, ipcEmailAPI_GetParameter(a_hAPI, ePARAMETER_IN, 2), buffer_size);
+ mail->info = (emf_mail_info_t*)em_core_malloc(sizeof(emf_mail_info_t));
+
+ if(NULL == mail->info) {
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+ em_convert_byte_stream_to_mail_info(local_info_stream, mail->info);
+ }
+ else {
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+ }
+
+ EM_DEBUG_LOG("mailbox");
+ buffer_size = ipcEmailAPI_GetParameterLength(a_hAPI, ePARAMETER_IN, 3);
+
+ if(buffer_size > 0) {
+ local_stream = (char*)em_core_malloc(buffer_size+1);
+ if(local_stream) {
+ memcpy(local_stream, ipcEmailAPI_GetParameter(a_hAPI, ePARAMETER_IN, 3), buffer_size);
+ mailbox = (emf_mailbox_t*)em_core_malloc(sizeof(emf_mailbox_t));
+ if(!mailbox) {
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+ em_convert_byte_stream_to_mailbox(local_stream, mailbox);
+ }
+ else {
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+ }
+
+ EM_DEBUG_LOG("from_composer");
+ memcpy(&from_composer, ipcEmailAPI_GetParameter(a_hAPI, ePARAMETER_IN, 4), sizeof(int));
+
+ EM_DEBUG_LOG("calling emf_mail_save_to_mailbox");
+
+ if ( mail->info->is_meeting_request == EMF_MAIL_TYPE_MEETING_REQUEST
+ || mail->info->is_meeting_request == EMF_MAIL_TYPE_MEETING_RESPONSE
+ || mail->info->is_meeting_request == EMF_MAIL_TYPE_MEETING_ORIGINATINGREQUEST) {
+ buffer_size = ipcEmailAPI_GetParameterLength(a_hAPI, ePARAMETER_IN, 5);
+
+ if(buffer_size > 0) {
+ local_stream = (char*)em_core_malloc(buffer_size+1);
+ if(local_stream) {
+ memcpy(local_stream, ipcEmailAPI_GetParameter(a_hAPI, ePARAMETER_IN, 5), buffer_size);
+ meeting_req = (emf_meeting_request_t*)em_core_malloc(sizeof(emf_meeting_request_t));
+ if(meeting_req) {
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+ em_convert_byte_stream_to_meeting_req(local_stream, meeting_req);
+ }
+ else {
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+ }
+ }
+
+ EM_DEBUG_LOG("calling emf_mail_save_to_mailbox with meeting request");
+ if(emf_mail_save_to_mailbox(mail, mailbox, meeting_req, from_composer, &err)) { /* successfully saving */
+ local_result = 1;
+ if(!ipcEmailAPI_AddParameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter result failed ");
+ if(!ipcEmailAPI_AddParameter(a_hAPI, ePARAMETER_OUT, &(mail->info->uid), sizeof(int)))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter mail_idFail ");
+ if (!ipcEmailStub_ExecuteAPI(a_hAPI))
+ EM_DEBUG_EXCEPTION("ipcEmailStub_ExecuteAPI failed ");
+ }
+
+FINISH_OFF:
+ if ( local_result == 0 ) {
+ if(!ipcEmailAPI_AddParameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed ");
+ if (!ipcEmailStub_ExecuteAPI(a_hAPI))
+ EM_DEBUG_EXCEPTION("ipcEmailStub_ExecuteAPI failed ");
+ }
+
+ EM_SAFE_FREE(local_head_stream);
+ EM_SAFE_FREE(local_body_stream);
+ EM_SAFE_FREE(local_info_stream);
+ EM_SAFE_FREE(local_stream);
+
+ if(mail)
+ em_core_mail_free(&mail, 1, &err);
+
+ if(mailbox)
+ em_core_mailbox_free(&mailbox, 1, &err);
+
+ em_core_flush_memory();
+ EM_DEBUG_FUNC_END();
+}
+
+void stb_mail_get_mailbox_count(HIPC_API a_hAPI)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int buffer_size = 0;
+ int local_result = 0;
+ char* local_stream = NULL;
+ emf_mailbox_t mailbox;
+ int total_count = 0;
+ int unseen= 0;
+
+ EM_DEBUG_LOG("mailbox");
+ buffer_size = ipcEmailAPI_GetParameterLength(a_hAPI, ePARAMETER_IN, 0);
+
+ if(buffer_size > 0) {
+ local_stream = (char*)em_core_malloc(buffer_size+1);
+ if(!local_stream) {
+ EM_DEBUG_EXCEPTION("EMF_ERROR_OUT_OF_MEMORY");
+ goto FINISH_OFF;
+ }
+ memcpy(local_stream, ipcEmailAPI_GetParameter(a_hAPI, ePARAMETER_IN, 0), buffer_size);
+ em_convert_byte_stream_to_mailbox(local_stream, &mailbox);
+ EM_SAFE_FREE(local_stream);
+ }
+
+ /*get the Mailbox Count */
+ if (!emf_mailbox_get_mail_count(&mailbox, &total_count, &unseen, NULL)) {
+ EM_DEBUG_EXCEPTION("emf_mailbox_get_mail_count - failed");
+ goto FINISH_OFF;
+ }
+ else {
+ EM_DEBUG_LOG("emf_mailbox_get_mail_count - success");
+ local_result = 1;
+ }
+
+FINISH_OFF:
+
+ if(local_result) {
+ if(!ipcEmailAPI_AddParameter(a_hAPI, ePARAMETER_OUT, &local_result, sizeof(int)))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter local_result failed ");
+
+ /* Totol count of mails */
+ if(!ipcEmailAPI_AddParameter(a_hAPI, ePARAMETER_OUT, &total_count, sizeof(int)))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed ");
+
+ /* Unread Mail */
+ if(!ipcEmailAPI_AddParameter(a_hAPI, ePARAMETER_OUT, &unseen, sizeof(int)))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed ");
+
+ if (!ipcEmailStub_ExecuteAPI(a_hAPI))
+ EM_DEBUG_EXCEPTION("ipcEmailStub_ExecuteAPI failed ");
+ }
+ else {
+ if(!ipcEmailAPI_AddParameter(a_hAPI, ePARAMETER_OUT, &local_result, sizeof(int)))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter local_result failed ");
+ if (!ipcEmailStub_ExecuteAPI(a_hAPI))
+ EM_DEBUG_EXCEPTION("ipcEmailStub_ExecuteAPI failed");
+ }
+
+ EM_DEBUG_FUNC_END();
+}
+
+
+/* sowmya.kr, 10-May-2010, changes for API improvement */
+void stb_mailbox_sync_header(HIPC_API a_hAPI)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int buffer_size = 0;
+ int err = EMF_ERROR_NONE;
+ char* local_stream = NULL;
+ emf_mailbox_t mailbox, *pointer_mailbox = NULL;
+ int handle = -1;
+
+ EM_DEBUG_LOG("mailbox");
+ buffer_size = ipcEmailAPI_GetParameterLength(a_hAPI, ePARAMETER_IN, 0);
+
+ if(buffer_size > 0) {
+ local_stream = (char*)em_core_malloc(buffer_size+1);
+ EM_NULL_CHECK_FOR_VOID(local_stream);
+ if(!local_stream) {
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+ memcpy(local_stream, ipcEmailAPI_GetParameter(a_hAPI, ePARAMETER_IN, 0), buffer_size);
+ em_convert_byte_stream_to_mailbox(local_stream, &mailbox);
+ EM_SAFE_FREE(local_stream);
+ pointer_mailbox = &mailbox;
+ }
+
+ if(emf_mailbox_sync_header(pointer_mailbox, (unsigned*)&handle, &err)) {
+ EM_DEBUG_LOG("emf_mailbox_sync_header success ");
+ }
+
+FINISH_OFF:
+ if(!ipcEmailAPI_AddParameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed ");
+ if(!ipcEmailAPI_AddParameter(a_hAPI, ePARAMETER_OUT, &handle, sizeof(int)))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed ");
+ if (!ipcEmailStub_ExecuteAPI(a_hAPI))
+ EM_DEBUG_EXCEPTION("ipcEmailStub_ExecuteAPI failed ");
+ EM_DEBUG_FUNC_END();
+}
+
+void stb_mailbox_download_body(HIPC_API a_hAPI)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int buffer_size = 0;
+ int err = EMF_ERROR_NONE;
+ char* local_stream = NULL;
+ emf_mailbox_t mailbox;
+ int mail_id = 0;
+ int has_attachment = 0;
+ unsigned int handle = 0;
+
+ buffer_size = ipcEmailAPI_GetParameterLength(a_hAPI, ePARAMETER_IN, 0);
+
+ if(buffer_size > 0) {
+ local_stream = (char*)em_core_malloc(buffer_size+1);
+ EM_NULL_CHECK_FOR_VOID(local_stream);
+ if(local_stream) {
+ memcpy(local_stream, ipcEmailAPI_GetParameter(a_hAPI, ePARAMETER_IN, 0), buffer_size);
+ em_convert_byte_stream_to_mailbox(local_stream, &mailbox);
+ EM_SAFE_FREE(local_stream);
+ }
+ }
+
+ /* Mail Id */
+ memcpy(&mail_id, ipcEmailAPI_GetParameter(a_hAPI, ePARAMETER_IN, 1), sizeof(int));
+
+ /* Has Attachment */
+ memcpy(&has_attachment, ipcEmailAPI_GetParameter(a_hAPI, ePARAMETER_IN, 2), sizeof(int));
+
+ /*Download Body */
+ if (!emf_mail_download_body(&mailbox, mail_id, 1, has_attachment, &handle, &err)) {
+ EM_DEBUG_EXCEPTION("emf_mail_download_body - failed");
+ goto FINISH_OFF;
+ }
+
+ err = EMF_ERROR_NONE;
+
+FINISH_OFF:
+
+ if(!ipcEmailAPI_AddParameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter local_result failed ");
+ if(!ipcEmailAPI_AddParameter(a_hAPI, ePARAMETER_OUT, &handle, sizeof(int)))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter local_result failed ");
+ if (!ipcEmailStub_ExecuteAPI(a_hAPI))
+ EM_DEBUG_EXCEPTION("ipcEmailStub_ExecuteAPI failed ");
+
+ EM_DEBUG_FUNC_END();
+}
+
+
+
+void stb_mail_get_mail(HIPC_API a_hAPI)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ emf_mailbox_t mailbox;
+ int mail_id = 0;
+ emf_mail_t* mail = NULL;
+ int size =0;
+ char* local_head_stream = NULL;
+ char* local_body_stream = NULL;
+ char* local_info_stream = NULL;
+ int err=EMF_ERROR_NONE;
+
+ EM_DEBUG_LOG("mail_id");
+ memcpy(&mail_id, ipcEmailAPI_GetParameter(a_hAPI, ePARAMETER_IN, 0), sizeof(int));
+
+ if(emf_mail_get_mail(&mailbox, mail_id, &mail, &err))
+ EM_DEBUG_LOG("success");
+
+ if(!ipcEmailAPI_AddParameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
+ EM_DEBUG_EXCEPTION(" stb_mail_get_mail ipcEmailAPI_AddParameter local_result failed ");
+ if(EMF_ERROR_NONE == err) {
+ /* Head */
+ EM_DEBUG_LOG("convert mail head");
+ local_head_stream = em_convert_mail_head_to_byte_stream(mail->head, &size);
+
+ EM_NULL_CHECK_FOR_VOID(local_head_stream);
+
+ if(!ipcEmailAPI_AddParameter(a_hAPI, ePARAMETER_OUT, local_head_stream, size))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed ");
+
+ /* Body */
+ EM_DEBUG_LOG("convert mail Body");
+ local_body_stream = em_convert_mail_body_to_byte_stream(mail->body, &size);
+
+ if ( !local_body_stream ) {
+ EM_SAFE_FREE(local_head_stream);
+ return;
+ }
+
+ if(!ipcEmailAPI_AddParameter(a_hAPI, ePARAMETER_OUT, local_body_stream, size))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed ");
+
+ /* Info */
+ EM_DEBUG_LOG("convert mail Info");
+ local_info_stream = em_convert_mail_info_to_byte_stream(mail->info, &size);
+
+ if ( !local_info_stream ) {
+ EM_SAFE_FREE(local_head_stream);
+ EM_SAFE_FREE(local_body_stream);
+ return;
+ }
+
+ if(!ipcEmailAPI_AddParameter(a_hAPI, ePARAMETER_OUT, local_info_stream, size))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed ");
+ }
+
+ EM_DEBUG_LOG("Before Execute API");
+ if (!ipcEmailStub_ExecuteAPI(a_hAPI)) {
+ EM_DEBUG_EXCEPTION("ipcEmailStub_ExecuteAPI failed ");
+ EM_SAFE_FREE(local_head_stream);
+ EM_SAFE_FREE(local_body_stream);
+ EM_SAFE_FREE(local_info_stream);
+ return;
+ }
+
+ EM_SAFE_FREE(local_head_stream);
+ EM_SAFE_FREE(local_body_stream);
+ EM_SAFE_FREE(local_info_stream);
+
+ EM_DEBUG_FUNC_END();
+}
+
+void stb_mailbox_create(HIPC_API a_hAPI)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int buffer_size = 0;
+ int err = EMF_ERROR_NONE;
+ char *local_stream = NULL;
+ int on_server = 0;
+ emf_mailbox_t mailbox;
+ int handle = 0; /* Added for cancelling mailbox creating */
+
+ buffer_size = ipcEmailAPI_GetParameterLength(a_hAPI, ePARAMETER_IN, 0);
+ EM_DEBUG_LOG("size [%d]", buffer_size);
+
+ if(buffer_size > 0) {
+ local_stream = (char*)em_core_malloc(buffer_size+1);
+ EM_NULL_CHECK_FOR_VOID(local_stream);
+ if(local_stream) {
+ memcpy(local_stream, ipcEmailAPI_GetParameter(a_hAPI, ePARAMETER_IN, 0), buffer_size);
+ memcpy(&on_server, ipcEmailAPI_GetParameter(a_hAPI, ePARAMETER_IN, 1), sizeof(int));
+ em_convert_byte_stream_to_mailbox(local_stream, &mailbox);
+ EM_SAFE_FREE(local_stream);
+
+ if (mailbox.name)
+ EM_DEBUG_LOG("Mailbox name - %s", mailbox.name);
+
+ if(emf_mailbox_create(&mailbox, on_server, (unsigned*)&handle, &err))
+ err = EMF_ERROR_NONE;
+
+ if(!ipcEmailAPI_AddParameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed 1");
+ if(!ipcEmailAPI_AddParameter(a_hAPI, ePARAMETER_OUT, &handle, sizeof(int)))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed 2");
+
+ if (!ipcEmailStub_ExecuteAPI(a_hAPI)) {
+ EM_DEBUG_EXCEPTION("ipcEmailStub_ExecuteAPI failed ");
+ return;
+ }
+ }
+ }
+ EM_DEBUG_FUNC_END();
+}
+
+
+void stb_mailbox_delete(HIPC_API a_hAPI)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int buffer_size = 0;
+ int err = EMF_ERROR_NONE;
+ char *local_stream = NULL;
+ int on_server = 0;
+ emf_mailbox_t mailbox;
+ int handle = 0; /* Added for cancelling mailbox deleting */
+
+ buffer_size = ipcEmailAPI_GetParameterLength(a_hAPI, ePARAMETER_IN, 0);
+
+ EM_DEBUG_LOG("size [%d]", buffer_size);
+
+ if(buffer_size > 0) {
+ local_stream = (char*)em_core_malloc(buffer_size+1);
+ EM_NULL_CHECK_FOR_VOID(local_stream);
+ if(local_stream) {
+ memcpy(local_stream, ipcEmailAPI_GetParameter(a_hAPI, ePARAMETER_IN, 0), buffer_size);
+ memcpy(&on_server, ipcEmailAPI_GetParameter(a_hAPI, ePARAMETER_IN, 1), sizeof(int));
+
+ em_convert_byte_stream_to_mailbox(local_stream, &mailbox);
+ EM_SAFE_FREE(local_stream);
+
+ if (mailbox.name)
+ EM_DEBUG_LOG("Mailbox name - %s", mailbox.name);
+ if(emf_mailbox_delete(&mailbox, on_server, (unsigned*)&handle, &err))
+ err = EMF_ERROR_NONE;
+
+ if(!ipcEmailAPI_AddParameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed");
+ if(!ipcEmailAPI_AddParameter(a_hAPI, ePARAMETER_OUT, &handle, sizeof(int)))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed");
+
+ if (!ipcEmailStub_ExecuteAPI(a_hAPI))
+ EM_DEBUG_EXCEPTION("ipcEmailStub_ExecuteAPI failed");
+
+ }
+ }
+ EM_DEBUG_FUNC_END();
+}
+
+void stb_mailbox_update(HIPC_API a_hAPI)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int buffer_size = 0;
+ int err = EMF_ERROR_NONE;
+ char *old_mailbox_stream = NULL;
+ char *new_mailbox_stream = NULL;
+ int on_server = 0;
+ emf_mailbox_t *old_mailbox = NULL;
+ emf_mailbox_t *new_mailbox = NULL;
+ int handle = 0; /* Added for cancelling mailbox updating */
+
+ buffer_size = ipcEmailAPI_GetParameterLength(a_hAPI, ePARAMETER_IN, 0);
+ EM_DEBUG_LOG("size [%d]", buffer_size);
+ if(buffer_size > 0) {
+ old_mailbox_stream = (char*)em_core_malloc(buffer_size+1);
+ EM_NULL_CHECK_FOR_VOID(old_mailbox_stream);
+ if(old_mailbox_stream) {
+ memcpy(old_mailbox_stream, ipcEmailAPI_GetParameter(a_hAPI, ePARAMETER_IN, 0), buffer_size);
+ old_mailbox = (emf_mailbox_t*)em_core_malloc(sizeof(emf_mailbox_t));
+ if ( old_mailbox == NULL ) {
+ EM_DEBUG_EXCEPTION("em_core_malloc failed.");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ em_convert_byte_stream_to_mailbox(old_mailbox_stream, old_mailbox);
+ EM_SAFE_FREE(old_mailbox_stream);
+ }
+ }
+ else {
+ EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ buffer_size = ipcEmailAPI_GetParameterLength(a_hAPI, ePARAMETER_IN, 1);
+ EM_DEBUG_LOG("size [%d]", buffer_size);
+ if(buffer_size > 0) {
+ new_mailbox_stream = (char*)em_core_malloc(buffer_size+1);
+ EM_NULL_CHECK_FOR_VOID(new_mailbox_stream);
+ if(new_mailbox_stream) {
+ memcpy(new_mailbox_stream, ipcEmailAPI_GetParameter(a_hAPI, ePARAMETER_IN, 1), buffer_size);
+ new_mailbox = (emf_mailbox_t*)em_core_malloc(sizeof(emf_mailbox_t));
+ if ( new_mailbox == NULL ) {
+ EM_DEBUG_EXCEPTION("em_core_malloc failed.");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+ em_convert_byte_stream_to_mailbox(new_mailbox_stream, new_mailbox);
+ EM_SAFE_FREE(new_mailbox_stream);
+ }
+ }
+ else {
+ EM_DEBUG_EXCEPTION("INVALID PARAM : old mailbox");
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ memcpy(&on_server, ipcEmailAPI_GetParameter(a_hAPI, ePARAMETER_IN, 2), sizeof(int));
+
+ if(emf_mailbox_update(old_mailbox, new_mailbox, on_server, (unsigned*)&handle, &err))
+ err = EMF_ERROR_NONE;
+
+ if(!ipcEmailAPI_AddParameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed");
+ if(!ipcEmailAPI_AddParameter(a_hAPI, ePARAMETER_OUT, &handle, sizeof(int)))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed");
+
+ if (!ipcEmailStub_ExecuteAPI(a_hAPI))
+ EM_DEBUG_EXCEPTION("ipcEmailStub_ExecuteAPI failed");
+
+
+FINISH_OFF:
+ EM_SAFE_FREE(old_mailbox_stream);
+ EM_SAFE_FREE(new_mailbox_stream);
+
+ emf_mailbox_free(&old_mailbox, 1, NULL);
+ emf_mailbox_free(&new_mailbox, 1, NULL);
+ EM_DEBUG_FUNC_END();
+}
+
+
+void stb_mailbox_set_mail_slot_size(HIPC_API a_hAPI)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int buffer_size = 0;
+ int err = EMF_ERROR_NONE;
+ int handle = 0;
+ int account_id = 0, mail_slot_size = 0;
+ char *mailbox_name = NULL;
+
+
+ memcpy(&account_id, ipcEmailAPI_GetParameter(a_hAPI, ePARAMETER_IN, 0), sizeof(int));
+ EM_DEBUG_LOG("account_id[%d]", account_id);
+
+ memcpy(&mail_slot_size, ipcEmailAPI_GetParameter(a_hAPI, ePARAMETER_IN, 1), sizeof(int));
+ EM_DEBUG_LOG("mail_slot_size[%d]", mail_slot_size);
+
+ buffer_size = ipcEmailAPI_GetParameterLength(a_hAPI, ePARAMETER_IN, 2);
+ EM_DEBUG_LOG("mailbox name string size[%d]", buffer_size);
+ if(buffer_size > 0) {
+ mailbox_name = (char*)em_core_malloc(buffer_size + 1);
+ memcpy(mailbox_name, ipcEmailAPI_GetParameter(a_hAPI, ePARAMETER_IN, 2), buffer_size);
+ EM_DEBUG_LOG("mailbox_name [%s]", mailbox_name);
+ }
+
+ if(emf_mailbox_set_mail_slot_size(account_id, mailbox_name, mail_slot_size, (unsigned*)&handle, &err))
+ err = EMF_ERROR_NONE;
+ if(!ipcEmailAPI_AddParameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed 1");
+
+ if(!ipcEmailAPI_AddParameter(a_hAPI, ePARAMETER_OUT, &handle, sizeof(int)))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed 2");
+
+ if (!ipcEmailStub_ExecuteAPI(a_hAPI))
+ EM_DEBUG_EXCEPTION("ipcEmailStub_ExecuteAPI failed ");
+
+ EM_SAFE_FREE(mailbox_name);
+ EM_DEBUG_FUNC_END();
+}
+
+void stb_mail_send(HIPC_API a_hAPI)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int buffer_size = 0;
+ char* local_option_stream = NULL;
+ char* local_stream = NULL;
+ emf_mailbox_t* mailbox = NULL;
+ emf_option_t sending_option;
+ int mail_id;
+ int handle;
+ int err = EMF_ERROR_NONE;
+ char* mailbox_name = NULL;
+
+ /* Mailbox */
+ buffer_size = ipcEmailAPI_GetParameterLength(a_hAPI, ePARAMETER_IN, 0);
+
+ if(buffer_size > 0) {
+ local_stream = (char*)em_core_malloc(buffer_size+1);
+ EM_NULL_CHECK_FOR_VOID(local_stream);
+ if(local_stream) {
+ memcpy(local_stream, ipcEmailAPI_GetParameter(a_hAPI, ePARAMETER_IN, 0), buffer_size);
+ mailbox = (emf_mailbox_t*)em_core_malloc(sizeof(emf_mailbox_t));
+ em_convert_byte_stream_to_mailbox(local_stream, mailbox);
+
+ if (!em_storage_get_mailboxname_by_mailbox_type(mailbox->account_id,EMF_MAILBOX_TYPE_DRAFT,&mailbox_name, false, &err)) {
+ EM_DEBUG_EXCEPTION("em_storage_get_mailboxname_by_mailbox_type failed [%d]", err);
+ err = em_storage_get_emf_error_from_em_storage_error(err);
+ goto FINISH_OFF;
+ }
+ mailbox->name = mailbox_name;
+ }
+ }
+
+ /* Mail_id */
+ memcpy(&mail_id, ipcEmailAPI_GetParameter(a_hAPI, ePARAMETER_IN, 1), sizeof(int));
+ EM_DEBUG_LOG("mail_id [%d]", mail_id);
+
+ /* Sending Option */
+ buffer_size = ipcEmailAPI_GetParameterLength(a_hAPI, ePARAMETER_IN, 2);
+
+ if(buffer_size > 0) {
+ local_option_stream = (char*)em_core_malloc(buffer_size+1);
+
+ if(NULL == local_option_stream) {
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ if(local_option_stream) {
+ memcpy(local_option_stream, ipcEmailAPI_GetParameter(a_hAPI, ePARAMETER_IN, 2), buffer_size);
+ em_convert_byte_stream_to_option(local_option_stream, &sending_option);
+ }
+ }
+
+ if(emf_mail_send(mailbox, mail_id, &sending_option, (unsigned*)&handle, &err)) {
+ err = EMF_ERROR_NONE;
+ if(!ipcEmailAPI_AddParameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter result failed ");
+ if(!ipcEmailAPI_AddParameter(a_hAPI, ePARAMETER_OUT, &handle, sizeof(int)))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter result failed ");
+ if (!ipcEmailStub_ExecuteAPI(a_hAPI))
+ EM_DEBUG_EXCEPTION("ipcEmailStub_ExecuteAPI failed ");
+ }
+ else {
+ if(!ipcEmailAPI_AddParameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed ");
+ if (!ipcEmailStub_ExecuteAPI(a_hAPI))
+ EM_DEBUG_EXCEPTION("ipcEmailStub_ExecuteAPI failed ");
+ }
+
+FINISH_OFF:
+ EM_SAFE_FREE(local_stream);
+ EM_SAFE_FREE(local_option_stream);
+ EM_SAFE_FREE(mailbox);
+ EM_SAFE_FREE(mailbox_name);
+
+ EM_DEBUG_FUNC_END();
+}
+
+void stb_mailbox_get_list(HIPC_API a_hAPI)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int err = EMF_ERROR_NONE;
+ int counter = 0;
+ char* local_stream = NULL;
+ int account_id;
+ emf_mailbox_t* mailbox_list = NULL;
+ int count = 0;
+ int size = 0;
+
+ memcpy(&account_id, ipcEmailAPI_GetParameter(a_hAPI, ePARAMETER_IN, 0), sizeof(int));
+
+ if(emf_mailbox_get_list(account_id, &mailbox_list, &count, &err))
+ EM_DEBUG_LOG("emf_mailbox_get_list - success");
+
+ if(!ipcEmailAPI_AddParameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed ");
+
+ if(EMF_ERROR_NONE == err) {
+ EM_DEBUG_LOG("Count [%d]", count);
+ if(!ipcEmailAPI_AddParameter(a_hAPI, ePARAMETER_OUT, &count, sizeof(int)))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed ");
+
+ for(counter=0; counter<count; counter++) {
+ EM_DEBUG_LOG("Name - %s", mailbox_list[counter].name);
+
+ local_stream = em_convert_mailbox_to_byte_stream(mailbox_list+counter, &size);
+
+ EM_NULL_CHECK_FOR_VOID(local_stream);
+
+ if(!ipcEmailAPI_AddParameter(a_hAPI, ePARAMETER_OUT, local_stream, size))
+ EM_DEBUG_EXCEPTION("Add Param mailbox failed ");
+
+ EM_SAFE_FREE(local_stream);
+ size = 0;
+ }
+ }
+
+ if (!ipcEmailStub_ExecuteAPI(a_hAPI))
+ EM_DEBUG_EXCEPTION("ipcEmailStub_ExecuteAPI failed ");
+ EM_DEBUG_FUNC_END();
+}
+
+
+void stb_update_mail_old(HIPC_API a_hAPI)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ int mail_id;
+ int buffer_size = 0;
+ int local_result = 0;
+ char* stream_for_head = NULL;
+ char* stream_for_body = NULL;
+ char* local_info_stream = NULL;
+ emf_mail_t *mail = NULL;
+ int err = EMF_ERROR_NONE;
+ char* stream_for_meeting_request = NULL;
+ emf_meeting_request_t *meeting_req = NULL;
+
+ mail = (emf_mail_t*)em_core_malloc(sizeof(emf_mail_t));
+
+ memcpy(&mail_id, ipcEmailAPI_GetParameter(a_hAPI, ePARAMETER_IN, 0), sizeof(int));;
+
+ buffer_size = ipcEmailAPI_GetParameterLength(a_hAPI, ePARAMETER_IN, 1);
+
+ if(buffer_size > 0) {
+ stream_for_head = (char*)em_core_malloc(buffer_size+1);
+ EM_NULL_CHECK_FOR_VOID(stream_for_head);
+ if(stream_for_head) {
+ memcpy(stream_for_head, ipcEmailAPI_GetParameter(a_hAPI, ePARAMETER_IN, 1), buffer_size);
+ mail->head = (emf_mail_head_t*)em_core_malloc(sizeof(emf_mail_head_t));
+ if(NULL == mail->head) {
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+ em_convert_byte_stream_to_mail_head(stream_for_head, mail->head);
+ }
+ else {
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+ }
+
+ buffer_size = ipcEmailAPI_GetParameterLength(a_hAPI, ePARAMETER_IN, 2);
+ if ( buffer_size == sizeof(int) ) {
+ EM_DEBUG_LOG(">>>>> Mail body is Null");
+ mail->body = NULL;
+ }
+ else if(buffer_size > 0) {
+ stream_for_body = (char*)em_core_malloc(buffer_size+1);
+ if(stream_for_body) {
+ memcpy(stream_for_body, ipcEmailAPI_GetParameter(a_hAPI, ePARAMETER_IN, 2), buffer_size);
+ mail->body = (emf_mail_body_t*)em_core_malloc(sizeof(emf_mail_body_t));
+ if(NULL == mail->body) {
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+ em_convert_byte_stream_to_mail_body(stream_for_body, mail->body);
+ }
+ else {
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+ }
+
+ buffer_size = ipcEmailAPI_GetParameterLength(a_hAPI, ePARAMETER_IN, 3);
+ if(buffer_size > 0) {
+ local_info_stream = (char*)em_core_malloc(buffer_size+1);
+ if(local_info_stream) {
+ memcpy(local_info_stream, ipcEmailAPI_GetParameter(a_hAPI, ePARAMETER_IN, 3), buffer_size);
+ mail->info = (emf_mail_info_t*)em_core_malloc(sizeof(emf_mail_info_t));
+ if(NULL == mail->info) {
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+ em_convert_byte_stream_to_mail_info(local_info_stream, mail->info);
+ }
+ else {
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+ }
+
+ EM_DEBUG_LOG("meeting request[%d]", mail->info->is_meeting_request);
+
+ if ( mail->info->is_meeting_request == EMF_MAIL_TYPE_MEETING_REQUEST
+ || mail->info->is_meeting_request == EMF_MAIL_TYPE_MEETING_RESPONSE
+ || mail->info->is_meeting_request == EMF_MAIL_TYPE_MEETING_ORIGINATINGREQUEST) {
+ buffer_size = ipcEmailAPI_GetParameterLength(a_hAPI, ePARAMETER_IN, 4);
+
+ if(buffer_size > 0) {
+ stream_for_meeting_request = (char*)em_core_malloc(buffer_size+1);
+ if(stream_for_meeting_request) {
+ memcpy(stream_for_meeting_request, ipcEmailAPI_GetParameter(a_hAPI, ePARAMETER_IN, 4), buffer_size);
+ meeting_req = (emf_meeting_request_t*)em_core_malloc(sizeof(emf_meeting_request_t));
+ if(meeting_req) {
+ em_convert_byte_stream_to_meeting_req(stream_for_meeting_request, meeting_req);
+ }
+ }
+ else {
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+ }
+ }
+
+ EM_DEBUG_LOG("calling emf_mail_update with meeting request");
+ if(emf_mail_update(mail_id, mail, meeting_req, 0, &err)) {
+ local_result = 1;
+
+ if(!ipcEmailAPI_AddParameter(a_hAPI, ePARAMETER_OUT, &local_result, sizeof(int)))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed ");
+
+ if (!ipcEmailStub_ExecuteAPI(a_hAPI))
+ EM_DEBUG_EXCEPTION("ipcEmailStub_ExecuteAPI failed ");
+ }
+
+FINISH_OFF:
+ if ( local_result == 0 ) {
+ if(!ipcEmailAPI_AddParameter(a_hAPI, ePARAMETER_OUT, &local_result, sizeof(int)))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed ");
+ if(!ipcEmailAPI_AddParameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed ");
+
+ if (!ipcEmailStub_ExecuteAPI(a_hAPI))
+ EM_DEBUG_EXCEPTION("ipcEmailStub_ExecuteAPI failed ");
+ }
+
+ EM_SAFE_FREE(stream_for_head);
+ EM_SAFE_FREE(stream_for_body);
+ EM_SAFE_FREE(local_info_stream);
+
+ /* Caution!! Don't free mail here. mail will be freed after using in event loop.
+ if (mail)
+ em_core_mail_free(&mail, 1, &err_code);
+ EM_SAFE_FREE(meeting_req);
+ */
+
+ em_core_flush_memory();
+ EM_DEBUG_FUNC_END();
+}
+
+void stb_mail_delete_all(HIPC_API a_hAPI)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int buffer_size = 0;
+ char* local_stream = NULL;
+ emf_mailbox_t *mailbox = NULL;
+ int with_server = 0;
+ int err = EMF_ERROR_NONE;
+
+ /* Mailbox */
+ buffer_size = ipcEmailAPI_GetParameterLength(a_hAPI, ePARAMETER_IN, 0);
+
+ if(buffer_size > 0) {
+ local_stream = (char*)em_core_malloc(buffer_size+1);
+ EM_NULL_CHECK_FOR_VOID(local_stream);
+ if(local_stream) {
+ memcpy(local_stream, ipcEmailAPI_GetParameter(a_hAPI, ePARAMETER_IN, 0), buffer_size);
+ mailbox = (emf_mailbox_t*)em_core_malloc(sizeof(emf_mailbox_t));
+ em_convert_byte_stream_to_mailbox(local_stream, mailbox);
+ }
+ }
+
+ /* with_server */
+ memcpy(&with_server, ipcEmailAPI_GetParameter(a_hAPI, ePARAMETER_IN, 1), sizeof(int));
+
+ emf_mail_delete_all(mailbox, with_server, NULL, &err);
+
+ if(!ipcEmailAPI_AddParameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed ");
+ if (!ipcEmailStub_ExecuteAPI(a_hAPI))
+ EM_DEBUG_EXCEPTION("ipcEmailStub_ExecuteAPI failed ");
+
+ EM_SAFE_FREE(local_stream);
+ EM_SAFE_FREE(mailbox);
+
+ EM_DEBUG_FUNC_END();
+}
+
+void stb_mail_delete(HIPC_API a_hAPI)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int buffer_size = 0;
+ int err = EMF_ERROR_NONE;
+ char* local_stream = NULL;
+ emf_mailbox_t *mailbox = NULL;
+ int with_server = 0;
+ int counter = 0;
+ int num;
+
+ /* Mailbox */
+ EM_DEBUG_LOG("mailbox");
+ buffer_size = ipcEmailAPI_GetParameterLength(a_hAPI, ePARAMETER_IN, 0);
+
+ if(buffer_size > 0) {
+ local_stream = (char*)em_core_malloc(buffer_size+1);
+ EM_NULL_CHECK_FOR_VOID(local_stream);
+ if(local_stream) {
+ memcpy(local_stream, ipcEmailAPI_GetParameter(a_hAPI, ePARAMETER_IN, 0), buffer_size);
+ /* Memory is not yet allocated for mailbox */
+ mailbox = (emf_mailbox_t*)em_core_malloc(sizeof(emf_mailbox_t));
+ em_convert_byte_stream_to_mailbox(local_stream, mailbox);
+ }
+ EM_DEBUG_LOG("account_id [%d]", mailbox->account_id);
+ EM_DEBUG_LOG("mailbox name - %s", mailbox->name);
+
+ /* Number of mail_ids */
+ memcpy(&num, ipcEmailAPI_GetParameter(a_hAPI, ePARAMETER_IN, 1), sizeof(int));
+ EM_DEBUG_LOG("number of mails [%d]", num);
+
+ int mail_ids[num];
+ memcpy(mail_ids, ipcEmailAPI_GetParameter(a_hAPI, ePARAMETER_IN, 2), num * sizeof(int));
+ for(counter = 0; counter < num; counter++)
+ EM_DEBUG_LOG("mail_ids [%d]", mail_ids[counter]);
+
+ /* with_server */
+ memcpy(&with_server, ipcEmailAPI_GetParameter(a_hAPI, ePARAMETER_IN, 3), sizeof(int));
+ EM_DEBUG_LOG("with_Server [%d]", with_server);
+
+ emf_mail_delete(mailbox->account_id, mailbox, mail_ids, num, with_server, NULL, &err);
+ }
+ else
+ err = EMF_ERROR_IPC_CRASH;
+
+ if(!ipcEmailAPI_AddParameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed");
+ if (!ipcEmailStub_ExecuteAPI(a_hAPI))
+ EM_DEBUG_EXCEPTION("ipcEmailStub_ExecuteAPI failed");
+
+ EM_SAFE_FREE(local_stream);
+ EM_SAFE_FREE(mailbox);
+
+ EM_DEBUG_FUNC_END();
+}
+void stb_clear_mail_data (HIPC_API a_hAPI)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int err = EMF_ERROR_NONE;
+
+ if(emf_clear_mail_data(&err)) {
+ EM_DEBUG_LOG(">>> stb_clear_mail_data Success [ %d] >> ", err);
+ }
+
+ if(!ipcEmailAPI_AddParameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed : err");
+ if (!ipcEmailStub_ExecuteAPI(a_hAPI))
+ EM_DEBUG_EXCEPTION("ipcEmailStub_ExecuteAPI failed ");
+ EM_DEBUG_FUNC_END();
+}
+
+void stb_rule_add(HIPC_API a_hAPI)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int buffer_size = 0;
+ int err = EMF_ERROR_NONE;
+ char* local_rule_stream = NULL;
+ emf_rule_t rule = { 0 };
+
+ buffer_size = ipcEmailAPI_GetParameterLength(a_hAPI, ePARAMETER_IN, 0);
+
+ if(buffer_size > 0) {
+ local_rule_stream = (char*)em_core_malloc(buffer_size + 1);
+ EM_NULL_CHECK_FOR_VOID(local_rule_stream);
+ if(local_rule_stream) {
+ memcpy(local_rule_stream, ipcEmailAPI_GetParameter(a_hAPI, ePARAMETER_IN, 0), buffer_size);
+ em_convert_byte_stream_to_rule(local_rule_stream, &rule);
+ EM_DEBUG_LOG("account ID [%d]", rule.account_id);
+
+ if(emf_filter_add(&rule, &err))
+ err = EMF_ERROR_NONE;
+
+ if(!ipcEmailAPI_AddParameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed ");
+ if (!ipcEmailStub_ExecuteAPI(a_hAPI))
+ EM_DEBUG_EXCEPTION("ipcEmailStub_ExecuteAPI failed ");
+
+ }
+ }
+
+ EM_SAFE_FREE(local_rule_stream);
+
+ EM_DEBUG_FUNC_END();
+}
+
+void stb_rule_get(HIPC_API a_hAPI)
+{
+ int err = EMF_ERROR_NONE;
+ int filter_id = 0;
+ emf_rule_t* rule = NULL;
+ int size =0;
+ char* local_rule_stream = NULL;
+
+ EM_DEBUG_LOG(" filter_id");
+ memcpy(&filter_id, ipcEmailAPI_GetParameter(a_hAPI, ePARAMETER_IN, 0), sizeof(int));
+
+ if(emf_filter_get(filter_id, &rule, &err)) {
+ err = EMF_ERROR_NONE;
+ if(!ipcEmailAPI_AddParameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed ");
+
+ /* Rule */
+ local_rule_stream = em_convert_rule_to_byte_stream(rule, &size);
+
+ EM_NULL_CHECK_FOR_VOID(local_rule_stream);
+
+ if(!ipcEmailAPI_AddParameter(a_hAPI, ePARAMETER_OUT, local_rule_stream, size))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed ");
+
+ if (!ipcEmailStub_ExecuteAPI(a_hAPI)) {
+ EM_DEBUG_EXCEPTION("ipcEmailStub_ExecuteAPI failed ");
+ EM_SAFE_FREE( local_rule_stream );
+ return;
+ }
+ }
+ else {
+ if(!ipcEmailAPI_AddParameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed ");
+
+ if (!ipcEmailStub_ExecuteAPI(a_hAPI)) {
+ EM_DEBUG_EXCEPTION("ipcEmailStub_ExecuteAPI failed ");
+ EM_SAFE_FREE( local_rule_stream );
+ return;
+ }
+ }
+ EM_SAFE_FREE( local_rule_stream );
+ EM_DEBUG_FUNC_END();
+}
+
+void stb_rule_get_list(HIPC_API a_hAPI)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ /* int buffer_size = 0; */
+ int err = EMF_ERROR_NONE;
+ int counter = 0;
+ char* local_stream = NULL;
+ int count = 0;
+ int size = 0;
+
+ emf_rule_t* filtering_list = NULL;
+
+ if(emf_filter_get_list(&filtering_list, &count, &err)) {
+ EM_DEBUG_LOG("emf_filter_get_list - success");
+ err = EMF_ERROR_NONE;
+ if(!ipcEmailAPI_AddParameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed ");
+
+ EM_DEBUG_LOG("Count [%d]", count);
+ if(!ipcEmailAPI_AddParameter(a_hAPI, ePARAMETER_OUT, &count, sizeof(int)))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed ");
+
+ for(counter=0; counter<count; counter++) {
+ EM_DEBUG_LOG("Value - %s", filtering_list[counter].value);
+
+ local_stream = em_convert_rule_to_byte_stream(filtering_list+counter, &size);
+
+ EM_NULL_CHECK_FOR_VOID(local_stream);
+
+ if(!ipcEmailAPI_AddParameter(a_hAPI, ePARAMETER_OUT, local_stream, size))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed ");
+
+ EM_SAFE_FREE(local_stream);
+ size = 0;
+ }
+
+ if (!ipcEmailStub_ExecuteAPI(a_hAPI)) {
+ EM_DEBUG_EXCEPTION("ipcEmailStub_ExecuteAPI failed ");
+ return;
+ }
+ }
+
+ else {
+ EM_DEBUG_EXCEPTION("emf_filter_get_list - failed");
+ if(!ipcEmailAPI_AddParameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter local_result failed ");
+
+ if (!ipcEmailStub_ExecuteAPI(a_hAPI)) {
+ EM_DEBUG_EXCEPTION("ipcEmailStub_ExecuteAPI failed ");
+ return;
+ }
+ }
+ EM_DEBUG_FUNC_END();
+}
+
+void stb_rule_find(HIPC_API a_hAPI)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int buffer_size = 0;
+ int err = EMF_ERROR_NONE;
+ char* local_rule_stream = NULL;
+ emf_rule_t rule = { 0 };
+
+
+ buffer_size = ipcEmailAPI_GetParameterLength(a_hAPI, ePARAMETER_IN, 0);
+
+ if(buffer_size > 0) {
+ local_rule_stream = (char*)em_core_malloc(buffer_size+1);
+ EM_NULL_CHECK_FOR_VOID(local_rule_stream);
+ if(local_rule_stream) {
+ memcpy(local_rule_stream, ipcEmailAPI_GetParameter(a_hAPI, ePARAMETER_IN, 0), buffer_size);
+ em_convert_byte_stream_to_rule(local_rule_stream, &rule);
+ EM_SAFE_FREE(local_rule_stream);
+ EM_DEBUG_LOG("account ID [%d]", rule.account_id);
+
+ if(emf_filter_find(&rule, &err))
+ err = EMF_ERROR_NONE;
+
+ if(!ipcEmailAPI_AddParameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed ");
+ if (!ipcEmailStub_ExecuteAPI(a_hAPI))
+ EM_DEBUG_EXCEPTION("ipcEmailStub_ExecuteAPI failed ");
+
+ }
+ }
+ EM_DEBUG_FUNC_END();
+}
+
+void stb_rule_change(HIPC_API a_hAPI)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ int filter_id = 0;
+ int buffer_size = 0;
+ int err = EMF_ERROR_NONE;
+ char* rule_stream = NULL;
+ emf_rule_t *rule = NULL;
+
+ /* filter_id */
+ memcpy(&filter_id, ipcEmailAPI_GetParameter(a_hAPI, ePARAMETER_IN, 0), sizeof(int));;
+
+ buffer_size = ipcEmailAPI_GetParameterLength(a_hAPI, ePARAMETER_IN, 1);
+ EM_DEBUG_LOG("size [%d]", buffer_size);
+
+ if(buffer_size > 0) {
+ rule_stream = (char*)em_core_malloc(buffer_size+1);
+ EM_NULL_CHECK_FOR_VOID(rule_stream);
+ if(rule_stream) {
+ memcpy(rule_stream, ipcEmailAPI_GetParameter(a_hAPI, ePARAMETER_IN, 1), buffer_size);
+ rule = (emf_rule_t*)em_core_malloc(sizeof(emf_rule_t));
+
+ if(NULL == rule) {
+ EM_SAFE_FREE(rule_stream);
+ return;
+ }
+
+ em_convert_byte_stream_to_rule(rule_stream, rule);
+ EM_SAFE_FREE(rule_stream);
+ }
+ }
+
+ if(emf_filter_change(filter_id, rule, &err))
+ err = EMF_ERROR_NONE;
+
+ if(!ipcEmailAPI_AddParameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed");
+
+ if (!ipcEmailStub_ExecuteAPI(a_hAPI))
+ EM_DEBUG_EXCEPTION("ipcEmailStub_ExecuteAPI failed");
+
+ EM_SAFE_FREE(rule);
+ EM_DEBUG_FUNC_END();
+}
+
+void stb_mail_move_all_mails(HIPC_API a_hAPI)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int buffer_size = 0;
+ int err = EMF_ERROR_NONE;
+ char* src_mailbox_stream = NULL;
+ char* dst_mailbox_stream = NULL;
+ emf_mailbox_t dst_mailbox;
+ emf_mailbox_t src_mailbox;
+
+ buffer_size = ipcEmailAPI_GetParameterLength(a_hAPI, ePARAMETER_IN, 0);
+ EM_DEBUG_LOG("buffer_size [%d]", buffer_size);
+
+ if(buffer_size > 0) {
+ src_mailbox_stream = (char*)em_core_malloc(buffer_size+1);
+ EM_NULL_CHECK_FOR_VOID(src_mailbox_stream);
+ if(src_mailbox_stream) {
+ memcpy(src_mailbox_stream, ipcEmailAPI_GetParameter(a_hAPI, ePARAMETER_IN, 0), buffer_size);
+ /* Convert Byte stream to mailbox structure */
+ EM_DEBUG_LOG("Before em_convert_byte_stream_to_mailbox");
+ em_convert_byte_stream_to_mailbox(src_mailbox_stream, &src_mailbox);
+ EM_SAFE_FREE(src_mailbox_stream);
+ if (src_mailbox.name)
+ EM_DEBUG_LOG("Mailbox name - %s", src_mailbox.name);
+ else
+ EM_DEBUG_EXCEPTION(">>>> Mailbox Information is NULL >> ");
+
+ }
+ }
+
+ buffer_size =0;
+ buffer_size = ipcEmailAPI_GetParameterLength(a_hAPI, ePARAMETER_IN, 1);
+ EM_DEBUG_LOG(" size [%d]", buffer_size);
+
+ if(buffer_size > 0) {
+ dst_mailbox_stream = (char*)em_core_malloc(buffer_size+1);
+ EM_NULL_CHECK_FOR_VOID(dst_mailbox_stream);
+ if(dst_mailbox_stream) {
+ memcpy(dst_mailbox_stream, ipcEmailAPI_GetParameter(a_hAPI, ePARAMETER_IN, 1), buffer_size);
+ em_convert_byte_stream_to_mailbox(dst_mailbox_stream, &dst_mailbox);
+ EM_SAFE_FREE(dst_mailbox_stream);
+ if (dst_mailbox.name)
+ EM_DEBUG_LOG("Mailbox name - %s", dst_mailbox.name);
+ else
+ EM_DEBUG_EXCEPTION(">>>> Mailbox Information is NULL >> ");
+ }
+ }
+
+ if(emf_mail_move_all_mails(&src_mailbox, &dst_mailbox, &err))
+ EM_DEBUG_LOG("emf_mail_move_all_mails:Success");
+ if(!ipcEmailAPI_AddParameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int))) {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed ");
+ return;
+ }
+
+ if (!ipcEmailStub_ExecuteAPI(a_hAPI)) {
+ EM_DEBUG_EXCEPTION("ipcEmailStub_ExecuteAPI failed");
+ return;
+ }
+ EM_DEBUG_FUNC_END();
+}
+
+void stb_set_flags_field(HIPC_API a_hAPI)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int err = EMF_ERROR_NONE;
+ emf_flags_field_type field_type = 0;
+ void *temp_buffer = NULL;
+ int account_id;
+ int value = 0;
+ int onserver = 0;
+ int num = 0;
+ int counter = 0;
+ int *mail_ids = NULL;
+
+ /* account_id */
+ temp_buffer = ipcEmailAPI_GetParameter(a_hAPI, ePARAMETER_IN, 0);
+ if(!temp_buffer) {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_GetParameter failed ");
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ memcpy(&account_id, temp_buffer, sizeof(int));
+ EM_DEBUG_LOG("account_id [%d]", account_id);
+
+ /* Number of mail_ids */
+ temp_buffer = ipcEmailAPI_GetParameter(a_hAPI, ePARAMETER_IN, 1);
+ if(!temp_buffer) {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_GetParameter failed ");
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ memcpy(&num, temp_buffer, sizeof(int));
+ EM_DEBUG_LOG("number of mails [%d]", num);
+
+ /* mail_id */
+ mail_ids = em_core_malloc(sizeof(int) * num);
+
+ if(!mail_ids) {
+ EM_DEBUG_EXCEPTION("em_core_malloc failed ");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ temp_buffer = ipcEmailAPI_GetParameter(a_hAPI, ePARAMETER_IN, 2);
+ if(!temp_buffer) {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_GetParameter failed ");
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ memcpy(mail_ids, temp_buffer, num * sizeof(int));
+
+ for(counter=0; counter < num; counter++) {
+ EM_DEBUG_LOG("mailids [%d]", mail_ids[counter]);
+ }
+
+ /* field type */
+ temp_buffer = ipcEmailAPI_GetParameter(a_hAPI, ePARAMETER_IN, 3);
+ if(!temp_buffer) {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_GetParameter failed ");
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ memcpy(&field_type, temp_buffer, sizeof(int));
+ EM_DEBUG_LOG("field_type [%d]", field_type);
+
+ /* value */
+ temp_buffer = ipcEmailAPI_GetParameter(a_hAPI, ePARAMETER_IN, 4);
+ if(!temp_buffer) {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_GetParameter failed ");
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ memcpy(&value, temp_buffer, sizeof(int));
+ EM_DEBUG_LOG("value [%d]", value);
+
+ /* on server */
+ temp_buffer = ipcEmailAPI_GetParameter(a_hAPI, ePARAMETER_IN, 5);
+ if(!temp_buffer) {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_GetParameter failed ");
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ memcpy(&onserver, temp_buffer, sizeof(int));
+ EM_DEBUG_LOG("onserver [%d]", value);
+
+ if(emf_mail_set_flags_field(account_id, mail_ids, num, field_type, value, onserver, &err))
+ EM_DEBUG_LOG("emf_mail_set_flags_field - success");
+
+FINISH_OFF:
+
+ if(!ipcEmailAPI_AddParameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter local_result failed ");
+
+ if (!ipcEmailStub_ExecuteAPI(a_hAPI))
+ EM_DEBUG_EXCEPTION("ipcEmailStub_ExecuteAPI failed ");
+ EM_DEBUG_FUNC_END();
+}
+
+void stb_add_mail(HIPC_API a_hAPI)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int buffer_size = 0;
+ int local_result = 0;
+ int result_mail_data_count = 0;
+ int result_attachment_data_count = 0;
+ int parameter_index = 0;
+ int sync_server = 0;
+ int err = EMF_ERROR_NONE;
+ char *mail_data_stream = NULL;
+ char *attachment_data_list_stream = NULL;
+ char *meeting_request_stream = NULL;
+ char *parameter_data = NULL;
+ emf_mail_data_t *result_mail_data = NULL;
+ emf_attachment_data_t *result_attachment_data = NULL;
+ emf_meeting_request_t *result_meeting_request = NULL;
+
+ EM_DEBUG_LOG("emf_mail_data_t");
+ buffer_size = ipcEmailAPI_GetParameterLength(a_hAPI, ePARAMETER_IN, parameter_index);
+
+ if(buffer_size > 0) {
+ mail_data_stream = (char*)em_core_malloc(buffer_size + 1);
+ if(!mail_data_stream) {
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+ parameter_data = ipcEmailAPI_GetParameter(a_hAPI, ePARAMETER_IN, parameter_index++);
+
+ if(!parameter_data) {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_GetParameter failed");
+ err = EMF_ERROR_ON_PARSING;
+ goto FINISH_OFF;
+ }
+
+ memcpy(mail_data_stream, parameter_data, buffer_size);
+
+ em_convert_byte_stream_to_mail_data(mail_data_stream, &result_mail_data, &result_mail_data_count);
+ if(!result_mail_data) {
+ EM_DEBUG_EXCEPTION("em_convert_byte_stream_to_mail_data failed");
+ err = EMF_ERROR_ON_PARSING;
+ goto FINISH_OFF;
+ }
+ }
+
+ buffer_size = ipcEmailAPI_GetParameterLength(a_hAPI, ePARAMETER_IN, parameter_index);
+ EM_DEBUG_LOG("emf_attachment_data_t buffer_size[%d]", buffer_size);
+
+ if(buffer_size > 0) {
+ attachment_data_list_stream = (char*)em_core_malloc(buffer_size + 1);
+ if(!attachment_data_list_stream) {
+ EM_DEBUG_EXCEPTION("em_core_malloc failed");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ parameter_data = ipcEmailAPI_GetParameter(a_hAPI, ePARAMETER_IN, parameter_index++);
+
+ if(!parameter_data) {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_GetParameter failed");
+ err = EMF_ERROR_ON_PARSING;
+ goto FINISH_OFF;
+ }
+
+ memcpy(attachment_data_list_stream, parameter_data, buffer_size);
+
+ em_convert_byte_stream_to_attachment_data(attachment_data_list_stream, &result_attachment_data, &result_attachment_data_count);
+
+ EM_DEBUG_LOG("result_attachment_data_count[%d]", result_attachment_data_count);
+
+ if(result_attachment_data_count && !result_attachment_data) {
+ EM_DEBUG_EXCEPTION("em_convert_byte_stream_to_attachment_data failed");
+ err = EMF_ERROR_ON_PARSING;
+ goto FINISH_OFF;
+ }
+ }
+
+ EM_DEBUG_LOG("emf_meeting_request_t");
+
+ if ( result_mail_data->meeting_request_status == EMF_MAIL_TYPE_MEETING_REQUEST
+ || result_mail_data->meeting_request_status == EMF_MAIL_TYPE_MEETING_RESPONSE
+ || result_mail_data->meeting_request_status == EMF_MAIL_TYPE_MEETING_ORIGINATINGREQUEST) {
+ buffer_size = ipcEmailAPI_GetParameterLength(a_hAPI, ePARAMETER_IN, parameter_index);
+
+ if(buffer_size > 0) {
+ meeting_request_stream = (char*)em_core_malloc(buffer_size + 1);
+ if(!meeting_request_stream) {
+ EM_DEBUG_EXCEPTION("em_convert_byte_stream_to_mail_data failed");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+ parameter_data = ipcEmailAPI_GetParameter(a_hAPI, ePARAMETER_IN, parameter_index++);
+
+ if(!parameter_data) {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_GetParameter failed");
+ err = EMF_ERROR_ON_PARSING;
+ goto FINISH_OFF;
+ }
+
+ memcpy(meeting_request_stream, parameter_data, buffer_size);
+ result_meeting_request = (emf_meeting_request_t*)em_core_malloc(sizeof(emf_meeting_request_t));
+ if(result_meeting_request)
+ em_convert_byte_stream_to_meeting_req(meeting_request_stream, result_meeting_request);
+ }
+ }
+
+ EM_DEBUG_LOG("sync_server");
+ memcpy(&sync_server, ipcEmailAPI_GetParameter(a_hAPI, ePARAMETER_IN, parameter_index++), sizeof(int));
+
+ if( (err = emf_add_mail(result_mail_data, result_attachment_data, result_attachment_data_count, result_meeting_request, sync_server)) != EMF_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("emf_add_mail failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ local_result = 1;
+ if(!ipcEmailAPI_AddParameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed");
+ if(!ipcEmailAPI_AddParameter(a_hAPI, ePARAMETER_OUT, &(result_mail_data->mail_id), sizeof(int)))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed");
+ if(!ipcEmailAPI_AddParameter(a_hAPI, ePARAMETER_OUT, &(result_mail_data->thread_id), sizeof(int)))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed");
+ if (!ipcEmailStub_ExecuteAPI(a_hAPI))
+ EM_DEBUG_EXCEPTION("ipcEmailStub_ExecuteAPI failed");
+
+FINISH_OFF:
+ if ( local_result == 0 ) {
+ if(!ipcEmailAPI_AddParameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed");
+ if (!ipcEmailStub_ExecuteAPI(a_hAPI))
+ EM_DEBUG_EXCEPTION("ipcEmailStub_ExecuteAPI failed");
+ }
+
+ EM_SAFE_FREE(mail_data_stream);
+ EM_SAFE_FREE(attachment_data_list_stream);
+ EM_SAFE_FREE(meeting_request_stream);
+
+ if(result_mail_data)
+ em_core_free_mail_data(&result_mail_data, 1, NULL);
+
+ if(result_attachment_data)
+ em_core_free_attachment_data(&result_attachment_data, result_attachment_data_count, NULL);
+
+ if(result_meeting_request)
+ em_storage_free_meeting_request(&result_meeting_request, 1, NULL);
+
+ em_core_flush_memory();
+ EM_DEBUG_FUNC_END();
+}
+
+
+void stb_update_mail(HIPC_API a_hAPI)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int buffer_size = 0;
+ int local_result = 0;
+ int result_mail_data_count = 0;
+ int result_attachment_data_count = 0;
+ int parameter_index = 0;
+ int sync_server = 0;
+ int err = EMF_ERROR_NONE;
+ char *mail_data_stream = NULL;
+ char *attachment_data_list_stream = NULL;
+ char *meeting_request_stream = NULL;
+ char *parameter_data = NULL;
+ emf_mail_data_t *result_mail_data = NULL;
+ emf_attachment_data_t *result_attachment_data = NULL;
+ emf_meeting_request_t *result_meeting_request = NULL;
+
+ EM_DEBUG_LOG("emf_mail_data_t");
+ buffer_size = ipcEmailAPI_GetParameterLength(a_hAPI, ePARAMETER_IN, parameter_index);
+
+ if(buffer_size > 0) {
+ mail_data_stream = (char*)em_core_malloc(buffer_size + 1);
+ if(!mail_data_stream) {
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+ parameter_data = ipcEmailAPI_GetParameter(a_hAPI, ePARAMETER_IN, parameter_index++);
+
+ if(!parameter_data) {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_GetParameter failed");
+ err = EMF_ERROR_ON_PARSING;
+ goto FINISH_OFF;
+ }
+
+ memcpy(mail_data_stream, parameter_data, buffer_size);
+
+ em_convert_byte_stream_to_mail_data(mail_data_stream, &result_mail_data, &result_mail_data_count);
+ if(!result_mail_data) {
+ EM_DEBUG_EXCEPTION("em_convert_byte_stream_to_mail_data failed");
+ err = EMF_ERROR_ON_PARSING;
+ goto FINISH_OFF;
+ }
+ }
+
+ buffer_size = ipcEmailAPI_GetParameterLength(a_hAPI, ePARAMETER_IN, parameter_index);
+ EM_DEBUG_LOG("emf_attachment_data_t buffer_size[%d]", buffer_size);
+
+ if(buffer_size > 0) {
+ attachment_data_list_stream = (char*)em_core_malloc(buffer_size + 1);
+ if(!attachment_data_list_stream) {
+ EM_DEBUG_EXCEPTION("em_core_malloc failed");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ parameter_data = ipcEmailAPI_GetParameter(a_hAPI, ePARAMETER_IN, parameter_index++);
+
+ if(!parameter_data) {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_GetParameter failed");
+ err = EMF_ERROR_ON_PARSING;
+ goto FINISH_OFF;
+ }
+
+ memcpy(attachment_data_list_stream, parameter_data, buffer_size);
+
+ em_convert_byte_stream_to_attachment_data(attachment_data_list_stream, &result_attachment_data, &result_attachment_data_count);
+
+ EM_DEBUG_LOG("result_attachment_data_count[%d]", result_attachment_data_count);
+
+ if(result_attachment_data_count && !result_attachment_data) {
+ EM_DEBUG_EXCEPTION("em_convert_byte_stream_to_attachment_data failed");
+ err = EMF_ERROR_ON_PARSING;
+ goto FINISH_OFF;
+ }
+ }
+
+ EM_DEBUG_LOG("emf_meeting_request_t");
+
+ if ( result_mail_data->meeting_request_status == EMF_MAIL_TYPE_MEETING_REQUEST
+ || result_mail_data->meeting_request_status == EMF_MAIL_TYPE_MEETING_RESPONSE
+ || result_mail_data->meeting_request_status == EMF_MAIL_TYPE_MEETING_ORIGINATINGREQUEST) {
+ buffer_size = ipcEmailAPI_GetParameterLength(a_hAPI, ePARAMETER_IN, parameter_index);
+
+ if(buffer_size > 0) {
+ meeting_request_stream = (char*)em_core_malloc(buffer_size + 1);
+ if(!meeting_request_stream) {
+ EM_DEBUG_EXCEPTION("em_convert_byte_stream_to_mail_data failed");
+ err = EMF_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+ parameter_data = ipcEmailAPI_GetParameter(a_hAPI, ePARAMETER_IN, parameter_index++);
+
+ if(!parameter_data) {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_GetParameter failed");
+ err = EMF_ERROR_ON_PARSING;
+ goto FINISH_OFF;
+ }
+
+ memcpy(meeting_request_stream, parameter_data, buffer_size);
+ result_meeting_request = (emf_meeting_request_t*)em_core_malloc(sizeof(emf_meeting_request_t));
+ if(result_meeting_request)
+ em_convert_byte_stream_to_meeting_req(meeting_request_stream, result_meeting_request);
+ }
+ }
+
+ EM_DEBUG_LOG("sync_server");
+ memcpy(&sync_server, ipcEmailAPI_GetParameter(a_hAPI, ePARAMETER_IN, parameter_index++), sizeof(int));
+
+ if( (err = emf_update_mail(result_mail_data, result_attachment_data, result_attachment_data_count, result_meeting_request, sync_server)) != EMF_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("emf_update_mail failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ local_result = 1;
+ if(!ipcEmailAPI_AddParameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed");
+ if(!ipcEmailAPI_AddParameter(a_hAPI, ePARAMETER_OUT, &(result_mail_data->mail_id), sizeof(int)))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed");
+ if(!ipcEmailAPI_AddParameter(a_hAPI, ePARAMETER_OUT, &(result_mail_data->thread_id), sizeof(int)))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed");
+ if (!ipcEmailStub_ExecuteAPI(a_hAPI))
+ EM_DEBUG_EXCEPTION("ipcEmailStub_ExecuteAPI failed");
+
+FINISH_OFF:
+ if ( local_result == 0 ) {
+ if(!ipcEmailAPI_AddParameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed");
+ if (!ipcEmailStub_ExecuteAPI(a_hAPI))
+ EM_DEBUG_EXCEPTION("ipcEmailStub_ExecuteAPI failed");
+ }
+
+ EM_SAFE_FREE(mail_data_stream);
+ EM_SAFE_FREE(attachment_data_list_stream);
+ EM_SAFE_FREE(meeting_request_stream);
+
+ if(result_mail_data)
+ em_core_free_mail_data(&result_mail_data, 1, NULL);
+
+ if(result_attachment_data)
+ em_core_free_attachment_data(&result_attachment_data, result_attachment_data_count, NULL);
+
+ if(result_meeting_request)
+ em_storage_free_meeting_request(&result_meeting_request, 1, NULL);
+
+ em_core_flush_memory();
+ EM_DEBUG_FUNC_END();
+}
+
+
+void stb_move_thread_to_mailbox(HIPC_API a_hAPI)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int buffer_size = 0, thread_id = 0, move_always_flag = 0;
+ int err = EMF_ERROR_NONE;
+ char *target_mailbox_name = NULL;
+
+ memcpy(&thread_id, ipcEmailAPI_GetParameter(a_hAPI, ePARAMETER_IN, 0), sizeof(int));
+ EM_DEBUG_LOG("thread_id [%d]", thread_id);
+
+ buffer_size = ipcEmailAPI_GetParameterLength(a_hAPI, ePARAMETER_IN, 1);
+ EM_DEBUG_LOG("mailbox stream size [%d]", buffer_size);
+
+ if(buffer_size > 0) {
+ target_mailbox_name = (char*)em_core_malloc(buffer_size + 1);
+ EM_NULL_CHECK_FOR_VOID(target_mailbox_name);
+ if(target_mailbox_name) {
+ memcpy(target_mailbox_name, ipcEmailAPI_GetParameter(a_hAPI, ePARAMETER_IN, 1), buffer_size);
+ /* Convert Byte stream to mailbox structure */
+ if (target_mailbox_name)
+ EM_DEBUG_LOG("Mailbox name - %s", target_mailbox_name);
+ else
+ EM_DEBUG_EXCEPTION("Mailbox name is NULL");
+ }
+ }
+
+ memcpy(&move_always_flag, ipcEmailAPI_GetParameter(a_hAPI, ePARAMETER_IN, 2), sizeof(int));
+ EM_DEBUG_LOG("move_always_flag [%d]", move_always_flag);
+
+ if(emf_mail_move_thread_to_mailbox(thread_id, target_mailbox_name, move_always_flag, &err))
+ EM_DEBUG_LOG("emf_mail_move_thread_to_mailbox success");
+
+ if(!ipcEmailAPI_AddParameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int))) {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter fail");
+ EM_SAFE_FREE(target_mailbox_name);
+ return;
+ }
+
+ if (!ipcEmailStub_ExecuteAPI(a_hAPI)) {
+ EM_DEBUG_EXCEPTION("ipcEmailStub_ExecuteAPI fail");
+ EM_SAFE_FREE(target_mailbox_name);
+ return;
+ }
+
+ EM_SAFE_FREE(target_mailbox_name);
+ EM_DEBUG_FUNC_END();
+}
+
+void stb_delete_thread(HIPC_API a_hAPI)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ int thread_id = 0, delete_always_flag = 0;
+ unsigned int handle = 0;
+ int err = EMF_ERROR_NONE;
+
+ memcpy(&thread_id, ipcEmailAPI_GetParameter(a_hAPI, ePARAMETER_IN, 0), sizeof(int));
+ EM_DEBUG_LOG("thread_id [%d]", thread_id);
+
+ memcpy(&delete_always_flag, ipcEmailAPI_GetParameter(a_hAPI, ePARAMETER_IN, 1), sizeof(int));
+ EM_DEBUG_LOG("delete_always_flag [%d]", delete_always_flag);
+
+ if(emf_mail_delete_thread(thread_id, delete_always_flag, &handle, &err))
+ EM_DEBUG_LOG("emf_mail_delete_thread success");
+
+ if(!ipcEmailAPI_AddParameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int))) {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter fail");
+ return;
+ }
+
+ if (!ipcEmailStub_ExecuteAPI(a_hAPI)) {
+ EM_DEBUG_EXCEPTION("ipcEmailStub_ExecuteAPI fail");
+ return;
+ }
+ EM_DEBUG_FUNC_END();
+}
+
+void stb_modify_seen_flag_of_thread(HIPC_API a_hAPI)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ int thread_id = 0, seen_flag = 0, on_server = 0;
+ unsigned int handle = 0;
+ int err = EMF_ERROR_NONE;
+
+ memcpy(&thread_id, ipcEmailAPI_GetParameter(a_hAPI, ePARAMETER_IN, 0), sizeof(int));
+ EM_DEBUG_LOG("thread_id [%d]", thread_id);
+
+ memcpy(&seen_flag, ipcEmailAPI_GetParameter(a_hAPI, ePARAMETER_IN, 1), sizeof(int));
+ EM_DEBUG_LOG("seen_flag [%d]", seen_flag);
+
+ memcpy(&on_server, ipcEmailAPI_GetParameter(a_hAPI, ePARAMETER_IN, 2), sizeof(int));
+ EM_DEBUG_LOG("on_server [%d]", on_server);
+
+ if(emf_mail_modify_seen_flag_of_thread(thread_id, seen_flag, on_server, &handle, &err))
+ EM_DEBUG_LOG("emf_mail_modify_seen_flag_of_thread success");
+
+ if(!ipcEmailAPI_AddParameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int))) {
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter fail");
+ return;
+ }
+
+ if (!ipcEmailStub_ExecuteAPI(a_hAPI)) {
+ EM_DEBUG_EXCEPTION("ipcEmailStub_ExecuteAPI fail");
+ return;
+ }
+ EM_DEBUG_FUNC_END();
+}
+
+
+void stb_mail_move(HIPC_API a_hAPI)
+{
+ int err = EMF_ERROR_NONE;
+ int buffer_size = 0, num = 0, counter = 0;
+ char *local_stream = NULL;
+ emf_mailbox_t mailbox;
+
+ /* Number of mail_ids */
+ memcpy(&num, ipcEmailAPI_GetParameter(a_hAPI, ePARAMETER_IN, 0), sizeof(int));
+ EM_DEBUG_LOG("number of mails [%d]", num);
+
+ /* mail_id */
+ int mail_ids[num];
+ memcpy(mail_ids, ipcEmailAPI_GetParameter(a_hAPI, ePARAMETER_IN, 1), num * sizeof(int));
+
+ for(counter = 0; counter < num; counter++)
+ EM_DEBUG_LOG("mailids [%d]", mail_ids[counter]);
+
+ buffer_size = ipcEmailAPI_GetParameterLength(a_hAPI, ePARAMETER_IN, 2);
+ EM_DEBUG_LOG("size [%d]", buffer_size);
+
+ if(buffer_size > 0) {
+ local_stream = (char*)em_core_malloc(buffer_size+1);
+ EM_NULL_CHECK_FOR_VOID(local_stream);
+ if(local_stream) {
+ memcpy(local_stream, ipcEmailAPI_GetParameter(a_hAPI, ePARAMETER_IN, 2), buffer_size);
+ em_convert_byte_stream_to_mailbox(local_stream, &mailbox);
+ EM_SAFE_FREE(local_stream);
+
+ if (mailbox.name)
+ EM_DEBUG_LOG("mailbox.name [%s]", mailbox.name);
+ else
+ EM_DEBUG_EXCEPTION("mailbox.name is NULL");
+
+ if(emf_mail_move(mail_ids, num, &mailbox, EMF_MOVED_BY_COMMAND, 0, &err))
+ EM_DEBUG_LOG("emf_mail_move success");
+ }
+ }
+
+ if(!ipcEmailAPI_AddParameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter fail");
+
+ if (!ipcEmailStub_ExecuteAPI(a_hAPI))
+ EM_DEBUG_EXCEPTION("ipcEmailStub_ExecuteAPI fail");
+ EM_DEBUG_FUNC_END();
+}
+
+void stb_rule_delete(HIPC_API a_hAPI)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ int filter_id = 0;
+ int err = EMF_ERROR_NONE;
+
+ /* filter_id */
+ memcpy(&filter_id, ipcEmailAPI_GetParameter(a_hAPI, ePARAMETER_IN, 0), sizeof(int));;
+
+ if(emf_filter_delete(filter_id, &err))
+ err = EMF_ERROR_NONE;
+
+ if(!ipcEmailAPI_AddParameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed ");
+
+ if (!ipcEmailStub_ExecuteAPI(a_hAPI))
+ EM_DEBUG_EXCEPTION("ipcEmailStub_ExecuteAPI failed ");
+ EM_DEBUG_FUNC_END();
+}
+
+void stb_mail_add_attachment(HIPC_API a_hAPI)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int buffer_size = 0;
+ int err = EMF_ERROR_NONE;
+ char* local_stream = NULL;
+ emf_mailbox_t mailbox;
+ int mail_id = -1;
+ char* attachment_stream = NULL;
+ emf_attachment_info_t* attachment = NULL;
+
+ /* mailbox */
+ EM_DEBUG_LOG("mailbox");
+ buffer_size = ipcEmailAPI_GetParameterLength(a_hAPI, ePARAMETER_IN, 0);
+
+ if(buffer_size > 0) {
+ local_stream = (char*)em_core_malloc(buffer_size+1);
+ EM_NULL_CHECK_FOR_VOID(local_stream);
+ if(local_stream) {
+ memcpy(local_stream, ipcEmailAPI_GetParameter(a_hAPI, ePARAMETER_IN, 0), buffer_size);
+ em_convert_byte_stream_to_mailbox(local_stream, &mailbox);
+ EM_SAFE_FREE(local_stream);
+ }
+ }
+
+ /* mail_id */
+ memcpy(&mail_id, ipcEmailAPI_GetParameter(a_hAPI, ePARAMETER_IN, 1), sizeof(int));
+
+ /* attachment */
+ buffer_size = ipcEmailAPI_GetParameterLength(a_hAPI, ePARAMETER_IN, 2);
+
+ if(buffer_size > 0) {
+ attachment_stream = (char*)em_core_malloc(buffer_size+1);
+ EM_NULL_CHECK_FOR_VOID(attachment_stream);
+ if(attachment_stream) {
+ memcpy(attachment_stream, ipcEmailAPI_GetParameter(a_hAPI, ePARAMETER_IN, 2), buffer_size);
+ em_convert_byte_stream_to_attachment_info(attachment_stream, 1, &attachment);
+ EM_SAFE_FREE(attachment_stream);
+ }
+ }
+
+ emf_mail_add_attachment(&mailbox, mail_id, attachment, &err);
+
+ if(!ipcEmailAPI_AddParameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter local_result failed ");
+ if(EMF_ERROR_NONE == err) {
+ EM_DEBUG_LOG("emf_mail_add_attachment -Success");
+
+ if(!ipcEmailAPI_AddParameter(a_hAPI, ePARAMETER_OUT, &(attachment->attachment_id), sizeof(int)))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter attachment_id failed ");
+ }
+ if (!ipcEmailStub_ExecuteAPI(a_hAPI))
+ EM_DEBUG_EXCEPTION("ipcEmailStub_ExecuteAPI failed ");
+
+ EM_SAFE_FREE(attachment);
+ EM_DEBUG_FUNC_END();
+}
+
+void stb_mail_get_attachment(HIPC_API a_hAPI)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int buffer_size = 0;
+ int err = EMF_ERROR_NONE;
+ char* local_stream = NULL;
+ emf_mailbox_t mailbox;
+ int mail_id = -1;
+ char* attachment_no = NULL;
+ char* attachment_stream = NULL;
+ emf_attachment_info_t* attachment = NULL;
+ int size = 0;
+
+ /* mailbox */
+ EM_DEBUG_LOG("mailbox");
+ buffer_size = ipcEmailAPI_GetParameterLength(a_hAPI, ePARAMETER_IN, 0);
+
+ if(buffer_size > 0) {
+ local_stream = (char*)em_core_malloc(buffer_size+1);
+ EM_NULL_CHECK_FOR_VOID(local_stream);
+ if(local_stream) {
+ memcpy(local_stream, ipcEmailAPI_GetParameter(a_hAPI, ePARAMETER_IN, 0), buffer_size);
+ em_convert_byte_stream_to_mailbox(local_stream, &mailbox);
+ EM_SAFE_FREE(local_stream);
+ }
+ }
+
+ /* mail_id */
+ memcpy(&mail_id, ipcEmailAPI_GetParameter(a_hAPI, ePARAMETER_IN, 1), sizeof(int));
+
+ /* attachment_no */
+ buffer_size = ipcEmailAPI_GetParameterLength(a_hAPI, ePARAMETER_IN, 2);
+ if(buffer_size > 0) {
+ attachment_no = (char*)em_core_malloc(buffer_size+1);
+ if(attachment_no) {
+ memcpy(attachment_no, ipcEmailAPI_GetParameter(a_hAPI, ePARAMETER_IN, 2), buffer_size);
+ }
+ }
+ emf_mail_get_attachment(&mailbox, mail_id, attachment_no, &attachment, &err);
+
+ if(!ipcEmailAPI_AddParameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter local_result failed ");
+ if(EMF_ERROR_NONE == err) {
+ EM_DEBUG_LOG("emf_mail_get_attachment - Success");
+ /* attachment */
+ attachment_stream = em_convert_attachment_info_to_byte_stream(attachment, &size);
+
+ EM_NULL_CHECK_FOR_VOID(attachment_stream);
+
+ if(!ipcEmailAPI_AddParameter(a_hAPI, ePARAMETER_OUT, attachment_stream, size))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed ");
+ }
+ if (!ipcEmailStub_ExecuteAPI(a_hAPI)) {
+ EM_DEBUG_EXCEPTION("ipcEmailStub_ExecuteAPI failed ");
+ EM_SAFE_FREE(attachment_no);
+ EM_SAFE_FREE(attachment_stream);
+ return;
+ }
+
+ EM_SAFE_FREE(attachment_no);
+ EM_SAFE_FREE(attachment_stream);
+ EM_DEBUG_FUNC_END();
+}
+
+void stb_mailbox_get_imap_mailbox_list(HIPC_API a_hAPI)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int err = EMF_ERROR_NONE;
+ int account_id = 0;
+ unsigned int handle = 0;
+
+ /* account_id */
+ memcpy(&account_id, ipcEmailAPI_GetParameter(a_hAPI, ePARAMETER_IN, 0), sizeof(int));
+
+ if(emf_mailbox_get_imap_mailbox_list(account_id, "", &handle, &err))
+ err = EMF_ERROR_NONE;
+
+ if(!ipcEmailAPI_AddParameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
+ EM_DEBUG_LOG("ipcAPI_AddParameter local_result failed ");
+ if(!ipcEmailAPI_AddParameter(a_hAPI, ePARAMETER_OUT, &handle, sizeof(int)))
+ EM_DEBUG_LOG("ipcAPI_AddParameter local_result failed ");
+ if (!ipcEmailStub_ExecuteAPI(a_hAPI))
+ EM_DEBUG_LOG("ipcEmailStub_ExecuteAPI failed ");
+ EM_DEBUG_FUNC_END();
+}
+
+void stb_mail_delete_attachment(HIPC_API a_hAPI)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int buffer_size = 0;
+ int err = EMF_ERROR_NONE;
+ char* local_stream = NULL;
+ emf_mailbox_t mailbox;
+ int mail_id = -1;
+ char* attachment_no = NULL;
+
+ /* mailbox */
+ EM_DEBUG_LOG("mailbox");
+ buffer_size = ipcEmailAPI_GetParameterLength(a_hAPI, ePARAMETER_IN, 0);
+
+ if(buffer_size > 0) {
+ local_stream = (char*)em_core_malloc(buffer_size+1);
+ EM_NULL_CHECK_FOR_VOID(local_stream);
+ if(local_stream) {
+ memcpy(local_stream, ipcEmailAPI_GetParameter(a_hAPI, ePARAMETER_IN, 0), buffer_size);
+ em_convert_byte_stream_to_mailbox(local_stream, &mailbox);
+ EM_SAFE_FREE(local_stream);
+ }
+ }
+
+ /* mail_id */
+ memcpy(&mail_id, ipcEmailAPI_GetParameter(a_hAPI, ePARAMETER_IN, 1), sizeof(int));
+
+ /* attachment_no */
+ buffer_size = ipcEmailAPI_GetParameterLength(a_hAPI, ePARAMETER_IN, 2);
+ if(buffer_size > 0) {
+ attachment_no = (char*)em_core_malloc(buffer_size+1);
+ if(attachment_no) {
+ memcpy(attachment_no, ipcEmailAPI_GetParameter(a_hAPI, ePARAMETER_IN, 2), buffer_size);
+ }
+ }
+
+ emf_mail_delete_attachment(&mailbox, mail_id, attachment_no, &err);
+
+ if(!ipcEmailAPI_AddParameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter local_result failed ");
+ if (!ipcEmailStub_ExecuteAPI(a_hAPI))
+ EM_DEBUG_EXCEPTION("ipcEmailStub_ExecuteAPI failed ");
+
+ EM_SAFE_FREE(attachment_no);
+ EM_DEBUG_FUNC_END();
+}
+
+void stb_download_attachment(HIPC_API a_hAPI)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ int buffer_size = 0;
+ int err = EMF_ERROR_NONE;
+ char* local_stream = NULL;
+ emf_mailbox_t mailbox;
+ int mail_id = 0;
+ char *nth = NULL;
+ unsigned int handle = 0;
+
+ EM_DEBUG_LOG("mailbox");
+ buffer_size = ipcEmailAPI_GetParameterLength(a_hAPI, ePARAMETER_IN, 0);
+
+ if(buffer_size > 0) {
+ local_stream = (char*)em_core_malloc(buffer_size+1);
+ EM_NULL_CHECK_FOR_VOID(local_stream);
+ if(local_stream) {
+ memcpy(local_stream, ipcEmailAPI_GetParameter(a_hAPI, ePARAMETER_IN, 0), buffer_size);
+ em_convert_byte_stream_to_mailbox(local_stream, &mailbox);
+ EM_SAFE_FREE(local_stream);
+ }
+ }
+
+ EM_DEBUG_LOG("mail_id");
+ memcpy(&mail_id, ipcEmailAPI_GetParameter(a_hAPI, ePARAMETER_IN, 1), sizeof(int));
+
+ /* nth */
+ EM_DEBUG_LOG("nth");
+ buffer_size = ipcEmailAPI_GetParameterLength(a_hAPI, ePARAMETER_IN, 2);
+ if(buffer_size > 0) {
+ nth = (char*)em_core_malloc(buffer_size+1);
+ if(nth) {
+ memcpy(nth, ipcEmailAPI_GetParameter(a_hAPI, ePARAMETER_IN, 2), buffer_size);
+ }
+ }
+
+ if(emf_mail_download_attachment(&mailbox, mail_id, nth, &handle, &err)) {
+ err = EMF_ERROR_NONE;
+
+ if(!ipcEmailAPI_AddParameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed ");
+ EM_DEBUG_LOG(">>>>>>>>>> HANDLE = %d", handle);
+ if(!ipcEmailAPI_AddParameter(a_hAPI, ePARAMETER_OUT, &handle, sizeof(int)))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter handle failed ");
+ if (!ipcEmailStub_ExecuteAPI(a_hAPI))
+ EM_DEBUG_EXCEPTION("ipcEmailStub_ExecuteAPI failed ");
+ }
+ else {
+ if(!ipcEmailAPI_AddParameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed ");
+ /* Download handle - 17-Apr-09 */
+ EM_DEBUG_LOG(">>>>>>>>>> HANDLE = %d", handle);
+ if(!ipcEmailAPI_AddParameter(a_hAPI, ePARAMETER_OUT, &handle, sizeof(int)))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter handle failed ");
+ if (!ipcEmailStub_ExecuteAPI(a_hAPI))
+ EM_DEBUG_EXCEPTION("ipcEmailStub_ExecuteAPI failed ");
+ }
+
+ EM_SAFE_FREE(nth);
+ EM_DEBUG_FUNC_END();
+}
+
+void stb_get_info(HIPC_API a_hAPI)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int buffer_size = 0;
+ int err = EMF_ERROR_NONE;
+ char* local_stream = NULL;
+ char* local_info_stream = NULL;
+ emf_mailbox_t mailbox = { 0 };
+ int mail_id = 0;
+ emf_mail_info_t* info = NULL;
+ int size =0;
+
+ EM_DEBUG_LOG("mailbox");
+ buffer_size = ipcEmailAPI_GetParameterLength(a_hAPI, ePARAMETER_IN, 0);
+
+ if(buffer_size > 0) {
+ local_stream = (char*)em_core_malloc(buffer_size+1);
+ EM_NULL_CHECK_FOR_VOID(local_stream);
+ if(local_stream) {
+ memcpy(local_stream, ipcEmailAPI_GetParameter(a_hAPI, ePARAMETER_IN, 0), buffer_size);
+ em_convert_byte_stream_to_mailbox(local_stream, &mailbox);
+ EM_SAFE_FREE(local_stream);
+ }
+ }
+
+ EM_DEBUG_LOG("mail_id");
+ memcpy(&mail_id, ipcEmailAPI_GetParameter(a_hAPI, ePARAMETER_IN, 1), sizeof(int));
+
+ emf_mail_get_info(&mailbox, mail_id, &info, &err);
+
+ if(!ipcEmailAPI_AddParameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed ");
+ if(EMF_ERROR_NONE == err) {
+ EM_DEBUG_LOG("emf_mail_get_info - success");
+ /* Info */
+ EM_DEBUG_LOG("emf_mail_get_info - convert mail Info");
+ local_info_stream = em_convert_mail_info_to_byte_stream(info, &size);
+
+ EM_NULL_CHECK_FOR_VOID(local_info_stream);
+
+ if(!ipcEmailAPI_AddParameter(a_hAPI, ePARAMETER_OUT, local_info_stream, size))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed ");
+ }
+
+ if (!ipcEmailStub_ExecuteAPI(a_hAPI))
+ EM_DEBUG_EXCEPTION("ipcEmailStub_ExecuteAPI failed ");
+
+ EM_SAFE_FREE(local_info_stream);
+ EM_DEBUG_FUNC_END();
+}
+
+void stb_get_header_info(HIPC_API a_hAPI)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int buffer_size = 0;
+ int err = EMF_ERROR_NONE;
+ char* local_stream = NULL;
+ emf_mailbox_t mailbox;
+ int mail_id = 0;
+ emf_mail_head_t* head = NULL;
+ int size =0;
+ char* local_head_stream = NULL;
+
+ EM_DEBUG_LOG("mailbox");
+ buffer_size = ipcEmailAPI_GetParameterLength(a_hAPI, ePARAMETER_IN, 0);
+
+ if(buffer_size > 0) {
+ local_stream = (char*)em_core_malloc(buffer_size+1);
+ EM_NULL_CHECK_FOR_VOID(local_stream);
+ if(local_stream) {
+ memcpy(local_stream, ipcEmailAPI_GetParameter(a_hAPI, ePARAMETER_IN, 0), buffer_size);
+ em_convert_byte_stream_to_mailbox(local_stream, &mailbox);
+ EM_SAFE_FREE(local_stream);
+ }
+ }
+
+ EM_DEBUG_LOG("mail_id");
+ memcpy(&mail_id, ipcEmailAPI_GetParameter(a_hAPI, ePARAMETER_IN, 1), sizeof(int));
+
+ emf_mail_get_head(&mailbox, mail_id, &head, &err);
+
+ if(!ipcEmailAPI_AddParameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed ");
+
+ if(EMF_ERROR_NONE == err) {
+ EM_DEBUG_LOG("success");
+ /* Head */
+ EM_DEBUG_LOG("convert mail head");
+ local_head_stream = em_convert_mail_head_to_byte_stream(head, &size);
+
+ EM_NULL_CHECK_FOR_VOID(local_head_stream);
+
+ if(!ipcEmailAPI_AddParameter(a_hAPI, ePARAMETER_OUT, local_head_stream, size))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed");
+ }
+ if (!ipcEmailStub_ExecuteAPI(a_hAPI))
+ EM_DEBUG_EXCEPTION("ipcEmailStub_ExecuteAPI failed");
+
+ EM_SAFE_FREE(local_head_stream);
+ EM_DEBUG_FUNC_END();
+}
+
+void stb_get_mail_body_info(HIPC_API a_hAPI)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int buffer_size = 0;
+ int err = EMF_ERROR_NONE;
+ char* local_stream = NULL;
+ char* local_body_stream = NULL;
+ emf_mailbox_t mailbox = { 0 };
+ emf_mail_body_t* body = NULL;
+ int size =0;
+ int mail_id = 0;
+
+ EM_DEBUG_LOG("mailbox");
+ buffer_size = ipcEmailAPI_GetParameterLength(a_hAPI, ePARAMETER_IN, 0);
+
+ if(buffer_size > 0) {
+ local_stream = (char*)em_core_malloc(buffer_size+1);
+ EM_NULL_CHECK_FOR_VOID(local_stream);
+ if(local_stream) {
+ memcpy(local_stream, ipcEmailAPI_GetParameter(a_hAPI, ePARAMETER_IN, 0), buffer_size);
+ em_convert_byte_stream_to_mailbox(local_stream, &mailbox);
+ EM_SAFE_FREE(local_stream);
+ }
+ }
+
+ EM_DEBUG_LOG("mail_id");
+ memcpy(&mail_id, ipcEmailAPI_GetParameter(a_hAPI, ePARAMETER_IN, 1), sizeof(int));
+
+ emf_mail_get_body(&mailbox, mail_id, &body, &err);
+
+ if(!ipcEmailAPI_AddParameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter local_result failed ");
+
+ if(EMF_ERROR_NONE == err) {
+ EM_DEBUG_LOG("success");
+ /* Body */
+ EM_DEBUG_LOG("convert mail Body[%p]", body);
+
+ local_body_stream = em_convert_mail_body_to_byte_stream(body, &size);
+
+ /* EM_NULL_CHECK_FOR_VOID(local_body_stream); */
+ if ( !local_body_stream ) {
+ EM_DEBUG_EXCEPTION("local_body_stream is NULL");
+ }
+ else {
+ if(!ipcEmailAPI_AddParameter(a_hAPI, ePARAMETER_OUT, local_body_stream, size))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed");
+ }
+ }
+
+ EM_DEBUG_LOG("Before ipcEmailStub_ExecuteAPI");
+ if (!ipcEmailStub_ExecuteAPI(a_hAPI)) {
+ EM_DEBUG_EXCEPTION("ipcEmailStub_ExecuteAPI failed ");
+ EM_SAFE_FREE(local_body_stream);
+ return;
+ }
+
+ EM_SAFE_FREE(local_body_stream);
+ EM_DEBUG_FUNC_END();
+}
+
+void stb_mail_send_saved(HIPC_API a_hAPI)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int buffer_size = 0;
+ int err = EMF_ERROR_NONE;
+ char* local_option_stream = NULL;
+ emf_option_t sending_option;
+ int account_id = 0;
+ /* unsigned *handle = NULL; */
+
+ /* account_id */
+ memcpy(&account_id, ipcEmailAPI_GetParameter(a_hAPI, ePARAMETER_IN, 0), sizeof(int));
+
+ /* Sending Option */
+ EM_DEBUG_LOG("Sending option");
+ buffer_size = ipcEmailAPI_GetParameterLength(a_hAPI, ePARAMETER_IN, 1);
+
+ if(buffer_size > 0) {
+ local_option_stream = (char*)em_core_malloc(buffer_size+1);
+ EM_NULL_CHECK_FOR_VOID(local_option_stream);
+ if(local_option_stream) {
+ memcpy(local_option_stream, ipcEmailAPI_GetParameter(a_hAPI, ePARAMETER_IN, 1), buffer_size);
+ em_convert_byte_stream_to_option(local_option_stream, &sending_option);
+ /* EM_SAFE_FREE(local_option_stream); */
+ }
+ }
+
+ EM_DEBUG_LOG("calling emf_mail_send_saved");
+ if(emf_mail_send_saved(account_id, &sending_option, NULL, &err))
+ err = EMF_ERROR_NONE;
+
+ if(!ipcEmailAPI_AddParameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter result failed ");
+
+ if (!ipcEmailStub_ExecuteAPI(a_hAPI))
+ EM_DEBUG_EXCEPTION("ipcEmailStub_ExecuteAPI failed ");
+ EM_DEBUG_FUNC_END();
+}
+
+void stb_mail_send_report(HIPC_API a_hAPI)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ int buffer_size = 0;
+ int err = EMF_ERROR_NONE;
+ char* local_mail_stream = NULL;
+ char* local_info_stream = NULL;
+ emf_mail_t mail = { 0 };
+
+ /* head */
+ buffer_size = ipcEmailAPI_GetParameterLength(a_hAPI, ePARAMETER_IN, 0);
+ EM_DEBUG_LOG("size [%d]", buffer_size);
+
+ if(buffer_size > 0) {
+ local_mail_stream = (char*)em_core_malloc(buffer_size+1);
+ if(local_mail_stream) {
+ memcpy(local_mail_stream, ipcEmailAPI_GetParameter(a_hAPI, ePARAMETER_IN, 0), buffer_size);
+ /* Convert Byte stream to Mail Head structure */
+ EM_DEBUG_LOG("Before em_convert_byte_stream_to_mail");
+ mail.head = (emf_mail_head_t*)em_core_malloc(sizeof(emf_mail_head_t));
+ /* EM_NULL_CHECK_FOR_VOID(mail.head); */
+ if(NULL == mail.head) {
+ EM_SAFE_FREE(local_mail_stream);
+ return;
+ }
+
+ em_convert_byte_stream_to_mail_head(local_mail_stream, mail.head);
+ EM_SAFE_FREE(local_mail_stream);
+ }
+ }
+
+ /* body */
+ buffer_size = ipcEmailAPI_GetParameterLength(a_hAPI, ePARAMETER_IN, 1);
+ if(buffer_size > 0) {
+ local_mail_stream = (char*)em_core_malloc(buffer_size+1);
+ EM_NULL_CHECK_FOR_VOID(local_mail_stream);
+ if(local_mail_stream) {
+ memcpy(local_mail_stream, ipcEmailAPI_GetParameter(a_hAPI, ePARAMETER_IN, 1), buffer_size);
+ /* Convert Byte stream to Mail Body structure */
+ EM_DEBUG_LOG("Before em_convert_byte_stream_to_mail");
+ mail.body = (emf_mail_body_t*)em_core_malloc(sizeof(emf_mail_body_t));
+ /* EM_NULL_CHECK_FOR_VOID(mail.body); */
+ if(NULL == mail.body) {
+ EM_SAFE_FREE(local_mail_stream);
+ return;
+ }
+
+ em_convert_byte_stream_to_mail_body(local_mail_stream, mail.body);
+ EM_SAFE_FREE(local_mail_stream);
+ }
+ }
+
+ /* info */
+ buffer_size = ipcEmailAPI_GetParameterLength(a_hAPI, ePARAMETER_IN, 2);
+ if(buffer_size > 0) {
+ local_info_stream = (char*)em_core_malloc(buffer_size+1);
+ EM_NULL_CHECK_FOR_VOID(local_info_stream);
+ if(local_info_stream) {
+ memcpy(local_info_stream, ipcEmailAPI_GetParameter(a_hAPI, ePARAMETER_IN, 2), buffer_size);
+ /* Convert Byte stream to Mail Info structure */
+ EM_DEBUG_LOG("Before em_convert_byte_stream_to_mail");
+ mail.info = (emf_mail_info_t*)em_core_malloc(sizeof(emf_mail_info_t));
+ /* EM_NULL_CHECK_FOR_VOID(mail.info); */
+
+ if(NULL == mail.info) {
+ EM_SAFE_FREE(local_info_stream);
+ return;
+ }
+
+ em_convert_byte_stream_to_mail_info(local_info_stream, mail.info);
+ EM_SAFE_FREE(local_info_stream);
+ }
+ }
+
+ if(emf_mail_send_report(&mail, NULL, &err))
+ err = EMF_ERROR_NONE;
+
+ if(!ipcEmailAPI_AddParameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed ");
+
+ if (!ipcEmailStub_ExecuteAPI(a_hAPI))
+ EM_DEBUG_EXCEPTION("ipcEmailStub_ExecuteAPI failed ");
+
+ EM_SAFE_FREE(mail.head);
+ EM_SAFE_FREE(mail.info);
+ EM_SAFE_FREE(mail.body);
+ EM_DEBUG_FUNC_END();
+}
+
+void stb_mail_send_retry(HIPC_API a_hAPI)
+{
+
+ EM_DEBUG_FUNC_BEGIN();
+ int mail_id = 0;
+ int timeout_in_sec = 0;
+ int err = EMF_ERROR_NONE;
+
+ /* Mail_id */
+ memcpy(&mail_id, ipcEmailAPI_GetParameter(a_hAPI, ePARAMETER_IN, 0), sizeof(int));
+ EM_DEBUG_LOG("mail_id [%d]", mail_id);
+
+ /* timeout_in_sec */
+ memcpy(&timeout_in_sec, ipcEmailAPI_GetParameter(a_hAPI, ePARAMETER_IN, 1), sizeof(int));
+ EM_DEBUG_LOG("mail_id [%d]", timeout_in_sec);
+
+ if(emf_mail_send_retry(mail_id, timeout_in_sec,&err))
+ EM_DEBUG_LOG("emf_mailbox_get_list - success");
+
+ if(!ipcEmailAPI_AddParameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed ");
+
+ if (!ipcEmailStub_ExecuteAPI(a_hAPI))
+ EM_DEBUG_EXCEPTION("ipcEmailStub_ExecuteAPI failed ");
+ EM_DEBUG_FUNC_END();
+}
+
+void stb_get_event_queue_status(HIPC_API a_hAPI)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int on_sending = 0;
+ int on_receiving = 0;
+
+ /*get the network status */
+ emf_get_event_queue_status(&on_sending, &on_receiving);
+
+ /* on_sending */
+ if(!ipcEmailAPI_AddParameter(a_hAPI, ePARAMETER_OUT, &on_sending, sizeof(int)))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed");
+
+ /* on_receving */
+ if(!ipcEmailAPI_AddParameter(a_hAPI, ePARAMETER_OUT, &on_receiving, sizeof(int)))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed");
+
+ EM_DEBUG_LOG("stb_get_event_queue_status - Before Execute API");
+ if (!ipcEmailStub_ExecuteAPI(a_hAPI))
+ EM_DEBUG_EXCEPTION("ipcEmailStub_ExecuteAPI failed");
+
+ EM_DEBUG_FUNC_END();
+}
+
+void stb_cancel_job(HIPC_API a_hAPI)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int account_id = 0;
+ int handle = 0;
+ int err = EMF_ERROR_NONE;
+
+ memcpy(&account_id, ipcEmailAPI_GetParameter(a_hAPI, ePARAMETER_IN, 0), sizeof(int));
+ EM_DEBUG_LOG("account_id [%d]", account_id);
+
+ memcpy(&handle, ipcEmailAPI_GetParameter(a_hAPI, ePARAMETER_IN, 1), sizeof(int));
+ EM_DEBUG_LOG("handle [%d]", handle);
+
+ if(emf_cancel_job(account_id, handle, &err))
+ err = EMF_ERROR_NONE;
+
+ if(!ipcEmailAPI_AddParameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter local_result failed ");
+ if (!ipcEmailStub_ExecuteAPI(a_hAPI))
+ EM_DEBUG_EXCEPTION("ipcEmailStub_ExecuteAPI failed ");
+ EM_DEBUG_FUNC_END();
+}
+
+void stb_get_pending_job(HIPC_API a_hAPI)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ emf_action_t action = -1;
+ int account_id = 0;
+ int mail_id = -1;
+ int err = EMF_ERROR_NONE;
+ emf_event_status_type_t status = 0;
+
+ memcpy(&action, ipcEmailAPI_GetParameter(a_hAPI, ePARAMETER_IN, 0), sizeof(int));
+ EM_DEBUG_LOG("action [%d]", action);
+
+ memcpy(&account_id, ipcEmailAPI_GetParameter(a_hAPI, ePARAMETER_IN, 1), sizeof(int));
+ EM_DEBUG_LOG("account_id [%d]", account_id);
+
+ memcpy(&mail_id, ipcEmailAPI_GetParameter(a_hAPI, ePARAMETER_IN, 2), sizeof(int));
+ EM_DEBUG_LOG("mail_id [%d]", mail_id);
+
+ if(emf_get_pending_job(action, account_id, mail_id, &status))
+ err = EMF_ERROR_NONE;
+ else
+ err = EMF_ERROR_UNKNOWN;
+
+ if(!ipcEmailAPI_AddParameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter local_result failed ");
+ if(!ipcEmailAPI_AddParameter(a_hAPI, ePARAMETER_OUT, &status, sizeof(int)))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter status failed ");
+ if (!ipcEmailStub_ExecuteAPI(a_hAPI))
+ EM_DEBUG_EXCEPTION("ipcEmailStub_ExecuteAPI failed ");
+ EM_DEBUG_FUNC_END();
+}
+
+void stb_print_receiving_event_queue_via_debug_msg(HIPC_API a_hAPI)
+{
+ emf_event_t *event_queue = NULL;
+ int event_active_queue = 0, err, i;
+
+ em_core_get_receiving_event_queue(&event_queue, &event_active_queue, &err);
+
+ EM_DEBUG_LOG("======================================================================");
+ EM_DEBUG_LOG("Event active index [%d]", event_active_queue);
+ EM_DEBUG_LOG("======================================================================");
+ for(i = 1; i < 32; i++)
+ EM_DEBUG_LOG("event[%d] : type[%d], account_id[%d], arg[%d], status[%d]", i, event_queue[i].type, event_queue[i].account_id, event_queue[i].event_param_data_4, event_queue[i].status);
+ EM_DEBUG_LOG("======================================================================");
+ EM_DEBUG_LOG("======================================================================");
+
+ if(!ipcEmailAPI_AddParameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed ");
+
+ if (!ipcEmailStub_ExecuteAPI(a_hAPI))
+ EM_DEBUG_EXCEPTION("ipcEmailStub_ExecuteAPI failed");
+ EM_DEBUG_FUNC_END();
+}
+
+void stb_send_mail_cancel_job(HIPC_API a_hAPI)
+{
+
+ EM_DEBUG_FUNC_BEGIN();
+ int mail_id = 0;
+ int err = EMF_ERROR_NONE;
+ int account_id = 0;
+
+
+ /* account_id */
+ memcpy(&account_id, ipcEmailAPI_GetParameter(a_hAPI, ePARAMETER_IN, 0), sizeof(int));
+ EM_DEBUG_LOG("account_id [%d]", account_id);
+
+
+ /* Mail_id */
+ memcpy(&mail_id, ipcEmailAPI_GetParameter(a_hAPI, ePARAMETER_IN, 1), sizeof(int));
+ EM_DEBUG_LOG("mail_id [%d]", mail_id);
+
+
+ if(emf_mail_send_mail_cancel_job(account_id,mail_id,&err))
+ EM_DEBUG_LOG("success");
+
+ if(!ipcEmailAPI_AddParameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed");
+
+ if (!ipcEmailStub_ExecuteAPI(a_hAPI))
+ EM_DEBUG_EXCEPTION("ipcEmailStub_ExecuteAPI failed");
+ EM_DEBUG_FUNC_END();
+}
+
+void stb_find_mail_on_server(HIPC_API a_hAPI)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ EM_DEBUG_FUNC_END();
+}
+
+void stb_account_create_with_validation(HIPC_API a_hAPI)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int buffer_size = 0;
+ int local_result = 0;
+ unsigned int handle = 0;
+ char* local_account_stream = NULL;
+ emf_account_t *account;
+ int err = EMF_ERROR_NONE;
+
+ buffer_size = ipcEmailAPI_GetParameterLength(a_hAPI, ePARAMETER_IN, 0);
+ EM_DEBUG_LOG("size [%d]", buffer_size);
+
+ if(buffer_size > 0) {
+ local_account_stream = (char*)em_core_malloc(buffer_size+1);
+ if(local_account_stream) {
+ memcpy(local_account_stream, ipcEmailAPI_GetParameter(a_hAPI, ePARAMETER_IN, 0), buffer_size);
+ /* Convert account stream to structure */
+ EM_DEBUG_LOG("Before Convert_ByteStream_To_Account");
+
+ account = em_core_account_get_new_account_ref();
+ em_convert_byte_stream_to_account(local_account_stream, account);
+ EM_SAFE_FREE(local_account_stream);
+
+ account->account_id = NEW_ACCOUNT_ID;
+
+ if (account->account_name)
+ EM_DEBUG_LOG("Account name - %s", account->account_name);
+ if(account->email_addr)
+ EM_DEBUG_LOG("Email Address - %s", account->email_addr);
+
+ if(emf_account_validate_and_create(account, &handle, &err)) {
+
+#ifdef __FEATURE_AUTO_POLLING__
+ /* start auto polling, if check_interval not zero */
+ if(account->check_interval > 0) {
+ if(!emf_add_polling_alarm( account->account_id,account->check_interval))
+ EM_DEBUG_EXCEPTION("emf_add_polling_alarm[NOTI_ACCOUNT_ADD] : start auto poll failed >>> ");
+ }
+#endif /* __FEATURE_AUTO_POLLING__ */
+ /* add account details to contact DB */
+ /* emf_account_insert_accountinfo_to_contact(account); */
+
+ local_result = 1;
+ if(!ipcEmailAPI_AddParameter(a_hAPI, ePARAMETER_OUT, &local_result, sizeof(int)))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed ");
+ if(!ipcEmailAPI_AddParameter(a_hAPI, ePARAMETER_OUT, &handle, sizeof(int)))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed ");
+ if (!ipcEmailStub_ExecuteAPI(a_hAPI))
+ EM_DEBUG_EXCEPTION("ipcEmailStub_ExecuteAPI failed ");
+ }
+ else {
+ EM_DEBUG_EXCEPTION("emf_account_validate_and_create fail ");
+ goto FINISH_OFF;
+ }
+ }
+ else {
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+ }
+ else {
+ err = EMF_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+FINISH_OFF:
+ if ( local_result == 0 ) {
+ if(!ipcEmailAPI_AddParameter(a_hAPI, ePARAMETER_OUT, &local_result, sizeof(int)))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed : local_result ");
+ if(!ipcEmailAPI_AddParameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed : err");
+ if (!ipcEmailStub_ExecuteAPI(a_hAPI))
+ EM_DEBUG_EXCEPTION("ipcEmailStub_ExecuteAPI failed ");
+ }
+ EM_DEBUG_FUNC_END();
+}
+
+void stb_account_backup(HIPC_API a_hAPI)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+#ifdef __FEATURE_BACKUP_ACCOUNT__
+ char *file_path = NULL;
+ int local_result = 0, err_code = 0, handle = 0, file_path_length = 0;
+
+ /* file_path_length */
+ file_path_length = ipcEmailAPI_GetParameterLength(a_hAPI, ePARAMETER_IN, 0);
+ if(file_path_length > 0) {
+ EM_DEBUG_LOG("file_path_length [%d]", file_path_length);
+ file_path = em_core_malloc(file_path_length + 1);
+ memcpy(file_path, ipcEmailAPI_GetParameter(a_hAPI, ePARAMETER_IN, 0), file_path_length);;
+ EM_DEBUG_LOG("file_path [%s]", file_path);
+ local_result = em_core_backup_accounts((const char*)file_path, &err_code);
+ }
+
+ if(!ipcEmailAPI_AddParameter(a_hAPI, ePARAMETER_OUT, &local_result, sizeof(int)))
+ EM_DEBUG_LOG("ipcEmailAPI_AddParameter failed ");
+
+ if(!ipcEmailAPI_AddParameter(a_hAPI, ePARAMETER_OUT, &err_code, sizeof(int)))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed ");
+
+ if(!ipcEmailAPI_AddParameter(a_hAPI, ePARAMETER_OUT, &handle, sizeof(int)))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter result failed ");
+
+ if (!ipcEmailStub_ExecuteAPI(a_hAPI))
+ EM_DEBUG_EXCEPTION("ipcEmailStub_ExecuteAPI failed ");
+
+ EM_SAFE_FREE(file_path);
+#endif /* __FEATURE_BACKUP_ACCOUNT__ */
+ EM_DEBUG_FUNC_END();
+}
+
+void stb_account_restore(HIPC_API a_hAPI)
+{
+ EM_DEBUG_FUNC_BEGIN();
+#ifdef __FEATURE_BACKUP_ACCOUNT__
+ char *file_path = NULL;
+ int local_result = 0, err_code = 0, handle = 0, file_path_length = 0;
+
+ /* file_path_length */
+ file_path_length = ipcEmailAPI_GetParameterLength(a_hAPI, ePARAMETER_IN, 0);
+ if(file_path_length > 0) {
+ EM_DEBUG_LOG("file_path_length [%d]", file_path_length);
+ file_path = em_core_malloc(file_path_length + 1);
+ memcpy(file_path, ipcEmailAPI_GetParameter(a_hAPI, ePARAMETER_IN, 0), file_path_length);
+ EM_DEBUG_LOG("file_path [%s]", file_path);
+ local_result = em_core_restore_accounts((const char*)file_path, &err_code);
+ }
+
+ if(!ipcEmailAPI_AddParameter(a_hAPI, ePARAMETER_OUT, &local_result, sizeof(int)))
+ EM_DEBUG_LOG("ipcEmailAPI_AddParameter failed ");
+
+ if(!ipcEmailAPI_AddParameter(a_hAPI, ePARAMETER_OUT, &err_code, sizeof(int)))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed ");
+
+ if(!ipcEmailAPI_AddParameter(a_hAPI, ePARAMETER_OUT, &handle, sizeof(int)))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter result failed ");
+
+ if (!ipcEmailStub_ExecuteAPI(a_hAPI))
+ EM_DEBUG_EXCEPTION("ipcEmailStub_ExecuteAPI failed ");
+
+ EM_SAFE_FREE(file_path);
+#endif /* __FEATURE_BACKUP_ACCOUNT__ */
+ EM_DEBUG_FUNC_END();
+}
+
+
+void stb_account_get_password_length(HIPC_API a_hAPI)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int account_id = 0;
+ int local_result = 0;
+ int err_code = 0;
+ int password_length = 0;
+
+ /* account_id */
+ memcpy(&account_id, ipcEmailAPI_GetParameter(a_hAPI, ePARAMETER_IN, 0), sizeof(int));;
+ local_result = em_storage_get_password_length_of_account(account_id, &password_length,&err_code);
+
+ EM_DEBUG_LOG("password_length [%d]", password_length);
+
+ if(!ipcEmailAPI_AddParameter(a_hAPI, ePARAMETER_OUT, &local_result, sizeof(int)))
+ EM_DEBUG_LOG("ipcEmailAPI_AddParameter failed ");
+
+ if(!ipcEmailAPI_AddParameter(a_hAPI, ePARAMETER_OUT, &err_code, sizeof(int)))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed ");
+
+ if(!ipcEmailAPI_AddParameter(a_hAPI, ePARAMETER_OUT, &password_length, sizeof(int)))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter result failed ");
+
+ if (!ipcEmailStub_ExecuteAPI(a_hAPI))
+ EM_DEBUG_EXCEPTION("ipcEmailStub_ExecuteAPI failed ");
+ EM_DEBUG_FUNC_END();
+}
+
+
+void stb_ping_service(HIPC_API a_hAPI)
+{
+ int err = EMF_ERROR_NONE;
+ if(!ipcEmailAPI_AddParameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed ");
+
+ if (!ipcEmailStub_ExecuteAPI(a_hAPI))
+ EM_DEBUG_EXCEPTION("ipcEmailStub_ExecuteAPI failed ");
+ EM_DEBUG_FUNC_END();
+}
+
+void stb_update_notification_bar_for_unread_mail(HIPC_API a_hAPI)
+{
+ int err = EMF_ERROR_NONE, account_id;
+
+ /* account_id */
+ memcpy(&account_id, ipcEmailAPI_GetParameter(a_hAPI, ePARAMETER_IN, 0), sizeof(int));
+ EM_DEBUG_LOG("account_id [%d]", account_id);
+
+ if(!em_core_finalize_sync(account_id, &err)) {
+ EM_DEBUG_EXCEPTION("em_core_finalize_sync failed [%d]", err);
+ }
+
+ if(!ipcEmailAPI_AddParameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
+ EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed ");
+
+ if (!ipcEmailStub_ExecuteAPI(a_hAPI))
+ EM_DEBUG_EXCEPTION("ipcEmailStub_ExecuteAPI failed ");
+ EM_DEBUG_FUNC_END();
+}
+
+
+void stb_API_mapper(HIPC_API a_hAPI)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int nAPIID = ipcEmailAPI_GetAPIID(a_hAPI);
+
+ switch(nAPIID) {
+ case _EMAIL_API_ADD_ACCOUNT:
+ stb_account_create(a_hAPI);
+ break;
+
+ case _EMAIL_API_ADD_MAIL_OLD:
+ stb_mail_save_to_mailbox(a_hAPI);
+ break;
+
+ case _EMAIL_API_GET_MAIL:
+ stb_mail_get_mail(a_hAPI);
+ break;
+
+ case _EMAIL_API_ADD_MAILBOX:
+ stb_mailbox_create(a_hAPI);
+ break;
+
+ case _EMAIL_API_DELETE_MAILBOX:
+ stb_mailbox_delete(a_hAPI);
+ break;
+ case _EMAIL_API_UPDATE_MAILBOX:
+ stb_mailbox_update(a_hAPI);
+ break;
+
+ case _EMAIL_API_SET_MAIL_SLOT_SIZE:
+ stb_mailbox_set_mail_slot_size(a_hAPI);
+ break;
+
+ case _EMAIL_API_SEND_MAIL:
+ stb_mail_send(a_hAPI);
+ break;
+
+ case _EMAIL_API_GET_MAILBOX_COUNT:
+ stb_mail_get_mailbox_count(a_hAPI);
+ break;
+
+ case _EMAIL_API_GET_MAILBOX_LIST:
+ stb_mailbox_get_list(a_hAPI);
+ break;
+
+ case _EMAIL_API_GET_SUBMAILBOX_LIST:
+ break;
+
+ case _EMAIL_API_SYNC_HEADER:
+ stb_mailbox_sync_header(a_hAPI);
+ break;
+
+ case _EMAIL_API_DOWNLOAD_BODY:
+ stb_mailbox_download_body(a_hAPI);
+ break;
+
+ case _EMAIL_API_CLEAR_DATA:
+ stb_clear_mail_data (a_hAPI);
+ break;
+
+ case _EMAIL_API_UPDATE_MAIL_OLD:
+ stb_update_mail_old(a_hAPI);
+ break;
+
+ case _EMAIL_API_DELETE_ALL_MAIL:
+ stb_mail_delete_all(a_hAPI);
+ break;
+
+ case _EMAIL_API_DELETE_MAIL:
+ stb_mail_delete(a_hAPI);
+ break;
+
+ case _EMAIL_API_MODIFY_MAIL_FLAG:
+ stb_modify_mail_flag(a_hAPI);
+ break;
+
+ case _EMAIL_API_MODIFY_MAIL_EXTRA_FLAG:
+ stb_modify_mail_extra_flag(a_hAPI);
+ break;
+
+ case _EMAIL_API_ADD_RULE:
+ stb_rule_add(a_hAPI);
+ break;
+
+ case _EMAIL_API_GET_RULE:
+ stb_rule_get(a_hAPI);
+ break;
+
+ case _EMAIL_API_GET_RULE_LIST:
+ stb_rule_get_list(a_hAPI);
+ break;
+
+ case _EMAIL_API_FIND_RULE:
+ stb_rule_find(a_hAPI);
+ break;
+
+ case _EMAIL_API_UPDATE_RULE:
+ stb_rule_change(a_hAPI);
+ break;
+
+ case _EMAIL_API_DELETE_RULE:
+ stb_rule_delete(a_hAPI);
+ break;
+
+ case _EMAIL_API_MOVE_MAIL:
+ stb_mail_move(a_hAPI);
+ break;
+
+ case _EMAIL_API_MOVE_ALL_MAIL:
+ stb_mail_move_all_mails(a_hAPI);
+ break;
+
+ case _EMAIL_API_SET_FLAGS_FIELD:
+ stb_set_flags_field(a_hAPI);
+ break;
+
+ case _EMAIL_API_ADD_MAIL:
+ stb_add_mail(a_hAPI);
+ break;
+
+ case _EMAIL_API_UPDATE_MAIL:
+ stb_update_mail(a_hAPI);
+ break;
+
+ case _EMAIL_API_MOVE_THREAD_TO_MAILBOX:
+ stb_move_thread_to_mailbox(a_hAPI);
+ break;
+
+ case _EMAIL_API_DELETE_THREAD:
+ stb_delete_thread(a_hAPI);
+ break;
+
+ case _EMAIL_API_MODIFY_SEEN_FLAG_OF_THREAD:
+ stb_modify_seen_flag_of_thread(a_hAPI);
+ break;
+
+ case _EMAIL_API_DELETE_ACCOUNT:
+ stb_account_delete(a_hAPI);
+ break;
+
+ case _EMAIL_API_UPDATE_ACCOUNT:
+ stb_account_update(a_hAPI);
+ break;
+
+ case _EMAIL_API_ADD_ATTACHMENT:
+ stb_mail_add_attachment(a_hAPI);
+ break;
+
+ case _EMAIL_API_GET_IMAP_MAILBOX_LIST:
+ stb_mailbox_get_imap_mailbox_list(a_hAPI);
+ break;
+
+ case _EMAIL_API_GET_ATTACHMENT:
+ stb_mail_get_attachment(a_hAPI);
+ break;
+
+ case _EMAIL_API_DELETE_ATTACHMENT:
+ stb_mail_delete_attachment(a_hAPI);
+ break;
+
+ case _EMAIL_API_DOWNLOAD_ATTACHMENT:
+ stb_download_attachment(a_hAPI);
+ break;
+
+ case _EMAIL_API_GET_INFO:
+ stb_get_info(a_hAPI);
+ break;
+
+ case _EMAIL_API_GET_HEADER_INFO:
+ stb_get_header_info(a_hAPI);
+ break;
+
+ case _EMAIL_API_GET_BODY_INFO:
+ stb_get_mail_body_info(a_hAPI);
+ break;
+
+ case _EMAIL_API_GET_ACCOUNT_LIST:
+ stb_account_get_list(a_hAPI);
+ break;
+
+ case _EMAIL_API_MAIL_SEND_SAVED:
+ stb_mail_send_saved(a_hAPI);
+ break;
+
+ case _EMAIL_API_MAIL_SEND_REPORT:
+ stb_mail_send_report(a_hAPI);
+ break;
+
+ case _EMAIL_API_CANCEL_JOB:
+ stb_cancel_job(a_hAPI);
+ break;
+
+ case _EMAIL_API_GET_PENDING_JOB:
+ stb_get_pending_job(a_hAPI);
+ break;
+
+ case _EMAIL_API_NETWORK_GET_STATUS:
+ stb_get_event_queue_status(a_hAPI);
+ break;
+
+ case _EMAIL_API_SEND_RETRY:
+ stb_mail_send_retry(a_hAPI);
+ break;
+
+ case _EMAIL_API_VALIDATE_ACCOUNT :
+ stb_account_validate(a_hAPI);
+ break;
+
+ case _EMAIL_API_SEND_MAIL_CANCEL_JOB :
+ stb_send_mail_cancel_job(a_hAPI);
+ break;
+
+ case _EMAIL_API_FIND_MAIL_ON_SERVER :
+ stb_find_mail_on_server(a_hAPI);
+ break;
+
+ case _EMAIL_API_ADD_ACCOUNT_WITH_VALIDATION :
+ stb_account_create_with_validation(a_hAPI);
+ break;
+
+ case _EMAIL_API_BACKUP_ACCOUNTS:
+ stb_account_backup(a_hAPI);
+ break;
+
+ case _EMAIL_API_RESTORE_ACCOUNTS:
+ stb_account_restore(a_hAPI);
+ break;
+
+ case _EMAIL_API_GET_PASSWORD_LENGTH_OF_ACCOUNT:
+ stb_account_get_password_length(a_hAPI);
+ break;
+
+ case _EMAIL_API_PRINT_RECEIVING_EVENT_QUEUE :
+ stb_print_receiving_event_queue_via_debug_msg(a_hAPI);
+ break;
+
+ case _EMAIL_API_PING_SERVICE :
+ stb_ping_service(a_hAPI);
+ break;
+
+ case _EMAIL_API_UPDATE_NOTIFICATION_BAR_FOR_UNREAD_MAIL :
+ stb_update_notification_bar_for_unread_mail(a_hAPI);
+ break;
+ }
+ EM_DEBUG_FUNC_END();
+}
+
+
+
+
+void hibernation_enter_callback()
+{
+ EM_DEBUG_FUNC_BEGIN();
+ em_storage_db_close(NULL);
+ EM_DEBUG_FUNC_END();
+}
+
+void hibernation_leave_callback()
+{
+ EM_DEBUG_FUNC_BEGIN();
+ em_storage_db_open(NULL);
+ EM_DEBUG_FUNC_END();
+}
+
+EXPORT_API int main(int argc, char *argv[])
+{
+ /* Do the Email Engine Initialization
+ 1. Create all DB tables and load the email engine */
+ EM_DEBUG_LOG("Email service begin");
+ int err = 0, ret;
+
+ signal(SIGPIPE, SIG_IGN); /* to ignore signal 13(SIGPIPE) */
+
+ emf_init(&err);
+ EM_DEBUG_LOG("emf_emn_noti_init Start");
+#ifdef USE_OMA_EMN
+ emf_emn_noti_init();
+#endif
+
+ EM_DEBUG_LOG("ipcEmailStub_Initialize Start");
+
+ ret = ipcEmailStub_Initialize(stb_API_mapper);
+
+ if(ret == true)
+ EM_DEBUG_LOG("ipcEmailStub_Initialize Success");
+ else
+ EM_DEBUG_EXCEPTION("ipcEmailStub_Initialize failed");
+
+ /* Start auto polling */
+#ifdef __FEATURE_AUTO_POLLING__
+ emf_auto_polling(&err);
+#endif
+
+ int fd_HibernationNoti;
+
+ fd_HibernationNoti = heynoti_init();
+
+ if(fd_HibernationNoti == -1)
+ EM_DEBUG_EXCEPTION("heynoti_init failed");
+ else {
+ EM_DEBUG_LOG("heynoti_init Success");
+ ret = heynoti_subscribe(fd_HibernationNoti, "HIBERNATION_ENTER", hibernation_enter_callback, (void *)fd_HibernationNoti);
+ EM_DEBUG_LOG("heynoti_subscribe returns %d", ret);
+ ret = heynoti_subscribe(fd_HibernationNoti, "HIBERNATION_LEAVE", hibernation_leave_callback, (void *)fd_HibernationNoti);
+ EM_DEBUG_LOG("heynoti_subscribe returns %d", ret);
+ ret = heynoti_attach_handler(fd_HibernationNoti);
+ EM_DEBUG_LOG("heynoti_attach_handler returns %d", ret);
+ }
+
+ GMainLoop *mainloop;
+
+ mainloop = g_main_loop_new (NULL, 0);
+
+ g_type_init();
+
+ g_main_loop_run (mainloop);
+
+ if(fd_HibernationNoti != -1) {
+ heynoti_unsubscribe(fd_HibernationNoti, "HIBERNATION_ENTER", hibernation_enter_callback);
+ heynoti_unsubscribe(fd_HibernationNoti, "HIBERNATION_LEAVE", hibernation_leave_callback);
+ heynoti_close(fd_HibernationNoti);
+ }
+
+ EM_DEBUG_FUNC_END();
+ return 0;
+}
+
diff --git a/email-service.pc.in b/email-service.pc.in
new file mode 100755
index 0000000..9458dd5
--- /dev/null
+++ b/email-service.pc.in
@@ -0,0 +1,9 @@
+prefix=/usr
+libdir=${prefix}/lib
+includedir=${prefix}/include
+
+Name: Email Engine Library
+Description: Email Engine Library 1.0
+Version: $version
+Libs: -L${libdir} -lemail-storage -lemail-core -lemail-base -lemail-ipc -lemail-api -lemail-network
+Cflags: -I${includedir}/email-service -D_PREVIEW_IN_MAILIST
diff --git a/emf-emn-storage/emf-emn-storage.c b/emf-emn-storage/emf-emn-storage.c
new file mode 100755
index 0000000..c184d6f
--- /dev/null
+++ b/emf-emn-storage/emf-emn-storage.c
@@ -0,0 +1,177 @@
+/*
+* email-service
+*
+* Copyright (c) 2000 - 2011 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.
+*
+*/
+
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <time.h>
+#include <sys/types.h>
+#include "db-util.h"
+#include "em-storage.h"
+#include "emf-emn-storage.h"
+#include "emf-dbglog.h"
+#include "emflib.h"
+
+#define EMF_DB_PARS_ERR(code__, msg__) memset(msg__, 0x00, sizeof(msg__)); EDBGetErrorInfo(&code__, msg__)
+
+#ifdef UNUSED
+sqlite3* sqlite_emmb;
+
+static int _string_to_tm(struct tm* time, const char* string);
+static void _tm_to_string(const struct tm* time, char* string, size_t string_size);
+
+
+static void __emn_storage_log_func(const char* format, ...)
+{
+ FILE* fp = NULL;
+ va_list va_args;
+ char msg_buffer[256] = {0, };
+
+ va_start(va_args, format);
+ vsnprintf(msg_buffer, sizeof(msg_buffer), format, va_args);
+ va_end(va_args);
+
+ if (strlen(LOG_FILE_PATH) > 0)
+ fp = fopen(LOG_FILE_PATH, "a");
+ else
+ fp = fopen("/var/log/email_ui.log", "a");
+
+ if (fp != NULL) {
+/* tzset(); */
+ time_t ct = time(&ct);
+ struct tm* lt = localtime(&ct);
+
+ if (lt) {
+ fprintf(fp, "[%d-%d-%d %d:%d:%d] %s: %s\n",
+ lt->tm_year + 1900, lt->tm_mon + 1, lt->tm_mday,
+ lt->tm_hour, lt->tm_min, lt->tm_sec,
+ "EMN", msg_buffer);
+ }
+
+ fclose(fp);
+ }
+}
+
+
+enum {
+ ACCOUNT_ID___MAIL_NEW_TBL = 0,
+ ACCOUNT_NAME___MAIL_NEW_TBL,
+ ARRIVALTIME___MAIL_NEW_TBL,
+ NEW_MAIL_COUNT___MAIL_NEW_TBL,
+ SVC_TYPE___MAIL_NEW_TBL,
+};
+
+/* static char _g_sql_query[1024] = {0x00, }; */
+/* char _g_err_msg[1024] = {0x00, }; */
+/* int _g_err = 0; */
+
+
+static char* _cpy_str(char* src)
+{
+ char* p = NULL;
+ if (src) {
+ if (!(p = malloc((int)strlen(src) + 1)))
+ return NULL;
+
+ strcpy(p, src);
+ }
+ return p;
+}
+
+static int _emf_storage_close(int* err_code)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ int ret = true;
+ int rc = -1;
+ rc = db_util_close( sqlite_emmb);
+ sqlite_emmb = NULL;
+ if(SQLITE_OK != rc) {
+ EM_DEBUG_LOG("\t db_util_close failed - %d\n", rc);
+ ret = false;
+ }
+
+ if (err_code != NULL)
+ *err_code = rc;
+
+ return ret;
+}
+
+static int _emf_storage_open(int* err_code)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ int ret = true;
+
+ if ( !em_db_open(&sqlite_emmb, NULL) ) {
+ EM_DEBUG_EXCEPTION("em_db_open failed\n");
+ ret = false;
+ }
+
+ return ret;
+}
+
+
+
+static int _string_to_tm(struct tm* time, const char* string)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ char year[5] = {0x00, };
+ char month[3] = {0x00, };
+ char hour[3] = {0x00, };
+ char day[3] = {0x00, };
+ char min[3] = {0x00, };
+ char sec[3] = {0x00, };
+
+ if (!time)
+ return false;
+
+ if ((!string) || (strlen(string) != 14))
+ return false;
+
+ strncpy(year, string, 4); time->tm_year = atoi(year); string += 4;
+ strncpy(month, string, 2); time->tm_mon = atoi(month); string += 2;
+ strncpy(day, string, 2); time->tm_mday = atoi(day); string += 2;
+ strncpy(hour, string, 2); time->tm_hour = atoi(hour); string += 2;
+ strncpy(min, string, 2); time->tm_min = atoi(min); string += 2;
+ strncpy(sec, string, 2); time->tm_sec = atoi(sec);
+
+ return true;
+}
+
+static void _tm_to_string(const struct tm* time, char* string, size_t string_size)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ memset(string, 0x00, string_size);
+
+ snprintf(string, string_size, "%04d%02d%02d%02d%02d%02d",
+ time->tm_year, time->tm_mon,
+ time->tm_mday, time->tm_hour,
+ time->tm_min, time->tm_sec);
+
+ return;
+}
+
+#endif
+
diff --git a/image/email_image001.png b/image/email_image001.png
new file mode 100755
index 0000000..0d78bfd
--- /dev/null
+++ b/image/email_image001.png
Binary files differ
diff --git a/image/email_image002.png b/image/email_image002.png
new file mode 100755
index 0000000..5eda4be
--- /dev/null
+++ b/image/email_image002.png
Binary files differ
diff --git a/image/email_image003.png b/image/email_image003.png
new file mode 100755
index 0000000..cf8be88
--- /dev/null
+++ b/image/email_image003.png
Binary files differ
diff --git a/image/email_image004.png b/image/email_image004.png
new file mode 100755
index 0000000..c90711f
--- /dev/null
+++ b/image/email_image004.png
Binary files differ
diff --git a/image/email_image005.png b/image/email_image005.png
new file mode 100755
index 0000000..e913091
--- /dev/null
+++ b/image/email_image005.png
Binary files differ
diff --git a/image/email_image006.png b/image/email_image006.png
new file mode 100755
index 0000000..1d2708c
--- /dev/null
+++ b/image/email_image006.png
Binary files differ
diff --git a/image/email_image007.png b/image/email_image007.png
new file mode 100755
index 0000000..46b0dc7
--- /dev/null
+++ b/image/email_image007.png
Binary files differ
diff --git a/image/email_image008.png b/image/email_image008.png
new file mode 100755
index 0000000..1f117c5
--- /dev/null
+++ b/image/email_image008.png
Binary files differ
diff --git a/image/email_image009.png b/image/email_image009.png
new file mode 100755
index 0000000..1141e51
--- /dev/null
+++ b/image/email_image009.png
Binary files differ
diff --git a/image/email_image010.png b/image/email_image010.png
new file mode 100755
index 0000000..df9aac0
--- /dev/null
+++ b/image/email_image010.png
Binary files differ
diff --git a/image/email_image011.png b/image/email_image011.png
new file mode 100755
index 0000000..70a54fe
--- /dev/null
+++ b/image/email_image011.png
Binary files differ
diff --git a/image/email_image012.png b/image/email_image012.png
new file mode 100755
index 0000000..bd6b019
--- /dev/null
+++ b/image/email_image012.png
Binary files differ
diff --git a/include/.gitignore b/include/.gitignore
new file mode 100644
index 0000000..f42dfd4
--- /dev/null
+++ b/include/.gitignore
@@ -0,0 +1,2 @@
+contact-engine-h
+filemanager-service-h
diff --git a/include/emf-account.h b/include/emf-account.h
new file mode 100755
index 0000000..1891fda
--- /dev/null
+++ b/include/emf-account.h
@@ -0,0 +1,52 @@
+/*
+* email-service
+*
+* Copyright (c) 2000 - 2011 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.
+*
+*/
+
+
+/******************************************************************************
+ * File: emf-account.h
+ * Desc: Mail Framework Account Header
+ *
+ * Auth:
+ *
+ * History:
+ * 2006.08.01 : created
+ *****************************************************************************/
+#ifndef __EMF_ACCONT_H__
+#define __EMF_ACCONT_H__
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif /* __cplusplus */
+
+#include "emflib.h"
+
+ int
+ emf_init_account_reference();
+ emf_account_t*
+ emf_get_account_reference(int account_id);
+ int emf_free_account_reference(void);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif
diff --git a/include/emf-auto-poll.h b/include/emf-auto-poll.h
new file mode 100755
index 0000000..1f8cd98
--- /dev/null
+++ b/include/emf-auto-poll.h
@@ -0,0 +1,62 @@
+/*
+* email-service
+*
+* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+*
+* Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com>
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*
+*/
+
+
+/**
+ * This file defines all APIs of Auto Poll.
+ * @file emf-auto-poll.h
+ * @author
+ * @version 0.1
+ * @brief This file is the header file of Auto Poll.
+ */
+#ifndef __EMF_AUTO_POLL_H__
+#define __EMF_AUTO_POLL_H__
+
+#include "em-core-types.h"
+
+#ifdef __FEATURE_AUTO_POLLING__
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif /* __cplusplus */
+
+ #include "alarm.h"
+
+#if !defined(EXPORT_API)
+#define EXPORT_API __attribute__((visibility("default")))
+#endif
+
+
+EXPORT_API int emf_add_polling_alarm(int account_id, int alarm_interval);
+EXPORT_API int emf_remove_polling_alarm(int account_id);
+EXPORT_API int is_auto_polling_started(int account_id);
+EXPORT_API int emf_alarm_polling_cb(alarm_id_t alarm_id, void* user_param);
+EXPORT_API int emf_free_account_alarm_binder_list();
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* __FEATURE_AUTO_POLLING__ */
+
+#endif /* __EMF_AUTO_POLL_H__ */
+/* EOF */
diff --git a/include/emf-dbglog.h b/include/emf-dbglog.h
new file mode 100755
index 0000000..6375d59
--- /dev/null
+++ b/include/emf-dbglog.h
@@ -0,0 +1,228 @@
+/*
+* email-service
+*
+* Copyright (c) 2000 - 2011 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.
+*
+*/
+
+
+
+/******************************************************************************
+ * File: emf-dbglog.h
+ * Desc: Mail Framework Debug Header
+ *
+ * Auth:
+ *
+ * History:
+ * 2006.08.01 : created
+ *****************************************************************************/
+#ifndef __DEBUG_LOG_H__
+#define __DEBUG_LOG_H__
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <stdio.h>
+#include <string.h>
+#include <glib.h>
+#include <glib-object.h>
+#include <dlog.h>
+
+#define __FEATURE_DEBUG_LOG__
+
+#ifdef __FEATURE_DEBUG_LOG__
+
+#define DEBUG_PREFIX "Email-Engine"
+#define LOG_FILE_PATH "/var/log/email.log"
+
+/* definition of LOG_TAG */
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+
+#define LOG_TAG "email-service"
+
+#define EM_DEBUG_LOG(format, arg...) SLOGD("[%s:%s():%d] " format "\n", (rindex(__FILE__, '/')? rindex(__FILE__,'/')+1 : __FILE__ ), __FUNCTION__, __LINE__, ##arg)
+#define EM_DEBUG_EXCEPTION(format, arg...) SLOGE("[%s:%s():%d][EXCEPTION!!] " format "\n", (rindex(__FILE__, '/')? rindex(__FILE__,'/')+1 : __FILE__ ), __FUNCTION__, __LINE__, ##arg)
+
+#ifdef _DEBUG_MIME_PARSE_
+#define EM_DEBUG_LOG_MIME(format, arg...) EM_DEBUG_LOG(format, ##arg)
+#else /* _DEBUG_MIME_PARSE */
+#define EM_DEBUG_LOG_MIME(format, arg...)
+#endif /* _DEBUG_MIME_PARSE */
+
+#define EM_DEBUG_FUNC_BEGIN(format, arg...) EM_DEBUG_LOG("BEGIN - "format, ##arg)
+#define EM_DEBUG_FUNC_END(format, arg...) EM_DEBUG_LOG("END - "format, ##arg)
+#define EM_DEBUG_LINE EM_DEBUG_LOG("FUNC[%s : %d]", __FUNCTION__, __LINE__)
+#define EM_DEBUG_DB_EXEC(eval, expr, X) if (eval) { EM_DEBUG_LOG X; expr;} else {;}
+
+#define EM_DEBUG_ERROR_FILE_PATH "/opt/data/email/.emfdata/.critical_error.log"
+#define EM_DEBUG_CRITICAL_EXCEPTION(format, arg...) { FILE *fp_error = NULL; fp_error = fopen(EM_DEBUG_ERROR_FILE_PATH, "a");\
+ if(fp_error) {fprintf(fp_error, "[%s:%s():%d] " format "\n", (rindex(__FILE__, '/')? rindex(__FILE__,'/')+1 : __FILE__ ), __FUNCTION__, __LINE__, ##arg); \
+ fclose(fp_error);}}
+#ifdef _USE_PROFILE_DEBUG_
+#define EM_PROFILE_BEGIN(pfid) \
+ unsigned int __prf_l1_##pfid = __LINE__;\
+ struct timeval __prf_1_##pfid;\
+ struct timeval __prf_2_##pfid;\
+ do {\
+ gettimeofday(&__prf_1_##pfid, 0);\
+ EM_DEBUG_LOG("**PROFILE BEGIN** [EMAILFW: %s: %s() %u ~ ] " #pfid \
+ " -> Start Time: %u.%06u seconds\n",\
+ rindex(__FILE__,'/')+1, \
+ __FUNCTION__,\
+ __prf_l1_##pfid,\
+ (unsigned int)__prf_1_##pfid.tv_sec,\
+ (unsigned int)__prf_1_##pfid.tv_usec );\
+ } while (0)
+
+#define EM_PROFILE_END(pfid) \
+ unsigned int __prf_l2_##pfid = __LINE__;\
+ do { \
+ gettimeofday(&__prf_2_##pfid, 0);\
+ long __ds = __prf_2_##pfid.tv_sec - __prf_1_##pfid.tv_sec;\
+ long __dm = __prf_2_##pfid.tv_usec - __prf_1_##pfid.tv_usec;\
+ if ( __dm < 0 ) { __ds--; __dm = 1000000 + __dm; } \
+ EM_DEBUG_LOG("**PROFILE END** [EMAILFW: %s: %s() %u ~ %u] " #pfid \
+ " -> Elapsed Time: %u.%06u seconds\n",\
+ rindex(__FILE__, '/')+1,\
+ __FUNCTION__,\
+ __prf_l1_##pfid,\
+ __prf_l2_##pfid,\
+ (unsigned int)(__ds),\
+ (unsigned int)(__dm));\
+ } while (0)
+#else
+
+#define EM_PROFILE_BEGIN(pfid)
+#define EM_PROFILE_END(pfid)
+
+#endif
+
+
+#else /* __FEATURE_DEBUG_LOG__ */
+
+ #define EM_DEBUG_LINE
+ #define EM_DEBUG_LOG(format, arg...)
+ #define EM_DEBUG_ASSERT(format, arg...)
+ #define EM_DEBUG_EXCEPTION(format, arg...)
+
+
+ #define EM_DEBUG_DB_EXEC(eval, expr, X) if (eval) { EM_DEBUG_DB X; expr;} else {;}
+ #define EM_PROFILE_BEGIN(pfid)
+ #define EM_PROFILE_END(pfid)
+
+#endif /* __FEATURE_DEBUG_LOG__ */
+
+
+#define EM_NULL_CHECK_FOR_VOID(expr) \
+ {\
+ if (!expr) {\
+ EM_DEBUG_EXCEPTION ("INVALID PARAM: "#expr" NULL ");\
+ return;\
+ }\
+ }
+
+#define EM_IF_NULL_RETURN_VALUE(expr, val) \
+ {\
+ if (!expr ) {\
+ EM_DEBUG_EXCEPTION ("INVALID PARAM: "#expr" NULL ");\
+ return val; \
+ }\
+ }
+
+#define EM_RETURN_ERR_CODE(err_ptr, err_code, ret) \
+ {\
+ if(err_ptr) *err_ptr = err_code;\
+ return ret;\
+ }
+
+#define EM_EXIT_ERR_CODE(err_ptr, err_code) \
+ {\
+ if(err_ptr) *err_ptr = err_code;\
+ return;\
+ }
+
+
+#define EM_SAFE_FREE(expr) \
+ ({\
+ if (expr ) {\
+ free(expr);\
+ expr = NULL;\
+ }\
+ })
+
+#define EM_SAFE_STRDUP(s) \
+ ({\
+ char* _s = (char*)s;\
+ (_s)? strdup(_s) : NULL;\
+ })
+
+#define EM_SAFE_STRCMP(dest, src) \
+ ({\
+ char* _dest = dest;\
+ char* _src = src;\
+ ((_src) && (_dest))? strcmp(_dest, _src) : -1;\
+ })
+
+#define EM_SAFE_STRCPY(dest, src) \
+ ({\
+ char* _dest = dest;\
+ char* _src = src;\
+ ((_src) && (_dest))? strcpy(_dest, _src) : NULL;\
+ })
+
+#define EM_SAFE_STRNCPY(dest, src, size) \
+ ({\
+ char* _dest = dest;\
+ char* _src = src;\
+ int _size = size;\
+ ((_src) && (_dest))? strncpy(_dest, _src, _size) : NULL;\
+ })
+
+#define EM_SAFE_STRCAT(dest, src) \
+ ({\
+ char* _dest = dest;\
+ char* _src = src;\
+ ((_src) && (_dest))? strcat(_dest, _src) : NULL;\
+ })
+
+#define EM_SAFE_STRLEN(s) \
+ ({\
+ char* _s = (char*)s;\
+ (_s)? strlen(_s) : 0;\
+ })
+
+
+#define EM_IF_ACCOUNT_ID_NULL(expr, ret) {\
+ if (expr <= 0) {\
+ EM_DEBUG_EXCEPTION ("EM_IF_ACCOUNT_ID_NULL: Account ID [ %d ] ", expr);\
+ return ret;\
+ }\
+ }
+
+
+#define EM_STRERROR(err) ({ char buf[128]; strerror_r(err, buf, sizeof(buf));})
+
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplu */
+
+#endif /* __DEBUG_LOG_H_ */
diff --git a/include/emf-emn-noti.h b/include/emf-emn-noti.h
new file mode 100755
index 0000000..fc458c9
--- /dev/null
+++ b/include/emf-emn-noti.h
@@ -0,0 +1,69 @@
+/*
+* email-service
+*
+* Copyright (c) 2000 - 2011 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.
+*
+*/
+
+
+/******************************************************************************
+ * File: emf_noti.h
+ * Desc: Email notification
+ *
+ * Auth:
+ *
+ * History:
+ * 2006.08.01 : created
+ *****************************************************************************/
+#ifndef __EMF_EMN_NOTI_H__
+#define __EMF_EMN_NOTI_H__
+
+
+enum
+{
+ EMN_HEADER_DATA = 0,
+ EMN_WBXML_DATA,
+};
+
+/* Error Values for the Email options */
+enum
+{
+ EMAIL_OPTION_ERROR_NONE = 0,
+ EMAIL_OPTION_ERROR_INVALID_PARAM,
+ EMAIL_OPTION_ERROR_STORAGE,
+};
+
+/* Manual Network value */
+#define EMAIL_OPTION_NETWORK_MANUAL 1
+
+
+/* Enums for the Gcong Option Key */
+typedef enum
+{
+ EMAIL_OPTION_KEY_HOME_NETWORK = 0,
+ EMAIL_OPTION_KEY_ROAMING_NETWORK,
+}optionkey;
+
+#define EMAIL_GCONF_DIR "/Apps/Email"
+
+
+int emf_emn_noti_init(void);
+int emf_emn_noti_quit(int bExtDest);
+
+void
+emn_test_func(void);
+#endif /*__EMF_EMN_NOTI_H__*/
diff --git a/include/emf-emn-storage.h b/include/emf-emn-storage.h
new file mode 100755
index 0000000..812fd92
--- /dev/null
+++ b/include/emf-emn-storage.h
@@ -0,0 +1,83 @@
+/*
+* email-service
+*
+* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+*
+* Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com>
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*
+*/
+
+
+/**
+ * This file defines all APIs of EMN's storage.
+ * @file emf-emn-storage.h
+ * @version 0.1
+ * @brief This file is the header file of EMN's storage library.
+ */
+
+#ifndef __EMF_EMN_STORAGE_H__
+#define __EMF_EMN_STORAGE_H__
+
+/**
+* @ingroup EMAIL_FRAMEWORK
+* @defgroup EMN_STORAGE EMN Storage
+* @{
+*/
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif /* __cplusplus */
+
+#if !defined(EXPORT_API)
+#define EXPORT_API __attribute__((visibility("default")))
+#endif
+
+#ifdef MAILHOME
+#undef MAILHOME
+#endif
+
+#define MAILHOME DATA_PATH"/.email-service/.emfdata" /**< This defines the storage mailbox. */
+#define MAILTEMP "tmp" /**< This defines the temporary mailbox. */
+#ifndef true
+#define true 1 /**< This defines true. */
+#define false 0 /**< This defines false. */
+#endif
+
+/**
+ * This enumeration specifies the mail service type.
+ */
+typedef enum
+{
+ EMF_SVC_EMN = 1, /**< Specifies the EMN service.*/
+ EMF_SVC_VISTO, /**< Specifies the Pushmail service(VISTO).*/
+ EMF_SVC_IMAP_IDLE /**< Specifies the normal email service.*/
+} emf_svc_type_t;
+
+
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+/**
+* @} @}
+*/
+
+
+
+#endif /* __EMF_EMN_STORAGE_H__ */
+/* EOF */
+
diff --git a/include/emf-emn.h b/include/emf-emn.h
new file mode 100755
index 0000000..01815f9
--- /dev/null
+++ b/include/emf-emn.h
@@ -0,0 +1,88 @@
+/*
+* email-service
+*
+* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+*
+* Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com>
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*
+*/
+
+
+
+/**
+ * This file defines all APIs of EMN.
+ * @file emf-emn.h
+ * @author Kyuho Jo(kyuho.jo@samsung.com)
+ * @version 0.1
+ * @brief This file is the header file of EMN library.
+ */
+
+#ifndef __EMF_EMN_H__
+#define __EMF_EMN_H__
+
+/**
+* @ingroup EMAIL_FRAMEWORK
+* @defgroup EMN EMN
+* @{
+*/
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif /* __cplusplus */
+
+#if !defined(EXPORT_API)
+#define EXPORT_API __attribute__((visibility("default")))
+#endif
+
+/**
+ * This callback specifies the callback of retrieving the result that is downloaded new messages.
+ *
+ * @param[in] mail_count Specifies count of new mail.
+ * @param[in] user_data Specifies the user data.
+ * @param[in] err_code Specifies the error code.
+ * @remarks N/A
+ * @return This function returns true on success or false on failure.
+ */
+typedef int (*emf_emn_noti_cb)(
+ void* user_data,
+ int err_code
+);
+
+#ifdef USE_OMA_EMN
+/**
+ * Handle OMA EMN data
+ *
+ * @param[in] wbxml_b64 Specifies the encoded string
+ * @param[in] callback Specifies the callback function for retrieving the result that is downloaded new mail.
+ * @param[out] err_code Specifies the error code returned.
+ * @remarks N/A
+ * @return This function returns true on success or false on failure.
+ */
+EXPORT_API int emf_emn_handler(unsigned char* wbxml_b64, emf_emn_noti_cb callback, int* err_code);
+#endif
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+/**
+* @} @}
+*/
+
+
+#endif /* __EMF_EMN_H__ */
+/* EOF */
+
diff --git a/include/emf-global.h b/include/emf-global.h
new file mode 100755
index 0000000..609d049
--- /dev/null
+++ b/include/emf-global.h
@@ -0,0 +1,54 @@
+/*
+* email-service
+*
+* Copyright (c) 2000 - 2011 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.
+*
+*/
+
+
+
+/******************************************************************************
+ * File: emf-global.h
+ * Desc: Mail Framework Global Header
+ *
+ * Auth:
+ *
+ * History:
+ * 2006.08.01 : created
+ *****************************************************************************/
+#ifndef __EMF_GLOBAL_H__
+#define __EMF_GLOBAL_H__
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif /* __cplusplus */
+
+#include "emflib.h"
+
+#ifndef NULL
+#define NULL (char*)0
+#endif
+
+#include "vconf-keys.h"
+
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif
diff --git a/include/emf-init.h b/include/emf-init.h
new file mode 100755
index 0000000..0e4e61f
--- /dev/null
+++ b/include/emf-init.h
@@ -0,0 +1,46 @@
+/*
+* email-service
+*
+* Copyright (c) 2000 - 2011 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.
+*
+*/
+
+
+/******************************************************************************
+ * File: emf-init.h
+ * Desc: Mail Framework Initialization Header
+ *
+ * Auth:
+ *
+ * History:
+ * 2006.08.16 : created
+ *****************************************************************************/
+#ifndef __EMF_INIT_H__
+#define __EMF_INIT_H__
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif /* __cplusplus */
+
+#include "em-storage.h"
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif
diff --git a/include/emf-mutex.h b/include/emf-mutex.h
new file mode 100755
index 0000000..27b8fe9
--- /dev/null
+++ b/include/emf-mutex.h
@@ -0,0 +1,79 @@
+/*
+* email-service
+*
+* Copyright (c) 2000 - 2011 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.
+*
+*/
+
+
+#ifndef _EMF_MUTEX_H_
+#define _EMF_MUTEX_H_
+
+#include <sys/time.h>
+
+class Mutex
+{
+public:
+ Mutex(){ pthread_mutex_init(&m, NULL); }
+ void lock(){ pthread_mutex_lock(&m); }
+ void unlock(){ pthread_mutex_unlock(&m); }
+ pthread_mutex_t* pMutex() { return &m; }
+
+private:
+ pthread_mutex_t m;
+};
+
+class MutexLocker
+{
+public:
+ MutexLocker(Mutex& mx) {
+ pm = &mx;
+ pm->lock();
+ }
+
+ ~MutexLocker() {
+ pm->unlock();
+ }
+
+private:
+ Mutex *pm;
+};
+
+class CndVar
+{
+public:
+ CndVar(){ pthread_cond_init(&c, NULL); }
+ void wait(pthread_mutex_t* m) { pthread_cond_wait(&c, m); }
+ int timedwait(pthread_mutex_t* m, int sec) {
+ struct timeval now = {0};
+ struct timespec timeout = {0};
+ gettimeofday(&now, NULL);
+ timeout.tv_sec = now.tv_sec+sec;
+ timeout.tv_nsec = now.tv_usec;
+ int retcode = pthread_cond_timedwait(&c, m, &timeout);
+ return retcode;
+ }
+ int signal(){ return pthread_cond_signal(&c); }
+ int broadcast(){ return pthread_cond_broadcast(&c); }
+
+private:
+ pthread_cond_t c;
+};
+
+
+#endif
+
diff --git a/include/emf-types.h b/include/emf-types.h
new file mode 100755
index 0000000..8b878ed
--- /dev/null
+++ b/include/emf-types.h
@@ -0,0 +1,1445 @@
+/*
+* email-service
+*
+* Copyright (c) 2000 - 2011 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.
+*
+*/
+
+
+#ifndef __EMF_TYPES_H__
+#define __EMF_TYPES_H__
+
+/**
+* @defgroup EMAIL_FRAMEWORK Email Service
+* @{
+*/
+
+/**
+* @ingroup EMAIL_FRAMEWORK
+* @defgroup EMAIL_TYPES Email Types
+* @{
+*/
+/**
+ * This file defines structures and enums of Email Framework.
+ * @file emf-types.h
+ * @author Kyu-ho Jo(kyuho.jo@samsung.com)
+ * @author Choongho Lee(ch715.lee@samsung.com)
+ * @version 0.1
+ * @brief This file is the header file of Email Framework library.
+ */
+
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif /* __cplusplus */
+
+#include <glib.h>
+#include <stdbool.h>
+
+
+/*****************************************************************************/
+/* Macros */
+/*****************************************************************************/
+
+#define MAILBOX_NAME_LENGTH 256
+#define MAX_EMAIL_ADDRESS_LENGTH 320 /* 64(user name) + 1(@) + 255(host name */
+#define MAX_DATETIME_STRING_LENGTH 20
+#define MAX_PREVIEW_TEXT_LENGTH 50 /* should be 512 */
+#define STRING_LENGTH_FOR_DISPLAY 100
+#define MEETING_REQ_OBJECT_ID_LENGTH 128 /* should be 256 */
+
+#define ALL_ACCOUNT 0
+#define NEW_ACCOUNT_ID 0xFFFFFFFE
+#define ALL_MAIL -1
+
+#define EMF_SEARCH_FILTER_NONE 0x00
+#define EMF_SEARCH_FILTER_SUBJECT 0x01
+#define EMF_SEARCH_FILTER_SENDER 0x02
+#define EMF_SEARCH_FILTER_RECIPIENT 0x04
+#define EMF_SEARCH_FILTER_ALL 0x07 /* EMF_SEARCH_FILTER_SUBJECT + EMF_SEARCH_FILTER_SENDER + EMF_SEARCH_FILTER_RECIPIEN */
+
+#define EMF_SUCCESS 0 /* we need to modify the success return valu */
+
+#define EMF_ACC_GET_OPT_DEFAULT 0x01 /**< Default values without account name */
+#define EMF_ACC_GET_OPT_ACCOUNT_NAME 0x02 /**< Account name */
+#define EMF_ACC_GET_OPT_PASSWORD 0x04 /**< With password */
+#define EMF_ACC_GET_OPT_OPTIONS 0x08 /**< Account options : emf_option_t */
+#define EMF_ACC_GET_OPT_FULL_DATA 0xFF /**< With all data of account */
+
+#define GET_FULL_DATA 0x00
+#define GET_FULL_DATA_WITHOUT_PASSWORD (EMF_ACC_GET_OPT_DEFAULT | EMF_ACC_GET_OPT_ACCOUNT_NAME | EMF_ACC_GET_OPT_OPTIONS )
+#define WITHOUT_OPTION (EMF_ACC_GET_OPT_DEFAULT | EMF_ACC_GET_OPT_ACCOUNT_NAME )
+#define ONLY_OPTION (EMF_ACC_GET_OPT_OPTIONS)
+
+#define THREAD_TYPE_RECEIVING 0 /**< for function 'email_activate_pdp' */
+#define THREAD_TYPE_SENDING 1 /**< for function 'email_activate_pdp' */
+
+#define EMF_IMAP_PORT 143 /**< Specifies the default IMAP port.*/
+#define EMF_POP3_PORT 110 /**< Specifies the default POP3 port.*/
+#define EMF_SMTP_PORT 25 /**< Specifies the default SMTP port.*/
+#define EMF_IMAPS_PORT 993 /**< Specifies the default IMAP SSL port.*/
+#define EMF_POP3S_PORT 995 /**< Specifies the default POP3 SSL port.*/
+#define EMF_SMTPS_PORT 465 /**< Specifies the default SMTP SSL port.*/
+#define EMF_ACCOUNT_MAX 10 /**< Specifies the MAX account.*/
+
+#define EMF_INBOX_NAME "INBOX" /**< Specifies the name of inbox.*/
+#define EMF_DRAFTBOX_NAME "DRAFTBOX" /**< Specifies the name of draftbox.*/
+#define EMF_OUTBOX_NAME "OUTBOX" /**< Specifies the name of outbox.*/
+#define EMF_SENTBOX_NAME "SENTBOX" /**< Specifies the name of sentbox.*/
+#define EMF_TRASH_NAME "TRASH" /**< Specifies the name of trash.*/
+#define EMF_SPAMBOX_NAME "SPAMBOX" /**< Specifies the name of spambox.*/
+
+#define EMF_INBOX_DISPLAY_NAME "Inbox" /**< Specifies the display name of inbox.*/
+#define EMF_DRAFTBOX_DISPLAY_NAME "Draftbox" /**< Specifies the display name of draftbox.*/
+#define EMF_OUTBOX_DISPLAY_NAME "Outbox" /**< Specifies the display name of outbox.*/
+#define EMF_SENTBOX_DISPLAY_NAME "Sentbox" /**< Specifies the display name of sentbox.*/
+#define EMF_TRASH_DISPLAY_NAME "Trash" /**< Specifies the display name of sentbox.*/
+#define EMF_SPAMBOX_DISPLAY_NAME "Spambox" /**< Specifies the display name of spambox.*/
+
+#define EMF_SEARCH_RESULT_MAILBOX_NAME "_`S1!E2@A3#R4$C5^H6&R7*E8(S9)U0-L=T_" /**< Specifies the name of search mailbox.*/
+
+#define FAILURE -1
+#define SUCCESS 0
+
+#define NATIVE_EMAIL_APPLICATION_PKG "org.tizen.email"
+#define DAEMON_EXECUTABLE_PATH "/usr/bin/email-service"
+
+#ifndef DEPRECATED
+#define DEPRECATED __attribute__((deprecated))
+#endif
+
+#ifndef EXPORT_API
+#define EXPORT_API __attribute__((visibility("default")))
+#endif
+
+/* __LOCAL_ACTIVITY__ supported
+#define BULK_OPERATION_COUNT 50
+#define ALL_ACTIVITIES 0
+*/
+
+/*****************************************************************************/
+/* Enumerations */
+/*****************************************************************************/
+enum
+{
+ EMF_DELETE_LOCALLY = 0, /**< Specifies Mail Delete local only */
+ EMF_DELETE_LOCAL_AND_SERVER, /**< Specifies Mail Delete local & server */
+ EMF_DELETE_FOR_SEND_THREAD, /**< Created to check which activity to delete in send thread */
+};
+
+typedef enum
+{
+ NOTI_MAIL_ADD = 10000,
+ NOTI_MAIL_DELETE = 10001,
+ NOTI_MAIL_DELETE_ALL = 10002,
+ NOTI_MAIL_DELETE_WITH_ACCOUNT = 10003,
+ NOTI_MAIL_DELETE_FAIL = 10007,
+ NOTI_MAIL_DELETE_FINISH = 10008,
+
+ NOTI_MAIL_UPDATE = 10004,
+ NOTI_MAIL_FIELD_UPDATE = 10020,
+
+ NOTI_MAIL_MOVE = 10005,
+ NOTI_MAIL_MOVE_FAIL = 10010,
+ NOTI_MAIL_MOVE_FINISH = 10006,
+
+ NOTI_THREAD_MOVE = 11000,
+ NOTI_THREAD_DELETE = 11001,
+ NOTI_THREAD_MODIFY_SEEN_FLAG = 11002,
+
+ NOTI_ACCOUNT_ADD = 20000,
+ NOTI_ACCOUNT_DELETE = 20001,
+ NOTI_ACCOUNT_DELETE_FAIL = 20003,
+ NOTI_ACCOUNT_UPDATE = 20002,
+ NOTI_ACCOUNT_UPDATE_SYNC_STATUS = 20010,
+
+
+ NOTI_MAILBOX_ADD = 40000,
+ NOTI_MAILBOX_DELETE,
+ NOTI_MAILBOX_UPDATE,
+ /* To be added more */
+}emf_noti_on_storage_event;
+
+typedef enum
+{
+ NOTI_SEND_START = 1002,
+ NOTI_SEND_FINISH = 1004,
+ NOTI_SEND_FAIL = 1005,
+ NOTI_SEND_CANCEL = 1003,
+
+ NOTI_DOWNLOAD_START = 2000,
+ NOTI_DOWNLOAD_FINISH,
+ NOTI_DOWNLOAD_FAIL,
+ NOTI_DOWNLOAD_CANCEL = 2004,
+ NOTI_DOWNLOAD_NEW_MAIL = 2003,
+
+ NOTI_DOWNLOAD_BODY_START = 3000,
+ NOTI_DOWNLOAD_BODY_FINISH = 3002,
+ NOTI_DOWNLOAD_BODY_FAIL = 3004,
+ NOTI_DOWNLOAD_BODY_CANCEL = 3003,
+ NOTI_DOWNLOAD_MULTIPART_BODY = 3001,
+
+ NOTI_DOWNLOAD_ATTACH_START = 4000,
+ NOTI_DOWNLOAD_ATTACH_FINISH,
+ NOTI_DOWNLOAD_ATTACH_FAIL,
+ NOTI_DOWNLOAD_ATTACH_CANCEL,
+
+ NOTI_MAIL_DELETE_ON_SERVER_FAIL = 5000,
+ NOTI_MAIL_MOVE_ON_SERVER_FAIL,
+
+ NOTI_VALIDATE_ACCOUNT_FINISH = 7000,
+ NOTI_VALIDATE_ACCOUNT_FAIL,
+ NOTI_VALIDATE_ACCOUNT_CANCEL,
+
+ NOTI_VALIDATE_AND_CREATE_ACCOUNT_FINISH = 8000,
+ NOTI_VALIDATE_AND_CREATE_ACCOUNT_FAIL,
+ NOTI_VALIDATE_AND_CREATE_ACCOUNT_CANCEL,
+
+ NOTI_VALIDATE_AND_UPDATE_ACCOUNT_FINISH = 9000,
+ NOTI_VALIDATE_AND_UPDATE_ACCOUNT_FAIL,
+ NOTI_VALIDATE_AND_UPDATE_ACCOUNT_CANCEL,
+
+ /* To be added more */
+}emf_noti_on_network_event;
+
+
+
+/**
+ * This enumeration specifies the core engine type.
+ */
+typedef enum
+{
+ EMF_ENGINE_TYPE_EM_CORE = 1, /**< Specifies the Callia mail core engine.*/
+} emf_engine_type_t;
+
+/**
+ * This enumeration specifies the mail type of account.
+ */
+typedef enum
+{
+ EMF_BIND_TYPE_DISABLE = 0, /**< Specifies the bind type for Disabled account.*/
+ EMF_BIND_TYPE_EM_CORE = 1, /**< Specifies the bind type for Callia.*/
+} emf_account_bind_t;
+
+/**
+ * This enumeration specifies the server type of account.
+ */
+typedef enum
+{
+ EMF_SERVER_TYPE_POP3 = 1, /**< Specifies the POP3 Server.*/
+ EMF_SERVER_TYPE_IMAP4, /**< Specifies the IMAP4 Server.*/
+ EMF_SERVER_TYPE_SMTP, /**< Specifies the SMTP Server.*/
+ EMF_SERVER_TYPE_NONE, /**< Specifies the Local.*/
+ EMF_SERVER_TYPE_ACTIVE_SYNC, /** < Specifies the Active Sync. */
+} emf_account_server_t;
+
+/**
+ * This enumeration specifies the mode of retrieval.
+ */
+typedef enum
+{
+ EMF_IMAP4_RETRIEVAL_MODE_NEW = 0, /**< Specifies the retrieval mode for new email.*/
+ EMF_IMAP4_RETRIEVAL_MODE_ALL, /**< Specifies the retrieval mode for all email.*/
+} emf_imap4_retrieval_mode_t;
+
+/**
+ * This enumeration specifies the filtering type.
+ */
+typedef enum
+{
+ EMF_FILTER_FROM = 1, /**< Specifies the filtering of sender.*/
+ EMF_FILTER_SUBJECT, /**< Specifies the filtering of email subject.*/
+ EMF_FILTER_BODY, /** < Specifies the filterinf of email body.*/
+} emf_rule_type_t;
+
+
+/**
+ * This enumeration specifies the rules for filtering type.
+ */
+typedef enum
+{
+ RULE_TYPE_INCLUDES = 1, /**< Specifies the filtering rule for includes.*/
+ RULE_TYPE_EXACTLY, /**< Specifies the filtering rule for Exactly same as.*/
+} emf_filtering_type_t;
+
+
+/**
+ * This enumeration specifies the action for filtering type.
+ */
+typedef enum
+{
+ EMF_FILTER_MOVE = 1, /**< Specifies the move of email.*/
+ EMF_FILTER_BLOCK = 2, /**< Specifies the block of email.*/
+ EMF_FILTER_DELETE = 3, /**< Specifies delete email.*/
+} emf_rule_action_t;
+
+/**
+ * This enumeration specifies the email status.
+ */
+typedef enum
+{
+ EMF_MAIL_STATUS_NONE = 0, /**< The Mail is in No Operation state */
+ EMF_MAIL_STATUS_RECEIVED, /**< The mail is a received mail.*/
+ EMF_MAIL_STATUS_SENT, /**< The mail is a sent mail.*/
+ EMF_MAIL_STATUS_SAVED, /**< The mail is a saved mail.*/
+ EMF_MAIL_STATUS_SAVED_OFFLINE, /**< The mail is a saved mail in offline-mode.*/
+ EMF_MAIL_STATUS_SENDING, /**< The mail is being sent.*/
+ EMF_MAIL_STATUS_SEND_FAILURE, /**< The mail is a mail to been failed to send.*/
+ EMF_MAIL_STATUS_SEND_CANCELED, /**< The mail is a cancelled mail.*/
+ EMF_MAIL_STATUS_SEND_WAIT, /**< The mail is a mail to be send .*/
+} emf_mail_status_t;
+
+/**
+ * This enumeration specifies the email priority.
+ */
+typedef enum
+{
+ EMF_MAIL_PRIORITY_HIGH = 1, /**< The priority is high.*/
+ EMF_MAIL_PRIORITY_NORMAL = 3, /**< The priority is normal.*/
+ EMF_MAIL_PRIORITY_LOW = 5, /**< The priority is low.*/
+} emf_mail_priority_t;
+
+/**
+ * This enumeration specifies the email status.
+ */
+typedef enum
+{
+ EMF_MAIL_REPORT_NONE = 0, /**< The mail isn't report mail.*/
+ EMF_MAIL_REPORT_DSN, /**< The mail is a delivery-status report mail.*/
+ EMF_MAIL_REPORT_MDN, /**< The mail is a read-status report mail.*/
+ EMF_MAIL_REPORT_REQUEST, /**< The mail require a read-status report mail.*/
+} emf_mail_report_t;
+
+/**
+ * This enumeration specifies the DRM type
+ */
+typedef enum
+{
+ EMF_ATTACHMENT_DRM_NONE = 0, /**< The mail isn't DRM file.*/
+ EMF_ATTACHMENT_DRM_OBJECT, /**< The mail is a DRM object.*/
+ EMF_ATTACHMENT_DRM_RIGHTS, /**< The mail is a DRM rights as xml format.*/
+ EMF_ATTACHMENT_DRM_DCF, /**< The mail is a DRM dcf.*/
+} emf_attachment_drm_t;
+
+typedef enum
+{
+ EMF_MAIL_TYPE_NORMAL = 0, /* NOT a meeting request mail. A Normal mail */
+ EMF_MAIL_TYPE_MEETING_REQUEST = 1, /* a meeting request mail from a serve */
+ EMF_MAIL_TYPE_MEETING_RESPONSE = 2, /* a response mail about meeting reques */
+ EMF_MAIL_TYPE_MEETING_ORIGINATINGREQUEST = 3 /* a originating mail about meeting reques */
+} emf_mail_type_t;
+
+typedef enum
+{
+ EMF_MEETING_RESPONSE_NONE = 0,
+ EMF_MEETING_RESPONSE_ACCEPT,
+ EMF_MEETING_RESPONSE_TENTATIVE,
+ EMF_MEETING_RESPONSE_DECLINE,
+ EMF_MEETING_RESPONSE_REQUEST, /* create a meeting reques */
+ EMF_MEETING_RESPONSE_CANCEL, /* create a meeting cancelatio */
+} emf_meeting_response_t;
+
+
+typedef enum
+{
+ EMF_ACTION_SEND_MAIL = 0,
+ EMF_ACTION_SYNC_HEADER,
+ EMF_ACTION_DOWNLOAD_BODY,
+ EMF_ACTION_DOWNLOAD_ATTACHMENT,
+ EMF_ACTION_DELETE_MAIL,
+ EMF_ACTION_SEARCH_MAIL,
+ EMF_ACTION_SAVE_MAIL,
+ EMF_ACTION_SYNC_MAIL_FLAG_TO_SERVER,
+ EMF_ACTION_SYNC_FLAGS_FIELD_TO_SERVER,
+ EMF_ACTION_MOVE_MAIL,
+ EMF_ACTION_CREATE_MAILBOX, /* = 1 */
+ EMF_ACTION_DELETE_MAILBOX,
+ EMF_ACTION_SYNC_HEADER_OMA,
+ EMF_ACTION_VALIDATE_ACCOUNT,
+ EMF_ACTION_VALIDATE_AND_CREATE_ACCOUNT,
+ EMF_ACTION_VALIDATE_AND_UPDATE_ACCOUNT,
+ EMF_ACTION_ACTIVATE_PDP = 20,
+ EMF_ACTION_DEACTIVATE_PDP,
+ EMF_ACTION_UPDATE_MAIL,
+ EMF_ACTION_SET_MAIL_SLOT_SIZE,
+ EMF_ACTION_NUM,
+} emf_action_t;
+
+/**
+ * This enumeration specifies the status of getting envelope list.
+ */
+typedef enum
+{
+ EMF_LIST_NONE = 0,
+ EMF_LIST_WAITING,
+ EMF_LIST_PREPARE, /**< Specifies the preparation.*/
+ EMF_LIST_CONNECTION_START, /**< Specifies the connection start.*/
+ EMF_LIST_CONNECTION_SUCCEED, /**< Specifies the success of connection.*/
+ EMF_LIST_CONNECTION_FINISH, /**< Specifies the connection finish.*/
+ EMF_LIST_CONNECTION_FAIL, /**< Specifies the connection failure.*/
+ EMF_LIST_START, /**< Specifies the getting start.*/
+ EMF_LIST_PROGRESS, /**< Specifies the status of getting.*/
+ EMF_LIST_FINISH, /**< Specifies the getting complete.*/
+ EMF_LIST_FAIL, /**< Specifies the download failure.*/
+} emf_envelope_list_status_t;
+
+/**
+ * This enumeration specifies the downloaded status of email.
+ */
+typedef enum
+{
+ EMF_DOWNLOAD_NONE = 0,
+ EMF_DOWNLOAD_WAITING,
+ EMF_DOWNLOAD_PREPARE, /**< Specifies the preparation.*/
+ EMF_DOWNLOAD_CONNECTION_START, /**< Specifies the connection start.*/
+ EMF_DOWNLOAD_CONNECTION_SUCCEED, /**< Specifies the success of connection.*/
+ EMF_DOWNLOAD_CONNECTION_FINISH, /**< Specifies the connection finish.*/
+ EMF_DOWNLOAD_CONNECTION_FAIL, /**< Specifies the connection failure.*/
+ EMF_DOWNLOAD_START, /**< Specifies the download start.*/
+ EMF_DOWNLOAD_PROGRESS, /**< Specifies the status of download.*/
+ EMF_DOWNLOAD_FINISH, /**< Specifies the download complete.*/
+ EMF_DOWNLOAD_FAIL, /**< Specifies the download failure.*/
+} emf_download_status_t;
+
+/**
+ * This enumeration specifies the status of sending email.
+ */
+typedef enum
+{
+ EMF_SEND_NONE = 0,
+ EMF_SEND_WAITING,
+ EMF_SEND_PREPARE, /**< Specifies the preparation.*/
+ EMF_SEND_CONNECTION_START, /**< Specifies the connection start.*/
+ EMF_SEND_CONNECTION_SUCCEED, /**< Specifies the success of connection.*/
+ EMF_SEND_CONNECTION_FINISH, /**< Specifies the connection finish.*/
+ EMF_SEND_CONNECTION_FAIL, /**< Specifies the connection failure.*/
+ EMF_SEND_START, /**< Specifies the sending start.*/
+ EMF_SEND_PROGRESS, /**< Specifies the status of sending.*/
+ EMF_SEND_FINISH, /**< Specifies the sending complete.*/
+ EMF_SEND_FAIL, /**< Specifies the sending failure.*/
+ EMF_SAVE_WAITING, /**< Specfies the Waiting of Sync */
+} emf_send_status_t;
+
+typedef enum
+{
+ EMF_SYNC_NONE = 0,
+ EMF_SYNC_WAITING,
+ EMF_SYNC_PREPARE,
+ EMF_SYNC_CONNECTION_START,
+ EMF_SYNC_CONNECTION_SUCCEED,
+ EMF_SYNC_CONNECTION_FINISH,
+ EMF_SYNC_CONNECTION_FAIL,
+ EMF_SYNC_START,
+ EMF_SYNC_PROGRESS,
+ EMF_SYNC_FINISH,
+ EMF_SYNC_FAIL,
+} emf_sync_status_t;
+
+/**
+* This enumeration specifies the deleting status of email.
+*/
+typedef enum
+{
+ EMF_DELETE_NONE = 0,
+ EMF_DELETE_WAITING,
+ EMF_DELETE_PREPARE, /**< Specifies the preparation.*/
+ EMF_DELETE_CONNECTION_START, /**< Specifies the connection start.*/
+ EMF_DELETE_CONNECTION_SUCCEED, /**< Specifies the success of connection.*/
+ EMF_DELETE_CONNECTION_FINISH, /**< Specifies the connection finish.*/
+ EMF_DELETE_CONNECTION_FAIL, /**< Specifies the connection failure.*/
+ EMF_DELETE_START, /**< Specifies the deletion start.*/
+ EMF_DELETE_PROGRESS, /**< Specifies the status of deleting.*/
+ EMF_DELETE_SERVER_PROGRESS, /**< Specifies the status of server deleting.*/
+ EMF_DELETE_LOCAL_PROGRESS, /**< Specifies the status of local deleting.*/
+ EMF_DELETE_FINISH, /**< Specifies the deletion complete.*/
+ EMF_DELETE_FAIL, /**< Specifies the deletion failure.*/
+} emf_delete_status_t;
+
+/**
+* This enumeration specifies the status of validating account
+*/
+typedef enum
+{
+ EMF_VALIDATE_ACCOUNT_NONE = 0,
+ EMF_VALIDATE_ACCOUNT_WAITING,
+ EMF_VALIDATE_ACCOUNT_PREPARE, /**< Specifies the preparation.*/
+ EMF_VALIDATE_ACCOUNT_CONNECTION_START, /**< Specifies the connection start.*/
+ EMF_VALIDATE_ACCOUNT_CONNECTION_SUCCEED, /**< Specifies the success of connection.*/
+ EMF_VALIDATE_ACCOUNT_CONNECTION_FINISH, /**< Specifies the connection finish.*/
+ EMF_VALIDATE_ACCOUNT_CONNECTION_FAIL, /**< Specifies the connection failure.*/
+ EMF_VALIDATE_ACCOUNT_START, /**< Specifies the getting start.*/
+ EMF_VALIDATE_ACCOUNT_PROGRESS, /**< Specifies the status of getting.*/
+ EMF_VALIDATE_ACCOUNT_FINISH, /**< Specifies the getting complete.*/
+ EMF_VALIDATE_ACCOUNT_FAIL, /**< Specifies the validation failure.*/
+} emf_validate_account_status_t;
+
+typedef enum
+{
+ EMF_SET_SLOT_SIZE_NONE = 0,
+ EMF_SET_SLOT_SIZE_WAITING,
+ EMF_SET_SLOT_SIZE_START,
+ EMF_SET_SLOT_SIZE_FINISH,
+ EMF_SET_SLOT_SIZE_FAIL,
+}emf_set_slot_size_status_e;
+
+/**
+* This enumeration specifies the type of mailbox
+*/
+typedef enum
+{
+ EMF_MAILBOX_TYPE_NONE = 0, /**< Unspecified mailbox type*/
+ EMF_MAILBOX_TYPE_INBOX = 1, /**< Specified inbox type*/
+ EMF_MAILBOX_TYPE_SENTBOX = 2, /**< Specified sent box type*/
+ EMF_MAILBOX_TYPE_TRASH = 3, /**< Specified trash type*/
+ EMF_MAILBOX_TYPE_DRAFT = 4, /**< Specified draft box type*/
+ EMF_MAILBOX_TYPE_SPAMBOX = 5, /**< Specified spam box type*/
+ EMF_MAILBOX_TYPE_OUTBOX = 6, /**< Specified outbox type*/
+ EMF_MAILBOX_TYPE_ALL_EMAILS = 7, /**< Specified all emails type of gmail*/
+ EMF_MAILBOX_TYPE_SEARCH_RESULT = 8, /**< Specified mailbox type for result of search on server */
+ EMF_MAILBOX_TYPE_USER_DEFINED = 0xFF, /**< Specified mailbox type for all other mailboxes */
+}emf_mailbox_type_e;
+
+typedef enum
+{
+ EMF_SYNC_LATEST_MAILS_FIRST = 0,
+ EMF_SYNC_OLDEST_MAILS_FIRST,
+ EMF_SYNC_ALL_MAILBOX_50_MAILS,
+} EMF_RETRIEVE_MODE;
+
+/* event typ */
+typedef enum
+{
+ EMF_EVENT_NONE = 0,
+ EMF_EVENT_SYNC_HEADER = 1, /* synchronize mail headers with server (network used) */
+ EMF_EVENT_DOWNLOAD_BODY, /* download mail body from server (network used)*/
+ EMF_EVENT_DOWNLOAD_ATTACHMENT, /* download mail attachment from server (network used) */
+ EMF_EVENT_SEND_MAIL, /* send a mail (network used) */
+ EMF_EVENT_SEND_MAIL_SAVED, /* send all mails in 'outbox' box (network used) */
+ EMF_EVENT_SYNC_IMAP_MAILBOX, /* download imap mailboxes from server (network used) */
+ EMF_EVENT_DELETE_MAIL, /* delete mails (network unused) */
+ EMF_EVENT_DELETE_MAIL_ALL, /* delete all mails (network unused) */
+ EMF_EVENT_SYNC_MAIL_FLAG_TO_SERVER, /* sync mail flag to server */
+ EMF_EVENT_SYNC_FLAGS_FIELD_TO_SERVER, /* sync a field of flags to server */
+ EMF_EVENT_SAVE_MAIL,
+ EMF_EVENT_MOVE_MAIL, /* move mails to specific mailbox on server */
+ EMF_EVENT_CREATE_MAILBOX,
+ EMF_EVENT_UPDATE_MAILBOX,
+ EMF_EVENT_DELETE_MAILBOX,
+ EMF_EVENT_ISSUE_IDLE,
+ EMF_EVENT_SYNC_HEADER_OMA,
+ EMF_EVENT_VALIDATE_ACCOUNT,
+ EMF_EVENT_VALIDATE_AND_CREATE_ACCOUNT,
+ EMF_EVENT_VALIDATE_AND_UPDATE_ACCOUNT,
+
+ EMF_EVENT_ADD_MAIL = 10001,
+ EMF_EVENT_UPDATE_MAIL_OLD = 10002,
+ EMF_EVENT_UPDATE_MAIL = 10003,
+ EMF_EVENT_SET_MAIL_SLOT_SIZE = 20000,
+
+/* EMF_EVENT_LOCAL_ACTIVITY, // __LOCAL_ACTIVITY_ */
+
+ EMF_EVENT_BULK_PARTIAL_BODY_DOWNLOAD, /* __FEATURE_PARTIAL_BODY_DOWNLOAD__ supported */
+ EMF_EVENT_LOCAL_ACTIVITY_SYNC_BULK_PBD, /* __FEATURE_PARTIAL_BODY_DOWNLOAD__ supported */
+ EMF_EVENT_GET_PASSWORD_LENGTH /* get password length of an account */
+} emf_event_type_t;
+
+/* event statu */
+typedef enum
+{
+ EMF_EVENT_STATUS_UNUSED = 0,
+ EMF_EVENT_STATUS_WAIT,
+ EMF_EVENT_STATUS_STARTED,
+ EMF_EVENT_STATUS_CANCELED,
+} emf_event_status_type_t;
+
+
+/* sorting_orde */
+typedef enum
+{
+ EMF_SORT_DATETIME_HIGH = 0,
+ EMF_SORT_DATETIME_LOW,
+ EMF_SORT_SENDER_HIGH,
+ EMF_SORT_SENDER_LOW,
+ EMF_SORT_RCPT_HIGH,
+ EMF_SORT_RCPT_LOW,
+ EMF_SORT_SUBJECT_HIGH,
+ EMF_SORT_SUBJECT_LOW,
+ EMF_SORT_PRIORITY_HIGH,
+ EMF_SORT_PRIORITY_LOW,
+ EMF_SORT_ATTACHMENT_HIGH,
+ EMF_SORT_ATTACHMENT_LOW,
+ EMF_SORT_FAVORITE_HIGH,
+ EMF_SORT_FAVORITE_LOW,
+ EMF_SORT_MAILBOX_NAME_HIGH,
+ EMF_SORT_MAILBOX_NAME_LOW,
+ EMF_SORT_FLAGGED_FLAG_HIGH,
+ EMF_SORT_FLAGGED_FLAG_LOW,
+ EMF_SORT_SEEN_FLAG_HIGH,
+ EMF_SORT_SEEN_FLAG_LOW,
+ EMF_SORT_END,
+}emf_sort_type_t;
+
+typedef enum
+{
+ EMAIL_MAILBOX_SORT_BY_NAME_ASC = 0,
+ EMAIL_MAILBOX_SORT_BY_NAME_DSC,
+ EMAIL_MAILBOX_SORT_BY_TYPE_ASC,
+ EMAIL_MAILBOX_SORT_BY_TYPE_DSC,
+} email_mailbox_sort_type_t;
+
+
+/**
+* This enumeration specifies the priority.
+*/
+enum
+{
+ EMF_OPTION_PRIORITY_HIGH = 1, /**< Specifies the high priority.*/
+ EMF_OPTION_PRIORITY_NORMAL = 3, /**< Specifies the normal priority*/
+ EMF_OPTION_PRIORITY_LOW = 5, /**< Specifies the low priority.*/
+};
+
+/**
+* This enumeration specifies the saving save a copy after sending.
+*/
+enum
+{
+ EMF_OPTION_KEEP_LOCAL_COPY_OFF = 0, /**< Specifies off the keeping local copy.*/
+ EMF_OPTION_KEEP_LOCAL_COPY_ON = 1, /**< Specifies on the keeping local copy.*/
+};
+
+/**
+* This enumeration specifies the request of delivery report.
+*/
+enum
+{
+ EMF_OPTION_REQ_DELIVERY_RECEIPT_OFF = 0, /**< Specifies off the requesting delivery receipt.*/
+ EMF_OPTION_REQ_DELIVERY_RECEIPT_ON = 1, /**< Specifies on the requesting delivery receipt.*/
+};
+
+/**
+* This enumeration specifies the request of read receipt.
+*/
+enum
+{
+ EMF_OPTION_REQ_READ_RECEIPT_OFF = 0, /**< Specifies off the requesting read receipt.*/
+ EMF_OPTION_REQ_READ_RECEIPT_ON = 1, /**< Specifies on the requesting read receipt.*/
+};
+
+/**
+* This enumeration specifies the blocking of address.
+*/
+enum
+{
+ EMF_OPTION_BLOCK_ADDRESS_OFF = 0, /**< Specifies off the blocking by address.*/
+ EMF_OPTION_BLOCK_ADDRESS_ON = 1, /**< Specifies on the blocking by address.*/
+};
+
+/**
+* This enumeration specifies the blocking of subject.
+*/
+enum
+{
+ EMF_OPTION_BLOCK_SUBJECT_OFF = 0, /**< Specifies off the blocking by subject.*/
+ EMF_OPTION_BLOCK_SUBJECT_ON = 1, /**< Specifies on the blocking by subject.*/
+};
+
+enum
+{
+ EMF_LIST_TYPE_UNREAD = -3,
+ EMF_LIST_TYPE_LOCAL = -2,
+ EMF_LIST_TYPE_THREAD = -1,
+ EMF_LIST_TYPE_NORMAL = 0
+};
+
+/**
+* This enumeration specifies the mailbox sync type.
+*/
+enum
+{
+ EMF_MAILBOX_ALL = -1, /**< All mailboxes.*/
+ EMF_MAILBOX_FROM_SERVER = 0, /**< Mailboxes from server. */
+ EMF_MAILBOX_FROM_LOCAL = 1, /**< Mailboxes from local. */
+};
+
+typedef enum
+{
+ APPEND_BODY = 1,
+ UPDATE_MAILBOX,
+ UPDATE_ATTACHMENT_INFO,
+ UPDATE_FLAG,
+ UPDATE_SAVENAME,
+ UPDATE_EXTRA_FLAG,
+ UPDATE_MAIL,
+ UPDATE_DATETIME,
+ UPDATE_FROM_CONTACT_INFO,
+ UPDATE_TO_CONTACT_INFO,
+ UPDATE_ALL_CONTACT_NAME,
+ UPDATE_ALL_CONTACT_INFO,
+ UPDATE_STICKY_EXTRA_FLAG,
+ UPDATE_PARTIAL_BODY_DOWNLOAD,
+ UPDATE_MEETING,
+ UPDATE_SEEN_FLAG_OF_THREAD,
+} emf_mail_change_type_t;
+
+
+/**
+* This enumeration specifies the address type.
+*/
+typedef enum
+{
+ EMF_ADDRESS_TYPE_FROM = 1, /**< Specifies the from address.*/
+ EMF_ADDRESS_TYPE_TO, /**< Specifies the to receipient address.*/
+ EMF_ADDRESS_TYPE_CC, /**< Specifies the cc receipient address.*/
+ EMF_ADDRESS_TYPE_BCC, /**< Specifies the bcc receipient address.*/
+ EMF_ADDRESS_TYPE_REPLY, /**< Specifies the reply receipient address.*/
+ EMF_ADDRESS_TYPE_RETURN, /**< Specifies the return receipient address.*/
+} emf_address_type_t;
+
+/**
+ * This enumeration specifies the search type for searching mailbox.
+ */
+typedef enum
+{
+ EMF_MAILBOX_SEARCH_KEY_TYPE_SUBJECT, /**< The search key is for searching subject.*/
+ EMF_MAILBOX_SEARCH_KEY_TYPE_FROM, /**< The search key is for searching sender address.*/
+ EMF_MAILBOX_SEARCH_KEY_TYPE_BODY, /**< The search key is for searching body.*/
+ EMF_MAILBOX_SEARCH_KEY_TYPE_TO, /**< The search key is for searching recipient address.*/
+} emf_mailbox_search_key_t;
+
+/**
+ * This enumeration specifies the download status of mail body.
+ */
+
+typedef enum
+{
+ EMF_BODY_DOWNLOAD_STATUS_NONE = 0,
+ EMF_BODY_DOWNLOAD_STATUS_FULLY_DOWNLOADED = 1,
+ EMF_BODY_DOWNLOAD_STATUS_PARTIALLY_DOWNLOADED = 2,
+} emf_body_download_status_t;
+
+/**
+ * This enumeration specifies the moving type.
+ */
+typedef enum
+{
+ EMF_MOVED_BY_COMMAND = 0,
+ EMF_MOVED_BY_MOVING_THREAD,
+ EMF_MOVED_AFTER_SENDING
+} emf_move_type;
+
+/**
+ * This enumeration specifies the deletion type.
+ */
+typedef enum
+{
+ EMF_DELETED_BY_COMMAND = 0,
+ EMF_DELETED_BY_OVERFLOW,
+ EMF_DELETED_BY_DELETING_THREAD,
+ EMF_DELETED_BY_MOVING_TO_OTHER_ACCOUNT,
+ EMF_DELETED_AFTER_SENDING,
+ EMF_DELETED_FROM_SERVER,
+} emf_delete_type;
+
+/**
+ * This enumeration specifies the status field type.
+ */
+typedef enum
+{
+ EMF_FLAGS_SEEN_FIELD = 0,
+ EMF_FLAGS_DELETED_FIELD,
+ EMF_FLAGS_FLAGGED_FIELD,
+ EMF_FLAGS_ANSWERED_FIELD,
+ EMF_FLAGS_RECENT_FIELD,
+ EMF_FLAGS_DRAFT_FIELD,
+ EMF_FLAGS_FORWARDED_FIELD,
+ EMF_FLAGS_FIELD_COUNT,
+} emf_flags_field_type;
+
+typedef enum
+{
+ EMF_FLAG_NONE = 0,
+ EMF_FLAG_FLAGED = 1,
+ EMF_FLAG_TASK_STATUS_CLEAR = 2,
+ EMF_FLAG_TASK_STATUS_ACTIVE = 3,
+ EMF_FLAG_TASK_STATUS_COMPLETE = 4,
+} emf_flagged_type;
+
+
+/*****************************************************************************/
+/* Data Structures */
+/*****************************************************************************/
+
+/**
+ * This structure is used to save mail time.
+ */
+typedef struct
+{
+ unsigned short year; /**< Specifies the Year.*/
+ unsigned short month; /**< Specifies the Month.*/
+ unsigned short day; /**< Specifies the Day.*/
+ unsigned short hour; /**< Specifies the Hour.*/
+ unsigned short minute; /**< Specifies the Minute.*/
+ unsigned short second; /**< Specifies the Second.*/
+} emf_datetime_t;
+
+/**
+ * This structure is used to save the options.
+ */
+typedef struct
+{
+ int priority; /**< Specifies the prority. 1=high 3=normal 5=low.*/
+ int keep_local_copy; /**< Specifies the saving save a copy after sending.*/
+ int req_delivery_receipt; /**< Specifies the request of delivery report. 0=off 1=on*/
+ int req_read_receipt; /**< Specifies the request of read receipt. 0=off 1=on*/
+ int download_limit; /**< Specifies the limit of size for downloading.*/
+ int block_address; /**< Specifies the blocking of address. 0=off 1=on*/
+ int block_subject; /**< Specifies the blocking of subject. 0=off 1=on*/
+ char *display_name_from; /**< Specifies the display name of from.*/
+ int reply_with_body; /**< Specifies the replying with body 0=off 1=on*/
+ int forward_with_files; /**< Specifies the fowarding with files 0=off 1=on*/
+ int add_myname_card; /**< Specifies the adding name card 0=off 1=on*/
+ int add_signature; /**< Specifies the adding signature 0=off 1=on*/
+ char *signature; /**< Specifies the signature*/
+ int add_my_address_to_bcc; /**< Specifies whether bcc field should be always filled with my address. 0=off 1=on*/
+} emf_option_t;
+
+/**
+ * This structure is used to save the information of email account.
+ */
+typedef struct
+{
+ emf_account_bind_t account_bind_type; /**< Specifies the Bind Type.*/
+ char *account_name; /**< Specifies the account name.*/
+ emf_account_server_t receiving_server_type; /**< Specifies the receiving server type.*/
+ char *receiving_server_addr; /**< Specifies the address of receiving server.*/
+ char *email_addr; /**< Specifies the email adderee.*/
+ char *user_name; /**< Specifies the user name.*/
+ char *password; /**< Specifies the password.*/
+ emf_imap4_retrieval_mode_t retrieval_mode; /**< Specifies the retrieval mode in IMAP case.*/
+ int port_num; /**< Specifies the port number of receiving server.*/
+ int use_security; /**< Specifies the security such as SSL.*/
+ emf_account_server_t sending_server_type; /**< Specifies the type of sending server.*/
+ char *sending_server_addr; /**< Specifies the address of sending server.*/
+ int sending_port_num; /**< Specifies the port number of sending server.*/
+ int sending_auth; /**< Specifies the authentication of sending server.*/
+ int sending_security; /**< Specifies the security such as SSL.*/
+ char *sending_user; /**< Specifies the user name of SMTP server.*/
+ char *sending_password; /**< Specifies the user password of SMTP server.*/
+ char *display_name; /**< Specifies the display name.*/
+ char *reply_to_addr; /**< Specifies the reply email address.*/
+ char *return_addr; /**< Specifies the email address for return.*/
+ int account_id; /**< Specifies the ID of account. Especially, 1 is assigned to Local Account.*/
+ int keep_on_server; /**< Specifies the keeping mail on server.*/
+ int flag1; /**< Specifies the downloading option. 0 is subject only, 1 is text body, 2 is normal.*/
+ int flag2; /**< Specifies the 'Same as POP3' option. 0 is none, 1 is 'Same as POP3'.*/
+ int pop_before_smtp; /**< POP before SMTP authentication */
+ int apop; /**< APOP Authentication */
+ char *logo_icon_path; /**< Account logo icon */
+ int preset_account; /**< Preset account or not */
+ emf_option_t options; /**< Specifies the Sending options */
+ int target_storage; /**< Specifies the targetStorage. 0 is phone, 1 is MMC */
+ int check_interval; /**< Specifies the Check interval. Unit is minutes */
+ int my_account_id; /**< Specifies accout id of my account */
+ int index_color; /**< Specifies index color for displaying classifying accounts */
+}emf_account_t;
+
+/**
+ * This structure is used to save the information of email server.
+ */
+
+typedef struct
+{
+ int configuration_id; /**< Specifies the id of configuration.*/
+ emf_account_server_t protocol_type; /**< Specifies the type of configuration.*/
+ char *server_addr; /**< Specifies the address of configuration.*/
+ int port_number; /**< Specifies the port number of configuration.*/
+ int security_type; /**< Specifies the security such as SSL.*/
+ int auth_type; /**< Specifies the authentication type of configuration.*/
+} emf_protocol_config_t;
+
+typedef struct
+{
+ char *service_name; /**< Specifies the name of service.*/
+ int authname_format; /**< Specifies the type of user name for authentication.*/
+ int protocol_conf_count; /**< Specifies count of protocol configurations.*/
+ emf_protocol_config_t *protocol_config_array; /**< Specifies array of protocol configurations.*/
+} emf_server_info_t;
+
+typedef struct
+{
+ int mailbox_type;
+ char mailbox_name[MAILBOX_NAME_LENGTH];
+} emf_mailbox_type_item_t;
+
+/**
+ * This structure is contains the Mail information.
+ */
+
+typedef struct
+{
+ int mail_id; /**< Specifies the Mail ID.*/
+ int account_id; /**< Specifies the Account ID.*/
+ char *mailbox_name; /**< Specifies the Mailbox Name.*/
+ int mailbox_type; /**< Specifies the mailbox type of the mail. */
+ char *subject; /**< Specifies the subject.*/
+ char *datetime; /**< Specifies the Date time.*/
+ int server_mail_status; /**< Specifies the Whether sever mail or not.*/
+ char *server_mailbox_name; /**< Specifies the server mailbox.*/
+ char *server_mail_id; /**< Specifies the Server Mail ID.*/
+ char *message_id; /**< Specifies the message id */
+ char *full_address_from; /**< Specifies the From Addr.*/
+ char *full_address_reply; /**< Specifies the Reply to addr */
+ char *full_address_to; /**< Specifies the To addr.*/
+ char *full_address_cc; /**< Specifies the CC addr.*/
+ char *full_address_bcc; /**< Specifies the BCC addr*/
+ char *full_address_return; /**< Specifies the return Path*/
+ char *email_address_sender; /**< Specifies the email address of sender.*/
+ char *email_address_recipient; /**< Specifies the email address of recipients.*/
+ char *alias_sender; /**< Specifies the alias of sender. */
+ char *alias_recipient; /**< Specifies the alias of recipients. */
+ int body_download_status; /**< Specifies the Text donwloaded or not.*/
+ char *file_path_plain; /**< Specifies the path of text mail body.*/
+ char *file_path_html; /**< Specifies the path of HTML mail body.*/
+ int mail_size; /**< Specifies the Mail Size.*/
+ char flags_seen_field; /**< Specifies the seen flags*/
+ char flags_deleted_field; /**< Specifies the deleted flags*/
+ char flags_flagged_field; /**< Specifies the flagged flags*/
+ char flags_answered_field; /**< Specifies the answered flags*/
+ char flags_recent_field; /**< Specifies the recent flags*/
+ char flags_draft_field; /**< Specifies the draft flags*/
+ char flags_forwarded_field; /**< Specifies the forwarded flags*/
+ int DRM_status; /**< Specifies the DRM state. */
+ int priority; /**< Specifies the priority of Mails.*/
+ int save_status; /**< Specifies the save status*/
+ int lock_status; /**< Specifies the Locked*/
+ int report_status; /**< Specifies the Mail Report.*/
+ int attachment_count; /**< Specifies the attachment count. */
+ int inline_content_count; /**< Specifies the inline content count. */
+ int thread_id; /**< Specifies the thread id for thread view. */
+ int thread_item_count; /**< Specifies the item count of specific thread. */
+ char *preview_text; /**< Specifies the preview body. */
+ int meeting_request_status; /**< Specifies the status of meeting request. */
+}emf_mail_data_t;
+
+/**
+ * This structure is contains information for displaying mail list.
+ */
+typedef struct
+{
+ int mail_id; /**< Specifies the Mail ID.*/
+ int account_id; /**< Specifies the Account ID.*/
+ char mailbox_name[STRING_LENGTH_FOR_DISPLAY]; /**< Specifies the Mailbox Name.*/
+ char from[STRING_LENGTH_FOR_DISPLAY]; /**< Specifies the from display name.*/
+ char from_email_address[MAX_EMAIL_ADDRESS_LENGTH]; /**< Specifies the from email address.*/
+ char recipients[STRING_LENGTH_FOR_DISPLAY]; /**< Specifies the recipients display name.*/
+ char subject[STRING_LENGTH_FOR_DISPLAY]; /**< Specifies the subject.*/
+ int is_text_downloaded; /**< Specifies the Text donwloaded or not.*/
+ char datetime[MAX_DATETIME_STRING_LENGTH]; /**< Specifies the Date time.*/
+ char flags_seen_field; /**< Specifies the seen flags*/
+ char flags_deleted_field; /**< Specifies the deleted flags*/
+ char flags_flagged_field; /**< Specifies the flagged flags*/
+ char flags_answered_field; /**< Specifies the answered flags*/
+ char flags_recent_field; /**< Specifies the recent flags*/
+ char flags_draft_field; /**< Specifies the draft flags*/
+ char flags_forwarded_field; /**< Specifies the forwarded flags*/
+ int priority; /**< Specifies the priority of Mails.*/
+ int save_status; /**< Specifies the save status*/
+ int is_locked; /**< Specifies the Locked*/
+ int is_report_mail; /**< Specifies the Mail Report.*/
+ int recipients_count; /**< Specifies the number of to Recipients*/
+ int has_attachment; /**< the mail has attachments or not[ 0: none, 1: over one] */
+ int has_drm_attachment; /**< the mail has drm attachment or not*/
+ char previewBodyText[MAX_PREVIEW_TEXT_LENGTH]; /**< text for preview body*/
+ int thread_id; /**< thread id for thread view*/
+ int thread_item_count; /**< item count of specific thread */
+ int is_meeting_request; /**< Whether the mail is a meeting request or not */
+}emf_mail_list_item_t;
+
+/**
+ * This structure is used to save the filtering structure.
+ */
+typedef struct
+{
+ int account_id; /**< Specifies the account ID.*/
+ int filter_id; /**< Specifies the filtering ID.*/
+ emf_rule_type_t type; /**< Specifies the filtering type.*/
+ char *value; /**< Specifies the filtering value.*/
+ emf_rule_action_t faction; /**< Specifies the action type for filtering.*/
+ char *mailbox; /**< Specifies the mail box if action type means move.*/
+ int flag1; /**< Specifies the activation.*/
+ int flag2; /**< Reserved.*/
+} emf_rule_t;
+
+/**
+ * This structure is used to save the information of mail flag.
+ */
+typedef struct
+{
+ unsigned int seen : 1; /**< Specifies the read email.*/
+ unsigned int deleted : 1; /**< Reserved.*/
+ unsigned int flagged : 1; /**< Specifies the flagged email.*/
+ unsigned int answered : 1; /**< Reserved.*/
+ unsigned int recent : 1; /**< Reserved.*/
+ unsigned int draft : 1; /**< Specifies the draft email.*/
+ unsigned int has_attachment : 1; /**< Reserved.*/
+ unsigned int forwarded : 1; /**< Reserved.*/
+ unsigned int sticky : 1; /**< Sticky flagged mails cannot be deleted */
+} emf_mail_flag_t;
+
+
+/**
+ * This structure is used to save the information of mail extra flag.
+ */
+typedef struct
+{
+ unsigned int priority : 3; /**< Specifies the mail priority.
+ The value is greater than or equal to EMF_MAIL_PRIORITY_HIGH.
+ The value is less than or eqult to EMF_MAIL_PRIORITY_LOW.*/
+ unsigned int status : 4; /**< Specifies the mail status.
+ The value is a value of enumeration emf_mail_status_t.*/
+ unsigned int noti : 1; /**< Specifies the notified mail.*/
+ unsigned int lock : 1; /**< Specifies the locked mail.*/
+ unsigned int report : 2; /**< Specifies the MDN/DSN mail. The value is a value of enumeration emf_mail_report_t.*/
+ unsigned int drm : 1; /**< Specifies the drm mail.*/
+ unsigned int text_download_yn : 2; /**< body download y/n*/ /* To be removed */
+} emf_extra_flag_t;
+
+/**
+ * This structure is used to save the email basic information.
+ */
+typedef struct
+{
+ int account_id; /**< Specifies the email's account ID.*/
+ int uid; /**< Specifies the email's UID on local.*/
+ int rfc822_size; /**< Specifies the email's size.*/
+ int body_downloaded; /**< Specifies the download of email body.*/
+ emf_mail_flag_t flags; /**< Specifies the email's flag information.*/
+ emf_extra_flag_t extra_flags; /**< Specifies the email's extra flag information.*/
+ char *sid; /**< Specifies the email's UID on server.*/
+ int is_meeting_request; /**< Specifies whether this mail is a meeting request mail or not. 0: normal mail, 1: meeting request mail from server, 2: response mail about meeting request mail */
+ int thread_id; /**< Specifies the email's thread id.*/
+ int thread_item_count; /**< Specifies the item count of thread*/
+} emf_mail_info_t;
+
+/**
+ * This structure is used to save the information of email header.
+ */
+typedef struct
+{
+ char *mid; /**< Specifies the message ID.*/
+ char *subject; /**< Specifies the email subject.*/
+ char *to; /**< Specifies the recipient.*/
+ char *from; /**< Specifies the sender.*/
+ char *cc; /**< Specifies the carbon copy.*/
+ char *bcc; /**< Specifies the blind carbon copy.*/
+ char *reply_to; /**< Specifies the replier.*/
+ char *return_path; /**< Specifies the address of return.*/
+ emf_datetime_t datetime; /**< Specifies the sending or receiving time.*/
+ char *from_contact_name;
+ char *to_contact_name;
+ char *cc_contact_name;
+ char *bcc_contact_name;
+ char *previewBodyText; /**< Specifies the text contains for preview body.*/
+} emf_mail_head_t;
+
+/**
+ * This structure is used to save the information of attachment.
+ */
+typedef struct st_emf_attachment_info
+{
+ int inline_content;
+ int attachment_id; /**< Specifies the attachment ID*/
+ char *name; /**< Specifies the attachment name.*/
+ int size; /**< Specifies the attachment size.*/
+ int downloaded; /**< Specifies the download of attachment.*/
+ char *savename; /**< Specifies the absolute path of attachment.*/
+ int drm; /**< Specifies the drm type.*/
+ struct st_emf_attachment_info *next; /**< Specifies the pointer of next attachment.*/
+} emf_attachment_info_t;
+
+typedef struct
+{
+ int attachment_id;
+ char *attachment_name;
+ char *attachment_path;
+ int attachment_size;
+ int mail_id;
+ int account_id;
+ char *mailbox_name;
+ int save_status;
+ int drm_status;
+ int inline_content_status;
+} emf_attachment_data_t;
+
+/**
+ * This structure is used to save the information of email body
+ */
+typedef struct
+{
+ char *plain; /**< Specifies the absolute path of file to contain email body (Plain Text).*/
+ char *plain_charset; /**< Specifies the character set of plain text boy. */
+ char *html; /**< Specifies the absolute path of file to contain email body (HTML).*/
+ int attachment_num; /**< Specifies the count of attachment.*/
+ emf_attachment_info_t *attachment; /**< Specifies the structure of attachment.*/
+} emf_mail_body_t;
+
+/**
+ * This structure is used to save the information of email
+ */
+typedef struct
+{
+ emf_mail_info_t *info; /**< Specifies the structure pointer of mail basic information.*/
+ emf_mail_head_t *head; /**< Specifies the structure pointer of email header.*/
+ emf_mail_body_t *body; /**< Specifies the structure pointer of email body.*/
+} emf_mail_t;
+
+
+typedef struct
+{
+ int offset_from_GMT;
+ char standard_name[32];
+ struct tm standard_time_start_date;
+ int standard_bias;
+ char daylight_name[32];
+ struct tm daylight_time_start_date;
+ int daylight_bias;
+} emf_time_zone_t;
+
+typedef struct
+{
+ int mail_id; /**< Specifies the mail id of meeting request on DB. This is the primary key. */
+ emf_meeting_response_t meeting_response; /**< Specifies the meeting response. */
+ struct tm start_time;
+ struct tm end_time;
+ char *location; /**< Specifies the location of meeting. Maximum length of this string is 32768 */
+ char global_object_id[MEETING_REQ_OBJECT_ID_LENGTH]; /**< Specifies the object id. */
+ emf_time_zone_t time_zone;
+} emf_meeting_request_t;
+
+/**
+ * This structure is used to save the informatioin of sender list with unread/total mail counts
+ */
+typedef struct
+{
+ char *address; /**< Specifies the address of a sender.*/
+ char *display_name; /**< Specifies a display name. This may be one of contact name, alias in original mail and email address of sender. (Priority order : contact name, alias, email address) */
+ int unread_count; /**< Specifies the number of unread mails received from sender address*/
+ int total_count; /**< Specifies the total number of mails which are received from sender address*/
+} emf_sender_list_t;
+
+
+/* Creates a type name for structure emf_mailbox_st */
+typedef struct emf_mailbox_st emf_mailbox_t; /**< This is an information of mail box. */
+
+/**
+ * This structure is used to save the information of mailbox.
+ */
+struct emf_mailbox_st
+{
+ int mailbox_id; /**< Unique id on mailbox table.*/
+ char *name; /**< Specifies the path of mailbox.*/
+ emf_mailbox_type_e mailbox_type;
+ char *alias; /**< Specifies the display name of mailbox.*/
+ int unread_count; /**< Specifies the Unread Mail count in the mailbox.*/
+ int total_mail_count_on_local; /**< Specifies the total number of mails in the mailbox in the local DB.*/
+ int total_mail_count_on_server; /**< Specifies the total number of mails in the mailbox in the mail server.*/
+ int hold_connection; /**< Will have a valid socket descriptor when connection to server is active.. else 0>*/
+ int local; /**< Specifies the local mailbox.*/
+ int synchronous; /**< Specifies the mailbox with synchronized the server.*/
+ int account_id; /**< Specifies the account ID for mailbox.*/
+ void *user_data; /**< Specifies the internal data.*/
+ void *mail_stream; /**< Specifies the internal data.*/
+ int has_archived_mails; /**< Specifies the archived mails.*/
+ int mail_slot_size; /**< Specifies how many mails can be stored.*/
+ char *account_name; /**< Specifies the name of account.*/
+ emf_mailbox_t *next; /**< Reserved.*/
+};
+
+
+typedef struct
+{
+ char *contact_name;
+ char *email_address;
+ char *alias;
+ int storage_type;
+ int contact_id;
+} emf_mail_contact_info_t;
+
+typedef struct
+{
+ emf_address_type_t address_type;
+ char *address;
+ char *display_name;
+ int storage_type;
+ int contact_id;
+} emf_address_info_t;
+
+typedef struct
+{
+ GList *from;
+ GList *to;
+ GList *cc;
+ GList *bcc;
+} emf_address_info_list_t;
+
+typedef struct
+{
+ int contact_id; /* Inpu */
+ int storage_type; /* Input, but not used in email-servic */
+ int address_count; /* Inpu */
+ char **address_list; /* Input, array of email account */
+ int unread_count; /* Outpu */
+} emf_contact_item_for_count_t;
+
+typedef struct
+{
+ int contact_id; /* Inpu */
+ int storage_type; /* Input, but not used in email-servic */
+ int address_count; /* Inpu */
+ char **address_list; /* Input array of email account */
+ int mail_id_count; /* Outpu */
+ int *mail_id_list; /* Outpu */
+} emf_contact_item_for_mail_id_t;
+
+typedef struct
+{
+ int address_type; /* type of mail (sender : 0, recipient : 1)*/
+ int address_count; /* The number of email addresse */
+ char **address_list; /* strings of email addresse */
+}emf_email_address_list_t;
+
+/* global account lis */
+typedef struct emf_account_list_t emf_account_list_t;
+struct emf_account_list_t
+{
+ emf_account_t *account;
+ emf_account_list_t *next;
+};
+
+
+/*****************************************************************************/
+/* Errors */
+/*****************************************************************************/
+
+#define EMF_ERROR_NONE 1 /* There is no error */
+#define EMF_ERROR_INVALID_PARAM -1001 /* invalid parameter was given. - Invalid input paramete */
+#define EMF_ERROR_INVALID_ACCOUNT -1002 /* invalid account information was given. - Unsupported accoun */
+#define EMF_ERROR_INVALID_USER -1003 /* NOT USED : unknown user ID was given. - Invalid user or passwor */
+#define EMF_ERROR_INVALID_PASSWORD -1004 /* NOT USED : invalid password was given. - Invalid user or passwor */
+#define EMF_ERROR_INVALID_SERVER -1005 /* invalid server information was given. - Server unavailabl */
+#define EMF_ERROR_INVALID_MAIL -1006 /* invalid mail information was given */
+#define EMF_ERROR_INVALID_ADDRESS -1007 /* invalid address information was given. - Incorrect addres */
+#define EMF_ERROR_INVALID_ATTACHMENT -1008 /* invalid attachment information was given */
+#define EMF_ERROR_INVALID_MAILBOX -1009 /* invalid mailbox information was given */
+#define EMF_ERROR_INVALID_FILTER -1010 /* invalid filter information was given */
+#define EMF_ERROR_INVALID_PATH -1011 /* invalid flle path was given */
+#define EMF_ERROR_INVALID_DATA -1012 /* NOT USE */
+#define EMF_ERROR_INVALID_RESPONSE -1013 /* unexpected network response was given. - Invalid server respons */
+#define EMF_ERROR_ACCOUNT_NOT_FOUND -1014 /* no matched account was found */
+#define EMF_ERROR_MAIL_NOT_FOUND -1015 /* no matched mail was found */
+#define EMF_ERROR_MAILBOX_NOT_FOUND -1016 /* no matched mailbox was found */
+#define EMF_ERROR_ATTACHMENT_NOT_FOUND -1017 /* no matched attachment was found */
+#define EMF_ERROR_FILTER_NOT_FOUND -1018 /* no matched filter was found */
+#define EMF_ERROR_CONTACT_NOT_FOUND -1019 /* no matched contact was found */
+#define EMF_ERROR_FILE_NOT_FOUND -1020 /* no matched file was found */
+#define EMF_ERROR_DATA_NOT_FOUND -1021 /* NOT USE */
+#define EMF_ERROR_NO_MORE_DATA -1022 /* NOT USE */
+#define EMF_ERROR_ALREADY_EXISTS -1023 /* data duplicate */
+#define EMF_ERROR_MAX_EXCEEDED -1024 /* NOT USE */
+#define EMF_ERROR_DATA_TOO_LONG -1025 /* NOT USE */
+#define EMF_ERROR_DATA_TOO_SMALL -1026 /* NOT USE */
+#define EMF_ERROR_NETWORK_TOO_BUSY -1027 /* NOT USE */
+#define EMF_ERROR_OUT_OF_MEMORY -1028 /* There is not enough memory */
+#define EMF_ERROR_DB_FAILURE -1029 /* database operation failed */
+#define EMF_ERROR_PROFILE_FAILURE -1030 /* no proper profile was found */
+#define EMF_ERROR_SOCKET_FAILURE -1031 /* socket operation failed */
+#define EMF_ERROR_CONNECTION_FAILURE -1032 /* network connection failed */
+#define EMF_ERROR_CONNECTION_BROKEN -1033 /* network connection was broken */
+#define EMF_ERROR_DISCONNECTED -1034 /* NOT USED : connection was disconnected */
+#define EMF_ERROR_LOGIN_FAILURE -1035 /* login failed */
+#define EMF_ERROR_NO_RESPONSE -1036 /* There is no server response */
+#define EMF_ERROR_MAILBOX_FAILURE -1037 /* The agent failed to scan mailboxes in server */
+#define EMF_ERROR_AUTH_NOT_SUPPORTED -1038 /* The server doesn't support authentication */
+#define EMF_ERROR_AUTHENTICATE -1039 /* The server failed to authenticate user */
+#define EMF_ERROR_TLS_NOT_SUPPORTED -1040 /* The server doesn't support TLS */
+#define EMF_ERROR_TLS_SSL_FAILURE -1041 /* The agent failed TLS/SSL */
+#define EMF_ERROR_APPEND_FAILURE -1042 /* The agent failed to append mail to server */
+#define EMF_ERROR_COMMAND_NOT_SUPPORTED -1043 /* The server doesn't support this command */
+#define EMF_ERROR_ANNONYM_NOT_SUPPORTED -1044 /* The server doesn't support anonymous user */
+#define EMF_ERROR_CERTIFICATE_FAILURE -1045 /* certificate failure - Invalid server certificat */
+#define EMF_ERROR_CANCELLED -1046 /* The job was canceled by user */
+#define EMF_ERROR_NOT_IMPLEMENTED -1047 /* The function was not implemented */
+#define EMF_ERROR_NOT_SUPPORTED -1048 /* The function is not supported */
+#define EMF_ERROR_MAIL_LOCKED -1049 /* The mail was locked */
+#define EMF_ERROR_SYSTEM_FAILURE -1050 /* There is a system error */
+#define EMF_ERROR_MAIL_MAX_COUNT -1052 /* The mailbox is full */
+#define EMF_ERROR_ACCOUNT_MAX_COUNT -1053 /* There is too many account */
+#define EMF_ERROR_MAIL_MEMORY_FULL -1054 /* There is no more storage */
+#define EMF_ERROR_MAIL_NOT_FOUND_ON_SERVER -1055 /* The expected mail is not found in server */
+#define EMF_ERROR_LOAD_ENGINE_FAILURE -1056 /* loading engine failed */
+#define EMF_ERROR_CLOSE_FAILURE -1057 /* engine is still used */
+#define EMF_ERROR_GCONF_FAILURE -1058 /* The error occurred on accessing Gconf */
+#define EMF_ERROR_NO_SUCH_HOST -1059 /* no such host was found */
+#define EMF_ERROR_EVENT_QUEUE_FULL -1060 /* event queue is full */
+#define EMF_ERROR_EVENT_QUEUE_EMPTY -1061 /* event queue is empty */
+#define EMF_ERROR_NO_RECIPIENT -1062 /* no recipients information was found */
+#define EMF_ERROR_SMTP_SEND_FAILURE -1063 /* SMTP send failed */
+#define EMF_ERROR_MAILBOX_OPEN_FAILURE -1064 /* accessing mailbox failed */
+#define EMF_ERROR_RETRIEVE_HEADER_DATA_FAILURE -1065 /* retrieving header failed */
+#define EMF_ERROR_XML_PARSER_FAILURE -1066 /* XML parsing failed */
+#define EMF_ERROR_SESSION_NOT_FOUND -1067 /* no matched session was found */
+#define EMF_ERROR_INVALID_STREAM -1068
+#define EMF_ERROR_AUTH_REQUIRED -1069 /* SMTP Authentication needed */
+#define EMF_ERROR_POP3_DELE_FAILURE -1100
+#define EMF_ERROR_POP3_UIDL_FAILURE -1101
+#define EMF_ERROR_POP3_LIST_FAILURE -1102
+#define EMF_ERROR_IMAP4_STORE_FAILURE -1200
+#define EMF_ERROR_IMAP4_EXPUNGE_FAILURE -1201
+#define EMF_ERROR_IMAP4_FETCH_UID_FAILURE -1202
+#define EMF_ERROR_IMAP4_FETCH_SIZE_FAILURE -1203
+#define EMF_ERROR_IMAP4_IDLE_FAILURE -1204 /* IDLE faile */
+#define EMF_ERROR_NO_SIM_INSERTED -1205
+#define EMF_ERROR_FLIGHT_MODE -1206
+#define EMF_SUCCESS_VALIDATE_ACCOUNT -1207
+#define EMF_ERROR_VALIDATE_ACCOUNT -1208
+#define EMF_ERROR_NO_MMC_INSERTED -1209
+#define EMF_ERROR_ACTIVE_SYNC_NOTI_FAILURE -1300
+#define EMF_ERROR_HANDLE_NOT_FOUND -1301
+#define EMF_ERROR_NULL_VALUE -1302
+#define EMF_ERROR_FAILED_BY_SECURITY_POLICY -1303
+#define EMF_ERROR_CANNOT_NEGOTIATE_TLS -1400 /* "Cannot negotiate TLS" */
+#define EMF_ERROR_STARTLS -1401 /* "STARTLS" */
+#define EMF_ERROR_IPC_CRASH -1500
+#define EMF_ERROR_IPC_CONNECTION_FAILURE -1501
+#define EMF_ERROR_IPC_SOCKET_FAILURE -1502
+#define EMF_ERROR_LOGIN_ALLOWED_EVERY_15_MINS -1600 /* "login allowed only every 15 minutes" */
+#define EMF_ERROR_TOO_MANY_LOGIN_FAILURE -1601 /* "Too many login failure" */
+#define EMF_ERROR_ON_PARSING -1700
+#define EMF_ERROR_NETWORK_NOT_AVAILABLE -1800 /* WIFI not availble*/
+#define EMF_ERROR_CANNOT_STOP_THREAD -2000
+#define EMF_ERROR_UNKNOWN -8000 /* unknown erro */
+
+
+
+/*****************************************************************************/
+/* For Active Sync */
+/*****************************************************************************/
+
+#define VCONFKEY_EMAIL_SERVICE_ACTIVE_SYNC_HANDLE "db/email_handle/active_sync_handle"
+#define EMF_ACTIVE_SYNC_NOTI "User.Email.ActiveSync"
+
+typedef enum
+{
+ ACTIVE_SYNC_NOTI_SEND_MAIL, /* a sending notification to ASE (active sync engine */
+ ACTIVE_SYNC_NOTI_SEND_SAVED, /* a sending notification to ASE (active sync engine), All saved mails should be sent */
+ ACTIVE_SYNC_NOTI_SEND_REPORT, /* a sending notification to ASE (active sync engine), report should be sen */
+ ACTIVE_SYNC_NOTI_SYNC_HEADER, /* a sync header - download mails from server. */
+ /* It is depended on account/s flag1 field whether it excutes downloading header only or downloading header + body */
+ /* downloading option : 0 is subject only, 1 is text body, 2 is normal */
+ ACTIVE_SYNC_NOTI_DOWNLOAD_BODY, /* a downloading body notification to AS */
+ ACTIVE_SYNC_NOTI_DOWNLOAD_ATTACHMENT, /* a downloading attachment notification to AS */
+ ACTIVE_SYNC_NOTI_VALIDATE_ACCOUNT, /* a account validating notification to AS */
+ ACTIVE_SYNC_NOTI_CANCEL_JOB, /* a cancling job notification to AS */
+ ACTIVE_SYNC_NOTI_SEARCH_ON_SERVER, /* a searching on server notification to AS */
+} eactivesync_noti_t;
+
+typedef union
+{
+ struct _send_mail
+ {
+ int handle;
+ int account_id;
+ char *mailbox_name;
+ int mail_id;
+ emf_option_t options;
+ } send_mail;
+
+ struct _send_mail_saved
+ {/* not defined ye */
+ int handle;
+ int account_id;
+ } send_mail_saved;
+
+ struct _send_report
+ {/* not defined ye */
+ int handle;
+ int account_id;
+ } send_report;
+
+ struct _sync_header
+ {
+ int handle;
+ int account_id;
+ char *mailbox_name;
+ } sync_header;
+
+ struct _download_body
+ {
+ int handle;
+ int account_id;
+ int mail_id;
+ int with_attachment; /* 0: without attachments, 1: with attachment */
+ } download_body;
+
+ struct _download_attachment
+ {
+ int handle;
+ int account_id;
+ int mail_id;
+ char *attachment_order;
+ } download_attachment;
+
+ struct _cancel_job
+ {
+ int account_id;
+ int handle; /* job handle to be canceled. this value is issued by email-service (actually in Emf_Mapi_xxx() */
+ } cancel_job;
+
+ struct _validate_account
+ {/* not defined yet */
+ int handle;
+ int account_id;
+ } validate_account;
+
+ struct _find_mail_on_server
+ {
+ int handle;
+ int account_id;
+ char *mailbox_name;
+ int search_type;
+ char *search_value;
+ } find_mail_on_server;
+
+} ASNotiData;
+
+
+/* types for noti string */
+typedef enum
+{
+ EMF_CONVERT_STRUCT_TYPE_MAIL_LIST_ITEM, /** specifies emf_mail_list_t */
+} emf_convert_struct_type_e;
+
+#ifdef __cplusplus
+}
+#endif
+
+/**
+* @} @}
+*/
+
+#endif /* __EMF_LIB_H__ */
diff --git a/include/emflib.h b/include/emflib.h
new file mode 100755
index 0000000..c9c1992
--- /dev/null
+++ b/include/emflib.h
@@ -0,0 +1,837 @@
+/*
+* email-service
+*
+* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+*
+* Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com>
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*
+*/
+
+
+
+/**
+ * This file defines all APIs of Email Framework.
+ * @file emflib.h
+ * @author Kyu-ho Jo(kyuho.jo@samsung.com)
+ * @version 0.1
+ * @brief This file is the header file of email-engine library.
+ */
+#ifndef __EMFLIB_H__
+#define __EMFLIB_H__
+
+/**
+* @defgroup EMAIL_FRAMEWORK EmailFW
+* @{
+*/
+
+/**
+* @ingroup EMAIL_FRAMEWORK
+* @defgroup EMAIL_SERVICE Email Service
+* @{
+*/
+
+#include "emf-types.h"
+#include "em-core-types.h"
+
+#include <time.h>
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif /* __cplusplus */
+
+#if !defined(EXPORT_API)
+#define EXPORT_API __attribute__((visibility("default")))
+#endif
+
+/*****************************************************************************/
+/* Initialization */
+/*****************************************************************************/
+/**
+ * Initialize Email-engine.
+ *
+ * @param[out] err_code Specifies the error code returned.
+ * @remarks N/A
+ * @return This function returns true on success or false on failure.
+ */
+EXPORT_API int emf_init(int* err_code);
+
+/**
+ * Finalize Email-engine.
+ *
+ * @param[out] err_code Specifies the error code returned.
+ * @remarks N/A
+ * @return This function returns true on success or false on failure.
+ */
+EXPORT_API int emf_close(int* err_code);
+
+
+/*****************************************************************************/
+/* Account */
+/*****************************************************************************/
+/**
+ * Create a new email account.
+ *
+ * @param[in] account Specifies the structure pointer of account.
+ * @param[out] err_code Specifies the error code returned.
+ * @remarks N/A
+ * @return This function returns true on success or false on failure.
+ */
+EXPORT_API int emf_account_create(emf_account_t* account, int* err_code);
+
+/**
+ * Delete a email account.
+ *
+ * @param[in] account_id Specifies the account ID.
+ * @param[out] err_code Specifies the error code returned.
+ * @remarks N/A
+ * @return This function returns true on success or false on failure.
+ */
+EXPORT_API int emf_account_delete(int account_id, int* err_code);
+
+/**
+ * Validate a email account.
+ *
+ * @param[in] account_id Specifies the account ID.
+ * @param[out] err_code Specifies the error code returned.
+ * @remarks N/A
+ * @return This function returns true on success or false on failure.
+ */
+EXPORT_API int emf_account_validate(int account_id, unsigned* handle, int* err_code);
+
+/**
+ * Change the information of a email account.
+ *
+ * @param[in] account_id Specifies the orignal account ID.
+ * @param[in] new_account Specifies the information of new account.
+ * @param[out] err_code Specifies the error code returned.
+ * @remarks N/A
+ * @return This function returns true on success or false on failure.
+ */
+EXPORT_API int emf_account_modify(int account_id, emf_account_t* new_account, int* err_code);
+
+/**
+ * Change the information of a email account after validation
+ *
+ * @param[in] old_account_id Specifies the orignal account ID.
+ * @param[in] new_account_info Specifies the information of new account.
+ * @param[in] handle Specifies the handle for stopping validation.
+ * @param[out] err_code Specifies the error code returned.
+ * @remarks N/A
+ * @return This function returns true on success or false on failure.
+ */
+EXPORT_API int emf_account_validate_and_update(int old_account_id, emf_account_t* new_account_info, unsigned* handle,int *err_code);
+
+/**
+ * Get a email account by ID.
+ *
+ * @param[in] account_id Specifies the account ID.
+ * @param[in] pulloption Specifies the pulloption.
+ * @param[out] acount The returned account is saved here.
+ * @param[out] err_code Specifies the error code returned.
+ * @remarks N/A
+ * @return This function returns true on success or false on failure.
+ */
+EXPORT_API int emf_account_get(int account_id, int pulloption, emf_account_t** acount, int* err_code);
+
+/**
+ * Get all emails.
+ *
+ * @param[out] acount_list The returned accounts are saved here.(possibly NULL)
+ * @param[out] count The count of returned accounts is saved here.(possibly 0)
+ * @param[out] err_code Specifies the error code returned.
+ * @remarks N/A
+ * @return This function returns true on success or false on failure.
+ */
+EXPORT_API int emf_account_get_list(emf_account_t** acount_list, int* count, int* err_code);
+
+/**
+ * Free allocated memory.
+ *
+ * @param[in] account_list Specifies the structure pointer of account.
+ * @param[in] count Specifies the count of accounts.
+ * @param[out] err_code Specifies the error code returned.
+ * @remarks N/A
+ * @return This function returns true on success or false on failure.
+ */
+EXPORT_API int emf_account_free(emf_account_t** account_list, int count, int* err_code);
+
+/**
+ * Get a information of filtering.
+ *
+ * @param[in] filter_id Specifies the filter ID.
+ * @param[out] filtering_set The returned information of filter are saved here.
+ * @param[out] err_code Specifies the error code returned.
+ * @remarks N/A
+ * @return This function returns true on success or false on failure.
+ */
+EXPORT_API int emf_filter_get(int filter_id, emf_rule_t** filtering_set, int* err_code);
+
+/**
+ * Get all filterings.
+ *
+ * @param[out] filtering_set The returned filterings are saved here.(possibly NULL)
+ * @param[out] count The count of returned filters is saved here.(possibly 0)
+ * @param[out] err_code Specifies the error code returned.
+ * @remarks N/A
+ * @return This function returns true on success or false on failure.
+ */
+EXPORT_API int emf_filter_get_list(emf_rule_t** filtering_set, int* count, int* err_code);
+
+/**
+ * find a filter already exists.
+ *
+ * @param[in] filtering_set Specifies the pointer of adding filter structure.
+ * @param[out] err_code Specifies the error code returned.
+ * @remarks N/A
+ * @return This function returns true if enable add filter, else returns false.
+ */
+EXPORT_API int emf_filter_find(emf_rule_t* filter_info, int* err_code);
+
+/**
+ * Add a filter information.
+ *
+ * @param[in] filtering_set Specifies the pointer of adding filter structure.
+ * @param[out] err_code Specifies the error code returned.
+ * @remarks N/A
+ * @return This function returns true on success or false on failure.(only EMF_FILTER_BLOCK supported.)
+ */
+EXPORT_API int emf_filter_add(emf_rule_t* filtering_set, int* err_code);
+
+/**
+ * Change a filter information.
+ *
+ * @param[in] filter_id Specifies the original filter ID.
+ * @param[in] new_set Specifies the information of new filter.
+ * @param[out] err_code Specifies the error code returned.
+ * @remarks N/A
+ * @return This function returns true on success or false on failure.
+ */
+EXPORT_API int emf_filter_change(int filter_id, emf_rule_t* new_set, int* err_code);
+
+/**
+ * Delete a filter information.
+ *
+ * @param[in] filter_id Specifies the filter ID.
+ * @param[out] err_code Specifies the error code returned.
+ * @remarks N/A
+ * @return This function returns true on success or false on failure.
+ */
+EXPORT_API int emf_filter_delete(int filter_id, int* err_code);
+
+/**
+ * Free allocated memory.
+ *
+ * @param[in] filtering_set Specifies the pointer of pointer of filter structure for memory free.
+ * @param[in] count Specifies the count of filter.
+ * @param[out] err_code Specifies the error code returned.
+ * @remarks N/A
+ * @return This function returns true on success or false on failure.
+ */
+EXPORT_API int emf_filter_free (emf_rule_t** filtering_set, int count, int* err_code);
+
+
+/*****************************************************************************/
+/* Mail */
+/*****************************************************************************/
+
+/**
+ * Send a mail.
+ *
+ * @param[in] mailbox Specifies the mailbox to consist a sending email.
+ * @param[in] mail_id Specifies the mail ID.
+ * @param[in] sending_option Specifies the sending option.
+ * @param[in] callback Specifies the callback function for retrieving sending information.
+ * @param[in] handle Specifies the handle for stopping sending.
+ * @param[out] err_code Specifies the error code returned.
+ * @remarks N/A
+ * @return This function returns true on success or false on failure.
+ */
+EXPORT_API int emf_mail_send(emf_mailbox_t* mailbox, int mail_id, emf_option_t* sending_option, unsigned* handle, int* err_code);
+
+/**
+ * Send all mails to been saved in Offline-mode.
+ *
+ * @param[in] account_id Specifies the account ID.
+ * @param[in] sending_option Specifies the sending option.
+ * @param[in] callback Specifies the callback function for retrieving sending information.
+ * @param[in] handle Specifies the handle for stopping sending.
+ * @param[out] err_code Specifies the error code returned.
+ * @remarks N/A
+ * @return This function returns true on success or false on failure.
+ */
+EXPORT_API int emf_mail_send_saved(int account_id, emf_option_t* sending_option, unsigned* handle, int* err_code);
+
+/**
+ * Send a read receipt mail.
+ *
+ * @param[in] mail Specifies the mail to been read.
+ * @param[in] callback Specifies the callback function for retrieving sending information.
+ * @param[in] handle Specifies the handle for stopping sending.
+ * @param[out] err_code Specifies the error code returned.
+ * @remarks N/A
+ * @return This function returns true on success or false on failure.
+ */
+EXPORT_API int emf_mail_send_report(emf_mail_t* mail, unsigned* handle, int* err_code);
+
+EXPORT_API int emf_add_mail(emf_mail_data_t *input_mail_data, emf_attachment_data_t *input_attachment_data_list, int input_attachment_count, emf_meeting_request_t *input_meeting_request, int input_sync_server);
+
+/**
+ * Save a mail to specific mail box.
+ *
+ * @param[in] mail Specifies the saving mail.
+ * @param[in] mailbox Specifies the mailbox structure for saving email.
+ * @param[in] meeting_req Specifies the meeting_req structure for saving email.
+ * @param[in] from_composer Specifies the mail is from composer.
+ * @param[out] err_code Specifies the error code returned.
+ * @remarks N/A
+ * @return This function returns true on success or false on failure.
+ */
+
+EXPORT_API int emf_mail_save_to_mailbox(emf_mail_t* mail, emf_mailbox_t* mailbox, emf_meeting_request_t *meeting_req, int from_composer, int* err_code);
+
+EXPORT_API int emf_mail_add_meeting_request(int account_id, char *mailbox_name, emf_meeting_request_t *meeting_req, int* err_code);
+
+/**
+ * Delete a mail or multiple mails.
+ *
+ * @param[in] account_id Specifies the account id.
+ * @param[in] mailbox Specifies the mailbox.
+ * @param[in] mail_id Specifies the arrary of mail id.
+ * @param[in] num Specifies the number of mail id.
+ * @param[in] from_server Specifies whether mails are deleted from server.
+ * @param[in] callback Specifies the callback function for retrieving deleting information.
+ * @param[in] handle Reserved.
+ * @param[out] err_code Specifies the error code returned.
+ * @remarks N/A
+ * @return This function returns true on success or false on failure.
+ */
+
+EXPORT_API int emf_mail_delete(int account_id, emf_mailbox_t* mailbox, int mail_id[], int num, int from_server, unsigned* handle, int* err_code);
+
+/**
+ * Delete all mail from a mailbox.
+ *
+ * @param[in] mailbox Specifies the structure of mailbox.
+ * @param[in] with_server Specifies whether mails are also deleted from server.
+ * @param[in] callback Specifies the callback function for delivering status during deleting.
+ * @param[in] handle Reserved.
+ * @param[out] err_code Specifies the error code returned.
+ * @remarks N/A
+ * @return This function returns true on success or false on failure.
+ */
+EXPORT_API int emf_mail_delete_all(emf_mailbox_t* mailbox, int with_server, unsigned* handle, int* err_code);
+
+/**
+ * Move a email to another mailbox.
+ *
+ *
+ * @param[in] mail_id Specifies the mail ID.
+ * @param[in] dst_mailbox Specifies the mailbox structure for moving email.
+ * @param[in] noti_param_1 Specifies first parameter of result notification.
+ * @param[in] noti_param_2 Specifies second parameter of result notification.
+ * @param[out] err_code Specifies the error code returned.
+ * @remarks N/A
+ * @return This function returns true on success or false on failure.
+ */
+EXPORT_API int emf_mail_move(int mail_ids[], int num, emf_mailbox_t* dst_mailbox, int noti_param_1, int noti_param_2, int* err_code);
+
+/**
+ * Move all email to another mailbox.
+ *
+ *
+ * @param[in] src_mailbox Specifies the source mailbox structure for moving email.
+ * @param[in] dst_mailbox Specifies the destination mailbox structure for moving email.
+ * @param[out] err_code Specifies the error code returned.
+ * @remarks N/A
+ * @return This function returns true on success or false on failure.
+ */
+EXPORT_API int emf_mail_move_all_mails(emf_mailbox_t* src_mailbox, emf_mailbox_t* dst_mailbox, int* err_code);
+
+
+/* Deprecated */
+EXPORT_API int emf_mail_update(int mail_id, emf_mail_t* mail, emf_meeting_request_t *meeting_req, int with_server, int* err_code);
+
+/**
+ * Update a existing email information.
+ *
+ * @param[in] input_mail_data Specifies the structure of mail data.
+ * @param[in] input_attachment_data_list Specifies the structure of mail data.
+ * @param[in] input_attachment_count Specifies the pointer of attachment structure.
+ * @param[in] input_meeting_request Specifies the number of attachment data.
+ * @param[in] input_sync_server Specifies whether sync server.
+ * @remarks N/A
+ * @return This function returns EMF_ERROR_NONE on success or error code on failure.
+ */
+EXPORT_API int emf_update_mail(emf_mail_data_t *input_mail_data, emf_attachment_data_t *input_attachment_data_list, int input_attachment_count, emf_meeting_request_t *input_meeting_request, int input_sync_server);
+
+
+/**
+ * Callback for mail resend
+ *
+ * @param[in] data Specifies the pointer to mail_id.
+ * @remarks N/A
+ * @return This function returns void.
+ */
+EXPORT_API void _OnMailSendRetryTimerCB( void* data );
+
+/**
+ * Get a mail from mailbox.
+ *
+ * @param[in] mailbox Reserved.
+ * @param[in] mail_id Specifies the mail ID.
+ * @param[out] mail The returned mail is save here.
+ * @param[out] err_code Specifies the error code returned.
+ * @remarks N/A
+ * @return This function returns true on success or false on failure.
+ */
+EXPORT_API int emf_mail_get_mail(emf_mailbox_t* mailbox, int mail_id, emf_mail_t** mail, int* err_code);
+
+/**
+ * Get a mail info.
+ *
+ * @param[in] mailbox Reserved.
+ * @param[in] mail_id Specifies the mail ID.
+ * @param[out] info The returned body of mail is saved here.
+ * @param[out] err_code Specifies the error code returned.
+ * @remarks N/A
+ * @return This function returns true on success or false on failure.
+ */
+EXPORT_API int emf_mail_get_info(emf_mailbox_t* mailbox, int mail_id, emf_mail_info_t** info, int* err_code);
+
+/**
+ * Get a mail head.
+ *
+ * @param[in] mailbox Reserved.
+ * @param[in] mail_id Specifies the mail ID.
+ * @param[out] head The returned info of mail is saved here.
+ * @param[out] err_code Specifies the error code returned.
+ * @remarks N/A
+ * @return This function returns true on success or false on failure.
+ */
+EXPORT_API int emf_mail_get_head(emf_mailbox_t* mailbox, int mail_id, emf_mail_head_t** head, int* err_code);
+
+/**
+ * Get a mail body.
+ *
+ * @param[in] mailbox Reserved.
+ * @param[in] mail_id Specifies the mail ID.
+ * @param[out] body The returned body of mail is saved here.
+ * @param[out] err_code Specifies the error code returned.
+ * @remarks N/A
+ * @return This function returns true on success or false on failure.
+ */
+EXPORT_API int emf_mail_get_body(emf_mailbox_t* mailbox, int mail_id, emf_mail_body_t** body, int* err_code);
+
+/**
+ * Download email body from server.
+ *
+ * @param[in] mailbox Reserved.
+ * @param[in] mail_id Specifies the mail ID.
+ * @param[in] callback Specifies the callback function for retrieving download status.
+ * @param[in] handle Specifies the handle for stopping downloading.
+ * @param[out] err_code Specifies the error code returned.
+ * @remarks N/A
+ * @return This function returns true on success or false on failure.
+ */
+EXPORT_API int emf_mail_download_body(emf_mailbox_t* mailbox, int mail_id, int verbose, int with_attachment, unsigned* handle, int* err_code);
+
+/**
+ * Get a mail attachment.
+ *
+ * @param[in] mailbox Reserved.
+ * @param[in] mail_id Specifies the mail ID.
+ * @param[in] attachment_id Specifies the buffer that a attachment ID been saved.
+ * @param[out] attachment The returned attachment is save here.
+ * @param[out] err_code Specifies the error code returned.
+ * @remarks N/A
+ * @return This function returns true on success or false on failure.
+ */
+EXPORT_API int emf_mail_get_attachment(emf_mailbox_t* mailbox, int mail_id, char* attachment_id, emf_attachment_info_t** attachment, int* err_code);
+
+/**
+ * Download a email nth-attachment from server.
+ *
+ * @param[in] mailbox Reserved.
+ * @param[in] mail_id Specifies the mail ID.
+ * @param[in] nth Specifies the buffer that a attachment number been saved. the minimum number is "1".
+ * @param[in] callback Specifies the callback function for retrieving download status.
+ * @param[in] handle Specifies the handle for stopping downloading.
+ * @param[out] err_code Specifies the error code returned.
+ * @remarks N/A
+ * @return This function returns true on success or false on failure.
+ */
+EXPORT_API int emf_mail_download_attachment(emf_mailbox_t* mailbox, int mail_id, char* nth, unsigned* handle, int* err_code);
+
+
+/**
+ * Append a attachment to email.
+ *
+ * @param[in] mailbox Reserved.
+ * @param[in] mail_id Specifies the mail ID.
+ * @param[in] attachment Specifies the structure of attachment.
+ * @param[out] err_code Specifies the error code returned.
+ * @remarks N/A
+ * @return This function returns true on success or false on failure.
+ */
+EXPORT_API int emf_mail_add_attachment(emf_mailbox_t* mailbox, int mail_id, emf_attachment_info_t* attachment, int* err_code);
+
+/**
+ * Delete a attachment from email.
+ *
+ * @param[in] mailbox Reserved.
+ * @param[in] mail_id Specifies the mail ID.
+ * @param[in] attachment_id Specifies the buffer that a attachment ID been saved.
+ * @param[out] err_code Specifies the error code returned.
+ * @remarks N/A
+ * @return This function returns true on success or false on failure.
+ */
+EXPORT_API int emf_mail_delete_attachment(emf_mailbox_t* mailbox, int mail_id, char* attachment_id, int* err_code);
+
+/**
+ * Free allocated memroy for emails.
+ *
+ * @param[in] mail_list Specifies the pointer of mail structure pointer.
+ * @param[in] count Specifies the count of mails.
+ * @param[out] err_code Specifies the error code returned.
+ * @remarks N/A
+ * @return This function returns true on success or false on failure.
+ */
+EXPORT_API int emf_mail_free(emf_mail_t** mail_list, int count, int* err_code);
+
+/**
+ * Free allocated memroy for email infoes.
+ *
+ * @param[in] head_list Specifies the pointer of mail info structures.
+ * @param[in] count Specifies the number of mail infoes.
+ * @param[out] err_code Specifies the error code returned.
+ * @remarks N/A
+ * @return This function returns true on success or false on failure.
+ */
+EXPORT_API int emf_mail_info_free(emf_mail_info_t** info_list, int count, int* err_code);
+
+/**
+ * Free allocated memroy for email headers.
+ *
+ * @param[in] head_list Specifies the pointer of mail head structure list.
+ * @param[in] count Specifies the number of mail heads.
+ * @param[out] err_code Specifies the error code returned.
+ * @remarks N/A
+ * @return This function returns true on success or false on failure.
+ */
+EXPORT_API int emf_mail_head_free(emf_mail_head_t** head_list, int count, int* err_code);
+
+/**
+ * Free allocated memroy for email bodies.
+ *
+ * @param[in] body_list Specifies the pointer of mail body structures.
+ * @param[in] count Specifies the number of mail bodies.
+ * @param[out] err_code Specifies the error code returned.
+ * @remarks N/A
+ * @return This function returns true on success or false on failure.
+ */
+EXPORT_API int emf_mail_body_free(emf_mail_body_t** body_list, int count, int* err_code);
+
+/**
+ * Free allocated memroy for email attachment.
+ *
+ * @param[in] atch_info Specifies the pointer of mail attachment structure pointer.
+ * @param[out] err_code Specifies the error code returned.
+ * @remarks N/A
+ * @return This function returns true on success or false on failure.
+ */
+EXPORT_API int emf_mail_attachment_info_free(emf_attachment_info_t** atch_info, int* err_code);
+
+/**
+ * Change email flag.
+ *
+ * @param[in] mailbox Reserved.
+ * @param[in] mail_id Specifies the mail ID.
+ * @param[in] new_flag Specifies the new email flag.
+ * @param[out] err_code Specifies the error code returned.
+ * @remarks N/A
+ * @return This function returns true on success or false on failure.
+ */
+EXPORT_API int emf_mail_modify_flag(int mail_id, emf_mail_flag_t new_flag, int onserver, int sticky_flag, int* err_code);
+
+/**
+ * Change email extra flag.
+ *
+ * @param[in] mailbox Reserved.
+ * @param[in] mail_id Specifies the mail ID.
+ * @param[in] new_flag Specifies the new email extra flag.
+ * @param[out] err_code Specifies the error code returned.
+ * @remarks N/A
+ * @return This function returns true on success or false on failure.
+ */
+EXPORT_API int emf_mail_modify_extra_flag(int mail_id, emf_extra_flag_t new_flag, int* err_code);
+
+/**
+ * Change email read/unread flag.
+ * @param[in] account_id Specifies the account id.
+ * @param[in] mail_ids Specifies the array of mail ID.
+ * @param[in] num Specifies the numbers of mail ID.
+ * @param[in] field_type Specifies the field type what you want to set. Refer emf_flags_field_type.
+ * @param[in] value Specifies the value what you want to set.
+ * @param[in] onserver Specifies the mail on server.
+ * @param[out] err_code Specifies the error code returned.
+ * @remarks N/A
+ * @return This function returns true on success or false on failure.
+ */
+EXPORT_API int emf_mail_set_flags_field(int account_id, int mail_ids[], int num, emf_flags_field_type field_type, int value, int onserver, int* err_code);
+
+/*****************************************************************************/
+/* Mailbox */
+/*****************************************************************************/
+EXPORT_API int emf_mailbox_get_imap_mailbox_list(int account_id, char* mailbox, unsigned* handle, int* err_code);
+
+/**
+ * Download header of new emails from mail server.
+ *
+ * @param[in] mailbox Specifies the structure of mailbox.
+ * @param[in] callback Specifies the callback function for retrieving download status.
+ * @param[out] handle Specifies the handle for stopping downloading.
+ * @param[out] err_code Specifies the error code returned.
+ * @remarks N/A
+ * @return This function returns true on success or false on failure.
+ */
+EXPORT_API int emf_mailbox_sync_header(emf_mailbox_t* mailbox, unsigned* handle, int* err_code);
+
+
+EXPORT_API int emf_mailbox_oma_sync_header(int account_id, char*email_address, unsigned* handle, int* err_code);
+
+
+EXPORT_API int emf_mailbox_get_by_now_account_addr(int account_id, char* now_address, emf_mailbox_t** mailbox_list, int* count, int* err_code);
+
+/**
+ * Get mail count from mailbox.
+ *
+ * @param[in] mailbox Specifies the pointer of mailbox structure.
+ * @param[out] total Total email count is saved here.
+ * @param[out] unseen Unread email count is saved here.
+ * @param[out] err_code Specifies the error code returned.
+ * @remarks N/A
+ * @return This function returns true on success or false on failure.
+ */
+EXPORT_API int emf_mailbox_get_mail_count(emf_mailbox_t* mailbox, int* total, int* unseen, int* err_code);
+
+/**
+ * Get all mailboxes from account.
+ *
+ * @param[in] account_id Specifies the account ID.
+ * @param[out] mailbox_list Specifies the pointer of mailbox structure pointer.(possibly NULL)
+ * @param[out] count The mailbox count is saved here.(possibly 0)
+ * @param[out] err_code Specifies the error code returned.
+ * @remarks N/A
+ * @return This function returns true on success or false on failure.
+ */
+EXPORT_API int emf_mailbox_get_list(int account_id, emf_mailbox_t** mailbox_list, int* count, int* err_code);
+
+/**
+ * Create a new mailbox.
+ *
+ * @param[in] new_mailbox Specifies the pointer of creating mailbox information.
+ * @param[out] handle Specifies the handle for stopping creating mailbox.
+ * @param[out] err_code Specifies the error code returned.
+ * @remarks N/A
+ * @return This function returns true on success or false on failure.
+ */
+EXPORT_API int emf_mailbox_create(emf_mailbox_t* new_mailbox, int on_server, unsigned* handle, int* err_code);
+
+/**
+ * Delete a mailbox.
+ *
+ * @param[in] mailbox Specifies the pointer of deleting mailbox information.
+ * @param[out] handle Specifies the handle for stopping creating mailbox.
+ * @param[out] err_code Specifies the error code returned.
+ * @remarks N/A
+ * @return This function returns true on success or false on failure.
+ */
+EXPORT_API int emf_mailbox_delete(emf_mailbox_t* mailbox, int on_server, unsigned* handle, int* err_code);
+
+/**
+ * Delete all sub-mailboxes from a specific mailbox.
+ *
+ * @param[in] mailbox Specifies the pointer of mailbox information.
+ * @param[out] err_code Specifies the error code returned.
+ * @remarks N/A
+ * @return This function returns true on success or false on failure.
+ */
+EXPORT_API int emf_mailbox_delete_all(emf_mailbox_t* mailbox, int* err_code);
+
+/**
+ * Free allocated memory for mailbox information.
+ *
+ * @param[in] mailbox_list Specifies the pointer for searching mailbox structure pointer.
+ * @param[in] count Specifies the count of mailboxes.
+ * @param[out] err_code Specifies the error code returned.
+ * @remarks N/A
+ * @return This function returns true on success or false on failure.
+ */
+EXPORT_API int emf_mailbox_free(emf_mailbox_t** mailbox_list, int count, int* err_code);
+
+/*****************************************************************************/
+/* Etc */
+/*****************************************************************************/
+
+
+/**
+ * Register a callback for event processing.
+ *
+ * @param[in] action Kind of event callback.
+ * @param[in] callback Function which will be called during processing event.
+ * @param[in] event_data Event data which will be passed to the callback.
+ * @remarks N/A
+ * @return This function returns true on success or false on failure.
+ */
+EXPORT_API int emf_register_event_callback(emf_action_t action, emf_event_callback callback, void* event_data);
+
+/**
+ * Unregister a callback for event processing.
+ *
+ * @param[in] action Kind of event callback.
+ * @param[in] callback Function which will be called during processing event.
+ * @remarks N/A
+ * @return This function returns true on success or false on failure.
+ */
+EXPORT_API int emf_unregister_event_callback(emf_action_t action, emf_event_callback callback);
+
+/**
+ * Get current event queue status.
+ *
+ * @param[out] on_sending True if sending is in progress.
+ * @param[out] on_receiving True if receiving is in progress.
+ * @remarks N/A
+ */
+EXPORT_API void emf_get_event_queue_status(int* on_sending, int* on_receiving);
+
+/**
+ * Get the handle of a pending job.
+ *
+ * @param[in] action Specifies kind of the job.
+ * @param[in] account_id Specifies the account ID.
+ * @param[in] mail_id Specifies the mail ID.
+ * @remarks N/A
+ * @return This function return its handle if a pending job exists, otherwise -1.
+ */
+EXPORT_API int emf_get_pending_job(emf_action_t action, int account_id, int mail_id, emf_event_status_type_t* status);
+
+/**
+ * Cancel a progressive work.
+ *
+ * @param[in] account_id Specifies the account ID.
+ * @param[in] handle Specifies the ID of cancelling work.
+ * @param[out] err_code Specifies the error code returned.
+ * @remarks N/A
+ * @return This function returns true on success or false on failure.
+ */
+EXPORT_API int emf_cancel_job(int account_id, int handle, int* err_code);
+
+
+
+/**
+ * Cancel a progressive send mail job.
+ *
+ * @param[in] account_id Specifies the account ID.
+ * @param[in] mail_id Specifies the Mail ID of cancelling send mail.
+ * @param[out] err_code Specifies the error code returned.
+ * @remarks N/A
+ * @return This function returns true on success or false on failure.
+ */
+EXPORT_API int emf_mail_send_mail_cancel_job(int account_id, int mail_id, int* err_code);
+
+
+
+#ifdef PARSING_EMN_WBXML
+/**
+ * Retrieve a account from OMA EMN data.
+ *
+ * @param[in] wbxml_b64 Specifies the EMN data. The data is a BASE64 encoded string.
+ * @param[out] account_id The account ID is saved here.
+ * @param[out] mailbox The name of mailbox is saved here.
+ * @param[out] err_code Specifies the error code returned.
+ * @remarks N/A
+ * @return This function returns true on success or false on failure.
+ */
+EXPORT_API int emf_get_emn_account (unsigned char* wbxml_b64, int* account_id, char** mailbox, int* err_code);
+#endif
+
+/**
+ * set email options.
+ *
+ * @param[in] option Specifies the email options.
+ * @param[out] err_code Specifies the error code returned.
+ * @remarks N/A
+ * @return This function returns true on success or false on failure.
+ */
+EXPORT_API int emf_set_option(emf_option_t* option, int* err_code);
+
+/**
+ * get email options.
+ *
+ * @param[out] option Specifies the email options.
+ * @param[out] err_code Specifies the error code returned.
+ * @remarks N/A
+ * @return This function returns true on success or false on failure.
+ */
+EXPORT_API int emf_get_option(emf_option_t* option, int* err_code);
+
+/**
+ * Sync the Local activity
+ *
+ *
+ * @param[in] account_id Specifies the Account ID.
+ * @param[out] err_code Specifies the error code returned.
+ * @remarks N/A
+ * @return This function returns true on success or false on failure.
+ */
+EXPORT_API int emf_local_activity_sync(int account_id, int *err_code);
+
+
+#ifdef __FEATURE_AUTO_POLLING__
+EXPORT_API int emf_auto_polling(int* err_code);
+#endif
+
+EXPORT_API int emf_account_insert_accountinfo_to_contact(emf_account_t* account);
+
+EXPORT_API int emf_account_update_accountinfo_to_contact(emf_account_t* old_account, emf_account_t* new_account);
+
+EXPORT_API int emf_mail_get_mail_by_uid(int account_id, char *uid, emf_mail_t **mail, int *err);
+
+EXPORT_API int emf_mailbox_update(emf_mailbox_t* old_mailbox, emf_mailbox_t* new_mailbox, int on_server, unsigned* handle, int* err_code);
+
+EXPORT_API int emf_clear_mail_data(int* err_code);
+
+EXPORT_API int emf_mail_send_retry( int mail_id, int timeout_in_sec, int* err_code);
+
+EXPORT_API int emf_account_validate_and_create(emf_account_t* new_account, unsigned* handle, int* err_code);
+
+EXPORT_API int emf_mailbox_set_mail_slot_size(int account_id, char* mailbox_name, int new_slot_size, unsigned* handle, int *err_code);
+
+EXPORT_API int emf_mail_move_thread_to_mailbox(int thread_id, char *target_mailbox_name, int move_always_flag, int *err_code);
+
+EXPORT_API int emf_mail_delete_thread(int thread_id, int delete_always_flag, unsigned* handle, int *err_code);
+
+EXPORT_API int emf_mail_modify_seen_flag_of_thread(int thread_id, int seen_flag, int on_server, unsigned* handle, int *err_code);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+/**
+* @} @}
+*/
+
+#endif /* __EMFLIB_H__ */
diff --git a/ipc/CMakeLists.txt b/ipc/CMakeLists.txt
new file mode 100755
index 0000000..e11a628
--- /dev/null
+++ b/ipc/CMakeLists.txt
@@ -0,0 +1,78 @@
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+PROJECT(email-ipc)
+
+SET(CMAKE_SKIP_BUILD_RPATH TRUE)
+
+IF("${CMAKE_BUILD_TYPE}" STREQUAL "")
+ SET(CMAKE_BUILD_TYPE "Debug")
+ENDIF("${CMAKE_BUILD_TYPE}" STREQUAL "")
+
+MESSAGE("")
+MESSAGE(">>> current directory: ${CMAKE_CURRENT_SOURCE_DIR}")
+MESSAGE(">>> Build type: ${CMAKE_BUILD_TYPE}")
+
+SET(VISIBILITY "-DEXPORT_API=\"__attribute__((visibility(\\\"default\\\")))\"")
+SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${VISIBILITY} -fvisibility=hidden")
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${VISIBILITY} -fvisibility=hidden")
+
+SET(IPC-LIB "email-ipc")
+SET(IPC-SRCS
+ ${CMAKE_SOURCE_DIR}/ipc/ipc-library-api.cpp
+ ${CMAKE_SOURCE_DIR}/ipc/ipc-library-build.cpp
+ ${CMAKE_SOURCE_DIR}/ipc/ipc-library-proxy.cpp
+ ${CMAKE_SOURCE_DIR}/ipc/ipc-library-stub.cpp
+ ${CMAKE_SOURCE_DIR}/ipc/api/ipc-api-info.cpp
+ ${CMAKE_SOURCE_DIR}/ipc/api/ipc-param.cpp
+ ${CMAKE_SOURCE_DIR}/ipc/api/ipc-param-list.cpp
+ ${CMAKE_SOURCE_DIR}/ipc/common/cm-list.cpp
+ ${CMAKE_SOURCE_DIR}/ipc/common/cm-sys-msg-queue.cpp
+ ${CMAKE_SOURCE_DIR}/ipc/proxy/ipc-callback-info.cpp
+ ${CMAKE_SOURCE_DIR}/ipc/proxy/ipc-proxy-main.cpp
+ ${CMAKE_SOURCE_DIR}/ipc/proxy/ipc-proxy-socket.cpp
+ ${CMAKE_SOURCE_DIR}/ipc/socket/ipc-socket.cpp
+ ${CMAKE_SOURCE_DIR}/ipc/stub/ipc-queue.cpp
+ ${CMAKE_SOURCE_DIR}/ipc/stub/ipc-response-info.cpp
+ ${CMAKE_SOURCE_DIR}/ipc/stub/ipc-stub-main.cpp
+ ${CMAKE_SOURCE_DIR}/ipc/stub/ipc-stub-socket.cpp
+ ${CMAKE_SOURCE_DIR}/ipc/stub/ipc-task.cpp
+ ${CMAKE_SOURCE_DIR}/ipc/stub/ipc-task-manager.cpp
+)
+
+INCLUDE_DIRECTORIES(
+ ${CMAKE_SOURCE_DIR}/include
+ ${CMAKE_SOURCE_DIR}/ipc/include
+ ${CMAKE_SOURCE_DIR}/ipc/proxy/include
+ ${CMAKE_SOURCE_DIR}/ipc/stub/include
+ ${CMAKE_SOURCE_DIR}/ipc/common/include
+ ${CMAKE_SOURCE_DIR}/ipc/socket/include
+ ${CMAKE_SOURCE_DIR}/ipc/api/include
+ ${CMAKE_SOURCE_DIR}/Common/include
+ ${CMAKE_SOURCE_DIR}/MAPI/include
+)
+
+INCLUDE(FindPkgConfig)
+pkg_check_modules(ipc_pkgs REQUIRED dlog glib-2.0)
+
+FOREACH(flag ${ipc_pkgs_CFLAGS})
+ SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS}")
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
+#message("***cmake_c_flags ${CMAKE_C_FLAGS}")
+#message("***extra_cflags ${EXTRA_CFLAGS}")
+#message("***base_pkgs_cflags ${base_pkgs_CFLAGS}")
+#message("***result ${CMAKE_CXX_FLAGS}")
+
+
+ADD_DEFINITIONS("-DBRSDK_VER=\"2\"")
+
+SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed")
+
+ADD_LIBRARY(${IPC-LIB} SHARED ${IPC-SRCS})
+TARGET_LINK_LIBRARIES(${IPC-LIB} ${ipc_pkgs_LDFLAGS} email-base pthread)
+SET_TARGET_PROPERTIES(${IPC-LIB} PROPERTIES SOVERSION ${VERSION_MAJOR})
+SET_TARGET_PROPERTIES(${IPC-LIB} PROPERTIES VERSION ${VERSION})
+
+INSTALL(TARGETS ${IPC-LIB} DESTINATION lib COMPONENT RuntimeLibraries)
+
diff --git a/ipc/api/include/ipc-api-info.h b/ipc/api/include/ipc-api-info.h
new file mode 100755
index 0000000..50d5146
--- /dev/null
+++ b/ipc/api/include/ipc-api-info.h
@@ -0,0 +1,259 @@
+/*
+* email-service
+*
+* Copyright (c) 2000 - 2011 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.
+*
+*/
+
+
+#ifndef _IPC_APIINFO_H_
+#define _IPC_APIINFO_H_
+
+#include <stdio.h>
+#include "ipc-library.h"
+#include "emf-dbglog.h"
+#include "Emf_Mapi.h"
+
+class ipcEmailParamList;
+
+class ipcEmailAPIInfo {
+public:
+ ipcEmailAPIInfo();
+ virtual ~ipcEmailAPIInfo();
+
+private:
+
+ long m_nAPIID;
+ long m_nResponseID; /* sync */
+ long m_nAPPID; /* Async 0 : Sync, > 0 : Async */
+ ipcEmailParamList *m_pParams[2];
+
+public:
+ bool SetAPIID(long a_nAPIID);
+ long GetAPIID();
+ bool SetAPPID(long a_nResponseID);
+ long GetAPPID();
+ bool SetResponseID(long a_nResponseID);
+ long GetResponseID();
+
+ bool ParseStream(EPARAMETER_DIRECTION a_eDirection, void* a_pStream);
+ void* GetStream(EPARAMETER_DIRECTION a_eDirection);
+
+ int GetStreamLength(EPARAMETER_DIRECTION a_eDirection);
+ void* GetParameters(EPARAMETER_DIRECTION a_eDirection);
+
+private:
+ long ParseAPIID(void* a_pStream);
+ long ParseResponseID(void* a_pStream);
+ long ParseAPPID(void* a_pStream);
+
+};
+
+
+/* don't insert empty line */
+#define EM_APIID_TO_STR(nAPIID) \
+ ({\
+ int id=nAPIID;\
+ const char* s=NULL;\
+ switch(id) {\
+ case _EMAIL_API_ADD_ACCOUNT:\
+ s = "_EMAIL_API_ADD_ACCOUNT";\
+ break;\
+ case _EMAIL_API_ADD_MAIL_OLD:\
+ s = "_EMAIL_API_ADD_MAIL_OLD";\
+ break;\
+ case _EMAIL_API_GET_MAIL:\
+ s = "_EMAIL_API_GET_MAIL";\
+ break;\
+ case _EMAIL_API_ADD_MAILBOX:\
+ s = "_EMAIL_API_ADD_MAILBOX";\
+ break;\
+ case _EMAIL_API_DELETE_MAILBOX:\
+ s = "_EMAIL_API_DELETE_MAILBOX";\
+ break;\
+ case _EMAIL_API_UPDATE_MAILBOX:\
+ s = "_EMAIL_API_UPDATE_MAILBOX";\
+ break;\
+ case _EMAIL_API_SET_MAIL_SLOT_SIZE:\
+ s = "_EMAIL_API_SET_MAIL_SLOT_SIZE";\
+ break;\
+ case _EMAIL_API_SEND_MAIL:\
+ s = "_EMAIL_API_SEND_MAIL";\
+ break;\
+ case _EMAIL_API_GET_MAILBOX_COUNT:\
+ s = "_EMAIL_API_GET_MAILBOX_COUNT";\
+ break;\
+ case _EMAIL_API_GET_MAILBOX_LIST:\
+ s = "_EMAIL_API_GET_MAILBOX_LIST";\
+ break;\
+ case _EMAIL_API_GET_SUBMAILBOX_LIST:\
+ s = "_EMAIL_API_GET_SUBMAILBOX_LIST";\
+ break;\
+ case _EMAIL_API_SYNC_HEADER:\
+ s = "_EMAIL_API_SYNC_HEADER";\
+ break;\
+ case _EMAIL_API_DOWNLOAD_BODY:\
+ s = "_EMAIL_API_DOWNLOAD_BODY";\
+ break;\
+ case _EMAIL_API_CLEAR_DATA:\
+ s = "_EMAIL_API_CLEAR_DATA";\
+ break;\
+ case _EMAIL_API_UPDATE_MAIL_OLD:\
+ s = "_EMAIL_API_UPDATE_MAIL_OLD";\
+ break;\
+ case _EMAIL_API_DELETE_ALL_MAIL:\
+ s = "_EMAIL_API_DELETE_ALL_MAIL";\
+ break;\
+ case _EMAIL_API_DELETE_MAIL:\
+ s = "_EMAIL_API_DELETE_MAIL";\
+ break;\
+ case _EMAIL_API_MODIFY_MAIL_FLAG:\
+ s = "_EMAIL_API_MODIFY_MAIL_FLAG";\
+ break;\
+ case _EMAIL_API_MODIFY_MAIL_EXTRA_FLAG:\
+ s = "_EMAIL_API_MODIFY_MAIL_EXTRA_FLAG";\
+ break;\
+ case _EMAIL_API_ADD_RULE:\
+ s = "_EMAIL_API_ADD_RULE";\
+ break;\
+ case _EMAIL_API_GET_RULE:\
+ s = "_EMAIL_API_GET_RULE";\
+ break;\
+ case _EMAIL_API_GET_RULE_LIST:\
+ s = "_EMAIL_API_GET_RULE";\
+ break;\
+ case _EMAIL_API_FIND_RULE:\
+ s = "_EMAIL_API_FIND_RULE";\
+ break;\
+ case _EMAIL_API_UPDATE_RULE:\
+ s = "_EMAIL_API_UPDATE_RULE";\
+ break;\
+ case _EMAIL_API_DELETE_RULE:\
+ s = "_EMAIL_API_DELETE_RULE";\
+ break;\
+ case _EMAIL_API_MOVE_MAIL:\
+ s = "_EMAIL_API_MOVE_MAIL";\
+ break;\
+ case _EMAIL_API_MOVE_ALL_MAIL:\
+ s = "_EMAIL_API_MOVE_ALL_MAIL";\
+ break;\
+ case _EMAIL_API_SET_FLAGS_FIELD:\
+ s = "_EMAIL_API_SET_FLAGS_FIELD";\
+ break;\
+ case _EMAIL_API_ADD_MAIL:\
+ s = "_EMAIL_API_ADD_MAIL";\
+ break;\
+ case _EMAIL_API_UPDATE_MAIL:\
+ s = "_EMAIL_API_UPDATE_MAIL";\
+ break;\
+ case _EMAIL_API_MOVE_THREAD_TO_MAILBOX:\
+ s = "_EMAIL_API_MOVE_THREAD_TO_MAILBOX";\
+ break;\
+ case _EMAIL_API_DELETE_THREAD:\
+ s = "_EMAIL_API_DELETE_THREAD";\
+ break;\
+ case _EMAIL_API_MODIFY_SEEN_FLAG_OF_THREAD:\
+ s = "_EMAIL_API_MODIFY_SEEN_FLAG_OF_THREAD";\
+ break;\
+ case _EMAIL_API_UPDATE_ACCOUNT:\
+ s = "_EMAIL_API_UPDATE_ACCOUNT";\
+ break;\
+ case _EMAIL_API_ADD_ATTACHMENT:\
+ s = "_EMAIL_API_ADD_ATTACHMENT";\
+ break;\
+ case _EMAIL_API_GET_IMAP_MAILBOX_LIST:\
+ s = "_EMAIL_API_GET_IMAP_MAILBOX_LIST";\
+ break;\
+ case _EMAIL_API_GET_ATTACHMENT:\
+ s = "_EMAIL_API_GET_ATTACHMENT";\
+ break;\
+ case _EMAIL_API_DELETE_ATTACHMENT:\
+ s = "_EMAIL_API_DELETE_ATTACHMENT";\
+ break;\
+ case _EMAIL_API_DOWNLOAD_ATTACHMENT:\
+ s = "_EMAIL_API_DOWNLOAD_ATTACHMENT";\
+ break;\
+ case _EMAIL_API_GET_INFO:\
+ s = "_EMAIL_API_GET_INFO";\
+ break;\
+ case _EMAIL_API_GET_HEADER_INFO:\
+ s = "_EMAIL_API_GET_INFO";\
+ break;\
+ case _EMAIL_API_GET_BODY_INFO:\
+ s = "_EMAIL_API_GET_BODY_INFO";\
+ break;\
+ case _EMAIL_API_GET_ACCOUNT_LIST:\
+ s = "_EMAIL_API_GET_ACCOUNT_LIST";\
+ break;\
+ case _EMAIL_API_MAIL_SEND_SAVED:\
+ s = "_EMAIL_API_MAIL_SEND_SAVED";\
+ break;\
+ case _EMAIL_API_MAIL_SEND_REPORT:\
+ s = "_EMAIL_API_MAIL_SEND_REPORT";\
+ break;\
+ case _EMAIL_API_CANCEL_JOB:\
+ s = "_EMAIL_API_CANCEL_JOB";\
+ break;\
+ case _EMAIL_API_GET_PENDING_JOB:\
+ s = "_EMAIL_API_GET_PENDING_JOB";\
+ break;\
+ case _EMAIL_API_NETWORK_GET_STATUS:\
+ s = "_EMAIL_API_NETWORK_GET_STATUS";\
+ break;\
+ case _EMAIL_API_SEND_RETRY:\
+ s = "_EMAIL_API_SEND_RETRY";\
+ break;\
+ case _EMAIL_API_VALIDATE_ACCOUNT :\
+ s = "_EMAIL_API_VALIDATE_ACCOUNT";\
+ break;\
+ case _EMAIL_API_SEND_MAIL_CANCEL_JOB :\
+ s = "_EMAIL_API_SEND_MAIL_CANCEL_JOB";\
+ break;\
+ case _EMAIL_API_FIND_MAIL_ON_SERVER :\
+ s = "_EMAIL_API_FIND_MAIL_ON_SERVER";\
+ break;\
+ case _EMAIL_API_ADD_ACCOUNT_WITH_VALIDATION :\
+ s = "_EMAIL_API_ADD_ACCOUNT_WITH_VALIDATION";\
+ break;\
+ case _EMAIL_API_BACKUP_ACCOUNTS :\
+ s = "_EMAIL_API_BACKUP_ACCOUNTS";\
+ break;\
+ case _EMAIL_API_RESTORE_ACCOUNTS :\
+ s = "_EMAIL_API_RESTORE_ACCOUNTS";\
+ break;\
+ case _EMAIL_API_PRINT_RECEIVING_EVENT_QUEUE :\
+ s = "_EMAIL_API_PRINT_RECEIVING_EVENT_QUEUE";\
+ break;\
+ case _EMAIL_API_PING_SERVICE :\
+ s = "_EMAIL_API_PING_SERVICE";\
+ break;\
+ case _EMAIL_API_UPDATE_NOTIFICATION_BAR_FOR_UNREAD_MAIL :\
+ s = "_EMAIL_API_UPDATE_NOTIFICATION_BAR_FOR_UNREAD_MAIL";\
+ break;\
+ case _EMAIL_API_GET_PASSWORD_LENGTH_OF_ACCOUNT:\
+ s = "_EMAIL_API_GET_PASSWORD_LENGTH_OF_ACCOUNT";\
+ break;\
+ default : \
+ s = "UNKNOWN_APIID";\
+ }\
+ s;\
+ })
+
+
+#endif /* _IPC_APIINFO_H_ */
+
+
diff --git a/ipc/api/include/ipc-param-list.h b/ipc/api/include/ipc-param-list.h
new file mode 100755
index 0000000..0da39c1
--- /dev/null
+++ b/ipc/api/include/ipc-param-list.h
@@ -0,0 +1,67 @@
+/*
+* email-service
+*
+* Copyright (c) 2000 - 2011 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.
+*
+*/
+
+
+#ifndef _IPC_PARAMLIST_H_
+#define _IPC_PARAMLIST_H_
+
+
+#include "ipc-param.h"
+#include "emf-dbglog.h"
+
+typedef enum {
+ eSTREAM_APIID,
+ eSTREAM_RESID,
+ eSTREAM_APPID,
+ eSTREAM_COUNT,
+ eSTREAM_DATA,
+ eSTREAM_MAX
+
+}IPC_STREAM_INFO;
+
+class ipcEmailParamList {
+public:
+ ipcEmailParamList();
+ virtual ~ipcEmailParamList();
+
+ bool ParseStream(void* a_pStreamData);
+ void* GetStream();
+ int GetStreamLength();
+
+ bool AddParam(void* a_pData, int a_nLen);
+
+ void* GetParam(int a_nIndex);
+ int GetParamLen(int a_nIndex);
+ int GetParamCount();
+
+private:
+ long ParseParameterCount(void *a_pStream);
+
+private:
+ int m_nParamCount;
+ ipcEmailParam m_lstParams[10];
+ unsigned char *m_pbyteStream;
+
+};
+
+#endif /* _IPC_PARAMLIST_H_ */
+
+
diff --git a/ipc/api/include/ipc-param.h b/ipc/api/include/ipc-param.h
new file mode 100755
index 0000000..f363219
--- /dev/null
+++ b/ipc/api/include/ipc-param.h
@@ -0,0 +1,43 @@
+/*
+* email-service
+*
+* Copyright (c) 2000 - 2011 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.
+*
+*/
+
+
+#ifndef _IPC_PARAM_H_
+#define _IPC_PARAM_H_
+
+class ipcEmailParam {
+ public:
+ ipcEmailParam();
+ virtual ~ipcEmailParam();
+
+ private:
+ int m_nLength;
+ void* m_pData;
+ public:
+ bool SetParam(void* a_pData, int a_nLen);
+ int GetLength();
+ void* GetData();
+
+};
+
+#endif /* _IPC_PARAM_H_ */
+
+
diff --git a/ipc/api/ipc-api-info.cpp b/ipc/api/ipc-api-info.cpp
new file mode 100755
index 0000000..7fd8720
--- /dev/null
+++ b/ipc/api/ipc-api-info.cpp
@@ -0,0 +1,150 @@
+/*
+* email-service
+*
+* Copyright (c) 2000 - 2011 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.
+*
+*/
+
+
+#include <string.h>
+#include <unistd.h>
+#include "ipc-api-info.h"
+#include "ipc-param-list.h"
+#include "ipc-library-build.h"
+
+ipcEmailAPIInfo::ipcEmailAPIInfo()
+{
+ m_pParams[ePARAMETER_IN] = NULL;
+ m_pParams[ePARAMETER_OUT] = NULL;
+ m_nAPIID = 0;
+ m_nResponseID = 0;
+ m_nAPPID = 0;
+}
+
+ipcEmailAPIInfo::~ipcEmailAPIInfo()
+{
+ if(m_pParams[ePARAMETER_IN]) {
+ delete m_pParams[ePARAMETER_IN];
+ m_pParams[ePARAMETER_IN] = NULL;
+ }
+
+ if(m_pParams[ePARAMETER_OUT]) {
+ delete m_pParams[ePARAMETER_OUT];
+ m_pParams[ePARAMETER_OUT] = NULL;
+ }
+}
+
+bool ipcEmailAPIInfo::SetAPIID(long a_nAPIID)
+{
+ m_nAPIID = a_nAPIID;
+ return true;
+}
+
+long ipcEmailAPIInfo::GetAPIID()
+{
+ return m_nAPIID;
+}
+
+
+bool ipcEmailAPIInfo::SetAPPID(long a_nAPPID)
+{
+ m_nAPPID = a_nAPPID;
+ return true;
+}
+
+long ipcEmailAPIInfo::GetAPPID()
+{
+ return m_nAPPID;
+}
+
+
+bool ipcEmailAPIInfo::SetResponseID(long a_nResponseID)
+{
+ m_nResponseID = a_nResponseID;
+ return true;
+}
+
+long ipcEmailAPIInfo::GetResponseID()
+{
+ return m_nResponseID;
+}
+
+bool ipcEmailAPIInfo::ParseStream(EPARAMETER_DIRECTION a_eDirection, void* a_pStream)
+{
+ if(m_pParams[a_eDirection] == NULL) {
+ m_pParams[a_eDirection] = new ipcEmailParamList();
+ }
+
+ ParseAPIID(a_pStream);
+ ParseResponseID(a_pStream);
+ ParseAPPID(a_pStream);
+ return m_pParams[a_eDirection]->ParseStream(a_pStream);
+}
+
+void* ipcEmailAPIInfo::GetStream(EPARAMETER_DIRECTION a_eDirection)
+{
+
+ if(m_pParams[a_eDirection] == NULL) {
+ m_pParams[a_eDirection] = new ipcEmailParamList();
+ }
+
+ unsigned char* pStream = (unsigned char*)m_pParams[a_eDirection]->GetStream();
+ if ( pStream != NULL ) {
+ memcpy(pStream, (void*)&m_nAPIID, sizeof(m_nAPIID));
+ memcpy(pStream+(sizeof(long)*eSTREAM_RESID), (void*)&m_nResponseID, sizeof(m_nResponseID));
+ memcpy(pStream+(sizeof(long)*eSTREAM_APPID), (void*)&m_nAPPID, sizeof(m_nAPPID));
+ }
+
+ return (void*)pStream;
+}
+
+int ipcEmailAPIInfo::GetStreamLength(EPARAMETER_DIRECTION a_eDirection)
+{
+ if(m_pParams[a_eDirection] == NULL)
+ return 0;
+
+ return m_pParams[a_eDirection]->GetStreamLength();
+}
+
+void* ipcEmailAPIInfo::GetParameters(EPARAMETER_DIRECTION a_eDirection)
+{
+ if(m_pParams[a_eDirection] == NULL) {
+ m_pParams[a_eDirection] = new ipcEmailParamList();
+ }
+ return m_pParams[a_eDirection];
+}
+
+
+long ipcEmailAPIInfo::ParseAPIID(void* a_pStream)
+{
+ m_nAPIID = *((long*)a_pStream + eSTREAM_APIID);
+ return m_nAPIID;
+}
+
+long ipcEmailAPIInfo::ParseResponseID(void* a_pStream)
+{
+ m_nResponseID = *((long*)a_pStream + eSTREAM_RESID);
+ return m_nResponseID;
+}
+
+
+long ipcEmailAPIInfo::ParseAPPID(void* a_pStream)
+{
+ m_nAPPID = *((long*)a_pStream + eSTREAM_APPID);
+ return m_nAPPID;
+
+}
diff --git a/ipc/api/ipc-param-list.cpp b/ipc/api/ipc-param-list.cpp
new file mode 100755
index 0000000..074ce23
--- /dev/null
+++ b/ipc/api/ipc-param-list.cpp
@@ -0,0 +1,201 @@
+/*
+* email-service
+*
+* Copyright (c) 2000 - 2011 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.
+*
+*/
+
+
+#include <string.h>
+#include <stdlib.h>
+#include "ipc-library-build.h"
+#include "ipc-param-list.h"
+
+
+ipcEmailParamList::ipcEmailParamList()
+{
+ EM_DEBUG_FUNC_BEGIN();
+ m_nParamCount = 0;
+ m_pbyteStream = NULL;
+}
+
+ipcEmailParamList::~ipcEmailParamList()
+{
+ EM_DEBUG_FUNC_BEGIN();
+ EM_SAFE_FREE(m_pbyteStream);
+ EM_DEBUG_FUNC_END();
+}
+
+/* stream */
+/* +----------------------------------------------------------------------------------------------------------+ */
+/* | API ID(4B) | Resp. ID (4B) | Param Count(4B) | Param1 Len | Param1 Data | ... | ParamN Len | ParamN data | */
+/* +----------------------------------------------------------------------------------------------------------+ */
+bool ipcEmailParamList::ParseStream(void* a_pStreamData)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ long nParameterCount = ParseParameterCount(a_pStreamData);
+ if(nParameterCount <= 0) {
+ EM_DEBUG_EXCEPTION("There is no parameter. ");
+ return false;
+ }
+
+ unsigned char* pStream = (unsigned char*)a_pStreamData;
+ long nIndex, nParamLen, nPos = sizeof(long)*eSTREAM_DATA;
+/* _pal_ITrace_IPCPrintF("[IPCLib] Parameter Count [%x] ", nParameterCount); */
+
+ for(nIndex = 0; nIndex < nParameterCount; nIndex++) {
+/* unsigned char szLen[5] = {NULL,}; */
+/* memcpy(szLen, pStream+nPos, sizeof(long)); */
+/* nParamLen = *(long*)(szLen); */
+
+ long nLen =0;
+ memcpy(&nLen, pStream+nPos, sizeof(long));
+ nParamLen = nLen;
+ EM_DEBUG_LOG("Parameter Length [%d] : %d ", nIndex, nParamLen);
+ nPos += sizeof(long); /* Move from length position to data position */
+
+ AddParam((void*)(pStream+nPos), nParamLen);
+ nPos += nParamLen; /* move to next parameter */
+ }
+
+ return true;
+}
+
+void* ipcEmailParamList::GetStream()
+{
+ EM_DEBUG_FUNC_BEGIN();
+ if(m_pbyteStream)
+ return m_pbyteStream;
+
+ int nStreamLen = GetStreamLength();
+
+ if ( nStreamLen > 0 ) {
+ m_pbyteStream = (unsigned char*) calloc(1, nStreamLen);
+ int nPos = sizeof(long)*eSTREAM_COUNT;
+
+ if ( nPos + (int)sizeof(m_nParamCount) > nStreamLen ) {
+ EM_DEBUG_EXCEPTION("%d > nStreamLen", nPos + sizeof(m_nParamCount));
+ EM_SAFE_FREE(m_pbyteStream);
+ return NULL;
+ }
+
+ memcpy((void*)(m_pbyteStream+nPos), (void*)&m_nParamCount, sizeof(m_nParamCount));
+
+ nPos += sizeof(long);
+ int nIndex = 0, nLength = 0;
+
+ /* check memory overflow */
+ for(nIndex=0; nIndex<m_nParamCount; nIndex++) {
+ nLength = m_lstParams[nIndex].GetLength();
+ if ( nLength <= 0 ) {
+ EM_DEBUG_EXCEPTION("nLength = %d", nIndex, nLength);
+ EM_SAFE_FREE(m_pbyteStream);
+ return NULL;
+ }
+
+ if ( nPos + (int)sizeof(long) > nStreamLen ) {
+ EM_DEBUG_EXCEPTION("%d > nStreamLen", nPos + sizeof(long));
+ EM_SAFE_FREE(m_pbyteStream);
+ return NULL;
+ }
+ memcpy((void*)(m_pbyteStream+nPos), (void*)&nLength, sizeof(long));
+ nPos += sizeof(long);
+
+ if ( nPos + nLength > nStreamLen ) {
+ EM_DEBUG_EXCEPTION("%d > nStreamLen", nPos + nLength);
+ EM_SAFE_FREE(m_pbyteStream);
+ return NULL;
+ }
+
+ memcpy((void*)(m_pbyteStream+nPos), (void*)m_lstParams[nIndex].GetData(), nLength);
+ nPos += nLength;
+ }
+ return (void*)m_pbyteStream;
+ }
+
+ EM_DEBUG_EXCEPTION("failed.");
+ EM_SAFE_FREE(m_pbyteStream);
+
+ EM_DEBUG_FUNC_END();
+ return NULL;
+}
+
+
+int ipcEmailParamList::GetStreamLength()
+{
+ /* if(m_lstParams ) // prevent 20071030 : m_lstParams is array */ {
+ int nLength = sizeof(long)*eSTREAM_DATA; /* API ID, Response ID, Param count */
+ int nIndex;
+ for(nIndex=0; nIndex<m_nParamCount; nIndex++) {
+ nLength += sizeof(long); /* Length size */
+ nLength += m_lstParams[nIndex].GetLength(); /* data size */
+ }
+ return nLength;
+ }
+ return 0;
+}
+
+bool ipcEmailParamList::AddParam(void* a_pData, int a_nLen)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ if(m_lstParams[m_nParamCount].SetParam(a_pData, a_nLen)) {
+ m_nParamCount++;
+ EM_SAFE_FREE(m_pbyteStream);
+ return true;
+ }
+
+ return false;
+
+}
+
+void* ipcEmailParamList::GetParam(int a_nIndex)
+{
+ EM_DEBUG_FUNC_BEGIN("a_nIndex [%d]", a_nIndex);
+ if(a_nIndex < 0 || a_nIndex >= m_nParamCount) {
+ EM_DEBUG_EXCEPTION("Index value is not valid ");
+ return NULL;
+ }
+
+ return (void*)m_lstParams[a_nIndex].GetData();
+}
+
+int ipcEmailParamList::GetParamLen(int a_nIndex)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ if(a_nIndex < 0 || a_nIndex >= m_nParamCount) {
+ EM_DEBUG_EXCEPTION("Index value is not valid ");
+ return 0;
+ }
+
+ return m_lstParams[a_nIndex].GetLength();
+}
+
+int ipcEmailParamList::GetParamCount()
+{
+ EM_DEBUG_FUNC_BEGIN("Paramter count [%d] ", m_nParamCount);
+ return m_nParamCount;
+}
+
+long ipcEmailParamList::ParseParameterCount(void *a_pStream)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ long *pParameterCountPostion = (long*)a_pStream + eSTREAM_COUNT;
+
+ return *pParameterCountPostion;
+}
+
diff --git a/ipc/api/ipc-param.cpp b/ipc/api/ipc-param.cpp
new file mode 100755
index 0000000..f704626
--- /dev/null
+++ b/ipc/api/ipc-param.cpp
@@ -0,0 +1,67 @@
+/*
+* email-service
+*
+* Copyright (c) 2000 - 2011 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.
+*
+*/
+
+
+#include <string.h>
+#include <stdlib.h>
+
+#include "ipc-param.h"
+#include "emf-dbglog.h"
+
+ipcEmailParam::ipcEmailParam()
+{
+ m_nLength = 0;
+ m_pData = NULL;
+
+}
+ipcEmailParam::~ipcEmailParam()
+{
+ EM_SAFE_FREE(m_pData);
+}
+
+bool ipcEmailParam::SetParam(void* a_pData, int a_nLen)
+{
+ if(a_nLen == 0)
+ return true;
+
+ m_pData = (void*)malloc(a_nLen);
+ if(m_pData == NULL)
+ return false;
+ memset(m_pData, 0x00, a_nLen);
+
+ if(a_pData != NULL) {
+ memcpy(m_pData, a_pData, a_nLen);
+ }
+ m_nLength = a_nLen;
+ return true;
+}
+
+int ipcEmailParam::GetLength()
+{
+ return m_nLength;
+}
+
+void* ipcEmailParam::GetData()
+{
+ return m_pData;
+}
+
+
diff --git a/ipc/common/cm-list.cpp b/ipc/common/cm-list.cpp
new file mode 100755
index 0000000..43959c0
--- /dev/null
+++ b/ipc/common/cm-list.cpp
@@ -0,0 +1,113 @@
+/*
+* email-service
+*
+* Copyright (c) 2000 - 2011 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.
+*
+*/
+
+
+#include <stdio.h>
+#include "cm-list.h"
+#include "ipc-queue.h"
+#include "ipc-library-build.h"
+
+cmList::cmList()
+{
+ m_pHead = NULL;
+ m_pTail = NULL;
+ m_nCount = 0;
+}
+
+cmList::~cmList()
+{
+}
+
+bool cmList::AddTail(void* a_pData)
+{
+ if(!a_pData)
+ return false;
+
+ ipcEmailQueueItem *pItem = new ipcEmailQueueItem(a_pData);
+ if(!pItem)
+ return false;
+
+ if(m_pTail) {
+ m_pTail->m_pNext = pItem;
+ m_pTail = pItem;
+ } else {
+ m_pHead = m_pTail = pItem;
+ }
+
+ m_nCount++;
+
+ return true;
+}
+
+bool cmList::RemoveItem(void* a_pData)
+{
+ if(m_pHead) {
+ ipcEmailQueueItem *pItem = m_pHead;
+ ipcEmailQueueItem *pPrevItem = NULL;
+ int nIndex = 0;
+ for(nIndex = 0; nIndex < m_nCount; nIndex++) {
+ if(pItem->m_pData == a_pData) {
+ if(pPrevItem) {
+ pPrevItem->m_pNext = pItem->m_pNext;
+
+ if(pItem->m_pNext == NULL) /* TailÀ» Áö¿ì´Â °æ¿ì */
+ m_pTail = pPrevItem; /* TailÀ» ¹Ù·Î ÀÌÀü °ÍÀ¸·Î ¼³Á¤ */
+ } else /* Head¸¦ Áö¿ì´Â °æ¿ì */ {
+ m_pHead = m_pHead->m_pNext;
+
+ if(m_pHead == NULL) /* ´Ù Áö¿öÁ³À¸¸é Tailµµ NULL·Î ÃʱâÈ­ */
+ m_pTail = NULL;
+ }
+
+ delete pItem;
+ pItem = NULL;
+ m_nCount--;
+ return true;
+ }
+ pPrevItem = pItem; /* prevent 20071030 */
+ pItem = pItem->m_pNext;
+ }
+ }
+ return false;
+}
+
+void* cmList::GetAt(int a_nIndex)
+{
+ if(m_pHead) {
+ ipcEmailQueueItem *pItem = m_pHead;
+ int nIndex = 0;
+ for(nIndex = 0; nIndex < a_nIndex; nIndex++) {
+ pItem = pItem->m_pNext;
+ }
+
+ if(pItem) {
+ return pItem->m_pData;
+ }
+ }
+ return NULL;
+}
+
+int cmList::GetCount()
+{
+ return m_nCount;
+}
+
+
diff --git a/ipc/common/cm-sys-msg-queue.cpp b/ipc/common/cm-sys-msg-queue.cpp
new file mode 100755
index 0000000..1adefd1
--- /dev/null
+++ b/ipc/common/cm-sys-msg-queue.cpp
@@ -0,0 +1,127 @@
+/*
+* email-service
+*
+* Copyright (c) 2000 - 2011 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.
+*
+*/
+
+
+#include <string.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include "cm-sys-msg-queue.h"
+#include "ipc-library-build.h"
+
+cmSysMsgQueue::cmSysMsgQueue(int a_nMsgType)
+{
+ m_nMsgType = a_nMsgType;
+ m_pSendBuf = NULL;
+ m_pRecvBuf = NULL;
+ m_nMsgqid = -1;
+ m_pSendBuf = (ipcMsgbuf * )malloc(sizeof(ipcMsgbuf));
+ m_pRecvBuf = (ipcMsgbuf * )malloc(sizeof(ipcMsgbuf));
+}
+
+cmSysMsgQueue::~cmSysMsgQueue()
+{
+ if(m_pSendBuf) {
+ free(m_pSendBuf);
+ m_pSendBuf = NULL;
+ }
+ if(m_pRecvBuf) {
+ free(m_pRecvBuf);
+ m_pRecvBuf = NULL;
+ }
+
+}
+
+void cmSysMsgQueue::MsgCreate()
+{
+ EM_DEBUG_FUNC_BEGIN();
+ key_t key = (key_t)640;/* (key_t)a_nKey; */
+
+ /* if ((m_nMsgqid = msgget(key, IPC_CREAT | IPC_EXCL | 0640)) == -1) */
+ if ((m_nMsgqid = msgget(key, IPC_CREAT | IPC_EXCL | 0777)) == -1) /* Security Issue - DAC */ {
+ m_nMsgqid = msgget(key, 1);
+
+ /* ±âÁ¸ÀÇ ¸Þ¼¼Áö Å¥°¡ Á¸ÀçÇÑ´Ù¸é ÀÏ´Ü Áö¿ì°í ´Ù½Ã »ý¼ºÇÑ´Ù. */
+ if(errno == EEXIST) {
+ EM_DEBUG_LOG("Message Queue Exist ");
+ /* msgctl(m_nMsgqid, IPC_RMID, (struct msqid_ds *)NULL); */
+ /* m_nMsgqid = msgget(key, IPC_CREAT | IPC_EXCL | 0640); */
+ EM_DEBUG_LOG("===================================================== ");
+ EM_DEBUG_LOG("[cmSysMsgQueue::MsgCreate][EXIST]");
+ EM_DEBUG_LOG("=====================================================");
+ }
+ }
+ EM_DEBUG_LOG("=====================================================");
+ EM_DEBUG_LOG("[cmSysMsgQueue::MsgCreate][msggid = %d]", m_nMsgqid);
+ EM_DEBUG_LOG("=====================================================");
+
+}
+int cmSysMsgQueue::MsgSnd(void *a_pMsg, int a_nSize, long a_nType)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ memset(m_pSendBuf, 0x00, sizeof(ipcMsgbuf));
+ m_pSendBuf->mtype = a_nType;
+ memcpy(m_pSendBuf->mtext, a_pMsg, a_nSize);
+ int nRet;
+ EM_DEBUG_LOG("===========================================================");
+ EM_DEBUG_LOG("[cmSysMsgQueue::MsgSnd][m_nMsgqid = %d]", m_nMsgqid);
+ EM_DEBUG_LOG("[cmSysMsgQueue::MsgSnd][a_nSize = %d]", a_nSize);
+ EM_DEBUG_LOG("[cmSysMsgQueue::MsgSnd][a_nType = %d]", a_nType);
+ EM_DEBUG_LOG("===========================================================");
+ nRet = msgsnd(m_nMsgqid, m_pSendBuf, IPC_MSGQ_SIZE, 0); /* 0 °ª ¸»°í IPC_NOWAIT */
+
+ EM_DEBUG_LOG("=====================================================");
+ EM_DEBUG_LOG("[cmSysMsgQueue::MsgSnd][ret = %d]", nRet);
+ EM_DEBUG_LOG("=====================================================");
+ return nRet;
+}
+
+int cmSysMsgQueue::MsgRcv(void *a_pMsg, int a_nSize)
+{
+ int nRet;
+ EM_DEBUG_LOG("===========================================================");
+ EM_DEBUG_LOG("[cmSysMsgQueue::MsgRcv][m_nMsgqid = %d]", m_nMsgqid);
+ EM_DEBUG_LOG("[cmSysMsgQueue::MsgRcv][m_nMsgType = %d]", m_nMsgType);
+ EM_DEBUG_LOG("===========================================================");
+ nRet = msgrcv(m_nMsgqid, m_pRecvBuf, IPC_MSGQ_SIZE, m_nMsgType, 0);
+ if (nRet == -1) { EM_DEBUG_LOG("===========================================================");
+ EM_DEBUG_LOG("[cmSysMsgQueue::MsgRcv][FAIL]");
+ EM_DEBUG_LOG("[cmSysMsgQueue::MsgRcv][error:=%d][errorstr =%s]", errno, strerror(errno));
+ EM_DEBUG_LOG("===========================================================");
+ }
+ memcpy(a_pMsg, m_pRecvBuf->mtext, a_nSize);
+ EM_DEBUG_LOG("=====================================================");
+ EM_DEBUG_LOG("[cmSysMsgQueue::MsgRcv][ret = %d][mtype = %x][Size = %d]", nRet, m_nMsgType, a_nSize);
+ EM_DEBUG_LOG("=====================================================");
+ return nRet;
+}
+
+bool cmSysMsgQueue::MsgDestroy()
+{
+ if(msgctl(m_nMsgqid, IPC_RMID, NULL) == -1)
+ return false;
+
+
+ EM_DEBUG_LOG("=====================================================");
+ EM_DEBUG_LOG("[cmSysMsgQueue][MsgDestroy]");
+ EM_DEBUG_LOG("=====================================================");
+ return true;
+}
+
diff --git a/ipc/common/include/cm-list.h b/ipc/common/include/cm-list.h
new file mode 100755
index 0000000..ba84e8a
--- /dev/null
+++ b/ipc/common/include/cm-list.h
@@ -0,0 +1,49 @@
+/*
+* email-service
+*
+* Copyright (c) 2000 - 2011 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.
+*
+*/
+
+
+#ifndef _IPC_LIST_H_
+#define _IPC_LIST_H_
+
+class ipcEmailQueueItem;
+
+class cmList
+{
+public:
+ cmList();
+ virtual ~cmList();
+
+private:
+ ipcEmailQueueItem* m_pHead;
+ ipcEmailQueueItem* m_pTail;
+ int m_nCount;
+
+public:
+ bool AddTail(void* a_pData);
+
+ bool RemoveItem(void* a_pData);
+ void* GetAt(int a_nIndex);
+ int GetCount();
+};
+
+#endif /* _IPC_LIST_H_ */
+
+
diff --git a/ipc/common/include/cm-sys-msg-queue.h b/ipc/common/include/cm-sys-msg-queue.h
new file mode 100755
index 0000000..aabde81
--- /dev/null
+++ b/ipc/common/include/cm-sys-msg-queue.h
@@ -0,0 +1,62 @@
+/*
+* email-service
+*
+* Copyright (c) 2000 - 2011 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.
+*
+*/
+
+
+#ifndef _IPC_MESSAGE_Q_H_
+#define _IPC_MESSAGE_Q_H_
+#include <sys/ipc.h>
+#include <sys/msg.h>
+#include <errno.h>
+
+#include "emf-dbglog.h"
+#define IPC_MSGQ_SIZE 512
+
+typedef struct {
+ long mtype; /* type of message ¸Þ¼¼Áö ŸÀÔ */
+ char mtext[IPC_MSGQ_SIZE]; /* message text ¸Þ¼¼Áö ³»¿ë */
+}ipcMsgbuf;
+
+class cmSysMsgQueue
+{
+public:
+ cmSysMsgQueue(int a_nMsgType);
+ virtual ~ cmSysMsgQueue();
+
+private:
+ int m_nMsgType;
+ /* key_t m_nKey; */ /*CID = 17033 BU not used */
+ long m_nMsgqid;
+ ipcMsgbuf *m_pSendBuf;
+ ipcMsgbuf *m_pRecvBuf;
+
+public:
+ void MsgCreate();
+ int MsgSnd(void *a_pMsg, int a_nSize, long a_nType);
+ int MsgRcv(void *a_pMsg, int a_nSize);
+ bool MsgDestroy();
+
+};
+
+#endif /* _IPC_MESSAGE_Q_H_ */
+
+
+
+
diff --git a/ipc/include/ipc-library-build.h b/ipc/include/ipc-library-build.h
new file mode 100755
index 0000000..0014b6a
--- /dev/null
+++ b/ipc/include/ipc-library-build.h
@@ -0,0 +1,33 @@
+/*
+* email-service
+*
+* Copyright (c) 2000 - 2011 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.
+*
+*/
+
+
+#ifndef __IPC_LIBRARY_BUILD_H_
+#define __IPC_LIBRARY_BUILD_H_
+
+#include <stdio.h>
+/* #include "MessagingFramework/msBuild.h */
+/* #include "EFCInterface/Common/SDKInterface.h */
+
+
+#endif /* __IPC_LIBRARY_BUILD_H */
+
+
diff --git a/ipc/include/ipc-library.h b/ipc/include/ipc-library.h
new file mode 100755
index 0000000..3df7c59
--- /dev/null
+++ b/ipc/include/ipc-library.h
@@ -0,0 +1,87 @@
+/*
+* email-service
+*
+* Copyright (c) 2000 - 2011 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.
+*
+*/
+
+
+#ifndef __IPC_LIBRARY_H
+#define __IPC_LIBRARY_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define EM_PROXY_IF_NULL_RETURN_VALUE(expr1, expr2, val) { \
+ if (!expr1&& expr2) { \
+ EM_DEBUG_LOG ("EM_PROXY_IF_NULL_RETURN_VALUE : PARAM IS NULL \n"); \
+ ipcEmailAPI_Destroy(expr2); \
+ return val; \
+ }; }
+
+
+/* ------------------------------------------------------------------------------------------------------------ */
+/* Type Definitio */
+/* ------------------------------------------------------------------------------------------------------------ */
+typedef enum {
+ ePARAMETER_IN = 0,
+ ePARAMETER_OUT,
+} EPARAMETER_DIRECTION;
+
+typedef void* HIPC_API;
+typedef void* HIPC_PARAMETER;
+typedef void (*PFN_PROXY_CALLBACK) (HIPC_API a_hAPI, void* pParam1, void* pParam2);
+typedef void (*PFN_EXECUTE_API) (HIPC_API a_hAPI);
+
+/* ------------------------------------------------------------------------------------------------------------ */
+/* Proxy AP */
+/* ------------------------------------------------------------------------------------------------------------ */
+int ipcEmailProxy_Initialize();
+int ipcEmailProxy_Finalize(void);
+
+bool ipcEmailProxy_ExecuteAPI(HIPC_API a_hAPI);
+
+/* ------------------------------------------------------------------------------------------------------------ */
+/* Stub AP */
+/* ------------------------------------------------------------------------------------------------------------ */
+bool ipcEmailStub_Initialize(PFN_EXECUTE_API a_pfnAPIMapper);
+bool ipcEmailStub_Finalize(void);
+
+bool ipcEmailStub_ExecuteAPI(HIPC_API a_hAPI);
+
+/* ------------------------------------------------------------------------------------------------------------ */
+/* AP */
+/* ------------------------------------------------------------------------------------------------------------ */
+HIPC_API ipcEmailAPI_Create(long a_nAPIID);
+void ipcEmailAPI_Destroy(HIPC_API a_hAPI);
+
+long ipcEmailAPI_GetAPIID(HIPC_API a_hAPI);
+long ipcEmailAPI_GetAPPID(HIPC_API a_hAPI);
+
+bool ipcEmailAPI_AddParameter(HIPC_API a_hAPI, EPARAMETER_DIRECTION a_eDirection, void *a_pData, int a_nDataLength);
+int ipcEmailAPI_GetParameterCount(HIPC_API a_hAPI, EPARAMETER_DIRECTION a_eDirection);
+void* ipcEmailAPI_GetParameter(HIPC_API a_hAPI, EPARAMETER_DIRECTION a_eDirection, int a_nParameterIndex);
+int ipcEmailAPI_GetParameterLength(HIPC_API a_hAPI, EPARAMETER_DIRECTION a_eDirection, int a_nParameterIndex);
+
+
+#ifdef __cplusplus
+}
+#endif
+#endif
+
+
diff --git a/ipc/ipc-library-api.cpp b/ipc/ipc-library-api.cpp
new file mode 100755
index 0000000..12ae808
--- /dev/null
+++ b/ipc/ipc-library-api.cpp
@@ -0,0 +1,139 @@
+/*
+* email-service
+*
+* Copyright (c) 2000 - 2011 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.
+*
+*/
+
+
+
+#include "include/ipc-library-build.h"
+#include "include/ipc-library.h"
+#include "proxy/include/ipc-proxy-main.h"
+#include "api/include/ipc-api-info.h"
+#include "api/include/ipc-param-list.h"
+#include "socket/include/ipc-socket.h"
+#include "emf-dbglog.h"
+
+EXPORT_API ipcEmailParamList* _ipcAPI_GetParameters(HIPC_API a_hAPI, EPARAMETER_DIRECTION a_eDirection)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ ipcEmailAPIInfo *pAPI = (ipcEmailAPIInfo*)a_hAPI;
+ if(pAPI) {
+ return (ipcEmailParamList*)pAPI->GetParameters(a_eDirection);
+ }
+ return 0;
+}
+
+EXPORT_API HIPC_API ipcEmailAPI_Create(long a_nAPIID)
+{
+
+ EM_DEBUG_FUNC_BEGIN();
+
+ ipcEmailAPIInfo *pApi = new ipcEmailAPIInfo();
+ if(pApi == NULL) {
+ return NULL;
+ }
+
+ pApi->SetAPIID(a_nAPIID);
+ return (HIPC_API)pApi;
+}
+
+EXPORT_API void ipcEmailAPI_Destroy(HIPC_API a_hAPI)
+{
+ EM_DEBUG_FUNC_BEGIN("a_hAPI = %p", a_hAPI);
+ ipcEmailAPIInfo *pAPI = (ipcEmailAPIInfo*)a_hAPI;
+ if(pAPI) {
+ delete pAPI;
+ }
+}
+
+
+EXPORT_API long ipcEmailAPI_GetAPIID(HIPC_API a_hAPI)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ ipcEmailAPIInfo *pAPI = (ipcEmailAPIInfo*)a_hAPI;
+ if(pAPI) {
+ return pAPI->GetAPIID();
+ }
+ return -1;
+}
+
+
+EXPORT_API long ipcEmailAPI_GetAPPID(HIPC_API a_hAPI)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ ipcEmailAPIInfo *pAPI = (ipcEmailAPIInfo*)a_hAPI;
+ if(pAPI) {
+ return pAPI->GetAPPID();
+ }
+ return -1;
+}
+
+EXPORT_API bool ipcEmailAPI_AddParameter(HIPC_API a_hAPI, EPARAMETER_DIRECTION a_eDirection, void *a_pData, int a_nDataLength)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ ipcEmailParamList *pParameters = _ipcAPI_GetParameters(a_hAPI, a_eDirection);
+
+ if(pParameters) {
+ pParameters->AddParam(a_pData, a_nDataLength);
+ return true;
+ }
+ return false;
+}
+
+EXPORT_API int ipcEmailAPI_GetParameterCount(HIPC_API a_hAPI, EPARAMETER_DIRECTION a_eDirection)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ ipcEmailParamList *pParameters = _ipcAPI_GetParameters(a_hAPI, a_eDirection);
+ if(pParameters) {
+ return pParameters->GetParamCount();
+ }
+ return -1;
+}
+
+EXPORT_API void* ipcEmailAPI_GetParameter(HIPC_API a_hAPI, EPARAMETER_DIRECTION a_eDirection, int a_nParameterIndex)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ ipcEmailParamList *pParameters = _ipcAPI_GetParameters(a_hAPI, a_eDirection);
+
+ if(pParameters) {
+ EM_DEBUG_FUNC_END("Suceeded");
+ return pParameters->GetParam(a_nParameterIndex);
+ }
+ EM_DEBUG_FUNC_END("Failed");
+ return 0;
+}
+
+EXPORT_API int ipcEmailAPI_GetParameterLength(HIPC_API a_hAPI, EPARAMETER_DIRECTION a_eDirection, int a_nParameterIndex)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ ipcEmailParamList *pParameters = _ipcAPI_GetParameters(a_hAPI, a_eDirection);
+ if(pParameters) {
+ EM_DEBUG_FUNC_END("Suceeded");
+ return pParameters->GetParamLen(a_nParameterIndex);
+ }
+ EM_DEBUG_FUNC_END("Failed");
+ return -1;
+}
+
+
+
+
+
diff --git a/ipc/ipc-library-build.cpp b/ipc/ipc-library-build.cpp
new file mode 100755
index 0000000..53c2428
--- /dev/null
+++ b/ipc/ipc-library-build.cpp
@@ -0,0 +1,28 @@
+/*
+* email-service
+*
+* Copyright (c) 2000 - 2011 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.
+*
+*/
+
+
+#include <stdlib.h>
+#include <stdarg.h>
+#include "ipc-library-build.h"
+
+
+
diff --git a/ipc/ipc-library-proxy.cpp b/ipc/ipc-library-proxy.cpp
new file mode 100755
index 0000000..b750751
--- /dev/null
+++ b/ipc/ipc-library-proxy.cpp
@@ -0,0 +1,80 @@
+/* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * PROPRIETARY/CONFIDENTIAL
+ *
+ * This software is the confidential and proprietary information of SAMSUNG
+ * ELECTRONICS ("Confidential Information"). You agree and acknowledge that
+ * this software is owned by Samsung and you shall not disclose such
+ * Confidential Information and shall use it only in accordance with the terms
+ * of the license agreement you entered into with SAMSUNG ELECTRONICS.
+ * SAMSUNG make no representations or warranties about the suitability of the
+ * software, either express or implied, including but not limited to the
+ * implied warranties of merchantability, fitness for a particular purpose,
+ * or non-infringement. SAMSUNG shall not be liable for any damages suffered
+ * by licensee arising out of or releated to this software.
+ *
+ */
+
+#include "include/ipc-library-build.h"
+#include "include/ipc-library.h"
+#include "proxy/include/ipc-proxy-main.h"
+#include "api/include/ipc-api-info.h"
+#include "api/include/ipc-param-list.h"
+#include "emf-dbglog.h"
+#include "ipc-socket.h"
+
+EXPORT_API int ipcEmailProxy_Initialize()
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ int err = ipcEmailProxyMain::Instance()->Initialize();
+
+ EM_DEBUG_FUNC_END();
+ return err;
+}
+
+EXPORT_API int ipcEmailProxy_Finalize()
+{
+ EM_DEBUG_FUNC_BEGIN();
+ return ipcEmailProxyMain::Instance()->Finalize();;
+}
+
+EXPORT_API bool ipcEmailProxy_ExecuteAPI(HIPC_API a_hAPI)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int ret;
+ int err = EMF_ERROR_NONE;
+ ipcEmailAPIInfo *pApi = static_cast<ipcEmailAPIInfo *>(a_hAPI);
+
+ EM_DEBUG_LOG("pApi [%p]", pApi);
+
+ if(pApi == NULL) {
+ EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
+ return EMF_ERROR_INVALID_PARAM;
+ }
+
+ EM_DEBUG_LOG("APIID [%s], ResponseID [%d], APPID[%d]", EM_APIID_TO_STR(pApi->GetAPIID()), pApi->GetResponseID(), pApi->GetAPPID());
+
+ ret = ipcEmailProxyMain::Instance()->ExecuteAPI(pApi);
+
+ /* connection retry */
+
+ if (!ret) {
+ ipcEmailProxy_Finalize();
+
+ err = ipcEmailProxy_Initialize();
+ if (err != EMF_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("Failed to open the socket : [%d]", err);
+ return EMF_ERROR_CONNECTION_FAILURE;
+ }
+
+ ret = ipcEmailProxyMain::Instance()->ExecuteAPI(pApi);
+
+ if (!ret) {
+ EM_DEBUG_EXCEPTION("ipcEmailProxyMain::ExecuteAPI failed [%d]", err);
+ return EMF_ERROR_CONNECTION_FAILURE;
+ }
+ }
+ EM_DEBUG_FUNC_END("err [%d]", err);
+ return err;
+}
diff --git a/ipc/ipc-library-stub.cpp b/ipc/ipc-library-stub.cpp
new file mode 100755
index 0000000..8900b2f
--- /dev/null
+++ b/ipc/ipc-library-stub.cpp
@@ -0,0 +1,52 @@
+/*
+* email-service
+*
+* Copyright (c) 2000 - 2011 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.
+*
+*/
+
+
+#include "include/ipc-library.h"
+#include "stub/include/ipc-stub-main.h"
+#include "include/ipc-library-build.h"
+#include "emf-dbglog.h"
+
+EXPORT_API bool ipcEmailStub_Initialize(PFN_EXECUTE_API a_pfnAPIMapper)
+{
+ EM_DEBUG_LOG("[IPCLib] ipcEmailStub_Initialize ");
+
+ return ipcEmailStubMain::Instance()->Initialize(a_pfnAPIMapper);
+}
+
+EXPORT_API bool ipcEmailStub_Finalize(void)
+{
+
+ ipcEmailStubMain::Instance()->Finalize();
+ ipcEmailStubMain::Instance()->FreeInstance();
+ return true;
+}
+
+EXPORT_API bool ipcEmailStub_ExecuteAPI(HIPC_API a_hAPI)
+{
+ EM_DEBUG_LOG("ipcEmailStub_ExecuteAPI [%x]", a_hAPI);
+ ipcEmailAPIInfo *pApi = static_cast<ipcEmailAPIInfo *>(a_hAPI);
+ if(pApi == NULL)
+ return false;
+ return ipcEmailStubMain::Instance()->ExecuteAPIStubToProxy(pApi);
+
+}
+
diff --git a/ipc/proxy/include/ipc-callback-info.h b/ipc/proxy/include/ipc-callback-info.h
new file mode 100755
index 0000000..0af5b7d
--- /dev/null
+++ b/ipc/proxy/include/ipc-callback-info.h
@@ -0,0 +1,48 @@
+/*
+* email-service
+*
+* Copyright (c) 2000 - 2011 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.
+*
+*/
+
+
+#ifndef _IPC_CALLBACK_INFO_H_
+#define _IPC_CALLBACK_INFO_H_
+
+
+class ipcEmailAPIInfo;
+
+
+class ipcEmailCallbackInfo
+{
+public:
+ ipcEmailCallbackInfo();
+ virtual ~ipcEmailCallbackInfo();
+
+private:
+ int m_nAPIID;
+ void *m_pfnCallBack;
+
+public:
+ bool SetValue(int m_nAPIID, void* a_pfnCallBack);
+ int GetAPIID();
+ void* GetCallBack();
+};
+
+#endif /* _IPC_CALLBACK_INFO_H_ */
+
+
diff --git a/ipc/proxy/include/ipc-proxy-main.h b/ipc/proxy/include/ipc-proxy-main.h
new file mode 100755
index 0000000..268d2a2
--- /dev/null
+++ b/ipc/proxy/include/ipc-proxy-main.h
@@ -0,0 +1,66 @@
+/*
+* email-service
+*
+* Copyright (c) 2000 - 2011 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.
+*
+*/
+
+
+
+#ifndef _IPC_PROXY_MAIN_H_
+#define _IPC_PROXY_MAIN_H_
+
+#include "ipc-library.h"
+#include <pthread.h>
+#include "cm-list.h"
+#include "cm-sys-msg-queue.h"
+#include "ipc-api-info.h"
+#include "ipc-proxy-socket.h"
+#include "ipc-callback-info.h"
+#include "emf-mutex.h"
+
+
+class ipcEmailProxyMain
+{
+public:
+ ipcEmailProxyMain();
+ virtual ~ipcEmailProxyMain();
+
+private:
+ static ipcEmailProxyMain* s_pThis;
+ int m_nReference;
+ ipcEmailProxySocket *m_pSyncSocket;
+ bool m_bRecvStopFlag;
+ cmSysMsgQueue *m_pProxyMessageQ;
+ int m_nAPPID;
+ Mutex mx;
+
+private:
+ bool RegisterTask(ipcEmailAPIInfo *a_pApiInfo);
+
+public:
+
+ static ipcEmailProxyMain* Instance();
+ static void FreeInstance();
+ int Initialize();
+ int Finalize();
+ bool ExecuteAPI(ipcEmailAPIInfo* pApi);
+ bool Dispatch();
+
+};
+#endif/* _IPC_PROXY_MAIN_H_ */
+
diff --git a/ipc/proxy/include/ipc-proxy-socket.h b/ipc/proxy/include/ipc-proxy-socket.h
new file mode 100755
index 0000000..bcca207
--- /dev/null
+++ b/ipc/proxy/include/ipc-proxy-socket.h
@@ -0,0 +1,48 @@
+/*
+* email-service
+*
+* Copyright (c) 2000 - 2011 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.
+*
+*/
+
+
+
+#ifndef _IPC_PROXY_SOCKET_H_
+#define _IPC_PROXY_SOCKET_H_
+#include "ipc-socket.h"
+#include "emf-dbglog.h"
+
+class ipcEmailProxySocket
+{
+ public:
+ ipcEmailProxySocket();
+ virtual ~ipcEmailProxySocket();
+
+ private:
+ fd_set fds_read;
+ ipcEmailSocket *m_pSocket;
+ public:
+ int Start();
+ bool End();
+ int Send(char* pData , int a_nLen );
+ int Recv(char** pData);
+ int GetSocketID();
+};
+
+#endif /* _IPC_PROXY_SOCKET_H_ */
+
+
diff --git a/ipc/proxy/ipc-callback-info.cpp b/ipc/proxy/ipc-callback-info.cpp
new file mode 100755
index 0000000..e89d22b
--- /dev/null
+++ b/ipc/proxy/ipc-callback-info.cpp
@@ -0,0 +1,52 @@
+/*
+* email-service
+*
+* Copyright (c) 2000 - 2011 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.
+*
+*/
+
+
+
+#include "ipc-callback-info.h"
+
+ipcEmailCallbackInfo::ipcEmailCallbackInfo()
+{
+ m_nAPIID = 0;
+ m_pfnCallBack = 0;
+}
+
+ipcEmailCallbackInfo::~ipcEmailCallbackInfo()
+{
+}
+
+
+bool ipcEmailCallbackInfo::SetValue(int a_nAPIID, void* a_pfnCallBack)
+{
+ m_nAPIID = a_nAPIID;
+ m_pfnCallBack = a_pfnCallBack;
+ return true;
+}
+
+int ipcEmailCallbackInfo::GetAPIID()
+{
+ return m_nAPIID;
+}
+
+void* ipcEmailCallbackInfo::GetCallBack()
+{
+ return m_pfnCallBack;
+}
diff --git a/ipc/proxy/ipc-proxy-main.cpp b/ipc/proxy/ipc-proxy-main.cpp
new file mode 100755
index 0000000..7490033
--- /dev/null
+++ b/ipc/proxy/ipc-proxy-main.cpp
@@ -0,0 +1,199 @@
+/*
+* email-service
+*
+* Copyright (c) 2000 - 2011 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.
+*
+*/
+
+
+
+#include <unistd.h>
+#include "ipc-library-build.h"
+#include "ipc-proxy-main.h"
+#include "emf-types.h"
+
+ipcEmailProxyMain* ipcEmailProxyMain::s_pThis = NULL;
+
+ipcEmailProxyMain::ipcEmailProxyMain() : mx()
+{
+ EM_DEBUG_FUNC_BEGIN();
+ m_pSyncSocket = NULL;
+ m_pProxyMessageQ = NULL;
+ m_bRecvStopFlag = false;
+ m_nReference = 0;
+ m_nAPPID = 0;
+ EM_DEBUG_FUNC_END();
+}
+
+ipcEmailProxyMain::~ipcEmailProxyMain()
+{
+ EM_DEBUG_FUNC_BEGIN();
+ EM_DEBUG_FUNC_END();
+}
+
+ipcEmailProxyMain* ipcEmailProxyMain::Instance()
+{
+ EM_DEBUG_FUNC_BEGIN();
+ if(s_pThis)
+ return s_pThis;
+
+ s_pThis = new ipcEmailProxyMain();
+
+ EM_DEBUG_FUNC_END();
+ return s_pThis;
+}
+
+void ipcEmailProxyMain::FreeInstance()
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ if(s_pThis) {
+ s_pThis->Finalize();
+ delete s_pThis;
+ s_pThis = NULL;
+ }
+ EM_DEBUG_FUNC_END();
+}
+
+int ipcEmailProxyMain::Initialize()
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ if (m_nReference > 0) {
+ EM_DEBUG_EXCEPTION("Already Initialized m_nReference[%d]", m_nReference);
+ return EMF_ERROR_NONE;
+ }
+
+ m_nReference++;
+
+ m_pSyncSocket = new ipcEmailProxySocket();
+
+ if(!m_pSyncSocket) {
+ EM_DEBUG_EXCEPTION("m_pSyncSocket == NULL");
+ return EMF_ERROR_IPC_SOCKET_FAILURE;
+ }
+
+ if( m_pSyncSocket->Start() != EMF_SUCCESS ) {
+ EM_DEBUG_EXCEPTION("Socket start FAILs");
+ return EMF_ERROR_IPC_CONNECTION_FAILURE;
+ }
+
+ EM_DEBUG_LOG("Socket ID : %x", m_pSyncSocket->GetSocketID());
+ EM_DEBUG_FUNC_END();
+ return EMF_ERROR_NONE;
+}
+
+int ipcEmailProxyMain::Finalize()
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ if (--m_nReference > 0) {
+ EM_DEBUG_EXCEPTION("More than one reference m_nReference[%d]",m_nReference);
+ return EMF_ERROR_NONE;
+ }
+
+ if(m_pSyncSocket) {
+ delete m_pSyncSocket;
+ m_pSyncSocket = NULL;
+ }
+
+ if(m_pProxyMessageQ) {
+ delete m_pProxyMessageQ;
+ m_pProxyMessageQ = NULL;
+ }
+ EM_DEBUG_FUNC_END();
+ return EMF_ERROR_NONE;
+}
+
+
+bool ipcEmailProxyMain::ExecuteAPI(ipcEmailAPIInfo* a_hAPI)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ if(!a_hAPI) {
+ EM_DEBUG_EXCEPTION("Invalid Parameter");
+ return false;
+ }
+
+ int nRet;
+ char* pInStream = (char*)a_hAPI->GetStream(ePARAMETER_IN);
+ int nLength = a_hAPI->GetStreamLength(ePARAMETER_IN);
+ bool result = false;
+ int sending_bytes;
+
+ mx.lock();
+ sending_bytes = m_pSyncSocket->Send(pInStream, nLength);
+ mx.unlock();
+
+ EM_DEBUG_LOG("Proxy=>Stub Sending %dB.", sending_bytes);
+
+ if( sending_bytes > 0 ) {
+#ifdef IPCLIB_STREAM_TRACE_ON
+ int index;
+ for(index=0; index< nLength; index++)
+ EM_DEBUG_LOG("pInStream[index] : [%x]", pInStream[index]);
+#endif
+
+ char* ipc_buf = NULL;
+
+ /* now waiting for response from email-service */
+ mx.lock();
+ nRet = m_pSyncSocket->Recv(&ipc_buf);
+ mx.unlock();
+ EM_DEBUG_LOG("Recv length : %d", nRet);
+
+ if (nRet > 0)
+ result = a_hAPI->ParseStream(ePARAMETER_OUT, ipc_buf);
+ else
+ result = false;
+
+ if(ipc_buf)
+ delete []ipc_buf;
+ }
+
+ EM_DEBUG_FUNC_END();
+ return result;
+}
+
+bool ipcEmailProxyMain::Dispatch()
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ unsigned char pStream[IPC_MSGQ_SIZE];
+
+ while(!m_bRecvStopFlag) {
+ memset(pStream, 0x00, sizeof(pStream));
+
+ if(m_pProxyMessageQ->MsgRcv(pStream, sizeof(pStream))>0) {
+ ipcEmailAPIInfo *pAPIInfo = new ipcEmailAPIInfo();
+ int nAPIID = *((int*)pStream);
+
+ pAPIInfo->SetAPIID(nAPIID);
+ pAPIInfo->ParseStream(ePARAMETER_OUT, pStream);
+ EM_DEBUG_LOG("Proxy Message Queue Recv [APIID=%x], [RecvLen=%d]", nAPIID, pAPIInfo->GetStreamLength(ePARAMETER_OUT));
+
+#ifdef IPCLIB_STREAM_TRACE_ON
+ int index;
+ for(index=0; index< pAPIInfo->GetStreamLength(ePARAMETER_OUT); index++)
+ EM_DEBUG_LOG("[%x]", pStream[index]);
+#endif
+ }
+ usleep(1000);
+ }
+ EM_DEBUG_FUNC_END();
+ return false;
+}
diff --git a/ipc/proxy/ipc-proxy-socket.cpp b/ipc/proxy/ipc-proxy-socket.cpp
new file mode 100755
index 0000000..44507a9
--- /dev/null
+++ b/ipc/proxy/ipc-proxy-socket.cpp
@@ -0,0 +1,161 @@
+/*
+* email-service
+*
+* Copyright (c) 2000 - 2011 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.
+*
+*/
+
+
+
+#include <unistd.h>
+#include <sys/select.h>
+#include "ipc-library-build.h"
+#include "ipc-proxy-socket.h"
+
+ipcEmailProxySocket::ipcEmailProxySocket()
+{
+ EM_DEBUG_FUNC_BEGIN();
+ memset(&fds_read, 0, sizeof(fd_set));/* CID = 17042 BU */
+ m_pSocket = NULL;
+}
+
+ipcEmailProxySocket::~ipcEmailProxySocket()
+{
+ EM_DEBUG_FUNC_BEGIN();
+ End();
+}
+
+int ipcEmailProxySocket::Start()
+{
+ EM_DEBUG_FUNC_BEGIN();
+ m_pSocket = new ipcEmailSocket();
+
+ if(m_pSocket) {
+ return m_pSocket->Connect();
+ }
+
+ return -1;
+}
+
+bool ipcEmailProxySocket::End()
+{
+ EM_DEBUG_FUNC_BEGIN();
+ EM_DEBUG_LOG("[IPCLib] ipcEmailProxySocket::End ");
+
+ if(m_pSocket) {
+ m_pSocket->Close(); /* prevent 20071030 */
+ delete(m_pSocket);
+ m_pSocket = NULL;
+ }
+
+ return true;
+}
+
+int ipcEmailProxySocket::Send(char* pData , int a_nLen)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ if(m_pSocket && m_pSocket->IsConnected()) {
+ return m_pSocket->Send(m_pSocket->GetSocketID(), pData, a_nLen);
+ } else {
+ EM_DEBUG_EXCEPTION("[IPCLib] ipcEmailProxySocket not connect");
+ /* m_pSocket->Connect(); */
+ return 0;
+ }
+}
+
+int ipcEmailProxySocket::GetSocketID()
+{
+ EM_DEBUG_FUNC_BEGIN();
+ if(m_pSocket)
+ return m_pSocket->GetSocketID();
+
+ return 0;
+}
+
+
+int ipcEmailProxySocket::Recv(char** pData)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+
+ int nRecvLen = 0;
+
+ if(m_pSocket /*&& m_pSocket->IsConnected()*/)
+ nRecvLen = m_pSocket->Recv(m_pSocket->GetSocketID(), pData); else {
+ EM_DEBUG_EXCEPTION("[IPCLib] m_pSocket[%p] is not available or disconnected", m_pSocket);
+ return 0;
+ }
+
+ if( nRecvLen == 0 ) {
+ EM_DEBUG_EXCEPTION("[IPCLib] Proxy Recv delete %x", m_pSocket->GetSocketID());
+ m_pSocket->Close();
+ } else if(nRecvLen == -1) {
+ EM_DEBUG_EXCEPTION("[IPCLib] Proxy Recv error");
+ }
+
+ return nRecvLen;
+/*
+ int ret_select;
+ fd_set fds_buf;
+ int nRecvLen = -2, timeout_count = 0;
+ struct timeval timeout;
+
+ while(1) {
+ fds_buf = fds_read;
+
+ FD_ZERO(&fds_buf);
+
+ FD_SET(m_pSocket->GetSocketID(), &fds_buf);
+ timeout.tv_sec = 0;
+ timeout.tv_usec = 1000000;
+ ret_select = select(m_pSocket->GetSocketID()+1, &fds_buf, NULL, NULL, &timeout);
+
+ if(ret_select == -1) {
+ EM_DEBUG_EXCEPTION("[IPCLib] Proxy select error");
+ break;
+ } else if(ret_select == 0) {
+ EM_DEBUG_EXCEPTION("[IPCLib] Proxy select timeout");
+
+ if(timeout_count++ > 10) {
+ EM_DEBUG_EXCEPTION("[IPCLib] exit from select loop");
+ break;
+ }
+ continue;
+ }
+
+ if(FD_ISSET(m_pSocket->GetSocketID(), &fds_buf)) {
+ nRecvLen = m_pSocket->Recv(m_pSocket->GetSocketID(), pData);
+ if(nRecvLen > 0) {
+ EM_DEBUG_LOG("[IPCLib] Proxy Recv[fd = %x], [nRecvLen = %d]", m_pSocket->GetSocketID(), nRecvLen);
+ break;
+ }
+ else if(nRecvLen == 0) {
+ EM_DEBUG_EXCEPTION("[IPCLib] Proxy Recv delete %x", m_pSocket->GetSocketID());
+ m_pSocket->Close();
+ break;
+ }
+ else if(nRecvLen == -1) {
+ EM_DEBUG_EXCEPTION("[IPCLib] Proxy Recv error");
+ break;
+ }
+ }
+
+ }
+*/
+ return nRecvLen;
+
+}
diff --git a/ipc/socket/include/ipc-socket.h b/ipc/socket/include/ipc-socket.h
new file mode 100755
index 0000000..5d11503
--- /dev/null
+++ b/ipc/socket/include/ipc-socket.h
@@ -0,0 +1,89 @@
+/*
+* email-service
+*
+* Copyright (c) 2000 - 2011 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.
+*
+*/
+
+
+#ifndef _IPC_SOCKET_H_
+#define _IPC_SOCKET_H_
+
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <string.h>
+#include <stdlib.h>
+
+#include <map>
+
+#define SOCKET_IP "127.0.0.1"
+#define SOCKET_PORT 9000
+
+#define BUF_SIZE 204800
+#define OPT_USEC 100000
+
+
+#define EM_SOCKET_PATH "/tmp/.emailfw_socket"
+
+class ipcEmailSocket
+{
+
+ protected:
+ int m_sockfd;
+ bool m_bConnect;
+
+ fd_set fds;
+ int maxfd;
+ std::map<int, int> mapFds;
+
+ public:
+ ipcEmailSocket();
+ ~ipcEmailSocket();
+
+ private:
+ int readn( int fd, char *buf, int len );
+ int writen (int fd, const char *buf, int len);
+
+ public:
+ bool IsConnected();
+
+ void Close();
+ void Close(int fd);
+ int Recv(int fd, char** buffer);
+ int Send(int fd, char* buffer, int len);
+ int GetSocketID();
+
+ int accept();
+ int open(const char* path);
+ int Connect();
+ void addfd(int fd);
+
+ int maxFd() { return (maxfd+1); }
+ fd_set fdSet() { return fds; }
+
+};
+
+#endif /* _IPC_SOCKET_H_ */
+
+
+
+
+
+
diff --git a/ipc/socket/ipc-socket.cpp b/ipc/socket/ipc-socket.cpp
new file mode 100755
index 0000000..c2a4a83
--- /dev/null
+++ b/ipc/socket/ipc-socket.cpp
@@ -0,0 +1,353 @@
+/*
+* email-service
+*
+* Copyright (c) 2000 - 2011 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.
+*
+*/
+
+
+#include "ipc-socket.h"
+#include "ipc-library-build.h"
+#include "emf-dbglog.h"
+#include "emf-types.h"
+
+#include <sys/socket.h>
+#include <sys/un.h>
+#include <sys/ioctl.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include <errno.h>
+#include <unistd.h>
+#include <errno.h>
+
+/* Constructor */
+ipcEmailSocket::ipcEmailSocket() : maxfd(-1)
+{
+ m_sockfd = socket(AF_UNIX, SOCK_STREAM, 0);
+
+ EM_DEBUG_LOG("fd = %d", m_sockfd);
+
+ if (m_sockfd < 0) {
+ EM_DEBUG_LOG("socket creation fails!!!: %s", strerror(errno));
+ }
+
+ FD_ZERO(&fds);
+}
+
+/* Destructor */
+ipcEmailSocket::~ipcEmailSocket()
+{
+ FD_ZERO(&fds);
+ mapFds.clear();
+ EM_DEBUG_LOG("socket object is destoryed");
+}
+
+/* Close */
+void ipcEmailSocket::Close()
+{
+ close(m_sockfd);
+ m_sockfd = 0;
+ m_bConnect = false;
+ EM_DEBUG_LOG("sockfd = [%d] is closed", m_sockfd);
+}
+
+void ipcEmailSocket::Close(int fd)
+{
+ EM_DEBUG_FUNC_BEGIN("fd [%d]",fd);
+
+ if (fd == -1) {
+ EM_DEBUG_LOG("server_socket not init");
+ return;
+ }
+
+ EM_DEBUG_LOG("%d to be removed", fd);
+ FD_CLR(fd, &fds);
+
+ std::map<int, int>::iterator it = mapFds.find(fd);
+ if(it == mapFds.end()) {
+ EM_DEBUG_LOG("No matching socket fd [%d]", fd);
+ return;
+ } else
+ mapFds.erase(it);
+
+ if ( fd == maxfd ) {
+ int newmax = 0;
+ for( it = mapFds.begin() ; it != mapFds.end() ; it++ )
+ newmax = (it->second > newmax )? it->second : newmax;
+ maxfd = newmax;
+ }
+ EM_DEBUG_LOG("fd %d removal done", fd);
+ ::close(fd);
+ EM_DEBUG_FUNC_END();
+}
+
+bool ipcEmailSocket::IsConnected()
+{
+ return m_bConnect;
+}
+
+int ipcEmailSocket::writen (int fd, const char *buf, int len)
+{
+ int nleft, nwrite;
+
+ nleft = len;
+ while( nleft > 0 ) {
+ nwrite = ::send(fd, (const void*) buf, nleft, MSG_NOSIGNAL);
+/* nwrite = ::write(fd, (const void*) buf, nleft); */
+ if( nwrite == -1 ) {
+ EM_DEBUG_LOG("write: %s", EM_STRERROR(errno));
+ if (errno == EINTR) continue;
+ return nwrite;
+ } else if ( nwrite == 0 )
+ break;
+
+ nleft -= nwrite;
+ buf += nwrite;
+ }
+ return (len-nleft);
+}
+
+int ipcEmailSocket::Send(int fd, char* buffer, int buf_len)
+{
+ EM_DEBUG_FUNC_BEGIN("fd [%d], buffer [%p], buf_len [%d]", fd, buffer, buf_len);
+
+ if( !buffer ) {
+ EM_DEBUG_EXCEPTION("No data to send");
+ return 0;
+ }
+
+ /*
+ if(!IsConnected()) {
+ EM_DEBUG_EXCEPTION("Socket is not connected.");
+ return FAILURE;
+ }
+ */
+
+ int send_bytes = sizeof(int)+buf_len;
+ char buf[send_bytes];
+ memcpy(buf, (char*) &buf_len, sizeof(int)); /* write buffer lenth */
+ memcpy(buf + sizeof(int), buffer, buf_len); /* write buffer */
+
+ EM_DEBUG_LOG("Sending %dB data to [fd = %d] ", send_bytes, fd);
+ int nRet = writen(fd, buf, send_bytes);
+
+ EM_DEBUG_FUNC_END();
+ return nRet;
+/*
+ EM_DEBUG_LOG("Sending %dB data to [fd = %d] ", buf_len, fd);
+ int n = writen(fd, buffer, buf_len);
+
+ if( n != buf_len ) {
+ EM_DEBUG_LOG("WARNING: write buf_size[%d] != send_len [%d]", n, buf_len);
+ return FAILURE;
+ }
+ EM_DEBUG_FUNC_END();
+ return n;
+*/
+}
+
+
+int ipcEmailSocket::readn( int fd, char *buf, int len )
+{
+ int nleft, nread;
+
+ nleft = len;
+ while( nleft > 0 ) {
+ nread = ::read(fd, (void*)buf, nleft);
+ if( nread < 0 ) {
+ EM_DEBUG_EXCEPTION("read: %s", strerror(errno));
+ if (errno == EINTR) continue;
+ return nread;
+ } else if( nread == 0 )
+ break;
+
+ nleft -= nread;
+ buf += nread;
+ }
+ return (len-nleft);
+}
+
+int ipcEmailSocket::Recv(int fd, char** buffer)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ if ( !buffer ) {
+ EM_DEBUG_LOG("buffer MUST NOT NULL");
+ return FAILURE;
+ }
+
+ /* read the data size first and store it to len */
+ int n, len = 0;
+
+ EM_DEBUG_LOG("[IPC Socket] Receiving header begins");
+ n = readn(fd, (char*) &len, sizeof(int));
+ EM_DEBUG_LOG("[IPC Socket] Receiving header %dB data", len);
+
+ if ( n == 0 ) /* if service gets down, it signals to all IPC clients */
+ return n; else if ( n != sizeof(int) ) {
+ EM_DEBUG_LOG("WARNING: read header_size[%d] not matched [%d]", n, sizeof(int));
+ return FAILURE;
+ }
+/* if( ioctl(fd, FIONREAD, &len) == -1 ) {
+ EM_DEBUG_LOG("FIONREAD %s", EM_STRERROR(errno));
+ return FAILURE;
+ }
+*/
+ /* alloc buffer and read data */
+ *buffer = new char[len];
+
+ EM_DEBUG_LOG("[IPC Socket] Receiving Body begins for [%d] bytes", len);
+ n = readn(fd, *buffer, len);
+ if ( n != len ) {
+ delete[] *buffer;
+ *buffer = NULL;
+ EM_DEBUG_LOG("WARNING: read buf_size [%d] != read_len[%d]", n, len);
+ return FAILURE;
+ }
+
+ EM_DEBUG_LOG("[IPC Socket] Receiving [%d] bytes Completed", len);
+
+ return n;
+}
+
+int ipcEmailSocket::GetSocketID()
+{
+ return m_sockfd;
+}
+
+
+int ipcEmailSocket::accept()
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ if (m_sockfd == -1) {
+ EM_DEBUG_LOG("server_socket not init");
+ return FAILURE;
+ }
+
+ struct sockaddr_un remote;
+
+ int t = sizeof(remote);
+ int fd = ::accept(m_sockfd, (struct sockaddr *)&remote, (socklen_t*) &t);
+ if (fd == -1) {
+ EM_DEBUG_LOG("accept: %s", EM_STRERROR(errno));
+ return FAILURE;
+ }
+
+ addfd(fd);
+ EM_DEBUG_LOG("%d is added", fd);
+
+ EM_DEBUG_FUNC_END();
+ return fd;
+}
+
+int ipcEmailSocket::open(const char* path)
+{
+ EM_DEBUG_FUNC_BEGIN("path [%s]", path);
+
+ if (!path || strlen(path) > 108) {
+ EM_DEBUG_LOG("path is null");
+ return FAILURE;
+ }
+
+ if ( m_sockfd <= 0 ) {
+ EM_DEBUG_LOG("Server_socket not created %d", m_sockfd);
+ return FAILURE;
+ }
+
+ struct sockaddr_un local;
+
+ local.sun_family = AF_UNIX;
+ strcpy(local.sun_path, path);
+ unlink(local.sun_path);
+
+ int len = strlen(local.sun_path) + sizeof(local.sun_family);
+
+ if (bind(m_sockfd, (struct sockaddr *)&local, len) == -1) {
+ EM_DEBUG_LOG("bind: %s", strerror(errno));
+ return FAILURE;
+ }
+
+ /**
+ * determine permission of socket file
+ *
+ * - S_IRWXU : for user, allow read and write and execute
+ * - S_IRWXG : for group, allow read and write and execute
+ * - S_IRWXO : for other, allow read and write and execute
+ *
+ * - S_IRUSR, S_IWUSR, S_IXUSR : for user, allow only read, write, execute respectively
+ * - S_IRGRP, S_IWGRP, S_IXGRP : for group, allow only read, write, execute respectively
+ * - S_IROTH, S_IWOTH, S_IXOTH : for other, allow only read, write, execute respectively
+ */
+ mode_t sock_mode = (S_IRWXU | S_IRWXG | S_IRWXO); /* has 777 permission */
+
+ if (chmod(path, sock_mode) == -1) {
+ EM_DEBUG_LOG("chmod: %s", strerror(errno));
+ return FAILURE;
+ }
+
+ if (listen(m_sockfd, 10) == -1) {
+ EM_DEBUG_LOG("listen: %s", strerror(errno));
+ return FAILURE;
+ }
+
+ addfd(m_sockfd);
+
+ EM_DEBUG_FUNC_END();
+ return 0;
+}
+
+
+int ipcEmailSocket::Connect()
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ struct sockaddr_un serverSA;
+ serverSA.sun_family = AF_UNIX;
+ strcpy(serverSA.sun_path, EM_SOCKET_PATH); /* "./socket" */
+
+ int len = strlen(serverSA.sun_path) + sizeof(serverSA.sun_family);
+
+ if (::connect(m_sockfd, (struct sockaddr *)&serverSA, len) == -1) {
+ EM_DEBUG_LOG("cannot connect server %s", strerror(errno));
+ return FAILURE;
+ }
+
+ /* add fd for select() */
+ addfd(m_sockfd);
+ m_bConnect = true;
+
+ return 0;
+}
+
+void ipcEmailSocket::addfd(int fd)
+{
+ EM_DEBUG_LOG("%d added", fd);
+ FD_SET(fd, &fds);
+
+ std::map<int, int>::iterator it = mapFds.find(fd);
+ if(it != mapFds.end()) {
+ EM_DEBUG_LOG("Duplicate FD %d", fd);
+ return;
+ } else
+ mapFds[fd] = fd;
+
+ if ( fd > maxfd )
+ maxfd = fd;
+}
+
+
diff --git a/ipc/stub/include/ipc-queue.h b/ipc/stub/include/ipc-queue.h
new file mode 100755
index 0000000..f51a51a
--- /dev/null
+++ b/ipc/stub/include/ipc-queue.h
@@ -0,0 +1,64 @@
+/*
+* email-service
+*
+* Copyright (c) 2000 - 2011 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.
+*
+*/
+
+
+
+#ifndef _IPC_QUEUE_H_
+#define _IPC_QUEUE_H_
+
+class ipcEmailQueueItem
+{
+public:
+ ipcEmailQueueItem();
+ ipcEmailQueueItem(void* a_pData);
+ virtual ~ipcEmailQueueItem();
+
+private:
+public:
+ void* m_pData;
+ ipcEmailQueueItem* m_pNext;
+
+public:
+ void* Get();
+ void Set(void* a_pData);
+};
+
+class ipcEmailQueue
+{
+public:
+ ipcEmailQueue();
+ virtual ~ipcEmailQueue();
+
+private:
+ ipcEmailQueueItem* m_pHead;
+ ipcEmailQueueItem* m_pTail;
+ int m_nCount;
+
+public:
+ void* Pop();
+ bool Push(void* a_pData);
+
+ int GetCount();
+};
+
+#endif /* _IPC_QUEUE_H_ */
+
+
diff --git a/ipc/stub/include/ipc-response-info.h b/ipc/stub/include/ipc-response-info.h
new file mode 100755
index 0000000..2b876a4
--- /dev/null
+++ b/ipc/stub/include/ipc-response-info.h
@@ -0,0 +1,46 @@
+/*
+* email-service
+*
+* Copyright (c) 2000 - 2011 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.
+*
+*/
+
+
+
+#ifndef _IPC_RESPONSE_INFO_H_
+#define _IPC_RESPONSE_INFO_H_
+
+class ipcEmailResponseInfo
+{
+public:
+ ipcEmailResponseInfo();
+ virtual ~ipcEmailResponseInfo();
+
+private:
+ long m_nResponseID;
+ long m_nAPIID;
+
+public:
+ bool SetVaue(long a_nResponseID, long a_nAPIID);
+ long GetResponseID();
+ long GetAPIID();
+
+};
+
+#endif /* _IPC_RESPONSE_INFO_H_ */
+
+
diff --git a/ipc/stub/include/ipc-stub-main.h b/ipc/stub/include/ipc-stub-main.h
new file mode 100755
index 0000000..7596358
--- /dev/null
+++ b/ipc/stub/include/ipc-stub-main.h
@@ -0,0 +1,61 @@
+/*
+* email-service
+*
+* Copyright (c) 2000 - 2011 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.
+*
+*/
+
+
+
+#ifndef _IPC_STUB_MAIN_H_
+#define _IPC_STUB_MAIN_H_
+
+#include "ipc-library.h"
+#include "cm-sys-msg-queue.h"
+#include "cm-list.h"
+#include "ipc-stub-socket.h"
+
+class ipcEmailAPIInfo;
+
+class ipcEmailStubMain
+{
+public:
+ ipcEmailStubMain();
+ virtual ~ipcEmailStubMain();
+
+private:
+ static ipcEmailStubMain *s_pThis;
+ PFN_EXECUTE_API m_pfnAPIMapper;
+ ipcEmailStubSocket* m_pStubSocket;
+
+ cmSysMsgQueue *m_pMsgSender;
+ cmList *m_pResponseList;
+public:
+ static ipcEmailStubMain* Instance();
+ static void FreeInstance();
+
+ bool Initialize(PFN_EXECUTE_API a_pfnAPIMapper);
+ bool Finalize();
+
+ bool ExecuteAPIProxyToStub(ipcEmailAPIInfo *a_pAPI);
+ bool ExecuteAPIStubToProxy(ipcEmailAPIInfo *a_pAPI);
+ bool SetResponseInfo(long a_nResponseID, long a_nAPIID);
+};
+
+#endif /* _IPC_STUB_MAIN_H_ */
+
+
diff --git a/ipc/stub/include/ipc-stub-socket.h b/ipc/stub/include/ipc-stub-socket.h
new file mode 100755
index 0000000..7eade99
--- /dev/null
+++ b/ipc/stub/include/ipc-stub-socket.h
@@ -0,0 +1,60 @@
+/*
+* email-service
+*
+* Copyright (c) 2000 - 2011 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.
+*
+*/
+
+
+
+#ifndef _IPC_STUB_SOCKET_H_
+#define _IPC_STUB_SOCKET_H_
+
+#include <pthread.h>
+#include "ipc-library.h"
+#include "ipc-socket.h"
+#include "ipc-task-manager.h"
+
+
+class ipcEmailStubSocket
+{
+public:
+ ipcEmailStubSocket();
+ virtual ~ipcEmailStubSocket();
+ bool Start();
+ bool End();
+ int Send(int fd, void* pData , int a_nLen);
+ void WaitForIPCRequest();
+
+private:
+ bool StartStubSocketThread();
+ bool StopStubSocketThread();
+ static void* StubSocketThreadProc(void *a_pOwner);
+
+
+private:
+ ipcEmailSocket *m_pSocket;
+ pthread_t m_hStubSocketThread;
+ bool m_bStopThread;
+
+ ipcEmailTaskManager *m_pTaskManager;
+
+};
+
+#endif /* _IPC_STUB_SOCKET_H_ */
+
+
diff --git a/ipc/stub/include/ipc-task-manager.h b/ipc/stub/include/ipc-task-manager.h
new file mode 100755
index 0000000..15e7e63
--- /dev/null
+++ b/ipc/stub/include/ipc-task-manager.h
@@ -0,0 +1,60 @@
+/*
+* email-service
+*
+* Copyright (c) 2000 - 2011 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.
+*
+*/
+
+
+#ifndef _IPC_TASK_MANAGER_H_
+#define _IPC_TASK_MANAGER_H_
+
+#include <unistd.h>
+#include <pthread.h>
+#include "ipc-task.h"
+#include "ipc-queue.h"
+#include "emf-mutex.h"
+
+#define IPC_TASK_MAX 64
+
+
+class ipcEmailTaskManager
+{
+public:
+ ipcEmailTaskManager();
+ virtual ~ipcEmailTaskManager();
+
+private:
+ ipcEmailQueue m_TaskQueue;
+ pthread_t m_hTaskThread;
+ bool m_bStopFlag;
+ Mutex mx;
+ CndVar cv;
+
+public:
+ bool StartTaskThread();
+ bool StopTaskThread();
+
+ bool CreateTask(unsigned char* a_pTaskStream, int a_nResponseChannel);
+ bool DoTask();
+private:
+ static void* TaskThreadProc(void *a_pOwner);
+};
+
+#endif /* _IPC_TASK_MANAGER_H_ */
+
+
diff --git a/ipc/stub/include/ipc-task.h b/ipc/stub/include/ipc-task.h
new file mode 100755
index 0000000..e12357d
--- /dev/null
+++ b/ipc/stub/include/ipc-task.h
@@ -0,0 +1,49 @@
+/*
+* email-service
+*
+* Copyright (c) 2000 - 2011 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.
+*
+*/
+
+
+#ifndef _IPC_TASK_H_
+#define _IPC_TASK_H_
+
+#include "ipc-api-info.h"
+
+class ipcEmailTask
+{
+public:
+ ipcEmailTask();
+ virtual ~ipcEmailTask();
+
+private:
+ ipcEmailAPIInfo *m_pAPIInfo;
+ int m_nResponseChannel;
+
+public:
+ bool Run();
+
+ bool ParseStream(void* a_pStream, int nResponseFD);
+
+ ipcEmailAPIInfo* GetAPIInfo();
+ int GetResponseChannel();
+};
+
+#endif /* _IPC_TASK_H */
+
+
diff --git a/ipc/stub/ipc-queue.cpp b/ipc/stub/ipc-queue.cpp
new file mode 100755
index 0000000..490c904
--- /dev/null
+++ b/ipc/stub/ipc-queue.cpp
@@ -0,0 +1,114 @@
+/*
+* email-service
+*
+* Copyright (c) 2000 - 2011 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.
+*
+*/
+
+
+#include <stdio.h>
+#include "ipc-queue.h"
+#include "ipc-library-build.h"
+#include "emf-dbglog.h"
+
+ipcEmailQueue::ipcEmailQueue()
+{
+ m_pHead = NULL;
+ m_pTail = NULL;
+ m_nCount = 0;
+}
+
+ipcEmailQueue::~ipcEmailQueue()
+{
+}
+
+void* ipcEmailQueue::Pop()
+{
+ if(m_pHead) {
+ ipcEmailQueueItem *pPopped = m_pHead;
+ void* pData = pPopped->Get();
+
+ if(pPopped->m_pNext) {
+ m_pHead = pPopped->m_pNext;
+ } else {
+ m_pHead = m_pTail = NULL;
+ }
+
+ delete pPopped;
+ pPopped = NULL;
+ m_nCount = (m_nCount <= 0)? 0 : m_nCount-1;
+
+ return pData;
+ }
+ return NULL;
+}
+
+bool ipcEmailQueue::Push(void* a_pData)
+{
+ /* EM_DEBUG_FUNC_BEGIN(); */
+ if(!a_pData) {
+ EM_DEBUG_EXCEPTION("[IPCLib] ipcEmailQueue::Push - invalid input \n");
+ return false;
+ }
+
+ ipcEmailQueueItem *pItem = new ipcEmailQueueItem(a_pData);
+ if(m_pTail) {
+ m_pTail->m_pNext = pItem;
+ m_pTail = pItem;
+ } else {
+ m_pHead = m_pTail = pItem;
+ }
+
+ m_nCount++;
+ pItem->m_pNext = NULL;
+ return true;
+}
+
+int ipcEmailQueue::GetCount()
+{
+ return m_nCount;
+}
+
+
+
+
+ipcEmailQueueItem::ipcEmailQueueItem()
+{
+ m_pData = NULL;
+ m_pNext = NULL;
+}
+
+ipcEmailQueueItem::ipcEmailQueueItem(void* a_pData)
+{
+ m_pData = a_pData;
+ m_pNext = NULL;
+}
+
+ipcEmailQueueItem::~ipcEmailQueueItem()
+{
+}
+
+void* ipcEmailQueueItem::Get()
+{
+ return m_pData;
+}
+
+void ipcEmailQueueItem::Set(void* a_pData)
+{
+ m_pData = a_pData;
+}
+
diff --git a/ipc/stub/ipc-response-info.cpp b/ipc/stub/ipc-response-info.cpp
new file mode 100755
index 0000000..f181e75
--- /dev/null
+++ b/ipc/stub/ipc-response-info.cpp
@@ -0,0 +1,52 @@
+/*
+* email-service
+*
+* Copyright (c) 2000 - 2011 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.
+*
+*/
+
+#include "ipc-response-info.h"
+
+ipcEmailResponseInfo::ipcEmailResponseInfo()
+{
+ m_nResponseID = 0;
+ m_nAPIID = 0;
+}
+
+ipcEmailResponseInfo::~ipcEmailResponseInfo()
+{
+}
+
+bool ipcEmailResponseInfo::SetVaue(long a_nResponseID, long a_nAPIID)
+{
+ m_nResponseID = a_nResponseID;
+ m_nAPIID = a_nAPIID;
+ return true;
+}
+
+long ipcEmailResponseInfo::GetResponseID()
+{
+ return m_nResponseID;
+}
+
+
+long ipcEmailResponseInfo::GetAPIID()
+{
+ return m_nAPIID;
+}
+
+
diff --git a/ipc/stub/ipc-stub-main.cpp b/ipc/stub/ipc-stub-main.cpp
new file mode 100755
index 0000000..454e6a0
--- /dev/null
+++ b/ipc/stub/ipc-stub-main.cpp
@@ -0,0 +1,191 @@
+/*
+* email-service
+*
+* Copyright (c) 2000 - 2011 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.
+*
+*/
+
+
+
+#include "ipc-stub-main.h"
+#include "ipc-library.h"
+#include "ipc-response-info.h"
+#include "ipc-param-list.h"
+#include "ipc-library-build.h"
+
+
+ipcEmailStubMain* ipcEmailStubMain::s_pThis = NULL;
+
+ipcEmailStubMain::ipcEmailStubMain()
+{
+ EM_DEBUG_FUNC_BEGIN();
+ m_pfnAPIMapper = NULL;
+ m_pStubSocket = NULL;
+ m_pMsgSender = NULL;
+ m_pResponseList = NULL;
+ EM_DEBUG_FUNC_END();
+}
+
+ipcEmailStubMain::~ipcEmailStubMain()
+{
+ EM_DEBUG_FUNC_BEGIN();
+ Finalize();
+ EM_DEBUG_FUNC_END();
+}
+
+
+ipcEmailStubMain* ipcEmailStubMain::Instance()
+{
+ EM_DEBUG_FUNC_BEGIN();
+ if(s_pThis)
+ return s_pThis;
+
+ s_pThis = new ipcEmailStubMain();
+ EM_DEBUG_FUNC_END();
+ return s_pThis;
+}
+
+void ipcEmailStubMain::FreeInstance()
+{
+ EM_DEBUG_FUNC_BEGIN();
+ if(s_pThis) {
+ delete s_pThis;
+ s_pThis = NULL;
+ }
+ EM_DEBUG_FUNC_END();
+}
+
+bool ipcEmailStubMain::Initialize(PFN_EXECUTE_API a_pfnAPIMapper)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ m_pfnAPIMapper = a_pfnAPIMapper;
+
+ if(!a_pfnAPIMapper || m_pStubSocket) {
+ EM_DEBUG_EXCEPTION("Invalid Param");
+ return false;
+ }
+
+ m_pfnAPIMapper = a_pfnAPIMapper;
+
+ m_pResponseList = new cmList();
+ if(!m_pResponseList) {
+ EM_DEBUG_EXCEPTION("m_pResponseList == NULL\n");
+ return false;
+ }
+
+ m_pMsgSender = new cmSysMsgQueue(0);
+ if(!m_pMsgSender) {
+ EM_DEBUG_EXCEPTION("m_pMsgSender == NULL\n");
+ return false;
+ }
+ m_pMsgSender->MsgCreate();
+
+ m_pStubSocket = new ipcEmailStubSocket;
+
+ if(m_pStubSocket) {
+ return m_pStubSocket->Start();
+ } else {
+ EM_DEBUG_EXCEPTION("m_pStubSocket == NULL\n");
+ return false;
+ }
+ EM_DEBUG_FUNC_END();
+ return false;
+}
+
+bool ipcEmailStubMain::Finalize()
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ if(m_pResponseList) {
+ int nIndex;
+ for(nIndex = 0; nIndex<m_pResponseList->GetCount(); nIndex++) {
+ ipcEmailResponseInfo *pResponseInfo = (ipcEmailResponseInfo *)m_pResponseList->GetAt(nIndex);
+ if(pResponseInfo)
+ m_pResponseList->RemoveItem(pResponseInfo);
+ }
+ delete m_pResponseList;
+ }
+ if(m_pMsgSender) {
+ m_pMsgSender->MsgDestroy();
+ m_pMsgSender = NULL;
+ }
+
+ if(m_pStubSocket) {
+ m_pStubSocket->End();
+ delete m_pStubSocket;
+ m_pStubSocket = NULL;
+ }
+
+ if(m_pfnAPIMapper)
+ m_pfnAPIMapper = NULL;
+
+ EM_DEBUG_FUNC_END();
+ return true;
+}
+
+bool ipcEmailStubMain::ExecuteAPIProxyToStub(ipcEmailAPIInfo *a_pAPI)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ if(!m_pfnAPIMapper || !a_pAPI) {
+ EM_DEBUG_EXCEPTION("Invalid Param");
+ return false;
+ }
+
+ m_pfnAPIMapper(a_pAPI);
+ EM_DEBUG_FUNC_END();
+ return true;
+}
+
+bool ipcEmailStubMain::ExecuteAPIStubToProxy(ipcEmailAPIInfo *a_pAPI)
+{
+ EM_DEBUG_FUNC_BEGIN("a_pAPI [%p]", a_pAPI);
+ EM_IF_NULL_RETURN_VALUE(a_pAPI, false);
+ EM_DEBUG_LOG("APIID [%s], Response SockID [%d], APPID [%d]", EM_APIID_TO_STR(a_pAPI->GetAPIID()), a_pAPI->GetResponseID(), a_pAPI->GetAPPID());
+
+ unsigned char* pStream = (unsigned char*)a_pAPI->GetStream(ePARAMETER_OUT);
+ int nStreamLength = a_pAPI->GetStreamLength(ePARAMETER_OUT);
+ EM_DEBUG_LOG("Data : %p, Data length : %dB",pStream, nStreamLength);
+ EM_DEBUG_LOG("Stub => Proxy Sending %dB", nStreamLength);
+ m_pStubSocket->Send(a_pAPI->GetResponseID(), pStream, nStreamLength);
+
+#ifdef IPCLIB_STREAM_TRACE_ON
+ int nIndex;
+ for(nIndex=0; nIndex< nStreamLength; nIndex++)
+ EM_DEBUG_LOG("pStream[nIndex] :[%d]", pStream[nIndex]);
+#endif
+
+ EM_DEBUG_FUNC_END();
+ return true;
+}
+
+bool ipcEmailStubMain::SetResponseInfo( long a_nAPPID, long a_nAPIID)
+{
+ EM_DEBUG_FUNC_BEGIN("ResponseID [%d]", a_nAPPID);
+
+ if(a_nAPPID <= 0)
+ return true;
+
+ ipcEmailResponseInfo *pResponseInfo = new ipcEmailResponseInfo();
+ if(pResponseInfo) {
+ pResponseInfo->SetVaue(a_nAPPID, a_nAPIID);
+ m_pResponseList->AddTail(pResponseInfo);
+ return true;
+ }
+ EM_DEBUG_FUNC_END();
+ return false;
+}
+
diff --git a/ipc/stub/ipc-stub-socket.cpp b/ipc/stub/ipc-stub-socket.cpp
new file mode 100755
index 0000000..9244419
--- /dev/null
+++ b/ipc/stub/ipc-stub-socket.cpp
@@ -0,0 +1,208 @@
+/*
+* email-service
+*
+* Copyright (c) 2000 - 2011 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.
+*
+*/
+
+
+
+
+#include <unistd.h>
+#include "ipc-task.h"
+#include "ipc-library-build.h"
+#include "emf-dbglog.h"
+#include "ipc-stub-socket.h"
+#include <errno.h>
+#include <sys/epoll.h>
+
+ipcEmailStubSocket::ipcEmailStubSocket()
+{
+ m_pSocket = NULL;
+ m_hStubSocketThread = 0;
+ m_pTaskManager = NULL;
+ m_bStopThread = false;
+}
+
+ipcEmailStubSocket::~ipcEmailStubSocket()
+{
+ End();
+}
+
+bool ipcEmailStubSocket::Start()
+{
+ m_pTaskManager = new ipcEmailTaskManager();
+ if(m_pTaskManager == NULL)
+ return false;
+
+ m_pSocket = new ipcEmailSocket();
+ if( m_pSocket == NULL )
+ return false;
+
+ if( m_pSocket ) {
+ StartStubSocketThread();
+ }
+
+ return m_pTaskManager->StartTaskThread();
+}
+
+/* stub socket accpet, recv, send */
+bool ipcEmailStubSocket::StartStubSocketThread()
+{
+ EM_DEBUG_LOG("[IPCLib] ipcEmailStubSocket::StartStubSocketThread \n");
+ if(m_hStubSocketThread)
+ return true;
+
+ pthread_attr_t thread_attr;
+ pthread_attr_init(&thread_attr);
+ pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_DETACHED);
+ if (pthread_create(&m_hStubSocketThread, &thread_attr, &StubSocketThreadProc, (void*)this) != 0) {
+ EM_DEBUG_EXCEPTION("[IPCLib] ipcEmailStubSocket::StartStubSocketThread() - fail to create a thread \n");
+ return false;
+ }
+ return true;
+
+}
+
+bool ipcEmailStubSocket::StopStubSocketThread()
+{
+ if(m_hStubSocketThread)
+ m_bStopThread = true;
+
+ return true;
+}
+
+void* ipcEmailStubSocket::StubSocketThreadProc(void *a_pOwner)
+{
+ ipcEmailStubSocket *pStubSocket = (ipcEmailStubSocket*)a_pOwner;
+ if(pStubSocket) {
+ pStubSocket->WaitForIPCRequest();
+ pStubSocket->m_hStubSocketThread = 0; /* prevent 20071030 */
+ }
+ return NULL;
+}
+
+#define MAX_EPOLL_EVENT 50
+
+void ipcEmailStubSocket::WaitForIPCRequest()
+{
+ if ( !m_pSocket ) {
+ EM_DEBUG_EXCEPTION("server socket is not initialized");
+ return;
+ }
+
+ m_pSocket->open(EM_SOCKET_PATH);
+
+ struct epoll_event ev = {0};
+ struct epoll_event events[MAX_EPOLL_EVENT] = {{0}, };
+ int epfd = epoll_create(MAX_EPOLL_EVENT);
+ if( epfd < 0 ) {
+ EM_DEBUG_EXCEPTION("epoll_create: %s[%d]", EM_STRERROR(errno), errno);
+ EM_DEBUG_CRITICAL_EXCEPTION("epoll_create: %s[%d]", EM_STRERROR(errno), errno);
+ abort();
+ }
+ int server_fd = m_pSocket->GetSocketID();
+ ev.events = EPOLLIN;
+ ev.data.fd = server_fd;
+ if( epoll_ctl(epfd, EPOLL_CTL_ADD, server_fd, &ev) == -1 ) {
+ EM_DEBUG_EXCEPTION("epoll_ctl: %s[%d]", EM_STRERROR(errno), errno);
+ EM_DEBUG_CRITICAL_EXCEPTION("epoll_ctl: %s[%d]", EM_STRERROR(errno), errno);
+ }
+
+ int event_num = 0;
+ while(1){
+
+ event_num = epoll_wait(epfd, events, MAX_EPOLL_EVENT, -1);
+
+ if( event_num == -1 ) {
+ EM_DEBUG_EXCEPTION("epoll_wait: %s[%d]", EM_STRERROR(errno), errno);
+ EM_DEBUG_CRITICAL_EXCEPTION("epoll_wait: %s[%d]", EM_STRERROR(errno), errno);
+ if (errno == EINTR) continue; /* resume when interrupted system call*/
+ else abort();
+ } else
+ for (int i=0 ; i < event_num; i++) {
+ int event_fd = events[i].data.fd;
+
+ if (event_fd == server_fd) { /* if it is socket connection request */
+ int cfd = m_pSocket->accept();
+ if( cfd < 0 ) {
+ EM_DEBUG_EXCEPTION("accept error: %s[%d]", EM_STRERROR(errno), errno);
+ EM_DEBUG_CRITICAL_EXCEPTION("accept error: %s[%d]", EM_STRERROR(errno), errno);
+ /* abort(); */
+ }
+ ev.events = EPOLLIN;
+ ev.data.fd = cfd;
+ epoll_ctl(epfd, EPOLL_CTL_ADD, cfd, &ev);
+ } else {
+ int nRecvLen;
+ char *szBuff = NULL;
+
+ nRecvLen = m_pSocket->Recv(event_fd, &szBuff);
+
+ if(nRecvLen > 0) {
+ EM_DEBUG_LOG("====================================================================");
+ EM_DEBUG_LOG("[IPCLib]Stub Socket Recv [Socket ID = %d], [RecvLen = %d]", event_fd, nRecvLen);
+ EM_DEBUG_LOG("====================================================================");
+ m_pTaskManager->CreateTask((unsigned char*)szBuff, event_fd);
+ } else {
+ EM_DEBUG_LOG("[IPCLib] Socket [%d] removed - [%d] ", event_fd, nRecvLen);
+ epoll_ctl(epfd, EPOLL_CTL_DEL, event_fd, events);
+ close(event_fd);
+ }
+ if(szBuff)
+ delete []szBuff;
+ }
+ }
+ }
+}
+
+
+bool ipcEmailStubSocket::End()
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ if(m_pSocket) {
+ m_pSocket->Close(); /* prevent 20071030 */
+ delete m_pSocket;
+ m_pSocket = NULL;
+ }
+
+ if(m_hStubSocketThread) {
+ StopStubSocketThread();
+ pthread_cancel(m_hStubSocketThread);
+ m_hStubSocketThread = 0;
+ }
+ if(m_pTaskManager) {
+ m_pTaskManager->StopTaskThread();
+ delete m_pTaskManager;
+ m_pTaskManager = NULL;
+ }
+
+ return true;
+}
+
+int ipcEmailStubSocket::Send(int fd, void* pData , int a_nLen)
+{
+ EM_DEBUG_FUNC_END();
+
+ EM_DEBUG_LOG("Stub socket sending %d bytes", a_nLen);
+ int sending_bytes = m_pSocket->Send(fd, (char*)pData, a_nLen);
+
+ EM_DEBUG_FUNC_END();
+ return sending_bytes;
+}
+
diff --git a/ipc/stub/ipc-task-manager.cpp b/ipc/stub/ipc-task-manager.cpp
new file mode 100755
index 0000000..bca67c0
--- /dev/null
+++ b/ipc/stub/ipc-task-manager.cpp
@@ -0,0 +1,171 @@
+/*
+* email-service
+*
+* Copyright (c) 2000 - 2011 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.
+*
+*/
+
+
+
+#include <string.h>
+#include "ipc-task-manager.h"
+#include "ipc-task.h"
+#include "ipc-library-build.h"
+#include "emf-dbglog.h"
+#include <pthread.h>
+#include <errno.h>
+
+pthread_cond_t email_task_queue_signal;
+pthread_mutex_t email_task_queue_lock;
+
+
+/*
+void* worker_func(void *a_pOwner)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ ipcEmailTaskManager *pTaskManager = (ipcEmailTaskManager*) a_pOwner;
+ if(pTaskManager) {
+ pTaskManager->DoTask();
+ }
+ return NULL;
+}
+*/
+ipcEmailTaskManager::ipcEmailTaskManager() : m_TaskQueue(), m_hTaskThread(0), m_bStopFlag(false), mx(), cv()
+{
+}
+
+ipcEmailTaskManager::~ipcEmailTaskManager()
+{
+ StopTaskThread();
+ pthread_cancel(m_hTaskThread);
+
+ ipcEmailTask* pTask = (ipcEmailTask*)m_TaskQueue.Pop();
+ while(pTask) {
+ delete pTask;
+ pTask = (ipcEmailTask*)m_TaskQueue.Pop();
+ }
+}
+
+bool ipcEmailTaskManager::StartTaskThread()
+{
+ EM_DEBUG_FUNC_BEGIN();
+ if(m_hTaskThread)
+ return true;
+/*
+ pthread_attr_t thread_attr;
+ pthread_attr_init(&thread_attr);
+ pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_DETACHED);
+
+ if (pthread_create(&m_hTaskThread, &thread_attr, &TaskThreadProc, (void*)this) != 0)
+*/
+ if (pthread_create(&m_hTaskThread, NULL, &TaskThreadProc, (void*)this) != 0) {
+ EM_DEBUG_LOG("Worker thread creation failed: %s", strerror(errno));
+ return false;
+ }
+
+ return true;
+}
+
+bool ipcEmailTaskManager::StopTaskThread()
+{
+ m_bStopFlag = true;
+ return true;
+}
+
+void* ipcEmailTaskManager::TaskThreadProc(void *a_pOwner)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ ipcEmailTaskManager *pTaskManager = (ipcEmailTaskManager*)a_pOwner;
+ if(pTaskManager) {
+ pTaskManager->DoTask();
+ }
+ return NULL;
+}
+
+
+/* important! m_TaskQueue is shared by worker thread and ipc handler thread */
+/* code for worker thread */
+bool ipcEmailTaskManager::DoTask()
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ ipcEmailTask *pTask = NULL;
+
+ while(!m_bStopFlag) {
+
+ mx.lock();
+ while(m_TaskQueue.GetCount() == 0) {
+ EM_DEBUG_LOG("Blocked until new task arrives %p.", &cv);
+ cv.wait(mx.pMutex());
+ }
+
+ pTask = (ipcEmailTask*)m_TaskQueue.Pop();
+ mx.unlock();
+
+ if(pTask) {
+ pTask->Run();
+ delete pTask;
+ pTask = NULL;
+ }
+ }
+
+ return false;
+}
+
+/* code for ipc handler */
+bool ipcEmailTaskManager::CreateTask(unsigned char* a_pTaskStream, int a_nResponseChannel)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+/* pthread_mutex_init(&email_task_queue_lock, NULL); */
+/* pthread_cond_init(&email_task_queue_signal, NULL); */
+
+/*
+ if(!m_hTaskThread) {
+ if (pthread_create(&m_hTaskThread, NULL, &worker_func, (void*)this) != 0) {
+ EM_DEBUG_LOG("Worker thread creation failed: %s", strerror(errno));
+ return false;
+ }
+ EM_DEBUG_LOG("* Worker thread now running *");
+ }
+*/
+ ipcEmailTask *pTask = new ipcEmailTask();
+ if(pTask) {
+ pTask->ParseStream(a_pTaskStream, a_nResponseChannel);
+
+ EM_DEBUG_LOG("[IPCLib] ====================================================");
+ EM_DEBUG_LOG("[IPCLib] Register new task : %p", pTask);
+ EM_DEBUG_LOG("[IPCLib] Task API ID : %s", EM_APIID_TO_STR(pTask->GetAPIInfo()->GetAPIID()));
+ EM_DEBUG_LOG("[IPCLib] Task Response ID : %d", pTask->GetAPIInfo()->GetResponseID());
+ EM_DEBUG_LOG("[IPCLib] Task APP ID : %d", pTask->GetAPIInfo()->GetAPPID());
+ EM_DEBUG_LOG("[IPCLib] ====================================================");
+
+ mx.lock();
+ bool bRtn = m_TaskQueue.Push(pTask);
+
+ int err = cv.signal();
+ if(err)
+ EM_DEBUG_LOG("cv wakeup error: %s", strerror(errno));
+
+ mx.unlock();
+
+ return bRtn;
+ }
+ return false;
+}
+
+
diff --git a/ipc/stub/ipc-task.cpp b/ipc/stub/ipc-task.cpp
new file mode 100755
index 0000000..cabf04a
--- /dev/null
+++ b/ipc/stub/ipc-task.cpp
@@ -0,0 +1,88 @@
+/*
+* email-service
+*
+* Copyright (c) 2000 - 2011 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.
+*
+*/
+
+
+
+#include <sys/socket.h>
+#include "ipc-library.h"
+#include "ipc-task.h"
+#include "ipc-stub-main.h"
+#include "ipc-param-list.h"
+#include "ipc-library-build.h"
+
+ipcEmailTask::ipcEmailTask()
+{
+ EM_DEBUG_FUNC_BEGIN();
+ m_nResponseChannel = 0;
+ m_pAPIInfo = NULL;
+ EM_DEBUG_LOG("pcTask::ipcEmailTask() ");
+}
+
+ipcEmailTask::~ipcEmailTask()
+{
+ EM_DEBUG_FUNC_BEGIN();
+ if(m_pAPIInfo) {
+ delete m_pAPIInfo;
+ m_pAPIInfo = NULL;
+ }
+}
+
+bool ipcEmailTask::ParseStream(void* a_pStream, int a_nResponseID)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ if(m_pAPIInfo)
+ delete m_pAPIInfo;
+
+ m_pAPIInfo = new ipcEmailAPIInfo();
+
+ if(m_pAPIInfo) {
+ m_pAPIInfo->ParseStream(ePARAMETER_IN, a_pStream);
+ m_pAPIInfo->SetResponseID(a_nResponseID);
+ return true;
+ }
+ return false;
+}
+
+ipcEmailAPIInfo *ipcEmailTask::GetAPIInfo()
+{
+ return m_pAPIInfo;
+}
+
+int ipcEmailTask::GetResponseChannel()
+{
+ return m_nResponseChannel;
+}
+
+bool ipcEmailTask::Run()
+{
+ EM_DEBUG_LOG("[IPCLib] Starting a new task...");
+
+ int nAPPID = m_pAPIInfo->GetAPPID();
+ if(nAPPID > 0) /* If the call is for async, APP ID is passed. */ { /* It means this call is for async, response ID set. */
+ EM_DEBUG_LOG("[IPCLib] This task (%s) is for async. Response ID [%d]", EM_APIID_TO_STR(m_pAPIInfo->GetAPIID()), m_pAPIInfo->GetAPIID());
+ ipcEmailStubMain::Instance()->SetResponseInfo(nAPPID, m_pAPIInfo->GetAPIID());
+ }
+
+ return ipcEmailStubMain::Instance()->ExecuteAPIProxyToStub(m_pAPIInfo);
+
+}
+
+
diff --git a/packaging/email-service.spec b/packaging/email-service.spec
new file mode 100644
index 0000000..c6d50b8
--- /dev/null
+++ b/packaging/email-service.spec
@@ -0,0 +1,574 @@
+Name: email-service
+Summary: E-mail Framework Middleware package
+Version: 0.2.9
+Release: 3
+Group: System/Libraries
+License: TBD
+Source0: %{name}-%{version}.tar.gz
+Requires(post): /sbin/ldconfig
+Requires(post): /usr/bin/sqlite3
+Requires(post): /usr/bin/vconftool
+Requires(postun): /sbin/ldconfig
+BuildRequires: cmake
+BuildRequires: pkgconfig(glib-2.0)
+BuildRequires: pkgconfig(gthread-2.0)
+BuildRequires: pkgconfig(aul)
+BuildRequires: pkgconfig(vconf)
+BuildRequires: pkgconfig(heynoti)
+BuildRequires: pkgconfig(dlog)
+BuildRequires: pkgconfig(db-util)
+BuildRequires: pkgconfig(dnet)
+BuildRequires: pkgconfig(dbus-1)
+BuildRequires: pkgconfig(dbus-glib-1)
+BuildRequires: pkgconfig(contacts-service)
+BuildRequires: pkgconfig(uw-imap-toolkit)
+BuildRequires: pkgconfig(drm-service)
+BuildRequires: pkgconfig(openssl)
+BuildRequires: pkgconfig(alarm-service)
+BuildRequires: pkgconfig(mm-player)
+BuildRequires: pkgconfig(devman_haptic)
+BuildRequires: pkgconfig(secure-storage)
+BuildRequires: pkgconfig(quickpanel)
+BuildRequires: pkgconfig(notification)
+BuildRequires: pkgconfig(accounts-svc)
+BuildRequires: pkgconfig(libcurl)
+
+
+BuildRoot: %{_tmppath}/%{name}-%{version}-build
+
+%description
+E-mail Framework Middleware Library/Binary package
+
+
+%package devel
+Summary: E-mail Framework Middleware Development package
+Group: Development/Libraries
+Requires: %{name} = %{version}-%{release}
+
+%description devel
+E-mail Framework Middleware Development package
+
+
+%package tools
+Summary: Tools for use with email-service
+Group: Development/Libraries
+Requires: %{name} = %{version}-%{release}
+
+%description tools
+Tools for use with email-service
+
+
+%prep
+%setup -q
+
+%build
+
+export CFLAGS="${CFLAGS} -fPIC -Wall -g -fvisibility=hidden"
+export CXXFLAGS="${CXXFLAGS} -fPIC -Wall -g -fvisibility=hidden"
+export LDFLAGS="${LDFLAGS} -Wl,--hash-style=both -Wl,--rpath=%{_prefix}/lib -Wl,--as-needed"
+
+cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix}
+
+# Call make instruction with smp support
+#make %{?jobs:-j%jobs}
+make
+
+%install
+%make_install
+
+%clean
+rm -rf %{buildroot}
+
+%post
+/sbin/ldconfig
+
+#################################################################
+# Add preset account information
+#################################################################
+echo "[EMAIL-SERVICE] Start adding preset account information..."
+
+#################################################################
+# Email Settings
+#################################################################
+
+## Setting
+# Sending
+vconftool set -g 5000 -t bool db/Services/Email/Sending/KeepCopy "1"
+vconftool set -g 5000 -t bool db/Services/Email/Sending/SendMeCopy "1"
+vconftool set -g 5000 -t bool db/Services/Email/Sending/ReqDeliveryRep "0"
+vconftool set -g 5000 -t bool db/Services/Email/Sending/ReqReadRep "0"
+vconftool set -g 5000 -t int db/Services/Email/Sending/Priority "1"
+vconftool set -g 5000 -t string db/Services/Email/Sending/ActiveAccount ""
+vconftool set -g 5000 -t bool db/Services/Email/Sending/IncBodyReply "1"
+vconftool set -g 5000 -t bool db/Services/Email/Sending/IncAttachFwd "1"
+# Receiving
+vconftool set -g 5000 -t int db/Services/Email/Receiving/AutoPoll "0"
+vconftool set -g 5000 -t int db/Services/Email/Receiving/PollTime "0"
+vconftool set -g 5000 -t int db/Services/Email/Receiving/SendReadRep "2"
+vconftool set -g 5000 -t int db/Services/Email/Receiving/Reclimit "0"
+vconftool set -g 5000 -t int db/Services/Email/Receiving/FetchOption "0"
+vconftool set -g 5000 -t bool db/Services/Email/Receiving/KeepServer "1"
+vconftool set -g 5000 -t int db/Services/Email/Receiving/ServDelOption "1"
+
+vconftool set -g 5000 -t int db/Services/Email/NbAccount "6"
+
+## Accounts
+
+# Gmail
+vconftool set -g 5000 -t string db/Services/Email/1/General/NetworkName "default"
+vconftool set -g 5000 -t string db/Services/Email/1/General/AccountName "Gmail"
+vconftool set -g 5000 -t string db/Services/Email/1/General/EmailAddr ""
+vconftool set -g 5000 -t string db/Services/Email/1/General/UserId ""
+vconftool set -g 5000 -t string db/Services/Email/1/General/Password ""
+vconftool set -g 5000 -t string db/Services/Email/1/General/LoginType "username_type"
+
+# MailboxType : pop3(0), imap4(1) -> pop3(1), imap4(2) in email-service
+vconftool set -g 5000 -t int db/Services/Email/1/Incoming/MailboxType "1"
+vconftool set -g 5000 -t string db/Services/Email/1/Incoming/ServAddr "imap.gmail.com"
+vconftool set -g 5000 -t int db/Services/Email/1/Incoming/Port "993"
+vconftool set -g 5000 -t int db/Services/Email/1/Incoming/Secure "1"
+vconftool set -g 5000 -t bool db/Services/Email/1/Incoming/Apop "0"
+vconftool set -g 5000 -t bool db/Services/Email/1/Incoming/AutoEmailSync "0"
+vconftool set -g 5000 -t bool db/Services/Email/1/Incoming/IncludeAttach "0"
+vconftool set -g 5000 -t int db/Services/Email/1/Incoming/ImapFetchOpt "1"
+
+vconftool set -g 5000 -t string db/Services/Email/1/Outgoing/ServAddr "smtp.gmail.com"
+vconftool set -g 5000 -t int db/Services/Email/1/Outgoing/Port "465"
+vconftool set -g 5000 -t bool db/Services/Email/1/Outgoing/SmtpAuth "0"
+vconftool set -g 5000 -t int db/Services/Email/1/Outgoing/Secure "1"
+vconftool set -g 5000 -t bool db/Services/Email/1/Outgoing/SameIdPwd "1"
+vconftool set -g 5000 -t bool db/Services/Email/1/Outgoing/PopBeforeSmtp "0"
+
+# Hotmail
+vconftool set -g 5000 -t string db/Services/Email/2/General/NetworkName "default"
+vconftool set -g 5000 -t string db/Services/Email/2/General/AccountName "Hotmail"
+vconftool set -g 5000 -t string db/Services/Email/2/General/EmailAddr ""
+vconftool set -g 5000 -t string db/Services/Email/2/General/UserId ""
+vconftool set -g 5000 -t string db/Services/Email/2/General/Password ""
+vconftool set -g 5000 -t string db/Services/Email/2/General/LoginType "username_type"
+
+# MailboxType : pop3(0), imap4(1) -> pop3(1), imap4(2) in email-service
+vconftool set -g 5000 -t int db/Services/Email/2/Incoming/MailboxType "0"
+vconftool set -g 5000 -t string db/Services/Email/2/Incoming/ServAddr "pop3.live.com"
+vconftool set -g 5000 -t int db/Services/Email/2/Incoming/Port "995"
+vconftool set -g 5000 -t int db/Services/Email/2/Incoming/Secure "1"
+vconftool set -g 5000 -t bool db/Services/Email/2/Incoming/Apop "0"
+vconftool set -g 5000 -t bool db/Services/Email/2/Incoming/AutoEmailSync "0"
+vconftool set -g 5000 -t bool db/Services/Email/2/Incoming/IncludeAttach "0"
+vconftool set -g 5000 -t int db/Services/Email/2/Incoming/ImapFetchOpt "1"
+
+vconftool set -g 5000 -t string db/Services/Email/2/Outgoing/ServAddr "smtp.live.com"
+vconftool set -g 5000 -t int db/Services/Email/2/Outgoing/Port "587"
+vconftool set -g 5000 -t bool db/Services/Email/2/Outgoing/SmtpAuth "0"
+vconftool set -g 5000 -t int db/Services/Email/2/Outgoing/Secure "2"
+vconftool set -g 5000 -t bool db/Services/Email/2/Outgoing/SameIdPwd "1"
+vconftool set -g 5000 -t bool db/Services/Email/2/Outgoing/PopBeforeSmtp "0"
+
+# AOL
+vconftool set -g 5000 -t string db/Services/Email/3/General/NetworkName "default"
+vconftool set -g 5000 -t string db/Services/Email/3/General/AccountName "AOL"
+vconftool set -g 5000 -t string db/Services/Email/3/General/EmailAddr ""
+vconftool set -g 5000 -t string db/Services/Email/3/General/UserId ""
+vconftool set -g 5000 -t string db/Services/Email/3/General/Password ""
+vconftool set -g 5000 -t string db/Services/Email/3/General/LoginType "username_type"
+
+# MailboxType : pop3(0), imap4(1) -> pop3(1), imap4(2) in email-service
+vconftool set -g 5000 -t int db/Services/Email/3/Incoming/MailboxType "1"
+vconftool set -g 5000 -t string db/Services/Email/3/Incoming/ServAddr "imap.aol.com"
+vconftool set -g 5000 -t int db/Services/Email/3/Incoming/Port "143"
+vconftool set -g 5000 -t int db/Services/Email/3/Incoming/Secure "0"
+vconftool set -g 5000 -t bool db/Services/Email/3/Incoming/Apop "0"
+vconftool set -g 5000 -t bool db/Services/Email/3/Incoming/AutoEmailSync "0"
+vconftool set -g 5000 -t bool db/Services/Email/3/Incoming/IncludeAttach "0"
+vconftool set -g 5000 -t int db/Services/Email/3/Incoming/ImapFetchOpt "0"
+
+vconftool set -g 5000 -t string db/Services/Email/3/Outgoing/ServAddr "smtp.aol.com"
+vconftool set -g 5000 -t int db/Services/Email/3/Outgoing/Port "587"
+vconftool set -g 5000 -t bool db/Services/Email/3/Outgoing/SmtpAuth "0"
+vconftool set -g 5000 -t int db/Services/Email/3/Outgoing/Secure "0"
+vconftool set -g 5000 -t bool db/Services/Email/3/Outgoing/SameIdPwd "1"
+vconftool set -g 5000 -t bool db/Services/Email/3/Outgoing/PopBeforeSmtp "0"
+
+# Yahoo
+vconftool set -g 5000 -t string db/Services/Email/6/General/NetworkName "default"
+vconftool set -g 5000 -t string db/Services/Email/6/General/AccountName "Yahoomail"
+vconftool set -g 5000 -t string db/Services/Email/6/General/EmailAddr ""
+vconftool set -g 5000 -t string db/Services/Email/6/General/UserId ""
+vconftool set -g 5000 -t string db/Services/Email/6/General/Password ""
+vconftool set -g 5000 -t string db/Services/Email/6/General/LoginType "username_type"
+
+# MailboxType : pop3(0), imap4(1) -> pop3(1), imap4(2) in email-service
+vconftool set -g 5000 -t int db/Services/Email/6/Incoming/MailboxType "0"
+vconftool set -g 5000 -t string db/Services/Email/6/Incoming/ServAddr "pop.mail.yahoo.co.kr"
+vconftool set -g 5000 -t int db/Services/Email/6/Incoming/Port "995"
+vconftool set -g 5000 -t int db/Services/Email/6/Incoming/Secure "1"
+vconftool set -g 5000 -t bool db/Services/Email/6/Incoming/Apop "0"
+vconftool set -g 5000 -t bool db/Services/Email/6/Incoming/AutoEmailSync "0"
+vconftool set -g 5000 -t bool db/Services/Email/6/Incoming/IncludeAttach "0"
+vconftool set -g 5000 -t int db/Services/Email/6/Incoming/ImapFetchOpt "1"
+
+vconftool set -g 5000 -t string db/Services/Email/6/Outgoing/ServAddr "smtp.mail.yahoo.co.kr"
+vconftool set -g 5000 -t int db/Services/Email/6/Outgoing/Port "465"
+vconftool set -g 5000 -t bool db/Services/Email/6/Outgoing/SmtpAuth "0"
+vconftool set -g 5000 -t int db/Services/Email/6/Outgoing/Secure "1"
+vconftool set -g 5000 -t bool db/Services/Email/6/Outgoing/SameIdPwd "1"
+vconftool set -g 5000 -t bool db/Services/Email/6/Outgoing/PopBeforeSmtp "0"
+
+vconftool set -t string db/email/preset_account/aol/sending_address "smtp.aol.com"
+vconftool set -t int db/email/preset_account/aol/sending_port "587"
+vconftool set -t int db/email/preset_account/aol/sending_ssl "0"
+vconftool set -t int db/email/preset_account/aol/receiving_type "2"
+vconftool set -t string db/email/preset_account/aol/receiving_address "imap.aol.com"
+vconftool set -t int db/email/preset_account/aol/receiving_port "143"
+vconftool set -t int db/email/preset_account/aol/receiving_ssl "0"
+
+vconftool set -t string db/email/preset_account/gmail/sending_address "smtp.gmail.com"
+vconftool set -t int db/email/preset_account/gmail/sending_port "465"
+vconftool set -t int db/email/preset_account/gmail/sending_ssl "1"
+vconftool set -t int db/email/preset_account/gmail/receiving_type "2"
+# for POP3 server
+#vconftool set -t string db/email/preset_account/gmail/receiving_address "pop.gmail.com"
+#vconftool set -t int db/email/preset_account/gmail/receiving_port "995"
+# for IMAP4 server
+vconftool set -t string db/email/preset_account/gmail/receiving_address "imap.gmail.com"
+vconftool set -t int db/email/preset_account/gmail/receiving_port "993"
+vconftool set -t int db/email/preset_account/gmail/receiving_ssl "1"
+
+vconftool set -t string db/email/preset_account/yahoo/sending_address "smtp.mail.yahoo.co.kr"
+vconftool set -t int db/email/preset_account/yahoo/sending_port "465"
+vconftool set -t int db/email/preset_account/yahoo/sending_ssl "1"
+vconftool set -t int db/email/preset_account/yahoo/receiving_type "1"
+vconftool set -t string db/email/preset_account/yahoo/receiving_address "pop.mail.yahoo.co.kr"
+vconftool set -t int db/email/preset_account/yahoo/receiving_port "995"
+vconftool set -t int db/email/preset_account/yahoo/receiving_ssl "1"
+
+vconftool set -t string db/email/preset_account/hotmail/sending_address "smtp.live.com"
+vconftool set -t int db/email/preset_account/hotmail/sending_port "587"
+vconftool set -t int db/email/preset_account/hotmail/sending_ssl "2"
+vconftool set -t int db/email/preset_account/hotmail/receiving_type "1"
+vconftool set -t string db/email/preset_account/hotmail/receiving_address "pop3.live.com"
+vconftool set -t int db/email/preset_account/hotmail/receiving_port "995"
+vconftool set -t int db/email/preset_account/hotmail/receiving_ssl "1"
+
+# for Active Sync - Let email app create this key
+#vconftool set -t int db/email_handle/active_sync_handle "0"
+
+# for contact sync - sync from the first contact change
+vconftool set -t int db/email/last_sync_time "0"
+
+# for contact sync - sync from the first contact change
+vconftool set -t int db/email/slot_size "100"
+
+# for badge
+vconftool set -t int db/badge/org.tizen.email "0"
+
+
+echo "[EMAIL-SERVICE] Finish adding preset account information"
+
+
+#################################################################
+# Set executin script
+#################################################################
+echo "[EMAIL-SERVICE] Set executing script ..."
+EMAIL_SERVICE_EXEC_SCRIPT=/etc/rc.d/init.d/email-service
+EMAIL_SERVICE_BOOT_SCRIPT=/etc/rc.d/rc3.d/S70email-service
+EMAIL_SERVICE_FASTBOOT_SCRIPT=/etc/rc.d/rc5.d/S70email-service
+echo '#!/bin/sh' > ${EMAIL_SERVICE_EXEC_SCRIPT}
+echo '/usr/bin/email-service &' >> ${EMAIL_SERVICE_EXEC_SCRIPT}
+chmod 755 ${EMAIL_SERVICE_EXEC_SCRIPT}
+rm -rf ${EMAIL_SERVICE_BOOT_SCRIPT}
+rm -rf ${EMAIL_SERVICE_FASTBOOT_SCRIPT}
+ln -s ${EMAIL_SERVICE_EXEC_SCRIPT} ${EMAIL_SERVICE_BOOT_SCRIPT}
+ln -s ${EMAIL_SERVICE_EXEC_SCRIPT} ${EMAIL_SERVICE_FASTBOOT_SCRIPT}
+echo "[EMAIL-SERVICE] Finish executing script ..."
+
+#################################################################
+# Create DB file and tables.
+#################################################################
+echo "[EMAIL-SERVICE] Creating Email Tables ..."
+sqlite3 /opt/dbspace/.email-service.db 'PRAGMA journal_mode = PERSIST;
+CREATE TABLE mail_account_tbl
+(
+ account_bind_type INTEGER,
+ account_name varchar(51),
+ receiving_server_type INTEGER,
+ receiving_server_addr varchar(51),
+ email_addr varchar(129),
+ user_name varchar(51),
+ password varchar(51),
+ retrieval_mode INTEGER,
+ port_num INTEGER,
+ use_security INTEGER,
+ sending_server_type INTEGER,
+ sending_server_addr varchar(51),
+ sending_port_num INTEGER,
+ sending_auth INTEGER,
+ sending_security INTEGER,
+ sending_user varchar(51),
+ sending_password varchar(51),
+ display_name varchar(31),
+ reply_to_addr varchar(129),
+ return_addr varchar(129),
+ account_id INTEGER,
+ keep_on_server INTEGER,
+ flag1 INTEGER,
+ flag2 INTEGER,
+ pop_before_smtp INTEGER,
+ apop INTEGER,
+ logo_icon_path varchar(256),
+ preset_account INTEGER,
+ target_storage INTEGER,
+ check_interval INTEGER,
+ priority INTEGER,
+ keep_local_copy INTEGER,
+ req_delivery_receipt INTEGER,
+ req_read_receipt INTEGER,
+ download_limit INTEGER,
+ block_address INTEGER,
+ block_subject INTEGER,
+ display_name_from varchar(256),
+ reply_with_body INTEGER,
+ forward_with_files INTEGER,
+ add_myname_card INTEGER,
+ add_signature INTEGER,
+ signature varchar(256),
+ add_my_address_to_bcc INTEGER,
+ my_account_id INTEGER,
+ index_color INTEGER
+);
+
+CREATE TABLE mail_attachment_tbl
+(
+ attachment_id INTEGER PRIMARY KEY,
+ attachment_name varchar(257),
+ attachment_path varchar(257),
+ attachment_size INTEGER,
+ mail_id INTEGER,
+ account_id INTEGER,
+ mailbox_name varchar(129),
+ file_yn INTEGER,
+ flag1 INTEGER,
+ flag2 INTEGER,
+ flag3 INTEGER
+);
+
+CREATE TABLE mail_box_tbl
+(
+ mailbox_id INTEGER,
+ account_id INTEGER,
+ local_yn INTEGER,
+ mailbox_name varchar(256),
+ mailbox_type INTEGER,
+ alias varchar(256),
+ sync_with_server_yn INTEGER,
+ modifiable_yn INTEGER,
+ total_mail_count_on_server INTEGER,
+ has_archived_mails INTEGER,
+ mail_slot_size INTEGER
+);
+CREATE TABLE mail_read_mail_uid_tbl
+(
+ account_id INTEGER ,
+ local_mbox varchar(129) ,
+ local_uid INTEGER ,
+ mailbox_name varchar(129) ,
+ s_uid varchar(129) ,
+ data1 INTEGER ,
+ data2 varchar(257) ,
+ flag INTEGER ,
+ idx_num INTEGER PRIMARY KEY
+);
+CREATE TABLE mail_rule_tbl
+(
+ account_id INTEGER ,
+ rule_id INTEGER PRIMARY KEY,
+ type INTEGER ,
+ value varchar(257) ,
+ action_type INTEGER ,
+ dest_mailbox varchar(129),
+ flag1 INTEGER ,
+ flag2 INTEGER
+);
+CREATE TABLE mail_tbl
+(
+ mail_id INTEGER,
+ account_id INTEGER,
+ mailbox_name VARCHAR(129),
+ mailbox_type INTEGER,
+ subject UCS2TEXT,
+ date_time VARCHAR(129),
+ server_mail_status INTEGER,
+ server_mailbox_name VARCHAR(129),
+ server_mail_id VARCHAR(129),
+ message_id VARCHAR(257),
+ full_address_from UCS2TEXT,
+ full_address_reply UCS2TEXT,
+ full_address_to UCS2TEXT,
+ full_address_cc UCS2TEXT,
+ full_address_bcc UCS2TEXT,
+ full_address_return UCS2TEXT,
+ email_address_sender UCS2TEXT collation user1,
+ email_address_recipient UCS2TEXT collation user1,
+ alias_sender UCS2TEXT,
+ alias_recipient UCS2TEXT,
+ body_download_status INTEGER,
+ file_path_plain VARCHAR(257),
+ file_path_html VARCHAR(257),
+ mail_size INTEGER,
+ mail_status INTEGER,
+ DRM_status INTEGER,
+ priority INTEGER,
+ save_status INTEGER,
+ lock_status INTEGER,
+ report_status INTEGER,
+ attachment_count INTEGER,
+ inline_content_count INTEGER,
+ thread_id INTEGER,
+ thread_item_count INTEGER,
+ preview_text UCS2TEXT,
+ meeting_request_status INTEGER
+);
+CREATE TABLE mail_meeting_tbl
+(
+ mail_id INTEGER PRIMARY KEY,
+ account_id INTEGER,
+ mailbox_name UCS2TEXT ,
+ meeting_response INTEGER,
+ start_time INTEGER,
+ end_time INTEGER,
+ location UCS2TEXT ,
+ global_object_id UCS2TEXT ,
+ offset INTEGER,
+ standard_name UCS2TEXT ,
+ standard_time_start_date INTEGER,
+ standard_bias INTEGER,
+ daylight_name UCS2TEXT ,
+ daylight_time_start_date INTEGER,
+ daylight_bias INTEGER
+);
+CREATE TABLE mail_local_activity_tbl
+(
+ activity_id INTEGER,
+ account_id INTEGER,
+ mail_id INTEGER,
+ activity_type INTEGER,
+ server_mailid VARCHAR(129),
+ src_mbox VARCHAR(129),
+ dest_mbox VARCHAR(129)
+);
+
+
+CREATE UNIQUE INDEX mail_account_idx1 ON mail_account_tbl (account_bind_type, account_id);
+CREATE UNIQUE INDEX mail_attachment_idx1 ON mail_attachment_tbl (mail_id, attachment_id);
+CREATE UNIQUE INDEX mail_box_idx1 ON mail_box_tbl (account_id, local_yn, mailbox_name);
+CREATE UNIQUE INDEX mail_idx1 ON mail_tbl (mail_id, account_id);
+CREATE UNIQUE INDEX mail_read_mail_uid_idx1 ON mail_read_mail_uid_tbl (account_id, local_mbox, local_uid, mailbox_name, s_uid);
+CREATE UNIQUE INDEX mail_meeting_idx1 ON mail_meeting_tbl (mail_id);
+CREATE INDEX mail_idx_date_time ON mail_tbl (date_time);
+CREATE INDEX mail_idx_thread_item_count ON mail_tbl (thread_item_count);
+'
+
+echo "[EMAIL-SERVICE] Finish Creating Email Tables."
+
+
+#################################################################
+# Change file permission
+#################################################################
+#echo "[EMAIL-SERVICE] Start setting permission ..."
+# 1. libraries
+#chmod 644 /usr/lib/libemail-ipc.so.0.0.0
+#chmod 644 /usr/lib/libemail-core.so.0.0.0
+#chmod 644 /usr/lib/libemail-emn-storage.so.0.0.0
+#chmod 644 /usr/lib/libemail-base.so.0.0.0
+#chmod 644 /usr/lib/libem-storage.so.0.0.0
+#chmod 644 /usr/lib/libem-network.so.0.0.0
+#chmod 644 /usr/lib/libemail-mapi.so.0.0.0
+#chmod 644 /usr/lib/libem-storage.so
+#chmod 644 /usr/lib/libemail-base.so.0
+#chmod 644 /usr/lib/libem-network.so.0
+#chmod 644 /usr/lib/libemail-core.so.0
+#chmod 644 /usr/lib/libemail-emn-storage.so
+#chmod 644 /usr/lib/libemail-ipc.so
+#chmod 644 /usr/lib/libemail-mapi.so.0
+#chmod 644 /usr/lib/libem-storage.so.0
+#chmod 644 /usr/lib/libem-network.so
+#chmod 644 /usr/lib/libemail-ipc.so.0
+#chmod 644 /usr/lib/libemail-core.so
+#chmod 644 /usr/lib/libemail-base.so
+#chmod 644 /usr/lib/libemail-mapi.so
+#chmod 644 /usr/lib/libemail-emn-storage.so.0
+
+# 2. executables
+#chmod 700 /usr/bin/email-service_initDB
+#chmod 700 /usr/bin/email-service
+
+# 3. DB files
+chmod 644 /opt/dbspace/.email-service.db
+chmod 644 /opt/dbspace/.email-service.db-journal
+
+
+#################################################################
+# Change file owner
+#################################################################
+#echo "[EMAIL-SERVICE] Start setting owner ..."
+
+ # 1. libraries
+# chown root:root /usr/lib/libemail-ipc.so.0.0.0
+# chown root:root /usr/lib/libemail-core.so.0.0.0
+# chown root:root /usr/lib/libemail-emn-storage.so.0.0.0
+# chown root:root /usr/lib/libemail-base.so.0.0.0
+# chown root:root /usr/lib/libem-storage.so.0.0.0
+# chown root:root /usr/lib/libem-network.so.0.0.0
+# chown root:root /usr/lib/libemail-mapi.so.0.0.0
+# chown root:root /usr/lib/libem-storage.so
+# chown root:root /usr/lib/libemail-base.so.0
+# chown root:root /usr/lib/libem-network.so.0
+# chown root:root /usr/lib/libemail-core.so.0
+# chown root:root /usr/lib/libemail-emn-storage.so
+# chown root:root /usr/lib/libemail-ipc.so
+# chown root:root /usr/lib/libemail-mapi.so.0
+# chown root:root /usr/lib/libem-storage.so.0
+# chown root:root /usr/lib/libem-network.so
+# chown root:root /usr/lib/libemail-ipc.so.0
+# chown root:root /usr/lib/libemail-core.so
+# chown root:root /usr/lib/libemail-base.so
+# chown root:root /usr/lib/libemail-mapi.so
+# chown root:root /usr/lib/libemail-emn-storage.so.0
+
+ # 2. executables
+# chown root:root /usr/bin/email-service_initDB
+# chown root:root /usr/bin/email-service
+
+ # 3. DB files
+chown root:root /opt/dbspace/.email-service.db
+chown root:root /opt/dbspace/.email-service.db-journal
+
+%postun -p /sbin/ldconfig
+
+
+
+%files
+%defattr(-,root,root,-)
+%exclude /opt/dbspace/.email-service.db
+%exclude /opt/dbspace/.email-service.db-journal
+%exclude %{_bindir}/email-test-app
+%{_libdir}/libemail-api.so.*
+%{_libdir}/libemail-base.so.*
+%{_libdir}/libemail-core.so.*
+%{_libdir}/libemail-ipc.so.*
+%{_libdir}/libemail-network.so.*
+%{_libdir}/libemail-storage.so.*
+%{_bindir}/email-service
+
+
+%files devel
+%defattr(-,root,root,-)
+%{_includedir}/email-service/*.h
+%{_libdir}/libemail-api.so
+%{_libdir}/libemail-base.so
+%{_libdir}/libemail-core.so
+%{_libdir}/libemail-ipc.so
+%{_libdir}/libemail-network.so
+%{_libdir}/libemail-storage.so
+%{_libdir}/pkgconfig/*.pc
+
diff --git a/po/CMakeLists.txt b/po/CMakeLists.txt
new file mode 100755
index 0000000..b27e5bc
--- /dev/null
+++ b/po/CMakeLists.txt
@@ -0,0 +1,28 @@
+# for i18n
+
+#SET(POFILES en_US.po en_GB.po ja.po ko.po zh_CN.po)
+#SET(POFILES de.po el.po en_US.po es.po fr.po it.po ja.po ko.po nl.po pt.po ru.po tk.po zh_CN.po zh_HK.po zh_TW.po)
+SET(POFILES en.po nl_NL.po de_DE.po zh_HK.po zh_CN.po ru_RU.po ko_KR.po zh_TW.po ja_JP.po es_ES.po el_GR.po it_IT.po tr_TR.po pt_PT.po fr_FR.po)
+
+SET(MSGFMT "/usr/bin/msgfmt")
+
+FOREACH(pofile ${POFILES})
+ SET(pofile ${CMAKE_CURRENT_SOURCE_DIR}/${pofile})
+ MESSAGE("PO: ${pofile}")
+ GET_FILENAME_COMPONENT(absPofile ${pofile} ABSOLUTE)
+ GET_FILENAME_COMPONENT(lang ${absPofile} NAME_WE)
+ SET(moFile ${CMAKE_CURRENT_BINARY_DIR}/${lang}.mo)
+ ADD_CUSTOM_COMMAND(
+ OUTPUT ${moFile}
+ COMMAND ${MSGFMT} -o ${moFile} ${absPofile}
+ DEPENDS ${absPofile}
+ )
+
+ INSTALL(FILES ${moFile}
+ DESTINATION /opt/apps/email-service/res/locale/${lang}/LC_MESSAGES RENAME email.mo)
+
+ SET(moFiles ${moFiles} ${moFile})
+ENDFOREACH(pofile)
+
+MESSAGE(".mo files: ${moFiles}")
+ADD_CUSTOM_TARGET(po ALL DEPENDS ${moFiles})
diff --git a/po/POTFILES.in b/po/POTFILES.in
new file mode 100755
index 0000000..dcff06f
--- /dev/null
+++ b/po/POTFILES.in
@@ -0,0 +1,46 @@
+# List of source files containing translatable strings.
+account/email-account.c
+block/email-block.c
+common/email-debug.c
+common/email-dialog-util.c
+common/email-drm-util.c
+common/email-engine.c
+common/email-evt-delivery-util.c
+common/email-external.c
+common/email-gconf-util.c
+common/email-html-converter.c
+common/email-ime-util.c
+common/email-launch-ext.c
+common/email-settings.c
+common/email-utils.c
+mailbox/email-mailbox.c
+main/email.c
+popup/email-popup.c
+setting/email-setting.c
+setting/email-setting-account-set.c
+setting/email-setting-utils.c
+setting/email-setting-view.c
+setting/email-view-account-edit.c
+setting/email-view-account-options.c
+setting/email-view-default-account.c
+setting/email-view-other-account.c
+setting/email-view-receiving-option-mailbox-setup.c
+setting/email-view-receiving-option-size.c
+setting/email-view-select-account.c
+setting/email-view-server-type.c
+setting/email-view-setting.c
+setting/email-view-show-email-list.c
+viewer/email-viewer.c
+viewer/email-viewer-logic.c
+viewer/email-viewer-multitouch.c
+viewer/email-viewer-utils.c
+viewer/email-viewer-webview.c
+composer/email-composer.c
+composer/email-composer-attachment.c
+composer/email-composer-callback.c
+composer/email-composer-contents.c
+composer/email-composer-predictive-search.c
+composer/email-composer-recent.c
+composer/email-composer-recipient.c
+composer/email-composer-ug-caller.c
+composer/email-composer-util.c \ No newline at end of file
diff --git a/po/de_DE.po b/po/de_DE.po
new file mode 100755
index 0000000..1f476fd
--- /dev/null
+++ b/po/de_DE.po
@@ -0,0 +1,465 @@
+msgid "IDS_EMAIL_POP_NO_EMAIL_ADDRESS"
+msgstr "Keine E-Mail-Adresse"
+
+msgid "IDS_EMAIL_BODY_COMPLETE"
+msgstr "Abgeschlossen"
+
+msgid "IDS_EMAIL_BODY_ACCEPTED_C_PS"
+msgstr "Angenommen: %s"
+
+msgid "IDS_EMAIL_BODY_DECLINED_C_PS"
+msgstr "Abgelehnt: %s"
+
+msgid "IDS_EMAIL_BODY_DOWNLOAD_FULL_MESSAGE"
+msgstr "Vollständige Nachricht herunterladen"
+
+msgid "IDS_EMAIL_BODY_GENERAL_SETTINGS"
+msgstr "Allgemeine Einstellungen"
+
+msgid "IDS_EMAIL_BODY_TENTATIVE_C_PS"
+msgstr "Vorläufig: %s"
+
+msgid "IDS_EMAIL_BODY_WHEN_C_PS"
+msgstr "Wann: %s"
+
+msgid "IDS_EMAIL_BODY_WHERE_C_PS"
+msgstr "Wo: %s"
+
+msgid "IDS_EMAIL_BUTTON_DECLINE_ABB"
+msgstr "Ablehnen"
+
+msgid "IDS_EMAIL_BODY_NO_CONTENTS"
+msgstr "Kein Inhalt"
+
+msgid "IDS_EMAIL_BODY_ORIGINAL_MESSAGE"
+msgstr "Ursprüngliche Nachricht"
+
+msgid "IDS_EMAIL_HEADER_ACCOUNT_SETTINGS"
+msgstr "Kontoeinstellungen"
+
+msgid "IDS_EMAIL_OPT_BLOCK"
+msgstr "Sperren"
+
+msgid "IDS_EMAIL_OPT_MARK_AS_READ"
+msgstr "Als gelesen markieren"
+
+msgid "IDS_EMAIL_OPT_MARK_AS_UNREAD"
+msgstr "Als ungelesen markieren"
+
+msgid "IDS_EMAIL_OPT_OTHERS"
+msgstr "Sonstiges"
+
+msgid "IDS_EMAIL_OPT_UNREAD"
+msgstr "Ungelesen"
+
+msgid "IDS_EMAIL_SK_COMPOSE"
+msgstr "Verfassen"
+
+msgid "IDS_EMAIL_HEADER_DOWNLOAD_FAILED"
+msgstr "Herunterladen fehlgeschlagen"
+
+msgid "IDS_EMAIL_OPT_ADD_TO_CONTACT"
+msgstr "Zu Kontakt hinzufügen"
+
+msgid "IDS_EMAIL_OPT_VOICE_CALL"
+msgstr "Sprachanruf"
+
+msgid "IDS_EMAIL_BODY_ACCOUNT_NAME"
+msgstr "Kontoname"
+
+msgid "IDS_EMAIL_BODY_ATTACHMENTS"
+msgstr "Anhänge"
+
+msgid "IDS_EMAIL_BODY_FROM_C"
+msgstr "Von:"
+
+msgid "IDS_EMAIL_BODY_IMAP4_SERVER"
+msgstr "IMAP4-Server"
+
+msgid "IDS_EMAIL_BODY_INCLUDES"
+msgstr "Enthält"
+
+msgid "IDS_EMAIL_BODY_INCOMING_PORT"
+msgstr "Eingangsport"
+
+msgid "IDS_EMAIL_BODY_INCOMING_SERVER"
+msgstr "Eingangsserver"
+
+msgid "IDS_EMAIL_BODY_IN_PD_MINUTES"
+msgstr "In %d Minuten"
+
+msgid "IDS_EMAIL_BODY_KEEP_IN_SERVER"
+msgstr "Auf Server behalten"
+
+msgid "IDS_EMAIL_BODY_NO_TEXT"
+msgstr "Kein Text"
+
+msgid "IDS_EMAIL_BODY_OUTGOING_PORT"
+msgstr "Ausgangs-Port"
+
+msgid "IDS_EMAIL_BODY_OUTGOING_SERVER"
+msgstr "Ausgangsserver"
+
+msgid "IDS_EMAIL_BODY_PD_EMAILS"
+msgstr "%d E-Mails"
+
+msgid "IDS_EMAIL_BODY_POP3_SERVER"
+msgstr "POP3-Server"
+
+msgid "IDS_EMAIL_BODY_RECENT"
+msgstr "Kürzlich"
+
+msgid "IDS_EMAIL_BODY_RETRIEVING_OPTIONS"
+msgstr "Abrufoptionen"
+
+msgid "IDS_EMAIL_BODY_RE_C"
+msgstr "AW:"
+
+msgid "IDS_EMAIL_BODY_SENT_C"
+msgstr "Gesendet:"
+
+msgid "IDS_EMAIL_BODY_SENT_FROM_SAMSUNG_MOBILE"
+msgstr "Von Samsung Mobile gesendet"
+
+msgid "IDS_EMAIL_BODY_USER_PASSWORD"
+msgstr "Benutzerpasswort"
+
+msgid "IDS_EMAIL_HEADER_EDIT_RULES"
+msgstr "Regeln bearbeiten"
+
+msgid "IDS_EMAIL_HEADER_EMAIL_SETTINGS"
+msgstr "E-Mail Einstellungen"
+
+msgid "IDS_EMAIL_HEADER_MAILBOXES"
+msgstr "Mailboxen"
+
+msgid "IDS_EMAIL_POP_ALERT"
+msgstr "Signal"
+
+msgid "IDS_EMAIL_POP_FILE_ALREADY_EXISTS"
+msgstr "Datei bereits vorhanden."
+
+msgid "IDS_EMAIL_POP_NO_SENDER"
+msgstr "Kein Absender"
+
+msgid "IDS_EMAIL_POP_SUCCEEDED"
+msgstr "Erfolgreich"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_ATTACH_MAXIMUM_NUMBER_OF_FILES_IS_PD"
+msgstr "Anhängen nicht möglich. Maximale Dateianzahl ist %d"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_ATTACH_MAXIMUM_SIZE_OF_FILES_IS_PD_KB"
+msgstr "Anhängen nicht möglich. Maximale Dateigröße ist %d KB"
+
+msgid "IDS_EMAIL_POP_VALIDATION_FAILED"
+msgstr "Validierung fehlgeschlagen"
+
+msgid "IDS_EMAIL_SK_REPLY_ALL"
+msgstr "Allen antworten"
+
+msgid "IDS_EMAIL_BODY_1_ITEM"
+msgstr "1 Element"
+
+msgid "IDS_EMAIL_BODY_ADD_MY_NAMECARD"
+msgstr "Eigene Visitenkarte hinzufügen"
+
+msgid "IDS_EMAIL_BODY_ADD_SIGNATURE"
+msgstr "Signatur anfügen"
+
+msgid "IDS_EMAIL_BODY_ALL_EMAILS"
+msgstr "Alle E-Mails"
+
+msgid "IDS_EMAIL_BODY_ALWAYS_BCC_MYSELF"
+msgstr "Mich immer Bcc setzen"
+
+msgid "IDS_EMAIL_BODY_BCC"
+msgstr "Bcc"
+
+msgid "IDS_EMAIL_BODY_BLOCK_EMAILS"
+msgstr "E-Mails sperren"
+
+msgid "IDS_EMAIL_BODY_BODY"
+msgstr "Körper"
+
+msgid "IDS_EMAIL_BODY_CC"
+msgstr "Cc"
+
+msgid "IDS_EMAIL_BODY_CC_BCC"
+msgstr "Cc/Bcc"
+
+msgid "IDS_EMAIL_BODY_CHECK_INTERVAL"
+msgstr "Prüfintervall"
+
+msgid "IDS_EMAIL_BODY_DEFAULT_ACCOUNT"
+msgstr "Standardkonto"
+
+msgid "IDS_EMAIL_BODY_DRAFTS"
+msgstr "Entwürfe"
+
+msgid "IDS_EMAIL_BODY_EMAIL_ACCOUNTS"
+msgstr "E-Mail-Konten"
+
+msgid "IDS_EMAIL_BODY_END_TIME"
+msgstr "Endzeit"
+
+msgid "IDS_EMAIL_BODY_ENTIRE_EMAIL"
+msgstr "Gesamte E-Mail"
+
+msgid "IDS_EMAIL_BODY_EXACTLY_THE_SAME_AS"
+msgstr "Identisch mit"
+
+msgid "IDS_EMAIL_BODY_EXAMPLE"
+msgstr "Beispiel"
+
+msgid "IDS_EMAIL_BODY_FROM_M_SENDER"
+msgstr "Von:"
+
+msgid "IDS_EMAIL_BODY_INBOX"
+msgstr "Posteingang"
+
+msgid "IDS_EMAIL_BODY_INCLUDE"
+msgstr "Enthält"
+
+msgid "IDS_EMAIL_BODY_MATCH_CRITERIA"
+msgstr "Passende Kriterien"
+
+msgid "IDS_EMAIL_BODY_NOT_USED"
+msgstr "Nicht verwendet"
+
+msgid "IDS_EMAIL_BODY_NO_ACCOUNTS"
+msgstr "Keine Konten"
+
+msgid "IDS_EMAIL_BODY_PD_DAYS"
+msgstr "%d Tage"
+
+msgid "IDS_EMAIL_BODY_PD_ITEMS"
+msgstr "%d Einträge"
+
+msgid "IDS_EMAIL_BODY_PRIORITY"
+msgstr "Priorität"
+
+msgid "IDS_EMAIL_BODY_RECEIVING_OPTIONS"
+msgstr "Empfangsoptionen"
+
+msgid "IDS_EMAIL_BODY_SECURE_CONNECTION"
+msgstr "Sichere Verbindung"
+
+msgid "IDS_EMAIL_BODY_SENDING_OPTIONS"
+msgstr "Sendeoptionen"
+
+msgid "IDS_EMAIL_BODY_SENTBOX"
+msgstr "Gesendete Nachrichten"
+
+msgid "IDS_EMAIL_BODY_SERVER_URL"
+msgstr "Server-URL"
+
+msgid "IDS_EMAIL_BODY_SIGNATURE"
+msgstr "Signatur"
+
+msgid "IDS_EMAIL_BODY_SPAMBOX"
+msgstr "Spamordner"
+
+msgid "IDS_EMAIL_BODY_START_TIME"
+msgstr "Startzeit"
+
+msgid "IDS_EMAIL_BODY_SYNC_SCHEDULE_TMO"
+msgstr "Abrufeinstellungen"
+
+msgid "IDS_EMAIL_BODY_TRASH"
+msgstr "Papierkorb"
+
+msgid "IDS_EMAIL_BODY_WITHOUT_ATTACHMENTS"
+msgstr "Ohne Anhänge"
+
+msgid "IDS_EMAIL_BUTTON_GROUP"
+msgstr "Gruppe"
+
+msgid "IDS_EMAIL_HEADER_ADD_RULES"
+msgstr "Regeln hinzufügen"
+
+msgid "IDS_EMAIL_OPT_ATTACH_ITEMS"
+msgstr "Elemente anhängen"
+
+msgid "IDS_EMAIL_OPT_EXCHANGE"
+msgstr "Exchange"
+
+msgid "IDS_EMAIL_OPT_FILE"
+msgstr "Datei"
+
+msgid "IDS_EMAIL_OPT_NAMECARD"
+msgstr "Visitenkarte"
+
+msgid "IDS_EMAIL_OPT_OPEN_URL"
+msgstr "URL öffnen"
+
+msgid "IDS_EMAIL_OPT_SENDER"
+msgstr "Absender"
+
+msgid "IDS_EMAIL_OPT_SEND_EMAIL"
+msgstr "E-Mail senden"
+
+msgid "IDS_EMAIL_OPT_UPDATE_EXISTING"
+msgstr "Vorhandene aktualisieren"
+
+msgid "IDS_EMAIL_POP_ADD_ACCOUNTS"
+msgstr "Konten hinzufügen"
+
+msgid "IDS_EMAIL_POP_DOWNLOADING_ATTACHMENT_ING"
+msgstr "Anhang wird heruntergeladen..."
+
+msgid "IDS_EMAIL_POP_INVALID_EMAIL_ADDRESS"
+msgstr "Ungültige E-Mail-Adresse"
+
+msgid "IDS_EMAIL_POP_LOADING_CONTENTS_ING"
+msgstr "Inhalte werden geladen..."
+
+msgid "IDS_EMAIL_POP_MAXIMUM_NUMBER_OF_ATTACHMENTS_REACHED"
+msgstr "Maximale Anzahl an Anhängen erreicht"
+
+msgid "IDS_EMAIL_POP_MOVE_TO_SPAMBOX_Q"
+msgstr "In Spamordner verschieben?"
+
+msgid "IDS_EMAIL_POP_NO_RECIPIENTS_ADDED_ENTER_RECIPIENTS"
+msgstr "Keine Empfänger hinzugefügt. Empfänger hinzufügen."
+
+msgid "IDS_EMAIL_POP_PLEASE_FILL_ALL_THE_MANDATORY_FIELDS"
+msgstr "Füllen Sie alle obligatorischen Felder aus"
+
+msgid "IDS_EMAIL_POP_SAVE_IN_DRAFTS_Q"
+msgstr "In Entwürfe speichern"
+
+msgid "IDS_EMAIL_POP_THERE_IS_NO_ACCOUNT_CREATE_A_NEW_ACCOUNT_FIRST"
+msgstr "Kein Konto vorhanden. Erstellen Sie zunächst ein neues Konto"
+
+msgid "IDS_EMAIL_POP_TOO_MANY_RECIPIENTS"
+msgstr "Zu viele Empfänger"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_DOWNLOAD"
+msgstr "Download nicht möglich"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_ENTER_TEXT"
+msgstr "Text kann nicht eingegeben werden"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_LAUNCH_APPLICATION"
+msgstr "Anwendung kann nicht gestartet werden"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_OPEN_ATTACHMENT"
+msgstr "Anhang kann nicht geöffnet werden"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_SAVE_ATTACHMENT"
+msgstr "Anhang kann nicht gespeichert werden"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_SAVE_IN_DRAFTS"
+msgstr "Kann nicht in Entwürfe gespeichert werden"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_SEND_EMAIL"
+msgstr "E-Mail kann nicht gesendet werden."
+
+msgid "IDS_EMAIL_POP_UNSUPPORTED_FILE_TYPE"
+msgstr "Nicht unterstützter Dateityp"
+
+msgid "IDS_EMAIL_POP_VALIDATING_ACCOUNT_ING"
+msgstr "Konto wird validiert..."
+
+msgid "IDS_EMAIL_SK_RESEND"
+msgstr "Erneut senden"
+
+msgid "IDS_EMAIL_BODY_ACCEPT_ALL_SSL_CERTIFICATES"
+msgstr "Alle SSL-Zertifikate akzeptieren"
+
+msgid "IDS_EMAIL_SK3_ACCOUNT_LIST"
+msgstr "Kontoliste"
+
+msgid "IDS_EMAIL_BODY_USER_ID"
+msgstr "Benutzerkennung"
+
+msgid "IDS_EMAIL_POP_ACCOUNT_ALREADY_REGISTERED"
+msgstr "Konto bereits registriert"
+
+msgid "IDS_EMAIL_HEADER_ATTACH_FILE"
+msgstr "Datei anhängen"
+
+msgid "IDS_EMAIL_BODY_EXCHANGE_SYNC_SETTINGS_MSG"
+msgstr "Durch Aktivieren dieser Anwendung stimmen Sie zu, dass einige Ihrer Gerätedaten (eindeutige Geräte-ID und Modellname) von Samsung gespeichert, verarbeitet und dazu verwendet werden, den Lizenzgebern der Anwendungssoftware die Aktivierung dieser Anwendung zu melden. Der Umgang mit von Samsung unterhaltenen Daten erfolgt unter strenger Einhaltung der Datenschutzrichtlinie von Samsung, welche auf www.samsung.com verfügbar ist. Fortfahren?"
+
+msgid "IDS_EMAIL_BODY_FORWARD_WITH_FILES"
+msgstr "Mit Dateien weiterleiten"
+
+msgid "IDS_EMAIL_BODY_REPLY_WITH_BODY"
+msgstr "Mit Text antworten"
+
+msgid "IDS_EMAIL_BODY_NO_SUBJECT"
+msgstr "Kein Betreff"
+
+msgid "IDS_EMAIL_BODY_FROM"
+msgstr "Von"
+
+msgid "IDS_EMAIL_BODY_NO_ADDRESS"
+msgstr "Keine Adresse"
+
+msgid "IDS_EMAIL_OPT_RECORD_SOUND"
+msgstr "Ton aufzeichnen"
+
+msgid "IDS_EMAIL_OPT_RECORD_VIDEO"
+msgstr "Video aufzeichnen"
+
+msgid "IDS_EMAIL_OPT_INSERT_IMAGE"
+msgstr "Bild einfügen"
+
+msgid "IDS_EMAIL_OPT_ADD_TO_CALENDAR"
+msgstr "Zu Kalender hinzufügen"
+
+msgid "IDS_EMAIL_OPT_CHANGE_EMAIL_ADDRESS_ABB"
+msgstr "E-Mail-Adresse ändern"
+
+msgid "IDS_EMAIL_OPT_CLIPBOARD"
+msgstr "Zwischenablage"
+
+msgid "IDS_EMAIL_OPT_MARKED_AS_UNREAD"
+msgstr "Als ungelesen markiert"
+
+msgid "IDS_EMAIL_OPT_VIEW_CONTACT_DETAILS"
+msgstr "Kontaktdetails anzeigen"
+
+msgid "IDS_EMAIL_POP_SAVED_IN_DRAFTS"
+msgstr "In Entwürfe gespeichert"
+
+msgid "IDS_EMAIL_POP_NETWORK_BUSY"
+msgstr "Netz besetzt"
+
+msgid "IDS_EMAIL_POP_LOGIN_ALLOWED_ONLY_EVERY_PD_MINUTES"
+msgstr "Das Anmelden ist nur alle %d Minuten zulässig."
+
+msgid "IDS_EMAIL_POP_HOST_NOT_FOUND"
+msgstr "Host nicht gefunden"
+
+msgid "IDS_EMAIL_POP_HOST_NOT_REACHABLE"
+msgstr "Host nicht erreichbar"
+
+msgid "IDS_EMAIL_POP_NO_SERVICE"
+msgstr "Kein Netz"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_FORWARD_DRM_CONTENTS"
+msgstr "DRM-Inhalte können nicht weitergeleitet werden"
+
+msgid "IDS_EMAIL_POP_BLOCKED"
+msgstr "Gesperrt"
+
+msgid "IDS_EMAIL_POP_1_EMAIL_SELECTED"
+msgstr "1 E-Mail ausgewählt"
+
+msgid "IDS_EMAIL_POP_PD_EMAILS_SELECTED"
+msgstr "%d E-Mails ausgewählt"
+
+msgid "IDS_EMAIL_POP_1_RECIPIENT_SELECTED"
+msgstr "1 Empfänger ausgewählt"
+
+msgid "IDS_EMAIL_POP_PD_RECIPIENTS_SELECTED"
+msgstr "%d Empfänger ausgewählt"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_ADD_ACCOUNT"
+msgstr "Konto kann nicht hinzugefügt werden"
+
+msgid "IDS_EMAIL_SK3_MOVE_HERE"
+msgstr "Hierher verschieben"
+
diff --git a/po/el_GR.po b/po/el_GR.po
new file mode 100755
index 0000000..ce8f169
--- /dev/null
+++ b/po/el_GR.po
@@ -0,0 +1,465 @@
+msgid "IDS_EMAIL_POP_NO_EMAIL_ADDRESS"
+msgstr "Δεν υπάÏχει διεÏθυνση email"
+
+msgid "IDS_EMAIL_BODY_COMPLETE"
+msgstr "ΟλοκληÏώθηκε"
+
+msgid "IDS_EMAIL_BODY_ACCEPTED_C_PS"
+msgstr "Έγινε αποδεκτό: %s"
+
+msgid "IDS_EMAIL_BODY_DECLINED_C_PS"
+msgstr "ΑποÏÏίφθηκε: %s"
+
+msgid "IDS_EMAIL_BODY_DOWNLOAD_FULL_MESSAGE"
+msgstr "Λήψη πλήÏους μηνÏματος"
+
+msgid "IDS_EMAIL_BODY_GENERAL_SETTINGS"
+msgstr "Γεν. Ρυθμίσεις"
+
+msgid "IDS_EMAIL_BODY_TENTATIVE_C_PS"
+msgstr "Αβέβαιη: %s"
+
+msgid "IDS_EMAIL_BODY_WHEN_C_PS"
+msgstr "Πότε: %s"
+
+msgid "IDS_EMAIL_BODY_WHERE_C_PS"
+msgstr "ΠοÏ: %s"
+
+msgid "IDS_EMAIL_BUTTON_DECLINE_ABB"
+msgstr "ΑπόÏÏιψη"
+
+msgid "IDS_EMAIL_BODY_NO_CONTENTS"
+msgstr "Κανένα πεÏιεχόμενο"
+
+msgid "IDS_EMAIL_BODY_ORIGINAL_MESSAGE"
+msgstr "ΑÏχικό μήνυμα"
+
+msgid "IDS_EMAIL_HEADER_ACCOUNT_SETTINGS"
+msgstr "Ρυθμίσεις λογαÏιασμοÏ"
+
+msgid "IDS_EMAIL_OPT_BLOCK"
+msgstr "Αποκλεισμός"
+
+msgid "IDS_EMAIL_OPT_MARK_AS_READ"
+msgstr "Σήμανση ως αναγνωσμένου"
+
+msgid "IDS_EMAIL_OPT_MARK_AS_UNREAD"
+msgstr "Σήμανση ως μη αναγνωσμένο"
+
+msgid "IDS_EMAIL_OPT_OTHERS"
+msgstr "Άλλα"
+
+msgid "IDS_EMAIL_OPT_UNREAD"
+msgstr "Μη αναγνωσμένο"
+
+msgid "IDS_EMAIL_SK_COMPOSE"
+msgstr "Compose"
+
+msgid "IDS_EMAIL_HEADER_DOWNLOAD_FAILED"
+msgstr "Αποτυχία λήψης"
+
+msgid "IDS_EMAIL_OPT_ADD_TO_CONTACT"
+msgstr "ΠÏοσθήκη σε επαφή"
+
+msgid "IDS_EMAIL_OPT_VOICE_CALL"
+msgstr "Φωνητική κλήση"
+
+msgid "IDS_EMAIL_BODY_ACCOUNT_NAME"
+msgstr "Όνομα λογαÏιασμοÏ"
+
+msgid "IDS_EMAIL_BODY_ATTACHMENTS"
+msgstr "Συνημμένα"
+
+msgid "IDS_EMAIL_BODY_FROM_C"
+msgstr "Από:"
+
+msgid "IDS_EMAIL_BODY_IMAP4_SERVER"
+msgstr "Διακομιστής IMAP4"
+
+msgid "IDS_EMAIL_BODY_INCLUDES"
+msgstr "ΠεÏιέχει"
+
+msgid "IDS_EMAIL_BODY_INCOMING_PORT"
+msgstr "ΘÏÏα εισεÏχόμενων"
+
+msgid "IDS_EMAIL_BODY_INCOMING_SERVER"
+msgstr "Διακομιστής εισεÏχομένων"
+
+msgid "IDS_EMAIL_BODY_IN_PD_MINUTES"
+msgstr "Σε %d λεπτά"
+
+msgid "IDS_EMAIL_BODY_KEEP_IN_SERVER"
+msgstr "ΦÏλαξη στο διακομιστή"
+
+msgid "IDS_EMAIL_BODY_NO_TEXT"
+msgstr "ΧωÏίς κείμενο"
+
+msgid "IDS_EMAIL_BODY_OUTGOING_PORT"
+msgstr "ΘÏÏα εξεÏχόμενων"
+
+msgid "IDS_EMAIL_BODY_OUTGOING_SERVER"
+msgstr "Διακομιστής εξεÏχομένων"
+
+msgid "IDS_EMAIL_BODY_PD_EMAILS"
+msgstr "%d emails"
+
+msgid "IDS_EMAIL_BODY_POP3_SERVER"
+msgstr "Διακομιστής POP3"
+
+msgid "IDS_EMAIL_BODY_RECENT"
+msgstr "ΠÏόσφατα"
+
+msgid "IDS_EMAIL_BODY_RETRIEVING_OPTIONS"
+msgstr "Επιλογές ανάκτησης"
+
+msgid "IDS_EMAIL_BODY_RE_C"
+msgstr "ΠΡΟΣ:"
+
+msgid "IDS_EMAIL_BODY_SENT_C"
+msgstr "Εστάλη:"
+
+msgid "IDS_EMAIL_BODY_SENT_FROM_SAMSUNG_MOBILE"
+msgstr "Αποστολή από κινητό Samsung"
+
+msgid "IDS_EMAIL_BODY_USER_PASSWORD"
+msgstr "Κωδικός χÏήστη"
+
+msgid "IDS_EMAIL_HEADER_EDIT_RULES"
+msgstr "ΕπεξεÏγασία κανόνων"
+
+msgid "IDS_EMAIL_HEADER_EMAIL_SETTINGS"
+msgstr "Ρυθμίσεις email"
+
+msgid "IDS_EMAIL_HEADER_MAILBOXES"
+msgstr "Φάκελοι αλληλογÏαφίας"
+
+msgid "IDS_EMAIL_POP_ALERT"
+msgstr "Ειδοποίηση"
+
+msgid "IDS_EMAIL_POP_FILE_ALREADY_EXISTS"
+msgstr "Το αÏχείο υπάÏχει ήδη"
+
+msgid "IDS_EMAIL_POP_NO_SENDER"
+msgstr "ΧωÏίς αποστολέα"
+
+msgid "IDS_EMAIL_POP_SUCCEEDED"
+msgstr "Πέτυχε"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_ATTACH_MAXIMUM_NUMBER_OF_FILES_IS_PD"
+msgstr "Δεν είναι δυνατή η επισÏναψη. Ο μέγιστος αÏιθμός αÏχείων είναι %d"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_ATTACH_MAXIMUM_SIZE_OF_FILES_IS_PD_KB"
+msgstr "Δεν είναι δυνατή η επισÏναψη. Το μέγιστο ÏŒÏιο μεγέθους των αÏχείων είναι %d KB"
+
+msgid "IDS_EMAIL_POP_VALIDATION_FAILED"
+msgstr "Αποτυχία επικÏÏωσης"
+
+msgid "IDS_EMAIL_SK_REPLY_ALL"
+msgstr "Απάντ. σε όλους"
+
+msgid "IDS_EMAIL_BODY_1_ITEM"
+msgstr "1 στοιχείο"
+
+msgid "IDS_EMAIL_BODY_ADD_MY_NAMECARD"
+msgstr "ΠÏοσθήκη κάÏτας στοιχείων μου"
+
+msgid "IDS_EMAIL_BODY_ADD_SIGNATURE"
+msgstr "ΠÏοσθήκη υπογÏαφής"
+
+msgid "IDS_EMAIL_BODY_ALL_EMAILS"
+msgstr "Όλα τα email"
+
+msgid "IDS_EMAIL_BODY_ALWAYS_BCC_MYSELF"
+msgstr "Îα γίνεται πάντα Ιδ.Κοιν. σε εμένα"
+
+msgid "IDS_EMAIL_BODY_BCC"
+msgstr "ΙδιαίτεÏη κοινοποίηση"
+
+msgid "IDS_EMAIL_BODY_BLOCK_EMAILS"
+msgstr "Αποκλεισμός μηνυμάτων email"
+
+msgid "IDS_EMAIL_BODY_BODY"
+msgstr "Το σώμα μου"
+
+msgid "IDS_EMAIL_BODY_CC"
+msgstr "Κοιν."
+
+msgid "IDS_EMAIL_BODY_CC_BCC"
+msgstr "Κ./Ιδ.κ."
+
+msgid "IDS_EMAIL_BODY_CHECK_INTERVAL"
+msgstr "Έλεγχος διαστήματος"
+
+msgid "IDS_EMAIL_BODY_DEFAULT_ACCOUNT"
+msgstr "ΠÏοεπ. λογαÏιασμός"
+
+msgid "IDS_EMAIL_BODY_DRAFTS"
+msgstr "ΠÏόχειÏο"
+
+msgid "IDS_EMAIL_BODY_EMAIL_ACCOUNTS"
+msgstr "ΛογαÏιασμοί email"
+
+msgid "IDS_EMAIL_BODY_END_TIME"
+msgstr "ÎÏα λήξης"
+
+msgid "IDS_EMAIL_BODY_ENTIRE_EMAIL"
+msgstr "ΟλόκληÏο μήνυμα email"
+
+msgid "IDS_EMAIL_BODY_EXACTLY_THE_SAME_AS"
+msgstr "ΑκÏιβώς ίδιο με"
+
+msgid "IDS_EMAIL_BODY_EXAMPLE"
+msgstr "ΠαÏάδειγμα"
+
+msgid "IDS_EMAIL_BODY_FROM_M_SENDER"
+msgstr "Από:"
+
+msgid "IDS_EMAIL_BODY_INBOX"
+msgstr "ΕισεÏχόμενα"
+
+msgid "IDS_EMAIL_BODY_INCLUDE"
+msgstr "Îα συμπεÏιληφθεί"
+
+msgid "IDS_EMAIL_BODY_MATCH_CRITERIA"
+msgstr "Αντιστοίχιση κÏιτηÏίων"
+
+msgid "IDS_EMAIL_BODY_NOT_USED"
+msgstr "Δεν χÏησιμοποιείται"
+
+msgid "IDS_EMAIL_BODY_NO_ACCOUNTS"
+msgstr "Δεν υπάÏχουν λογαÏιασμοί"
+
+msgid "IDS_EMAIL_BODY_PD_DAYS"
+msgstr "%d ημέÏες"
+
+msgid "IDS_EMAIL_BODY_PD_ITEMS"
+msgstr "%d στοιχεία"
+
+msgid "IDS_EMAIL_BODY_PRIORITY"
+msgstr "ΠÏοτεÏαιότητα"
+
+msgid "IDS_EMAIL_BODY_RECEIVING_OPTIONS"
+msgstr "Επιλογές λήψης"
+
+msgid "IDS_EMAIL_BODY_SECURE_CONNECTION"
+msgstr "Ασφαλής σÏνδεση"
+
+msgid "IDS_EMAIL_BODY_SENDING_OPTIONS"
+msgstr "Επιλογές αποστολής"
+
+msgid "IDS_EMAIL_BODY_SENTBOX"
+msgstr "Απεσταλμένα"
+
+msgid "IDS_EMAIL_BODY_SERVER_URL"
+msgstr "URL διακομιστή"
+
+msgid "IDS_EMAIL_BODY_SIGNATURE"
+msgstr "ΥπογÏαφή"
+
+msgid "IDS_EMAIL_BODY_SPAMBOX"
+msgstr "Φάκελος ανεπιθÏμητης αλληλογÏαφίας"
+
+msgid "IDS_EMAIL_BODY_START_TIME"
+msgstr "ÎÏα έναÏξης"
+
+msgid "IDS_EMAIL_BODY_SYNC_SCHEDULE_TMO"
+msgstr "ΣυγχÏονισμός Ï€ÏογÏάμματος"
+
+msgid "IDS_EMAIL_BODY_TRASH"
+msgstr "ΑποÏÏίμματα"
+
+msgid "IDS_EMAIL_BODY_WITHOUT_ATTACHMENTS"
+msgstr "ΧωÏίς συνημμένα"
+
+msgid "IDS_EMAIL_BUTTON_GROUP"
+msgstr "Ομάδα"
+
+msgid "IDS_EMAIL_HEADER_ADD_RULES"
+msgstr "ΠÏοσθήκη κανόνων"
+
+msgid "IDS_EMAIL_OPT_ATTACH_ITEMS"
+msgstr "ΕπισÏναψη στοιχείου"
+
+msgid "IDS_EMAIL_OPT_EXCHANGE"
+msgstr "Exchange"
+
+msgid "IDS_EMAIL_OPT_FILE"
+msgstr "ΑÏχείο"
+
+msgid "IDS_EMAIL_OPT_NAMECARD"
+msgstr "ΚάÏτα στοιχειών"
+
+msgid "IDS_EMAIL_OPT_OPEN_URL"
+msgstr "Άνοιγμα διεÏθυνσης URL"
+
+msgid "IDS_EMAIL_OPT_SENDER"
+msgstr "Αποστολέας"
+
+msgid "IDS_EMAIL_OPT_SEND_EMAIL"
+msgstr "Αποστολή email"
+
+msgid "IDS_EMAIL_OPT_UPDATE_EXISTING"
+msgstr "ΕνημέÏωση υπάÏχοντων"
+
+msgid "IDS_EMAIL_POP_ADD_ACCOUNTS"
+msgstr "ΠÏοσθήκη λογαÏιασμών"
+
+msgid "IDS_EMAIL_POP_DOWNLOADING_ATTACHMENT_ING"
+msgstr "Λήψη συνημμένου..."
+
+msgid "IDS_EMAIL_POP_INVALID_EMAIL_ADDRESS"
+msgstr "Μη έγκυÏη διεÏθυνση email"
+
+msgid "IDS_EMAIL_POP_LOADING_CONTENTS_ING"
+msgstr "ΦόÏτωση πεÏιεχομένων..."
+
+msgid "IDS_EMAIL_POP_MAXIMUM_NUMBER_OF_ATTACHMENTS_REACHED"
+msgstr "ΣυμπληÏώθηκε ο μέγιστος αÏιθμός συνημμένων"
+
+msgid "IDS_EMAIL_POP_MOVE_TO_SPAMBOX_Q"
+msgstr "Μετακίνηση στο φάκελο ανεπιθÏμητης αλληλογÏαφίας;"
+
+msgid "IDS_EMAIL_POP_NO_RECIPIENTS_ADDED_ENTER_RECIPIENTS"
+msgstr "Δεν έχουν Ï€Ïοστεθεί παÏαλήπτες. Εισάγετε παÏαλήπτες"
+
+msgid "IDS_EMAIL_POP_PLEASE_FILL_ALL_THE_MANDATORY_FIELDS"
+msgstr "ΣυμπληÏώστε όλα τα υποχÏεωτικά πεδία"
+
+msgid "IDS_EMAIL_POP_SAVE_IN_DRAFTS_Q"
+msgstr "Αποθήκευση στα Ï€ÏόχειÏα"
+
+msgid "IDS_EMAIL_POP_THERE_IS_NO_ACCOUNT_CREATE_A_NEW_ACCOUNT_FIRST"
+msgstr "Δεν υπάÏχει κανένας λογαÏιασμός. ΔημιουÏγήστε ένα νέο λογαÏιασμό Ï€Ïώτα."
+
+msgid "IDS_EMAIL_POP_TOO_MANY_RECIPIENTS"
+msgstr "Μεγάλος αÏιθμός παÏαληπτών"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_DOWNLOAD"
+msgstr "Δεν είναι δυνατή η λήψη"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_ENTER_TEXT"
+msgstr "Δεν είναι δυνατή η εισαγωγή κειμένου"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_LAUNCH_APPLICATION"
+msgstr "ΑδÏνατη η εκκίνηση της εφαÏμογής"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_OPEN_ATTACHMENT"
+msgstr "Δεν ήταν δυνατό το άνοιγμα του συνημμένου"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_SAVE_ATTACHMENT"
+msgstr "Δεν ήταν δυνατή η αποθήκευση του συνημμένου"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_SAVE_IN_DRAFTS"
+msgstr "Δεν ήταν δυνατή η αποθήκευση στα ΠÏόχειÏα"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_SEND_EMAIL"
+msgstr "Δεν ήταν δυνατή η αποστολή email"
+
+msgid "IDS_EMAIL_POP_UNSUPPORTED_FILE_TYPE"
+msgstr "Μη υποστηÏιζόμενος Ï„Ïπος αÏχείου"
+
+msgid "IDS_EMAIL_POP_VALIDATING_ACCOUNT_ING"
+msgstr "Επαλήθευση λογαÏιασμοÏ..."
+
+msgid "IDS_EMAIL_SK_RESEND"
+msgstr "Επανάληψη αποστολής"
+
+msgid "IDS_EMAIL_BODY_ACCEPT_ALL_SSL_CERTIFICATES"
+msgstr "Αποδοχή όλων των πιστοποιητικών SSL"
+
+msgid "IDS_EMAIL_SK3_ACCOUNT_LIST"
+msgstr "Λίστα\nλογαÏ."
+
+msgid "IDS_EMAIL_BODY_USER_ID"
+msgstr "Ταυτότητα χÏήστη"
+
+msgid "IDS_EMAIL_POP_ACCOUNT_ALREADY_REGISTERED"
+msgstr "Ο λογαÏιασμός έχει ήδη καταχωÏηθεί"
+
+msgid "IDS_EMAIL_HEADER_ATTACH_FILE"
+msgstr "ΕπισÏναψη αÏχείου"
+
+msgid "IDS_EMAIL_BODY_EXCHANGE_SYNC_SETTINGS_MSG"
+msgstr "ΕνεÏγοποιώντας αυτή την εφαÏμογή, αποδέχεστε ότι μέÏος των δεδομένων της συσκευής σας (πεÏιλαμβανομένου του Î¼Î¿Î½Î±Î´Î¹ÎºÎ¿Ï Î±Î½Î±Î³Î½Ï‰ÏÎ¹ÏƒÏ„Î¹ÎºÎ¿Ï ÏƒÏ…ÏƒÎºÎµÏ…Î®Ï‚ και του ονόματος μοντέλου) θα αποθηκευτοÏν, θα υποστοÏν επεξεÏγασία και θα χÏησιμοποιηθοÏν από τη Samsung για την αναφοÏά της ενεÏγοποίησης της εφαÏμογής στους παÏέχοντες την άδεια χÏήσης του ίδιου του Î»Î¿Î³Î¹ÏƒÎ¼Î¹ÎºÎ¿Ï Ï„Î·Ï‚ εφαÏμογής. Τα δεδομένα που φυλάσσονται από τη Samsung θα υποστοÏν επεξεÏγασία σε αυστηÏή συμμόÏφωση με την πολιτική Î¹Î´Î¹Ï‰Ï„Î¹ÎºÎ¿Ï Î±Ï€Î¿ÏÏήτου της Samsung που είναι διαθέσιμα στη διεÏθυνση www.samsung.com. Θέλετε να συνεχίσετε;"
+
+msgid "IDS_EMAIL_BODY_FORWARD_WITH_FILES"
+msgstr "ΠÏοώθηση με αÏχεία"
+
+msgid "IDS_EMAIL_BODY_REPLY_WITH_BODY"
+msgstr "Απαν.με κÏÏιο κείμενο"
+
+msgid "IDS_EMAIL_BODY_NO_SUBJECT"
+msgstr "ΧωÏίς θέμα"
+
+msgid "IDS_EMAIL_BODY_FROM"
+msgstr "Από"
+
+msgid "IDS_EMAIL_BODY_NO_ADDRESS"
+msgstr "Καμία διεÏθυνση"
+
+msgid "IDS_EMAIL_OPT_RECORD_SOUND"
+msgstr "ΕγγÏαφή ήχου"
+
+msgid "IDS_EMAIL_OPT_RECORD_VIDEO"
+msgstr "ΕγγÏαφή βίντεο"
+
+msgid "IDS_EMAIL_OPT_INSERT_IMAGE"
+msgstr "Εισαγωγή εικόνας"
+
+msgid "IDS_EMAIL_OPT_ADD_TO_CALENDAR"
+msgstr "ΠÏοσθήκη στο ημεÏολόγιο"
+
+msgid "IDS_EMAIL_OPT_CHANGE_EMAIL_ADDRESS_ABB"
+msgstr "Αλλαγή διεÏθυνσης email"
+
+msgid "IDS_EMAIL_OPT_CLIPBOARD"
+msgstr "ΠÏόχειÏο"
+
+msgid "IDS_EMAIL_OPT_MARKED_AS_UNREAD"
+msgstr "Σήμανση ως μη αναγνωσμένο"
+
+msgid "IDS_EMAIL_OPT_VIEW_CONTACT_DETAILS"
+msgstr "ΠÏοβολή λεπτομεÏειών επαφής"
+
+msgid "IDS_EMAIL_POP_SAVED_IN_DRAFTS"
+msgstr "ΑποθηκεÏτηκε στα Ï€ÏόχειÏα"
+
+msgid "IDS_EMAIL_POP_NETWORK_BUSY"
+msgstr "Κατειλημμένο δίκτυο"
+
+msgid "IDS_EMAIL_POP_LOGIN_ALLOWED_ONLY_EVERY_PD_MINUTES"
+msgstr "Login allowed only every %d minutes"
+
+msgid "IDS_EMAIL_POP_HOST_NOT_FOUND"
+msgstr "Δεν εντοπίστηκε ο κεντÏικός υπολογιστής"
+
+msgid "IDS_EMAIL_POP_HOST_NOT_REACHABLE"
+msgstr "Δεν είναι δυνατή η Ï€Ïόσβαση στον κεντÏικό υπολογιστή"
+
+msgid "IDS_EMAIL_POP_NO_SERVICE"
+msgstr "Μη διαθέσιμη υπηÏεσία"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_FORWARD_DRM_CONTENTS"
+msgstr "Δεν ήταν δυνατή η Ï€Ïοώθηση πεÏιεχομένων DRM"
+
+msgid "IDS_EMAIL_POP_BLOCKED"
+msgstr "Αποκλεισμένο"
+
+msgid "IDS_EMAIL_POP_1_EMAIL_SELECTED"
+msgstr "Επιλέχθηκε 1 email"
+
+msgid "IDS_EMAIL_POP_PD_EMAILS_SELECTED"
+msgstr "%d email επιλέχθηκαν"
+
+msgid "IDS_EMAIL_POP_1_RECIPIENT_SELECTED"
+msgstr "1 επιλογή αποδέκτη"
+
+msgid "IDS_EMAIL_POP_PD_RECIPIENTS_SELECTED"
+msgstr "Επιλογή %d αποδεκτών"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_ADD_ACCOUNT"
+msgstr "Δεν είναι δυνατή η Ï€Ïοσθήκη του λογαÏιασμοÏ"
+
+msgid "IDS_EMAIL_SK3_MOVE_HERE"
+msgstr "Μετακίνηση εδώ"
+
diff --git a/po/email.pot b/po/email.pot
new file mode 100755
index 0000000..c979cde
--- /dev/null
+++ b/po/email.pot
@@ -0,0 +1,1546 @@
+# SOME DESCRIPTIVE TITLE.
+# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
+# This file is distributed under the same license as the PACKAGE package.
+# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
+#
+#, fuzzy
+msgid ""
+msgstr ""
+"Project-Id-Version: PACKAGE VERSION\n"
+"Report-Msgid-Bugs-To: \n"
+"POT-Creation-Date: 2011-05-11 17:44-0700\n"
+"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
+"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
+"Language-Team: LANGUAGE <LL@li.org>\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=CHARSET\n"
+"Content-Transfer-Encoding: 8bit\n"
+
+#. snprintf(buf, sizeof(buf), "%s", N_("Accounts"));
+#: account/email-account.c:396 mailbox/email-mailbox.c:6069
+#: setting/email-view-setting.c:411
+msgid "IDS_COM_BODY_ACCOUNTS"
+msgstr ""
+
+#: account/email-account.c:448
+msgid "IDS_EMAIL_SK_UPDATE"
+msgstr ""
+
+#: account/email-account.c:787
+#, c-format
+msgid "IDS_EMAIL_BODY_NO_TEXT"
+msgstr ""
+
+#: account/email-account.c:830 mailbox/email-mailbox.c:4432
+#: mailbox/email-mailbox.c:6375 mailbox/email-mailbox.c:7485
+#: mailbox/email-mailbox.c:8218
+msgid "IDS_EMAIL_BODY_ALL_EMAILS"
+msgstr ""
+
+#: account/email-account.c:1232 mailbox/email-mailbox.c:4023
+msgid "IDS_COM_POP_EMPTY"
+msgstr ""
+
+#: block/email-block.c:502 composer/email-composer-callback.c:1520
+msgid "IDS_COM_ADD"
+msgstr ""
+
+#: block/email-block.c:511 block/email-block.c:863 block/email-block.c:1222
+msgid "IDS_COM_POP_ADDRESS"
+msgstr ""
+
+#: block/email-block.c:512 block/email-block.c:868 block/email-block.c:1201
+#: mailbox/email-mailbox.c:6284 composer/email-composer-contents.c:70
+#: composer/email-composer-util.c:2421 composer/email-composer-util.c:2425
+#: composer/email-composer-util.c:2604
+msgid "IDS_COM_BODY_SUBJECT"
+msgstr ""
+
+#. elm_button_label_set(ug_data->edit_button, _("Edit"));
+#. Change button label
+#. elm_button_label_set(ug_data->edit_button, _("Edit"));
+#. elm_button_label_set(edit_btn, _("Edit"));
+#. elm_navigationbar_ex_item_title_label_set(mailbox_sg->navibar_item[mailbox_sg->previous_view], _("Edit"));
+#: block/email-block.c:543 block/email-block.c:1368 block/email-block.c:2058
+#: mailbox/email-mailbox.c:6103 mailbox/email-mailbox.c:6776
+#: setting/email-view-account-edit.c:1105
+#: composer/email-composer-callback.c:432
+msgid "IDS_COM_SK_EDIT"
+msgstr ""
+
+#: block/email-block.c:573 setting/email-view-setting.c:395
+#: setting/email-view-setting.c:777
+msgid "IDS_EMAIL_BODY_BLOCK_EMAILS"
+msgstr ""
+
+#. elm_nocontents_label_set(ug_data->noc, N_("No content"));
+#: block/email-block.c:739
+msgid "IDS_EMAIL_BODY_NO_CONTENTS"
+msgstr ""
+
+#: block/email-block.c:929 setting/email-view-account-edit.c:1101
+#: setting/email-view-other-account.c:975
+#: setting/email-view-server-type.c:1167
+msgid "IDS_COM_SK_SAVE"
+msgstr ""
+
+#. elm_button_label_set(ug_data->l_button3, _("Cancel"));
+#. elm_button_label_set(button, "Cancel");
+#. elm_button_label_set(cancel_button, _("Cancel"));
+#. elm_button_label_set(third_button, "Cancel");
+#: block/email-block.c:935 block/email-block.c:1874
+#: mailbox/email-mailbox.c:2832 mailbox/email-mailbox.c:6186
+#: popup/email-popup.c:507 setting/email-view-account-edit.c:523
+#: setting/email-view-account-edit.c:556
+#: setting/email-view-other-account.c:359 setting/email-view-server-type.c:294
+#: setting/email-view-setting.c:314 viewer/email-viewer.c:5127
+#: viewer/email-viewer.c:5129 viewer/email-viewer.c:5131
+#: viewer/email-viewer.c:5133 viewer/email-viewer.c:5313
+#: composer/email-composer.c:387 composer/email-composer-callback.c:100
+#: composer/email-composer-callback.c:1070 composer/email-composer-util.c:1343
+#: composer/email-composer-util.c:1388
+msgid "IDS_COM_SK_CANCEL"
+msgstr ""
+
+#: block/email-block.c:940
+msgid "IDS_EMAIL_HEADER_EDIT_RULES"
+msgstr ""
+
+#: block/email-block.c:944
+msgid "IDS_EMAIL_HEADER_ADD_RULES"
+msgstr ""
+
+#: block/email-block.c:986 setting/email-view-account-edit.c:589
+#: setting/email-view-other-account.c:467
+#: setting/email-view-other-account.c:525 setting/email-view-server-type.c:383
+msgid "IDS_EMAIL_POP_PLEASE_FILL_ALL_THE_MANDATORY_FIELDS"
+msgstr ""
+
+#: block/email-block.c:987 block/email-block.c:1025 block/email-block.c:1064
+#: block/email-block.c:1146 mailbox/email-mailbox.c:2314
+#: viewer/email-viewer.c:3755
+msgid "IDS_EMAIL_POP_ALERT"
+msgstr ""
+
+#: block/email-block.c:1024 setting/email-view-other-account.c:476
+#: setting/email-view-other-account.c:546
+#: composer/email-composer-callback.c:491
+#: composer/email-composer-callback.c:521
+#: composer/email-composer-callback.c:551
+#: composer/email-composer-callback.c:945 composer/email-composer-util.c:1899
+msgid "IDS_EMAIL_POP_INVALID_EMAIL_ADDRESS"
+msgstr ""
+
+#. elm_popup_desc_set(ug_data->popup_empty, _("IDS_EMAIL_POP_INVALID_SUBJECT"));
+#. elm_popup_desc_set(ug_data->popup_empty, dgettext("sys_string", "IDS_COM_POP_EMPTY")); //print EMPTY
+#: block/email-block.c:1063
+msgid "Empty subject"
+msgstr ""
+
+#: block/email-block.c:1143
+msgid "Already blocked for this address"
+msgstr ""
+
+#: block/email-block.c:1145
+msgid "Already blocked for this subject"
+msgstr ""
+
+#: block/email-block.c:1213 mailbox/email-mailbox.c:4757
+msgid "No subject"
+msgstr ""
+
+#: block/email-block.c:1234
+msgid "No address"
+msgstr ""
+
+#. Change button label
+#. elm_button_label_set(ug_data->edit_button, _("Done"));
+#: block/email-block.c:1304 block/email-block.c:2258
+#: composer/email-composer-recent.c:79
+msgid "IDS_COM_SK_DONE"
+msgstr ""
+
+#. elm_button_label_set(g_delete_button, _("Delete"));
+#: block/email-block.c:1315 block/email-block.c:2066
+#: mailbox/email-mailbox.c:3177 mailbox/email-mailbox.c:6203
+#: setting/email-view-account-edit.c:1085 viewer/email-viewer.c:639
+#: composer/email-composer-callback.c:424
+#: composer/email-composer-callback.c:431
+msgid "IDS_COM_SK_DELETE"
+msgstr ""
+
+#. elm_layout_text_set(ug_data->select_all_layout, "elm.text", "Select All");
+#. elm_layout_text_set(mailbox_sg->select_all_layout, "elm.text", "Select All");
+#. elm_layout_text_set(ugd->select_all_layout, "elm.text", "Select all");
+#: block/email-block.c:1337 block/email-block.c:2315
+#: mailbox/email-mailbox.c:6766 composer/email-composer-recent.c:144
+msgid "IDS_COM_BODY_SELECT_ALL"
+msgstr ""
+
+#: block/email-block.c:1683 composer/email-composer-callback.c:1544
+#: composer/email-composer-recipient.c:164
+msgid "IDS_COM_BODY_CONTACTS"
+msgstr ""
+
+#. elm_button_label_set(ugd->recent_button, _("Recent"));
+#: block/email-block.c:1692 block/email-block.c:2273 block/email-block.c:2283
+#: setting/email-view-setting.c:446 setting/email-view-setting.c:767
+#: setting/email-view-show-email-list.c:161
+#: composer/email-composer-recent.c:92 composer/email-composer-recent.c:104
+#: composer/email-composer-recipient.c:156
+msgid "IDS_COM_BUTTON_RECENT"
+msgstr ""
+
+#. elm_entry_entry_set(elm_editfield_entry_get(ug_data->ef_match), _("IDS_EMAIL_BODY_EXACTLY_THE_SAME_AS"));
+#: block/email-block.c:1832 block/email-block.c:1896
+msgid "IDS_EMAIL_BODY_EXACTLY_THE_SAME_AS"
+msgstr ""
+
+#. elm_entry_entry_set(elm_editfield_entry_get(ug_data->ef_match), _("IDS_EMAIL_BODY_INCLUDES"));
+#: block/email-block.c:1847 block/email-block.c:1902
+msgid "IDS_EMAIL_BODY_INCLUDES"
+msgstr ""
+
+#. elm_button_label_set(ug_data->r_button3, _("Set"));
+#. p->icon = elm_icon_add(p->r_button);
+#. snprintf(buf, sizeof(buf), "%s/logo_small.png", ICON_DIR);
+#. elm_icon_file_set(p->icon, buf, NULL);
+#. elm_button_icon_set(p->r_button, p->icon);
+#: block/email-block.c:1879
+#: setting/email-view-receiving-option-mailbox-setup.c:128
+#: setting/email-view-receiving-option-size.c:342
+msgid "IDS_COM_SK_SET"
+msgstr ""
+
+#: block/email-block.c:1882
+msgid "IDS_EMAIL_BODY_MATCH_CRITERIA"
+msgstr ""
+
+#: block/email-block.c:1938 mailbox/email-mailbox.c:4739
+#: mailbox/email-mailbox.c:4747
+msgid "IDS_COM_BODY_NO_NAME"
+msgstr ""
+
+#: block/email-block.c:2265
+msgid "IDS_COM_BODY_BACK"
+msgstr ""
+
+#: block/email-block.c:2715 mailbox/email-mailbox.c:3661
+#: mailbox/email-mailbox.c:7562 viewer/email-viewer.c:6200
+#: composer/email-composer-recent.c:372
+msgid "IDS_COM_BODY_NO_CONTENTS"
+msgstr ""
+
+#: block/email-block.c:2736
+#, c-format
+msgid "%d address selected"
+msgstr ""
+
+#: block/email-block.c:2738
+#, c-format
+msgid "%d addresses selected"
+msgstr ""
+
+#. elm_button_label_set(left_bt, _("Yes"));
+#: common/email-dialog-util.c:136 viewer/email-viewer.c:2797
+msgid "IDS_COM_SK_YES"
+msgstr ""
+
+#. elm_button_label_set(right_bt, _("No"));
+#: common/email-dialog-util.c:144 viewer/email-viewer.c:2797
+msgid "IDS_COM_SK_NO"
+msgstr ""
+
+#: common/email-utils.c:39
+msgid "JAN"
+msgstr ""
+
+#: common/email-utils.c:40
+msgid "FEB"
+msgstr ""
+
+#: common/email-utils.c:41
+msgid "MAR"
+msgstr ""
+
+#: common/email-utils.c:42
+msgid "APR"
+msgstr ""
+
+#: common/email-utils.c:43
+msgid "MAY"
+msgstr ""
+
+#: common/email-utils.c:44
+msgid "JUN"
+msgstr ""
+
+#: common/email-utils.c:45
+msgid "JUL"
+msgstr ""
+
+#: common/email-utils.c:46
+msgid "AUG"
+msgstr ""
+
+#: common/email-utils.c:47
+msgid "SEP"
+msgstr ""
+
+#: common/email-utils.c:48
+msgid "OCT"
+msgstr ""
+
+#: common/email-utils.c:49
+msgid "NOV"
+msgstr ""
+
+#: common/email-utils.c:50
+msgid "DEC"
+msgstr ""
+
+#: common/email-utils.c:52 composer/email-composer-util.c:55
+msgid "IDS_COM_BODY_JAN"
+msgstr ""
+
+#: common/email-utils.c:53 composer/email-composer-util.c:56
+msgid "IDS_COM_BODY_FEB"
+msgstr ""
+
+#: common/email-utils.c:54 composer/email-composer-util.c:57
+msgid "IDS_COM_BODY_MAR"
+msgstr ""
+
+#: common/email-utils.c:55 composer/email-composer-util.c:58
+msgid "IDS_COM_BODY_APR"
+msgstr ""
+
+#: common/email-utils.c:56 composer/email-composer-util.c:59
+msgid "IDS_COM_BODY_MAY"
+msgstr ""
+
+#: common/email-utils.c:57 composer/email-composer-util.c:60
+msgid "IDS_COM_BODY_JUN"
+msgstr ""
+
+#: common/email-utils.c:58 composer/email-composer-util.c:61
+msgid "IDS_COM_BODY_JUL"
+msgstr ""
+
+#: common/email-utils.c:59 composer/email-composer-util.c:62
+msgid "IDS_COM_BODY_AUG"
+msgstr ""
+
+#: common/email-utils.c:60 composer/email-composer-util.c:63
+msgid "IDS_COM_BODY_SEP"
+msgstr ""
+
+#: common/email-utils.c:61 composer/email-composer-util.c:64
+msgid "IDS_COM_BODY_OCT"
+msgstr ""
+
+#: common/email-utils.c:62 composer/email-composer-util.c:65
+msgid "IDS_COM_BODY_NOV"
+msgstr ""
+
+#: common/email-utils.c:63 composer/email-composer-util.c:66
+msgid "IDS_COM_BODY_DEC"
+msgstr ""
+
+#: common/email-utils.c:406 viewer/email-viewer.c:1530
+#: viewer/email-viewer.c:1623 viewer/email-viewer.c:1694
+msgid "B"
+msgstr ""
+
+#: common/email-utils.c:413 viewer/email-viewer.c:1538
+#: viewer/email-viewer.c:1631 viewer/email-viewer.c:1701
+#: composer/email-composer-attachment.c:356
+#: composer/email-composer-attachment.c:373
+msgid "KB"
+msgstr ""
+
+#: common/email-utils.c:420 viewer/email-viewer.c:1546
+#: viewer/email-viewer.c:1639 viewer/email-viewer.c:1708
+#: composer/email-composer-attachment.c:356
+#: composer/email-composer-attachment.c:373
+msgid "MB"
+msgstr ""
+
+#: common/email-utils.c:424 viewer/email-viewer.c:1551
+#: viewer/email-viewer.c:1644 viewer/email-viewer.c:1713
+msgid "GB"
+msgstr ""
+
+#. strcpy(date, N_("Sun"));
+#. sprintf(wday, "%s", N_("Sun"));
+#: common/email-utils.c:933 composer/email-composer-util.c:1611
+msgid "IDS_COM_BODY_SUN"
+msgstr ""
+
+#. strcpy(date, "Mon");
+#: common/email-utils.c:937 composer/email-composer-util.c:1614
+msgid "IDS_COM_BODY_MON"
+msgstr ""
+
+#. strcpy(date, "Tue");
+#: common/email-utils.c:941 composer/email-composer-util.c:1617
+msgid "IDS_COM_BODY_TUE"
+msgstr ""
+
+#. strcpy(date, "Wed");
+#: common/email-utils.c:945 composer/email-composer-util.c:1620
+msgid "IDS_COM_BODY_WED"
+msgstr ""
+
+#. strncpy(date, "Thu");
+#: common/email-utils.c:949 composer/email-composer-util.c:1623
+msgid "IDS_COM_BODY_THU"
+msgstr ""
+
+#. strcpy(date, "Fri");
+#: common/email-utils.c:953 composer/email-composer-util.c:1626
+msgid "IDS_COM_BODY_FRI"
+msgstr ""
+
+#. strcpy(date, "Sat");
+#: common/email-utils.c:957 composer/email-composer-util.c:1629
+msgid "IDS_COM_BODY_SAT"
+msgstr ""
+
+#: common/email-utils.c:966
+msgid "IDS_COM_BODY_TODAY"
+msgstr ""
+
+#: common/email-utils.c:973
+msgid "IDS_COM_BODY_YESTERDAY"
+msgstr ""
+
+#: common/email-utils.c:979
+msgid "IDS_COM_BODY_PREVIOUS_DAYS"
+msgstr ""
+
+#. (t2_hour < 12) ? _("AM") : _("PM"));
+#: common/email-utils.c:1039 composer/email-composer-util.c:1594
+msgid "IDS_COM_BODY_AM"
+msgstr ""
+
+#: common/email-utils.c:1039 composer/email-composer-util.c:1594
+msgid "IDS_COM_POP_PM"
+msgstr ""
+
+#. elm_popup_desc_set(popup,N_("<b>Adding an account</b> <br>Default account is not set.<br>Move to account wizard."));
+#. ugd->popup_one = email_setting_get_auto_notify(vd, dgettext("sys_string", "IDS_COM_POP_NO_ACCOUNTS"));
+#: mailbox/email-mailbox.c:2313 mailbox/email-mailbox.c:5973
+#: mailbox/email-mailbox.c:6011 mailbox/email-mailbox.c:6304
+#: mailbox/email-mailbox.c:6441 setting/email-view-setting.c:165
+#: setting/email-view-setting.c:192 setting/email-view-setting.c:213
+#: setting/email-view-setting.c:629 composer/email-composer.c:1302
+msgid "IDS_EMAIL_POP_THERE_IS_NO_ACCOUNT_CREATE_A_NEW_ACCOUNT_FIRST"
+msgstr ""
+
+#. elm_popup_buttons_add(ugd->popup_color, 2, "Ok", ELM_POPUP_RESPONSE_OK, "Cancel", ELM_POPUP_RESPONSE_CANCEL, NULL);
+#: mailbox/email-mailbox.c:2315 mailbox/email-mailbox.c:7152
+#: mailbox/email-mailbox.c:7214 setting/email-view-account-edit.c:488
+#: setting/email-view-account-edit.c:493 setting/email-view-account-edit.c:556
+#: setting/email-view-account-edit.c:589
+#: setting/email-view-other-account.c:319
+#: setting/email-view-other-account.c:323
+#: setting/email-view-other-account.c:398
+#: setting/email-view-other-account.c:400
+#: setting/email-view-other-account.c:467
+#: setting/email-view-other-account.c:476
+#: setting/email-view-other-account.c:525
+#: setting/email-view-other-account.c:535
+#: setting/email-view-other-account.c:546 setting/email-view-server-type.c:254
+#: setting/email-view-server-type.c:259 setting/email-view-server-type.c:332
+#: setting/email-view-server-type.c:334 setting/email-view-server-type.c:383
+#: setting/email-view-setting.c:314 viewer/email-viewer.c:2320
+#: viewer/email-viewer.c:2786 viewer/email-viewer.c:4113
+#: viewer/email-viewer.c:4472 viewer/email-viewer.c:5235
+#: viewer/email-viewer.c:5781 viewer/email-viewer.c:5964
+#: viewer/email-viewer.c:6007 viewer/email-viewer.c:6018
+#: viewer/email-viewer.c:6135 viewer/email-viewer.c:6137
+#: viewer/email-viewer.c:6139 viewer/email-viewer.c:7773
+#: viewer/email-viewer.c:7808 viewer/email-viewer.c:7963
+#: viewer/email-viewer.c:8010 viewer/email-viewer.c:8014
+#: viewer/email-viewer.c:8018 composer/email-composer.c:387
+#: composer/email-composer.c:1915 composer/email-composer-callback.c:100
+#: composer/email-composer-util.c:1343
+msgid "IDS_COM_SK_OK"
+msgstr ""
+
+#. Mail send is cancelled . Change the label of button to Resend
+#. elm_button_label_set(obj, "Resend");
+#. elm_button_label_set(button, "Resend");
+#: mailbox/email-mailbox.c:2747 mailbox/email-mailbox.c:2849
+#: viewer/email-viewer.c:686
+msgid "IDS_EMAIL_SK_RESEND"
+msgstr ""
+
+#. Trash or Spam Box. Set Label as Move
+#. ug_data->item[2] = elm_controlbar_tool_item_append(obj, NULL, N_("Calendar"), ev_sk_add_to_calendar_cb, ug_data);
+#: mailbox/email-mailbox.c:3140 mailbox/email-mailbox.c:4948
+#: mailbox/email-mailbox.c:6253 mailbox/email-mailbox.c:7726
+#: viewer/email-viewer.c:638
+msgid "IDS_COM_BODY_MOVE"
+msgstr ""
+
+#. elm_button_label_set(button, N_("Mark as Read"));
+#: mailbox/email-mailbox.c:3149 mailbox/email-mailbox.c:3163
+msgid "IDS_EMAIL_OPT_MARK_AS_READ"
+msgstr ""
+
+#. elm_button_label_set(button, N_("Mark as Unread"));
+#: mailbox/email-mailbox.c:3152 mailbox/email-mailbox.c:3166
+msgid "IDS_EMAIL_OPT_MARK_AS_UNREAD"
+msgstr ""
+
+#: mailbox/email-mailbox.c:3646 mailbox/email-mailbox.c:7553
+#: mailbox/email-mailbox.c:8102
+msgid "No search result"
+msgstr ""
+
+#: mailbox/email-mailbox.c:4037
+msgid "Loading more emails"
+msgstr ""
+
+#: mailbox/email-mailbox.c:4080
+msgid "Move to email account setting"
+msgstr ""
+
+#: mailbox/email-mailbox.c:4084
+msgid "Welcome to Email App"
+msgstr ""
+
+#: mailbox/email-mailbox.c:4483 mailbox/email-mailbox.c:8199
+#: mailbox/email-mailbox.c:8227 setting/email-view-setting.c:445
+#: setting/email-view-setting.c:766 setting/email-view-show-email-list.c:160
+#, c-format
+msgid "IDS_EMAIL_BODY_PD_EMAILS"
+msgstr ""
+
+#: mailbox/email-mailbox.c:4767 mailbox/email-mailbox.c:7121
+msgid "IDS_EMAIL_POP_NO_SENDER"
+msgstr ""
+
+#: mailbox/email-mailbox.c:6037
+msgid "IDS_COM_POP_DATE"
+msgstr ""
+
+#: mailbox/email-mailbox.c:6038
+msgid "IDS_EMAIL_OPT_SENDER"
+msgstr ""
+
+#: mailbox/email-mailbox.c:6039
+msgid "IDS_EMAIL_OPT_UNREAD"
+msgstr ""
+
+#: mailbox/email-mailbox.c:6132
+msgid "IDS_COM_POP_UPDATE"
+msgstr ""
+
+#: mailbox/email-mailbox.c:6151 composer/email-composer.c:843
+msgid "IDS_EMAIL_SK_COMPOSE"
+msgstr ""
+
+#: mailbox/email-mailbox.c:6227 viewer/email-viewer.c:3001
+#: viewer/email-viewer.c:3051 viewer/email-viewer.c:4295
+msgid "IDS_EMAIL_OPT_BLOCK"
+msgstr ""
+
+#: mailbox/email-mailbox.c:6283
+msgid "IDS_COM_BODY_ALL"
+msgstr ""
+
+#. ugd->from_popup = elm_popup_add(ugd->main_layout);
+#. sprintf(from_str, "%s %s", _("IDS_EMAIL_BODY_FROM_M_SENDER"), ": ");
+#: mailbox/email-mailbox.c:6285 composer/email-composer-callback.c:1200
+#: composer/email-composer-recipient.c:127
+#: composer/email-composer-recipient.c:131
+#: composer/email-composer-recipient.c:361 composer/email-composer-util.c:2394
+#: composer/email-composer-util.c:2398 composer/email-composer-util.c:2586
+msgid "IDS_EMAIL_BODY_FROM_M_SENDER"
+msgstr ""
+
+#: mailbox/email-mailbox.c:6286 popup/email-popup.c:443
+#: viewer/email-viewer.c:863 viewer/email-viewer.c:1318
+#: composer/email-composer-recipient.c:27
+#: composer/email-composer-recipient.c:80
+#: composer/email-composer-recipient.c:83 composer/email-composer-util.c:2412
+#: composer/email-composer-util.c:2416 composer/email-composer-util.c:2596
+#: composer/email-composer-util.c:2600
+msgid "IDS_COM_BODY_TO"
+msgstr ""
+
+#: mailbox/email-mailbox.c:7151
+msgid "Selected mail's sender was blocked"
+msgstr ""
+
+#: mailbox/email-mailbox.c:7213
+msgid "Selected sender was blocked"
+msgstr ""
+
+#: mailbox/email-mailbox.c:8075
+msgid "IDS_COM_BODY_SEARCH"
+msgstr ""
+
+#: mailbox/email-mailbox.c:8315
+#, c-format
+msgid "%d thread selected"
+msgstr ""
+
+#: mailbox/email-mailbox.c:8317
+#, c-format
+msgid "%d threads selected"
+msgstr ""
+
+#: mailbox/email-mailbox.c:8322
+#, c-format
+msgid "%d sender selected"
+msgstr ""
+
+#: mailbox/email-mailbox.c:8324
+#, c-format
+msgid "%d senders selected"
+msgstr ""
+
+#: mailbox/email-mailbox.c:8329
+#, c-format
+msgid "%d email selected"
+msgstr ""
+
+#: mailbox/email-mailbox.c:8331
+#, c-format
+msgid "%d emails selected"
+msgstr ""
+
+#: main/email.c:94 viewer/email-viewer.c:238
+msgid "Application template"
+msgstr ""
+
+#: main/email.c:95 viewer/email-viewer.c:239
+msgid "Click to exit"
+msgstr ""
+
+#: popup/email-popup.c:443 composer/email-composer-callback.c:958
+msgid "IDS_EMAIL_POP_UNABLE_TO_SEND_EMAIL"
+msgstr ""
+
+#: popup/email-popup.c:443
+msgid "IDS_COM_BODY_DETAILS_TITLE"
+msgstr ""
+
+#: popup/email-popup.c:473
+msgid "IDS_COM_SK_RETRY"
+msgstr ""
+
+#: popup/email-popup.c:490
+msgid "Retry in 5 minutes"
+msgstr ""
+
+#: setting/email-setting.c:901 setting/email-view-other-account.c:288
+#: setting/email-view-server-type.c:219
+msgid "IDS_EMAIL_POP_SUCCEEDED"
+msgstr ""
+
+#: setting/email-setting-account-set.c:134
+#: setting/email-setting-account-set.c:202
+#: setting/email-setting-account-set.c:270
+#: setting/email-setting-account-set.c:340
+#: setting/email-setting-account-set.c:406
+#: setting/email-setting-account-set.c:475
+#: setting/email-setting-account-set.c:544 composer/email-composer-util.c:2649
+#: composer/email-composer-util.c:2691 composer/email-composer-util.c:3032
+#: composer/email-composer-util.c:3034 composer/email-composer-util.c:3087
+msgid "Sent from SLP"
+msgstr ""
+
+#: setting/email-setting-utils.c:921 viewer/email-viewer.c:8072
+#: composer/email-composer-util.c:3404
+msgid "PDP activation failure:Transport Error"
+msgstr ""
+
+#: setting/email-setting-utils.c:926 viewer/email-viewer.c:8077
+#: composer/email-composer-util.c:3409
+msgid "PDP activation failure:IP full"
+msgstr ""
+
+#: setting/email-setting-utils.c:931 viewer/email-viewer.c:8082
+#: composer/email-composer-util.c:3414
+msgid "Network busy"
+msgstr ""
+
+#: setting/email-setting-utils.c:936 viewer/email-viewer.c:8087
+#: composer/email-composer-util.c:3419
+msgid "Login allowed only every 15 minutes"
+msgstr ""
+
+#. ret = N_("Connection failure:Unknown");
+#: setting/email-setting-utils.c:942 viewer/email-viewer.c:8093
+#: composer/email-composer-util.c:3425
+msgid "IDS_COM_POP_CONNECTION_FAILED"
+msgstr ""
+
+#: setting/email-setting-utils.c:947
+msgid "Incorrect username or password"
+msgstr ""
+
+#: setting/email-setting-utils.c:952 viewer/email-viewer.c:8103
+#: composer/email-composer-util.c:3435
+msgid "Authentication failure"
+msgstr ""
+
+#: setting/email-setting-utils.c:957 viewer/email-viewer.c:8108
+#: composer/email-composer-util.c:3440
+msgid "Download canceled"
+msgstr ""
+
+#: setting/email-setting-utils.c:962 viewer/email-viewer.c:8113
+#: composer/email-composer-util.c:3445
+msgid "This mail was deleted at server side"
+msgstr ""
+
+#: setting/email-setting-utils.c:967 viewer/email-viewer.c:8118
+#: composer/email-composer-util.c:3450
+msgid "No such host"
+msgstr ""
+
+#: setting/email-setting-utils.c:972 viewer/email-viewer.c:8123
+#: composer/email-composer-util.c:3455
+msgid "Server unavailable"
+msgstr ""
+
+#: setting/email-setting-utils.c:977 viewer/email-viewer.c:8128
+#: composer/email-composer-util.c:3460
+msgid "No service"
+msgstr ""
+
+#: setting/email-setting-utils.c:982 viewer/email-viewer.c:8133
+#: composer/email-composer-util.c:3465
+msgid "Other failure"
+msgstr ""
+
+#: setting/email-view-account-edit.c:363
+msgid "IDS_COM_POP_DELETED"
+msgstr ""
+
+#: setting/email-view-account-edit.c:370
+msgid "IDS_COM_POP_UNABLE_TO_DELETE"
+msgstr ""
+
+#. ugd->popup_one = email_setting_get_auto_notify(vd, N_("Success to Edit Account"));
+#: setting/email-view-account-edit.c:454
+msgid "Succeeded in editing account"
+msgstr ""
+
+#: setting/email-view-account-edit.c:487 setting/email-view-server-type.c:253
+msgid "Creating account is canceled"
+msgstr ""
+
+#: setting/email-view-account-edit.c:492 setting/email-view-server-type.c:258
+msgid "IDS_EMAIL_POP_VALIDATION_FAILED"
+msgstr ""
+
+#: setting/email-view-account-edit.c:523
+#: setting/email-view-other-account.c:359 setting/email-view-server-type.c:294
+msgid "IDS_EMAIL_POP_VALIDATING_ACCOUNT_ING"
+msgstr ""
+
+#: setting/email-view-account-edit.c:556 viewer/email-viewer.c:2797
+msgid "IDS_COM_POP_DELETE_Q"
+msgstr ""
+
+#. elm_editfield_label_set(p->ef_incoming_port, _("Incoming Port"));
+#: setting/email-view-account-edit.c:712 setting/email-view-account-edit.c:821
+#: setting/email-view-account-edit.c:918 setting/email-view-account-edit.c:982
+#: setting/email-view-server-type.c:681
+msgid "IDS_EMAIL_BODY_INCOMING_PORT"
+msgstr ""
+
+#. elm_editfield_label_set(p->ef_smtp_port, N_("SMTP port"));
+#: setting/email-view-account-edit.c:713 setting/email-view-account-edit.c:823
+#: setting/email-view-account-edit.c:919 setting/email-view-account-edit.c:994
+#: setting/email-view-server-type.c:637
+msgid "IDS_EMAIL_BODY_OUTGOING_PORT"
+msgstr ""
+
+#. set entry name
+#: setting/email-view-account-edit.c:717 setting/email-view-account-edit.c:816
+#: setting/email-view-account-edit.c:913 setting/email-view-account-edit.c:952
+#: setting/email-view-other-account.c:826
+#: setting/email-view-other-account.c:852
+#: setting/email-view-other-account.c:889
+msgid "IDS_EMAIL_BODY_ACCOUNT_NAME"
+msgstr ""
+
+#. p->ly_title3 = elm_layout_add(p->bx);
+#. elm_layout_file_set(p->ly_title3, EV_THEME_PATH, "email.title.nbeat");
+#. evas_object_size_hint_align_set(p->ly_title3, EVAS_HINT_FILL, EVAS_HINT_FILL);
+#. evas_object_show(p->ly_title3);
+#. elm_box_pack_end(p->bx, p->ly_title3);
+#. edje_object_part_text_set(_EDJ(p->ly_title3), "elm.text", dgettext("sys_string", "IDS_COM_BODY_AUTH_PASSWORD"));
+#: setting/email-view-account-edit.c:771 setting/email-view-account-edit.c:819
+#: setting/email-view-account-edit.c:916 setting/email-view-account-edit.c:964
+#: setting/email-view-other-account.c:763
+#: setting/email-view-other-account.c:835
+#: setting/email-view-other-account.c:860
+#: setting/email-view-other-account.c:931
+msgid "IDS_COM_BODY_AUTH_PASSWORD"
+msgstr ""
+
+#: setting/email-view-account-edit.c:772 setting/email-view-account-edit.c:825
+#: setting/email-view-account-edit.c:922
+#: setting/email-view-account-edit.c:1002
+msgid "Sending Password"
+msgstr ""
+
+#. edje_object_part_text_set(_EDJ(p->ly_title1), "elm.text", dgettext("sys_string", "IDS_COM_BODY_EMAIL_ADDRESS"));
+#: setting/email-view-account-edit.c:817 setting/email-view-account-edit.c:914
+#: setting/email-view-account-edit.c:956
+#: setting/email-view-other-account.c:833
+#: setting/email-view-other-account.c:858
+#: setting/email-view-other-account.c:901
+msgid "IDS_COM_BODY_EMAIL_ADDRESS"
+msgstr ""
+
+#. p->ly_title2 = elm_layout_add(p->bx);
+#. elm_layout_file_set(p->ly_title2, EV_THEME_PATH, "email.title.nbeat");
+#. evas_object_size_hint_align_set(p->ly_title2, EVAS_HINT_FILL, EVAS_HINT_FILL);
+#. evas_object_show(p->ly_title2);
+#. elm_box_pack_end(p->bx, p->ly_title2);
+#. edje_object_part_text_set(_EDJ(p->ly_title2), "elm.text", dgettext("sys_string", "IDS_COM_BODY_USER_NAME"));
+#: setting/email-view-account-edit.c:818 setting/email-view-account-edit.c:915
+#: setting/email-view-account-edit.c:960
+#: setting/email-view-other-account.c:834
+#: setting/email-view-other-account.c:859
+#: setting/email-view-other-account.c:916
+msgid "IDS_COM_BODY_USER_NAME"
+msgstr ""
+
+#. elm_editfield_label_set(p->ef_incoming_server, _("Incoming Server"));
+#: setting/email-view-account-edit.c:820 setting/email-view-account-edit.c:917
+#: setting/email-view-server-type.c:659
+msgid "IDS_EMAIL_BODY_INCOMING_SERVER"
+msgstr ""
+
+#. elm_editfield_label_set(p->ef_smtp_server, N_("SMTP server"));
+#: setting/email-view-account-edit.c:822 setting/email-view-account-edit.c:920
+#: setting/email-view-account-edit.c:990 setting/email-view-server-type.c:615
+msgid "IDS_EMAIL_BODY_OUTGOING_SERVER"
+msgstr ""
+
+#: setting/email-view-account-edit.c:824 setting/email-view-account-edit.c:921
+#: setting/email-view-account-edit.c:998
+msgid "Sending Username"
+msgstr ""
+
+#: setting/email-view-account-edit.c:971
+msgid "IDS_EMAIL_BODY_IMAP4_SERVER"
+msgstr ""
+
+#: setting/email-view-account-edit.c:978
+msgid "IDS_EMAIL_BODY_POP3_SERVER"
+msgstr ""
+
+#. snprintf(buf, sizeof(buf), "%s", _("Off"));
+#: setting/email-view-account-edit.c:986
+#: setting/email-view-account-edit.c:1007 setting/email-view-server-type.c:509
+#: setting/email-view-server-type.c:548 setting/email-view-server-type.c:714
+msgid "IDS_COM_SK_OFF"
+msgstr ""
+
+#. snprintf(buf, sizeof(buf), "%s", N_("Sending security"));
+#. snprintf(buf, sizeof(buf), "%s", N_("Incoming security"));
+#: setting/email-view-account-edit.c:988
+#: setting/email-view-account-edit.c:1009 setting/email-view-server-type.c:481
+#: setting/email-view-server-type.c:496
+msgid "IDS_EMAIL_BODY_SECURE_CONNECTION"
+msgstr ""
+
+#: setting/email-view-account-options.c:382
+#: setting/email-view-account-options.c:622
+msgid "IDS_EMAIL_BODY_REPLY_WITH_BODY"
+msgstr ""
+
+#: setting/email-view-account-options.c:398
+#: setting/email-view-account-options.c:627
+msgid "IDS_EMAIL_BODY_FORWARD_WITH_FILES"
+msgstr ""
+
+#: setting/email-view-account-options.c:414
+#: setting/email-view-account-options.c:632
+msgid "IDS_EMAIL_BODY_ALWAYS_BCC_MYSELF"
+msgstr ""
+
+#: setting/email-view-account-options.c:430
+#: setting/email-view-account-options.c:642
+msgid "IDS_EMAIL_BODY_ADD_SIGNATURE"
+msgstr ""
+
+#: setting/email-view-account-options.c:443
+#: setting/email-view-account-options.c:659
+#: setting/email-view-account-options.c:905
+msgid "IDS_EMAIL_BODY_SIGNATURE"
+msgstr ""
+
+#: setting/email-view-account-options.c:490
+#: setting/email-view-account-options.c:674
+#: setting/email-view-receiving-option-size.c:356
+msgid "IDS_COM_BODY_EMAIL_SIZE"
+msgstr ""
+
+#. set the struct values
+#: setting/email-view-account-options.c:494
+#: setting/email-view-account-options.c:498
+#: setting/email-view-account-options.c:684
+#: setting/email-view-account-options.c:688
+#: setting/email-view-account-options.c:759
+#: setting/email-view-receiving-option-size.c:112
+msgid "IDS_EMAIL_BODY_WITHOUT_ATTACHMENTS"
+msgstr ""
+
+#: setting/email-view-account-options.c:502
+#: setting/email-view-account-options.c:692
+#: setting/email-view-account-options.c:763
+#: setting/email-view-receiving-option-size.c:113
+msgid "IDS_EMAIL_BODY_ENTIRE_EMAIL"
+msgstr ""
+
+#: setting/email-view-account-options.c:515
+#: setting/email-view-account-options.c:637
+msgid "IDS_EMAIL_BODY_KEEP_IN_SERVER"
+msgstr ""
+
+#: setting/email-view-account-options.c:545
+msgid "IDS_EMAIL_HEADER_MAILBOXES"
+msgstr ""
+
+#: setting/email-view-account-options.c:552
+#: setting/email-view-account-options.c:713
+msgid "IDS_EMAIL_BODY_SENTBOX"
+msgstr ""
+
+#: setting/email-view-account-options.c:560
+#: setting/email-view-account-options.c:717
+msgid "IDS_EMAIL_BODY_DRAFTS"
+msgstr ""
+
+#: setting/email-view-account-options.c:568
+#: setting/email-view-account-options.c:721
+msgid "IDS_EMAIL_BODY_TRASH"
+msgstr ""
+
+#: setting/email-view-account-options.c:576
+#: setting/email-view-account-options.c:725
+msgid "IDS_EMAIL_BODY_SPAMBOX"
+msgstr ""
+
+#: setting/email-view-account-options.c:797
+msgid "Mailbox setup"
+msgstr ""
+
+#. elm_navigationbar_push(vd->ugd->navi_bar, N_("Account Settings"), p->l_button, NULL, NULL, p->layout);
+#: setting/email-view-account-options.c:1421
+msgid "IDS_EMAIL_HEADER_ACCOUNT_SETTINGS"
+msgstr ""
+
+#: setting/email-view-default-account.c:326 setting/email-view-setting.c:422
+#: setting/email-view-setting.c:752
+msgid "IDS_EMAIL_BODY_DEFAULT_ACCOUNT"
+msgstr ""
+
+#: setting/email-view-other-account.c:319
+msgid "<align=center>Creating account is canceled"
+msgstr ""
+
+#: setting/email-view-other-account.c:398 setting/email-view-server-type.c:332
+#: composer/email-composer-attachment.c:44
+#: composer/email-composer-predictive-search.c:550
+#: composer/email-composer-predictive-search.c:565
+#: composer/email-composer-predictive-search.c:580
+#: composer/email-composer-predictive-search.c:1008
+#: composer/email-composer-predictive-search.c:1023
+#: composer/email-composer-predictive-search.c:1038
+#: composer/email-composer-recent.c:581
+#: composer/email-composer-ug-caller.c:870
+#: composer/email-composer-ug-caller.c:1100
+#: composer/email-composer-util.c:1800 composer/email-composer-util.c:1890
+#: composer/email-composer-util.c:2013 composer/email-composer-util.c:2135
+msgid "IDS_COM_POP_ALREDY_EXISTS"
+msgstr ""
+
+#: setting/email-view-other-account.c:400 setting/email-view-server-type.c:334
+msgid "Failed to create account"
+msgstr ""
+
+#: setting/email-view-other-account.c:535
+msgid "Please check server name in email address"
+msgstr ""
+
+#: setting/email-view-other-account.c:888
+msgid "IDS_EMAIL_BODY_EXAMPLE"
+msgstr ""
+
+#: setting/email-view-other-account.c:931
+msgid "IDS_EMAIL_BODY_USER_PASSWORD"
+msgstr ""
+
+#: setting/email-view-other-account.c:970
+msgid "IDS_COM_SK_NEXT"
+msgstr ""
+
+#: setting/email-view-other-account.c:990
+#: setting/email-view-select-account.c:270
+#: setting/email-view-server-type.c:1181
+msgid "IDS_COM_SK_ADD_ACCOUNT"
+msgstr ""
+
+#: setting/email-view-receiving-option-mailbox-setup.c:142
+msgid "Mailbox Setup"
+msgstr ""
+
+#. str = strdup(N_("Others")); //20110208_string
+#: setting/email-view-select-account.c:143
+msgid "IDS_EMAIL_OPT_OTHERS"
+msgstr ""
+
+#: setting/email-view-server-type.c:488
+msgid "Incoming server type"
+msgstr ""
+
+#: setting/email-view-server-type.c:515 setting/email-view-server-type.c:554
+#: setting/email-view-server-type.c:718
+msgid "SSL"
+msgstr ""
+
+#: setting/email-view-server-type.c:521 setting/email-view-server-type.c:560
+#: setting/email-view-server-type.c:722
+msgid "TLS"
+msgstr ""
+
+#: setting/email-view-server-type.c:531 setting/email-view-server-type.c:766
+msgid "POP3"
+msgstr ""
+
+#: setting/email-view-server-type.c:537 setting/email-view-server-type.c:770
+msgid "IMAP4"
+msgstr ""
+
+#: setting/email-view-setting.c:125
+msgid "IDS_COM_POP_NO_ACCOUNTS"
+msgstr ""
+
+#: setting/email-view-setting.c:311
+msgid "Change account color"
+msgstr ""
+
+#. snprintf(buf, sizeof(buf), "%s", N_("General settings"));
+#: setting/email-view-setting.c:403
+msgid "IDS_EMAIL_BODY_GENERAL_SETTINGS"
+msgstr ""
+
+#: setting/email-view-setting.c:429 setting/email-view-setting.c:762
+#: setting/email-view-show-email-list.c:367
+msgid "IDS_EMAIL_BODY_RETRIEVING_OPTIONS"
+msgstr ""
+
+#: setting/email-view-setting.c:691
+msgid "IDS_COM_SK_ADD"
+msgstr ""
+
+#: setting/email-view-setting.c:705
+msgid "IDS_EMAIL_HEADER_EMAIL_SETTINGS"
+msgstr ""
+
+#. snprintf(send_subject, sizeof(send_subject), "%s: %s", N_("None"), ugd->emf_data->mail_info->head->subject);
+#. snprintf(send_subject, sizeof(send_subject), "%s: ", N_("None"));
+#: setting/email-view-setting.c:1007 viewer/email-viewer.c:771
+#: viewer/email-viewer.c:796
+msgid "IDS_COM_BODY_NONE"
+msgstr ""
+
+#: viewer/email-viewer.c:634
+msgid "IDS_COM_SK_REPLY"
+msgstr ""
+
+#: viewer/email-viewer.c:635
+msgid "IDS_EMAIL_SK_REPLY_ALL"
+msgstr ""
+
+#: viewer/email-viewer.c:636
+msgid "IDS_COM_BODY_FORWARD"
+msgstr ""
+
+#: viewer/email-viewer.c:751 viewer/email-viewer.c:776
+#: viewer/email-viewer.c:909 viewer/email-viewer.c:1208
+msgid "IDS_COM_POP_ACCEPT"
+msgstr ""
+
+#. snprintf(send_subject, sizeof(send_subject), "%s: %s", N_("Accepted"), ugd->emf_data->mail_info->head->subject);
+#. snprintf(send_subject, sizeof(send_subject), "%s: ", N_("Accepted"));
+#: viewer/email-viewer.c:754 viewer/email-viewer.c:779
+#, c-format
+msgid "IDS_EMAIL_BODY_ACCEPTED_C_PS"
+msgstr ""
+
+#. else if(!strcmp(button_label, N_("Decline")))
+#. elm_button_label_set( peoDeclineBtn, N_("Decline") );
+#: viewer/email-viewer.c:757 viewer/email-viewer.c:782
+#: viewer/email-viewer.c:918 viewer/email-viewer.c:1211
+msgid "IDS_EMAIL_BUTTON_DECLINE_ABB"
+msgstr ""
+
+#. snprintf(send_subject, sizeof(send_subject), "%s: %s", N_("Declined"), ugd->emf_data->mail_info->head->subject);
+#. snprintf(send_subject, sizeof(send_subject), "%s: ", N_("Declined"));
+#: viewer/email-viewer.c:760 viewer/email-viewer.c:785
+#, c-format
+msgid "IDS_EMAIL_BODY_DECLINED_C_PS"
+msgstr ""
+
+#: viewer/email-viewer.c:762 viewer/email-viewer.c:787
+#: viewer/email-viewer.c:913 viewer/email-viewer.c:1209
+msgid "Tentative"
+msgstr ""
+
+#. snprintf(send_subject, sizeof(send_subject), "%s: %s", N_("Tentative"), ugd->emf_data->mail_info->head->subject);
+#. snprintf(send_subject, sizeof(send_subject), "%s: ", N_("Tentative"));
+#: viewer/email-viewer.c:765 viewer/email-viewer.c:790
+#, c-format
+msgid "IDS_EMAIL_BODY_TENTATIVE_C_PS"
+msgstr ""
+
+#: viewer/email-viewer.c:848
+#, c-format
+msgid "IDS_EMAIL_BODY_WHEN_C_PS"
+msgstr ""
+
+#. sprintf(send_text_body, "%s: %s\n%s: %s - %s\n%s: %s", dgettext("sys_string", "IDS_COM_BODY_TO"), reply,
+#. N_("When"), asctime(&(meeting_req->start_time)), asctime(&(meeting_req->end_time)),
+#. N_("Where"), meeting_req->location);
+#. sprintf(send_text_body, "%s: %s\n%s: %s - %s\n%s: ", dgettext("sys_string", "IDS_COM_BODY_TO"), reply,
+#. N_("When"), asctime(&(meeting_req->start_time)), asctime(&(meeting_req->end_time)),
+#. N_("Where"));
+#: viewer/email-viewer.c:854 viewer/email-viewer.c:861
+#, c-format
+msgid "IDS_EMAIL_BODY_WHERE_C_PS"
+msgstr ""
+
+#: viewer/email-viewer.c:1394 composer/email-composer.c:788
+#: composer/email-composer-recipient.c:89
+#: composer/email-composer-recipient.c:92
+#: composer/email-composer-recipient.c:198
+#: composer/email-composer-recipient.c:267
+#: composer/email-composer-recipient.c:596
+#: composer/email-composer-recipient.c:607
+#: composer/email-composer-recipient.c:625
+#: composer/email-composer-recipient.c:633
+msgid "IDS_EMAIL_BODY_CC"
+msgstr ""
+
+#: viewer/email-viewer.c:1473 composer/email-composer.c:803
+#: composer/email-composer-recipient.c:107
+#: composer/email-composer-recipient.c:110
+#: composer/email-composer-recipient.c:276
+msgid "IDS_EMAIL_BODY_BCC"
+msgstr ""
+
+#: viewer/email-viewer.c:1618 composer/email-composer.c:817
+msgid "IDS_EMAIL_BODY_ATTACHMENTS"
+msgstr ""
+
+#. elm_button_label_set(dn_btn, N_("Download full message"));
+#: viewer/email-viewer.c:1912
+msgid "IDS_EMAIL_BODY_DOWNLOAD_FULL_MESSAGE"
+msgstr ""
+
+#: viewer/email-viewer.c:2283 viewer/email-viewer.c:4105
+#: viewer/email-viewer.c:5561
+msgid "IDS_COM_POP_DOWNLOADING"
+msgstr ""
+
+#. show popup
+#: viewer/email-viewer.c:2320 viewer/email-viewer.c:4113
+#: viewer/email-viewer.c:4472 viewer/email-viewer.c:5235
+#: viewer/email-viewer.c:5781
+msgid "IDS_COM_POP_WARNING"
+msgstr ""
+
+#: viewer/email-viewer.c:2320 viewer/email-viewer.c:4113
+#: viewer/email-viewer.c:4472 viewer/email-viewer.c:5780
+#: viewer/email-viewer.c:5963 viewer/email-viewer.c:6006
+#: viewer/email-viewer.c:6017 composer/email-composer.c:1914
+msgid "IDS_EMAIL_POP_UNABLE_TO_DOWNLOAD"
+msgstr ""
+
+#: viewer/email-viewer.c:2731 viewer/email-viewer.c:3631
+#: viewer/email-viewer.c:3667 viewer/email-viewer.c:3703
+msgid "IDS_COM_OPT_CREATE_CONTACT"
+msgstr ""
+
+#. 20101104_string
+#: viewer/email-viewer.c:2732 viewer/email-viewer.c:3041
+#: viewer/email-viewer.c:3632 viewer/email-viewer.c:3668
+#: viewer/email-viewer.c:3704 viewer/email-viewer.c:4294
+msgid "IDS_EMAIL_OPT_UPDATE_EXISTING"
+msgstr ""
+
+#: viewer/email-viewer.c:2786
+msgid "Delete is under construction in Split-view"
+msgstr ""
+
+#. elm_button_label_set(ug_data->opt_btn1, N_("View detail contact"));
+#: viewer/email-viewer.c:2991
+msgid "View contact detail"
+msgstr ""
+
+#. elm_ctxpopup_item_append(ug_data->con_popup, _("IDS_EMAIL_OPT_SEND_MESSAGE"), NULL, ev_ctxpopup_send_message_by_email_cb, link_text);
+#: viewer/email-viewer.c:3031 viewer/email-viewer.c:4293
+#: viewer/email-viewer.c:8401 viewer/email-viewer.c:8420
+#: viewer/email-viewer.c:8438 viewer/email-viewer.c:8457
+#: viewer/email-viewer.c:8906 viewer/email-viewer.c:8931
+#: viewer/email-viewer.c:8955 viewer/email-viewer.c:8980
+#: viewer/email-viewer.c:9006
+msgid "IDS_COM_OPT_ADD_TO_CONTACTS"
+msgstr ""
+
+#: viewer/email-viewer.c:3754
+msgid "Failed to add block rule"
+msgstr ""
+
+#. snprintf(desc, MAX_STR_LEN, "%s %s", addr, N_("is blocked"));
+#. elm_popup_desc_set(ug_data->timeout_popup, desc);
+#. elm_popup_title_label_set(ug_data->timeout_popup, N_("Notice"));
+#. 20110208_string
+#: viewer/email-viewer.c:3770
+msgid "Blocked"
+msgstr ""
+
+#: viewer/email-viewer.c:4464
+msgid "IDS_EMAIL_POP_DOWNLOADING_ING"
+msgstr ""
+
+#. if(info && info->name)
+#. snprintf(buf, sizeof(buf), N_("Saving %s %d%%"), info->name, per);
+#. else
+#: viewer/email-viewer.c:5193
+#, c-format
+msgid "Saving in My files %d%%"
+msgstr ""
+
+#: viewer/email-viewer.c:5234
+msgid "Cancelling all attachment download operations..."
+msgstr ""
+
+#: viewer/email-viewer.c:5283
+msgid "Saving in My files"
+msgstr ""
+
+#: viewer/email-viewer.c:5287
+#, c-format
+msgid "Saving in My files 0%%"
+msgstr ""
+
+#. must be
+#. ug_data->b_eng_att_start = 1;
+#: viewer/email-viewer.c:5810 viewer/email-viewer.c:7801
+#: viewer/email-viewer.c:7899 viewer/email-viewer.c:7956
+#: composer/email-composer.c:1803 composer/email-composer.c:1889
+#: composer/email-composer-util.c:1385
+msgid "IDS_EMAIL_POP_DOWNLOADING_ATTACHMENT_ING"
+msgstr ""
+
+#: viewer/email-viewer.c:6135
+msgid "IDS_EMAIL_POP_FILE_ALREADY_EXISTS"
+msgstr ""
+
+#: viewer/email-viewer.c:6137
+msgid "IDS_COM_POP_SAVED"
+msgstr ""
+
+#: viewer/email-viewer.c:6139
+msgid "IDS_EMAIL_POP_UNABLE_TO_SAVE_ATTACHMENT"
+msgstr ""
+
+#: viewer/email-viewer.c:6205
+msgid "Download message"
+msgstr ""
+
+#: viewer/email-viewer.c:7773
+msgid "Download already in progress"
+msgstr ""
+
+#. attachment open fail popup
+#: viewer/email-viewer.c:7808 viewer/email-viewer.c:7963
+msgid "IDS_EMAIL_POP_UNABLE_TO_OPEN_ATTACHMENT"
+msgstr ""
+
+#: viewer/email-viewer.c:8010
+msgid "IDS_EMAIL_POP_UNABLE_TO_LAUNCH_APPLICATION"
+msgstr ""
+
+#: viewer/email-viewer.c:8014 viewer/email-viewer.c:8018
+msgid "IDS_COM_POP_UNSUPPORTED_FILE_TYPE"
+msgstr ""
+
+#: viewer/email-viewer.c:8098 composer/email-composer-util.c:3430
+msgid "Login failure"
+msgstr ""
+
+#: viewer/email-viewer.c:8398 viewer/email-viewer.c:8903
+msgid "IDS_COM_BODY_VOICE_CALL"
+msgstr ""
+
+#: viewer/email-viewer.c:8399 viewer/email-viewer.c:8904
+msgid "IDS_COM_BODY_VIDEO_CALL"
+msgstr ""
+
+#: viewer/email-viewer.c:8400 viewer/email-viewer.c:8905
+msgid "IDS_COM_BODY_SEND_MESSAGE"
+msgstr ""
+
+#: viewer/email-viewer.c:8418 viewer/email-viewer.c:8929
+msgid "IDS_EMAIL_OPT_SEND_EMAIL"
+msgstr ""
+
+#: viewer/email-viewer.c:8437 viewer/email-viewer.c:8456
+#: viewer/email-viewer.c:8954 viewer/email-viewer.c:8979
+#: viewer/email-viewer.c:9005
+msgid "IDS_EMAIL_OPT_OPEN_URL"
+msgstr ""
+
+#: viewer/email-viewer.c:8439 viewer/email-viewer.c:8458
+#: viewer/email-viewer.c:8956 viewer/email-viewer.c:8981
+#: viewer/email-viewer.c:9007
+msgid "IDS_COM_OPT_ADD_TO_BOOKMARKS"
+msgstr ""
+
+#: viewer/email-viewer-webview.c:219
+msgid "IDS_EMAIL_POP_LOADING_CONTENTS_ING"
+msgstr ""
+
+#: composer/email-composer.c:386 composer/email-composer-callback.c:99
+msgid "IDS_EMAIL_POP_SAVE_IN_DRAFTS_Q"
+msgstr ""
+
+#: composer/email-composer.c:775 composer/email-composer.c:830
+msgid "IDS_COM_SK_SEND_ABB"
+msgstr ""
+
+#: composer/email-composer-attachment.c:101
+#: composer/email-composer-util.c:2883
+#, c-format
+msgid "IDS_EMAIL_POP_UNABLE_TO_ATTACH_MAXIMUM_NUMBER_OF_FILES_IS_PD"
+msgstr ""
+
+#: composer/email-composer-attachment.c:113
+#: composer/email-composer-util.c:2903
+#, c-format
+msgid "IDS_EMAIL_POP_UNABLE_TO_ATTACH_MAXIMUM_SIZE_OF_FILES_IS_PD_KB"
+msgstr ""
+
+#: composer/email-composer-attachment.c:348
+#, c-format
+msgid "IDS_EMAIL_BODY_PD_ITEMS"
+msgstr ""
+
+#: composer/email-composer-attachment.c:356
+#: composer/email-composer-attachment.c:373
+msgid "Byte"
+msgstr ""
+
+#: composer/email-composer-callback.c:415
+#: composer/email-composer-callback.c:1201
+#: composer/email-composer-callback.c:1521
+msgid "IDS_COM_POP_CLOSE"
+msgstr ""
+
+#: composer/email-composer-callback.c:427
+#: composer/email-composer-callback.c:1069
+msgid "Change address"
+msgstr ""
+
+#. _composer_popup_add(ugd, 0, dgettext("sys_string", "IDS_COM_POP_SENDING")); //20110104_string
+#: composer/email-composer-callback.c:940
+#: composer/email-composer-callback.c:1571
+msgid "IDS_COM_POP_SENDING"
+msgstr ""
+
+#: composer/email-composer-callback.c:952
+msgid "IDS_EMAIL_POP_TOO_MANY_RECIPIENTS"
+msgstr ""
+
+#: composer/email-composer-callback.c:1186
+msgid "IDS_EMAIL_POP_UNABLE_TO_ENTER_TEXT"
+msgstr ""
+
+#: composer/email-composer-callback.c:1537
+msgid "Inline image"
+msgstr ""
+
+#: composer/email-composer-callback.c:1539
+msgid "IDS_COM_BODY_GALLERY"
+msgstr ""
+
+#: composer/email-composer-callback.c:1540
+msgid "IDS_COM_BODY_TAKE_PHOTO"
+msgstr ""
+
+#: composer/email-composer-callback.c:1541
+msgid "Record sound"
+msgstr ""
+
+#: composer/email-composer-callback.c:1542
+msgid "IDS_COM_BODY_MY_FILES"
+msgstr ""
+
+#: composer/email-composer-callback.c:1546
+msgid "IDS_COM_BODY_CALENDAR"
+msgstr ""
+
+#: composer/email-composer-callback.c:1547
+msgid "IDS_COM_BODY_MEMO"
+msgstr ""
+
+#: composer/email-composer-callback.c:1550
+msgid "IDS_COM_OPT_IMAGE"
+msgstr ""
+
+#. 20110104_string
+#: composer/email-composer-callback.c:1551
+msgid "IDS_COM_BODY_VIDEO"
+msgstr ""
+
+#: composer/email-composer-callback.c:1552
+msgid "IDS_COM_BODY_SOUNDS"
+msgstr ""
+
+#: composer/email-composer-contents.c:87 composer/email-composer-contents.c:93
+msgid "Content"
+msgstr ""
+
+#: composer/email-composer-contents.c:642
+#: composer/email-composer-contents.c:746
+msgid "Clipboard"
+msgstr ""
+
+#: composer/email-composer-recent.c:635
+#: composer/email-composer-ug-caller.c:613 composer/email-composer-util.c:1715
+msgid "Duplicated recipient"
+msgstr ""
+
+#: composer/email-composer-recipient.c:42
+msgid "Cc/Bcc/From"
+msgstr ""
+
+#: composer/email-composer-recipient.c:46
+#: composer/email-composer-recipient.c:98
+#: composer/email-composer-recipient.c:101
+#: composer/email-composer-recipient.c:713
+#: composer/email-composer-recipient.c:795
+msgid "IDS_EMAIL_BODY_CC_BCC"
+msgstr ""
+
+#. else if(strcmp(title, N_("Cc/Bcc/From")) == 0) //20101104_string
+#. sprintf(str, "%s %s", N_("Cc/Bcc/From"), ": ");
+#. snprintf(str, sizeof(str)-1, "%s %s", N_("Cc/Bcc/From"), ": ");
+#: composer/email-composer-recipient.c:117
+#: composer/email-composer-recipient.c:121
+#: composer/email-composer-recipient.c:677
+#: composer/email-composer-recipient.c:757
+msgid "IDS_EMAIL_BODY_CC_BCC_FROM"
+msgstr ""
+
+#: composer/email-composer-ug-caller.c:689
+#: composer/email-composer-ug-caller.c:993
+msgid "Contact has no email address."
+msgstr ""
+
+#: composer/email-composer-util.c:42
+msgid "Jan"
+msgstr ""
+
+#: composer/email-composer-util.c:43
+msgid "Feb"
+msgstr ""
+
+#: composer/email-composer-util.c:44
+msgid "Mar"
+msgstr ""
+
+#: composer/email-composer-util.c:45
+msgid "Apr"
+msgstr ""
+
+#: composer/email-composer-util.c:46
+msgid "May"
+msgstr ""
+
+#: composer/email-composer-util.c:47
+msgid "Jun"
+msgstr ""
+
+#: composer/email-composer-util.c:48
+msgid "Jul"
+msgstr ""
+
+#: composer/email-composer-util.c:49
+msgid "Aug"
+msgstr ""
+
+#: composer/email-composer-util.c:50
+msgid "Sep"
+msgstr ""
+
+#: composer/email-composer-util.c:51
+msgid "Oct"
+msgstr ""
+
+#: composer/email-composer-util.c:52
+msgid "Nov"
+msgstr ""
+
+#: composer/email-composer-util.c:53
+msgid "Dec"
+msgstr ""
+
+#: composer/email-composer-util.c:976
+msgid "IDS_EMAIL_POP_UNABLE_TO_SAVE_IN_DRAFTS"
+msgstr ""
+
+#: composer/email-composer-util.c:987
+msgid "Saved in Drafts"
+msgstr ""
+
+#: composer/email-composer-util.c:1342
+msgid "Download attachment?"
+msgstr ""
+
+#: composer/email-composer-util.c:1841 composer/email-composer-util.c:1978
+#: composer/email-composer-util.c:2095
+msgid "Maximum number of recipients reached. <br>(Maximum = 100)"
+msgstr ""
+
+#. sprintf(subject_temp, "%s: %s",N_("Fwd"), ugd->mail_info->mail->head->subject); //20101105_string
+#: composer/email-composer-util.c:2187
+msgid "IDS_EMAIL_BODY_FWD_C"
+msgstr ""
+
+#: composer/email-composer-util.c:2195
+msgid "RE"
+msgstr ""
+
+#. sprintf(subject_temp, "%s: %s",N_("RE"), ugd->mail_info->mail->head->subject);
+#: composer/email-composer-util.c:2199
+msgid "IDS_EMAIL_BODY_RE_C"
+msgstr ""
+
+#: composer/email-composer-util.c:2403 composer/email-composer-util.c:2407
+#: composer/email-composer-util.c:2592
+msgid "IDS_EMAIL_BODY_SENT_C"
+msgstr ""
+
+#. text_for_original_info = g_strconcat(BODY_TAG_START, DIVIDE_LINE_FOR_HTML, text_for_from, text_for_sent, text_for_to, text_for_subject, BODY_TAG_END, NULL);
+#. text_for_original_info = g_strconcat(BODY_TAG_START, DIVIDE_LEFT_LINE_FOR_HTML, N_("Original Message"), DIVIDE_RIGHT_LINE_FOR_HTML, text_for_from, text_for_sent, text_for_to, text_for_subject, BODY_TAG_END, NULL);
+#: composer/email-composer-util.c:2609
+msgid "IDS_EMAIL_BODY_ORIGINAL_MESSAGE"
+msgstr ""
diff --git a/po/en.po b/po/en.po
new file mode 100755
index 0000000..14172f4
--- /dev/null
+++ b/po/en.po
@@ -0,0 +1,465 @@
+msgid "IDS_EMAIL_POP_NO_EMAIL_ADDRESS"
+msgstr "No email address"
+
+msgid "IDS_EMAIL_BODY_COMPLETE"
+msgstr "Complete"
+
+msgid "IDS_EMAIL_BODY_ACCEPTED_C_PS"
+msgstr "Accepted: %s"
+
+msgid "IDS_EMAIL_BODY_DECLINED_C_PS"
+msgstr "Declined: %s"
+
+msgid "IDS_EMAIL_BODY_DOWNLOAD_FULL_MESSAGE"
+msgstr "Download full message"
+
+msgid "IDS_EMAIL_BODY_GENERAL_SETTINGS"
+msgstr "General settings"
+
+msgid "IDS_EMAIL_BODY_TENTATIVE_C_PS"
+msgstr "Tentative: %s"
+
+msgid "IDS_EMAIL_BODY_WHEN_C_PS"
+msgstr "When: %s"
+
+msgid "IDS_EMAIL_BODY_WHERE_C_PS"
+msgstr "Where: %s"
+
+msgid "IDS_EMAIL_BUTTON_DECLINE_ABB"
+msgstr "Decline"
+
+msgid "IDS_EMAIL_BODY_NO_CONTENTS"
+msgstr "No contents"
+
+msgid "IDS_EMAIL_BODY_ORIGINAL_MESSAGE"
+msgstr "Original message"
+
+msgid "IDS_EMAIL_HEADER_ACCOUNT_SETTINGS"
+msgstr "Account settings"
+
+msgid "IDS_EMAIL_OPT_BLOCK"
+msgstr "Block"
+
+msgid "IDS_EMAIL_OPT_MARK_AS_READ"
+msgstr "Mark as read"
+
+msgid "IDS_EMAIL_OPT_MARK_AS_UNREAD"
+msgstr "Mark as unread"
+
+msgid "IDS_EMAIL_OPT_OTHERS"
+msgstr "Others"
+
+msgid "IDS_EMAIL_OPT_UNREAD"
+msgstr "Unread"
+
+msgid "IDS_EMAIL_SK_COMPOSE"
+msgstr "Compose"
+
+msgid "IDS_EMAIL_HEADER_DOWNLOAD_FAILED"
+msgstr "Download failed"
+
+msgid "IDS_EMAIL_OPT_ADD_TO_CONTACT"
+msgstr "Add to contact"
+
+msgid "IDS_EMAIL_OPT_VOICE_CALL"
+msgstr "Voice call"
+
+msgid "IDS_EMAIL_BODY_ACCOUNT_NAME"
+msgstr "Account name"
+
+msgid "IDS_EMAIL_BODY_ATTACHMENTS"
+msgstr "Attachments"
+
+msgid "IDS_EMAIL_BODY_FROM_C"
+msgstr "From:"
+
+msgid "IDS_EMAIL_BODY_IMAP4_SERVER"
+msgstr "IMAP4 server"
+
+msgid "IDS_EMAIL_BODY_INCLUDES"
+msgstr "Includes"
+
+msgid "IDS_EMAIL_BODY_INCOMING_PORT"
+msgstr "Incoming port"
+
+msgid "IDS_EMAIL_BODY_INCOMING_SERVER"
+msgstr "Incoming server"
+
+msgid "IDS_EMAIL_BODY_IN_PD_MINUTES"
+msgstr "In %d minutes"
+
+msgid "IDS_EMAIL_BODY_KEEP_IN_SERVER"
+msgstr "Keep in server"
+
+msgid "IDS_EMAIL_BODY_NO_TEXT"
+msgstr "No text"
+
+msgid "IDS_EMAIL_BODY_OUTGOING_PORT"
+msgstr "Outgoing port"
+
+msgid "IDS_EMAIL_BODY_OUTGOING_SERVER"
+msgstr "Outgoing server"
+
+msgid "IDS_EMAIL_BODY_PD_EMAILS"
+msgstr "%d emails"
+
+msgid "IDS_EMAIL_BODY_POP3_SERVER"
+msgstr "POP3 server"
+
+msgid "IDS_EMAIL_BODY_RECENT"
+msgstr "Recent"
+
+msgid "IDS_EMAIL_BODY_RETRIEVING_OPTIONS"
+msgstr "Retrieving options"
+
+msgid "IDS_EMAIL_BODY_RE_C"
+msgstr "RE:"
+
+msgid "IDS_EMAIL_BODY_SENT_C"
+msgstr "Sent:"
+
+msgid "IDS_EMAIL_BODY_SENT_FROM_SAMSUNG_MOBILE"
+msgstr "Sent from Samsung Mobile"
+
+msgid "IDS_EMAIL_BODY_USER_PASSWORD"
+msgstr "User password"
+
+msgid "IDS_EMAIL_HEADER_EDIT_RULES"
+msgstr "Edit rules"
+
+msgid "IDS_EMAIL_HEADER_EMAIL_SETTINGS"
+msgstr "Email settings"
+
+msgid "IDS_EMAIL_HEADER_MAILBOXES"
+msgstr "Mailboxes"
+
+msgid "IDS_EMAIL_POP_ALERT"
+msgstr "Alert"
+
+msgid "IDS_EMAIL_POP_FILE_ALREADY_EXISTS"
+msgstr "File already exists"
+
+msgid "IDS_EMAIL_POP_NO_SENDER"
+msgstr "No sender"
+
+msgid "IDS_EMAIL_POP_SUCCEEDED"
+msgstr "Succeeded"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_ATTACH_MAXIMUM_NUMBER_OF_FILES_IS_PD"
+msgstr "Unable to attach. Maximum number of files is %d"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_ATTACH_MAXIMUM_SIZE_OF_FILES_IS_PD_KB"
+msgstr "Unable to attach. Maximum size of files is %d KB"
+
+msgid "IDS_EMAIL_POP_VALIDATION_FAILED"
+msgstr "Validation failed"
+
+msgid "IDS_EMAIL_SK_REPLY_ALL"
+msgstr "Reply all"
+
+msgid "IDS_EMAIL_BODY_1_ITEM"
+msgstr "1 item"
+
+msgid "IDS_EMAIL_BODY_ADD_MY_NAMECARD"
+msgstr "Add my namecard"
+
+msgid "IDS_EMAIL_BODY_ADD_SIGNATURE"
+msgstr "Add signature"
+
+msgid "IDS_EMAIL_BODY_ALL_EMAILS"
+msgstr "All emails"
+
+msgid "IDS_EMAIL_BODY_ALWAYS_BCC_MYSELF"
+msgstr "Always Bcc myself"
+
+msgid "IDS_EMAIL_BODY_BCC"
+msgstr "Bcc"
+
+msgid "IDS_EMAIL_BODY_BLOCK_EMAILS"
+msgstr "Block emails"
+
+msgid "IDS_EMAIL_BODY_BODY"
+msgstr "Body"
+
+msgid "IDS_EMAIL_BODY_CC"
+msgstr "Cc"
+
+msgid "IDS_EMAIL_BODY_CC_BCC"
+msgstr "Cc/Bcc"
+
+msgid "IDS_EMAIL_BODY_CHECK_INTERVAL"
+msgstr "Check interval"
+
+msgid "IDS_EMAIL_BODY_DEFAULT_ACCOUNT"
+msgstr "Default account"
+
+msgid "IDS_EMAIL_BODY_DRAFTS"
+msgstr "Drafts"
+
+msgid "IDS_EMAIL_BODY_EMAIL_ACCOUNTS"
+msgstr "Email accounts"
+
+msgid "IDS_EMAIL_BODY_END_TIME"
+msgstr "End time"
+
+msgid "IDS_EMAIL_BODY_ENTIRE_EMAIL"
+msgstr "Entire email"
+
+msgid "IDS_EMAIL_BODY_EXACTLY_THE_SAME_AS"
+msgstr "Exactly the same as"
+
+msgid "IDS_EMAIL_BODY_EXAMPLE"
+msgstr "Example"
+
+msgid "IDS_EMAIL_BODY_FROM_M_SENDER"
+msgstr "From:"
+
+msgid "IDS_EMAIL_BODY_INBOX"
+msgstr "Inbox"
+
+msgid "IDS_EMAIL_BODY_INCLUDE"
+msgstr "Include"
+
+msgid "IDS_EMAIL_BODY_MATCH_CRITERIA"
+msgstr "Match criteria"
+
+msgid "IDS_EMAIL_BODY_NOT_USED"
+msgstr "Not used"
+
+msgid "IDS_EMAIL_BODY_NO_ACCOUNTS"
+msgstr "No accounts"
+
+msgid "IDS_EMAIL_BODY_PD_DAYS"
+msgstr "%d days"
+
+msgid "IDS_EMAIL_BODY_PD_ITEMS"
+msgstr "%d items"
+
+msgid "IDS_EMAIL_BODY_PRIORITY"
+msgstr "Priority"
+
+msgid "IDS_EMAIL_BODY_RECEIVING_OPTIONS"
+msgstr "Receiving options"
+
+msgid "IDS_EMAIL_BODY_SECURE_CONNECTION"
+msgstr "Secure connection"
+
+msgid "IDS_EMAIL_BODY_SENDING_OPTIONS"
+msgstr "Sending options"
+
+msgid "IDS_EMAIL_BODY_SENTBOX"
+msgstr "Sentbox"
+
+msgid "IDS_EMAIL_BODY_SERVER_URL"
+msgstr "Server URL"
+
+msgid "IDS_EMAIL_BODY_SIGNATURE"
+msgstr "Signature"
+
+msgid "IDS_EMAIL_BODY_SPAMBOX"
+msgstr "Spambox"
+
+msgid "IDS_EMAIL_BODY_START_TIME"
+msgstr "Start time"
+
+msgid "IDS_EMAIL_BODY_SYNC_SCHEDULE_TMO"
+msgstr "Sync schedule"
+
+msgid "IDS_EMAIL_BODY_TRASH"
+msgstr "Recycle bin"
+
+msgid "IDS_EMAIL_BODY_WITHOUT_ATTACHMENTS"
+msgstr "Without attachments"
+
+msgid "IDS_EMAIL_BUTTON_GROUP"
+msgstr "Group"
+
+msgid "IDS_EMAIL_HEADER_ADD_RULES"
+msgstr "Add rules"
+
+msgid "IDS_EMAIL_OPT_ATTACH_ITEMS"
+msgstr "Attach items"
+
+msgid "IDS_EMAIL_OPT_EXCHANGE"
+msgstr "Exchange"
+
+msgid "IDS_EMAIL_OPT_FILE"
+msgstr "File"
+
+msgid "IDS_EMAIL_OPT_NAMECARD"
+msgstr "Namecard"
+
+msgid "IDS_EMAIL_OPT_OPEN_URL"
+msgstr "Open URL"
+
+msgid "IDS_EMAIL_OPT_SENDER"
+msgstr "Sender"
+
+msgid "IDS_EMAIL_OPT_SEND_EMAIL"
+msgstr "Send email"
+
+msgid "IDS_EMAIL_OPT_UPDATE_EXISTING"
+msgstr "Update existing"
+
+msgid "IDS_EMAIL_POP_ADD_ACCOUNTS"
+msgstr "Add accounts"
+
+msgid "IDS_EMAIL_POP_DOWNLOADING_ATTACHMENT_ING"
+msgstr "Downloading attachment..."
+
+msgid "IDS_EMAIL_POP_INVALID_EMAIL_ADDRESS"
+msgstr "Invalid email address"
+
+msgid "IDS_EMAIL_POP_LOADING_CONTENTS_ING"
+msgstr "Loading contents..."
+
+msgid "IDS_EMAIL_POP_MAXIMUM_NUMBER_OF_ATTACHMENTS_REACHED"
+msgstr "Maximum number of attachments reached"
+
+msgid "IDS_EMAIL_POP_MOVE_TO_SPAMBOX_Q"
+msgstr "Move to Spambox?"
+
+msgid "IDS_EMAIL_POP_NO_RECIPIENTS_ADDED_ENTER_RECIPIENTS"
+msgstr "No recipients added. Enter recipients"
+
+msgid "IDS_EMAIL_POP_PLEASE_FILL_ALL_THE_MANDATORY_FIELDS"
+msgstr "Please fill all the mandatory fields"
+
+msgid "IDS_EMAIL_POP_SAVE_IN_DRAFTS_Q"
+msgstr "Save in Drafts?"
+
+msgid "IDS_EMAIL_POP_THERE_IS_NO_ACCOUNT_CREATE_A_NEW_ACCOUNT_FIRST"
+msgstr "There is no account. Create a new account first"
+
+msgid "IDS_EMAIL_POP_TOO_MANY_RECIPIENTS"
+msgstr "Too many recipients"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_DOWNLOAD"
+msgstr "Unable to download"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_ENTER_TEXT"
+msgstr "Unable to enter text"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_LAUNCH_APPLICATION"
+msgstr "Unable to launch application"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_OPEN_ATTACHMENT"
+msgstr "Unable to open attachment"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_SAVE_ATTACHMENT"
+msgstr "Unable to save attachment"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_SAVE_IN_DRAFTS"
+msgstr "Unable to save in Drafts"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_SEND_EMAIL"
+msgstr "Unable to send email"
+
+msgid "IDS_EMAIL_POP_UNSUPPORTED_FILE_TYPE"
+msgstr "Unsupported file type"
+
+msgid "IDS_EMAIL_POP_VALIDATING_ACCOUNT_ING"
+msgstr "Validating account..."
+
+msgid "IDS_EMAIL_SK_RESEND"
+msgstr "Resend"
+
+msgid "IDS_EMAIL_BODY_ACCEPT_ALL_SSL_CERTIFICATES"
+msgstr "Accept all SSL certificates"
+
+msgid "IDS_EMAIL_SK3_ACCOUNT_LIST"
+msgstr "Account list"
+
+msgid "IDS_EMAIL_BODY_USER_ID"
+msgstr "User ID"
+
+msgid "IDS_EMAIL_POP_ACCOUNT_ALREADY_REGISTERED"
+msgstr "Account already registered"
+
+msgid "IDS_EMAIL_HEADER_ATTACH_FILE"
+msgstr "Attach file"
+
+msgid "IDS_EMAIL_BODY_EXCHANGE_SYNC_SETTINGS_MSG"
+msgstr "By activating this application, you accept that some of your device data (the unique device identifier and model name) will be stored, processed, and used by Samsung to report the activation of this application to the licensors of the application software. Data held by Samsung will be dealt with strictly in accordance with Samsung's privacy policy which is available at www.samsung.com. Continue?"
+
+msgid "IDS_EMAIL_BODY_FORWARD_WITH_FILES"
+msgstr "Forward with files"
+
+msgid "IDS_EMAIL_BODY_REPLY_WITH_BODY"
+msgstr "Reply with body"
+
+msgid "IDS_EMAIL_BODY_NO_SUBJECT"
+msgstr "No subject"
+
+msgid "IDS_EMAIL_BODY_FROM"
+msgstr "From"
+
+msgid "IDS_EMAIL_BODY_NO_ADDRESS"
+msgstr "No address"
+
+msgid "IDS_EMAIL_OPT_RECORD_SOUND"
+msgstr "Record sound"
+
+msgid "IDS_EMAIL_OPT_RECORD_VIDEO"
+msgstr "Record video"
+
+msgid "IDS_EMAIL_OPT_INSERT_IMAGE"
+msgstr "Insert image"
+
+msgid "IDS_EMAIL_OPT_ADD_TO_CALENDAR"
+msgstr "Add to Calendar"
+
+msgid "IDS_EMAIL_OPT_CHANGE_EMAIL_ADDRESS_ABB"
+msgstr "Change email address"
+
+msgid "IDS_EMAIL_OPT_CLIPBOARD"
+msgstr "Clipboard"
+
+msgid "IDS_EMAIL_OPT_MARKED_AS_UNREAD"
+msgstr "Marked as unread"
+
+msgid "IDS_EMAIL_OPT_VIEW_CONTACT_DETAILS"
+msgstr "View contact details"
+
+msgid "IDS_EMAIL_POP_SAVED_IN_DRAFTS"
+msgstr "Saved in Drafts"
+
+msgid "IDS_EMAIL_POP_NETWORK_BUSY"
+msgstr "Network busy"
+
+msgid "IDS_EMAIL_POP_LOGIN_ALLOWED_ONLY_EVERY_PD_MINUTES"
+msgstr "Login allowed only every %d minutes"
+
+msgid "IDS_EMAIL_POP_HOST_NOT_FOUND"
+msgstr "Host not found"
+
+msgid "IDS_EMAIL_POP_HOST_NOT_REACHABLE"
+msgstr "Host not reachable"
+
+msgid "IDS_EMAIL_POP_NO_SERVICE"
+msgstr "No service"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_FORWARD_DRM_CONTENTS"
+msgstr "Unable to forward DRM contents"
+
+msgid "IDS_EMAIL_POP_BLOCKED"
+msgstr "Blocked"
+
+msgid "IDS_EMAIL_POP_1_EMAIL_SELECTED"
+msgstr "1 email selected"
+
+msgid "IDS_EMAIL_POP_PD_EMAILS_SELECTED"
+msgstr "%d emails selected"
+
+msgid "IDS_EMAIL_POP_1_RECIPIENT_SELECTED"
+msgstr "1 recipient selected"
+
+msgid "IDS_EMAIL_POP_PD_RECIPIENTS_SELECTED"
+msgstr "%d recipients selected"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_ADD_ACCOUNT"
+msgstr "Unable to add account"
+
+msgid "IDS_EMAIL_SK3_MOVE_HERE"
+msgstr "Move here"
+
diff --git a/po/es_ES.po b/po/es_ES.po
new file mode 100755
index 0000000..859e34b
--- /dev/null
+++ b/po/es_ES.po
@@ -0,0 +1,465 @@
+msgid "IDS_EMAIL_POP_NO_EMAIL_ADDRESS"
+msgstr "Sin dirección de correo"
+
+msgid "IDS_EMAIL_BODY_COMPLETE"
+msgstr "Completo"
+
+msgid "IDS_EMAIL_BODY_ACCEPTED_C_PS"
+msgstr "Aceptado: %s"
+
+msgid "IDS_EMAIL_BODY_DECLINED_C_PS"
+msgstr "No aceptado: %s"
+
+msgid "IDS_EMAIL_BODY_DOWNLOAD_FULL_MESSAGE"
+msgstr "Descargar mensaje completo"
+
+msgid "IDS_EMAIL_BODY_GENERAL_SETTINGS"
+msgstr "Ajustes generales"
+
+msgid "IDS_EMAIL_BODY_TENTATIVE_C_PS"
+msgstr "Provisional: %s"
+
+msgid "IDS_EMAIL_BODY_WHEN_C_PS"
+msgstr "Cuándo: %s"
+
+msgid "IDS_EMAIL_BODY_WHERE_C_PS"
+msgstr "Dónde: %s"
+
+msgid "IDS_EMAIL_BUTTON_DECLINE_ABB"
+msgstr "Rechazar"
+
+msgid "IDS_EMAIL_BODY_NO_CONTENTS"
+msgstr "No hay contenido"
+
+msgid "IDS_EMAIL_BODY_ORIGINAL_MESSAGE"
+msgstr "Mensaje original"
+
+msgid "IDS_EMAIL_HEADER_ACCOUNT_SETTINGS"
+msgstr "Ajustes de cuenta"
+
+msgid "IDS_EMAIL_OPT_BLOCK"
+msgstr "Bloquear"
+
+msgid "IDS_EMAIL_OPT_MARK_AS_READ"
+msgstr "Marcar como leído"
+
+msgid "IDS_EMAIL_OPT_MARK_AS_UNREAD"
+msgstr "Marcar como no leído"
+
+msgid "IDS_EMAIL_OPT_OTHERS"
+msgstr "Otros"
+
+msgid "IDS_EMAIL_OPT_UNREAD"
+msgstr "No leídos"
+
+msgid "IDS_EMAIL_SK_COMPOSE"
+msgstr "Crear"
+
+msgid "IDS_EMAIL_HEADER_DOWNLOAD_FAILED"
+msgstr "Descarga no disponible"
+
+msgid "IDS_EMAIL_OPT_ADD_TO_CONTACT"
+msgstr "Añadir a contacto"
+
+msgid "IDS_EMAIL_OPT_VOICE_CALL"
+msgstr "Llamada de voz"
+
+msgid "IDS_EMAIL_BODY_ACCOUNT_NAME"
+msgstr "Nombre de cuenta"
+
+msgid "IDS_EMAIL_BODY_ATTACHMENTS"
+msgstr "Archivos adjuntos"
+
+msgid "IDS_EMAIL_BODY_FROM_C"
+msgstr "De:"
+
+msgid "IDS_EMAIL_BODY_IMAP4_SERVER"
+msgstr "Servidor IMAP4"
+
+msgid "IDS_EMAIL_BODY_INCLUDES"
+msgstr "Incluye"
+
+msgid "IDS_EMAIL_BODY_INCOMING_PORT"
+msgstr "Puerto entrante"
+
+msgid "IDS_EMAIL_BODY_INCOMING_SERVER"
+msgstr "Servidor entrante"
+
+msgid "IDS_EMAIL_BODY_IN_PD_MINUTES"
+msgstr "Dentro de %d minutos"
+
+msgid "IDS_EMAIL_BODY_KEEP_IN_SERVER"
+msgstr "Mantener en el servidor"
+
+msgid "IDS_EMAIL_BODY_NO_TEXT"
+msgstr "Sin texto"
+
+msgid "IDS_EMAIL_BODY_OUTGOING_PORT"
+msgstr "Puerto saliente"
+
+msgid "IDS_EMAIL_BODY_OUTGOING_SERVER"
+msgstr "Servidor saliente"
+
+msgid "IDS_EMAIL_BODY_PD_EMAILS"
+msgstr "%d correos electrónicos"
+
+msgid "IDS_EMAIL_BODY_POP3_SERVER"
+msgstr "Servidor POP3"
+
+msgid "IDS_EMAIL_BODY_RECENT"
+msgstr "Reciente"
+
+msgid "IDS_EMAIL_BODY_RETRIEVING_OPTIONS"
+msgstr "Ajustes de recepción"
+
+msgid "IDS_EMAIL_BODY_RE_C"
+msgstr "RE:"
+
+msgid "IDS_EMAIL_BODY_SENT_C"
+msgstr "Enviado:"
+
+msgid "IDS_EMAIL_BODY_SENT_FROM_SAMSUNG_MOBILE"
+msgstr "Enviado de Samsung Mobile"
+
+msgid "IDS_EMAIL_BODY_USER_PASSWORD"
+msgstr "Contraseña de usuario"
+
+msgid "IDS_EMAIL_HEADER_EDIT_RULES"
+msgstr "Editar reglas"
+
+msgid "IDS_EMAIL_HEADER_EMAIL_SETTINGS"
+msgstr "Ajustes de email"
+
+msgid "IDS_EMAIL_HEADER_MAILBOXES"
+msgstr "Buzones de correo"
+
+msgid "IDS_EMAIL_POP_ALERT"
+msgstr "Alerta"
+
+msgid "IDS_EMAIL_POP_FILE_ALREADY_EXISTS"
+msgstr "El archivo ya existe"
+
+msgid "IDS_EMAIL_POP_NO_SENDER"
+msgstr "Ningún remitente"
+
+msgid "IDS_EMAIL_POP_SUCCEEDED"
+msgstr "Realizado con éxito"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_ATTACH_MAXIMUM_NUMBER_OF_FILES_IS_PD"
+msgstr "No se puede adjuntar. El número máximo de archivos es de %d"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_ATTACH_MAXIMUM_SIZE_OF_FILES_IS_PD_KB"
+msgstr "No se puede adjuntar. El tamaño máximo de archivos es de %d KB"
+
+msgid "IDS_EMAIL_POP_VALIDATION_FAILED"
+msgstr "Error de validación"
+
+msgid "IDS_EMAIL_SK_REPLY_ALL"
+msgstr "Responder todos"
+
+msgid "IDS_EMAIL_BODY_1_ITEM"
+msgstr "1 elemento"
+
+msgid "IDS_EMAIL_BODY_ADD_MY_NAMECARD"
+msgstr "Añadir mi tarjeta de contacto"
+
+msgid "IDS_EMAIL_BODY_ADD_SIGNATURE"
+msgstr "Añadir firma"
+
+msgid "IDS_EMAIL_BODY_ALL_EMAILS"
+msgstr "Todos los correos"
+
+msgid "IDS_EMAIL_BODY_ALWAYS_BCC_MYSELF"
+msgstr "Copiarme siempre en copia oculta"
+
+msgid "IDS_EMAIL_BODY_BCC"
+msgstr "Cco"
+
+msgid "IDS_EMAIL_BODY_BLOCK_EMAILS"
+msgstr "Bloquear mensajes de correo electrónico"
+
+msgid "IDS_EMAIL_BODY_BODY"
+msgstr "Cuerpo"
+
+msgid "IDS_EMAIL_BODY_CC"
+msgstr "Cc"
+
+msgid "IDS_EMAIL_BODY_CC_BCC"
+msgstr "CC/CCO"
+
+msgid "IDS_EMAIL_BODY_CHECK_INTERVAL"
+msgstr "Comprobar intervalo"
+
+msgid "IDS_EMAIL_BODY_DEFAULT_ACCOUNT"
+msgstr "Cuenta predetermin"
+
+msgid "IDS_EMAIL_BODY_DRAFTS"
+msgstr "Borradores"
+
+msgid "IDS_EMAIL_BODY_EMAIL_ACCOUNTS"
+msgstr "Cuentas de correo electrónico"
+
+msgid "IDS_EMAIL_BODY_END_TIME"
+msgstr "Hora de finalización"
+
+msgid "IDS_EMAIL_BODY_ENTIRE_EMAIL"
+msgstr "Correo electrónico completo"
+
+msgid "IDS_EMAIL_BODY_EXACTLY_THE_SAME_AS"
+msgstr "Exactamente igual a"
+
+msgid "IDS_EMAIL_BODY_EXAMPLE"
+msgstr "Ejemplo"
+
+msgid "IDS_EMAIL_BODY_FROM_M_SENDER"
+msgstr "De:"
+
+msgid "IDS_EMAIL_BODY_INBOX"
+msgstr "Entrada"
+
+msgid "IDS_EMAIL_BODY_INCLUDE"
+msgstr "Incluir"
+
+msgid "IDS_EMAIL_BODY_MATCH_CRITERIA"
+msgstr "Coincidir criterios"
+
+msgid "IDS_EMAIL_BODY_NOT_USED"
+msgstr "No usado"
+
+msgid "IDS_EMAIL_BODY_NO_ACCOUNTS"
+msgstr "Ninguna cuenta"
+
+msgid "IDS_EMAIL_BODY_PD_DAYS"
+msgstr "%d días"
+
+msgid "IDS_EMAIL_BODY_PD_ITEMS"
+msgstr "%d elementos"
+
+msgid "IDS_EMAIL_BODY_PRIORITY"
+msgstr "Prioridad"
+
+msgid "IDS_EMAIL_BODY_RECEIVING_OPTIONS"
+msgstr "Opciones de recepción"
+
+msgid "IDS_EMAIL_BODY_SECURE_CONNECTION"
+msgstr "Conexión segura"
+
+msgid "IDS_EMAIL_BODY_SENDING_OPTIONS"
+msgstr "Opciones de envío"
+
+msgid "IDS_EMAIL_BODY_SENTBOX"
+msgstr "Enviados"
+
+msgid "IDS_EMAIL_BODY_SERVER_URL"
+msgstr "URL del servidor"
+
+msgid "IDS_EMAIL_BODY_SIGNATURE"
+msgstr "Firma"
+
+msgid "IDS_EMAIL_BODY_SPAMBOX"
+msgstr "Correo no deseado"
+
+msgid "IDS_EMAIL_BODY_START_TIME"
+msgstr "Hora de inicio"
+
+msgid "IDS_EMAIL_BODY_SYNC_SCHEDULE_TMO"
+msgstr "Sincronizar planificación"
+
+msgid "IDS_EMAIL_BODY_TRASH"
+msgstr "Papelera"
+
+msgid "IDS_EMAIL_BODY_WITHOUT_ATTACHMENTS"
+msgstr "Sin archivos adjuntos"
+
+msgid "IDS_EMAIL_BUTTON_GROUP"
+msgstr "Grupo"
+
+msgid "IDS_EMAIL_HEADER_ADD_RULES"
+msgstr "Añadir reglas"
+
+msgid "IDS_EMAIL_OPT_ATTACH_ITEMS"
+msgstr "Adjuntar elementos"
+
+msgid "IDS_EMAIL_OPT_EXCHANGE"
+msgstr "Exchange"
+
+msgid "IDS_EMAIL_OPT_FILE"
+msgstr "Archivo"
+
+msgid "IDS_EMAIL_OPT_NAMECARD"
+msgstr "Tarjeta de contacto"
+
+msgid "IDS_EMAIL_OPT_OPEN_URL"
+msgstr "Abrir URL"
+
+msgid "IDS_EMAIL_OPT_SENDER"
+msgstr "Remitente"
+
+msgid "IDS_EMAIL_OPT_SEND_EMAIL"
+msgstr "Enviar correo electrónico"
+
+msgid "IDS_EMAIL_OPT_UPDATE_EXISTING"
+msgstr "Actualizar existente"
+
+msgid "IDS_EMAIL_POP_ADD_ACCOUNTS"
+msgstr "Añadir cuentas"
+
+msgid "IDS_EMAIL_POP_DOWNLOADING_ATTACHMENT_ING"
+msgstr "Descargando adjunto..."
+
+msgid "IDS_EMAIL_POP_INVALID_EMAIL_ADDRESS"
+msgstr "Dirección de correo electrónico no válida"
+
+msgid "IDS_EMAIL_POP_LOADING_CONTENTS_ING"
+msgstr "Cargando contenidos..."
+
+msgid "IDS_EMAIL_POP_MAXIMUM_NUMBER_OF_ATTACHMENTS_REACHED"
+msgstr "Alcanzado el número máximo de adjuntos"
+
+msgid "IDS_EMAIL_POP_MOVE_TO_SPAMBOX_Q"
+msgstr "¿Mover a bandeja de correo no deseado?"
+
+msgid "IDS_EMAIL_POP_NO_RECIPIENTS_ADDED_ENTER_RECIPIENTS"
+msgstr "No se han añadido destinatarios. Introduzca destinatarios"
+
+msgid "IDS_EMAIL_POP_PLEASE_FILL_ALL_THE_MANDATORY_FIELDS"
+msgstr "Rellene todos los campos obligatorios"
+
+msgid "IDS_EMAIL_POP_SAVE_IN_DRAFTS_Q"
+msgstr "¿Guardar en Borradores?"
+
+msgid "IDS_EMAIL_POP_THERE_IS_NO_ACCOUNT_CREATE_A_NEW_ACCOUNT_FIRST"
+msgstr "No hay ninguna cuenta. Cree una cuenta nueva primero"
+
+msgid "IDS_EMAIL_POP_TOO_MANY_RECIPIENTS"
+msgstr "Demasiados destinatarios"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_DOWNLOAD"
+msgstr "No se puede descargar"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_ENTER_TEXT"
+msgstr "No se puede escribir texto"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_LAUNCH_APPLICATION"
+msgstr "No se puede iniciar aplicación"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_OPEN_ATTACHMENT"
+msgstr "No se puede abrir adjunto"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_SAVE_ATTACHMENT"
+msgstr "No se puede guardar adjunto"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_SAVE_IN_DRAFTS"
+msgstr "No se puede guardar en Borradores"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_SEND_EMAIL"
+msgstr "No se puede enviar el correo electrónico"
+
+msgid "IDS_EMAIL_POP_UNSUPPORTED_FILE_TYPE"
+msgstr "Tipo de archivo no admitido"
+
+msgid "IDS_EMAIL_POP_VALIDATING_ACCOUNT_ING"
+msgstr "Validando cuenta..."
+
+msgid "IDS_EMAIL_SK_RESEND"
+msgstr "Reenviar"
+
+msgid "IDS_EMAIL_BODY_ACCEPT_ALL_SSL_CERTIFICATES"
+msgstr "Aceptar todos los certificados de SSL"
+
+msgid "IDS_EMAIL_SK3_ACCOUNT_LIST"
+msgstr "Lista de cuentas"
+
+msgid "IDS_EMAIL_BODY_USER_ID"
+msgstr "ID de usuario"
+
+msgid "IDS_EMAIL_POP_ACCOUNT_ALREADY_REGISTERED"
+msgstr "Cuenta ya registrada"
+
+msgid "IDS_EMAIL_HEADER_ATTACH_FILE"
+msgstr "Adjuntar archivo"
+
+msgid "IDS_EMAIL_BODY_EXCHANGE_SYNC_SETTINGS_MSG"
+msgstr "Al activar esta aplicación acepta el almacenamiento, procesamiento y uso de algunos de datos de su dispositivo (identificador único de dispositivo y nombre del modelo) por parte de Samsung, para informar de la activación de esta aplicación a los cedentes de licencia del propio software. Los datos que Samsung posea serán tratados estrictamente conforme a la directiva de privacidad de Samsung, que está disponible en www.samsung.com. ¿Continuar?"
+
+msgid "IDS_EMAIL_BODY_FORWARD_WITH_FILES"
+msgstr "Reenviar con archivos"
+
+msgid "IDS_EMAIL_BODY_REPLY_WITH_BODY"
+msgstr "Responder con cuerpo"
+
+msgid "IDS_EMAIL_BODY_NO_SUBJECT"
+msgstr "Sin asunto"
+
+msgid "IDS_EMAIL_BODY_FROM"
+msgstr "De"
+
+msgid "IDS_EMAIL_BODY_NO_ADDRESS"
+msgstr "Sin dirección"
+
+msgid "IDS_EMAIL_OPT_RECORD_SOUND"
+msgstr "Grabar sonido"
+
+msgid "IDS_EMAIL_OPT_RECORD_VIDEO"
+msgstr "Grabar vídeo"
+
+msgid "IDS_EMAIL_OPT_INSERT_IMAGE"
+msgstr "Insertar imagen"
+
+msgid "IDS_EMAIL_OPT_ADD_TO_CALENDAR"
+msgstr "Añadir a calendario"
+
+msgid "IDS_EMAIL_OPT_CHANGE_EMAIL_ADDRESS_ABB"
+msgstr "Cambiar dirección de correo electrónico"
+
+msgid "IDS_EMAIL_OPT_CLIPBOARD"
+msgstr "Portapapeles"
+
+msgid "IDS_EMAIL_OPT_MARKED_AS_UNREAD"
+msgstr "Marcado como no leído"
+
+msgid "IDS_EMAIL_OPT_VIEW_CONTACT_DETAILS"
+msgstr "Ver detalles de contacto"
+
+msgid "IDS_EMAIL_POP_SAVED_IN_DRAFTS"
+msgstr "Guardado en Borradores"
+
+msgid "IDS_EMAIL_POP_NETWORK_BUSY"
+msgstr "Red ocupada"
+
+msgid "IDS_EMAIL_POP_LOGIN_ALLOWED_ONLY_EVERY_PD_MINUTES"
+msgstr "Login allowed only every %d minutes"
+
+msgid "IDS_EMAIL_POP_HOST_NOT_FOUND"
+msgstr "Host no encontrado"
+
+msgid "IDS_EMAIL_POP_HOST_NOT_REACHABLE"
+msgstr "Host no localizable"
+
+msgid "IDS_EMAIL_POP_NO_SERVICE"
+msgstr "Sin servicio"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_FORWARD_DRM_CONTENTS"
+msgstr "No se pueden reenviar contenidos de DRM"
+
+msgid "IDS_EMAIL_POP_BLOCKED"
+msgstr "Bloqueado"
+
+msgid "IDS_EMAIL_POP_1_EMAIL_SELECTED"
+msgstr "1 correo electrónico seleccionado"
+
+msgid "IDS_EMAIL_POP_PD_EMAILS_SELECTED"
+msgstr "%d correos electrónicos seleccionados"
+
+msgid "IDS_EMAIL_POP_1_RECIPIENT_SELECTED"
+msgstr "1 destinatario seleccionado"
+
+msgid "IDS_EMAIL_POP_PD_RECIPIENTS_SELECTED"
+msgstr "%d destinatarios seleccionados"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_ADD_ACCOUNT"
+msgstr "No se puede añadir cuenta"
+
+msgid "IDS_EMAIL_SK3_MOVE_HERE"
+msgstr "Mover aquí"
+
diff --git a/po/fr_FR.po b/po/fr_FR.po
new file mode 100755
index 0000000..3820c65
--- /dev/null
+++ b/po/fr_FR.po
@@ -0,0 +1,465 @@
+msgid "IDS_EMAIL_POP_NO_EMAIL_ADDRESS"
+msgstr "Aucune adresse e-mail"
+
+msgid "IDS_EMAIL_BODY_COMPLETE"
+msgstr "OK"
+
+msgid "IDS_EMAIL_BODY_ACCEPTED_C_PS"
+msgstr "Accepté : %s"
+
+msgid "IDS_EMAIL_BODY_DECLINED_C_PS"
+msgstr "Refusé : %s"
+
+msgid "IDS_EMAIL_BODY_DOWNLOAD_FULL_MESSAGE"
+msgstr "Télécharger l'intégralité du message"
+
+msgid "IDS_EMAIL_BODY_GENERAL_SETTINGS"
+msgstr "Paramètres généraux"
+
+msgid "IDS_EMAIL_BODY_TENTATIVE_C_PS"
+msgstr "Tentative : %s"
+
+msgid "IDS_EMAIL_BODY_WHEN_C_PS"
+msgstr "Date : %s"
+
+msgid "IDS_EMAIL_BODY_WHERE_C_PS"
+msgstr "Emplacement : %s"
+
+msgid "IDS_EMAIL_BUTTON_DECLINE_ABB"
+msgstr "Refuser"
+
+msgid "IDS_EMAIL_BODY_NO_CONTENTS"
+msgstr "Aucun fichier"
+
+msgid "IDS_EMAIL_BODY_ORIGINAL_MESSAGE"
+msgstr "Message d'origine"
+
+msgid "IDS_EMAIL_HEADER_ACCOUNT_SETTINGS"
+msgstr "Paramètres du compte"
+
+msgid "IDS_EMAIL_OPT_BLOCK"
+msgstr "Bloquer"
+
+msgid "IDS_EMAIL_OPT_MARK_AS_READ"
+msgstr "Marqué comme lu"
+
+msgid "IDS_EMAIL_OPT_MARK_AS_UNREAD"
+msgstr "Marquer comme Non lu"
+
+msgid "IDS_EMAIL_OPT_OTHERS"
+msgstr "Autres"
+
+msgid "IDS_EMAIL_OPT_UNREAD"
+msgstr "Non lu"
+
+msgid "IDS_EMAIL_SK_COMPOSE"
+msgstr "Rédiger"
+
+msgid "IDS_EMAIL_HEADER_DOWNLOAD_FAILED"
+msgstr "Téléchargement impossible"
+
+msgid "IDS_EMAIL_OPT_ADD_TO_CONTACT"
+msgstr "Ajouter aux contacts"
+
+msgid "IDS_EMAIL_OPT_VOICE_CALL"
+msgstr "Appel vocal"
+
+msgid "IDS_EMAIL_BODY_ACCOUNT_NAME"
+msgstr "Nom du compte"
+
+msgid "IDS_EMAIL_BODY_ATTACHMENTS"
+msgstr "pièce(s) jointe(s)"
+
+msgid "IDS_EMAIL_BODY_FROM_C"
+msgstr "De :"
+
+msgid "IDS_EMAIL_BODY_IMAP4_SERVER"
+msgstr "Serveur IMAP4"
+
+msgid "IDS_EMAIL_BODY_INCLUDES"
+msgstr "Inclut"
+
+msgid "IDS_EMAIL_BODY_INCOMING_PORT"
+msgstr "Port entrant"
+
+msgid "IDS_EMAIL_BODY_INCOMING_SERVER"
+msgstr "Serveur entrant"
+
+msgid "IDS_EMAIL_BODY_IN_PD_MINUTES"
+msgstr "Dans %d minutes"
+
+msgid "IDS_EMAIL_BODY_KEEP_IN_SERVER"
+msgstr "Garder sur le serveur"
+
+msgid "IDS_EMAIL_BODY_NO_TEXT"
+msgstr "Aucun texte"
+
+msgid "IDS_EMAIL_BODY_OUTGOING_PORT"
+msgstr "Port sortant"
+
+msgid "IDS_EMAIL_BODY_OUTGOING_SERVER"
+msgstr "Serveur sortant"
+
+msgid "IDS_EMAIL_BODY_PD_EMAILS"
+msgstr "%d e-mails"
+
+msgid "IDS_EMAIL_BODY_POP3_SERVER"
+msgstr "Serveur POP3"
+
+msgid "IDS_EMAIL_BODY_RECENT"
+msgstr "Récent"
+
+msgid "IDS_EMAIL_BODY_RETRIEVING_OPTIONS"
+msgstr "Paramètres de récupération"
+
+msgid "IDS_EMAIL_BODY_RE_C"
+msgstr "RE :"
+
+msgid "IDS_EMAIL_BODY_SENT_C"
+msgstr "Envoyé :"
+
+msgid "IDS_EMAIL_BODY_SENT_FROM_SAMSUNG_MOBILE"
+msgstr "Envoyé depuis un mobile Samsung"
+
+msgid "IDS_EMAIL_BODY_USER_PASSWORD"
+msgstr "Mot de passe utilisateur"
+
+msgid "IDS_EMAIL_HEADER_EDIT_RULES"
+msgstr "Modifier les règles"
+
+msgid "IDS_EMAIL_HEADER_EMAIL_SETTINGS"
+msgstr "Paramètres e-mail"
+
+msgid "IDS_EMAIL_HEADER_MAILBOXES"
+msgstr "Messageries"
+
+msgid "IDS_EMAIL_POP_ALERT"
+msgstr "Alerte"
+
+msgid "IDS_EMAIL_POP_FILE_ALREADY_EXISTS"
+msgstr "Le fichier existe déjà"
+
+msgid "IDS_EMAIL_POP_NO_SENDER"
+msgstr "Aucun expéditeur"
+
+msgid "IDS_EMAIL_POP_SUCCEEDED"
+msgstr "Opérations terminées"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_ATTACH_MAXIMUM_NUMBER_OF_FILES_IS_PD"
+msgstr "Impossible d'ajouter la pièce jointe. Le nombre maximum de fichiers est %d"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_ATTACH_MAXIMUM_SIZE_OF_FILES_IS_PD_KB"
+msgstr "Impossible d'ajouter la pièce jointe. La taille maximale des fichiers est de %d Ko"
+
+msgid "IDS_EMAIL_POP_VALIDATION_FAILED"
+msgstr "Echec de la validation"
+
+msgid "IDS_EMAIL_SK_REPLY_ALL"
+msgstr "Répondre à tous"
+
+msgid "IDS_EMAIL_BODY_1_ITEM"
+msgstr "1 élément"
+
+msgid "IDS_EMAIL_BODY_ADD_MY_NAMECARD"
+msgstr "Ajouter ma carte de visite"
+
+msgid "IDS_EMAIL_BODY_ADD_SIGNATURE"
+msgstr "Ajouter une signature"
+
+msgid "IDS_EMAIL_BODY_ALL_EMAILS"
+msgstr "Tous les e-mails"
+
+msgid "IDS_EMAIL_BODY_ALWAYS_BCC_MYSELF"
+msgstr "Toujours me mettre en copie"
+
+msgid "IDS_EMAIL_BODY_BCC"
+msgstr "Cci"
+
+msgid "IDS_EMAIL_BODY_BLOCK_EMAILS"
+msgstr "Bloquer les e-mails"
+
+msgid "IDS_EMAIL_BODY_BODY"
+msgstr "Corps"
+
+msgid "IDS_EMAIL_BODY_CC"
+msgstr "Cc"
+
+msgid "IDS_EMAIL_BODY_CC_BCC"
+msgstr "Cc/Cci"
+
+msgid "IDS_EMAIL_BODY_CHECK_INTERVAL"
+msgstr "Fréquence de vérification"
+
+msgid "IDS_EMAIL_BODY_DEFAULT_ACCOUNT"
+msgstr "Compte par défaut"
+
+msgid "IDS_EMAIL_BODY_DRAFTS"
+msgstr "Brouillons"
+
+msgid "IDS_EMAIL_BODY_EMAIL_ACCOUNTS"
+msgstr "Comptes e-mail"
+
+msgid "IDS_EMAIL_BODY_END_TIME"
+msgstr "Heure de fin"
+
+msgid "IDS_EMAIL_BODY_ENTIRE_EMAIL"
+msgstr "E-mail entier"
+
+msgid "IDS_EMAIL_BODY_EXACTLY_THE_SAME_AS"
+msgstr "Identique à"
+
+msgid "IDS_EMAIL_BODY_EXAMPLE"
+msgstr "Exemple"
+
+msgid "IDS_EMAIL_BODY_FROM_M_SENDER"
+msgstr "De :"
+
+msgid "IDS_EMAIL_BODY_INBOX"
+msgstr "Boîte de réception"
+
+msgid "IDS_EMAIL_BODY_INCLUDE"
+msgstr "Inclure"
+
+msgid "IDS_EMAIL_BODY_MATCH_CRITERIA"
+msgstr "Critères correspondants"
+
+msgid "IDS_EMAIL_BODY_NOT_USED"
+msgstr "Non utilisé"
+
+msgid "IDS_EMAIL_BODY_NO_ACCOUNTS"
+msgstr "Aucun compte"
+
+msgid "IDS_EMAIL_BODY_PD_DAYS"
+msgstr "%d jours"
+
+msgid "IDS_EMAIL_BODY_PD_ITEMS"
+msgstr "%d éléments"
+
+msgid "IDS_EMAIL_BODY_PRIORITY"
+msgstr "Priorité"
+
+msgid "IDS_EMAIL_BODY_RECEIVING_OPTIONS"
+msgstr "Options de réception"
+
+msgid "IDS_EMAIL_BODY_SECURE_CONNECTION"
+msgstr "Connexion sécurisée"
+
+msgid "IDS_EMAIL_BODY_SENDING_OPTIONS"
+msgstr "Options d'envoi"
+
+msgid "IDS_EMAIL_BODY_SENTBOX"
+msgstr "Messages envoyés"
+
+msgid "IDS_EMAIL_BODY_SERVER_URL"
+msgstr "URL serveur"
+
+msgid "IDS_EMAIL_BODY_SIGNATURE"
+msgstr "Signature"
+
+msgid "IDS_EMAIL_BODY_SPAMBOX"
+msgstr "Boîte des spams"
+
+msgid "IDS_EMAIL_BODY_START_TIME"
+msgstr "Heure de début"
+
+msgid "IDS_EMAIL_BODY_SYNC_SCHEDULE_TMO"
+msgstr "Paramètres de synchronisation"
+
+msgid "IDS_EMAIL_BODY_TRASH"
+msgstr "Corbeille"
+
+msgid "IDS_EMAIL_BODY_WITHOUT_ATTACHMENTS"
+msgstr "Sans pièce jointe"
+
+msgid "IDS_EMAIL_BUTTON_GROUP"
+msgstr "Groupe"
+
+msgid "IDS_EMAIL_HEADER_ADD_RULES"
+msgstr "Ajouter des règles"
+
+msgid "IDS_EMAIL_OPT_ATTACH_ITEMS"
+msgstr "Pièces jointes"
+
+msgid "IDS_EMAIL_OPT_EXCHANGE"
+msgstr "Exchange"
+
+msgid "IDS_EMAIL_OPT_FILE"
+msgstr "Fichier"
+
+msgid "IDS_EMAIL_OPT_NAMECARD"
+msgstr "Carte de visite"
+
+msgid "IDS_EMAIL_OPT_OPEN_URL"
+msgstr "Ouvrir la page internet"
+
+msgid "IDS_EMAIL_OPT_SENDER"
+msgstr "Expéditeur"
+
+msgid "IDS_EMAIL_OPT_SEND_EMAIL"
+msgstr "Envoyer un e-mail"
+
+msgid "IDS_EMAIL_OPT_UPDATE_EXISTING"
+msgstr "Mettre à jour les contacts existants"
+
+msgid "IDS_EMAIL_POP_ADD_ACCOUNTS"
+msgstr "Ajouter des comptes"
+
+msgid "IDS_EMAIL_POP_DOWNLOADING_ATTACHMENT_ING"
+msgstr "Téléchargement de la pièce jointe..."
+
+msgid "IDS_EMAIL_POP_INVALID_EMAIL_ADDRESS"
+msgstr "E-mail incorrect"
+
+msgid "IDS_EMAIL_POP_LOADING_CONTENTS_ING"
+msgstr " Chargement du contenu..."
+
+msgid "IDS_EMAIL_POP_MAXIMUM_NUMBER_OF_ATTACHMENTS_REACHED"
+msgstr "Nombre maximum de pièces jointes atteint"
+
+msgid "IDS_EMAIL_POP_MOVE_TO_SPAMBOX_Q"
+msgstr "Déplacer vers la boîte des spams ?"
+
+msgid "IDS_EMAIL_POP_NO_RECIPIENTS_ADDED_ENTER_RECIPIENTS"
+msgstr "Aucun destinataire ajouté. Sélectionnez"
+
+msgid "IDS_EMAIL_POP_PLEASE_FILL_ALL_THE_MANDATORY_FIELDS"
+msgstr "Complétez les champs obligatoires"
+
+msgid "IDS_EMAIL_POP_SAVE_IN_DRAFTS_Q"
+msgstr "Enregistrer dans Brouillons ?"
+
+msgid "IDS_EMAIL_POP_THERE_IS_NO_ACCOUNT_CREATE_A_NEW_ACCOUNT_FIRST"
+msgstr "Aucun compte existant. Créez d'abord un compte"
+
+msgid "IDS_EMAIL_POP_TOO_MANY_RECIPIENTS"
+msgstr "Trop de destinataires"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_DOWNLOAD"
+msgstr "Téléchargement impossible"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_ENTER_TEXT"
+msgstr "Impossible de saisir du texte"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_LAUNCH_APPLICATION"
+msgstr "Impossible de lancer l'application"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_OPEN_ATTACHMENT"
+msgstr "Impossible d'ouvrir la pièce jointe"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_SAVE_ATTACHMENT"
+msgstr "Impossible d'enregistrer la pièce jointe"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_SAVE_IN_DRAFTS"
+msgstr "Impossible d'enregistrer dans Brouillons"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_SEND_EMAIL"
+msgstr "Impossible d'envoyer l'e-mail"
+
+msgid "IDS_EMAIL_POP_UNSUPPORTED_FILE_TYPE"
+msgstr "Type de fichier non pris en charge"
+
+msgid "IDS_EMAIL_POP_VALIDATING_ACCOUNT_ING"
+msgstr "Validation du compte..."
+
+msgid "IDS_EMAIL_SK_RESEND"
+msgstr "Renvoyer"
+
+msgid "IDS_EMAIL_BODY_ACCEPT_ALL_SSL_CERTIFICATES"
+msgstr "Accepter tous les certificats SSL"
+
+msgid "IDS_EMAIL_SK3_ACCOUNT_LIST"
+msgstr "Liste comptes"
+
+msgid "IDS_EMAIL_BODY_USER_ID"
+msgstr "ID utilisateur"
+
+msgid "IDS_EMAIL_POP_ACCOUNT_ALREADY_REGISTERED"
+msgstr "Compte déjà enregistré"
+
+msgid "IDS_EMAIL_HEADER_ATTACH_FILE"
+msgstr "Joindre le fichier"
+
+msgid "IDS_EMAIL_BODY_EXCHANGE_SYNC_SETTINGS_MSG"
+msgstr "En activant cette application, vous acceptez que certaines données stockées sur votre périphérique (ID périphérique unique et nom de modèle) soient enregistrées, traitées et utilisées par Samsung afin de signaler l'activation de l'application aux concédants de licences du logiciel. Les données détenues par Samsung seront diffusées conformément à la politique de confidentialité de Samsung qui est disponible sur www.samsung.com. Continuer ?"
+
+msgid "IDS_EMAIL_BODY_FORWARD_WITH_FILES"
+msgstr "Transférer fichiers"
+
+msgid "IDS_EMAIL_BODY_REPLY_WITH_BODY"
+msgstr "Répondre avec le corps"
+
+msgid "IDS_EMAIL_BODY_NO_SUBJECT"
+msgstr "Aucun objet"
+
+msgid "IDS_EMAIL_BODY_FROM"
+msgstr "De"
+
+msgid "IDS_EMAIL_BODY_NO_ADDRESS"
+msgstr "Aucune adresse"
+
+msgid "IDS_EMAIL_OPT_RECORD_SOUND"
+msgstr "Enregistrer un mémo"
+
+msgid "IDS_EMAIL_OPT_RECORD_VIDEO"
+msgstr "Enregistrer une vidéo"
+
+msgid "IDS_EMAIL_OPT_INSERT_IMAGE"
+msgstr "Insérer une image"
+
+msgid "IDS_EMAIL_OPT_ADD_TO_CALENDAR"
+msgstr "Ajouter au calendrier"
+
+msgid "IDS_EMAIL_OPT_CHANGE_EMAIL_ADDRESS_ABB"
+msgstr "Changer l'adresse e-mail"
+
+msgid "IDS_EMAIL_OPT_CLIPBOARD"
+msgstr "Presse-papiers"
+
+msgid "IDS_EMAIL_OPT_MARKED_AS_UNREAD"
+msgstr "Marqué comme non lu"
+
+msgid "IDS_EMAIL_OPT_VIEW_CONTACT_DETAILS"
+msgstr "Afficher détails du contact"
+
+msgid "IDS_EMAIL_POP_SAVED_IN_DRAFTS"
+msgstr "Enregistré dans Brouillons"
+
+msgid "IDS_EMAIL_POP_NETWORK_BUSY"
+msgstr "Réseau occupé"
+
+msgid "IDS_EMAIL_POP_LOGIN_ALLOWED_ONLY_EVERY_PD_MINUTES"
+msgstr "Connexion autorisée toutes les %d minutes uniquement"
+
+msgid "IDS_EMAIL_POP_HOST_NOT_FOUND"
+msgstr "Hôte introuvable"
+
+msgid "IDS_EMAIL_POP_HOST_NOT_REACHABLE"
+msgstr "Hôte non disponible"
+
+msgid "IDS_EMAIL_POP_NO_SERVICE"
+msgstr "Aucun service"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_FORWARD_DRM_CONTENTS"
+msgstr "Impossible de transférer les contenus DRM"
+
+msgid "IDS_EMAIL_POP_BLOCKED"
+msgstr "Bloqué"
+
+msgid "IDS_EMAIL_POP_1_EMAIL_SELECTED"
+msgstr "1 e-mail sélectionné"
+
+msgid "IDS_EMAIL_POP_PD_EMAILS_SELECTED"
+msgstr "%d e-mails sélectionnés"
+
+msgid "IDS_EMAIL_POP_1_RECIPIENT_SELECTED"
+msgstr "1 destinataire sélectionné"
+
+msgid "IDS_EMAIL_POP_PD_RECIPIENTS_SELECTED"
+msgstr "%d destinataires sélectionnés"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_ADD_ACCOUNT"
+msgstr "Impossible d'ajouter le compte"
+
+msgid "IDS_EMAIL_SK3_MOVE_HERE"
+msgstr "Déplacer ici"
+
diff --git a/po/it_IT.po b/po/it_IT.po
new file mode 100755
index 0000000..a9f69c6
--- /dev/null
+++ b/po/it_IT.po
@@ -0,0 +1,465 @@
+msgid "IDS_EMAIL_POP_NO_EMAIL_ADDRESS"
+msgstr "Nessun indirizzo e-mail"
+
+msgid "IDS_EMAIL_BODY_COMPLETE"
+msgstr "Completo"
+
+msgid "IDS_EMAIL_BODY_ACCEPTED_C_PS"
+msgstr "Accettato: %s"
+
+msgid "IDS_EMAIL_BODY_DECLINED_C_PS"
+msgstr "Rifiutato: %s"
+
+msgid "IDS_EMAIL_BODY_DOWNLOAD_FULL_MESSAGE"
+msgstr "Scarica messaggio completo"
+
+msgid "IDS_EMAIL_BODY_GENERAL_SETTINGS"
+msgstr "Generali"
+
+msgid "IDS_EMAIL_BODY_TENTATIVE_C_PS"
+msgstr "Provvisorio: %s"
+
+msgid "IDS_EMAIL_BODY_WHEN_C_PS"
+msgstr "Quando: %s"
+
+msgid "IDS_EMAIL_BODY_WHERE_C_PS"
+msgstr "Dove: %s"
+
+msgid "IDS_EMAIL_BUTTON_DECLINE_ABB"
+msgstr "Rifiuta"
+
+msgid "IDS_EMAIL_BODY_NO_CONTENTS"
+msgstr "Nessun contenuto"
+
+msgid "IDS_EMAIL_BODY_ORIGINAL_MESSAGE"
+msgstr "Messaggio originale"
+
+msgid "IDS_EMAIL_HEADER_ACCOUNT_SETTINGS"
+msgstr "Impostazioni account"
+
+msgid "IDS_EMAIL_OPT_BLOCK"
+msgstr "Blocca"
+
+msgid "IDS_EMAIL_OPT_MARK_AS_READ"
+msgstr "Segna come letto"
+
+msgid "IDS_EMAIL_OPT_MARK_AS_UNREAD"
+msgstr "Segna come non letto"
+
+msgid "IDS_EMAIL_OPT_OTHERS"
+msgstr "Altro"
+
+msgid "IDS_EMAIL_OPT_UNREAD"
+msgstr "Non letto"
+
+msgid "IDS_EMAIL_SK_COMPOSE"
+msgstr "Componi"
+
+msgid "IDS_EMAIL_HEADER_DOWNLOAD_FAILED"
+msgstr "Errore download"
+
+msgid "IDS_EMAIL_OPT_ADD_TO_CONTACT"
+msgstr "Aggiungi a contatto"
+
+msgid "IDS_EMAIL_OPT_VOICE_CALL"
+msgstr "Chiamata vocale"
+
+msgid "IDS_EMAIL_BODY_ACCOUNT_NAME"
+msgstr "Nome account"
+
+msgid "IDS_EMAIL_BODY_ATTACHMENTS"
+msgstr "Allegati"
+
+msgid "IDS_EMAIL_BODY_FROM_C"
+msgstr "Da:"
+
+msgid "IDS_EMAIL_BODY_IMAP4_SERVER"
+msgstr "Server IMAP4"
+
+msgid "IDS_EMAIL_BODY_INCLUDES"
+msgstr "Include"
+
+msgid "IDS_EMAIL_BODY_INCOMING_PORT"
+msgstr "Porta in arrivo"
+
+msgid "IDS_EMAIL_BODY_INCOMING_SERVER"
+msgstr "Server posta in arrivo"
+
+msgid "IDS_EMAIL_BODY_IN_PD_MINUTES"
+msgstr "Tra %d minuti"
+
+msgid "IDS_EMAIL_BODY_KEEP_IN_SERVER"
+msgstr "Conserva sul server"
+
+msgid "IDS_EMAIL_BODY_NO_TEXT"
+msgstr "Nessun testo"
+
+msgid "IDS_EMAIL_BODY_OUTGOING_PORT"
+msgstr "Porta in uscita"
+
+msgid "IDS_EMAIL_BODY_OUTGOING_SERVER"
+msgstr "Server posta in uscita"
+
+msgid "IDS_EMAIL_BODY_PD_EMAILS"
+msgstr "%d e-mail"
+
+msgid "IDS_EMAIL_BODY_POP3_SERVER"
+msgstr "Server POP3"
+
+msgid "IDS_EMAIL_BODY_RECENT"
+msgstr "Recenti"
+
+msgid "IDS_EMAIL_BODY_RETRIEVING_OPTIONS"
+msgstr "Opzioni di recupero"
+
+msgid "IDS_EMAIL_BODY_RE_C"
+msgstr "R:"
+
+msgid "IDS_EMAIL_BODY_SENT_C"
+msgstr "Inviato:"
+
+msgid "IDS_EMAIL_BODY_SENT_FROM_SAMSUNG_MOBILE"
+msgstr "Inviato da Samsung Mobile"
+
+msgid "IDS_EMAIL_BODY_USER_PASSWORD"
+msgstr "Password utente"
+
+msgid "IDS_EMAIL_HEADER_EDIT_RULES"
+msgstr "Modifica regole"
+
+msgid "IDS_EMAIL_HEADER_EMAIL_SETTINGS"
+msgstr "Impostaz. e-mail"
+
+msgid "IDS_EMAIL_HEADER_MAILBOXES"
+msgstr "Caselle di posta"
+
+msgid "IDS_EMAIL_POP_ALERT"
+msgstr "Avviso"
+
+msgid "IDS_EMAIL_POP_FILE_ALREADY_EXISTS"
+msgstr "File già esistente"
+
+msgid "IDS_EMAIL_POP_NO_SENDER"
+msgstr "Nessun mittente"
+
+msgid "IDS_EMAIL_POP_SUCCEEDED"
+msgstr "Operazioni eseguite"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_ATTACH_MAXIMUM_NUMBER_OF_FILES_IS_PD"
+msgstr "Impossibile allegare. Numero massimo file %d"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_ATTACH_MAXIMUM_SIZE_OF_FILES_IS_PD_KB"
+msgstr "Impossibile allegare. Dimensioni massime file %d KB"
+
+msgid "IDS_EMAIL_POP_VALIDATION_FAILED"
+msgstr "Convalida non eseguita"
+
+msgid "IDS_EMAIL_SK_REPLY_ALL"
+msgstr "Rispondi a tutti"
+
+msgid "IDS_EMAIL_BODY_1_ITEM"
+msgstr "1 elemento"
+
+msgid "IDS_EMAIL_BODY_ADD_MY_NAMECARD"
+msgstr "Aggiungi biglietto da visita personale"
+
+msgid "IDS_EMAIL_BODY_ADD_SIGNATURE"
+msgstr "Aggiungi firma"
+
+msgid "IDS_EMAIL_BODY_ALL_EMAILS"
+msgstr "Tutte le e-mail"
+
+msgid "IDS_EMAIL_BODY_ALWAYS_BCC_MYSELF"
+msgstr "Sempre Ccn a me stesso"
+
+msgid "IDS_EMAIL_BODY_BCC"
+msgstr "Ccn"
+
+msgid "IDS_EMAIL_BODY_BLOCK_EMAILS"
+msgstr "Blocca e-mail"
+
+msgid "IDS_EMAIL_BODY_BODY"
+msgstr "Corpo"
+
+msgid "IDS_EMAIL_BODY_CC"
+msgstr "Cc"
+
+msgid "IDS_EMAIL_BODY_CC_BCC"
+msgstr "Cc/Ccn"
+
+msgid "IDS_EMAIL_BODY_CHECK_INTERVAL"
+msgstr "Frequenza controllo"
+
+msgid "IDS_EMAIL_BODY_DEFAULT_ACCOUNT"
+msgstr "Account predefinito"
+
+msgid "IDS_EMAIL_BODY_DRAFTS"
+msgstr "Bozze"
+
+msgid "IDS_EMAIL_BODY_EMAIL_ACCOUNTS"
+msgstr "Account e-mail"
+
+msgid "IDS_EMAIL_BODY_END_TIME"
+msgstr "Ora fine"
+
+msgid "IDS_EMAIL_BODY_ENTIRE_EMAIL"
+msgstr "Intera e-mail"
+
+msgid "IDS_EMAIL_BODY_EXACTLY_THE_SAME_AS"
+msgstr "Esattamente uguale a"
+
+msgid "IDS_EMAIL_BODY_EXAMPLE"
+msgstr "Esempio"
+
+msgid "IDS_EMAIL_BODY_FROM_M_SENDER"
+msgstr "Da:"
+
+msgid "IDS_EMAIL_BODY_INBOX"
+msgstr "Ricevuti"
+
+msgid "IDS_EMAIL_BODY_INCLUDE"
+msgstr "Contiene"
+
+msgid "IDS_EMAIL_BODY_MATCH_CRITERIA"
+msgstr "Criteri esatti"
+
+msgid "IDS_EMAIL_BODY_NOT_USED"
+msgstr "Non attivo"
+
+msgid "IDS_EMAIL_BODY_NO_ACCOUNTS"
+msgstr "Nessun account"
+
+msgid "IDS_EMAIL_BODY_PD_DAYS"
+msgstr "%d giorni"
+
+msgid "IDS_EMAIL_BODY_PD_ITEMS"
+msgstr "%d elementi"
+
+msgid "IDS_EMAIL_BODY_PRIORITY"
+msgstr "Priorità"
+
+msgid "IDS_EMAIL_BODY_RECEIVING_OPTIONS"
+msgstr "Opzioni di ricezione"
+
+msgid "IDS_EMAIL_BODY_SECURE_CONNECTION"
+msgstr "Connessione protetta"
+
+msgid "IDS_EMAIL_BODY_SENDING_OPTIONS"
+msgstr "Opzioni di invio"
+
+msgid "IDS_EMAIL_BODY_SENTBOX"
+msgstr "Inviati"
+
+msgid "IDS_EMAIL_BODY_SERVER_URL"
+msgstr "URL server"
+
+msgid "IDS_EMAIL_BODY_SIGNATURE"
+msgstr "Firma"
+
+msgid "IDS_EMAIL_BODY_SPAMBOX"
+msgstr "Cartella spam"
+
+msgid "IDS_EMAIL_BODY_START_TIME"
+msgstr "Ora inizio"
+
+msgid "IDS_EMAIL_BODY_SYNC_SCHEDULE_TMO"
+msgstr "Pianifica sincronizzazione"
+
+msgid "IDS_EMAIL_BODY_TRASH"
+msgstr "Cestino"
+
+msgid "IDS_EMAIL_BODY_WITHOUT_ATTACHMENTS"
+msgstr "Senza allegati"
+
+msgid "IDS_EMAIL_BUTTON_GROUP"
+msgstr "Gruppo"
+
+msgid "IDS_EMAIL_HEADER_ADD_RULES"
+msgstr "Aggiungi regole"
+
+msgid "IDS_EMAIL_OPT_ATTACH_ITEMS"
+msgstr "Allega elementi"
+
+msgid "IDS_EMAIL_OPT_EXCHANGE"
+msgstr "Exchange"
+
+msgid "IDS_EMAIL_OPT_FILE"
+msgstr "File"
+
+msgid "IDS_EMAIL_OPT_NAMECARD"
+msgstr "Biglietto da visita"
+
+msgid "IDS_EMAIL_OPT_OPEN_URL"
+msgstr "Apri URL"
+
+msgid "IDS_EMAIL_OPT_SENDER"
+msgstr "Mittente"
+
+msgid "IDS_EMAIL_OPT_SEND_EMAIL"
+msgstr "Invia e-mail"
+
+msgid "IDS_EMAIL_OPT_UPDATE_EXISTING"
+msgstr "Aggiorna esistente"
+
+msgid "IDS_EMAIL_POP_ADD_ACCOUNTS"
+msgstr "Aggiungi account"
+
+msgid "IDS_EMAIL_POP_DOWNLOADING_ATTACHMENT_ING"
+msgstr "Download allegato..."
+
+msgid "IDS_EMAIL_POP_INVALID_EMAIL_ADDRESS"
+msgstr "Indirizzo e-mail non valido"
+
+msgid "IDS_EMAIL_POP_LOADING_CONTENTS_ING"
+msgstr "Caricamento contenuti..."
+
+msgid "IDS_EMAIL_POP_MAXIMUM_NUMBER_OF_ATTACHMENTS_REACHED"
+msgstr "Raggiunto numero massimo di allegati"
+
+msgid "IDS_EMAIL_POP_MOVE_TO_SPAMBOX_Q"
+msgstr "Spostare in Casella spam?"
+
+msgid "IDS_EMAIL_POP_NO_RECIPIENTS_ADDED_ENTER_RECIPIENTS"
+msgstr "Nessun destinatario aggiunto. Immettere i destinatari"
+
+msgid "IDS_EMAIL_POP_PLEASE_FILL_ALL_THE_MANDATORY_FIELDS"
+msgstr "Compilare tutti i campi obbligatori"
+
+msgid "IDS_EMAIL_POP_SAVE_IN_DRAFTS_Q"
+msgstr "Salvare in Bozze?"
+
+msgid "IDS_EMAIL_POP_THERE_IS_NO_ACCOUNT_CREATE_A_NEW_ACCOUNT_FIRST"
+msgstr "Nessun account esistente. Creare prima un nuovo account"
+
+msgid "IDS_EMAIL_POP_TOO_MANY_RECIPIENTS"
+msgstr "Troppi destinatari"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_DOWNLOAD"
+msgstr "Impossibile eseguire download"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_ENTER_TEXT"
+msgstr "Impossibile immettere testo"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_LAUNCH_APPLICATION"
+msgstr "Impossibile avviare applicazione"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_OPEN_ATTACHMENT"
+msgstr "Impossibile aprire allegato"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_SAVE_ATTACHMENT"
+msgstr "Impossibile salvare allegato"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_SAVE_IN_DRAFTS"
+msgstr "Impossibile salvare in Bozze"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_SEND_EMAIL"
+msgstr "Impossibile inviare e-mail"
+
+msgid "IDS_EMAIL_POP_UNSUPPORTED_FILE_TYPE"
+msgstr "Tipo file non supportato"
+
+msgid "IDS_EMAIL_POP_VALIDATING_ACCOUNT_ING"
+msgstr "Convalida account..."
+
+msgid "IDS_EMAIL_SK_RESEND"
+msgstr "Invia di nuovo"
+
+msgid "IDS_EMAIL_BODY_ACCEPT_ALL_SSL_CERTIFICATES"
+msgstr "Accetta tutti i certificati SSL"
+
+msgid "IDS_EMAIL_SK3_ACCOUNT_LIST"
+msgstr "Elenco account"
+
+msgid "IDS_EMAIL_BODY_USER_ID"
+msgstr "ID utente"
+
+msgid "IDS_EMAIL_POP_ACCOUNT_ALREADY_REGISTERED"
+msgstr "Account già registrato"
+
+msgid "IDS_EMAIL_HEADER_ATTACH_FILE"
+msgstr "Allega file"
+
+msgid "IDS_EMAIL_BODY_EXCHANGE_SYNC_SETTINGS_MSG"
+msgstr "Attivando questa applicazione, l'utente accetta che parte dei dati del dispositivo (identificatore univoco del dispositivo e nome del modello) siano memorizzati, elaborati e utilizzati da Samsung allo scopo di segnalare l'attivazione dell'applicazione ai concessori della licenza del software stesso. I dati in possesso di Samsung saranno trattati in modo strettamente conforme all'informativa sulla privacy di Samsung disponibile sul sito Web www.samsung.com. Continuare?"
+
+msgid "IDS_EMAIL_BODY_FORWARD_WITH_FILES"
+msgstr "Inoltra con allegati"
+
+msgid "IDS_EMAIL_BODY_REPLY_WITH_BODY"
+msgstr "Rispondi con msg. origin."
+
+msgid "IDS_EMAIL_BODY_NO_SUBJECT"
+msgstr "Nessun oggetto"
+
+msgid "IDS_EMAIL_BODY_FROM"
+msgstr "Da"
+
+msgid "IDS_EMAIL_BODY_NO_ADDRESS"
+msgstr "Nessun indirizzo"
+
+msgid "IDS_EMAIL_OPT_RECORD_SOUND"
+msgstr "Registra suono"
+
+msgid "IDS_EMAIL_OPT_RECORD_VIDEO"
+msgstr "Registra video"
+
+msgid "IDS_EMAIL_OPT_INSERT_IMAGE"
+msgstr "Inserisci immagine"
+
+msgid "IDS_EMAIL_OPT_ADD_TO_CALENDAR"
+msgstr "Aggiungi in Agenda"
+
+msgid "IDS_EMAIL_OPT_CHANGE_EMAIL_ADDRESS_ABB"
+msgstr "Cambia indirizzo e-mail"
+
+msgid "IDS_EMAIL_OPT_CLIPBOARD"
+msgstr "Appunti"
+
+msgid "IDS_EMAIL_OPT_MARKED_AS_UNREAD"
+msgstr "Contrassegnato come non letto"
+
+msgid "IDS_EMAIL_OPT_VIEW_CONTACT_DETAILS"
+msgstr "Visualizza dettagli contatto"
+
+msgid "IDS_EMAIL_POP_SAVED_IN_DRAFTS"
+msgstr "Salvato in Bozze"
+
+msgid "IDS_EMAIL_POP_NETWORK_BUSY"
+msgstr "Rete occupata"
+
+msgid "IDS_EMAIL_POP_LOGIN_ALLOWED_ONLY_EVERY_PD_MINUTES"
+msgstr "Accesso consentito solo ogni %d minuti"
+
+msgid "IDS_EMAIL_POP_HOST_NOT_FOUND"
+msgstr "Host non trovato"
+
+msgid "IDS_EMAIL_POP_HOST_NOT_REACHABLE"
+msgstr "Host non raggiungibile"
+
+msgid "IDS_EMAIL_POP_NO_SERVICE"
+msgstr "Nessun servizio"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_FORWARD_DRM_CONTENTS"
+msgstr "Impossibile inoltrare contenuti DRM"
+
+msgid "IDS_EMAIL_POP_BLOCKED"
+msgstr "Bloccato"
+
+msgid "IDS_EMAIL_POP_1_EMAIL_SELECTED"
+msgstr "1 e-mail selezionata"
+
+msgid "IDS_EMAIL_POP_PD_EMAILS_SELECTED"
+msgstr "%d email selezionate"
+
+msgid "IDS_EMAIL_POP_1_RECIPIENT_SELECTED"
+msgstr "1 destinatario selezionato"
+
+msgid "IDS_EMAIL_POP_PD_RECIPIENTS_SELECTED"
+msgstr "%d destinatari selezionati"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_ADD_ACCOUNT"
+msgstr "Impossibile aggiungere account"
+
+msgid "IDS_EMAIL_SK3_MOVE_HERE"
+msgstr "Sposta qui"
+
diff --git a/po/ja_JP.po b/po/ja_JP.po
new file mode 100755
index 0000000..866281f
--- /dev/null
+++ b/po/ja_JP.po
@@ -0,0 +1,465 @@
+msgid "IDS_EMAIL_POP_NO_EMAIL_ADDRESS"
+msgstr "Eメール​アドレス​ãŒâ€‹ã‚ã‚Šã¾ã›ã‚“"
+
+msgid "IDS_EMAIL_BODY_COMPLETE"
+msgstr "完了"
+
+msgid "IDS_EMAIL_BODY_ACCEPTED_C_PS"
+msgstr "ã“ã®äºˆå®šã¯å—ç†ã•ã‚Œã¾ã—ãŸï¼š %s"
+
+msgid "IDS_EMAIL_BODY_DECLINED_C_PS"
+msgstr "ã“ã®äºˆå®šã¯æ‹’å¦ã•ã‚Œã¾ã—ãŸï¼š %s"
+
+msgid "IDS_EMAIL_BODY_DOWNLOAD_FULL_MESSAGE"
+msgstr "メッセージ​全体​を​ダウンロード"
+
+msgid "IDS_EMAIL_BODY_GENERAL_SETTINGS"
+msgstr "基本設定"
+
+msgid "IDS_EMAIL_BODY_TENTATIVE_C_PS"
+msgstr "ä»®ã®äºˆå®šï¼š%s"
+
+msgid "IDS_EMAIL_BODY_WHEN_C_PS"
+msgstr "予定日時: %s"
+
+msgid "IDS_EMAIL_BODY_WHERE_C_PS"
+msgstr "予定場所: %s"
+
+msgid "IDS_EMAIL_BUTTON_DECLINE_ABB"
+msgstr "æ‹’å¦"
+
+msgid "IDS_EMAIL_BODY_NO_CONTENTS"
+msgstr "コンテンツãŒã‚ã‚Šã¾ã›ã‚“。"
+
+msgid "IDS_EMAIL_BODY_ORIGINAL_MESSAGE"
+msgstr "å…ƒã®ãƒ¡ãƒ¼ãƒ«"
+
+msgid "IDS_EMAIL_HEADER_ACCOUNT_SETTINGS"
+msgstr "アカウント設定"
+
+msgid "IDS_EMAIL_OPT_BLOCK"
+msgstr "ブロック"
+
+msgid "IDS_EMAIL_OPT_MARK_AS_READ"
+msgstr "既読ã«å¤‰æ›´"
+
+msgid "IDS_EMAIL_OPT_MARK_AS_UNREAD"
+msgstr "未読ã«å¤‰æ›´"
+
+msgid "IDS_EMAIL_OPT_OTHERS"
+msgstr "ãã®ä»–"
+
+msgid "IDS_EMAIL_OPT_UNREAD"
+msgstr "未読"
+
+msgid "IDS_EMAIL_SK_COMPOSE"
+msgstr "作æˆ"
+
+msgid "IDS_EMAIL_HEADER_DOWNLOAD_FAILED"
+msgstr "ダウンロードã«å¤±æ•—ã—ã¾ã—ãŸã€‚"
+
+msgid "IDS_EMAIL_OPT_ADD_TO_CONTACT"
+msgstr "電話帳ã«è¿½åŠ "
+
+msgid "IDS_EMAIL_OPT_VOICE_CALL"
+msgstr "音声通話"
+
+msgid "IDS_EMAIL_BODY_ACCOUNT_NAME"
+msgstr "アカウントå"
+
+msgid "IDS_EMAIL_BODY_ATTACHMENTS"
+msgstr "ファイル添付"
+
+msgid "IDS_EMAIL_BODY_FROM_C"
+msgstr "発信元:"
+
+msgid "IDS_EMAIL_BODY_IMAP4_SERVER"
+msgstr "IMAP4​サーãƒãƒ¼"
+
+msgid "IDS_EMAIL_BODY_INCLUDES"
+msgstr "部分一致"
+
+msgid "IDS_EMAIL_BODY_INCOMING_PORT"
+msgstr "å—信​ãƒãƒ¼ãƒˆ"
+
+msgid "IDS_EMAIL_BODY_INCOMING_SERVER"
+msgstr "å—信サーãƒãƒ¼"
+
+msgid "IDS_EMAIL_BODY_IN_PD_MINUTES"
+msgstr "%d​分​後"
+
+msgid "IDS_EMAIL_BODY_KEEP_IN_SERVER"
+msgstr "サーãƒãƒ¼ã«â€‹ä¿å­˜â€‹"
+
+msgid "IDS_EMAIL_BODY_NO_TEXT"
+msgstr "テキスト​ãŒâ€‹ã‚ã‚Šã¾ã›ã‚“"
+
+msgid "IDS_EMAIL_BODY_OUTGOING_PORT"
+msgstr "外部​ãƒãƒ¼ãƒˆ"
+
+msgid "IDS_EMAIL_BODY_OUTGOING_SERVER"
+msgstr "é€ä¿¡ã‚µãƒ¼ãƒãƒ¼"
+
+msgid "IDS_EMAIL_BODY_PD_EMAILS"
+msgstr "Eメール%d件"
+
+msgid "IDS_EMAIL_BODY_POP3_SERVER"
+msgstr "POP3サーãƒãƒ¼"
+
+msgid "IDS_EMAIL_BODY_RECENT"
+msgstr "最近"
+
+msgid "IDS_EMAIL_BODY_RETRIEVING_OPTIONS"
+msgstr "オプション​ã®â€‹å–å¾—"
+
+msgid "IDS_EMAIL_BODY_RE_C"
+msgstr "RE:"
+
+msgid "IDS_EMAIL_BODY_SENT_C"
+msgstr "é€ä¿¡æ¸ˆã¿ï¼š"
+
+msgid "IDS_EMAIL_BODY_SENT_FROM_SAMSUNG_MOBILE"
+msgstr "Samsung Mobileã‹ã‚‰é€ä¿¡ã—ã¾ã—ãŸ"
+
+msgid "IDS_EMAIL_BODY_USER_PASSWORD"
+msgstr "ユーザ​ーパスワード"
+
+msgid "IDS_EMAIL_HEADER_EDIT_RULES"
+msgstr "ルール​を​編集"
+
+msgid "IDS_EMAIL_HEADER_EMAIL_SETTINGS"
+msgstr "Eメール​設定"
+
+msgid "IDS_EMAIL_HEADER_MAILBOXES"
+msgstr "メールボックス"
+
+msgid "IDS_EMAIL_POP_ALERT"
+msgstr "通知"
+
+msgid "IDS_EMAIL_POP_FILE_ALREADY_EXISTS"
+msgstr "ファイルãŒâ€‹æ—¢ã«â€‹å­˜åœ¨ã—ã¾ã™ã€‚"
+
+msgid "IDS_EMAIL_POP_NO_SENDER"
+msgstr "é€ä¿¡è€…​ãŒâ€‹æœªå…¥åŠ›â€‹ã§ã™"
+
+msgid "IDS_EMAIL_POP_SUCCEEDED"
+msgstr "æˆåŠŸã—ã¾ã—ãŸ"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_ATTACH_MAXIMUM_NUMBER_OF_FILES_IS_PD"
+msgstr "添付​ã§ãã¾ã›ã‚“。​最大件数​ã¯â€‹%d​件ã§ã™"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_ATTACH_MAXIMUM_SIZE_OF_FILES_IS_PD_KB"
+msgstr "添付​ã§ãã¾ã›ã‚“。​ファイルã®æœ€å¤§â€‹ã‚µã‚¤ã‚ºâ€‹ã¯â€‹%dKB​ã§ã™"
+
+msgid "IDS_EMAIL_POP_VALIDATION_FAILED"
+msgstr "èªè¨¼â€‹ã«â€‹å¤±æ•—​ã—ã¾ã—ãŸ"
+
+msgid "IDS_EMAIL_SK_REPLY_ALL"
+msgstr "全員ã«è¿”ä¿¡"
+
+msgid "IDS_EMAIL_BODY_1_ITEM"
+msgstr "1 ​件​ã®â€‹ã‚¢ã‚¤ãƒ†ãƒ "
+
+msgid "IDS_EMAIL_BODY_ADD_MY_NAMECARD"
+msgstr "ãƒãƒ¼ãƒ ã‚«ãƒ¼ãƒ‰â€‹â€‹è¿½åŠ â€‹"
+
+msgid "IDS_EMAIL_BODY_ADD_SIGNATURE"
+msgstr "ç½²åを追加"
+
+msgid "IDS_EMAIL_BODY_ALL_EMAILS"
+msgstr "å…¨ã¦ã®Eメール"
+
+msgid "IDS_EMAIL_BODY_ALWAYS_BCC_MYSELF"
+msgstr "å¿…ãšè‡ªåˆ†ã«Bccã‚’é€ä¿¡"
+
+msgid "IDS_EMAIL_BODY_BCC"
+msgstr "Bcc"
+
+msgid "IDS_EMAIL_BODY_BLOCK_EMAILS"
+msgstr "Eメール​を​ブロック​"
+
+msgid "IDS_EMAIL_BODY_BODY"
+msgstr "本文"
+
+msgid "IDS_EMAIL_BODY_CC"
+msgstr "Cc"
+
+msgid "IDS_EMAIL_BODY_CC_BCC"
+msgstr "Cc/Bcc"
+
+msgid "IDS_EMAIL_BODY_CHECK_INTERVAL"
+msgstr "ãƒã‚§ãƒƒã‚¯â€‹é–“éš”"
+
+msgid "IDS_EMAIL_BODY_DEFAULT_ACCOUNT"
+msgstr "メインアカウント"
+
+msgid "IDS_EMAIL_BODY_DRAFTS"
+msgstr "下書ã"
+
+msgid "IDS_EMAIL_BODY_EMAIL_ACCOUNTS"
+msgstr "Eメール​アカウント"
+
+msgid "IDS_EMAIL_BODY_END_TIME"
+msgstr "終了時刻"
+
+msgid "IDS_EMAIL_BODY_ENTIRE_EMAIL"
+msgstr "Eメール全体"
+
+msgid "IDS_EMAIL_BODY_EXACTLY_THE_SAME_AS"
+msgstr "完全一致"
+
+msgid "IDS_EMAIL_BODY_EXAMPLE"
+msgstr "サンプル"
+
+msgid "IDS_EMAIL_BODY_FROM_M_SENDER"
+msgstr "発信元:"
+
+msgid "IDS_EMAIL_BODY_INBOX"
+msgstr "å—信トレイ"
+
+msgid "IDS_EMAIL_BODY_INCLUDE"
+msgstr "内容"
+
+msgid "IDS_EMAIL_BODY_MATCH_CRITERIA"
+msgstr "振り分ã‘ルール"
+
+msgid "IDS_EMAIL_BODY_NOT_USED"
+msgstr "利用​ä¸å¯"
+
+msgid "IDS_EMAIL_BODY_NO_ACCOUNTS"
+msgstr "アカウント​ãŒâ€‹ã‚ã‚Šã¾ã›ã‚“。"
+
+msgid "IDS_EMAIL_BODY_PD_DAYS"
+msgstr "%dæ—¥"
+
+msgid "IDS_EMAIL_BODY_PD_ITEMS"
+msgstr "%d​アイテム"
+
+msgid "IDS_EMAIL_BODY_PRIORITY"
+msgstr "優先度"
+
+msgid "IDS_EMAIL_BODY_RECEIVING_OPTIONS"
+msgstr "å—信​オプション"
+
+msgid "IDS_EMAIL_BODY_SECURE_CONNECTION"
+msgstr "セキュア​コãƒã‚¯ã‚·ãƒ§ãƒ³"
+
+msgid "IDS_EMAIL_BODY_SENDING_OPTIONS"
+msgstr "é€ä¿¡ã‚ªãƒ—ション"
+
+msgid "IDS_EMAIL_BODY_SENTBOX"
+msgstr "é€ä¿¡æ¸ˆãƒˆãƒ¬ã‚¤"
+
+msgid "IDS_EMAIL_BODY_SERVER_URL"
+msgstr "サーãƒãƒ¼URL"
+
+msgid "IDS_EMAIL_BODY_SIGNATURE"
+msgstr "ç½²å"
+
+msgid "IDS_EMAIL_BODY_SPAMBOX"
+msgstr "スパムボックス"
+
+msgid "IDS_EMAIL_BODY_START_TIME"
+msgstr "開始時刻"
+
+msgid "IDS_EMAIL_BODY_SYNC_SCHEDULE_TMO"
+msgstr "予定をåŒæœŸ"
+
+msgid "IDS_EMAIL_BODY_TRASH"
+msgstr "削除"
+
+msgid "IDS_EMAIL_BODY_WITHOUT_ATTACHMENTS"
+msgstr "添付​ãªã—"
+
+msgid "IDS_EMAIL_BUTTON_GROUP"
+msgstr "グループ"
+
+msgid "IDS_EMAIL_HEADER_ADD_RULES"
+msgstr "ルール​を​追加"
+
+msgid "IDS_EMAIL_OPT_ATTACH_ITEMS"
+msgstr "添付​"
+
+msgid "IDS_EMAIL_OPT_EXCHANGE"
+msgstr "交æ›"
+
+msgid "IDS_EMAIL_OPT_FILE"
+msgstr "ファイル"
+
+msgid "IDS_EMAIL_OPT_NAMECARD"
+msgstr "連絡先"
+
+msgid "IDS_EMAIL_OPT_OPEN_URL"
+msgstr "URLã‚’é–‹ã"
+
+msgid "IDS_EMAIL_OPT_SENDER"
+msgstr "é€ä¿¡è€…"
+
+msgid "IDS_EMAIL_OPT_SEND_EMAIL"
+msgstr "Eメールé€ä¿¡"
+
+msgid "IDS_EMAIL_OPT_UPDATE_EXISTING"
+msgstr "既存連絡先ã®æ›´æ–°"
+
+msgid "IDS_EMAIL_POP_ADD_ACCOUNTS"
+msgstr "アカウント​を​追加​ã—ã¾ã™"
+
+msgid "IDS_EMAIL_POP_DOWNLOADING_ATTACHMENT_ING"
+msgstr "添付​ファイルを​ダウンロード中..."
+
+msgid "IDS_EMAIL_POP_INVALID_EMAIL_ADDRESS"
+msgstr "EメールアドレスãŒæ­£ã—ãã‚ã‚Šã¾ã›ã‚“。"
+
+msgid "IDS_EMAIL_POP_LOADING_CONTENTS_ING"
+msgstr "コンテンツ​ã®â€‹èª­ã¿è¾¼ã¿â€‹ä¸­â€‹..."
+
+msgid "IDS_EMAIL_POP_MAXIMUM_NUMBER_OF_ATTACHMENTS_REACHED"
+msgstr "最大​添付数​ã«â€‹ãªã‚Šã¾ã—ãŸ"
+
+msgid "IDS_EMAIL_POP_MOVE_TO_SPAMBOX_Q"
+msgstr "Spambox​ã«â€‹ç§»å‹•â€‹ã—ã¾ã™ã‹ï¼Ÿ"
+
+msgid "IDS_EMAIL_POP_NO_RECIPIENTS_ADDED_ENTER_RECIPIENTS"
+msgstr "宛先ã¯è¿½åŠ ã•ã‚Œã¾ã›ã‚“ã§ã—ãŸã€‚宛先を入力ã—ã¦ãã ã•ã„。"
+
+msgid "IDS_EMAIL_POP_PLEASE_FILL_ALL_THE_MANDATORY_FIELDS"
+msgstr "必須​事項​を​全ã¦â€‹è¨˜å…¥â€‹ã—ã¦â€‹ãã ã•ã„"
+
+msgid "IDS_EMAIL_POP_SAVE_IN_DRAFTS_Q"
+msgstr "下書ãã«ä¿å­˜ã—ã¾ã™ã‹ï¼Ÿ"
+
+msgid "IDS_EMAIL_POP_THERE_IS_NO_ACCOUNT_CREATE_A_NEW_ACCOUNT_FIRST"
+msgstr "アカウント​ãŒâ€‹ã‚ã‚Šã¾ã›ã‚“。ã¯ã˜ã‚​ã«â€‹ã‚¢ã‚«ã‚¦ãƒ³ãƒˆâ€‹ã‚’​作æˆâ€‹ã—ã¦â€‹ãã ã•ã„"
+
+msgid "IDS_EMAIL_POP_TOO_MANY_RECIPIENTS"
+msgstr "宛先ãŒå¤šã™ãŽã¾ã™"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_DOWNLOAD"
+msgstr "ダウンロード​ã§ã​ã¾ã›ã‚“"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_ENTER_TEXT"
+msgstr "テキスト​を​入力​ã§ã​ã¾ã›ã‚“"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_LAUNCH_APPLICATION"
+msgstr "アプリケーションを​起動​ã§ãã¾ã›ã‚“"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_OPEN_ATTACHMENT"
+msgstr "添付​を​開ã‘​ã¾ã›ã‚“"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_SAVE_ATTACHMENT"
+msgstr "添付​書類を​ä¿å­˜ã§ãã¾ã›ã‚“"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_SAVE_IN_DRAFTS"
+msgstr "下書ã​ã«â€‹ä¿å­˜â€‹ã§ãã¾ã›ã‚“"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_SEND_EMAIL"
+msgstr "Eメール​を​é€ä¿¡â€‹ã§ãã¾ã›ã‚“"
+
+msgid "IDS_EMAIL_POP_UNSUPPORTED_FILE_TYPE"
+msgstr "未対応ã®ãƒ•ã‚¡ã‚¤ãƒ«ã§ã™"
+
+msgid "IDS_EMAIL_POP_VALIDATING_ACCOUNT_ING"
+msgstr "アカウント​ã®â€‹èªè¨¼ä¸­..."
+
+msgid "IDS_EMAIL_SK_RESEND"
+msgstr "å†é€ä¿¡"
+
+msgid "IDS_EMAIL_BODY_ACCEPT_ALL_SSL_CERTIFICATES"
+msgstr "å…¨ã¦ã®SSL証明書をå—ã‘入れる"
+
+msgid "IDS_EMAIL_SK3_ACCOUNT_LIST"
+msgstr "アカウント​リスト"
+
+msgid "IDS_EMAIL_BODY_USER_ID"
+msgstr "ユーザー​ID"
+
+msgid "IDS_EMAIL_POP_ACCOUNT_ALREADY_REGISTERED"
+msgstr "アカウント​ã¯â€‹æ—¢ã«â€‹ç™»éŒ²â€‹ã•ã‚Œã¦ã„ã¾ã™"
+
+msgid "IDS_EMAIL_HEADER_ATTACH_FILE"
+msgstr "ファイル​を​添付"
+
+msgid "IDS_EMAIL_BODY_EXCHANGE_SYNC_SETTINGS_MSG"
+msgstr "ã“ã®â€‹ã‚¢ãƒ—リ​を​起動​ã™ã‚‹â€‹ã¨ã€â€‹Samsung​ãŒâ€‹ã‚¢ãƒ—リ​ソフト​ã®â€‹ä½¿ç”¨è¨±è«¾è€…​ã«â€‹ã‚¢ãƒ—リ​ã®â€‹èµ·å‹•â€‹ã‚’​通知​ã™ã‚‹â€‹ãŸã‚ã«â€‹æœ¬ä½“​ã®â€‹ãƒ‡ãƒ¼ã‚¿â€‹ï¼ˆç«¯æœ«å›ºæœ‰ID​ã¨â€‹ãƒ¢ãƒ‡ãƒ«å)​を​ä¿ç®¡ã€â€‹å‡¦ç†ã€â€‹ãŠã‚ˆã³â€‹ä½¿ç”¨â€‹ã™ã‚‹â€‹ã“ã¨ã‚’​承èªâ€‹ã—ãŸâ€‹ã“ã¨ã«â€‹ãªã‚Šã¾ã™ã€‚​ã“ã®â€‹ãƒ‡ãƒ¼ã‚¿â€‹ã¯ã€â€‹www.samsung.com​ã§â€‹è¨˜è¼‰â€‹ã•ã‚Œã¦â€‹ã„る​Samsung​ã®â€‹ãƒ—ライãƒã‚·ãƒ¼â€‹ãƒãƒªã‚·ãƒ¼â€‹ã«â€‹ã‚ˆã£ã¦â€‹å®ˆã‚‰ã‚Œã¦â€‹ã„ã¾ã™ã€‚​続行​ã—ã¾ã™ã‹ï¼Ÿ"
+
+msgid "IDS_EMAIL_BODY_FORWARD_WITH_FILES"
+msgstr "添付ファイル付ãã§è»¢é€"
+
+msgid "IDS_EMAIL_BODY_REPLY_WITH_BODY"
+msgstr "引用返信"
+
+msgid "IDS_EMAIL_BODY_NO_SUBJECT"
+msgstr "件åãªã—"
+
+msgid "IDS_EMAIL_BODY_FROM"
+msgstr "é€ä¿¡å…ƒ"
+
+msgid "IDS_EMAIL_BODY_NO_ADDRESS"
+msgstr "アドレスã¯ã‚ã‚Šã¾ã›ã‚“"
+
+msgid "IDS_EMAIL_OPT_RECORD_SOUND"
+msgstr "ボイスレコーダー起動"
+
+msgid "IDS_EMAIL_OPT_RECORD_VIDEO"
+msgstr "ビデオカメラ起動"
+
+msgid "IDS_EMAIL_OPT_INSERT_IMAGE"
+msgstr "ç”»åƒâ€‹ã‚’​挿入"
+
+msgid "IDS_EMAIL_OPT_ADD_TO_CALENDAR"
+msgstr "Add to Calendar"
+
+msgid "IDS_EMAIL_OPT_CHANGE_EMAIL_ADDRESS_ABB"
+msgstr "Eメールアドレス変更"
+
+msgid "IDS_EMAIL_OPT_CLIPBOARD"
+msgstr "クリップ​ボード"
+
+msgid "IDS_EMAIL_OPT_MARKED_AS_UNREAD"
+msgstr "未読​ã«â€‹ãƒžãƒ¼ã‚¯æ¸ˆã¿ã§ã™"
+
+msgid "IDS_EMAIL_OPT_VIEW_CONTACT_DETAILS"
+msgstr "電話帳​詳細​表示​"
+
+msgid "IDS_EMAIL_POP_SAVED_IN_DRAFTS"
+msgstr "下書ãã«ä¿å­˜"
+
+msgid "IDS_EMAIL_POP_NETWORK_BUSY"
+msgstr "ãƒãƒƒãƒˆãƒ¯ãƒ¼ã‚¯â€‹æ··é›‘中"
+
+msgid "IDS_EMAIL_POP_LOGIN_ALLOWED_ONLY_EVERY_PD_MINUTES"
+msgstr "Login allowed only every %d minutes"
+
+msgid "IDS_EMAIL_POP_HOST_NOT_FOUND"
+msgstr "ホスト​ãŒâ€‹è¦‹ã¤ã‹ã‚Šâ€‹ã¾ã›ã‚“"
+
+msgid "IDS_EMAIL_POP_HOST_NOT_REACHABLE"
+msgstr "ホスト​ã¯â€‹ã¾ã â€‹åˆ°ç€â€‹ã—ã¦â€‹ã„ã¾ã›ã‚“"
+
+msgid "IDS_EMAIL_POP_NO_SERVICE"
+msgstr "サービスãŒåˆ©ç”¨ã§ãã¾ã›ã‚“。"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_FORWARD_DRM_CONTENTS"
+msgstr "DRMコンテンツを転é€ã§ãã¾ã›ã‚“"
+
+msgid "IDS_EMAIL_POP_BLOCKED"
+msgstr "ブロック"
+
+msgid "IDS_EMAIL_POP_1_EMAIL_SELECTED"
+msgstr "Eメール​を​1件​é¸æŠžâ€‹ã—ã¾ã—ãŸ"
+
+msgid "IDS_EMAIL_POP_PD_EMAILS_SELECTED"
+msgstr "%d件​ã®â€‹Eメール​を​é¸æŠžâ€‹ã—ã¾ã—ãŸ"
+
+msgid "IDS_EMAIL_POP_1_RECIPIENT_SELECTED"
+msgstr "1å—信者を​é¸æŠžâ€‹ã—ã¾ã—ãŸ"
+
+msgid "IDS_EMAIL_POP_PD_RECIPIENTS_SELECTED"
+msgstr "%dã®â€‹å—信者を​é¸æŠžã—ã¾ã—ãŸ"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_ADD_ACCOUNT"
+msgstr "Unable to add account"
+
+msgid "IDS_EMAIL_SK3_MOVE_HERE"
+msgstr "ã“ã“ã«â€‹ç§»å‹•"
+
diff --git a/po/ko_KR.po b/po/ko_KR.po
new file mode 100755
index 0000000..db9066a
--- /dev/null
+++ b/po/ko_KR.po
@@ -0,0 +1,465 @@
+msgid "IDS_EMAIL_POP_NO_EMAIL_ADDRESS"
+msgstr "ì´ë©”ì¼ ì£¼ì†Œê°€ 없습니다"
+
+msgid "IDS_EMAIL_BODY_COMPLETE"
+msgstr "완료"
+
+msgid "IDS_EMAIL_BODY_ACCEPTED_C_PS"
+msgstr "수ë½: %s"
+
+msgid "IDS_EMAIL_BODY_DECLINED_C_PS"
+msgstr "ê±°ì ˆ: %s"
+
+msgid "IDS_EMAIL_BODY_DOWNLOAD_FULL_MESSAGE"
+msgstr "전체 메시지 다운로드"
+
+msgid "IDS_EMAIL_BODY_GENERAL_SETTINGS"
+msgstr "ì¼ë°˜ 설정"
+
+msgid "IDS_EMAIL_BODY_TENTATIVE_C_PS"
+msgstr "임시: %s"
+
+msgid "IDS_EMAIL_BODY_WHEN_C_PS"
+msgstr "언제: %s"
+
+msgid "IDS_EMAIL_BODY_WHERE_C_PS"
+msgstr "위치: %s"
+
+msgid "IDS_EMAIL_BUTTON_DECLINE_ABB"
+msgstr "ê±°ì ˆ"
+
+msgid "IDS_EMAIL_BODY_NO_CONTENTS"
+msgstr "ë‚´ìš©ì´ ì—†ìŠµë‹ˆë‹¤"
+
+msgid "IDS_EMAIL_BODY_ORIGINAL_MESSAGE"
+msgstr "ì›ë³¸ 메시지"
+
+msgid "IDS_EMAIL_HEADER_ACCOUNT_SETTINGS"
+msgstr "계정 설정"
+
+msgid "IDS_EMAIL_OPT_BLOCK"
+msgstr "차단"
+
+msgid "IDS_EMAIL_OPT_MARK_AS_READ"
+msgstr "ì½ìŒìœ¼ë¡œ 표시"
+
+msgid "IDS_EMAIL_OPT_MARK_AS_UNREAD"
+msgstr "ì½ì§€ ì•ŠìŒìœ¼ë¡œ 표시"
+
+msgid "IDS_EMAIL_OPT_OTHERS"
+msgstr "기타"
+
+msgid "IDS_EMAIL_OPT_UNREAD"
+msgstr "ì½ì§€ ì•ŠìŒ"
+
+msgid "IDS_EMAIL_SK_COMPOSE"
+msgstr "작성"
+
+msgid "IDS_EMAIL_HEADER_DOWNLOAD_FAILED"
+msgstr "다운로드할 수 없습니다"
+
+msgid "IDS_EMAIL_OPT_ADD_TO_CONTACT"
+msgstr "ì—°ë½ì²˜ì— 추가"
+
+msgid "IDS_EMAIL_OPT_VOICE_CALL"
+msgstr "ìŒì„±í†µí™”"
+
+msgid "IDS_EMAIL_BODY_ACCOUNT_NAME"
+msgstr "계정 ì´ë¦„"
+
+msgid "IDS_EMAIL_BODY_ATTACHMENTS"
+msgstr "첨부파ì¼"
+
+msgid "IDS_EMAIL_BODY_FROM_C"
+msgstr "발신:"
+
+msgid "IDS_EMAIL_BODY_IMAP4_SERVER"
+msgstr "IMAP4 서버"
+
+msgid "IDS_EMAIL_BODY_INCLUDES"
+msgstr "ìž…ë ¥ 번호를 í¬í•¨"
+
+msgid "IDS_EMAIL_BODY_INCOMING_PORT"
+msgstr "수신 í¬íŠ¸"
+
+msgid "IDS_EMAIL_BODY_INCOMING_SERVER"
+msgstr "받는 ë©”ì¼ ì„œë²„"
+
+msgid "IDS_EMAIL_BODY_IN_PD_MINUTES"
+msgstr "%d분 후ì—"
+
+msgid "IDS_EMAIL_BODY_KEEP_IN_SERVER"
+msgstr "ì„œë²„ì— ì €ìž¥"
+
+msgid "IDS_EMAIL_BODY_NO_TEXT"
+msgstr "메시지 ë‚´ìš©ì´ ì—†ìŠµë‹ˆë‹¤"
+
+msgid "IDS_EMAIL_BODY_OUTGOING_PORT"
+msgstr "전송 í¬íŠ¸â€"
+
+msgid "IDS_EMAIL_BODY_OUTGOING_SERVER"
+msgstr "보내는 ë©”ì¼ ì„œë²„"
+
+msgid "IDS_EMAIL_BODY_PD_EMAILS"
+msgstr "ì´ë©”ì¼ %dê°œ"
+
+msgid "IDS_EMAIL_BODY_POP3_SERVER"
+msgstr "POP3 서버"
+
+msgid "IDS_EMAIL_BODY_RECENT"
+msgstr "최근 검색 결과"
+
+msgid "IDS_EMAIL_BODY_RETRIEVING_OPTIONS"
+msgstr "가져오기 옵션"
+
+msgid "IDS_EMAIL_BODY_RE_C"
+msgstr "회신:"
+
+msgid "IDS_EMAIL_BODY_SENT_C"
+msgstr "발신:"
+
+msgid "IDS_EMAIL_BODY_SENT_FROM_SAMSUNG_MOBILE"
+msgstr "삼성 모바ì¼ì—ì„œ 전송하였습니다"
+
+msgid "IDS_EMAIL_BODY_USER_PASSWORD"
+msgstr "ì‚¬ìš©ìž ë¹„ë°€ë²ˆí˜¸"
+
+msgid "IDS_EMAIL_HEADER_EDIT_RULES"
+msgstr "규칙 편집"
+
+msgid "IDS_EMAIL_HEADER_EMAIL_SETTINGS"
+msgstr "ì´ë©”ì¼ ì„¤ì •"
+
+msgid "IDS_EMAIL_HEADER_MAILBOXES"
+msgstr "ë©”ì¼í•¨"
+
+msgid "IDS_EMAIL_POP_ALERT"
+msgstr "알림"
+
+msgid "IDS_EMAIL_POP_FILE_ALREADY_EXISTS"
+msgstr "ê°™ì€ íŒŒì¼ì´ 있습니다"
+
+msgid "IDS_EMAIL_POP_NO_SENDER"
+msgstr "발신ì¸ì´ 없습니다"
+
+msgid "IDS_EMAIL_POP_SUCCEEDED"
+msgstr "성공하였습니다"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_ATTACH_MAXIMUM_NUMBER_OF_FILES_IS_PD"
+msgstr "첨부할 수 없습니다. 첨부할 수 있는 íŒŒì¼ ìˆ˜ëŠ” %d개입니다"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_ATTACH_MAXIMUM_SIZE_OF_FILES_IS_PD_KB"
+msgstr "첨부할 수 없습니다. 첨부할 수 있는 íŒŒì¼ í¬ê¸°ëŠ” %dKB까지 입니다"
+
+msgid "IDS_EMAIL_POP_VALIDATION_FAILED"
+msgstr "확ì¸í•  수 없습니다"
+
+msgid "IDS_EMAIL_SK_REPLY_ALL"
+msgstr "전체 회신"
+
+msgid "IDS_EMAIL_BODY_1_ITEM"
+msgstr "1개"
+
+msgid "IDS_EMAIL_BODY_ADD_MY_NAMECARD"
+msgstr "내 명함 추가"
+
+msgid "IDS_EMAIL_BODY_ADD_SIGNATURE"
+msgstr "서명 추가"
+
+msgid "IDS_EMAIL_BODY_ALL_EMAILS"
+msgstr "모든 ì´ë©”ì¼"
+
+msgid "IDS_EMAIL_BODY_ALWAYS_BCC_MYSELF"
+msgstr "í•­ìƒ ë‚˜ë¥¼ 숨ì€ì°¸ì¡°ì— í¬í•¨"
+
+msgid "IDS_EMAIL_BODY_BCC"
+msgstr "숨ì€ì°¸ì¡°"
+
+msgid "IDS_EMAIL_BODY_BLOCK_EMAILS"
+msgstr "ì´ë©”ì¼ ì°¨ë‹¨"
+
+msgid "IDS_EMAIL_BODY_BODY"
+msgstr "본문"
+
+msgid "IDS_EMAIL_BODY_CC"
+msgstr "참조"
+
+msgid "IDS_EMAIL_BODY_CC_BCC"
+msgstr "참조/숨ì€ì°¸ì¡°"
+
+msgid "IDS_EMAIL_BODY_CHECK_INTERVAL"
+msgstr "수신 í™•ì¸ ê°„ê²©"
+
+msgid "IDS_EMAIL_BODY_DEFAULT_ACCOUNT"
+msgstr "기본 계정"
+
+msgid "IDS_EMAIL_BODY_DRAFTS"
+msgstr "임시보관함"
+
+msgid "IDS_EMAIL_BODY_EMAIL_ACCOUNTS"
+msgstr "ì´ë©”ì¼ ê³„ì •"
+
+msgid "IDS_EMAIL_BODY_END_TIME"
+msgstr "종료 시간"
+
+msgid "IDS_EMAIL_BODY_ENTIRE_EMAIL"
+msgstr "ì „ì²´ ì´ë©”ì¼"
+
+msgid "IDS_EMAIL_BODY_EXACTLY_THE_SAME_AS"
+msgstr "ìž…ë ¥ ë‚´ìš©ê³¼ ì¼ì¹˜"
+
+msgid "IDS_EMAIL_BODY_EXAMPLE"
+msgstr "예시"
+
+msgid "IDS_EMAIL_BODY_FROM_M_SENDER"
+msgstr "발신:"
+
+msgid "IDS_EMAIL_BODY_INBOX"
+msgstr "수신함"
+
+msgid "IDS_EMAIL_BODY_INCLUDE"
+msgstr "í¬í•¨"
+
+msgid "IDS_EMAIL_BODY_MATCH_CRITERIA"
+msgstr "ì ìš© 기준"
+
+msgid "IDS_EMAIL_BODY_NOT_USED"
+msgstr "사용 안 함"
+
+msgid "IDS_EMAIL_BODY_NO_ACCOUNTS"
+msgstr "ì„¤ì •ëœ ê³„ì •ì´ ì—†ìŠµë‹ˆë‹¤"
+
+msgid "IDS_EMAIL_BODY_PD_DAYS"
+msgstr "%dì¼"
+
+msgid "IDS_EMAIL_BODY_PD_ITEMS"
+msgstr "%d개"
+
+msgid "IDS_EMAIL_BODY_PRIORITY"
+msgstr "중요ë„"
+
+msgid "IDS_EMAIL_BODY_RECEIVING_OPTIONS"
+msgstr "수신 옵션"
+
+msgid "IDS_EMAIL_BODY_SECURE_CONNECTION"
+msgstr "보안 연결"
+
+msgid "IDS_EMAIL_BODY_SENDING_OPTIONS"
+msgstr "전송 옵션"
+
+msgid "IDS_EMAIL_BODY_SENTBOX"
+msgstr "발신함"
+
+msgid "IDS_EMAIL_BODY_SERVER_URL"
+msgstr "서버 URL"
+
+msgid "IDS_EMAIL_BODY_SIGNATURE"
+msgstr "서명"
+
+msgid "IDS_EMAIL_BODY_SPAMBOX"
+msgstr "스팸메시지함"
+
+msgid "IDS_EMAIL_BODY_START_TIME"
+msgstr "시작 시간"
+
+msgid "IDS_EMAIL_BODY_SYNC_SCHEDULE_TMO"
+msgstr "ë™ê¸°í™” ì¼ì •"
+
+msgid "IDS_EMAIL_BODY_TRASH"
+msgstr "휴지통"
+
+msgid "IDS_EMAIL_BODY_WITHOUT_ATTACHMENTS"
+msgstr "ì²¨ë¶€íŒŒì¼ ì œì™¸"
+
+msgid "IDS_EMAIL_BUTTON_GROUP"
+msgstr "그룹"
+
+msgid "IDS_EMAIL_HEADER_ADD_RULES"
+msgstr "규칙 추가"
+
+msgid "IDS_EMAIL_OPT_ATTACH_ITEMS"
+msgstr "íŒŒì¼ ì²¨ë¶€"
+
+msgid "IDS_EMAIL_OPT_EXCHANGE"
+msgstr "Exchange"
+
+msgid "IDS_EMAIL_OPT_FILE"
+msgstr "파ì¼"
+
+msgid "IDS_EMAIL_OPT_NAMECARD"
+msgstr "명함"
+
+msgid "IDS_EMAIL_OPT_OPEN_URL"
+msgstr "URL ì—°ê²°"
+
+msgid "IDS_EMAIL_OPT_SENDER"
+msgstr "발신ì¸"
+
+msgid "IDS_EMAIL_OPT_SEND_EMAIL"
+msgstr "ì´ë©”ì¼ ë³´ë‚´ê¸°"
+
+msgid "IDS_EMAIL_OPT_UPDATE_EXISTING"
+msgstr "기존 ì—°ë½ì²˜ì— 추가"
+
+msgid "IDS_EMAIL_POP_ADD_ACCOUNTS"
+msgstr "계정 추가"
+
+msgid "IDS_EMAIL_POP_DOWNLOADING_ATTACHMENT_ING"
+msgstr "ì²¨ë¶€íŒŒì¼ ë‹¤ìš´ë¡œë“œ 중..."
+
+msgid "IDS_EMAIL_POP_INVALID_EMAIL_ADDRESS"
+msgstr "ì´ë©”ì¼ ì£¼ì†Œê°€ 바르지 않습니다"
+
+msgid "IDS_EMAIL_POP_LOADING_CONTENTS_ING"
+msgstr "컨í…츠 불러오는 중..."
+
+msgid "IDS_EMAIL_POP_MAXIMUM_NUMBER_OF_ATTACHMENTS_REACHED"
+msgstr "최대 ì²¨ë¶€íŒŒì¼ ìˆ˜ë¥¼ 초과하였습니다"
+
+msgid "IDS_EMAIL_POP_MOVE_TO_SPAMBOX_Q"
+msgstr "스팸메시지함으로 ì´ë™ì‹œí‚¬ê¹Œìš”?"
+
+msgid "IDS_EMAIL_POP_NO_RECIPIENTS_ADDED_ENTER_RECIPIENTS"
+msgstr "ì¶”ê°€ëœ ìˆ˜ì‹ ì¸ì´ 없습니다. 수신ì¸ì„ 입력하세요"
+
+msgid "IDS_EMAIL_POP_PLEASE_FILL_ALL_THE_MANDATORY_FIELDS"
+msgstr "필수 í•­ëª©ì„ ëª¨ë‘ ìž…ë ¥í•˜ì„¸ìš”"
+
+msgid "IDS_EMAIL_POP_SAVE_IN_DRAFTS_Q"
+msgstr "ìž„ì‹œë³´ê´€í•¨ì— ì €ìž¥í• ê¹Œìš”?"
+
+msgid "IDS_EMAIL_POP_THERE_IS_NO_ACCOUNT_CREATE_A_NEW_ACCOUNT_FIRST"
+msgstr "ì €ìž¥ëœ ê³„ì •ì´ ì—†ìŠµë‹ˆë‹¤. ê³„ì •ì„ ì¶”ê°€í•˜ì„¸ìš”"
+
+msgid "IDS_EMAIL_POP_TOO_MANY_RECIPIENTS"
+msgstr "수신ì¸ì´ 너무 많습니다"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_DOWNLOAD"
+msgstr "다운로드할 수 없습니다"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_ENTER_TEXT"
+msgstr "í…스트를 입력할 수 없습니다"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_LAUNCH_APPLICATION"
+msgstr "애플리케ì´ì…˜ì„ 실행할 수 없습니다"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_OPEN_ATTACHMENT"
+msgstr "첨부파ì¼ì„ ì—´ 수 없습니다"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_SAVE_ATTACHMENT"
+msgstr "첨부파ì¼ì„ 저장할 수 없습니다"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_SAVE_IN_DRAFTS"
+msgstr "ìž„ì‹œë³´ê´€í•¨ì— ì €ìž¥í•  수 없습니다"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_SEND_EMAIL"
+msgstr "ì´ë©”ì¼ì„ 전송할 수 없습니다"
+
+msgid "IDS_EMAIL_POP_UNSUPPORTED_FILE_TYPE"
+msgstr "지ì›ë˜ì§€ 않는 íŒŒì¼ í˜•ì‹ìž…니다"
+
+msgid "IDS_EMAIL_POP_VALIDATING_ACCOUNT_ING"
+msgstr "계정 í™•ì¸ ì¤‘..."
+
+msgid "IDS_EMAIL_SK_RESEND"
+msgstr "재전송"
+
+msgid "IDS_EMAIL_BODY_ACCEPT_ALL_SSL_CERTIFICATES"
+msgstr "모든 SSL ì¸ì¦ì„œì— ë™ì˜"
+
+msgid "IDS_EMAIL_SK3_ACCOUNT_LIST"
+msgstr "계정 목ë¡"
+
+msgid "IDS_EMAIL_BODY_USER_ID"
+msgstr "ì‚¬ìš©ìž ID"
+
+msgid "IDS_EMAIL_POP_ACCOUNT_ALREADY_REGISTERED"
+msgstr "ê³„ì •ì´ ì´ë¯¸ 등ë¡ë˜ì–´ 있습니다"
+
+msgid "IDS_EMAIL_HEADER_ATTACH_FILE"
+msgstr "íŒŒì¼ ì²¨ë¶€"
+
+msgid "IDS_EMAIL_BODY_EXCHANGE_SYNC_SETTINGS_MSG"
+msgstr "ì´ ì• í”Œë¦¬ì¼€ì´ì…˜ì„ 실행하면 ì†Œí”„íŠ¸ì›¨ì–´ì˜ ì €ìž‘ê¶Œìžì—게 애플리케ì´ì…˜ ì‹¤í–‰ì„ ë³´ê³ í•˜ê¸° 위하여 ì‚¼ì„±ì´ ë””ë°”ì´ìŠ¤ì˜ ì¼ë¶€ ì •ë³´(ë‹¨ë§ ê³ ìœ ë²ˆí˜¸ 구성 ë° ëª¨ë¸ëª…)를 저장, 가공, 사용하는 ê²ƒì— ë™ì˜í•œ 것으로 ì¸ì •ë©ë‹ˆë‹¤. ì´ëŸ¬í•œ 정보는 ì‚¼ì„±ì˜ ê°œì¸ì •ë³´ ë³´í˜¸ì •ì±…ì— ë”°ë¼ ì² ì €ížˆ 취급ë©ë‹ˆë‹¤. ê°œì¸ì •ë³´ ë³´í˜¸ì •ì±…ì€ www.samsung.comì—ì„œ 확ì¸í•  수 있습니다. 계ì†í• ê¹Œìš”?"
+
+msgid "IDS_EMAIL_BODY_FORWARD_WITH_FILES"
+msgstr "전달시 ì²¨ë¶€íŒŒì¼ í¬í•¨"
+
+msgid "IDS_EMAIL_BODY_REPLY_WITH_BODY"
+msgstr "본문 í¬í•¨í•˜ì—¬ 회신"
+
+msgid "IDS_EMAIL_BODY_NO_SUBJECT"
+msgstr "ì œëª©ì´ ì—†ìŠµë‹ˆë‹¤"
+
+msgid "IDS_EMAIL_BODY_FROM"
+msgstr "발신"
+
+msgid "IDS_EMAIL_BODY_NO_ADDRESS"
+msgstr "ì €ìž¥ëœ ì£¼ì†Œê°€ 없습니다"
+
+msgid "IDS_EMAIL_OPT_RECORD_SOUND"
+msgstr "ìŒì„±ë…¹ìŒ"
+
+msgid "IDS_EMAIL_OPT_RECORD_VIDEO"
+msgstr "ë™ì˜ìƒ ì´¬ì˜"
+
+msgid "IDS_EMAIL_OPT_INSERT_IMAGE"
+msgstr "ì´ë¯¸ì§€ 추가"
+
+msgid "IDS_EMAIL_OPT_ADD_TO_CALENDAR"
+msgstr "ì¼ì •ì— 추가"
+
+msgid "IDS_EMAIL_OPT_CHANGE_EMAIL_ADDRESS_ABB"
+msgstr "ì´ë©”ì¼ ì£¼ì†Œ 변경"
+
+msgid "IDS_EMAIL_OPT_CLIPBOARD"
+msgstr "í´ë¦½ë³´ë“œ"
+
+msgid "IDS_EMAIL_OPT_MARKED_AS_UNREAD"
+msgstr "ì½ì§€ ì•ŠìŒìœ¼ë¡œ 표시"
+
+msgid "IDS_EMAIL_OPT_VIEW_CONTACT_DETAILS"
+msgstr "ì—°ë½ì²˜ ìƒì„¸ë³´ê¸°"
+
+msgid "IDS_EMAIL_POP_SAVED_IN_DRAFTS"
+msgstr "ìž„ì‹œë³´ê´€í•¨ì— ì €ìž¥ë˜ì—ˆìŠµë‹ˆë‹¤"
+
+msgid "IDS_EMAIL_POP_NETWORK_BUSY"
+msgstr "ë„¤íŠ¸ì›Œí¬ ì—°ê²° ìƒíƒœê°€ ì›í™œí•˜ì§€ 않습니다"
+
+msgid "IDS_EMAIL_POP_LOGIN_ALLOWED_ONLY_EVERY_PD_MINUTES"
+msgstr "%d분마다 í•œ 번 로그ì¸í•  수 있습니다"
+
+msgid "IDS_EMAIL_POP_HOST_NOT_FOUND"
+msgstr "호스트를 ì°¾ì„ ìˆ˜ 없습니다"
+
+msgid "IDS_EMAIL_POP_HOST_NOT_REACHABLE"
+msgstr "호스트와 연결할 수 없습니다"
+
+msgid "IDS_EMAIL_POP_NO_SERVICE"
+msgstr "서비스 ì§€ì—­ì´ ì•„ë‹™ë‹ˆë‹¤"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_FORWARD_DRM_CONTENTS"
+msgstr "DRM 컨í…츠는 전송할 수 없습니다"
+
+msgid "IDS_EMAIL_POP_BLOCKED"
+msgstr "차단ë˜ì—ˆìŠµë‹ˆë‹¤"
+
+msgid "IDS_EMAIL_POP_1_EMAIL_SELECTED"
+msgstr "ì´ë©”ì¼ 1개가 ì„ íƒë˜ì—ˆìŠµë‹ˆë‹¤"
+
+msgid "IDS_EMAIL_POP_PD_EMAILS_SELECTED"
+msgstr "%d개가 ì„ íƒë˜ì—ˆìŠµë‹ˆë‹¤"
+
+msgid "IDS_EMAIL_POP_1_RECIPIENT_SELECTED"
+msgstr "수신ì¸ì´ í•œ 명 ì„ íƒë˜ì—ˆìŠµë‹ˆë‹¤"
+
+msgid "IDS_EMAIL_POP_PD_RECIPIENTS_SELECTED"
+msgstr "ìˆ˜ì‹ ì¸ %d명 ì„ íƒë˜ì—ˆìŠµë‹ˆë‹¤"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_ADD_ACCOUNT"
+msgstr "ê³„ì •ì„ ì¶”ê°€í•  수 없습니다"
+
+msgid "IDS_EMAIL_SK3_MOVE_HERE"
+msgstr "여기로 ì´ë™"
+
diff --git a/po/nl_NL.po b/po/nl_NL.po
new file mode 100755
index 0000000..c6172ff
--- /dev/null
+++ b/po/nl_NL.po
@@ -0,0 +1,465 @@
+msgid "IDS_EMAIL_POP_NO_EMAIL_ADDRESS"
+msgstr "Geen e-mailadres"
+
+msgid "IDS_EMAIL_BODY_COMPLETE"
+msgstr "Voltooid"
+
+msgid "IDS_EMAIL_BODY_ACCEPTED_C_PS"
+msgstr "Geaccepteerd: %s"
+
+msgid "IDS_EMAIL_BODY_DECLINED_C_PS"
+msgstr "Afgewezen: %s"
+
+msgid "IDS_EMAIL_BODY_DOWNLOAD_FULL_MESSAGE"
+msgstr "Volledig bericht downloaden"
+
+msgid "IDS_EMAIL_BODY_GENERAL_SETTINGS"
+msgstr "Algemene instellingen"
+
+msgid "IDS_EMAIL_BODY_TENTATIVE_C_PS"
+msgstr "Proef: %s"
+
+msgid "IDS_EMAIL_BODY_WHEN_C_PS"
+msgstr "Wanneer: %s"
+
+msgid "IDS_EMAIL_BODY_WHERE_C_PS"
+msgstr "Waar: %s"
+
+msgid "IDS_EMAIL_BUTTON_DECLINE_ABB"
+msgstr "Weigeren"
+
+msgid "IDS_EMAIL_BODY_NO_CONTENTS"
+msgstr "Geen inhoud"
+
+msgid "IDS_EMAIL_BODY_ORIGINAL_MESSAGE"
+msgstr "Oorspronkelijk bericht"
+
+msgid "IDS_EMAIL_HEADER_ACCOUNT_SETTINGS"
+msgstr "Accountinstellingen"
+
+msgid "IDS_EMAIL_OPT_BLOCK"
+msgstr "Blokkeren"
+
+msgid "IDS_EMAIL_OPT_MARK_AS_READ"
+msgstr "Markeren als gelezen"
+
+msgid "IDS_EMAIL_OPT_MARK_AS_UNREAD"
+msgstr "Markeren als Ongelezen"
+
+msgid "IDS_EMAIL_OPT_OTHERS"
+msgstr "Overige"
+
+msgid "IDS_EMAIL_OPT_UNREAD"
+msgstr "Ongelezen"
+
+msgid "IDS_EMAIL_SK_COMPOSE"
+msgstr "Opstellen"
+
+msgid "IDS_EMAIL_HEADER_DOWNLOAD_FAILED"
+msgstr "Downloaden mislukt"
+
+msgid "IDS_EMAIL_OPT_ADD_TO_CONTACT"
+msgstr "Toevoegen aan contactpersoon"
+
+msgid "IDS_EMAIL_OPT_VOICE_CALL"
+msgstr "Spraakoproep"
+
+msgid "IDS_EMAIL_BODY_ACCOUNT_NAME"
+msgstr "Accountnaam"
+
+msgid "IDS_EMAIL_BODY_ATTACHMENTS"
+msgstr "Bijlagen"
+
+msgid "IDS_EMAIL_BODY_FROM_C"
+msgstr "Van:"
+
+msgid "IDS_EMAIL_BODY_IMAP4_SERVER"
+msgstr "IMAP4-server"
+
+msgid "IDS_EMAIL_BODY_INCLUDES"
+msgstr "Inclusief"
+
+msgid "IDS_EMAIL_BODY_INCOMING_PORT"
+msgstr "Poort inkomende e-mail"
+
+msgid "IDS_EMAIL_BODY_INCOMING_SERVER"
+msgstr "Inkomende server"
+
+msgid "IDS_EMAIL_BODY_IN_PD_MINUTES"
+msgstr "In %d minuten"
+
+msgid "IDS_EMAIL_BODY_KEEP_IN_SERVER"
+msgstr "Op server bewaren"
+
+msgid "IDS_EMAIL_BODY_NO_TEXT"
+msgstr "Geen tekst"
+
+msgid "IDS_EMAIL_BODY_OUTGOING_PORT"
+msgstr "Poort uitgaande e-mail"
+
+msgid "IDS_EMAIL_BODY_OUTGOING_SERVER"
+msgstr "Uitgaande server"
+
+msgid "IDS_EMAIL_BODY_PD_EMAILS"
+msgstr "%d e-mails"
+
+msgid "IDS_EMAIL_BODY_POP3_SERVER"
+msgstr "POP3-server"
+
+msgid "IDS_EMAIL_BODY_RECENT"
+msgstr "Recent"
+
+msgid "IDS_EMAIL_BODY_RETRIEVING_OPTIONS"
+msgstr "Ophaalopties"
+
+msgid "IDS_EMAIL_BODY_RE_C"
+msgstr "Re:"
+
+msgid "IDS_EMAIL_BODY_SENT_C"
+msgstr "Verzonden:"
+
+msgid "IDS_EMAIL_BODY_SENT_FROM_SAMSUNG_MOBILE"
+msgstr "Verzonden vanaf Samsung Mobile"
+
+msgid "IDS_EMAIL_BODY_USER_PASSWORD"
+msgstr "Wachtwoord"
+
+msgid "IDS_EMAIL_HEADER_EDIT_RULES"
+msgstr "Regels bewerken"
+
+msgid "IDS_EMAIL_HEADER_EMAIL_SETTINGS"
+msgstr "E-mailinstellingen"
+
+msgid "IDS_EMAIL_HEADER_MAILBOXES"
+msgstr "Mailboxen"
+
+msgid "IDS_EMAIL_POP_ALERT"
+msgstr "Signaal"
+
+msgid "IDS_EMAIL_POP_FILE_ALREADY_EXISTS"
+msgstr "Bestand bestaat al"
+
+msgid "IDS_EMAIL_POP_NO_SENDER"
+msgstr "Geen afzender"
+
+msgid "IDS_EMAIL_POP_SUCCEEDED"
+msgstr "Gelukt"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_ATTACH_MAXIMUM_NUMBER_OF_FILES_IS_PD"
+msgstr "Kan niet toevoegen. Maximumaantal bestanden is %d"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_ATTACH_MAXIMUM_SIZE_OF_FILES_IS_PD_KB"
+msgstr "Kan niet toevoegen. Maximumgrootte van bestanden is %d KB"
+
+msgid "IDS_EMAIL_POP_VALIDATION_FAILED"
+msgstr "Validatie mislukt"
+
+msgid "IDS_EMAIL_SK_REPLY_ALL"
+msgstr "Allen beantw."
+
+msgid "IDS_EMAIL_BODY_1_ITEM"
+msgstr "1 item"
+
+msgid "IDS_EMAIL_BODY_ADD_MY_NAMECARD"
+msgstr "Mijn visitekaartje toevoegen"
+
+msgid "IDS_EMAIL_BODY_ADD_SIGNATURE"
+msgstr "Handtekening toevoegen"
+
+msgid "IDS_EMAIL_BODY_ALL_EMAILS"
+msgstr "Alle e-mailberichten"
+
+msgid "IDS_EMAIL_BODY_ALWAYS_BCC_MYSELF"
+msgstr "Altijd BCC aan mijzelf"
+
+msgid "IDS_EMAIL_BODY_BCC"
+msgstr "BCC"
+
+msgid "IDS_EMAIL_BODY_BLOCK_EMAILS"
+msgstr "E-mail blokkeren"
+
+msgid "IDS_EMAIL_BODY_BODY"
+msgstr "Hoofdtekst"
+
+msgid "IDS_EMAIL_BODY_CC"
+msgstr "CC"
+
+msgid "IDS_EMAIL_BODY_CC_BCC"
+msgstr "Cc/Bcc"
+
+msgid "IDS_EMAIL_BODY_CHECK_INTERVAL"
+msgstr "Controle-interval"
+
+msgid "IDS_EMAIL_BODY_DEFAULT_ACCOUNT"
+msgstr "Standaard account"
+
+msgid "IDS_EMAIL_BODY_DRAFTS"
+msgstr "Concepten"
+
+msgid "IDS_EMAIL_BODY_EMAIL_ACCOUNTS"
+msgstr "E-mailaccounts"
+
+msgid "IDS_EMAIL_BODY_END_TIME"
+msgstr "Eindtijd"
+
+msgid "IDS_EMAIL_BODY_ENTIRE_EMAIL"
+msgstr "Volledige e-mail"
+
+msgid "IDS_EMAIL_BODY_EXACTLY_THE_SAME_AS"
+msgstr "Precies gelijk aan"
+
+msgid "IDS_EMAIL_BODY_EXAMPLE"
+msgstr "Voorbeeld"
+
+msgid "IDS_EMAIL_BODY_FROM_M_SENDER"
+msgstr "Van:"
+
+msgid "IDS_EMAIL_BODY_INBOX"
+msgstr "Postvak IN"
+
+msgid "IDS_EMAIL_BODY_INCLUDE"
+msgstr "Invoegen"
+
+msgid "IDS_EMAIL_BODY_MATCH_CRITERIA"
+msgstr "Blokkeringscriteria"
+
+msgid "IDS_EMAIL_BODY_NOT_USED"
+msgstr "Niet gebruiken"
+
+msgid "IDS_EMAIL_BODY_NO_ACCOUNTS"
+msgstr "Geen accounts"
+
+msgid "IDS_EMAIL_BODY_PD_DAYS"
+msgstr "%d dagen"
+
+msgid "IDS_EMAIL_BODY_PD_ITEMS"
+msgstr "%d items"
+
+msgid "IDS_EMAIL_BODY_PRIORITY"
+msgstr "Prioriteit"
+
+msgid "IDS_EMAIL_BODY_RECEIVING_OPTIONS"
+msgstr "Ontvangstopties"
+
+msgid "IDS_EMAIL_BODY_SECURE_CONNECTION"
+msgstr "Veilige verbinding"
+
+msgid "IDS_EMAIL_BODY_SENDING_OPTIONS"
+msgstr "Verzendopties"
+
+msgid "IDS_EMAIL_BODY_SENTBOX"
+msgstr "Verzonden berichten"
+
+msgid "IDS_EMAIL_BODY_SERVER_URL"
+msgstr "URL server"
+
+msgid "IDS_EMAIL_BODY_SIGNATURE"
+msgstr "Handtekening"
+
+msgid "IDS_EMAIL_BODY_SPAMBOX"
+msgstr "Ongewenste berichten"
+
+msgid "IDS_EMAIL_BODY_START_TIME"
+msgstr "Begintijd"
+
+msgid "IDS_EMAIL_BODY_SYNC_SCHEDULE_TMO"
+msgstr "Synchronisatieschema"
+
+msgid "IDS_EMAIL_BODY_TRASH"
+msgstr "Prullenbak"
+
+msgid "IDS_EMAIL_BODY_WITHOUT_ATTACHMENTS"
+msgstr "Zonder bijlagen"
+
+msgid "IDS_EMAIL_BUTTON_GROUP"
+msgstr "Groep"
+
+msgid "IDS_EMAIL_HEADER_ADD_RULES"
+msgstr "Regels toevoegen"
+
+msgid "IDS_EMAIL_OPT_ATTACH_ITEMS"
+msgstr "Items toevoegen"
+
+msgid "IDS_EMAIL_OPT_EXCHANGE"
+msgstr "Exchange"
+
+msgid "IDS_EMAIL_OPT_FILE"
+msgstr "Bestand"
+
+msgid "IDS_EMAIL_OPT_NAMECARD"
+msgstr "Visitekaartje"
+
+msgid "IDS_EMAIL_OPT_OPEN_URL"
+msgstr "URL openen"
+
+msgid "IDS_EMAIL_OPT_SENDER"
+msgstr "Afzender"
+
+msgid "IDS_EMAIL_OPT_SEND_EMAIL"
+msgstr "E-mail verzenden"
+
+msgid "IDS_EMAIL_OPT_UPDATE_EXISTING"
+msgstr "Bestaande bijwerken"
+
+msgid "IDS_EMAIL_POP_ADD_ACCOUNTS"
+msgstr "Accounts toevoegen"
+
+msgid "IDS_EMAIL_POP_DOWNLOADING_ATTACHMENT_ING"
+msgstr "Bijlage downloaden..."
+
+msgid "IDS_EMAIL_POP_INVALID_EMAIL_ADDRESS"
+msgstr "Ongeldig e-mailadres"
+
+msgid "IDS_EMAIL_POP_LOADING_CONTENTS_ING"
+msgstr "Inhoud laden..."
+
+msgid "IDS_EMAIL_POP_MAXIMUM_NUMBER_OF_ATTACHMENTS_REACHED"
+msgstr "Maximumaantal bijlagen bereikt"
+
+msgid "IDS_EMAIL_POP_MOVE_TO_SPAMBOX_Q"
+msgstr "Verplaatsen naar Ongewenste e-mail?"
+
+msgid "IDS_EMAIL_POP_NO_RECIPIENTS_ADDED_ENTER_RECIPIENTS"
+msgstr "Geen ontvangers toegevoegd. Geef ontvangers in"
+
+msgid "IDS_EMAIL_POP_PLEASE_FILL_ALL_THE_MANDATORY_FIELDS"
+msgstr "Vul alle verplichte velden in"
+
+msgid "IDS_EMAIL_POP_SAVE_IN_DRAFTS_Q"
+msgstr "Opslaan in Concepten?"
+
+msgid "IDS_EMAIL_POP_THERE_IS_NO_ACCOUNT_CREATE_A_NEW_ACCOUNT_FIRST"
+msgstr "Er is geen account. Maak eerst een nieuwe account"
+
+msgid "IDS_EMAIL_POP_TOO_MANY_RECIPIENTS"
+msgstr "Te veel ontvangers"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_DOWNLOAD"
+msgstr "Kan niet downloaden"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_ENTER_TEXT"
+msgstr "Kan tekst niet ingeven"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_LAUNCH_APPLICATION"
+msgstr "Kan applicatie niet starten"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_OPEN_ATTACHMENT"
+msgstr "Kan bijlage niet openen"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_SAVE_ATTACHMENT"
+msgstr "Kan bijlage niet opslaan"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_SAVE_IN_DRAFTS"
+msgstr "Kan niet opslaan in Concepten"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_SEND_EMAIL"
+msgstr "Kan e-mail niet verzenden"
+
+msgid "IDS_EMAIL_POP_UNSUPPORTED_FILE_TYPE"
+msgstr "Niet-ondersteund bestandstype"
+
+msgid "IDS_EMAIL_POP_VALIDATING_ACCOUNT_ING"
+msgstr "Account controleren..."
+
+msgid "IDS_EMAIL_SK_RESEND"
+msgstr "Opnieuw verzenden"
+
+msgid "IDS_EMAIL_BODY_ACCEPT_ALL_SSL_CERTIFICATES"
+msgstr "Alle SSL-certificaten accepteren"
+
+msgid "IDS_EMAIL_SK3_ACCOUNT_LIST"
+msgstr "Account-lijst"
+
+msgid "IDS_EMAIL_BODY_USER_ID"
+msgstr "Gebruikersnaam"
+
+msgid "IDS_EMAIL_POP_ACCOUNT_ALREADY_REGISTERED"
+msgstr "Account reeds geregistreerd"
+
+msgid "IDS_EMAIL_HEADER_ATTACH_FILE"
+msgstr "Bestand toevoegen"
+
+msgid "IDS_EMAIL_BODY_EXCHANGE_SYNC_SETTINGS_MSG"
+msgstr "Door deze applicatie te activeren accepteert u dat bepaalde apparaatgegevens (unieke apparaat-id en modelnaam) door Samsung worden opgeslagen, verwerkt en gebruikt om het activeren van deze applicatie te rapporteren aan de licentiegevers van de applicatiesoftware. Gegevens worden door Samsung strikt volgens het Samsung-privacybeleid behandeld. Een exemplaar van dit beleid is op www.samsung.com beschikbaar. Doorgaan?"
+
+msgid "IDS_EMAIL_BODY_FORWARD_WITH_FILES"
+msgstr "Doorsturen met bestanden"
+
+msgid "IDS_EMAIL_BODY_REPLY_WITH_BODY"
+msgstr "Beantwoorden met oorspronkelijke tekst"
+
+msgid "IDS_EMAIL_BODY_NO_SUBJECT"
+msgstr "Geen onderwerp"
+
+msgid "IDS_EMAIL_BODY_FROM"
+msgstr "Van"
+
+msgid "IDS_EMAIL_BODY_NO_ADDRESS"
+msgstr "Geen adres"
+
+msgid "IDS_EMAIL_OPT_RECORD_SOUND"
+msgstr "Geluid opnemen"
+
+msgid "IDS_EMAIL_OPT_RECORD_VIDEO"
+msgstr "Video opnemen"
+
+msgid "IDS_EMAIL_OPT_INSERT_IMAGE"
+msgstr "Afbeelding invoegen"
+
+msgid "IDS_EMAIL_OPT_ADD_TO_CALENDAR"
+msgstr "Toevoegen aan agenda"
+
+msgid "IDS_EMAIL_OPT_CHANGE_EMAIL_ADDRESS_ABB"
+msgstr "E-mailadres wijzigen"
+
+msgid "IDS_EMAIL_OPT_CLIPBOARD"
+msgstr "Klembord"
+
+msgid "IDS_EMAIL_OPT_MARKED_AS_UNREAD"
+msgstr "Markeren als ongelezen"
+
+msgid "IDS_EMAIL_OPT_VIEW_CONTACT_DETAILS"
+msgstr "Details contact weergeven"
+
+msgid "IDS_EMAIL_POP_SAVED_IN_DRAFTS"
+msgstr "Opgeslagen in Concepten"
+
+msgid "IDS_EMAIL_POP_NETWORK_BUSY"
+msgstr "Netwerk bezet"
+
+msgid "IDS_EMAIL_POP_LOGIN_ALLOWED_ONLY_EVERY_PD_MINUTES"
+msgstr "Login allowed only every %d minutes"
+
+msgid "IDS_EMAIL_POP_HOST_NOT_FOUND"
+msgstr "Host niet gevonden"
+
+msgid "IDS_EMAIL_POP_HOST_NOT_REACHABLE"
+msgstr "Host onbereikbaar"
+
+msgid "IDS_EMAIL_POP_NO_SERVICE"
+msgstr "Geen netwerk"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_FORWARD_DRM_CONTENTS"
+msgstr "Kan DRM-inhoud niet doorsturen"
+
+msgid "IDS_EMAIL_POP_BLOCKED"
+msgstr "Geblokkeerd"
+
+msgid "IDS_EMAIL_POP_1_EMAIL_SELECTED"
+msgstr "1 e-mail geselecteerd"
+
+msgid "IDS_EMAIL_POP_PD_EMAILS_SELECTED"
+msgstr "%d e-mails geselecteerd"
+
+msgid "IDS_EMAIL_POP_1_RECIPIENT_SELECTED"
+msgstr "1 ontvanger geselecteerd"
+
+msgid "IDS_EMAIL_POP_PD_RECIPIENTS_SELECTED"
+msgstr "%d ontvangers geselecteerd"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_ADD_ACCOUNT"
+msgstr "Kan account niet toevoegen"
+
+msgid "IDS_EMAIL_SK3_MOVE_HERE"
+msgstr "Hier plaatsen"
+
diff --git a/po/pt_PT.po b/po/pt_PT.po
new file mode 100755
index 0000000..7ec97f2
--- /dev/null
+++ b/po/pt_PT.po
@@ -0,0 +1,465 @@
+msgid "IDS_EMAIL_POP_NO_EMAIL_ADDRESS"
+msgstr "Nenhum endereço de e-mail"
+
+msgid "IDS_EMAIL_BODY_COMPLETE"
+msgstr "Concluída"
+
+msgid "IDS_EMAIL_BODY_ACCEPTED_C_PS"
+msgstr "Aceite: %s"
+
+msgid "IDS_EMAIL_BODY_DECLINED_C_PS"
+msgstr "Declinado: %s"
+
+msgid "IDS_EMAIL_BODY_DOWNLOAD_FULL_MESSAGE"
+msgstr "Transferir mensagem completa"
+
+msgid "IDS_EMAIL_BODY_GENERAL_SETTINGS"
+msgstr "Defin. gerais"
+
+msgid "IDS_EMAIL_BODY_TENTATIVE_C_PS"
+msgstr "Tentativa: %s"
+
+msgid "IDS_EMAIL_BODY_WHEN_C_PS"
+msgstr "Quando: %s"
+
+msgid "IDS_EMAIL_BODY_WHERE_C_PS"
+msgstr "Onde: %s"
+
+msgid "IDS_EMAIL_BUTTON_DECLINE_ABB"
+msgstr "Declinar"
+
+msgid "IDS_EMAIL_BODY_NO_CONTENTS"
+msgstr "Sem conteúdo"
+
+msgid "IDS_EMAIL_BODY_ORIGINAL_MESSAGE"
+msgstr "Mensagem original"
+
+msgid "IDS_EMAIL_HEADER_ACCOUNT_SETTINGS"
+msgstr "Definições da conta"
+
+msgid "IDS_EMAIL_OPT_BLOCK"
+msgstr "Bloquear"
+
+msgid "IDS_EMAIL_OPT_MARK_AS_READ"
+msgstr "Marcar como lida"
+
+msgid "IDS_EMAIL_OPT_MARK_AS_UNREAD"
+msgstr "Marcar como não lida"
+
+msgid "IDS_EMAIL_OPT_OTHERS"
+msgstr "Outros"
+
+msgid "IDS_EMAIL_OPT_UNREAD"
+msgstr "Não lida"
+
+msgid "IDS_EMAIL_SK_COMPOSE"
+msgstr "Escrever"
+
+msgid "IDS_EMAIL_HEADER_DOWNLOAD_FAILED"
+msgstr "Falha na transferência"
+
+msgid "IDS_EMAIL_OPT_ADD_TO_CONTACT"
+msgstr "Adicionar a contacto"
+
+msgid "IDS_EMAIL_OPT_VOICE_CALL"
+msgstr "Chamada de voz"
+
+msgid "IDS_EMAIL_BODY_ACCOUNT_NAME"
+msgstr "Nome da conta"
+
+msgid "IDS_EMAIL_BODY_ATTACHMENTS"
+msgstr "Anexos"
+
+msgid "IDS_EMAIL_BODY_FROM_C"
+msgstr "De:"
+
+msgid "IDS_EMAIL_BODY_IMAP4_SERVER"
+msgstr "Servidor IMAP4"
+
+msgid "IDS_EMAIL_BODY_INCLUDES"
+msgstr "Inclui"
+
+msgid "IDS_EMAIL_BODY_INCOMING_PORT"
+msgstr "Porta de recepção"
+
+msgid "IDS_EMAIL_BODY_INCOMING_SERVER"
+msgstr "Servidor de recepção"
+
+msgid "IDS_EMAIL_BODY_IN_PD_MINUTES"
+msgstr "Dentro de %d minutos"
+
+msgid "IDS_EMAIL_BODY_KEEP_IN_SERVER"
+msgstr "Manter cópia no servidor"
+
+msgid "IDS_EMAIL_BODY_NO_TEXT"
+msgstr "Sem texto"
+
+msgid "IDS_EMAIL_BODY_OUTGOING_PORT"
+msgstr "Porta de envio"
+
+msgid "IDS_EMAIL_BODY_OUTGOING_SERVER"
+msgstr "Servidor de envio"
+
+msgid "IDS_EMAIL_BODY_PD_EMAILS"
+msgstr "%d e-mails"
+
+msgid "IDS_EMAIL_BODY_POP3_SERVER"
+msgstr "Servidor POP3"
+
+msgid "IDS_EMAIL_BODY_RECENT"
+msgstr "Recente"
+
+msgid "IDS_EMAIL_BODY_RETRIEVING_OPTIONS"
+msgstr "Opções de recepção"
+
+msgid "IDS_EMAIL_BODY_RE_C"
+msgstr "RE:"
+
+msgid "IDS_EMAIL_BODY_SENT_C"
+msgstr "Enviado:"
+
+msgid "IDS_EMAIL_BODY_SENT_FROM_SAMSUNG_MOBILE"
+msgstr "Enviado de Samsung Mobile"
+
+msgid "IDS_EMAIL_BODY_USER_PASSWORD"
+msgstr "Palavra-passe de utilizador"
+
+msgid "IDS_EMAIL_HEADER_EDIT_RULES"
+msgstr "Editar regras"
+
+msgid "IDS_EMAIL_HEADER_EMAIL_SETTINGS"
+msgstr "Definições e-mail"
+
+msgid "IDS_EMAIL_HEADER_MAILBOXES"
+msgstr "Caixas de correio"
+
+msgid "IDS_EMAIL_POP_ALERT"
+msgstr "Alerta"
+
+msgid "IDS_EMAIL_POP_FILE_ALREADY_EXISTS"
+msgstr "Ficheiro já existe"
+
+msgid "IDS_EMAIL_POP_NO_SENDER"
+msgstr "Nenhum remetente"
+
+msgid "IDS_EMAIL_POP_SUCCEEDED"
+msgstr "Com êxito"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_ATTACH_MAXIMUM_NUMBER_OF_FILES_IS_PD"
+msgstr "Impossível anexar. O número máximo de ficheiros é %d"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_ATTACH_MAXIMUM_SIZE_OF_FILES_IS_PD_KB"
+msgstr "Impossível anexar. O tamanho máximo dos ficheiros é %d KB"
+
+msgid "IDS_EMAIL_POP_VALIDATION_FAILED"
+msgstr "Validação falhou"
+
+msgid "IDS_EMAIL_SK_REPLY_ALL"
+msgstr "Respond. a todos"
+
+msgid "IDS_EMAIL_BODY_1_ITEM"
+msgstr "1 item"
+
+msgid "IDS_EMAIL_BODY_ADD_MY_NAMECARD"
+msgstr "Adicionar o meu cartão de visita"
+
+msgid "IDS_EMAIL_BODY_ADD_SIGNATURE"
+msgstr "Adicionar assinatura"
+
+msgid "IDS_EMAIL_BODY_ALL_EMAILS"
+msgstr "Todos os e-mails"
+
+msgid "IDS_EMAIL_BODY_ALWAYS_BCC_MYSELF"
+msgstr "Sempre com Bcc para mim"
+
+msgid "IDS_EMAIL_BODY_BCC"
+msgstr "Bcc"
+
+msgid "IDS_EMAIL_BODY_BLOCK_EMAILS"
+msgstr "Bloquear e-mails"
+
+msgid "IDS_EMAIL_BODY_BODY"
+msgstr "Corpo"
+
+msgid "IDS_EMAIL_BODY_CC"
+msgstr "Cc"
+
+msgid "IDS_EMAIL_BODY_CC_BCC"
+msgstr "Cc/Bcc"
+
+msgid "IDS_EMAIL_BODY_CHECK_INTERVAL"
+msgstr "Verificar intervalo"
+
+msgid "IDS_EMAIL_BODY_DEFAULT_ACCOUNT"
+msgstr "Conta padrão"
+
+msgid "IDS_EMAIL_BODY_DRAFTS"
+msgstr "Rascunhos"
+
+msgid "IDS_EMAIL_BODY_EMAIL_ACCOUNTS"
+msgstr "Contas de e-mail"
+
+msgid "IDS_EMAIL_BODY_END_TIME"
+msgstr "Hora de fim"
+
+msgid "IDS_EMAIL_BODY_ENTIRE_EMAIL"
+msgstr "E-mail completo"
+
+msgid "IDS_EMAIL_BODY_EXACTLY_THE_SAME_AS"
+msgstr "Exactamente o mesmo que"
+
+msgid "IDS_EMAIL_BODY_EXAMPLE"
+msgstr "Exemplo"
+
+msgid "IDS_EMAIL_BODY_FROM_M_SENDER"
+msgstr "De :"
+
+msgid "IDS_EMAIL_BODY_INBOX"
+msgstr "Caixa de Entrada"
+
+msgid "IDS_EMAIL_BODY_INCLUDE"
+msgstr "Incluir"
+
+msgid "IDS_EMAIL_BODY_MATCH_CRITERIA"
+msgstr "Corresponder critérios"
+
+msgid "IDS_EMAIL_BODY_NOT_USED"
+msgstr "Não utilizado"
+
+msgid "IDS_EMAIL_BODY_NO_ACCOUNTS"
+msgstr "Sem contas"
+
+msgid "IDS_EMAIL_BODY_PD_DAYS"
+msgstr "%d dias"
+
+msgid "IDS_EMAIL_BODY_PD_ITEMS"
+msgstr "%d itens"
+
+msgid "IDS_EMAIL_BODY_PRIORITY"
+msgstr "Prioridade"
+
+msgid "IDS_EMAIL_BODY_RECEIVING_OPTIONS"
+msgstr "Opções de recepção"
+
+msgid "IDS_EMAIL_BODY_SECURE_CONNECTION"
+msgstr "Ligação segura"
+
+msgid "IDS_EMAIL_BODY_SENDING_OPTIONS"
+msgstr "Opções de envio"
+
+msgid "IDS_EMAIL_BODY_SENTBOX"
+msgstr "Itens enviados"
+
+msgid "IDS_EMAIL_BODY_SERVER_URL"
+msgstr "URL do servidor"
+
+msgid "IDS_EMAIL_BODY_SIGNATURE"
+msgstr "Assinatura"
+
+msgid "IDS_EMAIL_BODY_SPAMBOX"
+msgstr "Caixa de Spam"
+
+msgid "IDS_EMAIL_BODY_START_TIME"
+msgstr "Hora de início"
+
+msgid "IDS_EMAIL_BODY_SYNC_SCHEDULE_TMO"
+msgstr "Agenda de sincronização"
+
+msgid "IDS_EMAIL_BODY_TRASH"
+msgstr "Lixo"
+
+msgid "IDS_EMAIL_BODY_WITHOUT_ATTACHMENTS"
+msgstr "Sem anexos"
+
+msgid "IDS_EMAIL_BUTTON_GROUP"
+msgstr "Grupo"
+
+msgid "IDS_EMAIL_HEADER_ADD_RULES"
+msgstr "Adicionar regras"
+
+msgid "IDS_EMAIL_OPT_ATTACH_ITEMS"
+msgstr "Anexar itens"
+
+msgid "IDS_EMAIL_OPT_EXCHANGE"
+msgstr "Exchange"
+
+msgid "IDS_EMAIL_OPT_FILE"
+msgstr "Ficheiro"
+
+msgid "IDS_EMAIL_OPT_NAMECARD"
+msgstr "Cartão de visita"
+
+msgid "IDS_EMAIL_OPT_OPEN_URL"
+msgstr "Abrir URL"
+
+msgid "IDS_EMAIL_OPT_SENDER"
+msgstr "Remetente"
+
+msgid "IDS_EMAIL_OPT_SEND_EMAIL"
+msgstr "Enviar e-mail"
+
+msgid "IDS_EMAIL_OPT_UPDATE_EXISTING"
+msgstr "Actualizar existente"
+
+msgid "IDS_EMAIL_POP_ADD_ACCOUNTS"
+msgstr "Adicionar contas"
+
+msgid "IDS_EMAIL_POP_DOWNLOADING_ATTACHMENT_ING"
+msgstr "A transferir anexo..."
+
+msgid "IDS_EMAIL_POP_INVALID_EMAIL_ADDRESS"
+msgstr "Endereço de e-mail inválido"
+
+msgid "IDS_EMAIL_POP_LOADING_CONTENTS_ING"
+msgstr "A carregar conteúdos..."
+
+msgid "IDS_EMAIL_POP_MAXIMUM_NUMBER_OF_ATTACHMENTS_REACHED"
+msgstr "Número máximo de anexos atingido"
+
+msgid "IDS_EMAIL_POP_MOVE_TO_SPAMBOX_Q"
+msgstr "Mover para caixa de spam?"
+
+msgid "IDS_EMAIL_POP_NO_RECIPIENTS_ADDED_ENTER_RECIPIENTS"
+msgstr "Nenhum destinatário adicionado. Introduzir destinatários"
+
+msgid "IDS_EMAIL_POP_PLEASE_FILL_ALL_THE_MANDATORY_FIELDS"
+msgstr "Preencha todos os campos obrigatórios"
+
+msgid "IDS_EMAIL_POP_SAVE_IN_DRAFTS_Q"
+msgstr "Guardar nos Rascunhos?"
+
+msgid "IDS_EMAIL_POP_THERE_IS_NO_ACCOUNT_CREATE_A_NEW_ACCOUNT_FIRST"
+msgstr "Não existe conta. Primeiro, tem de criar uma conta nova"
+
+msgid "IDS_EMAIL_POP_TOO_MANY_RECIPIENTS"
+msgstr "Demasiados destinatários"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_DOWNLOAD"
+msgstr "Impossível transferir"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_ENTER_TEXT"
+msgstr "Impossível introduzir texto"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_LAUNCH_APPLICATION"
+msgstr "Impossível iniciar aplicação"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_OPEN_ATTACHMENT"
+msgstr "Impossível abrir anexo"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_SAVE_ATTACHMENT"
+msgstr "Impossível guardar anexo"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_SAVE_IN_DRAFTS"
+msgstr "Impossível guardar em Rascunhos"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_SEND_EMAIL"
+msgstr "Impossível enviar e-mail"
+
+msgid "IDS_EMAIL_POP_UNSUPPORTED_FILE_TYPE"
+msgstr "Tipo de ficheiro não suportado"
+
+msgid "IDS_EMAIL_POP_VALIDATING_ACCOUNT_ING"
+msgstr "A validar conta..."
+
+msgid "IDS_EMAIL_SK_RESEND"
+msgstr "Reenviar"
+
+msgid "IDS_EMAIL_BODY_ACCEPT_ALL_SSL_CERTIFICATES"
+msgstr "Aceitar todos os certificados SSL"
+
+msgid "IDS_EMAIL_SK3_ACCOUNT_LIST"
+msgstr "Lista contas"
+
+msgid "IDS_EMAIL_BODY_USER_ID"
+msgstr "ID de utilizador"
+
+msgid "IDS_EMAIL_POP_ACCOUNT_ALREADY_REGISTERED"
+msgstr "Conta já registada"
+
+msgid "IDS_EMAIL_HEADER_ATTACH_FILE"
+msgstr "Anexar ficheiro"
+
+msgid "IDS_EMAIL_BODY_EXCHANGE_SYNC_SETTINGS_MSG"
+msgstr "Ao activar esta aplicação, aceita que parte dos dados do seu dispositivo (o identificador único do dispositivo e o nome do modelo) sejam guardados, processados e utilizados pela Samsung para comunicar a activação desta aplicação aos licenciadores do software. Os dados que estejam na posse da Samsung serão rigorosamente tratados de acordo com a política de privacidade da Samsung que está disponível em www.samsung.com. Continuar?"
+
+msgid "IDS_EMAIL_BODY_FORWARD_WITH_FILES"
+msgstr "Reencam. com ficheiros"
+
+msgid "IDS_EMAIL_BODY_REPLY_WITH_BODY"
+msgstr "Responder com corpo"
+
+msgid "IDS_EMAIL_BODY_NO_SUBJECT"
+msgstr "Sem assunto"
+
+msgid "IDS_EMAIL_BODY_FROM"
+msgstr "De"
+
+msgid "IDS_EMAIL_BODY_NO_ADDRESS"
+msgstr "Nenhum endereço"
+
+msgid "IDS_EMAIL_OPT_RECORD_SOUND"
+msgstr "Gravar som"
+
+msgid "IDS_EMAIL_OPT_RECORD_VIDEO"
+msgstr "Gravar vídeo"
+
+msgid "IDS_EMAIL_OPT_INSERT_IMAGE"
+msgstr "Introduzir imagem"
+
+msgid "IDS_EMAIL_OPT_ADD_TO_CALENDAR"
+msgstr "Adicionar à Agenda"
+
+msgid "IDS_EMAIL_OPT_CHANGE_EMAIL_ADDRESS_ABB"
+msgstr "Alterar endereço de e-mail"
+
+msgid "IDS_EMAIL_OPT_CLIPBOARD"
+msgstr "Ãrea de transferência"
+
+msgid "IDS_EMAIL_OPT_MARKED_AS_UNREAD"
+msgstr "Marcada como não lida"
+
+msgid "IDS_EMAIL_OPT_VIEW_CONTACT_DETAILS"
+msgstr "Ver detalhes de contacto"
+
+msgid "IDS_EMAIL_POP_SAVED_IN_DRAFTS"
+msgstr "Guardado nos Rascunhos"
+
+msgid "IDS_EMAIL_POP_NETWORK_BUSY"
+msgstr "Rede ocupada"
+
+msgid "IDS_EMAIL_POP_LOGIN_ALLOWED_ONLY_EVERY_PD_MINUTES"
+msgstr "Login allowed only every %d minutes"
+
+msgid "IDS_EMAIL_POP_HOST_NOT_FOUND"
+msgstr "Anfitrião não encontrado"
+
+msgid "IDS_EMAIL_POP_HOST_NOT_REACHABLE"
+msgstr "Anfitrião incontactável"
+
+msgid "IDS_EMAIL_POP_NO_SERVICE"
+msgstr "Sem serviço"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_FORWARD_DRM_CONTENTS"
+msgstr "Impossível reencaminhar conteúdos DRM"
+
+msgid "IDS_EMAIL_POP_BLOCKED"
+msgstr "Bloqueado"
+
+msgid "IDS_EMAIL_POP_1_EMAIL_SELECTED"
+msgstr "1 e-mail seleccionado"
+
+msgid "IDS_EMAIL_POP_PD_EMAILS_SELECTED"
+msgstr "%d e-mails seleccionados"
+
+msgid "IDS_EMAIL_POP_1_RECIPIENT_SELECTED"
+msgstr "1 destinatário seleccionado"
+
+msgid "IDS_EMAIL_POP_PD_RECIPIENTS_SELECTED"
+msgstr "%d destinatários seleccionados"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_ADD_ACCOUNT"
+msgstr "Impossível adicionar conta"
+
+msgid "IDS_EMAIL_SK3_MOVE_HERE"
+msgstr "Mover para aqui"
+
diff --git a/po/ru_RU.po b/po/ru_RU.po
new file mode 100755
index 0000000..f17d76e
--- /dev/null
+++ b/po/ru_RU.po
@@ -0,0 +1,465 @@
+msgid "IDS_EMAIL_POP_NO_EMAIL_ADDRESS"
+msgstr "Ðет адреÑа E-mail"
+
+msgid "IDS_EMAIL_BODY_COMPLETE"
+msgstr "Завершено"
+
+msgid "IDS_EMAIL_BODY_ACCEPTED_C_PS"
+msgstr "ПринÑто: %s"
+
+msgid "IDS_EMAIL_BODY_DECLINED_C_PS"
+msgstr "Отклонено: %s"
+
+msgid "IDS_EMAIL_BODY_DOWNLOAD_FULL_MESSAGE"
+msgstr "Загрузить вÑе Ñообщение"
+
+msgid "IDS_EMAIL_BODY_GENERAL_SETTINGS"
+msgstr "Общие наÑтройки"
+
+msgid "IDS_EMAIL_BODY_TENTATIVE_C_PS"
+msgstr "Под вопроÑом: %s"
+
+msgid "IDS_EMAIL_BODY_WHEN_C_PS"
+msgstr "Когда: %s"
+
+msgid "IDS_EMAIL_BODY_WHERE_C_PS"
+msgstr "Где: %s"
+
+msgid "IDS_EMAIL_BUTTON_DECLINE_ABB"
+msgstr "Отклонить"
+
+msgid "IDS_EMAIL_BODY_NO_CONTENTS"
+msgstr "Ðет Ñодержимого"
+
+msgid "IDS_EMAIL_BODY_ORIGINAL_MESSAGE"
+msgstr "ИÑходное Ñообщение"
+
+msgid "IDS_EMAIL_HEADER_ACCOUNT_SETTINGS"
+msgstr "Параметры учетной запиÑи"
+
+msgid "IDS_EMAIL_OPT_BLOCK"
+msgstr "Блокировать"
+
+msgid "IDS_EMAIL_OPT_MARK_AS_READ"
+msgstr "Пометить как прочитанное"
+
+msgid "IDS_EMAIL_OPT_MARK_AS_UNREAD"
+msgstr "Пометить как непрочитанное"
+
+msgid "IDS_EMAIL_OPT_OTHERS"
+msgstr "Прочее"
+
+msgid "IDS_EMAIL_OPT_UNREAD"
+msgstr "Ðепрочитанные"
+
+msgid "IDS_EMAIL_SK_COMPOSE"
+msgstr "Создать"
+
+msgid "IDS_EMAIL_HEADER_DOWNLOAD_FAILED"
+msgstr "Загрузка невозможна"
+
+msgid "IDS_EMAIL_OPT_ADD_TO_CONTACT"
+msgstr "Добавить к контакту"
+
+msgid "IDS_EMAIL_OPT_VOICE_CALL"
+msgstr "ГолоÑовой вызов"
+
+msgid "IDS_EMAIL_BODY_ACCOUNT_NAME"
+msgstr "Ð˜Ð¼Ñ ÑƒÑ‡ÐµÑ‚Ð½Ð¾Ð¹ запиÑи"
+
+msgid "IDS_EMAIL_BODY_ATTACHMENTS"
+msgstr "ВложениÑ"
+
+msgid "IDS_EMAIL_BODY_FROM_C"
+msgstr "От:"
+
+msgid "IDS_EMAIL_BODY_IMAP4_SERVER"
+msgstr "Сервер IMAP4"
+
+msgid "IDS_EMAIL_BODY_INCLUDES"
+msgstr "Содержит"
+
+msgid "IDS_EMAIL_BODY_INCOMING_PORT"
+msgstr "Порт Ñервера вх. почты"
+
+msgid "IDS_EMAIL_BODY_INCOMING_SERVER"
+msgstr "ВходÑщий Ñервер"
+
+msgid "IDS_EMAIL_BODY_IN_PD_MINUTES"
+msgstr "Через %d мин."
+
+msgid "IDS_EMAIL_BODY_KEEP_IN_SERVER"
+msgstr "Хранить копии на Ñервере"
+
+msgid "IDS_EMAIL_BODY_NO_TEXT"
+msgstr "Ðет текÑта"
+
+msgid "IDS_EMAIL_BODY_OUTGOING_PORT"
+msgstr "Порт Ñервера иÑÑ…. почты"
+
+msgid "IDS_EMAIL_BODY_OUTGOING_SERVER"
+msgstr "ИÑходÑщий Ñервер"
+
+msgid "IDS_EMAIL_BODY_PD_EMAILS"
+msgstr "Сообщений Ñлектронной почты: %d"
+
+msgid "IDS_EMAIL_BODY_POP3_SERVER"
+msgstr "Сервер POP3"
+
+msgid "IDS_EMAIL_BODY_RECENT"
+msgstr "ПоÑледние"
+
+msgid "IDS_EMAIL_BODY_RETRIEVING_OPTIONS"
+msgstr "Параметры приема"
+
+msgid "IDS_EMAIL_BODY_RE_C"
+msgstr "RE:"
+
+msgid "IDS_EMAIL_BODY_SENT_C"
+msgstr "Отправлено:"
+
+msgid "IDS_EMAIL_BODY_SENT_FROM_SAMSUNG_MOBILE"
+msgstr "Отправлено Ñ Samsung Mobile"
+
+msgid "IDS_EMAIL_BODY_USER_PASSWORD"
+msgstr "Пароль пользователÑ"
+
+msgid "IDS_EMAIL_HEADER_EDIT_RULES"
+msgstr "Изменить правила"
+
+msgid "IDS_EMAIL_HEADER_EMAIL_SETTINGS"
+msgstr "ÐаÑтройки Ñл.почты"
+
+msgid "IDS_EMAIL_HEADER_MAILBOXES"
+msgstr "Почтовые Ñщики"
+
+msgid "IDS_EMAIL_POP_ALERT"
+msgstr "Сигнал"
+
+msgid "IDS_EMAIL_POP_FILE_ALREADY_EXISTS"
+msgstr "Файл уже ÑущеÑтвует"
+
+msgid "IDS_EMAIL_POP_NO_SENDER"
+msgstr "Отправитель отÑутÑтвует"
+
+msgid "IDS_EMAIL_POP_SUCCEEDED"
+msgstr "УÑпешно"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_ATTACH_MAXIMUM_NUMBER_OF_FILES_IS_PD"
+msgstr "Ðевозможно вложить. МакÑимальное количеÑтво файлов: %d"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_ATTACH_MAXIMUM_SIZE_OF_FILES_IS_PD_KB"
+msgstr "Ðевозможно вложить. МакÑимальный размер файлов: %d КБ"
+
+msgid "IDS_EMAIL_POP_VALIDATION_FAILED"
+msgstr "Сбой проверки"
+
+msgid "IDS_EMAIL_SK_REPLY_ALL"
+msgstr "Ответить вÑем"
+
+msgid "IDS_EMAIL_BODY_1_ITEM"
+msgstr "1 Ñлемент"
+
+msgid "IDS_EMAIL_BODY_ADD_MY_NAMECARD"
+msgstr "Добавить мою визитку"
+
+msgid "IDS_EMAIL_BODY_ADD_SIGNATURE"
+msgstr "ДобавлÑÑ‚ÑŒ подпиÑÑŒ"
+
+msgid "IDS_EMAIL_BODY_ALL_EMAILS"
+msgstr "Ð’Ñе ÑообщениÑ"
+
+msgid "IDS_EMAIL_BODY_ALWAYS_BCC_MYSELF"
+msgstr "Ð’Ñегда отправлÑÑ‚ÑŒ Ñебе Ñкрытую копию"
+
+msgid "IDS_EMAIL_BODY_BCC"
+msgstr "СК"
+
+msgid "IDS_EMAIL_BODY_BLOCK_EMAILS"
+msgstr "Блокировка E-mail Ñообщений"
+
+msgid "IDS_EMAIL_BODY_BODY"
+msgstr "ТелоÑложение"
+
+msgid "IDS_EMAIL_BODY_CC"
+msgstr "КопиÑ"
+
+msgid "IDS_EMAIL_BODY_CC_BCC"
+msgstr "КопиÑ/ÑÐºÑ€Ñ‹Ñ‚Ð°Ñ ÐºÐ¾Ð¿Ð¸Ñ"
+
+msgid "IDS_EMAIL_BODY_CHECK_INTERVAL"
+msgstr "Интервал проверки"
+
+msgid "IDS_EMAIL_BODY_DEFAULT_ACCOUNT"
+msgstr "Уч. зап. по умолч."
+
+msgid "IDS_EMAIL_BODY_DRAFTS"
+msgstr "Черновики"
+
+msgid "IDS_EMAIL_BODY_EMAIL_ACCOUNTS"
+msgstr "Учетные запиÑи"
+
+msgid "IDS_EMAIL_BODY_END_TIME"
+msgstr "Ð’Ñ€ÐµÐ¼Ñ Ð¾ÐºÐ¾Ð½Ñ‡Ð°Ð½Ð¸Ñ"
+
+msgid "IDS_EMAIL_BODY_ENTIRE_EMAIL"
+msgstr "Ð’Ñе ÑÐ¾Ð¾Ð±Ñ‰ÐµÐ½Ð¸Ñ Ñлектронной почты"
+
+msgid "IDS_EMAIL_BODY_EXACTLY_THE_SAME_AS"
+msgstr "Точное Ñовпадение"
+
+msgid "IDS_EMAIL_BODY_EXAMPLE"
+msgstr "Пример"
+
+msgid "IDS_EMAIL_BODY_FROM_M_SENDER"
+msgstr "От:"
+
+msgid "IDS_EMAIL_BODY_INBOX"
+msgstr "ВходÑщие"
+
+msgid "IDS_EMAIL_BODY_INCLUDE"
+msgstr "Содержит"
+
+msgid "IDS_EMAIL_BODY_MATCH_CRITERIA"
+msgstr "УÑловие ÑовпадениÑ"
+
+msgid "IDS_EMAIL_BODY_NOT_USED"
+msgstr "Ðе иÑпользуетÑÑ"
+
+msgid "IDS_EMAIL_BODY_NO_ACCOUNTS"
+msgstr "Ðет учетных запиÑей"
+
+msgid "IDS_EMAIL_BODY_PD_DAYS"
+msgstr "%d дней"
+
+msgid "IDS_EMAIL_BODY_PD_ITEMS"
+msgstr "Элементов: %d"
+
+msgid "IDS_EMAIL_BODY_PRIORITY"
+msgstr "Приоритет"
+
+msgid "IDS_EMAIL_BODY_RECEIVING_OPTIONS"
+msgstr "Параметры приема"
+
+msgid "IDS_EMAIL_BODY_SECURE_CONNECTION"
+msgstr "БезопаÑное Ñоединение"
+
+msgid "IDS_EMAIL_BODY_SENDING_OPTIONS"
+msgstr "Параметры отправки"
+
+msgid "IDS_EMAIL_BODY_SENTBOX"
+msgstr "Отправленные"
+
+msgid "IDS_EMAIL_BODY_SERVER_URL"
+msgstr "URL Ñервера"
+
+msgid "IDS_EMAIL_BODY_SIGNATURE"
+msgstr "ПодпиÑÑŒ"
+
+msgid "IDS_EMAIL_BODY_SPAMBOX"
+msgstr "Спам"
+
+msgid "IDS_EMAIL_BODY_START_TIME"
+msgstr "Ð’Ñ€ÐµÐ¼Ñ Ð½Ð°Ñ‡Ð°Ð»Ð°"
+
+msgid "IDS_EMAIL_BODY_SYNC_SCHEDULE_TMO"
+msgstr "РаÑпиÑание Ñинхронизации"
+
+msgid "IDS_EMAIL_BODY_TRASH"
+msgstr "Корзина"
+
+msgid "IDS_EMAIL_BODY_WITHOUT_ATTACHMENTS"
+msgstr "Без вложений"
+
+msgid "IDS_EMAIL_BUTTON_GROUP"
+msgstr "Группа"
+
+msgid "IDS_EMAIL_HEADER_ADD_RULES"
+msgstr "Добавить правила"
+
+msgid "IDS_EMAIL_OPT_ATTACH_ITEMS"
+msgstr "Вложить Ñлементы"
+
+msgid "IDS_EMAIL_OPT_EXCHANGE"
+msgstr "Exchange"
+
+msgid "IDS_EMAIL_OPT_FILE"
+msgstr "Файл"
+
+msgid "IDS_EMAIL_OPT_NAMECARD"
+msgstr "Визитка"
+
+msgid "IDS_EMAIL_OPT_OPEN_URL"
+msgstr "Открыть URL"
+
+msgid "IDS_EMAIL_OPT_SENDER"
+msgstr "Отправитель"
+
+msgid "IDS_EMAIL_OPT_SEND_EMAIL"
+msgstr "Отправить E-mail"
+
+msgid "IDS_EMAIL_OPT_UPDATE_EXISTING"
+msgstr "Обновить контакт"
+
+msgid "IDS_EMAIL_POP_ADD_ACCOUNTS"
+msgstr "Добавить учетные запиÑи"
+
+msgid "IDS_EMAIL_POP_DOWNLOADING_ATTACHMENT_ING"
+msgstr "Загрузка вложениÑ..."
+
+msgid "IDS_EMAIL_POP_INVALID_EMAIL_ADDRESS"
+msgstr "Ðеправильный Ð°Ð´Ñ€ÐµÑ Ñл. почты"
+
+msgid "IDS_EMAIL_POP_LOADING_CONTENTS_ING"
+msgstr "Загрузка Ñодержимого..."
+
+msgid "IDS_EMAIL_POP_MAXIMUM_NUMBER_OF_ATTACHMENTS_REACHED"
+msgstr "ДоÑтигнуто макÑимальное чиÑло вложений"
+
+msgid "IDS_EMAIL_POP_MOVE_TO_SPAMBOX_Q"
+msgstr "ПеремеÑтить в папку нежелательной почты?"
+
+msgid "IDS_EMAIL_POP_NO_RECIPIENTS_ADDED_ENTER_RECIPIENTS"
+msgstr "Получатели не введены. Введите получателей"
+
+msgid "IDS_EMAIL_POP_PLEASE_FILL_ALL_THE_MANDATORY_FIELDS"
+msgstr "Заполните вÑе обÑзательные полÑ"
+
+msgid "IDS_EMAIL_POP_SAVE_IN_DRAFTS_Q"
+msgstr "Сохранить в черновиках?"
+
+msgid "IDS_EMAIL_POP_THERE_IS_NO_ACCOUNT_CREATE_A_NEW_ACCOUNT_FIRST"
+msgstr "Ðет учетной запиÑи. Сначала Ñоздайте новую учетную запиÑÑŒ"
+
+msgid "IDS_EMAIL_POP_TOO_MANY_RECIPIENTS"
+msgstr "Слишком много получателей"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_DOWNLOAD"
+msgstr "Ðевозможно выполнить загрузку"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_ENTER_TEXT"
+msgstr "Ðе удаетÑÑ Ð²Ð²ÐµÑти текÑÑ‚"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_LAUNCH_APPLICATION"
+msgstr "Ðе удаетÑÑ Ð·Ð°Ð¿ÑƒÑтить приложение"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_OPEN_ATTACHMENT"
+msgstr "Ðе удаетÑÑ Ð¾Ñ‚ÐºÑ€Ñ‹Ñ‚ÑŒ вложение"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_SAVE_ATTACHMENT"
+msgstr "Ðе удаетÑÑ Ñохранить вложение"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_SAVE_IN_DRAFTS"
+msgstr "Ðе удаетÑÑ Ñохранить как черновик"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_SEND_EMAIL"
+msgstr "Ðе удаетÑÑ Ð¾Ñ‚Ð¿Ñ€Ð°Ð²Ð¸Ñ‚ÑŒ Ñообщение Ñлектронной почты"
+
+msgid "IDS_EMAIL_POP_UNSUPPORTED_FILE_TYPE"
+msgstr "Ðеподдерживаемый тип файла"
+
+msgid "IDS_EMAIL_POP_VALIDATING_ACCOUNT_ING"
+msgstr "Проверка учетной запиÑи..."
+
+msgid "IDS_EMAIL_SK_RESEND"
+msgstr "Отправить повторно"
+
+msgid "IDS_EMAIL_BODY_ACCEPT_ALL_SSL_CERTIFICATES"
+msgstr "Принимать вÑе Ñертификаты SSL"
+
+msgid "IDS_EMAIL_SK3_ACCOUNT_LIST"
+msgstr "Учетные запиÑи"
+
+msgid "IDS_EMAIL_BODY_USER_ID"
+msgstr "Логин"
+
+msgid "IDS_EMAIL_POP_ACCOUNT_ALREADY_REGISTERED"
+msgstr "Ð£Ñ‡ÐµÑ‚Ð½Ð°Ñ Ð·Ð°Ð¿Ð¸ÑÑŒ уже зарегиÑтрирована"
+
+msgid "IDS_EMAIL_HEADER_ATTACH_FILE"
+msgstr "Вложить файл"
+
+msgid "IDS_EMAIL_BODY_EXCHANGE_SYNC_SETTINGS_MSG"
+msgstr "ÐÐºÑ‚Ð¸Ð²Ð¸Ñ€ÑƒÑ Ñто приложение, вы ÑоглашаетеÑÑŒ Ñ Ñ‚ÐµÐ¼, что чаÑÑ‚ÑŒ данных об уÑтройÑтве (идентификатор и название модели) будет хранитьÑÑ, обрабатыватьÑÑ Ð¸ иÑпользоватьÑÑ ÐºÐ¾Ð¼Ð¿Ð°Ð½Ð¸ÐµÐ¹ Samsung Ð´Ð»Ñ Ð¾Ñ‚Ð¿Ñ€Ð°Ð²ÐºÐ¸ отчетов об активации Ð¿Ñ€Ð¸Ð»Ð¾Ð¶ÐµÐ½Ð¸Ñ ÐµÐ³Ð¾ лицензиарам. Данные, которые хранÑÑ‚ÑÑ ÐºÐ¾Ñ€Ð¿Ð¾Ñ€Ð°Ñ†Ð¸ÐµÐ¹ Samsung, будут иÑпользоватьÑÑ Ð¸Ñключительно в ÑоответÑтвии Ñ Ð¿Ð¾Ð»Ð¸Ñ‚Ð¸ÐºÐ¾Ð¹ конфиденциальноÑти Samsung, опубликованной на Ñайте www.samsung.com. Продолжить?"
+
+msgid "IDS_EMAIL_BODY_FORWARD_WITH_FILES"
+msgstr "ПереÑылать Ñ Ñ„Ð°Ð¹Ð»Ð°Ð¼Ð¸"
+
+msgid "IDS_EMAIL_BODY_REPLY_WITH_BODY"
+msgstr "ТекÑÑ‚ ÑÐ¾Ð¾Ð±Ñ‰ÐµÐ½Ð¸Ñ Ð¿Ñ€Ð¸ ответе"
+
+msgid "IDS_EMAIL_BODY_NO_SUBJECT"
+msgstr "Ðет темы"
+
+msgid "IDS_EMAIL_BODY_FROM"
+msgstr "От"
+
+msgid "IDS_EMAIL_BODY_NO_ADDRESS"
+msgstr "Ðет адреÑа"
+
+msgid "IDS_EMAIL_OPT_RECORD_SOUND"
+msgstr "ЗапиÑать звук"
+
+msgid "IDS_EMAIL_OPT_RECORD_VIDEO"
+msgstr "ЗапиÑать видео"
+
+msgid "IDS_EMAIL_OPT_INSERT_IMAGE"
+msgstr "Ð’Ñтавить изображение"
+
+msgid "IDS_EMAIL_OPT_ADD_TO_CALENDAR"
+msgstr "Добавить в календарь"
+
+msgid "IDS_EMAIL_OPT_CHANGE_EMAIL_ADDRESS_ABB"
+msgstr "Изменить Ñлектронный адреÑ"
+
+msgid "IDS_EMAIL_OPT_CLIPBOARD"
+msgstr "Буфер обмена"
+
+msgid "IDS_EMAIL_OPT_MARKED_AS_UNREAD"
+msgstr "Отмечено как непрочитанное"
+
+msgid "IDS_EMAIL_OPT_VIEW_CONTACT_DETAILS"
+msgstr "Ð¡Ð²ÐµÐ´ÐµÐ½Ð¸Ñ Ð¾ контакте"
+
+msgid "IDS_EMAIL_POP_SAVED_IN_DRAFTS"
+msgstr "Сохранено в Черновики"
+
+msgid "IDS_EMAIL_POP_NETWORK_BUSY"
+msgstr "Сеть занÑта"
+
+msgid "IDS_EMAIL_POP_LOGIN_ALLOWED_ONLY_EVERY_PD_MINUTES"
+msgstr "Login allowed only every %d minutes"
+
+msgid "IDS_EMAIL_POP_HOST_NOT_FOUND"
+msgstr "ХоÑÑ‚ не обнаружен"
+
+msgid "IDS_EMAIL_POP_HOST_NOT_REACHABLE"
+msgstr "ХоÑÑ‚ недоÑтупен"
+
+msgid "IDS_EMAIL_POP_NO_SERVICE"
+msgstr "Ðет Ñети"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_FORWARD_DRM_CONTENTS"
+msgstr "Ðе удаетÑÑ Ð¿ÐµÑ€ÐµÑлать Ñодержимое DRM"
+
+msgid "IDS_EMAIL_POP_BLOCKED"
+msgstr "Заблокировано"
+
+msgid "IDS_EMAIL_POP_1_EMAIL_SELECTED"
+msgstr "Выбрано 1 Ñообщение Ñлектронной почты"
+
+msgid "IDS_EMAIL_POP_PD_EMAILS_SELECTED"
+msgstr "Выбрано Ñообщений Ñлектронной почты: %d"
+
+msgid "IDS_EMAIL_POP_1_RECIPIENT_SELECTED"
+msgstr "Выбран 1 получатель"
+
+msgid "IDS_EMAIL_POP_PD_RECIPIENTS_SELECTED"
+msgstr "Выбрано получателей: %d"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_ADD_ACCOUNT"
+msgstr "Ðе удаетÑÑ Ð´Ð¾Ð±Ð°Ð²Ð¸Ñ‚ÑŒ учетную запиÑÑŒ"
+
+msgid "IDS_EMAIL_SK3_MOVE_HERE"
+msgstr "ПеремеÑтить Ñюда"
+
diff --git a/po/tr_TR.po b/po/tr_TR.po
new file mode 100755
index 0000000..eb1e8b3
--- /dev/null
+++ b/po/tr_TR.po
@@ -0,0 +1,465 @@
+msgid "IDS_EMAIL_POP_NO_EMAIL_ADDRESS"
+msgstr "E-posta adresi yok"
+
+msgid "IDS_EMAIL_BODY_COMPLETE"
+msgstr "Tamamlandı"
+
+msgid "IDS_EMAIL_BODY_ACCEPTED_C_PS"
+msgstr "Kabul edildi: %s"
+
+msgid "IDS_EMAIL_BODY_DECLINED_C_PS"
+msgstr "Reddedildi: %s"
+
+msgid "IDS_EMAIL_BODY_DOWNLOAD_FULL_MESSAGE"
+msgstr "Tam mesajı indirin"
+
+msgid "IDS_EMAIL_BODY_GENERAL_SETTINGS"
+msgstr "Genel ayarlar"
+
+msgid "IDS_EMAIL_BODY_TENTATIVE_C_PS"
+msgstr "Deneysel: %s"
+
+msgid "IDS_EMAIL_BODY_WHEN_C_PS"
+msgstr "Ne zaman: %s"
+
+msgid "IDS_EMAIL_BODY_WHERE_C_PS"
+msgstr "Yeri: %s"
+
+msgid "IDS_EMAIL_BUTTON_DECLINE_ABB"
+msgstr "Reddetme"
+
+msgid "IDS_EMAIL_BODY_NO_CONTENTS"
+msgstr "İçerik yok"
+
+msgid "IDS_EMAIL_BODY_ORIGINAL_MESSAGE"
+msgstr "Orjinal mesaj"
+
+msgid "IDS_EMAIL_HEADER_ACCOUNT_SETTINGS"
+msgstr "Hesap ayarları"
+
+msgid "IDS_EMAIL_OPT_BLOCK"
+msgstr "Engelle"
+
+msgid "IDS_EMAIL_OPT_MARK_AS_READ"
+msgstr "Okundu olarak iÅŸaretle"
+
+msgid "IDS_EMAIL_OPT_MARK_AS_UNREAD"
+msgstr "Okunmadı olarak işaretle"
+
+msgid "IDS_EMAIL_OPT_OTHERS"
+msgstr "DiÄŸerleri"
+
+msgid "IDS_EMAIL_OPT_UNREAD"
+msgstr "Okunmadı"
+
+msgid "IDS_EMAIL_SK_COMPOSE"
+msgstr "Yaz"
+
+msgid "IDS_EMAIL_HEADER_DOWNLOAD_FAILED"
+msgstr "İndirme başarısız"
+
+msgid "IDS_EMAIL_OPT_ADD_TO_CONTACT"
+msgstr "Rehbere ekle"
+
+msgid "IDS_EMAIL_OPT_VOICE_CALL"
+msgstr "Sesli arama"
+
+msgid "IDS_EMAIL_BODY_ACCOUNT_NAME"
+msgstr "Hesap adı"
+
+msgid "IDS_EMAIL_BODY_ATTACHMENTS"
+msgstr "Eklentiler"
+
+msgid "IDS_EMAIL_BODY_FROM_C"
+msgstr "Başlangıç tarihi:"
+
+msgid "IDS_EMAIL_BODY_IMAP4_SERVER"
+msgstr "IMAP4 sunucusu"
+
+msgid "IDS_EMAIL_BODY_INCLUDES"
+msgstr "İçerik"
+
+msgid "IDS_EMAIL_BODY_INCOMING_PORT"
+msgstr "Gelen bağlantı noktası"
+
+msgid "IDS_EMAIL_BODY_INCOMING_SERVER"
+msgstr "Gelen sunucu"
+
+msgid "IDS_EMAIL_BODY_IN_PD_MINUTES"
+msgstr "%d dakika içinde"
+
+msgid "IDS_EMAIL_BODY_KEEP_IN_SERVER"
+msgstr "Sunucuda sakla"
+
+msgid "IDS_EMAIL_BODY_NO_TEXT"
+msgstr "Metin yok"
+
+msgid "IDS_EMAIL_BODY_OUTGOING_PORT"
+msgstr "Giden bağlantı noktası"
+
+msgid "IDS_EMAIL_BODY_OUTGOING_SERVER"
+msgstr "Giden sunucu"
+
+msgid "IDS_EMAIL_BODY_PD_EMAILS"
+msgstr "%d e-posta"
+
+msgid "IDS_EMAIL_BODY_POP3_SERVER"
+msgstr "POP3 sunucusu"
+
+msgid "IDS_EMAIL_BODY_RECENT"
+msgstr "Yakın"
+
+msgid "IDS_EMAIL_BODY_RETRIEVING_OPTIONS"
+msgstr "Alma seçenekleri"
+
+msgid "IDS_EMAIL_BODY_RE_C"
+msgstr "YNT:"
+
+msgid "IDS_EMAIL_BODY_SENT_C"
+msgstr "Gönderildi:"
+
+msgid "IDS_EMAIL_BODY_SENT_FROM_SAMSUNG_MOBILE"
+msgstr "Samsung Mobile tarafından gönderildi"
+
+msgid "IDS_EMAIL_BODY_USER_PASSWORD"
+msgstr "Kullanıcı şifresi"
+
+msgid "IDS_EMAIL_HEADER_EDIT_RULES"
+msgstr "Kuralları düzenle"
+
+msgid "IDS_EMAIL_HEADER_EMAIL_SETTINGS"
+msgstr "E-Posta ayarları"
+
+msgid "IDS_EMAIL_HEADER_MAILBOXES"
+msgstr "Posta kutuları"
+
+msgid "IDS_EMAIL_POP_ALERT"
+msgstr "Uyarı"
+
+msgid "IDS_EMAIL_POP_FILE_ALREADY_EXISTS"
+msgstr "Dosya zaten var"
+
+msgid "IDS_EMAIL_POP_NO_SENDER"
+msgstr "Gönderici yok"
+
+msgid "IDS_EMAIL_POP_SUCCEEDED"
+msgstr "Başarılı"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_ATTACH_MAXIMUM_NUMBER_OF_FILES_IS_PD"
+msgstr "Eklenemiyor. Maksimum dosya sayısı %d"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_ATTACH_MAXIMUM_SIZE_OF_FILES_IS_PD_KB"
+msgstr "Eklenemiyor. Maksimum dosya boyutu %d KB"
+
+msgid "IDS_EMAIL_POP_VALIDATION_FAILED"
+msgstr "Onaylama başarısız"
+
+msgid "IDS_EMAIL_SK_REPLY_ALL"
+msgstr "Tümünü yanıtla"
+
+msgid "IDS_EMAIL_BODY_1_ITEM"
+msgstr "1 öğe"
+
+msgid "IDS_EMAIL_BODY_ADD_MY_NAMECARD"
+msgstr "Kartvizitimi ekle"
+
+msgid "IDS_EMAIL_BODY_ADD_SIGNATURE"
+msgstr "Ä°mza ekle"
+
+msgid "IDS_EMAIL_BODY_ALL_EMAILS"
+msgstr "Tüm e-postalar"
+
+msgid "IDS_EMAIL_BODY_ALWAYS_BCC_MYSELF"
+msgstr "Kendimi her zaman Bcc’ye ekle"
+
+msgid "IDS_EMAIL_BODY_BCC"
+msgstr "Gizli"
+
+msgid "IDS_EMAIL_BODY_BLOCK_EMAILS"
+msgstr "E-postaları engelle"
+
+msgid "IDS_EMAIL_BODY_BODY"
+msgstr "Gövde"
+
+msgid "IDS_EMAIL_BODY_CC"
+msgstr "Bilgi"
+
+msgid "IDS_EMAIL_BODY_CC_BCC"
+msgstr "Cc/Bcc"
+
+msgid "IDS_EMAIL_BODY_CHECK_INTERVAL"
+msgstr "Aralığı denetle"
+
+msgid "IDS_EMAIL_BODY_DEFAULT_ACCOUNT"
+msgstr "Varsayılan hesap"
+
+msgid "IDS_EMAIL_BODY_DRAFTS"
+msgstr "Taslaklar"
+
+msgid "IDS_EMAIL_BODY_EMAIL_ACCOUNTS"
+msgstr "E-posta hesapları"
+
+msgid "IDS_EMAIL_BODY_END_TIME"
+msgstr "BitiÅŸ saati"
+
+msgid "IDS_EMAIL_BODY_ENTIRE_EMAIL"
+msgstr "Bütün e-posta"
+
+msgid "IDS_EMAIL_BODY_EXACTLY_THE_SAME_AS"
+msgstr "Aynısı"
+
+msgid "IDS_EMAIL_BODY_EXAMPLE"
+msgstr "Örnek"
+
+msgid "IDS_EMAIL_BODY_FROM_M_SENDER"
+msgstr "Kimden:"
+
+msgid "IDS_EMAIL_BODY_INBOX"
+msgstr "Gelen kutusu"
+
+msgid "IDS_EMAIL_BODY_INCLUDE"
+msgstr "Dahil et"
+
+msgid "IDS_EMAIL_BODY_MATCH_CRITERIA"
+msgstr "EÅŸleÅŸme kriterleri"
+
+msgid "IDS_EMAIL_BODY_NOT_USED"
+msgstr "Kullanılmıyor"
+
+msgid "IDS_EMAIL_BODY_NO_ACCOUNTS"
+msgstr "Hesap yok"
+
+msgid "IDS_EMAIL_BODY_PD_DAYS"
+msgstr "%d gün"
+
+msgid "IDS_EMAIL_BODY_PD_ITEMS"
+msgstr "%d öğe"
+
+msgid "IDS_EMAIL_BODY_PRIORITY"
+msgstr "Öncelik"
+
+msgid "IDS_EMAIL_BODY_RECEIVING_OPTIONS"
+msgstr "Alma seçenekleri"
+
+msgid "IDS_EMAIL_BODY_SECURE_CONNECTION"
+msgstr "Güvenli bağlantı"
+
+msgid "IDS_EMAIL_BODY_SENDING_OPTIONS"
+msgstr "Gönderme seçenekleri"
+
+msgid "IDS_EMAIL_BODY_SENTBOX"
+msgstr "Gönderilenler kutusu"
+
+msgid "IDS_EMAIL_BODY_SERVER_URL"
+msgstr "Sunucu Url'si"
+
+msgid "IDS_EMAIL_BODY_SIGNATURE"
+msgstr "Ä°mza"
+
+msgid "IDS_EMAIL_BODY_SPAMBOX"
+msgstr "Spam kutusu"
+
+msgid "IDS_EMAIL_BODY_START_TIME"
+msgstr "Başlangıç saati"
+
+msgid "IDS_EMAIL_BODY_SYNC_SCHEDULE_TMO"
+msgstr "Program senkronizasyonu"
+
+msgid "IDS_EMAIL_BODY_TRASH"
+msgstr "Çöp kutusu"
+
+msgid "IDS_EMAIL_BODY_WITHOUT_ATTACHMENTS"
+msgstr "Ekler olmadan"
+
+msgid "IDS_EMAIL_BUTTON_GROUP"
+msgstr "Grup"
+
+msgid "IDS_EMAIL_HEADER_ADD_RULES"
+msgstr "Kural ekle"
+
+msgid "IDS_EMAIL_OPT_ATTACH_ITEMS"
+msgstr "Dosya ekle"
+
+msgid "IDS_EMAIL_OPT_EXCHANGE"
+msgstr "DeÄŸiÅŸim"
+
+msgid "IDS_EMAIL_OPT_FILE"
+msgstr "Dosya"
+
+msgid "IDS_EMAIL_OPT_NAMECARD"
+msgstr "Kartvizit"
+
+msgid "IDS_EMAIL_OPT_OPEN_URL"
+msgstr "URL'yi aç"
+
+msgid "IDS_EMAIL_OPT_SENDER"
+msgstr "Gönderen"
+
+msgid "IDS_EMAIL_OPT_SEND_EMAIL"
+msgstr "E-posta gönder"
+
+msgid "IDS_EMAIL_OPT_UPDATE_EXISTING"
+msgstr "Mevcut kişiyi güncelle"
+
+msgid "IDS_EMAIL_POP_ADD_ACCOUNTS"
+msgstr "Hesapları ekle"
+
+msgid "IDS_EMAIL_POP_DOWNLOADING_ATTACHMENT_ING"
+msgstr "Ek indiriliyor..."
+
+msgid "IDS_EMAIL_POP_INVALID_EMAIL_ADDRESS"
+msgstr "Geçersiz e-posta adresi"
+
+msgid "IDS_EMAIL_POP_LOADING_CONTENTS_ING"
+msgstr "İçerik yükleniyor..."
+
+msgid "IDS_EMAIL_POP_MAXIMUM_NUMBER_OF_ATTACHMENTS_REACHED"
+msgstr "Maksimum ek sayısına ulaşıldı"
+
+msgid "IDS_EMAIL_POP_MOVE_TO_SPAMBOX_Q"
+msgstr "Spam kutusuna taşınsın mı?"
+
+msgid "IDS_EMAIL_POP_NO_RECIPIENTS_ADDED_ENTER_RECIPIENTS"
+msgstr "Alıcı eklenemedi. Alıcı girin"
+
+msgid "IDS_EMAIL_POP_PLEASE_FILL_ALL_THE_MANDATORY_FIELDS"
+msgstr "Lütfen tüm zorunlu alanları doldurun"
+
+msgid "IDS_EMAIL_POP_SAVE_IN_DRAFTS_Q"
+msgstr "Taslaklara kaydedilsin mi?"
+
+msgid "IDS_EMAIL_POP_THERE_IS_NO_ACCOUNT_CREATE_A_NEW_ACCOUNT_FIRST"
+msgstr "Hesap yok. Önce yeni bir hesap oluşturun"
+
+msgid "IDS_EMAIL_POP_TOO_MANY_RECIPIENTS"
+msgstr "Çok fazla alıcı"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_DOWNLOAD"
+msgstr "Ä°ndirilemiyor"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_ENTER_TEXT"
+msgstr "Metin girilemiyor"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_LAUNCH_APPLICATION"
+msgstr "Uygulama başlatılamıyor"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_OPEN_ATTACHMENT"
+msgstr "Ek açılamıyor"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_SAVE_ATTACHMENT"
+msgstr "Ek kaydedilemiyor"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_SAVE_IN_DRAFTS"
+msgstr "Taslaklara kaydedilemiyor"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_SEND_EMAIL"
+msgstr "E-posta gönderilemiyor"
+
+msgid "IDS_EMAIL_POP_UNSUPPORTED_FILE_TYPE"
+msgstr "Desteklenmeyen dosya türü"
+
+msgid "IDS_EMAIL_POP_VALIDATING_ACCOUNT_ING"
+msgstr "Hesap doğrulanıyor..."
+
+msgid "IDS_EMAIL_SK_RESEND"
+msgstr "Tekrar Gönder"
+
+msgid "IDS_EMAIL_BODY_ACCEPT_ALL_SSL_CERTIFICATES"
+msgstr "Tüm SSL sertifikalarını kabul edin"
+
+msgid "IDS_EMAIL_SK3_ACCOUNT_LIST"
+msgstr "Hesap listesi"
+
+msgid "IDS_EMAIL_BODY_USER_ID"
+msgstr "Kullanıcı kimliği"
+
+msgid "IDS_EMAIL_POP_ACCOUNT_ALREADY_REGISTERED"
+msgstr "Hesap zaten kaydedilmiÅŸ"
+
+msgid "IDS_EMAIL_HEADER_ATTACH_FILE"
+msgstr "Dosya ekle"
+
+msgid "IDS_EMAIL_BODY_EXCHANGE_SYNC_SETTINGS_MSG"
+msgstr "Bu uygulamayı etkinleştirerek bu uygulama aktivasyonunun lisans sahiplerine bildirilmesi amacıyla cihaz bilgilerinizin bir kısmının (eşsiz cihaz tanımlayıcı ve model adı) Samsung tarafından saklanacağını, işleneceğini ve kullanılacağını kabul etmiş oluyorsunuz. Samsung tarafından tutulan bilgiler Samsung’un gizlilik politikası uyarınca muhafaza edilen gizlilik politikasının kopyası, isteğe bağlı olarak www.samsung.com'da bulunabilir. Devam edilsin mi?"
+
+msgid "IDS_EMAIL_BODY_FORWARD_WITH_FILES"
+msgstr "Dosyalar ile ilet"
+
+msgid "IDS_EMAIL_BODY_REPLY_WITH_BODY"
+msgstr "Gövde ile yanıtla"
+
+msgid "IDS_EMAIL_BODY_NO_SUBJECT"
+msgstr "Konu yok"
+
+msgid "IDS_EMAIL_BODY_FROM"
+msgstr "Kimden"
+
+msgid "IDS_EMAIL_BODY_NO_ADDRESS"
+msgstr "Adres yok"
+
+msgid "IDS_EMAIL_OPT_RECORD_SOUND"
+msgstr "Ses kaydet"
+
+msgid "IDS_EMAIL_OPT_RECORD_VIDEO"
+msgstr "Video kaydet"
+
+msgid "IDS_EMAIL_OPT_INSERT_IMAGE"
+msgstr "Resim ekle"
+
+msgid "IDS_EMAIL_OPT_ADD_TO_CALENDAR"
+msgstr "Takvime Ekle"
+
+msgid "IDS_EMAIL_OPT_CHANGE_EMAIL_ADDRESS_ABB"
+msgstr "E-posta adresini deÄŸiÅŸtir"
+
+msgid "IDS_EMAIL_OPT_CLIPBOARD"
+msgstr "Pano"
+
+msgid "IDS_EMAIL_OPT_MARKED_AS_UNREAD"
+msgstr "Okunmadı olarak işaretlendi"
+
+msgid "IDS_EMAIL_OPT_VIEW_CONTACT_DETAILS"
+msgstr "Kişi detaylarını göster"
+
+msgid "IDS_EMAIL_POP_SAVED_IN_DRAFTS"
+msgstr "Taslaklara kaydedildi"
+
+msgid "IDS_EMAIL_POP_NETWORK_BUSY"
+msgstr "Åžebeke meÅŸgul"
+
+msgid "IDS_EMAIL_POP_LOGIN_ALLOWED_ONLY_EVERY_PD_MINUTES"
+msgstr "Login allowed only every %d minutes"
+
+msgid "IDS_EMAIL_POP_HOST_NOT_FOUND"
+msgstr "Ana makine bulunamadı"
+
+msgid "IDS_EMAIL_POP_HOST_NOT_REACHABLE"
+msgstr "Ana makine ulaşılamaz"
+
+msgid "IDS_EMAIL_POP_NO_SERVICE"
+msgstr "Servis yok"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_FORWARD_DRM_CONTENTS"
+msgstr "DRM içerikleri iletilemiyor"
+
+msgid "IDS_EMAIL_POP_BLOCKED"
+msgstr "Engellendi"
+
+msgid "IDS_EMAIL_POP_1_EMAIL_SELECTED"
+msgstr "1 e-posta seçildi"
+
+msgid "IDS_EMAIL_POP_PD_EMAILS_SELECTED"
+msgstr "%d e-posta seçildi"
+
+msgid "IDS_EMAIL_POP_1_RECIPIENT_SELECTED"
+msgstr "1 alıcı seçildi"
+
+msgid "IDS_EMAIL_POP_PD_RECIPIENTS_SELECTED"
+msgstr "%d alıcı seçildi"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_ADD_ACCOUNT"
+msgstr "Hesaba eklenemiyor"
+
+msgid "IDS_EMAIL_SK3_MOVE_HERE"
+msgstr "Buraya taşı"
+
diff --git a/po/update-po.sh b/po/update-po.sh
new file mode 100755
index 0000000..665dd9e
--- /dev/null
+++ b/po/update-po.sh
@@ -0,0 +1,58 @@
+#!/bin/sh
+
+PACKAGE=email
+SRCROOT=..
+POTFILES=POTFILES.in
+
+#ALL_LINGUAS= "am az be ca cs da de el en_CA en_GB en_US es et fi fr hr hu it ja ko lv mk ml ms nb ne nl pa pl pt pt_BR ru rw sk sl sr sr@Latn sv ta tr uk vi zh_CN zh_TW ko_KR"
+#ALL_LINGUAS="en_US en_GB ja ko zh_CN"
+#ALL_LINGUAS="en_US"
+
+XGETTEXT=/usr/bin/xgettext
+MSGMERGE=/usr/bin/msgmerge
+
+echo -n "Make ${PACKAGE}.pot"
+if [ ! -e $POTFILES ] ; then
+ echo "$POTFILES not found"
+ exit 1
+fi
+
+$XGETTEXT --default-domain=${PACKAGE} --directory=${SRCROOT} \
+ --add-comments --keyword=_ --keyword=N_ --files-from=$POTFILES \
+&& test ! -f ${PACKAGE}.po \
+ || (rm -f ${PACKAGE}.pot && mv ${PACKAGE}.po ${PACKAGE}.pot)
+
+if [ $? -ne 0 ]; then
+ echo "error"
+ exit 1
+else
+ echo "done"
+fi
+
+for LANG in $ALL_LINGUAS; do
+ echo "$LANG : "
+
+ if [ ! -e $LANG.po ] ; then
+ sed 's/CHARSET/UTF-8/g' ${PACKAGE}.pot > ${LANG}.po
+ echo "${LANG}.po created"
+ else
+ if $MSGMERGE ${LANG}.po ${PACKAGE}.pot -o ${LANG}.new.po ; then
+ if cmp ${LANG}.po ${LANG}.new.po > /dev/null 2>&1; then
+ rm -f ${LANG}.new.po
+ else
+ if mv -f ${LANG}.new.po ${LANG}.po; then
+ echo ""
+ else
+ echo "msgmerge for $LANG.po failed: cannot move $LANG.new.po to $LANG.po" 1>&2
+ rm -f ${LANG}.new.po
+ exit 1
+ fi
+ fi
+ else
+ echo "msgmerge for $LANG failed!"
+ rm -f ${LANG}.new.po
+ fi
+ fi
+ echo ""
+done
+
diff --git a/po/zh_CN.po b/po/zh_CN.po
new file mode 100755
index 0000000..2a43cfb
--- /dev/null
+++ b/po/zh_CN.po
@@ -0,0 +1,465 @@
+msgid "IDS_EMAIL_POP_NO_EMAIL_ADDRESS"
+msgstr "没有电邮地å€"
+
+msgid "IDS_EMAIL_BODY_COMPLETE"
+msgstr "完æˆ"
+
+msgid "IDS_EMAIL_BODY_ACCEPTED_C_PS"
+msgstr "已接收:%s"
+
+msgid "IDS_EMAIL_BODY_DECLINED_C_PS"
+msgstr "å·²å–消:%s"
+
+msgid "IDS_EMAIL_BODY_DOWNLOAD_FULL_MESSAGE"
+msgstr "下载完整信æ¯"
+
+msgid "IDS_EMAIL_BODY_GENERAL_SETTINGS"
+msgstr "基本设置"
+
+msgid "IDS_EMAIL_BODY_TENTATIVE_C_PS"
+msgstr "测试:%s"
+
+msgid "IDS_EMAIL_BODY_WHEN_C_PS"
+msgstr "时间:%s"
+
+msgid "IDS_EMAIL_BODY_WHERE_C_PS"
+msgstr "地点:%s"
+
+msgid "IDS_EMAIL_BUTTON_DECLINE_ABB"
+msgstr "æ‹’ç»"
+
+msgid "IDS_EMAIL_BODY_NO_CONTENTS"
+msgstr "无内容"
+
+msgid "IDS_EMAIL_BODY_ORIGINAL_MESSAGE"
+msgstr "原始信æ¯"
+
+msgid "IDS_EMAIL_HEADER_ACCOUNT_SETTINGS"
+msgstr "å¸æˆ·è®¾ç½®"
+
+msgid "IDS_EMAIL_OPT_BLOCK"
+msgstr "阻止"
+
+msgid "IDS_EMAIL_OPT_MARK_AS_READ"
+msgstr "记为已读"
+
+msgid "IDS_EMAIL_OPT_MARK_AS_UNREAD"
+msgstr "记为未读"
+
+msgid "IDS_EMAIL_OPT_OTHERS"
+msgstr "其它"
+
+msgid "IDS_EMAIL_OPT_UNREAD"
+msgstr "未读"
+
+msgid "IDS_EMAIL_SK_COMPOSE"
+msgstr "编写"
+
+msgid "IDS_EMAIL_HEADER_DOWNLOAD_FAILED"
+msgstr "ä¸èƒ½ä¸‹è½½"
+
+msgid "IDS_EMAIL_OPT_ADD_TO_CONTACT"
+msgstr "添加到è”系人"
+
+msgid "IDS_EMAIL_OPT_VOICE_CALL"
+msgstr "语音通è¯"
+
+msgid "IDS_EMAIL_BODY_ACCOUNT_NAME"
+msgstr "å¸æˆ·å称"
+
+msgid "IDS_EMAIL_BODY_ATTACHMENTS"
+msgstr "附件"
+
+msgid "IDS_EMAIL_BODY_FROM_C"
+msgstr "由:"
+
+msgid "IDS_EMAIL_BODY_IMAP4_SERVER"
+msgstr "IMAP4 æœåŠ¡å™¨"
+
+msgid "IDS_EMAIL_BODY_INCLUDES"
+msgstr "包括"
+
+msgid "IDS_EMAIL_BODY_INCOMING_PORT"
+msgstr "接收端å£"
+
+msgid "IDS_EMAIL_BODY_INCOMING_SERVER"
+msgstr "接收æœåŠ¡å™¨"
+
+msgid "IDS_EMAIL_BODY_IN_PD_MINUTES"
+msgstr "在%d分钟内"
+
+msgid "IDS_EMAIL_BODY_KEEP_IN_SERVER"
+msgstr "ä¿å­˜åœ¨æœåŠ¡å™¨ä¸­"
+
+msgid "IDS_EMAIL_BODY_NO_TEXT"
+msgstr "无文本"
+
+msgid "IDS_EMAIL_BODY_OUTGOING_PORT"
+msgstr "呼出端å£"
+
+msgid "IDS_EMAIL_BODY_OUTGOING_SERVER"
+msgstr "å‘é€æœåŠ¡å™¨"
+
+msgid "IDS_EMAIL_BODY_PD_EMAILS"
+msgstr "%d电å­é‚®ä»¶"
+
+msgid "IDS_EMAIL_BODY_POP3_SERVER"
+msgstr "POP3 æœåŠ¡å™¨"
+
+msgid "IDS_EMAIL_BODY_RECENT"
+msgstr "最近"
+
+msgid "IDS_EMAIL_BODY_RETRIEVING_OPTIONS"
+msgstr "å–回选项"
+
+msgid "IDS_EMAIL_BODY_RE_C"
+msgstr "回å¤:"
+
+msgid "IDS_EMAIL_BODY_SENT_C"
+msgstr "å·²å‘é€ï¼š"
+
+msgid "IDS_EMAIL_BODY_SENT_FROM_SAMSUNG_MOBILE"
+msgstr "已从三星手机å‘é€"
+
+msgid "IDS_EMAIL_BODY_USER_PASSWORD"
+msgstr "用户密ç "
+
+msgid "IDS_EMAIL_HEADER_EDIT_RULES"
+msgstr "编辑规则"
+
+msgid "IDS_EMAIL_HEADER_EMAIL_SETTINGS"
+msgstr "电邮设置"
+
+msgid "IDS_EMAIL_HEADER_MAILBOXES"
+msgstr "邮箱"
+
+msgid "IDS_EMAIL_POP_ALERT"
+msgstr "æ示音"
+
+msgid "IDS_EMAIL_POP_FILE_ALREADY_EXISTS"
+msgstr "文件已存在"
+
+msgid "IDS_EMAIL_POP_NO_SENDER"
+msgstr "æ— å‘件人"
+
+msgid "IDS_EMAIL_POP_SUCCEEDED"
+msgstr "æˆåŠŸ"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_ATTACH_MAXIMUM_NUMBER_OF_FILES_IS_PD"
+msgstr "无法附加。最大文件数é‡æ˜¯ %d"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_ATTACH_MAXIMUM_SIZE_OF_FILES_IS_PD_KB"
+msgstr "无法附加。最大文件大å°æ˜¯ %d KB"
+
+msgid "IDS_EMAIL_POP_VALIDATION_FAILED"
+msgstr "确认失败"
+
+msgid "IDS_EMAIL_SK_REPLY_ALL"
+msgstr "回å¤å…¨éƒ¨"
+
+msgid "IDS_EMAIL_BODY_1_ITEM"
+msgstr "1个"
+
+msgid "IDS_EMAIL_BODY_ADD_MY_NAMECARD"
+msgstr "添加我的å片"
+
+msgid "IDS_EMAIL_BODY_ADD_SIGNATURE"
+msgstr "添加签å"
+
+msgid "IDS_EMAIL_BODY_ALL_EMAILS"
+msgstr "全部电邮"
+
+msgid "IDS_EMAIL_BODY_ALWAYS_BCC_MYSELF"
+msgstr "总是密é€ç»™è‡ªå·±"
+
+msgid "IDS_EMAIL_BODY_BCC"
+msgstr "æš—é€"
+
+msgid "IDS_EMAIL_BODY_BLOCK_EMAILS"
+msgstr "阻止电å­é‚®ä»¶"
+
+msgid "IDS_EMAIL_BODY_BODY"
+msgstr "正文"
+
+msgid "IDS_EMAIL_BODY_CC"
+msgstr "抄é€"
+
+msgid "IDS_EMAIL_BODY_CC_BCC"
+msgstr "抄é€/密é€"
+
+msgid "IDS_EMAIL_BODY_CHECK_INTERVAL"
+msgstr "检查时间间隔"
+
+msgid "IDS_EMAIL_BODY_DEFAULT_ACCOUNT"
+msgstr "预置å¸æˆ·"
+
+msgid "IDS_EMAIL_BODY_DRAFTS"
+msgstr "è‰ç¨¿ç®±"
+
+msgid "IDS_EMAIL_BODY_EMAIL_ACCOUNTS"
+msgstr "电å­é‚®ä»¶å¸æˆ·"
+
+msgid "IDS_EMAIL_BODY_END_TIME"
+msgstr "结æŸæ—¶é—´"
+
+msgid "IDS_EMAIL_BODY_ENTIRE_EMAIL"
+msgstr "完整电å­é‚®ä»¶"
+
+msgid "IDS_EMAIL_BODY_EXACTLY_THE_SAME_AS"
+msgstr "完全一样"
+
+msgid "IDS_EMAIL_BODY_EXAMPLE"
+msgstr "举例"
+
+msgid "IDS_EMAIL_BODY_FROM_M_SENDER"
+msgstr "从:"
+
+msgid "IDS_EMAIL_BODY_INBOX"
+msgstr "收件箱"
+
+msgid "IDS_EMAIL_BODY_INCLUDE"
+msgstr "包括"
+
+msgid "IDS_EMAIL_BODY_MATCH_CRITERIA"
+msgstr "匹é…标准"
+
+msgid "IDS_EMAIL_BODY_NOT_USED"
+msgstr "未使用"
+
+msgid "IDS_EMAIL_BODY_NO_ACCOUNTS"
+msgstr "没有å¸æˆ·"
+
+msgid "IDS_EMAIL_BODY_PD_DAYS"
+msgstr "%d 天"
+
+msgid "IDS_EMAIL_BODY_PD_ITEMS"
+msgstr "%d个"
+
+msgid "IDS_EMAIL_BODY_PRIORITY"
+msgstr "优先级"
+
+msgid "IDS_EMAIL_BODY_RECEIVING_OPTIONS"
+msgstr "接收选项"
+
+msgid "IDS_EMAIL_BODY_SECURE_CONNECTION"
+msgstr "安全连接"
+
+msgid "IDS_EMAIL_BODY_SENDING_OPTIONS"
+msgstr "å‘é€é€‰é¡¹"
+
+msgid "IDS_EMAIL_BODY_SENTBOX"
+msgstr "å·²å‘件箱"
+
+msgid "IDS_EMAIL_BODY_SERVER_URL"
+msgstr "æœåŠ¡å™¨ç½‘å€"
+
+msgid "IDS_EMAIL_BODY_SIGNATURE"
+msgstr "ç­¾å"
+
+msgid "IDS_EMAIL_BODY_SPAMBOX"
+msgstr "垃圾箱"
+
+msgid "IDS_EMAIL_BODY_START_TIME"
+msgstr "开始时间"
+
+msgid "IDS_EMAIL_BODY_SYNC_SCHEDULE_TMO"
+msgstr "åŒæ­¥è®¡åˆ’"
+
+msgid "IDS_EMAIL_BODY_TRASH"
+msgstr "垃圾"
+
+msgid "IDS_EMAIL_BODY_WITHOUT_ATTACHMENTS"
+msgstr "ä¸å«é™„件"
+
+msgid "IDS_EMAIL_BUTTON_GROUP"
+msgstr "分组"
+
+msgid "IDS_EMAIL_HEADER_ADD_RULES"
+msgstr "添加规则"
+
+msgid "IDS_EMAIL_OPT_ATTACH_ITEMS"
+msgstr "附加项目"
+
+msgid "IDS_EMAIL_OPT_EXCHANGE"
+msgstr "æ›´æ¢"
+
+msgid "IDS_EMAIL_OPT_FILE"
+msgstr "文件"
+
+msgid "IDS_EMAIL_OPT_NAMECARD"
+msgstr "è”系人"
+
+msgid "IDS_EMAIL_OPT_OPEN_URL"
+msgstr "打开网å€"
+
+msgid "IDS_EMAIL_OPT_SENDER"
+msgstr "å‘件人"
+
+msgid "IDS_EMAIL_OPT_SEND_EMAIL"
+msgstr "å‘é€é‚®ä»¶"
+
+msgid "IDS_EMAIL_OPT_UPDATE_EXISTING"
+msgstr "更新现存"
+
+msgid "IDS_EMAIL_POP_ADD_ACCOUNTS"
+msgstr "添加å¸æˆ·"
+
+msgid "IDS_EMAIL_POP_DOWNLOADING_ATTACHMENT_ING"
+msgstr "正在下载附件…"
+
+msgid "IDS_EMAIL_POP_INVALID_EMAIL_ADDRESS"
+msgstr "电å­é‚®ä»¶åœ°å€æ— æ•ˆ"
+
+msgid "IDS_EMAIL_POP_LOADING_CONTENTS_ING"
+msgstr "正在加载内容…"
+
+msgid "IDS_EMAIL_POP_MAXIMUM_NUMBER_OF_ATTACHMENTS_REACHED"
+msgstr "已达附件最大数é‡"
+
+msgid "IDS_EMAIL_POP_MOVE_TO_SPAMBOX_Q"
+msgstr "移动到垃圾箱?"
+
+msgid "IDS_EMAIL_POP_NO_RECIPIENTS_ADDED_ENTER_RECIPIENTS"
+msgstr "没有添加收件人,请输入è”系人"
+
+msgid "IDS_EMAIL_POP_PLEASE_FILL_ALL_THE_MANDATORY_FIELDS"
+msgstr "请填写所有必填字段"
+
+msgid "IDS_EMAIL_POP_SAVE_IN_DRAFTS_Q"
+msgstr "ä¿å­˜åˆ°è‰ç¨¿ç®±ï¼Ÿ"
+
+msgid "IDS_EMAIL_POP_THERE_IS_NO_ACCOUNT_CREATE_A_NEW_ACCOUNT_FIRST"
+msgstr "没有å¸æˆ·ã€‚ 请先创建新å¸æˆ·"
+
+msgid "IDS_EMAIL_POP_TOO_MANY_RECIPIENTS"
+msgstr "太多接收人"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_DOWNLOAD"
+msgstr "无法下载"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_ENTER_TEXT"
+msgstr "无法输入文本"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_LAUNCH_APPLICATION"
+msgstr "无法å¯åŠ¨åº”用程åº"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_OPEN_ATTACHMENT"
+msgstr "无法打开附件"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_SAVE_ATTACHMENT"
+msgstr "无法ä¿å­˜é™„件"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_SAVE_IN_DRAFTS"
+msgstr "无法ä¿å­˜åˆ°è‰ç¨¿ç®±"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_SEND_EMAIL"
+msgstr "无法å‘é€ç”µå­é‚®ä»¶"
+
+msgid "IDS_EMAIL_POP_UNSUPPORTED_FILE_TYPE"
+msgstr "ä¸æ”¯æŒçš„文件类型"
+
+msgid "IDS_EMAIL_POP_VALIDATING_ACCOUNT_ING"
+msgstr "å¸æˆ·ç¡®è®¤ä¸­â€¦"
+
+msgid "IDS_EMAIL_SK_RESEND"
+msgstr "é‡æ–°å‘é€"
+
+msgid "IDS_EMAIL_BODY_ACCEPT_ALL_SSL_CERTIFICATES"
+msgstr "接å—全部SSLè¯ä¹¦"
+
+msgid "IDS_EMAIL_SK3_ACCOUNT_LIST"
+msgstr "å¸æˆ·åˆ—表"
+
+msgid "IDS_EMAIL_BODY_USER_ID"
+msgstr "用户ID"
+
+msgid "IDS_EMAIL_POP_ACCOUNT_ALREADY_REGISTERED"
+msgstr "已注册å¸æˆ·"
+
+msgid "IDS_EMAIL_HEADER_ATTACH_FILE"
+msgstr "附加文件"
+
+msgid "IDS_EMAIL_BODY_EXCHANGE_SYNC_SETTINGS_MSG"
+msgstr "激活此应用程åºï¼Œè¡¨ç¤ºæ‚¨æŽ¥å—三星ä¿å­˜ã€å¤„ç†å’Œä½¿ç”¨æ‚¨çš„部分设备数æ®ï¼ˆå”¯ä¸€è®¾å¤‡æ ‡è¯†ç¬¦å’Œæœºåž‹å称),用于å‘应用程åºè½¯ä»¶æŽˆæƒæ–¹æŠ¥å‘Šåº”用程åºæ¿€æ´»æƒ…况。三星将严格根æ®ä¸‰æ˜Ÿéšç§æ”¿ç­–处ç†æ•°æ®ï¼Œä¸‰æ˜Ÿéšç§æ”¿ç­–æ供于 www.samsung.com。是å¦ç»§ç»­ï¼Ÿ"
+
+msgid "IDS_EMAIL_BODY_FORWARD_WITH_FILES"
+msgstr "转å‘附件"
+
+msgid "IDS_EMAIL_BODY_REPLY_WITH_BODY"
+msgstr "回å¤åŒ…括正文"
+
+msgid "IDS_EMAIL_BODY_NO_SUBJECT"
+msgstr "没有主题"
+
+msgid "IDS_EMAIL_BODY_FROM"
+msgstr "å‘件人"
+
+msgid "IDS_EMAIL_BODY_NO_ADDRESS"
+msgstr "无地å€"
+
+msgid "IDS_EMAIL_OPT_RECORD_SOUND"
+msgstr "录音"
+
+msgid "IDS_EMAIL_OPT_RECORD_VIDEO"
+msgstr "æ‹æ‘„录åƒ"
+
+msgid "IDS_EMAIL_OPT_INSERT_IMAGE"
+msgstr "æ’入图åƒ"
+
+msgid "IDS_EMAIL_OPT_ADD_TO_CALENDAR"
+msgstr "添加至日历"
+
+msgid "IDS_EMAIL_OPT_CHANGE_EMAIL_ADDRESS_ABB"
+msgstr "更改电å­é‚®ä»¶åœ°å€"
+
+msgid "IDS_EMAIL_OPT_CLIPBOARD"
+msgstr "剪贴æ¿"
+
+msgid "IDS_EMAIL_OPT_MARKED_AS_UNREAD"
+msgstr "已标记为未读"
+
+msgid "IDS_EMAIL_OPT_VIEW_CONTACT_DETAILS"
+msgstr "查看è”系人详细信æ¯"
+
+msgid "IDS_EMAIL_POP_SAVED_IN_DRAFTS"
+msgstr "å·²ä¿å­˜åˆ°è‰ç¨¿ç®±"
+
+msgid "IDS_EMAIL_POP_NETWORK_BUSY"
+msgstr "网络ç¹å¿™"
+
+msgid "IDS_EMAIL_POP_LOGIN_ALLOWED_ONLY_EVERY_PD_MINUTES"
+msgstr "ä»…å…许æ¯%d分钟登录一次"
+
+msgid "IDS_EMAIL_POP_HOST_NOT_FOUND"
+msgstr "未找到主机"
+
+msgid "IDS_EMAIL_POP_HOST_NOT_REACHABLE"
+msgstr "无法访问主机"
+
+msgid "IDS_EMAIL_POP_NO_SERVICE"
+msgstr "æ— æœåŠ¡"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_FORWARD_DRM_CONTENTS"
+msgstr "无法转å‘DRM内容"
+
+msgid "IDS_EMAIL_POP_BLOCKED"
+msgstr "已阻止"
+
+msgid "IDS_EMAIL_POP_1_EMAIL_SELECTED"
+msgstr "已选中 1 å°ç”µå­é‚®ä»¶"
+
+msgid "IDS_EMAIL_POP_PD_EMAILS_SELECTED"
+msgstr "已选择 %d å°ç”µå­é‚®ä»¶"
+
+msgid "IDS_EMAIL_POP_1_RECIPIENT_SELECTED"
+msgstr "已选择1个收件人"
+
+msgid "IDS_EMAIL_POP_PD_RECIPIENTS_SELECTED"
+msgstr "已选择%d个收件人"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_ADD_ACCOUNT"
+msgstr "无法添加å¸æˆ·"
+
+msgid "IDS_EMAIL_SK3_MOVE_HERE"
+msgstr "移动到这里"
+
diff --git a/po/zh_HK.po b/po/zh_HK.po
new file mode 100755
index 0000000..cbe511e
--- /dev/null
+++ b/po/zh_HK.po
@@ -0,0 +1,465 @@
+msgid "IDS_EMAIL_POP_NO_EMAIL_ADDRESS"
+msgstr "ç„¡é›»å­éƒµä»¶åœ°å€"
+
+msgid "IDS_EMAIL_BODY_COMPLETE"
+msgstr "完æˆ"
+
+msgid "IDS_EMAIL_BODY_ACCEPTED_C_PS"
+msgstr "已接å—: %s"
+
+msgid "IDS_EMAIL_BODY_DECLINED_C_PS"
+msgstr "已拒絕: %s"
+
+msgid "IDS_EMAIL_BODY_DOWNLOAD_FULL_MESSAGE"
+msgstr "下載完整訊æ¯"
+
+msgid "IDS_EMAIL_BODY_GENERAL_SETTINGS"
+msgstr "一般設定"
+
+msgid "IDS_EMAIL_BODY_TENTATIVE_C_PS"
+msgstr "暫定: %s"
+
+msgid "IDS_EMAIL_BODY_WHEN_C_PS"
+msgstr "時間: %s"
+
+msgid "IDS_EMAIL_BODY_WHERE_C_PS"
+msgstr "地點: %s"
+
+msgid "IDS_EMAIL_BUTTON_DECLINE_ABB"
+msgstr "拒絕"
+
+msgid "IDS_EMAIL_BODY_NO_CONTENTS"
+msgstr "無內容"
+
+msgid "IDS_EMAIL_BODY_ORIGINAL_MESSAGE"
+msgstr "原有訊æ¯"
+
+msgid "IDS_EMAIL_HEADER_ACCOUNT_SETTINGS"
+msgstr "帳戶設定"
+
+msgid "IDS_EMAIL_OPT_BLOCK"
+msgstr "å°éŽ–"
+
+msgid "IDS_EMAIL_OPT_MARK_AS_READ"
+msgstr "標記為已讀"
+
+msgid "IDS_EMAIL_OPT_MARK_AS_UNREAD"
+msgstr "標記為未讀"
+
+msgid "IDS_EMAIL_OPT_OTHERS"
+msgstr "其他"
+
+msgid "IDS_EMAIL_OPT_UNREAD"
+msgstr "未讀"
+
+msgid "IDS_EMAIL_SK_COMPOSE"
+msgstr "撰寫"
+
+msgid "IDS_EMAIL_HEADER_DOWNLOAD_FAILED"
+msgstr "ä¸èƒ½ä¸‹è¼‰"
+
+msgid "IDS_EMAIL_OPT_ADD_TO_CONTACT"
+msgstr "加到è¯çµ¡äºº"
+
+msgid "IDS_EMAIL_OPT_VOICE_CALL"
+msgstr "語音通話"
+
+msgid "IDS_EMAIL_BODY_ACCOUNT_NAME"
+msgstr "帳戶å稱"
+
+msgid "IDS_EMAIL_BODY_ATTACHMENTS"
+msgstr "附件"
+
+msgid "IDS_EMAIL_BODY_FROM_C"
+msgstr "由:"
+
+msgid "IDS_EMAIL_BODY_IMAP4_SERVER"
+msgstr "IMAP4 伺æœå™¨"
+
+msgid "IDS_EMAIL_BODY_INCLUDES"
+msgstr "包括"
+
+msgid "IDS_EMAIL_BODY_INCOMING_PORT"
+msgstr "接收端å£"
+
+msgid "IDS_EMAIL_BODY_INCOMING_SERVER"
+msgstr "å…§é€ä¼ºæœå™¨"
+
+msgid "IDS_EMAIL_BODY_IN_PD_MINUTES"
+msgstr "在 %d 分é˜å…§"
+
+msgid "IDS_EMAIL_BODY_KEEP_IN_SERVER"
+msgstr "ä¿å­˜åœ¨ä¼ºæœå™¨ä¸­"
+
+msgid "IDS_EMAIL_BODY_NO_TEXT"
+msgstr "無文字"
+
+msgid "IDS_EMAIL_BODY_OUTGOING_PORT"
+msgstr "外寄端å£"
+
+msgid "IDS_EMAIL_BODY_OUTGOING_SERVER"
+msgstr "外寄伺æœå™¨"
+
+msgid "IDS_EMAIL_BODY_PD_EMAILS"
+msgstr "%d個電郵"
+
+msgid "IDS_EMAIL_BODY_POP3_SERVER"
+msgstr "POP3 伺æœå™¨"
+
+msgid "IDS_EMAIL_BODY_RECENT"
+msgstr "最近"
+
+msgid "IDS_EMAIL_BODY_RETRIEVING_OPTIONS"
+msgstr "å–回é¸é …"
+
+msgid "IDS_EMAIL_BODY_RE_C"
+msgstr "回覆:"
+
+msgid "IDS_EMAIL_BODY_SENT_C"
+msgstr "已發é€ï¼š"
+
+msgid "IDS_EMAIL_BODY_SENT_FROM_SAMSUNG_MOBILE"
+msgstr "從三星手機發é€"
+
+msgid "IDS_EMAIL_BODY_USER_PASSWORD"
+msgstr "用戶密碼"
+
+msgid "IDS_EMAIL_HEADER_EDIT_RULES"
+msgstr "編輯è¦å‰‡"
+
+msgid "IDS_EMAIL_HEADER_EMAIL_SETTINGS"
+msgstr "é›»å­éƒµä»¶è¨­å®š"
+
+msgid "IDS_EMAIL_HEADER_MAILBOXES"
+msgstr "郵箱"
+
+msgid "IDS_EMAIL_POP_ALERT"
+msgstr "æ醒"
+
+msgid "IDS_EMAIL_POP_FILE_ALREADY_EXISTS"
+msgstr "檔案已存在"
+
+msgid "IDS_EMAIL_POP_NO_SENDER"
+msgstr "無寄件人"
+
+msgid "IDS_EMAIL_POP_SUCCEEDED"
+msgstr "å·²æˆåŠŸ"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_ATTACH_MAXIMUM_NUMBER_OF_FILES_IS_PD"
+msgstr "無法附加。最大檔案數é‡æ˜¯ ï¼…d"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_ATTACH_MAXIMUM_SIZE_OF_FILES_IS_PD_KB"
+msgstr "無法附加。檔案最大為%d KB"
+
+msgid "IDS_EMAIL_POP_VALIDATION_FAILED"
+msgstr "驗證失敗"
+
+msgid "IDS_EMAIL_SK_REPLY_ALL"
+msgstr "全部回覆"
+
+msgid "IDS_EMAIL_BODY_1_ITEM"
+msgstr "1個項目"
+
+msgid "IDS_EMAIL_BODY_ADD_MY_NAMECARD"
+msgstr "加入我的å片"
+
+msgid "IDS_EMAIL_BODY_ADD_SIGNATURE"
+msgstr "加入簽å"
+
+msgid "IDS_EMAIL_BODY_ALL_EMAILS"
+msgstr "全部電å­éƒµä»¶"
+
+msgid "IDS_EMAIL_BODY_ALWAYS_BCC_MYSELF"
+msgstr "總是密é€çµ¦è‡ªå·±"
+
+msgid "IDS_EMAIL_BODY_BCC"
+msgstr "密é€"
+
+msgid "IDS_EMAIL_BODY_BLOCK_EMAILS"
+msgstr "å°éŽ–é›»å­éƒµä»¶"
+
+msgid "IDS_EMAIL_BODY_BODY"
+msgstr "正文"
+
+msgid "IDS_EMAIL_BODY_CC"
+msgstr "抄é€"
+
+msgid "IDS_EMAIL_BODY_CC_BCC"
+msgstr "抄é€/密é€"
+
+msgid "IDS_EMAIL_BODY_CHECK_INTERVAL"
+msgstr "檢查時間間隔"
+
+msgid "IDS_EMAIL_BODY_DEFAULT_ACCOUNT"
+msgstr "é è¨­å¸³æˆ¶"
+
+msgid "IDS_EMAIL_BODY_DRAFTS"
+msgstr "è‰ç¨¿åŒ£"
+
+msgid "IDS_EMAIL_BODY_EMAIL_ACCOUNTS"
+msgstr "é›»å­éƒµä»¶å¸³æˆ¶"
+
+msgid "IDS_EMAIL_BODY_END_TIME"
+msgstr "çµæŸæ™‚é–“"
+
+msgid "IDS_EMAIL_BODY_ENTIRE_EMAIL"
+msgstr "完整電郵"
+
+msgid "IDS_EMAIL_BODY_EXACTLY_THE_SAME_AS"
+msgstr "完全相åŒæ–¼"
+
+msgid "IDS_EMAIL_BODY_EXAMPLE"
+msgstr "範例"
+
+msgid "IDS_EMAIL_BODY_FROM_M_SENDER"
+msgstr "由:"
+
+msgid "IDS_EMAIL_BODY_INBOX"
+msgstr "收件匣"
+
+msgid "IDS_EMAIL_BODY_INCLUDE"
+msgstr "包括"
+
+msgid "IDS_EMAIL_BODY_MATCH_CRITERIA"
+msgstr "符åˆæ¨™æº–"
+
+msgid "IDS_EMAIL_BODY_NOT_USED"
+msgstr "未有使用"
+
+msgid "IDS_EMAIL_BODY_NO_ACCOUNTS"
+msgstr "無帳戶"
+
+msgid "IDS_EMAIL_BODY_PD_DAYS"
+msgstr "%d 天"
+
+msgid "IDS_EMAIL_BODY_PD_ITEMS"
+msgstr "%d 個項目"
+
+msgid "IDS_EMAIL_BODY_PRIORITY"
+msgstr "優先次åº"
+
+msgid "IDS_EMAIL_BODY_RECEIVING_OPTIONS"
+msgstr "接收é¸é …"
+
+msgid "IDS_EMAIL_BODY_SECURE_CONNECTION"
+msgstr "安全連接"
+
+msgid "IDS_EMAIL_BODY_SENDING_OPTIONS"
+msgstr "發é€é¸é …"
+
+msgid "IDS_EMAIL_BODY_SENTBOX"
+msgstr "寄件備份匣"
+
+msgid "IDS_EMAIL_BODY_SERVER_URL"
+msgstr "伺æœå™¨ç¶²å€"
+
+msgid "IDS_EMAIL_BODY_SIGNATURE"
+msgstr "ç°½å"
+
+msgid "IDS_EMAIL_BODY_SPAMBOX"
+msgstr "垃圾箱"
+
+msgid "IDS_EMAIL_BODY_START_TIME"
+msgstr "開始時間"
+
+msgid "IDS_EMAIL_BODY_SYNC_SCHEDULE_TMO"
+msgstr "åŒæ­¥æ—¥ç¨‹"
+
+msgid "IDS_EMAIL_BODY_TRASH"
+msgstr "垃圾"
+
+msgid "IDS_EMAIL_BODY_WITHOUT_ATTACHMENTS"
+msgstr "無附件"
+
+msgid "IDS_EMAIL_BUTTON_GROUP"
+msgstr "分組"
+
+msgid "IDS_EMAIL_HEADER_ADD_RULES"
+msgstr "加入è¦å‰‡"
+
+msgid "IDS_EMAIL_OPT_ATTACH_ITEMS"
+msgstr "附加項目"
+
+msgid "IDS_EMAIL_OPT_EXCHANGE"
+msgstr "Exchange"
+
+msgid "IDS_EMAIL_OPT_FILE"
+msgstr "檔案"
+
+msgid "IDS_EMAIL_OPT_NAMECARD"
+msgstr "å片"
+
+msgid "IDS_EMAIL_OPT_OPEN_URL"
+msgstr "開啟網å€"
+
+msgid "IDS_EMAIL_OPT_SENDER"
+msgstr "寄件人"
+
+msgid "IDS_EMAIL_OPT_SEND_EMAIL"
+msgstr "發é€é›»å­éƒµä»¶"
+
+msgid "IDS_EMAIL_OPT_UPDATE_EXISTING"
+msgstr "æ›´æ–°ç¾æœ‰çš„"
+
+msgid "IDS_EMAIL_POP_ADD_ACCOUNTS"
+msgstr "加入帳戶"
+
+msgid "IDS_EMAIL_POP_DOWNLOADING_ATTACHMENT_ING"
+msgstr "正在下載附件..."
+
+msgid "IDS_EMAIL_POP_INVALID_EMAIL_ADDRESS"
+msgstr "無效電å­éƒµä»¶åœ°å€"
+
+msgid "IDS_EMAIL_POP_LOADING_CONTENTS_ING"
+msgstr "正在載入內容..."
+
+msgid "IDS_EMAIL_POP_MAXIMUM_NUMBER_OF_ATTACHMENTS_REACHED"
+msgstr "附件數目已é”上é™"
+
+msgid "IDS_EMAIL_POP_MOVE_TO_SPAMBOX_Q"
+msgstr "è¦ç§»å‹•åˆ°åžƒåœ¾ç®±å—Žï¼Ÿ"
+
+msgid "IDS_EMAIL_POP_NO_RECIPIENTS_ADDED_ENTER_RECIPIENTS"
+msgstr "未加入收件人。請輸入收件人"
+
+msgid "IDS_EMAIL_POP_PLEASE_FILL_ALL_THE_MANDATORY_FIELDS"
+msgstr "請填寫所有必填欄ä½"
+
+msgid "IDS_EMAIL_POP_SAVE_IN_DRAFTS_Q"
+msgstr "è¦å„²å­˜åˆ°è‰ç¨¿åŒ£å—Žï¼Ÿ"
+
+msgid "IDS_EMAIL_POP_THERE_IS_NO_ACCOUNT_CREATE_A_NEW_ACCOUNT_FIRST"
+msgstr "沒有帳戶。請先建立一個新帳戶"
+
+msgid "IDS_EMAIL_POP_TOO_MANY_RECIPIENTS"
+msgstr "太多收件人"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_DOWNLOAD"
+msgstr "無法下載"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_ENTER_TEXT"
+msgstr "無法輸入文字"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_LAUNCH_APPLICATION"
+msgstr "無法啟動應用程å¼"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_OPEN_ATTACHMENT"
+msgstr "無法開啟附件"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_SAVE_ATTACHMENT"
+msgstr "無法儲存附件"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_SAVE_IN_DRAFTS"
+msgstr "無法儲存到è‰ç¨¿åŒ£"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_SEND_EMAIL"
+msgstr "無法發é€é›»å­éƒµä»¶"
+
+msgid "IDS_EMAIL_POP_UNSUPPORTED_FILE_TYPE"
+msgstr "ä¸æ”¯æ´çš„檔案類型"
+
+msgid "IDS_EMAIL_POP_VALIDATING_ACCOUNT_ING"
+msgstr "正在確èªå¸³æˆ¶..."
+
+msgid "IDS_EMAIL_SK_RESEND"
+msgstr "é‡æ–°ç™¼é€"
+
+msgid "IDS_EMAIL_BODY_ACCEPT_ALL_SSL_CERTIFICATES"
+msgstr "接å—所有SSL證書"
+
+msgid "IDS_EMAIL_SK3_ACCOUNT_LIST"
+msgstr "帳戶清單"
+
+msgid "IDS_EMAIL_BODY_USER_ID"
+msgstr "用戶 ID"
+
+msgid "IDS_EMAIL_POP_ACCOUNT_ALREADY_REGISTERED"
+msgstr "帳戶已註冊"
+
+msgid "IDS_EMAIL_HEADER_ATTACH_FILE"
+msgstr "附加檔案"
+
+msgid "IDS_EMAIL_BODY_EXCHANGE_SYNC_SETTINGS_MSG"
+msgstr "通éŽå•Ÿå‹•æ­¤æ‡‰ç”¨ç¨‹å¼ï¼Œæ‚¨æŽ¥å—三星還原ã€è™•ç†åŠä½¿ç”¨éƒ¨åˆ†è£ç½®è³‡æ–™ (唯一的è£ç½® ID 和型號å稱),將該應用程å¼çš„å•Ÿå‹•å‘應用程å¼è»Ÿä»¶çš„授權者彙報。三星æŒæœ‰çš„資料將ä¾æ“šä¸‰æ˜Ÿçš„éš±ç§æ¬Šæ”¿ç­–åš´æ ¼è™•ç† (è«‹åƒè¦‹ www.samsung.com) 。è¦ç¹¼çºŒå—Žï¼Ÿ"
+
+msgid "IDS_EMAIL_BODY_FORWARD_WITH_FILES"
+msgstr "連檔案轉寄"
+
+msgid "IDS_EMAIL_BODY_REPLY_WITH_BODY"
+msgstr "以正文回覆"
+
+msgid "IDS_EMAIL_BODY_NO_SUBJECT"
+msgstr "無主題"
+
+msgid "IDS_EMAIL_BODY_FROM"
+msgstr "ç”±"
+
+msgid "IDS_EMAIL_BODY_NO_ADDRESS"
+msgstr "無地å€"
+
+msgid "IDS_EMAIL_OPT_RECORD_SOUND"
+msgstr "錄音"
+
+msgid "IDS_EMAIL_OPT_RECORD_VIDEO"
+msgstr "錄影"
+
+msgid "IDS_EMAIL_OPT_INSERT_IMAGE"
+msgstr "æ’入圖åƒ"
+
+msgid "IDS_EMAIL_OPT_ADD_TO_CALENDAR"
+msgstr "加到日曆"
+
+msgid "IDS_EMAIL_OPT_CHANGE_EMAIL_ADDRESS_ABB"
+msgstr "更改電å­éƒµä»¶åœ°å€"
+
+msgid "IDS_EMAIL_OPT_CLIPBOARD"
+msgstr "剪貼æ¿"
+
+msgid "IDS_EMAIL_OPT_MARKED_AS_UNREAD"
+msgstr "已標記為未讀"
+
+msgid "IDS_EMAIL_OPT_VIEW_CONTACT_DETAILS"
+msgstr "檢視è¯çµ¡äººè©³ç´°è³‡æ–™"
+
+msgid "IDS_EMAIL_POP_SAVED_IN_DRAFTS"
+msgstr "已儲存到è‰ç¨¿åŒ£"
+
+msgid "IDS_EMAIL_POP_NETWORK_BUSY"
+msgstr "網絡ç¹å¿™"
+
+msgid "IDS_EMAIL_POP_LOGIN_ALLOWED_ONLY_EVERY_PD_MINUTES"
+msgstr "Login allowed only every %d minutes"
+
+msgid "IDS_EMAIL_POP_HOST_NOT_FOUND"
+msgstr "找ä¸åˆ°ä¸»æ©Ÿ"
+
+msgid "IDS_EMAIL_POP_HOST_NOT_REACHABLE"
+msgstr "無法到é”主機"
+
+msgid "IDS_EMAIL_POP_NO_SERVICE"
+msgstr "ç„¡æœå‹™"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_FORWARD_DRM_CONTENTS"
+msgstr "無法轉寄DRM內容"
+
+msgid "IDS_EMAIL_POP_BLOCKED"
+msgstr "å·²å°éŽ–"
+
+msgid "IDS_EMAIL_POP_1_EMAIL_SELECTED"
+msgstr "å·²é¸æ“‡ 1 å°é›»å­éƒµä»¶"
+
+msgid "IDS_EMAIL_POP_PD_EMAILS_SELECTED"
+msgstr "å·²é¸æ“‡ %d å°é›»å­éƒµä»¶"
+
+msgid "IDS_EMAIL_POP_1_RECIPIENT_SELECTED"
+msgstr "1個收件人已é¸å–"
+
+msgid "IDS_EMAIL_POP_PD_RECIPIENTS_SELECTED"
+msgstr "%d個收件人已é¸å–"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_ADD_ACCOUNT"
+msgstr "無法加入帳戶"
+
+msgid "IDS_EMAIL_SK3_MOVE_HERE"
+msgstr "移到這裡"
+
diff --git a/po/zh_TW.po b/po/zh_TW.po
new file mode 100755
index 0000000..7dcdde8
--- /dev/null
+++ b/po/zh_TW.po
@@ -0,0 +1,465 @@
+msgid "IDS_EMAIL_POP_NO_EMAIL_ADDRESS"
+msgstr "ç„¡é›»å­éƒµä»¶åœ°å€"
+
+msgid "IDS_EMAIL_BODY_COMPLETE"
+msgstr "完æˆ"
+
+msgid "IDS_EMAIL_BODY_ACCEPTED_C_PS"
+msgstr "已接å—:%s"
+
+msgid "IDS_EMAIL_BODY_DECLINED_C_PS"
+msgstr "拒絕:%s"
+
+msgid "IDS_EMAIL_BODY_DOWNLOAD_FULL_MESSAGE"
+msgstr "下載完整的郵件"
+
+msgid "IDS_EMAIL_BODY_GENERAL_SETTINGS"
+msgstr "一般設定"
+
+msgid "IDS_EMAIL_BODY_TENTATIVE_C_PS"
+msgstr "暫定:%s"
+
+msgid "IDS_EMAIL_BODY_WHEN_C_PS"
+msgstr "時間:%s"
+
+msgid "IDS_EMAIL_BODY_WHERE_C_PS"
+msgstr "地點:%s"
+
+msgid "IDS_EMAIL_BUTTON_DECLINE_ABB"
+msgstr "拒絕"
+
+msgid "IDS_EMAIL_BODY_NO_CONTENTS"
+msgstr "無內容"
+
+msgid "IDS_EMAIL_BODY_ORIGINAL_MESSAGE"
+msgstr "原始郵件"
+
+msgid "IDS_EMAIL_HEADER_ACCOUNT_SETTINGS"
+msgstr "帳號設定"
+
+msgid "IDS_EMAIL_OPT_BLOCK"
+msgstr "å°éŽ–"
+
+msgid "IDS_EMAIL_OPT_MARK_AS_READ"
+msgstr "標記為已讀"
+
+msgid "IDS_EMAIL_OPT_MARK_AS_UNREAD"
+msgstr "標記為未讀"
+
+msgid "IDS_EMAIL_OPT_OTHERS"
+msgstr "其他"
+
+msgid "IDS_EMAIL_OPT_UNREAD"
+msgstr "未讀"
+
+msgid "IDS_EMAIL_SK_COMPOSE"
+msgstr "撰寫"
+
+msgid "IDS_EMAIL_HEADER_DOWNLOAD_FAILED"
+msgstr "無法下載"
+
+msgid "IDS_EMAIL_OPT_ADD_TO_CONTACT"
+msgstr "加到è¯çµ¡äºº"
+
+msgid "IDS_EMAIL_OPT_VOICE_CALL"
+msgstr "語音通話"
+
+msgid "IDS_EMAIL_BODY_ACCOUNT_NAME"
+msgstr "帳號å稱"
+
+msgid "IDS_EMAIL_BODY_ATTACHMENTS"
+msgstr "附件"
+
+msgid "IDS_EMAIL_BODY_FROM_C"
+msgstr "自:"
+
+msgid "IDS_EMAIL_BODY_IMAP4_SERVER"
+msgstr "IMAP4 伺æœå™¨"
+
+msgid "IDS_EMAIL_BODY_INCLUDES"
+msgstr "包括"
+
+msgid "IDS_EMAIL_BODY_INCOMING_PORT"
+msgstr "傳入連接埠"
+
+msgid "IDS_EMAIL_BODY_INCOMING_SERVER"
+msgstr "å…§é€ä¼ºæœå™¨"
+
+msgid "IDS_EMAIL_BODY_IN_PD_MINUTES"
+msgstr "在%d分é˜å¾Œ"
+
+msgid "IDS_EMAIL_BODY_KEEP_IN_SERVER"
+msgstr "ä¿ç•™åœ¨ä¼ºæœå™¨ä¸­"
+
+msgid "IDS_EMAIL_BODY_NO_TEXT"
+msgstr "無文字"
+
+msgid "IDS_EMAIL_BODY_OUTGOING_PORT"
+msgstr "外寄連接埠"
+
+msgid "IDS_EMAIL_BODY_OUTGOING_SERVER"
+msgstr "外寄郵件伺æœå™¨"
+
+msgid "IDS_EMAIL_BODY_PD_EMAILS"
+msgstr "ï¼…d個電å­éƒµä»¶"
+
+msgid "IDS_EMAIL_BODY_POP3_SERVER"
+msgstr "POP3 伺æœå™¨"
+
+msgid "IDS_EMAIL_BODY_RECENT"
+msgstr "最近"
+
+msgid "IDS_EMAIL_BODY_RETRIEVING_OPTIONS"
+msgstr "æ“·å–é¸é …"
+
+msgid "IDS_EMAIL_BODY_RE_C"
+msgstr "收件人:"
+
+msgid "IDS_EMAIL_BODY_SENT_C"
+msgstr "已傳é€ï¼š"
+
+msgid "IDS_EMAIL_BODY_SENT_FROM_SAMSUNG_MOBILE"
+msgstr "從三星手機發é€"
+
+msgid "IDS_EMAIL_BODY_USER_PASSWORD"
+msgstr "使用者密碼"
+
+msgid "IDS_EMAIL_HEADER_EDIT_RULES"
+msgstr "編輯è¦å‰‡"
+
+msgid "IDS_EMAIL_HEADER_EMAIL_SETTINGS"
+msgstr "é›»å­éƒµä»¶è¨­å®š"
+
+msgid "IDS_EMAIL_HEADER_MAILBOXES"
+msgstr "收件匣"
+
+msgid "IDS_EMAIL_POP_ALERT"
+msgstr "æ醒"
+
+msgid "IDS_EMAIL_POP_FILE_ALREADY_EXISTS"
+msgstr "文件已存在"
+
+msgid "IDS_EMAIL_POP_NO_SENDER"
+msgstr "無寄件人"
+
+msgid "IDS_EMAIL_POP_SUCCEEDED"
+msgstr "å·²æˆåŠŸ"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_ATTACH_MAXIMUM_NUMBER_OF_FILES_IS_PD"
+msgstr "無法連接。文件的最大編號為%d個"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_ATTACH_MAXIMUM_SIZE_OF_FILES_IS_PD_KB"
+msgstr "無法附加。最大文件%d KB"
+
+msgid "IDS_EMAIL_POP_VALIDATION_FAILED"
+msgstr "驗證失敗"
+
+msgid "IDS_EMAIL_SK_REPLY_ALL"
+msgstr "全部回覆"
+
+msgid "IDS_EMAIL_BODY_1_ITEM"
+msgstr "1個項目"
+
+msgid "IDS_EMAIL_BODY_ADD_MY_NAMECARD"
+msgstr "加入我的å片"
+
+msgid "IDS_EMAIL_BODY_ADD_SIGNATURE"
+msgstr "加入簽å"
+
+msgid "IDS_EMAIL_BODY_ALL_EMAILS"
+msgstr "全部電å­éƒµä»¶"
+
+msgid "IDS_EMAIL_BODY_ALWAYS_BCC_MYSELF"
+msgstr "總是寄é€å¯†ä»¶å‰¯æœ¬çµ¦è‡ªå·±"
+
+msgid "IDS_EMAIL_BODY_BCC"
+msgstr "密件副本"
+
+msgid "IDS_EMAIL_BODY_BLOCK_EMAILS"
+msgstr "å°éŽ–é›»å­éƒµä»¶"
+
+msgid "IDS_EMAIL_BODY_BODY"
+msgstr "本文"
+
+msgid "IDS_EMAIL_BODY_CC"
+msgstr "副本"
+
+msgid "IDS_EMAIL_BODY_CC_BCC"
+msgstr "副本/密件"
+
+msgid "IDS_EMAIL_BODY_CHECK_INTERVAL"
+msgstr "檢查時間間隔"
+
+msgid "IDS_EMAIL_BODY_DEFAULT_ACCOUNT"
+msgstr "é è¨­å¸³æˆ¶"
+
+msgid "IDS_EMAIL_BODY_DRAFTS"
+msgstr "è‰ç¨¿åŒ£"
+
+msgid "IDS_EMAIL_BODY_EMAIL_ACCOUNTS"
+msgstr "é›»å­éƒµä»¶å¸³æˆ¶"
+
+msgid "IDS_EMAIL_BODY_END_TIME"
+msgstr "çµæŸæ™‚é–“"
+
+msgid "IDS_EMAIL_BODY_ENTIRE_EMAIL"
+msgstr "æ•´å°é›»å­éƒµä»¶"
+
+msgid "IDS_EMAIL_BODY_EXACTLY_THE_SAME_AS"
+msgstr "完全相åŒæ–¼"
+
+msgid "IDS_EMAIL_BODY_EXAMPLE"
+msgstr "範例"
+
+msgid "IDS_EMAIL_BODY_FROM_M_SENDER"
+msgstr "自:"
+
+msgid "IDS_EMAIL_BODY_INBOX"
+msgstr "收件匣"
+
+msgid "IDS_EMAIL_BODY_INCLUDE"
+msgstr "包括"
+
+msgid "IDS_EMAIL_BODY_MATCH_CRITERIA"
+msgstr "符åˆæ¢ä»¶"
+
+msgid "IDS_EMAIL_BODY_NOT_USED"
+msgstr "未使用"
+
+msgid "IDS_EMAIL_BODY_NO_ACCOUNTS"
+msgstr "沒有任何帳戶"
+
+msgid "IDS_EMAIL_BODY_PD_DAYS"
+msgstr "%d 天"
+
+msgid "IDS_EMAIL_BODY_PD_ITEMS"
+msgstr "%d 個項目"
+
+msgid "IDS_EMAIL_BODY_PRIORITY"
+msgstr "優先順åº"
+
+msgid "IDS_EMAIL_BODY_RECEIVING_OPTIONS"
+msgstr "接收é¸é …"
+
+msgid "IDS_EMAIL_BODY_SECURE_CONNECTION"
+msgstr "安全連接"
+
+msgid "IDS_EMAIL_BODY_SENDING_OPTIONS"
+msgstr "傳é€é¸é …"
+
+msgid "IDS_EMAIL_BODY_SENTBOX"
+msgstr "已傳é€è¨Šæ¯"
+
+msgid "IDS_EMAIL_BODY_SERVER_URL"
+msgstr "伺æœå™¨ URL"
+
+msgid "IDS_EMAIL_BODY_SIGNATURE"
+msgstr "ç°½å"
+
+msgid "IDS_EMAIL_BODY_SPAMBOX"
+msgstr "垃圾郵件"
+
+msgid "IDS_EMAIL_BODY_START_TIME"
+msgstr "開始時間"
+
+msgid "IDS_EMAIL_BODY_SYNC_SCHEDULE_TMO"
+msgstr "åŒæ­¥è™•ç†æŽ’程"
+
+msgid "IDS_EMAIL_BODY_TRASH"
+msgstr "垃圾"
+
+msgid "IDS_EMAIL_BODY_WITHOUT_ATTACHMENTS"
+msgstr "無附件"
+
+msgid "IDS_EMAIL_BUTTON_GROUP"
+msgstr "群組"
+
+msgid "IDS_EMAIL_HEADER_ADD_RULES"
+msgstr "加入è¦å‰‡"
+
+msgid "IDS_EMAIL_OPT_ATTACH_ITEMS"
+msgstr "附加項目"
+
+msgid "IDS_EMAIL_OPT_EXCHANGE"
+msgstr "交æ›"
+
+msgid "IDS_EMAIL_OPT_FILE"
+msgstr "檔案"
+
+msgid "IDS_EMAIL_OPT_NAMECARD"
+msgstr "å片"
+
+msgid "IDS_EMAIL_OPT_OPEN_URL"
+msgstr "é–‹å•Ÿ URL"
+
+msgid "IDS_EMAIL_OPT_SENDER"
+msgstr "寄件人"
+
+msgid "IDS_EMAIL_OPT_SEND_EMAIL"
+msgstr "傳é€é›»å­éƒµä»¶"
+
+msgid "IDS_EMAIL_OPT_UPDATE_EXISTING"
+msgstr "æ›´æ–°ç¾æœ‰"
+
+msgid "IDS_EMAIL_POP_ADD_ACCOUNTS"
+msgstr "新增帳戶"
+
+msgid "IDS_EMAIL_POP_DOWNLOADING_ATTACHMENT_ING"
+msgstr "下載附件..."
+
+msgid "IDS_EMAIL_POP_INVALID_EMAIL_ADDRESS"
+msgstr "é›»å­éƒµä»¶åœ°å€ç„¡æ•ˆ"
+
+msgid "IDS_EMAIL_POP_LOADING_CONTENTS_ING"
+msgstr "讀å–中"
+
+msgid "IDS_EMAIL_POP_MAXIMUM_NUMBER_OF_ATTACHMENTS_REACHED"
+msgstr "附件數已é”上é™"
+
+msgid "IDS_EMAIL_POP_MOVE_TO_SPAMBOX_Q"
+msgstr "è¦ç§»è‡³åžƒåœ¾éƒµä»¶å—Žï¼Ÿ"
+
+msgid "IDS_EMAIL_POP_NO_RECIPIENTS_ADDED_ENTER_RECIPIENTS"
+msgstr "沒有收件人,請輸入收件人"
+
+msgid "IDS_EMAIL_POP_PLEASE_FILL_ALL_THE_MANDATORY_FIELDS"
+msgstr "請填入所有必填欄ä½"
+
+msgid "IDS_EMAIL_POP_SAVE_IN_DRAFTS_Q"
+msgstr "è¦å„²å­˜åœ¨è‰ç¨¿åŒ£ä¸­å—Žï¼Ÿ"
+
+msgid "IDS_EMAIL_POP_THERE_IS_NO_ACCOUNT_CREATE_A_NEW_ACCOUNT_FIRST"
+msgstr "沒有帳戶。請先建立新帳戶"
+
+msgid "IDS_EMAIL_POP_TOO_MANY_RECIPIENTS"
+msgstr "收件人太多"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_DOWNLOAD"
+msgstr "無法下載"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_ENTER_TEXT"
+msgstr "無法輸入文字"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_LAUNCH_APPLICATION"
+msgstr "無法執行應用程å¼"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_OPEN_ATTACHMENT"
+msgstr "無法開啟附件"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_SAVE_ATTACHMENT"
+msgstr "無法儲存附件"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_SAVE_IN_DRAFTS"
+msgstr "無法儲存在è‰ç¨¿åŒ£ä¸­"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_SEND_EMAIL"
+msgstr "無法傳é€é›»å­éƒµä»¶"
+
+msgid "IDS_EMAIL_POP_UNSUPPORTED_FILE_TYPE"
+msgstr "ä¸æ”¯æ´çš„檔案類型"
+
+msgid "IDS_EMAIL_POP_VALIDATING_ACCOUNT_ING"
+msgstr "正在驗證帳戶..."
+
+msgid "IDS_EMAIL_SK_RESEND"
+msgstr "é‡æ–°å‚³é€"
+
+msgid "IDS_EMAIL_BODY_ACCEPT_ALL_SSL_CERTIFICATES"
+msgstr "接å—所有SSL證書"
+
+msgid "IDS_EMAIL_SK3_ACCOUNT_LIST"
+msgstr "帳戶列表"
+
+msgid "IDS_EMAIL_BODY_USER_ID"
+msgstr "使用者 ID"
+
+msgid "IDS_EMAIL_POP_ACCOUNT_ALREADY_REGISTERED"
+msgstr "帳號已經被註冊"
+
+msgid "IDS_EMAIL_HEADER_ATTACH_FILE"
+msgstr "附加文件"
+
+msgid "IDS_EMAIL_BODY_EXCHANGE_SYNC_SETTINGS_MSG"
+msgstr "藉由啟動此應用程å¼ï¼Œæ‚¨æŽ¥å—三星還原ã€è™•ç†åŠä½¿ç”¨éƒ¨åˆ†è£ç½®è³‡æ–™ (唯一的è£ç½® ID 和型號å稱),將該應用程å¼çš„å•Ÿå‹•å‘應用程å¼è»Ÿé«”的授權者彙報。 三星æŒæœ‰çš„資料將ä¾æ“šä¸‰æ˜Ÿçš„éš±ç§æ¬Šæ”¿ç­– (è«‹åƒè¦‹ www.samsung.com) 嚴格處ç†ã€‚è¦ç¹¼çºŒå—Žï¼Ÿ"
+
+msgid "IDS_EMAIL_BODY_FORWARD_WITH_FILES"
+msgstr "連檔案轉寄"
+
+msgid "IDS_EMAIL_BODY_REPLY_WITH_BODY"
+msgstr "以正文回覆"
+
+msgid "IDS_EMAIL_BODY_NO_SUBJECT"
+msgstr "無主旨"
+
+msgid "IDS_EMAIL_BODY_FROM"
+msgstr "自"
+
+msgid "IDS_EMAIL_BODY_NO_ADDRESS"
+msgstr "無地å€"
+
+msgid "IDS_EMAIL_OPT_RECORD_SOUND"
+msgstr "錄音"
+
+msgid "IDS_EMAIL_OPT_RECORD_VIDEO"
+msgstr "錄影"
+
+msgid "IDS_EMAIL_OPT_INSERT_IMAGE"
+msgstr "æ’入影åƒ"
+
+msgid "IDS_EMAIL_OPT_ADD_TO_CALENDAR"
+msgstr "加到日曆"
+
+msgid "IDS_EMAIL_OPT_CHANGE_EMAIL_ADDRESS_ABB"
+msgstr "變更電å­éƒµä»¶åœ°å€"
+
+msgid "IDS_EMAIL_OPT_CLIPBOARD"
+msgstr "剪貼簿"
+
+msgid "IDS_EMAIL_OPT_MARKED_AS_UNREAD"
+msgstr "標記為未讀"
+
+msgid "IDS_EMAIL_OPT_VIEW_CONTACT_DETAILS"
+msgstr "檢視è¯çµ¡äººè©³ç´°è³‡æ–™"
+
+msgid "IDS_EMAIL_POP_SAVED_IN_DRAFTS"
+msgstr "已儲存在è‰ç¨¿åŒ£ä¸­"
+
+msgid "IDS_EMAIL_POP_NETWORK_BUSY"
+msgstr "網路ç¹å¿™"
+
+msgid "IDS_EMAIL_POP_LOGIN_ALLOWED_ONLY_EVERY_PD_MINUTES"
+msgstr "Login allowed only every %d minutes"
+
+msgid "IDS_EMAIL_POP_HOST_NOT_FOUND"
+msgstr "找ä¸åˆ°ä¸»æ©Ÿ"
+
+msgid "IDS_EMAIL_POP_HOST_NOT_REACHABLE"
+msgstr "無法到é”主機"
+
+msgid "IDS_EMAIL_POP_NO_SERVICE"
+msgstr "ç„¡æœå‹™"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_FORWARD_DRM_CONTENTS"
+msgstr "無法轉發 DRM 內容"
+
+msgid "IDS_EMAIL_POP_BLOCKED"
+msgstr "å·²å°éŽ–"
+
+msgid "IDS_EMAIL_POP_1_EMAIL_SELECTED"
+msgstr "å·²é¸æ“‡ 1 å°é›»å­éƒµä»¶"
+
+msgid "IDS_EMAIL_POP_PD_EMAILS_SELECTED"
+msgstr "å·²é¸æ“‡ %d å°é›»å­éƒµä»¶"
+
+msgid "IDS_EMAIL_POP_1_RECIPIENT_SELECTED"
+msgstr "1收件人已é¸æ“‡"
+
+msgid "IDS_EMAIL_POP_PD_RECIPIENTS_SELECTED"
+msgstr "å·²é¸æ“‡ï¼…d個收件者"
+
+msgid "IDS_EMAIL_POP_UNABLE_TO_ADD_ACCOUNT"
+msgstr "無法加入帳戶"
+
+msgid "IDS_EMAIL_SK3_MOVE_HERE"
+msgstr "移到這裡"
+
diff --git a/utilities/CMakeLists.txt b/utilities/CMakeLists.txt
new file mode 100755
index 0000000..dca696f
--- /dev/null
+++ b/utilities/CMakeLists.txt
@@ -0,0 +1,56 @@
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+PROJECT(email-service)
+
+SET(CMAKE_SKIP_BUILD_RPATH TRUE)
+
+IF("${CMAKE_BUILD_TYPE}" STREQUAL "")
+ SET(CMAKE_BUILD_TYPE "Debug")
+ENDIF("${CMAKE_BUILD_TYPE}" STREQUAL "")
+
+MESSAGE("")
+MESSAGE(">>> current directory: ${CMAKE_CURRENT_SOURCE_DIR}")
+MESSAGE(">>> Build type: ${CMAKE_BUILD_TYPE}")
+
+SET(VISIBILITY "-DEXPORT_API=\"__attribute__((visibility(\\\"default\\\")))\"")
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${VISIBILITY} -fvisibility=hidden")
+
+##########################################################
+# Define Test App
+##########################################################
+
+
+SET(TEST-APP-SRCS
+ ${CMAKE_SOURCE_DIR}/utilities/email-service-test-application/email-service-test-application/emf-test-main.c
+ ${CMAKE_SOURCE_DIR}/utilities/email-service-test-application/email-service-test-application/emf-test-utility.c
+ ${CMAKE_SOURCE_DIR}/utilities/email-service-test-application/email-service-test-application/emf-test-message.c
+ ${CMAKE_SOURCE_DIR}/utilities/email-service-test-application/email-service-test-application/emf-test-mailbox.c
+ ${CMAKE_SOURCE_DIR}/utilities/email-service-test-application/email-service-test-application/emf-test-account.c
+ ${CMAKE_SOURCE_DIR}/utilities/email-service-test-application/email-service-test-application/emf-test-rule.c
+ ${CMAKE_SOURCE_DIR}/utilities/email-service-test-application/email-service-test-application/emf-test-thread.c
+ ${CMAKE_SOURCE_DIR}/utilities/email-service-test-application/email-service-test-application/emf-test-others.c
+)
+
+INCLUDE_DIRECTORIES(
+ ${CMAKE_SOURCE_DIR}/utilities/email-service-test-application/email-service-test-application/include
+ ${CMAKE_SOURCE_DIR}/MAPI/include
+ ${CMAKE_SOURCE_DIR}/include
+ ${CMAKE_SOURCE_DIR}/email-core/em-storage/include
+ ${CMAKE_SOURCE_DIR}/email-core/include
+ ${CMAKE_SOURCE_DIR}/ipc/include
+)
+
+INCLUDE(FindPkgConfig)
+pkg_check_modules(test_app_pkgs REQUIRED glib-2.0 gthread-2.0 vconf db-util uw-imap-toolkit contacts-service)
+
+FOREACH(flag ${test_app_pkgs_CFLAGS})
+ SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
+SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed")
+
+ADD_EXECUTABLE(email-test-app ${TEST-APP-SRCS})
+TARGET_LINK_LIBRARIES(email-test-app ${test_app_pkgs_LDFLAGS} email-api)
+
+INSTALL(TARGETS email-test-app DESTINATION bin)
+
diff --git a/utilities/email-service-test-application/email-service-test-application/emf-test-account.c b/utilities/email-service-test-application/email-service-test-application/emf-test-account.c
new file mode 100755
index 0000000..99806db
--- /dev/null
+++ b/utilities/email-service-test-application/email-service-test-application/emf-test-account.c
@@ -0,0 +1,624 @@
+/*
+* email-service
+*
+* Copyright (c) 2000 - 2011 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.
+*
+*/
+
+/* common header */
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+/* open header */
+#include <glib.h>
+
+#include "Emf_Mapi_Account.h"
+#include "Emf_Mapi_Network.h"
+
+/* internal header */
+#include "emf-test-utility.h"
+#include "emf-test-account.h"
+#include <sys/time.h>
+#include <sys/times.h>
+
+/* internal defines */
+
+#define GWB_RECV_SERVER_ADDR "pop.gawab.com"
+#define GWB_SMTP_SERVER_ADDR "smtp.gawab.com"
+
+#define VDF_RECV_SERVER_ADDR "imap.email.vodafone.de"
+#define VDF_SMTP_SERVER_ADDR "smtp.email.vodafone.de"
+
+
+gboolean testapp_test_create_account_by_account_type(int account_type,int *account_id)
+{
+ emf_account_t *account = NULL;
+ char id_string[100] = { 0, }, password_string[100] = { 0, }, address_string[100] = { 0, };
+ int err_code = EMF_ERROR_NONE, samsung3g_account_index;
+ unsigned handle;
+
+ switch(account_type) {
+ case 4 :
+ case 5 :
+ do {
+ testapp_print("Enter your account index [1~10] : ");
+ scanf("%d",&samsung3g_account_index);
+ }while( samsung3g_account_index > 10 || samsung3g_account_index < 1);
+ sprintf(id_string, "test%02d", samsung3g_account_index);
+ sprintf(address_string, "<test%02d@streaming.s3glab.net>", samsung3g_account_index);
+ strcpy(password_string, id_string);
+ break;
+ default:
+ testapp_print("Enter email address : ");
+ scanf("%s", address_string);
+
+ testapp_print("Enter id : ");
+ scanf("%s", id_string);
+
+ testapp_print("Enter password_string : ");
+ scanf("%s", password_string);
+ break;
+ }
+
+ account = malloc(sizeof(emf_account_t));
+ memset(account, 0x00, sizeof(emf_account_t));
+
+ /* Common Options */
+ account->account_bind_type = EMF_BIND_TYPE_EM_CORE;
+ account->retrieval_mode = EMF_IMAP4_RETRIEVAL_MODE_ALL;
+ account->use_security = 1;
+ account->sending_server_type = EMF_SERVER_TYPE_SMTP;
+ account->flag1 = 2;
+ account->flag2 = 1;
+ account->pop_before_smtp = 0;
+ account->apop = 0;
+ account->logo_icon_path = NULL;
+ account->preset_account = 0;
+ account->options.priority = 3;
+ account->options.keep_local_copy = 0;
+ account->options.req_delivery_receipt = 0;
+ account->options.req_read_receipt = 0;
+ account->options.download_limit = 0;
+ account->options.block_address = 0;
+ account->options.block_subject = 0;
+ account->options.display_name_from = NULL;
+ account->options.reply_with_body = 0;
+ account->options.forward_with_files = 0;
+ account->options.add_myname_card = 0;
+ account->options.add_signature = 0;
+ account->options.signature = NULL;
+ account->options.add_my_address_to_bcc = 0;
+ account->target_storage = 0;
+ account->check_interval = 0;
+ account->keep_on_server = 1;
+
+ account->account_name = strdup(address_string);
+ account->display_name = strdup(id_string);
+ account->email_addr = strdup(address_string);
+ account->reply_to_addr = strdup(address_string);
+ account->return_addr = strdup(address_string);
+
+ account->user_name = strdup(id_string);
+ account->password = strdup(password_string);
+ account->sending_user = strdup(id_string);
+ account->sending_password = strdup(password_string);
+
+ switch (account_type) {
+ case 1:/* gawab */
+ account->receiving_server_type = EMF_SERVER_TYPE_POP3 ;
+ account->receiving_server_addr = strdup(GWB_RECV_SERVER_ADDR);
+ account->port_num = EMF_POP3S_PORT;
+ account->sending_server_addr = strdup(GWB_SMTP_SERVER_ADDR);
+ account->use_security = 1;
+ account->sending_auth = 1;
+ account->sending_port_num = EMF_SMTPS_PORT;
+ account->sending_security = 1;
+
+ break;
+
+ case 2:/* vadofone */
+ account->receiving_server_type = EMF_SERVER_TYPE_IMAP4;
+ account->receiving_server_addr = strdup(VDF_RECV_SERVER_ADDR);
+ account->port_num = EMF_IMAP_PORT;
+ account->sending_server_addr = strdup(VDF_SMTP_SERVER_ADDR);
+ account->use_security = 0;
+ account->sending_auth = 0;
+ break;
+
+ case 6:/* Gmail POP3 */
+ account->receiving_server_type = EMF_SERVER_TYPE_POP3;
+ account->receiving_server_addr = strdup("pop.gmail.com");
+ account->port_num = 995;
+ account->use_security = 1;
+ account->sending_server_addr = strdup("smtp.gmail.com");
+ account->sending_port_num = 465;
+ account->sending_security = 1;
+ account->sending_auth = 1;
+ break;
+
+ case 7 : /* Gmail IMAP4 */
+ account->receiving_server_type = EMF_SERVER_TYPE_IMAP4;
+ account->receiving_server_addr = strdup("imap.gmail.com");
+ account->port_num = 993;
+ account->use_security = 1;
+ account->sending_server_addr = strdup("smtp.gmail.com");
+ account->sending_port_num = 465;
+ account->sending_security = 1;
+ account->sending_auth = 1;
+ break;
+
+ case 8: /* Active Sync */
+ account->receiving_server_type = EMF_SERVER_TYPE_ACTIVE_SYNC;
+ account->receiving_server_addr = strdup("");
+ account->port_num = 0;
+ account->use_security = 1;
+ account->sending_server_addr = strdup("");
+ account->sending_port_num = 0;
+ account->sending_security = 1;
+ account->sending_auth = 1;
+ break;
+
+ case 9: /* AOL */
+ account->receiving_server_type = EMF_SERVER_TYPE_IMAP4;
+ account->receiving_server_addr = strdup("imap.aol.com");
+ account->port_num = 143;
+ account->use_security = 0;
+ account->sending_server_addr = strdup("smtp.aol.com");
+ account->sending_port_num = 587;
+ account->sending_security = 0;
+ account->sending_auth = 1;
+ break;
+
+ case 10: /* Hotmail */
+ account->receiving_server_type = EMF_SERVER_TYPE_POP3;
+ account->receiving_server_addr = strdup("pop3.live.com");
+ account->port_num = 995;
+ account->use_security = 1;
+ account->sending_server_addr = strdup("smtp.live.com");
+ account->sending_port_num = 587;
+ account->sending_security = 0x02;
+ account->sending_auth = 1;
+ break;
+
+ case 11:/* Daum IMAP4*/
+ account->receiving_server_type = EMF_SERVER_TYPE_IMAP4;
+ account->receiving_server_addr = strdup("imap.daum.net");
+ account->port_num = 993;
+ account->use_security = 1;
+ account->sending_server_addr = strdup("smtp.daum.net");
+ account->sending_port_num = 465;
+ account->sending_security = 1;
+ account->sending_auth = 1;
+ break;
+
+ case 12:/* Daum POP3*/
+ account->receiving_server_type = EMF_SERVER_TYPE_POP3;
+ account->receiving_server_addr = strdup("pop.daum.net");
+ account->port_num = 995;
+ account->use_security = 1;
+ account->sending_server_addr = strdup("smtp.daum.net");
+ account->sending_port_num = 465;
+ account->sending_security = 1;
+ account->sending_auth = 1;
+ break;
+
+ default:
+ testapp_print("Invalid Account Number\n");
+ return FALSE;
+ break;
+ }
+ account->my_account_id = 77;
+ err_code = email_add_account_with_validation(account, &handle);
+ if( err_code < 0) {
+ testapp_print (" email_add_account_with_validation error : %d\n",err_code);
+ return FALSE;
+ }
+
+ testapp_print (" email_add_account succeed\n");
+
+ if(account_id)
+ *account_id = account->account_id;
+
+ err_code = email_free_account(&account, 1);
+ return TRUE;
+
+}
+
+static gboolean testapp_test_create_account()
+{
+ int account_type = 0 ;
+ int err = EMF_ERROR_NONE;
+
+ testapp_print("1. Gawab\n");
+ testapp_print("2. Vodafone\n");
+ testapp_print("6. Gmail (POP3)\n");
+ testapp_print("7. Gmail (IMAP4)\n");
+ testapp_print("8. Active Sync (dummy)\n");
+ testapp_print("9. AOL\n");
+ testapp_print("10. Hotmail\n");
+ testapp_print("11. Daum (IMAP4)\n");
+ testapp_print("12. Daum (POP3)\n");
+ testapp_print("Choose server type: ");
+
+ scanf("%d",&account_type);
+
+ if(!testapp_test_create_account_by_account_type(account_type,&err)) {
+ testapp_print (" testapp_test_create_account_by_account_type error\n");
+ return FALSE;
+ }
+ return FALSE;
+}
+
+static gboolean testapp_test_update_account()
+{
+ int account_id;
+ emf_account_t *account = NULL;
+ char account_name[20];
+ int err = EMF_ERROR_NONE;
+ char signature[100] = {0};
+ char email_addr[50] = {0,};
+ int add_my_address_to_bcc = 0;
+ int my_account_id = 0, with_validation = 0;
+
+
+ testapp_print("\n>> Enter Account No: ");
+ scanf("%d",&account_id);
+
+/* sowmya.kr, 281209 Adding signature to options in emf_account_t changes */
+ if( (err = email_get_account(account_id, GET_FULL_DATA,&account)) < 0) {
+ testapp_print ("email_get_account failed \n");
+ }
+ else
+ testapp_print ("email_get_account result account_name - %s \n", account->account_name);
+
+ testapp_print ("email_get_account result signature - %s \n", account->options.signature);
+
+#ifdef __FEATURE_AUTO_POLLING__
+ testapp_print ("email_get_account result check_interval - %d \n", account->check_interval);
+#endif
+
+ testapp_print("\n Enter new Account name:");
+ scanf("%s",account_name);
+
+
+ testapp_print("\n Enter new email addr:");
+ scanf("%s",email_addr);
+#ifdef __FEATURE_AUTO_POLLING__
+ testapp_print("\n Enter new check interval (in mins):");
+ scanf("%d",&(account->check_interval));
+#endif
+ testapp_print("\n Enter new signature:");
+ scanf("%s",signature);
+
+ testapp_print("\n>> Enter add_my_address_to_bcc:(0:off, 1:on) ");
+ scanf("%d",&add_my_address_to_bcc);
+
+ testapp_print("\n>> Enter my_account_id: ");
+ scanf("%d",&my_account_id);
+
+ testapp_print("\n>> With validation ? (0: No, 1:Yes) ");
+ scanf("%d",&with_validation);
+
+ if( account ) {
+ account->account_name = strdup(account_name);
+ testapp_print("\n Assigning New Account name: %p", account->account_name);
+ account->email_addr = strdup(email_addr);
+ account->options.signature = strdup(signature);
+ testapp_print("\n Assigning New Account name: %p", account->options.signature);
+ account->options.add_my_address_to_bcc = add_my_address_to_bcc;
+ account->my_account_id= my_account_id;
+
+ if(with_validation) {
+ if((err = email_update_account_with_validation(account_id, account)) < 0)
+ testapp_print ("email_update_account_with_validation successful \n");
+ }
+ else {
+ if((err = email_update_account(account_id, account)) < 0)
+ testapp_print ("email_update_account_with_validation successful \n");
+ }
+ }
+ return FALSE;
+}
+
+static gboolean testapp_test_delete_account ()
+{
+ int account_id;
+ emf_account_t *account=NULL;
+ int err = EMF_ERROR_NONE;
+ testapp_print("\n>> Enter Account No: ");
+ scanf("%d",&account_id);
+
+/* sowmya.kr, 281209 Adding signature to options in emf_account_t changes */
+ if( (err = email_get_account(account_id, WITHOUT_OPTION,&account)) < 0) {
+ testapp_print ("email_get_account failed \n");
+ testapp_print("testapp_test_delete_account failed\n");
+ }
+ else {
+ testapp_print ("email_get_account result account_name - %s \n", account->account_name);
+
+ if((err = email_delete_account(account_id)) < 0)
+ testapp_print ("email_delete_account failed[%d]\n", err);
+ else
+ testapp_print ("email_delete_account successful \n");
+ }
+ return FALSE;
+
+}
+
+
+static gboolean testapp_test_validate_account ()
+{
+ int account_id;
+ emf_account_t *account=NULL;
+ int err_code = EMF_ERROR_NONE;
+ unsigned account_handle = 0;
+
+ testapp_print("\n>> Enter Account No: ");
+ scanf("%d",&account_id);
+
+/* sowmya.kr, 281209 Adding signature to options in emf_account_t changes */
+ if( (err_code = email_get_account(account_id, WITHOUT_OPTION,&account)) < 0 ) {
+ testapp_print ("email_get_account failed \n");
+ return FALSE;
+ }
+ else
+ testapp_print ("email_get_account result account_name - %s \n", account->account_name);
+
+ if((err_code = email_validate_account(account_id, &account_handle)) == EMF_ERROR_NONE )
+ testapp_print ("email_validate_account successful account_handle : %u\n",account_handle);
+ else
+ testapp_print ("email_validate_account failed err_code: %d \n",err_code);
+
+ return FALSE;
+
+}
+
+
+static gboolean testapp_test_cancel_validate_account ()
+{
+ int account_id = 0;
+ int err_code = EMF_ERROR_NONE;
+ unsigned account_handle = 0;
+
+ testapp_print("\n > Enter account_id: ");
+ scanf("%d", &account_id);
+
+ testapp_print("\n > Enter handle: ");
+ scanf("%d", &account_handle);
+
+ err_code = email_cancel_job(account_id, account_handle);
+ if(err_code == 0)
+ testapp_print("email_cancel_job Success..!handle:[%d]", account_handle);
+ else
+ testapp_print ("email_cancel_job failed err_code: %d \n",err_code);
+
+ return FALSE;
+}
+
+static gboolean testapp_test_get_account()
+{
+ int account_id;
+ emf_account_t *account=NULL;
+ int err_code = EMF_ERROR_NONE;
+ testapp_print("\n>> Enter Account No: ");
+ scanf("%d",&account_id);
+
+/* sowmya.kr, 281209 Adding signature to options in emf_account_t changes */
+ testapp_print ("email_get_account GET_FULL_DATA \n");
+ if( (err_code = email_get_account(account_id,GET_FULL_DATA,&account)) < 0) {
+ testapp_print ("email_get_account failed \n");
+ return FALSE;
+ }
+ else
+ testapp_print ("email_get_account result account_name - %s \n email_addr - %s \n use_security %d \n add_sig : %d \n signature %s \n add_my_address_to_bcc %d \nmy_account_id %d\n",
+ account->account_name,
+ account->email_addr,
+ account->use_security,
+ account->options.add_signature,
+ account->options.signature,
+ account->options.add_my_address_to_bcc,
+ account->my_account_id
+ );
+
+ err_code = email_free_account(&account, 1);
+
+ testapp_print ("email_get_account WITHOUT_OPTION \n");
+
+ if( (err_code = email_get_account(account_id,WITHOUT_OPTION,&account)) < 0) {
+ testapp_print ("email_get_account failed \n");
+ return FALSE;
+ }
+ else
+ testapp_print ("email_get_account result account_name - %s \n email_addr - %s \n use_security %d \n add_sig : %d \n ",
+ account->account_name,
+ account->email_addr,
+ account->use_security,
+ account->options.add_signature);
+
+ if(account->options.signature)
+ testapp_print ("signature : %s \n", account->options.signature);
+ else
+ testapp_print ("signature not retrieved \n");
+
+ err_code = email_free_account(&account, 1);
+
+ testapp_print ("email_get_account ONLY_OPTION \n");
+
+ if( (err_code = email_get_account(account_id,ONLY_OPTION,&account)) < 0) {
+ testapp_print ("email_get_account failed \n");
+ return FALSE;
+ }
+ else
+ testapp_print ("email_get_account result add_sig : %d \n signature %s \n add_my_address_to_bcc %d\n my_account_id %d\n",
+ account->options.add_signature,
+ account->options.signature,
+ account->options.add_my_address_to_bcc,
+ account->my_account_id
+ );
+
+ if(account->account_name)
+ testapp_print ("account_name : %s \n", account->account_name);
+ else
+ testapp_print ("account_name not retrieved \n");
+
+ if(account->email_addr)
+ testapp_print ("email_addr : %s \n", account->email_addr);
+ else
+ testapp_print ("email_addr not retrieved \n");
+ err_code = email_free_account(&account, 1);
+
+ return FALSE;
+}
+
+static gboolean testapp_test_get_account_list ()
+{
+
+ int count, i;
+ emf_account_t *account_list=NULL;
+ struct timeval tv_1, tv_2;
+ int interval;
+ int err_code = EMF_ERROR_NONE;
+
+ gettimeofday(&tv_1, NULL);
+
+ if((err_code = email_get_account_list(&account_list, &count)) < 0 ) {
+ testapp_print(" email_get_account_list error\n");
+ return false ;
+ }
+
+ gettimeofday(&tv_2, NULL);
+ interval = tv_2.tv_usec - tv_1.tv_usec;
+ testapp_print("\t testapp_test_get_account_list Proceed time %d us\n",interval);
+
+ for(i=0;i<count;i++){
+ testapp_print(" %2d) %-15s %-30s\n",account_list[i].account_id,
+ account_list[i].account_name,
+ account_list[i].email_addr);
+ }
+
+ err_code = email_free_account(&account_list, count);
+ return FALSE;
+}
+
+static gboolean testapp_test_backup_account()
+{
+ char *file_name = "accounts_file";
+ int error_code;
+ error_code = email_backup_accounts_into_secure_storage(file_name);
+ testapp_print("\n email_backup_accounts_into_secure_storage returned [%d]\n",error_code);
+ return FALSE;
+}
+static gboolean testapp_test_restore_account()
+{
+ char *file_name = "accounts_file";
+ int error_code;
+ error_code = email_restore_accounts_from_secure_storage(file_name);
+ testapp_print("\n email_restore_accounts_from_secure_storage returned [%d]\n",error_code);
+ return FALSE;
+}
+
+static gboolean testapp_test_get_password_length_of_account()
+{
+ int error_code, password_length, account_id;
+
+ testapp_print("\n input account id\n");
+ scanf("%d", &account_id);
+ error_code = email_get_password_length_of_account(account_id, &password_length);
+ testapp_print("testapp_test_get_password_length_of_account returned [%d]\n",password_length);
+ return FALSE;
+}
+
+
+static gboolean testapp_test_clear_all_notification()
+{
+ int error_code;
+
+ error_code = email_clear_all_notification_bar();
+ testapp_print("email_clear_all_notification_bar returned [%d]\n",error_code);
+ return FALSE;
+}
+static gboolean testapp_test_interpret_command (int selected_number)
+{
+ gboolean go_to_loop = TRUE;
+
+ switch (selected_number) {
+ case 1:
+ testapp_test_create_account();
+ break;
+ case 2:
+ testapp_test_update_account();
+ break;
+ case 3:
+ testapp_test_delete_account();
+ break;
+ case 4:
+ testapp_test_get_account();
+ break;
+
+ case 5:
+ testapp_test_get_account_list();
+ break;
+
+ case 7:
+ testapp_test_validate_account();
+ break;
+
+ case 8:
+ testapp_test_cancel_validate_account();
+ break;
+
+ case 9:
+ testapp_test_backup_account();
+ break;
+
+ case 10:
+ testapp_test_restore_account();
+ break;
+
+ case 11:
+ testapp_test_get_password_length_of_account();
+ break;
+
+ case 13:
+ testapp_test_clear_all_notification();
+
+ case 0:
+ go_to_loop = FALSE;
+ break;
+ default:
+ break;
+ }
+
+ return go_to_loop;
+}
+
+void testapp_account_main ()
+{
+ gboolean go_to_loop = TRUE;
+ int menu_number = 0;
+
+ while (go_to_loop) {
+ testapp_show_menu (EMF_ACCOUNT_MENU);
+ testapp_show_prompt (EMF_ACCOUNT_MENU);
+
+ scanf ("%d", &menu_number);
+
+ go_to_loop = testapp_test_interpret_command (menu_number);
+ }
+}
+
diff --git a/utilities/email-service-test-application/email-service-test-application/emf-test-mailbox.c b/utilities/email-service-test-application/email-service-test-application/emf-test-mailbox.c
new file mode 100755
index 0000000..b949663
--- /dev/null
+++ b/utilities/email-service-test-application/email-service-test-application/emf-test-mailbox.c
@@ -0,0 +1,359 @@
+/*
+* email-service
+*
+* Copyright (c) 2000 - 2011 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.
+*
+*/
+
+
+
+/* common header */
+#include <stdio.h>
+#include <string.h>
+
+
+/* open header */
+#include <glib.h>
+
+#include "Emf_Mapi_Message.h"
+#include "Emf_Mapi_Network.h"
+#include "Emf_Mapi_Mailbox.h"
+
+/* internal header */
+#include "emf-test-utility.h"
+#include "emf-test-mailbox.h"
+
+
+static gboolean testapp_test_add_mailbox()
+{
+ emf_mailbox_t mbox;
+ int account_id,mailbox_type = 0;
+ int local_yn = 0;
+ char arg[500];
+ int ret;
+ unsigned handle;
+
+ memset(arg, 0x00, 500);
+ testapp_print("\n> Enter mailbox name: ");
+ scanf("%s",arg);
+ mbox.name = strdup(arg);
+
+ memset(arg, 0x00, 500);
+ testapp_print("> Enter mailbox alias name: ");
+ scanf("%s",arg);
+ mbox.alias = strdup(arg);
+
+ testapp_print("> Enter account id: ");
+ scanf("%d", &account_id);
+ mbox.account_id = account_id;
+
+ testapp_print("> Enter local_yn (1/0): ");
+ scanf("%d", &local_yn);
+ mbox.local= local_yn;
+
+
+ testapp_print("> Enter mailbox type: ");
+ scanf("%d", &mailbox_type);
+ mbox.mailbox_type= mailbox_type;
+
+ ret = email_add_mailbox(&mbox, local_yn?0:1, &handle);
+
+ if (ret < 0) {
+ testapp_print("\n email_add_mailbox failed");
+ }
+ else {
+ testapp_print("\n email_add_mailbox succeed : handle[%d]\n", handle);
+ }
+
+ return FALSE;
+}
+
+static gboolean testapp_test_delete_mailbox()
+{
+
+ emf_mailbox_t mbox;
+ int account_id;
+ int local_yn = 0;
+ char arg[500];
+ int ret;
+ unsigned handle;
+
+ memset(arg, 0x00, 500);
+ testapp_print("\n> Enter mailbox name:");
+ scanf("%s",arg);
+ mbox.name = strdup(arg);
+
+ testapp_print("> Enter account id: ");
+ scanf("%d", &account_id);
+ mbox.account_id = account_id;
+
+ testapp_print("> Enter local_yn (1/0): ");
+ scanf("%d", &local_yn);
+
+ ret = email_delete_mailbox(&mbox, local_yn?0:1, &handle);
+
+ if ( ret < 0) {
+ testapp_print("\n email_delete_mailbox failed");
+ }
+ else {
+ testapp_print("\n email_delete_mailbox succeed : handle[%d]\n", handle);
+ }
+
+ return FALSE;
+
+}
+
+static gboolean testapp_test_update_mailbox()
+{
+ testapp_print ("testapp_test_update_mailbox - support ONLY updating mailbox type\n");
+ emf_mailbox_t *old_mailbox_name = NULL;
+ emf_mailbox_t *new_mbox = NULL;
+ int account_id,mailbox_type = 0;
+ char arg[500];
+ int err;
+
+ memset(arg, 0x00, 500);
+
+ testapp_print("> Enter account id: ");
+ scanf("%d", &account_id);
+
+ testapp_print("\n> Enter mailbox name: ");
+ scanf("%s", arg);
+
+ testapp_print("> Enter mailbox type: ");
+ scanf("%d", &mailbox_type);
+
+ /* Get old mailbox information from db */
+ if ( (err = email_get_mailbox_by_name(account_id, arg, &old_mailbox_name)) < 0 ) {
+ testapp_print("\n email_get_mailbox_by_name failed[%d]\n", err);
+ }
+ else {
+ testapp_print("\n email_get_mailbox_by_name succeed\n");
+ }
+
+ /* copy old maibox to new mailbox */
+ if ( (err = email_get_mailbox_by_name(account_id, arg, &new_mbox)) < 0 ) {
+ testapp_print("\n email_get_mailbox_by_name failed[%d]\n", err);
+ }
+ else {
+ testapp_print("\n email_get_mailbox_by_name succeed\n");
+ }
+
+ /* set new value of new mailbox */
+ new_mbox->mailbox_type= mailbox_type;
+
+ if ( (err = email_update_mailbox(old_mailbox_name, new_mbox)) < 0) {
+ testapp_print("\n email_update_mailbox failed[%d]\n", err);
+ }
+ else {
+ testapp_print("\n email_update_mailbox succeed\n");
+ }
+
+ email_free_mailbox(&old_mailbox_name, 1);
+ email_free_mailbox(&new_mbox, 1);
+
+ return FALSE;
+}
+
+static gboolean testapp_test_get_imap_mailbox_list()
+{
+ int account_id = 0;
+ unsigned handle = 0;
+
+ testapp_print("> Enter account id: ");
+ scanf("%d", &account_id);
+
+ if( email_get_imap_mailbox_list(account_id, "", &handle) < 0)
+ testapp_print("email_get_imap_mailbox_list failed");
+
+ return FALSE;
+
+}
+
+static gboolean testapp_test_get_child_mailbox_list ()
+{
+
+ int account_id =0;
+ int count = 0;
+ int i = 0, err_code = EMF_ERROR_NONE;
+ emf_mailbox_t *mailbox_list=NULL;
+ char parent_mailbox[100], *parent_mailbox_pointer = NULL;
+
+
+ memset(parent_mailbox,0x00,sizeof(parent_mailbox));
+
+ testapp_print("\n > Enter account id: ");
+ scanf("%d", &account_id);
+
+ testapp_print("\n > Enter parent mailbox name to fetch child list: ");
+ scanf("%s", parent_mailbox);
+
+
+
+ if(strcmp(parent_mailbox, "0") != 0) {
+ testapp_print("\ninput : %s\n", parent_mailbox);
+ parent_mailbox_pointer = parent_mailbox;
+ }
+
+ if( (err_code = email_get_child_mailbox_list(account_id,parent_mailbox_pointer, &mailbox_list, &count)) < 0) {
+ testapp_print(" email_get_child_mailbox_list error : %d\n",err_code);
+ return false ;
+ }
+
+ testapp_print("There are %d mailboxes\n", count);
+
+ testapp_print("============================================================================\n");
+ testapp_print("number\taccount_id\t name\t alias\t local_yn\t unread\t mailbox_type\thas_archived_mails\n");
+ testapp_print("============================================================================\n");
+ if(count == 0) {
+ testapp_print("No mailbox is matched\n");
+ }
+ else {
+ for(i=0;i<count;i++)
+ {
+ testapp_print("[%d] - ", i);
+ testapp_print(" %2d\t [%-15s]\t[%-15s]\t", mailbox_list[i].account_id, mailbox_list[i].name, mailbox_list[i].alias);
+ testapp_print(" %d\t %d\t %d\n", mailbox_list[i].local, mailbox_list[i].unread_count,mailbox_list[i].mailbox_type, mailbox_list[i].has_archived_mails);
+ }
+ }
+ testapp_print("============================================================================\n");
+
+ email_free_mailbox(&mailbox_list, count);
+ return FALSE;
+}
+
+static gboolean testapp_test_get_mailbox_by_type ()
+{
+
+ int account_id =0;
+ int i = 0, err_code = EMF_ERROR_NONE;
+ emf_mailbox_t *mailbox =NULL;
+ emf_mailbox_type_e mailbox_type =0;
+
+ testapp_print("\n > Enter account id: ");
+ scanf("%d", &account_id);
+
+ testapp_print("\n > Enter mailbox_type: ");
+ scanf("%d", (int*)&mailbox_type);
+
+ if( (err_code = email_get_mailbox_by_mailbox_type(account_id,mailbox_type,&mailbox)) < 0) {
+ testapp_print(" email_get_mailbox_by_mailbox_type error : %d\n",err_code);
+ return false ;
+ }
+
+ testapp_print("============================================================================\n");
+ testapp_print("number\taccount_id\t name\t alias\t local_yn\t unread\t mailbox_type\thas_archived_mails\n");
+ testapp_print("============================================================================\n");
+
+ testapp_print("[%d] - ", i);
+ testapp_print(" %2d\t [%-15s]\t[%-15s]\t", mailbox->account_id, mailbox->name, mailbox->alias);
+ testapp_print(" %d\t %d\t %d\n", mailbox->local, mailbox->unread_count,mailbox->mailbox_type, mailbox->has_archived_mails);
+
+ testapp_print("============================================================================\n");
+
+ email_free_mailbox(&mailbox, 1);
+ return FALSE;
+}
+
+static gboolean testapp_test_set_mail_slot_size ()
+{
+
+ int account_id = 0, mail_slot_size = 0;
+ int err_code = EMF_ERROR_NONE;
+ char arg[500];
+ char *mailbox_name = NULL;
+
+ testapp_print("\n > Enter account id (0: All account): ");
+ scanf("%d", &account_id);
+
+ memset(arg, 0x00, 500);
+ testapp_print("\n> Enter mailbox name (0 : All mailboxes):");
+ scanf("%s",arg);
+ if (strcmp(arg, "0") != 0 ) {
+ mailbox_name = arg;
+ }
+
+ testapp_print("\n > Enter mailbox slot size: ");
+ scanf("%d", &mail_slot_size);
+
+ if( (err_code = email_set_mail_slot_size(account_id, mailbox_name, mail_slot_size) ) < 0) {
+ testapp_print(" testapp_test_set_mail_slot_size error : %d\n", err_code);
+ return false ;
+ }
+
+ return FALSE;
+}
+
+
+static gboolean testapp_test_interpret_command (int menu_number)
+{
+ gboolean go_to_loop = TRUE;
+
+ switch (menu_number) {
+ case 1:
+ testapp_test_add_mailbox();
+ break;
+
+ case 2:
+ testapp_test_delete_mailbox ();
+ break;
+
+ case 3:
+ testapp_test_update_mailbox ();
+ break;
+
+ case 4:
+ testapp_test_get_imap_mailbox_list();
+ break;
+
+ case 6:
+ testapp_test_get_child_mailbox_list();
+ break;
+
+ case 7:
+ testapp_test_get_mailbox_by_type();
+ break;
+
+ case 8:
+ testapp_test_set_mail_slot_size();
+ break;
+
+ case 0:
+ go_to_loop = FALSE;
+ break;
+ default:
+ break;
+ }
+
+ return go_to_loop;
+}
+
+void emf_test_mailbox_main()
+{
+ gboolean go_to_loop = TRUE;
+ int menu_number = 0;
+
+ while (go_to_loop) {
+ testapp_show_menu (EMF_MAILBOX_MENU);
+ testapp_show_prompt (EMF_MAILBOX_MENU);
+
+ scanf ("%d", &menu_number);
+
+ go_to_loop = testapp_test_interpret_command (menu_number);
+ }
+}
+
diff --git a/utilities/email-service-test-application/email-service-test-application/emf-test-main.c b/utilities/email-service-test-application/email-service-test-application/emf-test-main.c
new file mode 100755
index 0000000..e802b9f
--- /dev/null
+++ b/utilities/email-service-test-application/email-service-test-application/emf-test-main.c
@@ -0,0 +1,199 @@
+/*
+* email-service
+*
+* Copyright (c) 2000 - 2011 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.
+*
+*/
+
+
+
+/* common header */
+#include <stdio.h>
+#include <stdlib.h>
+#include <signal.h>
+#include <sys/time.h>
+#include <unistd.h>
+
+/* open header */
+#include <glib.h>
+
+#include "Emf_Mapi_Init.h"
+
+/* internal header */
+#include "emf-test-utility.h"
+#include "emf-test-account.h"
+#include "emf-test-message.h"
+#include "emf-test-mailbox.h"
+#include "emf-test-rule.h"
+#include "emf-test-thread.h"
+#include "emf-test-others.h"
+#include "db-util.h"
+
+/* function prototype */
+static void testapp_system_signal_handler (int signal_number);
+
+
+/* implementation */
+static gboolean testapp_initialize_testing ()
+{
+ struct timeval tv_1, tv_2;
+ int interval;
+ int error;
+
+ /* register signal handler */
+ if ( signal (SIGINT, testapp_system_signal_handler) == SIG_ERR ) {
+ testapp_print ("register signal handler fail\n");
+ return FALSE;
+ }
+
+ if ( signal (SIGQUIT, testapp_system_signal_handler) == SIG_ERR ) {
+ testapp_print ("register signal handler fail\n");
+ return FALSE;
+ }
+
+ if ( signal (SIGTSTP, testapp_system_signal_handler) == SIG_ERR ) {
+ testapp_print ("register signal handler fail\n");
+ return FALSE;
+ }
+
+ if ( signal (SIGTERM, testapp_system_signal_handler) == SIG_ERR ) {
+ testapp_print ("register signal handler fail\n");
+ return FALSE;
+ }
+
+
+ gettimeofday(&tv_1, NULL);
+
+ if ( email_service_begin() != EMF_ERROR_NONE ) {
+ testapp_print ("unexpected error: opening email service fail\n");
+ return FALSE;
+ }
+ gettimeofday(&tv_2, NULL);
+ interval = tv_2.tv_usec - tv_1.tv_usec;
+ testapp_print("\t email_service_begin Proceed time %d us\n",interval);
+
+ gettimeofday(&tv_1, NULL);
+ if ( (error = email_open_db()) != EMF_ERROR_NONE) {
+ testapp_print("email_open_db failed [%d]\n", error);
+ }
+ gettimeofday(&tv_2, NULL);
+ interval = tv_2.tv_usec - tv_1.tv_usec;
+ testapp_print("\t email_open_db Proceed time %d us\n",interval);
+
+ return TRUE;
+}
+
+static gboolean testapp_finalize_testing ()
+{
+ int error;
+
+ if ( (error = email_close_db()) != EMF_ERROR_NONE) {
+ testapp_print("email_close_db failed [%d]\n", error);
+ }
+
+ if ( email_service_end() != EMF_ERROR_NONE) {
+ testapp_print ("unexpected error: closing email service fail \n");
+ }
+
+ return TRUE;
+}
+
+static void testapp_system_signal_handler (int signal_number)
+{
+ testapp_print ("signal:%d\n", signal_number);
+ switch (signal_number) {
+ case SIGQUIT:
+ case SIGINT:
+ case SIGTSTP:
+ case SIGTERM:
+ testapp_finalize_testing();
+ break;
+
+ default:
+ testapp_print ("unhandled signal:%d\n", signal_number);
+ break;
+ }
+ exit(0);
+}
+
+
+static gboolean testapp_interpret_command (int menu_number)
+{
+ gboolean go_to_loop = TRUE;
+
+ switch (menu_number) {
+ case 1:
+ testapp_account_main();
+ break;
+
+ case 2:
+ testapp_mail_main();
+ break;
+
+ case 3:
+ emf_test_mailbox_main();
+ break;
+
+ case 4:
+ break;
+
+ case 5:
+ emf_test_rule_main();
+ break;
+
+ case 6:
+ testapp_thread_main();
+ break;
+
+ case 7:
+ testapp_others_main();
+ break;
+ case 0:
+ go_to_loop = FALSE;
+ break;
+ default:
+ break;
+ }
+
+ return go_to_loop;
+}
+
+int main (int argc, char *argv[])
+{
+ gboolean go_to_loop = TRUE;
+ int menu_number = 0;
+
+ if ( testapp_initialize_testing() == FALSE ) {
+ testapp_print ("email-serivce is not ready\n");
+ exit(0);
+ }
+
+ while (go_to_loop) {
+ testapp_show_menu (EMF_MAIN_MENU);
+ testapp_show_prompt (EMF_MAIN_MENU);
+
+ scanf ("%d", &menu_number);
+
+ go_to_loop = testapp_interpret_command (menu_number);
+ }
+
+ testapp_finalize_testing();
+
+ exit(0);
+}
+
+
diff --git a/utilities/email-service-test-application/email-service-test-application/emf-test-message.c b/utilities/email-service-test-application/email-service-test-application/emf-test-message.c
new file mode 100755
index 0000000..0a91ff3
--- /dev/null
+++ b/utilities/email-service-test-application/email-service-test-application/emf-test-message.c
@@ -0,0 +1,2653 @@
+/*
+* email-service
+*
+* Copyright (c) 2000 - 2011 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.
+*
+*/
+
+
+
+/* common header */
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+/* open header */
+#include <glib.h>
+#include <time.h>
+
+#include "Emf_Mapi_Message.h"
+#include "Emf_Mapi_Network.h"
+#include "Emf_Mapi_Mailbox.h"
+
+/* internal header */
+#include "emf-test-utility.h"
+#include "emf-test-message.h"
+#include "em-core-utils.h"
+
+#define MAIL_TEMP_BODY "/tmp/mail.txt"
+#define NO_OF_TESTS 40
+
+/*
+static void testapp_test_print_sorting_menu()
+{
+ testapp_print(" EMF_SORT_DATETIME_HIGH = 0\n");
+ testapp_print(" EMF_SORT_DATETIME_LOW = 1\n");
+ testapp_print(" EMF_SORT_SENDER_HIGH = 2\n");
+ testapp_print(" EMF_SORT_SENDER_LOW = 3\n");
+ testapp_print(" EMF_SORT_RCPT_HIGH = 4\n");
+ testapp_print(" EMF_SORT_RCPT_LOW = 5\n");
+ testapp_print(" EMF_SORT_SUBJECT_HIGH = 6\n");
+ testapp_print(" EMF_SORT_SUBJECT_LOW = 7\n");
+ testapp_print(" EMF_SORT_PRIORITY_HIGH = 8\n");
+ testapp_print(" EMF_SORT_PRIORITY_LOW = 9\n");
+ testapp_print(" EMF_SORT_ATTACHMENT_HIGH = 10\n");
+ testapp_print(" EMF_SORT_ATTACHMENT_LOW = 11\n");
+ testapp_print(" EMF_SORT_FAVORITE_HIGH = 12\n");
+ testapp_print(" EMF_SORT_FAVORITE_LOW = 13\n");
+}
+
+static void testapp_test_print_mail_list_item(emf_mail_list_item_t *mail_list_item, int count)
+{
+ int i;
+
+ testapp_print("\n>>>>> Print mail list items: count[%d]\n", count);
+ for (i=0; i< count; i++) {
+ testapp_print("\n[%d]\n", i);
+ testapp_print(" >>> Mailbox Name [ %s ] \n", mail_list_item[i].mailbox_name);
+ testapp_print(" >>> Mail ID [ %d ] \n", mail_list_item[i].mail_id);
+ testapp_print(" >>> Account ID [ %d ] \n", mail_list_item[i].account_id);
+ if ( mail_list_item[i].from!= NULL ) {
+ testapp_print(" >>> From [ %s ] \n", mail_list_item[i].from);
+ }
+ if ( mail_list_item[i].from_email_address != NULL ) {
+ testapp_print(" >>> from_email_address [ %s ] \n", mail_list_item[i].from_email_address);
+ }
+ if ( mail_list_item[i].recipients!= NULL ) {
+ testapp_print(" >>> recipients [ %s ] \n", mail_list_item[i].recipients);
+ }
+ if ( mail_list_item[i].subject != NULL ) {
+ testapp_print(" >>> subject [ %s ] \n", mail_list_item[i].subject);
+ }
+ testapp_print(" >>> text_download_yn [ %d ] \n", mail_list_item[i].is_text_downloaded);
+ if ( mail_list_item[i].datetime != NULL ) {
+ testapp_print(" >>> datetime [ %s ] \n", mail_list_item[i].datetime);
+ }
+ testapp_print(" >>> flags_seen_field [ %d ] \n", mail_list_item[i].flags_seen_field);
+ testapp_print(" >>> priority [ %d ] \n", mail_list_item[i].priority);
+ testapp_print(" >>> save_status [ %d ] \n", mail_list_item[i].save_status);
+ testapp_print(" >>> lock [ %d ] \n", mail_list_item[i].is_locked);
+ testapp_print(" >>> is_report_mail [ %d ] \n", mail_list_item[i].is_report_mail);
+ testapp_print(" >>> recipients_count [ %d ] \n", mail_list_item[i].recipients_count);
+ testapp_print(" >>> has_attachment [ %d ] \n", mail_list_item[i].has_attachment);
+ testapp_print(" >>> has_drm_attachment [ %d ] \n", mail_list_item[i].has_drm_attachment);
+
+ if ( mail_list_item[i].previewBodyText != NULL ) {
+ testapp_print(" >>> previewBodyText [ %s ] \n", mail_list_item[i].previewBodyText);
+ }
+
+ testapp_print(" >>> thread_id [ %d ] \n", mail_list_item[i].thread_id);
+ testapp_print(" >>> thread_item_count [ %d ] \n", mail_list_item[i].thread_item_count);
+ }
+}
+*/
+
+static gboolean testapp_test_send_html_mail_with_inline_content()
+{
+ int account_id = 0, i = 0, from_composer = 1;
+ int err_code = EMF_ERROR_NONE;
+ unsigned handle = 0;
+ FILE *p_file = NULL;
+ char *p_plain_text_file_path = "/opt/data/email/.emfdata/tmp/mail.txt";
+ char *p_html_text_file_path = "/opt/data/email/.emfdata/tmp/mail.html";
+ char *p_attachment_file_path = "/opt/media/Images and videos/Wallpapers/Default.png";
+ char *p_attachment_name = "Default.png";
+ emf_mail_t *mail = NULL;
+ emf_mailbox_t *mailbox = NULL;
+ emf_attachment_info_t *attachment = NULL;
+ emf_option_t option;
+
+
+ testapp_print("\n > Enter account no:");
+ scanf("%d", &account_id);
+
+ mail = malloc(sizeof(emf_mail_t));
+ memset(mail, 0x00, sizeof(emf_mail_t));
+
+ mail->info = malloc(sizeof(emf_mail_info_t));
+ memset(mail->info, 0x00, sizeof(emf_mail_info_t));
+
+
+ mail->info->account_id = account_id;
+ mail->info->extra_flags.text_download_yn = 1;
+ mail->info->flags.seen = 1;
+ mail->info->account_id = account_id;
+
+ mail->head = malloc(sizeof(emf_mail_head_t));
+ memset(mail->head, 0x00, sizeof(emf_mail_head_t));
+
+ mail->head->to = strdup("<kyuho.jo@samsung.com>");
+ mail->head->cc = strdup("<slpmany@gmail.com>");
+ mail->head->bcc = strdup("<samsungtest09@gmail.com>");
+ mail->head->from = strdup("<slpmany@gmail.com>");
+ mail->head->subject = strdup("HTML Inline");
+
+ mail->body = malloc(sizeof(emf_mail_body_t));
+ memset(mail->body, 0x00, sizeof(emf_mail_body_t));
+ mail->body->plain = strdup(p_plain_text_file_path);
+ mail->body->html = strdup(p_html_text_file_path);
+
+ mailbox = malloc(sizeof(emf_mailbox_t));
+ if(!mailbox) {
+ testapp_print("malloc failed\n");
+ email_free_mail(&mail, 1);
+ return false;
+ }
+ memset(mailbox, 0x00, sizeof(emf_mailbox_t));
+ mailbox->name = strdup("INBOX");
+ mailbox->account_id = account_id;
+
+ attachment = malloc(sizeof(emf_attachment_info_t));
+ memset(attachment, 0x00, sizeof(emf_attachment_info_t));
+ attachment->name = strdup(p_attachment_name);
+ attachment->savename = strdup(p_attachment_file_path);
+ attachment->downloaded = 1;
+ attachment->inline_content = 1;
+ attachment->next = NULL;
+
+ mail->body->attachment = attachment;
+ mail->body->attachment_num = 1;
+
+ p_file = fopen(p_plain_text_file_path, "w");
+
+ if(!p_file) {
+ testapp_print("fopen failed\n");
+ email_free_mail(&mail, 1);
+ email_free_mailbox(&mailbox, 1);
+ return false;
+ }
+ for(i = 0; i < 50; i++)
+ fprintf(p_file, "X2 X2 X2 X2 X2 X2 X2");
+ fclose(p_file);
+
+ p_file = fopen(p_html_text_file_path, "w");
+ if(!p_file) {
+ testapp_print("fopen failed\n");
+ email_free_mail(&mail, 1);
+ email_free_mailbox(&mailbox, 1);
+ return false;
+ }
+ fprintf(p_file, "<HTML><HEAD></HEAD>\r\n<BODY>\r\n<IMG SRC = \"%s\"></IMG>\r\n</BODY></HTML>", p_attachment_name);
+ fclose(p_file);
+
+ if((err_code = email_add_message(mail, mailbox, from_composer)) < 0)
+ testapp_print("email_add_message failed. [%d]\n", err_code);
+ else
+ testapp_print("email_add_message success\n");
+
+ testapp_print("saved mail id = [%d]\n", mail->info->uid);
+
+ memset(&option, 0x00, sizeof(emf_option_t));
+ option.keep_local_copy = 1;
+ err_code = email_send_mail(mailbox, mail->info->uid, &option, &handle);
+ if( err_code < 0)
+ testapp_print(" fail sending [%d]\n", err_code);
+ else
+ testapp_print(" finish sending. handle[%d]\n", handle);
+
+ email_free_mail(&mail, 1);
+ email_free_mailbox(&mailbox, 1);
+
+ return true;
+}
+
+static char *testapp_test_generate_random_string(int length)
+{
+ int i, string_length = length + 10, random_number, loop_cnt = length / 8;
+ char *result_string = NULL, temp_string[20] = { 0, };
+
+ result_string = em_core_malloc(string_length);
+
+ if (!result_string) {
+ return NULL;
+ }
+
+ memset(result_string, 0, string_length);
+ srand(time(NULL));
+
+ for(i = 0; i < loop_cnt; i++) {
+ random_number = rand() * rand();
+ snprintf(temp_string, 20, "%08x", random_number);
+ strcat(result_string, temp_string);
+ }
+
+ return result_string;
+}
+
+static gboolean testapp_test_add_mail ()
+{
+ int i = 0;
+ int account_id = 0;
+ int sync_server = 0;
+ int attachment_count = 0;
+ int err = EMF_ERROR_NONE;
+ char arg[50] = { 0 , };
+ char *body_file_path = "/opt/data/email/.emfdata/tmp/mail.txt";
+ emf_mailbox_t *mailbox_data = NULL;
+ emf_mail_data_t *test_mail_data = NULL;
+ emf_attachment_data_t *attachment_data = NULL;
+ emf_meeting_request_t *meeting_req = NULL;
+ FILE *body_file;
+
+ testapp_print("\n > Enter account id : ");
+ scanf("%d", &account_id);
+
+
+ memset(arg, 0x00, 50);
+ testapp_print("\n > Enter mailbox name : ");
+ scanf("%s", arg);
+
+ email_get_mailbox_by_name(account_id, arg, &mailbox_data);
+
+ test_mail_data = malloc(sizeof(emf_mail_data_t));
+ memset(test_mail_data, 0x00, sizeof(emf_mail_data_t));
+
+ testapp_print("\n Sync server? [0/1]> ");
+ scanf("%d", &sync_server);
+
+ test_mail_data->account_id = account_id;
+ test_mail_data->save_status = 1;
+ test_mail_data->flags_seen_field = 1;
+ test_mail_data->file_path_plain = strdup(body_file_path);
+ test_mail_data->mailbox_name = strdup(mailbox_data->name);
+ test_mail_data->mailbox_type = mailbox_data->mailbox_type;
+ test_mail_data->full_address_from = strdup("<test1@test.com>");
+ test_mail_data->full_address_to = strdup("<test2@test.com>");
+ test_mail_data->full_address_cc = strdup("<test3@test.com>");
+ test_mail_data->full_address_bcc = strdup("<test4@test.com>");
+ test_mail_data->subject = strdup("Meeting request mail");
+
+ body_file = fopen(body_file_path, "w");
+
+ for(i = 0; i < 500; i++)
+ fprintf(body_file, "X2 X2 X2 X2 X2 X2 X2");
+ fflush(body_file);
+ fclose(body_file);
+
+ testapp_print(" > Attach file? [0/1] : ");
+ scanf("%d",&attachment_count);
+
+ if ( attachment_count ) {
+ memset(arg, 0x00, 50);
+ testapp_print("\n > Enter attachment name : ");
+ scanf("%s", arg);
+
+ attachment_data = malloc(sizeof(emf_attachment_data_t));
+
+ attachment_data->attachment_name = strdup(arg);
+
+ memset(arg, 0x00, 50);
+ testapp_print("\n > Enter attachment absolute path : ");
+ scanf("%s",arg);
+
+ attachment_data->attachment_path = strdup(arg);
+ attachment_data->save_status = 1;
+ test_mail_data->attachment_count = attachment_count;
+ }
+
+ testapp_print("\n > Meeting Request? [0: no, 1: yes (request from server), 2: yes (response from local)]");
+ scanf("%d", &(test_mail_data->meeting_request_status));
+
+ if ( test_mail_data->meeting_request_status == 1
+ || test_mail_data->meeting_request_status == 2 ) {
+ time_t current_time;
+ /* dummy data for meeting request */
+ meeting_req = malloc(sizeof(emf_meeting_request_t));
+ memset(meeting_req, 0x00, sizeof(emf_meeting_request_t));
+
+ meeting_req->meeting_response = 1;
+ current_time = time(NULL);
+ gmtime_r(&current_time, &(meeting_req->start_time));
+ gmtime_r(&current_time, &(meeting_req->end_time));
+ meeting_req->location = malloc(strlen("Seoul") + 1);
+ memset(meeting_req->location, 0x00, strlen("Seoul") + 1);
+ strcpy(meeting_req->location, "Seoul");
+ strcpy(meeting_req->global_object_id, "abcdef12345");
+
+ meeting_req->time_zone.offset_from_GMT = 9;
+ strcpy(meeting_req->time_zone.standard_name, "STANDARD_NAME");
+ gmtime_r(&current_time, &(meeting_req->time_zone.standard_time_start_date));
+ meeting_req->time_zone.standard_bias = 3;
+
+ strcpy(meeting_req->time_zone.daylight_name, "DAYLIGHT_NAME");
+ gmtime_r(&current_time, &(meeting_req->time_zone.daylight_time_start_date));
+ meeting_req->time_zone.daylight_bias = 7;
+
+ }
+
+ if((err = email_add_mail(test_mail_data, attachment_data, attachment_count, meeting_req, sync_server)) != EMF_ERROR_NONE)
+ testapp_print("email_add_mail failed. [%d]\n", err);
+ else
+ testapp_print("email_add_mail success.\n");
+
+ if(attachment_data)
+ email_free_attachment_data(&attachment_data, attachment_count);
+
+ if(meeting_req)
+ email_free_meeting_request(&meeting_req, 1);
+
+ email_free_mail_data(&test_mail_data, 1);
+ email_free_mailbox(&mailbox_data, 1);
+
+ testapp_print("saved mail id = [%d]\n", test_mail_data->mail_id);
+
+ return FALSE;
+}
+
+static gboolean testapp_test_update_mail()
+{
+ int mail_id = 0;
+ int err = EMF_ERROR_NONE;
+ int test_attachment_data_count = 0;
+ char arg[50];
+ emf_mail_data_t *test_mail_data = NULL;
+ emf_attachment_data_t *test_attachment_data_list = NULL;
+ emf_meeting_request_t *meeting_req = NULL;
+
+ testapp_print("\n > Enter mail id : ");
+ scanf("%d", &mail_id);
+
+ email_get_mail_data(mail_id, &test_mail_data);
+
+ testapp_print("\n > Enter Subject: ");
+ scanf("%s", arg);
+
+ test_mail_data->subject= strdup(arg);
+
+
+
+ if (test_mail_data->attachment_count > 0) {
+ if ( (err = email_get_attachment_data_list(mail_id, &test_attachment_data_list, &test_attachment_data_count)) != EMF_ERROR_NONE ) {
+ testapp_print("email_get_meeting_request() failed [%d]\n", err);
+ return FALSE;
+ }
+ }
+
+ if ( test_mail_data->meeting_request_status == EMF_MAIL_TYPE_MEETING_REQUEST
+ || test_mail_data->meeting_request_status == EMF_MAIL_TYPE_MEETING_RESPONSE
+ || test_mail_data->meeting_request_status == EMF_MAIL_TYPE_MEETING_ORIGINATINGREQUEST) {
+
+ if ( (err = email_get_meeting_request(mail_id, &meeting_req)) != EMF_ERROR_NONE ) {
+ testapp_print("email_get_meeting_request() failed [%d]\n", err);
+ return FALSE;
+ }
+
+ testapp_print("\n > Enter meeting response: ");
+ scanf("%d", (int*)&(meeting_req->meeting_response));
+ }
+
+ if ( (err = email_update_mail(test_mail_data, test_attachment_data_list, test_attachment_data_count, meeting_req, 0)) != EMF_ERROR_NONE)
+ testapp_print("email_update_mail failed.[%d]\n", err);
+ else
+ testapp_print("email_update_mail success\n");
+
+ if(test_mail_data)
+ email_free_mail_data(&test_mail_data, 1);
+
+ if(test_attachment_data_list)
+ email_free_attachment_data(&test_attachment_data_list, test_attachment_data_count);
+
+ if(meeting_req)
+ email_free_meeting_request(&meeting_req, 1);
+
+ return TRUE;
+}
+
+
+static gboolean testapp_test_save_mail ()
+{
+ int account_id=0;
+ int i, j, from_composer = 0, mail_count = 0;
+ int attach_num = 0;
+ int err;
+ emf_mailbox_t *mailbox = NULL;
+ emf_mail_t *mail = malloc(sizeof(emf_mail_t));
+ emf_attachment_info_t attachment;
+ char arg[50], *temp_string_1 = NULL, *temp_string_2 = NULL, temp_address[512] = {0, };
+ emf_meeting_request_t *meeting_req = NULL;
+
+ testapp_print("\n > Enter account no:");
+ scanf("%d", &account_id);
+ memset(mail, 0x00, sizeof(emf_mail_t));
+ mail->info = malloc(sizeof(emf_mail_info_t));
+ memset(mail->info, 0x00, sizeof(emf_mail_info_t));
+ mail->info->account_id = account_id;
+ mail->info->extra_flags.text_download_yn = 1;
+ mail->info->flags.seen = 1;
+ mail->info->account_id = account_id;
+
+ mail->head = malloc(sizeof(emf_mail_head_t));
+ memset(mail->head, 0x00, sizeof(emf_mail_head_t));
+
+ mail->body = malloc(sizeof(emf_mail_body_t));
+ memset(mail->body, 0x00, sizeof(emf_mail_body_t));
+
+ FILE *pFile;
+ char *pFilePath = "/opt/data/email/.emfdata/tmp/mail.txt";
+
+ mail->body->plain = strdup(pFilePath);
+
+ mailbox = malloc(sizeof(emf_mailbox_t));
+ memset(mailbox, 0x00, sizeof(emf_mailbox_t));
+
+ memset(arg, 0x00, 50);
+ testapp_print("\n > Enter Mailbox:");
+ scanf("%s", arg);
+
+ mailbox->name = strdup(arg);
+ mailbox->account_id = account_id;
+
+ testapp_print(" Attach file 1/0 > ");
+ scanf("%d",&attach_num);
+ if ( attach_num ) {
+ memset(&attachment, 0x00, sizeof(emf_attachment_info_t));
+ memset(arg, 0x00, 50);
+ testapp_print("\n > Enter attachment name: ");
+ scanf("%s",arg);
+
+ attachment.name = strdup(arg);
+
+ memset(arg, 0x00, 50);
+ testapp_print("\n > Enter attachment absolute path: ");
+ scanf("%s",arg);
+
+ attachment.savename = strdup(arg);
+ attachment.downloaded = 1;
+ attachment.next = NULL;
+
+ mail->body->attachment = &attachment;
+ mail->body->attachment_num = attach_num;
+ }
+ /* set flag1 as seen */
+
+
+ testapp_print("\n From composer? (0/1)> ");
+ scanf("%d", &from_composer);
+
+ testapp_print("\n mail count? (n)> ");
+ scanf("%d", &mail_count);
+
+ testapp_print("\n > Meeting Request? (0: no, 1: yes (request from server), 2: yes (response from local) )");
+ scanf("%d", &(mail->info->is_meeting_request));
+ if ( mail->info->is_meeting_request == 1
+ || mail->info->is_meeting_request == 2 ) {
+ time_t current_time;
+
+ mail->head->from = strdup("<test@test.com>");
+ mail->head->to = strdup("\"ActiveSync8\" <ActiveSync8@test.local>");
+ mail->head->cc = strdup("<bapina@gawab.com>");
+ mail->head->bcc = strdup("<tom@gmail.com>");
+
+ mail->head->subject = strdup("save.mailbox...........");
+
+ /* dummy data for meeting request */
+ meeting_req = malloc(sizeof(emf_meeting_request_t));
+ memset(meeting_req, 0x00, sizeof(emf_meeting_request_t));
+
+ meeting_req->meeting_response = 1;
+ current_time = time(NULL);
+ gmtime_r(&current_time, &(meeting_req->start_time));
+ gmtime_r(&current_time, &(meeting_req->end_time));
+ meeting_req->location = malloc(strlen("Seoul") + 1);
+ memset(meeting_req->location, 0x00, strlen("Seoul") + 1);
+ strcpy(meeting_req->location, "Seoul");
+ strcpy(meeting_req->global_object_id, "abcdef12345");
+
+ meeting_req->time_zone.offset_from_GMT = 9;
+ strcpy(meeting_req->time_zone.standard_name, "STANDARD_NAME");
+ gmtime_r(&current_time, &(meeting_req->time_zone.standard_time_start_date));
+ meeting_req->time_zone.standard_bias = 3;
+
+ strcpy(meeting_req->time_zone.daylight_name, "DAYLIGHT_NAME");
+ gmtime_r(&current_time, &(meeting_req->time_zone.daylight_time_start_date));
+ meeting_req->time_zone.daylight_bias = 7;
+
+ if((err = email_add_message_with_meeting_request(mail, mailbox, meeting_req, from_composer)) < 0)
+ testapp_print("email_add_message failed. [%d]\n", err);
+ else
+ testapp_print("email_add_message success\n");
+ }
+ else {
+ mail->info->is_meeting_request = 0;
+
+ for(j = 0; j < mail_count; j++) {
+ pFile = fopen(pFilePath, "w");
+ for(i = 0; i < 500; i++)
+ fprintf(pFile, "X2 X2 X2 X2 X2 X2 X2");
+ fflush(pFile);
+ fclose(pFile);
+
+ temp_string_1 = testapp_test_generate_random_string(128);
+ temp_string_2 = testapp_test_generate_random_string(128);
+ if(temp_string_1 && temp_string_2) {
+ snprintf(temp_address, 512, "<%s@%s.com>", temp_string_1, temp_string_2);
+ free(temp_string_1);
+ free(temp_string_2);
+ temp_string_1 = NULL;
+ temp_string_2 = NULL;
+ }
+
+ mail->head->from = strdup(temp_address);
+
+ temp_string_1 = testapp_test_generate_random_string(128);
+ temp_string_2 = testapp_test_generate_random_string(128);
+ if(temp_string_1 && temp_string_2) {
+ snprintf(temp_address, 512, "<%s@%s.com>", temp_string_1, temp_string_2);
+ free(temp_string_1);
+ free(temp_string_2);
+ temp_string_1 = NULL;
+ temp_string_2 = NULL;
+
+ }
+
+ mail->head->to = strdup(temp_address);
+
+ temp_string_1 = testapp_test_generate_random_string(128);
+ temp_string_2 = testapp_test_generate_random_string(128);
+ if(temp_string_1 && temp_string_2) {
+ snprintf(temp_address, 512, "<%s@%s.com>", temp_string_1, temp_string_2);
+ free(temp_string_1);
+ free(temp_string_2);
+ temp_string_1 = NULL;
+ temp_string_2 = NULL;
+ }
+
+ mail->head->cc = strdup(temp_address);
+
+ temp_string_1 = testapp_test_generate_random_string(128);
+ temp_string_2 = testapp_test_generate_random_string(128);
+ if(temp_string_1 && temp_string_2) {
+ snprintf(temp_address, 512, "<%s@%s.com>", temp_string_1, temp_string_2);
+ free(temp_string_1);
+ free(temp_string_2);
+ temp_string_1 = NULL;
+ temp_string_2 = NULL;
+ }
+
+ mail->head->bcc = strdup(temp_address);
+
+ mail->head->subject = testapp_test_generate_random_string(128);
+
+ if((err = email_add_message(mail, mailbox, from_composer)) < 0)
+ testapp_print("email_add_message failed. [%d]\n", err);
+ else {
+ testapp_print("email_add_message success [%d/%d]\n", j, mail_count);
+ if(attach_num) {
+ testapp_print("attachment id[%d]\n", mail->body->attachment->attachment_id);
+ }
+ }
+ if(mail->head->from) free(mail->head->from);
+ if(mail->head->to) free(mail->head->to);
+ if(mail->head->cc) free(mail->head->cc);
+ if(mail->head->bcc) free(mail->head->bcc);
+ if(mail->head->subject) free(mail->head->subject);
+ }
+ }
+
+ testapp_print("saved mail id = [%d]\n", mail->info->uid);
+
+ return FALSE;
+}
+
+
+static gboolean testapp_test_mail_send ()
+{
+ FILE *fp;
+ emf_mailbox_t mbox;
+ emf_mail_t *mail = malloc(sizeof(emf_mail_t));
+ emf_mail_head_t *head = malloc(sizeof(emf_mail_head_t));
+ emf_mail_body_t *body = malloc(sizeof(emf_mail_body_t));
+ char arg[4096];
+ int i=0;
+ int account_id = 0;
+ emf_option_t option;
+ emf_attachment_info_t attachment;
+ int attach_num = 0;
+ int err = EMF_ERROR_NONE;;
+
+ memset(&option, 0x00, sizeof(emf_option_t));
+
+ memset(mail, 0x00, sizeof(emf_mail_t));
+ memset(head, 0x00, sizeof(emf_mail_head_t));
+ memset(body, 0x00, sizeof(emf_mail_body_t));
+
+ memset(arg, 0x00, 4096);
+ testapp_print(" mail to> ");
+ scanf("%s",arg);
+
+ if(arg[0]=='\0' || !strstr(arg, "@")) {
+ printf(" invalid argument");
+ return false;
+ }
+
+ for(i=0; i<strlen(arg); i++) {
+ if(arg[i]==';') arg[i] = ',';
+ }
+ head->to = malloc(strlen(arg)+1);
+ strcpy(head->to, arg);
+
+ head->from = strdup("<tom@gmail.com>");
+
+ /* head->to = strdup("&quot;test09&quot; <+ test09@gmail.com>"); */
+
+ memset(arg, 0x00, 4096);
+ testapp_print(" input subject> ");
+ scanf("%s",arg);
+
+ if(arg[0]=='\0') {
+ printf(" invalid argument");
+ return FALSE;
+ }
+ head->subject = malloc(strlen(arg)+1);
+ strcpy(head->subject, arg);
+
+ testapp_print("mail account_id >");
+ scanf("%d",&account_id);
+
+ memset(arg, 0x00, 4096);
+ testapp_print(" input body> ");
+ scanf("%s",arg);
+
+ if(arg[0]=='\0') {
+ printf(" invalid argument");
+ return FALSE;
+ }
+
+ fp = fopen(MAIL_TEMP_BODY, "w+");
+ fprintf(fp, arg);
+ fclose(fp);
+ body->plain = strdup(MAIL_TEMP_BODY);
+ mail->body = body;
+ mail->head = head;
+ mail->info = malloc(sizeof(emf_mail_info_t));
+ memset(mail->info, 0x00, sizeof(emf_mail_info_t));
+ mail->info->account_id = account_id;
+ mail->info->flags.draft = 1;
+ mail->info->extra_flags.priority = 4;
+
+ /* set flag1 as seen */
+ mail->info->flags.seen = 1;
+ testapp_print("\n > mail->info->flags:%d \n",mail->info->flags);
+
+ memset(&mbox, 0x00, sizeof(emf_mailbox_t));
+ mbox.account_id = account_id;
+ mbox.name = strdup("OUTBOX");
+
+ testapp_print(" Attach file 1/0 > ");
+ scanf("%d",&attach_num);
+ if ( attach_num ) {
+ memset(&attachment, 0x00, sizeof(emf_attachment_info_t));
+ memset(arg, 0x00, 4096);
+ testapp_print("\n > Enter attachment name: ");
+ scanf("%s",arg);
+
+ attachment.name = strdup(arg);
+
+ memset(arg, 0x00, 4096);
+ testapp_print("\n > Enter attachment absolute path: ");
+ scanf("%s",arg);
+
+ attachment.savename = strdup(arg);
+ attachment.next = NULL;
+
+ mail->body->attachment = &attachment;
+ mail->body->attachment_num = attach_num;
+ }
+
+ if(email_add_message(mail, &mbox, 1) < 0) {
+ testapp_print("email_add_message failed[%d]\n", err);
+ return FALSE;
+ }
+ else
+ testapp_print("email_add_message success\n");
+
+ testapp_print(" sending...\n");
+
+ unsigned handle = 0;
+ option.keep_local_copy = 1;
+
+ if( email_send_mail(&mbox, mail->info->uid, &option, &handle) < 0) {
+ testapp_print(" fail sending [%d]\n", err);
+ }
+ else {
+ testapp_print(" finish sending. handle[%d]\n", handle);
+ }
+
+ return FALSE;
+}
+
+static gboolean testapp_test_send_test (int *MailId)
+{
+
+ FILE *fp;
+ emf_mailbox_t mbox;
+ emf_mail_t *mail = malloc(sizeof(emf_mail_t));
+ emf_mail_head_t *head = malloc(sizeof(emf_mail_head_t));
+ emf_mail_body_t *body = malloc(sizeof(emf_mail_body_t));
+ char arg[4096];
+ int i=0;
+ int account_id = 0;
+ emf_option_t option;
+ emf_attachment_info_t attachment;
+ int attach_num = 0;
+ int err = EMF_ERROR_NONE;;
+
+ memset(&option, 0x00, sizeof(emf_option_t));
+
+ memset(mail, 0x00, sizeof(emf_mail_t));
+ memset(head, 0x00, sizeof(emf_mail_head_t));
+ memset(body, 0x00, sizeof(emf_mail_body_t));
+
+ memset(arg, 0x00, 4096);
+ testapp_print(" mail to> ");
+ scanf("%s",arg);
+
+ if(arg[0]=='\0' || !strstr(arg, "@")){
+ printf(" invalid argument");
+ return false;
+ }
+
+ for(i=0; i<strlen(arg); i++){
+ if(arg[i]==';') arg[i] = ',';
+ }
+ head->to = malloc(strlen(arg)+1);
+ strcpy(head->to, arg);
+
+ memset(arg, 0x00, 4096);
+ testapp_print(" input subject> ");
+ scanf("%s",arg);
+
+ if(arg[0]=='\0'){
+ printf(" invalid argument");
+ return FALSE;
+ }
+ head->subject = malloc(strlen(arg)+1);
+ strcpy(head->subject, arg);
+
+ testapp_print("mail account_id >");
+ scanf("%d",&account_id);
+
+ memset(arg, 0x00, 4096);
+ testapp_print(" input body> ");
+ scanf("%s",arg);
+
+ if(arg[0]=='\0'){
+ printf(" invalid argument");
+ return FALSE;
+ }
+
+ fp = fopen(MAIL_TEMP_BODY, "w+");
+ fprintf(fp, arg);
+ fclose(fp);
+ body->plain = strdup(MAIL_TEMP_BODY);
+ mail->body = body;
+ mail->head = head;
+ mail->info = malloc(sizeof(emf_mail_info_t));
+ memset(mail->info, 0x00, sizeof(emf_mail_info_t));
+ mail->info->account_id = account_id;
+ mail->info->flags.draft = 1;
+
+ /* set flag1 as seen */
+ mail->info->flags.seen = 1;
+ testapp_print("\n > mail->info->flags:%d \n",mail->info->flags);
+
+ memset(&mbox, 0x00, sizeof(emf_mailbox_t));
+ mbox.account_id = account_id;
+ mbox.name = strdup("OUTBOX");
+
+ testapp_print(" Attach file 1/0 > ");
+ scanf("%d",&attach_num);
+ if ( attach_num ) {
+ memset(&attachment, 0x00, sizeof(emf_attachment_info_t));
+ memset(arg, 0x00, 4096);
+ testapp_print("\n > Enter attachment name: ");
+ scanf("%s",arg);
+
+ attachment.name = strdup(arg);
+
+ memset(arg, 0x00, 4096);
+ testapp_print("\n > Enter attachment absolute path: ");
+ scanf("%s",arg);
+
+ attachment.savename = strdup(arg);
+ attachment.next = NULL;
+
+ mail->body->attachment = &attachment;
+ mail->body->attachment_num = attach_num;
+ }
+
+ if(email_add_message(mail, &mbox, 1) < 0) {
+ testapp_print("email_add_message failed[%d]\n", err);
+ return FALSE;
+ }
+ else
+ testapp_print("email_add_message success\n");
+
+ testapp_print(" sending...\n");
+
+ unsigned handle = 0;
+ option.keep_local_copy = 1;
+ email_send_mail(&mbox, mail->info->uid, &option, &handle);
+ *MailId = mail->info->uid;
+ testapp_print("*MailId[%d]\n",*MailId);
+ printf("*MailId[%d]\n",*MailId);
+ testapp_print("handle[%d]\n", handle);
+ return FALSE;
+}
+
+static gboolean testapp_test_send_cancel ()
+{
+ int num = 0;
+ int Y = 0;
+ int i = 0;
+ int j = 0;
+ int *mailIdList = NULL;
+ int mail_id = 0;
+
+ testapp_print("\n > Enter total Number of mail want to send: ");
+ scanf("%d", &num);
+ mailIdList = (int *)malloc(sizeof(int)*num);
+ if(!mailIdList)
+ return false ;
+
+ for(i = 1;i <=num ; i++) {
+ testapp_test_send_test(&mail_id);
+
+ testapp_print("mail_id[%d]",mail_id);
+
+ mailIdList[i] = mail_id;
+ testapp_print("mailIdList[%d][%d]",i,mailIdList[i]);
+
+ mail_id = 0;
+ testapp_print("\n > Do you want to cancel the send mail job '1' or '0': ");
+ scanf("%d", &Y);
+ if(Y == 1) {
+ testapp_print("\n >Enter mail-id[1-%d] ",i);
+ scanf("%d", &j);
+ testapp_print("\n mailIdList[%d] ",mailIdList[j]);
+ if(email_cancel_send_mail( mailIdList[j]) < 0)
+ testapp_print("EmfMailSendCancel failed..!");
+ else
+ testapp_print("EmfMailSendCancel success..!");
+ }
+ }
+ return FALSE;
+}
+
+static gboolean testapp_test_send_mail_with_option ()
+{
+ FILE *fp;
+ emf_mailbox_t mbox;
+ emf_mail_t *mail = malloc(sizeof(emf_mail_t));
+ emf_mail_head_t *head = malloc(sizeof(emf_mail_head_t));
+ emf_mail_body_t *body = malloc(sizeof(emf_mail_body_t));
+ char arg[4096];
+ int i=0;
+ int account_id = 0;
+ emf_option_t option;
+ emf_attachment_info_t attachment;
+ int attach_num = 0;
+
+ memset(&option, 0x00, sizeof(emf_option_t));
+
+ memset(mail, 0x00, sizeof(emf_mail_t));
+ memset(head, 0x00, sizeof(emf_mail_head_t));
+ memset(body, 0x00, sizeof(emf_mail_body_t));
+
+ memset(arg, 0x00, 4096);
+ testapp_print(" mail to> ");
+ scanf("%s",arg);
+ if(arg[0]=='\0' || !strstr(arg, "@")){
+ printf(" invalid argument");
+ return false;
+ }
+ for(i=0; i<strlen(arg); i++){
+ if(arg[i]==';') arg[i] = ',';
+ }
+ head->to = malloc(strlen(arg)+1);
+ strcpy(head->to, arg);
+
+ memset(arg, 0x00, 4096);
+ testapp_print(" input subject> ");
+ scanf("%s",arg);
+
+ if(arg[0]=='\0'){
+ printf(" invalid argument");
+ return FALSE;
+ }
+ head->subject = malloc(strlen(arg)+1);
+ strcpy(head->subject, arg);
+
+ testapp_print("mail account_id >");
+ scanf("%d",&account_id);
+
+ memset(arg, 0x00, 4096);
+ testapp_print(" input body> ");
+ scanf("%s",arg);
+
+ if(arg[0]=='\0'){
+ printf(" invalid argument");
+ return FALSE;
+ }
+
+ fp = fopen(MAIL_TEMP_BODY, "w+");
+ fprintf(fp, arg);
+ fclose(fp);
+ body->plain = strdup(MAIL_TEMP_BODY);
+ mail->body = body;
+ mail->head = head;
+ mail->info = malloc(sizeof(emf_mail_info_t));
+ memset(mail->info, 0x00, sizeof(emf_mail_info_t));
+ mail->info->account_id = account_id;
+ mail->info->flags.draft = 1;
+
+ /* set flag1 as seen */
+ mail->info->flags.seen = 1;
+ testapp_print("\n > mail->info->flags:%d ",mail->info->flags);
+
+ memset(&mbox, 0x00, sizeof(emf_mailbox_t));
+ mbox.account_id = account_id;
+ mbox.name = strdup("OUTBOX");
+
+ testapp_print(" Attach file 1/0 > ");
+ scanf("%d",&attach_num);
+ if ( attach_num ) {
+ memset(&attachment, 0x00, sizeof(emf_attachment_info_t));
+ memset(arg, 0x00, 4096);
+ testapp_print("\n > Enter attachment name: ");
+ scanf("%s",arg);
+
+ attachment.name = strdup(arg);
+
+ memset(arg, 0x00, 4096);
+ testapp_print("\n > Enter attachment absolute path: ");
+ scanf("%s",arg);
+
+ attachment.savename = strdup(arg);
+ attachment.next = NULL;
+
+ mail->body->attachment = &attachment;
+ mail->body->attachment_num = attach_num;
+ }
+
+ testapp_print("Keep local copy? (1=true, 0=false)");
+ scanf("%d",&option.keep_local_copy);
+
+ testapp_print("Request delivery receipt? (1=true, 0=false)");
+ scanf("%d",&option.req_delivery_receipt);
+
+ testapp_print("Request read receipt? (1=true, 0=false)");
+ scanf("%d",&option.req_read_receipt);
+
+ if(email_add_message(mail, &mbox, 1) < 0) {
+ testapp_print("email_add_message failed\n");
+ }
+ else
+ testapp_print("email_add_message success\n");
+
+ testapp_print(" sending...\n");
+
+ unsigned handle = 0;
+
+
+ if(email_send_mail(&mbox, mail->info->uid, &option, &handle) < 0) {
+ testapp_print(" fail sending\n");
+ } else {
+ testapp_print(" finish sending\n");
+ testapp_print("handle[%d]\n", handle);
+ }
+
+ return FALSE;
+}
+
+static gboolean testapp_test_download()
+{
+
+ emf_mailbox_t mbox;
+ int account_id = 0;
+ char arg[50];
+ unsigned handle = 0;
+ testapp_print("\n > Enter Account id (0: for all account) : ");
+ scanf("%d",&account_id);
+
+ memset(arg, 0x00, 50);
+ testapp_print("\n > Enter Mailbox name (ALL: for all mailboxes) : ");
+ scanf("%s",arg);
+
+ memset(&mbox, 0x00, sizeof(emf_mailbox_t));
+
+ mbox.account_id = account_id;
+
+ if(strcmp("ALL", arg) == 0)
+ mbox.name = NULL;
+ else
+ mbox.name = strdup(arg);
+
+ if(account_id == ALL_ACCOUNT) {
+ if(email_sync_header_for_all_account(&handle) < 0)
+ testapp_print("\n email_sync_header_for_all_account failed\n");
+ else
+ testapp_print("\n email_sync_header_for_all_account success. Handle[%d]\n", handle);
+ }
+ else {
+ if(email_sync_header(&mbox,&handle) < 0)
+ testapp_print("\n email_sync_header failed\n");
+ else
+ testapp_print("\n email_sync_header success. Handle[%d]\n", handle);
+ }
+
+ return FALSE;
+}
+
+static gboolean testapp_test_delete()
+{
+ int mail_id=0, account_id =0;
+ emf_mailbox_t mbox = {0};
+ char arg[10];
+ int err = EMF_ERROR_NONE;
+ int from_server = 0;
+
+ testapp_print("\n > Enter Account_id: ");
+ scanf("%d",&account_id);
+
+ testapp_print("\n > Enter Mail_id: ");
+ scanf("%d",&mail_id);
+
+ testapp_print("\n > Enter Mailbox name: ");
+ scanf("%s",arg);
+
+ testapp_print("\n > Enter from_server: ");
+ scanf("%d",&from_server);
+
+ mbox.account_id = account_id;
+ mbox.name = strdup(arg);
+
+
+ /* delete message */
+ if( (err = email_delete_message(&mbox, &mail_id, 1, from_server)) < 0)
+ testapp_print("\n email_delete_message failed[%d]\n", err);
+ else
+ testapp_print("\n email_delete_message success\n");
+
+ if ( mbox.name )
+ free(mbox.name);
+
+ return FALSE;
+}
+
+static gboolean testapp_test_get_mailbox_list ()
+{
+
+ int account_id =0;
+ int mailbox_sync_type;
+ int count = 0;
+ int i = 0, error_code = EMF_ERROR_NONE;
+ emf_mailbox_t *mailbox_list=NULL;
+ testapp_print("\n > Enter account id: ");
+ scanf("%d", &account_id);
+ testapp_print("\n > Enter mailbox_sync_type\n[-1 :for all mailboxes, 0 : for mailboxes from server, 1 : local mailboxes\n : ");
+ scanf("%d", &mailbox_sync_type);
+
+ if((error_code = email_get_mailbox_list(account_id, mailbox_sync_type, &mailbox_list, &count)) < 0) {
+ testapp_print(" email_get_mailbox_list error %d\n", error_code);
+ return false ;
+ }
+
+ testapp_print("There are %d mailboxes\n", count);
+
+ testapp_print("============================================================================\n");
+ testapp_print("number\taccount_id\t name\t\t alias\t local_yn\t unread\tmailbox_type\t has_archived_mails\n");
+ testapp_print("============================================================================\n");
+ if ( count == 0 ) {
+ testapp_print("No mailbox is matched\n");
+ }
+ else {
+ for(i=0;i<count;i++) {
+ testapp_print("[%d] - ", i);
+ testapp_print(" %2d\t [%-15s]\t[%-15s]\t", mailbox_list[i].account_id, mailbox_list[i].name, mailbox_list[i].alias);
+ testapp_print(" %d\t %d\t %d\n", mailbox_list[i].local, mailbox_list[i].unread_count,mailbox_list[i].mailbox_type, mailbox_list[i].has_archived_mails);
+ }
+ }
+ testapp_print("============================================================================\n");
+ /* EmfMailboxFree(emf_mailbox_t** mailbox_list, int count, int* err_code) */
+
+ if((error_code = email_get_mailbox_list_ex(account_id, mailbox_sync_type, 1, &mailbox_list, &count)) < 0) {
+ testapp_print(" email_get_mailbox_list_ex error %d\n", error_code);
+ return false ;
+ }
+
+ testapp_print("There are %d mailboxes\n", count);
+
+ testapp_print("============================================================================\n");
+ testapp_print("number\taccount_id\t name\t\t alias\t local_yn\t unread\t total\t total_on_ server\tmailbox_type\t has_archived_mails\n");
+ testapp_print("============================================================================\n");
+ if ( count == 0 ) {
+ testapp_print("No mailbox is matched\n");
+ }
+ else {
+ for(i=0;i<count;i++) {
+ testapp_print("[%d] - ", i);
+ testapp_print(" %2d\t [%-15s]\t[%-15s]\t", mailbox_list[i].account_id, mailbox_list[i].name, mailbox_list[i].alias);
+ testapp_print(" %d\t %d\t %d\t %d\t %d\t %d\n", mailbox_list[i].local, mailbox_list[i].unread_count, mailbox_list[i].total_mail_count_on_local, mailbox_list[i].total_mail_count_on_server, mailbox_list[i].mailbox_type, mailbox_list[i].has_archived_mails);
+ }
+ }
+ testapp_print("============================================================================\n");
+ testapp_print("Start to free\n");
+
+ email_free_mailbox(&mailbox_list, count);
+ return FALSE;
+}
+
+static gboolean testapp_test_move()
+{
+ int mail_id[3];
+ int account_id =0;
+ emf_mailbox_t mbox;
+ char arg[10];
+ int i = 0;
+
+ testapp_print("\n > Enter Account_id: ");
+ scanf("%d",&account_id);
+
+ for(i = 0; i< 3; i++) {
+ testapp_print("\n > Enter Mail_id: ");
+ scanf("%d",&mail_id[i]);
+ }
+
+ memset(&mbox, 0x00, sizeof(emf_mailbox_t));
+
+ testapp_print("\n > Enter Mailbox name: ");
+ scanf("%s",arg);
+ mbox.account_id = account_id;
+ mbox.name = strdup(arg);
+ /* move message */
+ email_move_mail_to_mailbox(mail_id, 3, &mbox);
+ return FALSE;
+}
+
+static gboolean testapp_test_delete_all()
+{
+ int account_id =0;
+ emf_mailbox_t mbox = {0};
+ char arg[100] = {0};
+ int err = EMF_ERROR_NONE;
+ testapp_print("\n > Enter Account_id: ");
+ scanf("%d",&account_id);
+
+ testapp_print("\n > Enter Mailbox name: ");
+ scanf("%s",arg);
+
+ mbox.account_id = account_id;
+ mbox.name = strdup(arg);
+
+ /* delete all message */
+ if ( (err = email_delete_all_message_in_mailbox(&mbox, 0)) < 0)
+ testapp_print("email_delete_all_message_in_mailbox failed[%d]\n", err);
+ else
+ testapp_print("email_delete_all_message_in_mailbox Success\n");
+
+ return FALSE;
+}
+
+
+static gboolean testapp_test_add_attachment()
+{
+ int account_id = 0;
+ int mail_id = 0;
+ char arg[100];
+ emf_mailbox_t mbox;
+ emf_attachment_info_t attachment;
+
+ testapp_print("\n > Enter Mail Id: ");
+ scanf("%d", &mail_id);
+
+ testapp_print("\n > Enter Account_id: ");
+ scanf("%d",&account_id);
+
+ memset(arg, 0x00, 100);
+ testapp_print("\n > Enter Mailbox name: ");
+ scanf("%s",arg);
+
+ memset(&mbox, 0x00, sizeof(emf_attachment_info_t));
+ mbox.account_id = account_id;
+ mbox.name = strdup(arg);
+
+ memset(&attachment, 0x00, sizeof(emf_attachment_info_t));
+ memset(arg, 0x00, 100);
+ testapp_print("\n > Enter attachment name: ");
+ scanf("%s",arg);
+
+ attachment.name = strdup(arg);
+
+ memset(arg, 0x00, 100);
+ testapp_print("\n > Enter attachment absolute path: ");
+ scanf("%s",arg);
+
+ attachment.downloaded = true;
+ attachment.savename = strdup(arg);
+ attachment.next = NULL;
+ if(email_add_attachment( &mbox, mail_id, &attachment) < 0)
+ testapp_print("email_add_attachment failed\n");
+ else
+ testapp_print("email_add_attachment success\n");
+
+
+ return FALSE;
+
+}
+
+static gboolean testapp_test_update()
+{
+ emf_mailbox_t mailbox;
+ emf_mail_t *mail = NULL;
+ int mail_id = 0;
+ int err = EMF_ERROR_NONE;
+ char arg[50];
+
+ memset(&mailbox, 0x00, sizeof(emf_mailbox_t));
+
+ testapp_print("\n > Enter Mail Id: ");
+ scanf("%d", &mail_id);
+
+ if (email_get_mail(&mailbox, mail_id, &mail) < 0) {
+ testapp_print("email_get_mail failed\n");
+ return FALSE;
+ }
+
+ testapp_print("\n > Enter Subject: ");
+ scanf("%s", arg);
+
+ mail->head->subject= strdup(arg);
+
+ if (mail->body && mail->body->attachment) {
+ emf_attachment_info_t* p = mail->body->attachment;
+ struct stat st_buf;
+
+ while (p) {
+ if (!p->savename || stat(p->savename, &st_buf) < 0) {
+ testapp_print("\t stat(\"%s\" failed...\n", p->savename);
+
+ err = EMF_ERROR_INVALID_PARAM; /* TODO: confirm me */
+ goto FINISH_OFF;
+ }
+
+ p->downloaded = 1;
+
+ p = p->next;
+ }
+ }
+
+ if ( mail->info->is_meeting_request == EMF_MAIL_TYPE_MEETING_REQUEST
+ || mail->info->is_meeting_request == EMF_MAIL_TYPE_MEETING_RESPONSE
+ || mail->info->is_meeting_request == EMF_MAIL_TYPE_MEETING_ORIGINATINGREQUEST) {
+ emf_meeting_request_t *meeting_req = NULL;
+ if ( (err = email_get_meeting_request(mail_id, &meeting_req)) < 0 ) {
+ testapp_print("email_get_meeting_request() failed\n");
+ return FALSE;
+ }
+
+ testapp_print("\n > Enter meeting response: ");
+ scanf("%d", (int*)&(meeting_req->meeting_response));
+ if ( (err = email_update_message_with_meeting_request(mail_id, mail, meeting_req)) < 0)
+ testapp_print("email_update_message failed.[%d]\n", err);
+ else
+ testapp_print("email_update_message success\n");
+
+ email_free_meeting_request(&meeting_req, 1);
+ }
+ else {
+ if (email_update_message(mail_id, mail) < 0)
+ testapp_print("email_update_message failed.[%d]\n", err);
+ else
+ testapp_print("email_update_message success\n");
+ }
+
+FINISH_OFF:
+
+ return FALSE;
+
+}
+
+
+static gboolean testapp_test_get_mail_list_ex()
+{
+ testapp_print(" >>> testapp_test_get_mail_list_ex : Entered \n");
+ emf_mail_list_item_t *mail_list = NULL, **mail_list_pointer = NULL;
+ char mailbox_name[50];
+ int count = 0, i = 0;
+ int account_id = 0;
+ int start_index =0;
+ int limit_count = 0;
+ int sorting = 0;
+ int err_code = EMF_ERROR_NONE;
+ int to_get_count = 0;
+ int is_for_thread_view = 0;
+ int list_type;
+
+ memset(mailbox_name, 0x00, 10);
+ testapp_print("\n > Enter Mailbox name (0 = all mailboxes) :");
+ scanf("%s", mailbox_name);
+
+ testapp_print("\n > Enter Account_id (0 = all accounts) : ");
+ scanf("%d",&account_id);
+
+ testapp_print("\n > Enter Sorting : ");
+ scanf("%d",&sorting);
+
+ testapp_print("\n > Enter Start index : ");
+ scanf("%d",&start_index);
+
+ testapp_print("\n > Enter max_count : ");
+ scanf("%d",&limit_count);
+
+ testapp_print("\n > For thread view : ");
+ scanf("%d",&is_for_thread_view);
+
+ testapp_print("\n > To get count : ");
+ scanf("%d",&to_get_count);
+
+ if(to_get_count)
+ mail_list_pointer = NULL;
+ else
+ mail_list_pointer = &mail_list;
+
+ if(is_for_thread_view == -2) {
+ list_type = EMF_LIST_TYPE_LOCAL;
+ }
+ else if(is_for_thread_view == -1)
+ list_type = EMF_LIST_TYPE_THREAD;
+ else
+ list_type = EMF_LIST_TYPE_NORMAL;
+
+ /* Get mail list */
+ if(strcmp(mailbox_name, "0") == 0) {
+ testapp_print("Calling email_get_mail_list_ex for all mailbox.\n");
+ err_code = email_get_mail_list_ex(account_id, NULL, list_type, start_index, limit_count, sorting, mail_list_pointer, &count);
+ if ( err_code < 0)
+ testapp_print("email_get_mail_list_ex failed - err[%d]\n", err_code);
+ }
+ else {
+ testapp_print("Calling email_get_mail_list_ex for %s mailbox.\n", mailbox_name);
+ err_code = email_get_mail_list_ex(account_id, mailbox_name, list_type, start_index, limit_count, sorting, mail_list_pointer, &count);
+ if ( err_code < 0)
+ testapp_print("email_get_mail_list_ex failed - err[%d]\n", err_code);
+ }
+ testapp_print("email_get_mail_list_ex >>>>>>count - %d\n",count);
+
+ if (mail_list) {
+ for (i=0; i< count; i++) {
+ testapp_print("\n[%d]\n", i);
+ testapp_print(" >>> mailbox_name [ %s ] \n", mail_list[i].mailbox_name);
+ testapp_print(" >>> mail_id [ %d ] \n", mail_list[i].mail_id);
+ testapp_print(" >>> account_id [ %d ] \n", mail_list[i].account_id);
+ if ( mail_list[i].from != NULL )
+ testapp_print(" >>> From [ %s ] \n", mail_list[i].from);
+ if ( mail_list[i].recipients != NULL )
+ testapp_print(" >>> recipients [ %s ] \n", mail_list[i].recipients);
+ if ( mail_list[i].subject != NULL )
+ testapp_print(" >>> subject [ %s ] \n", mail_list[i].subject);
+ testapp_print(" >>> is_text_downloaded [ %d ] \n", mail_list[i].is_text_downloaded);
+ if ( mail_list[i].datetime != NULL )
+ testapp_print(" >>> datetime [ %s ] \n", mail_list[i].datetime);
+ testapp_print(" >>> flags_seen_field [ %d ] \n", mail_list[i].flags_seen_field);
+ testapp_print(" >>> priority [ %d ] \n", mail_list[i].priority);
+ testapp_print(" >>> save_status [ %d ] \n", mail_list[i].save_status);
+ testapp_print(" >>> is_locked [ %d ] \n", mail_list[i].is_locked);
+ testapp_print(" >>> has_attachment [ %d ] \n", mail_list[i].has_attachment);
+ if ( mail_list[i].previewBodyText != NULL )
+ testapp_print(" >>> previewBodyText [ %s ] \n", mail_list[i].previewBodyText);
+ }
+ free(mail_list);
+ }
+
+ testapp_print(" >>> email_get_mail_list_ex : End \n");
+ return 0;
+}
+
+
+static gboolean testapp_test_get_mail_list_for_thread_view()
+{
+ testapp_print(" >>> testapp_test_get_mail_list_for_thread_view : Entered \n");
+ emf_mail_list_item_t *mail_list = NULL;
+ int count = 0, i = 0;
+ int account_id = 0;
+ int err_code = EMF_ERROR_NONE;
+
+ /* Get mail list */
+ if ( email_get_mail_list_ex(account_id, NULL , EMF_LIST_TYPE_THREAD, 0, 500, EMF_SORT_DATETIME_HIGH, &mail_list, &count) < 0) {
+ testapp_print("email_get_mail_list_ex failed : %d\n",err_code);
+ return FALSE;
+ }
+ testapp_print("email_get_mail_list_ex >>>>>>count - %d\n",count);
+ if (mail_list) {
+ for (i=0; i< count; i++) {
+ testapp_print(" i [%d]\n", i);
+ testapp_print(" >>> Mail ID [ %d ] \n", mail_list[i].mail_id);
+ testapp_print(" >>> Account ID [ %d ] \n", mail_list[i].account_id);
+ testapp_print(" >>> Mailbox Name [ %s ] \n", mail_list[i].mailbox_name);
+ testapp_print(" >>> From [ %s ] \n", mail_list[i].from);
+ testapp_print(" >>> recipients [ %s ] \n", mail_list[i].recipients);
+ testapp_print(" >>> subject [ %s ] \n", mail_list[i].subject);
+ testapp_print(" >>> is_text_downloaded [ %d ] \n", mail_list[i].is_text_downloaded);
+ testapp_print(" >>> datetime [ %s ] \n", mail_list[i].datetime);
+ testapp_print(" >>> flags_seen_field [ %d ] \n", mail_list[i].flags_seen_field);
+ testapp_print(" >>> priority [ %d ] \n", mail_list[i].priority);
+ testapp_print(" >>> save_status [ %d ] \n", mail_list[i].save_status);
+ testapp_print(" >>> lock [ %d ] \n", mail_list[i].is_locked);
+ testapp_print(" >>> has_attachment [ %d ] \n", mail_list[i].has_attachment);
+ testapp_print(" >>> previewBodyText [ %s ] \n", mail_list[i].previewBodyText);
+ testapp_print(" >>> thread_id [ %d ] \n", mail_list[i].thread_id);
+ testapp_print(" >>> thread__item_count [ %d ] \n", mail_list[i].thread_item_count);
+ }
+ free(mail_list);
+ }
+ testapp_print(" >>> testapp_test_get_mail_list_for_thread_view : End \n");
+ return 0;
+}
+
+
+static gboolean testapp_test_get ()
+{
+
+ emf_mailbox_t mailbox;
+ emf_mail_t *mail = NULL;
+ int mail_id = 0;
+ int err = EMF_ERROR_NONE;
+
+ memset(&mailbox, 0x00, sizeof(emf_mailbox_t));
+
+ testapp_print("\n > Enter Mail Id: ");
+ scanf("%d", &mail_id);
+
+ if ( (err = email_get_mail(&mailbox, mail_id, &mail)) < 0)
+ testapp_print("email_get_mail failed[%d]\n", err);
+ else {
+ testapp_print("email_get_mail success\n");
+ testapp_print("preview : [%s]\n", mail->head->previewBodyText);
+
+ emf_meeting_request_t *meeting_req = NULL;
+ testapp_print("mail->info->is_meeting_request[%d]\n", mail->info->is_meeting_request);
+ if ( mail->info->is_meeting_request != 0 ) {
+ if ( (err = email_get_meeting_request(mail->info->uid, &meeting_req)) < 0 ) {
+ testapp_print("email_get_meeting_request() failed[%d]\n", err);
+ }
+ else {
+ testapp_print("email_get_meeting_request() success\n");
+ testapp_print(">>>>> meeting_req->mail_id[%d]\n", meeting_req->mail_id);
+ testapp_print(">>>>> meeting_req->meeting_response[%d]\n", meeting_req->meeting_response);
+ testapp_print(">>>>> meeting_req->start_time[%s]\n", asctime(&(meeting_req->start_time)));
+ testapp_print(">>>>> meeting_req->end_time[%s]\n", asctime(&(meeting_req->end_time)));
+ testapp_print(">>>>> meeting_req->location[%s]\n", meeting_req->location);
+ testapp_print(">>>>> meeting_req->global_object_id[%s]\n", meeting_req->global_object_id);
+ testapp_print(">>>>> meeting_req->time_zone.offset_from_GMT[%d]\n", meeting_req->time_zone.offset_from_GMT);
+ testapp_print(">>>>> meeting_req->time_zone.standard_name[%s]\n", meeting_req->time_zone.standard_name);
+ testapp_print(">>>>> meeting_req->time_zone.standard_time_start_date[%s]\n", asctime(&(meeting_req->time_zone.standard_time_start_date)));
+ testapp_print(">>>>> meeting_req->time_zone.standard_bias[%d]\n", meeting_req->time_zone.standard_bias);
+ testapp_print(">>>>> meeting_req->time_zone.daylight_name[%s]\n", meeting_req->time_zone.daylight_name);
+ testapp_print(">>>>> meeting_req->time_zone.daylight_time_start_date[%s]\n", asctime(&(meeting_req->time_zone.daylight_time_start_date)));
+ testapp_print(">>>>> meeting_req->time_zone.daylight_bias[%d]\n", meeting_req->time_zone.daylight_bias);
+ }
+ }
+
+ if ( meeting_req != NULL )
+ email_free_meeting_request(&meeting_req, 1);
+ }
+
+ if ( mail )
+ email_free_mail(&mail, 1);
+
+ return TRUE;
+}
+
+static gboolean testapp_test_get_info()
+{
+ emf_mailbox_t mailbox;
+ emf_mail_info_t *mail_info = NULL;
+ int mail_id = 0,account_id = 0;
+
+ memset(&mailbox, 0x00, sizeof(emf_mailbox_t));
+
+ testapp_print("\n > Enter Mail Id: ");
+ scanf("%d", &mail_id);
+
+ testapp_print("\n > Enter account Id: ");
+ scanf("%d", &account_id);
+
+ mailbox.account_id = account_id;
+ if (email_get_info(&mailbox, mail_id, &mail_info) < 0)
+ testapp_print("email_get_info failed\n");
+ else
+ testapp_print("email_get_info SUCCESS\n");
+
+ if (mail_info != NULL) {
+ em_core_mail_info_free(&mail_info, 1, NULL);
+ }
+ return TRUE;
+}
+
+
+static gboolean testapp_test_get_header ()
+{
+ emf_mailbox_t mailbox;
+ emf_mail_head_t *head = NULL;
+ int mail_id = 0,account_id = 0;
+
+ memset(&mailbox, 0x00, sizeof(emf_mailbox_t));
+
+ testapp_print("\n > Enter Mail Id: ");
+ scanf("%d", &mail_id);
+
+ testapp_print("\n > Enter account Id: ");
+ scanf("%d", &account_id);
+
+ mailbox.account_id = account_id;
+
+ if ( email_get_header_info(&mailbox, mail_id, &head) < 0) {
+ testapp_print("email_get_header_info failed\n");
+ return FALSE;
+ }
+ else
+ testapp_print("email_get_header_info SUCCESS\n");
+
+ if(head->subject)
+ testapp_print("\n subject : %s", head->subject);
+ if(head->from)
+ testapp_print("\n from : %s", head->from);
+ if(head->reply_to)
+ testapp_print("\n reply_to : %s", head->reply_to);
+
+ return TRUE;
+}
+
+static gboolean testapp_test_get_body ()
+{
+ emf_mailbox_t mailbox;
+ emf_mail_body_t *body = NULL;
+ int mail_id = 0,account_id = 0;
+
+ memset(&mailbox, 0x00, sizeof(emf_mailbox_t));
+
+ testapp_print("\n > Enter Mail Id: ");
+ scanf("%d", &mail_id);
+
+ testapp_print("\n > Enter account Id: ");
+ scanf("%d", &account_id);
+
+ mailbox.account_id = account_id;
+
+ if ( email_get_body_info(&mailbox, mail_id, &body) < 0)
+ testapp_print("email_get_body_info failed\n");
+ else
+ testapp_print("email_get_body_info SUCCESS\n");
+
+ return TRUE;
+}
+
+static gboolean testapp_test_count ()
+{
+ emf_mailbox_t mailbox;
+ int account_id = 0;
+ int total = 0;
+ int unseen = 0;
+ char arg[50];
+
+ memset(&mailbox, 0x00, sizeof(emf_mailbox_t));
+
+ testapp_print("\n > Enter account_id (0 means all accounts) : ");
+ scanf("%d", &account_id);
+
+ if(account_id == 0) {
+ mailbox.name = NULL;
+ }
+ else {
+ testapp_print("\n > Enter maibox name: ");
+ scanf("%s", arg);
+ mailbox.name = strdup(arg);
+ }
+
+ mailbox.account_id = account_id;
+ if(email_count_message(&mailbox, &total, &unseen) >= 0)
+ testapp_print("\n Total: %d, Unseen: %d \n", total, unseen);
+
+ return TRUE;
+}
+
+static gboolean testapp_test_modify_flag()
+{
+ emf_mail_flag_t newflag;
+ int mail_id = 0;
+
+ memset(&newflag, 0x00, sizeof(emf_mail_flag_t));
+ newflag.seen = 1;
+ newflag.answered = 0;
+ newflag.sticky = 1;
+
+ testapp_print("\n > Enter Mail Id: ");
+ scanf("%d", &mail_id);
+
+ if(email_modify_mail_flag(mail_id, newflag, 1) < 0)
+ testapp_print("email_modify_mail_flag failed");
+ else
+ testapp_print("email_modify_mail_flag success");
+
+ return TRUE;
+}
+
+static gboolean testapp_test_modify_extra_flag ()
+{
+ emf_extra_flag_t newflag;
+ int mail_id = 0;
+
+ memset(&newflag, 0x00, sizeof(emf_extra_flag_t));
+
+ testapp_print("\n > Enter Mail Id: ");
+ scanf("%d", &mail_id);
+
+ if( email_modify_extra_mail_flag(mail_id, newflag) < 0)
+ testapp_print("email_modify_extra_mail_flag failed");
+ else
+ testapp_print("email_modify_extra_mail_flag success");
+ return TRUE;
+}
+
+static gboolean testapp_test_set_flags_field ()
+{
+ int account_id = 0;
+ int mail_id = 0;
+
+ testapp_print("\n > Enter Account ID: ");
+ scanf("%d", &account_id);
+
+ testapp_print("\n > Enter Mail ID: ");
+ scanf("%d", &mail_id);
+
+ if(email_set_flags_field(account_id, &mail_id, 1, EMF_FLAGS_FLAGGED_FIELD, 1, 1) < 0)
+ testapp_print("email_set_flags_field failed");
+ else
+ testapp_print("email_set_flags_field success");
+
+ return TRUE;
+}
+
+static gboolean testapp_test_download_body ()
+{
+ int mail_id = 0;
+ int account_id = 0;
+ char arg[50];
+ unsigned handle = 0, err;
+
+ emf_mailbox_t mailbox;
+ memset(&mailbox, 0x00, sizeof(emf_mailbox_t));
+
+ testapp_print("\n > Enter account_id: ");
+ scanf("%d", &account_id);
+
+ testapp_print("\n > Enter maibox name: ");
+ scanf("%s", arg);
+
+ mailbox.name = strdup(arg);
+ mailbox.account_id = account_id;
+
+ testapp_print("\n > Enter Mail Id: ");
+ scanf("%d", &mail_id);
+ err = email_download_body(&mailbox, mail_id, 0, &handle);
+ if(err < 0)
+ testapp_print("email_download_body failed");
+ else {
+ testapp_print("email_download_body success");
+ testapp_print("handle[%d]\n", handle);
+ }
+ return TRUE;
+}
+
+
+static gboolean testapp_test_cancel_download_body ()
+{
+ int mail_id = 0;
+ int account_id = 0;
+ int yes = 0;
+ char arg[50];
+ unsigned handle = 0;
+
+ emf_mailbox_t mailbox;
+ memset(&mailbox, 0x00, sizeof(emf_mailbox_t));
+
+ testapp_print("\n > Enter account_id: ");
+ scanf("%d", &account_id);
+
+ testapp_print("\n > Enter maibox name: ");
+ scanf("%s", arg);
+
+ mailbox.name = strdup(arg);
+ mailbox.account_id = account_id;
+
+ testapp_print("\n > Enter Mail Id: ");
+ scanf("%d", &mail_id);
+
+ if( email_download_body(&mailbox, mail_id, 0, &handle) < 0)
+ testapp_print("email_download_body failed");
+ else {
+ testapp_print("email_download_body success\n");
+ testapp_print("Do u want to cancel download job>>>>>1/0\n");
+ scanf("%d",&yes);
+ if(1 == yes) {
+ if(email_cancel_job(account_id, handle) < 0)
+ testapp_print("EmfCancelJob failed..!");
+ else {
+ testapp_print("EmfCancelJob success..!");
+ testapp_print("handle[%d]\n", handle);
+ }
+ }
+
+ }
+ return TRUE;
+}
+static gboolean testapp_test_download_attachment ()
+{
+ int mail_id = 0;
+ int account_id = 0;
+ char arg[50];
+ unsigned handle = 0;
+
+ emf_mailbox_t mailbox;
+ memset(&mailbox, 0x00, sizeof(emf_mailbox_t));
+
+ testapp_print("\n > Enter account_id: ");
+ scanf("%d", &account_id);
+
+ memset(arg, 0x00, 50);
+ testapp_print("\n > Enter maibox name: ");
+ scanf("%s", arg);
+
+ mailbox.name = strdup(arg);
+ mailbox.account_id = account_id;
+
+ testapp_print("\n > Enter Mail Id: ");
+ scanf("%d", &mail_id);
+
+ memset(arg, 0x00, 50);
+ testapp_print("\n > Enter attachment number: ");
+ scanf("%s",arg);
+
+ if( email_download_attachment(&mailbox, mail_id, arg ,&handle) < 0)
+ testapp_print("email_download_attachment failed");
+ else {
+ testapp_print("email_download_attachment success");
+ testapp_print("handle[%d]\n", handle);
+ }
+ return TRUE;
+}
+
+static gboolean testapp_test_retry_send()
+{
+ int mail_id = 0;
+ int timeout = 0;
+
+ emf_mailbox_t mailbox;
+ memset(&mailbox, 0x00, sizeof(emf_mailbox_t));
+
+ testapp_print("\n > Enter Mail Id: ");
+ scanf("%d", &mail_id);
+
+ testapp_print("\n > Enter timeout in seconds: ");
+ scanf("%d", &timeout);
+
+ if( email_retry_send_mail(mail_id, timeout) < 0)
+ testapp_print("email_retry_send_mail failed");
+ return TRUE;
+}
+
+static gboolean testapp_test_find()
+{
+ int i, account_id = 0, result_count;
+ char mailbox_name[255] = { 0, }, *mailbox_name_pointer = NULL, search_keyword[255] = { 0, };
+ emf_mail_list_item_t *mail_list = NULL;
+
+ testapp_print("\n > Enter account_id : ");
+ scanf("%d", &account_id);
+
+ testapp_print("\n > Enter maibox name [0 means all mailboxes] : ");
+ scanf("%s", mailbox_name);
+
+ if(strcmp(mailbox_name, "0") == 0)
+ mailbox_name_pointer = NULL;
+ else
+ mailbox_name_pointer = mailbox_name;
+
+ testapp_print("\n > Enter Keyword : ");
+ scanf("%s", search_keyword);
+
+ if(email_find_mail(account_id, mailbox_name_pointer, EMF_LIST_TYPE_NORMAL, EMF_SEARCH_FILTER_ALL , search_keyword, -1, -1, EMF_SORT_DATETIME_HIGH, &mail_list, &result_count) == EMF_ERROR_NONE) {
+ testapp_print("\n Result count [%d]", result_count);
+ for(i = 0; i < result_count; i++) {
+ testapp_print("\nmail_id[%d], from[%s], subject[%s]", mail_list[i].mail_id, mail_list[i].from, mail_list[i].subject);
+ }
+ }
+
+ if(mail_list)
+ free(mail_list);
+
+ return TRUE;
+}
+
+static gboolean testapp_test_load_test_mail_send()
+{
+ FILE *fp;
+ emf_mailbox_t mbox;
+ emf_mail_t *mail = malloc(sizeof(emf_mail_t));
+ emf_mail_head_t *head = malloc(sizeof(emf_mail_head_t));
+ emf_mail_body_t *body = malloc(sizeof(emf_mail_body_t));
+ char arg[4096];
+ int i=0, count =0;
+ int account_id = 0;
+ emf_option_t option;
+ emf_attachment_info_t attachment;
+ int attach_num = 0;
+ int interval =0;
+ int no_of_tests=0;
+ memset(&option, 0x00, sizeof(emf_option_t));
+
+ memset(mail, 0x00, sizeof(emf_mail_t));
+ memset(head, 0x00, sizeof(emf_mail_head_t));
+ memset(body, 0x00, sizeof(emf_mail_body_t));
+
+ memset(arg, 0x00, 4096);
+ testapp_print(" mail to> ");
+ scanf("%s",arg);
+ if(arg[0]=='\0' || !strstr(arg, "@")){
+ printf(" invalid argument");
+ return false;
+ }
+ for(i=0; i<strlen(arg); i++){
+ if(arg[i]==';') arg[i] = ',';
+ }
+ head->to = malloc(strlen(arg)+1);
+ strcpy(head->to, arg);
+
+ memset(arg, 0x00, 4096);
+ testapp_print(" input subject> ");
+ scanf("%s",arg);
+
+ if(arg[0]=='\0'){
+ printf(" invalid argument");
+ return FALSE;
+ }
+ head->subject = malloc(strlen(arg)+1);
+ strcpy(head->subject, arg);
+
+ testapp_print("mail account_id >");
+ scanf("%d",&account_id);
+
+ memset(arg, 0x00, 4096);
+ testapp_print(" input body> ");
+ scanf("%s",arg);
+
+ if(arg[0]=='\0'){
+ printf(" invalid argument");
+ return FALSE;
+ }
+
+ fp = fopen(MAIL_TEMP_BODY, "w+");
+ fprintf(fp, arg);
+ fclose(fp);
+ body->plain = strdup(MAIL_TEMP_BODY);
+ mail->body = body;
+ mail->head = head;
+ mail->info = malloc(sizeof(emf_mail_info_t));
+ memset(mail->info, 0x00, sizeof(emf_mail_info_t));
+ mail->info->account_id = account_id;
+ mail->info->flags.draft = 1;
+
+ memset(&mbox, 0x00, sizeof(emf_mailbox_t));
+ mbox.account_id = account_id;
+ /* mbox.name = strdup("Drafts"); */
+ mbox.name = strdup("DRAFTBOX");
+
+ testapp_print(" Attach file 1/0 > ");
+ scanf("%d",&attach_num);
+ if ( attach_num ) {
+
+ memset(&attachment, 0x00, sizeof(emf_attachment_info_t));
+ memset(arg, 0x00, 4096);
+ testapp_print("\n > Enter attachment name: ");
+ scanf("%s",arg);
+
+ attachment.name = strdup(arg);
+
+ memset(arg, 0x00, 4096);
+ testapp_print("\n > Enter attachment absolute path: ");
+ scanf("%s",arg);
+
+ attachment.savename = strdup(arg);
+ attachment.next = NULL;
+
+ mail->body->attachment = &attachment;
+ mail->body->attachment_num = attach_num;
+ }
+
+ testapp_print("> Enter Number of tests: ");
+ scanf("%d",&no_of_tests);
+
+ testapp_print("> Enter time interval: ");
+ scanf("%d",&interval);
+ for(count=0;count<no_of_tests;count++) {
+ if(email_add_message(mail, &mbox, 1) < 0) {
+ testapp_print("email_add_message failed\n");
+ }
+
+ testapp_print(" sending...\n");
+
+ unsigned handle = 0;
+ option.keep_local_copy = 1;
+
+ if(email_send_mail(&mbox, mail->info->uid, &option, &handle) < 0){
+ testapp_print(" fail sending\n");
+ } else {
+ testapp_print(" finish sending\n");
+ testapp_print("handle[%d]\n", handle);
+ }
+ sleep(interval);
+ }
+ return FALSE;
+}
+
+
+static gboolean testapp_test_count_message_on_sending()
+{
+ emf_mailbox_t mailbox;
+ int total_count;
+ int err = EMF_ERROR_NONE;
+ char temp[128];
+
+ memset(&mailbox, 0x00, sizeof(emf_mailbox_t));
+ /* input mailbox information : need account_id and name */
+ testapp_print("mail account id(0: All account)> ");
+ scanf("%d", &mailbox.account_id);
+
+ testapp_print("mailbox_name(0 : NULL)> ");
+ scanf("%s", temp );
+ if ( strcmp(temp, "0") == 0 ) {
+ mailbox.name = NULL;
+ }
+ else {
+ mailbox.name = malloc(strlen(temp) + 1);
+ if ( mailbox.name == NULL ) {
+ testapp_print("fail malloc\n");
+ return false;
+ }
+ strcpy(mailbox.name, temp);
+ }
+
+ err = email_count_message_on_sending(&mailbox, &total_count);
+ if ( err < 0 ) {
+ testapp_print(" fail email_count_message_on_sending: err[%d]\n", err);
+ }
+ else {
+ testapp_print(" success email_count_message_on_sending: # of messages on senging status : %d\n", total_count);
+ }
+
+ if ( mailbox.name ) {
+ free(mailbox.name);
+ mailbox.name = NULL;
+ }
+ return false;
+}
+
+
+static gboolean testapp_test_move_all_mails_to_mailbox()
+{
+ emf_mailbox_t src_mailbox;
+ emf_mailbox_t dest_mailbox;
+ int err = EMF_ERROR_NONE;
+ char temp[128];
+
+ memset(&src_mailbox, 0x00, sizeof(emf_mailbox_t));
+ memset(&dest_mailbox, 0x00, sizeof(emf_mailbox_t));
+
+ /* input mailbox information : need account_id and name (src & dest) */
+ testapp_print("src mail account id(0: All account)> ");
+ scanf("%d", &src_mailbox.account_id);
+
+ testapp_print("src mailbox_name(0 : NULL)> ");
+ scanf("%s", temp );
+ if ( strcmp(temp, "0") == 0 ) {
+ src_mailbox.name = NULL;
+ }
+ else {
+ src_mailbox.name = malloc(strlen(temp) + 1);
+ if ( src_mailbox.name == NULL ) {
+ testapp_print("fail malloc\n");
+ return false;
+ }
+ strcpy(src_mailbox.name, temp);
+ }
+
+ /* Destination mailbox */
+ testapp_print("dest mail account id> ");
+ scanf("%d", &dest_mailbox.account_id);
+ if ( dest_mailbox.account_id <= 0 ) {
+ testapp_print("Invalid dest account_id[%d]\n", dest_mailbox.account_id);
+ goto FINISH_OFF;
+ }
+
+ testapp_print("dest mailbox_name> ");
+ scanf("%s", temp);
+ if ( strcmp(temp, "") == 0 ) {
+ testapp_print("Invalid dest mailbox_name[%s]\n", temp);
+ goto FINISH_OFF;
+ }
+ else {
+ dest_mailbox.name = malloc(strlen(temp) + 1);
+ if ( dest_mailbox.name == NULL ) {
+ testapp_print("fail malloc\n");
+ goto FINISH_OFF;
+ }
+ strcpy(dest_mailbox.name, temp);
+ }
+
+ err = email_move_all_mails_to_mailbox(&src_mailbox, &dest_mailbox);
+ if ( err < 0 ) {
+ testapp_print(" fail email_move_all_mails_to_mailbox: err[%d]\n", err);
+ }
+ else {
+ testapp_print(" success email_move_all_mails_to_mailbox: from [%d:%s] to [%d:%s]\n", src_mailbox.account_id, src_mailbox.name, dest_mailbox.account_id, dest_mailbox.name);
+ }
+
+FINISH_OFF:
+ if ( src_mailbox.name ) {
+ free(src_mailbox.name);
+ src_mailbox.name = NULL;
+ }
+ if ( dest_mailbox.name ) {
+ free(dest_mailbox.name);
+ dest_mailbox.name = NULL;
+ }
+ return false;
+}
+
+static gboolean testapp_test_count_message_with_draft_flag()
+{
+ emf_mailbox_t mailbox;
+ int total_count;
+ int err = EMF_ERROR_NONE;
+ char temp[128];
+
+ memset(&mailbox, 0x00, sizeof(emf_mailbox_t));
+ /* input mailbox information : need account_id and name */
+ testapp_print("mail account id(0: All account)> ");
+ scanf("%d", &mailbox.account_id);
+
+ testapp_print("mailbox_name(0 : NULL)> ");
+ scanf("%s", temp );
+ if ( strcmp(temp, "0") == 0 ) {
+ mailbox.name = NULL;
+ }
+ else {
+ mailbox.name = malloc(strlen(temp) + 1);
+ if ( mailbox.name == NULL ) {
+ testapp_print("fail malloc\n");
+ return false;
+ }
+ strcpy(mailbox.name, temp);
+ }
+
+ err = email_count_message_with_draft_flag(&mailbox, &total_count);
+
+ if ( err < 0) {
+ testapp_print(" fail email_count_message_with_draft_flag: err[%d]\n", err);
+ }
+ else {
+ testapp_print(" success email_count_message_with_draft_flag: # of messages with draft flag : %d\n", total_count);
+ }
+
+ if ( mailbox.name ) {
+ free(mailbox.name);
+ mailbox.name = NULL;
+ }
+ return false;
+}
+
+/* sowmya.kr@samsung.com, 01282010 - Changes to get latest unread mail id for given account */
+static gboolean testapp_test_get_latest_unread_mail_id()
+{
+
+ int mail_id = 0,account_id = 0;
+ int err = EMF_ERROR_NONE;
+
+
+ testapp_print("Enter account Id to get latest unread mail Id,<-1 to get latest irrespective of account id> ");
+ scanf("%d", &account_id);
+
+ err = email_get_latest_unread_mail_id(account_id, &mail_id);
+ if ( err < 0) {
+ testapp_print(" fail email_get_latest_unread_mail_id: err[%d]\n", err);
+ }
+ else {
+ testapp_print(" success email_get_latest_unread_mail_id: Latest unread mail id : %d\n", mail_id);
+ }
+ return FALSE;
+}
+
+static gboolean testapp_test_get_totaldiskusage()
+{
+ unsigned long total_size = 0;
+ int err_code = EMF_ERROR_NONE ;
+
+ err_code = email_get_disk_space_usage(&total_size);
+ if ( err_code < 0)
+ testapp_print("email_get_disk_space_usage failed err : %d\n",err_code);
+ else
+ testapp_print("email_get_disk_space_usage SUCCESS, total disk usage in KB : %ld \n", total_size);
+
+ return FALSE;
+}
+
+
+
+static gboolean testapp_test_db_test()
+{
+ int err = EMF_ERROR_NONE;
+ int mail_id;
+ int account_id;
+ char *to = NULL;
+ char *cc = NULL;
+ char *bcc = NULL;
+
+ to = (char *) malloc(500000);
+ cc = (char *) malloc(500000);
+ bcc = (char *) malloc(500000);
+
+ memset(to, 0x00, sizeof(to));
+ memset(cc, 0x00, sizeof(to));
+ memset(bcc, 0x00, sizeof(to));
+
+ testapp_print("Input Mail id:\n");
+ scanf("%d", &mail_id);
+ testapp_print("Input Account id:\n");
+ scanf("%d", &account_id);
+ testapp_print("Input TO field:\n");
+ scanf("%s", to);
+ testapp_print("Input CC field:\n");
+ scanf("%s", cc);
+ testapp_print("Input BCC field:\n");
+ scanf("%s", bcc);
+
+ if ( em_storage_test(mail_id, account_id, to, cc, bcc, &err) == true ) {
+ testapp_print(">> Saving Succeeded\n");
+ }
+ else {
+ testapp_print(">> Saving Failed[%d]\n", err);
+ }
+
+ free(to);
+ free(cc);
+ free(bcc);
+
+ return false;
+}
+
+static gboolean testapp_test_address_format_check_test()
+{
+ int i;
+ int type;
+ int index;
+ int check_yn;
+ int err = EMF_ERROR_NONE;
+ char *pAddress = NULL;
+ char input_address[8096];
+ char *address_list[] = {
+ "tom@gmail.com",
+ "tom@gmail,com",
+ "tom@gmail.com@gmail.com",
+ "[tom@gmail.com]",
+ "\"Tom\"<tom@gmail.com>",
+ "\"Tom\"[tom@gmail.com]",
+ "\"Tom\"<tom,@gmail.com>",
+ "<tom@gmail.com>",
+ "<tom@gmail,com>",
+ "<tom@gmail.>",
+ "<tom@gmail.com>,tom@gmail.com",
+ "<tom@gmail.com>;tom@gmail.com",
+ "tom @gmail.com",
+ "tom@ gmail.com",
+ "tom@gmail..com",
+ "tom@",
+ "tom@gmail",
+ "tom@gmail.",
+ "tom@gmail.c",
+ "tom@.",
+ "\"\"Tom\"<tom,@gmail.com>",
+ "tom@gmail.com,tom@gmail.com",
+ "tom@gmail.com.",
+ "<tom@gmail.com>,tom@.gmail.com",
+ "&& tom@live.com ----",
+ "madhu <tom@gmail.com>",
+ "tom@gmail.com, && tom@live.com",
+ "tom@gmail.com , && tom@live.com",
+ "< tom@gmail.com > , < tom@.gmail.com >",
+ "tom@gmail.com , tom@gmail.com",
+ "<tom@gmail.com >",
+ "<to m@gmail.com >",
+ "<tom@gmail.com>;tom@gmail.com",
+ "Tom< tom@gmail.com > , Tom <tom@gmail.com>",
+ " \"Tom\" < tom@gmail.com> , \"Tom\" < tom@gmail.com> , Tom < tom@gmail.com> ; Tom < tom@gmail.com>,\"tomtom\" < tom@aol.com>,\"tomtom\" < tom@aol.com> ,\"tomtom\" <tom@aol.com>;<tom@live.com>, <tom@live.com>; \"tomtomtomtom\" <tom@live.com> ; \"tomtomtomtom\" <tom@live.com>,\"Tom\" < tom@gmail.com>",
+ "<tom@gmail.com>,<tom@gmail.com>,<tom@gmail.com>,<tom@gmail.com>,<tom@gmail.com>,<tom@gmail.com>,<tom@gmail.com>,<tom@gmail.com>,<tom@gmail.com>,<tom@gmail.com>,<tom@gmail.com>,<tom@gmail.com>,<tom@gmail.com>,<tom@gmail.com>,<tom@gmail.com>,<tom@gmail.com>",
+ " tom@gmail.com ; < tom@gmail.com > ",
+ "\"Tom\" < tom@gmail.com > ; mama < tom@gmail.com > , abcd@gmail.com , abc@gmail.com ,\"tomtom\" <tom@aol.com>,\"tomtom\" < tom@aol.com> ;\"tomtom\" < tom@aol.com > ,\"tomtom\" <tom@aol.com> , \"tomtomtomtom\" <tom@live.com> ",
+ " \"tomtom\" <tom@aol.com> ;\"tomtom\" <tom@aol.com> ; ",
+ " tom@gmail.com , tom@gmail.com , tom@gmail.com; Tom < tom@gmail.com > ,< tom@aol.com>, <tom@aol.com> ,<tom@aol.com>;<tom@live.com>, tom@live.com;tom@live.com; \"tomtomtomtom\" <tom@live.com>,\"Tom\" < tom@gmail.com> ; ",
+ "<tom@aol.com> , \"tomtomtomtom\" <tom@live.com>,\"Tom\" < tom@gmail.com> ; ",
+ " Tom <tom@gmail.com>,Tom <tom@gmail.com>,Tom <tom@gmail.com>,Tom <tom@gmail.com>,Tom < tom@gmail.com> ,<tom@gmail.com>,Tom <tom@gmail.com >,Tom< tom@gmail.com > , Tom <tom@gmail.com>,Tom <tom@gmail.com>,Tom <tom@gmail.com>,Tom <tom@gmail.com>,Tom <tom@gmail.com>,Tom <tom@gmail.com>,Tom <tom@gmail.com>,Tom <tom@gmail.com>",
+ NULL
+ };
+ int address_count = 0;
+
+ testapp_print("Select input method:\n");
+ testapp_print("1. Test data\n");
+ testapp_print("2. Keyboard\n");
+ scanf("%d", &type);
+
+ switch ( type ) {
+ case 1:
+ do {
+ for ( i = 0; address_list[i] != NULL; i++ ) {
+ testapp_print("[%d] addr[%s]\n", i, address_list[i]);
+ address_count++;
+ }
+ testapp_print("Choose address to be tested:[99:quit]\n");
+ scanf("%d", &index);
+ if ( index == 99 )
+ break;
+
+ testapp_print(">> [%d] Checking? (1:Yes, Other:No) [%s]\n", index, address_list[index]);
+ scanf("%d", &check_yn);
+ if ( check_yn == 1 ) {
+ pAddress = strdup(address_list[index]);
+ if ( em_core_verify_email_address(pAddress, false, &err ) == true ) {
+ testapp_print("<< [%d] Checking Succeeded : addr[%s]\n", index, address_list[index]);
+ }
+ else {
+ testapp_print("<< [%d] Checking Failed : addr[%s], err[%d]\n", index, address_list[index], err);
+ }
+ if(pAddress) {
+ free(pAddress);
+ pAddress = NULL;
+ }
+ }
+ else {
+ testapp_print("<< [%d] Skipped : addr[%s]\n", index, address_list[index]);
+ }
+ }
+ while (1);
+ break;
+ case 2:
+ testapp_print("Input address: \n");
+ scanf("%s", input_address);
+ if ( em_core_verify_email_address(input_address, false, &err ) == true ) {
+ testapp_print(">> Saving Succeeded : addr[%s]\n", input_address);
+ }
+ else {
+ testapp_print(">> Saving Failed : addr[%s], err[%d]\n", input_address, err);
+ }
+ break;
+ default:
+ testapp_print("wrong nuber... [%d]\n", type);
+ break;
+ }
+
+ return FALSE;
+}
+
+static gboolean testapp_test_get_max_mail_count()
+{
+ int max_count = -1;
+ int err = EMF_ERROR_NONE;
+
+ err = email_get_max_mail_count(&max_count);
+ testapp_print("\n\t>>>>> email_get_max_mail_count() return [%d]\n\n", max_count);
+
+ return false;
+}
+
+#include "em-storage.h"
+static gboolean testapp_test_test_get_thread_information()
+{
+ int error_code, thread_id= 38;
+ emf_mail_list_item_t *result_mail;
+
+ if( (error_code = email_get_thread_information_ex(thread_id, &result_mail)) == EMF_ERROR_NONE) {
+ testapp_print("email_get_thread_information returns = %d\n", error_code);
+ testapp_print("subject = %s\n", result_mail->subject);
+ testapp_print("mail_id = %d\n", result_mail->mail_id);
+ testapp_print("from = %s\n", result_mail->from);
+ testapp_print("thrad_id = %d\n", result_mail->thread_id);
+ testapp_print("count = %d\n", result_mail->thread_item_count);
+ }
+
+ return TRUE;
+}
+
+
+static gboolean testapp_test_get_sender_list()
+{
+ testapp_print(" >>> testapp_test_get_sender_list : Entered \n");
+
+ char *mailbox_name = NULL;
+ int i = 0;
+ int account_id = 0;
+ int sorting = 0;
+ int err_code = EMF_ERROR_NONE;
+ emf_sender_list_t *sender_list = NULL;
+ int sender_count = 0;
+
+ mailbox_name = NULL;
+ account_id = 0;
+ sorting = 0;
+
+ if ( (err_code = email_get_sender_list(account_id, mailbox_name, EMF_SEARCH_FILTER_NONE, NULL, sorting, &sender_list, &sender_count)) != EMF_ERROR_NONE) {
+ testapp_print("email_get_sender_list failed : %d\n",err_code);
+ return FALSE;
+ }
+
+ testapp_print("===================================================\n");
+ testapp_print("\t\t\tSender list\n");
+ testapp_print("===================================================\n");
+ testapp_print("sender address \tdisplay_name\t [unread/total]\n");
+ testapp_print("===================================================\n");
+ for ( i =0; i < sender_count; i++ ) {
+ testapp_print("[%s]\t[%s]\t[%d/%d]\n", sender_list[i].address, sender_list[i].display_name, sender_list[i].unread_count, sender_list[i].total_count);
+ }
+ testapp_print("===================================================\n");
+
+ if ( sender_list ) {
+ email_free_sender_list(&sender_list, sender_count);
+ }
+ if ( mailbox_name ) {
+ free(mailbox_name);
+ mailbox_name = NULL;
+ }
+
+ testapp_print(" >>> testapp_test_get_sender_list : END \n");
+ return TRUE;
+}
+
+
+static gboolean testapp_test_get_address_info_list()
+{
+ testapp_print(" >>> testapp_test_get_address_info_list : Entered \n");
+
+ char buf[1024];
+ int i = 0;
+ int mail_id = 0;
+ int err_code = EMF_ERROR_NONE;
+ emf_address_info_list_t *address_info_list= NULL;
+ emf_address_info_t *p_address_info = NULL;
+ GList *list = NULL;
+ GList *node = NULL;
+
+ memset(buf, 0x00, sizeof(buf));
+ testapp_print("\n > Enter mail_id: ");
+ scanf("%d",&mail_id);
+
+
+ if ((err_code = email_get_address_info_list(mail_id, &address_info_list)) != EMF_ERROR_NONE) {
+ testapp_print("email_get_address_info_list failed : %d\n",err_code);
+ email_free_address_info_list(&address_info_list);
+ return FALSE;
+ }
+
+ testapp_print("===================================================\n");
+ testapp_print("\t\t\t address info list\n");
+ testapp_print("===================================================\n");
+ testapp_print("address_type\t address \t\tdisplay_name\t contact id\n");
+ testapp_print("===================================================\n");
+
+ for ( i = EMF_ADDRESS_TYPE_FROM; i <= EMF_ADDRESS_TYPE_BCC; i++ ) {
+ switch ( i ) {
+ case EMF_ADDRESS_TYPE_FROM:
+ list = address_info_list->from;
+ break;
+ case EMF_ADDRESS_TYPE_TO:
+ list = address_info_list->to;
+ break;
+ case EMF_ADDRESS_TYPE_CC:
+ list = address_info_list->cc;
+ break;
+ case EMF_ADDRESS_TYPE_BCC:
+ list = address_info_list->bcc;
+ break;
+ }
+
+ /* delete dynamic-allocated memory for each item */
+ node = g_list_first(list);
+ while ( node != NULL ) {
+ p_address_info = (emf_address_info_t*)node->data;
+ testapp_print("%d\t\t%s\t%s\t%d\n", p_address_info->address_type, p_address_info->address, p_address_info->display_name, p_address_info->contact_id);
+
+ node = g_list_next(node);
+ }
+ testapp_print("\n");
+ }
+ testapp_print("===================================================\n");
+
+ email_free_address_info_list(&address_info_list);
+
+ testapp_print(" >>> testapp_test_get_address_info_list : END \n");
+ return TRUE;
+}
+
+static gboolean testapp_test_find_mail_on_server()
+{
+ testapp_print(" >>> testapp_test_find_mail_on_server : Entered \n");
+
+ int err_code = EMF_ERROR_NONE;
+ int account_id = 0;
+ int search_type = 0;
+ unsigned int handle = 0;
+ char mailbox_name[MAILBOX_NAME_LENGTH];
+ char search_value[MAX_EMAIL_ADDRESS_LENGTH];
+
+ testapp_print("input account id : ");
+ scanf("%d",&account_id);
+
+ testapp_print("input mailbox name : ");
+ scanf("%s", mailbox_name);
+
+ testapp_print("input search type : ");
+ scanf("%d",&search_type);
+
+ testapp_print("input search type : ");
+ scanf("%s", search_value);
+
+ if( (err_code = email_find_mail_on_server(account_id, mailbox_name, search_type, search_value, &handle)) != EMF_ERROR_NONE) {
+ testapp_print("email_find_mail_on_server failed [%d]", err_code);
+ }
+
+ testapp_print(" >>> testapp_test_find_mail_on_server : END \n");
+ return TRUE;
+}
+
+/* internal functions */
+static gboolean testapp_test_interpret_command (int menu_number)
+{
+ gboolean go_to_loop = TRUE;
+
+ switch (menu_number) {
+ case 1:
+ testapp_test_save_mail();
+ break;
+ case 2:
+ testapp_test_mail_send ();
+ break;
+ case 3:
+ testapp_test_update();
+ break;
+ case 4:
+ testapp_test_add_attachment();
+ break;
+ case 5:
+ testapp_test_get ();
+ break;
+ case 6:
+ testapp_test_get_info();
+ break;
+ case 7:
+ testapp_test_get_header ();
+ break;
+ case 8:
+ testapp_test_get_body ();
+ break;
+ case 9:
+ testapp_test_count ();
+ break;
+ case 10:
+ testapp_test_modify_flag();
+ break;
+ case 11:
+ testapp_test_modify_extra_flag ();
+ break;
+ case 12:
+ testapp_test_download();
+ break;
+ case 14:
+ testapp_test_delete ();
+ break;
+ case 16:
+ testapp_test_download_body ();
+ break;
+ case 17:
+ testapp_test_download_attachment();
+ break;
+ case 18:
+ testapp_test_load_test_mail_send();
+ break;
+ case 19:
+ testapp_test_get_mailbox_list ();
+ break;
+ case 20:
+ testapp_test_delete_all();
+ break;
+ case 21:
+ testapp_test_move();
+ break;
+ case 23:
+ testapp_test_retry_send();
+ break;
+ case 24:
+ testapp_test_find();
+ break;
+ case 26:
+ testapp_test_count_message_on_sending();
+ break;
+ case 27:
+ testapp_test_move_all_mails_to_mailbox();
+ break;
+ case 28:
+ testapp_test_count_message_with_draft_flag();
+ break;
+ case 29:
+ testapp_test_get_latest_unread_mail_id();
+ break;
+ case 38:
+ testapp_test_get_totaldiskusage();
+ break;
+ case 39:
+ testapp_test_send_mail_with_option();
+ break;
+ case 40:
+ testapp_test_address_format_check_test();
+ break;
+ case 41:
+ testapp_test_get_max_mail_count();
+ break;
+ case 42:
+ testapp_test_db_test();
+ break;
+ case 43:
+ testapp_test_send_cancel();
+ break;
+ case 44:
+ testapp_test_cancel_download_body();
+ break;
+ case 46:
+ testapp_test_get_mail_list_for_thread_view();
+ break;
+ case 48:
+ testapp_test_test_get_thread_information();
+ break;
+ case 49:
+ testapp_test_get_sender_list();
+ break;
+ case 51:
+ testapp_test_get_mail_list_ex();
+ break;
+ case 52:
+ testapp_test_get_address_info_list();
+ break;
+ case 53:
+ testapp_test_send_html_mail_with_inline_content();
+ break;
+ case 54:
+ email_get_recipients_list(1, NULL, NULL);
+ break;
+ case 55:
+ testapp_test_set_flags_field();
+ break;
+ case 56:
+ testapp_test_add_mail();
+ break;
+ case 57:
+ testapp_test_update_mail();
+ break;
+ case 58:
+ testapp_test_find_mail_on_server();
+ break;
+ case 0:
+ go_to_loop = FALSE;
+ break;
+ default:
+ break;
+ }
+
+ return go_to_loop;
+}
+
+void testapp_mail_main()
+{
+ gboolean go_to_loop = TRUE;
+ int menu_number = 0;
+
+ while (go_to_loop) {
+ testapp_show_menu (EMF_MESSAGE_MENU);
+ testapp_show_prompt (EMF_MESSAGE_MENU);
+
+ scanf ("%d", &menu_number);
+
+ go_to_loop = testapp_test_interpret_command (menu_number);
+ }
+}
+
diff --git a/utilities/email-service-test-application/email-service-test-application/emf-test-others.c b/utilities/email-service-test-application/email-service-test-application/emf-test-others.c
new file mode 100755
index 0000000..a251ba0
--- /dev/null
+++ b/utilities/email-service-test-application/email-service-test-application/emf-test-others.c
@@ -0,0 +1,448 @@
+/*
+* email-service
+*
+* Copyright (c) 2000 - 2011 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.
+*
+*/
+
+
+/* common header */
+#include <stdio.h>
+#include <string.h>
+
+/* open header */
+#include <glib.h>
+#include <dlfcn.h>
+#include <vconf.h>
+#include "c-client.h"
+
+
+#include "Emf_Mapi.h"
+#include "Emf_Mapi_Message.h"
+#include "Emf_Mapi_Network.h"
+
+
+/* internal header */
+#include "emf-test-utility.h"
+#include "emf-test-others.h"
+#include "ipc-library.h"
+
+static gboolean testapp_test_get_network_status()
+{
+ int on_sending = 0;
+ int on_receiving = 0;
+ email_get_network_status(&on_sending, &on_receiving);
+ testapp_print("\tNetwork status : \n On sending - %d \n On Receiving - %d \n", on_sending, on_receiving);
+ return FALSE;
+}
+
+static gboolean testapp_test_get_pending_job()
+{
+ int action = -1;
+ int account_id = 0;
+ int mail_id = 0;
+ emf_event_status_type_t status = -1;
+ testapp_print( " Enter Action \n SEND_MAIL = 0 \n SYNC_HEADER = 1 \n" \
+ " DOWNLOAD_BODY,= 2 \n DOWNLOAD_ATTACHMENT = 3 \n" \
+ " DELETE_MAIL = 4 \n SEARCH_MAIL = 5 \n SAVE_MAIL = 6 \n" \
+ " NUM = 7 \n");
+ scanf("%d",&action);
+
+ testapp_print("\n > Enter account_id: ");
+ scanf("%d", &account_id);
+
+ testapp_print("\n > Enter Mail Id: ");
+ scanf("%d", &mail_id);
+
+ if( email_get_pending_job( action, account_id, mail_id, &status) >= 0)
+ testapp_print("\t status - %d \n",status);
+
+ return FALSE;
+}
+
+static gboolean testapp_test_cancel_job ()
+{
+ int account_id = 0;
+ int handle = 0;
+
+ testapp_print("\n > Enter account_id (0: all account): ");
+ scanf("%d", &account_id);
+
+ testapp_print("\n > Enter handle: ");
+ scanf("%d", &handle);
+
+ if(email_cancel_job(account_id, handle) < 0)
+ testapp_print("email_cancel_job failed..!");
+ return FALSE;
+}
+
+static gboolean testapp_test_set_dnet_proper_profile_type()
+{
+ testapp_print("NOT Support\n");
+
+ return TRUE;
+}
+
+static gboolean testapp_test_get_dnet_proper_profile_type()
+{
+ testapp_print("NOT Support\n");
+
+ return TRUE;
+}
+
+static gboolean testapp_test_test_thread_functions()
+{
+ /*
+ int result, thread_id, thread_item_count = 0;
+ char sampletext[200] = " RE: re: FW: Re: RE: FWD: Hello re fw:qwe", *latest_thread_datetime = NULL;
+
+
+ em_core_find_tag_for_thread_view(sampletext, &result);
+
+ testapp_print("em_core_find_tag_for_thread_view returns = %d\n", result);
+
+ if(result) {
+ em_storage_get_thread_id_of_thread_mails(1, "Inbox", sampletext, &thread_id, &latest_thread_datetime, &thread_item_count);
+ testapp_print("em_storage_get_thread_id_of_thread_mails returns = %d\n", thread_id);
+ }
+ */
+
+ return TRUE;
+}
+
+static gboolean testapp_test_print_receving_queue_via_debug_msg()
+{
+ int err;
+ void* hAPI = (void*)ipcEmailAPI_Create(_EMAIL_API_PRINT_RECEIVING_EVENT_QUEUE);
+
+ if(hAPI == NULL)
+ return EMF_ERROR_NULL_VALUE;
+
+ if(!ipcEmailProxy_ExecuteAPI(hAPI)) {
+ testapp_print("testapp_test_print_receving_queue_via_debug_msg - ipcEmailProxy_ExecuteAPI failed \n ");
+ if(hAPI == NULL)
+ return EMF_ERROR_NULL_VALUE;
+ }
+
+ err = *(int*)ipcEmailAPI_GetParameter(hAPI, 1, 0);
+
+ testapp_print(" >>>> RETURN VALUE : %d \n", err);
+
+ ipcEmailAPI_Destroy(hAPI);
+
+ hAPI = NULL;
+ testapp_print("testapp_test_print_receving_queue_via_debug_msg ..........End\n");
+ return err;
+}
+
+static gboolean testapp_test_create_db_full()
+{
+ int err;
+
+ err = email_create_db_full();
+
+ testapp_print("testapp_test_create_db_full returns [%d]", err);
+
+ return err;
+}
+
+static int encode_base64(char *src, unsigned long src_len, char **enc, unsigned long* enc_len, int *err_code)
+{
+ unsigned char *content = NULL;
+ int ret = true;
+ int err = EMF_ERROR_NONE;
+
+ if (err_code != NULL) {
+ *err_code = EMF_ERROR_NONE;
+ }
+
+ content = rfc822_binary(src, src_len, enc_len);
+
+ if (content)
+ *enc = (char *)content;
+ else {
+ err = EMF_ERROR_UNKNOWN;
+ ret = false;
+ }
+
+ if (err_code)
+ *err_code = err;
+
+ return ret;
+}
+
+
+static gboolean testapp_test_encoding_test()
+{
+ int error = EMF_ERROR_NONE;
+ int has_special_character = 0, base64_file_name_length = 0, i;
+ gsize bytes_read, bytes_written;
+ char *encoded_file_name = NULL, *base64_file_name = NULL;
+ SIZEDTEXT source_text;
+ GError *glib_error = NULL;
+ CHARSET *result_charset = NULL;
+ char filename[] = {0xEB, 0xB0, 0x94, 0xED, 0x83, 0x95, 0x32, 0x2E, 0x70, 0x6E, 0x67, 0x00}; /* UTF-8 */
+
+ source_text.data = (unsigned char*)filename;
+ source_text.size = strlen(filename);
+
+ result_charset = (CHARSET*)utf8_infercharset(&source_text);
+
+ if(result_charset) {
+ testapp_print("return_charset->name [%s]", result_charset->name);
+ encoded_file_name = (char*)g_convert (filename, -1, "UTF-8", result_charset->name, &bytes_read, &bytes_written, &glib_error);
+ }
+ else {
+ i = 0;
+ while(filename[i++] & 0x80)
+ has_special_character = 1;
+ testapp_print("has_special_character [%d]", has_special_character);
+ if(has_special_character)
+ encoded_file_name = (char*)g_convert (filename, -1, "UTF-8", "EUC-KR", &bytes_read, &bytes_written, &glib_error);
+ }
+
+ if(encoded_file_name == NULL)
+ encoded_file_name = strdup(filename);
+
+ testapp_print("encoded_file_name [%s]", encoded_file_name);
+
+ if(!encode_base64(encoded_file_name, strlen(encoded_file_name), &base64_file_name, (unsigned long*)&base64_file_name_length, &error)) {
+ testapp_print("encode_base64 failed. error [%d]", error);
+ goto FINISH_OFF;
+ }
+
+ testapp_print("base64_file_name [%s]", base64_file_name);
+
+ if(base64_file_name) {
+ free(encoded_file_name);
+ encoded_file_name = malloc(strlen(base64_file_name) + 15);
+ if(!encoded_file_name) {
+ testapp_print("em_core_malloc failed.");
+ goto FINISH_OFF;
+ }
+ snprintf(encoded_file_name, strlen(base64_file_name) + 15, "=?UTF-8?B?%s?=", base64_file_name);
+ testapp_print("encoded_file_name [%s]", encoded_file_name);
+ }
+FINISH_OFF:
+
+ return error;
+}
+
+#define LIB_EMAIL_SERVICE_PATH "/usr/lib/libemail-api.so"
+
+int (*Datastore_FI_EMTB)(char **);
+int (*Datastore_FI_EMSB)(char **);
+int (*Datastore_FI_EMOB)(char **);
+int (*Datastore_FI_EMDR)(char **);
+int (*Datastore_FI_EMMF)(char **);
+int (*Datastore_FI_EMTR)(char **);
+int (*Datastore_FI_EMSP)(char **);
+
+static gboolean email_test_dtt_Datastore_FI()
+{
+ void *handle = NULL;
+ char *dl_error = NULL, *output_str = NULL;
+
+ handle = dlopen(LIB_EMAIL_SERVICE_PATH, RTLD_LAZY | RTLD_GLOBAL);
+ if (!handle) {
+ dl_error = dlerror();
+ if (dl_error)
+ testapp_print("\t dlopen error : Open Library with absolute path return : %s\n", dl_error);
+ return false;
+ }
+
+ Datastore_FI_EMTB = dlsym(handle, "Datastore_FI_EMTB");
+ Datastore_FI_EMSB = dlsym(handle, "Datastore_FI_EMSB");
+ Datastore_FI_EMOB = dlsym(handle, "Datastore_FI_EMOB");
+ Datastore_FI_EMDR = dlsym(handle, "Datastore_FI_EMDR");
+ Datastore_FI_EMMF = dlsym(handle, "Datastore_FI_EMMF");
+ Datastore_FI_EMTR = dlsym(handle, "Datastore_FI_EMTR");
+ Datastore_FI_EMSP = dlsym(handle, "Datastore_FI_EMSP");
+
+ Datastore_FI_EMTB(&output_str);
+
+ testapp_print("\nemail_test_dtt_Datastore_FI\n%s\n", output_str);
+
+ if(output_str)
+ free(output_str);
+
+ if (handle) {
+ dlclose(handle);
+ dl_error = dlerror();
+ if (dl_error)
+ testapp_print("\t Close handle return : %s\n", dl_error);
+ }
+
+ return true;
+}
+
+int (*Datastore_R_EMTB)(char **);
+int (*Datastore_R_EMSB)(char **);
+int (*Datastore_R_EMOB)(char **);
+int (*Datastore_R_EMDR)(char **);
+int (*Datastore_R_EMMF)(char **);
+int (*Datastore_R_EMTR)(char **);
+int (*Datastore_R_EMSP)(char **);
+
+
+static gboolean email_test_dtt_Datastore_R()
+{
+ void *handle = NULL;
+ char *dl_error = NULL, *output_str = NULL;
+
+ handle = dlopen(LIB_EMAIL_SERVICE_PATH, RTLD_LAZY | RTLD_GLOBAL);
+ if (!handle) {
+ dl_error = dlerror();
+ if (dl_error)
+ testapp_print("\t dlopen error : Open Library with absolute path return : %s\n", dl_error);
+ return false;
+ }
+
+ Datastore_R_EMTB = dlsym(handle, "Datastore_R_EMTB");
+ Datastore_R_EMSB = dlsym(handle, "Datastore_R_EMSB");
+ Datastore_R_EMOB = dlsym(handle, "Datastore_R_EMOB");
+ Datastore_R_EMDR = dlsym(handle, "Datastore_R_EMDR");
+ Datastore_R_EMMF = dlsym(handle, "Datastore_R_EMMF");
+ Datastore_R_EMTR = dlsym(handle, "Datastore_R_EMTR");
+ Datastore_R_EMSP = dlsym(handle, "Datastore_R_EMSP");
+
+ Datastore_R_EMTB(&output_str);
+
+ testapp_print("\nemail_test_dtt_Datastore_R\n%s\n", output_str);
+
+ if(output_str)
+ free(output_str);
+
+ if (handle) {
+ dlclose(handle);
+ dl_error = dlerror();
+ if (dl_error)
+ testapp_print("\t Close handle return : %s\n", dl_error);
+ }
+
+ return true;
+}
+
+int (*Datastore_C_EMTB)(char **);
+int (*Datastore_C_EMSB)(char **);
+int (*Datastore_C_EMOB)(char **);
+int (*Datastore_C_EMDR)(char **);
+int (*Datastore_C_EMMF)(char **);
+int (*Datastore_C_EMTR)(char **);
+int (*Datastore_C_EMSP)(char **);
+
+static gboolean email_test_dtt_Datastore_C()
+{
+ void *handle = NULL;
+ char *dl_error = NULL, *output_str = NULL;
+
+ handle = dlopen(LIB_EMAIL_SERVICE_PATH, RTLD_LAZY | RTLD_GLOBAL);
+ if (!handle) {
+ dl_error = dlerror();
+ if (dl_error)
+ testapp_print("\t dlopen error : Open Library with absolute path return : %s\n", dl_error);
+ return false;
+ }
+
+ Datastore_C_EMTB = dlsym(handle, "Datastore_C_EMTB");
+ Datastore_C_EMSB = dlsym(handle, "Datastore_C_EMSB");
+ Datastore_C_EMOB = dlsym(handle, "Datastore_C_EMOB");
+ Datastore_C_EMDR = dlsym(handle, "Datastore_C_EMDR");
+ Datastore_C_EMMF = dlsym(handle, "Datastore_C_EMMF");
+ Datastore_C_EMTR = dlsym(handle, "Datastore_C_EMTR");
+ Datastore_C_EMSP = dlsym(handle, "Datastore_C_EMSP");
+
+ Datastore_C_EMTB(&output_str);
+
+
+ testapp_print("\nemail_test_dtt_Datastore_C\n%s\n", output_str);
+
+ if(output_str)
+ free(output_str);
+
+ if (handle) {
+ dlclose(handle);
+ dl_error = dlerror();
+ if (dl_error)
+ testapp_print("\t Close handle return : %s\n", dl_error);
+ }
+
+ return true;
+}
+
+static gboolean testapp_test_interpret_command (int menu_number)
+{
+ gboolean go_to_loop = TRUE;
+
+ switch (menu_number) {
+ case 1:
+ testapp_test_get_network_status();
+ break;
+ case 2:
+ testapp_test_get_pending_job ();
+ break;
+ case 3:
+ testapp_test_cancel_job ();
+ break;
+ case 5:
+ testapp_test_set_dnet_proper_profile_type();
+ break;
+ case 6:
+ testapp_test_get_dnet_proper_profile_type();
+ break;
+ case 8:
+ testapp_test_test_thread_functions();
+ break;
+ case 11:
+ testapp_test_print_receving_queue_via_debug_msg();
+ break;
+ case 12:
+ testapp_test_create_db_full();
+ break;
+ case 13:
+ testapp_test_encoding_test();
+ break;
+ case 14:
+ email_test_dtt_Datastore_FI();
+ email_test_dtt_Datastore_C();
+ email_test_dtt_Datastore_R();
+ break;
+ case 0:
+ go_to_loop = FALSE;
+ break;
+ default:
+ break;
+ }
+
+ return go_to_loop;
+}
+
+void testapp_others_main()
+{
+ gboolean go_to_loop = TRUE;
+ int menu_number = 0;
+
+ while (go_to_loop) {
+ testapp_show_menu (EMF_OTHERS_MENU);
+ testapp_show_prompt (EMF_OTHERS_MENU);
+
+ scanf ("%d", &menu_number);
+
+ go_to_loop = testapp_test_interpret_command (menu_number);
+ }
+}
+
diff --git a/utilities/email-service-test-application/email-service-test-application/emf-test-rule.c b/utilities/email-service-test-application/email-service-test-application/emf-test-rule.c
new file mode 100755
index 0000000..c2621b9
--- /dev/null
+++ b/utilities/email-service-test-application/email-service-test-application/emf-test-rule.c
@@ -0,0 +1,245 @@
+/*
+* email-service
+*
+* Copyright (c) 2000 - 2011 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.
+*
+*/
+
+
+
+/* common header */
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+
+/* open header */
+#include <glib.h>
+
+#include "Emf_Mapi_Rule.h"
+
+/* internal header */
+#include "emf-test-utility.h"
+#include "emf-test-mailbox.h"
+
+static gboolean testapp_test_add_rule()
+{
+ emf_rule_t* rule = NULL;
+ int account_id = 0;
+ int action = 0;
+ int type = 0;
+ int flag = 0;
+ char arg[500];
+
+ rule = malloc(sizeof(emf_rule_t));
+ testapp_print("> Enter account id: ");
+ scanf("%d", &account_id);
+ rule->account_id = account_id;
+
+ testapp_print("> Enter Type(FROM - 1 / SUBJECT - 2): ");
+ scanf("%d", &type);
+ rule->type= type;
+
+ memset(arg, 0x00, 500);
+ testapp_print("\n> Enter Filtering Value:");
+ scanf("%s",arg);
+ rule->value= strdup(arg);
+
+ testapp_print("> Enter Action(MOVE - 1, BLOCK - 2, DELETE - 3): ");
+ scanf("%d", &action);
+ rule->faction= action;
+
+ memset(arg, 0x00, 500);
+ testapp_print("\n> Enter mailbox name:");
+ scanf("%s",arg);
+ rule->mailbox= strdup(arg);
+
+ testapp_print("> Enter Flag1 value: ");
+ scanf("%d", &flag);
+ rule->flag1= flag;
+
+ testapp_print("> Enter Flag2 value: ");
+ scanf("%d", &flag);
+ rule->flag2= flag;
+
+ if ( email_add_rule(rule) < 0)
+ testapp_print("\n EmfRuleAdd failed");
+
+
+ email_free_rule(&rule, 1);
+
+ return FALSE;
+}
+
+static gboolean testapp_test_delete_rule()
+{
+
+ int filter_id = 0;
+
+ testapp_print("> Enter filter id: ");
+ scanf("%d", &filter_id);
+
+ if(email_delete_rule(filter_id) < 0)
+ testapp_print("email_delete_rule failed..! ");
+
+ return FALSE;
+}
+
+
+static gboolean testapp_test_update_rule()
+{
+
+ emf_rule_t* rule = NULL;
+ int account_id = 0;
+ int action = 0;
+ int type = 0;
+ int flag = 0;
+ char arg[500];
+ int filter_id = 0;
+
+ rule = malloc(sizeof(emf_rule_t));
+ memset(rule,0X00,sizeof(emf_rule_t));
+ testapp_print("> Enter filter id: ");
+ scanf("%d", &filter_id);
+
+ testapp_print("> Enter account id: ");
+ scanf("%d", &account_id);
+ rule->account_id = account_id;
+
+ testapp_print("> Enter Type(FROM - 1 / SUBJECT - 2): ");
+ scanf("%d", &type);
+ rule->type= type;
+
+ memset(arg, 0x00, 500);
+ testapp_print("\n> Enter Filtering Value:");
+ scanf("%s",arg);
+ rule->value= strdup(arg);
+
+ testapp_print("> Enter Action(MOVE - 1, BLOCK - 2, DELETE - 3): ");
+ scanf("%d", &action);
+ rule->faction= action;
+
+ memset(arg, 0x00, 500);
+ testapp_print("\n> Enter mailbox name:");
+ scanf("%s",arg);
+ rule->mailbox= strdup(arg);
+
+ testapp_print("> Enter Flag1 value: ");
+ scanf("%d", &flag);
+ rule->flag1= flag;
+
+ testapp_print("> Enter Flag2 value: ");
+ scanf("%d", &flag);
+ rule->flag2= flag;
+
+ if( !email_update_rule(filter_id, rule) < 0)
+ testapp_print("email_update_rule failed..! ");
+
+ email_free_rule(&rule, 1);
+
+ return FALSE;
+}
+
+
+static gboolean testapp_test_get_rule(void)
+{
+ emf_rule_t* rule = NULL;
+ int filter_id = 0;
+
+ testapp_print("> Enter filter id: ");
+ scanf("%d", &filter_id);
+
+ if(email_get_rule(filter_id, &rule) >= 0)
+ testapp_print("\n Got rule of account_id = %d and type = %d\n", rule->account_id, rule->type);
+
+ email_free_rule(&rule, 1);
+
+ return FALSE;
+
+}
+
+static gboolean testapp_test_get_rule_list (void)
+{
+ int count, i;
+ emf_rule_t* rule_list=NULL;
+
+ if(email_get_rule_list(&rule_list, &count) < 0) {
+ testapp_print(" email_get_rule_list error\n");
+ return false ;
+ }
+
+ for(i=0;i<count;i++){
+ testapp_print(" %2d) Fileter_Id: %d | Account_id: %d | Type: %d | Value %s \n", i+1,
+ rule_list[i].filter_id,
+ rule_list[i].account_id,
+ rule_list[i].type,
+ rule_list[i].value);
+ }
+
+ email_free_rule(&rule_list, count);
+ return FALSE;
+
+}
+
+
+
+static gboolean testapp_test_interpret_command (int menu_number)
+{
+ gboolean go_to_loop = TRUE;
+
+ switch (menu_number) {
+ case 1:
+ testapp_test_add_rule();
+ break;
+ case 2:
+ testapp_test_delete_rule ();
+ break;
+ case 3:
+ testapp_test_update_rule();
+ break;
+ case 5:
+ testapp_test_get_rule ();
+ break;
+ case 6:
+ testapp_test_get_rule_list();
+ break;
+
+ case 0:
+ go_to_loop = FALSE;
+ break;
+ default:
+ break;
+ }
+
+ return go_to_loop;
+}
+
+void emf_test_rule_main()
+{
+ gboolean go_to_loop = TRUE;
+ int menu_number = 0;
+
+ while (go_to_loop) {
+ testapp_show_menu (EMF_RULE_MENU);
+ testapp_show_prompt (EMF_RULE_MENU);
+
+ scanf ("%d", &menu_number);
+
+ go_to_loop = testapp_test_interpret_command (menu_number);
+ }
+}
+
diff --git a/utilities/email-service-test-application/email-service-test-application/emf-test-thread.c b/utilities/email-service-test-application/email-service-test-application/emf-test-thread.c
new file mode 100755
index 0000000..8f74588
--- /dev/null
+++ b/utilities/email-service-test-application/email-service-test-application/emf-test-thread.c
@@ -0,0 +1,134 @@
+/*
+* email-service
+*
+* Copyright (c) 2000 - 2011 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.
+*
+*/
+
+
+
+/* common header */
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+
+/* open header */
+#include <glib.h>
+
+#include "Emf_Mapi_Message.h"
+
+/* internal header */
+#include "emf-test-utility.h"
+#include "emf-test-thread.h"
+
+static gboolean testapp_test_move_thread()
+{
+ int thread_id, move_always_flag;
+ char target_mailbox_name[512];
+ int result;
+
+ testapp_print("\n > Enter thread_id: ");
+ scanf("%d", &thread_id);
+
+ testapp_print("\n > Enter target_mailbox_name: ");
+ scanf("%s", target_mailbox_name);
+
+ testapp_print("\n > Enter move_always_flag: ");
+ scanf("%d", &move_always_flag);
+
+ result = email_move_thread_to_mailbox(thread_id, target_mailbox_name, move_always_flag);
+
+ return FALSE;
+}
+
+static gboolean testapp_test_delete_thread()
+{
+ int thread_id, delete_always_flag;
+ int result;
+
+ testapp_print("\n > Enter thread_id: ");
+ scanf("%d", &thread_id);
+
+ testapp_print("\n > Enter delete_always_flag: ");
+ scanf("%d", &delete_always_flag);
+
+ result = email_delete_thread(thread_id, delete_always_flag);
+
+ return FALSE;
+}
+
+static gboolean testapp_test_set_seen_flag_of_thread()
+{
+ int thread_id, seen_flag, on_server;
+ int result;
+
+ testapp_print("\n > Enter thread_id: ");
+ scanf("%d", &thread_id);
+
+ testapp_print("\n > Enter seen_flag: ");
+ scanf("%d", &seen_flag);
+
+ testapp_print("\n > Enter on_server: ");
+ scanf("%d", &on_server);
+
+ result = email_modify_seen_flag_of_thread(thread_id, seen_flag, on_server);
+
+ return FALSE;
+}
+
+static gboolean testapp_test_interpret_command (int menu_number)
+{
+ gboolean go_to_loop = TRUE;
+
+ switch (menu_number) {
+ case 1:
+ testapp_test_move_thread();
+ break;
+
+ case 2:
+ testapp_test_delete_thread();
+ break;
+
+ case 3:
+ testapp_test_set_seen_flag_of_thread();
+ break;
+
+ case 0:
+ go_to_loop = FALSE;
+ break;
+ default:
+ break;
+ }
+
+ return go_to_loop;
+}
+
+void testapp_thread_main()
+{
+ gboolean go_to_loop = TRUE;
+ int menu_number = 0;
+
+ while (go_to_loop) {
+ testapp_show_menu (EMF_THREAD_MENU);
+ testapp_show_prompt (EMF_THREAD_MENU);
+
+ scanf ("%d", &menu_number);
+
+ go_to_loop = testapp_test_interpret_command (menu_number);
+ }
+} \ No newline at end of file
diff --git a/utilities/email-service-test-application/email-service-test-application/emf-test-utility.c b/utilities/email-service-test-application/email-service-test-application/emf-test-utility.c
new file mode 100755
index 0000000..186ad4a
--- /dev/null
+++ b/utilities/email-service-test-application/email-service-test-application/emf-test-utility.c
@@ -0,0 +1,228 @@
+/*
+* email-service
+*
+* Copyright (c) 2000 - 2011 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.
+*
+*/
+
+
+
+/* common header */
+#include <stdarg.h>
+#include <string.h>
+
+/* open header */
+#include <glib.h>
+#include <glib/gprintf.h>
+
+/* internal header */
+#include "emf-test-utility.h"
+
+/* internal data struct */
+
+void testapp_print (char *fmt, ...)
+{
+ va_list args = {0};
+ va_start(args, fmt);
+ vfprintf (stdout, fmt, args);
+ va_end (args);
+ fflush (stdout);
+}
+
+void testapp_show_menu (eEMF_MENU menu)
+{
+ switch (menu) {
+ case EMF_MAIN_MENU:
+ testapp_print ("==========================================\n");
+ testapp_print (" Email service test application \n");
+ testapp_print ("==========================================\n");
+ testapp_print ("1. Account Test\n");
+ testapp_print ("2. Message Test\n");
+ testapp_print ("3. Mailbox Test\n");
+ testapp_print ("5. Rule Test\n");
+ testapp_print ("6. Thread Test\n");
+ testapp_print ("7. Others\n");
+ testapp_print ("0. Exit \n");
+ testapp_print ("------------------------------------------\n");
+ break;
+
+ case EMF_ACCOUNT_MENU:
+ testapp_print ("==========================================\n");
+ testapp_print (" ACCOUNT MENU \n");
+ testapp_print ("==========================================\n");
+ testapp_print (" 1. Create Account\n");
+ testapp_print (" 2. Update Account\n");
+ testapp_print (" 3. Delete Account\n");
+ testapp_print (" 4. Get Account\n");
+ testapp_print (" 5. Get Account List\n");
+ testapp_print (" 7. Validate Account\n");
+ testapp_print (" 8. Cancel validate Account\n");
+ testapp_print (" 9. Backup All Accounts\n");
+ testapp_print (" 10. Restore accounts\n");
+ testapp_print (" 11. Get password length of account\n");
+ testapp_print (" 13. Clear all notifications\n");
+ testapp_print (" 0. Go to Main Menu\n");
+ testapp_print ("------------------------------------------\n");
+ break;
+
+ case EMF_MESSAGE_MENU:
+ testapp_print ("==========================================\n");
+ testapp_print (" MESSAGE MENU\n");
+ testapp_print ("==========================================\n");
+ testapp_print ("1. Mail Save\n");
+ testapp_print ("2. Mail Send\n");
+ testapp_print ("3. Mail Update\n");
+ testapp_print ("4. Add Attachment\n");
+ testapp_print ("5. Get Mail \n");
+ testapp_print ("6. Get Mail Info\n");
+ testapp_print ("7. Get Mail Header\n");
+ testapp_print ("8. Get Mail Body\n");
+ testapp_print ("9. Mail Count \n");
+ testapp_print ("10. Mail Flag Modify\n");
+ testapp_print ("11. Mail Extra Flag Modify\n");
+ testapp_print ("12. Download \n");
+ testapp_print ("14. Mail Delete\n");
+ testapp_print ("16. Download body\n");
+ testapp_print ("17. Download attachment\n");
+ testapp_print ("18. Load test - mail send\n");
+ testapp_print ("19. Mailbox Get List\n");
+ testapp_print ("20. Mail Delete All\n");
+ testapp_print ("21. Mail move\n");
+ testapp_print ("23. Mail Resend\n");
+ testapp_print ("24. Find mails\n");
+ testapp_print ("26. Count Messages On Sending\n");
+ testapp_print ("27. Move all mails to mailbox\n");
+ testapp_print ("28. Count Messages with Draft Flag\n");
+ testapp_print ("29. Get latest unread mail Id\n");
+ testapp_print ("38. Get total email disk usage \n");
+ testapp_print ("39. Send Mail with Option \n");
+ testapp_print ("40. Email Address Format Check\n");
+ testapp_print ("41. Get Max Mail Count\n");
+ testapp_print ("42. Storage test : (Input : to fields)\n");
+ testapp_print ("43. Send mail Cancel\n");
+ testapp_print ("44. Cancel Download Body\n");
+ testapp_print ("48. Get thread information\n");
+ testapp_print ("49. Get sender list\n");
+ testapp_print ("51. Get mail list ex\n");
+ testapp_print ("52. Get address info list\n");
+ testapp_print ("53. Save HTML mail with inline content\n");
+ testapp_print ("55. Set a field of flags\n");
+ testapp_print ("56. Add mail\n");
+ testapp_print ("57. Update mail\n");
+ testapp_print ("0. Go to Main Menu\n");
+ testapp_print ("------------------------------------------\n");
+ break;
+
+ case EMF_MAILBOX_MENU:
+ testapp_print ("==========================================\n");
+ testapp_print (" MAILBOX MENU\n");
+ testapp_print ("==========================================\n");
+ testapp_print ("1. Add mailbox\n");
+ testapp_print ("2. Delete mailbox\n");
+ testapp_print ("3. Update mailbox\n");
+ testapp_print ("4. Get IMAP mailbox List\n");
+ testapp_print ("6. Get Child List for given mailbox \n");
+ testapp_print ("7. Get mailbox by mailbox type\n");
+ testapp_print ("8. Set mail slot size\n");
+ testapp_print ("0. Go to Main Menu\n");
+ testapp_print ("------------------------------------------\n");
+ break;
+
+ case EMF_RULE_MENU:
+ testapp_print ("==========================================\n");
+ testapp_print (" RULE MENU\n");
+ testapp_print ("==========================================\n");
+ testapp_print ("1. Add Rule\n");
+ testapp_print ("2. Delete Rule\n");
+ testapp_print ("3. Update Rule\n");
+ testapp_print ("5. Get Rule\n");
+ testapp_print ("6. Get Rule List\n");
+ testapp_print ("0. Go to Main Menu\n");
+ testapp_print ("------------------------------------------\n");
+ break;
+
+ case EMF_THREAD_MENU:
+ testapp_print ("==========================================\n");
+ testapp_print (" TRHEAD MENU\n");
+ testapp_print ("==========================================\n");
+ testapp_print ("1. Move Thread\n");
+ testapp_print ("2. Delete Thread\n");
+ testapp_print ("3. Set Seen Flag of Thread\n");
+ testapp_print ("0. Go to Main Menu\n");
+ testapp_print ("------------------------------------------\n");
+ break;
+
+ case EMF_OTHERS_MENU:
+ testapp_print ("==========================================\n");
+ testapp_print (" OTHERS\n");
+ testapp_print ("==========================================\n");
+ testapp_print ("1. Get Network Status\n");
+ testapp_print ("2. Get Pending Job\n");
+ testapp_print ("3. Cancel Job\n");
+ testapp_print ("5. Set DNET Proper Profile Type\n");
+ testapp_print ("6. Get DNET Proper Profile Type\n");
+ testapp_print ("7. Send mail cancel job\n");
+ testapp_print ("8. Thread View Test\n");
+ testapp_print ("11. Print receiving event queue via debug msg\n");
+ testapp_print ("12. Create DB full\n");
+ testapp_print ("13. Encoding Test\n");
+ testapp_print ("14. DTT Test\n");
+ testapp_print ("0. Go to Main Menu\n");
+ testapp_print ("------------------------------------------\n");
+ break;
+
+ default:
+ break;
+ }
+}
+void testapp_show_prompt (eEMF_MENU menu)
+{
+ switch (menu) {
+ case EMF_MAIN_MENU:
+ testapp_print ("[MAIN]# ");
+ break;
+
+ case EMF_ACCOUNT_MENU:
+ testapp_print ("[ACCOUNT]# ");
+ break;
+
+ case EMF_MESSAGE_MENU:
+ testapp_print ("[MESSAGE]# ");
+ break;
+
+ case EMF_MAILBOX_MENU:
+ testapp_print ("[MAILBOX]# ");
+ break;
+
+ case EMF_RULE_MENU:
+ testapp_print ("[RULE]# ");
+ break;
+
+ case EMF_THREAD_MENU:
+ testapp_print ("[THREAD]# ");
+ break;
+
+ case EMF_OTHERS_MENU:
+ testapp_print ("[OTHERS]# ");
+ break;
+
+ default:
+ break;
+ }
+}
+
+
diff --git a/utilities/email-service-test-application/email-service-test-application/include/emf-test-account.h b/utilities/email-service-test-application/email-service-test-application/include/emf-test-account.h
new file mode 100755
index 0000000..267e01e
--- /dev/null
+++ b/utilities/email-service-test-application/email-service-test-application/include/emf-test-account.h
@@ -0,0 +1,29 @@
+/*
+* email-service
+*
+* Copyright (c) 2000 - 2011 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.
+*
+*/
+
+
+#ifndef EMF_TEST_ACCOUNT_H
+#define EMF_TEST_ACCOUNT_H
+
+/* export API */
+void testapp_account_main();
+
+#endif
diff --git a/utilities/email-service-test-application/email-service-test-application/include/emf-test-mailbox.h b/utilities/email-service-test-application/email-service-test-application/include/emf-test-mailbox.h
new file mode 100755
index 0000000..3f92a9a
--- /dev/null
+++ b/utilities/email-service-test-application/email-service-test-application/include/emf-test-mailbox.h
@@ -0,0 +1,28 @@
+/*
+* email-service
+*
+* Copyright (c) 2000 - 2011 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.
+*
+*/
+
+
+#ifndef EMF_TEST_MAILBOX_H
+#define EMF_TEST_MAILBOX_H
+
+/* export API */
+void emf_test_mailbox_main (void);
+#endif
diff --git a/utilities/email-service-test-application/email-service-test-application/include/emf-test-message.h b/utilities/email-service-test-application/email-service-test-application/include/emf-test-message.h
new file mode 100755
index 0000000..0c50437
--- /dev/null
+++ b/utilities/email-service-test-application/email-service-test-application/include/emf-test-message.h
@@ -0,0 +1,35 @@
+/*
+* email-service
+*
+* Copyright (c) 2000 - 2011 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.
+*
+*/
+
+
+
+#ifndef EMF_TEST_MESSAGE_H
+#define EMF_TEST_MESSAGE_H
+
+#include <glib.h>
+
+
+/* export API */
+void testapp_mail_main (void);
+
+
+#endif /* EMF_TEST_MESSAGE_H */
+
diff --git a/utilities/email-service-test-application/email-service-test-application/include/emf-test-others.h b/utilities/email-service-test-application/email-service-test-application/include/emf-test-others.h
new file mode 100755
index 0000000..6864300
--- /dev/null
+++ b/utilities/email-service-test-application/email-service-test-application/include/emf-test-others.h
@@ -0,0 +1,31 @@
+/*
+* email-service
+*
+* Copyright (c) 2000 - 2011 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.
+*
+*/
+
+
+
+#ifndef EMF_TEST_OTHERS_H
+#define EMF_TEST_OTHERS_H
+
+/* export API */
+void testapp_others_main(void);
+
+#endif
+
diff --git a/utilities/email-service-test-application/email-service-test-application/include/emf-test-rule.h b/utilities/email-service-test-application/email-service-test-application/include/emf-test-rule.h
new file mode 100755
index 0000000..1a59a28
--- /dev/null
+++ b/utilities/email-service-test-application/email-service-test-application/include/emf-test-rule.h
@@ -0,0 +1,31 @@
+/*
+* email-service
+*
+* Copyright (c) 2000 - 2011 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.
+*
+*/
+
+
+
+#ifndef EMF_TEST_RULE_H
+#define EMF_TEST_RULE_H
+
+/* export API */
+void emf_test_rule_main (void);
+
+#endif
+
diff --git a/utilities/email-service-test-application/email-service-test-application/include/emf-test-thread.h b/utilities/email-service-test-application/email-service-test-application/include/emf-test-thread.h
new file mode 100755
index 0000000..e5e0e99
--- /dev/null
+++ b/utilities/email-service-test-application/email-service-test-application/include/emf-test-thread.h
@@ -0,0 +1,34 @@
+/*
+* email-service
+*
+* Copyright (c) 2000 - 2011 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.
+*
+*/
+
+
+
+#ifndef EMF_TEST_THREAD_H
+#define EMF_TEST_THREAD_H
+
+#include <glib.h>
+
+
+/* export API */
+void testapp_thread_main();
+
+
+#endif /* EMF_TEST_THREAD_H */ \ No newline at end of file
diff --git a/utilities/email-service-test-application/email-service-test-application/include/emf-test-utility.h b/utilities/email-service-test-application/email-service-test-application/include/emf-test-utility.h
new file mode 100755
index 0000000..0083bbb
--- /dev/null
+++ b/utilities/email-service-test-application/email-service-test-application/include/emf-test-utility.h
@@ -0,0 +1,47 @@
+/*
+* email-service
+*
+* Copyright (c) 2000 - 2011 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.
+*
+*/
+
+
+
+#ifndef EMF_TEST_UTILITY_H
+#define EMF_TEST_UTILITY_H
+
+#include <glib.h>
+
+typedef enum
+{
+ EMF_MAIN_MENU = 0x0,
+ EMF_ACCOUNT_MENU,
+ EMF_MESSAGE_MENU,
+ EMF_MAILBOX_MENU,
+ EMF_RULE_MENU,
+ EMF_THREAD_MENU,
+ EMF_OTHERS_MENU,
+} eEMF_MENU;
+
+
+/* export API */
+void testapp_print(char *fmt, ...);
+void testapp_show_menu(eEMF_MENU menu);
+void testapp_show_prompt(eEMF_MENU menu);
+
+#endif
+