diff options
author | jk7744.park <jk7744.park@samsung.com> | 2015-02-01 13:42:43 +0900 |
---|---|---|
committer | jk7744.park <jk7744.park@samsung.com> | 2015-02-01 13:42:43 +0900 |
commit | a6c760c2c03fb2b0272c05cd5edcaa1e30364a68 (patch) | |
tree | b6e46642be84e831d291cb4266f07fc68ce2fb75 | |
parent | cf4b33b19053b7909812be3a77bfecd23ff15e76 (diff) | |
download | email-service-tizen_2.3.tar.gz email-service-tizen_2.3.tar.bz2 email-service-tizen_2.3.zip |
tizen 2.3 releasetizen_2.3_releasesubmit/tizen_2.3/20150202.062410tizen_2.3
288 files changed, 39149 insertions, 13113 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6fe4345 --- /dev/null +++ b/.gitignore @@ -0,0 +1,13 @@ +build_log +*.log +*.pyc +usr +opt +*.o +*.os +*.exe +packages +binaries +*.ipk +control +*~ diff --git a/CMakeLists.txt b/CMakeLists.txt index de6dd71..4978b7a 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,25 +27,21 @@ ADD_SUBDIRECTORY(email-ipc) ########################################################## # Define STORAGE, NETWORK, CORE lib ########################################################## - ADD_SUBDIRECTORY(email-core) ########################################################## # Define Email API ########################################################## - ADD_SUBDIRECTORY(email-api) ########################################################## # Define Execute File ########################################################## - ADD_SUBDIRECTORY(email-daemon) ########################################################## # Define Test App ########################################################## - ADD_SUBDIRECTORY(utilities) ########################################################## @@ -53,13 +49,16 @@ ADD_SUBDIRECTORY(utilities) ########################################################## CONFIGURE_FILE(email-service.pc.in email-service.pc @ONLY) - -INSTALL(FILES ${CMAKE_BINARY_DIR}/email-service.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig) +INSTALL(FILES ${CMAKE_BINARY_DIR}/email-service.pc DESTINATION lib/pkgconfig) # LICENSE file -INSTALL(FILES ${CMAKE_SOURCE_DIR}/LICENSE.BSD DESTINATION /usr/share/license RENAME email-service) +INSTALL(FILES ${CMAKE_SOURCE_DIR}/LICENSE DESTINATION /usr/share/license/email-service) + +INSTALL(FILES ${CMAKE_SOURCE_DIR}/email-service.rule DESTINATION /etc/smack/accesses.d RENAME email-service.rule) -INSTALL(FILES ${CMAKE_SOURCE_DIR}/email-service.rule DESTINATION /opt/etc/smack/accesses.d/) +#INSTALL(DIRECTORY ${CMAKE_SOURCE_DIR}/res/ DESTINATION /opt/usr/data/email/res/image FILES_MATCHING PATTERN "*.png") +#INSTALL(DIRECTORY ${CMAKE_SOURCE_DIR}/res/ DESTINATION /opt/usr/data/email/res FILES_MATCHING PATTERN "*.sql") -INSTALL(DIRECTORY ${CMAKE_SOURCE_DIR}/res/ DESTINATION /opt/usr/data/email/res/image FILES_MATCHING PATTERN "*.png") -INSTALL(DIRECTORY ${CMAKE_SOURCE_DIR}/res/ DESTINATION /opt/usr/data/email/res FILES_MATCHING PATTERN "*.sql") +INSTALL(FILES ${CMAKE_SOURCE_DIR}/res/noti_single_email.png DESTINATION /usr/share/email-service) +INSTALL(FILES ${CMAKE_SOURCE_DIR}/res/noti_single_indicator_email.png DESTINATION /usr/share/email-service) +INSTALL(FILES ${CMAKE_SOURCE_DIR}/res/email-service.sql DESTINATION /usr/share/email-service) diff --git a/LICENSE.APLv2 b/LICENSE index 74f474e..7d6a5a6 100644..100755 --- a/LICENSE.APLv2 +++ b/LICENSE @@ -201,3 +201,27 @@ Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. 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. + +------------------------------------------------------------------------------- +Copyright (c) 2005-2010, Troy D. Hanson http://tpl.sourceforge.net +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS +IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A +PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER +OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + diff --git a/LICENSE.BSD b/LICENSE.BSD deleted file mode 100644 index b68368e..0000000 --- a/LICENSE.BSD +++ /dev/null @@ -1,20 +0,0 @@ -Copyright (c) 2005-2010, Troy D. Hanson http://tpl.sourceforge.net -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS -IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED -TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A -PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER -OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. @@ -1,7 +0,0 @@ -Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. -Except as noted, this software is licensed under Apache License, Version 2. -Please, see the LICENSE.APLv2 file for Apache License, Version 2 terms and conditions. - -tpl.c and tpl.h are licensed under BSD license. -Please, see copyright and license comments section in the header of each file, -and the LICENSE.BSD file for BSD License terms and conditions. diff --git a/TC/TC_email_service/Makefile b/TC/TC_email_service/Makefile new file mode 100755 index 0000000..ddb5074 --- /dev/null +++ b/TC/TC_email_service/Makefile @@ -0,0 +1,33 @@ +testbuildtype=normal +#export testbuildtype + +all: TCInit TCAccount TCFolder TCRule TCNetwork TCMessage + echo done + +TCInit: + make -s -C TC_Init + +TCAccount: + make -s -C TC_Account + + +TCFolder: + make -s -C TC_Folder + +TCRule: + make -s -C TC_Rule + +TCNetwork: + make -s -C TC_Network + +TCMessage: + make -s -C TC_Message + +clean: + make clean -C TC_Init + make clean -C TC_Account + make clean -C TC_Folder + make clean -C TC_Rule + make clean -C TC_Network + make clean -C TC_Message + diff --git a/TC/TC_email_service/TC_Account/Makefile b/TC/TC_email_service/TC_Account/Makefile new file mode 100755 index 0000000..557a5ee --- /dev/null +++ b/TC/TC_email_service/TC_Account/Makefile @@ -0,0 +1,55 @@ +################################################### +# add your TestCase List Here +# +# e.g., +# TC1 = utc_frameworkName_apiName_func +# TC2 = utc_ApplicationLib_recurGetDayOfWeek_func +TARGETS = uts-email-add-account \ + uts-email-add-account-with-validation \ + uts-email-free-account \ + uts-email-get-account \ + uts-email-get-account-list \ + uts-email-update-account \ + uts-email-validate-account \ + uts-email-delete-account +# uts-email-get-account-list-refer \ + uts-email-get-account-refer +################################################### +# add your Package Config Info Here +# +# e.g., +# PKGS=calendar +PKGS= email-service + +LIBS = `pkg-config --libs $(PKGS)` +LIBS += `pkg-config --libs glib-2.0` +LIBS +=$(TET_ROOT)/lib/tet3/tcm_s.o +LIBS +=-L$(TET_ROOT)/lib/tet3 -ltcm_s +LIBS +=-L$(TET_ROOT)/lib/tet3 -lapi_s + +INCS = -I. `pkg-config --cflags $(PKGS)` +INCS += -I. `pkg-config --cflags glib-2.0` +INCS += -I$(TET_ROOT)/inc/tet3 +INCS += -I$(TET_SUITE_ROOT)/TC_email_service/TC_Utility + +UTIL_SRC = $(TET_SUITE_ROOT)/TC_email_service/TC_Utility/uts-email-dummy-utility.c +UTIL_SRC += $(TET_SUITE_ROOT)/TC_email_service/TC_Utility/uts-email-real-utility.c + +CFLAGS = $(INCS) +CFLAGS += -D_TETWARE_MODE +LDFLAGS = $(LIBS) + +################################################### +# Modify here +# depending on the Test Case you want to build +# +# e.g., +# TCLIST = $(TC1) $(TC2) +all : $(TARGETS) + +$(TARGETS) : %: %.c + $(CC) -o $@ $< $(CFLAGS) $(LDFLAGS) + +clean : + rm -rf $(TARGETS) + diff --git a/TC/TC_email_service/TC_Account/tslist b/TC/TC_email_service/TC_Account/tslist new file mode 100755 index 0000000..3f2b3ed --- /dev/null +++ b/TC/TC_email_service/TC_Account/tslist @@ -0,0 +1,8 @@ +uts-email-add-account +uts-email-validate-account +uts-email-update-account +uts-email-add-account-with-validation +uts-email-get-account +uts-email-get-account-list +uts-email-free-account +uts-email-delete-account diff --git a/TC/TC_email_service/TC_Account/uts-email-add-account-with-validation.c b/TC/TC_email_service/TC_Account/uts-email-add-account-with-validation.c new file mode 100755 index 0000000..72319c7 --- /dev/null +++ b/TC/TC_email_service/TC_Account/uts-email-add-account-with-validation.c @@ -0,0 +1,137 @@ +/* +* Copyright (c) 2012 - 2013 Samsung Electronics, Inc. +* All rights reserved. +* +* This software is a confidential and proprietary information of Samsung +* Electronics, Inc. ("Confidential Information"). 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. +*/ + +#include "uts-email-add-account-with-validation.h" + +sqlite3 *sqlite_emmb; + +static void startup() +{ + tet_printf("\n TC startup"); + if (EMAIL_ERROR_NONE == email_service_begin()) { + tet_infoline("Email service Begin\n"); + if (EMAIL_ERROR_NONE == email_open_db()) + tet_infoline("Email open DB success\n"); + else + tet_infoline("Email open DB failed\n"); + } + else { + tet_infoline("Email service not started\n"); + } +} + +static void cleanup() +{ + tet_printf("\n TC End"); + if (EMAIL_ERROR_NONE == email_close_db()) { + tet_infoline("Email Close DB Success\n"); + if (EMAIL_ERROR_NONE == email_service_end()) + tet_infoline("Email service close Success\n"); + else + tet_infoline("Email service end failed\n"); + } + else + tet_infoline("Email Close DB failed\n"); +} + +/*Testcase : uts_Email_Add_Account_With_Validation_01 + TestObjective : To add and validate an email account + APIs Tested : int email_add_account_with_validation(email_account_t *account, unsigned *handle) + */ + +static void uts_Email_Add_Account_With_Validation_01() +{ + email_account_t *account = NULL; + int handle; + int err_code = EMAIL_ERROR_NONE; + + tet_infoline("uts_Email_Add_Account_With_Validation_01 Begin\n"); + account = (email_account_t *)malloc(sizeof(email_account_t)); + if (account) { + memset(account, 0x00, sizeof(email_account_t)); + + account->account_name = strdup("GmailImap"); + account->user_display_name = strdup("samsungtest"); + account->user_email_address = strdup("samsungtest09@gmail.com"); + account->reply_to_address = strdup("samsungtest09@gmail.com"); + account->return_address = strdup("samsungtest09@gmail.com"); + account->incoming_server_type = EMAIL_SERVER_TYPE_IMAP4; + account->incoming_server_address= strdup("imap.gmail.com"); + account->incoming_server_port_number = 993; + account->incoming_server_secure_connection = 1; + account->retrieval_mode = EMAIL_IMAP4_RETRIEVAL_MODE_NEW; + account->incoming_server_user_name = strdup("Samsung Test 09"); + account->incoming_server_password = strdup("samsung09"); + account->outgoing_server_type = EMAIL_SERVER_TYPE_SMTP; + account->outgoing_server_address = strdup("smtp.gmail.com"); + account->outgoing_server_port_number = 465; + account->outgoing_server_secure_connection = 1; + account->outgoing_server_need_authentication = 1; + account->outgoing_server_user_name = strdup("samsungtest09"); + account->outgoing_server_password = strdup("samsung09"); + account->pop_before_smtp = 0; + account->incoming_server_requires_apop = 0; + account->auto_download_size = 0; /* downloading option, 0 is subject only, 1 is text body, 2 is normal */ + account->outgoing_server_use_same_authenticator = 1; /* Specifies the 'Same as POP3' option, 0 is none, 1 is 'Same as POP3 */ + account->logo_icon_path = NULL; + 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 = strdup("Gmail POP3 Signature"); + account->check_interval = 0; + + err_code = email_add_account_with_validation(account, &handle); + if (EMAIL_ERROR_NONE == err_code) { + tet_printf("Email add account_with_validation success : accountID[%d]\n", account->account_id); + tet_result(TET_PASS); + } + else { + tet_printf("Email add account_with_validation failed : error_code[%d]\n", err_code); + tet_result(TET_FAIL); + } + email_free_account(&account, 1); + } +} + +/*Testcase : uts_Email_Add_Account_With_Validation_02 + TestObjective : To validate parameter for account in add an email account with validation + APIs Tested : int email_add_account_with_validation(email_account_t *account, unsigned *handle) + */ + +static void uts_Email_Add_Account_With_Validation_02() +{ + int err_code = EMAIL_ERROR_NONE; + email_account_t *pAccount = NULL ; + int handle; + + tet_infoline("uts_Email_Add_Account_With_Validation_02 : Begin\n"); + + err_code = email_add_account_with_validation(pAccount, &handle); + if (EMAIL_ERROR_NONE != err_code) { + tet_printf("Email add account with validation success\n"); + tet_result(TET_PASS); + } + else { + tet_printf("Email add account with validation failed\n"); + tet_result(TET_FAIL); + } +} + + + diff --git a/TC/TC_email_service/TC_Account/uts-email-add-account-with-validation.h b/TC/TC_email_service/TC_Account/uts-email-add-account-with-validation.h new file mode 100755 index 0000000..45bb09b --- /dev/null +++ b/TC/TC_email_service/TC_Account/uts-email-add-account-with-validation.h @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2012 - 2013 Samsung Electronics, Co., Ltd. + * All rights reserved. + * + * This software is a confidential and proprietary information of Samsung + * Electronics, Co., Ltd. ("Confidential Information"). 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. + */ + +#include <tet_api.h> +#include <string.h> +#include <stdlib.h> +#include <sqlite3.h> +#include "email-api-init.h" +#include "email-api-account.h" + +static void startup(), cleanup(); +void (*tet_startup) () = startup; +void (*tet_cleanup) () = cleanup; + +static void uts_Email_Add_Account_With_Validation_01(void); +static void uts_Email_Add_Account_With_Validation_02(void); + +struct tet_testlist tet_testlist[] = { + { uts_Email_Add_Account_With_Validation_01, 1}, { uts_Email_Add_Account_With_Validation_02, 2}, {NULL, 0} + + +}; diff --git a/TC/TC_email_service/TC_Account/uts-email-add-account.c b/TC/TC_email_service/TC_Account/uts-email-add-account.c new file mode 100755 index 0000000..c307ebb --- /dev/null +++ b/TC/TC_email_service/TC_Account/uts-email-add-account.c @@ -0,0 +1,147 @@ +/* +* Copyright (c) 2012 - 2013 Samsung Electronics, Inc. +* All rights reserved. +* +* This software is a confidential and proprietary information of Samsung +* Electronics, Inc. ("Confidential Information"). 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. +*/ + + +#include "uts-email-add-account.h" + + +sqlite3 *sqlite_emmb; +static int g_accountId; + + + +static void startup() +{ + tet_printf("\n TC startup"); + if (EMAIL_ERROR_NONE == email_service_begin()) { + tet_infoline("Email service Begin\n"); + if (EMAIL_ERROR_NONE == email_open_db()) + tet_infoline("Email open DB success\n"); + else + tet_infoline("Email open DB failed\n"); + } + else { + tet_infoline("Email service not started\n"); + } +} + +static void cleanup() +{ + tet_printf("\n TC End"); + if (EMAIL_ERROR_NONE == email_close_db()) { + tet_infoline("Email Close DB Success\n"); + if (EMAIL_ERROR_NONE == email_service_end()) + tet_infoline("Email service close Success\n"); + else + tet_infoline("Email service end failed\n"); + } + else + tet_infoline("Email Close DB failed\n"); +} + + + + + +/*Testcase : uts_Email_Add_Account_01 + TestObjective : To add an email account + APIs Tested : int email_add_account(email_account_t *account) + */ + +static void uts_Email_Add_Account_01() +{ + email_account_t *account = NULL; + int err_code = EMAIL_ERROR_NONE; + + tet_infoline("uts_Email_Add_Account_01 Begin\n"); + account = (email_account_t *)malloc(sizeof(email_account_t)); + if (account) { + memset(account , 0x00, sizeof(email_account_t)); + + account->account_name = strdup("Gmail POP"); + account->user_display_name = strdup("samsungtest09"); + account->user_email_address = strdup("samsungtest09@gmail.com"); + account->reply_to_address = strdup("samsungtest09@gmail.com"); + account->return_address = strdup("samsungtest09@gmail.com"); + account->incoming_server_type = EMAIL_SERVER_TYPE_POP3; + account->incoming_server_address= strdup("pop.gmail.com"); + account->incoming_server_port_number = 995; + account->incoming_server_secure_connection = 1; + account->retrieval_mode = EMAIL_IMAP4_RETRIEVAL_MODE_NEW; + account->incoming_server_user_name = strdup("samsungtest09"); + account->incoming_server_password = strdup("samsung09"); + account->outgoing_server_type = EMAIL_SERVER_TYPE_SMTP; + account->outgoing_server_address = strdup("smtp.gmail.com"); + account->outgoing_server_port_number = 465; + account->outgoing_server_secure_connection = 1; + account->outgoing_server_need_authentication = 1; + account->outgoing_server_user_name = strdup("samsungtest09"); + account->outgoing_server_password = strdup("samsung09"); + account->pop_before_smtp = 0; + account->incoming_server_requires_apop = 0; + account->auto_download_size = 0; /* downloading option, 0 is subject only, 1 is text body, 2 is normal */ + account->outgoing_server_use_same_authenticator = 1; /* Specifies the 'Same as POP3' option, 0 is none, 1 is 'Same as POP3 */ + account->logo_icon_path = NULL; + 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 = strdup("Gmail POP3 Signature"); + account->check_interval = 0; + + err_code = email_add_account(account); + if (EMAIL_ERROR_NONE == err_code) { + tet_printf("Email add account success : accountID[%d]\n", account->account_id); + tet_result(TET_PASS); + g_accountId = account->account_id; + } + else { + + tet_printf("Email add account failed : error_code[%d]\n", err_code); + tet_result(TET_FAIL); + } + email_free_account(&account, 1); + + } + +} + + +/*Testcase : uts_Email_Add_Account_02 + TestObjective : To validate parameter for add an email account + APIs Tested : int email_add_account(email_account_t *account) + */ +static void uts_Email_Add_Account_02() +{ + int err_code = EMAIL_ERROR_NONE; + email_account_t *pAccount = NULL ; + + tet_infoline("uts_Email_Add_Account_02 : Begin\n"); + + err_code = email_add_account(pAccount); + if (EMAIL_ERROR_NONE != err_code) { + tet_printf("Email add account success\n"); + tet_result(TET_PASS); + } + else { + tet_printf("Email add account failed\n"); + tet_result(TET_FAIL); + } +} + + diff --git a/TC/TC_email_service/TC_Account/uts-email-add-account.h b/TC/TC_email_service/TC_Account/uts-email-add-account.h new file mode 100755 index 0000000..7bd6af9 --- /dev/null +++ b/TC/TC_email_service/TC_Account/uts-email-add-account.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2012 - 2013 Samsung Electronics, Co., Ltd. + * All rights reserved. + * + * This software is a confidential and proprietary information of Samsung + * Electronics, Co., Ltd. ("Confidential Information"). 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. + */ + +#include <tet_api.h> + +#include <string.h> +#include <stdlib.h> +#include <sqlite3.h> +#include "email-api-init.h" +#include "email-api-account.h" + + + +static void startup(), cleanup(); +void (*tet_startup) () = startup; +void (*tet_cleanup) () = cleanup; + +static void uts_Email_Add_Account_01(void); +static void uts_Email_Add_Account_02(void); + + + + +struct tet_testlist tet_testlist[] = { + { uts_Email_Add_Account_01, 1}, { uts_Email_Add_Account_02, 2}, {NULL, 0} + + +}; diff --git a/TC/TC_email_service/TC_Account/uts-email-delete-account.c b/TC/TC_email_service/TC_Account/uts-email-delete-account.c new file mode 100755 index 0000000..584ef95 --- /dev/null +++ b/TC/TC_email_service/TC_Account/uts-email-delete-account.c @@ -0,0 +1,121 @@ +/* +* Copyright (c) 2012 - 2013 Samsung Electronics, Inc. +* All rights reserved. +* +* This software is a confidential and proprietary information of Samsung +* Electronics, Inc. ("Confidential Information"). 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. +*/ + + +#include "uts-email-delete-account.h" +#include "../TC_Utility/uts-email-dummy-utility.c" + + +sqlite3 *sqlite_emmb; +static int g_accountId; + + + +static void startup() +{ + int err_code = EMAIL_ERROR_NONE; + int count = 0; + int i = 0; + email_account_t *pAccount = NULL ; + + tet_printf("\n TC startup"); + if (EMAIL_ERROR_NONE == email_service_begin()) { + tet_infoline("Email service Begin\n"); + if (EMAIL_ERROR_NONE == email_open_db()) { + tet_infoline("Email open DB success\n"); + err_code = email_get_account_list(&pAccount, &count); + if (!count) { + g_accountId = uts_Email_Add_Dummy_Account_01(); + } + else + g_accountId = pAccount[i].account_id; + email_free_account(&pAccount, count); + + } + else + tet_infoline("Email open DB failed\n"); + } + else { + tet_infoline("Email service not started\n"); + } +} + +static void cleanup() +{ + tet_printf("\n TC End"); + if (EMAIL_ERROR_NONE == email_close_db()) { + tet_infoline("Email Close DB Success\n"); + if (EMAIL_ERROR_NONE == email_service_end()) + tet_infoline("Email service close Success\n"); + else + tet_infoline("Email service end failed\n"); + } + else + tet_infoline("Email Close DB failed\n"); +} + + + + + + + +/*Testcase : uts_Email_Delete_Account_01 + TestObjective : To delete an email account + APIs Tested : int email_delete_account(int account_id) + */ + +static void uts_Email_Delete_Account_01() +{ + int err_code = EMAIL_ERROR_NONE; + int account_id = 0; + int count = 0; + int i = 0; + email_account_t *pAccount = NULL ; + + tet_infoline("uts_Email_Delete_Account_01 : Begin\n"); + account_id = g_accountId; + + + err_code = email_delete_account(account_id); + if (EMAIL_ERROR_NONE == err_code) { + tet_infoline("Email delete account : success\n"); + tet_result(TET_PASS); + } + else { + tet_printf("Email delete account failed : error_code[%d]\n", err_code); + tet_result(TET_FAIL); + } +} + + +/*Testcase : uts_Email_Delete_Account_02 + TestObjective : To validate parameter for delete an email account + APIs Tested : int email_delete_account(int account_id) + */ + +static void uts_Email_Delete_Account_02() +{ + int err_code = EMAIL_ERROR_NONE; + int account_id = -1; + + tet_infoline("uts_Email_Delete_Account_02 : Begin\n"); + + err_code = email_delete_account(account_id); + if (EMAIL_ERROR_NONE != err_code) { + tet_infoline("Email delete account success\n"); + tet_result(TET_PASS); + } + else { + tet_printf("Email delete account failed : \n"); + tet_result(TET_FAIL); + } +} + diff --git a/TC/TC_email_service/TC_Account/uts-email-delete-account.h b/TC/TC_email_service/TC_Account/uts-email-delete-account.h new file mode 100755 index 0000000..976c228 --- /dev/null +++ b/TC/TC_email_service/TC_Account/uts-email-delete-account.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2012 - 2013 Samsung Electronics, Co., Ltd. + * All rights reserved. + * + * This software is a confidential and proprietary information of Samsung + * Electronics, Co., Ltd. ("Confidential Information"). 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. + */ + +#include <tet_api.h> + +#include <string.h> +#include <stdlib.h> +#include <sqlite3.h> +#include "email-api-init.h" +#include "email-api-account.h" +#include "../TC_Utility/uts-email-dummy-utility.h" +/* #include "uts-email-dummy-utility.h */ + + +static void startup(), cleanup(); +void (*tet_startup) () = startup; +void (*tet_cleanup) () = cleanup; + +static void uts_Email_Delete_Account_01(void); +static void uts_Email_Delete_Account_02(void); + + + + +struct tet_testlist tet_testlist[] = { + { uts_Email_Delete_Account_01, 1}, { uts_Email_Delete_Account_02, 2}, {NULL, 0} + + +}; diff --git a/TC/TC_email_service/TC_Account/uts-email-free-account.c b/TC/TC_email_service/TC_Account/uts-email-free-account.c new file mode 100755 index 0000000..6814b85 --- /dev/null +++ b/TC/TC_email_service/TC_Account/uts-email-free-account.c @@ -0,0 +1,149 @@ +/* +* Copyright (c) 2012 - 2013 Samsung Electronics, Inc. +* All rights reserved. +* +* This software is a confidential and proprietary information of Samsung +* Electronics, Inc. ("Confidential Information"). 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. +*/ + + +#include "uts-email-free-account.h" + + +sqlite3 *sqlite_emmb; + + +static void startup() +{ + tet_printf("\n TC startup"); + if (EMAIL_ERROR_NONE == email_service_begin()) { + tet_infoline("Email service Begin\n"); + if (EMAIL_ERROR_NONE == email_open_db()) + tet_infoline("Email open DB success\n"); + else + tet_infoline("Email open DB failed\n"); + } + else { + tet_infoline("Email service not started\n"); + } +} + +static void cleanup() +{ + tet_printf("\n TC End"); + if (EMAIL_ERROR_NONE == email_close_db()) { + tet_infoline("Email Close DB Success\n"); + if (EMAIL_ERROR_NONE == email_service_end()) + tet_infoline("Email service close Success\n"); + else + tet_infoline("Email service end failed\n"); + } + else + tet_infoline("Email Close DB failed\n"); +} + + + + + + + + +/*Testcase : uts_Email_Free_Account_01 + TestObjective : To free an email account + APIs Tested : int email_free_account(email_account_t **account_list, int count) + */ + +static void uts_Email_Free_Account_01() +{ + email_account_t *account = NULL; + int handle; + int err_code = EMAIL_ERROR_NONE; + + tet_infoline("uts_Email_Free_Account_01 Begin\n"); + account = (email_account_t *)malloc(sizeof(email_account_t)); + if (account) { + memset(account, 0x00, sizeof(email_account_t)); + + account->account_name = strdup("Gmail Account"); + account->user_display_name = strdup("samsungtest"); + account->user_email_address = strdup("samsungtest09@gmail.com"); + account->reply_to_address = strdup("samsungtest09@gmail.com"); + account->return_address = strdup("samsungtest09@gmail.com"); + account->incoming_server_type = EMAIL_SERVER_TYPE_POP3; + account->incoming_server_address= strdup("pop.gmail.com"); + account->incoming_server_port_number = 995; + account->incoming_server_secure_connection = 1; + account->retrieval_mode = EMAIL_IMAP4_RETRIEVAL_MODE_NEW; + account->incoming_server_user_name = strdup("samsungtest09"); + account->incoming_server_password = strdup("samsung09"); + account->outgoing_server_type = EMAIL_SERVER_TYPE_SMTP; + account->outgoing_server_address= strdup("smtp.gmail.com"); + account->outgoing_server_port_number = 465; + account->outgoing_server_secure_connection = 1; + account->outgoing_server_need_authentication = 1; + account->outgoing_server_user_name = strdup("samsungtest09"); + account->outgoing_server_password = strdup("samsung09"); + account->pop_before_smtp = 0; + account->incoming_server_requires_apop = 0; + account->auto_download_size = 0; /* downloading option, 0 is subject only, 1 is text body, 2 is normal */ + account->outgoing_server_use_same_authenticator = 1; /* Specifies the 'Same as POP3' option, 0 is none, 1 is 'Same as POP3 */ + account->logo_icon_path = NULL; + 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 = strdup("Gmail POP3 Signature"); + account->check_interval = 0; + + err_code = email_add_account(account); + if (EMAIL_ERROR_NONE == err_code) + tet_printf("Email add account success : accountID[%d]\n", account->account_id); + else + tet_printf("Email add account_with_validation failed : error_code[%d]\n", err_code); + err_code = email_free_account(&account, 1); + if (EMAIL_ERROR_NONE == err_code) { + tet_infoline("Email free account success\n"); + tet_result(TET_PASS); + } + else { + tet_printf("Email free account : Failed err_code[%d]\n", err_code); + tet_result(TET_FAIL); + } + } +} + +/*Testcase : uts_Email_Free_Account_02 + TestObjective : To validate parameter for account_list in add free email account + APIs Tested : int email_free_account(email_account_t **account_list, int count) + */ + +static void uts_Email_Free_Account_02() +{ + int err_code = EMAIL_ERROR_NONE; + + tet_infoline("uts_Email_Free_Account_02 : Begin\n"); + + err_code = email_free_account(NULL, 1); + if (EMAIL_ERROR_NONE != err_code) { + tet_printf("Email free account success\n"); + tet_result(TET_PASS); + } + else { + tet_printf("Email free account failed\n"); + tet_result(TET_FAIL); + } +} + + + diff --git a/TC/TC_email_service/TC_Account/uts-email-free-account.h b/TC/TC_email_service/TC_Account/uts-email-free-account.h new file mode 100755 index 0000000..ff46972 --- /dev/null +++ b/TC/TC_email_service/TC_Account/uts-email-free-account.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2012 - 2013 Samsung Electronics, Co., Ltd. + * All rights reserved. + * + * This software is a confidential and proprietary information of Samsung + * Electronics, Co., Ltd. ("Confidential Information"). 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. + */ + +#include <tet_api.h> + +#include <string.h> +#include <stdlib.h> +#include <sqlite3.h> +#include "email-api-init.h" +#include "email-api-account.h" + + + +static void startup(), cleanup(); +void (*tet_startup) () = startup; +void (*tet_cleanup) () = cleanup; + +static void uts_Email_Free_Account_01(void); +static void uts_Email_Free_Account_02(void); + + + + +struct tet_testlist tet_testlist[] = { + { uts_Email_Free_Account_01, 1}, { uts_Email_Free_Account_02, 2}, {NULL, 0} + + +}; diff --git a/TC/TC_email_service/TC_Account/uts-email-get-account-list-refer.h b/TC/TC_email_service/TC_Account/uts-email-get-account-list-refer.h new file mode 100755 index 0000000..b913edc --- /dev/null +++ b/TC/TC_email_service/TC_Account/uts-email-get-account-list-refer.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2012 - 2013 Samsung Electronics, Co., Ltd. + * All rights reserved. + * + * This software is a confidential and proprietary information of Samsung + * Electronics, Co., Ltd. ("Confidential Information"). 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. + */ + +#include <tet_api.h> + +#include <string.h> +#include <stdlib.h> +#include <sqlite3.h> +#include "email-api-init.h" +#include "email-api-account.h" + + + +static void startup(), cleanup(); +void (*tet_startup) () = startup; +void (*tet_cleanup) () = cleanup; + +static void uts_Email_Get_Account_List_Refer_01(void); +static void uts_Email_Get_Account_List_Refer_02(void); +static void uts_Email_Get_Account_List_Refer_03(void); + + + + +struct tet_testlist tet_testlist[] = { + { uts_Email_Get_Account_List_Refer_01, 1}, { uts_Email_Get_Account_List_Refer_02, 2}, { uts_Email_Get_Account_List_Refer_03, 3}, {NULL, 0} + + +}; diff --git a/TC/TC_email_service/TC_Account/uts-email-get-account-list.c b/TC/TC_email_service/TC_Account/uts-email-get-account-list.c new file mode 100755 index 0000000..97a72b5 --- /dev/null +++ b/TC/TC_email_service/TC_Account/uts-email-get-account-list.c @@ -0,0 +1,128 @@ +/* +* Copyright (c) 2012 - 2013 Samsung Electronics, Inc. +* All rights reserved. +* +* This software is a confidential and proprietary information of Samsung +* Electronics, Inc. ("Confidential Information"). 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. +*/ + + +#include "uts-email-get-account-list.h" + + +sqlite3 *sqlite_emmb; + + +static void startup() +{ + tet_printf("\n TC startup"); + if (EMAIL_ERROR_NONE == email_service_begin()) { + tet_infoline("Email service Begin\n"); + if (EMAIL_ERROR_NONE == email_open_db()) + tet_infoline("Email open DB success\n"); + else + tet_infoline("Email open DB failed\n"); + } + else { + tet_infoline("Email service not started\n"); + } +} + +static void cleanup() +{ + tet_printf("\n TC End"); + if (EMAIL_ERROR_NONE == email_close_db()) { + tet_infoline("Email Close DB Success\n"); + if (EMAIL_ERROR_NONE == email_service_end()) + tet_infoline("Email service close Success\n"); + else + tet_infoline("Email service end failed\n"); + } + else + tet_infoline("Email Close DB failed\n"); +} + + + + + + +/*Testcase : uts_Email_Get_Account_List_01 + TestObjective : To get account list + APIs Tested : int email_get_account_list(email_account_t **account, int *count) + */ + +static void uts_Email_Get_Account_List_01() +{ + int err_code = EMAIL_ERROR_NONE; + int count = 0; + int i = 0; + email_account_t *pAccount = NULL ; + + tet_infoline("uts_Email_Get_Account_List_01 : Begin\n"); + + err_code = email_get_account_list(&pAccount, &count); + if (EMAIL_ERROR_NONE == err_code) { + tet_infoline("Email get account list success\n"); + for (i ; i < count;i++) + tet_printf("account_id[%d] account_name[%s] email_addr[%s]\n", + pAccount[i].account_id, pAccount[i].account_name, pAccount[i].user_email_address); + + tet_result(TET_PASS); + } + else { + tet_printf("Email get account list failed : error_code[%d]\n", err_code); + tet_result(TET_FAIL); + } +} + + +/*Testcase : uts_Email_Get_Account_List_02 + TestObjective : To validate parameter for account_list in get account list + APIs Tested : int email_get_account_list(email_account_t **account_list, int *count) + */ + +static void uts_Email_Get_Account_List_02() +{ + int err_code = EMAIL_ERROR_NONE; + int count = 0; + + tet_infoline("uts_Email_Get_Account_List_02 : Begin\n"); + + err_code = email_get_account_list(NULL, &count); + if (EMAIL_ERROR_NONE != err_code) { + tet_infoline("Email get account list success\n"); + tet_result(TET_PASS); + } + else { + tet_printf("Email get account list failed : \n"); + tet_result(TET_FAIL); + } +} + + +/*Testcase : uts_Email_Get_Account_List_03 + TestObjective : To validate parameter for count in get account list + APIs Tested : int email_get_account_list(email_account_t **account, int *count) + */ + +static void uts_Email_Get_Account_List_03() +{ + int err_code = EMAIL_ERROR_NONE; + email_account_t *pAccount = NULL ; + + tet_infoline("uts_Email_Get_Account_List_03 : Begin\n"); + + err_code = email_get_account_list(&pAccount, 0); + if (EMAIL_ERROR_NONE != err_code) { + tet_infoline("Email get account list success\n"); + tet_result(TET_PASS); + } + else { + tet_printf("Email get account list failed : \n"); + tet_result(TET_FAIL); + } +} + diff --git a/TC/TC_email_service/TC_Account/uts-email-get-account-list.h b/TC/TC_email_service/TC_Account/uts-email-get-account-list.h new file mode 100755 index 0000000..c0d2fbe --- /dev/null +++ b/TC/TC_email_service/TC_Account/uts-email-get-account-list.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2012 - 2013 Samsung Electronics, Co., Ltd. + * All rights reserved. + * + * This software is a confidential and proprietary information of Samsung + * Electronics, Co., Ltd. ("Confidential Information"). 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. + */ + +#include <tet_api.h> + +#include <string.h> +#include <stdlib.h> +#include <sqlite3.h> +#include "email-api-init.h" +#include "email-api-account.h" + + + +static void startup(), cleanup(); +void (*tet_startup) () = startup; +void (*tet_cleanup) () = cleanup; + +static void uts_Email_Get_Account_List_01(void); +static void uts_Email_Get_Account_List_02(void); +static void uts_Email_Get_Account_List_03(void); + + + + +struct tet_testlist tet_testlist[] = { + { uts_Email_Get_Account_List_01, 1}, { uts_Email_Get_Account_List_02, 2}, { uts_Email_Get_Account_List_03, 3}, {NULL, 0} + + +}; diff --git a/TC/TC_email_service/TC_Account/uts-email-get-account-refer.h b/TC/TC_email_service/TC_Account/uts-email-get-account-refer.h new file mode 100755 index 0000000..fb6ed38 --- /dev/null +++ b/TC/TC_email_service/TC_Account/uts-email-get-account-refer.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2012 - 2013 Samsung Electronics, Co., Ltd. + * All rights reserved. + * + * This software is a confidential and proprietary information of Samsung + * Electronics, Co., Ltd. ("Confidential Information"). 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. + */ + +#include <tet_api.h> + +#include <string.h> +#include <stdlib.h> +#include <sqlite3.h> +#include "email-api-init.h" +#include "email-api-account.h" + + + +static void startup(), cleanup(); +void (*tet_startup) () = startup; +void (*tet_cleanup) () = cleanup; + +static void uts_Email_Get_Account_Refer_01(void); +static void uts_Email_Get_Account_Refer_02(void); +static void uts_Email_Get_Account_Refer_03(void); + + + + +struct tet_testlist tet_testlist[] = { + { uts_Email_Get_Account_Refer_01, 1}, { uts_Email_Get_Account_Refer_02, 2}, { uts_Email_Get_Account_Refer_03, 3}, {NULL, 0} + + +}; diff --git a/TC/TC_email_service/TC_Account/uts-email-get-account.c b/TC/TC_email_service/TC_Account/uts-email-get-account.c new file mode 100755 index 0000000..e6fc5e4 --- /dev/null +++ b/TC/TC_email_service/TC_Account/uts-email-get-account.c @@ -0,0 +1,142 @@ +/* +* Copyright (c) 2012 - 2013 Samsung Electronics, Inc. +* All rights reserved. +* +* This software is a confidential and proprietary information of Samsung +* Electronics, Inc. ("Confidential Information"). 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. +*/ + + +#include "uts-email-get-account.h" +#include "../TC_Utility/uts-email-dummy-utility.c" + + + +sqlite3 *sqlite_emmb; +static int g_accountId; + + +static void startup() +{ + int err_code = EMAIL_ERROR_NONE; + int count = 0; + int i = 0; + email_account_t *pAccount = NULL ; + + tet_printf("\n TC startup"); + if (EMAIL_ERROR_NONE == email_service_begin()) { + tet_infoline("Email service Begin\n"); + if (EMAIL_ERROR_NONE == email_open_db()) { + tet_infoline("Email open DB success\n"); + err_code = email_get_account_list(&pAccount, &count); + if (!count) { + g_accountId = uts_Email_Add_Dummy_Account_01(); + } + else + g_accountId = pAccount[i].account_id; + email_free_account(&pAccount, count); + + } + + else + tet_infoline("Email open DB failed\n"); + } + else { + tet_infoline("Email service not started\n"); + } +} + +static void cleanup() +{ + tet_printf("\n TC End"); + if (EMAIL_ERROR_NONE == email_close_db()) { + tet_infoline("Email Close DB Success\n"); + if (EMAIL_ERROR_NONE == email_service_end()) + tet_infoline("Email service close Success\n"); + else + tet_infoline("Email service end failed\n"); + } + else + tet_infoline("Email Close DB failed\n"); +} + + + + + + +/*Testcase : uts_Email_Get_Account_01 + TestObjective : To get account information based on account id + APIs Tested : int email_get_account(int account_id, int pulloption, email_account_t **account) + */ + +static void uts_Email_Get_Account_01() +{ + int err_code = EMAIL_ERROR_NONE; + email_account_t *pAccount = NULL ; + + tet_infoline("uts_Email_Account_01 : Begin\n"); + + err_code = email_get_account(g_accountId, GET_FULL_DATA, &pAccount); + if (EMAIL_ERROR_NONE == err_code) { + tet_infoline("Email get account success\n"); + tet_printf("account_name[%s]\n email_addr[%s]\n", pAccount->account_name, pAccount->user_email_address); + tet_result(TET_PASS); + } + else { + tet_printf("Email get account failed : error_code[%d]\n", err_code); + tet_result(TET_FAIL); + } + } + +/*Testcase : uts_Email_Get_Account_02 + TestObjective : To validate parameter for account_id in get account information based on account id + APIs Tested : int email_get_account(int account_id, int pulloption, email_account_t **account) + */ + +static void uts_Email_Get_Account_02() +{ + int err_code = EMAIL_ERROR_NONE; + int account_id = -1; + email_account_t *pAccount = NULL ; + + tet_infoline("uts_Email_Get_Account_02 : Begin\n"); + + err_code = email_get_account(account_id, GET_FULL_DATA, &pAccount); + if (EMAIL_ERROR_NONE != err_code) { + tet_infoline("Email get account success\n"); + tet_result(TET_PASS); + } + else { + tet_printf("Email get account failed : \n"); + tet_result(TET_FAIL); + } +} + + +/*Testcase : uts_Email_Get_Account_03 + TestObjective : To validate parameter for account in get account information based on account id + APIs Tested : int email_get_account(int account_id, int pulloption, email_account_t **account) + */ + +static void uts_Email_Get_Account_03() +{ + int err_code = EMAIL_ERROR_NONE; + + tet_infoline("uts_Email_Get_Account_03 : Begin\n"); + + err_code = email_get_account(g_accountId, GET_FULL_DATA, NULL); + if (EMAIL_ERROR_NONE != err_code) { + tet_infoline("Email get account success\n"); + tet_result(TET_PASS); + } + else { + tet_printf("Email get account failed : \n"); + tet_result(TET_FAIL); + } +} + + + diff --git a/TC/TC_email_service/TC_Account/uts-email-get-account.h b/TC/TC_email_service/TC_Account/uts-email-get-account.h new file mode 100755 index 0000000..2207ee9 --- /dev/null +++ b/TC/TC_email_service/TC_Account/uts-email-get-account.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2012 - 2013 Samsung Electronics, Co., Ltd. + * All rights reserved. + * + * This software is a confidential and proprietary information of Samsung + * Electronics, Co., Ltd. ("Confidential Information"). 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. + */ + +#include <tet_api.h> + +#include <string.h> +#include <stdlib.h> +#include <sqlite3.h> +#include "email-api-init.h" +#include "email-api-account.h" + + + +static void startup(), cleanup(); +void (*tet_startup) () = startup; +void (*tet_cleanup) () = cleanup; + +static void uts_Email_Get_Account_01(void); +static void uts_Email_Get_Account_02(void); +static void uts_Email_Get_Account_03(void); + + + + +struct tet_testlist tet_testlist[] = { + { uts_Email_Get_Account_01, 1}, { uts_Email_Get_Account_02, 2}, { uts_Email_Get_Account_03, 3}, {NULL, 0} + + +}; diff --git a/TC/TC_email_service/TC_Account/uts-email-update-account.c b/TC/TC_email_service/TC_Account/uts-email-update-account.c new file mode 100755 index 0000000..509712f --- /dev/null +++ b/TC/TC_email_service/TC_Account/uts-email-update-account.c @@ -0,0 +1,154 @@ +/* +* Copyright (c) 2012 - 2013 Samsung Electronics, Inc. +* All rights reserved. +* +* This software is a confidential and proprietary information of Samsung +* Electronics, Inc. ("Confidential Information"). 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. +*/ + + +#include "uts-email-update-account.h" +#include "../TC_Utility/uts-email-dummy-utility.c" + + +sqlite3 *sqlite_emmb; +int g_accountId; + +static void startup() +{ + int err_code = EMAIL_ERROR_NONE; + int count = 0; + int i = 0; + email_account_t *pAccount = NULL ; + + tet_printf("\n TC startup"); + if (EMAIL_ERROR_NONE == email_service_begin()) { + tet_infoline("Email service Begin\n"); + if (EMAIL_ERROR_NONE == email_open_db()) { + tet_infoline("Email open DB success\n"); + err_code = email_get_account_list(&pAccount, &count); + if (!count) { + g_accountId = uts_Email_Add_Dummy_Account_01(); + } + else + g_accountId = pAccount[i].account_id ; + email_free_account(&pAccount, count); + } + else + tet_infoline("Email open DB failed\n"); + } + else { + tet_infoline("Email service not started\n"); + } +} + +static void cleanup() +{ + tet_printf("\n TC End"); + if (EMAIL_ERROR_NONE == email_close_db()) { + tet_infoline("Email Close DB Success\n"); + if (EMAIL_ERROR_NONE == email_service_end()) + tet_infoline("Email service close Success\n"); + else + tet_infoline("Email service end failed\n"); + } + else + tet_infoline("Email Close DB failed\n"); +} + + + + + + +/*Testcase : uts_Email_Update_Account_01 + TestObjective : To update account information of an email account + APIs Tested : int email_update_account(int account_id, email_account_t *new_account) + */ + +static void uts_Email_Update_Account_01() +{ + int err_code = EMAIL_ERROR_NONE; + int count = 0; + int i = 0; + email_account_t *pAccount = NULL ; + email_account_t *pNewAccount = NULL ; + + tet_infoline("uts_Email_Update_Account_01 : Begin\n"); + + err_code = email_get_account(g_accountId, GET_FULL_DATA, &pNewAccount); + tet_printf("account_id[%d] account_name[%s] email_addr[%s]\n", + pNewAccount[i].account_id, pNewAccount[i].account_name, pNewAccount[i].user_email_address); + + pNewAccount[i].account_name = strdup("Test_Tc"); + pNewAccount[i].user_email_address = strdup("Test@gmail.com"); + + err_code = email_update_account(pNewAccount->account_id , pNewAccount); + if (EMAIL_ERROR_NONE == err_code) { + tet_infoline("Email update account success\n"); + tet_result(TET_PASS); + } + else { + tet_printf("Email update account failed : error_code[%d]\n", err_code); + tet_result(TET_FAIL); + } + } + +/*Testcase : uts_Email_Update_Account_02 + TestObjective : To validate update account parameter. + APIs tested : Tint email_update_account(int account_id, email_account_t *new_account); + */ + +static void uts_Email_Update_Account_02() +{ + int account_id; + int err_code = EMAIL_ERROR_NONE; + email_account_t *pAccount = NULL; + + tet_infoline("uts_Email_Account_02 : Begin\n"); + account_id = -1; + + pAccount = (email_account_t *) malloc(sizeof(email_account_t)); + memset(pAccount, 0x00, sizeof(email_account_t)); + + pAccount->account_name = strdup("UpdateTest"); + + err_code = email_update_account(account_id, pAccount); + if (EMAIL_ERROR_NONE == err_code) { + tet_printf(" email Update Account Falied : \n"); + tet_result (TET_FAIL); + } + else { + tet_printf ("email Update Account successful \n"); + tet_result (TET_PASS); + } + } + + + +/*Testcase : uts_Email_Update_Account_03 + TestObjective : To validate update account parameter. + APIs tested : Tint email_update_account(int account_id, email_account_t *new_account); + */ + +static void uts_Email_Update_Account_03() +{ + int account_id = 1; + int err_code = EMAIL_ERROR_NONE; + email_account_t *pAccount = NULL; + + tet_infoline("utc_Email_Account_14 : Begin\n"); + + err_code = email_update_account(account_id, pAccount); + if (EMAIL_ERROR_NONE == err_code) { + tet_printf(" email Update Account : Falied\n"); + tet_result (TET_FAIL); + } + else { + tet_printf ("email Update Account : successful \n"); + tet_result (TET_PASS); + } + } + diff --git a/TC/TC_email_service/TC_Account/uts-email-update-account.h b/TC/TC_email_service/TC_Account/uts-email-update-account.h new file mode 100755 index 0000000..bcd1863 --- /dev/null +++ b/TC/TC_email_service/TC_Account/uts-email-update-account.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2012 - 2013 Samsung Electronics, Co., Ltd. + * All rights reserved. + * + * This software is a confidential and proprietary information of Samsung + * Electronics, Co., Ltd. ("Confidential Information"). 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. + */ + +#include <tet_api.h> + +#include <string.h> +#include <stdlib.h> +#include <sqlite3.h> +#include "email-api-init.h" +#include "email-api-account.h" + + + +static void startup(), cleanup(); +void (*tet_startup) () = startup; +void (*tet_cleanup) () = cleanup; + +static void uts_Email_Update_Account_01(void); +static void uts_Email_Update_Account_02(void); +static void uts_Email_Update_Account_03(void); + + + + +struct tet_testlist tet_testlist[] = { + { uts_Email_Update_Account_01, 1}, { uts_Email_Update_Account_02, 2}, { uts_Email_Update_Account_03, 3}, {NULL, 0} + + +}; diff --git a/TC/TC_email_service/TC_Account/uts-email-validate-account.c b/TC/TC_email_service/TC_Account/uts-email-validate-account.c new file mode 100755 index 0000000..6ad6686 --- /dev/null +++ b/TC/TC_email_service/TC_Account/uts-email-validate-account.c @@ -0,0 +1,155 @@ +/* +* Copyright (c) 2012 - 2013 Samsung Electronics, Inc. +* All rights reserved. +* +* This software is a confidential and proprietary information of Samsung +* Electronics, Inc. ("Confidential Information"). 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. +*/ + + +#include "uts-email-validate-account.h" + + +sqlite3 *sqlite_emmb; + + +static void startup() +{ + tet_printf("\n TC startup"); + if (EMAIL_ERROR_NONE == email_service_begin()) { + tet_infoline("Email service Begin\n"); + if (EMAIL_ERROR_NONE == email_open_db()) + tet_infoline("Email open DB success\n"); + else + tet_infoline("Email open DB failed\n"); + } + else { + tet_infoline("Email service not started\n"); + } +} + +static void cleanup() +{ + tet_printf("\n TC End"); + if (EMAIL_ERROR_NONE == email_close_db()) { + tet_infoline("Email Close DB Success\n"); + if (EMAIL_ERROR_NONE == email_service_end()) + tet_infoline("Email service close Success\n"); + else + tet_infoline("Email service end failed\n"); + } + else + tet_infoline("Email Close DB failed\n"); +} + + + + + + +/*Testcase : uts_Email_Validate_Account_01 + TestObjective : To validate an email account + APIs Tested : int email_validate_account(int account_id, unsigned *handle) + */ + +static void uts_Email_Validate_Account_01() +{ + int err_code = EMAIL_ERROR_NONE; + int handle; + email_account_t *account = NULL; + + tet_infoline("uts_Email_Validate_Account_01 : Begin\n"); + + account = (email_account_t *)malloc(sizeof(email_account_t)); + if (account) { + memset(account , 0x00, sizeof(email_account_t)); + + account->account_name = strdup("Gmail1 POP"); + account->user_display_name = strdup("samsung"); + account->user_email_address = strdup("samsungtest09@gmail.com"); + account->reply_to_address = strdup("samsungtest09@gmail.com"); + account->return_address = strdup("samsungtest09@gmail.com"); + account->incoming_server_type = EMAIL_SERVER_TYPE_POP3; + account->incoming_server_address= strdup("pop.gmail.com"); + account->incoming_server_port_number = 995; + account->incoming_server_secure_connection = 1; + account->retrieval_mode = EMAIL_IMAP4_RETRIEVAL_MODE_NEW; + account->incoming_server_user_name = strdup("samsungtest09"); + account->incoming_server_password = strdup("samsung09"); + account->outgoing_server_type = EMAIL_SERVER_TYPE_SMTP; + account->outgoing_server_address= strdup("smtp.gmail.com"); + account->outgoing_server_port_number = 465; + account->outgoing_server_secure_connection = 1; + account->outgoing_server_need_authentication = 1; + account->outgoing_server_user_name = strdup("samsungtest09"); + account->outgoing_server_password = strdup("samsung09"); + account->pop_before_smtp = 0; + account->incoming_server_requires_apop = 0; + account->auto_download_size = 0; /* downloading option, 0 is subject only, 1 is text body, 2 is normal */ + account->outgoing_server_use_same_authenticator = 1; /* Specifies the 'Same as POP3' option, 0 is none, 1 is 'Same as POP3 */ + account->logo_icon_path = NULL; + 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 = strdup("Gmail POP3 Signature"); + account->check_interval = 0; + + err_code = email_add_account(account); + if (EMAIL_ERROR_NONE == err_code) { + tet_printf("Email add account success : accountID[%d]\n", account->account_id); + err_code = email_validate_account(account->account_id, &handle); + if (EMAIL_ERROR_NONE == err_code) { + tet_printf("Email validate account success\n"); + tet_result(TET_PASS); + } + else { + tet_printf("Email validate account failed : error_code[%d]\n", err_code); + tet_result(TET_FAIL); + } + } + else { + + tet_printf("Email add account failed : err_code[%d]n", err_code); + tet_result(TET_UNRESOLVED); + } + email_free_account(&account, 1); + } + +} + +/*Testcase : uts_Email_Validate_Account_02 + TestObjective : To validate paramete for account_id in validate an email account + APIs Tested : int email_validate_account(int account_id, unsigned *handle) + */ + +static void uts_Email_Validate_Account_02() +{ + int err_code = EMAIL_ERROR_NONE; + int handle; + int account_id = -1; + + tet_infoline("uts_Email_Validate_Account_05 : Begin\n"); + + err_code = email_validate_account(account_id, &handle); + if (EMAIL_ERROR_NONE != err_code) { + tet_printf("Email validate account success\n"); + tet_result(TET_PASS); + } + else { + tet_printf("Email validate account failed : \n"); + tet_result(TET_FAIL); + } +} + + diff --git a/TC/TC_email_service/TC_Account/uts-email-validate-account.h b/TC/TC_email_service/TC_Account/uts-email-validate-account.h new file mode 100755 index 0000000..5189fdc --- /dev/null +++ b/TC/TC_email_service/TC_Account/uts-email-validate-account.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2012 - 2013 Samsung Electronics, Co., Ltd. + * All rights reserved. + * + * This software is a confidential and proprietary information of Samsung + * Electronics, Co., Ltd. ("Confidential Information"). 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. + */ + +#include <tet_api.h> + +#include <string.h> +#include <stdlib.h> +#include <sqlite3.h> +#include "email-api-init.h" +#include "email-api-account.h" + + + +static void startup(), cleanup(); +void (*tet_startup) () = startup; +void (*tet_cleanup) () = cleanup; + +static void uts_Email_Validate_Account_01(void); +static void uts_Email_Validate_Account_02(void); + + + + +struct tet_testlist tet_testlist[] = { + { uts_Email_Validate_Account_01, 1}, { uts_Email_Validate_Account_02, 2}, {NULL, 0} + + +}; diff --git a/TC/TC_email_service/TC_Folder/Makefile b/TC/TC_email_service/TC_Folder/Makefile new file mode 100755 index 0000000..a35443e --- /dev/null +++ b/TC/TC_email_service/TC_Folder/Makefile @@ -0,0 +1,51 @@ +################################################### +# add your TestCase List Here +# +# e.g., +# TC1 = utc_frameworkName_apiName_func +# TC2 = utc_ApplicationLib_recurGetDayOfWeek_func +TARGETS = uts-email-add-mailbox \ + uts-email-get-mailbox-list \ + uts-email-get-mailbox-by-mailboxtype \ + uts-email-delete-mailbox + +# uts-email-get-sync-mailbox-list (deprecated function) +################################################### +# add your Package Config Info Here +# +# e.g., +# PKGS=calendar +PKGS= email-service + +LIBS = `pkg-config --libs $(PKGS)` +LIBS += `pkg-config --libs glib-2.0` +LIBS +=$(TET_ROOT)/lib/tet3/tcm_s.o +LIBS +=-L$(TET_ROOT)/lib/tet3 -ltcm_s +LIBS +=-L$(TET_ROOT)/lib/tet3 -lapi_s + +INCS = -I. `pkg-config --cflags $(PKGS)` +INCS += -I. `pkg-config --cflags glib-2.0` +INCS += -I$(TET_ROOT)/inc/tet3 +INCS += -I$(TET_SUITE_ROOT)/TC_email_service/TC_Utility + +UTIL_SRC = $(TET_SUITE_ROOT)/TC_email_service/TC_Utility/uts-email-dummy-utility.c +UTIL_SRC += $(TET_SUITE_ROOT)/TC_email_service/TC_Utility/uts-email-real-utility.c + +CFLAGS = $(INCS) +CFLAGS += -D_TETWARE_MODE +LDFLAGS = $(LIBS) + +################################################### +# Modify here +# depending on the Test Case you want to build +# +# e.g., +# TCLIST = $(TC1) $(TC2) +all : $(TARGETS) + +$(TARGETS) : %: %.c + $(CC) -o $@ $< $(CFLAGS) $(LDFLAGS) + +clean : + rm -rf $(TARGETS) + diff --git a/TC/TC_email_service/TC_Folder/tslist b/TC/TC_email_service/TC_Folder/tslist new file mode 100755 index 0000000..f16ff20 --- /dev/null +++ b/TC/TC_email_service/TC_Folder/tslist @@ -0,0 +1,5 @@ +uts-email-add-mailbox +uts-email-get-mailbox-list +uts-email-get-mailbox-by-mailboxtype +uts-email-delete-mailbox + diff --git a/TC/TC_email_service/TC_Folder/uts-email-add-mailbox.c b/TC/TC_email_service/TC_Folder/uts-email-add-mailbox.c new file mode 100755 index 0000000..df9dd93 --- /dev/null +++ b/TC/TC_email_service/TC_Folder/uts-email-add-mailbox.c @@ -0,0 +1,161 @@ +/* +* Copyright (c) 2012 - 2013 Samsung Electronics, Inc. +* All rights reserved. +* +* This software is a confidential and proprietary information of Samsung +* Electronics, Inc. ("Confidential Information"). 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. +*/ + + +#include "uts-email-add-mailbox.h" +#include "../TC_Utility/uts-email-dummy-utility.c" + + +sqlite3 *sqlite_emmb; +int g_accountId; + +static void startup() +{ + int err_code = EMAIL_ERROR_NONE; + int count = 0; + int i = 0; + email_account_t *pAccount = NULL ; + + tet_printf("\n TC startup"); + + if (EMAIL_ERROR_NONE == email_service_begin()) { + tet_infoline("Email service Begin\n"); + if (EMAIL_ERROR_NONE == email_open_db()) { + tet_infoline("Email open DB success\n"); + err_code = email_get_account_list(&pAccount, &count); + if (!count) { + g_accountId = uts_Email_Add_Dummy_Account_01(); + } + else + g_accountId = pAccount[i].account_id; + email_free_account(&pAccount, count); + + } + else + tet_infoline("Email open DB failed\n"); + } + else + tet_infoline("Email service not started\n"); + +} + +static void cleanup() +{ + tet_printf("\n TC End"); + + if (EMAIL_ERROR_NONE == email_close_db()) { + tet_infoline("Email Close DB Success\n"); + if (EMAIL_ERROR_NONE == email_service_end()) + tet_infoline("Email service close Success\n"); + else + tet_infoline("Email service end failed\n"); + } + else + tet_infoline("Email Close DB failed\n"); +} + + + + + + +/*Testcase : uts_Email_Add_Mailbox_01 + TestObjective : To add a new mailbox to an account only localy + APIs Tested : int email_add_mailbox(email_mailbox_t *new_mailbox, int on_server, unsigned *handle) + */ + +static void uts_Email_Add_Mailbox_01() +{ + int err_code = EMAIL_ERROR_NONE ; + email_mailbox_t mbox; + int local_yn = 1; + int handle; + + tet_infoline("uts_Email_Add_Mailbox_01 Begin\n"); + + memset(&mbox , 0x00, sizeof(email_mailbox_t)); + mbox.mailbox_name = strdup("Test"); + mbox.alias = strdup("Test"); + mbox.local = local_yn; + mbox.mailbox_type = 7; + mbox.account_id = g_accountId; + err_code = email_add_mailbox(&mbox , 0, &handle); + if (EMAIL_ERROR_NONE == err_code) { + tet_infoline("Email add mailbox Success\n"); + tet_result(TET_PASS); + } + else { + tet_printf("Email add mailbox failed : error_code[%d]\n", err_code); + tet_result(TET_FAIL); + } +} + + +/*Testcase : uts_Email_Add_Mailbox_02 + TestObjective : To add a new mailbox to an account on server as well as in local also + APIs Tested : int email_add_mailbox(email_mailbox_t *new_mailbox, int on_server, unsigned *handle) + */ + +static void uts_Email_Add_Mailbox_02() +{ + int err_code = EMAIL_ERROR_NONE ; + email_mailbox_t mbox; + int local_yn = 0; + int handle; + + tet_infoline("uts_Email_Add_Mailbox_02 Begin\n"); + + memset(&mbox , 0x00, sizeof(email_mailbox_t)); + mbox.mailbox_name = strdup("Test"); + mbox.alias = strdup("Test"); + mbox.local = local_yn; + mbox.mailbox_type = 7; + + mbox.account_id = g_accountId; + err_code = email_add_mailbox(&mbox , 1, &handle); + if (EMAIL_ERROR_NONE == err_code) { + tet_infoline("Email add mailbox on server and in local : Success\n"); + tet_result(TET_PASS); + } + else { + tet_printf("Email add mailbox failed : error_code[%d]\n", err_code); + tet_result(TET_FAIL); + } +} + + +/*Testcase : uts_Email_Add_Mailbox_03 + TestObjective : To validate parameter for add a new mailbox + APIs Tested : int email_add_mailbox(email_mailbox_t *new_mailbox, int on_server, unsigned *handle) + */ + +static void uts_Email_Add_Mailbox_03() +{ + int err_code = EMAIL_ERROR_NONE ; + email_mailbox_t *mbox = NULL; + int local_yn = 0; + int handle; + int count = 0; + + tet_infoline("uts_Email_Add_Mailbox_03 Begin\n"); + + err_code = email_add_mailbox(mbox , 1, &handle); + if (EMAIL_ERROR_NONE != err_code) { + tet_infoline("Email add mailbox validate parameter : Success\n"); + tet_result(TET_PASS); + } + else { + tet_printf("Email add mailbox failed validate parameter\n"); + tet_result(TET_FAIL); + } + +} + + diff --git a/TC/TC_email_service/TC_Folder/uts-email-add-mailbox.h b/TC/TC_email_service/TC_Folder/uts-email-add-mailbox.h new file mode 100755 index 0000000..3d528bb --- /dev/null +++ b/TC/TC_email_service/TC_Folder/uts-email-add-mailbox.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2012 - 2013 Samsung Electronics, Co., Ltd. + * All rights reserved. + * + * This software is a confidential and proprietary information of Samsung + * Electronics, Co., Ltd. ("Confidential Information"). 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. + */ + +#include <tet_api.h> + +#include <string.h> +#include <stdlib.h> +#include <sqlite3.h> +#include "email-api-init.h" +#include "email-api-account.h" +#include "email-api-mailbox.h" + + +static void startup(), cleanup(); +void (*tet_startup) () = startup; +void (*tet_cleanup) () = cleanup; + +static void uts_Email_Add_Mailbox_01(void); +static void uts_Email_Add_Mailbox_02(void); +static void uts_Email_Add_Mailbox_03(void); + + + +struct tet_testlist tet_testlist[] = { {uts_Email_Add_Mailbox_01, 1}, {uts_Email_Add_Mailbox_02, 2}, {uts_Email_Add_Mailbox_03, 3}, {NULL, 0}}; diff --git a/TC/TC_email_service/TC_Folder/uts-email-delete-mailbox.c b/TC/TC_email_service/TC_Folder/uts-email-delete-mailbox.c new file mode 100755 index 0000000..93e61da --- /dev/null +++ b/TC/TC_email_service/TC_Folder/uts-email-delete-mailbox.c @@ -0,0 +1,138 @@ +/* +* Copyright (c) 2012 - 2013 Samsung Electronics, Inc. +* All rights reserved. +* +* This software is a confidential and proprietary information of Samsung +* Electronics, Inc. ("Confidential Information"). 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. +*/ + + +#include "email-api-account.h" +#include "uts-email-delete-mailbox.h" +#include "../TC_Utility/uts-email-dummy-utility.c" + + +sqlite3 *sqlite_emmb; +static int g_accountId; + + +static void startup() +{ + int err_code = EMAIL_ERROR_NONE; + int count = 0; + int i = 0; + email_account_t *pAccount = NULL ; + + tet_printf("\n TC startup"); + + if (EMAIL_ERROR_NONE == email_service_begin()) { + tet_infoline("Email service Begin\n"); + if (EMAIL_ERROR_NONE == email_open_db()) { + tet_infoline("Email open DB success\n"); + err_code = email_get_account_list(&pAccount, &count); + if (!count) { + g_accountId = uts_Email_Add_Dummy_Account_01(); + } + else + g_accountId = pAccount[i].account_id; + email_free_account(&pAccount, count); + + } + else + tet_infoline("Email open DB failed\n"); + } + else + tet_infoline("Email service not started\n"); + +} + +static void cleanup() +{ + tet_printf("\n TC End"); + int err_code = EMAIL_ERROR_NONE; + + if (EMAIL_ERROR_NONE == email_close_db()) { + tet_infoline("Email Close DB Success\n"); + if (EMAIL_ERROR_NONE == email_service_end()) + tet_infoline("Email service close Success\n"); + else + tet_infoline("Email service end failed\n"); + } + else + tet_infoline("Email Close DB failed\n"); +} + + + + + + +/*Testcase : uts_Email_Delete_Mailbox_01 + TestObjective : To delete mailbox + APIs Tested : int email_delete_mailbox(int input_mailbox_id, int input_on_server, unsigned* output_handle) + */ + +static void uts_Email_Delete_Mailbox_01() +{ + int err_code = EMAIL_ERROR_NONE ; + email_mailbox_t *pMailbox = NULL; + int count = 0; + int i = 0; + int handle; + int on_server ; + + tet_infoline("uts_Email_Delete_Mailbox_01 : Begin\n"); + + err_code = email_get_mailbox_list(g_accountId , 1, &pMailbox, &count); + if (EMAIL_ERROR_NONE == err_code) { + tet_infoline("Email get mailbox list : Success\n"); + if (count > 0) { + i = 0; + on_server = pMailbox[i].local; + err_code = email_delete_mailbox(pMailbox[i].mailbox_id, on_server, &handle); + if (EMAIL_ERROR_NONE == err_code) { + tet_infoline("email delete mailbox : Success\n"); + tet_result(TET_PASS); + email_delete_account(g_accountId); + } + else { + tet_printf("Email delete mailbox failed : error_code[%d]\n", err_code); + tet_result(TET_FAIL); + } + } + } + else { + tet_printf("Email get mailbox list failed : error_code[%d]\n", err_code); + tet_result(TET_UNRESOLVED); + } + +} + + +/*Testcase : uts_Email_Delete_Mailbox_02 + TestObjective : To validate parameter for mailbox in delete mailbox + APIs Tested : int email_delete_mailbox(int input_mailbox_id, int input_on_server, unsigned* output_handle) + */ + +static void uts_Email_Delete_Mailbox_02() +{ + int err_code = EMAIL_ERROR_NONE ; + int handle; + int on_server = 0 ; + + tet_infoline("uts_Email_Delete_Mailbox_02 : Begin\n"); + + err_code = email_delete_mailbox(0, on_server, &handle); + if (EMAIL_ERROR_NONE != err_code) { + tet_infoline("email delete mailbox : Success\n"); + tet_result(TET_PASS); + } + else { + tet_printf("Email delete mailbox failed\n"); + tet_result(TET_FAIL); + } + +} + diff --git a/TC/TC_email_service/TC_Folder/uts-email-delete-mailbox.h b/TC/TC_email_service/TC_Folder/uts-email-delete-mailbox.h new file mode 100755 index 0000000..54513b6 --- /dev/null +++ b/TC/TC_email_service/TC_Folder/uts-email-delete-mailbox.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2012 - 2013 Samsung Electronics, Co., Ltd. + * All rights reserved. + * + * This software is a confidential and proprietary information of Samsung + * Electronics, Co., Ltd. ("Confidential Information"). 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. + */ + +#include <tet_api.h> + +#include <string.h> +#include <stdlib.h> +#include <sqlite3.h> +#include "email-api-init.h" +#include "email-api-account.h" +#include "email-api-mailbox.h" + + +static void startup(), cleanup(); +void (*tet_startup) () = startup; +void (*tet_cleanup) () = cleanup; + +static void uts_Email_Delete_Mailbox_01(void); +static void uts_Email_Delete_Mailbox_02(void); + + + +struct tet_testlist tet_testlist[] = { {uts_Email_Delete_Mailbox_01, 1}, {uts_Email_Delete_Mailbox_02, 2}, {NULL, 0} +}; diff --git a/TC/TC_email_service/TC_Folder/uts-email-get-mailbox-by-mailboxtype.c b/TC/TC_email_service/TC_Folder/uts-email-get-mailbox-by-mailboxtype.c new file mode 100755 index 0000000..1cf7795 --- /dev/null +++ b/TC/TC_email_service/TC_Folder/uts-email-get-mailbox-by-mailboxtype.c @@ -0,0 +1,148 @@ +/* +* Copyright (c) 2012 - 2013 Samsung Electronics, Inc. +* All rights reserved. +* +* This software is a confidential and proprietary information of Samsung +* Electronics, Inc. ("Confidential Information"). 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. +*/ + + +#include "uts-email-get-mailbox-by-mailboxtype.h" +#include "../TC_Utility/uts-email-dummy-utility.c" + + +sqlite3 *sqlite_emmb; +static int g_accountId; + + +static void startup() +{ + int err_code = EMAIL_ERROR_NONE; + int count = 0; + int i = 0; + email_account_t *pAccount = NULL ; + + tet_printf("\n TC startup"); + + if (EMAIL_ERROR_NONE == email_service_begin()) { + tet_infoline("Email service Begin\n"); + if (EMAIL_ERROR_NONE == email_open_db()) { + tet_infoline("Email open DB success\n"); + err_code = email_get_account_list(&pAccount, &count); + if (!count) { + g_accountId = uts_Email_Add_Dummy_Account_01(); + } + else + g_accountId = pAccount[i].account_id; + tet_printf("g_accountId [%d], count[%d]\n", g_accountId, count); + email_free_account(&pAccount, count); + + } + + else + tet_infoline("Email open DB failed\n"); + } + else + tet_infoline("Email service not started\n"); + +} + +static void cleanup() +{ + tet_printf("\n TC End"); + + if (EMAIL_ERROR_NONE == email_close_db()) { + tet_infoline("Email Close DB Success\n"); + if (EMAIL_ERROR_NONE == email_service_end()) + tet_infoline("Email service close Success\n"); + else + tet_infoline("Email service end failed\n"); + } + else + tet_infoline("Email Close DB failed\n"); +} + + + + + + +/*Testcase : uts_Email_Get_Mailbox_By_Mailboxtype_01 + TestObjective : To get mailbox by mailbox type + APIs Tested : int email_get_mailbox_by_mailbox_type(int account_id, email_mailbox_type_e mailbox_type, email_mailbox_t **mailbox) + */ + +static void uts_Email_Get_Mailbox_By_Mailboxtype_01() +{ + int err_code = EMAIL_ERROR_NONE ; + email_mailbox_t *pMailbox = NULL; + int mailbox_type = EMAIL_MAILBOX_TYPE_INBOX; + + tet_infoline("uts_Email_Get_Mailbox_By_Mailboxtype_01 : Begin\n"); + + err_code = email_get_mailbox_by_mailbox_type(g_accountId , mailbox_type, &pMailbox); + if (EMAIL_ERROR_NONE == err_code) { + tet_infoline("Email get mailbox by mailbox type : Success\n"); + tet_result(TET_PASS); + } + else { + tet_printf("Email get mailbox by mailbox type failed : error_code[%d]\n", err_code); + tet_result(TET_FAIL); + } + +} + + +/*Testcase : uts_Email_Get_Mailbox_By_Mailboxtype_02 + TestObjective : To validate parameter for account_id in get mailbox by mailbox_type + APIs Tested : int email_get_mailbox_by_mailbox_type(int account_id, email_mailbox_type_e mailbox_type, email_mailbox_t **mailbox) + */ + +static void uts_Email_Get_Mailbox_By_Mailboxtype_02() +{ + int err_code = EMAIL_ERROR_NONE ; + email_mailbox_t *pMailbox = NULL; + int account_id = -1; + int mailbox_type = EMAIL_MAILBOX_TYPE_USER_DEFINED; + + tet_infoline("uts_Email_Get_Mailbox_By_Mailboxtype_02 : Begin\n"); + + err_code = email_get_mailbox_by_mailbox_type(account_id , mailbox_type, &pMailbox); + if (EMAIL_ERROR_NONE != err_code) { + tet_infoline("Email get mailbox by mailbox type : Success\n"); + tet_result(TET_PASS); + } + else { + tet_printf("Email get mailbox by mailbox type failed : \n"); + tet_result(TET_FAIL); + } + +} + + +/*Testcase : uts_Email_Get_Mailbox_By_Mailboxtype_03 + TestObjective : To validate parameter for mailbox in get mailbox by mailbox_type + APIs Tested : int email_get_mailbox_by_mailbox_type(int account_id, email_mailbox_type_e mailbox_type, email_mailbox_t **mailbox) + */ + +static void uts_Email_Get_Mailbox_By_Mailboxtype_03() +{ + int err_code = EMAIL_ERROR_NONE ; + int mailbox_type = EMAIL_MAILBOX_TYPE_USER_DEFINED; + + tet_infoline("uts_Email_Get_Mailbox_By_Mailboxtype_03 : Begin\n"); + + err_code = email_get_mailbox_by_mailbox_type(g_accountId , mailbox_type, NULL); + if (EMAIL_ERROR_NONE != err_code) { + tet_infoline("Email get mailbox by mailbox type : Success\n"); + tet_result(TET_PASS); + } + else { + tet_printf("Email get mailbox by mailbox type failed : \n"); + tet_result(TET_FAIL); + } +} + + diff --git a/TC/TC_email_service/TC_Folder/uts-email-get-mailbox-by-mailboxtype.h b/TC/TC_email_service/TC_Folder/uts-email-get-mailbox-by-mailboxtype.h new file mode 100755 index 0000000..55deffa --- /dev/null +++ b/TC/TC_email_service/TC_Folder/uts-email-get-mailbox-by-mailboxtype.h @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2012 - 2013 Samsung Electronics, Co., Ltd. + * All rights reserved. + * + * This software is a confidential and proprietary information of Samsung + * Electronics, Co., Ltd. ("Confidential Information"). 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. + */ + +#include <tet_api.h> + +#include <string.h> +#include <stdlib.h> +#include <sqlite3.h> +#include "email-api-init.h" +#include "email-api-account.h" +#include "email-api-mailbox.h" + + +static void startup(), cleanup(); +void (*tet_startup) () = startup; +void (*tet_cleanup) () = cleanup; + +static void uts_Email_Get_Mailbox_By_Mailboxtype_01(void); +static void uts_Email_Get_Mailbox_By_Mailboxtype_02(void); +static void uts_Email_Get_Mailbox_By_Mailboxtype_03(void); + + + +struct tet_testlist tet_testlist[] = { {uts_Email_Get_Mailbox_By_Mailboxtype_01, 1}, {uts_Email_Get_Mailbox_By_Mailboxtype_02, 2}, {uts_Email_Get_Mailbox_By_Mailboxtype_03, 3}, {NULL, 0} +}; diff --git a/TC/TC_email_service/TC_Folder/uts-email-get-mailbox-list.c b/TC/TC_email_service/TC_Folder/uts-email-get-mailbox-list.c new file mode 100755 index 0000000..b4b2754 --- /dev/null +++ b/TC/TC_email_service/TC_Folder/uts-email-get-mailbox-list.c @@ -0,0 +1,200 @@ +/* +* Copyright (c) 2012 - 2013 Samsung Electronics, Inc. +* All rights reserved. +* +* This software is a confidential and proprietary information of Samsung +* Electronics, Inc. ("Confidential Information"). 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. +*/ + + +#include "uts-email-get-mailbox-list.h" +#include "../TC_Utility/uts-email-dummy-utility.c" + + +sqlite3 *sqlite_emmb; +int g_accountId; + +static void startup() +{ + int err_code = EMAIL_ERROR_NONE; + int count = 0; + int i = 0; + email_account_t *pAccount = NULL ; + + tet_printf("\n TC startup"); + + if (EMAIL_ERROR_NONE == email_service_begin()) { + tet_infoline("Email service Begin\n"); + if (EMAIL_ERROR_NONE == email_open_db()) { + tet_infoline("Email open DB success\n"); + err_code = email_get_account_list(&pAccount, &count); + if (!count) { + g_accountId = uts_Email_Add_Dummy_Account_01(); + } + else + g_accountId = pAccount[i].account_id; + email_free_account(&pAccount, count); + + } + else + tet_infoline("Email open DB failed\n"); + } + else + tet_infoline("Email service not started\n"); + +} + +static void cleanup() +{ + tet_printf("\n TC End"); + + if (EMAIL_ERROR_NONE == email_close_db()) { + tet_infoline("Email Close DB Success\n"); + if (EMAIL_ERROR_NONE == email_service_end()) + tet_infoline("Email service close Success\n"); + else + tet_infoline("Email service end failed\n"); + } + else + tet_infoline("Email Close DB failed\n"); +} + + + + + + + + +/*Testcase : uts_Email_Get_Mailbox_List_01 + TestObjective : To get all local folderlist + APIs Tested : int email_get_mailbox_list(int account_id, int local_yn, email_mailbox_t **mailbox_list, int *count) + */ + +static void uts_Email_Get_Mailbox_List_01() +{ + int err_code = EMAIL_ERROR_NONE ; + email_mailbox_t *pMailbox_list = NULL; + int count = 0; + int local_yn = 0; + + tet_infoline("uts_Email_Get_Mailbox_List_01 Begin\n"); + + err_code = email_get_mailbox_list(g_accountId, local_yn, &pMailbox_list, &count); + if (EMAIL_ERROR_NONE == err_code) { + tet_infoline("Email get all local mailboxes : Success\n"); + tet_result(TET_PASS); + } + else { + tet_printf("Email get all local mailboxes failed : error_code[%d]\n", err_code); + tet_result(TET_FAIL); + } + +} + + +/*Testcase : uts_Email_Get_Mailbox_List_02 + TestObjective : To get all server mailbox list as well as local folderlist + APIs Tested : int email_get_mailbox_list(int account_id, int local_yn, email_mailbox_t **mailbox_list, int *count) + */ + +static void uts_Email_Get_Mailbox_List_02() +{ + int err_code = EMAIL_ERROR_NONE ; + email_mailbox_t *pMailbox_list = NULL; + int local_yn = 1; + int count = 0; + + tet_infoline("uts_Email_Get_Mailbox_List_02 Begin\n"); + + err_code = email_get_mailbox_list(g_accountId , local_yn, &pMailbox_list, &count); + if (EMAIL_ERROR_NONE == err_code) { + tet_infoline("Email get all server & local mailboxes : Success\n"); + tet_result(TET_PASS); + } + else { + tet_printf("Email get all server & local mailboxes failed : error_code[%d]\n", err_code); + tet_result(TET_FAIL); + } +} + + +/*Testcase : uts_Email_Get_Mailbox_List_03 + TestObjective : To validate parameter for account_id in get all mailbox list + APIs Tested : int email_get_mailbox_list(int account_id, int local_yn, email_mailbox_t **mailbox_list, int *count) + */ + +static void uts_Email_Get_Mailbox_List_03() +{ + int err_code = EMAIL_ERROR_NONE ; + email_mailbox_t *pMailbox_list = NULL; + int local_yn = 1; + int count = 0; + int account_id = -1; + + tet_infoline("uts_Email_Get_Mailbox_List_03 Begin\n"); + + err_code = email_get_mailbox_list(account_id , local_yn, &pMailbox_list, &count); + if (EMAIL_ERROR_NONE != err_code) { + tet_infoline("Email get all mailboxes validate parameter : Success\n"); + tet_result(TET_PASS); + } + else { + tet_printf("Email get all mailboxes validate parameter failed : \n"); + tet_result(TET_FAIL); + } +} + + +/*Testcase : uts_Email_Get_Mailbox_List_04 + TestObjective : To validate parameter for mailbox_list in get all mailbox list + APIs Tested : int email_get_mailbox_list(int account_id, int local_yn, email_mailbox_t **mailbox_list, int *count) + */ + +static void uts_Email_Get_Mailbox_List_04() +{ + int err_code = EMAIL_ERROR_NONE ; + int local_yn = 1; + int count = 0; + int account_id = 1; + + tet_infoline("uts_Email_Get_Mailbox_List_04 Begin\n"); + + err_code = email_get_mailbox_list(account_id , local_yn, NULL, &count); + if (EMAIL_ERROR_NONE != err_code) { + tet_infoline("Email get all mailboxes validate parameter : Success\n"); + tet_result(TET_PASS); + } + else { + tet_printf("Email get all mailboxes validate parameter failed : \n"); + tet_result(TET_FAIL); + } +} + + +/*Testcase : uts_Email_Get_Mailbox_List_05 + TestObjective : To validate parameter for count in get all mailbox list + APIs Tested : int email_get_mailbox_list(int account_id, int local_yn, email_mailbox_t **mailbox_list, int *count) + */ + +static void uts_Email_Get_Mailbox_List_05() +{ + int err_code = EMAIL_ERROR_NONE ; + email_mailbox_t *pMailbox_list = NULL; + int local_yn = 1; + int account_id = 1; + + tet_infoline("uts_Email_Get_Mailbox_List_05 Begin\n"); + + err_code = email_get_mailbox_list(account_id , local_yn, &pMailbox_list, 0); + if (EMAIL_ERROR_NONE != err_code) { + tet_infoline("Email get all mailboxes validate parameter : Success\n"); + tet_result(TET_PASS); + } + else { + tet_printf("Email get all mailboxes validate parameter failed : \n"); + tet_result(TET_FAIL); + } +} diff --git a/TC/TC_email_service/TC_Folder/uts-email-get-mailbox-list.h b/TC/TC_email_service/TC_Folder/uts-email-get-mailbox-list.h new file mode 100755 index 0000000..0c45d7f --- /dev/null +++ b/TC/TC_email_service/TC_Folder/uts-email-get-mailbox-list.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2012 - 2013 Samsung Electronics, Co., Ltd. + * All rights reserved. + * + * This software is a confidential and proprietary information of Samsung + * Electronics, Co., Ltd. ("Confidential Information"). 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. + */ + +#include <tet_api.h> + +#include <string.h> +#include <stdlib.h> +#include <sqlite3.h> +#include "email-api-init.h" +#include "email-api-account.h" +#include "email-api-mailbox.h" + + +static void startup(), cleanup(); +void (*tet_startup) () = startup; +void (*tet_cleanup) () = cleanup; + +static void uts_Email_Get_Mailbox_List_01(void); +static void uts_Email_Get_Mailbox_List_02(void); +static void uts_Email_Get_Mailbox_List_03(void); +static void uts_Email_Get_Mailbox_List_04(void); +static void uts_Email_Get_Mailbox_List_05(void); + + + +struct tet_testlist tet_testlist[] = { {uts_Email_Get_Mailbox_List_01, 1}, {uts_Email_Get_Mailbox_List_02, 2}, {uts_Email_Get_Mailbox_List_03, 3}, {uts_Email_Get_Mailbox_List_04, 4}, {uts_Email_Get_Mailbox_List_05, 5}, {NULL, 0} +}; diff --git a/TC/TC_email_service/TC_Init/Makefile b/TC/TC_email_service/TC_Init/Makefile new file mode 100755 index 0000000..bd39e8a --- /dev/null +++ b/TC/TC_email_service/TC_Init/Makefile @@ -0,0 +1,52 @@ +################################################### +# add your TestCase List Here +# +# e.g., +# TC1 = utc_frameworkName_apiName_func +# TC2 = utc_ApplicationLib_recurGetDayOfWeek_func +TARGETS = uts-email-service-begin \ + uts-email-open-db \ + uts-email-init-storage \ + uts-email-ping-service \ + uts-email-service-end \ + uts-email-close-db + +################################################### +# add your Package Config Info Here +# +# e.g., +# PKGS=calendar +PKGS= email-service + +LIBS = `pkg-config --libs $(PKGS)` +LIBS += `pkg-config --libs glib-2.0` +LIBS +=$(TET_ROOT)/lib/tet3/tcm_s.o +LIBS +=-L$(TET_ROOT)/lib/tet3 -ltcm_s +LIBS +=-L$(TET_ROOT)/lib/tet3 -lapi_s + +INCS = -I. `pkg-config --cflags $(PKGS)` +INCS += -I. `pkg-config --cflags glib-2.0` +INCS += -I$(TET_ROOT)/inc/tet3 +INCS += -I$(TET_SUITE_ROOT)/TC_email_service/TC_Utility + +UTIL_SRC = $(TET_SUITE_ROOT)/TC_email_service/TC_Utility/uts-email-dummy-utility.c +UTIL_SRC += $(TET_SUITE_ROOT)/TC_email_service/TC_Utility/uts-email-real-utility.c + +CFLAGS = $(INCS) +CFLAGS += -D_TETWARE_MODE +LDFLAGS = $(LIBS) + +################################################### +# Modify here +# depending on the Test Case you want to build +# +# e.g., +# TCLIST = $(TC1) $(TC2) +all : $(TARGETS) + +$(TARGETS) : %: %.c + $(CC) -o $@ $< $(CFLAGS) $(LDFLAGS) + +clean : + rm -rf $(TARGETS) + diff --git a/TC/TC_email_service/TC_Init/tslist b/TC/TC_email_service/TC_Init/tslist new file mode 100755 index 0000000..f6be9c5 --- /dev/null +++ b/TC/TC_email_service/TC_Init/tslist @@ -0,0 +1,6 @@ +uts-email-service-begin +uts-email-open-db +uts-email-init-storage +uts-email-ping-service +uts-email-close-db +uts-email-service-end diff --git a/TC/TC_email_service/TC_Init/uts-email-close-db.c b/TC/TC_email_service/TC_Init/uts-email-close-db.c new file mode 100755 index 0000000..a362ad4 --- /dev/null +++ b/TC/TC_email_service/TC_Init/uts-email-close-db.c @@ -0,0 +1,63 @@ +/* +* Copyright (c) 2012 - 2013 Samsung Electronics, Inc. +* All rights reserved. +* +* This software is a confidential and proprietary information of Samsung +* Electronics, Inc. ("Confidential Information"). 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. +*/ + + +#include "uts-email-close-db.h" + + +sqlite3 *sqlite_emmb; + + +static void startup() +{ + tet_printf("\n TC startup"); + if (EMAIL_ERROR_NONE == email_service_begin()) { + tet_infoline("Email service Begin\n"); + if (EMAIL_ERROR_NONE == email_open_db()) + tet_infoline("Email open DB success\n"); + else + tet_infoline("Email open DB failed\n"); + } + else { + tet_infoline("Email service not started\n"); + } +} + +static void cleanup() +{ + tet_printf("\n TC End"); + if (EMAIL_ERROR_NONE == email_service_end()) + tet_infoline("Email service close Success\n"); + else + tet_infoline("Email service end failed\n"); +} + + + + + +/*Testcase : uts_Email_Close_Db_01 + TestObjective : To close db + APIs Tested : int email_close_db() + */ + +static void uts_Email_Close_Db_01() +{ + if (EMAIL_ERROR_NONE == email_close_db()) { + tet_infoline("Email Close DB Success\n"); + tet_result(TET_PASS); + } + else { + tet_infoline("Email Close DB failed\n"); + tet_result(TET_FAIL); + } +} + + diff --git a/TC/TC_email_service/TC_Init/uts-email-close-db.h b/TC/TC_email_service/TC_Init/uts-email-close-db.h new file mode 100755 index 0000000..67e3139 --- /dev/null +++ b/TC/TC_email_service/TC_Init/uts-email-close-db.h @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2012 - 2013 Samsung Electronics, Co., Ltd. + * All rights reserved. + * + * This software is a confidential and proprietary information of Samsung + * Electronics, Co., Ltd. ("Confidential Information"). 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. + */ + +#include <tet_api.h> + +#include <string.h> +#include <stdlib.h> +#include <sqlite3.h> +#include "email-api-init.h" + + +static void startup(), cleanup(); +void (*tet_startup) () = startup; +void (*tet_cleanup) () = cleanup; + +static void uts_Email_Close_Db_01(void); + + + + +struct tet_testlist tet_testlist[] = { + { uts_Email_Close_Db_01, 1}, {NULL, 0} + + +}; diff --git a/TC/TC_email_service/TC_Init/uts-email-init-storage.c b/TC/TC_email_service/TC_Init/uts-email-init-storage.c new file mode 100755 index 0000000..ebe9a61 --- /dev/null +++ b/TC/TC_email_service/TC_Init/uts-email-init-storage.c @@ -0,0 +1,72 @@ +/* +* Copyright (c) 2012 - 2013 Samsung Electronics, Inc. +* All rights reserved. +* +* This software is a confidential and proprietary information of Samsung +* Electronics, Inc. ("Confidential Information"). 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. +*/ + + +#include "uts-email-init-storage.h" + + +sqlite3 *sqlite_emmb; + + +static void startup() +{ + tet_printf("\n TC startup"); + if (EMAIL_ERROR_NONE == email_service_begin()) { + tet_infoline("Email service Begin\n"); + if (EMAIL_ERROR_NONE == email_open_db()) + tet_infoline("Email open DB success\n"); + else + tet_infoline("Email open DB failed\n"); + } + else { + tet_infoline("Email service not started\n"); + } +} + +static void cleanup() +{ + tet_printf("\n TC End"); + if (EMAIL_ERROR_NONE == email_close_db()) { + tet_infoline("Email Close DB Success\n"); + if (EMAIL_ERROR_NONE == email_service_end()) + tet_infoline("Email service close Success\n"); + else + tet_infoline("Email service end failed\n"); + } + else + tet_infoline("Email Close DB failed\n"); +} + + + + + +/*Testcase : uts_Email_Init_Storage_01 + TestObjective : To initialize email storage + APIs Tested : int email_init_storage() + */ + +static void uts_Email_Init_Storage_01() +{ + int err_code = EMAIL_ERROR_NONE; + + tet_infoline("uts_Email_Init_Storage_01"); + err_code = email_init_storage(); + if (EMAIL_ERROR_NONE == err_code) { + tet_infoline("email init storage : Success\n"); + tet_result(TET_PASS); + } + else { + tet_printf("uts_Email_Init_Storage_01 failed : err_code[%d]\n", err_code); + tet_result(TET_FAIL); + } +} + + diff --git a/TC/TC_email_service/TC_Init/uts-email-init-storage.h b/TC/TC_email_service/TC_Init/uts-email-init-storage.h new file mode 100755 index 0000000..fe13ede --- /dev/null +++ b/TC/TC_email_service/TC_Init/uts-email-init-storage.h @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2012 - 2013 Samsung Electronics, Co., Ltd. + * All rights reserved. + * + * This software is a confidential and proprietary information of Samsung + * Electronics, Co., Ltd. ("Confidential Information"). 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. + */ + +#include <tet_api.h> + +#include <string.h> +#include <stdlib.h> +#include <sqlite3.h> +#include "email-api-init.h" + + + +static void startup(), cleanup(); +void (*tet_startup) () = startup; +void (*tet_cleanup) () = cleanup; + +static void uts_Email_Init_Storage_01(void); + + + + +struct tet_testlist tet_testlist[] = { + { uts_Email_Init_Storage_01, 1}, {NULL, 0} + + +}; diff --git a/TC/TC_email_service/TC_Init/uts-email-open-db.c b/TC/TC_email_service/TC_Init/uts-email-open-db.c new file mode 100755 index 0000000..19a9827 --- /dev/null +++ b/TC/TC_email_service/TC_Init/uts-email-open-db.c @@ -0,0 +1,64 @@ +/* +* Copyright (c) 2012 - 2013 Samsung Electronics, Inc. +* All rights reserved. +* +* This software is a confidential and proprietary information of Samsung +* Electronics, Inc. ("Confidential Information"). 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. +*/ + + +#include "uts-email-open-db.h" + + +sqlite3 *sqlite_emmb; +static int g_accountId; + + + +static void startup() +{ + tet_printf("\n TC startup"); + if (EMAIL_ERROR_NONE == email_service_begin()) { + tet_infoline("Email service Begin\n"); + } + else { + tet_infoline("Email service not started\n"); + } +} + +static void cleanup() +{ + tet_printf("\n TC End"); + if (EMAIL_ERROR_NONE == email_close_db()) { + tet_infoline("Email Close DB Success\n"); + if (EMAIL_ERROR_NONE == email_service_end()) + tet_infoline("Email service close Success\n"); + else + tet_infoline("Email service end failed\n"); + } + else + tet_infoline("Email Close DB failed\n"); +} + + + + + +/*Testcase : uts_Email_Open_Db_01 + TestObjective : To Open Db + APIs Tested : int email_open_db() + */ + +static void uts_Email_Open_Db_01() +{ + if (EMAIL_ERROR_NONE == email_open_db()) { + tet_infoline("Email open DB success\n"); + tet_result(TET_PASS); + } + else { + tet_infoline("Email open DB failed\n"); + tet_result(TET_FAIL); + } +} diff --git a/TC/TC_email_service/TC_Init/uts-email-open-db.h b/TC/TC_email_service/TC_Init/uts-email-open-db.h new file mode 100755 index 0000000..d5cfa6c --- /dev/null +++ b/TC/TC_email_service/TC_Init/uts-email-open-db.h @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2012 - 2013 Samsung Electronics, Co., Ltd. + * All rights reserved. + * + * This software is a confidential and proprietary information of Samsung + * Electronics, Co., Ltd. ("Confidential Information"). 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. + */ + +#include <tet_api.h> + +#include <string.h> +#include <stdlib.h> +#include <sqlite3.h> +#include "email-api-init.h" + + + +static void startup(), cleanup(); +void (*tet_startup) () = startup; +void (*tet_cleanup) () = cleanup; + +static void uts_Email_Open_Db_01(void); + + + + +struct tet_testlist tet_testlist[] = { + { uts_Email_Open_Db_01, 1}, {NULL, 0} + + +}; diff --git a/TC/TC_email_service/TC_Init/uts-email-ping-service.c b/TC/TC_email_service/TC_Init/uts-email-ping-service.c new file mode 100755 index 0000000..067766b --- /dev/null +++ b/TC/TC_email_service/TC_Init/uts-email-ping-service.c @@ -0,0 +1,68 @@ +/* +* Copyright (c) 2012 - 2013 Samsung Electronics, Inc. +* All rights reserved. +* +* This software is a confidential and proprietary information of Samsung +* Electronics, Inc. ("Confidential Information"). 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. +*/ + + +#include "uts-email-ping-service.h" + + +sqlite3 *sqlite_emmb; + + +static void startup() +{ + tet_printf("\n TC startup"); + if (EMAIL_ERROR_NONE == email_service_begin()) { + tet_infoline("Email service Begin\n"); + if (EMAIL_ERROR_NONE == email_open_db()) + tet_infoline("Email open DB success\n"); + else + tet_infoline("Email open DB failed\n"); + } + else { + tet_infoline("Email service not started\n"); + } +} + +static void cleanup() +{ + tet_printf("\n TC End"); + if (EMAIL_ERROR_NONE == email_close_db()) { + tet_infoline("Email Close DB Success\n"); + if (EMAIL_ERROR_NONE == email_service_end()) + tet_infoline("Email service close Success\n"); + else + tet_infoline("Email service end failed\n"); + } + else + tet_infoline("Email Close DB failed\n"); +} + + + + + +/*Testcase : uts_Email_Ping_Service_01 + TestObjective : To ping email service + APIs Tested : int email_ping_service() + */ + +static void uts_Email_Ping_Service_01() +{ + if (EMAIL_ERROR_NONE == email_ping_service()) { + tet_infoline("uts_Email_Ping_Service_01 : Success\n"); + tet_result(TET_PASS); + } + else { + tet_infoline("Email Ping Service Failed : \n"); + tet_result(TET_FAIL); + } +} + + diff --git a/TC/TC_email_service/TC_Init/uts-email-ping-service.h b/TC/TC_email_service/TC_Init/uts-email-ping-service.h new file mode 100755 index 0000000..d06de7d --- /dev/null +++ b/TC/TC_email_service/TC_Init/uts-email-ping-service.h @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2012 - 2013 Samsung Electronics, Co., Ltd. + * All rights reserved. + * + * This software is a confidential and proprietary information of Samsung + * Electronics, Co., Ltd. ("Confidential Information"). 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. + */ + +#include <tet_api.h> + +#include <string.h> +#include <stdlib.h> +#include <sqlite3.h> +#include "email-api-init.h" + + +static void startup(), cleanup(); +void (*tet_startup) () = startup; +void (*tet_cleanup) () = cleanup; + +static void uts_Email_Ping_Service_01(void); + + + + +struct tet_testlist tet_testlist[] = { + { uts_Email_Ping_Service_01, 1}, {NULL, 0} + + +}; diff --git a/TC/TC_email_service/TC_Init/uts-email-service-begin.c b/TC/TC_email_service/TC_Init/uts-email-service-begin.c new file mode 100755 index 0000000..471a438 --- /dev/null +++ b/TC/TC_email_service/TC_Init/uts-email-service-begin.c @@ -0,0 +1,63 @@ +/* +* Copyright (c) 2012 - 2013 Samsung Electronics, Inc. +* All rights reserved. +* +* This software is a confidential and proprietary information of Samsung +* Electronics, Inc. ("Confidential Information"). 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. +*/ + + +#include "uts-email-service-begin.h" + + +sqlite3 *sqlite_emmb; + + +static void startup() +{ + tet_printf("\n TC startup"); +} + +static void cleanup() +{ + tet_printf("\n TC End"); + if (EMAIL_ERROR_NONE == email_close_db()) { + tet_infoline("Email Close DB Success\n"); + if (EMAIL_ERROR_NONE == email_service_end()) + tet_infoline("Email service close Success\n"); + else + tet_infoline("Email service end failed\n"); + } + else + tet_infoline("Email Close DB failed\n"); +} + + + + + +/*Testcase : uts_Email_Service_Begin_01 + TestObjective : To start email service + APIs Tested : int email_service_begin() + */ + +static void uts_Email_Service_Begin_01() +{ + if (EMAIL_ERROR_NONE == email_service_begin()) { + tet_infoline("Email service Begin\n"); + tet_result(TET_PASS); + if (EMAIL_ERROR_NONE == email_open_db()) + tet_infoline("Email open DB success\n"); + else + tet_infoline("Email open DB failed\n"); + } + else { + tet_result(TET_FAIL); + tet_infoline("Email service not started\n"); + } + +} + + diff --git a/TC/TC_email_service/TC_Init/uts-email-service-begin.h b/TC/TC_email_service/TC_Init/uts-email-service-begin.h new file mode 100755 index 0000000..ff07069 --- /dev/null +++ b/TC/TC_email_service/TC_Init/uts-email-service-begin.h @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2012 - 2013 Samsung Electronics, Co., Ltd. + * All rights reserved. + * + * This software is a confidential and proprietary information of Samsung + * Electronics, Co., Ltd. ("Confidential Information"). 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. + */ + +#include <tet_api.h> + +#include <string.h> +#include <stdlib.h> +#include <sqlite3.h> +#include "email-api-init.h" + + + +static void startup(), cleanup(); +void (*tet_startup) () = startup; +void (*tet_cleanup) () = cleanup; + +static void uts_Email_Service_Begin_01(void); + + + + +struct tet_testlist tet_testlist[] = { + { uts_Email_Service_Begin_01, 1}, {NULL, 0} + + +}; diff --git a/TC/TC_email_service/TC_Init/uts-email-service-end.c b/TC/TC_email_service/TC_Init/uts-email-service-end.c new file mode 100755 index 0000000..c7a3a25 --- /dev/null +++ b/TC/TC_email_service/TC_Init/uts-email-service-end.c @@ -0,0 +1,66 @@ +/* +* Copyright (c) 2012 - 2013 Samsung Electronics, Inc. +* All rights reserved. +* +* This software is a confidential and proprietary information of Samsung +* Electronics, Inc. ("Confidential Information"). 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. +*/ + + +#include "uts-email-service-end.h" + + +sqlite3 *sqlite_emmb; + + +static void startup() +{ + tet_printf("\n TC startup"); + if (EMAIL_ERROR_NONE == email_service_begin()) { + tet_infoline("Email service Begin\n"); + if (EMAIL_ERROR_NONE == email_open_db()) + tet_infoline("Email open DB success\n"); + else + tet_infoline("Email open DB failed\n"); + } + else { + tet_infoline("Email service not started\n"); + } +} + +static void cleanup() +{ + tet_printf("\n TC End"); +} + + + + + +/*Testcase : uts_Email_Service_End_01 + TestObjective : To close email service + APIs Tested : int email_service_end() + */ + +static void uts_Email_Service_End_01() +{ + if (EMAIL_ERROR_NONE == email_close_db()) { + tet_infoline("Email Close DB Success\n"); + + if (EMAIL_ERROR_NONE == email_service_end()) { + tet_infoline("Email service close Success\n"); + tet_result(TET_PASS); + } + else { + tet_infoline("Email service end failed\n"); + tet_result(TET_FAIL); + } + } + else + tet_infoline("Email Close DB failed\n"); + +} + + diff --git a/TC/TC_email_service/TC_Init/uts-email-service-end.h b/TC/TC_email_service/TC_Init/uts-email-service-end.h new file mode 100755 index 0000000..aef969f --- /dev/null +++ b/TC/TC_email_service/TC_Init/uts-email-service-end.h @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2012 - 2013 Samsung Electronics, Co., Ltd. + * All rights reserved. + * + * This software is a confidential and proprietary information of Samsung + * Electronics, Co., Ltd. ("Confidential Information"). 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. + */ + +#include <tet_api.h> + +#include <string.h> +#include <stdlib.h> +#include <sqlite3.h> +#include "email-api-init.h" + + +static void startup(), cleanup(); +void (*tet_startup) () = startup; +void (*tet_cleanup) () = cleanup; + +static void uts_Email_Service_End_01(void); + + + + +struct tet_testlist tet_testlist[] = { + { uts_Email_Service_End_01, 1}, {NULL, 0} + + +}; diff --git a/TC/TC_email_service/TC_Message/Makefile b/TC/TC_email_service/TC_Message/Makefile new file mode 100644 index 0000000..cf19547 --- /dev/null +++ b/TC/TC_email_service/TC_Message/Makefile @@ -0,0 +1,89 @@ +################################################### +# add your TestCase List Here +# +# e.g., +# TC1 = utc_frameworkName_apiName_func +# TC2 = utc_ApplicationLib_recurGetDayOfWeek_func +TARGETS = uts-email-add-message \ + uts-email-add-attachment \ + uts-email-update-message \ + uts-email-count-message \ + uts-email-delete-message \ + uts-email-delete-attachment \ + uts-email-get-info \ + uts-email-free-mail-info \ + uts-email-get-disk-space-usage \ + uts-email-get-max-mail-count \ + uts-email-cancel-send-mail \ + uts-email-send-retry \ + uts-email-get-mail-list-ex \ + uts-email-get-attachment-info \ + uts-email-free-attachment-info \ + uts-email-move-mail-to-folder \ + uts-email-move-all-mails-to-folder \ + uts-email-get-mailbox-list \ + uts-email-delete-all-message-in-folder \ + uts-email-free-mailbox \ + uts-email-create-db-full \ + uts-email-clear-mail-data \ + +# uts-email-query-message \ + uts-email-add-query-message \ + uts-email-release-query-message \ + uts-email-get-list-by-emails \ + uts-email-get-mail-list-for-thread-view \ + uts-email-get-mail-list-of-thread \ + uts-email-get-mail-list-of-sender \ + uts-email-get-thread-information \ + uts-email-searched-mail-list \ + uts-email-get-searched-mail-list_by-count \ + uts-email-get-mail-list-by-count \ + uts-email-convert-mailbox-name-to-utf8 \ + uts-email-convert-text-utf8 \ + uts-email-convert-utf8-text \ + uts-email-get-mail-during-sync \ + uts-email-count-message-with-searching \ + uts-email-get-rfc-822 \ + uts-email-parse-rfc-822 \ + uts-email-free-envelope \ + uts-email-get-temp-file-size \ + uts-email-get-mail-list (deprecated function) +################################################### +# add your Package Config Info Here +# +# e.g., +# PKGS=calendar +PKGS= email-service + +LIBS = `pkg-config --libs $(PKGS)` +LIBS += `pkg-config --libs glib-2.0` +LIBS +=$(TET_ROOT)/lib/tet3/tcm_s.o +LIBS +=-L$(TET_ROOT)/lib/tet3 -ltcm_s +LIBS +=-L$(TET_ROOT)/lib/tet3 -lapi_s + +INCS = `pkg-config --cflags $(PKGS)` +INCS += `pkg-config --cflags glib-2.0` +INCS += -I$(TET_ROOT)/inc/tet3 +INCS += -I$(TET_SUITE_ROOT)/TC_Utility/include + +UTIL_SRC = $(TET_SUITE_ROOT)/TC_Utility/uts-email-dummy-utility.c +UTIL_SRC += $(TET_SUITE_ROOT)/TC_Utility/uts-email-real-utility.c + +CFLAGS = $(INCS) +CFLAGS += -D_TETWARE_MODE +LDFLAGS = $(LIBS) + +################################################### +# Modify here +# depending on the Test Case you want to build +# +# e.g., +# TCLIST = $(TC1) $(TC2) +all : $(TARGETS) + +$(TARGETS) : %: %.c + $(CC) -o $@ $< $(CFLAGS) $(LDFLAGS) + +clean : + rm -rf $(TARGETS) + diff --git a/TC/TC_email_service/TC_Message/tslist b/TC/TC_email_service/TC_Message/tslist new file mode 100755 index 0000000..b178c86 --- /dev/null +++ b/TC/TC_email_service/TC_Message/tslist @@ -0,0 +1,22 @@ +uts-email-add-message +uts-email-add-attachment +uts-email-get-info +uts-email-get-attachment-info +uts-email-get-mail-list-ex +uts-email-get-disk-space-usage +uts-email-get-max-mail-count +uts-email-get-mailbox-list +uts-email-update-message +uts-email-count-message +uts-email-cancel-send-mail +uts-email-send-retry +uts-email-move-mail-to-folder +uts-email-move-all-mails-to-folder +uts-email-free-mail-info +uts-email-free-attachment-info +uts-email-free-mailbox +uts-email-delete-attachment +uts-email-delete-message +uts-email-delete-all-message-in-folder +uts-email-create-db-full +uts-email-clear-mail-data diff --git a/TC/TC_email_service/TC_Message/uts-email-add-attachment.c b/TC/TC_email_service/TC_Message/uts-email-add-attachment.c new file mode 100755 index 0000000..951d451 --- /dev/null +++ b/TC/TC_email_service/TC_Message/uts-email-add-attachment.c @@ -0,0 +1,278 @@ +/* +* Copyright (c) 2012 - 2013 Samsung Electronics, Inc. +* All rights reserved. +* +* This software is a confidential and proprietary information of Samsung +* Electronics, Inc. ("Confidential Information"). 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. +*/ + + +#include "uts-email-add-attachment.h" +#include "../TC_Utility/uts-email-dummy-utility.c" + + +sqlite3 *sqlite_emmb; +static int g_accountId; + + + +static void startup() +{ + int err_code = EMAIL_ERROR_NONE; + int count = 0; + int i = 0; + email_account_t *pAccount = NULL ; + email_mailbox_t mbox; + email_mail_list_item_t *mail_list = NULL; + + tet_printf("\n TC startup"); + if (EMAIL_ERROR_NONE == email_service_begin()) + { + tet_infoline("Email service Begin\n"); + if (EMAIL_ERROR_NONE == email_open_db()) + { + tet_infoline("Email open DB success\n"); + + g_accountId = 0; + /* Check if there are any accounts and Get account id. If there is no account in the db, add new dummy account data to the d */ + err_code = email_get_account_list(&pAccount, &count); + if (EMAIL_ERROR_NONE == err_code) { + /* get the account id from the d */ + g_accountId = pAccount[i].account_id; + email_free_account(&pAccount, count); + tet_printf("g_accountId[%d]\n", g_accountId); + } else if (EMAIL_ERROR_ACCOUNT_NOT_FOUND == err_code) { + /* Add new dummy account to the db if there is no account in the d */ + tet_printf("Add new account\n"); + g_accountId = uts_Email_Add_Dummy_Account_01(); + tet_printf("g_accountId[%d]\n", g_accountId); + } else { + tet_printf("email_get_account_list() failed : err_code[%d]\n", err_code); + } + + /* Check if there are any mails and Get mail id of one of them. If there is no mail in the db, add new dummy mail data to the d */ + count = 0; + err_code = uts_Email_Get_Mail_List_03(ALL_ACCOUNT, 0, &mail_list, &count, 0); + if (EMAIL_ERROR_NONE == err_code) { + tet_printf("email_get_mail_list() success\n"); + } else if (EMAIL_ERROR_MAIL_NOT_FOUND == err_code) { + tet_printf("Add new email\n"); + err_code = uts_Email_Add_Dummy_Message_02(); + if (EMAIL_ERROR_NONE == err_code) { /* Make db contain at least one mai */ + tet_printf("uts_Email_Add_Dummy_Message_02() success.\n"); + count = 0; + err_code = uts_Email_Get_Mail_List_03(ALL_ACCOUNT, 0, &mail_list, &count, 0); + } else { + tet_printf("uts_Email_Add_Dummy_Message_02() failed : err_code[%d]\n", err_code); + } + } else { + tet_printf("Email Get Mail List Failed : err_code[%d]", err_code); + } + } else + tet_infoline("Email open DB failed\n"); + } else { + tet_infoline("Email service not started\n"); + } +} + + +static void cleanup() +{ + tet_printf("\n TC End"); + + if (EMAIL_ERROR_NONE == email_close_db()) { + tet_infoline("Email Close DB Success\n"); + if (EMAIL_ERROR_NONE == email_service_end()) + tet_infoline("Email service close Success\n"); + else + tet_infoline("Email service end failed\n"); + } + else + tet_infoline("Email Close DB failed\n"); +} + + + + + + + +/*Testcase : uts_Email_Add_Attachment_01 + TestObjective : To add attachment to mail + APIs Tested : int email_add_attachment(int mail_id, email_attachment_data_t* attachment) + */ + +static void uts_Email_Add_Attachment_01() +{ + int err_code = EMAIL_ERROR_NONE; + int count = 0; + int i = 0; + email_attachment_data_t attachment; + email_mail_list_item_t *mail_list = NULL; + email_account_t *account = NULL ; + FILE *fp = NULL; + + + tet_infoline("uts_Email_Add_Attachment_01 Begin\n"); + + err_code = email_get_account_list(&account, &count); + if (EMAIL_ERROR_NONE == err_code) + { + tet_infoline("Email get account list success\n"); + if (count > 0) + { + g_accountId = account[i].account_id; + err_code = uts_Email_Get_Mail_List_03(g_accountId, EMAIL_MAILBOX_TYPE_INBOX, &mail_list, &count, 0); + if (EMAIL_ERROR_NONE == err_code) { + tet_infoline("Email get mail list : success\n"); + if (count > 0) { + memset(&attachment, 0x00, sizeof(email_attachment_data_t)); + attachment.attachment_name = strdup("Test attachment"); + attachment.attachment_path = strdup("/tmp/mail.txt"); + fp = fopen("/tmp/mail.txt", "w"); + fprintf(fp, "xxxxxxxxx"); + fclose(fp); + i = 0; + err_code = email_add_attachment(mail_list[i].mail_id , &attachment); + if (EMAIL_ERROR_NONE == err_code) { + tet_infoline("Email add attachment : success\n"); + tet_result(TET_PASS); + } + else { + tet_printf("Email add attachment : Failed err_code[%d]", err_code); + tet_result(TET_FAIL); + } + } + else { + tet_infoline("No Mails in mailbox\n"); + tet_result(TET_UNRESOLVED); + } + } + else { + tet_printf("Email get mail list : Failed err_code[%d]", err_code); + tet_result(TET_UNRESOLVED); + } + } + else { + tet_infoline("NO email account found : success\n"); + tet_result(TET_UNRESOLVED); + } + } + else { + tet_printf("Email get account list failed : error_code[%d]\n", err_code); + tet_result(TET_UNRESOLVED); + } + +} + + +/*Testcase : uts_Email_Add_Attchment_02 + TestObjective : To validate parameter for mailbox in add attachment to mail + APIs Tested : int email_add_attachment(int mail_id, email_attachment_data_t* attachment) + */ + +static void uts_Email_Add_Attachment_02() +{ + int err_code = EMAIL_ERROR_NONE; + email_attachment_data_t attachment; + + tet_infoline("uts_Email_Add_attachment_02 Begin\n"); + + memset(&attachment, 0x00, sizeof(email_attachment_data_t)); + attachment.attachment_name = strdup("Test"); + + err_code = email_add_attachment(1 , &attachment); + if (EMAIL_ERROR_NONE != err_code) { + tet_infoline("Email add attachment : success\n"); + tet_result(TET_PASS); + } + else { + tet_printf("Email add attachment : Failed\n"); + tet_result(TET_FAIL); + } +} + + +/*Testcase : uts_Email_Add_Attchment_03 + TestObjective : To validate parameter for mailbox account_id in add attachment to mail + APIs Tested : int email_add_attachment(int mail_id, email_attachment_data_t* attachment) + */ + +static void uts_Email_Add_Attachment_03() +{ + int err_code = EMAIL_ERROR_NONE; + int mail_id = 1; + email_attachment_data_t attachment; + + tet_infoline("uts_Email_Add_attachment_02 Begin\n"); + + memset(&attachment, 0x00, sizeof(email_attachment_data_t)); + attachment.attachment_name = strdup("Test"); + + err_code = email_add_attachment(mail_id , &attachment); + if (EMAIL_ERROR_NONE != err_code) { + tet_infoline("Email add attachment : success\n"); + tet_result(TET_PASS); + } + else { + tet_printf("Email add attachment : Failed\n"); + tet_result(TET_FAIL); + } +} + + +/*Testcase : uts_Email_Add_Attchment_04 + TestObjective : To validate parameter for mail_id in add attachment to mail + APIs Tested : int email_add_attachment(int mail_id, email_attachment_data_t* attachment) + */ + +static void uts_Email_Add_Attachment_04() +{ + int err_code = EMAIL_ERROR_NONE; + int i = 0; + email_attachment_data_t attachment; + + tet_infoline("uts_Email_Add_attachment_04 Begin\n"); + + + memset(&attachment, 0x00, sizeof(email_attachment_data_t)); + attachment.attachment_name = strdup("Test"); + + err_code = email_add_attachment( 0 , &attachment); + if (EMAIL_ERROR_NONE != err_code) { + tet_infoline("Email add attachment : success\n"); + tet_result(TET_PASS); + } + else { + tet_printf("Email add attachment : Failed\n"); + tet_result(TET_FAIL); + } +} + + +/*Testcase : uts_Email_Add_Attchment_05 + TestObjective : To validate parameter for mailbox in add attachment to mail + APIs Tested : int email_add_attachment(int mail_id, email_attachment_data_t* attachment) + */ + +static void uts_Email_Add_Attachment_05() +{ + int err_code = EMAIL_ERROR_NONE; + int i = 0; + + tet_infoline("uts_Email_Add_attachment_05 Begin\n"); + + err_code = email_add_attachment( 1 , NULL); + if (EMAIL_ERROR_NONE != err_code) { + tet_infoline("Email add attachment : success\n"); + tet_result(TET_PASS); + } + else { + tet_printf("Email add attachment : Failed\n"); + tet_result(TET_FAIL); + } +} + + diff --git a/TC/TC_email_service/TC_Message/uts-email-add-attachment.h b/TC/TC_email_service/TC_Message/uts-email-add-attachment.h new file mode 100755 index 0000000..b0ae23e --- /dev/null +++ b/TC/TC_email_service/TC_Message/uts-email-add-attachment.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2012 - 2013 Samsung Electronics, Co., Ltd. + * All rights reserved. + * + * This software is a confidential and proprietary information of Samsung + * Electronics, Co., Ltd. ("Confidential Information"). 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. + */ + +#include <tet_api.h> + +#include <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <sqlite3.h> +#include "email-api-init.h" +#include "email-api-account.h" +#include "email-api-mail.h" + +static void startup(), cleanup(); +void (*tet_startup) () = startup; +void (*tet_cleanup) () = cleanup; + +static void uts_Email_Add_Attachment_01(void); +static void uts_Email_Add_Attachment_02(void); +static void uts_Email_Add_Attachment_03(void); +static void uts_Email_Add_Attachment_04(void); +static void uts_Email_Add_Attachment_05(void); + + +struct tet_testlist tet_testlist[] = { + { uts_Email_Add_Attachment_01, 1}, { uts_Email_Add_Attachment_02, 2}, { uts_Email_Add_Attachment_03, 3}, { uts_Email_Add_Attachment_04, 4}, { uts_Email_Add_Attachment_05, 5}, {NULL, 0} +}; + diff --git a/TC/TC_email_service/TC_Message/uts-email-add-message.c b/TC/TC_email_service/TC_Message/uts-email-add-message.c new file mode 100755 index 0000000..7a16a13 --- /dev/null +++ b/TC/TC_email_service/TC_Message/uts-email-add-message.c @@ -0,0 +1,211 @@ +/* +* Copyright (c) 2012 - 2013 Samsung Electronics, Inc. +* All rights reserved. +* +* This software is a confidential and proprietary information of Samsung +* Electronics, Inc. ("Confidential Information"). 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. +*/ + + +#include "uts-email-add-message.h" +#include "../TC_Utility/uts-email-dummy-utility.c" + + +sqlite3 *sqlite_emmb; +static int g_accountId; + + +static void startup() +{ + int err_code = EMAIL_ERROR_NONE; + int count = 0; + int i = 0; + email_account_t *pAccount = NULL ; + email_mailbox_t mbox; + + tet_printf("\n TC startup"); + if (EMAIL_ERROR_NONE == email_service_begin()) { + tet_infoline("Email service Begin\n"); + if (EMAIL_ERROR_NONE == email_open_db()) { + tet_infoline("Email open DB success\n"); + + g_accountId = 0; + /* Check if there are any accounts and Get account id. If there is no account in the db, add new dummy account data to the d */ + err_code = email_get_account_list(&pAccount, &count); + if (EMAIL_ERROR_NONE == err_code) { + /* get the account id from the d */ + g_accountId = pAccount[i].account_id; + email_free_account(&pAccount, count); + tet_printf("g_accountId[%d]\n", g_accountId); + } + else if (EMAIL_ERROR_ACCOUNT_NOT_FOUND == err_code) { + /* Add new dummy account to the db if there is no account in the d */ + tet_printf("Add new account\n"); + g_accountId = uts_Email_Add_Dummy_Account_01(); + tet_printf("g_accountId[%d]\n", g_accountId); + } + else { + tet_printf("email_get_account_list() failed : err_code[%d]\n", err_code); + } + + } + else + tet_infoline("Email open DB failed\n"); + } + else { + tet_infoline("Email service not started\n"); + } +} + +static void cleanup() +{ + tet_printf("\n TC End"); + + if (EMAIL_ERROR_NONE == email_close_db()) { + tet_infoline("Email Close DB Success\n"); + if (EMAIL_ERROR_NONE == email_service_end()) + tet_infoline("Email service close Success\n"); + else + tet_infoline("Email service end failed\n"); + } + else + tet_infoline("Email Close DB failed\n"); +} + + + + + + +/*Testcase : uts_Email_Add_Message_01 + TestObjective : To save message + APIs Tested : int email_add_mail(email_mail_data_t *input_mail_data, email_attachment_data_t *input_attachment_data_list, int input_attachment_count, email_meeting_request_t* input_meeting_request, int input_from_eas) + */ + +static void uts_Email_Add_Message_01() +{ + int err_code = EMAIL_ERROR_NONE; + int handle; + email_mail_data_t *test_mail_data = NULL; + email_attachment_data_t *attachment_data = NULL; + email_meeting_request_t *meeting_req = NULL; + + FILE *fp; + email_option_t option; + int count = 0; + int i = 0; + email_account_t *account = NULL ; + email_mailbox_t *mailbox = NULL; + + tet_infoline("uts_Email_Add_Message_01 Begin\n"); + + + memset(&option, 0x00, sizeof(email_option_t)); + option.keep_local_copy = 1; + + + test_mail_data = malloc(sizeof(email_mail_data_t)); + memset(test_mail_data, 0x00, sizeof(email_mail_data_t)); + + attachment_data = malloc(sizeof(email_attachment_data_t)); + memset(attachment_data, 0x00, sizeof(email_attachment_data_t)); + + + err_code = email_get_account_list(&account, &count); + if (EMAIL_ERROR_NONE == err_code) { + tet_infoline("Email get account list success\n"); + if (count > 0) { + test_mail_data->account_id = account[i].account_id; + g_accountId = account[i].account_id; + test_mail_data->flags_draft_field = 1; + + tet_printf("g_accountId[%d]\n", g_accountId); + + test_mail_data->full_address_from = strdup("<samsungtest09@gmail.com>"); + test_mail_data->full_address_to = strdup("<samsungtest09@gmail.com>"); + test_mail_data->subject = strdup("Test"); + + err_code = email_get_mailbox_by_mailbox_type(g_accountId , EMAIL_MAILBOX_TYPE_INBOX, &mailbox); + if (EMAIL_ERROR_NONE != err_code) { + tet_printf("Email get mailbox by mailbox type failed : error_code[%d]\n", err_code); + tet_result(TET_UNRESOLVED); + return ; + } + + test_mail_data->mailbox_id = mailbox->mailbox_id; + test_mail_data->mailbox_type = mailbox->mailbox_type; + + test_mail_data->save_status = 1; + test_mail_data->body_download_status = 1; + + fp = fopen("/tmp/mail.txt", "w"); + fprintf(fp, "xxxxxxxxx"); + fclose(fp); + test_mail_data->file_path_plain = strdup("/tmp/mail.txt"); + test_mail_data->attachment_count = 1; + + fp = fopen("/tmp/attach.txt", "w"); + fprintf(fp, "Simple Attachment"); + fclose(fp); + + attachment_data->attachment_name = strdup("Attach"); + attachment_data->attachment_path = strdup("/tmp/attach.txt"); + attachment_data->save_status = 1; + + err_code = email_add_mail(test_mail_data, attachment_data, 1, NULL, 0); + if (EMAIL_ERROR_NONE == err_code) { + tet_infoline("Email add message Success\n"); + tet_result(TET_PASS); + } + else { + tet_printf("Email add message failed : error_code[%d]\n", err_code); + tet_result(TET_FAIL); + } + } + else { + tet_infoline("NO email account found : success\n"); + tet_result(TET_UNRESOLVED); + } + } + else { + tet_printf("Email get account list failed : error_code[%d]\n", err_code); + tet_result(TET_UNRESOLVED); + } + tet_infoline("Free email data\n"); + + email_free_attachment_data(&attachment_data, 1); + email_free_mail_data(&test_mail_data, 1); + if (mailbox) { + email_free_mailbox(&mailbox, 1); + mailbox = NULL; + } +} + + +/*Testcase : uts_Email_Add_Message_02 + TestObjective : To validate parameter for mail in add message + APIs Tested : int email_add_mail(email_mail_data_t *input_mail_data, email_attachment_data_t *input_attachment_data_list, int input_attachment_count, email_meeting_request_t* input_meeting_request, int input_from_eas) + */ + +static void uts_Email_Add_Message_02() +{ + int err_code = EMAIL_ERROR_NONE; + + + tet_infoline("uts_Email_Add_Message_02 Begin\n"); + + err_code = email_add_mail(NULL, NULL, 0, NULL, 0); + if (EMAIL_ERROR_NONE != err_code) { + tet_infoline("Email add message : success\n"); + tet_result(TET_PASS); + } + else { + tet_infoline("Email add message : failed \n"); + tet_result(TET_FAIL); + } + + +} + diff --git a/TC/TC_email_service/TC_Message/uts-email-add-message.h b/TC/TC_email_service/TC_Message/uts-email-add-message.h new file mode 100755 index 0000000..7b17539 --- /dev/null +++ b/TC/TC_email_service/TC_Message/uts-email-add-message.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2012 - 2013 Samsung Electronics, Co., Ltd. + * All rights reserved. + * + * This software is a confidential and proprietary information of Samsung + * Electronics, Co., Ltd. ("Confidential Information"). 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. + */ + +#include <tet_api.h> + +#include <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <sqlite3.h> +#include "email-api-init.h" +#include "email-api-account.h" +#include "email-api-mail.h" + +static void startup(), cleanup(); +void (*tet_startup) () = startup; +void (*tet_cleanup) () = cleanup; + +static void uts_Email_Add_Message_01(void); +static void uts_Email_Add_Message_02(void); + + + + + + +struct tet_testlist tet_testlist[] = { + {uts_Email_Add_Message_01, 1}, {uts_Email_Add_Message_02, 2}, {NULL, 0} + + +}; + diff --git a/TC/TC_email_service/TC_Message/uts-email-cancel-send-mail.c b/TC/TC_email_service/TC_Message/uts-email-cancel-send-mail.c new file mode 100755 index 0000000..ac422ec --- /dev/null +++ b/TC/TC_email_service/TC_Message/uts-email-cancel-send-mail.c @@ -0,0 +1,121 @@ +/* +* Copyright (c) 2012 - 2013 Samsung Electronics, Inc. +* All rights reserved. +* +* This software is a confidential and proprietary information of Samsung +* Electronics, Inc. ("Confidential Information"). 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. +*/ + + +#include "uts-email-cancel-send-mail.h" +#include "../TC_Utility/uts-email-dummy-utility.c" + + +sqlite3 *sqlite_emmb; + + +static void startup() +{ + tet_printf("\n TC startup"); + + if (EMAIL_ERROR_NONE == email_service_begin()) { + tet_infoline("Email service Begin\n"); + if (EMAIL_ERROR_NONE == email_open_db()) + tet_infoline("Email open DB success\n"); + else + tet_infoline("Email open DB failed\n"); + } + else { + tet_infoline("Email service not started\n"); + } + +} + +static void cleanup() +{ + tet_printf("\n TC End"); + + if (EMAIL_ERROR_NONE == email_close_db()) { + tet_infoline("Email Close DB Success\n"); + if (EMAIL_ERROR_NONE == email_service_end()) + tet_infoline("Email service close Success\n"); + else + tet_infoline("Email service end failed\n"); + } + else + tet_infoline("Email Close DB failed\n"); +} + + + + + + +/*Testcase : uts_Email_Cancel_Send_Mail_01 + TestObjective : To get the total count and unread count of all mailboxes + APIs Tested : int email_cancel_sending_mail(int mail_id) + */ + +static void uts_Email_Cancel_Send_Mail_01() +{ + int err_code = EMAIL_ERROR_NONE; + email_mail_list_item_t *mail_list = NULL; + int account_id = 0; + int count = 0; + int i = 0; + email_account_t *pAccount = NULL ; + + tet_infoline("uts_Email_Cancel_Send_Mail_01 Begin\n"); + + err_code = email_get_account_list(&pAccount, &count); + if (EMAIL_ERROR_NONE != err_code || count <= 0) { + tet_printf("Email Get Account List Failed : err_code[%d]", err_code); + tet_result(TET_UNRESOLVED); + } + + count = 0; + err_code = uts_Email_Get_Mail_List_03(pAccount[0].account_id, EMAIL_MAILBOX_TYPE_INBOX, &mail_list, &count, 0); + if (EMAIL_ERROR_NONE == err_code) { + err_code = email_cancel_sending_mail(mail_list[i].mail_id); + if (EMAIL_ERROR_NONE == err_code) { + tet_infoline("Email Cancel Send Mail Success\n"); + tet_result(TET_PASS); + } + else { + tet_printf("Email Cancel Send Mail Failed\n"); + tet_result(TET_FAIL); + } + } + else { + tet_printf("email_get_mail_list() Failed : failed error_code[%d]\n", err_code); + tet_result(TET_FAIL); + } +} + + +/*Testcase : uts_Email_Cancel_Send_Mail_02 + TestObjective : To validate parameter for mail_id in cancel send mail + APIs Tested : int email_cancel_sending_mail(int mail_id) + */ + +static void uts_Email_Cancel_Send_Mail_02() +{ + int err_code = EMAIL_ERROR_NONE; + int mail_id = -1; + + tet_infoline("uts_Email_Cancel_Send_Mail_02 Begin\n"); + + err_code = email_cancel_sending_mail(mail_id); + if (EMAIL_ERROR_NONE == err_code) { + tet_infoline("Email Cancel Send Mail Success\n"); + tet_result(TET_PASS); + } + else { + tet_printf("Email Cancel Send Mail failed : \n"); + tet_result(TET_FAIL); + } +} + + diff --git a/TC/TC_email_service/TC_Message/uts-email-cancel-send-mail.h b/TC/TC_email_service/TC_Message/uts-email-cancel-send-mail.h new file mode 100755 index 0000000..309b6b3 --- /dev/null +++ b/TC/TC_email_service/TC_Message/uts-email-cancel-send-mail.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2012 - 2013 Samsung Electronics, Co., Ltd. + * All rights reserved. + * + * This software is a confidential and proprietary information of Samsung + * Electronics, Co., Ltd. ("Confidential Information"). 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. + */ + +#include <tet_api.h> + +#include <string.h> +#include <stdlib.h> +#include <sqlite3.h> +#include "email-api-init.h" +#include "email-api-account.h" +#include "email-api-mail.h" + +static void startup(), cleanup(); +void (*tet_startup) () = startup; +void (*tet_cleanup) () = cleanup; + +static void uts_Email_Cancel_Send_Mail_01(void); +static void uts_Email_Cancel_Send_Mail_02(void); + + + + + +struct tet_testlist tet_testlist[] = { + { uts_Email_Cancel_Send_Mail_01, 1}, { uts_Email_Cancel_Send_Mail_02, 2}, {NULL, 0} + + +}; + diff --git a/TC/TC_email_service/TC_Message/uts-email-clear-mail-data.c b/TC/TC_email_service/TC_Message/uts-email-clear-mail-data.c new file mode 100755 index 0000000..81037e0 --- /dev/null +++ b/TC/TC_email_service/TC_Message/uts-email-clear-mail-data.c @@ -0,0 +1,90 @@ +/* +* Copyright (c) 2012 - 2013 Samsung Electronics, Inc. +* All rights reserved. +* +* This software is a confidential and proprietary information of Samsung +* Electronics, Inc. ("Confidential Information"). 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. +*/ + + +#include "uts-email-clear-mail-data.h" + + +sqlite3 *sqlite_emmb; +static int g_accountId; + + +static void startup() +{ + tet_printf("\n TC startup"); + + if (EMAIL_ERROR_NONE == email_service_begin()) { + tet_infoline("Email service Begin\n"); + if (EMAIL_ERROR_NONE == email_open_db()) + tet_infoline("Email open DB success\n"); + else + tet_infoline("Email open DB failed\n"); + } + else { + tet_infoline("Email service not started\n"); + } + +} + +static void cleanup() +{ + tet_printf("\n TC End"); + + if (EMAIL_ERROR_NONE == email_close_db()) { + tet_infoline("Email Close DB Success\n"); + if (EMAIL_ERROR_NONE == email_service_end()) + tet_infoline("Email service close Success\n"); + else + tet_infoline("Email service end failed\n"); + } + else + tet_infoline("Email Close DB failed\n"); +} + + + + + + +/*Testcase : uts_Email_Clear_Mail_Data_01 + TestObjective : To Clear Mail data + APIs Tested : int email_clear_mail_data() + */ + +static void uts_Email_Clear_Mail_Data_01() +{ + int err_code = EMAIL_ERROR_NONE; + err_code = email_clear_mail_data(); + if (EMAIL_ERROR_NONE == err_code) { + tet_infoline("Email clear mail data Success\n"); + tet_result(TET_PASS); + } + else { + tet_printf("Email clear mail data failed : error_code[%d]\n", err_code); + tet_result(TET_UNRESOLVED); + } + } + + +/*Testcase : uts_Email_Clear_Mail_Data_02 + TestObjective : To validate parameter + APIs Tested : int email_clear_mail_data() + */ + +static void uts_Email_Clear_Mail_Data_02() +{ + int err_code = EMAIL_ERROR_NONE; + + /* this function has no paramete */ + tet_result(TET_PASS); +} + + + diff --git a/TC/TC_email_service/TC_Message/uts-email-clear-mail-data.h b/TC/TC_email_service/TC_Message/uts-email-clear-mail-data.h new file mode 100755 index 0000000..0a4bbec --- /dev/null +++ b/TC/TC_email_service/TC_Message/uts-email-clear-mail-data.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2012 - 2013 Samsung Electronics, Co., Ltd. + * All rights reserved. + * + * This software is a confidential and proprietary information of Samsung + * Electronics, Co., Ltd. ("Confidential Information"). 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. + */ + +#include <tet_api.h> + +#include <string.h> +#include <stdlib.h> +#include <sqlite3.h> +#include "email-api-init.h" +#include "email-api-account.h" +#include "email-api-mail.h" + +static void startup(), cleanup(); +void (*tet_startup) () = startup; +void (*tet_cleanup) () = cleanup; + +static void uts_Email_Clear_Mail_Data_01(void); +static void uts_Email_Clear_Mail_Data_02(void); + + + + + +struct tet_testlist tet_testlist[] = { + { uts_Email_Clear_Mail_Data_01, 1}, { uts_Email_Clear_Mail_Data_02, 2}, {NULL, 0} + + +}; + diff --git a/TC/TC_email_service/TC_Message/uts-email-count-message.c b/TC/TC_email_service/TC_Message/uts-email-count-message.c new file mode 100755 index 0000000..410a68e --- /dev/null +++ b/TC/TC_email_service/TC_Message/uts-email-count-message.c @@ -0,0 +1,228 @@ +/* +* Copyright (c) 2012 - 2013 Samsung Electronics, Inc. +* All rights reserved. +* +* This software is a confidential and proprietary information of Samsung +* Electronics, Inc. ("Confidential Information"). 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. +*/ + + +#include "uts-email-count-message.h" +#include "../TC_Utility/uts-email-dummy-utility.c" + + +sqlite3 *sqlite_emmb; +static int g_accountId; + + + +static void startup() +{ + int err_code = EMAIL_ERROR_NONE; + int count = 0; + int i = 0; + email_account_t *pAccount = NULL ; + email_mail_list_item_t *mail_list = NULL; + + tet_printf("\n TC startup"); + if (EMAIL_ERROR_NONE == email_service_begin()) { + tet_infoline("Email service Begin\n"); + if (EMAIL_ERROR_NONE == email_open_db()) { + tet_infoline("Email open DB success\n"); + + g_accountId = 0; + /* Check if there are any accounts and Get account id. If there is no account in the db, add new dummy account data to the d */ + err_code = email_get_account_list(&pAccount, &count); + if (EMAIL_ERROR_NONE == err_code) { + /* get the account id from the d */ + g_accountId = pAccount[i].account_id; + email_free_account(&pAccount, count); + tet_printf("g_accountId[%d]\n", g_accountId); + } + else if (EMAIL_ERROR_ACCOUNT_NOT_FOUND == err_code) { + /* Add new dummy account to the db if there is no account in the d */ + tet_printf("Add new account\n"); + g_accountId = uts_Email_Add_Dummy_Account_01(); + tet_printf("g_accountId[%d]\n", g_accountId); + } + else { + tet_printf("email_get_account_list() failed : err_code[%d]\n", err_code); + } + + /* Check if there are any mails and Get mail id of one of them. If there is no mail in the db, add new dummy mail data to the d */ + count = 0; + err_code = uts_Email_Get_Mail_List_03(ALL_ACCOUNT, 0, &mail_list, &count, 0); + if (EMAIL_ERROR_NONE == err_code) { + tet_printf("email_get_mail_list() success\n"); + } + else if (EMAIL_ERROR_MAIL_NOT_FOUND == err_code) { + tet_printf("Add new email\n"); + err_code = uts_Email_Add_Dummy_Message_02(); + if (EMAIL_ERROR_NONE == err_code) { /* Make db contain at least one mai */ + tet_printf("uts_Email_Add_Dummy_Message_02() success.\n"); + } + else { + tet_printf("uts_Email_Add_Dummy_Message_02() failed : err_code[%d]\n", err_code); + } + } + else { + tet_printf("Email Get Mail List Failed : err_code[%d]", err_code); + } + } + else + tet_infoline("Email open DB failed\n"); + } + else { + tet_infoline("Email service not started\n"); + } +} + + +static void cleanup() +{ + tet_printf("\n TC End"); + + if (EMAIL_ERROR_NONE == email_close_db()) { + tet_infoline("Email Close DB Success\n"); + if (EMAIL_ERROR_NONE == email_service_end()) + tet_infoline("Email service close Success\n"); + else + tet_infoline("Email service end failed\n"); + } + else + tet_infoline("Email Close DB failed\n"); +} + + + + + + +/*Testcase : uts_Email_Count_Message_01 + TestObjective : To get mail count for mailbox + APIs Tested : int email_count_mail(email_list_filter_t *input_filter_list, int input_filter_count, int *output_total_mail_count, int *output_unseen_mail_count) + */ + +static void uts_Email_Count_Message_01() +{ + int err_code = EMAIL_ERROR_NONE; + int total = 0; + int unseen = 0; + email_list_filter_t *filter_list = NULL; + + tet_infoline("utc_Email_Count_Message_01 Begin\n"); + + filter_list = malloc(sizeof(email_list_filter_t) * 3); + memset(filter_list, 0 , sizeof(email_list_filter_t) * 3); + + filter_list[0].list_filter_item_type = EMAIL_LIST_FILTER_ITEM_RULE; + filter_list[0].list_filter_item.rule.target_attribute = EMAIL_MAIL_ATTRIBUTE_MAILBOX_TYPE; + filter_list[0].list_filter_item.rule.rule_type = EMAIL_LIST_FILTER_RULE_EQUAL; + filter_list[0].list_filter_item.rule.key_value.integer_type_value = EMAIL_MAILBOX_TYPE_INBOX; + filter_list[0].list_filter_item.rule.case_sensitivity = false; + + err_code = email_count_mail(filter_list, 1, &total, &unseen); + if (EMAIL_ERROR_NONE == err_code) { + tet_infoline("Email count message : success\n"); + tet_result(TET_PASS); + } + else { + tet_printf("Email count message : failed error_code[%d]\n", err_code); + tet_result(TET_FAIL); + } +} + +/*Testcase : uts_Email_Count_Message_02 + TestObjective : To validate parameter for mailbox in get mail count for mailbox + APIs Tested : int email_count_mail(email_list_filter_t *input_filter_list, int input_filter_count, int *output_total_mail_count, int *output_unseen_mail_count) + */ + +static void uts_Email_Count_Message_02() +{ + int err_code = EMAIL_ERROR_NONE; + int total = 0; + int unseen = 0; + + tet_infoline("utc_Email_Count_Message_02 Begin\n"); + + err_code = email_count_mail(NULL, 1, &total, &unseen); + if (EMAIL_ERROR_NONE != err_code) { + tet_infoline("Email count message : success\n"); + tet_result(TET_PASS); + } + else { + tet_infoline("Email count message : failed \n"); + tet_result(TET_FAIL); + } +} + +/*Testcase : uts_Email_Count_Message_03 + TestObjective : To validate parameter for total in get mail count for mailbox + APIs Tested : int email_count_mail(email_list_filter_t *input_filter_list, int input_filter_count, int *output_total_mail_count, int *output_unseen_mail_count) + */ + +static void uts_Email_Count_Message_03() +{ + int err_code = EMAIL_ERROR_NONE; + int unseen = 0; + email_list_filter_t *filter_list = NULL; + + tet_infoline("utc_Email_Count_Message_03 Begin\n"); + + filter_list = malloc(sizeof(email_list_filter_t) * 3); + memset(filter_list, 0 , sizeof(email_list_filter_t) * 3); + + filter_list[0].list_filter_item_type = EMAIL_LIST_FILTER_ITEM_RULE; + filter_list[0].list_filter_item.rule.target_attribute = EMAIL_MAIL_ATTRIBUTE_MAILBOX_TYPE; + filter_list[0].list_filter_item.rule.rule_type = EMAIL_LIST_FILTER_RULE_EQUAL; + filter_list[0].list_filter_item.rule.key_value.integer_type_value = EMAIL_MAILBOX_TYPE_SENTBOX; + filter_list[0].list_filter_item.rule.case_sensitivity = false; + + err_code = email_count_mail(filter_list, 1, 0, &unseen); + + if (EMAIL_ERROR_NONE != err_code) { + tet_infoline("Email count message : success\n"); + tet_result(TET_PASS); + } + else { + tet_infoline("Email count message : failed \n"); + tet_result(TET_FAIL); + } +} + +/*Testcase : uts_Email_Count_Message_04 + TestObjective : To validate parameter for seen in get mail count for mailbox + APIs Tested : int email_count_mail(email_list_filter_t *input_filter_list, int input_filter_count, int *output_total_mail_count, int *output_unseen_mail_count) + */ + +static void uts_Email_Count_Message_04() +{ + int err_code = EMAIL_ERROR_NONE; + int total = 0; + email_list_filter_t *filter_list = NULL; + + tet_infoline("utc_Email_Count_Message_04 Begin\n"); + + filter_list = malloc(sizeof(email_list_filter_t) * 3); + memset(filter_list, 0 , sizeof(email_list_filter_t) * 3); + + filter_list[0].list_filter_item_type = EMAIL_LIST_FILTER_ITEM_RULE; + filter_list[0].list_filter_item.rule.target_attribute = EMAIL_MAIL_ATTRIBUTE_MAILBOX_TYPE; + filter_list[0].list_filter_item.rule.rule_type = EMAIL_LIST_FILTER_RULE_EQUAL; + filter_list[0].list_filter_item.rule.key_value.integer_type_value = EMAIL_MAILBOX_TYPE_SENTBOX; + filter_list[0].list_filter_item.rule.case_sensitivity = false; + + err_code = email_count_mail(filter_list, 1, &total, 0); + + if (EMAIL_ERROR_NONE != err_code) { + tet_infoline("Email count message : success\n"); + tet_result(TET_PASS); + } + else { + tet_infoline("Email count message : failed \n"); + tet_result(TET_FAIL); + } +} + diff --git a/TC/TC_email_service/TC_Message/uts-email-count-message.h b/TC/TC_email_service/TC_Message/uts-email-count-message.h new file mode 100755 index 0000000..03bd343 --- /dev/null +++ b/TC/TC_email_service/TC_Message/uts-email-count-message.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2012 - 2013 Samsung Electronics, Co., Ltd. + * All rights reserved. + * + * This software is a confidential and proprietary information of Samsung + * Electronics, Co., Ltd. ("Confidential Information"). 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. + */ + +#include <tet_api.h> + +#include <string.h> +#include <stdlib.h> +#include <sqlite3.h> +#include "email-api-init.h" +#include "email-api-account.h" +#include "email-api-mail.h" + +static void startup(), cleanup(); +void (*tet_startup) () = startup; +void (*tet_cleanup) () = cleanup; + +static void uts_Email_Count_Message_01(void); +static void uts_Email_Count_Message_02(void); +static void uts_Email_Count_Message_03(void); +static void uts_Email_Count_Message_04(void); + + + + + +struct tet_testlist tet_testlist[] = { + { uts_Email_Count_Message_01, 1}, { uts_Email_Count_Message_02, 2}, { uts_Email_Count_Message_03, 3}, { uts_Email_Count_Message_04, 4}, {NULL, 0} + + +}; + diff --git a/TC/TC_email_service/TC_Message/uts-email-create-db-full.c b/TC/TC_email_service/TC_Message/uts-email-create-db-full.c new file mode 100755 index 0000000..468d237 --- /dev/null +++ b/TC/TC_email_service/TC_Message/uts-email-create-db-full.c @@ -0,0 +1,137 @@ +/* +* Copyright (c) 2012 - 2013 Samsung Electronics, Inc. +* All rights reserved. +* +* This software is a confidential and proprietary information of Samsung +* Electronics, Inc. ("Confidential Information"). 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. +*/ + + +#include "uts-email-create-db-full.h" +#include "../TC_Utility/uts-email-dummy-utility.c" + + +sqlite3 *sqlite_emmb; +static int g_accountId; + + + +static void startup() +{ + int err_code = EMAIL_ERROR_NONE; + int count = 0; + int i = 0; + email_account_t *pAccount = NULL ; + email_mail_list_item_t *mail_list = NULL; + + tet_printf("\n TC startup"); + if (EMAIL_ERROR_NONE == email_service_begin()) { + tet_infoline("Email service Begin\n"); + if (EMAIL_ERROR_NONE == email_open_db()) { + tet_infoline("Email open DB success\n"); + + g_accountId = 0; + /* Check if there are any accounts and Get account id. If there is no account in the db, add new dummy account data to the d */ + err_code = email_get_account_list(&pAccount, &count); + if (EMAIL_ERROR_NONE == err_code) { + /* get the account id from the d */ + g_accountId = pAccount[i].account_id; + email_free_account(&pAccount, count); + tet_printf("g_accountId[%d]\n", g_accountId); + } + else if (EMAIL_ERROR_ACCOUNT_NOT_FOUND == err_code) { + /* Add new dummy account to the db if there is no account in the d */ + tet_printf("Add new account\n"); + g_accountId = uts_Email_Add_Dummy_Account_01(); + tet_printf("g_accountId[%d]\n", g_accountId); + } + else { + tet_printf("email_get_account_list() failed : err_code[%d]\n", err_code); + } + + /* Check if there are any mails and Get mail id of one of them. If there is no mail in the db, add new dummy mail data to the d */ + count = 0; + err_code = uts_Email_Get_Mail_List_03(ALL_ACCOUNT, 0, &mail_list, &count, 0); + if (EMAIL_ERROR_NONE == err_code) { + tet_printf("email_get_mail_list() success\n"); + } + else if (EMAIL_ERROR_MAIL_NOT_FOUND == err_code) { + tet_printf("Add new email\n"); + err_code = uts_Email_Add_Dummy_Message_02(); + if (EMAIL_ERROR_NONE == err_code) { /* Make db contain at least one mai */ + tet_printf("uts_Email_Add_Dummy_Message_02() success.\n"); + } + else { + tet_printf("uts_Email_Add_Dummy_Message_02() failed : err_code[%d]\n", err_code); + } + } + else { + tet_printf("Email Get Mail List Failed : err_code[%d]", err_code); + } + } + else + tet_infoline("Email open DB failed\n"); + } + else { + tet_infoline("Email service not started\n"); + } +} + + + +static void cleanup() +{ + tet_printf("\n TC End"); + + if (EMAIL_ERROR_NONE == email_close_db()) { + tet_infoline("Email Close DB Success\n"); + if (EMAIL_ERROR_NONE == email_service_end()) + tet_infoline("Email service close Success\n"); + else + tet_infoline("Email service end failed\n"); + } + else + tet_infoline("Email Close DB failed\n"); +} + + + + + + +/*Testcase : uts_Email_Create_Db_Full_01 + TestObjective : To Create DB full + APIs Tested : int email_create_db_full() + */ + +static void uts_Email_Create_Db_Full_01() +{ + int err_code = EMAIL_ERROR_NONE; + + err_code = email_create_db_full(); + if (EMAIL_ERROR_NONE == err_code) { + tet_infoline("Email Create Db Full Success\n"); + tet_result(TET_PASS); + } + else { + tet_printf("Email Create Db Full Failed\n"); + tet_result(TET_FAIL); + } +} + +/*Testcase : uts_Email_Create_Db_Full_02 + TestObjective : email_create_db_full() have no parameter. return TET_PASS + APIs Tested : int email_create_db_full() + */ + +static void uts_Email_Create_Db_Full_02() +{ + int err_code = EMAIL_ERROR_NONE; + + tet_result(TET_PASS); +} + + + diff --git a/TC/TC_email_service/TC_Message/uts-email-create-db-full.h b/TC/TC_email_service/TC_Message/uts-email-create-db-full.h new file mode 100755 index 0000000..e36ae57 --- /dev/null +++ b/TC/TC_email_service/TC_Message/uts-email-create-db-full.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2012 - 2013 Samsung Electronics, Co., Ltd. + * All rights reserved. + * + * This software is a confidential and proprietary information of Samsung + * Electronics, Co., Ltd. ("Confidential Information"). 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. + */ + +#include <tet_api.h> + +#include <string.h> +#include <stdlib.h> +#include <sqlite3.h> +#include "email-api-init.h" +#include "email-api-account.h" +#include "email-api-mail.h" + +static void startup(), cleanup(); +void (*tet_startup) () = startup; +void (*tet_cleanup) () = cleanup; + +static void uts_Email_Create_Db_Full_01(void); +static void uts_Email_Create_Db_Full_02(void); + + + + + +struct tet_testlist tet_testlist[] = { + { uts_Email_Create_Db_Full_01, 1}, { uts_Email_Create_Db_Full_02, 2}, {NULL, 0} + + +}; + diff --git a/TC/TC_email_service/TC_Message/uts-email-delete-all-message-in-folder.c b/TC/TC_email_service/TC_Message/uts-email-delete-all-message-in-folder.c new file mode 100755 index 0000000..ca34dc3 --- /dev/null +++ b/TC/TC_email_service/TC_Message/uts-email-delete-all-message-in-folder.c @@ -0,0 +1,180 @@ +/* +* Copyright (c) 2012 - 2013 Samsung Electronics, Inc. +* All rights reserved. +* +* This software is a confidential and proprietary information of Samsung +* Electronics, Inc. ("Confidential Information"). 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. +*/ + + +#include "uts-email-delete-all-message-in-folder.h" +#include "../TC_Utility/uts-email-dummy-utility.c" + + +sqlite3 *sqlite_emmb; +static int g_accountId; + + + +static void startup() +{ + int err_code = EMAIL_ERROR_NONE; + int count = 0; + int i = 0; + email_account_t *pAccount = NULL ; + email_mail_list_item_t *mail_list = NULL; + + tet_printf("\n TC startup"); + if (EMAIL_ERROR_NONE == email_service_begin()) { + tet_infoline("Email service Begin\n"); + if (EMAIL_ERROR_NONE == email_open_db()) { + tet_infoline("Email open DB success\n"); + + g_accountId = 0; + /* Check if there are any accounts and Get account id. If there is no account in the db, add new dummy account data to the d */ + err_code = email_get_account_list(&pAccount, &count); + if (EMAIL_ERROR_NONE == err_code) { + /* get the account id from the d */ + g_accountId = pAccount[i].account_id; + email_free_account(&pAccount, count); + tet_printf("g_accountId[%d]\n", g_accountId); + } + else if (EMAIL_ERROR_ACCOUNT_NOT_FOUND == err_code) { + /* Add new dummy account to the db if there is no account in the d */ + tet_printf("Add new account\n"); + g_accountId = uts_Email_Add_Dummy_Account_01(); + tet_printf("g_accountId[%d]\n", g_accountId); + } + else { + tet_printf("email_get_account_list() failed : err_code[%d]\n", err_code); + } + + /* Check if there are any mails and Get mail id of one of them. If there is no mail in the db, add new dummy mail data to the d */ + count = 0; + err_code = uts_Email_Get_Mail_List_03(ALL_ACCOUNT, 0, &mail_list, &count, 0); + if (EMAIL_ERROR_NONE == err_code) { + tet_printf("email_get_mail_list() success\n"); + } + else if (EMAIL_ERROR_MAIL_NOT_FOUND == err_code) { + tet_printf("Add new email\n"); + err_code = uts_Email_Add_Dummy_Message_02(); + if (EMAIL_ERROR_NONE == err_code) { /* Make db contain at least one mai */ + tet_printf("uts_Email_Add_Dummy_Message_02() success.\n"); + } + else { + tet_printf("uts_Email_Add_Dummy_Message_02() failed : err_code[%d]\n", err_code); + } + } + else { + tet_printf("Email Get Mail List Failed : err_code[%d]", err_code); + } + } + else + tet_infoline("Email open DB failed\n"); + } + else { + tet_infoline("Email service not started\n"); + } +} + + + +static void cleanup() +{ + tet_printf("\n TC End"); + + if (EMAIL_ERROR_NONE == email_close_db()) { + tet_infoline("Email Close DB Success\n"); + if (EMAIL_ERROR_NONE == email_service_end()) + tet_infoline("Email service close Success\n"); + else + tet_infoline("Email service end failed\n"); + } + else + tet_infoline("Email Close DB failed\n"); +} + + + + + + + +/*Testcase : uts_Email_Delete_All_Message_In_Folder_01 + TestObjective : To delete all message in mailbox message + APIs Tested : int email_delete_all_mails_in_mailbox(int input_mailbox_id, int input_from_server) + */ + +static void uts_Email_Delete_All_Message_In_Folder_01() +{ + int err_code = EMAIL_ERROR_NONE; + int handle; + int count = 0; + int i = 0; + email_account_t *account = NULL ; + email_mailbox_t *mailbox = NULL; + + tet_infoline("utc_Email_Delete_All_Message_In_Folder_01 Begin\n"); + + err_code = email_get_account_list(&account, &count); + if (EMAIL_ERROR_NONE == err_code) { + tet_infoline("Email get account list success\n"); + if (count > 0) { + err_code = email_get_mailbox_by_mailbox_type(account[i].account_id , EMAIL_MAILBOX_TYPE_SENTBOX, &mailbox); + if (EMAIL_ERROR_NONE != err_code) { + tet_printf("Email get mailbox by mailbox type failed : error_code[%d]\n", err_code); + tet_result(TET_UNRESOLVED); + } + err_code = email_delete_all_mails_in_mailbox(mailbox->mailbox_id, 0); + if (EMAIL_ERROR_NONE == err_code) { + tet_infoline("Email delete all message in mailbox : success\n"); + tet_result(TET_PASS); + } + else { + tet_printf("Email delete all message in mailbox failed : error_code[%d]\n", err_code); + tet_printf("account_id[%d], mailbox->mailbox_id[%d]\n", account[i].account_id, mailbox->mailbox_id); + tet_result(TET_FAIL); + } + } + else { + tet_infoline("NO email account found : success\n"); + tet_result(TET_UNRESOLVED); + } + } + else { + tet_printf("Email get account list failed : error_code[%d]\n", err_code); + tet_result(TET_UNRESOLVED); + } + + if (mailbox) { + email_free_mailbox(&mailbox, 1); + mailbox = NULL; + } + +} + + + +/*Testcase : uts_Email_Delete_All_Message_In_Folder_02 + TestObjective : To validate parameter for mailbox in delete all message in mailbox message + APIs Tested : int email_delete_all_mails_in_mailbox(int input_mailbox_id, int input_from_server) + */ + +static void uts_Email_Delete_All_Message_In_Folder_02() +{ + int err_code = EMAIL_ERROR_NONE; + + tet_infoline("utc_Email_delete_all_Message_in_folder Begin\n"); + + err_code = email_delete_all_mails_in_mailbox(0, 0); + if (EMAIL_ERROR_NONE != err_code) { + tet_infoline("Email delete all_message_in_folder : success\n"); + tet_result(TET_PASS); + } + else { + tet_infoline("Email delete all_message in mailbox : failed \n"); + tet_result(TET_FAIL); + } +} diff --git a/TC/TC_email_service/TC_Message/uts-email-delete-all-message-in-folder.h b/TC/TC_email_service/TC_Message/uts-email-delete-all-message-in-folder.h new file mode 100755 index 0000000..3b56dfe --- /dev/null +++ b/TC/TC_email_service/TC_Message/uts-email-delete-all-message-in-folder.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2012 - 2013 Samsung Electronics, Co., Ltd. + * All rights reserved. + * + * This software is a confidential and proprietary information of Samsung + * Electronics, Co., Ltd. ("Confidential Information"). 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. + */ + +#include <tet_api.h> + +#include <string.h> +#include <stdlib.h> +#include <sqlite3.h> +#include "email-api-init.h" +#include "email-api-account.h" +#include "email-api-mail.h" + +static void startup(), cleanup(); +void (*tet_startup) () = startup; +void (*tet_cleanup) () = cleanup; + +static void uts_Email_Delete_All_Message_In_Folder_01(void); +static void uts_Email_Delete_All_Message_In_Folder_02(void); + + + + + +struct tet_testlist tet_testlist[] = { + { uts_Email_Delete_All_Message_In_Folder_01, 1}, { uts_Email_Delete_All_Message_In_Folder_02, 2}, {NULL, 0} + + +}; + diff --git a/TC/TC_email_service/TC_Message/uts-email-delete-attachment.c b/TC/TC_email_service/TC_Message/uts-email-delete-attachment.c new file mode 100755 index 0000000..303e3b0 --- /dev/null +++ b/TC/TC_email_service/TC_Message/uts-email-delete-attachment.c @@ -0,0 +1,180 @@ +/* +* Copyright (c) 2012 - 2013 Samsung Electronics, Inc. +* All rights reserved. +* +* This software is a confidential and proprietary information of Samsung +* Electronics, Inc. ("Confidential Information"). 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. +*/ + + +#include "uts-email-delete-attachment.h" +#include "../TC_Utility/uts-email-dummy-utility.c" + + +sqlite3 *sqlite_emmb; +static int g_accountId; + + + +static void startup() +{ + int err_code = EMAIL_ERROR_NONE; + int count = 0; + int i = 0; + email_account_t *pAccount = NULL ; + email_mail_list_item_t *mail_list = NULL; + + tet_printf("\n TC startup"); + if (EMAIL_ERROR_NONE == email_service_begin()) { + tet_infoline("Email service Begin\n"); + if (EMAIL_ERROR_NONE == email_open_db()) { + tet_infoline("Email open DB success\n"); + + g_accountId = 0; + /* Check if there are any accounts and Get account id. If there is no account in the db, add new dummy account data to the d */ + err_code = email_get_account_list(&pAccount, &count); + if (EMAIL_ERROR_NONE == err_code) { + /* get the account id from the d */ + g_accountId = pAccount[i].account_id; + email_free_account(&pAccount, count); + tet_printf("g_accountId[%d]\n", g_accountId); + } + else if (EMAIL_ERROR_ACCOUNT_NOT_FOUND == err_code) { + /* Add new dummy account to the db if there is no account in the d */ + tet_printf("Add new account\n"); + g_accountId = uts_Email_Add_Dummy_Account_01(); + tet_printf("g_accountId[%d]\n", g_accountId); + } + else { + tet_printf("email_get_account_list() failed : err_code[%d]\n", err_code); + } + + /* Check if there are any mails and Get mail id of one of them. If there is no mail in the db, add new dummy mail data to the d */ + count = 0; + err_code = uts_Email_Get_Mail_List_03(g_accountId, EMAIL_MAILBOX_TYPE_INBOX, &mail_list, &count, 0); + if (EMAIL_ERROR_NONE == err_code) { + tet_printf("email_get_mail_list() success\n"); + } + else if (EMAIL_ERROR_MAIL_NOT_FOUND == err_code) { + tet_printf("Add new email\n"); + err_code = uts_Email_Add_Dummy_Message_02(); + if (EMAIL_ERROR_NONE == err_code) { /* Make db contain at least one mai */ + tet_printf("uts_Email_Add_Dummy_Message_02() success.\n"); + } + else { + tet_printf("uts_Email_Add_Dummy_Message_02() failed : err_code[%d]\n", err_code); + } + } + else { + tet_printf("Email Get Mail List Failed : err_code[%d]", err_code); + } + } + else + tet_infoline("Email open DB failed\n"); + } + else { + tet_infoline("Email service not started\n"); + } +} + + +static void cleanup() +{ + tet_printf("\n TC End"); + + if (EMAIL_ERROR_NONE == email_close_db()) { + tet_infoline("Email Close DB Success\n"); + if (EMAIL_ERROR_NONE == email_service_end()) + tet_infoline("Email service close Success\n"); + else + tet_infoline("Email service end failed\n"); + } + else + tet_infoline("Email Close DB failed\n"); +} + + + + + + +/*Testcase : uts_Email_Delete_Attachment_01 + TestObjective : To delete a attachment from mail + APIs Tested : int email_delete_attachment(int attachment_id) + */ + +static void uts_Email_Delete_Attachment_01() +{ + int err_code = EMAIL_ERROR_NONE; + int attachment_id = 0; + int i = 0; + email_attachment_data_t *mail_attach_info = NULL; + email_mail_list_item_t *mail_list = NULL; + int count = 0; + email_account_t *account = NULL ; + + tet_infoline("uts_Email_Delete_Attachment_01 Begin\n"); + + err_code = email_get_account_list(&account, &count); + if (EMAIL_ERROR_NONE != err_code || count < 0) { + tet_printf("Email Get Account List Failed : err_code[%d]\n", err_code); + tet_result(TET_UNRESOLVED); + return; + } + g_accountId = account[i].account_id; + + err_code = uts_Email_Get_Mail_List_03(g_accountId, EMAIL_MAILBOX_TYPE_INBOX, &mail_list, &count, 0); + if (EMAIL_ERROR_NONE != err_code || count < 0) { + tet_printf("Email Get Account List Failed : err_code[%d]\n", err_code); + tet_result(TET_UNRESOLVED); + return; + } + for (i ; i < count ; i++) { + if(mail_list[i].attachment_count) { + err_code = email_get_attachment_data_list(mail_list[i].mail_id, &mail_attach_info, &count); + if (EMAIL_ERROR_NONE == err_code) { + err_code = email_delete_attachment(mail_attach_info->attachment_id); + if (EMAIL_ERROR_NONE == err_code) { + tet_infoline("Email delete attachment : success\n"); + tet_result(TET_PASS); + return ; + } + else { + tet_printf("Email delete attachment : Failed err_code[%d]\n", err_code); + tet_result(TET_FAIL); + return ; + } + + }else { + tet_printf("Email get attachment data list : Failed err_code[%d]\n", err_code); + tet_result(TET_UNRESOLVED); + } + } + } +} + + +/*Testcase : uts_Email_Delete_Attachment_02 + TestObjective : To validate parmete for mailbox in delete a attachment from mail + APIs Tested : int email_delete_attachment(int attachment_id) + */ + +static void uts_Email_Delete_Attachment_02() +{ + int err_code = EMAIL_ERROR_NONE; + + tet_infoline("uts_Email_Delete_Attachment_02 Begin\n"); + + err_code = email_delete_attachment(0); + if (EMAIL_ERROR_NONE != err_code) { + tet_infoline("Email delete attachment : success\n"); + tet_result(TET_PASS); + } + else { + tet_printf("Email delete attachment : Failed \n"); + tet_result(TET_FAIL); + } + +} diff --git a/TC/TC_email_service/TC_Message/uts-email-delete-attachment.h b/TC/TC_email_service/TC_Message/uts-email-delete-attachment.h new file mode 100755 index 0000000..dec459f --- /dev/null +++ b/TC/TC_email_service/TC_Message/uts-email-delete-attachment.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2012 - 2013 Samsung Electronics, Co., Ltd. + * All rights reserved. + * + * This software is a confidential and proprietary information of Samsung + * Electronics, Co., Ltd. ("Confidential Information"). 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. + */ + +#include <tet_api.h> + +#include <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <sqlite3.h> +#include "email-api-init.h" +#include "email-api-account.h" +#include "email-api-mail.h" + +static void startup(), cleanup(); +void (*tet_startup) () = startup; +void (*tet_cleanup) () = cleanup; + +static void uts_Email_Delete_Attachment_01(void); +static void uts_Email_Delete_Attachment_02(void); + + + + +struct tet_testlist tet_testlist[] = { + { uts_Email_Delete_Attachment_01, 1}, { uts_Email_Delete_Attachment_02, 2}, {NULL, 0} + + +}; + diff --git a/TC/TC_email_service/TC_Message/uts-email-delete-message.c b/TC/TC_email_service/TC_Message/uts-email-delete-message.c new file mode 100755 index 0000000..2468330 --- /dev/null +++ b/TC/TC_email_service/TC_Message/uts-email-delete-message.c @@ -0,0 +1,237 @@ +/* +* Copyright (c) 2012 - 2013 Samsung Electronics, Inc. +* All rights reserved. +* +* This software is a confidential and proprietary information of Samsung +* Electronics, Inc. ("Confidential Information"). 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. +*/ + + +#include "uts-email-delete-message.h" +#include "../TC_Utility/uts-email-dummy-utility.c" + + +sqlite3 *sqlite_emmb; +static int g_accountId; + + + +static void startup() +{ + int err_code = EMAIL_ERROR_NONE; + int count = 0; + int i = 0; + email_account_t *pAccount = NULL ; + email_mail_list_item_t *mail_list = NULL; + + tet_printf("\n TC startup"); + if (EMAIL_ERROR_NONE == email_service_begin()) { + tet_infoline("Email service Begin\n"); + if (EMAIL_ERROR_NONE == email_open_db()) { + tet_infoline("Email open DB success\n"); + + g_accountId = 0; + /* Check if there are any accounts and Get account id. If there is no account in the db, add new dummy account data to the d */ + err_code = email_get_account_list(&pAccount, &count); + if (EMAIL_ERROR_NONE == err_code) { + /* get the account id from the d */ + g_accountId = pAccount[i].account_id; + email_free_account(&pAccount, count); + tet_printf("g_accountId[%d]\n", g_accountId); + } + else if (EMAIL_ERROR_ACCOUNT_NOT_FOUND == err_code) { + /* Add new dummy account to the db if there is no account in the d */ + tet_printf("Add new account\n"); + g_accountId = uts_Email_Add_Dummy_Account_01(); + tet_printf("g_accountId[%d]\n", g_accountId); + } + else { + tet_printf("email_get_account_list() failed : err_code[%d]\n", err_code); + } + + /* Check if there are any mails and Get mail id of one of them. If there is no mail in the db, add new dummy mail data to the d */ + count = 0; + err_code = uts_Email_Get_Mail_List_03(g_accountId, EMAIL_MAILBOX_TYPE_INBOX, &mail_list, &count, 0); + if (EMAIL_ERROR_NONE == err_code) { + tet_printf("email_get_mail_list() success\n"); + } + else if (EMAIL_ERROR_MAIL_NOT_FOUND == err_code) { + tet_printf("Add new email\n"); + err_code = uts_Email_Add_Dummy_Message_02(); + if (EMAIL_ERROR_NONE == err_code) { /* Make db contain at least one mai */ + tet_printf("uts_Email_Add_Dummy_Message_02() success.\n"); + } + else { + tet_printf("uts_Email_Add_Dummy_Message_02() failed : err_code[%d]\n", err_code); + } + } + else { + tet_printf("Email Get Mail List Failed : err_code[%d]", err_code); + } + } + else + tet_infoline("Email open DB failed\n"); + } + else { + tet_infoline("Email service not started\n"); + } +} + +static void cleanup() +{ + tet_printf("\n TC End"); + + if (EMAIL_ERROR_NONE == email_close_db()) { + tet_infoline("Email Close DB Success\n"); + if (EMAIL_ERROR_NONE == email_service_end()) + tet_infoline("Email service close Success\n"); + else + tet_infoline("Email service end failed\n"); + } + else + tet_infoline("Email Close DB failed\n"); +} + + + + + + + +/*Testcase : uts_Email_Delete_Message_01 + TestObjective : To update message + APIs Tested : int email_delete_mail(int input_mailbox_id, int *input_mail_ids, int input_num, int input_from_server) + */ + +static void uts_Email_Delete_Message_01() +{ + int err_code = EMAIL_ERROR_NONE; + int handle; + int count = 0; + int i = 0; + email_account_t *account = NULL ; + email_mail_list_item_t *mail_list = NULL; + + tet_infoline("uts_Email_Delete_Message_01 Begin\n"); + + err_code = email_get_account_list(&account, &count); + if (EMAIL_ERROR_NONE == err_code) { + tet_infoline("Email get account list success\n"); + if (count > 0) { + count = 0; + err_code = uts_Email_Get_Mail_List_03(account[i].account_id, EMAIL_MAILBOX_TYPE_INBOX, &mail_list, &count, 0); + if (EMAIL_ERROR_NONE == err_code) { + tet_infoline("Email get mail list : success\n"); + if (count > 0) { + tet_printf("mail_list[i].mailbox_id[%d] mail_list[i].mail_id[%d]\n", mail_list[i].mailbox_id, mail_list[i].mail_id); + err_code = email_delete_mail(mail_list[i].mailbox_id, &mail_list[i].mail_id , 1, 0); + if (EMAIL_ERROR_NONE == err_code) { + tet_infoline("Email delete message : success\n"); + tet_result(TET_PASS); + } + else { + tet_printf("Email delete message failed : error_code[%d]\n", err_code); + tet_result(TET_FAIL); + } + } + } + else { + tet_printf("Email get mail list failed : error_code[%d]\n", err_code); + tet_result(TET_UNRESOLVED); + } + /* email_free_mail_list(&mail_list, count) */ + free(mail_list); + } + else { + tet_infoline("NO email account found : success\n"); + tet_result(TET_UNRESOLVED); + } + } + else { + tet_printf("Email get account list failed : error_code[%d]\n", err_code); + tet_result(TET_UNRESOLVED); + } + +} + + + +/*Testcase : uts_Email_Delete_Message_02 + TestObjective : To validate parameter for mailbox in delete message + APIs Tested : int email_delete_mail(int input_mailbox_id, int *input_mail_ids, int input_num, int input_from_server) + */ + +static void uts_Email_Delete_Message_02() +{ + int err_code = EMAIL_ERROR_NONE; + int mail_id = 1; + + tet_infoline("uts_Email_delete_Message_02 Begin\n"); + + err_code = email_delete_mail(0, &mail_id , 1, 0); + if (EMAIL_ERROR_NONE != err_code) { + tet_infoline("Email delete message : success\n"); + tet_result(TET_PASS); + } + else { + tet_infoline("Email delete message : failed \n"); + tet_result(TET_FAIL); + } +} + + +/*Testcase : uts_Email_Delete_Message_03 + TestObjective : To validate parameter for mail_id in delete message + APIs Tested : int email_delete_mail(int input_mailbox_id, int *input_mail_ids, int input_num, int input_from_server) + */ + +static void uts_Email_Delete_Message_03() +{ + int err_code = EMAIL_ERROR_NONE; + int mail_id = 0; + int count = 0; + email_mailbox_t *mail_box = NULL; + email_account_t *account = NULL; + + tet_infoline("uts_Email_delete_Message_03 Begin\n"); + + err_code = email_get_account_list(&account, &count); + if (EMAIL_ERROR_NONE == err_code) { + tet_infoline("Email get account list success\n"); + if (count > 0) { + count = 0; + err_code = email_get_mailbox_by_mailbox_type(account[0].account_id, EMAIL_MAILBOX_TYPE_INBOX, &mail_box); + + if (EMAIL_ERROR_NONE != err_code) { + tet_infoline("email_get_mailbox_by_mailbox_type : failed\n"); + tet_result(TET_UNRESOLVED); + } + + err_code = email_delete_mail(mail_box->mailbox_id, &mail_id , 1, 0); + + if (mail_box) { + email_free_mailbox(&mail_box, 1); + mail_box = NULL; + } + + if (EMAIL_ERROR_NONE != err_code) { + tet_infoline("Email delete message : success\n"); + tet_result(TET_PASS); + } + else { + tet_infoline("Email delete message : failed \n"); + tet_result(TET_FAIL); + } + } + }else { + tet_printf("Email get account list failed : error_code[%d]\n", err_code); + tet_result(TET_UNRESOLVED); + } +} + + + + + diff --git a/TC/TC_email_service/TC_Message/uts-email-delete-message.h b/TC/TC_email_service/TC_Message/uts-email-delete-message.h new file mode 100755 index 0000000..c61f21c --- /dev/null +++ b/TC/TC_email_service/TC_Message/uts-email-delete-message.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2012 - 2013 Samsung Electronics, Co., Ltd. + * All rights reserved. + * + * This software is a confidential and proprietary information of Samsung + * Electronics, Co., Ltd. ("Confidential Information"). 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. + */ + +#include <tet_api.h> + +#include <string.h> +#include <stdlib.h> +#include <sqlite3.h> +#include "email-api-init.h" +#include "email-api-account.h" +#include "email-api-mail.h" + +static void startup(), cleanup(); +void (*tet_startup) () = startup; +void (*tet_cleanup) () = cleanup; + +static void uts_Email_Delete_Message_01(void); +static void uts_Email_Delete_Message_02(void); +static void uts_Email_Delete_Message_03(void); + + + + + + +struct tet_testlist tet_testlist[] = { + { uts_Email_Delete_Message_01, 1}, { uts_Email_Delete_Message_02, 2}, { uts_Email_Delete_Message_03, 3}, {NULL, 0} + + +}; + diff --git a/TC/TC_email_service/TC_Message/uts-email-free-attachment-info.c b/TC/TC_email_service/TC_Message/uts-email-free-attachment-info.c new file mode 100755 index 0000000..e6005a5 --- /dev/null +++ b/TC/TC_email_service/TC_Message/uts-email-free-attachment-info.c @@ -0,0 +1,187 @@ +/* +* Copyright (c) 2012 - 2013 Samsung Electronics, Inc. +* All rights reserved. +* +* This software is a confidential and proprietary information of Samsung +* Electronics, Inc. ("Confidential Information"). 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. +*/ + + +#include "uts-email-free-attachment-info.h" +#include "../TC_Utility/uts-email-dummy-utility.c" + + +sqlite3 *sqlite_emmb; +static int g_accountId; + + +static void startup() +{ + int err_code = EMAIL_ERROR_NONE; + int count = 0; + int i = 0; + email_account_t *pAccount = NULL ; + email_mail_list_item_t *mail_list = NULL; + tet_printf("\n TC startup"); + + if (EMAIL_ERROR_NONE == email_service_begin()) { + tet_infoline("Email service Begin\n"); + if (EMAIL_ERROR_NONE == email_open_db()) { + tet_infoline("Email open DB success\n"); + g_accountId = 0; + /* Check if there are any accounts and Get account id. If there is no account in the db, add new dummy account data to the d */ + err_code = email_get_account_list(&pAccount, &count); + if (EMAIL_ERROR_NONE == err_code) { + /* get the account id from the d */ + g_accountId = pAccount[i].account_id; + email_free_account(&pAccount, count); + tet_printf("g_accountId[%d]\n", g_accountId); + } + else if (EMAIL_ERROR_ACCOUNT_NOT_FOUND == err_code) { + /* Add new dummy account to the db if there is no account in the d */ + tet_printf("Add new account\n"); + g_accountId = uts_Email_Add_Dummy_Account_01(); + tet_printf("g_accountId[%d]\n", g_accountId); + } + else { + tet_printf("email_get_account_list() failed : err_code[%d]\n", err_code); + } + + /* Check if there are any mails and Get mail id of one of them. If there is no mail in the db, add new dummy mail data to the d */ + count = 0; + err_code = uts_Email_Get_Mail_List_03(g_accountId, EMAIL_MAILBOX_TYPE_INBOX, &mail_list, &count, 0); + if (EMAIL_ERROR_NONE == err_code) { + tet_printf("email_get_mail_list() success\n"); + } + else if (EMAIL_ERROR_MAIL_NOT_FOUND == err_code) { + tet_printf("Add new email\n"); + err_code = uts_Email_Add_Dummy_Message_02(); + if (EMAIL_ERROR_NONE == err_code) { /* Make db contain at least one mai */ + tet_printf("uts_Email_Add_Dummy_Message_02() success.\n"); + } + else { + tet_printf("uts_Email_Add_Dummy_Message_02() failed : err_code[%d]\n", err_code); + } + } + else { + tet_printf("Email Get Mail List Failed : err_code[%d]", err_code); + } + } + else + tet_infoline("Email open DB failed\n"); + } + else { + tet_infoline("Email service not started\n"); + } + +} + +static void cleanup() +{ + tet_printf("\n TC End"); + + if (EMAIL_ERROR_NONE == email_close_db()) { + tet_infoline("Email Close DB Success\n"); + if (EMAIL_ERROR_NONE == email_service_end()) + tet_infoline("Email service close Success\n"); + else + tet_infoline("Email service end failed\n"); + } + else + tet_infoline("Email Close DB failed\n"); +} + + + + + + +/*Testcase : uts_Email_Free_Attachment_Info_01 + TestObjective : Free mail attachment + APIs Tested : int email_free_attachment_data(email_attachment_data_t **attachment_data_list, int attachment_data_count) + */ + +static void uts_Email_Free_Attachment_Info_01() +{ + int err_code = EMAIL_ERROR_NONE; + int i = 0; + char att_pos[10]; + email_attachment_data_t *mail_attach_info = NULL; + email_mail_list_item_t *mail_list = NULL; + int count = 0; + email_account_t *account = NULL ; + email_attachment_data_t *test_attachment_data_list = NULL; + int test_attachment_data_count = 0; + + + tet_infoline("uts_Email_Free_Attachment_Info_01 Begin\n"); + + err_code = email_get_account_list(&account, &count); + if (EMAIL_ERROR_NONE != err_code || count < 0) { + tet_printf("Email Get Account List Failed : err_code[%d]\n", err_code); + tet_result(TET_UNRESOLVED); + return; + } + g_accountId = account[i].account_id; + err_code = uts_Email_Get_Mail_List_03(g_accountId, EMAIL_MAILBOX_TYPE_INBOX, &mail_list, &count, 0); + if (EMAIL_ERROR_NONE != err_code || count < 0) { + tet_printf("Email Get Account List Failed : err_code[%d]\n", err_code); + tet_result(TET_UNRESOLVED); + return; + } + for (i = 0 ; i < count ; i++) { + err_code = email_get_attachment_data_list(mail_list[i].mail_id, &test_attachment_data_list, &test_attachment_data_count); + if (EMAIL_ERROR_NONE == err_code) { + if (test_attachment_data_count > 0) { + + if(test_attachment_data_list) + err_code = email_free_attachment_data(&test_attachment_data_list, test_attachment_data_count); + + if (EMAIL_ERROR_NONE == err_code) { + tet_infoline("Email free attachment info : success\n"); + tet_result(TET_PASS); + return; + } + else { + tet_printf("Email free attachment info : Failed err_code[%d]\n", err_code); + tet_result(TET_FAIL); + return; + } + } + } + } + + tet_printf("uts_Email_Free_Attachment_Info_01 End\n"); + tet_result(TET_UNRESOLVED); +} + + +/*Testcase : uts_Email_Free_Attachment_Info_02 + TestObjective : Validate Parameter for Free mail attachment + APIs Tested : int email_free_attachment_data(email_attachment_data_t **attachment_data_list, int attachment_data_count) + */ + +static void uts_Email_Free_Attachment_Info_02() +{ + int err_code = EMAIL_ERROR_NONE; + int attachment_data_count = 0; + + tet_infoline("uts_Email_Free_Attachment_Info_02 Begin\n"); + + err_code = email_free_attachment_data(NULL, attachment_data_count); + if (EMAIL_ERROR_NONE != err_code) { + tet_infoline("Email free attachment info : success\n"); + tet_result(TET_PASS); + return; + } + else { + tet_printf("Email free attachment info : Failed \n"); + tet_result(TET_FAIL); + return; + } + +} + + diff --git a/TC/TC_email_service/TC_Message/uts-email-free-attachment-info.h b/TC/TC_email_service/TC_Message/uts-email-free-attachment-info.h new file mode 100755 index 0000000..fe11d61 --- /dev/null +++ b/TC/TC_email_service/TC_Message/uts-email-free-attachment-info.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2012 - 2013 Samsung Electronics, Co., Ltd. + * All rights reserved. + * + * This software is a confidential and proprietary information of Samsung + * Electronics, Co., Ltd. ("Confidential Information"). 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. + */ + +#include <tet_api.h> + +#include <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <sqlite3.h> +#include "email-api-init.h" +#include "email-api-account.h" +#include "email-api-mail.h" + +static void startup(), cleanup(); +void (*tet_startup) () = startup; +void (*tet_cleanup) () = cleanup; + +static void uts_Email_Free_Attachment_Info_01(void); +static void uts_Email_Free_Attachment_Info_02(void); + + + + + +struct tet_testlist tet_testlist[] = { + { uts_Email_Free_Attachment_Info_01, 1}, { uts_Email_Free_Attachment_Info_02, 2}, {NULL, 0} + + +}; + diff --git a/TC/TC_email_service/TC_Message/uts-email-free-mail-info.c b/TC/TC_email_service/TC_Message/uts-email-free-mail-info.c new file mode 100755 index 0000000..8bb699e --- /dev/null +++ b/TC/TC_email_service/TC_Message/uts-email-free-mail-info.c @@ -0,0 +1,197 @@ +/* +* Copyright (c) 2012 - 2013 Samsung Electronics, Inc. +* All rights reserved. +* +* This software is a confidential and proprietary information of Samsung +* Electronics, Inc. ("Confidential Information"). 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. +*/ + + +#include "uts-email-free-mail-info.h" +#include "../TC_Utility/uts-email-dummy-utility.c" + + +sqlite3 *sqlite_emmb; +static int g_accountId; + + + +static void startup() +{ + int err_code = EMAIL_ERROR_NONE; + int count = 0; + int i = 0; + email_account_t *pAccount = NULL ; + email_mail_list_item_t *mail_list = NULL; + + tet_printf("\n TC startup"); + if (EMAIL_ERROR_NONE == email_service_begin()) { + tet_infoline("Email service Begin\n"); + if (EMAIL_ERROR_NONE == email_open_db()) { + tet_infoline("Email open DB success\n"); + + g_accountId = 0; + /* Check if there are any accounts and Get account id. If there is no account in the db, add new dummy account data to the d */ + err_code = email_get_account_list(&pAccount, &count); + if (EMAIL_ERROR_NONE == err_code) { + /* get the account id from the d */ + g_accountId = pAccount[i].account_id; + email_free_account(&pAccount, count); + tet_printf("g_accountId[%d]\n", g_accountId); + } + else if (EMAIL_ERROR_ACCOUNT_NOT_FOUND == err_code) { + /* Add new dummy account to the db if there is no account in the d */ + tet_printf("Add new account\n"); + g_accountId = uts_Email_Add_Dummy_Account_01(); + tet_printf("g_accountId[%d]\n", g_accountId); + } + else { + tet_printf("email_get_account_list() failed : err_code[%d]\n", err_code); + } + + /* Check if there are any mails and Get mail id of one of them. If there is no mail in the db, add new dummy mail data to the d */ + count = 0; + err_code = uts_Email_Get_Mail_List_03(ALL_ACCOUNT, 0, &mail_list, &count, 0); + if (EMAIL_ERROR_NONE == err_code) { + tet_printf("email_get_mail_list() success\n"); + } + else if (EMAIL_ERROR_MAIL_NOT_FOUND == err_code) { + tet_printf("Add new email\n"); + err_code = uts_Email_Add_Dummy_Message_02(); + if (EMAIL_ERROR_NONE == err_code) { /* Make db contain at least one mai */ + tet_printf("uts_Email_Add_Dummy_Message_02() success.\n"); + } + else { + tet_printf("uts_Email_Add_Dummy_Message_02() failed : err_code[%d]\n", err_code); + } + } + else { + tet_printf("Email Get Mail List Failed : err_code[%d]", err_code); + } + } + else + tet_infoline("Email open DB failed\n"); + } + else { + tet_infoline("Email service not started\n"); + } +} + + +static void cleanup() +{ + tet_printf("\n TC End"); + + if (EMAIL_ERROR_NONE == email_close_db()) { + tet_infoline("Email Close DB Success\n"); + if (EMAIL_ERROR_NONE == email_service_end()) + tet_infoline("Email service close Success\n"); + else + tet_infoline("Email service end failed\n"); + } + else + tet_infoline("Email Close DB failed\n"); +} + + + + + + +/*Testcase : uts_Email_Get_Free_Mail_Info_01 + TestObjective : To Free mail info + APIs Tested : int email_free_mail_data(email_mail_data_t** mail_list, int count) + */ + +static void uts_Email_Free_Mail_Info_01() +{ + int err_code = EMAIL_ERROR_NONE; + int count = 0; + email_mail_data_t *mail_data = NULL; + email_mail_list_item_t *mail_list = NULL; + email_account_t *account = NULL ; + + + tet_infoline("uts_Email_Free_Mail_Info_01 Begin\n"); + + err_code = email_get_account_list(&account, &count); + if (EMAIL_ERROR_NONE == err_code) { + tet_infoline("Email get account list success\n"); + if (count > 0) { + count = 0; + err_code = uts_Email_Get_Mail_List_03(ALL_ACCOUNT, 0, &mail_list, &count, 0); + if (EMAIL_ERROR_NONE == err_code) { + tet_infoline("Email get mail list : success\n"); + if (count > 0) { + err_code = email_get_mail_data(mail_list[0].mail_id, &mail_data); + if (EMAIL_ERROR_NONE == err_code) { + tet_infoline("Email get mail info : success\n"); + err_code = email_free_mail_data(&mail_data, 1); + if (EMAIL_ERROR_NONE == err_code) { + tet_infoline("Email free mail info : success\n"); + tet_result(TET_PASS); + } + else { + tet_printf("Email free mail info : Failed err_code[%d] \n", err_code); + tet_result(TET_FAIL); + } + + } + else { + tet_printf("Email get mail data : Failed err_code[%d] \n", err_code); + tet_result(TET_UNRESOLVED); + } + + } + else { + tet_infoline("No Mails in mailbox\n"); + tet_result(TET_UNRESOLVED); + } + } + else { + tet_printf("Email get mail list : Failed err_code[%d]", err_code); + tet_result(TET_UNRESOLVED); + } + } + else { + tet_infoline("NO email account found : success\n"); + tet_result(TET_UNRESOLVED); + } + } + else { + tet_printf("Email get account list failed : error_code[%d]\n", err_code); + tet_result(TET_UNRESOLVED); + } + +} + + +/*Testcase : uts_Email_Free_Mail_Info_02 + TestObjective : To validate parameter for free mail info + APIs Tested : int email_free_mail_data(email_mail_data_t** mail_list, int count) + */ + +static void uts_Email_Free_Mail_Info_02() +{ + int err_code = EMAIL_ERROR_NONE; + email_mail_data_t *mail_data = NULL; + + tet_infoline("uts_Email_Free_Mail_Info_02 Begin\n"); + + err_code = email_free_mail_data(NULL, 1); + + if (EMAIL_ERROR_NONE != err_code) { + tet_infoline("Email free mail info : success\n"); + tet_result(TET_PASS); + } + else { + tet_printf("Email free mail info : Failed \n"); + tet_result(TET_FAIL); + } + +} + + + diff --git a/TC/TC_email_service/TC_Message/uts-email-free-mail-info.h b/TC/TC_email_service/TC_Message/uts-email-free-mail-info.h new file mode 100755 index 0000000..730cd45 --- /dev/null +++ b/TC/TC_email_service/TC_Message/uts-email-free-mail-info.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2012 - 2013 Samsung Electronics, Co., Ltd. + * All rights reserved. + * + * This software is a confidential and proprietary information of Samsung + * Electronics, Co., Ltd. ("Confidential Information"). 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. + */ + +#include <tet_api.h> + +#include <string.h> +#include <stdlib.h> +#include <sqlite3.h> +#include "email-api-init.h" +#include "email-api-account.h" +#include "email-api-mail.h" + +static void startup(), cleanup(); +void (*tet_startup) () = startup; +void (*tet_cleanup) () = cleanup; + +static void uts_Email_Free_Mail_Info_01(void); +static void uts_Email_Free_Mail_Info_02(void); + + + + + +struct tet_testlist tet_testlist[] = { + { uts_Email_Free_Mail_Info_01, 1}, { uts_Email_Free_Mail_Info_02, 2}, {NULL, 0} + + +}; + diff --git a/TC/TC_email_service/TC_Message/uts-email-free-mail-list.c b/TC/TC_email_service/TC_Message/uts-email-free-mail-list.c new file mode 100755 index 0000000..20f0ecf --- /dev/null +++ b/TC/TC_email_service/TC_Message/uts-email-free-mail-list.c @@ -0,0 +1,161 @@ +/* +* Copyright (c) 2012 - 2013 Samsung Electronics, Inc. +* All rights reserved. +* +* This software is a confidential and proprietary information of Samsung +* Electronics, Inc. ("Confidential Information"). 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. +*/ + + +#include "uts-email-free-mail-list.h" +#include "../TC_Utility/uts-email-dummy-utility.c" + + +sqlite3 *sqlite_emmb; +static int g_accountId; + + + +static void startup() +{ + int err_code = EMAIL_ERROR_NONE; + int count = 0; + int i = 0; + email_account_t *pAccount = NULL ; + email_mail_list_item_t *mail_list = NULL; + + tet_printf("\n TC startup"); + if (EMAIL_ERROR_NONE == email_service_begin()) { + tet_infoline("Email service Begin\n"); + if (EMAIL_ERROR_NONE == email_open_db()) { + tet_infoline("Email open DB success\n"); + + g_accountId = 0; + /* Check if there are any accounts and Get account id. If there is no account in the db, add new dummy account data to the d */ + err_code = email_get_account_list(&pAccount, &count); + if (EMAIL_ERROR_NONE == err_code) { + /* get the account id from the d */ + g_accountId = pAccount[i].account_id; + email_free_account(&pAccount, count); + tet_printf("g_accountId[%d]\n", g_accountId); + } + else if (EMAIL_ERROR_ACCOUNT_NOT_FOUND == err_code) { + /* Add new dummy account to the db if there is no account in the d */ + tet_printf("Add new account\n"); + g_accountId = uts_Email_Add_Dummy_Account_01(); + tet_printf("g_accountId[%d]\n", g_accountId); + } + else { + tet_printf("email_get_account_list() failed : err_code[%d]\n", err_code); + } + + /* Check if there are any mails and Get mail id of one of them. If there is no mail in the db, add new dummy mail data to the d */ + count = 0; + err_code = uts_Email_Get_Mail_List_03(ALL_ACCOUNT, 0, &mail_list, &count, 0); + if (EMAIL_ERROR_NONE == err_code) { + tet_printf("email_get_mail_list() success\n"); + } + else if (EMAIL_ERROR_MAIL_NOT_FOUND == err_code) { + tet_printf("Add new email\n"); + err_code = uts_Email_Add_Dummy_Message_02(); + if (EMAIL_ERROR_NONE == err_code) { /* Make db contain at least one mai */ + tet_printf("uts_Email_Add_Dummy_Message_02() success.\n"); + } + else { + tet_printf("uts_Email_Add_Dummy_Message_02() failed : err_code[%d]\n", err_code); + } + } + else { + tet_printf("Email Get Mail List Failed : err_code[%d]", err_code); + } + } + else + tet_infoline("Email open DB failed\n"); + } + else { + tet_infoline("Email service not started\n"); + } +} + + +static void cleanup() +{ + tet_printf("\n TC End"); + + if (EMAIL_ERROR_NONE == email_close_db()) { + tet_infoline("Email Close DB Success\n"); + if (EMAIL_ERROR_NONE == email_service_end()) + tet_infoline("Email service close Success\n"); + else + tet_infoline("Email service end failed\n"); + } + else + tet_infoline("Email Close DB failed\n"); +} + + + + + + +/*Testcase : uts_Email_Free_Mail_List_01 + TestObjective : To Free the MailList Information + APIs Tested : int email_free_mail_list(email_mail_list_item_t **mail_list, int count) + */ + +static void uts_Email_Free_Mail_List_01() +{ + int err_code = EMAIL_ERROR_NONE; + int count = 0; + email_mail_list_item_t *mail_list = NULL; + + tet_infoline("uts_Email_Free_Mail_List_01\n"); + + err_code = uts_Email_Get_Mail_List_03(ALL_ACCOUNT, 0, &mail_list, &count, 0); + if (EMAIL_ERROR_NONE == err_code) { + +/* err_code = email_free_mail_list(&mail_list , count) */ + free(mail_list); + if (EMAIL_ERROR_NONE == err_code) { + tet_infoline("Email free Mail list Success\n"); + tet_result(TET_PASS); + } + else { + tet_printf("Email free mail list failed : error_code[%d]\n", err_code); + tet_result(TET_FAIL); + } + } + else { + tet_printf("Email get mail list failed : error_code[%d]\n", err_code); + tet_result(TET_UNRESOLVED); + } +} + + +/*Testcase : uts_Email_Free_Mail_List_02 + TestObjective : To validate parameter for mail_list in Free the MailList Information + APIs Tested : int email_free_mail_list(email_mail_list_item_t **mail_list, int count) + */ + +static void uts_Email_Free_Mail_List_02() +{ + int err_code = EMAIL_ERROR_NONE; + int count = 1; + + tet_infoline("uts_Email_Free_Mail_List_02\n"); + + err_code = email_free_mail_list(NULL, count); + if (EMAIL_ERROR_NONE != err_code) { + tet_infoline("Email free mail list Success\n"); + tet_result(TET_PASS); + } + else { + tet_printf("Email free Mail list failed : \n"); + tet_result(TET_FAIL); + } +} + + + diff --git a/TC/TC_email_service/TC_Message/uts-email-free-mail-list.h b/TC/TC_email_service/TC_Message/uts-email-free-mail-list.h new file mode 100755 index 0000000..ef2225f --- /dev/null +++ b/TC/TC_email_service/TC_Message/uts-email-free-mail-list.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2012 - 2013 Samsung Electronics, Co., Ltd. + * All rights reserved. + * + * This software is a confidential and proprietary information of Samsung + * Electronics, Co., Ltd. ("Confidential Information"). 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. + */ + +#include <tet_api.h> + +#include <string.h> +#include <stdlib.h> +#include <sqlite3.h> +#include "email-api-init.h" +#include "email-api-account.h" +#include "email-api-mail.h" + +static void startup(), cleanup(); +void (*tet_startup) () = startup; +void (*tet_cleanup) () = cleanup; + +static void uts_Email_Free_Mail_List_01(void); +static void uts_Email_Free_Mail_List_02(void); + + + + + +struct tet_testlist tet_testlist[] = { + { uts_Email_Free_Mail_List_01, 1}, { uts_Email_Free_Mail_List_02, 2}, {NULL, 0} + +}; + diff --git a/TC/TC_email_service/TC_Message/uts-email-free-mailbox.c b/TC/TC_email_service/TC_Message/uts-email-free-mailbox.c new file mode 100755 index 0000000..9a293ec --- /dev/null +++ b/TC/TC_email_service/TC_Message/uts-email-free-mailbox.c @@ -0,0 +1,168 @@ +/* +* Copyright (c) 2012 - 2013 Samsung Electronics, Inc. +* All rights reserved. +* +* This software is a confidential and proprietary information of Samsung +* Electronics, Inc. ("Confidential Information"). 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. +*/ + + +#include "uts-email-free-mailbox.h" +#include "../TC_Utility/uts-email-dummy-utility.c" + + +sqlite3 *sqlite_emmb; +static int g_accountId; + + + +static void startup() +{ + int err_code = EMAIL_ERROR_NONE; + int count = 0; + int i = 0; + email_account_t *pAccount = NULL ; + email_mail_list_item_t *mail_list = NULL; + + tet_printf("\n TC startup"); + if (EMAIL_ERROR_NONE == email_service_begin()) { + tet_infoline("Email service Begin\n"); + if (EMAIL_ERROR_NONE == email_open_db()) { + tet_infoline("Email open DB success\n"); + + g_accountId = 0; + /* Check if there are any accounts and Get account id. If there is no account in the db, add new dummy account data to the d */ + err_code = email_get_account_list(&pAccount, &count); + if (EMAIL_ERROR_NONE == err_code) { + /* get the account id from the d */ + g_accountId = pAccount[i].account_id; + email_free_account(&pAccount, count); + tet_printf("g_accountId[%d]\n", g_accountId); + } + else if (EMAIL_ERROR_ACCOUNT_NOT_FOUND == err_code) { + /* Add new dummy account to the db if there is no account in the d */ + tet_printf("Add new account\n"); + g_accountId = uts_Email_Add_Dummy_Account_01(); + tet_printf("g_accountId[%d]\n", g_accountId); + } + else { + tet_printf("email_get_account_list() failed : err_code[%d]\n", err_code); + } + + /* Check if there are any mails and Get mail id of one of them. If there is no mail in the db, add new dummy mail data to the d */ + count = 0; + err_code = uts_Email_Get_Mail_List_03(ALL_ACCOUNT, 0, &mail_list, &count, 0); + if (EMAIL_ERROR_NONE == err_code) { + tet_printf("email_get_mail_list() success\n"); + } + else if (EMAIL_ERROR_MAIL_NOT_FOUND == err_code) { + tet_printf("Add new email\n"); + err_code = uts_Email_Add_Dummy_Message_02(); + if (EMAIL_ERROR_NONE == err_code) { /* Make db contain at least one mai */ + tet_printf("uts_Email_Add_Dummy_Message_02() success.\n"); + } + else { + tet_printf("uts_Email_Add_Dummy_Message_02() failed : err_code[%d]\n", err_code); + } + } + else { + tet_printf("Email Get Mail List Failed : err_code[%d]", err_code); + } + } + else + tet_infoline("Email open DB failed\n"); + } + else { + tet_infoline("Email service not started\n"); + } +} + + +static void cleanup() +{ + tet_printf("\n TC End"); + + if (EMAIL_ERROR_NONE == email_close_db()) { + tet_infoline("Email Close DB Success\n"); + if (EMAIL_ERROR_NONE == email_service_end()) + tet_infoline("Email service close Success\n"); + else + tet_infoline("Email service end failed\n"); + } + else + tet_infoline("Email Close DB failed\n"); +} + + + + + + +/*Testcase : uts_Email_Free_Mailbox_01 + TestObjective : Free allocated memory for mailbox information. + APIs Tested : int email_free_mailbox(email_mailbox_t **mailbox_list, int count) + */ + +static void uts_Email_Free_Mailbox_01() +{ + int err_code = EMAIL_ERROR_NONE; + int count = 0; + email_mailbox_t *mbox; + email_account_t *account = NULL ; + + + tet_infoline("utc_Email_Free_Mailbox_01 Begin\n"); + + err_code = email_get_account_list(&account, &count); + if (EMAIL_ERROR_NONE != err_code || count < 0) { + tet_printf("Email Get Account List Failed : err_code[%d]", err_code); + tet_result(TET_UNRESOLVED); + return; + } + err_code = email_get_mailbox_list(account[0].account_id, 1, &mbox, &count); + if (EMAIL_ERROR_NONE != err_code || count < 0) { + tet_printf("Email Get Mailbox List Failed : err_code[%d]", err_code); + tet_result(TET_UNRESOLVED); + return; + + } + err_code = email_free_mailbox(&mbox, count); + if (EMAIL_ERROR_NONE == err_code) { + tet_infoline("Email freeMailbox : success\n"); + tet_result(TET_PASS); + } + else { + tet_printf("Email freet Mailbox : Failed err_code[%d] \n", err_code); + tet_result(TET_FAIL); + } +} + + + +/*Testcase : uts_Email_Free_Mailbox_02 + TestObjective : validate parameter Free allocated memory for mailbox information. + APIs Tested : int email_free_mailbox(email_mailbox_t **mailbox_list, int count) + */ + +static void uts_Email_Free_Mailbox_02() +{ + int err_code = EMAIL_ERROR_NONE; + int count = 1; + + tet_infoline("utc_Email_Free_Mailbox_02 Begin\n"); + + err_code = email_free_mailbox(NULL, count); + if (EMAIL_ERROR_NONE != err_code) { + tet_infoline("Email Free Mailbox : success\n"); + tet_result(TET_PASS); + } + else { + tet_printf("Email Free Mailbox : Failed \n"); + tet_result(TET_FAIL); + } +} + + + diff --git a/TC/TC_email_service/TC_Message/uts-email-free-mailbox.h b/TC/TC_email_service/TC_Message/uts-email-free-mailbox.h new file mode 100755 index 0000000..031aad0 --- /dev/null +++ b/TC/TC_email_service/TC_Message/uts-email-free-mailbox.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2012 - 2013 Samsung Electronics, Co., Ltd. + * All rights reserved. + * + * This software is a confidential and proprietary information of Samsung + * Electronics, Co., Ltd. ("Confidential Information"). 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. + */ + +#include <tet_api.h> + +#include <string.h> +#include <stdlib.h> +#include <sqlite3.h> +#include "email-api-init.h" +#include "email-api-account.h" +#include "email-api-mail.h" + +static void startup(), cleanup(); +void (*tet_startup) () = startup; +void (*tet_cleanup) () = cleanup; + +static void uts_Email_Free_Mailbox_01(void); +static void uts_Email_Free_Mailbox_02(void); + + + + + +struct tet_testlist tet_testlist[] = { + { uts_Email_Free_Mailbox_01, 1}, { uts_Email_Free_Mailbox_02, 2}, {NULL, 0} + + +}; + diff --git a/TC/TC_email_service/TC_Message/uts-email-get-attachment-info.c b/TC/TC_email_service/TC_Message/uts-email-get-attachment-info.c new file mode 100755 index 0000000..e779e4d --- /dev/null +++ b/TC/TC_email_service/TC_Message/uts-email-get-attachment-info.c @@ -0,0 +1,205 @@ +/* +* Copyright (c) 2012 - 2013 Samsung Electronics, Inc. +* All rights reserved. +* +* This software is a confidential and proprietary information of Samsung +* Electronics, Inc. ("Confidential Information"). 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. +*/ + + +#include "uts-email-get-attachment-info.h" +#include "../TC_Utility/uts-email-dummy-utility.c" + + +sqlite3 *sqlite_emmb; +static int g_accountId; + + + +static void startup() +{ + int err_code = EMAIL_ERROR_NONE; + int count = 0; + int i = 0; + email_account_t *pAccount = NULL ; + email_mail_list_item_t *mail_list = NULL; + + tet_printf("\n TC startup"); + if (EMAIL_ERROR_NONE == email_service_begin()) { + tet_infoline("Email service Begin\n"); + if (EMAIL_ERROR_NONE == email_open_db()) { + tet_infoline("Email open DB success\n"); + + g_accountId = 0; + /* Check if there are any accounts and Get account id. If there is no account in the db, add new dummy account data to the d */ + err_code = email_get_account_list(&pAccount, &count); + if (EMAIL_ERROR_NONE == err_code) { + /* get the account id from the d */ + g_accountId = pAccount[i].account_id; + email_free_account(&pAccount, count); + tet_printf("g_accountId[%d]\n", g_accountId); + } + else if (EMAIL_ERROR_ACCOUNT_NOT_FOUND == err_code) { + /* Add new dummy account to the db if there is no account in the d */ + tet_printf("Add new account\n"); + g_accountId = uts_Email_Add_Dummy_Account_01(); + tet_printf("g_accountId[%d]\n", g_accountId); + } + else { + tet_printf("email_get_account_list() failed : err_code[%d]\n", err_code); + } + + /* Check if there are any mails and Get mail id of one of them. If there is no mail in the db, add new dummy mail data to the d */ + count = 0; + err_code = uts_Email_Get_Mail_List_03(ALL_ACCOUNT, 0, &mail_list, &count, 0); + if (EMAIL_ERROR_NONE == err_code) { + tet_printf("email_get_mail_list() success\n"); + } + else if (EMAIL_ERROR_MAIL_NOT_FOUND == err_code) { + tet_printf("Add new email\n"); + err_code = uts_Email_Add_Dummy_Message_02(); + if (EMAIL_ERROR_NONE == err_code) { /* Make db contain at least one mai */ + tet_printf("uts_Email_Add_Dummy_Message_02() success.\n"); + } + else { + tet_printf("uts_Email_Add_Dummy_Message_02() failed : err_code[%d]\n", err_code); + } + } + else { + tet_printf("Email Get Mail List Failed : err_code[%d]", err_code); + } + } + else + tet_infoline("Email open DB failed\n"); + } + else { + tet_infoline("Email service not started\n"); + } +} + + +static void cleanup() +{ + tet_printf("\n TC End"); + + if (EMAIL_ERROR_NONE == email_close_db()) { + tet_infoline("Email Close DB Success\n"); + if (EMAIL_ERROR_NONE == email_service_end()) + tet_infoline("Email service close Success\n"); + else + tet_infoline("Email service end failed\n"); + } + else + tet_infoline("Email Close DB failed\n"); +} + + + + + + +/*Testcase : uts_Email_Get_Attachment_Info_01 + TestObjective : Get a mail attachment + APIs Tested : int email_get_attachment_data_list(int input_mail_id, email_attachment_data_t **output_attachment_data, int *output_attachment_count) + */ + +static void uts_Email_Get_Attachment_Info_01() +{ + int err_code = EMAIL_ERROR_NONE; + int i = 0; + email_attachment_data_t *mail_attach_info = NULL; + email_mail_list_item_t *mail_list = NULL; + int count = 0; + email_account_t *account = NULL ; + + tet_infoline("uts_Email_Get_Attachment_Info_01 Begin\n"); + + err_code = email_get_account_list(&account, &count); + if (EMAIL_ERROR_NONE != err_code || count < 0) { + tet_printf("Email Get Account List Failed : err_code[%d]\n", err_code); + tet_result(TET_UNRESOLVED); + return; + } + g_accountId = account[i].account_id; + + err_code = uts_Email_Get_Mail_List_03(g_accountId, EMAIL_MAILBOX_TYPE_INBOX, &mail_list, &count, 0); + if (EMAIL_ERROR_NONE != err_code || count < 0) { + tet_printf("Email Get Account List Failed : err_code[%d]\n", err_code); + tet_result(TET_UNRESOLVED); + return; + } + for (i ; i < count ; i++) { + if(mail_list[i].attachment_count) { + err_code = email_get_attachment_data_list(mail_list[i].mail_id, &mail_attach_info, &count); + if (EMAIL_ERROR_NONE == err_code) { + tet_infoline("Email get attachment info : success\n"); + tet_result(TET_PASS); + return; + }else { + tet_printf("Email get attachment info : Failed err_code[%d]\n", err_code); + tet_result(TET_FAIL); + return; + } + } + } +} + + +/*Testcase : uts_Email_Get_Attachment_Info_02 + TestObjective : Validate Parameter for mailbox in Get a mail attachment + APIs Tested : int email_get_attachment_data_list(int input_mail_id, email_attachment_data_t **output_attachment_data, int *output_attachment_count) + */ + +static void uts_Email_Get_Attachment_Info_02() +{ + int err_code = EMAIL_ERROR_NONE; + int mail_id = 1; + email_attachment_data_t *mail_attach_info = NULL; + int count = 0; + + tet_infoline("uts_Email_Get_Attachment_Info_02 Begin\n"); + + err_code = email_get_attachment_data_list(0, &mail_attach_info, &count); + if (EMAIL_ERROR_NONE != err_code) { + tet_infoline("Email get attachment info : success\n"); + tet_result(TET_PASS); + return; + } + else { + tet_printf("Email get attachment info : Failed \n"); + tet_result(TET_FAIL); + return; + } + +} + +/*Testcase : uts_Email_Get_Attachment_Info_03 + TestObjective : Validate Parameter for mailbox account_id in Get a mail attachment + APIs Tested : int email_get_attachment_data_list(int input_mail_id, email_attachment_data_t **output_attachment_data, int *output_attachment_count) + */ + +static void uts_Email_Get_Attachment_Info_03() +{ + int err_code = EMAIL_ERROR_NONE; + int mail_id = 1; + email_mailbox_t mbox; + int count = 0; + + tet_infoline("uts_Email_Get_Attachment_Info_03 Begin\n"); + + err_code = email_get_attachment_data_list(1, NULL, &count); + if (EMAIL_ERROR_NONE != err_code) { + tet_infoline("Email get attachment info : success\n"); + tet_result(TET_PASS); + return; + } + else { + tet_printf("Email get attachment info : Failed \n"); + tet_result(TET_FAIL); + return; + } + +} + diff --git a/TC/TC_email_service/TC_Message/uts-email-get-attachment-info.h b/TC/TC_email_service/TC_Message/uts-email-get-attachment-info.h new file mode 100755 index 0000000..fbc680f --- /dev/null +++ b/TC/TC_email_service/TC_Message/uts-email-get-attachment-info.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2012 - 2013 Samsung Electronics, Co., Ltd. + * All rights reserved. + * + * This software is a confidential and proprietary information of Samsung + * Electronics, Co., Ltd. ("Confidential Information"). 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. + */ + +#include <tet_api.h> + +#include <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <sqlite3.h> +#include "email-api-init.h" +#include "email-api-account.h" +#include "email-api-mail.h" + +static void startup(), cleanup(); +void (*tet_startup) () = startup; +void (*tet_cleanup) () = cleanup; + +static void uts_Email_Get_Attachment_Info_01(void); +static void uts_Email_Get_Attachment_Info_02(void); +static void uts_Email_Get_Attachment_Info_03(void); + + + + + +struct tet_testlist tet_testlist[] = { + { uts_Email_Get_Attachment_Info_01, 1}, { uts_Email_Get_Attachment_Info_02, 2}, { uts_Email_Get_Attachment_Info_03, 3}, {NULL, 0} + + +}; + diff --git a/TC/TC_email_service/TC_Message/uts-email-get-disk-space-usage.c b/TC/TC_email_service/TC_Message/uts-email-get-disk-space-usage.c new file mode 100755 index 0000000..0f61f18 --- /dev/null +++ b/TC/TC_email_service/TC_Message/uts-email-get-disk-space-usage.c @@ -0,0 +1,104 @@ +/* +* Copyright (c) 2012 - 2013 Samsung Electronics, Inc. +* All rights reserved. +* +* This software is a confidential and proprietary information of Samsung +* Electronics, Inc. ("Confidential Information"). 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. +*/ + + +#include "uts-email-get-disk-space-usage.h" + + +sqlite3 *sqlite_emmb; + + +static void startup() +{ + tet_printf("\n TC startup"); + + if (EMAIL_ERROR_NONE == email_service_begin()) { + tet_infoline("Email service Begin\n"); + if (EMAIL_ERROR_NONE == email_open_db()) + tet_infoline("Email open DB success\n"); + else + tet_infoline("Email open DB failed\n"); + } + else { + tet_infoline("Email service not started\n"); + } + +} + +static void cleanup() +{ + tet_printf("\n TC End"); + + if (EMAIL_ERROR_NONE == email_close_db()) { + tet_infoline("Email Close DB Success\n"); + if (EMAIL_ERROR_NONE == email_service_end()) + tet_infoline("Email service close Success\n"); + else + tet_infoline("Email service end failed\n"); + } + else + tet_infoline("Email Close DB failed\n"); +} + + + + + + +/*Testcase : uts_Email_Get_Disk_Space_Usage_01 + TestObjective : To get the total disk usage of emails + APIs Tested : int email_get_disk_space_usage(unsigned long *total_size) + */ + +static void uts_Email_Get_Disk_Space_Usage_01() +{ + int err_code = EMAIL_ERROR_NONE; + unsigned long total_size = 0; + + tet_infoline("uts_Email_Get_Disk_Space_Usage_01 Begin\n"); + + err_code = email_get_disk_space_usage(&total_size); + if (EMAIL_ERROR_NONE == err_code) { + tet_infoline("Email Get Disk Space Usage success\n"); + tet_result(TET_PASS); + } + else { + tet_printf("Email Get Disk Space Usage Failed err_code[%d]\n", err_code); + tet_result(TET_FAIL); + } +} + + + +/*Testcase : uts_Email_Get_Disk Space_Usage_02 + TestObjective : To validate parameter for total_size in get disk space usage + APIs Tested : int email_get_disk_space_usage(unsigned long *total_size) + */ + +static void uts_Email_Get_Disk_Space_Usage_02() +{ + int err_code = EMAIL_ERROR_NONE; + + tet_infoline("uts_Email_Get_Disk_Space_Usage_02 Begin\n"); + + err_code = email_get_disk_space_usage(0); + if (EMAIL_ERROR_NONE != err_code) { + tet_infoline("Email Get Disk Space Usage Success\n"); + tet_result(TET_PASS); + } + else { + tet_printf("Email Get Disk Space Usage failed\n"); + tet_result(TET_FAIL); + } + +} + + + diff --git a/TC/TC_email_service/TC_Message/uts-email-get-disk-space-usage.h b/TC/TC_email_service/TC_Message/uts-email-get-disk-space-usage.h new file mode 100755 index 0000000..97911eb --- /dev/null +++ b/TC/TC_email_service/TC_Message/uts-email-get-disk-space-usage.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2012 - 2013 Samsung Electronics, Co., Ltd. + * All rights reserved. + * + * This software is a confidential and proprietary information of Samsung + * Electronics, Co., Ltd. ("Confidential Information"). 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. + */ + +#include <tet_api.h> + +#include <string.h> +#include <stdlib.h> +#include <sqlite3.h> +#include "email-api-init.h" +#include "email-api-account.h" +#include "email-api-mail.h" + +static void startup(), cleanup(); +void (*tet_startup) () = startup; +void (*tet_cleanup) () = cleanup; + +static void uts_Email_Get_Disk_Space_Usage_01(void); +static void uts_Email_Get_Disk_Space_Usage_02(void); + + + + + +struct tet_testlist tet_testlist[] = { + {uts_Email_Get_Disk_Space_Usage_01, 1}, {uts_Email_Get_Disk_Space_Usage_02, 2}, {NULL, 0} + + +}; + diff --git a/TC/TC_email_service/TC_Message/uts-email-get-info.c b/TC/TC_email_service/TC_Message/uts-email-get-info.c new file mode 100755 index 0000000..91f4ca5 --- /dev/null +++ b/TC/TC_email_service/TC_Message/uts-email-get-info.c @@ -0,0 +1,209 @@ +/* +* Copyright (c) 2012 - 2013 Samsung Electronics, Inc. +* All rights reserved. +* +* This software is a confidential and proprietary information of Samsung +* Electronics, Inc. ("Confidential Information"). 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. +*/ + + +#include "uts-email-get-info.h" +#include "../TC_Utility/uts-email-dummy-utility.c" + + +sqlite3 *sqlite_emmb; +static int g_accountId; + + + +static void startup() +{ + int err_code = EMAIL_ERROR_NONE; + int count = 0; + int i = 0; + email_account_t *pAccount = NULL ; + email_mail_list_item_t *mail_list = NULL; + + tet_printf("\n TC startup"); + if (EMAIL_ERROR_NONE == email_service_begin()) { + tet_infoline("Email service Begin\n"); + if (EMAIL_ERROR_NONE == email_open_db()) { + tet_infoline("Email open DB success\n"); + + g_accountId = 0; + /* Check if there are any accounts and Get account id. If there is no account in the db, add new dummy account data to the d */ + err_code = email_get_account_list(&pAccount, &count); + if (EMAIL_ERROR_NONE == err_code) { + /* get the account id from the d */ + g_accountId = pAccount[i].account_id; + email_free_account(&pAccount, count); + tet_printf("g_accountId[%d]\n", g_accountId); + } + else if (EMAIL_ERROR_ACCOUNT_NOT_FOUND == err_code) { + /* Add new dummy account to the db if there is no account in the d */ + tet_printf("Add new account\n"); + g_accountId = uts_Email_Add_Dummy_Account_01(); + tet_printf("g_accountId[%d]\n", g_accountId); + } + else { + tet_printf("email_get_account_list() failed : err_code[%d]\n", err_code); + } + + /* Check if there are any mails and Get mail id of one of them. If there is no mail in the db, add new dummy mail data to the d */ + count = 0; + err_code = uts_Email_Get_Mail_List_03(ALL_ACCOUNT, 0, &mail_list, &count, 0); + if (EMAIL_ERROR_NONE == err_code) { + tet_printf("email_get_mail_list() success\n"); + } + else if (EMAIL_ERROR_MAIL_NOT_FOUND == err_code) { + tet_printf("Add new email\n"); + err_code = uts_Email_Add_Dummy_Message_02(); + if (EMAIL_ERROR_NONE == err_code) { /* Make db contain at least one mai */ + tet_printf("uts_Email_Add_Dummy_Message_02() success.\n"); + } + else { + tet_printf("uts_Email_Add_Dummy_Message_02() failed : err_code[%d]\n", err_code); + } + } + else { + tet_printf("Email Get Mail List Failed : err_code[%d]", err_code); + } + } + else + tet_infoline("Email open DB failed\n"); + } + else { + tet_infoline("Email service not started\n"); + } +} + + +static void cleanup() +{ + tet_printf("\n TC End"); + + if (EMAIL_ERROR_NONE == email_close_db()) { + tet_infoline("Email Close DB Success\n"); + if (EMAIL_ERROR_NONE == email_service_end()) + tet_infoline("Email service close Success\n"); + else + tet_infoline("Email service end failed\n"); + } + else + tet_infoline("Email Close DB failed\n"); +} + + + + + + +/*Testcase : uts_Email_Get_Info_01 + TestObjective : To get mail info + APIs Tested : int email_get_mail_data(int input_mail_id, email_mail_data_t **output_mail_data) + */ + +static void uts_Email_Get_Info_01() +{ + int err_code = EMAIL_ERROR_NONE; + int count = 0; + email_mail_data_t *mail_data = NULL; + email_mail_list_item_t *mail_list = NULL; + email_account_t *account = NULL ; + + tet_infoline("utc_Email_Get_Info_01 Begin\n"); + + err_code = email_get_account_list(&account, &count); + if (EMAIL_ERROR_NONE == err_code) { + tet_infoline("Email get account list success\n"); + if (count > 0) { + g_accountId = account[0].account_id; + count = 0; + err_code = uts_Email_Get_Mail_List_03(g_accountId, EMAIL_MAILBOX_TYPE_INBOX, &mail_list, &count, 0); + if (EMAIL_ERROR_NONE == err_code) { + tet_infoline("Email get mail list : success\n"); + if (count > 0) { + err_code = email_get_mail_data(mail_list[0].mail_id , &mail_data); + if (EMAIL_ERROR_NONE == err_code) { + tet_infoline("Email get mail data : success\n"); + tet_result(TET_PASS); + } + else { + tet_printf("Email get mail data : Failed err_code[%d] \n", err_code); + tet_result(TET_FAIL); + } + + } + else { + tet_infoline("No Mails in mailbox\n"); + tet_result(TET_UNRESOLVED); + } + } + else { + tet_printf("Email get mail list : Failed err_code[%d]", err_code); + tet_result(TET_UNRESOLVED); + } + } + else { + tet_infoline("NO email account found : success\n"); + tet_result(TET_UNRESOLVED); + } + } + else { + tet_printf("Email get account list failed : error_code[%d]\n", err_code); + tet_result(TET_UNRESOLVED); + } +} + + +/*Testcase : uts_Email_Get_Info_02 + TestObjective : To validate parameter for mailbox in get mail info + APIs Tested : int email_get_info(email_mailbox_t *mailbox, int mail_id, email_mail_info_t **info) + */ + +static void uts_Email_Get_Info_02() +{ + int err_code = EMAIL_ERROR_NONE; + int mail_id = -1; + email_mail_data_t *mail_data = NULL; + + tet_infoline("utc_Email_Get_Info_02 Begin\n"); + + err_code = email_get_mail_data(mail_id , &mail_data); + if (EMAIL_ERROR_NONE != err_code) { + tet_infoline("Email get mail data : success\n"); + tet_result(TET_PASS); + } + else { + tet_printf("Email get mail data : Failed \n"); + tet_result(TET_FAIL); + } + +} + + +/*Testcase : uts_Email_Get_Info_03 + TestObjective : To validate parameter for mail_id in get mail info + APIs Tested : int email_get_info(email_mailbox_t *mailbox, int mail_id, email_mail_info_t **info) + */ + +static void uts_Email_Get_Info_03() +{ + int err_code = EMAIL_ERROR_NONE; + + tet_infoline("utc_Email_Get_Info_03 Begin\n"); + + err_code = email_get_mail_data(1 , NULL); + if (EMAIL_ERROR_NONE != err_code) { + tet_infoline("Email get mail info : success\n"); + tet_result(TET_PASS); + } + else { + tet_printf("Email get mail info : Failed \n"); + tet_result(TET_FAIL); + } +} + + diff --git a/TC/TC_email_service/TC_Message/uts-email-get-info.h b/TC/TC_email_service/TC_Message/uts-email-get-info.h new file mode 100755 index 0000000..6f7755e --- /dev/null +++ b/TC/TC_email_service/TC_Message/uts-email-get-info.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2012 - 2013 Samsung Electronics, Co., Ltd. + * All rights reserved. + * + * This software is a confidential and proprietary information of Samsung + * Electronics, Co., Ltd. ("Confidential Information"). 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. + */ + +#include <tet_api.h> + +#include <string.h> +#include <stdlib.h> +#include <sqlite3.h> +#include "email-api-init.h" +#include "email-api-account.h" +#include "email-api-mail.h" + +static void startup(), cleanup(); +void (*tet_startup) () = startup; +void (*tet_cleanup) () = cleanup; + +static void uts_Email_Get_Info_01(void); +static void uts_Email_Get_Info_02(void); +static void uts_Email_Get_Info_03(void); + + + + + +struct tet_testlist tet_testlist[] = { + { uts_Email_Get_Info_01, 1}, { uts_Email_Get_Info_02, 2}, { uts_Email_Get_Info_03, 3}, {NULL, 0} + + +}; + diff --git a/TC/TC_email_service/TC_Message/uts-email-get-mail-list-ex.c b/TC/TC_email_service/TC_Message/uts-email-get-mail-list-ex.c new file mode 100755 index 0000000..e238382 --- /dev/null +++ b/TC/TC_email_service/TC_Message/uts-email-get-mail-list-ex.c @@ -0,0 +1,215 @@ +/* +* Copyright (c) 2012 - 2013 Samsung Electronics, Inc. +* All rights reserved. +* +* This software is a confidential and proprietary information of Samsung +* Electronics, Inc. ("Confidential Information"). 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. +*/ + + +#include "uts-email-get-mail-list-ex.h" +#include "../TC_Utility/uts-email-dummy-utility.c" + + +sqlite3 *sqlite_emmb; +static int g_accountId; + + + +static void startup() +{ + int err_code = EMAIL_ERROR_NONE; + int count = 0; + int i = 0; + email_account_t *pAccount = NULL ; + email_mail_list_item_t *mail_list = NULL; + + tet_printf("\n TC startup"); + if (EMAIL_ERROR_NONE == email_service_begin()) { + tet_infoline("Email service Begin\n"); + if (EMAIL_ERROR_NONE == email_open_db()) { + tet_infoline("Email open DB success\n"); + + g_accountId = 0; + /* Check if there are any accounts and Get account id. If there is no account in the db, add new dummy account data to the d */ + err_code = email_get_account_list(&pAccount, &count); + if (EMAIL_ERROR_NONE == err_code) { + /* get the account id from the d */ + g_accountId = pAccount[i].account_id; + email_free_account(&pAccount, count); + tet_printf("g_accountId[%d]\n", g_accountId); + } + else if (EMAIL_ERROR_ACCOUNT_NOT_FOUND == err_code) { + /* Add new dummy account to the db if there is no account in the d */ + tet_printf("Add new account\n"); + g_accountId = uts_Email_Add_Dummy_Account_01(); + tet_printf("g_accountId[%d]\n", g_accountId); + } + else { + tet_printf("email_get_account_list() failed : err_code[%d]\n", err_code); + } + + /* Check if there are any mails and Get mail id of one of them. If there is no mail in the db, add new dummy mail data to the d */ + count = 0; + err_code = uts_Email_Get_Mail_List_03(ALL_ACCOUNT, 0, &mail_list, &count, 0); + if (EMAIL_ERROR_NONE == err_code) { + tet_printf("email_get_mail_list() success\n"); + } + else if (EMAIL_ERROR_MAIL_NOT_FOUND == err_code) { + tet_printf("Add new email\n"); + err_code = uts_Email_Add_Dummy_Message_02(); + if (EMAIL_ERROR_NONE == err_code) { /* Make db contain at least one mai */ + tet_printf("uts_Email_Add_Dummy_Message_02() success.\n"); + } + else { + tet_printf("uts_Email_Add_Dummy_Message_02() failed : err_code[%d]\n", err_code); + } + } + else { + tet_printf("Email Get Mail List Failed : err_code[%d]", err_code); + } + } + else + tet_infoline("Email open DB failed\n"); + } + else { + tet_infoline("Email service not started\n"); + } +} + + +static void cleanup() +{ + tet_printf("\n TC End"); + + if (EMAIL_ERROR_NONE == email_close_db()) { + tet_infoline("Email Close DB Success\n"); + if (EMAIL_ERROR_NONE == email_service_end()) + tet_infoline("Email service close Success\n"); + else + tet_infoline("Email service end failed\n"); + } + else + tet_infoline("Email Close DB failed\n"); +} + + + + + + +/*Testcase : uts_Email_Get_Mail_List_Ex_01 + TestObjective : Get the Mail List information from DB based on the mailbox mailbox_name + APIs Tested : int email_get_mail_list_ex(email_list_filter_t *input_filter_list, int input_filter_count, email_list_sorting_rule_t *input_sorting_rule_list, + int input_sorting_rule_count, int input_start_index, int input_limit_count, email_mail_list_item_t** output_mail_list, int *output_result_count) + */ + +static void uts_Email_Get_Mail_List_Ex_01() +{ + int err_code = EMAIL_ERROR_NONE; + email_mail_list_item_t *mail_list = NULL; + int count = 0; + int start_index = 0; + int limit_count = 2; + email_list_filter_t *filter_list = NULL; + + tet_infoline("uts_Email_Get_Mail_Ex_01\n"); + + filter_list = malloc(sizeof(email_list_filter_t) * 1); + memset(filter_list, 0 , sizeof(email_list_filter_t) * 1); + + filter_list[0].list_filter_item_type = EMAIL_LIST_FILTER_ITEM_RULE; + filter_list[0].list_filter_item.rule.target_attribute = EMAIL_MAIL_ATTRIBUTE_MAILBOX_TYPE; + filter_list[0].list_filter_item.rule.rule_type = EMAIL_LIST_FILTER_RULE_EQUAL; + filter_list[0].list_filter_item.rule.key_value.integer_type_value = EMAIL_MAILBOX_TYPE_INBOX; + filter_list[0].list_filter_item.rule.case_sensitivity = false; + + err_code = email_get_mail_list_ex(filter_list, 1, NULL, 0, start_index, limit_count, &mail_list , &count); + if (EMAIL_ERROR_NONE == err_code) { + tet_infoline("Email get mail list ex Success\n"); + tet_result(TET_PASS); + } + else { + tet_printf("Email get mail list ex failed : error_code[%d]\n", err_code); + tet_result(TET_FAIL); + } + email_free_list_filter(&filter_list, 1); +} + + +/*Testcase : uts_Email_Get_Mail_List_Ex_02 + TestObjective : Validate parameter for mail_list in Get the Mail List information from DB based on the mailbox mailbox_name + APIs Tested : email_get_mail_list_ex(int account_id , const char *mailbox_mailbox_name, int thread_id, int start_index, int limit_count, email_sort_type_t sorting, + email_mail_list_item_t **mail_list, int *result_count) + */ +static void uts_Email_Get_Mail_List_Ex_02() +{ + int err_code = EMAIL_ERROR_NONE; + email_mail_list_item_t *mail_list = NULL; + int count = 0; + int start_index = 0; + int limit_count = 2; + + tet_infoline("uts_Email_Get_Mail_Ex_02\n"); + + count = 0; + err_code = email_get_mail_list_ex(NULL, 1, NULL, 0, start_index, limit_count, &mail_list , &count); + if (EMAIL_ERROR_NONE != err_code) { + tet_infoline("Email get mail list ex Success\n"); + tet_result(TET_PASS); + } + else { + tet_printf("Email get mail list ex failed : error_code[%d]\n", err_code); + tet_result(TET_FAIL); + } + +} + +/*Testcase : uts_Email_Get_Mail_List_Ex_03 + TestObjective : Validate parameter for result_count in Get the Mail List information from DB based on the mailbox mailbox_name + APIs Tested : email_get_mail_list_ex(int account_id , const char *mailbox_mailbox_name, int thread_id, int start_index, int limit_count, email_sort_type_t sorting, + email_mail_list_item_t **mail_list, int *result_count) + */ + +static void uts_Email_Get_Mail_List_Ex_03() +{ + int err_code = EMAIL_ERROR_NONE; + email_mail_list_item_t *mail_list = NULL; + int count = 0; + int start_index = 0; + int limit_count = 2 ; + email_list_filter_t *filter_list = NULL; + + tet_infoline("uts_Email_Get_Mail_Ex_03\n"); + + + filter_list = malloc(sizeof(email_list_filter_t) * 1); + memset(filter_list, 0 , sizeof(email_list_filter_t) * 1); + + filter_list[0].list_filter_item_type = EMAIL_LIST_FILTER_ITEM_RULE; + filter_list[0].list_filter_item.rule.target_attribute = EMAIL_MAIL_ATTRIBUTE_MAILBOX_TYPE; + filter_list[0].list_filter_item.rule.rule_type = EMAIL_LIST_FILTER_RULE_EQUAL; + filter_list[0].list_filter_item.rule.key_value.integer_type_value = EMAIL_MAILBOX_TYPE_INBOX; + filter_list[0].list_filter_item.rule.case_sensitivity = false; + count = 0; + err_code = email_get_mail_list_ex(filter_list, 1, NULL, 0, start_index, limit_count, &mail_list , 0); + if (EMAIL_ERROR_NONE != err_code) { + tet_infoline("Email get mail list ex Success\n"); + tet_result(TET_PASS); + } + else { + tet_printf("Email get mail list ex failed : error_code[%d]\n", err_code); + tet_result(TET_FAIL); + } + + email_free_list_filter(&filter_list, 1); + +} + + + + + + diff --git a/TC/TC_email_service/TC_Message/uts-email-get-mail-list-ex.h b/TC/TC_email_service/TC_Message/uts-email-get-mail-list-ex.h new file mode 100755 index 0000000..b0169b7 --- /dev/null +++ b/TC/TC_email_service/TC_Message/uts-email-get-mail-list-ex.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2012 - 2013 Samsung Electronics, Co., Ltd. + * All rights reserved. + * + * This software is a confidential and proprietary information of Samsung + * Electronics, Co., Ltd. ("Confidential Information"). 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. + */ + +#include <tet_api.h> + +#include <string.h> +#include <stdlib.h> +#include <sqlite3.h> +#include "email-api-init.h" +#include "email-api-account.h" +#include "email-api-mail.h" + +static void startup(), cleanup(); +void (*tet_startup) () = startup; +void (*tet_cleanup) () = cleanup; + +static void uts_Email_Get_Mail_List_Ex_01(void); +static void uts_Email_Get_Mail_List_Ex_02(void); +static void uts_Email_Get_Mail_List_Ex_03(void); + + + + + + +struct tet_testlist tet_testlist[] = { + {uts_Email_Get_Mail_List_Ex_01, 1}, {uts_Email_Get_Mail_List_Ex_02, 2}, {uts_Email_Get_Mail_List_Ex_03, 3}, {NULL, 0} + + +}; + diff --git a/TC/TC_email_service/TC_Message/uts-email-get-mail-list.h b/TC/TC_email_service/TC_Message/uts-email-get-mail-list.h new file mode 100755 index 0000000..90c1ec4 --- /dev/null +++ b/TC/TC_email_service/TC_Message/uts-email-get-mail-list.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2012 - 2013 Samsung Electronics, Co., Ltd. + * All rights reserved. + * + * This software is a confidential and proprietary information of Samsung + * Electronics, Co., Ltd. ("Confidential Information"). 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. + */ + +#include <tet_api.h> + +#include <string.h> +#include <stdlib.h> +#include <sqlite3.h> +#include "email-api-init.h" +#include "email-api-account.h" +#include "email-api-mail.h" + +static void startup(), cleanup(); +void (*tet_startup) () = startup; +void (*tet_cleanup) () = cleanup; + +static void uts_Email_Get_Mail_List_01(void); +static void uts_Email_Get_Mail_List_02(void); +static void uts_Email_Get_Mail_List_03(void); + + + + + +struct tet_testlist tet_testlist[] = { + {uts_Email_Get_Mail_List_01, 1}, {uts_Email_Get_Mail_List_02, 2}, {uts_Email_Get_Mail_List_03, 3}, {NULL, 0} + + +}; + diff --git a/TC/TC_email_service/TC_Message/uts-email-get-mailbox-list.c b/TC/TC_email_service/TC_Message/uts-email-get-mailbox-list.c new file mode 100755 index 0000000..1dc4a19 --- /dev/null +++ b/TC/TC_email_service/TC_Message/uts-email-get-mailbox-list.c @@ -0,0 +1,235 @@ +/* +* Copyright (c) 2012 - 2013 Samsung Electronics, Inc. +* All rights reserved. +* +* This software is a confidential and proprietary information of Samsung +* Electronics, Inc. ("Confidential Information"). 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. +*/ + + +#include "uts-email-get-mailbox-list.h" +#include "../TC_Utility/uts-email-dummy-utility.c" + + +sqlite3 *sqlite_emmb; +static int g_accountId; + + + +static void startup() +{ + int err_code = EMAIL_ERROR_NONE; + int count = 0; + int i = 0; + email_account_t *pAccount = NULL ; + email_mail_list_item_t *mail_list = NULL; + + tet_printf("\n TC startup"); + if (EMAIL_ERROR_NONE == email_service_begin()) { + tet_infoline("Email service Begin\n"); + if (EMAIL_ERROR_NONE == email_open_db()) { + tet_infoline("Email open DB success\n"); + + g_accountId = 0; + /* Check if there are any accounts and Get account id. If there is no account in the db, add new dummy account data to the d */ + err_code = email_get_account_list(&pAccount, &count); + if (EMAIL_ERROR_NONE == err_code) { + /* get the account id from the d */ + g_accountId = pAccount[i].account_id; + email_free_account(&pAccount, count); + tet_printf("g_accountId[%d]\n", g_accountId); + } + else if (EMAIL_ERROR_ACCOUNT_NOT_FOUND == err_code) { + /* Add new dummy account to the db if there is no account in the d */ + tet_printf("Add new account\n"); + g_accountId = uts_Email_Add_Dummy_Account_01(); + tet_printf("g_accountId[%d]\n", g_accountId); + } + else { + tet_printf("email_get_account_list() failed : err_code[%d]\n", err_code); + } + + /* Check if there are any mails and Get mail id of one of them. If there is no mail in the db, add new dummy mail data to the d */ + count = 0; + err_code = uts_Email_Get_Mail_List_03(ALL_ACCOUNT, 0, &mail_list, &count, 0); + if (EMAIL_ERROR_NONE == err_code) { + tet_printf("email_get_mail_list() success\n"); + } + else if (EMAIL_ERROR_MAIL_NOT_FOUND == err_code) { + tet_printf("Add new email\n"); + err_code = uts_Email_Add_Dummy_Message_02(); + if (EMAIL_ERROR_NONE == err_code) { /* Make db contain at least one mai */ + tet_printf("uts_Email_Add_Dummy_Message_02() success.\n"); + } + else { + tet_printf("uts_Email_Add_Dummy_Message_02() failed : err_code[%d]\n", err_code); + } + } + else { + tet_printf("Email Get Mail List Failed : err_code[%d]", err_code); + } + } + else + tet_infoline("Email open DB failed\n"); + } + else { + tet_infoline("Email service not started\n"); + } +} + + +static void cleanup() +{ + tet_printf("\n TC End"); + + if (EMAIL_ERROR_NONE == email_close_db()) { + tet_infoline("Email Close DB Success\n"); + if (EMAIL_ERROR_NONE == email_service_end()) + tet_infoline("Email service close Success\n"); + else + tet_infoline("Email service end failed\n"); + } + else + tet_infoline("Email Close DB failed\n"); +} + + + + + + +/*Testcase : uts_Email_Get_Mailbox_List_01 + TestObjective : To Get all mailboxes from account. + APIs Tested : int email_get_mailbox_list(int account_id, email_mailbox_t **mailbox_list, int *count) + */ + +static void uts_Email_Get_Mailbox_List_01() +{ + int err_code = EMAIL_ERROR_NONE; + int count = 0; + email_mailbox_t *mbox; + int mailbox_sync_type = 1; + email_account_t *account = NULL ; + + + tet_infoline("utc_Email_Get_Mailbox_List_01 Begin\n"); + + err_code = email_get_account_list(&account, &count); + if (EMAIL_ERROR_NONE != err_code || count < 0) { + tet_printf("Email Get Account List Failed : err_code[%d]", err_code); + tet_result(TET_UNRESOLVED); + return; + } + err_code = email_get_mailbox_list(account[0].account_id, mailbox_sync_type, &mbox, &count); + if (EMAIL_ERROR_NONE == err_code) { + tet_infoline("Email Get Mailbox List : success\n"); + tet_result(TET_PASS); + } + else { + tet_printf("Email Get Mailbox List : Failed err_code[%d] \n", err_code); + tet_result(TET_FAIL); + } +} + + +/*Testcase : uts_Email_Get_Mailbox_List_02 + TestObjective : To validate parameter for account_id in Get all mailboxes from account. + APIs Tested : int email_get_mailbox_list(int account_id, email_mailbox_t **mailbox_list, int *count) + */ + +static void uts_Email_Get_Mailbox_List_02() +{ + int err_code = EMAIL_ERROR_NONE; + int count = 0; + email_mailbox_t *mbox; + int account_id = -1 ; + + tet_infoline("utc_Email_Get_Mailbox_List_02 Begin\n"); + + err_code = email_get_mailbox_list(account_id, 1, &mbox, &count); + if (EMAIL_ERROR_NONE != err_code) { + tet_infoline("Email Get Mailbox List : success\n"); + tet_result(TET_PASS); + } + else { + tet_printf("Email Get Mailbox List : Failed \n"); + tet_result(TET_FAIL); + } +} + + +/*Testcase : uts_Email_Get_Mailbox_List_03 + TestObjective : To validate parameter for mailbox_list in Get all mailboxes from account. + APIs Tested : int email_get_mailbox_list(int account_id, email_mailbox_t **mailbox_list, int *count) + */ + +static void uts_Email_Get_Mailbox_List_03() +{ + int err_code = EMAIL_ERROR_NONE; + int count = 0; + email_account_t *account = NULL ; + + + tet_infoline("utc_Email_Get_Mailbox_List_03 Begin\n"); + + err_code = email_get_account_list(&account, &count); + if (EMAIL_ERROR_NONE != err_code || count < 0) { + tet_printf("Email Get Account List Failed : err_code[%d]", err_code); + tet_result(TET_UNRESOLVED); + return; + } + err_code = email_get_mailbox_list(account[0].account_id, 1, NULL, &count); + if (EMAIL_ERROR_NONE != err_code) { + tet_infoline("Email Get Mailbox List : success\n"); + tet_result(TET_PASS); + } + else { + tet_printf("Email Get Mailbox List : Failed \n"); + tet_result(TET_FAIL); + } +} + + + +/*Testcase : uts_Email_Get_Mailbox_List_04 + TestObjective : To validate parameter for Get all mailboxes from account. + APIs Tested : int email_get_mailbox_list(int account_id, email_mailbox_t **mailbox_list, int *count) + */ + +static void uts_Email_Get_Mailbox_List_04() +{ + int err_code = EMAIL_ERROR_NONE; + int count = 0; + email_mailbox_t *mbox; + email_account_t *account = NULL ; + + + tet_infoline("utc_Email_Get_Mailbox_List_04 Begin\n"); + + err_code = email_get_account_list(&account, &count); + if (EMAIL_ERROR_NONE != err_code || count < 0) { + tet_printf("Email Get Account List Failed : err_code[%d]", err_code); + tet_result(TET_UNRESOLVED); + return; + } + err_code = email_get_mailbox_list(account[0].account_id, 1, &mbox, 0); + if (EMAIL_ERROR_NONE != err_code) { + tet_infoline("Email Get Mailbox List : success\n"); + tet_result(TET_PASS); + } + else { + tet_printf("Email Get Mailbox List : Failed \n"); + tet_result(TET_FAIL); + } +} + + + + + + + + + diff --git a/TC/TC_email_service/TC_Message/uts-email-get-mailbox-list.h b/TC/TC_email_service/TC_Message/uts-email-get-mailbox-list.h new file mode 100755 index 0000000..686eb2e --- /dev/null +++ b/TC/TC_email_service/TC_Message/uts-email-get-mailbox-list.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2012 - 2013 Samsung Electronics, Co., Ltd. + * All rights reserved. + * + * This software is a confidential and proprietary information of Samsung + * Electronics, Co., Ltd. ("Confidential Information"). 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. + */ + +#include <tet_api.h> + +#include <string.h> +#include <stdlib.h> +#include <sqlite3.h> +#include "email-api-init.h" +#include "email-api-account.h" +#include "email-api-mail.h" + +static void startup(), cleanup(); +void (*tet_startup) () = startup; +void (*tet_cleanup) () = cleanup; + +static void uts_Email_Get_Mailbox_List_01(void); +static void uts_Email_Get_Mailbox_List_02(void); +static void uts_Email_Get_Mailbox_List_03(void); +static void uts_Email_Get_Mailbox_List_04(void); + + + + + +struct tet_testlist tet_testlist[] = { + { uts_Email_Get_Mailbox_List_01, 1}, { uts_Email_Get_Mailbox_List_02, 2}, { uts_Email_Get_Mailbox_List_03, 3}, { uts_Email_Get_Mailbox_List_04, 4}, {NULL, 0} + + +}; + diff --git a/TC/TC_email_service/TC_Message/uts-email-get-max-mail-count.c b/TC/TC_email_service/TC_Message/uts-email-get-max-mail-count.c new file mode 100755 index 0000000..2cea12c --- /dev/null +++ b/TC/TC_email_service/TC_Message/uts-email-get-max-mail-count.c @@ -0,0 +1,102 @@ +/* +* Copyright (c) 2012 - 2013 Samsung Electronics, Inc. +* All rights reserved. +* +* This software is a confidential and proprietary information of Samsung +* Electronics, Inc. ("Confidential Information"). 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. +*/ + + +#include "uts-email-get-max-mail-count.h" + + +sqlite3 *sqlite_emmb; + + +static void startup() +{ + tet_printf("\n TC startup"); + + if (EMAIL_ERROR_NONE == email_service_begin()) { + tet_infoline("Email service Begin\n"); + if (EMAIL_ERROR_NONE == email_open_db()) + tet_infoline("Email open DB success\n"); + else + tet_infoline("Email open DB failed\n"); + } + else { + tet_infoline("Email service not started\n"); + } + +} + +static void cleanup() +{ + tet_printf("\n TC End"); + + if (EMAIL_ERROR_NONE == email_close_db()) { + tet_infoline("Email Close DB Success\n"); + if (EMAIL_ERROR_NONE == email_service_end()) + tet_infoline("Email service close Success\n"); + else + tet_infoline("Email service end failed\n"); + } + else + tet_infoline("Email Close DB failed\n"); +} + + + + + + +/*Testcase : uts_Email_Get_Max_Mail_Count_01 + TestObjective : To get the maximum count of emails + APIs Tested : int email_get_max_mail_count(int *Count) + */ + +static void uts_Email_Get_Max_Mail_Count_01() +{ + int err_code = EMAIL_ERROR_NONE; + int count = 0; + + tet_infoline("uts_Email_Get_Max_Mail_Count_01 Begin\n"); + + err_code = email_get_max_mail_count(&count); + if (EMAIL_ERROR_NONE == err_code) { + tet_infoline("Email Get Max Mail Count success\n"); + tet_result(TET_PASS); + } + else { + tet_printf("Email Get Max Mail Count Failed err_code[%d]\n", err_code); + tet_result(TET_FAIL); + } +} + + +/*Testcase : uts_Email_Get_Max_Mail_Count_02 + TestObjective : validate parameter + APIs Tested : int email_get_max_mail_count(int *Count) + */ + +static void uts_Email_Get_Max_Mail_Count_02() +{ + int err_code = EMAIL_ERROR_NONE; + + tet_infoline("uts_Email_Get_Max_Mail_Count_01 Begin\n"); + + err_code = email_get_max_mail_count(NULL); + if (EMAIL_ERROR_NONE != err_code) { + tet_infoline("Email Get Max Mail Count success\n"); + tet_result(TET_PASS); + } + else { + tet_printf("Email Get Max Mail Count Failed err_code[%d]\n", err_code); + tet_result(TET_FAIL); + } +} + + + diff --git a/TC/TC_email_service/TC_Message/uts-email-get-max-mail-count.h b/TC/TC_email_service/TC_Message/uts-email-get-max-mail-count.h new file mode 100755 index 0000000..eadcbf4 --- /dev/null +++ b/TC/TC_email_service/TC_Message/uts-email-get-max-mail-count.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2012 - 2013 Samsung Electronics, Co., Ltd. + * All rights reserved. + * + * This software is a confidential and proprietary information of Samsung + * Electronics, Co., Ltd. ("Confidential Information"). 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. + */ + +#include <tet_api.h> + +#include <string.h> +#include <stdlib.h> +#include <sqlite3.h> +#include "email-api-init.h" +#include "email-api-account.h" +#include "email-api-mail.h" + +static void startup(), cleanup(); +void (*tet_startup) () = startup; +void (*tet_cleanup) () = cleanup; + +static void uts_Email_Get_Max_Mail_Count_01(void); +static void uts_Email_Get_Max_Mail_Count_02(void); + + + + + +struct tet_testlist tet_testlist[] = { + { uts_Email_Get_Max_Mail_Count_01, 1}, { uts_Email_Get_Max_Mail_Count_02, 2}, {NULL, 0} + + +}; + diff --git a/TC/TC_email_service/TC_Message/uts-email-get-thread-information.h b/TC/TC_email_service/TC_Message/uts-email-get-thread-information.h new file mode 100755 index 0000000..14fc932 --- /dev/null +++ b/TC/TC_email_service/TC_Message/uts-email-get-thread-information.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2012 - 2013 Samsung Electronics, Co., Ltd. + * All rights reserved. + * + * This software is a confidential and proprietary information of Samsung + * Electronics, Co., Ltd. ("Confidential Information"). 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. + */ + +#include <tet_api.h> + +#include <string.h> +#include <stdlib.h> +#include <sqlite3.h> +#include "email-api-init.h" +#include "email-api-account.h" +#include "email-api-mail.h" + +static void startup(), cleanup(); +void (*tet_startup) () = startup; +void (*tet_cleanup) () = cleanup; + +static void uts_Email_Get_Thread_Information_01(void); +static void uts_Email_Get_Thread_Information_02(void); + + + + +struct tet_testlist tet_testlist[] = { + { uts_Email_Get_Thread_Information_01, 1}, { uts_Email_Get_Thread_Information_02, 2}, {NULL, 0} + + +}; + diff --git a/TC/TC_email_service/TC_Message/uts-email-move-all-mails-to-folder.c b/TC/TC_email_service/TC_Message/uts-email-move-all-mails-to-folder.c new file mode 100755 index 0000000..ac2ee5d --- /dev/null +++ b/TC/TC_email_service/TC_Message/uts-email-move-all-mails-to-folder.c @@ -0,0 +1,249 @@ +/* +* Copyright (c) 2012 - 2013 Samsung Electronics, Inc. +* All rights reserved. +* +* This software is a confidential and proprietary information of Samsung +* Electronics, Inc. ("Confidential Information"). 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. +*/ + + +#include "uts-email-move-all-mails-to-folder.h" +#include "../TC_Utility/uts-email-dummy-utility.c" + + +sqlite3 *sqlite_emmb; +static int g_accountId; + + + +static void startup() +{ + int err_code = EMAIL_ERROR_NONE; + int count = 0; + int i = 0; + email_account_t *pAccount = NULL ; + email_mail_list_item_t *mail_list = NULL; + + tet_printf("\n TC startup"); + if (EMAIL_ERROR_NONE == email_service_begin()) { + tet_infoline("Email service Begin\n"); + if (EMAIL_ERROR_NONE == email_open_db()) { + tet_infoline("Email open DB success\n"); + + g_accountId = 0; + /* Check if there are any accounts and Get account id. If there is no account in the db, add new dummy account data to the d */ + err_code = email_get_account_list(&pAccount, &count); + if (EMAIL_ERROR_NONE == err_code) { + /* get the account id from the d */ + g_accountId = pAccount[i].account_id; + email_free_account(&pAccount, count); + tet_printf("g_accountId[%d]\n", g_accountId); + } + else if (EMAIL_ERROR_ACCOUNT_NOT_FOUND == err_code) { + /* Add new dummy account to the db if there is no account in the d */ + tet_printf("Add new account\n"); + g_accountId = uts_Email_Add_Dummy_Account_01(); + tet_printf("g_accountId[%d]\n", g_accountId); + } + else { + tet_printf("email_get_account_list() failed : err_code[%d]\n", err_code); + } + + /* Check if there are any mails and Get mail id of one of them. If there is no mail in the db, add new dummy mail data to the d */ + count = 0; + err_code = uts_Email_Get_Mail_List_03(g_accountId, EMAIL_MAILBOX_TYPE_INBOX, &mail_list, &count, 0); + if (EMAIL_ERROR_NONE == err_code) { + tet_printf("email_get_mail_list() success\n"); + } + else if (EMAIL_ERROR_MAIL_NOT_FOUND == err_code) { + tet_printf("Add new email\n"); + + err_code = uts_Email_Add_Dummy_Message_02(); + if (EMAIL_ERROR_NONE == err_code) { /* Make db contain at least one mai */ + tet_printf("uts_Email_Add_Dummy_Message_02() success.\n"); + } + else { + tet_printf("uts_Email_Add_Dummy_Message_02() failed : err_code[%d]\n", err_code); + } + } + else { + tet_printf("Email Get Mail List Failed : err_code[%d]", err_code); + } + } + else + tet_infoline("Email open DB failed\n"); + } + else { + tet_infoline("Email service not started\n"); + } +} + + +static void cleanup() +{ + tet_printf("\n TC End"); + if (EMAIL_ERROR_NONE == email_close_db()) { + tet_infoline("Email Close DB Success\n"); + if (EMAIL_ERROR_NONE == email_service_end()) + tet_infoline("Email service close Success\n"); + else + tet_infoline("Email service end failed\n"); + } + else + tet_infoline("Email Close DB failed\n"); +} + + + + + +/*Testcase : uts_Email_Move_All_Mails_To_Folder_01 + TestObjective : To move all mails to a mailbox + APIs Tested : int email_move_all_mails_to_mailbox(int input_source_mailbox_id, int input_target_mailbox_id) + + */ + +static void uts_Email_Move_All_Mails_To_Folder_01() +{ + int err_code = EMAIL_ERROR_NONE; + + email_mailbox_t *src_mailbox = NULL; + email_mailbox_t *new_mailbox = NULL; + email_account_t *account = NULL; + int count = 0; + + tet_infoline("uts_Email_Move_All_Mails_To_Folder_01 Begin\n"); + if (!email_get_account_list(&account, &count) || NULL == account || count <= 0) { + tet_printf("Email Move All Mails To mailbox failed in account list fetch\n"); + tet_result(TET_UNRESOLVED); + return; + } + + err_code = email_get_mailbox_by_mailbox_type(account[0].account_id, EMAIL_MAILBOX_TYPE_INBOX, &src_mailbox); + if(err_code != EMAIL_ERROR_NONE) { + tet_printf("email_get_mailbox_by_mailbox_type failed in uts_Email_Move_All_Mails_To_Folder_01\n"); + tet_result(TET_UNRESOLVED); + return; + } + err_code = email_get_mailbox_by_mailbox_type(account[0].account_id, EMAIL_MAILBOX_TYPE_TRASH, &new_mailbox); + if(err_code != EMAIL_ERROR_NONE) { + tet_printf("email_get_mailbox_by_mailbox_type failed in uts_Email_Move_All_Mails_To_Folder_01\n"); + tet_result(TET_UNRESOLVED); + return; + } + + err_code = email_move_all_mails_to_mailbox(src_mailbox->mailbox_id, new_mailbox->mailbox_id); + if (EMAIL_ERROR_NONE == err_code) { + tet_printf("Email Move All Mails To mailbox success\n"); + tet_result(TET_PASS); + } + else { + + tet_printf("Email Move All Mails To mailbox failed : error_code[%d]\n", err_code); + tet_result(TET_FAIL); + } + + if (account && count > 0) { + email_free_account(&account, count); + } + + if (src_mailbox) { + email_free_mailbox(&src_mailbox, 1); + src_mailbox = NULL; + } + if (new_mailbox) { + email_free_mailbox(&new_mailbox, 1); + new_mailbox = NULL; + } +} + + +/*Testcase : uts_Email_Move_All_Mails_To_Folder_02 + TestObjective : To validate parameter for all mail move to mailbox + APIs Tested : int email_move_all_mails_to_mailbox(int input_source_mailbox_id, int input_target_mailbox_id) + + */ +static void uts_Email_Move_All_Mails_To_Folder_02() +{ + int err_code = EMAIL_ERROR_NONE; + + int src_mailbox_id = 0; /* src_mailbox is 0 */ + email_mailbox_t *new_mailbox = NULL; + email_account_t *account = NULL; + int count = 0; + + tet_infoline("uts_Email_Move_All_Mails_To_Folder_02 Begin\n"); + if (!email_get_account_list(&account, &count) || NULL == account || count <= 0) { + tet_printf("Email Move All Mails To mailbox failed in account list fetch\n"); + tet_result(TET_UNRESOLVED); + return; + } + email_get_mailbox_by_mailbox_type(account[0].account_id, EMAIL_MAILBOX_TYPE_TRASH, &new_mailbox); + + err_code = email_move_all_mails_to_mailbox(src_mailbox_id, new_mailbox->mailbox_id); + if (EMAIL_ERROR_NONE != err_code) { + tet_printf("Email Move All Mails To mailbox success\n"); + tet_result(TET_PASS); + } + else { + + tet_printf("Email Move All Mails To mailbox failed : error_code[%d]\n", err_code); + tet_result(TET_FAIL); + } + + if (account && count > 0) { + email_free_account(&account, count); + } + if (new_mailbox) { + email_free_mailbox(&new_mailbox, 1); + new_mailbox = NULL; + } + +} + +/*Testcase : uts_Email_Move_All_Mails_To_Folder_03 + TestObjective : To validate parameter for all mail move to mailbox + APIs Tested : int email_move_all_mails_to_mailbox(int input_source_mailbox_id, int input_target_mailbox_id) + + */ +static void uts_Email_Move_All_Mails_To_Folder_03() +{ + + int err_code = EMAIL_ERROR_NONE; + + email_mailbox_t *src_mailbox = NULL; + int new_mailbox_id = 0; /* Destination mailbox is 0 */ + email_account_t *account = NULL; + int count = 0; + + tet_infoline("uts_Email_Move_All_Mails_To_Folder_03 Begin\n"); + if (!email_get_account_list(&account, &count) || NULL == account || count <= 0) { + tet_printf("Email Move All Mails To mailbox failed in account list fetch\n"); + tet_result(TET_UNRESOLVED); + return; + } + email_get_mailbox_by_mailbox_type(account[0].account_id, EMAIL_MAILBOX_TYPE_INBOX, &src_mailbox); + + err_code = email_move_all_mails_to_mailbox(src_mailbox->mailbox_id, new_mailbox_id); + if (EMAIL_ERROR_NONE != err_code) { + tet_printf("Email Move All Mails To mailbox success\n"); + tet_result(TET_PASS); + } + else { + + tet_printf("Email Move All Mails To mailbox failed : error_code[%d]\n", err_code); + tet_result(TET_FAIL); + } + + if (account && count > 0) { + email_free_account(&account, count); + } + if (src_mailbox) { + email_free_mailbox(&src_mailbox, 1); + src_mailbox = NULL; + } +} + + diff --git a/TC/TC_email_service/TC_Message/uts-email-move-all-mails-to-folder.h b/TC/TC_email_service/TC_Message/uts-email-move-all-mails-to-folder.h new file mode 100755 index 0000000..bbf0098 --- /dev/null +++ b/TC/TC_email_service/TC_Message/uts-email-move-all-mails-to-folder.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2012 - 2013 Samsung Electronics, Co., Ltd. + * All rights reserved. + * + * This software is a confidential and proprietary information of Samsung + * Electronics, Co., Ltd. ("Confidential Information"). 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. + */ + +#include <tet_api.h> + +#include <string.h> +#include <stdlib.h> +#include <sqlite3.h> +#include "email-api-init.h" +#include "email-api-mail.h" + + + +static void startup(), cleanup(); +void (*tet_startup) () = startup; +void (*tet_cleanup) () = cleanup; + +static void uts_Email_Move_All_Mails_To_Folder_01(void); +static void uts_Email_Move_All_Mails_To_Folder_02(void); +static void uts_Email_Move_All_Mails_To_Folder_03(void); + + + + + + +struct tet_testlist tet_testlist[] = { + { uts_Email_Move_All_Mails_To_Folder_01, 1}, { uts_Email_Move_All_Mails_To_Folder_02, 2}, { uts_Email_Move_All_Mails_To_Folder_03, 3}, {NULL, 0} + +}; diff --git a/TC/TC_email_service/TC_Message/uts-email-move-mail-to-folder.c b/TC/TC_email_service/TC_Message/uts-email-move-mail-to-folder.c new file mode 100755 index 0000000..23f26ae --- /dev/null +++ b/TC/TC_email_service/TC_Message/uts-email-move-mail-to-folder.c @@ -0,0 +1,264 @@ +/* +* Copyright (c) 2012 - 2013 Samsung Electronics, Inc. +* All rights reserved. +* +* This software is a confidential and proprietary information of Samsung +* Electronics, Inc. ("Confidential Information"). 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. +*/ + + +#include "uts-email-move-mail-to-folder.h" +#include "../TC_Utility/uts-email-dummy-utility.c" + + +sqlite3 *sqlite_emmb; +static int g_accountId; + + + +static void startup() +{ + int err_code = EMAIL_ERROR_NONE; + int count = 0; + int i = 0; + email_account_t *pAccount = NULL ; + email_mail_list_item_t *mail_list = NULL; + + tet_printf("\n TC startup"); + if (EMAIL_ERROR_NONE == email_service_begin()) { + tet_infoline("Email service Begin\n"); + if (EMAIL_ERROR_NONE == email_open_db()) { + tet_infoline("Email open DB success\n"); + + g_accountId = 0; + /* Check if there are any accounts and Get account id. If there is no account in the db, add new dummy account data to the d */ + err_code = email_get_account_list(&pAccount, &count); + if (EMAIL_ERROR_NONE == err_code) { + /* get the account id from the d */ + g_accountId = pAccount[i].account_id; + email_free_account(&pAccount, count); + tet_printf("g_accountId[%d]\n", g_accountId); + } + else if (EMAIL_ERROR_ACCOUNT_NOT_FOUND == err_code) { + /* Add new dummy account to the db if there is no account in the d */ + tet_printf("Add new account\n"); + g_accountId = uts_Email_Add_Dummy_Account_01(); + tet_printf("g_accountId[%d]\n", g_accountId); + } + else { + tet_printf("email_get_account_list() failed : err_code[%d]\n", err_code); + } + + /* Check if there are any mails and Get mail id of one of them. If there is no mail in the db, add new dummy mail data to the d */ + count = 0; + err_code = uts_Email_Get_Mail_List_03(ALL_ACCOUNT, 0, &mail_list, &count, 0); + if (EMAIL_ERROR_NONE == err_code) { + tet_printf("email_get_mail_list() success\n"); + } + else if (EMAIL_ERROR_MAIL_NOT_FOUND == err_code) { + tet_printf("Add new email\n"); + + err_code = uts_Email_Add_Dummy_Message_02(); + if (EMAIL_ERROR_NONE == err_code) { /* Make db contain at least one mai */ + tet_printf("uts_Email_Add_Dummy_Message_02() success.\n"); + } + else { + tet_printf("uts_Email_Add_Dummy_Message_02() failed : err_code[%d]\n", err_code); + } + } + else { + tet_printf("Email Get Mail List Failed : err_code[%d]", err_code); + } + } + else + tet_infoline("Email open DB failed\n"); + } + else { + tet_infoline("Email service not started\n"); + } +} + + +static void cleanup() +{ + tet_printf("\n TC End"); + if (EMAIL_ERROR_NONE == email_close_db()) { + tet_infoline("Email Close DB Success\n"); + if (EMAIL_ERROR_NONE == email_service_end()) + tet_infoline("Email service close Success\n"); + else + tet_infoline("Email service end failed\n"); + } + else + tet_infoline("Email Close DB failed\n"); +} + + + + + +/*Testcase : uts_Email_Move_Mail_To_Folder_01 + TestObjective : To move mails to a mailbox + APIs Tested : int email_move_mail_to_mailbox(int *mail_ids, int num, int input_target_mailbox_id) + */ + +static void uts_Email_Move_Mail_To_Folder_01() +{ + int err_code = EMAIL_ERROR_NONE; + int mail_ids[] = {1, 2}; + int num = 0; + int new_mailbox_id = 0; + int count = 0; + email_mailbox_t mbox; + email_mail_list_item_t *mail_list = NULL; + int mailbox_type = EMAIL_MAILBOX_TYPE_TRASH; + email_mailbox_t *pMailbox = NULL; + + tet_infoline("uts_Email_Move_Mail_To_Folder_01 Begin\n"); + + if (g_accountId <= 0) { + tet_infoline("g_accountId is invalid\n"); + tet_result(TET_UNRESOLVED); + } + + count = 0; + err_code = uts_Email_Get_Mail_List_03(g_accountId, 0, &mail_list, &count, 0); + if (EMAIL_ERROR_NONE != err_code || count < 0) { + tet_printf("uts_Email_Get_Mail_List_03 Failed : err_code[%d]", err_code); + tet_result(TET_UNRESOLVED); + return; + } + + err_code = email_get_mailbox_by_mailbox_type(g_accountId , mailbox_type, &pMailbox); + if (EMAIL_ERROR_NONE != err_code) { + tet_printf("Email get mailbox by mailbox type failed : error_code[%d]\n", err_code); + tet_result(TET_UNRESOLVED); + } + + mail_ids[0] = mail_list[0].mail_id; + num = 1; + new_mailbox_id = pMailbox->mailbox_id; + + tet_printf("New mailbox : new_mailbox_id[%d]\n", new_mailbox_id); + + err_code = email_move_mail_to_mailbox(mail_ids, num, new_mailbox_id); + if (EMAIL_ERROR_NONE == err_code) { + tet_printf("Email Move Mail To mailbox success\n"); + tet_result(TET_PASS); + } + else { + + tet_printf("Email Move Mail To mailbox failed : error_code[%d]\n", err_code); + tet_result(TET_FAIL); + } + if (pMailbox) { + email_free_mailbox(&pMailbox, 1); + pMailbox = NULL; + } + +} + + +/*Testcase : uts_Email_Move_Mail_To_Folder_02 + TestObjective : To validate parameter for mail move to mailbox + APIs Tested : int email_move_mail_to_mailbox(int *mail_ids, int num, int input_target_mailbox_id) + */ +static void uts_Email_Move_Mail_To_Folder_02() +{ + int err_code = EMAIL_ERROR_NONE; + int *mail_ids = NULL; /* mail ids initialized to NULL*/ + int num = 2; + email_mailbox_t *pMailbox = NULL; + int count = 0; + + tet_infoline("uts_Email_Move_Mail_To_Folder_02 Begin\n"); + + err_code = email_get_mailbox_by_mailbox_type(g_accountId , EMAIL_MAILBOX_TYPE_TRASH, &pMailbox); + if (EMAIL_ERROR_NONE != err_code) { + tet_printf("Email get mailbox by mailbox type failed : error_code[%d]\n", err_code); + tet_result(TET_UNRESOLVED); + } + + err_code = email_move_mail_to_mailbox(mail_ids, num, pMailbox->mailbox_id); + if (EMAIL_ERROR_NONE != err_code) { + tet_printf("Email Move Mail To mailbox success\n"); + tet_result(TET_PASS); + } + else { + + tet_printf("Email Move Mail To mailbox failed : error_code[%d]\n", err_code); + tet_result(TET_FAIL); + } + if (pMailbox) { + email_free_mailbox(&pMailbox, 1); + pMailbox = NULL; + } +} + +/*Testcase : uts_Email_Move_Mail_To_Folder_03 + TestObjective : To validate parameter for mail move to mailbox + APIs Tested : int email_move_mail_to_mailbox(int *mail_ids, int num, int input_target_mailbox_id) + */ +static void uts_Email_Move_Mail_To_Folder_03() +{ + int err_code = EMAIL_ERROR_NONE; + int mail_ids[] = {1, 2}; + int num = -1; /* Boundary condition test */ + email_mailbox_t *pMailbox = NULL; + int count = 0; + + tet_infoline("uts_Email_Move_Mail_To_Folder_03 Begin\n"); + + err_code = email_get_mailbox_by_mailbox_type(g_accountId , EMAIL_MAILBOX_TYPE_TRASH, &pMailbox); + if (EMAIL_ERROR_NONE != err_code) { + tet_printf("Email get mailbox by mailbox type failed : error_code[%d]\n", err_code); + tet_result(TET_UNRESOLVED); + } + + err_code = email_move_mail_to_mailbox(mail_ids, num, pMailbox->mailbox_id); + if (EMAIL_ERROR_NONE != err_code) { + tet_printf("Email Move Mail To mailbox success\n"); + tet_result(TET_PASS); + } + else { + + tet_printf("Email Move Mail To mailbox failed : error_code[%d]\n", err_code); + tet_result(TET_FAIL); + } + if (pMailbox) { + email_free_mailbox(&pMailbox, 1); + pMailbox = NULL; + } +} + +/*Testcase : uts_Email_Move_Mail_To_Folder_04 + TestObjective : To validate parameter for mail move to mailbox + APIs Tested : int email_move_mail_to_mailbox(int *mail_ids, int num, int input_target_mailbox_id) + */ +static void uts_Email_Move_Mail_To_Folder_04() + +{ + int err_code = EMAIL_ERROR_NONE; + int mail_ids[] = {1, 2}; + int num = 2; + int input_target_mailbox_id = 0; /* input_target_mailbox_id as 0 */ + + tet_infoline("uts_Email_Move_Mail_To_Folder_04 Begin\n"); + + err_code = email_move_mail_to_mailbox(mail_ids, num, input_target_mailbox_id); + if (EMAIL_ERROR_NONE != err_code) { + tet_printf("Email Move Mail To mailbox success\n"); + tet_result(TET_PASS); + } + else { + + tet_printf("Email Move Mail To mailbox failed : error_code[%d]\n", err_code); + tet_result(TET_FAIL); + } + +} + + + diff --git a/TC/TC_email_service/TC_Message/uts-email-move-mail-to-folder.h b/TC/TC_email_service/TC_Message/uts-email-move-mail-to-folder.h new file mode 100755 index 0000000..4ec3c9b --- /dev/null +++ b/TC/TC_email_service/TC_Message/uts-email-move-mail-to-folder.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2012 - 2013 Samsung Electronics, Co., Ltd. + * All rights reserved. + * + * This software is a confidential and proprietary information of Samsung + * Electronics, Co., Ltd. ("Confidential Information"). 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. + */ + +#include <tet_api.h> + +#include <string.h> +#include <stdlib.h> +#include <sqlite3.h> +#include "email-api-init.h" +#include "email-api-mail.h" + + + +static void startup(), cleanup(); +void (*tet_startup) () = startup; +void (*tet_cleanup) () = cleanup; + +static void uts_Email_Move_Mail_To_Folder_01(void); +static void uts_Email_Move_Mail_To_Folder_02(void); +static void uts_Email_Move_Mail_To_Folder_03(void); +static void uts_Email_Move_Mail_To_Folder_04(void); + + + + + + +struct tet_testlist tet_testlist[] = { + { uts_Email_Move_Mail_To_Folder_01, 1}, { uts_Email_Move_Mail_To_Folder_02, 2}, { uts_Email_Move_Mail_To_Folder_03, 3}, { uts_Email_Move_Mail_To_Folder_04, 4}, {NULL, 0} + +}; diff --git a/TC/TC_email_service/TC_Message/uts-email-send-retry.c b/TC/TC_email_service/TC_Message/uts-email-send-retry.c new file mode 100755 index 0000000..791ae72 --- /dev/null +++ b/TC/TC_email_service/TC_Message/uts-email-send-retry.c @@ -0,0 +1,119 @@ +/* +* Copyright (c) 2012 - 2013 Samsung Electronics, Inc. +* All rights reserved. +* +* This software is a confidential and proprietary information of Samsung +* Electronics, Inc. ("Confidential Information"). 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. +*/ + + +#include "uts-email-send-retry.h" +#include "../TC_Utility/uts-email-dummy-utility.c" + + +sqlite3 *sqlite_emmb; + + +static void startup() +{ + tet_printf("\n TC startup"); + + if (EMAIL_ERROR_NONE == email_service_begin()) { + tet_infoline("Email service Begin\n"); + if (EMAIL_ERROR_NONE == email_open_db()) + tet_infoline("Email open DB success\n"); + else + tet_infoline("Email open DB failed\n"); + } + else { + tet_infoline("Email service not started\n"); + } + +} + +static void cleanup() +{ + tet_printf("\n TC End"); + + if (EMAIL_ERROR_NONE == email_close_db()) { + tet_infoline("Email Close DB Success\n"); + if (EMAIL_ERROR_NONE == email_service_end()) + tet_infoline("Email service close Success\n"); + else + tet_infoline("Email service end failed\n"); + } + else + tet_infoline("Email Close DB failed\n"); +} + + + + + + +/*Testcase : uts_Email_Send_Retry_01 + TestObjective : To Retry mail send + APIs Tested : int email_retry_sending_mail(int mail_id, int timeout_in_sec) + */ + +static void uts_Email_Send_Retry_01() +{ + int err_code = EMAIL_ERROR_NONE; + int count = 0; + int i = 0; + email_mail_list_item_t *mail_list = NULL; + + tet_infoline("uts_Email_Send_Retry_01\n"); + + err_code = uts_Email_Get_Mail_List_03(ALL_ACCOUNT, 0, &mail_list, &count, 0); + if (EMAIL_ERROR_NONE == err_code) { + if (count > 0) { + + err_code = email_retry_sending_mail(mail_list[i].mail_id , 3); + if (EMAIL_ERROR_NONE == err_code) { + tet_infoline("Email Send Retry Success\n"); + tet_result(TET_PASS); + } + else { + tet_printf("Email Send Retry failed : error_code[%d]\n", err_code); + tet_result(TET_FAIL); + } + } + else { + tet_infoline("No mail found\n"); + tet_result(TET_UNRESOLVED); + } + } + else { + tet_printf("Email get mail list failed : error_code[%d]\n", err_code); + tet_result(TET_UNRESOLVED); + } +} + + +/*Testcase : uts_Email_Send_Retry_02 + TestObjective : To validate parameter for mail_id in Retry mail send + APIs Tested : int email_retry_sending_mail(int mail_id, int timeout_in_sec) + */ + +static void uts_Email_Send_Retry_02() +{ + int err_code = EMAIL_ERROR_NONE; + + tet_infoline("uts_Email_Send_Retry_02\n"); + + err_code = email_retry_sending_mail(-1, 2); + if (EMAIL_ERROR_NONE != err_code) { + tet_infoline("Email Send Retry Success\n"); + tet_result(TET_PASS); + } + else { + tet_printf("Email Send Retry failed : \n"); + tet_result(TET_FAIL); + } +} + + + diff --git a/TC/TC_email_service/TC_Message/uts-email-send-retry.h b/TC/TC_email_service/TC_Message/uts-email-send-retry.h new file mode 100755 index 0000000..5f447ca --- /dev/null +++ b/TC/TC_email_service/TC_Message/uts-email-send-retry.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2012 - 2013 Samsung Electronics, Co., Ltd. + * All rights reserved. + * + * This software is a confidential and proprietary information of Samsung + * Electronics, Co., Ltd. ("Confidential Information"). 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. + */ + +#include <tet_api.h> + +#include <string.h> +#include <stdlib.h> +#include <sqlite3.h> +#include "email-api-init.h" +#include "email-api-account.h" +#include "email-api-mail.h" + +static void startup(), cleanup(); +void (*tet_startup) () = startup; +void (*tet_cleanup) () = cleanup; + +static void uts_Email_Send_Retry_01(void); +static void uts_Email_Send_Retry_02(void); + + + + + +struct tet_testlist tet_testlist[] = { + { uts_Email_Send_Retry_01, 1}, { uts_Email_Send_Retry_02, 2}, {NULL, 0} + + +}; + diff --git a/TC/TC_email_service/TC_Message/uts-email-update-message.c b/TC/TC_email_service/TC_Message/uts-email-update-message.c new file mode 100755 index 0000000..2fc65d9 --- /dev/null +++ b/TC/TC_email_service/TC_Message/uts-email-update-message.c @@ -0,0 +1,199 @@ +/* +* Copyright (c) 2012 - 2013 Samsung Electronics, Inc. +* All rights reserved. +* +* This software is a confidential and proprietary information of Samsung +* Electronics, Inc. ("Confidential Information"). 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. +*/ + + +#include "uts-email-update-message.h" +#include "../TC_Utility/uts-email-dummy-utility.c" + + + +sqlite3 *sqlite_emmb; +static int g_accountId; + + + +static void startup() +{ + int err_code = EMAIL_ERROR_NONE; + int count = 0; + int i = 0; + email_account_t *pAccount = NULL ; + email_mail_list_item_t *mail_list = NULL; + + tet_printf("\n TC startup"); + if (EMAIL_ERROR_NONE == email_service_begin()) { + tet_infoline("Email service Begin\n"); + if (EMAIL_ERROR_NONE == email_open_db()) { + tet_infoline("Email open DB success\n"); + + g_accountId = 0; + /* Check if there are any accounts and Get account id. If there is no account in the db, add new dummy account data to the d */ + err_code = email_get_account_list(&pAccount, &count); + if (EMAIL_ERROR_NONE == err_code) { + /* get the account id from the d */ + g_accountId = pAccount[i].account_id; + email_free_account(&pAccount, count); + tet_printf("g_accountId[%d]\n", g_accountId); + } + else if (EMAIL_ERROR_ACCOUNT_NOT_FOUND == err_code) { + /* Add new dummy account to the db if there is no account in the d */ + tet_printf("Add new account\n"); + g_accountId = uts_Email_Add_Dummy_Account_01(); + tet_printf("g_accountId[%d]\n", g_accountId); + } + else { + tet_printf("email_get_account_list() failed : err_code[%d]\n", err_code); + } + + /* Check if there are any mails and Get mail id of one of them. If there is no mail in the db, add new dummy mail data to the d */ + count = 0; + err_code = uts_Email_Get_Mail_List_03(ALL_ACCOUNT, 0, &mail_list, &count, 0); + if (EMAIL_ERROR_NONE == err_code) { + tet_printf("email_get_mail_list() success\n"); + } + else if (EMAIL_ERROR_MAIL_NOT_FOUND == err_code) { + tet_printf("Add new email\n"); + err_code = uts_Email_Add_Dummy_Message_02(); + if (EMAIL_ERROR_NONE == err_code) { /* Make db contain at least one mai */ + tet_printf("uts_Email_Add_Dummy_Message_02() success.\n"); + } + else { + tet_printf("uts_Email_Add_Dummy_Message_02() failed : err_code[%d]\n", err_code); + } + } + else { + tet_printf("Email Get Mail List Failed : err_code[%d]", err_code); + } + } + else + tet_infoline("Email open DB failed\n"); + } + else { + tet_infoline("Email service not started\n"); + } +} + + +static void cleanup() +{ + tet_printf("\n TC End"); + + if (EMAIL_ERROR_NONE == email_close_db()) { + tet_infoline("Email Close DB Success\n"); + if (EMAIL_ERROR_NONE == email_service_end()) + tet_infoline("Email service close Success\n"); + else + tet_infoline("Email service end failed\n"); + } + else + tet_infoline("Email Close DB failed\n"); +} + + + + + + + +/*Testcase : uts_Email_Update_Message_01 + TestObjective : To update message + APIs Tested : int email_update_mail(email_mail_data_t *input_mail_data, email_attachment_data_t *input_attachment_data_list, int input_attachment_count, email_meeting_request_t* input_meeting_request, int input_from_eas); + */ + +static void uts_Email_Update_Message_01() +{ + int err_code = EMAIL_ERROR_NONE; + int handle; + int count = 0; + email_account_t *account = NULL ; + email_mail_list_item_t *mail_list = NULL; + email_mail_data_t *mail_data = NULL; + email_attachment_data_t *test_attachment_data_list = NULL; + email_meeting_request_t *meeting_req = NULL; + int test_attachment_data_count = 0; + + tet_infoline("uts_Email_Update_Message_01 Begin\n"); + + + err_code = email_get_account_list(&account, &count); + if (EMAIL_ERROR_NONE == err_code) { + tet_infoline("Email get account list success\n"); + if (count > 0) { + count = 0; + err_code = uts_Email_Get_Mail_List_03(account[0].account_id, EMAIL_MAILBOX_TYPE_INBOX, &mail_list, &count, 0); + if (EMAIL_ERROR_NONE == err_code) { + tet_infoline("Email get mail list : success\n"); + if (count > 0) { + err_code = email_get_mail_data(mail_list[0].mail_id , &mail_data); + if (EMAIL_ERROR_NONE == err_code) { + tet_infoline("Email get mail success\n"); + + mail_data->full_address_cc = strdup("samsungtest09@gmail.com"); + + err_code = email_update_mail(mail_data, NULL, 0, NULL, 0); + if (EMAIL_ERROR_NONE == err_code) { + tet_infoline("email_update_mail : success\n"); + tet_result(TET_PASS); + } + else { + tet_printf("email_update_mail failed : error_code[%d]\n", err_code); + tet_result(TET_FAIL); + } + } + else { + tet_printf("Email get mail failed : error_code[%d]\n", err_code); + tet_result(TET_UNRESOLVED); + } + } + } + else { + tet_printf("Email get mail list failed : error_code[%d]\n", err_code); + tet_result(TET_UNRESOLVED); + } +// email_free_mail_list(&mail_list, count) + free(mail_list); + } + else { + tet_infoline("NO email account found : success\n"); + tet_result(TET_UNRESOLVED); + } + } + else { + tet_printf("Email get account list failed : error_code[%d]\n", err_code); + tet_result(TET_UNRESOLVED); + } + +} + + +/*Testcase : uts_Email_Update_Message_02 + TestObjective : To validate parameter for mail_id in update message + APIs Tested : int email_update_mail(email_mail_data_t *input_mail_data, email_attachment_data_t *input_attachment_data_list, int input_attachment_count, email_meeting_request_t* input_meeting_request, int input_from_eas); + */ + +static void uts_Email_Update_Message_02() +{ + int err_code = EMAIL_ERROR_NONE; + int mail_id = 0; + + tet_infoline("uts_Email_Update_Message_02 Begin\n"); + + err_code = email_update_mail(NULL, NULL, 0, NULL, 0); + + if (EMAIL_ERROR_NONE != err_code) { + tet_infoline("Email update message : success\n"); + tet_result(TET_PASS); + } + else { + tet_infoline("Email update message : failed \n"); + tet_result(TET_FAIL); + } +} + diff --git a/TC/TC_email_service/TC_Message/uts-email-update-message.h b/TC/TC_email_service/TC_Message/uts-email-update-message.h new file mode 100755 index 0000000..64fd8b8 --- /dev/null +++ b/TC/TC_email_service/TC_Message/uts-email-update-message.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2012 - 2013 Samsung Electronics, Co., Ltd. + * All rights reserved. + * + * This software is a confidential and proprietary information of Samsung + * Electronics, Co., Ltd. ("Confidential Information"). 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. + */ + +#include <tet_api.h> + +#include <string.h> +#include <stdlib.h> +#include <sqlite3.h> +#include "email-api-init.h" +#include "email-api-account.h" +#include "email-api-mail.h" + +static void startup(), cleanup(); +void (*tet_startup) () = startup; +void (*tet_cleanup) () = cleanup; + +static void uts_Email_Update_Message_01(void); +static void uts_Email_Update_Message_02(void); + + + + + +struct tet_testlist tet_testlist[] = { + { uts_Email_Update_Message_01, 1}, { uts_Email_Update_Message_02, 2}, {NULL, 0} + + +}; + diff --git a/TC/TC_email_service/TC_Network/Makefile b/TC/TC_email_service/TC_Network/Makefile new file mode 100755 index 0000000..2f3c575 --- /dev/null +++ b/TC/TC_email_service/TC_Network/Makefile @@ -0,0 +1,56 @@ +################################################### +# add your TestCase List Here +# +# e.g., +# TC1 = utc_frameworkName_apiName_func +# TC2 = utc_ApplicationLib_recurGetDayOfWeek_func +TARGETS = uts_email_send_mail \ + uts_email_send_saved \ + uts_email_sync_header \ + uts_email_sync_header_for_all_account \ + uts_email_download_body \ + uts_email_download_attachment \ + uts_email_get_imap_folder_list \ + uts_email_cancel_job \ + uts_email_get_network_status \ + uts_email_get_pending_job \ + +################################################### +# add your Package Config Info Here +# +# e.g., +# PKGS=calendar +PKGS= email-service + +LIBS = `pkg-config --libs $(PKGS)` +LIBS += `pkg-config --libs glib-2.0` +LIBS +=$(TET_ROOT)/lib/tet3/tcm_s.o +LIBS +=-L$(TET_ROOT)/lib/tet3 -ltcm_s +LIBS +=-L$(TET_ROOT)/lib/tet3 -lapi_s + +INCS = -I. `pkg-config --cflags $(PKGS)` +INCS += -I. `pkg-config --cflags glib-2.0` +INCS += -I$(TET_ROOT)/inc/tet3 +INCS += -I$(TET_SUITE_ROOT)/TC_email_service/TC_Utility + +UTIL_SRC = $(TET_SUITE_ROOT)/TC_email_service/TC_Utility/uts-email-dummy-utility.c +UTIL_SRC += $(TET_SUITE_ROOT)/TC_email_service/TC_Utility/uts-email-real-utility.c + +CFLAGS = $(INCS) +CFLAGS += -D_TETWARE_MODE +LDFLAGS = $(LIBS) + +################################################### +# Modify here +# depending on the Test Case you want to build +# +# e.g., +# TCLIST = $(TC1) $(TC2) +all : $(TARGETS) + +$(TARGETS) : %: %.c + $(CC) -o $@ $< $(CFLAGS) $(LDFLAGS) + +clean : + rm -rf $(TARGETS) + diff --git a/TC/TC_email_service/TC_Network/tslist b/TC/TC_email_service/TC_Network/tslist new file mode 100755 index 0000000..072193d --- /dev/null +++ b/TC/TC_email_service/TC_Network/tslist @@ -0,0 +1,10 @@ +uts_email_get_network_status +uts_email_get_pending_job +uts_email_send_mail +uts_email_send_saved +uts_email_sync_header +uts_email_sync_header_for_all_account +uts_email_download_body +uts_email_download_attachment +uts_email_get_imap_folder_list +uts_email_cancel_job diff --git a/TC/TC_email_service/TC_Network/uts_email_activate_pdp.c b/TC/TC_email_service/TC_Network/uts_email_activate_pdp.c new file mode 100755 index 0000000..fa3c016 --- /dev/null +++ b/TC/TC_email_service/TC_Network/uts_email_activate_pdp.c @@ -0,0 +1,144 @@ +/* +* Copyright (c) 2012 - 2013 Samsung Electronics, Inc. +* All rights reserved. +* +* This software is a confidential and proprietary information of Samsung +* Electronics, Inc. ("Confidential Information"). 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. +*/ + +/*************************************** +* add your header file here +* e.g., +* #include "uts_ApplicationLib_recurGetDayOfWeek_func.h" +***************************************/ +#include "uts_email_activate_pdp.h" +#include "../TC_Utility/uts-email-real-utility.c" + + +sqlite3 *sqlite_emmb; +int g_accountId; + +static void startup() +{ + int err_code = EMAIL_ERROR_NONE; + int count = 0; + int i = 0; + email_account_t *pAccount = NULL ; + + tet_printf("\n TC startup"); + + if (EMAIL_ERROR_NONE == email_service_begin()) { + tet_infoline("Email service Begin\n"); + if (EMAIL_ERROR_NONE == email_open_db()) { + tet_infoline("Email open DB success\n"); + err_code = email_get_account_list(&pAccount, &count); + if (!count) { + g_accountId = uts_Email_Add_Real_Account_01(); + } + else + g_accountId = pAccount[i].account_id; + email_free_account(&pAccount, count); + + } + else + tet_infoline("Email open DB failed\n"); + } + else + tet_infoline("Email service not started\n"); + +} + + +static void cleanup() +{ + tet_printf("\n TC End"); + + if (EMAIL_ERROR_NONE == email_close_db()) { + tet_infoline("Email Close DB Success\n"); + if (EMAIL_ERROR_NONE == email_service_end()) + tet_infoline("Email service close Success\n"); + else + tet_infoline("Email service end failed\n"); + } + else + tet_infoline("Email Close DB failed\n"); +} + + + + +/*************************************** +* add your Test Cases +* e.g., +* static void uts_ApplicationLib_recurGetDayOfWeek_01() +* { +* int ret; +* +* ret = target_api(); +* if (ret == 1) +* tet_result(TET_PASS); +* else +* tet_result(TET_FAIL); +* } +* +* static void uts_ApplicationLib_recurGetDayOfWeek_02() +* { +* code.. +* condition1 +* tet_result(TET_PASS); +* condition2 +* tet_result(TET_FAIL); +* } +* +***************************************/ + + +/*Testcase : uts_Email_Activate_Pdp_01 + TestObjective : To activate pdp + APIs Tested : int email_activate_pdp(int thread_type) + */ + +static void uts_Email_Activate_Pdp_01() +{ + int err_code = EMAIL_ERROR_NONE; + int thread_type = 1; + + tet_infoline("uts_Email_Activate_Pdp_01 Begin\n"); + + err_code = email_activate_pdp(thread_type); + if (EMAIL_ERROR_NONE == err_code) { + tet_printf("Email activate pdp : success\n"); + tet_result(TET_PASS); + } + else { + tet_printf("Email activate pdp failed : error_code[%d]\n", err_code); + tet_result(TET_FAIL); + } +} + + +/*Testcase : uts_Email_Activate_Pdp_02 + TestObjective : To validate parameter for activate pdp + APIs Tested : int email_activate_pdp(int thread_type) + */ + +static void uts_Email_Activate_Pdp_02() +{ + int err_code = EMAIL_ERROR_NONE; + int thread_type = -1; + + tet_infoline("uts_Email_Activate_pdp_01 Begin\n"); + + err_code = email_activate_pdp(thread_type); + if (EMAIL_ERROR_NONE != err_code) { + tet_printf("Email activate pdp : success\n"); + tet_result(TET_PASS); + } + else { + tet_printf("Email activate pdp failed : \n"); + tet_result(TET_FAIL); + } +} + diff --git a/TC/TC_email_service/TC_Network/uts_email_activate_pdp.h b/TC/TC_email_service/TC_Network/uts_email_activate_pdp.h new file mode 100755 index 0000000..2fbb3ba --- /dev/null +++ b/TC/TC_email_service/TC_Network/uts_email_activate_pdp.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2012 - 2013 Samsung Electronics, Co., Ltd. + * All rights reserved. + * + * This software is a confidential and proprietary information of Samsung + * Electronics, Co., Ltd. ("Confidential Information"). 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. + */ + +#include <tet_api.h> + +#include <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <sqlite3.h> +#include "email-api-init.h" +#include "email-api-account.h" +#include "email-api-mailbox.h" + +static void startup(), cleanup(); +void (*tet_startup) () = startup; +void (*tet_cleanup) () = cleanup; + + +static void uts_Email_Activate_Pdp_01(void); +static void uts_Email_Activate_Pdp_02(void); + + + + + +struct tet_testlist tet_testlist[] = { {uts_Email_Activate_Pdp_01, 1}, {uts_Email_Activate_Pdp_02, 2}, {NULL, 0} +}; diff --git a/TC/TC_email_service/TC_Network/uts_email_cancel_job.c b/TC/TC_email_service/TC_Network/uts_email_cancel_job.c new file mode 100755 index 0000000..e16c965 --- /dev/null +++ b/TC/TC_email_service/TC_Network/uts_email_cancel_job.c @@ -0,0 +1,144 @@ +/* +* Copyright (c) 2012 - 2013 Samsung Electronics, Inc. +* All rights reserved. +* +* This software is a confidential and proprietary information of Samsung +* Electronics, Inc. ("Confidential Information"). 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. +*/ + +/*************************************** +* add your header file here +* e.g., +* #include "uts_ApplicationLib_recurGetDayOfWeek_func.h" +***************************************/ +#include "uts_email_cancel_job.h" +#include "../TC_Utility/uts-email-real-utility.c" + + +sqlite3 *sqlite_emmb; + +static void startup() +{ + tet_printf("\n TC startup"); + + if (EMAIL_ERROR_NONE == email_service_begin()) { + tet_infoline("Email service Begin\n"); + if (EMAIL_ERROR_NONE == email_open_db()) + tet_infoline("Email open DB success\n"); + else + tet_infoline("Email open DB failed\n"); + } + else + tet_infoline("Email service not started\n"); + +} + +static void cleanup() +{ + tet_printf("\n TC End"); + + if (EMAIL_ERROR_NONE == email_close_db()) { + tet_infoline("Email Close DB Success\n"); + if (EMAIL_ERROR_NONE == email_service_end()) + tet_infoline("Email service close Success\n"); + else + tet_infoline("Email service end failed\n"); + } + else + tet_infoline("Email Close DB failed\n"); +} + + + + +/*************************************** +* add your Test Cases +* e.g., +* static void uts_ApplicationLib_recurGetDayOfWeek_01() +* { +* int ret; +* +* ret = target_api(); +* if (ret == 1) +* tet_result(TET_PASS); +* else +* tet_result(TET_FAIL); +* } +* +* static void uts_ApplicationLib_recurGetDayOfWeek_02() +* { +* code.. +* condition1 +* tet_result(TET_PASS); +* condition2 +* tet_result(TET_FAIL); +* } +* +***************************************/ + + +/*Testcase : uts_email_cancel_job_01 + TestObjective : To cancel the ongoing job + APIs Tested : int email_cancel_job(int account_id, int handle) + */ + +static void uts_Email_Cancel_Job_01() +{ + int err_code = EMAIL_ERROR_NONE; + int handle = 0; + + tet_infoline("uts_Email_cancel_job_01 Begin\n"); + + err_code = email_sync_header_for_all_account(&handle); + if (EMAIL_ERROR_NONE == err_code) { + tet_infoline("Email sync mail header for all account : success\n"); + err_code = email_cancel_job(0, handle); + if (EMAIL_ERROR_NONE == err_code) { + tet_printf("Email cancel job : success\n"); + tet_result(TET_PASS); + } + else { + tet_printf("Email cancel job failed : error_code[%d]\n", err_code); + tet_result(TET_FAIL); + } + } + else { + tet_printf("Email sync mail header for all account failed : error_code[%d]\n", err_code); + tet_result(TET_UNRESOLVED); + } +} + + +/*Testcase : uts_email_cancel_job_02 + TestObjective : To validate the parameter for account id in cancel the ongoing job + APIs Tested : int email_cancel_job(int account_id, int handle) + */ +static void uts_Email_Cancel_Job_02() +{ + int err_code = EMAIL_ERROR_NONE; + int account_id = -1; + int handle; + + tet_infoline("uts_Email_cancel_job_10 Begin\n"); + + err_code = email_sync_header_for_all_account(&handle); + if (EMAIL_ERROR_NONE == err_code) { + tet_infoline("Email sync mail header for all account : success\n"); + err_code = email_cancel_job(account_id, handle); + if (EMAIL_ERROR_NONE != err_code) { + tet_printf("Email cancel job : success\n"); + tet_result(TET_PASS); + } + else { + tet_printf("Email cancel job failed : \n"); + tet_result(TET_FAIL); + } + } + else { + tet_printf("Email sync mail header for all account failed : error_code[%d]\n", err_code); + tet_result(TET_UNRESOLVED); + } +} + diff --git a/TC/TC_email_service/TC_Network/uts_email_cancel_job.h b/TC/TC_email_service/TC_Network/uts_email_cancel_job.h new file mode 100755 index 0000000..2165ee3 --- /dev/null +++ b/TC/TC_email_service/TC_Network/uts_email_cancel_job.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2012 - 2013 Samsung Electronics, Co., Ltd. + * All rights reserved. + * + * This software is a confidential and proprietary information of Samsung + * Electronics, Co., Ltd. ("Confidential Information"). 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. + */ + +#include <tet_api.h> + +#include <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <sqlite3.h> +#include "email-api-init.h" +#include "email-api-account.h" +#include "email-api-mailbox.h" + +static void startup(), cleanup(); +void (*tet_startup) () = startup; +void (*tet_cleanup) () = cleanup; + + +static void uts_Email_Cancel_Job_01(void); +static void uts_Email_Cancel_Job_02(void); + + + + + +struct tet_testlist tet_testlist[] = { {uts_Email_Cancel_Job_01, 1}, {uts_Email_Cancel_Job_02, 2}, {NULL, 0} +}; diff --git a/TC/TC_email_service/TC_Network/uts_email_deactivate_pdp.c b/TC/TC_email_service/TC_Network/uts_email_deactivate_pdp.c new file mode 100755 index 0000000..7e292ff --- /dev/null +++ b/TC/TC_email_service/TC_Network/uts_email_deactivate_pdp.c @@ -0,0 +1,128 @@ +/* +* Copyright (c) 2012 - 2013 Samsung Electronics, Inc. +* All rights reserved. +* +* This software is a confidential and proprietary information of Samsung +* Electronics, Inc. ("Confidential Information"). 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. +*/ + +/*************************************** +* add your header file here +* e.g., +* #include "uts_ApplicationLib_recurGetDayOfWeek_func.h" +***************************************/ +#include "uts_email_deactivate_pdp.h" +#include "../TC_Utility/uts-email-real-utility.c" + + +sqlite3 *sqlite_emmb; + +static void startup() +{ + tet_printf("\n TC startup"); + + if (EMAIL_ERROR_NONE == email_service_begin()) { + tet_infoline("Email service Begin\n"); + if (EMAIL_ERROR_NONE == email_open_db()) + tet_infoline("Email open DB success\n"); + else + tet_infoline("Email open DB failed\n"); + } + else + tet_infoline("Email service not started\n"); + +} + +static void cleanup() +{ + tet_printf("\n TC End"); + + if (EMAIL_ERROR_NONE == email_close_db()) { + tet_infoline("Email Close DB Success\n"); + if (EMAIL_ERROR_NONE == email_service_end()) + tet_infoline("Email service close Success\n"); + else + tet_infoline("Email service end failed\n"); + } + else + tet_infoline("Email Close DB failed\n"); +} + + + + +/*************************************** +* add your Test Cases +* e.g., +* static void uts_ApplicationLib_recurGetDayOfWeek_01() +* { +* int ret; +* +* ret = target_api(); +* if (ret == 1) +* tet_result(TET_PASS); +* else +* tet_result(TET_FAIL); +* } +* +* static void uts_ApplicationLib_recurGetDayOfWeek_02() +* { +* code.. +* condition1 +* tet_result(TET_PASS); +* condition2 +* tet_result(TET_FAIL); +* } +* +***************************************/ + + +/*Testcase : uts_Email_Deactivate_Pdp_01 + TestObjective : To Deactivate pdp + APIs Tested : int email_deactivate_pdp(int thread_type) + */ + +static void uts_Email_Deactivate_Pdp_01() +{ + int err_code = EMAIL_ERROR_NONE; + int thread_type = 1; + + tet_infoline("uts_Email_Deactivate_Pdp_01 Begin\n"); + + err_code = email_deactivate_pdp(thread_type); + if (EMAIL_ERROR_NONE == err_code) { + tet_printf("Email deactivate pdp : success\n"); + tet_result(TET_PASS); + } + else { + tet_printf("Email deactivate pdp failed : error_code[%d]\n", err_code); + tet_result(TET_FAIL); + } +} + + +/*Testcase : uts_Email_Deactivate_Pdp_02 + TestObjective : To validate parameter for deactivate pdp + APIs Tested : int email_deactivate_pdp(int thread_type) + */ + +static void uts_Email_Deactivate_Pdp_02() +{ + int err_code = EMAIL_ERROR_NONE; + int thread_type = -1; + + tet_infoline("uts_Email_Deactivate_pdp_01 Begin\n"); + + err_code = email_deactivate_pdp(thread_type); + if (EMAIL_ERROR_NONE != err_code) { + tet_printf("Email deactivate pdp : success\n"); + tet_result(TET_PASS); + } + else { + tet_printf("Email deactivate pdp failed : \n"); + tet_result(TET_FAIL); + } +} + diff --git a/TC/TC_email_service/TC_Network/uts_email_deactivate_pdp.h b/TC/TC_email_service/TC_Network/uts_email_deactivate_pdp.h new file mode 100755 index 0000000..2afc147 --- /dev/null +++ b/TC/TC_email_service/TC_Network/uts_email_deactivate_pdp.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2012 - 2013 Samsung Electronics, Co., Ltd. + * All rights reserved. + * + * This software is a confidential and proprietary information of Samsung + * Electronics, Co., Ltd. ("Confidential Information"). 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. + */ + +#include <tet_api.h> + +#include <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <sqlite3.h> +#include "email-api-init.h" +#include "email-api-account.h" +#include "email-api-mailbox.h" + +static void startup(), cleanup(); +void (*tet_startup) () = startup; +void (*tet_cleanup) () = cleanup; + + +static void uts_Email_Deactivate_Pdp_01(void); +static void uts_Email_Deactivate_Pdp_02(void); + + + + + +struct tet_testlist tet_testlist[] = { {uts_Email_Deactivate_Pdp_01, 1}, {uts_Email_Deactivate_Pdp_02, 2}, {NULL, 0} +}; diff --git a/TC/TC_email_service/TC_Network/uts_email_download_attachment.c b/TC/TC_email_service/TC_Network/uts_email_download_attachment.c new file mode 100755 index 0000000..cba5f38 --- /dev/null +++ b/TC/TC_email_service/TC_Network/uts_email_download_attachment.c @@ -0,0 +1,190 @@ +/* +* Copyright (c) 2012 - 2013 Samsung Electronics, Inc. +* All rights reserved. +* +* This software is a confidential and proprietary information of Samsung +* Electronics, Inc. ("Confidential Information"). 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. +*/ + +/*************************************** +* add your header file here +* e.g., +* #include "uts_ApplicationLib_recurGetDayOfWeek_func.h" +***************************************/ +#include "uts_email_download_attachment.h" +#include "../TC_Utility/uts-email-real-utility.c" +#include "../TC_Utility/uts-email-dummy-utility.c" + +sqlite3 *sqlite_emmb; +int g_accountId; +int mail_id ; + +static void startup() +{ + int err_code = EMAIL_ERROR_NONE; + int count = 0; + int i = 0; + email_account_t *pAccount = NULL ; + + tet_printf("\n TC startup"); + + if (EMAIL_ERROR_NONE == email_service_begin()) { + tet_infoline("Email service Begin\n"); + if (EMAIL_ERROR_NONE == email_open_db()) { + tet_infoline("Email open DB success\n"); + err_code = email_get_account_list(&pAccount, &count); + if (!count) { + g_accountId = uts_Email_Add_Real_Account_01(); + mail_id = uts_Email_Add_Real_Message_02(); + } + else { + g_accountId = pAccount[i].account_id; + mail_id = uts_Email_Add_Real_Message_02(); + + } + email_free_account(&pAccount, count); + + } + else + tet_infoline("Email open DB failed\n"); + } + else + tet_infoline("Email service not started\n"); + +} + +static void cleanup() +{ + tet_printf("\n TC End"); + + if (EMAIL_ERROR_NONE == email_close_db()) { + tet_infoline("Email Close DB Success\n"); + if (EMAIL_ERROR_NONE == email_service_end()) + tet_infoline("Email service close Success\n"); + else + tet_infoline("Email service end failed\n"); + } + else + tet_infoline("Email Close DB failed\n"); +} + + + + +/*************************************** +* add your Test Cases +* e.g., +* static void uts_ApplicationLib_recurGetDayOfWeek_01() +* { +* int ret; +* +* ret = target_api(); +* if (ret == 1) +* tet_result(TET_PASS); +* else +* tet_result(TET_FAIL); +* } +* +* static void uts_ApplicationLib_recurGetDayOfWeek_02() +* { +* code.. +* condition1 +* tet_result(TET_PASS); +* condition2 +* tet_result(TET_FAIL); +* } +* +***************************************/ + + +/*Testcase : uts_email_download_attachment_01 + TestObjective : To download attachment part of email + APIs Tested : int email_download_attachment(int mail_id, int nth, unsigned* handle) + */ +static void uts_Email_Download_Attachment_01() +{ + int err_code = EMAIL_ERROR_NONE; + int handle; + int i = 0; + email_mail_list_item_t *mail_list = NULL; + int count = 0; + + tet_infoline("uts_Email_Download_Attachment_01 Begin\n"); + + err_code = uts_Email_Get_Mail_List_03(g_accountId, EMAIL_MAILBOX_TYPE_INBOX, &mail_list, &count, 0); + if (EMAIL_ERROR_NONE != err_code || count < 0) { + tet_printf("Email Get Account List Failed : err_code[%d]\n", err_code); + tet_result(TET_UNRESOLVED); + return; + } + + for (i ; i < count ; i++) { + if(mail_list[i].attachment_count) { + err_code = email_download_attachment(mail_list[i].mail_id, 1, &handle); + if (EMAIL_ERROR_NONE == err_code) { + tet_infoline("Email download mail attachment success\n"); + tet_result(TET_PASS); + return ; + } + else + { + tet_printf("Email download mail attachment failed : error_code[%d]\n", err_code); + tet_result(TET_FAIL); + return; + } + } + } +} + + + +/*Testcase : uts_email_download_attachment_02 + TestObjective : To validate parameter account_id for email download attachment + APIs Tested : int email_download_attachment(int mail_id, int nth, unsigned* handle) + */ +static void uts_Email_Download_Attachment_02() +{ + int err_code = EMAIL_ERROR_NONE; + int handle; + int mail_id = 0; /* validation fiel */ + + tet_infoline("uts_Email_Download_Attachment_02 Begin\n"); + + err_code = email_download_attachment(mail_id, 1, &handle); + if (EMAIL_ERROR_NONE != err_code) { + tet_infoline("Email download mail attachment success\n"); + tet_result(TET_PASS); + } + else { + tet_printf("Email download attachment failed : error_code[%d]\n", err_code); + tet_result(TET_FAIL); + } +} + + + + +/*Testcase : uts_email_download_attachment_03 + TestObjective : To validate parameter mailbox for email download attachment + APIs Tested : int email_download_attachment(int mail_id, int nth, unsigned* handle) + */ +static void uts_Email_Download_Attachment_03() +{ + int err_code = EMAIL_ERROR_NONE; + int handle; + + tet_infoline("uts_Email_Download_Attachment_03 Begin\n"); + + + err_code = email_download_attachment(1, 0, &handle); + if (EMAIL_ERROR_NONE != err_code) { + tet_infoline("Email download mail attachment success\n"); + tet_result(TET_PASS); + } + else { + tet_printf("Email download attachment failed : error_code[%d]\n", err_code); + tet_result(TET_FAIL); + } +} diff --git a/TC/TC_email_service/TC_Network/uts_email_download_attachment.h b/TC/TC_email_service/TC_Network/uts_email_download_attachment.h new file mode 100755 index 0000000..dc42faf --- /dev/null +++ b/TC/TC_email_service/TC_Network/uts_email_download_attachment.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2012 - 2013 Samsung Electronics, Co., Ltd. + * All rights reserved. + * + * This software is a confidential and proprietary information of Samsung + * Electronics, Co., Ltd. ("Confidential Information"). 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. + */ + +#include <tet_api.h> + +#include <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <sqlite3.h> +#include "email-api-init.h" +#include "email-api-account.h" +#include "email-api-mailbox.h" + +static void startup(), cleanup(); +void (*tet_startup) () = startup; +void (*tet_cleanup) () = cleanup; + + +static void uts_Email_Download_Attachment_01(void); +static void uts_Email_Download_Attachment_02(void); +static void uts_Email_Download_Attachment_03(void); + + + + + +struct tet_testlist tet_testlist[] = { {uts_Email_Download_Attachment_01, 1}, {uts_Email_Download_Attachment_02, 2}, {uts_Email_Download_Attachment_03, 3}, {NULL, 0} +}; diff --git a/TC/TC_email_service/TC_Network/uts_email_download_body.c b/TC/TC_email_service/TC_Network/uts_email_download_body.c new file mode 100755 index 0000000..9b3b953 --- /dev/null +++ b/TC/TC_email_service/TC_Network/uts_email_download_body.c @@ -0,0 +1,217 @@ +/* +* Copyright (c) 2012 - 2013 Samsung Electronics, Inc. +* All rights reserved. +* +* This software is a confidential and proprietary information of Samsung +* Electronics, Inc. ("Confidential Information"). 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. +*/ + +/*************************************** +* add your header file here +* e.g., +* #include "uts_ApplicationLib_recurGetDayOfWeek_func.h" +***************************************/ +#include "uts_email_download_body.h" +#include "../TC_Utility/uts-email-real-utility.c" +#include "../TC_Utility/uts-email-dummy-utility.c" + +sqlite3 *sqlite_emmb; +int g_accountId; + +static void startup() +{ + int err_code = EMAIL_ERROR_NONE; + int count = 0; + int i = 0; + email_account_t *pAccount = NULL ; + + tet_printf("\n TC startup"); + + if (EMAIL_ERROR_NONE == email_service_begin()) { + tet_infoline("Email service Begin\n"); + if (EMAIL_ERROR_NONE == email_open_db()) { + tet_infoline("Email open DB success\n"); + err_code = email_get_account_list(&pAccount, &count); + if (!count) { + g_accountId = uts_Email_Add_Real_Account_01(); + uts_Email_Add_Real_Message_02(); + } + else { + g_accountId = pAccount[i].account_id; + uts_Email_Add_Real_Message_02(); + } + email_free_account(&pAccount, count); + } + else + tet_infoline("Email open DB failed\n"); + } + else + tet_infoline("Email service not started\n"); +} + +static void cleanup() +{ + tet_printf("\n TC End"); + + if (EMAIL_ERROR_NONE == email_close_db()) { + tet_infoline("Email Close DB Success\n"); + if (EMAIL_ERROR_NONE == email_service_end()) + tet_infoline("Email service close Success\n"); + else + tet_infoline("Email service end failed\n"); + } + else + tet_infoline("Email Close DB failed\n"); +} + + + + +/*************************************** +* add your Test Cases +* e.g., +* static void uts_ApplicationLib_recurGetDayOfWeek_01() +* { +* int ret; +* +* ret = target_api(); +* if (ret == 1) +* tet_result(TET_PASS); +* else +* tet_result(TET_FAIL); +* } +* +* static void uts_ApplicationLib_recurGetDayOfWeek_02() +* { +* code.. +* condition1 +* tet_result(TET_PASS); +* condition2 +* tet_result(TET_FAIL); +* } +* +***************************************/ + + +/*Testcase : uts_Email_Download_Body_01 + TestObjective : To download email body + APIs Tested : int email_download_body(int mail_id, int with_attachment, unsigned* handle) + */ +static void uts_Email_Download_Body_01() +{ + int err_code = EMAIL_ERROR_NONE; + int handle; + int count = 0; + int i = 0; + email_account_t *account = NULL ; + email_mail_list_item_t *mail_list = NULL; + + tet_infoline("uts_Email_Download_Body_01 Begin\n"); + + err_code = uts_Email_Get_Mail_List_03(g_accountId, EMAIL_MAILBOX_TYPE_INBOX, &mail_list, &count, 0); + if (EMAIL_ERROR_NONE == err_code) { + tet_infoline("Email get mail list : success\n"); + for (i = 0 ;i<count ; i++) { + /* if (mail_list[i].text_download_yn == 0 */ { + tet_printf("mail_id[%d]\n", mail_list[i].mail_id); + err_code = email_download_body( mail_list[i].mail_id, 0, &handle); + i = count; + if (EMAIL_ERROR_NONE == err_code) { + tet_infoline("Email download mail body success\n"); + tet_result(TET_PASS); + return; + } + else { + tet_printf("Email download body failed : error_code[%d]\n", err_code); + tet_result(TET_FAIL); + return; + } + } + } + +/* email_free_mail_list(&mail_list, count) */ + free(mail_list); + } + else { + tet_printf("Email get mail list failed : error_code[%d]\n", err_code); + tet_result(TET_UNRESOLVED); + } +} + + + +/*Testcase : uts_Email_Download_Body_02 + TestObjective : To validate parameter for mailbox in email download body + APIs Tested : int email_download_body(int mail_id, int with_attachment, unsigned* handle) + */ +static void uts_Email_Download_Body_02() +{ + int err_code = EMAIL_ERROR_NONE; + int handle; + int mail_id = 1; /* Validation Fiel */ + + tet_infoline("uts_Email_Download_Body_02 Begin\n"); + + err_code = email_download_body(mail_id, 0, &handle); + if (EMAIL_ERROR_NONE != err_code) { + tet_infoline("Email download mail body success\n"); + tet_result(TET_PASS); + } + else { + tet_printf("Email download body failed : error_code[%d]\n", err_code); + tet_result(TET_FAIL); + } +} + + +/*Testcase : uts_Email_Download_Body_03 + TestObjective : To validate parameter for account id in email download body + APIs Tested : int email_download_body(int mail_id, int with_attachment, unsigned* handle) + */ +static void uts_Email_Download_Body_03() +{ + int err_code = EMAIL_ERROR_NONE; + int handle; + int mail_id = 1; + + tet_infoline("uts_Email_Download_Body_03 Begin\n"); + + err_code = email_download_body(mail_id, 0, &handle); + if (EMAIL_ERROR_NONE != err_code) { + tet_infoline("Email download mail body success\n"); + tet_result(TET_PASS); + } + else { + tet_printf("Email download body failed : error_code[%d]\n", err_code); + tet_result(TET_FAIL); + } +} + + + + +/*Testcase : uts_Email_Download_Body_04 + TestObjective : To validate parameter for mail_id in email download body + APIs Tested : int email_download_body(int mail_id, int with_attachment, unsigned* handle) + */ +static void uts_Email_Download_Body_04() +{ + int err_code = EMAIL_ERROR_NONE; + int handle; + int mail_id = -1; + + tet_infoline("uts_Email_Download_Body_04 Begin\n"); + + err_code = email_download_body(mail_id, 0, &handle); + if (EMAIL_ERROR_NONE != err_code) { + tet_infoline("Email download mail body success\n"); + tet_result(TET_PASS); + } + else { + tet_printf("Email download body failed : error_code[%d]\n", err_code); + tet_result(TET_FAIL); + } +} + diff --git a/TC/TC_email_service/TC_Network/uts_email_download_body.h b/TC/TC_email_service/TC_Network/uts_email_download_body.h new file mode 100755 index 0000000..fe21204 --- /dev/null +++ b/TC/TC_email_service/TC_Network/uts_email_download_body.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2012 - 2013 Samsung Electronics, Co., Ltd. + * All rights reserved. + * + * This software is a confidential and proprietary information of Samsung + * Electronics, Co., Ltd. ("Confidential Information"). 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. + */ + +#include <tet_api.h> + +#include <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <sqlite3.h> +#include "email-api-init.h" +#include "email-api-account.h" +#include "email-api-mailbox.h" + +static void startup(), cleanup(); +void (*tet_startup) () = startup; +void (*tet_cleanup) () = cleanup; + + +static void uts_Email_Download_Body_01(void); +static void uts_Email_Download_Body_04(void); +static void uts_Email_Download_Body_03(void); +static void uts_Email_Download_Body_02(void); + + + + +struct tet_testlist tet_testlist[] = { {uts_Email_Download_Body_01, 1}, {uts_Email_Download_Body_02, 1}, {uts_Email_Download_Body_03, 1}, {uts_Email_Download_Body_04, 1}, {NULL, 0} +}; diff --git a/TC/TC_email_service/TC_Network/uts_email_get_imap_folder_list.c b/TC/TC_email_service/TC_Network/uts_email_get_imap_folder_list.c new file mode 100755 index 0000000..d2081ba --- /dev/null +++ b/TC/TC_email_service/TC_Network/uts_email_get_imap_folder_list.c @@ -0,0 +1,152 @@ +/* +* Copyright (c) 2012 - 2013 Samsung Electronics, Inc. +* All rights reserved. +* +* This software is a confidential and proprietary information of Samsung +* Electronics, Inc. ("Confidential Information"). 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. +*/ + +/*************************************** +* add your header file here +* e.g., +* #include "uts_ApplicationLib_recurGetDayOfWeek_func.h" +***************************************/ +#include "uts_email_get_imap_folder_list.h" +#include "../TC_Utility/uts-email-real-utility.c" + + +sqlite3 *sqlite_emmb; +static int g_accountId; + +static void startup() +{ + int err_code = EMAIL_ERROR_NONE; + int count = 0; + int i = 0; + email_account_t *pAccount = NULL ; + + tet_printf("\n TC startup"); + + if (EMAIL_ERROR_NONE == email_service_begin()) { + tet_infoline("Email service Begin\n"); + if (EMAIL_ERROR_NONE == email_open_db()) { + tet_infoline("Email open DB success\n"); + err_code = email_get_account_list(&pAccount, &count); + if (!count) { + g_accountId = uts_Email_Add_Real_Account_01(); + } + else + g_accountId = pAccount[i].account_id; + email_free_account(&pAccount, count); + } + else + tet_infoline("Email open DB failed\n"); + } + else + tet_infoline("Email service not started\n"); + +} + +static void cleanup() +{ + tet_printf("\n TC End"); + + if (EMAIL_ERROR_NONE == email_close_db()) { + tet_infoline("Email Close DB Success\n"); + if (EMAIL_ERROR_NONE == email_service_end()) + tet_infoline("Email service close Success\n"); + else + tet_infoline("Email service end failed\n"); + } + else + tet_infoline("Email Close DB failed\n"); +} + + + + +/*************************************** +* add your Test Cases +* e.g., +* static void uts_ApplicationLib_recurGetDayOfWeek_01() +* { +* int ret; +* +* ret = target_api(); +* if (ret == 1) +* tet_result(TET_PASS); +* else +* tet_result(TET_FAIL); +* } +* +* static void uts_ApplicationLib_recurGetDayOfWeek_02() +* { +* code.. +* condition1 +* tet_result(TET_PASS); +* condition2 +* tet_result(TET_FAIL); +* } +* +***************************************/ + + +/*Testcase : uts_Email_Get_Imap_Folder_List_01 + TestObjective : To get imap mailbox list + APIs Tested : int email_get_imap_mailbox_list(int account_id, unsigned *handle) + */ + +static void uts_Email_Get_Imap_Folder_List_01() +{ + int err_code = EMAIL_ERROR_NONE; + int handle; + email_account_t *account = NULL ; + int count = 0; + + tet_infoline("uts_email_get_imap_folder_list_01 Begin\n"); + err_code = email_get_account_list(&account, &count); + if (EMAIL_ERROR_NONE != err_code || count <=0 ) { + tet_printf("email_get_account_list failed : error_code[%d]\n", err_code); + tet_result(TET_UNRESOLVED); + } + + err_code = email_sync_imap_mailbox_list(account[0].account_id, &handle); + if (EMAIL_ERROR_NONE == err_code) { + tet_infoline("Email get Imap mailbox list : success\n "); + tet_result(TET_PASS); + } + else { + tet_printf("Email get Imap mailbox list : failed err_code[%d]\n", err_code); + tet_result(TET_FAIL); + } + } + +/*Testcase : uts_email_get_imap_folder_list_02 + TestObjective : To validate parametr for account_id in get imap mailbox list + APIs Tested : int email_get_imap_mailbox_list(int account_id, unsigned *handle) + */ + +static void uts_Email_Get_Imap_Folder_List_02() +{ + int err_code = EMAIL_ERROR_NONE; + int handle; + int account_id = -1; + + + tet_infoline("uts_email_get_imap_folder_list_02 Begin\n"); + + + err_code = email_sync_imap_mailbox_list(account_id, &handle); + if (EMAIL_ERROR_NONE != err_code) { + tet_infoline("Email get Imap mailbox list : success\n "); + tet_result(TET_PASS); + } + else { + tet_printf("Email get Imap mailbox list : failed \n"); + tet_result(TET_FAIL); + } +} + + diff --git a/TC/TC_email_service/TC_Network/uts_email_get_imap_folder_list.h b/TC/TC_email_service/TC_Network/uts_email_get_imap_folder_list.h new file mode 100755 index 0000000..9d11bfa --- /dev/null +++ b/TC/TC_email_service/TC_Network/uts_email_get_imap_folder_list.h @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2012 - 2013 Samsung Electronics, Co., Ltd. + * All rights reserved. + * + * This software is a confidential and proprietary information of Samsung + * Electronics, Co., Ltd. ("Confidential Information"). 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. + */ + +#include <tet_api.h> + +#include <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <sqlite3.h> +#include "email-api-init.h" +#include "email-api-account.h" +#include "email-api-mailbox.h" + +static void startup(), cleanup(); +void (*tet_startup) () = startup; +void (*tet_cleanup) () = cleanup; + + +static void uts_Email_Get_Imap_Folder_List_01(void); +static void uts_Email_Get_Imap_Folder_List_02(void); + + + + +struct tet_testlist tet_testlist[] = { {uts_Email_Get_Imap_Folder_List_01, 1}, {uts_Email_Get_Imap_Folder_List_02, 2}, {NULL, 0} +}; diff --git a/TC/TC_email_service/TC_Network/uts_email_get_network_status.c b/TC/TC_email_service/TC_Network/uts_email_get_network_status.c new file mode 100755 index 0000000..a183862 --- /dev/null +++ b/TC/TC_email_service/TC_Network/uts_email_get_network_status.c @@ -0,0 +1,108 @@ +/* +* Copyright (c) 2012 - 2013 Samsung Electronics, Inc. +* All rights reserved. +* +* This software is a confidential and proprietary information of Samsung +* Electronics, Inc. ("Confidential Information"). 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. +*/ + +/*************************************** +* add your header file here +* e.g., +* #include "uts_ApplicationLib_recurGetDayOfWeek_func.h" +***************************************/ +#include "uts_email_get_network_status.h" +#include "../TC_Utility/uts-email-real-utility.c" + + +sqlite3 *sqlite_emmb; + + +static void startup() +{ + tet_printf("\n TC startup"); + + if (EMAIL_ERROR_NONE == email_service_begin()) { + tet_infoline("Email service Begin\n"); + if (EMAIL_ERROR_NONE == email_open_db()) + tet_infoline("Email open DB success\n"); + else + tet_infoline("Email open DB failed\n"); + } + else + tet_infoline("Email service not started\n"); + +} + +static void cleanup() +{ + tet_printf("\n TC End"); + + if (EMAIL_ERROR_NONE == email_close_db()) { + tet_infoline("Email Close DB Success\n"); + if (EMAIL_ERROR_NONE == email_service_end()) + tet_infoline("Email service close Success\n"); + else + tet_infoline("Email service end failed\n"); + } + else + tet_infoline("Email Close DB failed\n"); +} + + + + +/*************************************** +* add your Test Cases +* e.g., +* static void uts_ApplicationLib_recurGetDayOfWeek_01() +* { +* int ret; +* +* ret = target_api(); +* if (ret == 1) +* tet_result(TET_PASS); +* else +* tet_result(TET_FAIL); +* } +* +* static void uts_ApplicationLib_recurGetDayOfWeek_02() +* { +* code.. +* condition1 +* tet_result(TET_PASS); +* condition2 +* tet_result(TET_FAIL); +* } +* +***************************************/ + + +/*Testcase : uts_Email_Get_Network_Status_01 + TestObjective : To get network status + APIs Tested : int email_get_network_status(int *on_sending, int *on_receiving) + */ + +static void uts_Email_Get_Network_Status_01() +{ + int err_code = EMAIL_ERROR_NONE; + int on_sending = 0; + int on_receiving = 0; + + tet_infoline("uts_email_get_network_status_01 Begin\n"); + + err_code = email_get_network_status(&on_sending, &on_receiving); + if (EMAIL_ERROR_NONE == err_code) { + tet_printf("Email get Network status : success\n"); + tet_result(TET_PASS); + } + else { + tet_printf("Email get Network status failed : error_code[%d]\n", err_code); + tet_result(TET_FAIL); + } +} + + + diff --git a/TC/TC_email_service/TC_Network/uts_email_get_network_status.h b/TC/TC_email_service/TC_Network/uts_email_get_network_status.h new file mode 100755 index 0000000..a3e69fb --- /dev/null +++ b/TC/TC_email_service/TC_Network/uts_email_get_network_status.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2012 - 2013 Samsung Electronics, Co., Ltd. + * All rights reserved. + * + * This software is a confidential and proprietary information of Samsung + * Electronics, Co., Ltd. ("Confidential Information"). 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. + */ + +#include <tet_api.h> + +#include <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <sqlite3.h> +#include "email-api-init.h" +#include "email-api-account.h" +#include "email-api-mailbox.h" + +static void startup(), cleanup(); +void (*tet_startup) () = startup; +void (*tet_cleanup) () = cleanup; + + +static void uts_Email_Get_Network_Status_01(void); + + + +struct tet_testlist tet_testlist[] = { {uts_Email_Get_Network_Status_01, 1}, {NULL, 0} +}; diff --git a/TC/TC_email_service/TC_Network/uts_email_get_pending_job.c b/TC/TC_email_service/TC_Network/uts_email_get_pending_job.c new file mode 100755 index 0000000..cde82fe --- /dev/null +++ b/TC/TC_email_service/TC_Network/uts_email_get_pending_job.c @@ -0,0 +1,169 @@ +/* +* Copyright (c) 2012 - 2013 Samsung Electronics, Inc. +* All rights reserved. +* +* This software is a confidential and proprietary information of Samsung +* Electronics, Inc. ("Confidential Information"). 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. +*/ + +/*************************************** +* add your header file here +* e.g., +* #include "uts_ApplicationLib_recurGetDayOfWeek_func.h" +***************************************/ +#include "uts_email_get_pending_job.h" +#include "../TC_Utility/uts-email-real-utility.c" + + +sqlite3 *sqlite_emmb; +int g_accountId; + +static void startup() +{ + int err_code = EMAIL_ERROR_NONE; + int count = 0; + int i = 0; + email_account_t *pAccount = NULL ; + + tet_printf("\n TC startup"); + + if (EMAIL_ERROR_NONE == email_service_begin()) { + tet_infoline("Email service Begin\n"); + if (EMAIL_ERROR_NONE == email_open_db()) { + tet_infoline("Email open DB success\n"); + err_code = email_get_account_list(&pAccount, &count); + if (!count) { + g_accountId = uts_Email_Add_Real_Account_01(); + } + else + g_accountId = pAccount[i].account_id; + email_free_account(&pAccount, count); + } + else + tet_infoline("Email open DB failed\n"); + } + else + tet_infoline("Email service not started\n"); + +} + +static void cleanup() +{ + tet_printf("\n TC End"); + + if (EMAIL_ERROR_NONE == email_close_db()) { + tet_infoline("Email Close DB Success\n"); + if (EMAIL_ERROR_NONE == email_service_end()) + tet_infoline("Email service close Success\n"); + else + tet_infoline("Email service end failed\n"); + } + else + tet_infoline("Email Close DB failed\n"); +} + + + + +/*************************************** +* add your Test Cases +* e.g., +* static void uts_ApplicationLib_recurGetDayOfWeek_01() +* { +* int ret; +* +* ret = target_api(); +* if (ret == 1) +* tet_result(TET_PASS); +* else +* tet_result(TET_FAIL); +* } +* +* static void uts_ApplicationLib_recurGetDayOfWeek_02() +* { +* code.. +* condition1 +* tet_result(TET_PASS); +* condition2 +* tet_result(TET_FAIL); +* } +* +***************************************/ + + +/*Testcase : uts_Email_Get_Pending_job_01 + TestObjective : To get pending job list + APIs Tested : int email_get_pending_job(email_action_t action, int account_id, int mail_id, email_event_status_type_t *status) + */ + +static void uts_Email_Get_Pending_Job_01() +{ + int err_code = EMAIL_ERROR_NONE; + int handle = 0; + + tet_infoline("uts_Email_Get_pending_Job_01 Begin\n"); + + err_code = email_get_pending_job(EMAIL_ACTION_SEND_MAIL, g_accountId, 1, &handle); + if (EMAIL_ERROR_NONE == err_code) { + tet_printf("Email get pending job : success\n"); + tet_result(TET_PASS); + } + else { + tet_printf("Email get pending job failed : error_code[%d]\n", err_code); + tet_result(TET_FAIL); + } +} + + +/*Testcase : uts_Email_Get_Pending_Job_02 + TestObjective : To get pending job list + APIs Tested : int email_get_pending_job(email_action_t action, int account_id, int mail_id, email_event_status_type_t *status) + */ + +static void uts_Email_Get_Pending_Job_02() +{ + int err_code = EMAIL_ERROR_NONE; + int handle = 0; + int account_id = -1; + int mail_id = 1; + + tet_infoline("uts_Email_Get_Pending_Job_02 Begin\n"); + + err_code = email_get_pending_job(EMAIL_ACTION_SEND_MAIL, account_id, mail_id, &handle); + if (EMAIL_ERROR_NONE != err_code) { + tet_printf("Email get pending job : success\n"); + tet_result(TET_PASS); + } + else { + tet_printf("Email get pending job failed : \n"); + tet_result(TET_FAIL); + } +} + + +/*Testcase : uts_Email_Get_Pending_Job_03 + TestObjective : To get pending job list + APIs Tested : int email_get_pending_job(email_action_t action, int account_id, int mail_id, email_event_status_type_t *status) + */ + +static void uts_Email_Get_Pending_Job_03() +{ + int err_code = EMAIL_ERROR_NONE; + int handle = 0; + int account_id = -1 ; + int mail_id = 0; + + tet_infoline("uts_Email_Network_11 Begin\n"); + + err_code = email_get_pending_job(EMAIL_ACTION_SEND_MAIL, account_id , mail_id, &handle); + if (EMAIL_ERROR_NONE != err_code) { + tet_printf("Email get pending job : success\n"); + tet_result(TET_PASS); + } + else { + tet_printf("Email get pending job failed : \n"); + tet_result(TET_FAIL); + } +} diff --git a/TC/TC_email_service/TC_Network/uts_email_get_pending_job.h b/TC/TC_email_service/TC_Network/uts_email_get_pending_job.h new file mode 100755 index 0000000..eebeb02 --- /dev/null +++ b/TC/TC_email_service/TC_Network/uts_email_get_pending_job.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2012 - 2013 Samsung Electronics, Co., Ltd. + * All rights reserved. + * + * This software is a confidential and proprietary information of Samsung + * Electronics, Co., Ltd. ("Confidential Information"). 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. + */ + +#include <tet_api.h> + +#include <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <sqlite3.h> +#include "email-api-init.h" +#include "email-api-account.h" +#include "email-api-mailbox.h" + +static void startup(), cleanup(); +void (*tet_startup) () = startup; +void (*tet_cleanup) () = cleanup; + + +static void uts_Email_Get_Pending_Job_01(void); +static void uts_Email_Get_Pending_Job_02(void); +static void uts_Email_Get_Pending_Job_03(void); + + + + + +struct tet_testlist tet_testlist[] = { {uts_Email_Get_Pending_Job_01, 1}, {uts_Email_Get_Pending_Job_02, 2}, {uts_Email_Get_Pending_Job_03, 3}, {NULL, 0} +}; diff --git a/TC/TC_email_service/TC_Network/uts_email_send_mail.c b/TC/TC_email_service/TC_Network/uts_email_send_mail.c new file mode 100755 index 0000000..41cd96b --- /dev/null +++ b/TC/TC_email_service/TC_Network/uts_email_send_mail.c @@ -0,0 +1,219 @@ +/* +* Copyright (c) 2012 - 2013 Samsung Electronics, Inc. +* All rights reserved. +* +* This software is a confidential and proprietary information of Samsung +* Electronics, Inc. ("Confidential Information"). 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. +*/ + +/*************************************** +* add your header file here +* e.g., +* #include "uts_ApplicationLib_recurGetDayOfWeek_func.h" +***************************************/ +#include "uts_email_send_mail.h" +#include "../TC_Utility/uts-email-real-utility.c" +#include "../TC_Utility/uts-email-dummy-utility.c" + + +sqlite3 *sqlite_emmb; +int g_accountId; + +static void startup() +{ + int err_code = EMAIL_ERROR_NONE; + int count = 0; + int i = 0; + email_account_t *pAccount = NULL ; + + tet_printf("\n TC startup"); + + if (EMAIL_ERROR_NONE == email_service_begin()) { + tet_infoline("Email service Begin\n"); + if (EMAIL_ERROR_NONE == email_open_db()) { + tet_infoline("Email open DB success\n"); + err_code = email_get_account_list(&pAccount, &count); + if (!count) { + g_accountId = uts_Email_Add_Real_Account_01(); + } + else + g_accountId = pAccount[i].account_id; + email_free_account(&pAccount, count); + + tet_printf("Add new email\n"); + err_code = uts_Email_Add_Real_Message_02(); + if (EMAIL_ERROR_NONE == err_code) { /* Make db contain at least one mai */ + tet_printf("uts_Email_Add_Real_Message_02() success.\n"); + } + else { + tet_printf("uts_Email_Add_Real_Message_02() failed : err_code[%d]\n", err_code); + } + + } + else + tet_infoline("Email open DB failed\n"); + } + else + tet_infoline("Email service not started\n"); + +} + +static void cleanup() +{ + tet_printf("\n TC End"); + + if (EMAIL_ERROR_NONE == email_close_db()) { + tet_infoline("Email Close DB Success\n"); + if (EMAIL_ERROR_NONE == email_service_end()) + tet_infoline("Email service close Success\n"); + else + tet_infoline("Email service end failed\n"); + } + else + tet_infoline("Email Close DB failed\n"); +} + + + + +/*************************************** +* add your Test Cases +* e.g., +* static void uts_ApplicationLib_recurGetDayOfWeek_01() +* { +* int ret; +* +* ret = target_api(); +* if (ret == 1) +* tet_result(TET_PASS); +* else +* tet_result(TET_FAIL); +* } +* +* static void uts_ApplicationLib_recurGetDayOfWeek_02() +* { +* code.. +* condition1 +* tet_result(TET_PASS); +* condition2 +* tet_result(TET_FAIL); +* } +* +***************************************/ + +/*Testcase : uts_Email_Send_Mail_01 + TestObjective : To send a mail + APIs Tested : int email_send_mail(int mail_id, email_option_t* sending_option, unsigned* handle) + */ + +static void uts_Email_Send_Mail_01() +{ + int err_code = EMAIL_ERROR_NONE; + int handle; + email_mail_data_t *test_mail_data = NULL; + email_attachment_data_t *attachment_data = NULL; + email_meeting_request_t *meeting_req = NULL; + + FILE *fp; + email_option_t option; + int count = 0; + int i = 0; + email_account_t *account = NULL ; + email_mailbox_t *mailbox = NULL; + + tet_infoline("uts_Email_Send_Mail_01 Begin\n"); + + memset(&option, 0x00, sizeof(email_option_t)); + option.keep_local_copy = 1; + + test_mail_data = malloc(sizeof(email_mail_data_t)); + memset(test_mail_data, 0x00, sizeof(email_mail_data_t)); + + attachment_data = malloc(sizeof(email_attachment_data_t)); + memset(attachment_data, 0x00, sizeof(email_attachment_data_t)); + + test_mail_data->account_id = g_accountId; + test_mail_data->flags_draft_field = 1; + + test_mail_data->full_address_from = strdup("<samsungtest09@gmail.com>"); + test_mail_data->full_address_to = strdup("<samsungtest09@gmail.com>"); + test_mail_data->subject = strdup("Test"); + + err_code = email_get_mailbox_by_mailbox_type(g_accountId , EMAIL_MAILBOX_TYPE_OUTBOX, &mailbox); + if (EMAIL_ERROR_NONE != err_code) { + tet_printf("Email get mailbox by mailbox type failed : error_code[%d]\n", err_code); + tet_result(TET_UNRESOLVED); + return ; + } + + test_mail_data->mailbox_id = mailbox->mailbox_id; + test_mail_data->mailbox_type = mailbox->mailbox_type; + + fp = fopen("/tmp/mail.txt", "w"); + fprintf(fp, "xxxxxxxxx"); + fclose(fp); + + test_mail_data->file_path_plain = strdup("/tmp/mail.txt"); + test_mail_data->attachment_count = 1; + + fp = fopen("/tmp/attach.txt", "w"); + fprintf(fp, "Simple Attach"); + fclose(fp); + + attachment_data->attachment_name = strdup("Attach"); + attachment_data->attachment_path = strdup("/tmp/attach.txt"); + + err_code = email_add_mail(test_mail_data, attachment_data, 1, NULL, 0); + if (EMAIL_ERROR_NONE == err_code) { + tet_infoline("email_add_mail Success\n"); + tet_printf("account_id[%d], test_mail_data->mail_id[%d]", g_accountId, test_mail_data->mail_id); + err_code = email_send_mail(test_mail_data->mail_id, &option, &handle); + if (EMAIL_ERROR_NONE == err_code) { + tet_infoline("email_send_mail : success\n"); + tet_result(TET_PASS); + } + else { + tet_printf("email_send_mail failed : error_code[%d]\n", err_code); + tet_result(TET_FAIL); + } + } + else { + tet_printf("email_add_message failed : error_code[%d]\n", err_code); + tet_result(TET_UNRESOLVED); + } + if (mailbox) { + email_free_mailbox(&mailbox, 1); + mailbox = NULL; + } +} + + + +/*Testcase : uts_Email_Send_Mail_02 + TestObjective : To validate parameter for send a mail + APIs Tested : int email_send_mail(int mail_id, email_option_t* sending_option, unsigned* handle) + */ + +static void uts_Email_Send_Mail_02() +{ + int err_code = EMAIL_ERROR_NONE; + int handle; + email_option_t option; + + tet_infoline("Email Email_send_mail_02 Begin\n"); + + memset(&option, 0x00, sizeof(email_option_t)); + option.keep_local_copy = 1; + err_code = email_send_mail(0, &option, &handle); + if (EMAIL_ERROR_NONE != err_code) { + tet_infoline("Email send mail : success\n"); + tet_result(TET_PASS); + } + else { + tet_printf("Email send mail failed : \n"); + tet_result(TET_FAIL); + } +} + diff --git a/TC/TC_email_service/TC_Network/uts_email_send_mail.h b/TC/TC_email_service/TC_Network/uts_email_send_mail.h new file mode 100755 index 0000000..4070318 --- /dev/null +++ b/TC/TC_email_service/TC_Network/uts_email_send_mail.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2012 - 2013 Samsung Electronics, Co., Ltd. + * All rights reserved. + * + * This software is a confidential and proprietary information of Samsung + * Electronics, Co., Ltd. ("Confidential Information"). 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. + */ + +#include <tet_api.h> + +#include <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <sqlite3.h> +#include "email-api-init.h" +#include "email-api-account.h" +#include "email-api-mailbox.h" + +static void startup(), cleanup(); +void (*tet_startup) () = startup; +void (*tet_cleanup) () = cleanup; + + +static void uts_Email_Send_Mail_01(void); +static void uts_Email_Send_Mail_02(void); + + + + + + +struct tet_testlist tet_testlist[] = { {uts_Email_Send_Mail_01, 1}, {uts_Email_Send_Mail_02, 2}, {NULL, 0} +}; diff --git a/TC/TC_email_service/TC_Network/uts_email_send_saved.c b/TC/TC_email_service/TC_Network/uts_email_send_saved.c new file mode 100755 index 0000000..2646985 --- /dev/null +++ b/TC/TC_email_service/TC_Network/uts_email_send_saved.c @@ -0,0 +1,184 @@ +/* +* Copyright (c) 2012 - 2013 Samsung Electronics, Inc. +* All rights reserved. +* +* This software is a confidential and proprietary information of Samsung +* Electronics, Inc. ("Confidential Information"). 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. +*/ + +/*************************************** +* add your header file here +* e.g., +* #include "uts_ApplicationLib_recurGetDayOfWeek_func.h" +***************************************/ +#include "uts_email_send_saved.h" +#include "../TC_Utility/uts-email-real-utility.c" + + +sqlite3 *sqlite_emmb; +int g_accountId; + +static void startup() +{ + int err_code = EMAIL_ERROR_NONE; + int count = 0; + int i = 0; + email_account_t *pAccount = NULL ; + + tet_printf("\n TC startup"); + + if (EMAIL_ERROR_NONE == email_service_begin()) { + tet_infoline("Email service Begin\n"); + if (EMAIL_ERROR_NONE == email_open_db()) { + tet_infoline("Email open DB success\n"); + err_code = email_get_account_list(&pAccount, &count); + if (!count) { + g_accountId = uts_Email_Add_Real_Account_01(); + } + else + g_accountId = pAccount[i].account_id; + email_free_account(&pAccount, count); + + } + else + tet_infoline("Email open DB failed\n"); + } + else + tet_infoline("Email service not started\n"); + +} + +static void cleanup() +{ + tet_printf("\n TC End"); + + if (EMAIL_ERROR_NONE == email_close_db()) { + tet_infoline("Email Close DB Success\n"); + if (EMAIL_ERROR_NONE == email_service_end()) + tet_infoline("Email service close Success\n"); + else + tet_infoline("Email service end failed\n"); + } + else + tet_infoline("Email Close DB failed\n"); +} + + + + +/*************************************** +* add your Test Cases +* e.g., +* static void uts_ApplicationLib_recurGetDayOfWeek_01() +* { +* int ret; +* +* ret = target_api(); +* if (ret == 1) +* tet_result(TET_PASS); +* else +* tet_result(TET_FAIL); +* } +* +* static void uts_ApplicationLib_recurGetDayOfWeek_02() +* { +* code.. +* condition1 +* tet_result(TET_PASS); +* condition2 +* tet_result(TET_FAIL); +* } +* +***************************************/ + + +/*Testcase : uts_Email_Send_Saved_01 + TestObjective : To send all saved mails + APIs Tested : int email_send_saved(int account_id, email_option_t *sending_option, unsigned *handle) + */ + +static void uts_Email_Send_Saved_01() +{ + int err_code = EMAIL_ERROR_NONE; + int handle; + email_option_t option; + email_account_t *account = NULL ; + int count = 0; + + tet_infoline("uts_email_send_saved_01 Begin\n"); + + err_code = email_get_account_list(&account, &count); + if (EMAIL_ERROR_NONE != err_code || count <=0 ) { + tet_printf("email_get_account_list failed : error_code[%d]\n", err_code); + tet_result(TET_UNRESOLVED); + } + + memset(&option , 0x00, sizeof(email_option_t)); + option.keep_local_copy = 1; + + err_code = email_send_saved(account[0].account_id, &option, &handle); + if (EMAIL_ERROR_NONE == err_code) { + tet_infoline("Email send and saved : success\n"); + tet_result(TET_PASS); + } + else { + tet_printf("Email send and saved failed : error_code[%d]\n", err_code); + tet_result(TET_FAIL); + } + +} + +/*Testcase : uts_Email_Send_Saved_02 + TestObjective : To validate parameter for account_id in send all saved mails + APIs Tested : int email_send_saved(int account_id, email_option_t *sending_option, unsigned *handle) + */ + +static void uts_Email_Send_Saved_02() +{ + int err_code = EMAIL_ERROR_NONE; + int handle; + int account_id = -1; + email_option_t option; + + tet_infoline("uts_email_send_saved_02 Begin\n"); + + memset(&option , 0x00, sizeof(email_option_t)); + option.keep_local_copy = 1; + + err_code = email_send_saved(account_id, &option, &handle); + if (EMAIL_ERROR_NONE != err_code) { + tet_infoline("Email send and saved : success\n"); + tet_result(TET_PASS); + } + else { + tet_printf("Email send and saved failed : \n"); + tet_result(TET_FAIL); + } +} + + +/*Testcase : uts_email_send_saved_03 + TestObjective : To validate parameter for sending_option in send all saved mails + APIs Tested : int email_send_saved(int account_id, email_option_t *sending_option, unsigned *handle) + */ + +static void uts_Email_Send_Saved_03() +{ + int err_code = EMAIL_ERROR_NONE; + int handle; + + tet_infoline("uts_email_send_saved_03 Begin\n"); + + + err_code = email_send_saved(g_accountId, NULL, &handle); + if (EMAIL_ERROR_NONE != err_code) { + tet_infoline("Email send and saved : success\n"); + tet_result(TET_PASS); + } + else { + tet_printf("Email send and saved failed : \n"); + tet_result(TET_FAIL); + } +} diff --git a/TC/TC_email_service/TC_Network/uts_email_send_saved.h b/TC/TC_email_service/TC_Network/uts_email_send_saved.h new file mode 100755 index 0000000..b23a007 --- /dev/null +++ b/TC/TC_email_service/TC_Network/uts_email_send_saved.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2012 - 2013 Samsung Electronics, Co., Ltd. + * All rights reserved. + * + * This software is a confidential and proprietary information of Samsung + * Electronics, Co., Ltd. ("Confidential Information"). 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. + */ + +#include <tet_api.h> + +#include <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <sqlite3.h> +#include "email-api-init.h" +#include "email-api-account.h" +#include "email-api-mailbox.h" + +static void startup(), cleanup(); +void (*tet_startup) () = startup; +void (*tet_cleanup) () = cleanup; + + +static void uts_Email_Send_Saved_01(void); +static void uts_Email_Send_Saved_03(void); +static void uts_Email_Send_Saved_02(void); + + + + + +struct tet_testlist tet_testlist[] = { {uts_Email_Send_Saved_01, 1}, {uts_Email_Send_Saved_02, 2}, {uts_Email_Send_Saved_03, 3}, {NULL, 0} +}; diff --git a/TC/TC_email_service/TC_Network/uts_email_sync_header.c b/TC/TC_email_service/TC_Network/uts_email_sync_header.c new file mode 100755 index 0000000..efead29 --- /dev/null +++ b/TC/TC_email_service/TC_Network/uts_email_sync_header.c @@ -0,0 +1,186 @@ +/* +* Copyright (c) 2012 - 2013 Samsung Electronics, Inc. +* All rights reserved. +* +* This software is a confidential and proprietary information of Samsung +* Electronics, Inc. ("Confidential Information"). 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. +*/ + +/*************************************** +* add your header file here +* e.g., +* #include "uts_ApplicationLib_recurGetDayOfWeek_func.h" +***************************************/ +#include "uts_email_sync_header.h" +#include "../TC_Utility/uts-email-real-utility.c" + + +sqlite3 *sqlite_emmb; +int g_accountId; + +static void startup() +{ + int err_code = EMAIL_ERROR_NONE; + int count = 0; + int i = 0; + email_account_t *pAccount = NULL ; + + tet_printf("\n TC startup"); + + if (EMAIL_ERROR_NONE == email_service_begin()) { + tet_infoline("Email service Begin\n"); + if (EMAIL_ERROR_NONE == email_open_db()) { + tet_infoline("Email open DB success\n"); + err_code = email_get_account_list(&pAccount, &count); + if (!count) { + g_accountId = uts_Email_Add_Real_Account_01(); + } + else + g_accountId = pAccount[i].account_id; + email_free_account(&pAccount, count); + + } + else + tet_infoline("Email open DB failed\n"); + } + else + tet_infoline("Email service not started\n"); + +} + +static void cleanup() +{ + tet_printf("\n TC End"); + + if (EMAIL_ERROR_NONE == email_close_db()) { + tet_infoline("Email Close DB Success\n"); + if (EMAIL_ERROR_NONE == email_service_end()) + tet_infoline("Email service close Success\n"); + else + tet_infoline("Email service end failed\n"); + } + else + tet_infoline("Email Close DB failed\n"); +} + + + + +/*************************************** +* add your Test Cases +* e.g., +* static void uts_ApplicationLib_recurGetDayOfWeek_01() +* { +* int ret; +* +* ret = target_api(); +* if (ret == 1) +* tet_result(TET_PASS); +* else +* tet_result(TET_FAIL); +* } +* +* static void uts_ApplicationLib_recurGetDayOfWeek_02() +* { +* code.. +* condition1 +* tet_result(TET_PASS); +* condition2 +* tet_result(TET_FAIL); +* } +* +***************************************/ + + +/*Testcase : uts_Email_Sync_Header_01 + TestObjective : To download email headers + APIs Tested : int email_sync_header(int input_account_id, int input_maibox_id, unsigned* handle) + */ + +static void uts_Email_Sync_Header_01() +{ + int err_code = EMAIL_ERROR_NONE; + int handle; + email_mailbox_t *mailbox = NULL; + email_account_t *account = NULL ; + int count = 0; + + tet_infoline("uts_email_sync_header_01 Begin\n"); + err_code = email_get_account_list(&account, &count); + if (EMAIL_ERROR_NONE != err_code || count <=0 ) { + tet_printf("email_get_account_list failed : error_code[%d]\n", err_code); + tet_result(TET_UNRESOLVED); + } + + err_code = email_get_mailbox_by_mailbox_type(account[0].account_id, EMAIL_MAILBOX_TYPE_INBOX, &mailbox); + if (EMAIL_ERROR_NONE != err_code) { + tet_printf("Email get mailbox by mailbox type failed : error_code[%d]\n", err_code); + tet_result(TET_UNRESOLVED); + } + + err_code = email_sync_header(g_accountId, mailbox->mailbox_id , &handle); + if (EMAIL_ERROR_NONE == err_code) { + tet_infoline("Email sync mail header : success\n"); + tet_result(TET_PASS); + } + else { + tet_printf("Email sync mail header failed : error_code[%d]\n", err_code); + tet_result(TET_FAIL); + } + if (mailbox) { + email_free_mailbox(&mailbox, 1); + mailbox = NULL; + } +} + + +/*Testcase : uts_Email_Sync_Header_02 + TestObjective : To validate parameter for mailbox account_id in download email headers + APIs Tested : int email_sync_header(int input_account_id, int input_maibox_id, unsigned* handle) + */ + +static void uts_Email_Sync_Header_02() +{ + int err_code = EMAIL_ERROR_NONE; + email_mailbox_t mbox; + int handle; + + tet_infoline("uts_Email_Sync_Header_02 Begin\n"); + + err_code = email_sync_header(-1, 0, &handle); + if (EMAIL_ERROR_NONE != err_code) { + tet_infoline("Email sync mail header : success\n"); + tet_result(TET_PASS); + } + else { + tet_printf("Email sync mail header failed : \n"); + tet_result(TET_FAIL); + } +} + +/*Testcase : uts_Email_Sync_Header_03 + TestObjective : To validate parameter for mailbox in download email headers + APIs Tested : int email_sync_header(int input_account_id, int input_maibox_id, unsigned* handle) + */ + +static void uts_Email_Sync_Header_03() +{ + int err_code = EMAIL_ERROR_NONE; + int handle; + + tet_infoline("uts_Email_Sync_Header_03 Begin\n"); + + + err_code = email_sync_header(-1, -1 , &handle); + if (EMAIL_ERROR_NONE != err_code) { + tet_infoline("Email sync mail header : success\n"); + tet_result(TET_PASS); + } + else { + tet_printf("Email sync mail header failed : \n"); + tet_result(TET_FAIL); + } +} + diff --git a/TC/TC_email_service/TC_Network/uts_email_sync_header.h b/TC/TC_email_service/TC_Network/uts_email_sync_header.h new file mode 100755 index 0000000..e1361dd --- /dev/null +++ b/TC/TC_email_service/TC_Network/uts_email_sync_header.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2012 - 2013 Samsung Electronics, Co., Ltd. + * All rights reserved. + * + * This software is a confidential and proprietary information of Samsung + * Electronics, Co., Ltd. ("Confidential Information"). 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. + */ + +#include <tet_api.h> + +#include <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <sqlite3.h> +#include "email-api-init.h" +#include "email-api-account.h" +#include "email-api-mailbox.h" + +static void startup(), cleanup(); +void (*tet_startup) () = startup; +void (*tet_cleanup) () = cleanup; + + +static void uts_Email_Sync_Header_01(void); +static void uts_Email_Sync_Header_02(void); +static void uts_Email_Sync_Header_03(void); + + + + + +struct tet_testlist tet_testlist[] = { {uts_Email_Sync_Header_01, 1}, {uts_Email_Sync_Header_02, 2}, {uts_Email_Sync_Header_03, 3}, {NULL, 0} +}; diff --git a/TC/TC_email_service/TC_Network/uts_email_sync_header_for_all_account.c b/TC/TC_email_service/TC_Network/uts_email_sync_header_for_all_account.c new file mode 100755 index 0000000..626b73c --- /dev/null +++ b/TC/TC_email_service/TC_Network/uts_email_sync_header_for_all_account.c @@ -0,0 +1,105 @@ +/* +* Copyright (c) 2012 - 2013 Samsung Electronics, Inc. +* All rights reserved. +* +* This software is a confidential and proprietary information of Samsung +* Electronics, Inc. ("Confidential Information"). 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. +*/ + +/*************************************** +* add your header file here +* e.g., +* #include "uts_ApplicationLib_recurGetDayOfWeek_func.h" +***************************************/ +#include "uts_email_sync_header_for_all_account.h" +#include "../TC_Utility/uts-email-real-utility.c" + + +sqlite3 *sqlite_emmb; + + +static void startup() +{ + tet_printf("\n TC startup"); + + if (EMAIL_ERROR_NONE == email_service_begin()) { + tet_infoline("Email service Begin\n"); + if (EMAIL_ERROR_NONE == email_open_db()) + tet_infoline("Email open DB success\n"); + else + tet_infoline("Email open DB failed\n"); + } + else + tet_infoline("Email service not started\n"); + +} + +static void cleanup() +{ + tet_printf("\n TC End"); + + if (EMAIL_ERROR_NONE == email_close_db()) { + tet_infoline("Email Close DB Success\n"); + if (EMAIL_ERROR_NONE == email_service_end()) + tet_infoline("Email service close Success\n"); + else + tet_infoline("Email service end failed\n"); + } + else + tet_infoline("Email Close DB failed\n"); +} + + + + +/*************************************** +* add your Test Cases +* e.g., +* static void uts_ApplicationLib_recurGetDayOfWeek_01() +* { +* int ret; +* +* ret = target_api(); +* if (ret == 1) +* tet_result(TET_PASS); +* else +* tet_result(TET_FAIL); +* } +* +* static void uts_ApplicationLib_recurGetDayOfWeek_02() +* { +* code.. +* condition1 +* tet_result(TET_PASS); +* condition2 +* tet_result(TET_FAIL); +* } +* +***************************************/ + +/*Testcase : uts_Eemail_Sync_Header_For_All_Account_01 + TestObjective : To download email headers for all account + APIs Tested : int email_sync_header_for_all_account(unsigned *handle) + */ + +static void uts_Email_Sync_Header_For_All_Account_01() +{ + int err_code = EMAIL_ERROR_NONE; + email_mailbox_t mbox; + int handle; + + tet_infoline("uts_email_sync_header_for_all_account_01 Begin\n"); + + err_code = email_sync_header_for_all_account(&handle); + if (EMAIL_ERROR_NONE == err_code) { + tet_infoline("Email sync mail header for all account : success\n"); + tet_result(TET_PASS); + } + else { + tet_printf("Email sync mail header for all account failed : error_code[%d]\n", err_code); + tet_result(TET_FAIL); + } +} + diff --git a/TC/TC_email_service/TC_Network/uts_email_sync_header_for_all_account.h b/TC/TC_email_service/TC_Network/uts_email_sync_header_for_all_account.h new file mode 100755 index 0000000..d368267 --- /dev/null +++ b/TC/TC_email_service/TC_Network/uts_email_sync_header_for_all_account.h @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2012 - 2013 Samsung Electronics, Co., Ltd. + * All rights reserved. + * + * This software is a confidential and proprietary information of Samsung + * Electronics, Co., Ltd. ("Confidential Information"). 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. + */ + +#include <tet_api.h> + +#include <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <sqlite3.h> +#include "email-api-init.h" +#include "email-api-account.h" +#include "email-api-mailbox.h" + +static void startup(), cleanup(); +void (*tet_startup) () = startup; +void (*tet_cleanup) () = cleanup; + + +static void uts_Email_Sync_Header_For_All_Account_01(void); + + + + + +struct tet_testlist tet_testlist[] = { {uts_Email_Sync_Header_For_All_Account_01, 1}, {NULL, 0} +}; diff --git a/TC/TC_email_service/TC_Rule/Makefile b/TC/TC_email_service/TC_Rule/Makefile new file mode 100755 index 0000000..4abc2fb --- /dev/null +++ b/TC/TC_email_service/TC_Rule/Makefile @@ -0,0 +1,52 @@ +################################################### +# add your TestCase List Here +# +# e.g., +# TC1 = utc_frameworkName_apiName_func +# TC2 = utc_ApplicationLib_recurGetDayOfWeek_func +TARGETS = uts-email-add-rule \ + uts-email-delete-rule \ + uts-email-get-rule \ + uts-email-get-rule-list \ + uts-email-update-rule \ + uts-email-free-rule + +################################################### +# add your Package Config Info Here +# +# e.g., +# PKGS=calendar +PKGS= email-service + +LIBS = `pkg-config --libs $(PKGS)` +LIBS += `pkg-config --libs glib-2.0` +LIBS +=$(TET_ROOT)/lib/tet3/tcm_s.o +LIBS +=-L$(TET_ROOT)/lib/tet3 -ltcm_s +LIBS +=-L$(TET_ROOT)/lib/tet3 -lapi_s + +INCS = -I. `pkg-config --cflags $(PKGS)` +INCS += -I. `pkg-config --cflags glib-2.0` +INCS += -I$(TET_ROOT)/inc/tet3 +INCS += -I$(TET_SUITE_ROOT)/TC_email_service/TC_Utility + +UTIL_SRC = $(TET_SUITE_ROOT)/TC_email_service/TC_Utility/uts-email-dummy-utility.c +UTIL_SRC += $(TET_SUITE_ROOT)/TC_email_service/TC_Utility/uts-email-real-utility.c + +CFLAGS = $(INCS) +CFLAGS += -D_TETWARE_MODE +LDFLAGS = $(LIBS) + +################################################### +# Modify here +# depending on the Test Case you want to build +# +# e.g., +# TCLIST = $(TC1) $(TC2) +all : $(TARGETS) + +$(TARGETS) : %: %.c + $(CC) -o $@ $< $(CFLAGS) $(LDFLAGS) + +clean : + rm -rf $(TARGETS) + diff --git a/TC/TC_email_service/TC_Rule/tslist b/TC/TC_email_service/TC_Rule/tslist new file mode 100755 index 0000000..dc0f06e --- /dev/null +++ b/TC/TC_email_service/TC_Rule/tslist @@ -0,0 +1,6 @@ +uts-email-add-rule +uts-email-get-rule +uts-email-get-rule-list +uts-email-update-rule +uts-email-free-rule +uts-email-delete-rule diff --git a/TC/TC_email_service/TC_Rule/uts-email-add-rule.c b/TC/TC_email_service/TC_Rule/uts-email-add-rule.c new file mode 100755 index 0000000..fc6f4c0 --- /dev/null +++ b/TC/TC_email_service/TC_Rule/uts-email-add-rule.c @@ -0,0 +1,141 @@ +/* +* Copyright (c) 2012 - 2013 Samsung Electronics, Inc. +* All rights reserved. +* +* This software is a confidential and proprietary information of Samsung +* Electronics, Inc. ("Confidential Information"). 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. +*/ + + +#include "uts-email-add-rule.h" +#include "../TC_Utility/uts-email-dummy-utility.c" + + + +sqlite3 *sqlite_emmb; +static int g_accountId; + +static void startup() +{ + int err_code = EMAIL_ERROR_NONE; + int count = 0; + int i = 0; + email_account_t *pAccount = NULL ; + + tet_printf("\n TC startup"); + + if (EMAIL_ERROR_NONE == email_service_begin()) { + tet_infoline("Email service Begin\n"); + if (EMAIL_ERROR_NONE == email_open_db()) { + tet_infoline("Email open DB success\n"); + err_code = email_get_account_list(&pAccount, &count); + if (!count) + g_accountId = uts_Email_Add_Dummy_Account_01(); + else + g_accountId = pAccount[i].account_id; + email_free_account(&pAccount, count); + + } + else + tet_infoline("Email open DB failed\n"); + } + else + tet_infoline("Email service not started\n"); +} + +static void cleanup() +{ + tet_printf("\n TC End"); + if (EMAIL_ERROR_NONE == email_close_db()) { + tet_infoline("Email Close DB Success\n"); + if (EMAIL_ERROR_NONE == email_service_end()) + tet_infoline("Email service close Success\n"); + else + tet_infoline("Email service end failed\n"); + } + else + tet_infoline("Email Cloase DB failed\n"); +} + + + + + + +/*Testcase : uts_Email_Add_Rule_01 + TestObjective : To add a filter rule to an email account + APIs Tested : int email_add_rule(email_rule_t *filtering_set) + */ + +static void uts_Email_Add_Rule_01() +{ + int err_code = EMAIL_ERROR_NONE ; + email_rule_t *pRule; + int count = 0; + int i = 0; + email_account_t *pAccount = NULL ; + email_mailbox_t *src_mailbox = NULL; + + tet_infoline("uts_Email_Add_Rule_01 Begin\n"); + + pRule = (email_rule_t *)malloc(sizeof(email_rule_t)); + memset(pRule, 0x00, sizeof(email_rule_t)); + + err_code = email_get_mailbox_by_mailbox_type(g_accountId, EMAIL_MAILBOX_TYPE_INBOX, &src_mailbox); + if (EMAIL_ERROR_NONE != err_code) { + tet_printf("Email get mailbox by mailbox type failed : error_code[%d]\n", err_code); + tet_result(TET_UNRESOLVED); + } + + pRule->account_id = g_accountId; + pRule->type = RULE_TYPE_INCLUDES; + pRule->value = strdup("a"); + pRule->faction = EMAIL_FILTER_BLOCK; + pRule->target_mailbox_id = src_mailbox->mailbox_id; + pRule->flag1 = 1; + pRule->flag2 = 0; + err_code = email_add_rule(pRule); + if (EMAIL_ERROR_NONE == err_code || EMAIL_ERROR_ALREADY_EXISTS == err_code) { + tet_infoline("Email add rule Success\n"); + tet_result(TET_PASS); + } + else { + tet_printf("Email add rule failed : error_code[%d]\n", err_code); + tet_result(TET_FAIL); + } + email_free_rule(&pRule, 1); + + if (src_mailbox) { + email_free_mailbox(&src_mailbox, 1); + src_mailbox = NULL; + } +} + + +/*Testcase : uts_Email_Add_Rule_02 + TestObjective : To validate parameter for add a filter rule to an email account + APIs Tested : int email_add_rule(email_rule_t *filtering_set) + */ + +static void uts_Email_Add_Rule_02() +{ + int err_code = EMAIL_ERROR_NONE ; + email_rule_t *pRule = NULL; + + tet_infoline("uts_Email_Add_Rule_02 Begin\n"); + + err_code = email_add_rule(pRule); + if (EMAIL_ERROR_NONE != err_code) { + tet_infoline("Email add rule Success\n"); + tet_result(TET_PASS); + } + else { + tet_printf("Email add rule failed : \n"); + tet_result(TET_FAIL); + } +} + + + diff --git a/TC/TC_email_service/TC_Rule/uts-email-add-rule.h b/TC/TC_email_service/TC_Rule/uts-email-add-rule.h new file mode 100755 index 0000000..71830ee --- /dev/null +++ b/TC/TC_email_service/TC_Rule/uts-email-add-rule.h @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2012 - 2013 Samsung Electronics, Co., Ltd. + * All rights reserved. + * + * This software is a confidential and proprietary information of Samsung + * Electronics, Co., Ltd. ("Confidential Information"). 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. + */ + +#include <tet_api.h> + + #include <string.h> + #include <stdlib.h> + #include <sqlite3.h> + #include "email-api-init.h" + #include "email-api-account.h" + #include "email-api-rule.h" + +static void startup(), cleanup(); +void (*tet_startup) () = startup; +void (*tet_cleanup) () = cleanup; + +static void uts_Email_Add_Rule_01(void); +static void uts_Email_Add_Rule_02(void); + + + + struct tet_testlist tet_testlist[] = { {uts_Email_Add_Rule_01, 1}, {uts_Email_Add_Rule_02, 2}, {NULL, 0} + }; diff --git a/TC/TC_email_service/TC_Rule/uts-email-delete-rule.c b/TC/TC_email_service/TC_Rule/uts-email-delete-rule.c new file mode 100755 index 0000000..af9f9f3 --- /dev/null +++ b/TC/TC_email_service/TC_Rule/uts-email-delete-rule.c @@ -0,0 +1,191 @@ +/* +* Copyright (c) 2012 - 2013 Samsung Electronics, Inc. +* All rights reserved. +* +* This software is a confidential and proprietary information of Samsung +* Electronics, Inc. ("Confidential Information"). 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. +*/ + + +#include "uts-email-delete-rule.h" +#include "../TC_Utility/uts-email-dummy-utility.c" + + +sqlite3 *sqlite_emmb; +static int g_accountId; + +static void startup() +{ + int err_code = EMAIL_ERROR_NONE; + int count = 0; + int i = 0; + email_account_t *pAccount = NULL ; + + tet_printf("\n TC startup"); + + if (EMAIL_ERROR_NONE == email_service_begin()) { + tet_infoline("Email service Begin\n"); + if (EMAIL_ERROR_NONE == email_open_db()) { + tet_infoline("Email open DB success\n"); + err_code = email_get_account_list(&pAccount, &count); + if (!count) { + g_accountId = uts_Email_Add_Dummy_Account_01(); + } + else + g_accountId = pAccount[i].account_id; + email_free_account(&pAccount, count); + + } + else + tet_infoline("Email open DB failed\n"); + } + else + tet_infoline("Email service not started\n"); +} + +static void cleanup() +{ + tet_printf("\n TC End"); + if (EMAIL_ERROR_NONE == email_close_db()) { + tet_infoline("Email Close DB Success\n"); + if (EMAIL_ERROR_NONE == email_service_end()) + tet_infoline("Email service close Success\n"); + else + tet_infoline("Email service end failed\n"); + } + else + tet_infoline("Email Cloase DB failed\n"); +} + + + + +/*************************************** +* add your Test Cases +* e.g., +* static void utc_ApplicationLib_recurGetDayOfWeek_01() +* { +* int ret; +* +* ret = target_api(); +* if (ret == 1) +* tet_result(TET_PASS); +* else +* tet_result(TET_FAIL); +* } +* +* static void utc_ApplicationLib_recurGetDayOfWeek_02() +* { +* code.. +* condition1i +* tet_result(TET_PASS); +* condition2 +* tet_result(TET_FAIL); +* } +* +***************************************/ + + +/*Testcase : utc_Email_Delete_Rule_01 + TestObjective : To delete filter rule information + APIs Tested : int email_delete_rule(int filter_id) + */ + +static void uts_Email_Delete_Rule_01() +{ + int err_code = EMAIL_ERROR_NONE ; + int count = 0; + int i = 0; + email_rule_t *pRule_list = NULL; + email_rule_t *pRule = NULL; + email_mailbox_t *mailbox = NULL; + + tet_infoline("uts_Email_Delete_Rule_01 Begin\n"); + + tet_printf("Email Add rule\n"); + pRule = (email_rule_t *)malloc(sizeof(email_rule_t)); + memset(pRule, 0x00, sizeof(email_rule_t)); + + err_code = email_get_mailbox_by_mailbox_type(g_accountId, EMAIL_MAILBOX_TYPE_INBOX, &mailbox); + if (EMAIL_ERROR_NONE != err_code) { + tet_printf("Email get mailbox by mailbox type failed : error_code[%d]\n", err_code); + tet_result(TET_UNRESOLVED); + } + + pRule->account_id = g_accountId; + pRule->type = RULE_TYPE_INCLUDES; + pRule->value = strdup("a"); + pRule->faction = EMAIL_FILTER_BLOCK; + pRule->target_mailbox_id = mailbox->mailbox_id; + pRule->flag1 = 1; + pRule->flag2 = 0; + err_code = email_add_rule(pRule); + if (EMAIL_ERROR_NONE == err_code || EMAIL_ERROR_ALREADY_EXISTS == err_code) { + tet_infoline("Email add rule Success\n"); + } + else { + tet_printf("Email add rule failed : error_code[%d]\n", err_code); + tet_result(TET_FAIL); + } + email_free_rule(&pRule, 1); + + tet_printf("Email Get Rule List\n"); + err_code = email_get_rule_list(&pRule_list, &count); + if (EMAIL_ERROR_NONE == err_code) { + tet_infoline("Email get all filter rule Success\n"); + if (count > 0) { + tet_printf("Email Delete Rule : rule id [%d]\n", pRule_list[0].filter_id); + err_code = email_delete_rule(pRule_list[0].filter_id); + if (EMAIL_ERROR_NONE == err_code) { + tet_infoline("Email delete filter rule : Success\n"); + tet_result(TET_PASS); + } + else { + tet_printf("Email delete filter rule failed : error_code[%d]\n", err_code); + tet_result(TET_FAIL); + } + + } + else { + tet_infoline("NO filter rule found : Success\n"); + tet_result(TET_UNRESOLVED); + } + } + else { + tet_printf("Email get all filter rule failed : error_code[%d]\n", err_code); + tet_result(TET_UNRESOLVED); + } + if (mailbox) { + email_free_mailbox(&mailbox, 1); + mailbox = NULL; + } +} + + +/*Testcase : uts_Email_Delete_Rule_02 + TestObjective : To validate parameter for delete filter rule information + APIs Tested : int email_delete_rule(int filter_id) + */ + +static void uts_Email_Delete_Rule_02() +{ + int err_code = EMAIL_ERROR_NONE ; + email_rule_t *pRule = NULL; + + tet_infoline("uts_Email_Delete_Rule_02 Begin\n"); + + err_code = email_delete_rule(0); + if (EMAIL_ERROR_NONE != err_code) { + tet_infoline("Email delete filter rule Success\n"); + tet_result(TET_PASS); + } + else { + tet_printf("Email delete filter rule failed\n"); + tet_result(TET_FAIL); + } +} + + + diff --git a/TC/TC_email_service/TC_Rule/uts-email-delete-rule.h b/TC/TC_email_service/TC_Rule/uts-email-delete-rule.h new file mode 100755 index 0000000..8e8b883 --- /dev/null +++ b/TC/TC_email_service/TC_Rule/uts-email-delete-rule.h @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2012 - 2013 Samsung Electronics, Co., Ltd. + * All rights reserved. + * + * This software is a confidential and proprietary information of Samsung + * Electronics, Co., Ltd. ("Confidential Information"). 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. + */ + +#include <tet_api.h> + + #include <string.h> + #include <stdlib.h> + #include <sqlite3.h> + #include "email-api-init.h" + #include "email-api-account.h" + #include "email-api-rule.h" + +static void startup(), cleanup(); +void (*tet_startup) () = startup; +void (*tet_cleanup) () = cleanup; + +static void uts_Email_Delete_Rule_01(void); +static void uts_Email_Delete_Rule_02(void); + + + + struct tet_testlist tet_testlist[] = { {uts_Email_Delete_Rule_01, 1}, {uts_Email_Delete_Rule_02, 2}, {NULL, 0} + }; diff --git a/TC/TC_email_service/TC_Rule/uts-email-free-rule.c b/TC/TC_email_service/TC_Rule/uts-email-free-rule.c new file mode 100755 index 0000000..bdbf1a2 --- /dev/null +++ b/TC/TC_email_service/TC_Rule/uts-email-free-rule.c @@ -0,0 +1,112 @@ +/* +* Copyright (c) 2012 - 2013 Samsung Electronics, Inc. +* All rights reserved. +* +* This software is a confidential and proprietary information of Samsung +* Electronics, Inc. ("Confidential Information"). 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. +*/ + + +#include "uts-email-free-rule.h" +#include "../TC_Utility/uts-email-dummy-utility.c" + + +sqlite3 *sqlite_emmb; +int g_accountId; + +static void startup() +{ + int err_code = EMAIL_ERROR_NONE; + int count = 0; + int i = 0; + email_account_t *pAccount = NULL ; + + tet_printf("\n TC startup"); + + if (EMAIL_ERROR_NONE == email_service_begin()) { + tet_infoline("Email service Begin\n"); + if (EMAIL_ERROR_NONE == email_open_db()) { + tet_infoline("Email open DB success\n"); + err_code = email_get_account_list(&pAccount, &count); + if (!count) { + g_accountId = uts_Email_Add_Dummy_Account_01(); + } + else + g_accountId = pAccount[i].account_id; + email_free_account(&pAccount, count); + } + else + tet_infoline("Email open DB failed\n"); + } + else + tet_infoline("Email service not started\n"); +} + +static void cleanup() +{ + tet_printf("\n TC End"); + if (EMAIL_ERROR_NONE == email_close_db()) { + tet_infoline("Email Close DB Success\n"); + if (EMAIL_ERROR_NONE == email_service_end()) + tet_infoline("Email service close Success\n"); + else + tet_infoline("Email service end failed\n"); + } + else + tet_infoline("Email Cloase DB failed\n"); +} + + + + + + +/*Testcase : uts_Email_Free_Rule_01 + TestObjective : To free allcated memory for a filter rule + APIs Tested : int email_free_rule(email_rule_t *filtering_set, int count) + */ + +static void uts_Email_Free_Rule_01() +{ + int err_code = EMAIL_ERROR_NONE ; + email_rule_t *pRule; + email_mailbox_t *mailbox = NULL; + + tet_infoline("uts_Email_Free_Rule_01 Begin\n"); + + pRule = (email_rule_t *)malloc(sizeof(email_rule_t)); + memset(pRule, 0x00, sizeof(email_rule_t)); + + err_code = email_get_mailbox_by_mailbox_type(g_accountId, EMAIL_MAILBOX_TYPE_INBOX, &mailbox); + if (EMAIL_ERROR_NONE != err_code) { + tet_printf("Email get mailbox by mailbox type failed : error_code[%d]\n", err_code); + tet_result(TET_UNRESOLVED); + } + + pRule->account_id = g_accountId; + pRule->type = RULE_TYPE_INCLUDES; + pRule->value = strdup("a"); + pRule->faction = EMAIL_FILTER_BLOCK; + pRule->target_mailbox_id = mailbox->mailbox_id; + pRule->flag1 = 1; + pRule->flag2 = 0; + + err_code = email_free_rule(&pRule, 1); + if (EMAIL_ERROR_NONE == err_code) { + tet_infoline("Email free rule success\n"); + tet_result(TET_PASS); + } + else { + tet_infoline("Email free rule failed\n"); + tet_result(TET_FAIL); + } + if (mailbox) { + email_free_mailbox(&mailbox, 1); + mailbox = NULL; + } +} + + + diff --git a/TC/TC_email_service/TC_Rule/uts-email-free-rule.h b/TC/TC_email_service/TC_Rule/uts-email-free-rule.h new file mode 100755 index 0000000..744a546 --- /dev/null +++ b/TC/TC_email_service/TC_Rule/uts-email-free-rule.h @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2012 - 2013 Samsung Electronics, Co., Ltd. + * All rights reserved. + * + * This software is a confidential and proprietary information of Samsung + * Electronics, Co., Ltd. ("Confidential Information"). 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. + */ + +#include <tet_api.h> + + #include <string.h> + #include <stdlib.h> + #include <sqlite3.h> + #include "email-api-init.h" + #include "email-api-account.h" + #include "email-api-rule.h" + +static void startup(), cleanup(); +void (*tet_startup) () = startup; +void (*tet_cleanup) () = cleanup; + +static void uts_Email_Free_Rule_01(void); + + + + struct tet_testlist tet_testlist[] = { {uts_Email_Free_Rule_01, 1}, {NULL, 0} + }; diff --git a/TC/TC_email_service/TC_Rule/uts-email-get-rule-list.c b/TC/TC_email_service/TC_Rule/uts-email-get-rule-list.c new file mode 100755 index 0000000..6651b83 --- /dev/null +++ b/TC/TC_email_service/TC_Rule/uts-email-get-rule-list.c @@ -0,0 +1,178 @@ +/* +* Copyright (c) 2012 - 2013 Samsung Electronics, Inc. +* All rights reserved. +* +* This software is a confidential and proprietary information of Samsung +* Electronics, Inc. ("Confidential Information"). 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. +*/ + + +#include "uts-email-get-rule-list.h" +#include "../TC_Utility/uts-email-dummy-utility.c" + + +sqlite3 *sqlite_emmb; +static int g_accountId; + +static void startup() +{ + int err_code = EMAIL_ERROR_NONE; + int count = 0; + int i = 0; + email_account_t *pAccount = NULL ; + + tet_printf("\n TC startup"); + + if (EMAIL_ERROR_NONE == email_service_begin()) { + tet_infoline("Email service Begin\n"); + if (EMAIL_ERROR_NONE == email_open_db()) { + tet_infoline("Email open DB success\n"); + err_code = email_get_account_list(&pAccount, &count); + if (!count) { + g_accountId = uts_Email_Add_Dummy_Account_01(); + } + else + g_accountId = pAccount[i].account_id; + email_free_account(&pAccount, count); + + } + else + tet_infoline("Email open DB failed\n"); + } + else + tet_infoline("Email service not started\n"); +} + +static void cleanup() +{ + tet_printf("\n TC End"); + if (EMAIL_ERROR_NONE == email_close_db()) { + tet_infoline("Email Close DB Success\n"); + if (EMAIL_ERROR_NONE == email_service_end()) + tet_infoline("Email service close Success\n"); + else + tet_infoline("Email service end failed\n"); + } + else + tet_infoline("Email Cloase DB failed\n"); +} + + + + + + + +/*Testcase : uts_Email_Get_Rule_List_01 + TestObjective : To get all filter rule information + APIs Tested : int email_get_rule_list(email_rule_t **filtering_set, int *count) + */ + +static void uts_Email_Get_Rule_List_01() +{ + int err_code = EMAIL_ERROR_NONE ; + int count = 0; + email_rule_t *pRule_list = NULL; + email_rule_t *pRule = NULL; + email_mailbox_t *mailbox = NULL; + + tet_infoline("uts_Email_Get_Rule_List_01 Begin\n"); + + + tet_printf("Email Add rule\n"); + pRule = (email_rule_t *)malloc(sizeof(email_rule_t)); + memset(pRule, 0x00, sizeof(email_rule_t)); + + err_code = email_get_mailbox_by_mailbox_type(g_accountId, EMAIL_MAILBOX_TYPE_INBOX, &mailbox); + if (EMAIL_ERROR_NONE != err_code) { + tet_printf("Email get mailbox by mailbox type failed : error_code[%d]\n", err_code); + tet_result(TET_UNRESOLVED); + } + + pRule->account_id = g_accountId; + pRule->type = RULE_TYPE_INCLUDES; + pRule->value = strdup("a"); + pRule->faction = EMAIL_FILTER_BLOCK; + pRule->target_mailbox_id = mailbox->mailbox_id; + pRule->flag1 = 1; + pRule->flag2 = 0; + err_code = email_add_rule(pRule); + if (EMAIL_ERROR_NONE == err_code || EMAIL_ERROR_ALREADY_EXISTS == err_code) { + tet_infoline("Email add rule Success\n"); + } + else { + tet_printf("Email add rule failed : error_code[%d]\n", err_code); + tet_result(TET_FAIL); + } + email_free_rule(&pRule, 1); + + tet_printf("Email Get Rule List\n"); + + err_code = email_get_rule_list(&pRule_list, &count); + if (EMAIL_ERROR_NONE == err_code) { + tet_infoline("Email get all filter rule Success\n"); + tet_result(TET_PASS); + } + else { + tet_printf("Email get all filter rule failed : error_code[%d]\n", err_code); + tet_result(TET_FAIL); + } + if (mailbox) { + email_free_mailbox(&mailbox, 1); + mailbox = NULL; + } +} + + +/*Testcase : uts_Email_Get_Rule_List_02 + TestObjective : To validate parameter for filtering_set in get all filter rule information + APIs Tested : int email_get_rule_list(email_rule_t **filtering_set, int *count) + */ + +static void uts_Email_Get_Rule_List_02() +{ + int err_code = EMAIL_ERROR_NONE ; + int count = 0; + email_rule_t *pRule = NULL; + + tet_infoline("uts_Email_Get_Rule_List_02 Begin\n"); + + err_code = email_get_rule_list(NULL, &count); + if (EMAIL_ERROR_NONE != err_code) { + tet_infoline("Email get all filter rule Success\n"); + tet_result(TET_PASS); + } + else { + tet_printf("Email get all filter rule failed\n"); + tet_result(TET_FAIL); + } +} + + +/*Testcase : uts_Email_Get_Rule_List_03 + TestObjective : To validate parameter for count in get all filter rule information + APIs Tested : int email_get_rule_list(email_rule_t **filtering_set, int *count) + */ + +static void uts_Email_Get_Rule_List_03() +{ + int err_code = EMAIL_ERROR_NONE ; + int count = 0; + email_rule_t *pRule = NULL; + + tet_infoline("uts_Email_Get_Rule_List_03 Begin\n"); + + err_code = email_get_rule_list(&pRule, 0); + if (EMAIL_ERROR_NONE != err_code) { + tet_infoline("Email get all filter rule Success\n"); + tet_result(TET_PASS); + } + else { + tet_printf("Email get all filter rule failed\n"); + tet_result(TET_FAIL); + } +} + + diff --git a/TC/TC_email_service/TC_Rule/uts-email-get-rule-list.h b/TC/TC_email_service/TC_Rule/uts-email-get-rule-list.h new file mode 100755 index 0000000..92725c3 --- /dev/null +++ b/TC/TC_email_service/TC_Rule/uts-email-get-rule-list.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2012 - 2013 Samsung Electronics, Co., Ltd. + * All rights reserved. + * + * This software is a confidential and proprietary information of Samsung + * Electronics, Co., Ltd. ("Confidential Information"). 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. + */ + +#include <tet_api.h> + + #include <string.h> + #include <stdlib.h> + #include <sqlite3.h> + #include "email-api-init.h" + #include "email-api-account.h" + #include "email-api-rule.h" + +static void startup(), cleanup(); +void (*tet_startup) () = startup; +void (*tet_cleanup) () = cleanup; + +static void uts_Email_Get_Rule_List_01(void); +static void uts_Email_Get_Rule_List_02(void); +static void uts_Email_Get_Rule_List_03(void); + + + + struct tet_testlist tet_testlist[] = { {uts_Email_Get_Rule_List_01, 1}, {uts_Email_Get_Rule_List_02, 2}, {uts_Email_Get_Rule_List_03, 3}, {NULL, 0} + }; diff --git a/TC/TC_email_service/TC_Rule/uts-email-get-rule.c b/TC/TC_email_service/TC_Rule/uts-email-get-rule.c new file mode 100755 index 0000000..4924806 --- /dev/null +++ b/TC/TC_email_service/TC_Rule/uts-email-get-rule.c @@ -0,0 +1,169 @@ +/* +* Copyright (c) 2012 - 2013 Samsung Electronics, Inc. +* All rights reserved. +* +* This software is a confidential and proprietary information of Samsung +* Electronics, Inc. ("Confidential Information"). 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. +*/ + + +#include "uts-email-get-rule.h" +#include "../TC_Utility/uts-email-dummy-utility.c" + + +sqlite3 *sqlite_emmb; +static int g_accountId; + +static void startup() +{ + int err_code = EMAIL_ERROR_NONE; + int count = 0; + int i = 0; + email_account_t *pAccount = NULL ; + + tet_printf("\n TC startup"); + + if (EMAIL_ERROR_NONE == email_service_begin()) { + tet_infoline("Email service Begin\n"); + if (EMAIL_ERROR_NONE == email_open_db()) { + tet_infoline("Email open DB success\n"); + err_code = email_get_account_list(&pAccount, &count); + if (!count) { + g_accountId = uts_Email_Add_Dummy_Account_01(); + } + else + g_accountId = pAccount[i].account_id; + email_free_account(&pAccount, count); + + } + else + tet_infoline("Email open DB failed\n"); + } + else + tet_infoline("Email service not started\n"); +} + +static void cleanup() +{ + tet_printf("\n TC End"); + if (EMAIL_ERROR_NONE == email_close_db()) { + tet_infoline("Email Close DB Success\n"); + if (EMAIL_ERROR_NONE == email_service_end()) + tet_infoline("Email service close Success\n"); + else + tet_infoline("Email service end failed\n"); + } + else + tet_infoline("Email Cloase DB failed\n"); +} + + + + + + +/*Testcase : uts_Email_Get_Rule_01 + TestObjective : To get filter information + APIs Tested : int email_get_rule(int filter_id, email_rule_t **filter_info) + */ + +static void uts_Email_Get_Rule_01() +{ + int err_code = EMAIL_ERROR_NONE ; + int filter_id = 1; + email_rule_t *pRule = NULL; + email_mailbox_t *mailbox = NULL; + + tet_infoline("uts_Email_Get_Rule_01 Begin\n"); + + tet_printf("Email Add rule\n"); + pRule = (email_rule_t *)malloc(sizeof(email_rule_t)); + memset(pRule, 0x00, sizeof(email_rule_t)); + + err_code = email_get_mailbox_by_mailbox_type(g_accountId, EMAIL_MAILBOX_TYPE_INBOX, &mailbox); + if (EMAIL_ERROR_NONE != err_code) { + tet_printf("Email get mailbox by mailbox type failed : error_code[%d]\n", err_code); + tet_result(TET_UNRESOLVED); + } + + pRule->account_id = g_accountId; + pRule->type = RULE_TYPE_INCLUDES; + pRule->value = strdup("a"); + pRule->faction = EMAIL_FILTER_BLOCK; + pRule->target_mailbox_id = mailbox->mailbox_id; + pRule->flag1 = 1; + pRule->flag2 = 0; + err_code = email_add_rule(pRule); + if (EMAIL_ERROR_NONE == err_code || EMAIL_ERROR_ALREADY_EXISTS == err_code) { + tet_infoline("Email add rule Success\n"); + } + else { + tet_printf("Email add rule failed : error_code[%d]\n", err_code); + tet_result(TET_FAIL); + } + email_free_rule(&pRule, 1); + + err_code = email_get_rule(filter_id, &pRule); + if (EMAIL_ERROR_NONE == err_code) { + tet_infoline("Email get rule Success\n"); + tet_result(TET_PASS); + } + else { + tet_printf("Email get rule failed : error_code[%d]\n", err_code); + tet_result(TET_FAIL); + } + if (mailbox) { + email_free_mailbox(&mailbox, 1); + mailbox = NULL; + } +} + + +/*Testcase : uts_Email_Get_Rule_02 + TestObjective : To validate parameter for filter_info in find filter rule to an email account + APIs Tested : int email_get_rule(int filter_id, email_rule_t **filter_info) + */ + +static void uts_Email_Get_Rule_02() +{ + int err_code = EMAIL_ERROR_NONE ; + email_rule_t *pRule = NULL; + + tet_infoline("uts_Email_Get_Rule_02 Begin\n"); + + err_code = email_get_rule(1, NULL); + if (EMAIL_ERROR_NONE != err_code) { + tet_infoline("Email get rule Success\n"); + tet_result(TET_PASS); + } + else { + tet_printf("Email get rule failed\n"); + tet_result(TET_FAIL); + } +} + + +/*Testcase : uts_Email_Get_Rule_03 + TestObjective : To validate parameter for filter_id in find filter rule to an email account + APIs Tested : int email_get_rule(int filter_id, email_rule_t **filter_info) + */ + +static void uts_Email_Get_Rule_03() +{ + int err_code = EMAIL_ERROR_NONE ; + email_rule_t *pRule = NULL; + + tet_infoline("uts_Email_Get_Rule_03 Begin\n"); + + err_code = email_get_rule(0, &pRule); + if (EMAIL_ERROR_NONE != err_code) { + tet_infoline("Email get rule Success\n"); + tet_result(TET_PASS); + } + else { + tet_printf("Email get rule failed\n"); + tet_result(TET_FAIL); + } +} diff --git a/TC/TC_email_service/TC_Rule/uts-email-get-rule.h b/TC/TC_email_service/TC_Rule/uts-email-get-rule.h new file mode 100755 index 0000000..b007f32 --- /dev/null +++ b/TC/TC_email_service/TC_Rule/uts-email-get-rule.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2012 - 2013 Samsung Electronics, Co., Ltd. + * All rights reserved. + * + * This software is a confidential and proprietary information of Samsung + * Electronics, Co., Ltd. ("Confidential Information"). 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. + */ + +#include <tet_api.h> + + #include <string.h> + #include <stdlib.h> + #include <sqlite3.h> + #include "email-api-init.h" + #include "email-api-account.h" + #include "email-api-rule.h" + +static void startup(), cleanup(); +void (*tet_startup) () = startup; +void (*tet_cleanup) () = cleanup; + +static void uts_Email_Get_Rule_01(void); +static void uts_Email_Get_Rule_02(void); +static void uts_Email_Get_Rule_03(void); + + + + struct tet_testlist tet_testlist[] = { {uts_Email_Get_Rule_01, 1}, {uts_Email_Get_Rule_02, 2}, {uts_Email_Get_Rule_03, 3}, {NULL, 0} + }; diff --git a/TC/TC_email_service/TC_Rule/uts-email-update-rule.c b/TC/TC_email_service/TC_Rule/uts-email-update-rule.c new file mode 100755 index 0000000..5758faa --- /dev/null +++ b/TC/TC_email_service/TC_Rule/uts-email-update-rule.c @@ -0,0 +1,195 @@ +/* +* Copyright (c) 2012 - 2013 Samsung Electronics, Inc. +* All rights reserved. +* +* This software is a confidential and proprietary information of Samsung +* Electronics, Inc. ("Confidential Information"). 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. +*/ + + +#include "uts-email-update-rule.h" +#include "../TC_Utility/uts-email-dummy-utility.c" + + +sqlite3 *sqlite_emmb; +static int g_accountId; + +static void startup() +{ + int err_code = EMAIL_ERROR_NONE; + int count = 0; + int i = 0; + email_account_t *pAccount = NULL ; + + tet_printf("\n TC startup"); + + if (EMAIL_ERROR_NONE == email_service_begin()) { + tet_infoline("Email service Begin\n"); + if (EMAIL_ERROR_NONE == email_open_db()) { + tet_infoline("Email open DB success\n"); + err_code = email_get_account_list(&pAccount, &count); + if (!count) { + g_accountId = uts_Email_Add_Dummy_Account_01(); + } + else + g_accountId = pAccount[i].account_id; + email_free_account(&pAccount, count); + + } + else + tet_infoline("Email open DB failed\n"); + } + else + tet_infoline("Email service not started\n"); +} + +static void cleanup() +{ + tet_printf("\n TC End"); + if (EMAIL_ERROR_NONE == email_close_db()) { + tet_infoline("Email Close DB Success\n"); + if (EMAIL_ERROR_NONE == email_service_end()) + tet_infoline("Email service close Success\n"); + else + tet_infoline("Email service end failed\n"); + } + else + tet_infoline("Email Cloase DB failed\n"); +} + + + + + + +/*Testcase : uts_Email_Update_Rule_01 + TestObjective : To update filter rule information + APIs Tested : int email_update_rule(int filter_id, email_rule_t *new_set) + */ + +static void uts_Email_Update_Rule_01() +{ + int err_code = EMAIL_ERROR_NONE ; + int count = 0; + int i = 0; + email_rule_t *pRule_list = NULL; + email_rule_t *pNew_rule; + email_rule_t *pRule = NULL; + email_mailbox_t *mailbox = NULL; + + tet_infoline("uts_Email_Update_Rule_01 Begin\n"); + + tet_printf("Email Add rule\n"); + pRule = (email_rule_t *)malloc(sizeof(email_rule_t)); + memset(pRule, 0x00, sizeof(email_rule_t)); + + err_code = email_get_mailbox_by_mailbox_type(g_accountId, EMAIL_MAILBOX_TYPE_INBOX, &mailbox); + if (EMAIL_ERROR_NONE != err_code) { + tet_printf("Email get mailbox by mailbox type failed : error_code[%d]\n", err_code); + tet_result(TET_UNRESOLVED); + } + + pRule->account_id = g_accountId; + pRule->type = RULE_TYPE_INCLUDES; + pRule->value = strdup("a"); + pRule->faction = EMAIL_FILTER_BLOCK; + pRule->target_mailbox_id = mailbox->mailbox_id; + pRule->flag1 = 1; + pRule->flag2 = 0; + err_code = email_add_rule(pRule); + if (EMAIL_ERROR_NONE == err_code || EMAIL_ERROR_ALREADY_EXISTS == err_code) { + tet_infoline("Email add rule Success\n"); + } + else { + tet_printf("Email add rule failed : error_code[%d]\n", err_code); + tet_result(TET_FAIL); + } + email_free_rule(&pRule, 1); + + tet_printf("Email Get Rule List\n"); + err_code = email_get_rule_list(&pRule_list, &count); + if (EMAIL_ERROR_NONE == err_code && count > 0) { + tet_infoline("Email get all filter rule Success\n"); + pNew_rule = (email_rule_t *)malloc(sizeof(email_rule_t)); + memset(pNew_rule , 0x00, sizeof(email_rule_t)); + + pNew_rule->account_id = pRule_list[i].account_id; + pNew_rule->type = RULE_TYPE_EXACTLY; + pNew_rule->value = strdup("ab"); + pNew_rule->target_mailbox_id = mailbox->mailbox_id; + pNew_rule->faction = pRule_list[i].faction; + pNew_rule->flag1 = pRule_list[i].flag1; + pNew_rule->flag2 = pRule_list[i].flag2; + + tet_printf("Email Update Rule\n"); + err_code = email_update_rule(pRule_list[i].filter_id, pNew_rule); + if (EMAIL_ERROR_NONE == err_code) { + tet_infoline("Email update rule : Success\n"); + tet_result(TET_PASS); + } + else { + tet_printf("Email update filter rule failed : error_code[%d]\n", err_code); + tet_result(TET_FAIL); + } + email_free_rule(&pNew_rule, 1); + } + else { + tet_printf("Email get all filter rule failed : error_code[%d]\n", err_code); + tet_result(TET_UNRESOLVED); + } + if (mailbox) { + email_free_mailbox(&mailbox, 1); + mailbox = NULL; + } +} + + +/*Testcase : uts_Email_Update_Rule_02 + TestObjective : To validate parameter for new_set in update filter rule information + APIs Tested : int email_update_rule(int filter_id , email_rule_t *new_set) + */ + +static void uts_Email_Update_Rule_02() +{ + int err_code = EMAIL_ERROR_NONE ; + email_rule_t *pRule = NULL; + + tet_infoline("uts_Email_Update_Rule_02 Begin\n"); + + err_code = email_update_rule(1, NULL); + if (EMAIL_ERROR_NONE != err_code) { + tet_infoline("Email update filter rule Success\n"); + tet_result(TET_PASS); + } + else { + tet_printf("Email update filter rule failed\n"); + tet_result(TET_FAIL); + } +} + + +/*Testcase : uts_Email_Update_Rule_03 + TestObjective : To validate parameter for filter_id in update filter rule information + APIs Tested : int email_update_rule(int filter_id , email_rule_t *new_set) + */ + +static void uts_Email_Update_Rule_03() +{ + int err_code = EMAIL_ERROR_NONE ; + email_rule_t *pRule = NULL; + + tet_infoline("uts_Email_Update_Rule_03 Begin\n"); + + err_code = email_update_rule(0, pRule); + if (EMAIL_ERROR_NONE != err_code) { + tet_infoline("Email update filter rule Success\n"); + tet_result(TET_PASS); + } + else { + tet_printf("Email update filter rule failed\n"); + tet_result(TET_FAIL); + } +} + diff --git a/TC/TC_email_service/TC_Rule/uts-email-update-rule.h b/TC/TC_email_service/TC_Rule/uts-email-update-rule.h new file mode 100755 index 0000000..fe26b1a --- /dev/null +++ b/TC/TC_email_service/TC_Rule/uts-email-update-rule.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2012 - 2013 Samsung Electronics, Co., Ltd. + * All rights reserved. + * + * This software is a confidential and proprietary information of Samsung + * Electronics, Co., Ltd. ("Confidential Information"). 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. + */ + +#include <tet_api.h> + + #include <string.h> + #include <stdlib.h> + #include <sqlite3.h> + #include "email-api-init.h" + #include "email-api-account.h" + #include "email-api-rule.h" + +static void startup(), cleanup(); +void (*tet_startup) () = startup; +void (*tet_cleanup) () = cleanup; + +static void uts_Email_Update_Rule_01(void); +static void uts_Email_Update_Rule_02(void); +static void uts_Email_Update_Rule_03(void); + + + + struct tet_testlist tet_testlist[] = { {uts_Email_Update_Rule_01, 1}, {uts_Email_Update_Rule_02, 2}, {uts_Email_Update_Rule_03, 3}, {NULL, 0} + }; diff --git a/TC/TC_email_service/TC_Utility/uts-email-dummy-utility.c b/TC/TC_email_service/TC_Utility/uts-email-dummy-utility.c new file mode 100755 index 0000000..2590c07 --- /dev/null +++ b/TC/TC_email_service/TC_Utility/uts-email-dummy-utility.c @@ -0,0 +1,169 @@ +#include "uts-email-dummy-utility.h" + + +int uts_Email_Add_Dummy_Account_01() +{ + email_account_t *account = NULL; + int err_code = EMAIL_ERROR_NONE; + + tet_infoline("uts_Email_Add_Dummy_Account\n"); + account = (email_account_t *)malloc(sizeof(email_account_t)); + if (account) { + memset(account , 0x00, sizeof(email_account_t)); + + account->account_name = strdup("Gmail POP"); + account->user_display_name = strdup("samsungtest09"); + account->user_email_address = strdup("samsungtest09@gmail.com"); + account->reply_to_address = strdup("samsungtest09@gmail.com"); + account->return_address = strdup("samsungtest09@gmail.com"); + account->incoming_server_type = EMAIL_SERVER_TYPE_POP3; + account->incoming_server_address = strdup("pop.gmail.com"); + account->incoming_server_port_number = 995; + account->incoming_server_secure_connection = 1; + account->retrieval_mode = EMAIL_IMAP4_RETRIEVAL_MODE_NEW; + account->incoming_server_user_name = strdup("samsungtest09"); + account->incoming_server_password = strdup("samsung09"); + account->outgoing_server_type = EMAIL_SERVER_TYPE_SMTP; + account->outgoing_server_address = strdup("smtp.gmail.com"); + account->outgoing_server_port_number = 465; + account->outgoing_server_secure_connection = 1; + account->outgoing_server_need_authentication = 1; + account->outgoing_server_user_name = strdup("samsungtest09"); + account->outgoing_server_password = strdup("samsung09"); + account->pop_before_smtp = 0; + account->incoming_server_requires_apop = 0; + account->auto_download_size = 0; /* downloading option, 0 is subject only, 1 is text body, 2 is normal */ + account->outgoing_server_use_same_authenticator = 1; /* Specifies the 'Same as POP3' option, 0 is none, 1 is 'Same as POP3 */ + account->logo_icon_path = NULL; + 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.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 = strdup("Gmail POP3 Signature"); + account->check_interval = 0; + + err_code = email_add_account(account); + if (EMAIL_ERROR_NONE == err_code) { + printf("email add account : success\n"); + tet_printf("email add account : success\n"); + return account->account_id; + } + else { + printf("email add account : failed err_code[%d]", err_code); + tet_printf("email add account : failed err_code[%d]", err_code); + } + email_free_account(&account, 1); + } + return 0; +} + + +int uts_Email_Add_Dummy_Message_02() +{ + int err_code = EMAIL_ERROR_NONE; + int handle; + + email_mail_data_t *test_mail_data = NULL; + email_attachment_data_t *attachment_data = NULL; + email_meeting_request_t *meeting_req = NULL; + email_mailbox_t *mailbox = NULL; + + FILE *fp; + email_option_t option; + int count = 0; + int i = 0; + email_account_t *account = NULL ; + + memset(&option, 0x00, sizeof(email_option_t)); + option.keep_local_copy = 1; + + test_mail_data = malloc(sizeof(email_mail_data_t)); + memset(test_mail_data, 0x00, sizeof(email_mail_data_t)); + + attachment_data = malloc(sizeof(email_attachment_data_t)); + memset(attachment_data, 0x00, sizeof(email_attachment_data_t)); + + err_code = email_get_account_list(&account, &count); + if (EMAIL_ERROR_NONE == err_code && count > 0) { + + test_mail_data->account_id = account[i].account_id; + test_mail_data->flags_draft_field = 1; + + test_mail_data->save_status = 1; + test_mail_data->body_download_status = 1; + + test_mail_data->server_mail_id = strdup("TESTMAIL_1"); + + test_mail_data->full_address_from = strdup("<samsungtest09@gmail.com>"); + test_mail_data->full_address_to = strdup("<samsungtest09@gmail.com>"); + test_mail_data->subject = strdup("Test"); + + err_code = email_get_mailbox_by_mailbox_type(account[i].account_id , EMAIL_MAILBOX_TYPE_INBOX, &mailbox); + if (EMAIL_ERROR_NONE != err_code) { + tet_printf("Email get mailbox by mailbox type failed : error_code[%d]\n", err_code); + return err_code; + } + + test_mail_data->mailbox_id = mailbox->mailbox_id; + test_mail_data->mailbox_type = mailbox->mailbox_type; + + fp = fopen("/tmp/mail.txt", "w"); + fprintf(fp, "xxxxxxxxx"); + fclose(fp); + test_mail_data->file_path_plain = strdup("/tmp/mail.txt"); + test_mail_data->attachment_count = 1; + + fp = fopen("/tmp/attach.txt", "w"); + fprintf(fp, "Simple Attachment"); + fclose(fp); + + attachment_data->attachment_name = strdup("Attach"); + attachment_data->attachment_path = strdup("/tmp/attach.txt"); + attachment_data->save_status = 1; + + err_code = email_add_mail(test_mail_data, attachment_data, 1, NULL, 0); + if (EMAIL_ERROR_NONE == err_code) { + printf("email add mail : success\n"); + } + else { + printf("email add mail : failed err_code[%d]\n", err_code); + } + } + else { + printf("emaill get account list : failed err_code[%d]", err_code); + } + if (mailbox) { + email_free_mailbox(&mailbox, 1); + mailbox = NULL; + } + + return err_code; +} + +int uts_Email_Get_Mail_List_03(int account_id, email_mailbox_type_e mailbox_type, email_mail_list_item_t** mail_list, int* result_count, email_sort_type_t sorting) { + + email_mailbox_t *mailbox = NULL; + int err_code = EMAIL_ERROR_NONE; + + if(account_id != ALL_ACCOUNT && mailbox_type != 0) + err_code = email_get_mailbox_by_mailbox_type(account_id , mailbox_type, &mailbox); + + if (EMAIL_ERROR_NONE == err_code) { + err_code = email_get_mail_list(account_id , mailbox ? mailbox->mailbox_id : 0, 0, 0, EMAIL_GET_MAIL_LIST_MAX, sorting, mail_list, result_count); + } + + if (mailbox) { + email_free_mailbox(&mailbox, 1); + mailbox = NULL; + } + + return err_code; + +} diff --git a/TC/TC_email_service/TC_Utility/uts-email-dummy-utility.h b/TC/TC_email_service/TC_Utility/uts-email-dummy-utility.h new file mode 100755 index 0000000..5e82eda --- /dev/null +++ b/TC/TC_email_service/TC_Utility/uts-email-dummy-utility.h @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2012 - 2013 Samsung Electronics, Co., Ltd. + * All rights reserved. + * + * This software is a confidential and proprietary information of Samsung + * Electronics, Co., Ltd. ("Confidential Information"). 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. + */ + +/* #include <tet_api.h */ + +#include <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <sqlite3.h> +#include "email-api-init.h" +#include "email-api-account.h" +#include "email-api-mail.h" + +//#define email_get_mail_list(account_id, mailbox_name, mail_list, count, sorting) email_get_mail_list_ex(account_id, mailbox_name, EMAIL_LIST_TYPE_NORMAL, -1, -1, sorting, mail_list, count) +#define EMAIL_GET_MAIL_LIST_MAX 20 + +int uts_Email_Add_Dummy_Account_01(void); +int uts_Email_Add_Dummy_Message_02(void); +int uts_Email_Get_Mail_List_03(int account_id, email_mailbox_type_e mailbox_type, email_mail_list_item_t** mail_list, int* result_count, email_sort_type_t sorting); + +/* struct tet_testlist tet_testlist[] = */ +/* */ +/* { uts_Email_Add_Dummy_Account_01, 1} */ +/* { uts_Email_Add_Dummy_Message_02, 2} */ +/* {NULL, 0 */ +/* } */ diff --git a/TC/TC_email_service/TC_Utility/uts-email-real-utility.c b/TC/TC_email_service/TC_Utility/uts-email-real-utility.c new file mode 100755 index 0000000..462bcd1 --- /dev/null +++ b/TC/TC_email_service/TC_Utility/uts-email-real-utility.c @@ -0,0 +1,221 @@ +#include "uts-email-real-utility.h" + + +int uts_Email_Add_Real_Account_01() +{ + email_account_t *account = NULL; + int err_code = EMAIL_ERROR_NONE; + int handle; + int account_id = 0; + + tet_infoline("uts_Email_Add_Real_Account_01\n"); + + /* POP */ + tet_infoline("Add POP3 account\n"); + printf("Add POP3 account\n"); + account = (email_account_t *)malloc(sizeof(email_account_t)); + if (account) { + memset(account , 0x00, sizeof(email_account_t)); + + account->account_name = strdup("Gmail POP"); + account->user_display_name = strdup("samsungtest09"); + account->user_email_address = strdup("samsungtest09@gmail.com"); + account->reply_to_address = strdup("samsungtest09@gmail.com"); + account->return_address = strdup("samsungtest09@gmail.com"); + account->incoming_server_type = EMAIL_SERVER_TYPE_POP3; + account->incoming_server_address = strdup("pop.gmail.com"); + account->incoming_server_port_number = 995; + account->incoming_server_secure_connection = 1; + account->retrieval_mode = EMAIL_IMAP4_RETRIEVAL_MODE_NEW; + account->incoming_server_user_name = strdup("samsungtest09"); + account->incoming_server_password = strdup("samsung09"); + account->outgoing_server_type = EMAIL_SERVER_TYPE_SMTP; + account->outgoing_server_address = strdup("smtp.gmail.com"); + account->outgoing_server_port_number = 465; + account->outgoing_server_secure_connection = 1; + account->outgoing_server_need_authentication = 1; + account->outgoing_server_user_name = strdup("samsungtest09"); + account->outgoing_server_password = strdup("samsung09"); + account->pop_before_smtp = 0; + account->incoming_server_requires_apop = 0; + account->auto_download_size = 0; /* downloading option, 0 is subject only, 1 is text body, 2 is normal */ + account->outgoing_server_use_same_authenticator = 1; /* Specifies the 'Same as POP3' option, 0 is none, 1 is 'Same as POP3 */ + account->logo_icon_path = NULL; + 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.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 = strdup("Gmail POP3 Signature"); + account->check_interval = 0; + + err_code = email_add_account(account); + if (EMAIL_ERROR_NONE == err_code) { + printf("email add account : success\n"); + tet_printf("email add account : success\n"); + /* return account->account_id */ + account_id = account->account_id; + } + else { + printf("email add account : failed err_code[%d]", err_code); + tet_printf("email add account : failed err_code[%d]", err_code); + } + email_free_account(&account, 1); + } + + tet_infoline("Add IMAP4 account\n"); + printf("Add IMAP4 account\n"); + account = (email_account_t *)malloc(sizeof(email_account_t)); + if (account) { + memset(account , 0x00, sizeof(email_account_t)); + + account->account_name = strdup("Gmail IMAP"); + account->user_display_name = strdup("samsungtest09"); + account->user_email_address = strdup("samsungtest09@gmail.com"); + account->reply_to_address = strdup("samsungtest09@gmail.com"); + account->return_address = strdup("samsungtest09@gmail.com"); + account->incoming_server_type = EMAIL_SERVER_TYPE_IMAP4; + account->incoming_server_address = strdup("imap.gmail.com"); + account->incoming_server_port_number = 993; + account->incoming_server_secure_connection = 1; + account->retrieval_mode = EMAIL_IMAP4_RETRIEVAL_MODE_NEW; + account->incoming_server_user_name = strdup("samsungtest09"); + account->incoming_server_password = strdup("samsung09"); + account->outgoing_server_type = EMAIL_SERVER_TYPE_SMTP; + account->outgoing_server_address = strdup("smtp.gmail.com"); + account->outgoing_server_port_number = 465; + account->outgoing_server_secure_connection = 1; + account->outgoing_server_need_authentication = 1; + account->outgoing_server_user_name = strdup("samsungtest09"); + account->outgoing_server_password = strdup("samsung09"); + account->pop_before_smtp = 0; + account->incoming_server_requires_apop = 0; + account->auto_download_size = 0; /* downloading option, 0 is subject only, 1 is text body, 2 is normal */ + account->outgoing_server_use_same_authenticator = 1; /* Specifies the 'Same as POP3' option, 0 is none, 1 is 'Same as POP3 */ + account->logo_icon_path = NULL; + 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.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 = strdup("Gmail IMAP4 Signature"); + account->check_interval = 0; + + err_code = email_add_account_with_validation(account, &handle); + if (EMAIL_ERROR_NONE == err_code) { + /* + err_code = email_validate_account(account->account_id, &handle); + if (EMAIL_ERROR_NONE == err_code) { + printf("email add account success\n"); + return account->account_id; + } + else { + + printf("email add ccount : Failed err_code[%d]", err_code); + } + */ + printf("email add account - in progress\n"); + } + else { + printf("email add ccount : Failed err_code[%d]", err_code); + } + email_free_account(&account, 1); + } + + return account_id; +} + + +int uts_Email_Add_Real_Message_02() +{ + int err_code = EMAIL_ERROR_NONE; + int handle; + email_mail_data_t *test_mail_data = NULL; + email_attachment_data_t *attachment_data = NULL; + email_meeting_request_t *meeting_req = NULL; + email_mailbox_t *mailbox = NULL; + + FILE *fp; + email_option_t option; + int count = 0; + int i = 0; + email_account_t *account = NULL ; + + memset(&option, 0x00, sizeof(email_option_t)); + option.keep_local_copy = 1; + + test_mail_data = malloc(sizeof(email_mail_data_t)); + memset(test_mail_data, 0x00, sizeof(email_mail_data_t)); + + attachment_data = malloc(sizeof(email_attachment_data_t)); + memset(attachment_data, 0x00, sizeof(email_attachment_data_t)); + + err_code = email_get_account_list(&account, &count); + if (EMAIL_ERROR_NONE == err_code && count > 0) { + test_mail_data->account_id = account[i].account_id; + test_mail_data->flags_draft_field = 1; + + test_mail_data->body_download_status = 1; + + test_mail_data->server_mail_id = strdup("testmail_1"); + + test_mail_data->full_address_from = strdup("<samsungtest09@gmail.com>"); + test_mail_data->full_address_to = strdup("<samsungtest09@gmail.com>"); + test_mail_data->subject = strdup("Test"); + + err_code = email_get_mailbox_by_mailbox_type(account[i].account_id , EMAIL_MAILBOX_TYPE_INBOX, &mailbox); + if (EMAIL_ERROR_NONE != err_code) { + tet_printf("Email get mailbox by mailbox type failed : error_code[%d]\n", err_code); + return err_code; + } + + test_mail_data->mailbox_id = mailbox->mailbox_id; + test_mail_data->mailbox_type = mailbox->mailbox_type; + + fp = fopen("/tmp/mail.txt", "w"); + fprintf(fp, "xxxxxxxxx"); + fclose(fp); + + test_mail_data->file_path_plain = strdup("/tmp/mail.txt"); + test_mail_data->attachment_count = 1; + + fp = fopen("/tmp/attach.txt", "w"); + fprintf(fp, "Simple Attachment"); + fclose(fp); + + attachment_data->attachment_name = strdup("Attach"); + attachment_data->attachment_path = strdup("/tmp/attach.txt"); + attachment_data->save_status = 1; + + err_code = email_add_mail(test_mail_data, attachment_data, 1, NULL, 0); + + if (EMAIL_ERROR_NONE == err_code) { + printf("email add message success\n"); + return test_mail_data->mail_id; + } + else { + printf("email add message : Failed err_code[%d]", err_code); + } + } + else { + printf("emailccount list : Failed err_code[%d]", err_code); + } + if (mailbox) { + email_free_mailbox(&mailbox, 1); + mailbox = NULL; + } +} + + diff --git a/TC/TC_email_service/TC_Utility/uts-email-real-utility.h b/TC/TC_email_service/TC_Utility/uts-email-real-utility.h new file mode 100755 index 0000000..37776c2 --- /dev/null +++ b/TC/TC_email_service/TC_Utility/uts-email-real-utility.h @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2012 - 2013 Samsung Electronics, Co., Ltd. + * All rights reserved. + * + * This software is a confidential and proprietary information of Samsung + * Electronics, Co., Ltd. ("Confidential Information"). 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. + */ + +/* #include <tet_api.h */ + +#include <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <sqlite3.h> +#include "email-api-init.h" +#include "email-api-account.h" +#include "email-api-mail.h" + +//#define email_get_mail_list(account_id, mailbox_name, mail_list, count, sorting) email_get_mail_list_ex(account_id, mailbox_name, EMAIL_LIST_TYPE_NORMAL, -1, -1, sorting, mail_list, count) + +int uts_Email_Add_Real_Account_01(void); +int uts_Email_Add_Real_Message_02(void); + +/* struct tet_testlist tet_testlist[] = */ +/* */ +/* { uts_Email_Add_Real_Account_01, 1} */ +/* { uts_Email_Add_Real_Message_02, 2} */ +/* {NULL, 0 */ +/* } */ + + diff --git a/TC/TC_email_service/_export_env.sh b/TC/TC_email_service/_export_env.sh new file mode 100755 index 0000000..119d077 --- /dev/null +++ b/TC/TC_email_service/_export_env.sh @@ -0,0 +1,19 @@ +export ARCH=target + +export TET_INSTALL_PATH=/myfiles/download/DTS/TETware # tetware root path +echo $TET_INSTALL_PATH +export TET_TARGET_PATH=$TET_INSTALL_PATH/tetware-target.3.8 # tetware target path +export PATH=$TET_TARGET_PATH/bin:$PATH +export LD_LIBRARY_PATH=$TET_TARGET_PATH/lib/tet3:$LD_LIBRARY_PATH + +export TET_ROOT=$TET_TARGET_PATH + +set $(pwd) +export TET_SUITE_ROOT=$1 +echo $TET_SUITE_ROOT + +set $(date +%s) +FILE_NAME_EXTENSION=$1 +echo $TET_SUITE_ROOT + +make diff --git a/TC/_export_target_env.sh b/TC/_export_target_env.sh new file mode 100755 index 0000000..7a39b14 --- /dev/null +++ b/TC/_export_target_env.sh @@ -0,0 +1,17 @@ + +export ARCH=target + +#export TET_INSTALL_PATH=/opt/slp/TETware # path to mount +export TET_INSTALL_PATH=/mnt/nfs/tet # path to mount +export TET_TARGET_PATH=$TET_INSTALL_PATH/tet3.8 +export PATH=$TET_TARGET_PATH/bin:$PATH +export LD_LIBRARY_PATH=$TET_TARGET_PATH/lib/tet3:$LD_LIBRARY_PATH + +export TET_ROOT=$TET_TARGET_PATH + +set $(pwd) +export TET_SUITE_ROOT=$1 + +set $(date +%s) +FILE_NAME_EXTENSION=$1 + diff --git a/TC/build.sh b/TC/build.sh new file mode 100755 index 0000000..439bfde --- /dev/null +++ b/TC/build.sh @@ -0,0 +1,20 @@ +. ./TC_email_service/_export_env.sh # setting environment variables + +echo PATH=$PATH +echo LD_LIBRARY_PATH=$LD_LIBRARY_PATH +echo TET_ROOT=$TET_ROOT +echo TET_SUITE_ROOT=$TET_SUITE_ROOT +echo ARCH=$ARCH + +export TET_INSTALL_PATH=/git/tet/tet3.8 + +RESULT_DIR=results-$ARCH +HTML_RESULT=$RESULT_DIR/build-tar-result-$FILE_NAME_EXTENSION.html +JOURNAL_RESULT=$RESULT_DIR/build-tar-result-$FILE_NAME_EXTENSION.journal + +mkdir $RESULT_DIR + +tcc -c -p ./ # executing tcc, with clean option (-c) +tcc -b -j $JOURNAL_RESULT -p ./ # executing tcc to build test cases (-b) +grw -c 3 -f chtml -o $HTML_RESULT $JOURNAL_RESULT # reporting the result + diff --git a/TC/execute.sh b/TC/execute.sh new file mode 100755 index 0000000..e1ed207 --- /dev/null +++ b/TC/execute.sh @@ -0,0 +1,17 @@ +. ./_export_target_env.sh # setting environment variables + +echo PATH=$PATH +echo LD_LIBRARY_PATH=$LD_LIBRARY_PATH +echo TET_ROOT=$TET_ROOT +echo TET_SUITE_ROOT=$TET_SUITE_ROOT +echo ARCH=$ARCH + +RESULT_DIR=results-$ARCH +HTML_RESULT=$RESULT_DIR/exec-tar-result-$FILE_NAME_EXTENSION.html +JOURNAL_RESULT=$RESULT_DIR/exec-tar-result-$FILE_NAME_EXTENSION.journal + +mkdir $RESULT_DIR + +tcc -e -j $JOURNAL_RESULT -p ./ # executing tcc, with –e option +grw -c 3 -f chtml -o $HTML_RESULT $JOURNAL_RESULT # reporting the result + diff --git a/TC/making_new_tet_scen.py b/TC/making_new_tet_scen.py new file mode 100755 index 0000000..8cde490 --- /dev/null +++ b/TC/making_new_tet_scen.py @@ -0,0 +1,70 @@ +#!/usr/bin/python + +############################################# +# tet_scen auto generator +# +# ** argv[1] = TC root +############################################# + +import sys,string,os + + +write_file = open("tet_scen", 'w') + +# +# making new tet_scen +# +def making_tet_scen (filename): + #tmp_list = filename.strip().split('/') + n_filename = filename.replace(' ', '\\ ') + #print n_filename + #new_path = "/"+ sys.argv[1] +"/"+n_filename[2:-6] + new_path = "/"+n_filename[:-6] + #print new_path + file = open(filename, 'r') + lines = file.readlines() + for line in lines: + if len(line.strip()) > 1: + list = line.strip().split('/') + #print new_path + list[0] + #print new_path + list[-1] + write_file.write("\t"+new_path + list[0]+"\n") + +# +# usage() +# +def usage(): + print(" ") + print("./making_new_tet_scen.py tc_root") + print("Put the Test Case's root directory.") + print("Do not include '/' at the end") + print(" ") + +# +# main() +# +def main(): + if len(sys.argv) < 2: + usage() + sys.exit(0) + + os.system('find '+ sys.argv[1] +' -name "tslist" > tslist.txt') + + #write_file = open("tetscen", w) + write_file.write("# auto generated tet_scen\n") + write_file.write("all\n") + write_file.write("\t\"Starting Full Test Suite\"\n") + + for file in open("tslist.txt", 'r'): + #print file.strip() + making_tet_scen(file.strip()) + + write_file.write("\t\"Completed Full Test Suite\"\n") + write_file.write("# EOF\n") + write_file.close() + print(" ") + print("==============================") + print("New tet_scen file is made~~~~") + print("==============================") + print(" ") +main() diff --git a/TC/tet_scen b/TC/tet_scen new file mode 100644 index 0000000..ed179f3 --- /dev/null +++ b/TC/tet_scen @@ -0,0 +1,61 @@ +# auto generated tet_scen +all + "Starting Full Test Suite" + /./TC_email_service/TC_Folder/uts-email-add-mailbox + /./TC_email_service/TC_Folder/uts-email-get-mailbox-list + /./TC_email_service/TC_Folder/uts-email-get-mailbox-by-mailboxtype + /./TC_email_service/TC_Folder/uts-email-delete-mailbox + /./TC_email_service/TC_Message/uts-email-add-message + /./TC_email_service/TC_Message/uts-email-add-attachment + /./TC_email_service/TC_Message/uts-email-get-info + /./TC_email_service/TC_Message/uts-email-get-attachment-info + /./TC_email_service/TC_Message/uts-email-get-mail-list-ex + /./TC_email_service/TC_Message/uts-email-get-disk-space-usage + /./TC_email_service/TC_Message/uts-email-get-max-mail-count + /./TC_email_service/TC_Message/uts-email-get-mailbox-list + /./TC_email_service/TC_Message/uts-email-update-message + /./TC_email_service/TC_Message/uts-email-count-message + /./TC_email_service/TC_Message/uts-email-cancel-send-mail + /./TC_email_service/TC_Message/uts-email-send-retry + /./TC_email_service/TC_Message/uts-email-move-mail-to-folder + /./TC_email_service/TC_Message/uts-email-move-all-mails-to-folder + /./TC_email_service/TC_Message/uts-email-free-mail-info + /./TC_email_service/TC_Message/uts-email-free-attachment-info + /./TC_email_service/TC_Message/uts-email-free-mailbox + /./TC_email_service/TC_Message/uts-email-delete-attachment + /./TC_email_service/TC_Message/uts-email-delete-message + /./TC_email_service/TC_Message/uts-email-delete-all-message-in-folder + /./TC_email_service/TC_Message/uts-email-create-db-full + /./TC_email_service/TC_Message/uts-email-clear-mail-data + /./TC_email_service/TC_Account/uts-email-add-account + /./TC_email_service/TC_Account/uts-email-validate-account + /./TC_email_service/TC_Account/uts-email-update-account + /./TC_email_service/TC_Account/uts-email-add-account-with-validation + /./TC_email_service/TC_Account/uts-email-get-account + /./TC_email_service/TC_Account/uts-email-get-account-list + /./TC_email_service/TC_Account/uts-email-free-account + /./TC_email_service/TC_Account/uts-email-delete-account + /./TC_email_service/TC_Rule/uts-email-add-rule + /./TC_email_service/TC_Rule/uts-email-get-rule + /./TC_email_service/TC_Rule/uts-email-get-rule-list + /./TC_email_service/TC_Rule/uts-email-update-rule + /./TC_email_service/TC_Rule/uts-email-free-rule + /./TC_email_service/TC_Rule/uts-email-delete-rule + /./TC_email_service/TC_Network/uts_email_get_network_status + /./TC_email_service/TC_Network/uts_email_get_pending_job + /./TC_email_service/TC_Network/uts_email_send_mail + /./TC_email_service/TC_Network/uts_email_send_saved + /./TC_email_service/TC_Network/uts_email_sync_header + /./TC_email_service/TC_Network/uts_email_sync_header_for_all_account + /./TC_email_service/TC_Network/uts_email_download_body + /./TC_email_service/TC_Network/uts_email_download_attachment + /./TC_email_service/TC_Network/uts_email_get_imap_folder_list + /./TC_email_service/TC_Network/uts_email_cancel_job + /./TC_email_service/TC_Init/uts-email-service-begin + /./TC_email_service/TC_Init/uts-email-open-db + /./TC_email_service/TC_Init/uts-email-init-storage + /./TC_email_service/TC_Init/uts-email-ping-service + /./TC_email_service/TC_Init/uts-email-close-db + /./TC_email_service/TC_Init/uts-email-service-end + "Completed Full Test Suite" +# EOF diff --git a/TC/tetbuild.cfg b/TC/tetbuild.cfg new file mode 100755 index 0000000..225bf4d --- /dev/null +++ b/TC/tetbuild.cfg @@ -0,0 +1,25 @@ +# TETware Training Course +# Build mode configuration file for Exercise 1 + +# An example build mode configuration +# that uses make as the build tool +# and -f makefile as the arguments to +# the build tool. + +TET_BUILD_TOOL=make +TET_BUILD_FILE=-f Makefile + +# Clearly, make doesn't use the TETware API when printing messages - +# it just writes messages on stdout or stderr. +# So we must tell tcc to execute make with output capture mode enabled. +# When make is executed, stdout and stderr is captured and written to +# the journal. + +TET_OUTPUT_CAPTURE=True + +# we just want make -f makefile executed; +# if the following was set to true , then +# it would be make -f makefile tc1 etc... + +TET_PASS_TC_NAME=True + diff --git a/TC/tetclean.cfg b/TC/tetclean.cfg new file mode 100755 index 0000000..9038770 --- /dev/null +++ b/TC/tetclean.cfg @@ -0,0 +1,12 @@ +# TETware Training Course +# Clean mode configuration file for Exercise 1 + +# Use "make clean" to clean up each test case. +TET_CLEAN_TOOL=make clean +TET_CLEAN_FILE=Makefile +# Tell tcc to execute make with output capture mode enabled +TET_OUTPUT_CAPTURE=True +# don't want to pass the test case name to the clean tool +TET_PASS_TC_NAME=True +TET_API_COMPLAINT=True + diff --git a/TC/tetexec.cfg b/TC/tetexec.cfg new file mode 100755 index 0000000..673f800 --- /dev/null +++ b/TC/tetexec.cfg @@ -0,0 +1,16 @@ +# TETware Training Course +# Execute mode configuration file for Exercise 1 + +# TET_OUTPUT_CAPTURE specifies whether or not tcc should capture standard +# output and standard error output from test cases +# and record it in the journal. +# Test cases in this test suite are API-conforming test cases, so they +# will use API functions to write to the journal. + +# Setting TET_OUTPUT_CAPTURE to False provides a default value +# of True for TET_API_COMPLIANT + +TET_OUTPUT_CAPTURE=False +TET_API_COMPLAINT=True +TET_PASS_TC_NAME=True + diff --git a/TC/tslist.txt b/TC/tslist.txt new file mode 100755 index 0000000..8826d6f --- /dev/null +++ b/TC/tslist.txt @@ -0,0 +1,6 @@ +./TC_email_service/TC_Folder/tslist +./TC_email_service/TC_Message/tslist +./TC_email_service/TC_Account/tslist +./TC_email_service/TC_Rule/tslist +./TC_email_service/TC_Network/tslist +./TC_email_service/TC_Init/tslist diff --git a/email-api/CMakeLists.txt b/email-api/CMakeLists.txt index eea919f..9ea8f18 100755 --- a/email-api/CMakeLists.txt +++ b/email-api/CMakeLists.txt @@ -14,6 +14,7 @@ MESSAGE(">>> Build type: ${CMAKE_BUILD_TYPE}") SET(VISIBILITY "-DEXPORT_API=\"__attribute__((visibility(\\\"default\\\")))\"") SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${VISIBILITY} -fvisibility=hidden") +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wl,--gc-sections") ########################################################## # Define Email API @@ -35,13 +36,14 @@ INCLUDE_DIRECTORIES( ${CMAKE_SOURCE_DIR}/email-api/include ${CMAKE_SOURCE_DIR}/email-api/socket/include ${CMAKE_SOURCE_DIR}/email-ipc/include + ${CMAKE_SOURCE_DIR}/email-ipc/email-activation/include ${CMAKE_SOURCE_DIR}/email-core/include ${CMAKE_SOURCE_DIR}/email-core/email-storage/include ${CMAKE_SOURCE_DIR}/email-common-use/include ) INCLUDE(FindPkgConfig) -pkg_check_modules(api_pkgs REQUIRED glib-2.0 dlog dbus-1 vconf db-util contacts-service2 uw-imap-toolkit) +pkg_check_modules(api_pkgs REQUIRED glib-2.0 dlog dbus-1 vconf contacts-service2 uw-imap-toolkit gmime-2.6) FOREACH(flag ${api_pkgs_CFLAGS}) SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") @@ -59,7 +61,7 @@ TARGET_LINK_LIBRARIES(${API-LIB} ${api_pkgs_LDFLAGS} email-ipc email-storage ema SET_TARGET_PROPERTIES(${API-LIB} PROPERTIES SOVERSION ${VERSION_MAJOR}) SET_TARGET_PROPERTIES(${API-LIB} PROPERTIES VERSION ${VERSION}) -INSTALL(TARGETS ${API-LIB} DESTINATION ${LIB_INSTALL_DIR} COMPONENT RuntimeLibraries) +INSTALL(TARGETS ${API-LIB} DESTINATION lib COMPONENT RuntimeLibraries) SET(EMAIL-API-HEADERS ${CMAKE_SOURCE_DIR}/email-api/include/email-api.h @@ -107,7 +109,7 @@ TARGET_LINK_LIBRARIES(${SMIME-API-LIB} ${api_pkgs_LDFLAGS} email-ipc email-stora SET_TARGET_PROPERTIES(${SMIME-API-LIB} PROPERTIES SOVERSION ${VERSION_MAJOR}) SET_TARGET_PROPERTIES(${SMIME-API-LIB} PROPERTIES VERSION ${VERSION}) -INSTALL(TARGETS ${SMIME-API-LIB} DESTINATION ${LIB_INSTALL_DIR} COMPONENT RuntimeLibraries) +INSTALL(TARGETS ${SMIME-API-LIB} DESTINATION lib COMPONENT RuntimeLibraries) SET(SMIME-EMAIL-API-HEADERS ${CMAKE_SOURCE_DIR}/email-api/include/email-api-smime.h diff --git a/email-api/doc/email-service_doc.h b/email-api/doc/email-service_doc.h new file mode 100755 index 0000000..0625199 --- /dev/null +++ b/email-api/doc/email-service_doc.h @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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 __TIZEN_EMAIL_SERVICE_DOC_H__ +#define __TIZEN_EMAIL_SERVICE_DOC_H__ + +/** + * @internal + * @ingroup CAPI_MESSAGING_FRAMEWORK + * @defgroup EMAIL_SERVICE_FRAMEWORK email-service + * @brief The Platform API for email functionalities. + * @internal + * + * @addtogroup EMAIL_SERVICE_FRAMEWORK + * + * @section EMAIL_SERVICE_FRAMEWORK_HEADER Required Header + * \#include <email-api.h> + * + * @section EMAIL_SERVICE_FRAMEWORK_OVERVIEW Overview + * 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. + * The email-service API is implemented to provide functionalities to applications that make use of email service. + * The email-service API can be utilized by any component in the application layer which facilitates the end user + * to perform the email realted operations such as save, send, download email message and others. + * For Example, the email-service API’s shall be invoked by 1) Multimedia when user opts to send media file through email + * 2) Email application when user tries to send an email message etc. + * + * <table> + * <tr> + * <th>Feature</th> + * <th>Description</th> + * </tr> + * <tr> + * <td>Account API</td> + * <td>Account API is a set of operations to manage email accounts like add, update, delete or get account related details.</td> + * </tr> + * <tr> + * <td>Other API</td> + * <td>Various API set for initializing and MIME operations and verifying email address. </td> + * </tr> + * <tr> + * <td>Mail API</td> + * <td>Mail API is a set of operations to manage mail like add, update, delete or get mail related details.</td> + * </tr> + * <tr> + * <td>Mailbox API</td> + * <td>Mailbox API is a set of operations to manage email mailboxes like add, update, delete or get mailbox related details.</td> + * </tr> + * <tr> + * <td>Network API</td> + * <td>Network API is a set of operations to manage email send, receive and cancel related details.</td> + * </tr> + * <tr> + * <td>Rule API</td> + * <td>Rule API is a set of operations to manage email rules like add, get, delete or update rule related details.</td> + * </tr> + * <tr> + * <td>SMIME API</td> + * <td>SMIME API is a set of operations to handle SMIME data for secured email. </td> + * </tr> + * </table> + */ + +#endif /* __TIZEN_EMAIL_SERVICE_DOC_H__ */ + + + + + diff --git a/email-api/email-api-account.c b/email-api/email-api-account.c index 5bc0ebc..08702c3 100755 --- a/email-api/email-api-account.c +++ b/email-api/email-api-account.c @@ -39,6 +39,7 @@ #include "email-core-utils.h" #include "email-utilities.h" #include "email-ipc.h" +#include "email-dbus-activation.h" /* API - Adds the Email Account */ EXPORT_API int email_add_account(email_account_t* account) @@ -133,9 +134,11 @@ EXPORT_API int email_free_account(email_account_t** account_list, int count) EM_SAFE_FREE(p[i].return_address); EM_SAFE_FREE(p[i].logo_icon_path); EM_SAFE_FREE(p[i].user_data); + EM_SAFE_FREE(p[i].certificate_path); p[i].user_data_length = 0; EM_SAFE_FREE(p[i].options.display_name_from); EM_SAFE_FREE(p[i].options.signature); + EM_SAFE_FREE(p[i].options.alert_ringtone_path); } free(p); *account_list = NULL; } @@ -191,7 +194,6 @@ EXPORT_API int email_update_account(int account_id, email_account_t* new_account { EM_DEBUG_API_BEGIN ("account_id[%d] new_account[%p]", account_id, new_account); - int ret = 0; int size = 0; int err = EMAIL_ERROR_NONE; int with_validation = false; @@ -231,18 +233,14 @@ EXPORT_API int email_update_account(int account_id, email_account_t* new_account EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_IPC_SOCKET_FAILURE); } - emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &ret); - if(ret != EMAIL_ERROR_NONE) { - /* get error code */ - emipc_get_parameter(hAPI, ePARAMETER_OUT, 1, sizeof(int), &err); - } + emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &err); FINISH_OFF: emipc_destroy_email_api(hAPI); hAPI = NULL; - EM_DEBUG_API_END ("ret[%d] err[%d]", ret, err); + EM_DEBUG_API_END ("err[%d]", err); return err; } @@ -251,7 +249,6 @@ EXPORT_API int email_update_account_with_validation(int account_id, email_accoun { EM_DEBUG_API_BEGIN ("account_id[%d] new_account[%p]", account_id, new_account); - int ret = 0; int size = 0; int err = EMAIL_ERROR_NONE; int with_validation = true; @@ -293,15 +290,12 @@ EXPORT_API int email_update_account_with_validation(int account_id, email_accoun EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_IPC_SOCKET_FAILURE); } - emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &ret); - if(ret != EMAIL_ERROR_NONE) { /* get error code */ - emipc_get_parameter(hAPI, ePARAMETER_OUT, 1, sizeof(int), &err); - } + emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &err); emipc_destroy_email_api(hAPI); hAPI = NULL; - EM_DEBUG_API_END ("ret[%d] err[%d]", ret, err); + EM_DEBUG_API_END ("err[%d]", err); return err; } @@ -310,20 +304,12 @@ EXPORT_API int email_update_account_with_validation(int account_id, email_accoun EXPORT_API int email_get_account(int account_id, int pulloption, email_account_t** account) { EM_DEBUG_FUNC_BEGIN ("account_id[%d] pulloption[%d]", account_id, pulloption); - int ret = 0; int err = EMAIL_ERROR_NONE; emstorage_account_tbl_t *account_tbl = NULL; EM_IF_NULL_RETURN_VALUE(account_id, EMAIL_ERROR_INVALID_PARAM); EM_IF_NULL_RETURN_VALUE(account, EMAIL_ERROR_INVALID_PARAM); -#ifdef __FEATURE_ACCESS_CONTROL__ - err = em_check_db_privilege_by_pid(getpid()); - if (err == EMAIL_ERROR_PERMISSION_DENIED) { - EM_DEBUG_LOG("permission denied"); - goto FINISH_OFF; - } -#endif if (pulloption == GET_FULL_DATA) pulloption = EMAIL_ACC_GET_OPT_FULL_DATA; @@ -353,9 +339,6 @@ EXPORT_API int email_get_account(int account_id, int pulloption, email_account_t memset((void*)*account, 0, sizeof(email_account_t)); em_convert_account_tbl_to_account(account_tbl, *account); - - ret = true; - FINISH_OFF: if (account_tbl) emstorage_free_account(&account_tbl, 1, NULL); @@ -374,13 +357,6 @@ EXPORT_API int email_get_account_list(email_account_t** account_list, int* count EM_IF_NULL_RETURN_VALUE(account_list, EMAIL_ERROR_INVALID_PARAM); EM_IF_NULL_RETURN_VALUE(count, EMAIL_ERROR_INVALID_PARAM); -#ifdef __FEATURE_ACCESS_CONTROL__ - err = em_check_db_privilege_by_pid(getpid()); - if (err == EMAIL_ERROR_PERMISSION_DENIED) { - EM_DEBUG_LOG("permission denied"); - goto FINISH_OFF; - } -#endif if (!emstorage_get_account_list(count, &temp_account_tbl , true, false, &err)) { EM_DEBUG_EXCEPTION("emstorage_get_account_list failed [%d]", err); @@ -596,30 +572,26 @@ EXPORT_API int email_restore_accounts_from_secure_storage(const char * file_name int ret = 0; int err = EMAIL_ERROR_NONE; - if (!file_name) { - EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM"); - err = EMAIL_ERROR_INVALID_PARAM; - return err; - } - HIPC_API hAPI = emipc_create_email_api(_EMAIL_API_RESTORE_ACCOUNTS); EM_IF_NULL_RETURN_VALUE(hAPI, EMAIL_ERROR_NULL_VALUE); /* file_name */ - if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)file_name, EM_SAFE_STRLEN(file_name)+1)) { - EM_DEBUG_EXCEPTION(" emipc_add_parameter account_id failed "); - EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_NULL_VALUE); + if (file_name) { + if (!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)file_name, EM_SAFE_STRLEN(file_name)+1)) { + EM_DEBUG_EXCEPTION(" emipc_add_parameter account_id failed "); + EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_NULL_VALUE); + } } - if(emipc_execute_proxy_api(hAPI) != EMAIL_ERROR_NONE) { + if (emipc_execute_proxy_api(hAPI) != EMAIL_ERROR_NONE) { EM_DEBUG_EXCEPTION(" emipc_execute_proxy_api failed "); EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_IPC_SOCKET_FAILURE); } emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &ret); - if(0==ret) { /* get error code */ + if (0 == ret) { /* get error code */ emipc_get_parameter(hAPI, ePARAMETER_OUT, 1, sizeof(int), &err); } @@ -630,12 +602,11 @@ EXPORT_API int email_restore_accounts_from_secure_storage(const char * file_name return err; } -EXPORT_API int email_get_password_length_of_account(const int account_id, int *password_length) +EXPORT_API int email_get_password_length_of_account(int account_id, email_get_password_length_type password_type, int *password_length) { EM_DEBUG_API_BEGIN ("account_id[%d] password_length[%p]", account_id, password_length); int ret = 0; int err = EMAIL_ERROR_NONE; - int password_type = 1; if (account_id <= 0 || password_length == NULL) { EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM"); @@ -675,48 +646,11 @@ EXPORT_API int email_get_password_length_of_account(const int account_id, int *p return err; } -EXPORT_API int email_query_server_info(const char* domain_name, email_server_info_t **result_server_info) -{ - EM_DEBUG_API_BEGIN ("domain_name[%p] result_server_info[%p]", domain_name, result_server_info); - int err = EMAIL_ERROR_NONE; - - if (!domain_name || !result_server_info) { - EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM"); - err = EMAIL_ERROR_INVALID_PARAM; - return err; - } - - err = emcore_query_server_info(domain_name, result_server_info); - - EM_DEBUG_API_END ("err[%d]", err); - return err; -} - - -EXPORT_API int email_free_server_info(email_server_info_t **result_server_info) +EXPORT_API int email_update_notification_bar(int account_id, int total_mail_count, int unread_mail_count, int input_from_eas) { - EM_DEBUG_API_BEGIN ("result_server_info[%p]", result_server_info); + EM_DEBUG_API_BEGIN ("account_id[%d] total_mail_count[%d] unread_mail_count[%d]", account_id, total_mail_count, unread_mail_count); int err = EMAIL_ERROR_NONE; - if (!result_server_info) { - EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM"); - err = EMAIL_ERROR_INVALID_PARAM; - return err; - } - - err = emcore_free_server_info(result_server_info); - - EM_DEBUG_API_END ("ret[%d]", err); - return err; -} - -EXPORT_API int email_update_notification_bar(int account_id) -{ - EM_DEBUG_API_BEGIN("account_id [%d]", account_id); - int err = EMAIL_ERROR_NONE; - int total_mail_count = 0; - int unread_mail_count = 0; - if (account_id == 0) { EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM"); err = EMAIL_ERROR_INVALID_PARAM; @@ -744,6 +678,14 @@ EXPORT_API int email_update_notification_bar(int account_id) EM_DEBUG_EXCEPTION(" emipc_add_parameter account_id failed"); EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_NULL_VALUE); } + + /* input_from_eas */ + if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)&input_from_eas, sizeof(int))) { + EM_DEBUG_EXCEPTION(" emipc_add_parameter account_id failed"); + EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_NULL_VALUE); + } + + if(emipc_execute_proxy_api(hAPI) != EMAIL_ERROR_NONE) { EM_DEBUG_EXCEPTION(" emipc_execute_proxy_api failed "); EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_IPC_SOCKET_FAILURE); @@ -757,15 +699,65 @@ EXPORT_API int email_update_notification_bar(int account_id) return err; } - EXPORT_API int email_clear_all_notification_bar() { - EM_DEBUG_FUNC_BEGIN (); + EM_DEBUG_API_BEGIN (); int err = EMAIL_ERROR_NONE; + int account_id = ALL_ACCOUNT; - err = emcore_clear_all_notifications(); + HIPC_API hAPI = emipc_create_email_api(_EMAIL_API_CLEAR_NOTIFICATION_BAR); - EM_DEBUG_FUNC_END ("ret[%d]", err); + EM_IF_NULL_RETURN_VALUE(hAPI, EMAIL_ERROR_NULL_VALUE); + + /* account_id */ + if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)&account_id, sizeof(int))) { + EM_DEBUG_EXCEPTION(" emipc_add_parameter account_id failed"); + EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_NULL_VALUE); + } + + if(emipc_execute_proxy_api(hAPI) != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION(" emipc_execute_proxy_api failed "); + EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_IPC_SOCKET_FAILURE); + } + + emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &err); + emipc_destroy_email_api(hAPI); + + hAPI = NULL; + EM_DEBUG_API_END ("ret[%d]", err); + return err; +} + +EXPORT_API int email_clear_notification_bar(int account_id) +{ + EM_DEBUG_API_BEGIN (); + int err = EMAIL_ERROR_NONE; + + if (account_id < ALL_ACCOUNT) { + EM_DEBUG_EXCEPTION ("EMAIL_ERROR_INVALID_PARAM"); + return EMAIL_ERROR_INVALID_PARAM; + } + + HIPC_API hAPI = emipc_create_email_api(_EMAIL_API_CLEAR_NOTIFICATION_BAR); + + EM_IF_NULL_RETURN_VALUE(hAPI, EMAIL_ERROR_NULL_VALUE); + + /* account_id */ + if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)&account_id, sizeof(int))) { + EM_DEBUG_EXCEPTION(" emipc_add_parameter account_id failed"); + EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_NULL_VALUE); + } + + if(emipc_execute_proxy_api(hAPI) != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION(" emipc_execute_proxy_api failed "); + EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_IPC_SOCKET_FAILURE); + } + + emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &err); + emipc_destroy_email_api(hAPI); + + hAPI = NULL; + EM_DEBUG_API_END ("ret[%d]", err); return err; } @@ -774,6 +766,11 @@ EXPORT_API int email_save_default_account_id(int input_account_id) EM_DEBUG_API_BEGIN ("input_account_id [%d]", input_account_id); int err = EMAIL_ERROR_NONE; + if (input_account_id < ALL_ACCOUNT) { + EM_DEBUG_EXCEPTION ("EMAIL_ERROR_INVALID_PARAM"); + return EMAIL_ERROR_INVALID_PARAM; + } + err = emcore_save_default_account_id(input_account_id); EM_DEBUG_API_END ("ret[%d]", err); diff --git a/email-api/email-api-etc.c b/email-api/email-api-etc.c index 4c5a1cd..c46a559 100755 --- a/email-api/email-api-etc.c +++ b/email-api/email-api-etc.c @@ -100,12 +100,8 @@ EXPORT_API int email_write_mime_file(email_mail_data_t *input_mail_data, email_a { EM_DEBUG_API_BEGIN ("input_mail_data[%p] input_attachment_data[%p] input_attachment_count[%d]", input_mail_data, input_attachment_data, input_attachment_count); - int err = EMAIL_ERROR_NONE; - int size = 0; - int *ret_nth_value = 0; - char *p_output_file_path = NULL; - char *mail_data_stream = NULL; - char *attachment_data_list_stream = NULL; + int err = EMAIL_ERROR_NONE; + int *ret_nth_value = NULL; HIPC_API hAPI = NULL; EM_IF_NULL_RETURN_VALUE(input_mail_data, EMAIL_ERROR_INVALID_PARAM); @@ -118,75 +114,27 @@ EXPORT_API int email_write_mime_file(email_mail_data_t *input_mail_data, email_a goto FINISH_OFF; } - mail_data_stream = em_convert_mail_data_to_byte_stream(input_mail_data, &size); - if (!mail_data_stream) { - EM_DEBUG_EXCEPTION("em_convert_mail_data_to_byte_stream failed"); - err = EMAIL_ERROR_NULL_VALUE; - goto FINISH_OFF; - } - - if (!emipc_add_dynamic_parameter(hAPI, ePARAMETER_IN, mail_data_stream, size)) { - EM_DEBUG_EXCEPTION("emipc_add_dynamic_parameter failed"); - err = EMAIL_ERROR_OUT_OF_MEMORY; - goto FINISH_OFF; - } - - attachment_data_list_stream = em_convert_attachment_data_to_byte_stream(input_attachment_data, input_attachment_count, &size); - if ((size > 0) && !emipc_add_dynamic_parameter(hAPI, ePARAMETER_IN, attachment_data_list_stream, size)) { - EM_DEBUG_EXCEPTION("emipc_add_dynamic_parameter failed"); - err = EMAIL_ERROR_OUT_OF_MEMORY; - goto FINISH_OFF; - } - - if (*output_file_path && (size = EM_SAFE_STRLEN(*output_file_path)) > 0) { - EM_DEBUG_LOG_SEC("output_file_path : [%s] size : [%d]", *output_file_path, size); - size = size + 1; - } else { - size = 0; - } - - if (!emipc_add_parameter(hAPI, ePARAMETER_IN, *output_file_path, size)) { - EM_DEBUG_EXCEPTION("emipc_add_dynamic_parameter failed"); - err = EMAIL_ERROR_OUT_OF_MEMORY; - goto FINISH_OFF; - } - if (emipc_execute_proxy_api(hAPI) != EMAIL_ERROR_NONE) { EM_DEBUG_EXCEPTION("emipc_execute_proxy_api failed"); err = EMAIL_ERROR_IPC_SOCKET_FAILURE; goto FINISH_OFF; } - if ((ret_nth_value = (int*)emipc_get_nth_parameter_data(hAPI, ePARAMETER_OUT, 0))) { + if (*(ret_nth_value = (int*)emipc_get_nth_parameter_data(hAPI, ePARAMETER_OUT, 0)) != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("email_write_mime_file failed:[%d]", *ret_nth_value); err = *ret_nth_value; - - if (err == EMAIL_ERROR_NONE) { - size = emipc_get_parameter_length(hAPI, ePARAMETER_OUT, 1); - if (size > 0) { - p_output_file_path = (char *)em_malloc(size); - if (p_output_file_path == NULL) { - err = EMAIL_ERROR_OUT_OF_MEMORY; - goto FINISH_OFF; - } - - if ((err = emipc_get_parameter(hAPI, ePARAMETER_OUT, 1, size, p_output_file_path)) != EMAIL_ERROR_NONE) { - EM_DEBUG_EXCEPTION("emipc_get_parameter failed : [%d]", err); - goto FINISH_OFF; - } - } - } + goto FINISH_OFF; } - EM_SAFE_FREE(*output_file_path); - *output_file_path = EM_SAFE_STRDUP(p_output_file_path); + if (!emcore_make_rfc822_file(input_mail_data, input_attachment_data, input_attachment_count, false, output_file_path, &err)) { + EM_DEBUG_EXCEPTION("emcore_make_rfc822_file failed : [%d]", err); + } FINISH_OFF: if (hAPI) emipc_destroy_email_api(hAPI); - EM_SAFE_FREE(p_output_file_path); - EM_DEBUG_API_END ("err[%d]", err); return err; } @@ -219,4 +167,16 @@ EXPORT_API int email_get_mime_entity(char *mime_path, char **mime_entity) return err; } +EXPORT_API int email_verify_email_address(char *input_email_address) +{ + EM_DEBUG_API_BEGIN ("input_email_address[%p]", input_email_address); + int err = EMAIL_ERROR_NONE; + + EM_IF_NULL_RETURN_VALUE(input_email_address, EMAIL_ERROR_INVALID_PARAM); + if ((err = em_verify_email_address (input_email_address)) != EMAIL_ERROR_NONE) + EM_DEBUG_EXCEPTION("em_verify_email_address failed [%d]", err); + + EM_DEBUG_API_END("err [%d]", err); + return err; +} diff --git a/email-api/email-api-init.c b/email-api/email-api-init.c index cfb2aa9..8068824 100755 --- a/email-api/email-api-init.c +++ b/email-api/email-api-init.c @@ -36,23 +36,17 @@ #include "email-storage.h" #include "email-ipc.h" #include "email-core-task-manager.h" +#include "email-core-account.h" #include "email-utilities.h" +#include "email-dbus-activation.h" #include <sqlite3.h> - +#include <gio/gio.h> EXPORT_API int email_open_db(void) { EM_DEBUG_API_BEGIN (); int error = EMAIL_ERROR_NONE; -#ifdef __FEATURE_ACCESS_CONTROL__ - error = em_check_db_privilege_by_pid(getpid()); - if (error == EMAIL_ERROR_PERMISSION_DENIED) { - EM_DEBUG_EXCEPTION ("permission denied"); - return error; - } -#endif - if (emstorage_db_open(&error) == NULL) EM_DEBUG_EXCEPTION("emstorage_db_open failed [%d]", error); @@ -89,12 +83,18 @@ EXPORT_API int email_service_begin(void) return ret; } +extern GCancellable *cancel; EXPORT_API int email_service_end(void) { EM_DEBUG_API_BEGIN (); int ret = -1; - + + if (cancel) { + g_cancellable_cancel (cancel); + while (cancel) usleep(1000000); + } + ret = emipc_finalize_proxy(); EM_DEBUG_API_END ("err[%d]", ret); @@ -109,16 +109,8 @@ EXPORT_API int email_init_storage(void) { EM_DEBUG_API_BEGIN (); int error = EMAIL_ERROR_NONE; - -#ifdef __FEATURE_ACCESS_CONTROL__ - error = em_check_db_privilege_by_pid(getpid()); - if (error == EMAIL_ERROR_PERMISSION_DENIED) { - EM_DEBUG_LOG("permission denied"); - return error; - } -#endif - if (!emstorage_create_table(EMAIL_CREATE_DB_CHECK, &error)) { + if (!emstorage_create_table(EMAIL_CREATE_DB_NORMAL, &error)) { EM_DEBUG_EXCEPTION("emstorage_create_table failed [%d]", error); } diff --git a/email-api/email-api-mail.c b/email-api/email-api-mail.c index 579f082..46477c0 100755 --- a/email-api/email-api-mail.c +++ b/email-api/email-api-mail.c @@ -46,7 +46,6 @@ #include "email-core-signal.h" #include "email-utilities.h" #include "email-core-smime.h" -#include "db-util.h" #define DIR_SEPERATOR_CH '/' @@ -78,12 +77,12 @@ EXPORT_API int email_add_mail(email_mail_data_t *input_mail_data, email_attachme if(input_from_eas == 0) { /* native emails */ if ((input_mail_data->smime_type != EMAIL_SMIME_NONE) && (input_mail_data->mailbox_type != EMAIL_MAILBOX_TYPE_DRAFT)) { - if (!emcore_make_rfc822_file(input_mail_data, input_attachment_data_list, input_attachment_count, &rfc822_file, &err)) { + if (!emcore_make_rfc822_file(input_mail_data, input_attachment_data_list, input_attachment_count, true, &rfc822_file, &err)) { EM_DEBUG_EXCEPTION("emcore_make_rfc822_file failed [%d]", err); goto FINISH_OFF; } - input_mail_data->file_path_mime_entity = EM_SAFE_STRDUP(emcore_set_mime_entity(rfc822_file)); + input_mail_data->file_path_mime_entity = emcore_set_mime_entity(rfc822_file); emstorage_delete_file(rfc822_file, NULL); EM_SAFE_FREE(rfc822_file); @@ -244,10 +243,9 @@ int email_create_db_full() goto FINISH_OFF; } - body_file = fopen(TMP_BODY_PATH, "w"); - if (body_file == NULL) { - EM_DEBUG_EXCEPTION("fopen failed"); - err = EMAIL_ERROR_SYSTEM_FAILURE; + err = em_fopen(TMP_BODY_PATH, "w", &body_file); + if (err != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("em_fopen failed : [%s][%d]", TMP_BODY_PATH, err); goto FINISH_OFF; } @@ -296,6 +294,7 @@ FINISH_OFF: EM_SAFE_FREE(mail_table_data.subject); EM_SAFE_FREE(mail_table_data.full_address_from); EM_SAFE_FREE(mail_table_data.full_address_to); + EM_SAFE_FREE(mail_table_data.file_path_plain); return err; } @@ -485,13 +484,6 @@ EXPORT_API int email_count_mail(email_list_filter_t *input_filter_list, int inpu EM_IF_NULL_RETURN_VALUE(output_total_mail_count, EMAIL_ERROR_INVALID_PARAM); EM_IF_NULL_RETURN_VALUE(output_unseen_mail_count, EMAIL_ERROR_INVALID_PARAM); -#ifdef __FEATURE_ACCESS_CONTROL__ - err = em_check_db_privilege_by_pid(getpid()); - if (err == EMAIL_ERROR_PERMISSION_DENIED) { - EM_DEBUG_LOG("permission denied"); - goto FINISH_OFF; - } -#endif if( (err = emstorage_write_conditional_clause_for_getting_mail_list(input_filter_list, input_filter_count, NULL, 0, -1, -1, &conditional_clause_string)) != EMAIL_ERROR_NONE) { EM_DEBUG_EXCEPTION("emstorage_write_conditional_clause_for_getting_mail_list failed[%d]", err); @@ -507,7 +499,7 @@ EXPORT_API int email_count_mail(email_list_filter_t *input_filter_list, int inpu *output_unseen_mail_count = unread; FINISH_OFF: - + EM_SAFE_FREE (conditional_clause_string); /* detected by valgrind */ EM_DEBUG_API_END ("err[%d]", err); return err; } @@ -756,13 +748,6 @@ EXPORT_API int email_query_mails(char *conditional_clause_string, email_mail_dat EM_IF_NULL_RETURN_VALUE(result_count, EMAIL_ERROR_INVALID_PARAM); EM_IF_NULL_RETURN_VALUE(conditional_clause_string, EMAIL_ERROR_INVALID_PARAM); -#ifdef __FEATURE_ACCESS_CONTROL__ - err = em_check_db_privilege_by_pid(getpid()); - if (err == EMAIL_ERROR_PERMISSION_DENIED) { - EM_DEBUG_LOG("permission denied"); - goto FINISH_OFF; - } -#endif if (!emstorage_query_mail_tbl(conditional_clause_string, true, &result_mail_tbl, result_count, &err)) { EM_DEBUG_EXCEPTION("emstorage_query_mail_list failed [%d]", err); @@ -792,13 +777,6 @@ EXPORT_API int email_query_mail_list(char *input_conditional_clause_string, emai EM_IF_NULL_RETURN_VALUE(input_conditional_clause_string, EMAIL_ERROR_INVALID_PARAM); EM_IF_NULL_RETURN_VALUE(output_result_count, EMAIL_ERROR_INVALID_PARAM); -#ifdef __FEATURE_ACCESS_CONTROL__ - err = em_check_db_privilege_by_pid(getpid()); - if (err == EMAIL_ERROR_PERMISSION_DENIED) { - EM_DEBUG_LOG("permission denied"); - goto FINISH_OFF; - } -#endif if (!emstorage_query_mail_list(input_conditional_clause_string, true, output_mail_list, output_result_count, &err)) { EM_DEBUG_EXCEPTION("emstorage_query_mail_list failed [%d]", err); @@ -887,14 +865,6 @@ EXPORT_API int email_get_attachment_data_list(int input_mail_id, email_attachmen { EM_DEBUG_API_BEGIN ("input_mail_id[%d] output_attachment_data[%p] output_attachment_count[%p]", input_mail_id, output_attachment_data, output_attachment_count); int err = EMAIL_ERROR_NONE; - -#ifdef __FEATURE_ACCESS_CONTROL__ - err = em_check_db_privilege_by_pid(getpid()); - if (err == EMAIL_ERROR_PERMISSION_DENIED) { - EM_DEBUG_LOG("permission denied"); - return err; - } -#endif if((err = emcore_get_attachment_data_list(input_mail_id, output_attachment_data, output_attachment_count)) != EMAIL_ERROR_NONE) { EM_DEBUG_EXCEPTION("emcore_get_attachment_data_list failed [%d]", err); @@ -926,13 +896,6 @@ EXPORT_API int email_get_mail_list_ex(email_list_filter_t *input_filter_list, in EM_IF_NULL_RETURN_VALUE(output_mail_list, EMAIL_ERROR_INVALID_PARAM); EM_IF_NULL_RETURN_VALUE(output_result_count, EMAIL_ERROR_INVALID_PARAM); -#ifdef __FEATURE_ACCESS_CONTROL__ - err = em_check_db_privilege_by_pid(getpid()); - if (err == EMAIL_ERROR_PERMISSION_DENIED) { - EM_DEBUG_LOG("permission denied"); - goto FINISH_OFF; - } -#endif if( (err = emstorage_write_conditional_clause_for_getting_mail_list(input_filter_list, input_filter_count, input_sorting_rule_list, input_sorting_rule_count, input_start_index, input_limit_count, &conditional_clause_string)) != EMAIL_ERROR_NONE) { EM_DEBUG_EXCEPTION("emstorage_write_conditional_clause_for_getting_mail_list failed[%d]", err); @@ -981,13 +944,6 @@ EXPORT_API int email_get_mails(int account_id , int mailbox_id, int thread_id, i goto FINISH_OFF; } -#ifdef __FEATURE_ACCESS_CONTROL__ - err = em_check_db_privilege_by_pid(getpid()); - if (err == EMAIL_ERROR_PERMISSION_DENIED) { - EM_DEBUG_LOG("permission denied"); - goto FINISH_OFF; - } -#endif if (!emstorage_get_mails(account_id, mailbox_id, NULL, thread_id, start_index, limit_count, sorting, true, &mail_tbl_list, result_count, &err)) { EM_DEBUG_EXCEPTION("emstorage_get_mails failed [%d]", err); @@ -1021,13 +977,6 @@ EXPORT_API int email_get_mail_list(int account_id , int mailbox_id, int thread_i return EMAIL_ERROR_INVALID_PARAM; } -#ifdef __FEATURE_ACCESS_CONTROL__ - err = em_check_db_privilege_by_pid(getpid()); - if (err == EMAIL_ERROR_PERMISSION_DENIED) { - EM_DEBUG_LOG("permission denied"); - goto FINISH_OFF; - } -#endif if (!emstorage_get_mail_list(account_id, mailbox_id, NULL, thread_id, start_index, limit_count, 0, NULL, sorting, true, mail_list, result_count, &err)) { EM_DEBUG_EXCEPTION("emstorage_get_mail_list failed [%d]", err); @@ -1057,13 +1006,6 @@ EXPORT_API int email_get_mail_by_address(int account_id , int mailbox_id, email_ return err; } -#ifdef __FEATURE_ACCESS_CONTROL__ - err = em_check_db_privilege_by_pid(getpid()); - if (err == EMAIL_ERROR_PERMISSION_DENIED) { - EM_DEBUG_LOG("permission denied"); - goto FINISH_OFF; - } -#endif if (!emstorage_get_mail_list(account_id, mailbox_id, addr_list, EMAIL_LIST_TYPE_NORMAL, start_index, limit_count, search_type, search_value, sorting, true, &mail_list_item, result_count, &err)) { EM_DEBUG_EXCEPTION("emstorage_get_mail_list failed [%d]", err); @@ -1086,13 +1028,6 @@ EXPORT_API int email_get_thread_information_by_thread_id(int thread_id, email_ma EM_IF_NULL_RETURN_VALUE(thread_info, EMAIL_ERROR_INVALID_PARAM); -#ifdef __FEATURE_ACCESS_CONTROL__ - err = em_check_db_privilege_by_pid(getpid()); - if (err == EMAIL_ERROR_PERMISSION_DENIED) { - EM_DEBUG_LOG("permission denied"); - goto FINISH_OFF; - } -#endif if (!emstorage_get_thread_information(thread_id, &mail_table_data , true, &err)) { EM_DEBUG_EXCEPTION("emstorage_get_thread_information failed [%d]", err); @@ -1122,13 +1057,6 @@ EXPORT_API int email_get_thread_information_ex(int thread_id, email_mail_list_it EM_IF_NULL_RETURN_VALUE(thread_info, EMAIL_ERROR_INVALID_PARAM); -#ifdef __FEATURE_ACCESS_CONTROL__ - err = em_check_db_privilege_by_pid(getpid()); - if (err == EMAIL_ERROR_PERMISSION_DENIED) { - EM_DEBUG_LOG("permission denied"); - goto FINISH_OFF; - } -#endif if (!emstorage_get_thread_information(thread_id, &mail_table_data , true, &err)) { EM_DEBUG_EXCEPTION("emstorage_get_thread_information -- failed [%d]", err); @@ -1181,14 +1109,6 @@ EXPORT_API int email_get_mail_data(int input_mail_id, email_mail_data_t **output EM_DEBUG_API_BEGIN ("input_mail_id[%d]", input_mail_id); int err = EMAIL_ERROR_NONE; -#ifdef __FEATURE_ACCESS_CONTROL__ - err = em_check_db_privilege_by_pid(getpid()); - if (err == EMAIL_ERROR_PERMISSION_DENIED) { - EM_DEBUG_LOG("permission denied"); - return err; - } -#endif - if ( ((err = emcore_get_mail_data(input_mail_id, output_mail_data)) != EMAIL_ERROR_NONE) || !output_mail_data) EM_DEBUG_EXCEPTION("emcore_get_mail_data failed [%d]", err); @@ -1444,6 +1364,9 @@ EXPORT_API int email_free_mail_data(email_mail_data_t** mail_list, int count) { EM_DEBUG_FUNC_BEGIN ("mail_list[%p] count[%d]", mail_list, count); int err = EMAIL_ERROR_NONE; + + EM_IF_NULL_RETURN_VALUE(mail_list, EMAIL_ERROR_INVALID_PARAM); + emcore_free_mail_data_list(mail_list, count); EM_DEBUG_FUNC_END ("err[%d]", err); return err; @@ -1644,13 +1567,6 @@ EXPORT_API int email_get_address_info_list(int mail_id, email_address_info_list_ return err; } -#ifdef __FEATURE_ACCESS_CONTROL__ - err = em_check_db_privilege_by_pid(getpid()); - if (err == EMAIL_ERROR_PERMISSION_DENIED) { - EM_DEBUG_LOG("permission denied"); - goto FINISH_OFF; - } -#endif if ( !emcore_get_mail_address_info_list(mail_id, &temp_address_info_list, &err) ) { EM_DEBUG_EXCEPTION("emcore_get_mail_address_info_list failed [%d]", err); @@ -1683,13 +1599,6 @@ EXPORT_API int email_free_address_info_list(email_address_info_list_t **address_ return err; } -EXPORT_API int email_get_structure(const char*encoded_string, void **struct_var, email_convert_struct_type_e type) -{ - EM_DEBUG_API_BEGIN ("encoded_string[%s] struct_var[%p] type[%d]", encoded_string, struct_var, type); - EM_DEBUG_API_END ("err[%d]", EMAIL_ERROR_NOT_IMPLEMENTED); - return EMAIL_ERROR_NOT_IMPLEMENTED; -} - EXPORT_API int email_query_meeting_request(char *input_conditional_clause_string, email_meeting_request_t **output_meeting_req, int *output_count) { EM_DEBUG_API_BEGIN ("input_conditional_clause_string[%s] output_meeting_req[%p] output_count[%p]", input_conditional_clause_string, output_meeting_req, output_count); @@ -1698,14 +1607,6 @@ EXPORT_API int email_query_meeting_request(char *input_conditional_clause_string EM_IF_NULL_RETURN_VALUE(input_conditional_clause_string, EMAIL_ERROR_INVALID_PARAM); EM_IF_NULL_RETURN_VALUE(output_count, EMAIL_ERROR_INVALID_PARAM); -#ifdef __FEATURE_ACCESS_CONTROL__ - err = em_check_db_privilege_by_pid(getpid()); - if (err == EMAIL_ERROR_PERMISSION_DENIED) { - EM_DEBUG_LOG("permission denied"); - return err; - } -#endif - if ((err = emstorage_query_meeting_request(input_conditional_clause_string, output_meeting_req, output_count, true)) != EMAIL_ERROR_NONE) { EM_DEBUG_EXCEPTION("emstorage_query_meeting_request failed [%d]", err); } @@ -1729,13 +1630,6 @@ EXPORT_API int email_get_meeting_request(int mail_id, email_meeting_request_t ** return err; } -#ifdef __FEATURE_ACCESS_CONTROL__ - err = em_check_db_privilege_by_pid(getpid()); - if (err == EMAIL_ERROR_PERMISSION_DENIED) { - EM_DEBUG_LOG("permission denied"); - goto FINISH_OFF; - } -#endif if ( !emstorage_get_meeting_request(mail_id, &temp_meeting_req, 1, &err) ) { EM_DEBUG_EXCEPTION("emstorage_get_meeting_request failed[%d]", err); @@ -1828,6 +1722,12 @@ EXPORT_API int email_delete_thread(int thread_id, int delete_always_flag) EM_DEBUG_API_BEGIN ("thread_id[%d] delete_always_flag[%d]", thread_id, delete_always_flag); int err = EMAIL_ERROR_NONE; + if (thread_id <= 0) { + EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM"); + err = EMAIL_ERROR_INVALID_PARAM; + return err; + } + HIPC_API hAPI = emipc_create_email_api(_EMAIL_API_DELETE_THREAD); if(!hAPI) { @@ -1871,6 +1771,13 @@ EXPORT_API int email_modify_seen_flag_of_thread(int thread_id, int seen_flag, in { EM_DEBUG_API_BEGIN ("thread_id[%d] seen_flag[%d] on_server[%d]", thread_id, seen_flag, on_server); int err = EMAIL_ERROR_NONE; + + if (thread_id <= 0) { + EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM"); + err = EMAIL_ERROR_INVALID_PARAM; + return err; + } + HIPC_API hAPI = emipc_create_email_api(_EMAIL_API_MODIFY_SEEN_FLAG_OF_THREAD); if(!hAPI) { diff --git a/email-api/email-api-mailbox.c b/email-api/email-api-mailbox.c index ccd01cf..070fb5b 100755 --- a/email-api/email-api-mailbox.c +++ b/email-api/email-api-mailbox.c @@ -38,7 +38,6 @@ #include "email-core-signal.h" #include "email-utilities.h" #include "email-ipc.h" -#include "db-util.h" /* API - Create a mailbox */ @@ -611,13 +610,6 @@ EXPORT_API int email_get_mailbox_list(int account_id, int mailbox_sync_type, ema EM_IF_ACCOUNT_ID_NULL(account_id, EMAIL_ERROR_INVALID_PARAM); EM_IF_NULL_RETURN_VALUE(count, EMAIL_ERROR_INVALID_PARAM); -#ifdef __FEATURE_ACCESS_CONTROL__ - err = em_check_db_privilege_by_pid(getpid()); - if (err == EMAIL_ERROR_PERMISSION_DENIED) { - EM_DEBUG_LOG("permission denied"); - goto FINISH_OFF; - } -#endif if (!emstorage_get_mailbox_list(account_id, mailbox_sync_type, EMAIL_MAILBOX_SORT_BY_NAME_ASC, &mailbox_count, &mailbox_tbl_list, true, &err)) { EM_DEBUG_EXCEPTION("emstorage_get_mailbox failed [%d]", err); @@ -663,13 +655,6 @@ EXPORT_API int email_get_mailbox_list_ex(int account_id, int mailbox_sync_type, EM_IF_ACCOUNT_ID_NULL(account_id, EMAIL_ERROR_INVALID_PARAM); EM_IF_NULL_RETURN_VALUE(count, EMAIL_ERROR_INVALID_PARAM); -#ifdef __FEATURE_ACCESS_CONTROL__ - err = em_check_db_privilege_by_pid(getpid()); - if (err == EMAIL_ERROR_PERMISSION_DENIED) { - EM_DEBUG_LOG("permission denied"); - goto FINISH_OFF; - } -#endif if (!emstorage_get_mailbox_list_ex(account_id, mailbox_sync_type, with_count, &mailbox_count, &mailbox_tbl_list, true, &err)) { EM_DEBUG_EXCEPTION("emstorage_get_mailbox_list_ex failed [%d]", err); @@ -714,13 +699,6 @@ EXPORT_API int email_get_mailbox_list_by_keyword(int account_id, char *keyword, EM_IF_NULL_RETURN_VALUE(mailbox_list, EMAIL_ERROR_INVALID_PARAM); EM_IF_NULL_RETURN_VALUE(count, EMAIL_ERROR_INVALID_PARAM); -#ifdef __FEATURE_ACCESS_CONTROL__ - err = em_check_db_privilege_by_pid(getpid()); - if (err == EMAIL_ERROR_PERMISSION_DENIED) { - EM_DEBUG_LOG("permission denied"); - goto FINISH_OFF; - } -#endif if (!emstorage_get_mailbox_by_keyword(account_id, keyword, &mailbox_tbl_list, &mailbox_count, true, &err)) { EM_DEBUG_EXCEPTION("emstorage_get_mailbox_by_keyword failed [%d]", err); @@ -765,13 +743,6 @@ EXPORT_API int email_get_mailbox_by_mailbox_type(int account_id, email_mailbox_t if(mailbox_type < EMAIL_MAILBOX_TYPE_INBOX || mailbox_type > EMAIL_MAILBOX_TYPE_USER_DEFINED) return EMAIL_ERROR_INVALID_PARAM; -#ifdef __FEATURE_ACCESS_CONTROL__ - err = em_check_db_privilege_by_pid(getpid()); - if (err == EMAIL_ERROR_PERMISSION_DENIED) { - EM_DEBUG_LOG("permission denied"); - goto FINISH_OFF; - } -#endif if (!emstorage_get_mailbox_by_mailbox_type(account_id, mailbox_type, &local_mailbox, true, &err)) { EM_DEBUG_EXCEPTION("emstorage_get_mailbox_by_mailbox_type failed [%d]", err); @@ -803,14 +774,6 @@ EXPORT_API int email_get_mailbox_by_mailbox_id(int input_mailbox_id, email_mailb EM_IF_NULL_RETURN_VALUE(output_mailbox, EMAIL_ERROR_INVALID_PARAM); -#ifdef __FEATURE_ACCESS_CONTROL__ - err = em_check_db_privilege_by_pid(getpid()); - if (err == EMAIL_ERROR_PERMISSION_DENIED) { - EM_DEBUG_LOG("permission denied"); - return err; - } -#endif - if ( (err = emstorage_get_mailbox_by_id(input_mailbox_id, &local_mailbox)) != EMAIL_ERROR_NONE) { EM_DEBUG_EXCEPTION("emstorage_get_mailbox_by_id failed [%d]", err); return err; @@ -889,14 +852,6 @@ EXPORT_API int email_stamp_sync_time_of_mailbox(int input_mailbox_id) EM_IF_NULL_RETURN_VALUE(input_mailbox_id, EMAIL_ERROR_INVALID_PARAM); -#ifdef __FEATURE_ACCESS_CONTROL__ - err = em_check_db_privilege_by_pid(getpid()); - if (err == EMAIL_ERROR_PERMISSION_DENIED) { - EM_DEBUG_LOG("permission denied"); - return err; - } -#endif - err = emstorage_stamp_last_sync_time_of_mailbox(input_mailbox_id, 1); EM_DEBUG_API_END ("err[%d]", err); @@ -909,6 +864,8 @@ EXPORT_API int email_free_mailbox(email_mailbox_t** mailbox_list, int count) int err = EMAIL_ERROR_NONE; if (count <= 0 || !mailbox_list || !*mailbox_list) { + EM_DEBUG_LOG("EMAIL_ERROR_INVALID_PARAM"); + err = EMAIL_ERROR_INVALID_PARAM; goto FINISH_OFF; } diff --git a/email-api/email-api-network.c b/email-api/email-api-network.c index 1054660..a02556c 100755 --- a/email-api/email-api-network.c +++ b/email-api/email-api-network.c @@ -921,6 +921,9 @@ EXPORT_API int email_get_task_information(email_task_information_t **output_task } } + if (err == EMAIL_ERROR_DATA_NOT_FOUND) + err = EMAIL_ERROR_NONE; + FINISH_OFF: if(hAPI) emipc_destroy_email_api(hAPI); @@ -964,182 +967,6 @@ EXPORT_API int email_sync_imap_mailbox_list(int account_id, int *handle) return err; } -EXPORT_API int email_search_mail_on_server(int input_account_id, int input_mailbox_id, email_search_filter_t *input_search_filter_list, int input_search_filter_count, int *output_handle) -{ - EM_DEBUG_API_BEGIN ("input_account_id[%d] input_mailbox_id[%d] input_search_filter_list[%p] input_search_filter_count[%d] output_handle[%p]", input_account_id, input_mailbox_id, input_search_filter_list, input_search_filter_count, output_handle); - - int err = EMAIL_ERROR_NONE; - int return_value = 0; - int stream_size_for_search_filter_list = 0; - char *stream_for_search_filter_list = NULL; - HIPC_API hAPI = NULL; - email_account_server_t account_server_type = EMAIL_SERVER_TYPE_NONE; - ASNotiData as_noti_data; - - EM_IF_NULL_RETURN_VALUE(input_account_id, EMAIL_ERROR_INVALID_PARAM); - EM_IF_NULL_RETURN_VALUE(input_mailbox_id, EMAIL_ERROR_INVALID_PARAM); - EM_IF_NULL_RETURN_VALUE(input_search_filter_list, EMAIL_ERROR_INVALID_PARAM); - - memset(&as_noti_data, 0, sizeof(ASNotiData)); /* initialization of union members */ - - if ( em_get_account_server_type_by_account_id(input_account_id, &account_server_type, true, &err) == false ) { - EM_DEBUG_EXCEPTION("em_get_account_server_type_by_account_id failed[%d]", err); - goto FINISH_OFF; - } - - if ( account_server_type == EMAIL_SERVER_TYPE_ACTIVE_SYNC ) { - int as_handle = 0; - - if ( em_get_handle_for_activesync(&as_handle, &err) == false ) { - EM_DEBUG_EXCEPTION("em_get_handle_for_activesync failed[%d].", err); - goto FINISH_OFF; - } - - /* noti to active sync */ - as_noti_data.search_mail_on_server.handle = as_handle; - as_noti_data.search_mail_on_server.account_id = input_account_id; - as_noti_data.search_mail_on_server.mailbox_id = input_mailbox_id; - as_noti_data.search_mail_on_server.search_filter_list = input_search_filter_list; - as_noti_data.search_mail_on_server.search_filter_count = input_search_filter_count; - - return_value = em_send_notification_to_active_sync_engine(ACTIVE_SYNC_NOTI_SEARCH_ON_SERVER, &as_noti_data); - - if ( return_value == false ) { - EM_DEBUG_EXCEPTION("em_send_notification_to_active_sync_engine failed."); - err = EMAIL_ERROR_ACTIVE_SYNC_NOTI_FAILURE; - goto FINISH_OFF; - } - - if(output_handle) - *output_handle = as_handle; - } - else - { - hAPI = emipc_create_email_api(_EMAIL_API_SEARCH_MAIL_ON_SERVER); - - EM_IF_NULL_RETURN_VALUE(hAPI, EMAIL_ERROR_NULL_VALUE); - - if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (void*)&input_account_id, sizeof(int))) { - EM_DEBUG_EXCEPTION("emipc_add_parameter failed "); - err = EMAIL_ERROR_IPC_PROTOCOL_FAILURE; - goto FINISH_OFF; - } - - if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (void*)&input_mailbox_id, sizeof(int))){ - EM_DEBUG_EXCEPTION("emipc_add_parameter failed "); - err = EMAIL_ERROR_IPC_PROTOCOL_FAILURE; - goto FINISH_OFF; - } - - stream_for_search_filter_list = em_convert_search_filter_to_byte_stream(input_search_filter_list, input_search_filter_count, &stream_size_for_search_filter_list); - - EM_PROXY_IF_NULL_RETURN_VALUE(stream_for_search_filter_list, hAPI, EMAIL_ERROR_NULL_VALUE); - - if(!emipc_add_dynamic_parameter(hAPI, ePARAMETER_IN, stream_for_search_filter_list, stream_size_for_search_filter_list)) { /*prevent 18950*/ - EM_DEBUG_EXCEPTION("emipc_add_parameter failed "); - err = EMAIL_ERROR_IPC_PROTOCOL_FAILURE; - goto FINISH_OFF; - } - - if(emipc_execute_proxy_api(hAPI) != EMAIL_ERROR_NONE) { - EM_DEBUG_EXCEPTION("emipc_execute_proxy_api failed"); - EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_IPC_SOCKET_FAILURE); - } - - emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &err); - - if (err != EMAIL_ERROR_NONE) { - EM_DEBUG_EXCEPTION("_EMAIL_API_SEARCH_MAIL_ON_SERVER failed [%d]", err); - goto FINISH_OFF; - } - - if(output_handle) - emipc_get_parameter(hAPI, ePARAMETER_OUT, 1, sizeof(int), output_handle); - } - -FINISH_OFF: - if(hAPI) { - emipc_destroy_email_api(hAPI); - hAPI = NULL; - } - - EM_DEBUG_API_END ("err[%d]", err); - return err; -} - -EXPORT_API int email_clear_result_of_search_mail_on_server(int input_account_id) -{ - EM_DEBUG_API_BEGIN ("input_account_id[%d]", input_account_id); - - int err = EMAIL_ERROR_NONE; - int return_value = 0; - HIPC_API hAPI = NULL; - email_account_server_t account_server_type = EMAIL_SERVER_TYPE_NONE; - ASNotiData as_noti_data; - - EM_IF_NULL_RETURN_VALUE(input_account_id, EMAIL_ERROR_INVALID_PARAM); - - memset(&as_noti_data, 0, sizeof(ASNotiData)); /* initialization of union members */ - - if ( em_get_account_server_type_by_account_id(input_account_id, &account_server_type, true, &err) == false ) { - EM_DEBUG_EXCEPTION("em_get_account_server_type_by_account_id failed[%d]", err); - goto FINISH_OFF; - } - - if ( account_server_type == EMAIL_SERVER_TYPE_ACTIVE_SYNC ) { - int as_handle = 0; - - if ( em_get_handle_for_activesync(&as_handle, &err) == false ) { - EM_DEBUG_EXCEPTION("em_get_handle_for_activesync failed[%d].", err); - goto FINISH_OFF; - } - - /* noti to active sync */ - as_noti_data.clear_result_of_search_mail_on_server.handle = as_handle; - as_noti_data.clear_result_of_search_mail_on_server.account_id = input_account_id; - - return_value = em_send_notification_to_active_sync_engine(ACTIVE_SYNC_NOTI_CLEAR_RESULT_OF_SEARCH_ON_SERVER, &as_noti_data); - - if ( return_value == false ) { - EM_DEBUG_EXCEPTION("em_send_notification_to_active_sync_engine failed."); - err = EMAIL_ERROR_ACTIVE_SYNC_NOTI_FAILURE; - goto FINISH_OFF; - } - } - else { - hAPI = emipc_create_email_api(_EMAIL_API_CLEAR_RESULT_OF_SEARCH_MAIL_ON_SERVER); - - EM_IF_NULL_RETURN_VALUE(hAPI, EMAIL_ERROR_NULL_VALUE); - - if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (void*)&input_account_id, sizeof(int))) { - EM_DEBUG_EXCEPTION("emipc_add_parameter failed "); - err = EMAIL_ERROR_IPC_PROTOCOL_FAILURE; - goto FINISH_OFF; - } - - if(emipc_execute_proxy_api(hAPI) != EMAIL_ERROR_NONE) { - EM_DEBUG_EXCEPTION("emipc_execute_proxy_api failed"); - EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_IPC_SOCKET_FAILURE); - } - - emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &err); - - if (err != EMAIL_ERROR_NONE) { - EM_DEBUG_EXCEPTION("_EMAIL_API_CLEAR_RESULT_OF_SEARCH_MAIL_ON_SERVER failed [%d]", err); - goto FINISH_OFF; - } - } - -FINISH_OFF: - if(hAPI) { - emipc_destroy_email_api(hAPI); - hAPI = NULL; - } - - EM_DEBUG_API_END ("err[%d]", err); - return err; -} - EXPORT_API int email_query_smtp_mail_size_limit(int account_id, int *handle) { EM_DEBUG_API_BEGIN ("account_id[%d] handle[%p]", account_id, handle); diff --git a/email-api/email-api-rule.c b/email-api/email-api-rule.c index 34a61f7..3290150 100755 --- a/email-api/email-api-rule.c +++ b/email-api/email-api-rule.c @@ -36,6 +36,7 @@ #include "email-storage.h" #include "email-utilities.h" #include "email-ipc.h" +#include "email-core-utils.h" EXPORT_API int email_get_rule(int filter_id, email_rule_t** filtering_set) { @@ -46,13 +47,6 @@ EXPORT_API int email_get_rule(int filter_id, email_rule_t** filtering_set) EM_IF_NULL_RETURN_VALUE(filtering_set, EMAIL_ERROR_INVALID_PARAM); EM_IF_NULL_RETURN_VALUE(filter_id, EMAIL_ERROR_INVALID_PARAM); -#ifdef __FEATURE_ACCESS_CONTROL__ - err = em_check_db_privilege_by_pid(getpid()); - if (err == EMAIL_ERROR_PERMISSION_DENIED) { - EM_DEBUG_LOG("permission denied"); - goto FINISH_OFF; - } -#endif if (!emstorage_get_rule_by_id(filter_id, (emstorage_rule_tbl_t**)filtering_set, true, &err)) { EM_DEBUG_EXCEPTION("emstorage_get_rule_by_id failed [%d]", err); @@ -77,13 +71,6 @@ EXPORT_API int email_get_rule_list(email_rule_t** filtering_set, int* count) EM_IF_NULL_RETURN_VALUE(filtering_set, EMAIL_ERROR_INVALID_PARAM); EM_IF_NULL_RETURN_VALUE(count, EMAIL_ERROR_INVALID_PARAM); -#ifdef __FEATURE_ACCESS_CONTROL__ - err = em_check_db_privilege_by_pid(getpid()); - if (err == EMAIL_ERROR_PERMISSION_DENIED) { - EM_DEBUG_LOG("permission denied"); - goto FINISH_OFF; - } -#endif *count = 1000; @@ -245,11 +232,11 @@ EXPORT_API int email_free_rule (email_rule_t** filtering_set, int count) if (count > 0) { email_rule_t* p = *filtering_set; - for (i = 0; i < count; i++) { - EM_SAFE_FREE(p[i].value); - } + for (i = 0; i < count; i++) + emcore_free_rule(p + i); - EM_SAFE_FREE(p); *filtering_set = NULL; + EM_SAFE_FREE(p); + *filtering_set = NULL; } EM_DEBUG_FUNC_END ("err[%d]", err); diff --git a/email-api/email-api-smime.c b/email-api/email-api-smime.c index 96708dc..c84890b 100755 --- a/email-api/email-api-smime.c +++ b/email-api/email-api-smime.c @@ -41,6 +41,7 @@ #include "email-core-account.h" #include "email-core-cert.h" #include "email-core-smime.h" +#include "email-core-pgp.h" #include "email-core-signal.h" #include "email-ipc.h" @@ -154,14 +155,6 @@ EXPORT_API int email_get_certificate(char *email_address, email_certificate_t ** EM_IF_NULL_RETURN_VALUE(email_address, EMAIL_ERROR_INVALID_PARAM); EM_IF_NULL_RETURN_VALUE(certificate, EMAIL_ERROR_INVALID_PARAM); -#ifdef __FEATURE_ACCESS_CONTROL__ - err = em_check_db_privilege_by_pid(getpid()); - if (err == EMAIL_ERROR_PERMISSION_DENIED) { - EM_DEBUG_LOG("permission denied"); - return err; - } -#endif - SNPRINTF(temp_email_address, sizeof(temp_email_address), "<%s>", email_address); if (!emstorage_get_certificate_by_email_address(temp_email_address, &cert, false, 0, &err)) { @@ -184,6 +177,7 @@ EXPORT_API int email_get_decrypt_message(int mail_id, email_mail_data_t **output int err = EMAIL_ERROR_NONE; int p_output_attachment_count = 0; int i = 0; + int verify = 0; char *decrypt_filepath = NULL; char *search = NULL; email_mail_data_t *p_output_mail_data = NULL; @@ -198,14 +192,6 @@ EXPORT_API int email_get_decrypt_message(int mail_id, email_mail_data_t **output goto FINISH_OFF; } -#ifdef __FEATURE_ACCESS_CONTROL__ - err = em_check_db_privilege_by_pid(getpid()); - if (err == EMAIL_ERROR_PERMISSION_DENIED) { - EM_DEBUG_LOG("permission denied"); - goto FINISH_OFF; - } -#endif - if ((err = emcore_get_mail_data(mail_id, &p_output_mail_data)) != EMAIL_ERROR_NONE) { EM_DEBUG_EXCEPTION("emcore_get_mail_data failed"); goto FINISH_OFF; @@ -226,7 +212,10 @@ EXPORT_API int email_get_decrypt_message(int mail_id, email_mail_data_t **output if (p_output_attachment_data[i].attachment_mime_type && (search = strcasestr(p_output_attachment_data[i].attachment_mime_type, "PKCS7-MIME"))) { EM_DEBUG_LOG("Found the encrypt file"); break; - } + } else if (p_output_attachment_data[i].attachment_mime_type && (search = strcasestr(p_output_attachment_data[i].attachment_mime_type, "octet-stream"))) { + EM_DEBUG_LOG("Found the encrypt file"); + break; + } } if (!search) { @@ -235,8 +224,27 @@ EXPORT_API int email_get_decrypt_message(int mail_id, email_mail_data_t **output goto FINISH_OFF; } - if (!emcore_smime_set_decrypt_message(p_output_attachment_data[i].attachment_path, p_account_tbl->certificate_path, &decrypt_filepath, &err)) { - EM_DEBUG_EXCEPTION("emcore_smime_set_decrypt_message failed"); + if (p_output_mail_data->smime_type == EMAIL_SMIME_ENCRYPTED || p_output_mail_data->smime_type == EMAIL_SMIME_SIGNED_AND_ENCRYPTED) { + emcore_init_openssl_library(); + if (!emcore_smime_get_decrypt_message(p_output_attachment_data[i].attachment_path, p_account_tbl->certificate_path, &decrypt_filepath, &err)) { + EM_DEBUG_EXCEPTION("emcore_smime_get_decrypt_message failed"); + emcore_clean_openssl_library(); + goto FINISH_OFF; + } + emcore_clean_openssl_library(); + } else if (p_output_mail_data->smime_type == EMAIL_PGP_ENCRYPTED) { + if ((err = emcore_pgp_get_decrypted_message(p_output_attachment_data[i].attachment_path, p_output_mail_data->pgp_password, false, &decrypt_filepath, &verify)) != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emcore_pgp_get_decrypted_message failed : [%d]", err); + goto FINISH_OFF; + } + } else if (p_output_mail_data->smime_type == EMAIL_PGP_SIGNED_AND_ENCRYPTED) { + if ((err = emcore_pgp_get_decrypted_message(p_output_attachment_data[i].attachment_path, p_output_mail_data->pgp_password, true, &decrypt_filepath, &verify)) != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emcore_pgp_get_decrypted_message failed : [%d]", err); + goto FINISH_OFF; + } + } else { + EM_DEBUG_LOG("Invalid encrypted mail"); + err = EMAIL_ERROR_INVALID_PARAM; goto FINISH_OFF; } @@ -256,9 +264,12 @@ EXPORT_API int email_get_decrypt_message(int mail_id, email_mail_data_t **output (*output_mail_data)->full_address_to = EM_SAFE_STRDUP(p_output_mail_data->full_address_to); (*output_mail_data)->full_address_cc = EM_SAFE_STRDUP(p_output_mail_data->full_address_cc); (*output_mail_data)->full_address_bcc = EM_SAFE_STRDUP(p_output_mail_data->full_address_bcc); + (*output_mail_data)->flags_flagged_field = p_output_mail_data->flags_flagged_field; FINISH_OFF: + EM_SAFE_FREE(decrypt_filepath); + if (p_account_tbl) emstorage_free_account(&p_account_tbl, 1, NULL); @@ -272,6 +283,100 @@ FINISH_OFF: return err; } +EXPORT_API int email_get_decrypt_message_ex(email_mail_data_t *input_mail_data, email_attachment_data_t *input_attachment_data, int input_attachment_count, + email_mail_data_t **output_mail_data, email_attachment_data_t **output_attachment_data, int *output_attachment_count) +{ + EM_DEBUG_API_BEGIN (); + int err = EMAIL_ERROR_NONE; + int i = 0; + int verify = 0; + char *decrypt_filepath = NULL; + char *search = NULL; + emstorage_account_tbl_t *p_account_tbl = NULL; + + EM_IF_NULL_RETURN_VALUE(input_mail_data, EMAIL_ERROR_INVALID_PARAM); + + if (!output_mail_data || !output_attachment_data || !output_attachment_count) { + EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM"); + err = EMAIL_ERROR_INVALID_PARAM; + goto FINISH_OFF; + } + + if (!emstorage_get_account_by_id(input_mail_data->account_id, EMAIL_ACC_GET_OPT_OPTIONS, &p_account_tbl, false, &err)) { + EM_DEBUG_EXCEPTION("emstorage_get_account_by_id failed : [%d]", err); + goto FINISH_OFF; + } + + for (i = 0; i < input_attachment_count; i++) { + EM_DEBUG_LOG("mime_type : [%s]", input_attachment_data[i].attachment_mime_type); + if (input_attachment_data[i].attachment_mime_type && (search = strcasestr(input_attachment_data[i].attachment_mime_type, "PKCS7-MIME"))) { + EM_DEBUG_LOG("Found the encrypt file"); + break; + } else if (input_attachment_data[i].attachment_mime_type && (search = strcasestr(input_attachment_data[i].attachment_mime_type, "octet-stream"))) { + EM_DEBUG_LOG("Found the encrypt file"); + break; + } + } + + if (!search) { + EM_DEBUG_EXCEPTION("No have a decrypt file"); + err = EMAIL_ERROR_INVALID_PARAM; + goto FINISH_OFF; + } + + if (input_mail_data->smime_type == EMAIL_SMIME_ENCRYPTED || input_mail_data->smime_type == EMAIL_SMIME_SIGNED_AND_ENCRYPTED) { + emcore_init_openssl_library(); + if (!emcore_smime_get_decrypt_message(input_attachment_data[i].attachment_path, p_account_tbl->certificate_path, &decrypt_filepath, &err)) { + EM_DEBUG_EXCEPTION("emcore_smime_get_decrypt_message failed"); + emcore_clean_openssl_library(); + goto FINISH_OFF; + } + emcore_clean_openssl_library(); + } else if (input_mail_data->smime_type == EMAIL_PGP_ENCRYPTED) { + if ((err = emcore_pgp_get_decrypted_message(input_attachment_data[i].attachment_path, input_mail_data->pgp_password, false, &decrypt_filepath, &verify)) != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emcore_pgp_get_decrypted_message failed : [%d]", err); + goto FINISH_OFF; + } + } else if (input_mail_data->smime_type == EMAIL_PGP_SIGNED_AND_ENCRYPTED) { + if ((err = emcore_pgp_get_decrypted_message(input_attachment_data[i].attachment_path, input_mail_data->pgp_password, true, &decrypt_filepath, &verify)) != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emcore_pgp_get_decrypted_message failed : [%d]", err); + goto FINISH_OFF; + } + } else { + EM_DEBUG_LOG("Invalid encrypted mail"); + err = EMAIL_ERROR_INVALID_PARAM; + goto FINISH_OFF; + } + + /* Change decrpyt_message to mail_data_t */ + if (!emcore_parse_mime_file_to_mail(decrypt_filepath, output_mail_data, output_attachment_data, output_attachment_count, &err)) { + EM_DEBUG_EXCEPTION("emcore_parse_mime_file_to_mail failed : [%d]", err); + goto FINISH_OFF; + } + + (*output_mail_data)->subject = EM_SAFE_STRDUP(input_mail_data->subject); + (*output_mail_data)->date_time = input_mail_data->date_time; + (*output_mail_data)->full_address_return = EM_SAFE_STRDUP(input_mail_data->full_address_return); + (*output_mail_data)->email_address_recipient = EM_SAFE_STRDUP(input_mail_data->email_address_recipient); + (*output_mail_data)->email_address_sender = EM_SAFE_STRDUP(input_mail_data->email_address_sender); + (*output_mail_data)->full_address_reply = EM_SAFE_STRDUP(input_mail_data->full_address_reply); + (*output_mail_data)->full_address_from = EM_SAFE_STRDUP(input_mail_data->full_address_from); + (*output_mail_data)->full_address_to = EM_SAFE_STRDUP(input_mail_data->full_address_to); + (*output_mail_data)->full_address_cc = EM_SAFE_STRDUP(input_mail_data->full_address_cc); + (*output_mail_data)->full_address_bcc = EM_SAFE_STRDUP(input_mail_data->full_address_bcc); + (*output_mail_data)->flags_flagged_field = input_mail_data->flags_flagged_field; + +FINISH_OFF: + + EM_SAFE_FREE(decrypt_filepath); + + if (p_account_tbl) + emstorage_free_account(&p_account_tbl, 1, NULL); + + EM_DEBUG_API_END ("err[%d]", err); + return err; +} + EXPORT_API int email_verify_signature(int mail_id, int *verify) { EM_DEBUG_API_BEGIN ("mail_id[%d]", mail_id); @@ -279,7 +384,7 @@ EXPORT_API int email_verify_signature(int mail_id, int *verify) int err = EMAIL_ERROR_NONE; int p_verify = 0; - EM_IF_NULL_RETURN_VALUE(mail_id, EMAIL_ERROR_INVALID_PARAM); + EM_IF_NULL_RETURN_VALUE(mail_id, EMAIL_ERROR_INVALID_PARAM); HIPC_API hAPI = emipc_create_email_api(_EMAIL_API_VERIFY_SIGNATURE); if (hAPI == NULL) { @@ -336,8 +441,20 @@ EXPORT_API int email_verify_signature_ex(email_mail_data_t *input_mail_data, ema break; } - if (!emcore_verify_signature(input_attachment_data[count].attachment_path, input_mail_data->file_path_mime_entity, verify, &err)) - EM_DEBUG_EXCEPTION("emcore_verify_signature failed"); + if (input_mail_data->smime_type == EMAIL_SMIME_SIGNED) { + emcore_init_openssl_library(); + if (!emcore_verify_signature(input_attachment_data[count].attachment_path, input_mail_data->file_path_mime_entity, verify, &err)) + EM_DEBUG_EXCEPTION("emcore_verify_signature failed : [%d]", err); + + emcore_clean_openssl_library(); + } else if(input_mail_data->smime_type == EMAIL_PGP_SIGNED) { + if ((err = emcore_pgp_get_verify_signature(input_attachment_data[count].attachment_path, input_mail_data->file_path_mime_entity, input_mail_data->digest_type, verify)) != EMAIL_ERROR_NONE) + EM_DEBUG_EXCEPTION("emcore_pgp_get_verify_siganture failed : [%d]", err); + } else { + EM_DEBUG_LOG("Invalid signed mail : mime_type[%d]", input_mail_data->smime_type); + err = EMAIL_ERROR_INVALID_PARAM; + } + EM_DEBUG_API_END ("err[%d]", err); return err; diff --git a/email-api/include/email-api-account.h b/email-api/include/email-api-account.h index 98c545c..6da101a 100755 --- a/email-api/include/email-api-account.h +++ b/email-api/include/email-api-account.h @@ -26,371 +26,429 @@ #include "email-types.h" /** -* @defgroup EMAIL_SERVICE Email Service -* @{ -*/ - - -/** -* @ingroup EMAIL_SERVICE -* @defgroup EMAIL_API_ACCOUNT Email Account API -* @{ -*/ + * @internal + * @ingroup EMAIL_SERVICE_FRAMEWORK + * @defgroup EMAIL_SERVICE_ACCOUNT_MODULE Account API + * @brief Account API is a set of operations to manage email accounts like add, update, delete or get account related details. + * + * @section EMAIL_SERVICE_ACCOUNT_MODULE_HEADER Required Header + * \#include <email-api.h> + * + * @section EMAIL_SERVICE_ACCOUNT_MODULE_OVERVIEW Overview + * Account API is a set of operations to manage email accounts like add, update, delete or get account related details. + */ /** + * @file email-api-account.h + * @brief This file contains the data structures and interfaces of Accounts provided by email-service. + * @{ + * @code + * #include "email-api-account.h" + * bool + * other_app_invoke_uniform_api_sample(int* error_code) + * { + * email_account_t *account = NULL; + * email_account_t *new_account = NULL; * - * This file contains the data structures and interfaces needed for application, - * to interact with email-service. - * @file email-api-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-service . + * account = malloc(sizeof(email_account_t)); + * memset(account, 0x00, sizeof(email_account_t)); * -* @{ - -* @code -* #include "email-api-account.h" -* bool -* other_app_invoke_uniform_api_sample(int* error_code) -* { -* email_account_t *account = NULL; -* email_account_t *new_account = NULL; -* -* account = malloc(sizeof(email_account_t)); -* memset(account, 0x00, sizeof(email_account_t)); -* -* account->retrieval_mode = 1; -* account->incoming_server_secure_connection = 1; -* account->outgoing_server_type = EMAIL_SERVER_TYPE_SMTP; -* account->outgoing_server_port_number = EMAIL_SMTP_PORT; -* account->outgoing_server_need_authentication = 1; -* account->account_name = strdup("gmail"); -* account->display_name = strdup("Tom"); -* account->user_email_address = strdup("tom@gmail.com"); -* account->reply_to_addr = strdup("tom@gmail.com"); -* account->return_addr = strdup("tom@gmail.com"); -* account->incoming_server_type = EMAIL_SERVER_TYPE_POP3; -* account->incoming_server_address = strdup("pop3.gmail.com"); -* account->incoming_server_port_number = 995; -* account->incoming_server_secure_connection = 1; -* account->retrieval_mode = EMAIL_IMAP4_RETRIEVAL_MODE_ALL; -* account->incoming_server_user_name = strdup("tom"); -* account->password = strdup("password"); -* account->outgoing_server_type = EMAIL_SERVER_TYPE_SMTP; -* account->outgoing_server_address = strdup("smtp.gmail.com"); -* account->outgoing_server_port_number = 587; -* account->outgoing_server_secure_connection = 0x02; -* account->outgoing_server_need_authentication = 1; -* account->outgoing_server_user_name = strdup("tom@gmail.com"); -* account->sending_password = strdup("password"); -* account->auto_resend_times = 0; -* account->pop_before_smtp = 0; -* account->incoming_server_requires_apop = 0; -* account->incoming_server_authentication_method = 0; -* account->is_preset_account = 1; -* account->logo_icon_path = strdup("Logo Icon Path"); -* 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(EMAIL_ERROR_NONE != email_add_account(account)) -* //failure -* //else -* { -* //success -* if(account_id) -* *account_id = account->account_id; -* } -* if(EMAIL_ERROR_NONE != email_validate_account(account_id,&account_handle)) -* //failure -* else -* //success -* if(EMAIL_ERROR_NONE != email_delete_account(account_id)) -* //failure -* else -* //success -* new_account = malloc(sizeof(email_account_t)); -* memset(new_account, 0x00, sizeof(email_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(EMAIL_ERROR_NONE != email_update_account(acount_id,new_account)) -* //failure -* else -* //success -* // Get account -* if(EMAIL_ERROR_NONE != email_get_account(account_id,GET_FULL_DATA,&account)) -* //failure -* else -* //success -* // Get list of accounts -* if(EMAIL_ERROR_NONE != email_get_account_list(&account_list,&count)) -* //failure -* else -* //success -* // free account -* email_free_account(&account, 1); -* } + * account->retrieval_mode = 1; + * account->incoming_server_secure_connection = 1; + * account->outgoing_server_type = EMAIL_SERVER_TYPE_SMTP; + * account->outgoing_server_port_number = EMAIL_SMTP_PORT; + * account->outgoing_server_need_authentication = 1; + * account->account_name = strdup("gmail"); + * account->display_name = strdup("Tom"); + * account->user_email_address = strdup("tom@gmail.com"); + * account->reply_to_addr = strdup("tom@gmail.com"); + * account->return_addr = strdup("tom@gmail.com"); + * account->incoming_server_type = EMAIL_SERVER_TYPE_POP3; + * account->incoming_server_address = strdup("pop3.gmail.com"); + * account->incoming_server_port_number = 995; + * account->incoming_server_secure_connection = 1; + * account->retrieval_mode = EMAIL_IMAP4_RETRIEVAL_MODE_ALL; + * account->incoming_server_user_name = strdup("tom"); + * account->password = strdup("password"); + * account->outgoing_server_type = EMAIL_SERVER_TYPE_SMTP; + * account->outgoing_server_address = strdup("smtp.gmail.com"); + * account->outgoing_server_port_number = 587; + * account->outgoing_server_secure_connection = 0x02; + * account->outgoing_server_need_authentication = 1; + * account->outgoing_server_user_name = strdup("tom@gmail.com"); + * account->sending_password = strdup("password"); + * account->auto_resend_times = 0; + * account->pop_before_smtp = 0; + * account->incoming_server_requires_apop = 0; + * account->incoming_server_authentication_method = 0; + * account->is_preset_account = 1; + * account->logo_icon_path = strdup("Logo Icon Path"); + * 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(EMAIL_ERROR_NONE != email_add_account(account)) + * //failure + * //else + * { + * //success + * if(account_id) + * *account_id = account->account_id; + * } + * if(EMAIL_ERROR_NONE != email_validate_account(account_id,&account_handle)) + * //failure + * else + * //success + * if(EMAIL_ERROR_NONE != email_delete_account(account_id)) + * //failure + * else + * //success + * new_account = malloc(sizeof(email_account_t)); + * memset(new_account, 0x00, sizeof(email_account_t)); + * new_account->flag1 = 1; + * new_account->account_name = strdup("tizen001"); + * new_account->display_name = strdup("Tom001"); + * new_account->options.keep_local_copy = 1; + * new_account->check_interval = 55; + * // Update account + * if(EMAIL_ERROR_NONE != email_update_account(acount_id,new_account)) + * //failure + * else + * //success + * // Get account + * if(EMAIL_ERROR_NONE != email_get_account(account_id,GET_FULL_DATA,&account)) + * //failure + * else + * //success + * // Get list of accounts + * if(EMAIL_ERROR_NONE != email_get_account_list(&account_list,&count)) + * //failure + * else + * //success + * // free account + * email_free_account(&account, 1); + * } * * @endcode * @} */ +/** + * @internal + * @addtogroup EMAIL_SERVICE_ACCOUNT_MODULE + * @{ + */ #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ /** - * @fn email_add_account(email_account_t* account) - * @brief Create a new email account.This function is invoked when user wants to add new email account + * @brief Creates a new email account. + * @details This function is invoked when the user wants to add a new email account. * - * @param[in] account Specifies the structure pointer of account. - * @exception none - * @return This function returns EMAIL_ERROR_NONE on success or error code (refer to EMAIL_ERROR_XXX) on failure. - * @see email_account_t - * @remarks N/A + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/email + * @param[in] account The structure pointer of an account + * + * @return #EMAIL_ERROR_NONE on success, + * otherwise an error code (see #EMAIL_ERROR_XXX) on failure + * + * @see #email_account_t */ EXPORT_API int email_add_account(email_account_t* account); /** - * @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 + * @brief Deletes an email account. + * @details This function is invoked when the user wants to delete an existing email account. * - * @param[in] account_id Specifies the account ID. - * @exception EMAIL_ERROR_INVALID_PARAM -Invalid argument - * @return This function returns EMAIL_ERROR_NONE on success or error code (refer to EMAIL_ERROR_XXX) on failure. - * @see - * @remarks N/A + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/email + * + * @param[in] account_id The account ID + * + * @return #EMAIL_ERROR_NONE on success, + * otherwise an error code (see #EMAIL_ERROR_XXX) on failure + * + * @retval EMAIL_ERROR_INVALID_PARAM Invalid argument */ EXPORT_API int email_delete_account(int account_id); /** - * @fn email_update_account(int account_id, email_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 EMAIL_ERROR_INVALID_PARAM -Invalid argument - * @return This function returns EMAIL_ERROR_NONE on success or error code (refer to EMAIL_ERROR_XXX) on failure. - * @see email_account_t - * @remarks N/A + * @brief Changes the information of an email account. + * @details This function is invoked when the user wants to change some information of the existing email account. + * + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/email + * + * @param[in] account_id The original account ID + * @param[in] new_account The information of new account + * @param[in] with_validation The validation flag \n + * If this is @c 1, email-service will validate the account before updating. + * If this is @c 0, email-service will update the account without validation. + * + * @return #EMAIL_ERROR_NONE on success, + * otherwise an error code (see #EMAIL_ERROR_XXX) on failure + * + * @retval #EMAIL_ERROR_INVALID_PARAM Invalid argument + * + * @see #email_account_t */ EXPORT_API int email_update_account(int account_id, email_account_t* new_account); /** - * @fn email_update_account_with_validation(int account_id, email_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 EMAIL_ERROR_INVALID_PARAM -Invalid argument - * @return This function returns EMAIL_ERROR_NONE on success or error code (refer to EMAIL_ERROR_XXX) on failure. - * @see email_account_t - * @remarks N/A + * @brief Changes the information of an email account. + * @details This function is invoked when the user wants to change some information of the existing email account. + * + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/email + * + * @param[in] account_id The original account ID + * @param[in] new_account The information of new account + * @param[in] with_validation The validation tag \n + * If this is @c 1, email-service will validate the account before updating. + * If this is @c 0, email-service will update the account without validation. + * + * @return #EMAIL_ERROR_NONE on success, + * otherwise an error code (see #EMAIL_ERROR_XXX) on failure + * + * @retval #EMAIL_ERROR_INVALID_PARAM Invalid argument + * + * @see #email_account_t */ EXPORT_API int email_update_account_with_validation(int account_id, email_account_t* new_account); /** - * @fn email_get_account(int account_id, int pulloption, email_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 EMAIL_ACC_GET_OPT_XXX - * @param[out] account The returned account is saved here. - * @exception EMAIL_ERROR_INVALID_PARAM -Invalid argument - * @return This function returns EMAIL_ERROR_NONE on success or error code (refer to EMAIL_ERROR_XXX) on failure. - * @see email_account_t - * @remarks N/A + * @brief Gets an email account by ID. + * @details This function is invoked when the user wants to get the account information based on account ID and option (GET_FULL_DATA/WITHOUT_OPTION/ONLY_OPTION). + * Memory for account information will be allocated to the 3rd param (@a account). + * You must free the allocated memory using email_free_account(). + * + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/email + * + * @param[in] account_id The account ID + * @param[in] pulloption The option to specify to get full details or partial \n + * See definition of #EMAIL_ACC_GET_OPT_XXX. + * @param[out] account The returned account is saved here + * + * @return #EMAIL_ERROR_NONE on success, + * otherwise an error code (see #EMAIL_ERROR_XXX) on failure + * + * @retval #EMAIL_ERROR_INVALID_PARAM Invalid argument + * + * @see #email_account_t */ EXPORT_API int email_get_account(int account_id, int pulloption, email_account_t** account); /** - * @fn email_get_account_list(email_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 EMAIL_ERROR_INVALID_PARAM -Invalid argument - * @return This function returns EMAIL_ERROR_NONE on success or error code (refer to EMAIL_ERROR_XXX) on failure. - * @see email_account_t - * @remarks N/A + * @brief Gets an account list. + * @details This function is invoked when the user wants to get all account information based on the count of accounts provided by user. + * Memory for account information will be allocated to 3rd param (@a account). + * You must free the allocated memory using email_free_account(). + * + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/email + * + * @param[in] account_list The structure pointer of an account + * @param[out] count The count of accounts + * + * @return #EMAIL_ERROR_NONE on success, + * otherwise an error code (see #EMAIL_ERROR_XXX) on failure + * + * @retval #EMAIL_ERROR_INVALID_PARAM Invalid argument + * + * @see #email_account_t */ EXPORT_API int email_get_account_list(email_account_t** account_list, int* count); /** - * @fn email_free_account(email_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 EMAIL_ERROR_INVALID_PARAM -Invalid argument - * @return This function returns EMAIL_ERROR_NONE on success or error code (refer to EMAIL_ERROR_XXX) on failure. - * @see email_account_t - * @remarks N/A + * @brief Frees allocated memory. + * @details This function is invoked when the user wants to delete all account information. + * + * @since_tizen 2.3 + * @privlevel N/P + * + * @param[in] account_list The structure pointer of an account + * @param[out] count The count of accounts + * + * @return #EMAIL_ERROR_NONE on success, + * otherwise an error code (see #EMAIL_ERROR_XXX) on failure + * + * @retval #EMAIL_ERROR_INVALID_PARAM Invalid argument + * + * @see #email_account_t */ EXPORT_API int email_free_account(email_account_t** account_list, int count); - -/** - * @fn email_validate_account(int account_id, int *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 EMAIL_ERROR_INVALID_PARAM -Invalid argument - * @return This function returns EMAIL_ERROR_NONE on success or error code (refer to EMAIL_ERROR_XXX) on failure. - * @see none - * @remarks N/A - */ EXPORT_API int email_validate_account(int account_id, int *handle) DEPRECATED; /* Will be replaced with email_validate_account_ex */ /** - * @fn email_validate_account_ex(email_account_t* account, int *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 . + * @brief Validates an account. + * @details This function is invoked after adding one account to validate it. + * If the account is not validated then t user should retry once again to add the account. * - * @param[in] account Specifies the account structure - * @param[out] handle Specifies the sending handle. - * @remarks N/A - * @exception EMAIL_ERROR_INVALID_PARAM - Invalid argument - * @return This function returns EMAIL_ERROR_NONE on success or error code (refer to EMAIL_ERROR_XXX) on failure. - * @see email_account_t - * @remarks N/A + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/email + * + * @param[in] account The account structure + * @param[out] handle The sending handle + * + * @return #EMAIL_ERROR_NONE on success, + * otherwise an error code (see #EMAIL_ERROR_XXX) on failure + * + * @retval #EMAIL_ERROR_INVALID_PARAM Invalid argument + * + * @see #email_account_t */ EXPORT_API int email_validate_account_ex(email_account_t* account, int *handle); /** - * @fn email_add_account_with_validation(email_account_t* account, int *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 + * @brief Adds an account when the account is validated. + * @details This function is invoked when a user wants to validate an account. + * If the account is not validated then user should retry once again to add the account. + * 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. + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/email + * + * @param[in] account The structure pointer of an account + * @param[out] handle The sending handle + * + * @return @c true on success, + * otherwise @c false on failure */ EXPORT_API int email_add_account_with_validation(email_account_t* account, int *handle); /** - * @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. + * @brief Backs up information of all accounts into the secure storage. + * @details This function is invoked when a user wants 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. + * @param[in] file_name The file name in secure storage + * + * @return @c true on success, + * otherwise @c false on failure */ EXPORT_API int email_backup_accounts_into_secure_storage(const char *file_name); /** - * @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. + * @brief Restores accounts from a file stored in the secure storage. + * @details This function is invoked when a user wants 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. + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/email + * + * @param[in] file_name The file name in the secure storage + * + * @return @c true on success, + * otherwise @c false on failure */ EXPORT_API int email_restore_accounts_from_secure_storage(const char * file_name); /** - * @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. + * @brief Gets the password length of an account. + * @details This function is invoked when a user wants to know the length of an account. * - * @param[in] account_id Specifies the account id - * @param[in] password_type Specifies the password type - * @param[out] password_length 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(int account_id, int *password_length); - - -/** - * @fn email_query_server_info(const char* domain_name, email_server_info_t **result_server_info) - * @brief Query email server information. - * This function is getting invoked when user want to get email server information. + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/email * - * @param[in] domain_name Specifies the domain name of server - * @param[out] result_server_info Specifies the information of email server. - * @remarks N/A - * @return This function returns true on success or false on failure. + * @param[in] account_id The account ID + * @param[in] password_type The password type + * @param[out] password_length The password length + * + * @return @c true on success, + * otherwise @c false on failure */ -EXPORT_API int email_query_server_info(const char* domain_name, email_server_info_t **result_server_info); +EXPORT_API int email_get_password_length_of_account(int account_id, email_get_password_length_type password_type, int *password_length); /** - * @fn email_free_server_info(email_server_info_t **result_server_info) - * @brief Free email_server_info_t. - * This function is getting invoked when user want to free email_server_info_t. + * @brief Updates notifications on the notification bar. + * @details This function is invoked when user want to update notification bar. * - * @param[in] result_server_info Specifies the pointer of in secure storage - * @remarks N/A - * @return This function returns true on success or false on failure. + * @param[in] account_id The account ID + * @param[in] total_mail_count The total number of synced mail + * @param[in] unread_mail_count The unread number of synced mail + * @param[in] input_from_eas The flag that specifies whether the mail is from EAS + * + * @return #EMAIL_ERROR_NONE on success, + * otherwise error code (see #EMAIL_ERROR_XXX) on failure */ -EXPORT_API int email_free_server_info(email_server_info_t **result_server_info); +EXPORT_API int email_update_notification_bar(int account_id, int total_mail_count, int unread_mail_count, int input_from_eas); /** - * @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. + * @brief Clears all notification on the notification bar. + * @details This function is invoked when a user wants to clear 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. + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/email + * + * @return #EMAIL_ERROR_NONE on success, + * otherwise error code (see #EMAIL_ERROR_XXX) on failure */ -EXPORT_API int email_update_notification_bar(int account_id); +EXPORT_API int email_clear_all_notification_bar(); /** - * @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. + * @fn email_clear_notification_bar(int account_id) + * @brief Clear notification of account on notification bar. + * This function is getting invoked when user want to clear notification bar. + * + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/email * * @remarks N/A - * @return This function returns true on success or false on failure. + * + * @return #EMAIL_ERROR_NONE on success, + * otherwise an error code (see #EMAIL_ERROR_XXX) on failure */ -EXPORT_API int email_clear_all_notification_bar(); - +EXPORT_API int email_clear_notification_bar(int account_id); /** - * @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. + * @brief Saves the default account ID to the vconf storage. + * @details This function is invoked when a user wants to save a default account ID. * - * @remarks N/A - * @return This function returns true on success or false on failure. + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/email + * + * @return #EMAIL_ERROR_NONE on success, + * otherwise an error code (see #EMAIL_ERROR_XXX) on failure */ EXPORT_API int email_save_default_account_id(int input_account_id); /** - * @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. + * @brief Loads the default account ID to the vconf storage. + * @details This function is invoked when a user wants to load a default account ID. * - * @remarks N/A - * @return This function returns true on success or false on failure. + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/email + * + * @return @c true on success, + * otherwise @c false on failure */ EXPORT_API int email_load_default_account_id(int *output_account_id); @@ -399,8 +457,8 @@ EXPORT_API int email_load_default_account_id(int *output_account_id); #endif /* __cplusplus */ /** -* @} @} -*/ + * @} + */ #endif /* __EMAIL_API_ACCOUNT_H__ */ diff --git a/email-api/include/email-api-etc.h b/email-api/include/email-api-etc.h index 4d6d2e5..1d19100 100755 --- a/email-api/include/email-api-etc.h +++ b/email-api/include/email-api-etc.h @@ -20,26 +20,27 @@ */ /** -* @defgroup EMAIL_SERVICE Email Service -* @{ -*/ + * @file email-api-etc.h + * @brief This file contains the data structures and interfaces of etc APIs provided by email-service. + */ /** -* @ingroup EMAIL_SERVICE -* @defgroup EMAIL_API_ETC Email API -* @{ -*/ + * @internal + * @ingroup EMAIL_SERVICE_FRAMEWORK + * @defgroup EMAIL_SERVICE_ETC_MODULE Other API + * @brief Various API set for initializing and MIME operations and verifying email address. + * + * @section EMAIL_SERVICE_ETC_MODULE_HEADER Required Header + * \#include <email-api-etc.h> + * \#include <email-api-init.h> + * + * @section EMAIL_SERVICE_ETC_MODULE_OVERVIEW Overview + */ /** - * - * This file contains the data structures and interfaces needed for application, - * to interact with email-service. - * @file email-api-etc.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-service . + * @internal + * @addtogroup EMAIL_SERVICE_FRAMEWORK + * @{ */ #ifndef __EMAIL_API_ETC_H__ @@ -52,67 +53,98 @@ extern "C" { #include "email-types.h" /** - * @fn email_show_user_message - * @brief This function show user message. + * @brief Shows a user message. + * + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/email * - * @return This function returns EMAIL_ERROR_NONE on success or error code (refer to EMAIL_ERROR_XXX) on failure. - * @exception none - * @see email_action_t - * @remarks N/A + * @param[in] id (need to be updated) + * @param[in] action (need to be updated) + * @param[in] error_code (need to be updated) + * + * @return #EMAIL_ERROR_NONE on success, + * otherwise error code (see #EMAIL_ERROR_XXX) on failure + * + * @see #email_action_t */ EXPORT_API int email_show_user_message(int id, email_action_t action, int error_code); /** - * @fn email_parse_mime_file - * @brief This function parse mime file - * @param[in] eml_file_path - * @param[out] output_mail_data - * @param[out] output_attachment_data - * @param[out] output_attachment_count - * @return This function returns EMAIL_ERROR_NONE on success or error code (refer to EMAIL_ERROR_XXX) on failure. - * @exception none - * @see - * @remarks N/A + * @brief Parses a MIME file. + * + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/email + * + * @param[in] eml_file_path (need to be updated) + * @param[out] output_mail_data (need to be updated) + * @param[out] output_attachment_data (need to be updated) + * @param[out] output_attachment_count (need to be updated) + * + * @return #EMAIL_ERROR_NONE on success, + * otherwise error code (see #EMAIL_ERROR_XXX) on failure */ EXPORT_API int email_parse_mime_file(char *eml_file_path, email_mail_data_t **output_mail_data, email_attachment_data_t **output_attachment_data, int *output_attachment_count); /** - * @fn email_write_mime_file - * @brief This function create mime file from input data - * @param[in] input_mail_data - * @param[in] input_attachment_data - * @param[in] input_attachment_count - * @param[out] output_file_path - * @return This function returns EMAIL_ERROR_NONE on success or error code (refer to EMAIL_ERROR_XXX) on failure. - * @exception none - * @see - * @remarks N/A + * @brief Creates a MIME file from input data. + * + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/email + * + * @param[in] input_mail_data (need to be updated) + * @param[in] input_attachment_data (need to be updated) + * @param[in] input_attachment_count (need to be updated) + * @param[out] output_file_path (need to be updated) + * + * @return #EMAIL_ERROR_NONE on success, + * otherwise error code (see #EMAIL_ERROR_XXX) on failure */ EXPORT_API int email_write_mime_file(email_mail_data_t *input_mail_data, email_attachment_data_t *input_attachment_data, int input_attachment_count, char **output_file_path); /** - * @fn email_delete_parsed_data - * @brief This function delete parsed files of mime - * @param[in] input_mail_data - * @return This function returns EMAIL_ERROR_NONE on success or error code (refer to EMAIL_ERROR_XXX) on failure. - * @exception none - * @see - * @remarks N/A + * @brief Deletes the parsed files of MIME. + * + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/email + * + * @param[in] input_mail_data (need to be updated) + * + * @return #EMAIL_ERROR_NONE on success, + * otherwise an error code (see #EMAIL_ERROR_XXX) on failure */ EXPORT_API int email_delete_parsed_data(email_mail_data_t *input_mail_data); /** - * @fn email_get_mime_entity - * @brief This function get mime entity - * @param[in] mime_path - * @param[out] mime_entity - * @return This function returns EMAIL_ERROR_NONE on success or error code (refer to EMAIL_ERROR_XXX) on failure. - * @exception none - * @see - * @remarks N/A + * @brief Gets a MIME entity. + * + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/email + * + * @param[in] mime_path (need to be updated) + * @param[out] mime_entity (need to be updated) + * + * @return #EMAIL_ERROR_NONE on success, + * otherwise an error code (see #EMAIL_ERROR_XXX) on failure */ EXPORT_API int email_get_mime_entity(char *mime_path, char **mime_entity); + +/** + * @brief Validates email address. + * + * @since_tizen 2.3 + * + * @param[in] input_email_address The email address string + * + * @return #EMAIL_ERROR_NONE on success, + * otherwise an error code (see #EMAIL_ERROR_XXX) on failure + */ +EXPORT_API int email_verify_email_address(char *input_email_address); #ifdef __cplusplus } #endif /* __cplusplus */ @@ -120,5 +152,5 @@ EXPORT_API int email_get_mime_entity(char *mime_path, char **mime_entity); #endif /* __EMAIL_API_ETC_H__ */ /** -* @} @} -*/ + * @} + */ diff --git a/email-api/include/email-api-init.h b/email-api/include/email-api-init.h index 6e2ffe1..6e15f3f 100755 --- a/email-api/include/email-api-init.h +++ b/email-api/include/email-api-init.h @@ -26,140 +26,133 @@ #include "email-types.h" /** -* @defgroup EMAIL_SERVICE Email Service -* @{ -*/ - - -/** -* @ingroup EMAIL_SERVICE -* @defgroup EMAIL_API_INIT Email Initialization API -* @{ -*/ - -/** + * @internal + * @file email-api-init.h + * @brief This file contains the data structures and interfaces of Email FW Initialization provided by email-service. + * + * @{ + * @code + * + * #include "email-api-init.h" + * + * bool + * other_app_invoke_uniform_api_sample(int* error_code) + * { + * int err = EMAIL_ERROR_NONE; + * + * // Opens connections to email-service and DB + * // The connections will be maintain throughout application's execution + * if(EMAIL_ERROR_NONE == email_service_begin()) + * { + * If(EMAIL_ERROR_NONE != email_open_db()) + * { + * return false; + * } + * + * // Executes email_init_storage() if and only if there is no db file. + * // This function will create db file and tables for email service + * If(EMAIL_ERROR_NONE !=email_init_storage()) + * { + * return false; + * } + * } + * + * ...... + * + * // Work with calling MAPI functions * - * This file contains the data structures and interfaces needed for application, - * to interact with email-service. - * @file email-api-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-service . - *@{ - *@code - * - * #include "email-api-init.h" - * - * bool - * other_app_invoke_uniform_api_sample(int* error_code) - * { - * int err = EMAIL_ERROR_NONE; - * - * // Open connections to email-service and DB - * // The connections will be maintain throughout application's execution - * if(EMAIL_ERROR_NONE == email_service_begin()) - * { - * If(EMAIL_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(EMAIL_ERROR_NONE !=email_init_storage()) - * { - * return false; - * } - * } - * - * ...... - * - * // Work with calling MAPI functions - * - * ...... - * - * // Close the connections to email-service 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(); - * } + * ...... + * + * // Closes the connections to email-service and DB after all email jobs are finished. (ex. close an email application) + * // DO NOT have to call these funtions until the connections are not needed any more. + * err =email_close_db(); + * err =email_service_end(); + * } * * @endcode * @} */ - +/** + * @internal + * @addtogroup EMAIL_SERVICE_ETC_MODULE + * @{ + */ #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ /** - * @fn email_init_storage(void) - * @brief Create all tables for email. + * @brief Creates all tables for an email. * - * @return This function returns EMAIL_ERROR_NONE on success or error code (refer to EMAIL_ERROR_XXX) on failure - * @exception none - * @see none - * @remarks N/A + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/email + * + * @return #EMAIL_ERROR_NONE on success, + * otherwise an error code (see #EMAIL_ERROR_XXX) on failure */ EXPORT_API int email_init_storage(void); /** - * @fn email_open_db(void) - * @brief This function Open the email DB and register busy handler + * @brief Opens the email DB and registers a busy handler. + * + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/email * - * @return This function returns EMAIL_ERROR_NONE on success or error code (refer to EMAIL_ERROR_XXX) on failure. - * @exception none - * @see none - * @remarks N/A + * @return #EMAIL_ERROR_NONE on success, + * otherwise an error code (see #EMAIL_ERROR_XXX) on failure */ EXPORT_API int email_open_db(void); /** - * @fn email_close_db(void) - * @brief This function closes the connection of the email DB + * @brief Closes the connection to the email DB. + * + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/email * - * @return This function returns EMAIL_ERROR_NONE on success or error code (refer to EMAIL_ERROR_XXX) on failure. - * @exception none - * @see none - * @remarks N/A + * @return #EMAIL_ERROR_NONE on success, + * otherwise an error code (see #EMAIL_ERROR_XXX) on failure */ EXPORT_API int email_close_db(void); /** - * @fn email_service_begin(void) - * @brief Does the IPC Proxy Initialization by the Application which used the Email FW API's + * @brief Initializes IPC Proxy by an application which used the Email FW API's. * - * @return This function returns EMAIL_ERROR_NONE on success or error code (refer to EMAIL_ERROR_XXX) on failure. - * @exception none - * @see none - * @remarks N/A + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/email + * + * @return #EMAIL_ERROR_NONE on success, + * otherwise an error code (see #EMAIL_ERROR_XXX) on failure */ EXPORT_API int email_service_begin(void); /** - * @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 EMAIL_ERROR_NONE on success or error code (refer to EMAIL_ERROR_XXX) on failure. - * @exception none - * @see none - * @remarks N/A + * @brief Finalizes IPC Proxy by an application which used the Email FW API's. + + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/email + * + * @return #EMAIL_ERROR_NONE on success, + * otherwise an error code (see #EMAIL_ERROR_XXX) on failure */ EXPORT_API int email_service_end(void); /** - * @fn email_ping_service(void) - * @brief This function check email-service process is running or not + * @brief Checks whether the email-service process is running. + * + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/email * - * @return This function returns EMAIL_ERROR_NONE on success or error code (refer to EMAIL_ERROR_XXX) on failure. - * @exception none - * @see none - * @remarks N/A + * @return #EMAIL_ERROR_NONE on success, + * otherwise an error code (see #EMAIL_ERROR_XXX) on failure */ EXPORT_API int email_ping_service(void); @@ -168,8 +161,8 @@ EXPORT_API int email_ping_service(void); #endif /* __cplusplus */ /** -* @} @} -*/ + * @} + */ #endif /* __EMAIL_API_INTI_H__ */ diff --git a/email-api/include/email-api-mail.h b/email-api/include/email-api-mail.h index 212cd81..b2cdf1a 100755 --- a/email-api/include/email-api-mail.h +++ b/email-api/include/email-api-mail.h @@ -30,913 +30,1000 @@ #include <unistd.h> /** -* @defgroup EMAIL_SERVICE Email Service -* @{ -*/ - - -/** -* @ingroup EMAIL_SERVICE -* @defgroup EMAIL_API_MAIL Email Mail API -* @{ -*/ + * @file email-api-mail.h + */ /** + * @internal + * @ingroup EMAIL_SERVICE_FRAMEWORK + * @defgroup EMAIL_SERVICE_MAIL_MODULE Mail API + * @brief Mail API is a set of operations to manage mail like add, update, delete or get mail related details. + * + * @section EMAIL_SERVICE_MAIL_MODULE_HEADER Required Header + * \#include <email-api-mail.h> * - * This file contains the data structures and interfaces needed for application, - * to interact with email-service. - * @file email-api-mail.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-service . + * @section EMAIL_SERVICE_MAIL_MODULE_OVERVIEW Overview + * Mail API is a set of operations to manage mail like add, update, delete or get mail related details. */ - +/** + * @internal + * @addtogroup EMAIL_SERVICE_MAIL_MODULE + * @{ + */ #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ /** - * @fn email_add_mail(email_mail_data_t *input_mail_data, email_attachment_data_t *input_attachment_data_list, int input_attachment_count, email_meeting_request_t* input_meeting_request, int input_from_eas) - * @brief Save a mail. This function is invoked when user wants to add a mail. - * If the option from_eas is 1 then this will save the message on server as well as on locally. - * If the incoming_server_type is EMAIL_SERVER_TYPE_POP3 then from_eas value will be 0 - * If the incoming_server_type is EMAIL_SERVER_TYPE_IMAP4 then from_eas value will be 1/0 - * - * @return This function returns EMAIL_ERROR_NONE on success or error code (refer to EMAIL_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_from_eas Specifies if the mail will be saved on server. - - * @exception none - * @see email_mail_data_t and email_mailbox_t - * @remarks N/A - * @code - * #include "email-api-mail.h" - * int _test_add_mail () - * { - * int i = 0; - * int account_id = 0; - * int from_eas = 0; - * int attachment_count = 0; - * int err = EMAIL_ERROR_NONE; - * char arg[50] = { 0 , }; - * char *body_file_path = MAILHOME"/tmp/mail.txt"; - * email_mailbox_t *mailbox_data = NULL; - * email_mail_data_t *test_mail_data = NULL; - * email_attachment_data_t *attachment_data = NULL; - * email_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(email_mail_data_t)); - * memset(test_mail_data, 0x00, sizeof(email_mail_data_t)); - * - * printf("\n From EAS? [0/1]> "); - * scanf("%d", &from_eas); - * - * 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_id = mailbox_data->mailbox_id; - * 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(email_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; - * } + * @brief Saves a mail. + * @details This function is invoked when a user wants to add a mail.\n + * If the option from_eas is 1 then this will save the message on server as well as on locally.\n + * If the incoming_server_type is EMAIL_SERVER_TYPE_POP3 then from_eas value will be 0.\n + * If the incoming_server_type is EMAIL_SERVER_TYPE_IMAP4 then from_eas value will be 1/0. * - * 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(email_meeting_request_t)); - * memset(meeting_req, 0x00, sizeof(email_meeting_request_t)); - * - * meeting_req->meeting_response = 1; - * current_time = time(NULL); - * gmtime_r(¤t_time, &(meeting_req->start_time)); - * gmtime_r(¤t_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(¤t_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(¤t_time, &(meeting_req->time_zone.daylight_time_start_date)); - * meeting_req->time_zone.daylight_bias = 7; + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/email * - * } + * @param[in] input_mail_data The mail to be saved + * @param[in] input_attachment_data_list The mailbox structure for saving email + * @param[in] input_attachment_count The mail attachment count + * @param[in] input_meeting_request Specifies if the mail comes from composer + * @param[in] input_from_eas Specifies if the mail will be saved on server * - * if((err = email_add_mail(test_mail_data, attachment_data, attachment_count, meeting_req, from_eas)) != EMAIL_ERROR_NONE) - * printf("email_add_mail failed. [%d]\n", err); - * else - * printf("email_add_mail success.\n"); + * @return #EMAIL_ERROR_NONE on success, + * otherwise an error code (see #EMAIL_ERROR_XXX) on failure * - * if(attachment_data) - * email_free_attachment_data(&attachment_data, attachment_count); + * @see #email_mail_data_t and #email_mailbox_t + * + * @code + * #include "email-api-mail.h" + * int _test_add_mail () + * { + * int i = 0; + * int account_id = 0; + * int from_eas = 0; + * int attachment_count = 0; + * int err = EMAIL_ERROR_NONE; + * char arg[50] = { 0 , }; + * char *body_file_path = MAILHOME"/tmp/mail.txt"; + * email_mailbox_t *mailbox_data = NULL; + * email_mail_data_t *test_mail_data = NULL; + * email_attachment_data_t *attachment_data = NULL; + * email_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(email_mail_data_t)); + * memset(test_mail_data, 0x00, sizeof(email_mail_data_t)); + * + * printf("\n From EAS? [0/1]> "); + * scanf("%d", &from_eas); + * + * 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_id = mailbox_data->mailbox_id; + * 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(email_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(email_meeting_request_t)); + * memset(meeting_req, 0x00, sizeof(email_meeting_request_t)); + * + * meeting_req->meeting_response = 1; + * current_time = time(NULL); + * gmtime_r(¤t_time, &(meeting_req->start_time)); + * gmtime_r(¤t_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(¤t_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(¤t_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, from_eas)) != EMAIL_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); + * if(meeting_req) + * email_free_meeting_request(&meeting_req, 1); * - * email_free_mail_data(&test_mail_data, 1); - * email_free_mailbox(&mailbox_data, 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); + * printf("saved mail id = [%d]\n", test_mail_data->mail_id); * - * return 0; + * return 0; * } * @endcode */ EXPORT_API int email_add_mail(email_mail_data_t *input_mail_data, email_attachment_data_t *input_attachment_data_list, int input_attachment_count, email_meeting_request_t* input_meeting_request, int input_from_eas); /** - * @fn email_add_read_receipt(int input_read_mail_id, int *output_handle) - * @brief Add 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 EMAIL_ERROR_NONE on success or error code (refer to EMAIL_ERROR_XXX) on failure. - * @param[in] input_read_mail_id Specifies the id of mail which has been read. - * @param[out] output_receipt_mail_id Specifies the receipt mail id . - * @exception none - * @see - * @remarks N/A + * @brief Adds a read receipt mail. + * @details This function is invoked when a user receives a mail with read report enable and wants to send a read report for the same. + * + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/email + * + * @param[in] input_read_mail_id The ID of mail which has been read + * @param[out] output_receipt_mail_id The receipt mail ID + * + * @return #EMAIL_ERROR_NONE on success, + * otherwise error code (see #EMAIL_ERROR_XXX) on failure */ EXPORT_API int email_add_read_receipt(int input_read_mail_id, int *output_receipt_mail_id); /** - * @fn email_update_mail(email_mail_data_t *input_mail_data, email_attachment_data_t *input_attachment_data_list, int input_attachment_count, email_meeting_request_t* input_meeting_request, int input_from_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 EMAIL_ERROR_NONE on success or error code (refer to EMAIL_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_from_eas Specifies whether sync server. - - * @exception none - * @see email_mail_data_t + * @brief Updates an existing email information. + * @details This function is invoked when a user wants to change some existing email information with new email information. + * + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/email + * + * @param[in] input_mail_data The mail ID + * @param[in] input_attachment_data_list The pointer of attachment data + * @param[in] input_attachment_count The number of attachment data + * @param[in] input_meeting_request The meeting request data + * @param[in] input_from_eas Specifies whether sync server + * + * @return #EMAIL_ERROR_NONE on success, + * otherwise an error code (see #EMAIL_ERROR_XXX) on failure + * + * @see #email_mail_data_t + * * @code * #include "email-api-account.h" * int email_test_update_mail() * { - * int mail_id = 0; - * int err = EMAIL_ERROR_NONE; - * int test_attachment_data_count = 0; - * char arg[50]; - * email_mail_data_t *test_mail_data = NULL; - * email_attachment_data_t *test_attachment_data_list = NULL; - * email_meeting_request_t *meeting_req = NULL; + * int mail_id = 0; + * int err = EMAIL_ERROR_NONE; + * int test_attachment_data_count = 0; + * char arg[50]; + * email_mail_data_t *test_mail_data = NULL; + * email_attachment_data_t *test_attachment_data_list = NULL; + * email_meeting_request_t *meeting_req = NULL; * - * printf("\n > Enter mail id : "); - * scanf("%d", &mail_id); + * printf("\n > Enter mail id : "); + * scanf("%d", &mail_id); * - * email_get_mail_data(mail_id, &test_mail_data); + * email_get_mail_data(mail_id, &test_mail_data); * - * printf("\n > Enter Subject: "); - * scanf("%s", arg); + * printf("\n > Enter Subject: "); + * scanf("%s", arg); * - * test_mail_data->subject= strdup(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)) != EMAIL_ERROR_NONE ) { - * printf("email_get_meeting_request() failed [%d]\n", err); - * return -1; - * } - * } + * if (test_mail_data->attachment_count > 0) { + * if ( (err = email_get_attachment_data_list(mail_id, &test_attachment_data_list, &test_attachment_data_count)) != EMAIL_ERROR_NONE ) { + * printf("email_get_meeting_request() failed [%d]\n", err); + * return -1; + * } + * } * - * if ( test_mail_data->meeting_request_status == EMAIL_MAIL_TYPE_MEETING_REQUEST - * || test_mail_data->meeting_request_status == EMAIL_MAIL_TYPE_MEETING_RESPONSE - * || test_mail_data->meeting_request_status == EMAIL_MAIL_TYPE_MEETING_ORIGINATINGREQUEST) { + * if ( test_mail_data->meeting_request_status == EMAIL_MAIL_TYPE_MEETING_REQUEST + * || test_mail_data->meeting_request_status == EMAIL_MAIL_TYPE_MEETING_RESPONSE + * || test_mail_data->meeting_request_status == EMAIL_MAIL_TYPE_MEETING_ORIGINATINGREQUEST) { * - * if ( (err = email_get_meeting_request(mail_id, &meeting_req)) != EMAIL_ERROR_NONE ) { - * printf("email_get_meeting_request() failed [%d]\n", err); - * return -1; - * } + * if ( (err = email_get_meeting_request(mail_id, &meeting_req)) != EMAIL_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)); - * } + * 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)) != EMAIL_ERROR_NONE) - * printf("email_update_mail failed.[%d]\n", err); - * else - * printf("email_update_mail success\n"); + * if ( (err = email_update_mail(test_mail_data, test_attachment_data_list, test_attachment_data_count, meeting_req, 0)) != EMAIL_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_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(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); + * if(meeting_req) + * email_free_meeting_request(&meeting_req, 1); * - * return 0; + * return 0; * } * @endcode - * @remarks N/A */ EXPORT_API int email_update_mail(email_mail_data_t *input_mail_data, email_attachment_data_t *input_attachment_data_list, int input_attachment_count, email_meeting_request_t* input_meeting_request, int input_from_eas); /** - * @fn email_update_mail_attribute(int input_account_id, int *input_mail_id_array, int input_mail_id_count, email_mail_attribute_type input_attribute_type, email_mail_attribute_value_t input_value) - * @brief This function update individual attribute of mail data. - * - * @return This function returns EMAIL_ERROR_NONE on success or error code (refer to EMAIL_ERROR_XXX) on failure. - * @param[in] input_account_id Specifies the id of account. - * @param[in] input_mail_id_array Specify the array list if mail id - * @param[in] input_mail_id_count Specify the count of mail id array - * @param[in] input_attribute_type Specify the attribute type which to update - * @param[in] input_value Specify the value of attribute - * @exception none - * @see - * @remarks N/A + * @brief Updates an individual attribute of the mail data. + * + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/email + * + * @param[in] input_account_id The ID of account + * @param[in] input_mail_id_array The array list of mail IDs + * @param[in] input_mail_id_count The count of mail ID array + * @param[in] input_attribute_type The attribute type to update + * @param[in] input_value The value of attribute + * + * @return #EMAIL_ERROR_NONE on success, + * otherwise an error code (see #EMAIL_ERROR_XXX) on failure */ EXPORT_API int email_update_mail_attribute(int input_account_id, int *input_mail_id_array, int input_mail_id_count, email_mail_attribute_type input_attribute_type, email_mail_attribute_value_t input_value); /** - * @fn email_count_mail(email_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. + * @brief Gets the mail count. + * @details This function is invoked when a user wants to know how many total mails and out of that + * how many unseen mails are there in a given mailbox. + * + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/email + * + * @param[in] mailbox The pointer of mailbox structure + * @param[out] total The total email count + * @param[out] unseen The unread email count + * + * @return #EMAIL_ERROR_NONE on success, + * otherwise an error code (see #EMAIL_ERROR_XXX) on failure + * + * @see #email_mailbox_t * - * @return This function returns EMAIL_ERROR_NONE on success or error code (refer to EMAIL_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 email_mailbox_t - * @code - * #include "email-api-account.h" - * bool - * _api_sample_count_mail() - * { - * int total = 0; - * int unseen = 0; - * email_list_filter_t *filter_list = NULL; - * int err = EMAIL_ERROR_NONE; - * int i = 0; - * filter_list = malloc(sizeof(email_list_filter_t) * 3); - * memset(filter_list, 0 , sizeof(email_list_filter_t) * 3); - * - * filter_list[0].list_filter_item_type = EMAIL_LIST_FILTER_ITEM_RULE; - * filter_list[0].list_filter_item.rule.target_attribute = EMAIL_MAIL_ATTRIBUTE_SUBJECT; - * filter_list[0].list_filter_item.rule.rule_type = EMAIL_LIST_FILTER_RULE_INCLUDE; - * filter_list[0].list_filter_item.rule.key_value.string_type_value = strdup("RE"); - * filter_list[0].list_filter_item.rule.case_sensitivity = false; - * - * filter_list[1].list_filter_item_type = EMAIL_LIST_FILTER_ITEM_OPERATOR; - * filter_list[1].list_filter_item.operator_type = EMAIL_LIST_FILTER_OPERATOR_OR; - * - * filter_list[2].list_filter_item_type = EMAIL_LIST_FILTER_ITEM_RULE; - * filter_list[2].list_filter_item.rule.target_attribute = EMAIL_MAIL_ATTRIBUTE_TO; - * filter_list[2].list_filter_item.rule.rule_type = EMAIL_LIST_FILTER_RULE_INCLUDE; - * filter_list[2].list_filter_item.rule.key_value.string_type_value = strdup("RE"); - * filter_list[2].list_filter_item.rule.case_sensitivity = false; - * - * if(EMAIL_ERROR_NONE == email_count_mail(filter_list, 3, &total, &unseen)) - * printf("\n Total: %d, Unseen: %d \n", total, unseen); - * } + * #include "email-api-account.h" + * bool + * _api_sample_count_mail() + * { + * int total = 0; + * int unseen = 0; + * email_list_filter_t *filter_list = NULL; + * int err = EMAIL_ERROR_NONE; + * int i = 0; + * filter_list = malloc(sizeof(email_list_filter_t) * 3); + * memset(filter_list, 0 , sizeof(email_list_filter_t) * 3); + * + * filter_list[0].list_filter_item_type = EMAIL_LIST_FILTER_ITEM_RULE; + * filter_list[0].list_filter_item.rule.target_attribute = EMAIL_MAIL_ATTRIBUTE_SUBJECT; + * filter_list[0].list_filter_item.rule.rule_type = EMAIL_LIST_FILTER_RULE_INCLUDE; + * filter_list[0].list_filter_item.rule.key_value.string_type_value = strdup("RE"); + * filter_list[0].list_filter_item.rule.case_sensitivity = false; + * + * filter_list[1].list_filter_item_type = EMAIL_LIST_FILTER_ITEM_OPERATOR; + * filter_list[1].list_filter_item.operator_type = EMAIL_LIST_FILTER_OPERATOR_OR; + * + * filter_list[2].list_filter_item_type = EMAIL_LIST_FILTER_ITEM_RULE; + * filter_list[2].list_filter_item.rule.target_attribute = EMAIL_MAIL_ATTRIBUTE_TO; + * filter_list[2].list_filter_item.rule.rule_type = EMAIL_LIST_FILTER_RULE_INCLUDE; + * filter_list[2].list_filter_item.rule.key_value.string_type_value = strdup("RE"); + * filter_list[2].list_filter_item.rule.case_sensitivity = false; + * + * if(EMAIL_ERROR_NONE == email_count_mail(filter_list, 3, &total, &unseen)) + * printf("\n Total: %d, Unseen: %d \n", total, unseen); + * } * @endcode - * @remarks N/A */ EXPORT_API int email_count_mail(email_list_filter_t *input_filter_list, int input_filter_count, int *output_total_mail_count, int *output_unseen_mail_count); /** - * @fn email_get_max_mail_count(int *Count) - * @brief Gets the max count of mails which can be supported by email-service + * @brief Gets the max count of mails which can be supported by email-service. + * + * @param[out] count The max count of mails which can be supported by email-service + * + * @return #EMAIL_ERROR_NONE on success, + * otherwise an error code (see #EMAIL_ERROR_XXX) on failure * - * @return This function returns EMAIL_ERROR_NONE on success or error code (refer to EMAIL_ERROR_XXX) on failure. - * @param[out] Count max count of mails which can be supported by email-service - * @exception none * @code - * #include "email-api-account.h" - * bool - * _api_sample_get_max_mail_count() - * { - * int max_count = -1; - * - * if(EMAIL_ERROR_NONE == email_get_max_mail_count(&max_count)) - * printf("\n\t>>>>> email_get_max_mail_count() return [%d]\n\n", max_count); - * } + * #include "email-api-account.h" + * bool + * _api_sample_get_max_mail_count() + * { + * int max_count = -1; + * + * if(EMAIL_ERROR_NONE == email_get_max_mail_count(&max_count)) + * printf("\n\t>>>>> email_get_max_mail_count() returns [%d]\n\n", max_count); + * } * @endcode - * @remarks N/A */ EXPORT_API int email_get_max_mail_count(int *count); /** - * @fn email_delete_mail(email_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 incoming_server_type is EMAIL_SERVER_TYPE_POP3 then from_server value will be 0 - * If the incoming_server_type is EMAIL_SERVER_TYPE_IMAP4 then from_server value will be 1/0 - * - * @param[in] mail_ids[] Specifies the array 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 EMAIL_ERROR_NONE on success or error code (refer to EMAIL_ERROR_XXX) on failure. - * @exception none + * @brief Deletes a mail or multiple mails. + * @details Based on from_server value, this function will delete a mail or multiple mails from the server or locally. + * + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/email + * + * @remarks If the incoming_server_type is #EMAIL_SERVER_TYPE_POP3 then from_server value will be @c 0. \n + * If the incoming_server_type is #EMAIL_SERVER_TYPE_IMAP4 then from_server value will be 1/0. + * + * @param[in] mailbox Reserved + * @param[in] mail_ids[] The array of mail IDs + * @param[in] num The number of mail IDs + * @param[in] from_server The flag that specifies whether mails are deleted from server + * + * @return #EMAIL_ERROR_NONE on success, + * otherwise error code (see #EMAIL_ERROR_XXX) on failure + * * @code - * #include "email-api-account.h" - * bool - * _api_sample_delete_mail() - * { - * int count, i, mail_id=0, mailbox_id =0; - * - * printf("\n > Enter Mail_id: "); - * scanf("%d",&mail_id); - * printf("\n > Enter Mailbox ID: "); - * scanf("%d",&mailbox_id); - * if(EMAIL_ERROR_NONE == email_delete_mail(mailbox_id, &mail_id, 1, 1)) - * printf("\n email_delete_mail success"); - * else - * printf("\n email_delete_mail failed"); - * } + * #include "email-api-account.h" + * bool + * _api_sample_delete_mail() + * { + * int count, i, mail_id=0, mailbox_id =0; + * + * printf("\n > Enter Mail_id: "); + * scanf("%d",&mail_id); + * printf("\n > Enter Mailbox ID: "); + * scanf("%d",&mailbox_id); + * if(EMAIL_ERROR_NONE == email_delete_mail(mailbox_id, &mail_id, 1, 1)) + * printf("\n email_delete_mail success"); + * else + * printf("\n email_delete_mail failed"); + * } * @endcode - * @remarks N/A */ EXPORT_API int email_delete_mail(int input_mailbox_id, int *input_mail_ids, int input_num, int input_from_server); /** - * @fn email_delete_all_mails_in_mailbox(int input_mailbox_id, int input_from_server) - * @brief Delete all mail from a mailbox. - * If the incoming_server_type is EMAIL_SERVER_TYPE_POP3 then from_server value will be 0 - * If the incoming_server_type is EMAIL_SERVER_TYPE_IMAP4 then from_server value will be 1/0 + * @brief Deletes all mails from a mailbox. + * @details If the incoming_server_type is #EMAIL_SERVER_TYPE_POP3 then @a from_server value will be @c 0. \n + * If the incoming_server_type is #EMAIL_SERVER_TYPE_IMAP4 then @a from_server value will be 1/0. * - * @return This function returns EMAIL_ERROR_NONE on success or error code (refer to EMAIL_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 email_mailbox_t - + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/email + * + * @param[in] mailbox The structure of mailbox + * @param[in] from_server The flag that specifies whether mails are also deleted from server + * + * @return #EMAIL_ERROR_NONE on success, + * otherwise an error code (see #EMAIL_ERROR_XXX) on failure + * + * @see #email_mailbox_t + * @code - * #include "email-api-account.h" - * bool - * _api_sample_delete_all_mails_in_mailbox() - * { - * int count, mailbox_id =0; - * - * printf("\n > Enter mailbox_id: "); - * scanf("%d",&mailbox_id); - * - * if (EMAIL_ERROR_NONE != email_delete_all_mails_in_mailbox(mailbox_id, 0)) - * printf("email_delete_all_mails_in_mailbox failed"); - * else - * printf("email_delete_all_mails_in_mailbox Success"); - * } + * #include "email-api-account.h" + * bool + * _api_sample_delete_all_mails_in_mailbox() + * { + * int count, mailbox_id =0; + * + * printf("\n > Enter mailbox_id: "); + * scanf("%d",&mailbox_id); + * + * if (EMAIL_ERROR_NONE != email_delete_all_mails_in_mailbox(mailbox_id, 0)) + * printf("email_delete_all_mails_in_mailbox failed"); + * else + * printf("email_delete_all_mails_in_mailbox Success"); + * } * @endcode - * @remarks N/A */ EXPORT_API int email_delete_all_mails_in_mailbox(int input_mailbox_id, int input_from_server); /** - * @fn email_clear_mail_data() - * @brief delete email data from storage. This API will be used by the Settings Application + * @brief Deletes email data from the storage. + * @details This API will be used by Settings Application. + * + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/email + * + * @return #EMAIL_ERROR_NONE on success, + * otherwise an error code (see #EMAIL_ERROR_XXX) on failure * - * @return This function returns EMAIL_ERROR_NONE on success or error code (refer to EMAIL_ERROR_XXX) on failure. - * @exception none - * @see none - * @code - * #include "email-api-account.h" - * bool - * _api_sample_clear_mail_data() - * { - * if(EMAIL_ERROR_NONE == email_clear_mail_data()) - * //success - * else - * //failure - * - * } + * #include "email-api-account.h" + * bool + * _api_sample_clear_mail_data() + * { + * if(EMAIL_ERROR_NONE == email_clear_mail_data()) + * //success + * else + * //failure + * } * @endcode - * @remarks N/A */ EXPORT_API int email_clear_mail_data(); /** - * @fn email_add_attachment(int mail_id, email_attachment_data_t* attachment) - * @brief Append a attachment to email.This function is invoked when user wants to add attachment to existing mail. + * @brief Appends an attachment to an email. + * @details This function is invoked when a user wants to add attachment to an existing mail. + * + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/email + * + * @param[in] mail_id The mail ID + * @param[in] attachment The structure of attachment + * + * @return #EMAIL_ERROR_NONE on success, + * otherwise an error code (see #EMAIL_ERROR_XXX) on failure + * + * @see #email_attachment_data_t * - * @return This function returns EMAIL_ERROR_NONE on success or error code (refer to EMAIL_ERROR_XXX) on failure. - * @param[in] mail_id Specifies the mail ID. - * @param[in] attachment Specifies the structure of attachment. - * @exception none - * @see email_attachment_data_t - * @code - * #include "email-api-account.h" - * bool - * _api_sample_mail_add_attachment() - * { - * int mail_id = 0; - * email_attachment_data_t attachment; - * - * printf("\n > Enter Mail Id: "); - * scanf("%d", &mail_id); - * memset(&attachment, 0x00, sizeof(email_attachment_data_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(EMAIL_ERROR_NONE != email_add_attachment(mail_id, &attachment)) - * printf("email_add_attachment failed\n"); - * else - * printf(email_add_attachment success\n"); - * } + * #include "email-api-account.h" + * bool + * _api_sample_mail_add_attachment() + * { + * int mail_id = 0; + * email_attachment_data_t attachment; + * + * printf("\n > Enter Mail Id: "); + * scanf("%d", &mail_id); + * memset(&attachment, 0x00, sizeof(email_attachment_data_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(EMAIL_ERROR_NONE != email_add_attachment(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(int mail_id, email_attachment_data_t* attachment); /** - * @fn email_delete_attachment(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 EMAIL_ERROR_NONE on success or error code (refer to EMAIL_ERROR_XXX) on failure. - * @param[in] mail_id Specifies the mail ID. - * @param[in] attachment_id Specifies the attachment id. - * @exception none - * @see email_mailbox_t + * @brief Deletes an attachment from email. + * @details This function is invoked when a user wants to delete a attachment from an existing mail based on mail ID and attachment ID. + * + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/email + * + * @param[in] mail_id The mail ID + * @param[in] attachment_id The attachment ID + * + * @return #EMAIL_ERROR_NONE on success, + * otherwise an error code (see #EMAIL_ERROR_XXX) on failure + * + * @see #email_mailbox_t + * * @code - * #include "email-api-account.h" - * bool - * _api_sample_mail_delete_attachment() - * { - * - * if(EMAIL_ERROR_NONE != email_delete_attachment(1)) - * //failure - * else - * //success - * } + * #include "email-api-account.h" + * bool + * _api_sample_mail_delete_attachment() + * { + * + * if(EMAIL_ERROR_NONE != email_delete_attachment(1)) + * //failure + * else + * //success + * } * @endcode - * @remarks N/A */ EXPORT_API int email_delete_attachment(int attachment_id); /** - * @fn email_get_attachment_data(int mail_id, const char* attachment_id, email_attachment_data_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. + * @brief Gets a mail attachment. + * @details This function is invoked when a user wants to get the attachment information based on an attachment ID for the specified mail ID. + * + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/email + * + * @param[in] mail_id The mail ID + * @param[in] attachment_id The buffer that an attachment ID is saved + * @param[out] attachment The returned attachment + * + * @return #EMAIL_ERROR_NONE on success, + * otherwise an error code (see #EMAIL_ERROR_XXX) on failure + * + * @see #email_mailbox_t and #email_mail_attachment_info_t * - * @return This function returns EMAIL_ERROR_NONE on success or error code (refer to EMAIL_ERROR_XXX) on failure. - * @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 email_mailbox_t and email_mail_attachment_info_t - * @code - * #include "email-api-account.h" - * bool - * _api_sample_mail_get_attachment_info() - * { - * email_mail_attachment_info_t *mail_attach_info = NULL; - * int mail_id = 0; - * char arg[10]; - * int err = EMAIL_ERROR_NONE; - * - * - * printf("\n > Enter Mail Id: "); - * scanf("%d", &mail_id); - * printf("> attachment Id\n"); - * scanf("%s",arg); - * if (EMAIL_ERROR_NONE != email_get_attachment_data(mail_id, &mail_attach_info)) - * printf("email_get_attachment_data failed\n"); - * else - * { - * printf("email_get_attachment_data SUCCESS\n"); - * //do something - * email_free_attachment_data(&mail_attach_info,1); - * } - * } + * #include "email-api-account.h" + * bool + * _api_sample_mail_get_attachment_info() + * { + * email_mail_attachment_info_t *mail_attach_info = NULL; + * int mail_id = 0; + * char arg[10]; + * int err = EMAIL_ERROR_NONE; + * + * + * printf("\n > Enter Mail Id: "); + * scanf("%d", &mail_id); + * printf("> attachment Id\n"); + * scanf("%s",arg); + * if (EMAIL_ERROR_NONE != email_get_attachment_data(mail_id, &mail_attach_info)) + * printf("email_get_attachment_data failed\n"); + * else + * { + * printf("email_get_attachment_data SUCCESS\n"); + * //do something + * email_free_attachment_data(&mail_attach_info,1); + * } + * } * @endcode - * @remarks N/A */ EXPORT_API int email_get_attachment_data(int attachment_id, email_attachment_data_t** attachment); /** - * @fn email_get_attachment_data_list(int input_mail_id, email_attachment_data_t **output_attachment_data, int *output_attachment_count) - * @brief Get a list of mail attachment.This function is invoked when user wants to get the information of attachment list based on mail id. - * - * @return This function returns EMAIL_ERROR_NONE on success or error code (refer to EMAIL_ERROR_XXX) on failure. - * @param[in] input_mail_id Specifies the mail ID. - * @param[out] output_attachment_data The returned attachment list is save here. - * @param[out] output_attachment_count The returned count of attachment list. - * @exception none - * @see email_attachment_data_t - * @remarks N/A + * @brief Gets a list of mail attachments. + * @details This function is invoked when a user wants to get the the attachment list information based on the mail ID. + * + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/email + * + * @param[in] input_mail_id The mail ID + * @param[out] output_attachment_data The returned attachment list is save here + * @param[out] output_attachment_count The returned count of attachment list + * + * @return #EMAIL_ERROR_NONE on success, + * otherwise an error code (see #EMAIL_ERROR_XXX) on failure + * + * @see #email_attachment_data_t */ EXPORT_API int email_get_attachment_data_list(int input_mail_id, email_attachment_data_t **output_attachment_data, int *output_attachment_count); /** - * @fn email_free_attachment_data(email_attachment_data_t **attachment_data_list, int attachment_data_count) - * @brief Free allocated memroy for email attachment. + * @brief Frees the allocated memory for email attachments. + * + * @since_tizen 2.3 + * + * @param[in] atch_info The pointer of mail attachment structure pointer + * + * @return #EMAIL_ERROR_NONE on success, + * otherwise an error code (see #EMAIL_ERROR_XXX) on failure + * + * @see #email_mail_attachment_info_t * - * @return This function returns EMAIL_ERROR_NONE on success or error code (refer to EMAIL_ERROR_XXX) on failure. - * @param[in] atch_info Specifies the pointer of mail attachment structure pointer. - * @exception none - * @see email_mail_attachment_info_t - * @code - * #include "email-api-account.h" - * bool - * _api_sample_mail_free_attachment_info() - * { - * email_mailbox_t mailbox; - * email_mail_attachment_info_t *mail_attach_info = NULL; - * int mail_id = 0,account_id = 0; - * char arg[10]; - * int err = EMAIL_ERROR_NONE; - * - * memset(&mailbox, 0x00, sizeof(email_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 (EMAIL_ERROR_NONE != email_get_attachment_data(&mailbox, mail_id, &mail_attach_info)) - * printf("email_get_attachment_data failed\n"); - * else - * { - * printf("email_get_attachment_data SUCCESS\n"); - * //do something - * email_free_attachment_info(&mail_attach_info,1); - * } - * } + * #include "email-api-account.h" + * bool + * _api_sample_mail_free_attachment_info() + * { + * email_mailbox_t mailbox; + * email_mail_attachment_info_t *mail_attach_info = NULL; + * int mail_id = 0,account_id = 0; + * char arg[10]; + * int err = EMAIL_ERROR_NONE; + * + * memset(&mailbox, 0x00, sizeof(email_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 (EMAIL_ERROR_NONE != email_get_attachment_data(&mailbox, mail_id, &mail_attach_info)) + * printf("email_get_attachment_data failed\n"); + * else + * { + * printf("email_get_attachment_data SUCCESS\n"); + * //do something + * email_free_attachment_info(&mail_attach_info,1); + * } + * } * @endcode - * @remarks N/A */ EXPORT_API int email_free_attachment_data(email_attachment_data_t **attachment_data_list, int attachment_data_count); /*----------------------------------------------------------- - Mail Information API + Mail Information API -----------------------------------------------------------*/ /** - * @fn email_query_mails(char *conditional_clause_string, email_mail_data_t** mail_list, int *result_count) - * @brief Query the mail list information from DB based on the mailbox name. + * @brief Queries the mail list information from the DB based on the mailbox name. + * + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/email + * + * @param[in] conditional_clause_string The where clause string + * @param[in/out] mail_list The pointer to the structure #email_mail_data_t + * @param[in/out] result_count The number of mails returned + * + * @return #EMAIL_ERROR_NONE on success, + * otherwise an error code (see #EMAIL_ERROR_XXX) on failure + * + * @see #email_mail_list_item_t * - * @return This function returns EMAIL_ERROR_NONE on success or error code (refer to EMAIL_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 email_mail_data_t. - * @param[in/out] result_count Specifies the number of mails returned. - * @exception None - * @see email_mail_list_item_t - * @code - * #include "email-api-account.h" - * bool - * _api_sample_query_mail() - * { - * email_mail_data_t *mail_list = NULL; - * char conditional_clause_string[500]; - * int result_count = 0; - * - * memset(conditional_clause_string, 0x00, 10); - * printf("\n > Enter where clause: "); - * scanf("%s", conditional_clause_string); - * - * - * if (EMAIL_ERROR_NONE != email_query_mails(conditional_clause_string, &mail_list, &result_count)) - * printf("email_query_mails failed \n"); - * else { - * printf("Success\n"); - * //do something - * free(mail_list); - * } - * - * } + * #include "email-api-account.h" + * bool + * _api_sample_query_mail() + * { + * email_mail_data_t *mail_list = NULL; + * char conditional_clause_string[500]; + * int result_count = 0; + * + * memset(conditional_clause_string, 0x00, 10); + * printf("\n > Enter where clause: "); + * scanf("%s", conditional_clause_string); + * + * + * if (EMAIL_ERROR_NONE != email_query_mails(conditional_clause_string, &mail_list, &result_count)) + * printf("email_query_mails 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, email_mail_data_t** mail_list, int *result_count); /** - * @fn email_query_mail_list(char *input_conditional_clause_string, email_mail_list_item_t** output_mail_list, int *output_result_count) - * @brief Query the mail list information from DB. + * @brief Queries the mail list information from the DB. + * + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/email + * + * @param[in] input_conditional_clause_string The where clause string + * @param[in/out] output_mail_list The pointer to the structure #email_mail_list_item_t + * @param[in/out] output_result_count The number of mails returned + * + * @return #EMAIL_ERROR_NONE on success, + * otherwise an error code (see #EMAIL_ERROR_XXX) on failure + * + * @see #email_mail_list_item_t * - * @return This function returns EMAIL_ERROR_NONE on success or error code (refer to EMAIL_ERROR_XXX) on failure. - * @param[in] input_conditional_clause_string Specifies the where clause string. - * @param[in/out] output_mail_list Specifies the pointer to the structure email_mail_list_item_t. - * @param[in/out] output_result_count Specifies the number of mails returned. - * @exception None - * @see email_mail_list_item_t - * @code - * #include "email-api-account.h" - * bool - * _api_sample_query_mail_list() - * { - * email_mail_list_item_t *mail_list = NULL; - * char conditional_clause_string[500]; - * int result_count = 0; - * - * memset(conditional_clause_string, 0x00, 10); - * printf("\n > Enter where clause: "); - * scanf("%s", conditional_clause_string); - * - * - * if (EMAIL_ERROR_NONE != email_query_mail_list(conditional_clause_string, &mail_list, &result_count)) - * printf("email_query_mail_list failed \n"); - * else { - * printf("Success\n"); - * //do something - * free(mail_list); - * } - * - * } + * #include "email-api-account.h" + * bool + * _api_sample_query_mail_list() + * { + * email_mail_list_item_t *mail_list = NULL; + * char conditional_clause_string[500]; + * int result_count = 0; + * + * memset(conditional_clause_string, 0x00, 10); + * printf("\n > Enter where clause: "); + * scanf("%s", conditional_clause_string); + * + * + * if (EMAIL_ERROR_NONE != email_query_mail_list(conditional_clause_string, &mail_list, &result_count)) + * printf("email_query_mail_list failed \n"); + * else { + * printf("Success\n"); + * //do something + * free(mail_list); + * } + * + * } * @endcode - * @remarks N/A */ EXPORT_API int email_query_mail_list(char *input_conditional_clause_string, email_mail_list_item_t** output_mail_list, int *output_result_count); /** - * @fn email_get_mail_data(int input_mail_id, email_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. + * @brief Gets a mail by its mail ID. + * @details This function is invoked when a user wants to get a mail based on mail ID existing in the DB. + * + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/email + * + * @param[in] input_mail_id The mail ID + * @param[out] output_mail_data The returned mail is save here + * + * @return #EMAIL_ERROR_NONE on success, + * otherwise an error code (see #EMAIL_ERROR_XXX) on failure + * + * @see #email_mail_data_t * - * @return This function returns EMAIL_ERROR_NONE on success or error code (refer to EMAIL_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 email_mail_data_t - * @code * #include "email-api-account.h" - * bool - * _api_sample_get_mail_data() - * { - * email_mail_data_t *mail = NULL; - * int mail_id = 0 ; - * int err = EMAIL_ERROR_NONE; - * - * printf("\n > Enter mail id: "); - * scanf("%d", &mail_id); - * - * if (EMAIL_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); - * } - * } + * bool + * _api_sample_get_mail_data() + * { + * email_mail_data_t *mail = NULL; + * int mail_id = 0 ; + * int err = EMAIL_ERROR_NONE; + * + * printf("\n > Enter mail id: "); + * scanf("%d", &mail_id); + * + * if (EMAIL_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, email_mail_data_t **output_mail_data); /** - * @fn email_free_mail_data(email_mail_data_t** mail_list, int count) - * @brief Free allocated memroy for emails. + * @brief Frees the allocated memory for emails. + * + * @since_tizen 2.3 + * + * @param[in] mail_list The pointer of mail structure pointer + * @param[in] count The count of mails + * + * @return #EMAIL_ERROR_NONE on success, + * otherwise an error code (see #EMAIL_ERROR_XXX) on failure + * + * @see #email_mail_data_t * - * @return This function returns EMAIL_ERROR_NONE on success or error code (refer to EMAIL_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 email_mail_data_t - * @code - * #include "email-api-account.h" - * bool - * _api_sample_free_mail() - * { - * email_mail_data_t *mail; - * - * //fill the mail structure - * //count - number of mail structure user want to free - * if(EMAIL_ERROR_NONE == email_free_mail_data(&mail,count)) - * //success - * else - * //failure - * - * } + * #include "email-api-account.h" + * bool + * _api_sample_free_mail() + * { + * email_mail_data_t *mail; + * + * //fill the mail structure + * //count - number of mail structure a user want to free + * if(EMAIL_ERROR_NONE == email_free_mail_data(&mail,count)) + * //success + * else + * //failure + * + * } * @endcode - * @remarks N/A */ EXPORT_API int email_free_mail_data(email_mail_data_t** mail_list, int count); /*----------------------------------------------------------- - Mail Flag API + Mail Flag API -----------------------------------------------------------*/ /** - * @fn email_set_flags_field(int *mail_ids, int num, email_flags_field_type field_type, int value, int onserver) - * @brief Change email flags field. - * If the incoming_server_type is EMAIL_SERVER_TYPE_POP3 then from_server value will be 0 - * If the incoming_server_type is EMAIL_SERVER_TYPE_IMAP4 then from_server value will be 1/0 - * - * @return This function returns EMAIL_ERROR_NONE on success or error code (refer to EMAIL_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 email_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 + * @brief Changes an email flags field. + * @details If the incoming_server_type is EMAIL_SERVER_TYPE_POP3 then from_server value will be 0. \n + * If the incoming_server_type is EMAIL_SERVER_TYPE_IMAP4 then from_server value will be 1/0. + * + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/email + * + * @param[in] account_id The account ID + * @param[in] mail_ids The array of mail IDs + * @param[in] num The number of mail IDs + * @param[in] field_type The field type to be set \n + * See #email_flags_field_type. + * @param[in] value The value to be set + * @param[in] onserver The flag indicating whether mail flag updating is in server + * + * @return #EMAIL_ERROR_NONE on success, + * otherwise an error code (see #EMAIL_ERROR_XXX) on failure + * * @code - * #include "email-api-account.h" - * bool - * _api_sample_set_flags_field() - * { - * int account_id = 0; - * int mail_id = 0; - * int err = EMAIL_ERROR_NONE; - * - * printf("\n > Enter account id: "); - * scanf("%d", &account_id); - * - * printf("\n > Enter mail id: "); - * scanf("%d", &mail_id); - * if (EMAIL_ERROR_NONE != email_set_flags_field(&account_id, &mail_id, EMAIL_FLAGS_SEEN_FIELD, 1, 0)) - * printf("email_set_flags_field failed\n"); - * else - * { - * printf("email_set_flags_field succeed\n"); - * //do something - * } - * } + * #include "email-api-account.h" + * bool + * _api_sample_set_flags_field() + * { + * int account_id = 0; + * int mail_id = 0; + * int err = EMAIL_ERROR_NONE; + * + * printf("\n > Enter account id: "); + * scanf("%d", &account_id); + * + * printf("\n > Enter mail id: "); + * scanf("%d", &mail_id); + * if (EMAIL_ERROR_NONE != email_set_flags_field(&account_id, &mail_id, EMAIL_FLAGS_SEEN_FIELD, 1, 0)) + * printf("email_set_flags_field failed\n"); + * else + * { + * printf("email_set_flags_field succeed\n"); + * //do something + * } + * } * @endcode - * @remarks N/A */ EXPORT_API int email_set_flags_field(int account_id, int *mail_ids, int num, email_flags_field_type field_type, int value, int onserver); /* ----------------------------------------------------------- - Mail Move API + Mail Move API -----------------------------------------------------------*/ /** - * @fn email_move_mail_to_mailbox(int *mail_ids, int num, int input_target_mailbox_id) - * @brief Move a email to another mailbox. + * @brief Moves an email to another mailbox. + * + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/email + * + * @param[in] mail_id The array of mail ID + * @param[in] num The count of mail IDs + * @param[in] input_target_mailbox_id The mailbox ID for moving email + * + * @return #EMAIL_ERROR_NONE on success, + * otherwise an error code (see #EMAIL_ERROR_XXX) on failure + * + * @see #email_mailbox_t * - * @return This function returns EMAIL_ERROR_NONE on success or error code (refer to EMAIL_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] input_target_mailbox_id Specifies the mailbox ID for moving email. - * @exception none - * @see email_mailbox_t - * @code - * #include "email-api-account.h" - * bool - * _api_sample_move_mail_to_mailbox() - * { - * int mail_id = 0; + * #include "email-api-account.h" + * bool + * _api_sample_move_mail_to_mailbox() + * { + * int mail_id = 0; * int mailbox_id = 0; - * int err = EMAIL_ERROR_NONE; + * int err = EMAIL_ERROR_NONE; - * printf("\n > Enter mail_id: "); - * scanf("%d",&mail_id); + * printf("\n > Enter mail_id: "); + * scanf("%d",&mail_id); * - * printf("\n > Enter target mailbox_id: "); - * scanf("%d",&mailbox_id); + * printf("\n > Enter target mailbox_id: "); + * scanf("%d",&mailbox_id); * - * if(EMAIL_ERROR_NONE == email_move_mail_to_mailbox(&mail_id, 1, mailbox_id)) - * printf("Success\n"); + * if(EMAIL_ERROR_NONE == email_move_mail_to_mailbox(&mail_id, 1, mailbox_id)) + * printf("Success\n"); * - * } + * } * @endcode - * @remarks N/A */ EXPORT_API int email_move_mail_to_mailbox(int *mail_ids, int num, int input_target_mailbox_id); /** - * @fn email_move_all_mails_to_mailbox(int input_source_mailbox_id, int input_target_mailbox_id) - * @brief Move all email to another mailbox. + * @brief Moves all emails to another mailbox. + * + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/email + * + * @param[in] input_source_mailbox_id The source mailbox ID for moving email + * @param[in] input_target_mailbox_id The destination mailbox ID for moving email + * + * @return #EMAIL_ERROR_NONE on success, + * otherwise an error code (see #EMAIL_ERROR_XXX) on failure + * + * @see #email_mailbox_t * - * @return This function returns EMAIL_ERROR_NONE on success or error code (refer to EMAIL_ERROR_XXX) on failure. - * @param[in] input_source_mailbox_id Specifies the source mailbox ID for moving email. - * @param[in] input_target_mailbox_id Specifies the destination mailbox ID for moving email. - * @exception none - * @see email_mailbox_t - * @code - * #include "email-api-account.h" - * bool - * _api_sample_move_all_mails_to_mailbox() - * { - * int src_mailbox_id; - * int dst_mailbox_id; - * int total_count; - * int err = EMAIL_ERROR_NONE; - * char temp[128]; - * - * - * // input mailbox information : need account_id and name (src & dest) - * printf("src mail maibox id> "); - * scanf("%d", &src_mailbox_id); - * - * // Destination mailbox - * printf("dest mailbox id> "); - * scanf("%d", &dst_mailbox_id); - * - * if( EMAIL_ERROR_NONE == email_move_all_mails_to_mailbox(src_mailbox_id, dst_mailbox_id)) - * { - * printf(" fail email_move_all_mails_to_mailbox: \n"); - * } - * else - * //success + * #include "email-api-account.h" + * bool + * _api_sample_move_all_mails_to_mailbox() + * { + * int src_mailbox_id; + * int dst_mailbox_id; + * int total_count; + * int err = EMAIL_ERROR_NONE; + * char temp[128]; + * + * + * // input mailbox information : need account_id and name (src & dest) + * printf("src mail maibox id> "); + * scanf("%d", &src_mailbox_id); + * + * // Destination mailbox + * printf("dest mailbox id> "); + * scanf("%d", &dst_mailbox_id); + * + * if( EMAIL_ERROR_NONE == email_move_all_mails_to_mailbox(src_mailbox_id, dst_mailbox_id)) + * { + * printf(" fail email_move_all_mails_to_mailbox: \n"); + * } + * else + * //success * } * @endcode - * @remarks N/A */ EXPORT_API int email_move_all_mails_to_mailbox(int input_source_mailbox_id, int input_target_mailbox_id); /** - * @fn email_move_mails_to_mailbox_of_another_account(int input_source_mailbox_id, int *mail_id_array, int mail_id_count, int input_target_mailbox_id, int *output_task_id) - * @brief Move mails to a mailbox of another account. - * - * @return This function returns EMAIL_ERROR_NONE on success or error code (refer to EMAIL_ERROR_XXX) on failure. - * @param[in] input_source_mailbox_id Specifies the source mailbox ID for moving email. - * @param[in] mail_id_array Specifies the source mail id array for moving email. - * @param[in] mail_id_count Specifies the count of source mail for moving email. - * @param[in] input_target_mailbox_id Specifies the destination mailbox ID for moving email. - * @param[out] output_task_id Specifies the task id for handling the task. - * @exception none - * @remarks N/A + * @brief Moves mails to the mailbox of an another account. + * + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/email + * + * @param[in] input_source_mailbox_id The source mailbox ID for moving email + * @param[in] mail_id_array The source mail ID array for moving email + * @param[in] mail_id_count The count of source mail for moving email + * @param[in] input_target_mailbox_id The destination mailbox ID for moving email + * @param[out] output_task_id The Task ID for handling the task + * + * @return #EMAIL_ERROR_NONE on success, + * or an error code (see #EMAIL_ERROR_XXX) on failure */ EXPORT_API int email_move_mails_to_mailbox_of_another_account(int input_source_mailbox_id, int *mail_id_array, int mail_id_count, int input_target_mailbox_id, int *output_task_id); /** - * @fn email_get_mail_list_ex(email_list_filter_t *input_filter_list, int input_filter_count, email_list_sorting_rule_t *input_sorting_rule_list, int input_sorting_rule_count, int input_start_index, int input_limit_count, email_mail_list_item_t** output_mail_list, int *output_result_count) - * @brief Get the Mail List information from DB. - * - * @return This function returns EMAIL_ERROR_NONE on success or error code (refer to EMAIL_ERROR_XXX) on failure. - * @param[in] input_filter_list Specifies the filter list - * @param[in] input_filter_count Specifies the number of filter - * @param[in] input_sorting_rule_list Specifies the sorting rule list. - * @param[in] input_sorting_rule_count Specifies the number of sorting rule - * @param[in] input_start_index Specifies start index for LIMIT clause of SQL query. - * @param[in] input_limit_count Specifies limit count for LIMIT clause of SQL query. - * @param[in/out] output_mail_list Specifies the pointer to the structure email_mail_list_item_t. - * @param[in/out] output_result_count Specifies the number of mails returned. - * @exception none - * @see email_mail_list_item_t + * @brief Gets the Mail List information from the DB. + * + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/email + * + * @param[in] input_filter_list The filter list + * @param[in] input_filter_count The number of filter + * @param[in] input_sorting_rule_list The sorting rule list + * @param[in] input_sorting_rule_count The number of sorting rule + * @param[in] input_start_index The start index for LIMIT clause of SQL query + * @param[in] input_limit_count The limit count for LIMIT clause of SQL query + * @param[in/out] output_mail_list The pointer to the structure #email_mail_list_item_t + * @param[in/out] output_result_count The number of mails returned + * + * @return #EMAIL_ERROR_NONE on success, + * otherwise an error code (see #EMAIL_ERROR_XXX) on failure + * + * @see #email_mail_list_item_t + * * @code * email_list_filter_t *filter_list = NULL; * email_list_sorting_rule_t *sorting_rule_list = NULL; @@ -1015,482 +1102,543 @@ EXPORT_API int email_move_mails_to_mailbox_of_another_account(int input_source_m * * return FALSE; * @endcode - * @remarks N/A */ EXPORT_API int email_get_mail_list_ex(email_list_filter_t *input_filter_list, int input_filter_count, email_list_sorting_rule_t *input_sorting_rule_list, int input_sorting_rule_count, int input_start_index, int input_limit_count, email_mail_list_item_t** output_mail_list, int *output_result_count); /** - * @fn email_free_list_filter(email_list_filter_t **input_filter_list, int input_filter_count) - * @brief Free allocated memroy for filers. - * - * @return This function returns EMAIL_ERROR_NONE on success or error code (refer to EMAIL_ERROR_XXX) on failure. - * @param[in] input_filter_list Specifies the pointer of filter structure. - * @param[in] input_filter_count Specifies the count of filter. - * @exception none - * @see email_list_filter_t - * @remarks N/A + * @brief Frees the allocated memory for filters. + * + * @since_tizen 2.3 + * @privlevel N/P + * + * @param[in] input_filter_list The pointer of filter structure + * @param[in] input_filter_count The count of filter + * + * @return #EMAIL_ERROR_NONE on success, + * otherwise an error code (see #EMAIL_ERROR_XXX) on failure + * + * @see #email_list_filter_t */ EXPORT_API int email_free_list_filter(email_list_filter_t **input_filter_list, int input_filter_count); /** - * @fn email_get_mails(int account_id , int mailbox_id, int thread_id, int start_index, int limit_count, email_sort_type_t sorting, email_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 EMAIL_ERROR_NONE on success or error code (refer to EMAIL_ERROR_XXX) on failure. - * @param[in] account_id Specifies the account ID - * @param[in] mailbox_id Specifies the mailbox id - * @param[in] thread_id Specifies the thread id. It can be EMAIL_LIST_TYPE_THREAD, EMAIL_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 email_mail_data_t. - * @param[in/out] result_count Specifies the number of mails returned. - * @exception none - * @see email_mail_data_t - + * @brief Gets the Mail List information from the DB based on the mailbox name. + * + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/email + * + * @param[in] account_id The account ID + * @param[in] mailbox_id The mailbox ID + * @param[in] thread_id The thread ID \n + * It can be #EMAIL_LIST_TYPE_THREAD, #EMAIL_LIST_TYPE_NORMAL or thread ID. + * @param[in] start_index The start index for LIMIT clause of SQL query + * @param[in] limit_count The limit count for LIMIT clause of SQL query + * @param[in] sorting The sorting type + * @param[in/out] mail_list The pointer to the structure #email_mail_data_t + * @param[in/out] result_count The number of mails returned + * + * @return #EMAIL_ERROR_NONE on success, + * otherwise an error code (see #EMAIL_ERROR_XXX) on failure + * + * @see #email_mail_data_t + * * @code - * #include "email-api-account.h" - * bool - * _api_sample_get_mail() - * { - * email_mail_data_t *mail_list = NULL; - * int mailbox_id; - * int result_count = 0; - * int account_id = 0; - * int err_code = EMAIL_ERROR_NONE; - * - * printf("\n > Enter Mailbox id: "); - * scanf("%d", mailbox_id); - * - * printf("\n > Enter Account_id: "); - * scanf("%d",&account_id); - * - * if (EMAIL_ERROR_NONE != email_get_mails(account_id, mailbox_id, EMAIL_LIST_TYPE_NORMAL, 0, 100, EMAIL_SORT_DATETIME_HIGH, &mail_list, &result_count)) { - * printf("email_get_mails failed \n"); - * } - * else { - * printf("Success\n"); - * //do something - * free(mail_list); - * } - * - * } + * #include "email-api-account.h" + * bool + * _api_sample_get_mail() + * { + * email_mail_data_t *mail_list = NULL; + * int mailbox_id; + * int result_count = 0; + * int account_id = 0; + * int err_code = EMAIL_ERROR_NONE; + * + * printf("\n > Enter Mailbox id: "); + * scanf("%d", mailbox_id); + * + * printf("\n > Enter Account_id: "); + * scanf("%d",&account_id); + * + * if (EMAIL_ERROR_NONE != email_get_mails(account_id, mailbox_id, EMAIL_LIST_TYPE_NORMAL, 0, 100, EMAIL_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 , int mailbox_id, int thread_id, int start_index, int limit_count, email_sort_type_t sorting, email_mail_data_t** mail_list, int* result_count); /** - * @fn email_get_mail_list(int account_id, int mailbox_id, int thread_id, int start_index, int limit_count, email_sort_type_t sorting, email_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 EMAIL_ERROR_NONE on success or error code (refer to EMAIL_ERROR_XXX) on failure. - * @param[in] account_id Specifies the account id - * @param[in] mailbox_id Specifies the mailbox id - * @param[in] thread_id Specifies the thread id. It can be EMAIL_LIST_TYPE_THREAD, EMAIL_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 email_mail_list_item_t. - * @param[in/out] result_count Specifies the number of mails returned. - * @exception none - * @see email_mail_list_item_t - + * @brief Gets the Mail List information from the DB based on the mailbox name. + * + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/email + * + * @param[in] account_id The account ID + * @param[in] mailbox_id The mailbox ID + * @param[in] thread_id The thread ID \n + * It can be #EMAIL_LIST_TYPE_THREAD, #EMAIL_LIST_TYPE_NORMAL or thread ID. + * @param[in] start_index The start index for LIMIT clause of SQL query + * @param[in] limit_count The limit count for LIMIT clause of SQL query + * @param[in] sorting The sorting type + * @param[in/out] mail_list The pointer to the structure #email_mail_list_item_t + * @param[in/out] result_count The number of mails returned + * + * @return #EMAIL_ERROR_NONE on success, + * otherwise an error code (see #EMAIL_ERROR_XXX) on failure + * + * @see #email_mail_list_item_t + * * @code - * #include "email-api-account.h" - * bool - * _api_sample_get_mail() - * { - * email_mail_list_item_t *mail_list = NULL; - * int mailbox_id; - * int result_count = 0; - * int account_id = 0; - * int err_code = EMAIL_ERROR_NONE; - * - * printf("\n > Enter Mailbox id: "); - * scanf("%d", mailbox_id); - * - * printf("\n > Enter Account_id: "); - * scanf("%d",&account_id); - * - * if (EMAIL_ERROR_NONE != email_get_mail_list(account_id, mailbox_id, EMAIL_LIST_TYPE_NORMAL, 0, 100, EMAIL_SORT_DATETIME_HIGH, &mail_list, &result_count)) - * { - * printf("email_get_mail_list_ex failed \n"); - * } - * else - * { - * printf("Success\n"); - * //do something - * free(mail_list); - * } - * - * } + * #include "email-api-account.h" + * bool + * _api_sample_get_mail() + * { + * email_mail_list_item_t *mail_list = NULL; + * int mailbox_id; + * int result_count = 0; + * int account_id = 0; + * int err_code = EMAIL_ERROR_NONE; + * + * printf("\n > Enter Mailbox id: "); + * scanf("%d", mailbox_id); + * + * printf("\n > Enter Account_id: "); + * scanf("%d",&account_id); + * + * if (EMAIL_ERROR_NONE != email_get_mail_list(account_id, mailbox_id, EMAIL_LIST_TYPE_NORMAL, 0, 100, EMAIL_SORT_DATETIME_HIGH, &mail_list, &result_count)) + * { + * printf("email_get_mail_list_ex failed \n"); + * } + * else + * { + * printf("Success\n"); + * //do something + * free(mail_list); + * } + * + * } * @endcode - * @remarks N/A */ EXPORT_API int email_get_mail_list(int account_id, int mailbox_id, int thread_id, int start_index, int limit_count, email_sort_type_t sorting, email_mail_list_item_t** mail_list, int* result_count); /** - * @fn email_get_mail_by_address(int account_id, int mailbox_id, email_email_address_list_t* addr_list, - int start_index, int limit_count, email_sort_type_t sorting, email_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 EMAIL_ERROR_NONE on success or error code (refer to EMAIL_ERROR_XXX) on failure. - * @param[in] account_id Specifies the Account ID - * @param[in] mailbox_id Specifies the Mailbox ID - * @param[in] addr_list Specifies the addresses of senders. see email_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 email_sort_type_t - * @param[in/out] mail_list Specifies the Pointer to the structure email_mail_list_item_t. - * @param[in/out] result_count Specifies the Number of searched Mails - * @exception none - * @see email_email_address_list_t, email_sort_type_t, email_mail_list_item_t - * @code - * @endcode - * @remarks N/A + * @brief Gets the Mail List information from the DB based on the mailbox name account_id and sender addresses. + * + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/email + * + * @param[in] account_id The Account ID + * @param[in] mailbox_id The Mailbox ID + * @param[in] addr_list The addresses of senders \n + * See #email_email_address_list_t. + * @param[in] start_index The first mail index of searched mail \n + * This function will return mails whose index in the result list are from @a start_index to @a start_index + @a limit_count. + * @param[in] limit_count The max number of returned mails + * @param[in] search_type The search type + * @param[in] search_value The search value + * @param[in] sorting The sorting order \n + * See #email_sort_type_t. + * @param[in/out] mail_list The Pointer to the structure #email_mail_list_item_t + * @param[in/out] result_count The number of searched mails + * + * @return #EMAIL_ERROR_NONE on success, + * otherwise an error code (see #EMAIL_ERROR_XXX) on failure + * + * @see #email_email_address_list_t, #email_sort_type_t, #email_mail_list_item_t */ EXPORT_API int email_get_mail_by_address(int account_id , int mailbox_id, email_email_address_list_t* addr_list, - int start_index, int limit_count, int search_type, const char *search_value, email_sort_type_t sorting, email_mail_list_item_t** mail_list, int* result_count); + int start_index, int limit_count, int search_type, const char *search_value, email_sort_type_t sorting, email_mail_list_item_t** mail_list, int* result_count); /** - * @fn email_get_thread_information_by_thread_id(int thread_id, email_mail_data_t** thread_info) - * @brief Get the thread information for specific thread from DB based on the mailbox name. - * - * @return This function returns EMAIL_ERROR_NONE on success or error code (refer to EMAIL_ERROR_XXX) on failure. - * @param[in] thread_id Specifies the thread_id - * @param[in/out] thread_info Specifies the Pointer to the structure email_mail_data_t. - * @exception none - * @see email_mail_data_t + * @brief Gets thread information for a specific thread from DB based on the mailbox name. + * + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/email + * + * @param[in] thread_id The thread ID + * @param[in/out] thread_info The pointer to the structure #email_mail_data_t + * + * @return #EMAIL_ERROR_NONE on success, + * otherwise an error code (see #EMAIL_ERROR_XXX) on failure + * + * @see #email_mail_data_t + * * @code - * #include "email-api-account.h" - * bool - * _api_sample_get_thread_information() - * { - * email_mail_data_t *thread_info = NULL; - * int thread_id = 0; - * int err_code = EMAIL_ERROR_NONE; - * - * printf("\n > Enter thread_id: "); - * scanf("%d",&thread_id); - * - * if ( EMAIL_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 - * } - * - * } + * #include "email-api-account.h" + * bool + * _api_sample_get_thread_information() + * { + * email_mail_data_t *thread_info = NULL; + * int thread_id = 0; + * int err_code = EMAIL_ERROR_NONE; + * + * printf("\n > Enter thread_id: "); + * scanf("%d",&thread_id); + * + * if ( EMAIL_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, email_mail_data_t** thread_info); /** - * @fn email_get_thread_information_ex(int thread_id, email_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 EMAIL_ERROR_NONE on success or error code (refer to EMAIL_ERROR_XXX) on failure. - * @param[in] thread_id Specifies the thread_id - * @param[in/out] thread_info Specifies the Pointer to the structure email_mail_list_item_t. - * @exception none - * @see email_mail_list_item_t + * @brief Gets Mail List information for a specific thread from the DB based on the mailbox name. + * + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/email + * + * @param[in] thread_id The thread ID + * @param[in/out] thread_info The pointer to the structure #email_mail_list_item_t + * + * @return #EMAIL_ERROR_NONE on success, + * otherwise an error code (see #EMAIL_ERROR_XXX) on failure + * + * @see #email_mail_list_item_t + * * @code - * #include "email-api-account.h" - * bool - * _api_sample_get_thread_information_ex() - * { - * email_mail_list_item_t *thread_info = NULL; - * int thread_id = 0; - * int err_code = EMAIL_ERROR_NONE; - * - * printf("\n > Enter thread_id: "); - * scanf("%d",&thread_id); - * - * if ( EMAIL_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 - * } - * - * } + * #include "email-api-account.h" + * bool + * _api_sample_get_thread_information_ex() + * { + * email_mail_list_item_t *thread_info = NULL; + * int thread_id = 0; + * int err_code = EMAIL_ERROR_NONE; + * + * printf("\n > Enter thread_id: "); + * scanf("%d",&thread_id); + * + * if ( EMAIL_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, email_mail_list_item_t** thread_info); /** - * @fn email_retry_sending_mail( int mail_id, int timeout_in_sec) - * @brief Retry mail send + * @brief Retries to send a mail. + * + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/email + * + * @param[in] mail_id The mail ID for the mail to resend + * @param[in] timeout_in_sec The timeout value in seconds + * + * @return #EMAIL_ERROR_NONE on success, + * otherwise an error code (see #EMAIL_ERROR_XXX) on failure * - * @return This function returns EMAIL_ERROR_NONE on success or error code (refer to EMAIL_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 "email-api-account.h" - * bool - * _api_sample_retry_send_mail() - * { - * int mail_id = 1; - * int timeout_in_sec = 2; - * - * if(EMAIL_ERROR_NONE == email_retry_sending_mail(mail_id,timeout_in_sec)) - * //success - * else - * //failure - * - * } + * #include "email-api-account.h" + * bool + * _api_sample_retry_send_mail() + * { + * int mail_id = 1; + * int timeout_in_sec = 2; + * + * if(EMAIL_ERROR_NONE == email_retry_sending_mail(mail_id,timeout_in_sec)) + * //success + * else + * //failure + * + * } * @endcode - * @remarks N/A */ EXPORT_API int email_retry_sending_mail(int mail_id, int timeout_in_sec); /** - * @fn email_create_db_full() - * @brief Create db and fill with dummy data + * @brief Creates a DB and fill it with dummy data. + * + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/email * - * @return This function returns EMAIL_ERROR_NONE on success or error code (refer to EMAIL_ERROR_XXX) on failure. - * @exception none - * @see none - * @remarks N/A + * @return #EMAIL_ERROR_NONE on success, + * otherwise error code (see #EMAIL_ERROR_XXX) on failure */ EXPORT_API int email_create_db_full(); /** - * @fn email_cancel_sending_mail( int mail_id) - * @brief Callback function for cm popup. We set the status as EMAIL_MAIL_STATUS_SEND_CANCELED + * @brief Callback function for cm popup. + * We set the status as EMAIL_MAIL_STATUS_SEND_CANCELED <<need to be updated>>. + * + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/email + * + * @param[in] mail_id The mail ID + * + * @return #EMAIL_ERROR_NONE on success, + * otherwise an error code (see #EMAIL_ERROR_XXX) on failure * - * @return This function returns EMAIL_ERROR_NONE on success or error code (refer to EMAIL_ERROR_XXX) on failure. - * @param[in] mail_id Specifies the mailID - * @exception none - * @see none * @code - * #include "email-api-account.h" - * bool - * _api_sample_cancel_send_mail() - * { - * int mail_id = 10; + * #include "email-api-account.h" + * bool + * _api_sample_cancel_send_mail() + * { + * int mail_id = 10; * * - * if(EMAIL_ERROR_NONE == email_cancel_sending_mail(mail_id,)) - * //success - * else - * //failure + * if(EMAIL_ERROR_NONE == email_cancel_sending_mail(mail_id,)) + * //success + * else + * //failure * - * } + * } * @endcode - * @remarks N/A */ EXPORT_API int email_cancel_sending_mail(int mail_id) ; /** - * @fn email_get_disk_space_usage(unsigned long *total_size) - * @brief Gets the total disk usage of emails in KB. + * @brief Gets the total disk usage of emails in KB. + * + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/email + * + * @param[out] total_size The total disk usage of emails + * + * @return #EMAIL_ERROR_NONE on success, + * otherwise an error code (see #EMAIL_ERROR_XXX) on failure * - * @return This function returns EMAIL_ERROR_NONE on success or error code (refer to EMAIL_ERROR_XXX) on failure. - * @param[out] total_size total disk usage of emails - * @exception none * @code - * #include "email-api-account.h" - * bool - * _api_sample_get_disk_space_usage() - * { - * unsigned long total_size = 0; - * - * if ( EMAIL_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); - * } + * #include "email-api-account.h" + * bool + * _api_sample_get_disk_space_usage() + * { + * unsigned long total_size = 0; + * + * if ( EMAIL_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); /** - * @fn email_get_address_info_list(int mail_id, email_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 email_address_info_list_t) - * Each GList (from, to, cc, bcc) is the list of email_address_info_t data. - * "data" variable of GList structure contains email_address_info_t data. <br> - * To get email_address_info_t data from GList, Use type casting from GList node. - * - * @return This function returns EMAIL_ERROR_NONE on success or error code (refer to EMAIL_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 email_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 email_address_info_list_t, email_address_info_t, email_free_address_info_list() + * @brief Gets the address info list. + * @details The address info list contains From, To, CC, BCC addresses and their display name, contact ID and etc (see #email_address_info_list_t).\n + * Each GList (From, To, CC, BCC) is the list of #email_address_info_t data. \n + * "data" variable of GList structure contains #email_address_info_t data. \n + * To get #email_address_info_t data from GList, use type casting from GList node. + * + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/email + * + * @param[in] mail_id The mail ID to get the list + * @param[out] address_info_list The pointer to the structure #email_address_info_list_t \n + * Memory for a new address info list will be allocated to this. + * You must call email_free_address_info_list() to free the memory allocated to this. + * + * @return #EMAIL_ERROR_NONE on success, + * otherwise an error code (see #EMAIL_ERROR_XXX) on failure + * + * @see #email_address_info_list_t, #email_address_info_t, email_free_address_info_list() + * * @code - * #include "email-api-account.h" - * bool - * _api_sample_get_address_info_list() - * { - * email_address_info_list_t *p_address_info_list= NULL; - * email_address_info_t *p_address_info = NULL; - * int mai_id; - * int err_code = EMAIL_ERROR_NONE; - * - * mail_id = 1; - * - * if ( EMAIL_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 = (email_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); - * } - * } + * #include "email-api-account.h" + * bool + * _api_sample_get_address_info_list() + * { + * email_address_info_list_t *p_address_info_list= NULL; + * email_address_info_t *p_address_info = NULL; + * int mai_id; + * int err_code = EMAIL_ERROR_NONE; + * + * mail_id = 1; + * + * if ( EMAIL_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 = (email_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, email_address_info_list_t** address_info_list); /** - * @fn email_free_address_info_list(email_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. + * @brief Frees the address info list allocated by email_get_address_info_list(). + * @details This function will free the memory which is allocated to address_info_list itself. + * + * @since_tizen 2.3 + * @privlevel N/P + * + * @param[in] address_info_list The pointer to the structure #email_address_info_list_t to be freed * - * @return This function returns EMAIL_ERROR_NONE on success or error code (refer to EMAIL_ERROR_XXX) on failure. - * @param[in] address_info_list Specifies the Pointer to the structure email_address_info_list_t to be freed. - * @exception none - * @see email_address_info_list_t, email_get_address_info_list() + * @return #EMAIL_ERROR_NONE on success, + * otherwise an error code (see #EMAIL_ERROR_XXX) on failure + * + * @see #email_address_info_list_t, email_get_address_info_list() */ EXPORT_API int email_free_address_info_list(email_address_info_list_t **address_info_list); /** - * @fn email_get_structure(const char*encoded_string, void **struct_var, email_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 EMAIL_ERROR_NONE on success or error code (refer to EMAIL_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 email_convert_struct_type_e - * @exception none - * @see email_convert_struct_type_e - */ -EXPORT_API int email_get_structure(const char*encoded_string, void **struct_var, email_convert_struct_type_e type); - -/** - - * @fn email_get_meeting_request(int mail_id, email_meeting_request_t **meeting_req) - * @brief Query the information of meeting request. - * 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 EMAIL_ERROR_NONE on success. This function returns EMAIL_ERROR_DATA_NOT_FOUND if there isn't a matched mail. Otherwise it returns error code (refer to EMAIL_ERROR_XXX) on failure. - * @param[in] input_conditional_clause_string Specifies the where clause string. - * @param[out] output_meeting_req Specifies the Pointer to the structure email_meeting_request_t. - * @param[out] output_count Specifies the number of meeting request returned. - * @exception none - * @see email_meeting_request_t + * @brief Queries the information of a meeting request. + * @details The information of a meeting request is corresponding to only one mail. \n + * For this reason, the information of a meeting request can be added by using email_add_message_with_meeting_request() with the matched mail information. + * + * @param[in] input_conditional_clause_string The where clause string + * @param[out] output_meeting_req The pointer to the structure #email_meeting_request_t + * @param[out] output_count The number of meeting request returned + * + * @return #EMAIL_ERROR_NONE on success, + * #EMAIL_ERROR_DATA_NOT_FOUND if there is no matched mail, + * otherwise an error code (see #EMAIL_ERROR_XXX) on failure + * + * @see #email_meeting_request_t */ EXPORT_API int email_query_meeting_request(char *input_conditional_clause_string, email_meeting_request_t **output_meeting_req, int *output_count); /** - * @fn email_get_meeting_request(int mail_id, email_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 EMAIL_ERROR_NONE on success. This function returns EMAIL_ERROR_DATA_NOT_FOUND if there isn't a matched mail. Otherwise it returns error code (refer to EMAIL_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 email_meeting_request_t. - * @exception none - * @see email_meeting_request_t + * @brief Gets the information of a meeting request. + * @details The information of a meeting request is based on the Mail ID. \n + * The information of the meeting request is corresponding to only one mail. \n + * For this reason, the meeting request information can be added by using email_add_message_with_meeting_request() with the matched mail information. + * + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/email + * + * @param[in] mail_id The mail ID for which meeting request details need to be fetched + * @param[in/out] meeting_req The pointer to the structure #email_meeting_request_t + * + * @return #EMAIL_ERROR_NONE on success, + * #EMAIL_ERROR_DATA_NOT_FOUND if there is no matched mail, + * otherwise an error code (see #EMAIL_ERROR_XXX) on failure + * + * @see #email_meeting_request_t */ EXPORT_API int email_get_meeting_request(int mail_id, email_meeting_request_t **meeting_req); /** - * @fn email_free_meeting_request(email_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 EMAIL_ERROR_NONE on success or error code (refer to EMAIL_ERROR_XXX) on failure. - * @param[in] email_meeting_request_t Specifies the Pointer to the structure email_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 email_meeting_request_t, email_get_meeting_request() + * @brief Frees a meeting request allocated by email_get_meeting_request() or allocated to add. + * @details This function will free the memory which is allocated to meeting_req (= *meeting_req) itself. + * + * @since_tizen 2.3 + * @privlevel N/P + * + * @param[in] email_meeting_request_t The pointer to the structure #email_meeting_request_t to be freed + * @param[in] count The number of elements in #meeting_req array (usually @c 1) + * + * @return #EMAIL_ERROR_NONE on success, + * otherwise an error code (see #EMAIL_ERROR_XXX) on failure + * + * @see #email_meeting_request_t, email_get_meeting_request() */ EXPORT_API int email_free_meeting_request(email_meeting_request_t** meeting_req, int count); /** - * @fn email_move_thread_to_mailbox(int thread_id, int target_mailbox_id, int move_always_flag) - * @brief Move a thread of mails to target mailbox. - * - * @return This function returns EMAIL_ERROR_NONE on success or error code (refer to EMAIL_ERROR_XXX) on failure. - * @param[in] thread_id Specifies the thread id to move - * @param[in] target_mailbox_id Specifies the mailbox id which move in - * @param[in] move_always_flag Specify move always flag - * @exception none - * @see + * @brief Moves a thread of mails to the target mailbox. + * + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/email + * + * @param[in] thread_id The thread ID to move + * @param[in] target_mailbox_id The mailbox ID in which to move + * @param[in] move_always_flag The move always flag + * + * @return #EMAIL_ERROR_NONE on success, + * otherwise an error code (see #EMAIL_ERROR_XXX) on failure */ EXPORT_API int email_move_thread_to_mailbox(int thread_id, int target_mailbox_id, int move_always_flag); /** - * @fn email_delete_thread(int thread_id, int delete_always_flag) - * @brief delete a thread of mails. - * - * @return This function returns EMAIL_ERROR_NONE on success or error code (refer to EMAIL_ERROR_XXX) on failure. - * @param[in] thread_id Specifies the thread id to delete - * @param[in] delete_always_flag Specify delete always flag - * @exception none - * @see + * @brief Deletes a thread of mails. + * + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/email + * + * @param[in] thread_id The thread ID to delete + * @param[in] delete_always_flag The delete always flag + * + * @return #EMAIL_ERROR_NONE on success, + * otherwise an error code (see #EMAIL_ERROR_XXX) on failure */ EXPORT_API int email_delete_thread(int thread_id, int delete_always_flag); /** - * @fn email_modify_seen_flag_of_thread(int thread_id, int seen_flag, int on_server) - * @brief Modify seen flags of thread - * - * @return This function returns EMAIL_ERROR_NONE on success or error code (refer to EMAIL_ERROR_XXX) on failure. - * @param[in] thread_id Specifies the thread id to modify - * @param[in] seen_flag Specify seem flag - * @param[in] on_server Specify to sync with server - * @exception none - * @see + * @brief Modifies seen flags of the thread. + * + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/email + * + * @param[in] thread_id The thread ID to modify + * @param[in] seen_flag The seen flag + * @param[in] on_server The flag to sync with server + * + * @return #EMAIL_ERROR_NONE on success, + * otherwise an error code (see #EMAIL_ERROR_XXX) on failure */ EXPORT_API int email_modify_seen_flag_of_thread(int thread_id, int seen_flag, int on_server); /** - * @fn email_expunge_mails_deleted_flagged(int input_mailbox_id, int input_on_server, int *output_handle) - * @brief Delete mails which flagged to delete - * - * @return This function returns EMAIL_ERROR_NONE on success or error code (refer to EMAIL_ERROR_XXX) on failure. - * @param[in] input_mailbox_id Specifies the id of mailbox - * @param[in] input_on_server Specify to sync with server - * @param[out] output_handle Specify the handle of task - * @exception none - * @see + * @brief Deletes mails flagged to "delete". + * + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/email + * + * @param[in] input_mailbox_id The mailbox ID + * @param[in] input_on_server The flag to sync with server + * @param[out] output_handle The handle of task + * + * @return #EMAIL_ERROR_NONE on success, + * otherwise an error code (see #EMAIL_ERROR_XXX) on failure */ EXPORT_API int email_expunge_mails_deleted_flagged(int input_mailbox_id, int input_on_server, int *output_handle); @@ -1499,8 +1647,8 @@ EXPORT_API int email_expunge_mails_deleted_flagged(int input_mailbox_id, int inp #endif /* __cplusplus */ /** -* @} @} -*/ + * @} + */ #endif /* __EMAIL_API_MAIL_H__ */ diff --git a/email-api/include/email-api-mailbox.h b/email-api/include/email-api-mailbox.h index 0a7b7bb..60ceeea 100755 --- a/email-api/include/email-api-mailbox.h +++ b/email-api/include/email-api-mailbox.h @@ -26,104 +26,102 @@ #include "email-types.h" /** -* @defgroup EMAIL_SERVICE Email Service -* @{ -*/ - - -/** -* @ingroup EMAIL_SERVICE -* @defgroup EMAIL_API_MAILBOX Email Mailbox API -* @{ -*/ - -/** - * - * This file contains the data structures and interfaces needed for application, - * to interact with email-service. - * @file email-api-mailbox.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 provided by - * email-service . + * @file email-api-mailbox.h + * @brief This file contains the data structures and interfaces of mailbox provided by email-service. * @{ * @code * * #include "email_api_mailbox.h" * * bool other_app_invoke_uniform_api_sample(int *error_code) - * { - * email_mailbox_t mailbox; - * email_mailbox_t *new_mailbox =NULL; - * email_mailbox_t *mailbox_list = NULL; - * int count = 0; - * int mailbox_type; - * int handle = 0; - * char *pMaiboxName; - * char *pParentMailbox; - * - * memset(&mailbox,0x00,sizeof(email_mailbox_t)); - * mailbox.mailbox_name = strdup("test"); - * mailbox.alias = strdup("Personal"); - * mailbox.account_id = 1; - * printf("Enter local_yn(1/0)"); - * scanf("%d",&local_yn); - * mailbox.local=local_yn; - * mailbox.mailbox_type = 7; - * - * //create new mailbox - * - * if(EMAIL_ERR_NONE != email_add_mailbox(&mailbox,local_yn,&handle)) - * printf("email_add_mailbox failed\n"); - * else - * printf("email_add_mailbox success"); - * - * //delete mailbox - * - * if(EMAIL_ERROR_NONE != email_delete_mailbox(mailbox,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(EMAIL_ERROR_NONE != email_get_mailbox_list(account_id,local_yn,&mailbox_list,&count)) - * //failure - * else - * //success - * - * //Get mailbox by name - * pMailboxName = strdup("test"); - * if(EMAIL_ERROR_NONE != email_get_mailbox_by_name(account_id,pMailboxName,&mailbox_list)) - * //failure - * else - * //success - * - * //Get child mailbox list - * pParentMailbox = strdup("test"); - * if(EMAIL_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(EMAIL_ERROR_NONE != email_get_mailbox_by_mailbox_type(account_id,mailbox_type,&mailbox_list)) - * //failure - * else - * //success - * - * } + * { + * email_mailbox_t mailbox; + * email_mailbox_t *new_mailbox =NULL; + * email_mailbox_t *mailbox_list = NULL; + * int count = 0; + * int mailbox_type; + * int handle = 0; + * char *pMaiboxName; + * char *pParentMailbox; + * + * memset(&mailbox,0x00,sizeof(email_mailbox_t)); + * mailbox.mailbox_name = strdup("test"); + * mailbox.alias = strdup("Personal"); + * mailbox.account_id = 1; + * printf("Enter local_yn(1/0)"); + * scanf("%d",&local_yn); + * mailbox.local=local_yn; + * mailbox.mailbox_type = 7; + * + * //create new mailbox + * + * if(EMAIL_ERR_NONE != email_add_mailbox(&mailbox,local_yn,&handle)) + * printf("email_add_mailbox failed\n"); + * else + * printf("email_add_mailbox success"); + * + * //delete mailbox + * + * if(EMAIL_ERROR_NONE != email_delete_mailbox(mailbox,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(EMAIL_ERROR_NONE != email_get_mailbox_list(account_id,local_yn,&mailbox_list,&count)) + * //failure + * else + * //success + * + * //Get mailbox by name + * pMailboxName = strdup("test"); + * if(EMAIL_ERROR_NONE != email_get_mailbox_by_name(account_id,pMailboxName,&mailbox_list)) + * //failure + * else + * //success + * + * //Get child mailbox list + * pParentMailbox = strdup("test"); + * if(EMAIL_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(EMAIL_ERROR_NONE != email_get_mailbox_by_mailbox_type(account_id,mailbox_type,&mailbox_list)) + * //failure + * else + * //success + * + * } * * @endcode * @} */ +/** + * @internal + * @ingroup EMAIL_SERVICE_FRAMEWORK + * @defgroup EMAIL_SERVICE_MAILBOX_MODULE Mailbox API + * @brief Mailbox API is a set of operations to manage email mailboxes like add, update, delete or get mailbox related details. + * + * @section EMAIL_SERVICE_MAILBOX_MODULE_HEADER Required Header + * \#include <email-api-mailbox.h> + * + * @section EMAIL_SERVICE_MAILBOX_MODULE_OVERVIEW Overview + * Mailbox API is a set of operations to manage email mailboxes like add, update, delete or get mailbox related details. + */ +/** + * @internal + * @addtogroup EMAIL_SERVICE_MAILBOX_MODULE + * @{ + */ #ifdef __cplusplus extern "C" @@ -132,269 +130,347 @@ extern "C" /** - * @fn int email_add_mailbox(email_mailbox_t* new_mailbox, int on_server, int *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 EMAIL_ERROR_NONE on success or error code(refer to EMAIL_ERROR_XXX) on failure. - * @param[in] new_mailbox Specifies the pointer of creating mailbox information. -* @param[in] on_server Specifies the creating mailbox on server. - * @param[out] handle Specifies the sending handle. - * @exception none - * @see email_mailbox_t - * @remarks N/A + * @brief Creates a new mailbox. + * @details This function is invoked when a user wants to create a new mailbox for the specified account.\n + * If on_server is true, it will create the mailbox on the server as well as locally. + * + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/email + * + * @param[in] new_mailbox The pointer of creating mailbox information + * @param[in] on_server The creating mailbox on server + * @param[out] handle The sending handle + * + * @return #EMAIL_ERROR_NONE on success, + * otherwise an error code (see #EMAIL_ERROR_XXX) on failure + * + * @see #email_mailbox_t */ EXPORT_API int email_add_mailbox(email_mailbox_t *new_mailbox, int on_server, int *handle); /** - * @fn int email_rename_mailbox(int input_mailbox_id, char *input_mailbox_name, char *input_mailbox_alias) - * @brief Change mailbox name. This function is invoked when user wants to change the name of existing mail box. - * - * @return This function returns EMAIL_ERROR_NONE on success or error code(refer to EMAIL_ERROR_XXX) on failure. - * @param[in] input_mailbox_id Specifies the id of the mailbox. - * @param[in] input_mailbox_name Specifies the name of the mailbox. - * @param[in] input_mailbox_alias Specifies the alias of the mailbox. - * @param[in] input_on_server Specifies the moving mailbox on server. - * @param[out] output_handle Specifies the handle to manage tasks. - * - * @exception see email-errors.h - * @see email_mailbox_t, email_mailbox_type_e - * @remarks N/A + * @brief Changes the name of a mailbox. + * @details This function is invoked when a user wants to change the name of an existing mail box. + * + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/email + * + * @remarks See email-errors.h for exception. + * + * @param[in] input_mailbox_id The mailbox ID + * @param[in] input_mailbox_name The name of the mailbox + * @param[in] input_mailbox_alias The alias of the mailbox + * @param[in] input_on_server The moving mailbox on server + * @param[out] output_handle The handle to manage tasks + * + * @return #EMAIL_ERROR_NONE on success, + * otherwise an error code (see #EMAIL_ERROR_XXX) on failure + * + * @see #email_mailbox_t, #email_mailbox_type_e */ EXPORT_API int email_rename_mailbox(int input_mailbox_id, char *input_mailbox_name, char *input_mailbox_alias, int input_on_server, int *output_handle); /** - * @fn int email_rename_mailbox_ex(int input_mailbox_id, char *input_mailbox_name, char *input_mailbox_alias, void *input_eas_data, int input_eas_data_length, int input_on_server, int *output_handle); - * @brief Change mailbox name. This function is invoked when user wants to change the name of existing mail box. - * - * @return This function returns EMAIL_ERROR_NONE on success or error code(refer to EMAIL_ERROR_XXX) on failure. - * @param[in] input_mailbox_id Specifies the id of the mailbox. - * @param[in] input_mailbox_name Specifies the name of the mailbox. - * @param[in] input_mailbox_alias Specifies the alias of the mailbox. - * @param[in] input_eas_data Specifies the eas data. - * @param[in] input_eas_data_length Specifies the length of eas data. - * @param[in] input_on_server Specifies the moving mailbox on server. - * @param[out] output_handle Specifies the handle to manage tasks. - * - * @exception see email-errors.h - * @see email_mailbox_t, email_mailbox_type_e - * @remarks N/A + * @brief Changes the name of a mailbox. + * @details This function is invoked when a user wants to change the name of an existing mail box. + * + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/email + * + * @remarks See email-errors.h for exception. + * + * @param[in] input_mailbox_id The mailbox ID + * @param[in] input_mailbox_name The name of the mailbox + * @param[in] input_mailbox_alias The alias of the mailbox + * @param[in] input_eas_data The EAS data + * @param[in] input_eas_data_length The length of EAS data + * @param[in] input_on_server The moving mailbox on server + * @param[out] output_handle The handle to manage tasks + * + * @return #EMAIL_ERROR_NONE on success, + * otherwise an error code (see #EMAIL_ERROR_XXX) on failure + * + * @see #email_mailbox_t, #email_mailbox_type_e */ EXPORT_API int email_rename_mailbox_ex(int input_mailbox_id, char *input_mailbox_name, char *input_mailbox_alias, void *input_eas_data, int input_eas_data_length, int input_on_server, int *output_handle); /** - * @fn int email_delete_mailbox(int input_mailbox_id, int input_on_server, int *output_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 EMAIL_ERROR_NONE on success or error code(refer to EMAIL_ERROR_XXX) on failure. - * @param[in] input_mailbox_id Specifies the id of target mailbox . - * @param[in] input_on_server Specifies the deleting mailbox on server. - * @param[out] output_handle Specifies the sending handle. - * @exception see email-errors.h - * @see email_mailbox_t - * @remarks N/A + * @brief Deletes a mailbox. + * @details This function deletes the existing mailbox for the specified account based on the on_server option. \n + * If on_server is true, it deletes the mailbox from the server as well as locally. + * + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/email + * + * @remarks See email-errors.h for exception. + * + * @param[in] input_mailbox_id The target mailbox ID + * @param[in] input_on_server The deleting mailbox on server + * @param[out] output_handle The sending handle + * + * @return #EMAIL_ERROR_NONE on success, + * otherwise an error code (see #EMAIL_ERROR_XXX) on failure + * + * @see #email_mailbox_t */ EXPORT_API int email_delete_mailbox(int input_mailbox_id, int input_on_server, int *output_handle); /** - * @fn int email_delete_mailbox_ex(int input_account_id, int *input_mailbox_id_array, int input_mailbox_id_count, int input_on_server, int *output_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 EMAIL_ERROR_NONE on success or error code(refer to EMAIL_ERROR_XXX) on failure. - * @param[in] input_account_id Specifies the id of account. - * @param[in] input_mailbox_id_array Specifies the mailbox array for deleting. - * @param[in] input_mailbox_id_count Specifies the count of mailbox for deleting. - * @param[in] input_on_server Specifies the deleting mailbox on server. - * @param[out] output_handle Specifies the sending handle. - * @exception see email-errors.h - * @see email_mailbox_t - * @remarks N/A + * @brief Deletes a mailbox. + * @details This function deletes the existing mailbox for the specified account based on the option on_server option. \n + * If on_server is true, it deletes the mailbox from the server as well as locally. + * + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/email + * + * @remarks See email-errors.h for exception. + * + * @param[in] input_account_id The account ID + * @param[in] input_mailbox_id_array The mailbox array for deleting + * @param[in] input_mailbox_id_count The count of mailbox for deleting + * @param[in] input_on_server The deleting mailbox on server + * @param[out] output_handle The sending handle + * + * @return #EMAIL_ERROR_NONE on success, + * otherwise an error code (see #EMAIL_ERROR_XXX) on failure + * + * @see #email_mailbox_t */ EXPORT_API int email_delete_mailbox_ex(int input_account_id, int *input_mailbox_id_array, int input_mailbox_id_count, int input_on_server, int *output_handle); /** - * @fn int email_set_mailbox_type(int input_mailbox_id, email_mailbox_type_e input_mailbox_type) - * @brief Change the mailbox type. This function is invoked when user wants to change the mailbox type. - * - * @return This function returns EMAIL_ERROR_NONE on success or error code(refer to EMAIL_ERROR_XXX) on failure. - * @param[in] input_mailbox_id Specifies the id of the mailbox. - * @param[in] input_mailbox_type Specifies the mailbox type. - * @exception see email-errors.h - * @see email_mailbox_type_e - * @remarks N/A + * @brief Changes the mailbox type. + * @details This function is invoked when a user wants to change the mailbox type. + * + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/email + * + * @remarks See email-errors.h for exception. + * + * @param[in] input_mailbox_id The mailbox ID + * @param[in] input_mailbox_type The mailbox type + * + * @return #EMAIL_ERROR_NONE on success, + * otherwise an error code(see #EMAIL_ERROR_XXX) on failure + * + * @see #email_mailbox_type_e */ EXPORT_API int email_set_mailbox_type(int input_mailbox_id, email_mailbox_type_e input_mailbox_type); /** - * @fn int email_set_local_mailbox(int input_mailbox_id, int input_is_local_mailbox) - * @brief Change the attribute 'local' of email_mailbox_t. This function is invoked when user wants to change the attribute 'local'. - * - * @return This function returns EMAIL_ERROR_NONE on success or error code(refer to EMAIL_ERROR_XXX) on failure. - * @param[in] input_mailbox_id Specifies the id of the mailbox. - * @param[in] input_is_local_mailbox Specifies the value of the attribute 'local' of email_mailbox_t. - * @exception see email-errors.h - * @see none - * @remarks N/A + * @brief Changes the 'local' attribute of #email_mailbox_t. + * @details This function is invoked when a user wants to change the 'local' attribute. + * + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/email + * + * @remarks See email-errors.h for exception. + * + * @param[in] input_mailbox_id The mailbox ID + * @param[in] input_is_local_mailbox The value of the attribute 'local' of #email_mailbox_t + * + * @return #EMAIL_ERROR_NONE on success, + * otherwise an error code (see #EMAIL_ERROR_XXX) on failure */ EXPORT_API int email_set_local_mailbox(int input_mailbox_id, int input_is_local_mailbox); /** - * @fn email_get_mailbox_list(int account_id, int mailbox_sync_type, email_mailbox_t** mailbox_list, int* count) - * @brief Get all mailboxes from account. - * - * @return This function returns EMAIL_ERROR_NONE on success or error code(refer to EMAIL_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 email_mailbox_t - + * @brief Gets all mailboxes from account. + * + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/email + * + * @param[in] account_id The account ID + * @param[in] mailbox_sync_type The sync type + * @param[out] mailbox_list The pointer of mailbox structure pointer (possibly @c NULL) + * @param[out] count The mailbox count (possibly @c 0) + * + * @return #EMAIL_ERROR_NONE on success, + * otherwise an error code (see #EMAIL_ERROR_XXX) on failure + * + * @see #email_mailbox_t + * * @code - * #include "email-api-mailbox.h" - * bool - * _api_sample_get_mailbox_list() - * { - * int account_id =0,count = 0; - * int mailbox_sync_type; - * int error_code = EMAIL_ERROR_NONE; - * email_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((EMAIL_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); - * } - * } + * #include "email-api-mailbox.h" + * bool + * _api_sample_get_mailbox_list() + * { + * int account_id =0,count = 0; + * int mailbox_sync_type; + * int error_code = EMAIL_ERROR_NONE; + * email_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((EMAIL_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, email_mailbox_t** mailbox_list, int* count); /** - * @fn email_get_mailbox_list_ex(int account_id, int mailbox_sync_type, int with_count, email_mailbox_t** mailbox_list, int* count) - * @brief Extend the email_get_mailbox_list_ex function. - * - * @return This function returns EMAIL_ERROR_NONE on success or error code(refer to EMAIL_ERROR_XXX) on failure. - * @param[in] account_id Specifies the account ID. - * @param[in] mailbox_sync_type Specifies the sync type. - * @param[in] with_count specifies the count of mailbox. - * @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 email_mailbox_t - * @remarks N/A + * @brief Extends the email_get_mailbox_list_ex() function. + * + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/email + * + * @param[in] account_id The account ID + * @param[in] mailbox_sync_type The sync type + * @param[in] with_count The count of mailbox + * @param[out] mailbox_list The pointer of mailbox structure pointer (possibly @c NULL) + * @param[out] count The mailbox count is saved here (possibly @c 0) + * + * @return #EMAIL_ERROR_NONE on success, + * otherwise an error code (see #EMAIL_ERROR_XXX) on failure + * + * @see #email_mailbox_t */ EXPORT_API int email_get_mailbox_list_ex(int account_id, int mailbox_sync_type, int with_count, email_mailbox_t** mailbox_list, int* count); /** - * @fn email_get_mailbox_list_by_keyworkd(int account_id, char *keyword , email_mailbox_t** mailbox_list, int* count) - * @brief Get the mailbox list to using keywork. - * - * @return This function returns EMAIL_ERROR_NONE on success or error code(refer to EMAIL_ERROR_XXX) on failure. - * @param[in] account_id Specifies the account ID. - * @param[in] keywork Specifies the specified keyworkd for searching. - * @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 email_mailbox_t - * @remarks N/A + * @brief Gets the mailbox list based on a keyword. + * + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/email + * + * @param[in] account_id The account ID + * @param[in] keyword The specified keyword for searching + * @param[out] mailbox_list The pointer of mailbox structure pointer (possibly @c NULL) + * @param[out] count The mailbox count is saved here (possibly @c 0) + * + * @return #EMAIL_ERROR_NONE on success, + * otherwise an error code (see #EMAIL_ERROR_XXX) on failure + * + * @see #email_mailbox_t */ EXPORT_API int email_get_mailbox_list_by_keyword(int account_id, char *keyword, email_mailbox_t** mailbox_list, int* count); /** - * @fn email_get_mailbox_by_mailbox_type(int account_id, email_mailbox_type_e mailbox_type, email_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 EMAIL_ERROR_NONE on success or error code(refer to EMAIL_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 email_mailbox_t - * @remarks N/A + * @brief Gets a mailbox by mailbox type. + * @details This function is invoked when a user wants to know the mailbox information by @a mailbox_type for the given account. + * + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/email + * + * @param[in] account_id The account ID + * @param[in] mailbox_type The mailbox type + * @param[out] mailbox The pointer of mailbox structure pointer (possibly @c NULL) + * + * @return #EMAIL_ERROR_NONE on success, + * otherwise an error code (see #EMAIL_ERROR_XXX) on failure + * + * @see #email_mailbox_t */ EXPORT_API int email_get_mailbox_by_mailbox_type(int account_id, email_mailbox_type_e mailbox_type, email_mailbox_t** mailbox); /** - * @fn email_get_mailbox_by_mailbox_id(int input_mailbox_id, email_mailbox_t** output_mailbox) - * @brief Get mailbox by mailbox_id. This function is invoked when user wants to know the mailbox information by mailbox id. - * - * @return This function returns EMAIL_ERROR_NONE on success or error code(refer to EMAIL_ERROR_XXX) on failure. - * @param[in] input_mailbox_id Specifies the mailbox id. - * @param[out] output_mailbox Specifies the pointer of mailbox structure pointer.(possibly NULL) - * @exception none - * @see email_mailbox_t - * @remarks N/A + * @brief Gets a mailbox by mailbox ID. + * @details This function is invoked when a user wants to know the mailbox information by mailbox ID. + * + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/email + * + * @param[in] input_mailbox_id The mailbox ID + * @param[out] output_mailbox The pointer of mailbox structure pointer (possibly @c NULL) + * + * @return #EMAIL_ERROR_NONE on success, + * otherwise an error code (see #EMAIL_ERROR_XXX) on failure + * + * @see #email_mailbox_t */ EXPORT_API int email_get_mailbox_by_mailbox_id(int input_mailbox_id, email_mailbox_t** output_mailbox); /** - * @fn email_set_mail_slot_size(int input_account_id, int input_mailbox_id, int input_new_slot_size) - * @brief Set mail slot size.This function is invoked when user wants to set the size of mail slot. - * - * @return This function returns EMAIL_ERROR_NONE on success or error code(refer to EMAIL_ERROR_XXX) on failure. - * @param[in] input_account_id Specifies the account ID. - * @param[in] input_mailbox_id Specifies the mailbox id. - * @param[in] input_new_slot_size Specifies the mail slot size. - * @exception none - * @see email_mailbox_t - * @remarks N/A + * @brief Sets a mail slot size. + * @details This function is invoked when a user wants to set the size of mail slot. + * + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/email + * + * @param[in] input_account_id The account ID + * @param[in] input_mailbox_id The mailbox ID + * @param[in] input_new_slot_size The mail slot size + * + * @return #EMAIL_ERROR_NONE on success, + * otherwise an error code (see #EMAIL_ERROR_XXX) on failure + * + * @see #email_mailbox_t */ EXPORT_API int email_set_mail_slot_size(int input_account_id, int input_mailbox_id, int input_new_slot_size); /** - * @fn email_stamp_sync_time_of_mailbox(int input_mailbox_id) - * @brief Stamp sync time of mailbox. This function is invoked when user wants to set the sync time of the mailbox. - * - * @return This function returns EMAIL_ERROR_NONE on success or error code(refer to EMAIL_ERROR_XXX) on failure. - * @param[in] input_mailbox_id Specifies the mailbox id. - * @exception none - * @see email_mailbox_t - * @remarks N/A + * @brief Sets the sync time of a mailbox. + * @details This function is invoked when a user wants to set the sync time of the mailbox. + * + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/email + * + * @param[in] input_mailbox_id The mailbox ID + * + * @return #EMAIL_ERROR_NONE on success, + * otherwise an error code (see #EMAIL_ERROR_XXX) on failure + * + * @see #email_mailbox_t */ EXPORT_API int email_stamp_sync_time_of_mailbox(int input_mailbox_id); /** - * @fn email_free_mailbox(email_mailbox_t** mailbox_list, int count) - * @brief Free allocated memory for mailbox information. - * - * @return This function returns EMAIL_ERROR_NONE on success or error code (refer to EMAIL_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 email_mailbox_t - + * @brief Frees the memory allocated for the mailbox information. + * + * @since_tizen 2.3 + * @privlevel N/P + * + * @param[in] mailbox_list The pointer for searching mailbox structure pointer + * @param[in] count The count of mailboxes + * + * @return #EMAIL_ERROR_NONE on success, + * otherwise an error code (see #EMAIL_ERROR_XXX) on failure + * + * @see #email_mailbox_t + * * @code - * #include "email-api-mailbox.h" - * bool - * _api_sample_free_mailbox_info() - * { - * email_mailbox_t *mailbox; - * - * //fill the mailbox structure - * //count - number of mailbox structure user want to free - * if(EMAIL_ERROR_NONE == email_free_mailbox(&mailbox,count)) - * //success - * else - * //failure - * - * } + * #include "email-api-mailbox.h" + * bool + * _api_sample_free_mailbox_info() + * { + * email_mailbox_t *mailbox; + * + * //fill the mailbox structure + * //count - number of mailbox structure user want to free + * if(EMAIL_ERROR_NONE == email_free_mailbox(&mailbox,count)) + * //success + * else + * //failure + * + * } * @endcode - * @remarks N/A */ EXPORT_API int email_free_mailbox(email_mailbox_t** mailbox_list, int count); @@ -404,8 +480,8 @@ EXPORT_API int email_free_mailbox(email_mailbox_t** mailbox_list, int count); #endif /* __cplusplus */ /** -* @} @} -*/ + * @} + */ #endif /* __EMAIL_API_MAILBOX_H__ */ diff --git a/email-api/include/email-api-network.h b/email-api/include/email-api-network.h index 77f3e16..cbce793 100755 --- a/email-api/include/email-api-network.h +++ b/email-api/include/email-api-network.h @@ -26,259 +26,289 @@ #include "email-types.h" /** -* @defgroup EMAIL_SERVICE Email Service -* @{ -*/ - -/** -* @ingroup EMAIL_SERVICE -* @defgroup EMAIL_API_NETWORK Email Network API -* @{ -*/ - -/** - * - * This file contains the data structures and interfaces needed for application, - * to interact with email-service. - * @file email-api-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-service . + * @internal + * @file email-api-network.h + * @brief This file contains the data structures and interfaces of Network related Functionality provided by + * email-service. * * @{ - * @code - * #include "email-api.h" - * - * bool - * other_app_invoke_uniform_api_sample(int* error_code) - * { - * - * // Send a mail - * email_attachment_data_t attachment; - * int account_id = 1; - * int mailbox_id = 0; - * int attachment_id = 0; - * int err = EMAIL_ERROR_NONE; - * int mail_id = 0; - * int action = -1; - * - * printf("Enter mail id\n"); - * scanf("%d",&mail_id); - * - * if(EMAIL_ERROR_NONE == email_send_mail(mail_id, &handle)) - * //success - * else - * //failure - * - * // Download header of new emails from mail server - * int handle = 0; - * - * mailbox.account_id = account_id; - * printf("Enter mailbox id\n"); - * scanf("%d",&mailbox_id); - * if(EMAIL_ERROR_NONE == email_sync_header (account_id, mailbox_id, &handle)) - * //success - * else - * //failure - * - * //Sync mail header for all accounts - * if(EMAIL_ERROR_NONE == email_sync_header_for_all_account(&handle)) - * //success - * else - * //failure - * - * //Download email body from server - * - * if(EMAIL_ERROR_NONE == email_download_body (mail_id,0,&handle)) - * //success - * else - * //failure - * - * //Download a email nth-attachment from server - * prinf("Enter attachment number\n"); - * scanf("%d",&attachment_id); - * if(EMAIL_ERROR_NONE == email_download_attachment(mail_id, attachment_id, &handle)) - * //success - * else - * //failure - * - * //Cancel job - * if(EMAIL_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 list for 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(EMAIL_ERROR_NONE == email_get_pending_job(action,account_id,mail_id,&status)) - * //success - * else - * //error - * - * //Get Network status - * if(EMAIL_ERROR_NONE == email_get_network_status(&sending,&receiving)) - * //success - * else - * //failure - * - * //Send read report - * if(EMAIL_ERROR_NONE == email_send_report(mail ,&handle)) - * //success - * else - * //failure - * //Save and send - * - * - * if(EMAIL_ERROR_NONE == email_add_mail(mail,NULL,0, NULL, 0)) - * { - * if(EMAIL_ERROR_NONE == email_send_saved(account_id,&option,&handle)) - * //success - * else - * //failure - * } - * //Get Imap mailbox list - * if(EMAIL_ERROR_NONE == email_sync_imap_mailbox_list(account_id, &handle)) - * //success - * else - * //failure + * #include "email-api.h" + * + * bool + * other_app_invoke_uniform_api_sample(int* error_code) + * { + * + * // Sends a mail + * email_attachment_data_t attachment; + * int account_id = 1; + * int mailbox_id = 0; + * int attachment_id = 0; + * int err = EMAIL_ERROR_NONE; + * int mail_id = 0; + * int action = -1; + * + * printf("Enter mail id\n"); + * scanf("%d",&mail_id); + * + * if(EMAIL_ERROR_NONE == email_send_mail(mail_id, &handle)) + * //success + * else + * //failure + * + * // Downloads header of new emails from mail server + * int handle = 0; + * + * mailbox.account_id = account_id; + * printf("Enter mailbox id\n"); + * scanf("%d",&mailbox_id); + * if(EMAIL_ERROR_NONE == email_sync_header (account_id, mailbox_id, &handle)) + * //success + * else + * //failure + * + * //Syncs mail header for all accounts + * if(EMAIL_ERROR_NONE == email_sync_header_for_all_account(&handle)) + * //success + * else + * //failure + * + * //Downloads email body from server + * + * if(EMAIL_ERROR_NONE == email_download_body (mail_id,0,&handle)) + * //success + * else + * //failure + * + * //Downloads an email nth-attachment from server + * prinf("Enter attachment number\n"); + * scanf("%d",&attachment_id); + * if(EMAIL_ERROR_NONE == email_download_attachment(mail_id, attachment_id, &handle)) + * //success + * else + * //failure + * + * //Cancel job + * if(EMAIL_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 + * //Gets pending job list for 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(EMAIL_ERROR_NONE == email_get_pending_job(action,account_id,mail_id,&status)) + * //success + * else + * //error + * + * //Gets Network status + * if(EMAIL_ERROR_NONE == email_get_network_status(&sending,&receiving)) + * //success + * else + * //failure + * + * //Sends read report + * if(EMAIL_ERROR_NONE == email_send_report(mail ,&handle)) + * //success + * else + * //failure + * //Saves and sends + * + * + * if(EMAIL_ERROR_NONE == email_add_mail(mail,NULL,0, NULL, 0)) + * { + * if(EMAIL_ERROR_NONE == email_send_saved(account_id,&option,&handle)) + * //success + * else + * //failure + * } + * //Get Imap mailbox list + * if(EMAIL_ERROR_NONE == email_sync_imap_mailbox_list(account_id, &handle)) + * //success + * else + * //failure * * } * * @endcode * @} - */ +/** + * @internal + * @ingroup EMAIL_SERVICE_FRAMEWORK + * @defgroup EMAIL_SERVICE_NETWORK_MODULE Network API + * @brief Network API is a set of operations to manage email send, receive and cancel related details. + * + * @section EMAIL_SERVICE_NETWORK_MODULE_HEADER Required Header + * \#include <email-api-network.h> + * + * @section EMAIL_SERVICE_NETWORK_MODULE_OVERVIEW Overview + * Network API is a set of operations to manage email send, receive and cancel related details. + */ +/** + * @internal +* @addtogroup EMAIL_SERVICE_NETWORK_MODULE +* @{ +*/ #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ /** - * @fn email_send_mail(int mail_id, int *handle) - * @brief Send a mail.This function is invoked when user wants to send a composed mail. - * - * @return This function returns EMAIL_ERROR_NONE on success or error code (refer to EMAIL_ERROR_XXX) on failure. - * @param[in] mail_id Specifies the mail ID. - * @param[out] handle Specifies the sending handle. - * @exception none - * @see email_mailbox_t and email_option_t - * @remarks N/A + * @brief Sends a mail. + * @details This function is invoked when a user wants to send a composed mail. + * + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/email + * + * @param[in] mail_id The mail ID + * @param[out] handle The sending handle + * + * @return #EMAIL_ERROR_NONE on success, + * otherwise an error code (see #EMAIL_ERROR_XXX) on failure + * + * @see #email_mailbox_t and #email_option_t */ EXPORT_API int email_send_mail(int mail_id, int *handle); /** - * @fn email_send_mail_with_downloading_attachment_of_original_mail(int input_mail_id, int *output_handle) - * @brief Send a mail. This function is invoked when user wants to send the mail, not been downloaded the attachment. - * - * @return This function returns EMAIL_ERROR_NONE on success or error code (refer to EMAIL_ERROR_XXX) on failure. - * @param[in] input_mail_id Specifies the mail ID. - * @param[out] handle Specifies the sending handle. - * @exception none - * @see email_mailbox_t and email_option_t - * @remarks N/A + * @brief Sends a mail. + * @details This function is invoked when a user wants to send the mail, not been downloaded the attachment. + * + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/email + * + * @param[in] input_mail_id The mail ID + * @param[out] handle The sending handle + * + * @return #EMAIL_ERROR_NONE on success, + * otherwise an error code (see #EMAIL_ERROR_XXX) on failure + * + * @see #email_mailbox_t and #email_option_t */ EXPORT_API int email_send_mail_with_downloading_attachment_of_original_mail(int input_mail_id, int *output_handle); /** - * @fn email_schedule_sending_mail(int input_mail_id, time_t input_time) - * @brief Send a mail. This function is invoked when user wants to send the scheduled mail. - * - * @return This function returns EMAIL_ERROR_NONE on success or error code (refer to EMAIL_ERROR_XXX) on failure. - * @param[in] input_mail_id Specifies the mail ID. - * @param[out] input_time Specifies the scheduled time. - * @exception none - * @see email_mailbox_t and email_option_t - * @remarks N/A + * @brief Sends a mail. + * @details This function is invoked when a user wants to send the scheduled mail. + * + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/email + * + * @param[in] input_mail_id The mail ID + * @param[out] input_time The scheduled time + * + * @return #EMAIL_ERROR_NONE on success, + * otherwise an error code (refer to #EMAIL_ERROR_XXX) on failure + * + * @see #email_mailbox_t and #email_option_t */ EXPORT_API int email_schedule_sending_mail(int input_mail_id, time_t input_time); /** - * @fn email_sync_header(int input_account_id, int input_mailbox_id, int *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 EMAIL_ERROR_NONE on success or error code (refer to EMAIL_ERROR_XXX) on failure. - * @param[in] input_account_id Specifies the account ID. - * @param[in] input_mailbox_id Specifies the mailbox ID. - * @param[out] handle Specifies the handle for stopping downloading. - * @exception none - * @see email_mailbox_t - * @remarks N/A + * @brief Downloads headers of new emails from the mail server. + * @details This function is invoked when a user wants to download only the headers of new mails. + * + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/email + * + * @param[in] input_account_id The account ID + * @param[in] input_mailbox_id The mailbox ID + * @param[out] handle The handle for stopping downloading + * + * @return #EMAIL_ERROR_NONE on success, + * otherwise an error code (see #EMAIL_ERROR_XXX) on failure + * + * @see #email_mailbox_t */ EXPORT_API int email_sync_header(int input_account_id, int input_mailbox_id, int *handle); /** - * @fn email_sync_header_for_all_account(int *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 EMAIL_ERROR_NONE on success or error code (refer to EMAIL_ERROR_XXX) on failure. - * @param[out] handle Specifies the handle for stopping downloading. - * @exception none - * @see none - * @remarks N/A + * @brief Downloads headers of new emails from the mail server for all emails. + * @details This function is invoked when a user wants to download headers of new mails for all accounts. + * + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/email + * + * @param[out] handle The handle for stopping downloading + * + * @return #EMAIL_ERROR_NONE on success, + * otherwise an error code (see #EMAIL_ERROR_XXX) on failure */ EXPORT_API int email_sync_header_for_all_account(int *handle); /** - - * @fn email_download_body(int mail_id, int with_attachment, int *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 EMAIL_ERROR_NONE on success or error code (refer to EMAIL_ERROR_XXX) on failure. - * @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 email_mailbox_t - * @remarks N/A + * @brief Downloads an email body from the server. + * @details This function is invoked when a user wants to download email body with/without attachment based on the @a with_attachment option + * from the server. + * + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/email + * + * @param[in] mail_id The mail ID + * @param[in] with_attachment The flag indicating whether there is an attachment + * @param[out] handle The handle for stopping downloading + * + * @return #EMAIL_ERROR_NONE on success, + * otherwise an error code (see #EMAIL_ERROR_XXX) on failure + * + * @see #email_mailbox_t */ EXPORT_API int email_download_body(int mail_id, int with_attachment, int *handle); - - - - /** - * @fn email_download_attachment(int mail_id, const char* nth, int *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 EMAIL_ERROR_NONE on success or error code (refer to EMAIL_ERROR_XXX) on failure. - * @param[in] mail_id Specifies the mail ID. - * @param[in] nth Specifies the attachment number been saved. the minimum number is "1". - * @param[out] handle Specifies the handle for stopping downloading. - * @exception none - * @see email_mailbox_t - * @remarks N/A + * @brief Downloads an email nth-attachment from the server. + * @details This function is invoked if a user wants to download only specific attachment of a mail whose body is already downloaded. + * + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/email + * + * @param[in] mail_id The mail ID + * @param[in] nth The attachment number been saved (The minimum number is "1") + * @param[out] handle The handle for stopping downloading + * + * @return #EMAIL_ERROR_NONE on success, + * otherwise an error code (see #EMAIL_ERROR_XXX) on failure + * + * @see #email_mailbox_t */ EXPORT_API int email_download_attachment(int mail_id, int nth, int *handle); /** - * @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 EMAIL_ERROR_NONE on success or error code (refer to EMAIL_ERROR_XXX) on failure. - * @param[in] input_account_id Specifies the account ID. - * @param[in] input_handle Specifies the handle for stopping the operation. - * @param[in] input_cancel_type Specifies the type of cancellation. - * @exception none - * @see none - * @remarks N/A + * @brief Cancels the ongoing job. + * @details This function is invoked if a user wants to cancel any ongoing job of a specified account. + * + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/email + * + * @param[in] input_account_id The account ID + * @param[in] input_handle The handle for stopping the operation + * @param[in] input_cancel_type The type of cancellation + * + * @return #EMAIL_ERROR_NONE on success, + * otherwise an error code (see #EMAIL_ERROR_XXX) on failure */ EXPORT_API int email_cancel_job(int input_account_id, int input_handle, email_cancelation_type input_cancel_type); @@ -287,90 +317,67 @@ EXPORT_API int email_get_pending_job(email_action_t action, int account_id, int EXPORT_API int email_get_network_status(int* on_sending, int* on_receiving) DEPRECATED; /** - * @fn email_get_task_information(email_task_information_t *output_task_information) - * @brief This function gives the current job information. - * - * @return This function returns EMAIL_ERROR_NONE on success or error code (refer to EMAIL_ERROR_XXX) on failure. - * @param[out] output_task_information The array of job information. - * @param[out] output_task_information_count The count of job information. - * @exception none - * @see none - * @remarks N/A + * @brief Gives the current job information. + * + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/email + * + * @param[out] output_task_information The array of job information + * @param[out] output_task_information_count The count of job information + * + * @return #EMAIL_ERROR_NONE on success, + * otherwise an error code (see #EMAIL_ERROR_XXX) on failure */ EXPORT_API int email_get_task_information(email_task_information_t **output_task_information, int *output_task_information_count); /** - * @fn email_send_saved(int account_id, int *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 EMAIL_ERROR_NONE on success or error code (refer to EMAIL_ERROR_XXX) on failure. - * @param[in] account_id Specifies the account ID. - * @param[out] handle Specifies the handle for stopping sending. - * @exception none - * @see email_option_t - * @remarks N/A + * @brief Sends all mails to be saved in offline-mode. + * @details This function is invoked when a user wants to send an email and saving it afterwards. + * This will save the email in draft mailbox and then send it. + * + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/email + * + * @param[in] account_id The account ID + * @param[out] handle The handle for stopping sending + * + * @return #EMAIL_ERROR_NONE on success, + * otherwise an error code (see #EMAIL_ERROR_XXX) on failure + * + * @see #email_option_t */ EXPORT_API int email_send_saved(int account_id, int *handle); /** - - * @fn email_sync_imap_mailbox_list(int account_id, int *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 EMAIL_ERROR_NONE on success or error code (refer to EMAIL_ERROR_XXX) on failure. - * @param[in] account_id Specifies the account ID. - * @param[out] handle Specifies the handle for stopping Network operation. - * @exception none - * @see none - * @remarks N/A + * @brief Fetches all mailbox names from the server and stores the non-existing mailboxes in the DB. + * @details This function is invoked when a user wants to download all server mailboxes from IMAP server. + * + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/email + * + * @param[in] account_id The account ID + * @param[out] handle The handle for stopping Network operation + * + * @return #EMAIL_ERROR_NONE on success, + * otherwise an error code (see #EMAIL_ERROR_XXX) on failure */ EXPORT_API int email_sync_imap_mailbox_list(int account_id, int *handle); /** - - * @fn email_search_mail_on_server(int input_account_id, int input_mailbox_id, email_search_filter_t *input_search_filter_list, int input_search_filter_count, int *output_handle) - * @brief Search the mails on server. - * - * @return This function returns EMAIL_ERROR_NONE on success or error code (refer to EMAIL_ERROR_XXX) on failure. - * @param[in] account_id Specifies the Account ID - * @param[in] mailbox_id Specifies the Mailbox ID - * @param[in] search_type Specifies the searching type(EMAIL_SEARCH_FILTER_SUBJECT, EMAIL_SEARCH_FILTER_SENDER, EMAIL_SEARCH_FILTER_RECIPIENT, EMAIL_SEARCH_FILTER_ALL) - * @param[in] search_value Specifies the value to use for searching. (ex : Subject, email address, display name) - * @exception none - * @see email_search_filter_t, - * @code - * @endcode - * @remarks N/A - */ -EXPORT_API int email_search_mail_on_server(int input_account_id, int input_mailbox_id, email_search_filter_t *input_search_filter_list, int input_search_filter_count, int *output_handle); - -/** - - * @fn email_clear_result_of_search_mail_on_server(int input_account_id) - * @brief Delete the temporarily downloaded mails on local storage. + * @brief Queries the maximum mail size limit from the SMTP server. * - * @return This function returns EMAIL_ERROR_NONE on success or error code (refer to EMAIL_ERROR_XXX) on failure. - * @param[in] account_id Specifies the Account ID - * @exception none - * @see email_search_filter_t, - * @code - * @endcode - * @remarks N/A - */ -EXPORT_API int email_clear_result_of_search_mail_on_server(int input_account_id); - -/** - - * @fn email_query_smtp_mail_size_limit(int account_id) - * @brief query maximum mail size limit from smtp server + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/email * - * @return This function returns EMAIL_ERROR_NONE on success or error code (refer to EMAIL_ERROR_XXX) on failure. - * @param[in] account_id Specifies the Account ID - * @exception none - * @code - * @endcode - * @remarks N/A + * @param[in] account_id The Account ID + * @param[out] handle The handle for stopping Network operation + * + * @return #EMAIL_ERROR_NONE on success, + * otherwise an error code (see #EMAIL_ERROR_XXX) on failure */ EXPORT_API int email_query_smtp_mail_size_limit(int account_id, int *handle); @@ -379,8 +386,8 @@ EXPORT_API int email_query_smtp_mail_size_limit(int account_id, int *handle); #endif /* __cplusplus */ /** -* @} -*/ + * @} + */ #endif /* __EMAIL_API_NETWORK_H__ */ diff --git a/email-api/include/email-api-rule.h b/email-api/include/email-api-rule.h index befcbc3..68b5644 100755 --- a/email-api/include/email-api-rule.h +++ b/email-api/include/email-api-rule.h @@ -26,192 +26,218 @@ #include "email-types.h" /** -* @defgroup EMAIL_SERVICE Email Service -* @{ -*/ - -/** -* @ingroup EMAIL_SERVICE -* @defgroup EMAIL_API_RULE Email Rule API -* @{ -*/ - - /** + * @file email-api-rule.h + * @brief This file contains the data structures and interfaces of Rule related Functionality provided by email-service. * - * This file contains the data structures and interfaces needed for application, - * to interact with email-service. - * @file email-api-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-service . * @{ - * @code - * #include "email-api-rule.h" - * bool - * other_app_invoke_uniform_api_sample(int* error_code) - * { - * int err = EMAIL_ERROR_NONE; - * email_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(EMAIL_ERROR_NONE == email_get_rule (filter_id,&rule)) - * //success - * else - * //failure - * - * // Get all filterings - * if(EMAIL_ERROR_NONE == email_get_rule_list(&rule,&count)) - * //success - * else - * //failure - * - * - * // Add a filter information - * if(EMAIL_ERROR_NONE == email_add_rule (rule)) - * //success - * else - * //failure - * err = email_free_rule (&rule,1); - * - * // Change a filter information - * if(EMAIL_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(EMAIL_ERROR_NONE == email_delete_rule (filter_id)) - * //success - * else - * //failure - * - * // Free allocated memory - * if(EMAIL_ERROR_NONE == email_free_rule (&rule,1)) - * //success - * else - * //failure - * - * } + * #include "email-api-rule.h" + * bool + * other_app_invoke_uniform_api_sample(int* error_code) + * { + * int err = EMAIL_ERROR_NONE; + * email_rule_t* rule = NULL; + * int filter_id = 1; + * int count = 0; + * + * // Gets information of filtering + * printf("Enter filter Id:\n"); + * scanf("%d",&filter_id); + * + * if(EMAIL_ERROR_NONE == email_get_rule (filter_id,&rule)) + * //success + * else + * //failure + * + * // Get all filterings + * if(EMAIL_ERROR_NONE == email_get_rule_list(&rule,&count)) + * //success + * else + * //failure + * + * + * // Adds a filter information + * if(EMAIL_ERROR_NONE == email_add_rule (rule)) + * //success + * else + * //failure + * err = email_free_rule (&rule,1); + * + * // Changes a filter information + * if(EMAIL_ERROR_NONE == email_update_rule (filter_id,rule)) + * //success + * else + * //failure + * err = email_free_rule (&rule,1); + * + * // Deletes a filter information + * printf("Enter filter Id:\n"); + * scanf("%d",&filter_id); + * + * if(EMAIL_ERROR_NONE == email_delete_rule (filter_id)) + * //success + * else + * //failure + * + * // Free allocated memory + * if(EMAIL_ERROR_NONE == email_free_rule (&rule,1)) + * //success + * else + * //failure + * + * } * * @endcode * @} */ +/** + * @internal + * @ingroup EMAIL_SERVICE_FRAMEWORK + * @defgroup EMAIL_SERVICE_RULE_MOUDLE Rule API + * @brief Rule API is a set of operations to manage email rules like add, get, delete or update rule related details. + * + * @section EMAIL_SERVICE_RULE_MOUDLE_HEADER Required Header + * \#include <email-api-rule.h> + * + * @section EMAIL_SERVICE_RULE_MOUDLE_OVERVIEW Overview + * Rule API is a set of operations to manage email rules like add, get, delete or update rule related details. + */ +/** + * @internal + * @addtogroup EMAIL_SERVICE_RULE_MOUDLE + * @{ + */ #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ /** - - - * @fn email_get_rule(int filter_id, email_rule_t** filtering_set) - * @brief Get a information of filtering. + * @brief Gets a filter rule. + * + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/email + * + * @param[in] filter_id The filter ID + * @param[out] filtering_set The filter rule * - * @return This function returns EMAIL_ERROR_NONE on success or error code (refer to EMAIL_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 EMAIL_ERROR_INVALID_PARAM -Invalid argument - * @see email_rule_t - * @remarks N/A + * @return #EMAIL_ERROR_NONE on success, + * otherwise an error code (see #EMAIL_ERROR_XXX) on failure + * + * @retval #EMAIL_ERROR_INVALID_PARAM Invalid argument + * + * @see #email_rule_t */ EXPORT_API int email_get_rule(int filter_id, email_rule_t** filtering_set); /** - - - * @fn email_get_rule_list(email_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. + * @brief Gets all filter rules. + * @details 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. + * + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/email + * + * @param[out] filtering_set The filtering rules (possibly @c NULL) + * @param[out] count The count of returned filters (possibly @c 0) * - * @return This function returns EMAIL_ERROR_NONE on success or error code (refer to EMAIL_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 EMAIL_ERROR_INVALID_PARAM -Invalid argument - * @see email_rule_t - * @remarks N/A + * @return #EMAIL_ERROR_NONE on success, + * otherwise an error code (see #EMAIL_ERROR_XXX) on failure + * + * @retval EMAIL_ERROR_INVALID_PARAM Invalid argument + * + * @see #email_rule_t */ EXPORT_API int email_get_rule_list(email_rule_t** filtering_set, int* count); /** - - - * @fn email_add_rule(email_rule_t* filtering_set) - * @brief Add a filter information.This function is invoked if user wants to add a new filter rule. + * @brief Adds a filter rule. + * @details This function is invoked if a user wants to add a new filter rule. + * + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/email + * + * @param[in] filtering_set The pointer of adding a filter structure + * + * @return #EMAIL_ERROR_NONE on success, + * otherwise error code (see #EMAIL_ERROR_XXX) on failure * - * @return This function returns EMAIL_ERROR_NONE on success or error code (refer to EMAIL_ERROR_XXX) on failure. - * @param[in] filtering_set Specifies the pointer of adding filter structure. - * @exception EMAIL_ERROR_INVALID_PARAM -Invalid argument - * @see email_rule_t - * @remarks N/A + * @retval EMAIL_ERROR_INVALID_PARAM Invalid argument + * + * @see #email_rule_t */ EXPORT_API int email_add_rule(email_rule_t* filtering_set); /** - - - * @fn email_update_rule(int filter_id, email_rule_t* new_set) - * @brief Change a filter information.This function will update the existing filter rule with new information. + * @brief Changes a filter rule. + * @details This function will update the existing filter rule with new information. * - * @return This function returns EMAIL_ERROR_NONE on success or error code (refer to EMAIL_ERROR_XXX) on failure. - * @param[in] filter_id Specifies the original filter ID. - * @param[in] new_set Specifies the information of new filter. - * @exception EMAIL_ERROR_INVALID_PARAM -Invalid argument - * @see email_rule_t - * @remarks N/A + * @param[in] filter_id The original filter ID + * @param[in] new_set The information of new filter + + * @return #EMAIL_ERROR_NONE on success, + * otherwise an error code (see #EMAIL_ERROR_XXX) on failure + * + * @retval EMAIL_ERROR_INVALID_PARAM Invalid argument + * + * @see #email_rule_t */ EXPORT_API int email_update_rule(int filter_id, email_rule_t* new_set); /** - - * @fn email_delete_rule(int filter_id) - * @brief Delete a filter information.This function will delete the exsting filter information by specified filter Id. + * @brief Deletes a filter rule. + * @details This function will delete the existing filter information by the specified filter ID. + * + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/email + * + * @param[in] filter_id The filter ID + * + * @return #EMAIL_ERROR_NONE on success, + * otherwise an error code (see #EMAIL_ERROR_XXX) on failure * - * @return This function returns EMAIL_ERROR_NONE on success or error code (refer to EMAIL_ERROR_XXX) on failure - * @param[in] filter_id Specifies the filter ID. - * @exception EMAIL_ERROR_INVALID_PARAM -Invalid argument - * @see none - * @remarks N/A + * @retval EMAIL_ERROR_INVALID_PARAM Invalid argument */ EXPORT_API int email_delete_rule(int filter_id); /** - - * @fn email_free_rule (email_rule_t** filtering_set, int count) - * @brief Free allocated memory. + * @brief Frees allocated memory. + * + * @since_tizen 2.3 + * @privlevel N/P + * + * @param[in] filtering_set The pointer of pointer of filter structure for memory freeing + * @param[in] count The count of filter * - * @return This function returns EMAIL_ERROR_NONE on success or error code (refer to EMAIL_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 EMAIL_ERROR_INVALID_PARAM -Invalid argument - * @see email_rule_t - * @remarks N/A + * @return #EMAIL_ERROR_NONE on success, + * otherwise an error code (see #EMAIL_ERROR_XXX) on failure + * + * @retval EMAIL_ERROR_INVALID_PARAM Invalid argument + * + * @see #email_rule_t */ EXPORT_API int email_free_rule (email_rule_t** filtering_set, int count); /** - - * @fn email_apply_rule(int filter_id) - * @brief Delete a filter information.This function will delete the exsting filter information by specified filter Id. + * @brief Deletes a filter rule. + * @details This function will delete the existing filter information by the specified filter ID. * - * @return This function returns EMAIL_ERROR_NONE on success or error code (refer to EMAIL_ERROR_XXX) on failure - * @param[in] filter_id Specifies the filter ID. - * @exception EMAIL_ERROR_INVALID_PARAM -Invalid argument - * @see none - * @remarks N/A + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/email + * + * @param[in] filter_id The filter ID + * + * @return #EMAIL_ERROR_NONE on success, + * otherwise an error code (see #EMAIL_ERROR_XXX) on failure + * + * @retval EMAIL_ERROR_INVALID_PARAM Invalid argument */ EXPORT_API int email_apply_rule(int filter_id); @@ -220,8 +246,8 @@ EXPORT_API int email_apply_rule(int filter_id); #endif /* __cplusplus */ /** -* @} @} -*/ + * @} + */ #endif /* __EMAIL_API_RULE_H__ */ diff --git a/email-api/include/email-api-smime.h b/email-api/include/email-api-smime.h index fc66834..a9d27d8 100755 --- a/email-api/include/email-api-smime.h +++ b/email-api/include/email-api-smime.h @@ -29,136 +29,198 @@ extern "C" { #endif /* __cplusplus */ /** + * @file email-api-smime.h + */ - * @fn email_add_certificate(char *certificate_path, char *email_address) - * @brief Store infomations of public certificate in database. +/** + * @internal + * @ingroup EMAIL_SERVICE_FRAMEWORK + * @defgroup EMAIL_SERVICE_SMIME_MODULE SMIME API + * @brief SMIME API is a set of operations to handle SMIME data for secured email. * - * @param[in] certificate_path File path of public certificate. - * @param[in] email_address Keyword for searching the certificate information - * @exception none - * @return This function returns EMAIL_ERROR_NONE on success or error code (refer to EMAIL_ERROR_XXX) on failure. - * @see - * @remarks N/A + * @section EMAIL_SERVICE_SMIME_MODULE_HEADER Required Header + * \#include <email-api-smime.h> + * + * @section EMAIL_SERVICE_SMIME_MODULE_OVERVIEW Overview + * SMIME API is a set of operations to handle SMIME data for secured email. */ -EXPORT_API int email_add_certificate(char *certificate_path, char *email_address); /** + * @internal + * @addtogroup EMAIL_SERVICE_SMIME_MODULE + * @{ + */ + - * @fn email_delete_certificate(char *email_address) - * @brief Delete infomations of public certificate in database. +/** + * @brief Stores a public certificate information in the database. + * + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/email * - * @param[in] email_address Keyword for deleting the certificate information - * @exception none - * @return This function returns EMAIL_ERROR_NONE on success or error code (refer to EMAIL_ERROR_XXX) on failure. - * @see - * @remarks N/A + * @param[in] certificate_path The file path of public certificate + * @param[in] email_address The keyword for searching the certificate information + * + * @return #EMAIL_ERROR_NONE on success, + * otherwise an error code (see #EMAIL_ERROR_XXX) on failure */ -EXPORT_API int email_delete_certificate(char *email_address); +EXPORT_API int email_add_certificate(char *certificate_path, char *email_address); /** + * @brief Deletes a public certificate information from the database. + * + * @param[in] email_address The keyword for deleting the certificate information + * + * @return #EMAIL_ERROR_NONE on success, + * otherwise an error code (see #EMAIL_ERROR_XXX) on failure + */ +EXPORT_API int email_delete_certificate(char *email_address); - * @fn email_get_certificate(char *email_address, email_certificate_t **certificate) - * @brief Get infomations of public certificate in database. +/** + * @brief Gets the the public certificate information from the database. + * + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/email * - * @param[in] email_address Keyword for geting the certificate information - * @param[out] certificate Specifies the certificate - * @exception none - * @return This function returns EMAIL_ERROR_NONE on success or error code (refer to EMAIL_ERROR_XXX) on failure. - * @see - * @remarks N/A + * @param[in] email_address The keyword for getting the certificate information + * @param[out] certificate The certificate + * + * @return #EMAIL_ERROR_NONE on success, + * otherwise an error code (see #EMAIL_ERROR_XXX) on failure */ EXPORT_API int email_get_certificate(char *email_address, email_certificate_t **certificate); /** + * @brief Gets a decrypted message. + * + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/email + * + * @param[in] mail_id The mail ID + * @param[out] output_mail_data The mail data + * @param[out] output_attachment_data The mail attachment data + * @param[out] output_attachment_count The count of attachment + * + * @return #EMAIL_ERROR_NONE on success, + * otherwise an error code (see #EMAIL_ERROR_XXX) on failure + */ +EXPORT_API int email_get_decrypt_message(int mail_id, email_mail_data_t **output_mail_data, email_attachment_data_t **output_attachment_data, int *output_attachment_count); - * @fn email_get_decrypt_message(int mail_id, email_mail_data_t **output_mail_data, email_attachment_data_t **output_attachment_data, int *output_attachment_count); - - * @brief Get the decrypted message - * @param[in] mail_id Specifies the mail_id - * @param[out] output_mail_data Specifies the mail_data +/** + * @brief Gets a decrypted message. + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/email + * @param[in] input_mail_data Specifies the signed mail data + * @param[in] input_attachment_data Specifies the attachment of signed mail + * @param[in] input_attachment_count Specifies the attachment count of signed mail + * @param[out] output_mail_data Specifies the mail_data * @param[out] output_attachment_data Specifies the mail_attachment_data * @param[out] output_attachment_count Specifies the count of attachment - * @exception none - * @return This function returns EMAIL_ERROR_NONE on success or error code (refer to EMAIL_ERROR_XXX) on failure. - * @see - * @remarks N/A + * @return EMAIL_ERROR_NONE on success or an error code (refer to EMAIL_ERROR_XXX) on failure */ -EXPORT_API int email_get_decrypt_message(int mail_id, email_mail_data_t **output_mail_data, email_attachment_data_t **output_attachment_data, int *output_attachment_count); - +EXPORT_API int email_get_decrypt_message_ex(email_mail_data_t *input_mail_data, email_attachment_data_t *input_attachment_data, int input_attachment_count, + email_mail_data_t **output_mail_data, email_attachment_data_t **output_attachment_data, int *output_attachment_count); /** - - * @fn email_verify_signature(int mail_id, int *verify); - - * @brief Verify the signed mail - * @param[in] mail_id Specifies the mail_id - * @param[out] verify Specifies verify [false : failed verify, true : success the verification] - * @exception none - * @return This function returns EMAIL_ERROR_NONE on success or error code (refer to EMAIL_ERROR_XXX) on failure. - * @see - * @remarks N/A + * @brief Verifies a signed mail. + * + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/email + * + * @param[in] mail_id The mail ID + * @param[out] verify The verification state \n + * [false : failed verification, true : verification successful] + * + * @return #EMAIL_ERROR_NONE on success, + * otherwise an error code (see #EMAIL_ERROR_XXX) on failure */ EXPORT_API int email_verify_signature(int mail_id, int *verify); +/** +* @brief Verifies a signed mail. +* @since_tizen 2.3 +* +* @param[in] input_mail_data The signed mail data +* @param[in] input_attachment_data The attachment of signed mail +* @param[in] input_attachment_count The attachment count of signed mail +* @param[out] verify The verification status \n +* false : failed verification, true : verification successful +* +* @return #EMAIL_ERROR_NONE on success, +* otherwise an error code (see #EMAIL_ERROR_XXX) on failure +*/ EXPORT_API int email_verify_signature_ex(email_mail_data_t *input_mail_data, email_attachment_data_t *input_attachment_data, int input_attachment_count, int *verify); /** - - * @fn email_verify_certificate(char *certificate_path, int *verify); - - * @brief Verify the certificate - * @param[in] certificate_path Specifies the path of certificate - * @param[out] verify Specifies verify [false : failed verify, true : success the verification] - * @exception none - * @return This function returns EMAIL_ERROR_NONE on success or error code (refer to EMAIL_ERROR_XXX) on failure. - * @see - * @remarks N/A + * @brief Verifies a certificate. + * + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/email + * + * @param[in] certificate_path The path of the certificate + * @param[out] verify The verification status \n + * false : failed verification, true : verification successful + * + * @return #EMAIL_ERROR_NONE on success, + * otherwise an error code (see #EMAIL_ERROR_XXX) on failure */ EXPORT_API int email_verify_certificate(char *certificate_path, int *verify); /** - - * @fn email_get_resolve_recipients(int account_id, char *email_address, unsigned *handle); - - * @brief Get the certificate at the server [Using exchange server] - * @param[in] account_id Specifies an account_id - * @param[in] email_address Specifies email address for getting certificate - * @param[out] handle Specifies the handle for stopping - * @exception none - * @return This function returns EMAIL_ERROR_NONE on success or error code (refer to EMAIL_ERROR_XXX) on failure. - * @see - * @remarks N/A + * @brief Gets the certificate from the server (using exchange server). + * + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/email + * + * @param[in] account_id The account ID + * @param[in] email_address The email address that gets a certificate + * @param[out] handle The handle for stopping + * + * @return #EMAIL_ERROR_NONE on success, + * otherwise an error code (see #EMAIL_ERROR_XXX) on failure */ EXPORT_API int email_get_resolve_recipients(int account_id, char *email_address, unsigned *handle); /** - - * @fn email_validate_certificate(int account_id, char *email_address, unsigned *handle); - - * @brief Verfiy the certificate to the server [Using exchange server] - * @param[in] account_id Specifies an account_id - * @param[in] email_address Specifies email address for validating certificate - * @param[out] handle Specifies the handle for stopping - * @exception none - * @return This function returns EMAIL_ERROR_NONE on success or error code (refer to EMAIL_ERROR_XXX) on failure. - * @see - * @remarks N/A + * @brief Verifies the certificate to the server (using exchange server). + * + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/email + * + * @param[in] account_id The account ID + * @param[in] email_address The email address that validates a certificate + * @param[out] handle The handle for stopping + * + * @return #EMAIL_ERROR_NONE on success, + * otherwise an error code (see #EMAIL_ERROR_XXX) on failure */ EXPORT_API int email_validate_certificate(int account_id, char *email_address, unsigned *handle); /** - - * @fn email_free_certificate(email_certificate_t **certificate, int count); - - * @brief Free the memory of certificate - * @param[in] certificate Specifies the certificate - * @param[in] count Specifies the count of certificates - * @exception none - * @return This function returns EMAIL_ERROR_NONE on success or error code (refer to EMAIL_ERROR_XXX) on failure. - * @see - * @remarks N/A + * @brief Frees the memory of the certificate. + * + * @since_tizen 2.3 + * @privlevel N/P + * + * @param[in] certificate The certificate + * @param[in] count The count of certificates + * + * @return #EMAIL_ERROR_NONE on success, + * otherwise error code (see #EMAIL_ERROR_XXX) on failure */ EXPORT_API int email_free_certificate(email_certificate_t **certificate, int count); +/** + * @} + */ + #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/email-api/include/email-api.h b/email-api/include/email-api.h index 8da1b26..e3841e9 100755 --- a/email-api/include/email-api.h +++ b/email-api/include/email-api.h @@ -35,26 +35,9 @@ #include "email-api-smime.h" #include "email-api-etc.h" - /** -* @defgroup EMAIL_SERVICE Email Service -* @{ -*/ - -/** -* @{ -*/ - -/** - * - * This file contains the data structures and interfaces needed for application, - * to interact with email-service. - * @file email-api.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-service. + * @file email-api.h + * @brief This file contains the data structures and interfaces provided by email-service. */ @@ -67,9 +50,6 @@ extern "C" { } #endif -/** -* @} @} -*/ #endif /* __EMAIL_MAPI_H__ */ diff --git a/email-common-use/CMakeLists.txt b/email-common-use/CMakeLists.txt index 0f777b2..803956c 100755 --- a/email-common-use/CMakeLists.txt +++ b/email-common-use/CMakeLists.txt @@ -12,6 +12,7 @@ MESSAGE(">>> current directory: ${CMAKE_CURRENT_SOURCE_DIR}") MESSAGE(">>> Build type: ${CMAKE_BUILD_TYPE}") SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${VISIBILITY} -fvisibility=hidden") +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wl,--gc-sections") SET(COMMON-USE-LIB "email-common-use") SET(COMMON-USE-SRCS @@ -46,5 +47,5 @@ TARGET_LINK_LIBRARIES(${COMMON-USE-LIB} ${common_pkgs_LDFLAGS}) SET_TARGET_PROPERTIES(${COMMON-USE-LIB} PROPERTIES SOVERSION ${VERSION_MAJOR}) SET_TARGET_PROPERTIES(${COMMON-USE-LIB} PROPERTIES VERSION ${VERSION}) -INSTALL(TARGETS ${COMMON-USE-LIB} DESTINATION ${LIB_INSTALL_DIR} COMPONENT RuntimeLibraries) +INSTALL(TARGETS ${COMMON-USE-LIB} DESTINATION lib COMPONENT RuntimeLibraries) diff --git a/email-common-use/email-convert.c b/email-common-use/email-convert.c index f9437e5..0545b19 100755 --- a/email-common-use/email-convert.c +++ b/email-common-use/email-convert.c @@ -45,70 +45,77 @@ INTERNAL_FUNC int em_convert_account_to_account_tbl(email_account_t *account, em EM_DEBUG_FUNC_BEGIN("account[%p], account_tbl[%p]", account, account_tbl); int ret = 1; - account_tbl->account_name = EM_SAFE_STRDUP(account->account_name); - account_tbl->incoming_server_type = account->incoming_server_type; - account_tbl->incoming_server_address = EM_SAFE_STRDUP(account->incoming_server_address); - account_tbl->user_email_address = EM_SAFE_STRDUP(account->user_email_address); - account_tbl->incoming_server_user_name = EM_SAFE_STRDUP(account->incoming_server_user_name); - account_tbl->incoming_server_password = EM_SAFE_STRDUP(account->incoming_server_password); - account_tbl->retrieval_mode = account->retrieval_mode; - account_tbl->incoming_server_port_number = account->incoming_server_port_number; - account_tbl->incoming_server_secure_connection = account->incoming_server_secure_connection; - account_tbl->outgoing_server_type = account->outgoing_server_type; - account_tbl->outgoing_server_address = EM_SAFE_STRDUP(account->outgoing_server_address); - account_tbl->outgoing_server_port_number = account->outgoing_server_port_number; - account_tbl->outgoing_server_need_authentication = account->outgoing_server_need_authentication; - account_tbl->outgoing_server_secure_connection = account->outgoing_server_secure_connection; - account_tbl->outgoing_server_user_name = EM_SAFE_STRDUP(account->outgoing_server_user_name); - account_tbl->outgoing_server_password = EM_SAFE_STRDUP(account->outgoing_server_password); - account_tbl->user_display_name = EM_SAFE_STRDUP(account->user_display_name); - account_tbl->reply_to_address = EM_SAFE_STRDUP(account->reply_to_address); - account_tbl->return_address = EM_SAFE_STRDUP(account->return_address); - account_tbl->account_id = account->account_id; - account_tbl->keep_mails_on_pop_server_after_download = account->keep_mails_on_pop_server_after_download; - account_tbl->auto_download_size = account->auto_download_size; - account_tbl->peak_interval = account->peak_interval; - account_tbl->peak_days = account->peak_days; - account_tbl->peak_start_time = account->peak_start_time; - account_tbl->peak_end_time = account->peak_end_time; - - - account_tbl->outgoing_server_use_same_authenticator = account->outgoing_server_use_same_authenticator; - account_tbl->auto_resend_times = account->auto_resend_times; - account_tbl->pop_before_smtp = account->pop_before_smtp; - account_tbl->incoming_server_requires_apop = account->incoming_server_requires_apop; - account_tbl->incoming_server_authentication_method = account->incoming_server_authentication_method; - account_tbl->logo_icon_path = EM_SAFE_STRDUP(account->logo_icon_path); - - account_tbl->user_data = em_memdup(account->user_data, account->user_data_length); - account_tbl->user_data_length = account->user_data_length; - account_tbl->roaming_option = account->roaming_option; - - 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->check_interval = account->check_interval; - account_tbl->account_svc_id = account->account_svc_id; - account_tbl->sync_status = account->sync_status; - account_tbl->sync_disabled = account->sync_disabled; - account_tbl->default_mail_slot_size = account->default_mail_slot_size; - account_tbl->smime_type = account->smime_type; - account_tbl->certificate_path = EM_SAFE_STRDUP(account->certificate_path); - account_tbl->cipher_type = account->cipher_type; - account_tbl->digest_type = account->digest_type; - account_tbl->outgoing_server_size_limit = account->outgoing_server_size_limit; - + account_tbl->account_name = EM_SAFE_STRDUP(account->account_name); + account_tbl->incoming_server_type = account->incoming_server_type; + account_tbl->incoming_server_address = EM_SAFE_STRDUP(account->incoming_server_address); + account_tbl->user_email_address = EM_SAFE_STRDUP(account->user_email_address); + account_tbl->incoming_server_user_name = EM_SAFE_STRDUP(account->incoming_server_user_name); + account_tbl->incoming_server_password = EM_SAFE_STRDUP(account->incoming_server_password); + account_tbl->retrieval_mode = account->retrieval_mode; + account_tbl->incoming_server_port_number = account->incoming_server_port_number; + account_tbl->incoming_server_secure_connection = account->incoming_server_secure_connection; + account_tbl->outgoing_server_type = account->outgoing_server_type; + account_tbl->outgoing_server_address = EM_SAFE_STRDUP(account->outgoing_server_address); + account_tbl->outgoing_server_port_number = account->outgoing_server_port_number; + account_tbl->outgoing_server_need_authentication = account->outgoing_server_need_authentication; + account_tbl->outgoing_server_secure_connection = account->outgoing_server_secure_connection; + account_tbl->outgoing_server_user_name = EM_SAFE_STRDUP(account->outgoing_server_user_name); + account_tbl->outgoing_server_password = EM_SAFE_STRDUP(account->outgoing_server_password); + account_tbl->user_display_name = EM_SAFE_STRDUP(account->user_display_name); + account_tbl->reply_to_address = EM_SAFE_STRDUP(account->reply_to_address); + account_tbl->return_address = EM_SAFE_STRDUP(account->return_address); + account_tbl->account_id = account->account_id; + account_tbl->keep_mails_on_pop_server_after_download = account->keep_mails_on_pop_server_after_download; + account_tbl->auto_download_size = account->auto_download_size; + account_tbl->peak_interval = account->peak_interval; + account_tbl->peak_days = account->peak_days; + account_tbl->peak_start_time = account->peak_start_time; + account_tbl->peak_end_time = account->peak_end_time; + + + account_tbl->outgoing_server_use_same_authenticator = account->outgoing_server_use_same_authenticator; + account_tbl->auto_resend_times = account->auto_resend_times; + account_tbl->pop_before_smtp = account->pop_before_smtp; + account_tbl->incoming_server_requires_apop = account->incoming_server_requires_apop; + account_tbl->incoming_server_authentication_method = account->incoming_server_authentication_method; + account_tbl->logo_icon_path = EM_SAFE_STRDUP(account->logo_icon_path); + + account_tbl->roaming_option = account->roaming_option; + account_tbl->color_label = account->color_label; + account_tbl->user_data = em_memdup(account->user_data, account->user_data_length); + account_tbl->user_data_length = account->user_data_length; + + 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->options.notification_status = account->options.notification_status; + account_tbl->options.vibrate_status = account->options.vibrate_status; + account_tbl->options.display_content_status = account->options.display_content_status; + account_tbl->options.default_ringtone_status = account->options.default_ringtone_status; + account_tbl->options.alert_ringtone_path = EM_SAFE_STRDUP(account->options.alert_ringtone_path); + + account_tbl->check_interval = account->check_interval; + account_tbl->account_svc_id = account->account_svc_id; + account_tbl->sync_status = account->sync_status; + account_tbl->sync_disabled = account->sync_disabled; + account_tbl->default_mail_slot_size = account->default_mail_slot_size; + account_tbl->smime_type = account->smime_type; + account_tbl->certificate_path = EM_SAFE_STRDUP(account->certificate_path); + account_tbl->cipher_type = account->cipher_type; + account_tbl->digest_type = account->digest_type; + account_tbl->outgoing_server_size_limit = account->outgoing_server_size_limit; + account_tbl->wifi_auto_download = account->wifi_auto_download; EM_DEBUG_FUNC_END(); return ret; @@ -119,65 +126,72 @@ INTERNAL_FUNC int em_convert_account_tbl_to_account(emstorage_account_tbl_t *acc EM_DEBUG_FUNC_BEGIN("account_tbl[%p], account[%p]", account_tbl, account); int ret = 1; - account->account_name = EM_SAFE_STRDUP(account_tbl->account_name); - account->incoming_server_type = account_tbl->incoming_server_type; - account->incoming_server_address = EM_SAFE_STRDUP(account_tbl->incoming_server_address); - account->user_email_address = EM_SAFE_STRDUP(account_tbl->user_email_address); - account->incoming_server_user_name = EM_SAFE_STRDUP(account_tbl->incoming_server_user_name); - account->incoming_server_password = EM_SAFE_STRDUP(account_tbl->incoming_server_password); - account->retrieval_mode = account_tbl->retrieval_mode; - account->incoming_server_port_number = account_tbl->incoming_server_port_number; - account->incoming_server_secure_connection = account_tbl->incoming_server_secure_connection; - account->outgoing_server_type = account_tbl->outgoing_server_type; - account->outgoing_server_address = EM_SAFE_STRDUP(account_tbl->outgoing_server_address); - account->outgoing_server_port_number = account_tbl->outgoing_server_port_number; - account->outgoing_server_need_authentication = account_tbl->outgoing_server_need_authentication; - account->outgoing_server_secure_connection = account_tbl->outgoing_server_secure_connection; - account->outgoing_server_user_name = EM_SAFE_STRDUP(account_tbl->outgoing_server_user_name); - account->outgoing_server_password = EM_SAFE_STRDUP(account_tbl->outgoing_server_password); - account->user_display_name = EM_SAFE_STRDUP(account_tbl->user_display_name); - account->reply_to_address = EM_SAFE_STRDUP(account_tbl->reply_to_address); - account->return_address = EM_SAFE_STRDUP(account_tbl->return_address); - account->account_id = account_tbl->account_id; - account->keep_mails_on_pop_server_after_download = account_tbl->keep_mails_on_pop_server_after_download; - account->auto_download_size = account_tbl->auto_download_size; - account->peak_interval = account_tbl->peak_interval; - account->peak_days = account_tbl->peak_days; - account->peak_start_time = account_tbl->peak_start_time; - account->peak_end_time = account_tbl->peak_end_time; - account->outgoing_server_use_same_authenticator = account_tbl->outgoing_server_use_same_authenticator; - account->pop_before_smtp = account_tbl->pop_before_smtp; - account->auto_resend_times = account_tbl->auto_resend_times; - account->incoming_server_requires_apop = account_tbl->incoming_server_requires_apop; - account->incoming_server_authentication_method = account_tbl->incoming_server_authentication_method; - account->logo_icon_path = EM_SAFE_STRDUP(account_tbl->logo_icon_path); - account->user_data = em_memdup(account_tbl->user_data, account_tbl->user_data_length); - account->user_data_length = account_tbl->user_data_length; - account->roaming_option = account_tbl->roaming_option; - 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->check_interval = account_tbl->check_interval; - account->account_svc_id = account_tbl->account_svc_id; - account->sync_status = account_tbl->sync_status; - account->sync_disabled = account_tbl->sync_disabled; - account->default_mail_slot_size = account_tbl->default_mail_slot_size; - account->smime_type = account_tbl->smime_type; - account->certificate_path = EM_SAFE_STRDUP(account_tbl->certificate_path); - account->cipher_type = account_tbl->cipher_type; - account->digest_type = account_tbl->digest_type; - account->outgoing_server_size_limit = account_tbl->outgoing_server_size_limit; + account->account_name = EM_SAFE_STRDUP(account_tbl->account_name); + account->incoming_server_type = account_tbl->incoming_server_type; + account->incoming_server_address = EM_SAFE_STRDUP(account_tbl->incoming_server_address); + account->user_email_address = EM_SAFE_STRDUP(account_tbl->user_email_address); + account->incoming_server_user_name = EM_SAFE_STRDUP(account_tbl->incoming_server_user_name); + account->incoming_server_password = EM_SAFE_STRDUP(account_tbl->incoming_server_password); + account->retrieval_mode = account_tbl->retrieval_mode; + account->incoming_server_port_number = account_tbl->incoming_server_port_number; + account->incoming_server_secure_connection = account_tbl->incoming_server_secure_connection; + account->outgoing_server_type = account_tbl->outgoing_server_type; + account->outgoing_server_address = EM_SAFE_STRDUP(account_tbl->outgoing_server_address); + account->outgoing_server_port_number = account_tbl->outgoing_server_port_number; + account->outgoing_server_need_authentication = account_tbl->outgoing_server_need_authentication; + account->outgoing_server_secure_connection = account_tbl->outgoing_server_secure_connection; + account->outgoing_server_user_name = EM_SAFE_STRDUP(account_tbl->outgoing_server_user_name); + account->outgoing_server_password = EM_SAFE_STRDUP(account_tbl->outgoing_server_password); + account->user_display_name = EM_SAFE_STRDUP(account_tbl->user_display_name); + account->reply_to_address = EM_SAFE_STRDUP(account_tbl->reply_to_address); + account->return_address = EM_SAFE_STRDUP(account_tbl->return_address); + account->account_id = account_tbl->account_id; + account->keep_mails_on_pop_server_after_download = account_tbl->keep_mails_on_pop_server_after_download; + account->auto_download_size = account_tbl->auto_download_size; + account->peak_interval = account_tbl->peak_interval; + account->peak_days = account_tbl->peak_days; + account->peak_start_time = account_tbl->peak_start_time; + account->peak_end_time = account_tbl->peak_end_time; + account->outgoing_server_use_same_authenticator = account_tbl->outgoing_server_use_same_authenticator; + account->pop_before_smtp = account_tbl->pop_before_smtp; + account->auto_resend_times = account_tbl->auto_resend_times; + account->incoming_server_requires_apop = account_tbl->incoming_server_requires_apop; + account->incoming_server_authentication_method = account_tbl->incoming_server_authentication_method; + account->logo_icon_path = EM_SAFE_STRDUP(account_tbl->logo_icon_path); + account->user_data = em_memdup(account_tbl->user_data, account_tbl->user_data_length); + account->user_data_length = account_tbl->user_data_length; + account->roaming_option = account_tbl->roaming_option; + account->color_label = account_tbl->color_label; + 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->options.notification_status = account_tbl->options.notification_status; + account->options.vibrate_status = account_tbl->options.vibrate_status; + account->options.display_content_status = account_tbl->options.display_content_status; + account->options.default_ringtone_status = account_tbl->options.default_ringtone_status; + account->options.alert_ringtone_path = EM_SAFE_STRDUP(account_tbl->options.alert_ringtone_path); + account->check_interval = account_tbl->check_interval; + account->account_svc_id = account_tbl->account_svc_id; + account->sync_status = account_tbl->sync_status; + account->sync_disabled = account_tbl->sync_disabled; + account->default_mail_slot_size = account_tbl->default_mail_slot_size; + account->smime_type = account_tbl->smime_type; + account->certificate_path = EM_SAFE_STRDUP(account_tbl->certificate_path); + account->cipher_type = account_tbl->cipher_type; + account->digest_type = account_tbl->digest_type; + account->outgoing_server_size_limit = account_tbl->outgoing_server_size_limit; + account->wifi_auto_download = account_tbl->wifi_auto_download; EM_DEBUG_FUNC_END(); return ret; @@ -331,6 +345,7 @@ INTERNAL_FUNC int em_convert_mail_tbl_to_mail_data(emstorage_mail_tbl_t *mail_ta } } memcpy(temp_mail_data[i].eas_data, mail_table_data[i].eas_data, mail_table_data[i].eas_data_length); + temp_mail_data[i].pgp_password = EM_SAFE_STRDUP(mail_table_data[i].pgp_password); } *mail_data = temp_mail_data; @@ -437,6 +452,7 @@ INTERNAL_FUNC int em_convert_mail_data_to_mail_tbl(email_mail_data_t *mail_dat } } memcpy(temp_mail_tbl[i].eas_data, mail_data[i].eas_data, mail_data[i].eas_data_length); + temp_mail_tbl[i].pgp_password = EM_SAFE_STRDUP(mail_data[i].pgp_password); } *mail_table_data = temp_mail_tbl; @@ -660,8 +676,8 @@ static int fetch_string_from_stream(char *input_stream, int *input_output_stream return EMAIL_ERROR_NONE; } /* divide struct at binary field (void* user_data)*/ -#define EMAIL_ACCOUNT_FMT "S(" "isiii" "isi" ")" "B" "S(" "issss" "isiss" "iiiii" "iiiii" "isiss" "iii"\ - "$(" "iiiii" "iisii" "iisi" ")" "iiiiisii" ")" +#define EMAIL_ACCOUNT_FMT "S(" "isiii" "isii" ")" "B" "S(" "issss" "isiss" "iiiii" "iiiii" "isiss" "iii"\ + "$(" "iiiii" "iisii" "iisi" "iiiis" ")" "iiiiiisii" ")" INTERNAL_FUNC char* em_convert_account_to_byte_stream(email_account_t* account, int *stream_len) @@ -718,7 +734,7 @@ INTERNAL_FUNC void em_convert_byte_stream_to_account(char *stream, int stream_le } #define EMAIL_MAIL_DATA_FMT "S(" "iiiis" "iisss" "issss" "sssss" "sisss"\ - "icccc" "cccii" "iiiii" "iisii" "iiiii" "iii)B" + "icccc" "cccii" "iiiii" "iisii" "iiiii" "iisi" ")B" INTERNAL_FUNC char* em_convert_mail_data_to_byte_stream(email_mail_data_t *mail_data, int *stream_len) { @@ -784,17 +800,12 @@ INTERNAL_FUNC void em_convert_byte_stream_to_mail_data(char *stream, int stream_ } -#define EMAIL_ATTACHMENT_DATA_FMT "A(S(" "issii" "iciii" "s" "))" +#define EMAIL_ATTACHMENT_DATA_FMT "A(S(" "isssi" "iicii" "is" "))" INTERNAL_FUNC char* em_convert_attachment_data_to_byte_stream(email_attachment_data_t *attachment, int attachment_count, int* stream_len) { EM_DEBUG_FUNC_BEGIN(); EM_IF_NULL_RETURN_VALUE(stream_len, NULL); - if(!attachment) { - EM_DEBUG_LOG("no attachment to be included"); - *stream_len = 0; - return NULL; - } email_attachment_data_t cur = {0}; tpl_node *tn = NULL; @@ -806,8 +817,10 @@ INTERNAL_FUNC char* em_convert_attachment_data_to_byte_stream(email_attachment_d EM_DEBUG_EXCEPTION("tpl_map failed"); return NULL; } + + /* if attachment_count is zero, for loop is skipped */ int i=0; - for( ; i < attachment_count ; i++ ) { + for( ; (i < attachment_count) && (attachment+i) ; i++ ) { memcpy(&cur, attachment + i, sizeof(email_attachment_data_t)); tpl_pack(tn, 1); } @@ -846,36 +859,31 @@ INTERNAL_FUNC void em_convert_byte_stream_to_attachment_data(char *stream, int s /* tpl does not return the size of variable-length array, but we need variable-length array */ /* so, make list and get list count in the first phase, */ /* and then copy list to var array after allocating memory */ - GList *head = NULL; - int count = 0; + + int num_element = tpl_Alen (tn, 1); + email_attachment_data_t *attached = NULL; + if (num_element > 0) + attached = (email_attachment_data_t*) em_malloc(sizeof(email_attachment_data_t)*num_element); + + int i = 0; while( tpl_unpack(tn, 1) > 0) { - email_attachment_data_t* pdata = (email_attachment_data_t*) em_malloc(sizeof(email_attachment_data_t)); + if (!(attached+i)) { + EM_DEBUG_EXCEPTION ("num element mismatched [%d] vs [%d]", num_element, i); + num_element = i; + break; + } + email_attachment_data_t* pdata = attached+i; memcpy(pdata, &cur, sizeof(email_attachment_data_t)); /* copy unpacked data to list item */ pdata->attachment_name = EM_SAFE_STRDUP(cur.attachment_name); pdata->attachment_path = EM_SAFE_STRDUP(cur.attachment_path); + pdata->content_id = EM_SAFE_STRDUP(cur.content_id); pdata->attachment_mime_type = EM_SAFE_STRDUP(cur.attachment_mime_type); - head = g_list_prepend(head, pdata); /* add it to list */ memset(&cur, 0, sizeof(email_attachment_data_t)); /* initialize variable, used for unpacking */ - count++; + i++; } tpl_free(tn); - /*finally we get the list count and allocate var length array */ - email_attachment_data_t *attached = (email_attachment_data_t*) em_malloc(sizeof(email_attachment_data_t)*count); - - /*write glist item into variable array*/ - head = g_list_reverse(head); - GList *p = g_list_first(head); - int i=0; - for( ; p ; p = g_list_next(p), i++ ) { - email_attachment_data_t* pdata = (email_attachment_data_t*) g_list_nth_data(p, 0); - memcpy( attached+i, pdata, sizeof(email_attachment_data_t)); - EM_SAFE_FREE(pdata); /*now, list item is useless */ - } - - g_list_free(head); - - *attachment_count = count; + *attachment_count = num_element; *attachment_data = attached; EM_DEBUG_FUNC_END(); } @@ -1155,38 +1163,45 @@ INTERNAL_FUNC char* em_convert_search_filter_to_byte_stream(email_search_filter_ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_search_filter_count), sizeof(int)); for( i = 0; i < input_search_filter_count; i++) { - result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_search_filter_list->search_filter_type), sizeof(int)); - switch(input_search_filter_list->search_filter_type) { + result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_search_filter_list[i].search_filter_type), sizeof(int)); + switch(input_search_filter_list[i].search_filter_type) { case EMAIL_SEARCH_FILTER_TYPE_MESSAGE_NO : case EMAIL_SEARCH_FILTER_TYPE_UID : + case EMAIL_SEARCH_FILTER_TYPE_ALL : case EMAIL_SEARCH_FILTER_TYPE_SIZE_LARSER : case EMAIL_SEARCH_FILTER_TYPE_SIZE_SMALLER : case EMAIL_SEARCH_FILTER_TYPE_FLAGS_ANSWERED : + case EMAIL_SEARCH_FILTER_TYPE_FLAGS_NEW : case EMAIL_SEARCH_FILTER_TYPE_FLAGS_DELETED : + case EMAIL_SEARCH_FILTER_TYPE_FLAGS_OLD : case EMAIL_SEARCH_FILTER_TYPE_FLAGS_DRAFT : case EMAIL_SEARCH_FILTER_TYPE_FLAGS_FLAGED : case EMAIL_SEARCH_FILTER_TYPE_FLAGS_RECENT : case EMAIL_SEARCH_FILTER_TYPE_FLAGS_SEEN : - result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_search_filter_list->search_filter_key_value.integer_type_key_value), sizeof(int)); + case EMAIL_SEARCH_FILTER_TYPE_HEADER_PRIORITY : + result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_search_filter_list[i].search_filter_key_value.integer_type_key_value), sizeof(int)); break; case EMAIL_SEARCH_FILTER_TYPE_BCC : + case EMAIL_SEARCH_FILTER_TYPE_BODY : case EMAIL_SEARCH_FILTER_TYPE_CC : case EMAIL_SEARCH_FILTER_TYPE_FROM : case EMAIL_SEARCH_FILTER_TYPE_KEYWORD : + case EMAIL_SEARCH_FILTER_TYPE_TEXT : case EMAIL_SEARCH_FILTER_TYPE_SUBJECT : case EMAIL_SEARCH_FILTER_TYPE_TO : case EMAIL_SEARCH_FILTER_TYPE_MESSAGE_ID : - result_stream = append_string_to_stream(result_stream, &stream_size, input_search_filter_list->search_filter_key_value.string_type_key_value); + case EMAIL_SEARCH_FILTER_TYPE_ATTACHMENT_NAME : + result_stream = append_string_to_stream(result_stream, &stream_size, input_search_filter_list[i].search_filter_key_value.string_type_key_value); break; case EMAIL_SEARCH_FILTER_TYPE_SENT_DATE_BEFORE : case EMAIL_SEARCH_FILTER_TYPE_SENT_DATE_ON : case EMAIL_SEARCH_FILTER_TYPE_SENT_DATE_SINCE : - result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_search_filter_list->search_filter_key_value.time_type_key_value), sizeof(struct tm)); + result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_search_filter_list[i].search_filter_key_value.time_type_key_value), sizeof(time_t)); break; default : - EM_DEBUG_EXCEPTION("Invalid filter type [%d]", input_search_filter_list->search_filter_type); + EM_DEBUG_EXCEPTION("Invalid filter type [%d]", input_search_filter_list[i].search_filter_type); break; } } @@ -1232,24 +1247,31 @@ INTERNAL_FUNC void em_convert_byte_stream_to_search_filter(char *input_stream, switch(local_search_filter[i].search_filter_type) { case EMAIL_SEARCH_FILTER_TYPE_MESSAGE_NO : case EMAIL_SEARCH_FILTER_TYPE_UID : + case EMAIL_SEARCH_FILTER_TYPE_ALL : case EMAIL_SEARCH_FILTER_TYPE_SIZE_LARSER : case EMAIL_SEARCH_FILTER_TYPE_SIZE_SMALLER : case EMAIL_SEARCH_FILTER_TYPE_FLAGS_ANSWERED : + case EMAIL_SEARCH_FILTER_TYPE_FLAGS_NEW : case EMAIL_SEARCH_FILTER_TYPE_FLAGS_DELETED : + case EMAIL_SEARCH_FILTER_TYPE_FLAGS_OLD : case EMAIL_SEARCH_FILTER_TYPE_FLAGS_DRAFT : case EMAIL_SEARCH_FILTER_TYPE_FLAGS_FLAGED : case EMAIL_SEARCH_FILTER_TYPE_FLAGS_RECENT : case EMAIL_SEARCH_FILTER_TYPE_FLAGS_SEEN : + case EMAIL_SEARCH_FILTER_TYPE_HEADER_PRIORITY : fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&(local_search_filter[i].search_filter_key_value.integer_type_key_value)); break; case EMAIL_SEARCH_FILTER_TYPE_BCC : + case EMAIL_SEARCH_FILTER_TYPE_BODY : case EMAIL_SEARCH_FILTER_TYPE_CC : case EMAIL_SEARCH_FILTER_TYPE_FROM : case EMAIL_SEARCH_FILTER_TYPE_KEYWORD : + case EMAIL_SEARCH_FILTER_TYPE_TEXT : case EMAIL_SEARCH_FILTER_TYPE_SUBJECT : case EMAIL_SEARCH_FILTER_TYPE_TO : case EMAIL_SEARCH_FILTER_TYPE_MESSAGE_ID : + case EMAIL_SEARCH_FILTER_TYPE_ATTACHMENT_NAME : fetch_string_from_stream(input_stream, &stream_offset, &(local_search_filter[i].search_filter_key_value.string_type_key_value)); break; @@ -1316,8 +1338,6 @@ INTERNAL_FUNC void em_convert_byte_stream_to_task_information(char *input_stream email_task_information_t cur = {0}; tpl_node *tn = NULL; int i = 0; - int count = 0; - GList *head = NULL; tn = tpl_map(EMAIL_JOB_INFORMATION_FMT, &cur); if (!tn) { @@ -1325,30 +1345,26 @@ INTERNAL_FUNC void em_convert_byte_stream_to_task_information(char *input_stream return; } tpl_load(tn, TPL_MEM, input_stream, input_stream_len); + int num_element = tpl_Alen (tn, 1); + email_task_information_t* deserialized = NULL; + if (num_element > 0) + deserialized = (email_task_information_t*) em_malloc(sizeof(email_task_information_t)*num_element); while( tpl_unpack(tn, 1) > 0) { - email_task_information_t* pdata = (email_task_information_t*) em_malloc(sizeof(email_task_information_t)); + if (!(deserialized+i)) { + EM_DEBUG_EXCEPTION ("num element mismatched [%d] vs [%d]", num_element, i); + num_element = i; + break; + } + email_task_information_t* pdata = deserialized+i; memcpy(pdata, &cur, sizeof(email_task_information_t)); - head = g_list_prepend(head, pdata); memset(&cur, 0, sizeof(email_task_information_t)); - count++; + i++; } tpl_free(tn); - email_task_information_t *deserialized = (email_task_information_t*) em_malloc(sizeof(email_task_information_t)*count); - head = g_list_reverse(head); - GList *p = g_list_first(head); - - for( ; p ; p = g_list_next(p), i++ ) { - email_task_information_t* pdata = (email_task_information_t*) g_list_nth_data(p, 0); - memcpy( deserialized+i, pdata, sizeof(email_task_information_t)); - EM_SAFE_FREE(pdata); - } - - g_list_free(head); - - *output_task_information_count = count; + *output_task_information_count = num_element; *output_task_information = deserialized; EM_DEBUG_FUNC_END(); @@ -1359,7 +1375,7 @@ INTERNAL_FUNC int em_convert_certificate_tbl_to_certificate(emstorage_certificat EM_DEBUG_FUNC_BEGIN("certficate_tbl[%p], certificate[%p]", certificate_tbl, certificate); int err_code = EMAIL_ERROR_NONE; - int ret = false; + email_certificate_t *temp_certificate = NULL; if (!certificate_tbl || !certificate) { @@ -1389,7 +1405,6 @@ INTERNAL_FUNC int em_convert_certificate_tbl_to_certificate(emstorage_certificat *certificate = temp_certificate; - ret = true; FINISH_OFF: if (error) *error = err_code; diff --git a/email-common-use/email-utilities.c b/email-common-use/email-utilities.c index b5f36f5..d4a0930 100755 --- a/email-common-use/email-utilities.c +++ b/email-common-use/email-utilities.c @@ -37,6 +37,7 @@ #include <pthread.h> #include <regex.h> #include <security-server.h> +#include <locale.h> #include "c-client.h" @@ -299,6 +300,83 @@ INTERNAL_FUNC char* em_replace_string(char *source_string, char *old_string, cha return result_buffer; } +INTERNAL_FUNC int em_replace_string_ex(char **input_source_string, char *input_old_string, char *input_new_string) +{ + EM_DEBUG_FUNC_BEGIN(); + int err = 0; + int buffer_length = 0; + int old_string_length = 0; + int new_string_length = 0; + int match_count = 0; + + char *cursor_of_source_string = NULL; + char *cursor_of_result_buffer = NULL; + char *result_buffer = NULL; + char *source_string = NULL; + char *found_pos = NULL; + + EM_IF_NULL_RETURN_VALUE(input_source_string, EMAIL_ERROR_INVALID_PARAM); + EM_IF_NULL_RETURN_VALUE(input_old_string, EMAIL_ERROR_INVALID_PARAM); + EM_IF_NULL_RETURN_VALUE(input_new_string, EMAIL_ERROR_INVALID_PARAM); + + source_string = *input_source_string; + + found_pos = strstr(source_string, input_old_string); + + if (found_pos == NULL) { + err = EMAIL_ERROR_DATA_NOT_FOUND; + goto FINISH_OFF; + } + + old_string_length = EM_SAFE_STRLEN(input_old_string); + new_string_length = EM_SAFE_STRLEN(input_new_string); + + while (found_pos) { + match_count++; + found_pos++; + found_pos = strstr(found_pos, input_old_string); + } + + buffer_length = EM_SAFE_STRLEN(source_string) + ((new_string_length - old_string_length) * match_count) + 50; + + result_buffer = (char*)malloc(buffer_length); + + if (!result_buffer) { + err = EMAIL_ERROR_OUT_OF_MEMORY; + goto FINISH_OFF; + } + memset(result_buffer, 0 , buffer_length); + + cursor_of_source_string = source_string; + cursor_of_result_buffer = result_buffer; + found_pos = strstr(source_string, input_old_string); + + while (found_pos) { + memcpy(cursor_of_result_buffer, cursor_of_source_string, found_pos - cursor_of_source_string); + + cursor_of_result_buffer = result_buffer + EM_SAFE_STRLEN(result_buffer); + cursor_of_source_string = found_pos + old_string_length; + + memcpy(cursor_of_result_buffer, input_new_string, new_string_length); + + cursor_of_result_buffer = result_buffer + EM_SAFE_STRLEN(result_buffer); + + found_pos++; + found_pos = strstr(found_pos, input_old_string); + } + + EM_SAFE_STRCAT(result_buffer, cursor_of_source_string); + + EM_SAFE_FREE(*input_source_string); + *input_source_string = result_buffer; + +FINISH_OFF: + + EM_DEBUG_FUNC_END("err[%d]", err); + return err; +} + + /* Memory clean up */ #include <sys/mman.h> @@ -410,7 +488,7 @@ INTERNAL_FUNC int em_get_file_name_and_extension_from_file_path(char *input_sour char file_name_string[MAX_PATH] = { 0, }; char extension_string[MAX_PATH] = { 0, }; - if (!input_source_file_path || !output_file_name || !output_extension) { + if (!input_source_file_path || !output_file_name || !output_extension || EM_SAFE_STRLEN(input_source_file_path) <= 0) { EM_DEBUG_EXCEPTION("Invalid Parameter"); err = EMAIL_ERROR_INVALID_PARAM; goto FINISH_OFF; @@ -467,10 +545,12 @@ INTERNAL_FUNC char *em_get_extension_from_file_path(char *source_file_path, int pos_on_string = EM_SAFE_STRLEN(source_file_path) - 1; - while(pos_on_string > 0 && source_file_path[pos_on_string--] != '.') ; + while(pos_on_string >= 0 && source_file_path[pos_on_string] != '.') { + pos_on_string--; + } - if(pos_on_string > 0) - extension = source_file_path + pos_on_string + 2; + if (pos_on_string >= 0 && pos_on_string < EM_SAFE_STRLEN(source_file_path) - 1) + extension = source_file_path + pos_on_string + 1; EM_DEBUG_LOG("*extension [%s] pos_on_string [%d]", extension, pos_on_string); @@ -481,6 +561,61 @@ FINISH_OFF: return extension; } +INTERNAL_FUNC char *em_shrink_filename(char *fname, int size_limit) +{ + EM_DEBUG_FUNC_BEGIN("fname[%s], size_limit[%d]", fname, size_limit); + + char *modified_name = NULL; + char *extension = NULL; + + modified_name = em_malloc(sizeof(char)*size_limit); + if (!modified_name) { + return NULL; + } + + extension = em_get_extension_from_file_path(fname, NULL); + + if (extension && EM_SAFE_STRLEN(extension) > 0) { + int ext_len = EM_SAFE_STRLEN(extension); + int name_len = EM_SAFE_STRLEN(fname) - EM_SAFE_STRLEN(extension) - 1; + int name_strip_len = size_limit - EM_SAFE_STRLEN(extension) - 2; + + char *tmp_ext = NULL; + char *tmp_name = NULL; + char *tmp_name_strip = NULL; + tmp_ext = em_malloc(sizeof(char)*(ext_len+1)); + tmp_name = em_malloc(sizeof(char)*(name_len+1)); + tmp_name_strip = em_malloc(sizeof(char)*name_strip_len); + + snprintf(tmp_ext, sizeof(char)*(ext_len+1), "%s", extension); + snprintf(tmp_name, sizeof(char)*(name_len+1), "%s", fname); + + EM_DEBUG_LOG(">>>>> extention [%s]", tmp_ext); + EM_DEBUG_LOG(">>>>> name [%s]", tmp_name); + + if (EM_SAFE_STRLEN(extension) > EM_SAFE_STRLEN(fname) - EM_SAFE_STRLEN(extension)) { + snprintf(modified_name, sizeof(char)*size_limit, "%s", fname); + } else { + if (tmp_name_strip && name_strip_len > 1) { + snprintf(tmp_name_strip, sizeof(char)*name_strip_len, "%s", tmp_name); + snprintf(modified_name, sizeof(char)*size_limit, "%s.%s", tmp_name_strip, tmp_ext); + } else { + snprintf(modified_name, sizeof(char)*size_limit, "%s", fname); + } + } + + EM_SAFE_FREE(tmp_ext); + EM_SAFE_FREE(tmp_name); + EM_SAFE_FREE(tmp_name_strip); + } else { + snprintf(modified_name, sizeof(char)*size_limit, "%s", fname); + } + + EM_DEBUG_FUNC_END(); + + return modified_name; +} + INTERNAL_FUNC int em_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); @@ -489,7 +624,6 @@ INTERNAL_FUNC int em_get_encoding_type_from_file_path(const char *input_file_pat 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) { @@ -500,7 +634,7 @@ INTERNAL_FUNC int em_get_encoding_type_from_file_path(const char *input_file_pat enf_of_string = pos_of_filename = EM_SAFE_STRLEN(input_file_path); - while(pos_of_filename >= 0 && input_file_path[pos_of_filename--] != '/') { + while(pos_of_filename > 0 && input_file_path[pos_of_filename--] != '/') { if(input_file_path[pos_of_filename] == '.') pos_of_dot = pos_of_filename; } @@ -508,16 +642,12 @@ INTERNAL_FUNC int em_get_encoding_type_from_file_path(const char *input_file_pat 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_malloc(sizeof(char) * (result_string_length + 1))) ) { + if( !(result_encoding_type = em_malloc(sizeof(char) * (result_string_length + 1))) ) { EM_DEBUG_EXCEPTION("EMAIL_ERROR_OUT_OF_MEMORY"); err = EMAIL_ERROR_OUT_OF_MEMORY; goto FINISH_OFF; @@ -525,7 +655,7 @@ INTERNAL_FUNC int em_get_encoding_type_from_file_path(const char *input_file_pat memcpy(result_encoding_type, input_file_path + pos_of_filename, result_string_length); - EM_DEBUG_LOG("*result_encoding_type [%s]", result_encoding_type); + EM_DEBUG_LOG("result_encoding_type [%s]", result_encoding_type); *output_encoding_type = result_encoding_type; @@ -538,7 +668,7 @@ INTERNAL_FUNC int em_get_content_type_from_extension_string(const char *extensio { EM_DEBUG_FUNC_BEGIN("extension_string[%s]", extension_string); int i = 0, err = EMAIL_ERROR_NONE, result_content_type = TYPEAPPLICATION; - char *image_extension[] = { "jpeg", "jpg", "png", "gif", "bmp", "pic", "agif", "tif", "wbmp" , "p7s", "p7m", NULL}; + char *image_extension[] = { "jpeg", "jpg", "png", "gif", "bmp", "pic", "agif", "tif", "wbmp" , "p7s", "p7m", "asc", NULL}; if (!extension_string) { EM_DEBUG_EXCEPTION("Invalid Parameter"); @@ -572,6 +702,9 @@ INTERNAL_FUNC int em_get_content_type_from_extension_string(const char *extensio case EXTENSION_P7M: result_content_type = TYPEPKCS7_MIME; break; + case EXTENSION_ASC: + result_content_type = TYPEPGP; + break; default: break; } @@ -583,20 +716,28 @@ FINISH_OFF: return result_content_type; } -#define EMAIL_ACCOUNT_RGEX "([a-z0-9!#$%&'*+/=?^_`{|}~-]+.)*[a-z0-9!#$%&'*+/=?^_`{|}~-]+" -#define EMAIL_DOMAIN_RGEX "([a-z0-9!#$%&'*+/=?^_`{|}~-]+.)+[a-z0-9!#$%&'*+/=?^_`{|}~-]+" +#define EMAIL_ATOM "([^]()<>@,;:\\\".[\x20\x01-\x1f\x7f])+" // x20: space, +#define EMAIL_QTEXT "[^\"\\\x0d]" /* " \ CR */ +#define EMAIL_DTEXT "[^][\\\x0d]" /* [ ] \ CR */ +#define EMAIL_QUOTED_PAIR "([\\].)" // first char :\ second char : anything (.) +#define EMAIL_QUOTED_STRING "[\"](" EMAIL_QTEXT "|" EMAIL_QUOTED_PAIR ")*[\"]" +#define EMAIL_WORD "(" EMAIL_ATOM "|" EMAIL_QUOTED_STRING ")" +#define EMAIL_PHRASE "(" EMAIL_ATOM "|" EMAIL_QUOTED_STRING ")" -#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_DOMAIN_LITERAL "\\[(" EMAIL_DTEXT "|" EMAIL_QUOTED_PAIR ")*\\]" /* literal match for "[" and "]"*/ +#define EMAIL_SUB_DOMAIN "(" EMAIL_ATOM "|" EMAIL_DOMAIN_LITERAL ")" -#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:]]*$" +#define EMAIL_LOCAL_PART "(" EMAIL_WORD "(\\." EMAIL_WORD ")*)" +#define EMAIL_DOMAIN "(" EMAIL_SUB_DOMAIN "(\\." EMAIL_SUB_DOMAIN ")*)" +#define EMAIL_ADDR_SPEC "(" EMAIL_LOCAL_PART "@" EMAIL_DOMAIN ")" -INTERNAL_FUNC int em_verify_email_address(char *address, int without_bracket) +#define EMAIL_MAILBOX "("EMAIL_ADDR_SPEC "|" EMAIL_PHRASE "[[:space:]]*" "<" EMAIL_ADDR_SPEC ">|<" EMAIL_ADDR_SPEC ">)" +#define EMAIL_ADDRESS "^([:blank:]*" EMAIL_MAILBOX "[,;[:blank:]]*([,;][,;[:blank:]]*" EMAIL_MAILBOX "[,;[:blank:]]*)*)$" + + +static int em_verify_email_address_by_using_regex(char *address) { - EM_DEBUG_FUNC_BEGIN_SEC("address[%s] without_bracket[%d]", address, without_bracket); + EM_DEBUG_FUNC_BEGIN_SEC("address[%s]", address); /* this following code verfies the email alias string using reg. exp. */ regex_t alias_list_regex = {0}; @@ -610,10 +751,7 @@ INTERNAL_FUNC int em_verify_email_address(char *address, int without_bracket) return EMAIL_ERROR_INVALID_PARAM; } - if(without_bracket) - reg_rule = EMAIL_ALIAS_LIST_WITHOUT_BRACKET_RGEX; - else - reg_rule = EMAIL_ALIAS_LIST_RGEX; + reg_rule = EMAIL_ADDRESS; if (regcomp (&alias_list_regex, reg_rule, REG_ICASE | REG_EXTENDED) != 0) { EM_DEBUG_EXCEPTION("email alias regex unrecognized"); @@ -642,16 +780,152 @@ FINISH_OFF: return error; } -INTERNAL_FUNC int em_verify_email_address_of_mail_data (email_mail_data_t *mail_data, int without_bracket) +static int em_verify_email_address_without_regex(char *address) +{ + EM_DEBUG_FUNC_BEGIN_SEC("address[%s]", address); + char *local_address = NULL; + char *address_start = NULL; + char *cur = NULL; + char *local_part = NULL; + char *domain = NULL; + char *saveptr = NULL; + char currunt_char; + int address_length = 0; + int i = 0; + int error = EMAIL_ERROR_NONE; + int occur = 0; + + EM_DEBUG_LOG_SEC("address [%s]", address); + + if (address == NULL) { + EM_DEBUG_EXCEPTION("Invalid parameter"); + error = EMAIL_ERROR_INVALID_PARAM; + return error; + } + + local_address = strdup(address); + + address_start = local_address; + + while ((cur = strchr(address_start, '\"'))) { + address_start = cur + 1; + if (local_address >= cur - 1 || *(cur - 1) != '\\') + occur++; + } + + if (occur % 2) { + error = EMAIL_ERROR_INVALID_ADDRESS; + EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_ADDRESS"); + goto FINISH_OFF; + } + + if ((cur = strchr(address_start, '<'))) { + char *close_pos = NULL; + + address_start = cur + 1; + close_pos = address_start; + + while ((cur = strchr(close_pos, '>'))) { + close_pos = cur + 1; + } + + if (address_start == close_pos) { + error = EMAIL_ERROR_INVALID_ADDRESS; + EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_ADDRESS"); + goto FINISH_OFF; + } + + address_start[close_pos - 1 - address_start] = '\0'; + } + + EM_DEBUG_LOG_SEC("address_start [%s]", address_start); + + address_length = EM_SAFE_STRLEN(address_start); + + for (i = 0; i < address_length; i++) { + currunt_char = address_start[i]; + if (!isalpha(currunt_char) && !isdigit(currunt_char) && currunt_char != '_' && currunt_char != '.' && currunt_char != '@') { + error = EMAIL_ERROR_INVALID_ADDRESS; + EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_ADDRESS"); + goto FINISH_OFF; + } + } + + if (strstr(address_start, "..") || strstr(address_start, ".@") || strstr(address_start, "@.") || strstr(address_start, "._.")) { + error = EMAIL_ERROR_INVALID_ADDRESS; + EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_ADDRESS"); + goto FINISH_OFF; + } + + local_part = strtok_r(address_start, "@", &saveptr); + + EM_DEBUG_LOG("local_part [%s]", local_part); + + if (local_part == NULL || EM_SAFE_STRLEN(local_part) == 0) { + error = EMAIL_ERROR_INVALID_ADDRESS; + goto FINISH_OFF; + } + + domain = strtok_r(NULL, "@", &saveptr); + + EM_DEBUG_LOG("domain [%s]", domain); + + if (domain == NULL || EM_SAFE_STRLEN(domain) < 3) { + error = EMAIL_ERROR_INVALID_ADDRESS; + EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_ADDRESS"); + goto FINISH_OFF; + } + + if (strchr(domain, '.') == NULL) { + error = EMAIL_ERROR_INVALID_ADDRESS; + EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_ADDRESS"); + goto FINISH_OFF; + } + + if (!isalpha(local_part[0])) { + error = EMAIL_ERROR_INVALID_ADDRESS; + EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_ADDRESS"); + goto FINISH_OFF; + } + +FINISH_OFF: + EM_SAFE_FREE(local_address); + + EM_DEBUG_FUNC_END("error [%d]", error); + return error; +} + +INTERNAL_FUNC int em_verify_email_address(char *address) +{ + EM_DEBUG_FUNC_BEGIN("address[%p]", address); + int error = EMAIL_ERROR_NONE; + char *result_locale = NULL; + + setlocale(LC_ALL, ""); + + result_locale = setlocale(LC_ALL, NULL); + + EM_DEBUG_LOG("LC_ALL[%s]" , result_locale); + + if ( EM_SAFE_STRCMP(result_locale, "or_IN.UTF-8") == 0) + error = em_verify_email_address_without_regex(address); + else + error = em_verify_email_address_by_using_regex(address); + + EM_DEBUG_FUNC_END("error [%d]", error); + return error; +} + +INTERNAL_FUNC int em_verify_email_address_of_mail_data (email_mail_data_t *mail_data) { - EM_DEBUG_FUNC_BEGIN("mail_data[%p] without_bracket[%d]", mail_data, without_bracket); + EM_DEBUG_FUNC_BEGIN("mail_data[%p]", mail_data); 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 err = EMAIL_ERROR_NONE, i; /* check for email_address validation */ for (i = 0; i < 4; i++) { if (address_array[i] && address_array[i][0] != 0) { - err = em_verify_email_address (address_array[i] , without_bracket); + err = em_verify_email_address (address_array[i]); if (err != EMAIL_ERROR_NONE) { EM_DEBUG_EXCEPTION_SEC("em_verify_email_address error[%d] idx[%d] addr[%s]", err, i, address_array[i]); goto FINISH_OFF; @@ -663,16 +937,16 @@ FINISH_OFF: return err; } -INTERNAL_FUNC int em_verify_email_address_of_mail_tbl(emstorage_mail_tbl_t *input_mail_tbl, int input_without_bracket) +INTERNAL_FUNC int em_verify_email_address_of_mail_tbl(emstorage_mail_tbl_t *input_mail_tbl) { - EM_DEBUG_FUNC_BEGIN("input_mail_tbl[%p] input_without_bracket[%d]", input_mail_tbl, input_without_bracket); + EM_DEBUG_FUNC_BEGIN("input_mail_tbl[%p]", input_mail_tbl); char *address_array[4] = { input_mail_tbl->full_address_to, input_mail_tbl->full_address_cc, input_mail_tbl->full_address_bcc, input_mail_tbl->full_address_from}; int err = EMAIL_ERROR_NONE, i; /* check for email_address validation */ for (i = 0; i < 4; i++) { if (address_array[i] && address_array[i][0] != 0) { - if ((err = em_verify_email_address (address_array[i] , input_without_bracket)) != EMAIL_ERROR_NONE) { + if ((err = em_verify_email_address (address_array[i])) != EMAIL_ERROR_NONE) { EM_DEBUG_EXCEPTION_SEC("em_verify_email_address error[%d] idx[%d] addr[%s]", err, i, address_array[i]); goto FINISH_OFF; } @@ -703,7 +977,7 @@ INTERNAL_FUNC int em_find_tag_for_thread_view(char *subject, int *result) } em_upper_string(copy_of_subject); - EM_DEBUG_LOG("em_upper_string result : %s\n", copy_of_subject); + EM_DEBUG_LOG_SEC("em_upper_string result : %s\n", copy_of_subject); if (strstr(copy_of_subject, "RE:") == NULL) { if (strstr(copy_of_subject, "FWD:") == NULL) { @@ -744,21 +1018,21 @@ INTERNAL_FUNC int em_find_pos_stripped_subject_for_thread_view(char *subject, ch em_upper_string(copy_of_subject); curpos = copy_of_subject; - EM_DEBUG_LOG("em_upper_string result : %s", copy_of_subject); + while ((result = strstr(curpos, "RE:")) != NULL) { curpos = result + 3; - EM_DEBUG_LOG("RE result : %s", curpos); + EM_DEBUG_LOG_SEC("RE result : %s", curpos); } while ((result = strstr(curpos, "FWD:")) != NULL) { curpos = result + 4; - EM_DEBUG_LOG("FWD result : %s", curpos); + EM_DEBUG_LOG_SEC("FWD result : %s", curpos); } while ((result = strstr(curpos, "FW:")) != NULL) { curpos = result + 3; - EM_DEBUG_LOG("FW result : %s", curpos); + EM_DEBUG_LOG_SEC("FW result : %s", curpos); } while (curpos != NULL && *curpos == ' ') { @@ -772,9 +1046,6 @@ INTERNAL_FUNC int em_find_pos_stripped_subject_for_thread_view(char *subject, ch FINISH_OFF: EM_SAFE_FREE(copy_of_subject); - if (error_code == EMAIL_ERROR_NONE && stripped_subject) - EM_DEBUG_LOG("result[%s]", stripped_subject); - EM_DEBUG_FUNC_END("error_code[%d]", error_code); return error_code; } @@ -1049,7 +1320,7 @@ static void* worker_func (void* arg) do { /* running thread main function */ if (warg->thread_func) - (warg->thread_func) (warg->arg); + (warg->thread_func) (warg->arg); if (warg->destroy) (warg->destroy) (warg->arg); EM_SAFE_FREE (warg); @@ -1082,6 +1353,7 @@ void em_thread_run (email_thread_handle_t *thd_handle, void *(*thread_func)(void return; } worker_handle->thread_func = thread_func; + worker_handle->destroy = destroy; worker_handle->arg = arg; worker_handle->thd_handle = thd_handle; @@ -1089,7 +1361,7 @@ void em_thread_run (email_thread_handle_t *thd_handle, void *(*thread_func)(void /* adding task to queue */ if (thd_handle->running) { - g_queue_push_tail (thd_handle->q, worker_handle); + g_queue_push_tail (thd_handle->q, worker_handle); } else { thd_handle->running = 1; @@ -1110,4 +1382,75 @@ void em_thread_join (email_thread_handle_t *thd_handle) } } +INTERNAL_FUNC int em_fopen(const char *filename, const char *mode, FILE **fp) +{ + EM_DEBUG_FUNC_BEGIN("filename : [%s]", filename); + + int err = EMAIL_ERROR_NONE; + + if (!filename) { + EM_DEBUG_EXCEPTION("Invalid param"); + err = EMAIL_ERROR_INVALID_PARAM; + return err; + } + + FILE *temp_fp = NULL; + char errno_buf[ERRNO_BUF_SIZE] = {0}; + + temp_fp = fopen(filename, mode); + if (temp_fp == NULL) { + EM_DEBUG_EXCEPTION("fopen failed : [%s][%d]", EM_STRERROR(errno_buf), errno); + if (errno == EACCES || errno == EPERM) + err = EMAIL_ERROR_PERMISSION_DENIED; + else if (errno == ENOSPC) + err = EMAIL_ERROR_MAIL_MEMORY_FULL; + else + err = EMAIL_ERROR_SYSTEM_FAILURE; + } + + if (fp) + *fp = temp_fp; + else + if (temp_fp) fclose(temp_fp); + + EM_DEBUG_FUNC_END(); + return err; +} + +INTERNAL_FUNC int em_open(const char *filename, int oflags, mode_t mode, int *handle) +{ + EM_DEBUG_FUNC_BEGIN("filename : [%s]", filename); + int err = EMAIL_ERROR_NONE; + + if (!filename) { + EM_DEBUG_EXCEPTION("Invalid param"); + err = EMAIL_ERROR_INVALID_PARAM; + return err; + } + int temp_handle = -1; + char errno_buf[ERRNO_BUF_SIZE] = {0}; + + if (mode) + temp_handle = open(filename, oflags, mode); + else + temp_handle = open(filename, oflags); + + if (temp_handle < 0) { + EM_DEBUG_EXCEPTION("open failed : [%s][%d]", EM_STRERROR(errno_buf), errno); + if (errno == EACCES || errno == EPERM) + err = EMAIL_ERROR_PERMISSION_DENIED; + else if (errno == ENOSPC) + err = EMAIL_ERROR_MAIL_MEMORY_FULL; + else + err = EMAIL_ERROR_SYSTEM_FAILURE; + } + + if (handle) + *handle = temp_handle; + else + if (temp_handle >= 0) close(temp_handle); + + EM_DEBUG_FUNC_END(); + return err; +} diff --git a/email-common-use/include/email-debug-log.h b/email-common-use/include/email-debug-log.h index 21820d4..fe981c1 100755 --- a/email-common-use/include/email-debug-log.h +++ b/email-common-use/include/email-debug-log.h @@ -45,8 +45,9 @@ extern "C" #include <errno.h> #define __FEATURE_DEBUG_LOG__ -#define __FEATURE_LOG_FOR_LIFE_CYCLE_OF_FUNCTION__ -#define __FEATURE_LOG_FOR_DEBUG_LOG_DEV__ +/* #define __FEATURE_LOG_FOR_LIFE_CYCLE_OF_FUNCTION__ */ +/* #define __FEATURE_LOG_FOR_DEBUG_LOG_DEV__ */ +/* #define FEATURE_CORE_DEBUG */ #ifdef __FEATURE_DEBUG_LOG__ @@ -60,19 +61,9 @@ extern "C" #define EM_DEBUG_LOG(format, arg...) SLOGD(format, ##arg) #define EM_DEBUG_EXCEPTION(format, arg...) SLOGE("[EXCEPTION!] " format "\n", ##arg) -#ifdef _SECURE_LOG -#undef _SECURE_LOG -#endif - -#ifdef _SECURE_LOG #define EM_DEBUG_LOG_SEC(format, arg...) SECURE_SLOGD(format, ##arg) #define EM_DEBUG_EXCEPTION_SEC(format, arg...) SECURE_SLOGE("[EXCEPTION!] " format "\n", ##arg) #define EM_DEBUG_FUNC_BEGIN_SEC(format, arg...) EM_DEBUG_LOG_SEC("BEGIN - "format, ##arg) -#else -#define EM_DEBUG_LOG_SEC(format, arg...) SLOGD(format, ##arg) -#define EM_DEBUG_EXCEPTION_SEC(format, arg...) SLOGE("[EXCEPTION!] " format "\n", ##arg) -#define EM_DEBUG_FUNC_BEGIN_SEC(format, arg...) EM_DEBUG_LOG("BEGIN - "format, ##arg) -#endif #ifdef _DEBUG_MIME_PARSE_ #define EM_DEBUG_LOG_MIME(format, arg...) EM_DEBUG_LOG_SEC(format, ##arg) @@ -97,7 +88,7 @@ extern "C" #endif #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_DB_EXEC(eval, expr, X) if (eval) { EM_DEBUG_EXCEPTION X; expr;} else {;} #define EM_DEBUG_ERROR_FILE_PATH "/opt/usr/data/email/.email_data/.critical_error.log" #define EM_DEBUG_CRITICAL_EXCEPTION(format, arg...) \ @@ -203,16 +194,16 @@ extern "C" #define EM_NULL_CHECK_FOR_VOID(expr) \ {\ if (!expr) {\ - EM_DEBUG_EXCEPTION ("INVALID PARAM: "#expr" NULL ");\ + EM_DEBUG_LOG ("NULL_PARAM: ["#expr"]");\ return;\ }\ } -#define EM_IF_NULL_RETURN_VALUE(expr, val) \ +#define EM_IF_NULL_RETURN_VALUE(expr, ret) \ {\ if (!expr ) {\ - EM_DEBUG_EXCEPTION ("INVALID PARAM: "#expr" NULL ");\ - return val; \ + EM_DEBUG_LOG("NULL_PARAM: ["#expr"]");\ + return ret; \ }\ } @@ -237,6 +228,17 @@ extern "C" }\ }) +#define EM_SAFE_CLOSE(fd) \ + ({\ + int err = 0;\ + if (fd >=0) {\ + err = close (fd);\ + if (err < 0)\ + EM_DEBUG_EXCEPTION ("close errno [%d]", errno);\ + fd = 0;\ + }\ + }) + #define EM_SAFE_STRDUP(s) \ ({\ char* _s = (char*)s;\ diff --git a/email-common-use/include/email-errors.h b/email-common-use/include/email-errors.h index 2a5247e..73a71b1 100755 --- a/email-common-use/include/email-errors.h +++ b/email-common-use/include/email-errors.h @@ -23,196 +23,214 @@ #ifndef __EMAIL_ERRORS_H__ #define __EMAIL_ERRORS_H__ +#include <tizen_error.h> +/** + * @file email-errors.h + */ + +/** + * @internal + * @addtogroup EMAIL_SERVICE_FRAMEWORK + * @{ + */ + /*****************************************************************************/ /* Errors */ /*****************************************************************************/ -#define EMAIL_ERROR_NONE 1 /* There is no error */ +#define EMAIL_ERROR_NONE 1 /**< There is no error */ /* Error codes for invalid input */ -#define EMAIL_ERROR_INVALID_PARAM -1001 /* invalid parameter was given. - Invalid input parameter */ -#define EMAIL_ERROR_INVALID_ACCOUNT -1002 /* invalid account information was given. - Unsupported account */ -#define EMAIL_ERROR_INVALID_SERVER -1005 /* invalid server information was given. - Server unavailable */ -#define EMAIL_ERROR_INVALID_MAIL -1006 /* invalid mail information was given */ -#define EMAIL_ERROR_INVALID_ADDRESS -1007 /* invalid address information was given. - Incorrect address */ -#define EMAIL_ERROR_INVALID_ATTACHMENT -1008 /* invalid attachment information was given */ -#define EMAIL_ERROR_INVALID_MAILBOX -1009 /* invalid mailbox information was given */ -#define EMAIL_ERROR_INVALID_FILTER -1010 /* invalid filter information was given */ -#define EMAIL_ERROR_INVALID_DATA -1012 /* invalid data */ -#define EMAIL_ERROR_INVALID_RESPONSE -1013 /* unexpected network response was given. - Invalid server response */ -#define EMAIL_ERROR_NO_RECIPIENT -1062 /* no recipients information was found */ -#define EMAIL_ERROR_INVALID_FILE_PATH -4101 /* invalid file path was given */ -#define EMAIL_ERROR_INVALID_REFERENCE_MAIL -4102 /* invalid reference mail was given */ +#define EMAIL_ERROR_INVALID_PARAM -1001 /**< Invalid parameter was given. - Invalid input parameter */ +#define EMAIL_ERROR_INVALID_ACCOUNT -1002 /**< Invalid account information was given. - Unsupported account */ +#define EMAIL_ERROR_INVALID_SERVER -1005 /**< Invalid server information was given. - Server unavailable */ +#define EMAIL_ERROR_INVALID_MAIL -1006 /**< Invalid mail information was given */ +#define EMAIL_ERROR_INVALID_ADDRESS -1007 /**< Invalid address information was given. - Incorrect address */ +#define EMAIL_ERROR_INVALID_ATTACHMENT -1008 /**< Invalid attachment information was given */ +#define EMAIL_ERROR_INVALID_MAILBOX -1009 /**< Invalid mailbox information was given */ +#define EMAIL_ERROR_INVALID_FILTER -1010 /**< Invalid filter information was given */ +#define EMAIL_ERROR_INVALID_DATA -1012 /**< Invalid data */ +#define EMAIL_ERROR_INVALID_RESPONSE -1013 /**< Unexpected network response was given. - Invalid server response */ +#define EMAIL_ERROR_NO_RECIPIENT -1062 /**< No recipients information was found */ +#define EMAIL_ERROR_INVALID_FILE_PATH -4101 /**< Invalid file path was given */ +#define EMAIL_ERROR_INVALID_REFERENCE_MAIL -4102 /**< Invalid reference mail was given */ /* Error codes for missing data */ -#define EMAIL_ERROR_ACCOUNT_NOT_FOUND -1014 /* no matched account was found */ -#define EMAIL_ERROR_MAIL_NOT_FOUND -1015 /* no matched mail was found */ -#define EMAIL_ERROR_MAILBOX_NOT_FOUND -1016 /* no matched mailbox was found */ -#define EMAIL_ERROR_ATTACHMENT_NOT_FOUND -1017 /* no matched attachment was found */ -#define EMAIL_ERROR_FILTER_NOT_FOUND -1018 /* no matched filter was found */ -#define EMAIL_ERROR_CONTACT_NOT_FOUND -1019 /* no matched contact was found */ -#define EMAIL_ERROR_FILE_NOT_FOUND -1020 /* no matched file was found */ -#define EMAIL_ERROR_DATA_NOT_FOUND -1021 /* no matched data was found */ -#define EMAIL_ERROR_TASK_BINDER_NOT_FOUND -1023 /* no matched task binder was found */ -#define EMAIL_ERROR_TASK_NOT_FOUND -1168 /* no matched task was found */ -#define EMAIL_ERROR_HANDLE_NOT_FOUND -1301 -#define EMAIL_ERROR_ALARM_DATA_NOT_FOUND -1933 +#define EMAIL_ERROR_ACCOUNT_NOT_FOUND -1014 /**< No matched account was found */ +#define EMAIL_ERROR_MAIL_NOT_FOUND -1015 /**< No matched mail was found */ +#define EMAIL_ERROR_MAILBOX_NOT_FOUND -1016 /**< No matched mailbox was found */ +#define EMAIL_ERROR_ATTACHMENT_NOT_FOUND -1017 /**< No matched attachment was found */ +#define EMAIL_ERROR_FILTER_NOT_FOUND -1018 /**< No matched filter was found */ +#define EMAIL_ERROR_CONTACT_NOT_FOUND -1019 /**< No matched contact was found */ +#define EMAIL_ERROR_FILE_NOT_FOUND -1020 /**< No matched file was found */ +#define EMAIL_ERROR_DATA_NOT_FOUND -1021 /**< No matched data was found */ +#define EMAIL_ERROR_TASK_BINDER_NOT_FOUND -1023 /**< No matched task binder was found */ +#define EMAIL_ERROR_TASK_NOT_FOUND -1168 /**< No matched task was found */ +#define EMAIL_ERROR_HANDLE_NOT_FOUND -1169 /**< No matched handle was found */ +#define EMAIL_ERROR_ALARM_DATA_NOT_FOUND -1933 /**< No matched alarm data was found */ /* Error codes for specification for maximum data */ -#define EMAIL_ERROR_NO_MORE_DATA -1022 /* No more data available */ -#define EMAIL_ERROR_MAX_EXCEEDED -1024 /* Can't handle more data */ -#define EMAIL_ERROR_OUT_OF_MEMORY -1028 /* There is not enough memory */ -#define EMAIL_ERROR_ACCOUNT_MAX_COUNT -1053 /* There is too many account */ -#define EMAIL_ERROR_MAIL_MEMORY_FULL -1054 /* There is no more storage */ -#define EMAIL_ERROR_DATA_TOO_LONG -1025 /* Data is too long */ -#define EMAIL_ERROR_MAXIMUM_DEVICES_LIMIT_REACHED -1530 /* EAS - Maximum devices limit reached */ +#define EMAIL_ERROR_NO_MORE_DATA -1022 /**< No more data available */ +#define EMAIL_ERROR_MAX_EXCEEDED -1024 /**< Cannot handle more data */ +#define EMAIL_ERROR_OUT_OF_MEMORY -1028 /**< There is not enough memory */ +#define EMAIL_ERROR_ACCOUNT_MAX_COUNT -1053 /**< There is too many account */ +#define EMAIL_ERROR_MAIL_MEMORY_FULL -1054 /**< There is no more storage */ +#define EMAIL_ERROR_DATA_TOO_LONG -1025 /**< Data is too long */ +#define EMAIL_ERROR_MAXIMUM_DEVICES_LIMIT_REACHED -1530 /**< EAS - Maximum devices limit reached */ /* Error codes for storage */ -#define EMAIL_ERROR_DB_FAILURE -1029 /* database operation failed */ -#define EMAIL_ERROR_SECURED_STORAGE_FAILURE -2100 /* Error from secured storage */ -#define EMAIL_ERROR_GCONF_FAILURE -1058 /* The error occurred on accessing Gconf */ -#define EMAIL_ERROR_FILE -1059 /* file related error */ +#define EMAIL_ERROR_DB_FAILURE -1029 /**< Database operation failed */ +#define EMAIL_ERROR_SECURED_STORAGE_FAILURE -2100 /**< Error from secured storage */ +#define EMAIL_ERROR_GCONF_FAILURE -1058 /**< The error occurred on accessing Gconf */ +#define EMAIL_ERROR_FILE -1059 /**< File related error */ /* Error codes for network */ -#define EMAIL_ERROR_SOCKET_FAILURE -1031 /* socket operation failed */ -#define EMAIL_ERROR_CONNECTION_FAILURE -1032 /* network connection failed */ -#define EMAIL_ERROR_CONNECTION_BROKEN -1033 /* network connection was broken */ -#define EMAIL_ERROR_NO_SUCH_HOST -1059 /* no such host was found */ -#define EMAIL_ERROR_NETWORK_NOT_AVAILABLE -1800 /* WIFI not available*/ +#define EMAIL_ERROR_SOCKET_FAILURE -1031 /**< Socket operation failed */ +#define EMAIL_ERROR_CONNECTION_FAILURE -1032 /**< Network connection failed */ +#define EMAIL_ERROR_CONNECTION_BROKEN -1033 /**< Network connection was broken */ +#define EMAIL_ERROR_NO_SUCH_HOST -1802 /**< No such host was found */ +#define EMAIL_ERROR_NETWORK_NOT_AVAILABLE -1800 /**< WIFI not available*/ #define EMAIL_ERROR_INVALID_STREAM -1068 +#define EMAIL_ERROR_FLIGHT_MODE_ENABLE -1801 /**< Flight mode enable : network not available */ /* Error codes for SSL/TLS */ -#define EMAIL_ERROR_STARTLS -1401 /* "STARTLS" */ -#define EMAIL_ERROR_TLS_NOT_SUPPORTED -1040 /* The server doesn't support TLS */ -#define EMAIL_ERROR_TLS_SSL_FAILURE -1041 /* The agent failed TLS/SSL */ -#define EMAIL_ERROR_CANNOT_NEGOTIATE_TLS -1400 /* "Cannot negotiate TLS" */ +#define EMAIL_ERROR_STARTLS -1401 /**< "STARTLS" */ +#define EMAIL_ERROR_TLS_NOT_SUPPORTED -1040 /**< The server doesn't support TLS */ +#define EMAIL_ERROR_TLS_SSL_FAILURE -1041 /**< The agent failed TLS/SSL */ +#define EMAIL_ERROR_CANNOT_NEGOTIATE_TLS -1400 /**< "Cannot negotiate TLS" */ -#define EMAIL_ERROR_NO_RESPONSE -1036 /* There is no server response */ +#define EMAIL_ERROR_NO_RESPONSE -1036 /**< There is no server response */ /* Error codes for authentication */ -#define EMAIL_ERROR_AUTH_NOT_SUPPORTED -1038 /* The server doesn't support authentication */ -#define EMAIL_ERROR_AUTHENTICATE -1039 /* The server failed to authenticate user */ -#define EMAIL_ERROR_AUTH_REQUIRED -1069 /* SMTP Authentication needed */ -#define EMAIL_ERROR_LOGIN_FAILURE -1035 /* login failed */ -#define EMAIL_ERROR_LOGIN_ALLOWED_EVERY_15_MINS -1600 /* "login allowed only every 15 minutes" */ -#define EMAIL_ERROR_TOO_MANY_LOGIN_FAILURE -1601 /* "Too many login failure" */ -#define EMAIL_ERROR_XOAUTH_BAD_REQUEST -1602 /* "{"status":"400"..." */ -#define EMAIL_ERROR_XOAUTH_INVALID_UNAUTHORIZED -1603 /* "{"status":"401"..." */ -#define EMAIL_ERROR_XOAUTH_INVALID_GRANT -1604 /* "error" : "invalid_grant" */ +#define EMAIL_ERROR_AUTH_NOT_SUPPORTED -1038 /**< The server does not support authentication */ +#define EMAIL_ERROR_AUTHENTICATE -1039 /**< The server failed to authenticate user */ +#define EMAIL_ERROR_AUTH_REQUIRED -1069 /**< SMTP Authentication needed */ +#define EMAIL_ERROR_LOGIN_FAILURE -1035 /**< Login failed */ +#define EMAIL_ERROR_LOGIN_ALLOWED_EVERY_15_MINS -1600 /**< "login allowed only every 15 minutes" */ +#define EMAIL_ERROR_TOO_MANY_LOGIN_FAILURE -1601 /**< "Too many login failure" */ +#define EMAIL_ERROR_XOAUTH_BAD_REQUEST -1602 /**< "{"status":"400"..." */ +#define EMAIL_ERROR_XOAUTH_INVALID_UNAUTHORIZED -1603 /**< "{"status":"401"..." */ +#define EMAIL_ERROR_XOAUTH_INVALID_GRANT -1604 /**< "error" : "invalid_grant" */ /* Error codes for functionality */ -#define EMAIL_ERROR_NOT_IMPLEMENTED -1047 /* The function is not implemented yet*/ -#define EMAIL_ERROR_NOT_SUPPORTED -1048 /* The function is not supported */ -#define EMAIL_ERROR_SERVER_NOT_SUPPORT_FUNCTION -1823 +#define EMAIL_ERROR_NOT_IMPLEMENTED -1047 /**< The function is not implemented yet */ +#define EMAIL_ERROR_NOT_SUPPORTED TIZEN_ERROR_PERMISSION_DENIED /**< The function is not supported */ +#define EMAIL_ERROR_SERVER_NOT_SUPPORT_FUNCTION -1823 /**< The function is not supported in server */ /* Error codes for from system */ -#define EMAIL_ERROR_NO_SIM_INSERTED -1205 -#define EMAIL_ERROR_BADGE_API_FAILED -3004 +#define EMAIL_ERROR_NO_SIM_INSERTED -1205 /**< The SIM card did not insert */ +#define EMAIL_ERROR_BADGE_API_FAILED -3004 /**< The badge API returned false */ /* Error codes for event handling */ -#define EMAIL_ERROR_EVENT_QUEUE_FULL -1060 /* event queue is full */ -#define EMAIL_ERROR_EVENT_QUEUE_EMPTY -1061 /* event queue is empty */ -#define EMAIL_ERROR_SESSION_NOT_FOUND -1067 /* no matched session was found */ +#define EMAIL_ERROR_EVENT_QUEUE_FULL -1060 /**< Event queue is full */ +#define EMAIL_ERROR_EVENT_QUEUE_EMPTY -1061 /**< Event queue is empty */ +#define EMAIL_ERROR_SESSION_NOT_FOUND -1067 /**< No matched session was found */ #define EMAIL_ERROR_CANNOT_STOP_THREAD -2000 -#define EMAIL_ERROR_CANCELLED -1046 /* The job was canceled by user */ -#define EMAIL_NO_AVAILABLE_TASK_SLOT -2656 /* There is no available task slot */ +#define EMAIL_ERROR_CANCELLED -1046 /**< The job was canceled by user */ +#define EMAIL_NO_AVAILABLE_TASK_SLOT -2656 /**< There is no available task slot */ /* Error codes for IPC*/ -#define EMAIL_ERROR_IPC_CRASH -1500 -#define EMAIL_ERROR_IPC_CONNECTION_FAILURE -1501 -#define EMAIL_ERROR_IPC_SOCKET_FAILURE -1502 -#define EMAIL_ERROR_IPC_PROTOCOL_FAILURE -1503 -#define EMAIL_ERROR_IPC_ALREADY_INITIALIZED -1504 -#define EMAIL_ERROR_ACTIVE_SYNC_NOTI_FAILURE -1300 +#define EMAIL_ERROR_IPC_CRASH -1500 /**< The IPC connection is broken */ +#define EMAIL_ERROR_IPC_CONNECTION_FAILURE -1501 /**< The server(daemon) and client(app) did not connet */ +#define EMAIL_ERROR_IPC_SOCKET_FAILURE -1502 /**< The IPC socket failed read and write */ +#define EMAIL_ERROR_IPC_PROTOCOL_FAILURE -1503 /**< The IPC protocol failed */ +#define EMAIL_ERROR_IPC_ALREADY_INITIALIZED -1504 /**< The IPC already is initialized */ +#define EMAIL_ERROR_ACTIVE_SYNC_NOTI_FAILURE -1300 /**< The active sync noti failed */ /* Error codes for error from server */ -#define EMAIL_ERROR_COMMAND_NOT_SUPPORTED -1043 /* The server doesn't support this command */ -#define EMAIL_ERROR_ANNONYM_NOT_SUPPORTED -1044 /* The server doesn't support anonymous user */ -#define EMAIL_ERROR_SCAN_NOT_SUPPORTED -1037 /* The server doesn't support 'scan mailbox' */ - -#define EMAIL_ERROR_SMTP_SEND_FAILURE -1063 /* SMTP send failed */ -#define EMAIL_ERROR_SMTP_SEND_FAILURE_BY_OVERSIZE -1073 /* SMTP send failed by too large mail size*/ - -#define EMAIL_ERROR_POP3_DELE_FAILURE -1100 /* Failed to run the command 'Dele' on POP server */ -#define EMAIL_ERROR_POP3_UIDL_FAILURE -1101 /* Failed to run the command 'Uidl' on POP server */ -#define EMAIL_ERROR_POP3_LIST_FAILURE -1102 /* Failed to run the command 'List' on POP server */ - -#define EMAIL_ERROR_IMAP4_APPEND_FAILURE -1042 /* Failed to run the command 'Append' on IMAP server */ -#define EMAIL_ERROR_IMAP4_STORE_FAILURE -1200 /* Failed to run the command 'Store' on IMAP server */ -#define EMAIL_ERROR_IMAP4_EXPUNGE_FAILURE -1201 /* Failed to run the command 'Expunge' on IMAP server */ -#define EMAIL_ERROR_IMAP4_FETCH_UID_FAILURE -1202 /* Failed to run the command 'Fetch UID' on IMAP server */ -#define EMAIL_ERROR_IMAP4_FETCH_SIZE_FAILURE -1203 /* Failed to run the command 'Fetch SIZE' on IMAP server */ -#define EMAIL_ERROR_IMAP4_IDLE_FAILURE -1204 /* Failed to run the command 'Idle' on IMAP server */ -#define EMAIL_ERROR_IMAP4_CREATE_FAILURE -1210 /* Failed to run the command 'Create' on IMAP server */ -#define EMAIL_ERROR_IMAP4_DELETE_FAILURE -1211 /* Failed to run the command 'Delete' on IMAP server */ -#define EMAIL_ERROR_IMAP4_RENAME_FAILURE -1212 /* Failed to run the command 'Rename' on IMAP server */ - -#define EMAIL_ERROR_INVALID_ATTACHMENT_SAVE_NAME -1301 - -#define EMAIL_ERROR_DOMAIN_LOOKUP_FAILED -1423 /* The domain name provided was not found */ +#define EMAIL_ERROR_COMMAND_NOT_SUPPORTED -1043 /**< The server does not support this command */ +#define EMAIL_ERROR_ANNONYM_NOT_SUPPORTED -1044 /**< The server does not support anonymous user */ +#define EMAIL_ERROR_SCAN_NOT_SUPPORTED -1037 /**< The server does not support 'scan mailbox' */ + +#define EMAIL_ERROR_SMTP_SEND_FAILURE -1063 /**< SMTP send failed */ +#define EMAIL_ERROR_SMTP_SEND_FAILURE_BY_OVERSIZE -1073 /**< SMTP send failed by too large mail size*/ + +#define EMAIL_ERROR_POP3_DELE_FAILURE -1100 /**< Failed to run the command 'Dele' on POP server */ +#define EMAIL_ERROR_POP3_UIDL_FAILURE -1101 /**< Failed to run the command 'Uidl' on POP server */ +#define EMAIL_ERROR_POP3_LIST_FAILURE -1102 /**< Failed to run the command 'List' on POP server */ +#define EMAIL_ERROR_POP3_NOOP_FAILURE -1103 /**< Failed to run the command 'NOOP' on POP server */ + +#define EMAIL_ERROR_IMAP4_APPEND_FAILURE -1042 /**< Failed to run the command 'Append' on IMAP server */ +#define EMAIL_ERROR_IMAP4_STORE_FAILURE -1200 /**< Failed to run the command 'Store' on IMAP server */ +#define EMAIL_ERROR_IMAP4_EXPUNGE_FAILURE -1201 /**< Failed to run the command 'Expunge' on IMAP server */ +#define EMAIL_ERROR_IMAP4_FETCH_UID_FAILURE -1202 /**< Failed to run the command 'Fetch UID' on IMAP server */ +#define EMAIL_ERROR_IMAP4_FETCH_SIZE_FAILURE -1203 /**< Failed to run the command 'Fetch SIZE' on IMAP server */ +#define EMAIL_ERROR_IMAP4_IDLE_FAILURE -1204 /**< Failed to run the command 'Idle' on IMAP server */ +#define EMAIL_ERROR_IMAP4_CREATE_FAILURE -1210 /**< Failed to run the command 'Create' on IMAP server */ +#define EMAIL_ERROR_IMAP4_DELETE_FAILURE -1211 /**< Failed to run the command 'Delete' on IMAP server */ +#define EMAIL_ERROR_IMAP4_RENAME_FAILURE -1212 /**< Failed to run the command 'Rename' on IMAP server */ +#define EMAIL_ERROR_IMAP4_COPY_FAILURE -1213 /**< Failed to run the command 'Copy' on IMAP server */ +#define EMAIL_ERROR_IMAP4_NOOP_FAILURE -1214 /**< Failed to run the command 'NOOP' on IMAP server */ + +#define EMAIL_ERROR_INVALID_ATTACHMENT_SAVE_NAME -1301 /**< Invalid attachment save name */ + +#define EMAIL_ERROR_DOMAIN_LOOKUP_FAILED -1423 /**< The domain name provided was not found */ /* Error codes for certificate */ -#define EMAIL_ERROR_LOAD_CERTIFICATE_FAILURE -3001 /* Cannot load the certificate */ -#define EMAIL_ERROR_INVALID_CERTIFICATE -3002 /* invalid certificate */ -#define EMAIL_ERROR_DECRYPT_FAILED -3003 /* Cannot decipher the encrypt mail */ -#define EMAIL_ERROR_CERTIFICATE_FAILURE -1045 /* certificate failure - Invalid server certificate */ +#define EMAIL_ERROR_LOAD_CERTIFICATE_FAILURE -3001 /**< Cannot load the certificate */ +#define EMAIL_ERROR_INVALID_CERTIFICATE -3002 /**< Invalid certificate */ +#define EMAIL_ERROR_DECRYPT_FAILED -3003 /**< Cannot decipher the encrypt mail */ +#define EMAIL_ERROR_CERTIFICATE_FAILURE -1045 /**< Certificate failure - Invalid server certificate */ /* Error codes for account */ -#define EMAIL_ERROR_ACCOUNT_IS_QUARANTINED -5001 -#define EMAIL_ERROR_ACCOUNT_IS_BLOCKED -5002 -#define EMAIL_ERROR_ACCOUNT_SYNC_IS_DISALBED -5003 +#define EMAIL_ERROR_ACCOUNT_IS_QUARANTINED -5001 /**< Account is quarantined */ +#define EMAIL_ERROR_ACCOUNT_IS_BLOCKED -5002 /**< Account is blocked */ +#define EMAIL_ERROR_ACCOUNT_SYNC_IS_DISALBED -5003 /**< Account sync is disabled */ /* Error codes for mails */ -#define EMAIL_ERROR_MAIL_NOT_FOUND_ON_SERVER -1055 /* The expected mail is not found in server */ -#define EMAIL_ERROR_MAIL_IS_NOT_DOWNLOADED -1095 /* The mail is not downloaded */ -#define EMAIL_ERROR_MAIL_IS_ALREADY_DOWNLOADED -1456 /* The mail is already downloaded */ +#define EMAIL_ERROR_MAIL_NOT_FOUND_ON_SERVER -1055 /**< The expected mail is not found in server */ +#define EMAIL_ERROR_MAIL_IS_NOT_DOWNLOADED -1095 /**< The mail is not downloaded */ +#define EMAIL_ERROR_MAIL_IS_ALREADY_DOWNLOADED -1456 /**< The mail is already downloaded */ /* Error codes for attachment */ -#define EMAIL_ERROR_ATTACHMENT_SIZE_EXCEED_POLICY_LIMIT -7001 +#define EMAIL_ERROR_ATTACHMENT_SIZE_EXCEED_POLICY_LIMIT -7001 /**< The attachment size is exceeded the policy value */ /* Error codes for Other Module */ -#define EMAIL_ERROR_MDM_SERVICE_FAILURE -7100 -#define EMAIL_ERROR_MDM_RESTRICTED_MODE -7101 -#define EMAIL_ERROR_NOTI -7110 +#define EMAIL_ERROR_MDM_SERVICE_FAILURE -7100 /**< The MDM service did not work */ +#define EMAIL_ERROR_MDM_RESTRICTED_MODE -7101 /**< The MDM service is in restricted mode */ +#define EMAIL_ERROR_NOTI -7110 /**< The Notification API returned the error */ /* Etc */ -#define EMAIL_ERROR_ALREADY_INITIALIZED -7321 -#define EMAIL_ERROR_NOT_INITIALIZED -7322 -#define EMAIL_ERROR_UNKNOWN -8000 /* unknown error */ +#define EMAIL_ERROR_ALREADY_INITIALIZED -7321 /**< The thread is already intialized */ +#define EMAIL_ERROR_NOT_INITIALIZED -7322 /**< The thread is not intialized */ +#define EMAIL_ERROR_UNKNOWN -8000 /**< Unknown error */ /* Should be replaced with proper name */ -#define EMAIL_ERROR_LOAD_ENGINE_FAILURE -1056 /* loading engine failed */ -#define EMAIL_ERROR_CLOSE_FAILURE -1057 /* engine is still used */ -#define EMAIL_ERROR_NULL_VALUE -1302 -#define EMAIL_ERROR_EMPTY_FILE -1304 +#define EMAIL_ERROR_LOAD_ENGINE_FAILURE -1056 /**< Loading engine failed */ +#define EMAIL_ERROR_CLOSE_FAILURE -1057 /**< Engine is still used */ +#define EMAIL_ERROR_NULL_VALUE -1302 /**< The value is null */ +#define EMAIL_ERROR_EMPTY_FILE -1304 /**< The file did not exist */ /* Should be classified */ -#define EMAIL_ERROR_SYSTEM_FAILURE -1050 /* There is a system error */ -#define EMAIL_ERROR_ON_PARSING -1700 -#define EMAIL_ERROR_ALREADY_EXISTS -1023 /* data duplicated */ -#define EMAIL_ERROR_INPROPER_RESPONSE_FROM_MSG_SERVICE -1323 +#define EMAIL_ERROR_SYSTEM_FAILURE -1050 /**< There is a system error */ +#define EMAIL_ERROR_ON_PARSING -1700 /**< MIME parsering is failed */ +#define EMAIL_ERROR_ALREADY_EXISTS -1322 /**< Data duplicated */ +#define EMAIL_ERROR_INPROPER_RESPONSE_FROM_MSG_SERVICE -1323 /**< Returned the error from msg server */ /* smack */ -#define EMAIL_ERROR_NO_SMACK_RULE -1710 /* No smack rule exist for file access */ -#define EMAIL_ERROR_PERMISSION_DENIED -1720 /* Failed to check privilege */ +#define EMAIL_ERROR_NO_SMACK_RULE -1710 /**< No smack rule exist for file access */ +#define EMAIL_ERROR_PERMISSION_DENIED TIZEN_ERROR_PERMISSION_DENIED /**< Failed to check privilege */ /* Not used */ -#define EMAIL_ERROR_INVALID_USER -1003 /* invalid user ID was given. - Invalid user or password */ -#define EMAIL_ERROR_INVALID_PASSWORD -1004 /* invalid password was given. - Invalid user or password */ -#define EMAIL_ERROR_INVALID_PATH -1011 /* invalid flle path was given */ -#define EMAIL_ERROR_MAIL_MAX_COUNT -1052 /* The mailbox is full */ -#define EMAIL_ERROR_DATA_TOO_SMALL -1026 /* Data is too small */ -#define EMAIL_ERROR_PROFILE_FAILURE -1030 /* no proper profile was found */ -#define EMAIL_ERROR_NO_MMC_INSERTED -1209 -#define EMAIL_ERROR_VALIDATE_ACCOUNT -1208 -#define EMAIL_ERROR_VALIDATE_ACCOUNT_OF_SMTP -1215 -#define EMAIL_ERROR_NETWORK_TOO_BUSY -1027 /* Network is busy */ -#define EMAIL_ERROR_DISCONNECTED -1034 /* connection was disconnected */ -#define EMAIL_ERROR_MAIL_LOCKED -1049 /* The mail was locked */ -#define EMAIL_ERROR_RETRIEVE_HEADER_DATA_FAILURE -1065 /* retrieving header failed */ -#define EMAIL_ERROR_MAILBOX_OPEN_FAILURE -1064 /* accessing mailbox failed */ -#define EMAIL_ERROR_XML_PARSER_FAILURE -1066 /* XML parsing failed */ -#define EMAIL_ERROR_FAILED_BY_SECURITY_POLICY -1303 -#define EMAIL_ERROR_FLIGHT_MODE -1206 - +#define EMAIL_ERROR_INVALID_USER -1003 /**< Invalid user ID was given. - Invalid user or password */ +#define EMAIL_ERROR_INVALID_PASSWORD -1004 /**< Invalid password was given. - Invalid user or password */ +#define EMAIL_ERROR_INVALID_PATH -1011 /**< Invalid flle path was given */ +#define EMAIL_ERROR_MAIL_MAX_COUNT -1052 /**< The mailbox is full */ +#define EMAIL_ERROR_DATA_TOO_SMALL -1026 /**< Data is too small */ +#define EMAIL_ERROR_PROFILE_FAILURE -1030 /**< No proper profile was found */ +#define EMAIL_ERROR_NO_MMC_INSERTED -1209 /**< The MMC card did not exist */ +#define EMAIL_ERROR_VALIDATE_ACCOUNT -1208 /**< Account validation failed */ +#define EMAIL_ERROR_VALIDATE_ACCOUNT_OF_SMTP -1215 /**< Account validation of SMTP failed */ +#define EMAIL_ERROR_NETWORK_TOO_BUSY -1027 /**< Network is busy */ +#define EMAIL_ERROR_DISCONNECTED -1034 /**< Connection was disconnected */ +#define EMAIL_ERROR_MAIL_LOCKED -1049 /**< The mail was locked */ +#define EMAIL_ERROR_RETRIEVE_HEADER_DATA_FAILURE -1065 /**< Retrieving header failed */ +#define EMAIL_ERROR_MAILBOX_OPEN_FAILURE -1064 /**< Accessing mailbox failed */ +#define EMAIL_ERROR_XML_PARSER_FAILURE -1066 /**< XML parsing failed */ +#define EMAIL_ERROR_FAILED_BY_SECURITY_POLICY -1303 /**< Failed by security policy */ +#define EMAIL_ERROR_FLIGHT_MODE -1206 /**< The network is flight mode */ + + /** + * @} + */ #endif /* __EMAIL_ERRORS_H__ */ diff --git a/email-common-use/include/email-internal-types.h b/email-common-use/include/email-internal-types.h index dc2c43f..d78097c 100755 --- a/email-common-use/include/email-internal-types.h +++ b/email-common-use/include/email-internal-types.h @@ -49,9 +49,8 @@ extern "C" #define __FEATURE_USING_ACCOUNT_SVC_FOR_SYNC_STATUS__ #define __FEATURE_BACKUP_ACCOUNT__ #define __FEATURE_MOVE_TO_OUTBOX_FIRST__ -/* #define __FEATURE_PARTIAL_BODY_FOR_POP3__*/ +#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__ @@ -67,22 +66,29 @@ extern "C" #define __FEATURE_SUPPORT_SYNC_STATE_ON_NOTI_BAR__ #define __FEATURE_SUPPORT_VALIDATION_SYSTEM__ #define __FEATURE_PROGRESS_IN_OUTBOX__ -#define __FEATURE_OMA_EMN__ + /* #define __FEATURE_USE_SHARED_MUTEX_FOR_PROTECTED_FUNC_CALL__ */ -/* #define __FEATURE_IMAP_IDLE__ */ +#define __FEATURE_IMAP_IDLE__ #define __FEATURE_DRIVING_MODE__ #define __FEATURE_DELETE_MAILBOX_RECURSIVELY__ #define __FEATURE_RENAME_MAILBOX_RECURSIVELY__ #define __FEATURE_AUTO_RETRY_SEND__ -/* #define __FEATURE_SMTP_VALIDATION__ */ -/* #define FEATURE_CORE_DEBUG */ -/* #define FEATURE_USE_GMIME */ -/* #define __FEATURE_BLOCKING_MODE__ */ +#define __FEATURE_SMTP_VALIDATION__ +#define __FEATURE_USE_GMIME__ +#define __FEATURE_WIFI_AUTO_DOWNLOAD__ + +#define __FEATURE_BLOCKING_MODE__ #define __FEATURE_BODY_SEARCH__ -/* #define __FEATURE_USE_APPSYNC__ */ -/* #define __FEATURE_ACCESS_CONTROL__ */ -/* #define __FEATURE_IMAP_QUOTA__ */ +#define __FEATURE_ACCESS_CONTROL__ +#define __FEATURE_UPDATE_DB_TABLE_SCHEMA__ +#define __FEATURE_OPEN_SSL_MULTIHREAD_HANDLE__ +/* #define __FEATURE_COMPARE_DOMAIN__ */ +/* #define __FEATURE_FORK_FOR_CURL__ */ +/* #define __FEATURE_USE_DRM_API__ */ +#define __FEATURE_SECURE_PGP__ +#define __FEATURE_SYNC_STATUS__ +/* #define __FEATURE_IMAP_QUOTA__ */ /* ----------------------------------------------------------------------------- */ /* Macro */ @@ -90,7 +96,7 @@ extern "C" #define NULL (char *)0 #endif -#define SESSION_MAX 10 +#define SESSION_MAX 50 #define IMAP_2004_LOG 1 #define TEXT_SIZE 161 #define MAILBOX_COUNT 6 @@ -106,6 +112,7 @@ extern "C" #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 MAX_FILENAME 255 #define DATETIME_LENGTH 16 #define MAIL_ID_STRING_LENGTH 10 #define MAILBOX_ID_STRING_LENGTH 10 @@ -136,7 +143,7 @@ extern "C" #define ACCOUNT_PASSWORD_SS_GROUP_ID "secure-storage::email-service" -#define NATIVE_EMAIL_APPLICATION_PKG "com.samsung.email" +#define NATIVE_EMAIL_APPLICATION_PKG "org.tizen.email" #define NATIVE_EMAIL_DOMAIN "email" #define IMAP_ID_OS "TIZEN" @@ -167,8 +174,6 @@ extern "C" #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 (!emcore_check_thread_status()) { err = EMAIL_ERROR_CANCELLED; goto FINISH_OFF; } -#define CHECK_JOB_CANCELED() {if (!emcore_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...) \ @@ -217,7 +222,7 @@ typedef pthread_t thread_t; #define VCONF_KEY_DEFAULT_ACCOUNT_ID "db/private/email-service/default_account_id" #define VCONF_KEY_NOTI_PRIVATE_ID "db/private/email-service/noti_private_id" -#define VCONF_KEY_TOPMOST_WINDOW "db/private/com.samsung.email/is_topmost_window" +#define VCONF_KEY_TOPMOST_WINDOW "db/private/org.tizen.email/is_topmost_window" #define OUTMODE "wb" #define INMODE "rb" @@ -226,6 +231,7 @@ typedef pthread_t thread_t; #define TYPEPKCS7_SIGN 10 #define TYPEPKCS7_MIME 11 +#define TYPEPGP 12 #define INLINE_ATTACHMENT 1 #define ATTACHMENT 2 @@ -295,14 +301,16 @@ enum EXTENSION_TIF = 7, EXTENSION_WBMP = 8, EXTENSION_P7S = 9, - EXTENSION_P7M = 10 + EXTENSION_P7M = 10, + EXTENSION_ASC = 11 }; typedef enum { EMAIL_ALARM_CLASS_SCHEDULED_SENDING = 1, EMAIL_ALARM_CLASS_NEW_MAIL_ALERT = 2, EMAIL_ALARM_CLASS_AUTO_POLLING = 3, - EMAIL_ALARM_CLASS_AUTO_RESEND = 4 + EMAIL_ALARM_CLASS_AUTO_RESEND = 4, + EMAIL_ALARM_CLASS_IMAP_IDLE = 5, } email_alarm_class_t; @@ -339,15 +347,11 @@ struct email_search_key_t email_search_key_t *next; }; -typedef struct -{ - int tid; - email_protocol_type_t protocol; - void *stream; +/* the type is used to get uw-imap-toolkit error with thread local storage */ +typedef struct { int auth; int network; int error; - int status; } email_session_t; typedef struct @@ -393,7 +397,7 @@ typedef struct } email_mail_contact_info_t; /* global account list */ -typedef struct email_account_list { +typedef struct email_account_list { email_account_t *account; struct email_account_list *next; } email_account_list_t; @@ -404,6 +408,14 @@ typedef struct { thread_t thread_id; } email_active_task_t; +typedef struct emcore_uid_elem { + int msgno; + char *uid; + char *internaldate; + email_mail_flag_t flag; + struct emcore_uid_elem *next; +} emcore_uid_list; + typedef void (*email_event_callback)(int total, int done, int status, int account_id, int mail_id, int handle, void *user_data, int error); /* ----------------------------------------------------------------------------- */ @@ -430,6 +442,15 @@ typedef struct } email_event_partial_body_thd; #endif /* __FEATURE_PARTIAL_BODY_DOWNLOAD__ */ +typedef enum +{ + EMAIL_ALERT_TYPE_MELODY, + EMAIL_ALERT_TYPE_VIB, + EMAIL_ALERT_TYPE_MELODY_AND_VIB, + EMAIL_ALERT_TYPE_MUTE, + EMAIL_ALERT_TYPE_NONE, +} EMAIL_ALERT_TYPE; + #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/email-common-use/include/email-types.h b/email-common-use/include/email-types.h index 0ffecde..e0b7af2 100755 --- a/email-common-use/include/email-types.h +++ b/email-common-use/include/email-types.h @@ -24,25 +24,17 @@ #define __EMAIL_TYPES_H__ /** -* @defgroup EMAIL_SERVICE Email Service -* @{ -*/ + * @internal + * @file email-types.h + * @brief This file is the header file of Email Framework library. + */ /** -* @ingroup EMAIL_SERVICE -* @defgroup EMAIL_TYPES Email Types -* @{ -*/ -/** - * This file defines structures and enums of Email Framework. - * @file email-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. + * @internal + * @addtogroup EMAIL_SERVICE_FRAMEWORK + * @{ */ - #ifdef __cplusplus extern "C" { @@ -61,7 +53,7 @@ extern "C" #define MAX_EMAIL_ADDRESS_LENGTH 254 /* RFC5322, RFC3696 */ #define MAX_USER_NAME_LENGTH 64 #define MAX_DATETIME_STRING_LENGTH 20 -#define MAX_PREVIEW_TEXT_LENGTH 512 +#define MAX_PREVIEW_TEXT_LENGTH 1000 #define STRING_LENGTH_FOR_DISPLAY 100 #define MEETING_REQ_OBJECT_ID_LENGTH 256 #define EMAIL_NO_LIMITED_RETRY_COUNT -1 @@ -78,43 +70,122 @@ extern "C" #define EMAIL_SUCCESS 0 /* we need to modify the success return value */ -#define EMAIL_ACC_GET_OPT_DEFAULT 0x01 /**< Default values without account name */ -#define EMAIL_ACC_GET_OPT_ACCOUNT_NAME 0x02 /**< Account name */ -#define EMAIL_ACC_GET_OPT_PASSWORD 0x04 /**< With password */ -#define EMAIL_ACC_GET_OPT_OPTIONS 0x08 /**< Account options : email_option_t */ -#define EMAIL_ACC_GET_OPT_FULL_DATA 0xFF /**< With all data of account */ +/** @brief Definition for default values without account name. + * @since_tizen 2.3 */ +#define EMAIL_ACC_GET_OPT_DEFAULT 0x01 + +/** @brief Definition for account name. + * @since_tizen 2.3 */ +#define EMAIL_ACC_GET_OPT_ACCOUNT_NAME 0x02 + +/** @brief Definition for account with password. + * @since_tizen 2.3 */ +#define EMAIL_ACC_GET_OPT_PASSWORD 0x04 + +/** @brief Definition for account with options: #email_option_t. + * @since_tizen 2.3 */ +#define EMAIL_ACC_GET_OPT_OPTIONS 0x08 + +/** @brief Definition for account with all data of account. + * @since_tizen 2.3 */ +#define EMAIL_ACC_GET_OPT_FULL_DATA 0xFF + #define GET_FULL_DATA (EMAIL_ACC_GET_OPT_FULL_DATA) #define GET_FULL_DATA_WITHOUT_PASSWORD (EMAIL_ACC_GET_OPT_DEFAULT | EMAIL_ACC_GET_OPT_ACCOUNT_NAME | EMAIL_ACC_GET_OPT_OPTIONS ) #define WITHOUT_OPTION (EMAIL_ACC_GET_OPT_DEFAULT | EMAIL_ACC_GET_OPT_ACCOUNT_NAME ) #define ONLY_OPTION (EMAIL_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 EMAIL_IMAP_PORT 143 /**< Specifies the default IMAP port.*/ -#define EMAIL_POP3_PORT 110 /**< Specifies the default POP3 port.*/ -#define EMAIL_SMTP_PORT 25 /**< Specifies the default SMTP port.*/ -#define EMAIL_IMAPS_PORT 993 /**< Specifies the default IMAP SSL port.*/ -#define EMAIL_POP3S_PORT 995 /**< Specifies the default POP3 SSL port.*/ -#define EMAIL_SMTPS_PORT 465 /**< Specifies the default SMTP SSL port.*/ -#define EMAIL_ACCOUNT_MAX 10 /**< Specifies the MAX account.*/ - -#define EMAIL_INBOX_NAME "INBOX" /**< Specifies the name of inbox.*/ -#define EMAIL_DRAFTBOX_NAME "DRAFTBOX" /**< Specifies the name of draftbox.*/ -#define EMAIL_OUTBOX_NAME "OUTBOX" /**< Specifies the name of outbox.*/ -#define EMAIL_SENTBOX_NAME "SENTBOX" /**< Specifies the name of sentbox.*/ -#define EMAIL_TRASH_NAME "TRASH" /**< Specifies the name of trash.*/ -#define EMAIL_SPAMBOX_NAME "SPAMBOX" /**< Specifies the name of spambox.*/ - -#define EMAIL_INBOX_DISPLAY_NAME "Inbox" /**< Specifies the display name of inbox.*/ -#define EMAIL_DRAFTBOX_DISPLAY_NAME "Draftbox" /**< Specifies the display name of draftbox.*/ -#define EMAIL_OUTBOX_DISPLAY_NAME "Outbox" /**< Specifies the display name of outbox.*/ -#define EMAIL_SENTBOX_DISPLAY_NAME "Sentbox" /**< Specifies the display name of sentbox.*/ -#define EMAIL_TRASH_DISPLAY_NAME "Trash" /**< Specifies the display name of sentbox.*/ -#define EMAIL_SPAMBOX_DISPLAY_NAME "Spambox" /**< Specifies the display name of spambox.*/ - -#define EMAIL_SEARCH_RESULT_MAILBOX_NAME "_`S1!E2@A3#R4$C5^H6&R7*E8(S9)U0-L=T_" /**< Specifies the name of search result mailbox.*/ + +/** @brief Definition for the function 'email_activate_pdp'. + * @since_tizen 2.3 */ +#define THREAD_TYPE_RECEIVING 0 + +/** @brief Definition for the function 'email_activate_pdp'. + * @since_tizen 2.3 */ +#define THREAD_TYPE_SENDING 1 + + +/** @brief Definition for the default IMAP port. + * @since_tizen 2.3 */ +#define EMAIL_IMAP_PORT 143 + +/** @brief Definition for the default POP3 port. + * @since_tizen 2.3 */ +#define EMAIL_POP3_PORT 110 + +/** @brief Definition for the default SMTP port. + * @since_tizen 2.3 */ +#define EMAIL_SMTP_PORT 25 + +/** @brief Definition for the default IMAP SSL port. + * @since_tizen 2.3 */ +#define EMAIL_IMAPS_PORT 993 + +/** @brief Definition for the default POP3 SSL port. + * @since_tizen 2.3 */ +#define EMAIL_POP3S_PORT 995 + +/** @brief Definition for the default SMTP SSL port. + * @since_tizen 2.3 */ +#define EMAIL_SMTPS_PORT 465 + +/** @brief Definition for the MAX account. + * @since_tizen 2.3 */ +#define EMAIL_ACCOUNT_MAX 10 + +/** @brief Definition for the name of inbox. + * @since_tizen 2.3 */ +#define EMAIL_INBOX_NAME "INBOX" + +/** @brief Definition for the name of draftbox. + * @since_tizen 2.3 */ +#define EMAIL_DRAFTBOX_NAME "DRAFTBOX" + +/** @brief Definition for the name of outbox. + * @since_tizen 2.3 */ +#define EMAIL_OUTBOX_NAME "OUTBOX" + +/** @brief Definition for the name of sentbox. + * @since_tizen 2.3 */ +#define EMAIL_SENTBOX_NAME "SENTBOX" + +/** @brief Definition for the name of trash. + * @since_tizen 2.3 */ +#define EMAIL_TRASH_NAME "TRASH" + +/** @brief Definition for the name of spambox. + * @since_tizen 2.3 */ +#define EMAIL_SPAMBOX_NAME "SPAMBOX" + +/** @brief Definition for the display name of inbox. + * @since_tizen 2.3 */ +#define EMAIL_INBOX_DISPLAY_NAME "Inbox" + +/** @brief Definition for the display name of draftbox. + * @since_tizen 2.3 */ +#define EMAIL_DRAFTBOX_DISPLAY_NAME "Draftbox" + +/** @brief Definition for the display name of outbox. + * @since_tizen 2.3 */ +#define EMAIL_OUTBOX_DISPLAY_NAME "Outbox" + +/** @brief Definition for the display name of sentbox. + * @since_tizen 2.3 */ +#define EMAIL_SENTBOX_DISPLAY_NAME "Sentbox" + +/** @brief Definition for the display name of trash. + * @since_tizen 2.3 */ +#define EMAIL_TRASH_DISPLAY_NAME "Trash" + +/** @brief Definition for the display name of spambox. + * @since_tizen 2.3 */ +#define EMAIL_SPAMBOX_DISPLAY_NAME "Spambox" + + +/** @brief Definition for the name of search result mailbox. + * @since_tizen 2.3 */ +#define EMAIL_SEARCH_RESULT_MAILBOX_NAME "_`S1!E2@A3#R4$C5^H6&R7*E8(S9)U0-L=T_" #define SYNC_STATUS_FINISHED 0 /* BIN 00000000 */ #define SYNC_STATUS_SYNCING 1 /* BIN 00000001 */ @@ -162,1031 +233,1154 @@ extern "C" /*****************************************************************************/ 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, - _EMAIL_API_VALIDATE_ACCOUNT_EX = 0x0100000D, - - /* Mail */ - _EMAIL_API_DELETE_MAIL = 0x01100002, - _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_MAIL_EXTRA_FLAG = 0x01100011, - _EMAIL_API_SET_FLAGS_FIELD = 0x01100016, - _EMAIL_API_ADD_MAIL = 0x01100017, - _EMAIL_API_UPDATE_MAIL = 0x01100018, - _EMAIL_API_ADD_READ_RECEIPT = 0x01100019, - _EMAIL_API_EXPUNGE_MAILS_DELETED_FLAGGED = 0x0110001A, - - /* 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_SET_MAIL_SLOT_SIZE = 0x01200007, - _EMAIL_API_RENAME_MAILBOX = 0x01200008, - _EMAIL_API_RENAME_MAILBOX_EX = 0x0120000B, - _EMAIL_API_SET_MAILBOX_TYPE = 0x01200009, - _EMAIL_API_SET_LOCAL_MAILBOX = 0x0120000A, - - /* Network */ - _EMAIL_API_SEND_MAIL = 0x01300000, - _EMAIL_API_SYNC_HEADER = 0x01300001, - _EMAIL_API_DOWNLOAD_BODY = 0x01300002, - _EMAIL_API_DOWNLOAD_ATTACHMENT = 0x01300003, - _EMAIL_API_SEND_SAVED = 0x01300005, - _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_SEARCH_MAIL_ON_SERVER = 0x01300019, - _EMAIL_API_CLEAR_RESULT_OF_SEARCH_MAIL_ON_SERVER = 0x0130001A, - _EMAIL_API_QUERY_SMTP_MAIL_SIZE_LIMIT = 0x0130001B, - - /* 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_APPLY_RULE = 0x01400006, - _EMAIL_API_CANCEL_JOB = 0x01400007, - _EMAIL_API_SEND_RETRY = 0x01400009, - _EMAIL_API_UPDATE_ACTIVITY = 0x0140000A, - _EMAIL_API_SYNC_LOCAL_ACTIVITY = 0x0140000B, - - /* Etc */ - _EMAIL_API_PING_SERVICE = 0x01500000, - _EMAIL_API_UPDATE_NOTIFICATION_BAR_FOR_UNREAD_MAIL = 0x01500001, - _EMAIL_API_SHOW_USER_MESSAGE = 0x01500002, - _EMAIL_API_WRITE_MIME_FILE = 0x01500003, - _EMAIL_API_GET_TASK_INFORMATION = 0x01500004, - - /* Smime */ - _EMAIL_API_ADD_CERTIFICATE = 0x01600000, - _EMAIL_API_DELETE_CERTIFICATE = 0x01600001, - _EMAIL_API_VERIFY_SIGNATURE = 0x01600002, - _EMAIL_API_VERIFY_CERTIFICATE = 0x01600003, + /* Account */ + _EMAIL_API_ADD_ACCOUNT = 0x01000000, /**< IPC API ID for email_add_account */ + _EMAIL_API_DELETE_ACCOUNT = 0x01000001, /**< IPC API ID for email_delete_account */ + _EMAIL_API_UPDATE_ACCOUNT = 0x01000002, /**< IPC API ID for email_update_account */ + _EMAIL_API_GET_ACCOUNT = 0x01000003, /**< IPC API ID for email_get_account */ + _EMAIL_API_GET_ACCOUNT_LIST = 0x01000005, /**< IPC API ID for email_get_account_list */ + _EMAIL_API_GET_MAILBOX_COUNT = 0x01000007, /**< IPC API ID for email_get_mailbox_count */ + _EMAIL_API_VALIDATE_ACCOUNT = 0x01000008, /**< IPC API ID for email_validate_account */ + _EMAIL_API_ADD_ACCOUNT_WITH_VALIDATION = 0x01000009, /**< IPC API ID for email_add_account_with_validation */ + _EMAIL_API_BACKUP_ACCOUNTS = 0x0100000A, /**< IPC API ID for email_backup_accounts */ + _EMAIL_API_RESTORE_ACCOUNTS = 0x0100000B, /**< IPC API ID for email_restore_accounts */ + _EMAIL_API_GET_PASSWORD_LENGTH_OF_ACCOUNT = 0x0100000C, /**< IPC API ID for email_get_password_legnth_of_account */ + _EMAIL_API_VALIDATE_ACCOUNT_EX = 0x0100000D, /**< IPC API ID for email_validate_account_ex */ + + /* Mail */ + _EMAIL_API_DELETE_MAIL = 0x01100002, /**< IPC API ID for email_delete_mail */ + _EMAIL_API_DELETE_ALL_MAIL = 0x01100004, /**< IPC API ID for email_delete_mail_all */ + _EMAIL_API_GET_MAILBOX_LIST = 0x01100006, /**< IPC API ID for email_get_mailbox_list */ + _EMAIL_API_GET_SUBMAILBOX_LIST = 0x01100007, /**< IPC API ID for email_get_submailbox_list */ + _EMAIL_API_CLEAR_DATA = 0x01100009, /**< IPC API ID for email_clear_data */ + _EMAIL_API_MOVE_MAIL = 0x0110000A, /**< IPC API ID for email_move_mail */ + _EMAIL_API_MOVE_ALL_MAIL = 0x0110000B, /**< IPC API ID for email_move_all_mail */ + _EMAIL_API_ADD_ATTACHMENT = 0x0110000C, /**< IPC API ID for email_move_add_attachment */ + _EMAIL_API_GET_ATTACHMENT = 0x0110000D, /**< IPC API ID for email_get_attachment */ + _EMAIL_API_DELETE_ATTACHMENT = 0x0110000E, /**< IPC API ID for email_delete_attachment */ + _EMAIL_API_MODIFY_MAIL_FLAG = 0x0110000F, /**< IPC API ID for email_modify_mail_flag */ + _EMAIL_API_MODIFY_MAIL_EXTRA_FLAG = 0x01100011, /**< IPC API ID for email_modify_mail_extra_flag */ + _EMAIL_API_SET_FLAGS_FIELD = 0x01100016, /**< IPC API ID for email_set_flags_field */ + _EMAIL_API_ADD_MAIL = 0x01100017, /**< IPC API ID for email_add_mail */ + _EMAIL_API_UPDATE_MAIL = 0x01100018, /**< IPC API ID for email_update_mail */ + _EMAIL_API_ADD_READ_RECEIPT = 0x01100019, /**< IPC API ID for email_add_read_receipt */ + _EMAIL_API_EXPUNGE_MAILS_DELETED_FLAGGED = 0x0110001A, /**< IPC API ID for email_expunge_mails_deleted_flagged */ + + /* Thread */ + _EMAIL_API_MOVE_THREAD_TO_MAILBOX = 0x01110000, /**< IPC API ID for email_move_thread_to_mailbox */ + _EMAIL_API_DELETE_THREAD = 0x01110001, /**< IPC API ID for email_delete_thread */ + _EMAIL_API_MODIFY_SEEN_FLAG_OF_THREAD = 0x01110002, /**< IPC API ID for email_modify_seen_flag_of_thread */ + + /* Mailbox */ + _EMAIL_API_ADD_MAILBOX = 0x01200000, /**< IPC API ID for email_add_mailbox */ + _EMAIL_API_DELETE_MAILBOX = 0x01200001, /**< IPC API ID for email_delete mailbox */ + _EMAIL_API_SET_MAIL_SLOT_SIZE = 0x01200007, /**< IPC API ID for email_set_mail_slot_size */ + _EMAIL_API_RENAME_MAILBOX = 0x01200008, /**< IPC API ID for email_rename_mailbox */ + _EMAIL_API_RENAME_MAILBOX_EX = 0x0120000B, /**< IPC API ID for email_rename_mailbox_ex */ + _EMAIL_API_SET_MAILBOX_TYPE = 0x01200009, /**< IPC API ID for email_set_mailbox_type */ + _EMAIL_API_SET_LOCAL_MAILBOX = 0x0120000A, /**< IPC API ID for email_set_local_mailbox */ + + /* Network */ + _EMAIL_API_SEND_MAIL = 0x01300000, /**< IPC API ID for email_send_mail */ + _EMAIL_API_SYNC_HEADER = 0x01300001, /**< IPC API ID for email_sycn_header */ + _EMAIL_API_DOWNLOAD_BODY = 0x01300002, /**< IPC API ID for email_download_body */ + _EMAIL_API_DOWNLOAD_ATTACHMENT = 0x01300003, /**< IPC API ID for email_download_attachment */ + _EMAIL_API_SEND_SAVED = 0x01300005, /**< IPC API ID for email_send_saved */ + _EMAIL_API_DELETE_EMAIL = 0x01300007, /**< IPC API ID for email_delete_email */ + _EMAIL_API_DELETE_EMAIL_ALL = 0x01300008, /**< IPC API ID for email_delete_email_all */ + _EMAIL_API_GET_IMAP_MAILBOX_LIST = 0x01300015, /**< IPC API ID for email_get_imap_mailbox_list */ + _EMAIL_API_SEND_MAIL_CANCEL_JOB = 0x01300017, /**< IPC API ID for email_send_mail_cancel_job */ + _EMAIL_API_QUERY_SMTP_MAIL_SIZE_LIMIT = 0x0130001B, /**< IPC API ID for email_query_smtp_mail_size_limit */ + + /* Rule */ + _EMAIL_API_ADD_RULE = 0x01400000, /**< IPC API ID for email_add_rule */ + _EMAIL_API_GET_RULE = 0x01400001, /**< IPC API ID for email_get_rule */ + _EMAIL_API_GET_RULE_LIST = 0x01400002, /**< IPC API ID for email_get_rule_list */ + _EMAIL_API_FIND_RULE = 0x01400003, /**< IPC API ID for email_find_rule */ + _EMAIL_API_DELETE_RULE = 0x01400004, /**< IPC API ID for email_delete_rule */ + _EMAIL_API_UPDATE_RULE = 0x01400005, /**< IPC API ID for email_update_rule */ + _EMAIL_API_APPLY_RULE = 0x01400006, /**< IPC API ID for email_apply_rule */ + _EMAIL_API_CANCEL_JOB = 0x01400007, /**< IPC API ID for email_cancel_job */ + _EMAIL_API_SEND_RETRY = 0x01400009, /**< IPC API ID for email_send_retry */ + _EMAIL_API_UPDATE_ACTIVITY = 0x0140000A, /**< IPC API ID for email_update_activity */ + _EMAIL_API_SYNC_LOCAL_ACTIVITY = 0x0140000B, /**< IPC API ID for email_sync_local_activity */ + + /* Etc */ + _EMAIL_API_PING_SERVICE = 0x01500000, /**< IPC API ID for email_ping_service */ + _EMAIL_API_UPDATE_NOTIFICATION_BAR_FOR_UNREAD_MAIL = 0x01500001, /**< IPC API ID for email_update_notification_bar_for_unread_mail */ + _EMAIL_API_SHOW_USER_MESSAGE = 0x01500002, /**< IPC API ID for email_show_user_message */ + _EMAIL_API_WRITE_MIME_FILE = 0x01500003, /**< IPC API ID for email_write_mime_file */ + _EMAIL_API_GET_TASK_INFORMATION = 0x01500004, /**< IPC API ID for email_get_task_information */ + _EMAIL_API_CLEAR_NOTIFICATION_BAR = 0x01500005, + + /* Smime */ + _EMAIL_API_ADD_CERTIFICATE = 0x01600000, /**< IPC API ID for email_add_certificate */ + _EMAIL_API_DELETE_CERTIFICATE = 0x01600001, /**< IPC API ID for email_delete_certificate */ + _EMAIL_API_VERIFY_SIGNATURE = 0x01600002, /**< IPC API ID for email_verify_signature */ + _EMAIL_API_VERIFY_CERTIFICATE = 0x01600003, /**< IPC API ID for email_verify_certificate */ }; typedef enum { - EMAIL_DELETE_LOCALLY = 0, /**< Specifies Mail Delete local only */ - EMAIL_DELETE_LOCAL_AND_SERVER, /**< Specifies Mail Delete local & server */ - EMAIL_DELETE_FOR_SEND_THREAD, /**< Created to check which activity to delete in send thread */ - EMAIL_DELETE_FROM_SERVER, - EMAIL_DELETE_MAIL_AND_MEETING_FOR_EAS, /**< Delete mails and meetings on an EAS account. */ + EMAIL_DELETE_LOCALLY = 0, /**< Delete mail locally only */ + EMAIL_DELETE_LOCAL_AND_SERVER, /**< Delete mail locally and on server */ + EMAIL_DELETE_FOR_SEND_THREAD, /**< Check which activity to delete in send thread */ + EMAIL_DELETE_FROM_SERVER, /**< Delete mail on server */ + EMAIL_DELETE_MAIL_AND_MEETING_FOR_EAS, /**< Delete mails and meetings on an EAS account */ } email_delete_option_t; +/** + * @brief Enumeration for the notification of changes on storage. + * @since_tizen 2.3 + */ 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 = 40001, - NOTI_MAILBOX_UPDATE = 40002, - NOTI_MAILBOX_FIELD_UPDATE = 40003, - - NOTI_MAILBOX_RENAME = 40010, - NOTI_MAILBOX_RENAME_FAIL = 40011, - - NOTI_CERTIFICATE_ADD = 50000, - NOTI_CERTIFICATE_DELETE = 50001, - NOTI_CERTIFICATE_UPDATE = 50002, - /* To be added more */ + NOTI_MAIL_ADD = 10000, /**< A mail is added */ + NOTI_MAIL_DELETE = 10001, /**< Some mails are removed */ + NOTI_MAIL_DELETE_ALL = 10002, /**< All mails in mailbox are removed */ + NOTI_MAIL_DELETE_WITH_ACCOUNT = 10003, /**< All mails of an account removed */ + NOTI_MAIL_DELETE_FAIL = 10007, /**< Removing mails failed */ + NOTI_MAIL_DELETE_FINISH = 10008, /**< Removing mails finished */ + + NOTI_MAIL_UPDATE = 10004, /**< Some fields of mail are updated */ + NOTI_MAIL_FIELD_UPDATE = 10020, /**< A field of some mails is updated */ + + NOTI_MAIL_MOVE = 10005, /**< Some mail are moved */ + NOTI_MAIL_MOVE_FAIL = 10010, /**< Moving mails failed */ + NOTI_MAIL_MOVE_FINISH = 10006, /**< Moving mails finished */ + + NOTI_THREAD_MOVE = 11000, /**< A mail thread is moved */ + NOTI_THREAD_DELETE = 11001, /**< A mail thread is removed */ + NOTI_THREAD_MODIFY_SEEN_FLAG = 11002, /**< Seen flag of a mail thread is modified */ + NOTI_THREAD_ID_CHANGED_BY_ADD = 11003, /**< The thread ID is changed by adding a new mail */ + NOTI_THREAD_ID_CHANGED_BY_MOVE_OR_DELETE = 11004, /**< The thread ID is changed by moving or removing mails */ + + NOTI_ACCOUNT_ADD = 20000, /**< An account is added */ + NOTI_ACCOUNT_ADD_FINISH = 20005, /**< An account is added and account reference updated */ + NOTI_ACCOUNT_ADD_FAIL = 20007, /**< An account adding failed */ + NOTI_ACCOUNT_DELETE = 20001, /**< An account is removed */ + NOTI_ACCOUNT_DELETE_FAIL = 20003, /**< Removing an account failed */ + NOTI_ACCOUNT_UPDATE = 20002, /**< An account is updated */ + NOTI_ACCOUNT_UPDATE_SYNC_STATUS = 20010, /**< Sync status of an account is updated */ + + NOTI_MAILBOX_ADD = 40000, /**< A mailbox is added */ + NOTI_MAILBOX_DELETE = 40001, /**< A mailbox is removed */ + NOTI_MAILBOX_UPDATE = 40002, /**< A mailbox is updated */ + NOTI_MAILBOX_FIELD_UPDATE = 40003, /**< Some fields of a mailbox are updated */ + + NOTI_MAILBOX_RENAME = 40010, /**< A mailbox is renamed */ + NOTI_MAILBOX_RENAME_FAIL = 40011, /**< Renaming a mailbox failed */ + + NOTI_CERTIFICATE_ADD = 50000, /**< A certificate is added */ + NOTI_CERTIFICATE_DELETE = 50001, /**< A certificate is removed */ + NOTI_CERTIFICATE_UPDATE = 50002, /**< A certificate is updated */ + + NOTI_ACCOUNT_RESTORE_START = 60001, /**< Start of restoring accounts */ + NOTI_ACCOUNT_RESTORE_FINISH = 60002, /**< Finish of restoring accounts */ + NOTI_ACCOUNT_RESTORE_FAIL = 60003, /**< Failure of restoring accounts */ + + NOTI_RULE_ADD = 70000, /**< A rule is added in DB */ + NOTI_RULE_APPLY = 70001, /**< A rule is applied */ + NOTI_RULE_DELETE = 70002, /**< A rule is removed in DB */ + NOTI_RULE_UPDATE = 70003, /**< A rule is updated in DB */ + + /* To be added more */ } email_noti_on_storage_event; +/** + * @brief Enumeration for the notification of network event. + * @since_tizen 2.3 + */ 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_SEARCH_ON_SERVER_START = 6000, - NOTI_SEARCH_ON_SERVER_FINISH = 6001, - NOTI_SEARCH_ON_SERVER_FAIL = 6002, - NOTI_SEARCH_ON_SERVER_CANCEL = 6003, - - 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, - - NOTI_VALIDATE_CERTIFICATE_FINISH = 10000, - NOTI_VALIDATE_CERTIFICATE_FAIL = 10001, - NOTI_VALIDATE_CERTIFICATE_CANCEL = 10002, - - NOTI_RESOLVE_RECIPIENT_START = 11000, - NOTI_RESOLVE_RECIPIENT_FINISH, - NOTI_RESOLVE_RECIPIENT_FAIL, - NOTI_RESOLVE_RECIPIENT_CANCEL, - - NOTI_RENAME_MAILBOX_START = 12000, - NOTI_RENAME_MAILBOX_FINISH, - NOTI_RENAME_MAILBOX_FAIL, - NOTI_RENAME_MAILBOX_CANCEL, - - NOTI_ADD_MAILBOX_START = 12100, - NOTI_ADD_MAILBOX_FINISH, - NOTI_ADD_MAILBOX_FAIL, - NOTI_ADD_MAILBOX_CANCEL, - - NOTI_DELETE_MAILBOX_START = 12200, - NOTI_DELETE_MAILBOX_FINISH, - NOTI_DELETE_MAILBOX_FAIL, - NOTI_DELETE_MAILBOX_CANCEL, - - NOTI_SYNC_IMAP_MAILBOX_LIST_START = 12300, - NOTI_SYNC_IMAP_MAILBOX_LIST_FINISH, - NOTI_SYNC_IMAP_MAILBOX_LIST_FAIL, - NOTI_SYNC_IMAP_MAILBOX_LIST_CANCEL, - - NOTI_DELETE_MAIL_START = 12400, - NOTI_DELETE_MAIL_FINISH, - NOTI_DELETE_MAIL_FAIL, - NOTI_DELETE_MAIL_CANCEL, - - NOTI_QUERY_SMTP_MAIL_SIZE_LIMIT_FINISH = 12500, - NOTI_QUERY_SMTP_MAIL_SIZE_LIMIT_FAIL, - - /* To be added more */ + NOTI_SEND_START = 1002, /**< Sending a mail started */ + NOTI_SEND_FINISH = 1004, /**< Sending a mail finished */ + NOTI_SEND_FAIL = 1005, /**< Sending a mail failed */ + NOTI_SEND_CANCEL = 1003, /**< Sending a mail canceled */ + + NOTI_DOWNLOAD_START = 2000, /**< Syncing header started */ + NOTI_DOWNLOAD_FINISH, /**< Syncing header finished */ + NOTI_DOWNLOAD_FAIL, /**< Syncing header failed */ + NOTI_DOWNLOAD_CANCEL = 2004, /**< Syncing header canceled */ + NOTI_DOWNLOAD_NEW_MAIL = 2003, /**< Deprecated */ + + NOTI_DOWNLOAD_BODY_START = 3000, /**< Downloading mail body started */ + NOTI_DOWNLOAD_BODY_FINISH = 3002, /**< Downloading mail body finished */ + NOTI_DOWNLOAD_BODY_FAIL = 3004, /**< Downloading mail body failed */ + NOTI_DOWNLOAD_BODY_CANCEL = 3003, /**< Downloading mail body canceled */ + NOTI_DOWNLOAD_MULTIPART_BODY = 3001, /**< Downloading multipart body is in progress */ + + NOTI_DOWNLOAD_ATTACH_START = 4000, /**< Downloading attachment started */ + NOTI_DOWNLOAD_ATTACH_FINISH, /**< Downloading attachment finished */ + NOTI_DOWNLOAD_ATTACH_FAIL, /**< Downloading attachment failed */ + NOTI_DOWNLOAD_ATTACH_CANCEL, /**< Downloading attachment canceled */ + + NOTI_MAIL_DELETE_ON_SERVER_FAIL = 5000, /**< Deleting mails on server failed */ + NOTI_MAIL_MOVE_ON_SERVER_FAIL, /**< Moving mails on server failed */ + + NOTI_SEARCH_ON_SERVER_START = 6000, /**< Searching mails on server started */ + NOTI_SEARCH_ON_SERVER_FINISH = 6001, /**< Searching mails on server finished */ + NOTI_SEARCH_ON_SERVER_FAIL = 6002, /**< Searching mails on server failed */ + NOTI_SEARCH_ON_SERVER_CANCEL = 6003, /**< Searching mails on server canceled */ + + NOTI_VALIDATE_ACCOUNT_FINISH = 7000, /**< Validating an account finished */ + NOTI_VALIDATE_ACCOUNT_FAIL, /**< Validating an account failed */ + NOTI_VALIDATE_ACCOUNT_CANCEL, /**< Validating an account canceled */ + + NOTI_VALIDATE_AND_CREATE_ACCOUNT_FINISH = 8000, /**< Validating and creating an account finished */ + NOTI_VALIDATE_AND_CREATE_ACCOUNT_FAIL, /**< Validating and creating an account failed */ + NOTI_VALIDATE_AND_CREATE_ACCOUNT_CANCEL, /**< Validating and creating an account canceled */ + + NOTI_VALIDATE_AND_UPDATE_ACCOUNT_FINISH = 9000, /**< Validating and updating an account finished */ + NOTI_VALIDATE_AND_UPDATE_ACCOUNT_FAIL, /**< Validating and updating an account failed */ + NOTI_VALIDATE_AND_UPDATE_ACCOUNT_CANCEL, /**< Validating and updating an account canceled */ + + NOTI_VALIDATE_CERTIFICATE_FINISH = 10000, /**< Validating a certificate finished */ + NOTI_VALIDATE_CERTIFICATE_FAIL = 10001, /**< Validating a certificate failed */ + NOTI_VALIDATE_CERTIFICATE_CANCEL = 10002, /**< Validating a certificate canceled */ + + NOTI_RESOLVE_RECIPIENT_START = 11000, /**< Resolving recipients started */ + NOTI_RESOLVE_RECIPIENT_FINISH, /**< Resolving recipients finished */ + NOTI_RESOLVE_RECIPIENT_FAIL, /**< Resolving recipients failed */ + NOTI_RESOLVE_RECIPIENT_CANCEL, /**< Resolving recipients canceled */ + + NOTI_RENAME_MAILBOX_START = 12000, /**< Renaming a mailbox started */ + NOTI_RENAME_MAILBOX_FINISH, /**< Renaming a mailbox finished */ + NOTI_RENAME_MAILBOX_FAIL, /**< Renaming a mailbox failed */ + NOTI_RENAME_MAILBOX_CANCEL, /**< Renaming a mailbox canceled */ + + NOTI_ADD_MAILBOX_START = 12100, /**< Adding a mailbox started */ + NOTI_ADD_MAILBOX_FINISH, /**< Adding a mailbox finished */ + NOTI_ADD_MAILBOX_FAIL, /**< Adding a mailbox failed */ + NOTI_ADD_MAILBOX_CANCEL, /**< Adding a mailbox canceled */ + + NOTI_DELETE_MAILBOX_START = 12200, /**< Removing a mailbox started */ + NOTI_DELETE_MAILBOX_FINISH, /**< Removing a mailbox finished */ + NOTI_DELETE_MAILBOX_FAIL, /**< Removing a mailbox failed */ + NOTI_DELETE_MAILBOX_CANCEL, /**< Removing a mailbox canceled */ + + NOTI_SYNC_IMAP_MAILBOX_LIST_START = 12300, /**< Syncing mailbox list started */ + NOTI_SYNC_IMAP_MAILBOX_LIST_FINISH, /**< Syncing mailbox list finished */ + NOTI_SYNC_IMAP_MAILBOX_LIST_FAIL, /**< Syncing mailbox list failed */ + NOTI_SYNC_IMAP_MAILBOX_LIST_CANCEL, /**< Syncing mailbox list canceled */ + + NOTI_DELETE_MAIL_START = 12400, /**< Removing mails started */ + NOTI_DELETE_MAIL_FINISH, /**< Removing mails finished */ + NOTI_DELETE_MAIL_FAIL, /**< Removing mails failed */ + NOTI_DELETE_MAIL_CANCEL, /**< Removing mails canceled */ + + NOTI_QUERY_SMTP_MAIL_SIZE_LIMIT_FINISH = 12500, /**< Querying limitation of mail size to SMTP finished */ + NOTI_QUERY_SMTP_MAIL_SIZE_LIMIT_FAIL, /**< Querying limitation of mail size to SMTP failed */ + + /* To be added more */ } email_noti_on_network_event; +/** + * @brief Enumeration for the response to request. + * @since_tizen 2.3 + */ typedef enum { - RESPONSE_SUCCEEDED = 0, - RESPONSE_FAILED = 1, - RESPONSE_CANCELED = 2 - /* To be added more */ + RESPONSE_SUCCEEDED = 0, /**< The request succeeded */ + RESPONSE_FAILED = 1, /**< The request failed */ + RESPONSE_CANCELED = 2 /**< The request is canceled */ + /* To be added more */ } email_response_to_request; /** - * This enumeration specifies the mail type of account. + * @brief Enumeration for the account mail type. + * @since_tizen 2.3 */ typedef enum { - EMAIL_BIND_TYPE_DISABLE = 0, /**< Specifies the bind type for Disabled account.*/ - EMAIL_BIND_TYPE_EM_CORE = 1, /**< Specifies the bind type for email-service .*/ + EMAIL_BIND_TYPE_DISABLE = 0, /**< The bind type for Disabled account */ + EMAIL_BIND_TYPE_EM_CORE = 1, /**< The bind type for email-service */ } email_account_bind_t DEPRECATED; /** - * This enumeration specifies the server type of account. + * @brief Enumeration for the account server type. + * @since_tizen 2.3 */ typedef enum { - EMAIL_SERVER_TYPE_POP3 = 1, /**< Specifies the POP3 Server.*/ - EMAIL_SERVER_TYPE_IMAP4, /**< Specifies the IMAP4 Server.*/ - EMAIL_SERVER_TYPE_SMTP, /**< Specifies the SMTP Server.*/ - EMAIL_SERVER_TYPE_NONE, /**< Specifies the Local.*/ - EMAIL_SERVER_TYPE_ACTIVE_SYNC, /** < Specifies the Active Sync. */ + EMAIL_SERVER_TYPE_POP3 = 1, /**< The POP3 Server */ + EMAIL_SERVER_TYPE_IMAP4, /**< The IMAP4 Server */ + EMAIL_SERVER_TYPE_SMTP, /**< The SMTP Server */ + EMAIL_SERVER_TYPE_NONE, /**< The local account */ + EMAIL_SERVER_TYPE_ACTIVE_SYNC, /**< The Active Sync */ } email_account_server_t; /** - * This enumeration specifies the mode of retrieval. + * @brief Enumeration for the retrieval mode. + * @since_tizen 2.3 */ typedef enum { - EMAIL_IMAP4_RETRIEVAL_MODE_NEW = 0, /**< Specifies the retrieval mode for new email.*/ - EMAIL_IMAP4_RETRIEVAL_MODE_ALL, /**< Specifies the retrieval mode for all email.*/ + EMAIL_IMAP4_RETRIEVAL_MODE_NEW = 1, /**< Retrieval mode for new email */ + EMAIL_IMAP4_RETRIEVAL_MODE_ALL = 2, /**< Retrieval mode for all email */ + EMAIL_IMAP4_IDLE_SUPPORTED = 0x00100000 /**< Support for feature 'imap idle' */ } email_imap4_retrieval_mode_t; /** - * This enumeration specifies the filtering type. + * @brief Enumeration for the filtering type. + * @since_tizen 2.3 */ typedef enum { - EMAIL_FILTER_FROM = 1, /**< Specifies the filtering of sender.*/ - EMAIL_FILTER_SUBJECT = 2, /**< Specifies the filtering of email subject.*/ - EMAIL_FILTER_BODY = 4, /**< Specifies the filterinf of email body.*/ - EMAIL_PRIORITY_SENDER = 8, /**< Specifies the priority sender of email. */ + EMAIL_FILTER_FROM = 1, /**< Filtering of sender */ + EMAIL_FILTER_SUBJECT = 2, /**< Filtering of email subject */ + EMAIL_FILTER_BODY = 4, /**< Filtering of email body */ + EMAIL_PRIORITY_SENDER = 8, /**< Priority sender of email */ } email_rule_type_t; /** - * This enumeration specifies the rules for filtering type. + * @brief Enumeration for the rules for filtering type. + * @since_tizen 2.3 */ typedef enum { - RULE_TYPE_INCLUDES = 1, /**< Specifies the filtering rule for includes.*/ - RULE_TYPE_EXACTLY, /**< Specifies the filtering rule for Exactly same as.*/ + RULE_TYPE_INCLUDES = 1, /**< Filtering rule for includes */ + RULE_TYPE_EXACTLY, /**< Filtering rule for Exactly same as */ } email_filtering_type_t; /** - * This enumeration specifies the action for filtering type. + * @brief Enumeration for the action for filtering type. + * @since_tizen 2.3 */ typedef enum { - EMAIL_FILTER_MOVE = 1, /**< Specifies the move of email.*/ - EMAIL_FILTER_BLOCK = 2, /**< Specifies the block of email.*/ - EMAIL_FILTER_DELETE = 3, /**< Specifies delete email.*/ + EMAIL_FILTER_MOVE = 1, /**< Filter action is moving email */ + EMAIL_FILTER_BLOCK = 2, /**< Filtering action is blocking email */ + EMAIL_FILTER_DELETE = 3, /**< Filtering action is deleting email */ } email_rule_action_t; /** - * This enumeration specifies the email status. + * @brief Enumeration for the email status. + * @since_tizen 2.3 */ typedef enum { - EMAIL_MAIL_STATUS_NONE = 0, /**< The Mail is in No Operation state */ - EMAIL_MAIL_STATUS_RECEIVED, /**< The mail is a received mail.*/ - EMAIL_MAIL_STATUS_SENT, /**< The mail is a sent mail.*/ - EMAIL_MAIL_STATUS_SAVED, /**< The mail is a saved mail.*/ - EMAIL_MAIL_STATUS_SAVED_OFFLINE, /**< The mail is a saved mail in off-line mode.*/ - EMAIL_MAIL_STATUS_SENDING, /**< The mail is being sent.*/ - EMAIL_MAIL_STATUS_SEND_FAILURE, /**< The mail is a mail to been failed to send.*/ - EMAIL_MAIL_STATUS_SEND_CANCELED, /**< The mail is a canceled mail.*/ - EMAIL_MAIL_STATUS_SEND_WAIT, /**< The mail is a mail to be send .*/ - EMAIL_MAIL_STATUS_SEND_SCHEDULED, /**< The mail is a scheduled mail to be send later.*/ - EMAIL_MAIL_STATUS_SEND_DELAYED, /**< The mail is a delayed mail to be send later.*/ + EMAIL_MAIL_STATUS_NONE = 0, /**< The Mail is in No Operation state */ + EMAIL_MAIL_STATUS_RECEIVED, /**< The mail is a received mail */ + EMAIL_MAIL_STATUS_SENT, /**< The mail is a sent mail */ + EMAIL_MAIL_STATUS_SAVED, /**< The mail is a saved mail */ + EMAIL_MAIL_STATUS_SAVED_OFFLINE, /**< The mail is a saved mail in off-line mode */ + EMAIL_MAIL_STATUS_SENDING, /**< The mail is being sent */ + EMAIL_MAIL_STATUS_SEND_FAILURE, /**< The mail is a sending failed mail */ + EMAIL_MAIL_STATUS_SEND_CANCELED, /**< The mail is a canceled mail */ + EMAIL_MAIL_STATUS_SEND_WAIT, /**< The mail is waiting to be sent */ + EMAIL_MAIL_STATUS_SEND_SCHEDULED, /**< The mail is a scheduled mail to be sent later.*/ + EMAIL_MAIL_STATUS_SEND_DELAYED, /**< The mail is a delayed mail to be sent later */ + EMAIL_MAIL_STATUS_NOTI_WAITED, /**< The mail is a waited notification */ } email_mail_status_t; /** - * This enumeration specifies the email priority. + * @brief Enumeration for the email priority. + * @since_tizen 2.3 */ typedef enum { - EMAIL_MAIL_PRIORITY_HIGH = 1, /**< The priority is high.*/ - EMAIL_MAIL_PRIORITY_NORMAL = 3, /**< The priority is normal.*/ - EMAIL_MAIL_PRIORITY_LOW = 5, /**< The priority is low.*/ + EMAIL_MAIL_PRIORITY_HIGH = 1, /**< The priority is high */ + EMAIL_MAIL_PRIORITY_NORMAL = 3, /**< The priority is normal */ + EMAIL_MAIL_PRIORITY_LOW = 5, /**< The priority is low */ } email_mail_priority_t; /** - * This enumeration specifies the email status. + * @brief Enumeration for the email status. + * @since_tizen 2.3 */ typedef enum { - EMAIL_MAIL_REPORT_NONE = 0x00, /**< The mail isn't report mail.*/ - EMAIL_MAIL_REPORT_REQUEST = 0x03, /* Deprecated */ - EMAIL_MAIL_REPORT_DSN = 0x04, /**< The mail is a Delivery Status Notifications mail.*/ - EMAIL_MAIL_REPORT_MDN = 0x08, /**< The mail is a Message Disposition Notifications mail.*/ - EMAIL_MAIL_REQUEST_DSN = 0x10, /**< The mail requires Delivery Status Notifications.*/ - EMAIL_MAIL_REQUEST_MDN = 0x20, /**< The mail requires Message Disposition Notifications.*/ + EMAIL_MAIL_REPORT_NONE = 0x00, /**< The mail is not report mail */ + EMAIL_MAIL_REPORT_REQUEST = 0x03, /**< The mail is to request report mail */ + EMAIL_MAIL_REPORT_DSN = 0x04, /**< The mail is a Delivery Status Notifications mail */ + EMAIL_MAIL_REPORT_MDN = 0x08, /**< The mail is a Message Disposition Notifications mail */ + EMAIL_MAIL_REQUEST_DSN = 0x10, /**< The mail requires Delivery Status Notifications */ + EMAIL_MAIL_REQUEST_MDN = 0x20, /**< The mail requires Message Disposition Notifications */ } email_mail_report_t; /** - * This enumeration specifies the DRM type + * @brief Enumeration for the DRM type. + * @since_tizen 2.3 */ typedef enum { - EMAIL_ATTACHMENT_DRM_NONE = 0, /**< The mail isn't DRM file.*/ - EMAIL_ATTACHMENT_DRM_OBJECT, /**< The mail is a DRM object.*/ - EMAIL_ATTACHMENT_DRM_RIGHTS, /**< The mail is a DRM rights as XML format.*/ - EMAIL_ATTACHMENT_DRM_DCF, /**< The mail is a DRM DCF.*/ + EMAIL_ATTACHMENT_DRM_NONE = 0, /**< The mail is not DRM file */ + EMAIL_ATTACHMENT_DRM_OBJECT, /**< The mail is a DRM object */ + EMAIL_ATTACHMENT_DRM_RIGHTS, /**< The mail is a DRM rights as XML format */ + EMAIL_ATTACHMENT_DRM_DCF, /**< The mail is a DRM DCF */ } email_attachment_drm_t; /** - * This enumeration specifies the mail type + * @brief Enumeration for the mail type. + * @since_tizen 2.3 */ typedef enum { - EMAIL_MAIL_TYPE_NORMAL = 0, /**< NOT a meeting request mail. A Normal mail */ - EMAIL_MAIL_TYPE_MEETING_REQUEST = 1, /**< a meeting request mail from a serve */ - EMAIL_MAIL_TYPE_MEETING_RESPONSE = 2, /**< a response mail about meeting request */ - EMAIL_MAIL_TYPE_MEETING_ORIGINATINGREQUEST = 3 /**< a originating mail about meeting request */ + EMAIL_MAIL_TYPE_NORMAL = 0, /**< NOT a meeting request mail. A Normal mail */ + EMAIL_MAIL_TYPE_MEETING_REQUEST = 1, /**< A meeting request mail */ + EMAIL_MAIL_TYPE_MEETING_RESPONSE = 2, /**< A response mail about meeting request */ + EMAIL_MAIL_TYPE_MEETING_ORIGINATINGREQUEST = 3 /**< An originating mail about meeting request */ } email_mail_type_t; /** - * This enumeration specifies the meeting response type + * @brief Enumeration for the meeting response type. + * @since_tizen 2.3 */ typedef enum { - EMAIL_MEETING_RESPONSE_NONE = 0, /**< NOT response */ - EMAIL_MEETING_RESPONSE_ACCEPT = 1, /**< The response is acceptance */ - EMAIL_MEETING_RESPONSE_TENTATIVE = 2, /**< The response is tentative */ - EMAIL_MEETING_RESPONSE_DECLINE = 3, /**< The response is decline */ - EMAIL_MEETING_RESPONSE_REQUEST = 4, /**< The response is request */ - EMAIL_MEETING_RESPONSE_CANCEL = 5, /**< The response is cancellation */ - EMAIL_MEETING_RESPONSE_PROPOSE_NEW_TIME_TENTATIVE, - EMAIL_MEETING_RESPONSE_PROPOSE_NEW_TIME_DECLINE + EMAIL_MEETING_RESPONSE_NONE = 0, /**< NOT a response */ + EMAIL_MEETING_RESPONSE_ACCEPT = 1, /**< The response is acceptance */ + EMAIL_MEETING_RESPONSE_TENTATIVE = 2, /**< The response is tentative */ + EMAIL_MEETING_RESPONSE_DECLINE = 3, /**< The response is decline */ + EMAIL_MEETING_RESPONSE_REQUEST = 4, /**< The response is request */ + EMAIL_MEETING_RESPONSE_CANCEL = 5, /**< The response is cancellation */ + EMAIL_MEETING_RESPONSE_PROPOSE_NEW_TIME_TENTATIVE, /**< The response proposes new time tentative */ + EMAIL_MEETING_RESPONSE_PROPOSE_NEW_TIME_DECLINE /**< The response proposes new time decline */ } email_meeting_response_t; typedef enum { - EMAIL_ACTION_SEND_MAIL = 0, - EMAIL_ACTION_SYNC_HEADER = 1, - EMAIL_ACTION_DOWNLOAD_BODY = 2, - EMAIL_ACTION_DOWNLOAD_ATTACHMENT = 3, - EMAIL_ACTION_DELETE_MAIL = 4, - EMAIL_ACTION_SEARCH_MAIL = 5, - EMAIL_ACTION_SAVE_MAIL = 6, - EMAIL_ACTION_SYNC_MAIL_FLAG_TO_SERVER = 7, - EMAIL_ACTION_SYNC_FLAGS_FIELD_TO_SERVER = 8, - EMAIL_ACTION_MOVE_MAIL = 9, - EMAIL_ACTION_CREATE_MAILBOX = 10, - EMAIL_ACTION_DELETE_MAILBOX = 11, - EMAIL_ACTION_SYNC_HEADER_OMA = 12, - EMAIL_ACTION_VALIDATE_ACCOUNT = 13, - EMAIL_ACTION_VALIDATE_AND_CREATE_ACCOUNT = 14, - EMAIL_ACTION_VALIDATE_AND_UPDATE_ACCOUNT = 15, - EMAIL_ACTION_VALIDATE_ACCOUNT_EX = 16, - EMAIL_ACTION_UPDATE_MAIL = 30, - EMAIL_ACTION_SET_MAIL_SLOT_SIZE = 31, - EMAIL_ACTION_EXPUNGE_MAILS_DELETED_FLAGGED = 32, - EMAIL_ACTION_SEARCH_ON_SERVER = 33, - EMAIL_ACTION_MOVE_MAILBOX = 34, - EMAIL_ACTION_SENDING_MAIL = 35, - EMAIL_ACTION_NUM, + EMAIL_ACTION_SEND_MAIL = 0, /**< Action type for sending mail */ + EMAIL_ACTION_SYNC_HEADER = 1, /**< Action type for syncing header */ + EMAIL_ACTION_DOWNLOAD_BODY = 2, /**< Action type for downloading body */ + EMAIL_ACTION_DOWNLOAD_ATTACHMENT = 3, /**< Action type for downloading attachment */ + EMAIL_ACTION_DELETE_MAIL = 4, /**< Action type for deleting mail */ + EMAIL_ACTION_SEARCH_MAIL = 5, /**< Action type for searching mail */ + EMAIL_ACTION_SAVE_MAIL = 6, /**< Action type for saving mail */ + EMAIL_ACTION_SYNC_MAIL_FLAG_TO_SERVER = 7, /**< Action type for syncing mail flag */ + EMAIL_ACTION_SYNC_FLAGS_FIELD_TO_SERVER = 8, /**< Action type for syncing flags field */ + EMAIL_ACTION_MOVE_MAIL = 9, /**< Action type for moving mail */ + EMAIL_ACTION_CREATE_MAILBOX = 10, /**< Action type for creating mailbox */ + EMAIL_ACTION_DELETE_MAILBOX = 11, /**< Action type for deleting mailbox */ + EMAIL_ACTION_SYNC_HEADER_OMA = 12, /**< Action type for syncing header by oma-emn */ + EMAIL_ACTION_VALIDATE_ACCOUNT = 13, /**< Action type for validating account */ + EMAIL_ACTION_VALIDATE_AND_CREATE_ACCOUNT = 14, /**< Action type for validating and creating account */ + EMAIL_ACTION_VALIDATE_AND_UPDATE_ACCOUNT = 15, /**< Action type for validating and updating account */ + EMAIL_ACTION_VALIDATE_ACCOUNT_EX = 16, /**< Action type for validating account */ + EMAIL_ACTION_UPDATE_MAIL = 30, /**< Action type for updating account */ + EMAIL_ACTION_SET_MAIL_SLOT_SIZE = 31, /**< Action type for setting mail slot size */ + EMAIL_ACTION_EXPUNGE_MAILS_DELETED_FLAGGED = 32, /**< Action type for expunge mails deleted flagged */ + EMAIL_ACTION_SEARCH_ON_SERVER = 33, /**< Action type for searching on server */ + EMAIL_ACTION_MOVE_MAILBOX = 34, /**< Action type for moving mailbox */ + EMAIL_ACTION_SENDING_MAIL = 35, /**< Action type for sending mail */ + EMAIL_ACTION_NUM, /**< end of email_action_t */ } email_action_t; /** - * This enumeration specifies the status of getting envelope list. + * @brief Enumeration for the status of getting an envelope list. + * @since_tizen 2.3 */ typedef enum { - EMAIL_LIST_NONE = 0, - EMAIL_LIST_WAITING, - EMAIL_LIST_PREPARE, /**< Specifies the preparation.*/ - EMAIL_LIST_CONNECTION_START, /**< Specifies the connection start.*/ - EMAIL_LIST_CONNECTION_SUCCEED, /**< Specifies the success of connection.*/ - EMAIL_LIST_CONNECTION_FINISH, /**< Specifies the connection finish.*/ - EMAIL_LIST_CONNECTION_FAIL, /**< Specifies the connection failure.*/ - EMAIL_LIST_START, /**< Specifies the getting start.*/ - EMAIL_LIST_PROGRESS, /**< Specifies the status of getting.*/ - EMAIL_LIST_FINISH, /**< Specifies the getting complete.*/ - EMAIL_LIST_FAIL, /**< Specifies the download failure.*/ + EMAIL_LIST_NONE = 0, /**< Initial status */ + EMAIL_LIST_WAITING, /**< Waiting status */ + EMAIL_LIST_PREPARE, /**< Preparation status */ + EMAIL_LIST_CONNECTION_START, /**< Connection start */ + EMAIL_LIST_CONNECTION_SUCCEED, /**< Connection success */ + EMAIL_LIST_CONNECTION_FINISH, /**< Connection finish */ + EMAIL_LIST_CONNECTION_FAIL, /**< Connection failure */ + EMAIL_LIST_START, /**< Getting the list started */ + EMAIL_LIST_PROGRESS, /**< The progress status of getting */ + EMAIL_LIST_FINISH, /**< Getting the list completed */ + EMAIL_LIST_FAIL, /**< Getting the list failed */ } email_envelope_list_status_t; /** - * This enumeration specifies the downloaded status of email. + * @brief Enumeration for the downloaded status of an email. + * @since_tizen 2.3 */ typedef enum { - EMAIL_DOWNLOAD_NONE = 0, - EMAIL_DOWNLOAD_WAITING, - EMAIL_DOWNLOAD_PREPARE, /**< Specifies the preparation.*/ - EMAIL_DOWNLOAD_CONNECTION_START, /**< Specifies the connection start.*/ - EMAIL_DOWNLOAD_CONNECTION_SUCCEED, /**< Specifies the success of connection.*/ - EMAIL_DOWNLOAD_CONNECTION_FINISH, /**< Specifies the connection finish.*/ - EMAIL_DOWNLOAD_CONNECTION_FAIL, /**< Specifies the connection failure.*/ - EMAIL_DOWNLOAD_START, /**< Specifies the download start.*/ - EMAIL_DOWNLOAD_PROGRESS, /**< Specifies the status of download.*/ - EMAIL_DOWNLOAD_FINISH, /**< Specifies the download complete.*/ - EMAIL_DOWNLOAD_FAIL, /**< Specifies the download failure.*/ + EMAIL_DOWNLOAD_NONE = 0, /**< Initial status */ + EMAIL_DOWNLOAD_WAITING, /**< Download is waiting */ + EMAIL_DOWNLOAD_PREPARE, /**< Preparing for download */ + EMAIL_DOWNLOAD_CONNECTION_START, /**< Connection start */ + EMAIL_DOWNLOAD_CONNECTION_SUCCEED, /**< Connection success */ + EMAIL_DOWNLOAD_CONNECTION_FINISH, /**< Connection finish */ + EMAIL_DOWNLOAD_CONNECTION_FAIL, /**< Connection failure */ + EMAIL_DOWNLOAD_START, /**< Download start */ + EMAIL_DOWNLOAD_PROGRESS, /**< Progress of download */ + EMAIL_DOWNLOAD_FINISH, /**< Download complete */ + EMAIL_DOWNLOAD_FAIL, /**< Download failure */ } email_download_status_t; /** - * This enumeration specifies the status of sending email. + * @brief Enumeration for the status of sending an email. + * @since_tizen 2.3 */ typedef enum { - EMAIL_SEND_NONE = 0, - EMAIL_SEND_WAITING, - EMAIL_SEND_PREPARE, /**< Specifies the preparation.*/ - EMAIL_SEND_CONNECTION_START, /**< Specifies the connection start.*/ - EMAIL_SEND_CONNECTION_SUCCEED, /**< Specifies the success of connection.*/ - EMAIL_SEND_CONNECTION_FINISH, /**< Specifies the connection finish.*/ - EMAIL_SEND_CONNECTION_FAIL, /**< Specifies the connection failure.*/ - EMAIL_SEND_START, /**< Specifies the sending start.*/ - EMAIL_SEND_PROGRESS, /**< Specifies the status of sending.*/ - EMAIL_SEND_FINISH, /**< Specifies the sending complete.*/ - EMAIL_SEND_FAIL, /**< Specifies the sending failure.*/ - EMAIL_SAVE_WAITING, /**< Specfies the Waiting of Sync */ + EMAIL_SEND_NONE = 0, /**< Initial status */ + EMAIL_SEND_WAITING, /**< Waiting to send */ + EMAIL_SEND_PREPARE, /**< Preparing to send */ + EMAIL_SEND_CONNECTION_START, /**< Starting the send connection */ + EMAIL_SEND_CONNECTION_SUCCEED, /**< Send connection success */ + EMAIL_SEND_CONNECTION_FINISH, /**< Send connection finish */ + EMAIL_SEND_CONNECTION_FAIL, /**< Send connection failure */ + EMAIL_SEND_START, /**< Start sending */ + EMAIL_SEND_PROGRESS, /**< Sending status */ + EMAIL_SEND_FINISH, /**< Sending complete */ + EMAIL_SEND_FAIL, /**< Sending failure */ + EMAIL_SAVE_WAITING, /**< Waiting to save */ } email_send_status_t; typedef enum { - EMAIL_SYNC_NONE = 0, - EMAIL_SYNC_WAITING, - EMAIL_SYNC_PREPARE, - EMAIL_SYNC_CONNECTION_START, - EMAIL_SYNC_CONNECTION_SUCCEED, - EMAIL_SYNC_CONNECTION_FINISH, - EMAIL_SYNC_CONNECTION_FAIL, - EMAIL_SYNC_START, - EMAIL_SYNC_PROGRESS, - EMAIL_SYNC_FINISH, - EMAIL_SYNC_FAIL, + EMAIL_SYNC_NONE = 0, /**< Initial status */ + EMAIL_SYNC_WAITING, /**< Waiting to sync */ + EMAIL_SYNC_PREPARE, /**< Preparing to sync */ + EMAIL_SYNC_CONNECTION_START, /**< Starting sync connection */ + EMAIL_SYNC_CONNECTION_SUCCEED, /**< Sync connection success */ + EMAIL_SYNC_CONNECTION_FINISH, /**< Sync connection finish */ + EMAIL_SYNC_CONNECTION_FAIL, /**< Sync connection failure*/ + EMAIL_SYNC_START, /**< Start syncing */ + EMAIL_SYNC_PROGRESS, /**< Sync status */ + EMAIL_SYNC_FINISH, /**< Sync complete */ + EMAIL_SYNC_FAIL, /**< Sync failure */ } email_sync_status_t; /** -* This enumeration specifies the deleting status of email. +* @brief Enumeration for the deleting status of an email. +* @since_tizen 2.3 */ typedef enum { - EMAIL_DELETE_NONE = 0, - EMAIL_DELETE_WAITING, - EMAIL_DELETE_PREPARE, /**< Specifies the preparation.*/ - EMAIL_DELETE_CONNECTION_START, /**< Specifies the connection start.*/ - EMAIL_DELETE_CONNECTION_SUCCEED, /**< Specifies the success of connection.*/ - EMAIL_DELETE_CONNECTION_FINISH, /**< Specifies the connection finish.*/ - EMAIL_DELETE_CONNECTION_FAIL, /**< Specifies the connection failure.*/ - EMAIL_DELETE_START, /**< Specifies the deletion start.*/ - EMAIL_DELETE_PROGRESS, /**< Specifies the status of deleting.*/ - EMAIL_DELETE_SERVER_PROGRESS, /**< Specifies the status of server deleting.*/ - EMAIL_DELETE_LOCAL_PROGRESS, /**< Specifies the status of local deleting.*/ - EMAIL_DELETE_FINISH, /**< Specifies the deletion complete.*/ - EMAIL_DELETE_FAIL, /**< Specifies the deletion failure.*/ + EMAIL_DELETE_NONE = 0, /**< Initial status */ + EMAIL_DELETE_WAITING, /**< Waiting to delete */ + EMAIL_DELETE_PREPARE, /**< Preparing to delete */ + EMAIL_DELETE_CONNECTION_START, /**< Starting delete connection */ + EMAIL_DELETE_CONNECTION_SUCCEED, /**< Delete connection success */ + EMAIL_DELETE_CONNECTION_FINISH, /**< Delete connection finish */ + EMAIL_DELETE_CONNECTION_FAIL, /**< Delete connection failure */ + EMAIL_DELETE_START, /**< Deletion start */ + EMAIL_DELETE_PROGRESS, /**< Delete status */ + EMAIL_DELETE_SERVER_PROGRESS, /**< Server deleting status */ + EMAIL_DELETE_LOCAL_PROGRESS, /**< Local deleting status*/ + EMAIL_DELETE_FINISH, /**< Deletion complete */ + EMAIL_DELETE_FAIL, /**< Deletion failure */ } email_delete_status_t; /** -* This enumeration specifies the status of validating account +* @brief Enumeration for the status of validating an account. +* @since_tizen 2.3 */ typedef enum { - EMAIL_VALIDATE_ACCOUNT_NONE = 0, - EMAIL_VALIDATE_ACCOUNT_WAITING, - EMAIL_VALIDATE_ACCOUNT_PREPARE, /**< Specifies the preparation.*/ - EMAIL_VALIDATE_ACCOUNT_CONNECTION_START, /**< Specifies the connection start.*/ - EMAIL_VALIDATE_ACCOUNT_CONNECTION_SUCCEED, /**< Specifies the success of connection.*/ - EMAIL_VALIDATE_ACCOUNT_CONNECTION_FINISH, /**< Specifies the connection finish.*/ - EMAIL_VALIDATE_ACCOUNT_CONNECTION_FAIL, /**< Specifies the connection failure.*/ - EMAIL_VALIDATE_ACCOUNT_START, /**< Specifies the getting start.*/ - EMAIL_VALIDATE_ACCOUNT_PROGRESS, /**< Specifies the status of getting.*/ - EMAIL_VALIDATE_ACCOUNT_FINISH, /**< Specifies the getting complete.*/ - EMAIL_VALIDATE_ACCOUNT_FAIL, /**< Specifies the validation failure.*/ + EMAIL_VALIDATE_ACCOUNT_NONE = 0, /**< Initial status */ + EMAIL_VALIDATE_ACCOUNT_WAITING, /**< Waiting to validate account */ + EMAIL_VALIDATE_ACCOUNT_PREPARE, /**< Preparing to validate account */ + EMAIL_VALIDATE_ACCOUNT_CONNECTION_START, /**< Starting validate account connection */ + EMAIL_VALIDATE_ACCOUNT_CONNECTION_SUCCEED, /**< Validate account connection success */ + EMAIL_VALIDATE_ACCOUNT_CONNECTION_FINISH, /**< Validate account connection finish */ + EMAIL_VALIDATE_ACCOUNT_CONNECTION_FAIL, /**< Validate account connection failure */ + EMAIL_VALIDATE_ACCOUNT_START, /**< Start validating account */ + EMAIL_VALIDATE_ACCOUNT_PROGRESS, /**< Account validation status */ + EMAIL_VALIDATE_ACCOUNT_FINISH, /**< Account validation complete */ + EMAIL_VALIDATE_ACCOUNT_FAIL, /**< Account validation failure.*/ } email_validate_account_status_t; +/** +* @brief Enumeration for the status of setting slot size. +* @since_tizen 2.3 +*/ typedef enum { - EMAIL_SET_SLOT_SIZE_NONE = 0, - EMAIL_SET_SLOT_SIZE_WAITING, - EMAIL_SET_SLOT_SIZE_START, - EMAIL_SET_SLOT_SIZE_FINISH, - EMAIL_SET_SLOT_SIZE_FAIL, + EMAIL_SET_SLOT_SIZE_NONE = 0, /**< Initial status */ + EMAIL_SET_SLOT_SIZE_WAITING, /**< Waiting status*/ + EMAIL_SET_SLOT_SIZE_START, /**< Task started */ + EMAIL_SET_SLOT_SIZE_FINISH, /**< Task finished */ + EMAIL_SET_SLOT_SIZE_FAIL, /**< Task failed */ }email_set_slot_size_status_e; +/** +* @brief Enumeration for the status of expunging mails. +* @since_tizen 2.3 +*/ typedef enum { - EMAIL_EXPUNGE_MAILS_DELETED_FLAGGED_NONE = 0, - EMAIL_EXPUNGE_MAILS_DELETED_FLAGGED_WAITING, - EMAIL_EXPUNGE_MAILS_DELETED_FLAGGED_START, - EMAIL_EXPUNGE_MAILS_DELETED_FLAGGED_FINISH, - EMAIL_EXPUNGE_MAILS_DELETED_FLAGGED_FAIL, + EMAIL_EXPUNGE_MAILS_DELETED_FLAGGED_NONE = 0, /**< Initial status */ + EMAIL_EXPUNGE_MAILS_DELETED_FLAGGED_WAITING, /**< Waiting status*/ + EMAIL_EXPUNGE_MAILS_DELETED_FLAGGED_START, /**< Task started */ + EMAIL_EXPUNGE_MAILS_DELETED_FLAGGED_FINISH, /**< Task finished */ + EMAIL_EXPUNGE_MAILS_DELETED_FLAGGED_FAIL, /**< Task failed */ }email_expunge_mails_deleted_flagged_status_e; +/** +* @brief Enumeration for the status of searching mails on server. +* @since_tizen 2.3 +*/ typedef enum { - EMAIL_SEARCH_ON_SERVER_NONE = 0, - EMAIL_SEARCH_ON_SERVER_WAITING, - EMAIL_SEARCH_ON_SERVER_START, - EMAIL_SEARCH_ON_SERVER_FINISH, - EMAIL_SEARCH_ON_SERVER_FAIL, + EMAIL_SEARCH_ON_SERVER_NONE = 0, /**< Initial status */ + EMAIL_SEARCH_ON_SERVER_WAITING, /**< Waiting status*/ + EMAIL_SEARCH_ON_SERVER_START, /**< Task started */ + EMAIL_SEARCH_ON_SERVER_FINISH, /**< Task finished */ + EMAIL_SEARCH_ON_SERVER_FAIL, /**< Task failed */ }email_search_on_server_status_e; +/** +* @brief Enumeration for the status of moving mails. +* @since_tizen 2.3 +*/ typedef enum { - EMAIL_MOVE_MAILBOX_ON_IMAP_SERVER_NONE = 0, - EMAIL_MOVE_MAILBOX_ON_IMAP_SERVER_WAITING, - EMAIL_MOVE_MAILBOX_ON_IMAP_SERVER_START, - EMAIL_MOVE_MAILBOX_ON_IMAP_SERVER_FINISH, - EMAIL_MOVE_MAILBOX_ON_IMAP_SERVER_FAIL, + EMAIL_MOVE_MAILBOX_ON_IMAP_SERVER_NONE = 0, /**< Initial status */ + EMAIL_MOVE_MAILBOX_ON_IMAP_SERVER_WAITING, /**< Waiting status*/ + EMAIL_MOVE_MAILBOX_ON_IMAP_SERVER_START, /**< Task started */ + EMAIL_MOVE_MAILBOX_ON_IMAP_SERVER_FINISH, /**< Task finished */ + EMAIL_MOVE_MAILBOX_ON_IMAP_SERVER_FAIL, /**< Task failed */ }email_move_mailbox_status_e; +/** +* @brief Enumeration for the status of updating mails. +* @since_tizen 2.3 +*/ typedef enum { - EMAIL_UPDATE_MAIL_NONE = 0, - EMAIL_UPDATE_MAIL_WAITING, - EMAIL_UPDATE_MAIL_START, - EMAIL_UPDATE_MAIL_FINISH, - EMAIL_UPDATE_MAIL_FAIL, + EMAIL_UPDATE_MAIL_NONE = 0, /**< Initial status */ + EMAIL_UPDATE_MAIL_WAITING, /**< Waiting status*/ + EMAIL_UPDATE_MAIL_START, /**< Task started */ + EMAIL_UPDATE_MAIL_FINISH, /**< Task finished */ + EMAIL_UPDATE_MAIL_FAIL, /**< Task failed */ }email_update_mail_status_e; /** -* This enumeration specifies the type of mailbox +* @brief Enumeration for the mailbox type. +* @since_tizen 2.3 */ typedef enum { - EMAIL_MAILBOX_TYPE_NONE = 0, /**< Unspecified mailbox type*/ - EMAIL_MAILBOX_TYPE_INBOX = 1, /**< Specified inbox type*/ - EMAIL_MAILBOX_TYPE_SENTBOX = 2, /**< Specified sent box type*/ - EMAIL_MAILBOX_TYPE_TRASH = 3, /**< Specified trash type*/ - EMAIL_MAILBOX_TYPE_DRAFT = 4, /**< Specified draft box type*/ - EMAIL_MAILBOX_TYPE_SPAMBOX = 5, /**< Specified spam box type*/ - EMAIL_MAILBOX_TYPE_OUTBOX = 6, /**< Specified outbox type*/ - EMAIL_MAILBOX_TYPE_ALL_EMAILS = 7, /**< Specified all emails type of gmail*/ - EMAIL_MAILBOX_TYPE_SEARCH_RESULT = 8, /**< Specified mailbox type for result of search on server */ - EMAIL_MAILBOX_TYPE_FLAGGED = 9, /**< Specified flagged mailbox type on gmail */ - EMAIL_MAILBOX_TYPE_USER_DEFINED = 0xFF, /**< Specified mailbox type for all other mailboxes */ + EMAIL_MAILBOX_TYPE_NONE = 0, /**< Unspecified mailbox type */ + EMAIL_MAILBOX_TYPE_INBOX = 1, /**< Specified inbox type */ + EMAIL_MAILBOX_TYPE_SENTBOX = 2, /**< Specified sent box type */ + EMAIL_MAILBOX_TYPE_TRASH = 3, /**< Specified trash type */ + EMAIL_MAILBOX_TYPE_DRAFT = 4, /**< Specified draft box type */ + EMAIL_MAILBOX_TYPE_SPAMBOX = 5, /**< Specified spam box type */ + EMAIL_MAILBOX_TYPE_OUTBOX = 6, /**< Specified outbox type */ + EMAIL_MAILBOX_TYPE_ALL_EMAILS = 7, /**< Specified all emails type of gmail */ + EMAIL_MAILBOX_TYPE_SEARCH_RESULT = 8, /**< Specified mailbox type for result of search on server */ + EMAIL_MAILBOX_TYPE_FLAGGED = 9, /**< Specified flagged mailbox type on gmail */ + EMAIL_MAILBOX_TYPE_USER_DEFINED = 0xFF, /**< Specified mailbox type for all other mailboxes */ }email_mailbox_type_e; + +/** @brief Enumeration for the sync order. + * @since_tizen 2.3 */ + + typedef enum { - EMAIL_SYNC_LATEST_MAILS_FIRST = 0, - EMAIL_SYNC_OLDEST_MAILS_FIRST, - EMAIL_SYNC_ALL_MAILBOX_50_MAILS, + EMAIL_SYNC_LATEST_MAILS_FIRST = 0, /**< Download latest mails first */ + EMAIL_SYNC_OLDEST_MAILS_FIRST, /**< Download oldest mails first */ + EMAIL_SYNC_ALL_MAILBOX_50_MAILS, /**< Download latest 50 mails only */ } EMAIL_RETRIEVE_MODE; -/* event type */ +/** @brief Enumeration for the event type. + * @since_tizen 2.3 */ typedef enum { - EMAIL_EVENT_NONE = 0, - EMAIL_EVENT_SYNC_HEADER = 1, /* synchronize mail headers with server (network used) */ - EMAIL_EVENT_DOWNLOAD_BODY = 2, /* download mail body from server (network used)*/ - EMAIL_EVENT_DOWNLOAD_ATTACHMENT = 3, /* download mail attachment from server (network used) */ - EMAIL_EVENT_SEND_MAIL = 4, /* send a mail (network used) */ - EMAIL_EVENT_SEND_MAIL_SAVED = 5, /* send all mails in 'outbox' box (network used) */ - EMAIL_EVENT_SYNC_IMAP_MAILBOX = 6, /* download imap mailboxes from server (network used) */ - EMAIL_EVENT_DELETE_MAIL = 7, /* delete mails (network unused) */ - EMAIL_EVENT_DELETE_MAIL_ALL = 8, /* delete all mails (network unused) */ - EMAIL_EVENT_SYNC_MAIL_FLAG_TO_SERVER = 9, /* sync mail flag to server */ - EMAIL_EVENT_SYNC_FLAGS_FIELD_TO_SERVER = 10, /* sync a field of flags to server */ - EMAIL_EVENT_SAVE_MAIL = 11, /* add mail on server */ - EMAIL_EVENT_MOVE_MAIL = 12, /* move mails to specific mailbox on server */ - EMAIL_EVENT_CREATE_MAILBOX = 13, - EMAIL_EVENT_UPDATE_MAILBOX = 14, - EMAIL_EVENT_DELETE_MAILBOX = 15, - EMAIL_EVENT_ISSUE_IDLE = 16, - EMAIL_EVENT_SYNC_HEADER_OMA = 17, - EMAIL_EVENT_VALIDATE_ACCOUNT = 18, - EMAIL_EVENT_VALIDATE_AND_CREATE_ACCOUNT = 19, - EMAIL_EVENT_VALIDATE_AND_UPDATE_ACCOUNT = 20, - EMAIL_EVENT_SEARCH_ON_SERVER = 21, - EMAIL_EVENT_RENAME_MAILBOX_ON_IMAP_SERVER = 22, - EMAIL_EVENT_VALIDATE_ACCOUNT_EX = 23, - EMAIL_EVENT_QUERY_SMTP_MAIL_SIZE_LIMIT = 24, - - EMAIL_EVENT_ADD_MAIL = 10001, /* Deprecated */ - EMAIL_EVENT_UPDATE_MAIL_OLD = 10002, /* Deprecated */ - EMAIL_EVENT_UPDATE_MAIL = 10003, - EMAIL_EVENT_SET_MAIL_SLOT_SIZE = 20000, - EMAIL_EVENT_EXPUNGE_MAILS_DELETED_FLAGGED = 20001, - -/* EMAIL_EVENT_LOCAL_ACTIVITY, __LOCAL_ACTIVITY_ */ - - EMAIL_EVENT_BULK_PARTIAL_BODY_DOWNLOAD = 20002, /* __FEATURE_PARTIAL_BODY_DOWNLOAD__ supported */ - EMAIL_EVENT_LOCAL_ACTIVITY_SYNC_BULK_PBD = 20003, /* __FEATURE_PARTIAL_BODY_DOWNLOAD__ supported */ - EMAIL_EVENT_GET_PASSWORD_LENGTH = 20004, /* get password length of an account */ + EMAIL_EVENT_NONE = 0, /**< Initial value of #email_event_type_t */ + EMAIL_EVENT_SYNC_HEADER = 1, /**< Synchronize mail headers with server (network used) */ + EMAIL_EVENT_DOWNLOAD_BODY = 2, /**< Download mail body from server (network used)*/ + EMAIL_EVENT_DOWNLOAD_ATTACHMENT = 3, /**< Download mail attachment from server (network used) */ + EMAIL_EVENT_SEND_MAIL = 4, /**< Send a mail (network used) */ + EMAIL_EVENT_SEND_MAIL_SAVED = 5, /**< Send all mails in 'outbox' (network used) */ + EMAIL_EVENT_SYNC_IMAP_MAILBOX = 6, /**< Download IMAP mailboxes from server (network used) */ + EMAIL_EVENT_DELETE_MAIL = 7, /**< Delete mails (network not used) */ + EMAIL_EVENT_DELETE_MAIL_ALL = 8, /**< Delete all mails (network not used) */ + EMAIL_EVENT_SYNC_MAIL_FLAG_TO_SERVER = 9, /**< Sync mail flag to server */ + EMAIL_EVENT_SYNC_FLAGS_FIELD_TO_SERVER = 10, /**< Sync a field of flags to server */ + EMAIL_EVENT_SAVE_MAIL = 11, /**< Add mail on server */ + EMAIL_EVENT_MOVE_MAIL = 12, /**< Move mails to specific mailbox on server */ + EMAIL_EVENT_CREATE_MAILBOX = 13, /**< Create a mailbox */ + EMAIL_EVENT_UPDATE_MAILBOX = 14, /**< Update a mailbox */ + EMAIL_EVENT_DELETE_MAILBOX = 15, /**< Delete a mailbox */ + EMAIL_EVENT_ISSUE_IDLE = 16, /**< Deprecated */ + EMAIL_EVENT_SYNC_HEADER_OMA = 17, /**< Sync mail headers by OMA-EMN */ + EMAIL_EVENT_VALIDATE_ACCOUNT = 18, /**< Validate account */ + EMAIL_EVENT_VALIDATE_AND_CREATE_ACCOUNT = 19, /**< Validate and create account */ + EMAIL_EVENT_VALIDATE_AND_UPDATE_ACCOUNT = 20, /**< Validate and update account */ + EMAIL_EVENT_SEARCH_ON_SERVER = 21, /**< Search mails on server */ + EMAIL_EVENT_RENAME_MAILBOX_ON_IMAP_SERVER = 22, /**< Rename a mailbox on imap server */ + EMAIL_EVENT_VALIDATE_ACCOUNT_EX = 23, /**< Validate account */ + EMAIL_EVENT_QUERY_SMTP_MAIL_SIZE_LIMIT = 24, /**< Query limitation of mail size to SMTP server */ + + EMAIL_EVENT_ADD_MAIL = 10001, /**< Deprecated */ + EMAIL_EVENT_UPDATE_MAIL_OLD = 10002, /**< Deprecated */ + EMAIL_EVENT_UPDATE_MAIL = 10003, /**< Update a mail */ + EMAIL_EVENT_SET_MAIL_SLOT_SIZE = 20000, /**< Set mail slot size */ + EMAIL_EVENT_EXPUNGE_MAILS_DELETED_FLAGGED = 20001, /**< Expunge mails deleted flagged */ + +/* EMAIL_EVENT_LOCAL_ACTIVITY, __LOCAL_ACTIVITY_ */ + + EMAIL_EVENT_BULK_PARTIAL_BODY_DOWNLOAD = 20002, /**< Download body partially */ + EMAIL_EVENT_LOCAL_ACTIVITY_SYNC_BULK_PBD = 20003, /**< Deprecated */ + EMAIL_EVENT_GET_PASSWORD_LENGTH = 20004, /**< Get password length of an account */ } email_event_type_t; -/* event status */ +/** @brief Enumeration for the event status. + * @since_tizen 2.3 */ typedef enum { - EMAIL_EVENT_STATUS_UNUSED = 0, - EMAIL_EVENT_STATUS_WAIT, - EMAIL_EVENT_STATUS_STARTED, - EMAIL_EVENT_STATUS_CANCELED, + EMAIL_EVENT_STATUS_UNUSED = 0, /**< Initial status of event */ + EMAIL_EVENT_STATUS_WAIT, /**< Waiting status */ + EMAIL_EVENT_STATUS_STARTED, /**< Event handling is started */ + EMAIL_EVENT_STATUS_CANCELED, /**< Event handling is canceled */ } email_event_status_type_t; -/* sorting_orde */ +/** @brief Enumeration for the srting type. + * @since_tizen 2.3 */ typedef enum { - EMAIL_SORT_DATETIME_HIGH = 0, - EMAIL_SORT_DATETIME_LOW, - EMAIL_SORT_SENDER_HIGH, - EMAIL_SORT_SENDER_LOW, - EMAIL_SORT_RCPT_HIGH, - EMAIL_SORT_RCPT_LOW, - EMAIL_SORT_SUBJECT_HIGH, - EMAIL_SORT_SUBJECT_LOW, - EMAIL_SORT_PRIORITY_HIGH, - EMAIL_SORT_PRIORITY_LOW, - EMAIL_SORT_ATTACHMENT_HIGH, - EMAIL_SORT_ATTACHMENT_LOW, - EMAIL_SORT_FAVORITE_HIGH, - EMAIL_SORT_FAVORITE_LOW, - EMAIL_SORT_MAILBOX_ID_HIGH, - EMAIL_SORT_MAILBOX_ID_LOW, - EMAIL_SORT_FLAGGED_FLAG_HIGH, - EMAIL_SORT_FLAGGED_FLAG_LOW, - EMAIL_SORT_SEEN_FLAG_HIGH, - EMAIL_SORT_SEEN_FLAG_LOW, - EMAIL_SORT_END, + EMAIL_SORT_DATETIME_HIGH = 0, /**< Sort mails by datetime ascending order */ + EMAIL_SORT_DATETIME_LOW, /**< Sort mails by datetime descending order */ + EMAIL_SORT_SENDER_HIGH, /**< Sort mails by sender ascending order */ + EMAIL_SORT_SENDER_LOW, /**< Sort mails by sender descending order */ + EMAIL_SORT_RCPT_HIGH, /**< Sort mails by recipient ascending order */ + EMAIL_SORT_RCPT_LOW, /**< Sort mails by recipient descending order */ + EMAIL_SORT_SUBJECT_HIGH, /**< Sort mails by subject ascending order */ + EMAIL_SORT_SUBJECT_LOW, /**< Sort mails by subject descending order */ + EMAIL_SORT_PRIORITY_HIGH, /**< Sort mails by priority ascending order */ + EMAIL_SORT_PRIORITY_LOW, /**< Sort mails by priority descending order */ + EMAIL_SORT_ATTACHMENT_HIGH, /**< Sort mails by attachment ascending order */ + EMAIL_SORT_ATTACHMENT_LOW, /**< Sort mails by attachment descending order */ + EMAIL_SORT_FAVORITE_HIGH, /**< Sort mails by favorite ascending order */ + EMAIL_SORT_FAVORITE_LOW, /**< Sort mails by favorite descending order */ + EMAIL_SORT_MAILBOX_ID_HIGH, /**< Sort mails by mailbox ID ascending order */ + EMAIL_SORT_MAILBOX_ID_LOW, /**< Sort mails by mailbox ID descending order */ + EMAIL_SORT_FLAGGED_FLAG_HIGH, /**< Sort mails by flagged flag ID ascending order */ + EMAIL_SORT_FLAGGED_FLAG_LOW, /**< Sort mails by flagged flag ID descending order */ + EMAIL_SORT_SEEN_FLAG_HIGH, /**< Sort mails by seen flag ID ascending order */ + EMAIL_SORT_SEEN_FLAG_LOW, /**< Sort mails by seen flag ID descending order */ + EMAIL_SORT_END, /**< end of #email_sort_type_t */ }email_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_BY_NAME_ASC = 0, /**< Sort mailbox by name ascending order */ + EMAIL_MAILBOX_SORT_BY_NAME_DSC, /**< Sort mailbox by name descending order */ + EMAIL_MAILBOX_SORT_BY_TYPE_ASC, /**< Sort mailbox by type ascending order */ + EMAIL_MAILBOX_SORT_BY_TYPE_DSC, /**< Sort mailbox by type descending order */ } email_mailbox_sort_type_t; /** -* This enumeration specifies the priority. +* @brief Enumeration for the priority. +* @since_tizen 2.3 */ enum { - EMAIL_OPTION_PRIORITY_HIGH = 1, /**< Specifies the high priority.*/ - EMAIL_OPTION_PRIORITY_NORMAL = 3, /**< Specifies the normal priority*/ - EMAIL_OPTION_PRIORITY_LOW = 5, /**< Specifies the low priority.*/ + EMAIL_OPTION_PRIORITY_HIGH = 1, /**< High priority */ + EMAIL_OPTION_PRIORITY_NORMAL = 3, /**< Normal priority */ + EMAIL_OPTION_PRIORITY_LOW = 5, /**< Low priority */ }; /** -* This enumeration specifies the saving save a copy after sending. +* @brief Enumeration for the saving a copy after sending. +* @since_tizen 2.3 */ enum { - EMAIL_OPTION_KEEP_LOCAL_COPY_OFF = 0, /**< Specifies off the keeping local copy.*/ - EMAIL_OPTION_KEEP_LOCAL_COPY_ON = 1, /**< Specifies on the keeping local copy.*/ + EMAIL_OPTION_KEEP_LOCAL_COPY_OFF = 0, /**< Keeping local copy is not enabled */ + EMAIL_OPTION_KEEP_LOCAL_COPY_ON = 1, /**< Keeping local copy is enabled */ }; /** -* This enumeration specifies the request of delivery report. +* @brief Enumeration for the request of a delivery report. +* @since_tizen 2.3 */ enum { - EMAIL_OPTION_REQ_DELIVERY_RECEIPT_OFF = 0, /**< Specifies off the requesting delivery receipt.*/ - EMAIL_OPTION_REQ_DELIVERY_RECEIPT_ON = 1, /**< Specifies on the requesting delivery receipt.*/ + EMAIL_OPTION_REQ_DELIVERY_RECEIPT_OFF = 0, /**< Requesting delivery receipt is not enabled */ + EMAIL_OPTION_REQ_DELIVERY_RECEIPT_ON = 1, /**< Requesting delivery receipt is enabled */ }; /** -* This enumeration specifies the request of read receipt. +* @brief Enumeration for the request of a read receipt. +* @since_tizen 2.3 */ enum { - EMAIL_OPTION_REQ_READ_RECEIPT_OFF = 0, /**< Specifies off the requesting read receipt.*/ - EMAIL_OPTION_REQ_READ_RECEIPT_ON = 1, /**< Specifies on the requesting read receipt.*/ + EMAIL_OPTION_REQ_READ_RECEIPT_OFF = 0, /**< Requesting read receipt is not enabled */ + EMAIL_OPTION_REQ_READ_RECEIPT_ON = 1, /**< Requesting read receipt is enabled */ }; /** -* This enumeration specifies the blocking of address. +* @brief Enumeration for the blocking of an address. +* @since_tizen 2.3 */ enum { - EMAIL_OPTION_BLOCK_ADDRESS_OFF = 0, /**< Specifies off the blocking by address.*/ - EMAIL_OPTION_BLOCK_ADDRESS_ON = 1, /**< Specifies on the blocking by address.*/ + EMAIL_OPTION_BLOCK_ADDRESS_OFF = 0, /**< Blocking an address is not enabled */ + EMAIL_OPTION_BLOCK_ADDRESS_ON = 1, /**< Blocking an address is enabled */ }; /** -* This enumeration specifies the blocking of subject. +* @brief Enumeration for the blocking of a subject. +* @since_tizen 2.3 */ enum { - EMAIL_OPTION_BLOCK_SUBJECT_OFF = 0, /**< Specifies off the blocking by subject.*/ - EMAIL_OPTION_BLOCK_SUBJECT_ON = 1, /**< Specifies on the blocking by subject.*/ + EMAIL_OPTION_BLOCK_SUBJECT_OFF = 0, /**< Blocking by subject is not enabled */ + EMAIL_OPTION_BLOCK_SUBJECT_ON = 1, /**< Blocking by subject is enabled */ }; enum { - EMAIL_LIST_TYPE_UNREAD = -3, - EMAIL_LIST_TYPE_LOCAL = -2, - EMAIL_LIST_TYPE_THREAD = -1, - EMAIL_LIST_TYPE_NORMAL = 0 + EMAIL_LIST_TYPE_UNREAD = -3, /**< List unread mails */ + EMAIL_LIST_TYPE_LOCAL = -2, /**< List local mails */ + EMAIL_LIST_TYPE_THREAD = -1, /**< List thread */ + EMAIL_LIST_TYPE_NORMAL = 0 /**< List all mails */ }; /** -* This enumeration specifies the mailbox sync type. +* @brief Enumeration for the mailbox sync type. +* @since_tizen 2.3 */ enum { - EMAIL_MAILBOX_ALL = -1, /**< All mailboxes.*/ - EMAIL_MAILBOX_FROM_SERVER = 0, /**< Mailboxes from server. */ - EMAIL_MAILBOX_FROM_LOCAL = 1, /**< Mailboxes from local. */ + EMAIL_MAILBOX_ALL = -1, /**< All mailboxes */ + EMAIL_MAILBOX_FROM_SERVER = 0, /**< Mailboxes from server */ + EMAIL_MAILBOX_FROM_LOCAL = 1, /**< Mailboxes from local */ }; +/** +* @brief Enumeration for the mail change type. +* @since_tizen 2.3 +*/ 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, - UPDATE_FILE_PATH, -} email_mail_change_type_t; // Should be moved intenal types */ + APPEND_BODY = 1, /**< Body is appended */ + UPDATE_MAILBOX, /**< Mailbox is updated */ + UPDATE_ATTACHMENT_INFO, /**< Attachment info is updated */ + UPDATE_FLAG, /**< Flag is updated */ + UPDATE_SAVENAME, /**< Savename is updated */ + UPDATE_EXTRA_FLAG, /**< Extra flag is updated */ + UPDATE_MAIL, /**< Mail information is updated */ + UPDATE_DATETIME, /**< Datetime is updated */ + UPDATE_FROM_CONTACT_INFO, /**< From contact info is updated */ + UPDATE_TO_CONTACT_INFO, /**< To contact info is updated */ + UPDATE_ALL_CONTACT_NAME, /**< All contact name is updated */ + UPDATE_ALL_CONTACT_INFO, /**< All contact info is updated */ + UPDATE_STICKY_EXTRA_FLAG, /**< Sticky extra flag is updated */ + UPDATE_PARTIAL_BODY_DOWNLOAD, /**< Partial body download is updated */ + UPDATE_MEETING, /**< Meeting is updated */ + UPDATE_SEEN_FLAG_OF_THREAD, /**< Seen flag of thread is updated */ + UPDATE_FILE_PATH, /**< File path is updated */ +} email_mail_change_type_t; /** -* This enumeration specifies the address type. +* @brief Enumeration for the address type. +* @since_tizen 2.3 */ typedef enum { - EMAIL_ADDRESS_TYPE_FROM = 1, /**< Specifies the from address.*/ - EMAIL_ADDRESS_TYPE_TO, /**< Specifies the to recipient address.*/ - EMAIL_ADDRESS_TYPE_CC, /**< Specifies the cc recipient address.*/ - EMAIL_ADDRESS_TYPE_BCC, /**< Specifies the bcc recipient address.*/ - EMAIL_ADDRESS_TYPE_REPLY, /**< Specifies the reply recipient address.*/ - EMAIL_ADDRESS_TYPE_RETURN, /**< Specifies the return recipient address.*/ + EMAIL_ADDRESS_TYPE_FROM = 1, /**< From address */ + EMAIL_ADDRESS_TYPE_TO, /**< To recipient address */ + EMAIL_ADDRESS_TYPE_CC, /**< CC recipient address */ + EMAIL_ADDRESS_TYPE_BCC, /**< BCC recipient address */ + EMAIL_ADDRESS_TYPE_REPLY, /**< Reply recipient address */ + EMAIL_ADDRESS_TYPE_RETURN, /**< Return recipient address */ } email_address_type_t; /** - * This enumeration specifies the search type for searching mailbox. + * @brief Enumeration for the search type for searching a mailbox. + * @since_tizen 2.3 */ typedef enum { - EMAIL_MAILBOX_SEARCH_KEY_TYPE_SUBJECT, /**< The search key is for searching subject.*/ - EMAIL_MAILBOX_SEARCH_KEY_TYPE_FROM, /**< The search key is for searching sender address.*/ - EMAIL_MAILBOX_SEARCH_KEY_TYPE_BODY, /**< The search key is for searching body.*/ - EMAIL_MAILBOX_SEARCH_KEY_TYPE_TO, /**< The search key is for searching recipient address.*/ + EMAIL_MAILBOX_SEARCH_KEY_TYPE_SUBJECT, /**< The search key for searching subject */ + EMAIL_MAILBOX_SEARCH_KEY_TYPE_FROM, /**< The search key for searching sender address */ + EMAIL_MAILBOX_SEARCH_KEY_TYPE_BODY, /**< The search key for searching body */ + EMAIL_MAILBOX_SEARCH_KEY_TYPE_TO, /**< The search key for searching recipient address */ } email_mailbox_search_key_t; /** - * This enumeration specifies the download status of mail body. + * @brief Enumeration for the download status of a mail body. + * @since_tizen 2.3 */ typedef enum { - EMAIL_BODY_DOWNLOAD_STATUS_NONE = 0, - EMAIL_BODY_DOWNLOAD_STATUS_FULLY_DOWNLOADED = 1, - EMAIL_BODY_DOWNLOAD_STATUS_PARTIALLY_DOWNLOADED = 2, + EMAIL_BODY_DOWNLOAD_STATUS_NONE = 0, /**< The mail is not downloaded yet */ + EMAIL_BODY_DOWNLOAD_STATUS_FULLY_DOWNLOADED = 1, /**< The mail is fully downloaded */ + EMAIL_BODY_DOWNLOAD_STATUS_PARTIALLY_DOWNLOADED = 2, /**< The mail is partially downloaded */ } email_body_download_status_t; /** - * This enumeration specifies the moving type. + * @brief Enumeration for the download status of a mail body. + * @since_tizen 2.3 */ + typedef enum { - EMAIL_MOVED_BY_COMMAND = 0, - EMAIL_MOVED_BY_MOVING_THREAD, - EMAIL_MOVED_AFTER_SENDING, - EMAIL_MOVED_CANCELATION_MAIL + EMAIL_PART_DOWNLOAD_STATUS_NONE = 0, /**< The part is not downloaded yet */ + EMAIL_PART_DOWNLOAD_STATUS_FULLY_DOWNLOADED = 1, /**< The part is fully downloaded */ + EMAIL_PART_DOWNLOAD_STATUS_PARTIALLY_DOWNLOADED = 2, /**< The part is partially downloaded */ +} email_part_download_status_t; + +/** + * @brief Enumeration for the moving type. + * @since_tizen 2.3 + */ +typedef enum +{ + EMAIL_MOVED_BY_COMMAND = 0, /**< The mails are moved by user */ + EMAIL_MOVED_BY_MOVING_THREAD, /**< The mails are moved with moving thread mails*/ + EMAIL_MOVED_AFTER_SENDING, /**< The mails are moved by 'move after sending' option */ + EMAIL_MOVED_CANCELATION_MAIL /**< The mails are moved by cancellation of meeting request */ } email_move_type; /** - * This enumeration specifies the deletion type. + * @brief Enumeration for the deletion type. + * @since_tizen 2.3 */ typedef enum { - EMAIL_DELETED_BY_COMMAND = 0, - EMAIL_DELETED_BY_OVERFLOW, - EMAIL_DELETED_BY_DELETING_THREAD, - EMAIL_DELETED_BY_MOVING_TO_OTHER_ACCOUNT, - EMAIL_DELETED_AFTER_SENDING, - EMAIL_DELETED_FROM_SERVER, + EMAIL_DELETED_BY_COMMAND = 0, /**< The mails are deleted by user */ + EMAIL_DELETED_BY_OVERFLOW, /**< The mails are deleted by overflow */ + EMAIL_DELETED_BY_DELETING_THREAD, /**< The mails are deleted with removing thread mails */ + EMAIL_DELETED_BY_MOVING_TO_OTHER_ACCOUNT, /**< The mails are deleted by moving to other account */ + EMAIL_DELETED_AFTER_SENDING, /**< The mails are deleted by 'delete after sending' option */ + EMAIL_DELETED_FROM_SERVER, /**< The mails are deleted because the mails are deleted on server */ } email_delete_type; /** - * This enumeration specifies the status field type. + * @brief Enumeration for the status field type. + * @since_tizen 2.3 */ typedef enum { - EMAIL_FLAGS_SEEN_FIELD = 0, - EMAIL_FLAGS_DELETED_FIELD, - EMAIL_FLAGS_FLAGGED_FIELD, - EMAIL_FLAGS_ANSWERED_FIELD, - EMAIL_FLAGS_RECENT_FIELD, - EMAIL_FLAGS_DRAFT_FIELD, - EMAIL_FLAGS_FORWARDED_FIELD, - EMAIL_FLAGS_FIELD_COUNT, + EMAIL_FLAGS_SEEN_FIELD = 0, /**< mail flag : \Seen */ + EMAIL_FLAGS_DELETED_FIELD, /**< mail flag : \Deleted */ + EMAIL_FLAGS_FLAGGED_FIELD, /**< mail flag : \Flagged */ + EMAIL_FLAGS_ANSWERED_FIELD, /**< mail flag : \Answered */ + EMAIL_FLAGS_RECENT_FIELD, /**< mail flag : \Recent */ + EMAIL_FLAGS_DRAFT_FIELD, /**< mail flag : \Draft */ + EMAIL_FLAGS_FORWARDED_FIELD, /**< mail flag : \Forwarded */ + EMAIL_FLAGS_FIELD_COUNT, /**< field count */ } email_flags_field_type; typedef enum { - EMAIL_FLAG_NONE = 0, - EMAIL_FLAG_FLAGED = 1, - EMAIL_FLAG_TASK_STATUS_CLEAR = 2, - EMAIL_FLAG_TASK_STATUS_COMPLETE = 3, - EMAIL_FLAG_TASK_STATUS_ACTIVE = 4, + EMAIL_FLAG_NONE = 0, /**< No flag */ + EMAIL_FLAG_FLAGED = 1, /**< Flagged */ + EMAIL_FLAG_TASK_STATUS_CLEAR = 2, /**< For EAS task management : No task */ + EMAIL_FLAG_TASK_STATUS_COMPLETE = 3, /**< For EAS task management : Completed task */ + EMAIL_FLAG_TASK_STATUS_ACTIVE = 4, /**< For EAS task management : Active task */ } email_flagged_type; typedef enum { - EMAIL_SEARCH_FILTER_TYPE_MESSAGE_NO = 1, /* integer type */ - EMAIL_SEARCH_FILTER_TYPE_UID = 2, /* integer type */ - EMAIL_SEARCH_FILTER_TYPE_BCC = 7, /* string type */ - EMAIL_SEARCH_FILTER_TYPE_CC = 9, /* string type */ - EMAIL_SEARCH_FILTER_TYPE_FROM = 10, /* string type */ - EMAIL_SEARCH_FILTER_TYPE_KEYWORD = 11, /* string type */ - EMAIL_SEARCH_FILTER_TYPE_SUBJECT = 13, /* string type */ - EMAIL_SEARCH_FILTER_TYPE_TO = 15, /* string type */ - EMAIL_SEARCH_FILTER_TYPE_SIZE_LARSER = 16, /* integer type */ - EMAIL_SEARCH_FILTER_TYPE_SIZE_SMALLER = 17, /* integer type */ - EMAIL_SEARCH_FILTER_TYPE_SENT_DATE_BEFORE = 20, /* time type */ - EMAIL_SEARCH_FILTER_TYPE_SENT_DATE_ON = 21, /* time type */ - EMAIL_SEARCH_FILTER_TYPE_SENT_DATE_SINCE = 22, /* time type */ - EMAIL_SEARCH_FILTER_TYPE_FLAGS_ANSWERED = 26, /* integer type */ - EMAIL_SEARCH_FILTER_TYPE_FLAGS_DELETED = 28, /* integer type */ - EMAIL_SEARCH_FILTER_TYPE_FLAGS_DRAFT = 30, /* integer type */ - EMAIL_SEARCH_FILTER_TYPE_FLAGS_FLAGED = 32, /* integer type */ - EMAIL_SEARCH_FILTER_TYPE_FLAGS_RECENT = 34, /* integer type */ - EMAIL_SEARCH_FILTER_TYPE_FLAGS_SEEN = 36, /* integer type */ - EMAIL_SEARCH_FILTER_TYPE_MESSAGE_ID = 43, /* string type */ + EMAIL_SEARCH_FILTER_TYPE_MESSAGE_NO = 1, /* integer type */ /**< Messages with specified message no */ + EMAIL_SEARCH_FILTER_TYPE_UID = 2, /* integer type */ /**< Messages with unique identifiers corresponding to the specified unique identifier set */ + EMAIL_SEARCH_FILTER_TYPE_ALL = 3, /* integer type */ /**< All messages in the mailbox; the default initial key for ANDing */ + EMAIL_SEARCH_FILTER_TYPE_BCC = 7, /* string type */ /**< Messages that contain the specified string in the envelope structure's BCC field */ + EMAIL_SEARCH_FILTER_TYPE_BODY = 8, /* string type */ /**< Messages that contain the specified string in the body of the message */ + EMAIL_SEARCH_FILTER_TYPE_CC = 9, /* string type */ /**< Messages that contain the specified string in the envelope structure's CC field */ + EMAIL_SEARCH_FILTER_TYPE_FROM = 10, /* string type */ /**< Messages that contain the specified string in the envelope structure's FROM field */ + EMAIL_SEARCH_FILTER_TYPE_KEYWORD = 11, /* string type */ /**< Messages with the specified keyword set */ + EMAIL_SEARCH_FILTER_TYPE_TEXT = 12, /* string type */ /**< Messages that contain the specified string in the header or body of the message */ + EMAIL_SEARCH_FILTER_TYPE_SUBJECT = 13, /* string type */ /**< Messages that contain the specified string in the envelope structure's SUBJECT field */ + EMAIL_SEARCH_FILTER_TYPE_TO = 15, /* string type */ /**< Messages that contain the specified string in the envelope structure's TO field */ + EMAIL_SEARCH_FILTER_TYPE_SIZE_LARSER = 16, /* integer type */ /**< Messages with a size larger than the specified number of octets */ + EMAIL_SEARCH_FILTER_TYPE_SIZE_SMALLER = 17, /* integer type */ /**< Messages with a size smaller than the specified number of octets */ + EMAIL_SEARCH_FILTER_TYPE_SENT_DATE_BEFORE = 20, /* time type */ /**< Messages whose Date: header is earlier than the specified date */ + EMAIL_SEARCH_FILTER_TYPE_SENT_DATE_ON = 21, /* time type */ /**< Messages whose Date: header is within the specified date */ + EMAIL_SEARCH_FILTER_TYPE_SENT_DATE_SINCE = 22, /* time type */ /**< Messages whose Date: header is within or later than the specified date */ + EMAIL_SEARCH_FILTER_TYPE_FLAGS_ANSWERED = 26, /* integer type */ /**< Messages with the \Answered flag set */ + EMAIL_SEARCH_FILTER_TYPE_FLAGS_NEW = 27, /* integer type */ /**< Messages that have the \Recent flag set but not the \Seen flag */ + EMAIL_SEARCH_FILTER_TYPE_FLAGS_DELETED = 28, /* integer type */ /**< Messages with the \Deleted flag set */ + EMAIL_SEARCH_FILTER_TYPE_FLAGS_OLD = 29, /* integer type */ /**< Messages that do not have the \Recent flag set */ + EMAIL_SEARCH_FILTER_TYPE_FLAGS_DRAFT = 30, /* integer type */ /**< Messages with the \Draft flag set */ + EMAIL_SEARCH_FILTER_TYPE_FLAGS_FLAGED = 32, /* integer type */ /**< Messages with the \Flagged flag set */ + EMAIL_SEARCH_FILTER_TYPE_FLAGS_RECENT = 34, /* integer type */ /**< Messages that have the \Recent flag set */ + EMAIL_SEARCH_FILTER_TYPE_FLAGS_SEEN = 36, /* integer type */ /**< Messages that have the \Seen flag set */ + EMAIL_SEARCH_FILTER_TYPE_MESSAGE_ID = 43, /* string type */ /**< Messages with specified message ID */ + EMAIL_SEARCH_FILTER_TYPE_HEADER_PRIORITY = 50, /* integer type */ /**< Messages that have a header with the specified priority */ + EMAIL_SEARCH_FILTER_TYPE_ATTACHMENT_NAME = 60, /* string type */ /**< Messages that contain the specified string in attachment name */ } email_search_filter_type; typedef enum { - EMAIL_DRM_TYPE_NONE = 0, - EMAIL_DRM_TYPE_OBJECT = 1, - EMAIL_DRM_TYPE_RIGHT = 2, - EMAIL_DRM_TYPE_DCF = 3 + EMAIL_DRM_TYPE_NONE = 0, /**< No DRM type */ + EMAIL_DRM_TYPE_OBJECT = 1, /**< DRM object */ + EMAIL_DRM_TYPE_RIGHT = 2, /**< DRM right */ + EMAIL_DRM_TYPE_DCF = 3 /**< DRM Content Format */ } email_drm_type; typedef enum { - EMAIL_DRM_METHOD_NONE = 0, - EMAIL_DRM_METHOD_FL = 1, - EMAIL_DRM_METHOD_CD = 2, - EMAIL_DRM_METHOD_SSD = 3, - EMAIL_DRM_METHOD_SD = 4 + EMAIL_DRM_METHOD_NONE = 0, /**< No DRM method */ + EMAIL_DRM_METHOD_FL = 1, /**< Forward lock method */ + EMAIL_DRM_METHOD_CD = 2, /**< Combined Delivery method */ + EMAIL_DRM_METHOD_SSD = 3, /**< Deprecated */ + EMAIL_DRM_METHOD_SD = 4 /**< Separated Delivery method */ } email_drm_method; typedef enum { - EMAIL_CANCELED_BY_USER = 0, - EMAIL_CANCELED_BY_MDM = 1, + EMAIL_CANCELED_BY_USER = 0, /**< Canceled by user */ + EMAIL_CANCELED_BY_MDM = 1, /**< Canceled by MDM policy */ } email_cancelation_type; typedef enum { - EMAIL_MAIL_ATTRIBUTE_MAIL_ID = 0, /* integer type */ - EMAIL_MAIL_ATTRIBUTE_ACCOUNT_ID = 1, /* integer type */ - EMAIL_MAIL_ATTRIBUTE_MAILBOX_ID = 2, /* integer type */ - EMAIL_MAIL_ATTRIBUTE_MAILBOX_NAME = 3, /* string type */ - EMAIL_MAIL_ATTRIBUTE_MAILBOX_TYPE = 4, /* integer type */ - EMAIL_MAIL_ATTRIBUTE_SUBJECT = 5, /* string type */ - EMAIL_MAIL_ATTRIBUTE_DATE_TIME = 6, /* datetime type */ - EMAIL_MAIL_ATTRIBUTE_SERVER_MAIL_STATUS = 7, /* integer type */ - EMAIL_MAIL_ATTRIBUTE_SERVER_MAILBOX_NAME = 8, /* string type */ - EMAIL_MAIL_ATTRIBUTE_SERVER_MAIL_ID = 9, /* string type */ - EMAIL_MAIL_ATTRIBUTE_MESSAGE_ID = 10, /* string type */ - EMAIL_MAIL_ATTRIBUTE_REFERENCE_MAIL_ID = 11, /* integer type */ - EMAIL_MAIL_ATTRIBUTE_FROM = 12, /* string type */ - EMAIL_MAIL_ATTRIBUTE_TO = 13, /* string type */ - EMAIL_MAIL_ATTRIBUTE_CC = 14, /* string type */ - EMAIL_MAIL_ATTRIBUTE_BCC = 15, /* string type */ - EMAIL_MAIL_ATTRIBUTE_BODY_DOWNLOAD_STATUS = 16, /* integer type */ - EMAIL_MAIL_ATTRIBUTE_MAIL_SIZE = 17, /* integer type */ - EMAIL_MAIL_ATTRIBUTE_FILE_PATH_PLAIN = 18, /* string type */ - EMAIL_MAIL_ATTRIBUTE_FILE_PATH_HTML = 19, /* string type */ - EMAIL_MAIL_ATTRIBUTE_FILE_SIZE = 20, /* integer type */ - EMAIL_MAIL_ATTRIBUTE_FLAGS_SEEN_FIELD = 21, /* integer type */ - EMAIL_MAIL_ATTRIBUTE_FLAGS_DELETED_FIELD = 22, /* integer type */ - EMAIL_MAIL_ATTRIBUTE_FLAGS_FLAGGED_FIELD = 23, /* integer type */ - EMAIL_MAIL_ATTRIBUTE_FLAGS_ANSWERED_FIELD = 24, /* integer type */ - EMAIL_MAIL_ATTRIBUTE_FLAGS_RECENT_FIELD = 25, /* integer type */ - EMAIL_MAIL_ATTRIBUTE_FLAGS_DRAFT_FIELD = 26, /* integer type */ - EMAIL_MAIL_ATTRIBUTE_FLAGS_FORWARDED_FIELD = 27, /* integer type */ - EMAIL_MAIL_ATTRIBUTE_DRM_STATUS = 28, /* integer type */ - EMAIL_MAIL_ATTRIBUTE_PRIORITY = 29, /* integer type */ - EMAIL_MAIL_ATTRIBUTE_SAVE_STATUS = 30, /* integer type */ - EMAIL_MAIL_ATTRIBUTE_LOCK_STATUS = 31, /* integer type */ - EMAIL_MAIL_ATTRIBUTE_REPORT_STATUS = 32, /* integer type */ - EMAIL_MAIL_ATTRIBUTE_ATTACHMENT_COUNT = 33, /* integer type */ - EMAIL_MAIL_ATTRIBUTE_INLINE_CONTENT_COUNT = 34, /* integer type */ - EMAIL_MAIL_ATTRIBUTE_THREAD_ID = 35, /* integer type */ - EMAIL_MAIL_ATTRIBUTE_THREAD_ITEM_COUNT = 36, /* integer type */ - EMAIL_MAIL_ATTRIBUTE_PREVIEW_TEXT = 37, /* string type */ - EMAIL_MAIL_ATTRIBUTE_MEETING_REQUEST_STATUS = 38, /* integer type */ - EMAIL_MAIL_ATTRIBUTE_MESSAGE_CLASS = 39, /* integer type */ - EMAIL_MAIL_ATTRIBUTE_DIGEST_TYPE = 40, /* integer type */ - EMAIL_MAIL_ATTRIBUTE_SMIME_TYPE = 41, /* integer type */ - EMAIL_MAIL_ATTRIBUTE_SCHEDULED_SENDING_TIME = 42, /* integer type */ - EMAIL_MAIL_ATTRIBUTE_REMAINING_RESEND_TIMES = 43, /* integer type */ - EMAIL_MAIL_ATTRIBUTE_TAG_ID = 44, /* integer type */ - EMAIL_MAIL_ATTRIBUTE_REPLIED_TIME = 45, /* integer type */ - EMAIL_MAIL_ATTRIBUTE_FORWARDED_TIME = 46, /* integer type */ - EMAIL_MAIL_ATTRIBUTE_RECIPIENT_ADDRESS = 47, /* string type */ - EMAIL_MAIL_ATTRIBUTE_EAS_DATA_LENGTH_TYPE = 48, /* integer type */ - EMAIL_MAIL_ATTRIBUTE_EAS_DATA_TYPE = 49, /* binary type */ - EMAIL_MAIL_ATTRIBUTE_END + EMAIL_MAIL_ATTRIBUTE_MAIL_ID = 0, /* integer type */ /**< @a mail_id field of email_mail_data_t */ + EMAIL_MAIL_ATTRIBUTE_ACCOUNT_ID = 1, /* integer type */ /**< @a account_id field of email_mail_data_t */ + EMAIL_MAIL_ATTRIBUTE_MAILBOX_ID = 2, /* integer type */ /**< @a mailbox_id field of email_mail_data_t */ + EMAIL_MAIL_ATTRIBUTE_MAILBOX_NAME = 3, /* string type */ /**< @a mailbox_name field of email_mail_data_t */ + EMAIL_MAIL_ATTRIBUTE_MAILBOX_TYPE = 4, /* integer type */ /**< @a mailbox_type field of email_mail_data_t */ + EMAIL_MAIL_ATTRIBUTE_SUBJECT = 5, /* string type */ /**< @a subject field of email_mail_data_t */ + EMAIL_MAIL_ATTRIBUTE_DATE_TIME = 6, /* datetime type */ /**< @a date_time field of email_mail_data_t */ + EMAIL_MAIL_ATTRIBUTE_SERVER_MAIL_STATUS = 7, /* integer type */ /**< @a server_mail_status field of email_mail_data_t */ + EMAIL_MAIL_ATTRIBUTE_SERVER_MAILBOX_NAME = 8, /* string type */ /**< @a server_mailbox_name field of email_mail_data_t */ + EMAIL_MAIL_ATTRIBUTE_SERVER_MAIL_ID = 9, /* string type */ /**< @a server_mail_id field of email_mail_data_t */ + EMAIL_MAIL_ATTRIBUTE_MESSAGE_ID = 10, /* string type */ /**< @a message_id field of email_mail_data_t */ + EMAIL_MAIL_ATTRIBUTE_REFERENCE_MAIL_ID = 11, /* integer type */ /**< @a reference_mail_id field of email_mail_data_t */ + EMAIL_MAIL_ATTRIBUTE_FROM = 12, /* string type */ /**< @a full_address_from field of email_mail_data_t */ + EMAIL_MAIL_ATTRIBUTE_TO = 13, /* string type */ /**< @a full_address_to field of email_mail_data_t */ + EMAIL_MAIL_ATTRIBUTE_CC = 14, /* string type */ /**< @a full_address_cc field of email_mail_data_t */ + EMAIL_MAIL_ATTRIBUTE_BCC = 15, /* string type */ /**< @a full_address_bcc field of email_mail_data_t */ + EMAIL_MAIL_ATTRIBUTE_BODY_DOWNLOAD_STATUS = 16, /* integer type */ /**< @a body_download_status field of email_mail_data_t */ + EMAIL_MAIL_ATTRIBUTE_MAIL_SIZE = 17, /* integer type */ /**< @a mail_size field of email_mail_data_t */ + EMAIL_MAIL_ATTRIBUTE_FILE_PATH_PLAIN = 18, /* string type */ /**< @a file_path_plain field of email_mail_data_t */ + EMAIL_MAIL_ATTRIBUTE_FILE_PATH_HTML = 19, /* string type */ /**< @a file_path_html field of email_mail_data_t */ + EMAIL_MAIL_ATTRIBUTE_FILE_SIZE = 20, /* integer type */ /* Deprecated */ /**< @a file_size field of email_mail_data_t */ + EMAIL_MAIL_ATTRIBUTE_FLAGS_SEEN_FIELD = 21, /* integer type */ /**< @a flags_seen_field field of email_mail_data_t */ + EMAIL_MAIL_ATTRIBUTE_FLAGS_DELETED_FIELD = 22, /* integer type */ /**< @a flags_deleted_field field of email_mail_data_t */ + EMAIL_MAIL_ATTRIBUTE_FLAGS_FLAGGED_FIELD = 23, /* integer type */ /**< @a flags_flagged_field field of email_mail_data_t */ + EMAIL_MAIL_ATTRIBUTE_FLAGS_ANSWERED_FIELD = 24, /* integer type */ /**< @a flags_answered_field field of email_mail_data_t */ + EMAIL_MAIL_ATTRIBUTE_FLAGS_RECENT_FIELD = 25, /* integer type */ /**< @a flags_recent_field field of email_mail_data_t */ + EMAIL_MAIL_ATTRIBUTE_FLAGS_DRAFT_FIELD = 26, /* integer type */ /**< @a flags_draft_field field of email_mail_data_t */ + EMAIL_MAIL_ATTRIBUTE_FLAGS_FORWARDED_FIELD = 27, /* integer type */ /**< @a flags_forwarded_field field of email_mail_data_t */ + EMAIL_MAIL_ATTRIBUTE_DRM_STATUS = 28, /* integer type */ /**< @a drm_status field of email_mail_data_t */ + EMAIL_MAIL_ATTRIBUTE_PRIORITY = 29, /* integer type */ /**< @a priority field of email_mail_data_t */ + EMAIL_MAIL_ATTRIBUTE_SAVE_STATUS = 30, /* integer type */ /**< @a save_status field of email_mail_data_t */ + EMAIL_MAIL_ATTRIBUTE_LOCK_STATUS = 31, /* integer type */ /**< @a lock_status field of email_mail_data_t */ + EMAIL_MAIL_ATTRIBUTE_REPORT_STATUS = 32, /* integer type */ /**< @a report_status field of email_mail_data_t */ + EMAIL_MAIL_ATTRIBUTE_ATTACHMENT_COUNT = 33, /* integer type */ /**< @a attachment_count field of email_mail_data_t */ + EMAIL_MAIL_ATTRIBUTE_INLINE_CONTENT_COUNT = 34, /* integer type */ /**< @a inline_content_count field of email_mail_data_t */ + EMAIL_MAIL_ATTRIBUTE_THREAD_ID = 35, /* integer type */ /**< @a thread_id field of email_mail_data_t */ + EMAIL_MAIL_ATTRIBUTE_THREAD_ITEM_COUNT = 36, /* integer type */ /**< @a thread_item_count field of email_mail_data_t */ + EMAIL_MAIL_ATTRIBUTE_PREVIEW_TEXT = 37, /* string type */ /**< @a preview_text field of email_mail_data_t */ + EMAIL_MAIL_ATTRIBUTE_MEETING_REQUEST_STATUS = 38, /* integer type */ /**< @a meeting_request_status field of email_mail_data_t */ + EMAIL_MAIL_ATTRIBUTE_MESSAGE_CLASS = 39, /* integer type */ /**< @a message_class field of email_mail_data_t */ + EMAIL_MAIL_ATTRIBUTE_DIGEST_TYPE = 40, /* integer type */ /**< @a digest_type field of email_mail_data_t */ + EMAIL_MAIL_ATTRIBUTE_SMIME_TYPE = 41, /* integer type */ /**< @a smime_type field of email_mail_data_t */ + EMAIL_MAIL_ATTRIBUTE_SCHEDULED_SENDING_TIME = 42, /* integer type */ /**< @a scheduled_sending_time field of email_mail_data_t */ + EMAIL_MAIL_ATTRIBUTE_REMAINING_RESEND_TIMES = 43, /* integer type */ /**< @a remaining_resend_times field of email_mail_data_t */ + EMAIL_MAIL_ATTRIBUTE_TAG_ID = 44, /* integer type */ /**< @a tag_id field of email_mail_data_t */ + EMAIL_MAIL_ATTRIBUTE_REPLIED_TIME = 45, /* integer type */ /**< @a replied_time field of email_mail_data_t */ + EMAIL_MAIL_ATTRIBUTE_FORWARDED_TIME = 46, /* integer type */ /**< @a forwared_time field of email_mail_data_t */ + EMAIL_MAIL_ATTRIBUTE_RECIPIENT_ADDRESS = 47, /* string type */ /**< @a recipient_address field of email_mail_data_t */ + EMAIL_MAIL_ATTRIBUTE_EAS_DATA_LENGTH_TYPE = 48, /* integer type */ /**< @a eas_data_length_type field of email_mail_data_t */ + EMAIL_MAIL_ATTRIBUTE_EAS_DATA_TYPE = 49, /* binary type */ /**< @a eas_data_type field of email_mail_data_t */ + EMAIL_MAIL_ATTRIBUTE_END /**< The end of attribute */ } email_mail_attribute_type; typedef enum { - EMAIL_MAIL_TEXT_ATTRIBUTE_FULL_TEXT = 1, - EMAIL_MAIL_TEXT_ATTRIBUTE_END + EMAIL_MAIL_TEXT_ATTRIBUTE_FULL_TEXT = 1, /**< Full text attribute of email_mail_text */ + EMAIL_MAIL_TEXT_ATTRIBUTE_END /**< The end of email_mail_text_attribute */ } email_mail_text_attribute_type; typedef enum { - EMAIL_MAIL_ATTACH_ATTRIBUTE_ATTACHMENT_NAME = 1, - EMAIL_MAIL_ATTCH_ATTRIBUTE_END + EMAIL_MAIL_ATTACH_ATTRIBUTE_ATTACHMENT_NAME = 1, /**< Attachment name */ + EMAIL_MAIL_ATTCH_ATTRIBUTE_END /**< The end of email_mail_attach_attribute_type */ } email_mail_attach_attribute_type; typedef enum { - EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_NONE = 0, - EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_INTEGER = 1, - EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_STRING = 2, - EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_TIME = 3, - EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_BINARY = 4 + EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_NONE = 0, /**< The attribute type is none */ + EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_INTEGER = 1, /**< The attribute type is integer */ + EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_STRING = 2, /**< The attribute type is string */ + EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_TIME = 3, /**< The attribute type is time */ + EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_BINARY = 4 /**< The attribute type is binary */ } email_mail_attribute_value_type; typedef enum { - EMAIL_ADD_MY_ADDRESS_OPTION_DO_NOT_ADD = 0, - EMAIL_ADD_MY_ADDRESS_OPTION_ALWAYS_ADD_TO_CC = 1, - EMAIL_ADD_MY_ADDRESS_OPTION_ALWAYS_ADD_TO_BCC = 2, + EMAIL_ADD_MY_ADDRESS_OPTION_DO_NOT_ADD = 0, /**< Address option type is not added */ + EMAIL_ADD_MY_ADDRESS_OPTION_ALWAYS_ADD_TO_CC = 1, /**< Address option type is added to cc */ + EMAIL_ADD_MY_ADDRESS_OPTION_ALWAYS_ADD_TO_BCC = 2, /**< Address option type is added to bcc */ } email_add_my_address_option_type; typedef enum { - EMAIL_MESSAGE_CLASS_UNSPECIFIED, - EMAIL_MESSAGE_CLASS_UNKNOWN, - EMAIL_MESSAGE_CLASS_NOTE, - EMAIL_MESSAGE_CLASS_NOTE_RULES_OF_TEMPLATE_MICROSOFT, - EMAIL_MESSAGE_CLASS_NOTE_SMIME, - EMAIL_MESSAGE_CLASS_NOTE_SMIME_MULTIPART_SIGNED, - EMAIL_MESSAGE_CLASS_NOTIFICATION_MEETING, - EMAIL_MESSAGE_CLASS_OCTEL_VOICE, - EMAIL_MESSAGE_CLASS_SCHEDULE_MEETING_REQUEST, - EMAIL_MESSAGE_CLASS_SCHEDULE_MEETING_CANCELED, - EMAIL_MESSAGE_CLASS_SCHEDULE_MEETING_RESP_POS, - EMAIL_MESSAGE_CLASS_SCHEDULE_MEETING_RESP_TENT, - EMAIL_MESSAGE_CLASS_SCHEDULE_MEETING_RESP_NEG, - EMAIL_MESSAGE_CLASS_POST, - EMAIL_MESSAGE_CLASS_INFO_PATH_FORM, - EMAIL_MESSAGE_CLASS_VOICE_NOTES, - EMAIL_MESSAGE_CLASS_SHARING, - EMAIL_MESSAGE_CLASS_NOTE_EXCHANGE_ACTIVE_SYNC_REMOTE_WIPE_CONFIRMATION, - EMAIL_MESSAGE_CLASS_VOICE_MAIL, - EMAIL_MESSAGE_CLASS_SMS, - EMAIL_MESSAGE_CLASS_IRM_MESSAGE = 0x00100000, - EMAIL_MESSAGE_CLASS_SMART_REPLY = 0x01000000, - EMAIL_MESSAGE_CLASS_SMART_FORWARD = 0x02000000, - EMAIL_MESSAGE_CLASS_REPORT_NOT_READ_REPORT = 0x10000000, - EMAIL_MESSAGE_CLASS_REPORT_READ_REPORT = 0x20000000, - EMAIL_MESSAGE_CLASS_REPORT_NON_DELIVERY_RECEIPT = 0x40000000, - EMAIL_MESSAGE_CLASS_REPORT_DELIVERY_RECEIPT = 0x80000000, - EMAIL_MESSAGE_CLASS_CALENDAR_FORWARD = 0x04000000 + EMAIL_MESSAGE_CLASS_UNSPECIFIED, /**< The message class is unspecified */ + EMAIL_MESSAGE_CLASS_UNKNOWN, /**< The message class is unknown */ + EMAIL_MESSAGE_CLASS_NOTE, /**< The message class is note */ + EMAIL_MESSAGE_CLASS_NOTE_RULES_OF_TEMPLATE_MICROSOFT, /**< The message class is note_rule_of_template_microsoft */ + EMAIL_MESSAGE_CLASS_NOTE_SMIME, /**< The message class is note_smime */ + EMAIL_MESSAGE_CLASS_NOTE_SMIME_MULTIPART_SIGNED, /**< The message class is note_smime_multipart_signed */ + EMAIL_MESSAGE_CLASS_NOTIFICATION_MEETING, /**< The message class is notification meeting */ + EMAIL_MESSAGE_CLASS_OCTEL_VOICE, /**< The message class is octel voice */ + EMAIL_MESSAGE_CLASS_SCHEDULE_MEETING_REQUEST, /**< The message class is meeting request */ + EMAIL_MESSAGE_CLASS_SCHEDULE_MEETING_CANCELED, /**< The message class is meeting canceled */ + EMAIL_MESSAGE_CLASS_SCHEDULE_MEETING_RESP_POS, /**< The message class is meeting resp pos */ + EMAIL_MESSAGE_CLASS_SCHEDULE_MEETING_RESP_TENT, /**< The message class is meeting resp tent */ + EMAIL_MESSAGE_CLASS_SCHEDULE_MEETING_RESP_NEG, /**< The message class is meeting resp neg */ + EMAIL_MESSAGE_CLASS_POST, /**< The message class is post */ + EMAIL_MESSAGE_CLASS_INFO_PATH_FORM, /**< The message class is info path form */ + EMAIL_MESSAGE_CLASS_VOICE_NOTES, /**< The message class is voice notes */ + EMAIL_MESSAGE_CLASS_SHARING, /**< The message class is sharing */ + EMAIL_MESSAGE_CLASS_NOTE_EXCHANGE_ACTIVE_SYNC_REMOTE_WIPE_CONFIRMATION, /**< The message class is note exchange active sync remote wipe confirmation */ + EMAIL_MESSAGE_CLASS_VOICE_MAIL, /**< The message class is voice mail */ + EMAIL_MESSAGE_CLASS_SMS, /**< The message class is SMS */ + EMAIL_MESSAGE_CLASS_IRM_MESSAGE = 0x00010000, /**< The message class is IRM message */ + EMAIL_MESSAGE_CLASS_SMART_REPLY = 0x00100000, /**< The message class is smart reply */ + EMAIL_MESSAGE_CLASS_SMART_FORWARD = 0x00200000, /**< The message class is smart forward */ + EMAIL_MESSAGE_CLASS_REPORT_NOT_READ_REPORT = 0x01000000, /**< The message class is report not read report */ + EMAIL_MESSAGE_CLASS_REPORT_READ_REPORT = 0x02000000, /**< The message class is report read report */ + EMAIL_MESSAGE_CLASS_REPORT_NON_DELIVERY_RECEIPT = 0x04000000, /**< The message class is report non delivery receipt */ + EMAIL_MESSAGE_CLASS_REPORT_DELIVERY_RECEIPT = 0x08000000, /**< The message class is report delivery receipt */ + EMAIL_MESSAGE_CLASS_CALENDAR_FORWARD = 0x00400000 /**< The message class is calendar forward */ } email_message_class; typedef enum{ - EMAIL_SMIME_NONE = 0, /* Not use smime */ - EMAIL_SMIME_SIGNED, - EMAIL_SMIME_ENCRYPTED, - EMAIL_SMIME_SIGNED_AND_ENCRYPTED, + EMAIL_SMIME_NONE = 0, /**< Not using smime : Normal mail */ + EMAIL_SMIME_SIGNED, /**< Signed mail of smime */ + EMAIL_SMIME_ENCRYPTED, /**< Encrypted mail of smime */ + EMAIL_SMIME_SIGNED_AND_ENCRYPTED, /**< Signed/encrypted mail of smime */ + EMAIL_PGP_SIGNED, /**< Signed mail of pgp */ + EMAIL_PGP_ENCRYPTED, /**< Encrypted mail of pgp */ + EMAIL_PGP_SIGNED_AND_ENCRYPTED /**< Signed/encrypted mail of pgp */ } email_smime_type; typedef enum { - CIPHER_TYPE_DES3 = 0, - CIPHER_TYPE_DES, - CIPHER_TYPE_RC2_128, - CIPHER_TYPE_RC2_64, - CIPHER_TYPE_RC2_40, + CIPHER_TYPE_NONE = 0, /**< None of cipher type */ + CIPHER_TYPE_DES3, /**< DES3 of cipher type */ + CIPHER_TYPE_DES, /**< DES of cipher type */ + CIPHER_TYPE_RC2_128, /**< RC2 128 of cipher type */ + CIPHER_TYPE_RC2_64, /**< RC2 64 of cipher type */ + CIPHER_TYPE_RC2_40, /**< RC2 40 of cipher type */ } email_cipher_type; typedef enum { - DIGEST_TYPE_SHA1 = 0, - DIGEST_TYPE_MD5, + DIGEST_TYPE_NONE = 0, /**< None of digest type */ + DIGEST_TYPE_SHA1 = 1, /**< SHA1 of digest type */ + DIGEST_TYPE_MD5 = 2, /**< MD5 of digest type */ + DIGEST_TYPE_RIPEMD160 = 3, /**< RIPEMD160 of digest type */ + DIGEST_TYPE_MD2 = 4, /**< MD2 of digest type */ + DIGEST_TYPE_TIGER192 = 5, /**< TIGER192 of digest type */ + DIGEST_TYPE_HAVAL5160 = 6, /**< HAVAL5160 of digest type */ + DIGEST_TYPE_SHA256 = 7, /**< SHA256 of digest type */ + DIGEST_TYPE_SHA384 = 8, /**< SHA384 of digest type */ + DIGEST_TYPE_SHA512 = 9, /**< SHA512 of digest type */ + DIGEST_TYPE_SHA224 = 10, /**< SHA224 of digest type */ + DIGEST_TYPE_MD4 = 11, /**< MD4 of digest type */ } email_digest_type; typedef enum { - EMAIL_AUTHENTICATION_METHOD_NO_AUTH = 0, - EMAIL_AUTHENTICATION_METHOD_DEFAULT = 1, - EMAIL_AUTHENTICATION_METHOD_XOAUTH2 = 2, + EMAIL_AUTHENTICATION_METHOD_NO_AUTH = 0, /**< The authentication method is no auth */ + EMAIL_AUTHENTICATION_METHOD_DEFAULT = 1, /**< The authentication method is default(SSL/TLS) */ + EMAIL_AUTHENTICATION_METHOD_XOAUTH2 = 2, /**< The authentication method is xoauth2 */ } email_authentication_method_t; typedef enum { - EMAIL_ROAMING_OPTION_RESTRICTED_BACKGROUND_TASK = 0, - EMAIL_ROAMING_OPTION_UNRESTRICTED = 1, + EMAIL_ROAMING_OPTION_RESTRICTED_BACKGROUND_TASK = 0, /**< The roaming option is restricted background task */ + EMAIL_ROAMING_OPTION_UNRESTRICTED = 1, /**< The roaming option is unrestricted */ } email_roaming_option_t; typedef enum { - EMAIL_GET_INCOMING_PASSWORD_LENGTH = 1, - EMAIL_GET_OUTGOING_PASSWORD_LENGTH + EMAIL_GET_INCOMING_PASSWORD_LENGTH = 1, /**< Length of receiving password */ + EMAIL_GET_OUTGOING_PASSWORD_LENGTH /**< Length of SMTP password */ } email_get_password_length_type; /*****************************************************************************/ @@ -1194,539 +1388,597 @@ typedef enum { /*****************************************************************************/ /** - * This structure is used to save mail time. + * @brief The structure type to save the mail time. + * @since_tizen 2.3 */ 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.*/ + unsigned short year; /**< The Year */ + unsigned short month; /**< The Month */ + unsigned short day; /**< The Day */ + unsigned short hour; /**< The Hour */ + unsigned short minute; /**< The Minute */ + unsigned short second; /**< The Second */ } email_datetime_t DEPRECATED; /** - * This structure is used to save the options. + * @brief The structure type to save the options. + * @since_tizen 2.3 */ typedef struct { - email_mail_priority_t 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*/ - email_add_my_address_option_type add_my_address_to_bcc; /**< Specifies whether cc or bcc field should be always filled with my address. */ + email_mail_priority_t priority; /**< The priority. 1=high 3=normal 5=low */ + int keep_local_copy; /**< Saves a copy after sending */ + int req_delivery_receipt; /**< The request of delivery report. 0=off 1=on */ + int req_read_receipt; /**< The request of read receipt. 0=off 1=on */ + int download_limit; /**< The limit of size for downloading */ + int block_address; /**< Specifies the blocking of address. 0=off 1=on */ + int block_subject; /**< The blocking of subject. 0=off 1=on */ + char *display_name_from; /**< The display name of from */ + int reply_with_body; /**< The replying with body 0=off 1=on */ + int forward_with_files; /**< The forwarding with files 0=off 1=on */ + int add_myname_card; /**< The adding name card 0=off 1=on */ + int add_signature; /**< The adding signature 0=off 1=on */ + char *signature; /**< The signature */ + email_add_my_address_option_type add_my_address_to_bcc; /**< The flag specifying whether cc or bcc field should be always filled with my address */ + int notification_status; /**< The notification status. 1 = ON, 0 = OFF */ + int vibrate_status; /**< The repetition type */ + int display_content_status; /**< The display_content status. 1 = ON, 0 = OFF */ + int default_ringtone_status; /**< The badge status. 1 = ON, 0 = OFF */ + char *alert_ringtone_path; /**< The ringtone path */ } email_option_t; /** - * This structure is used to save the information of email account. + * @brief The structure type to save the information of an email account. + * @since_tizen 2.3 */ typedef struct { - /* General account information */ - int account_id; /**< Account id */ - char *account_name; /**< Account name */ - int account_svc_id; /**< AccountSvc priv data: Specifies id from account-svc */ - int sync_status; /**< Sync Status. SYNC_STATUS_FINISHED, SYNC_STATUS_SYNCING, SYNC_STATUS_HAVE_NEW_MAILS */ - int sync_disabled; /**< If this attriube is set as true, email-service will not synchronize this account. */ - int default_mail_slot_size; - char *logo_icon_path; /**< account logo icon (used by account svc and email app) */ - email_roaming_option_t roaming_option; /**< roaming option */ - void *user_data; /**< binary user data */ - int user_data_length; /**< user data length */ - - /* User information */ - char *user_display_name; /**< User's display */ - char *user_email_address; /**< User's email address */ - char *reply_to_address; /**< Email address for reply */ - char *return_address; /**< Email address for error from server*/ - - /* Configuration for incoming server */ - email_account_server_t incoming_server_type; /**< Incoming server type */ - char *incoming_server_address; /**< Incoming server address */ - int incoming_server_port_number; /**< Incoming server port number */ - char *incoming_server_user_name; /**< Incoming server user name */ - char *incoming_server_password; /**< Incoming server password */ - int incoming_server_secure_connection; /**< Does incoming server requires secured connection? */ - email_authentication_method_t incoming_server_authentication_method; /**< Incoming server authentication method */ - - /* Options for incoming server */ - email_imap4_retrieval_mode_t retrieval_mode; /**< Retrieval mode : EMAIL_IMAP4_RETRIEVAL_MODE_NEW or EMAIL_IMAP4_RETRIEVAL_MODE_ALL */ - int keep_mails_on_pop_server_after_download; /**< Keep mails on POP server after download */ - int check_interval; /**< Specifies the interval for checking new mail periodically */ - int auto_download_size; /**< Specifies the size for auto download in bytes. -1 means entire mails body */ - int peak_interval; /**< Specifies the interval for checking new mail periodically of peak schedule */ - int peak_days; /**< Specifies the weekdays of peak schedule */ - int peak_start_time; /**< Specifies the start time of peak schedule */ - int peak_end_time; /**< Specifies the end time of peak schedule */ - - /* Configuration for outgoing server */ - email_account_server_t outgoing_server_type; /**< Outgoing server type */ - char *outgoing_server_address; /**< Outgoing server address */ - int outgoing_server_port_number; /**< Outgoing server port number */ - char *outgoing_server_user_name; /**< Outgoing server user name */ - char *outgoing_server_password; /**< Outgoing server password */ - int outgoing_server_secure_connection; /**< Does outgoing server requires secured connection? */ - int outgoing_server_need_authentication; /**< Does outgoing server requires authentication? */ - int outgoing_server_use_same_authenticator; /**< Use same authenticator for outgoing server - email_authentication_method_t - */ - - - /* Options for outgoing server */ - email_option_t options; - int auto_resend_times; /**< Auto retry count for sending a email */ - int outgoing_server_size_limit; /** Mail size limitation for SMTP sending*/ - - /* Authentication Options */ - int pop_before_smtp; /**< POP before SMTP Authentication */ - int incoming_server_requires_apop; /**< APOP authentication */ - - /* S/MIME Options */ - email_smime_type smime_type; /**< Specifies the smime type 0=Normal 1=Clear signed 2=encrypted 3=Signed + encrypted */ - char *certificate_path; /**< Specifies the certificate path of private*/ - email_cipher_type cipher_type; /**< Specifies the encryption algorithm*/ - email_digest_type digest_type; /**< Specifies the digest algorithm*/ + /* General account information */ + int account_id; /**< Account ID */ + char *account_name; /**< Account name */ + int account_svc_id; /**< AccountSvc priv data: Specifies ID from account-svc */ + int sync_status; /**< Sync Status. SYNC_STATUS_FINISHED, SYNC_STATUS_SYNCING, SYNC_STATUS_HAVE_NEW_MAILS */ + int sync_disabled; /**< Flag to enable or disable syncing. If this attribute is set as true, email-service will not synchronize this account. */ + int default_mail_slot_size; /**< Synced mail count in mailbox */ + char *logo_icon_path; /**< Account logo icon (used by account svc and email app) */ + email_roaming_option_t roaming_option; /**< Roaming option */ + int color_label; /**< Account color label */ + void *user_data; /**< Binary user data */ + int user_data_length; /**< User data length */ + + /* User information */ + char *user_display_name; /**< User's display */ + char *user_email_address; /**< User's email address */ + char *reply_to_address; /**< Email address for reply */ + char *return_address; /**< Email address for error from server*/ + + /* Configuration for incoming server */ + email_account_server_t incoming_server_type; /**< Incoming server type */ + char *incoming_server_address; /**< Incoming server address */ + int incoming_server_port_number; /**< Incoming server port number */ + char *incoming_server_user_name; /**< Incoming server user name */ + char *incoming_server_password; /**< Incoming server password */ + int incoming_server_secure_connection; /**< Flag indicating whether incoming server requires secured connection */ + email_authentication_method_t incoming_server_authentication_method; /**< Incoming server authentication method */ + + /* Options for incoming server */ + email_imap4_retrieval_mode_t retrieval_mode; /**< Retrieval mode : EMAIL_IMAP4_RETRIEVAL_MODE_NEW or EMAIL_IMAP4_RETRIEVAL_MODE_ALL */ + int keep_mails_on_pop_server_after_download; /**< Keep mails on POP server after download */ + int check_interval; /**< The interval for checking new mail periodically */ + int auto_download_size; /**< The size for auto download in bytes. @c -1 means entire mails body */ + int peak_interval; /**< The interval for checking new mail periodically of peak schedule */ + int peak_days; /**< The weekdays of peak schedule */ + int peak_start_time; /**< The start time of peak schedule */ + int peak_end_time; /**< The end time of peak schedule */ + + /* Configuration for outgoing server */ + email_account_server_t outgoing_server_type; /**< Outgoing server type */ + char *outgoing_server_address; /**< Outgoing server address */ + int outgoing_server_port_number; /**< Outgoing server port number */ + char *outgoing_server_user_name; /**< Outgoing server user name */ + char *outgoing_server_password; /**< Outgoing server password */ + int outgoing_server_secure_connection; /**< Flag indicating whether outgoing server requires secured connection */ + int outgoing_server_need_authentication; /**< Flag indicating whether outgoing server requires authentication */ + int outgoing_server_use_same_authenticator; /**< Use same authenticator for outgoing server - email_authentication_method_t - */ + + + /* Options for outgoing server */ + email_option_t options; /**< Account options for setting */ + int auto_resend_times; /**< Auto retry count for sending a email */ + int outgoing_server_size_limit; /**< Mail size limitation for SMTP sending */ + + /* Auto download */ + int wifi_auto_download; /**< Auto attachment download in WiFi connection */ + + /* Authentication Options */ + int pop_before_smtp; /**< POP before SMTP Authentication */ + int incoming_server_requires_apop; /**< APOP authentication */ + + /* S/MIME Options */ + email_smime_type smime_type; /**< The smime type 0=Normal 1=Clear signed 2=encrypted 3=Signed + encrypted */ + char *certificate_path; /**< The certificate path of private */ + email_cipher_type cipher_type; /**< The encryption algorithm */ + email_digest_type digest_type; /**< The digest algorithm */ } email_account_t; /** - * This structure is used to save the information of certificate + * @brief The structure type to save the certificate information. + * @since_tizen 2.3 */ typedef struct { - int certificate_id; - int issue_year; - int issue_month; - int issue_day; - int expiration_year; - int expiration_month; - int expiration_day; - char *issue_organization_name; - char *email_address; - char *subject_str; - char *filepath; + int certificate_id; /**< The saved certificate ID */ + int issue_year; /**< The issue year information of certificate */ + int issue_month; /**< The issue month information of certificate */ + int issue_day; /**< The issue day information of certificate */ + int expiration_year; /**< The expiration year information of certificate */ + int expiration_month; /**< The expiration month information of certificate */ + int expiration_day; /**< The expiration day information of certificate */ + char *issue_organization_name; /**< The issue organization information of certificate */ + char *email_address; /**< The email address of certificate */ + char *subject_str; /**< The subject information of certificate */ + char *filepath; /**< The saved path of certificate */ } email_certificate_t; /** - * This structure is used to save the information of email server. + * @brief The structure type to save the email server information. + * @since_tizen 2.3 */ typedef struct { - int configuration_id; /**< Specifies the id of configuration.*/ - email_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.*/ + int configuration_id; /**< The configuration ID */ + email_account_server_t protocol_type; /**< The type of configuration */ + char *server_addr; /**< The address of configuration */ + int port_number; /**< The port number of configuration */ + int security_type; /**< The security such as SSL */ + int auth_type; /**< The authentication type of configuration */ } email_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.*/ - email_protocol_config_t *protocol_config_array; /**< Specifies array of protocol configurations.*/ + char *service_name; /**< The name of service */ + int authname_format; /**< The type of user name for authentication */ + int protocol_conf_count; /**< The count of protocol configurations */ + email_protocol_config_t *protocol_config_array; /**< The array of protocol configurations */ } email_server_info_t; typedef struct { - int mailbox_type; - char mailbox_name[MAILBOX_NAME_LENGTH]; + int mailbox_type; /**< The mailbox type */ + char mailbox_name[MAILBOX_NAME_LENGTH]; /**< The mailbox name */ } email_mailbox_type_item_t; /** - * This structure is contains the Mail information. + * @brief The structure type which contains the Mail information. + * @since_tizen 2.3 */ typedef struct { - int mail_id; /**< Specifies the Mail ID.*/ - int account_id; /**< Specifies the Account ID.*/ - int mailbox_id; /**< Specifies the Mailbox ID.*/ - email_mailbox_type_e mailbox_type; /**< Specifies the mailbox type of the mail. */ - char *subject; /**< Specifies the subject.*/ - time_t date_time; /**< 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 */ - int reference_mail_id; /**< Specifies the reference mail id */ - char *full_address_from; /**< Specifies the From address.*/ - char *full_address_reply; /**< Specifies the Reply to address */ - char *full_address_to; /**< Specifies the To address.*/ - char *full_address_cc; /**< Specifies the CC address.*/ - char *full_address_bcc; /**< Specifies the BCC address*/ - 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 downloaded or not.*/ - char *file_path_plain; /**< Specifies the path of text mail body.*/ - char *file_path_html; /**< Specifies the path of HTML mail body.*/ - char *file_path_mime_entity; /**< Specifies the path of MIME entity. */ - 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; /**< Has the mail DRM content? (1 : true, 0 : false) */ - email_mail_priority_t priority; /**< Specifies the priority of the mail.*/ - email_mail_status_t save_status; /**< Specifies the save status*/ - int lock_status; /**< Specifies the mail is locked*/ - email_mail_report_t 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. */ - email_mail_type_t meeting_request_status; /**< Specifies the status of meeting request. */ - int message_class; /**< Specifies the class of message for EAS. */ /* email_message_class */ - email_digest_type digest_type; /**< Specifies the digest algorithm*/ - email_smime_type smime_type; /**< Specifies the SMIME type. */ - time_t scheduled_sending_time; /**< Specifies the scheduled sending time.*/ - int remaining_resend_times; /**< Specifies the remaining resend times.*/ - int tag_id; /**< Specifies the data for filtering. */ - time_t replied_time; /**< Specifies the time of replied. */ - time_t forwarded_time; /**< Specifies the time of forwarded. */ - int eas_data_length; /**< Specifies the length of eas_data. */ - void *eas_data; /**< Extended Application Specific data. */ + int mail_id; /**< The Mail ID */ + int account_id; /**< The Account ID */ + int mailbox_id; /**< The mailbox ID */ + email_mailbox_type_e mailbox_type; /**< The mailbox type of the mail */ + char *subject; /**< The subject */ + time_t date_time; /**< The Date time */ + int server_mail_status; /**< The flag indicating whether sever mail or not */ + char *server_mailbox_name; /**< The server mailbox */ + char *server_mail_id; /**< The Server Mail ID */ + char *message_id; /**< The message ID */ + int reference_mail_id; /**< The reference mail ID */ + char *full_address_from; /**< The From address */ + char *full_address_reply; /**< The Reply to address */ + char *full_address_to; /**< The To address */ + char *full_address_cc; /**< The CC address */ + char *full_address_bcc; /**< The BCC address */ + char *full_address_return; /**< The return path */ + char *email_address_sender; /**< The email address of sender */ + char *email_address_recipient; /**< The email address of recipients */ + char *alias_sender; /**< The alias of sender */ + char *alias_recipient; /**< The alias of recipients */ + int body_download_status; /**< The text download status */ + char *file_path_plain; /**< The path of text mail body */ + char *file_path_html; /**< The path of HTML mail body */ + char *file_path_mime_entity; /**< The path of MIME entity */ + int mail_size; /**< The mail size */ + char flags_seen_field; /**< The seen flags */ + char flags_deleted_field; /**< The deleted flags */ + char flags_flagged_field; /**< The flagged flags */ + char flags_answered_field; /**< The answered flags */ + char flags_recent_field; /**< The recent flags */ + char flags_draft_field; /**< The draft flags */ + char flags_forwarded_field; /**< The forwarded flags */ + int DRM_status; /**< The flag indicating whether the mail has DRM content (1 : true, 0 : false) */ + email_mail_priority_t priority; /**< The priority of the mail */ + email_mail_status_t save_status; /**< The save status */ + int lock_status; /**< The mail is locked */ + email_mail_report_t report_status; /**< The mail report */ + int attachment_count; /**< The attachment count */ + int inline_content_count; /**< The inline content count */ + int thread_id; /**< The thread ID for thread view */ + int thread_item_count; /**< The item count of specific thread */ + char *preview_text; /**< The preview body */ + email_mail_type_t meeting_request_status; /**< The status of meeting request */ + int message_class; /**< The class of message for EAS */ /* email_message_class */ + email_digest_type digest_type; /**< The digest algorithm */ + email_smime_type smime_type; /**< The SMIME type */ + time_t scheduled_sending_time; /**< The scheduled sending time */ + int remaining_resend_times; /**< The remaining resend times */ + int tag_id; /**< The data for filtering */ + time_t replied_time; /**< The time of replied */ + time_t forwarded_time; /**< The time of forwarded */ + char *pgp_password; /**< The password of PGP. */ + int eas_data_length; /**< The length of eas_data */ + void *eas_data; /**< Extended Application Specific data */ } email_mail_data_t; /** - * This structure is contains information for displaying mail list. + * @brief The structure type which contains information for displaying a mail list. + * @since_tizen 2.3 */ typedef struct { - int mail_id; /**< Specifies the mail id.*/ - int account_id; /**< Specifies the account id.*/ - int mailbox_id; /**< Specifies the mailbox id.*/ - email_mailbox_type_e mailbox_type; /**< Specifies the mailbox type of the mail. */ - char full_address_from[STRING_LENGTH_FOR_DISPLAY]; /**< Specifies the full from email address.*/ - char email_address_sender[MAX_EMAIL_ADDRESS_LENGTH]; /**< Specifies the sender email address.*/ - char email_address_recipient[STRING_LENGTH_FOR_DISPLAY]; /**< Specifies the recipients email address.*/ - char subject[STRING_LENGTH_FOR_DISPLAY]; /**< Specifies the subject.*/ - int body_download_status; /**< Specifies the text donwloaded or not.*/ - int mail_size; /**< Specifies the mail size. */ - time_t date_time; /**< 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 DRM_status; /**< Has the mail DRM content? (1 : true, 0 : false) */ - email_mail_priority_t priority; /**< Specifies the priority of Mails.*/ /* email_mail_priority_t*/ - email_mail_status_t save_status; /**< Specifies the save status*/ /* email_mail_status_t */ - int lock_status; /**< Specifies the locked*/ - email_mail_report_t report_status; /**< Specifies the mail report.*/ /* email_mail_report_t */ - int attachment_count; /**< Specifies the attachment count. */ - int inline_content_count; /**< Specifies the inline content count. */ - char preview_text[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 */ - email_mail_type_t meeting_request_status; /**< Whether the mail is a meeting request or not */ /* email_mail_type_t */ - int message_class; /**< Specifies the message class */ /* email_message_class */ - email_smime_type smime_type; /**< Specifies the smime type */ /* email_smime_type */ - time_t scheduled_sending_time; /**< Specifies the scheduled sending time.*/ - int remaining_resend_times; /**< Specifies the remaining resend times.*/ - int tag_id; /**< Specifies the data for filtering */ - int eas_data_length; /**< Specifies the length of eas_data. */ - void *eas_data; /**< Extended Application Specific data. */ + int mail_id; /**< The mail ID */ + int account_id; /**< The account ID */ + int mailbox_id; /**< The mailbox ID */ + email_mailbox_type_e mailbox_type; /**< The mailbox type of the mail */ + char full_address_from[STRING_LENGTH_FOR_DISPLAY]; /**< The full from email address */ + char email_address_sender[MAX_EMAIL_ADDRESS_LENGTH]; /**< The sender email address */ + char email_address_recipient[STRING_LENGTH_FOR_DISPLAY]; /**< The recipients email address */ + char subject[STRING_LENGTH_FOR_DISPLAY]; /**< The subject */ + int body_download_status; /**< The text download status */ + int mail_size; /**< The mail size */ + time_t date_time; /**< The date time */ + char flags_seen_field; /**< The seen flags */ + char flags_deleted_field; /**< The deleted flags */ + char flags_flagged_field; /**< The flagged flags */ + char flags_answered_field; /**< The answered flags */ + char flags_recent_field; /**< The recent flags */ + char flags_draft_field; /**< The draft flags */ + char flags_forwarded_field; /**< The forwarded flags */ + int DRM_status; /**< The flag indicating whether the has mail DRM content (1 : true, 0 : false) */ + email_mail_priority_t priority; /**< The priority of mails */ /* email_mail_priority_t*/ + email_mail_status_t save_status; /**< The save status */ /* email_mail_status_t */ + int lock_status; /**< The lock status */ + email_mail_report_t report_status; /**< The mail report */ /* email_mail_report_t */ + int attachment_count; /**< The attachment count */ + int inline_content_count; /**< The inline content count */ + char preview_text[MAX_PREVIEW_TEXT_LENGTH]; /**< The text for preview body */ + int thread_id; /**< The thread ID for thread view */ + int thread_item_count; /**< The item count of specific thread */ + email_mail_type_t meeting_request_status; /**< The flag indicating whether the mail is a meeting request or not */ /* email_mail_type_t */ + int message_class; /**< The message class */ /* email_message_class */ + email_smime_type smime_type; /**< The smime type */ /* email_smime_type */ + time_t scheduled_sending_time; /**< The scheduled sending time */ + int remaining_resend_times; /**< The remaining resend times */ + int tag_id; /**< The data for filtering */ + int eas_data_length; /**< The length of eas_data */ + void *eas_data; /**< Extended Application Specific data */ } email_mail_list_item_t; /** - * This structure is used to save the filtering structure. + * @brief The structure type used to save the filtering structure. + * @since_tizen 2.3 */ typedef struct { - int account_id; /**< Specifies the account ID.*/ - int filter_id; /**< Specifies the filtering ID.*/ - char *filter_name; /**< Specifies the filtering name. */ - email_rule_type_t type; /**< Specifies the filtering type.*/ - char *value; /**< Specifies the filtering value : subject. */ - char *value2; /**< Specifies the filtering value2 : sender address. */ - email_rule_action_t faction; /**< Specifies the action type for filtering.*/ - int target_mailbox_id; /**< Specifies the mail box if action type means move.*/ - int flag1; /**< Specifies the activation.*/ - int flag2; /**< Reserved.*/ + int account_id; /**< The account ID */ + int filter_id; /**< The filtering ID */ + char *filter_name; /**< The filtering name */ + email_rule_type_t type; /**< The filtering type */ + char *value; /**< The filtering value : subject */ + char *value2; /**< The filtering value2 : sender address */ + email_rule_action_t faction; /**< The action type for filtering */ + int target_mailbox_id; /**< The mail box if action type means move */ + int flag1; /**< The activation */ + int flag2; /**< Reserved */ } email_rule_t; /** - * This structure is used to save the information of mail flag. + * @brief The structure type used to save the information of a mail flag. + * @since_tizen 2.3 */ 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 attachment_count : 1; /**< Reserved.*/ - unsigned int forwarded : 1; /**< Reserved.*/ - unsigned int sticky : 1; /**< Sticky flagged mails cannot be deleted */ + unsigned int seen : 1; /**< The read email */ + unsigned int deleted : 1; /**< The deleted email */ + unsigned int flagged : 1; /**< The flagged email */ + unsigned int answered : 1; /**< The answered email */ + unsigned int recent : 1; /**< The recent email */ + unsigned int draft : 1; /**< The draft email */ + unsigned int attachment_count : 1; /**< The attachment count */ + unsigned int forwarded : 1; /**< The forwarded email. */ + unsigned int sticky : 1; /**< The sticky flagged mails cannot be deleted */ } email_mail_flag_t /* DEPRECATED */; /** - * This structure is used to save the information of mail extra flag. + * @brief The structure type used to save the information of a mail extra flag. + * @since_tizen 2.3 */ typedef struct { - unsigned int priority : 3; /**< Specifies the mail priority. - The value is greater than or equal to EMAIL_MAIL_PRIORITY_HIGH. - The value is less than or equal to EMAIL_MAIL_PRIORITY_LOW.*/ - unsigned int status : 4; /**< Specifies the mail status. - The value is a value of enumeration email_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 email_mail_report_t.*/ - unsigned int drm : 1; /**< Specifies the drm mail.*/ - unsigned int text_download_yn : 2; /**< body download y/n*/ + unsigned int priority : 3; /**< The mail priority \n + The value is greater than or equal to EMAIL_MAIL_PRIORITY_HIGH. + The value is less than or equal to EMAIL_MAIL_PRIORITY_LOW.*/ + unsigned int status : 4; /**< The mail status \n + The value is a value of enumeration email_mail_status_t.*/ + unsigned int noti : 1; /**< The notified mail */ + unsigned int lock : 1; /**< The locked mail */ + unsigned int report : 2; /**< The MDN/DSN mail \n + The value is a value of enumeration email_mail_report_t.*/ + unsigned int drm : 1; /**< The DRM mail */ + unsigned int text_download_yn : 2; /**< The body download y/n */ } email_extra_flag_t DEPRECATED; /** - * This structure is used to save the information of attachment. + * @brief The structure type used to save the information of an attachment. + * @since_tizen 2.3 */ typedef struct { - int attachment_id; - char *attachment_name; - char *attachment_path; - int attachment_size; - int mail_id; - int account_id; - char mailbox_id; - int save_status; - int drm_status; - int inline_content_status; - char *attachment_mime_type; /**< Specifies the context mime type.*/ + int attachment_id; /**< The attachment ID */ + char *attachment_name; /**< The attachment name */ + char *attachment_path; /**< The path of a downloaded attachment */ + char *content_id; /**< The content ID string of an attachment */ + int attachment_size; /**< The size of an attachment */ + int mail_id; /**< The mail ID of an included attachment */ + int account_id; /**< The account ID of an included attachment */ + char mailbox_id; /**< The mailbox ID of an include attachment */ + int save_status; /**< The save status of an attachment */ + int drm_status; /**< The DRM status of an attachment */ + int inline_content_status; /**< The distinguished inline attachment and normal attachment */ + char *attachment_mime_type; /**< The context MIME type */ } email_attachment_data_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; + int offset_from_GMT; /**< The time from base GMT */ + char standard_name[32]; /**< The name of time zone */ + struct tm standard_time_start_date; /**< The start date of time zone */ + int standard_bias; /**< The bias of time zone */ + char daylight_name[32]; /**< The daylight name of time zone */ + struct tm daylight_time_start_date; /**< The daylight start date of time zone */ + int daylight_bias; /**< The daylight bias of time zone */ } email_time_zone_t; +/** + * @brief Structure used to save the information of a meeting request + * @since_tizen 2.3 + */ typedef struct { - int mail_id; /**< Specifies the mail id of meeting request on DB. This is the primary key. */ - email_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; /**< Specifies the object id. */ - email_time_zone_t time_zone; + int mail_id; /**< The mail ID of meeting request on DB <br> + This is the primary key. */ + email_meeting_response_t meeting_response; /**< The meeting response */ + struct tm start_time; /**< The meeting start time */ + struct tm end_time; /**< The meeting end time */ + char *location; /**< The location of meeting <br> + Maximum length of this string is 32768. */ + char *global_object_id; /**< The object ID */ + email_time_zone_t time_zone; /**< The time zone of meeting */ } email_meeting_request_t; /** - * This structure is used to save the information of sender list with unread/total mail counts + * @brief The structure type used to save the information of a sender list with unread/total mail counts. + * @since_tizen 2.3 */ 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*/ + char *address; /**< The address of a sender */ + char *display_name; /**< The display name <br> + 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; /**< The number of unread mails received from sender address */ + int total_count; /**< The total number of mails which are received from sender address */ } email_sender_list_t /* DEPRECATED */; /** - * This structure is used to save the information of mailbox. + * @brief The structure type used to save the information of a mailbox. + * @since_tizen 2.3 */ typedef struct { - int mailbox_id; /**< Unique id on mailbox table.*/ - char *mailbox_name; /**< Specifies the path of mailbox.*/ - email_mailbox_type_e mailbox_type; /**< Specifies the type of mailbox */ - 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 local; /**< Specifies the local mailbox.*/ - int account_id; /**< Specifies the account ID for mailbox.*/ - int mail_slot_size; /**< Specifies how many mails can be stored in local mailbox.*/ - int no_select; /**< Specifies the 'no_select' attribute from xlist.*/ - time_t last_sync_time; - int deleted_flag; /**< Specifies whether mailbox is deleted.*/ - int eas_data_length; /**< Specifies the length of eas_data. */ - void *eas_data; /**< Specifies the data for eas engine. */ + int mailbox_id; /**< The unique ID on mailbox table */ + char *mailbox_name; /**< The path of mailbox */ + email_mailbox_type_e mailbox_type; /**< The type of mailbox */ + char *alias; /**< The display name of mailbox */ + int unread_count; /**< The unread mail count in the mailbox */ + int total_mail_count_on_local; /**< The total number of mails in the mailbox in the local DB */ + int total_mail_count_on_server; /**< The total number of mails in the mailbox in the mail server */ + int local; /**< The local mailbox */ + int account_id; /**< The account ID for mailbox */ + int mail_slot_size; /**< The number of mails that can be stored in local mailbox */ + int no_select; /**< The 'no_select' attribute from xlist */ + time_t last_sync_time; /**< The last sync time of the mailbox */ + int deleted_flag; /**< The flag specifying whether mailbox is deleted */ + int eas_data_length; /**< The length of eas_data */ + void *eas_data; /**< The data for eas engine. */ } email_mailbox_t; +/** + * @brief Structure used to save the information of email a address. + * @since_tizen 2.3 + */ + typedef struct { - email_address_type_t address_type; - char *address; - char *display_name; - int storage_type; - int contact_id; + email_address_type_t address_type; /**< The address type using the email (TO, CC, BCC, etc..) */ + char *address; /**< The Email address */ + char *display_name; /**< The alias */ + int storage_type; /**< The type of saved storage on contact-service */ + int contact_id; /**< The ID of saved storage on contact-service */ } email_address_info_t; +/** + * @brief Structure used to save the set of email addresses + * @since_tizen 2.3 + */ typedef struct { - GList *from; - GList *to; - GList *cc; - GList *bcc; + GList *from; /**< The From address list */ + GList *to; /**< The TO address list */ + GList *cc; /**< The CC address list */ + GList *bcc; /**< The BCC address list */ } email_address_info_list_t; +/** + * @brief Structure used to save the list of email addresses + * @since_tizen 2.3 + */ typedef struct { - int address_type; /* type of mail (sender : 0, recipient : 1)*/ - int address_count; /* The number of email addresses */ - char **address_list; /* strings of email addresses */ + int address_type; /**< The type of mail (sender : 0, recipient : 1)*/ + int address_count; /**< The number of email addresses */ + char **address_list; /**< The strings of email addresses */ } email_email_address_list_t; +/** + * @brief Structure used to save the information of a search filter + * @since_tizen 2.3 + */ typedef struct _email_search_filter_t { - email_search_filter_type search_filter_type; /* type of search filter */ - union { - int integer_type_key_value; - time_t time_type_key_value; - char *string_type_key_value; - } search_filter_key_value; + email_search_filter_type search_filter_type; /**< The type of search filter */ + union { + int integer_type_key_value; /**< The integer value for searching */ + time_t time_type_key_value; /**< The time value for searching */ + char *string_type_key_value; /**< The string value for searching */ + } search_filter_key_value; /**< The key value of search filter */ } email_search_filter_t; typedef enum { - EMAIL_LIST_FILTER_RULE_EQUAL = 0, - EMAIL_LIST_FILTER_RULE_NOT_EQUAL = 1, - EMAIL_LIST_FILTER_RULE_LESS_THAN = 2, - EMAIL_LIST_FILTER_RULE_GREATER_THAN = 3, - EMAIL_LIST_FILTER_RULE_LESS_THAN_OR_EQUAL = 4, - EMAIL_LIST_FILTER_RULE_GREATER_THAN_OR_EQUAL = 5, - EMAIL_LIST_FILTER_RULE_INCLUDE = 6, - EMAIL_LIST_FILTER_RULE_MATCH = 7, - EMAIL_LIST_FILTER_RULE_IN = 8, - EMAIL_LIST_FILTER_RULE_NOT_IN = 9 + EMAIL_LIST_FILTER_RULE_EQUAL = 0, /**< EQUAL(=) of filter type */ + EMAIL_LIST_FILTER_RULE_NOT_EQUAL = 1, /**< NOT EQUAL(!=) of filter type */ + EMAIL_LIST_FILTER_RULE_LESS_THAN = 2, /**< LESS THAN(<) of filter type */ + EMAIL_LIST_FILTER_RULE_GREATER_THAN = 3, /**< GREATER THAN(>) of filter type */ + EMAIL_LIST_FILTER_RULE_LESS_THAN_OR_EQUAL = 4, /**< LESS THAN OR EQUAL(<=) of filter type */ + EMAIL_LIST_FILTER_RULE_GREATER_THAN_OR_EQUAL = 5, /**< GREATER THAN OR EQUAL(>=) of filter type */ + EMAIL_LIST_FILTER_RULE_INCLUDE = 6, /**< LIKE operator in SQL statements */ + EMAIL_LIST_FILTER_RULE_MATCH = 7, /**< MATCH operator in SQL statements */ + EMAIL_LIST_FILTER_RULE_IN = 8, /**< IN operator in SQL statements */ + EMAIL_LIST_FILTER_RULE_NOT_IN = 9 /**< NOT IN operator in SQL statements */ } email_list_filter_rule_type_t; typedef enum { - EMAIL_CASE_SENSITIVE = 0, - EMAIL_CASE_INSENSITIVE = 1, + EMAIL_CASE_SENSITIVE = 0, /**< Case sensitive search */ + EMAIL_CASE_INSENSITIVE = 1, /**< Case insensitive search */ } email_list_filter_case_sensitivity_t; typedef union { - int integer_type_value; - char *string_type_value; - time_t datetime_type_value; + int integer_type_value; /**< Container for integer type value */ + char *string_type_value; /**< Container for string type value */ + time_t datetime_type_value; /**< Container for datetime type value */ } email_mail_attribute_value_t; typedef struct { - email_list_filter_rule_type_t rule_type; - email_mail_attribute_type target_attribute; - email_mail_attribute_value_t key_value; - email_list_filter_case_sensitivity_t case_sensitivity; + email_list_filter_rule_type_t rule_type; /**< Operator type of the filter rule */ + email_mail_attribute_type target_attribute; /**< Target attribute type of the filter rule */ + email_mail_attribute_value_t key_value; /**< Target attribute value of the filter rule */ + email_list_filter_case_sensitivity_t case_sensitivity; /**< Specifies case sensitivity of the filter rule */ } email_list_filter_rule_t; typedef struct { - email_list_filter_rule_type_t rule_type; - email_mail_text_attribute_type target_attribute; - email_mail_attribute_value_t key_value; + email_list_filter_rule_type_t rule_type; /**< Operator type of the filter rule for full text search */ + email_mail_text_attribute_type target_attribute; /**< Target attribute type of the filter rule */ + email_mail_attribute_value_t key_value; /**< Target attribute value of the filter rule */ } email_list_filter_rule_fts_t; typedef struct { - email_list_filter_rule_type_t rule_type; - email_mail_attach_attribute_type target_attribute; - email_mail_attribute_value_t key_value; - email_list_filter_case_sensitivity_t case_sensitivity; + email_list_filter_rule_type_t rule_type; /**< Operator type of the filter rule for searching attachment */ + email_mail_attach_attribute_type target_attribute; /**< Target attribute type of the filter rule */ + email_mail_attribute_value_t key_value; /**< Target attribute value of the filter rule */ + email_list_filter_case_sensitivity_t case_sensitivity; /**< Specifies case sensitivity of the filter rule */ } email_list_filter_rule_attach_t; typedef enum { - EMAIL_LIST_FILTER_ITEM_RULE = 0, - EMAIL_LIST_FILTER_ITEM_RULE_FTS = 1, - EMAIL_LIST_FILTER_ITEM_RULE_ATTACH = 2, - EMAIL_LIST_FILTER_ITEM_OPERATOR = 3, + EMAIL_LIST_FILTER_ITEM_RULE = 0, /**< Normal search rule */ + EMAIL_LIST_FILTER_ITEM_RULE_FTS = 1, /**< Full text search rule */ + EMAIL_LIST_FILTER_ITEM_RULE_ATTACH = 2, /**< Searching attachment rule */ + EMAIL_LIST_FILTER_ITEM_OPERATOR = 3, /**< Operator */ } email_list_filter_item_type_t; typedef enum { - EMAIL_LIST_FILTER_OPERATOR_AND = 0, - EMAIL_LIST_FILTER_OPERATOR_OR = 1, - EMAIL_LIST_FILTER_OPERATOR_LEFT_PARENTHESIS = 2, - EMAIL_LIST_FILTER_OPERATOR_RIGHT_PARENTHESIS = 3 + EMAIL_LIST_FILTER_OPERATOR_AND = 0, /**< AND operator */ + EMAIL_LIST_FILTER_OPERATOR_OR = 1, /**< OR operator */ + EMAIL_LIST_FILTER_OPERATOR_LEFT_PARENTHESIS = 2, /**< ( operator */ + EMAIL_LIST_FILTER_OPERATOR_RIGHT_PARENTHESIS = 3 /**< ) operator */ } email_list_filter_operator_type_t; +/** + * @brief Structure used to save the information of a list filter + * @since_tizen 2.3 + */ typedef struct { - email_list_filter_item_type_t list_filter_item_type; + email_list_filter_item_type_t list_filter_item_type; /**< Filter item type */ - union { - email_list_filter_rule_t rule; - email_list_filter_rule_fts_t rule_fts; - email_list_filter_rule_attach_t rule_attach; - email_list_filter_operator_type_t operator_type; - } list_filter_item; + union { + email_list_filter_rule_t rule; /**< Rule type */ + email_list_filter_rule_fts_t rule_fts; /**< Rule type for full text search */ + email_list_filter_rule_attach_t rule_attach; /**< Rule type for searching attachment */ + email_list_filter_operator_type_t operator_type; /**< Operator type */ + } list_filter_item; /**< filter item of list */ } email_list_filter_t; typedef enum { - EMAIL_SORT_ORDER_ASCEND = 0, - EMAIL_SORT_ORDER_DESCEND = 1, - EMAIL_SORT_ORDER_TO_CCBCC = 2, - EMAIL_SORT_ORDER_TO_CC_BCC = 3, - EMAIL_SORT_ORDER_TO_CCBCC_ALL = 4 + EMAIL_SORT_ORDER_ASCEND = 0, /**< Ascending order sorting */ + EMAIL_SORT_ORDER_DESCEND = 1, /**< Descending order sorting */ + EMAIL_SORT_ORDER_TO_CCBCC = 2, /**< full_address_to sorting */ + EMAIL_SORT_ORDER_TO_CC_BCC = 3, /**< full_address_to, full_address_cc sorting */ + EMAIL_SORT_ORDER_TO_CCBCC_ALL = 4, /**< full_address_to of all account sorting */ + EMAIL_SORT_ORDER_NOCASE_ASCEND = 5, /**< Ascending order with COLLATE NOCASE option*/ + EMAIL_SORT_ORDER_NOCASE_DESCEND = 6, /**< Descending order with COLLATE NOCASE option */ + EMAIL_SORT_ORDER_LOCALIZE_ASCEND = 7, /**< Localize ascending order sorting */ + EMAIL_SORT_ORDER_LOCALIZE_DESCEND = 8 /**< Localize descending order sorting */ } email_list_filter_sort_order_t; typedef struct { - email_mail_attribute_type target_attribute; - email_mail_attribute_value_t key_value; - bool force_boolean_check; - email_list_filter_sort_order_t sort_order; + email_mail_attribute_type target_attribute; /**< The attribute type of mail for sorting*/ + email_mail_attribute_value_t key_value; /**< The attribute value of mail for sorting*/ + bool force_boolean_check; /**< The distinguished true/false for sorting */ + email_list_filter_sort_order_t sort_order; /**< The ordering rule for sorting */ } email_list_sorting_rule_t; typedef struct { - int handle; - int account_id; - email_event_type_t type; - email_event_status_type_t status; + int handle; /**< The job handle to be canceled */ + int account_id; /**< The account ID for task information */ + email_event_type_t type; /**< The type for task information */ + email_event_status_type_t status; /**< The status for task information */ } email_task_information_t; typedef enum { - EMAIL_MESSAGE_CONTEXT_VOICE_MESSAGE = 1, - EMAIL_MESSAGE_CONTEXT_VIDEO_MESSAGE = 2, - EMAIL_MESSAGE_CONTEXT_FAX_MESSAGE = 3, - EMAIL_MESSAGE_CONTEXT_X_EMPTY_CALL_CAPTURE_MESSAGE = 4, - EMAIL_MESSAGE_CONTEXT_X_NUMBER_MESSAGE = 5, - EMAIL_MESSAGE_CONTEXT_X_VOICE_INFOTAINMENT_MESSAGE = 6 + EMAIL_MESSAGE_CONTEXT_VOICE_MESSAGE = 1, /**< Voice message context */ + EMAIL_MESSAGE_CONTEXT_VIDEO_MESSAGE = 2, /**< Video message context */ + EMAIL_MESSAGE_CONTEXT_FAX_MESSAGE = 3, /**< Fax message context */ + EMAIL_MESSAGE_CONTEXT_X_EMPTY_CALL_CAPTURE_MESSAGE = 4, /**< X empty call capture message context */ + EMAIL_MESSAGE_CONTEXT_X_NUMBER_MESSAGE = 5, /**< X number message context */ + EMAIL_MESSAGE_CONTEXT_X_VOICE_INFOTAINMENT_MESSAGE = 6 /**< X voice infotainment message context */ } email_message_context_t; typedef enum { - EMAIL_MESSAGE_SENSITIVITY_PRIVATE = 1, - EMAIL_MESSAGE_SENSITIVITY_CONFIDENTIAL = 2, - EMAIL_MESSAGE_SENSITIVITY_PERSONAL = 3 + EMAIL_MESSAGE_SENSITIVITY_PRIVATE = 1, /**< Private sensitivity of message */ + EMAIL_MESSAGE_SENSITIVITY_CONFIDENTIAL = 2, /**< Confidential sensitivity of message */ + EMAIL_MESSAGE_SENSITIVITY_PERSONAL = 3 /**< Personal sensitivity of message */ } email_message_sensitivity_t; typedef struct { - email_message_context_t message_context; - int content_length; /* Content-Duration for audio/video or X-Content-Pages for fax */ - email_message_sensitivity_t sensitivity; + email_message_context_t message_context; /**< Message context for visual voice mail */ + int content_length; /**< Content-Duration for audio/video or X-Content-Pages for fax */ + email_message_sensitivity_t sensitivity; /**< Sensitivity of message for visual voice mail */ } email_vvm_specific_data_t; typedef struct { - char *quota_root; - char *resource_name; - int usage; - int limits; + char *quota_root; /**< Quota root for IMAP quota */ + char *resource_name; /**< Resource name for IMAP quota */ + int usage; /**< Usage for IMAP quota */ + int limits; /**< Limit for IMAP quota */ } email_quota_resource_t; /*****************************************************************************/ @@ -1738,294 +1990,296 @@ typedef struct { 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 */ - ACTIVE_SYNC_NOTI_CLEAR_RESULT_OF_SEARCH_ON_SERVER, /* a notification for clearing result of search on server to AS */ - ACTIVE_SYNC_NOTI_EXPUNGE_MAILS_DELETED_FLAGGED, /* a notification to expunge deleted flagged mails */ - ACTIVE_SYNC_NOTI_RESOLVE_RECIPIENT, /* a notification to get the resolve recipients */ - ACTIVE_SYNC_NOTI_VALIDATE_CERTIFICATE, /* a notification to validate certificate */ - ACTIVE_SYNC_NOTI_ADD_MAILBOX, /* a notification to add mailbox */ - ACTIVE_SYNC_NOTI_RENAME_MAILBOX, /* a notification to rename mailbox */ - ACTIVE_SYNC_NOTI_DELETE_MAILBOX, /* a notification to delete mailbox */ - ACTIVE_SYNC_NOTI_CANCEL_SENDING_MAIL, /* a notification to cancel a sending mail */ - ACTIVE_SYNC_NOTI_DELETE_MAILBOX_EX, /* a notification to delete multiple mailboxes */ - ACTIVE_SYNC_NOTI_SEND_MAIL_WITH_DOWNLOADING_OF_ORIGINAL_MAIL, /* a notification to send a mail with downloading attachment of original mail */ - ACTIVE_SYNC_NOTI_SCHEDULE_SENDING_MAIL, /* a notification to schedule a mail to send later*/ -} eactivesync_noti_t; + ACTIVE_SYNC_NOTI_SEND_MAIL, /**< Sending notification to ASE (active sync engine) */ + ACTIVE_SYNC_NOTI_SEND_SAVED, /**< Sending notification to ASE (active sync engine), all saved mails should be sent */ + ACTIVE_SYNC_NOTI_SEND_REPORT, /**< Sending notification to ASE (active sync engine), report should be sent */ + ACTIVE_SYNC_NOTI_SYNC_HEADER, /**< Sync header - download mails from server <br> + It depends on account/s flag1 field whether it executes 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, /**< Downloading body notification to AS */ + ACTIVE_SYNC_NOTI_DOWNLOAD_ATTACHMENT, /**< Downloading attachment notification to AS */ + ACTIVE_SYNC_NOTI_VALIDATE_ACCOUNT, /**< Account validating notification to AS */ + ACTIVE_SYNC_NOTI_CANCEL_JOB, /**< Canceling job notification to AS */ + ACTIVE_SYNC_NOTI_SEARCH_ON_SERVER, /**< Searching on server notification to AS */ + ACTIVE_SYNC_NOTI_CLEAR_RESULT_OF_SEARCH_ON_SERVER, /**< Notification for clearing result of search on server to AS */ + ACTIVE_SYNC_NOTI_EXPUNGE_MAILS_DELETED_FLAGGED, /**< Notification to expunge deleted flagged mails */ + ACTIVE_SYNC_NOTI_RESOLVE_RECIPIENT, /**< Notification to get the resolve recipients */ + ACTIVE_SYNC_NOTI_VALIDATE_CERTIFICATE, /**< Notification to validate certificate */ + ACTIVE_SYNC_NOTI_ADD_MAILBOX, /**< Notification to add mailbox */ + ACTIVE_SYNC_NOTI_RENAME_MAILBOX, /**< Notification to rename mailbox */ + ACTIVE_SYNC_NOTI_DELETE_MAILBOX, /**< Notification to delete mailbox */ + ACTIVE_SYNC_NOTI_CANCEL_SENDING_MAIL, /**< Notification to cancel a sending mail */ + ACTIVE_SYNC_NOTI_DELETE_MAILBOX_EX, /**< Notification to delete multiple mailboxes */ + ACTIVE_SYNC_NOTI_SEND_MAIL_WITH_DOWNLOADING_OF_ORIGINAL_MAIL, /**< Notification to send a mail with downloading attachment of original mail */ + ACTIVE_SYNC_NOTI_SCHEDULE_SENDING_MAIL, /**< Notification to schedule a mail to send later*/ +} eactivesync_noti_t; typedef union { - struct _send_mail - { - int handle; - int account_id; - int mail_id; - } 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; - int mailbox_id; - } 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; - int attachment_order; - } download_attachment; - - struct _cancel_job - { - int account_id; - int handle; /* job handle to be canceled. this value is issued by email-service. */ - int cancel_type; - } cancel_job; - - struct _validate_account - {/* not defined yet */ - int handle; - int account_id; - } validate_account; - - struct _search_mail_on_server - { - int handle; - int account_id; - int mailbox_id; - email_search_filter_t *search_filter_list; - int search_filter_count; - } search_mail_on_server; - - struct _clear_result_of_search_mail_on_server - { - int handle; - int account_id; - } clear_result_of_search_mail_on_server; - - struct _expunge_mails_deleted_flagged - { - int handle; - int account_id; - int mailbox_id; - int on_server; - } expunge_mails_deleted_flagged; - - struct _get_resolve_recipients - { - int handle; - int account_id; - char *email_address; - } get_resolve_recipients; - - struct _validate_certificate - { - int handle; - int account_id; - char *email_address; - } validate_certificate; - - struct _add_mailbox - { - int handle; - int account_id; - char *mailbox_path; - char *mailbox_alias; - void *eas_data; - int eas_data_length; - } add_mailbox; - - struct _rename_mailbox - { - int handle; - int account_id; - int mailbox_id; - char *mailbox_name; - char *mailbox_alias; - void *eas_data; - int eas_data_length; - } rename_mailbox; - - struct _delete_mailbox - { - int handle; - int account_id; - int mailbox_id; - } delete_mailbox; - - struct _cancel_sending_mail - { - int handle; - int account_id; - int mail_id; - } cancel_sending_mail; - - struct _delete_mailbox_ex - { - int handle; - int account_id; - int *mailbox_id_array; - int mailbox_id_count; - int on_server; - } delete_mailbox_ex; - - struct _send_mail_with_downloading_attachment_of_original_mail - { - int handle; - int account_id; - int mail_id; - } send_mail_with_downloading_attachment_of_original_mail; - - struct _schedule_sending_mail - { - int handle; - int account_id; - int mail_id; - time_t scheduled_time; - } schedule_sending_mail; + struct _send_mail + { + int handle; /**< The job handle to be canceled. This value is issued by email-service. */ + int account_id; /**< The account ID for sending the mail */ + int mail_id; /**< The mail ID for sending the mail */ + } send_mail; /**< Noti data for sending the mail */ + + struct _send_mail_saved + {/* not defined ye */ + int handle; /**< The job handle to be canceled. This value is issued by email-service. */ + int account_id; /**< The account ID for sending the saved mail */ + } send_mail_saved; /**< Noti data for sending the saved mail */ + + struct _send_report + {/* not defined ye */ + int handle; /**< The job handle to be canceled. This value is issued by email-service. */ + int account_id; /**< The account ID for sending the report */ + } send_report; /**< Noti data for sending the report */ + + struct _sync_header + { + int handle; /**< The job handle to be canceled. This value is issued by email-service. */ + int account_id; /**< The account ID for syncing the header */ + int mailbox_id; /**< The mailbox ID for syncing the header */ + } sync_header; /**< Noti data for syncing the header */ + + struct _download_body + { + int handle; /**< The job handle to be canceled. This value is issued by email-service. */ + int account_id; /**< The account ID for downloading the body */ + int mail_id; /**< The mail ID for downloading the body */ + int with_attachment; /**< 0: without attachments, 1: with attachment */ + } download_body; /**< Noti data for downloading the body */ + + struct _download_attachment + { + int handle; /**< The job handle to be canceled. This value is issued by email-service. */ + int account_id; /**< The account ID for downloading the attachment */ + int mail_id; /**< The mail ID for downloading the attachment */ + int attachment_order; /**< The ordered attachment for downloading the attachment */ + } download_attachment; /**< Noti data for downloading the attachment */ + + struct _cancel_job + { + int account_id; /**< The account ID for canceling the job */ + int handle; /**< The job handle to be canceled. This value is issued by email-service. */ + int cancel_type; /**< The canceling type for canceling the job */ + } cancel_job; /**< Noti data for canceling the job */ + + struct _validate_account + {/* not defined yet */ + int handle; /**< The job handle to be canceled. This value is issued by email-service. */ + int account_id; /**< The account ID for validating the account */ + } validate_account; /**< Noti data for validating the account */ + + struct _search_mail_on_server + { + int handle; /**< The job handle to be canceled. This value is issued by email-service. */ + int account_id; /**< The account ID for searching the mail on server */ + int mailbox_id; /**< The mailbox ID for searching the mail on server */ + email_search_filter_t *search_filter_list; /**< The list of search filter for searching the mail on server */ + int search_filter_count; /**< The count of search filter for searching the mail on server */ + } search_mail_on_server; /**< Noti data for searching the mail on server */ + + struct _clear_result_of_search_mail_on_server + { + int handle; /**< The job handle to be canceled. This value is issued by email-service. */ + int account_id; /**< The account ID for clearing the result of search mail on server */ + } clear_result_of_search_mail_on_server; /**< Noti data for clearing the result of search mail on server */ + + struct _expunge_mails_deleted_flagged + { + int handle; /**< The job handle to be canceled. This value is issued by email-service. */ + int account_id; /**< The account ID for expunging the mails flagged for deleting */ + int mailbox_id; /**< The mailbox ID for expunging the mails flagged for deleting */ + int on_server; /**< The flag indicating whether the mail is on server for expunging the mails flagged for deleting */ + } expunge_mails_deleted_flagged; /**< Noti data for expunging the mails flagged for deleting */ + + struct _get_resolve_recipients + { + int handle; /**< The job handle to be canceled. This value is issued by email-service. */ + int account_id; /**< The account ID for getting the resolve recipients */ + char *email_address; /**< The email address for getting the resolve recipients */ + } get_resolve_recipients; /**< Noti data for getting the resolve recipients */ + + struct _validate_certificate + { + int handle; /**< The job handle to be canceled. This value is issued by email-service. */ + int account_id; /**< The account ID for validating the certificate */ + char *email_address; /**< The email address for validating the certifiate */ + } validate_certificate; /**< Noti data for validating the certificate */ + + struct _add_mailbox + { + int handle; /**< The job handle to be canceled. This value is issued by email-service. */ + int account_id; /**< The account ID for adding the mailbox */ + char *mailbox_path; /**< The path of mailbox for adding the mailbox */ + char *mailbox_alias; /**< The alias of mailbox for adding the mailbox */ + void *eas_data; /**< The eas-data for adding the mailbox */ + int eas_data_length; /**< The length of eas-data for adding the mailbox */ + } add_mailbox; /**< Noti data for adding the mailbox */ + + struct _rename_mailbox + { + int handle; /**< The job handle to be canceled. This value is issued by email-service. */ + int account_id; /**< The account ID for renaming the mailbox */ + int mailbox_id; /**< The mailbox ID for renaming the mailbox */ + char *mailbox_name; /**< The mailbox name for renaming the mailbox */ + char *mailbox_alias; /**< The alias of mailbox for renaming the mailbox */ + void *eas_data; /**< The eas-data for renaming the mailbox */ + int eas_data_length; /**< The length of eas-data for renaming the mailbox */ + } rename_mailbox; /**< Noti data for renaming the mailbox */ + + struct _delete_mailbox + { + int handle; /**< The job handle to be canceled. This value is issued by email-service. */ + int account_id; /**< The account ID for deleting mailbox */ + int mailbox_id; /**< The mailbox ID for deleting mailbox */ + } delete_mailbox; /**< Noti data for deleting mailbox */ + + struct _cancel_sending_mail + { + int handle; /**< The job handle to be canceled. This value is issued by email-service. */ + int account_id; /**< The account ID for canceled sending mail */ + int mail_id; /**< The mail ID for canceled sending mail */ + } cancel_sending_mail; /**< Noti data for canceled sending mail */ + + struct _delete_mailbox_ex + { + int handle; /**< The job handle to be canceled. This value is issued by email-service. */ + int account_id; /**< The account ID for deleting mailbox (extention) */ + int *mailbox_id_array; /**< The mailbox ID array for deleting mailbox (extention) */ + int mailbox_id_count; /**< The mailbox ID count for deleting mailbox (extention) */ + int on_server; /**< The on server for deleting mailbox (extention) */ + } delete_mailbox_ex; /**< Noti data for deleting mailbox (extention) */ + + struct _send_mail_with_downloading_attachment_of_original_mail + { + int handle; /**< The job handle to be canceled. This value is issued by email-service. */ + int account_id; /**< The account ID for downloading attachment */ + int mail_id; /**< The mail ID for download attachment */ + } send_mail_with_downloading_attachment_of_original_mail; /**< Noti data for send mail with downloading attachment of original mail */ + + struct _schedule_sending_mail + { + int handle; /**< The job handle to be canceled. This value is issued by email-service. */ + int account_id; /**< The account ID for scheduled sending mail */ + int mail_id; /**< The mail ID for scheduled sending mail */ + time_t scheduled_time; /**< The scheduled time for scheduled sending mail */ + } schedule_sending_mail; /**< Noti data for schedule sending mail */ } ASNotiData; -/* types for noti string */ +/** @brief Enumeration for noti string types. + * @since_tizen 2.3 */ typedef enum { - EMAIL_CONVERT_STRUCT_TYPE_MAIL_LIST_ITEM, /** specifies email_mail_list_t */ + EMAIL_CONVERT_STRUCT_TYPE_MAIL_LIST_ITEM, /**< specifies email_mail_list_t */ } email_convert_struct_type_e; -/* Tasks */ +/** @brief Enumeration for task types. + * @since_tizen 2.3 */ typedef enum { - /* Sync tasks */ - EMAIL_SYNC_TASK_BOUNDARY_START = 11000, - /* Sync tasks for account - from 11000 */ - EMAIL_SYNC_TASK_ADD_ACCOUNT = 11010, - EMAIL_SYNC_TASK_DELETE_ACCOUNT = 11020, - EMAIL_SYNC_TASK_UPDATE_ACCOUNT = 11030, - EMAIL_SYNC_TASK_GET_ACCOUNT = 11040, - EMAIL_SYNC_TASK_GET_ACCOUNT_LIST = 11050, - EMAIL_SYNC_TASK_BACKUP_ACCOUNTS = 11060, - EMAIL_SYNC_TASK_RESTORE_ACCOUNTS = 11070, - EMAIL_SYNC_TASK_GET_PASSWORD_LENGTH_OF_ACCOUNT = 11090, - - /* Sync tasks for mailbox - from 12000 */ - EMAIL_SYNC_TASK_GET_MAILBOX_COUNT = 12010, - EMAIL_SYNC_TASK_GET_MAILBOX_LIST = 12020, - EMAIL_SYNC_TASK_GET_SUB_MAILBOX_LIST = 12030, - EMAIL_SYNC_TASK_SET_MAIL_SLOT_SIZE = 12040, - EMAIL_SYNC_TASK_SET_MAILBOX_TYPE = 12050, - EMAIL_SYNC_TASK_SET_LOCAL_MAILBOX = 12060, - - /* Sync tasks for mail - from 13000 */ - EMAIL_SYNC_TASK_GET_ATTACHMENT = 13010, - EMAIL_SYNC_TASK_CLEAR_RESULT_OF_SEARCH_MAIL_ON_SERVER = 13020, - EMAIL_SYNC_TASK_SCHEDULE_SENDING_MAIL = 13030, - EMAIL_SYNC_TASK_UPDATE_ATTRIBUTE = 13040, - - /* Sync tasks for mail thread - from 14000 */ - - /* Sync tasks for rule - from 15000 */ - - /* Sync tasks for etc - from 16000 */ - EMAIL_SYNC_TASK_BOUNDARY_END = 59999, - /* Async tasks */ - EMAIL_ASYNC_TASK_BOUNDARY_START = 60000, - /* Async tasks for account - from 61000 */ - EMAIL_ASYNC_TASK_VALIDATE_ACCOUNT = 61010, - EMAIL_ASYNC_TASK_ADD_ACCOUNT_WITH_VALIDATION = 61020, - - /* Async tasks for mailbox - from 62000 */ - EMAIL_ASYNC_TASK_ADD_MAILBOX = 62010, - EMAIL_ASYNC_TASK_DELETE_MAILBOX = 62020, - EMAIL_ASYNC_TASK_RENAME_MAILBOX = 62030, - EMAIL_ASYNC_TASK_DOWNLOAD_IMAP_MAILBOX_LIST = 62040, - EMAIL_ASYNC_TASK_DELETE_MAILBOX_EX = 62050, - - /* Async tasks for mail - from 63000 */ - EMAIL_ASYNC_TASK_ADD_MAIL = 63010, - EMAIL_ASYNC_TASK_ADD_READ_RECEIPT = 63020, - - EMAIL_ASYNC_TASK_UPDATE_MAIL = 63030, - - EMAIL_ASYNC_TASK_DELETE_MAIL = 63040, - EMAIL_ASYNC_TASK_DELETE_ALL_MAIL = 63050, - EMAIL_ASYNC_TASK_EXPUNGE_MAILS_DELETED_FLAGGED = 63060, - - EMAIL_ASYNC_TASK_MOVE_MAIL = 63070, - EMAIL_ASYNC_TASK_MOVE_ALL_MAIL = 63080, - EMAIL_ASYNC_TASK_MOVE_MAILS_TO_MAILBOX_OF_ANOTHER_ACCOUNT = 63090, - - EMAIL_ASYNC_TASK_SET_FLAGS_FIELD = 63300, - - EMAIL_ASYNC_TASK_DOWNLOAD_MAIL_LIST = 63400, - EMAIL_ASYNC_TASK_DOWNLOAD_BODY = 63410, - EMAIL_ASYNC_TASK_DOWNLOAD_ATTACHMENT = 63420, - - EMAIL_ASYNC_TASK_SEND_MAIL = 63500, - EMAIL_ASYNC_TASK_SEND_SAVED = 63510, - EMAIL_ASYNC_TASK_SEND_MAIL_WITH_DOWNLOADING_ATTACHMENT_OF_ORIGINAL_MAIL = 63520, - - EMAIL_ASYNC_TASK_SEARCH_MAIL_ON_SERVER = 63600, - - /* Async tasks for mail thread - from 64000 */ - EMAIL_ASYNC_TASK_MOVE_THREAD_TO_MAILBOX = 64010, - EMAIL_ASYNC_TASK_DELETE_THREAD = 64020, - EMAIL_ASYNC_TASK_MODIFY_SEEN_FLAG_OF_THREAD = 64030, - - /* Async tasks for rule - from 65000 */ - - /* Async tasks for etc - from 66000 */ - EMAIL_ASYNC_TASK_BOUNDARY_END = 99999, + /* Sync tasks */ + EMAIL_SYNC_TASK_BOUNDARY_START = 11000, /**< Sync task for boundary start */ + /* Sync tasks for account - from 11000 */ + EMAIL_SYNC_TASK_ADD_ACCOUNT = 11010, /**< Sync task for adding the account */ + EMAIL_SYNC_TASK_DELETE_ACCOUNT = 11020, /**< Sync task for deleting the account */ + EMAIL_SYNC_TASK_UPDATE_ACCOUNT = 11030, /**< Sync task for updating the account */ + EMAIL_SYNC_TASK_GET_ACCOUNT = 11040, /**< Sync task for getting the account */ + EMAIL_SYNC_TASK_GET_ACCOUNT_LIST = 11050, /**< Sync task for getting the account list */ + EMAIL_SYNC_TASK_BACKUP_ACCOUNTS = 11060, /**< Sync task for backup the account */ + EMAIL_SYNC_TASK_RESTORE_ACCOUNTS = 11070, /**< Sync task for restoring the account */ + EMAIL_SYNC_TASK_GET_PASSWORD_LENGTH_OF_ACCOUNT = 11090, /**< Sync task for getting the password length of account */ + + /* Sync tasks for mailbox - from 12000 */ + EMAIL_SYNC_TASK_GET_MAILBOX_COUNT = 12010, /**< Sync task for getting the mailbox count */ + EMAIL_SYNC_TASK_GET_MAILBOX_LIST = 12020, /**< Sync task for getting the mailbox list */ + EMAIL_SYNC_TASK_GET_SUB_MAILBOX_LIST = 12030, /**< Sync task for getting the sub-mailbox list */ + EMAIL_SYNC_TASK_SET_MAIL_SLOT_SIZE = 12040, /**< Sync task for setting the mail slot size */ + EMAIL_SYNC_TASK_SET_MAILBOX_TYPE = 12050, /**< Sync task for setting the mailbox type */ + EMAIL_SYNC_TASK_SET_LOCAL_MAILBOX = 12060, /**< Sync task for setting the local mailbox */ + + /* Sync tasks for mail - from 13000 */ + EMAIL_SYNC_TASK_GET_ATTACHMENT = 13010, /**< Sync task for getting the attachment */ + EMAIL_SYNC_TASK_CLEAR_RESULT_OF_SEARCH_MAIL_ON_SERVER = 13020, /**< Sync task for clearing the result of search mail on server */ + EMAIL_SYNC_TASK_SCHEDULE_SENDING_MAIL = 13030, /**< Sync task for scheduling the sending mail */ + EMAIL_SYNC_TASK_UPDATE_ATTRIBUTE = 13040, /**< Sync task for updating the attribute */ + + /* Sync tasks for mail thread - from 14000 */ + + /* Sync tasks for rule - from 15000 */ + + /* Sync tasks for etc - from 16000 */ + EMAIL_SYNC_TASK_BOUNDARY_END = 59999, /**< Sync task for boundary end */ + /* Async tasks */ + EMAIL_ASYNC_TASK_BOUNDARY_START = 60000, /**< Async task for boundary start */ + /* Async tasks for account - from 61000 */ + EMAIL_ASYNC_TASK_VALIDATE_ACCOUNT = 61010, /**< Async task for validating the account */ + EMAIL_ASYNC_TASK_ADD_ACCOUNT_WITH_VALIDATION = 61020, /**< Async task for adding the account with validation */ + + /* Async tasks for mailbox - from 62000 */ + EMAIL_ASYNC_TASK_ADD_MAILBOX = 62010, /**< Async task for adding the mailbox */ + EMAIL_ASYNC_TASK_DELETE_MAILBOX = 62020, /**< Async task for deleting the mailbox */ + EMAIL_ASYNC_TASK_RENAME_MAILBOX = 62030, /**< Async task for renaming the mailbox */ + EMAIL_ASYNC_TASK_DOWNLOAD_IMAP_MAILBOX_LIST = 62040, /**< Async task for downloading the imap mailbox list */ + EMAIL_ASYNC_TASK_DELETE_MAILBOX_EX = 62050, /**< Async task for deleting the mailbox : extentiong version */ + + /* Async tasks for mail - from 63000 */ + EMAIL_ASYNC_TASK_ADD_MAIL = 63010, /**< Async task for adding the mail */ + EMAIL_ASYNC_TASK_ADD_READ_RECEIPT = 63020, /**< Async task for adding the read receipt */ + + EMAIL_ASYNC_TASK_UPDATE_MAIL = 63030, /**< Async task for updating the mail */ + + EMAIL_ASYNC_TASK_DELETE_MAIL = 63040, /**< Async task for deleting the mail */ + EMAIL_ASYNC_TASK_DELETE_ALL_MAIL = 63050, /**< Async task for deleting the all mails */ + EMAIL_ASYNC_TASK_EXPUNGE_MAILS_DELETED_FLAGGED = 63060, /**< Async task for expunging the deleted flagged mails */ + + EMAIL_ASYNC_TASK_MOVE_MAIL = 63070, /**< Async task for moving the mail */ + EMAIL_ASYNC_TASK_MOVE_ALL_MAIL = 63080, /**< Async task for moving the all mails */ + EMAIL_ASYNC_TASK_MOVE_MAILS_TO_MAILBOX_OF_ANOTHER_ACCOUNT = 63090, /**< Async task for moving the mails to mailbox of another account */ + + EMAIL_ASYNC_TASK_SET_FLAGS_FIELD = 63300, /**< Async task for setting the flags field */ + + EMAIL_ASYNC_TASK_DOWNLOAD_MAIL_LIST = 63400, /**< Async task for downloading the mail list */ + EMAIL_ASYNC_TASK_DOWNLOAD_BODY = 63410, /**< Async taks for downloading the body */ + EMAIL_ASYNC_TASK_DOWNLOAD_ATTACHMENT = 63420, /**< Async task for downloading the attachment */ + + EMAIL_ASYNC_TASK_SEND_MAIL = 63500, /**< Async task for sending the mail */ + EMAIL_ASYNC_TASK_SEND_SAVED = 63510, /**< Async task for sending the saved */ + EMAIL_ASYNC_TASK_SEND_MAIL_WITH_DOWNLOADING_ATTACHMENT_OF_ORIGINAL_MAIL = 63520, /**< Async task for sending the mail with downloading attachment of original mail */ + + EMAIL_ASYNC_TASK_SEARCH_MAIL_ON_SERVER = 63600, /**< Async task for searching the mail on server */ + + /* Async tasks for mail thread - from 64000 */ + EMAIL_ASYNC_TASK_MOVE_THREAD_TO_MAILBOX = 64010, /**< Async task for moving the thread to mailbox */ + EMAIL_ASYNC_TASK_DELETE_THREAD = 64020, /**< Async task for deleting the thread */ + EMAIL_ASYNC_TASK_MODIFY_SEEN_FLAG_OF_THREAD = 64030, /**< Async task for modified the seen flag of thread */ + + /* Async tasks for rule - from 65000 */ + + /* Async tasks for etc - from 66000 */ + EMAIL_ASYNC_TASK_BOUNDARY_END = 99999, /**< Async tasks for boundary end*/ } email_task_type_t; typedef enum { - EMAIL_TASK_STATUS_UNUSED = 0, - EMAIL_TASK_STATUS_WAIT = 1, - EMAIL_TASK_STATUS_STARTED = 2, - EMAIL_TASK_STATUS_IN_PROGRESS = 3, - EMAIL_TASK_STATUS_FINISHED = 4, - EMAIL_TASK_STATUS_FAILED = 5, - EMAIL_TASK_STATUS_CANCELED = 6, - EMAIL_TASK_STATUS_SCHEDULED = 7, + EMAIL_TASK_STATUS_UNUSED = 0, /**< The status of task is unused */ + EMAIL_TASK_STATUS_WAIT = 1, /**< The status of task is waited */ + EMAIL_TASK_STATUS_STARTED = 2, /**< The status of task is started */ + EMAIL_TASK_STATUS_IN_PROGRESS = 3, /**< The status of task is in progress */ + EMAIL_TASK_STATUS_FINISHED = 4, /**< The status of task is finished */ + EMAIL_TASK_STATUS_FAILED = 5, /**< The status of task is failed */ + EMAIL_TASK_STATUS_CANCELED = 6, /**< The status of task is canceled */ + EMAIL_TASK_STATUS_SCHEDULED = 7, /**< The status of task is scheduled */ } email_task_status_type_t; typedef enum { - EMAIL_TASK_PRIORITY_UNUSED = 0, - EMAIL_TASK_PRIORITY_SCHEDULED = 1, - EMAIL_TASK_PRIORITY_LOW = 3, - EMAIL_TASK_PRIORITY_MID = 5, - EMAIL_TASK_PRIORITY_HIGH = 7, - EMAIL_TASK_PRIORITY_BACK_GROUND_TASK = 9, + EMAIL_TASK_PRIORITY_UNUSED = 0, /**< Unused the priority task*/ + EMAIL_TASK_PRIORITY_SCHEDULED = 1, /**< Scheduled the priority task */ + EMAIL_TASK_PRIORITY_LOW = 3, /**< The priority task is low */ + EMAIL_TASK_PRIORITY_MID = 5, /**< The priority task is MID */ + EMAIL_TASK_PRIORITY_HIGH = 7, /**< The priority task is HIGH */ + EMAIL_TASK_PRIORITY_BACK_GROUND_TASK = 9, /**< The priority task is back ground */ } email_task_priority_t; /* Tasks */ @@ -2034,7 +2288,7 @@ typedef enum #endif /** -* @} @} +* @} */ #endif /* __EMAIL_TYPES_H__ */ diff --git a/email-common-use/include/email-utilities.h b/email-common-use/include/email-utilities.h index 9a9ebf5..5bbdf74 100755 --- a/email-common-use/include/email-utilities.h +++ b/email-common-use/include/email-utilities.h @@ -46,16 +46,18 @@ INTERNAL_FUNC void em_skip_whitespace(char *addr_str , char **pAddr); INTERNAL_FUNC char* em_skip_whitespace_without_strdup(char *source_string); INTERNAL_FUNC char* em_replace_all_string(char *source_string, char *old_string, char *new_string); INTERNAL_FUNC char* em_replace_string(char *source_string, char *old_string, char *new_string); +INTERNAL_FUNC int em_replace_string_ex(char **input_source_string, char *input_old_string, char *input_new_string); INTERNAL_FUNC void em_flush_memory(); INTERNAL_FUNC int em_get_file_name_from_file_path(char *input_source_file_path, char **output_file_name); INTERNAL_FUNC int em_get_file_name_and_extension_from_file_path(char *input_source_file_path, char **output_file_name, char **output_extention); INTERNAL_FUNC char* em_get_extension_from_file_path(char *source_file_path, int *err_code); INTERNAL_FUNC int em_get_encoding_type_from_file_path(const char *input_file_path, char **output_encoding_type); INTERNAL_FUNC int em_get_content_type_from_extension_string(const char *extension_string, int *err_code); +INTERNAL_FUNC char *em_shrink_filename(char *fname, int size_limit); -INTERNAL_FUNC int em_verify_email_address(char *address, int without_bracket); -INTERNAL_FUNC int em_verify_email_address_of_mail_data(email_mail_data_t *mail_data, int without_bracket); -INTERNAL_FUNC int em_verify_email_address_of_mail_tbl(emstorage_mail_tbl_t *input_mail_tbl, int input_without_bracket); +INTERNAL_FUNC int em_verify_email_address(char *address); +INTERNAL_FUNC int em_verify_email_address_of_mail_data(email_mail_data_t *mail_data); +INTERNAL_FUNC int em_verify_email_address_of_mail_tbl(emstorage_mail_tbl_t *input_mail_tbl); INTERNAL_FUNC int em_find_pos_stripped_subject_for_thread_view(char *subject, char *stripped_subject, int stripped_subject_buffer_size); INTERNAL_FUNC int em_find_tag_for_thread_view(char *subject, int *result); @@ -86,6 +88,7 @@ INTERNAL_FUNC email_thread_handle_t* em_thread_create (); INTERNAL_FUNC void em_thread_destroy (email_thread_handle_t* th); INTERNAL_FUNC void em_thread_run (email_thread_handle_t *th, void *(*thread_func)(void*), void *(*destroy)(void*), void* arg); INTERNAL_FUNC void em_thread_join (email_thread_handle_t *th); - +INTERNAL_FUNC int em_fopen(const char *filename, const char *mode, FILE **fp); +INTERNAL_FUNC int em_open(const char *filename, int oflags, mode_t mode, int *handle); #endif /* __EMAIL_UTILITIES_H__ */ diff --git a/email-core/CMakeLists.txt b/email-core/CMakeLists.txt index 7e0efaf..ab63631 100755 --- a/email-core/CMakeLists.txt +++ b/email-core/CMakeLists.txt @@ -13,7 +13,7 @@ MESSAGE(">>> Build type: ${CMAKE_BUILD_TYPE}") SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${VISIBILITY} -fvisibility=hidden") - +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wl,--gc-sections") ########################################################## # Define device lib @@ -31,7 +31,7 @@ INCLUDE_DIRECTORIES( INCLUDE(FindPkgConfig) -pkg_check_modules(device_pkgs REQUIRED glib-2.0 dlog vconf pmapi dbus-1) +pkg_check_modules(device_pkgs REQUIRED glib-2.0 dlog vconf capi-system-device dbus-1) set(EXTRA_CFLAGS "") FOREACH(flag ${device_pkgs_CFLAGS}) @@ -47,11 +47,11 @@ SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}") SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed") ADD_LIBRARY(${DEVICE-LIB} SHARED ${DEVICE-SRCS}) -TARGET_LINK_LIBRARIES(${DEVICE-LIB} ${device_pkgs_LDFLAGS} ${BASE-LIB}) +TARGET_LINK_LIBRARIES(${DEVICE-LIB} ${device_pkgs_LDFLAGS} ss-client) SET_TARGET_PROPERTIES(${DEVICE-LIB} PROPERTIES SOVERSION ${VERSION_MAJOR}) SET_TARGET_PROPERTIES(${DEVICE-LIB} PROPERTIES VERSION ${VERSION}) -INSTALL(TARGETS ${DEVICE-LIB} DESTINATION ${LIB_INSTALL_DIR} COMPONENT RuntimeLibraries) +INSTALL(TARGETS ${DEVICE-LIB} DESTINATION lib COMPONENT RuntimeLibraries) ########################################################## @@ -72,7 +72,7 @@ INCLUDE_DIRECTORIES( INCLUDE(FindPkgConfig) -pkg_check_modules(storage_pkgs REQUIRED drm-client glib-2.0 dlog db-util openssl vconf secure-storage dbus-1 contacts-service2) +pkg_check_modules(storage_pkgs REQUIRED glib-2.0 dlog openssl vconf secure-storage dbus-1 contacts-service2) set(EXTRA_CFLAGS "") FOREACH(flag ${storage_pkgs_CFLAGS}) @@ -88,11 +88,11 @@ SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}") 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) +TARGET_LINK_LIBRARIES(${STORAGE-LIB} ${storage_LDFLAGS} ss-client) SET_TARGET_PROPERTIES(${STORAGE-LIB} PROPERTIES SOVERSION ${VERSION_MAJOR}) SET_TARGET_PROPERTIES(${STORAGE-LIB} PROPERTIES VERSION ${VERSION}) -INSTALL(TARGETS ${STORAGE-LIB} DESTINATION ${LIB_INSTALL_DIR} COMPONENT RuntimeLibraries) +INSTALL(TARGETS ${STORAGE-LIB} DESTINATION lib COMPONENT RuntimeLibraries) ########################################################## @@ -125,55 +125,11 @@ 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) +TARGET_LINK_LIBRARIES(${NETWORK-LIB} ${network_pkgs_LDFLAGS} ${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_INSTALL_DIR} COMPONENT RuntimeLibraries) - -########################################################## -# Define Core-sound lib -########################################################## - -SET(CORE-SOUND-LIB "email-core-sound") -SET(CORE-SOUND-SRCS - ${CMAKE_SOURCE_DIR}/email-core/email-core-sound.c -) - -INCLUDE_DIRECTORIES( - ${CMAKE_SOURCE_DIR}/email-common-use/include - ${CMAKE_SOURCE_DIR}/email-daemon/include/ - ${CMAKE_SOURCE_DIR}/email-core/include - ${CMAKE_SOURCE_DIR}/email-core/email-storage/include -) - - -INCLUDE(FindPkgConfig) -pkg_check_modules(core_sound_pkgs REQUIRED glib-2.0 dlog dbus-1 gthread-2.0 - vconf vconf-internal-keys mm-player mm-session feedback - alarm-service notification badge) - -set(EXTRA_CFLAGS "") -FOREACH(flag ${core_sound_pkgs_CFLAGS}) - SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") -ENDFOREACH(flag) - -SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}") - -#message(">> core extra raw: ${core_sound_pkgs_CFLAGS}") -#message(">> core extra : ${EXTRA_CFLAGS}") -#message(">> core result: ${CMAKE_C_FLAGS}") - -SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed") - -ADD_LIBRARY(${CORE-SOUND-LIB} SHARED ${CORE-SOUND-SRCS}) - -TARGET_LINK_LIBRARIES(${CORE-SOUND-LIB} ${core_sound_pkgs_LDFLAGS} ${STORAGE-LIB} ${CORE-LIB}) - -SET_TARGET_PROPERTIES(${CORE-SOUND-LIB} PROPERTIES SOVERSION ${VERSION_MAJOR}) -SET_TARGET_PROPERTIES(${CORE-SOUND-LIB} PROPERTIES VERSION ${VERSION}) - -INSTALL(TARGETS ${CORE-SOUND-LIB} DESTINATION lib COMPONENT RuntimeLibraries) +INSTALL(TARGETS ${NETWORK-LIB} DESTINATION lib COMPONENT RuntimeLibraries) ########################################################## # Define Core lib @@ -194,11 +150,12 @@ SET(CORE-SRCS ${CMAKE_SOURCE_DIR}/email-core/email-core-global.c ${CMAKE_SOURCE_DIR}/email-core/email-core-account.c ${CMAKE_SOURCE_DIR}/email-core/email-core-mime.c -# ${CMAKE_SOURCE_DIR}/email-core/email-core-sound.c + ${CMAKE_SOURCE_DIR}/email-core/email-core-gmime.c ${CMAKE_SOURCE_DIR}/email-core/email-core-task-manager.c ${CMAKE_SOURCE_DIR}/email-core/email-core-tasks.c ${CMAKE_SOURCE_DIR}/email-core/email-core-signal.c ${CMAKE_SOURCE_DIR}/email-core/email-core-alarm.c + ${CMAKE_SOURCE_DIR}/email-core/email-core-auto-download.c ) INCLUDE_DIRECTORIES( @@ -207,11 +164,15 @@ INCLUDE_DIRECTORIES( ${CMAKE_SOURCE_DIR}/email-core/email-storage/include ${CMAKE_SOURCE_DIR}/email-core/email-network/include ${CMAKE_SOURCE_DIR}/email-core/email-device/include + ${CMAKE_SOURCE_DIR}/email-ipc/email-activation/include/ ) INCLUDE(FindPkgConfig) -pkg_check_modules(core_pkgs REQUIRED glib-2.0 drm-client dlog dbus-1 gthread-2.0 uw-imap-toolkit vconf vconf-internal-keys contacts-service2 secure-storage openssl accounts-svc mm-player mm-session feedback alarm-service notification libcurl libxml-2.0 cert-svc cert-svc-vcore badge capi-appfw-application icu-i18n) +pkg_check_modules(core_pkgs REQUIRED glib-2.0 dlog dbus-1 gthread-2.0 + uw-imap-toolkit vconf vconf-internal-keys contacts-service2 secure-storage + openssl accounts-svc alarm-service notification libcurl libxml-2.0 feedback + cert-svc cert-svc-vcore badge capi-appfw-application icu-i18n gmime-2.6 storage) set(EXTRA_CFLAGS "") FOREACH(flag ${core_pkgs_CFLAGS}) @@ -239,16 +200,20 @@ ADD_DEFINITIONS("-DLOCKPGM=\"\"") ADD_DEFINITIONS("-DLOCKPGM1=\"/usr/libexec/mlock\"") ADD_DEFINITIONS("-DLOCKPGM2=\"/usr/sbin/mlock\"") ADD_DEFINITIONS("-DLOCKPGM3=\"/usr/etc/mlock\"") +IF(_FEATURE_OPCO_DOCOMO) + ADD_DEFINITIONS("-DFEATURE_OPCO_DOCOMO") +ENDIF(_FEATURE_OPCO_DOCOMO) + SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed") ADD_LIBRARY(${CORE-LIB} SHARED ${CORE-SRCS}) -TARGET_LINK_LIBRARIES(${CORE-LIB} ${core_pkgs_LDFLAGS} ${STORAGE-LIB} ${NETWORK-LIB} ${DEVICE-LIB} ${CORE-SOUND-LIB}) +TARGET_LINK_LIBRARIES(${CORE-LIB} ${core_pkgs_LDFLAGS} ${STORAGE-LIB} ${NETWORK-LIB} ${DEVICE-LIB}) SET_TARGET_PROPERTIES(${CORE-LIB} PROPERTIES SOVERSION ${VERSION_MAJOR}) SET_TARGET_PROPERTIES(${CORE-LIB} PROPERTIES VERSION ${VERSION}) -INSTALL(TARGETS ${CORE-LIB} DESTINATION ${LIB_INSTALL_DIR} COMPONENT RuntimeLibraries) +INSTALL(TARGETS ${CORE-LIB} DESTINATION lib COMPONENT RuntimeLibraries) ########################################################## # Define smime lib @@ -258,6 +223,7 @@ SET(SMIME-LIB "email-smime") SET(SMIME-SRCS ${CMAKE_SOURCE_DIR}/email-core/email-core-smime.c ${CMAKE_SOURCE_DIR}/email-core/email-core-cert.c + ${CMAKE_SOURCE_DIR}/email-core/email-core-pgp.c ) INCLUDE_DIRECTORIES( @@ -284,7 +250,7 @@ TARGET_LINK_LIBRARIES(${SMIME-LIB} ${smime_pkgs_LDFLAGS} ${BASE-LIB}) SET_TARGET_PROPERTIES(${SMIME-LIB} PROPERTIES SOVERSION ${VERSION_MAJOR}) SET_TARGET_PROPERTIES(${SMIME-LIB} PROPERTIES VERSION ${VERSION}) -INSTALL(TARGETS ${SMIME-LIB} DESTINATION ${LIB_INSTALL_DIR} COMPONENT RuntimeLibraries) +INSTALL(TARGETS ${SMIME-LIB} DESTINATION lib COMPONENT RuntimeLibraries) diff --git a/email-core/email-core-account.c b/email-core/email-core-account.c index 31149dc..27c4d2b 100755 --- a/email-core/email-core-account.c +++ b/email-core/email-core-account.c @@ -34,8 +34,10 @@ #include <string.h> #include <time.h> #include <sys/types.h> +#include <sys/stat.h> #include <vconf.h> #include <curl/curl.h> +#include <sys/shm.h> #include "email-convert.h" #include "email-types.h" @@ -52,10 +54,10 @@ #include "email-core-signal.h" #include "email-core-imap-mailbox.h" -#if defined(__FEATURE_USING_ACCOUNT_SVC_FOR_ACCOUNT_MANAGEMENT__) || defined(__FEATURE_USING_ACCOUNT_SVC_FOR_SYNC_STATUS__) +#include "imap4r1.h" + #include "account.h" #include "account-types.h" -#endif /* __FEATURE_USING_ACCOUNT_SVC_FOR_ACCOUNT_MANAGEMENT__ */ char *g_default_mbox_alias[MAILBOX_COUNT] = { @@ -117,6 +119,7 @@ INTERNAL_FUNC email_account_t* emcore_get_account_reference(int account_id) goto FINISH_OFF; /* refresh and check once again */ + EM_DEBUG_LOG ("init_account_id [%d]", account_id); emcore_init_account_reference(); ENTER_CRITICAL_SECTION(_account_ref_lock); if (g_account_num > 0 && g_account_list) { @@ -137,21 +140,45 @@ FINISH_OFF: return result_account; } +static char *emcore_get_imap_capability_string(MAILSTREAM *input_stream) +{ + EM_DEBUG_FUNC_BEGIN_SEC("input_stream[%p]", input_stream); + char *result_string = NULL; + IMAPCAP *imap_capability = NULL; + char capability_string[512] = { 0, }; + + if ((imap_capability = imap_cap(input_stream))) { + if (imap_capability->idle) + EM_SAFE_STRCAT(capability_string, "IDLE "); + if (imap_capability->quota) + EM_SAFE_STRCAT(capability_string, "QUOTA "); + if (imap_capability->starttls) + EM_SAFE_STRCAT(capability_string, "STARTTLS "); +#ifdef __FEATURE_XLIST_SUPPORT__ + if (imap_capability->xlist) + EM_SAFE_STRCAT(capability_string, "XLIST "); +#endif /* __FEATURE_XLIST_SUPPORT__ */ + result_string = EM_SAFE_STRDUP(capability_string); + } + + EM_DEBUG_FUNC_END("[%s]", result_string); + return result_string; +} -INTERNAL_FUNC int emcore_validate_account_with_account_info(email_account_t *account, email_event_type_t event_type, int *err_code) +INTERNAL_FUNC int emcore_validate_account_with_account_info(email_account_t *account, email_event_type_t event_type, char **output_server_capability_string, int event_handle, int *err_code) { - EM_DEBUG_FUNC_BEGIN_SEC("account[%p], err_code[%p], incoming_server_address [%s]", account, err_code, account->incoming_server_address); + EM_DEBUG_FUNC_BEGIN_SEC("account[%p] output_server_capability_string[%p] err_code[%p] incoming_server_address [%s]", account, output_server_capability_string, err_code, account->incoming_server_address); int ret = false; int err = EMAIL_ERROR_NONE; + int server_capability_string_length = 0; email_session_t *session = NULL; + char *imap_capability_string = NULL; + char smtp_capability_string[128] = { 0, }; SENDSTREAM *stream = NULL; MAILSTREAM *tmp_stream = NULL; - if (!emcore_check_thread_status()) { - err = EMAIL_ERROR_CANCELLED; - goto FINISH_OFF; - } + FINISH_OFF_IF_EVENT_CANCELED (err, event_handle); if (!emnetwork_check_network_status(&err)) { EM_DEBUG_EXCEPTION("emnetwork_check_network_status failed [%d]", err); @@ -159,59 +186,46 @@ INTERNAL_FUNC int emcore_validate_account_with_account_info(email_account_t *acc } EM_DEBUG_LOG("Network available"); - if (!emcore_check_thread_status()) { - err = EMAIL_ERROR_CANCELLED; - goto FINISH_OFF; - } + FINISH_OFF_IF_EVENT_CANCELED (err, event_handle); if (!emcore_get_empty_session(&session)) { EM_DEBUG_EXCEPTION("emcore_get_empty_session failed..."); - err = EMAIL_ERROR_SESSION_NOT_FOUND; - goto FINISH_OFF; +/* err = EMAIL_ERROR_SESSION_NOT_FOUND; + goto FINISH_OFF; */ } /* validate connection for pop3/imap */ EM_DEBUG_LOG("Validate connection for POP3/IMAP4"); - if (EMAIL_ERROR_NONE == err) { - if (!emcore_check_thread_status()) { - err = EMAIL_ERROR_CANCELLED; - goto FINISH_OFF; - } - if (!emcore_connect_to_remote_mailbox_with_account_info(account, 0, (void **)&tmp_stream, &err) || !tmp_stream) { - EM_DEBUG_LOG("emcore_connect_to_remote_mailbox failed [%d]", err); - if (EMAIL_ERROR_AUTHENTICATE == err || EMAIL_ERROR_LOGIN_FAILURE == err) { /* wrong password or etc */ - EM_DEBUG_EXCEPTION("emcore_connect_to_remote_mailbox failed : Login or Authentication failed - %d", err); - } else if (EMAIL_ERROR_CONNECTION_FAILURE != err) { - /* err = EMAIL_ERROR_VALIDATE_ACCOUNT */ - } - goto FINISH_OFF; + FINISH_OFF_IF_EVENT_CANCELED (err, event_handle); + + if (!emcore_connect_to_remote_mailbox_with_account_info(account, 0, (void **)&tmp_stream, &err) || !tmp_stream) { + EM_DEBUG_LOG("emcore_connect_to_remote_mailbox failed [%d]", err); + if (EMAIL_ERROR_AUTHENTICATE == err || EMAIL_ERROR_LOGIN_FAILURE == err) { /* wrong password or etc */ + EM_DEBUG_EXCEPTION("emcore_connect_to_remote_mailbox failed : Login or Authentication failed - %d", err); + } else if (EMAIL_ERROR_CONNECTION_FAILURE != err) { + /* err = EMAIL_ERROR_VALIDATE_ACCOUNT */ } + goto FINISH_OFF; } + if (account->incoming_server_type == EMAIL_SERVER_TYPE_IMAP4) + imap_capability_string = emcore_get_imap_capability_string(tmp_stream); + #ifdef __FEATURE_SMTP_VALIDATION__ /* validate connection for SMTP */ EM_DEBUG_LOG("Validate connection for SMTP server"); - if (!emcore_check_thread_status()) { - err = EMAIL_ERROR_CANCELLED; - goto FINISH_OFF; - } + FINISH_OFF_IF_EVENT_CANCELED (err, event_handle); if (!emcore_connect_to_remote_mailbox_with_account_info(account, EMAIL_CONNECT_FOR_SENDING, (void **)&stream, &err) || !stream) { - EM_DEBUG_LOG("emcore_connect_to_remote_mailbox failed [%d]", err); - if (EMAIL_ERROR_AUTHENTICATE == err || EMAIL_ERROR_LOGIN_FAILURE == err) { - /* Wrong password or etc */ - EM_DEBUG_EXCEPTION("emcore_connect_to_remote_mailbox failed [%d]", err); - err = EMAIL_ERROR_VALIDATE_ACCOUNT_OF_SMTP; - goto FINISH_OFF; - } + EM_DEBUG_EXCEPTION("emcore_connect_to_remote_mailbox failed [%d]", err); + err = EMAIL_ERROR_VALIDATE_ACCOUNT_OF_SMTP; + goto FINISH_OFF; +#if 0 if (account->outgoing_server_secure_connection == 0x01) /* 0x01 == SSL */ { - if (!emcore_check_thread_status()) { - err = EMAIL_ERROR_CANCELLED; - goto FINISH_OFF; - } + FINISH_OFF_IF_EVENT_CANCELED (err, event_handle); EM_DEBUG_LOG("Retry with TLS"); account->outgoing_server_secure_connection = 0x02; /* 0x02 == TLS */ @@ -223,28 +237,51 @@ INTERNAL_FUNC int emcore_validate_account_with_account_info(email_account_t *acc goto FINISH_OFF; } - if (!emcore_check_thread_status()) { - err = EMAIL_ERROR_CANCELLED; - goto FINISH_OFF; - } + FINISH_OFF_IF_EVENT_CANCELED (err, event_handle); } else { - if (EMAIL_ERROR_CONNECTION_FAILURE != err) - err = EMAIL_ERROR_VALIDATE_ACCOUNT_OF_SMTP; + err = EMAIL_ERROR_VALIDATE_ACCOUNT_OF_SMTP; goto FINISH_OFF; } +#endif + } + if (stream && stream->protocol.esmtp.ok) { + if (stream->protocol.esmtp.size.ok && stream->protocol.esmtp.size.limit > 0) { + account->outgoing_server_size_limit = stream->protocol.esmtp.size.limit; + SNPRINTF(smtp_capability_string, 128, "SMTP_MAIL_SIZE_LIMIT=%d ", account->outgoing_server_size_limit); + EM_DEBUG_LOG("%s", smtp_capability_string); + } } #endif /* __FEATURE_SMTP_VALIDATION__ */ - if (!emcore_check_thread_status()) { + int dummy = 0; + if (!emcore_check_event_thread_status(&dummy, event_handle)) { + EM_DEBUG_LOG ("canceled event: [%d]", dummy); if (event_type == EMAIL_EVENT_VALIDATE_AND_CREATE_ACCOUNT || event_type == EMAIL_EVENT_VALIDATE_ACCOUNT_EX) { - if (!emcore_delete_account(account->account_id, NULL)) + if (!emcore_delete_account(account->account_id, false, NULL)) EM_DEBUG_EXCEPTION("emdaemon_delete_account failed [%d]", account->account_id); } err = EMAIL_ERROR_CANCELLED; goto FINISH_OFF; } + if (output_server_capability_string) { + server_capability_string_length = EM_SAFE_STRLEN(imap_capability_string) + EM_SAFE_STRLEN(smtp_capability_string); + if (server_capability_string_length) { + *output_server_capability_string = em_malloc(server_capability_string_length + 1); + + if (*output_server_capability_string == NULL) { + EM_DEBUG_EXCEPTION("EMAIL_ERROR_OUT_OF_MEMORY"); + err = EMAIL_ERROR_OUT_OF_MEMORY; + goto FINISH_OFF; + } + + EM_SAFE_STRCAT(*output_server_capability_string, smtp_capability_string); + EM_SAFE_STRCAT(*output_server_capability_string, imap_capability_string); + EM_DEBUG_LOG("%s", *output_server_capability_string); + } + } + ret = true; FINISH_OFF: @@ -257,6 +294,8 @@ FINISH_OFF: if (err_code != NULL) *err_code = err; + EM_SAFE_FREE(imap_capability_string); + emcore_clear_session(session); EM_DEBUG_FUNC_END(); @@ -264,7 +303,7 @@ FINISH_OFF: } -INTERNAL_FUNC int emcore_validate_account(int account_id, int *err_code) +INTERNAL_FUNC int emcore_validate_account(int account_id, int handle, int *err_code) { EM_DEBUG_FUNC_BEGIN("account_id[%d], err_code[%p]", account_id, err_code); @@ -280,7 +319,7 @@ INTERNAL_FUNC int emcore_validate_account(int account_id, int *err_code) ref_account = emcore_get_account_reference(account_id); - if (ref_account && emcore_validate_account_with_account_info(ref_account, EMAIL_EVENT_VALIDATE_ACCOUNT, &err) == false) { + if (ref_account && emcore_validate_account_with_account_info(ref_account, EMAIL_EVENT_VALIDATE_ACCOUNT, NULL, handle, &err) == false) { EM_DEBUG_EXCEPTION("emcore_validate_account_with_account_info failed (%d)", err); goto FINISH_OFF; } @@ -302,10 +341,31 @@ FINISH_OFF: return ret; } -INTERNAL_FUNC int emcore_delete_account(int account_id, int *err_code) +key_t del_account_key = 4511; /* name of the segment d/4 e/5 l/11 */ + +INTERNAL_FUNC int emcore_delete_account(int account_id, int input_delete_from_account_svc, int *err_code) { EM_DEBUG_FUNC_BEGIN("account_id[%d], err_code[%p]", account_id, err_code); + int shmid = 0; + int *del_account_id = NULL; + + EM_DEBUG_LOG ("begin account_id [%d]", account_id); + /* worker thread is single instance, so multiple accounts cant be deleted concurrently */ + if ((shmid = shmget (del_account_key, sizeof (int), IPC_CREAT | 0666)) != -1) { + /* attaching the segment to the current process space */ + if ((del_account_id = (int*) shmat (shmid, NULL, 0)) != (int*) -1) { + /* write it */ + *del_account_id = account_id; + EM_DEBUG_LOG ("recorded account_id [%d]", *del_account_id); + } + else + EM_DEBUG_EXCEPTION ("shmget error[%d]", errno); + + } + else + EM_DEBUG_EXCEPTION ("shmget error[%d]", errno); + /* default variabl */ int ret = false; int err = EMAIL_ERROR_NONE; @@ -314,12 +374,13 @@ INTERNAL_FUNC int emcore_delete_account(int account_id, int *err_code) if (account_id < FIRST_ACCOUNT_ID) { EM_DEBUG_EXCEPTION("account_id[%d]", account_id); err = EMAIL_ERROR_INVALID_PARAM; + before_tr_begin = 1; goto FINISH_OFF; } #ifdef __FEATURE_LOCAL_ACTIVITY__ /* Delete all local activities of previous account */ - + emstorage_activity_tbl_t activity; memset(&activity, 0x00, sizeof(emstorage_activity_tbl_t)); @@ -327,7 +388,7 @@ INTERNAL_FUNC int emcore_delete_account(int account_id, int *err_code) if (!emcore_delete_activity(&activity, &err)) { EM_DEBUG_LOG("\t emcore_delete_activity failed - %d", err); - + before_tr_begin = 1; goto FINISH_OFF; } #endif @@ -341,20 +402,27 @@ INTERNAL_FUNC int emcore_delete_account(int account_id, int *err_code) #endif -#ifdef __FEATURE_USING_ACCOUNT_SVC_FOR_ACCOUNT_MANAGEMENT__ - { - int error_code; +#ifdef __FEATURE_WIFI_AUTO_DOWNLOAD__ + if (!emcore_clear_auto_download_queue()) + EM_DEBUG_EXCEPTION("emcore_clear_auto_download_queue failed"); + + if (!emstorage_delete_all_auto_download_activity(account_id, true, &err)) + EM_DEBUG_EXCEPTION("emstorage_delete_all_auto_download_activity failed [%d]", err); +#endif + + if (input_delete_from_account_svc == true) { + int error_code_from_account_svc; email_account_t *account_to_be_deleted; account_to_be_deleted = emcore_get_account_reference(account_id); if (account_to_be_deleted && account_to_be_deleted->incoming_server_type != EMAIL_SERVER_TYPE_ACTIVE_SYNC) { EM_DEBUG_LOG("Calling account_svc_delete with account_svc_id[%d]", account_to_be_deleted->account_svc_id); - error_code = account_connect(); - EM_DEBUG_LOG("account_connect returns [%d]", error_code); - error_code = account_delete_from_db_by_id(account_to_be_deleted->account_svc_id); - EM_DEBUG_LOG("account_delete_from_db_by_id returns [%d]", error_code); - error_code = account_disconnect(); - EM_DEBUG_LOG("account_disconnect returns [%d]", error_code); + error_code_from_account_svc = account_connect(); + EM_DEBUG_LOG("account_connect returns [%d]", error_code_from_account_svc); + error_code_from_account_svc = account_delete_from_db_by_id(account_to_be_deleted->account_svc_id); + EM_DEBUG_LOG("account_delete_from_db_by_id returns [%d]", error_code_from_account_svc); + error_code_from_account_svc = account_disconnect(); + EM_DEBUG_LOG("account_disconnect returns [%d]", error_code_from_account_svc); } if (account_to_be_deleted) { @@ -362,10 +430,11 @@ INTERNAL_FUNC int emcore_delete_account(int account_id, int *err_code) EM_SAFE_FREE(account_to_be_deleted); } } -#endif + if (emcore_cancel_all_threads_of_an_account(account_id) < EMAIL_ERROR_NONE) { EM_DEBUG_EXCEPTION("There are some remaining jobs. I couldn't stop them."); err = EMAIL_ERROR_CANNOT_STOP_THREAD; + before_tr_begin = 1; goto FINISH_OFF; } @@ -380,7 +449,7 @@ INTERNAL_FUNC int emcore_delete_account(int account_id, int *err_code) before_tr_begin = 1; goto FINISH_OFF; } - + if (!emstorage_delete_account(account_id, false, &err)) { if(err != EMAIL_ERROR_SYSTEM_FAILURE) { EM_DEBUG_EXCEPTION("emstorage_delete_account failed [%d]", err); @@ -392,7 +461,7 @@ INTERNAL_FUNC int emcore_delete_account(int account_id, int *err_code) /* emcore_reset_streams(); */ emcore_remove_connection_info(account_id); #endif - + if ((err = emcore_delete_all_mails_of_acount(account_id)) != EMAIL_ERROR_NONE) { EM_DEBUG_EXCEPTION("emcore_delete_all_mails_of_acount failed [%d]", err); goto FINISH_OFF; @@ -412,9 +481,8 @@ INTERNAL_FUNC int emcore_delete_account(int account_id, int *err_code) goto FINISH_OFF; } - emcore_display_unread_in_badge(); + emcore_display_unread_in_badge(NULL); emcore_delete_notification_by_account(account_id, true); - emcore_init_account_reference(); ret = true; @@ -435,17 +503,24 @@ FINISH_OFF: EM_DEBUG_EXCEPTION (" emcore_notify_storage_event[ NOTI_ACCOUNT_DELETE] : Notification Failed >>> "); } + emcore_init_account_reference(); + if (err_code) *err_code = err; + /* del the segment */ + if (shmid != -1) { + shmctl (shmid, IPC_RMID, NULL); + } + EM_DEBUG_FUNC_END(); return ret; } -INTERNAL_FUNC int emcore_create_account(email_account_t *account, int *err_code) +INTERNAL_FUNC int emcore_create_account(email_account_t *account, int add_account_to_account_svc, int *err_code) { - EM_DEBUG_FUNC_BEGIN("account[%p], err_code[%p]", account, err_code); + EM_DEBUG_FUNC_BEGIN("account[%p] add_account_to_account_svc [%d] err_code[%p]", account, add_account_to_account_svc, err_code); int ret = false; int err = EMAIL_ERROR_NONE; @@ -485,97 +560,102 @@ INTERNAL_FUNC int emcore_create_account(email_account_t *account, int *err_code) /* check for email address validation */ EM_DEBUG_LOG_SEC("account->user_email_address[%s]", account->user_email_address); if (account->user_email_address) { - if ((err = em_verify_email_address (account->user_email_address, true)) != EMAIL_ERROR_NONE) { + if ((err = em_verify_email_address (account->user_email_address)) != EMAIL_ERROR_NONE) { EM_DEBUG_EXCEPTION("em_verify_email_address error [%d]", err); goto FINISH_OFF; } } -#ifdef __FEATURE_USING_ACCOUNT_SVC_FOR_ACCOUNT_MANAGEMENT__ - if (account->incoming_server_type != EMAIL_SERVER_TYPE_ACTIVE_SYNC) { - int account_svc_id = 0; - int error_code; - account_h account_handle = NULL; + if (EM_SAFE_STRLEN(account->options.alert_ringtone_path) == 0) { + account->options.alert_ringtone_path = EM_SAFE_STRDUP(vconf_get_str(VCONFKEY_SETAPPL_NOTI_MSG_RINGTONE_PATH_STR)); + } - error_code = account_connect(); - if(error_code != ACCOUNT_ERROR_NONE) { - EM_DEBUG_EXCEPTION("account_connect failed [%d]", error_code); - err = error_code; - goto FINISH_OFF; - } + if (add_account_to_account_svc) { + if (account->incoming_server_type != EMAIL_SERVER_TYPE_ACTIVE_SYNC) { + int account_svc_id = 0; + int error_code; + account_h account_handle = NULL; - error_code = account_create(&account_handle); - if(error_code != ACCOUNT_ERROR_NONE) { - EM_DEBUG_EXCEPTION("account_create failed [%d]", error_code); - err = error_code; - account_disconnect(); - goto FINISH_OFF; - } + error_code = account_connect(); + if(error_code != ACCOUNT_ERROR_NONE) { + EM_DEBUG_EXCEPTION("account_connect failed [%d]", error_code); + err = error_code; + goto FINISH_OFF; + } - error_code = account_set_user_name(account_handle, account->incoming_server_user_name); - if(error_code != ACCOUNT_ERROR_NONE) { - EM_DEBUG_LOG("account_set_user_name failed [%d]", error_code); - } + error_code = account_create(&account_handle); + if(error_code != ACCOUNT_ERROR_NONE) { + EM_DEBUG_EXCEPTION("account_create failed [%d]", error_code); + err = error_code; + account_disconnect(); + goto FINISH_OFF; + } - error_code = account_set_domain_name(account_handle, account->account_name); - if(error_code != ACCOUNT_ERROR_NONE) { - EM_DEBUG_LOG("account_set_domain_name failed [%d]", error_code); - } + error_code = account_set_user_name(account_handle, account->incoming_server_user_name); + if(error_code != ACCOUNT_ERROR_NONE) { + EM_DEBUG_LOG("account_set_user_name failed [%d]", error_code); + } - error_code = account_set_email_address(account_handle, account->user_email_address); - if(error_code != ACCOUNT_ERROR_NONE) { - EM_DEBUG_LOG("account_set_email_address failed [%d]", error_code); - } + error_code = account_set_domain_name(account_handle, account->account_name); + if(error_code != ACCOUNT_ERROR_NONE) { + EM_DEBUG_LOG("account_set_domain_name failed [%d]", error_code); + } - error_code = account_set_source(account_handle, "SLP EMAIL"); - if(error_code != ACCOUNT_ERROR_NONE) { - EM_DEBUG_LOG("account_set_source failed [%d]", error_code); - } + error_code = account_set_email_address(account_handle, account->user_email_address); + if(error_code != ACCOUNT_ERROR_NONE) { + EM_DEBUG_LOG("account_set_email_address failed [%d]", error_code); + } - error_code = account_set_package_name(account_handle, "email-setting-efl"); - if(error_code != ACCOUNT_ERROR_NONE) { - EM_DEBUG_LOG("account_set_package_name failed [%d]", error_code); - } + error_code = account_set_source(account_handle, "SLP EMAIL"); + if(error_code != ACCOUNT_ERROR_NONE) { + EM_DEBUG_LOG("account_set_source failed [%d]", error_code); + } - /* account_set_capability(account_handle , ACCOUNT_CAPABILITY_EMAIL, ACCOUNT_CAPABILITY_ENABLED); OLD API */ - error_code = account_set_capability(account_handle , ACCOUNT_SUPPORTS_CAPABILITY_EMAIL , ACCOUNT_CAPABILITY_ENABLED); - if(error_code != ACCOUNT_ERROR_NONE) { - EM_DEBUG_LOG("account_set_capability failed [%d]", error_code); - } + error_code = account_set_package_name(account_handle, "email-setting-efl"); + if(error_code != ACCOUNT_ERROR_NONE) { + EM_DEBUG_LOG("account_set_package_name failed [%d]", error_code); + } - error_code = account_set_sync_support(account_handle, ACCOUNT_SYNC_STATUS_IDLE); /* This means "The account is supporting 'sync' and initialized as idle status" */ - if(error_code != ACCOUNT_ERROR_NONE) { - EM_DEBUG_LOG("account_set_sync_support failed [%d]", error_code); - } + /* account_set_capability(account_handle , ACCOUNT_CAPABILITY_EMAIL, ACCOUNT_CAPABILITY_ENABLED); OLD API */ + error_code = account_set_capability(account_handle , ACCOUNT_SUPPORTS_CAPABILITY_EMAIL , ACCOUNT_CAPABILITY_ENABLED); + if(error_code != ACCOUNT_ERROR_NONE) { + EM_DEBUG_LOG("account_set_capability failed [%d]", error_code); + } - if (account->logo_icon_path) { - error_code = account_set_icon_path(account_handle, account->logo_icon_path); + error_code = account_set_sync_support(account_handle, ACCOUNT_SYNC_STATUS_IDLE); /* This means "The account is supporting 'sync' and initialized as idle status" */ if(error_code != ACCOUNT_ERROR_NONE) { - EM_DEBUG_LOG("account_set_icon_path failed [%d]", error_code); + EM_DEBUG_LOG("account_set_sync_support failed [%d]", error_code); } - } - 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); - } - else { - account->account_svc_id = account_svc_id; - EM_DEBUG_LOG("account_insert_to_db succeed"); - } + if (account->logo_icon_path) { + error_code = account_set_icon_path(account_handle, account->logo_icon_path); + if(error_code != ACCOUNT_ERROR_NONE) { + EM_DEBUG_LOG("account_set_icon_path failed [%d]", error_code); + } + } + + 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); + } + else { + account->account_svc_id = account_svc_id; + EM_DEBUG_LOG("account_insert_to_db succeed"); + } - if (account_handle) - account_destroy(account_handle); + if (account_handle) + account_destroy(account_handle); - account_disconnect(); + account_disconnect(); + } } -#endif /* __FEATURE_USING_ACCOUNT_SVC_FOR_ACCOUNT_MANAGEMENT__ */ temp_account_tbl = em_malloc(sizeof(emstorage_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 (!emstorage_add_account(temp_account_tbl, true, &err)) { @@ -602,17 +682,17 @@ INTERNAL_FUNC int emcore_create_account(email_account_t *account, int *err_code) else local_mailbox.local = EMAIL_MAILBOX_FROM_LOCAL; - if (!emcore_create_mailbox(&local_mailbox, 0, &err)) { + if (!emcore_create_mailbox(&local_mailbox, 0, account->incoming_server_type, account->default_mail_slot_size, &err)) { EM_DEBUG_EXCEPTION("emcore_create failed [%d]", err); emcore_free_mailbox(&local_mailbox); goto FINISH_OFF; } - + emcore_free_mailbox(&local_mailbox); } } - /* Initialize the noti private id */ + /* Initialize the noti private id */ SNPRINTF(vconf_private_id, sizeof(vconf_private_id), "%s/%d", VCONF_KEY_NOTI_PRIVATE_ID, account->account_id); if (vconf_get_int(vconf_private_id, &private_id) != 0) { EM_DEBUG_EXCEPTION("vconf_get_int failed"); @@ -621,18 +701,18 @@ INTERNAL_FUNC int emcore_create_account(email_account_t *account, int *err_code) EM_DEBUG_EXCEPTION("vconf_set_int failed : [NOTI key initialize]"); } } - + ret = true; - -FINISH_OFF: + +FINISH_OFF: if (temp_account_tbl) emstorage_free_account(&temp_account_tbl, 1, NULL); - + if (ret == false && account != NULL) { - if (!emcore_delete_account(account->account_id, NULL)) + if (!emcore_delete_account(account->account_id, false, NULL)) EM_DEBUG_EXCEPTION("emdaemon_delete_account Failed [%d]", account->account_id); } - + if (err_code) *err_code = err; @@ -643,17 +723,18 @@ FINISH_OFF: INTERNAL_FUNC int emcore_init_account_reference() { - EM_DEBUG_FUNC_BEGIN(); - +// static int num_call = 0; +// EM_DEBUG_LOG("num_call [%d]", num_call++); + int err = EMAIL_ERROR_NONE; - + email_account_list_t *account_list = NULL; email_account_list_t **p = NULL; email_account_t *account = NULL; emstorage_account_tbl_t *account_tbl_array = NULL; - int count = 0; + int count = 0; int i = 0; - + /* free account reference if any */ emcore_free_account_reference(); @@ -669,7 +750,7 @@ INTERNAL_FUNC int emcore_init_account_reference() err = EMAIL_ERROR_OUT_OF_MEMORY; goto FINISH_OFF; } - + em_convert_account_tbl_to_account(account_tbl_array + i, account); *p = (email_account_list_t*) em_malloc(sizeof(email_account_list_t)); @@ -691,7 +772,7 @@ INTERNAL_FUNC int emcore_init_account_reference() g_account_list = account_list; LEAVE_CRITICAL_SECTION(_account_ref_lock); -FINISH_OFF: +FINISH_OFF: if (account_tbl_array) emstorage_free_account(&account_tbl_array, count, NULL); @@ -699,6 +780,95 @@ FINISH_OFF: return err; } +INTERNAL_FUNC int emcore_add_account_reference(email_account_t *account) +{ + EM_DEBUG_FUNC_BEGIN(); + + email_account_list_t *account_iter = NULL; + email_account_list_t **p = NULL; + email_account_t *dup_account = NULL; + int account_count = 0; + + if (account == NULL) { + EM_DEBUG_EXCEPTION("account [%p]", account); + return false; + } + + emcore_duplicate_account(account, &dup_account, NULL); + + if (dup_account == NULL) { + EM_DEBUG_EXCEPTION("dup_account [%p]", dup_account); + return false; + } + + ENTER_CRITICAL_SECTION(_account_ref_lock); + account_iter = g_account_list; + + p = &g_account_list; + while (*p) { + if ((*p)->account->account_id == account->account_id) { + EM_DEBUG_LOG("already added to g_account_list"); + emcore_free_account(dup_account); + EM_SAFE_FREE(dup_account); + LEAVE_CRITICAL_SECTION(_account_ref_lock); + return false; + } + p = &(*p)->next; + } + + if (account_iter == NULL) { + email_account_list_t *new_item = (email_account_list_t*) em_malloc(sizeof(email_account_list_t)); + if (!new_item) { + EM_DEBUG_EXCEPTION("malloc failed..."); + emcore_free_account(dup_account); + EM_SAFE_FREE(dup_account); + LEAVE_CRITICAL_SECTION(_account_ref_lock); + return false; + } + + new_item->account = dup_account; + new_item->next = NULL; + + g_account_list = new_item; + EM_DEBUG_LOG("added 1 th item to g_account_list"); + LEAVE_CRITICAL_SECTION(_account_ref_lock); + return true; + } + + while(account_iter) { + if (account_iter->account) + account_count++; + + EM_DEBUG_LOG_DEV("account count[%d]", account_count); + + if (account_iter->next == NULL) { + email_account_list_t *new_item = (email_account_list_t*) em_malloc(sizeof(email_account_list_t)); + if (!new_item) { + EM_DEBUG_EXCEPTION("malloc failed..."); + emcore_free_account(dup_account); + EM_SAFE_FREE(dup_account); + LEAVE_CRITICAL_SECTION(_account_ref_lock); + return false; + } + + new_item->account = dup_account; + new_item->next = NULL; + + account_iter->next = new_item; + EM_DEBUG_LOG("added %d th item to g_account_list", account_count+1); + break; + } + else { + account_iter = account_iter->next; + } + } + + LEAVE_CRITICAL_SECTION(_account_ref_lock); + + EM_DEBUG_FUNC_END(); + return true; +} + INTERNAL_FUNC int emcore_free_account_reference() { EM_DEBUG_FUNC_BEGIN(); @@ -709,7 +879,7 @@ INTERNAL_FUNC int emcore_free_account_reference() while (p) { emcore_free_account(p->account); EM_SAFE_FREE(p->account); - + p_next = p->next; EM_SAFE_FREE(p); p = p_next; @@ -726,26 +896,26 @@ INTERNAL_FUNC int emcore_free_account_reference() INTERNAL_FUNC int emcore_free_account_list(email_account_t **account_list, int count, int *err_code) { EM_DEBUG_FUNC_BEGIN("account_list[%p], count[%d], err_code[%p]", account_list, count, err_code); - + int ret = false; int err = EMAIL_ERROR_NONE; - + if (count <= 0 || !account_list || !*account_list) { err = EMAIL_ERROR_INVALID_PARAM; goto FINISH_OFF; } - + email_account_t *p = *account_list; int i; for (i = 0; i < count; i++) emcore_free_account(p+i); - + EM_SAFE_FREE(p); *account_list = NULL; - + ret = true; - -FINISH_OFF: + +FINISH_OFF: if (err_code) *err_code = err; EM_DEBUG_FUNC_END(); @@ -764,22 +934,21 @@ INTERNAL_FUNC void emcore_free_account(email_account_t *account) if(!account) return; EM_SAFE_FREE(account->account_name); - EM_SAFE_FREE(account->incoming_server_address); + EM_SAFE_FREE(account->logo_icon_path); + EM_SAFE_FREE(account->user_data); + account->user_data_length = 0; + EM_SAFE_FREE(account->user_display_name); EM_SAFE_FREE(account->user_email_address); + EM_SAFE_FREE(account->reply_to_address); + EM_SAFE_FREE(account->return_address); + EM_SAFE_FREE(account->incoming_server_address); EM_SAFE_FREE(account->incoming_server_user_name); EM_SAFE_FREE(account->incoming_server_password); EM_SAFE_FREE(account->outgoing_server_address); EM_SAFE_FREE(account->outgoing_server_user_name); EM_SAFE_FREE(account->outgoing_server_password); - EM_SAFE_FREE(account->user_display_name); - EM_SAFE_FREE(account->reply_to_address); - EM_SAFE_FREE(account->return_address); - EM_SAFE_FREE(account->logo_icon_path); - EM_SAFE_FREE(account->certificate_path); - EM_SAFE_FREE(account->user_data); - account->user_data_length = 0; emcore_free_option(&account->options); - + EM_SAFE_FREE(account->certificate_path); EM_DEBUG_FUNC_END(); } @@ -815,7 +984,7 @@ INTERNAL_FUNC void emcore_duplicate_account(const email_account_t *account, emai if(!account || !account_dup) { /*prevent 40514*/ EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM"); - if(err_code) *err_code = EMAIL_ERROR_INVALID_PARAM; + if(err_code) *err_code = EMAIL_ERROR_INVALID_PARAM; return; } @@ -862,7 +1031,7 @@ INTERNAL_FUNC int emcore_get_account_reference_list(email_account_t **account_li *count = countOfAccounts; if (countOfAccounts > 0) { - *account_list = malloc(sizeof(email_account_t) * countOfAccounts); + *account_list = em_malloc(sizeof(email_account_t) * countOfAccounts); if (!*account_list) { EM_DEBUG_LOG("malloc failed..."); err = EMAIL_ERROR_OUT_OF_MEMORY; @@ -873,6 +1042,7 @@ INTERNAL_FUNC int emcore_get_account_reference_list(email_account_t **account_li p = g_account_list; for (i = 0; i < countOfAccounts; i++) { accountRef = (*account_list) + i; + emcore_free_account(accountRef); emcore_duplicate_account_members(p->account, accountRef); EM_DEBUG_LOG_SEC("Result account id[%d], name[%s]", accountRef->account_id, accountRef->account_name); p = p->next; @@ -928,7 +1098,7 @@ static int append_data_into_buffer(char **target_buffer, int *target_buffer_lent ret_code = true; -FINISH_OFF: +FINISH_OFF: if (error_code) *error_code = local_error_code; @@ -948,7 +1118,7 @@ static int emcore_write_account_into_buffer(char **target_buffer, int *target_bu 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("incoming_server_password [%s]", temp_account->password) */ + /* EM_DEBUG_LOG_SEC("incoming_server_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)) { @@ -971,7 +1141,7 @@ static int emcore_write_account_into_buffer(char **target_buffer, int *target_bu } ret_code = true; -FINISH_OFF: +FINISH_OFF: emcore_free_account(&temp_account); if (error_code) *error_code = local_error_code; @@ -987,25 +1157,41 @@ INTERNAL_FUNC int emcore_backup_accounts(const char *file_path, int *error_code) EM_DEBUG_FUNC_BEGIN_SEC("file_path [%s], error_code [%p]", file_path, error_code); int local_error_code = EMAIL_ERROR_NONE, local_error_code_2 = EMAIL_ERROR_NONE, ret_code = false; int select_num, i, target_buff_length = 0; + int normal_email_account_count = 0; char *target_buffer = NULL; emstorage_account_tbl_t *account_list = NULL; + int fd = 0; if (!file_path) { local_error_code = EMAIL_ERROR_INVALID_PARAM; EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM"); - goto FINISH_OFF; + goto FINISH_OFF; } select_num = 1000; - + if (!emstorage_get_account_list(&select_num, &account_list, true, true, &local_error_code)) { EM_DEBUG_EXCEPTION("emstorage_get_account_list failed [%d]", local_error_code); - goto FINISH_OFF; + goto FINISH_OFF; } - + EM_DEBUG_LOG("select_num [%d]", select_num); - + if (account_list) { + for (i = 0; i < select_num; i++) { + if (account_list[i].incoming_server_type == EMAIL_SERVER_TYPE_POP3 || account_list[i].incoming_server_type == EMAIL_SERVER_TYPE_IMAP4) + normal_email_account_count++; + } + } + + EM_DEBUG_LOG("normal_email_account_count [%d]", normal_email_account_count); + + if (normal_email_account_count == 0) { + EM_DEBUG_EXCEPTION("EMAIL_ERROR_ACCOUNT_NOT_FOUND"); + local_error_code = EMAIL_ERROR_ACCOUNT_NOT_FOUND; + goto FINISH_OFF; + } + else { target_buffer = em_malloc(sizeof(int)); if (!target_buffer) { EM_DEBUG_EXCEPTION("malloc failed"); @@ -1013,32 +1199,49 @@ INTERNAL_FUNC int emcore_backup_accounts(const char *file_path, int *error_code) goto FINISH_OFF; } - memcpy(target_buffer, (char *)&select_num, sizeof(int)); + memcpy(target_buffer, (char *)&normal_email_account_count, sizeof(int)); target_buff_length = sizeof(int); for (i = 0; i < select_num; i++) { - if (!emcore_write_account_into_buffer(&target_buffer, &target_buff_length, account_list + i, &local_error_code)) { - EM_DEBUG_EXCEPTION("emcore_write_account_into_buffer failed [%d]", local_error_code); - goto FINISH_OFF; + if (account_list[i].incoming_server_type == EMAIL_SERVER_TYPE_POP3 || account_list[i].incoming_server_type == EMAIL_SERVER_TYPE_IMAP4) { + if (!emcore_write_account_into_buffer(&target_buffer, &target_buff_length, account_list + i, &local_error_code)) { + EM_DEBUG_EXCEPTION("emcore_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); + int data_length = 0; + char *encrypted_data_block = NULL; + + local_error_code = em_open(file_path, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR, &fd); + if (local_error_code != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("em_open failed - %d [%s] : ", local_error_code, file_path); + goto FINISH_OFF; + } + + data_length = ssa_encrypt(target_buffer, target_buff_length, &encrypted_data_block, NULL); + if (data_length < 0) { + EM_DEBUG_EXCEPTION("ss_encrypt error [%d]", data_length); + local_error_code = EMAIL_ERROR_SECURED_STORAGE_FAILURE; + goto FINISH_OFF; + } + + if (write(fd, encrypted_data_block, data_length) != data_length) { + EM_DEBUG_EXCEPTION("write failed : [%s]", strerror(errno)); local_error_code = EMAIL_ERROR_SYSTEM_FAILURE; - goto FINISH_OFF; + goto FINISH_OFF; } - } ret_code = true; FINISH_OFF: + EM_SAFE_CLOSE (fd); EM_SAFE_FREE(target_buffer); + if (account_list) emstorage_free_account(&account_list, select_num, &local_error_code_2); @@ -1049,29 +1252,31 @@ FINISH_OFF: return ret_code; } -INTERNAL_FUNC int emcore_restore_accounts(const char *file_path, int *error_code) +INTERNAL_FUNC int emcore_restore_accounts(const char *file_path) { - EM_DEBUG_FUNC_BEGIN_SEC("file_path [%s], error_code [%p]", file_path, error_code); - int local_error_code = EMAIL_ERROR_NONE, ret_code = false, buffer_length = 0, read_length = 0; + EM_DEBUG_FUNC_BEGIN_SEC("file_path [%s]", file_path); + int err = EMAIL_ERROR_NONE, 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; email_account_t temp_account = {0}; email_account_t *account_list = NULL; + char errno_buf[ERRNO_BUF_SIZE] = {0}; + char *encrypt_buffer = NULL; - ssm_file_info_t sfi; + if (!emcore_notify_storage_event (NOTI_ACCOUNT_RESTORE_START, 0, 0, NULL, 0)) + EM_DEBUG_EXCEPTION ("emcore_notify_storage_event [NOTI_ACCOUNT_RESTORE_START] failed"); if (!file_path) { - local_error_code = EMAIL_ERROR_INVALID_PARAM; + err = EMAIL_ERROR_INVALID_PARAM; EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM"); - goto FINISH_OFF; + goto FINISH_OFF; } - if (emcore_get_account_reference_list(&account_list, &account_count, &ret_code)) { + if (emcore_get_account_reference_list(&account_list, &account_count, &err)) { for (i = 0; i < account_count; i++) { if (account_list[i].incoming_server_type != EMAIL_SERVER_TYPE_ACTIVE_SYNC) { - if (!emcore_delete_account(account_list[i].account_id, &ret_code)) { - local_error_code = EMAIL_ERROR_INVALID_ACCOUNT; - EM_DEBUG_EXCEPTION("emcore_delete_account failed"); + if (!emcore_delete_account(account_list[i].account_id, true, &err)) { + EM_DEBUG_EXCEPTION("emcore_delete_account failed [%d]", err); goto FINISH_OFF; } } @@ -1083,33 +1288,48 @@ INTERNAL_FUNC int emcore_restore_accounts(const char *file_path, int *error_code } } - if (ssm_getinfo(file_path, &sfi, SSM_FLAG_SECRET_OPERATION, NULL) < 0) { - EM_DEBUG_EXCEPTION("ssm_getinfo() failed."); - ret_code = EMAIL_ERROR_SYSTEM_FAILURE; + int fd = 0; + struct stat st_buf; + + if (stat(file_path, &st_buf) < 0) { + EM_DEBUG_EXCEPTION("stat(\"%s\") failed...", file_path); + err = EMAIL_ERROR_SYSTEM_FAILURE; goto FINISH_OFF; } - buffer_length = sfi.originSize; + err = em_open(file_path, O_RDONLY, 0, &fd); + if (err != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("em_open failed : [%d] [%s]", err, file_path); + goto FINISH_OFF; + } + + buffer_length = st_buf.st_size; EM_DEBUG_LOG("account buffer_length[%d]", buffer_length); - if ((temp_buffer = (char *)em_malloc(buffer_length + 1)) == NULL) { + if ((encrypt_buffer = (char *)em_malloc(buffer_length + 1)) == NULL) { EM_DEBUG_EXCEPTION("em_malloc failed..."); - ret_code = EMAIL_ERROR_OUT_OF_MEMORY; + err = EMAIL_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 = EMAIL_ERROR_SYSTEM_FAILURE; + if (read(fd, encrypt_buffer, buffer_length) < 0) { + EM_DEBUG_EXCEPTION("read failed : [%s]", EM_STRERROR(errno_buf)); + err = EMAIL_ERROR_SYSTEM_FAILURE; + goto FINISH_OFF; + } + + if ((read_length = ssa_decrypt(encrypt_buffer, buffer_length, &temp_buffer, NULL)) < 0) { + EM_DEBUG_EXCEPTION("ss_decrypt error [%d]", read_length); + err = EMAIL_ERROR_SECURED_STORAGE_FAILURE; goto FINISH_OFF; } - EM_DEBUG_LOG("read_length[%d]", read_length); + EM_DEBUG_LOG("read_length : [%d]", read_length); - if (buffer_length == read_length) { + if (read_length > 0) { memcpy((void *)&account_count, temp_buffer, sizeof(int)); buffer_ptr = temp_buffer + sizeof(int); - EM_DEBUG_LOG("account_count[%d]", account_count); + EM_DEBUG_LOG("account_count[%d]", account_count); for (i = 0; i < account_count; i++) { memcpy((void *)&account_stream_length, buffer_ptr, sizeof(int)); @@ -1119,76 +1339,70 @@ INTERNAL_FUNC int emcore_restore_accounts(const char *file_path, int *error_code account_stream = em_malloc(account_stream_length); if (!account_stream) { EM_DEBUG_EXCEPTION("em_malloc() failed."); - ret_code = EMAIL_ERROR_OUT_OF_MEMORY ; + err = EMAIL_ERROR_OUT_OF_MEMORY ; goto FINISH_OFF; } memcpy(account_stream, buffer_ptr, account_stream_length); em_convert_byte_stream_to_account(account_stream, account_stream_length, &temp_account); EM_SAFE_FREE(account_stream); - - if (!emcore_create_account(&temp_account, &ret_code)) { - EM_DEBUG_EXCEPTION("emcore_create_account() failed."); + + if ((emstorage_check_duplicated_account(&temp_account, true, &err) == false) && (err = EMAIL_ERROR_ALREADY_EXISTS)) { + EM_DEBUG_EXCEPTION("An account is duplicated. "); + buffer_ptr += account_stream_length; + account_stream_length = 0; + emcore_free_account(&temp_account); + err = EMAIL_ERROR_NONE; + continue; + } + + if (!emcore_create_account(&temp_account, true, &err)) { + EM_DEBUG_EXCEPTION("emcore_create_account() failed. [%d]", err); goto FINISH_OFF; } emcore_free_account(&temp_account); + emcore_init_account_reference(); } buffer_ptr += account_stream_length; account_stream_length = 0; } } else { EM_DEBUG_EXCEPTION("ssm_read() failed."); - ret_code = EMAIL_ERROR_SYSTEM_FAILURE; + err = EMAIL_ERROR_SYSTEM_FAILURE; goto FINISH_OFF; } - ret_code = true; -FINISH_OFF: + +FINISH_OFF: +#ifdef FEATURE_SSS_ENABLE + EM_SAFE_CLOSE (fd); +#endif + + if (err == EMAIL_ERROR_NONE) { + if (!emcore_notify_storage_event (NOTI_ACCOUNT_RESTORE_FINISH, 0, 0, NULL, err)) + EM_DEBUG_EXCEPTION ("emcore_notify_storage_event [NOTI_ACCOUNT_RESTORE_FINISH] failed"); + } + else { + if (!emcore_notify_storage_event (NOTI_ACCOUNT_RESTORE_FAIL, 0, 0, NULL, err)) + EM_DEBUG_EXCEPTION ("emcore_notify_storage_event [NOTI_ACCOUNT_RESTORE_FAIL] failed"); + } + if(account_list) { emcore_free_account_list(&account_list, account_count, NULL); account_list = NULL; } emcore_free_account(&temp_account); + EM_SAFE_FREE(account_stream); EM_SAFE_FREE(temp_buffer); + EM_SAFE_FREE(encrypt_buffer); - EM_DEBUG_FUNC_END("ret_code [%d]", ret_code); - return ret_code; + EM_DEBUG_FUNC_END("err [%d]", err); + return err; } #endif /* __FEATURE_BACKUP_ACCOUNT_ */ - - -INTERNAL_FUNC int emcore_query_server_info(const char* domain_name, email_server_info_t **result_server_info) -{ - EM_DEBUG_FUNC_BEGIN_SEC("domain_name [%s], result_server_info [%p]", domain_name, result_server_info); - int ret_code = EMAIL_ERROR_NONE; - - EM_DEBUG_FUNC_END("ret_code [%d]", ret_code); - return ret_code; -} - - -INTERNAL_FUNC int emcore_free_server_info(email_server_info_t **target_server_info) -{ - EM_DEBUG_FUNC_BEGIN("result_server_info [%p]", target_server_info); - int i, ret_code = EMAIL_ERROR_NONE; - email_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; -} - INTERNAL_FUNC int emcore_save_default_account_id(int input_account_id) { EM_DEBUG_FUNC_BEGIN("account_id [%d]", input_account_id); @@ -1201,7 +1415,7 @@ INTERNAL_FUNC int emcore_save_default_account_id(int input_account_id) } EM_DEBUG_FUNC_END("ret_code [%d]", ret_code); - return ret_code; + return ret_code; } static int _recover_from_invalid_default_account_id(int *output_account_id) @@ -1218,7 +1432,7 @@ static int _recover_from_invalid_default_account_id(int *output_account_id) if(!emstorage_get_account_list(&account_count, &result_account_list, false, false, &ret_code) || !result_account_list) { if (ret_code == EMAIL_ERROR_ACCOUNT_NOT_FOUND) - EM_DEBUG_LOG ("no account found"); + EM_DEBUG_LOG ("no account found"); else EM_DEBUG_EXCEPTION ("emstorage_get_account_list() failed [%d]", ret_code); *output_account_id = 0; @@ -1246,7 +1460,7 @@ INTERNAL_FUNC int emcore_load_default_account_id(int *output_account_id) int ret_code = EMAIL_ERROR_NONE; int result_value = 0; emstorage_account_tbl_t *result_account = NULL; - + if (output_account_id == NULL) { ret_code = EMAIL_ERROR_INVALID_PARAM; goto FINISH_OFF; @@ -1277,7 +1491,7 @@ INTERNAL_FUNC int emcore_load_default_account_id(int *output_account_id) if ((ret_code = _recover_from_invalid_default_account_id (output_account_id)) != EMAIL_ERROR_NONE) { if (ret_code == EMAIL_ERROR_ACCOUNT_NOT_FOUND) EM_DEBUG_LOG ("no account found"); - else + else EM_DEBUG_EXCEPTION("_recover_from_invalid_default_account() failed [%d]", ret_code); *output_account_id = 0; } @@ -1286,9 +1500,9 @@ INTERNAL_FUNC int emcore_load_default_account_id(int *output_account_id) FINISH_OFF: if (result_account) emstorage_free_account(&result_account, 1, NULL); - + EM_DEBUG_FUNC_END("ret_code [%d]", ret_code); - return ret_code; + return ret_code; } INTERNAL_FUNC int emcore_recover_from_secured_storage_failure() @@ -1308,7 +1522,7 @@ INTERNAL_FUNC int emcore_recover_from_secured_storage_failure() for (i = 0; i < account_count; i++) { if(!emstorage_get_account_by_id(temp_account_tbl_list[i].account_id, EMAIL_ACC_GET_OPT_DEFAULT | EMAIL_ACC_GET_OPT_PASSWORD, &temp_account_tbl, true, &err)) { if(err == EMAIL_ERROR_SECURED_STORAGE_FAILURE) { - if(!emcore_delete_account(temp_account_tbl_list[i].account_id, &err)) { + if(!emcore_delete_account(temp_account_tbl_list[i].account_id, true, &err)) { EM_DEBUG_EXCEPTION("emcore_delete_account failed [%d]", err); goto FINISH_OFF; } @@ -1347,10 +1561,10 @@ INTERNAL_FUNC int emcore_update_sync_status_of_account(int input_account_id, ema else if(input_set_operator == SET_TYPE_MINUS) err_from_account_svc = account_update_sync_status_by_id(account_tbl_data->account_svc_id, ACCOUNT_SYNC_STATUS_IDLE); - EM_DEBUG_LOG("account_update_sync_status_by_id returns [%d] by id[%d]", err_from_account_svc, account_tbl_data->account_svc_id); + EM_DEBUG_LOG("account_update_sync_status_by_id returns [%d] by id[%d]", err_from_account_svc, account_tbl_data->account_svc_id); err_from_account_svc = account_disconnect(); - EM_DEBUG_LOG_DEV("account_disconnect returns [%d]", err_from_account_svc); + EM_DEBUG_LOG_DEV("account_disconnect returns [%d]", err_from_account_svc); } #endif /* __FEATURE_USING_ACCOUNT_SVC_FOR_SYNC_STATUS__ */ @@ -1404,7 +1618,7 @@ size_t emcore_curl_write_callback(char* data, size_t size, size_t nmemb, void* t } memcpy(*result_string + last_pos, data, received_length); - /*EM_DEBUG_LOG("result_string[%s]", *result_string);*/ + /*EM_DEBUG_LOG_SEC("result_string[%s]", *result_string);*/ FINISH_OFF: EM_DEBUG_FUNC_END("received_length [%d]", received_length); @@ -1461,7 +1675,7 @@ static int emcore_get_xoauth2_access_token(char *input_refresh_token, char **out curl_ressult_code = curl_easy_perform(curl); - EM_DEBUG_LOG("CURLcode: %d (%s)", curl_ressult_code, curl_easy_strerror(curl_ressult_code)); + EM_DEBUG_LOG_SEC("CURLcode: %d (%s)", curl_ressult_code, curl_easy_strerror(curl_ressult_code)); if (0 == curl_ressult_code) { curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &response_code); @@ -1594,7 +1808,7 @@ FINISH_OFF: emcore_free_account(ref_account); EM_SAFE_FREE(ref_account); } - + EM_DEBUG_FUNC_END("err [%d]", err); return err; } diff --git a/email-core/email-core-alarm.c b/email-core/email-core-alarm.c index 4181890..d1d75f3 100755 --- a/email-core/email-core-alarm.c +++ b/email-core/email-core-alarm.c @@ -50,18 +50,15 @@ #include "email-core-global.h" #include "email-core-alarm.h" -#ifdef __FEATURE_USE_APPSYNC__ -#include <appsync.h> -#endif - INTERNAL_FUNC GList *alarm_data_list = NULL; +static pthread_mutex_t alarm_data_lock = PTHREAD_MUTEX_INITIALIZER; INTERNAL_FUNC int emcore_get_alarm_data_by_alarm_id(alarm_id_t input_alarm_id, email_alarm_data_t **output_alarm_data) { EM_DEBUG_FUNC_BEGIN("input_alarm_id [%d] output_alarm_data [%p]", input_alarm_id, output_alarm_data); int err = EMAIL_ERROR_NONE; - GList *index = g_list_first(alarm_data_list); + GList *index = NULL; email_alarm_data_t *alarm_data = NULL; if (output_alarm_data == NULL) { @@ -70,6 +67,8 @@ INTERNAL_FUNC int emcore_get_alarm_data_by_alarm_id(alarm_id_t input_alarm_id, e goto FINISH_OFF; } + ENTER_CRITICAL_SECTION(alarm_data_lock); + index = g_list_first(alarm_data_list); while(index) { alarm_data = index->data; if(alarm_data->alarm_id == input_alarm_id) { @@ -77,6 +76,7 @@ INTERNAL_FUNC int emcore_get_alarm_data_by_alarm_id(alarm_id_t input_alarm_id, e } index = g_list_next(index); } + LEAVE_CRITICAL_SECTION(alarm_data_lock); if(alarm_data) *output_alarm_data = alarm_data; @@ -93,7 +93,7 @@ INTERNAL_FUNC int emcore_get_alarm_data_by_reference_id(email_alarm_class_t inpu { EM_DEBUG_FUNC_BEGIN("input_class_id [%d] input_reference_id [%d] output_alarm_data [%p]", input_class_id, input_reference_id, output_alarm_data); int err = EMAIL_ERROR_NONE; - GList *index = g_list_first(alarm_data_list); + GList *index = NULL; email_alarm_data_t *alarm_data = NULL; if (output_alarm_data == NULL) { @@ -102,6 +102,10 @@ INTERNAL_FUNC int emcore_get_alarm_data_by_reference_id(email_alarm_class_t inpu goto FINISH_OFF; } + ENTER_CRITICAL_SECTION(alarm_data_lock); + + index = g_list_first(alarm_data_list); + while(index) { alarm_data = index->data; if(alarm_data->class_id == input_class_id && alarm_data->reference_id == input_reference_id) { @@ -111,6 +115,8 @@ INTERNAL_FUNC int emcore_get_alarm_data_by_reference_id(email_alarm_class_t inpu index = g_list_next(index); } + LEAVE_CRITICAL_SECTION(alarm_data_lock); + if(index) *output_alarm_data = alarm_data; else @@ -126,9 +132,11 @@ INTERNAL_FUNC int emcore_check_alarm_by_class_id(email_alarm_class_t input_class { EM_DEBUG_FUNC_BEGIN("input_class_id [%d]", input_class_id); int err = EMAIL_ERROR_NONE; - GList *index = g_list_first(alarm_data_list); + GList *index = NULL; email_alarm_data_t *alarm_data = NULL; + ENTER_CRITICAL_SECTION(alarm_data_lock); + index = g_list_first(alarm_data_list); while(index) { alarm_data = index->data; if(alarm_data->class_id == input_class_id) { @@ -137,6 +145,7 @@ INTERNAL_FUNC int emcore_check_alarm_by_class_id(email_alarm_class_t input_class } index = g_list_next(index); } + LEAVE_CRITICAL_SECTION(alarm_data_lock); if(!index) err = EMAIL_ERROR_ALARM_DATA_NOT_FOUND; @@ -145,7 +154,7 @@ INTERNAL_FUNC int emcore_check_alarm_by_class_id(email_alarm_class_t input_class return err; } -static int emcore_add_alarm_data_to_alarm_data_list(alarm_id_t input_alarm_id, email_alarm_class_t input_class_id, int input_reference_id, time_t input_trigger_at_time, int (*input_alarm_callback)(int, void *), void *user_data) +static int emcore_add_alarm_data_to_alarm_data_list(alarm_id_t input_alarm_id, email_alarm_class_t input_class_id, int input_reference_id, time_t input_trigger_at_time, int (*input_alarm_callback)(email_alarm_data_t*, void *), void *user_data) { EM_DEBUG_FUNC_BEGIN("input_alarm_id [%d] input_class_id[%d] input_reference_id[%d] input_trigger_at_time[%d] input_alarm_callback [%p] user_data[%p]", input_alarm_id, input_class_id, input_reference_id, input_trigger_at_time, input_alarm_callback, user_data); int err = EMAIL_ERROR_NONE; @@ -171,12 +180,14 @@ static int emcore_add_alarm_data_to_alarm_data_list(alarm_id_t input_alarm_id, e alarm_data->alarm_callback = input_alarm_callback; alarm_data->user_data = user_data; + ENTER_CRITICAL_SECTION(alarm_data_lock); alarm_data_list = g_list_append(alarm_data_list, (gpointer)alarm_data); + LEAVE_CRITICAL_SECTION(alarm_data_lock); FINISH_OFF: - EM_DEBUG_FUNC_END("err [%d]", EMAIL_ERROR_NONE); - return EMAIL_ERROR_NONE; + EM_DEBUG_FUNC_END("err [%d]", err); + return err; } static int emcore_remove_alarm(email_alarm_data_t *input_alarm_data) @@ -186,11 +197,13 @@ static int emcore_remove_alarm(email_alarm_data_t *input_alarm_data) int ret = ALARMMGR_RESULT_SUCCESS; int err = EMAIL_ERROR_NONE; + ENTER_CRITICAL_SECTION(alarm_data_lock); EM_DEBUG_LOG("alarm_id [%d]", input_alarm_data->alarm_id); if ((ret = alarmmgr_remove_alarm(input_alarm_data->alarm_id)) != ALARMMGR_RESULT_SUCCESS) { EM_DEBUG_EXCEPTION ("alarmmgr_remove_alarm failed [%d]", ret); err = EMAIL_ERROR_SYSTEM_FAILURE; } + LEAVE_CRITICAL_SECTION(alarm_data_lock); EM_DEBUG_FUNC_END("err [%d]", err); return err; @@ -201,12 +214,25 @@ INTERNAL_FUNC int emcore_delete_alram_data_from_alarm_data_list(email_alarm_data EM_DEBUG_FUNC_BEGIN("input_alarm_data [%p]", input_alarm_data); int err = EMAIL_ERROR_NONE; + if (input_alarm_data == NULL ) { + EM_DEBUG_EXCEPTION ("EMAIL_ERROR_INVALID_PARAM"); + err = EMAIL_ERROR_INVALID_PARAM; + goto FINISH_OFF; + } + if ((err = emcore_remove_alarm(input_alarm_data)) != EMAIL_ERROR_NONE) { EM_DEBUG_EXCEPTION ("emcore_remove_alarm failed [%d]", err); } - alarm_data_list = g_list_remove(alarm_data_list, input_alarm_data); + ENTER_CRITICAL_SECTION(alarm_data_lock); + alarm_data_list = g_list_remove_all(alarm_data_list, input_alarm_data); + if (g_list_length(alarm_data_list) == 0) { + g_list_free (alarm_data_list); + alarm_data_list = NULL; + } + LEAVE_CRITICAL_SECTION(alarm_data_lock); +FINISH_OFF: EM_DEBUG_FUNC_END("err [%d]", err); return err; } @@ -231,7 +257,7 @@ FINISH_OFF: return err; } -INTERNAL_FUNC int emcore_add_alarm(time_t input_trigger_at_time, email_alarm_class_t input_class_id, int input_reference_id, int (*input_alarm_callback)(int, void *), void *input_user_data) +INTERNAL_FUNC int emcore_add_alarm(time_t input_trigger_at_time, email_alarm_class_t input_class_id, int input_reference_id, int (*input_alarm_callback)(email_alarm_data_t*, void *), void *input_user_data) { EM_DEBUG_FUNC_BEGIN("input_trigger_at_time[%d] input_class_id[%d] input_reference_id[%d] input_alarm_callback[%p] input_user_data[%p]", input_trigger_at_time, input_class_id, input_reference_id, input_alarm_callback, input_user_data); @@ -247,22 +273,10 @@ INTERNAL_FUNC int emcore_add_alarm(time_t input_trigger_at_time, email_alarm_cla EM_DEBUG_ALARM_LOG("alarm_interval [%d]", (int)alarm_interval); -#ifdef __FEATURE_USE_APPSYNC__ - if(input_class_id == EMAIL_ALARM_CLASS_AUTO_POLLING) { - if ((ret = appsync_daemon_schedule_after_delay(alarm_interval, 0, &alarm_id)) != APPSYNC_ERROR_NONE) { - EM_DEBUG_EXCEPTION("appsync_daemon_schedule_after_delay failed [%d]",ret); - err = EMAIL_ERROR_SYSTEM_FAILURE; - goto FINISH_OFF; - } - } - else -#endif - { - if ((ret = alarmmgr_add_alarm(ALARM_TYPE_VOLATILE, alarm_interval, ALARM_REPEAT_MODE_ONCE, EMAIL_ALARM_DESTINATION, &alarm_id)) != ALARMMGR_RESULT_SUCCESS) { - EM_DEBUG_EXCEPTION("alarmmgr_add_alarm failed [%d]",ret); - err = EMAIL_ERROR_SYSTEM_FAILURE; - goto FINISH_OFF; - } + if ((ret = alarmmgr_add_alarm(ALARM_TYPE_VOLATILE, alarm_interval, ALARM_REPEAT_MODE_ONCE, EMAIL_ALARM_DESTINATION, &alarm_id)) != ALARMMGR_RESULT_SUCCESS) { + EM_DEBUG_EXCEPTION("alarmmgr_add_alarm failed [%d]",ret); + err = EMAIL_ERROR_SYSTEM_FAILURE; + goto FINISH_OFF; } if((err = emcore_add_alarm_data_to_alarm_data_list(alarm_id, input_class_id, input_reference_id, input_trigger_at_time, input_alarm_callback, input_user_data)) != EMAIL_ERROR_NONE) { diff --git a/email-core/email-core-auto-download.c b/email-core/email-core-auto-download.c new file mode 100755 index 0000000..f5bdc5c --- /dev/null +++ b/email-core/email-core-auto-download.c @@ -0,0 +1,816 @@ +/* +* email-service +* +* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. +* +* Contact: Minsoo Kim <minnsoo.kim@samsung.com>, 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 <glib.h> +#include <malloc.h> +#include <pthread.h> +#include <vconf.h> +#include "email-storage.h" +#include "email-utilities.h" +#include "email-daemon.h" +#include "email-network.h" +#include "email-core-global.h" +#include "email-core-account.h" +#include "email-core-event.h" +#include "email-core-utils.h" +#include "email-core-mailbox.h" +#include "email-core-imap-mailbox.h" +#include "email-core-mail.h" +#include "email-core-mailbox-sync.h" +#include "email-core-smtp.h" +#include "email-core-utils.h" +#include "email-debug-log.h" +#include "email-types.h" +#include "email-internal-types.h" +#include "email-core-auto-download.h" + +/*----------------------------------------------------------------------------- + * Auto Download Event Queue + *---------------------------------------------------------------------------*/ +INTERNAL_FUNC thread_t g_auto_download_thread; +INTERNAL_FUNC pthread_cond_t _auto_downalod_available_signal = PTHREAD_COND_INITIALIZER; +INTERNAL_FUNC pthread_mutex_t *_auto_download_queue_lock = NULL; + +INTERNAL_FUNC GQueue *g_auto_download_que = NULL; +INTERNAL_FUNC int g_auto_download_loop = 1; +INTERNAL_FUNC int auto_download_thread_run = 0; + +#define AUTO_DOWNLOAD_QUEUE_MAX 100 + +static void* worker_auto_download_queue(void *arg); + +INTERNAL_FUNC int emcore_start_auto_download_loop(int *err_code) +{ + EM_DEBUG_FUNC_BEGIN(); + int thread_error; + + if (err_code != NULL) + *err_code = EMAIL_ERROR_NONE; + + if (g_auto_download_thread) { + EM_DEBUG_EXCEPTION("auto downlaod thread is already running..."); + if (err_code != NULL) + *err_code = EMAIL_ERROR_UNKNOWN; + return true; + } + + g_auto_download_que = g_queue_new(); + g_queue_init(g_auto_download_que); + g_auto_download_loop = 1; + + /* initialize lock */ + INITIALIZE_RECURSIVE_CRITICAL_SECTION(_auto_download_queue_lock); + + /* create thread */ + THREAD_CREATE(g_auto_download_thread, worker_auto_download_queue, NULL, thread_error); + + if (thread_error != 0) { + EM_DEBUG_EXCEPTION("cannot create thread"); + g_auto_download_loop = 0; + if (err_code != NULL) + *err_code = EMAIL_ERROR_SYSTEM_FAILURE; + return false; + } + + if (err_code != NULL) + *err_code = EMAIL_ERROR_NONE; + + return true; +} + + +INTERNAL_FUNC int emcore_auto_download_loop_continue(void) +{ + return g_auto_download_loop; +} + + +INTERNAL_FUNC int emcore_stop_auto_download_loop(int *err_code) +{ + EM_DEBUG_FUNC_BEGIN(); + + if (err_code != NULL) + *err_code = EMAIL_ERROR_NONE; + + if (!g_auto_download_thread) { + if (err_code != NULL) + *err_code = EMAIL_ERROR_UNKNOWN; + return false; + } + + /* stop event_data loop */ + g_auto_download_loop = 0; + + WAKE_CONDITION_VARIABLE(_auto_downalod_available_signal); + + /* wait for thread finished */ + THREAD_JOIN(g_auto_download_thread); + + g_queue_free(g_auto_download_que); + + g_auto_download_thread = 0; + + DELETE_RECURSIVE_CRITICAL_SECTION(_auto_download_queue_lock); + DELETE_CONDITION_VARIABLE(_auto_downalod_available_signal); + + if (err_code != NULL) + *err_code = EMAIL_ERROR_NONE; + EM_DEBUG_FUNC_END(); + return true; +} + + +INTERNAL_FUNC int emcore_insert_auto_download_event(email_event_auto_download *event_data, int *err_code) +{ + EM_DEBUG_FUNC_BEGIN("event_data[%p], err_code[%p]", event_data, err_code); + + if (!event_data) { + EM_DEBUG_EXCEPTION("Invalid Parameter"); + if (err_code != NULL) + *err_code = EMAIL_ERROR_INVALID_PARAM; + return false; + } + + if (!g_auto_download_thread) { + EM_DEBUG_EXCEPTION("g_auto_download_thread is not ready"); + if (err_code != NULL) + *err_code = EMAIL_ERROR_LOAD_ENGINE_FAILURE; + return false; + } + + int ret = false; + int error = EMAIL_ERROR_NONE; + int q_length = 0; + + ENTER_RECURSIVE_CRITICAL_SECTION(_auto_download_queue_lock); + + if (g_auto_download_que) + q_length = g_queue_get_length(g_auto_download_que); + EM_DEBUG_LOG("Q Length : [%d]", q_length); + + if (q_length > AUTO_DOWNLOAD_QUEUE_MAX) { + EM_DEBUG_EXCEPTION("auto download que is full..."); + error = EMAIL_ERROR_EVENT_QUEUE_FULL; + ret = false; + } else { + event_data->status = EMAIL_EVENT_STATUS_WAIT; + g_queue_push_tail(g_auto_download_que, event_data); + //WAKE_CONDITION_VARIABLE(_auto_downalod_available_signal); + ret = true; + } + + LEAVE_RECURSIVE_CRITICAL_SECTION(_auto_download_queue_lock); + + if (err_code) { + EM_DEBUG_LOG("ERR [%d]", error); + *err_code = error; + } + + return ret; +} + + +INTERNAL_FUNC int emcore_retrieve_auto_download_event(email_event_auto_download **event_data, int *err_code) +{ + EM_DEBUG_FUNC_BEGIN("event_data[%p], err_code[%p]", event_data, err_code); + + int ret = false; + int error = EMAIL_ERROR_NONE; + int q_length = 0; + //email_event_auto_download *poped = NULL; + email_event_auto_download *head_event = NULL; + + if (g_auto_download_que) + q_length = g_queue_get_length(g_auto_download_que); + EM_DEBUG_LOG("Q Length : [%d]", q_length); + + if (!q_length) { + error = EMAIL_ERROR_EVENT_QUEUE_EMPTY; + EM_DEBUG_LOG("QUEUE is empty"); + goto FINISH_OFF; + } + + while (1) { + head_event = (email_event_auto_download *)g_queue_peek_head(g_auto_download_que); + if (!head_event) { + error = EMAIL_ERROR_EVENT_QUEUE_EMPTY; + EM_DEBUG_LOG_DEV ("QUEUE is empty"); + break; + } + + /*if (head_event->status != EMAIL_EVENT_STATUS_WAIT) { + EM_DEBUG_LOG("EVENT STATUS [%d]", head_event->status); + poped = g_queue_pop_head(g_auto_download_que); + if (poped) { + EM_SAFE_FREE(poped); + } else { + error = EMAIL_ERROR_EVENT_QUEUE_EMPTY; + EM_DEBUG_LOG("QUEUE is empty"); + break; + } + } else*/ + { + head_event->status = EMAIL_EVENT_STATUS_STARTED; + *event_data = head_event; + ret = true; + break; + } + } + +FINISH_OFF: + + if (err_code != NULL) + *err_code = error; + + EM_DEBUG_FUNC_END("ret [%d]", ret); + return ret; +} + + +INTERNAL_FUNC int emcore_is_auto_download_queue_empty(void) +{ + EM_DEBUG_FUNC_BEGIN(); + + int ret = false; + int q_length = 0; + + ENTER_RECURSIVE_CRITICAL_SECTION(_auto_download_queue_lock); + + if (g_auto_download_que) + q_length = g_queue_get_length(g_auto_download_que); + + EM_DEBUG_LOG("Q Length : [%d]", q_length); + + if (q_length <= 0) { + EM_DEBUG_LOG("auto downlaod que is empty..."); + ret = true; + } + + LEAVE_RECURSIVE_CRITICAL_SECTION(_auto_download_queue_lock); + EM_DEBUG_FUNC_END("ret [%d]", ret); + return ret; +} + + +INTERNAL_FUNC int emcore_is_auto_download_queue_full(void) +{ + EM_DEBUG_FUNC_BEGIN(); + + int ret = false; + int q_length = 0; + + ENTER_RECURSIVE_CRITICAL_SECTION(_auto_download_queue_lock); + + if (g_auto_download_que) + q_length = g_queue_get_length(g_auto_download_que); + + EM_DEBUG_LOG("Q Length : [%d]", q_length); + + if (q_length > AUTO_DOWNLOAD_QUEUE_MAX) { + EM_DEBUG_LOG("auto downlaod que is full..."); + ret = true; + } + + LEAVE_RECURSIVE_CRITICAL_SECTION(_auto_download_queue_lock); + EM_DEBUG_FUNC_END(); + return ret; +} + + +INTERNAL_FUNC int emcore_clear_auto_download_queue(void) +{ + EM_DEBUG_FUNC_BEGIN(); + int ret = false; + int i = 0; + int q_length = 0; + email_event_auto_download *pop_elm = NULL; + + ENTER_RECURSIVE_CRITICAL_SECTION(_auto_download_queue_lock); + + q_length = g_auto_download_que? g_queue_get_length (g_auto_download_que): 0; + + for (i = 0; i < q_length; i++) { + pop_elm = (email_event_auto_download *)g_queue_peek_nth(g_auto_download_que, i); + + if (pop_elm) { + EM_SAFE_FREE(pop_elm); + } + } + + g_queue_clear(g_auto_download_que); + ret = true; + + LEAVE_RECURSIVE_CRITICAL_SECTION(_auto_download_queue_lock); + EM_DEBUG_FUNC_END(); + return ret; +} + + +static void* worker_auto_download_queue(void *arg) +{ + EM_DEBUG_FUNC_BEGIN(); + int err = EMAIL_ERROR_NONE; + + int ai = 0; + int mi = 0; + int di = 0; + int account_count = 0; + int mailbox_count = 0; + int activity_count = 0; + int activity_list_count = 0; + int *account_list = NULL; + int *mailbox_list = NULL; + email_event_auto_download *event_data = NULL; + email_event_auto_download *started_event = NULL; + email_event_auto_download *activity_list = NULL; + + + if (!emstorage_open(&err)) { + EM_DEBUG_EXCEPTION("emstorage_open falied [%d]", err); + return false; + } + + /* check that event_data loop is continuous */ + while (emcore_auto_download_loop_continue()) { + + ENTER_RECURSIVE_CRITICAL_SECTION(_auto_download_queue_lock); + + if (!emcore_retrieve_auto_download_event(&event_data, &err)) { + /* no event_data pending */ + if (err != EMAIL_ERROR_EVENT_QUEUE_EMPTY) { + LEAVE_RECURSIVE_CRITICAL_SECTION(_auto_download_queue_lock); + continue; + } + + activity_count = 0; + if (!emstorage_get_auto_download_activity_count(&activity_count, false, &err)) { + EM_DEBUG_LOG("emstorage_get_auto_download_activity_count failed [%d]", err); + goto CHECK_CONTINUE; + } + + if (activity_count <= 0) { + EM_DEBUG_LOG("auto download activity count is 0"); + goto CHECK_CONTINUE; + } + + account_count = 0; + EM_SAFE_FREE(account_list); + if (!emstorage_get_auto_download_account_list(&account_list, &account_count, false, &err)) { + EM_DEBUG_EXCEPTION(" emstorage_get_auto_download_account_list failed.. [%d]", err); + goto CHECK_CONTINUE; + } + + if (account_count <= 0 || !account_list) { + EM_DEBUG_LOG("auto download account count is 0"); + goto CHECK_CONTINUE; + } + + for (ai = 0; ai < account_count; ai++) { + + email_account_t *account_ref = NULL; + if (!(account_ref = emcore_get_account_reference(account_list[ai]))) { + EM_DEBUG_EXCEPTION("emcore_get_account_reference failed [%d]", account_list[ai]); + err = EMAIL_ERROR_INVALID_ACCOUNT; + continue; + } + + if (!(account_ref->wifi_auto_download)) { + if (account_ref) { + emcore_free_account(account_ref); + EM_SAFE_FREE(account_ref); + } + + continue; + } + + if (account_ref) { + emcore_free_account(account_ref); + EM_SAFE_FREE(account_ref); + } + + mailbox_count = 0; + EM_SAFE_FREE(mailbox_list); + if (!emstorage_get_auto_download_mailbox_list(account_list[ai], &mailbox_list, &mailbox_count, false, &err)) { + EM_DEBUG_EXCEPTION(" emstorage_get_auto_download_mailbox_list failed.. [%d]", err); + goto CHECK_CONTINUE; + } + + if (mailbox_count <= 0 || !mailbox_list) { + EM_DEBUG_LOG("auto download mailbox count is 0"); + goto CHECK_CONTINUE; + } + + for (mi = 0; mi < mailbox_count; mi++) { + emstorage_mailbox_tbl_t *target_mailbox = NULL; + + activity_list_count = 0; + EM_SAFE_FREE(activity_list); + + if ((err = emstorage_get_mailbox_by_id(mailbox_list[mi], &target_mailbox)) != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emstorage_get_mailbox_by_id failed. [%d]", err); + } + + if (target_mailbox) { + if (target_mailbox->mailbox_type != EMAIL_MAILBOX_TYPE_INBOX) { + EM_DEBUG_LOG("Not INBOX mail, skip to next"); + emstorage_free_mailbox(&target_mailbox, 1, NULL); + continue; + } + emstorage_free_mailbox(&target_mailbox, 1, NULL); + } + + if (!emstorage_get_auto_download_activity(account_list[ai], mailbox_list[mi], &activity_list, &activity_list_count, false, &err)) { + EM_DEBUG_EXCEPTION(" emstorage_get_auto_download_activity failed.. [%d]", err); + goto CHECK_CONTINUE; + } + + if (activity_list_count <= 0 || !activity_list) { + EM_DEBUG_LOG("auto download activity count is 0"); + goto CHECK_CONTINUE; + } + + for (di = 0; di < activity_list_count; di++) { + email_event_auto_download *activity = NULL; + activity = (email_event_auto_download *)em_malloc(sizeof(email_event_auto_download)); + if (!activity) { + EM_DEBUG_EXCEPTION("Malloc failed"); + err = EMAIL_ERROR_OUT_OF_MEMORY; + goto CHECK_CONTINUE; + } + + activity->activity_id = activity_list[di].activity_id; + activity->status = 0; + activity->account_id = activity_list[di].account_id; + activity->mail_id = activity_list[di].mail_id; + activity->server_mail_id = activity_list[di].server_mail_id; + activity->mailbox_id = activity_list[di].mailbox_id; + + if (!emcore_insert_auto_download_event(activity, &err)) { + EM_DEBUG_EXCEPTION("emcore_insert_auto_download_event is failed [%d]", err); + EM_SAFE_FREE(activity); + if (err == EMAIL_ERROR_EVENT_QUEUE_FULL) goto CHECK_CONTINUE; + } + } + } + } + +CHECK_CONTINUE: + + EM_SAFE_FREE(account_list); + EM_SAFE_FREE(mailbox_list); + EM_SAFE_FREE(activity_list); + + if (!emcore_is_auto_download_queue_empty()) { + LEAVE_RECURSIVE_CRITICAL_SECTION(_auto_download_queue_lock); + continue; + } + + auto_download_thread_run = 0; + //go to sleep when queue is empty + SLEEP_CONDITION_VARIABLE(_auto_downalod_available_signal, *_auto_download_queue_lock); + EM_DEBUG_LOG("Wake up by _auto_downalod_available_signal"); + LEAVE_RECURSIVE_CRITICAL_SECTION(_auto_download_queue_lock); + } + else { + LEAVE_RECURSIVE_CRITICAL_SECTION(_auto_download_queue_lock); + EM_DEBUG_LOG_DEV(">>>>>>>>>>>>>>> Got auto download event_data !!! <<<<<<<<<<<<<<<"); + int state1 = 0, state2 = 0, state3 = 0, wifi_status = 0; + char uid_str[50] = {0, }; + emstorage_mail_tbl_t *mail = NULL; + emstorage_mailbox_tbl_t *target_mailbox = NULL; + email_account_t *account_ref = NULL; + auto_download_thread_run = 1; + + if ((err = emnetwork_get_wifi_status(&wifi_status)) != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emnetwork_get_wifi_status failed [%d]", err); + } + + EM_DEBUG_LOG("WIFI Status [%d]", wifi_status); + + if ((state1 = emcore_get_pbd_thd_state()) == true || + (state2 = emcore_is_event_queue_empty()) == false || + (state3 = emcore_is_send_event_queue_empty()) == false || + (wifi_status <= 1)) { + + EM_DEBUG_LOG("Auto Download Thread going to SLEEP"); + + ENTER_RECURSIVE_CRITICAL_SECTION(_auto_download_queue_lock); + auto_download_thread_run = 0; + SLEEP_CONDITION_VARIABLE(_auto_downalod_available_signal, *_auto_download_queue_lock); + EM_DEBUG_LOG("Wake up by _auto_downalod_available_signal"); + LEAVE_RECURSIVE_CRITICAL_SECTION(_auto_download_queue_lock); + + auto_download_thread_run = 1; + } + + if (!(account_ref = emcore_get_account_reference(event_data->account_id))) { + EM_DEBUG_EXCEPTION("emcore_get_account_reference failed [%d]", event_data->account_id); + err = EMAIL_ERROR_INVALID_ACCOUNT; + goto POP_HEAD; + } + + if (!(account_ref->wifi_auto_download)) { + EM_DEBUG_LOG("ACCOUNT[%d] AUTO DOWNLOAD MODE OFF", event_data->account_id); + goto POP_HEAD; + } + + if (account_ref) { + emcore_free_account(account_ref); + EM_SAFE_FREE(account_ref); + } + + if ((err = emstorage_get_mailbox_by_id(event_data->mailbox_id, &target_mailbox)) != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emstorage_get_mailbox_by_id failed. [%d]", err); + } + + if (target_mailbox) { + if (target_mailbox->mailbox_type != EMAIL_MAILBOX_TYPE_INBOX) { + EM_DEBUG_LOG("Not INBOX mail, skip to next"); + emstorage_free_mailbox(&target_mailbox, 1, NULL); + goto DELETE_ACTIVITY; + } + + emstorage_free_mailbox(&target_mailbox, 1, NULL); + } + + /* Handling storage full */ + if ((err = emcore_is_storage_full()) == EMAIL_ERROR_MAIL_MEMORY_FULL) { + EM_DEBUG_EXCEPTION("Storage is full"); + + ENTER_RECURSIVE_CRITICAL_SECTION(_auto_download_queue_lock); + auto_download_thread_run = 0; + SLEEP_CONDITION_VARIABLE(_auto_downalod_available_signal, *_auto_download_queue_lock); + EM_DEBUG_LOG("Wake up by _auto_downalod_available_signal"); + LEAVE_RECURSIVE_CRITICAL_SECTION(_auto_download_queue_lock); + + continue; + } + + snprintf(uid_str, sizeof(uid_str), "%ld", event_data->server_mail_id); + if (!emstorage_get_maildata_by_servermailid(event_data->mailbox_id, uid_str, &mail, true, &err) || !mail) { + EM_DEBUG_EXCEPTION("emstorage_get_mail_data_by_servermailid failed : [%d]", err); + } + else { + if (mail->body_download_status & EMAIL_BODY_DOWNLOAD_STATUS_FULLY_DOWNLOADED) { + EM_DEBUG_LOG("fully downloaded mail"); + } + else { + EM_DEBUG_LOG("#####AUTO DOWNLOAD BODY: ACCOUNT_ID[%d] MAILBOX_ID[%d] MAIL_ID[%d] UID[%d] ACTIVITY[%d]#####", + event_data->account_id, event_data->mailbox_id, + event_data->mail_id, event_data->server_mail_id, event_data->activity_id); + + if (!emcore_gmime_download_body_sections(NULL, event_data->account_id, event_data->mail_id, + 1, NO_LIMITATION, -1, 0, 1, &err)) + EM_DEBUG_EXCEPTION("emcore_gmime_download_body_sections failed - %d", err); + } + + if (mail->attachment_count > 0) { + int i = 0; + int j = 0; + int attachment_count = 0; + emstorage_attachment_tbl_t *attachment_list = NULL; + + if ((err = emstorage_get_attachment_list(event_data->mail_id, true, &attachment_list, &attachment_count)) != EMAIL_ERROR_NONE ) { + EM_DEBUG_EXCEPTION("emstorage_get_attachment_list failed [%d]", err); + } else { + for (i = 0; i < attachment_count; i++) { + if (attachment_list[i].attachment_inline_content_status) + continue; + + j++; + + if (attachment_list[i].attachment_save_status) + continue; + + EM_DEBUG_LOG("#####AUTO DOWNLOAD ATTACHMENT[%d]: ACCOUNT_ID[%d] MAILBOX_ID[%d] MAIL_ID[%d] UID[%d] ACTIVITY[%d]#####", + j, event_data->account_id, event_data->mailbox_id, + event_data->mail_id, event_data->server_mail_id, event_data->activity_id); + + if (!emcore_gmime_download_attachment(event_data->mail_id, j, 0, -1, 1, &err)) + EM_DEBUG_EXCEPTION("emcore_gmime_download_attachment failed [%d]", err); + } + + if (attachment_list) + emstorage_free_attachment(&attachment_list, attachment_count, NULL); + } + } + + if (mail) + emstorage_free_mail(&mail, 1, NULL); + } + +DELETE_ACTIVITY: + if (!emcore_delete_auto_download_activity(event_data->account_id, event_data->mail_id, event_data->activity_id, &err)) { + EM_DEBUG_EXCEPTION("emcore_delete_auto_download_activity failed [%d]", err); + } + + +POP_HEAD: + /* free event itself */ + ENTER_RECURSIVE_CRITICAL_SECTION(_auto_download_queue_lock); + started_event = g_queue_pop_head(g_auto_download_que); + LEAVE_RECURSIVE_CRITICAL_SECTION(_auto_download_queue_lock); + if (!started_event) { + EM_DEBUG_EXCEPTION("Failed to g_queue_pop_head"); + } + else { + EM_SAFE_FREE(started_event); + } + + if (account_ref) { + emcore_free_account(account_ref); + EM_SAFE_FREE(account_ref); + } + + em_flush_memory(); + } + } + + if (!emstorage_close(&err)) + EM_DEBUG_EXCEPTION("emstorage_close falied [%d]", err); + + emcore_close_recv_stream_list(); + + EM_DEBUG_FUNC_END(); + return SUCCESS; +} + + +INTERNAL_FUNC int emcore_insert_auto_download_job(int account_id, int mailbox_id, int mail_id, int auto_download_on, char *uid, int *err_code) +{ + EM_DEBUG_FUNC_BEGIN("account_id [%d], maibox_id[%d], mail_id[%d], uid[%p]", account_id, mailbox_id, mail_id, uid); + + int ret = false; + int err = EMAIL_ERROR_NONE; + int event_pushed = 0; + email_event_auto_download *ad_event = NULL; + + if (account_id < FIRST_ACCOUNT_ID || mailbox_id <= 0 || mail_id < 0 || !uid) { + EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM"); + err = EMAIL_ERROR_INVALID_PARAM; + goto FINISH_OFF; + } + + ad_event = (email_event_auto_download *)em_malloc(sizeof(email_event_auto_download)); + + if (!ad_event) { + EM_DEBUG_EXCEPTION("em_malloc failed..."); + err = EMAIL_ERROR_OUT_OF_MEMORY; + goto FINISH_OFF; + } + + ad_event->status = 0; + ad_event->account_id = account_id; + ad_event->mail_id = mail_id; + ad_event->server_mail_id = strtoul(uid, NULL, 0); + ad_event->mailbox_id = mailbox_id; + + if (!emcore_insert_auto_download_activity(ad_event, &(ad_event->activity_id), &err)) { + EM_DEBUG_EXCEPTION("Inserting auto download activity failed with error[%d]", err); + goto FINISH_OFF; + } + else { + ret = true; + + if (!auto_download_on) { + goto FINISH_OFF; + } + + if (emcore_is_auto_download_queue_full()) { + EM_DEBUG_LOG("Activity inserted only in DB .. Queue is Full"); + } + else { + if (!emcore_insert_auto_download_event(ad_event, &err)) { + EM_DEBUG_EXCEPTION("emcore_insert_auto_download_event is failed [%d]", err); + goto FINISH_OFF; + } + event_pushed = 1; + } + } + +FINISH_OFF: + + if (!event_pushed) + EM_SAFE_FREE(ad_event); + + EM_DEBUG_FUNC_END(); + return ret; +} + + +INTERNAL_FUNC int emcore_insert_auto_download_activity(email_event_auto_download *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 = EMAIL_ERROR_INVALID_PARAM; + return false; + } + + int ret = false; + int err = EMAIL_ERROR_NONE; + int before_tr_begin = 0; + + if (!emstorage_begin_transaction(NULL, NULL, &err)) { + EM_DEBUG_EXCEPTION("emstorage_begin_transaction failed [%d]", err); + before_tr_begin = 1; + goto FINISH_OFF; + } + + if (!emstorage_add_auto_download_activity(local_activity, activity_id, false, &err)) { + EM_DEBUG_EXCEPTION("emstorage_add_auto_download_activity failed [%d]", err); + goto FINISH_OFF; + } + + ret = true; + +FINISH_OFF: + if (ret == true) { /* COMMIT TRANSACTION; */ + if (emstorage_commit_transaction(NULL, NULL, NULL) == false) { + err = EMAIL_ERROR_DB_FAILURE; + ret = false; + } + } else { /* ROLLBACK TRANSACTION; */ + if (!before_tr_begin && emstorage_rollback_transaction(NULL, NULL, NULL) == false) + err = EMAIL_ERROR_DB_FAILURE; + } + + if (err_code != NULL) + *err_code = err; + EM_DEBUG_FUNC_END(); + return ret; +} + + +INTERNAL_FUNC int emcore_delete_auto_download_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 = EMAIL_ERROR_INVALID_PARAM; + return false; + } + + int ret = false; + int err = EMAIL_ERROR_NONE; + int before_tr_begin = 0; + + if (!emstorage_begin_transaction(NULL, NULL, &err)) { + EM_DEBUG_EXCEPTION("emstorage_begin_transaction failed [%d]", err); + before_tr_begin = 1; + goto FINISH_OFF; + } + + if (!emstorage_delete_auto_download_activity(account_id, mail_id, activity_id, false, &err)) { + EM_DEBUG_EXCEPTION("emstorage_delete_auto_download_activity failed [%d]", err); + goto FINISH_OFF; + } + else if (err == EMAIL_ERROR_DATA_NOT_FOUND) + err = EMAIL_ERROR_NONE; + + ret = true; + +FINISH_OFF: + + if (ret == true) { /* COMMIT TRANSACTION; */ + if (emstorage_commit_transaction(NULL, NULL, NULL) == false) { + err = EMAIL_ERROR_DB_FAILURE; + ret = false; + } + } else { /* ROLLBACK TRANSACTION; */ + if (!before_tr_begin && emstorage_rollback_transaction(NULL, NULL, NULL) == false) + err = EMAIL_ERROR_DB_FAILURE; + } + + if (err_code != NULL) + *err_code = err; + EM_DEBUG_FUNC_END(); + return ret; +} + + diff --git a/email-core/email-core-cert.c b/email-core/email-core-cert.c index 7247b4e..0b7de69 100755 --- a/email-core/email-core-cert.c +++ b/email-core/email-core-cert.c @@ -4,7 +4,7 @@ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> -* +* * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -24,9 +24,9 @@ * File : email-core-cert.h * Desc : Certificate API * - * Auth : + * Auth : * - * History : + * History : * 2006.08.16 : created *****************************************************************************/ #include <openssl/pkcs7.h> @@ -55,7 +55,7 @@ typedef enum { CERT_TYPE_ETC = 0, - CERT_TYPE_PKCS12, + CERT_TYPE_PKCS12, CERT_TYPE_PKCS7, CERT_TYPE_P7S } cert_type; @@ -73,7 +73,7 @@ static int emcore_get_certificate_type(char *extension, int *err_code) err = EMAIL_ERROR_INVALID_PARAM; goto FINISH_OFF; } - + while(supported_file_type[index]) { EM_DEBUG_LOG_SEC("certificate extension[%d]:[%s]", index, supported_file_type[index]); if (strcasecmp(extension, supported_file_type[index]) == 0) { @@ -95,7 +95,7 @@ static int emcore_get_certificate_type(char *extension, int *err_code) default: type = CERT_TYPE_ETC; err = EMAIL_ERROR_INVALID_CERTIFICATE; - break; + break; } } index++; @@ -110,7 +110,7 @@ FINISH_OFF: EM_DEBUG_FUNC_END("File type is [%d]", type); return type; } -/* +/* static GList *emcore_make_glist_from_string(char *email_address_list) { EM_DEBUG_FUNC_BEGIN_SEC("email_address list : [%s]", email_address_list); @@ -127,11 +127,11 @@ static GList *emcore_make_glist_from_string(char *email_address_list) email_list = g_list_append(email_list, token_list[index]); index++; } - + if (p_email_address_list) g_free(p_email_address_list); - return email_list; + return email_list; } static char *emcore_store_public_certificate(STACK_OF(X509) *certificates, char *email_address, int *err_code) @@ -161,7 +161,7 @@ static char *emcore_store_public_certificate(STACK_OF(X509) *certificates, char EM_DEBUG_LOG("Write the certificate in pem file : [%d]", index); PEM_write_bio_X509(outfile, sk_X509_value(certificates, index)); } - + FINISH_OFF: if (outfile) @@ -182,14 +182,12 @@ INTERNAL_FUNC int emcore_load_PFX_file(char *certificate, char *password, EVP_PK FILE *fp = NULL; PKCS12 *p12 = NULL; - OpenSSL_add_all_algorithms(); - ERR_load_crypto_strings(); - if (!(fp = fopen(certificate, "rb"))) { - EM_DEBUG_EXCEPTION_SEC("fopen failed : [%s]", certificate); - err = EMAIL_ERROR_SYSTEM_FAILURE; + err = em_fopen(certificate, "rb", &fp); + if (err != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION_SEC("em_fopen failed : [%s] [%d]", certificate, err); goto FINISH_OFF; } - + p12 = d2i_PKCS12_fp(fp, NULL); if (!p12) { EM_DEBUG_EXCEPTION("d2i_PKCS12_fp failed"); @@ -216,7 +214,7 @@ FINISH_OFF: if (err_code) *err_code = err; - return ret; + return ret; } #endif @@ -232,7 +230,7 @@ INTERNAL_FUNC int emcore_load_PFX_file(char *certificate, EVP_PKEY **pri_key, X5 X509 *t_cert = NULL; BIO *bio_mem = NULL; // STACK_OF(X509) *t_ca = NULL; - + /* Variable for private key */ EVP_PKEY *t_pri_key = NULL; @@ -319,7 +317,7 @@ INTERNAL_FUNC int emcore_load_PFX_file(char *certificate, EVP_PKEY **pri_key, X5 } ret = true; - + FINISH_OFF: if (bio_mem) @@ -345,10 +343,107 @@ FINISH_OFF: return ret; } +INTERNAL_FUNC int emcore_load_PFX_file_from_string(char *certificate, char **key_string, int *key_size, int *err_code) +{ + EM_DEBUG_FUNC_BEGIN_SEC("certificate : [%s]", certificate); + int err = EMAIL_ERROR_NONE; + int ret = false; + size_t p_key_size = 0; + char *private_key = NULL; + + /* Variable for certificate */ + X509 *t_cert = NULL; +// STACK_OF(X509) *t_ca = NULL; + + /* Variable for private key */ + EVP_PKEY *t_pri_key = NULL; + + CertSvcString csstring; + CertSvcInstance cert_instance; + CertSvcCertificate csc_cert; + CertSvcCertificateList certificate_list; + + if (certificate == NULL) { + EM_DEBUG_EXCEPTION("Invalid parameter"); + err = EMAIL_ERROR_INVALID_PARAM; + goto FINISH_OFF; + } + + /* Create instance */ + err = certsvc_instance_new(&cert_instance); + if (err != CERTSVC_SUCCESS) { + EM_DEBUG_EXCEPTION("certsvc_instance_new failed : [%d]", err); + err = EMAIL_ERROR_LOAD_CERTIFICATE_FAILURE; + goto FINISH_OFF; + } + + /* Make the pfxID string */ + err = certsvc_string_new(cert_instance, certificate, EM_SAFE_STRLEN(certificate), &csstring); + if (err != CERTSVC_SUCCESS) { + EM_DEBUG_EXCEPTION("certsvc_string_new failed : [%d]", err); + err = EMAIL_ERROR_LOAD_CERTIFICATE_FAILURE; + goto FINISH_OFF; + } + + /* Load the certificate list of pkcs12 type */ + err = certsvc_pkcs12_load_certificate_list(cert_instance, csstring, &certificate_list); + if (err != CERTSVC_SUCCESS) { + EM_DEBUG_EXCEPTION("certsvc_pkcs12_load_certificate_list failed : [%d]", err); + err = EMAIL_ERROR_LOAD_CERTIFICATE_FAILURE; + goto FINISH_OFF; + } + + /* Get a certificate */ + err = certsvc_certificate_list_get_one(certificate_list, 0, &csc_cert); + if (err != CERTSVC_SUCCESS) { + EM_DEBUG_EXCEPTION("certsvc_certificate_list_get_one failed : [%d]", err); + err = EMAIL_ERROR_LOAD_CERTIFICATE_FAILURE; + goto FINISH_OFF; + } + + /* Convert from char to X509 */ + err = certsvc_certificate_dup_x509(csc_cert, &t_cert); + if (t_cert == NULL || err != CERTSVC_SUCCESS) { + EM_DEBUG_EXCEPTION("certsvc_certificate_dup_x509 failed"); + err = EMAIL_ERROR_LOAD_CERTIFICATE_FAILURE; + goto FINISH_OFF; + } + + /* Get the private key */ + err = certsvc_pkcs12_private_key_dup(cert_instance, csstring, &private_key, &p_key_size); + if (err != CERTSVC_SUCCESS) { + EM_DEBUG_EXCEPTION("certsvc_pkcs12_private_key_dup failed : [%d]", err); + err = EMAIL_ERROR_LOAD_CERTIFICATE_FAILURE; + goto FINISH_OFF; + } + + EM_DEBUG_LOG_DEV("key_size : [%d], private_key : [%s]", p_key_size, private_key); + ret = true; + +FINISH_OFF: + + if (true) { + if (key_string) + *key_string = private_key; + + if (key_size) + *key_size = p_key_size; + } else { + X509_free(t_cert); + EVP_PKEY_free(t_pri_key); + EM_SAFE_FREE(private_key); + } + + if (err_code) + *err_code = err; + + return ret; +} + INTERNAL_FUNC int emcore_add_public_certificate(char *public_cert_path, char *save_name, int *err_code) { EM_DEBUG_FUNC_BEGIN_SEC("Path [%s], filename [%s]", public_cert_path, save_name); - int err = EMAIL_ERROR_NONE; + int err = EMAIL_ERROR_NONE; int ret = false; int validity = 0; int cert_type = 0; @@ -362,9 +457,9 @@ INTERNAL_FUNC int emcore_add_public_certificate(char *public_cert_path, char *sa if (public_cert_path == NULL || save_name == NULL) { EM_DEBUG_EXCEPTION("Invalid parameter"); err = EMAIL_ERROR_INVALID_PARAM; - goto FINISH_OFF; + goto FINISH_OFF; } - + /* Initilize the structure of certificate */ context = cert_svc_cert_context_init(); @@ -387,15 +482,15 @@ INTERNAL_FUNC int emcore_add_public_certificate(char *public_cert_path, char *sa if (cert_type == CERT_TYPE_P7S) { extension = "der"; } - + SNPRINTF(temp_file, sizeof(temp_file), "%s%s%s.%s", MAILTEMP, DIR_SEPERATOR, save_name, extension); - EM_DEBUG_LOG("temp cert path : [%s]", temp_file); + EM_DEBUG_LOG_SEC("temp cert path : [%s]", temp_file); if (!emstorage_copy_file(public_cert_path, temp_file, false, &err)) { EM_DEBUG_EXCEPTION("emstorage_copy_file failed [%d]", err); goto FINISH_OFF; } - + /* Load the public certificate */ err = cert_svc_load_file_to_context(context, temp_file); if (err != CERT_SVC_ERR_NO_ERROR) { @@ -409,7 +504,7 @@ INTERNAL_FUNC int emcore_add_public_certificate(char *public_cert_path, char *sa EM_DEBUG_EXCEPTION("cert_svc_verify_certificate failed"); // err = EMAIL_ERROR_INVALID_CERTIFICATE; // goto FINISH_OFF; - } + } if (validity <= 0) { EM_DEBUG_LOG("Invalid certificate"); @@ -443,16 +538,16 @@ INTERNAL_FUNC int emcore_add_public_certificate(char *public_cert_path, char *sa cert->issue_year = context->certDesc->info.validPeriod.firstYear; cert->issue_year = context->certDesc->info.validPeriod.firstYear; cert->issue_month = context->certDesc->info.validPeriod.firstMonth; - cert->issue_day = context->certDesc->info.validPeriod.firstDay; - cert->expiration_year= context->certDesc->info.validPeriod.secondYear; - cert->expiration_month = context->certDesc->info.validPeriod.secondMonth; - cert->expiration_day = context->certDesc->info.validPeriod.secondDay; + cert->issue_day = context->certDesc->info.validPeriod.firstDay; + cert->expiration_year= context->certDesc->info.validPeriod.secondYear; + cert->expiration_month = context->certDesc->info.validPeriod.secondMonth; + cert->expiration_day = context->certDesc->info.validPeriod.secondDay; cert->issue_organization_name = EM_SAFE_STRDUP(context->certDesc->info.issuer.organizationName); cert->email_address = EM_SAFE_STRDUP(temp_save_name); - cert->subject_str = EM_SAFE_STRDUP(context->certDesc->info.issuerStr); - cert->filepath = EM_SAFE_STRDUP(filepath); + cert->subject_str = EM_SAFE_STRDUP(context->certDesc->info.issuerStr); + cert->filepath = EM_SAFE_STRDUP(filepath); - if (emstorage_add_certificate(cert, true, &err)) { + if (!emstorage_add_certificate(cert, true, &err)) { EM_DEBUG_EXCEPTION("emstorage_add_certificate failed"); goto FINISH_OFF; } @@ -467,7 +562,7 @@ INTERNAL_FUNC int emcore_add_public_certificate(char *public_cert_path, char *sa FINISH_OFF: emstorage_delete_file(temp_file, NULL); - + emstorage_free_certificate(&cert, 1, NULL); cert_svc_cert_context_final(context); @@ -538,9 +633,6 @@ INTERNAL_FUNC int emcore_verify_signature(char *p7s_file_path, char *mime_entity PKCS7 *pkcs7_p7s = NULL; - /* Initialize */ - OpenSSL_add_all_algorithms(); - /* Open p7s file */ bio_p7s = BIO_new_file(p7s_file_path, INMODE); if (!bio_p7s) { @@ -567,7 +659,6 @@ INTERNAL_FUNC int emcore_verify_signature(char *p7s_file_path, char *mime_entity if (!PKCS7_verify(pkcs7_p7s, NULL, NULL, bio_indata, NULL, flags)) { EM_DEBUG_EXCEPTION("PKCS7_verify failed"); - err = EMAIL_ERROR_SYSTEM_FAILURE; goto FINISH_OFF; } @@ -577,8 +668,6 @@ INTERNAL_FUNC int emcore_verify_signature(char *p7s_file_path, char *mime_entity FINISH_OFF: - EVP_cleanup(); - if (pkcs7_p7s) PKCS7_free(pkcs7_p7s); @@ -606,7 +695,7 @@ INTERNAL_FUNC int emcore_verify_certificate(char *certificate, int *validity, in int p_validity = 0; CERT_CONTEXT *context = NULL; - + context = cert_svc_cert_context_init(); err = cert_svc_load_file_to_context(context, certificate); @@ -625,7 +714,7 @@ INTERNAL_FUNC int emcore_verify_certificate(char *certificate, int *validity, in FINISH_OFF: - if (validity != NULL) + if (validity != NULL) *validity = p_validity; if (err_code != NULL) { @@ -641,17 +730,17 @@ FINISH_OFF: INTERNAL_FUNC int emcore_free_certificate(email_certificate_t **certificate, int count, int *err_code) { EM_DEBUG_FUNC_BEGIN("certificate [%p], count [%d]", certificate, count); - + if (count <= 0 || !certificate || !*certificate) { EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM"); - if (err_code) + if (err_code) *err_code = EMAIL_ERROR_INVALID_PARAM; return false; } email_certificate_t *p_certificate = *certificate; int i; - + for (i=0;i<count;i++) { EM_SAFE_FREE(p_certificate[i].issue_organization_name); EM_SAFE_FREE(p_certificate[i].email_address); diff --git a/email-core/email-core-event.c b/email-core/email-core-event.c index 74fc387..9624ed0 100755 --- a/email-core/email-core-event.c +++ b/email-core/email-core-event.c @@ -26,6 +26,7 @@ #include <vconf.h> #include <signal.h> #include <contacts.h> +#include <contacts_internal.h> #include "c-client.h" #include "email-convert.h" #include "email-storage.h" @@ -43,7 +44,6 @@ #include "email-core-mailbox-sync.h" #include "email-core-smtp.h" #include "email-core-utils.h" -#include "email-core-sound.h" #include "email-core-signal.h" #include "email-debug-log.h" @@ -56,7 +56,7 @@ INTERNAL_FUNC pthread_cond_t _event_available_signal = PTHREAD_COND_INITIALIZER INTERNAL_FUNC pthread_mutex_t *_event_queue_lock = NULL; INTERNAL_FUNC pthread_mutex_t *_event_handle_map_lock = NULL; -INTERNAL_FUNC GQueue *g_event_que; +INTERNAL_FUNC GQueue *g_event_que = NULL; INTERNAL_FUNC int g_event_loop = 1; INTERNAL_FUNC int handle_map[EVENT_QUEUE_MAX] = {0,}; INTERNAL_FUNC int recv_thread_run = 0; @@ -73,7 +73,7 @@ INTERNAL_FUNC pthread_cond_t _send_event_available_signal = PTHREAD_COND_INITIA INTERNAL_FUNC pthread_mutex_t *_send_event_queue_lock = NULL; INTERNAL_FUNC pthread_mutex_t *_send_event_handle_map_lock = NULL; -INTERNAL_FUNC GQueue *g_send_event_que; +INTERNAL_FUNC GQueue *g_send_event_que = NULL; INTERNAL_FUNC int g_send_event_loop = 1; INTERNAL_FUNC int send_handle_map[EVENT_QUEUE_MAX] = {0,}; INTERNAL_FUNC int send_thread_run = 0; @@ -93,7 +93,7 @@ INTERNAL_FUNC pthread_mutex_t _state_variables_lock; INTERNAL_FUNC email_event_partial_body_thd g_partial_body_thd_event_que[TOTAL_PARTIAL_BODY_EVENTS]; INTERNAL_FUNC int g_partial_body_thd_next_event_idx = 0; /* Index of Next Event to be processed in the queue*/ -INTERNAL_FUNC int g_partial_body_thd_loop = 1; /* Variable to make a continuos while loop */ +//INTERNAL_FUNC int g_partial_body_thd_loop = 1; /* Variable to make a continuos while loop */ INTERNAL_FUNC int g_partial_body_thd_queue_empty = true; /* Variable to determine if event queue is empty.True means empty*/ INTERNAL_FUNC int g_partial_body_thd_queue_full = false; /* Variable to determine if event queue is full. True means full*/ INTERNAL_FUNC int g_pb_thd_local_activity_continue = true; /* Variable to control local activity sync */ @@ -106,6 +106,8 @@ INTERNAL_FUNC int g_partial_body_bulk_dwd_queue_empty = true; static int emcore_copy_partial_body_thd_event(email_event_partial_body_thd *src, email_event_partial_body_thd *dest, int *error_code); static int emcore_clear_bulk_pbd_que(int *err_code); +INTERNAL_FUNC email_event_t *sync_failed_event_data = NULL; + #endif /*----------------------------------------------------------------------------- @@ -216,11 +218,6 @@ static void fail_status_notify(email_event_t *event_data, int error) emcore_execute_event_callback(EMAIL_ACTION_SET_MAIL_SLOT_SIZE, 0, 0, EMAIL_SET_SLOT_SIZE_FAIL, account_id, 0, -1, EMAIL_ERROR_NONE); break; - case EMAIL_EVENT_SEARCH_ON_SERVER: - emcore_execute_event_callback(EMAIL_ACTION_SEARCH_ON_SERVER, 0, 0, EMAIL_SEARCH_ON_SERVER_FAIL, account_id, 0, -1, EMAIL_ERROR_NONE); - emcore_show_user_message(account_id, EMAIL_ACTION_SEARCH_ON_SERVER, error); - break; - case EMAIL_EVENT_RENAME_MAILBOX_ON_IMAP_SERVER: emcore_execute_event_callback(EMAIL_ACTION_MOVE_MAILBOX, 0, 0, EMAIL_MOVE_MAILBOX_ON_IMAP_SERVER_FAIL, account_id, 0, -1, EMAIL_ERROR_NONE); emcore_show_user_message(account_id, EMAIL_ACTION_SEARCH_ON_SERVER, error); @@ -427,22 +424,24 @@ INTERNAL_FUNC int emcore_insert_event(email_event_t *event_data, int *handle, in case EMAIL_EVENT_SET_MAIL_SLOT_SIZE: case EMAIL_EVENT_UPDATE_MAIL: case EMAIL_EVENT_EXPUNGE_MAILS_DELETED_FLAGGED: - case EMAIL_EVENT_SEARCH_ON_SERVER: case EMAIL_EVENT_RENAME_MAILBOX_ON_IMAP_SERVER: break; default: #ifdef __FEATURE_PARTIAL_BODY_DOWNLOAD__ - { - int is_local_activity_event_inserted = false; - - if (false == emcore_partial_body_thd_local_activity_sync(&is_local_activity_event_inserted, &error)) - EM_DEBUG_EXCEPTION("emcore_partial_body_thd_local_activity_sync failed [%d]", error); - else { - if (true == is_local_activity_event_inserted) - emcore_pb_thd_set_local_activity_continue(false); + { + int is_local_activity_event_inserted = false; + emcore_partial_body_thd_local_activity_sync ( + &is_local_activity_event_inserted, + &error); + if (error != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emcore_partial_body_thd_local_activity_sync failed [%d]", error); + } + else { + if (true == is_local_activity_event_inserted) + emcore_pb_thd_set_local_activity_continue (false); + } } - } #endif break; } @@ -519,6 +518,74 @@ INTERNAL_FUNC int emcore_event_loop_continue(void) return g_event_loop; } +INTERNAL_FUNC int emcore_is_event_queue_empty(void) +{ + int q_length = 0; + int ret = false; + + ENTER_RECURSIVE_CRITICAL_SECTION(_event_queue_lock); + if (g_event_que) + q_length = g_queue_get_length(g_event_que); + EM_DEBUG_LOG("Q Length : [%d]", q_length); + if (q_length > 0) { + ret = false; + } + else { + EM_DEBUG_LOG("event que is empty"); + ret = true; + } + LEAVE_RECURSIVE_CRITICAL_SECTION(_event_queue_lock); + + return ret; +} + + +INTERNAL_FUNC int emcore_is_send_event_queue_empty(void) +{ + int q_length = 0; + int ret = false; + + ENTER_RECURSIVE_CRITICAL_SECTION(_send_event_queue_lock); + if (g_send_event_que) + q_length = g_queue_get_length(g_send_event_que); + EM_DEBUG_LOG("Q Length : [%d]", q_length); + if (q_length > 0) { + ret = false; + } + else { + EM_DEBUG_LOG("send event que is empty"); + ret = true; + } + LEAVE_RECURSIVE_CRITICAL_SECTION(_send_event_queue_lock); + + return ret; +} + + +INTERNAL_FUNC void emcore_get_sync_fail_event_data(email_event_t **event_data) +{ + if (!sync_failed_event_data) { + EM_DEBUG_EXCEPTION("sync_failed_event_data is NULL"); + return; + } + + email_event_t *new_event = NULL; + + new_event = em_malloc(sizeof(email_event_t)); + new_event->account_id = sync_failed_event_data->account_id; + new_event->type = sync_failed_event_data->type; + if (sync_failed_event_data->event_param_data_3) + new_event->event_param_data_3 = EM_SAFE_STRDUP(sync_failed_event_data->event_param_data_3); + new_event->event_param_data_4 = sync_failed_event_data->event_param_data_4; + new_event->event_param_data_5 = sync_failed_event_data->event_param_data_5; + + *event_data = new_event; + + emcore_free_event(sync_failed_event_data); + EM_SAFE_FREE(sync_failed_event_data); + sync_failed_event_data = NULL; +} + INTERNAL_FUNC int emcore_insert_event_for_sending_mails(email_event_t *event_data, int *handle, int *err_code) { EM_DEBUG_FUNC_BEGIN("event_data[%p], handle[%p], err_code[%p]", event_data, handle, err_code); @@ -588,8 +655,8 @@ INTERNAL_FUNC int emcore_retrieve_send_event(email_event_t **event_data, int *er email_event_t *poped = NULL; email_event_t *head_event = NULL; - if (g_send_event_que); - q_length = g_queue_get_length(g_send_event_que); + /* g_queue_get_length is aborted when param is null */ + q_length = g_send_event_que? g_queue_get_length (g_send_event_que): 0; /*prevent 35141*/ EM_DEBUG_LOG("SEND Q Length : [%d]", q_length); @@ -713,10 +780,34 @@ INTERNAL_FUNC int emcore_stop_event_loop(int *err_code) return true; } -/* check thread status +/* check event thread status (worker_event_queue) * 0 : stop job 1 : continue job +event list handled by event thread : +case EMAIL_EVENT_SYNC_IMAP_MAILBOX: +case EMAIL_EVENT_SYNC_HEADER: +case EMAIL_EVENT_SYNC_HEADER_OMA: +case EMAIL_EVENT_DOWNLOAD_BODY: +case EMAIL_EVENT_DOWNLOAD_ATTACHMENT: +case EMAIL_EVENT_SYNC_FLAGS_FIELD_TO_SERVER: +case EMAIL_EVENT_DELETE_MAIL: +case EMAIL_EVENT_DELETE_MAIL_ALL: +case EMAIL_EVENT_SYNC_MAIL_FLAG_TO_SERVER: +case EMAIL_EVENT_CREATE_MAILBOX: +case EMAIL_EVENT_DELETE_MAILBOX: +case EMAIL_EVENT_SAVE_MAIL: +case EMAIL_EVENT_MOVE_MAIL: +case EMAIL_EVENT_VALIDATE_ACCOUNT: +case EMAIL_EVENT_VALIDATE_AND_CREATE_ACCOUNT: { +case EMAIL_EVENT_VALIDATE_ACCOUNT_EX: { +case EMAIL_EVENT_VALIDATE_AND_UPDATE_ACCOUNT: { +case EMAIL_EVENT_UPDATE_MAIL: +case EMAIL_EVENT_SET_MAIL_SLOT_SIZE: +case EMAIL_EVENT_EXPUNGE_MAILS_DELETED_FLAGGED: +case EMAIL_EVENT_LOCAL_ACTIVITY: +case EMAIL_EVENT_RENAME_MAILBOX_ON_IMAP_SERVER: +case EMAIL_EVENT_QUERY_SMTP_MAIL_SIZE_LIMIT: */ -INTERNAL_FUNC int emcore_check_thread_status() +INTERNAL_FUNC int emcore_check_event_thread_status(int *event_type, int handle) { EM_DEBUG_FUNC_BEGIN(); @@ -732,10 +823,16 @@ INTERNAL_FUNC int emcore_check_thread_status() if (q_length) { active_event = (email_event_t *)g_queue_peek_head(g_event_que); if (active_event) { - if (active_event->status == EMAIL_EVENT_STATUS_STARTED) + if (active_event->handle == handle) { + if (event_type) + *event_type = active_event->type; + if (active_event->status == EMAIL_EVENT_STATUS_STARTED) + ret = true; + else + ret = false; + } else { ret = true; - else - ret = false; + } } } else { EM_DEBUG_LOG("Rcv Queue is empty [%d]", q_length); @@ -820,7 +917,6 @@ INTERNAL_FUNC int emcore_cancel_thread(int handle, void *arg, int *err_code) case EMAIL_EVENT_CREATE_MAILBOX: case EMAIL_EVENT_DELETE_MAILBOX: case EMAIL_EVENT_SET_MAIL_SLOT_SIZE: - case EMAIL_EVENT_SEARCH_ON_SERVER: case EMAIL_EVENT_RENAME_MAILBOX_ON_IMAP_SERVER: EM_DEBUG_LOG("EMAIL_EVENT_DELETE_MAIL, EMAIL_EVENT_SYNC_IMAP_MAILBOX"); break; @@ -837,7 +933,8 @@ INTERNAL_FUNC int emcore_cancel_thread(int handle, void *arg, int *err_code) } else { EM_DEBUG_LOG("Failed to g_queue_pop_nth [%d] element", i); } - } else { + } + else { switch (found_elm->type) { case EMAIL_EVENT_SYNC_HEADER: @@ -884,8 +981,8 @@ INTERNAL_FUNC int emcore_cancel_all_thread(int *err_code) ENTER_RECURSIVE_CRITICAL_SECTION(_event_queue_lock); - if (g_event_que); - q_length = g_queue_get_length(g_event_que); + /* g_queue_get_length is aborted when param is null */ + q_length = g_event_que? g_queue_get_length (g_event_que): 0; /*prevent 35142 */ for (i = 0; i < q_length; i++) { pop_elm = (email_event_t *)g_queue_peek_nth(g_event_que, i); @@ -931,7 +1028,6 @@ INTERNAL_FUNC int emcore_cancel_all_thread(int *err_code) case EMAIL_EVENT_CREATE_MAILBOX: case EMAIL_EVENT_DELETE_MAILBOX: case EMAIL_EVENT_SET_MAIL_SLOT_SIZE: - case EMAIL_EVENT_SEARCH_ON_SERVER: case EMAIL_EVENT_RENAME_MAILBOX_ON_IMAP_SERVER: EM_DEBUG_LOG("EMAIL_EVENT_DELETE_MAIL, EMAIL_EVENT_SYNC_IMAP_MAILBOX"); break; @@ -950,7 +1046,8 @@ INTERNAL_FUNC int emcore_cancel_all_thread(int *err_code) if (g_event_que) q_length = g_queue_get_length(g_event_que); - } else { + } + else { pop_elm->status = EMAIL_EVENT_STATUS_CANCELED; } } @@ -1057,7 +1154,6 @@ INTERNAL_FUNC int emcore_cancel_all_threads_of_an_account(int account_id) case EMAIL_EVENT_CREATE_MAILBOX: case EMAIL_EVENT_DELETE_MAILBOX: case EMAIL_EVENT_SET_MAIL_SLOT_SIZE: - case EMAIL_EVENT_SEARCH_ON_SERVER: case EMAIL_EVENT_RENAME_MAILBOX_ON_IMAP_SERVER: EM_DEBUG_LOG("EMAIL_EVENT_DELETE_MAIL, EMAIL_EVENT_SYNC_IMAP_MAILBOX"); break; @@ -1078,7 +1174,8 @@ INTERNAL_FUNC int emcore_cancel_all_threads_of_an_account(int account_id) if (g_event_que) q_length = g_queue_get_length(g_event_que); - } else { + } + else { found_elm->status = EMAIL_EVENT_STATUS_CANCELED; } } @@ -1360,10 +1457,6 @@ INTERNAL_FUNC int emcore_free_event(email_event_t *event_data) break; #endif /* __FEATURE_LOCAL_ACTIVITY__*/ - case EMAIL_EVENT_SEARCH_ON_SERVER: - EM_SAFE_FREE(event_data->event_param_data_1); - break; - case EMAIL_EVENT_RENAME_MAILBOX_ON_IMAP_SERVER: EM_SAFE_FREE(event_data->event_param_data_1); EM_SAFE_FREE(event_data->event_param_data_2); @@ -1679,7 +1772,7 @@ static int emcore_copy_partial_body_thd_event(email_event_partial_body_thd *src, 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; @@ -1723,7 +1816,9 @@ INTERNAL_FUNC int emcore_free_partial_body_thd_event(email_event_partial_body_th return true; } -INTERNAL_FUNC int emcore_insert_partial_body_thread_event(email_event_partial_body_thd *partial_body_thd_event, int *error_code) +INTERNAL_FUNC int emcore_insert_partial_body_thread_event ( + email_event_partial_body_thd *partial_body_thd_event, + int *error_code) { EM_DEBUG_FUNC_BEGIN(); @@ -1745,49 +1840,40 @@ INTERNAL_FUNC int emcore_insert_partial_body_thread_event(email_event_partial_bo 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; + index = g_partial_body_thd_next_event_idx; + for (count = 0; count < TOTAL_PARTIAL_BODY_EVENTS; count++) { + /*Found empty Cell*/ + if (g_partial_body_thd_event_que[index].event_type == EMAIL_EVENT_NONE) { + empty_cell_index = index; break; } + index++; + index = index % TOTAL_PARTIAL_BODY_EVENTS; } - if (-1 != empty_cell_index) { - if (false == emcore_copy_partial_body_thd_event(partial_body_thd_event, g_partial_body_thd_event_que+empty_cell_index , &error)) { + if (empty_cell_index != -1) { + emcore_copy_partial_body_thd_event (partial_body_thd_event, + g_partial_body_thd_event_que + empty_cell_index, + &error); + if (error != EMAIL_ERROR_NONE) { EM_DEBUG_LOG("emcore_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 "); + EM_DEBUG_LOG("partial body thread event_data queue is full "); error = EMAIL_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); @@ -2043,8 +2129,8 @@ INTERNAL_FUNC int emcore_mail_partial_body_download (email_event_partial_body_th goto FINISH_OFF; /* Stop Local Activity Sync */ } } + stream = mail_close (stream); } - stream = mail_close (stream); } /* After completing one cycle of local activity sync , diff --git a/email-core/email-core-gmime.c b/email-core/email-core-gmime.c index 5e1890b..8fe4dfe 100755 --- a/email-core/email-core-gmime.c +++ b/email-core/email-core-gmime.c @@ -3,7 +3,8 @@ * * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * -* Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> +* Contact: Minsoo Kim <minnsoo.kim@samsung.com>, 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. @@ -29,6 +30,8 @@ #include <ctype.h> #include <sys/stat.h> #include <sys/time.h> +#include <glib.h> +#include <glib/gstdio.h> #include "email-internal-types.h" #include "email-utilities.h" @@ -44,132 +47,880 @@ #include "email-core-mailbox-sync.h" #include "email-debug-log.h" +static int multipart_status = 0; -/* - 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 -*/ +static void emcore_gmime_pop3_parse_foreach_cb(GMimeObject *parent, GMimeObject *part, gpointer user_data); +static void emcore_gmime_eml_parse_foreach_cb(GMimeObject *parent, GMimeObject *part, gpointer user_data); +static int emcore_gmime_parse_mime_header(GMimeMessage *message, struct _rfc822header *rfc822_header); + + +INTERNAL_FUNC void emcore_gmime_init(void) +{ + EM_DEBUG_FUNC_BEGIN(); + + g_thread_init(NULL); + g_mime_init(0); -static void emcore_parse_mime_foreach_callback(GMimeObject *parent, GMimeObject *part, gpointer user_data); + EM_DEBUG_FUNC_END(); +} + +INTERNAL_FUNC void emcore_gmime_shutdown(void) +{ + EM_DEBUG_FUNC_BEGIN(); + + g_mime_shutdown(); + + EM_DEBUG_FUNC_END(); +} -int emcore_gmime_parse_mime(char *eml_path, struct _m_content_info *cnt_info, int *err_code) +INTERNAL_FUNC int emcore_gmime_imap_parse_mime_partial(char *rfc822header_str, char *bodytext_str, struct _m_content_info *cnt_info) { - EM_DEBUG_FUNC_BEGIN("stream[%s], cnt_info[%p], err_code[%p]", eml_path, cnt_info, err_code); + EM_DEBUG_FUNC_BEGIN(); + + EM_DEBUG_LOG_DEV("RFC822H:%s", rfc822header_str); + EM_DEBUG_LOG_DEV("BODYTEXT:%s", bodytext_str); + + GMimeStream *stream = NULL; + GMimeMessage *message = NULL; + GMimeParser *parser = NULL; + char *fulltext = NULL; + + fulltext = g_strconcat(rfc822header_str, "\r\n\r\n", bodytext_str, NULL); + + stream = g_mime_stream_mem_new_with_buffer(fulltext, EM_SAFE_STRLEN(fulltext)); + + parser = g_mime_parser_new_with_stream(stream); + if (stream) g_object_unref(stream); + + message = g_mime_parser_construct_message(parser); + if (parser) g_object_unref(parser); + if (!message) { /* prevent null check for message */ + EM_DEBUG_EXCEPTION("g_mime_parser_construct_message error"); + EM_SAFE_FREE(fulltext); + return false; + } + + EM_DEBUG_LOG_DEV("Sender:%s", g_mime_message_get_sender(message)); + EM_DEBUG_LOG_DEV("Reply To:%s", g_mime_message_get_reply_to(message)); + EM_DEBUG_LOG_DEV("Subject:%s", g_mime_message_get_subject(message)); + EM_DEBUG_LOG_DEV("Date:%s", g_mime_message_get_date_as_string(message)); + EM_DEBUG_LOG_DEV("Message ID:%s", g_mime_message_get_message_id(message)); + + g_mime_message_foreach(message, emcore_gmime_imap_parse_foreach_cb, (gpointer)cnt_info); + + EM_SAFE_FREE(fulltext); + + if (message) g_object_unref (message); + + EM_DEBUG_FUNC_END(); + return true; +} + +INTERNAL_FUNC int emcore_gmime_pop3_parse_mime(char *eml_path, struct _m_content_info *cnt_info, int *err_code) +{ + EM_DEBUG_FUNC_BEGIN("cnt_info[%p], err_code[%p]", cnt_info, err_code); + EM_DEBUG_LOG_SEC("eml_path[%s]", eml_path); GMimeStream *stream = NULL; GMimeMessage *message = NULL; GMimeParser *parser = NULL; int fd = 0; + int err = EMAIL_ERROR_NONE; - if ((fd = open(eml_path, O_RDONLY, 0)) == -1) { + err = em_open(eml_path, O_RDONLY, 0, &fd); + if (err != EMAIL_ERROR_NONE) { EM_DEBUG_EXCEPTION("holder open failed : holder is a filename that will be saved."); + if (err_code) + *err_code = err; + return false; /*prevent 34936*/ } - g_mime_init(0); + stream = g_mime_stream_fs_new(fd); + + parser = g_mime_parser_new_with_stream(stream); + if (stream) g_object_unref(stream); + + message = g_mime_parser_construct_message(parser); + if (parser) g_object_unref(parser); + if (!message) { /* prevent null check for message */ + EM_DEBUG_EXCEPTION("g_mime_parser_construct_message error"); + return false; + } + + EM_DEBUG_LOG_DEV("Sender:%s", g_mime_message_get_sender(message)); + EM_DEBUG_LOG_DEV("Reply To:%s", g_mime_message_get_reply_to(message)); + EM_DEBUG_LOG_DEV("Subject:%s", g_mime_message_get_subject(message)); + EM_DEBUG_LOG_DEV("Date:%s", g_mime_message_get_date_as_string(message)); + EM_DEBUG_LOG_DEV("Message ID:%s", g_mime_message_get_message_id(message)); + + if (g_strrstr(g_mime_message_get_sender(message), "mmsc.plusnet.pl") != NULL || + g_strrstr(g_mime_message_get_sender(message), "mms.t-mobile.pl") != NULL) { + cnt_info->attachment_only = 1; + } + + g_mime_message_foreach(message, emcore_gmime_pop3_parse_foreach_cb, (gpointer)cnt_info); + + EM_SAFE_CLOSE (fd); + + if (message) g_object_unref (message); + + EM_DEBUG_FUNC_END(); + return true; +} + + +INTERNAL_FUNC int emcore_gmime_eml_parse_mime(char *eml_path, struct _rfc822header *rfc822_header, struct _m_content_info *cnt_info, int *err_code) +{ + EM_DEBUG_FUNC_BEGIN("cnt_info[%p], err_code[%p]", cnt_info, err_code); + EM_DEBUG_LOG_SEC("eml_path[%s]", eml_path); + + GMimeStream *stream = NULL; + GMimeMessage *message = NULL; + GMimeParser *parser = NULL; + int fd = 0; + int err = EMAIL_ERROR_NONE; + + err = em_open(eml_path, O_RDONLY, 0, &fd); + if (err != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("holder open failed : holder is a filename that will be saved."); + if (err_code) + *err_code = err; + return false; /*prevent 34936*/ + } + + multipart_status = 0; stream = g_mime_stream_fs_new(fd); parser = g_mime_parser_new_with_stream(stream); - g_object_unref(stream); + if (stream) g_object_unref(stream); message = g_mime_parser_construct_message(parser); - g_object_unref(parser); + if (parser) g_object_unref(parser); + if (!message) { /* prevent null check for message */ + EM_DEBUG_EXCEPTION("g_mime_parser_construct_message error"); + return false; + } - EM_DEBUG_LOG("Sender:%s", g_mime_message_get_sender(message)); - EM_DEBUG_LOG("Reply To:%s", g_mime_message_get_reply_to(message)); - EM_DEBUG_LOG("Subject:%s", g_mime_message_get_subject(message)); - EM_DEBUG_LOG("Date:%s", g_mime_message_get_date_as_string(message)); - EM_DEBUG_LOG("Message ID:%s", g_mime_message_get_message_id(message)); + EM_DEBUG_LOG_DEV("Sender:%s", g_mime_message_get_sender(message)); + EM_DEBUG_LOG_DEV("Reply To:%s", g_mime_message_get_reply_to(message)); + EM_DEBUG_LOG_DEV("Subject:%s", g_mime_message_get_subject(message)); + EM_DEBUG_LOG_DEV("Date:%s", g_mime_message_get_date_as_string(message)); + EM_DEBUG_LOG_DEV("Message ID:%s", g_mime_message_get_message_id(message)); - GMimeObject *po = (GMimeObject *)message; - EM_DEBUG_LOG("Header String:%s\n\n", g_mime_header_list_to_string(po->headers)); + emcore_gmime_parse_mime_header(message, rfc822_header); - g_mime_message_foreach(message, emcore_parse_mime_foreach_callback, (gpointer)cnt_info); + g_mime_message_foreach(message, emcore_gmime_eml_parse_foreach_cb, (gpointer)cnt_info); - if (fd) close(fd); + EM_SAFE_CLOSE (fd); - g_object_unref (message); + if (message) g_object_unref (message); EM_DEBUG_FUNC_END(); return true; } -static void emcore_parse_mime_foreach_callback(GMimeObject *parent, GMimeObject *part, gpointer user_data) +static void emcore_gmime_pop3_parse_foreach_cb(GMimeObject *parent, GMimeObject *part, gpointer user_data) { EM_DEBUG_FUNC_BEGIN("parent[%p], part[%p], user_data[%p]", parent, part, user_data); int error = EMAIL_ERROR_NONE; + char *msg_tmp_content_path = NULL; + char *content_path = NULL; struct _m_content_info *cnt_info = (struct _m_content_info *)user_data; - /* 'part' points to the current part node that - * g_mime_message_foreach() is iterating over */ - - /* find out what class 'part' is... */ if (GMIME_IS_MESSAGE_PART(part)) { - /* message/rfc822 or message/news */ - GMimeMessage *message; - /* g_mime_message_foreach() won't descend into - * child message parts, so if we want to count any - * subparts of this child message, we'll have to call - * g_mime_message_foreach() again here. */ EM_DEBUG_LOG("Message Part"); + GMimeMessage *message = NULL; + GMimeContentType *msg_ctype = NULL; + GMimeContentDisposition *msg_disposition = NULL; + GMimeStream *out_stream; + char *msg_ctype_type = NULL; + char *msg_ctype_subtype = NULL; + char *msg_ctype_name = NULL; + char *msg_disposition_str = NULL; + char *msg_disposition_filename = NULL; + char *msg_content_id = NULL; + int real_size = 0; + int msg_fd = 0; + + if (cnt_info->grab_type != (GRAB_TYPE_TEXT|GRAB_TYPE_ATTACHMENT) && + cnt_info->grab_type != GRAB_TYPE_ATTACHMENT) { + goto FINISH_OFF; + } + + message = g_mime_message_part_get_message((GMimeMessagePart *)part); + if (!message) { + EM_DEBUG_EXCEPTION("Message is NULL"); + goto FINISH_OFF; + } + + /*Content Type*/ + msg_ctype = g_mime_object_get_content_type(part); + msg_ctype_type = (char *)g_mime_content_type_get_media_type(msg_ctype); + msg_ctype_subtype = (char *)g_mime_content_type_get_media_subtype(msg_ctype); + msg_ctype_name = (char *)g_mime_content_type_get_parameter(msg_ctype, "name"); + EM_DEBUG_LOG("Content-Type[%s/%s]", msg_ctype_type, msg_ctype_subtype); + EM_DEBUG_LOG_SEC("RFC822/Message Content-Type-Name[%s]", msg_ctype_name); + /*Content Type - END*/ + + /*Content Disposition*/ + msg_disposition = g_mime_object_get_content_disposition(part); + if (msg_disposition) { + msg_disposition_str = (char *)g_mime_content_disposition_get_disposition(msg_disposition); + msg_disposition_filename = (char *)g_mime_content_disposition_get_parameter(msg_disposition, "filename"); + } + EM_DEBUG_LOG("RFC822/Message Disposition[%s]", msg_disposition_str); + EM_DEBUG_LOG_SEC("RFC822/Message Disposition-Filename[%s]", msg_disposition_filename); + /*Content Disposition - END*/ + + /*Content ID*/ + msg_content_id = (char *)g_mime_object_get_content_id(part); + EM_DEBUG_LOG("RFC822/Message Content-ID:%s", msg_content_id); + + /*save message content to tmp file*/ + if (!emcore_get_temp_file_name(&msg_tmp_content_path, &error)) { + EM_DEBUG_EXCEPTION("emcore_get_temp_file_name failed [%d]", error); + goto FINISH_OFF; + } + EM_DEBUG_LOG_SEC("Temporary Content Path[%s]", msg_tmp_content_path); + + msg_fd = open(msg_tmp_content_path, O_WRONLY|O_CREAT, 0644); + if (msg_fd < 0) { + EM_DEBUG_EXCEPTION("open failed"); + goto FINISH_OFF; + } + + out_stream = g_mime_stream_fs_new(msg_fd); + real_size = g_mime_object_write_to_stream(GMIME_OBJECT(message), out_stream); + if (out_stream) g_object_unref(out_stream); + + if (real_size <= 0) { + EM_DEBUG_EXCEPTION("g_mime_object_write_to_stream failed"); + goto FINISH_OFF; + } + + if (msg_disposition_str && g_ascii_strcasecmp(msg_disposition_str, GMIME_DISPOSITION_ATTACHMENT) == 0) { + EM_DEBUG_LOG("RFC822/Message is ATTACHMENT"); + + struct attachment_info *file = NULL; + struct attachment_info *temp_file = cnt_info->file; + char *utf8_text = NULL; + int err = EMAIL_ERROR_NONE; + + file = em_malloc(sizeof(struct attachment_info)); + if (file == NULL) { + EM_DEBUG_EXCEPTION("em_malloc failed..."); + goto FINISH_OFF; + } + + file->type = ATTACHMENT; + if (msg_disposition_filename) file->name = g_strdup(msg_disposition_filename); + else if (msg_ctype_name) file->name = g_strdup(msg_ctype_name); + else if (msg_content_id) file->name = g_strdup(msg_content_id); + else file->name = g_strdup("unknown"); + + if (msg_content_id) file->content_id = g_strdup(msg_content_id); + + if (!(utf8_text = g_mime_utils_header_decode_text(file->name))) { + EM_DEBUG_EXCEPTION("g_mime_utils_header_decode_text failed [%d]", err); + } + EM_DEBUG_LOG_SEC("utf8_text : [%s]", utf8_text); + + if (utf8_text) { + EM_SAFE_FREE(file->name); + file->name = EM_SAFE_STRDUP(utf8_text); + } + EM_SAFE_FREE(utf8_text); + + if(msg_ctype_type && msg_ctype_subtype) { + char mime_type_buffer[128] = {0,}; + snprintf(mime_type_buffer, sizeof(mime_type_buffer), "%s/%s", msg_ctype_type, msg_ctype_subtype); + file->attachment_mime_type = g_strdup(mime_type_buffer); + } + + file->save = g_strdup(msg_tmp_content_path); + file->size = real_size; + file->save_status = 1; + + while (temp_file && temp_file->next) + temp_file = temp_file->next; + + if (temp_file == NULL) + cnt_info->file = file; + else + temp_file->next = file; + } - message = g_mime_message_part_get_message((GMimeMessagePart *) part); - g_mime_message_foreach(message, emcore_parse_mime_foreach_callback, user_data); + //g_mime_message_foreach(message, emcore_gmime_pop3_parse_foreach_cb, user_data); } else if (GMIME_IS_MESSAGE_PARTIAL(part)) { - /* message/partial */ + EM_DEBUG_LOG("Partial Part"); + //TODO + } else if (GMIME_IS_MULTIPART(part)) { + EM_DEBUG_LOG("Multi Part"); + GMimeMultipart *multi_part = NULL; + multi_part = (GMimeMultipart *)part; + + int multi_count = g_mime_multipart_get_count(multi_part); + EM_DEBUG_LOG("Multi Part Count:%d", multi_count); + EM_DEBUG_LOG("Boundary:%s\n\n", g_mime_multipart_get_boundary(multi_part)); + + } else if (GMIME_IS_PART(part)) { + EM_DEBUG_LOG("Part"); + int content_size = 0; - /* this is an incomplete message part, probably a - * large message that the sender has broken into - * smaller parts and is sending us bit by bit. we - * could save some info about it so that we could - * piece this back together again once we get all the parts? */ + GMimePart *leaf_part = NULL; + leaf_part = (GMimePart *)part; + + EM_DEBUG_LOG("Content ID:%s", g_mime_part_get_content_id(leaf_part)); + EM_DEBUG_LOG_SEC("Description:%s", g_mime_part_get_content_description(leaf_part)); + EM_DEBUG_LOG_SEC("MD5:%s", g_mime_part_get_content_md5(leaf_part)); + + int content_disposition_type = 0; + char *content_location = (char *)g_mime_part_get_content_location(leaf_part); + EM_DEBUG_LOG_SEC("Location:%s", content_location); + + GMimeObject *mobject = (GMimeObject *)part; + + /*Content ID*/ + char *content_id = (char *)g_mime_object_get_content_id(mobject); + /*Content Disposition*/ + GMimeContentDisposition *disposition = NULL; + char *disposition_str = NULL; + char *disposition_filename = NULL; + disposition = g_mime_object_get_content_disposition(mobject); + if (disposition) { + disposition_str = (char *)g_mime_content_disposition_get_disposition(disposition); + disposition_filename = (char *)g_mime_content_disposition_get_parameter(disposition, "filename"); + } + EM_DEBUG_LOG("Disposition[%s]", disposition_str); + EM_DEBUG_LOG_SEC("Disposition-Filename[%s]", disposition_filename); + /*Content Disposition - END*/ + + /*Content Type*/ + GMimeContentType *ctype = NULL; + char *ctype_type = NULL; + char *ctype_subtype = NULL; + char *ctype_charset = NULL; + char *ctype_name = NULL; + + ctype = g_mime_object_get_content_type(mobject); + ctype_type = (char *)g_mime_content_type_get_media_type(ctype); + ctype_subtype = (char *)g_mime_content_type_get_media_subtype(ctype); + ctype_charset = (char *)g_mime_content_type_get_parameter(ctype, "charset"); + ctype_name = (char *)g_mime_content_type_get_parameter(ctype, "name"); + EM_DEBUG_LOG("Content-Type[%s/%s]", ctype_type, ctype_subtype); + EM_DEBUG_LOG("Content-Type-Charset[%s]", ctype_charset); + EM_DEBUG_LOG("Content-Type-Name[%s]", ctype_name); + /*Content Type - END*/ + + /*Content*/ + if (!emcore_get_temp_file_name(&content_path, &error)) { + EM_DEBUG_EXCEPTION("emcore_get_temp_file_name failed [%d]", error); + goto FINISH_OFF; + } + EM_DEBUG_LOG_SEC("Temporary Content Path[%s]", content_path); + + + GMimeContentEncoding enc = g_mime_part_get_content_encoding(leaf_part); + switch(enc) { + case GMIME_CONTENT_ENCODING_DEFAULT: + EM_DEBUG_LOG("Encoding:ENCODING_DEFAULT"); + break; + case GMIME_CONTENT_ENCODING_7BIT: + EM_DEBUG_LOG("Encoding:ENCODING_7BIT"); + break; + case GMIME_CONTENT_ENCODING_8BIT: + EM_DEBUG_LOG("Encoding:ENCODING_8BIT"); + break; + case GMIME_CONTENT_ENCODING_BINARY: + EM_DEBUG_LOG("Encoding:ENCODING_BINARY"); + break; + case GMIME_CONTENT_ENCODING_BASE64: + EM_DEBUG_LOG("Encoding:ENCODING_BASE64"); + break; + case GMIME_CONTENT_ENCODING_QUOTEDPRINTABLE: + EM_DEBUG_LOG("Encoding:ENCODING_QUOTEDPRINTABLE"); + break; + case GMIME_CONTENT_ENCODING_UUENCODE: + EM_DEBUG_LOG("Encoding:ENCODING_UUENCODE"); + break; + + default: + break; + } + + GMimeDataWrapper *data = g_mime_part_get_content_object(leaf_part); + if (data) { + int fd; + fd = open(content_path, O_WRONLY|O_CREAT, 0644); + if (fd < 0) { + EM_DEBUG_EXCEPTION("open failed"); + goto FINISH_OFF; + } + + GMimeStream *out_stream; + out_stream = g_mime_stream_fs_new(fd); + + //g_mime_data_wrapper_set_stream(data, out_stream); + //g_mime_data_wrapper_set_encoding(data, enc); + g_mime_data_wrapper_write_to_stream(data, out_stream); + if (out_stream) g_object_unref(out_stream); + emcore_get_file_size(content_path, &content_size, NULL); + } + /*Content - END*/ + + /*Figure out TEXT or ATTACHMENT(INLINE) ?*/ + int result = false; + if (disposition_str && g_ascii_strcasecmp(disposition_str, GMIME_DISPOSITION_ATTACHMENT) == 0) { + content_disposition_type = ATTACHMENT; + EM_DEBUG_LOG("ATTACHMENT"); + } else if ((content_id || content_location) && (ctype_name || disposition_filename)) { + if (cnt_info->attachment_only) { + content_disposition_type = ATTACHMENT; + EM_DEBUG_LOG("ATTACHMENT"); + } else { + content_disposition_type = INLINE_ATTACHMENT; + EM_DEBUG_LOG("INLINE_ATTACHMENT"); + } + } else { + if (content_id && + (emcore_search_string_from_file(cnt_info->text.html, content_id, NULL, &result) == EMAIL_ERROR_NONE && result)) { + content_disposition_type = INLINE_ATTACHMENT; + EM_DEBUG_LOG("INLINE_ATTACHMENT"); + } else if (content_id || content_location) { + if (g_ascii_strcasecmp(ctype_type, "text") == 0 && + (g_ascii_strcasecmp(ctype_subtype, "plain") == 0 || g_ascii_strcasecmp(ctype_subtype, "html") == 0)) { + EM_DEBUG_LOG("TEXT"); + } else { + if (cnt_info->attachment_only) { + content_disposition_type = ATTACHMENT; + EM_DEBUG_LOG("ATTACHMENT"); + } else { + content_disposition_type = INLINE_ATTACHMENT; + EM_DEBUG_LOG("INLINE_ATTACHMENT"); + } + } + } else { + if (g_ascii_strcasecmp(ctype_type, "text") == 0 && + (g_ascii_strcasecmp(ctype_subtype, "plain") == 0 || g_ascii_strcasecmp(ctype_subtype, "html") == 0)) { + EM_DEBUG_LOG("TEXT"); + } else { + content_disposition_type = ATTACHMENT; + EM_DEBUG_LOG("ATTACHMENT"); + } + } + } + + if (content_disposition_type != ATTACHMENT && content_disposition_type != INLINE_ATTACHMENT) { + /*TEXT*/ + EM_DEBUG_LOG("TEXT"); + if (ctype_type && g_ascii_strcasecmp(ctype_type, "text") == 0) { + if (!ctype_charset || g_ascii_strcasecmp(ctype_charset, "X-UNKNOWN") == 0) { + ctype_charset = "UTF-8"; + } + + if (ctype_subtype && g_ascii_strcasecmp(ctype_subtype, "plain") == 0) { + EM_DEBUG_LOG("TEXT/PLAIN"); + + char *file_content = NULL; + int content_size = 0; + + if (emcore_get_content_from_file(content_path, &file_content, &content_size) != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emcore_get_content_from_file failed"); + } + + if (file_content && content_size > 0) { + char escape = 0x1b; + char detector[25] = {0,}; + snprintf(detector, sizeof(detector), "%c$B", escape); + if (g_strrstr(ctype_charset, "UTF-8") && g_strrstr(file_content, detector)) { + ctype_charset = "ISO-2022-JP"; + } + } + + EM_SAFE_FREE(file_content); + + cnt_info->text.plain_charset = g_strdup(ctype_charset); + cnt_info->text.plain = g_strdup(content_path); + } else if (ctype_subtype && g_ascii_strcasecmp(ctype_subtype, "html") == 0) { + EM_DEBUG_LOG("TEXT/HTML"); + cnt_info->text.html_charset = g_strdup(ctype_charset); + cnt_info->text.html = g_strdup(content_path); + } + } + } else { + /*ATTACHMENT*/ + struct attachment_info *file = NULL; + struct attachment_info *temp_file = NULL; + char *utf8_text = NULL; + int err = EMAIL_ERROR_NONE; + + if (content_disposition_type == ATTACHMENT) { + EM_DEBUG_LOG("ATTACHMENT"); + temp_file = cnt_info->file; + } + else if (content_disposition_type == INLINE_ATTACHMENT) { + EM_DEBUG_LOG("INLINE ATTACHMENT"); + temp_file = cnt_info->inline_file; + } + else { + EM_DEBUG_EXCEPTION("Invalid content_disposition_type"); + goto FINISH_OFF; + } + + file = em_malloc(sizeof(struct attachment_info)); + if (file == NULL) { + EM_DEBUG_EXCEPTION("em_malloc failed..."); + goto FINISH_OFF; + } + + file->type = content_disposition_type; + if (disposition_filename) file->name = g_strdup(disposition_filename); + else if (ctype_name) file->name = g_strdup(ctype_name); + else if (content_id) file->name = g_strdup(content_id); + file->content_id = g_strdup(content_id); + + if (!(utf8_text = g_mime_utils_header_decode_text(file->name))) { + EM_DEBUG_EXCEPTION("g_mime_utils_header_decode_text failed [%d]", err); + } + EM_DEBUG_LOG_SEC("utf8_text : [%s]", utf8_text); + + if (utf8_text) { + EM_SAFE_FREE(file->name); + file->name = EM_SAFE_STRDUP(utf8_text); + } + EM_SAFE_FREE(utf8_text); + + /* check inline name duplication */ + if (content_disposition_type == INLINE_ATTACHMENT) { + char *modified_name = NULL; + if (emcore_gmime_check_filename_duplication(file->name, cnt_info)) { + modified_name = emcore_gmime_get_modified_filename_in_duplication(file->name); + EM_SAFE_FREE(file->name); + file->name = modified_name; + modified_name = NULL; + } + emcore_unescape_from_url(file->name, &modified_name); + EM_DEBUG_LOG_SEC("file->name[%s] modified_name[%s]", file->name, modified_name); + EM_SAFE_FREE(file->name); + file->name = modified_name; + } + + /*cid replacement for inline attachment*/ + if (content_disposition_type == INLINE_ATTACHMENT) { + char *file_content = NULL; + int content_size = 0; + + if (emcore_get_content_from_file(cnt_info->text.html, &file_content, &content_size) != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emcore_get_content_from_file failed"); + } + + if (file_content && content_size > 0) { + em_replace_string_ex(&file_content, "cid:", ""); + em_replace_string_ex(&file_content, file->content_id, file->name); + + content_size = EM_SAFE_STRLEN(file_content); + if (emcore_set_content_to_file(file_content, cnt_info->text.html, content_size) != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emcore_set_content_to_file failed"); + } + } + g_free(file_content); /* prevent 39110 */ + } + + if(ctype_type && ctype_subtype) { + char mime_type_buffer[128] = {0,}; + snprintf(mime_type_buffer, sizeof(mime_type_buffer), "%s/%s", ctype_type, ctype_subtype); + file->attachment_mime_type = g_strdup(mime_type_buffer); + } + + file->save = g_strdup(content_path); + file->size = content_size; + + if (ctype_type && g_ascii_strcasecmp(ctype_type, "APPLICATION") == 0) { + if (ctype_subtype && g_ascii_strcasecmp(ctype_subtype, MIME_SUBTYPE_DRM_OBJECT) == 0) + file->drm = EMAIL_ATTACHMENT_DRM_OBJECT; + else if (ctype_subtype && g_ascii_strcasecmp(ctype_subtype, MIME_SUBTYPE_DRM_RIGHTS) == 0) + file->drm = EMAIL_ATTACHMENT_DRM_RIGHTS; + else if (ctype_subtype && g_ascii_strcasecmp(ctype_subtype, MIME_SUBTYPE_DRM_DCF) == 0) + file->drm = EMAIL_ATTACHMENT_DRM_DCF; + } + + while (temp_file && temp_file->next) + temp_file = temp_file->next; + + if (temp_file == NULL) { + if (content_disposition_type == ATTACHMENT) { + cnt_info->file = file; + } else { + cnt_info->inline_file = file; + } + } + else + temp_file->next = file; + } + + EM_SAFE_FREE(content_path); + } + +FINISH_OFF: + + EM_SAFE_FREE(msg_tmp_content_path); + EM_SAFE_FREE(content_path); + EM_DEBUG_FUNC_END(); +} + + +static int emcore_gmime_parse_mime_header(GMimeMessage *message, struct _rfc822header *rfc822_header) +{ + EM_DEBUG_FUNC_BEGIN("message[%p], rfc822header[%p]", message, rfc822_header); + + int err = EMAIL_ERROR_NONE; + + if (!message || !rfc822_header) { + err = EMAIL_ERROR_INVALID_PARAM; + return err; + } + + rfc822_header->reply_to = EM_SAFE_STRDUP(g_mime_message_get_reply_to(message)); + EM_DEBUG_LOG_SEC("reply_to : [%s]", rfc822_header->reply_to); + + rfc822_header->date = g_mime_message_get_date_as_string(message); //PREVENT + EM_DEBUG_LOG_SEC("date : [%s]", rfc822_header->date); + + rfc822_header->subject = EM_SAFE_STRDUP(g_mime_message_get_subject(message)); + EM_DEBUG_LOG_SEC("subject : [%s]", rfc822_header->subject); + + rfc822_header->sender = EM_SAFE_STRDUP(g_mime_message_get_sender(message)); + EM_DEBUG_LOG_SEC("sender : [%s]", rfc822_header->sender); + + rfc822_header->to = EM_SAFE_STRDUP(internet_address_list_to_string(g_mime_message_get_recipients(message, GMIME_RECIPIENT_TYPE_TO), false)); + EM_DEBUG_LOG_SEC("to : [%s]", rfc822_header->to); + + rfc822_header->cc = EM_SAFE_STRDUP(internet_address_list_to_string(g_mime_message_get_recipients(message, GMIME_RECIPIENT_TYPE_CC), false)); + EM_DEBUG_LOG_SEC("cc : [%s]", rfc822_header->cc); + + rfc822_header->bcc = EM_SAFE_STRDUP(internet_address_list_to_string(g_mime_message_get_recipients(message, GMIME_RECIPIENT_TYPE_BCC), false)); + EM_DEBUG_LOG_SEC("bcc : [%s]", rfc822_header->bcc); + + rfc822_header->message_id = EM_SAFE_STRDUP(g_mime_message_get_message_id(message)); + EM_DEBUG_LOG("message_id : [%s]", rfc822_header->message_id); + + rfc822_header->content_type = EM_SAFE_STRDUP(g_mime_object_get_header((GMimeObject *)message, "content-type")); + EM_DEBUG_LOG("content_type : [%s]", rfc822_header->content_type); + + rfc822_header->from = EM_SAFE_STRDUP(g_mime_object_get_header((GMimeObject *)message, "from")); + EM_DEBUG_LOG_SEC("from : [%s]", rfc822_header->from); + + rfc822_header->received = EM_SAFE_STRDUP(g_mime_object_get_header((GMimeObject *)message, "received")); + EM_DEBUG_LOG_SEC("received : [%s]", rfc822_header->received); + + rfc822_header->return_path = EM_SAFE_STRDUP(g_mime_object_get_header((GMimeObject *)message, "return-path")); + EM_DEBUG_LOG_SEC("return_path : [%s]", rfc822_header->return_path); + + rfc822_header->priority = EM_SAFE_STRDUP(g_mime_object_get_header((GMimeObject *)message, "x-priority")); + EM_DEBUG_LOG("priority : [%s]", rfc822_header->priority); + + rfc822_header->ms_priority = EM_SAFE_STRDUP(g_mime_object_get_header((GMimeObject *)message, "x-msmail-priority")); + EM_DEBUG_LOG("ms_priority : [%s]", rfc822_header->ms_priority); + + rfc822_header->dsp_noti_to = EM_SAFE_STRDUP(g_mime_object_get_header((GMimeObject *)message, "disposition-notification-to")); + EM_DEBUG_LOG("dsp_noti_to : [%s]", rfc822_header->dsp_noti_to); + + EM_DEBUG_FUNC_END(); + return err; +} + +static void emcore_gmime_eml_parse_foreach_cb(GMimeObject *parent, GMimeObject *part, gpointer user_data) +{ + EM_DEBUG_FUNC_BEGIN("parent[%p], part[%p], user_data[%p]", parent, part, user_data); + + int error = EMAIL_ERROR_NONE; + int save_status = EMAIL_PART_DOWNLOAD_STATUS_NONE; + char *msg_tmp_content_path = NULL; + char *content_path = NULL; + struct _m_content_info *cnt_info = (struct _m_content_info *)user_data; + + if (GMIME_IS_MESSAGE_PART(part)) { + EM_DEBUG_LOG("Message Part"); + GMimeMessage *message = NULL; + GMimeContentType *msg_ctype = NULL; + GMimeContentDisposition *msg_disposition = NULL; + GMimeStream *out_stream; + char *msg_ctype_type = NULL; + char *msg_ctype_subtype = NULL; + char *msg_ctype_name = NULL; + char *msg_disposition_str = NULL; + char *msg_disposition_filename = NULL; + char *msg_content_id = NULL; + int real_size = 0; + int msg_fd = 0; + + save_status = EMAIL_PART_DOWNLOAD_STATUS_NONE; + + if (cnt_info->grab_type != (GRAB_TYPE_TEXT|GRAB_TYPE_ATTACHMENT) && + cnt_info->grab_type != GRAB_TYPE_ATTACHMENT) { + goto FINISH_OFF; + } + + message = g_mime_message_part_get_message((GMimeMessagePart *)part); + if (!message) { + EM_DEBUG_EXCEPTION("Message is NULL"); + goto FINISH_OFF; + } + + /*Content Type*/ + msg_ctype = g_mime_object_get_content_type(part); + msg_ctype_type = (char *)g_mime_content_type_get_media_type(msg_ctype); + msg_ctype_subtype = (char *)g_mime_content_type_get_media_subtype(msg_ctype); + msg_ctype_name = (char *)g_mime_content_type_get_parameter(msg_ctype, "name"); + EM_DEBUG_LOG("Content-Type[%s/%s]", msg_ctype_type, msg_ctype_subtype); + EM_DEBUG_LOG("RFC822/Message Content-Type-Name[%s]", msg_ctype_name); + /*Content Type - END*/ + + /*Content Disposition*/ + msg_disposition = g_mime_object_get_content_disposition(part); + if (msg_disposition) { + msg_disposition_str = (char *)g_mime_content_disposition_get_disposition(msg_disposition); + msg_disposition_filename = (char *)g_mime_content_disposition_get_parameter(msg_disposition, "filename"); + } + EM_DEBUG_LOG("RFC822/Message Disposition[%s]", msg_disposition_str); + EM_DEBUG_LOG_SEC("RFC822/Message Disposition-Filename[%s]", msg_disposition_filename); + /*Content Disposition - END*/ + + /*Content ID*/ + msg_content_id = (char *)g_mime_object_get_content_id(part); + EM_DEBUG_LOG("RFC822/Message Content-ID:%s", msg_content_id); + + /*save message content to tmp file*/ + if (!emcore_get_temp_file_name(&msg_tmp_content_path, &error)) { + EM_DEBUG_EXCEPTION("emcore_get_temp_file_name failed [%d]", error); + goto FINISH_OFF; + } + EM_DEBUG_LOG_SEC("Temporary Content Path[%s]", msg_tmp_content_path); + + msg_fd = open(msg_tmp_content_path, O_WRONLY|O_CREAT, 0644); + if (msg_fd < 0) { + EM_DEBUG_EXCEPTION("open failed"); + goto FINISH_OFF; + } + + out_stream = g_mime_stream_fs_new(msg_fd); + real_size = g_mime_object_write_to_stream(GMIME_OBJECT(message), out_stream); + if (out_stream) g_object_unref(out_stream); + + if (real_size <= 0) { + EM_DEBUG_EXCEPTION("g_mime_object_write_to_stream failed"); + goto FINISH_OFF; + } + + /* rfc822/message type is always saving to the attachment */ + EM_DEBUG_LOG("RFC822/Message is ATTACHMENT"); + + struct attachment_info *file = NULL; + struct attachment_info *temp_file = cnt_info->file; + char *utf8_text = NULL; + int err = EMAIL_ERROR_NONE; + + file = em_malloc(sizeof(struct attachment_info)); + if (file == NULL) { + EM_DEBUG_EXCEPTION("em_malloc failed..."); + goto FINISH_OFF; + } + + file->type = ATTACHMENT; + if (msg_disposition_filename) file->name = g_strdup(msg_disposition_filename); + else if (msg_ctype_name) file->name = g_strdup(msg_ctype_name); + else if (msg_content_id) file->name = g_strdup(msg_content_id); + else file->name = g_strdup("unknown"); + + if (msg_content_id) file->content_id = g_strdup(msg_content_id); + + if (!(utf8_text = g_mime_utils_header_decode_text(file->name))) { + EM_DEBUG_EXCEPTION("g_mime_utils_header_decode_text failed [%d]", err); + } + EM_DEBUG_LOG_SEC("utf8_text : [%s]", utf8_text); + + if (utf8_text) { + EM_SAFE_FREE(file->name); + file->name = EM_SAFE_STRDUP(utf8_text); + } + EM_SAFE_FREE(utf8_text); + + if(msg_ctype_type && msg_ctype_subtype) { + char mime_type_buffer[128] = {0,}; + snprintf(mime_type_buffer, sizeof(mime_type_buffer), "%s/%s", msg_ctype_type, msg_ctype_subtype); + file->attachment_mime_type = g_strdup(mime_type_buffer); + } + + file->save = g_strdup(msg_tmp_content_path); + file->size = real_size; + + while (temp_file && temp_file->next) + temp_file = temp_file->next; + + if (temp_file == NULL) + cnt_info->file = file; + else + temp_file->next = file; + + /* check the partial status */ + int save_status = EMAIL_BODY_DOWNLOAD_STATUS_NONE; + struct _m_content_info *temp_cnt_info = NULL; + struct attachment_info *ai = NULL; + + temp_cnt_info = (struct _m_content_info *)em_malloc(sizeof(struct _m_content_info)); + if (temp_cnt_info == NULL) { + EM_DEBUG_EXCEPTION("em_malloc failed..."); + err = EMAIL_ERROR_OUT_OF_MEMORY; + goto FINISH_OFF; + } + + g_mime_message_foreach(message, emcore_gmime_eml_parse_foreach_cb, temp_cnt_info); + + save_status = temp_cnt_info->text.plain_save_status; + save_status = temp_cnt_info->text.html_save_status; + + for (ai = temp_cnt_info->file; ai; ai = ai->next) { + save_status = ai->save_status; + } + + for (ai = temp_cnt_info->inline_file; ai; ai = ai->next) { + save_status = ai->save_status; + } + + file->save_status = save_status; + EM_DEBUG_LOG("save_status : [%d], [%d]", file->save_status, save_status); + + if (temp_cnt_info) { + emcore_free_content_info(temp_cnt_info); + EM_SAFE_FREE(temp_cnt_info); + } + + } else if (GMIME_IS_MESSAGE_PARTIAL(part)) { EM_DEBUG_LOG("Partial Part"); //TODO } else if (GMIME_IS_MULTIPART(part)) { - /* multipart/mixed, multipart/alternative, - * multipart/related, multipart/signed, - * multipart/encrypted, etc... */ EM_DEBUG_LOG("Multi Part"); GMimeMultipart *multi_part = NULL; - /* we'll get to finding out if this is a - * signed/encrypted multipart later... */ multi_part = (GMimeMultipart *)part; + multipart_status = 1; + int multi_count = g_mime_multipart_get_count(multi_part); EM_DEBUG_LOG("Multi Part Count:%d", multi_count); EM_DEBUG_LOG("Boundary:%s\n\n", g_mime_multipart_get_boundary(multi_part)); } else if (GMIME_IS_PART(part)) { - /* a normal leaf part, could be text/plain or - * image/jpeg etc */ EM_DEBUG_LOG("Part"); + int content_size = 0; + + save_status = EMAIL_PART_DOWNLOAD_STATUS_NONE; + GMimePart *leaf_part = NULL; leaf_part = (GMimePart *)part; @@ -179,7 +930,7 @@ static void emcore_parse_mime_foreach_callback(GMimeObject *parent, GMimeObject int content_disposition_type = 0; char *content_location = (char *)g_mime_part_get_content_location(leaf_part); - EM_DEBUG_LOG("Location:%s", content_location); + EM_DEBUG_LOG_SEC("Location:%s", content_location); GMimeObject *mobject = (GMimeObject *)part; @@ -196,19 +947,17 @@ static void emcore_parse_mime_foreach_callback(GMimeObject *parent, GMimeObject disposition_filename = (char *)g_mime_content_disposition_get_parameter(disposition, "filename"); } EM_DEBUG_LOG("Disposition[%s]", disposition_str); - EM_DEBUG_LOG("Disposition-Filename[%s]", disposition_filename); + EM_DEBUG_LOG_SEC("Disposition-Filename[%s]", disposition_filename); /*Content Disposition - END*/ /*Content Type*/ GMimeContentType *ctype = NULL; - GMimeParam *ctype_param = NULL; char *ctype_type = NULL; char *ctype_subtype = NULL; char *ctype_charset = NULL; char *ctype_name = NULL; ctype = g_mime_object_get_content_type(mobject); - ctype_param = (GMimeParam *)g_mime_content_type_get_params(ctype); ctype_type = (char *)g_mime_content_type_get_media_type(ctype); ctype_subtype = (char *)g_mime_content_type_get_media_subtype(ctype); ctype_charset = (char *)g_mime_content_type_get_parameter(ctype, "charset"); @@ -219,9 +968,12 @@ static void emcore_parse_mime_foreach_callback(GMimeObject *parent, GMimeObject /*Content Type - END*/ /*Content*/ - int content_size = 0; - char *content_path = emcore_mime_get_save_file_name(&error); - EM_DEBUG_LOG("Temporary Content Path[%s]", content_path); + if (!emcore_get_temp_file_name(&content_path, &error)) { + EM_DEBUG_EXCEPTION("emcore_get_temp_file_name failed [%d]", error); + goto FINISH_OFF; + } + EM_DEBUG_LOG_SEC("Temporary Content Path[%s]", content_path); + GMimeContentEncoding enc = g_mime_part_get_content_encoding(leaf_part); switch(enc) { @@ -256,7 +1008,7 @@ static void emcore_parse_mime_foreach_callback(GMimeObject *parent, GMimeObject int fd; fd = open(content_path, O_WRONLY|O_CREAT, 0644); if (fd < 0) { - EM_DEBUG_EXCEPTION("holder open failed : holder is a filename that will be saved."); + EM_DEBUG_EXCEPTION("open failed"); goto FINISH_OFF; } @@ -266,19 +1018,51 @@ static void emcore_parse_mime_foreach_callback(GMimeObject *parent, GMimeObject //g_mime_data_wrapper_set_stream(data, out_stream); //g_mime_data_wrapper_set_encoding(data, enc); g_mime_data_wrapper_write_to_stream(data, out_stream); - g_object_unref(out_stream); + if (out_stream) g_object_unref(out_stream); emcore_get_file_size(content_path, &content_size, NULL); + } else { + EM_DEBUG_LOG("Data is NULL"); + goto FINISH_OFF; } /*Content - END*/ + /* Set the partial body */ + GMimeStream *part_stream = g_mime_data_wrapper_get_stream(data); + if (part_stream) { + EM_DEBUG_LOG("part_stream->bound_end : [%lld]", part_stream->bound_end); + EM_DEBUG_LOG("super_stream->position : [%lld]", part_stream->super_stream->position); + EM_DEBUG_LOG("multipart_status : [%d]", multipart_status); + if (multipart_status && part_stream->super_stream->position <= part_stream->bound_end) { + save_status = EMAIL_PART_DOWNLOAD_STATUS_PARTIALLY_DOWNLOADED; + } else { + save_status = EMAIL_PART_DOWNLOAD_STATUS_FULLY_DOWNLOADED; + } + + EM_DEBUG_LOG("save_status : [%d]", save_status); + } + /*Figure out TEXT or ATTACHMENT(INLINE) ?*/ int result = false; + cnt_info->total_mail_size += content_size; if (content_id && (emcore_search_string_from_file(cnt_info->text.html, content_id, NULL, &result) == EMAIL_ERROR_NONE && result)) { content_disposition_type = INLINE_ATTACHMENT; + cnt_info->total_body_size += content_size; EM_DEBUG_LOG("INLINE_ATTACHMENT"); } else if ((disposition_str && g_ascii_strcasecmp(disposition_str, GMIME_DISPOSITION_ATTACHMENT) == 0) || disposition_filename || ctype_name) { content_disposition_type = ATTACHMENT; + cnt_info->total_attachment_size += content_size; + EM_DEBUG_LOG("ATTACHMENT"); + } else if (ctype_subtype && g_ascii_strcasecmp(ctype_subtype, "delivery-status") == 0) { + content_disposition_type = ATTACHMENT; + cnt_info->total_attachment_size += content_size; EM_DEBUG_LOG("ATTACHMENT"); + } else if (ctype_subtype && g_ascii_strcasecmp(ctype_subtype, "calendar") == 0) { + content_disposition_type = ATTACHMENT; + cnt_info->total_attachment_size += content_size; + EM_DEBUG_LOG("ATTACHMENT"); + } else { + cnt_info->total_body_size += content_size; + EM_DEBUG_LOG("Not INLINE or ATTACHMENT"); } if (content_disposition_type != ATTACHMENT && content_disposition_type != INLINE_ATTACHMENT) { @@ -291,21 +1075,55 @@ static void emcore_parse_mime_foreach_callback(GMimeObject *parent, GMimeObject if (ctype_subtype && g_ascii_strcasecmp(ctype_subtype, "plain") == 0) { EM_DEBUG_LOG("TEXT/PLAIN"); + + char *file_content = NULL; + int content_size = 0; + + if (emcore_get_content_from_file(content_path, &file_content, &content_size) != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emcore_get_content_from_file failed"); + } + + if (file_content && content_size > 0) { + char escape = 0x1b; + char detector[25] = {0,}; + snprintf(detector, sizeof(detector), "%c$B", escape); + if (g_strrstr(ctype_charset, "UTF-8") && g_strrstr(file_content, detector)) { + ctype_charset = "ISO-2022-JP"; + } + } + + EM_SAFE_FREE(file_content); + cnt_info->text.plain_charset = g_strdup(ctype_charset); - cnt_info->text.plain = content_path; + cnt_info->text.plain = g_strdup(content_path); + cnt_info->text.plain_save_status = save_status; } else if (ctype_subtype && g_ascii_strcasecmp(ctype_subtype, "html") == 0) { EM_DEBUG_LOG("TEXT/HTML"); cnt_info->text.html_charset = g_strdup(ctype_charset); - cnt_info->text.html = content_path; + cnt_info->text.html = g_strdup(content_path); + cnt_info->text.html_save_status = save_status; } } } else { /*ATTACHMENT*/ struct attachment_info *file = NULL; - struct attachment_info *temp_file = cnt_info->file; + struct attachment_info *temp_file = NULL; char *utf8_text = NULL; int err = EMAIL_ERROR_NONE; + if (content_disposition_type == ATTACHMENT) { + EM_DEBUG_LOG("ATTACHMENT"); + temp_file = cnt_info->file; + } + else if (content_disposition_type == INLINE_ATTACHMENT) { + EM_DEBUG_LOG("INLINE ATTACHMENT"); + temp_file = cnt_info->inline_file; + } + else { + EM_DEBUG_EXCEPTION("Invalid content_disposition_type"); + goto FINISH_OFF; + } + file = em_malloc(sizeof(struct attachment_info)); if (file == NULL) { EM_DEBUG_EXCEPTION("em_malloc failed..."); @@ -316,12 +1134,14 @@ static void emcore_parse_mime_foreach_callback(GMimeObject *parent, GMimeObject if (disposition_filename) file->name = g_strdup(disposition_filename); else if (ctype_name) file->name = g_strdup(ctype_name); else if (content_id) file->name = g_strdup(content_id); + else if (ctype_subtype && g_ascii_strcasecmp(ctype_subtype, "calendar") == 0) file->name = g_strdup("invite.vcs"); + else file->name = g_strdup("delivery-status"); file->content_id = g_strdup(content_id); - if (!(utf8_text = emcore_decode_rfc2047_text(file->name, &err))) { - EM_DEBUG_EXCEPTION("emcore_decode_rfc2047_text failed [%d]", err); + if (!(utf8_text = g_mime_utils_header_decode_text(file->name))) { + EM_DEBUG_EXCEPTION("g_mime_utils_header_decode_text failed [%d]", err); } - EM_DEBUG_LOG("utf8_text : [%s]", utf8_text); + EM_DEBUG_LOG_SEC("utf8_text : [%s]", utf8_text); if (utf8_text) { EM_SAFE_FREE(file->name); @@ -329,37 +1149,522 @@ static void emcore_parse_mime_foreach_callback(GMimeObject *parent, GMimeObject } EM_SAFE_FREE(utf8_text); + /* check inline name duplication */ + if (content_disposition_type == INLINE_ATTACHMENT) { + if (emcore_gmime_check_filename_duplication(file->name, cnt_info)) { + char *modified_name= NULL; + modified_name = emcore_gmime_get_modified_filename_in_duplication(file->name); + EM_SAFE_FREE(file->name); + file->name = modified_name; + } + } + /*cid replacement for inline attachment*/ if (content_disposition_type == INLINE_ATTACHMENT) { - gchar *file_content = NULL; - gsize content_size = 0; - GError* error = NULL; - if (!g_file_get_contents(cnt_info->text.html, &file_content, &content_size, &error)) { - if (error) { - EM_DEBUG_LOG("g_file_get_contents failed [%s]", error->message); - g_error_free(error); - error = NULL; - } else - EM_DEBUG_LOG("g_file_get_contents failed"); + char *file_content = NULL; + char *encoding_file_name = NULL; + int html_size = 0; + iconv_t cd; + + if (emcore_get_content_from_file(cnt_info->text.html, &file_content, &html_size) != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emcore_get_content_from_file failed"); + } + + EM_DEBUG_LOG_SEC("html_charset : [%s]", cnt_info->text.html_charset); + if (strcasecmp(cnt_info->text.html_charset, "UTF-8") != 0) { + cd = g_mime_iconv_open(cnt_info->text.html_charset, "UTF-8"); + if (cd) { + encoding_file_name = g_mime_iconv_strdup(cd, file->name); + } + + if (cd) + g_mime_iconv_close(cd); + + } else { + encoding_file_name = g_strdup(file->name); + } + + EM_DEBUG_LOG_SEC("File name : [%s], encoding file name : [%s]", file->name, encoding_file_name); + + if (file_content && html_size > 0) { + em_replace_string_ex(&file_content, "cid:", ""); + em_replace_string_ex(&file_content, file->content_id, encoding_file_name); + + html_size = EM_SAFE_STRLEN(file_content); + if (emcore_set_content_to_file(file_content, cnt_info->text.html, html_size) != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emcore_set_content_to_file failed"); + } + } + + g_free(file_content); /* prevent 39110 */ + g_free(encoding_file_name); + } + + if(ctype_type && ctype_subtype) { + char mime_type_buffer[128] = {0,}; + snprintf(mime_type_buffer, sizeof(mime_type_buffer), "%s/%s", ctype_type, ctype_subtype); + file->attachment_mime_type = g_strdup(mime_type_buffer); + } + + file->save_status = save_status; + file->save = g_strdup(content_path); + file->size = content_size; + + if (ctype_type && g_ascii_strcasecmp(ctype_type, "APPLICATION") == 0) { + if (ctype_subtype && g_ascii_strcasecmp(ctype_subtype, MIME_SUBTYPE_DRM_OBJECT) == 0) + file->drm = EMAIL_ATTACHMENT_DRM_OBJECT; + else if (ctype_subtype && g_ascii_strcasecmp(ctype_subtype, MIME_SUBTYPE_DRM_RIGHTS) == 0) + file->drm = EMAIL_ATTACHMENT_DRM_RIGHTS; + else if (ctype_subtype && g_ascii_strcasecmp(ctype_subtype, MIME_SUBTYPE_DRM_DCF) == 0) + file->drm = EMAIL_ATTACHMENT_DRM_DCF; + } + + while (temp_file && temp_file->next) + temp_file = temp_file->next; + + if (temp_file == NULL) { + if (content_disposition_type == ATTACHMENT) { + cnt_info->file = file; + } else { + cnt_info->inline_file = file; + } + } + else + temp_file->next = file; + } + + EM_SAFE_FREE(content_path); + } + +FINISH_OFF: + + EM_SAFE_FREE(msg_tmp_content_path); + EM_SAFE_FREE(content_path); + EM_DEBUG_FUNC_END(); +} + +INTERNAL_FUNC void emcore_gmime_imap_parse_foreach_cb(GMimeObject *parent, GMimeObject *part, gpointer user_data) +{ + EM_DEBUG_FUNC_BEGIN("parent[%p], part[%p], user_data[%p]", parent, part, user_data); + + int error = EMAIL_ERROR_NONE; + struct _m_content_info *cnt_info = (struct _m_content_info *)user_data; + char *content_path = NULL; + + if (GMIME_IS_MESSAGE_PART(part)) { + /* message/rfc822 or message/news */ + GMimeMessage *message = NULL; + GMimeContentType *msg_ctype = NULL; + GMimeContentDisposition *msg_disposition = NULL; + char *msg_ctype_type = NULL; + char *msg_ctype_subtype = NULL; + char *msg_ctype_name = NULL; + char *msg_ctype_size = NULL; + char *msg_disposition_str = NULL; + char *msg_disposition_filename = NULL; + char *msg_content_id = NULL; + unsigned long msg_content_size = 0; + EM_DEBUG_LOG("Message Part"); + + message = g_mime_message_part_get_message((GMimeMessagePart *)part); + if (!message) { + EM_DEBUG_EXCEPTION("Message is NULL"); + goto FINISH_OFF; + } + + /*Content Type*/ + msg_ctype = g_mime_object_get_content_type(part); + msg_ctype_type = (char *)g_mime_content_type_get_media_type(msg_ctype); + msg_ctype_subtype = (char *)g_mime_content_type_get_media_subtype(msg_ctype); + msg_ctype_name = (char *)g_mime_content_type_get_parameter(msg_ctype, "name"); + msg_ctype_size = (char *)g_mime_content_type_get_parameter(msg_ctype, "message_size"); + EM_DEBUG_LOG("Content-Type[%s/%s]", msg_ctype_type, msg_ctype_subtype); + EM_DEBUG_LOG("RFC822/Message Content-Type-Name[%s]", msg_ctype_name); + EM_DEBUG_LOG("Part.size.bytes[%s]", msg_ctype_size); + + if (msg_ctype_size) msg_content_size = atol(msg_ctype_size); + /*Content Type - END*/ + + /*Content Disposition*/ + msg_disposition = g_mime_object_get_content_disposition(part); + if (msg_disposition) { + msg_disposition_str = (char *)g_mime_content_disposition_get_disposition(msg_disposition); + msg_disposition_filename = (char *)g_mime_content_disposition_get_parameter(msg_disposition, "filename"); + } + EM_DEBUG_LOG("RFC822/Message Disposition[%s]", msg_disposition_str); + EM_DEBUG_LOG_SEC("RFC822/Message Disposition-Filename[%s]", msg_disposition_filename); + /*Content Disposition - END*/ + + /*Content ID*/ + msg_content_id = (char *)g_mime_object_get_content_id(part); + EM_DEBUG_LOG("RFC822/Message Content-ID:%s", msg_content_id); + + if (msg_disposition_str && g_ascii_strcasecmp(msg_disposition_str, GMIME_DISPOSITION_ATTACHMENT) == 0) { + EM_DEBUG_LOG("RFC822/Message is ATTACHMENT"); + + struct attachment_info *file = NULL; + struct attachment_info *temp_file = cnt_info->file; + char *utf8_text = NULL; + int err = EMAIL_ERROR_NONE; + + file = em_malloc(sizeof(struct attachment_info)); + if (file == NULL) { + EM_DEBUG_EXCEPTION("em_malloc failed..."); + goto FINISH_OFF; + } + + file->type = ATTACHMENT; + if (msg_disposition_filename) file->name = g_strdup(msg_disposition_filename); + else if (msg_ctype_name) file->name = g_strdup(msg_ctype_name); + else if (msg_content_id) file->name = g_strdup(msg_content_id); + else file->name = g_strdup("unknown"); + + if (msg_content_id) file->content_id = g_strdup(msg_content_id); + + if (!(utf8_text = g_mime_utils_header_decode_text(file->name))) { + EM_DEBUG_EXCEPTION("g_mime_utils_header_decode_text failed [%d]", err); + } + EM_DEBUG_LOG_SEC("utf8_text : [%s]", utf8_text); + + if (utf8_text) { + EM_SAFE_FREE(file->name); + file->name = EM_SAFE_STRDUP(utf8_text); + } + EM_SAFE_FREE(utf8_text); + + if(msg_ctype_type && msg_ctype_subtype) { + char mime_type_buffer[128] = {0,}; + snprintf(mime_type_buffer, sizeof(mime_type_buffer), "%s/%s", msg_ctype_type, msg_ctype_subtype); + file->attachment_mime_type = g_strdup(mime_type_buffer); + } + + file->save = NULL; + file->size = msg_content_size; + file->save_status = 0; + + while (temp_file && temp_file->next) + temp_file = temp_file->next; + + if (temp_file == NULL) + cnt_info->file = file; + else + temp_file->next = file; + } + + //g_mime_message_foreach(message, emcore_gmime_imap_parse_foreach_cb, user_data); + + } else if (GMIME_IS_MESSAGE_PARTIAL(part)) { + /* message/partial */ + + EM_DEBUG_LOG("Partial Part"); + //TODO + } else if (GMIME_IS_MULTIPART(part)) { + /* multipart/mixed, multipart/alternative, + * multipart/related, multipart/signed, + * multipart/encrypted, etc... */ + EM_DEBUG_LOG("Multi Part"); + GMimeMultipart *multi_part = NULL; + multi_part = (GMimeMultipart *)part; + + int multi_count = g_mime_multipart_get_count(multi_part); + EM_DEBUG_LOG("Multi Part Count:%d", multi_count); + EM_DEBUG_LOG("Boundary:%s\n\n", g_mime_multipart_get_boundary(multi_part)); + + } else if (GMIME_IS_PART(part)) { + /* a normal leaf part, could be text/plain or + * image/jpeg etc */ + + EM_DEBUG_LOG("Part"); + int download_status = 0; + int content_disposition_type = 0; + char *content_id = NULL; + char *content_location = NULL; + char *disposition_str = NULL; + char *disposition_filename = NULL; + char *ctype_type = NULL; + char *ctype_subtype = NULL; + char *ctype_charset = NULL; + char *ctype_name = NULL; + char *ctype_size = NULL; + unsigned long content_size = 0; + int real_size = 0; + + GMimeContentType *ctype = NULL; + GMimeContentDisposition *disposition = NULL; + GMimePart *leaf_part = NULL; + GMimeObject *mobject = (GMimeObject *)part; + leaf_part = (GMimePart *)part; + + /*Content Type*/ + ctype = g_mime_object_get_content_type(mobject); + ctype_type = (char *)g_mime_content_type_get_media_type(ctype); + ctype_subtype = (char *)g_mime_content_type_get_media_subtype(ctype); + ctype_charset = (char *)g_mime_content_type_get_parameter(ctype, "charset"); + ctype_name = (char *)g_mime_content_type_get_parameter(ctype, "name"); + ctype_size = (char *)g_mime_content_type_get_parameter(ctype, "part_size"); + EM_DEBUG_LOG("Content-Type[%s/%s]", ctype_type, ctype_subtype); + EM_DEBUG_LOG("Content-Type-Charset[%s]", ctype_charset); + EM_DEBUG_LOG_SEC("Content-Type-Name[%s]", ctype_name); + EM_DEBUG_LOG("Part.size.bytes[%s]", ctype_size); + + if (ctype_size) content_size = atol(ctype_size); + /*Content Type - END*/ + + /*Content Disposition*/ + disposition = g_mime_object_get_content_disposition(mobject); + if (disposition) { + disposition_str = (char *)g_mime_content_disposition_get_disposition(disposition); + disposition_filename = (char *)g_mime_content_disposition_get_parameter(disposition, "filename"); + } + EM_DEBUG_LOG("Disposition[%s]", disposition_str); + EM_DEBUG_LOG_SEC("Disposition-Filename[%s]", disposition_filename); + /*Content Disposition - END*/ + + /*Content ID*/ + content_id = (char *)g_mime_object_get_content_id(mobject); + EM_DEBUG_LOG_SEC("Content-ID:%s", content_id); + + /*Content Location*/ + content_location = (char *)g_mime_part_get_content_location(leaf_part); + EM_DEBUG_LOG_SEC("Content-Location:%s", content_location); + + /*Figure out TEXT or ATTACHMENT(INLINE) ?*/ + int result = false; + if (disposition_str && g_ascii_strcasecmp(disposition_str, GMIME_DISPOSITION_ATTACHMENT) == 0) { + if (content_id && + (emcore_search_string_from_file(cnt_info->text.html, content_id, NULL, &result) == EMAIL_ERROR_NONE && result)) { + content_disposition_type = INLINE_ATTACHMENT; + EM_DEBUG_LOG("INLINE_ATTACHMENT"); + } else { + content_disposition_type = ATTACHMENT; + EM_DEBUG_LOG("ATTACHMENT"); + } + } else if ((content_id || content_location) && (ctype_name || disposition_filename)) { + if (cnt_info->attachment_only) { + content_disposition_type = ATTACHMENT; + EM_DEBUG_LOG("ATTACHMENT"); + } else { + content_disposition_type = INLINE_ATTACHMENT; + EM_DEBUG_LOG("INLINE_ATTACHMENT"); + } + } else { + if (content_id && + (emcore_search_string_from_file(cnt_info->text.html, content_id, NULL, &result) == EMAIL_ERROR_NONE && result)) { + content_disposition_type = INLINE_ATTACHMENT; + EM_DEBUG_LOG("INLINE_ATTACHMENT"); + } else if (content_id || content_location) { + if (g_ascii_strcasecmp(ctype_type, "text") == 0 && + (g_ascii_strcasecmp(ctype_subtype, "plain") == 0 || g_ascii_strcasecmp(ctype_subtype, "html") == 0)) { + EM_DEBUG_LOG("TEXT"); + } else { + if (cnt_info->attachment_only) { + content_disposition_type = ATTACHMENT; + EM_DEBUG_LOG("ATTACHMENT"); + } else { + content_disposition_type = INLINE_ATTACHMENT; + EM_DEBUG_LOG("INLINE_ATTACHMENT"); + } + } + } else { + if (g_ascii_strcasecmp(ctype_type, "text") == 0 && + (g_ascii_strcasecmp(ctype_subtype, "plain") == 0 || g_ascii_strcasecmp(ctype_subtype, "html") == 0)) { + EM_DEBUG_LOG("TEXT"); + } else { + content_disposition_type = ATTACHMENT; + EM_DEBUG_LOG("ATTACHMENT"); + } + } + } + + /*if (content_id && (emcore_search_string_from_file(cnt_info->text.html, content_id, NULL, &result) == EMAIL_ERROR_NONE && result)) { + content_disposition_type = INLINE_ATTACHMENT; + EM_DEBUG_LOG("INLINE_ATTACHMENT"); + } else if ((disposition_str && g_ascii_strcasecmp(disposition_str, GMIME_DISPOSITION_ATTACHMENT) == 0) || disposition_filename || ctype_name) { + content_disposition_type = ATTACHMENT; + EM_DEBUG_LOG("ATTACHMENT"); + }*/ + + if (!emcore_get_temp_file_name(&content_path, &error)) { + EM_DEBUG_EXCEPTION("emcore_get_temp_file_name failed [%d]", error); + goto FINISH_OFF; + } + EM_DEBUG_LOG_SEC("Temporary Content Path[%s]", content_path); + + if (content_disposition_type != ATTACHMENT) { + /*Content*/ + GMimeContentEncoding enc = g_mime_part_get_content_encoding(leaf_part); + switch(enc) { + case GMIME_CONTENT_ENCODING_DEFAULT: + EM_DEBUG_LOG("Encoding:ENCODING_DEFAULT"); + break; + case GMIME_CONTENT_ENCODING_7BIT: + EM_DEBUG_LOG("Encoding:ENCODING_7BIT"); + break; + case GMIME_CONTENT_ENCODING_8BIT: + EM_DEBUG_LOG("Encoding:ENCODING_8BIT"); + break; + case GMIME_CONTENT_ENCODING_BINARY: + EM_DEBUG_LOG("Encoding:ENCODING_BINARY"); + break; + case GMIME_CONTENT_ENCODING_BASE64: + EM_DEBUG_LOG("Encoding:ENCODING_BASE64"); + break; + case GMIME_CONTENT_ENCODING_QUOTEDPRINTABLE: + EM_DEBUG_LOG("Encoding:ENCODING_QUOTEDPRINTABLE"); + break; + case GMIME_CONTENT_ENCODING_UUENCODE: + EM_DEBUG_LOG("Encoding:ENCODING_UUENCODE"); + break; + + default: + break; + } + + GMimeDataWrapper *data = g_mime_part_get_content_object(leaf_part); + if (data) { + EM_DEBUG_LOG_DEV("DataWrapper/ref-cnt[%d]", data->parent_object.ref_count); + int fd = 0; + int src_length = 0; + GMimeStream *out_stream = NULL; + GMimeStream *src_stream = NULL; + + fd = open(content_path, 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 (file_content) { - reg_replace_new(&file_content, "cid:", ""); - reg_replace_new(&file_content, file->content_id, file->name); - EM_DEBUG_LOG("%s", file_content); + out_stream = g_mime_stream_fs_new(fd); + src_stream = g_mime_data_wrapper_get_stream(data); + if (src_stream) src_length = g_mime_stream_length(src_stream); + EM_DEBUG_LOG_DEV("Data length [%d]", src_length); + + if (src_length >= content_size) /* fully downloaded */ + download_status = EMAIL_PART_DOWNLOAD_STATUS_FULLY_DOWNLOADED; + else /* partialy downloaded */ + download_status = EMAIL_PART_DOWNLOAD_STATUS_PARTIALLY_DOWNLOADED; + + /*g_mime_data_wrapper_set_stream(data, out_stream); + g_mime_data_wrapper_set_encoding(data, enc);*/ - if (!g_file_set_contents(cnt_info->text.html, file_content, -1, &error)) { - if (error) { - EM_DEBUG_LOG("g_file_set_contents failed [%s]", error->message); - g_error_free(error); - error = NULL; - } else - EM_DEBUG_LOG("g_file_set_contents failed"); + g_mime_data_wrapper_write_to_stream(data, out_stream); + if (out_stream) g_object_unref(out_stream); + emcore_get_file_size(content_path, &real_size, NULL); + } + /*Content - END*/ + } + + if (content_disposition_type != ATTACHMENT && content_disposition_type != INLINE_ATTACHMENT) { + /*TEXT*/ + EM_DEBUG_LOG("TEXT"); + + if (ctype_type && g_ascii_strcasecmp(ctype_type, "text") == 0) { + if (!ctype_charset || g_ascii_strcasecmp(ctype_charset, "X-UNKNOWN") == 0) { + ctype_charset = "UTF-8"; + } + + if (ctype_subtype && g_ascii_strcasecmp(ctype_subtype, "plain") == 0) { + EM_DEBUG_LOG("TEXT/PLAIN"); + + char *file_content = NULL; + int content_size = 0; + + if (emcore_get_content_from_file(content_path, &file_content, &content_size) != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emcore_get_content_from_file failed"); } - g_free(file_content); + if (file_content && content_size > 0) { + char escape = 0x1b; + char detector[25] = {0,}; + snprintf(detector, sizeof(detector), "%c$B", escape); + if (g_strrstr(ctype_charset, "UTF-8") && g_strrstr(file_content, detector)) { + ctype_charset = "ISO-2022-JP"; + } + } + + EM_SAFE_FREE(file_content); + + cnt_info->text.plain_charset = g_strdup(ctype_charset); + cnt_info->text.plain = g_strdup(content_path); + } else if (ctype_subtype && g_ascii_strcasecmp(ctype_subtype, "html") == 0) { + EM_DEBUG_LOG("TEXT/HTML"); + cnt_info->text.html_charset = g_strdup(ctype_charset); + cnt_info->text.html = g_strdup(content_path); } } + } else if (content_disposition_type == INLINE_ATTACHMENT) { + + struct attachment_info *file = NULL; + struct attachment_info *temp_file = cnt_info->inline_file; + char *utf8_text = NULL; + char *file_content = NULL; + int file_size = 0; + int err = EMAIL_ERROR_NONE; + + file = em_malloc(sizeof(struct attachment_info)); + if (file == NULL) { + EM_DEBUG_EXCEPTION("em_malloc failed..."); + goto FINISH_OFF; + } + + file->type = content_disposition_type; + if (disposition_filename) file->name = g_strdup(disposition_filename); + else if (ctype_name) file->name = g_strdup(ctype_name); + else if (content_id) file->name = g_strdup(content_id); + file->content_id = g_strdup(content_id); + + if (file->name && g_strrstr(file->name, "/") != NULL) { + char *tmp_ptr = file->name; + int tmp_len = EM_SAFE_STRLEN(file->name); + int tmpi = 0; + for (tmpi=0; tmpi<tmp_len; tmpi++) { + if (*(tmp_ptr+tmpi) == '/') { + *(tmp_ptr+tmpi) = '_'; + } + } + EM_DEBUG_LOG_SEC("file->name[%s]", file->name); + } + + if (!(utf8_text = g_mime_utils_header_decode_text(file->name))) { + EM_DEBUG_EXCEPTION("g_mime_utils_header_decode_text failed [%d]", err); + } + EM_DEBUG_LOG_SEC("utf8_text : [%s]", utf8_text); + + if (utf8_text) { + EM_SAFE_FREE(file->name); + file->name = EM_SAFE_STRDUP(utf8_text); + } + EM_SAFE_FREE(utf8_text); + + /* check inline name duplication */ + char *modified_name = NULL; + if (emcore_gmime_check_filename_duplication(file->name, cnt_info)) { + modified_name = emcore_gmime_get_modified_filename_in_duplication(file->name); + EM_SAFE_FREE(file->name); + file->name = modified_name; + modified_name = NULL; + } + + emcore_unescape_from_url(file->name, &modified_name); + EM_DEBUG_LOG_SEC("file->name[%s] modified_name[%s]", file->name, modified_name); + EM_SAFE_FREE(file->name); + file->name = modified_name; + + /*cid replacement for inline attachment*/ + if (emcore_get_content_from_file(cnt_info->text.html, &file_content, &file_size) != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emcore_get_content_from_file failed"); + } + + if (file_content && file_size > 0) { + em_replace_string_ex(&file_content, "cid:", ""); + em_replace_string_ex(&file_content, file->content_id, file->name); + + file_size = EM_SAFE_STRLEN(file_content); + if (emcore_set_content_to_file(file_content, cnt_info->text.html, file_size) != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emcore_set_content_to_file failed"); + } + } + g_free(file_content); /* prevent 39110 */ if(ctype_type && ctype_subtype) { char mime_type_buffer[128] = {0,}; @@ -367,8 +1672,63 @@ static void emcore_parse_mime_foreach_callback(GMimeObject *parent, GMimeObject file->attachment_mime_type = g_strdup(mime_type_buffer); } - file->save = content_path; + file->save = g_strdup(content_path); file->size = content_size; + if (download_status == EMAIL_PART_DOWNLOAD_STATUS_FULLY_DOWNLOADED) { + file->save_status = 1; + file->size = real_size; + } + else + file->save_status = 0; + + while (temp_file && temp_file->next) + temp_file = temp_file->next; + + if (temp_file == NULL) + cnt_info->inline_file = file; + else + temp_file->next = file; + } else if (content_disposition_type == ATTACHMENT) { + + struct attachment_info *file = NULL; + struct attachment_info *temp_file = cnt_info->file; + char *utf8_text = NULL; + int err = EMAIL_ERROR_NONE; + + file = em_malloc(sizeof(struct attachment_info)); + if (file == NULL) { + EM_DEBUG_EXCEPTION("em_malloc failed..."); + goto FINISH_OFF; + } + + file->type = content_disposition_type; + if (disposition_filename) file->name = g_strdup(disposition_filename); + else if (ctype_name) file->name = g_strdup(ctype_name); + else if (content_id) file->name = g_strdup(content_id); + else file->name = g_strdup("unknown-attachment"); + + file->content_id = g_strdup(content_id); + + if (!(utf8_text = g_mime_utils_header_decode_text(file->name))) { + EM_DEBUG_EXCEPTION("g_mime_utils_header_decode_text failed [%d]", err); + } + EM_DEBUG_LOG_SEC("utf8_text : [%s]", utf8_text); + + if (utf8_text) { + EM_SAFE_FREE(file->name); + file->name = EM_SAFE_STRDUP(utf8_text); + } + EM_SAFE_FREE(utf8_text); + + if(ctype_type && ctype_subtype) { + char mime_type_buffer[128] = {0,}; + snprintf(mime_type_buffer, sizeof(mime_type_buffer), "%s/%s", ctype_type, ctype_subtype); + file->attachment_mime_type = g_strdup(mime_type_buffer); + } + + file->save = g_strdup(content_path); + file->size = content_size; + file->save_status = 0; if (ctype_type && g_ascii_strcasecmp(ctype_type, "APPLICATION") == 0) { if (ctype_subtype && g_ascii_strcasecmp(ctype_subtype, MIME_SUBTYPE_DRM_OBJECT) == 0) @@ -387,12 +1747,2973 @@ static void emcore_parse_mime_foreach_callback(GMimeObject *parent, GMimeObject else temp_file->next = file; } + + EM_SAFE_FREE(content_path); + } + +FINISH_OFF: + + EM_SAFE_FREE(content_path); + + EM_DEBUG_FUNC_END(); +} + + +INTERNAL_FUNC void emcore_gmime_imap_parse_full_foreach_cb(GMimeObject *parent, GMimeObject *part, gpointer user_data) +{ + EM_DEBUG_FUNC_BEGIN("parent[%p], part[%p], user_data[%p]", parent, part, user_data); + + int error = EMAIL_ERROR_NONE; + struct _m_content_info *cnt_info = (struct _m_content_info *)user_data; + char *content_path = NULL; + + if (GMIME_IS_MESSAGE_PART(part)) { + EM_DEBUG_LOG("Message Part"); + GMimeContentType *msg_ctype = NULL; + GMimeContentDisposition *msg_disposition = NULL; + char *msg_ctype_type = NULL; + char *msg_ctype_subtype = NULL; + char *msg_ctype_name = NULL; + char *msg_disposition_str = NULL; + char *msg_disposition_filename = NULL; + char *msg_content_id = NULL; + char *msg_tmp_content_path = NULL; + int real_size = 0; + + if (cnt_info->grab_type != (GRAB_TYPE_TEXT|GRAB_TYPE_ATTACHMENT) && + cnt_info->grab_type != GRAB_TYPE_ATTACHMENT) { + goto FINISH_OFF; + } + + /*Content Type*/ + msg_ctype = g_mime_object_get_content_type(part); + msg_ctype_type = (char *)g_mime_content_type_get_media_type(msg_ctype); + msg_ctype_subtype = (char *)g_mime_content_type_get_media_subtype(msg_ctype); + msg_ctype_name = (char *)g_mime_content_type_get_parameter(msg_ctype, "name"); + msg_tmp_content_path = (char *)g_mime_content_type_get_parameter(msg_ctype, "tmp_content_path"); + EM_DEBUG_LOG("Content-Type[%s/%s]", msg_ctype_type, msg_ctype_subtype); + EM_DEBUG_LOG_SEC("RFC822/Message Content-Type-Name[%s]", msg_ctype_name); + EM_DEBUG_LOG_SEC("RFC822/Message Content-Type-tmp-path[%s]", msg_tmp_content_path); + /*Content Type - END*/ + + /*Content Disposition*/ + msg_disposition = g_mime_object_get_content_disposition(part); + if (msg_disposition) { + msg_disposition_str = (char *)g_mime_content_disposition_get_disposition(msg_disposition); + msg_disposition_filename = (char *)g_mime_content_disposition_get_parameter(msg_disposition, "filename"); + } + EM_DEBUG_LOG("RFC822/Message Disposition[%s]", msg_disposition_str); + EM_DEBUG_LOG_SEC("RFC822/Message Disposition-Filename[%s]", msg_disposition_filename); + /*Content Disposition - END*/ + + /*Content ID*/ + msg_content_id = (char *)g_mime_object_get_content_id(part); + EM_DEBUG_LOG("RFC822/Message Content-ID:%s", msg_content_id); + + emcore_get_file_size(msg_tmp_content_path, &real_size, NULL); + if (real_size <= 0) { + EM_DEBUG_EXCEPTION("tmp content file is not valid"); + goto FINISH_OFF; + } + + if (msg_disposition_str && g_ascii_strcasecmp(msg_disposition_str, GMIME_DISPOSITION_ATTACHMENT) == 0) { + EM_DEBUG_LOG("RFC822/Message is ATTACHMENT"); + + struct attachment_info *file = NULL; + struct attachment_info *temp_file = cnt_info->file; + char *utf8_text = NULL; + int err = EMAIL_ERROR_NONE; + + file = em_malloc(sizeof(struct attachment_info)); + if (file == NULL) { + EM_DEBUG_EXCEPTION("em_malloc failed..."); + goto FINISH_OFF; + } + + file->type = ATTACHMENT; + if (msg_disposition_filename) file->name = g_strdup(msg_disposition_filename); + else if (msg_ctype_name) file->name = g_strdup(msg_ctype_name); + else if (msg_content_id) file->name = g_strdup(msg_content_id); + else file->name = g_strdup("unknown"); + + if (msg_content_id) file->content_id = g_strdup(msg_content_id); + + if (!(utf8_text = g_mime_utils_header_decode_text(file->name))) { + EM_DEBUG_EXCEPTION("g_mime_utils_header_decode_text failed [%d]", err); + } + EM_DEBUG_LOG_SEC("utf8_text : [%s]", utf8_text); + + if (utf8_text) { + EM_SAFE_FREE(file->name); + file->name = EM_SAFE_STRDUP(utf8_text); + } + EM_SAFE_FREE(utf8_text); + + if(msg_ctype_type && msg_ctype_subtype) { + char mime_type_buffer[128] = {0,}; + snprintf(mime_type_buffer, sizeof(mime_type_buffer), "%s/%s", msg_ctype_type, msg_ctype_subtype); + file->attachment_mime_type = g_strdup(mime_type_buffer); + } + + file->save = g_strdup(msg_tmp_content_path); + file->size = real_size; + file->save_status = 1; + + while (temp_file && temp_file->next) + temp_file = temp_file->next; + + if (temp_file == NULL) + cnt_info->file = file; + else + temp_file->next = file; + } + + //g_mime_message_foreach(message, emcore_gmime_imap_parse_full_foreach_cb, user_data); + } else if (GMIME_IS_MESSAGE_PARTIAL(part)) { + EM_DEBUG_LOG("Partial Part"); + } else if (GMIME_IS_MULTIPART(part)) { + EM_DEBUG_LOG("Multi Part"); + GMimeMultipart *multi_part = NULL; + multi_part = (GMimeMultipart *)part; + + int multi_count = g_mime_multipart_get_count(multi_part); + EM_DEBUG_LOG("Multi Part Count:%d", multi_count); + EM_DEBUG_LOG("Boundary:%s\n\n", g_mime_multipart_get_boundary(multi_part)); + } else if (GMIME_IS_PART(part)) { + EM_DEBUG_LOG("Part"); + int content_disposition_type = 0; + int real_size = 0; + char *content_id = NULL; + char *content_location = NULL; + char *disposition_str = NULL; + char *disposition_filename = NULL; + char *ctype_type = NULL; + char *ctype_subtype = NULL; + char *ctype_charset = NULL; + char *ctype_name = NULL; + char *ctype_size = NULL; + char *tmp_path = NULL; + + GMimeContentType *ctype = NULL; + GMimeContentDisposition *disposition = NULL; + GMimePart *leaf_part = NULL; + GMimeObject *mobject = (GMimeObject *)part; + leaf_part = (GMimePart *)part; + + /*Content Type*/ + ctype = g_mime_object_get_content_type(mobject); + ctype_type = (char *)g_mime_content_type_get_media_type(ctype); + ctype_subtype = (char *)g_mime_content_type_get_media_subtype(ctype); + ctype_charset = (char *)g_mime_content_type_get_parameter(ctype, "charset"); + ctype_name = (char *)g_mime_content_type_get_parameter(ctype, "name"); + ctype_size = (char *)g_mime_content_type_get_parameter(ctype, "part_size"); + EM_DEBUG_LOG("Content-Type[%s/%s]", ctype_type, ctype_subtype); + EM_DEBUG_LOG("Content-Type-Charset[%s]", ctype_charset); + EM_DEBUG_LOG_SEC("Content-Type-Name[%s]", ctype_name); + /*Content Type - END*/ + + /*Content Disposition*/ + disposition = g_mime_object_get_content_disposition(mobject); + if (disposition) { + disposition_str = (char *)g_mime_content_disposition_get_disposition(disposition); + disposition_filename = (char *)g_mime_content_disposition_get_parameter(disposition, "filename"); + } + EM_DEBUG_LOG("Disposition[%s]", disposition_str); + EM_DEBUG_LOG_SEC("Disposition-Filename[%s]", disposition_filename); + /*Content Disposition - END*/ + + /*Content ID*/ + content_id = (char *)g_mime_object_get_content_id(mobject); + EM_DEBUG_LOG_SEC("Content-ID:%s", content_id); + + /*Content Location*/ + content_location = (char *)g_mime_part_get_content_location(leaf_part); + EM_DEBUG_LOG_SEC("Content-Location:%s", content_location); + + + /*Figure out TEXT or ATTACHMENT(INLINE) ?*/ + int result = false; + if (disposition_str && g_ascii_strcasecmp(disposition_str, GMIME_DISPOSITION_ATTACHMENT) == 0) { + content_disposition_type = ATTACHMENT; + EM_DEBUG_LOG("ATTACHMENT"); + } else if ((content_id || content_location) && (ctype_name || disposition_filename)) { + if (cnt_info->attachment_only) { + content_disposition_type = ATTACHMENT; + EM_DEBUG_LOG("ATTACHMENT"); + } else { + content_disposition_type = INLINE_ATTACHMENT; + EM_DEBUG_LOG("INLINE_ATTACHMENT"); + } + } else { + if (content_id && + (emcore_search_string_from_file(cnt_info->text.html, content_id, NULL, &result) == EMAIL_ERROR_NONE && result)) { + content_disposition_type = INLINE_ATTACHMENT; + EM_DEBUG_LOG("INLINE_ATTACHMENT"); + } else if (content_id || content_location) { + if (g_ascii_strcasecmp(ctype_type, "text") == 0 && + (g_ascii_strcasecmp(ctype_subtype, "plain") == 0 || g_ascii_strcasecmp(ctype_subtype, "html") == 0)) { + EM_DEBUG_LOG("TEXT"); + } else { + if (cnt_info->attachment_only) { + content_disposition_type = ATTACHMENT; + EM_DEBUG_LOG("ATTACHMENT"); + } else { + content_disposition_type = INLINE_ATTACHMENT; + EM_DEBUG_LOG("INLINE_ATTACHMENT"); + } + } + } else { + if (g_ascii_strcasecmp(ctype_type, "text") == 0 && + (g_ascii_strcasecmp(ctype_subtype, "plain") == 0 || g_ascii_strcasecmp(ctype_subtype, "html") == 0)) { + EM_DEBUG_LOG("TEXT"); + } else { + content_disposition_type = ATTACHMENT; + EM_DEBUG_LOG("ATTACHMENT"); + } + } + } + + /*if (content_id && (emcore_search_string_from_file(cnt_info->text.html, content_id, NULL, &result) == EMAIL_ERROR_NONE && result)) { + content_disposition_type = INLINE_ATTACHMENT; + EM_DEBUG_LOG("INLINE_ATTACHMENT"); + } else if ((disposition_str && g_ascii_strcasecmp(disposition_str, GMIME_DISPOSITION_ATTACHMENT) == 0) || disposition_filename || ctype_name) { + content_disposition_type = ATTACHMENT; + EM_DEBUG_LOG("ATTACHMENT"); + }*/ + + /*Content*/ + if (!emcore_get_temp_file_name(&content_path, &error)) { + EM_DEBUG_EXCEPTION("emcore_get_temp_file_name failed [%d]", error); + goto FINISH_OFF; + } + EM_DEBUG_LOG_SEC("Temporary Content Path[%s]", content_path); + + GMimeContentEncoding enc = g_mime_part_get_content_encoding(leaf_part); + switch(enc) { + case GMIME_CONTENT_ENCODING_DEFAULT: + EM_DEBUG_LOG("Encoding:ENCODING_DEFAULT"); + break; + case GMIME_CONTENT_ENCODING_7BIT: + EM_DEBUG_LOG("Encoding:ENCODING_7BIT"); + break; + case GMIME_CONTENT_ENCODING_8BIT: + EM_DEBUG_LOG("Encoding:ENCODING_8BIT"); + break; + case GMIME_CONTENT_ENCODING_BINARY: + EM_DEBUG_LOG("Encoding:ENCODING_BINARY"); + break; + case GMIME_CONTENT_ENCODING_BASE64: + EM_DEBUG_LOG("Encoding:ENCODING_BASE64"); + break; + case GMIME_CONTENT_ENCODING_QUOTEDPRINTABLE: + EM_DEBUG_LOG("Encoding:ENCODING_QUOTEDPRINTABLE"); + break; + case GMIME_CONTENT_ENCODING_UUENCODE: + EM_DEBUG_LOG("Encoding:ENCODING_UUENCODE"); + break; + + default: + break; + } + + GMimeDataWrapper *data = g_mime_part_get_content_object(leaf_part); + if (data) { + int fd = 0; + GMimeStream *out_stream = NULL; + GMimeStream *src_stream = NULL; + + fd = open(content_path, 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; + } + + out_stream = g_mime_stream_fs_new(fd); + src_stream = g_mime_data_wrapper_get_stream(data); + + if (src_stream) + EM_DEBUG_LOG_DEV("Data length [%d]", g_mime_stream_length(src_stream)); + + /*g_mime_data_wrapper_set_stream(data, out_stream); + g_mime_data_wrapper_set_encoding(data, enc);*/ + + g_mime_data_wrapper_write_to_stream(data, out_stream); + if (out_stream) g_object_unref(out_stream); + emcore_get_file_size(content_path, &real_size, NULL); + } + else + { + int fd = 0; + fd = open(content_path, 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; + } + close(fd); + } + /*Content - END*/ + + ctype = g_mime_object_get_content_type(mobject); + tmp_path = (char *)g_mime_content_type_get_parameter(ctype, "tmp_content_path"); + if (tmp_path) { + g_remove(tmp_path); + } + + if (content_disposition_type != ATTACHMENT && content_disposition_type != INLINE_ATTACHMENT) { + /*TEXT*/ + EM_DEBUG_LOG("TEXT"); + + if (ctype_type && g_ascii_strcasecmp(ctype_type, "text") == 0) { + if (!ctype_charset || g_ascii_strcasecmp(ctype_charset, "X-UNKNOWN") == 0) { + ctype_charset = "UTF-8"; + } + + if (ctype_subtype && g_ascii_strcasecmp(ctype_subtype, "plain") == 0) { + EM_DEBUG_LOG("TEXT/PLAIN"); + + char *file_content = NULL; + int content_size = 0; + + if (emcore_get_content_from_file(content_path, &file_content, &content_size) != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emcore_get_content_from_file failed"); + } + + if (file_content && content_size > 0) { + char escape = 0x1b; + char detector[25] = {0,}; + snprintf(detector, sizeof(detector), "%c$B", escape); + if (g_strrstr(ctype_charset, "UTF-8") && g_strrstr(file_content, detector)) { + ctype_charset = "ISO-2022-JP"; + } + } + + EM_SAFE_FREE(file_content); + EM_SAFE_FREE(cnt_info->text.plain_charset); + EM_SAFE_FREE(cnt_info->text.plain); + + cnt_info->text.plain_charset = g_strdup(ctype_charset); + cnt_info->text.plain = g_strdup(content_path); + } else if (ctype_subtype && g_ascii_strcasecmp(ctype_subtype, "html") == 0) { + EM_DEBUG_LOG("TEXT/HTML"); + + EM_SAFE_FREE(cnt_info->text.html_charset); + EM_SAFE_FREE(cnt_info->text.html); + + cnt_info->text.html_charset = g_strdup(ctype_charset); + cnt_info->text.html = g_strdup(content_path); + } + } + } else if (content_disposition_type == INLINE_ATTACHMENT) { + + struct attachment_info *file = NULL; + struct attachment_info *temp_file = cnt_info->inline_file; + char *utf8_text = NULL; + char *file_content = NULL; + int file_size = 0; + int err = EMAIL_ERROR_NONE; + + file = em_malloc(sizeof(struct attachment_info)); + if (file == NULL) { + EM_DEBUG_EXCEPTION("em_malloc failed..."); + goto FINISH_OFF; + } + + file->type = content_disposition_type; + if (disposition_filename) file->name = g_strdup(disposition_filename); + else if (ctype_name) file->name = g_strdup(ctype_name); + else if (content_id) file->name = g_strdup(content_id); + file->content_id = g_strdup(content_id); + + if (file->name && g_strrstr(file->name, "/") != NULL) { + char *tmp_ptr = file->name; + int tmp_len = EM_SAFE_STRLEN(file->name); + int tmpi = 0; + for (tmpi=0; tmpi<tmp_len; tmpi++) { + if (*(tmp_ptr+tmpi) == '/') { + *(tmp_ptr+tmpi) = '_'; + } + } + EM_DEBUG_LOG_SEC("file->name[%s]", file->name); + } + + if (!(utf8_text = g_mime_utils_header_decode_text(file->name))) { + EM_DEBUG_EXCEPTION("g_mime_utils_header_decode_text failed [%d]", err); + } + EM_DEBUG_LOG_SEC("utf8_text : [%s]", utf8_text); + + if (utf8_text) { + EM_SAFE_FREE(file->name); + file->name = EM_SAFE_STRDUP(utf8_text); + } + EM_SAFE_FREE(utf8_text); + + /* check inline name duplication */ + char *modified_name= NULL; + if (emcore_gmime_check_filename_duplication(file->name, cnt_info)) { + modified_name = emcore_gmime_get_modified_filename_in_duplication(file->name); + EM_SAFE_FREE(file->name); + file->name = modified_name; + } + + char *modified_name2 = NULL; + emcore_unescape_from_url(file->name, &modified_name2); + EM_DEBUG_LOG_SEC("file->name[%s] modified_name[%s]", file->name, modified_name2); + EM_SAFE_FREE(file->name); + file->name = modified_name2; + + /* cid replacement for inline attachment */ + if (emcore_get_content_from_file(cnt_info->text.html, &file_content, &file_size) != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emcore_get_content_from_file failed"); + } + + if (file_content && file_size > 0) { + EM_DEBUG_LOG_SEC("content_id[%s] name[%s]", file->content_id, file->name); + em_replace_string_ex(&file_content, "cid:", ""); + em_replace_string_ex(&file_content, file->content_id, file->name); + + file_size = EM_SAFE_STRLEN(file_content); + if (emcore_set_content_to_file(file_content, cnt_info->text.html, file_size) != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emcore_set_content_to_file failed"); + } + } + g_free(file_content); /* prevent 39110 */ + + if(ctype_type && ctype_subtype) { + char mime_type_buffer[128] = {0,}; + snprintf(mime_type_buffer, sizeof(mime_type_buffer), "%s/%s", ctype_type, ctype_subtype); + file->attachment_mime_type = g_strdup(mime_type_buffer); + } + + file->save = g_strdup(content_path); + file->size = real_size; + file->save_status = 1; + + while (temp_file && temp_file->next) + temp_file = temp_file->next; + + if (temp_file == NULL) + cnt_info->inline_file = file; + else + temp_file->next = file; + } else if (content_disposition_type == ATTACHMENT) { + + struct attachment_info *file = NULL; + struct attachment_info *temp_file = cnt_info->file; + char *utf8_text = NULL; + int err = EMAIL_ERROR_NONE; + + file = em_malloc(sizeof(struct attachment_info)); + if (file == NULL) { + EM_DEBUG_EXCEPTION("em_malloc failed..."); + goto FINISH_OFF; + } + + file->type = content_disposition_type; + if (disposition_filename) file->name = g_strdup(disposition_filename); + else if (ctype_name) file->name = g_strdup(ctype_name); + else if (content_id) file->name = g_strdup(content_id); + else file->name = g_strdup("unknown-attachment"); + + file->content_id = g_strdup(content_id); + + if (!(utf8_text = g_mime_utils_header_decode_text(file->name))) { + EM_DEBUG_EXCEPTION("g_mime_utils_header_decode_text failed [%d]", err); + } + EM_DEBUG_LOG_SEC("utf8_text : [%s]", utf8_text); + + if (utf8_text) { + EM_SAFE_FREE(file->name); + file->name = EM_SAFE_STRDUP(utf8_text); + } + EM_SAFE_FREE(utf8_text); + + if(ctype_type && ctype_subtype) { + char mime_type_buffer[128] = {0,}; + snprintf(mime_type_buffer, sizeof(mime_type_buffer), "%s/%s", ctype_type, ctype_subtype); + file->attachment_mime_type = g_strdup(mime_type_buffer); + } + + file->save = g_strdup(content_path); + if (real_size == 0 && ctype_size) + file->size = atoi(ctype_size); + else + file->size = real_size; + file->save_status = 1; + + if (ctype_type && g_ascii_strcasecmp(ctype_type, "APPLICATION") == 0) { + if (ctype_subtype && g_ascii_strcasecmp(ctype_subtype, MIME_SUBTYPE_DRM_OBJECT) == 0) + file->drm = EMAIL_ATTACHMENT_DRM_OBJECT; + else if (ctype_subtype && g_ascii_strcasecmp(ctype_subtype, MIME_SUBTYPE_DRM_RIGHTS) == 0) + file->drm = EMAIL_ATTACHMENT_DRM_RIGHTS; + else if (ctype_subtype && g_ascii_strcasecmp(ctype_subtype, MIME_SUBTYPE_DRM_DCF) == 0) + file->drm = EMAIL_ATTACHMENT_DRM_DCF; + } + + while (temp_file && temp_file->next) + temp_file = temp_file->next; + + if (temp_file == NULL) + cnt_info->file = file; + else + temp_file->next = file; + } + + EM_SAFE_FREE(content_path); + } + +FINISH_OFF: + + EM_SAFE_FREE(content_path); + EM_DEBUG_FUNC_END(); +} + +INTERNAL_FUNC void emcore_gmime_imap_parse_bodystructure_foreach_cb(GMimeObject *parent, GMimeObject *part, gpointer user_data) +{ + EM_DEBUG_FUNC_BEGIN("parent[%p], part[%p], user_data[%p]", parent, part, user_data); + + int error = EMAIL_ERROR_NONE; + struct _m_content_info *cnt_info = (struct _m_content_info *)user_data; + + if (GMIME_IS_MESSAGE_PART(part)) { + GMimeMessage *message = NULL; + GMimeContentType *msg_ctype = NULL; + GMimeContentDisposition *msg_disposition = NULL; + char *msg_ctype_type = NULL; + char *msg_ctype_subtype = NULL; + char *msg_ctype_size = NULL; + char *msg_disposition_str = NULL; + unsigned long msg_content_size = 0; + EM_DEBUG_LOG("Message Part"); + + message = g_mime_message_part_get_message((GMimeMessagePart *)part); + if (!message) { + EM_DEBUG_EXCEPTION("Message is NULL"); + //goto FINISH_OFF; + } + + /*Content Type*/ + msg_ctype = g_mime_object_get_content_type(part); + msg_ctype_type = (char *)g_mime_content_type_get_media_type(msg_ctype); + msg_ctype_subtype = (char *)g_mime_content_type_get_media_subtype(msg_ctype); + msg_ctype_size = (char *)g_mime_content_type_get_parameter(msg_ctype, "message_size"); + EM_DEBUG_LOG("Content-Type[%s/%s]", msg_ctype_type, msg_ctype_subtype); + EM_DEBUG_LOG("Part.size.bytes[%s]", msg_ctype_size); + + if (msg_ctype_size) msg_content_size = atol(msg_ctype_size); + cnt_info->total_mail_size += msg_content_size; + /*Content Type - END*/ + + /*Content Disposition*/ + msg_disposition = g_mime_object_get_content_disposition(part); + if (msg_disposition) { + msg_disposition_str = (char *)g_mime_content_disposition_get_disposition(msg_disposition); + } + EM_DEBUG_LOG("RFC822/Message Disposition[%s]", msg_disposition_str); + /*Content Disposition - END*/ + + if (msg_disposition_str && g_ascii_strcasecmp(msg_disposition_str, GMIME_DISPOSITION_ATTACHMENT) == 0) { + EM_DEBUG_LOG("RFC822/Message is ATTACHMENT"); + cnt_info->total_attachment_size += msg_content_size; + } + + //g_mime_message_foreach(message, emcore_gmime_imap_parse_bodystructure_foreach_cb, user_data); + } else if (GMIME_IS_MESSAGE_PARTIAL(part)) { + EM_DEBUG_LOG("Partial Part"); + //TODO + } else if (GMIME_IS_MULTIPART(part)) { + EM_DEBUG_LOG("Multi Part"); + GMimeMultipart *multi_part = NULL; + multi_part = (GMimeMultipart *)part; + + int multi_count = g_mime_multipart_get_count(multi_part); + EM_DEBUG_LOG("Multi Part Count:%d", multi_count); + EM_DEBUG_LOG("Boundary:%s\n\n", g_mime_multipart_get_boundary(multi_part)); + + } else if (GMIME_IS_PART(part)) { + EM_DEBUG_LOG("Part"); + int content_disposition_type = 0; + char *content_id = NULL; + char *content_location = NULL; + char *disposition_str = NULL; + char *disposition_filename = NULL; + char *ctype_type = NULL; + char *ctype_subtype = NULL; + char *ctype_charset = NULL; + char *ctype_name = NULL; + char *ctype_size = NULL; + unsigned long content_size = 0; + + GMimeContentType *ctype = NULL; + GMimeContentDisposition *disposition = NULL; + GMimePart *leaf_part = NULL; + GMimeObject *mobject = (GMimeObject *)part; + leaf_part = (GMimePart *)part; + + /*Content Type*/ + ctype = g_mime_object_get_content_type(mobject); + ctype_type = (char *)g_mime_content_type_get_media_type(ctype); + ctype_subtype = (char *)g_mime_content_type_get_media_subtype(ctype); + ctype_charset = (char *)g_mime_content_type_get_parameter(ctype, "charset"); + ctype_name = (char *)g_mime_content_type_get_parameter(ctype, "name"); + ctype_size = (char *)g_mime_content_type_get_parameter(ctype, "part_size"); + EM_DEBUG_LOG("Content-Type[%s/%s]", ctype_type, ctype_subtype); + EM_DEBUG_LOG("Content-Type-Charset[%s]", ctype_charset); + EM_DEBUG_LOG("Content-Type-Name[%s]", ctype_name); + EM_DEBUG_LOG("Part.size.bytes[%s]", ctype_size); + + if (ctype_size) content_size = atol(ctype_size); + cnt_info->total_mail_size += content_size; + /*Content Type - END*/ + + /*Content Disposition*/ + disposition = g_mime_object_get_content_disposition(mobject); + if (disposition) { + disposition_str = (char *)g_mime_content_disposition_get_disposition(disposition); + disposition_filename = (char *)g_mime_content_disposition_get_parameter(disposition, "filename"); + } + EM_DEBUG_LOG("Disposition[%s]", disposition_str); + EM_DEBUG_LOG_SEC("Disposition-Filename[%s]", disposition_filename); + /*Content Disposition - END*/ + + /*Content ID*/ + content_id = (char *)g_mime_object_get_content_id(mobject); + EM_DEBUG_LOG_SEC("Content-ID:%s", content_id); + + /*Content Location*/ + content_location = (char *)g_mime_part_get_content_location(leaf_part); + EM_DEBUG_LOG_SEC("Content-Location:%s", content_location); + + /*Figure out TEXT or ATTACHMENT(INLINE) */ + if (disposition_str && g_ascii_strcasecmp(disposition_str, GMIME_DISPOSITION_ATTACHMENT) == 0) { + content_disposition_type = ATTACHMENT; + cnt_info->total_attachment_size += content_size; + EM_DEBUG_LOG("ATTACHMENT"); + } else if ((content_id || content_location) && (ctype_name || disposition_filename)) { + if (cnt_info->attachment_only) { + content_disposition_type = ATTACHMENT; + cnt_info->total_attachment_size += content_size; + EM_DEBUG_LOG("ATTACHMENT"); + } else { + content_disposition_type = INLINE_ATTACHMENT; + cnt_info->total_body_size += content_size; + EM_DEBUG_LOG("INLINE_ATTACHMENT"); + } + } else { + if (content_id || content_location) { + if (g_ascii_strcasecmp(ctype_type, "text") == 0 && + (g_ascii_strcasecmp(ctype_subtype, "plain") == 0 || g_ascii_strcasecmp(ctype_subtype, "html") == 0)) { + cnt_info->total_body_size += content_size; + EM_DEBUG_LOG("TEXT"); + } else { + if (cnt_info->attachment_only) { + content_disposition_type = ATTACHMENT; + cnt_info->total_attachment_size += content_size; + EM_DEBUG_LOG("ATTACHMENT"); + } else { + content_disposition_type = INLINE_ATTACHMENT; + cnt_info->total_body_size += content_size; + EM_DEBUG_LOG("INLINE_ATTACHMENT"); + } + } + } else { + if (g_ascii_strcasecmp(ctype_type, "text") == 0 && + (g_ascii_strcasecmp(ctype_subtype, "plain") == 0 || g_ascii_strcasecmp(ctype_subtype, "html") == 0)) { + cnt_info->total_body_size += content_size; + EM_DEBUG_LOG("TEXT"); + } else { + content_disposition_type = ATTACHMENT; + cnt_info->total_attachment_size += content_size; + EM_DEBUG_LOG("ATTACHMENT"); + } + } + } + + if (content_disposition_type != ATTACHMENT && content_disposition_type != INLINE_ATTACHMENT) { + /*TEXT*/ + EM_DEBUG_LOG("TEXT"); + + if (ctype_type && g_ascii_strcasecmp(ctype_type, "text") == 0) { + char *tmp_file = NULL; + + if (!ctype_charset || g_ascii_strcasecmp(ctype_charset, "X-UNKNOWN") == 0) { + ctype_charset = "UTF-8"; + } + + if (!emcore_get_temp_file_name(&tmp_file, &error) || !tmp_file) { + EM_DEBUG_EXCEPTION("emcore_get_temp_file_name failed [%d]", error); + EM_SAFE_FREE(tmp_file); + goto FINISH_OFF; + } + + if (ctype_subtype && g_ascii_strcasecmp(ctype_subtype, "plain") == 0) { + EM_DEBUG_LOG("TEXT/PLAIN"); + cnt_info->text.plain_charset = g_strdup(ctype_charset); + cnt_info->text.plain = tmp_file; + } + else if (ctype_subtype && g_ascii_strcasecmp(ctype_subtype, "html") == 0) { + EM_DEBUG_LOG("TEXT/HTML"); + cnt_info->text.html_charset = g_strdup(ctype_charset); + cnt_info->text.html = tmp_file; + } + } + } + } + +FINISH_OFF: + + EM_DEBUG_FUNC_END(); +} + + +INTERNAL_FUNC void emcore_gmime_get_body_sections_foreach_cb(GMimeObject *parent, GMimeObject *part, gpointer user_data) +{ + EM_DEBUG_FUNC_BEGIN("parent[%p], part[%p], user_data[%p]", parent, part, user_data); + + struct _m_content_info *cnt_info = (struct _m_content_info *)user_data; + char sections[IMAP_MAX_COMMAND_LENGTH] = {0,}; + + if (GMIME_IS_MESSAGE_PART(part)) { + EM_DEBUG_LOG("Message Part"); + + if (cnt_info->grab_type != (GRAB_TYPE_TEXT|GRAB_TYPE_ATTACHMENT)) { + EM_DEBUG_LOG("grab_type is not GRAB_TYPE_TEXT|GRAB_TYPE_ATTACHMENT"); + goto FINISH_OFF; + } + + GMimeMessage *message = NULL; + GMimeContentDisposition *msg_disposition = NULL; + GMimeContentType *msg_ctype = NULL; + char *msg_disposition_str = NULL; + char *msg_ctype_section = NULL; + + message = g_mime_message_part_get_message((GMimeMessagePart *)part); + if (!message) { + EM_DEBUG_EXCEPTION("Message is NULL"); + //goto FINISH_OFF; + } + + /*Content Disposition*/ + msg_disposition = g_mime_object_get_content_disposition(part); + if (msg_disposition) { + msg_disposition_str = (char *)g_mime_content_disposition_get_disposition(msg_disposition); + } + EM_DEBUG_LOG("RFC822/Message Disposition[%s]", msg_disposition_str); + /*Content Disposition - END*/ + + if (!msg_disposition_str || g_ascii_strcasecmp(msg_disposition_str, GMIME_DISPOSITION_ATTACHMENT) != 0) { + goto FINISH_OFF; + } + + msg_ctype = g_mime_object_get_content_type(part); + msg_ctype_section = (char *)g_mime_content_type_get_parameter(msg_ctype, "section"); + EM_DEBUG_LOG("section[%s]", msg_ctype_section); + + if (!msg_ctype_section) { + EM_DEBUG_LOG("section is NULL"); + goto FINISH_OFF; + } + + snprintf(sections, sizeof(sections), "BODY.PEEK[%s]", msg_ctype_section); + + EM_DEBUG_LOG("sections <%s>", sections); + + if (cnt_info->sections) { + char *tmp_str = NULL; + tmp_str = g_strconcat(cnt_info->sections, " ", sections, NULL); + + if (tmp_str) { + EM_SAFE_FREE(cnt_info->sections); + cnt_info->sections = tmp_str; + } + } + else { + cnt_info->sections = EM_SAFE_STRDUP(sections); + } + + EM_DEBUG_LOG("sections <%s>", cnt_info->sections); + } else if (GMIME_IS_MESSAGE_PARTIAL(part)) { + EM_DEBUG_LOG("Partial Part"); + } else if (GMIME_IS_MULTIPART(part)) { + EM_DEBUG_LOG("Multi Part"); + } else if (GMIME_IS_PART(part)) { + EM_DEBUG_LOG("Part"); + int content_disposition_type = 0; + char *content_id = NULL; + char *content_location = NULL; + char *disposition_str = NULL; + char *disposition_filename = NULL; + char *ctype_type = NULL; + char *ctype_subtype = NULL; + char *ctype_name = NULL; + char *ctype_section = NULL; + + GMimeContentType *ctype = NULL; + GMimeContentDisposition *disposition = NULL; + GMimePart *leaf_part = NULL; + GMimeObject *mobject = (GMimeObject *)part; + leaf_part = (GMimePart *)part; + + /*Content Type*/ + ctype = g_mime_object_get_content_type(mobject); + ctype_type = (char *)g_mime_content_type_get_media_type(ctype); + ctype_subtype = (char *)g_mime_content_type_get_media_subtype(ctype); + ctype_name = (char *)g_mime_content_type_get_parameter(ctype, "name"); + ctype_section = (char *)g_mime_content_type_get_parameter(ctype, "section"); + EM_DEBUG_LOG("Content-Type-Name[%s]", ctype_name); + EM_DEBUG_LOG("Content-Type-Section[%s]", ctype_section); + + if (!ctype_section) { + EM_DEBUG_LOG("section is NULL"); + goto FINISH_OFF; + } + /*Content Type - END*/ + + /*Content Disposition*/ + disposition = g_mime_object_get_content_disposition(mobject); + if (disposition) { + disposition_str = (char *)g_mime_content_disposition_get_disposition(disposition); + disposition_filename = (char *)g_mime_content_disposition_get_parameter(disposition, "filename"); + } + EM_DEBUG_LOG("Disposition[%s]", disposition_str); + EM_DEBUG_LOG_SEC("Disposition-Filename[%s]", disposition_filename); + /*Content Disposition - END*/ + + /*Content ID*/ + content_id = (char *)g_mime_object_get_content_id(mobject); + EM_DEBUG_LOG_SEC("Content-ID:%s", content_id); + + /*Content Location*/ + content_location = (char *)g_mime_part_get_content_location(leaf_part); + EM_DEBUG_LOG_SEC("Content-Location:%s", content_location); + + /*Figure out TEXT or ATTACHMENT(INLINE) */ + if (disposition_str && g_ascii_strcasecmp(disposition_str, GMIME_DISPOSITION_ATTACHMENT) == 0) { + content_disposition_type = ATTACHMENT; + EM_DEBUG_LOG("ATTACHMENT"); + } else if ((content_id || content_location) && (ctype_name || disposition_filename)) { + if (cnt_info->attachment_only) { + content_disposition_type = ATTACHMENT; + EM_DEBUG_LOG("ATTACHMENT"); + } else { + content_disposition_type = INLINE_ATTACHMENT; + EM_DEBUG_LOG("INLINE_ATTACHMENT"); + } + } else { + if (content_id || content_location) { + if (g_ascii_strcasecmp(ctype_type, "text") == 0 && + (g_ascii_strcasecmp(ctype_subtype, "plain") == 0 || g_ascii_strcasecmp(ctype_subtype, "html") == 0)) { + EM_DEBUG_LOG("TEXT"); + } else { + if (cnt_info->attachment_only) { + content_disposition_type = ATTACHMENT; + EM_DEBUG_LOG("ATTACHMENT"); + } else { + content_disposition_type = INLINE_ATTACHMENT; + EM_DEBUG_LOG("INLINE_ATTACHMENT"); + } + } + } else { + if (g_ascii_strcasecmp(ctype_type, "text") == 0 && + (g_ascii_strcasecmp(ctype_subtype, "plain") == 0 || g_ascii_strcasecmp(ctype_subtype, "html") == 0)) { + EM_DEBUG_LOG("TEXT"); + } else { + content_disposition_type = ATTACHMENT; + EM_DEBUG_LOG("ATTACHMENT"); + } + } + } + + if (content_disposition_type == ATTACHMENT) { + EM_DEBUG_LOG("ATTACHMENT"); + + if (cnt_info->grab_type != (GRAB_TYPE_TEXT|GRAB_TYPE_ATTACHMENT)) + goto FINISH_OFF; + } + else { + snprintf(sections, sizeof(sections), "BODY.PEEK[%s.MIME] BODY.PEEK[%s]", ctype_section, ctype_section); + + if (cnt_info->sections) { + char *tmp_str = NULL; + tmp_str = g_strconcat(cnt_info->sections, " ", sections, NULL); + + if (tmp_str) { + EM_SAFE_FREE(cnt_info->sections); + cnt_info->sections = tmp_str; + } + } + else { + cnt_info->sections = EM_SAFE_STRDUP(sections); + } + + EM_DEBUG_LOG("sections <%s>", cnt_info->sections); + } + } + +FINISH_OFF: + + EM_DEBUG_FUNC_END(); +} + + +INTERNAL_FUNC void emcore_gmime_get_attachment_section_foreach_cb(GMimeObject *parent, GMimeObject *part, gpointer user_data) +{ + EM_DEBUG_FUNC_BEGIN("parent[%p], part[%p], user_data[%p]", parent, part, user_data); + + struct _m_content_info *cnt_info = (struct _m_content_info *)user_data; + char sections[IMAP_MAX_COMMAND_LENGTH] = {0,}; + + if (GMIME_IS_MESSAGE_PART(part)) { + EM_DEBUG_LOG("Message Part"); + + if (cnt_info->grab_type != GRAB_TYPE_ATTACHMENT) { + EM_DEBUG_LOG("grab_type is not GRAB_TYPE_ATTACHMENT"); + goto FINISH_OFF; + } + + GMimeMessage *message = NULL; + GMimeContentDisposition *msg_disposition = NULL; + GMimeContentType *msg_ctype = NULL; + char *msg_disposition_str = NULL; + char *msg_ctype_section = NULL; + + message = g_mime_message_part_get_message((GMimeMessagePart *)part); + if (!message) { + EM_DEBUG_EXCEPTION("Message is NULL"); + //goto FINISH_OFF; + } + + /*Content Disposition*/ + msg_disposition = g_mime_object_get_content_disposition(part); + if (msg_disposition) { + msg_disposition_str = (char *)g_mime_content_disposition_get_disposition(msg_disposition); + } + EM_DEBUG_LOG("RFC822/Message Disposition[%s]", msg_disposition_str); + /*Content Disposition - END*/ + + if (!msg_disposition_str || g_ascii_strcasecmp(msg_disposition_str, GMIME_DISPOSITION_ATTACHMENT) != 0) { + goto FINISH_OFF; + } + + if (--cnt_info->file_no != 0) + goto FINISH_OFF; + + msg_ctype = g_mime_object_get_content_type(part); + msg_ctype_section = (char *)g_mime_content_type_get_parameter(msg_ctype, "section"); + EM_DEBUG_LOG("section[%s]", msg_ctype_section); + + if (!msg_ctype_section) { + EM_DEBUG_LOG("section is NULL"); + goto FINISH_OFF; + } + + snprintf(sections, sizeof(sections), "%s", msg_ctype_section); + + EM_DEBUG_LOG("sections <%s>", sections); + + if (!cnt_info->sections) { + cnt_info->sections = EM_SAFE_STRDUP(sections); + } + + EM_DEBUG_LOG("sections <%s>", cnt_info->sections); + } else if (GMIME_IS_MESSAGE_PARTIAL(part)) { + EM_DEBUG_LOG("Partial Part"); + } else if (GMIME_IS_MULTIPART(part)) { + EM_DEBUG_LOG("Multi Part"); + } else if (GMIME_IS_PART(part)) { + EM_DEBUG_LOG("Part"); + int content_disposition_type = 0; + char *content_id = NULL; + char *content_location = NULL; + char *disposition_str = NULL; + char *disposition_filename = NULL; + char *ctype_type = NULL; + char *ctype_subtype = NULL; + char *ctype_name = NULL; + char *ctype_section = NULL; + + GMimeContentType *ctype = NULL; + GMimeContentDisposition *disposition = NULL; + GMimePart *leaf_part = NULL; + GMimeObject *mobject = (GMimeObject *)part; + leaf_part = (GMimePart *)part; + + if (cnt_info->grab_type != GRAB_TYPE_ATTACHMENT) { + EM_DEBUG_LOG("grab_type is not GRAB_TYPE_ATTACHMENT"); + goto FINISH_OFF; + } + + /*Content Type*/ + ctype = g_mime_object_get_content_type(mobject); + ctype_type = (char *)g_mime_content_type_get_media_type(ctype); + ctype_subtype = (char *)g_mime_content_type_get_media_subtype(ctype); + ctype_name = (char *)g_mime_content_type_get_parameter(ctype, "name"); + ctype_section = (char *)g_mime_content_type_get_parameter(ctype, "section"); + EM_DEBUG_LOG("Content-Type-Name[%s]", ctype_name); + EM_DEBUG_LOG("Content-Type-Section[%s]", ctype_section); + + if (!ctype_section) { + EM_DEBUG_LOG("section is NULL"); + goto FINISH_OFF; + } + /*Content Type - END*/ + + /*Content Disposition*/ + disposition = g_mime_object_get_content_disposition(mobject); + if (disposition) { + disposition_str = (char *)g_mime_content_disposition_get_disposition(disposition); + disposition_filename = (char *)g_mime_content_disposition_get_parameter(disposition, "filename"); + } + EM_DEBUG_LOG("Disposition[%s]", disposition_str); + EM_DEBUG_LOG("Disposition-Filename[%s]", disposition_filename); + /*Content Disposition - END*/ + + /*Content ID*/ + content_id = (char *)g_mime_object_get_content_id(mobject); + EM_DEBUG_LOG_SEC("Content-ID:%s", content_id); + + /*Content Location*/ + content_location = (char *)g_mime_part_get_content_location(leaf_part); + EM_DEBUG_LOG_SEC("Content-Location:%s", content_location); + + /*Figure out TEXT or ATTACHMENT(INLINE) */ + if (disposition_str && g_ascii_strcasecmp(disposition_str, GMIME_DISPOSITION_ATTACHMENT) == 0) { + content_disposition_type = ATTACHMENT; + EM_DEBUG_LOG("ATTACHMENT"); + } else if ((content_id || content_location) && (ctype_name || disposition_filename)) { + if (cnt_info->attachment_only) { + content_disposition_type = ATTACHMENT; + EM_DEBUG_LOG("ATTACHMENT"); + } else { + content_disposition_type = INLINE_ATTACHMENT; + EM_DEBUG_LOG("INLINE_ATTACHMENT"); + } + } else { + if (content_id || content_location) { + if (g_ascii_strcasecmp(ctype_type, "text") == 0 && + (g_ascii_strcasecmp(ctype_subtype, "plain") == 0 || g_ascii_strcasecmp(ctype_subtype, "html") == 0)) { + EM_DEBUG_LOG("TEXT"); + } else { + if (cnt_info->attachment_only) { + content_disposition_type = ATTACHMENT; + EM_DEBUG_LOG("ATTACHMENT"); + } else { + content_disposition_type = INLINE_ATTACHMENT; + EM_DEBUG_LOG("INLINE_ATTACHMENT"); + } + } + } else { + if (g_ascii_strcasecmp(ctype_type, "text") == 0 && + (g_ascii_strcasecmp(ctype_subtype, "plain") == 0 || g_ascii_strcasecmp(ctype_subtype, "html") == 0)) { + EM_DEBUG_LOG("TEXT"); + } else { + content_disposition_type = ATTACHMENT; + EM_DEBUG_LOG("ATTACHMENT"); + } + } + } + + if (content_disposition_type == ATTACHMENT) { + EM_DEBUG_LOG("ATTACHMENT"); + + if (--cnt_info->file_no != 0) + goto FINISH_OFF; + + snprintf(sections, sizeof(sections), "%s", ctype_section); + + if (!cnt_info->sections) { + cnt_info->sections = EM_SAFE_STRDUP(sections); + } + + EM_DEBUG_LOG("sections <%s>", cnt_info->sections); + } + } + +FINISH_OFF: + + EM_DEBUG_FUNC_END(); +} + +INTERNAL_FUNC void emcore_gmime_search_section_foreach_cb(GMimeObject *parent, GMimeObject *part, gpointer user_data) +{ + EM_DEBUG_FUNC_BEGIN(); + + search_section *search_info = (search_section *)user_data; + GMimeContentType *ctype = NULL; + char buf[255] = {0}; + char *ctype_section = NULL; + + if (!search_info) { + EM_DEBUG_LOG("search_info is NULL"); + goto FINISH_OFF; + } + + if (!part) { + EM_DEBUG_LOG("part is NULL"); + goto FINISH_OFF; + } + + if (GMIME_IS_MESSAGE_PART(part)) { + EM_DEBUG_LOG("Message Part"); + } else if (GMIME_IS_MESSAGE_PARTIAL(part)) { + EM_DEBUG_LOG("Partial Part"); + } else if (GMIME_IS_MULTIPART(part)) { + EM_DEBUG_LOG("Multi Part"); + } else if (GMIME_IS_PART(part)) { + EM_DEBUG_LOG("Part"); + } + + ctype = g_mime_object_get_content_type(part); + ctype_section = (char *)g_mime_content_type_get_parameter(ctype, "section"); + EM_DEBUG_LOG("section[%s]", ctype_section); + + if (!ctype_section) { + EM_DEBUG_LOG("section is NULL"); + goto FINISH_OFF; + } + + SNPRINTF(buf, sizeof(buf), "%s.MIME", ctype_section); + + if (g_ascii_strcasecmp(ctype_section, search_info->section) == 0) { + EM_DEBUG_LOG("found section"); + if (!(search_info->section_object)) search_info->section_object = part; + } else if (g_ascii_strcasecmp(search_info->section, buf) == 0) { + EM_DEBUG_LOG("Mime header"); + if (!(search_info->section_object)) search_info->section_object = part; + } + +FINISH_OFF: + + EM_DEBUG_FUNC_END(); +} + +INTERNAL_FUNC void emcore_gmime_construct_multipart (GMimeMultipart *multipart, + BODY *body, const char *spec, int *total_mail_size) +{ + EM_DEBUG_FUNC_BEGIN(); + PART *part = NULL; + GMimeObject *subpart = NULL; + GMimeMultipart *sub_multipart = NULL; + GMimeMessagePart *sub_messagepart = NULL; + GMimeMessage *sub_message = NULL; + GMimePart *sub_part = NULL; + char *subspec = NULL; + char *id = NULL; + char *section = NULL; + int i = 1; + + if (!body || !multipart || !spec) { + EM_DEBUG_EXCEPTION("body[%p], multipart[%p], spec[%p]", body, multipart, spec); + return; + } + + subspec = g_alloca (strlen(spec) + 14); + id = g_stpcpy(subspec, spec); + *id++ = '.'; + + EM_DEBUG_LOG("constructing a %s/%s part (%s)", body_types[body->type], + body->subtype, spec); + + /* checkout boundary */ + if (body->parameter) { + PARAMETER *param = body->parameter; + while(param) { + EM_DEBUG_LOG("Content-Type Parameter: attribute[%s], value[%s]", param->attribute, param->value); + param = param->next; + } + } + + part = body->nested.part; + + while (part != NULL) { + sprintf (id, "%d", i++); + + if (EM_SAFE_STRLEN(subspec) > 2) + section = EM_SAFE_STRDUP(subspec+2); + + EM_DEBUG_LOG("constructing a %s/%s part (%s/%s)", body_types[part->body.type], + part->body.subtype, subspec, section); + + if (part->body.type == TYPEMULTIPART) { + /*multipart*/ + char *subtype = g_ascii_strdown(part->body.subtype, -1); + sub_multipart = g_mime_multipart_new_with_subtype(subtype); + EM_SAFE_FREE(subtype); + emcore_gmime_construct_multipart(sub_multipart, &(part->body), subspec, total_mail_size); + + subpart = GMIME_OBJECT(sub_multipart); + } else if (part->body.type == TYPEMESSAGE) { + /*message/rfc822 or message/news*/ + BODY *nested_body = NULL; + MESSAGE *nested_message = NULL; + char *subtype = g_ascii_strdown(part->body.subtype, -1); + sub_messagepart = g_mime_message_part_new(subtype); + EM_SAFE_FREE(subtype); + + subpart = GMIME_OBJECT(sub_messagepart); + + if (part->body.size.bytes > 0) { + char size_str[sizeof(unsigned long)*8+1] = {0,}; + snprintf(size_str, sizeof(size_str), "%lu", part->body.size.bytes); + g_mime_object_set_content_type_parameter(subpart, "message_size", size_str); + } + + nested_message = part->body.nested.msg; + if (nested_message) nested_body = nested_message->body; + + if (!emcore_gmime_construct_mime_part_with_bodystructure(nested_body, &sub_message, subspec, NULL)) { + EM_DEBUG_EXCEPTION("emcore_gmime_construct_mime_part_with_bodystructure failed"); + } else { + g_mime_message_part_set_message(sub_messagepart, sub_message); + if (sub_message) g_object_unref(sub_message); + } + } else { + /*other parts*/ + char *type = g_ascii_strdown(body_types[part->body.type], -1); + char *subtype = g_ascii_strdown(part->body.subtype, -1); + sub_part = g_mime_part_new_with_type(type, subtype); + EM_SAFE_FREE(type); + EM_SAFE_FREE(subtype); + subpart = GMIME_OBJECT(sub_part); + + if (total_mail_size != NULL) { + *total_mail_size = *total_mail_size + (int)part->body.size.bytes; + EM_DEBUG_LOG("body.size.bytes [%d]", part->body.size.bytes); + EM_DEBUG_LOG("total_mail_size [%d]", *total_mail_size); + } + + /* encoding */ + if (part->body.encoding <= 5) { + EM_DEBUG_LOG("Content Encoding: %s", body_encodings[part->body.encoding]); + GMimeContentEncoding encoding = GMIME_CONTENT_ENCODING_DEFAULT; + switch(part->body.encoding) { + case ENC7BIT: + encoding = GMIME_CONTENT_ENCODING_7BIT; + break; + case ENC8BIT: + encoding = GMIME_CONTENT_ENCODING_8BIT; + break; + case ENCBINARY: + encoding = GMIME_CONTENT_ENCODING_BINARY; + break; + case ENCBASE64: + encoding = GMIME_CONTENT_ENCODING_BASE64; + break; + case ENCQUOTEDPRINTABLE: + encoding = GMIME_CONTENT_ENCODING_QUOTEDPRINTABLE; + break; + case ENCOTHER: + encoding = GMIME_CONTENT_ENCODING_DEFAULT; + break; + + default: + break; + } + g_mime_part_set_content_encoding(sub_part, encoding); + } + + /* content description */ + if (part->body.description) { + EM_DEBUG_LOG("Content-Description: %s", part->body.description); + g_mime_part_set_content_description(sub_part, part->body.description); + } + + /* content location */ + if (part->body.location) { + EM_DEBUG_LOG_SEC("Content-Location: %s", part->body.location); + g_mime_part_set_content_location(sub_part, part->body.location); + } + + /* md5 */ + if (part->body.md5) { + EM_DEBUG_LOG("Content-MD5: %s", part->body.md5); + g_mime_part_set_content_md5(sub_part, part->body.md5); + } + + if (part->body.size.bytes > 0) { + char size_str[sizeof(unsigned long)*8+1] = {0,}; + snprintf(size_str, sizeof(size_str), "%lu", part->body.size.bytes); + g_mime_object_set_content_type_parameter(subpart, "part_size", size_str); + } + } + + /* content type */ + if (part->body.parameter) { + PARAMETER *param = part->body.parameter; + while(param) { + EM_DEBUG_LOG_SEC("Content-Type Parameter: attribute[%s], value[%s]", param->attribute, param->value); + if (param->attribute || param->value) + g_mime_object_set_content_type_parameter(subpart, param->attribute, param->value); + param = param->next; + } + } + g_mime_object_set_content_type_parameter(subpart, "section", section); + + /* content disposition */ + if (part->body.disposition.type) { + EM_DEBUG_LOG("Content-Disposition: %s", part->body.disposition.type); + char *disposition_type = g_ascii_strdown(part->body.disposition.type, -1); + g_mime_object_set_disposition(subpart, disposition_type); + g_free(disposition_type); + } + + if (part->body.disposition.parameter) { + PARAMETER *param = part->body.disposition.parameter; + while(param) { + EM_DEBUG_LOG_SEC("Content-Disposition Parameter: attribute[%s], value[%s]", param->attribute, param->value); + if (param->attribute || param->value) + g_mime_object_set_content_disposition_parameter(subpart, param->attribute, param->value); + param = param->next; + } + } + + /* content id */ + if (part->body.id) { + EM_DEBUG_LOG_SEC("Content-ID: %s", part->body.id); + int i = 0; + char *cid = EM_SAFE_STRDUP(part->body.id); + g_strstrip(cid); + + while (strlen(cid) > 0 && cid[i] != '\0') { + if (cid[i] == '<' || cid[i] == '>') + cid[i] = ' '; + i++; + } + + g_strstrip(cid); + EM_DEBUG_LOG_DEV("Content-ID stripped: %s", cid); + g_mime_object_set_content_id(subpart, cid); + EM_SAFE_FREE(cid); + } + + g_mime_multipart_add (multipart, subpart); + + if (subpart) { + g_object_unref (subpart); + subpart = NULL; + } + + EM_SAFE_FREE(section); + + part = part->next; + } + EM_DEBUG_FUNC_END(); +} + +INTERNAL_FUNC void emcore_gmime_construct_part (GMimePart *part, + BODY *body, const char *spec, int *total_mail_size) +{ + EM_DEBUG_FUNC_BEGIN(); + GMimeObject *part_object = NULL; + + if (!body || !part || !spec) { + EM_DEBUG_EXCEPTION("body[%p], part[%p] spec[%p]", body, part, spec); + return; + } + + part_object = GMIME_OBJECT(part); + + if (total_mail_size != NULL) { + *total_mail_size = (int)(body->size.bytes); + EM_DEBUG_LOG("total_mail_size [%d]", *total_mail_size); + } + + GMimeContentType *ctype = NULL; + char *ctype_type = NULL; + char *ctype_subtype = NULL; + ctype = g_mime_object_get_content_type(GMIME_OBJECT(part)); + ctype_type = (char *)g_mime_content_type_get_media_type(ctype); + ctype_subtype = (char *)g_mime_content_type_get_media_subtype(ctype); + + /* Type-Subtype */ + if (g_strcmp0(ctype_type, "text") == 0 && g_strcmp0(ctype_subtype, "plain") == 0 && + body->type >= 0 && body->subtype) { + GMimeContentType *content_type = NULL; + char *type = g_ascii_strdown(body_types[body->type], -1); + char *subtype = g_ascii_strdown(body->subtype, -1); + EM_DEBUG_LOG("Content Type: [%s/%s]", type, subtype); + + content_type = g_mime_content_type_new(type, subtype); + g_mime_object_set_content_type(GMIME_OBJECT(part), content_type); + g_object_unref(content_type); + + EM_SAFE_FREE(type); + EM_SAFE_FREE(subtype); + } + + /* encoding */ + if (body->encoding <= 5) { + EM_DEBUG_LOG("Content Encoding: %s", body_encodings[body->encoding]); + GMimeContentEncoding encoding = GMIME_CONTENT_ENCODING_DEFAULT; + switch(body->encoding) { + case ENC7BIT: + encoding = GMIME_CONTENT_ENCODING_7BIT; + break; + case ENC8BIT: + encoding = GMIME_CONTENT_ENCODING_8BIT; + break; + case ENCBINARY: + encoding = GMIME_CONTENT_ENCODING_BINARY; + break; + case ENCBASE64: + encoding = GMIME_CONTENT_ENCODING_BASE64; + break; + case ENCQUOTEDPRINTABLE: + encoding = GMIME_CONTENT_ENCODING_QUOTEDPRINTABLE; + break; + case ENCOTHER: + encoding = GMIME_CONTENT_ENCODING_DEFAULT; + break; + + default: + break; + } + g_mime_part_set_content_encoding(part, encoding); + } + + /* content description */ + if (body->description) { + EM_DEBUG_LOG("Content-Description: %s", body->description); + g_mime_part_set_content_description(part, body->description); + } + + /* content location */ + if (body->location) { + EM_DEBUG_LOG_SEC("Content-Location: %s", body->location); + g_mime_part_set_content_location(part, body->location); + } + + /* md5 */ + if (body->md5) { + EM_DEBUG_LOG("Content-MD5: %s", body->md5); + g_mime_part_set_content_md5(part, body->md5); + } + + /* content type */ + if (body->parameter) { + PARAMETER *param = body->parameter; + while(param) { + EM_DEBUG_LOG("Content-Type Parameter: attribute[%s], value[%s]", param->attribute, param->value); + if (param->attribute || param->value) + g_mime_object_set_content_type_parameter(part_object, param->attribute, param->value); + param = param->next; + } + } + + if (body->size.bytes > 0) { + char size_str[sizeof(unsigned long)*8+1] = {0,}; + snprintf(size_str, sizeof(size_str), "%lu", body->size.bytes); + g_mime_object_set_content_type_parameter(part_object, "part_size", size_str); + } + + if (g_strcmp0(spec, "1") == 0) + g_mime_object_set_content_type_parameter(part_object, "section", spec); + else { + if (EM_SAFE_STRLEN(spec) > 2) { + char *tmp = EM_SAFE_STRDUP(spec+2); + g_mime_object_set_content_type_parameter(part_object, "section", tmp); + EM_SAFE_FREE(tmp); + } + } + + /* content disposition */ + if (body->disposition.type) { + EM_DEBUG_LOG("Content-Disposition: %s", body->disposition.type); + char *disposition_type = g_ascii_strdown(body->disposition.type, -1); + g_mime_object_set_disposition(part_object, disposition_type); + g_free(disposition_type); + } + + if (body->disposition.parameter) { + PARAMETER *param = body->disposition.parameter; + while(param) { + EM_DEBUG_LOG("Content-Disposition Parameter: attribute[%s], value[%s]", param->attribute, param->value); + if (param->attribute || param->value) + g_mime_object_set_content_disposition_parameter(part_object, param->attribute, param->value); + param = param->next; + } + } + + /* content id */ + if (body->id) { + EM_DEBUG_LOG("Content-ID: %s", body->id); + int i = 0; + char *cid = EM_SAFE_STRDUP(body->id); + g_strstrip(cid); + + while (strlen(cid) > 0 && cid[i] != '\0') { + if (cid[i] == '<' || cid[i] == '>') + cid[i] = ' '; + i++; + } + + g_strstrip(cid); + EM_DEBUG_LOG_DEV("Content-ID stripped: %s", cid); + g_mime_object_set_content_id(part_object, cid); + EM_SAFE_FREE(cid); + } + + EM_DEBUG_FUNC_END(); +} + +INTERNAL_FUNC int emcore_gmime_construct_mime_part_with_bodystructure(BODY *mbody, + GMimeMessage **message, const char *spec, int *total_mail_size) +{ + EM_DEBUG_FUNC_BEGIN(); + + GMimeMessage *message1 = NULL; + GMimeObject *mime_part = NULL; + GMimeMultipart *multipart = NULL; + GMimePart *singlepart = NULL; + int total_size = 0; + int ret = FALSE; + + if (!mbody || !message) { + EM_DEBUG_EXCEPTION("body[%p], message[%p]", mbody, message); + return ret; + } + + message1 = g_mime_message_new(FALSE); + + /* Construct mime_part of GMimeMessage */ + if (g_ascii_strcasecmp(body_types[mbody->type], "multipart") == 0) { + /* checkout boundary */ + int boundary_ok = 0; + if (mbody->parameter) { + PARAMETER *param = mbody->parameter; + while(param) { + EM_DEBUG_LOG("Content-Type Parameter: attribute[%s], value[%s]", param->attribute, param->value); + if (g_ascii_strcasecmp(param->attribute, "boundary") == 0 && param->value) + boundary_ok = 1; + param = param->next; + } + } + + if (!boundary_ok) { + EM_DEBUG_EXCEPTION("boundary is not exist in bodystructure"); + goto FINISH_OFF; + } + + char *subtype = g_ascii_strdown(mbody->subtype, -1); + multipart = g_mime_multipart_new_with_subtype(subtype); + + /* Fill up mime part of message1 using bodystructure info */ + emcore_gmime_construct_multipart(multipart, mbody, spec, &total_size); + + mime_part = GMIME_OBJECT(multipart); + EM_SAFE_FREE(subtype); + } + else { + char *type = g_ascii_strdown(body_types[mbody->type], -1); + char *subtype = g_ascii_strdown(mbody->subtype, -1); + singlepart = g_mime_part_new_with_type(type, subtype); + + emcore_gmime_construct_part(singlepart, mbody, spec, &total_size); + + mime_part = GMIME_OBJECT(singlepart); + EM_SAFE_FREE(type); + EM_SAFE_FREE(subtype); + } + + g_mime_message_set_mime_part(message1, mime_part); + if (mime_part) g_object_unref(mime_part); + + ret = TRUE; + +FINISH_OFF: + + if (total_mail_size) + *total_mail_size = total_size; + + if (message) + *message = message1; + + EM_DEBUG_FUNC_END(); + + return ret; +} + +INTERNAL_FUNC int emcore_gmime_get_body_sections_from_message(GMimeMessage *message, + struct _m_content_info *cnt_info, char **sections_to_fetch) +{ + EM_DEBUG_FUNC_BEGIN(); + + int ret = FALSE; + GMimePartIter *iter1 = NULL; + GMimeObject *part_tmp = NULL; + char *part_path = NULL; + char sections[IMAP_MAX_COMMAND_LENGTH] = {0,}; + + iter1 = g_mime_part_iter_new((GMimeObject *)message); + + if (!g_mime_part_iter_is_valid(iter1)) { + EM_DEBUG_EXCEPTION("Part iterator is not valid"); + goto FINISH_OFF; + } + + do { + part_tmp = g_mime_part_iter_get_current(iter1); + if (part_tmp && GMIME_IS_PART(part_tmp)) { + GMimeObject *mobject = (GMimeObject *)part_tmp; + GMimeContentDisposition *disposition = NULL; + char *disposition_str = NULL; + + /*Content Disposition*/ + disposition = g_mime_object_get_content_disposition(mobject); + if (disposition) { + disposition_str = (char *)g_mime_content_disposition_get_disposition(disposition); + } + EM_DEBUG_LOG("Disposition[%s]", disposition_str); + /*Content Disposition - END*/ + + part_path = g_mime_part_iter_get_path(iter1); + + if (cnt_info->grab_type == (GRAB_TYPE_TEXT | GRAB_TYPE_ATTACHMENT)) { + char t[100] = {0,}; + snprintf(t, sizeof(t), "BODY.PEEK[%s] ", part_path); + if (EM_SAFE_STRLEN(sections) + EM_SAFE_STRLEN(t) < sizeof(sections) - 1) { + strcat(sections, t); + } + else { + EM_DEBUG_EXCEPTION("Too many body parts. IMAP command may cross 2000bytes."); + goto FINISH_OFF; + } + } + else if (cnt_info->grab_type == GRAB_TYPE_TEXT) { + if (disposition_str && g_ascii_strcasecmp(disposition_str, GMIME_DISPOSITION_ATTACHMENT) == 0) { + EM_DEBUG_LOG("ATTACHMENT"); + } else { + char t[100] = {0,}; + snprintf(t, sizeof(t), "BODY.PEEK[%s] ", part_path); + if (EM_SAFE_STRLEN(sections) + EM_SAFE_STRLEN(t) < sizeof(sections) - 1) { + strcat(sections, t); + } + else { + EM_DEBUG_EXCEPTION("Too many body parts. IMAP command may cross 2000bytes."); + goto FINISH_OFF; + } + } + } + + EM_SAFE_FREE(part_path); + } + } while (g_mime_part_iter_next(iter1)); + + if (iter1) { + g_mime_part_iter_free(iter1); + iter1 = NULL; + } + + if (EM_SAFE_STRLEN(sections) <= 0 || EM_SAFE_STRLEN(sections) >= IMAP_MAX_COMMAND_LENGTH-1) { + EM_DEBUG_EXCEPTION("Too many body parts. IMAP command may cross 2000bytes."); + goto FINISH_OFF; + } + + if (sections[EM_SAFE_STRLEN(sections)-1] == ' ') + sections[EM_SAFE_STRLEN(sections)-1] = '\0'; + + EM_DEBUG_LOG("sections <%s>", sections); + + if (g_strlcpy(*sections_to_fetch, sections, IMAP_MAX_COMMAND_LENGTH) > 0) + ret = TRUE; + +FINISH_OFF: + + if (iter1) { + g_mime_part_iter_free(iter1); + iter1 = NULL; + } + + EM_SAFE_FREE(part_path); + + EM_DEBUG_FUNC_END(); + + return ret; +} + +INTERNAL_FUNC int emcore_gmime_get_attachment_section_from_message(GMimeMessage *message, + struct _m_content_info *cnt_info, int nth, char **section_to_fetch) +{ + EM_DEBUG_FUNC_BEGIN(); + + int ret = FALSE; + int count = nth; + GMimePartIter *iter1 = NULL; + GMimeObject *part_tmp = NULL; + char *part_path = NULL; + char sections[IMAP_MAX_COMMAND_LENGTH] = {0,}; + + if (nth <= 0) { + EM_DEBUG_EXCEPTION("parameter nth is not valid"); + goto FINISH_OFF; + } + + iter1 = g_mime_part_iter_new((GMimeObject *)message); + + if (!g_mime_part_iter_is_valid(iter1)) { + EM_DEBUG_EXCEPTION("Part iterator is not valid"); + goto FINISH_OFF; + } + + do { + part_tmp = g_mime_part_iter_get_current(iter1); + if (part_tmp && GMIME_IS_PART(part_tmp)) { + GMimeObject *mobject = (GMimeObject *)part_tmp; + GMimeContentDisposition *disposition = NULL; + char *disposition_str = NULL; + + /*Content Disposition*/ + disposition = g_mime_object_get_content_disposition(mobject); + if (disposition) { + disposition_str = (char *)g_mime_content_disposition_get_disposition(disposition); + } + EM_DEBUG_LOG("Disposition[%s]", disposition_str); + /*Content Disposition - END*/ + + part_path = g_mime_part_iter_get_path(iter1); + + if (disposition_str && g_ascii_strcasecmp(disposition_str, GMIME_DISPOSITION_ATTACHMENT) == 0) { + EM_DEBUG_LOG("ATTACHMENT"); + count--; + + if (count == 0) { + char t[100] = {0,}; + snprintf(t, sizeof(t), "%s", part_path); + if (EM_SAFE_STRLEN(sections) + EM_SAFE_STRLEN(t) < sizeof(sections) - 1) { + strcat(sections, t); + } + else { + EM_DEBUG_EXCEPTION("Too many body parts. IMAP command may cross 2000bytes."); + goto FINISH_OFF; + } + } + } + + EM_SAFE_FREE(part_path); + } + } while (g_mime_part_iter_next(iter1)); + + if (iter1) { + g_mime_part_iter_free(iter1); + iter1 = NULL; + } + + EM_DEBUG_LOG("sections <%s>", sections); + + if (g_strlcpy(*section_to_fetch, sections, IMAP_MAX_COMMAND_LENGTH) > 0) + ret = TRUE; + +FINISH_OFF: + + if (iter1) { + g_mime_part_iter_free(iter1); + iter1 = NULL; + } + + EM_SAFE_FREE(part_path); + + EM_DEBUG_FUNC_END(); + + return ret; +} + +static int emcore_gmime_get_section_n_bodysize(char *response, char *section, int *body_size) +{ + char *p = NULL; + char *s = NULL; + int size = 0; + + if ((p = strstr(response, "BODY[")) /* || (p = strstr(s + 1, "BODY["))*/) { + + p += strlen("BODY["); + s = p; + + while (*s != ']') + s++; + + *s = '\0'; + strcpy(section, p); + + /* if (strcmp(section, p)) { + err = EMAIL_ERROR_INVALID_RESPONSE; + goto FINISH_OFF; + }*/ + + p = strstr(s+1, " {"); + if (p) { + p += strlen(" {"); + s = p; + + while (isdigit(*s)) + s++; + + *s = '\0'; + + size = atoi(p); + *body_size = size; + + /* sending progress noti to application. + 1. mail_id + 2. file_id + 3. bodysize + */ + } else { + return FALSE; + } } else { - g_assert_not_reached(); + return FALSE; + } + + return TRUE; +} + +INTERNAL_FUNC int emcore_gmime_fetch_imap_body_sections(MAILSTREAM *stream, int msg_uid, int mail_id, + struct _m_content_info *cnt_info, GMimeMessage *message, int event_handle, int auto_download, int *err_code) +{ + EM_DEBUG_FUNC_BEGIN("stream[%p], msg_uid[%d], cnt_info[%p], err_code[%p]", + stream, msg_uid, cnt_info, err_code); + + int err = EMAIL_ERROR_NONE; + int ret = FALSE; + + IMAPLOCAL *imaplocal = NULL; + + char tag[16] = {0,}; + char command[IMAP_MAX_COMMAND_LENGTH+100] = {0,}; + char section[16] = {0,}; + char *response = NULL; + + int server_response_yn = 0; + int body_size = 0; + + char *buf = NULL; + + unsigned char encoded[DOWNLOAD_MAX_BUFFER_SIZE] = {0,}; + unsigned char test_buffer[LOCAL_MAX_BUFFER_SIZE] = {0,}; + + int total = 0; + int flag_first_write = 1; + char *tag_position = NULL; + + int part_header = 0; + int download_interval = 0; + int download_total_size = 0; + int downloaded_size = 0; + int download_progress = 0; + int last_notified_download_size = 0; + + GMimeDataWrapper *content = NULL; + GMimeStream *content_stream = NULL; + GMimeObject *mime_object = NULL; + GMimePart *mime_part = NULL; + GMimeMessagePart *mime_message_part = NULL; + //GMimePartIter *mime_iter = NULL; + search_section *search_info = NULL; + + imaplocal = stream->local; + + if (!imaplocal || !imaplocal->netstream) { + EM_DEBUG_EXCEPTION("invalid IMAP4 stream detected..."); + err = EMAIL_ERROR_INVALID_PARAM; + goto FINISH_OFF; + } + + if (!cnt_info || !cnt_info->sections) { + EM_DEBUG_EXCEPTION("invalid parameter detected..."); + err = EMAIL_ERROR_INVALID_PARAM; + goto FINISH_OFF; + } + + SNPRINTF(tag, sizeof(tag), "%08lx", 0xffffffff & (stream->gensym++)); + SNPRINTF(command, sizeof(command), "%s UID FETCH %d (%s)\015\012", tag, msg_uid, cnt_info->sections); + EM_DEBUG_LOG("command <%s>", command); + + /* send command : get msgno/uid for all message */ + if (!net_sout(imaplocal->netstream, command, (int)EM_SAFE_STRLEN(command))) { + EM_DEBUG_EXCEPTION("net_sout failed..."); + err = EMAIL_ERROR_CONNECTION_BROKEN; + goto FINISH_OFF; + } + + while (imaplocal->netstream) { + + /* receive response */ + if (!(response = net_getline(imaplocal->netstream))) { + EM_DEBUG_EXCEPTION("net_getline failed..."); + err = EMAIL_ERROR_INVALID_RESPONSE; + goto FINISH_OFF; + } + + EM_DEBUG_LOG("response :%s", response); + + if (strstr(response, "BODY[")) { + + if (!server_response_yn) { /* start of response */ + if (response[0] != '*') { + err = EMAIL_ERROR_INVALID_RESPONSE; + EM_DEBUG_EXCEPTION("Start of response doesn't contain *"); + goto FINISH_OFF; + } + server_response_yn = 1; + } + + part_header = 0; + flag_first_write = 1; + total = 0; + memset(encoded, 0x00, sizeof(encoded)); + + if (!emcore_gmime_get_section_n_bodysize(response, section, &body_size)) { + EM_DEBUG_EXCEPTION("emcore_get_section_body_size failed [%d]", err); + err = EMAIL_ERROR_INVALID_RESPONSE; + goto FINISH_OFF; + } + EM_DEBUG_LOG("section :%s, body_size :%d", section, body_size); + + /*if (GMIME_IS_MULTIPART (message->mime_part)) { + mime_iter = g_mime_part_iter_new((GMimeObject *)message); + + if (!g_mime_part_iter_is_valid(mime_iter)) { + EM_DEBUG_EXCEPTION("Part iterator is not valid"); + goto FINISH_OFF; + } + + if (g_mime_part_iter_jump_to(mime_iter, section)) { + EM_DEBUG_LOG("g_mime_part_iter_jump_to: %s", section); + mime_object = g_mime_part_iter_get_current(mime_iter); + if (!mime_object) { + EM_DEBUG_EXCEPTION("g_mime_part_iter_get_current failed"); + goto FINISH_OFF; + } + mime_part = GMIME_PART(mime_object); + } else { + EM_DEBUG_LOG("g_mime_part_iter_jump_to: failed to jump to %s", section); + goto FINISH_OFF; + } + + if (mime_iter) { + g_mime_part_iter_free(mime_iter); + mime_iter = NULL; + } + } else if (GMIME_IS_PART (message->mime_part)) { + mime_object = message->mime_part; + mime_part = GMIME_PART(mime_object); + }*/ + + if (search_info) { + EM_SAFE_FREE(search_info->section); + EM_SAFE_FREE(search_info); + } + + if (!(search_info = em_malloc(sizeof(search_section)))) { /* prevent */ + EM_DEBUG_EXCEPTION("em_malloc failed..."); + err = EMAIL_ERROR_OUT_OF_MEMORY; + goto FINISH_OFF; + } + + search_info->section = EM_SAFE_STRDUP(section); + g_mime_message_foreach(message, emcore_gmime_search_section_foreach_cb, (gpointer)search_info); + + if (!(search_info->section_object)) { + EM_DEBUG_EXCEPTION("section search failed"); + goto FINISH_OFF; + } + + mime_message_part = NULL; + mime_part = NULL; + mime_object = search_info->section_object; + if (GMIME_IS_MESSAGE_PART(mime_object)) { + if (strcasestr(section, "MIME")) + part_header = 1; + + mime_message_part = GMIME_MESSAGE_PART(mime_object); + } else if (GMIME_IS_PART(mime_object)) { + if (strcasestr(section, "MIME")) + part_header = 1; + + mime_part = GMIME_PART(mime_object); + } else { + EM_DEBUG_EXCEPTION("invalid mime part type"); + goto FINISH_OFF; + } + + if (!part_header) { + if (!emcore_get_temp_file_name(&buf, &err) || !buf) { + EM_DEBUG_EXCEPTION("emcore_get_temp_file_name failed [%d]", err); + goto FINISH_OFF; + } + + g_mime_object_set_content_type_parameter(mime_object, "tmp_content_path", buf); + + if (event_handle > 0) + FINISH_OFF_IF_EVENT_CANCELED (err, event_handle); + + if (cnt_info->grab_type == GRAB_TYPE_TEXT) { + if (cnt_info->total_body_size > body_size) { + EM_DEBUG_LOG("Multipart body size is [%d]", cnt_info->total_body_size); + if (!auto_download) { + if (!emcore_notify_network_event(NOTI_DOWNLOAD_MULTIPART_BODY, mail_id, buf, cnt_info->total_body_size, 0)) + EM_DEBUG_EXCEPTION(" emcore_notify_network_event [ NOTI_DOWNLOAD_BODY_START] Failed >>>> "); + } + + download_interval = cnt_info->total_body_size * DOWNLOAD_NOTI_INTERVAL_PERCENT / 100; + download_total_size = cnt_info->total_body_size; + } + else { + if (!auto_download) { + if (!emcore_notify_network_event(NOTI_DOWNLOAD_BODY_START, mail_id, buf, body_size, 0)) + EM_DEBUG_EXCEPTION(" emcore_notify_network_event [ NOTI_DOWNLOAD_BODY_START] Failed >>>> "); + } + + download_interval = body_size * DOWNLOAD_NOTI_INTERVAL_PERCENT / 100; + download_total_size = body_size; + } + } + + if (cnt_info->grab_type == (GRAB_TYPE_TEXT | GRAB_TYPE_ATTACHMENT)) { + if (!auto_download) { + if (!emcore_notify_network_event(NOTI_DOWNLOAD_MULTIPART_BODY, mail_id, buf, cnt_info->total_mail_size, 0)) + EM_DEBUG_EXCEPTION(" emcore_notify_network_event [ NOTI_DOWNLOAD_BODY_START] Failed >>>> "); + } + + download_interval = cnt_info->total_mail_size * DOWNLOAD_NOTI_INTERVAL_PERCENT / 100; + download_total_size = cnt_info->total_mail_size; + } + + if (download_interval > DOWNLOAD_NOTI_INTERVAL_SIZE) { + download_interval = 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 = EMAIL_ERROR_NO_RESPONSE; + goto FINISH_OFF; + } + + if (GMIME_IS_PART(mime_object) && mime_part) { + content_stream = g_mime_stream_mem_new_with_buffer((const char *)encoded, EM_SAFE_STRLEN(encoded)); + //parser = g_mime_parser_new_with_stream(content_stream); + content = g_mime_data_wrapper_new_with_stream(content_stream, mime_part->encoding); + if (content_stream) g_object_unref (content_stream); + g_mime_part_set_content_object(mime_part, content); + if (content) g_object_unref(content); + } + else if (GMIME_IS_MESSAGE_PART(mime_object) && mime_message_part) { + FILE *fp = NULL; + int encoded_len = EM_SAFE_STRLEN((char *)encoded); + + err = em_fopen(buf, "wb+", &fp); + if (err != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION_SEC("em_fopen failed - %s", buf); + goto FINISH_OFF; + } + + if (encoded_len > 0 && fwrite(encoded, encoded_len, 1, fp) == 0) { + EM_DEBUG_EXCEPTION("Error Occured while writing. fwrite() failed"); + err = EMAIL_ERROR_SYSTEM_FAILURE; + fclose(fp); + goto FINISH_OFF; + } + + if (fp != NULL) + fclose(fp); + } + + downloaded_size += EM_SAFE_STRLEN((char *)encoded); + EM_DEBUG_LOG("IMAP4 downloaded body size [%d]", downloaded_size); + EM_DEBUG_LOG("IMAP4 total body size [%d]", download_total_size); + EM_DEBUG_LOG("IMAP4 download interval [%d]", download_interval); + + /* In some situation, total_encoded_len includes the length of dummy bytes. + * So it might be greater than body_size */ + + download_progress = 100 * downloaded_size / download_total_size; + + EM_DEBUG_LOG("DOWNLOADING STATUS NOTIFY:Total[%d]/[%d] = %d %% Completed", + downloaded_size, download_total_size, download_progress); + + if (cnt_info->grab_type == GRAB_TYPE_TEXT && !auto_download) { + if (cnt_info->total_body_size > body_size) { + if (!emcore_notify_network_event(NOTI_DOWNLOAD_MULTIPART_BODY, mail_id, buf, download_total_size, downloaded_size)) + EM_DEBUG_EXCEPTION(" emcore_notify_network_event [NOTI_DOWNLOAD_MULTIPART_BODY] Failed >>>>"); + } + else { + if (!emcore_notify_network_event(NOTI_DOWNLOAD_BODY_START, mail_id, buf, download_total_size, downloaded_size)) + EM_DEBUG_EXCEPTION(" emcore_notify_network_event [NOTI_DOWNLOAD_BODY_START] Failed >>>>"); + } + } + } else { + int remain_body_size = body_size; + int x = 0; + int nsize = 0; + int fd = 0; + total = 0; + + if (mime_part && mime_part->encoding == GMIME_CONTENT_ENCODING_BASE64) + x = (sizeof(encoded)/78)*78; /* to solve base64 decoding pro */ + else + x = sizeof(encoded)-1; + + memset(test_buffer, 0x00, sizeof(test_buffer)); + while (remain_body_size && (total <body_size)) { + + memset(test_buffer, 0x00, sizeof(test_buffer)); + while ((total != body_size) && remain_body_size && ((EM_SAFE_STRLEN((char *)test_buffer) + x) < sizeof(test_buffer))) { + memset(encoded, 0x00, sizeof(encoded)); + + if (net_getbuffer (imaplocal->netstream, (long)x, (char *)encoded) <= 0) { + EM_DEBUG_EXCEPTION("net_getbuffer failed..."); + err = EMAIL_ERROR_NO_RESPONSE; + goto FINISH_OFF; + } + + nsize = EM_SAFE_STRLEN((char *)encoded); + remain_body_size = remain_body_size - nsize; + strncat((char *)test_buffer, (char *)encoded, nsize); + total = total + nsize; + downloaded_size += nsize; + + EM_DEBUG_LOG("total/body_size [%d/%d]", total, body_size); + + if (!(remain_body_size/x) && remain_body_size%x) + x = remain_body_size%x; + + //EM_DEBUG_LOG("IMAP4 - %d ", _imap4_last_notified_body_size); + EM_DEBUG_LOG("IMAP4 download interval [%d]", download_interval); + EM_DEBUG_LOG("IMAP4 downloaded size [%d]", downloaded_size); + EM_DEBUG_LOG("IMAP4 total body size [%d]", download_total_size); + + if (((last_notified_download_size + download_interval) <= downloaded_size) + || (downloaded_size >= download_total_size)) { + + /* In some situation, total_encoded_len includes the length of dummy bytes. + * So it might be greater than body_size */ + + if (downloaded_size > download_total_size) + downloaded_size = download_total_size; + + last_notified_download_size = downloaded_size; + + download_progress = 100*downloaded_size/download_total_size; + EM_DEBUG_LOG("DOWNLOADING STATUS NOTIFY :Total[%d] / [%d] = %d %% Completed.", + downloaded_size, download_total_size, download_progress); + + if (!auto_download) { + if (cnt_info->total_body_size > body_size) { + if (!emcore_notify_network_event(NOTI_DOWNLOAD_MULTIPART_BODY, mail_id, buf, download_total_size, downloaded_size)) + EM_DEBUG_EXCEPTION("emcore_notify_network_event [NOTI_DOWNLOAD_MULTIPART_BODY] Failed >>>>"); + } else { + if (!emcore_notify_network_event(NOTI_DOWNLOAD_BODY_START, mail_id, buf, download_total_size, downloaded_size)) + EM_DEBUG_EXCEPTION("emcore_notify_network_event [NOTI_DOWNLOAD_BODY_START] Failed >>>>"); + } + } + } + } + + if (flag_first_write == 1) { + FILE *fp = NULL; + int encoded_len = EM_SAFE_STRLEN((char *)test_buffer); + + err = em_fopen(buf, "wb+", &fp); + if (err != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION_SEC("em_fopen failed - %s", buf); + goto FINISH_OFF; + } + + if (encoded_len > 0 && fwrite(test_buffer, encoded_len, 1, fp) == 0) { + EM_DEBUG_EXCEPTION("Error Occured while writing. fwrite(\"%s\") failed", test_buffer); + err = EMAIL_ERROR_SYSTEM_FAILURE; + fclose (fp); /* prevent */ + goto FINISH_OFF; + } + + if (fp != NULL) + fclose(fp); + + flag_first_write = 0; + } else { + FILE *fp = NULL; + int encoded_len = EM_SAFE_STRLEN((char *)test_buffer); + + err = em_fopen(buf, "ab+", &fp); + if (err != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION_SEC("em_fopen failed - %s", buf); + goto FINISH_OFF; + } + + if (encoded_len > 0 && fwrite(test_buffer, encoded_len, 1, fp) == 0) { + EM_DEBUG_EXCEPTION("Error Occured while writing. fwrite(\"%s\") failed", test_buffer); + err = EMAIL_ERROR_SYSTEM_FAILURE; + fclose (fp); /* prevent */ + goto FINISH_OFF; + } + + if (fp != NULL) + fclose(fp); + } + EM_DEBUG_LOG("%d has been written", EM_SAFE_STRLEN((char *)test_buffer)); + } + + if (GMIME_IS_PART(mime_object) && mime_part) { + err = em_open(buf, O_RDONLY, 0, &fd); + if (err != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("holder open failed : holder is a filename that will be saved."); + goto FINISH_OFF; + } + + content_stream = g_mime_stream_fs_new(fd); + //parser = g_mime_parser_new_with_stream(content_stream); + content = g_mime_data_wrapper_new_with_stream(content_stream, mime_part->encoding); + if (content_stream) g_object_unref (content_stream); + g_mime_part_set_content_object(mime_part, content); + if (content) g_object_unref(content); + } + } + } else { + EM_DEBUG_LOG("MIME header"); + + char *file_name = NULL; + + GMimeObject *object_header = NULL; + GMimeParser *parser_header = NULL; + GMimeContentType *ctype_header = NULL; + GMimeContentDisposition *disposition_header = NULL; + + if (net_getbuffer(imaplocal->netstream, (long)body_size, (char *)encoded) <= 0) { + EM_DEBUG_EXCEPTION("net_getbuffer failed..."); + err = EMAIL_ERROR_NO_RESPONSE; + goto FINISH_OFF; + } + + EM_DEBUG_LOG_DEV("Data : [%s]", encoded); + + content_stream = g_mime_stream_mem_new_with_buffer((const char *)encoded, EM_SAFE_STRLEN(encoded)); + + parser_header = g_mime_parser_new_with_stream(content_stream); + if (content_stream) g_object_unref (content_stream); + + object_header = g_mime_parser_construct_part(parser_header); + if (parser_header) g_object_unref(parser_header); + + /* Content type */ + ctype_header = g_mime_object_get_content_type(object_header); + file_name = (char *)g_mime_content_type_get_parameter(ctype_header, "name"); + EM_DEBUG_LOG_DEV("Content name : [%s]", file_name); + + if (file_name == NULL) { + /* Content Disposition */ + disposition_header = g_mime_object_get_content_disposition(object_header); + file_name = (char *)g_mime_content_disposition_get_parameter(disposition_header, "filename"); + EM_DEBUG_LOG_DEV("Disposition name : [%s]", file_name); + } + + /* Replace the file name (Becase the server sometimes send the invalid name in bodystructure) */ + if (mime_part && file_name) g_mime_part_set_filename(mime_part, file_name); + + if (object_header) g_object_unref(object_header); + if (ctype_header) g_object_unref(ctype_header); + if (disposition_header) g_object_unref(disposition_header); + } + + EM_SAFE_FREE(buf); + } + else if ((tag_position = g_strrstr(response, tag))) /* end of response */ { + if (!strncmp(tag_position + EM_SAFE_STRLEN(tag) + 1, "OK", 2)) { + EM_SAFE_FREE(response); + } + else { /* 'NO' or 'BAD */ + err = EMAIL_ERROR_IMAP4_FETCH_UID_FAILURE; + goto FINISH_OFF; + } + break; + } + else if (!strcmp(response, ")")) { + } + + EM_SAFE_FREE (response); } + ret = TRUE; + FINISH_OFF: + /*if (mime_iter) { + g_mime_part_iter_free(mime_iter); + mime_iter = NULL; + }*/ + + if (search_info) { + EM_SAFE_FREE(search_info->section); + EM_SAFE_FREE(search_info); + } + + EM_SAFE_FREE(buf); + + EM_SAFE_FREE(response); + + if (err_code) + *err_code = err; + EM_DEBUG_FUNC_END(); + + return ret; } +INTERNAL_FUNC int emcore_gmime_fetch_imap_attachment_section(MAILSTREAM *stream, + int mail_id, int uid, int nth, struct _m_content_info *cnt_info, + GMimeMessage *message, int auto_download, int event_handle, int *err_code) +{ + EM_DEBUG_FUNC_BEGIN("stream[%p], uid[%d], err_code[%p]", stream, uid, err_code); + + int ret = FALSE; + int err = EMAIL_ERROR_NONE; + + IMAPLOCAL *imaplocal = NULL; + + char tag[16] = {0,}; + char command[64] = {0,}; + char *response = NULL; + unsigned char encoded[DOWNLOAD_MAX_BUFFER_SIZE] = {0, }; + unsigned char test_buffer[LOCAL_MAX_BUFFER_SIZE] = {0, }; + + int flag_first_write = TRUE; + int preline_len = 0; + int nskip = 0; + char *concat_encoded = NULL; + char *new_response = NULL; + char *tag_position = NULL; + char *tmp_file = NULL; + + int body_size = 0; + int total = 0; + int server_response_yn = 0; + int download_noti_interval = 0; + int download_total_size = 0; + int downloaded_size = 0; + int download_progress = 0; + int last_notified_download_size = 0; + + GMimeDataWrapper *content = NULL; + GMimeStream *content_stream = NULL; + GMimeObject *mime_object = NULL; + GMimePart *mime_part = NULL; + //GMimePartIter *mime_iter = NULL; + GMimeMessagePart *mime_message_part = NULL; + search_section *search_info = NULL; + + if (!stream || !cnt_info || !message) { + EM_DEBUG_EXCEPTION_SEC("stream[%p], section[%s], cnt_info[%p], message[%p]", + stream, cnt_info, message); + err = EMAIL_ERROR_INVALID_PARAM; + goto FINISH_OFF; + } + + if (!cnt_info->sections) { + EM_DEBUG_EXCEPTION("section is NULL"); + err = EMAIL_ERROR_INVALID_PARAM; + goto FINISH_OFF; + } + + imaplocal = stream->local; + + if (!imaplocal->netstream) { + EM_DEBUG_EXCEPTION("invalid IMAP4 stream detected... %p", imaplocal->netstream); + err = EMAIL_ERROR_INVALID_STREAM; + goto FINISH_OFF; + } + + memset(tag, 0x00, sizeof(tag)); + memset(command, 0x00, sizeof(command)); + + SNPRINTF(tag, sizeof(tag), "%08lx", 0xffffffff & (stream->gensym++)); + SNPRINTF(command, sizeof(command), "%s UID FETCH %d BODY.PEEK[%s]\015\012", tag, uid, cnt_info->sections); + EM_DEBUG_LOG("[IMAP4] >>> [%s]", command); + + /* send command : get msgno/uid for all message */ + if (!net_sout(imaplocal->netstream, command, (int)EM_SAFE_STRLEN(command))) { + EM_DEBUG_EXCEPTION("net_sout failed..."); + err = EMAIL_ERROR_CONNECTION_BROKEN; + goto FINISH_OFF; + } + + char *p_stream = NULL; + char *p_content = NULL; + + while (imaplocal->netstream) { + + /*don't delete the comment. several threads including event thread call this func + if (!emcore_check_thread_status()) { + EM_DEBUG_LOG("Canceled..."); + imaplocal->netstream = NULL; + err = EMAIL_ERROR_CANCELLED; + goto FINISH_OFF; + }*/ + + /* receive response */ + if (!(response = net_getline(imaplocal->netstream))) { + EM_DEBUG_EXCEPTION("net_getline failed..."); + err = EMAIL_ERROR_INVALID_RESPONSE; + goto FINISH_OFF; + } + +#ifdef FEATURE_CORE_DEBUG + EM_DEBUG_LOG("recv[%s]", response); +#endif + + /* start of response */ + if (response[0] == '*' && !server_response_yn) { + + p_stream = strstr(response, "BODY["); + + if (!p_stream) { + err = EMAIL_ERROR_INVALID_RESPONSE; + goto FINISH_OFF; + } + + server_response_yn = 1; + p_stream += strlen("BODY["); + p_content = p_stream; + + while (*p_content != ']') + p_content++; + + *p_content = '\0'; + + /* check correct section */ + if (g_strcmp0(cnt_info->sections, p_stream) != 0) { + EM_DEBUG_LOG("Invalid response of section"); + err = EMAIL_ERROR_INVALID_RESPONSE; + goto FINISH_OFF; + } + + /* get body size */ + p_stream = strstr(p_content+1, " {"); + if (p_stream) { + p_stream += strlen(" {"); + p_content = p_stream; + + while (isdigit(*p_content)) + p_content++; + + *p_content = '\0'; + + body_size = atoi(p_stream); + } else { /* no body length is replied */ + /* seek the termination of double quot */ + p_stream = strstr(p_content+1, " \""); + if (p_stream) { + char *t = NULL; + p_stream += strlen(" \""); + t = strstr(p_stream, "\""); + if (t) { + body_size = t - p_stream; + *t = '\0'; + EM_DEBUG_LOG("Body : start[%p] end[%p] : body[%s]", p_stream, t, p_stream); + /* need to decode */ + EM_SAFE_FREE(response); + response = EM_SAFE_STRDUP(p_stream); + } else { + err = EMAIL_ERROR_INVALID_RESPONSE; + goto FINISH_OFF; + } + } else { + err = EMAIL_ERROR_INVALID_RESPONSE; + goto FINISH_OFF; + } + } + + /*if (GMIME_IS_MULTIPART (message->mime_part)) { + mime_iter = g_mime_part_iter_new((GMimeObject *)message); + + if (!g_mime_part_iter_is_valid(mime_iter)) { + EM_DEBUG_EXCEPTION("Part iterator is not valid"); + goto FINISH_OFF; + } + + if (g_mime_part_iter_jump_to (mime_iter, section)) { + EM_DEBUG_LOG("g_mime_part_iter_jump_to: %s", section); + mime_object = g_mime_part_iter_get_current (mime_iter); + if (!mime_object) { + EM_DEBUG_EXCEPTION("g_mime_part_iter_get_current failed"); + goto FINISH_OFF; + } + mime_part = GMIME_PART(mime_object); + } else { + EM_DEBUG_LOG("g_mime_part_iter_jump_to: failed to jump to %s", section); + goto FINISH_OFF; + } + + if (mime_iter) { + g_mime_part_iter_free(mime_iter); + mime_iter = NULL; + } + } else if (GMIME_IS_PART (message->mime_part)) { + mime_object = message->mime_part; + mime_part = GMIME_PART(mime_object); + }*/ + + if (search_info) { + EM_SAFE_FREE(search_info->section); + EM_SAFE_FREE(search_info); + } + + if (!(search_info = em_malloc(sizeof(search_section)))) { /* prevent */ + EM_DEBUG_EXCEPTION("em_malloc failed..."); + err = EMAIL_ERROR_OUT_OF_MEMORY; + goto FINISH_OFF; + } + + search_info->section = EM_SAFE_STRDUP(cnt_info->sections); + g_mime_message_foreach(message, emcore_gmime_search_section_foreach_cb, (gpointer)search_info); + + if (!(search_info->section_object)) { + EM_DEBUG_EXCEPTION("section search failed"); + goto FINISH_OFF; + } + + mime_message_part = NULL; + mime_part = NULL; + mime_object = search_info->section_object; + if (GMIME_IS_MESSAGE_PART(mime_object)) { + mime_message_part = GMIME_MESSAGE_PART(mime_object); + } else if (GMIME_IS_PART(mime_object)) { + mime_part = GMIME_PART(mime_object); + } else { + EM_DEBUG_EXCEPTION("invalid mime part type"); + goto FINISH_OFF; + } + + if (!emcore_get_temp_file_name(&tmp_file, &err) || !tmp_file) { + EM_DEBUG_EXCEPTION("emcore_get_temp_file_name failed [%d]", err); + goto FINISH_OFF; + } + + g_mime_object_set_content_type_parameter(mime_object, "tmp_content_path", tmp_file); + + EM_DEBUG_LOG("Attachment number [%d]", nth); + if (!auto_download) { + if (!emcore_notify_network_event(NOTI_DOWNLOAD_ATTACH_START, mail_id, tmp_file, nth, 0)) + EM_DEBUG_EXCEPTION("emcore_notify_network_event [ NOTI_DOWNLOAD_ATTACH_START] Failed >>>>"); + } + + download_noti_interval = body_size * DOWNLOAD_NOTI_INTERVAL_PERCENT / 100; + download_total_size = body_size; + + if (download_noti_interval > DOWNLOAD_NOTI_INTERVAL_SIZE) { + download_noti_interval = DOWNLOAD_NOTI_INTERVAL_SIZE; + } + + /* remove new lines */ + do { + EM_SAFE_FREE(response); + if (!(response = net_getline(imaplocal->netstream))) { + EM_DEBUG_EXCEPTION("net_getline failed..."); + err = EMAIL_ERROR_INVALID_RESPONSE; + goto FINISH_OFF; + } + + EM_DEBUG_LOG("response:%s", response); + if (EM_SAFE_STRLEN(response) == 0) { + EM_DEBUG_LOG("Skip newline !!"); + nskip++; + } else { + EM_SAFE_FREE(new_response); /* detected by valgrind */ + new_response = g_strconcat(response, "\r\n", NULL); + EM_SAFE_FREE(response); + break; + } + } while(1); + + preline_len = EM_SAFE_STRLEN(new_response); + EM_DEBUG_LOG("preline_len : %d", preline_len); + + if (body_size <= 0 || preline_len <= 0) + continue; + + if ((body_size - preline_len - nskip*2) <= 0) { + /* 1 line content */ + + if (GMIME_IS_PART(mime_object) && mime_part) { + char *tmp_str = NULL; + tmp_str = g_strndup(new_response, body_size); + if (tmp_str == NULL) tmp_str = g_strdup(new_response); + + content_stream = g_mime_stream_mem_new_with_buffer((const char *)tmp_str, EM_SAFE_STRLEN(tmp_str)); + //parser = g_mime_parser_new_with_stream(content_stream); + content = g_mime_data_wrapper_new_with_stream(content_stream, mime_part->encoding); + if (content_stream) g_object_unref (content_stream); + g_mime_part_set_content_object(mime_part, content); + if (content) g_object_unref(content); + EM_SAFE_FREE(tmp_str); + } + else if (GMIME_IS_MESSAGE_PART(mime_object) && mime_message_part) { + FILE *fp = NULL; + int response_len = 0; + char *tmp_str = NULL; + + tmp_str = g_strndup(new_response, body_size); + if (tmp_str == NULL) tmp_str = g_strdup(new_response); + + response_len = EM_SAFE_STRLEN((char *)tmp_str); + + err = em_fopen(tmp_file, "wb+", &fp); + if (err != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION_SEC("em_fopen failed - %s", tmp_file); + EM_SAFE_FREE(tmp_str); + goto FINISH_OFF; + } + + if (response_len > 0 && fwrite(tmp_str, response_len, 1, fp) == 0) { + EM_DEBUG_EXCEPTION("Error Occured while writing. fwrite() failed"); + err = EMAIL_ERROR_SYSTEM_FAILURE; + fclose(fp); + EM_SAFE_FREE(tmp_str); + goto FINISH_OFF; + } + + if (fp != NULL) + fclose(fp); + + EM_SAFE_FREE(tmp_str); + } + + EM_SAFE_FREE(new_response); + + total = body_size; + EM_DEBUG_LOG("current total = %d", total); + downloaded_size += total; + + EM_DEBUG_LOG("DOWNLOADING STATUS NOTIFY : received[%d] / total_size[%d] = %d %% Completed", + downloaded_size, download_total_size, (int)((float)downloaded_size / (float)download_total_size * 100.0)); + + if (((last_notified_download_size + download_noti_interval) <= downloaded_size) || (downloaded_size >= download_total_size)) { + + if (downloaded_size > download_total_size) + downloaded_size = download_total_size; + + last_notified_download_size = downloaded_size; + + download_progress = (int)((float)downloaded_size / (float)download_total_size * 100.0); + + if (!auto_download) { + if (download_total_size && !emcore_notify_network_event(NOTI_DOWNLOAD_ATTACH_START, mail_id, tmp_file, nth, download_progress)) + EM_DEBUG_EXCEPTION("emcore_notify_network_event [ NOTI_DOWNLOAD_ATTACH_START] Failed >>>>"); + } + } + } + else if ((body_size < DOWNLOAD_MAX_BUFFER_SIZE) && (body_size - preline_len - nskip*2 < DOWNLOAD_MAX_BUFFER_SIZE)) { + memset(encoded, 0x00, sizeof(encoded)); + if (net_getbuffer(imaplocal->netstream, body_size - preline_len - nskip*2, (char *)encoded) <= 0) { + EM_DEBUG_EXCEPTION("net_getbuffer failed..."); + err = EMAIL_ERROR_NO_RESPONSE; + goto FINISH_OFF; + } + + concat_encoded = g_strconcat(new_response, encoded, NULL); + memset(encoded, 0x00, sizeof(encoded)); + memcpy(encoded, concat_encoded, EM_SAFE_STRLEN(concat_encoded)); + EM_SAFE_FREE(concat_encoded); + EM_SAFE_FREE(new_response); + + if (GMIME_IS_PART(mime_object) && mime_part) { + content_stream = g_mime_stream_mem_new_with_buffer((const char *)encoded, EM_SAFE_STRLEN(encoded)); + //parser = g_mime_parser_new_with_stream(content_stream); + content = g_mime_data_wrapper_new_with_stream(content_stream, mime_part->encoding); + if (content_stream) g_object_unref (content_stream); + g_mime_part_set_content_object(mime_part, content); + if (content) g_object_unref(content); + } + else if (GMIME_IS_MESSAGE_PART(mime_object) && mime_message_part) { + FILE *fp = NULL; + int encoded_len = EM_SAFE_STRLEN((char *)encoded); + + err = em_fopen(tmp_file, "wb+", &fp); + if (err != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION_SEC("em_fopen failed - %s", tmp_file); + goto FINISH_OFF; + } + + if (encoded_len > 0 && fwrite(encoded, encoded_len, 1, fp) == 0) { + EM_DEBUG_EXCEPTION("Error Occured while writing. fwrite() failed"); + err = EMAIL_ERROR_SYSTEM_FAILURE; + fclose(fp); + goto FINISH_OFF; + } + + if (fp != NULL) + fclose(fp); + } + + total = EM_SAFE_STRLEN((char *)encoded); + EM_DEBUG_LOG("total = %d", total); + downloaded_size += total; + + EM_DEBUG_LOG("DOWNLOADING STATUS NOTIFY : received[%d] / total_size[%d] = %d %% Completed", + downloaded_size, download_total_size, (int)((float)downloaded_size / (float)download_total_size * 100.0)); + + if (((last_notified_download_size + download_noti_interval) <= downloaded_size) || (downloaded_size >= download_total_size)) { + + if (downloaded_size > download_total_size) + downloaded_size = download_total_size; + + last_notified_download_size = downloaded_size; + + download_progress = (int)((float)downloaded_size / (float)download_total_size * 100.0); + + if (!auto_download) { + if (download_total_size && !emcore_notify_network_event(NOTI_DOWNLOAD_ATTACH_START, mail_id, tmp_file, nth, download_progress)) + EM_DEBUG_EXCEPTION("emcore_notify_network_event [ NOTI_DOWNLOAD_ATTACH_START] Failed >>>>"); + } + } + } + else { + int remain_body_size = body_size - preline_len - nskip*2; + int x = 0; + int nsize = 0; + int fd = 0; + total += preline_len + nskip*2; + downloaded_size += preline_len + nskip*2; + + memset(test_buffer, 0x00, sizeof(test_buffer)); + + while (remain_body_size > 0 && (total < body_size)) { + + memset(test_buffer, 0x00, sizeof(test_buffer)); + + if (remain_body_size < DOWNLOAD_MAX_BUFFER_SIZE) + x = remain_body_size; + else if (mime_part && mime_part->encoding == GMIME_CONTENT_ENCODING_BASE64) + x = (sizeof(encoded)/preline_len)*preline_len; /* to solve base64 decoding pro */ + else + x = sizeof(encoded)-1; + + if (new_response) { + strncat((char *)test_buffer, (char *)new_response, preline_len); + EM_SAFE_FREE(new_response); + } + + while (remain_body_size > 0 && (total < body_size) && ((EM_SAFE_STRLEN((char *)test_buffer) + x) < sizeof(test_buffer))) { + if (event_handle > 0) + FINISH_OFF_IF_EVENT_CANCELED (err, event_handle); + + memset(encoded, 0x00, sizeof(encoded)); + + if (net_getbuffer(imaplocal->netstream, (long)x, (char *)encoded) <= 0) { + EM_DEBUG_EXCEPTION("net_getbuffer failed..."); + err = EMAIL_ERROR_NO_RESPONSE; + goto FINISH_OFF; + } + + nsize = EM_SAFE_STRLEN((char *)encoded); + remain_body_size = remain_body_size - nsize; + strncat((char *)test_buffer, (char *)encoded, nsize); + total = total + nsize; + downloaded_size += nsize; + EM_DEBUG_LOG("nsize : %d", nsize); + EM_DEBUG_LOG("remain_body_size : %d", remain_body_size); + EM_DEBUG_LOG("total : %d", total); + EM_DEBUG_LOG("imap_received_body_size : %d", downloaded_size); + + if (!(remain_body_size/x) && remain_body_size%x) + x = remain_body_size%x; + + EM_DEBUG_LOG("DOWNLOADING STATUS NOTIFY : received[%d] / total_size[%d] = %d %% Completed", + downloaded_size, download_total_size, (int)((float)downloaded_size / (float)download_total_size * 100.0)); + + if (((last_notified_download_size + download_noti_interval) <= downloaded_size) || (downloaded_size >= download_total_size)) { + + if (downloaded_size > download_total_size) + downloaded_size = download_total_size; + + last_notified_download_size = downloaded_size; + + download_progress = (int)((float)downloaded_size / (float)download_total_size * 100.0); + + if (!auto_download) { + if (download_total_size && !emcore_notify_network_event(NOTI_DOWNLOAD_ATTACH_START, mail_id, tmp_file, nth, download_progress)) + EM_DEBUG_EXCEPTION("emcore_notify_network_event [ NOTI_DOWNLOAD_ATTACH_START] Failed >>>>"); + } + } + } + + if (flag_first_write == true) { + + FILE *fp = NULL; + int encoded_len = EM_SAFE_STRLEN((char *)test_buffer); + + err = em_fopen(tmp_file, "wb+", &fp); + if (err != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION_SEC("em_fopen failed - %s", tmp_file); + goto FINISH_OFF; + } + + if (encoded_len > 0 && fwrite(test_buffer, encoded_len, 1, fp) == 0) { + EM_DEBUG_EXCEPTION("Error Occured while writing. fwrite(\"%s\") failed", test_buffer); + err = EMAIL_ERROR_SYSTEM_FAILURE; + fclose(fp); /* prevent */ + goto FINISH_OFF; + } + + if (fp != NULL) + fclose(fp); + + flag_first_write = false; + } else { + FILE *fp = NULL; + int encoded_len = EM_SAFE_STRLEN((char *)test_buffer); + + err = em_fopen(tmp_file, "ab+", &fp); + if (err != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION_SEC("em_fopen failed - %s", tmp_file); + goto FINISH_OFF; + } + + if (encoded_len > 0 && fwrite(test_buffer, encoded_len, 1, fp) == 0) { + EM_DEBUG_EXCEPTION("Error Occured while writing. fwrite(\"%s\") failed", test_buffer); + err = EMAIL_ERROR_SYSTEM_FAILURE; + fclose(fp); /* prevent */ + goto FINISH_OFF; + } + + if (fp != NULL) + fclose(fp); + } + EM_DEBUG_LOG("%d has been written", EM_SAFE_STRLEN((char *)test_buffer)); + } + + if (GMIME_IS_PART(mime_object) && mime_part) { + err = em_open(tmp_file, O_RDONLY, 0, &fd); + if (err != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("holder open failed : holder is a filename that will be saved."); + if (fd) close(fd); + goto FINISH_OFF; + } + + content_stream = g_mime_stream_fs_new(fd); + //parser = g_mime_parser_new_with_stream(content_stream); + content = g_mime_data_wrapper_new_with_stream(content_stream, mime_part->encoding); + if (content_stream) g_object_unref (content_stream); + g_mime_part_set_content_object(mime_part, content); + if (content) g_object_unref(content); + } + } + + EM_SAFE_FREE(tmp_file); + } + else if ((tag_position = g_strrstr(response, tag))) /* end of response */ { + if (!strncmp(tag_position + EM_SAFE_STRLEN(tag) + 1, "OK", 2)) { + EM_SAFE_FREE(response); + } else { /* 'NO' or 'BAD */ + err = EMAIL_ERROR_IMAP4_FETCH_UID_FAILURE; + goto FINISH_OFF; + } + break; + } + else if (!strcmp(response, ")")) { + /* The end of response which contains body information */ + } + } /* while (imaplocal->netstream) */ + + ret = TRUE; + +FINISH_OFF: + + EM_SAFE_FREE(tmp_file); + EM_SAFE_FREE(response); + EM_SAFE_FREE (new_response); + + if (search_info) { + EM_SAFE_FREE(search_info->section); + EM_SAFE_FREE(search_info); + } + + /*if (mime_iter) { + g_mime_part_iter_free(mime_iter); + mime_iter = NULL; + }*/ + + if (err_code != NULL) + *err_code = err; + + EM_DEBUG_FUNC_END(); + + return ret; +} + +INTERNAL_FUNC int emcore_gmime_check_filename_duplication(char *source_filename, struct _m_content_info *cnt_info) +{ + EM_DEBUG_FUNC_BEGIN("source_file_name [%s], content_info [%p]", source_filename, cnt_info); + + if (!source_filename || !cnt_info || strlen(source_filename) <= 0) { + EM_DEBUG_EXCEPTION("Invalid parameter"); + return FALSE; + } + + struct attachment_info *cur_attachment_info = NULL; + int ret = FALSE; + + cur_attachment_info = cnt_info->inline_file; + + while (cur_attachment_info) { + + if(g_strcmp0(source_filename, cur_attachment_info->name) == 0) { + ret = TRUE; + break; + } + + cur_attachment_info = cur_attachment_info->next; + } + + EM_DEBUG_FUNC_END(); + return ret; +} + +INTERNAL_FUNC char *emcore_gmime_get_modified_filename_in_duplication(char *source_filename) +{ + EM_DEBUG_FUNC_BEGIN(); + + struct timeval tv; + char temp_filename[MAX_PATH] = {0,}; + //char *filename = NULL; + //char *extension = NULL; + + if (!source_filename) { + EM_DEBUG_EXCEPTION("Invalid parameter"); + return NULL; + } + + /*if ((err = em_get_file_name_and_extension_from_file_path(source_filename, &filename, &extension)) != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("em_get_file_name_and_extension_from_file_path failed [%d]", err); + return NULL; + }*/ + + gettimeofday(&tv, NULL); + srand(tv.tv_usec); + + snprintf(temp_filename, MAX_PATH, "%d_%s", rand(), source_filename); + EM_DEBUG_LOG_SEC("temp_file_name [%s]", temp_filename); + + EM_DEBUG_FUNC_END(); + return EM_SAFE_STRDUP(temp_filename); +} + +INTERNAL_FUNC char *emcore_gmime_get_encoding_to_utf8(const char *text) +{ + EM_DEBUG_FUNC_BEGIN(); + + if (text == NULL) { + EM_DEBUG_EXCEPTION("Invalid parameter"); + return NULL; + } + + char *encoded_text = NULL; + + encoded_text = g_mime_utils_header_encode_text(text); + if (encoded_text == NULL) { + EM_DEBUG_EXCEPTION("g_mime_utils_header_encode_text failed : [%s]", text); + return NULL; + } + + EM_DEBUG_LOG_SEC("encoded_text : [%s]", encoded_text); + + return encoded_text; +} diff --git a/email-core/email-core-imap-idle.c b/email-core/email-core-imap-idle.c index fdbc3fe..e24cedf 100755 --- a/email-core/email-core-imap-idle.c +++ b/email-core/email-core-imap-idle.c @@ -35,6 +35,7 @@ #include <glib.h> #include <openssl/ssl.h> #include "c-client.h" +#include <sys/epoll.h> #include "lnx_inc.h" #include "email-core-imap-idle.h" #include "email-debug-log.h" @@ -44,10 +45,12 @@ #include "email-core-mailbox.h" #include "email-core-event.h" #include "email-core-account.h" - +#include "email-core-alarm.h" +#include "email-utilities.h" /*Definitions copied temporarily from ssl_unix.c */ #define SSLBUFLEN 8192 +#define MAX_EPOLL_EVENT 100 typedef struct ssl_stream { TCPSTREAM *tcpstream; /* TCP stream */ @@ -59,290 +62,112 @@ typedef struct ssl_stream { } SSLSTREAM; /*Definitions copied temporarily from ssl_unix.c - end*/ -thread_t imap_idle_thread; -int g_imap_idle_thread_alive = 0; +typedef struct _email_imap_idle_connection_info_t { + int account_id; + int mailbox_id; + MAILSTREAM *mail_stream; + int socket_fd; +} email_imap_idle_connection_info_t; -void* emcore_imap_idle_run(void* thread_user_data); -static int emcore_imap_idle_parse_response_stream(email_mailbox_t *mailbox, int *err_code); -static int emcore_imap_idle_connect_and_idle_on_mailbox(email_mailbox_t *mailbox, int *err_code); +int imap_idle_pipe_fd[2]; +thread_t imap_idle_thread_id; -int emcore_create_imap_idle_thread(int account_id, int *err_code) +static int emcore_get_connection_info_by_socket_fd(GList *input_imap_idle_task_list, int input_socket_fd, email_imap_idle_connection_info_t **output_connection_info) { - EM_DEBUG_FUNC_BEGIN("account_id [%d], err_code [%p]", account_id, err_code); - int ret = false; + EM_DEBUG_FUNC_BEGIN("input_imap_idle_task_list[%p] input_socket_fd[%d] output_connection_info[%p]", input_imap_idle_task_list, input_socket_fd, output_connection_info); int err = EMAIL_ERROR_NONE; - int thread_error; - - g_imap_idle_thread_alive = 1; - THREAD_CREATE(imap_idle_thread, emcore_imap_idle_run, NULL, thread_error); - - if (thread_error != 0) { - EM_DEBUG_EXCEPTION("cannot make IMAP IDLE thread..."); - err = EMAIL_ERROR_UNKNOWN; - g_imap_idle_thread_alive = 0; - goto FINISH_OFF; - } - - ret = true; + email_imap_idle_connection_info_t *connection_info = NULL; + GList *index = NULL; -FINISH_OFF: - if (err_code != NULL) - *err_code = err; - - EM_DEBUG_FUNC_END("ret [%d]", ret); - 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 emnetwork_check_network_status() fails. -*/ -int emcore_kill_imap_idle_thread(int *err_code) -{ - EM_DEBUG_FUNC_BEGIN("err_code [%p]", err_code); - int ret = true; - int err = EMAIL_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 = 0; - EM_DEBUG_LOG("killed IMAP IDLE"); - - if (err_code) - *err_code = err; - - EM_DEBUG_FUNC_END("ret [%d]", ret); - return ret; -} - -int emcore_imap_idle_loop_start(email_mailbox_t *mailbox_list, int num, int *err_code) -{ - EM_DEBUG_FUNC_BEGIN("mailbox_list[%p], num[%d]", mailbox_list, num); - fd_set readfds; - int maxfd = 0; - int err = EMAIL_ERROR_NONE; - int counter = 0; - int select_result = 0; - int ret = false; - email_mailbox_t *temp = NULL; - struct timeval timeout; - - EM_DEBUG_EXCEPTION(">>>>>>> emcore_imap_idle_loop_start start "); - if (!mailbox_list || !num) { + if (input_imap_idle_task_list == NULL || output_connection_info == NULL) { EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM"); err = EMAIL_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 (!emcore_imap_idle_parse_response_stream(temp, &err)) { - EM_DEBUG_EXCEPTION(">>>> emcore_imap_idle_loop_start 6 "); - temp->mail_stream = mail_close (temp->mail_stream); - EM_DEBUG_EXCEPTION(">>>> emcore_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; - } - } + index = g_list_first(input_imap_idle_task_list); - else if (select_result == 0) /* Timeout occurred */ { - EM_DEBUG_EXCEPTION(">>>> emcore_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(">>>> emcore_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)EM_SAFE_STRLEN(cmd))) { - EM_DEBUG_EXCEPTION_SEC("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); - temp->mail_stream = mail_close (temp->mail_stream); - break; - } - } - } - temp = temp->next; - } - - - /* kill idle thread */ - emcore_kill_imap_idle_thread(&err); - break; - } - - else { - /* - might happen that a socket descriptor passed to select got closed - check which got closed and make hold_connection 0 - */ - EM_DEBUG_EXCEPTION(">>>>>> socket descriptor error : No Data "); + while(index) { + connection_info = index->data; + if(connection_info && connection_info->socket_fd == input_socket_fd) { break; } - - select_result = 0; + index = g_list_next(index); } - ret = true; - - EM_DEBUG_LOG(">>>> emcore_imap_idle_loop_start 17 "); - -FINISH_OFF: - - if (err_code) - *err_code = err; + if(connection_info) + *output_connection_info = connection_info; + else + err = EMAIL_ERROR_DATA_NOT_FOUND; - EM_DEBUG_FUNC_END("ret [%d]", ret); - return ret; +FINISH_OFF: + EM_DEBUG_FUNC_END("err [%d]", err); + return err; } -void* emcore_imap_idle_run(void* thread_user_data) +static int emcore_clear_old_connections(int input_epoll_fd, GList **input_imap_idle_task_list) { - EM_DEBUG_FUNC_BEGIN("thread_user_data [%p]", thread_user_data); - char *mailbox_list[3]; - int mailbox_num = 0; - int err = EMAIL_ERROR_NONE; - int flag = true; - int num = 0; - int counter = 0; - int accountID = (int)thread_user_data; - email_mailbox_t *mail_box_list = NULL; - email_mailbox_t *curr_mailbox = NULL; - email_mailbox_t *prev_mailbox = NULL; - emstorage_mailbox_tbl_t *local_mailbox = NULL; - email_session_t *session = NULL; - - if ( !emnetwork_check_network_status(&err)) { - EM_DEBUG_EXCEPTION("emnetwork_check_network_status failed [%d]", err); - goto FINISH_OFF; - } - /* Connect to DB */ - if (!emstorage_open(&err)) { - EM_DEBUG_EXCEPTION("emstorage_open falied [%d]", err); + EM_DEBUG_FUNC_BEGIN("input_epoll_fd[%d] input_imap_idle_task_list[%p] ", input_epoll_fd, input_imap_idle_task_list); + int err = EMAIL_ERROR_NONE; + email_imap_idle_connection_info_t *connection_info = NULL; + struct epoll_event ev = {0}; + GList *index = NULL; + char errno_buf[ERRNO_BUF_SIZE] = {0}; + + if (input_imap_idle_task_list == NULL) { + EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM"); + err = EMAIL_ERROR_INVALID_PARAM; goto FINISH_OFF; } - if (!emcore_get_empty_session(&session)) - EM_DEBUG_EXCEPTION("emcore_get_empty_session failed..."); + index = g_list_first(*input_imap_idle_task_list); - /* 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 */ + while(index) { + connection_info = index->data; - /* For testing - mailbox_num and mailbox_list are hardcoded here */ - mailbox_num = 1; - mailbox_list[0] = strdup("INBOX"); + /* Removes all fd from epoll_fd */ + ev.events = EPOLLIN; + ev.data.fd = connection_info->socket_fd; - /* make a list of mailboxes IDLING */ - for (counter = 0; counter < mailbox_num; counter++){ - EM_DEBUG_EXCEPTION(">>>> emcore_imap_idle_run 4 "); - if (!emstorage_get_mailbox_by_name(accountID, 0, mailbox_list[counter], &local_mailbox, true, &err)) { - EM_DEBUG_EXCEPTION("emstorage_get_mailbox_by_name failed [%d]", err); + if (epoll_ctl(input_epoll_fd, EPOLL_CTL_DEL, connection_info->socket_fd, &ev) == -1) { + EM_DEBUG_LOG("epoll_ctl failed: %s[%d]", EM_STRERROR(errno_buf), errno); } - else { - curr_mailbox = em_malloc(sizeof(email_mailbox_t)); - curr_mailbox->account_id = local_mailbox->account_id; - curr_mailbox->mailbox_name = EM_SAFE_STRDUP(local_mailbox->mailbox_name); - curr_mailbox->local = local_mailbox->local_yn; - if (!emcore_imap_idle_connect_and_idle_on_mailbox(curr_mailbox, &err)) { - EM_DEBUG_EXCEPTION("emcore_imap_idle_connect_and_idle_on_mailbox failed [%d]", err); - emcore_free_mailbox(curr_mailbox); - EM_SAFE_FREE(curr_mailbox); - } - 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) - emstorage_free_mailbox(&local_mailbox, 1, NULL); - } - emcore_clear_session(session); - emcore_imap_idle_loop_start(mail_box_list, num, NULL); - -FINISH_OFF: + /* Close connection */ + connection_info->mail_stream = mail_close(connection_info->mail_stream); + EM_SAFE_FREE(connection_info); - if (!emstorage_close(&err)) { - EM_DEBUG_EXCEPTION("emstorage_close falied [%d]", err); + index = g_list_next(index); } - EM_DEBUG_FUNC_END(); - return NULL; + g_list_free(*input_imap_idle_task_list); + *input_imap_idle_task_list = NULL; + +FINISH_OFF: + EM_DEBUG_FUNC_END("err [%d]", err); + return err; } -int emcore_imap_idle_insert_sync_event(email_mailbox_t *mailbox, int *err_code) +static int emcore_imap_idle_insert_sync_event(int input_account_id, int input_mailbox_id, int *err_code) { EM_DEBUG_FUNC_BEGIN(); - + int ret = false; int err = EMAIL_ERROR_NONE; int handle; email_event_t *event_data = NULL; - - if (!mailbox || mailbox->account_id <= 0) { + + if (input_account_id <= 0) { EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM"); err = EMAIL_ERROR_INVALID_PARAM; goto FINISH_OFF; } - event_data = em_malloc(sizeof(email_event_t)); + event_data = em_malloc(sizeof(email_event_t)); event_data->type = EMAIL_EVENT_SYNC_HEADER; - event_data->event_param_data_1 = mailbox ? EM_SAFE_STRDUP(mailbox->mailbox_name) : NULL; - event_data->event_param_data_3 = NULL; - event_data->account_id = mailbox->account_id; - + event_data->event_param_data_5 = input_mailbox_id; + event_data->account_id = input_account_id; + if (!emcore_insert_event(event_data, &handle, &err)) { EM_DEBUG_EXCEPTION("emcore_insert_event failed [%d]", err); goto FINISH_OFF; @@ -364,48 +189,102 @@ FINISH_OFF: return ret; } -/* connects to given mailbox. send idle and returns socket id */ -static int emcore_imap_idle_connect_and_idle_on_mailbox(email_mailbox_t *mailbox, int *err_code) +static int emcore_parse_imap_idle_response(int input_account_id, int input_mailbox_id, MAILSTREAM *input_mailstream, int input_socket_fd) { - EM_DEBUG_FUNC_BEGIN("mailbox [%p], err_code [%p]", mailbox, err_code); - void *mail_stream = NULL; - char cmd[128] = { 0, }; - char tag[32] = { 0, }; - char *p = NULL; - int socket_id = 0; - int ret = 0; - int err = EMAIL_ERROR_NONE; - email_account_t *ref_account = NULL; - IMAPLOCAL *imap_local = NULL; - NETSTREAM *net_stream = NULL; - TCPSTREAM *tcp_stream = NULL; - - /* NULL param check */ - if (!mailbox) { + EM_DEBUG_FUNC_BEGIN("input_account_id[%d] input_mailbox_id [%d] input_mailstream[%p] input_socket_fd[%d]", input_account_id, input_mailbox_id, input_mailstream, input_socket_fd); + int err = EMAIL_ERROR_NONE; + char *p = NULL; + IMAPLOCAL *imap_local = NULL; + + if (!input_mailstream) { EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM"); err = EMAIL_ERROR_INVALID_PARAM; goto FINISH_OFF; } - ref_account = emcore_get_account_reference(mailbox->account_id); - if (!ref_account) { - EM_DEBUG_EXCEPTION("emcore_get_account_reference failed. account_id[%d]", mailbox->account_id); - err = EMAIL_ERROR_INVALID_ACCOUNT; + imap_local = input_mailstream->local; + + if (!imap_local){ + EM_DEBUG_EXCEPTION("imap_local is NULL"); + err = EMAIL_ERROR_INVALID_PARAM; + 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); + err = EMAIL_ERROR_IMAP4_IDLE_FAILURE; + goto FINISH_OFF; + } + else { + if (!emcore_imap_idle_insert_sync_event(input_account_id, input_mailbox_id, &err)) + EM_DEBUG_EXCEPTION_SEC("Syncing mailbox[%d] failed with err_code [%d]", input_mailbox_id, 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; + } + } + +FINISH_OFF: + + EM_DEBUG_FUNC_END("err [%d]", err); + return err; +} + +/* connects to given mailbox. send idle and returns socket id */ +static int emcore_connect_and_idle_on_mailbox(GList **input_connection_list, email_account_t *input_account, email_mailbox_t *input_mailbox, MAILSTREAM **output_mailstream, int *output_socket_fd) +{ + EM_DEBUG_FUNC_BEGIN("input_connection_list [%p] input_account [%p] input_mailbox[%p] output_mailstream [%p] output_socket_fd [%p]", input_connection_list, input_account, input_mailbox, output_mailstream, output_socket_fd); + void *mail_stream = NULL; + char cmd[128] = { 0, }; + char tag[32] = { 0, }; + char *p = NULL; + int socket_fd = 0; + int err = EMAIL_ERROR_NONE; + email_session_t *session = NULL; + IMAPLOCAL *imap_local = NULL; + NETSTREAM *net_stream = NULL; + TCPSTREAM *tcp_stream = NULL; + GList *imap_idle_connection_list = NULL; + email_imap_idle_connection_info_t *connection_info = NULL; + + if (input_connection_list == NULL || input_account == NULL || input_mailbox == NULL || output_mailstream == NULL || output_socket_fd == NULL) { + EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM"); + err = EMAIL_ERROR_INVALID_PARAM; goto FINISH_OFF; } + imap_idle_connection_list = *input_connection_list; + + if (!emcore_get_empty_session(&session)) + EM_DEBUG_EXCEPTION("emcore_get_empty_session failed..."); + /* Open connection to mailbox */ - if (!emcore_connect_to_remote_mailbox(mailbox->account_id, mailbox->mailbox_name, (void **)&mail_stream, &err) || !mail_stream) { + if (!emcore_connect_to_remote_mailbox(input_mailbox->account_id, input_mailbox->mailbox_id, (void **)&mail_stream, &err) || !mail_stream) { EM_DEBUG_EXCEPTION("emcore_connect_to_remote_mailbox failed [%d]", err); goto FINISH_OFF; } imap_local = ((MAILSTREAM *)mail_stream)->local; net_stream = imap_local->netstream; - + /* check if ssl option is enabled on this account - shasikala.p */ - if (ref_account->incoming_server_secure_connection){ + if (input_account->incoming_server_secure_connection){ SSLSTREAM *ssl_stream = net_stream->stream; tcp_stream = ssl_stream->tcpstream; } @@ -413,14 +292,14 @@ static int emcore_imap_idle_connect_and_idle_on_mailbox(email_mailbox_t *mailbox tcp_stream = net_stream->stream; /* Get Socket ID */ - socket_id = ((TCPSTREAM *)tcp_stream)->tcpsi; + socket_fd = ((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)EM_SAFE_STRLEN(cmd))) { - EM_DEBUG_EXCEPTION_SEC("network error - failed to IDLE on Mailbox - %s ", mailbox->mailbox_name); + EM_DEBUG_EXCEPTION_SEC("network error - failed to IDLE on Mailbox - %s ", input_mailbox->mailbox_name); err = EMAIL_ERROR_IMAP4_IDLE_FAILURE; goto FINISH_OFF; } @@ -428,102 +307,300 @@ static int emcore_imap_idle_connect_and_idle_on_mailbox(email_mailbox_t *mailbox /* 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; + + if (p && !strncmp(p, "+", 1)) { + EM_DEBUG_LOG("OK. Go."); break; } - else if (!strncmp(p, "*", 1)) { + else if (p && !strncmp(p, "*", 1)) { EM_SAFE_FREE(p); continue; } else { - ret = 0; + EM_DEBUG_LOG("Unsuspected response."); + err = EMAIL_ERROR_IMAP4_IDLE_FAILURE; break; } } EM_SAFE_FREE(p); -FINISH_OFF: - - if (ret) { + connection_info = em_malloc(sizeof(email_imap_idle_connection_info_t)); + if (connection_info == NULL) { + EM_DEBUG_EXCEPTION("EMAIL_ERROR_OUT_OF_MEMORY"); + err = EMAIL_ERROR_OUT_OF_MEMORY; + goto FINISH_OFF; + } + + connection_info->account_id = input_account->account_id; + connection_info->mailbox_id = input_mailbox->mailbox_id; + connection_info->mail_stream = mail_stream; + connection_info->socket_fd = socket_fd; + + imap_idle_connection_list = g_list_append(imap_idle_connection_list, (gpointer)connection_info); + +FINISH_OFF: + + if (err == EMAIL_ERROR_NONE) { /* IMAP IDLE - SUCCESS */ - mailbox->mail_stream = mail_stream; - mailbox->hold_connection = socket_id; /* holds connection continuously on the given socket_id */ +// *output_mailstream = mail_stream; + *output_socket_fd = socket_fd; + *input_connection_list = imap_idle_connection_list; } else if (mail_stream) mail_stream = mail_close (mail_stream); - if (ref_account) { - emcore_free_account(ref_account); - EM_SAFE_FREE(ref_account); + emcore_clear_session(session); + + EM_DEBUG_FUNC_END("err [%d]", err); + return err; +} + +static int emcore_imap_idle_cb(email_alarm_data_t *alarm_data, void *user_parameter) +{ + EM_DEBUG_FUNC_BEGIN("alarm_data [%p] user_parameter [%p]", alarm_data, user_parameter); + int err = EMAIL_ERROR_NONE; + + emcore_refresh_imap_idle_thread(); + + EM_DEBUG_FUNC_END("err [%d]", err); + return err; +} + +static int emcore_refresh_alarm_for_imap_idle() +{ + EM_DEBUG_FUNC_BEGIN(); + int err = EMAIL_ERROR_NONE; + int i = 0; + int account_count = 0; + int auto_sync_account_count = 0; + time_t current_time; + time_t trigger_at_time; + email_account_t *account_ref_list = NULL; + + /* Check whether the alarm is already existing */ + if(emcore_check_alarm_by_class_id(EMAIL_ALARM_CLASS_IMAP_IDLE) == EMAIL_ERROR_NONE) { + EM_DEBUG_LOG("Already exist. Remove old one."); + emcore_delete_alram_data_by_reference_id(EMAIL_ALARM_CLASS_IMAP_IDLE, 0); } - if (err_code) - *err_code = err; + if (!emcore_get_account_reference_list(&account_ref_list, &account_count, &err)) { + EM_DEBUG_LOG("emcore_get_account_reference_list failed [%d]", err); + goto FINISH_OFF; + } - EM_DEBUG_FUNC_END("ret [%d]", ret); - return ret; + for (i = 0; i < account_count; i++) { + if (account_ref_list[i].incoming_server_type == EMAIL_SERVER_TYPE_IMAP4 && (account_ref_list[i].check_interval == 0 || account_ref_list[i].peak_interval == 0)) { + auto_sync_account_count++; + } + } + + if(account_ref_list) + emcore_free_account_list(&account_ref_list, account_count, NULL); + + if (auto_sync_account_count) { + time(¤t_time); + trigger_at_time = current_time + (29 * 60); + + if ((err = emcore_add_alarm(trigger_at_time, EMAIL_ALARM_CLASS_IMAP_IDLE, 0, emcore_imap_idle_cb, NULL)) != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emcore_add_alarm failed [%d]",err); + } + } + +FINISH_OFF: + + EM_DEBUG_FUNC_END("err [%d]", err); + return err; } -static int emcore_imap_idle_parse_response_stream(email_mailbox_t *mailbox, int *err_code) +void* emcore_imap_idle_worker(void* thread_user_data) { - EM_DEBUG_FUNC_BEGIN("mailbox [%p], err_code [%p]", mailbox, err_code); + EM_DEBUG_FUNC_BEGIN(); int err = EMAIL_ERROR_NONE; - char *p = NULL; - int ret = false; - IMAPLOCAL *imap_local = NULL; - - if (!mailbox || !mailbox->mail_stream) { - EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM"); - err = EMAIL_ERROR_INVALID_PARAM; + int i = 0, j = 0; + int event_num = 0; + int epoll_fd = 0; + int socket_fd = 0; + int signal_from_pipe = 0; + int refresh_connection_flag = 1; + int account_count = 0; + char errno_buf[ERRNO_BUF_SIZE] = {0}; + struct epoll_event ev = {0}; + struct epoll_event events[MAX_EPOLL_EVENT] = {{0}, }; + MAILSTREAM *mail_stream = NULL; + email_mailbox_t inbox_mailbox = {0}; + email_account_t *account_ref_list = NULL; + GList *imap_idle_connection_list = NULL; + email_imap_idle_connection_info_t *connection_info = NULL; + + EM_DEBUG_LOG("emcore_imap_idle_worker start "); + + if (pipe(imap_idle_pipe_fd) == -1) { + EM_DEBUG_EXCEPTION("pipe failed"); + err = EMAIL_ERROR_UNKNOWN; goto FINISH_OFF; } - imap_local = ((MAILSTREAM *)mailbox->mail_stream)->local; + epoll_fd = epoll_create(MAX_EPOLL_EVENT); - if (!imap_local){ - EM_DEBUG_EXCEPTION("imap_local is NULL"); - err = EMAIL_ERROR_INVALID_PARAM; + if (epoll_fd < 0) { + EM_DEBUG_CRITICAL_EXCEPTION("epoll_create failed: %s[%d]", EM_STRERROR(errno_buf), errno); + err = EMAIL_ERROR_IMAP4_IDLE_FAILURE; 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 (!emcore_imap_idle_insert_sync_event(mailbox, &err)) - EM_DEBUG_EXCEPTION_SEC("Syncing mailbox %s failed with err_code [%d]", mailbox->mailbox_name, err); - EM_SAFE_FREE(p); + ev.events = EPOLLIN; + ev.data.fd = imap_idle_pipe_fd[0]; + + if (epoll_ctl(epoll_fd, EPOLL_CTL_ADD, imap_idle_pipe_fd[0], &ev) == -1) { + EM_DEBUG_EXCEPTION("epoll_ctl failed: %s[%d]", EM_STRERROR(errno_buf), errno); + } + + EM_DEBUG_LOG("Enter imap idle loop"); + while (1) { + if (refresh_connection_flag) { + EM_DEBUG_LOG("Clear old connections"); + emcore_clear_old_connections(epoll_fd, &imap_idle_connection_list); + + EM_DEBUG_LOG("Getting account list"); + if (!emcore_get_account_reference_list(&account_ref_list, &account_count, &err)) { + EM_DEBUG_LOG("emcore_get_account_reference_list failed [%d]", err); break; } + + for (i = 0; i < account_count; i++) { + if (account_ref_list[i].incoming_server_type != EMAIL_SERVER_TYPE_IMAP4 || (account_ref_list[i].check_interval != 0 && account_ref_list[i].peak_interval != 0)) { + EM_DEBUG_LOG("account_id[%d] is not for auto sync", account_ref_list[i].account_id); + continue; + } + + /* TODO: peak schedule handling */ + + memset(&inbox_mailbox, 0, sizeof(email_mailbox_t)); + + if (!emcore_get_mailbox_by_type(account_ref_list[i].account_id, EMAIL_MAILBOX_TYPE_INBOX, &inbox_mailbox, &err)) { + EM_DEBUG_EXCEPTION("emcore_get_mailbox_by_type failed [%d]", err); + continue; + } + + EM_DEBUG_LOG("Connect to IMAP server"); + err = emcore_connect_and_idle_on_mailbox(&imap_idle_connection_list, &(account_ref_list[i]), &inbox_mailbox, &mail_stream, &socket_fd); + + emcore_free_mailbox(&inbox_mailbox); + + if (err != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emcore_connect_and_idle_on_mailbox failed [%d]", err); + continue; + } + + ev.events = EPOLLIN; + ev.data.fd = socket_fd; + + EM_DEBUG_LOG("Add listener for socket buffer"); + if (epoll_ctl(epoll_fd, EPOLL_CTL_ADD, socket_fd, &ev) == -1) { + EM_DEBUG_EXCEPTION("epoll_ctl failed: %s[%d]", EM_STRERROR(errno_buf), errno); + } + } + + if(account_ref_list) + emcore_free_account_list(&account_ref_list, account_count, NULL); + + EM_DEBUG_LOG(" Delete old an alarm and add an alarm to refresh connections every 29min"); + emcore_refresh_alarm_for_imap_idle(); + + refresh_connection_flag = 0; } - 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; + + EM_DEBUG_LOG("Waiting......."); + event_num = epoll_wait(epoll_fd, events, MAX_EPOLL_EVENT, -1); + EM_DEBUG_LOG("epoll_wait returns [%d]", event_num); + + if (event_num > 0) { + EM_DEBUG_LOG(">>>> Data coming from socket or pipe "); + for (j = 0; j < event_num; j++) { + int event_fd = events[j].data.fd; + + EM_DEBUG_LOG("event_fd [%d]", event_fd); + + if (event_fd == imap_idle_pipe_fd[0]) { + EM_DEBUG_LOG(">>>> Data coming from pipe "); + if (read(imap_idle_pipe_fd[0], (void*)&signal_from_pipe, sizeof(signal_from_pipe)) != -1) { + EM_DEBUG_LOG("Refresh IMAP connections"); + refresh_connection_flag = 1; + continue; + } + } + else { + if ((err = emcore_get_connection_info_by_socket_fd(imap_idle_connection_list, event_fd, &connection_info)) != EMAIL_ERROR_NONE) { + EM_DEBUG_LOG("emcore_get_connection_info_by_socket_fd couldn't find proper connection info. [%d]", err); + continue; + } + + if ((err = emcore_parse_imap_idle_response(connection_info->account_id, connection_info->mailbox_id, connection_info->mail_stream, connection_info->socket_fd)) != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emcore_parse_imap_idle_response failed. [%d] ", err); + refresh_connection_flag = 1; +// mail_stream = mail_close (mail_stream); + continue; + } + } + } } } - ret = true; + EM_DEBUG_LOG("Exit imap idle loop"); FINISH_OFF: + emcore_free_mailbox(&inbox_mailbox); - if (err_code) - *err_code = err; + EM_DEBUG_LOG("Close pipes"); - EM_DEBUG_FUNC_END("ret [%d]", ret); - return ret; + close(imap_idle_pipe_fd[0]); + close(imap_idle_pipe_fd[1]); + + imap_idle_thread_id = 0; + + EM_DEBUG_FUNC_END("err [%d]", err); + return NULL; +} + + +INTERNAL_FUNC int emcore_create_imap_idle_thread() +{ + EM_DEBUG_FUNC_BEGIN(); + int err = EMAIL_ERROR_NONE; + int thread_error; + + if (imap_idle_thread_id) { + EM_DEBUG_EXCEPTION("IMAP IDLE thread already exists."); + err = EMAIL_ERROR_ALREADY_EXISTS; + goto FINISH_OFF; + + } + + THREAD_CREATE(imap_idle_thread_id, emcore_imap_idle_worker, NULL, thread_error); + + if (thread_error != 0) { + EM_DEBUG_EXCEPTION("cannot make IMAP IDLE thread..."); + err = EMAIL_ERROR_UNKNOWN; + goto FINISH_OFF; + } + +FINISH_OFF: + + EM_DEBUG_FUNC_END("err [%d]", err); + return err; +} + +INTERNAL_FUNC int emcore_refresh_imap_idle_thread() +{ + EM_DEBUG_FUNC_BEGIN(); + int err = EMAIL_ERROR_NONE; + int signal = 1; + + write(imap_idle_pipe_fd[1], (char*) &signal, sizeof (signal)); + + EM_DEBUG_FUNC_END("err [%d]", err); + return err; } #endif /* __FEATURE_IMAP_IDLE__ */ diff --git a/email-core/email-core-imap-mailbox.c b/email-core/email-core-imap-mailbox.c index aa3b5c8..4c42511 100755 --- a/email-core/email-core-imap-mailbox.c +++ b/email-core/email-core-imap-mailbox.c @@ -4,7 +4,7 @@ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> -* +* * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -25,9 +25,9 @@ * File : email-core-imap_folder.c * Desc : Mail IMAP mailbox * - * Auth : + * Auth : * - * History : + * History : * 2006.08.01 : created *****************************************************************************/ #include <stdio.h> @@ -42,8 +42,9 @@ #include "email-core-event.h" #include "email-core-mailbox.h" #include "email-core-imap-mailbox.h" +#include "email-core-imap-idle.h" #include "email-core-mailbox-sync.h" -#include "email-core-account.h" +#include "email-core-account.h" #include "email-core-signal.h" #include "lnx_inc.h" @@ -52,7 +53,7 @@ #include "email-debug-log.h" INTERNAL_FUNC int emcore_get_default_mail_slot_count(int input_account_id, int *output_count) -{ +{ EM_DEBUG_FUNC_BEGIN("input_account_id [%d] output_count[%p]", input_account_id, output_count); int err = EMAIL_ERROR_NONE; @@ -68,13 +69,13 @@ INTERNAL_FUNC int emcore_get_default_mail_slot_count(int input_account_id, int * if (account_ref) default_mail_slot_count = account_ref->default_mail_slot_size; -FINISH_OFF: +FINISH_OFF: if (account_ref) { emcore_free_account(account_ref); EM_SAFE_FREE(account_ref); } - + if (output_count) *output_count = default_mail_slot_count; @@ -87,11 +88,11 @@ INTERNAL_FUNC int emcore_remove_overflowed_mails(emstorage_mailbox_tbl_t *intput { EM_DEBUG_FUNC_BEGIN("intput_mailbox_tbl[%p], err_code[%p]", intput_mailbox_tbl, err_code); - int ret = false; + int ret = false; int *mail_id_list = NULL, mail_id_list_count = 0; int err = EMAIL_ERROR_NONE; email_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); @@ -107,8 +108,8 @@ INTERNAL_FUNC int emcore_remove_overflowed_mails(emstorage_mailbox_tbl_t *intput goto FINISH_OFF; } } - - if (!emstorage_get_overflowed_mail_id_list(intput_mailbox_tbl->account_id, intput_mailbox_tbl->mailbox_id, intput_mailbox_tbl->mail_slot_size, &mail_id_list, &mail_id_list_count, true, &err)) { + + if (!emstorage_get_overflowed_mail_id_list(intput_mailbox_tbl->account_id, intput_mailbox_tbl->mailbox_id, intput_mailbox_tbl->mailbox_type, intput_mailbox_tbl->mail_slot_size, &mail_id_list, &mail_id_list_count, true, &err)) { if (err == EMAIL_ERROR_MAIL_NOT_FOUND) { EM_DEBUG_LOG_SEC("There are enough slot in intput_mailbox_tbl [%s]", intput_mailbox_tbl->mailbox_name); err = EMAIL_ERROR_NONE; @@ -125,9 +126,9 @@ INTERNAL_FUNC int emcore_remove_overflowed_mails(emstorage_mailbox_tbl_t *intput goto FINISH_OFF; } } - + ret = true; -FINISH_OFF: +FINISH_OFF: EM_SAFE_FREE(mail_id_list); if (account_ref) { @@ -147,7 +148,7 @@ INTERNAL_FUNC int emcore_set_mail_slot_size(int account_id, int mailbox_id, int { EM_DEBUG_FUNC_BEGIN("account_id [%d], mailbox_id[%d], err_code[%p]", account_id, mailbox_id, err_code); - int ret = false, err = EMAIL_ERROR_NONE; + int ret = false, err = EMAIL_ERROR_NONE; int i = 0; int account_count = 100; int mailbox_count = 0; @@ -204,14 +205,14 @@ INTERNAL_FUNC int emcore_set_mail_slot_size(int account_id, int mailbox_id, int } mailbox_tbl_list->account_id = account_id; mailbox_tbl_list->mailbox_id = mailbox_id; - mailbox_tbl_list->mail_slot_size = new_slot_size; + mailbox_tbl_list->mail_slot_size = new_slot_size; } else { /* read information from DB */ if ((err = emstorage_get_mailbox_by_id(mailbox_id, &mailbox_tbl_list)) != EMAIL_ERROR_NONE) { EM_DEBUG_EXCEPTION("emstorage_get_mailbox_by_id failed [%d]", err); goto FINISH_OFF; } - + } } else { @@ -231,8 +232,8 @@ INTERNAL_FUNC int emcore_set_mail_slot_size(int account_id, int mailbox_id, int } ret = true; - -FINISH_OFF: + +FINISH_OFF: if (account_ref) { emcore_free_account(account_ref); @@ -310,14 +311,17 @@ FINISH_OFF: EM_SAFE_FREE(ref_account); } + if (err_code) + *err_code = err; + if (!ret) return 0; return 1; } -static void emcore_find_mailbox_diff_between_local_and_remote (email_internal_mailbox_t *remote_box_list, - int remote_box_count, emstorage_mailbox_tbl_t *local_box_list, int local_box_count, +static void emcore_find_mailbox_diff_between_local_and_remote (email_internal_mailbox_t *remote_box_list, + int remote_box_count, emstorage_mailbox_tbl_t *local_box_list, int local_box_count, GList** remote_box_only, GList** local_box_only) { if ( !remote_box_only || !local_box_only ) { @@ -357,7 +361,7 @@ static void emcore_find_mailbox_diff_between_local_and_remote (email_internal_ma EM_DEBUG_LOG_DEV ("vs local [%s]", local_box->mailbox_name); if (!EM_SAFE_STRCMP (remote_box->mailbox_name, local_box->mailbox_name)) { /* It is unnecessary to compare the matched box in the next iteration, so remove it from local_box*/ - local_head = g_list_delete_link (local_head, local_p); + local_head = g_list_delete_link (local_head, local_p); matched = true; break; } @@ -371,15 +375,16 @@ static void emcore_find_mailbox_diff_between_local_and_remote (email_internal_ma /* local_head contains unmatched local box */ *local_box_only = local_head; + + if (remote_head) g_list_free(remote_head); } -INTERNAL_FUNC int emcore_sync_mailbox_list(int account_id, char *mailbox_name, int handle, int *err_code) +INTERNAL_FUNC int emcore_sync_mailbox_list(int account_id, char *mailbox_name, int event_handle, int *err_code) { - EM_DEBUG_FUNC_BEGIN("account_id[%d], mailbox_name[%p], handle[%d], err_code[%p]", account_id, mailbox_name, handle, err_code); - + EM_DEBUG_FUNC_BEGIN("account_id[%d], mailbox_name[%p], handle[%d], err_code[%p]", account_id, mailbox_name, event_handle, err_code); + int ret = false; int err = EMAIL_ERROR_NONE; - int status = EMAIL_DOWNLOAD_FAIL; MAILSTREAM *stream = NULL; email_internal_mailbox_t *mailbox_list = NULL; /* mailbox list from imap server */ /* mailbox list from DB */ @@ -392,68 +397,59 @@ INTERNAL_FUNC int emcore_sync_mailbox_list(int account_id, char *mailbox_name, i char *mbox_path = NULL; char *mailbox_name_for_mailbox_type = NULL; int i = 0, count = 0, counter = 0, mailbox_type_list[EMAIL_MAILBOX_TYPE_ALL_EMAILS + 1] = {-1, -1, -1, -1, -1, -1, -1, -1}; - - if (!emcore_notify_network_event(NOTI_SYNC_IMAP_MAILBOX_LIST_START, account_id, 0, handle, 0)) + int inbox_added = 0; + + if (!emcore_notify_network_event(NOTI_SYNC_IMAP_MAILBOX_LIST_START, account_id, 0, event_handle, 0)) EM_DEBUG_EXCEPTION("emcore_notify_network_event [ NOTI_SYNC_IMAP_MAILBOX_LIST_START] Failed >>>> "); - if (!emcore_check_thread_status()) { - err = EMAIL_ERROR_CANCELLED; - goto FINISH_OFF; - } + FINISH_OFF_IF_EVENT_CANCELED (err, event_handle); + if (!emnetwork_check_network_status(&err)) { EM_DEBUG_EXCEPTION("emnetwork_check_network_status failed [%d]", err); goto FINISH_OFF; } - + ref_account = emcore_get_account_reference(account_id); if (!ref_account) { EM_DEBUG_EXCEPTION("emcore_get_account_reference failed - %d", account_id); err = EMAIL_ERROR_INVALID_ACCOUNT; goto FINISH_OFF; } - + /* if not imap4 mail, return */ if ( ref_account->incoming_server_type != EMAIL_SERVER_TYPE_IMAP4) { EM_DEBUG_EXCEPTION("unsupported account..."); err = EMAIL_ERROR_INVALID_ACCOUNT; goto FINISH_OFF; } - + /* get mail server path */ /* mbox_path is not used. the below func might be unnecessary */ if (!emcore_get_mailbox_connection_path(account_id, NULL, &mbox_path, &err) || !mbox_path) { EM_DEBUG_EXCEPTION("emcore_get_mailbox_connection_path - %d", err); goto FINISH_OFF; } - - - if (!emcore_check_thread_status()) { - err = EMAIL_ERROR_CANCELLED; - goto FINISH_OFF; - } + + + FINISH_OFF_IF_EVENT_CANCELED (err, event_handle); stream = NULL; if (!emcore_connect_to_remote_mailbox(account_id, 0, (void **)&tmp_stream, &err) || !tmp_stream) { EM_DEBUG_EXCEPTION("emcore_connect_to_remote_mailbox failed - %d", err); - + if (err == EMAIL_ERROR_CONNECTION_BROKEN) err = EMAIL_ERROR_CANCELLED; else err = EMAIL_ERROR_CONNECTION_FAILURE; - - status = EMAIL_DOWNLOAD_CONNECTION_FAIL; goto FINISH_OFF; } - + EM_SAFE_FREE(mbox_path); - + stream = (MAILSTREAM *)tmp_stream; - - if (!emcore_check_thread_status()) { - err = EMAIL_ERROR_CANCELLED; - goto FINISH_OFF; - } - + + FINISH_OFF_IF_EVENT_CANCELED (err, event_handle); + /* download mailbox list */ if (!emcore_download_mailbox_list(stream, mailbox_name, &mailbox_list, &count, &err)) { EM_DEBUG_EXCEPTION("emcore_download_mailbox_list failed [%d]", err); @@ -470,11 +466,8 @@ INTERNAL_FUNC int emcore_sync_mailbox_list(int account_id, char *mailbox_name, i EM_DEBUG_LOG ("mailbox not found"); } - if (!emcore_check_thread_status()) { - err = EMAIL_ERROR_CANCELLED; - goto FINISH_OFF; - } - + FINISH_OFF_IF_EVENT_CANCELED (err, event_handle); + emcore_find_mailbox_diff_between_local_and_remote (mailbox_list, count, local_mailbox_list, local_mailbox_count, &remote_box_only, &local_box_only); @@ -483,11 +476,7 @@ INTERNAL_FUNC int emcore_sync_mailbox_list(int account_id, char *mailbox_name, i for (; p; p = g_list_next (p)) { email_internal_mailbox_t *new_mailbox = (email_internal_mailbox_t *) g_list_nth_data (p, 0); - if (!emcore_check_thread_status()) { - EM_DEBUG_LOG("emcore_check_thread_status - cancelled"); - err = EMAIL_ERROR_CANCELLED; - goto FINISH_OFF; - } + FINISH_OFF_IF_EVENT_CANCELED (err, event_handle); if (!new_mailbox->mailbox_name) { continue; @@ -525,13 +514,15 @@ INTERNAL_FUNC int emcore_sync_mailbox_list(int account_id, char *mailbox_name, i if (new_mailbox->alias) { mailbox_tbl.alias = new_mailbox->alias; - mailbox_tbl.modifiable_yn = 1; + mailbox_tbl.modifiable_yn = 1; mailbox_tbl.total_mail_count_on_server = 0; - + if (!emstorage_add_mailbox (&mailbox_tbl, true, &err)) { EM_DEBUG_EXCEPTION ("emstorage_add_mailbox error [%d]", err); goto FINISH_OFF; } + if (mailbox_tbl.mailbox_type == EMAIL_MAILBOX_TYPE_INBOX) + inbox_added = 1; EM_DEBUG_LOG_SEC ("MAILBOX ADDED: mailbox_name [%s] alias [%s] mailbox_type [%d]", new_mailbox->mailbox_name,\ new_mailbox->alias, mailbox_tbl.mailbox_type); } @@ -541,14 +532,20 @@ INTERNAL_FUNC int emcore_sync_mailbox_list(int account_id, char *mailbox_name, i p = local_box_only; for (; p; p = g_list_next (p)) { emstorage_mailbox_tbl_t *del_box = (emstorage_mailbox_tbl_t *) g_list_nth_data (p, 0); - if (!emstorage_delete_mail_by_mailbox (del_box->account_id, del_box->mailbox_id, 1, &err)) { + if (!emstorage_delete_mail_by_mailbox (del_box, 1, &err)) { EM_DEBUG_EXCEPTION ("emstorage_delete_mail_by_mailbox error [%d] account_id [%d] mailbox_name [%s]",\ err, del_box->account_id, del_box->mailbox_name); } if (!emstorage_delete_mailbox (del_box->account_id, EMAIL_MAILBOX_FROM_SERVER, del_box->mailbox_id, 1, &err)) { - EM_DEBUG_EXCEPTION ("emstorage_delete_mail_by_mailbox error [%d] account_id [%d] mailbox_name [%s]",\ + EM_DEBUG_EXCEPTION ("emstorage_delete_mailbox error [%d] account_id [%d] mailbox_name [%s]",\ err, del_box->account_id, del_box->mailbox_name); } + +#ifdef __FEATURE_WIFI_AUTO_DOWNLOAD__ + if (!emstorage_delete_auto_download_activity_by_mailbox(del_box->account_id, del_box->mailbox_id, 1, &err)) + EM_DEBUG_EXCEPTION("emstorage_delete_auto_download_activity_by_mailbox failed"); +#endif + EM_DEBUG_LOG_SEC ("MAILBOX REMOVED: mailbox_name[%s] mailbox_id[%d]", del_box->mailbox_name, del_box->mailbox_id); } @@ -619,26 +616,25 @@ INTERNAL_FUNC int emcore_sync_mailbox_list(int account_id, char *mailbox_name, i EM_DEBUG_EXCEPTION(" >>>> emstorage_set_all_mailbox_modifiable_yn Failed [ %d ]", err); goto FINISH_OFF; } - - if (!emcore_check_thread_status()) { - err = EMAIL_ERROR_CANCELLED; - goto FINISH_OFF; - } - + + if (inbox_added) + emcore_refresh_imap_idle_thread(); + + FINISH_OFF_IF_EVENT_CANCELED (err, event_handle); + for (i = 0; i < count; i++) mailbox_list[i].account_id = account_id; - - + ret = true; - -FINISH_OFF: + +FINISH_OFF: if (err == EMAIL_ERROR_NONE) { - if (!emcore_notify_network_event(NOTI_SYNC_IMAP_MAILBOX_LIST_FINISH, account_id, 0, handle, err)) + if (!emcore_notify_network_event(NOTI_SYNC_IMAP_MAILBOX_LIST_FINISH, account_id, 0, event_handle, err)) EM_DEBUG_EXCEPTION("emcore_notify_network_event [ NOTI_SYNC_IMAP_MAILBOX_LIST_FINISH] Failed >>>> "); } else { - if (!emcore_notify_network_event(NOTI_SYNC_IMAP_MAILBOX_LIST_FAIL, account_id, 0, handle, err)) + if (!emcore_notify_network_event(NOTI_SYNC_IMAP_MAILBOX_LIST_FAIL, account_id, 0, event_handle, err)) EM_DEBUG_EXCEPTION("emcore_notify_network_event [ NOTI_SYNC_IMAP_MAILBOX_LIST_FAIL] Failed >>>> "); } EM_SAFE_FREE(mailbox_name_for_mailbox_type); @@ -649,16 +645,16 @@ FINISH_OFF: EM_SAFE_FREE(ref_account); } - if (stream) + if (stream) stream = mail_close (stream); - - if (mailbox_list) + + if (mailbox_list) emcore_free_internal_mailbox (&mailbox_list, count, NULL); - if (local_mailbox_list) + if (local_mailbox_list) emstorage_free_mailbox (&local_mailbox_list, local_mailbox_count, NULL); - if (local_box_only) + if (local_box_only) g_list_free (local_box_only); if (remote_box_only) @@ -670,10 +666,10 @@ FINISH_OFF: return ret; } -int emcore_download_mailbox_list(void *mail_stream, +int emcore_download_mailbox_list(void *mail_stream, char *mailbox_name, email_internal_mailbox_t **mailbox_list, - int *count, + int *count, int *err_code) { EM_DEBUG_FUNC_BEGIN("mail_stream [%p], mailbox_name [%p], mailbox_list [%p], count [%p], err_code [%p]", mail_stream, mailbox_name, mailbox_list, count, err_code); @@ -689,7 +685,7 @@ int emcore_download_mailbox_list(void *mail_stream, err = EMAIL_ERROR_INVALID_PARAM; goto FINISH_OFF; } - + memset(&holder, 0x00, sizeof(holder)); /* reference (ex : "{mail.test.com}", "{mail.test.com}inbox") */ @@ -722,7 +718,7 @@ int emcore_download_mailbox_list(void *mail_stream, ret = true; -FINISH_OFF: +FINISH_OFF: if (err_code) *err_code = err; @@ -744,6 +740,7 @@ INTERNAL_FUNC int emcore_create_imap_mailbox(email_mailbox_t *mailbox, int *err_ void *tmp_stream = NULL; int ret = false; int err = EMAIL_ERROR_NONE; + email_session_t *session = NULL; EM_DEBUG_FUNC_BEGIN(); @@ -752,6 +749,9 @@ INTERNAL_FUNC int emcore_create_imap_mailbox(email_mailbox_t *mailbox, int *err_ goto FINISH_OFF; } + if (!emcore_get_empty_session(&session)) + EM_DEBUG_EXCEPTION("emcore_get_empty_session failed..."); + /* connect mail server */ stream = NULL; if (!emcore_connect_to_remote_mailbox(mailbox->account_id, 0, (void **)&tmp_stream, &err)) { @@ -770,7 +770,18 @@ INTERNAL_FUNC int emcore_create_imap_mailbox(email_mailbox_t *mailbox, int *err_ /* create mailbox */ if (!mail_create(stream, long_enc_path)) { EM_DEBUG_EXCEPTION("mail_create failed"); - err = EMAIL_ERROR_IMAP4_CREATE_FAILURE; + + if (!emcore_get_current_session(&session)) { + EM_DEBUG_EXCEPTION("emcore_get_current_session failed..."); + err = EMAIL_ERROR_SESSION_NOT_FOUND; + goto FINISH_OFF; + } + + if (session->error == EMAIL_ERROR_ALREADY_EXISTS) + err = session->error; + else + err = EMAIL_ERROR_IMAP4_CREATE_FAILURE; + goto FINISH_OFF; } @@ -794,6 +805,8 @@ FINISH_OFF: EM_DEBUG_EXCEPTION("emcore_notify_network_event[NOTI_ADD_MAILBOX_FAIL] failed"); } + emcore_clear_session(session); + if (err_code) *err_code = err; diff --git a/email-core/email-core-mail.c b/email-core/email-core-mail.c index c27f48f..d9047bb 100755 --- a/email-core/email-core-mail.c +++ b/email-core/email-core-mail.c @@ -4,7 +4,7 @@ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> -* +* * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -25,9 +25,9 @@ * File : email-core-mail.c * Desc : Mail Operation * - * Auth : + * Auth : * - * History : + * History : * 2006.08.16 : created *****************************************************************************/ #undef close @@ -45,8 +45,9 @@ #include <glib.h> #include <glib/gstdio.h> -#include <vconf.h> +#include <vconf.h> #include <contacts.h> +#include <contacts_internal.h> #include "email-internal-types.h" #include "c-client.h" @@ -54,14 +55,13 @@ #include "email-utilities.h" #include "email-core-global.h" #include "email-core-utils.h" -#include "email-core-mail.h" #include "email-core-mime.h" #include "email-core-mailbox.h" #include "email-storage.h" #include "email-network.h" #include "email-core-mailbox-sync.h" #include "email-core-event.h" -#include "email-core-account.h" +#include "email-core-account.h" #include "email-core-signal.h" #include "email-core-smtp.h" @@ -72,14 +72,12 @@ #include "email-core-gmime.h" #endif /* __FEATURE_USE_GMIME__ */ -#ifdef __FEATURE_DRM__ -#include <drm_client.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]; +static int g_copyuid_account_id = 0; bool only_body_download = false; @@ -133,9 +131,9 @@ static char *_getEncoding(int 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); - + EM_DEBUG_LOG("param->attribute[%s]", param->attribute); + EM_DEBUG_LOG("param->value[%s]", param->value); + param = param->next; } } @@ -145,7 +143,7 @@ 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; } } @@ -153,56 +151,56 @@ static void _print_stringlist(STRINGLIST *stringlist) 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_SEC("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_SEC("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 */ @@ -210,48 +208,48 @@ void _print_body(BODY *body, int recursive) 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 = EMAIL_ERROR_NONE; - + POP3LOCAL *pop3local = NULL; char cmd[64]; char *p = NULL; - + if (!stream) { EM_DEBUG_EXCEPTION("stream[%p]", stream); err = EMAIL_ERROR_INVALID_PARAM; goto FINISH_OFF; } - + if (!(pop3local = stream->local) || !pop3local->netstream) { EM_DEBUG_EXCEPTION("invalid POP3 stream detected..."); err = EMAIL_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)EM_SAFE_STRLEN(cmd))) { EM_DEBUG_EXCEPTION("net_sout failed..."); err = EMAIL_ERROR_CONNECTION_BROKEN; /* EMAIL_ERROR_UNKNOWN; */ goto FINISH_OFF; } - + /* receive response */ if (!(p = net_getline(pop3local->netstream))) { EM_DEBUG_EXCEPTION("net_getline failed..."); err = EMAIL_ERROR_INVALID_RESPONSE; goto FINISH_OFF; } - + #ifdef FEATURE_CORE_DEBUG EM_DEBUG_LOG("[POP3] <<< %s", p); #endif @@ -260,17 +258,17 @@ static int pop3_mail_delete(MAILSTREAM *stream, int msgno, int *err_code) err = EMAIL_ERROR_POP3_DELE_FAILURE; /* EMAIL_ERROR_MAIL_NOT_FOUND_ON_SERVER; */ goto FINISH_OFF; } - + if (*p != '+') { /* '+OK' ... */ err = EMAIL_ERROR_INVALID_RESPONSE; goto FINISH_OFF; } - + ret = true; -FINISH_OFF: +FINISH_OFF: EM_SAFE_FREE(p); - + if (err_code) *err_code = err; @@ -281,16 +279,16 @@ FINISH_OFF: static void emcore_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 = EMAIL_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; @@ -298,13 +296,14 @@ static void emcore_mail_copyuid_ex(MAILSTREAM *stream, char *mailbox, unsigned l char old_server_uid_char[129]; char new_server_uid_char[129]; + emstorage_mailbox_tbl_t *mailbox_tbl = NULL; 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 + /* + 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("emcore_mail_copyuid_ex failed : Invalid Parameters--> sourceset[%p] , destset[%p]", sourceset, destset); return; } @@ -326,19 +325,19 @@ static void emcore_mail_copyuid_ex(MAILSTREAM *stream, char *mailbox, unsigned l } } } - + temp = temp->next; } - + EM_DEBUG_LOG("Count of mails copied [%d]", count); old_server_uid = em_malloc(count * sizeof(unsigned long)); new_server_uid = em_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; @@ -357,7 +356,7 @@ static void emcore_mail_copyuid_ex(MAILSTREAM *stream, char *mailbox, unsigned l } } } - + sourceset = sourceset->next; } @@ -365,7 +364,7 @@ static void emcore_mail_copyuid_ex(MAILSTREAM *stream, char *mailbox, unsigned l index = -1; first_uid = last_uid = 0; - + while (destset) { if (destset->first > 0) { first_uid = destset->first; @@ -384,44 +383,63 @@ static void emcore_mail_copyuid_ex(MAILSTREAM *stream, char *mailbox, unsigned l } } } - + destset = destset->next; } +#ifdef __FEATURE_WIFI_AUTO_DOWNLOAD__ + if (!emstorage_get_mailbox_by_name(g_copyuid_account_id, -1, mailbox, &mailbox_tbl, false, &err)) { + EM_DEBUG_EXCEPTION("emstorage_get_mailbox_by_name failed [%d", err); + } +#endif + /* 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 (!emstorage_update_server_uid(old_server_uid_char, new_server_uid_char, &err)) { EM_DEBUG_EXCEPTION("emstorage_update_server_uid failed...[%d]", err); } - + if (!emstorage_update_read_mail_uid_by_server_uid(old_server_uid_char, new_server_uid_char, mailbox, &err)) { EM_DEBUG_EXCEPTION("emstorage_update_read_mail_uid_by_server_uid failed... [%d]", err); } - + #ifdef __FEATURE_PARTIAL_BODY_DOWNLOAD__ if (false == emstorage_update_pbd_activity(old_server_uid_char, new_server_uid_char, mailbox, &err)) { EM_DEBUG_EXCEPTION("emstorage_update_pbd_activity failed... [%d]", err); } - + #endif + +#ifdef __FEATURE_WIFI_AUTO_DOWNLOAD__ + if (mailbox_tbl) { + if (!emstorage_update_auto_download_activity(old_server_uid_char, new_server_uid_char, NULL, mailbox_tbl->mailbox_id, &err)) + EM_DEBUG_EXCEPTION("emstorage_update_auto_download_activity failed : [%d]", err); + } +#endif + } +#ifdef __FEATURE_WIFI_AUTO_DOWNLOAD__ + if (mailbox_tbl) + emstorage_free_mailbox(&mailbox_tbl, 1, NULL); + g_copyuid_account_id = 0; +#endif + EM_SAFE_FREE(old_server_uid); EM_SAFE_FREE(new_server_uid); - } INTERNAL_FUNC int emcore_move_mail_on_server_ex(int account_id, int src_mailbox_id, int mail_ids[], int num, int dest_mailbox_id, int *error_code) @@ -440,10 +458,10 @@ INTERNAL_FUNC int emcore_move_mail_on_server_ex(int account_id, int src_mailbox_ email_uid_range_set *uid_range_node = NULL; - char **string_list = NULL; + char **string_list = NULL; int string_count = 0; emstorage_mailbox_tbl_t* dest_mailbox = NULL; - + if (num <= 0 || account_id <= 0 || src_mailbox_id <= 0 || dest_mailbox_id <= 0 || NULL == mail_ids) { if (error_code != NULL) { *error_code = EMAIL_ERROR_INVALID_PARAM; @@ -453,10 +471,10 @@ INTERNAL_FUNC int emcore_move_mail_on_server_ex(int account_id, int src_mailbox_ } ref_account = emcore_get_account_reference(account_id); - + if (NULL == ref_account) { EM_DEBUG_EXCEPTION(" emcore_get_account_reference failed[%d]", account_id); - + *error_code = EMAIL_ERROR_INVALID_ACCOUNT; goto FINISH_OFF; } @@ -469,23 +487,24 @@ INTERNAL_FUNC int emcore_move_mail_on_server_ex(int account_id, int src_mailbox_ if (!emcore_connect_to_remote_mailbox(account_id, src_mailbox_id, (void **)&stream, &err_code)) { EM_DEBUG_EXCEPTION("emcore_connect_to_remote_mailbox failed[%d]", err_code); - + goto FINISH_OFF; } if (NULL != stream) { + g_copyuid_account_id = account_id; mail_parameters(stream, SET_COPYUID, emcore_mail_copyuid_ex); EM_DEBUG_LOG("calling mail_copy_full FODLER MAIL COPY "); /* [h.gahlaut] Break the set of mail_ids into comma separated strings of given length */ /* Length is decided on the basis of remaining keywords in the Query to be formed later on in emstorage_get_id_set_from_mail_ids */ /* Here about 90 bytes are required for fixed keywords in the query-> SELECT local_uid, server_uid from mail_read_mail_uid_tbl where local_uid in (....) ORDER by server_uid */ /* So length of comma separated strings which will be filled in (.....) in above query can be maximum QUERY_SIZE - 90 */ - + if (false == emcore_form_comma_separated_strings(mail_ids, num, QUERY_SIZE - 90, &string_list, &string_count, &err_code)) { EM_DEBUG_EXCEPTION("emcore_form_comma_separated_strings failed [%d]", err_code); goto FINISH_OFF; } - + if ( (err_code = emstorage_get_mailbox_by_id(dest_mailbox_id, &dest_mailbox)) != EMAIL_ERROR_NONE || !dest_mailbox) { EM_DEBUG_EXCEPTION("emstorage_get_mailbox_by_id failed [%d]", err_code); goto FINISH_OFF; @@ -495,23 +514,23 @@ INTERNAL_FUNC int emcore_move_mail_on_server_ex(int account_id, int src_mailbox_ for (i = 0; i < string_count; ++i) { /* Get the set of mail_ds and corresponding server_mail_ids sorted by server mail ids in ascending order */ - + if (false == emstorage_get_id_set_from_mail_ids(string_list[i], &id_set, &id_set_count, &err_code)) { EM_DEBUG_EXCEPTION("emstorage_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 == emcore_convert_to_uid_range_set(id_set, id_set_count, &uid_range_set, len_of_each_range, &err_code)) { EM_DEBUG_EXCEPTION("emcore_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[EM_SAFE_STRLEN(uid_range_node->uid_range) - 1] = '\0'; @@ -529,27 +548,27 @@ INTERNAL_FUNC int emcore_move_mail_on_server_ex(int account_id, int src_mailbox_ else { EM_DEBUG_LOG("Mail MOVE SUCCESS "); } - + uid_range_node = uid_range_node->next; - } + } emcore_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: +FINISH_OFF: emcore_free_comma_separated_strings(&string_list, &string_count); /*prevent 17958*/ stream = mail_close (stream); @@ -562,14 +581,14 @@ FINISH_OFF: #ifdef __FEATURE_LOCAL_ACTIVITY__ if (ret || ref_account->incoming_server_type != EMAIL_SERVER_TYPE_IMAP4) /* Delete local activity for POP3 mails and successful move operation in IMAP */ { emstorage_activity_tbl_t new_activity; - for (i = 0; i<num ; i++) { + for (i = 0; i<num ; i++) { memset(&new_activity, 0x00, sizeof(emstorage_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 (!emcore_delete_activity(&new_activity, &err_code)) { EM_DEBUG_EXCEPTION(">>>>>>Local Activity ACTIVITY_MOVEMAIL [%d] ", err_code); } @@ -591,7 +610,7 @@ FINISH_OFF: int emcore_delete_mails_from_imap4_server(int mail_ids[], int num, int from_server, int *err_code) { EM_DEBUG_FUNC_BEGIN(); - + int ret = false; int err = EMAIL_ERROR_NONE; IMAPLOCAL *imaplocal = NULL; @@ -605,11 +624,10 @@ int emcore_delete_mails_from_imap4_server(int mail_ids[], int num, int from_serv email_uid_range_set *uid_range_set = NULL; int len_of_each_range = 0; email_uid_range_set *uid_range_node = NULL; - char **string_list = NULL; + char **string_list = NULL; int string_count = 0; - int delete_success = false; emstorage_mail_tbl_t *mail_tbl_data = NULL; - + if (num <= 0 || !mail_ids) { EM_DEBUG_EXCEPTION(" Invalid parameter "); err = EMAIL_ERROR_INVALID_PARAM; @@ -653,7 +671,7 @@ int emcore_delete_mails_from_imap4_server(int mail_ids[], int num, int from_serv } /* 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 */ @@ -661,11 +679,11 @@ int emcore_delete_mails_from_imap4_server(int mail_ids[], int num, int from_serv EM_DEBUG_EXCEPTION("emstorage_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 == emcore_convert_to_uid_range_set(id_set, id_set_count, &uid_range_set, len_of_each_range, &err)) { EM_DEBUG_EXCEPTION("emcore_convert_to_uid_range_set failed [%d]", err); goto FINISH_OFF; @@ -680,43 +698,43 @@ int emcore_delete_mails_from_imap4_server(int mail_ids[], int num, int from_serv if (!(imaplocal = stream->local) || !imaplocal->netstream) { EM_DEBUG_EXCEPTION("invalid IMAP4 stream detected..."); - + err = EMAIL_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)EM_SAFE_STRLEN(cmd))) { EM_DEBUG_EXCEPTION("net_sout failed..."); - + err = EMAIL_ERROR_CONNECTION_BROKEN; /* EMAIL_ERROR_UNKNOWN */ goto FINISH_OFF; } - + while (imaplocal->netstream) { /* receive response */ if (!(p = net_getline(imaplocal->netstream))) { EM_DEBUG_EXCEPTION("net_getline failed..."); - + err = EMAIL_ERROR_INVALID_RESPONSE; /* EMAIL_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 + /* 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; @@ -724,41 +742,39 @@ int emcore_delete_mails_from_imap4_server(int mail_ids[], int num, int from_serv break; } */ - - + + if (!strncmp(p, tag, EM_SAFE_STRLEN(tag))) { if (!strncmp(p + EM_SAFE_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 = EMAIL_ERROR_IMAP4_STORE_FAILURE; /* EMAIL_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)EM_SAFE_STRLEN(cmd))) { EM_DEBUG_EXCEPTION("net_sout failed..."); - + err = EMAIL_ERROR_CONNECTION_BROKEN; goto FINISH_OFF; } @@ -767,19 +783,19 @@ int emcore_delete_mails_from_imap4_server(int mail_ids[], int num, int from_serv /* receive response */ if (!(p = net_getline(imaplocal->netstream))) { EM_DEBUG_EXCEPTION("net_getline failed..."); - + err = EMAIL_ERROR_INVALID_RESPONSE; /* EMAIL_ERROR_UNKNOWN; */ goto FINISH_OFF; } - + EM_DEBUG_LOG("[IMAP4] <<< %s", p); - + if (!strncmp(p, tag, EM_SAFE_STRLEN(tag))) { if (!strncmp(p + EM_SAFE_STRLEN(tag) + 1, "OK", 2)) { #ifdef __FEATURE_LOCAL_ACTIVITY__ int index = 0; emstorage_mail_tbl_t **mail = NULL; - + mail = (emstorage_mail_tbl_t **) em_malloc(num * sizeof(emstorage_mail_tbl_t *)); if (!mail) { EM_DEBUG_EXCEPTION("em_malloc failed"); @@ -791,21 +807,21 @@ int emcore_delete_mails_from_imap4_server(int mail_ids[], int num, int from_serv for (index = 0 ; index < num; index++) { if (!emstorage_get_downloaded_mail(mail_ids[index], &mail[index], false, &err)) { EM_DEBUG_LOG("emstorage_get_uid_by_mail_id failed [%d]", err); - - if (err == EMAIL_ERROR_MAIL_NOT_FOUND) { + + if (err == EMAIL_ERROR_MAIL_NOT_FOUND) { EM_DEBUG_LOG("EMAIL_ERROR_MAIL_NOT_FOUND_ON_SERVER : "); continue; } - } - - if (mail[index]) { + } + + if (mail[index]) { /* Clear entry from mail_read_mail_uid_tbl */ if (mail[index]->server_mail_id != NULL) { if (!emstorage_remove_downloaded_mail(mail[index]->account_id, mail[index]->mailbox_name, mail[index]->server_mail_id, true, &err)) { EM_DEBUG_LOG("emstorage_remove_downloaded_mail falied [%d]", err); } } - + /* Delete local activity */ emstorage_activity_tbl_t new_activity; memset(&new_activity, 0x00, sizeof(emstorage_activity_tbl_t)); @@ -821,14 +837,14 @@ int emcore_delete_mails_from_imap4_server(int mail_ids[], int num, int from_serv new_activity.server_mailid = NULL; new_activity.src_mbox = NULL; new_activity.dest_mbox = NULL; - + if (!emcore_delete_activity(&new_activity, &err)) { EM_DEBUG_EXCEPTION(" emcore_delete_activity 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. + * So there is no need of deleting entry in mail_read_mail_uid_tbl. However local activity has to be deleted. */ /* Delete local activity */ emstorage_activity_tbl_t new_activity; @@ -838,7 +854,7 @@ int emcore_delete_mails_from_imap4_server(int mail_ids[], int num, int from_serv new_activity.server_mailid = NULL; new_activity.src_mbox = NULL; new_activity.dest_mbox = NULL; - + if (!emcore_delete_activity(&new_activity, &err)) { EM_DEBUG_EXCEPTION(" emcore_delete_activity failed - %d ", err); } @@ -863,35 +879,35 @@ int emcore_delete_mails_from_imap4_server(int mail_ids[], int num, int from_serv goto FINISH_OFF; } } - + EM_SAFE_FREE(p); } uid_range_node = uid_range_node->next; - } + } emcore_free_uid_range_set(&uid_range_set); EM_SAFE_FREE(id_set); - + id_set_count = 0; } - + ret = true; -FINISH_OFF: +FINISH_OFF: EM_SAFE_FREE(p); EM_SAFE_FREE(id_set); /*prevent 17954*/ - + if (stream) { stream = mail_close (stream); } - + emcore_free_comma_separated_strings(&string_list, &string_count); if (false == ret) { emcore_free_uid_range_set(&uid_range_set); } - + if (err_code) { *err_code = err; } @@ -902,46 +918,48 @@ FINISH_OFF: #endif -typedef enum { - IMAP4_CMD_EXPUNGE -} imap4_cmd_t; - -static int imap4_send_command(MAILSTREAM *stream, imap4_cmd_t cmd_type, int *err_code) +INTERNAL_FUNC int emcore_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 = EMAIL_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 = EMAIL_ERROR_INVALID_PARAM; /* EMAIL_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); + + if (cmd_type == IMAP4_CMD_EXPUNGE) { + SNPRINTF(cmd, sizeof(cmd), "%s EXPUNGE\015\012", tag); + } + else if (cmd_type == IMAP4_CMD_NOOP) { + SNPRINTF(cmd, sizeof(cmd), "%s NOOP\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)EM_SAFE_STRLEN(cmd))) { EM_DEBUG_EXCEPTION("net_sout failed..."); - + err = EMAIL_ERROR_CONNECTION_BROKEN; goto FINISH_OFF; } - + while (imaplocal->netstream) { /* receive response */ if (!(p = net_getline(imaplocal->netstream))) { @@ -949,30 +967,107 @@ static int imap4_send_command(MAILSTREAM *stream, imap4_cmd_t cmd_type, int *err err = EMAIL_ERROR_INVALID_RESPONSE; /* EMAIL_ERROR_UNKNOWN; */ goto FINISH_OFF; } - + #ifdef FEATURE_CORE_DEBUG EM_DEBUG_LOG("[IMAP4] <<< %s", p); #endif - + if (!strncmp(p, tag, EM_SAFE_STRLEN(tag))) { if (!strncmp(p + EM_SAFE_STRLEN(tag) + 1, "OK", 2)) { EM_SAFE_FREE(p); break; } else { /* 'NO' or 'BAD' */ - err = EMAIL_ERROR_IMAP4_EXPUNGE_FAILURE; /* EMAIL_ERROR_INVALID_RESPONSE; */ + if (cmd_type == IMAP4_CMD_EXPUNGE) { + err = EMAIL_ERROR_IMAP4_EXPUNGE_FAILURE; /* EMAIL_ERROR_INVALID_RESPONSE; */ + } + else if (cmd_type == IMAP4_CMD_NOOP) { + err = EMAIL_ERROR_IMAP4_NOOP_FAILURE; + } goto FINISH_OFF; } } - + EM_SAFE_FREE(p); } - + ret = true; -FINISH_OFF: +FINISH_OFF: EM_SAFE_FREE(p); - + + if (err_code) + *err_code = err; + + return ret; +} + +INTERNAL_FUNC int emcore_pop3_send_command(MAILSTREAM *stream, pop3_cmd_t cmd_type, int *err_code) +{ + EM_DEBUG_FUNC_BEGIN("stream[%p], err_code[%p]", stream, err_code); + + int ret = false; + int err = EMAIL_ERROR_NONE; + + POP3LOCAL *pop3local = NULL; + char cmd[64]; + char *p = NULL; + + if (!stream) { + EM_DEBUG_EXCEPTION("stream[%p]", stream); + err = EMAIL_ERROR_INVALID_PARAM; + goto FINISH_OFF; + } + + if (!(pop3local = stream->local) || !pop3local->netstream) { + EM_DEBUG_EXCEPTION("invalid POP3 stream detected..."); + err = EMAIL_ERROR_UNKNOWN; + goto FINISH_OFF; + } + + memset(cmd, 0x00, sizeof(cmd)); + + if (cmd_type == POP3_CMD_NOOP) + SNPRINTF(cmd, sizeof(cmd), "NOOP\015\012"); + +#ifdef FEATURE_CORE_DEBUG + EM_DEBUG_LOG("[POP3] >>> %s", cmd); +#endif + + /* send command : delete specified mail */ + if (!net_sout(pop3local->netstream, cmd, (int)EM_SAFE_STRLEN(cmd))) { + EM_DEBUG_EXCEPTION("net_sout failed..."); + err = EMAIL_ERROR_CONNECTION_BROKEN; /* EMAIL_ERROR_UNKNOWN; */ + goto FINISH_OFF; + } + + /* receive response */ + if (!(p = net_getline(pop3local->netstream))) { + EM_DEBUG_EXCEPTION("net_getline failed..."); + err = EMAIL_ERROR_INVALID_RESPONSE; + goto FINISH_OFF; + } + +#ifdef FEATURE_CORE_DEBUG + EM_DEBUG_LOG("[POP3] <<< %s", p); +#endif + + if (*p == '-') { /* '-ERR' */ + if (cmd_type == POP3_CMD_NOOP) + err = EMAIL_ERROR_POP3_NOOP_FAILURE; + goto FINISH_OFF; + } + + if (*p != '+') { /* '+OK' ... */ + err = EMAIL_ERROR_INVALID_RESPONSE; + goto FINISH_OFF; + } + + ret = true; + +FINISH_OFF: + EM_SAFE_FREE(p); + if (err_code) *err_code = err; @@ -982,7 +1077,7 @@ FINISH_OFF: int emcore_get_mail_contact_info_with_update(email_mail_contact_info_t *contact_info, char *full_address, int mail_id, int *err_code) { EM_DEBUG_FUNC_BEGIN_SEC("contact_info[%p], full_address[%s], mail_id[%d], err_code[%p]", contact_info, full_address, mail_id, err_code); - + int ret = false; int err = EMAIL_ERROR_NONE; ADDRESS *addr = NULL; @@ -1015,7 +1110,7 @@ int emcore_get_mail_contact_info_with_update(email_mail_contact_info_t *contact_ } else { address_length = 2 * EM_SAFE_STRLEN(full_address); - temp_emailaddr = (char *)calloc(1, address_length); + temp_emailaddr = (char *)calloc(1, address_length); } em_skip_whitespace(full_address , &address); @@ -1025,13 +1120,13 @@ int emcore_get_mail_contact_info_with_update(email_mail_contact_info_t *contact_ /* ',' -> "%2C" */ gchar **tokens = g_strsplit(address, ", ", -1); char *p = g_strjoinv("%2C", tokens); - + g_strfreev(tokens); - + /* ';' -> ',' */ - while (p && p[i] != '\0') + while (p && p[i] != '\0') { - if (p[i] == ';') + if (p[i] == ';') p[i] = ','; i++; } @@ -1056,9 +1151,9 @@ int emcore_get_mail_contact_info_with_update(email_mail_contact_info_t *contact_ err = EMAIL_ERROR_OUT_OF_MEMORY; goto FINISH_OFF; } - + while (addr != NULL) { - if (addr->mailbox && addr->host) { + 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 "); @@ -1074,14 +1169,16 @@ int emcore_get_mail_contact_info_with_update(email_mail_contact_info_t *contact_ 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_SEC(" email_address[%s]", email_address); - + is_searched = false; EM_DEBUG_LOG(" >>>>> emcore_get_mail_contact_info - 10"); - - if (emcore_get_mail_display_name(email_address, &contact_display_name_from_contact_info, &err) && err == EMAIL_ERROR_NONE) { + + err = emcore_get_mail_display_name (email_address, + &contact_display_name_from_contact_info); + if ( err == EMAIL_ERROR_NONE) { contact_display_name = contact_display_name_from_contact_info; EM_DEBUG_LOG_SEC(">>> contact_name[%s]", contact_display_name); @@ -1093,7 +1190,7 @@ int emcore_get_mail_contact_info_with_update(email_mail_contact_info_t *contact_ 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); + contact_name = (char *)calloc(1, contact_name_buffer_size); if (contact_name == NULL) { EM_DEBUG_EXCEPTION("Memory allocation failed."); EM_SAFE_FREE(temp); @@ -1109,13 +1206,13 @@ int emcore_get_mail_contact_info_with_update(email_mail_contact_info_t *contact_ } else { snprintf(temp_string, sizeof(temp_string), "\"%s\" <%s>, ", contact_display_name, email_address); - } + } contact_display_name_len = EM_SAFE_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); + contact_name = (char *)calloc(1, contact_name_buffer_size); if (contact_name == NULL) { EM_DEBUG_EXCEPTION("Memory allocation failed."); EM_SAFE_FREE(temp); @@ -1138,11 +1235,11 @@ int emcore_get_mail_contact_info_with_update(email_mail_contact_info_t *contact_ 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; @@ -1171,13 +1268,13 @@ int emcore_get_mail_contact_info_with_update(email_mail_contact_info_t *contact_ else { snprintf(temp_string, sizeof(temp_string), "\"%s\" <%s>, ", contact_display_name, email_address); } - EM_DEBUG_LOG("temp_string[%s]", temp_string); + EM_DEBUG_LOG_SEC("temp_string[%s]", temp_string); contact_display_name_len = EM_SAFE_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); + contact_name = (char *)calloc(1, contact_name_buffer_size); if (contact_name == NULL) { EM_DEBUG_EXCEPTION("Memory allocation failed."); EM_SAFE_FREE(temp); @@ -1187,14 +1284,14 @@ int emcore_get_mail_contact_info_with_update(email_mail_contact_info_t *contact_ 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_SEC("new contact_name >>>>> %s ", contact_name); } } - if (temp_emailaddr && email_address) { + 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); @@ -1222,7 +1319,7 @@ int emcore_get_mail_contact_info_with_update(email_mail_contact_info_t *contact_ } /* while (addr != NULL) */ if (temp_emailaddr) { - EM_DEBUG_LOG(">>>> TEMPEMAIL ADDR [ %s ] ", temp_emailaddr); + EM_DEBUG_LOG_SEC(">>>> TEMPEMAIL ADDR [ %s ] ", temp_emailaddr); contact_info->email_address = temp_emailaddr; temp_emailaddr = NULL; } @@ -1231,44 +1328,44 @@ int emcore_get_mail_contact_info_with_update(email_mail_contact_info_t *contact_ contact_info->contact_name = g_strdup(contact_name); /*prevent 40020*/ ret = true; - -FINISH_OFF: + +FINISH_OFF: EM_SAFE_FREE(email_address); EM_SAFE_FREE(address); EM_SAFE_FREE(temp_emailaddr); - EM_SAFE_FREE(contact_name); + EM_SAFE_FREE(contact_name); EM_SAFE_FREE(contact_display_name_from_contact_info); - + if (err_code != NULL) *err_code = err; - + return ret; } int emcore_free_contact_info(email_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 = EMAIL_ERROR_NONE; - + if (!contact_info) { EM_DEBUG_EXCEPTION("contact_info[%p]", contact_info); err = EMAIL_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: + +FINISH_OFF: if (err_code != NULL) *err_code = err; EM_DEBUG_FUNC_END(); @@ -1289,13 +1386,13 @@ int emcore_sync_contact_info(int mail_id, int *err_code) email_mail_contact_info_t contact_info_to; email_mail_contact_info_t contact_info_cc; email_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(email_mail_contact_info_t)); + + memset(&contact_info_from, 0x00, sizeof(email_mail_contact_info_t)); memset(&contact_info_to, 0x00, sizeof(email_mail_contact_info_t)); memset(&contact_info_cc, 0x00, sizeof(email_mail_contact_info_t)); - memset(&contact_info_bcc, 0x00, sizeof(email_mail_contact_info_t)); + memset(&contact_info_bcc, 0x00, sizeof(email_mail_contact_info_t)); if (!emstorage_get_mail_by_id(mail_id, &mail, true, &err) || !mail) { EM_DEBUG_EXCEPTION("emstorage_get_mail_by_id failed [%d]", err); @@ -1325,46 +1422,39 @@ int emcore_sync_contact_info(int mail_id, int *err_code) if (!emcore_get_mail_contact_info_with_update(&contact_info_bcc, mail->full_address_bcc, mail_id, &err)) { EM_DEBUG_EXCEPTION("emcore_get_mail_contact_info failed [%d]", err); } - } + } EM_SAFE_FREE(mail->email_address_sender); mail->email_address_sender = contact_info_from.email_address; - contact_info_from.contact_name = NULL; - contact_info_from.email_address = NULL; + EM_SAFE_FREE(mail->email_address_recipient); if (mail->full_address_to != NULL) { mail->email_address_recipient = contact_info_to.email_address; - contact_info_to.contact_name = NULL; - contact_info_to.email_address = NULL; } else if (mail->full_address_cc != NULL) { mail->email_address_recipient = contact_info_cc.email_address; - contact_info_cc.contact_name = NULL; - contact_info_cc.email_address = NULL; } else if (mail->full_address_bcc != NULL) { mail->email_address_recipient = contact_info_bcc.email_address; - contact_info_bcc.contact_name = NULL; - contact_info_bcc.email_address = NULL; } - + /* Update DB */ - if (!emstorage_change_mail_field(mail_id, UPDATE_ALL_CONTACT_INFO, mail, false, &err)) { + if (!emstorage_change_mail_field(mail_id, UPDATE_ALL_CONTACT_INFO, mail, false, &err)) { EM_DEBUG_EXCEPTION("emstorage_change_mail_field failed [%d]", err); goto FINISH_OFF; - } + } ret = true; -FINISH_OFF: +FINISH_OFF: if (mail != NULL) emstorage_free_mail(&mail, 1, NULL); emcore_free_contact_info(&contact_info_from, NULL); emcore_free_contact_info(&contact_info_to, NULL); emcore_free_contact_info(&contact_info_cc, NULL); - emcore_free_contact_info(&contact_info_bcc, NULL); + emcore_free_contact_info(&contact_info_bcc, NULL); if (err_code != NULL) *err_code = err; @@ -1390,7 +1480,7 @@ static int emcore_sync_address_info(email_address_type_t address_type, char *ful char email_address[MAX_EMAIL_ADDRESS_LENGTH]; email_address_info_t *p_address_info = NULL; ADDRESS *addr = NULL; - + if (address_info_list == NULL) { EM_DEBUG_EXCEPTION("Invalid param : address_info_list is NULL"); error = EMAIL_ERROR_INVALID_PARAM; @@ -1404,29 +1494,29 @@ static int emcore_sync_address_info(email_address_type_t address_type, char *ful 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] == ';') + if (p[i] == ';') p[i] = ','; i++; } rfc822_parse_adrlist(&addr, p, NULL); - EM_SAFE_FREE(p); + EM_SAFE_FREE(p); if (!addr) { EM_DEBUG_EXCEPTION("rfc822_parse_adrlist failed..."); - error = EMAIL_ERROR_INVALID_PARAM; + error = EMAIL_ERROR_INVALID_PARAM; goto FINISH_OFF; } /* Get a contact name */ while (addr != NULL) { - if (addr->mailbox && addr->host) { + 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; @@ -1448,26 +1538,26 @@ static int emcore_sync_address_info(email_address_type_t address_type, char *ful EM_DEBUG_EXCEPTION("malloc failed..."); error = EMAIL_ERROR_OUT_OF_MEMORY; goto FINISH_OFF; - } - memset(p_address_info, 0x00, sizeof(email_address_info_t)); + } + memset(p_address_info, 0x00, sizeof(email_address_info_t)); SNPRINTF(email_address, MAX_EMAIL_ADDRESS_LENGTH, "%s@%s", addr->mailbox ? addr->mailbox : "", addr->host ? addr->host : ""); - + EM_DEBUG_LOG_SEC("Search a contact : address[%s]", email_address); is_search = false; - - if (emcore_get_mail_display_name(email_address, &contact_display_name_from_contact_info, &error) && error == EMAIL_ERROR_NONE) { + error = emcore_get_mail_display_name (email_address, + &contact_display_name_from_contact_info); + if (error == EMAIL_ERROR_NONE) { EM_DEBUG_LOG_SEC(">>> contact display name[%s]", contact_display_name_from_contact_info); - is_search = true; } else if (error != EMAIL_ERROR_DATA_NOT_FOUND) EM_DEBUG_EXCEPTION("emcore_get_mail_display_name - 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->contact_id = contact_index; + p_address_info->storage_type = -1; p_address_info->display_name = contact_display_name_from_contact_info; EM_DEBUG_LOG_SEC("display_name from contact[%s]", p_address_info->display_name); } @@ -1476,19 +1566,19 @@ static int emcore_sync_address_info(email_address_type_t address_type, char *ful 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; + 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); @@ -1497,7 +1587,7 @@ static int emcore_sync_address_info(email_address_type_t address_type, char *ful EM_DEBUG_LOG_SEC("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; @@ -1517,17 +1607,17 @@ static int emcore_sync_address_info(email_address_type_t address_type, char *ful } ret = true; - -FINISH_OFF: + +FINISH_OFF: EM_SAFE_FREE(address); if (addr) { mail_free_address(&addr); } - + if (err_code != NULL) - *err_code = error; + *err_code = error; EM_DEBUG_FUNC_END(); return ret; } @@ -1536,9 +1626,9 @@ static gint address_compare(gconstpointer a, gconstpointer b) { EM_DEBUG_FUNC_BEGIN(); email_sender_list_t *recipients_list1 = (email_sender_list_t *)a; - email_sender_list_t *recipients_list2 = (email_sender_list_t *)b; + email_sender_list_t *recipients_list2 = (email_sender_list_t *)b; - EM_DEBUG_FUNC_END(); + EM_DEBUG_FUNC_END(); return strcmp(recipients_list1->address, recipients_list2->address); } @@ -1558,7 +1648,7 @@ INTERNAL_FUNC GList *emcore_get_recipients_list(GList *old_recipients_list, char email_sender_list_t *temp_recipients_list = NULL; email_sender_list_t *old_recipients_list_t = NULL; - + if (full_address == NULL || EM_SAFE_STRLEN(full_address) == 0) { EM_DEBUG_EXCEPTION("Invalid param : full_address NULL or empty"); err = EMAIL_ERROR_INVALID_PARAM; @@ -1573,7 +1663,7 @@ INTERNAL_FUNC GList *emcore_get_recipients_list(GList *old_recipients_list, char g_strfreev(tokens); while (p && p[i] != '\0') { - if (p[i] == ';') + if (p[i] == ';') p[i] = ','; i++; } @@ -1594,25 +1684,26 @@ INTERNAL_FUNC GList *emcore_get_recipients_list(GList *old_recipients_list, char EM_DEBUG_LOG("Invalid address "); addr = addr->next; continue; - } + } } else { EM_DEBUG_LOG("Error in parsing..! "); addr = addr->next; continue; - } - + } + if ((temp_recipients_list = g_new0(email_sender_list_t, 1)) == NULL) { EM_DEBUG_EXCEPTION("EMAIL_ERROR_OUT_OF_MEMORY"); err = EMAIL_ERROR_OUT_OF_MEMORY; goto FINISH_OFF; } - + SNPRINTF(email_address, MAX_EMAIL_ADDRESS_LENGTH, "%s@%s", addr->mailbox ? addr->mailbox : "", addr->host ? addr->host : ""); EM_DEBUG_LOG_SEC("Search a contact : address[%s]", email_address); - if (emcore_get_mail_display_name(email_address, &display_name, &err) && err == EMAIL_ERROR_NONE) { + err = emcore_get_mail_display_name(email_address, &display_name); + if ( err == EMAIL_ERROR_NONE) { EM_DEBUG_LOG_SEC(">>> contact display name[%s]", display_name); is_search = true; } else { @@ -1675,7 +1766,7 @@ FINISH_OFF: *err_code = err; EM_DEBUG_FUNC_END(); - return new_recipients_list; + return new_recipients_list; } INTERNAL_FUNC int emcore_get_mail_address_info_list(int mail_id, email_address_info_list_t **address_info_list, int *err_code) @@ -1684,7 +1775,6 @@ INTERNAL_FUNC int emcore_get_mail_address_info_list(int mail_id, email_address_i int ret = false, err = EMAIL_ERROR_NONE; int failed = true; - int contact_error; emstorage_mail_tbl_t *mail = NULL; email_address_info_list_t *p_address_info_list = NULL; @@ -1694,11 +1784,11 @@ INTERNAL_FUNC int emcore_get_mail_address_info_list(int mail_id, email_address_i err = EMAIL_ERROR_INVALID_PARAM; goto FINISH_OFF; } - + /* get mail from mail table */ if (!emstorage_get_mail_by_id(mail_id, &mail, true, &err) || !mail) { EM_DEBUG_EXCEPTION("emstorage_get_mail_by_id failed [%d]", err); - + goto FINISH_OFF; } @@ -1707,12 +1797,11 @@ INTERNAL_FUNC int emcore_get_mail_address_info_list(int mail_id, email_address_i EM_DEBUG_EXCEPTION("malloc failed..."); err = EMAIL_ERROR_OUT_OF_MEMORY; goto FINISH_OFF; - } - memset(p_address_info_list, 0x00, sizeof(email_address_info_list_t)); + } + memset(p_address_info_list, 0x00, sizeof(email_address_info_list_t)); - if ((contact_error = contacts_connect2 ()) != CONTACTS_ERROR_NONE) { - EM_DEBUG_EXCEPTION("contacts_connect2 failed [%d]", contact_error); - err = EMAIL_ERROR_DB_FAILURE; + if ((err = emcore_connect_contacts_service()) != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emcore_connect_contacts_service error : [%d]", err); goto FINISH_OFF; } @@ -1725,14 +1814,15 @@ INTERNAL_FUNC int emcore_get_mail_address_info_list(int mail_id, email_address_i if (mail->full_address_bcc && emcore_sync_address_info(EMAIL_ADDRESS_TYPE_BCC, mail->full_address_bcc, &p_address_info_list->bcc, &err)) failed = false; - if ((contact_error = contacts_disconnect2 ()) != CONTACTS_ERROR_NONE) - EM_DEBUG_EXCEPTION("contacts_connect2 failed [%d]", contact_error); + if ((err = emcore_disconnect_contacts_service()) != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emcore_disconnect_contacts_service failed : [%d]", err); + } if (failed == false) ret = true; -FINISH_OFF: - if (ret == true) +FINISH_OFF: + if (ret == true) *address_info_list = p_address_info_list; else if (p_address_info_list != NULL) emstorage_free_address_info_list(&p_address_info_list); @@ -1748,22 +1838,22 @@ FINISH_OFF: /* description * get a mail data - * arguments + * arguments * input_mail_id : [in] mail id * output_mail_data : [out] double pointer to hold mail data. - * return + * return * succeed : EMAIL_ERROR_NONE * fail : error code */ INTERNAL_FUNC int emcore_get_mail_data(int input_mail_id, email_mail_data_t **output_mail_data) { EM_DEBUG_FUNC_BEGIN("input_mail_id[%d], output_mail_data[%p]", input_mail_id, output_mail_data); - + int error = EMAIL_ERROR_NONE; int result_mail_count = 0; char conditional_clause_string[QUERY_SIZE] = { 0, }; emstorage_mail_tbl_t *result_mail_tbl = NULL; - + if (input_mail_id == 0 || !output_mail_data) { EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM"); error = EMAIL_ERROR_INVALID_PARAM; @@ -1771,7 +1861,7 @@ INTERNAL_FUNC int emcore_get_mail_data(int input_mail_id, email_mail_data_t **ou } SNPRINTF(conditional_clause_string, QUERY_SIZE, "WHERE mail_id = %d", input_mail_id); - + if(!emstorage_query_mail_tbl(conditional_clause_string, true, &result_mail_tbl, &result_mail_count, &error)) { EM_DEBUG_EXCEPTION("emstorage_query_mail_tbl falied [%d]", error); goto FINISH_OFF; @@ -1781,8 +1871,8 @@ INTERNAL_FUNC int emcore_get_mail_data(int input_mail_id, email_mail_data_t **ou EM_DEBUG_EXCEPTION("em_convert_mail_tbl_to_mail_data falied [%d]", error); goto FINISH_OFF; } - -FINISH_OFF: + +FINISH_OFF: if (result_mail_tbl) emstorage_free_mail(&result_mail_tbl, result_mail_count, NULL); @@ -1795,31 +1885,6 @@ int emcore_check_drm(emstorage_attachment_tbl_t *input_attachment_tb_data) { EM_DEBUG_FUNC_BEGIN(); int ret = 0; -#ifdef __FEATURE_DRM__ - drm_bool_type_e drm_file = DRM_UNKNOWN; - drm_file_info_s drm_file_info; - - if (input_attachment_tb_data == NULL) - return ret; - - ret = drm_is_drm_file(input_attachment_tb_data->attachment_path, &drm_file); - - if (ret == DRM_RETURN_SUCCESS && drm_file == DRM_TRUE) { - if (drm_get_file_info (input_attachment_tb_data->attachment_path, &drm_file_info) == DRM_RETURN_SUCCESS) { - input_attachment_tb_data->attachment_drm_type = 0; - EM_DEBUG_LOG ("fileInfo is [%d]", drm_file_info.oma_info.method); - if (drm_file_info.oma_info.method != DRM_METHOD_TYPE_UNDEFINED) { - input_attachment_tb_data->attachment_drm_type = drm_file_info.oma_info.method; - ret = 1; - } - } - } - else { - EM_DEBUG_LOG("not DRM file %s", input_attachment_tb_data->attachment_path); - input_attachment_tb_data->attachment_drm_type = 0; - ret = 0; - } -#endif EM_DEBUG_FUNC_END(); return ret; } @@ -1827,12 +1892,12 @@ int emcore_check_drm(emstorage_attachment_tbl_t *input_attachment_tb_data) /* description * get mail attachment from local mailbox - * arguments + * 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 + * return * succeed : 1 * fail : 0 */ @@ -1846,27 +1911,28 @@ INTERNAL_FUNC int emcore_get_attachment_info(int attachment_id, email_attachment *err_code = EMAIL_ERROR_INVALID_PARAM; return false; } - + int ret = false; int err = EMAIL_ERROR_NONE; emstorage_attachment_tbl_t *attachment_tbl = NULL; - + /* get attachment from attachment tbl */ if (!emstorage_get_attachment(attachment_id, &attachment_tbl, true, &err) || !attachment_tbl) { EM_DEBUG_EXCEPTION("emstorage_get_attachment failed [%d]", err); goto FINISH_OFF; } - + *attachment = em_malloc(sizeof(email_attachment_data_t)); if (!*attachment) { EM_DEBUG_EXCEPTION("malloc failed..."); err = EMAIL_ERROR_OUT_OF_MEMORY; goto FINISH_OFF; } - + (*attachment)->attachment_id = attachment_id; (*attachment)->attachment_name = attachment_tbl->attachment_name; attachment_tbl->attachment_name = NULL; + (*attachment)->content_id = attachment_tbl->content_id; attachment_tbl->content_id = NULL; (*attachment)->attachment_size = attachment_tbl->attachment_size; (*attachment)->save_status = attachment_tbl->attachment_save_status; (*attachment)->attachment_path = attachment_tbl->attachment_path; attachment_tbl->attachment_path = NULL; @@ -1876,30 +1942,30 @@ INTERNAL_FUNC int emcore_get_attachment_info(int attachment_id, email_attachment ret = true; -FINISH_OFF: +FINISH_OFF: if (attachment_tbl) emstorage_free_attachment(&attachment_tbl, 1, NULL); if (err_code) *err_code = err; - + return ret; } /* description * get mail attachment - * arguments + * arguments * input_mail_id : mail id to own attachment * output_attachment_data : result attahchment data * output_attachment_count : result attahchment count - * return + * return * succeed : EMAIL_ERROR_NONE * fail : error code */ INTERNAL_FUNC int emcore_get_attachment_data_list(int input_mail_id, email_attachment_data_t **output_attachment_data, int *output_attachment_count) { 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("EMAIL_ERROR_INVALID_PARAM"); return EMAIL_ERROR_INVALID_PARAM; @@ -1910,13 +1976,13 @@ INTERNAL_FUNC int emcore_get_attachment_data_list(int input_mail_id, email_attac int attachment_tbl_count = 0; emstorage_attachment_tbl_t *attachment_tbl_list = NULL; email_attachment_data_t *temp_attachment_data = NULL; - + /* get attachment from attachment tbl */ if ( (err = emstorage_get_attachment_list(input_mail_id, true, &attachment_tbl_list, &attachment_tbl_count)) != EMAIL_ERROR_NONE ){ EM_DEBUG_EXCEPTION("emstorage_get_attachment_list failed [%d]", err); goto FINISH_OFF; - } + } if (attachment_tbl_count) { EM_DEBUG_LOG("attachment count %d", attachment_tbl_count); @@ -1935,6 +2001,7 @@ INTERNAL_FUNC int emcore_get_attachment_data_list(int input_mail_id, email_attac 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->content_id = attachment_tbl_list[i].content_id; attachment_tbl_list[i].content_id = 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; @@ -1945,25 +2012,26 @@ INTERNAL_FUNC int emcore_get_attachment_data_list(int input_mail_id, email_attac temp_attachment_data->attachment_mime_type = attachment_tbl_list[i].attachment_mime_type; attachment_tbl_list[i].attachment_mime_type = NULL; } } - -FINISH_OFF: - + +FINISH_OFF: + *output_attachment_count = attachment_tbl_count; if (attachment_tbl_list) emstorage_free_attachment(&attachment_tbl_list, attachment_tbl_count, NULL); - + return err; } -INTERNAL_FUNC int emcore_download_attachment(int account_id, int mail_id, int nth, int *err_code) +INTERNAL_FUNC int emcore_download_attachment (int account_id, int mail_id, int nth, + int cancellable, int event_handle, int *err_code) { EM_DEBUG_FUNC_BEGIN("account_id[%d], mail_id[%d], nth[%d], err_code[%p]", account_id, mail_id, nth, err_code); int err = EMAIL_ERROR_NONE; - if (mail_id < 1) { + if (mail_id < 1) { EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM"); err = EMAIL_ERROR_INVALID_PARAM; @@ -1975,7 +2043,6 @@ INTERNAL_FUNC int emcore_download_attachment(int account_id, int mail_id, int nt } int ret = false; - int status = EMAIL_DOWNLOAD_FAIL; MAILSTREAM *stream = NULL; BODY *mbody = NULL; emstorage_mail_tbl_t *mail = NULL; @@ -1992,13 +2059,11 @@ INTERNAL_FUNC int emcore_download_attachment(int account_id, int mail_id, int nt int server_mbox_id = 0; int decoded_attachment_size = 0; - if (!emcore_check_thread_status()) { - err = EMAIL_ERROR_CANCELLED; - goto FINISH_OFF; - } - + if (cancellable) + FINISH_OFF_IF_EVENT_CANCELED (err, event_handle); + only_body_download = false; - + /* get mail from mail table. */ if (!emstorage_get_mail_by_id(mail_id, &mail, true, &err) || !mail) { EM_DEBUG_EXCEPTION("emstorage_get_mail_by_id failed [%d]", err); @@ -2010,7 +2075,7 @@ INTERNAL_FUNC int emcore_download_attachment(int account_id, int mail_id, int nt err = EMAIL_ERROR_MAIL_NOT_FOUND_ON_SERVER; goto FINISH_OFF; } - + if (nth == 0) { /* download all attachments, nth starts from 1, not zero */ /* get attachment list from db */ attachment_count_to_be_downloaded = EMAIL_ATTACHMENT_MAX_COUNT; @@ -2027,12 +2092,10 @@ INTERNAL_FUNC int emcore_download_attachment(int account_id, int mail_id, int nt goto FINISH_OFF; } } - - if (!emcore_check_thread_status()) { - err = EMAIL_ERROR_CANCELLED; - goto FINISH_OFF; - } - + + if (cancellable) + FINISH_OFF_IF_EVENT_CANCELED (err, event_handle); + account_id = mail->account_id; server_uid = EM_SAFE_STRDUP(mail->server_mail_id); server_mbox_id = mail->mailbox_id; @@ -2047,12 +2110,11 @@ INTERNAL_FUNC int emcore_download_attachment(int account_id, int mail_id, int nt EM_DEBUG_EXCEPTION("emcore_connect_to_remote_mailbox failed [%d]", err); if(err == EMAIL_ERROR_NO_SUCH_HOST) err = EMAIL_ERROR_CONNECTION_FAILURE; - status = EMAIL_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); @@ -2062,23 +2124,21 @@ INTERNAL_FUNC int emcore_download_attachment(int account_id, int mail_id, int nt else /* download only nth attachment */ current_attachment_no = nth; /* attachment no */ - if (!emcore_check_thread_status()) { - err = EMAIL_ERROR_CANCELLED; - goto FINISH_OFF; - } - + if (cancellable) + FINISH_OFF_IF_EVENT_CANCELED (err, event_handle); + /*free cnt_info before reusing*/ if (cnt_info) { emcore_free_content_info(cnt_info); EM_SAFE_FREE(cnt_info); } - + if (!(cnt_info = em_malloc(sizeof(struct _m_content_info)))) { EM_DEBUG_EXCEPTION("malloc failed..."); err = EMAIL_ERROR_OUT_OF_MEMORY; goto FINISH_OFF; } - + cnt_info->grab_type = GRAB_TYPE_ATTACHMENT; /* attachment */ cnt_info->file_no = current_attachment_no; /* attachment no */ @@ -2090,11 +2150,9 @@ INTERNAL_FUNC int emcore_download_attachment(int account_id, int mail_id, int nt /* set sparep(member of BODY) memory free function. */ mail_parameters(stream, SET_FREEBODYSPAREP, emcore_free_body_sparep); - - if (!emcore_check_thread_status()) { - err = EMAIL_ERROR_CANCELLED; - goto FINISH_OFF; - } + + if (cancellable) + FINISH_OFF_IF_EVENT_CANCELED (err, event_handle); msg_no = server_uid? atoi(server_uid): 0; @@ -2105,17 +2163,15 @@ INTERNAL_FUNC int emcore_download_attachment(int account_id, int mail_id, int nt goto FINISH_OFF; } - if (!emcore_check_thread_status()) { - err = EMAIL_ERROR_CANCELLED; - goto FINISH_OFF; - } + if (cancellable) + FINISH_OFF_IF_EVENT_CANCELED (err, event_handle); /* set body fetch section. */ if (emcore_set_fetch_body_section(mbody, false, NULL, NULL, &err) < 0) { EM_DEBUG_EXCEPTION("emcore_set_fetch_body_section failed [%d]", err); goto FINISH_OFF; } - + /* download attachment. */ _imap4_received_body_size = 0; _imap4_last_notified_body_size = 0; @@ -2123,25 +2179,26 @@ INTERNAL_FUNC int emcore_download_attachment(int account_id, int mail_id, int nt _imap4_download_noti_interval_value = 0; /* This will be assigned in imap_mail_write_body_to_file() */ EM_DEBUG_LOG("cnt_info->file_no[%d], current_attachment_no[%d]", cnt_info->file_no, current_attachment_no); - if (emcore_get_body(stream, account_id, mail_id, msg_no, mbody, cnt_info, &err) < 0) { + if (emcore_get_body(stream, account_id, mail_id, msg_no, mbody, NULL, cnt_info, &err) < 0) { EM_DEBUG_EXCEPTION("emcore_get_body failed [%d]", err); goto FINISH_OFF; } - if (!emcore_check_thread_status()) { - err = EMAIL_ERROR_CANCELLED; - goto FINISH_OFF; - } + if (cancellable) + FINISH_OFF_IF_EVENT_CANCELED (err, event_handle); /* select target attachment information. */ for (ai = cnt_info->file ; ai; ai = ai->next) { - EM_DEBUG_LOG_SEC("[in loop] name[%s] save[%s] no[%d]", ai->save, ai->name, cnt_info->file_no); + EM_DEBUG_LOG_SEC("[in loop] save[%s] name[%s] no[%d]", ai->save, ai->name, cnt_info->file_no); + + if (ai->type == INLINE_ATTACHMENT) + continue; + if (--cnt_info->file_no == 0) break; } - EM_DEBUG_LOG("selected cnt_info->file_no = %d, ai = %p", cnt_info->file_no, ai); - + if (cnt_info->file_no == 0 && ai) { /* rename temporary file to real file. */ if (!emstorage_create_dir(account_id, mail_id, current_attachment_no, &err)) { @@ -2149,7 +2206,7 @@ INTERNAL_FUNC int emcore_download_attachment(int account_id, int mail_id, int nt goto FINISH_OFF; } - if (!emstorage_get_save_name(account_id, mail_id, current_attachment_no, ai->name, buf, &err)) { + if (!emstorage_get_save_name(account_id, mail_id, current_attachment_no, ai->name, buf, sizeof(buf), &err)) { EM_DEBUG_EXCEPTION("emstorage_get_save_name failed [%d]", err); goto FINISH_OFF; } @@ -2164,8 +2221,10 @@ INTERNAL_FUNC int emcore_download_attachment(int account_id, int mail_id, int nt emcore_get_file_size(buf, &decoded_attachment_size, NULL); EM_DEBUG_LOG("decoded_attachment_size [%d]", decoded_attachment_size); - attachment->attachment_size = decoded_attachment_size; - attachment->attachment_path = EM_SAFE_STRDUP(buf); + attachment->attachment_size = decoded_attachment_size; + attachment->attachment_path = EM_SAFE_STRDUP(buf); + attachment->content_id = EM_SAFE_STRDUP(ai->content_id); + attachment->attachment_save_status = 1; /* update attachment information. */ if (!emstorage_change_attachment_field(mail_id, UPDATE_SAVENAME, attachment, true, &err)) { @@ -2175,29 +2234,29 @@ INTERNAL_FUNC int emcore_download_attachment(int account_id, int mail_id, int nt goto FINISH_OFF; } - -#ifdef __FEATURE_DRM__ - if (emcore_check_drm(attachment)) { /* has drm attachment ? */ - if (drm_process_request(DRM_REQUEST_TYPE_REGISTER_FILE, (void *)attachment->attachment_path, NULL) == DRM_RETURN_SUCCESS) - EM_DEBUG_LOG("drm_svc_register_file success"); - else - EM_DEBUG_EXCEPTION("drm_svc_register_file fail"); - mail->DRM_status = attachment->attachment_drm_type; - } -#endif /* __FEATURE_DRM__ */ } else { EM_DEBUG_EXCEPTION("invalid attachment sequence..."); err = EMAIL_ERROR_INVALID_ATTACHMENT; goto FINISH_OFF; } - + EM_DEBUG_LOG(" >>>>>> Attachment Downloading [%d / %d] completed", i+1, attachment_count_to_be_downloaded); } ret = true; - + FINISH_OFF: + + if (ret == true) + emcore_notify_network_event(NOTI_DOWNLOAD_ATTACH_FINISH, mail_id, NULL, nth, 0); + else { + if (err != EMAIL_ERROR_CANCELLED) + emcore_notify_network_event(NOTI_DOWNLOAD_ATTACH_FAIL, mail_id, NULL, nth, err); + } + + EM_SAFE_FREE(server_uid); + if (stream) { stream = mail_close (stream); } @@ -2208,27 +2267,299 @@ FINISH_OFF: emcore_free_content_info(cnt_info); EM_SAFE_FREE(cnt_info); } + if (mail) emstorage_free_mail(&mail, 1, NULL); - EM_SAFE_FREE(server_uid); + if (err_code != NULL) + *err_code = err; - if (ret == true) - emcore_notify_network_event(NOTI_DOWNLOAD_ATTACH_FINISH, mail_id, NULL, nth, 0); + EM_DEBUG_FUNC_END(); + return ret; +} + +INTERNAL_FUNC int emcore_gmime_download_attachment(int mail_id, int nth, + int cancellable, int event_handle, int auto_download, int *err_code) +{ + EM_DEBUG_FUNC_BEGIN("mail_id[%d], nth[%d], err_code[%p]", mail_id, nth, err_code); + + int err = EMAIL_ERROR_NONE; + + if (mail_id < 1) { + EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM"); + err = EMAIL_ERROR_INVALID_PARAM; + + if (err_code != NULL) + *err_code = err; + + if (!auto_download) + emcore_notify_network_event(NOTI_DOWNLOAD_ATTACH_FAIL, mail_id, 0, nth, err); + return FALSE; + } + + int ret = FALSE; + MAILSTREAM *stream = NULL; + BODY *mbody = NULL; + emstorage_mail_tbl_t *mail = NULL; + emstorage_attachment_tbl_t *attachment = NULL; + emstorage_attachment_tbl_t *attachment_list = NULL; + + struct attachment_info *ai = NULL; + struct _m_content_info *cnt_info = NULL; + void *tmp_stream = NULL; + char *server_uid = NULL; + char buf[1024]; + + int msg_no = 0; + int account_id = 0; + int server_mbox_id = 0; + + int current_attachment_no = 0; + int attachment_count = 0; + int decoded_attachment_size = 0; + int i = 0; + + GMimeMessage *message = NULL; + + if (cancellable) + FINISH_OFF_IF_EVENT_CANCELED (err, event_handle); + + /* get mail from mail table. */ + if (!emstorage_get_mail_by_id(mail_id, &mail, true, &err) || !mail) { + EM_DEBUG_EXCEPTION("emstorage_get_mail_by_id failed [%d]", err); + goto FINISH_OFF; + } + + if (!mail->server_mail_status) { + EM_DEBUG_EXCEPTION("not synchronous mail..."); + err = EMAIL_ERROR_MAIL_NOT_FOUND_ON_SERVER; + goto FINISH_OFF; + } + + if (nth == 0) { /* download all attachments, nth starts from 1, not zero */ + if ((err = emstorage_get_attachment_list(mail_id, true, &attachment_list, &attachment_count)) != EMAIL_ERROR_NONE ) { + EM_DEBUG_EXCEPTION("emstorage_get_attachment_list failed [%d]", err); + goto FINISH_OFF; + } + } + else { /* download only nth attachment */ + attachment_count = 1; + if (!emstorage_get_attachment_nth(mail_id, nth, &attachment_list, true, &err) || !attachment_list) { + EM_DEBUG_EXCEPTION("emstorage_get_attachment_nth failed [%d]", err); + + goto FINISH_OFF; + } + } + + if (cancellable) + FINISH_OFF_IF_EVENT_CANCELED (err, event_handle); + + account_id = mail->account_id; + server_uid = EM_SAFE_STRDUP(mail->server_mail_id); + server_mbox_id = mail->mailbox_id; + + if (attachment_count == 1 && attachment_list) { + if (!auto_download) { + if (!emcore_notify_network_event(NOTI_DOWNLOAD_ATTACH_START, mail_id, attachment_list[0].attachment_name, nth, 0)) + EM_DEBUG_EXCEPTION("emcore_notify_network_event [ NOTI_DOWNLOAD_ATTACH_START] Failed >>>>"); + } + } + + /* open mail server. */ + if (!auto_download) { + if (!emcore_connect_to_remote_mailbox(account_id, server_mbox_id, (void **)&tmp_stream, &err) || !tmp_stream) { + EM_DEBUG_EXCEPTION("emcore_connect_to_remote_mailbox failed [%d]", err); + if(err == EMAIL_ERROR_NO_SUCH_HOST) + err = EMAIL_ERROR_CONNECTION_FAILURE; + goto FINISH_OFF; + } + + stream = (MAILSTREAM *)tmp_stream; + } else { - if (err != EMAIL_ERROR_CANCELLED) - emcore_notify_network_event(NOTI_DOWNLOAD_ATTACH_FAIL, mail_id, NULL, nth, err); + MAILSTREAM **mstream = NULL; + mstream = emcore_get_recv_stream (account_id, server_mbox_id, &err); + + if (!mstream) { + EM_DEBUG_EXCEPTION("emcore_get_recv_stream failed [%d]", err); + goto FINISH_OFF; + } + stream = (MAILSTREAM *)*mstream; + } + + for (i = 0; i < attachment_count; i++) { + EM_DEBUG_LOG(" >>>>>> Attachment Downloading [%d / %d] start", i+1, attachment_count); + + attachment = attachment_list + i; + + if (nth == 0) /* download all attachments, nth starts from 1, not zero */ + current_attachment_no = i + 1; /* attachment no */ + else /* download only nth attachment */ + current_attachment_no = nth; /* attachment no */ + + if (cancellable) + FINISH_OFF_IF_EVENT_CANCELED (err, event_handle); + + /*free cnt_info before reusing*/ + if (cnt_info) { + emcore_free_content_info(cnt_info); + EM_SAFE_FREE(cnt_info); + } + + if (!(cnt_info = em_malloc(sizeof(struct _m_content_info)))) { + EM_DEBUG_EXCEPTION("malloc failed..."); + err = EMAIL_ERROR_OUT_OF_MEMORY; + goto FINISH_OFF; + } + + cnt_info->grab_type = GRAB_TYPE_ATTACHMENT; /* attachment */ + cnt_info->file_no = current_attachment_no; /* attachment no */ + + /* set sparep(member of BODY) memory free function. */ + mail_parameters(stream, SET_FREEBODYSPAREP, emcore_free_body_sparep); + + if (cancellable) + FINISH_OFF_IF_EVENT_CANCELED (err, event_handle); + + msg_no = server_uid? atoi(server_uid): 0; + + /* get body structure. */ + /* don't free mbody because mbody is freed in closing mail_stream. */ + if ((!stream) || emcore_get_body_structure(stream, msg_no, &mbody, &err) < 0) { + EM_DEBUG_EXCEPTION("emcore_get_body_structure failed [%d]", err); + goto FINISH_OFF; + } + + if (cancellable) + FINISH_OFF_IF_EVENT_CANCELED (err, event_handle); + + if (!emcore_gmime_construct_mime_part_with_bodystructure(mbody, &message, "1", NULL)) { + EM_DEBUG_EXCEPTION("emcore_gmime_construct_mime_part_with_bodystructure failed"); + goto FINISH_OFF; + } + + if (g_strrstr(mail->full_address_from, "mmsc.plusnet.pl") != NULL || + g_strrstr(mail->full_address_from, "mms.t-mobile.pl") != NULL) { + cnt_info->attachment_only = 1; + } + + /* fill up section list */ + g_mime_message_foreach(message, emcore_gmime_get_attachment_section_foreach_cb, (gpointer)cnt_info); + cnt_info->file_no = current_attachment_no; + + /* FETCH sections */ + if (!emcore_gmime_fetch_imap_attachment_section(stream, mail_id, msg_no, + current_attachment_no, cnt_info, message, auto_download, event_handle, &err)) { + EM_DEBUG_EXCEPTION("emcore_gmime_fetch_imap_attachment_section failed"); + goto FINISH_OFF; + } + + /* decode contents */ + g_mime_message_foreach(message, emcore_gmime_imap_parse_full_foreach_cb, (gpointer)cnt_info); + + if (message) { + g_object_unref(message); + message = NULL; + } + + if (cancellable) + FINISH_OFF_IF_EVENT_CANCELED (err, event_handle); + + /* select target attachment information. */ + for (ai = cnt_info->file ; ai; ai = ai->next) { + EM_DEBUG_LOG_SEC("[in loop] save[%s] name[%s] no[%d]", ai->save, ai->name, cnt_info->file_no); + + if (--cnt_info->file_no == 0) + break; + } + EM_DEBUG_LOG("selected cnt_info->file_no = %d, ai = %p", cnt_info->file_no, ai); + + if (cnt_info->file_no != 0 || ai == NULL) { + EM_DEBUG_EXCEPTION("invalid attachment sequence..."); + err = EMAIL_ERROR_INVALID_ATTACHMENT; + goto FINISH_OFF; + } + + /* rename temporary file to real file. */ + if (!emstorage_create_dir(account_id, mail_id, current_attachment_no, &err)) { + EM_DEBUG_EXCEPTION("emstorage_create_dir failed [%d]", err); + goto FINISH_OFF; + } + + if (!emstorage_get_save_name(account_id, mail_id, current_attachment_no, ai->name, buf, sizeof(buf), &err)) { + EM_DEBUG_EXCEPTION("emstorage_get_save_name failed [%d]", err); + goto FINISH_OFF; + } + + if (!emstorage_move_file(ai->save, buf, false, &err)) { + EM_DEBUG_EXCEPTION("emstorage_move_file failed [%d]", err); + err = EMAIL_ERROR_INVALID_ATTACHMENT_SAVE_NAME; + goto FINISH_OFF; + } + + emcore_get_file_size(buf, &decoded_attachment_size, NULL); + EM_DEBUG_LOG("decoded_attachment_size [%d]", decoded_attachment_size); + attachment->attachment_size = decoded_attachment_size; + attachment->attachment_path = EM_SAFE_STRDUP(buf); + attachment->content_id = EM_SAFE_STRDUP(ai->content_id); + attachment->attachment_save_status = 1; + + /* update attachment information. */ + if (!emstorage_change_attachment_field(mail_id, UPDATE_SAVENAME, attachment, true, &err)) { + EM_DEBUG_EXCEPTION("emstorage_change_attachment_field failed [%d]", err); + /* delete created file. */ + g_remove(buf); + goto FINISH_OFF; + } + + EM_DEBUG_LOG(">>>>>> Attachment Downloading [%d/%d] completed", i+1, attachment_count); } + ret = TRUE; + +FINISH_OFF: + + if (!auto_download) { + if (ret == TRUE) + emcore_notify_network_event(NOTI_DOWNLOAD_ATTACH_FINISH, mail_id, NULL, nth, 0); + else { + if (err != EMAIL_ERROR_CANCELLED) + emcore_notify_network_event(NOTI_DOWNLOAD_ATTACH_FAIL, mail_id, NULL, nth, err); + } + } + + EM_SAFE_FREE(server_uid); + + if (message) { + g_object_unref(message); + message = NULL; + } + + if (stream && !auto_download) { + stream = mail_close(stream); + } + + if (attachment_list) + emstorage_free_attachment(&attachment_list, attachment_count, NULL); + + if (cnt_info) { + emcore_free_content_info(cnt_info); + EM_SAFE_FREE(cnt_info); + } + + if (mail) + emstorage_free_mail(&mail, 1, NULL); + if (err_code != NULL) *err_code = err; - + EM_DEBUG_FUNC_END(); return ret; } + #ifdef __ATTACHMENT_OPTI__ -INTERNAL_FUNC int emcore_download_attachment_bulk(int account_id, int mail_id, int nth, int *err_code) +INTERNAL_FUNC int emcore_download_attachment_bulk(int account_id, int mail_id, int nth, int event_handle, int *err_code) { EM_DEBUG_FUNC_BEGIN("account_id[%d], mail_id[%d], nth[%d], err_code[%p]", account_id, mail_id, nth, err_code); @@ -2259,7 +2590,7 @@ INTERNAL_FUNC int emcore_download_attachment_bulk(int account_id, int mail_id, i email_file_list *pFileList = NULL; #endif /* SUPPORT_EXTERNAL_MEMORY */ int decoded_attachment_size = 0; - + memset(buf, 0x00, 512); /* CID FIX 31230 */ if (mail_id < 1 || !nth) { @@ -2277,13 +2608,11 @@ INTERNAL_FUNC int emcore_download_attachment_bulk(int account_id, int mail_id, i return false; } - - if (!emcore_check_thread_status()) { - err = EMAIL_ERROR_CANCELLED; - goto FINISH_OFF; - } + + FINISH_OFF_IF_EVENT_CANCELED (err, event_handle); + only_body_download = false; - + attachment_no = atoi(nth); if (attachment_no == 0) { @@ -2292,7 +2621,7 @@ INTERNAL_FUNC int emcore_download_attachment_bulk(int account_id, int mail_id, i attachment_count_to_be_downloaded = EMAIL_ATTACHMENT_MAX_COUNT; if ( (err = emstorage_get_attachment_list(mail_id, true, &attachment_list, &attachment_count_to_be_downloaded)) != EMAIL_ERROR_NONE || !attachment_list){ EM_DEBUG_EXCEPTION("emstorage_get_attachment_list failed [%d]", err); - + goto FINISH_OFF; } } @@ -2307,26 +2636,19 @@ INTERNAL_FUNC int emcore_download_attachment_bulk(int account_id, int mail_id, i } - if (!emcore_check_thread_status()) { - err = EMAIL_ERROR_CANCELLED; - goto FINISH_OFF; - } + FINISH_OFF_IF_EVENT_CANCELED (err, event_handle); - /* get mail from mail table. */ if (!emstorage_get_mail_by_id(mail_id, &mail, true, &err) || !mail) { EM_DEBUG_EXCEPTION("emstorage_get_mail_by_id failed [%d]", err); - + goto FINISH_OFF; } /* if (!mail->server_mail_yn || !mail->text_download_yn) {*/ /* faizan.h@samsung.com */ - if (!emcore_check_thread_status()) { - err = EMAIL_ERROR_CANCELLED; - goto FINISH_OFF; - } + FINISH_OFF_IF_EVENT_CANCELED (err, event_handle); account_id = mail->account_id; s_uid = EM_SAFE_STRDUP(mail->server_mail_id); mail->server_mail_id = NULL; @@ -2344,12 +2666,7 @@ INTERNAL_FUNC int emcore_download_attachment_bulk(int account_id, int mail_id, i stream = (MAILSTREAM *)tmp_stream; - - if (!emcore_check_thread_status()) { - err = EMAIL_ERROR_CANCELLED; - goto FINISH_OFF; - } - + FINISH_OFF_IF_EVENT_CANCELED (err, event_handle); 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); @@ -2364,17 +2681,14 @@ INTERNAL_FUNC int emcore_download_attachment_bulk(int account_id, int mail_id, i current_attachment_no = attachment_no; /* attachment no */ } - if (!emcore_check_thread_status()) { - err = EMAIL_ERROR_CANCELLED; - goto FINISH_OFF; - } + FINISH_OFF_IF_EVENT_CANCELED (err, event_handle); _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 (!emcore_get_temp_file_name(&savefile, &err)) { EM_DEBUG_EXCEPTION("emcore_get_temp_file_name failed [%d]", err); @@ -2402,7 +2716,7 @@ INTERNAL_FUNC int emcore_download_attachment_bulk(int account_id, int mail_id, i EM_DEBUG_EXCEPTION("emstorage_mail_check_free_space failed [%d]", err); goto FINISH_OFF; } - + if (bIs_full) { /* If external memory not present, return error */ if (PS_MMC_REMOVED == emstorage_get_mmc_status()) { @@ -2431,8 +2745,9 @@ INTERNAL_FUNC int emcore_download_attachment_bulk(int account_id, int mail_id, i emcore_get_file_size(buf, &decoded_attachment_size, NULL); EM_DEBUG_LOG("decoded_attachment_size [%d]", decoded_attachment_size); - attachment->attachment_size = decoded_attachment_size; - attachment->attachment_path = EM_SAFE_STRDUP(buf); + attachment->attachment_size = decoded_attachment_size; + attachment->attachment_path = EM_SAFE_STRDUP(buf); + attachment->attachment_save_status = 1; /* update attachment information. */ if (!emstorage_change_attachment_field(mail_id, UPDATE_SAVENAME, attachment, true, &err)) { EM_DEBUG_EXCEPTION("emstorage_change_attachment_field failed [%d]", err); @@ -2440,21 +2755,7 @@ INTERNAL_FUNC int emcore_download_attachment_bulk(int account_id, int mail_id, i goto FINISH_OFF; } -#ifdef __FEATURE_DRM__ - if (emcore_check_drm(attachment)) { - /* is drm */ - 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->flag3 = attachment->flag2; - } -#endif /* __FEATURE_DRM__ */ - - if (!emcore_check_thread_status()) { - err = EMAIL_ERROR_CANCELLED; - goto FINISH_OFF; - } + FINISH_OFF_IF_EVENT_CANCELED (err, event_handle); EM_DEBUG_LOG(" >>>>>> Attachment Downloading [%d / %d] completed", i+1, attachment_count_to_be_downloaded); } @@ -2469,10 +2770,10 @@ INTERNAL_FUNC int emcore_download_attachment_bulk(int account_id, int mail_id, i stream = mail_close (stream); } - if (attachment_list) + if (attachment_list) emstorage_free_attachment(&attachment_list, attachment_count_to_be_downloaded, NULL); - if (mail) + if (mail) emstorage_free_mail(&mail, 1, NULL); EM_SAFE_FREE(s_uid); @@ -2491,17 +2792,31 @@ INTERNAL_FUNC int emcore_download_attachment_bulk(int account_id, int mail_id, i } #endif -INTERNAL_FUNC int emcore_download_body_multi_sections_bulk (void *mail_stream, int account_id, - int mail_id, int verbose, int with_attach, int limited_size, int event_handle , int *err_code) +/* +Three thread can call this function : + event worker thread, + partial body thread, + thread_func_EMAIL_ASYNC_TASK_MOVE_MAILS_TO_MAILBOX_OF_ANOTHER_ACCOUNT + CANCEL should be revised, later +*/ +INTERNAL_FUNC int emcore_download_body_multi_sections_bulk ( void *mail_stream, + int account_id, + int mail_id, + int verbose, + int with_attach, + int limited_size, + int event_handle, + int cancellable, + int *err_code) { - EM_DEBUG_FUNC_BEGIN("mail_stream[%p], account_id[%d], mail_id[%d], verbose[%d], with_attach[%d], event_handle [%d]", + EM_DEBUG_FUNC_BEGIN("mail_stream[%p], account_id[%d], mail_id[%d], verbose[%d], with_attach[%d], event_handle [%d]", mail_stream, account_id, mail_id, verbose, with_attach, event_handle); int ret = false; int err = EMAIL_ERROR_NONE; - int status = EMAIL_DOWNLOAD_FAIL; int pop3_body_size = 0; int pop3_downloaded_size = 0; + int p_with_attach = with_attach; MAILSTREAM *stream = NULL; BODY *mbody = NULL; PARTLIST *section_list = NULL; @@ -2511,8 +2826,7 @@ INTERNAL_FUNC int emcore_download_body_multi_sections_bulk (void *mail_stream, i email_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; + char *s_uid = NULL; char buf[512] = {0}; int msgno = 0, attachment_num = 1, local_attachment_count = 0, local_inline_content_count = 0; int iActualSize = 0; @@ -2523,7 +2837,7 @@ INTERNAL_FUNC int emcore_download_body_multi_sections_bulk (void *mail_stream, i #endif if (mail_id < 1) { - EM_DEBUG_EXCEPTION("mail_stream[%p], account_id[%d], mail_id[%d], verbose[%d], with_attach[%d]", + EM_DEBUG_EXCEPTION("mail_stream[%p], account_id[%d], mail_id[%d], verbose[%d], with_attach[%d]", mail_stream, account_id, mail_id, verbose, with_attach); err = EMAIL_ERROR_INVALID_PARAM; if (err_code != NULL) @@ -2532,50 +2846,75 @@ INTERNAL_FUNC int emcore_download_body_multi_sections_bulk (void *mail_stream, i emcore_notify_network_event(NOTI_DOWNLOAD_BODY_FAIL, mail_id, NULL, event_handle, err); return false; } - - FINISH_OFF_IF_CANCELED; + if (cancellable) + FINISH_OFF_IF_EVENT_CANCELED (err, event_handle); only_body_download = true; - if (!emstorage_get_mail_by_id(mail_id, &mail, true, &err) || !mail) { + /* looking for mail by mail_id in DB*/ + if (!emstorage_get_mail_by_id (mail_id, &mail, true, &err) || !mail) { EM_DEBUG_EXCEPTION("emstorage_get_mail_by_id failed [%d]", err); goto FINISH_OFF; } - - if (1 == mail->body_download_status) { - EM_DEBUG_EXCEPTION("not synchronous mail..."); - err = EMAIL_ERROR_MAIL_IS_ALREADY_DOWNLOADED; + + /* if mail is downloaded */ + if (mail->body_download_status & EMAIL_BODY_DOWNLOAD_STATUS_FULLY_DOWNLOADED) { + /* after entering viewer, the mail has been just downloaded */ + if (!emcore_notify_network_event (NOTI_DOWNLOAD_BODY_START, + mail_id, + "dummy-file", /* ?? */ + mail->mail_size, /*_pop3_total_body_size*/ + 0)) + EM_DEBUG_EXCEPTION ("emcore_notify_network_event [ NOTI_DOWNLOAD_BODY_START] error >>>> "); + else + EM_DEBUG_LOG("NOTI_DOWNLOAD_BODY_START notified (%d / %d)", + 0, mail->mail_size); + + err = EMAIL_ERROR_NONE; //EMAIL_ERROR_MAIL_IS_ALREADY_DOWNLOADED; + ret = true; goto FINISH_OFF; } - + s_uid = EM_SAFE_STRDUP(mail->server_mail_id); attachment.account_id = mail->account_id; attachment.mail_id = mail->mail_id; attachment.mailbox_id = mail->mailbox_id; attachment.attachment_save_status = 0; - + if (!(ref_account = emcore_get_account_reference(account_id))) { EM_DEBUG_EXCEPTION("emcore_get_account_reference failed [%d]", account_id); err = EMAIL_ERROR_INVALID_ACCOUNT; goto FINISH_OFF; } - FINISH_OFF_IF_CANCELED; + if (cancellable) + FINISH_OFF_IF_EVENT_CANCELED (err, event_handle); /* open mail server. */ - if (!mail_stream) { + if (!mail_stream) { +#if 0 + MAILSTREAM *tmp_stream = NULL; if (!emcore_connect_to_remote_mailbox(account_id, mail->mailbox_id, (void **)&tmp_stream, &err) || !tmp_stream) { EM_DEBUG_EXCEPTION("emcore_connect_to_remote_mailbox failed [%d]", err); - status = EMAIL_DOWNLOAD_CONNECTION_FAIL; goto FINISH_OFF; } + stream = (MAILSTREAM *)tmp_stream; +#endif + MAILSTREAM **mstream = NULL; + mstream = emcore_get_recv_stream (account_id, mail->mailbox_id, &err); + if (!mstream) { + EM_DEBUG_EXCEPTION("emcore_get_recv_stream failed [%d]", err); + goto FINISH_OFF; + } + stream = (MAILSTREAM *)*mstream; } else stream = (MAILSTREAM *)mail_stream; - - FINISH_OFF_IF_CANCELED; - + + if (cancellable) + FINISH_OFF_IF_EVENT_CANCELED (err, event_handle); + if (!(cnt_info = em_malloc(sizeof(struct _m_content_info)))) { EM_DEBUG_EXCEPTION("em_malloc failed..."); err = EMAIL_ERROR_OUT_OF_MEMORY; @@ -2586,7 +2925,6 @@ INTERNAL_FUNC int emcore_download_body_multi_sections_bulk (void *mail_stream, i /* POP3 */ /* in POP3 case, both text and attachment are downloaded in this call. */ cnt_info->grab_type = GRAB_TYPE_TEXT | GRAB_TYPE_ATTACHMENT; - attachment.attachment_save_status = 1; /* all attachments should be downloaded in the case of POP3 */ mailbox.account_id = account_id; @@ -2603,16 +2941,14 @@ INTERNAL_FUNC int emcore_download_body_multi_sections_bulk (void *mail_stream, i goto FINISH_OFF; } - if (!emcore_check_thread_status()) { - err = EMAIL_ERROR_CANCELLED; - goto FINISH_OFF; - } + if (cancellable) + FINISH_OFF_IF_EVENT_CANCELED (err, event_handle); _pop3_received_body_size = 0; _pop3_total_body_size = 0; _pop3_last_notified_body_size = 0; _pop3_receiving_mail_id = mail_id; - + /* send read mail commnad. */ if (!emcore_mail_cmd_read_mail_pop3(stream, msgno, limited_size, &pop3_downloaded_size, &pop3_body_size, &err)) { EM_DEBUG_EXCEPTION("emcore_mail_cmd_read_mail_pop3 failed [%d]", err); @@ -2626,8 +2962,9 @@ INTERNAL_FUNC int emcore_download_body_multi_sections_bulk (void *mail_stream, i else EM_DEBUG_LOG("NOTI_DOWNLOAD_BODY_START notified (%d / %d)", 0, _pop3_total_body_size); - FINISH_OFF_IF_CANCELED; - + if (cancellable) + FINISH_OFF_IF_EVENT_CANCELED (err, event_handle); + /* save message into tempfile */ /* parsing mime from stream. */ #ifdef __FEATURE_USE_GMIME__ @@ -2635,19 +2972,30 @@ INTERNAL_FUNC int emcore_download_body_multi_sections_bulk (void *mail_stream, i int fd = 0; char *tmp_path = emcore_mime_get_save_file_name(&err); EM_DEBUG_LOG ("tmp_path[%s]", tmp_path); - fd = open(tmp_path, O_WRONLY|O_CREAT, 0644); - if (fd < 0) { - EM_DEBUG_EXCEPTION("open error [%d]: holder is a filename that will be saved.", errno); + err = em_open(tmp_path, O_WRONLY | O_CREAT, 0644, &fd); + if (err != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("open error [%d]: holder is a filename that will be saved.", err); } while(emcore_mime_get_line_from_sock((void *)stream, sock_buf, 1024, &err)) { if (write(fd, sock_buf, EM_SAFE_STRLEN(sock_buf)) != EM_SAFE_STRLEN(sock_buf)) { EM_DEBUG_EXCEPTION("write failed"); } + + if (cancellable) { + int type = 0; + if (!emcore_check_event_thread_status(&type, event_handle)) { + EM_DEBUG_LOG ("CANCELED EVENT: type [%d]", type); + err = EMAIL_ERROR_CANCELLED; + EM_SAFE_CLOSE (fd); + g_remove(tmp_path); + goto FINISH_OFF; + } + } } - close(fd); + EM_SAFE_CLOSE (fd); - emcore_gmime_parse_mime(tmp_path, cnt_info, &err); + emcore_gmime_pop3_parse_mime(tmp_path, cnt_info, &err); g_remove(tmp_path); #else @@ -2656,11 +3004,13 @@ INTERNAL_FUNC int emcore_download_body_multi_sections_bulk (void *mail_stream, i goto FINISH_OFF; } #endif /* __FEATURE_USE_GMIME__ */ - FINISH_OFF_IF_CANCELED; + if (cancellable) + FINISH_OFF_IF_EVENT_CANCELED (err, event_handle); + } else { /* in IMAP case, both text and attachment list are downloaded in this call. */ /* This flag is just for downloading mailbox.(sync header), don't be used when retrieve body. */ - if (with_attach > 0) + if (p_with_attach > 0) cnt_info->grab_type = GRAB_TYPE_TEXT | GRAB_TYPE_ATTACHMENT; else cnt_info->grab_type = GRAB_TYPE_TEXT; @@ -2678,7 +3028,8 @@ INTERNAL_FUNC int emcore_download_body_multi_sections_bulk (void *mail_stream, i goto FINISH_OFF; } - FINISH_OFF_IF_CANCELED; + if (cancellable) + FINISH_OFF_IF_EVENT_CANCELED (err, event_handle); if (mbody->type == TYPEMULTIPART) { EM_DEBUG_LOG(">>> check multipart body size to download : only_body_download[%d]", only_body_download); @@ -2741,6 +3092,7 @@ INTERNAL_FUNC int emcore_download_body_multi_sections_bulk (void *mail_stream, i _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; @@ -2756,19 +3108,50 @@ INTERNAL_FUNC int emcore_download_body_multi_sections_bulk (void *mail_stream, i EM_DEBUG_EXCEPTION("emcore_get_body_part_list_full failed [%d]", err); goto FINISH_OFF; } - FINISH_OFF_IF_CANCELED; + + if (cancellable) + FINISH_OFF_IF_EVENT_CANCELED (err, event_handle); } if (cnt_info->text.plain) { - EM_DEBUG_LOG("cnt_info->text.plain [%s]", cnt_info->text.plain); + char *charset_plain_text = NULL; + EM_DEBUG_LOG_SEC("cnt_info->text.plain [%s]", cnt_info->text.plain); + + char *file_content = NULL; + int content_size = 0; + + if (emcore_get_content_from_file(cnt_info->text.plain, &file_content, &content_size) != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emcore_get_content_from_file failed"); + } + + if (file_content && content_size > 0) { + char escape = 0x1b; + char detector[25] = {0,}; + snprintf(detector, sizeof(detector), "%c$B", escape); + if (g_strrstr(cnt_info->text.plain_charset, "UTF-8") && g_strrstr(file_content, detector)) { + cnt_info->text.plain_charset = "ISO-2022-JP"; + } + } + + EM_SAFE_FREE(file_content); + + if (cnt_info->text.plain_charset) + charset_plain_text = cnt_info->text.plain_charset; + else { + if (mail->default_charset) { + charset_plain_text = mail->default_charset; + } else { + charset_plain_text = "UTF-8"; + } + } + EM_DEBUG_LOG("PLAIN DEFAULT CHARSET : %s", charset_plain_text); if (!emstorage_create_dir(account_id, mail_id, 0, &err)) { EM_DEBUG_EXCEPTION("emstorage_create_dir failed [%d]", err); goto FINISH_OFF; } - - if (!emstorage_get_save_name(account_id, mail_id, 0, cnt_info->text.plain_charset ? cnt_info->text.plain_charset : "UTF-8", buf, &err)) { + if (!emstorage_get_save_name(account_id, mail_id, 0, charset_plain_text, buf, sizeof(buf), &err)) { EM_DEBUG_EXCEPTION("emstorage_get_save_name failed [%d]", err); goto FINISH_OFF; } @@ -2782,13 +3165,13 @@ INTERNAL_FUNC int emcore_download_body_multi_sections_bulk (void *mail_stream, i mail->file_path_plain = EM_SAFE_STRDUP(buf); EM_DEBUG_LOG_SEC("mail->file_path_plain [%s]", mail->file_path_plain); } - + if (cnt_info->text.html) { if (!emstorage_create_dir(account_id, mail_id, 0, &err)) { EM_DEBUG_EXCEPTION("emstorage_create_dir failed [%d]", err); goto FINISH_OFF; } - + if (cnt_info->text.html_charset != NULL) { memcpy(html_body, cnt_info->text.html_charset, EM_SAFE_STRLEN(cnt_info->text.html_charset)); strcat(html_body, HTML_EXTENSION_STRING); @@ -2800,7 +3183,7 @@ INTERNAL_FUNC int emcore_download_body_multi_sections_bulk (void *mail_stream, i else { memcpy(html_body, "UTF-8.htm", strlen("UTF-8.htm")); } - if (!emstorage_get_save_name(account_id, mail_id, 0, html_body, buf, &err)) { + if (!emstorage_get_save_name(account_id, mail_id, 0, html_body, buf, sizeof(buf), &err)) { EM_DEBUG_EXCEPTION("emstorage_get_save_name failed [%d]", err); goto FINISH_OFF; } @@ -2812,59 +3195,74 @@ INTERNAL_FUNC int emcore_download_body_multi_sections_bulk (void *mail_stream, i EM_SAFE_FREE(mail->file_path_html); mail->file_path_html = EM_SAFE_STRDUP(buf); } - - if (ref_account->incoming_server_type == EMAIL_SERVER_TYPE_POP3 && limited_size != NO_LIMITATION && - limited_size < pop3_body_size) - mail->body_download_status = EMAIL_BODY_DOWNLOAD_STATUS_PARTIALLY_DOWNLOADED; - else - mail->body_download_status = EMAIL_BODY_DOWNLOAD_STATUS_FULLY_DOWNLOADED; + + if (ref_account->incoming_server_type == EMAIL_SERVER_TYPE_POP3 && limited_size != NO_LIMITATION && + limited_size < pop3_body_size) { + mail->body_download_status = (mail->body_download_status & ~0x00000003) | EMAIL_BODY_DOWNLOAD_STATUS_PARTIALLY_DOWNLOADED; + } + else { + mail->body_download_status = (mail->body_download_status & ~0x00000003) | EMAIL_BODY_DOWNLOAD_STATUS_FULLY_DOWNLOADED; + p_with_attach = true; + } /* Update local_preview_text */ - if ((err = emcore_get_preview_text_from_file (mail->file_path_plain, mail->file_path_html, + if ((err = emcore_get_preview_text_from_file (mail->file_path_plain, mail->file_path_html, MAX_PREVIEW_TEXT_LENGTH, &mail->preview_text)) != EMAIL_ERROR_NONE) { EM_DEBUG_EXCEPTION("emcore_get_preview_text_from_file error [%d]", err); } - + #ifdef CHANGE_HTML_BODY_TO_ATTACHMENT if (html_changed) mail->flag2 = 1; #endif - - FINISH_OFF_IF_CANCELED; - + + if (cancellable) + FINISH_OFF_IF_EVENT_CANCELED (err, event_handle); + for (ai = cnt_info->file; ai; ai = ai->next, attachment_num++) { + + if (ai->type == 1) + local_inline_content_count++; + else + local_attachment_count++; + + if (ref_account->incoming_server_type == EMAIL_SERVER_TYPE_IMAP4 && only_body_download && ai->type != INLINE_ATTACHMENT) + continue; + attachment.attachment_id = attachment_num; attachment.attachment_size = ai->size; attachment.attachment_path = ai->save; + attachment.content_id = ai->content_id; attachment.attachment_name = ai->name; attachment.attachment_drm_type = ai->drm; attachment.attachment_inline_content_status = ai->type == 1; - attachment.attachment_save_status = 0; attachment.attachment_mime_type = ai->attachment_mime_type; + + if (p_with_attach) + attachment.attachment_save_status = EMAIL_BODY_DOWNLOAD_STATUS_FULLY_DOWNLOADED; + else + attachment.attachment_save_status = (ai->type == 1) ? EMAIL_BODY_DOWNLOAD_STATUS_PARTIALLY_DOWNLOADED:EMAIL_BODY_DOWNLOAD_STATUS_NONE; + #ifdef __ATTACHMENT_OPTI__ attachment.encoding = ai->encoding; attachment.section = ai->section; #endif EM_DEBUG_LOG("attachment.attachment_id[%d]", attachment.attachment_id); EM_DEBUG_LOG("attachment.attachment_size[%d]", attachment.attachment_size); - EM_DEBUG_LOG("attachment.attachment_path[%s]", attachment.attachment_path); + EM_DEBUG_LOG_SEC("attachment.attachment_path[%s]", attachment.attachment_path); + EM_DEBUG_LOG("attachment.content_id[%s]", attachment.content_id); EM_DEBUG_LOG_SEC("attachment.attachment_name[%s]", attachment.attachment_name); EM_DEBUG_LOG("attachment.attachment_drm_type[%d]", attachment.attachment_drm_type); + EM_DEBUG_LOG("attachment.attachment_save_status[%d]", attachment.attachment_save_status); EM_DEBUG_LOG("attachment.attachment_inline_content_status[%d]", attachment.attachment_inline_content_status); - if (ai->type == 1) - local_inline_content_count++; - else - local_attachment_count++; - if (ai->save) { /* in POP3 case, rename temporary file to real file. */ - attachment.attachment_save_status = 1; if (ai->type == 1) { /* it is inline content */ if (!emstorage_create_dir(account_id, mail_id, 0, &err)) { EM_DEBUG_EXCEPTION("emstorage_create_dir failed [%d]", err); goto FINISH_OFF; } - if (!emstorage_get_save_name(account_id, mail_id, 0, attachment.attachment_name, buf, &err)) { + if (!emstorage_get_save_name(account_id, mail_id, 0, attachment.attachment_name, buf, sizeof(buf), &err)) { EM_DEBUG_EXCEPTION("emstorage_get_save_name failed [%d]", err); goto FINISH_OFF; } @@ -2875,7 +3273,7 @@ INTERNAL_FUNC int emcore_download_body_multi_sections_bulk (void *mail_stream, i goto FINISH_OFF; } - if (!emstorage_get_save_name(account_id, mail_id, attachment_num, attachment.attachment_name, buf, &err)) { + if (!emstorage_get_save_name(account_id, mail_id, attachment_num, attachment.attachment_name, buf, sizeof(buf), &err)) { EM_DEBUG_EXCEPTION("emstorage_get_save_name failed [%d]", err); goto FINISH_OFF; } @@ -2885,7 +3283,7 @@ INTERNAL_FUNC int emcore_download_body_multi_sections_bulk (void *mail_stream, i EM_DEBUG_EXCEPTION("emstorage_move_file failed [%d]", err); /* delete all created files. */ - if (!emstorage_get_save_name(account_id, mail_id, 0, NULL, buf, NULL)) { + if (!emstorage_get_save_name(account_id, mail_id, 0, NULL, buf, sizeof(buf),NULL)) { EM_DEBUG_EXCEPTION("emstorage_get_save_name failed..."); /* goto FINISH_OFF; */ } @@ -2899,19 +3297,11 @@ INTERNAL_FUNC int emcore_download_body_multi_sections_bulk (void *mail_stream, i goto FINISH_OFF; } - EM_SAFE_FREE(ai->save); + EM_SAFE_FREE(ai->save); ai->save = EM_SAFE_STRDUP(buf); attachment.attachment_path = ai->save; -#ifdef __FEATURE_DRM__ - if (emcore_check_drm(&attachment)) /* is drm content ?*/ { - if (drm_process_request(DRM_REQUEST_TYPE_REGISTER_FILE, attachment.attachment_path, NULL) - != DRM_RETURN_SUCCESS) - EM_DEBUG_EXCEPTION("drm_process_request : register file fail"); - mail->DRM_status = attachment.attachment_drm_type; - } -#endif/* __FEATURE_DRM__ */ } #ifdef __FEATURE_PARTIAL_BODY_DOWNLOAD__ @@ -2927,7 +3317,7 @@ INTERNAL_FUNC int emcore_download_body_multi_sections_bulk (void *mail_stream, i if (attch_info) emstorage_free_attachment(&attch_info, 1, NULL); /* delete all created files. */ - if (!emstorage_get_save_name(account_id, mail_id, 0, NULL, buf, &err)) { + if (!emstorage_get_save_name(account_id, mail_id, 0, NULL, buf, sizeof(buf), &err)) { EM_DEBUG_EXCEPTION("emstorage_get_save_name failed [%d]", err); goto FINISH_OFF; } @@ -2950,6 +3340,7 @@ INTERNAL_FUNC int emcore_download_body_multi_sections_bulk (void *mail_stream, i /* Update attachment size */ EM_DEBUG_LOG("attachment_size [%d], ai->size [%d]", attch_info->attachment_size, ai->size); attch_info->attachment_size = ai->size; + attch_info->attachment_save_status = attachment.attachment_save_status; if (!emstorage_update_attachment(attch_info, true, &err)) { EM_DEBUG_EXCEPTION("emstorage_update_attachment failed [%d]", err); emstorage_free_attachment(&attch_info, 1, NULL); /*prevent 17956*/ @@ -2962,7 +3353,7 @@ INTERNAL_FUNC int emcore_download_body_multi_sections_bulk (void *mail_stream, i } #else - + if (ai->type) { mail->attachment_yn = 1; /* save only attachment file. */ @@ -3016,6 +3407,7 @@ INTERNAL_FUNC int emcore_download_body_multi_sections_bulk (void *mail_stream, i if (!emstorage_get_mail_text_by_id(mail_id, &mail_text, true, &err) || !mail_text) { EM_DEBUG_EXCEPTION("emstorage_get_mail_text_by_id failed [%d]", err); emstorage_rollback_transaction(NULL, NULL, NULL); /* ROLLBACK TRANSACTION; */ + EM_SAFE_FREE(stripped_text); goto FINISH_OFF; } @@ -3034,7 +3426,7 @@ INTERNAL_FUNC int emcore_download_body_multi_sections_bulk (void *mail_stream, i #endif EM_DEBUG_LOG("cnt_info->text.plain [%s], cnt_info->text.html [%s]", cnt_info->text.plain, cnt_info->text.html); - + /* in pop3 mail case, the mail is deleted from server after being downloaded. */ if (ref_account->incoming_server_type == EMAIL_SERVER_TYPE_POP3) { #ifdef DELETE_AFTER_DOWNLOADING @@ -3047,11 +3439,12 @@ INTERNAL_FUNC int emcore_download_body_multi_sections_bulk (void *mail_stream, i EM_DEBUG_EXCEPTION("emcore_delete_mails_from_pop3_server failed [%d]", err); } #endif - + } - FINISH_OFF_IF_CANCELED; - + if (cancellable) + FINISH_OFF_IF_EVENT_CANCELED (err, event_handle); + ret = true; FINISH_OFF: @@ -3061,22 +3454,24 @@ FINISH_OFF: EM_SAFE_FREE(ref_account); } +#if 0 /* note that local stream should be freed here*/ if (mail_stream == NULL && stream != NULL) { stream = mail_close (stream); } +#endif multi_part_body_size = 0; _pop3_received_body_size = 0; _pop3_last_notified_body_size = 0; _pop3_total_body_size = 0; _pop3_receiving_mail_id = 0; - + _imap4_received_body_size = 0; _imap4_last_notified_body_size = 0; _imap4_total_body_size = 0; _imap4_download_noti_interval_value = 0; - + if (cnt_info) { emcore_free_content_info(cnt_info); EM_SAFE_FREE(cnt_info); @@ -3086,7 +3481,7 @@ FINISH_OFF: EM_SAFE_FREE(s_uid); multi_part_body_size = 0; - + if (ret == true) emcore_notify_network_event(NOTI_DOWNLOAD_BODY_FINISH, mail_id, NULL, event_handle, 0); else @@ -3094,10 +3489,760 @@ FINISH_OFF: if (err_code != NULL) *err_code = err; - + return ret; } +INTERNAL_FUNC int emcore_gmime_download_body_sections(void *mail_stream, + int account_id, int mail_id, int with_attach, int limited_size, + int event_handle, int cancellable, int auto_download, int *err_code) +{ + EM_DEBUG_FUNC_BEGIN("mail_stream[%p], account_id[%d], mail_id[%d], " + "with_attach[%d], event_handle [%d]", mail_stream, account_id, mail_id, + with_attach, event_handle); + + int ret = FALSE; + int err = EMAIL_ERROR_NONE; + int b_with_attach = with_attach; + int need_update_attachment = 0; + + BODY *mbody = NULL; + MAILSTREAM *stream = NULL; + + email_account_t *ref_account = NULL; + emstorage_mail_tbl_t *mail = NULL; + emstorage_attachment_tbl_t attachment = {0,}; + emstorage_attachment_tbl_t *attch_info = NULL; + + struct _m_content_info *cnt_info = NULL; + struct attachment_info *ai = NULL; + + char *s_uid = NULL; + char buf[512] = {0}; + + int msgno = 0; + int attachment_num = 1; + int local_attachment_count = 0; + int local_inline_content_count = 0; + + char html_body[MAX_PATH] = {0,}; + + emcore_uid_list *uid_list = NULL; + + GMimeMessage *message1 = NULL; + + if (mail_id < 1) { + EM_DEBUG_EXCEPTION("mail_stream[%p], account_id[%d], mail_id[%d]," + "with_attach[%d]", mail_stream, account_id, mail_id, with_attach); + + err = EMAIL_ERROR_INVALID_PARAM; + if (err_code != NULL) + *err_code = err; + + if (!auto_download) + emcore_notify_network_event(NOTI_DOWNLOAD_BODY_FAIL, mail_id, NULL, event_handle, err); + return ret; + } + + if (cancellable) + FINISH_OFF_IF_EVENT_CANCELED (err, event_handle); + + /* looking for mail by mail_id in DB*/ + if (!emstorage_get_mail_by_id (mail_id, &mail, true, &err) || !mail) { + EM_DEBUG_EXCEPTION("emstorage_get_mail_by_id failed [%d]", err); + goto FINISH_OFF; + } + + /* if mail is downloaded */ + if (mail->body_download_status & EMAIL_BODY_DOWNLOAD_STATUS_FULLY_DOWNLOADED) { + /* after entering viewer, the mail has been just downloaded */ + if (!auto_download) { + if (!emcore_notify_network_event (NOTI_DOWNLOAD_BODY_START, mail_id, + "dummy-file", mail->mail_size, 0)) + EM_DEBUG_EXCEPTION ("emcore_notify_network_event [ NOTI_DOWNLOAD_BODY_START] error >>>>"); + else + EM_DEBUG_LOG("NOTI_DOWNLOAD_BODY_START notified (%d / %d)", 0, mail->mail_size); + } + + err = EMAIL_ERROR_NONE; //EMAIL_ERROR_MAIL_IS_ALREADY_DOWNLOADED; + ret = TRUE; + goto FINISH_OFF; + } + else if (!mail->body_download_status) + need_update_attachment = 1; + + s_uid = EM_SAFE_STRDUP(mail->server_mail_id); + + if (!(ref_account = emcore_get_account_reference(account_id))) { + EM_DEBUG_EXCEPTION("emcore_get_account_reference failed [%d]", account_id); + err = EMAIL_ERROR_INVALID_ACCOUNT; + goto FINISH_OFF; + } + + if (cancellable) + FINISH_OFF_IF_EVENT_CANCELED (err, event_handle); + + /* open mail server. */ + if (!mail_stream) { +#if 0 + MAILSTREAM *tmp_stream = NULL; + if (!emcore_connect_to_remote_mailbox(account_id, mail->mailbox_id, (void **)&tmp_stream, &err) || !tmp_stream) { + EM_DEBUG_EXCEPTION("emcore_connect_to_remote_mailbox failed [%d]", err); + goto FINISH_OFF; + } + stream = (MAILSTREAM *)tmp_stream; +#endif + + MAILSTREAM **mstream = NULL; + mstream = emcore_get_recv_stream (account_id, mail->mailbox_id, &err); + + if (!mstream) { + EM_DEBUG_EXCEPTION("emcore_get_recv_stream failed [%d]", err); + goto FINISH_OFF; + } + stream = (MAILSTREAM *)*mstream; + } + else + stream = (MAILSTREAM *)mail_stream; + + if (cancellable) + FINISH_OFF_IF_EVENT_CANCELED (err, event_handle); + + if (!(cnt_info = em_malloc(sizeof(struct _m_content_info)))) { + EM_DEBUG_EXCEPTION("em_malloc failed..."); + err = EMAIL_ERROR_OUT_OF_MEMORY; + goto FINISH_OFF; + } + + /* POP3 */ + /* in POP3 case, both text and attachment are downloaded in this call. */ + if (ref_account->incoming_server_type == EMAIL_SERVER_TYPE_POP3) { + int fd = 0; + int pop3_total_body_size = 0; + int pop3_downloaded_size = 0; + char sock_buf[1024] = {0,}; + char *tmp_path = NULL; + email_internal_mailbox_t mailbox = {0,}; + + cnt_info->grab_type = GRAB_TYPE_TEXT | GRAB_TYPE_ATTACHMENT; + mailbox.account_id = account_id; + + /* download all uids from server. */ + if (!emcore_download_uid_all (stream, &mailbox, &uid_list, NULL, NULL, 0, EM_CORE_GET_UIDS_FOR_NO_DELETE, &err)) { + EM_DEBUG_EXCEPTION("emcore_download_uid_all failed [%d]", err); + goto FINISH_OFF; + } + + /* get mesg number to be related to last download mail from uid list file */ + if (!emcore_get_msgno(uid_list, s_uid, &msgno, &err)) { + EM_DEBUG_EXCEPTION("emcore_get_msgno failed [%d]", err); + err = EMAIL_ERROR_MAIL_NOT_FOUND_ON_SERVER; + goto FINISH_OFF; + } + + if (cancellable) + FINISH_OFF_IF_EVENT_CANCELED (err, event_handle); + + _pop3_received_body_size = 0; + _pop3_total_body_size = 0; + _pop3_last_notified_body_size = 0; + _pop3_receiving_mail_id = mail_id; + + /* send read mail commnad. */ + if (!emcore_mail_cmd_read_mail_pop3(stream, msgno, limited_size, &pop3_downloaded_size, &pop3_total_body_size, &err)) { + EM_DEBUG_EXCEPTION("emcore_mail_cmd_read_mail_pop3 failed [%d]", err); + goto FINISH_OFF; + } + + _pop3_total_body_size = pop3_total_body_size; + + if (!auto_download) { + if (!emcore_notify_network_event(NOTI_DOWNLOAD_BODY_START, mail_id, "dummy-file", _pop3_total_body_size, 0)) + EM_DEBUG_EXCEPTION(" emcore_notify_network_event [ NOTI_DOWNLOAD_BODY_START] failed >>>> "); + else + EM_DEBUG_LOG("NOTI_DOWNLOAD_BODY_START notified (%d / %d)", 0, _pop3_total_body_size); + } + + if (cancellable) + FINISH_OFF_IF_EVENT_CANCELED (err, event_handle); + + tmp_path = emcore_mime_get_save_file_name(&err); + EM_DEBUG_LOG ("tmp_path[%s]", tmp_path); + + err = em_open(tmp_path, O_WRONLY | O_CREAT, 0644, &fd); + if (err != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("em_open error [%d]", err); + EM_SAFE_FREE(tmp_path); + goto FINISH_OFF; + } + + while(emcore_mime_get_line_from_sock((void *)stream, sock_buf, 1024, &err)) { + if (write(fd, sock_buf, EM_SAFE_STRLEN(sock_buf)) != EM_SAFE_STRLEN(sock_buf)) { + EM_DEBUG_EXCEPTION("write failed"); + } + + if (cancellable) { + int type = 0; + if (!emcore_check_event_thread_status(&type, event_handle)) { + EM_DEBUG_LOG ("CANCELED EVENT: type [%d]", type); + err = EMAIL_ERROR_CANCELLED; + EM_SAFE_CLOSE(fd); + g_remove(tmp_path); + EM_SAFE_FREE(tmp_path); + goto FINISH_OFF; + } + } + } + EM_SAFE_CLOSE(fd); + + emcore_gmime_pop3_parse_mime(tmp_path, cnt_info, &err); + + g_remove(tmp_path); + EM_SAFE_FREE(tmp_path); + + if (cancellable) + FINISH_OFF_IF_EVENT_CANCELED (err, event_handle); + + if (limited_size != NO_LIMITATION && limited_size < pop3_total_body_size) { + mail->body_download_status = (mail->body_download_status & ~0x00000003) | EMAIL_BODY_DOWNLOAD_STATUS_PARTIALLY_DOWNLOADED; + } else { + mail->body_download_status = (mail->body_download_status & ~0x00000003) | EMAIL_BODY_DOWNLOAD_STATUS_FULLY_DOWNLOADED; + b_with_attach = 1; + } + } + /* IMAP */ + else if (ref_account->incoming_server_type == EMAIL_SERVER_TYPE_IMAP4) { + int total_mail_size = 0; + + if (b_with_attach > 0 || need_update_attachment) + cnt_info->grab_type = GRAB_TYPE_TEXT | GRAB_TYPE_ATTACHMENT; + else + cnt_info->grab_type = GRAB_TYPE_TEXT; + + int uid = s_uid? atoi(s_uid):0; + + /* set sparep(member of BODY) memory free function */ + mail_parameters(stream, SET_FREEBODYSPAREP, emcore_free_body_sparep); + + /* get body strucutre. */ + /* don't free mbody because mbody is freed in closing mail_stream. */ + if (emcore_get_body_structure(stream, uid, &mbody, &err) < 0 || (mbody == NULL)) { + EM_DEBUG_EXCEPTION("emcore_get_body_structure failed [%d]", err); + err = EMAIL_ERROR_MAIL_NOT_FOUND_ON_SERVER; + goto FINISH_OFF; + } + + if (cancellable) + FINISH_OFF_IF_EVENT_CANCELED (err, event_handle); + + /* construct GMimeMessage from bodystructure*/ + if (!emcore_gmime_construct_mime_part_with_bodystructure(mbody, &message1, "1", &total_mail_size)) { + EM_DEBUG_EXCEPTION("emcore_gmime_construct_mime_part_with_bodystructure failed"); + err = EMAIL_ERROR_ON_PARSING; + goto FINISH_OFF; + } + + if (g_strrstr(mail->full_address_from, "mmsc.plusnet.pl") != NULL || + g_strrstr(mail->full_address_from, "mms.t-mobile.pl") != NULL) { + cnt_info->attachment_only = 1; + } + + /* fill up cnt_info */ + g_mime_message_foreach(message1, emcore_gmime_imap_parse_bodystructure_foreach_cb, (gpointer)cnt_info); + + /* fill up section list */ + g_mime_message_foreach(message1, emcore_gmime_get_body_sections_foreach_cb, (gpointer)cnt_info); + + /* FETCH sections and set content to message */ + if (!emcore_gmime_fetch_imap_body_sections(stream, uid, mail_id, + cnt_info, message1, event_handle, auto_download, &err)) { + EM_DEBUG_EXCEPTION("emcore_gmime_get_imap_sections failed"); + goto FINISH_OFF; + } + + /* decoding contents */ + g_mime_message_foreach(message1, emcore_gmime_imap_parse_full_foreach_cb, (gpointer)cnt_info); + + /* free resources */ + if (message1) { + g_object_unref(message1); + message1 = NULL; + } + + mail->body_download_status = (mail->body_download_status & ~0x00000003) | EMAIL_BODY_DOWNLOAD_STATUS_FULLY_DOWNLOADED; + } + + /* text/plain */ + if (cnt_info->text.plain) { + char *charset_plain_text = NULL; + char *file_content = NULL; + int content_size = 0; + + EM_DEBUG_LOG("cnt_info->text.plain [%s]", cnt_info->text.plain); + + if (emcore_get_content_from_file(cnt_info->text.plain, &file_content, &content_size) != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emcore_get_content_from_file failed"); + } + + if (file_content && content_size > 0) { + char escape = 0x1b; + char detector[25] = {0,}; + snprintf(detector, sizeof(detector), "%c$B", escape); + if (g_strrstr(cnt_info->text.plain_charset, "UTF-8") && g_strrstr(file_content, detector)) { + cnt_info->text.plain_charset = "ISO-2022-JP"; + } + } + + EM_SAFE_FREE(file_content); + + if (cnt_info->text.plain_charset) + charset_plain_text = cnt_info->text.plain_charset; + else { + if (mail->default_charset) { + charset_plain_text = mail->default_charset; + } else { + charset_plain_text = "UTF-8"; + } + } + EM_DEBUG_LOG("PLAIN DEFAULT CHARSET : %s", charset_plain_text); + + if (!emstorage_create_dir(account_id, mail_id, 0, &err)) { + EM_DEBUG_EXCEPTION("emstorage_create_dir failed [%d]", err); + goto FINISH_OFF; + } + + if (!emstorage_get_save_name(account_id, mail_id, 0, charset_plain_text, buf, sizeof(buf), &err)) { + EM_DEBUG_EXCEPTION("emstorage_get_save_name failed [%d]", err); + goto FINISH_OFF; + } + + if (!emstorage_move_file(cnt_info->text.plain, buf, false, &err)) { + EM_DEBUG_EXCEPTION("emstorage_move_file failed [%d]", err); + goto FINISH_OFF; + } + + EM_SAFE_FREE(mail->file_path_plain); + mail->file_path_plain = EM_SAFE_STRDUP(buf); + EM_DEBUG_LOG_SEC("mail->file_path_plain [%s]", mail->file_path_plain); + } + + /* text/html */ + if (cnt_info->text.html) { + if (!emstorage_create_dir(account_id, mail_id, 0, &err)) { + EM_DEBUG_EXCEPTION("emstorage_create_dir failed [%d]", err); + goto FINISH_OFF; + } + + if (cnt_info->text.html_charset != NULL) { + memcpy(html_body, cnt_info->text.html_charset, EM_SAFE_STRLEN(cnt_info->text.html_charset)); + strcat(html_body, HTML_EXTENSION_STRING); + } + else if (cnt_info->text.plain_charset != NULL) { + memcpy(html_body, cnt_info->text.plain_charset, EM_SAFE_STRLEN(cnt_info->text.plain_charset)); + strcat(html_body, HTML_EXTENSION_STRING); + } + else { + memcpy(html_body, "UTF-8.htm", strlen("UTF-8.htm")); + } + + if (!emstorage_get_save_name(account_id, mail_id, 0, html_body, buf, sizeof(buf), &err)) { + EM_DEBUG_EXCEPTION("emstorage_get_save_name failed [%d]", err); + goto FINISH_OFF; + } + + if (!emstorage_move_file(cnt_info->text.html, buf, false, &err)) { + EM_DEBUG_EXCEPTION("emstorage_move_file failed [%d]", err); + goto FINISH_OFF; + } + + EM_SAFE_FREE(mail->file_path_html); + mail->file_path_html = EM_SAFE_STRDUP(buf); + } + + /* Update local_preview_text */ + if ((err = emcore_get_preview_text_from_file (mail->file_path_plain, + mail->file_path_html, MAX_PREVIEW_TEXT_LENGTH, &mail->preview_text)) != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emcore_get_preview_text_from_file error [%d]", err); + } + + if (cancellable) + FINISH_OFF_IF_EVENT_CANCELED (err, event_handle); + + attachment.account_id = mail->account_id; + attachment.mail_id = mail->mail_id; + attachment.mailbox_id = mail->mailbox_id; + attachment.attachment_save_status = 0; + + /* attachments */ + if (need_update_attachment) { + int total_attachment_size; + int attachment_num_from_cnt_info; + int inline_attachment_num_from_cnt_info; + + if ((err = emcore_update_attachment_except_inline(cnt_info, mail->account_id, + mail->mail_id, mail->mailbox_id, &total_attachment_size, + &attachment_num_from_cnt_info, &inline_attachment_num_from_cnt_info)) != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emcore_update_attachment_except_inline failed : [%d]", err); + goto FINISH_OFF; + } + } + + ai = cnt_info->file; + + while (ai) { + local_attachment_count++; + + if (b_with_attach == 0) { + attachment_num++; + ai = ai->next; + continue; + } + + attachment.attachment_id = attachment_num; + attachment.attachment_size = ai->size; + attachment.attachment_path = ai->save; + attachment.content_id = ai->content_id; + attachment.attachment_name = ai->name; + attachment.attachment_drm_type = ai->drm; + attachment.attachment_inline_content_status = 0; + attachment.attachment_mime_type = ai->attachment_mime_type; + attachment.attachment_save_status = 1; + + EM_DEBUG_LOG("attachment.attachment_id[%d]", attachment.attachment_id); + EM_DEBUG_LOG("attachment.attachment_size[%d]", attachment.attachment_size); + EM_DEBUG_LOG_SEC("attachment.attachment_path[%s]", attachment.attachment_path); + EM_DEBUG_LOG("attachment.content_id[%s]", attachment.content_id); + EM_DEBUG_LOG_SEC("attachment.attachment_name[%s]", attachment.attachment_name); + EM_DEBUG_LOG("attachment.attachment_drm_type[%d]", attachment.attachment_drm_type); + EM_DEBUG_LOG("attachment.attachment_save_status[%d]", attachment.attachment_save_status); + EM_DEBUG_LOG("attachment.attachment_inline_content_status[%d]", attachment.attachment_inline_content_status); + + if (!ai->save) { + attachment_num++; + ai = ai->next; + continue; + } + + if (!emstorage_create_dir(account_id, mail_id, attachment_num, &err)) { + EM_DEBUG_EXCEPTION("emstorage_create_dir failed [%d]", err); + goto FINISH_OFF; + } + + if (!emstorage_get_save_name(account_id, mail_id, attachment_num, attachment.attachment_name, buf, sizeof(buf), &err)) { + EM_DEBUG_EXCEPTION("emstorage_get_save_name failed [%d]", err); + goto FINISH_OFF; + } + + if (!emstorage_move_file(ai->save, buf, false, &err)) { + EM_DEBUG_EXCEPTION("emstorage_move_file failed [%d]", err); + + /* delete all created files. */ + if (!emstorage_get_save_name(account_id, mail_id, 0, NULL, buf, sizeof(buf), NULL)) { + EM_DEBUG_EXCEPTION("emstorage_get_save_name failed..."); + /* goto FINISH_OFF; */ + } + + if (!emstorage_delete_dir(buf, NULL)) { + EM_DEBUG_EXCEPTION("emstorage_delete_dir failed..."); + /* goto FINISH_OFF; */ + } + + goto FINISH_OFF; + } + + EM_SAFE_FREE(ai->save); + ai->save = EM_SAFE_STRDUP(buf); + attachment.attachment_path = ai->save; + + /* Get attachment details */ + if (!emstorage_get_attachment_nth(mail_id, attachment.attachment_id, &attch_info, true, &err) || !attch_info) { + EM_DEBUG_EXCEPTION("emstorage_get_attachment_nth failed [%d]", err); + + if (err == EMAIL_ERROR_ATTACHMENT_NOT_FOUND) { /* save only attachment file. */ + if (!emstorage_add_attachment(&attachment, 0, false, &err)) { + EM_DEBUG_EXCEPTION("emstorage_add_attachment failed [%d]", err); + + if (attch_info) + emstorage_free_attachment(&attch_info, 1, NULL); + + /* delete all created files. */ + if (!emstorage_get_save_name(account_id, mail_id, 0, NULL, buf, sizeof(buf), &err)) { + EM_DEBUG_EXCEPTION("emstorage_get_save_name failed [%d]", err); + goto FINISH_OFF; + } + + if (!emstorage_delete_dir(buf, &err)) { + EM_DEBUG_EXCEPTION("emstorage_delete_dir failed [%d]", err); + goto FINISH_OFF; + } + + /* ROLLBACK TRANSACTION; */ + emstorage_rollback_transaction(NULL, NULL, NULL); + + goto FINISH_OFF; + } + } + } + else { + EM_DEBUG_LOG("Attachment info already exists...!"); + /* Update attachment size */ + EM_DEBUG_LOG("attachment_size [%d], ai->size [%d]", attch_info->attachment_size, ai->size); + EM_SAFE_FREE(attch_info->attachment_name); + EM_SAFE_FREE(attch_info->attachment_path); + EM_SAFE_FREE(attch_info->content_id); + EM_SAFE_FREE(attch_info->attachment_mime_type); + + attch_info->attachment_size = ai->size; + attch_info->attachment_save_status = attachment.attachment_save_status; + attch_info->attachment_path = EM_SAFE_STRDUP(attachment.attachment_path); + attch_info->content_id = EM_SAFE_STRDUP(attachment.content_id); + attch_info->attachment_name = EM_SAFE_STRDUP(attachment.attachment_name); + attch_info->attachment_drm_type = attachment.attachment_drm_type; + attch_info->attachment_inline_content_status = 0; + attch_info->attachment_mime_type = EM_SAFE_STRDUP(attachment.attachment_mime_type); + + if (!emstorage_update_attachment(attch_info, true, &err)) { + EM_DEBUG_EXCEPTION("emstorage_update_attachment failed [%d]", err); + emstorage_free_attachment(&attch_info, 1, NULL); /*prevent 17956*/ + goto FINISH_OFF; + } + } + + if (attch_info) + emstorage_free_attachment(&attch_info, 1, NULL); + + attachment_num++; + ai = ai->next; + } + + /* inline attachments */ + ai = cnt_info->inline_file; + while (ai) { + local_inline_content_count++; + + attachment.attachment_id = attachment_num; + attachment.attachment_size = ai->size; + attachment.attachment_path = ai->save; + attachment.content_id = ai->content_id; + attachment.attachment_name = ai->name; + attachment.attachment_drm_type = ai->drm; + attachment.attachment_inline_content_status = 1; + attachment.attachment_mime_type = ai->attachment_mime_type; + attachment.attachment_save_status = 1; + + EM_DEBUG_LOG("attachment.attachment_id[%d]", attachment.attachment_id); + EM_DEBUG_LOG("attachment.attachment_size[%d]", attachment.attachment_size); + EM_DEBUG_LOG_SEC("attachment.attachment_path[%s]", attachment.attachment_path); + EM_DEBUG_LOG("attachment.content_id[%s]", attachment.content_id); + EM_DEBUG_LOG_SEC("attachment.attachment_name[%s]", attachment.attachment_name); + EM_DEBUG_LOG("attachment.attachment_drm_type[%d]", attachment.attachment_drm_type); + EM_DEBUG_LOG("attachment.attachment_save_status[%d]", attachment.attachment_save_status); + EM_DEBUG_LOG("attachment.attachment_inline_content_status[%d]", attachment.attachment_inline_content_status); + + if (!ai->save) { + attachment_num++; + ai = ai->next; + continue; + } + + if (!emstorage_create_dir(account_id, mail_id, 0, &err)) { + EM_DEBUG_EXCEPTION("emstorage_create_dir failed [%d]", err); + goto FINISH_OFF; + } + if (!emstorage_get_save_name(account_id, mail_id, 0, attachment.attachment_name, buf, sizeof(buf), &err)) { + EM_DEBUG_EXCEPTION("emstorage_get_save_name failed [%d]", err); + goto FINISH_OFF; + } + + if (!emstorage_move_file(ai->save, buf, false, &err)) { + EM_DEBUG_EXCEPTION("emstorage_move_file failed [%d]", err); + + /* delete all created files. */ + if (!emstorage_get_save_name(account_id, mail_id, 0, NULL, buf, sizeof(buf), NULL)) { + EM_DEBUG_EXCEPTION("emstorage_get_save_name failed..."); + /* goto FINISH_OFF; */ + } + + if (!emstorage_delete_dir(buf, NULL)) { + EM_DEBUG_EXCEPTION("emstorage_delete_dir failed..."); + /* goto FINISH_OFF; */ + } + + goto FINISH_OFF; + } + + EM_SAFE_FREE(ai->save); + ai->save = EM_SAFE_STRDUP(buf); + attachment.attachment_path = ai->save; + + /* Get attachment details */ + if (!emstorage_get_attachment_nth(mail_id, attachment.attachment_id, &attch_info, true, &err) || !attch_info) { + EM_DEBUG_EXCEPTION("emstorage_get_attachment_nth failed [%d]", err); + + if (err == EMAIL_ERROR_ATTACHMENT_NOT_FOUND) { /* save only attachment file. */ + if (!emstorage_add_attachment(&attachment, 0, false, &err)) { + EM_DEBUG_EXCEPTION("emstorage_add_attachment failed [%d]", err); + + if (attch_info) + emstorage_free_attachment(&attch_info, 1, NULL); + + /* delete all created files. */ + if (!emstorage_get_save_name(account_id, mail_id, 0, NULL, buf, sizeof(buf), &err)) { + EM_DEBUG_EXCEPTION("emstorage_get_save_name failed [%d]", err); + goto FINISH_OFF; + } + + if (!emstorage_delete_dir(buf, &err)) { + EM_DEBUG_EXCEPTION("emstorage_delete_dir failed [%d]", err); + goto FINISH_OFF; + } + + /* ROLLBACK TRANSACTION; */ + emstorage_rollback_transaction(NULL, NULL, NULL); + + goto FINISH_OFF; + } + } + } + else { + EM_DEBUG_LOG("Attachment info already exists...!"); + /* Update attachment size */ + EM_DEBUG_LOG("attachment_size [%d], ai->size [%d]", attch_info->attachment_size, ai->size); + EM_SAFE_FREE(attch_info->attachment_name); + EM_SAFE_FREE(attch_info->attachment_path); + EM_SAFE_FREE(attch_info->content_id); + EM_SAFE_FREE(attch_info->attachment_mime_type); + + attch_info->attachment_size = ai->size; + attch_info->attachment_save_status = attachment.attachment_save_status; + attch_info->attachment_path = EM_SAFE_STRDUP(attachment.attachment_path); + attch_info->content_id = EM_SAFE_STRDUP(attachment.content_id); + attch_info->attachment_name = EM_SAFE_STRDUP(attachment.attachment_name); + attch_info->attachment_drm_type = attachment.attachment_drm_type; + attch_info->attachment_inline_content_status = 1; + attch_info->attachment_mime_type = EM_SAFE_STRDUP(attachment.attachment_mime_type); + + if (!emstorage_update_attachment(attch_info, true, &err)) { + EM_DEBUG_EXCEPTION("emstorage_update_attachment failed [%d]", err); + emstorage_free_attachment(&attch_info, 1, NULL); /*prevent 17956*/ + goto FINISH_OFF; + } + } + + if (attch_info) + emstorage_free_attachment(&attch_info, 1, NULL); + + attachment_num++; + ai = ai->next; + } + + mail->attachment_count = local_attachment_count; + mail->inline_content_count = local_inline_content_count; + + /* change mail's information. */ + if (!emstorage_change_mail_field(mail_id, APPEND_BODY, mail, false, &err)) { + EM_DEBUG_EXCEPTION("emstorage_change_mail_field failed [%d]", err); + emstorage_rollback_transaction(NULL, NULL, NULL); /* ROLLBACK TRANSACTION; */ + + goto FINISH_OFF; + } + +#ifdef __FEATURE_BODY_SEARCH__ + /* strip html content and save into mail_text_tbl */ + char *stripped_text = NULL; + if (!emcore_strip_mail_body_from_file(mail, &stripped_text, &err) || stripped_text == NULL) { + EM_DEBUG_EXCEPTION("emcore_strip_mail_body_from_file failed [%d]", err); + } + + emstorage_mail_text_tbl_t *mail_text; + if (!emstorage_get_mail_text_by_id(mail_id, &mail_text, true, &err) || !mail_text) { + EM_DEBUG_EXCEPTION("emstorage_get_mail_text_by_id failed [%d]", err); + emstorage_rollback_transaction(NULL, NULL, NULL); /* ROLLBACK TRANSACTION; */ + EM_SAFE_FREE(stripped_text); + goto FINISH_OFF; + } + + EM_SAFE_FREE(mail_text->body_text); + mail_text->body_text = stripped_text; + + if (!emstorage_change_mail_text_field(mail_id, mail_text, false, &err)) { + EM_DEBUG_EXCEPTION("emstorage_change_mail_text_field failed [%d]", err); + emstorage_rollback_transaction(NULL, NULL, NULL); /* ROLLBACK TRANSACTION; */ + emstorage_free_mail_text(&mail_text, 1, NULL); /*prevent 17957*/ + goto FINISH_OFF; + } + + if (mail_text) + emstorage_free_mail_text(&mail_text, 1, NULL); +#endif + + EM_DEBUG_LOG_SEC("cnt_info->text.plain [%s], cnt_info->text.html [%s]", cnt_info->text.plain, cnt_info->text.html); + + /* in pop3 mail case, the mail is deleted from server after being downloaded. */ + if (ref_account->incoming_server_type == EMAIL_SERVER_TYPE_POP3) { +#ifdef DELETE_AFTER_DOWNLOADING + char delmsg[24]; + + SNPRINTF(delmsg, sizeof(delmsg), "%d", msg_no); + + if (!ref_account->keep_mails_on_pop_server_after_download) { + if (!emcore_delete_mails_from_pop3_server(&mbox, delmsg, &err)) + EM_DEBUG_EXCEPTION("emcore_delete_mails_from_pop3_server failed [%d]", err); + } +#endif + } + + if (cancellable) + FINISH_OFF_IF_EVENT_CANCELED (err, event_handle); + + ret = TRUE; + +FINISH_OFF: + + if (ref_account) { + emcore_free_account(ref_account); + EM_SAFE_FREE(ref_account); + } + +#if 0 + /* note that local stream should be freed here*/ + if (mail_stream == NULL && stream != NULL) { + stream = mail_close (stream); + } +#endif + + _pop3_received_body_size = 0; + _pop3_last_notified_body_size = 0; + _pop3_total_body_size = 0; + _pop3_receiving_mail_id = 0; + + EM_SAFE_FREE(s_uid); + + if (cnt_info) { + emcore_free_content_info(cnt_info); + EM_SAFE_FREE(cnt_info); + } + + if (mail) + emstorage_free_mail(&mail, 1, NULL); + + if (message1) { + g_object_unref(message1); + message1 = NULL; + } + + if (!auto_download) { + if (ret == TRUE) + emcore_notify_network_event(NOTI_DOWNLOAD_BODY_FINISH, mail_id, NULL, event_handle, 0); + else + emcore_notify_network_event(NOTI_DOWNLOAD_BODY_FAIL, mail_id, NULL, event_handle, err); + } + + if (err_code != NULL) + *err_code = err; + + return ret; +} void emcore_mail_copyuid(MAILSTREAM *stream, char *mailbox, @@ -3151,8 +4296,8 @@ static int emcore_delete_mails_from_remote_server(int input_account_id, int inpu EM_DEBUG_EXCEPTION("emnetwork_check_network_status failed [%d]", err); goto FINISH_OFF; } - - FINISH_OFF_IF_CANCELED; + /* don't delete this comment, several threads including event thread call it */ + /* FINISH_OFF_IF_CANCELED; */ /* Sending Notification */ noti_param_string = em_malloc(sizeof(char) * 10 * input_mail_id_count); @@ -3180,14 +4325,33 @@ static int emcore_delete_mails_from_remote_server(int input_account_id, int inpu err = EMAIL_ERROR_MAIL_NOT_FOUND_ON_SERVER; goto FINISH_OFF; } - else + else { bulk_flag = true; + +#ifdef __FEATURE_WIFI_AUTO_DOWNLOAD__ + for(i = 0; i < input_mail_id_count; i++) { + if (!emcore_delete_auto_download_activity(input_account_id, input_mail_ids[i], 0, &err)) { + EM_DEBUG_EXCEPTION("emcore_delete_auto_download_activity failed [%d]", err); + } + } +#endif + } } else if (account->incoming_server_type == EMAIL_SERVER_TYPE_POP3) { if (!emcore_delete_mails_from_pop3_server(account, input_mail_ids, input_mail_id_count)) { EM_DEBUG_EXCEPTION("emcore_delete_mails_from_pop3_server falied [%d]", err); goto FINISH_OFF; } +#ifdef __FEATURE_WIFI_AUTO_DOWNLOAD__ + else { + for(i = 0; i < input_mail_id_count; i++) { + if (!emcore_delete_auto_download_activity(input_account_id, input_mail_ids[i], 0, &err)) { + EM_DEBUG_EXCEPTION("emcore_delete_auto_download_activity failed [%d]", err); + } + } + } +#endif + #ifdef __FEATURE_LOCAL_ACTIVITY__ else { /* Remove local activity */ @@ -3261,11 +4425,12 @@ int emcore_delete_mail(int account_id, int mail_ids[], int num, int from_server, goto FINISH_OFF; } - FINISH_OFF_IF_CANCELED; + /* don't delete this comment, several threads including event thread call it */ + /* FINISH_OFF_IF_CANCELED; */ if (from_server == EMAIL_DELETE_LOCALLY) /* Delete mails from local storage*/ { emcore_delete_mails_from_local_storage(account_id, mail_ids, num, noti_param_1, noti_param_2, err_code); - emcore_display_unread_in_badge(); + emcore_display_unread_in_badge(NULL); } else { /* Delete mails from server*/ emcore_delete_mails_from_remote_server(account_id, mail_ids, num, from_server); @@ -3274,7 +4439,7 @@ int emcore_delete_mail(int account_id, int mail_ids[], int num, int from_server, ret = true; -FINISH_OFF: +FINISH_OFF: if (from_server) emcore_show_user_message(account_id, EMAIL_ACTION_DELETE_MAIL, ret == true ? 0 : err); @@ -3365,12 +4530,12 @@ int emcore_delete_all_mails_of_acount(int input_account_id) goto FINISH_OFF; } - if (!emstorage_get_save_name(input_account_id, 0, 0, NULL, buf, &err)) { + if (!emstorage_get_save_name(input_account_id, 0, 0, NULL, buf, 512, &err)) { EM_DEBUG_EXCEPTION("emstorage_get_save_name failed [%d]", err); goto FINISH_OFF; } - if (!del_thd) + if (!del_thd) del_thd = em_thread_create (del_exit, NULL); em_thread_run (del_thd, del_dir, free_buf, buf); @@ -3382,6 +4547,9 @@ int emcore_delete_all_mails_of_acount(int input_account_id) } FINISH_OFF: + + EM_SAFE_FREE(buf); + EM_DEBUG_FUNC_END("err [%d]",err); return err; } @@ -3416,7 +4584,7 @@ INTERNAL_FUNC int emcore_delete_all_mails_of_mailbox(int input_account_id, int i goto FINISH_OFF; } } - + ret = true; FINISH_OFF: @@ -3468,13 +4636,16 @@ INTERNAL_FUNC int emcore_delete_mails_from_local_storage(int account_id, int *ma EM_DEBUG_EXCEPTION(" emcore_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 (!emstorage_update_latest_thread_mail(account_id, result_mail_list[i].thread_id, 0, 0, false, &err)) { - EM_DEBUG_EXCEPTION("emstorage_update_latest_thread_mail failed [%d]", err); - goto FINISH_OFF; + if (result_mail_list[i].thread_id != 0) { + if (!emstorage_update_latest_thread_mail(account_id, result_mail_list[i].mailbox_id, result_mail_list[i].thread_id, NULL, 0, 0, NOTI_THREAD_ID_CHANGED_BY_MOVE_OR_DELETE, false, &err)) { + EM_DEBUG_EXCEPTION("emstorage_update_latest_thread_mail failed [%d]", err); + goto FINISH_OFF; + } } } + + /* Thread information should be updated as soon as possible. */ if (!emcore_notify_storage_event(NOTI_MAIL_DELETE_FINISH, account_id, noti_param_1, noti_param_string, noti_param_2)) EM_DEBUG_EXCEPTION(" emcore_notify_storage_event failed [ NOTI_MAIL_DELETE_FINISH ] >>>> "); @@ -3488,7 +4659,7 @@ INTERNAL_FUNC int emcore_delete_mails_from_local_storage(int account_id, int *ma /* Deleting Directories */ /* delete mail contents from filesystem */ - if (!emstorage_get_save_name(account_id, result_mail_list[i].mail_id, 0, NULL, buf, &err)) { + if (!emstorage_get_save_name(account_id, result_mail_list[i].mail_id, 0, NULL, buf, sizeof(buf), &err)) { EM_DEBUG_EXCEPTION("emstorage_get_save_name failed [%d]", err); goto FINISH_OFF; } @@ -3496,7 +4667,7 @@ INTERNAL_FUNC int emcore_delete_mails_from_local_storage(int account_id, int *ma if (!emstorage_delete_dir(buf, &err)) { EM_DEBUG_EXCEPTION("emstorage_delete_dir failed [%d]", err); } - + /* Deleting Meeting Request */ if (!emstorage_delete_meeting_request(account_id, result_mail_list[i].mail_id, 0, false, &err)) { EM_DEBUG_EXCEPTION("emstorage_delete_meeting_request failed [%d]", err); @@ -3504,8 +4675,22 @@ INTERNAL_FUNC int emcore_delete_mails_from_local_storage(int account_id, int *ma goto FINISH_OFF; } } + + /* Deleting mail_read_mail_uid_tbl */ + if (!emstorage_remove_downloaded_mail(account_id, result_mail_list[i].server_mailbox_name, result_mail_list[i].server_mail_id, true, &err)) { + EM_DEBUG_EXCEPTION("emstorage_remove_downloaded_mail failed [%d]", err); + goto FINISH_OFF; + } } +#ifdef __FEATURE_WIFI_AUTO_DOWNLOAD__ + for(i = 0; i < num; i++) { + if (!emcore_delete_auto_download_activity(account_id, mail_ids[i], 0, &err)) { + EM_DEBUG_EXCEPTION("emcore_delete_auto_download_activity failed [%d]", err); + } + } +#endif + ret = true; FINISH_OFF: @@ -3538,7 +4723,7 @@ static int emcore_delete_mails_from_pop3_server(email_account_t *input_account, void *stream = NULL; email_internal_mailbox_t mailbox_data = { 0, }; emstorage_mail_tbl_t *mail_tbl_data = NULL; - + if (!input_account || !input_mail_ids) { EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM"); err = EMAIL_ERROR_INVALID_PARAM; @@ -3546,7 +4731,8 @@ static int emcore_delete_mails_from_pop3_server(email_account_t *input_account, } for (i = 0; i < input_mail_id_count; i++) { - FINISH_OFF_IF_CANCELED; + /*several threads calls this function. don't use this statement */ + /* FINISH_OFF_IF_CANCELED; */ mail_id = input_mail_ids[i]; @@ -3586,7 +4772,7 @@ static int emcore_delete_mails_from_pop3_server(email_account_t *input_account, if (!pop3_mail_delete(mailbox_data.mail_stream, msgno, &err)) { EM_DEBUG_EXCEPTION("pop3_mail_delete failed [%d]", err); - + if (err == EMAIL_ERROR_POP3_DELE_FAILURE) err = EMAIL_ERROR_MAIL_NOT_FOUND_ON_SERVER; goto FINISH_OFF; @@ -3601,7 +4787,7 @@ NOT_FOUND_ON_SERVER : emstorage_free_mail(&mail_tbl_data, 1, NULL); } -FINISH_OFF: +FINISH_OFF: if (mail_tbl_data != NULL) emstorage_free_mail(&mail_tbl_data, 1, NULL); @@ -3625,17 +4811,17 @@ INTERNAL_FUNC int emcore_get_mail_msgno_by_uid(email_account_t *account, email_i int ret = false; int err = EMAIL_ERROR_NONE; - + emcore_uid_list *uid_list = NULL; - + if (!account || !mailbox || !uid || !msgno) { EM_DEBUG_EXCEPTION_SEC("account[%p], mailbox[%p], uid[%s], msgno[%p]", account, mailbox, uid, msgno); err = EMAIL_ERROR_INVALID_PARAM; goto FINISH_OFF; } - + uid_list = mailbox->user_data; - + if (uid_list == NULL) { if (account->incoming_server_type == EMAIL_SERVER_TYPE_POP3) { if (!pop3_mailbox_get_uids(mailbox->mail_stream, &uid_list, &err)) { @@ -3644,7 +4830,7 @@ INTERNAL_FUNC int emcore_get_mail_msgno_by_uid(email_account_t *account, email_i } } else { /* EMAIL_SERVER_TYPE_IMAP4 */ - if (!imap4_mailbox_get_uids(mailbox->mail_stream, &uid_list, &err)) { + if (!imap4_mailbox_get_uids(mailbox->mail_stream, NULL, &uid_list, &err)) { EM_DEBUG_EXCEPTION("imap4_mailbox_get_uids failed [%d]", err); goto FINISH_OFF; } @@ -3662,10 +4848,10 @@ INTERNAL_FUNC int emcore_get_mail_msgno_by_uid(email_account_t *account, email_i EM_DEBUG_LOG("other uid_list->msgno[%d]", uid_list->msgno); uid_list = uid_list->next; } - + err = EMAIL_ERROR_MAIL_NOT_FOUND_ON_SERVER; -FINISH_OFF: +FINISH_OFF: if (err_code != NULL) *err_code = err; @@ -3824,42 +5010,42 @@ FINISH_OFF: return err; } -/* description +/* description * add a attachment to mail. - * arguments + * arguments * mailbox : mail box * mail_id : mail id * attachment : attachment to be added - * return + * return * succeed : 1 * fail : 0 */ INTERNAL_FUNC int emcore_add_attachment(int mail_id, email_attachment_data_t *attachment, int *err_code) { EM_DEBUG_FUNC_BEGIN("mail_id[%d], attachment[%p], err_code[%p]", mail_id, attachment, err_code); - + if (attachment == NULL) { EM_DEBUG_EXCEPTION("mail_id[%d], attachment[%p]", mail_id, attachment); if (err_code) *err_code = EMAIL_ERROR_INVALID_PARAM; return false; } - + int ret = false, err = EMAIL_ERROR_NONE; emstorage_mail_tbl_t *mail_table_data = NULL; int attachment_id = 0; int before_tr_begin = 0; - + if (!emstorage_get_mail_field_by_id(mail_id, RETRIEVE_SUMMARY, &mail_table_data, true, &err) || !mail_table_data) { EM_DEBUG_EXCEPTION("emstorage_get_mail_field_by_id failed [%d]", err); goto FINISH_OFF2; } - + int account_id = mail_table_data->account_id; emstorage_attachment_tbl_t attachment_tbl; - + memset(&attachment_tbl, 0x00, sizeof(emstorage_attachment_tbl_t)); mail_table_data->attachment_count = mail_table_data->attachment_count + 1; @@ -3872,6 +5058,7 @@ INTERNAL_FUNC int emcore_add_attachment(int mail_id, email_attachment_data_t *at attachment_tbl.attachment_drm_type = attachment->drm_status; attachment_tbl.attachment_inline_content_status = attachment->inline_content_status; attachment_tbl.attachment_mime_type = attachment->attachment_mime_type; + attachment_tbl.content_id = attachment->content_id; /* BEGIN TRANSACTION; */ if (!emstorage_begin_transaction(NULL, NULL, &err)) { @@ -3885,7 +5072,7 @@ INTERNAL_FUNC int emcore_add_attachment(int mail_id, email_attachment_data_t *at goto FINISH_OFF; } - + attachment->attachment_id = attachment_tbl.attachment_id; if (attachment->attachment_path) { @@ -3899,11 +5086,11 @@ INTERNAL_FUNC int emcore_add_attachment(int mail_id, email_attachment_data_t *at attachment_id = attachment_tbl.attachment_id; } - if (!emstorage_get_save_name(account_id, mail_id, attachment_id, attachment->attachment_name, buf, &err)) { + if (!emstorage_get_save_name(account_id, mail_id, attachment_id, attachment->attachment_name, buf, sizeof(buf), &err)) { EM_DEBUG_EXCEPTION("emstorage_get_save_name failed [%d]", err); goto FINISH_OFF; } - attachment_tbl.attachment_path = buf; + attachment_tbl.attachment_path = buf; if (!emstorage_change_attachment_field(mail_id, UPDATE_SAVENAME, &attachment_tbl, false, &err)) { EM_DEBUG_EXCEPTION("emstorage_change_attachment_field failed [%d]", err); @@ -3913,7 +5100,7 @@ INTERNAL_FUNC int emcore_add_attachment(int mail_id, email_attachment_data_t *at if (!emstorage_change_mail_field(mail_id, APPEND_BODY, mail_table_data, false, &err)) { EM_DEBUG_EXCEPTION("emstorage_change_mail_field failed [%d]", err); - + goto FINISH_OFF; } @@ -3929,17 +5116,17 @@ INTERNAL_FUNC int emcore_add_attachment(int mail_id, email_attachment_data_t *at So no need to check for old files in this update case */ if (!emstorage_change_attachment_field(mail_id, UPDATE_SAVENAME, &attachment_tbl, false, &err)) { EM_DEBUG_EXCEPTION("emstorage_change_attachment_field failed [%d]", err); - + goto FINISH_OFF; } EM_SAFE_FREE(attachment->attachment_path); attachment->attachment_path = EM_SAFE_STRDUP(buf); } - + ret = true; - -FINISH_OFF: + +FINISH_OFF: if (ret == true) { /* COMMIT TRANSACTION; */ if (emstorage_commit_transaction(NULL, NULL, NULL) == false) { err = EMAIL_ERROR_DB_FAILURE; @@ -3951,7 +5138,7 @@ FINISH_OFF: err = EMAIL_ERROR_DB_FAILURE; } -FINISH_OFF2: +FINISH_OFF2: if (mail_table_data != NULL) emstorage_free_mail(&mail_table_data, 1, NULL); @@ -3973,7 +5160,7 @@ INTERNAL_FUNC int emcore_add_attachment_data(int input_mail_id, email_attachment char buf[512] = { 0, }; emstorage_mail_tbl_t *mail_table_data = NULL; emstorage_attachment_tbl_t attachment_tbl = { 0 }; - + if (input_attachment_data == NULL) { EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM"); return EMAIL_ERROR_INVALID_PARAM; @@ -3995,7 +5182,8 @@ INTERNAL_FUNC int emcore_add_attachment_data(int input_mail_id, email_attachment attachment_tbl.attachment_drm_type = input_attachment_data->drm_status; attachment_tbl.attachment_inline_content_status = input_attachment_data->inline_content_status; attachment_tbl.attachment_mime_type = input_attachment_data->attachment_mime_type; - + attachment_tbl.content_id = input_attachment_data->content_id; + /* BEGIN TRANSACTION; */ if (!emstorage_begin_transaction(NULL, NULL, &err)) { EM_DEBUG_EXCEPTION("emstorage_begin_transaction failed [%d]", err); @@ -4007,7 +5195,7 @@ INTERNAL_FUNC int emcore_add_attachment_data(int input_mail_id, email_attachment EM_DEBUG_EXCEPTION("emstorage_add_attachment failed [%d]", err); goto FINISH_OFF; } - + input_attachment_data->attachment_id = attachment_tbl.attachment_id; if (input_attachment_data->attachment_path) { @@ -4019,7 +5207,7 @@ INTERNAL_FUNC int emcore_add_attachment_data(int input_mail_id, email_attachment attachment_id = attachment_tbl.attachment_id; } - if (!emstorage_get_save_name(mail_table_data->account_id, input_mail_id, attachment_id, input_attachment_data->attachment_name, buf, &err)) { + if (!emstorage_get_save_name(mail_table_data->account_id, input_mail_id, attachment_id, input_attachment_data->attachment_name, buf, sizeof(buf), &err)) { EM_DEBUG_EXCEPTION("emstorage_get_save_name failed [%d]", err); goto FINISH_OFF; } @@ -4034,30 +5222,29 @@ INTERNAL_FUNC int emcore_add_attachment_data(int input_mail_id, email_attachment if (!emstorage_change_mail_field(input_mail_id, APPEND_BODY, mail_table_data, false, &err)) { EM_DEBUG_EXCEPTION("emstorage_change_mail_field failed [%d]", err); - + goto FINISH_OFF; } if (input_attachment_data->save_status) { - if (!emstorage_move_file(input_attachment_data->attachment_path, buf, false, &err)) { + if (!emstorage_copy_file(input_attachment_data->attachment_path, buf, false, &err)) { EM_DEBUG_EXCEPTION("emstorage_move_file failed [%d]", err); - goto FINISH_OFF; } } - + /* Here only filename is being updated. Since first add is being done there will not be any old files. So no need to check for old files in this update case */ if (!emstorage_change_attachment_field(input_mail_id, UPDATE_SAVENAME, &attachment_tbl, false, &err)) { EM_DEBUG_EXCEPTION("emstorage_change_attachment_field failed [%d]", err); - + goto FINISH_OFF; } - + EM_SAFE_FREE(input_attachment_data->attachment_path); input_attachment_data->attachment_path = EM_SAFE_STRDUP(buf); } - + ret = true; FINISH_OFF: @@ -4069,10 +5256,10 @@ FINISH_OFF: if (!before_tr_begin && emstorage_rollback_transaction(NULL, NULL, NULL) == false) err = EMAIL_ERROR_DB_FAILURE; } - + if (mail_table_data != NULL) emstorage_free_mail(&mail_table_data, 1, NULL); - + EM_DEBUG_FUNC_END("err [%d]", err); return err; } @@ -4092,7 +5279,7 @@ FINISH_OFF: int emcore_delete_mail_attachment(int attachment_id, int *err_code) { EM_DEBUG_FUNC_BEGIN("attachment_id[%d], err_code[%p]", attachment_id, err_code); - + if (attachment_id == 0) { EM_DEBUG_EXCEPTION("attachment_id[%d]", attachment_id); if (err_code != NULL) @@ -4104,7 +5291,7 @@ int emcore_delete_mail_attachment(int attachment_id, int *err_code) int error = EMAIL_ERROR_NONE; char attachment_folder_path[MAX_PATH] = {0, }; emstorage_attachment_tbl_t *attachment_tbl = NULL; - + if (!emstorage_get_attachment(attachment_id, &attachment_tbl, true, &error)) { EM_DEBUG_EXCEPTION("emstorage_get_attachment failed"); return false; @@ -4115,7 +5302,7 @@ int emcore_delete_mail_attachment(int attachment_id, int *err_code) EM_DEBUG_EXCEPTION("emstorage_begin_transaction failed [%d]", error); goto FINISH_OFF; } - + if (!emstorage_delete_attachment_on_db(attachment_id, false, &error)) { EM_DEBUG_EXCEPTION("emstorage_delete_attachment_on_db failed [%d]", error); @@ -4126,10 +5313,16 @@ int emcore_delete_mail_attachment(int attachment_id, int *err_code) goto FINISH_OFF; } - SNPRINTF(attachment_folder_path, sizeof(attachment_folder_path), "%s/%d/%d/%d", MAILHOME, attachment_tbl->account_id, attachment_tbl->mail_id, attachment_id); + if (attachment_tbl->attachment_inline_content_status != INLINE_ATTACHMENT) { + SNPRINTF(attachment_folder_path, sizeof(attachment_folder_path), "%s/%d/%d/%d", MAILHOME, attachment_tbl->account_id, attachment_tbl->mail_id, attachment_id); - if (!emstorage_delete_dir(attachment_folder_path, NULL)) { - EM_DEBUG_EXCEPTION("emstorage_delete_dir failed"); + if (!emstorage_delete_dir(attachment_folder_path, NULL)) { + EM_DEBUG_EXCEPTION("emstorage_delete_dir failed"); + } + } else { + if (!emstorage_delete_file(attachment_tbl->attachment_path, NULL)) { + EM_DEBUG_EXCEPTION("emstorage_delete_file failed"); + } } if (emstorage_commit_transaction(NULL, NULL, NULL) == false) { @@ -4169,7 +5362,7 @@ static int emcore_mail_update_attachment_data(int input_mail_id, email_attachmen goto FINISH_OFF; } - + attachment_tbl.mail_id = input_mail_id; attachment_tbl.account_id = existing_attachment_info->account_id; attachment_tbl.mailbox_id = existing_attachment_info->mailbox_id; @@ -4181,6 +5374,7 @@ static int emcore_mail_update_attachment_data(int input_mail_id, email_attachmen attachment_tbl.attachment_inline_content_status = input_attachment_data->inline_content_status; attachment_tbl.attachment_mime_type = input_attachment_data->attachment_mime_type; attachment_tbl.attachment_id = input_attachment_data->attachment_id; + attachment_tbl.content_id = input_attachment_data->content_id; if (!input_attachment_data->inline_content_status) { if (!emstorage_create_dir(attachment_tbl.account_id, input_mail_id, attachment_tbl.attachment_id, &err)) { @@ -4189,15 +5383,15 @@ static int emcore_mail_update_attachment_data(int input_mail_id, email_attachmen } attachment_id = attachment_tbl.attachment_id; } - - if (!emstorage_get_save_name(attachment_tbl.account_id, input_mail_id, attachment_id, input_attachment_data->attachment_name, buf, &err)) { + + if (!emstorage_get_save_name(attachment_tbl.account_id, input_mail_id, attachment_id, input_attachment_data->attachment_name, buf, sizeof(buf), &err)) { EM_DEBUG_EXCEPTION("emstorage_get_save_name failed [%d]", err); goto FINISH_OFF; } 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); + EM_DEBUG_LOG_SEC("downloaded [%d], savename [%s], attachment_path [%s]", input_attachment_data->save_status, input_attachment_data->attachment_path, existing_attachment_info->attachment_path); if (input_attachment_data->save_status && EM_SAFE_STRCMP(input_attachment_data->attachment_path, existing_attachment_info->attachment_path) != 0) { if (!emstorage_move_file(input_attachment_data->attachment_path, buf, false ,&err)) { EM_DEBUG_EXCEPTION("emstorage_move_file failed [%d]", err); @@ -4219,7 +5413,7 @@ static int emcore_mail_update_attachment_data(int input_mail_id, email_attachmen if (!emstorage_update_attachment(&attachment_tbl, false, &err)) { EM_DEBUG_EXCEPTION("emstorage_update_attachment failed [%d]", err); } - + if (err == EMAIL_ERROR_NONE) { /* COMMIT TRANSACTION; */ if (emstorage_commit_transaction(NULL, NULL, NULL) == false) { err = EMAIL_ERROR_DB_FAILURE; @@ -4247,8 +5441,37 @@ static int emcore_mail_compare_filename_of_attachment_data(int input_mail_id, in } int err = EMAIL_ERROR_NONE; + ssize_t ret_readlink; + char *linkpath = NULL; + struct stat st_buf; + emstorage_attachment_tbl_t *attachment_a_tbl = NULL; + if (input_attachment_b_data->attachment_path && (stat(input_attachment_b_data->attachment_path, &st_buf) == 0)) { + linkpath = em_malloc(st_buf.st_size + 1); + if (linkpath == NULL) { + EM_DEBUG_EXCEPTION("em_malloc failed"); + goto FINISH_OFF; + } + + ret_readlink = readlink(input_attachment_b_data->attachment_path, linkpath, st_buf.st_size + 1); + if (ret_readlink > 0) { + linkpath[st_buf.st_size] = '\0'; + EM_DEBUG_LOG("symbolic link path : [%s]", linkpath); + + if (emstorage_get_attachment_by_attachment_path(linkpath, &attachment_a_tbl, false, &err)) { + if (attachment_a_tbl->mail_id == input_mail_id) { + input_attachment_b_data->attachment_id = attachment_a_tbl->attachment_id; + *result = 2; + goto FINISH_OFF; + } + } + + if (attachment_a_tbl) + emstorage_free_attachment(&attachment_a_tbl, 1, NULL); + } + } + if (!emstorage_get_attachment(input_attachment_a_id, &attachment_a_tbl, 1, &err)) { if (err == EMAIL_ERROR_ATTACHMENT_NOT_FOUND) EM_DEBUG_LOG ("no attachment found"); @@ -4260,34 +5483,40 @@ static int emcore_mail_compare_filename_of_attachment_data(int input_mail_id, in goto FINISH_OFF; } - if (attachment_a_tbl->attachment_name && input_attachment_b_data->attachment_name) { - EM_DEBUG_LOG_SEC("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); + if (attachment_a_tbl->attachment_path && input_attachment_b_data->attachment_path) { + EM_DEBUG_LOG_SEC("attachment_a_tbl->attachment_path [%s], input_attachment_b_data->attachment_path [%s]", attachment_a_tbl->attachment_path, input_attachment_b_data->attachment_path); + if (strcmp(attachment_a_tbl->attachment_path, input_attachment_b_data->attachment_path) == 0) + *result = 0; + else + *result = 1; } -FINISH_OFF: +FINISH_OFF: if (attachment_a_tbl) emstorage_free_attachment(&attachment_a_tbl, 1, NULL); + + EM_SAFE_FREE(linkpath); + EM_DEBUG_FUNC_END("*result [%d]", *result); return err; } -/* description +/* description * copy a mail to mail box - * arguments + * arguments * src_mailbox : source mail box * msgno : mail sequence * dst_mailbox : target mail box - * return + * return * succeed : 1 * fail : 0 */ INTERNAL_FUNC int emcore_mail_copy(int mail_id, email_mailbox_t *dst_mailbox, int *err_code) { EM_DEBUG_FUNC_BEGIN("mail_id[%d], dst_mailbox[%p], err_code[%p]", mail_id, dst_mailbox, err_code); - + int ret = false; int err = EMAIL_ERROR_NONE; int i; @@ -4327,7 +5556,7 @@ INTERNAL_FUNC int emcore_mail_copy(int mail_id, email_mailbox_t *dst_mailbox, in gchar *filename = g_path_get_basename(mail->file_path_plain); - if (!emstorage_get_save_name(dst_mailbox->account_id, mail->mail_id, 0, filename, buf, &err)) { + if (!emstorage_get_save_name(dst_mailbox->account_id, mail->mail_id, 0, filename, buf, sizeof(buf), &err)) { EM_DEBUG_EXCEPTION("emstorage_get_save_name failed [%d]", err); g_free(filename); @@ -4356,7 +5585,7 @@ INTERNAL_FUNC int emcore_mail_copy(int mail_id, email_mailbox_t *dst_mailbox, in gchar *filename = g_path_get_basename(mail->file_path_html); - if (!emstorage_get_save_name(dst_mailbox->account_id, mail->mail_id, 0, filename, buf, &err)) { + if (!emstorage_get_save_name(dst_mailbox->account_id, mail->mail_id, 0, filename, buf, sizeof(buf), &err)) { EM_DEBUG_EXCEPTION("emstorage_get_save_name failed [%d]", err); g_free(filename); @@ -4367,7 +5596,7 @@ INTERNAL_FUNC int emcore_mail_copy(int mail_id, email_mailbox_t *dst_mailbox, in if (!emstorage_copy_file(mail->file_path_html, buf, false, &err)) { EM_DEBUG_EXCEPTION("emstorage_copy_file failed [%d]", err); - + goto FINISH_OFF; } @@ -4382,11 +5611,11 @@ INTERNAL_FUNC int emcore_mail_copy(int mail_id, email_mailbox_t *dst_mailbox, in } /* insert mail data */ - + mail->account_id = dst_mailbox->account_id; mail->mailbox_id = dst_mailbox->mailbox_id; mail->mailbox_type = dst_mailbox->mailbox_type; - + if (!emstorage_add_mail(mail, 0, false, &err)) { EM_DEBUG_EXCEPTION("emstorage_add_mail failed [%d]", err); @@ -4419,8 +5648,8 @@ INTERNAL_FUNC int emcore_mail_copy(int mail_id, email_mailbox_t *dst_mailbox, in EM_DEBUG_EXCEPTION("emstorage_create_dir failed [%d]", err); break; } - - if (!emstorage_get_save_name(dst_mailbox->account_id, mail->mail_id, i+1, atch_list[i].attachment_name, buf, &err)) { + + if (!emstorage_get_save_name(dst_mailbox->account_id, mail->mail_id, i+1, atch_list[i].attachment_name, buf, sizeof(buf), &err)) { EM_DEBUG_EXCEPTION("emstorage_get_save_name failed [%d]", err); break; } @@ -4450,7 +5679,7 @@ INTERNAL_FUNC int emcore_mail_copy(int mail_id, email_mailbox_t *dst_mailbox, in if (i && i != count) { for (;i >= 0; i--) { if (atch_list[i].attachment_path) { - + if (!emstorage_delete_file(atch_list[i].attachment_path, &err)) { EM_DEBUG_EXCEPTION("emstorage_delete_file failed [%d]", err); emstorage_rollback_transaction(NULL, NULL, NULL); @@ -4500,7 +5729,7 @@ INTERNAL_FUNC int emcore_mail_copy(int mail_id, email_mailbox_t *dst_mailbox, in if (output_mailbox != NULL) emstorage_free_mailbox(&output_mailbox, 1, NULL); - + #endif if (emstorage_commit_transaction(NULL, NULL, NULL) == false) { @@ -4516,11 +5745,11 @@ INTERNAL_FUNC int emcore_mail_copy(int mail_id, email_mailbox_t *dst_mailbox, in } if (!strcmp(dst_mailbox->mailbox_name, mailbox_name) && !(mail->flags_seen_field)) - emcore_display_unread_in_badge(); + emcore_display_unread_in_badge(NULL); ret = true; -FINISH_OFF: +FINISH_OFF: if (atch_list != NULL) emstorage_free_attachment(&atch_list, count, NULL); @@ -4555,28 +5784,86 @@ INTERNAL_FUNC int emcore_move_mail(int mail_ids[], int mail_ids_count, int dst_m int ret = false; int err = EMAIL_ERROR_NONE; emstorage_mail_tbl_t *mail_list = NULL; + emstorage_mail_tbl_t *p_mail_data = NULL; int account_id = 0; - int i = 0, parameter_string_length = 0; + int i = 0, j = 0, parameter_string_length = 0; + int p_thread_id = 0; + int p_thread_item_count = 0; + int p_lastest_mail_id = 0; char *parameter_string = NULL, mail_id_string[10]; + int *dest_prev_thread_id_list = NULL; + int dest_prev_thread_id = 0; + int dest_prev_thread_item_count = 0; + int find_striped_subject = 0; + char stripped_subject[4086]; + if ( dst_mailbox_id <= 0 && mail_ids_count < 1) { EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM"); err = EMAIL_ERROR_INVALID_PARAM; goto FINISH_OFF; } - if (!emstorage_get_mail_field_by_multiple_mail_id(mail_ids, mail_ids_count, RETRIEVE_FLAG, &mail_list, true, &err) || !mail_list) { + if (!emstorage_get_mail_field_by_multiple_mail_id(mail_ids, mail_ids_count, RETRIEVE_SUMMARY, &mail_list, true, &err) || !mail_list) { EM_DEBUG_EXCEPTION("emstorage_get_mail_field_by_multiple_mail_id failed [%d]", err); goto FINISH_OFF; } account_id = mail_list[0].account_id; + dest_prev_thread_id_list = em_malloc(sizeof(int) * mail_ids_count); + if (dest_prev_thread_id_list == NULL) { + EM_DEBUG_EXCEPTION("Memory allocation for mail_id_list_string failed"); + err = EMAIL_ERROR_OUT_OF_MEMORY; + goto FINISH_OFF; + } + + for (i = 0; i < mail_ids_count; i++) { + /* Get the thread_id before move */ + if (emstorage_get_thread_id_from_mailbox(account_id, dst_mailbox_id, mail_list[i].subject, &dest_prev_thread_id, &dest_prev_thread_item_count) != EMAIL_ERROR_NONE) + EM_DEBUG_LOG("emstorage_get_thread_id_of_thread_mails is failed."); + dest_prev_thread_id_list[i] = dest_prev_thread_id; + } + if(!emstorage_move_multiple_mails_on_db(account_id, dst_mailbox_id, mail_ids, mail_ids_count, true, &err)) { EM_DEBUG_EXCEPTION("emstorage_move_multiple_mails_on_db failed [%d]", err); goto FINISH_OFF; } - + + for (i = 0; i < mail_ids_count; i++) { + if (mail_list[i].subject == NULL) + continue; + if (dest_prev_thread_id_list[i] == -1) { + if (em_find_pos_stripped_subject_for_thread_view(mail_list[i].subject, stripped_subject, sizeof(stripped_subject)) != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("em_find_pos_stripped_subject_for_thread_view is failed"); + } else { + EM_DEBUG_LOG_SEC("subject: [%s]", mail_list[i].subject); + if (EM_SAFE_STRLEN(stripped_subject) >= 2) { + find_striped_subject = 1; + } + EM_DEBUG_LOG_SEC("em_find_pos_stripped_subject_for_thread_view returns[len = %d] = %s", EM_SAFE_STRLEN(stripped_subject), stripped_subject); + } + + if (find_striped_subject) { + for (j = 0; j < i; j++) { + if (g_strrstr(mail_list[j].subject, stripped_subject)) { + dest_prev_thread_id_list[i] = mail_ids[j]; + break; + } + } + if (j == i) + dest_prev_thread_id_list[i] = mail_ids[i]; + } else { + dest_prev_thread_id_list[i] = mail_ids[i]; + } + } + + if (!emstorage_update_thread_id_of_mail(account_id, dst_mailbox_id, mail_ids[i], dest_prev_thread_id_list[i], 0, false, &err)) { + EM_DEBUG_EXCEPTION("emstorage_update_latest_thread_mail failed [%d]", err); + goto FINISH_OFF; + } + } + /* Sending a notification */ parameter_string_length = sizeof(char) * (mail_ids_count * 10 + 128/*MAILBOX_LEN_IN_MAIL_TBL*/ * 2); parameter_string = em_malloc(parameter_string_length); @@ -4595,7 +5882,7 @@ INTERNAL_FUNC int emcore_move_mail(int mail_ids[], int mail_ids_count, int dst_m 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 (!emcore_notify_storage_event(NOTI_MAIL_MOVE, account_id, noti_param_1, parameter_string, noti_param_2)) @@ -4603,14 +5890,47 @@ INTERNAL_FUNC int emcore_move_mail(int mail_ids[], int mail_ids_count, int dst_m for (i = 0; i < mail_ids_count; i++) { - if (!emstorage_update_latest_thread_mail(account_id, mail_list[i].thread_id, 0, 0, false, &err)) + if (mail_list[i].subject == NULL) + continue; + p_thread_id = -1; + p_thread_item_count = 0; + p_lastest_mail_id = -1; + + /* Get the information of moved mail */ + if (!emstorage_get_mail_by_id(mail_ids[i], &p_mail_data, false, &err)) { + EM_DEBUG_EXCEPTION("emstorage_get_mail_by_id failed : [%d]", err); + goto FINISH_OFF; + } + + /* Get the thread_id of moved mail */ + if (emstorage_get_thread_id_of_thread_mails(p_mail_data, &p_thread_id, &p_lastest_mail_id, &p_thread_item_count) != EMAIL_ERROR_NONE) + EM_DEBUG_LOG("emstorage_get_thread_id_of_thread_mails is failed."); + + /* Original mailbox replace thread id */ + if (!emstorage_update_latest_thread_mail(account_id, mail_list[i].mailbox_id, mail_list[i].thread_id, NULL, 0, 0, NOTI_THREAD_ID_CHANGED_BY_MOVE_OR_DELETE, false, &err)) { EM_DEBUG_EXCEPTION("emstorage_update_latest_thread_mail failed [%d]", err); + goto FINISH_OFF; + } + + /* Destination mailbox replace thread id */ + if (p_thread_id == -1) { + if (!emstorage_update_latest_thread_mail(account_id, p_mail_data->mailbox_id, p_mail_data->mail_id, NULL, p_mail_data->mail_id, 1, NOTI_THREAD_ID_CHANGED_BY_MOVE_OR_DELETE, false, &err)) { + EM_DEBUG_EXCEPTION("emstorage_update_latest_thread_mail failed [%d]", err); + goto FINISH_OFF; + } + } else { + if (!emstorage_update_latest_thread_mail(account_id, p_mail_data->mailbox_id, dest_prev_thread_id_list[i], NULL, 0, 0, NOTI_THREAD_ID_CHANGED_BY_MOVE_OR_DELETE, false, &err)) { + EM_DEBUG_EXCEPTION("emstorage_update_latest_thread_mail failed [%d]", err); + goto FINISH_OFF; + } + } + emstorage_free_mail(&p_mail_data, 1, NULL); } if (!emcore_notify_storage_event(NOTI_MAIL_MOVE_FINISH, account_id, noti_param_1, parameter_string, noti_param_2)) EM_DEBUG_EXCEPTION(" emcore_notify_storage_event failed [NOTI_MAIL_MOVE_FINISH] >>>> "); - emcore_display_unread_in_badge(); + emcore_display_unread_in_badge(NULL); ret = true; @@ -4620,9 +5940,11 @@ FINISH_OFF: EM_DEBUG_EXCEPTION(" emcore_notify_storage_event failed [ NOTI_MAIL_MOVE_FAIL ] >>>> "); } + emstorage_free_mail(&p_mail_data, 1, NULL); emstorage_free_mail(&mail_list, mail_ids_count, NULL); EM_SAFE_FREE(parameter_string); + EM_SAFE_FREE(dest_prev_thread_id_list); /*prevent 38972*/ if (err_code != NULL) *err_code = err; @@ -4641,9 +5963,9 @@ INTERNAL_FUNC int emcore_move_mail_on_server(int account_id, int src_mailbox_id, int ret = 1; int mail_id = 0; int i = 0; - + mail_id = mail_ids[0]; - + ref_account = emcore_get_account_reference(account_id); if (!ref_account) { EM_DEBUG_EXCEPTION("emcore_move_mail_on_server failed : get account reference[%d]", account_id); @@ -4689,7 +6011,7 @@ INTERNAL_FUNC int emcore_move_mail_on_server(int account_id, int src_mailbox_id, mail_parameters(stream, SET_COPYUID, emcore_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("emcore_move_mail_on_server : Mail cannot be moved failed"); @@ -4697,7 +6019,7 @@ INTERNAL_FUNC int emcore_move_mail_on_server(int account_id, int src_mailbox_id, } else { /* send EXPUNGE command */ - if (!imap4_send_command(stream, IMAP4_CMD_EXPUNGE, &err_code)) { + if (!emcore_imap4_send_command(stream, IMAP4_CMD_EXPUNGE, &err_code)) { EM_DEBUG_EXCEPTION("imap4_send_command failed [%d]", err_code); if (err_code == EMAIL_ERROR_IMAP4_STORE_FAILURE) @@ -4725,7 +6047,7 @@ INTERNAL_FUNC int emcore_move_mail_on_server(int account_id, int src_mailbox_id, } FINISH_OFF: - if (stream) + if (stream) stream = mail_close (stream); if (ref_account) { @@ -4739,6 +6061,42 @@ FINISH_OFF: return ret; } +INTERNAL_FUNC int emcore_move_mail_on_server_by_server_mail_id(void *mail_stream, char *server_mail_id, char *dest_mailbox_name) +{ + EM_DEBUG_FUNC_BEGIN(); + int err_code = EMAIL_ERROR_NONE; + + if (mail_stream == NULL || server_mail_id == 0 || dest_mailbox_name == NULL) { + EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM"); + err_code = EMAIL_ERROR_INVALID_PARAM; + goto FINISH_OFF; + } + + /* set callback for COPY_UID */ + mail_parameters((MAILSTREAM*)mail_stream, SET_COPYUID, emcore_mail_copyuid); + + EM_DEBUG_LOG("calling mail_copy_full FODLER MAIL COPY "); + + if (!mail_copy_full((MAILSTREAM*)mail_stream, server_mail_id, dest_mailbox_name, CP_UID | CP_MOVE)) { + EM_DEBUG_EXCEPTION("emcore_move_mail_on_server : Mail cannot be moved failed"); + err_code = EMAIL_ERROR_IMAP4_COPY_FAILURE; + } + else { + /* send EXPUNGE command */ + if (!emcore_imap4_send_command((MAILSTREAM*)mail_stream, IMAP4_CMD_EXPUNGE, &err_code)) { + EM_DEBUG_EXCEPTION("imap4_send_command failed [%d]", err_code); + + if (err_code == EMAIL_ERROR_IMAP4_STORE_FAILURE) + err_code = EMAIL_ERROR_MAIL_NOT_FOUND_ON_SERVER; + goto FINISH_OFF; + } + } + +FINISH_OFF: + + EM_DEBUG_FUNC_END("err_code [%d]", err_code); + return err_code; +} static int emcore_copy_mail_to_another_account_on_local_storeage(int input_mail_id, emstorage_mailbox_tbl_t *input_source_mailbox, emstorage_mailbox_tbl_t *input_target_mailbox, int input_task_id, int *output_mail_id) { @@ -4762,8 +6120,15 @@ static int emcore_copy_mail_to_another_account_on_local_storeage(int input_mail_ } /* Check download status */ - if(mail_data->body_download_status != 1) { + if(!(mail_data->body_download_status & EMAIL_BODY_DOWNLOAD_STATUS_FULLY_DOWNLOADED)) { /* If not downloaded, download fully */ +#ifdef __FEATURE_USE_GMIME__ + if (!emcore_gmime_download_body_sections(NULL, input_source_mailbox->account_id, + input_mail_id, (mail_data->attachment_count > 0)?1:0, NO_LIMITATION, input_task_id, 0, 0, &err)) { + EM_DEBUG_EXCEPTION("emcore_gmime_download_body_sections failed - %d", err); + goto FINISH_OFF; + } +#else if (!emcore_download_body_multi_sections_bulk(NULL, input_source_mailbox->account_id, input_mail_id, @@ -4771,10 +6136,12 @@ static int emcore_copy_mail_to_another_account_on_local_storeage(int input_mail_ (mail_data->attachment_count > 0)?1:0, NO_LIMITATION, input_task_id, + 0, /*0: thread excluding event thread */ &err)) { EM_DEBUG_EXCEPTION("emcore_download_body_multi_sections_bulk failed [%d]", err); goto FINISH_OFF; } +#endif } /* Get attachments */ @@ -4907,11 +6274,11 @@ FINISH_OFF: return err; } -INTERNAL_FUNC int emcore_save_mail_file(int account_id, int mail_id, int attachment_id, char *src_file_path, char *file_name, char *full_path, int *err_code) +INTERNAL_FUNC int emcore_save_mail_file(int account_id, int mail_id, int attachment_id, char *src_file_path, char *file_name, char *full_path, int max_path_len, int *err_code) { 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 = EMAIL_ERROR_NONE; + int err = EMAIL_ERROR_NONE; if (!file_name || !full_path || !src_file_path) { EM_DEBUG_EXCEPTION("Invalid paramter"); @@ -4923,8 +6290,8 @@ INTERNAL_FUNC int emcore_save_mail_file(int account_id, int mail_id, int attachm EM_DEBUG_EXCEPTION("emstorage_create_dir failed [%d]", err); goto FINISH_OFF; } - - if (!emstorage_get_save_name(account_id, mail_id, attachment_id, file_name, full_path, &err)) { + + if (!emstorage_get_save_name(account_id, mail_id, attachment_id, file_name, full_path, max_path_len, &err)) { EM_DEBUG_EXCEPTION("emstorage_get_save_name failed [%d]", err); goto FINISH_OFF; } @@ -4936,8 +6303,6 @@ INTERNAL_FUNC int emcore_save_mail_file(int account_id, int mail_id, int attachm } } - ret = true; - FINISH_OFF: if (err_code) *err_code = err; @@ -4974,31 +6339,31 @@ INTERNAL_FUNC int emcore_update_mail(email_mail_data_t *input_mail_data, email_a if (stat(input_mail_data->file_path_plain, &st_buf) < 0) { EM_DEBUG_EXCEPTION_SEC("input_mail_data->file_path_plain, stat(\"%s\") failed...", input_mail_data->file_path_plain); err = EMAIL_ERROR_FILE_NOT_FOUND; - goto FINISH_OFF; + goto FINISH_OFF2; } } - + if (input_mail_data->file_path_html) { if (stat(input_mail_data->file_path_html, &st_buf) < 0) { EM_DEBUG_EXCEPTION_SEC("input_mail_data->file_path_html, stat(\"%s\") failed...", input_mail_data->file_path_html); err = EMAIL_ERROR_FILE_NOT_FOUND; - goto FINISH_OFF; + goto FINISH_OFF2; } } - + if (input_attachment_count && input_attachment_data_list) { for (i = 0; i < input_attachment_count; i++) { if (input_attachment_data_list[i].save_status) { if (!input_attachment_data_list[i].attachment_path || stat(input_attachment_data_list[i].attachment_path, &st_buf) < 0) { EM_DEBUG_EXCEPTION("stat(\"%s\") failed...", input_attachment_data_list[i].attachment_path); err = EMAIL_ERROR_FILE_NOT_FOUND; - goto FINISH_OFF; + goto FINISH_OFF2; } } } } } - + if(input_mail_data->mail_size == 0) { emcore_calc_mail_size(input_mail_data, input_attachment_data_list, input_attachment_count, &(input_mail_data->mail_size)); } @@ -5007,26 +6372,26 @@ INTERNAL_FUNC int emcore_update_mail(email_mail_data_t *input_mail_data, email_a if ( (err = em_get_file_name_from_file_path(input_mail_data->file_path_plain, &body_text_file_name)) != EMAIL_ERROR_NONE) { EM_DEBUG_EXCEPTION("em_get_file_name_from_file_path failed [%d]", err); err = EMAIL_ERROR_INVALID_FILE_PATH; - goto FINISH_OFF; + goto FINISH_OFF2; } - if (!emcore_save_mail_file(input_mail_data->account_id, input_mail_data->mail_id, 0, input_mail_data->file_path_plain, body_text_file_name, filename_buf, &err)) { + if (!emcore_save_mail_file(input_mail_data->account_id, input_mail_data->mail_id, 0, input_mail_data->file_path_plain, body_text_file_name, filename_buf, sizeof(filename_buf), &err)) { EM_DEBUG_EXCEPTION("emcore_save_mail_file failed [%d]", err); goto FINISH_OFF2; } EM_SAFE_FREE(input_mail_data->file_path_plain); input_mail_data->file_path_plain = EM_SAFE_STRDUP(filename_buf); } - + if (input_mail_data->file_path_html) { /* Save HTML text body. */ EM_SAFE_FREE(body_text_file_name); if ( (err = em_get_file_name_from_file_path(input_mail_data->file_path_html, &body_text_file_name)) != EMAIL_ERROR_NONE) { EM_DEBUG_EXCEPTION("em_get_file_name_from_file_path failed [%d]", err); err = EMAIL_ERROR_INVALID_FILE_PATH; - goto FINISH_OFF; + goto FINISH_OFF2; } - if (!emcore_save_mail_file(input_mail_data->account_id, input_mail_data->mail_id, 0, input_mail_data->file_path_html, body_text_file_name, filename_buf, &err)) { + if (!emcore_save_mail_file(input_mail_data->account_id, input_mail_data->mail_id, 0, input_mail_data->file_path_html, body_text_file_name, filename_buf, sizeof(filename_buf), &err)) { EM_DEBUG_EXCEPTION("emcore_save_mail_file failed [%d]", err); goto FINISH_OFF2; } @@ -5035,7 +6400,7 @@ INTERNAL_FUNC int emcore_update_mail(email_mail_data_t *input_mail_data, email_a } if (input_mail_data->file_path_mime_entity) { /* Save mime entity. */ - if (!emcore_save_mail_file(input_mail_data->account_id, input_mail_data->mail_id, 0, input_mail_data->file_path_mime_entity, "mime_entity", filename_buf, &err)) { + if (!emcore_save_mail_file(input_mail_data->account_id, input_mail_data->mail_id, 0, input_mail_data->file_path_mime_entity, "mime_entity", filename_buf, sizeof(filename_buf), &err)) { EM_DEBUG_EXCEPTION("emcore_save_mail_file failed [%d]", err); goto FINISH_OFF2; } @@ -5048,50 +6413,50 @@ INTERNAL_FUNC int emcore_update_mail(email_mail_data_t *input_mail_data, email_a int j = 0; int compare_result = 1; email_attachment_data_t *temp_attachment_data = NULL; - + if ((err = emcore_get_attachment_data_list(input_mail_data->mail_id, &ori_attachment_data_list, &ori_attachment_count)) != EMAIL_ERROR_NONE) { EM_DEBUG_EXCEPTION("emcore_get_attachment_data_list failed : [%d]", err); } - if (ori_attachment_count > 0) { /* prevent 33415 */ - temp_attachment_id_array = em_malloc (sizeof(int) * ori_attachment_count); - if (temp_attachment_id_array == NULL) { - EM_DEBUG_EXCEPTION("em_malloc failed"); - err = EMAIL_ERROR_OUT_OF_MEMORY; - goto FINISH_OFF2; - } + temp_attachment_id_array = em_malloc (sizeof(int) * input_attachment_count); + if (temp_attachment_id_array == NULL) { + EM_DEBUG_EXCEPTION("em_malloc failed"); + err = EMAIL_ERROR_OUT_OF_MEMORY; + goto FINISH_OFF2; } - + for(i = 0; i < input_attachment_count; i++) { temp_attachment_data = input_attachment_data_list + i; if ( (err = emcore_mail_compare_filename_of_attachment_data(input_mail_data->mail_id, \ temp_attachment_data->attachment_id, temp_attachment_data, &compare_result)) != EMAIL_ERROR_NONE) { - if (err == EMAIL_ERROR_ATTACHMENT_NOT_FOUND) + if (err == EMAIL_ERROR_ATTACHMENT_NOT_FOUND) EM_DEBUG_LOG ("no attachment found"); else EM_DEBUG_EXCEPTION ("emcore_mail_compare_filename_of_attachment_data failed [%d]", err); } - - if (compare_result == 0) { + + switch (compare_result) { + case 0 : EM_DEBUG_LOG("file name and attachment id are same, update exising attachment"); if (!emcore_mail_update_attachment_data(input_mail_data->mail_id, temp_attachment_data)) { EM_DEBUG_EXCEPTION("emcore_mail_update_attachment_data failed [%d]", err); goto FINISH_OFF2; } temp_attachment_id_array[i] = temp_attachment_data->attachment_id; - } - else { + break; + case 1 : EM_DEBUG_LOG("save names are different"); - if(temp_attachment_data->attachment_id > 0) { - if (!emcore_delete_mail_attachment(temp_attachment_data->attachment_id, &err)) { - EM_DEBUG_EXCEPTION("emcore_delete_mail_attachment failed [%d]", err); - } - } - if ( (err = emcore_add_attachment_data(input_mail_data->mail_id, temp_attachment_data)) != EMAIL_ERROR_NONE) { EM_DEBUG_EXCEPTION("emcore_add_attachment failed [%d]", err); goto FINISH_OFF2; } + + temp_attachment_id_array[i] = temp_attachment_data->attachment_id; + break; + case 2 : + EM_DEBUG_LOG("No chagned the attachment info"); + temp_attachment_id_array[i] = temp_attachment_data->attachment_id; + break; } if (temp_attachment_data->inline_content_status) @@ -5099,23 +6464,48 @@ INTERNAL_FUNC int emcore_update_mail(email_mail_data_t *input_mail_data, email_a } for (i = 0; i < ori_attachment_count; i++) { + emstorage_attachment_tbl_t *temp_attachment_tbl_t = NULL; + temp_attachment_data = ori_attachment_data_list + i; compare_result = 0; + for (j = 0; j < input_attachment_count; j++) { - if (temp_attachment_id_array[j] != temp_attachment_data->attachment_id) - continue; - - compare_result = 1; + if (!emstorage_get_attachment(temp_attachment_id_array[j], &temp_attachment_tbl_t, false, &err)) { + EM_DEBUG_EXCEPTION("emstorage_get_attachment failed : [%d]", err); + continue; + } + + if (temp_attachment_id_array[j] == temp_attachment_data->attachment_id) { + compare_result = 1; + break; + } + + if ((temp_attachment_data->inline_content_status == INLINE_ATTACHMENT) && (strcmp(temp_attachment_tbl_t->attachment_name, temp_attachment_data->attachment_name) == 0)) + compare_result = 2; + + emstorage_free_attachment(&temp_attachment_tbl_t, 1, NULL); + } - if (!compare_result) { + switch (compare_result) { + case 0 : /* Delete the attachment on db and file */ if (!emcore_delete_mail_attachment(temp_attachment_data->attachment_id, &err)) { EM_DEBUG_EXCEPTION("emcore_delete_mail_attachment failed [%d]", err); } + break; + case 2 : /* Delete the attachment on db */ + if (!emstorage_delete_attachment_on_db(temp_attachment_data->attachment_id, true, &err)) { + EM_DEBUG_EXCEPTION("emstorage_delete_attachment_on_db failed : [%d]", err); + } + break; + case 1: + break; } + + emstorage_free_attachment(&temp_attachment_tbl_t, 1, NULL); } } - + input_mail_data->attachment_count = input_attachment_count - local_inline_content_count; input_mail_data->inline_content_count = local_inline_content_count; @@ -5137,13 +6527,13 @@ INTERNAL_FUNC int emcore_update_mail(email_mail_data_t *input_mail_data, email_a EM_DEBUG_EXCEPTION("em_convert_mail_data_to_mail_tbl failed[%d]", err); goto FINISH_OFF2; } - + /* BEGIN TRANSACTION; */ if (!emstorage_begin_transaction(NULL, NULL, &err)) { EM_DEBUG_EXCEPTION("emstorage_begin_transaction failed [%d]", err); goto FINISH_OFF2; } - + if (!emstorage_change_mail_field(input_mail_data->mail_id, UPDATE_MAIL, converted_mail_tbl_data, false, &err)) { EM_DEBUG_EXCEPTION("emstorage_change_mail_field failed [%d]", err); goto FINISH_OFF; @@ -5159,6 +6549,7 @@ INTERNAL_FUNC int emcore_update_mail(email_mail_data_t *input_mail_data, email_a emstorage_mail_text_tbl_t *mail_text; if (!emstorage_get_mail_text_by_id(input_mail_data->mail_id, &mail_text, true, &err) || !mail_text) { EM_DEBUG_EXCEPTION("emstorage_get_mail_text_by_id failed [%d]", err); + EM_SAFE_FREE(stripped_text); goto FINISH_OFF; } @@ -5174,7 +6565,7 @@ INTERNAL_FUNC int emcore_update_mail(email_mail_data_t *input_mail_data, email_a if (mail_text) emstorage_free_mail_text(&mail_text, 1, NULL); #endif - + if (input_mail_data->meeting_request_status == EMAIL_MAIL_TYPE_MEETING_REQUEST || input_mail_data->meeting_request_status == EMAIL_MAIL_TYPE_MEETING_RESPONSE || input_mail_data->meeting_request_status == EMAIL_MAIL_TYPE_MEETING_ORIGINATINGREQUEST) { @@ -5183,7 +6574,6 @@ INTERNAL_FUNC int emcore_update_mail(email_mail_data_t *input_mail_data, email_a EM_DEBUG_EXCEPTION("emstorage_get_meeting_request failed [%d]", err); goto FINISH_OFF; } - EM_SAFE_FREE(meeting_req); if (err == EMAIL_ERROR_DATA_NOT_FOUND) { /* insert */ emstorage_mail_tbl_t *original_mail = NULL; @@ -5195,7 +6585,7 @@ INTERNAL_FUNC int emcore_update_mail(email_mail_data_t *input_mail_data, email_a if (original_mail) { if (!emstorage_add_meeting_request(input_mail_data->account_id, original_mail->mailbox_id, input_meeting_request, false, &err)) { EM_DEBUG_EXCEPTION("emstorage_add_meeting_request failed [%d]", err); - + emstorage_free_mail(&original_mail, 1, NULL); goto FINISH_OFF; } emstorage_free_mail(&original_mail, 1, NULL); @@ -5209,8 +6599,8 @@ INTERNAL_FUNC int emcore_update_mail(email_mail_data_t *input_mail_data, email_a } } } - -FINISH_OFF: + +FINISH_OFF: if (err == EMAIL_ERROR_NONE) { /* COMMIT TRANSACTION; */ if (emstorage_commit_transaction(NULL, NULL, NULL) == false) { @@ -5227,7 +6617,7 @@ FINISH_OFF: if (emstorage_rollback_transaction(NULL, NULL, NULL) == false) err = EMAIL_ERROR_DB_FAILURE; } - + FINISH_OFF2: EM_SAFE_FREE(body_text_file_name); @@ -5236,8 +6626,10 @@ FINISH_OFF2: if (ori_attachment_data_list) emcore_free_attachment_data(&ori_attachment_data_list, ori_attachment_count, NULL); - if(meeting_req) + if(meeting_req) { emstorage_free_meeting_request(meeting_req); + EM_SAFE_FREE(meeting_req); + } if(converted_mail_tbl_data) emstorage_free_mail(&converted_mail_tbl_data, 1, NULL); @@ -5269,36 +6661,36 @@ INTERNAL_FUNC int emcore_set_flags_field(int account_id, int mail_ids[], int num } if(field_type == EMAIL_FLAGS_SEEN_FIELD) - emcore_display_unread_in_badge(); + emcore_display_unread_in_badge(NULL); ret = true; - -FINISH_OFF: - + +FINISH_OFF: + if (err_code) *err_code = err; - EM_DEBUG_FUNC_END("err [%d]", err); + EM_DEBUG_FUNC_END("err [%d]", err); return ret; } int emcore_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 = EMAIL_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 = EMAIL_ERROR_INVALID_PARAM; goto FINISH_OFF; } - + pop3local = (POP3LOCAL *)(((MAILSTREAM *)stream)->local); if (!pop3local || !pop3local->netstream) { @@ -5313,7 +6705,7 @@ int emcore_mail_cmd_read_mail_pop3(void *stream, int msgno, int limited_size, in 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)EM_SAFE_STRLEN(command))) { EM_DEBUG_EXCEPTION("net_sout failed..."); @@ -5382,7 +6774,7 @@ int emcore_mail_cmd_read_mail_pop3(void *stream, int msgno, int limited_size, in EM_DEBUG_EXCEPTION("pop3_send failed..."); email_session_t *session = NULL; - + if (!emcore_get_current_session(&session)) { EM_DEBUG_EXCEPTION("emcore_get_current_session failed..."); err = EMAIL_ERROR_SESSION_NOT_FOUND; @@ -5398,30 +6790,29 @@ int emcore_mail_cmd_read_mail_pop3(void *stream, int msgno, int limited_size, in } ret = true; - -FINISH_OFF: + +FINISH_OFF: EM_SAFE_FREE(response); - + if (err_code != NULL) *err_code = err; - EM_DEBUG_FUNC_END("err [%d]", err); + EM_DEBUG_FUNC_END("err [%d]", err); return ret; } -INTERNAL_FUNC int emcore_sync_flag_with_server(int mail_id, int *err_code) +INTERNAL_FUNC int emcore_sync_flag_with_server(int mail_id, int event_handle, 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 = EMAIL_ERROR_INVALID_PARAM; return false; } - + int ret = false; int err = EMAIL_ERROR_NONE; - int status = EMAIL_DOWNLOAD_FAIL; MAILSTREAM *stream = NULL; email_internal_mailbox_t mailbox = {0}; emstorage_mail_tbl_t *mail = NULL; @@ -5431,12 +6822,9 @@ INTERNAL_FUNC int emcore_sync_flag_with_server(int mail_id, int *err_code) char set_flags[100] = { 0, }; char clear_flags[100] = { 0, }; char tmp[100] = { 0, }; - - if (!emcore_check_thread_status()) { - err = EMAIL_ERROR_CANCELLED; - goto FINISH_OFF; - } - + + FINISH_OFF_IF_EVENT_CANCELED (err, event_handle); + if (!emstorage_get_mail_by_id(mail_id, &mail, true, &err) || !mail) { EM_DEBUG_EXCEPTION("emstorage_get_mail_by_id failed [%d]", err); @@ -5450,23 +6838,16 @@ INTERNAL_FUNC int emcore_sync_flag_with_server(int mail_id, int *err_code) err = EMAIL_ERROR_INVALID_ACCOUNT; goto FINISH_OFF; } - - if (!emcore_check_thread_status()) { - err = EMAIL_ERROR_CANCELLED; - goto FINISH_OFF; - } + + FINISH_OFF_IF_EVENT_CANCELED (err, event_handle); /* open mail server. */ if (!emcore_connect_to_remote_mailbox(account_id, mail->mailbox_id, (void **)&stream, &err) || !stream) { EM_DEBUG_EXCEPTION("emcore_connect_to_remote_mailbox failed [%d]", err); - status = EMAIL_LIST_CONNECTION_FAIL; goto FINISH_OFF; } - if (!emcore_check_thread_status()) { - err = EMAIL_ERROR_CANCELLED; - goto FINISH_OFF; - } + FINISH_OFF_IF_EVENT_CANCELED (err, event_handle); mailbox.mailbox_id = mail->mailbox_id; mailbox.account_id = account_id; @@ -5477,7 +6858,7 @@ INTERNAL_FUNC int emcore_sync_flag_with_server(int mail_id, int *err_code) EM_DEBUG_EXCEPTION("emcore_get_mail_msgno_by_uid failed message_no : %d ", err); goto FINISH_OFF; } - + sprintf (tmp, "%d", msgno); if (mail->flags_seen_field) @@ -5489,7 +6870,7 @@ INTERNAL_FUNC int emcore_sync_flag_with_server(int mail_id, int *err_code) sprintf(set_flags, "%s \\Answered", set_flags); else sprintf(clear_flags, "%s \\Answered", clear_flags); - + if (mail->flags_flagged_field) sprintf(set_flags, "%s \\Flagged", set_flags); else @@ -5511,7 +6892,7 @@ INTERNAL_FUNC int emcore_sync_flag_with_server(int mail_id, int *err_code) 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"); @@ -5524,15 +6905,12 @@ INTERNAL_FUNC int emcore_sync_flag_with_server(int mail_id, int *err_code) EM_DEBUG_LOG(">>>> Returning from emcore_sync_flag_with_server "); - if (!emcore_check_thread_status()) { - err = EMAIL_ERROR_CANCELLED; - goto FINISH_OFF; - } + FINISH_OFF_IF_EVENT_CANCELED (err, event_handle); ret = true; -FINISH_OFF: - +FINISH_OFF: + if (stream) stream = mail_close (stream); @@ -5546,11 +6924,11 @@ FINISH_OFF: if (err_code != NULL) *err_code = err; - EM_DEBUG_FUNC_END("err [%d]", err); + EM_DEBUG_FUNC_END("err [%d]", err); return ret; } -INTERNAL_FUNC int emcore_sync_seen_flag_with_server(int mail_ids[], int num, int *err_code) +INTERNAL_FUNC int emcore_sync_seen_flag_with_server(int mail_ids[], int num, int event_handle, int *err_code) { EM_DEBUG_FUNC_BEGIN("mail_ids[%p], err_code[%p]", mail_ids[0], err_code); @@ -5562,7 +6940,6 @@ INTERNAL_FUNC int emcore_sync_seen_flag_with_server(int mail_ids[], int num, int int ret = false; int err = EMAIL_ERROR_NONE; - int status = EMAIL_DOWNLOAD_FAIL; MAILSTREAM *stream = NULL; email_internal_mailbox_t mailbox; emstorage_mail_tbl_t *mail = NULL; @@ -5592,43 +6969,36 @@ INTERNAL_FUNC int emcore_sync_seen_flag_with_server(int mail_ids[], int num, int err = EMAIL_ERROR_INVALID_ACCOUNT; goto FINISH_OFF; } - + /* open mail server. */ if (!emcore_connect_to_remote_mailbox(account_id, mail->mailbox_id, (void **)&stream, &err) || !stream) { EM_DEBUG_EXCEPTION("emcore_connect_to_remote_mailbox failed [%d]", err); - status = EMAIL_LIST_CONNECTION_FAIL; goto FINISH_OFF; } mailbox.mailbox_id = mail->mailbox_id; mailbox.account_id = account_id; mailbox.mail_stream = stream; - + for (i = 0; i < num; i++) { mail_id = mail_ids[i]; - - if (!emcore_check_thread_status()) { - err = EMAIL_ERROR_CANCELLED; - goto FINISH_OFF; - } + + FINISH_OFF_IF_EVENT_CANCELED (err, event_handle); if (!emstorage_get_mail_by_id(mail_id, &mail, true, &err) || !mail) { EM_DEBUG_EXCEPTION("emstorage_get_mail_by_id failed [%d]", err); - - goto FINISH_OFF; - } - - if (!emcore_check_thread_status()) { - err = EMAIL_ERROR_CANCELLED; + goto FINISH_OFF; } + FINISH_OFF_IF_EVENT_CANCELED (err, event_handle); + /* download message number from server. */ if (!emcore_get_mail_msgno_by_uid(ref_account, &mailbox, mail->server_mail_id, &msgno, &err)) { EM_DEBUG_LOG("emcore_get_mail_msgno_by_uid failed message_no : %d ", err); goto FINISH_OFF; } - + memset(tmp, 0x00, 100); sprintf (tmp, "%d", msgno); @@ -5654,18 +7024,15 @@ INTERNAL_FUNC int emcore_sync_seen_flag_with_server(int mail_ids[], int num, int EM_DEBUG_LOG(">>>> Returning from emcore_sync_flag_with_server "); - if (!emcore_check_thread_status()) { - err = EMAIL_ERROR_CANCELLED; - goto FINISH_OFF; - } + FINISH_OFF_IF_EVENT_CANCELED (err, event_handle); } ret = true; FINISH_OFF: - - if (stream) + + if (stream) stream = mail_close (stream); - if (mail) + if (mail) emstorage_free_mail(&mail, 1, NULL); if (ref_account) { @@ -5682,13 +7049,13 @@ FINISH_OFF: INTERNAL_FUNC void emcore_free_mail_data_list(email_mail_data_t **mail_list, int count) { EM_DEBUG_FUNC_BEGIN("count[%d]", count); - - if (count <= 0 || !mail_list || !*mail_list) + + if (count <= 0 || !mail_list || !*mail_list) return; - + email_mail_data_t* p = *mail_list; int i; - + for (i = 0; i < count; i++) emcore_free_mail_data( p+i); @@ -5696,7 +7063,7 @@ INTERNAL_FUNC void emcore_free_mail_data_list(email_mail_data_t **mail_list, int EM_DEBUG_FUNC_END(); } - + INTERNAL_FUNC void emcore_free_mail_data(email_mail_data_t *mail_data) { EM_DEBUG_FUNC_BEGIN(); @@ -5724,37 +7091,39 @@ INTERNAL_FUNC void emcore_free_mail_data(email_mail_data_t *mail_data) EM_SAFE_FREE(mail_data->file_path_html); EM_SAFE_FREE(mail_data->file_path_mime_entity); EM_SAFE_FREE(mail_data->preview_text); + EM_SAFE_FREE(mail_data->pgp_password); EM_SAFE_FREE(mail_data->eas_data); - EM_DEBUG_FUNC_END(); + EM_DEBUG_FUNC_END(); } INTERNAL_FUNC int emcore_free_attachment_data(email_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); - + 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 = EMAIL_ERROR_INVALID_PARAM; return false; } - + email_attachment_data_t* p = *attachment_data_list; int i = 0; - + for (i = 0; i < attachment_data_count; i++) { EM_SAFE_FREE(p[i].attachment_name); EM_SAFE_FREE(p[i].attachment_path); EM_SAFE_FREE(p[i].attachment_mime_type); + EM_SAFE_FREE(p[i].content_id); } EM_SAFE_FREE(p); *attachment_data_list = NULL; if(err_code) *err_code = EMAIL_ERROR_NONE; - - EM_DEBUG_FUNC_END(); + + EM_DEBUG_FUNC_END(); return true; } @@ -5762,7 +7131,7 @@ INTERNAL_FUNC int emcore_free_attachment_data(email_attachment_data_t **attachme #ifdef __FEATURE_PARTIAL_BODY_DOWNLOAD__ -INTERNAL_FUNC int emcore_delete_pbd_activity(int account_id, int mail_id, int activity_id, int *err_code) +INTERNAL_FUNC int emcore_delete_pbd_activity(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); @@ -5776,13 +7145,13 @@ INTERNAL_FUNC int emcore_delete_pbd_activity(int account_id, int mail_id, int ac int ret = false; int err = EMAIL_ERROR_NONE; int before_tr_begin = 0; - + if (!emstorage_begin_transaction(NULL, NULL, &err)) { EM_DEBUG_EXCEPTION("emstorage_begin_transaction failed [%d]", err); before_tr_begin = 1; goto FINISH_OFF; } - + if (!emstorage_delete_pbd_activity(account_id, mail_id, activity_id, false, &err)) { EM_DEBUG_EXCEPTION("emstorage_delete_pbd_activity failed [%d]", err); goto FINISH_OFF; @@ -5790,7 +7159,7 @@ INTERNAL_FUNC int emcore_delete_pbd_activity(int account_id, int mail_id, int ac ret = true; -FINISH_OFF: +FINISH_OFF: if (ret == true) { /* COMMIT TRANSACTION; */ if (emstorage_commit_transaction(NULL, NULL, NULL) == false) { err = EMAIL_ERROR_DB_FAILURE; @@ -5799,15 +7168,15 @@ FINISH_OFF: } else { /* ROLLBACK TRANSACTION; */ if (!before_tr_begin && emstorage_rollback_transaction(NULL, NULL, NULL) == false) err = EMAIL_ERROR_DB_FAILURE; - } - + } + if (err_code != NULL) *err_code = err; EM_DEBUG_FUNC_END(); return ret; } -INTERNAL_FUNC int emcore_insert_pbd_activity(email_event_partial_body_thd *local_activity, int *activity_id, int *err_code) +INTERNAL_FUNC int emcore_insert_pbd_activity(email_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); @@ -5817,17 +7186,17 @@ INTERNAL_FUNC int emcore_insert_pbd_activity(email_event_partial_body_thd *local *err_code = EMAIL_ERROR_INVALID_PARAM; return false; } - + int ret = false; int err = EMAIL_ERROR_NONE; int before_tr_begin = 0; - + if (!emstorage_begin_transaction(NULL, NULL, &err)) { EM_DEBUG_EXCEPTION("emstorage_begin_transaction failed [%d]", err); before_tr_begin = 1; goto FINISH_OFF; } - + if (!emstorage_add_pbd_activity(local_activity, activity_id, false, &err)) { EM_DEBUG_EXCEPTION("emstorage_add_pbd_activity failed [%d]", err); goto FINISH_OFF; @@ -5835,7 +7204,7 @@ INTERNAL_FUNC int emcore_insert_pbd_activity(email_event_partial_body_thd *local ret = true; -FINISH_OFF: +FINISH_OFF: if (ret == true) { /* COMMIT TRANSACTION; */ if (emstorage_commit_transaction(NULL, NULL, NULL) == false) { err = EMAIL_ERROR_DB_FAILURE; @@ -5844,8 +7213,8 @@ FINISH_OFF: } else { /* ROLLBACK TRANSACTION; */ if (!before_tr_begin && emstorage_rollback_transaction(NULL, NULL, NULL) == false) err = EMAIL_ERROR_DB_FAILURE; - } - + } + if (err_code != NULL) *err_code = err; EM_DEBUG_FUNC_END(); @@ -5861,7 +7230,7 @@ FINISH_OFF: INTERNAL_FUNC int emcore_sync_flags_field_with_server(int mail_ids[], int num, email_flags_field_type field_type, int value, int *err_code) { 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 >= EMAIL_FLAGS_FIELD_COUNT) { EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM"); if (err_code != NULL) { @@ -5869,16 +7238,15 @@ INTERNAL_FUNC int emcore_sync_flags_field_with_server(int mail_ids[], int num, e } 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; + char **string_list = NULL; int ret = false; int err = EMAIL_ERROR_NONE; - int command_success = false; int account_id = 0; int mail_id = 0; int i = 0; @@ -5892,10 +7260,10 @@ INTERNAL_FUNC int emcore_sync_flags_field_with_server(int mail_ids[], int num, e email_uid_range_set *uid_range_node = NULL; char *field_type_name[EMAIL_FLAGS_FIELD_COUNT] = { "\\Seen" , "\\Deleted", "\\Flagged", "\\Answered" - , "\\Recent", "\\Draft", "$Forwarded" }; - + , "\\Recent", "\\Draft", "$Forwarded" }; + mail_id = mail_ids[0]; - + if (!emstorage_get_mail_field_by_id(mail_id, RETRIEVE_FLAG, &mail, true, &err) || !mail) /*To DO : This is a existing bug. on mail deletion before this call it will fail always */ { EM_DEBUG_LOG("emstorage_get_mail_by_id failed [%d]", err); @@ -5911,13 +7279,13 @@ INTERNAL_FUNC int emcore_sync_flags_field_with_server(int mail_ids[], int num, e err = EMAIL_ERROR_INVALID_ACCOUNT; goto FINISH_OFF; } - + if (temp_account->incoming_server_type != EMAIL_SERVER_TYPE_IMAP4) { EM_DEBUG_EXCEPTION("Syncing seen flag is available only for IMAP4 server. The server type [%d]", temp_account->incoming_server_type); err = EMAIL_ERROR_NOT_SUPPORTED; goto FINISH_OFF; } - + if (!emcore_connect_to_remote_mailbox(account_id, mail->mailbox_id, (void **)&stream, &err) || !stream) { EM_DEBUG_EXCEPTION("emcore_connect_to_remote_mailbox failed [%d]", err); goto FINISH_OFF; @@ -5947,11 +7315,11 @@ INTERNAL_FUNC int emcore_sync_flags_field_with_server(int mail_ids[], int num, e EM_DEBUG_EXCEPTION("emstorage_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 == emcore_convert_to_uid_range_set(id_set, id_set_count, &uid_range_set, len_of_each_range, &err)) { EM_DEBUG_EXCEPTION("emcore_convert_to_uid_range_set failed [%d]", err); goto FINISH_OFF; @@ -5963,7 +7331,7 @@ INTERNAL_FUNC int emcore_sync_flags_field_with_server(int mail_ids[], int num, e /* Remove comma from end of uid_range */ uid_range_node->uid_range[EM_SAFE_STRLEN(uid_range_node->uid_range) - 1] = '\0'; - + /* Form the IMAP command */ SNPRINTF(tag, MAX_TAG_SIZE, "%08lx", 0xffffffff & (stream->gensym++)); @@ -5979,74 +7347,69 @@ INTERNAL_FUNC int emcore_sync_flags_field_with_server(int mail_ids[], int num, e if (!(imaplocal = stream->local) || !imaplocal->netstream) { EM_DEBUG_EXCEPTION("invalid IMAP4 stream detected..."); - - err = EMAIL_ERROR_UNKNOWN; + + err = EMAIL_ERROR_UNKNOWN; goto FINISH_OFF; } - + if (!net_sout(imaplocal->netstream, cmd, (int)EM_SAFE_STRLEN(cmd))) { EM_DEBUG_EXCEPTION("net_sout failed..."); - err = EMAIL_ERROR_CONNECTION_BROKEN; + err = EMAIL_ERROR_CONNECTION_BROKEN; goto FINISH_OFF; } /* Receive Response */ - command_success = false; - - while (imaplocal->netstream) { + while (imaplocal->netstream) { if (!(p = net_getline(imaplocal->netstream))) { EM_DEBUG_EXCEPTION("net_getline failed..."); - - err = EMAIL_ERROR_INVALID_RESPONSE; + + err = EMAIL_ERROR_INVALID_RESPONSE; goto FINISH_OFF; } - + EM_DEBUG_LOG("[IMAP4 Response ] %s", p); - + if (!strncmp(p, tag, EM_SAFE_STRLEN(tag))) { if (!strncmp(p + EM_SAFE_STRLEN(tag) + 1, "OK", 2)) { /*Delete all local activities */ - command_success = true; - - EM_SAFE_FREE(p); + EM_SAFE_FREE(p); break; } else { /* 'NO' or 'BAD' */ - command_success = false; - err = EMAIL_ERROR_IMAP4_STORE_FAILURE; + err = EMAIL_ERROR_IMAP4_STORE_FAILURE; EM_SAFE_FREE(p); goto FINISH_OFF; - } + } } - - EM_SAFE_FREE(p); + + EM_SAFE_FREE(p); } uid_range_node = uid_range_node->next; - } + } emcore_free_uid_range_set(&uid_range_set); EM_SAFE_FREE(id_set); - + id_set_count = 0; } ret = true; -FINISH_OFF: +FINISH_OFF: #ifdef __FEATURE_LOCAL_ACTIVITY__ if (ret) { emstorage_activity_tbl_t new_activity; - for (i = 0; i<num ; i++) { + for (i = 0; i<num ; i++) { memset(&new_activity, 0x00, sizeof(emstorage_activity_tbl_t)); new_activity.activity_type = ACTIVITY_MODIFYSEENFLAG; new_activity.account_id = account_id; new_activity.mail_id = mail_ids[i]; - + if (!emcore_delete_activity(&new_activity, &err)) EM_DEBUG_EXCEPTION("Local Activity ACTIVITY_MOVEMAIL [%d] ", err); } @@ -6055,10 +7418,10 @@ FINISH_OFF: #endif if (NULL != mail) { - if (false == emstorage_free_mail(&mail, 1, &err)) + if (false == emstorage_free_mail(&mail, 1, &err)) EM_DEBUG_EXCEPTION("emstorage_free_mail failed - %d ", err); } - + emcore_free_comma_separated_strings(&string_list, &string_count); if (false == ret) @@ -6092,7 +7455,7 @@ static int emcore_mail_move_by_filter_rule(int account_id, int mailbox_id, int m emstorage_mailbox_tbl_t *src_mailbox_tbl = NULL; emstorage_mailbox_tbl_t *dst_mailbox_tbl = NULL; emstorage_mail_tbl_t *mail_tbl = NULL; - + if ((account_id < 0) && !filter_info) { EM_DEBUG_EXCEPTION("Invalid parameter"); err = EMAIL_ERROR_INVALID_PARAM; @@ -6117,20 +7480,25 @@ static int emcore_mail_move_by_filter_rule(int account_id, int mailbox_id, int m goto FINISH_OFF; } - SNPRINTF(parameter_string, parameter_string_length, "[NA]%c%d%c", 0x01, mailbox_id, 0x01); - for (mail_id_index = 0; mail_id_index < filter_mail_id_count; mail_id_index++) { memset(mail_id_string, 0, 10); - SNPRINTF(mail_id_string, 10, "%d", filter_mail_id_list[mail_id_index]); + if ((filter_mail_id_count - 1) == mail_id_index) + SNPRINTF(mail_id_string, 10, "%d", filter_mail_id_list[mail_id_index]); + else + SNPRINTF(mail_id_string, 10, "%d,", filter_mail_id_list[mail_id_index]); strcat(parameter_string, mail_id_string); - strcat(parameter_string, ","); } EM_DEBUG_LOG("filtered_mail_id_count [%d]", filter_mail_id_count); EM_DEBUG_LOG("param string [%s]", parameter_string); - if (!emcore_notify_storage_event(NOTI_MAIL_MOVE, account_id, 0, parameter_string, 0)) - EM_DEBUG_EXCEPTION("emcore_notify_storage_event failed [ NOTI_MAIL_MOVE ] >>>> "); + if (filter_info->type == EMAIL_PRIORITY_SENDER) { + if (!emcore_notify_storage_event(NOTI_RULE_APPLY, account_id, filter_info->rule_id, parameter_string, 0)) + EM_DEBUG_EXCEPTION("emcore_notify_storage_event failed [ NOTI_MAIL_MOVE ] >>>> "); + } else { + if (!emcore_notify_storage_event(NOTI_MAIL_MOVE, account_id, 0, parameter_string, 0)) + EM_DEBUG_EXCEPTION("emcore_notify_storage_event failed [ NOTI_MAIL_MOVE ] >>>> "); + } } if (filter_info->action_type != EMAIL_FILTER_MOVE) { @@ -6156,11 +7524,16 @@ static int emcore_mail_move_by_filter_rule(int account_id, int mailbox_id, int m goto FINISH_OFF; } +#ifdef __FEATURE_WIFI_AUTO_DOWNLOAD__ + if (!emstorage_update_auto_download_activity(mail_tbl->server_mail_id, g_new_server_uid, NULL, dst_mailbox_tbl->mailbox_id, &err)) + EM_DEBUG_EXCEPTION("emstorage_update_auto_download_activity failed : [%d]", err); +#endif + emstorage_free_mailbox(&src_mailbox_tbl, 1, NULL); /*prevent 46750*/ } } -FINISH_OFF: +FINISH_OFF: if (src_mailbox_tbl) emstorage_free_mailbox(&src_mailbox_tbl, 1, NULL); @@ -6200,7 +7573,7 @@ INTERNAL_FUNC int emcore_mail_filter_by_rule(email_rule_t *filter_info, int *err EM_DEBUG_EXCEPTION("emcore_mail_move_by_filter_rule failed : [%d]", err); goto FINISH_OFF; } - break; + break; case EMAIL_FILTER_BLOCK : if (!emstorage_get_account_list(&account_count, &account_tbl_t_list, false, false, &err)) { EM_DEBUG_EXCEPTION("emstorage_get_account_list failed [%d]", err); @@ -6219,8 +7592,8 @@ INTERNAL_FUNC int emcore_mail_filter_by_rule(email_rule_t *filter_info, int *err EM_DEBUG_EXCEPTION("emcore_mail_move_by_filter_rule failed : [%d]", err); goto FINISH_OFF; } - - + + } break; case EMAIL_FILTER_DELETE : @@ -6229,12 +7602,12 @@ INTERNAL_FUNC int emcore_mail_filter_by_rule(email_rule_t *filter_info, int *err break; } - emcore_display_unread_in_badge(); + emcore_display_unread_in_badge(NULL); ret = true; -FINISH_OFF: - +FINISH_OFF: + if (account_tbl_t_list) emstorage_free_account(&account_tbl_t_list, account_count, NULL); @@ -6247,3 +7620,249 @@ FINISH_OFF: return ret; } +INTERNAL_FUNC int emcore_add_rule(email_rule_t *filter_info) +{ + EM_DEBUG_FUNC_BEGIN(); + int err = EMAIL_ERROR_NONE; + + if (!emstorage_find_rule((emstorage_rule_tbl_t*)filter_info, true, &err)) { + EM_DEBUG_EXCEPTION("emstorage_find_rule failed [%d]", err); + goto FINISH_OFF; + } else { + if (err != EMAIL_ERROR_FILTER_NOT_FOUND) { + EM_DEBUG_LOG("filter already exist"); + err = EMAIL_ERROR_ALREADY_EXISTS; + goto FINISH_OFF; + } + } + + switch (filter_info->faction) { + case EMAIL_FILTER_MOVE : + if (filter_info->account_id < 0) { + EM_DEBUG_EXCEPTION("Invalid Param : target_mailbox_id[%d], account_id[%d]", filter_info->target_mailbox_id, filter_info->account_id); + err = EMAIL_ERROR_INVALID_PARAM; + goto FINISH_OFF; + } + break; + case EMAIL_FILTER_BLOCK : + filter_info->account_id = ALL_ACCOUNT; + break; + case EMAIL_FILTER_DELETE : + default: + EM_DEBUG_LOG("filter_faction : [%d]", filter_info->faction); + break; + } + + if (!emstorage_add_rule((emstorage_rule_tbl_t*)filter_info, true, &err)) { + EM_DEBUG_EXCEPTION("emstorage_add_rule failed [%d]", err); + goto FINISH_OFF; + } + + EM_DEBUG_LOG("filter_id : [%d]", filter_info->filter_id); + + if (!emcore_notify_storage_event (NOTI_RULE_ADD, filter_info->account_id, filter_info->filter_id, NULL, 0)) + EM_DEBUG_EXCEPTION ("emcore_notify_storage_event failed [NOTI_RULE_ADD]"); + +FINISH_OFF: + + EM_DEBUG_FUNC_END(); + return err; +} + +INTERNAL_FUNC int emcore_update_rule(int filter_id, email_rule_t *filter_info) +{ + EM_DEBUG_FUNC_BEGIN(); + + int err = EMAIL_ERROR_NONE; + int filter_mail_id_count = 0; + int mail_id_index = 0; + int *filter_mail_id_list = NULL; + int parameter_string_length = 0; + char mail_id_string[10] = { 0x00, }; + char *parameter_string = NULL; + + emstorage_rule_tbl_t *old_filter_info = NULL; + + if (filter_id <= 0 || !filter_info) { + EM_DEBUG_EXCEPTION("filter_id [%d], filter_info[%p]", filter_id, filter_info); + err = EMAIL_ERROR_INVALID_PARAM; + return err; + } + + if (!emstorage_get_rule_by_id(filter_id, &old_filter_info, false, &err)) { + EM_DEBUG_EXCEPTION("emstorage_get_rule_by_id failed : [%d]", err); + goto FINISH_OFF; + } + + if (!emstorage_filter_mails_by_rule(old_filter_info->account_id, old_filter_info->target_mailbox_id, false, true, old_filter_info, &filter_mail_id_list, &filter_mail_id_count, &err)) { + EM_DEBUG_EXCEPTION("emstorage_filter_mails_by_rule failed : [%d]", err); + goto FINISH_OFF; + } + + if (filter_mail_id_count) { + parameter_string_length = 10 /*mailbox_id length*/ + 7 + (10 * filter_mail_id_count); + parameter_string = em_malloc(sizeof(char) * parameter_string_length); + if (parameter_string == NULL) { + err = EMAIL_ERROR_OUT_OF_MEMORY; + EM_DEBUG_EXCEPTION("em_malloc failed for parameter_string"); + goto FINISH_OFF; + } + + for (mail_id_index = 0; mail_id_index < filter_mail_id_count; mail_id_index++) { + memset(mail_id_string, 0, 10); + if ((filter_mail_id_count - 1) == mail_id_index) + SNPRINTF(mail_id_string, 10, "%d", filter_mail_id_list[mail_id_index]); + else + SNPRINTF(mail_id_string, 10, "%d,", filter_mail_id_list[mail_id_index]); + strcat(parameter_string, mail_id_string); + } + + EM_DEBUG_LOG("filtered_mail_id_count [%d]", filter_mail_id_count); + EM_DEBUG_LOG("param string [%s]", parameter_string); + } + + if (!emstorage_change_rule(filter_id, (emstorage_rule_tbl_t *)filter_info, true, &err)) { + EM_DEBUG_EXCEPTION("emstorage_change_rule failed [%d]", err); + goto FINISH_OFF; + } + + if (!emcore_notify_storage_event(NOTI_RULE_UPDATE, filter_info->account_id, filter_info->filter_id, parameter_string, 0)) + EM_DEBUG_EXCEPTION("emcore_notify_storage_event failed [NOTI_RULE_UPDATE]"); + +FINISH_OFF: + + if (old_filter_info) + emstorage_free_rule(&old_filter_info, 1, NULL); + + EM_SAFE_FREE(filter_mail_id_list); + EM_SAFE_FREE(parameter_string); + + EM_DEBUG_FUNC_END(); + return err; +} + +INTERNAL_FUNC int emcore_delete_rule(int filter_id) +{ + EM_DEBUG_FUNC_BEGIN(); + int err = EMAIL_ERROR_NONE; + int filter_mail_id_count = 0; + int mail_id_index = 0; + int *filter_mail_id_list = NULL; + int parameter_string_length = 0; + char mail_id_string[10] = { 0x00, }; + char *parameter_string = NULL; + + emstorage_rule_tbl_t *filter_info = NULL; + + if (filter_id <= 0) { + EM_DEBUG_EXCEPTION(" fliter_id[%d]", filter_id); + err = EMAIL_ERROR_INVALID_PARAM; + goto FINISH_OFF; + } + + if (!emstorage_get_rule_by_id(filter_id, &filter_info, false, &err)) { + EM_DEBUG_EXCEPTION("emstorage_get_rule_by_id failed : [%d]", err); + goto FINISH_OFF; + } + + if (!emstorage_filter_mails_by_rule(filter_info->account_id, filter_info->target_mailbox_id, false, true, filter_info, &filter_mail_id_list, &filter_mail_id_count, &err)) { + EM_DEBUG_EXCEPTION("emstorage_filter_mails_by_rule failed : [%d]", err); + goto FINISH_OFF; + } + + if (filter_mail_id_count) { + parameter_string_length = 10 /*mailbox_id length*/ + 7 + (10 * filter_mail_id_count); + parameter_string = em_malloc(sizeof(char) * parameter_string_length); + if (parameter_string == NULL) { + err = EMAIL_ERROR_OUT_OF_MEMORY; + EM_DEBUG_EXCEPTION("em_malloc failed for parameter_string"); + goto FINISH_OFF; + } + + for (mail_id_index = 0; mail_id_index < filter_mail_id_count; mail_id_index++) { + memset(mail_id_string, 0, 10); + if ((filter_mail_id_count - 1) == mail_id_index) + SNPRINTF(mail_id_string, 10, "%d", filter_mail_id_list[mail_id_index]); + else + SNPRINTF(mail_id_string, 10, "%d,", filter_mail_id_list[mail_id_index]); + strcat(parameter_string, mail_id_string); + } + + EM_DEBUG_LOG("filtered_mail_id_count [%d]", filter_mail_id_count); + EM_DEBUG_LOG("param string [%s]", parameter_string); + } + + if (!emstorage_delete_rule(filter_id, true, &err)) { + EM_DEBUG_EXCEPTION(" emstorage_delete_rule failed [%d]", err); + goto FINISH_OFF; + } + + if (!emcore_notify_storage_event (NOTI_RULE_DELETE, 0, filter_id, parameter_string, 0)) + EM_DEBUG_EXCEPTION ("emcore_notify_storage_event failed [NOTI_RULE_DELETE]"); + +FINISH_OFF: + + if (filter_info) + emstorage_free_rule(&filter_info, 1, NULL); + + EM_SAFE_FREE(filter_mail_id_list); + EM_SAFE_FREE(parameter_string); + + EM_DEBUG_FUNC_END(); + return err; +} + +INTERNAL_FUNC void emcore_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); + EM_SAFE_FREE(cnt_info->text.html_charset); + EM_SAFE_FREE(cnt_info->sections); + + while (cnt_info->file) { + p = cnt_info->file->next; + EM_SAFE_FREE(cnt_info->file->name); + EM_SAFE_FREE(cnt_info->file->save); + EM_SAFE_FREE(cnt_info->file->attachment_mime_type); + EM_SAFE_FREE(cnt_info->file->content_id); + EM_SAFE_FREE(cnt_info->file); + cnt_info->file = p; + } + + while (cnt_info->inline_file) { + p = cnt_info->inline_file->next; + EM_SAFE_FREE(cnt_info->inline_file->name); + EM_SAFE_FREE(cnt_info->inline_file->save); + EM_SAFE_FREE(cnt_info->inline_file->attachment_mime_type); + EM_SAFE_FREE(cnt_info->inline_file->content_id); + EM_SAFE_FREE(cnt_info->inline_file); + cnt_info->inline_file = p; + } + + EM_DEBUG_FUNC_END(); +} + +INTERNAL_FUNC void emcore_free_attachment_info(struct attachment_info *attchment) +{ + EM_DEBUG_FUNC_BEGIN(); + struct attachment_info *p; + + if (!attchment) return; + + while (attchment) { + p = attchment->next; + EM_SAFE_FREE(attchment->name); + EM_SAFE_FREE(attchment->save); + EM_SAFE_FREE(attchment->attachment_mime_type); + EM_SAFE_FREE(attchment->content_id); + EM_SAFE_FREE(attchment); + attchment = p; + } + + EM_DEBUG_FUNC_END(); +} diff --git a/email-core/email-core-mailbox-sync.c b/email-core/email-core-mailbox-sync.c index a9c3ae0..fe9b329 100755 --- a/email-core/email-core-mailbox-sync.c +++ b/email-core/email-core-mailbox-sync.c @@ -32,6 +32,8 @@ #include <ctype.h> #include <vconf.h> #include <unicode/ucsdet.h> +#include <glib.h> +#include <glib/gstdio.h> #include "email-internal-types.h" @@ -56,6 +58,7 @@ #include "email-core-account.h" #include "email-storage.h" #include "email-core-signal.h" +#include "email-core-gmime.h" #include "flstring.h" #include "email-debug-log.h" @@ -76,6 +79,29 @@ static int emcore_initiate_pbd(MAILSTREAM *stream, int account_id, int mail_id, static char g_append_uid_rsp[129]; /* added for getting server response */ #endif +static struct { + const char *charset; + const char *tm_zone; +} known_zone_charset[] = { + {"euc-kr", "kst"}, + {"euc-jp", "jst"} +#if 0 + {"Big5", "zh" }, + {"BIG5HKSCS", "zh" }, + {"gb2312", "zh" }, + {"gb18030", "zh" }, + {"gbk", "zh" }, + {"euc-tw", "zh" }, + {"iso-2022-jp", "ja" }, + {"Shift-JIS", "ja" }, + {"sjis", "ja" }, + {"ujis", "ja" }, + {"eucJP", "ja" }, + {"euc-kr", "ko" }, + {"koi8-r", "ru" }, + {"koi8-u", "uk" } +#endif +}; int pop3_mail_calc_rfc822_size(MAILSTREAM *stream, int msgno, int *size, int *err_code) { @@ -356,16 +382,17 @@ FINISH_OFF: return ret; } -int imap4_mailbox_get_uids(MAILSTREAM *stream, emcore_uid_list** uid_list, int *err_code) +int imap4_mailbox_get_uids(MAILSTREAM *stream, char *input_target_uid_string, emcore_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); + EM_DEBUG_FUNC_BEGIN("stream[%p] input_target_uid_string[%p] uid_list[%p] err_code[%p]", stream, input_target_uid_string, uid_list, err_code); int ret = false; int err = EMAIL_ERROR_NONE; - + int command_length = 0; IMAPLOCAL *imaplocal = NULL; - char tag[16], command[64]; + char tag[16]; + char *command= NULL; char *response = NULL; emcore_uid_list *uid_elem = NULL; @@ -385,11 +412,17 @@ int imap4_mailbox_get_uids(MAILSTREAM *stream, emcore_uid_list** uid_list, int * err = EMAIL_ERROR_MAIL_NOT_FOUND_ON_SERVER; goto FINISH_OFF; } + + command_length = sizeof(char) * (EM_SAFE_STRLEN(input_target_uid_string) + sizeof(tag) + 100); + command = em_malloc(command_length); memset(tag, 0x00, sizeof(tag)); - memset(command, 0x00, sizeof(command)); + memset(command, 0x00, command_length); SNPRINTF(tag, sizeof(tag), "%08lx", 0xffffffff & (stream->gensym++)); - SNPRINTF(command, sizeof(command), "%s FETCH 1:* (FLAGS UID)\015\012", tag); + if (input_target_uid_string) + SNPRINTF(command, command_length, "%s UID FETCH %s (FLAGS UID INTERNALDATE)\015\012", tag, input_target_uid_string); + else + SNPRINTF(command, command_length, "%s FETCH 1:* (FLAGS UID INTERNALDATE)\015\012", tag); EM_DEBUG_LOG("COMMAND [%s] \n", command); #ifdef FEATURE_CORE_DEBUG EM_DEBUG_LOG(" [IMAP4] >>> [%s]", command); @@ -406,6 +439,7 @@ int imap4_mailbox_get_uids(MAILSTREAM *stream, emcore_uid_list** uid_list, int * while (imaplocal->netstream) { char *p = NULL; + char *p_date = NULL; char *s = NULL; int seen = 0; int forwarded = 0; @@ -443,6 +477,19 @@ int imap4_mailbox_get_uids(MAILSTREAM *stream, emcore_uid_list** uid_list, int * forwarded = strstr(p, "$Forwarded") ? 1 : 0; if ((p = strstr(p, "UID "))) { + + /* get INTERNALDATE */ + char internaldate[100] = {0,}; + if ((p_date = strstr(p, "INTERNALDATE \""))) { + int i = 0; + p_date += strlen("INTERNALDATE \""); + while (*p_date != '"' && i < 99) { + internaldate[i] = *p_date; + i++; + p_date++; + } + } + s = p + strlen("UID "); while (isdigit(*s)) @@ -462,6 +509,7 @@ int imap4_mailbox_get_uids(MAILSTREAM *stream, emcore_uid_list** uid_list, int * uid_elem->flag.draft = draft; uid_elem->flag.forwarded = forwarded; uid_elem->flag.flagged = flagged; + uid_elem->internaldate = EM_SAFE_STRDUP(internaldate); if (*uid_list != NULL) uid_elem->next = *uid_list; /* prepend new data to list */ @@ -478,13 +526,14 @@ int imap4_mailbox_get_uids(MAILSTREAM *stream, emcore_uid_list** uid_list, int * goto FINISH_OFF; } - EM_SAFE_FREE(response);; + EM_SAFE_FREE(response); } ret = true; FINISH_OFF: EM_SAFE_FREE(response); + EM_SAFE_FREE(command); if (err_code != NULL) *err_code = err; @@ -494,53 +543,160 @@ FINISH_OFF: return ret; } -static char *__em_get_month_in_string(int month) +int emcore_get_uids_order_by_datetime_from_imap_server(MAILSTREAM *stream, int count_to_download, emcore_uid_list** output_uid_list) { - EM_DEBUG_FUNC_BEGIN("month [%d]", month); + EM_PROFILE_BEGIN(emcore_get_uids_order_by_datetime_from_imap_server); + EM_DEBUG_FUNC_BEGIN("stream[%p] count_to_download [%d] output_uid_list[%p]", stream, count_to_download, output_uid_list); - char *mon = NULL; + int err = EMAIL_ERROR_NONE; + + IMAPLOCAL *imaplocal = NULL; + char tag[16], command[64]; + char *response = NULL; + emcore_uid_list *uid_elem = NULL; + char delims[] = " "; + char *result = NULL; + int uid_count = 0; + time_t RawTime = 0; + char since_date_string[20]; + char before_date_string[20]; + char *uid_range_string = NULL; + emcore_uid_list *uid_list_for_listing = NULL; + + if (!stream || !output_uid_list) { + EM_DEBUG_EXCEPTION(" stream[%p], output_uid_list[%p]", stream, output_uid_list); + err = EMAIL_ERROR_INVALID_PARAM; + goto FINISH_OFF; + } + + if (!(imaplocal = stream->local) || !imaplocal->netstream) { + EM_DEBUG_EXCEPTION(" invalid IMAP4 stream detected..."); + err = EMAIL_ERROR_INVALID_PARAM; /* EMAIL_ERROR_UNKNOWN */ + goto FINISH_OFF; + } + + /* Fetch the System time and Retrieve the a Week before time */ + time(&RawTime); + + while (uid_count <= count_to_download) { + RawTime = RawTime - (604800 * 4); //4 Weeks Before - switch (month){ - case 0: - mon = strdup("jan"); - break; - case 1: - mon = strdup("feb"); - break; - case 2: - mon = strdup("mar"); - break; - case 3: - mon = strdup("apr"); - break; - case 4: - mon = strdup("may"); - break; - case 5: - mon = strdup("jun"); - break; - case 6: - mon = strdup("jul"); - break; - case 7: - mon = strdup("aug"); - break; - case 8: - mon = strdup("sep"); - break; - case 9: - mon = strdup("oct"); - break; - case 10: - mon = strdup("nov"); - break; - case 11: - mon = strdup("dec"); - break; - } - return mon; + emcore_make_date_string_for_search(RawTime, since_date_string); + + memset(tag, 0x00, sizeof(tag)); + memset(command, 0x00, sizeof(command)); + + SNPRINTF(tag, sizeof(tag), "%08lx", 0xffffffff & (stream->gensym++)); + if (EM_SAFE_STRLEN(before_date_string) > 0) + SNPRINTF(command, sizeof(command), "%s UID SEARCH 1:* SINCE %s BEFORE %s\015\012", tag, since_date_string, before_date_string); + else + SNPRINTF(command, sizeof(command), "%s UID SEARCH 1:* SINCE %s\015\012", tag, since_date_string); + 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)EM_SAFE_STRLEN(command))) { + EM_DEBUG_EXCEPTION(" net_sout failed..."); + err = EMAIL_ERROR_CONNECTION_BROKEN; + goto FINISH_OFF; + } + + while (imaplocal->netstream) { + char *p = NULL; + /* receive response */ + if (!(response = net_getline(imaplocal->netstream))) { + EM_DEBUG_EXCEPTION(" net_getline failed..."); + err = EMAIL_ERROR_INVALID_RESPONSE; + goto FINISH_OFF; + } +#ifdef FEATURE_CORE_DEBUG + EM_DEBUG_LOG(" [IMAP4] <<< [%s]", response); +#endif + + if (!strncmp(response, tag, EM_SAFE_STRLEN(tag))) { + if (!strncmp(response + EM_SAFE_STRLEN(tag) + 1, "OK", 2)) { + EM_SAFE_FREE (response); + break; + } + else { /* 'NO' or 'BAD' */ + err = EMAIL_ERROR_IMAP4_FETCH_UID_FAILURE; /* EMAIL_ERROR_INVALID_RESPONSE; */ + goto FINISH_OFF; + } + } + + if ((p = strstr(response, " SEARCH "))) { + *p = '\0'; p += strlen(" SEARCH "); + + result = strtok(p, delims); + + while (result != NULL) + { + EM_DEBUG_LOG("UID VALUE DEEP is [%s]", result); + + if (!(uid_elem = em_malloc(sizeof(emcore_uid_list)))) { + EM_DEBUG_EXCEPTION(" malloc failed..."); + err = EMAIL_ERROR_OUT_OF_MEMORY; + goto FINISH_OFF; + } + + uid_elem->uid = EM_SAFE_STRDUP(result); + + if (uid_list_for_listing != NULL) + uid_elem->next = uid_list_for_listing; + uid_list_for_listing = uid_elem; + result = strtok(NULL, delims); + uid_count++; + } + + EM_SAFE_FREE(response); + continue; + } + else if ((p = strstr(response, " SEARCH"))){ + /* there is no mail */ + continue; + } + else { + err = EMAIL_ERROR_INVALID_RESPONSE; + goto FINISH_OFF; + } + } + + EM_SAFE_STRCPY(before_date_string, since_date_string); + EM_DEBUG_LOG("uid_count [%d] ", uid_count); + } + + EM_DEBUG_LOG("uid_count [%d] ", uid_count); + + if ((err = emcore_make_uid_range_string(uid_list_for_listing, uid_count, &uid_range_string)) != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emcore_make_uid_range_string failed [%d]", err); + goto FINISH_OFF; + } + + EM_DEBUG_LOG("uid_range_string [%s] ", uid_range_string); + + /* Get uids with flags */ + if(!imap4_mailbox_get_uids(stream, uid_range_string, output_uid_list, &err)) { + EM_DEBUG_EXCEPTION("imap4_mailbox_get_uids failed [%d]", err); + goto FINISH_OFF; + } + +FINISH_OFF: + + if (uid_list_for_listing) + emcore_free_uids(uid_list_for_listing, NULL); + + EM_SAFE_FREE (response); + EM_SAFE_FREE (uid_range_string); + + EM_PROFILE_END(emcore_get_uids_order_by_datetime_from_imap_server); + EM_DEBUG_FUNC_END("err [%d]", err); + return err; } + int imap4_mailbox_get_uids_by_timestamp(MAILSTREAM *stream, emcore_uid_list** uid_list, int *err_code) { EM_PROFILE_BEGIN(emCoreMailboxuidsbystamp); @@ -706,7 +862,7 @@ static int emcore_parse_header(char *rfc822_header, char **subject, char **from, int len, i, j; int subject_flag = 0; - EM_DEBUG_LOG("Buffer length [%d]", PARSE_BUFFER_LENGTH); + *priority = 3; @@ -726,7 +882,7 @@ static int emcore_parse_header(char *rfc822_header, char **subject, char **from, EM_DEBUG_LOG_DEV("buf:%s", buf); /* disposition_notification_to */ - if (buf[0] == 'D' && buf[11] == '-' && buf[12] == 'N' && buf[24] == '-' && buf[25] == 'T') { + if ((buf[0] == 'D' || buf[0] == 'd') && buf[11] == '-' && (buf[12] == 'N' || buf[12] == 'n') && buf[24] == '-' && (buf[25] == 'T' || buf[25] == 't')) { em_upper_string(buf); if (req_read_receipt) *req_read_receipt = 1; @@ -735,7 +891,7 @@ static int emcore_parse_header(char *rfc822_header, char **subject, char **from, } /* x-priority */ - if (buf[0] == 'X' && buf[2] == 'P' && buf[9] == 'Y'){ + if ((buf[0] == 'X' || buf[0] == 'x') && (buf[2] == 'P' || buf[2] == 'p') && (buf[9] == 'Y' || buf[9] == 'y')) { em_upper_string(buf); size_t len_2 = EM_SAFE_STRLEN(buf); if (len_2 >= 12){ @@ -747,25 +903,36 @@ static int emcore_parse_header(char *rfc822_header, char **subject, char **from, } /* x-msmail-priority */ - if (buf[0] == 'X' && buf[2] == 'M' && buf[9] == 'P' && buf[16] == 'Y'){ + if ((buf[0] == 'X' || buf[0] == 'x') && (buf[2] == 'M' || buf[2] == 'm') && (buf[9] == 'P' || buf[9] == 'p') && (buf[16] == 'Y' || buf[16] == 'y')) { em_upper_string(buf); - if (strstr(buf, "HIGH")) + if (strcasestr(buf, "HIGH")) *priority = 1; - if (strstr(buf, "NORMAL")) + if (strcasestr(buf, "NORMAL")) *priority = 3; - if (strstr(buf, "LOW")) + if (strcasestr(buf, "LOW")) *priority = 5; memset(buf, 0x00, PARSE_BUFFER_LENGTH); continue; } + /* Importance */ + if ((buf[0] == 'I' || buf[0] == 'i') && (buf[2] == 'P' || buf[2] == 'p') && (buf[6] == 'A' || buf[6] == 'a')) { + em_upper_string(buf); + if (strcasestr(buf, "HIGH")) + *priority = 1; + if (strcasestr(buf, "NORMAL")) + *priority = 3; + if (strcasestr(buf, "LOW")) + *priority = 5; + } + /* subject */ if (subject) { if (buf[0] != ' ' && buf[0] != '\t') { subject_flag = 0; } - if (buf[0] == 'S' && buf[1] == 'u' && buf[2] == 'b') { + if ((buf[0] == 'S' || buf[0] == 's') && (buf[1] == 'u' || buf[1] == 'U') && (buf[2] == 'b' || buf[2] == 'B')) { char *deli = NULL; char *r = NULL; @@ -774,6 +941,7 @@ static int emcore_parse_header(char *rfc822_header, char **subject, char **from, if (r) *r = '\0'; if (deli) { + if (*subject) EM_SAFE_FREE(*subject); *subject = g_strdup(deli+1); EM_DEBUG_LOG_DEV("subject:%s", *subject); } @@ -802,7 +970,7 @@ static int emcore_parse_header(char *rfc822_header, char **subject, char **from, /* From */ if (from) { - if (buf[0] == 'F' && buf[1] == 'r' && buf[2] == 'o') { + if ((buf[0] == 'F' || buf[0] == 'f') && (buf[1] == 'r' || buf[1] == 'R') && (buf[2] == 'o' || buf[2] == 'O')) { char *deli = NULL; char *r = NULL; @@ -811,6 +979,7 @@ static int emcore_parse_header(char *rfc822_header, char **subject, char **from, if (r) *r = '\0'; if (deli) { + if (*from) EM_SAFE_FREE(*from); *from = g_strdup(deli+1); EM_DEBUG_LOG_DEV("from:%s", *from); } @@ -850,7 +1019,7 @@ static int emcore_get_mail_extra_info(MAILSTREAM *stream, int msgno, char **subj #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{ @@ -891,6 +1060,95 @@ FINISH_OFF: #define EMAIL_SYNC_STATUS_SEEN_FLAG_CHANGED 2 #define EMAIL_SYNC_STATUS_FLAG_CHANGED 3 +static GDateTime *emcore_convert_strftime(char *time_str) +{ + GDateTime *datetime = NULL; + gchar **token_list = NULL; + int i = 0; + int index = 0; + int day = 0; + int month = 0; + int year = 0; + int hh = 0; + int mm = 0; + int ss = 0; + char *month_str = NULL; + char *ar_month[13] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", NULL}; + + token_list = g_strsplit_set(time_str, "-: ", -1); + + if(token_list == NULL) { + EM_DEBUG_LOG("g_strsplit_set failed."); + return NULL; + } + + while (token_list[index] != NULL) { + index++; + } + + for (i = 0; i < index; i++) { + switch (i) { + case 0: //Day + day = atoi(token_list[i]); + break; + case 1: //Month + month_str = g_strdup(token_list[i]); + break; + case 2: //Year + year = atoi(token_list[i]); + break; + case 3: //HH + hh = atoi(token_list[i]); + break; + case 4: //MM + mm = atoi(token_list[i]); + break; + case 5: //SS + ss = atoi(token_list[i]); + break; + } + } + + if (month_str) { + i = 0; + while (ar_month[i]) { + if (g_ascii_strcasecmp(month_str, ar_month[i]) == 0) { + month = i+1; + break; + } + i++; + } + } + + EM_DEBUG_LOG_DEV("%d/%d/%d %d:%d:%d", day, month, year, hh, mm, ss); + + datetime = g_date_time_new_utc(year, month, day, hh, mm, ss); + + g_strfreev(token_list); + g_free(month_str); + + return datetime; +} + +static gint emcore_compare_uid_elem(gconstpointer a, gconstpointer b) +{ + emcore_uid_list *item_a = NULL; + emcore_uid_list *item_b = NULL; + GDateTime *datetime_a = NULL; + GDateTime *datetime_b = NULL; + int ret = 0; + + item_a = (emcore_uid_list *)a; + item_b = (emcore_uid_list *)b; + + datetime_a = emcore_convert_strftime(item_a->internaldate); + datetime_b = emcore_convert_strftime(item_b->internaldate); + + ret = g_date_time_compare(datetime_b, datetime_a); + + return ret; +} + static int emcore_get_uids_to_download(MAILSTREAM *stream, email_account_t *account, emstorage_mailbox_tbl_t *input_mailbox_tbl, int limit_count, emcore_uid_list** uid_list, int *uids, int retrieve_mode , int *err_code) { EM_PROFILE_BEGIN(emCoreGetUidsDownload); @@ -906,6 +1164,11 @@ static int emcore_get_uids_to_download(MAILSTREAM *stream, email_account_t *acco emcore_uid_list *next_uid_elem = NULL; emstorage_mail_tbl_t *mail = NULL; + emcore_uid_list *elem_item = NULL; + GList *item_list = NULL; + GList *item_iter = NULL; + GList *item_next = 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 = EMAIL_ERROR_INVALID_PARAM; @@ -921,13 +1184,20 @@ static int emcore_get_uids_to_download(MAILSTREAM *stream, email_account_t *acco } } else { /* EMAIL_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 != EMAIL_ERROR_MAIL_NOT_FOUND_ON_SERVER) - goto FINISH_OFF; + EM_DEBUG_LOG("nmsgs[%d]", ((MAILSTREAM *)stream)->nmsgs); + if ((limit_count < ((MAILSTREAM *)stream)->nmsgs)) { + if ((err = emcore_get_uids_order_by_datetime_from_imap_server(stream, limit_count, uid_list)) != EMAIL_ERROR_NONE ) { + EM_DEBUG_EXCEPTION("emcore_get_uids_order_by_datetime_from_imap_server failed [%d]", err); + if (err != EMAIL_ERROR_MAIL_NOT_FOUND_ON_SERVER) + goto FINISH_OFF; + } + } + else { + if(!imap4_mailbox_get_uids(stream, NULL, uid_list, &err)) { + EM_DEBUG_EXCEPTION("imap4_mailbox_get_uids failed [%d]", err); + if (err != EMAIL_ERROR_MAIL_NOT_FOUND_ON_SERVER) + goto FINISH_OFF; + } } } @@ -950,36 +1220,72 @@ static int emcore_get_uids_to_download(MAILSTREAM *stream, email_account_t *acco EM_PROFILE_BEGIN(emCoreGetUidsDownloadWhilwLoop); + /* Sort uid_elem list based on datetime */ + elem_item = uid_elem; + + while (elem_item) { + item_list = g_list_append(item_list, elem_item); + elem_item = elem_item->next; + } + + if (item_list) { + item_list = g_list_sort(item_list, emcore_compare_uid_elem); + item_iter = g_list_first(item_list); + + while (item_iter) { + item_next = g_list_next(item_iter); + if (item_next) { + elem_item = item_iter->data; + elem_item->next = (emcore_uid_list *)item_next->data; + } else { + elem_item = item_iter->data; + elem_item->next = NULL; + } + + item_iter = g_list_next(item_iter); + } + + g_list_free(item_list); + } + /* Sorting completed */ + while (uid_elem) { next_uid_elem = uid_elem->next; - if ((account->retrieval_mode == EMAIL_IMAP4_RETRIEVAL_MODE_NEW) && (uid_elem->flag.seen != 0)) { /* already seen */ + if ((account->retrieval_mode & EMAIL_IMAP4_RETRIEVAL_MODE_NEW) && (uid_elem->flag.seen != 0)) { /* already seen */ EM_SAFE_FREE (uid_elem->uid); + EM_SAFE_FREE (uid_elem->internaldate); EM_SAFE_FREE (uid_elem); } 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); */ + /* EM_DEBUG_LOG("hit the limit[%d] for [%s]", limit_count, uid_elem->uid); */ to_be_downloaded = 0; } else{ for (i = downloaded_uid_count; i > 0; i--) { - if (downloaded_uids[i - 1].sync_status == EMAIL_SYNC_STATUS_NOT_EXIST_ON_SERVER && !EM_SAFE_STRCMP(uid_elem->uid, downloaded_uids[i - 1].server_uid)) { - /* The mail exists on server and local storage, so it should not be downloaded, just check seen flag */ - if(downloaded_uids[i - 1].flags_seen_field != uid_elem->flag.seen || - downloaded_uids[i - 1].flags_flagged_field != uid_elem->flag.flagged) { - if(downloaded_uids[i - 1].flags_seen_field != uid_elem->flag.seen) { - downloaded_uids[i - 1].sync_status = EMAIL_SYNC_STATUS_FLAG_CHANGED; - downloaded_uids[i - 1].flags_seen_field = uid_elem->flag.seen; - } - if (downloaded_uids[i - 1].flags_flagged_field != uid_elem->flag.flagged) { - downloaded_uids[i - 1].sync_status = EMAIL_SYNC_STATUS_FLAG_CHANGED; - downloaded_uids[i - 1].flags_flagged_field = uid_elem->flag.flagged; + if (downloaded_uids[i - 1].sync_status == EMAIL_SYNC_STATUS_NOT_EXIST_ON_SERVER + && !EM_SAFE_STRCMP(uid_elem->uid, downloaded_uids[i - 1].server_uid)) { + if (downloaded_uids[i - 1].mailbox_id != input_mailbox_tbl->mailbox_id) { + uid_count--; + } + else { + /* The mail exists on server and local storage, so it should not be downloaded, just check seen flag */ + if(downloaded_uids[i - 1].flags_seen_field != uid_elem->flag.seen || + downloaded_uids[i - 1].flags_flagged_field != uid_elem->flag.flagged) { + if(downloaded_uids[i - 1].flags_seen_field != uid_elem->flag.seen) { + downloaded_uids[i - 1].sync_status = EMAIL_SYNC_STATUS_FLAG_CHANGED; + downloaded_uids[i - 1].flags_seen_field = uid_elem->flag.seen; + } + if (downloaded_uids[i - 1].flags_flagged_field != uid_elem->flag.flagged) { + downloaded_uids[i - 1].sync_status = EMAIL_SYNC_STATUS_FLAG_CHANGED; + downloaded_uids[i - 1].flags_flagged_field = uid_elem->flag.flagged; + } + } else { + downloaded_uids[i - 1].sync_status = EMAIL_SYNC_STATUS_EXIST_ON_SERVER; } - } else { - downloaded_uids[i - 1].sync_status = EMAIL_SYNC_STATUS_EXIST_ON_SERVER; } to_be_downloaded = 0; break; @@ -987,7 +1293,7 @@ static int emcore_get_uids_to_download(MAILSTREAM *stream, email_account_t *acco } } - /* EM_DEBUG_LOG("Is uid[%s] going to be downloded ? [%d]", uid_elem->uid, to_be_downloaded); */ + //EM_DEBUG_LOG("Is uid[%s] datetime[%s] going to be downloaded ? [%d]", uid_elem->uid, uid_elem->internaldate, to_be_downloaded); if (to_be_downloaded) { if (retrieve_mode == EMAIL_SYNC_OLDEST_MAILS_FIRST){ @@ -1025,7 +1331,8 @@ static int emcore_get_uids_to_download(MAILSTREAM *stream, email_account_t *acco for (i = 0; i < downloaded_uid_count; i++) { /* EM_DEBUG_LOG("input_mailbox_tbl[%s] sync_status[%d]", input_mailbox_tbl->name, downloaded_uids[i].sync_status); */ - if (downloaded_uids[i].sync_status == EMAIL_SYNC_STATUS_NOT_EXIST_ON_SERVER) { /* deleted on server */ + if ((downloaded_uids[i].sync_status == EMAIL_SYNC_STATUS_NOT_EXIST_ON_SERVER) && + (EM_SAFE_STRCMP(downloaded_uids[i].mailbox_name, EMAIL_SEARCH_RESULT_MAILBOX_NAME) != 0)) { /* deleted on server */ if (!emstorage_get_maildata_by_servermailid(input_mailbox_tbl->mailbox_id, downloaded_uids[i].server_uid, &mail, true, &err)){ EM_DEBUG_EXCEPTION("emstorage_get_maildata_by_servermailid for uid[%s] Failed [%d] \n ", downloaded_uids[i].server_uid, err); if (err == EMAIL_ERROR_MAIL_NOT_FOUND){ @@ -1034,12 +1341,13 @@ static int emcore_get_uids_to_download(MAILSTREAM *stream, email_account_t *acco } if (account->incoming_server_type == EMAIL_SERVER_TYPE_IMAP4) { - if (!emcore_delete_mails_from_local_storage(input_mailbox_tbl->account_id, &(mail->mail_id), 1, EMAIL_DELETED_FROM_SERVER, false, &err)) { + ret = emcore_delete_mails_from_local_storage(input_mailbox_tbl->account_id, &(mail->mail_id), 1, EMAIL_DELETED_FROM_SERVER, false, &err); + /* Update badge count */ + emcore_display_unread_in_badge(NULL); + if (!ret) { EM_DEBUG_EXCEPTION("emcore_delete_mails_from_local_storage falied - %d", err); goto FINISH_OFF; } - /* emcore_delete_notification_for_read_mail(mail->mail_id); */ - emcore_display_unread_in_badge(); } if (!emstorage_remove_downloaded_mail(input_mailbox_tbl->account_id, input_mailbox_tbl->mailbox_name, downloaded_uids[i].server_uid, true, &err)) { /* remove uid from uid list */ @@ -1059,7 +1367,7 @@ static int emcore_get_uids_to_download(MAILSTREAM *stream, email_account_t *acco EM_DEBUG_EXCEPTION("emcore_set_flags_field failed [%d]", err); } else - emcore_display_unread_in_badge(); + emcore_display_unread_in_badge(NULL); } @@ -1127,7 +1435,7 @@ static int emcore_add_read_mail_uid(emstorage_mailbox_tbl_t *input_maibox_data, read_mail_uid.mailbox_id = mailbox_tbl->mailbox_id; 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; @@ -1224,10 +1532,11 @@ INTERNAL_FUNC int emcore_add_mail_to_mailbox(emstorage_mailbox_tbl_t *input_maib /* Get the Mail_id */ if (!emstorage_increase_mail_id(&(input_new_mail_tbl_data->mail_id), false, &err)) { EM_DEBUG_EXCEPTION("emstorage_increase_mail_id failed [%d]", err); + emstorage_rollback_transaction(NULL, NULL, NULL); goto FINISH_OFF; } - if (emstorage_get_thread_id_of_thread_mails(input_new_mail_tbl_data, &thread_id, &latest_mail_id_in_thread, &thread_item_count) != EMAIL_ERROR_NONE) + if (emstorage_get_thread_id_of_thread_mails(input_new_mail_tbl_data, &thread_id, &latest_mail_id_in_thread, &thread_item_count) != EMAIL_ERROR_NONE) EM_DEBUG_LOG(" emstorage_get_thread_id_of_thread_mails is failed."); if (thread_id == -1){ @@ -1245,21 +1554,30 @@ INTERNAL_FUNC int emcore_add_mail_to_mailbox(emstorage_mailbox_tbl_t *input_maib goto FINISH_OFF; } - if (thread_item_count > 1){ - if (!emstorage_update_latest_thread_mail(input_new_mail_tbl_data->account_id, input_new_mail_tbl_data->thread_id, 0, 0, false, &err)) { + if (thread_item_count > 1) { + if (!emstorage_update_latest_thread_mail(input_new_mail_tbl_data->account_id, input_new_mail_tbl_data->mailbox_id, input_new_mail_tbl_data->thread_id, NULL, -1, -1, NOTI_THREAD_ID_CHANGED_BY_ADD, false, &err)) { + EM_DEBUG_EXCEPTION("emstorage_update_latest_thread_mail failed [%d]", err); + emstorage_rollback_transaction(NULL, NULL, NULL); + goto FINISH_OFF; + } + + if (!emstorage_update_latest_thread_mail(input_new_mail_tbl_data->account_id, input_new_mail_tbl_data->mailbox_id, input_new_mail_tbl_data->thread_id, NULL, 0, 0, NOTI_THREAD_ID_CHANGED_BY_ADD, false, &err)) { EM_DEBUG_EXCEPTION("emstorage_update_latest_thread_mail failed [%d]", err); emstorage_rollback_transaction(NULL, NULL, NULL); goto FINISH_OFF; } } + + if (emstorage_get_thread_id_of_thread_mails(input_new_mail_tbl_data, &thread_id, &latest_mail_id_in_thread, &thread_item_count) != EMAIL_ERROR_NONE) + EM_DEBUG_LOG(" emstorage_get_thread_id_of_thread_mails is failed."); + if (output_thread_id) - *output_thread_id = input_new_mail_tbl_data->thread_id; + *output_thread_id = thread_id; if (output_mail_id != NULL) *output_mail_id = input_new_mail_tbl_data->mail_id; - EM_DEBUG_LOG("mail_table_data.mail_id [%d]", input_new_mail_tbl_data->mail_id); - EM_DEBUG_LOG("mail_table_data.thread_id [%d]", input_new_mail_tbl_data->thread_id); + if (!emcore_add_read_mail_uid(input_maibox_data, input_maibox_data->mailbox_name, input_new_mail_tbl_data->mail_id, input_new_mail_tbl_data->server_mail_id, input_new_mail_tbl_data->mail_size, 0, &err)) { EM_DEBUG_EXCEPTION("emcore_add_read_mail_uid failed [%d]", err); @@ -1349,7 +1667,7 @@ int emcore_check_rule(const char *input_full_address_from, const char *input_sub else if (RULE_TYPE_EXACTLY == rule[i].flag2) { if (!strcasecmp(input_subject, rule[i].value)) *blocked = true; - } + } } } @@ -1363,9 +1681,17 @@ int emcore_check_rule(const char *input_full_address_from, const char *input_sub if (!strcasecmp(from_address, rule[i].value2)) *blocked = true; } +#ifdef __FEATURE_COMPARE_DOMAIN__ + else if (RULE_TYPE_COMPARE_DOMAIN == rule[i].flag2) { + char *domain_start = NULL; + domain_start = strchr(from_address, '@'); + if (domain_start && strncmp(domain_start, rule[i].value2, strlen(rule[i].value2)) == 0) + *blocked = true; + } +#endif /* __FEATURE_COMPARE_DOMAIN__ */ } } - + break; default: @@ -1376,11 +1702,11 @@ int emcore_check_rule(const char *input_full_address_from, const char *input_sub if (RULE_TYPE_INCLUDES == rule[i].flag2) { if (strcasestr(from_address, rule[i].value2)) *priority_sender = 1; - } + } else if (RULE_TYPE_EXACTLY == rule[i].flag2) { - if (!strcasecmp(from_address, rule[i].value2)) + if (!strcasecmp(from_address, rule[i].value2)) *priority_sender = 1; - } + } } break; } @@ -1467,7 +1793,7 @@ INTERNAL_FUNC int emcore_make_mail_tbl_data_from_envelope(int account_id, MAILST if (rfc822_subject) { EM_SAFE_FREE(input_envelope->subject); input_envelope->subject = g_strdup(rfc822_subject); - EM_DEBUG_LOG("rfc822_subject:%s", input_envelope->subject); + EM_DEBUG_LOG_SEC("rfc822_subject:%s", input_envelope->subject); EM_SAFE_FREE(rfc822_subject); } @@ -1475,14 +1801,31 @@ INTERNAL_FUNC int emcore_make_mail_tbl_data_from_envelope(int account_id, MAILST if (input_envelope->from) { EM_SAFE_FREE(input_envelope->from->personal); input_envelope->from->personal = g_strdup(rfc822_from); - EM_DEBUG_LOG("rfc822_from:%s", input_envelope->from->personal); + EM_DEBUG_LOG_SEC("rfc822_from:%s", input_envelope->from->personal); } EM_SAFE_FREE(rfc822_from); } if (input_envelope->subject) { temp_mail_tbl_data->subject = emcore_decode_rfc2047_text(input_envelope->subject, &err); - EM_DEBUG_LOG("subject[%s]", temp_mail_tbl_data->subject); + em_trim_left(temp_mail_tbl_data->subject); + + char *charset = NULL; + char *charset_end = NULL; + char *charset_start = NULL; + if(g_str_has_prefix(input_envelope->subject, "=?")) { + charset_start = input_envelope->subject + 2; + charset_end = strstr(charset_start, "?"); + if (charset_end) { + charset = g_strndup(charset_start, charset_end - charset_start); + } + } + + EM_DEBUG_LOG("DEFAULT CHARSET : %s", charset); + if (charset) { + temp_mail_tbl_data->default_charset = g_ascii_strup(charset, -1); + EM_SAFE_FREE(charset); + } } if (input_envelope->from) { @@ -1491,7 +1834,7 @@ INTERNAL_FUNC int emcore_make_mail_tbl_data_from_envelope(int account_id, MAILST goto FINISH_OFF; } - EM_DEBUG_LOG_SEC("full_address_from[%s]", temp_mail_tbl_data->full_address_from); + } if (input_envelope->to) { @@ -1500,7 +1843,7 @@ INTERNAL_FUNC int emcore_make_mail_tbl_data_from_envelope(int account_id, MAILST goto FINISH_OFF; } - EM_DEBUG_LOG_SEC("full_address_to[%s]", temp_mail_tbl_data->full_address_to); + } if (input_envelope->cc) { @@ -1542,7 +1885,7 @@ INTERNAL_FUNC int emcore_make_mail_tbl_data_from_envelope(int account_id, MAILST memset((void*)&temp_time_info, 0, sizeof(struct tm)); - EM_DEBUG_LOG("tm_hour[%d] zhours [%d] tm_min[%d] zminutes[%d] zoocident[%d]", mail_cache_element->hours, mail_cache_element->zhours, mail_cache_element->minutes, mail_cache_element->zminutes, mail_cache_element->zoccident); + zone_hour = mail_cache_element->zhours * (mail_cache_element->zoccident?-1:1); @@ -1588,8 +1931,12 @@ INTERNAL_FUNC int emcore_make_mail_tbl_data_from_envelope(int account_id, MAILST FINISH_OFF: - if (ret != true) - EM_SAFE_FREE(temp_mail_tbl_data); + if (ret != true) { + if (temp_mail_tbl_data) { + emstorage_free_mail(&temp_mail_tbl_data, 1, NULL); + temp_mail_tbl_data = NULL; + } + } if (account_ref) { emcore_free_account(account_ref); @@ -1604,8 +1951,18 @@ FINISH_OFF: return ret; } -INTERNAL_FUNC int emcore_sync_header (emstorage_mailbox_tbl_t *input_mailbox_tbl, void **stream, - emcore_uid_list **input_uid_list, int *mail_count, int *unread_mail, int *err_code) + + +INTERNAL_FUNC int emcore_sync_header (emstorage_mailbox_tbl_t *input_mailbox_tbl, + void **stream, + emcore_uid_list **input_uid_list, + int *mail_count, + int *unread_mail, + int *vip_mail_count, + int *vip_unread_mail, + int cancellable, /*0: excluding event thd*/ + int event_handle, + int *err_code) { EM_PROFILE_BEGIN(emCoreSyncHeader); EM_DEBUG_FUNC_BEGIN("input_mailbox_tbl[%p], input_uid_list [%p], err_code[%p]", input_mailbox_tbl, input_uid_list, err_code); @@ -1619,7 +1976,6 @@ INTERNAL_FUNC int emcore_sync_header (emstorage_mailbox_tbl_t *input_mailbox_tbl int ret = false; int err = EMAIL_ERROR_NONE, err_2 = EMAIL_ERROR_NONE; int err_from_vconf = 0; - int status = EMAIL_LIST_FAIL; int download_limit_count; email_account_t *account_ref = NULL; emstorage_rule_tbl_t *rule = NULL; @@ -1629,7 +1985,8 @@ INTERNAL_FUNC int emcore_sync_header (emstorage_mailbox_tbl_t *input_mailbox_tbl emstorage_mailbox_tbl_t *destination_mailbox = NULL; ENVELOPE *env = NULL; - int account_id = 0, mail_id = 0, rule_count = 1000, total = 0, unread = 0, i = 0, percentage = 0, thread_id = -1; + int account_id = 0, mail_id = 0, rule_count = 1000, i = 0, percentage = 0, thread_id = -1; + int total = 0, unread = 0, vip_total = 0, vip_unread = 0; char *uid_range = NULL; char mailbox_id_param_string[10] = {0,}; @@ -1648,28 +2005,45 @@ INTERNAL_FUNC int emcore_sync_header (emstorage_mailbox_tbl_t *input_mailbox_tbl goto FINISH_OFF; } - if(account_ref->incoming_server_type == EMAIL_SERVER_TYPE_IMAP4 && input_mailbox_tbl->local_yn == 1) { - EM_DEBUG_EXCEPTION("local_yn flag is false for this mailbox"); - err = EMAIL_ERROR_INVALID_MAILBOX; + if (account_ref->sync_disabled == 1) { + err = EMAIL_ERROR_ACCOUNT_SYNC_IS_DISALBED; + EM_DEBUG_LOG("Sync disabled for this account. Do not sync."); goto FINISH_OFF; } - FINISH_OFF_IF_CANCELED; + + if(account_ref->incoming_server_type == EMAIL_SERVER_TYPE_IMAP4 && input_mailbox_tbl->local_yn == 1) { + /* mailbox recovery starts */ + if (input_mailbox_tbl->mailbox_type == EMAIL_MAILBOX_TYPE_INBOX) { + emcore_sync_mailbox_list (account_id, "", event_handle, &err); + if (err != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emcore_sync_mailbox_list error [%d] account_id [%d]", err, account_id); + } + } + else { + EM_DEBUG_EXCEPTION ("because mailbox_name[%s] mailbox_type[%d] of account[%d] is a local box, it cant be synced", + input_mailbox_tbl->mailbox_name, input_mailbox_tbl->mailbox_type, account_id ); + err = EMAIL_ERROR_INVALID_MAILBOX; + goto FINISH_OFF; + } + } + + if (cancellable) + FINISH_OFF_IF_EVENT_CANCELED(err, event_handle); #ifdef __FEATURE_SUPPORT_SYNC_STATE_ON_NOTI_BAR__ if ((err_from_vconf = vconf_set_int(VCONFKEY_EMAIL_SYNC_STATE, 1)) != 0 ) { - EM_DEBUG_LOG("vconf_set_int failed [%d]", err_from_vconf); + EM_DEBUG_EXCEPTION("vconf_set_int failed (sync state) [%d]", err_from_vconf); } #endif /* __FEATURE_SUPPORT_SYNC_STATE_ON_NOTI_BAR__ */ - if (!emcore_connect_to_remote_mailbox(account_id, input_mailbox_tbl->mailbox_id, (void **)stream, &err) || !*stream){ + if (!emcore_connect_to_remote_mailbox(account_id, input_mailbox_tbl->mailbox_id, (void **)stream, &err) || !*stream) { EM_DEBUG_EXCEPTION("emcore_connect_to_remote_mailbox failed - %d", err); - status = EMAIL_LIST_CONNECTION_FAIL; - err = EMAIL_ERROR_CONNECTION_FAILURE; goto FINISH_OFF; } - FINISH_OFF_IF_CANCELED; + if (cancellable) + FINISH_OFF_IF_EVENT_CANCELED(err, event_handle); /* save total mail count on server to DB */ if (!emstorage_update_mailbox_total_count(account_id, input_mailbox_tbl->mailbox_id, ((MAILSTREAM *)*stream)->nmsgs, 1, &err)){ @@ -1681,7 +2055,7 @@ INTERNAL_FUNC int emcore_sync_header (emstorage_mailbox_tbl_t *input_mailbox_tbl /* if (((MAILSTREAM *)stream)->nmsgs > 0) */ { email_option_t *opt_ref = &account_ref->options; - EM_DEBUG_LOG("block_address = %d, block_subject = %d", opt_ref->block_address, opt_ref->block_subject); + EM_DEBUG_LOG_SEC("block_address = %d, block_subject = %d", opt_ref->block_address, opt_ref->block_subject); if (opt_ref->block_address || opt_ref->block_subject) { int is_completed = false; @@ -1697,15 +2071,17 @@ INTERNAL_FUNC int emcore_sync_header (emstorage_mailbox_tbl_t *input_mailbox_tbl EM_DEBUG_EXCEPTION ("emstorage_get_rule error [%d]", err); } } + download_limit_count = input_mailbox_tbl->mail_slot_size; - if (!emcore_get_uids_to_download(*stream, account_ref, input_mailbox_tbl, download_limit_count, &uid_list, + + if (!emcore_get_uids_to_download(*stream, account_ref, input_mailbox_tbl, download_limit_count, &uid_list, &total, EMAIL_SYNC_LATEST_MAILS_FIRST, &err)){ EM_DEBUG_EXCEPTION("emcore_get_uids_to_download failed [%d]", err); - uid_list = NULL; goto FINISH_OFF; } - FINISH_OFF_IF_CANCELED; + if (cancellable) + FINISH_OFF_IF_EVENT_CANCELED(err, event_handle); if (input_uid_list && *input_uid_list){ emcore_free_uids(*input_uid_list, NULL); @@ -1716,76 +2092,20 @@ INTERNAL_FUNC int emcore_sync_header (emstorage_mailbox_tbl_t *input_mailbox_tbl EM_PROFILE_BEGIN(emCoreSyncHeaderwhileloop); #ifdef __FEATURE_HEADER_OPTIMIZATION__ - /* g.shyamakshi@samsung.com : Bulk fetch of headers only if the recieving server type is IMAP */ + /* g.shyamakshi@samsung.com : Bulk fetch of headers only if the receiving server type is IMAP */ EM_DEBUG_LOG("((MAILSTREAM *)stream)->nmsgs [%d]", ((MAILSTREAM *)*stream)->nmsgs); EM_DEBUG_LOG("uid_list [%p]", uid_list); - if (account_ref->incoming_server_type == EMAIL_SERVER_TYPE_IMAP4 && uid_list != NULL){ - emcore_uid_list *uid_list_prev = NULL; - emcore_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 = EMAIL_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)); + if (account_ref->incoming_server_type == EMAIL_SERVER_TYPE_IMAP4 && uid_list != NULL) { - 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; - } - } + if ((err = emcore_make_uid_range_string(uid_list, total, &uid_range)) != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emcore_make_uid_range_string failed [%d]", err); + goto FINISH_OFF; } - FINISH_OFF_IF_CANCELED; - - EM_DEBUG_LOG("index [%d]", index); + if (cancellable) + FINISH_OFF_IF_EVENT_CANCELED(err, event_handle); uid_elem = uid_list; if (*stream && uid_elem){ @@ -1817,11 +2137,11 @@ INTERNAL_FUNC int emcore_sync_header (emstorage_mailbox_tbl_t *input_mailbox_tbl env = NULL; - if (uid_elem->msgno > ((MAILSTREAM *)*stream)->nmsgs) - EM_DEBUG_LOG ("WARN: msgno[%d] can't be greater than nmsgs[%d].", uid_elem->msgno, - ((MAILSTREAM *)*stream)->nmsgs); + if (uid_elem->msgno > ((MAILSTREAM *)*stream)->nmsgs) { + EM_DEBUG_LOG ("WARN: msgno[%d] can't be greater than nmsgs[%d].", + uid_elem->msgno, ((MAILSTREAM *)*stream)->nmsgs); + } else{ - #ifdef __FEATURE_HEADER_OPTIMIZATION__ if (account_ref->incoming_server_type == EMAIL_SERVER_TYPE_IMAP4) /* Fetch env from cache in case of IMAP */ env = mail_fetchstructure_full (*stream, uid_elem->msgno, NULL, FT_PEEK, 0); @@ -1831,14 +2151,16 @@ INTERNAL_FUNC int emcore_sync_header (emstorage_mailbox_tbl_t *input_mailbox_tbl env = mail_fetchstructure_full (*stream, uid_elem->msgno, NULL, FT_PEEK); #endif } - FINISH_OFF_IF_CANCELED; + + if (cancellable) + FINISH_OFF_IF_EVENT_CANCELED(err, event_handle); if (env != NULL) { int searched_mail_id = 0; int blocked = false; int priority_sender = false; - if (!emcore_make_mail_tbl_data_from_envelope (account_id, *stream, env, uid_elem, + if (!emcore_make_mail_tbl_data_from_envelope (account_id, *stream, env, uid_elem, &new_mail_tbl_data, &err) || !new_mail_tbl_data) { EM_DEBUG_EXCEPTION("emcore_make_mail_tbl_data_from_envelope failed [%d]", err); goto CONTINUE_NEXT; @@ -1862,84 +2184,106 @@ INTERNAL_FUNC int emcore_sync_header (emstorage_mailbox_tbl_t *input_mailbox_tbl if(destination_mailbox) /* cleanup before reusing */ emstorage_free_mailbox(&destination_mailbox, 1, NULL); - if (priority_sender) + if (priority_sender) { new_mail_tbl_data->tag_id = PRIORITY_SENDER_TAG_ID; + vip_total ++; + } - if (blocked) { - EM_DEBUG_LOG("mail[%d] added to spambox", mail_id); - if (!emstorage_get_mailbox_by_mailbox_type(account_id, EMAIL_MAILBOX_TYPE_SPAMBOX, - &destination_mailbox, false, &err)) { - EM_DEBUG_LOG("emstorage_get_mailbox_by_mailbox_type failed [%d]", err); + if (blocked && (input_mailbox_tbl->mailbox_type == EMAIL_MAILBOX_TYPE_INBOX)) { + if (input_mailbox_tbl->mailbox_type != EMAIL_MAILBOX_TYPE_SPAMBOX) { + EM_DEBUG_LOG("mail[%d] added to spambox", mail_id); + if (!emstorage_get_mailbox_by_mailbox_type(account_id, EMAIL_MAILBOX_TYPE_SPAMBOX, + &destination_mailbox, false, &err)) { + EM_DEBUG_LOG("emstorage_get_mailbox_by_mailbox_type failed [%d]", err); + } } + else + blocked = 0; } + /* Set the noti waited */ + new_mail_tbl_data->save_status = EMAIL_MAIL_STATUS_NOTI_WAITED; + if (destination_mailbox) { - if ((err = emcore_add_mail_to_mailbox(destination_mailbox, new_mail_tbl_data, &mail_id, - &thread_id)) != EMAIL_ERROR_NONE) { - EM_DEBUG_EXCEPTION("emcore_add_mail_to_mailbox falied [%d]", err); - goto CONTINUE_NEXT; + if (destination_mailbox->local_yn == 0 || account_ref->incoming_server_type == EMAIL_SERVER_TYPE_IMAP4) { + if ((err = emcore_move_mail_on_server_by_server_mail_id((void*)*stream, new_mail_tbl_data->server_mail_id, destination_mailbox->mailbox_name)) != EMAIL_ERROR_NONE){ + EM_DEBUG_EXCEPTION("emcore_move_mail_on_server_by_server_mail_id falied [%d]", err); + goto CONTINUE_NEXT; + } } - - if (account_ref->incoming_server_type == EMAIL_SERVER_TYPE_IMAP4) { - if (!emcore_move_mail_on_server(account_id, input_mailbox_tbl->mailbox_id, &mail_id, - 1, destination_mailbox->mailbox_name, &err)){ - EM_DEBUG_EXCEPTION("emcore_move_mail_on_server falied [%d]", err); + else { /* local mailbox */ + if ((err = emcore_add_mail_to_mailbox(destination_mailbox, new_mail_tbl_data, &mail_id, + &thread_id)) != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emcore_add_mail_to_mailbox failed [%d]", err); goto CONTINUE_NEXT; } + } + SNPRINTF(mailbox_id_param_string, 10, "%d", destination_mailbox->mailbox_id); } else { /* add mails to specified mail box */ EM_DEBUG_LOG_SEC("mail[%d] moved to input_mailbox_tbl [%s]", mail_id, input_mailbox_tbl->mailbox_name); - if ( (err = emcore_add_mail_to_mailbox (input_mailbox_tbl, new_mail_tbl_data, + if ( (err = emcore_add_mail_to_mailbox (input_mailbox_tbl, new_mail_tbl_data, &mail_id, &thread_id)) != EMAIL_ERROR_NONE) { EM_DEBUG_EXCEPTION("emcore_add_mail_to_mailbox falied [%d]", err); goto CONTINUE_NEXT; } - /*h.gahlaut : Start partial body dowload using partial body thread only for IMAP accounts*/ #ifndef __FEATURE_PARTIAL_BODY_FOR_POP3__ if (account_ref->incoming_server_type == EMAIL_SERVER_TYPE_IMAP4) { #endif /* __FEATURE_PARTIAL_BODY_FOR_POP3__ */ if (account_ref->auto_download_size != 0) { - if (false == emcore_initiate_pbd (*stream, account_id, mail_id, uid_elem->uid, + if (false == emcore_initiate_pbd (*stream, account_id, mail_id, uid_elem->uid, input_mailbox_tbl->mailbox_id, &err)) EM_DEBUG_LOG("Partial body download initiation failed [%d]", err); } #ifndef __FEATURE_PARTIAL_BODY_FOR_POP3__ } #endif /* __FEATURE_PARTIAL_BODY_FOR_POP3__ */ + +#ifdef __FEATURE_WIFI_AUTO_DOWNLOAD__ + if (input_mailbox_tbl->mailbox_type == EMAIL_MAILBOX_TYPE_INBOX) { + if (!emcore_insert_auto_download_job(account_id, input_mailbox_tbl->mailbox_id, + mail_id, /*account_ref->wifi_auto_download*/ 1, uid_elem->uid, &err)) + EM_DEBUG_LOG("emcore_insert_auto_download_job failed [%d]", err); + } +#endif /* if (!uid_elem->flag.seen && input_mailbox_tbl->mailbox_type != EMAIL_MAILBOX_TYPE_SPAMBOX) emcore_add_notification_for_unread_mail(new_mail_tbl_data); */ - FINISH_OFF_IF_CANCELED; + if (cancellable) + FINISH_OFF_IF_EVENT_CANCELED(err, event_handle); - if (!uid_elem->flag.seen) + if (!uid_elem->flag.seen) { unread++; + if (priority_sender) { + vip_unread++; + } + } percentage = ((i+1) * 100) / total ; - EM_DEBUG_LOG("Header Percentage Completed [%d] : [%d/%d] mail_id [%d]", percentage, i+1, + EM_DEBUG_LOG("Header Percentage Completed [%d] : [%d/%d] mail_id [%d]", percentage, i+1, total, mail_id); SNPRINTF(mailbox_id_param_string, 10, "%d", input_mailbox_tbl->mailbox_id); - - if (!emcore_notify_storage_event (NOTI_MAIL_ADD, account_id, mail_id, - mailbox_id_param_string, thread_id)) - EM_DEBUG_EXCEPTION ("emcore_notify_storage_event [NOTI_MAIL_ADD] failed"); } + if (!emcore_notify_storage_event (NOTI_MAIL_ADD, account_id, mail_id, mailbox_id_param_string, thread_id)) + EM_DEBUG_EXCEPTION ("emcore_notify_storage_event [NOTI_MAIL_ADD] failed"); + #ifdef __FEATURE_BLOCKING_MODE__ /* Check the blocking mode */ int blocking_mode = false; blocking_mode = emcore_get_blocking_mode_status(); if (!blocking_mode) { - if ((err = emcore_check_blocking_mode (new_mail_tbl_data->email_address_sender, + if ((err = emcore_check_blocking_mode (new_mail_tbl_data->email_address_sender, &blocking_mode)) != EMAIL_ERROR_NONE) { EM_DEBUG_EXCEPTION ("emcore_check_blocking_mode failed : [%d]", err); } if (blocking_mode) - emcore_set_blocking_mode_status (blocking_mode); + emcore_set_blocking_mode_status (blocking_mode); } #endif /* __FEATURE_BLOCKING_MODE__ */ @@ -1964,7 +2308,8 @@ INTERNAL_FUNC int emcore_sync_header (emstorage_mailbox_tbl_t *input_mailbox_tbl /* 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 */ - FINISH_OFF_IF_CANCELED; + if (cancellable) + FINISH_OFF_IF_EVENT_CANCELED(err, event_handle); } CONTINUE_NEXT: @@ -1988,6 +2333,12 @@ FINISH_OFF: if (unread_mail != NULL) *unread_mail = unread; + if (vip_mail_count != NULL) + *vip_mail_count = vip_total; + + if (vip_unread_mail != NULL) + *vip_unread_mail = vip_unread; + if (account_ref) { emcore_free_account(account_ref); EM_SAFE_FREE(account_ref); @@ -2001,7 +2352,7 @@ FINISH_OFF: #ifdef __FEATURE_SUPPORT_SYNC_STATE_ON_NOTI_BAR__ if ((err_from_vconf = vconf_set_int(VCONFKEY_EMAIL_SYNC_STATE, 0)) != 0 ) { - EM_DEBUG_LOG("vconf_set_int failed [%d]", err_from_vconf); + EM_DEBUG_EXCEPTION("vconf_set_int failed (sync state) [%d]", err_from_vconf); } #endif /* __FEATURE_SUPPORT_SYNC_STATE_ON_NOTI_BAR__ */ @@ -2145,7 +2496,7 @@ int emcore_download_uid_all(MAILSTREAM *mail_stream, email_internal_mailbox_t *m if (*p == '.') break; - /* EM_DEBUG_LOG("UID list [%s]", p); */ + /*EM_DEBUG_LOG("UID list [%s]", p);*/ uid_elem = (emcore_uid_list *)malloc(sizeof(emcore_uid_list)); if (!uid_elem) { @@ -2240,7 +2591,7 @@ int emcore_download_uid_all(MAILSTREAM *mail_stream, email_internal_mailbox_t *m } if (for_delete == EM_CORE_GET_UIDS_FOR_NO_DELETE) { - if ((ref_account->retrieval_mode == EMAIL_IMAP4_RETRIEVAL_MODE_NEW) && (strstr(p, "\\Seen"))) { + if ((ref_account->retrieval_mode & EMAIL_IMAP4_RETRIEVAL_MODE_NEW) && (strstr(p, "\\Seen"))) { EM_SAFE_FREE (p); continue; } @@ -2557,6 +2908,7 @@ int emcore_free_uids(emcore_uid_list *uid_list, int *err_code) p = uid_list; uid_list = uid_list->next; EM_SAFE_FREE (p->uid); + EM_SAFE_FREE (p->internaldate); EM_SAFE_FREE (p); } @@ -2581,8 +2933,10 @@ INTERNAL_FUNC char *emcore_guess_charset(char *source_string) int i = 0; int confidence = 0; int most_confidence = 0; - const char *detected_charset = NULL; + char *temp_charset = NULL; char *uscdet_result_charset = NULL; + const char *charset = NULL; + const char *detected_charset = NULL; char *ret = NULL; email_account_t *account_ref = NULL; @@ -2593,10 +2947,19 @@ INTERNAL_FUNC char *emcore_guess_charset(char *source_string) result_charset = (CHARSET*)utf8_infercharset(&source_text); if(result_charset) { - EM_DEBUG_LOG_SEC("return_charset->name [%s]", result_charset->name); return EM_SAFE_STRDUP(result_charset->name); } + time_t t = time(0); + struct tm *data = localtime(&t); + + for (i = 0 ; i < G_N_ELEMENTS(known_zone_charset); i++) { + if (!g_ascii_strcasecmp(known_zone_charset[i].tm_zone, data->tm_zone)) { + temp_charset = strdup(known_zone_charset[i].charset); + break; + } + } + detector = ucsdet_open(&err); if(U_FAILURE(err)) EM_DEBUG_LOG("ucsdet_open failed"); @@ -2614,13 +2977,18 @@ INTERNAL_FUNC char *emcore_guess_charset(char *source_string) if(U_FAILURE(err)) EM_DEBUG_LOG("ucsdet_getConfidence failed"); + charset = ucsdet_getName(match[i], &err); if(U_FAILURE(err)) EM_DEBUG_LOG("ucsdet_getName failed"); if (most_confidence < confidence) { most_confidence = confidence; - detected_charset = ucsdet_getName(match[i], &err); + detected_charset = charset; + } else if (most_confidence == confidence) { + if (temp_charset && !strcasecmp(charset, temp_charset)) + detected_charset = charset; } + EM_DEBUG_LOG_DEV("UCSDET DETECTED CHARSET:%s, %d", ucsdet_getName(match[i], &err), confidence); } @@ -2629,6 +2997,8 @@ INTERNAL_FUNC char *emcore_guess_charset(char *source_string) ucsdet_close(detector); + EM_SAFE_FREE(temp_charset); + if (uscdet_result_charset) return uscdet_result_charset; @@ -2676,14 +3046,18 @@ INTERNAL_FUNC int emcore_sync_mail_from_client_to_server(int mail_id) char *long_enc_path = NULL; char *data = NULL; char set_flags[100] = {0,}; + char message_size[100] = {0,}; ENVELOPE *envelope = NULL; FILE *fp = NULL; STRING str; + STRING str_data; MAILSTREAM *stream = NULL; email_account_t *account_ref = NULL; emstorage_mail_tbl_t *mail_table_data = NULL; emstorage_attachment_tbl_t *attachment_tbl_data = NULL; emstorage_mailbox_tbl_t *mailbox_tbl = NULL; + int max_alloc_size = 40960; /*40K*/ + int alloc_size = 0; /* get a mail from mail table */ if (!emstorage_get_mail_by_id(mail_id, &mail_table_data, true, &err)) { @@ -2731,10 +3105,10 @@ INTERNAL_FUNC int emcore_sync_mail_from_client_to_server(int mail_id) goto FINISH_OFF; } - if (fname){ - if (!(fp = fopen(fname, "a+"))) { - EM_DEBUG_EXCEPTION("fopen failed - %s", fname); - err = EMAIL_ERROR_SYSTEM_FAILURE; + if (fname) { + err = em_fopen(fname, "a+", &fp); + if (err != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("em_fopen failed - %s", fname); goto FINISH_OFF; } } @@ -2767,27 +3141,100 @@ INTERNAL_FUNC int emcore_sync_mail_from_client_to_server(int mail_id) /* 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"); - } + if (len < max_alloc_size) + alloc_size = len; + else + alloc_size = max_alloc_size; - INIT(&str, mail_string, data, len); + data = (char *)malloc(alloc_size + 1); + + + snprintf(message_size, sizeof(message_size), "%d", len); + INIT(&str, mail_string, message_size, EM_SAFE_STRLEN(message_size)); sprintf(set_flags, "\\Seen"); + int total_size = len; + int data_size = 0; + int sent_size = 0; + if (mail_table_data->flags_seen_field){ - if (!mail_append_full(stream, long_enc_path, set_flags, NULL, &str)) { - EM_DEBUG_EXCEPTION("mail_append failed -"); - err = EMAIL_ERROR_IMAP4_APPEND_FAILURE; - goto FINISH_OFF; + if (!mail_append_command(stream, long_enc_path, set_flags, NULL, &str)) { + EM_DEBUG_EXCEPTION("mail_append failed -"); + err = EMAIL_ERROR_IMAP4_APPEND_FAILURE; + goto FINISH_OFF; + } + + while (total_size > 0) { + if (total_size < max_alloc_size) + data_size = total_size; + else + data_size = max_alloc_size; + + memset(data, 0x0, data_size+1); + read_size = fread(data, sizeof(char), data_size, fp); + + if (read_size != data_size) { + /* read fail. */ + EM_SAFE_FREE(data); + EM_DEBUG_EXCEPTION("Read from file failed"); + } + sent_size += read_size; + + INIT(&str_data, mail_string, data, read_size); + if (!mail_append_message(stream, long_enc_path, &str_data)) { + EM_DEBUG_EXCEPTION("mail_append failed -"); + err = EMAIL_ERROR_IMAP4_APPEND_FAILURE; + goto FINISH_OFF; + } else { + EM_DEBUG_LOG("Sent data Successfully. sent[%d] total[%d]", sent_size, total_size); + } + total_size -= data_size; + } + EM_SAFE_FREE(data); + + if (!mail_append_end(stream, long_enc_path)) { + EM_DEBUG_EXCEPTION("mail_append failed -"); + err = EMAIL_ERROR_IMAP4_APPEND_FAILURE; + goto FINISH_OFF; } } else{ - if (!mail_append_full(stream, long_enc_path, NULL, NULL, &str)) { + if (!mail_append_command(stream, long_enc_path, NULL, NULL, &str)) { + EM_DEBUG_EXCEPTION("mail_append failed -"); + err = EMAIL_ERROR_IMAP4_APPEND_FAILURE; + goto FINISH_OFF; + } + + while (total_size > 0) { + if (total_size < max_alloc_size) + data_size = total_size; + else + data_size = max_alloc_size; + + memset(data, 0x0, data_size+1); + read_size = fread(data, sizeof(char), data_size, fp); + + if (read_size != data_size) { + /* read fail. */ + EM_SAFE_FREE(data); + EM_DEBUG_EXCEPTION("Read from file failed"); + } + sent_size += read_size; + + INIT(&str_data, mail_string, data, read_size); + if (!mail_append_message(stream, long_enc_path, &str_data)) { + EM_DEBUG_EXCEPTION("mail_append failed -"); + err = EMAIL_ERROR_IMAP4_APPEND_FAILURE; + goto FINISH_OFF; + } else { + EM_DEBUG_LOG_DEV("Sent data Successfully. sent[%d] total[%d]", sent_size, len); + } + total_size -= data_size; + } + EM_SAFE_FREE(data); + + if (!mail_append_end(stream, long_enc_path)) { EM_DEBUG_EXCEPTION("mail_append failed -"); err = EMAIL_ERROR_IMAP4_APPEND_FAILURE; goto FINISH_OFF; @@ -2947,6 +3394,8 @@ FINISH_OFF: EM_SAFE_FREE(account_ref); } + emcore_free_partial_body_thd_event(&pbd_event, NULL); + if (NULL != err_code) *err_code = err; @@ -2959,9 +3408,10 @@ static int emcore_parse_bodystructure(void *stream, IMAPPARSEDREPLY *reply_from_ EM_DEBUG_FUNC_BEGIN("stream:[%p], reply_from_server:[%p], bodystructure:[%p]", stream, reply_from_server, bodystructure); int err = EMAIL_ERROR_NONE; + char* ptr = NULL; if (!stream || !reply_from_server || !bodystructure || !cnt_info || !body || !total_mail_size) { - EM_DEBUG_EXCEPTION("Invalid paramter stream[%p] reply_from_server[%p] bodystructure[%p] cnt_info[%p] body[%p] total_mail_size[%p]", + EM_DEBUG_EXCEPTION("Invalid paramter stream[%p] reply_from_server[%p] bodystructure[%p] cnt_info[%p] body[%p] total_mail_size[%p]", stream, reply_from_server, bodystructure, cnt_info, body, total_mail_size); err = EMAIL_ERROR_INVALID_PARAM; return err; @@ -2982,8 +3432,7 @@ static int emcore_parse_bodystructure(void *stream, IMAPPARSEDREPLY *reply_from_ } bodystructure_start = bodystructure_start + strlen("BODYSTRUCTURE"); - bodystructure_string = strdup(bodystructure_start); - char* ptr = bodystructure_string; + ptr = bodystructure_string = strdup(bodystructure_start); EM_DEBUG_LOG_DEV("BODYSTRUCTURE:%s", bodystructure_string); @@ -3014,7 +3463,7 @@ static int emcore_parse_bodystructure(void *stream, IMAPPARSEDREPLY *reply_from_ goto FINISH_OFF; } - if (emcore_get_body(stream, 0, 0, 0, p_body, p_cnt_info, &err) < 0 || !p_cnt_info) { + if (emcore_get_body(stream, 0, 0, 0, p_body, NULL, p_cnt_info, &err) < 0 || !p_cnt_info) { EM_DEBUG_EXCEPTION("emcore_get_body failed[%d]", err); err = EMAIL_ERROR_IMAP4_FETCH_UID_FAILURE; goto FINISH_OFF; @@ -3041,7 +3490,7 @@ FINISH_OFF: return err; } -static int emcore_update_attachment_except_inline(struct _m_content_info *cnt_info, int account_id, int mail_id, int mailbox_id, int *output_total_attachment_size, int *output_attachment_count, int *output_inline_attachment_count) +INTERNAL_FUNC int emcore_update_attachment_except_inline(struct _m_content_info *cnt_info, int account_id, int mail_id, int mailbox_id, int *output_total_attachment_size, int *output_attachment_count, int *output_inline_attachment_count) { EM_DEBUG_FUNC_BEGIN("cnt_info : [%p], account_id : [%d], mail_id : [%d], mailbox_id : [%d]", cnt_info, account_id, mail_id, mailbox_id); int err = EMAIL_ERROR_NONE; @@ -3053,11 +3502,6 @@ static int emcore_update_attachment_except_inline(struct _m_content_info *cnt_in } - if (!cnt_info->file || !cnt_info->file->name) { - EM_DEBUG_LOG("Not include attachment"); - return err; - } - int attachment_count = 0; int total_attach_size = 0; int inline_attachment_count = 0; @@ -3069,17 +3513,28 @@ static int emcore_update_attachment_except_inline(struct _m_content_info *cnt_in attachment_tbl.mailbox_id = mailbox_id; attachment_tbl.attachment_save_status = 0; +#ifdef __FEATURE_USE_GMIME__ + for (inline_attachment_count = 0, attach_info = cnt_info->inline_file; attach_info; attach_info = attach_info->next) { + if (attach_info->type == INLINE_ATTACHMENT) { + inline_attachment_count++; + } + } +#endif + for (attachment_count = 0, attach_info = cnt_info->file; attach_info; attach_info = attach_info->next, attachment_count++) { + +#ifndef __FEATURE_USE_GMIME__ if (attach_info->type == INLINE_ATTACHMENT) { EM_DEBUG_LOG("INLINE ATTACHMENT"); inline_attachment_count++; continue; } - +#endif total_attach_size += attach_info->size; attachment_tbl.attachment_size = attach_info->size; attachment_tbl.attachment_path = attach_info->save; attachment_tbl.attachment_name = attach_info->name; + attachment_tbl.content_id = attach_info->content_id; attachment_tbl.attachment_drm_type = attach_info->drm; attachment_tbl.attachment_mime_type = attach_info->attachment_mime_type; #ifdef __ATTACHMENT_OPTI__ @@ -3099,7 +3554,11 @@ static int emcore_update_attachment_except_inline(struct _m_content_info *cnt_in FINISH_OFF: if (output_attachment_count) +#ifdef __FEATURE_USE_GMIME__ + *output_attachment_count = attachment_count; +#else *output_attachment_count = attachment_count - inline_attachment_count; +#endif if (output_inline_attachment_count) *output_inline_attachment_count = inline_attachment_count; @@ -3110,17 +3569,19 @@ FINISH_OFF: EM_DEBUG_FUNC_END("err : [%d]", err); return err; } -#define UID_RANGE_STRING_LENGTH 3000 -#define TEMP_STRING_LENGTH 50 + +#define UID_RANGE_STRING_LENGTH 3000 +#define MULTIPART_BOUNDARY_LENGTH 1024 +#define TEMP_STRING_LENGTH 50 +#define CONTENT_TRANSFER_ENCODING_STRING "Content-Transfer-Encoding" static int emcore_parse_html_part_for_partial_body(char *start_header, char *boundary_string, char *bufsendforparse, char *text_html, int body_size) { EM_DEBUG_FUNC_BEGIN("start_header [%p], boundary_string [%s], bufsendforparse [%s], text_html [%s], body_size [%d]", start_header, boundary_string, bufsendforparse, text_html, body_size); int err = EMAIL_ERROR_NONE; - int html_uidno = 0; int iEncodingHeader = 0; - int enc_type = ENCOTHER, dec_len = 0, html_length = 0; + int enc_type = ENCOTHER, dec_len = 0; char EncodingHeader[40] = {0}; char Encoding[30] = {0}; char *pEncodingHeaderEnd = NULL; @@ -3131,6 +3592,11 @@ static int emcore_parse_html_part_for_partial_body(char *start_header, char *bou EM_DEBUG_LOG("Content-Type : text/html or message/rfc822 or text/rfc822-headers"); + if(start_header == NULL) { /*prevent 27448*/ + EM_DEBUG_EXCEPTION("start_header NULL"); + return false; + } + pHeaderStart = start_header; pHeaderStart = pHeaderStart-2; do{ @@ -3139,29 +3605,36 @@ static int emcore_parse_html_part_for_partial_body(char *start_header, char *bou pHeaderStart++; - memcpy(EncodingHeader, pHeaderStart, 25); + /* Check string size */ + if (EM_SAFE_STRLEN(pHeaderStart) < strlen(CONTENT_TRANSFER_ENCODING_STRING)) { + EM_DEBUG_EXCEPTION("pHeaderStart is truncated."); + return false; + } - if (strcasecmp(EncodingHeader, "Content-Transfer-Encoding") == 0){ + memcpy(EncodingHeader, pHeaderStart, strlen(CONTENT_TRANSFER_ENCODING_STRING)); + + if (strcasecmp(EncodingHeader, CONTENT_TRANSFER_ENCODING_STRING) == 0){ pEncodingHeaderEnd = strstr(pHeaderStart, CRLF_STRING); + + if ((pEncodingHeaderEnd - (pHeaderStart+27)) > 30) { + EM_DEBUG_EXCEPTION("Encoding is too long"); + return false; + } memcpy(Encoding, pHeaderStart + 27, pEncodingHeaderEnd - (pHeaderStart+27)); iEncodingHeader = 1; } /* HTML Content found */ - - if(!start_header) { /*prevent 27448*/ - EM_DEBUG_EXCEPTION("start_header NULL"); - return false; - } 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[1600] = {0}; + char multipart_boundary[MULTIPART_BOUNDARY_LENGTH] = {0}; char *multipart_related_boundry = NULL; char *multipart_related_boundry_end = NULL; + if (iEncodingHeader == 1) multipart_related_boundry = pHeaderStart; else @@ -3173,8 +3646,10 @@ static int emcore_parse_html_part_for_partial_body(char *start_header, char *bou while (bufsendforparse < multipart_related_boundry && *multipart_related_boundry != LF && *multipart_related_boundry != NULL_CHAR) multipart_related_boundry -= 1; - if ((multipart_related_boundry_end - multipart_related_boundry) > 1600) + if ((multipart_related_boundry_end - multipart_related_boundry) > MULTIPART_BOUNDARY_LENGTH) { + EM_DEBUG_EXCEPTION("Encoding is too long"); return false; + } memcpy(multipart_boundary, multipart_related_boundry, multipart_related_boundry_end - multipart_related_boundry); @@ -3187,9 +3662,7 @@ static int emcore_parse_html_part_for_partial_body(char *start_header, char *bou if (end == NULL) { EM_DEBUG_LOG("HTML body contents exceeds limited 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"); @@ -3204,7 +3677,6 @@ static int emcore_parse_html_part_for_partial_body(char *start_header, char *bou else EM_DEBUG_EXCEPTION(" Content not per as grammar."); } - EM_DEBUG_LOG("iEncodingHeader [%d]", iEncodingHeader); if (iEncodingHeader == 1){ @@ -3243,14 +3715,12 @@ static int emcore_parse_html_part_for_partial_body(char *start_header, char *bou if (emcore_decode_body_text(text_html, end - txt_html, enc_type , &dec_len, &err) < 0) EM_DEBUG_EXCEPTION("emcore_decode_body_text failed [%d]", err); - html_length = dec_len; } EM_DEBUG_LOG("Decoded length = %d", dec_len); } else{ memcpy(text_html, start, end-txt_html); - html_length = (end-txt_html); } /* EM_DEBUG_LOG(" Content-Type: text/html [%s]\n", text_html); */ @@ -3282,13 +3752,11 @@ static int emcore_parse_plain_part_for_partial_body(char *header_start_string, c 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); @@ -3390,7 +3858,7 @@ static int emcore_parse_plain_part_for_partial_body(char *header_start_string, c /* Content-Type: IMAGE/octet-stream; name = Default.png */ /* Content-Transfer-Encoding: BASE64 */ -/* Content-ID: <4b0d6810b17291f9438783a8eb9d5228@com.samsung.slp.email> */ +/* Content-ID: <4b0d6810b17291f9438783a8eb9d5228@org.tizen.email> */ /* Content-Disposition: inline; filename = Default.png */ static void emcore_free_email_image_data(email_image_data **image_data, int count) @@ -3428,8 +3896,8 @@ static int emcore_parse_image_part_for_partial_body(char *header_start_string, c char *image_boundary = NULL; char *image_boundary_end = NULL; char *temp_image_boundary = NULL; - int i = 0, ch_image = 0, cidno = 0; - int enc_type = ENCOTHER, dec_len = 0, image_length = 0; + int i = 0, ch_image = 0; + int enc_type = ENCOTHER; char *p = header_start_string; char *start = NULL, *end = NULL, *txt_image = NULL; char *temp_image = NULL; @@ -3465,7 +3933,8 @@ static int emcore_parse_image_part_for_partial_body(char *header_start_string, c 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) + + if (((char *)strcasestr((const char *)temp_image_boundary, "Content-type:") == NULL) && (temp_image_boundary[0] == '-')) p_boundary_string = strdup(temp_image_boundary); else p_boundary_string = EM_SAFE_STRDUP(boundary_string); @@ -3481,19 +3950,17 @@ static int emcore_parse_image_part_for_partial_body(char *header_start_string, c emcore_get_content_type_from_mime_string(start_header, &(image_data[i].mime_type)); EM_DEBUG_LOG("image_data[i].mime_type : [%s]", image_data[i].mime_type); - if ((strcasestr(p, "Content-Disposition: attachment")) || (!strcasestr(p, "Content-ID: <"))){ + if ((strcasestr(p, "Content-Disposition: attachment")) || (!strcasestr(p, "Content-ID: <"))) { EM_DEBUG_LOG("Body has attachment no need to parse "); end = NULL; multiple_image = NULL; } else { /* HTML Content found */ ch_image = 0; - cidno = 0; - int boundarylen = -1; char *cid = NULL; char *temp_name = NULL; char *decoded_filename = NULL; - + image_data[i].image_file_name = NULL; if(!start_header) { /*prevent 27449*/ @@ -3509,30 +3976,31 @@ static int emcore_parse_image_part_for_partial_body(char *header_start_string, c if (temp_name != NULL){ temp_image = temp_name; if (*(temp_image + 5) == '"') { - temp_image = temp_image + 5; + temp_image = temp_image + 6; temp_name = temp_name + 6 ; } else { temp_image = temp_image + 5; temp_name = temp_name + 5; } - while (*temp_image != CR){ + while (*temp_image != CR){ temp_image++; ch_image++; } - + if (ch_image > 0) { - image_data[i].image_file_name = em_malloc(ch_image); + image_data[i].image_file_name = em_malloc(ch_image+3); if (image_data[i].image_file_name == NULL) { EM_DEBUG_EXCEPTION("em_malloc failed"); + EM_SAFE_FREE(p_boundary_string); return false; } if (*(temp_image - 1) == '"') { memcpy(image_data[i].image_file_name, temp_name, ch_image - 2); } else { - memcpy(image_data[i].image_file_name, temp_name, ch_image - 1); + memcpy(image_data[i].image_file_name, temp_name, ch_image); } - } + } decoded_filename = emcore_decode_rfc2047_text(image_data[i].image_file_name, &err); if(decoded_filename) { @@ -3563,6 +4031,7 @@ static int emcore_parse_image_part_for_partial_body(char *header_start_string, c image_data[i].image_file_name = em_malloc((cid_end - cid) + 1); if (image_data[i].image_file_name == NULL) { EM_DEBUG_EXCEPTION("em_malloc failed"); + EM_SAFE_FREE(p_boundary_string); return false; } memcpy(image_data[i].image_file_name, cid, cid_end - cid); @@ -3576,7 +4045,6 @@ static int emcore_parse_image_part_for_partial_body(char *header_start_string, c start = txt_image; end = strstr(txt_image, p_boundary_string); - if (end == NULL){ EM_DEBUG_LOG("HTML body contents exceeds limited Bytes"); /* end points to end of partial body data */ @@ -3584,7 +4052,6 @@ static int emcore_parse_image_part_for_partial_body(char *header_start_string, c } else{ EM_DEBUG_LOG("This image is fully downloaded"); - boundarylen = EM_SAFE_STRLEN(p_boundary_string); end -= 2; image_data[i].fully_downloaded = 1; } @@ -3612,14 +4079,12 @@ static int emcore_parse_image_part_for_partial_body(char *header_start_string, c memcpy(image_data[i].text_image, start, end-txt_image); if (emcore_decode_body_text(image_data[i].text_image, end-txt_image, enc_type , &(image_data[i].dec_len), &err) < 0) EM_DEBUG_EXCEPTION("emcore_decode_body_text failed [%d]", err); - else - image_length = image_data[i].dec_len; } else EM_DEBUG_EXCEPTION("em_malloc() failed"); } - EM_DEBUG_LOG("Decoded length [%d]", dec_len); + EM_DEBUG_LOG("Decoded length [%d]", image_data[i].dec_len); } else{ image_data[i].text_image = (char *)em_malloc(end-txt_image); @@ -3642,7 +4107,7 @@ static int emcore_parse_image_part_for_partial_body(char *header_start_string, c } while (multiple_image != NULL && donot_parse_next_image != 1 && (i < IMAGE_DISPLAY_PARTIAL_BODY_COUNT)); EM_SAFE_FREE(p_boundary_string); - + EM_DEBUG_FUNC_END(); return 1; } @@ -3670,7 +4135,7 @@ static int emcore_find_boundary_string_of_the_part(const char *whole_string, con 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_malloc(boundary_end - boundary_cur + 15); if(!boundary_string) { EM_DEBUG_EXCEPTION("em_malloc failed"); @@ -3734,7 +4199,11 @@ static int emcore_parse_body_for_imap(char *body_str, int body_size, struct _m_c char *temp_alternative_plain_header = NULL; char *temp_content_type = NULL; - p_body_str = EM_SAFE_STRDUP(body_str); + char *local_encoding_str = NULL; + char *local_boundary_str = NULL; + char *local_body_str = NULL; + + p_body_str = g_strdup(body_str); text_plain = em_malloc(body_size + 1); text_html = em_malloc(body_size + 1); @@ -3745,29 +4214,9 @@ static int emcore_parse_body_for_imap(char *body_str, int body_size, struct _m_c goto FINISH_OFF; } - if (!strcasestr(p_body_str, "Content-Type: ") && (cnt_info->text.plain || cnt_info->text.html)) { - /* 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("mbody->encoding [%d] ", encoding_type); - - if (emcore_decode_body_text(p_body_str, EM_SAFE_STRLEN(p_body_str), encoding_type, &dec_len, &err) < 0) { - EM_DEBUG_EXCEPTION("emcore_decode_body_text failed [%d]", err); - goto FINISH_OFF; - } - - EM_DEBUG_LOG("Decoded length [%d]", dec_len); - - if (dec_len > 0) { - if (cnt_info->text.plain) { - memcpy(text_plain, p_body_str, dec_len); - } - - if (cnt_info->text.html) { - memcpy(text_html, p_body_str, dec_len); - } - } - } else { /* Partial body has headers with Content-Type: text/html or Content-Type: text/plain */ + if ((cnt_info->text.plain && cnt_info->text.html) || cnt_info->file) { + /* Start multipart parsing */ + /* Partial body has headers with Content-Type: text/html or Content-Type: text/plain */ no_alternative_part_flag = 0; if (((temp_alternative_plain_header = (char *)strcasestr(p_body_str, "Content-type: multipart/alternative")) != NULL)) { /* Found 'alternative' */ if (((temp_content_type = (char *)strcasestr(p_body_str, "Content-type: text/plain")) != NULL)) { @@ -3779,8 +4228,8 @@ static int emcore_parse_body_for_imap(char *body_str, int body_size, struct _m_c EM_DEBUG_LOG(" Content-type: multipart/alternative "); boundary_start = strstr(temp_alternative_plain_header, "--"); if(!boundary_start) { /*prevent 37946 */ - err = EMAIL_ERROR_INVALID_DATA; - goto FINISH_OFF; + err = EMAIL_ERROR_INVALID_DATA; + goto FINISH_OFF; } boundary_end = strcasestr(boundary_start, "Content-type:"); if(!boundary_end) { /*prevent 37946 */ @@ -3804,13 +4253,13 @@ static int emcore_parse_body_for_imap(char *body_str, int body_size, struct _m_c if (no_alternative_part_flag) { boundary_start = strstr(p_body_str, "--"); if(!boundary_start) { /*prevent 37946 */ - err = EMAIL_ERROR_INVALID_DATA; - goto FINISH_OFF; + err = EMAIL_ERROR_INVALID_DATA; + goto FINISH_OFF; } - boundary_end = strcasestr(boundary_start, "Content-type:"); + boundary_end = strcasestr(boundary_start, "\r\n"); if(!boundary_end) { /*prevent 37946 */ - err = EMAIL_ERROR_INVALID_DATA; - goto FINISH_OFF; + err = EMAIL_ERROR_INVALID_DATA; + goto FINISH_OFF; } boundary_string = em_malloc(boundary_end - (boundary_start + strlen("--"))); @@ -3825,11 +4274,6 @@ static int emcore_parse_body_for_imap(char *body_str, int body_size, struct _m_c if (boundary_string && boundary_end) { /*prevent 37946 */ /* EM_DEBUG_LOG("boundary_string : [%s]", boundary_string); */ - char *next_boundary_start = NULL; - next_boundary_start = (char *)strcasestr(boundary_end, boundary_string); - - /*if (next_boundary_start) - boundary_end = next_boundary_start;*/ if (((start_header = (char *)strcasestr(boundary_end, "Content-Type: text/html")) != NULL) && (no_html != 1) &&(((char *)strcasestr(boundary_end, "Content-Type: message/rfc822")) == NULL) && (((char *)strcasestr(boundary_end, "Content-Type: text/rfc822-headers")) == NULL)) @@ -3864,11 +4308,93 @@ static int emcore_parse_body_for_imap(char *body_str, int body_size, struct _m_c } } } + else { + /* Encoded Content-Type: text/html or Content-Type: text/plain */ + /* No Partial body has No headers with Content-Type: text/html or Content-Type: text/plain */ + char *start_of_body = NULL; + char *end_of_body = NULL; + char *local_encoding = NULL; + char *local_encoding_end = NULL; + char *local_boundary_end = NULL; + int local_encoding_len = 0; + int local_boundary_len = 0; + int enc_type = encoding_type; + EM_DEBUG_LOG_DEV("mbody->encoding [%d] ", enc_type); + + if (EM_SAFE_STRLEN(p_body_str) > 2 && p_body_str[0] == '-' && p_body_str[1] == '-') { + + local_boundary_end = strstr(p_body_str, "\r\n"); + if (local_boundary_end) { + local_boundary_len = local_boundary_end - p_body_str; + local_boundary_str = em_malloc(local_boundary_len + 2); + memcpy(local_boundary_str, p_body_str+2, local_boundary_len-2); + EM_DEBUG_LOG_DEV("local_boundary_str : %s", local_boundary_str); + end_of_body = strstr(local_boundary_end, local_boundary_str); + if (end_of_body) end_of_body -= 2; + } + + local_encoding = strcasestr(p_body_str, "Content-Transfer-Encoding: "); + if (local_encoding) { + local_encoding_end = strstr(local_encoding, "\r\n"); + + if (local_encoding && (local_encoding_end > local_encoding)) { + local_encoding_len = local_encoding_end - local_encoding; + local_encoding_str = em_malloc(local_encoding_len + 2); + + if (local_encoding_str) { + memcpy(local_encoding_str, local_encoding + EM_SAFE_STRLEN("Content-Transfer-Encoding: "), local_encoding_len); + + enc_type = ENCOTHER; + if (strncasecmp(local_encoding_str, "base64", strlen("base64")) == 0) + enc_type = ENCBASE64; + else if (strncasecmp(local_encoding_str, "quoted-printable", strlen("quoted-printable")) == 0) + enc_type = ENCQUOTEDPRINTABLE; + + EM_DEBUG_LOG_DEV("local enc_type [%d]", enc_type); + } + } + } + + start_of_body = strstr(p_body_str, "\r\n\r\n"); + if (start_of_body) { + start_of_body = start_of_body+strlen("\r\n\r\n"); + if (end_of_body && (end_of_body > start_of_body)) { + local_body_str = em_malloc(end_of_body - start_of_body + 2); + memcpy(local_body_str, start_of_body, end_of_body - start_of_body); + } else { + local_body_str = EM_SAFE_STRDUP(start_of_body); + } + } + } + + if (!local_body_str) + local_body_str = g_strdup(p_body_str); + + if (emcore_decode_body_text(local_body_str, EM_SAFE_STRLEN(local_body_str), enc_type, &dec_len, &err) < 0) { + EM_DEBUG_EXCEPTION("emcore_decode_body_text failed [%d]", err); + goto FINISH_OFF; + } + + EM_DEBUG_LOG("Decoded length [%d]", dec_len); + + if (dec_len > 0) { + if (cnt_info->text.plain) { + memcpy(text_plain, local_body_str, dec_len); + } + + if (cnt_info->text.html) { + memcpy(text_html, local_body_str, dec_len); + } + } + } FINISH_OFF: EM_SAFE_FREE(p_body_str); EM_SAFE_FREE(boundary_string); + EM_SAFE_FREE(local_boundary_str); + EM_SAFE_FREE(local_encoding_str); + EM_SAFE_FREE(local_body_str); if (err != EMAIL_ERROR_NONE) { EM_SAFE_FREE(text_plain); @@ -3888,6 +4414,603 @@ FINISH_OFF: #define TAG_LENGTH 16 #define COMMAND_LENGTH 2000 +static int emcore_gmime_download_imap_partial_mail_body(MAILSTREAM *stream, int input_download_size, email_event_partial_body_thd *pbd_event, int item_count, int *error) +{ + EM_DEBUG_FUNC_BEGIN("stream [%p], input_download_size[%d], pbd_event [%p], item_count [%d], error [%p]", stream, input_download_size, pbd_event, item_count, error); + + int ret = false, err = EMAIL_ERROR_NONE; + int j = 0, i = 0; + int i32_index = 0; + int total_mail_size = 0, total_attachment_size = 0; + int temp_count = 0, attachment_num = 0, inline_attachment_num = 0; + int inline_download_count = 0; + char buf[512] = {0, }; + char uid_range_string_to_be_downloaded[UID_RANGE_STRING_LENGTH] = {0,}; + char imap_tag[TAG_LENGTH] = {0, }; + char command[COMMAND_LENGTH] = {0, }; + char uid_string[TEMP_STRING_LENGTH] = {0, }; + char rfc822_micalg[TEMP_STRING_LENGTH] = {0, }; + char rfc822_protocol[TEMP_STRING_LENGTH] = {0, }; + const char *sender = NULL; + IMAPLOCAL *imaplocal = NULL; + IMAPPARSEDREPLY *reply_from_server = NULL; + emstorage_mail_tbl_t *mail = NULL; + email_partial_buffer *imap_response = NULL; + BODY *body = NULL; + struct _m_content_info *cnt_info = NULL; + emstorage_attachment_tbl_t attachment_tbl; + email_event_partial_body_thd *stSectionNo = NULL; + emstorage_mail_text_tbl_t *mail_text = NULL; /* prevent */ + + GMimeMessage *message1 = NULL; + GMimeParser *parser1 = NULL; + GMimeStream *stream1 = NULL; + char *bodystructure_start = NULL; + char *bodystructure_buf = NULL; + char *bodystructure_ptr = NULL; + + GMimeStream *stream2 = NULL; + GMimeMessage *message2 = NULL; + GMimeParser *parser2 = NULL; + char *fulltext = NULL; + + GMimePartIter *iter1 = NULL; + GMimePartIter *iter2 = NULL; + GMimeObject *part_tmp1 = NULL; + GMimeObject *part_tmp2 = NULL; + char *part_path = NULL; + + if (!(stream) || !(imaplocal = stream->local) || !imaplocal->netstream || !pbd_event) { + EM_DEBUG_EXCEPTION("invalid parameter"); + err = EMAIL_ERROR_INVALID_PARAM; + EM_DEBUG_FUNC_END("ret [%d]", ret); + return ret; + } + + EM_DEBUG_LOG("Start of emcore_get_section_for_partial_download, item_count = %d ", item_count); + + /* For constructing UID list which is having 10 UID or less at a time */ + for (j = 0, stSectionNo = pbd_event; (stSectionNo != NULL && j < item_count); j++) + { + /* delete log before uploading master branch. it is flooding */ + + if (i32_index >= UID_RANGE_STRING_LENGTH){ + EM_DEBUG_EXCEPTION("String length exceeded its limitation!"); + goto FINISH_OFF; + } + + if (j == item_count - 1) + i32_index += SNPRINTF(uid_range_string_to_be_downloaded + i32_index, + UID_RANGE_STRING_LENGTH - i32_index, "%lu", stSectionNo[j].server_mail_id); + else + i32_index += SNPRINTF(uid_range_string_to_be_downloaded + i32_index, + UID_RANGE_STRING_LENGTH - i32_index, "%lu,", stSectionNo[j].server_mail_id); + } + + SNPRINTF(imap_tag, TAG_LENGTH, "%08lx", 0xffffffff & (stream->gensym++)); + SNPRINTF(command, COMMAND_LENGTH, "%s UID FETCH %s (BODYSTRUCTURE RFC822.HEADER BODY.PEEK[TEXT]<0.%d>)\015\012", + imap_tag, uid_range_string_to_be_downloaded, input_download_size); + + EM_DEBUG_LOG("command : %s", command); + + /* Sending out the IMAP request */ + if (!net_sout(imaplocal->netstream, command, (int)EM_SAFE_STRLEN(command))) { + EM_DEBUG_EXCEPTION("net_sout failed..."); + err = EMAIL_ERROR_CONNECTION_BROKEN; + goto FINISH_OFF; + } + + /* responce from the server */ + imap_response = emcore_get_response_from_server(imaplocal->netstream, + imap_tag, &reply_from_server, input_download_size, item_count); + + if (!imap_response || !reply_from_server ) { + EM_DEBUG_EXCEPTION(" Invalid response from emcore_get_response_from_server"); + goto FINISH_OFF; + } + + for (i = 0; i < item_count ; i++) { + + total_mail_size = 0; + total_attachment_size = 0; + attachment_num = 0; + + if(!(imap_response[i].bodystructure) || imap_response[i].bodystructure_len <= 0) continue; + + /* Search the account id of pbd_event */ + for (temp_count = 0; temp_count <= item_count && pbd_event[temp_count].server_mail_id != imap_response[i].uid_no; temp_count++) + continue; + + if (temp_count > item_count) { + EM_DEBUG_EXCEPTION("Can't find proper server_mail_id"); + goto FINISH_OFF; + } + + /* Start to parse the body */ + EM_DEBUG_LOG("Start partial body of server_mail_id %d", imap_response[i].uid_no); + + /* Check the body download status and body size */ + SNPRINTF(uid_string, sizeof(uid_string), "%ld", imap_response[i].uid_no); + if (!emstorage_get_maildata_by_servermailid(pbd_event[temp_count].mailbox_id, uid_string, &mail, true, &err) || !mail) { + EM_DEBUG_EXCEPTION("emstorage_get_mail_data_by_servermailid failed : [%d]", err); + if (err == EMAIL_ERROR_MAIL_NOT_FOUND || !mail) + goto FINISH_OFF; + } + + if (mail->body_download_status & EMAIL_BODY_DOWNLOAD_STATUS_FULLY_DOWNLOADED) { + EM_DEBUG_LOG("Downloaded mail"); + continue; + } + + if (cnt_info) { + emcore_free_content_info(cnt_info); + EM_SAFE_FREE(cnt_info); + } + + if (body) { + mail_free_body(&body); + body = NULL; + } + + EM_SAFE_FREE(fulltext); + + if (!(cnt_info = em_malloc(sizeof(struct _m_content_info)))) { + EM_DEBUG_EXCEPTION("em_malloc failed..."); + err = EMAIL_ERROR_OUT_OF_MEMORY; + goto FINISH_OFF; + } + + body = mail_newbody(); + if (body == NULL) { + EM_DEBUG_EXCEPTION("New body creationg failed"); + err = EMAIL_ERROR_OUT_OF_MEMORY; + goto FINISH_OFF; + } + + /* Get the body strcuture string */ + bodystructure_start = strstr(imap_response[i].bodystructure, "BODYSTRUCTURE ("); + if (!bodystructure_start) { + EM_DEBUG_EXCEPTION("Invalid bodystructure :[%s]", imap_response[i].bodystructure); + err = EMAIL_ERROR_INVALID_PARAM; + goto FINISH_OFF; + } + + bodystructure_start = bodystructure_start + strlen("BODYSTRUCTURE"); + bodystructure_ptr = bodystructure_buf = EM_SAFE_STRDUP(bodystructure_start); + EM_DEBUG_LOG_DEV("GMIME BODYSTRUCTURE:%s", bodystructure_buf); + + mail_parameters(stream, SET_FREEBODYSPAREP, emcore_free_body_sparep); + imap_parse_body_structure(stream, body, + (unsigned char **)&bodystructure_buf, reply_from_server); + + EM_SAFE_FREE(bodystructure_ptr); + + /* Construct message1(fake gmime message object) with rfc822 header */ + stream1 = g_mime_stream_mem_new_with_buffer(imap_response[i].rfc822header, imap_response[i].rfc822header_len); + parser1 = g_mime_parser_new_with_stream(stream1); + if (stream1) g_object_unref(stream1); + + message1 = g_mime_parser_construct_message(parser1); + if (parser1) g_object_unref(parser1); + + /* message1 is multipart? */ + if (GMIME_IS_MULTIPART (message1->mime_part)) { + + /* Fill up mime part of message1 using bodystructure info */ + emcore_gmime_construct_multipart((GMimeMultipart *)message1->mime_part, body, "1", &total_mail_size); + + /* Construct message2 with partial body text */ + EM_DEBUG_LOG_DEV("RFC822H:%s", imap_response[i].rfc822header); + EM_DEBUG_LOG_DEV("BODYTEXT:%s", imap_response[i].bodytext); + fulltext = g_strconcat(imap_response[i].rfc822header, "\r\n\r\n", imap_response[i].bodytext, NULL); + + stream2 = g_mime_stream_mem_new_with_buffer(fulltext, EM_SAFE_STRLEN(fulltext)); + parser2 = g_mime_parser_new_with_stream(stream2); + if (stream2) g_object_unref(stream2); + EM_SAFE_FREE(fulltext); + + message2 = g_mime_parser_construct_message(parser2); + if (parser2) g_object_unref(parser2); + + /* Merge message2 with message1 to make complete gmime message object */ + + iter1 = g_mime_part_iter_new((GMimeObject *)message1); + iter2 = g_mime_part_iter_new((GMimeObject *)message2); + + if (!g_mime_part_iter_is_valid(iter1) || !g_mime_part_iter_is_valid(iter2)) { + EM_DEBUG_EXCEPTION("Part iterator is not valid"); + goto FINISH_OFF; + } + + do { + part_tmp2 = g_mime_part_iter_get_current(iter2); + if (part_tmp2 && GMIME_IS_PART(part_tmp2)) { + part_path = g_mime_part_iter_get_path(iter2); + + if (g_mime_part_iter_jump_to(iter1, part_path)) { + EM_DEBUG_LOG_DEV("g_mime_part_iter_jump_to: %s", part_path); + part_tmp1 = g_mime_part_iter_get_current(iter1); + if (part_tmp1 && GMIME_IS_PART(part_tmp1)) { + GMimeContentType *ctype_tmp1 = NULL; + GMimeContentType *ctype_tmp2 = NULL; + char *ctype_str1 = NULL; + char *ctype_str2 = NULL; + ctype_tmp1 = g_mime_object_get_content_type(part_tmp1); + ctype_tmp2 = g_mime_object_get_content_type(part_tmp2); + ctype_str1 = g_mime_content_type_to_string(ctype_tmp1); + ctype_str2 = g_mime_content_type_to_string(ctype_tmp2); + EM_DEBUG_LOG_DEV("%s", ctype_str1); + EM_DEBUG_LOG_DEV("%s", ctype_str2); + + if (g_ascii_strcasecmp(ctype_str1, ctype_str2) != 0) { + EM_DEBUG_EXCEPTION("PART of fake_message is different from message"); + } else { + char *ctype_size = NULL; + GMimeDataWrapper *content_tmp2 = NULL; + + ctype_size = (char *)g_mime_content_type_get_parameter(ctype_tmp1, "part_size"); + EM_DEBUG_LOG("Part.size.bytes[%s]", ctype_size); + if (ctype_size) + g_mime_object_set_content_type_parameter(part_tmp2, "part_size", ctype_size); + + content_tmp2 = g_mime_part_get_content_object(GMIME_PART(part_tmp2)); + if (content_tmp2 && part_tmp1 && GMIME_IS_PART(part_tmp1)) { + g_mime_part_set_content_object(GMIME_PART(part_tmp1), content_tmp2); + } + + /*part_idx = g_mime_multipart_index_of(GMIME_MULTIPART(message1->mime_part), part_tmp1); + replaced = g_mime_multipart_replace(GMIME_MULTIPART(message1->mime_part), part_idx, part_tmp2); + if (!replaced) { + EM_DEBUG_EXCEPTION("g_mime_multipart_replace failed"); + } + if (replaced) g_object_unref(replaced);*/ + + /*content_tmp2 = g_mime_part_get_content_object(GMIME_PART(part_tmp2)); + part_tmp1 = g_mime_part_iter_get_current(iter1); + if (content_tmp2 && part_tmp1 && GMIME_IS_PART(part_tmp1)) { + g_mime_part_set_content_object(GMIME_PART(part_tmp1), content_tmp2); + g_object_unref(content_tmp2); + }*/ + + } + + EM_SAFE_FREE(ctype_str1); + EM_SAFE_FREE(ctype_str2); + } + } else { + EM_DEBUG_LOG_SEC("g_mime_part_iter_jump_to: failed to jump to %s", part_path); + EM_SAFE_FREE(part_path); + goto FINISH_OFF; + } + + EM_SAFE_FREE(part_path); + } + } while (g_mime_part_iter_next(iter2)); + + if (iter1) { + g_mime_part_iter_free(iter1); + iter1 = NULL; + } + + if (iter2) { + g_mime_part_iter_free(iter2); + iter2 = NULL; + } + + if (message2) { + g_object_unref(message2); + message2 = NULL; + } + + if (g_strrstr(g_mime_message_get_sender(message1), "mmsc.plusnet.pl") != NULL || + g_strrstr(g_mime_message_get_sender(message1), "mms.t-mobile.pl") != NULL) { + cnt_info->attachment_only = 1; + } + + g_mime_message_foreach(message1, emcore_gmime_imap_parse_foreach_cb, (gpointer)cnt_info); + + } else if (GMIME_IS_PART (message1->mime_part)) { + GMimeDataWrapper *content = NULL; + GMimePart *single_part = GMIME_PART(message1->mime_part); + + EM_DEBUG_LOG("constructing a %s/%s part", body_types[body->type], body->subtype); + emcore_gmime_construct_part(single_part, body, "1", &total_mail_size); + + stream1 = g_mime_stream_mem_new_with_buffer(imap_response[i].bodytext, imap_response[i].bodytext_len); + //parser1 = g_mime_parser_new_with_stream(stream1); + content = g_mime_data_wrapper_new_with_stream(stream1, single_part->encoding); + if (stream1) g_object_unref (stream1); + + g_mime_part_set_content_object(single_part, content); + if (content) g_object_unref(content); + + sender = g_mime_message_get_sender(message1); + + if (sender) { + if (g_strrstr(sender, "mmsc.plusnet.pl") != NULL || + g_strrstr(sender, "mms.t-mobile.pl") != NULL) { + cnt_info->attachment_only = 1; + } + } + + g_mime_message_foreach(message1, emcore_gmime_imap_parse_foreach_cb, (gpointer)cnt_info); + } + + if (!strcasecmp(body->subtype, "pkcs7-mime")) { + if (emcore_get_attribute_value_of_body_part(body->parameter, "PROTOCOL", rfc822_protocol, TEMP_STRING_LENGTH, false, &err)) { + if (strcasestr(rfc822_protocol, "enveloped-data")) + mail->smime_type = EMAIL_SMIME_ENCRYPTED; + else + mail->smime_type = EMAIL_SMIME_SIGNED_AND_ENCRYPTED; + } + } else if (!strcasecmp(body->subtype, "encrypted")) { + mail->smime_type = EMAIL_PGP_ENCRYPTED; + } else if (!strcasecmp(body->subtype, "signed")) { + if (emcore_get_attribute_value_of_body_part(body->parameter, "MICALG", rfc822_micalg, TEMP_STRING_LENGTH, false, &err)) { + mail->digest_type = emcore_get_digest_type(rfc822_micalg); + } + + if (emcore_get_attribute_value_of_body_part(body->parameter, "PROTOCOL", rfc822_protocol, TEMP_STRING_LENGTH, false, &err)) { + if (strcasestr(rfc822_protocol, "pkcs7-signature")) + mail->smime_type = EMAIL_SMIME_SIGNED; + else + mail->smime_type = EMAIL_PGP_SIGNED; + } + } else { + mail->smime_type = EMAIL_SMIME_NONE; + } + + if (body) { + mail_free_body(&body); + body = NULL; + } + + if (message1) { + g_object_unref(message1); + message1 = NULL; + } + + /* Update the attachment info except inline attachment */ + if ((err = emcore_update_attachment_except_inline(cnt_info, pbd_event[temp_count].account_id, + mail->mail_id, pbd_event[temp_count].mailbox_id, &total_attachment_size, + &attachment_num, &inline_attachment_num)) != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emcore_update_attachment_except_inline failed : [%d]", err); + goto FINISH_OFF; + } + + mail->mail_size = total_mail_size; + mail->attachment_count = attachment_num; + mail->inline_content_count = inline_attachment_num; + + if (imap_response[i].bodytext_len == 0) { + EM_DEBUG_LOG("BODY size is zero"); + continue; + } + + /* text/plain */ + if (cnt_info->text.plain) { + char *charset_plain_text = NULL; + memset(buf, 0x00, sizeof(buf)); + + if (cnt_info->text.plain_charset) + charset_plain_text = cnt_info->text.plain_charset; + else { + if (mail->default_charset) { + charset_plain_text = mail->default_charset; + } else { + charset_plain_text = "UTF-8"; + } + } + + if (!emstorage_create_dir(pbd_event[temp_count].account_id, mail->mail_id, 0, &err)) + EM_DEBUG_EXCEPTION("emstorage_create_dir failed [%d]", err); + + if (!emstorage_get_save_name(pbd_event[temp_count].account_id, mail->mail_id, 0, charset_plain_text, buf, sizeof(buf), &err)) + EM_DEBUG_EXCEPTION("emstorage_get_save_name failed [%d]", err); + + if (!emstorage_move_file(cnt_info->text.plain, buf, false, &err)) { + EM_DEBUG_EXCEPTION("emstorage_move_file failed [%d]", err); + mail->file_path_plain = NULL; + } + else + mail->file_path_plain = EM_SAFE_STRDUP(buf); + EM_DEBUG_LOG_SEC("mail->file_path_plain [%s]", mail->file_path_plain); + } + + /* text/html */ + if (cnt_info->text.html) { + char *charset_html_text = NULL; + memset(buf, 0x00, sizeof(buf)); + + if (cnt_info->text.html_charset) + charset_html_text = cnt_info->text.html_charset; + else { + if (mail->default_charset) { + charset_html_text = mail->default_charset; + } else { + charset_html_text = "UTF-8"; + } + } + + charset_html_text = g_strconcat(charset_html_text, HTML_EXTENSION_STRING, NULL); + + if (!emstorage_create_dir(pbd_event[temp_count].account_id, mail->mail_id, 0, &err)) + EM_DEBUG_EXCEPTION("emstorage_create_dir failed [%d]", err); + + if (!emstorage_get_save_name(pbd_event[temp_count].account_id, mail->mail_id, 0, charset_html_text, buf, sizeof(buf), &err)) + EM_DEBUG_EXCEPTION("emstorage_get_save_name failed [%d]", err); + + if (!emstorage_move_file(cnt_info->text.html, buf, false, &err)) { + EM_DEBUG_EXCEPTION("emstorage_move_file failed [%d]", err); + mail->file_path_html = NULL; + } + else + mail->file_path_html = EM_SAFE_STRDUP(buf); + g_free(charset_html_text); + } + + /* inline attachment */ + inline_download_count = 0; + if (cnt_info->inline_file) { + struct attachment_info *temp_file = NULL; + + if (inline_attachment_num > 0) { + temp_file = cnt_info->inline_file; + while (temp_file) { + if (temp_file->type == INLINE_ATTACHMENT && temp_file->save_status == 1) { + inline_download_count++; + memset(buf, 0x00, sizeof(buf)); + + if (!emstorage_create_dir(pbd_event[temp_count].account_id, mail->mail_id, 0, &err)) + EM_DEBUG_EXCEPTION("emstorage_create_dir failed [%d]", err); + + if (!emstorage_get_save_name(pbd_event[temp_count].account_id, mail->mail_id, 0, temp_file->name, buf, sizeof(buf), &err)) + EM_DEBUG_EXCEPTION("emstorage_get_save_name failed [%d]", err); + + if (!emstorage_move_file(temp_file->save, buf, false, &err)) { + EM_DEBUG_EXCEPTION("emstorage_move_file failed [%d]", err); + goto FINISH_OFF; + } + + if (!(mail->body_download_status & EMAIL_BODY_DOWNLOAD_STATUS_PARTIALLY_DOWNLOADED)) { + memset(&attachment_tbl, 0x00, sizeof(emstorage_attachment_tbl_t)); + attachment_tbl.mail_id = mail->mail_id; + attachment_tbl.account_id = pbd_event[temp_count].account_id; + attachment_tbl.mailbox_id = pbd_event[temp_count].mailbox_id; + attachment_tbl.attachment_name = temp_file->name; + attachment_tbl.attachment_size = temp_file->size; + attachment_tbl.attachment_path = buf; + attachment_tbl.attachment_save_status = 1; + attachment_tbl.attachment_inline_content_status = 1; /* set to 1 for inline image */ + attachment_tbl.attachment_mime_type = temp_file->attachment_mime_type; + attachment_tbl.content_id = temp_file->content_id; + EM_DEBUG_LOG("mime_type : [%s]", temp_file->attachment_mime_type); + if (!emstorage_add_attachment(&attachment_tbl, false, false, &err)) + EM_DEBUG_EXCEPTION("emstorage_add_attachment failed - %d", err); + } + } + else { + if (temp_file->save) + g_remove(temp_file->save); + } + temp_file = temp_file->next; + } + } + } + + mail->body_download_status = (mail->body_download_status & ~0x00000003) | (( (total_mail_size - total_attachment_size <= input_download_size) && (inline_download_count == inline_attachment_num))? + EMAIL_BODY_DOWNLOAD_STATUS_FULLY_DOWNLOADED: EMAIL_BODY_DOWNLOAD_STATUS_PARTIALLY_DOWNLOADED); + + EM_DEBUG_LOG("inline_download_count[%d] inline_attachment_num[%d]", inline_download_count, inline_attachment_num); + EM_DEBUG_LOG("total_mail_size[%d] total_attachment_size[%d] input_download_size[%d]", total_mail_size, total_attachment_size, input_download_size); + EM_DEBUG_LOG("mail_id [%d] body_download_status [%d]", mail->mail_id, mail->body_download_status); + + /* Get preview text */ + if ( (err = emcore_get_preview_text_from_file(mail->file_path_plain, + mail->file_path_html, MAX_PREVIEW_TEXT_LENGTH, &(mail->preview_text))) != EMAIL_ERROR_NONE) + EM_DEBUG_EXCEPTION("emcore_get_preview_text_from_file() failed[%d]", err); + + /* Update body contents */ + if (!emstorage_change_mail_field(mail->mail_id, UPDATE_PARTIAL_BODY_DOWNLOAD, mail, true, &err)) { + EM_DEBUG_EXCEPTION("emstorage_change_mail_field failed - %d", err); + goto FINISH_OFF; + } + +#ifdef __FEATURE_BODY_SEARCH__ + /* strip html content and save into mail_text_tbl */ + char *stripped_text = NULL; + if (!emcore_strip_mail_body_from_file(mail, &stripped_text, &err) || stripped_text == NULL) { + EM_DEBUG_EXCEPTION("emcore_strip_mail_body_from_file failed [%d]", err); + } + + if (!emstorage_get_mail_text_by_id(mail->mail_id, &mail_text, true, &err) || !mail_text) { + EM_DEBUG_EXCEPTION("emstorage_get_mail_text_by_id failed [%d]", err); + goto FINISH_OFF; + } + + EM_SAFE_FREE(mail_text->body_text); + mail_text->body_text = stripped_text; + if (!emstorage_change_mail_text_field(mail->mail_id, mail_text, false, &err)) { + EM_DEBUG_EXCEPTION("emstorage_change_mail_text_field failed [%d]", err); + goto FINISH_OFF; + } + + if (mail_text) + emstorage_free_mail_text(&mail_text, 1, NULL); +#endif + + if (mail) + emstorage_free_mail(&mail, 1, NULL); + + if (false == emcore_delete_pbd_activity(pbd_event[temp_count].account_id, pbd_event[temp_count].mail_id, pbd_event[temp_count].activity_id, &err)){ + EM_DEBUG_EXCEPTION("emcore_delete_pbd_activity failed [%d]", err); + goto FINISH_OFF; + } + } + + ret = true; + +FINISH_OFF: + + if (error) + *error = err; + + if (true != ret) + EM_DEBUG_EXCEPTION("Failed download for the uid list %s", command); + + if(reply_from_server) { + EM_SAFE_FREE(reply_from_server->key); + EM_SAFE_FREE(reply_from_server->line); + EM_SAFE_FREE(reply_from_server->tag); + EM_SAFE_FREE(reply_from_server->text); + EM_SAFE_FREE(reply_from_server); + } + + if (message1) { + g_object_unref(message1); + message1 = NULL; + } + + if (message2) { + g_object_unref(message2); + message2 = NULL; + } + + if (iter1) { + g_mime_part_iter_free(iter1); + iter1 = NULL; + } + + if (iter2) { + g_mime_part_iter_free(iter2); + iter2 = NULL; + } + + if (cnt_info) { + emcore_free_content_info(cnt_info); + EM_SAFE_FREE(cnt_info); + } + + EM_SAFE_FREE(fulltext); + + if (body) + mail_free_body(&body); + + if (mail) + emstorage_free_mail(&mail, 1, NULL); + + if (mail_text) + emstorage_free_mail_text(&mail_text, 1, NULL); + + if (imap_response) + emcore_free_email_partial_buffer(&imap_response, item_count); + + EM_SAFE_FREE(bodystructure_ptr); + + EM_DEBUG_FUNC_END("ret [%d]", ret); + return ret; +} + static int emcore_download_bulk_partial_mail_body_for_imap(MAILSTREAM *stream, int input_download_size, email_event_partial_body_thd *pbd_event, int item_count, int *error) { EM_DEBUG_FUNC_BEGIN("stream [%p], input_download_size[%d], pbd_event [%p], item_count [%d], error [%p]", stream, input_download_size, pbd_event, item_count, error); @@ -3927,8 +5050,7 @@ static int emcore_download_bulk_partial_mail_body_for_imap(MAILSTREAM *stream, i /* 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_SEC("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); + /* delete log before uploading master branch. it is flooding */ if (i32_index >= UID_RANGE_STRING_LENGTH){ EM_DEBUG_EXCEPTION("String length exceeded its limitation!"); @@ -3936,9 +5058,9 @@ static int emcore_download_bulk_partial_mail_body_for_imap(MAILSTREAM *stream, i } 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); + i32_index += SNPRINTF(uid_range_string_to_be_downloaded + i32_index, UID_RANGE_STRING_LENGTH - i32_index, "%lu", stSectionNo[j].server_mail_id); else - i32_index += SNPRINTF(uid_range_string_to_be_downloaded + i32_index, UID_RANGE_STRING_LENGTH, "%lu,", stSectionNo[j].server_mail_id); + i32_index += SNPRINTF(uid_range_string_to_be_downloaded + i32_index, UID_RANGE_STRING_LENGTH - i32_index, "%lu,", stSectionNo[j].server_mail_id); } SNPRINTF(imap_tag, TAG_LENGTH, "%08lx", 0xffffffff & (stream->gensym++)); @@ -3958,9 +5080,6 @@ static int emcore_download_bulk_partial_mail_body_for_imap(MAILSTREAM *stream, i if (!imap_response || !reply_from_server ){ EM_DEBUG_EXCEPTION(" Invalid response from emcore_get_response_from_server"); - for( i = 0 ; i< item_count ; i++ ) - emcore_delete_pbd_activity(pbd_event[i].account_id, pbd_event[i].mail_id, pbd_event[i].activity_id, &err); - goto FINISH_OFF; } @@ -3969,7 +5088,7 @@ static int emcore_download_bulk_partial_mail_body_for_imap(MAILSTREAM *stream, i total_attachment_size = 0; attachment_num = 0; - if( !(imap_response[i].header) ) continue; + if( !(imap_response[i].bodystructure) ) continue; if (body) { mail_free_body(&body); @@ -3981,7 +5100,7 @@ static int emcore_download_bulk_partial_mail_body_for_imap(MAILSTREAM *stream, i EM_SAFE_FREE(cnt_info); } - err = emcore_parse_bodystructure(stream, reply_from_server, imap_response[i].header, &body, &cnt_info, &total_mail_size); + err = emcore_parse_bodystructure(stream, reply_from_server, imap_response[i].bodystructure, &body, &cnt_info, &total_mail_size); if (err != EMAIL_ERROR_NONE || !body) { EM_DEBUG_EXCEPTION("emcore_parse_bodystructure failed : [%d]", err); err = EMAIL_ERROR_ON_PARSING; @@ -4008,7 +5127,7 @@ static int emcore_download_bulk_partial_mail_body_for_imap(MAILSTREAM *stream, i goto FINISH_OFF; } - if (mail->body_download_status == EMAIL_BODY_DOWNLOAD_STATUS_FULLY_DOWNLOADED) { + if (mail->body_download_status & EMAIL_BODY_DOWNLOAD_STATUS_FULLY_DOWNLOADED) { EM_DEBUG_LOG("Downloaded mail"); continue; } @@ -4019,36 +5138,47 @@ static int emcore_download_bulk_partial_mail_body_for_imap(MAILSTREAM *stream, i goto FINISH_OFF; } - EM_DEBUG_LOG("total_mail_size:[%d], total_attachment_size:[%d], attachment_num:[%d]", total_mail_size, total_attachment_size, attachment_num); + mail->mail_size = total_mail_size; mail->attachment_count = attachment_num; mail->inline_content_count = inline_attachment_num; - if (imap_response[i].body_len == 0) { + if (imap_response[i].bodytext_len == 0) { EM_DEBUG_LOG("BODY size is zero"); continue; } /*free the plain, html, and image_data before reusing*/ - if (image_data) + if (image_data) emcore_free_email_image_data(&image_data, IMAGE_DISPLAY_PARTIAL_BODY_COUNT); EM_SAFE_FREE(text_plain); EM_SAFE_FREE(text_html); - if ((err = emcore_parse_body_for_imap(imap_response[i].body, imap_response[i].body_len, cnt_info, body->encoding, &text_plain, &text_html, &image_data)) != EMAIL_ERROR_NONE) { + if ((err = emcore_parse_body_for_imap(imap_response[i].bodytext, imap_response[i].bodytext_len, cnt_info, body->encoding, &text_plain, &text_html, &image_data)) != EMAIL_ERROR_NONE) { EM_DEBUG_EXCEPTION("emcore_parse_body_for_imap failed"); goto FINISH_OFF; } int text_plain_len = EM_SAFE_STRLEN(text_plain); if (text_plain_len > 0) { + char *charset_plain_text = NULL; memset(buf, 0x00, sizeof(buf)); + if (cnt_info->text.plain_charset) + charset_plain_text = cnt_info->text.plain_charset; + else { + if (mail->default_charset) { + charset_plain_text = mail->default_charset; + } else { + charset_plain_text = "UTF-8"; + } + } + if (!emstorage_create_dir(pbd_event[temp_count].account_id, mail->mail_id, 0, &err)) EM_DEBUG_EXCEPTION("emstorage_create_dir failed [%d]", err); - if (!emstorage_get_save_name(pbd_event[temp_count].account_id, mail->mail_id, 0, cnt_info->text.plain_charset ? cnt_info->text.plain_charset : "UTF-8", buf, &err)) + if (!emstorage_get_save_name(pbd_event[temp_count].account_id, mail->mail_id, 0, charset_plain_text, buf, sizeof(buf), &err)) EM_DEBUG_EXCEPTION("emstorage_get_save_name failed [%d]", err); if (!emstorage_create_file(text_plain, text_plain_len, buf, &err)) @@ -4063,7 +5193,7 @@ static int emcore_download_bulk_partial_mail_body_for_imap(MAILSTREAM *stream, i int store_file = 0; int content_index = 0; - temp_data_html = em_malloc(imap_response[i].body_len + 1); + temp_data_html = em_malloc(imap_response[i].bodytext_len + 1); if(!temp_data_html) { EM_DEBUG_EXCEPTION("em_malloc failed"); err = EMAIL_ERROR_OUT_OF_MEMORY; @@ -4080,14 +5210,14 @@ static int emcore_download_bulk_partial_mail_body_for_imap(MAILSTREAM *stream, i if (!emstorage_create_dir(pbd_event[temp_count].account_id, mail->mail_id, 0, &err)) EM_DEBUG_EXCEPTION("emstorage_create_dir failed [%d]", err); - if (!emstorage_get_save_name(pbd_event[temp_count].account_id, mail->mail_id, 0, image_data[store_file].image_file_name, buf, &err)) + if (!emstorage_get_save_name(pbd_event[temp_count].account_id, mail->mail_id, 0, image_data[store_file].image_file_name, buf, sizeof(buf), &err)) EM_DEBUG_EXCEPTION("emstorage_get_save_name failed [%d]", err); if (image_data[store_file].dec_len>0) if (!emstorage_create_file(image_data[store_file].text_image, image_data[store_file].dec_len, buf, &err)) EM_DEBUG_EXCEPTION("emstorage_create_file failed [%d]", err); - if (mail->body_download_status != EMAIL_BODY_DOWNLOAD_STATUS_PARTIALLY_DOWNLOADED){ + if (!(mail->body_download_status & EMAIL_BODY_DOWNLOAD_STATUS_PARTIALLY_DOWNLOADED)){ memset(&attachment_tbl, 0x00, sizeof(emstorage_attachment_tbl_t)); attachment_tbl.mail_id = mail->mail_id; attachment_tbl.account_id = pbd_event[temp_count].account_id; @@ -4098,6 +5228,7 @@ static int emcore_download_bulk_partial_mail_body_for_imap(MAILSTREAM *stream, i attachment_tbl.attachment_save_status = 1; attachment_tbl.attachment_inline_content_status = 1; /* set to 1 for inline image */ attachment_tbl.attachment_mime_type = image_data[store_file].mime_type; + attachment_tbl.content_id = image_data[store_file].content_id; EM_DEBUG_LOG("mime_type : [%s]", image_data[store_file].mime_type); if (!emstorage_add_attachment (&attachment_tbl, false, false, &err)) EM_DEBUG_EXCEPTION("emstorage_add_attachment failed - %d", err); @@ -4113,7 +5244,7 @@ static int emcore_download_bulk_partial_mail_body_for_imap(MAILSTREAM *stream, i if(image_data[content_index].fully_downloaded == 1) { result_string_of_replacing = em_replace_string((char *)temp_data_html, (char *)image_data[content_index].content_id, (char *)image_data[content_index].image_file_name); if (result_string_of_replacing) { - memset(temp_data_html, 0x00, imap_response[i].body_len + 1); + memset(temp_data_html, 0x00, imap_response[i].bodytext_len + 1); strncpy(temp_data_html, result_string_of_replacing, strlen(result_string_of_replacing)); EM_SAFE_FREE (result_string_of_replacing); } @@ -4124,7 +5255,7 @@ static int emcore_download_bulk_partial_mail_body_for_imap(MAILSTREAM *stream, i content_index++; } - memset(text_html, 0, imap_response[i].body_len + 1); + memset(text_html, 0, imap_response[i].bodytext_len + 1); if (temp_data_html != NULL) memcpy(text_html, temp_data_html, EM_SAFE_STRLEN(temp_data_html)); @@ -4149,7 +5280,7 @@ static int emcore_download_bulk_partial_mail_body_for_imap(MAILSTREAM *stream, i if (!emstorage_create_dir(pbd_event[temp_count].account_id, mail->mail_id, 0, &err)) EM_DEBUG_EXCEPTION("emstorage_create_dir failed [%d]", err); - if (!emstorage_get_save_name(pbd_event[temp_count].account_id, mail->mail_id, 0, html_body, buf, &err)) + if (!emstorage_get_save_name(pbd_event[temp_count].account_id, mail->mail_id, 0, html_body, buf, sizeof(buf), &err)) EM_DEBUG_EXCEPTION("emstorage_get_save_name failed [%d]", err); int text_html_len = EM_SAFE_STRLEN(text_html); @@ -4161,7 +5292,7 @@ static int emcore_download_bulk_partial_mail_body_for_imap(MAILSTREAM *stream, i } - mail->body_download_status = (total_mail_size - total_attachment_size < input_download_size) ? 1 : 2; + mail->body_download_status = (mail->body_download_status & ~0x00000003) | ((total_mail_size - total_attachment_size < input_download_size) ? 1 : 2); EM_DEBUG_LOG("total_mail_size[%d] total_attachment_size[%d] input_download_size[%d]", total_mail_size, total_attachment_size, input_download_size); EM_DEBUG_LOG("mail_id [%d] body_download_status [%d]", mail->mail_id, mail->body_download_status); @@ -4266,10 +5397,26 @@ INTERNAL_FUNC int emcore_download_bulk_partial_mail_body_for_pop3(MAILSTREAM *st EM_DEBUG_LOG_SEC("pbd_event[%d].account_id [%d], mail_id [%d], server_mail_id [%d], activity_id [%d]", \ i, pbd_event[i].account_id, pbd_event[i].mail_id, pbd_event[i].server_mail_id, pbd_event[i].activity_id); - if (!emcore_download_body_multi_sections_bulk(stream, pbd_event[i].account_id, pbd_event[i].mail_id, false, false, input_download_size, 0 , &err)){ +#ifdef __FEATURE_USE_GMIME__ + if (!emcore_gmime_download_body_sections(stream, pbd_event[i].account_id, + pbd_event[i].mail_id, 0, input_download_size, -1, 0, 0, &err)) { + EM_DEBUG_EXCEPTION("emcore_gmime_download_body_sections failed - %d", err); + goto FINISH_OFF; + } +#else + if (!emcore_download_body_multi_sections_bulk (stream, + pbd_event[i].account_id, + pbd_event[i].mail_id, + false, + false, + input_download_size, + -1, + 0, + &err)) { EM_DEBUG_EXCEPTION("emcore_download_body_multi_sections_bulk failed"); goto FINISH_OFF; } +#endif if (false == emcore_delete_pbd_activity(pbd_event[i].account_id, pbd_event[i].mail_id, pbd_event[i].activity_id, &err)){ EM_DEBUG_EXCEPTION("emcore_delete_pbd_activity failed [%d]", err); @@ -4311,11 +5458,17 @@ INTERNAL_FUNC int emcore_download_bulk_partial_mail_body(MAILSTREAM *stream, ema switch (pbd_account_tbl->incoming_server_type){ case EMAIL_SERVER_TYPE_IMAP4: +#ifdef __FEATURE_USE_GMIME__ + ret = emcore_gmime_download_imap_partial_mail_body(stream, auto_download_size, pbd_event, item_count, &err); +#else ret = emcore_download_bulk_partial_mail_body_for_imap(stream, auto_download_size, pbd_event, item_count, &err); +#endif break; + case EMAIL_SERVER_TYPE_POP3: ret = emcore_download_bulk_partial_mail_body_for_pop3(stream, auto_download_size, pbd_event, item_count, &err); break; + default: err = EMAIL_ERROR_NOT_SUPPORTED; ret = false; @@ -4345,8 +5498,9 @@ static void emcore_free_email_partial_buffer(email_partial_buffer **partial_buff int i; for (i = 0; i < item_count ; i++, p++) { - EM_SAFE_FREE(p->header); - EM_SAFE_FREE(p->body); + EM_SAFE_FREE(p->bodystructure); + EM_SAFE_FREE(p->bodytext); + EM_SAFE_FREE(p->rfc822header); } EM_SAFE_FREE(*partial_buffer); @@ -4369,6 +5523,7 @@ static email_partial_buffer *emcore_get_response_from_server (NETSTREAM *nstream char *full_line = NULL; char *tmp = NULL; + int rfc822header_size = 0; int body_size = 0; int count = 0; int ret = false; @@ -4377,6 +5532,7 @@ static email_partial_buffer *emcore_get_response_from_server (NETSTREAM *nstream char *p_bodystructure = NULL; char *p_bodystructure_end = NULL; char *p_body_text = NULL; + char *p_rfc822header = NULL; server_response = (email_partial_buffer *)em_malloc(sizeof(email_partial_buffer) * item_count); if (NULL == server_response) { @@ -4401,6 +5557,27 @@ static email_partial_buffer *emcore_get_response_from_server (NETSTREAM *nstream EM_SAFE_FREE(cur_line); EM_SAFE_FREE(tmp); + p_rfc822header = strcasestr(full_line, "RFC822.HEADER {"); + if (p_rfc822header && server_response[count].rfc822header == NULL) { + p_rfc822header += strlen("RFC822.HEADER {"); + rfc822header_size = atoi(p_rfc822header); + + server_response[count].rfc822header_len = rfc822header_size; + server_response[count].rfc822header = em_malloc(server_response[count].rfc822header_len + 1); + if (server_response[count].rfc822header == NULL) { + EM_DEBUG_EXCEPTION("em_malloc failed"); + goto FINISH_OFF; + } + + if (net_getbuffer(nstream, server_response[count].rfc822header_len, server_response[count].rfc822header) <= 0) { + EM_DEBUG_EXCEPTION("net_getbuffer failed"); + goto FINISH_OFF; + } + + p_rfc822header = NULL; + continue; + } + p_bodystructure = strcasestr(full_line, "BODYSTRUCTURE"); p_bodystructure_end = strcasestr(full_line, "BODY[TEXT]"); @@ -4414,13 +5591,13 @@ static email_partial_buffer *emcore_get_response_from_server (NETSTREAM *nstream } /* get BODYSTRUCTURE */ - server_response[count].header_len = p_bodystructure_end - p_bodystructure; - server_response[count].header = em_malloc(server_response[count].header_len + 1); - if (server_response[count].header == NULL) { + server_response[count].bodystructure_len = p_bodystructure_end - p_bodystructure; + server_response[count].bodystructure = em_malloc(server_response[count].bodystructure_len + 1); + if (server_response[count].bodystructure == NULL) { EM_DEBUG_EXCEPTION("em_malloc failed"); goto FINISH_OFF; } - SNPRINTF(server_response[count].header, server_response[count].header_len, "%s", p_bodystructure); + SNPRINTF(server_response[count].bodystructure, server_response[count].bodystructure_len, "%s", p_bodystructure); /*EM_DEBUG_LOG("BODYSTRUCTURE(%d)[%s]", server_response[count].header_len, server_response[count].header);*/ /* get BODY size & text */ @@ -4432,14 +5609,14 @@ static email_partial_buffer *emcore_get_response_from_server (NETSTREAM *nstream p_body_text += strlen("BODY[TEXT]<0> {"); body_size = atoi(p_body_text); - server_response[count].body_len = (body_size > input_download_size) ? input_download_size : body_size; - server_response[count].body = em_malloc(server_response[count].body_len + 1); - if (server_response[count].body == NULL) { + server_response[count].bodytext_len = (body_size > input_download_size) ? input_download_size : body_size; + server_response[count].bodytext = em_malloc(server_response[count].bodytext_len + 1); + if (server_response[count].bodytext == NULL) { EM_DEBUG_EXCEPTION("em_malloc failed"); goto FINISH_OFF; } - if (net_getbuffer(nstream, server_response[count].body_len, server_response[count].body) <= 0) { + if (net_getbuffer(nstream, server_response[count].bodytext_len, server_response[count].bodytext) <= 0) { EM_DEBUG_EXCEPTION("net_getbuffer failed"); goto FINISH_OFF; } diff --git a/email-core/email-core-mailbox.c b/email-core/email-core-mailbox.c index 9525bcd..ca7c6c4 100755 --- a/email-core/email-core-mailbox.c +++ b/email-core/email-core-mailbox.c @@ -4,7 +4,7 @@ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> -* +* * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -24,7 +24,7 @@ * File : email-core-mailbox.c * Desc : Local Mailbox Management * - * Auth : + * Auth : * *****************************************************************************/ #include <stdio.h> @@ -32,6 +32,7 @@ #include <string.h> #include <time.h> #include <sys/types.h> + #include "email-types.h" #include "email-utilities.h" #include "email-convert.h" @@ -42,9 +43,11 @@ #include "email-core-event.h" #include "email-network.h" #include "email-core-mail.h" -#include "email-core-imap-mailbox.h" +#include "email-core-imap-mailbox.h" #include "email-storage.h" -#include "email-core-account.h" +#include "email-core-account.h" + +#include "imap4r1.h" #ifdef __FEATURE_KEEP_CONNECTION__ static void *g_receiving_thd_stream = NULL; /* Stores the recv thd stream for next time reuse */ @@ -59,26 +62,36 @@ __thread email_connection_info_t *g_connection_info_list = NULL; static pthread_mutex_t _close_stream_lock = PTHREAD_MUTEX_INITIALIZER; /* Mutex to protect closing stream */ #endif /* __FEATURE_KEEP_CONNECTION__ */ +int emcore_imap4_send_command(MAILSTREAM *stream, imap4_cmd_t cmd_type, int *err_code); +int emcore_pop3_send_command(MAILSTREAM *stream, pop3_cmd_t cmd_type, int *err_code); + +/* thread local variable for stream reuse */ +__thread GList* g_recv_stream_list = NULL; +typedef struct { + int account_id; + int mailbox_id; + MAILSTREAM **mail_stream; +} email_recv_stream_list_t; /* Binding IMAP mailbox with its function */ static email_mailbox_type_item_t g_mailbox_type[MAX_MAILBOX_TYPE] = { {EMAIL_MAILBOX_TYPE_INBOX, "INBOX" }, /* Naver */ {EMAIL_MAILBOX_TYPE_INBOX, "Inbox" }, - {EMAIL_MAILBOX_TYPE_SENTBOX, "Sent Messages"} , - {EMAIL_MAILBOX_TYPE_SPAMBOX, "&wqTTOLpUx3zVaA-"} , + {EMAIL_MAILBOX_TYPE_SENTBOX, "Sent Messages"} , + {EMAIL_MAILBOX_TYPE_SPAMBOX, "&wqTTOLpUx3zVaA-"} , {EMAIL_MAILBOX_TYPE_DRAFT, "Drafts"} , {EMAIL_MAILBOX_TYPE_TRASH, "Deleted Messages" } , /* AOL */ - {EMAIL_MAILBOX_TYPE_SENTBOX, "Sent"} , - {EMAIL_MAILBOX_TYPE_SPAMBOX, "Spam" }, + {EMAIL_MAILBOX_TYPE_SENTBOX, "Sent"} , + {EMAIL_MAILBOX_TYPE_SPAMBOX, "Spam" }, {EMAIL_MAILBOX_TYPE_DRAFT, "Drafts"} , {EMAIL_MAILBOX_TYPE_TRASH, "Trash"}, /* DAUM */ {EMAIL_MAILBOX_TYPE_SPAMBOX, "&wqTTONO4ycDVaA-"}, /* ETC */ - {EMAIL_MAILBOX_TYPE_SENTBOX, "mail/sent-mail"}, - {EMAIL_MAILBOX_TYPE_SPAMBOX, "mail/spam-mail" }, + {EMAIL_MAILBOX_TYPE_SENTBOX, "mail/sent-mail"}, + {EMAIL_MAILBOX_TYPE_SPAMBOX, "mail/spam-mail" }, {EMAIL_MAILBOX_TYPE_DRAFT, "mail/saved-drafts"} , {EMAIL_MAILBOX_TYPE_TRASH, "mail/mail-trash"}, }; @@ -94,7 +107,7 @@ email_connection_info_t* emcore_get_connection_info_by_account_id(int account_id break; connection_info = connection_info->next; } - + EM_DEBUG_FUNC_END("connection_info [%p]", connection_info); return connection_info; } @@ -127,7 +140,7 @@ int emcore_append_connection_info(email_connection_info_t *new_connection_info) new_connection_info->next = NULL; g_connection_info_list = new_connection_info; } - + EM_DEBUG_FUNC_END("EMAIL_ERROR_NONE"); return EMAIL_ERROR_NONE; } @@ -151,7 +164,7 @@ INTERNAL_FUNC int emcore_remove_connection_info(int account_id) prev_connection_info = connection_info; connection_info = connection_info->next; } - + EM_DEBUG_FUNC_END(""); return EMAIL_ERROR_NONE; } @@ -159,49 +172,170 @@ INTERNAL_FUNC int emcore_remove_connection_info(int account_id) #endif /* __FEATURE_KEEP_CONNECTION__ */ +INTERNAL_FUNC void emcore_close_recv_stream_list (void) +{ + EM_DEBUG_FUNC_BEGIN(); + GList* cur = g_recv_stream_list; + email_recv_stream_list_t* data = NULL; + + while(cur) { + data = cur->data; + if(data) *(data->mail_stream) = mail_close (*(data->mail_stream)); + g_recv_stream_list = g_list_delete_link (g_recv_stream_list, cur); + g_free (data); + cur = g_recv_stream_list; + } + + EM_DEBUG_FUNC_END(); +} + +INTERNAL_FUNC MAILSTREAM** emcore_get_recv_stream (int account_id, int mailbox_id, int *error) +{ + EM_DEBUG_FUNC_BEGIN("account_id[%d]", account_id); + GList* cur = g_recv_stream_list; + email_recv_stream_list_t* data = NULL; + MAILSTREAM** ret = NULL; + int err = EMAIL_ERROR_NONE; + email_account_t *ref_account = NULL; + + if (!(ref_account = emcore_get_account_reference(account_id))) { + EM_DEBUG_EXCEPTION("emcore_get_account_reference failed [%d]", account_id); + err = EMAIL_ERROR_INVALID_ACCOUNT; + goto FINISH_OFF; + } + + for ( ; cur; cur = g_list_next(cur)) { + data = cur->data; + if (data->account_id == account_id && data->mailbox_id == mailbox_id) { + if (data->mail_stream == NULL || *(data->mail_stream) == NULL) { + EM_DEBUG_LOG ("mail_stream was closed before"); + g_recv_stream_list = g_list_delete_link (g_recv_stream_list, cur); + g_free (data); + break; + } + + if (ref_account->incoming_server_type == EMAIL_SERVER_TYPE_IMAP4) { + /* send NOOP command */ + if (!emcore_imap4_send_command(*(data->mail_stream), IMAP4_CMD_NOOP, &err)) { + EM_DEBUG_LOG("imap4_send_command failed [%d]", err); + EM_DEBUG_LOG ("mail_stream is not reusable"); + *(data->mail_stream) = mail_close (*(data->mail_stream)); + g_recv_stream_list = g_list_delete_link (g_recv_stream_list, cur); + g_free (data); + break; + } + else { + EM_DEBUG_LOG ("reusable mail_stream found"); + emcore_free_account(ref_account); /* prevent */ + EM_SAFE_FREE(ref_account); + return data->mail_stream; + } + } + else if (ref_account->incoming_server_type == EMAIL_SERVER_TYPE_POP3) { + /* send NOOP command */ + if (!emcore_pop3_send_command(*(data->mail_stream), POP3_CMD_NOOP, &err)) { + EM_DEBUG_LOG("emcore_pop3_send_command failed [%d]", err); + EM_DEBUG_LOG ("mail_stream is not reusable"); + *(data->mail_stream) = mail_close (*(data->mail_stream)); + g_recv_stream_list = g_list_delete_link (g_recv_stream_list, cur); + g_free (data); + break; + } + else { + EM_DEBUG_LOG ("reusable mail_stream found"); + emcore_free_account(ref_account); /* prevent */ + EM_SAFE_FREE(ref_account); + return data->mail_stream; + } + } + } + } + + ret = em_malloc (sizeof(MAILSTREAM*)); + if (!ret) { + EM_DEBUG_EXCEPTION("em_malloc error"); + goto FINISH_OFF; + } + + if (!emcore_connect_to_remote_mailbox(account_id, mailbox_id, (void **)ret, &err)) { + EM_DEBUG_EXCEPTION("emcore_connect_to_remote_mailbox failed [%d]", err); + EM_SAFE_FREE(ret); + goto FINISH_OFF; + } + + email_recv_stream_list_t *node = em_malloc (sizeof(email_recv_stream_list_t)); + if (!node) { + EM_DEBUG_EXCEPTION ("em_malloc error"); + *ret = mail_close (*ret); + EM_SAFE_FREE(ret); + goto FINISH_OFF; + } + + node->account_id = account_id; + node->mailbox_id = mailbox_id; + node->mail_stream = ret; + + g_recv_stream_list = g_list_prepend (g_recv_stream_list, node); + +FINISH_OFF: + + if (error) + *error = err; + + if (ref_account) { + emcore_free_account(ref_account); + EM_SAFE_FREE(ref_account); + } + + EM_DEBUG_FUNC_END(); + + return ret; +} + + /* description * get local mailbox list */ INTERNAL_FUNC int emcore_get_mailbox_list(int account_id, email_mailbox_t **mailbox_list, int *p_count, int *err_code) { 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 = EMAIL_ERROR_INVALID_PARAM; return false; } - + int ret = false; int error = EMAIL_ERROR_NONE; emstorage_mailbox_tbl_t *local_mailbox_list = NULL; email_account_t *ref_account = NULL; int i, count = 512; - + /* get mailbox list from mailbox table */ - + if (!(ref_account = emcore_get_account_reference(account_id))) { EM_DEBUG_EXCEPTION(" emcore_get_account_reference failed - %d", account_id); error = EMAIL_ERROR_INVALID_ACCOUNT; goto FINISH_OFF; } - - if (!emstorage_get_mailbox_list(ref_account->account_id, EMAIL_MAILBOX_ALL, EMAIL_MAILBOX_SORT_BY_NAME_ASC, &count, &local_mailbox_list, true, &error)) { + + if (!emstorage_get_mailbox_list(ref_account->account_id, EMAIL_MAILBOX_ALL, EMAIL_MAILBOX_SORT_BY_NAME_ASC, &count, &local_mailbox_list, true, &error)) { EM_DEBUG_EXCEPTION(" emstorage_get_mailbox failed - %d", error); - + goto FINISH_OFF; } - + if (count > 0) { if (!(*mailbox_list = em_malloc(sizeof(email_mailbox_t) * count))) { EM_DEBUG_EXCEPTION(" mailloc failed..."); error = EMAIL_ERROR_OUT_OF_MEMORY; goto FINISH_OFF; } - + memset(*mailbox_list, 0x00, (sizeof(email_mailbox_t) * count)); - + for (i = 0; i < count; i++) { em_convert_mailbox_tbl_to_mailbox(local_mailbox_list + i, (*mailbox_list) + i); } @@ -213,7 +347,7 @@ INTERNAL_FUNC int emcore_get_mailbox_list(int account_id, email_mailbox_t **mail ret = true; -FINISH_OFF: +FINISH_OFF: if (local_mailbox_list != NULL) emstorage_free_mailbox(&local_mailbox_list, count, NULL); @@ -221,7 +355,7 @@ FINISH_OFF: emcore_free_account(ref_account); EM_SAFE_FREE(ref_account); } - + if (err_code != NULL) *err_code = error; @@ -235,7 +369,7 @@ FINISH_OFF: int emcore_get_mailbox_list_to_be_sync(int account_id, email_mailbox_t **mailbox_list, int *p_count, int *err_code) { EM_DEBUG_FUNC_BEGIN("account_id[%d], mailbox_list[%p], p_count[%p], err_code[%p]", account_id, mailbox_list, p_count, err_code); - + 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) @@ -249,29 +383,29 @@ int emcore_get_mailbox_list_to_be_sync(int account_id, email_mailbox_t **mailbox emstorage_mailbox_tbl_t *mailbox_tbl_list = NULL; email_account_t *ref_account = NULL; int i, count = 512; - + /* get mailbox list from mailbox table */ if (!(ref_account = emcore_get_account_reference(account_id))) { EM_DEBUG_EXCEPTION("emcore_get_account_reference failed - %d", account_id); error = EMAIL_ERROR_INVALID_ACCOUNT; goto FINISH_OFF; } - - if (!emstorage_get_mailbox_list(ref_account->account_id, 0, EMAIL_MAILBOX_SORT_BY_TYPE_ASC, &count, &mailbox_tbl_list, true, &error)) { + + if (!emstorage_get_mailbox_list(ref_account->account_id, 0, EMAIL_MAILBOX_SORT_BY_TYPE_ASC, &count, &mailbox_tbl_list, true, &error)) { EM_DEBUG_EXCEPTION("emstorage_get_mailbox failed - %d", error); - + goto FINISH_OFF; } - + if (count > 0) { if (!(tmp_mailbox_list = em_malloc(sizeof(email_mailbox_t) * count))) { EM_DEBUG_EXCEPTION("malloc failed..."); error = EMAIL_ERROR_OUT_OF_MEMORY; goto FINISH_OFF; } - + memset(tmp_mailbox_list, 0x00, (sizeof(email_mailbox_t) * count)); - + for (i = 0; i < count; i++) { em_convert_mailbox_tbl_to_mailbox(mailbox_tbl_list + i, tmp_mailbox_list + i); } @@ -280,19 +414,19 @@ int emcore_get_mailbox_list_to_be_sync(int account_id, email_mailbox_t **mailbox tmp_mailbox_list = NULL; *p_count = count; ret = true; - -FINISH_OFF: - + +FINISH_OFF: + *mailbox_list = tmp_mailbox_list; - + if (ref_account) { emcore_free_account(ref_account); EM_SAFE_FREE(ref_account); } - + if (mailbox_tbl_list != NULL) emstorage_free_mailbox(&mailbox_tbl_list, count, NULL); - + if (err_code != NULL) *err_code = error; EM_DEBUG_FUNC_END("error [%d]", error); @@ -302,33 +436,33 @@ FINISH_OFF: INTERNAL_FUNC int emcore_get_mail_count(email_mailbox_t *mailbox, int *total, int *unseen, int *err_code) { EM_DEBUG_FUNC_BEGIN("mailbox[%p], total[%p], unseen[%p], err_code[%p]", mailbox, total, unseen, err_code); - + int ret = false; int err = EMAIL_ERROR_NONE; - + if (!mailbox) { EM_DEBUG_EXCEPTION(" mailbox[%p], total[%p], unseen[%p]", mailbox, total, unseen); err = EMAIL_ERROR_INVALID_PARAM; goto FINISH_OFF; } - + if (!emstorage_get_mail_count(mailbox->account_id, mailbox->mailbox_id, total, unseen, true, &err)) { EM_DEBUG_EXCEPTION(" emstorage_get_mail_count failed - %d", err); goto FINISH_OFF; } - + ret = true; - -FINISH_OFF: + +FINISH_OFF: if (err_code != NULL) *err_code = err; - + return ret; } -INTERNAL_FUNC int emcore_create_mailbox(email_mailbox_t *new_mailbox, int on_server, int *err_code) +INTERNAL_FUNC int emcore_create_mailbox(email_mailbox_t *new_mailbox, int on_server, int server_type, int slot_size, int *err_code) { EM_DEBUG_FUNC_BEGIN("new_mailbox[%p], err_code[%p]", new_mailbox, err_code); int ret = false; @@ -336,22 +470,35 @@ INTERNAL_FUNC int emcore_create_mailbox(email_mailbox_t *new_mailbox, int on_ser emstorage_mailbox_tbl_t *local_mailbox = NULL; email_account_t *account_ref = NULL; char *enc_mailbox_name = NULL; - + int incomming_server_type = 0; + int mail_slot_size = 25; + if (new_mailbox == NULL || new_mailbox->mailbox_name == NULL) { err = EMAIL_ERROR_INVALID_PARAM; goto FINISH_OFF; } - account_ref = emcore_get_account_reference(new_mailbox->account_id); - if (!account_ref) { - EM_DEBUG_EXCEPTION("Invalid account_id [%d]", new_mailbox->account_id); - err = EMAIL_ERROR_INVALID_ACCOUNT; - goto FINISH_OFF; + if (server_type > 0 && slot_size > 0) { + incomming_server_type = server_type; + mail_slot_size = slot_size; } + else { + account_ref = emcore_get_account_reference(new_mailbox->account_id); + if (!account_ref) { + EM_DEBUG_EXCEPTION("Invalid account_id [%d]", new_mailbox->account_id); + err = EMAIL_ERROR_INVALID_ACCOUNT; + goto FINISH_OFF; + } + + incomming_server_type = account_ref->incoming_server_type; + mail_slot_size = account_ref->default_mail_slot_size; + emcore_free_account(account_ref); + EM_SAFE_FREE(account_ref); + } /* converting UTF-8 to UTF-7 except EAS */ - if (account_ref->incoming_server_type != EMAIL_SERVER_TYPE_ACTIVE_SYNC) { + if (incomming_server_type != EMAIL_SERVER_TYPE_ACTIVE_SYNC) { if (!emcore_get_encoded_mailbox_name(new_mailbox->mailbox_name, &enc_mailbox_name, &err)) { EM_DEBUG_EXCEPTION("emcore_get_encoded_mailbox_name failed [%d]", err); goto FINISH_OFF; @@ -379,7 +526,7 @@ INTERNAL_FUNC int emcore_create_mailbox(email_mailbox_t *new_mailbox, int on_ser em_convert_mailbox_to_mailbox_tbl(new_mailbox, local_mailbox); - emcore_get_default_mail_slot_count(local_mailbox->account_id, &(local_mailbox->mail_slot_size)); + local_mailbox->mail_slot_size = mail_slot_size; if (!emstorage_add_mailbox(local_mailbox, true, &err)) { EM_DEBUG_EXCEPTION("emstorage_add_mailbox failed [%d]", err); @@ -396,9 +543,6 @@ FINISH_OFF: if (err_code) *err_code = err; - - emcore_free_account(account_ref); - EM_SAFE_FREE(account_ref); return ret; } @@ -406,7 +550,7 @@ FINISH_OFF: INTERNAL_FUNC int emcore_delete_mailbox(int input_mailbox_id, int input_on_server, int input_recursive) { EM_DEBUG_FUNC_BEGIN("input_mailbox_id[%d] input_on_server[%d] input_recursive[%d]", input_mailbox_id, input_on_server, input_recursive); - + int err = EMAIL_ERROR_NONE; int i = 0; int mailbox_count = 0; @@ -418,7 +562,7 @@ INTERNAL_FUNC int emcore_delete_mailbox(int input_mailbox_id, int input_on_serve err = EMAIL_ERROR_INVALID_PARAM; goto FINISH_OFF; } - + if ((err = emstorage_get_mailbox_by_id(input_mailbox_id, &target_mailbox)) != EMAIL_ERROR_NONE || !target_mailbox) { EM_DEBUG_EXCEPTION("emstorage_get_mailbox_by_id failed. [%d]", err); goto FINISH_OFF; @@ -433,7 +577,7 @@ INTERNAL_FUNC int emcore_delete_mailbox(int input_mailbox_id, int input_on_serve } if (target_mailbox) - emstorage_free_mailbox(&target_mailbox, 1, NULL); + emstorage_free_mailbox(&target_mailbox, 1, NULL); target_mailbox = NULL; } else @@ -449,8 +593,10 @@ INTERNAL_FUNC int emcore_delete_mailbox(int input_mailbox_id, int input_on_serve EM_DEBUG_LOG("Deleting mailbox_id [%d]", target_mailbox_array[i].mailbox_id); if (input_on_server) { EM_DEBUG_LOG("Delete the mailbox in Sever >>> "); - if (!emcore_delete_imap_mailbox(target_mailbox_array[i].mailbox_id, &err)) + if (!emcore_delete_imap_mailbox(target_mailbox_array[i].mailbox_id, &err)) { EM_DEBUG_EXCEPTION("Delete the mailbox in server : failed [%d]", err); + goto FINISH_OFF; + } else EM_DEBUG_LOG("Delete the mailbox in server : success"); } @@ -510,7 +656,7 @@ FINISH_OFF: INTERNAL_FUNC int emcore_delete_mailbox_all(email_mailbox_t *mailbox, int *err_code) { EM_DEBUG_FUNC_BEGIN(" mailbox[%p], err_code[%p]", mailbox, err_code); - + int ret = false; int err = EMAIL_ERROR_NONE; @@ -519,23 +665,23 @@ INTERNAL_FUNC int emcore_delete_mailbox_all(email_mailbox_t *mailbox, int *err_c err = EMAIL_ERROR_INVALID_PARAM; goto FINISH_OFF; } - + if (!emcore_delete_all_mails_of_mailbox(mailbox->account_id, mailbox->mailbox_id, 0, /*NULL, */ &err)) { EM_DEBUG_EXCEPTION(" emcore_delete_all_mails_of_mailbox failed - %d", err); - + goto FINISH_OFF; } - + if (!emstorage_delete_mailbox(mailbox->account_id, -1, mailbox->mailbox_id, true, &err)) { EM_DEBUG_EXCEPTION(" emstorage_delete_mailbox failed - %d", err); - + goto FINISH_OFF; } - + ret = true; - -FINISH_OFF: + +FINISH_OFF: if (err_code != NULL) *err_code = err; EM_DEBUG_FUNC_END("err[%d]", err); @@ -653,14 +799,14 @@ FINISH_OFF: extern long smtp_send(SENDSTREAM *stream, char *command, char *args); #endif /* __FEATURE_KEEP_CONNECTION__ */ -INTERNAL_FUNC int emcore_connect_to_remote_mailbox_with_account_info (email_account_t *account, - int input_mailbox_id, void **result_stream, /*either MAILSTREAM or SENDSTREAM*/ +INTERNAL_FUNC int emcore_connect_to_remote_mailbox_with_account_info (email_account_t *account, + int input_mailbox_id, void **result_stream, /*either MAILSTREAM or SENDSTREAM*/ int *err_code) { EM_PROFILE_BEGIN(emCoreMailboxOpen); EM_DEBUG_FUNC_BEGIN("account[%p], input_mailbox_id[%d], mail_stream[%p], err_code[%p]", account, input_mailbox_id, result_stream, err_code); - + int ret = false; int error = EMAIL_ERROR_NONE; email_session_t *session = NULL; @@ -675,7 +821,7 @@ INTERNAL_FUNC int emcore_connect_to_remote_mailbox_with_account_info (email_acco error = EMAIL_ERROR_INVALID_PARAM; goto FINISH_OFF; } - + if (!emcore_get_current_session(&session)) { EM_DEBUG_EXCEPTION("emcore_get_current_session failed..."); error = EMAIL_ERROR_SESSION_NOT_FOUND; @@ -684,7 +830,7 @@ INTERNAL_FUNC int emcore_connect_to_remote_mailbox_with_account_info (email_acco if (input_mailbox_id == 0 || input_mailbox_id != EMAIL_CONNECT_FOR_SENDING) is_connection_for = _SERVICE_THREAD_TYPE_RECEIVING; - else + else is_connection_for = _SERVICE_THREAD_TYPE_SENDING; #ifdef __FEATURE_KEEP_CONNECTION__ @@ -700,14 +846,14 @@ INTERNAL_FUNC int emcore_connect_to_remote_mailbox_with_account_info (email_acco *result_stream = connection_info->sending_server_stream; } } - + if (*result_stream) EM_DEBUG_LOG("Stream reuse desired"); #endif session->error = EMAIL_ERROR_NONE; emcore_set_network_error (EMAIL_ERROR_NONE); /* set current network error as EMAIL_ERROR_NONE before network operation */ - + if (input_mailbox_id == EMAIL_CONNECT_FOR_SENDING) { mailbox_name = EM_SAFE_STRDUP(ENCODED_PATH_SMTP); } @@ -722,28 +868,29 @@ INTERNAL_FUNC int emcore_connect_to_remote_mailbox_with_account_info (email_acco mailbox_name = EM_SAFE_STRDUP (mailbox->mailbox_name); } - if (is_connection_for == _SERVICE_THREAD_TYPE_RECEIVING) { + if (is_connection_for == _SERVICE_THREAD_TYPE_RECEIVING) { /* open pop3/imap server */ if (!emcore_get_long_encoded_path_with_account_info (account, mailbox_name, '/', &mbox_path, &error)) { EM_DEBUG_EXCEPTION("emcore_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); - + + EM_DEBUG_LOG_SEC("open mail connection to mbox_path [%s]", mbox_path); + session->auth = 0; /* ref_account->receiving_auth ? 1 : 0 */ - if (!(*result_stream = mail_open (*result_stream, mbox_path, IMAP_2004_LOG))) { + if (!(*result_stream = mail_open (*result_stream, mbox_path, IMAP_2004_LOG))) { EM_DEBUG_EXCEPTION("mail_open failed. session->error[%d], session->network[%d]", session->error, session->network); *result_stream = mail_close (*result_stream); - + if(account->account_id > 0 && (session->network == EMAIL_ERROR_XOAUTH_BAD_REQUEST || session->network == EMAIL_ERROR_XOAUTH_INVALID_UNAUTHORIZED)) { if((error = emcore_refresh_xoauth2_access_token (account->account_id)) != EMAIL_ERROR_NONE) { EM_DEBUG_EXCEPTION("emcore_refresh_xoauth2_access_token failed. [%d]", error); } else { - while (*result_stream == NULL && connection_retry_count < 5) { + while (*result_stream == NULL && connection_retry_count < 3) { + sleep(3); /* wait for updating access token */ if (!(*result_stream = mail_open (*result_stream, mbox_path, IMAP_2004_LOG))) { EM_DEBUG_LOG("mail_open failed. session->error[%d], session->network[%d]", session->error, session->network); @@ -752,8 +899,18 @@ INTERNAL_FUNC int emcore_connect_to_remote_mailbox_with_account_info (email_acco EM_DEBUG_LOG ("connection_retry_count [%d]", connection_retry_count); } } + } else if ((session->error == EMAIL_ERROR_TLS_SSL_FAILURE || session->error == EMAIL_ERROR_CANNOT_NEGOTIATE_TLS)) { + char *replaced_mbox_path = NULL; + replaced_mbox_path = em_replace_string(mbox_path, "}", "/force_tls_v1_0}"); + + if (replaced_mbox_path != NULL && !(*result_stream = mail_open (*result_stream, replaced_mbox_path, IMAP_2004_LOG))) { + EM_DEBUG_EXCEPTION("retry --> mail_open failed. session->error[%d], session->network[%d]", session->error, session->network); + *result_stream = mail_close (*result_stream); + } + + EM_SAFE_FREE(replaced_mbox_path); } - + if (*result_stream == NULL) { /* Finally, connection failed */ if (session->error == EMAIL_ERROR_UNKNOWN || session->error == EMAIL_ERROR_NONE) session->error = EMAIL_ERROR_CONNECTION_FAILURE; @@ -762,7 +919,7 @@ INTERNAL_FUNC int emcore_connect_to_remote_mailbox_with_account_info (email_acco } } } - else { + else { /* open smtp server */ char *host_list[2] = {NULL, NULL}; @@ -773,7 +930,7 @@ INTERNAL_FUNC int emcore_connect_to_remote_mailbox_with_account_info (email_acco send_stream = *result_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; @@ -787,11 +944,11 @@ INTERNAL_FUNC int emcore_connect_to_remote_mailbox_with_account_info (email_acco session->error = error; goto FINISH_OFF; } - - EM_DEBUG_LOG("open SMTP connection to mbox_path [%s]", mbox_path); - + + EM_DEBUG_LOG_SEC("open SMTP connection to mbox_path [%s]", mbox_path); + session->auth = account->outgoing_server_need_authentication ? 1 : 0; - + host_list[0] = mbox_path; if (!(*result_stream = smtp_open (host_list, 1))) { @@ -799,7 +956,7 @@ INTERNAL_FUNC int emcore_connect_to_remote_mailbox_with_account_info (email_acco "session->error[%d] session->network[%d]", account->outgoing_server_secure_connection, session->error, session->network); - if (account->account_id > 0 && (session->network == EMAIL_ERROR_XOAUTH_BAD_REQUEST || + if (account->account_id > 0 && (session->network == EMAIL_ERROR_XOAUTH_BAD_REQUEST || session->network == EMAIL_ERROR_XOAUTH_INVALID_UNAUTHORIZED)) { *result_stream = smtp_close (*result_stream); if((error = emcore_refresh_xoauth2_access_token (account->account_id)) != EMAIL_ERROR_NONE) { @@ -829,17 +986,17 @@ INTERNAL_FUNC int emcore_connect_to_remote_mailbox_with_account_info (email_acco } } } - + ret = true; - -FINISH_OFF: + +FINISH_OFF: #ifdef __FEATURE_KEEP_CONNECTION__ if (ret == true) { if(!connection_info) { connection_info = em_malloc(sizeof(email_connection_info_t)); connection_info->account_id = account->account_id; - if(!connection_info) + if(!connection_info) EM_DEBUG_EXCEPTION("em_malloc for connection_info failed."); else emcore_append_connection_info(connection_info); @@ -869,7 +1026,7 @@ FINISH_OFF: if (err_code != NULL) *err_code = error; EM_PROFILE_END(emCoreMailboxOpen); - EM_DEBUG_FUNC_END("ret [%d]", ret); + EM_DEBUG_FUNC_END("ret [%d]", ret); return ret; } @@ -885,19 +1042,19 @@ mail_close is only used in emcore_connect_to_remote_mailbox and emcore_reset_str INTERNAL_FUNC int emcore_connect_to_remote_mailbox(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 = EMAIL_ERROR_NONE; email_account_t *ref_account = NULL; ref_account = emcore_get_account_reference(account_id); - if (!ref_account) { + if (!ref_account) { EM_DEBUG_EXCEPTION("emcore_get_account_reference failed - account id[%d]", account_id); - error = EMAIL_ERROR_INVALID_ACCOUNT; + error = EMAIL_ERROR_INVALID_ACCOUNT; goto FINISH_OFF; } - + ret = emcore_connect_to_remote_mailbox_with_account_info(ref_account, mailbox, mail_stream, &error); FINISH_OFF: @@ -936,8 +1093,8 @@ INTERNAL_FUNC void emcore_close_mailbox_partial_body_stream() EM_DEBUG_FUNC_END(); } -/* h.gahlaut@samsung.com : 21-10-2010 - -emcore_reset_stream() function is used to reset globally stored partial body thread and receiving thread streams +/* h.gahlaut@samsung.com : 21-10-2010 - +emcore_reset_stream() function is used to reset globally stored partial body thread and receiving thread streams on account deletion and pdp deactivation */ INTERNAL_FUNC void emcore_reset_streams() @@ -946,7 +1103,7 @@ INTERNAL_FUNC void emcore_reset_streams() emcore_close_mailbox_receiving_stream(); emcore_close_mailbox_partial_body_stream(); - + EM_DEBUG_FUNC_END(); return; } @@ -956,7 +1113,7 @@ INTERNAL_FUNC void emcore_reset_streams() INTERNAL_FUNC int emcore_connect_to_remote_mailbox(int account_id, int input_mailbox_id, void **mail_stream, int *err_code) { EM_DEBUG_FUNC_BEGIN("account_id[%d], input_mailbox_id[%d], mail_stream[%p], err_code[%p]", account_id, input_mailbox_id, mail_stream, err_code); - + int ret = false; int error = EMAIL_ERROR_NONE; email_session_t *session = NULL; @@ -964,17 +1121,18 @@ INTERNAL_FUNC int emcore_connect_to_remote_mailbox(int account_id, int input_mai ref_account = emcore_get_account_reference(account_id); - if (!ref_account) { + if (!ref_account) { EM_DEBUG_EXCEPTION("emcore_get_account_reference failed - account id[%d]", account_id); - error = EMAIL_ERROR_INVALID_ACCOUNT; + error = EMAIL_ERROR_INVALID_ACCOUNT; goto FINISH_OFF; } +/* Several threads call it, so check event status is disabled if (!emcore_check_thread_status()) { error = EMAIL_ERROR_CANCELLED; goto FINISH_OFF; } - +*/ if (!emnetwork_check_network_status(&error)) { EM_DEBUG_EXCEPTION("emnetwork_check_network_status failed [%d]", error); goto FINISH_OFF; @@ -982,13 +1140,48 @@ INTERNAL_FUNC int emcore_connect_to_remote_mailbox(int account_id, int input_mai if (!emcore_get_empty_session(&session)) { EM_DEBUG_EXCEPTION("emcore_get_empty_session failed..."); - error = EMAIL_ERROR_SESSION_NOT_FOUND; - goto FINISH_OFF; +/* error = EMAIL_ERROR_SESSION_NOT_FOUND; + goto FINISH_OFF; */ } ret = emcore_connect_to_remote_mailbox_with_account_info(ref_account, input_mailbox_id, mail_stream, &error); -FINISH_OFF: + EM_DEBUG_LOG("ret[%d] incoming_server_type[%d] input_mailbox_id[%d]", ret, ref_account->incoming_server_type, input_mailbox_id); + + if (ret == EMAIL_ERROR_NONE && input_mailbox_id == EMAIL_CONNECT_FOR_SENDING) { + SENDSTREAM *send_stream = (SENDSTREAM*)*mail_stream; + + if (send_stream && send_stream->protocol.esmtp.ok) { + if (send_stream->protocol.esmtp.size.ok && send_stream->protocol.esmtp.size.limit > 0) { + EM_DEBUG_LOG("Server size limit : %ld", send_stream->protocol.esmtp.size.limit); + if (send_stream->protocol.esmtp.size.limit != ref_account->outgoing_server_size_limit) { + emstorage_set_field_of_accounts_with_integer_value(account_id, "outgoing_server_size_limit", send_stream->protocol.esmtp.size.limit, true); + emcore_init_account_reference(); + } + } + } + } + else if (ret == EMAIL_ERROR_NONE && ref_account->incoming_server_type == EMAIL_SERVER_TYPE_IMAP4 + && input_mailbox_id != EMAIL_CONNECT_FOR_SENDING) { + IMAPCAP *capability = NULL; + /* check capability changes */ + capability = imap_cap((MAILSTREAM*)*mail_stream); + EM_DEBUG_LOG("capability [%p]", capability); + if (capability) { + EM_DEBUG_LOG("idle [%d] retrieval_mode[%d]", capability->idle, ref_account->retrieval_mode); + if (capability->idle != ((ref_account->retrieval_mode & EMAIL_IMAP4_IDLE_SUPPORTED) == EMAIL_IMAP4_IDLE_SUPPORTED)) { + if (capability->idle) + ref_account->retrieval_mode += EMAIL_IMAP4_IDLE_SUPPORTED; + else + ref_account->retrieval_mode -= EMAIL_IMAP4_IDLE_SUPPORTED; + emstorage_set_field_of_accounts_with_integer_value(account_id, "retrieval_mode", ref_account->retrieval_mode, true); + emcore_init_account_reference(); + } + } + } + + +FINISH_OFF: if (ref_account) { emcore_free_account(ref_account); @@ -996,10 +1189,10 @@ FINISH_OFF: } emcore_clear_session(session); - + if (err_code) *err_code = error; - + EM_DEBUG_FUNC_END("ret [%d]", ret); return ret; } @@ -1008,11 +1201,11 @@ FINISH_OFF: INTERNAL_FUNC int emcore_close_mailbox(int account_id, void *mail_stream) { EM_DEBUG_FUNC_BEGIN("account_id[%d], mail_stream[%p]", account_id, mail_stream); - + if (!mail_stream) { return false; } - + #ifdef __FEATURE_KEEP_CONNECTION__ thread_t thread_id = THREAD_SELF(); @@ -1037,15 +1230,15 @@ INTERNAL_FUNC int emcore_close_mailbox(int account_id, void *mail_stream) INTERNAL_FUNC void emcore_free_mailbox_list(email_mailbox_t **mailbox_list, int count) { EM_DEBUG_FUNC_BEGIN("mailbox_list[%p], count[%d]", mailbox_list, count); - + if (count <= 0 || !mailbox_list || !*mailbox_list) { EM_DEBUG_EXCEPTION("INVALID_PARAM: mailbox_list[%p], count[%d]", mailbox_list, count); return; } - + email_mailbox_t *p = *mailbox_list; int i; - + for (i = 0; i < count; i++) emcore_free_mailbox(p+i); @@ -1065,7 +1258,7 @@ INTERNAL_FUNC void emcore_free_mailbox(email_mailbox_t *mailbox) EM_SAFE_FREE(mailbox->mailbox_name); EM_SAFE_FREE(mailbox->alias); EM_SAFE_FREE(mailbox->eas_data); - + EM_DEBUG_FUNC_END(); } @@ -1115,7 +1308,7 @@ INTERNAL_FUNC void emcore_bind_mailbox_type(email_internal_mailbox_t *mailbox_li int i = 0; int bIsNotUserMailbox = false; email_mailbox_type_item_t *pMailboxType1 = NULL ; - + for (i = 0 ; i < MAX_MAILBOX_TYPE ; i++) { pMailboxType1 = g_mailbox_type + i; if (0 == EM_SAFE_STRCMP(pMailboxType1->mailbox_name, mailbox_list->mailbox_name)) { /*prevent 24662*/ @@ -1135,15 +1328,15 @@ INTERNAL_FUNC void emcore_bind_mailbox_type(email_internal_mailbox_t *mailbox_li INTERNAL_FUNC int emcore_send_mail_event(email_mailbox_t *mailbox, int mail_id , int *err_code) { EM_DEBUG_FUNC_BEGIN(); - + int ret = false; int err = EMAIL_ERROR_NONE; - int handle; + int handle; email_event_t *event_data = NULL; if (!mailbox || mailbox->account_id <= 0) { EM_DEBUG_LOG(" mailbox[%p]", mailbox); - + err = EMAIL_ERROR_INVALID_PARAM; goto FINISH_OFF; } @@ -1154,7 +1347,7 @@ INTERNAL_FUNC int emcore_send_mail_event(email_mailbox_t *mailbox, int mail_id event_data->event_param_data_4 = mail_id; event_data->event_param_data_1 = NULL; event_data->event_param_data_5 = mailbox->mailbox_id; - + if (!emcore_insert_event_for_sending_mails(event_data, &handle, &err)) { EM_DEBUG_LOG(" emcore_insert_event failed - %d", err); goto FINISH_OFF; @@ -1163,7 +1356,7 @@ INTERNAL_FUNC int emcore_send_mail_event(email_mailbox_t *mailbox, int mail_id ret = true; -FINISH_OFF: +FINISH_OFF: if (ret == false && event_data) { emcore_free_event(event_data); @@ -1172,7 +1365,7 @@ FINISH_OFF: if (err_code) *err_code = err; - + return ret; } @@ -1192,7 +1385,7 @@ INTERNAL_FUNC int emcore_partial_body_thd_local_activity_sync(int *is_event_inse email_event_partial_body_thd pbd_event; - /* Carefully initialise the event */ + /* Carefully initialise the event */ memset(&pbd_event, 0x00, sizeof(email_event_partial_body_thd)); pbd_event.event_type = EMAIL_EVENT_LOCAL_ACTIVITY_SYNC_BULK_PBD; @@ -1206,15 +1399,15 @@ INTERNAL_FUNC int emcore_partial_body_thd_local_activity_sync(int *is_event_inse /*Not checking for NULL here because is_event_inserted is never NULL. */ *is_event_inserted = true; } - + } else { - *is_event_inserted = false; + *is_event_inserted = false; } ret = true; - - FINISH_OFF: + +FINISH_OFF: if (NULL != err_code) { *err_code = error; @@ -1229,7 +1422,7 @@ INTERNAL_FUNC int emcore_get_mailbox_by_type(int account_id, email_mailbox_type_ int ret = false, err = EMAIL_ERROR_NONE; emstorage_mailbox_tbl_t *mail_box_tbl_spam = NULL; - if (result_mailbox == NULL) { + if (result_mailbox == NULL) { EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM"); err = EMAIL_ERROR_INVALID_PARAM; goto FINISH_OFF; @@ -1239,19 +1432,20 @@ INTERNAL_FUNC int emcore_get_mailbox_by_type(int account_id, email_mailbox_type_ EM_DEBUG_LOG("emstorage_get_mailbox_by_mailbox_type failed - %d", err); } - else { + else { if (mail_box_tbl_spam) { result_mailbox->mailbox_type = mail_box_tbl_spam->mailbox_type; result_mailbox->mailbox_name = EM_SAFE_STRDUP(mail_box_tbl_spam->mailbox_name); result_mailbox->account_id = mail_box_tbl_spam->account_id; + result_mailbox->mailbox_id = mail_box_tbl_spam->mailbox_id; result_mailbox->mail_slot_size = mail_box_tbl_spam->mail_slot_size; if (!emstorage_free_mailbox(&mail_box_tbl_spam, 1, &err)) EM_DEBUG_EXCEPTION(" emstorage_free_mailbox Failed [%d]", err); - ret = true; + ret = true; } } -FINISH_OFF: +FINISH_OFF: if (err_code) *err_code = err; EM_DEBUG_FUNC_END(); @@ -1264,7 +1458,7 @@ INTERNAL_FUNC int emcore_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; @@ -1295,7 +1489,7 @@ INTERNAL_FUNC int emcore_local_activity_sync(int account_id, int *err_code) EM_DEBUG_LOG(" emcore_insert_event failed - %d", err); goto FINISH_OFF; } - + ret = true; } @@ -1307,11 +1501,11 @@ FINISH_OFF: } if (activity_id_list) - emstorage_free_activity_id_list(activity_id_list, &err); - + emstorage_free_activity_id_list(activity_id_list, &err); + if (err_code != NULL) *err_code = err; - + return ret; } @@ -1321,7 +1515,7 @@ INTERNAL_FUNC int emcore_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); - + emstorage_activity_tbl_t *local_activity = NULL; int *activity_id_list = NULL; int activity_count = 0; @@ -1343,7 +1537,7 @@ INTERNAL_FUNC int emcore_save_local_activity_sync(int account_id, int *err_code) goto FINISH_OFF; } - + if (activity_count > 0) { event_data = em_malloc(sizeof(email_event_t)); event_data->type = EMAIL_EVENT_LOCAL_ACTIVITY; @@ -1351,8 +1545,8 @@ INTERNAL_FUNC int emcore_save_local_activity_sync(int account_id, int *err_code) if (!emcore_insert_event_for_sending_mails(event_data, &handle, &err)) { EM_DEBUG_LOG(" emcore_insert_event failed - %d", err); goto FINISH_OFF; - } - + } + ret = true; } @@ -1364,14 +1558,14 @@ FINISH_OFF: } if (local_activity) - emstorage_free_local_activity(&local_activity, activity_count, NULL); + emstorage_free_local_activity(&local_activity, activity_count, NULL); if (activity_id_list) - emstorage_free_activity_id_list(activity_id_list, &err); + emstorage_free_activity_id_list(activity_id_list, &err); if (err_code != NULL) *err_code = err; - + return ret; } diff --git a/email-core/email-core-mime.c b/email-core/email-core-mime.c index 5c0b09e..9e148dd 100755 --- a/email-core/email-core-mime.c +++ b/email-core/email-core-mime.c @@ -47,6 +47,7 @@ #include "email-core-utils.h" #include "email-core-mail.h" #include "email-core-mime.h" +#include "email-core-gmime.h" #include "email-storage.h" #include "email-core-event.h" #include "email-core-account.h" @@ -99,132 +100,7 @@ #define EML_FOLDER 20 /* save eml content to temporary folder */ -/* - 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 value */ - struct _parameter *next; /* next paramete */ -}; - -/* Content-Disposition */ -struct _disposition { - char *type; /* "inline" "attachment */ - struct _parameter *parameter; /* "filename", .. */ -}; - -/* RFC822 Header */ -struct _rfc822header { - char *return_path; /* error return path */ - 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, message */ - char *subtype; /* plain, html, jpeg, .. */ - char *encoding; /* encoding typ */ - struct _parameter *parameter; /* content-type parameter : "boundary" "charset" .. */ - char *desc; /* description */ - 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 Version */ - struct _m_part_header *part_header; /* MIME Part Header */ - /* char *message_context; */ /* Message-Context : Voice-message, Video-message, Fax-message... */ - /* int content_duration; */ /* Content-Duration */ - /* int x_content_pages; */ /* X-Content-Pages */ - /* char *sensitivity; */ /* Sensitivity */ -}; - -/* MIME Multipart Body linked list */ -typedef struct _m_body _m_body_t; -struct _m_part{ - _m_body_t *body; /* part body */ - struct _m_part *next; /* the next found part */ -}; - -/* MIME Multipart Body */ -struct _m_body { - struct _m_part_header *part_header; /* MIME Part Header */ - struct _m_part nested; /* nested structure if contain multipart */ - char *text; /* text if not contain multipart */ - int size; /* text size if not contain multipart */ - char *holdingfile; -}; -/* MIME Message */ -struct _m_mesg { - struct _rfc822header *rfc822header; /* RFC822 Header */ - struct _m_mesg_header *header; /* MIME Message Header */ - struct _m_part nested; /* nested structure if contain multipart */ - char *text; /* text if not contain multipart */ - int size; /* text size if not contain multipart */ -}; /* ---------------------------------------------------------------------- */ /* Global variable */ static int eml_data_count = 0; @@ -288,7 +164,6 @@ void emcore_mime_free_mime(struct _m_mesg *mmsg); /* 3 : save content to file (holder is file name */ static int emcore_mime_get_content_data(void *stream, int is_file, - int is_text, char *boundary_str, char *content_encoding, int *end_of_parsing, @@ -298,8 +173,8 @@ static int emcore_mime_get_content_data(void *stream, void *callback, int *err_code); -int emcore_decode_body_text_from_sock(void *stream, char *boundary_str, int encoding, int mode, int is_text, int fd, char **holder, int *end_of_parsing, int *size); -int emcore_decode_body_text_from_file(FILE *stream, char *boundary_str, int encoding, int mode, int is_text, int fd, char **holder, int *end_of_parsing, int *size); +int emcore_decode_body_text_from_sock(void *stream, char *boundary_str, int encoding, int mode, int fd, char **holder, int *end_of_parsing, int *size); +int emcore_decode_body_text_from_file(FILE *stream, char *boundary_str, int encoding, int mode, int fd, char **holder, int *end_of_parsing, int *size); /* skip content data to boundary_str or end of fil */ int emcore_mime_skip_content_data(void *stream, int is_file, @@ -466,13 +341,14 @@ int emcore_mime_flush_receiving_buffer(void *stream, int is_file, char *boundary } while (TRUE) { +/* Several threads including event thd call it, don't delete comment if (!emcore_check_thread_status()) { EM_DEBUG_FUNC_END("EMAIL_ERROR_CANCELLED"); if (err_code) *err_code = EMAIL_ERROR_CANCELLED; return false; } - +*/ if ((is_file == 0 && !emcore_mime_get_line_from_sock(stream, buf, MIME_LINE_LEN, &err)) || (is_file == 1 && !emcore_get_line_from_file(stream, buf, MIME_LINE_LEN, &err))) { if (err != EMAIL_ERROR_NO_MORE_DATA) { @@ -480,7 +356,7 @@ int emcore_mime_flush_receiving_buffer(void *stream, int is_file, char *boundary local_end_of_parsing = 0; break; } - + local_end_of_parsing = 1; break; } @@ -522,17 +398,18 @@ int emcore_parse_mime(void *stream, int is_file, struct _m_content_info *cnt_inf /* 1. parse the first found header */ EM_DEBUG_LOG(">>>>>> 1. parse the first found header"); if (!emcore_mime_parse_header(stream, is_file, &mmsg->rfc822header, &mmsg->header, err_code)) { - EM_SAFE_FREE(mmsg); + emcore_mime_free_mime(mmsg); return false; } +/* Several threads including event thd call it, don't delete comment if (!emcore_check_thread_status()) { if (err_code != NULL) *err_code = EMAIL_ERROR_CANCELLED; emcore_mime_free_mime(mmsg); return false; } - +*/ /* 2. parse body */ EM_DEBUG_LOG(">>>>>> 2. parse body"); if (mmsg && mmsg->header && mmsg->header->part_header && mmsg->header->part_header->parameter) { @@ -542,7 +419,7 @@ int emcore_parse_mime(void *stream, int is_file, struct _m_content_info *cnt_inf } if (!emcore_mime_parse_body(stream, is_file, mmsg, cnt_info, NULL, err_code)) { - EM_SAFE_FREE(mmsg); + emcore_mime_free_mime(mmsg); return false; } @@ -570,11 +447,13 @@ int emcore_mime_parse_header(void *stream, int is_file, struct _rfc822header **r char *pTemp = NULL; int is_longheader; +/* Several threads including event thd call it, don't delete comment if (!emcore_check_thread_status()) { if (err_code != NULL) *err_code = EMAIL_ERROR_CANCELLED; return false; } +*/ if ((is_file == 0 && !emcore_mime_get_line_from_sock(stream, buf, MIME_LINE_LEN, err_code)) || (is_file == 1 && !emcore_get_line_from_file(stream, buf, MIME_LINE_LEN, err_code))) { @@ -588,11 +467,13 @@ int emcore_mime_parse_header(void *stream, int is_file, struct _rfc822header **r return false; } +/* Several threads including event thd call it, don't delete comment if (!emcore_check_thread_status()) { if (err_code != NULL) *err_code = EMAIL_ERROR_CANCELLED; return false; } +*/ while (TRUE) { EM_DEBUG_LOG("buf[%s]", buf); @@ -669,11 +550,13 @@ int emcore_mime_parse_header(void *stream, int is_file, struct _rfc822header **r emcore_mime_set_rfc822_header_value(&tmp_rfc822header, name, value, err_code); } +/* Several threads including event thd call it, don't delete comment if (!emcore_check_thread_status()) { if (err_code != NULL) *err_code = EMAIL_ERROR_CANCELLED; return false; } +*/ if ((is_file == 0 && !emcore_mime_get_line_from_sock(stream, buf, MIME_LINE_LEN, err_code)) || (is_file == 1 && !emcore_get_line_from_file(stream, buf, MIME_LINE_LEN, err_code))) { @@ -711,14 +594,16 @@ int emcore_mime_parse_part_header(void *stream, int is_file, struct _m_part_head char *p = NULL; int is_longheader = false; +/* Several threads including event thd call it, don't delete comment if (!emcore_check_thread_status()) { if (err_code != NULL) *err_code = EMAIL_ERROR_CANCELLED; return false; } +*/ if ((is_file == 0 && !emcore_mime_get_line_from_sock(stream, buf, MIME_LINE_LEN, err_code)) || - (is_file == 1 && !emcore_get_line_from_file(stream, buf, MIME_LINE_LEN, err_code))) + (is_file == 1 && !emcore_get_line_from_file(stream, buf, MIME_LINE_LEN, err_code))) return false; tmp_header = em_malloc(sizeof(struct _m_part_header)); @@ -753,11 +638,13 @@ int emcore_mime_parse_part_header(void *stream, int is_file, struct _m_part_head emcore_mime_set_part_header_value(&tmp_header, name, value, err_code); +/* Several threads including event thd call it, don't delete comment if (!emcore_check_thread_status()) { if (err_code != NULL) *err_code = EMAIL_ERROR_CANCELLED; return false; } +*/ if ((is_file == 0 && !emcore_mime_get_line_from_sock(stream, buf, MIME_LINE_LEN, err_code)) || (is_file == 1 && !emcore_get_line_from_file(stream, buf, MIME_LINE_LEN, err_code))) { @@ -784,17 +671,19 @@ int emcore_mime_parse_body(void *stream, int is_file, struct _m_mesg *mmsg, stru EM_DEBUG_EXCEPTION("Invalid paramter"); *err_code = EMAIL_ERROR_INVALID_PARAM; return false; - } - + } + char *content_type = NULL, *content_encoding = NULL, *holder = NULL, *attachment_name, *t = NULL; int type = 0, end_of_parsing = 0, size; int err = EMAIL_ERROR_NONE; +/* Several threads including event thd call it, don't delete comment if (!emcore_check_thread_status()) { if (err_code != NULL) *err_code = EMAIL_ERROR_CANCELLED; return false; } +*/ if (mmsg->header) content_type = emcore_mime_get_header_value(mmsg->header->part_header, CONTENT_TYPE, err_code); @@ -843,7 +732,7 @@ int emcore_mime_parse_body(void *stream, int is_file, struct _m_mesg *mmsg, stru if (mmsg->header && emcore_mime_get_header_value(mmsg->header->part_header, CONTENT_DISPOSITION, err_code)) { attachment_name = emcore_mime_get_header_value(mmsg->header->part_header, CONTENT_FILENAME, err_code); /* if (!attachment_name) attachment_name = "unknown" */ - if (attachment_name) EM_DEBUG_LOG(" attachment = [%s]", attachment_name); + if (attachment_name) EM_DEBUG_LOG_SEC(" attachment = [%s]", attachment_name); } if (strcasestr(content_type, "PKCS7-MIME")) { @@ -858,13 +747,13 @@ int emcore_mime_parse_body(void *stream, int is_file, struct _m_mesg *mmsg, stru if (cnt_info->file) { cnt_info->file->type = ATTACHMENT; cnt_info->file->name = EM_SAFE_STRDUP(attachment_name); - if (!emcore_mime_get_content_data(stream, is_file, false, NULL, content_encoding, &end_of_parsing, SAVE_TYPE_FILE, &holder, &size, NULL, err_code)) { + if (!emcore_mime_get_content_data(stream, is_file, NULL, content_encoding, &end_of_parsing, SAVE_TYPE_FILE, &holder, &size, NULL, err_code)) { EM_DEBUG_EXCEPTION("emcore_mime_get_content_data failed : [%d]", err_code); return false; } cnt_info->file->save = holder; cnt_info->file->size = size; - cnt_info->file->attachment_mime_type = EM_SAFE_STRDUP(content_type); + cnt_info->file->attachment_mime_type = EM_SAFE_STRDUP(content_type); cnt_info->file->next = NULL; } break; @@ -873,7 +762,7 @@ int emcore_mime_parse_body(void *stream, int is_file, struct _m_mesg *mmsg, stru if (cnt_info->grab_type & GRAB_TYPE_TEXT) { /* EM_DEBUG_LINE */ /* get content data. content data is saved in file */ - if (!emcore_mime_get_content_data(stream, is_file, true, NULL, content_encoding, &end_of_parsing, SAVE_TYPE_FILE, &holder, &size, NULL, err_code)) { + if (!emcore_mime_get_content_data(stream, is_file, NULL, content_encoding, &end_of_parsing, SAVE_TYPE_FILE, &holder, &size, NULL, err_code)) { EM_DEBUG_EXCEPTION("emcore_mime_get_content_data failed : [%d]", err_code); return false; } @@ -934,7 +823,6 @@ int emcore_mime_parse_part(void *stream, int is_file, struct _m_part_header *par int content_disposition_type = 0; int end_of_parsing = 0; int size = 0, local_err_code = EMAIL_ERROR_NONE; - int is_skip = false; int result = 0; int inline_attach_index = 0; @@ -949,11 +837,13 @@ int emcore_mime_parse_part(void *stream, int is_file, struct _m_part_header *par /* goto the first found useful mime dat */ EM_DEBUG_LOG("Before first loop"); while (true) { +/* Several threads including event thd call it, don't delete comment if (!emcore_check_thread_status()) { if (err_code != NULL) *err_code = EMAIL_ERROR_CANCELLED; return false; } +*/ if ((is_file == 0 && !emcore_mime_get_line_from_sock(stream, buf, MIME_LINE_LEN, err_code)) || (is_file == 1 && !emcore_get_line_from_file(stream, buf, MIME_LINE_LEN, err_code))) { EM_DEBUG_EXCEPTION("emcore_mime_get_line_from_sock failed."); @@ -1060,22 +950,11 @@ int emcore_mime_parse_part(void *stream, int is_file, struct _m_part_header *par default: EM_DEBUG_LOG("default"); + content_disposition_type = 0; attachment_name = NULL; content_id = NULL; content_disposition = NULL; - if (type == TYPE_MESSAGE) - is_skip = true; - - if (is_skip == true) { - if (!emcore_mime_skip_content_data(stream, is_file, boundary_str, &end_of_parsing, &size, NULL, err_code)) - EM_DEBUG_EXCEPTION("emcore_mime_skip_content_data failed..."); - - emcore_mime_free_part_body(tmp_body); - EM_DEBUG_LOG_MIME("break"); - break; - } - /* first check inline content */ /* if the content id or content location exis */ content_disposition = emcore_mime_get_header_value(tmp_body->part_header, CONTENT_DISPOSITION, err_code); @@ -1088,13 +967,14 @@ int emcore_mime_parse_part(void *stream, int is_file, struct _m_part_header *par if (emcore_search_string_from_file(cnt_info->text.html, content_id, NULL, &result) == EMAIL_ERROR_NONE && result) { SNPRINTF(temp_inline_attachment_name, sizeof(temp_inline_attachment_name), "image_%d", ++inline_attach_index); - attachment_name = temp_inline_attachment_name; + attachment_name = temp_inline_attachment_name; if (emcore_search_string_from_file(cnt_info->text.html, content_id, attachment_name, &result) != EMAIL_ERROR_NONE) { EM_DEBUG_EXCEPTION("emcore_search_string_from file failed"); } - + content_disposition_type = INLINE_ATTACHMENT; + } else if (!strcasecmp(content_disposition ? content_disposition : "", "attachment")) { attachment_name = emcore_mime_get_header_value(tmp_body->part_header, CONTENT_NAME, err_code); @@ -1103,6 +983,14 @@ int emcore_mime_parse_part(void *stream, int is_file, struct _m_part_header *par content_disposition_type = ATTACHMENT; + } else if (!strcasecmp(content_disposition ? content_disposition : "", "inline")) { + attachment_name = emcore_mime_get_header_value(tmp_body->part_header, CONTENT_NAME, err_code); + + if (!attachment_name) + attachment_name = emcore_mime_get_header_value(tmp_body->part_header, CONTENT_FILENAME, err_code); + + content_disposition_type = INLINE_ATTACHMENT; + } else { EM_DEBUG_EXCEPTION("Unknown mime type"); } @@ -1113,12 +1001,15 @@ int emcore_mime_parse_part(void *stream, int is_file, struct _m_part_header *par if (!attachment_name) attachment_name = emcore_mime_get_header_value(tmp_body->part_header, CONTENT_FILENAME, err_code); + if (!attachment_name && type == TYPE_MESSAGE) + attachment_name = strdup("unknown_name"); + content_disposition_type = ATTACHMENT; } else if (!strcasecmp(content_disposition ? content_disposition : "", "inline")) { SNPRINTF(temp_inline_attachment_name, sizeof(temp_inline_attachment_name), "image_%d", ++inline_attach_index); - attachment_name = temp_inline_attachment_name; + attachment_name = temp_inline_attachment_name; if (emcore_search_string_from_file(cnt_info->text.html, content_id, attachment_name, &result) != EMAIL_ERROR_NONE) { EM_DEBUG_EXCEPTION("emcore_search_string_from file failed"); @@ -1136,6 +1027,7 @@ int emcore_mime_parse_part(void *stream, int is_file, struct _m_part_header *par } } +/* Several threads including event thd call it, don't delete comment if (!emcore_check_thread_status()) { if (err_code != NULL) *err_code = EMAIL_ERROR_CANCELLED; @@ -1144,13 +1036,14 @@ int emcore_mime_parse_part(void *stream, int is_file, struct _m_part_header *par EM_DEBUG_FUNC_END("false"); return false; } +*/ EM_DEBUG_LOG_SEC("attachment_name : [%s]", attachment_name); /* get content and content information */ if (content_disposition_type != ATTACHMENT && content_disposition_type != INLINE_ATTACHMENT) { /* text */ /* get content by buffer */ EM_DEBUG_LOG_MIME("attachment_name is NULL. It's a text message"); - if (!emcore_mime_get_content_data(stream, is_file, true, boundary_str, content_encoding, &end_of_parsing, SAVE_TYPE_FILE, &holder, &size, NULL, err_code)) { + if (!emcore_mime_get_content_data(stream, is_file, boundary_str, content_encoding, &end_of_parsing, SAVE_TYPE_FILE, &holder, &size, NULL, err_code)) { EM_DEBUG_EXCEPTION("emcore_mime_get_content_data failed [%d]", err_code); emcore_mime_free_part_body(tmp_body); return false; @@ -1182,7 +1075,7 @@ int emcore_mime_parse_part(void *stream, int is_file, struct _m_part_header *par EM_DEBUG_LOG(" cnt_info->text.plain [%s]", cnt_info->text.plain); } } else { - EM_SAFE_FREE (holder); + EM_SAFE_FREE (holder); } } else { /* attachment */ EM_DEBUG_LOG("attachment_name is not NULL. It's a attachment"); @@ -1204,13 +1097,13 @@ int emcore_mime_parse_part(void *stream, int is_file, struct _m_part_header *par file->name = EM_SAFE_STRDUP(attachment_name); file->content_id = EM_SAFE_STRDUP(tmp_body->part_header->content_id); file->attachment_mime_type = EM_SAFE_STRDUP(content_type); - + /* check if the current file is target file */ if ((cnt_info->grab_type & GRAB_TYPE_ATTACHMENT) || file->type == INLINE_ATTACHMENT) { /* get content by file */ EM_DEBUG_LOG_MIME("Trying to get content"); - if (!emcore_mime_get_content_data(stream, is_file, false, boundary_str, content_encoding, &end_of_parsing, SAVE_TYPE_FILE, &holder, &size, NULL, err_code)) { + if (!emcore_mime_get_content_data(stream, is_file, boundary_str, content_encoding, &end_of_parsing, SAVE_TYPE_FILE, &holder, &size, NULL, err_code)) { EM_DEBUG_EXCEPTION("emcore_mime_get_content_data failed [%d]", err_code); emcore_mime_free_part_body(tmp_body); emcore_free_attachment_info(file); @@ -1222,7 +1115,7 @@ int emcore_mime_parse_part(void *stream, int is_file, struct _m_part_header *par } else { /* only get content size */ EM_DEBUG_LOG_MIME("Pass downloading"); - if (!emcore_mime_get_content_data(stream, is_file, false, boundary_str, content_encoding, &end_of_parsing, SAVE_TYPE_SIZE, NULL, &size, NULL, err_code)) { + if (!emcore_mime_get_content_data(stream, is_file, boundary_str, content_encoding, &end_of_parsing, SAVE_TYPE_SIZE, NULL, &size, NULL, err_code)) { EM_DEBUG_EXCEPTION("emcore_mime_get_content_data failed [%d]", err_code); emcore_mime_free_part_body(tmp_body); emcore_free_attachment_info(file); @@ -1238,7 +1131,18 @@ int emcore_mime_parse_part(void *stream, int is_file, struct _m_part_header *par file->size = size; file->attachment_mime_type = strdup(content_type); - file->save_status = end_of_parsing; + + switch (end_of_parsing) { + case 0: + case 1: + /* Downloaded */ + file->save_status = 1; + break; + case 2: + file->save_status = 2; + break; + } + if (strstr(content_type, APPLICATION_STR)) { pTemp = content_type + EM_SAFE_STRLEN(APPLICATION_STR); @@ -1260,6 +1164,7 @@ int emcore_mime_parse_part(void *stream, int is_file, struct _m_part_header *par temp_file->next = file; } +/* Several threads including event thd call it, don't delete comment if (!emcore_check_thread_status()) { if (err_code != NULL) *err_code = EMAIL_ERROR_CANCELLED; @@ -1268,6 +1173,7 @@ int emcore_mime_parse_part(void *stream, int is_file, struct _m_part_header *par EM_DEBUG_FUNC_END("false"); return false; } +*/ if (!nested->body) nested->body = tmp_body; @@ -1372,6 +1278,7 @@ int emcore_mime_set_rfc822_header_value(struct _rfc822header **header, char *nam *p = t; } + EM_DEBUG_FUNC_END(); return true; } @@ -1388,6 +1295,7 @@ int emcore_mime_set_part_header_value(struct _m_part_header **header, char *name } struct _parameter *p = NULL; + struct _parameter *tmp = NULL; char *p_val = NULL; if (!*header) { @@ -1399,16 +1307,17 @@ int emcore_mime_set_part_header_value(struct _m_part_header **header, char *name } em_upper_string(name); - + em_trim_left(value); em_trim_right(value); +/* Several threads including event thd call it, don't delete comment if (!emcore_check_thread_status()) { if (err_code != NULL) *err_code = EMAIL_ERROR_CANCELLED; return false; } - +*/ if (name) { if (strncmp(name, "CONTENT-TYPE", strlen("CONTENT-TYPE")) == 0) { p_val = strtok(value, ";"); @@ -1421,8 +1330,16 @@ int emcore_mime_set_part_header_value(struct _m_part_header **header, char *name /* Content-Type Parameter (format : "name =value" */ do { - if (emcore_mime_get_param_from_str(p_val, &p, err_code)) + if (emcore_mime_get_param_from_str(p_val, &p, err_code)) { + /* Save the start node */ + tmp = (*header)->parameter; + /* insert node */ emcore_mime_add_param_to_list(&((*header)->parameter), p, err_code); + if (tmp != NULL) { + (*header)->parameter = tmp; + tmp = NULL; + } + } else /* name= CRLF value */ { struct _parameter *t = (*header)->parameter; while (t && t->next) { @@ -1435,12 +1352,22 @@ int emcore_mime_set_part_header_value(struct _m_part_header **header, char *name char *pointer = NULL; if (EM_SAFE_STRLEN(p_val) > 0) { - if ((pointer = strchr(p_val, '\"'))) { - p_val = pointer + 1; - if (!*p_val) return false; + /* "=?charset?B?value?= */ + /* "=?charset?B?value.... */ + /* =?charset?B?value" */ + if ((pointer = strchr(p_val, '\"'))) { + if (!*(pointer + 1)) { /* line end '"' */ + if (*p_val == *pointer) /* Example : '"' */ + return true; + else + *pointer = '\0'; /* Example : 'abcde"' */ + } + else { /* line start '"' */ + p_val = pointer + 1; + if ((pointer = strchr(p_val, '\"'))) + *pointer = '\0'; + } } - if ((pointer = strchr(p_val, '\"'))) - *pointer = '\0'; /* = ? ENCODING_TYPE ? B(Q) ? ENCODED_STRING ? */ int err = EMAIL_ERROR_NONE; @@ -1450,23 +1377,24 @@ int emcore_mime_set_part_header_value(struct _m_part_header **header, char *name EM_DEBUG_EXCEPTION("emcore_decode_rfc2047_text failed [%d]", err); continue; /*prevent 53050*/ } - EM_DEBUG_LOG("utf8_text : [%s]", utf8_text); + EM_DEBUG_LOG_SEC("utf8_text : [%s]", utf8_text); if (t->value == NULL) { EM_DEBUG_LOG("value is NULL"); t->value = EM_SAFE_STRDUP(utf8_text); } else { EM_DEBUG_LOG("value is not NULL"); - t->value = realloc(t->value, strlen(t->value) + EM_SAFE_STRLEN(utf8_text) + 1); - strcpy((t->value + strlen(utf8_text)), utf8_text); + t->value = realloc(t->value, strlen(t->value) + EM_SAFE_STRLEN(utf8_text) + 1); + strcpy((t->value + strlen(t->value)), utf8_text); + EM_DEBUG_LOG("long name : [%s]", t->value); } - - EM_DEBUG_LOG("value : [%s]", t->value); + + EM_DEBUG_LOG("value : [%s]", t->value); EM_SAFE_FREE (utf8_text); } } } - } while ((p_val = strtok(NULL, ";"))); + } while ((p_val = strtok(NULL, ";"))); } } else if (strncmp(name, "CONTENT-TRANSFER-ENCODING", strlen("CONTENT-TRANSFER-ENCODING")) == 0) { @@ -1485,16 +1413,73 @@ int emcore_mime_set_part_header_value(struct _m_part_header **header, char *name em_upper_string(p_val); (*header)->disp_type = EM_SAFE_STRDUP(p_val); } - else { /* Content-Disposition parameter (format : "name =value" */ - if (emcore_mime_get_param_from_str(p_val, &p, err_code)) + /* Content-Disposition Parameter (format : "name =value" */ + do { + if (emcore_mime_get_param_from_str(p_val, &p, err_code)) { + /* Save the start node */ + tmp = (*header)->disp_parameter; + /* insert node */ emcore_mime_add_param_to_list(&((*header)->disp_parameter), p, err_code); - } + if (tmp != NULL) { + (*header)->disp_parameter = tmp; + tmp = NULL; + } + } + else /* name= CRLF value */ { + struct _parameter *t = (*header)->disp_parameter; + while (t && t->next) { + EM_DEBUG_LOG_SEC("name : [%s]", t->name); + EM_DEBUG_LOG("value : [%s]", t->value); + t = t->next; + } - /* repeatedly get paramete */ - while ((p_val = strtok(NULL, ";"))) { - if (emcore_mime_get_param_from_str(p_val, &p, err_code)) - emcore_mime_add_param_to_list(&((*header)->disp_parameter), p, err_code); - } + if (t && t->name) { + char *pointer = NULL; + + if (EM_SAFE_STRLEN(p_val) > 0) { + /* "=?charset?B?value?= */ + /* "=?charset?B?value.... */ + /* =?charset?B?value" */ + if ((pointer = strchr(p_val, '\"'))) { + if (!*(pointer + 1)) { /* line end '"' */ + if (*p_val == *pointer) /* Example : '"' */ + return true; + else + *pointer = '\0'; /* Example : 'abcde"' */ + } + else { /* line start '"' */ + p_val = pointer + 1; + if ((pointer = strchr(p_val, '\"'))) + *pointer = '\0'; + } + } + + /* = ? ENCODING_TYPE ? B(Q) ? ENCODED_STRING ? */ + int err = EMAIL_ERROR_NONE; + char *utf8_text = NULL; + + if (!(utf8_text = emcore_decode_rfc2047_text(p_val, &err))) { + EM_DEBUG_EXCEPTION("emcore_decode_rfc2047_text failed [%d]", err); + continue; /*prevent 53050*/ + } + EM_DEBUG_LOG("utf8_text : [%s]", utf8_text); + + if (t->value == NULL) { + EM_DEBUG_LOG("value is NULL"); + t->value = EM_SAFE_STRDUP(utf8_text); + } else { + EM_DEBUG_LOG("value is not NULL"); + t->value = realloc(t->value, strlen(t->value) + EM_SAFE_STRLEN(utf8_text) + 1); + strcpy((t->value + strlen(t->value)), utf8_text); + EM_DEBUG_LOG("long name : [%s]", t->value); + } + + EM_DEBUG_LOG_SEC("value : [%s]", t->value); + EM_SAFE_FREE (utf8_text); + } + } + } + } while ((p_val = strtok(NULL, ";"))); } } else if (strncmp(name, "CONTENT-ID", strlen("CONTENT-ID")) == 0) { @@ -1512,9 +1497,17 @@ int emcore_mime_set_part_header_value(struct _m_part_header **header, char *name (*header)->content_id = EM_SAFE_STRDUP(value); } - else if (strncmp(name, "CONTENT-LOCATION", strlen("CONTENT-LOCATION")) == 0) + else if (strncmp(name, "CONTENT-LOCATION", strlen("CONTENT-LOCATION")) == 0) { (*header)->content_location = EM_SAFE_STRDUP(value); + } + else if (strncmp(name, "X-PRIORITY", strlen("X-PRIORITY")) == 0) { + (*header)->priority = EM_SAFE_STRDUP(value); + } + else if (strncmp(name, "X-MSMAIL-PRIORITY", strlen("X-MSMAIL-PRIORITY")) == 0) { + (*header)->ms_priority = EM_SAFE_STRDUP(value); + } } + EM_DEBUG_FUNC_END(); return true; } @@ -1590,6 +1583,7 @@ int emcore_mime_get_param_from_str(char *str, struct _parameter **param, int *er /* add a parameter to parameter lis */ int emcore_mime_add_param_to_list(struct _parameter **param_list, struct _parameter *param, int *err_code) { + EM_DEBUG_FUNC_BEGIN("param_list[%p], param[%p]", param_list, *param_list); struct _parameter **t = param_list; while (*t && (*t)->next) @@ -1702,12 +1696,12 @@ INTERNAL_FUNC int emcore_decode_body_text(char *enc_buf, int enc_len, int enc_ty 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; @@ -1743,7 +1737,7 @@ INTERNAL_FUNC int emcore_decode_body_text(char *enc_buf, int enc_len, int enc_ty /* mode - SAVE_TYPE_SIZE : no saving (only hold content size */ /* SAVE_TYPE_BUFFER : content is saved to buffer (holder is buffer */ /* SAVE_TYPE_FILE : content is saved to temporary file (holder is file name */ -int emcore_mime_get_content_data(void *stream, int is_file, int is_text, char *boundary_str, char *content_encoding, int *end_of_parsing, int mode, char **holder, int *size, void *callback, int *err_code) +int emcore_mime_get_content_data(void *stream, int is_file, char *boundary_str, char *content_encoding, int *end_of_parsing, int mode, char **holder, int *size, void *callback, int *err_code) { EM_DEBUG_FUNC_BEGIN_SEC("stream[%p], is_file[%d], boundary_str[%s], content_encoding[%s], end_of_parsing[%p], mode[%d], holder[%p], size[%p], callback[%p], err_code[%p]", stream, is_file, boundary_str, content_encoding, end_of_parsing, mode, holder, size, callback, err_code); @@ -1797,16 +1791,16 @@ int emcore_mime_get_content_data(void *stream, int is_file, int is_text, char *b 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."); + error = em_open(*holder, O_WRONLY|O_CREAT, 0644, &fd); + if (error != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("holder em_open failed : holder is a filename that will be saved."); goto FINISH_OFF; } } if (is_file) { EM_DEBUG_LOG("from file"); - error = emcore_decode_body_text_from_file((FILE *)stream, boundary_str, encoding, mode, is_text, fd, holder, end_of_parsing, &sz); + error = emcore_decode_body_text_from_file((FILE *)stream, boundary_str, encoding, mode, fd, holder, end_of_parsing, &sz); if (error != EMAIL_ERROR_NONE) { if (error != EMAIL_ERROR_NO_MORE_DATA) { EM_DEBUG_EXCEPTION("emcore_decode_body_text_from_file failed : [%d]", error); @@ -1815,7 +1809,7 @@ int emcore_mime_get_content_data(void *stream, int is_file, int is_text, char *b } } else { EM_DEBUG_LOG("from sock"); - error = emcore_decode_body_text_from_sock(stream, boundary_str, encoding, mode, is_text, fd, holder, end_of_parsing, &sz); + error = emcore_decode_body_text_from_sock(stream, boundary_str, encoding, mode, fd, holder, end_of_parsing, &sz); if (error != EMAIL_ERROR_NONE) { EM_DEBUG_EXCEPTION("emcore_decode_body_text_from_sock failed : [%d]", error); goto FINISH_OFF; @@ -1827,7 +1821,7 @@ FINISH_OFF: if (err_code != NULL) *err_code = error; - if(fd>0) close(fd); /*prevent 32736*/ + EM_SAFE_CLOSE (fd); /*prevent 32736*/ if (ret) { if (size) @@ -1858,12 +1852,13 @@ int emcore_mime_skip_content_data(void *stream, if (!boundary_str) { /* if no boundary, this content is from current line to end of all multipart */ while (TRUE) { - +/* Several threads including event thd call it, don't delete comment if (!emcore_check_thread_status()) { if (err_code != NULL) *err_code = EMAIL_ERROR_CANCELLED; return false; } +*/ if ((is_file == 0 && !emcore_mime_get_line_from_sock(stream, buf, MIME_LINE_LEN, err_code)) || (is_file == 1 && !emcore_get_line_from_file(stream, buf, MIME_LINE_LEN, err_code))) { *end_of_parsing = 1; @@ -1882,12 +1877,13 @@ int emcore_mime_skip_content_data(void *stream, SNPRINTF(boundary_end, BOUNDARY_LEN, "--%s%s", boundary_str, "--\r\n"); while (TRUE) { - +/* Several threads including event thd call it, don't delete comment if (!emcore_check_thread_status()) { if (err_code != NULL) *err_code = EMAIL_ERROR_CANCELLED; return false; } +*/ if ((is_file == 0 && !emcore_mime_get_line_from_sock(stream, buf, MIME_LINE_LEN, err_code)) || (is_file == 1 && !emcore_get_line_from_file(stream, buf, MIME_LINE_LEN, err_code))) { /* end of fil */ @@ -2059,6 +2055,8 @@ void emcore_mime_free_part_header(struct _m_part_header *header) EM_SAFE_FREE (header->disp_type); EM_SAFE_FREE (header->content_id); EM_SAFE_FREE (header->content_location); + EM_SAFE_FREE (header->priority); + EM_SAFE_FREE (header->ms_priority); if (header->disp_parameter) emcore_mime_free_param(header->disp_parameter); EM_SAFE_FREE (header); EM_DEBUG_FUNC_END(); @@ -2128,49 +2126,6 @@ void emcore_mime_free_mime(struct _m_mesg *mmsg) EM_DEBUG_FUNC_END(); } -void emcore_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); - EM_SAFE_FREE(cnt_info->text.html_charset); - while (cnt_info->file) { - p = cnt_info->file->next; - EM_SAFE_FREE(cnt_info->file->name); - EM_SAFE_FREE(cnt_info->file->save); - EM_SAFE_FREE(cnt_info->file->attachment_mime_type); - EM_SAFE_FREE(cnt_info->file->content_id); - EM_SAFE_FREE(cnt_info->file); - cnt_info->file = p; - } - - EM_DEBUG_FUNC_END(); -} - -void emcore_free_attachment_info(struct attachment_info *attchment) -{ - EM_DEBUG_FUNC_BEGIN(); - struct attachment_info *p; - - if (!attchment) return; - - while (attchment) { - p = attchment->next; - EM_SAFE_FREE(attchment->name); - EM_SAFE_FREE(attchment->save); - EM_SAFE_FREE(attchment->attachment_mime_type); - EM_SAFE_FREE(attchment->content_id); - EM_SAFE_FREE(attchment); - attchment = p; - } - - EM_DEBUG_FUNC_END(); -} - /* get body-part in nested part */ static PARTLIST *emcore_get_allnested_part_full(MAILSTREAM *stream, int msg_uid, BODY *body, struct _m_content_info *cnt_info, int *err_code, PARTLIST *section_list) { @@ -2258,7 +2213,7 @@ PARTLIST* emcore_get_body_full(MAILSTREAM *stream, int msg_uid, BODY *body, stru EM_DEBUG_FUNC_BEGIN("stream[%p], msg_uid[%d], body[%p], cnt_info[%p], err_code[%p]", stream, msg_uid, body, cnt_info, err_code); char content_type_buffer[512] = { 0, }; - if (!stream || !body || !cnt_info) { + if (!stream || !body || !cnt_info) { EM_DEBUG_EXCEPTION("stream[%p], msg_uid[%d], body[%p], cnt_info[%p]", stream, msg_uid, body, cnt_info); if (err_code != NULL) *err_code = EMAIL_ERROR_INVALID_PARAM; @@ -2266,7 +2221,7 @@ PARTLIST* emcore_get_body_full(MAILSTREAM *stream, int msg_uid, BODY *body, stru return NULL; } - switch (body->type) { + switch (body->type) { case TYPEMULTIPART: section_list = emcore_get_multi_part_full(stream, msg_uid, body, cnt_info, err_code, section_list); EM_DEBUG_FUNC_END("section_list [%p]", section_list); @@ -2307,10 +2262,14 @@ PARTLIST* emcore_get_body_full(MAILSTREAM *stream, int msg_uid, BODY *body, stru return NULL; } - if ((body->id) || (body->location) || ((body->disposition.type != NULL) && ((body->disposition.type[0] == 'i') || (body->disposition.type[0] == 'I')))) - ai->type = 1; /* inline contents */ - else - ai->type = 2; /* attachment */ + if (body->disposition.type != NULL && ((body->disposition.type[0] == 'a') || (body->disposition.type[0] == 'A'))) { + ai->type = ATTACHMENT; /* attachment */ + } else { + if ((body->id) || (body->location) || ((body->disposition.type != NULL) && ((body->disposition.type[0] == 'i') || (body->disposition.type[0] == 'I')))) + ai->type = INLINE_ATTACHMENT; /* inline contents */ + else + ai->type = ATTACHMENT; /* attachment */ + } ai->name = EM_SAFE_STRDUP(filename); ai->size = body->size.bytes; @@ -2343,9 +2302,9 @@ PARTLIST* emcore_get_body_full(MAILSTREAM *stream, int msg_uid, BODY *body, stru } else { while(current_ai->next != NULL) { if (ai->type == ATTACHMENT) { - if (current_ai->type == INLINE_ATTACHMENT) + if (current_ai->type == INLINE_ATTACHMENT) break; - } + } prev_ai = current_ai; current_ai = current_ai->next; @@ -2466,8 +2425,6 @@ INTERNAL_FUNC int emcore_get_body_part_list_full(MAILSTREAM *stream, int msg_uid static int emcore_write_response_into_file(char *filename, char *write_mode, char *encoded, int encoding_type, char *subtype, int account_id, int mail_id, int *err) { EM_DEBUG_FUNC_BEGIN(); - int temp_decoded_len = 0; - int inline_support = 0; int ret = false; int error = EMAIL_ERROR_NONE; int not_found = true; @@ -2518,6 +2475,7 @@ static int emcore_write_response_into_file(char *filename, char *write_mode, cha if(!decoded) { EM_DEBUG_EXCEPTION("em_malloc failed"); error = EMAIL_ERROR_OUT_OF_MEMORY; + g_free(orignal); goto FINISH_OFF; } memcpy(decoded, orignal, encoded_len + 3); @@ -2531,9 +2489,9 @@ static int emcore_write_response_into_file(char *filename, char *write_mode, cha EM_DEBUG_LOG("Decoded Length [%d] " , decoded_len); EM_DEBUG_LOG_SEC("filename [%s] " , filename); - if (!(fp = fopen(filename, write_mode))) { - EM_DEBUG_EXCEPTION_SEC("fopen failed - %s", filename); - error = EMAIL_ERROR_SYSTEM_FAILURE; /*prevent 28347*/ + error = em_fopen(filename, write_mode, &fp); + if (error != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION_SEC("em_fopen failed - %s", filename); goto FINISH_OFF; } @@ -2566,6 +2524,8 @@ static int emcore_write_response_into_file(char *filename, char *write_mode, cha else memcpy(body_inline_id, body_inline->id , EM_SAFE_STRLEN(body_inline->id)); + /* Handle the 'space__content_id(example : (yahoo : content_id: __abcdefgh__ijkl...) */ + em_trim_left(body_inline_id); EM_DEBUG_LOG_SEC("Inline body_inline_id [%s] ", body_inline_id); if ((param || param1) && 0 == strncmp(body_inline_id , decoded_content_id + strlen("cid:"), EM_SAFE_STRLEN(body_inline_id))) { @@ -2587,7 +2547,6 @@ static int emcore_write_response_into_file(char *filename, char *write_mode, cha decoded = decoded_temp; decoded_len = EM_SAFE_STRLEN(decoded); EM_DEBUG_LOG("Decoded Length [%d] ", decoded_len); - inline_support = 1; not_found = false; /* only_body_download = false */ break; @@ -2608,10 +2567,8 @@ static int emcore_write_response_into_file(char *filename, char *write_mode, cha /* EM_DEBUG_LOG(">>>> decoded_temp 2 [ %s ] ", decoded_temp) */ EM_SAFE_FREE(decoded); decoded = decoded_temp; - temp_decoded_len = EM_SAFE_STRLEN(body_inline_id); decoded_len = EM_SAFE_STRLEN(decoded); EM_DEBUG_LOG("Decoded Length [%d] ", decoded_len); - inline_support = 1; } } } @@ -2637,7 +2594,7 @@ static int emcore_write_response_into_file(char *filename, char *write_mode, cha ret = true; FINISH_OFF: - + if (err) *err = error; @@ -2703,11 +2660,13 @@ static int imap_mail_write_body_to_file(MAILSTREAM *stream, int account_id, int goto FINISH_OFF; } +/* don't delete the comment. several threads including event thread call it FINISH_OFF_IF_CANCELED; +*/ - if (!(fp = fopen(filepath, "wb+"))) { - EM_DEBUG_EXCEPTION_SEC("fopen failed - %s", filepath); - err = EMAIL_ERROR_SYSTEM_FAILURE; + err = em_fopen(filepath, "wb+", &fp); + if (err != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION_SEC("fopen failed - %s : [%d]", filepath, err); goto FINISH_OFF; } @@ -2738,17 +2697,14 @@ static int imap_mail_write_body_to_file(MAILSTREAM *stream, int account_id, int while (imaplocal->netstream) { +/* don't delete the comment. several threads including event thread call this func if (!emcore_check_thread_status()) { EM_DEBUG_LOG("Canceled..."); - /* Is it realy required ? It might cause crashes. - if (imaplocal->netstream) - net_close (imaplocal->netstream); - */ imaplocal->netstream = NULL; err = EMAIL_ERROR_CANCELLED; goto FINISH_OFF; } - +*/ /* receive response */ if (!(response = net_getline(imaplocal->netstream))) { EM_DEBUG_EXCEPTION("net_getline failed..."); @@ -2831,13 +2787,14 @@ static int imap_mail_write_body_to_file(MAILSTREAM *stream, int account_id, int EM_DEBUG_LOG("server_uid [%s]", server_uid); EM_DEBUG_LOG("mail_id [%d]", mail_id); +/* don't delete the comment. several threads including event thread call it if (!emcore_check_thread_status()) { EM_DEBUG_LOG("Canceled..."); imaplocal->netstream = NULL; err = EMAIL_ERROR_CANCELLED; goto FINISH_OFF; } - +*/ if (is_attachment) { EM_DEBUG_LOG("Attachment number [%d]", is_attachment); if (!emcore_notify_network_event(NOTI_DOWNLOAD_ATTACH_START, mail_id, filename, is_attachment, 0)) @@ -2860,10 +2817,6 @@ static int imap_mail_write_body_to_file(MAILSTREAM *stream, int account_id, int } } - if (_imap4_download_noti_interval_value > DOWNLOAD_NOTI_INTERVAL_SIZE) { - _imap4_download_noti_interval_value = DOWNLOAD_NOTI_INTERVAL_SIZE; - } - /* remove new lines */ do { EM_SAFE_FREE(response); @@ -2878,6 +2831,7 @@ static int imap_mail_write_body_to_file(MAILSTREAM *stream, int account_id, int EM_DEBUG_LOG("Skip newline !!"); nskip++; } else { + EM_SAFE_FREE (new_response); /* detected by valgrind */ new_response = g_strconcat(response, "\r\n", NULL); EM_SAFE_FREE(response); break; @@ -2887,10 +2841,46 @@ static int imap_mail_write_body_to_file(MAILSTREAM *stream, int account_id, int preline_len = EM_SAFE_STRLEN(new_response); EM_DEBUG_LOG("preline_len : %d", preline_len); - if (body_size - preline_len - nskip*2 <= 0) + if (body_size - preline_len - nskip*2 < 0) continue; - if (body_size - preline_len - nskip*2 < DOWNLOAD_MAX_BUFFER_SIZE) { + if ((body_size - preline_len -nskip*2) == 0) { + /* 1 line content */ + if (!emcore_write_response_into_file(filepath, "wb+", new_response, encoding, section_subtype, account_id, mail_id, &err)) { + EM_DEBUG_EXCEPTION("write_response_into_file failed [%d]", err); + goto FINISH_OFF; + } + + total = preline_len; + EM_DEBUG_LOG("total = %d", total); + EM_DEBUG_LOG_SEC("write_response_into_file successful %s.....", filename); + + /* In some situation, total_encoded_len includes the length of dummy bytes. So it might be greater than body_size */ + + _imap4_received_body_size += total; + EM_DEBUG_LOG("DOWNLOADING STATUS NOTIFY : received_body[%d] / total_body[%d] = %d %% Completed.", + _imap4_received_body_size, _imap4_total_body_size, 100*_imap4_received_body_size/_imap4_total_body_size); + + if (((_imap4_last_notified_body_size + _imap4_download_noti_interval_value) <= _imap4_received_body_size) + || (_imap4_received_body_size >= _imap4_total_body_size)) { + + _imap4_last_notified_body_size = _imap4_received_body_size; + + if (is_attachment) { + if (_imap4_total_body_size && !emcore_notify_network_event(NOTI_DOWNLOAD_ATTACH_START, mail_id, filename, is_attachment, 100 *total/body_size)) + EM_DEBUG_EXCEPTION("emcore_notify_network_event [ NOTI_DOWNLOAD_ATTACH_START] Failed >>>>"); + } else { + if (multi_part_body_size) { + if (!emcore_notify_network_event(NOTI_DOWNLOAD_MULTIPART_BODY, mail_id, filename, _imap4_total_body_size, _imap4_received_body_size)) + EM_DEBUG_EXCEPTION("emcore_notify_network_event [ NOTI_DOWNLOAD_BODY_START] Failed >>>>"); + } else { + if (!emcore_notify_network_event(NOTI_DOWNLOAD_BODY_START, mail_id, filename, _imap4_total_body_size, _imap4_received_body_size)) + EM_DEBUG_EXCEPTION("emcore_notify_network_event [ NOTI_DOWNLOAD_BODY_START] Failed >>>>"); + } + } + } + } + else if (body_size - preline_len - nskip*2 < DOWNLOAD_MAX_BUFFER_SIZE) { memset(encoded, 0x00, sizeof(encoded)); if (net_getbuffer(imaplocal->netstream, body_size - preline_len - nskip*2, (char *)encoded) <= 0) { EM_DEBUG_EXCEPTION("net_getbuffer failed..."); @@ -2915,24 +2905,30 @@ static int imap_mail_write_body_to_file(MAILSTREAM *stream, int account_id, int /* In some situation, total_encoded_len includes the length of dummy bytes. So it might be greater than body_size */ _imap4_received_body_size += total; - _imap4_last_notified_body_size = _imap4_received_body_size; EM_DEBUG_LOG("DOWNLOADING STATUS NOTIFY : received_body[%d] / total_body[%d] = %d %% Completed.", _imap4_received_body_size, _imap4_total_body_size, 100*_imap4_received_body_size/_imap4_total_body_size); - if (is_attachment) { - if (_imap4_total_body_size && !emcore_notify_network_event(NOTI_DOWNLOAD_ATTACH_START, mail_id, filename, is_attachment, 100 *total/body_size)) - EM_DEBUG_EXCEPTION("emcore_notify_network_event [ NOTI_DOWNLOAD_ATTACH_START] Failed >>>>"); - } else { - if (multi_part_body_size) { - if (!emcore_notify_network_event(NOTI_DOWNLOAD_MULTIPART_BODY, mail_id, filename, _imap4_total_body_size, _imap4_received_body_size)) - EM_DEBUG_EXCEPTION("emcore_notify_network_event [ NOTI_DOWNLOAD_BODY_START] Failed >>>>"); + if (((_imap4_last_notified_body_size + _imap4_download_noti_interval_value) <= _imap4_received_body_size) + || (_imap4_received_body_size >= _imap4_total_body_size)) { + + _imap4_last_notified_body_size = _imap4_received_body_size; + + if (is_attachment) { + if (_imap4_total_body_size && !emcore_notify_network_event(NOTI_DOWNLOAD_ATTACH_START, mail_id, filename, is_attachment, 100 *total/body_size)) + EM_DEBUG_EXCEPTION("emcore_notify_network_event [ NOTI_DOWNLOAD_ATTACH_START] Failed >>>>"); } else { - if (!emcore_notify_network_event(NOTI_DOWNLOAD_BODY_START, mail_id, filename, _imap4_total_body_size, _imap4_received_body_size)) - EM_DEBUG_EXCEPTION("emcore_notify_network_event [ NOTI_DOWNLOAD_BODY_START] Failed >>>>"); + if (multi_part_body_size) { + if (!emcore_notify_network_event(NOTI_DOWNLOAD_MULTIPART_BODY, mail_id, filename, _imap4_total_body_size, _imap4_received_body_size)) + EM_DEBUG_EXCEPTION("emcore_notify_network_event [ NOTI_DOWNLOAD_BODY_START] Failed >>>>"); + } else { + if (!emcore_notify_network_event(NOTI_DOWNLOAD_BODY_START, mail_id, filename, _imap4_total_body_size, _imap4_received_body_size)) + EM_DEBUG_EXCEPTION("emcore_notify_network_event [ NOTI_DOWNLOAD_BODY_START] Failed >>>>"); + } } } - } else { + } + else { int remain_body_size = body_size - preline_len - nskip*2; int x = 0; int nsize = 0; @@ -2987,8 +2983,8 @@ static int imap_mail_write_body_to_file(MAILSTREAM *stream, int account_id, int if (total > body_size) _imap4_received_body_size = body_size; - _imap4_last_notified_body_size = _imap4_received_body_size; +/* don't delete the comment. it can be called by several threads if (!emcore_check_thread_status()) { EM_DEBUG_LOG("Canceled..."); imaplocal->netstream = NULL; @@ -2996,19 +2992,25 @@ static int imap_mail_write_body_to_file(MAILSTREAM *stream, int account_id, int goto FINISH_OFF; } - EM_DEBUG_LOG("DOWNLOADING STATUS NOTIFY : Total[%d] / [%d] = %d %% Completed.\n", total, body_size, 100*total/body_size); +*/ EM_DEBUG_LOG("DOWNLOADING STATUS NOTIFY : Total[%d] / [%d] = %d %% Completed.\n", total, body_size, 100*total/body_size); - if (is_attachment) { - if (!emcore_notify_network_event(NOTI_DOWNLOAD_ATTACH_START, mail_id, filename, is_attachment, 100*total/body_size)) - EM_DEBUG_EXCEPTION("emcore_notify_network_event [ NOTI_DOWNLOAD_ATTACH_START] Failed >>>>"); - } else { - if (multi_part_body_size) { - /* EM_DEBUG_LOG("DOWNLOADING.......... : Multipart body size is [%d]", multi_part_body_size) */ - if (!emcore_notify_network_event(NOTI_DOWNLOAD_MULTIPART_BODY, mail_id, filename, _imap4_total_body_size, _imap4_received_body_size)) - EM_DEBUG_EXCEPTION("emcore_notify_network_event [ NOTI_DOWNLOAD_BODY_START] Failed >>>>"); + if (((_imap4_last_notified_body_size + _imap4_download_noti_interval_value) <= _imap4_received_body_size) + || (_imap4_received_body_size >= _imap4_total_body_size)) { + + _imap4_last_notified_body_size = _imap4_received_body_size; + + if (is_attachment) { + if (!emcore_notify_network_event(NOTI_DOWNLOAD_ATTACH_START, mail_id, filename, is_attachment, 100*total/body_size)) + EM_DEBUG_EXCEPTION("emcore_notify_network_event [ NOTI_DOWNLOAD_ATTACH_START] Failed >>>>"); } else { - if (!emcore_notify_network_event(NOTI_DOWNLOAD_BODY_START, mail_id, filename, _imap4_total_body_size, _imap4_received_body_size)) - EM_DEBUG_EXCEPTION("emcore_notify_network_event [ NOTI_DOWNLOAD_BODY_START] Failed >>>>"); + if (multi_part_body_size) { + /* EM_DEBUG_LOG("DOWNLOADING.......... : Multipart body size is [%d]", multi_part_body_size) */ + if (!emcore_notify_network_event(NOTI_DOWNLOAD_MULTIPART_BODY, mail_id, filename, _imap4_total_body_size, _imap4_received_body_size)) + EM_DEBUG_EXCEPTION("emcore_notify_network_event [ NOTI_DOWNLOAD_BODY_START] Failed >>>>"); + } else { + if (!emcore_notify_network_event(NOTI_DOWNLOAD_BODY_START, mail_id, filename, _imap4_total_body_size, _imap4_received_body_size)) + EM_DEBUG_EXCEPTION("emcore_notify_network_event [ NOTI_DOWNLOAD_BODY_START] Failed >>>>"); + } } } } @@ -3056,6 +3058,8 @@ static int imap_mail_write_body_to_file(MAILSTREAM *stream, int account_id, int FINISH_OFF: EM_SAFE_FREE(decoded); EM_SAFE_FREE(response); + EM_SAFE_FREE (file_id); /* detected by valgrind */ + EM_SAFE_FREE (new_response); /* detected by valgrind */ if (fp != NULL) fclose(fp); @@ -3108,39 +3112,37 @@ static int emcore_get_body_part_imap_full(MAILSTREAM *stream, int msg_uid, int a goto FINISH_OFF; } - if (section_list != NULL) { - PARTLIST *temp = section_list; + PARTLIST *temp = section_list; - if (cnt_info->grab_type == GRAB_TYPE_ATTACHMENT) { - /* to download attachment */ - body = temp->body; - if (body->sparep != NULL) { - snprintf(sections, sizeof(sections), "BODY.PEEK[%s]", (char *)body->sparep); - } else { - EM_DEBUG_EXCEPTION("body->sparep can not be null. "); - return_value = -1; - goto FINISH_OFF; - } + if (cnt_info->grab_type == GRAB_TYPE_ATTACHMENT) { + /* to download attachment */ + body = temp->body; + if (body->sparep != NULL) { + snprintf(sections, sizeof(sections), "BODY.PEEK[%s]", (char *)body->sparep); } else { - while (temp != NULL) { - char t[64] = {0,}; - body = temp->body; - - if ((body->type == TYPETEXT) || (body->id != NULL) || ((body->disposition.type != NULL) && ((body->disposition.type[0] == 'i') || (body->disposition.type[0] == 'I')))) { - snprintf(t, sizeof(t), "BODY.PEEK[%s] ", (char *)body->sparep); /* body parts seperated by period */ - if (EM_SAFE_STRLEN(sections) + EM_SAFE_STRLEN(t) < sizeof(sections)) - strcat(sections, t); - else { - EM_DEBUG_EXCEPTION("Too many body parts. IMAP command may cross 2000bytes."); - break; - } + EM_DEBUG_EXCEPTION("body->sparep can not be null. "); + return_value = -1; + goto FINISH_OFF; + } + } else { + while (temp != NULL) { + char t[64] = {0,}; + body = temp->body; + + if ((body->type == TYPETEXT) || (body->id != NULL) || ((body->disposition.type != NULL) && ((body->disposition.type[0] == 'i') || (body->disposition.type[0] == 'I')))) { + snprintf(t, sizeof(t), "BODY.PEEK[%s] ", (char *)body->sparep); /* body parts seperated by period */ + if (EM_SAFE_STRLEN(sections) + EM_SAFE_STRLEN(t) < sizeof(sections)) + strcat(sections, t); + else { + EM_DEBUG_EXCEPTION("Too many body parts. IMAP command may cross 2000bytes."); + break; } - temp = (PARTLIST *)temp->next; } + temp = (PARTLIST *)temp->next; } } - if (sections[EM_SAFE_STRLEN(sections)-1] == ' ') { + if (EM_SAFE_STRLEN (sections) > 0 && sections[EM_SAFE_STRLEN(sections)-1] == ' ') { /*prevent 32317*/ sections[EM_SAFE_STRLEN(sections)-1] = '\0'; } @@ -3212,7 +3214,7 @@ static int emcore_get_body_part_imap_full(MAILSTREAM *stream, int msg_uid, int a goto FINISH_OFF; } - EM_DEBUG_LOG("temp filename :%s", buf); + EM_DEBUG_LOG_SEC("temp filename :%s", buf); /* notifying UI start */ /* parse_file_path_to_filename(buf, &file_id); */ @@ -3229,6 +3231,7 @@ static int emcore_get_body_part_imap_full(MAILSTREAM *stream, int msg_uid, int a while (param) { if (!strcasecmp(param->attribute, "CHARSET")) { + EM_SAFE_FREE (cnt_info->text.plain_charset); /* detected by valgrind */ cnt_info->text.plain_charset = EM_SAFE_STRDUP(param->value); break; } @@ -3256,7 +3259,8 @@ static int emcore_get_body_part_imap_full(MAILSTREAM *stream, int msg_uid, int a } } - FINISH_OFF_IF_CANCELED; + if (event_handle > 0) + FINISH_OFF_IF_EVENT_CANCELED (err, event_handle); if (cnt_info->grab_type == GRAB_TYPE_ATTACHMENT) { if (!emcore_notify_network_event(NOTI_DOWNLOAD_ATTACH_START, mail_id, buf, cnt_info->file_no, 0)) @@ -3459,12 +3463,12 @@ static int emcore_get_body_part_imap_full(MAILSTREAM *stream, int msg_uid, int a static int _find_duplicated_inline_content_file(char *input_source_file_name, struct _m_content_info *input_content_info, bool *output_result) { - EM_DEBUG_FUNC_BEGIN("input_source_file_name [%p], input_content_info [%p], output_result [%p]", input_source_file_name,input_content_info, output_result); + EM_DEBUG_FUNC_BEGIN("input_source_file_name [%s], input_content_info [%p], output_result [%p]", input_source_file_name,input_content_info, output_result); struct attachment_info *cur_attachment_info = NULL; int err = EMAIL_ERROR_NONE; bool result = false; - if(!input_source_file_name || !input_content_info || !output_result) { + if(!input_source_file_name || !input_content_info || !output_result || strlen(input_source_file_name) <= 0) { EM_DEBUG_EXCEPTION("Invalid parameter"); return EMAIL_ERROR_INVALID_PARAM; } @@ -3487,7 +3491,7 @@ static int _find_duplicated_inline_content_file(char *input_source_file_name, st static int _modify_file_name_string_for_duplicated_inline_content(char *input_source_file_name, struct _m_content_info *input_content_info) { - EM_DEBUG_FUNC_BEGIN("input_source_file_name [%p], input_content_info [%p]", input_source_file_name,input_content_info); + EM_DEBUG_FUNC_BEGIN("input_source_file_name [%s], input_content_info [%p]", input_source_file_name,input_content_info); int err = EMAIL_ERROR_NONE; char temp_file_name[MAX_PATH] = { 0, }; char *file_name = NULL; @@ -3840,12 +3844,6 @@ INTERNAL_FUNC int emcore_get_utf8_address(char **dest, ADDRESS *address, int *er char *nickname = NULL; while (address) { - EM_DEBUG_LOG_SEC("address->mailbox[%s], address->host[%s]", address->mailbox, address->host); - if (!address->mailbox || !address->host) { - address = address->next; - continue; - } - EM_DEBUG_LOG_DEV("address->mailbox[%p]", address->personal); if (address->personal) { if (!(nickname = emcore_decode_rfc2047_text(address->personal, &err))) { EM_DEBUG_EXCEPTION("emcore_decode_rfc2047_text failed - %d", err); @@ -3853,24 +3851,28 @@ INTERNAL_FUNC int emcore_get_utf8_address(char **dest, ADDRESS *address, int *er } EM_DEBUG_LOG_DEV("nickname[%s]", nickname); if (*nickname != '\0') - utf8_address = g_strdup_printf("\"%s\" <%s@%s>", nickname, address->mailbox ? address->mailbox : "", address->host ? address->host : ""); + utf8_address = g_strdup_printf("\"%s\" <%s%s%s>", nickname, address->mailbox ? address->mailbox : "", address->host ? "@": "", address->host ? address->host : ""); else - utf8_address = g_strdup_printf("<%s@%s>", address->mailbox ? address->mailbox : "", address->host ? address->host : ""); + utf8_address = g_strdup_printf("<%s%s%s>", address->mailbox ? address->mailbox : "", address->host ? "@" : "", address->host ? address->host : ""); EM_SAFE_FREE(nickname); } - else - utf8_address = g_strdup_printf("<%s@%s>", address->mailbox ? address->mailbox : "", address->host ? address->host : ""); + else { + if (address->mailbox || address->host) + utf8_address = g_strdup_printf("<%s%s%s>", address->mailbox ? address->mailbox : "", address->host ? "@" : "", address->host ? address->host : ""); + } EM_DEBUG_LOG_DEV("utf8_address[%s]", utf8_address); - if (concatenated != NULL) { - temp = concatenated; - concatenated = g_strdup_printf("%s; %s", temp, utf8_address); - g_free(temp); + if (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); } - else - concatenated = g_strdup(utf8_address); g_free(utf8_address); utf8_address = NULL; @@ -4014,7 +4016,7 @@ FINISH_OFF: /* *download body part of imap mail (body-text and attachment) */ -static int emcore_get_body_part_imap(MAILSTREAM *stream, int account_id, int mail_id, int msg_uid, BODY *body, struct _m_content_info *cnt_info, int *err_code) +static int emcore_get_body_part_imap(MAILSTREAM *stream, int account_id, int mail_id, int msg_uid, BODY *body, char *part_body_type, struct _m_content_info *cnt_info, int *err_code) { EM_DEBUG_FUNC_BEGIN("stream[%p], msg_uid[%d], body[%p], cnt_info[%p], err_code[%p]", stream, msg_uid, body, cnt_info, err_code); @@ -4027,6 +4029,7 @@ static int emcore_get_body_part_imap(MAILSTREAM *stream, int account_id, int mai char filename[MAX_PATH + 1] = { 0, }; char *decoded_filename = NULL; int is_attachment = 0; + int attachment_type = 0; int o_data_len = 0; char charset_value_buffer[512] = { 0, }; char content_type_buffer[512] = { 0, }; @@ -4034,14 +4037,13 @@ static int emcore_get_body_part_imap(MAILSTREAM *stream, int account_id, int mai 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; + int search_result = false; /* } is_pb */ - EM_DEBUG_LOG("Grab Type [ %d ] ", cnt_info->grab_type); + /* unknown type */ if (body->type > TYPEOTHER) { /* unknown type */ @@ -4068,17 +4070,17 @@ static int emcore_get_body_part_imap(MAILSTREAM *stream, int account_id, int mai return FAILURE; } - if (body->subtype[0] == 'H') /* HTM */ - cnt_info->text.html = o_data; + if (body->subtype[0] == 'H' || body->subtype[0] == 'h') + cnt_info->text.html = EM_SAFE_STRDUP(o_data); else - cnt_info->text.plain = o_data; + cnt_info->text.plain = EM_SAFE_STRDUP(o_data); memset(charset_value_buffer, 0, 512); if (emcore_get_attribute_value_of_body_part(body->parameter, "CHARSET", charset_value_buffer, 512, true, &err)) { EM_SAFE_FREE(cnt_info->text.plain_charset); cnt_info->text.plain_charset = EM_SAFE_STRDUP(charset_value_buffer); - EM_DEBUG_LOG_SEC(">>>>> CHARSET [%s] ", filename); + } } } /* is_pbd */ @@ -4151,12 +4153,9 @@ static int emcore_get_body_part_imap(MAILSTREAM *stream, int account_id, int mai 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 = emcore_decode_rfc2047_text(body->location, &err); strncpy(filename, decoded_filename, MAX_PATH); EM_SAFE_FREE(decoded_filename); @@ -4164,7 +4163,6 @@ static int emcore_get_body_part_imap(MAILSTREAM *stream, int account_id, int mai } 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)) { @@ -4222,24 +4220,17 @@ static int emcore_get_body_part_imap(MAILSTREAM *stream, int account_id, int mai 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 (emcore_get_attribute_value_of_body_part(body->disposition.parameter, "filename", filename, MAX_PATH, true, &err)) EM_DEBUG_LOG_SEC(">>>>> FILENAME [%s] ", filename); if (!*filename) { /* If the part has no filename, it may be report ms */ - if ((body->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 */ { + if (body->parameter) /* Fix for the MMS attachment File name as unknown */ { char *extcheck = NULL; if (emcore_get_attribute_value_of_body_part(body->parameter, "NAME", filename, MAX_PATH, true, &err)) @@ -4251,7 +4242,7 @@ static int emcore_get_body_part_imap(MAILSTREAM *stream, int account_id, int mai EM_DEBUG_LOG(">>>> Extension Exist in the Attachment [ %s ] ", extcheck); else { /* No extension attached , So add the Extension based on the subtype */ if (body->subtype) { - if (EM_SAFE_STRLEN(filename) + EM_SAFE_STRLEN(body->subtype) + 1 < MAX_PATH) { + if (EM_SAFE_STRLEN(filename) + strlen(body->subtype) + 1 < MAX_PATH) { strcat(filename, "."); strcat(filename, body->subtype); } @@ -4265,10 +4256,6 @@ static int emcore_get_body_part_imap(MAILSTREAM *stream, int account_id, int mai else strncpy(filename, "unknown", MAX_PATH); } - else { - if ((body->disposition.type[0] == 'i' || body->disposition.type[0] == 'I')) - is_attachment = 0; - } } else { char *attr_upper = NULL; @@ -4279,6 +4266,7 @@ static int emcore_get_body_part_imap(MAILSTREAM *stream, int account_id, int mai EM_DEBUG_LOG_DEV("BODY-PARAM-ATTRIBUTE:%s", param->attribute); EM_DEBUG_LOG_DEV("BODY-PARAM-VALUE:%s", param->value); + EM_SAFE_FREE(attr_upper); /* valgrind */ attr_upper = g_ascii_strup(param->attribute, -1); if (g_strcmp0(attr_upper, "NAME") == 0) { decoded_value = emcore_decode_rfc2047_text(param->value, &err); @@ -4302,18 +4290,29 @@ static int emcore_get_body_part_imap(MAILSTREAM *stream, int account_id, int mai decoded_filename = emcore_decode_rfc2047_text(filename, &err); strncpy(filename, decoded_filename, MAX_PATH); EM_SAFE_FREE(decoded_filename); - EM_DEBUG_LOG_SEC("filename [%s]", filename); + + } + } + + /* the subtype of content-type is related and the dispostion type is attachment or inline, It is inline attachment */ + if (part_body_type != NULL) { + if ((part_body_type[0] == 'R' || part_body_type[0] == 'r') && body->disposition.type) { + attachment_type = INLINE_ATTACHMENT; + is_attachment = 1; + } else if ((part_body_type[0] == 'M' || part_body_type[0] == 'm') && body->disposition.type) { + /* the subtype of content-type is mixed and the dispostion type is attachment , It is attachment */ + attachment_type = ATTACHMENT; + is_attachment = 1; } } - 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); - EM_DEBUG_LOG("grab_type : [%d]", cnt_info->grab_type); if (((cnt_info->grab_type & GRAB_TYPE_TEXT) && (body->type == TYPEMESSAGE || body->type == TYPETEXT || body->type == TYPEIMAGE)) || (cnt_info->grab_type & GRAB_TYPE_ATTACHMENT)) { - if (is_pbd) + if (is_pbd) { + EM_SAFE_FREE(o_data); return SUCCESS; + } else { /* fetch body */ if (!emcore_get_temp_file_name(&o_data, &err)) { EM_DEBUG_EXCEPTION("emcore_get_temp_file_name failed [%d]", err); @@ -4334,11 +4333,13 @@ static int emcore_get_body_part_imap(MAILSTREAM *stream, int account_id, int mai 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; + + if (body->subtype[0] == 'H') { + EM_SAFE_FREE(cnt_info->text.html); + cnt_info->text.html = EM_SAFE_STRDUP(o_data); + } else { + EM_SAFE_FREE(cnt_info->text.plain); + cnt_info->text.plain = EM_SAFE_STRDUP(o_data); memset(charset_value_buffer, 0, 512); /*check: cnt_info->text.plain_charset is malloc'd twice */ if (emcore_get_attribute_value_of_body_part(body->parameter, "CHARSET", charset_value_buffer, 512, true, &err)) { @@ -4355,7 +4356,7 @@ static int emcore_get_body_part_imap(MAILSTREAM *stream, int account_id, int mai /* if (!is_pbd) */ { EM_DEBUG_LOG("TYPEIMAGE or TYPEAPPLICATION : inline content"); ai = &(cnt_info->file); - + while(*ai != NULL) ai = &(*ai)->next; @@ -4374,16 +4375,24 @@ static int emcore_get_body_part_imap(MAILSTREAM *stream, int account_id, int mai return FAILURE; } - if (((body->id) || (body->location)) && body->type == TYPEIMAGE) - (*ai)->type = 1; /* inline */ + if (((body->id) || (body->location)) && (body->type == TYPEIMAGE || body->type == TYPEAPPLICATION)) /* Some composer writes a content type of gif as application/octet-stream */ + (*ai)->type = INLINE_ATTACHMENT; /* inline */ else - (*ai)->type = 2; /* attachment */ + (*ai)->type = ATTACHMENT; /* attachment */ (*ai)->name = EM_SAFE_STRDUP(filename); (*ai)->size = body->size.bytes; - (*ai)->save = o_data; + (*ai)->save = EM_SAFE_STRDUP(o_data); (*ai)->content_id = EM_SAFE_STRDUP(body->id); + if (body->id && (emcore_search_string_from_file(cnt_info->text.html, body->id, NULL, &search_result) == EMAIL_ERROR_NONE && search_result)) { + (*ai)->type = INLINE_ATTACHMENT; + EM_DEBUG_LOG("INLINE_ATTACHMENT"); + } else if ((body->disposition.type && g_ascii_strcasecmp(body->disposition.type, "ATTACHMENT") == 0)) { + (*ai)->type = ATTACHMENT; + EM_DEBUG_LOG("ATTACHMENT"); + } + memset(content_type_buffer, 0, 512); if ( (err = emcore_get_content_type_from_mail_bodystruct(body, 512, content_type_buffer) ) == EMAIL_ERROR_NONE) (*ai)->attachment_mime_type = EM_SAFE_STRDUP(content_type_buffer); @@ -4417,7 +4426,7 @@ static int emcore_get_body_part_imap(MAILSTREAM *stream, int account_id, int mai ai = &cnt_info->file; EM_DEBUG_LOG(" ai - %p ", (*ai)); - if ((body->id) || (body->location)) { + if (attachment_type == INLINE_ATTACHMENT) { /* For Inline content append to the end */ for (i = 1; *ai; ai = &(*ai)->next) i++; @@ -4447,16 +4456,11 @@ static int emcore_get_body_part_imap(MAILSTREAM *stream, int account_id, int mai /* meaningless code */ dec_len = body->size.bytes; - if (body->id) - EM_DEBUG_LOG_SEC("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 */ + ((attachment_type == INLINE_ATTACHMENT) && (cnt_info->grab_type & GRAB_TYPE_TEXT)) /* Is it inline contents */ ) { /* fetch attachment */ EM_DEBUG_LOG_SEC("attachment (enc) : %s %ld bytes", filename, body->size.bytes); @@ -4468,7 +4472,7 @@ static int emcore_get_body_part_imap(MAILSTREAM *stream, int account_id, int mai goto FINISH_OFF; } - if (!is_pbd) { + if (!is_pbd && attachment_type == ATTACHMENT) { if (!imap_mail_write_body_to_file(stream, account_id, mail_id, cnt_info->file_no, savefile, msg_uid, body->sparep, body->encoding, &dec_len, body->subtype, &err)) { EM_DEBUG_EXCEPTION("imap_mail_write_body_to_file failed [%d]", err); goto FINISH_OFF; @@ -4486,11 +4490,6 @@ static int emcore_get_body_part_imap(MAILSTREAM *stream, int account_id, int mai goto FINISH_OFF; } - if ((body->id) || (body->location)) - (*ai)->type = 1; - else - (*ai)->type = 2; - if (is_pbd) { if (savefile != NULL) { if (section_plain == 1) @@ -4503,8 +4502,9 @@ static int emcore_get_body_part_imap(MAILSTREAM *stream, int account_id, int mai } /* is_pbd */ (*ai)->name = EM_SAFE_STRDUP(filename); (*ai)->size = dec_len; - (*ai)->save = savefile; + (*ai)->save = EM_SAFE_STRDUP(savefile); (*ai)->content_id = EM_SAFE_STRDUP(body->id); + (*ai)->type = attachment_type; memset(content_type_buffer, 0, 512); if ( (err = emcore_get_content_type_from_mail_bodystruct(body, 512, content_type_buffer) ) == EMAIL_ERROR_NONE) @@ -4544,6 +4544,8 @@ static int emcore_get_body_part_imap(MAILSTREAM *stream, int account_id, int mai FINISH_OFF: if (err_code) *err_code = err; + EM_SAFE_FREE(savefile); + EM_SAFE_FREE(o_data); EM_DEBUG_FUNC_END("ret [%d]", ret); return ret; } @@ -4555,7 +4557,7 @@ static int emcore_get_allnested_part(MAILSTREAM *stream, int account_id, int mai PART *part_child = body->nested.part; while (part_child) { - if (emcore_get_body(stream, account_id, mail_id, msg_uid, &part_child->body, cnt_info, err_code) < 0) + if (emcore_get_body(stream, account_id, mail_id, msg_uid, &part_child->body, body->subtype, cnt_info, err_code) < 0) return FAILURE; part_child = part_child->next; @@ -4574,7 +4576,7 @@ static int emcore_get_alternative_multi_part(MAILSTREAM *stream, int account_id, /* find the best sub part we can show */ while (part_child) { - if (emcore_get_body(stream, account_id, mail_id, msg_uid, &part_child->body, cnt_info, err_code) < 0) + if (emcore_get_body(stream, account_id, mail_id, msg_uid, &part_child->body, body->subtype, cnt_info, err_code) < 0) return FAILURE; part_child = part_child->next; @@ -4592,7 +4594,7 @@ static int emcore_get_signed_multi_part(MAILSTREAM *stream, int account_id, int /* find the best sub part we can show */ while (part_child) { - if (emcore_get_body(stream, account_id, mail_id, msg_uid, &part_child->body, cnt_info, err_code) < 0) + if (emcore_get_body(stream, account_id, mail_id, msg_uid, &part_child->body, body->subtype, cnt_info, err_code) < 0) return FAILURE; part_child = part_child->next; @@ -4644,7 +4646,7 @@ static int emcore_get_multi_part(MAILSTREAM *stream, int account_id, int mail_id /* get body data by body structure */ /* if POP3, ignored */ -INTERNAL_FUNC int emcore_get_body(MAILSTREAM *stream, int account_id, int mail_id, int msg_uid, BODY *body, struct _m_content_info *cnt_info, int *err_code) +INTERNAL_FUNC int emcore_get_body(MAILSTREAM *stream, int account_id, int mail_id, int msg_uid, BODY *body, char *part_body_type, struct _m_content_info *cnt_info, int *err_code) { EM_DEBUG_FUNC_BEGIN("stream[%p], msg_uid[%d], body[%p], cnt_info[%p], err_code[%p]", stream, msg_uid, body, cnt_info, err_code); @@ -4656,7 +4658,7 @@ INTERNAL_FUNC int emcore_get_body(MAILSTREAM *stream, int account_id, int mail_i return FAILURE; } - EM_DEBUG_LOG("body->type [%d]", body->type); + switch (body->type) { case TYPEMULTIPART: @@ -4664,7 +4666,7 @@ INTERNAL_FUNC int emcore_get_body(MAILSTREAM *stream, int account_id, int mail_i case TYPEMESSAGE: /* not support */ if (strcasecmp(body->subtype, "RFC822") == 0) - return emcore_get_body_part_imap(stream, account_id, mail_id, msg_uid, body, cnt_info, err_code); + return emcore_get_body_part_imap(stream, account_id, mail_id, msg_uid, body, part_body_type, cnt_info, err_code); break; case TYPETEXT: @@ -4675,7 +4677,7 @@ INTERNAL_FUNC int emcore_get_body(MAILSTREAM *stream, int account_id, int mail_i case TYPEMODEL: case TYPEOTHER: /* exactly, get a pure body part (text and attachment */ - return emcore_get_body_part_imap(stream, account_id, mail_id, msg_uid, body, cnt_info, err_code); + return emcore_get_body_part_imap(stream, account_id, mail_id, msg_uid, body, part_body_type, cnt_info, err_code); default: break; @@ -4829,13 +4831,11 @@ static void parse_file_path_to_filename(char *src_string, char **out_string) 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))); @@ -4872,7 +4872,7 @@ static char *emcore_decode_rfc2047_word(char *encoded_word, int *err_code) while (*current != NULL_CHAR) { /* search next */ start = strstr(current, "=?"); /* start of encoding */ - end = strstr(current, "?="); /* end of encoding */ + end = g_strrstr(current, "?="); /* end of encoding */ #ifdef FEATURE_CORE_DEBUG EM_DEBUG_LOG("current[%p][%s], start[%p][%s], end[%p][%s]", current, current, start, start, end, end); @@ -4905,13 +4905,14 @@ static char *emcore_decode_rfc2047_word(char *encoded_word, int *err_code) } if (base64_encoded) { /* BASE64 */ - charset = g_strndup(start + 2, p - (start + 2)); + if (p - (start + 2) > 0) + charset = g_strndup(start + 2, p - (start + 2)); encoded_text = g_strndup(p + 3, end - (p + 3)); } else { /* QUOTED-PRINTABLE */ charset = g_strndup(start + 2, p - (start + 2)); if (*(p+3) == '=') { /* encoded text might start with '='. ex) '?Q?=E0' */ - end = strstr(p+3, "?="); /* find new end flag */ + end = g_strrstr(p+3, "?="); /* find new end flag */ if (end) { encoded_text = g_strndup(p + 3, end - (p + 3)); } @@ -5061,8 +5062,10 @@ INTERNAL_FUNC char *emcore_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 = EMAIL_ERROR_NONE; + char *p = NULL; + gchar **encoded_words = NULL; + gchar **decoded_words = NULL; if (!rfc2047_text) { EM_DEBUG_EXCEPTION("rfc2047_text[%p]", rfc2047_text); @@ -5071,39 +5074,68 @@ INTERNAL_FUNC char *emcore_decode_rfc2047_text(char *rfc2047_text, int *err_code return NULL; } + char *p_text = 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); + text = strdup(rfc2047_text); - EM_DEBUG_LOG_DEV("rfc2047_text [%s]", rfc2047_text); - EM_DEBUG_LOG_DEV("g_strv_length(encoded_words) [%d]", g_strv_length(encoded_words)); + /* Handle the no include charset */ + while (strlen(text) != 0) { + if (g_str_has_prefix(text, "=?")) + encoded_words = g_strsplit_set(text, "\t\r\n ", -1); + else + encoded_words = g_strsplit_set(text, "\t\r\n", -1); + decoded_words = g_new0(char *, g_strv_length(encoded_words) + 1); - if (encoded_words != NULL) { - int i = 0; + EM_DEBUG_LOG_DEV("rfc2047_text [%s]", text); + EM_DEBUG_LOG_DEV("g_strv_length(encoded_words) [%d]", g_strv_length(encoded_words)); - while (encoded_words[i] != NULL) { - EM_DEBUG_LOG_DEV("encoded_words[%d] [%s]", i, encoded_words[i]); - if (!(decoded_words[i] = emcore_decode_rfc2047_word(encoded_words[i], &err))) { - EM_DEBUG_EXCEPTION("emcore_decode_rfc2047_word falied [%d]", err); - goto FINISH_OFF; + if (encoded_words != NULL) { + int i = 0; + + while (encoded_words[i] != NULL) { + EM_DEBUG_LOG_DEV("encoded_words[%d] [%s]", i, encoded_words[i]); + if (!(decoded_words[i] = emcore_decode_rfc2047_word(encoded_words[i], &err))) { + EM_DEBUG_EXCEPTION("emcore_decode_rfc2047_word falied [%d]", err); + goto FINISH_OFF; + } + EM_DEBUG_LOG_DEV("decoded_words[%d] [%s]", i, decoded_words[i]); + i++; } - EM_DEBUG_LOG_DEV("decoded_words[%d] [%s]", i, decoded_words[i]); - i++; + + p_text = g_strjoinv("", decoded_words); } + else + p_text = EM_SAFE_STRDUP(text); - text = g_strjoinv("", decoded_words); - } - else - text = EM_SAFE_STRDUP(rfc2047_text); + if (p_text) { + p = strstr(p_text, LF_STRING); + if (p) *p = '\0'; + } #ifdef FEATURE_CORE_DEBUG - EM_DEBUG_LOG(">>>>>>>>>>>>>>>>> TEXT[%s]", text); + EM_DEBUG_LOG(">>>>>>>>>>>>>>>>> TEXT[%s]", p_text); #endif /* FEATURE_CORE_DEBUG */ - ret = true; + char *charset_guess = NULL; + charset_guess = emcore_guess_charset(p_text); + EM_DEBUG_LOG("charset : [%s]", charset_guess); + + EM_SAFE_FREE(text); + text = EM_SAFE_STRDUP(p_text); + EM_SAFE_FREE(p_text); + + if (!strcasecmp(charset_guess, "euc-kr")) { + EM_SAFE_FREE(charset_guess); + } else { + EM_SAFE_FREE(charset_guess); + break; + } + } FINISH_OFF: + + EM_SAFE_FREE(p_text); g_strfreev(decoded_words); g_strfreev(encoded_words); @@ -5123,43 +5155,100 @@ static int emcore_make_mail_data_from_m_mesg(email_mail_data_t *dst_mail_data, s err = EMAIL_ERROR_INVALID_PARAM; return err; } - - char *content_type = NULL; - char *mime_type = NULL; + char *encoded_subject = NULL; + char *first_address = NULL; + char *first_alias = NULL; struct tm temp_time_info; ADDRESS *from = NULL; ADDRESS *to = NULL; ADDRESS *cc = NULL; ADDRESS *bcc = NULL; + ADDRESS *return_path = NULL; + ADDRESS *reply_to = NULL; MESSAGECACHE mail_cache_element = {0, }; memset(&mail_cache_element, 0x00, sizeof(MESSAGECACHE)); memset((void *)&temp_time_info, 0, sizeof(struct tm)); - if (mmsg->header) - content_type = emcore_mime_get_header_value(mmsg->header->part_header, CONTENT_TYPE, &err); - - if (content_type) { - if (strcasestr(content_type, "PKCS7-MIME")) { - mime_type = emcore_mime_get_header_value(mmsg->header->part_header, CONTENT_SMIME_TYPE, &err); - - if (mime_type && strcasestr(mime_type, "enveloped-data")) + /* Set the smime_type */ + if (mmsg->rfc822header && mmsg->rfc822header->content_type) { + if (strcasestr(mmsg->rfc822header->content_type, "pkcs7-mime")) { + if (strcasestr(mmsg->rfc822header->content_type, "enveloped-data")) dst_mail_data->smime_type = EMAIL_SMIME_ENCRYPTED; else dst_mail_data->smime_type = EMAIL_SMIME_SIGNED_AND_ENCRYPTED; - } else if (strcasestr(content_type, "SIGNED")) { - dst_mail_data->smime_type = EMAIL_SMIME_SIGNED; + } else if (strcasestr(mmsg->rfc822header->content_type, "encrypted")) { + dst_mail_data->smime_type = EMAIL_PGP_ENCRYPTED; + } else if (strcasestr(mmsg->rfc822header->content_type, "signed")) { + if (strcasestr(mmsg->rfc822header->content_type, "pkcs7-signature")) + dst_mail_data->smime_type = EMAIL_SMIME_SIGNED; + else + dst_mail_data->smime_type = EMAIL_PGP_SIGNED; + + dst_mail_data->digest_type = emcore_get_digest_type(mmsg->rfc822header->content_type); } else { - dst_mail_data->smime_type = EMAIL_SMIME_NONE; + dst_mail_data->smime_type = EMAIL_SMIME_NONE; } } + /* Set the priority */ + if (mmsg->rfc822header) { + if (mmsg->rfc822header->priority) { + switch(atoi(mmsg->rfc822header->priority)) { + case 1: + dst_mail_data->priority = EMAIL_MAIL_PRIORITY_HIGH; + break; + case 5: + dst_mail_data->priority = EMAIL_MAIL_PRIORITY_LOW; + break; + case 3: + default: + dst_mail_data->priority = EMAIL_MAIL_PRIORITY_NORMAL; + break; + } + } else if (mmsg->rfc822header->ms_priority) { + if (strcasestr(mmsg->rfc822header->ms_priority, "HIGH")) + dst_mail_data->priority = EMAIL_MAIL_PRIORITY_HIGH; + else if (strcasestr(mmsg->rfc822header->ms_priority, "NORMAL")) + dst_mail_data->priority = EMAIL_MAIL_PRIORITY_NORMAL; + else if (strcasestr(mmsg->rfc822header->ms_priority, "LOW")) + dst_mail_data->priority = EMAIL_MAIL_PRIORITY_LOW; + else + dst_mail_data->priority = EMAIL_MAIL_PRIORITY_NORMAL; + } + } else if (mmsg->nested.body) { + if (mmsg->nested.body->part_header->priority) { + switch(atoi(mmsg->nested.body->part_header->priority)) { + case 1: + dst_mail_data->priority = EMAIL_MAIL_PRIORITY_HIGH; + break; + case 5: + dst_mail_data->priority = EMAIL_MAIL_PRIORITY_LOW; + break; + case 3: + default: + dst_mail_data->priority = EMAIL_MAIL_PRIORITY_NORMAL; + break; + } + } else if (mmsg->nested.body->part_header->ms_priority) { + if (strcasestr(mmsg->nested.body->part_header->ms_priority, "HIGH")) + dst_mail_data->priority = EMAIL_MAIL_PRIORITY_HIGH; + else if (strcasestr(mmsg->nested.body->part_header->ms_priority, "NORMAL")) + dst_mail_data->priority = EMAIL_MAIL_PRIORITY_NORMAL; + else if (strcasestr(mmsg->nested.body->part_header->ms_priority, "LOW")) + dst_mail_data->priority = EMAIL_MAIL_PRIORITY_LOW; + else + dst_mail_data->priority = EMAIL_MAIL_PRIORITY_NORMAL; + } + } + if (!mmsg->rfc822header) { EM_DEBUG_LOG("This mail did not have envelop"); return err; } + /* Set the date */ if (mmsg->rfc822header->date) { EM_DEBUG_LOG("date : [%s]", mmsg->rfc822header->date); mail_parse_date(&mail_cache_element, (unsigned char *)mmsg->rfc822header->date); @@ -5180,43 +5269,65 @@ static int emcore_make_mail_data_from_m_mesg(email_mail_data_t *dst_mail_data, s dst_mail_data->date_time = timegm(&temp_time_info); + + /* Set the subject */ encoded_subject = emcore_decode_rfc2047_text(mmsg->rfc822header->subject, NULL); dst_mail_data->subject = EM_SAFE_STRDUP(encoded_subject); - dst_mail_data->full_address_return = EM_SAFE_STRDUP(mmsg->rfc822header->return_path); + /* Set the email address(from, to, cc, bcc, received ...) */ dst_mail_data->email_address_recipient = EM_SAFE_STRDUP(mmsg->rfc822header->received); - dst_mail_data->email_address_sender = EM_SAFE_STRDUP(mmsg->rfc822header->sender); - dst_mail_data->full_address_reply = EM_SAFE_STRDUP(mmsg->rfc822header->reply_to); if (mmsg->rfc822header->from) { rfc822_parse_adrlist(&from, mmsg->rfc822header->from, NULL); if (!emcore_get_utf8_address(&dst_mail_data->full_address_from, from, &err)) { EM_DEBUG_EXCEPTION_SEC("emcore_get_utf8_address failed : [%d], [%s]", err, mmsg->rfc822header->from); - } - } + } + } if (mmsg->rfc822header->to) { rfc822_parse_adrlist(&to, mmsg->rfc822header->to, NULL); if (!emcore_get_utf8_address(&dst_mail_data->full_address_to, to, &err)) { EM_DEBUG_EXCEPTION_SEC("emcore_get_utf8_address failed : [%d], [%s]", err, mmsg->rfc822header->to); - } - } + } + } if (mmsg->rfc822header->cc) { rfc822_parse_adrlist(&cc, mmsg->rfc822header->cc, NULL); if (!emcore_get_utf8_address(&dst_mail_data->full_address_cc, cc, &err)) { EM_DEBUG_EXCEPTION_SEC("emcore_get_utf8_address failed : [%d], [%s]", err, mmsg->rfc822header->cc); - } - } + } + } if (mmsg->rfc822header->bcc) { rfc822_parse_adrlist(&bcc, mmsg->rfc822header->bcc, NULL); if (!emcore_get_utf8_address(&dst_mail_data->full_address_bcc, bcc, &err)) { EM_DEBUG_EXCEPTION_SEC("emcore_get_utf8_address failed : [%d], [%s]", err, mmsg->rfc822header->bcc); - } - } + } + } + + if (mmsg->rfc822header->return_path) { + rfc822_parse_adrlist(&return_path, mmsg->rfc822header->return_path, NULL); + if (!emcore_get_utf8_address(&dst_mail_data->full_address_return, return_path, &err)) { + EM_DEBUG_EXCEPTION_SEC("emcore_get_utf8_address failed : [%d], [%s]", err, mmsg->rfc822header->return_path); + } + } + + if (mmsg->rfc822header->reply_to) { + rfc822_parse_adrlist(&reply_to, mmsg->rfc822header->reply_to, NULL); + if (!emcore_get_utf8_address(&dst_mail_data->full_address_reply, reply_to, &err)) { + EM_DEBUG_EXCEPTION_SEC("emcore_get_utf8_address failed : [%d], [%s]", err, mmsg->rfc822header->reply_to); + } + } + + if (emcore_get_first_address(dst_mail_data->full_address_from, &first_alias, &first_address) == true) { + dst_mail_data->alias_sender = EM_SAFE_STRDUP(first_alias); + dst_mail_data->email_address_sender = EM_SAFE_STRDUP(first_address); + } + EM_SAFE_FREE(encoded_subject); + EM_SAFE_FREE(first_alias); + EM_SAFE_FREE(first_address); if (from) mail_free_address(&from); @@ -5230,6 +5341,12 @@ static int emcore_make_mail_data_from_m_mesg(email_mail_data_t *dst_mail_data, s if (bcc) mail_free_address(&bcc); + if (return_path) + mail_free_address(&return_path); + + if (reply_to) + mail_free_address(&reply_to); + EM_DEBUG_FUNC_END("err : [%d]", err); return err; } @@ -5240,8 +5357,9 @@ INTERNAL_FUNC int emcore_make_mail_data_from_mime_data(struct _m_mesg *mmsg, str int i = 0; int ret = false; int eml_mail_id = 0; - int attachment_num = 0; int err = EMAIL_ERROR_NONE; + int save_status = EMAIL_BODY_DOWNLOAD_STATUS_NONE; + int attachment_num = 0; int local_attachment_count = 0; int local_inline_content_count = 0; char buf[512]; @@ -5271,7 +5389,7 @@ INTERNAL_FUNC int emcore_make_mail_data_from_mime_data(struct _m_mesg *mmsg, str p_mail_data->mail_id = eml_mail_id; p_mail_data->account_id = EML_FOLDER; - p_mail_data->body_download_status = (*err_code != EMAIL_ERROR_NO_MORE_DATA) ? EMAIL_BODY_DOWNLOAD_STATUS_FULLY_DOWNLOADED : EMAIL_BODY_DOWNLOAD_STATUS_PARTIALLY_DOWNLOADED; + p_mail_data->mail_size = cnt_info->total_body_size; if ((err = emcore_make_mail_data_from_m_mesg(p_mail_data, mmsg)) != EMAIL_ERROR_NONE) { EM_DEBUG_EXCEPTION("emcore_make_mail_data_from_m_mesg failed : [%d]", err); @@ -5286,7 +5404,7 @@ INTERNAL_FUNC int emcore_make_mail_data_from_mime_data(struct _m_mesg *mmsg, str goto FINISH_OFF; } - if (!emstorage_get_save_name(EML_FOLDER, eml_mail_id, 0, cnt_info->text.plain_charset ? cnt_info->text.plain_charset : UNKNOWN_CHARSET_PLAIN_TEXT_FILE, buf, &err)) { + if (!emstorage_get_save_name(EML_FOLDER, eml_mail_id, 0, cnt_info->text.plain_charset ? cnt_info->text.plain_charset : UNKNOWN_CHARSET_PLAIN_TEXT_FILE, buf, sizeof(buf), &err)) { EM_DEBUG_EXCEPTION("emstorage_get_save_name failed [%d]", err); goto FINISH_OFF; } @@ -5297,6 +5415,7 @@ INTERNAL_FUNC int emcore_make_mail_data_from_mime_data(struct _m_mesg *mmsg, str } p_mail_data->file_path_plain = EM_SAFE_STRDUP(buf); + save_status = cnt_info->text.plain_save_status; } if (cnt_info->text.html) { @@ -5311,7 +5430,7 @@ INTERNAL_FUNC int emcore_make_mail_data_from_mime_data(struct _m_mesg *mmsg, str strcpy(html_body, UNKNOWN_CHARSET_HTML_TEXT_FILE); } - if (!emstorage_get_save_name(EML_FOLDER, eml_mail_id, 0, html_body, buf, &err)) { + if (!emstorage_get_save_name(EML_FOLDER, eml_mail_id, 0, html_body, buf, sizeof(buf), &err)) { EM_DEBUG_EXCEPTION("emstorage_get_save_name failed [%d]", err); goto FINISH_OFF; } @@ -5322,10 +5441,19 @@ INTERNAL_FUNC int emcore_make_mail_data_from_mime_data(struct _m_mesg *mmsg, str } p_mail_data->file_path_html = EM_SAFE_STRDUP(buf); + save_status = cnt_info->text.html_save_status; } - for (ai = cnt_info->file; ai; ai = ai->next, attachment_num++) {} - EM_DEBUG_LOG("attachment_num : [%d]", attachment_num); + if ((err = emcore_get_preview_text_from_file(p_mail_data->file_path_plain, p_mail_data->file_path_html, MAX_PREVIEW_TEXT_LENGTH, &p_mail_data->preview_text)) != EMAIL_ERROR_NONE) + EM_DEBUG_EXCEPTION("emcore_get_preview_text_from_file error [%d]", err); + + for (ai = cnt_info->file; ai; ai = ai->next, local_attachment_count++) {} + EM_DEBUG_LOG("local_attachment_count : [%d]", local_attachment_count); + + for (ai = cnt_info->inline_file; ai; ai = ai->next, local_inline_content_count++) {} + EM_DEBUG_LOG("local_inline_content_count : [%d]", local_inline_content_count); + + attachment_num = local_attachment_count + local_inline_content_count; if (attachment_num > 0) { attachment = (email_attachment_data_t *)em_malloc(sizeof(email_attachment_data_t) * attachment_num); @@ -5339,9 +5467,10 @@ INTERNAL_FUNC int emcore_make_mail_data_from_mime_data(struct _m_mesg *mmsg, str attachment[i].attachment_id = i + 1; attachment[i].attachment_size = ai->size; attachment[i].attachment_name = EM_SAFE_STRDUP(ai->name); + attachment[i].content_id = EM_SAFE_STRDUP(ai->content_id); attachment[i].drm_status = ai->drm; - attachment[i].save_status = 0; - attachment[i].inline_content_status = ai->type == 1; + attachment[i].save_status = ai->save_status; + attachment[i].inline_content_status = 0; attachment[i].attachment_mime_type = EM_SAFE_STRDUP(ai->attachment_mime_type); #ifdef __ATTACHMENT_OPTI__ attachment[i].encoding = ai->encoding; @@ -5354,41 +5483,78 @@ INTERNAL_FUNC int emcore_make_mail_data_from_mime_data(struct _m_mesg *mmsg, str EM_DEBUG_LOG("attachment[%d].inline_content_status[%d]", i, attachment[i].inline_content_status); EM_DEBUG_LOG("attachment[%d].attachment_mime_type : [%s]", i, attachment[i].attachment_mime_type); - if (ai->type == 1) - local_inline_content_count ++; - else - local_attachment_count++; - if (ai->save) { - attachment[i].save_status = ai->save_status == EMAIL_BODY_DOWNLOAD_STATUS_PARTIALLY_DOWNLOADED ? EMAIL_BODY_DOWNLOAD_STATUS_PARTIALLY_DOWNLOADED : EMAIL_BODY_DOWNLOAD_STATUS_FULLY_DOWNLOADED; + if (!emstorage_create_dir(EML_FOLDER, eml_mail_id, i + 1, &err)) { + EM_DEBUG_EXCEPTION("emstorage_create_dir failed [%d]", err); + goto FINISH_OFF; + } - if (ai->type == 1) { /* it is inline content */ - if (!emstorage_create_dir(EML_FOLDER, eml_mail_id, 0, &err)) { - EM_DEBUG_EXCEPTION("emstorage_create_dir failed [%d]", err); - goto FINISH_OFF; - } - if (!emstorage_get_save_name(EML_FOLDER, eml_mail_id, 0, attachment[i].attachment_name, buf, &err)) { - EM_DEBUG_EXCEPTION("emstorage_get_save_name failed [%d]", err); - goto FINISH_OFF; - } + if (!emstorage_get_save_name(EML_FOLDER, eml_mail_id, i + 1, attachment[i].attachment_name, buf, sizeof(buf), &err)) { + EM_DEBUG_EXCEPTION("emstorage_get_save_name failed [%d]", err); + goto FINISH_OFF; } - else { - if (!emstorage_create_dir(EML_FOLDER, eml_mail_id, i + 1, &err)) { - EM_DEBUG_EXCEPTION("emstorage_create_dir failed [%d]", err); - goto FINISH_OFF; + + if (!emstorage_move_file(ai->save, buf, false, &err)) { + EM_DEBUG_EXCEPTION("emstorage_move_file failed [%d]", err); + + /* delete all created files. */ + if (!emstorage_get_save_name(EML_FOLDER, eml_mail_id, 0, NULL, buf, sizeof(buf), NULL)) { + EM_DEBUG_EXCEPTION("emstorage_get_save_name failed..."); + /* goto FINISH_OFF; */ } - if (!emstorage_get_save_name(EML_FOLDER, eml_mail_id, i + 1, attachment[i].attachment_name, buf, &err)) { - EM_DEBUG_EXCEPTION("emstorage_get_save_name failed [%d]", err); - goto FINISH_OFF; + if (!emstorage_delete_dir(buf, NULL)) { + EM_DEBUG_EXCEPTION("emstorage_delete_dir failed..."); + /* goto FINISH_OFF; */ } + + + goto FINISH_OFF; + } + + attachment[i].attachment_path = EM_SAFE_STRDUP(buf); + } + + EM_DEBUG_LOG_SEC("attachment[%d].attachment_path[%s]", i, attachment[i].attachment_path); + save_status = ai->save_status; + } + + for (ai = cnt_info->inline_file; ai; ai = ai->next, i++) { + attachment[i].attachment_id = i + 1; + attachment[i].attachment_size = ai->size; + attachment[i].attachment_name = EM_SAFE_STRDUP(ai->name); + attachment[i].content_id = EM_SAFE_STRDUP(ai->content_id); + attachment[i].drm_status = ai->drm; + attachment[i].save_status = ai->save_status; + attachment[i].inline_content_status = INLINE_ATTACHMENT; + attachment[i].attachment_mime_type = EM_SAFE_STRDUP(ai->attachment_mime_type); +#ifdef __ATTACHMENT_OPTI__ + attachment[i].encoding = ai->encoding; + attachment[i].section = ai->section; +#endif + EM_DEBUG_LOG("attachment[%d].attachment_id[%d]", i, attachment[i].attachment_id); + EM_DEBUG_LOG("attachment[%d].attachment_size[%d]", i, attachment[i].attachment_size); + EM_DEBUG_LOG_SEC("attachment[%d].attachment_name[%s]", i, attachment[i].attachment_name); + EM_DEBUG_LOG("attachment[%d].drm_status[%d]", i, attachment[i].drm_status); + EM_DEBUG_LOG("attachment[%d].inline_content_status[%d]", i, attachment[i].inline_content_status); + EM_DEBUG_LOG("attachment[%d].attachment_mime_type : [%s]", i, attachment[i].attachment_mime_type); + + if (ai->save) { + if (!emstorage_create_dir(EML_FOLDER, eml_mail_id, 0, &err)) { + EM_DEBUG_EXCEPTION("emstorage_create_dir failed [%d]", err); + goto FINISH_OFF; + } + + if (!emstorage_get_save_name(EML_FOLDER, eml_mail_id, 0, attachment[i].attachment_name, buf, sizeof(buf), &err)) { + EM_DEBUG_EXCEPTION("emstorage_get_save_name failed [%d]", err); + goto FINISH_OFF; } if (!emstorage_move_file(ai->save, buf, false, &err)) { EM_DEBUG_EXCEPTION("emstorage_move_file failed [%d]", err); /* delete all created files. */ - if (!emstorage_get_save_name(EML_FOLDER, eml_mail_id, 0, NULL, buf, NULL)) { + if (!emstorage_get_save_name(EML_FOLDER, eml_mail_id, 0, NULL, buf, sizeof(buf), NULL)) { EM_DEBUG_EXCEPTION("emstorage_get_save_name failed..."); /* goto FINISH_OFF; */ } @@ -5403,16 +5569,18 @@ INTERNAL_FUNC int emcore_make_mail_data_from_mime_data(struct _m_mesg *mmsg, str } attachment[i].attachment_path = EM_SAFE_STRDUP(buf); - } - EM_DEBUG_LOG("attachment[%d].attachment_path[%s]", i, attachment[i].attachment_path); + EM_DEBUG_LOG_SEC("attachment[%d].attachment_path[%s]", i, attachment[i].attachment_path); + save_status = ai->save_status; } } EM_DEBUG_LOG("Check #1"); + EM_DEBUG_LOG("save_status : [%d]", save_status); p_mail_data->attachment_count = local_attachment_count; p_mail_data->inline_content_count = local_inline_content_count; + p_mail_data->body_download_status = (save_status == EMAIL_BODY_DOWNLOAD_STATUS_FULLY_DOWNLOADED) ? 1 : 0; eml_data_count += 1; ret = true; @@ -5452,10 +5620,8 @@ INTERNAL_FUNC int emcore_parse_mime_file_to_mail(char *eml_file_path, email_mail int err = EMAIL_ERROR_NONE; int ret = false; - int is_file = 1; char buf[512]; char *mime_entity = NULL; - FILE *eml_fp = NULL; struct _m_content_info *cnt_info = NULL; struct _m_mesg *mmsg = NULL; @@ -5482,32 +5648,21 @@ INTERNAL_FUNC int emcore_parse_mime_file_to_mail(char *eml_file_path, email_mail goto FINISH_OFF; } - eml_fp = fopen(eml_file_path, "r"); - if (eml_fp == NULL) { - EM_DEBUG_EXCEPTION("file open failed"); - err = EMAIL_ERROR_ON_PARSING; - goto FINISH_OFF; - } - - if (!emcore_mime_parse_header(eml_fp, is_file, &mmsg->rfc822header, &mmsg->header, &err)) { - EM_DEBUG_EXCEPTION("emcore_mime_parse_header failed : [%d]", err); - err = EMAIL_ERROR_INVALID_DATA; + mmsg->rfc822header = (struct _rfc822header *)em_malloc(sizeof(struct _rfc822header)); + if (mmsg->rfc822header == NULL) { + EM_DEBUG_EXCEPTION("em_malloc failed"); + err = EMAIL_ERROR_OUT_OF_MEMORY; goto FINISH_OFF; } - if (!mmsg->header->part_header) { - EM_DEBUG_EXCEPTION("Invalid eml format"); + emcore_gmime_init(); + if (!emcore_gmime_eml_parse_mime(eml_file_path, mmsg->rfc822header, cnt_info, &err)) { + EM_DEBUG_EXCEPTION("emcore_gmime_parse_mime failed : [%d]", err); err = EMAIL_ERROR_INVALID_DATA; + emcore_gmime_shutdown(); goto FINISH_OFF; } - - if (!emcore_mime_parse_body(eml_fp, is_file, mmsg, cnt_info, NULL, &err)) { - if (err != EMAIL_ERROR_NO_MORE_DATA) { - EM_DEBUG_EXCEPTION("emcore_mime_parse_body failed : [%d]", err); - err = EMAIL_ERROR_INVALID_DATA; - goto FINISH_OFF; - } - } + emcore_gmime_shutdown(); if (!emcore_make_mail_data_from_mime_data(mmsg, cnt_info, output_mail_data, output_attachment_data, output_attachment_count, &err)) { EM_DEBUG_EXCEPTION("emcore_make_mail_tbl_data_from_mime failed : [%d]", err); @@ -5515,21 +5670,21 @@ INTERNAL_FUNC int emcore_parse_mime_file_to_mail(char *eml_file_path, email_mail } - if ((*output_mail_data)->smime_type == EMAIL_SMIME_SIGNED) { + if ((*output_mail_data)->smime_type == EMAIL_SMIME_SIGNED || (*output_mail_data)->smime_type == EMAIL_PGP_SIGNED) { if (!emcore_get_mime_entity(eml_file_path, &mime_entity, &err)) { EM_DEBUG_EXCEPTION("emcore_get_mime_entity failed: [%d]", err); goto FINISH_OFF; } - - if (!emstorage_get_save_name((*output_mail_data)->account_id, (*output_mail_data)->mail_id, 0, "mime_entity", buf, &err)) { + + if (!emstorage_get_save_name((*output_mail_data)->account_id, (*output_mail_data)->mail_id, 0, "mime_entity", buf, sizeof(buf), &err)) { EM_DEBUG_EXCEPTION("emstorage_get_save_name failed : [%d]", err); goto FINISH_OFF; } - + if (!emstorage_move_file(mime_entity, buf, false, &err)) { EM_DEBUG_EXCEPTION("emstorage_move_file failed [%d]", err); goto FINISH_OFF; - } + } (*output_mail_data)->file_path_mime_entity = EM_SAFE_STRDUP(buf); } @@ -5538,9 +5693,6 @@ INTERNAL_FUNC int emcore_parse_mime_file_to_mail(char *eml_file_path, email_mail FINISH_OFF: - if (eml_fp) - fclose(eml_fp); - if (mmsg) emcore_mime_free_mime(mmsg); @@ -5636,10 +5788,9 @@ INTERNAL_FUNC int emcore_get_mime_entity(char *mime_path, char **output_path, in goto FINISH_OFF; } - fp_read = fopen(mime_path, "r"); - if (fp_read == NULL) { - EM_DEBUG_EXCEPTION_SEC("File open(read) is failed : filename [%s]", mime_path); - err = EMAIL_ERROR_SYSTEM_FAILURE; + err = em_fopen(mime_path, "r", &fp_read); + if (err != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION_SEC("File em_fopen(read) is failed : filename [%s][%d]", mime_path, err); goto FINISH_OFF; } @@ -5665,10 +5816,9 @@ INTERNAL_FUNC int emcore_get_mime_entity(char *mime_path, char **output_path, in } EM_DEBUG_LOG("mime_entity_path = %s", mime_entity_path); - fp_write = fopen(mime_entity_path, "w"); - if (fp_write == NULL) { - EM_DEBUG_EXCEPTION_SEC("File open(write) is failed : filename [%s]", mime_entity_path); - err = EMAIL_ERROR_SYSTEM_FAILURE; + err = em_fopen(mime_entity_path, "w", &fp_write); + if (err != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION_SEC("File em_fopen(write) is failed : filename [%s][%d]", mime_entity_path, err); goto FINISH_OFF; } @@ -5746,7 +5896,8 @@ FINISH_OFF: emcore_mime_free_mime(mmsg); if (output_path) - *output_path = mime_entity_path; + *output_path = EM_SAFE_STRDUP(mime_entity_path); + EM_SAFE_FREE(mime_entity_path); if (err_code) *err_code = err; @@ -5757,7 +5908,7 @@ FINISH_OFF: return ret; } -int emcore_decode_body_text_from_file(FILE *stream, char *boundary_str, int encoding, int mode, int is_text, int fd, char **holder, int *end_of_parsing, int *size) +int emcore_decode_body_text_from_file(FILE *stream, char *boundary_str, int encoding, int mode, int fd, char **holder, int *end_of_parsing, int *size) { EM_DEBUG_FUNC_BEGIN(); int error = EMAIL_ERROR_NONE; @@ -5780,7 +5931,7 @@ int emcore_decode_body_text_from_file(FILE *stream, char *boundary_str, int enco 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"); + SNPRINTF(boundary_end, BOUNDARY_LEN, "--%s%s", boundary_str, "--"); } start_location = ftell(stream); @@ -5797,10 +5948,6 @@ int emcore_decode_body_text_from_file(FILE *stream, char *boundary_str, int enco error = EMAIL_ERROR_SYSTEM_FAILURE; goto FINISH_OFF; } - - partial_body = 1; - *end_of_parsing = 2; - break; } if (boundary_str) { @@ -5808,13 +5955,20 @@ int emcore_decode_body_text_from_file(FILE *stream, char *boundary_str, int enco *end_of_parsing = 0; break; } - else if (!strcmp(buf, boundary_end)) { /* if ending boundary, the parsing of other multipart will be started */ + else if (strcasestr(buf, boundary_end)) { /* if ending boundary, the parsing of other multipart will be started */ *end_of_parsing = 1; break; } } + + if (error != EMAIL_ERROR_NONE) { + partial_body = 1; + *end_of_parsing = 2; + break; + } } + EM_DEBUG_LOG("partial_body : [%d], buf:[%s]", partial_body, buf); end_location = ftell(stream); if(end_location < 0 ) { /*prevent 35555*/ error = EMAIL_ERROR_INVALID_PARAM; @@ -5844,26 +5998,20 @@ int emcore_decode_body_text_from_file(FILE *stream, char *boundary_str, int enco if (mode > SAVE_TYPE_SIZE) { /* decode content */ emcore_decode_body_text(body, p_size, encoding, &dec_len, &error); - if (is_text) { - modified_body = em_replace_all_string(body, "cid:", ""); - modified_body_size = EM_SAFE_STRLEN(modified_body); /*prevent 35585 */ - } - + modified_body = em_malloc(dec_len + 1); if (modified_body == NULL) { - modified_body = em_malloc(dec_len + 1); - if (modified_body == NULL) { - EM_DEBUG_EXCEPTION("em_malloc failed"); - error = EMAIL_ERROR_OUT_OF_MEMORY; - goto FINISH_OFF; - } - - memcpy(modified_body, body, dec_len); /*prevent 35585 */ - modified_body_size = dec_len; + EM_DEBUG_EXCEPTION("em_malloc failed"); + error = EMAIL_ERROR_OUT_OF_MEMORY; + goto FINISH_OFF; } + memcpy(modified_body, body, dec_len); /*prevent 35585 */ + modified_body_size = dec_len; + if (mode == SAVE_TYPE_BUFFER) { /* save content to buffer */ *holder = EM_SAFE_STRDUP(modified_body); } else if (mode == SAVE_TYPE_FILE) { /* save content to file */ + EM_DEBUG_LOG("Before write : size[%d]", modified_body_size); if (write(fd, modified_body, modified_body_size) != modified_body_size) { EM_DEBUG_EXCEPTION("write failed"); error = EMAIL_ERROR_SYSTEM_FAILURE; @@ -5884,7 +6032,7 @@ FINISH_OFF: return error; } -int emcore_decode_body_text_from_sock(void *stream, char *boundary_str, int encoding, int mode, int is_text, int fd, char **holder, int *end_of_parsing, int *size) +int emcore_decode_body_text_from_sock(void *stream, char *boundary_str, int encoding, int mode, int fd, char **holder, int *end_of_parsing, int *size) { EM_DEBUG_FUNC_BEGIN(); int error = EMAIL_ERROR_NONE; @@ -5907,12 +6055,13 @@ int emcore_decode_body_text_from_sock(void *stream, char *boundary_str, int enco } while (TRUE) { +/* don't delete the comment. several threads including event thread call it if (!emcore_check_thread_status()) { EM_DEBUG_EXCEPTION("EMAIL_ERROR_CANCELLED"); error = EMAIL_ERROR_CANCELLED; goto FINISH_OFF; } - +*/ if (!emcore_mime_get_line_from_sock(stream, buf, MIME_LINE_LEN, &error)) { if (error != EMAIL_ERROR_NO_MORE_DATA) { EM_DEBUG_EXCEPTION("emcore_mime_get_line_from_sock failed"); @@ -5941,7 +6090,7 @@ int emcore_decode_body_text_from_sock(void *stream, char *boundary_str, int enco } /* parsing string started by '.' in POP3 */ - if ((buf[0] == '.' && buf[1] == '.') && (encoding == ENCQUOTEDPRINTABLE || encoding == ENC7BIT)) { + if ((buf[0] == '.' && buf[1] == '.') && (encoding == ENCQUOTEDPRINTABLE || encoding == ENC7BIT)) { strncpy(buf, buf+1, MIME_LINE_LEN-1); buf[EM_SAFE_STRLEN(buf)] = NULL_CHAR; } @@ -5959,24 +6108,16 @@ int emcore_decode_body_text_from_sock(void *stream, char *boundary_str, int enco if (mode > SAVE_TYPE_SIZE) { /* decode content */ emcore_decode_body_text(buf, dec_len, encoding, &dec_len, &error); - if (is_text) { - result_buffer = em_replace_string(buf, "cid:", ""); - if (result_buffer) - result_buffer_size = EM_SAFE_STRLEN(result_buffer); - } - + result_buffer = em_malloc(dec_len + 1); if (result_buffer == NULL) { - result_buffer = em_malloc(dec_len + 1); - if (result_buffer == NULL) { - EM_DEBUG_EXCEPTION("em_malloc failed"); - error = EMAIL_ERROR_OUT_OF_MEMORY; - goto FINISH_OFF; - } - - memcpy(result_buffer, buf, dec_len); /*prevent 35499*/ - result_buffer_size = dec_len; + EM_DEBUG_EXCEPTION("em_malloc failed"); + error = EMAIL_ERROR_OUT_OF_MEMORY; + goto FINISH_OFF; } + memcpy(result_buffer, buf, dec_len); /*prevent 35499*/ + result_buffer_size = dec_len; + if (mode == SAVE_TYPE_BUFFER) { /* save content to buffer */ pTemp = realloc(*holder, sz + result_buffer_size + 2); if (!pTemp) { @@ -6018,3 +6159,39 @@ FINISH_OFF: return error; } +INTERNAL_FUNC int emcore_get_digest_type(char *micalg_value) +{ + EM_DEBUG_FUNC_BEGIN(); + int digest_type = DIGEST_TYPE_NONE; + + if (micalg_value == NULL) + return DIGEST_TYPE_NONE; + + if (strcasestr(micalg_value, "sha1")) + digest_type = DIGEST_TYPE_SHA1; + else if (strcasestr(micalg_value, "md5")) + digest_type = DIGEST_TYPE_MD5; + else if (strcasestr(micalg_value, "ripemd160")) + digest_type = DIGEST_TYPE_RIPEMD160; + else if (strcasestr(micalg_value, "md2")) + digest_type = DIGEST_TYPE_MD2; + else if (strcasestr(micalg_value, "tiger192")) + digest_type = DIGEST_TYPE_TIGER192; + else if (strcasestr(micalg_value, "haval5160")) + digest_type = DIGEST_TYPE_HAVAL5160; + else if (strcasestr(micalg_value, "sha256")) + digest_type = DIGEST_TYPE_SHA256; + else if (strcasestr(micalg_value, "sha384")) + digest_type = DIGEST_TYPE_SHA384; + else if (strcasestr(micalg_value, "sha512")) + digest_type = DIGEST_TYPE_SHA512; + else if (strcasestr(micalg_value, "sha224")) + digest_type = DIGEST_TYPE_SHA224; + else if (strcasestr(micalg_value, "md4")) + digest_type = DIGEST_TYPE_MD4; + else + digest_type = DIGEST_TYPE_NONE; + + EM_DEBUG_FUNC_END(); + return digest_type; +} diff --git a/email-core/email-core-mm-callbacks.c b/email-core/email-core-mm-callbacks.c index ed1c71c..5bbb5ea 100755 --- a/email-core/email-core-mm-callbacks.c +++ b/email-core/email-core-mm-callbacks.c @@ -4,7 +4,7 @@ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> -* +* * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -24,9 +24,9 @@ * File : email-core-mm_callbacks.c * Desc : mm_callbacks for IMAP-2004g * - * Auth : + * Auth : * - * History : + * History : * 2006.08.22 : created *****************************************************************************/ #include <stdio.h> @@ -60,7 +60,7 @@ INTERNAL_FUNC void mm_lsub(MAILSTREAM *stream, int delimiter, char *mailbox, lon /* uw-imap mailbox name format (ex : "{mail.test.com...}inbox" or "{mail.test.com...}anybox/anysubbox") */ enc_path = strchr(mailbox, '}'); - if (enc_path) + if (enc_path) enc_path += 1; else { emcore_free_mailbox_list(&p, count+1); @@ -113,7 +113,7 @@ INTERNAL_FUNC void mm_list(MAILSTREAM *stream, int delimiter, char *mailbox, lon /* uw-imap mailbox name format (ex : "{mail.test.com...}inbox" or "{mail.test.com...}anybox/anysubbox") */ enc_path = strchr(mailbox, '}'); - if (enc_path) + if (enc_path) enc_path += 1; else { emcore_free_internal_mailbox(&p, count+1, NULL); @@ -121,8 +121,8 @@ INTERNAL_FUNC void mm_list(MAILSTREAM *stream, int delimiter, char *mailbox, lon } /* convert directory delimiter to '/' */ - for (s = enc_path;*s;s++) - if (*s == (char)delimiter) + for (s = enc_path;*s;s++) + if (*s == (char)delimiter) *s = '/'; /* copy string */ @@ -140,7 +140,7 @@ INTERNAL_FUNC void mm_list(MAILSTREAM *stream, int delimiter, char *mailbox, lon else if(attributes & LATT_XLIST_JUNK) p[count].mailbox_type = EMAIL_MAILBOX_TYPE_SPAMBOX; else if(attributes & LATT_XLIST_FLAGGED) - p[count].mailbox_type = EMAIL_MAILBOX_TYPE_FLAGGED; + p[count].mailbox_type = EMAIL_MAILBOX_TYPE_USER_DEFINED; //EMAIL_MAILBOX_TYPE_FLAGGED; P141122-00523 sync starred folder as Inbox sync else if(attributes & LATT_XLIST_TRASH) p[count].mailbox_type = EMAIL_MAILBOX_TYPE_TRASH; #endif /* __FEATURE_XLIST_SUPPORT__ */ @@ -190,9 +190,9 @@ INTERNAL_FUNC void mm_status(MAILSTREAM *stream, char *mailbox, MAILSTATUS* stat email_callback_holder_t *p = stream->sparep; EM_DEBUG_FUNC_BEGIN(); - if (status->flags & SA_MESSAGES) + if (status->flags & SA_MESSAGES) p->num = status->messages; - if (status->flags & SA_UNSEEN) + if (status->flags & SA_UNSEEN) p->data = (void *)status->unseen; EM_DEBUG_FUNC_END(); } @@ -215,7 +215,7 @@ INTERNAL_FUNC void mm_login(NETMBX *mb, char *user, char *pwd, long trial) EM_DEBUG_EXCEPTION("invalid account_id..."); goto FINISH_OFF; } - + account_id = atoi(mb->user); ref_account = emcore_get_account_reference(account_id); @@ -279,43 +279,44 @@ INTERNAL_FUNC void mm_dlog(char *string) INTERNAL_FUNC void mm_log(char *string, long errflg) { - + switch ((short)errflg) { case NIL: - EM_DEBUG_LOG("IMAP_TOOLKIT_LOG NIL [%s]", string); + EM_DEBUG_LOG("IMAP_TOOLKIT_LOG [%s]", string); break; - + case WARN: - EM_DEBUG_LOG("IMAP_TOOLKIT_LOG WARN [%s]", string); + EM_DEBUG_EXCEPTION ("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); + EM_DEBUG_LOG_SEC("IMAP_TOOLKIT_LOG TCPDEBUG [%s]", string); break; - + case ERROR: { email_session_t *session = NULL; - + EM_DEBUG_EXCEPTION("IMAP_TOOLKIT_LOG ERROR [%s]", string); emcore_get_current_session(&session); - + if (session) { mm_get_error(string, &session->error); EM_DEBUG_EXCEPTION("IMAP_TOOLKIT_LOG ERROR [%d]", session->error); - if(session->error == EMAIL_ERROR_XOAUTH_BAD_REQUEST || session->error == EMAIL_ERROR_XOAUTH_INVALID_UNAUTHORIZED) { + if (session->error == EMAIL_ERROR_XOAUTH_BAD_REQUEST || + session->error == EMAIL_ERROR_XOAUTH_INVALID_UNAUTHORIZED) { session->network = session->error; } } - + break; } } @@ -348,7 +349,9 @@ INTERNAL_FUNC void mm_flags(MAILSTREAM *stream, unsigned long number) INTERNAL_FUNC void mm_notify(MAILSTREAM *stream, char *string, long errflg) { EM_DEBUG_FUNC_BEGIN(); +#ifdef FEATURE_CORE_DEBUG mm_log(string, errflg); +#endif /* FEATURE_CORE_DEBUG */ EM_DEBUG_FUNC_END(); } @@ -440,6 +443,8 @@ INTERNAL_FUNC void mm_get_error(char *string, int *err_code) *err_code = EMAIL_ERROR_XOAUTH_BAD_REQUEST; else if (strstr(string, "\"status\":\"401")) *err_code = EMAIL_ERROR_XOAUTH_INVALID_UNAUTHORIZED; + else if (strstr(string, "ALREADYEXISTS")) + *err_code = EMAIL_ERROR_ALREADY_EXISTS; else *err_code = EMAIL_ERROR_UNKNOWN; } @@ -449,7 +454,6 @@ INTERNAL_FUNC void mm_imap_id (char **id_string) { EM_DEBUG_FUNC_BEGIN("id_string [%p]", id_string); - int err = EMAIL_ERROR_NONE; /* char *result_string = NULL; char *tag_string = "ID (\"os\" \"" IMAP_ID_OS "\" \"os-version\" \"" IMAP_ID_OS_VERSION "\" \"vendor\" \"" IMAP_ID_VENDOR "\" \"device\" \"" IMAP_ID_DEVICE_NAME "\" \"AGUID\" \"" IMAP_ID_AGUID "\" \"ACLID\" \"" IMAP_ID_ACLID "\""; @@ -458,7 +462,6 @@ INTERNAL_FUNC void mm_imap_id (char **id_string) if (id_string == NULL) { EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM"); - err = EMAIL_ERROR_INVALID_PARAM; goto FINISH_OFF; } @@ -470,15 +473,13 @@ INTERNAL_FUNC void mm_imap_id (char **id_string) if(result_string == NULL) { EM_DEBUG_EXCEPTION("malloc failed"); - err = EMAIL_ERROR_OUT_OF_MEMORY; goto FINISH_OFF; } *id_string = result_string; */ - FINISH_OFF: - EM_DEBUG_FUNC_END("err [%d]", err); + return ; } #endif /* __FEATURE_SUPPORT_IMAP_ID__ */ /* EOF */ diff --git a/email-core/email-core-pgp.c b/email-core/email-core-pgp.c new file mode 100644 index 0000000..31e85d0 --- /dev/null +++ b/email-core/email-core-pgp.c @@ -0,0 +1,749 @@ +/* +* email-service +* +* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. +* +* Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +*/ + + + +/* ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** *** + *File : email-core-smime.c + *Desc : MIME Operation + * + *Auth : + * + *History : + * 2011.04.14 : created + ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ***/ +#undef close + +#include <glib.h> +#include <gmime/gmime.h> + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <fcntl.h> +#include <vconf.h> +#include <ctype.h> +#include <sys/stat.h> +#include <sys/time.h> +#include <glib.h> +#include <glib/gstdio.h> + +#include "email-utilities.h" +#include "email-core-global.h" +#include "email-core-utils.h" +#include "email-core-mail.h" +#include "email-core-smtp.h" +#include "email-storage.h" +#include "email-core-cert.h" +#include "email-debug-log.h" + +#define PGP_SIGNED_FILE "signature.asc" +#define PGP_ENCRYPTED_FILE "encrypted.asc" +#define DECRYPTED_TEMP_FILE "decrypted_temp_file.eml" + +static char *passphrase = NULL; + +static gboolean request_passwd(GMimeCryptoContext *ctx, const char *user_id, const char *prompt_ctx, gboolean reprompt, GMimeStream *response, GError **err) +{ + EM_DEBUG_FUNC_BEGIN(); + EM_DEBUG_LOG("passpharse : [%s]", passphrase); + if (g_mime_stream_write_string (response, passphrase) == -1 || + g_mime_stream_write (response, "\n", 1) == -1) { + g_set_error (err, GMIME_ERROR, errno, "%s", g_strerror (errno)); + return false; + } + + EM_SAFE_FREE(passphrase); + + EM_DEBUG_FUNC_END(); + return true; +} + +static int emcore_pgp_get_gmime_digest_algo(email_digest_type digest_type) +{ + EM_DEBUG_FUNC_BEGIN(); + int gmime_digest_algo = GMIME_DIGEST_ALGO_DEFAULT; + + switch (digest_type) { + case DIGEST_TYPE_SHA1: + gmime_digest_algo = GMIME_DIGEST_ALGO_SHA1; + break; + case DIGEST_TYPE_MD5: + gmime_digest_algo = GMIME_DIGEST_ALGO_MD5; + break; + case DIGEST_TYPE_RIPEMD160: + gmime_digest_algo = GMIME_DIGEST_ALGO_RIPEMD160; + break; + case DIGEST_TYPE_MD2: + gmime_digest_algo = GMIME_DIGEST_ALGO_MD2; + break; + case DIGEST_TYPE_TIGER192: + gmime_digest_algo = GMIME_DIGEST_ALGO_TIGER192; + break; + case DIGEST_TYPE_HAVAL5160: + gmime_digest_algo = GMIME_DIGEST_ALGO_HAVAL5160; + break; + case DIGEST_TYPE_SHA256: + gmime_digest_algo = GMIME_DIGEST_ALGO_SHA256; + break; + case DIGEST_TYPE_SHA384: + gmime_digest_algo = GMIME_DIGEST_ALGO_SHA384; + break; + case DIGEST_TYPE_SHA512: + gmime_digest_algo = GMIME_DIGEST_ALGO_SHA512; + break; + case DIGEST_TYPE_SHA224: + gmime_digest_algo = GMIME_DIGEST_ALGO_SHA224; + break; + case DIGEST_TYPE_MD4: + gmime_digest_algo = GMIME_DIGEST_ALGO_MD4; + break; + default: + gmime_digest_algo = GMIME_DIGEST_ALGO_DEFAULT; + break; + } + + EM_DEBUG_FUNC_END(); + return gmime_digest_algo; +} + +static int get_stack_of_recipients(char *recipients, GPtrArray **output_recipients_array) { + EM_DEBUG_FUNC_BEGIN(); + int err = EMAIL_ERROR_NONE; + int i, j = 0; + char *temp_recipients = NULL; + char *email_address = NULL; + + ADDRESS *token_address = NULL; + GPtrArray *p_recipients_array = NULL; + + p_recipients_array = g_ptr_array_new(); + if (p_recipients_array == NULL) { + EM_DEBUG_EXCEPTION("g_ptr_array_new failed"); + err = EMAIL_ERROR_OUT_OF_MEMORY; + goto FINISH_OFF; + } + + temp_recipients = EM_SAFE_STRDUP(recipients); + for (i = 0, j = EM_SAFE_STRLEN(temp_recipients); i < j ; i++) + if (temp_recipients[i] == ';') temp_recipients[i] = ','; + + rfc822_parse_adrlist(&token_address, temp_recipients, NULL); + + while (token_address) { + email_address = NULL; + email_address = g_strdup_printf("%s@%s", token_address->mailbox, token_address->host); + + g_ptr_array_add(p_recipients_array, email_address); + token_address = token_address->next; + } + +FINISH_OFF: + + if (err != EMAIL_ERROR_NONE) + g_ptr_array_free(p_recipients_array, true); + else + *output_recipients_array = p_recipients_array; + + EM_DEBUG_FUNC_END(); + return err; +} + +static GMimeSignatureStatus get_signature_status(GMimeSignatureList *signatures) +{ + EM_DEBUG_FUNC_BEGIN(); + + int i = 0; + + GMimeSignature *sig = NULL; + GMimeSignatureStatus status = GMIME_SIGNATURE_STATUS_GOOD; + + if (!signatures || signatures->array->len == 0) + return GMIME_SIGNATURE_STATUS_ERROR; + + for (i = 0; i < g_mime_signature_list_length(signatures); i++) { + sig = g_mime_signature_list_get_signature(signatures, i); + status = MAX(status, sig->status); + } + + EM_DEBUG_FUNC_END(); + + return status; +} + +INTERNAL_FUNC int emcore_pgp_set_signed_message(char *certificate, char *password, char *mime_entity, char *user_id, email_digest_type digest_type, char **file_path) +{ + EM_DEBUG_FUNC_BEGIN_SEC("Certificate path : [%s], mime_entity : [%s]", certificate, mime_entity); + +#ifdef __FEATURE_SECURE_PGP__ + int err = EMAIL_ERROR_NONE; + int clear_fd = 0; + int gpg_fd = 0; + int p_digest_type = 0; + char temp_pgp_filepath[512] = {0, }; + + GMimeCryptoContext *ctx = NULL; + GMimeStream *clear_text = NULL; + GMimeStream *signed_text = NULL; + GError *g_err = NULL; + + if (!password || !mime_entity || !user_id) { + EM_DEBUG_EXCEPTION("Invalid param"); + err = EMAIL_ERROR_INVALID_PARAM; + return err; + } + + /* Initialized the output stream (signed stream) */ + EM_SAFE_FREE(passphrase); + passphrase = EM_SAFE_STRDUP(password); + + g_thread_init(NULL); + g_mime_init(0); + + SNPRINTF(temp_pgp_filepath, sizeof(temp_pgp_filepath), "%s%s%s", MAILTEMP, DIR_SEPERATOR, PGP_SIGNED_FILE); + EM_DEBUG_LOG_SEC("attachment file path of pgp : [%s]", temp_pgp_filepath); + + err = em_open(temp_pgp_filepath, O_CREAT|O_TRUNC|O_RDWR, S_IRUSR|S_IWUSR|S_IWGRP|S_IRGRP|S_IROTH, &gpg_fd); + if (err != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("em_open failed : [%s] [%d]", temp_pgp_filepath, err); + goto FINISH_OFF; + } + + signed_text = g_mime_stream_fs_new(gpg_fd); + if (g_mime_stream_reset(signed_text) == -1) { + EM_DEBUG_EXCEPTION("g_mime_stream_reset signed_text failed"); + err = EMAIL_ERROR_SYSTEM_FAILURE; + goto FINISH_OFF; + } + + ctx = g_mime_gpg_context_new(request_passwd, "/usr/bin/gpg"); + g_mime_gpg_context_set_always_trust ((GMimeGpgContext *)ctx, true); + + /* Initialized the input stream (clear text stream) */ + EM_DEBUG_LOG("mime_entity : [%s]", mime_entity); + err = em_open(mime_entity, O_RDONLY, 0, &clear_fd); + if (err != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("em_open failed : [%s] [%d]", mime_entity, err); + goto FINISH_OFF; + } + + clear_text = g_mime_stream_fs_new(clear_fd); + if (g_mime_stream_reset(clear_text) == -1) { + EM_DEBUG_EXCEPTION("g_mime_stream_reset clear_text failed"); + err = EMAIL_ERROR_SYSTEM_FAILURE; + goto FINISH_OFF; + } + + /* Get the digest type of gmime */ + p_digest_type = emcore_pgp_get_gmime_digest_algo(digest_type); + + /* Set the signed message */ + if ((g_mime_crypto_context_sign(ctx, user_id, p_digest_type, clear_text, signed_text, &g_err) < 0) && (g_err != NULL)) { + EM_DEBUG_EXCEPTION("g_mime_crypto_context_sign failed : [%s]", g_err->message); + err = EMAIL_ERROR_SYSTEM_FAILURE; + goto FINISH_OFF; + } + +FINISH_OFF: + + if (g_err) + g_error_free(g_err); + + if (clear_text) + g_object_unref(clear_text); + + if (signed_text) + g_object_unref(signed_text); + + if (ctx) + g_object_unref(ctx); + + g_mime_shutdown(); + + close(clear_fd); + close(gpg_fd); + + if (file_path) + *file_path = EM_SAFE_STRDUP(temp_pgp_filepath); + + return err; +#else /* __FEATURE_SECURE_PGP__ */ + + return EMAIL_ERROR_NOT_SUPPORTED; + +#endif +} + +INTERNAL_FUNC int emcore_pgp_set_encrypted_message(char *recipient_list, char *certificate, char *password, char *mime_entity, char *user_id, email_digest_type digest_type, char **file_path) +{ + EM_DEBUG_FUNC_BEGIN_SEC("Certificate path : [%s], mime_entity : [%s]", certificate, mime_entity); + +#ifdef __FEATURE_SECURE_PGP__ + int err = EMAIL_ERROR_NONE; + int clear_fd = 0; + int gpg_fd = 0; + int p_digest_type = 0; + char temp_pgp_filepath[512] = {0, }; + + GPtrArray *recipients = NULL; + + GMimeCryptoContext *ctx = NULL; + GMimeStream *clear_text = NULL; + GMimeStream *encrypted_text = NULL; + GError *g_err = NULL; + + if (!recipient_list || !password || !mime_entity || !user_id) { + EM_DEBUG_EXCEPTION("Invalid param"); + err = EMAIL_ERROR_INVALID_PARAM; + return err; + } + + /* Initialized the output stream (signed stream) */ + EM_SAFE_FREE(passphrase); + passphrase = EM_SAFE_STRDUP(password); + + g_thread_init(NULL); + g_mime_init(0); + + SNPRINTF(temp_pgp_filepath, sizeof(temp_pgp_filepath), "%s%s%s", MAILTEMP, DIR_SEPERATOR, PGP_ENCRYPTED_FILE); + EM_DEBUG_LOG_SEC("attachment file path of pgp : [%s]", temp_pgp_filepath); + + err = em_open(temp_pgp_filepath, O_CREAT|O_TRUNC|O_RDWR, S_IRUSR|S_IWUSR|S_IWGRP|S_IRGRP|S_IROTH, &gpg_fd); + if (err != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("em_open failed : [%s] [%d]", temp_pgp_filepath, err); + goto FINISH_OFF; + } + + encrypted_text = g_mime_stream_fs_new(gpg_fd); + if (g_mime_stream_reset(encrypted_text) == -1) { + EM_DEBUG_EXCEPTION("g_mime_stream_reset encrypted_text failed"); + err = EMAIL_ERROR_SYSTEM_FAILURE; + goto FINISH_OFF; + } + + ctx = g_mime_gpg_context_new(request_passwd, "/usr/bin/gpg"); + g_mime_gpg_context_set_always_trust ((GMimeGpgContext *)ctx, true); + + /* Initialized the input stream (clear text stream) */ + EM_DEBUG_LOG("mime_entity : [%s]", mime_entity); + err = em_open(mime_entity, O_RDONLY, 0, &clear_fd); + if (err != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("em_open failed : [%s] [%d]", mime_entity, err); + goto FINISH_OFF; + } + + clear_text = g_mime_stream_fs_new(clear_fd); + if (g_mime_stream_reset(clear_text) == -1) { + EM_DEBUG_EXCEPTION("g_mime_stream_reset clear_text failed"); + err = EMAIL_ERROR_SYSTEM_FAILURE; + goto FINISH_OFF; + } + + /* Get the digest type of gmime */ + p_digest_type = emcore_pgp_get_gmime_digest_algo(digest_type); + + /* Set the recipients list */ + if ((err = get_stack_of_recipients(recipient_list, &recipients)) != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("get_stack_of_recipients failed : [%d]", err); + goto FINISH_OFF; + } + + /* Set the signed message */ + if ((g_mime_crypto_context_encrypt(ctx, false, user_id, p_digest_type, recipients, clear_text, encrypted_text, &g_err) < 0) && (g_err != NULL)) { + EM_DEBUG_EXCEPTION("NO signature : g_mime_crypto_context_encrypt failed : [%s]", g_err->message); + err = EMAIL_ERROR_SYSTEM_FAILURE; + goto FINISH_OFF; + } + +FINISH_OFF: + + g_ptr_array_free(recipients, true); + + if (g_err) + g_error_free(g_err); + + if (clear_text) + g_object_unref(clear_text); + + if (encrypted_text) + g_object_unref(encrypted_text); + + if (ctx) + g_object_unref(ctx); + + g_mime_shutdown(); + + close(clear_fd); + close(gpg_fd); + + if (file_path) + *file_path = EM_SAFE_STRDUP(temp_pgp_filepath); + + return err; +#else /* __FEATURE_SECURE_PGP__ */ + + return EMAIL_ERROR_NOT_SUPPORTED; + +#endif + +} + +INTERNAL_FUNC int emcore_pgp_set_signed_and_encrypted_message(char *recipient_list, char *certificate, char *password, char *mime_entity, char *user_id, email_digest_type digest_type, char **file_path) +{ + EM_DEBUG_FUNC_BEGIN_SEC("mime_entity : [%s]", mime_entity); + +#ifdef __FEATURE_SECURE_PGP__ + int err = EMAIL_ERROR_NONE; + int clear_fd = 0; + int gpg_fd = 0; + int p_digest_type = 0; + char temp_pgp_filepath[512] = {0, }; + + GPtrArray *recipients = NULL; + + GMimeCryptoContext *ctx = NULL; + GMimeStream *clear_text = NULL; + GMimeStream *encrypted_text = NULL; + GError *g_err = NULL; + + if (!recipient_list || !password || !mime_entity || !user_id) { + EM_DEBUG_EXCEPTION("Invalid param"); + err = EMAIL_ERROR_INVALID_PARAM; + return err; + } + + /* Initialized the output stream (signed stream) */ + EM_SAFE_FREE(passphrase); + passphrase = strdup(password); + + g_thread_init(NULL); + g_mime_init(0); + + SNPRINTF(temp_pgp_filepath, sizeof(temp_pgp_filepath), "%s%s%s", MAILTEMP, DIR_SEPERATOR, PGP_ENCRYPTED_FILE); + EM_DEBUG_LOG_SEC("attachment file path of pgp : [%s]", temp_pgp_filepath); + + err = em_open(temp_pgp_filepath, O_CREAT|O_TRUNC|O_RDWR, S_IRUSR|S_IWUSR|S_IWGRP|S_IRGRP|S_IROTH, &gpg_fd); + if (err != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("em_open failed : [%s], [%d]", temp_pgp_filepath, err); + goto FINISH_OFF; + } + + encrypted_text = g_mime_stream_fs_new(gpg_fd); + if (g_mime_stream_reset(encrypted_text) == -1) { + EM_DEBUG_EXCEPTION("g_mime_stream_reset encrypted_text failed"); + err = EMAIL_ERROR_SYSTEM_FAILURE; + goto FINISH_OFF; + } + + ctx = g_mime_gpg_context_new(request_passwd, "/usr/bin/gpg"); + g_mime_gpg_context_set_always_trust ((GMimeGpgContext *)ctx, true); + + /* Initialized the input stream (clear text stream) */ + EM_DEBUG_LOG("mime_entity : [%s]", mime_entity); + err = em_open(mime_entity, O_RDONLY, 0, &clear_fd); + if (err != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("em_open failed : [%s] [%d]", mime_entity, err); + goto FINISH_OFF; + } + + clear_text = g_mime_stream_fs_new(clear_fd); + if (g_mime_stream_reset(clear_text) == -1) { + EM_DEBUG_EXCEPTION("g_mime_stream_reset clear_text failed"); + err = EMAIL_ERROR_SYSTEM_FAILURE; + goto FINISH_OFF; + } + + /* Get the digest type of gmime */ + p_digest_type = emcore_pgp_get_gmime_digest_algo(digest_type); + + /* Set the recipients list */ + if ((err = get_stack_of_recipients(recipient_list, &recipients)) != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("get_stack_of_recipients failed : [%d]", err); + goto FINISH_OFF; + } + + /* Set the signed message */ + if ((g_mime_crypto_context_encrypt(ctx, true, user_id, p_digest_type, recipients, clear_text, encrypted_text, &g_err) < 0) && (g_err != NULL)) { + EM_DEBUG_EXCEPTION("Signature : g_mime_crypto_context_encrypt failed : [%s]", g_err->message); + err = EMAIL_ERROR_SYSTEM_FAILURE; + goto FINISH_OFF; + } + +FINISH_OFF: + + g_ptr_array_free(recipients, true); + + if (g_err) + g_error_free(g_err); + + if (clear_text) + g_object_unref(clear_text); + + if (encrypted_text) + g_object_unref(encrypted_text); + + if (ctx) + g_object_unref(ctx); + + g_mime_shutdown(); + + close(clear_fd); + close(gpg_fd); + + if (file_path) + *file_path = EM_SAFE_STRDUP(temp_pgp_filepath); + + return err; +#else /* __FEATURE_SECURE_PGP__ */ + + return EMAIL_ERROR_NOT_SUPPORTED; + +#endif + +} + +INTERNAL_FUNC int emcore_pgp_get_verify_signature(char *signature_path, char *mime_entity, email_digest_type digest_type, int *verify) +{ + EM_DEBUG_FUNC_BEGIN_SEC("signature path : [%s], mime_entity : [%s]", signature_path, mime_entity); + +#ifdef __FEATURE_SECURE_PGP__ + int err = EMAIL_ERROR_NONE; + int clear_fd = 0; + int signed_fd = 0; + int p_digest_type = 0; + int p_verify = false; + + GMimeCryptoContext *ctx = NULL; + GMimeStream *clear_text = NULL; + GMimeStream *signed_text = NULL; + GMimeSignatureList *signatures = NULL; + GError *g_err = NULL; + + if (!signature_path || !mime_entity) { + EM_DEBUG_EXCEPTION("Invalid param"); + err = EMAIL_ERROR_INVALID_PARAM; + return err; + } + + /* Initialized the Context */ + g_thread_init(NULL); + g_mime_init(0); + + ctx = g_mime_gpg_context_new(request_passwd, "/usr/bin/gpg"); + g_mime_gpg_context_set_always_trust ((GMimeGpgContext *)ctx, true); + + /* Initialized the input stream (clear text stream) */ + EM_DEBUG_LOG("mime_entity : [%s]", mime_entity); + err = em_open(mime_entity, O_RDONLY, 0, &clear_fd); + if (err != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("em_open failed : [%s] [%d]", mime_entity, err); + goto FINISH_OFF; + } + + clear_text = g_mime_stream_fs_new(clear_fd); + if (g_mime_stream_reset(clear_text) == -1) { + EM_DEBUG_EXCEPTION("g_mime_stream_reset clear_text failed"); + err = EMAIL_ERROR_SYSTEM_FAILURE; + goto FINISH_OFF; + } + + /* Initialized the output stream (signed stream) */ + EM_DEBUG_LOG("signature_path : [%s]", signature_path); + err = em_open(signature_path, O_RDONLY, 0, &signed_fd); + if (err != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("em_open failed : [%s] [%d]", signature_path, err); + goto FINISH_OFF; + } + + signed_text = g_mime_stream_fs_new(signed_fd); + if (g_mime_stream_reset(signed_text) == -1) { + EM_DEBUG_EXCEPTION("g_mime_stream_reset signed_text failed"); + err = EMAIL_ERROR_SYSTEM_FAILURE; + goto FINISH_OFF; + } + + /* Get the digest type of gmime */ + p_digest_type = emcore_pgp_get_gmime_digest_algo(digest_type); + + /* Verify the signature */ + signatures = g_mime_crypto_context_verify(ctx, p_digest_type, clear_text, signed_text, &g_err); + if (signatures == NULL) { + EM_DEBUG_EXCEPTION("g_mime_crypto_context_verify failed : [%s]", g_err->message); + err = EMAIL_ERROR_SYSTEM_FAILURE; + goto FINISH_OFF; + } + + if (get_signature_status(signatures) != GMIME_SIGNATURE_STATUS_GOOD) { + EM_DEBUG_LOG("Invalid the signature"); + goto FINISH_OFF; + } + + p_verify = true; + +FINISH_OFF: + + if (g_err) + g_error_free(g_err); + + if (signatures) + g_object_unref(signatures); + + if (clear_text) + g_object_unref(clear_text); + + if (signed_text) + g_object_unref(signed_text); + + if (ctx) + g_object_unref(ctx); + + g_mime_shutdown(); + + close(clear_fd); + close(signed_fd); + + if (verify) + *verify = p_verify; + + return err; +#else /* __FEATURE_SECURE_PGP__ */ + + return EMAIL_ERROR_NOT_SUPPORTED; + +#endif + +} + +INTERNAL_FUNC int emcore_pgp_get_decrypted_message(char *encrypted_message, char *password, int sign, char **decrypted_file, int *verify) +{ + EM_DEBUG_FUNC_BEGIN_SEC("Encrypted message : [%s], password : [%s]", encrypted_message, password); + +#ifdef __FEATURE_SECURE_PGP__ + int err = EMAIL_ERROR_NONE; + int p_verify = false; + int decrypted_fd = 0; + int encrypted_fd = 0; + char temp_decrypt_filepath[512] = {0, }; + + GError *g_err = NULL; + GMimeCryptoContext *ctx = NULL; + GMimeDecryptResult *result = NULL; + GMimeStream *encrypted_text = NULL; + GMimeStream *decrypted_text = NULL; + + if (!encrypted_message && !password) { + EM_DEBUG_EXCEPTION("Invalid parameter"); + err = EMAIL_ERROR_INVALID_PARAM; + return err; + } + + EM_SAFE_FREE(passphrase); + passphrase = EM_SAFE_STRDUP(password); + + g_thread_init(NULL); + g_mime_init(0); + + /* Initialized the context */ + ctx = g_mime_gpg_context_new(request_passwd, "/usr/bin/gpg"); + g_mime_gpg_context_set_always_trust ((GMimeGpgContext *)ctx, true); + + /* Initialized the input stream (clear text stream) */ + err = em_open(encrypted_message, O_RDONLY, 0, &encrypted_fd); + if (err != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("em_open failed : [%s] [%d]", encrypted_message, err); + goto FINISH_OFF; + } + + encrypted_text = g_mime_stream_fs_new(encrypted_fd); + if (g_mime_stream_reset(encrypted_text) == -1) { + EM_DEBUG_EXCEPTION("g_mime_stream_reset encrypted_text failed"); + err = EMAIL_ERROR_SYSTEM_FAILURE; + goto FINISH_OFF; + } + + /* Initialized the output stream (signed stream) */ + SNPRINTF(temp_decrypt_filepath, sizeof(temp_decrypt_filepath), "%s%s%s", MAILTEMP, DIR_SEPERATOR, DECRYPTED_TEMP_FILE); + EM_DEBUG_LOG_SEC("tmp decrypt file path : [%s]", temp_decrypt_filepath); + + err = em_open(temp_decrypt_filepath, O_CREAT|O_TRUNC|O_RDWR, S_IRUSR|S_IWUSR|S_IWGRP|S_IRGRP|S_IROTH, &decrypted_fd); + if (err != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("em_open failed : [%s] [%d]", temp_decrypt_filepath, err); + goto FINISH_OFF; + } + + decrypted_text = g_mime_stream_fs_new(decrypted_fd); + if (g_mime_stream_reset(decrypted_text) == -1) { + EM_DEBUG_EXCEPTION("g_mime_stream_reset decrypted_text failed"); + err = EMAIL_ERROR_SYSTEM_FAILURE; + goto FINISH_OFF; + } + + /* Get the decrypt message */ + result = g_mime_crypto_context_decrypt(ctx, encrypted_text, decrypted_text, &g_err); + if (result == NULL) { + EM_DEBUG_EXCEPTION("g_mime_crypto_context_decrypt failed : [%s]", g_err->message); + err = EMAIL_ERROR_DECRYPT_FAILED; + goto FINISH_OFF; + } + + if (sign) { + if (!result->signatures || get_signature_status(result->signatures) != GMIME_SIGNATURE_STATUS_GOOD) + p_verify = false; + else + p_verify = true; + } + +FINISH_OFF: + + if (g_err) + g_error_free(g_err); + + if (ctx) + g_object_unref(ctx); + + if (encrypted_text) + g_object_unref(encrypted_text); + + if (decrypted_text) + g_object_unref(decrypted_text); + + if (result) + g_object_unref(result); + + g_mime_shutdown(); + + close(encrypted_fd); + close(decrypted_fd); + + if (verify) + *verify = p_verify; + + if (decrypted_file) + *decrypted_file = EM_SAFE_STRDUP(temp_decrypt_filepath); + + return err; +#else /* __FEATURE_SECURE_PGP__ */ + + return EMAIL_ERROR_NOT_SUPPORTED; + +#endif +} + diff --git a/email-core/email-core-signal.c b/email-core/email-core-signal.c index eaf9818..8964cb6 100755 --- a/email-core/email-core-signal.c +++ b/email-core/email-core-signal.c @@ -263,24 +263,31 @@ INTERNAL_FUNC int em_send_notification_to_active_sync_engine(int subType, ASNoti switch(data->search_mail_on_server.search_filter_list[i].search_filter_type) {
case EMAIL_SEARCH_FILTER_TYPE_MESSAGE_NO :
case EMAIL_SEARCH_FILTER_TYPE_UID :
+ case EMAIL_SEARCH_FILTER_TYPE_ALL :
case EMAIL_SEARCH_FILTER_TYPE_SIZE_LARSER :
case EMAIL_SEARCH_FILTER_TYPE_SIZE_SMALLER :
case EMAIL_SEARCH_FILTER_TYPE_FLAGS_ANSWERED :
+ case EMAIL_SEARCH_FILTER_TYPE_FLAGS_NEW :
case EMAIL_SEARCH_FILTER_TYPE_FLAGS_DELETED :
+ case EMAIL_SEARCH_FILTER_TYPE_FLAGS_OLD :
case EMAIL_SEARCH_FILTER_TYPE_FLAGS_DRAFT :
case EMAIL_SEARCH_FILTER_TYPE_FLAGS_FLAGED :
case EMAIL_SEARCH_FILTER_TYPE_FLAGS_RECENT :
case EMAIL_SEARCH_FILTER_TYPE_FLAGS_SEEN :
+ case EMAIL_SEARCH_FILTER_TYPE_HEADER_PRIORITY :
dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->search_mail_on_server.search_filter_list[i].search_filter_key_value.integer_type_key_value), DBUS_TYPE_INVALID);
break;
case EMAIL_SEARCH_FILTER_TYPE_BCC :
+ case EMAIL_SEARCH_FILTER_TYPE_BODY :
case EMAIL_SEARCH_FILTER_TYPE_CC :
case EMAIL_SEARCH_FILTER_TYPE_FROM :
case EMAIL_SEARCH_FILTER_TYPE_KEYWORD :
+ case EMAIL_SEARCH_FILTER_TYPE_TEXT :
case EMAIL_SEARCH_FILTER_TYPE_SUBJECT :
case EMAIL_SEARCH_FILTER_TYPE_TO :
case EMAIL_SEARCH_FILTER_TYPE_MESSAGE_ID :
+ case EMAIL_SEARCH_FILTER_TYPE_ATTACHMENT_NAME :
dbus_message_append_args(signal, DBUS_TYPE_STRING, &(data->search_mail_on_server.search_filter_list[i].search_filter_key_value.string_type_key_value), DBUS_TYPE_INVALID);
break;
diff --git a/email-core/email-core-smime.c b/email-core/email-core-smime.c index bb9103a..fdf114c 100755 --- a/email-core/email-core-smime.c +++ b/email-core/email-core-smime.c @@ -37,6 +37,7 @@ #include <openssl/buffer.h> #include <openssl/pem.h> #include <openssl/err.h> +#include <openssl/ssl.h> #include "email-utilities.h" #include "email-core-global.h" @@ -45,6 +46,7 @@ #include "email-core-smtp.h" #include "email-storage.h" #include "email-core-smime.h" +#include "email-core-pgp.h" #include "email-core-cert.h" #include "email-debug-log.h" @@ -168,7 +170,7 @@ static int get_x509_stack_of_recipient_certs(char *recipients, STACK_OF(X509) ** goto FINISH_OFF; } - EM_DEBUG_LOG("email_address_mailbox : [%s], email_address_host : [%s]", token_address->mailbox, token_address->host); + EM_DEBUG_LOG_SEC("email_address_mailbox : [%s], email_address_host : [%s]", token_address->mailbox, token_address->host); email_address = g_strdup_printf("<%s@%s>", token_address->mailbox, token_address->host); if (!emstorage_get_certificate_by_email_address(email_address, &cert, false, 0, &err)) { @@ -184,9 +186,8 @@ static int get_x509_stack_of_recipient_certs(char *recipients, STACK_OF(X509) ** SNPRINTF(file_name, sizeof(file_name), "%s", cert->filepath); EM_DEBUG_LOG_SEC("file_name : [%s]", file_name); - err = cert_svc_load_file_to_context(context, file_name); - if (err != CERT_SVC_ERR_NO_ERROR) { - EM_DEBUG_EXCEPTION("cert_svc_load_file_to_context failed : [%d]", err); + if (cert_svc_load_file_to_context(context, file_name) != CERT_SVC_ERR_NO_ERROR) { + EM_DEBUG_EXCEPTION("cert_svc_load_file_to_context failed"); err = EMAIL_ERROR_SYSTEM_FAILURE; goto FINISH_OFF; } @@ -319,9 +320,6 @@ INTERNAL_FUNC int emcore_smime_set_signed_message(char *certificate, char *mime_ PKCS7 *signed_message = NULL; int flags = PKCS7_DETACHED | PKCS7_PARTIAL; - OpenSSL_add_all_algorithms(); - ERR_load_crypto_strings(); - SNPRINTF(temp_smime_filepath, sizeof(temp_smime_filepath), "%s%s%s", MAILTEMP, DIR_SEPERATOR, SMIME_SIGNED_FILE); EM_DEBUG_LOG_SEC("attachment file path of smime : [%s]", temp_smime_filepath); @@ -389,7 +387,6 @@ FINISH_OFF: BIO_free(bio_prikey); BIO_free_all(smime_attachment); - EVP_cleanup(); if (err_code != NULL) *err_code = err; @@ -413,9 +410,6 @@ INTERNAL_FUNC int emcore_smime_set_encrypt_message(char *recipient_list, char *m PKCS7 *encrypt_message = NULL; const EVP_CIPHER *cipher = NULL; - OpenSSL_add_all_algorithms(); - ERR_load_crypto_strings(); - loaded_cert = cert_svc_cert_context_init(); SNPRINTF(temp_smime_filepath, sizeof(temp_smime_filepath), "%s%s%s", MAILTEMP, DIR_SEPERATOR, SMIME_ENCRYPT_FILE); @@ -472,7 +466,6 @@ FINISH_OFF: BIO_free_all(smime_attachment); cert_svc_cert_context_final(loaded_cert); - EVP_cleanup(); if (err_code != NULL) *err_code = err; @@ -502,9 +495,6 @@ INTERNAL_FUNC int emcore_smime_set_signed_and_encrypt_message(char *recipient_li EVP_PKEY *private_key = NULL; X509 *cert = NULL; - OpenSSL_add_all_algorithms(); - ERR_load_crypto_strings(); - SNPRINTF(temp_smime_filepath, sizeof(temp_smime_filepath), "%s%s%s", MAILTEMP, DIR_SEPERATOR, SMIME_ENCRYPT_FILE); EM_DEBUG_LOG_SEC("attachment file path of smime : [%s]", temp_smime_filepath); @@ -623,7 +613,6 @@ FINISH_OFF: BIO_free(bio_signed_message); BIO_free_all(smime_attachment); - EVP_cleanup(); if (err_code != NULL) *err_code = err; @@ -631,9 +620,7 @@ FINISH_OFF: return ret; } - - -INTERNAL_FUNC int emcore_smime_set_decrypt_message(char *encrypt_message, char *certificate, char **decrypt_message, int *err_code) +INTERNAL_FUNC int emcore_smime_get_decrypt_message(char *encrypt_message, char *certificate, char **decrypt_message, int *err_code) { EM_DEBUG_FUNC_BEGIN_SEC("encrypt_file : [%s], certificate : [%s]", encrypt_message, certificate); int ret = false; @@ -646,8 +633,6 @@ INTERNAL_FUNC int emcore_smime_set_decrypt_message(char *encrypt_message, char * PKCS7 *p7_encrypt_message = NULL; STACK_OF(X509) *recipient_certs = NULL; - OpenSSL_add_all_algorithms(); - /* Load the encrypted message */ infile = BIO_new_file(encrypt_message, INMODE); if (infile == NULL) { @@ -693,7 +678,6 @@ FINISH_OFF: if (decrypt_message && ret) *decrypt_message = EM_SAFE_STRDUP(temp_decrypt_filepath); - EVP_cleanup(); X509_free(cert); EVP_PKEY_free(private_key); BIO_free(out_buf); @@ -718,9 +702,6 @@ INTERNAL_FUNC int emcore_smime_verify_signed_message(char *signed_message, char X509_LOOKUP *lookup = NULL; PKCS7 *p7 = NULL; - OpenSSL_add_all_algorithms(); - ERR_load_crypto_strings(); - if (BIO_write(indata, signed_message, sizeof(signed_message)) <= 0) { EM_DEBUG_EXCEPTION("Char to Bio failed"); goto FINISH_OFF; @@ -786,7 +767,6 @@ FINISH_OFF: *verify = temp_verify; ERR_clear_error(); - EVP_cleanup(); return ret; } */ @@ -795,7 +775,7 @@ INTERNAL_FUNC int emcore_convert_mail_data_to_smime_data(emstorage_account_tbl_t { EM_DEBUG_FUNC_BEGIN("input_mail_data[%p], input_attachment_data_list [%p], input_attachment_count [%d], output_mail_data [%p], output_attachment_data_list [%p]", input_mail_data, input_attachment_data_list, input_attachment_count, output_mail_data, output_attachment_data_list); - int i = 0, ret = false; + int i = 0; int err = EMAIL_ERROR_NONE; int smime_type = EMAIL_SMIME_NONE; int address_length = 0; @@ -812,7 +792,7 @@ INTERNAL_FUNC int emcore_convert_mail_data_to_smime_data(emstorage_account_tbl_t || !output_attachment_count || !output_mail_data || !output_attachment_data_list ) { /*prevent#53051*/ EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM"); err = EMAIL_ERROR_INVALID_PARAM; - return ret; + return err; } smime_type = input_mail_data->smime_type; @@ -859,7 +839,7 @@ INTERNAL_FUNC int emcore_convert_mail_data_to_smime_data(emstorage_account_tbl_t attachment_count = 1; break; - default: /* Signed and Encryption message */ + case EMAIL_SMIME_SIGNED_AND_ENCRYPTED: /* Signed and Encryption message */ address_length = EM_SAFE_STRLEN(input_mail_data->full_address_from) + EM_SAFE_STRLEN(input_mail_data->full_address_to) + EM_SAFE_STRLEN(input_mail_data->full_address_cc) + EM_SAFE_STRLEN(input_mail_data->full_address_bcc); other_certificate_list = em_malloc(address_length + 4); @@ -881,6 +861,67 @@ INTERNAL_FUNC int emcore_convert_mail_data_to_smime_data(emstorage_account_tbl_t attachment_count = 1; break; + case EMAIL_PGP_SIGNED: + if ((err = emcore_pgp_set_signed_message(NULL, input_mail_data->pgp_password, input_mail_data->file_path_mime_entity, account_tbl_item->user_email_address, account_tbl_item->digest_type, &smime_file_path)) != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("em_core_smime_set_clear_signed_message is failed : [%d]", err); + goto FINISH_OFF; + } + + EM_DEBUG_LOG_SEC("smime_file_path : %s", smime_file_path); + name = strrchr(smime_file_path, '/'); + + new_attachment_data.attachment_name = EM_SAFE_STRDUP(name + 1); + new_attachment_data.attachment_path = EM_SAFE_STRDUP(smime_file_path); + new_attachment_data.attachment_mime_type = strdup("pgp-signature"); + + attachment_count += 1; + + break; + case EMAIL_PGP_ENCRYPTED: + address_length = EM_SAFE_STRLEN(input_mail_data->full_address_from) + EM_SAFE_STRLEN(input_mail_data->full_address_to) + EM_SAFE_STRLEN(input_mail_data->full_address_cc) + EM_SAFE_STRLEN(input_mail_data->full_address_bcc); + + other_certificate_list = em_malloc(address_length + 4); + + SNPRINTF(other_certificate_list, address_length + 2, "%s;%s;%s;%s", input_mail_data->full_address_from, input_mail_data->full_address_to, input_mail_data->full_address_cc, input_mail_data->full_address_bcc); + + if ((err = emcore_pgp_set_encrypted_message(other_certificate_list, NULL, input_mail_data->pgp_password, input_mail_data->file_path_mime_entity, account_tbl_item->user_email_address, input_mail_data->digest_type, &smime_file_path)) != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emcore_pgp_set_encrypted_message failed : [%d]", err); + goto FINISH_OFF; + } + + name = strrchr(smime_file_path, '/'); + + new_attachment_data.attachment_name = EM_SAFE_STRDUP(name + 1); + new_attachment_data.attachment_path = EM_SAFE_STRDUP(smime_file_path); + new_attachment_data.attachment_mime_type = strdup("octet-stream"); + + attachment_count = 1; + + break; + case EMAIL_PGP_SIGNED_AND_ENCRYPTED: + address_length = EM_SAFE_STRLEN(input_mail_data->full_address_from) + EM_SAFE_STRLEN(input_mail_data->full_address_to) + EM_SAFE_STRLEN(input_mail_data->full_address_cc) + EM_SAFE_STRLEN(input_mail_data->full_address_bcc); + + other_certificate_list = em_malloc(address_length + 4); + + SNPRINTF(other_certificate_list, address_length + 2, "%s;%s;%s;%s", input_mail_data->full_address_from, input_mail_data->full_address_to, input_mail_data->full_address_cc, input_mail_data->full_address_bcc); + + if ((err = emcore_pgp_set_signed_and_encrypted_message(other_certificate_list, NULL, input_mail_data->pgp_password, input_mail_data->file_path_mime_entity, account_tbl_item->user_email_address, input_mail_data->digest_type, &smime_file_path)) != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emcore_pgp_set_encrypted_message failed : [%d]", err); + goto FINISH_OFF; + } + + name = strrchr(smime_file_path, '/'); + + new_attachment_data.attachment_name = EM_SAFE_STRDUP(name + 1); + new_attachment_data.attachment_path = EM_SAFE_STRDUP(smime_file_path); + new_attachment_data.attachment_mime_type = strdup("octet-stream"); + + attachment_count = 1; + + break; + default: + EM_DEBUG_LOG("MIME none"); + break; } if (!emcore_get_file_size(smime_file_path, &file_size, NULL)) { @@ -894,6 +935,7 @@ INTERNAL_FUNC int emcore_convert_mail_data_to_smime_data(emstorage_account_tbl_t new_attachment_list = (email_attachment_data_t *)em_malloc(sizeof(email_attachment_data_t) * attachment_count); if (new_attachment_list == NULL) { EM_DEBUG_EXCEPTION("em_malloc failed"); + err = EMAIL_ERROR_OUT_OF_MEMORY; goto FINISH_OFF; } @@ -902,6 +944,7 @@ INTERNAL_FUNC int emcore_convert_mail_data_to_smime_data(emstorage_account_tbl_t new_attachment_list[i].attachment_id = input_attachment_data_list[i].attachment_id; new_attachment_list[i].attachment_name = EM_SAFE_STRDUP(input_attachment_data_list[i].attachment_name); new_attachment_list[i].attachment_path = EM_SAFE_STRDUP(input_attachment_data_list[i].attachment_path); + new_attachment_list[i].content_id = EM_SAFE_STRDUP(input_attachment_data_list[i].content_id); new_attachment_list[i].attachment_size = input_attachment_data_list[i].attachment_size; new_attachment_list[i].mail_id = input_attachment_data_list[i].mail_id; new_attachment_list[i].account_id = input_attachment_data_list[i].account_id; @@ -916,6 +959,7 @@ INTERNAL_FUNC int emcore_convert_mail_data_to_smime_data(emstorage_account_tbl_t new_attachment_list[attachment_count - 1].attachment_id = new_attachment_data.attachment_id; new_attachment_list[attachment_count - 1].attachment_name = EM_SAFE_STRDUP(new_attachment_data.attachment_name); new_attachment_list[attachment_count - 1].attachment_path = EM_SAFE_STRDUP(new_attachment_data.attachment_path); + new_attachment_list[attachment_count - 1].content_id = EM_SAFE_STRDUP(new_attachment_data.content_id); new_attachment_list[attachment_count - 1].attachment_size = new_attachment_data.attachment_size; new_attachment_list[attachment_count - 1].mail_id = new_attachment_data.mail_id; new_attachment_list[attachment_count - 1].account_id = new_attachment_data.account_id; @@ -928,11 +972,10 @@ INTERNAL_FUNC int emcore_convert_mail_data_to_smime_data(emstorage_account_tbl_t input_mail_data->smime_type = smime_type; input_mail_data->digest_type = account_tbl_item->digest_type; - ret = true; - FINISH_OFF: EM_SAFE_FREE(other_certificate_list); + EM_SAFE_FREE(smime_file_path); *output_attachment_count = attachment_count; @@ -940,7 +983,27 @@ FINISH_OFF: *output_mail_data = input_mail_data; - return ret; + EM_SAFE_FREE(new_attachment_data.attachment_name); + EM_SAFE_FREE(new_attachment_data.attachment_path); + EM_SAFE_FREE(new_attachment_data.attachment_mime_type); + EM_SAFE_FREE(new_attachment_data.content_id); + + EM_DEBUG_LOG("err : [%d]", err); + return err; } +INTERNAL_FUNC void emcore_init_openssl_library() +{ + EM_DEBUG_FUNC_BEGIN(); + SSL_library_init(); + ERR_load_crypto_strings(); + EM_DEBUG_FUNC_END(); +} +INTERNAL_FUNC void emcore_clean_openssl_library() +{ + EM_DEBUG_FUNC_BEGIN(); + ERR_free_strings(); + EVP_cleanup(); + EM_DEBUG_FUNC_END(); +} diff --git a/email-core/email-core-smtp.c b/email-core/email-core-smtp.c index 7414588..b19e1ae 100755 --- a/email-core/email-core-smtp.c +++ b/email-core/email-core-smtp.c @@ -32,6 +32,7 @@ #include <alarm.h> #include <dlfcn.h> #include <ctype.h> +#include <sys/shm.h> #include "email-internal-types.h" #include "c-client.h" @@ -52,6 +53,7 @@ #include "email-utilities.h" #include "email-convert.h" #include "email-debug-log.h" +#include "email-core-gmime.h" #undef min @@ -162,8 +164,7 @@ static char *emcore_replace_inline_image_path_with_content_id(char *source_strin cur_body = root_body; if (root_body->type != TYPEMULTIPART) { - EM_DEBUG_EXCEPTION("Invalid related type : type[%d]", root_body->type); - err = EMAIL_ERROR_INVALID_DATA; + EM_DEBUG_LOG("The body is not multipart : type[%d]", root_body->type); goto FINISH_OFF; } @@ -197,7 +198,7 @@ static char *emcore_replace_inline_image_path_with_content_id(char *source_strin if (result_string) { EM_SAFE_FREE(input_string); input_string = result_string; - result_string = NULL; + result_string = NULL; /* prevent 34868 */ } cur_part = cur_part->next; @@ -206,7 +207,7 @@ static char *emcore_replace_inline_image_path_with_content_id(char *source_strin if (cur_part) cur_body = &(cur_part->body); - else + else cur_body = NULL; } while (cur_body); @@ -247,7 +248,6 @@ static int emcore_write_body (BODY *body, BODY *root_body, FILE *fp) 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; @@ -278,9 +278,9 @@ static int emcore_write_body (BODY *body, BODY *root_body, FILE *fp) goto FINISH_OFF; } - if (!(fp_html = fopen (file_path, "r"))) { - EM_DEBUG_EXCEPTION("fopen [%s] error [%d] ", file_path, errno); - error = EMAIL_ERROR_FILE ; + error = em_fopen(file_path, "r", &fp_html); + if (error != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("em_fopen [%s] error [%d] ", file_path, error); goto FINISH_OFF; } @@ -326,10 +326,9 @@ static int emcore_write_body (BODY *body, BODY *root_body, FILE *fp) } EM_DEBUG_LOG_DEV("tmp file path : %s", tmp_file_path); - fp_write = fopen (tmp_file_path, "w"); - if (fp_write == NULL) { - EM_DEBUG_EXCEPTION_SEC ("fopen [%s] error [%d]", tmp_file_path, errno); - error = EMAIL_ERROR_FILE ; + error = em_fopen(tmp_file_path, "w", &fp_write); + if (error != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION_SEC ("em_fopen [%s] error [%d]", tmp_file_path, error); goto FINISH_OFF; } @@ -344,7 +343,7 @@ static int emcore_write_body (BODY *body, BODY *root_body, FILE *fp) error = EMAIL_ERROR_FILE; goto FINISH_OFF; } - + file_path = tmp_file_path; fclose(fp_write); fp_write = NULL; @@ -355,10 +354,9 @@ static int emcore_write_body (BODY *body, BODY *root_body, FILE *fp) EM_DEBUG_LOG_DEV("Opening a file[%s]", file_path); - fd = open (file_path, O_RDONLY); - if (fd < 0) { - EM_DEBUG_EXCEPTION_SEC("open[%s] error [%d]", file_path, errno); - error = EMAIL_ERROR_OUT_OF_MEMORY; + error = em_open(file_path, O_RDONLY, 0, &fd); + if (error != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION_SEC("open[%s] error [%d]", file_path, error); goto FINISH_OFF; } @@ -374,7 +372,7 @@ static int emcore_write_body (BODY *body, BODY *root_body, FILE *fp) EM_DEBUG_EXCEPTION ("read [%s] error [%d]", file_path, errno); error = EMAIL_ERROR_FILE; break; - } + } len = nread; @@ -408,13 +406,14 @@ FINISH_OFF: /* prevent 34226 */ /* cleanup local vars */ EM_SAFE_FREE (body->sparep); - close(fd); + EM_SAFE_CLOSE (fd); /*prevent 34498*/ EM_SAFE_FREE (p); - if (tmp_file_path) + if (tmp_file_path) g_remove(tmp_file_path); - if (fp_html) + EM_SAFE_FREE(tmp_file_path); + if (fp_html) fclose (fp_html); - if (fp_write) + if (fp_write) fclose (fp_write); EM_SAFE_FREE(full_buf); EM_SAFE_FREE (replaced_string); @@ -466,7 +465,7 @@ static int emcore_write_rfc822_body(BODY *body, BODY *root_body, FILE *fp, int * fprintf(fp, "--%s--"CRLF_STRING, bndry); break; - default: + default: EM_DEBUG_LOG_DEV("body->type is not TYPEMULTIPART"); if ((error = emcore_write_body (body, root_body, fp)) != EMAIL_ERROR_NONE) { @@ -480,51 +479,68 @@ static int emcore_write_rfc822_body(BODY *body, BODY *root_body, FILE *fp, int * return true; } -static int emcore_write_rfc822 (ENVELOPE *env, BODY *body, email_mail_priority_t input_priority, +static int emcore_write_rfc822 (ENVELOPE *env, BODY *body, email_mail_priority_t input_priority, email_mail_report_t input_report_flag, char **data) { EM_DEBUG_FUNC_BEGIN("env[%p], body[%p], data[%p]", env, body, data); int error = EMAIL_ERROR_NONE; - FILE *fp = NULL; char *fname = NULL; - char *p = NULL; - size_t p_len = 0; + int file_exist = 0; + char *header_buffer = NULL; + size_t header_buffer_lenth = 0; + RFC822BUFFER buf; + int address_count = 0; + ADDRESS *index = NULL; if (!env || !data) { EM_DEBUG_EXCEPTION("Invalid Parameters"); error = EMAIL_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 ? EM_SAFE_STRLEN(env->subject) : 0) + 8192; + index = env->to; + while(index) { + address_count++; + index = index->next; + } + + index = env->cc; + while(index) { + address_count++; + index = index->next; + } + + header_buffer_lenth = (env->subject ? EM_SAFE_STRLEN(env->subject) : 0); + header_buffer_lenth += address_count * MAX_EMAIL_ADDRESS_LENGTH; + header_buffer_lenth += 8192; - if (!(p = em_malloc(p_len))) { /* (env->subject ? EM_SAFE_STRLEN(env->subject) : 0) + 8192))) */ + EM_DEBUG_LOG("header_buffer_lenth [%d]", header_buffer_lenth); + + if (!(header_buffer = em_malloc(header_buffer_lenth))) { EM_DEBUG_EXCEPTION(" malloc failed..."); error = EMAIL_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; + buf.beg = buf.cur = header_buffer; + buf.end = header_buffer + header_buffer_lenth - 1; + buf.f = buf_flush; + buf.s = NULL; /* 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 */ + EM_DEBUG_LOG("header_buffer [%d]", strlen(header_buffer)); + { - gchar **tokens = g_strsplit(p, "CHARSET=X-UNKNOWN", 2); + gchar **tokens = g_strsplit(header_buffer, "CHARSET=X-UNKNOWN", 2); if (g_strv_length(tokens) > 1) { gchar *charset; @@ -537,7 +553,7 @@ static int emcore_write_rfc822 (ENVELOPE *env, BODY *body, email_mail_priority_t charset[pHtml-charset] = '\0'; } - SNPRINTF(p, p_len, "%sCHARSET=%s%s", tokens[0], charset, tokens[1]); + SNPRINTF(header_buffer, header_buffer_lenth, "%sCHARSET=%s%s", tokens[0], charset, tokens[1]); g_free(charset); } else @@ -548,21 +564,21 @@ static int emcore_write_rfc822 (ENVELOPE *env, BODY *body, email_mail_priority_t } { - gchar **tokens = g_strsplit(p, "To: undisclosed recipients: ;\015\012", 2); + gchar **tokens = g_strsplit(header_buffer, "To: undisclosed recipients: ;\015\012", 2); if (g_strv_length(tokens) > 1) - SNPRINTF(p, p_len, "%s%s", tokens[0], tokens[1]); + SNPRINTF(header_buffer, header_buffer_lenth, "%s%s", tokens[0], tokens[1]); g_strfreev(tokens); } EM_DEBUG_LOG_DEV(" =============================================================================== " LF_STRING"%s"LF_STRING - " =============================================================================== ", p); + " =============================================================================== ", header_buffer); - if (EM_SAFE_STRLEN(p) > 2) - *(p + EM_SAFE_STRLEN(p) - 2) = '\0'; + if (EM_SAFE_STRLEN(header_buffer) > 2) + *(header_buffer + EM_SAFE_STRLEN(header_buffer) - 2) = '\0'; if (input_report_flag) { - char buf[512] = {0x00, }; + char string_buf[512] = {0x00, }; if(input_report_flag & EMAIL_MAIL_REPORT_DSN) { /* DSN (delivery status) */ @@ -581,42 +597,48 @@ static int emcore_write_rfc822 (ENVELOPE *env, BODY *body, email_mail_priority_t if(input_report_flag & EMAIL_MAIL_REQUEST_MDN) { /* require read status */ - rfc822_address(buf, env->from); - if (EM_SAFE_STRLEN(buf)) - SNPRINTF(p + EM_SAFE_STRLEN(p), p_len-(EM_SAFE_STRLEN(p)), "Disposition-Notification-To: %s"CRLF_STRING, buf); + rfc822_address(string_buf, env->from); + if (EM_SAFE_STRLEN(string_buf)) + SNPRINTF(header_buffer + EM_SAFE_STRLEN(header_buffer), header_buffer_lenth - EM_SAFE_STRLEN(header_buffer), "Disposition-Notification-To: %s"CRLF_STRING, string_buf); } } if (input_priority) { /* priority (1:high 3:normal 5:low) */ - SNPRINTF(p + EM_SAFE_STRLEN(p), p_len-(EM_SAFE_STRLEN(p)), "X-Priority: %d"CRLF_STRING, input_priority); + SNPRINTF(header_buffer + EM_SAFE_STRLEN(header_buffer), header_buffer_lenth-(EM_SAFE_STRLEN(header_buffer)), "X-Priority: %d"CRLF_STRING, input_priority); switch (input_priority) { case EMAIL_MAIL_PRIORITY_HIGH: - SNPRINTF(p + EM_SAFE_STRLEN(p), p_len-(EM_SAFE_STRLEN(p)), "X-MSMail-Priority: HIgh"CRLF_STRING); + SNPRINTF(header_buffer + EM_SAFE_STRLEN(header_buffer), header_buffer_lenth-(EM_SAFE_STRLEN(header_buffer)), "X-MSMail-Priority: High"CRLF_STRING); break; case EMAIL_MAIL_PRIORITY_NORMAL: - SNPRINTF(p + EM_SAFE_STRLEN(p), p_len-(EM_SAFE_STRLEN(p)), "X-MSMail-Priority: Normal"CRLF_STRING); + SNPRINTF(header_buffer + EM_SAFE_STRLEN(header_buffer), header_buffer_lenth-(EM_SAFE_STRLEN(header_buffer)), "X-MSMail-Priority: Normal"CRLF_STRING); break; case EMAIL_MAIL_PRIORITY_LOW: - SNPRINTF(p + EM_SAFE_STRLEN(p), p_len-(EM_SAFE_STRLEN(p)), "X-MSMail-Priority: Low"CRLF_STRING); + SNPRINTF(header_buffer + EM_SAFE_STRLEN(header_buffer), header_buffer_lenth-(EM_SAFE_STRLEN(header_buffer)), "X-MSMail-Priority: Low"CRLF_STRING); break; } } - SNPRINTF(p + EM_SAFE_STRLEN(p), p_len-(EM_SAFE_STRLEN(p)), CRLF_STRING); + SNPRINTF(header_buffer + EM_SAFE_STRLEN(header_buffer), header_buffer_lenth-(EM_SAFE_STRLEN(header_buffer)), CRLF_STRING); - if (!emcore_get_temp_file_name(&fname, &error)) { - EM_DEBUG_EXCEPTION(" emcore_get_temp_file_name failed[%d]", error); - goto FINISH_OFF; + if (data && EM_SAFE_STRLEN(*data) > 0) { + fname = EM_SAFE_STRDUP(*data); + file_exist = 1; + } + else { + if (!emcore_get_temp_file_name(&fname, &error)) { + EM_DEBUG_EXCEPTION(" emcore_get_temp_file_name failed[%d]", error); + goto FINISH_OFF; + } } - if (!(fp = fopen(fname, "w+"))) { - EM_DEBUG_EXCEPTION("fopen failed[%s]", fname); - error = EMAIL_ERROR_SYSTEM_FAILURE; + error = em_fopen(fname, "w+", &fp); + if (error != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("em_fopen failed[%s] [%d]", fname, error); goto FINISH_OFF; } - fprintf(fp, "%s", p); + fprintf(fp, "%s", header_buffer); if (body) { if (!emcore_write_rfc822_body(body, body, fp, &error)) { @@ -633,14 +655,16 @@ FINISH_OFF: emstorage_copy_file(fname, "/tmp/phone2pc.eml", false, NULL); #endif - if (error == EMAIL_ERROR_NONE) - *data = fname; + if (error == EMAIL_ERROR_NONE) { + if (!file_exist) + *data = EM_SAFE_STRDUP(fname); + } else if (fname != NULL) { remove(fname); - EM_SAFE_FREE(fname); } - EM_SAFE_FREE(p); + EM_SAFE_FREE(fname); + EM_SAFE_FREE(header_buffer); EM_DEBUG_FUNC_END(); return error; @@ -650,6 +674,26 @@ INTERNAL_FUNC int emcore_add_mail(email_mail_data_t *input_mail_data, email_atta { EM_DEBUG_FUNC_BEGIN("input_mail_data[%p], input_attachment_data_list [%p], input_attachment_count [%d], input_meeting_request [%p], input_from_eas[%d]", input_mail_data, input_attachment_data_list, input_attachment_count, input_meeting_request, input_from_eas); + /* IF an account is being deleted, there is no need to add the mail of the account */ + int shmid; + extern key_t del_account_key; /* in emcore_delete_account */ + int *del_account_id = NULL; + /* get the segment.*/ + + if ((shmid = shmget (del_account_key, sizeof (int), 0666)) != -1) { + /* attach the segment to current process space */ + if ((del_account_id = (int*) shmat (shmid, NULL, 0)) != (int*) -1) { + /* compare two account ids */ + EM_DEBUG_LOG ("del_id[%d] account_id[%d]",*del_account_id, input_mail_data->account_id); + if (*del_account_id == input_mail_data->account_id) { + EM_DEBUG_LOG ("SKIP adding mail: the account is being deleted"); + return EMAIL_ERROR_ACCOUNT_NOT_FOUND; + } + } + } + EM_DEBUG_LOG ("read del_id, account_id [%d]", (del_account_id? *del_account_id:-100),input_mail_data->account_id); + + int err = EMAIL_ERROR_NONE; int attachment_id = 0, thread_id = -1, thread_item_count = 0, latest_mail_id_in_thread = -1; int i = 0, rule_len, priority_sender = 0, blocked = 0, local_attachment_count = 0, local_inline_content_count = 0; @@ -672,6 +716,7 @@ INTERNAL_FUNC int emcore_add_mail(email_mail_data_t *input_mail_data, email_atta struct stat st_buf = { 0 }; char mailbox_id_param_string[10] = {0,}; char errno_buf[ERRNO_BUF_SIZE] = {0}; + int updated_thread_id = 0; #ifdef __FEATURE_BODY_SEARCH__ char *stripped_text = NULL; @@ -684,7 +729,7 @@ INTERNAL_FUNC int emcore_add_mail(email_mail_data_t *input_mail_data, email_atta goto FINISH_OFF; } - if (emcore_is_storage_full(&err) == true) { + if ((err = emcore_is_storage_full()) == EMAIL_ERROR_MAIL_MEMORY_FULL) { EM_DEBUG_EXCEPTION("Storage is full"); goto FINISH_OFF; } @@ -702,7 +747,7 @@ INTERNAL_FUNC int emcore_add_mail(email_mail_data_t *input_mail_data, email_atta err = EMAIL_ERROR_INVALID_PATH; goto FINISH_OFF; } - + dlerror(); convert_mail_data_to_smime = dlsym(dl_handle, "emcore_convert_mail_data_to_smime_data"); if ((dl_error = dlerror()) != NULL) { @@ -711,11 +756,11 @@ INTERNAL_FUNC int emcore_add_mail(email_mail_data_t *input_mail_data, email_atta goto FINISH_OFF; } - if (!convert_mail_data_to_smime(account_tbl_item, input_mail_data, input_attachment_data_list, input_attachment_count, &mail_data, &attachment_data_list, &attachment_count)) { - EM_DEBUG_EXCEPTION("S/MIME failed"); + if ((err = convert_mail_data_to_smime(account_tbl_item, input_mail_data, input_attachment_data_list, input_attachment_count, &mail_data, &attachment_data_list, &attachment_count)) != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("S/MIME failed : [%d]", err); goto FINISH_OFF; } - + mail_smime_flag = 1; } else { mail_data = input_mail_data; @@ -762,11 +807,11 @@ INTERNAL_FUNC int emcore_add_mail(email_mail_data_t *input_mail_data, email_atta input_mail_data->full_address_from = EM_SAFE_STRDUP(account_tbl_item->user_email_address); /* check for email_address validation */ - if ((err = em_verify_email_address_of_mail_data (mail_data, false)) != EMAIL_ERROR_NONE) { + if ((err = em_verify_email_address_of_mail_data (mail_data)) != EMAIL_ERROR_NONE) { EM_DEBUG_EXCEPTION("em_verify_email_address_of_mail_data failed [%d]", err); goto FINISH_OFF; } - + if (mail_data->report_status & EMAIL_MAIL_REPORT_MDN) { /* check read-report mail */ if(!mail_data->full_address_to) { /* A report mail should have 'to' address */ @@ -784,41 +829,42 @@ INTERNAL_FUNC int emcore_add_mail(email_mail_data_t *input_mail_data, email_atta } } else { /* For Spam handling */ - if (mail_data->mailbox_type != EMAIL_MAILBOX_TYPE_OUTBOX) { - email_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 = EMAIL_FILTER_SUBJECT; - else if (!opt->block_subject) - type = EMAIL_FILTER_FROM; - - if (!emstorage_get_rule(ALL_ACCOUNT, type, 0, &rule_len, &is_completed, &rule, true, &err) || !rule) - EM_DEBUG_LOG("No proper rules. emstorage_get_rule returns [%d]", err); - - if (rule && !emcore_check_rule(mail_data->full_address_from, mail_data->subject, rule, rule_len, &priority_sender, &blocked, &err)) { - EM_DEBUG_EXCEPTION("emcore_check_rule failed [%d]", err); - } - - if (priority_sender) - mail_data->tag_id = PRIORITY_SENDER_TAG_ID; - - if (blocked) { - EM_DEBUG_LOG("mail[%d] added to spambox", mail_data->mail_id); - if (!emstorage_get_mailbox_id_by_mailbox_type(mail_data->account_id, EMAIL_MAILBOX_TYPE_SPAMBOX, &mailbox_id_spam, false, &err)) { - EM_DEBUG_EXCEPTION("emstorage_get_mailbox_name_by_mailbox_type failed [%d]", err); - mailbox_id_spam = 0; - } + email_option_t *opt = &account_tbl_item->options; + EM_DEBUG_LOG_SEC("block_address [%d], block_subject [%d]", opt->block_address, opt->block_subject); - if (mailbox_id_spam) - mailbox_id_target = mailbox_id_spam; - } - } - } + /* For eas moving from spambox to other mailbox */ + if (mail_data->save_status != EMAIL_MAIL_STATUS_SAVED) { + if (opt->block_address || opt->block_subject) { + int is_completed = false; + int type = 0; + + if (!opt->block_address) + type = EMAIL_FILTER_SUBJECT; + else if (!opt->block_subject) + type = EMAIL_FILTER_FROM; + + if (!emstorage_get_rule(ALL_ACCOUNT, type, 0, &rule_len, &is_completed, &rule, true, &err) || !rule) + EM_DEBUG_LOG("No proper rules. emstorage_get_rule returns [%d]", err); + + if (rule && !emcore_check_rule(mail_data->full_address_from, mail_data->subject, rule, rule_len, &priority_sender, &blocked, &err)) { + EM_DEBUG_EXCEPTION("emcore_check_rule failed [%d]", err); + } + + if (priority_sender) + mail_data->tag_id = PRIORITY_SENDER_TAG_ID; + + if (blocked && (mail_data->mailbox_type == EMAIL_MAILBOX_TYPE_INBOX)) { + EM_DEBUG_LOG("mail[%d] added to spambox", mail_data->mail_id); + if (!emstorage_get_mailbox_id_by_mailbox_type(mail_data->account_id, EMAIL_MAILBOX_TYPE_SPAMBOX, &mailbox_id_spam, false, &err)) { + EM_DEBUG_EXCEPTION("emstorage_get_mailbox_name_by_mailbox_type failed [%d]", err); + mailbox_id_spam = 0; + } + + if (mailbox_id_spam) + mailbox_id_target = mailbox_id_spam; + } + } + } } if ((err = emstorage_get_mailbox_by_id(mailbox_id_target, (emstorage_mailbox_tbl_t**)&mailbox_tbl)) != EMAIL_ERROR_NONE) { @@ -861,16 +907,16 @@ INTERNAL_FUNC int emcore_add_mail(email_mail_data_t *input_mail_data, email_atta EM_SAFE_STRNCPY(body_text_file_name, "UTF-8", MAX_PATH); */ - if (!emstorage_get_save_name(mail_data->account_id, mail_data->mail_id, 0, body_text_file_name, name_buf, &err)) { + if (!emstorage_get_save_name(mail_data->account_id, mail_data->mail_id, 0, body_text_file_name, name_buf, sizeof(name_buf), &err)) { EM_DEBUG_EXCEPTION("emstorage_get_save_name failed [%d]", err); goto FINISH_OFF; } - if (!emstorage_copy_file(mail_data->file_path_plain, name_buf, input_from_eas, &err)) { - EM_DEBUG_EXCEPTION("emstorage_copy_file failed [%d]", err); + if (!emstorage_move_file(mail_data->file_path_plain, name_buf, input_from_eas, &err)) { + EM_DEBUG_EXCEPTION("emstorage_move_file failed [%d]", err); goto FINISH_OFF; } - if (mail_data->body_download_status == EMAIL_BODY_DOWNLOAD_STATUS_NONE) + if (!mail_data->body_download_status) mail_data->body_download_status = EMAIL_BODY_DOWNLOAD_STATUS_FULLY_DOWNLOADED; EM_SAFE_FREE(mail_data->file_path_plain); @@ -895,17 +941,17 @@ INTERNAL_FUNC int emcore_add_mail(email_mail_data_t *input_mail_data, email_atta EM_SAFE_STRNCPY(body_text_file_name, "UTF-8.htm", MAX_PATH); */ - if (!emstorage_get_save_name(mail_data->account_id, mail_data->mail_id, 0, body_text_file_name, name_buf, &err)) { + if (!emstorage_get_save_name(mail_data->account_id, mail_data->mail_id, 0, body_text_file_name, name_buf, sizeof(name_buf), &err)) { EM_DEBUG_EXCEPTION("emstorage_get_save_name failed [%d]", err); goto FINISH_OFF; } - if (!emstorage_copy_file(mail_data->file_path_html, name_buf, input_from_eas, &err)) { - EM_DEBUG_EXCEPTION("emstorage_copy_file failed [%d]", err); + if (!emstorage_move_file(mail_data->file_path_html, name_buf, input_from_eas, &err)) { + EM_DEBUG_EXCEPTION("emstorage_move_file failed [%d]", err); goto FINISH_OFF; } - if (mail_data->body_download_status == EMAIL_BODY_DOWNLOAD_STATUS_NONE) + if (!mail_data->body_download_status) mail_data->body_download_status = EMAIL_BODY_DOWNLOAD_STATUS_FULLY_DOWNLOADED; EM_SAFE_FREE(mail_data->file_path_html); @@ -916,13 +962,13 @@ INTERNAL_FUNC int emcore_add_mail(email_mail_data_t *input_mail_data, email_atta if (mail_data->file_path_mime_entity) { EM_DEBUG_LOG_SEC("mail_data->file_path_mime_entity [%s]", mail_data->file_path_mime_entity); - if (!emstorage_get_save_name(mail_data->account_id, mail_data->mail_id, 0, "mime_entity", name_buf, &err)) { + if (!emstorage_get_save_name(mail_data->account_id, mail_data->mail_id, 0, "mime_entity", name_buf, sizeof(name_buf), &err)) { EM_DEBUG_EXCEPTION("emstorage_get_save_name failed [%d]", err); goto FINISH_OFF; } - if (!emstorage_copy_file(mail_data->file_path_mime_entity, name_buf, input_from_eas, &err)) { - EM_DEBUG_EXCEPTION("emstorage_copy_file failed [%d]", err); + if (!emstorage_move_file(mail_data->file_path_mime_entity, name_buf, input_from_eas, &err)) { + EM_DEBUG_EXCEPTION("emstorage_move_file failed [%d]", err); goto FINISH_OFF; } @@ -937,7 +983,7 @@ INTERNAL_FUNC int emcore_add_mail(email_mail_data_t *input_mail_data, email_atta /* Generate message_id */ if (!input_from_eas) { - mail_data->message_id = strdup(emcore_generate_content_id_string("com.samsung.slp.email", NULL)); + mail_data->message_id = emcore_generate_content_id_string("org.tizen.email", NULL); mail_data->server_mail_id = strdup("0"); } @@ -1008,7 +1054,6 @@ INTERNAL_FUNC int emcore_add_mail(email_mail_data_t *input_mail_data, email_atta EM_DEBUG_EXCEPTION("emstorage_add_mail failed [%d]", err); /* ROLLBACK TRANSACTION; */ emstorage_rollback_transaction(NULL, NULL, NULL); - goto FINISH_OFF; } @@ -1016,12 +1061,14 @@ INTERNAL_FUNC int emcore_add_mail(email_mail_data_t *input_mail_data, email_atta EM_DEBUG_LOG("thread_item_count [%d]", thread_item_count); if (thread_item_count > 1) { - if (!emstorage_update_latest_thread_mail(mail_data->account_id, converted_mail_tbl->thread_id, 0, 0, false, &err)) { + if (!emstorage_update_latest_thread_mail(mail_data->account_id, mail_data->mailbox_id, converted_mail_tbl->thread_id, &updated_thread_id, 0, 0, NOTI_THREAD_ID_CHANGED_BY_ADD, false, &err)) { EM_DEBUG_EXCEPTION("emstorage_update_latest_thread_mail failed [%d]", err); emstorage_rollback_transaction(NULL, NULL, NULL); - goto FINISH_OFF; } + + if (updated_thread_id > 0) + input_mail_data->thread_id = updated_thread_id; } /* Insert attachment information to DB */ @@ -1047,17 +1094,25 @@ INTERNAL_FUNC int emcore_add_mail(email_mail_data_t *input_mail_data, email_atta goto FINISH_OFF; } - if (!emstorage_get_save_name(mail_data->account_id, mail_data->mail_id, attachment_data_list[i].inline_content_status ? 0 : attachment_id, attachment_data_list[i].attachment_name, name_buf, &err)) { + if (!emstorage_get_save_name(mail_data->account_id, mail_data->mail_id, attachment_data_list[i].inline_content_status ? 0 : attachment_id, attachment_data_list[i].attachment_name, name_buf, sizeof(name_buf), &err)) { EM_DEBUG_EXCEPTION("emstorage_get_save_name failed [%d]", err); emstorage_rollback_transaction(NULL, NULL, NULL); goto FINISH_OFF; } /* if (input_from_eas == 0 || attachment_data_list[i].save_status) { */ if (attachment_data_list[i].save_status) { - if (!emstorage_copy_file(attachment_data_list[i].attachment_path, name_buf, input_from_eas, &err)) { - EM_DEBUG_EXCEPTION("emstorage_copy_file failed [%d]", err); - emstorage_rollback_transaction(NULL, NULL, NULL); - goto FINISH_OFF; + if (attachment_data_list[i].attachment_mime_type && strcasestr(attachment_data_list[i].attachment_mime_type, "PKCS7")) { + if (!emstorage_move_file(attachment_data_list[i].attachment_path, name_buf, input_from_eas, &err)) { + EM_DEBUG_EXCEPTION("emstorage_move_file failed [%d]", err); + emstorage_rollback_transaction(NULL, NULL, NULL); + goto FINISH_OFF; + } + } else { + if (!emstorage_copy_file(attachment_data_list[i].attachment_path, name_buf, input_from_eas, &err)) { + EM_DEBUG_EXCEPTION("emstorage_copy_file failed [%d]", err); + emstorage_rollback_transaction(NULL, NULL, NULL); + goto FINISH_OFF; + } } } @@ -1072,6 +1127,7 @@ INTERNAL_FUNC int emcore_add_mail(email_mail_data_t *input_mail_data, email_atta attachment_tbl.attachment_drm_type = attachment_data_list[i].drm_status; attachment_tbl.attachment_inline_content_status = attachment_data_list[i].inline_content_status; attachment_tbl.attachment_mime_type = attachment_data_list[i].attachment_mime_type; + attachment_tbl.content_id = attachment_data_list[i].content_id; if (!emstorage_add_attachment(&attachment_tbl, 0, false, &err)) { EM_DEBUG_EXCEPTION("emstorage_add_attachment failed [%d]", err); @@ -1106,15 +1162,18 @@ INTERNAL_FUNC int emcore_add_mail(email_mail_data_t *input_mail_data, email_atta input_meeting_request->mail_id = mail_data->mail_id; if (!emstorage_add_meeting_request(mail_data->account_id, mailbox_tbl->mailbox_id, input_meeting_request, false, &err)) { EM_DEBUG_EXCEPTION("emstorage_add_meeting_request failed [%d]", err); - + emstorage_rollback_transaction(NULL, NULL, NULL); goto FINISH_OFF; } } emstorage_commit_transaction(NULL, NULL, NULL); + if (emstorage_get_thread_id_of_thread_mails(converted_mail_tbl, &thread_id, &latest_mail_id_in_thread, &thread_item_count) != EMAIL_ERROR_NONE) + EM_DEBUG_LOG(" emstorage_get_thread_id_of_thread_mails is failed."); + SNPRINTF(mailbox_id_param_string, 10, "%d", mailbox_tbl->mailbox_id); - if (!emcore_notify_storage_event(NOTI_MAIL_ADD, converted_mail_tbl->account_id, converted_mail_tbl->mail_id, mailbox_id_param_string, converted_mail_tbl->thread_id)) + if (!emcore_notify_storage_event(NOTI_MAIL_ADD, converted_mail_tbl->account_id, converted_mail_tbl->mail_id, mailbox_id_param_string, thread_id)) EM_DEBUG_LOG("emcore_notify_storage_event [NOTI_MAIL_ADD] failed."); if (account_tbl_item->incoming_server_type != EMAIL_SERVER_TYPE_ACTIVE_SYNC && !move_flag) { @@ -1131,8 +1190,6 @@ INTERNAL_FUNC int emcore_add_mail(email_mail_data_t *input_mail_data, email_atta // && mail_data->mailbox_type != EMAIL_MAILBOX_TYPE_SPAMBOX) { if ((err = emcore_update_sync_status_of_account(mail_data->account_id, SET_TYPE_SET, SYNC_STATUS_SYNCING | SYNC_STATUS_HAVE_NEW_MAILS)) != EMAIL_ERROR_NONE) EM_DEBUG_LOG("emcore_update_sync_status_of_account failed [%d]", err); -// emcore_add_notification_for_unread_mail(converted_mail_tbl); - emcore_display_unread_in_badge(); } FINISH_OFF: @@ -1289,6 +1346,9 @@ FINISH_OFF: if(receipt_mail_tbl_data) emstorage_free_mail(&receipt_mail_tbl_data, 1, NULL); + if (root_body) + mail_free_body(&root_body); + EM_DEBUG_FUNC_END("err [%d]", err); return err; } @@ -1334,6 +1394,7 @@ INTERNAL_FUNC int emcore_query_mail_size_limit(int account_id, int handle, int * int mail_size_limit = -1; email_account_t *ref_account = NULL; sslstart_t stls = NULL; + MAILSTREAM *mail_stream = NULL; if (account_id <= 0) { EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM"); @@ -1354,7 +1415,7 @@ INTERNAL_FUNC int emcore_query_mail_size_limit(int account_id, int handle, int * } if (ref_account->pop_before_smtp != FALSE) { - if (!emcore_connect_to_remote_mailbox(account_id, 0, (void **)&tmp_stream, &err)) { + if (!emcore_connect_to_remote_mailbox(account_id, 0, (void **)&mail_stream, &err)) { EM_DEBUG_EXCEPTION(" POP before SMTP Authentication failed [%d]", err); goto FINISH_OFF; } @@ -1388,6 +1449,9 @@ FINISH_OFF: smtp_close(stream); #endif /* __FEATURE_KEEP_CONNECTION__ */ + if (mail_stream) + mail_stream = mail_close (mail_stream); + if (stls) mail_parameters(NULL, SET_SSLSTART, (void *)stls); @@ -1406,31 +1470,137 @@ FINISH_OFF: return ret; } -/* send a mail */ +/* thread local variable for reuse */ +__thread GList* g_send_stream_list = NULL; +typedef struct { + int account_id; + SENDSTREAM **send_stream; +} email_send_stream_list_t; + +/* +stmp stream should be closed when threads exit, otherwise memory leaks +*/ +INTERNAL_FUNC void emcore_close_smtp_stream_list () +{ + EM_DEBUG_FUNC_BEGIN(); + GList* cur = g_send_stream_list; + email_send_stream_list_t* data = NULL; + + while (cur) { + data = cur->data; + if (data) *(data->send_stream) = smtp_close (*(data->send_stream)); + g_send_stream_list = g_list_delete_link (g_send_stream_list, cur); + g_free (data); + cur = g_send_stream_list; + } + + EM_DEBUG_FUNC_END(); +} + +/* +if threads exit after calling the function, emcore_close_smtp_stream_list should be called. +Otherwise, memory leaks +*/ +INTERNAL_FUNC SENDSTREAM** emcore_get_smtp_stream (int account_id, int *error) +{ + EM_DEBUG_FUNC_BEGIN("account_id[%d]", account_id); + GList* cur = g_send_stream_list; + email_send_stream_list_t* data = NULL; + SENDSTREAM** ret = NULL; + int err = EMAIL_ERROR_NONE; + + for ( ; cur ; cur = g_list_next(cur) ) { + data = cur->data; + if (data->account_id == account_id) { + if (data->send_stream == NULL || *(data->send_stream) == NULL) { + EM_DEBUG_LOG ("smtp_stream was closed before"); + g_send_stream_list = g_list_delete_link (g_send_stream_list, cur); + g_free (data); + break; + } + + int reply = smtp_send ( *(data->send_stream), "NOOP", NULL); + if (reply/100 == 2) { /* 2xx means a success */ + EM_DEBUG_LOG ("reusable smtp_stream found"); + return data->send_stream; + } + else { + EM_DEBUG_LOG ("smtp_stream is not reusable"); + *(data->send_stream) = smtp_close (*(data->send_stream)); + g_send_stream_list = g_list_delete_link (g_send_stream_list, cur); + g_free (data->send_stream); + break; + } + } + } + + ret = em_malloc (sizeof(SENDSTREAM*)); + if (!ret) { + EM_DEBUG_EXCEPTION("em_malloc error"); + goto FINISH_OFF; + } + + if (!emcore_connect_to_remote_mailbox(account_id, EMAIL_CONNECT_FOR_SENDING, (void **)ret, &err)) { + EM_DEBUG_EXCEPTION("emcore_connect_to_remote_mailbox failed [%d]", err); + + EM_SAFE_FREE(ret); + goto FINISH_OFF; + } + + email_send_stream_list_t *node = em_malloc (sizeof(email_send_stream_list_t)); + if (!node) { + EM_DEBUG_EXCEPTION ("em_malloc error"); + *ret = smtp_close (*ret); + EM_SAFE_FREE(ret); + goto FINISH_OFF; + } + + node->account_id = account_id; + node->send_stream = ret; + + g_send_stream_list = g_list_prepend (g_send_stream_list, node); + +FINISH_OFF: + + if (error) + *error = err; + + EM_DEBUG_FUNC_END(); + + return ret; +} + + +/* +send a mail +3 threads call this function : +worker_send_event_queue +mainloop (by alarm), +thread_func_EMAIL_ASYNC_TASK_SEND_MAIL_WITH_DOWNLOADING_ATTACHMENT_OF_ORIGINAL_MAIL, +*/ + INTERNAL_FUNC int emcore_send_mail(int mail_id, int *err_code) { EM_DEBUG_FUNC_BEGIN("mail_id[%d], err_code[%p]", mail_id, err_code); EM_PROFILE_BEGIN(profile_emcore_send_mail); int ret = false; int err = EMAIL_ERROR_NONE, err2 = EMAIL_ERROR_NONE; - int status = EMAIL_SEND_FAIL; int attachment_tbl_count = 0; int i = 0; int account_id = 0; - SENDSTREAM *stream = NULL; + SENDSTREAM** send_stream = NULL; ENVELOPE *envelope = NULL; sslstart_t stls = NULL; emstorage_mail_tbl_t *mail_tbl_data = NULL; emstorage_attachment_tbl_t *attachment_tbl_data = NULL; email_account_t *ref_account = NULL; email_option_t *opt = NULL; - void *tmp_stream = NULL; char *fpath = NULL; - int sent_box = 0; emstorage_mailbox_tbl_t* local_mailbox = NULL; int dst_mailbox_id = 0; int total_mail_size = 0; int sent_flag = 0; + MAILSTREAM *mail_stream = NULL; if (!mail_id) { EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM"); @@ -1469,7 +1639,7 @@ INTERNAL_FUNC int emcore_send_mail(int mail_id, int *err_code) goto FINISH_OFF; } else { - if ((err = em_verify_email_address_of_mail_tbl(mail_tbl_data, false)) != EMAIL_ERROR_NONE) { + if ((err = em_verify_email_address_of_mail_tbl(mail_tbl_data)) != EMAIL_ERROR_NONE) { err = EMAIL_ERROR_INVALID_ADDRESS; EM_DEBUG_EXCEPTION("em_verify_email_address_of_mail_tbl failed [%d]", err); goto FINISH_OFF; @@ -1519,9 +1689,8 @@ INTERNAL_FUNC int emcore_send_mail(int mail_id, int *err_code) } if (ref_account->pop_before_smtp != FALSE) { - if (!emcore_connect_to_remote_mailbox(account_id, 0, (void **)&tmp_stream, &err)) { + if (!emcore_connect_to_remote_mailbox(account_id, 0, (void **)&mail_stream, &err)) { EM_DEBUG_EXCEPTION(" POP before SMTP Authentication failed [%d]", err); - status = EMAIL_LIST_CONNECTION_FAIL; if (err == EMAIL_ERROR_CONNECTION_BROKEN) err = EMAIL_ERROR_CANCELLED; goto FINISH_OFF; @@ -1535,16 +1704,25 @@ INTERNAL_FUNC int emcore_send_mail(int mail_id, int *err_code) emstorage_free_mailbox(&local_mailbox, 1, NULL); + send_stream = emcore_get_smtp_stream (account_id, &err); + if (!send_stream) { + EM_DEBUG_EXCEPTION(" emcore_get_smtp_stream failed [%d]", err); + if (err == EMAIL_ERROR_CONNECTION_BROKEN) + err = EMAIL_ERROR_CANCELLED; + goto FINISH_OFF; + } + +#if 0 if (!emcore_connect_to_remote_mailbox(account_id, EMAIL_CONNECT_FOR_SENDING, (void **)&tmp_stream, &err)) { EM_DEBUG_EXCEPTION(" emcore_connect_to_remote_mailbox failed [%d]", err); if (err == EMAIL_ERROR_CONNECTION_BROKEN) err = EMAIL_ERROR_CANCELLED; - status = EMAIL_SEND_CONNECTION_FAIL; goto FINISH_OFF; } stream = (SENDSTREAM *)tmp_stream; +#endif if (!emcore_check_send_mail_thread_status()) { EM_DEBUG_EXCEPTION(" emcore_check_send_mail_thread_status failed..."); @@ -1552,12 +1730,12 @@ INTERNAL_FUNC int emcore_send_mail(int mail_id, int *err_code) goto FINISH_OFF; } - if (stream && stream->protocol.esmtp.ok) { - if (stream->protocol.esmtp.size.ok && stream->protocol.esmtp.size.limit > 0) { - EM_DEBUG_LOG("Server size limit : %ld", stream->protocol.esmtp.size.limit); + if (*send_stream && (*send_stream)->protocol.esmtp.ok) { + if ((*send_stream)->protocol.esmtp.size.ok && (*send_stream)->protocol.esmtp.size.limit > 0) { + EM_DEBUG_LOG("Server size limit : %ld", (*send_stream)->protocol.esmtp.size.limit); emcore_get_file_size(fpath, &total_mail_size, NULL); EM_DEBUG_LOG("mail size : %d", total_mail_size); - if (total_mail_size > stream->protocol.esmtp.size.limit) { + if (total_mail_size > (*send_stream)->protocol.esmtp.size.limit) { err = EMAIL_ERROR_SMTP_SEND_FAILURE_BY_OVERSIZE; goto FINISH_OFF; } @@ -1570,10 +1748,10 @@ INTERNAL_FUNC int emcore_send_mail(int mail_id, int *err_code) if (opt->req_delivery_receipt == EMAIL_OPTION_REQ_DELIVERY_RECEIPT_ON || (mail_tbl_data->report_status & EMAIL_MAIL_REQUEST_DSN)) { EM_DEBUG_LOG("DSN is required."); - 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; + (*send_stream)->protocol.esmtp.dsn.want = 1; + (*send_stream)->protocol.esmtp.dsn.full = 0; + (*send_stream)->protocol.esmtp.dsn.notify.failure = 1; + (*send_stream)->protocol.esmtp.dsn.notify.success = 1; } mail_tbl_data->save_status = EMAIL_MAIL_STATUS_SENDING; @@ -1584,7 +1762,7 @@ INTERNAL_FUNC int emcore_send_mail(int mail_id, int *err_code) EM_DEBUG_EXCEPTION("emstorage_set_field_of_mails_with_integer_value failed [%d]", err); /* send mail to server. */ - if (!emcore_send_mail_smtp(stream, envelope, fpath, account_id, mail_id, &err)) { + if (!emcore_send_mail_smtp(*send_stream, envelope, fpath, account_id, mail_id, &err)) { EM_DEBUG_EXCEPTION(" emcore_send_mail_smtp failed [%d]", err); if (err == SMTP_RESPONSE_EXCEED_SIZE_LIMIT) err = EMAIL_ERROR_SMTP_SEND_FAILURE_BY_OVERSIZE; @@ -1606,6 +1784,9 @@ INTERNAL_FUNC int emcore_send_mail(int mail_id, int *err_code) goto FINISH_OFF; } + emcore_show_user_message(mail_id, EMAIL_ACTION_SEND_MAIL, err); + sent_flag = 1; + /* sent mail is moved to 'SENT' box or deleted. */ if (opt->keep_local_copy) { if (!emstorage_get_mailbox_by_mailbox_type(account_id, EMAIL_MAILBOX_TYPE_SENTBOX, &local_mailbox, true, &err)) { @@ -1671,9 +1852,12 @@ INTERNAL_FUNC int emcore_send_mail(int mail_id, int *err_code) EM_DEBUG_LOG("local_yn:[%d]", src_mailbox->local_yn); if (src_mailbox->local_yn) { - if (!emcore_sync_header(local_mailbox, NULL, NULL, NULL, NULL, &err)) { + + void *local_stream = NULL; + if (!emcore_sync_header (local_mailbox, &local_stream, NULL, NULL, NULL, NULL, NULL, 0, -1, &err)) { EM_DEBUG_EXCEPTION("emcore_sync_header failed"); } + mail_close (local_stream); if (!emstorage_get_maildata_by_servermailid(local_mailbox->mailbox_id, "0", &temp_mail, false, &err)) { if (err != EMAIL_ERROR_MAIL_NOT_FOUND) { @@ -1684,7 +1868,7 @@ INTERNAL_FUNC int emcore_send_mail(int mail_id, int *err_code) if (temp_mail) { emcore_sync_mail_from_client_to_server(mail_id); - emstorage_free_mail(&temp_mail, 1, NULL); + emstorage_free_mail(&temp_mail, 1, NULL); } } else { @@ -1701,8 +1885,6 @@ INTERNAL_FUNC int emcore_send_mail(int mail_id, int *err_code) if (!emstorage_set_field_of_mails_with_integer_value(account_id, &mail_id, 1, "flags_draft_field", mail_tbl_data->flags_draft_field, true, &err)) EM_DEBUG_EXCEPTION("Failed to modify extra flag [%d]", err); - - sent_box = 1; } else { if (!emcore_delete_mail(account_id, &mail_id, 1, EMAIL_DELETE_LOCALLY, EMAIL_DELETED_AFTER_SENDING, false, &err)) @@ -1751,10 +1933,16 @@ FINISH_OFF: EM_SAFE_FREE(ref_account); } +#if 0 #ifndef __FEATURE_KEEP_CONNECTION__ if (stream) smtp_close(stream); #endif /* __FEATURE_KEEP_CONNECTION__ */ +#endif + + if (mail_stream) + mail_stream = mail_close (mail_stream); + if (stls) mail_parameters(NULL, SET_SSLSTART, (void *)stls); @@ -1765,7 +1953,7 @@ FINISH_OFF: mail_free_envelope(&envelope); if (fpath) { - EM_DEBUG_LOG("REMOVE TEMP FILE : %s", fpath); + EM_DEBUG_LOG_SEC("REMOVE TEMP FILE : %s", fpath); remove(fpath); EM_SAFE_FREE (fpath); } @@ -1847,12 +2035,18 @@ INTERNAL_FUNC int emcore_send_saved_mail(int account_id, char *input_mailbox_nam goto FINISH_OFF; } - FINISH_OFF_IF_CANCELED; +/*don't delete the comment. several threads including event thread call this func */ +/* FINISH_OFF_IF_CANCELED; */ opt = &(ref_account->options); + if (!emstorage_get_mailbox_by_name(account_id, -1, input_mailbox_name, &local_mailbox, false, &err)) { + EM_DEBUG_EXCEPTION("emstorage_get_mailbox_by_name failed : [%d]", err); + goto FINISH_OFF; + } + /* search mail. */ - if (!emstorage_mail_search_start(NULL, account_id, input_mailbox_name, 0, &handle, &total, true, &err)) { + if (!emstorage_mail_search_start(NULL, account_id, local_mailbox->mailbox_id, 0, &handle, &total, true, &err)) { EM_DEBUG_EXCEPTION("emstorage_mail_search_start failed [%d]", err); goto FINISH_OFF; } @@ -1880,8 +2074,12 @@ INTERNAL_FUNC int emcore_send_saved_mail(int account_id, char *input_mailbox_nam mail_send_notify(EMAIL_SEND_PREPARE, 0, 0, account_id, mail_ids[total], err); + if(local_mailbox) + emstorage_free_mailbox(&local_mailbox, 1, NULL); + for (i = 0; i < total; i++) { - FINISH_OFF_IF_CANCELED; +/*don't delete the comment. several threads including event thread call this func */ +/* FINISH_OFF_IF_CANCELED;*/ if (!emstorage_get_mail_by_id(mail_ids[i], &searched_mail_tbl_data, false, &err)) { EM_DEBUG_EXCEPTION("emstorage_get_mail_by_id failed [%d]", err); @@ -1902,7 +2100,7 @@ INTERNAL_FUNC int emcore_send_saved_mail(int account_id, char *input_mailbox_nam } /* check for email_address validation */ - if ( (err = em_verify_email_address_of_mail_tbl(searched_mail_tbl_data, false)) != EMAIL_ERROR_NONE ) { + if ( (err = em_verify_email_address_of_mail_tbl(searched_mail_tbl_data)) != EMAIL_ERROR_NONE ) { err = EMAIL_ERROR_INVALID_ADDRESS; EM_DEBUG_EXCEPTION("em_verify_email_address_of_mail_tbl failed [%d]", err); goto FINISH_OFF; @@ -1915,7 +2113,8 @@ INTERNAL_FUNC int emcore_send_saved_mail(int account_id, char *input_mailbox_nam goto FINISH_OFF; } - FINISH_OFF_IF_CANCELED; +/*don't delete the comment. several threads including event thread call this func */ +/* FINISH_OFF_IF_CANCELED;*/ /* connect mail server. */ if (!stream) { @@ -1938,7 +2137,8 @@ INTERNAL_FUNC int emcore_send_saved_mail(int account_id, char *input_mailbox_nam stream = (SENDSTREAM *)tmp_stream; - FINISH_OFF_IF_CANCELED; +/*don't delete the comment. several threads including event thread call this func */ +/* FINISH_OFF_IF_CANCELED;*/ mail_send_notify(EMAIL_SEND_CONNECTION_SUCCEED, 0, 0, account_id, mail_ids[i], err); @@ -2184,7 +2384,7 @@ static int emcore_send_mail_smtp(SENDSTREAM *stream, ENVELOPE *env, char *data_f 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); + EM_DEBUG_LOG_SEC("[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; @@ -2196,7 +2396,7 @@ static int emcore_send_mail_smtp(SENDSTREAM *stream, ENVELOPE *env, char *data_f 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); + EM_DEBUG_LOG_SEC("[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; @@ -2208,7 +2408,7 @@ static int emcore_send_mail_smtp(SENDSTREAM *stream, ENVELOPE *env, char *data_f 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); + EM_DEBUG_LOG_SEC("[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; @@ -2242,7 +2442,7 @@ static int emcore_send_mail_smtp(SENDSTREAM *stream, ENVELOPE *env, char *data_f } send_ret = smtp_send(stream, "DATA", 0); - EM_DEBUG_LOG("[SMTP] DATA --------> %s", stream->reply); + EM_DEBUG_LOG_SEC("[SMTP] DATA --------> %s", stream->reply); EM_PROFILE_END(profile_prepare_and_head); if (send_ret != SMTP_RESPONSE_READY) { @@ -2252,9 +2452,10 @@ static int emcore_send_mail_smtp(SENDSTREAM *stream, ENVELOPE *env, char *data_f if (data_file) { EM_PROFILE_BEGIN(profile_open_file); - if (!(fp = fopen(data_file, "r+"))) { - EM_DEBUG_EXCEPTION("fopen(\"%s\") failed...", data_file); - err = EMAIL_ERROR_SYSTEM_FAILURE; + + err = em_fopen(data_file, "r+", &fp); + if (err != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("em_fopen(\"%s\") failed..., error:[%d]", data_file, err); goto FINISH_OFF; } EM_PROFILE_END(profile_open_file); @@ -2288,6 +2489,14 @@ static int emcore_send_mail_smtp(SENDSTREAM *stream, ENVELOPE *env, char *data_f } while (total) { +#if 0 + /* Cancel the sending event */ + if (!emcore_check_send_mail_thread_status()) { + EM_DEBUG_EXCEPTION(" emcore_check_send_mail_thread_status failed..."); + err = EMAIL_ERROR_CANCELLED; + goto FINISH_OFF; + } +#endif if (total < allocSize) dataSize = total; else @@ -2437,7 +2646,7 @@ char *emcore_generate_content_id_string(const char *hostname, int *err) /* 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, +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_SEC("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); @@ -2447,6 +2656,7 @@ static int attach_part (BODY *body, const unsigned char *data, int data_len, int has_special_character = 0; int base64_file_name_length = 0; int i= 0; + int mail_type = EMAIL_SMIME_NONE; gsize bytes_read; gsize bytes_written; char *encoded_file_name = NULL; @@ -2555,16 +2765,36 @@ static int attach_part (BODY *body, const unsigned char *data, int data_len, part->body.type = em_get_content_type_from_extension_string(extension, NULL); if(part->body.type == TYPEIMAGE) { part->body.subtype = strdup(extension); + part->body.encoding = ENCBINARY; } else if (part->body.type == TYPEPKCS7_SIGN) { part->body.subtype = strdup("pkcs7-signature"); part->body.type = TYPEAPPLICATION; + part->body.encoding = ENCBINARY; } else if (part->body.type == TYPEPKCS7_MIME) { part->body.subtype = strdup("pkcs7-mime"); part->body.type = TYPEAPPLICATION; - } else + part->body.encoding = ENCBINARY; + } else if (part->body.type == TYPEPGP) { + part->body.type = TYPEAPPLICATION; + part->body.subtype = EM_SAFE_STRDUP(content_sub_type); + part->body.encoding = ENC7BIT; + } else { part->body.subtype = strdup("octet-stream"); + part->body.encoding = ENCBINARY; + } + + if (!extension && content_sub_type) { + char *p = NULL; + + if (strcasecmp(content_sub_type, "IMAGE") == 0) { + part->body.type = TYPEIMAGE; + if ((p = strstr(content_sub_type, "/"))) { + EM_SAFE_FREE(part->body.subtype); + part->body.subtype = EM_SAFE_STRDUP(p+1); + } + } + } - part->body.encoding = ENCBINARY; part->body.size.bytes = data_len; if (data) @@ -2593,7 +2823,7 @@ static int attach_part (BODY *body, const unsigned char *data, int data_len, if (is_inline) { /* CONTENT-ID */ - part->body.id = emcore_generate_content_id_string("com.samsung.slp.email", &error); + part->body.id = emcore_generate_content_id_string("org.tizen.email", &error); part->body.type = TYPEIMAGE; /* EM_SAFE_FREE(part->body.subtype); */ /* part->body.subtype = EM_SAFE_STRDUP(content_sub_type); */ @@ -2617,108 +2847,125 @@ static int attach_part (BODY *body, const unsigned char *data, int data_len, last_part->body.disposition.type = 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 && !strcasecmp(content_sub_type, "pgp-encrypted")) + mail_type = EMAIL_PGP_ENCRYPTED; + if (mail_type != EMAIL_PGP_ENCRYPTED) { + /* text body (plain/html) */ + part->body.type = TYPETEXT; + part->body.size.bytes = data_len; - if (!content_sub_type) { - /* Plain text body */ - part->body.encoding = ENC8BIT; - part->body.subtype = cpystr("plain"); - last_param = part->body.parameter; + if (data) + part->body.sparep = EM_SAFE_STRDUP((char *)data); /* file path */ + else + part->body.sparep = NULL; - if (last_param != NULL) { - while (last_param->next) - last_param = last_param->next; - } - param = mail_newbody_parameter(); + if (!content_sub_type) { + /* Plain text body */ + part->body.encoding = ENC8BIT; + part->body.subtype = cpystr("plain"); + last_param = part->body.parameter; - if (param == NULL) { - EM_DEBUG_EXCEPTION("mail_newbody_parameter failed..."); - error = EMAIL_ERROR_OUT_OF_MEMORY; - goto FINISH_OFF; - } + if (last_param != NULL) { + while (last_param->next) + last_param = last_param->next; + } - param->attribute = cpystr("CHARSET"); + param = mail_newbody_parameter(); - 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 == NULL) { + EM_DEBUG_EXCEPTION("mail_newbody_parameter failed..."); + error = EMAIL_ERROR_OUT_OF_MEMORY; + goto FINISH_OFF; + } - if(!param->value) - param->value = cpystr("UTF-8"); + param->attribute = cpystr("CHARSET"); - param->next = NULL; + 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 (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); + if(!param->value) + param->value = cpystr("UTF-8"); - last_param = part->body.parameter; + param->next = NULL; - if (last_param != NULL) { - while (last_param->next) - last_param = last_param->next; + 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); - param = mail_newbody_parameter(); + last_param = part->body.parameter; - if (param == NULL) { - EM_DEBUG_EXCEPTION("mail_newbody_parameter failed..."); - error = EMAIL_ERROR_OUT_OF_MEMORY; - goto FINISH_OFF; - } + if (last_param != NULL) { + while (last_param->next) + last_param = last_param->next; + } - param->attribute = cpystr("CHARSET"); + param = mail_newbody_parameter(); - 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 == NULL) { + EM_DEBUG_EXCEPTION("mail_newbody_parameter failed..."); + error = EMAIL_ERROR_OUT_OF_MEMORY; + goto FINISH_OFF; } - if(!param->value) + 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; - EM_SAFE_FREE(extract_charset); + if (last_param != NULL) + last_param->next = param; + else + part->body.parameter = param; } - 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); + } + } else { + part->body.type = TYPEAPPLICATION; + part->body.subtype = strdup(content_sub_type); + part->body.size.bytes = data_len; + part->body.encoding = ENC7BIT; - /* 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); + if (data) + part->body.sparep = EM_SAFE_STRDUP((char *)data); /* file path */ + else { + part->body.contents.text.data = (unsigned char *)strdup("Version: 1"); + part->body.contents.text.size = strlen("Version: 1"); + } } } @@ -2875,8 +3122,13 @@ static char *emcore_encode_rfc2047_text(char *utf8_text, int *err_code) EM_DEBUG_FUNC_END(); - if (len > 0) - return g_strdup_printf("=?UTF-8?B?%s?=", g_base64_encode((const guchar *)utf8_text, len)); + + if (len > 0) { +#ifdef __FEATURE_USE_GMIME__ + return emcore_gmime_get_encoding_to_utf8(utf8_text); +// return g_strdup(utf8_text); /* emoji handle */ +#endif /* __FEATURE_USE_GMIME__ */ + } else return strdup(""); } @@ -2990,12 +3242,13 @@ static int emcore_make_envelope_from_mail(emstorage_mail_tbl_t *input_mail_tbl_d } } else { +/* if (input_mail_tbl_data->full_address_from == NULL) { EM_DEBUG_EXCEPTION("input_mail_tbl_data->full_address_from[%p]", input_mail_tbl_data->full_address_from); error = EMAIL_ERROR_INVALID_MAIL; goto FINISH_OFF; } - +*/ int i, j; if (input_mail_tbl_data->full_address_from) { @@ -3092,7 +3345,27 @@ static int emcore_make_envelope_from_mail(emstorage_mail_tbl_t *input_mail_tbl_d if (!is_incomplete) { char localtime_string[DATE_STR_LENGTH] = { 0, }; - strftime(localtime_string, 128, "%a, %e %b %Y %H:%M:%S ", localtime(&input_mail_tbl_data->date_time)); + time_t tn = time(0); + struct tm *t = gmtime(&tn); + int zone = t->tm_hour * 60 + t->tm_min; + int julian = t->tm_yday; + + t = localtime(&input_mail_tbl_data->date_time); + zone = t->tm_hour * 60 + t->tm_min - zone; + + if ((julian = t->tm_yday - julian)) + zone += ((julian < 0) == (abs(julian) == 1)) ? -24 * 60 : 24*60; + + SNPRINTF(localtime_string, DATE_STR_LENGTH, "%s, %d %s %d %02d:%02d:%02d " + , days[t->tm_wday] + , t->tm_mday + , months[t->tm_mon] + , t->tm_year + 1900 + , t->tm_hour + , t->tm_min + , t->tm_sec + ); + EM_DEBUG_LOG("localtime string : [%s]", localtime_string); /* append last 5byes("+0900") */ g_strlcat(localtime_string, strchr(rfc822_date_string, '+'), DATE_STR_LENGTH); @@ -3121,6 +3394,70 @@ FINISH_OFF: EM_DEBUG_FUNC_END("error [%d]", error); return error; } + +static char *emcore_get_digest_string(int digest_type, int mime_type) +{ + EM_DEBUG_FUNC_BEGIN(); + char *digest_string = NULL; + char p_digest_string[100] = {0, }; + + switch (mime_type) { + case EMAIL_SMIME_SIGNED : + case EMAIL_SMIME_ENCRYPTED : + case EMAIL_SMIME_SIGNED_AND_ENCRYPTED : + memset(p_digest_string, 0x00, sizeof(p_digest_string)); + break; + case EMAIL_PGP_SIGNED : + case EMAIL_PGP_ENCRYPTED : + case EMAIL_PGP_SIGNED_AND_ENCRYPTED : + memset(p_digest_string, 0x00, sizeof(p_digest_string)); + strcpy(p_digest_string, "pgp-"); + break; + } + + switch (digest_type) { + case DIGEST_TYPE_SHA1 : + strcat(p_digest_string, "sha1"); + break; + case DIGEST_TYPE_MD5 : + strcat(p_digest_string, "md5"); + break; + case DIGEST_TYPE_RIPEMD160 : + strcat(p_digest_string, "ripemd160"); + break; + case DIGEST_TYPE_MD2 : + strcat(p_digest_string, "md2"); + break; + case DIGEST_TYPE_TIGER192 : + strcat(p_digest_string, "tiger192"); + break; + case DIGEST_TYPE_HAVAL5160 : + strcat(p_digest_string, "haval5160"); + break; + case DIGEST_TYPE_SHA256 : + strcat(p_digest_string, "sha256"); + break; + case DIGEST_TYPE_SHA384 : + strcat(p_digest_string, "sha384"); + break; + case DIGEST_TYPE_SHA512 : + strcat(p_digest_string, "sha512"); + break; + case DIGEST_TYPE_SHA224 : + strcat(p_digest_string, "sha224"); + break; + case DIGEST_TYPE_MD4 : + strcat(p_digest_string, "md4"); + break; + } + + digest_string = EM_SAFE_STRDUP(p_digest_string); + + EM_DEBUG_FUNC_END(); + return digest_string; +} + + /* Description : Make RFC822 text file from mail_tbl data */ /* Parameters : */ /* input_mail_tbl_data : */ @@ -3133,6 +3470,8 @@ INTERNAL_FUNC int emcore_make_rfc822_file_from_mail(emstorage_mail_tbl_t *input_ int ret = false; int error = EMAIL_ERROR_NONE; int i = 0; + char *digest_string = NULL; + ENVELOPE *envelope = NULL; BODY *root_body = NULL; BODY *text_body = NULL; @@ -3140,7 +3479,6 @@ INTERNAL_FUNC int emcore_make_rfc822_file_from_mail(emstorage_mail_tbl_t *input_ PART *part_for_alternative = NULL; PART *part_for_related = NULL; PARAMETER *param = NULL; - char *fname = NULL; if (!input_mail_tbl_data) { EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM"); @@ -3195,51 +3533,50 @@ INTERNAL_FUNC int emcore_make_rfc822_file_from_mail(emstorage_mail_tbl_t *input_ mail_free_body_parameter(¶m); param = NULL; - } else if (input_mail_tbl_data->smime_type == EMAIL_SMIME_SIGNED) { - PARAMETER *protocol_param = mail_newbody_parameter(); + PARAMETER *protocol_param = mail_newbody_parameter(); - root_body->type = TYPEMULTIPART; - root_body->subtype = strdup("SIGNED"); + root_body->type = TYPEMULTIPART; + root_body->subtype = strdup("SIGNED"); - param->attribute = cpystr("micalg"); - switch (input_mail_tbl_data->digest_type) { - case DIGEST_TYPE_SHA1: - param->value = cpystr("sha1"); - break; - case DIGEST_TYPE_MD5: - param->value = cpystr("md5"); - break; - default: - EM_DEBUG_EXCEPTION("Invalid digest type"); - break; - } + param->attribute = cpystr("micalg"); + + digest_string = emcore_get_digest_string(input_mail_tbl_data->digest_type, input_mail_tbl_data->smime_type); + param->value = cpystr(digest_string); protocol_param->attribute = cpystr("protocol"); protocol_param->value = cpystr("application/pkcs7-signature"); protocol_param->next = NULL; param->next = protocol_param; - - input_mail_tbl_data->file_path_plain = NULL; - input_mail_tbl_data->file_path_html = NULL; - - input_attachment_tbl = input_attachment_tbl + (input_attachment_count - 1); - - input_attachment_count = 1; - - } else { + } else if (input_mail_tbl_data->smime_type == EMAIL_SMIME_SIGNED || input_mail_tbl_data->smime_type == EMAIL_SMIME_SIGNED_AND_ENCRYPTED) { root_body->type = TYPEAPPLICATION; root_body->subtype = strdup("PKCS7-MIME"); param->attribute = cpystr("name"); param->value = cpystr("smime.p7m"); param->next = NULL; + } else if (input_mail_tbl_data->smime_type == EMAIL_PGP_SIGNED) { + PARAMETER *protocol_param = mail_newbody_parameter(); - input_mail_tbl_data->file_path_plain = NULL; - input_mail_tbl_data->file_path_html = NULL; - input_mail_tbl_data->file_path_mime_entity = NULL; + root_body->type = TYPEMULTIPART; + root_body->subtype = strdup("SIGNED"); - input_attachment_count = 1; + param->attribute = cpystr("micalg"); + + digest_string = emcore_get_digest_string(input_mail_tbl_data->digest_type, input_mail_tbl_data->smime_type); + param->value = cpystr(digest_string); + + protocol_param->attribute = cpystr("protocol"); + protocol_param->value = cpystr("application/pgp-signature"); + protocol_param->next = NULL; + param->next = protocol_param; + } else { + root_body->type = TYPEMULTIPART; + root_body->subtype = strdup("encrypted"); + + param->attribute = cpystr("protocol"); + param->value = cpystr("application/pgp-encrypted"); + param->next = NULL; } root_body->contents.text.data = NULL; @@ -3260,9 +3597,9 @@ INTERNAL_FUNC int emcore_make_rfc822_file_from_mail(emstorage_mail_tbl_t *input_ } } - if (part_for_related) + if (part_for_related) part_for_alternative = attach_multipart_with_sub_type(&(part_for_related->body), "ALTERNATIVE", &error); - else + else part_for_alternative = attach_multipart_with_sub_type(root_body, "ALTERNATIVE", &error); if (!part_for_alternative) { EM_DEBUG_EXCEPTION("attach_multipart_with_sub_type [alternative] failed [%d]", error); @@ -3288,12 +3625,12 @@ INTERNAL_FUNC int emcore_make_rfc822_file_from_mail(emstorage_mail_tbl_t *input_ goto FINISH_OFF; } } - } - else if (input_mail_tbl_data->smime_type == EMAIL_SMIME_NONE && + } + else if (input_mail_tbl_data->smime_type == EMAIL_SMIME_NONE && (input_mail_tbl_data->file_path_plain || input_mail_tbl_data->file_path_html)) { if (input_mail_tbl_data->file_path_plain && EM_SAFE_STRLEN(input_mail_tbl_data->file_path_plain) > 0) { EM_DEBUG_LOG_SEC("file_path_plain[%s]", input_mail_tbl_data->file_path_plain); - if (!attach_part (root_body, (unsigned char *) input_mail_tbl_data->file_path_plain, 0, + if (!attach_part (root_body, (unsigned char *) input_mail_tbl_data->file_path_plain, 0, NULL, "plain", false, &error)) { EM_DEBUG_EXCEPTION("attach_part failed [%d]", error); goto FINISH_OFF; @@ -3302,53 +3639,82 @@ INTERNAL_FUNC int emcore_make_rfc822_file_from_mail(emstorage_mail_tbl_t *input_ if (input_mail_tbl_data->file_path_html && EM_SAFE_STRLEN(input_mail_tbl_data->file_path_html) > 0) { EM_DEBUG_LOG_SEC("file_path_html[%s]", input_mail_tbl_data->file_path_html); - if (!attach_part (root_body, (unsigned char *)input_mail_tbl_data->file_path_html, 0, - NULL, "html", false, &error)) { + if (input_mail_tbl_data->inline_content_count > 0 && (strcasecmp(root_body->subtype, "RELATED") != 0)) { + part_for_related = attach_multipart_with_sub_type(root_body, "RELATED", &error); + if (!part_for_related) { + EM_DEBUG_EXCEPTION("attach_multipart_with_sub_type [related] failed [%d]", error); + goto FINISH_OFF; + } + } + + if (part_for_related) { + if (!attach_part(&(part_for_related->body), (unsigned char *)input_mail_tbl_data->file_path_html, 0, + NULL, "html", false, &error)) { + EM_DEBUG_EXCEPTION("attach_part failed [%d]", error); + goto FINISH_OFF; + } + } else { + if (!attach_part (root_body, (unsigned char *)input_mail_tbl_data->file_path_html, 0, + NULL, "html", false, &error)) { + EM_DEBUG_EXCEPTION("attach_part failed [%d]", error); + goto FINISH_OFF; + } + } + } + } else if (input_mail_tbl_data->smime_type == EMAIL_SMIME_SIGNED || input_mail_tbl_data->smime_type == EMAIL_PGP_SIGNED) { + if (input_mail_tbl_data->file_path_mime_entity && EM_SAFE_STRLEN(input_mail_tbl_data->file_path_mime_entity) > 0) { + EM_DEBUG_LOG_SEC("file_path_mime_entity[%s]", input_mail_tbl_data->file_path_mime_entity); + root_body->sparep = EM_SAFE_STRDUP(input_mail_tbl_data->file_path_mime_entity); + } + } else if (input_mail_tbl_data->smime_type == EMAIL_PGP_ENCRYPTED || input_mail_tbl_data->smime_type == EMAIL_PGP_SIGNED_AND_ENCRYPTED) { + if (input_mail_tbl_data->file_path_plain && EM_SAFE_STRLEN(input_mail_tbl_data->file_path_plain) > 0) { + EM_DEBUG_LOG_SEC("file_path_plain[%s]", input_mail_tbl_data->file_path_plain); + if (!attach_part (root_body, NULL, 0, NULL, "pgp-encrypted", false, &error)) { EM_DEBUG_EXCEPTION("attach_part failed [%d]", error); goto FINISH_OFF; } } - } - else { - EM_DEBUG_LOG("S/MIME type : [%d]", input_mail_tbl_data->smime_type); - } - - if (input_mail_tbl_data->file_path_mime_entity && EM_SAFE_STRLEN(input_mail_tbl_data->file_path_mime_entity) > 0) { - EM_DEBUG_LOG_SEC("file_path_mime_entity[%s]", input_mail_tbl_data->file_path_mime_entity); - root_body->sparep = EM_SAFE_STRDUP(input_mail_tbl_data->file_path_mime_entity); + } else { + EM_DEBUG_LOG("S/MIME encrypted type"); } if (input_attachment_tbl && input_attachment_count) { emstorage_attachment_tbl_t *temp_attachment_tbl = NULL; char *name = NULL; BODY *body_to_attach = NULL; - struct stat st_buf; for(i = 0; i < input_attachment_count; i++) { temp_attachment_tbl = input_attachment_tbl + i; - EM_DEBUG_LOG_SEC("attachment_name[%s], attachment_path[%s]", temp_attachment_tbl->attachment_name, temp_attachment_tbl->attachment_path); - if (stat(temp_attachment_tbl->attachment_path, &st_buf) == 0) { - if (!temp_attachment_tbl->attachment_name) { - if (!emcore_get_file_name(temp_attachment_tbl->attachment_path, &name, &error)) { - EM_DEBUG_EXCEPTION("emcore_get_file_name failed [%d]", error); - continue; - } - } - else - name = temp_attachment_tbl->attachment_name; - EM_DEBUG_LOG_SEC("name[%s]", name); - - if (temp_attachment_tbl->attachment_inline_content_status && part_for_related) - body_to_attach = &(part_for_related->body); - else - body_to_attach = root_body; + EM_DEBUG_LOG_SEC("attachment_name[%s], attachment_path[%s]", temp_attachment_tbl->attachment_name, temp_attachment_tbl->attachment_path); - if (!attach_part(body_to_attach, (unsigned char *)temp_attachment_tbl->attachment_path, 0, name, NULL, temp_attachment_tbl->attachment_inline_content_status, &error)) { - EM_DEBUG_EXCEPTION("attach_part failed [%d]", error); + if (!temp_attachment_tbl->attachment_name) { + if (!emcore_get_file_name(temp_attachment_tbl->attachment_path, &name, &error)) { + EM_DEBUG_EXCEPTION("emcore_get_file_name failed [%d]", error); continue; } } + else + name = temp_attachment_tbl->attachment_name; + + EM_DEBUG_LOG_SEC("name[%s]", name); + + if (temp_attachment_tbl->attachment_inline_content_status && part_for_related) + body_to_attach = &(part_for_related->body); + else + body_to_attach = root_body; + + if (!attach_part(body_to_attach, + (unsigned char *)temp_attachment_tbl->attachment_path, + 0, + name, + temp_attachment_tbl->attachment_mime_type, + temp_attachment_tbl->attachment_inline_content_status, + &error)) + { + EM_DEBUG_EXCEPTION("attach_part failed [%d]", error); + continue; + } } } text_body = NULL; @@ -3410,13 +3776,11 @@ INTERNAL_FUNC int emcore_make_rfc822_file_from_mail(emstorage_mail_tbl_t *input_ if (file_path) { EM_DEBUG_LOG("write rfc822 : file_path[%p]", file_path); - if ((error = emcore_write_rfc822 (envelope, root_body, input_mail_tbl_data->priority, - input_mail_tbl_data->report_status, &fname)) != EMAIL_ERROR_NONE) { + if ((error = emcore_write_rfc822 (envelope, root_body, input_mail_tbl_data->priority, + input_mail_tbl_data->report_status, file_path)) != EMAIL_ERROR_NONE) { EM_DEBUG_EXCEPTION("emcore_write_rfc822 failed [%d]", error); goto FINISH_OFF; } - - *file_path = fname; } ret = true; @@ -3433,6 +3797,8 @@ FINISH_OFF: if (root_body != NULL) mail_free_body(&root_body); + EM_SAFE_FREE(digest_string); + if (err_code != NULL) *err_code = error; @@ -3440,390 +3806,78 @@ FINISH_OFF: return ret; } -INTERNAL_FUNC int emcore_make_rfc822_file(email_mail_data_t *input_mail_tbl_data, email_attachment_data_t *input_attachment_tbl, int input_attachment_count, char **file_path, int *err_code) +INTERNAL_FUNC int emcore_make_rfc822_file(email_mail_data_t *input_mail_tbl_data, email_attachment_data_t *input_attachment_tbl, int input_attachment_count, int mime_entity_status, char **file_path, int *err_code) { EM_DEBUG_FUNC_BEGIN("input_mail_tbl_data[%p], file_path[%p], err_code[%p]", input_mail_tbl_data, file_path, err_code); - int ret = false; - int error = EMAIL_ERROR_NONE; - int is_incomplete = 0; - int i = 0; - ENVELOPE *envelope = NULL; - BODY *text_body = NULL; - BODY *root_body = NULL; - PART *part_for_html = NULL; - PART *part_for_text = NULL; - char temp_file_path_plain[512]; - char temp_file_path_html[512]; - char *pAdd = NULL; - char *fname = NULL; - emstorage_account_tbl_t *ref_account = NULL; - - if (!input_mail_tbl_data) { - EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM"); - error = EMAIL_ERROR_INVALID_PARAM; - goto FINISH_OFF; - } - - if ( (input_mail_tbl_data->report_status & EMAIL_MAIL_REPORT_MDN) != 0 && !input_mail_tbl_data->body_download_status) { - EM_DEBUG_EXCEPTION("input_mail_tbl_data->body_download_status[%p]", input_mail_tbl_data->body_download_status); - error = EMAIL_ERROR_INVALID_PARAM; - goto FINISH_OFF; - } - - if (!emstorage_get_account_by_id(input_mail_tbl_data->account_id, GET_FULL_DATA_WITHOUT_PASSWORD, &ref_account, true, &error)) { - EM_DEBUG_EXCEPTION("emstorage_get_account_by_id failed : [%d]", error); - goto FINISH_OFF; - } + int err = EMAIL_ERROR_NONE; + int ret = false; + int i = 0; + int attachment_count = 0; + int inline_content_count = 0; - if (!ref_account) { - EM_DEBUG_EXCEPTION("emcore_get_account_reference failed [%d]", input_mail_tbl_data->account_id); - error = EMAIL_ERROR_INVALID_ACCOUNT; - goto FINISH_OFF; - } + emstorage_mail_tbl_t *modified_mail_data = NULL; + emstorage_attachment_tbl_t *modified_attachment_data = NULL; - if (!(envelope = mail_newenvelope())) { - EM_DEBUG_EXCEPTION("mail_newenvelope failed..."); - error = EMAIL_ERROR_OUT_OF_MEMORY; + /* Convert from email_mail_data_t to emstorage_mail_tbl_t */ + if (!em_convert_mail_data_to_mail_tbl(input_mail_tbl_data, 1, &modified_mail_data, &err)) { + EM_DEBUG_EXCEPTION("em_convert_mail_tbl_to_mail_data falied [%d]", err); goto FINISH_OFF; } - is_incomplete = input_mail_tbl_data->flags_draft_field || (input_mail_tbl_data->save_status == EMAIL_MAIL_STATUS_SENDING); - - if (is_incomplete) { - if (ref_account->user_email_address && ref_account->user_email_address[0] != '\0') { - char *p = cpystr(ref_account->user_email_address); - - if (p == NULL) { - EM_DEBUG_EXCEPTION("cpystr failed..."); - error = EMAIL_ERROR_OUT_OF_MEMORY; - goto FINISH_OFF; - } - - EM_DEBUG_LOG("Assign envelop->from"); - - if (input_mail_tbl_data->full_address_from) { - char *temp_address_string = NULL ; - em_skip_whitespace(input_mail_tbl_data->full_address_from , &temp_address_string); - EM_DEBUG_LOG_SEC("address[temp_address_string][%s]", temp_address_string); - rfc822_parse_adrlist(&envelope->from, temp_address_string, ref_account->outgoing_server_address); - EM_SAFE_FREE(temp_address_string); - temp_address_string = NULL ; - } - else - envelope->from = rfc822_parse_mailbox(&p, NULL); - - EM_SAFE_FREE(p); - if (!envelope->from) { - EM_DEBUG_EXCEPTION("rfc822_parse_mailbox failed..."); - error = EMAIL_ERROR_INVALID_ADDRESS; - goto FINISH_OFF; - } - else { - - if (envelope->from->personal == NULL) { - envelope->from->personal = - (ref_account->user_display_name && ref_account->user_display_name[0] != '\0')? - cpystr(ref_account->user_display_name) : NULL; - } - } - } - } - - if (ref_account->return_address && ref_account->return_address[0] != '\0') { - char *p = cpystr(ref_account->return_address); - - if (p == NULL) { - EM_DEBUG_EXCEPTION("cpystr failed..."); - - error = EMAIL_ERROR_OUT_OF_MEMORY; - goto FINISH_OFF; - } - envelope->return_path = rfc822_parse_mailbox(&p, NULL); - EM_SAFE_FREE(p); - } - else { - if (!input_mail_tbl_data->full_address_from || !input_mail_tbl_data->full_address_to) { - EM_DEBUG_EXCEPTION("input_mail_tbl_data->full_address_from[%p], input_mail_tbl_data->full_address_to[%p]", input_mail_tbl_data->full_address_from, input_mail_tbl_data->full_address_to); - error = EMAIL_ERROR_INVALID_MAIL; - goto FINISH_OFF; - } - - int i, j; - - if (input_mail_tbl_data->full_address_from) { - for (i = 0, j = EM_SAFE_STRLEN(input_mail_tbl_data->full_address_from); i < j; i++) { - if (input_mail_tbl_data->full_address_from[i] == ';') - input_mail_tbl_data->full_address_from[i] = ','; - } - } - - if (input_mail_tbl_data->full_address_return) { - for (i = 0, j = EM_SAFE_STRLEN(input_mail_tbl_data->full_address_return); i < j; i++) { - if (input_mail_tbl_data->full_address_return[i] == ';') - input_mail_tbl_data->full_address_return[i] = ','; - } - } - em_skip_whitespace(input_mail_tbl_data->full_address_from , &pAdd); - EM_DEBUG_LOG_SEC("address[pAdd][%s]", pAdd); - - rfc822_parse_adrlist(&envelope->from, pAdd, ref_account->outgoing_server_address); - EM_SAFE_FREE(pAdd); - pAdd = NULL ; - - em_skip_whitespace(input_mail_tbl_data->full_address_return , &pAdd); - EM_DEBUG_LOG_SEC("address[pAdd][%s]", pAdd); - - rfc822_parse_adrlist(&envelope->return_path, pAdd, ref_account->outgoing_server_address); - EM_SAFE_FREE(pAdd); - pAdd = NULL ; - } - - { - int i, j; - - if (input_mail_tbl_data->full_address_to) { - for (i = 0, j = EM_SAFE_STRLEN(input_mail_tbl_data->full_address_to); i < j; i++) { - if (input_mail_tbl_data->full_address_to[i] == ';') - input_mail_tbl_data->full_address_to[i] = ','; - } - } - - if (input_mail_tbl_data->full_address_cc) { - for (i = 0, j = EM_SAFE_STRLEN(input_mail_tbl_data->full_address_cc); i < j; i++) { - if (input_mail_tbl_data->full_address_cc[i] == ';') - input_mail_tbl_data->full_address_cc[i] = ','; - } - } - - if (input_mail_tbl_data->full_address_bcc) { - for (i = 0, j = EM_SAFE_STRLEN(input_mail_tbl_data->full_address_bcc); i < j; i++) { - if (input_mail_tbl_data->full_address_bcc[i] == ';') - input_mail_tbl_data->full_address_bcc[i] = ','; - } - } - } - - em_skip_whitespace(input_mail_tbl_data->full_address_to , &pAdd); - EM_DEBUG_LOG_SEC("address[pAdd][%s]", pAdd); - - rfc822_parse_adrlist(&envelope->to, pAdd, ref_account->outgoing_server_address); - EM_SAFE_FREE(pAdd); - pAdd = NULL ; - - EM_DEBUG_LOG_SEC("address[input_mail_tbl_data->full_address_cc][%s]", input_mail_tbl_data->full_address_cc); - em_skip_whitespace(input_mail_tbl_data->full_address_cc , &pAdd); - EM_DEBUG_LOG_SEC("address[pAdd][%s]", pAdd); - - rfc822_parse_adrlist(&envelope->cc, pAdd, ref_account->outgoing_server_address); - EM_SAFE_FREE(pAdd); - pAdd = NULL ; - - em_skip_whitespace(input_mail_tbl_data->full_address_bcc , &pAdd); - rfc822_parse_adrlist(&envelope->bcc, pAdd, ref_account->outgoing_server_address); - EM_SAFE_FREE(pAdd); - pAdd = NULL ; - - emcore_encode_rfc2047_address(envelope->return_path, &error); - emcore_encode_rfc2047_address(envelope->from, &error); - emcore_encode_rfc2047_address(envelope->sender, &error); - emcore_encode_rfc2047_address(envelope->reply_to, &error); - emcore_encode_rfc2047_address(envelope->to, &error); - emcore_encode_rfc2047_address(envelope->cc, &error); - emcore_encode_rfc2047_address(envelope->bcc, &error); - - if (input_mail_tbl_data->subject) - envelope->subject = emcore_encode_rfc2047_text(input_mail_tbl_data->subject, &error); - - char rfc822_date_string[DATE_STR_LENGTH] = { 0, }; - char localtime_string[DATE_STR_LENGTH] = {0, }; - - rfc822_date(rfc822_date_string); - - if (!is_incomplete) { - strftime(localtime_string, 128, "%a, %e %b %Y %H : %M : %S ", localtime(&input_mail_tbl_data->date_time)); - /* append last 5byes("+0900") */ - g_strlcat(localtime_string, rfc822_date_string + (EM_SAFE_STRLEN(rfc822_date_string) - 5), DATE_STR_LENGTH); - envelope->date = (unsigned char *)cpystr((const char *)localtime_string); - } - else { - envelope->date = (unsigned char *)cpystr((const char *)rfc822_date_string); - } - /* check report input_mail_tbl_data */ - - /* Non-report input_mail_tbl_data */ - EM_DEBUG_LOG_SEC("input_mail_tbl_data->file_path_plain[%s]", input_mail_tbl_data->file_path_plain); - EM_DEBUG_LOG_SEC("input_mail_tbl_data->file_path_html[%s]", input_mail_tbl_data->file_path_html); - EM_DEBUG_LOG("input_mail_tbl_data->body->attachment_num[%d]", input_mail_tbl_data->attachment_count); - - if (input_mail_tbl_data->file_path_plain) { - memset(temp_file_path_plain, 0x00, sizeof(temp_file_path_plain)); - SNPRINTF(temp_file_path_plain, sizeof(temp_file_path_plain), "%s%s%s", MAILTEMP, DIR_SEPERATOR, "UTF-8"); + if (mime_entity_status) + modified_mail_data->smime_type = EMAIL_SMIME_NONE; - if (!emstorage_copy_file(input_mail_tbl_data->file_path_plain, temp_file_path_plain, 0, &error)) { - EM_DEBUG_EXCEPTION("emstorage_copy_file failed : [%d]", error); - goto FINISH_OFF; - } - } - - if (input_mail_tbl_data->file_path_html) { - memset(temp_file_path_html, 0x00, sizeof(temp_file_path_html)); - SNPRINTF(temp_file_path_html, sizeof(temp_file_path_html), "%s%s%s", MAILTEMP, DIR_SEPERATOR, "UTF-8.htm"); - - if (!emstorage_copy_file(input_mail_tbl_data->file_path_html, temp_file_path_html, 0, &error)) { - EM_DEBUG_EXCEPTION("emstorage_copy_file failed : [%d]", error); + /* Convert from email_attachment_data_t to emstorage_attachment_tbl_t */ + if (input_attachment_count > 0) { + modified_attachment_data = em_malloc(sizeof(emstorage_attachment_tbl_t) * input_attachment_count); + if (modified_attachment_data == NULL) { + EM_DEBUG_EXCEPTION("em_malloc failed"); + err = EMAIL_ERROR_OUT_OF_MEMORY; goto FINISH_OFF; } } - if ((input_mail_tbl_data->attachment_count > 0) || (input_mail_tbl_data->file_path_plain && input_mail_tbl_data->file_path_html)) { - EM_DEBUG_LOG("attachment_num : %d", input_mail_tbl_data->attachment_count); - root_body = mail_newbody(); - - if (root_body == NULL) { - EM_DEBUG_EXCEPTION("mail_newbody failed..."); - error = EMAIL_ERROR_OUT_OF_MEMORY; - goto FINISH_OFF; - } - - root_body->type = TYPEMULTIPART; - root_body->subtype = strdup("MIXED"); - root_body->contents.text.data = NULL; - root_body->contents.text.size = 0; - root_body->size.bytes = 0; - - part_for_text = attach_multipart_with_sub_type(root_body, "ALTERNATIVE", &error); - - if (!part_for_text) { - EM_DEBUG_EXCEPTION("attach_multipart_with_sub_type [part_for_text] failed [%d]", error); - goto FINISH_OFF; - } - - text_body = &part_for_text->body; - - if (input_mail_tbl_data->file_path_plain && EM_SAFE_STRLEN(input_mail_tbl_data->file_path_plain) > 0) { - EM_DEBUG_LOG_SEC("file_path_plain[%s]", input_mail_tbl_data->file_path_plain); - if (!attach_part(text_body, (unsigned char *)temp_file_path_plain, 0, NULL, NULL, false, &error)) { - EM_DEBUG_EXCEPTION("attach_part failed [%d]", error); - goto FINISH_OFF; - } - } - - if (input_mail_tbl_data->file_path_html && EM_SAFE_STRLEN(input_mail_tbl_data->file_path_html) > 0) { - EM_DEBUG_LOG_SEC("file_path_html[%s]", input_mail_tbl_data->file_path_html); - - part_for_html = attach_multipart_with_sub_type(text_body, "RELATED", &error); - if (!part_for_html) { - EM_DEBUG_EXCEPTION("attach_multipart_with_sub_type [part_for_html] failed [%d]", error); - goto FINISH_OFF; - } - - if (!attach_part(&(part_for_html->body) , (unsigned char *)temp_file_path_html, 0, NULL, "html", false, &error)) { - EM_DEBUG_EXCEPTION("attach_part failed [%d]", error); - goto FINISH_OFF; - } - } + for (i = 0; i < input_attachment_count; i++) { + modified_attachment_data[i].attachment_id = input_attachment_tbl[i].attachment_id; + modified_attachment_data[i].attachment_name = EM_SAFE_STRDUP(input_attachment_tbl[i].attachment_name); + modified_attachment_data[i].attachment_path = EM_SAFE_STRDUP(input_attachment_tbl[i].attachment_path); + modified_attachment_data[i].content_id = EM_SAFE_STRDUP(input_attachment_tbl[i].content_id); + modified_attachment_data[i].attachment_id = input_attachment_tbl[i].attachment_size; + modified_attachment_data[i].mail_id = input_attachment_tbl[i].mail_id; + modified_attachment_data[i].account_id = input_attachment_tbl[i].account_id; + modified_attachment_data[i].mailbox_id = input_attachment_tbl[i].mailbox_id; + modified_attachment_data[i].attachment_save_status = input_attachment_tbl[i].save_status; + modified_attachment_data[i].attachment_drm_type = input_attachment_tbl[i].drm_status; + modified_attachment_data[i].attachment_inline_content_status = input_attachment_tbl[i].inline_content_status; + modified_attachment_data[i].attachment_mime_type = EM_SAFE_STRDUP(input_attachment_tbl[i].attachment_mime_type); - if (input_attachment_tbl && input_attachment_count) { - email_attachment_data_t *temp_attachment_tbl = NULL; - char *name = NULL; - BODY *body_to_attach = NULL; - struct stat st_buf; - - for(i = 0; i < input_attachment_count; i++) { - temp_attachment_tbl = input_attachment_tbl + i; - EM_DEBUG_LOG_SEC("attachment_name[%s], attachment_path[%s]", temp_attachment_tbl->attachment_name, temp_attachment_tbl->attachment_path); - if (stat(temp_attachment_tbl->attachment_path, &st_buf) == 0) { - if (!temp_attachment_tbl->attachment_name) { - if (!emcore_get_file_name(temp_attachment_tbl->attachment_path, &name, &error)) { - EM_DEBUG_EXCEPTION("emcore_get_file_name failed [%d]", error); - continue; - } - } - else - name = temp_attachment_tbl->attachment_name; - EM_DEBUG_LOG_SEC("name[%s]", name); - - if (temp_attachment_tbl->inline_content_status && part_for_html) - body_to_attach = &(part_for_html->body); - else - body_to_attach = root_body; - - if (!attach_part(body_to_attach, (unsigned char *)temp_attachment_tbl->attachment_path, 0, name, NULL, temp_attachment_tbl->inline_content_status, &error)) { - EM_DEBUG_EXCEPTION("attach_part failed [%d]", error); - continue; - } - } - } - } - text_body = NULL; - } - else { - text_body = mail_newbody(); - - if (text_body == NULL) { - EM_DEBUG_EXCEPTION("mail_newbody failed..."); - - error = EMAIL_ERROR_OUT_OF_MEMORY; - goto FINISH_OFF; - } - - text_body->type = TYPETEXT; - text_body->encoding = ENC8BIT; - if (input_mail_tbl_data->file_path_plain || input_mail_tbl_data->file_path_html) - text_body->sparep = EM_SAFE_STRDUP(input_mail_tbl_data->file_path_plain ? temp_file_path_plain : temp_file_path_html); - else - text_body->sparep = NULL; - - if (input_mail_tbl_data->file_path_html != NULL && input_mail_tbl_data->file_path_html[0] != '\0') - text_body->subtype = strdup("html"); - if (text_body->sparep) - text_body->size.bytes = EM_SAFE_STRLEN(text_body->sparep); + if (input_attachment_tbl[i].inline_content_status == INLINE_ATTACHMENT) + inline_content_count += 1; else - text_body->size.bytes = 0; - } - - if (file_path) { - if ((error = emcore_write_rfc822 (envelope, (root_body? root_body: text_body), input_mail_tbl_data->priority, - input_mail_tbl_data->report_status, &fname)) != EMAIL_ERROR_NONE) { - EM_DEBUG_EXCEPTION("emcore_write_rfc822 failed [%d]", error); - goto FINISH_OFF; - } - - *file_path = fname; + attachment_count += 1; } - if (EM_SAFE_STRLEN(temp_file_path_plain) > 0) { - if (!emstorage_delete_file(temp_file_path_plain, &error)) { - EM_DEBUG_EXCEPTION("emstorage_delete_file failed [%d]", error); - goto FINISH_OFF; - } - } + modified_mail_data->attachment_count = attachment_count; + modified_mail_data->inline_content_count = inline_content_count; - if (EM_SAFE_STRLEN(temp_file_path_html) > 0) { - if (!emstorage_delete_file(temp_file_path_html, &error)) { - EM_DEBUG_EXCEPTION("emstorage_delete_file failed [%d]", error); - goto FINISH_OFF; - } + if (!emcore_make_rfc822_file_from_mail(modified_mail_data, modified_attachment_data, input_attachment_count, NULL, file_path, NULL, &err)) { + EM_DEBUG_EXCEPTION("emcore_make_rfc822_file_from_mail failed [%d]", err); + goto FINISH_OFF; } ret = true; FINISH_OFF: - emstorage_free_account(&ref_account, 1, NULL); - - if (envelope != NULL) - mail_free_envelope(&envelope); + if (modified_mail_data) + emstorage_free_mail(&modified_mail_data, 1, NULL); - if (text_body != NULL) - mail_free_body(&text_body); + if (modified_attachment_data) + emstorage_free_attachment(&modified_attachment_data, input_attachment_count, NULL); - if (root_body != NULL) - mail_free_body(&root_body); - - if (err_code != NULL) - *err_code = error; + if (err_code) + *err_code = err; EM_DEBUG_FUNC_END("ret [%d]", ret); return ret; @@ -3841,7 +3895,7 @@ static int emcore_get_report_mail_body(ENVELOPE *envelope, BODY **multipart_body BODY *p_body = NULL; BODY *text_body = NULL; PARAMETER *param = NULL; - emstorage_attachment_tbl_t temp_attachment_tbl; + emstorage_attachment_tbl_t *temp_attachment_tbl = NULL; FILE *fp = NULL; char *fname = NULL; char buf[512] = {0x00, }; @@ -3864,9 +3918,9 @@ static int emcore_get_report_mail_body(ENVELOPE *envelope, BODY **multipart_body goto FINISH_OFF; } - if (!(fp = fopen(fname, "wb+"))) { - EM_DEBUG_EXCEPTION(" fopen failed - %s", fname); - err = EMAIL_ERROR_SYSTEM_FAILURE; + err = em_fopen(fname, "wb+", &fp); + if (err != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("em_fopen failed - %s, error : [%d]", fname, err); goto FINISH_OFF; } @@ -3907,9 +3961,9 @@ static int emcore_get_report_mail_body(ENVELOPE *envelope, BODY **multipart_body goto FINISH_OFF; } - if (!(fp = fopen(fname, "wb+"))) { - EM_DEBUG_EXCEPTION(" fopen failed - %s", fname); - err = EMAIL_ERROR_SYSTEM_FAILURE; /* EMAIL_ERROR_UNKNOWN; */ + err = em_fopen(fname, "wb+", &fp); + if (err != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("em_fopen failed - %s, error : [%d]", fname, err); goto FINISH_OFF; } @@ -3925,16 +3979,21 @@ static int emcore_get_report_mail_body(ENVELOPE *envelope, BODY **multipart_body fclose(fp); fp = NULL; - memset(&temp_attachment_tbl, 0x00, sizeof(emstorage_attachment_tbl_t)); + temp_attachment_tbl = (emstorage_attachment_tbl_t *)em_malloc(sizeof(emstorage_attachment_tbl_t)); + if (temp_attachment_tbl == NULL) { + EM_DEBUG_EXCEPTION("em_malloc failed"); + err = EMAIL_ERROR_OUT_OF_MEMORY; + goto FINISH_OFF; + } - temp_attachment_tbl.attachment_path = EM_SAFE_STRDUP(fname); + temp_attachment_tbl->attachment_path = EM_SAFE_STRDUP(fname); - if (!emcore_get_file_size(fname, &temp_attachment_tbl.attachment_size, &err)) { + if (!emcore_get_file_size(fname, &temp_attachment_tbl->attachment_size, &err)) { EM_DEBUG_EXCEPTION(" emcore_get_file_size failed [%d]", err); goto FINISH_OFF; } - if (!attach_attachment_to_body(&m_body, text_body, &temp_attachment_tbl, 1, &err)) { + if (!attach_attachment_to_body(&m_body, text_body, temp_attachment_tbl, 1, &err)) { EM_DEBUG_EXCEPTION(" attach_attachment_to_body failed [%d]", err); goto FINISH_OFF; } @@ -3996,6 +4055,9 @@ FINISH_OFF: EM_SAFE_FREE(fname); + if (temp_attachment_tbl) + emstorage_free_attachment(&temp_attachment_tbl, 1, NULL); + if (err_code != NULL) *err_code = err; @@ -4009,11 +4071,9 @@ INTERNAL_FUNC int emcore_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"); @@ -4026,7 +4086,6 @@ INTERNAL_FUNC int emcore_get_body_buff(char *file_path, char **buff) if (stat(file_path, &stbuf) == 0 && stbuf.st_size > 0) { EM_DEBUG_LOG(" File Size [ %d ] ", stbuf.st_size); read_buff = calloc((stbuf.st_size+ 1), sizeof(char)); - read_size = fread(read_buff, 1, stbuf.st_size, r_fp); read_buff[stbuf.st_size] = '\0'; } @@ -4082,7 +4141,7 @@ static int emcore_copy_attachment_from_original_mail(int input_original_mail_id, EM_DEBUG_LOG("attachment_inline_content_status [%d] attachment_id[%d]", target_attach->attachment_inline_content_status, attachment_id); - if(!emcore_save_mail_file(target_attach->account_id, target_attach->mail_id, attachment_id, original_mail_attachment_array[i].attachment_path, original_mail_attachment_array[i].attachment_name, output_file_path, &err)) { + if(!emcore_save_mail_file(target_attach->account_id, target_attach->mail_id, attachment_id, original_mail_attachment_array[i].attachment_path, original_mail_attachment_array[i].attachment_name, output_file_path, sizeof(output_file_path), &err)) { EM_DEBUG_EXCEPTION("emcore_save_mail_file failed [%d]", err); goto FINISH_OFF; } @@ -4151,10 +4210,19 @@ INTERNAL_FUNC int emcore_send_mail_with_downloading_attachment_of_original_mail( /* If need be, download attachments */ for(i = 0; i < attachment_count; i++) { if(attachment_array[i].save_status != 1) { - if(!emcore_download_attachment(original_mail->account_id, original_mail->mail_id, i + 1, &err)) { + /* this function is not run by event thread, + so cancellable should be set to 0*/ +#ifdef __FEATURE_USE_GMIME__ + if(!emcore_gmime_download_attachment (original_mail->mail_id, i + 1, 0, -1, 0, &err)) { EM_DEBUG_EXCEPTION("emcore_download_attachment failed [%d]", err); goto FINISH_OFF; } +#else + if(!emcore_download_attachment (original_mail->account_id, original_mail->mail_id, i + 1, 0, -1, &err)) { + EM_DEBUG_EXCEPTION("emcore_download_attachment failed [%d]", err); + goto FINISH_OFF; + } +#endif } } @@ -4191,15 +4259,14 @@ FINISH_OFF: /* Scheduled sending ------------------------------------------------ */ -static int emcore_sending_alarm_cb(int input_alarm_id, void *user_parameter) +static int emcore_sending_alarm_cb(email_alarm_data_t *alarm_data, void *user_parameter) { - EM_DEBUG_FUNC_BEGIN("input_alarm_id [%d] user_parameter [%p]", input_alarm_id, user_parameter); + EM_DEBUG_FUNC_BEGIN("alarm_data [%p] user_parameter [%p]", alarm_data, user_parameter); int err = EMAIL_ERROR_NONE; int ret = 0; - email_alarm_data_t *alarm_data = NULL; - if (((err = emcore_get_alarm_data_by_alarm_id(input_alarm_id, &alarm_data)) != EMAIL_ERROR_NONE) || alarm_data == NULL) { - EM_DEBUG_EXCEPTION("emcore_get_alarm_data_by_alarm_id failed [%d]", err); + if (alarm_data == NULL) { + EM_DEBUG_EXCEPTION("Invalid parameter"); goto FINISH_OFF; } @@ -4257,9 +4324,9 @@ FINISH_OFF: #ifdef __FEATURE_AUTO_RETRY_SEND__ -static int emcore_auto_resend_cb(int input_alarm_id, void *user_parameter) +static int emcore_auto_resend_cb(email_alarm_data_t *alarm_data, void *user_parameter) { - EM_DEBUG_FUNC_BEGIN("input_alarm_id [%d] user_parameter [%p]", input_alarm_id, user_parameter); + EM_DEBUG_FUNC_BEGIN("alarm_data [%p] user_parameter [%p]", alarm_data, user_parameter); int err = EMAIL_ERROR_NONE; char *conditional_clause_string = NULL; char *attribute_field_name = NULL; @@ -4331,7 +4398,7 @@ static int emcore_auto_resend_cb(int input_alarm_id, void *user_parameter) } FINISH_OFF: - + EM_SAFE_FREE (conditional_clause_string); /* detected by valgrind */ EM_SAFE_FREE(result_mail_list); EM_DEBUG_FUNC_END("err [%d]", err); @@ -4345,7 +4412,6 @@ INTERNAL_FUNC int emcore_create_alarm_for_auto_resend(int input_alarm_interval_i time_t current_time; time_t trigger_at_time; char *conditional_clause_string = NULL; - char *attribute_field_name = NULL; email_list_filter_t filter_list[5]; email_mail_list_item_t *result_mail_list = NULL; email_list_sorting_rule_t sorting_rule_list[2]; @@ -4366,7 +4432,6 @@ INTERNAL_FUNC int emcore_create_alarm_for_auto_resend(int input_alarm_interval_i goto FINISH_OFF; } /* Get all mails have remaining resend counts in outbox with status 'EMAIL_MAIL_STATUS_SEND_FAILURE or EMAIL_MAIL_STATUS_SEND_WAIT' */ - attribute_field_name = emcore_get_mail_field_name_by_attribute_type(EMAIL_MAIL_ATTRIBUTE_REMAINING_RESEND_TIMES); memset(filter_list, 0 , sizeof(email_list_filter_t) * filter_rule_count); memset(sorting_rule_list, 0 , sizeof(email_list_sorting_rule_t) * sorting_rule_count); diff --git a/email-core/email-core-sound.c b/email-core/email-core-sound.c deleted file mode 100755 index 5bf7f98..0000000 --- a/email-core/email-core-sound.c +++ /dev/null @@ -1,343 +0,0 @@ -/* -* email-service -* -* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. -* -* Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -* -*/ - - -#include <stdlib.h> -#include <pthread.h> - -#include "email-debug-log.h" -#include "email-storage.h" -#include "email-core-utils.h" -#include "email-core-mailbox.h" -#include "email-core-sound.h" -#include "email-core-alarm.h" -#include "email-utilities.h" -#include "email-daemon.h" - -#define TIMER 30000 // 30 seconds -#define HAPTIC_TEST_ITERATION 1 -#define EMAIL_ALARM_REFERENCE_ID_FOR_ALERT_TONE -1 - -static int emcore_get_alert_type(int vip_mode); -static int emcore_alarm_timeout_cb_for_alert(int timer_id, void *user_parm); -static int emcore_set_alarm_for_alert(int alert_time_in_minute); -static void emcore_set_repetition_alarm(int repetition); -static char * emcore_get_sound_file_path(int vip_mode); - - -static int emcore_get_alert_type(int vip_mode) -{ - EM_DEBUG_FUNC_BEGIN(); - int global_sound_status = 0; - int global_vibe_status = 0; - int email_vibe_status = 0; - int call_state = 0; - int alert_type = EMAIL_ALERT_TYPE_MUTE; - int voicerecoder_state = 0; - - if (vconf_get_bool(VCONFKEY_SETAPPL_SOUND_STATUS_BOOL, &global_sound_status) != 0) { - EM_DEBUG_LOG("vconf_get_bool for VCONFKEY_SETAPPL_SOUND_STATUS_BOOL failed"); - goto FINISH_OFF; - } - - if (vconf_get_bool(VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL, &global_vibe_status) != 0) { - EM_DEBUG_LOG("vconf_get_bool for VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOLfailed"); - goto FINISH_OFF; - } - - EM_DEBUG_LOG("global_sound_status [%d] global_vibe_status [%d]", global_sound_status, global_vibe_status); - - if (global_sound_status || global_vibe_status) { - - if (vconf_get_int(VCONFKEY_VOICERECORDER_STATE, &voicerecoder_state) != 0) { - EM_DEBUG_LOG("vconf_get_int for VCONFKEY_VOICERECORDER_STATE failed"); - } - EM_DEBUG_LOG("voicerecoder_state [%d]", voicerecoder_state); - - if (vconf_get_int(VCONFKEY_CALL_STATE, &call_state) != 0) { - EM_DEBUG_LOG("vconf_get_int for VCONFKEY_CALL_STATE failed"); - } - EM_DEBUG_LOG("call_state [%d] ", call_state); - - if (vip_mode) { - if (vconf_get_bool(VCONF_VIP_NOTI_VIBRATION_STATUS_BOOL, &email_vibe_status) != 0) { - EM_DEBUG_EXCEPTION("vconf_get_bool failed"); - return EMAIL_ALERT_TYPE_NONE; - } - } - else { - if (vconf_get_bool(VCONF_EMAIL_NOTI_VIBRATION_STATUS_BOOL, &email_vibe_status) != 0) { - EM_DEBUG_EXCEPTION("vconf_get_bool failed"); - return EMAIL_ALERT_TYPE_NONE; - } - } - - EM_DEBUG_LOG("email_vibe_status [%d] ", email_vibe_status); - - if (voicerecoder_state == VCONFKEY_VOICERECORDER_RECORDING) { - alert_type = EMAIL_ALERT_TYPE_VIB; - EM_DEBUG_LOG("voice recorder is on recording..."); - } - else if (call_state > VCONFKEY_CALL_OFF && call_state < VCONFKEY_CALL_STATE_MAX) { - EM_DEBUG_LOG("Calling"); -#ifdef FEATURE_OPCO_DOCOMO - alert_type = EMAIL_ALERT_TYPE_NONE; -#else - alert_type = EMAIL_ALERT_TYPE_VIB; -#endif - } - else if (global_sound_status && email_vibe_status) { - alert_type = EMAIL_ALERT_TYPE_MELODY_AND_VIB; - } - else if (global_sound_status) { - alert_type = EMAIL_ALERT_TYPE_MELODY; - } - else if (global_vibe_status) { - alert_type = EMAIL_ALERT_TYPE_VIB; - } - else { - alert_type = EMAIL_ALERT_TYPE_MUTE; - } - } - -FINISH_OFF: - EM_DEBUG_FUNC_END("alert_type [%d]", alert_type); - return alert_type; -} - -static int emcore_alarm_timeout_cb_for_alert(int timer_id, void *user_parm) -{ - EM_DEBUG_FUNC_BEGIN(); - - int err = EMAIL_ERROR_NONE; - int total_unread_count = 0; - int total_mail_count = 0; - email_mailbox_t mailbox; - - memset(&mailbox, 0x00, sizeof(email_mailbox_t)); - - mailbox.account_id = ALL_ACCOUNT; - mailbox.mailbox_name = NULL; - - if (!emcore_get_mail_count(&mailbox, &total_mail_count, &total_unread_count, &err)) { - EM_DEBUG_EXCEPTION("emcore_get_mail_count failed - %d\n", err); - return false; - } - - EM_DEBUG_LOG(">>>> total_unread_count : [%d]\n", total_unread_count); - - if (total_unread_count) { - /* emdaemon_start_alert(); */ - /* Alarm repetition disabled */ - } - - EM_DEBUG_FUNC_END(); - return true; -} - -/* repetition_time in minutes */ -static int emcore_set_alarm_for_alert(int alert_time_in_minute) -{ - EM_DEBUG_FUNC_BEGIN(); - - int err = EMAIL_ERROR_NONE; - time_t current_time; - time_t trigger_at_time; - - time(¤t_time); - - trigger_at_time = current_time + (alert_time_in_minute * 60); - - if ((err = emcore_add_alarm(trigger_at_time, EMAIL_ALARM_CLASS_NEW_MAIL_ALERT, EMAIL_ALARM_REFERENCE_ID_FOR_ALERT_TONE, emcore_alarm_timeout_cb_for_alert, NULL)) != EMAIL_ERROR_NONE) { - EM_DEBUG_EXCEPTION("emcore_add_alarm failed [%d]", err); - goto FINISH_OFF; - } - -FINISH_OFF: - - EM_DEBUG_FUNC_END("err [%d]", err); - return err; -} - -static void emcore_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) { - emcore_set_alarm_for_alert(repetition_time); - } - - EM_DEBUG_FUNC_END(); -} - -static char * emcore_get_sound_file_path(int vip_mode) -{ - EM_DEBUG_FUNC_BEGIN("vip_mode [%d]", vip_mode); - char *ret = NULL; - int use_default_ring_tone = 0; - - if (vip_mode) { - if (vconf_get_bool(VCONF_VIP_NOTI_USE_DEFAULT_RINGTONE_BOOL, &use_default_ring_tone) != 0) - EM_DEBUG_LOG("vconf_get_bool for VCONF_VIP_NOTI_USE_DEFAULT_RINGTONE_BOOL failed"); - - EM_DEBUG_LOG("use_default_ring_tone [%d]", use_default_ring_tone); - - if (use_default_ring_tone) - ret = EM_SAFE_STRDUP(vconf_get_str(VCONFKEY_SETAPPL_NOTI_RINGTONE_DEFAULT_PATH_STR)); - else - ret = EM_SAFE_STRDUP(vconf_get_str(VCONF_VIP_NOTI_RINGTONE_PATH)); - } - else { - if (vconf_get_bool(VCONF_EMAIL_NOTI_USE_DEFAULT_RINGTONE_BOOL, &use_default_ring_tone) != 0) - EM_DEBUG_LOG("vconf_get_bool for VCONF_EMAIL_NOTI_USE_DEFAULT_RINGTONE_BOOL failed"); - - EM_DEBUG_LOG("use_default_ring_tone [%d]", use_default_ring_tone); - - if (use_default_ring_tone) - ret = EM_SAFE_STRDUP(vconf_get_str(VCONFKEY_SETAPPL_NOTI_RINGTONE_DEFAULT_PATH_STR)); - else - ret = EM_SAFE_STRDUP(vconf_get_str(VCONFKEY_SETAPPL_NOTI_EMAIL_RINGTONE_PATH_STR)); - } - - EM_DEBUG_FUNC_END("ret [%s]", ret); - return ret; -} - - -INTERNAL_FUNC int emcore_get_alert_policy(EMAIL_ALERT_TYPE *output_alert_type, char **output_alert_tone_path) -{ - EM_DEBUG_FUNC_BEGIN("output_alert_type [%p] output_alert_tone_path[%p]", output_alert_type, output_alert_tone_path); - - int err = EMAIL_ERROR_NONE; - int general_noti_status = false; - int vip_noti_status = false; - int vip_mail_count = 0; - int vip_unread_count = 0; - int vip_notification_mode = 0; - char *alert_tone_path = NULL; - EMAIL_ALERT_TYPE alert_type = EMAIL_ALERT_TYPE_NONE; - - if (output_alert_type == NULL || output_alert_tone_path == NULL) { - EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM"); - err = EMAIL_ERROR_INVALID_PARAM; - goto FINISH_OFF; - } - - /* get general noti status */ - if (vconf_get_bool(VCONFKEY_SETAPPL_STATE_TICKER_NOTI_EMAIL_BOOL, &general_noti_status) != 0) { - EM_DEBUG_EXCEPTION("vconf_get_int failed"); - err = EMAIL_ERROR_INVALID_PARAM; - goto FINISH_OFF; - } - - /* get vip noti status */ - if (vconf_get_bool(VCONF_VIP_NOTI_NOTIFICATION_TICKER, &vip_noti_status) != 0) { - EM_DEBUG_EXCEPTION("vconf_get_int failed"); - err = EMAIL_ERROR_DATA_NOT_FOUND; - goto FINISH_OFF; - } - - if (!general_noti_status && !vip_noti_status) { - EM_DEBUG_LOG("both notification disabled"); - goto FINISH_OFF; - } - - if (vip_noti_status) { - if (!emcore_get_mail_count_by_query(ALL_ACCOUNT, EMAIL_MAILBOX_TYPE_INBOX, true, &vip_mail_count, &vip_unread_count, &err)) { - EM_DEBUG_EXCEPTION("emcore_get_mail_count_by_query failed"); - err = EMAIL_ERROR_DATA_NOT_FOUND; - } - } - - if (general_noti_status && !vip_noti_status) { - EM_DEBUG_LOG("GERNERAL NOTI MODE"); - vip_notification_mode = 0; - } - else if (!general_noti_status && vip_noti_status) { - EM_DEBUG_LOG("VIP NOTI MODE"); - if (err == EMAIL_ERROR_FILTER_NOT_FOUND) { - EM_DEBUG_LOG("VIP filter not found"); - err = EMAIL_ERROR_DATA_NOT_FOUND; - goto FINISH_OFF; - } - vip_notification_mode = 1; - } - else if (general_noti_status && vip_noti_status) { - if (err == EMAIL_ERROR_FILTER_NOT_FOUND) { - EM_DEBUG_LOG("VIP filter not found"); - EM_DEBUG_LOG("GERNERAL NOTI MODE"); - vip_notification_mode = 0; - } else { - //confusing.. - if (vip_unread_count > 0) { - EM_DEBUG_LOG("VIP NOTI MODE"); - vip_notification_mode = 1; - } else { - EM_DEBUG_LOG("GERNERAL NOTI MODE"); - vip_notification_mode = 0; - } - } - } - - alert_type = emcore_get_alert_type(vip_notification_mode); - EM_DEBUG_LOG("alert_type [%d]", alert_type); - - - - EM_DEBUG_LOG("vip_notification_mode [%d]", vip_notification_mode); - - if (alert_type == EMAIL_ALERT_TYPE_MELODY_AND_VIB || alert_type == EMAIL_ALERT_TYPE_MELODY) - alert_tone_path = EM_SAFE_STRDUP(emcore_get_sound_file_path(vip_notification_mode)); - - *output_alert_type = alert_type; - if (alert_tone_path) - *output_alert_tone_path = alert_tone_path; - - EM_DEBUG_LOG("alert_type [%d] alert_tone_path [%s]", alert_type, alert_tone_path); - -FINISH_OFF: - - EM_DEBUG_FUNC_END("err [%d]", err); - - return err; -} diff --git a/email-core/email-core-task-manager.c b/email-core/email-core-task-manager.c index f3a1f7e..bad8921 100755 --- a/email-core/email-core-task-manager.c +++ b/email-core/email-core-task-manager.c @@ -200,7 +200,6 @@ static int emcore_register_task_handler(email_task_type_t input_task_type, void* email_task_handler_t *new_task_handler = NULL;
new_task_handler = malloc(sizeof(email_task_handler_t));
-
if (new_task_handler == NULL) {
err = EMAIL_ERROR_OUT_OF_MEMORY;
EM_DEBUG_EXCEPTION("EMAIL_ERROR_OUT_OF_MEMORY");
@@ -223,6 +222,7 @@ static int emcore_register_task_handler(email_task_type_t input_task_type, void* if (_task_handler_array == NULL) {
err = EMAIL_ERROR_OUT_OF_MEMORY;
+ EM_SAFE_FREE(new_task_handler);
goto FINISH_OFF;
}
@@ -234,13 +234,12 @@ FINISH_OFF: return err;
}
-
INTERNAL_FUNC int emcore_init_task_handler_array()
{
EM_DEBUG_FUNC_BEGIN();
if (_task_handler_array == NULL) {
- _task_handler_array = NULL;
+ _task_handler_array = NULL;
_task_handler_array_size = 0;
REGISTER_TASK_BINDER(EMAIL_ASYNC_TASK_MOVE_MAILS_TO_MAILBOX_OF_ANOTHER_ACCOUNT);
@@ -513,10 +512,11 @@ void* thread_func_task_manager_loop(void *arg) /* create a thread to do this task */
THREAD_CREATE(new_task->thread_id, emcore_default_async_task_handler, new_task, thread_error);
+ EM_DEBUG_LOG("pthread_create returns [%d]", thread_error);
/* new_task and task_parameter will be free in task handler. */
- new_task = NULL;
-
+ EM_SAFE_FREE(new_task->task_parameter);
+ EM_SAFE_FREE(new_task);
}
else {
/* If there is no task or no available slot, sleep until someone wake you up. */
diff --git a/email-core/email-core-tasks.c b/email-core/email-core-tasks.c index 019fa5d..1a9efec 100755 --- a/email-core/email-core-tasks.c +++ b/email-core/email-core-tasks.c @@ -79,7 +79,7 @@ INTERNAL_FUNC int email_encode_task_parameter_EMAIL_ASYNC_TASK_MOVE_MAILS_TO_MAI FINISH_OFF:
EM_DEBUG_FUNC_END("err [%d]", err);
- return EMAIL_ERROR_NONE;
+ return err;
}
INTERNAL_FUNC int email_decode_task_parameter_EMAIL_ASYNC_TASK_MOVE_MAILS_TO_MAILBOX_OF_ANOTHER_ACCOUNT(char *input_byte_stream, int input_stream_size, void **output_task_parameter_struct)
@@ -126,7 +126,7 @@ FINISH_OFF: tpl_free(tn);
EM_DEBUG_FUNC_END("err [%d]", err);
- return EMAIL_ERROR_NONE;
+ return err;
}
INTERNAL_FUNC void* task_handler_EMAIL_ASYNC_TASK_MOVE_MAILS_TO_MAILBOX_OF_ANOTHER_ACCOUNT(void *input_param)
@@ -195,7 +195,7 @@ INTERNAL_FUNC int email_encode_task_parameter_EMAIL_ASYNC_TASK_DELETE_MAILBOX_EX FINISH_OFF:
EM_DEBUG_FUNC_END("err [%d]", err);
- return EMAIL_ERROR_NONE;
+ return err;
}
INTERNAL_FUNC int email_decode_task_parameter_EMAIL_ASYNC_TASK_DELETE_MAILBOX_EX(char *input_byte_stream, int input_stream_size, void **output_task_parameter_struct)
@@ -242,7 +242,7 @@ FINISH_OFF: tpl_free(tn);
EM_DEBUG_FUNC_END("err [%d]", err);
- return EMAIL_ERROR_NONE;
+ return err;
}
INTERNAL_FUNC void* task_handler_EMAIL_ASYNC_TASK_DELETE_MAILBOX_EX(void *input_param)
@@ -281,7 +281,7 @@ INTERNAL_FUNC int email_encode_task_parameter_EMAIL_ASYNC_TASK_SEND_MAIL_WITH_DO FINISH_OFF:
EM_DEBUG_FUNC_END("err [%d]", err);
- return EMAIL_ERROR_NONE;
+ return err;
}
INTERNAL_FUNC int email_decode_task_parameter_EMAIL_ASYNC_TASK_SEND_MAIL_WITH_DOWNLOADING_ATTACHMENT_OF_ORIGINAL_MAIL(char *input_byte_stream, int input_stream_size, void **output_task_parameter_struct)
@@ -318,7 +318,7 @@ FINISH_OFF: tpl_free(tn);
EM_DEBUG_FUNC_END("err [%d]", err);
- return EMAIL_ERROR_NONE;
+ return err;
}
INTERNAL_FUNC void* task_handler_EMAIL_ASYNC_TASK_SEND_MAIL_WITH_DOWNLOADING_ATTACHMENT_OF_ORIGINAL_MAIL(void *input_param)
@@ -357,7 +357,7 @@ INTERNAL_FUNC int email_encode_task_parameter_EMAIL_SYNC_TASK_SCHEDULE_SENDING_M FINISH_OFF:
EM_DEBUG_FUNC_END("err [%d]", err);
- return EMAIL_ERROR_NONE;
+ return err;
}
INTERNAL_FUNC int email_decode_task_parameter_EMAIL_SYNC_TASK_SCHEDULE_SENDING_MAIL(char *input_byte_stream, int input_stream_size, void **output_task_parameter_struct)
@@ -394,7 +394,7 @@ FINISH_OFF: tpl_free(tn);
EM_DEBUG_FUNC_END("err [%d]", err);
- return EMAIL_ERROR_NONE;
+ return err;
}
INTERNAL_FUNC void* task_handler_EMAIL_SYNC_TASK_SCHEDULE_SENDING_MAIL(void *input_param)
@@ -411,8 +411,8 @@ INTERNAL_FUNC void* task_handler_EMAIL_SYNC_TASK_SCHEDULE_SENDING_MAIL(void *inp FINISH_OFF:
- EM_SAFE_FREE(task_param);
-
+ EM_SAFE_FREE(task_param); + emcore_close_smtp_stream_list ();
EM_DEBUG_FUNC_END("err [%d]", err);
return (void*)err;
}
@@ -609,6 +609,7 @@ INTERNAL_FUNC void* task_handler_EMAIL_SYNC_TASK_UPDATE_ATTRIBUTE(void *input_pa break;
case EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_STRING :
err = EMAIL_ERROR_NOT_SUPPORTED;
+ EM_DEBUG_LOG("EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_STRING is not supported");
break;
case EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_TIME :
if(!emstorage_set_field_of_mails_with_integer_value(task_param->account_id, task_param->mail_id_array, task_param->mail_id_count, field_name, task_param->value.datetime_type_value, true, &err)) {
@@ -618,6 +619,7 @@ INTERNAL_FUNC void* task_handler_EMAIL_SYNC_TASK_UPDATE_ATTRIBUTE(void *input_pa break;
case EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_NONE :
default :
+ EM_DEBUG_LOG("EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_NONE or default");
err = EMAIL_ERROR_INVALID_PARAM;
break;
}
@@ -631,7 +633,6 @@ FINISH_OFF: EM_SAFE_FREE (task_param);
-
EM_DEBUG_FUNC_END("err [%d]", err);
return (void*)err;
}
diff --git a/email-core/email-core-utils.c b/email-core/email-core-utils.c index ffcea51..9b12a93 100755 --- a/email-core/email-core-utils.c +++ b/email-core/email-core-utils.c @@ -49,9 +49,19 @@ #include <pthread.h> #include <notification.h> #include <notification_type.h> +#include <notification_internal.h> #include <badge.h> +#include <badge_internal.h> +#ifdef __FEATURE_USE_DRM_API__ #include <drm_client_types.h> #include <drm_client.h> +#endif /* __FEATURE_USE_DRM_API__ */ +#include <feedback.h> +#include <storage.h> +#include <bundle.h> +#include <curl/curl.h> +#include <contacts.h> +#include <contacts_internal.h> #include "email-types.h" #include "email-core-global.h" @@ -64,15 +74,18 @@ #include "email-core-mailbox-sync.h" #include "email-core-mime.h" #include "email-core-signal.h" -#include "email-core-sound.h" #include "email-daemon.h" #include "email-utilities.h" #include "email-convert.h" #include "email-internal-types.h" #include "email-device.h" +#include <gio/gio.h> +#include "email-dbus-activation.h" + + #ifdef __FEATURE_DRIVING_MODE__ -#include <app_service.h> +#include <app_control.h> #endif /* __FEATURE_DRIVING_MODE__ */ #define LED_TIMEOUT_SECS 12 @@ -89,7 +102,9 @@ #define EMAIL_CH_SQUARE_BRACKET_S '[' #define EMAIL_CH_SQUARE_BRACKET_E ']' #define EMAIL_CH_SPACE ' ' -#define EMAIL_NOTI_ICON_PATH EMAILPATH"/res/image/Q02_Notification_email.png" +#define EMAIL_NOTI_ICON_PATH "/usr/apps/org.tizen.quickpanel/shared/res/noti_icons/noti_email.png" +#define EMAIL_NOTI_MAX_MAIL_ID 100 + typedef struct _em_transaction_info_type_t { int mail_id; @@ -100,7 +115,7 @@ typedef struct _em_transaction_info_type_t { em_transaction_info_type_t *g_transaction_info_list; -static email_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},}; +__thread email_session_t g_session = {0}; static notification_h g_sending_noti_handle = NULL; typedef struct emcore_account_list_t emcore_account_list_t; struct emcore_account_list_t { @@ -108,10 +123,91 @@ struct emcore_account_list_t { emcore_account_list_t *next; }; +#include <gmime/gmime.h> + + INTERNAL_FUNC char *emcore_convert_mutf7_to_utf8(char *mailbox_name) { - EM_DEBUG_FUNC_BEGIN(); - return (char *)(utf8_from_mutf7((unsigned char *)mailbox_name)); + EM_DEBUG_FUNC_BEGIN("mailbox_name[%p]", mailbox_name); + + iconv_t cd; + char *result_mailbox_name = NULL; + char *mutf7_text = NULL; + char *cursor = NULL; + int is_base64 = 0; + + if (mailbox_name == NULL) { + EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM"); + return NULL; + } + + EM_DEBUG_LOG_SEC("mailbox_name[%s]", mailbox_name); + + cursor = mutf7_text = EM_SAFE_STRDUP(mailbox_name); + + if (mutf7_text == NULL) { + EM_DEBUG_EXCEPTION("EMAIL_ERROR_OUT_OF_MEMORY"); + return NULL; + } + + for (; *cursor; ++cursor) + switch (*cursor) { + case '+': + if (!is_base64) *cursor = '&'; + break; + + case '&': + *cursor = '+'; + is_base64 = 1; + break; + + case '-': + is_base64 = 0; + break; + + case ',': + if (is_base64) + *cursor = '/'; + break; + } + + cd = g_mime_iconv_open("UTF-8", "UTF-7"); + + if (cd) + result_mailbox_name = g_mime_iconv_strdup(cd, mutf7_text); + + EM_DEBUG_LOG_SEC("result_mailbox_name[%s]", result_mailbox_name); + + if (result_mailbox_name) { + cursor = result_mailbox_name; + for (; *cursor; ++cursor) { + switch (*cursor) { + case '&': + *cursor = '+'; + break; + + case '+': + *cursor = '&'; + break; + } + } + } + else { + result_mailbox_name = (char *)utf8_from_mutf7 ((unsigned char *)mailbox_name); + EM_DEBUG_LOG_SEC("result_mailbox_name[%s]", result_mailbox_name); + if (result_mailbox_name == NULL) + result_mailbox_name = EM_SAFE_STRDUP(mutf7_text); + } + + EM_DEBUG_LOG_SEC("result_mailbox_name[%s]", result_mailbox_name); + + if (cd) + g_mime_iconv_close(cd); + + EM_SAFE_FREE(mutf7_text); + + EM_DEBUG_FUNC_END("result_mailbox_name[%p]", result_mailbox_name); + return result_mailbox_name; } /* in smtp case, path argument must be ENCODED_PATH_SMTP */ @@ -158,14 +254,9 @@ int emcore_get_long_encoded_path_with_account_info(email_account_t *account, cha if (account->incoming_server_secure_connection & 0x01) { strncat(p, "/ssl", long_enc_path_len-(EM_SAFE_STRLEN(p)+1)); /* strcat(p, "/tryssl"); */ - } - - /* Currently, receiving servers doesn't require tls. - if (account->incoming_server_secure_connection & 0x02) + } else if (account->incoming_server_secure_connection & 0x02) { strncat(p, "/tls", long_enc_path_len-(EM_SAFE_STRLEN(p)+1)); - else - strncat(p, "/notls", long_enc_path_len-(EM_SAFE_STRLEN(p)+1)); - */ + } authentication_method = account->incoming_server_authentication_method; @@ -238,7 +329,7 @@ int emcore_get_long_encoded_path_with_account_info(email_account_t *account, cha } if(*long_enc_path) - EM_DEBUG_LOG("long_enc_path [%s]", *long_enc_path); + EM_DEBUG_LOG_SEC("long_enc_path [%s]", *long_enc_path); ret = true; @@ -331,12 +422,12 @@ int emcore_get_encoded_mailbox_name(char *name, char **enc_name, int *err_code) ret_enc_name = strdup(name); goto FINISH_OFF; } - + EM_DEBUG_LOG_SEC("UTF-7 [%s](%d)->[%s](%d)",last_word, strlen(last_word), last_enc_word, strlen(last_enc_word)); /* if last word of mailbox name is UTF-8, replace it */ /* it is not a subfolder */ - if (!last_slash) { + if (!last_slash) { ret_enc_name = strdup(last_enc_word); } else { /* it is a subfolder */ @@ -481,9 +572,7 @@ INTERNAL_FUNC int emcore_check_drm_file(char *path, int *err_code) EM_DEBUG_FUNC_BEGIN("path[%s], err_code[%p]", path, err_code); int ret = false; - int drm_ret = false; int error = EMAIL_ERROR_NONE; - drm_bool_type_e isdrm; if (path == NULL) { EM_DEBUG_EXCEPTION("path[%p]", path); @@ -491,6 +580,9 @@ INTERNAL_FUNC int emcore_check_drm_file(char *path, int *err_code) goto FINISH_OFF; } +#ifdef __FEATURE_USE_DRM_API__ + int drm_ret = false; + drm_bool_type_e isdrm; drm_ret = drm_is_drm_file(path, &isdrm); if (drm_ret != DRM_RETURN_SUCCESS || isdrm != DRM_TRUE) { EM_DEBUG_LOG("file is not drm file"); @@ -499,6 +591,7 @@ INTERNAL_FUNC int emcore_check_drm_file(char *path, int *err_code) } ret = true; +#endif /* __FEATURE_USE_DRM_API__ */ FINISH_OFF: @@ -514,7 +607,6 @@ INTERNAL_FUNC int emcore_check_drm_is_ringtone(char *ringtone_path, int *err_cod EM_DEBUG_FUNC_BEGIN("ringtone_path[%s], err_code[%p]", ringtone_path, err_code); int ret = false; - int drm_ret = false; int error = EMAIL_ERROR_NONE; if (ringtone_path == NULL) { @@ -523,6 +615,8 @@ INTERNAL_FUNC int emcore_check_drm_is_ringtone(char *ringtone_path, int *err_cod goto FINISH_OFF; } +#ifdef __FEATURE_USE_DRM_API__ + int drm_ret = false; drm_bool_type_e allowed = DRM_UNKNOWN; drm_action_allowed_data_s data; memset(&data, 0x00, sizeof(drm_action_allowed_data_s)); @@ -539,6 +633,7 @@ INTERNAL_FUNC int emcore_check_drm_is_ringtone(char *ringtone_path, int *err_cod EM_DEBUG_LOG("allowed [DRM_TRUE]"); ret = true; +#endif /* __FEATURE_USE_DRM_API__ */ FINISH_OFF: @@ -640,25 +735,10 @@ INTERNAL_FUNC int emcore_get_empty_session(email_session_t **session) { EM_DEBUG_FUNC_BEGIN("session[%p]", session); - /* lock()... */ - - int i; + *session = &g_session; - for (i = 0; i < SESSION_MAX; i++) { - if (!g_session_list[i].status) { - memset(g_session_list+i, 0x00, sizeof(email_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; + return true; } INTERNAL_FUNC int emcore_clear_session(email_session_t *session) @@ -666,7 +746,8 @@ INTERNAL_FUNC int emcore_clear_session(email_session_t *session) EM_DEBUG_FUNC_BEGIN(); if (session) - memset(session, 0x00, sizeof(email_session_t)); + memset (session, 0x00, sizeof(email_session_t)); + EM_DEBUG_FUNC_END(); return true; } @@ -675,21 +756,10 @@ INTERNAL_FUNC int emcore_get_current_session(email_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; - } - } + *session = &g_session; - if (session) - *session = (i != SESSION_MAX) ? g_session_list + i : NULL; EM_DEBUG_FUNC_END(); - return (i != SESSION_MAX) ? true : false; + return true; } INTERNAL_FUNC int emcore_get_mail_count_by_query(int account_id, int mailbox_type, int priority_sender, int *total_mail, int *unread_mail, int *err_code) @@ -727,15 +797,16 @@ INTERNAL_FUNC int emcore_get_mail_count_by_query(int account_id, int mailbox_typ EM_DEBUG_LOG_DEV ("rule count [%d]", rule_count); /* Make query for searching unread mail */ - filter_count = 1; /* unseen field requires one filter, "flags_seen_field = 0" */ - + filter_count = 3; /* unseen field requires one filter, "flags_seen_field = 0" + and "deleted_flag = 0" */ + if (rule_count > 0 ) filter_count += (rule_count * 2) + 2; /* one rule requires two filters,"A" "OR", plus two more operator "(" and ")" */ if (account_id != ALL_ACCOUNT) { filter_count += 2; /* two filters, "AND" "account_id = x" */ - } + } if (mailbox_type) filter_count += 2; /* two filters, "AND" "mailbox_type = x" */ @@ -747,7 +818,7 @@ INTERNAL_FUNC int emcore_get_mail_count_by_query(int account_id, int mailbox_typ goto FINISH_OFF; } - int k = 0; + int k = 0; /* priority sender only, convert one rule to two filters which is composed of from_address and or/and */ /* example: ( from_A OR from_B ) AND ... */ @@ -755,7 +826,7 @@ INTERNAL_FUNC int emcore_get_mail_count_by_query(int account_id, int mailbox_typ /* first, add left parenthesis to from address clause, "(" */ filter_list[0].list_filter_item_type = EMAIL_LIST_FILTER_ITEM_OPERATOR; filter_list[0].list_filter_item.operator_type = EMAIL_LIST_FILTER_OPERATOR_LEFT_PARENTHESIS; - + for (i = 0; i < rule_count; i++) { /*array at odd index(1, 3, 5,..) has rule values, "from_A" */ k = i*2+1; @@ -771,7 +842,7 @@ INTERNAL_FUNC int emcore_get_mail_count_by_query(int account_id, int mailbox_typ } else { /* ")" "AND" */ filter_list[++k].list_filter_item_type = EMAIL_LIST_FILTER_ITEM_OPERATOR; - filter_list[k].list_filter_item.operator_type = EMAIL_LIST_FILTER_OPERATOR_RIGHT_PARENTHESIS; + filter_list[k].list_filter_item.operator_type = EMAIL_LIST_FILTER_OPERATOR_RIGHT_PARENTHESIS; filter_list[++k].list_filter_item_type = EMAIL_LIST_FILTER_ITEM_OPERATOR; filter_list[k].list_filter_item.operator_type = EMAIL_LIST_FILTER_OPERATOR_AND; @@ -781,11 +852,19 @@ INTERNAL_FUNC int emcore_get_mail_count_by_query(int account_id, int mailbox_typ } /*rule value, unseen +1*/ - filter_list[k].list_filter_item_type = EMAIL_LIST_FILTER_ITEM_RULE; - filter_list[k].list_filter_item.rule.rule_type = EMAIL_LIST_FILTER_RULE_EQUAL; - filter_list[k].list_filter_item.rule.target_attribute = EMAIL_MAIL_ATTRIBUTE_FLAGS_SEEN_FIELD; + filter_list[k].list_filter_item_type = EMAIL_LIST_FILTER_ITEM_RULE; + filter_list[k].list_filter_item.rule.rule_type = EMAIL_LIST_FILTER_RULE_EQUAL; + filter_list[k].list_filter_item.rule.target_attribute = EMAIL_MAIL_ATTRIBUTE_FLAGS_SEEN_FIELD; filter_list[k++].list_filter_item.rule.key_value.integer_type_value = 0; + filter_list[k].list_filter_item_type = EMAIL_LIST_FILTER_ITEM_OPERATOR; + filter_list[k++].list_filter_item.operator_type = EMAIL_LIST_FILTER_OPERATOR_AND; + + filter_list[k].list_filter_item_type = EMAIL_LIST_FILTER_ITEM_RULE; + filter_list[k].list_filter_item.rule.rule_type = EMAIL_LIST_FILTER_RULE_NOT_EQUAL; + filter_list[k].list_filter_item.rule.target_attribute = EMAIL_MAIL_ATTRIBUTE_SAVE_STATUS; + filter_list[k++].list_filter_item.rule.key_value.integer_type_value = EMAIL_MAIL_STATUS_SAVED_OFFLINE; + /*account_id requires two filters*/ if (account_id != ALL_ACCOUNT) { /* odd index, logical operator */ @@ -803,7 +882,7 @@ INTERNAL_FUNC int emcore_get_mail_count_by_query(int account_id, int mailbox_typ if (mailbox_type) { /* odd index, logical operator */ filter_list[k].list_filter_item_type = EMAIL_LIST_FILTER_ITEM_OPERATOR; - filter_list[k++].list_filter_item.operator_type = EMAIL_LIST_FILTER_OPERATOR_AND; + filter_list[k++].list_filter_item.operator_type = EMAIL_LIST_FILTER_OPERATOR_AND; /* even index, rule value */ filter_list[k].list_filter_item_type = EMAIL_LIST_FILTER_ITEM_RULE; @@ -858,7 +937,7 @@ INTERNAL_FUNC int emcore_display_badge_count(int count) badge_error_e badge_err = BADGE_ERROR_NONE; bool exist; - if((badge_err = badge_is_existing("com.samsung.email", &exist)) != BADGE_ERROR_NONE) { + if((badge_err = badge_is_existing("org.tizen.email", &exist)) != BADGE_ERROR_NONE) { EM_DEBUG_EXCEPTION("badge_is_existing failed [%d]", badge_err); err = EMAIL_ERROR_BADGE_API_FAILED; goto FINISH_OFF; @@ -866,17 +945,27 @@ INTERNAL_FUNC int emcore_display_badge_count(int count) if (!exist) { /* create badge */ - if((badge_err = badge_create("com.samsung.email", "/usr/bin/email-service")) != BADGE_ERROR_NONE) { + if((badge_err = badge_create("org.tizen.email", "/usr/bin/email-service")) != BADGE_ERROR_NONE) { EM_DEBUG_EXCEPTION("badge_create failed [%d]", badge_err); err = EMAIL_ERROR_BADGE_API_FAILED; goto FINISH_OFF; } } - if((badge_err = badge_set_count("com.samsung.email", count)) != BADGE_ERROR_NONE) { + if((badge_err = badge_set_count("org.tizen.email", count)) != BADGE_ERROR_NONE) { EM_DEBUG_EXCEPTION("badge_set_count failed [%d]", badge_err); - err = EMAIL_ERROR_BADGE_API_FAILED; - goto FINISH_OFF; + if (badge_err != BADGE_ERROR_SERVICE_NOT_READY) { + err = EMAIL_ERROR_BADGE_API_FAILED; + goto FINISH_OFF; + } + + /* Badge callback function : When the badge service ready, call the callback function */ + badge_err = badge_add_deferred_task(emcore_display_unread_in_badge, NULL); + if (badge_err != BADGE_ERROR_NONE) { + EM_DEBUG_EXCEPTION("badge_add_deferred_task failed : [%d]", badge_err); + err = EMAIL_ERROR_BADGE_API_FAILED; + goto FINISH_OFF; + } } FINISH_OFF: @@ -885,251 +974,38 @@ FINISH_OFF: return err; } -int emcore_display_unread_in_badge() +void emcore_display_unread_in_badge(void *data) { EM_DEBUG_FUNC_BEGIN(); - int ret = false; int err = EMAIL_ERROR_NONE; int total_unread_count = 0; int total_mail_count = 0; int unseen = 0; - int badge_status = false; - int general_noti_status = false; - int vip_noti_status = false; - int vip_mail_count = 0; - int vip_unread_count = 0; - int vip_notification_mode = 0; - - /* get general noti status */ - if (vconf_get_bool(VCONFKEY_SETAPPL_STATE_TICKER_NOTI_EMAIL_BOOL, &general_noti_status) != 0) { - EM_DEBUG_EXCEPTION("vconf_get_int failed"); - err = EMAIL_ERROR_SYSTEM_FAILURE; - goto FINISH_OFF; - } - - /* get vip noti status */ - if (vconf_get_bool(VCONF_VIP_NOTI_NOTIFICATION_TICKER, &vip_noti_status) != 0) { - EM_DEBUG_EXCEPTION("vconf_get_int failed"); - err = EMAIL_ERROR_SYSTEM_FAILURE; - goto FINISH_OFF; - } - - if (!general_noti_status && !vip_noti_status) { - EM_DEBUG_LOG("both notification disabled"); - ret = true; - goto FINISH_OFF; - } if (!emcore_get_mail_count_by_query(ALL_ACCOUNT, EMAIL_MAILBOX_TYPE_INBOX, 0, &total_mail_count, &total_unread_count, &err)) { EM_DEBUG_EXCEPTION("emcore_get_mail_count_by_query failed"); goto FINISH_OFF; } - if (vip_noti_status) { - if (!emcore_get_mail_count_by_query(ALL_ACCOUNT, EMAIL_MAILBOX_TYPE_INBOX, true, &vip_mail_count, &vip_unread_count, &err)) { - EM_DEBUG_EXCEPTION("emcore_get_mail_count_by_query failed"); - goto FINISH_OFF; - } - } + unseen = total_unread_count; - if (general_noti_status && !vip_noti_status) { - EM_DEBUG_LOG("GERNERAL NOTI MODE"); - vip_notification_mode = 0; - unseen = total_unread_count; - } else if (!general_noti_status && vip_noti_status) { - EM_DEBUG_LOG("VIP NOTI MODE"); - if (err == EMAIL_ERROR_FILTER_NOT_FOUND) { - EM_DEBUG_LOG("VIP filter not found"); - ret = true; - goto FINISH_OFF; - } else { - unseen = vip_unread_count; - } - vip_notification_mode = 1; - } else if (general_noti_status && vip_noti_status) { - if (err == EMAIL_ERROR_FILTER_NOT_FOUND) { - EM_DEBUG_LOG("VIP filter not found"); - EM_DEBUG_LOG("GERNERAL NOTI MODE"); - vip_notification_mode = 0; - unseen = total_unread_count; - } else { - EM_DEBUG_LOG("VIP NOTI MODE"); - vip_notification_mode = 1; - unseen = vip_unread_count; - } - } +FINISH_OFF: - if (vip_notification_mode) { - if (vconf_get_bool(VCONF_VIP_NOTI_BADGE_TICKER, &badge_status) != 0) { - EM_DEBUG_EXCEPTION("vconf_get_bool failed"); - err = EMAIL_ERROR_GCONF_FAILURE; - goto FINISH_OFF; + if (unseen <= 0) { + if ((err = emcore_display_badge_count(0)) != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emcore_display_badge_count failed : [%d]", err); } } else { - if (vconf_get_bool(VCONFKEY_TICKER_NOTI_BADGE_EMAIL, &badge_status) != 0) { - EM_DEBUG_EXCEPTION("vconf_get_bool failed"); - err = EMAIL_ERROR_GCONF_FAILURE; - goto FINISH_OFF; + if ((err = emcore_display_badge_count(unseen)) != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emcore_display_badge_count failed : [%d]", err); } } - if (!badge_status) { - EM_DEBUG_LOG("badge setting OFF"); - ret = true; - goto FINISH_OFF; - } - - if (unseen < 0) - goto FINISH_OFF; - - if ((err = emcore_display_badge_count(unseen)) != EMAIL_ERROR_NONE) { - EM_DEBUG_EXCEPTION("emcore_display_badge_count failed : [%d]", err); - goto FINISH_OFF; - } - - ret = true; - -FINISH_OFF: - EM_DEBUG_FUNC_END(); - return ret; } -static int emcore_layout_multi_noti(notification_h noti, int unread_mail, char *email_address, char *account_name) -{ - EM_DEBUG_FUNC_BEGIN("unread_count %d", unread_mail); - notification_error_e noti_err = NOTIFICATION_ERROR_NONE; - - noti_err = notification_set_layout(noti, NOTIFICATION_LY_NOTI_EVENT_MULTIPLE); - if (noti_err != NOTIFICATION_ERROR_NONE) { - EM_DEBUG_EXCEPTION("notification_set_layout NOTI_EVENT_SINGLE failed [%d]", noti_err); - goto FINISH_OFF; - } - - noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE, "Email", "IDS_EMAIL_OPT_EMAIL", NOTIFICATION_VARIABLE_TYPE_NONE); - if (noti_err != NOTIFICATION_ERROR_NONE) { - EM_DEBUG_EXCEPTION("notification_set_text TEXT_TYPE_TITLE failed"); - goto FINISH_OFF; - } - - noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT, "New email received", "IDS_EMAIL_BODY_PD_NEW_EMAILS_RECEIVED", NOTIFICATION_VARIABLE_TYPE_INT, unread_mail, NOTIFICATION_VARIABLE_TYPE_NONE); - if (noti_err != NOTIFICATION_ERROR_NONE) { - EM_DEBUG_EXCEPTION("notification_set_text TEXT_TYPE_CONTENT failed"); - goto FINISH_OFF; - } - - noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_INFO_1, email_address, NULL, NOTIFICATION_VARIABLE_TYPE_NONE); - if (noti_err != NOTIFICATION_ERROR_NONE) { - EM_DEBUG_EXCEPTION("notification_set_text TEXT_TYPE_INFO_1 failed"); - goto FINISH_OFF; - } - - noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_INFO_2, account_name, NULL, NOTIFICATION_VARIABLE_TYPE_NONE); - if (noti_err != NOTIFICATION_ERROR_NONE) { - EM_DEBUG_EXCEPTION("notification_set_text TEXT_TYPE_INFO_2 failed"); - goto FINISH_OFF; - } - - noti_err = notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON, EMAIL_NOTI_ICON_PATH); - if (noti_err != NOTIFICATION_ERROR_NONE) { - EM_DEBUG_EXCEPTION("notification_set_image TYPE_ICON failed"); - goto FINISH_OFF; - } - - noti_err = notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON_FOR_INDICATOR, EMAIL_NOTI_ICON_PATH); - if (noti_err != NOTIFICATION_ERROR_NONE) { - EM_DEBUG_EXCEPTION("notification_set_image TYPE_ICON failed"); - goto FINISH_OFF; - } - - noti_err = notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON_FOR_LOCK, EMAIL_NOTI_ICON_PATH); - if (noti_err != NOTIFICATION_ERROR_NONE) { - EM_DEBUG_EXCEPTION("notification_set_image TYPE_ICON failed"); - goto FINISH_OFF; - } - -FINISH_OFF: - - EM_DEBUG_FUNC_END("noti_err : [%d]", noti_err); - return noti_err; -} - -static int emcore_layout_single_noti(notification_h noti, char *account_name, int ids, char *display_sender, time_t time, char *subject) -{ - EM_DEBUG_FUNC_BEGIN(); - notification_error_e noti_err = NOTIFICATION_ERROR_NONE; - - noti_err = notification_set_layout(noti, NOTIFICATION_LY_NOTI_EVENT_SINGLE); - if (noti_err != NOTIFICATION_ERROR_NONE) { - EM_DEBUG_EXCEPTION("notification_set_layout NOTI_EVENT_SINGLE failed [%d]", noti_err); - goto FINISH_OFF; - } - - if (ids) - noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE, "Email", "IDS_COM_BODY_EMAIL", NOTIFICATION_VARIABLE_TYPE_NONE); - else - noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE, "Email", "IDS_EMAIL_OPT_EMAIL", NOTIFICATION_VARIABLE_TYPE_NONE); - - if (noti_err != NOTIFICATION_ERROR_NONE) { - EM_DEBUG_EXCEPTION("notification_set_text TEXT_TYPE_TITLE failed"); - goto FINISH_OFF; - } - - noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT, account_name, NULL, NOTIFICATION_VARIABLE_TYPE_NONE); - if (noti_err != NOTIFICATION_ERROR_NONE) { - EM_DEBUG_EXCEPTION("notification_set_text TEXT_TYPE_CONTENT failed"); - goto FINISH_OFF; - } - - if (ids) - noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_INFO_1, NULL, display_sender, NOTIFICATION_VARIABLE_TYPE_NONE); - else - noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_INFO_1, display_sender, NULL, NOTIFICATION_VARIABLE_TYPE_NONE); - - if (noti_err != NOTIFICATION_ERROR_NONE) { - EM_DEBUG_EXCEPTION("notification_set_text TEXT_TYPE_INFO_1 failed"); - goto FINISH_OFF; - } - - /* - noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_INFO_SUB_1, time, NULL, NOTIFICATION_VARIABLE_TYPE_NONE); - if (noti_err != NOTIFICATION_ERROR_NONE) { - EM_DEBUG_EXCEPTION("notification_set_text TEXT_TYPE_INFO_SUB_1 failed"); - goto FINISH_OFF; - } - */ - - noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_INFO_2, subject, NULL, NOTIFICATION_VARIABLE_TYPE_NONE); - if (noti_err != NOTIFICATION_ERROR_NONE) { - EM_DEBUG_EXCEPTION("notification_set_text TEXT_TYPE_INFO_2 failed"); - goto FINISH_OFF; - } - - noti_err = notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON, EMAIL_NOTI_ICON_PATH); - if (noti_err != NOTIFICATION_ERROR_NONE) { - EM_DEBUG_EXCEPTION("notification_set_image TYPE_ICON failed"); - goto FINISH_OFF; - } - - noti_err = notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON_FOR_INDICATOR, EMAIL_NOTI_ICON_PATH); - if (noti_err != NOTIFICATION_ERROR_NONE) { - EM_DEBUG_EXCEPTION("notification_set_image TYPE_ICON failed"); - goto FINISH_OFF; - } - - noti_err = notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON_FOR_LOCK, EMAIL_NOTI_ICON_PATH); - if (noti_err != NOTIFICATION_ERROR_NONE) { - EM_DEBUG_EXCEPTION("notification_set_image TYPE_ICON failed"); - goto FINISH_OFF; - } -FINISH_OFF: - - EM_DEBUG_FUNC_END("noti_err : [%d]", noti_err); - return noti_err; -} - -INTERNAL_FUNC int emcore_add_notification(int account_id, int mail_id, int unread_mail_count, int input_play_alert_tone, int sending_error, unsigned long display) +INTERNAL_FUNC int emcore_add_notification(int account_id, int mail_id, int unread_mail_count, int vip_unread_mail_count, int input_play_alert_tone, int sending_error, unsigned long display) { EM_DEBUG_FUNC_BEGIN("account_id[%d] mail_id[%d] unread_mail_count[%d] input_play_alert_tone[%d]", account_id, mail_id, unread_mail_count, input_play_alert_tone ); int err = EMAIL_ERROR_NONE; @@ -1190,6 +1066,7 @@ INTERNAL_FUNC int emcore_show_user_message(int id, email_action_t action, int er return false; } + EM_DEBUG_LOG ("smtp_stream : sent_end"); if (emcore_add_notification_for_send(mail_table_data->account_id, id, action, error, display) != EMAIL_ERROR_NONE) { EM_DEBUG_EXCEPTION("emcore_notification_set error"); goto FINISH_OFF; @@ -1228,36 +1105,33 @@ int emcore_get_storage_status(void) return storage_status; } -INTERNAL_FUNC int emcore_is_storage_full(int *err_code) + + +INTERNAL_FUNC int emcore_is_storage_full() { EM_DEBUG_FUNC_BEGIN(); - - int ret = false; int err = EMAIL_ERROR_NONE; - struct statfs buf = {0}; + int ret_from_storage_lib = 0; + struct statvfs stat_result; - if (statfs(DATA_PATH, &buf) == -1) { - EM_DEBUG_EXCEPTION("statfs(\"%s\") failed - %d", DATA_PATH, errno); + ret_from_storage_lib = storage_get_internal_memory_size(&stat_result); + if (ret_from_storage_lib < 0) { + EM_DEBUG_EXCEPTION("ret_from_storage_lib [%d]", ret_from_storage_lib); err = EMAIL_ERROR_SYSTEM_FAILURE; goto FINISH_OFF; } - else { - long i_free = (buf.f_bavail * buf.f_bsize) / (1024 * 1024); - EM_DEBUG_LOG_DEV("f_bavail[%d] f_bsize[%d]", buf.f_bavail, buf.f_bsize); + else { + unsigned long i_free = (stat_result.f_bsize*stat_result.f_bavail) / (1024 * 1024); if (i_free < EMAIL_LIMITATION_FREE_SPACE) { + EM_DEBUG_EXCEPTION("total[%lf] avail[%lf]", (double)stat_result.f_frsize*stat_result.f_blocks, (double)stat_result.f_bsize*stat_result.f_bavail); EM_DEBUG_EXCEPTION("Not enough free space of storage [%ld] MB.", i_free); err = EMAIL_ERROR_MAIL_MEMORY_FULL; } } - if (err == EMAIL_ERROR_MAIL_MEMORY_FULL) - ret = true; - FINISH_OFF: - if (err_code != NULL) - *err_code = err; - EM_DEBUG_FUNC_END("ret[%d]", ret); - return ret; + EM_DEBUG_FUNC_END("err[%d]", err); + return err; } int emcore_calc_mail_size(email_mail_data_t *input_mail_data, email_attachment_data_t *input_attachment_data_list, int input_attachment_count, int *output_size) @@ -1325,12 +1199,14 @@ char *emcore_get_alias_of_mailbox(const char *mailbox_path) gchar *mailbox = NULL, *name = NULL; char *converted_name; - mailbox = g_strdup(mailbox_path); token_list = g_strsplit_set(mailbox, "/", -1); if(token_list == NULL) { EM_DEBUG_LOG("g_strsplit_set failed."); + if (mailbox) + g_free(mailbox); + return NULL; } @@ -1341,12 +1217,22 @@ char *emcore_get_alias_of_mailbox(const char *mailbox_path) index++; name = g_strdup(token_list[index - 1]); - if(!name) /* prevent 27459 */ + if (!name) /* prevent 27459 */ { + if (mailbox) + g_free(mailbox); + return NULL; + } g_strfreev(token_list); converted_name = emcore_convert_mutf7_to_utf8(name); + EM_DEBUG_LOG_DEV("converted_name:%s", converted_name); + + if (!converted_name || EM_SAFE_STRLEN(converted_name) == 0) { + EM_SAFE_FREE(converted_name); + converted_name = g_strdup(name); + } if (name) g_free(name); @@ -1356,67 +1242,50 @@ char *emcore_get_alias_of_mailbox(const char *mailbox_path) } -static int emcore_get_first_address(const char *full_address, char **alias, char **address) +INTERNAL_FUNC int emcore_get_first_address(const char *input_full_address, char **output_display_name, char **output_angle_addr) { - EM_DEBUG_FUNC_BEGIN(); + EM_DEBUG_FUNC_BEGIN("input_full_address[%p], output_display_name[%p], output_angle_addr[%p]", input_full_address, output_display_name, output_angle_addr); - 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; + int err = EMAIL_ERROR_NONE; + char *full_address = NULL; + char angle_addr[MAX_EMAIL_ADDRESS_LENGTH] = { 0, }; + ADDRESS *address_list = NULL; + + if (input_full_address == NULL || output_display_name == NULL || output_angle_addr == NULL) { + err = EMAIL_ERROR_INVALID_PARAM; + EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM"); + goto FINISH_OFF; } - 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; + /* full_address will be tainted by rfc822_parse_adrlist */ + /* So, input_full_address should be duplicated */ + full_address = EM_SAFE_STRDUP(input_full_address); - 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); - } - } + if (full_address == NULL) { + err = EMAIL_ERROR_OUT_OF_MEMORY; + EM_DEBUG_EXCEPTION("EMAIL_ERROR_OUT_OF_MEMORY"); + goto FINISH_OFF; + } - /* 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 */ + rfc822_parse_adrlist(&address_list, (char*)full_address, NULL); + + if (address_list) { + if (address_list->host) + SNPRINTF(angle_addr, MAX_EMAIL_ADDRESS_LENGTH, "%s@%s", address_list->mailbox, address_list->host); + else /* For SMS of eas-engine : (example : 01012345678) */ + SNPRINTF(angle_addr, MAX_EMAIL_ADDRESS_LENGTH, "%s", address_list->mailbox); + + *output_display_name = EM_SAFE_STRDUP(address_list->personal); + *output_angle_addr = EM_SAFE_STRDUP(angle_addr); + + mail_free_address(&address_list); } - EM_SAFE_FREE(first_address); +FINISH_OFF: + EM_SAFE_FREE(full_address); + EM_DEBUG_FUNC_END(); - return true; + return err; } void emcore_fill_address_information_of_mail_tbl(emstorage_mail_tbl_t *mail_data) @@ -1439,6 +1308,8 @@ void emcore_fill_address_information_of_mail_tbl(emstorage_mail_tbl_t *mail_data EM_DEBUG_LOG("emcore_get_account_reference failed [%d]", mail_data->account_id); } + EM_DEBUG_LOG_SEC("full_address_from [%s]", mail_data->full_address_from); + /* sender alias & address */ if (emcore_get_first_address(mail_data->full_address_from, &first_alias, &first_address) == true) { if (first_alias == NULL) { @@ -1452,6 +1323,8 @@ void emcore_fill_address_information_of_mail_tbl(emstorage_mail_tbl_t *mail_data first_address = NULL; } + EM_DEBUG_LOG_SEC("full_address_from [%s]", mail_data->full_address_from); + /* recipient alias & address */ if (mail_data->full_address_to != NULL) recipient = mail_data->full_address_to; @@ -1634,7 +1507,6 @@ int emcore_strip_mail_body_from_file(emstorage_mail_tbl_t *mail, char **stripped unsigned int byte_read = 0; unsigned int byte_written = 0; GError *glib_error = NULL; - FILE *fp_html = NULL; FILE *fp_plain = NULL; struct stat st_buf; @@ -1644,58 +1516,28 @@ int emcore_strip_mail_body_from_file(emstorage_mail_tbl_t *mail, char **stripped goto FINISH_OFF; } + /* MAX_PREVIEW_TEXT_LENGTH */ + /* read file to buf & strip if html text */ if (mail->file_path_html) { + char result_buffer[MAX_PREVIEW_TEXT_LENGTH] = { 0, }; if (mail->preview_text) { *stripped_text = EM_SAFE_STRDUP(mail->preview_text); ret = true; goto FINISH_OFF; } - if((err = em_get_encoding_type_from_file_path(mail->file_path_html, &encoding_type)) != EMAIL_ERROR_NONE) { + if ((err = em_get_encoding_type_from_file_path(mail->file_path_plain, &encoding_type)) != EMAIL_ERROR_NONE) { EM_DEBUG_EXCEPTION("em_get_encoding_type_from_file_path failed [%d]", err); goto FINISH_OFF; } - if (stat(mail->file_path_html, &st_buf) < 0) { - EM_DEBUG_EXCEPTION_SEC("stat(\"%s\") failed...", mail->file_path_html); - err = EMAIL_ERROR_FILE_NOT_FOUND; - goto FINISH_OFF; - } - - if (!(fp_html = fopen(mail->file_path_html, "r"))) { - EM_DEBUG_EXCEPTION_SEC("fopen failed [%s]", mail->file_path_html); - err = EMAIL_ERROR_SYSTEM_FAILURE; - goto FINISH_OFF; - } - - if (S_ISREG(st_buf.st_mode) && st_buf.st_size == 0) { - EM_DEBUG_LOG("html_file is empty size"); - err = EMAIL_ERROR_EMPTY_FILE; - goto FINISH_OFF; - } - - if (!(buf = (char*)em_malloc(sizeof(char)*(st_buf.st_size + 1)))) { - EM_DEBUG_EXCEPTION("em_malloc failed"); - err = EMAIL_ERROR_OUT_OF_MEMORY; + if ((err = emcore_strip_HTML_tag(mail->file_path_html, encoding_type, result_buffer, MAX_PREVIEW_TEXT_LENGTH)) != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emcore_strip_HTML_tag failed"); goto FINISH_OFF; } - byte_read = fread(buf, sizeof(char), st_buf.st_size, fp_html); - - if (byte_read <= 0) { - EM_SAFE_FREE(buf); - if (ferror(fp_html)) { - EM_DEBUG_EXCEPTION_SEC("fread failed [%s]", mail->file_path_html); - err = EMAIL_ERROR_SYSTEM_FAILURE; - goto FINISH_OFF; - } - } else { - if ((err = emcore_strip_HTML(&buf)) != EMAIL_ERROR_NONE) { - EM_DEBUG_EXCEPTION("emcore_strip failed"); - goto FINISH_OFF; - } - } + *stripped_text = EM_SAFE_STRDUP(result_buffer); } if (!buf && mail->file_path_plain) { @@ -1711,9 +1553,9 @@ int emcore_strip_mail_body_from_file(emstorage_mail_tbl_t *mail, char **stripped goto FINISH_OFF; } - if (!(fp_plain = fopen(mail->file_path_plain, "r"))) { - EM_DEBUG_EXCEPTION_SEC("fopen failed [%s]", mail->file_path_plain); - err = EMAIL_ERROR_SYSTEM_FAILURE; + err = em_fopen(mail->file_path_plain, "r", &fp_plain); + if (err != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION_SEC("em_fopen failed [%s]", mail->file_path_plain); goto FINISH_OFF; } @@ -1775,6 +1617,7 @@ int emcore_strip_mail_body_from_file(emstorage_mail_tbl_t *mail, char **stripped *stripped_text = EM_SAFE_STRDUP(utf8_encoded_string); } else { + EM_SAFE_FREE(*stripped_text); *stripped_text = EM_SAFE_STRDUP(buf); } } @@ -1790,9 +1633,6 @@ FINISH_OFF: EM_SAFE_FREE(encoding_type); EM_SAFE_FREE(utf8_encoded_string); - if (fp_html != NULL) - fclose(fp_html); - if (fp_plain != NULL) fclose(fp_plain); @@ -1813,7 +1653,6 @@ int emcore_get_preview_text_from_file(const char *input_plain_path, const char * char *local_preview_text = NULL; char *encoding_type = NULL; char *utf8_encoded_string = NULL; - FILE *fp_html = NULL; FILE *fp_plain = NULL; GError *glib_error = NULL; struct stat st_buf; @@ -1828,51 +1667,18 @@ int emcore_get_preview_text_from_file(const char *input_plain_path, const char * if ( input_html_path ) { /*prevent 26249*/ /* get preview text from html file */ + char result_buffer[MAX_PREVIEW_TEXT_LENGTH] = { 0, }; + if( (err = em_get_encoding_type_from_file_path(input_html_path, &encoding_type)) != EMAIL_ERROR_NONE) { EM_DEBUG_EXCEPTION("em_get_encoding_type_from_file_path failed [%d]", err); goto FINISH_OFF; } - if (stat(input_html_path, &st_buf) < 0) { - EM_DEBUG_EXCEPTION("stat(\"%s\") failed...", input_html_path); - err = EMAIL_ERROR_FILE_NOT_FOUND; - goto FINISH_OFF; - } - - if (!(fp_html = fopen(input_html_path, "r"))) { - EM_DEBUG_EXCEPTION("fopen failed [%s]", input_html_path); - err = EMAIL_ERROR_SYSTEM_FAILURE; - goto FINISH_OFF; - } - - if (S_ISREG(st_buf.st_mode) && st_buf.st_size == 0) { - EM_DEBUG_LOG("input_html_file is empty size"); - err = EMAIL_ERROR_EMPTY_FILE; + if ((err = emcore_strip_HTML_tag(input_html_path, encoding_type, result_buffer, MAX_PREVIEW_TEXT_LENGTH)) != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emcore_strip_HTML_tag failed"); goto FINISH_OFF; } - - if (!(local_preview_text = (char*)em_malloc(sizeof(char) * (st_buf.st_size + 1)))) { - EM_DEBUG_EXCEPTION("em_malloc failed"); - err = EMAIL_ERROR_OUT_OF_MEMORY; - goto FINISH_OFF; - } - - byte_read = fread(local_preview_text, sizeof(char), st_buf.st_size, fp_html); - - if(byte_read <= 0) { /*prevent 26249*/ - EM_SAFE_FREE(local_preview_text); - if (ferror(fp_html)) { - EM_DEBUG_EXCEPTION("fread failed [%s]", input_html_path); - err = EMAIL_ERROR_SYSTEM_FAILURE; - goto FINISH_OFF; - } - } - else { - if ( (err = emcore_strip_HTML(&local_preview_text)) != EMAIL_ERROR_NONE) { - EM_DEBUG_EXCEPTION("emcore_strip failed"); - goto FINISH_OFF; - } - } + local_preview_text = EM_SAFE_STRDUP(result_buffer); } if ( !local_preview_text && input_plain_path) { /*prevent 26249*/ @@ -1889,9 +1695,9 @@ int emcore_get_preview_text_from_file(const char *input_plain_path, const char * goto FINISH_OFF; } - if (!(fp_plain = fopen(input_plain_path, "r"))) { - EM_DEBUG_EXCEPTION("fopen failed [%s]", input_plain_path); - err = EMAIL_ERROR_SYSTEM_FAILURE; + err = em_fopen(input_plain_path, "r", &fp_plain); + if (err != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("em_fopen failed [%s]", input_plain_path); goto FINISH_OFF; } @@ -1920,10 +1726,9 @@ int emcore_get_preview_text_from_file(const char *input_plain_path, const char * reg_replace(local_preview_text, CR_STRING, " "); reg_replace(local_preview_text, LF_STRING, " "); reg_replace(local_preview_text, TAB_STRING, " "); - } - if(local_preview_text) { em_trim_left(local_preview_text); + if(encoding_type && strcasecmp(encoding_type, "UTF-8") != 0) { EM_DEBUG_LOG("encoding_type [%s]", encoding_type); @@ -1944,6 +1749,7 @@ int emcore_get_preview_text_from_file(const char *input_plain_path, const char * utf8_encoded_string = (char *)g_convert(local_preview_text, byte_read, "UTF-8", encoding_type, &byte_read, &byte_written, &glib_error); if (utf8_encoded_string == NULL) { + EM_DEBUG_LOG("g_convert fail, again"); goto FINISH_OFF; } } @@ -1965,9 +1771,6 @@ FINISH_OFF: EM_SAFE_FREE(local_preview_text); EM_SAFE_FREE(encoding_type); - if (fp_html != NULL) - fclose(fp_html); - if (fp_plain != NULL) fclose(fp_plain); @@ -2086,7 +1889,7 @@ INTERNAL_FUNC int emcore_delete_transaction_info_by_mailId(int mail_id ) #include <regex.h> -int reg_replace (char *input_source_text, char *input_old_pattern_string, char *input_new_string) +INTERNAL_FUNC int reg_replace (char *input_source_text, char *input_old_pattern_string, char *input_new_string) { int error_code = EMAIL_ERROR_NONE; char *pos = NULL; @@ -2162,14 +1965,18 @@ FINISH_OFF: } -int reg_replace_new (char **input_source_text, char *input_old_pattern_string, char *input_new_string) +INTERNAL_FUNC int reg_replace_new (char **input_source_text, char *input_old_pattern_string, char *input_new_string) { char *replaced_str = NULL; int error_code = EMAIL_ERROR_NONE; GRegex *regex = NULL; GError *error = NULL; - regex = g_regex_new(input_old_pattern_string, G_REGEX_RAW | G_REGEX_OPTIMIZE | G_REGEX_CASELESS, 0, &error); + if (input_source_text == NULL || *input_source_text == NULL) { + return EMAIL_ERROR_INVALID_PARAM; + } + + regex = g_regex_new(input_old_pattern_string, G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, &error); if (!regex) { EM_DEBUG_LOG("g_regex_new failed"); @@ -2177,7 +1984,7 @@ int reg_replace_new (char **input_source_text, char *input_old_pattern_string, c goto FINISH_OFF; } - replaced_str = g_regex_replace_literal(regex, *input_source_text, strlen(*input_source_text), 0, input_new_string, 0, &error); + replaced_str = g_regex_replace_literal(regex, *input_source_text, EM_SAFE_STRLEN(*input_source_text), 0, input_new_string, 0, &error); EM_SAFE_FREE(*input_source_text); @@ -2190,50 +1997,127 @@ FINISH_OFF: } -int emcore_strip_HTML(char **source_string) +#include <libxml/HTMLparser.h> + +static void emcore_get_content_string(xmlNode *input_node, char *input_result_buffer, int input_result_buffer_legnth, int *input_exit_flag) { - EM_DEBUG_FUNC_BEGIN("source_string [%p]", source_string); + xmlNode *cur_node = NULL; + char *temp_content_string = NULL; + + if (input_node == NULL || input_result_buffer == NULL || input_exit_flag == NULL) { + EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM"); + goto FINISH_OFF; + } + + for (cur_node = input_node; cur_node; cur_node = cur_node->next) { + if (cur_node->name && (strcasecmp((const char *)cur_node->name, "head") == 0 || strcasecmp((const char *)cur_node->name, "title") == 0)) + continue; + + if (cur_node->type == XML_TEXT_NODE && cur_node->content) { + if ((EM_SAFE_STRLEN(cur_node->content) + EM_SAFE_STRLEN(input_result_buffer)) >= input_result_buffer_legnth) { + int len1 = EM_SAFE_STRLEN(input_result_buffer); + + if (len1 >= 0 && len1 < input_result_buffer_legnth) { + int remain_size = input_result_buffer_legnth - len1 - 2; + char *remain_str = em_malloc(remain_size); + if (remain_str && cur_node->content) { + snprintf(remain_str, remain_size, "%s", (char*)(cur_node->content)); + } - int result = EMAIL_ERROR_NONE; + if (remain_str) + EM_SAFE_STRCAT(input_result_buffer, remain_str); - /* strip out CR, LF */ - reg_replace_new(source_string, "(\r|\n)", ""); + EM_SAFE_FREE(remain_str); + } - /* strip out HEAD */ - reg_replace_new(source_string, "<head[^>]*>.*<*/head>", ""); + *input_exit_flag = 1; + break; + } + temp_content_string = EM_SAFE_STRDUP((const char *)cur_node->content); + if (temp_content_string) { + reg_replace_new(&temp_content_string, "[ \t\r\n\v\f]+", " "); + EM_SAFE_STRCAT(input_result_buffer, temp_content_string); + EM_SAFE_FREE(temp_content_string); + } + } - /* strip out STYLE */ - reg_replace_new(source_string, "<style[^>]*>.*<*/style>", ""); + if (cur_node->children) + emcore_get_content_string(cur_node->children, input_result_buffer, input_result_buffer_legnth, input_exit_flag); - /* strip out SCRIPT */ - reg_replace_new(source_string, "<script[^>]*>.*<*/script>", ""); + if (*input_exit_flag == 1) + break; + } +FINISH_OFF: + return; +} - /* strip out ALL TAG & comment */ - reg_replace_new(source_string, "<[^>]*>", ""); +static void emcore_default_xml_error_handler(void *ctx, const char *msg, ...) { + EM_DEBUG_EXCEPTION("htmlReadFile failed"); +} - /* for remaining comment in some cases */ - reg_replace_new(source_string, "-->", ""); +int emcore_strip_HTML_tag(const char *input_html_file_path, char *input_encoding_type, char *output_result_buffer, int input_result_buffer_legnth) +{ + EM_DEBUG_FUNC_BEGIN("input_html_file_path[%p] input_encoding_type[%s] output_result_buffer[%p] input_result_buffer_legnth[%d]", input_html_file_path, input_encoding_type, output_result_buffer, input_result_buffer_legnth); + int err = EMAIL_ERROR_NONE; + int exit_flag = 0; + char *result_string = NULL; + xmlNode *root_element = NULL; + htmlDocPtr result_html_document = NULL; + char *encoding_type = NULL; + char *utf_charset = "UTF-8"; + char *euc_kr_charset = "euc-kr"; - /* strip out html entities */ - reg_replace_new(source_string, "&(quot|#34|#034);", "\""); - reg_replace_new(source_string, "&(#35|#035);", "#"); - reg_replace_new(source_string, "&(#36|#036);", "$"); - reg_replace_new(source_string, "&(#37|#037);", "%"); - reg_replace_new(source_string, "&(amp|#38|#038);", "&"); - reg_replace_new(source_string, "&(lt|#60|#060);", "<"); - reg_replace_new(source_string, "&(gt|#62|#062);", ">"); - reg_replace_new(source_string, "&(#64|#064);", "@"); - reg_replace_new(source_string, "&(lsquo|rsquo);", "'"); - reg_replace_new(source_string, "&(ldquo|rdquo);", "\""); - reg_replace_new(source_string, "‚", ","); - reg_replace_new(source_string, "&(trade|#x2122);", "(TM)"); + if (input_html_file_path == NULL || output_result_buffer == NULL || input_result_buffer_legnth == 0) { + EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM"); + err = EMAIL_ERROR_INVALID_PARAM; + goto FINISH_OFF; + } - /* strip out all type of spaces */ - reg_replace_new(source_string, "&(nbsp|#160);", " "); - reg_replace_new(source_string, " +", " "); + result_string = em_malloc(sizeof(char) * input_result_buffer_legnth); - EM_DEBUG_FUNC_END(); - return result; + if (result_string == NULL) { + EM_DEBUG_EXCEPTION("EMAIL_ERROR_OUT_OF_MEMORY"); + err = EMAIL_ERROR_OUT_OF_MEMORY; + goto FINISH_OFF; + } + + if (EM_SAFE_STRCMP(input_encoding_type, "unknown") == 0) + encoding_type = utf_charset; + else if (input_encoding_type && (strcasecmp(input_encoding_type, "ks_c_5601-1987") == 0 || + strcasecmp(input_encoding_type, "ksc5601") == 0 || + strcasecmp(input_encoding_type, "cp949") == 0)) + encoding_type = euc_kr_charset; + else + encoding_type = input_encoding_type; + + EM_DEBUG_LOG("encoding_type [%s]", encoding_type); + + LIBXML_TEST_VERSION + xmlSetGenericErrorFunc(NULL, emcore_default_xml_error_handler); + result_html_document = htmlReadFile(input_html_file_path, encoding_type, HTML_PARSE_RECOVER | HTML_PARSE_NOWARNING | HTML_PARSE_NOERROR | HTML_PARSE_NONET | HTML_PARSE_NOBLANKS); + if (result_html_document == NULL) { + EM_DEBUG_EXCEPTION("htmlReadFile failed"); + err = EMAIL_ERROR_ON_PARSING; + goto FINISH_OFF; + } + + root_element = xmlDocGetRootElement(result_html_document); + + + emcore_get_content_string(root_element, result_string, input_result_buffer_legnth, &exit_flag); + reg_replace_new(&result_string, "[ \t\r\n\v\f]+", " "); + EM_SAFE_STRCPY(output_result_buffer, result_string); + // em_trim_left(output_result_buffer); + +FINISH_OFF: + if (result_html_document) { + xmlFreeDoc(result_html_document); + } + + EM_SAFE_FREE(result_string); + + EM_DEBUG_FUNC_END("err [%d]", err); + return err; } INTERNAL_FUNC int emcore_send_noti_for_new_mail(int account_id, char *mailbox_name, char *subject, char *from, char *uid, char *datetime) @@ -2271,7 +2155,7 @@ INTERNAL_FUNC int emcore_send_noti_for_new_mail(int account_id, char *mailbox_na FINISH_OFF: EM_SAFE_FREE(param_string); - EM_DEBUG_FUNC_END(); + EM_DEBUG_FUNC_END(); return error_code; } @@ -2283,13 +2167,13 @@ int convert_app_err_to_email_err(int app_error) int err = EMAIL_ERROR_NONE; switch(app_error) { - case SERVICE_ERROR_NONE : + case APP_CONTROL_ERROR_NONE : err = EMAIL_ERROR_NONE; break; - case SERVICE_ERROR_INVALID_PARAMETER : + case APP_CONTROL_ERROR_INVALID_PARAMETER : err = EMAIL_ERROR_INVALID_PARAM; break; - case SERVICE_ERROR_OUT_OF_MEMORY : + case APP_CONTROL_ERROR_OUT_OF_MEMORY : err = EMAIL_ERROR_OUT_OF_MEMORY; break; default: @@ -2300,14 +2184,15 @@ int convert_app_err_to_email_err(int app_error) return err; } -INTERNAL_FUNC int emcore_start_driving_mode(int account_id) +INTERNAL_FUNC int emcore_start_driving_mode(int mail_id) { EM_DEBUG_FUNC_BEGIN(); - - int err = SERVICE_ERROR_NONE; - int tts_enable = 0; - char string_account[10] = { 0 }; - service_h service = NULL; + + int err = APP_CONTROL_ERROR_NONE; + int tts_enable = 0; + char string_mail[10] = { 0 }; + emstorage_mail_tbl_t *p_mail_data = NULL; + app_control_h service = NULL; if (vconf_get_bool(VCONFKEY_SETAPPL_DRIVINGMODE_DRIVINGMODE, &tts_enable) != 0) { EM_DEBUG_EXCEPTION("vconf_get_int failed"); @@ -2330,58 +2215,83 @@ INTERNAL_FUNC int emcore_start_driving_mode(int account_id) if (!tts_enable) goto FINISH_OFF; - SNPRINTF(string_account, sizeof(string_account), "%d", account_id); + if (!emstorage_get_mail_by_id(mail_id, &p_mail_data, false, NULL)) { + EM_DEBUG_EXCEPTION("emstorage_get_mail_by_id failed"); + goto FINISH_OFF; + } - err = service_create(&service); - if (err != SERVICE_ERROR_NONE) { - EM_DEBUG_EXCEPTION("service_create failed : [%d]", err); + if (p_mail_data->tag_id >= 0) + goto FINISH_OFF; + + SNPRINTF(string_mail, sizeof(string_mail), "%d", mail_id); + + err = app_control_create(&service); + if (err != APP_CONTROL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("app_control_create failed : [%d]", err); goto FINISH_OFF; } - err = service_set_package(service, "com.samsung.email-tts-play"); - if (err != SERVICE_ERROR_NONE) { - EM_DEBUG_EXCEPTION("service_set_package failed : [%d]", err); + err = app_control_set_app_id(service, "org.tizen.email-tts-play"); + if (err != APP_CONTROL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("app_control_set_app_id failed : [%d]", err); goto FINISH_OFF; } - err = service_add_extra_data(service, "tts_email_account_id", string_account); - if (err != SERVICE_ERROR_NONE) { - EM_DEBUG_EXCEPTION("service_add_extra_data failed : [%d]", err); + err = app_control_add_extra_data(service, "tts_email_id", string_mail); + if (err != APP_CONTROL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("app_control_add_extra_data failed : [%d]", err); goto FINISH_OFF; } - err = service_send_launch_request(service, NULL, NULL); - if (err != SERVICE_ERROR_NONE) { - EM_DEBUG_EXCEPTION("service_send_launch_request failed : [%d]", err); + err = app_control_send_launch_request(service, NULL, NULL); + if (err != APP_CONTROL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("app_control_send_launch_request failed : [%d]", err); goto FINISH_OFF; } FINISH_OFF: if (service) - service_destroy(service); + app_control_destroy(service); + + if (p_mail_data) + emstorage_free_mail(&p_mail_data, 1, NULL); EM_DEBUG_FUNC_END(); return convert_app_err_to_email_err(err); } #endif /* __FEATURE_DRIVING_MODE__ */ -INTERNAL_FUNC int emcore_clear_all_notifications() +INTERNAL_FUNC int emcore_clear_notifications(int account_id) { int account_count = 0, i; emstorage_account_tbl_t *account_list; int error_code = EMAIL_ERROR_NONE; - if(!emstorage_get_account_list(&account_count, &account_list, true, false, &error_code)) { - EM_DEBUG_EXCEPTION("emstorage_get_account_list failed"); - goto FINISH_OFF; + if (account_id == ALL_ACCOUNT) { + if(!emstorage_get_account_list(&account_count, &account_list, true, false, &error_code)) { + EM_DEBUG_EXCEPTION("emstorage_get_account_list failed"); + goto FINISH_OFF; + } + + for(i = 0; i < account_count; i++) { + error_code = emcore_delete_notification_by_account(account_list[i].account_id, true); + if (error_code != EMAIL_ERROR_NONE) + EM_DEBUG_EXCEPTION("emcore_delete_notification_by_account failed"); + } + } else { + error_code = emcore_delete_notification_by_account(account_id, true); + if (error_code != EMAIL_ERROR_NONE) + EM_DEBUG_EXCEPTION("emcore_delete_notification_by_account failed"); } - for(i = 0; i < account_count; i++) { - emcore_delete_notification_by_account(account_list[i].account_id, true); + if (!emstorage_update_save_status(account_id, &error_code)) { + EM_DEBUG_EXCEPTION("emstorage_update_save_status failed : [%d]", error_code); + goto FINISH_OFF; } FINISH_OFF: + if(account_count) { emstorage_free_account(&account_list, account_count, NULL); } @@ -2403,6 +2313,7 @@ INTERNAL_FUNC int emcore_delete_notification_by_account(int account_id, int with if (vconf_get_int(vconf_private_id, &private_id) != 0) { EM_DEBUG_EXCEPTION("vconf_get_int failed"); } + EM_DEBUG_FUNC_END(); return error_code; } @@ -2834,6 +2745,12 @@ int emcore_make_attachment_file_name_with_extension(char *source_file_name, char 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) { + if ((MAX_PATH + 1) < (strlen(sub_type) + 1)) { + EM_DEBUG_EXCEPTION("Buffer overflow"); + err = EMAIL_ERROR_OUT_OF_MEMORY; + goto FINISH_OFF; + } + strcat(attachment_file_name, "."); strcat(attachment_file_name, sub_type); EM_DEBUG_LOG_SEC("attachment_file_name with extension[%s] ", attachment_file_name); @@ -2921,7 +2838,7 @@ INTERNAL_FUNC int emcore_get_next_activity_id(int *activity_id, int *err_code) int err = EMAIL_ERROR_NONE; if (NULL == activity_id) - { + { EM_DEBUG_EXCEPTION("\t activity_id[%p]", activity_id); err = EMAIL_ERROR_INVALID_PARAM; @@ -2977,6 +2894,7 @@ INTERNAL_FUNC int emcore_search_string_from_file(char *file_path, char *search_s FILE *fp = NULL; char *buf = NULL; char *stripped = NULL; + char *cid_string = NULL; char *modified_string = NULL; if (!search_string || !file_path || !result) { @@ -2985,15 +2903,14 @@ INTERNAL_FUNC int emcore_search_string_from_file(char *file_path, char *search_s return error; } - fp = fopen(file_path, "r"); - if (fp == NULL) { - EM_DEBUG_EXCEPTION("fopen failed"); - error = EMAIL_ERROR_SYSTEM_FAILURE; + error = em_fopen(file_path, "r", &fp); + if (error != EMAIL_ERROR_NONE || fp == NULL) { + EM_DEBUG_EXCEPTION("em_fopen error [%d] [%s]", error, file_path); goto FINISH_OFF; } if (!emcore_get_file_size(file_path, &file_size, &error)) { - EM_DEBUG_EXCEPTION("emcore_get_file_size failed"); + EM_DEBUG_EXCEPTION("emcore_get_file_size error [%s]", file_path); goto FINISH_OFF; } @@ -3005,7 +2922,7 @@ INTERNAL_FUNC int emcore_search_string_from_file(char *file_path, char *search_s } if (fread(buf, sizeof(char), file_size, fp) != file_size) { - EM_DEBUG_EXCEPTION("Get the data from file : failed"); + EM_DEBUG_EXCEPTION("fread error [%d]", errno); error = EMAIL_ERROR_SYSTEM_FAILURE; goto FINISH_OFF; } @@ -3014,21 +2931,29 @@ INTERNAL_FUNC int emcore_search_string_from_file(char *file_path, char *search_s stripped = em_replace_all_string(buf, CRLF_STRING, ""); if (stripped) { if (new_string) { - modified_string = em_replace_string(stripped, search_string, new_string); + cid_string = em_malloc(strlen(search_string) + strlen("cid:") + 1); + if (cid_string == NULL) { + EM_DEBUG_EXCEPTION("em_malloc failed"); + error = EMAIL_ERROR_OUT_OF_MEMORY; + goto FINISH_OFF; + } + + sprintf(cid_string, "cid:%s", search_string); + + modified_string = em_replace_string(stripped, cid_string, new_string); if (modified_string) { if (fp) fclose(fp); - - fp = fopen(file_path, "w"); - if (fp == NULL) { - EM_DEBUG_EXCEPTION("fopen failed"); - error = EMAIL_ERROR_SYSTEM_FAILURE; + + error = em_fopen(file_path, "w", &fp); + if (error != EMAIL_ERROR_NONE || fp == NULL) { + EM_DEBUG_EXCEPTION("em_fopen failed"); goto FINISH_OFF; } - fprintf(fp, "%s", modified_string); + fprintf(fp, "%s", modified_string); - p_result = true; + p_result = true; } } else { @@ -3048,6 +2973,7 @@ FINISH_OFF: EM_SAFE_FREE(buf); EM_SAFE_FREE(stripped); /*prevent 35586*/ + EM_SAFE_FREE(cid_string); EM_SAFE_FREE(modified_string); EM_DEBUG_FUNC_END("error:[%d]", error); @@ -3071,10 +2997,9 @@ INTERNAL_FUNC int emcore_load_query_from_file(char *file_path, char ***query_arr return error; } - fp = fopen(file_path, "r"); - if (fp == NULL) { - EM_DEBUG_EXCEPTION("fopen failed"); - error = EMAIL_ERROR_SYSTEM_FAILURE; + error = em_fopen(file_path, "r", &fp); + if (error != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("em_fopen failed"); goto FINISH_OFF; } @@ -3083,7 +3008,7 @@ INTERNAL_FUNC int emcore_load_query_from_file(char *file_path, char ***query_arr goto FINISH_OFF; } - buf = em_malloc(file_size); + buf = em_malloc(file_size + 1); if (buf == NULL) { EM_DEBUG_EXCEPTION("em_malloc failed"); error = EMAIL_ERROR_OUT_OF_MEMORY; @@ -3277,12 +3202,12 @@ INTERNAL_FUNC int emcore_calc_next_time_to_sync(int input_account_id, time_t inp goto FINISH_OFF; } - if (account->peak_interval <= 0) { + if (account->peak_days < 0) { /* peak schedule disabled */ if (account->check_interval > 0) result_time = input_current_time + (account->check_interval * 60); } - else if(account->peak_days) { + else if(account->peak_days > 0) { /* peak schedule enabled */ /* if current time is in peak schedule */ @@ -3374,18 +3299,18 @@ static int convert_contact_err_to_email_err(int contact_err) int emcore_get_mail_contact_info(email_mail_contact_info_t *contact_info, char *full_address, int *err_code) { EM_DEBUG_FUNC_BEGIN_SEC("contact_info[%p], full_address[%s], err_code[%p]", contact_info, full_address, err_code); - + int ret = false; int err = EMAIL_ERROR_NONE; - + if (!emcore_get_mail_contact_info_with_update(contact_info, full_address, 0, &err)) EM_DEBUG_EXCEPTION("emcore_get_mail_contact_info_with_update failed [%d]", err); else ret = true; - + if (err_code != NULL) *err_code = err; - + return ret; } @@ -3393,7 +3318,7 @@ int emcore_search_contact_info(const char *contact_uri, int address_property_id, { EM_DEBUG_FUNC_BEGIN(); int contact_err = CONTACTS_ERROR_NONE; - + contacts_query_h query = NULL; contacts_filter_h filter = NULL; contacts_list_h list = NULL; @@ -3402,7 +3327,7 @@ int emcore_search_contact_info(const char *contact_uri, int address_property_id, EM_DEBUG_EXCEPTION("contacts_query_create failed"); goto FINISH_OFF; } - + if ((contact_err = contacts_filter_create(contact_uri, &filter)) != CONTACTS_ERROR_NONE) { EM_DEBUG_EXCEPTION("contacts_filter_create failed"); goto FINISH_OFF; @@ -3456,7 +3381,7 @@ int emcore_search_contact_info_by_address(const char *contact_uri, int property_ { EM_DEBUG_FUNC_BEGIN(); int contact_err = CONTACTS_ERROR_NONE; - + contacts_query_h query = NULL; contacts_filter_h filter = NULL; contacts_list_h list = NULL; @@ -3465,7 +3390,7 @@ int emcore_search_contact_info_by_address(const char *contact_uri, int property_ EM_DEBUG_EXCEPTION("contacts_query_create failed"); goto FINISH_OFF; } - + if ((contact_err = contacts_filter_create(contact_uri, &filter)) != CONTACTS_ERROR_NONE) { EM_DEBUG_EXCEPTION("contacts_filter_create failed"); goto FINISH_OFF; @@ -3487,7 +3412,7 @@ int emcore_search_contact_info_by_address(const char *contact_uri, int property_ } if ((contact_err = contacts_list_get_current_record_p(list, contacts_record)) != CONTACTS_ERROR_NONE) { - if (contact_err != CONTACTS_ERROR_NO_DATA) /* no matching record found */ + if (contact_err != CONTACTS_ERROR_NO_DATA) /* no matching record found */ EM_DEBUG_EXCEPTION ("contacts_list_get_current_record_p failed [%d]", contact_err); goto FINISH_OFF; } @@ -3506,23 +3431,40 @@ FINISH_OFF: return contact_err; } -int emcore_set_contacts_log(int account_id, char *email_address, char *subject, time_t date_time, email_action_t action) +typedef struct { + int account_id; + char *email_address; + char *subject; + time_t date_time; + email_action_t action; +} set_contacts_log_internal_t; + +gboolean emcore_set_contacts_log_internal (void* arg) { - EM_DEBUG_FUNC_BEGIN_SEC("account_id : [%d], address : [%p], subject : [%s], action : [%d], date_time : [%d]", account_id, email_address, subject, action, (int)date_time); - - int err = EMAIL_ERROR_NONE; + if (!arg) { + EM_DEBUG_EXCEPTION ("no contact data to add"); + return FALSE; + } + set_contacts_log_internal_t* tmp = (set_contacts_log_internal_t*) arg; + int account_id = tmp->account_id; + char *email_address = tmp->email_address; + char *subject = tmp->subject; + time_t date_time = tmp->date_time; + email_action_t action = tmp->action; + int contacts_error = CONTACTS_ERROR_NONE; int person_id = 0; int action_type = 0; - + contacts_record_h phone_record = NULL; - contacts_record_h person_record = NULL; + contacts_record_h person_record = NULL; - if ((contacts_error = contacts_connect2()) != CONTACTS_ERROR_NONE) { +/* + if ((contacts_error = contacts_connect_on_thread()) != CONTACTS_ERROR_NONE) { EM_DEBUG_EXCEPTION("Open connect service failed [%d]", contacts_error); goto FINISH_OFF; } - +*/ if ((contacts_error = contacts_record_create(_contacts_phone_log._uri, &phone_record)) != CONTACTS_ERROR_NONE) { EM_DEBUG_EXCEPTION("contacts_query_create failed [%d]", contacts_error); goto FINISH_OFF; @@ -3602,21 +3544,49 @@ FINISH_OFF: if (person_record != NULL) contacts_record_destroy(person_record, false); - err = convert_contact_err_to_email_err(contacts_error); - - if ((contacts_error = contacts_disconnect2()) != CONTACTS_ERROR_NONE) { +/* + if ((contacts_error = contacts_disconnect_on_thread()) != CONTACTS_ERROR_NONE) { EM_DEBUG_EXCEPTION("Open connect service failed [%d]", contacts_error); err = convert_contact_err_to_email_err(contacts_error); } +*/ + EM_SAFE_FREE (email_address); + EM_SAFE_FREE (subject); + EM_SAFE_FREE (tmp); - EM_DEBUG_FUNC_END("err [%d]", err); - return err; + EM_DEBUG_FUNC_END("contact err [%d]", convert_contact_err_to_email_err(contacts_error)); + return FALSE; +} + +int emcore_set_contacts_log (int account_id, + char *email_address, + char *subject, + time_t date_time, + email_action_t action) +{ + /* arg shall be destroyed in emcore_set_contacts_log_internal */ + set_contacts_log_internal_t *arg = em_malloc (sizeof(set_contacts_log_internal_t)); + if (!arg) { + EM_DEBUG_EXCEPTION ("em_malloc error"); + return EMAIL_ERROR_OUT_OF_MEMORY; + } + + /* deep copy */ + arg->account_id = account_id; + arg->email_address = EM_SAFE_STRDUP (email_address); + arg->subject = EM_SAFE_STRDUP (subject); + arg->date_time = date_time; + arg->action = action; + + g_main_context_invoke (NULL, emcore_set_contacts_log_internal, arg); + + return EMAIL_ERROR_NONE; } INTERNAL_FUNC int emcore_set_sent_contacts_log(emstorage_mail_tbl_t *input_mail_data) { EM_DEBUG_FUNC_BEGIN("input_mail_data : [%p]", input_mail_data); - + int i = 0; int err = EMAIL_ERROR_NONE; char email_address[MAX_EMAIL_ADDRESS_LENGTH]; @@ -3634,8 +3604,8 @@ INTERNAL_FUNC int emcore_set_sent_contacts_log(emstorage_mail_tbl_t *input_mail_ goto FINISH_OFF; } } - - if (addr) { + + if (addr) { mail_free_address(&addr); addr = NULL; } @@ -3644,13 +3614,14 @@ INTERNAL_FUNC int emcore_set_sent_contacts_log(emstorage_mail_tbl_t *input_mail_ FINISH_OFF: - if (addr) + if (addr) mail_free_address(&addr); EM_DEBUG_FUNC_END("err [%d]", err); return err; } + INTERNAL_FUNC int emcore_set_received_contacts_log(emstorage_mail_tbl_t *input_mail_data) { EM_DEBUG_FUNC_BEGIN("input_mail_data : [%p]", input_mail_data); @@ -3664,51 +3635,125 @@ INTERNAL_FUNC int emcore_set_received_contacts_log(emstorage_mail_tbl_t *input_m return err; } -INTERNAL_FUNC int emcore_delete_contacts_log(int account_id) +gboolean emcore_delete_contacts_log_internal(void* arg) { - EM_DEBUG_FUNC_BEGIN("account_id [%d]", account_id); + EM_DEBUG_FUNC_BEGIN(); - int err = EMAIL_ERROR_NONE; + + int account_id = (int) arg; /* it is not a pointer */ int contacts_error = CONTACTS_ERROR_NONE; - if ((contacts_error = contacts_connect2()) != CONTACTS_ERROR_NONE) { +/* + if ((contacts_error = contacts_connect_on_thread()) != CONTACTS_ERROR_NONE) { EM_DEBUG_EXCEPTION("Open connect service failed [%d]", contacts_error); goto FINISH_OFF; } - +*/ /* Delete record of the account id */ if ((contacts_error = contacts_phone_log_delete(CONTACTS_PHONE_LOG_DELETE_BY_EMAIL_EXTRA_DATA1, account_id)) != CONTACTS_ERROR_NONE) { EM_DEBUG_EXCEPTION("contacts_phone_log_delete failed [%d]", contacts_error); } - -FINISH_OFF: - err = convert_contact_err_to_email_err(contacts_error); +/* err = convert_contact_err_to_email_err(contacts_error); */ - if ((contacts_error = contacts_disconnect2()) != CONTACTS_ERROR_NONE) { +/* + if ((contacts_error = contacts_disconnect_on_thread()) != CONTACTS_ERROR_NONE) { EM_DEBUG_EXCEPTION("Open connect service failed [%d]", contacts_error); err = convert_contact_err_to_email_err(contacts_error); } +*/ + EM_DEBUG_FUNC_END(); + return FALSE; +} - EM_DEBUG_FUNC_END("err [%d]", err); - return err; +INTERNAL_FUNC int emcore_delete_contacts_log(int account_id) +{ + g_main_context_invoke (NULL, emcore_delete_contacts_log_internal, (void*) account_id); + + return EMAIL_ERROR_NONE; +} + +INTERNAL_FUNC int emcore_get_mail_display_name (char *email_address, char **contact_display_name) +{ + if (!email_address || !contact_display_name) { + EM_DEBUG_EXCEPTION ("NULL_PARAM email_address[%p] contact_display_name[%p]", + email_address, contact_display_name); + return EMAIL_ERROR_INVALID_PARAM; + } + + GError *gerror = NULL; + GVariant *result = NULL; + int ret = EMAIL_ERROR_NONE; + + g_type_init (); + GDBusProxy* bproxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM, + G_DBUS_PROXY_FLAGS_NONE, + NULL, + EMAIL_SERVICE_NAME, + EMAIL_SERVICE_PATH, + EMAIL_SERVICE_NAME, + NULL, + &gerror); + if (!bproxy) { + EM_DEBUG_EXCEPTION ("g_dbus_proxy_new_for_bus_sync error [%s]", + gerror->message); + ret = EMAIL_ERROR_IPC_PROTOCOL_FAILURE; + goto FINISH_OFF; + } + + result = g_dbus_proxy_call_sync (bproxy, + "GetDisplayName", + g_variant_new ("(s)", email_address), + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, + &gerror); + + + if (!result) { + EM_DEBUG_EXCEPTION ("g_dbus_proxy_call_sync 'SetContactsLog' error [%s]", + gerror->message); + ret = EMAIL_ERROR_IPC_PROTOCOL_FAILURE; + goto FINISH_OFF; + } + + g_variant_get (result, "(si)", contact_display_name, &ret); + + /* replace "" to NULL */ + if (!g_strcmp0 (*contact_display_name, "")) + EM_SAFE_FREE (*contact_display_name); + + g_variant_unref (result); + +FINISH_OFF: + EM_DEBUG_LOG ("ret [%d]\n", ret); + if (bproxy) + g_object_unref (bproxy); + if (gerror) + g_error_free (gerror); + + return ret; } -INTERNAL_FUNC int emcore_get_mail_display_name(char *email_address, char **contact_display_name, int *err_code) + +INTERNAL_FUNC int emcore_get_mail_display_name_internal (char *email_address, + char **contact_display_name) { EM_DEBUG_FUNC_BEGIN_SEC("contact_name_value[%s], contact_display_name[%p]", email_address, contact_display_name); int contact_err = 0; + int err = EMAIL_ERROR_NONE; int ret = false; char *display = NULL; /* Contact variable */ contacts_record_h record = NULL; - if ((contact_err = contacts_connect2()) != CONTACTS_ERROR_NONE) { +/* + if ((contact_err = contacts_connect_on_thread()) != CONTACTS_ERROR_NONE) { EM_DEBUG_EXCEPTION("Open connect service failed [%d]", contact_err); goto FINISH_OFF; } - +*/ if ((contact_err = emcore_search_contact_info_by_address(_contacts_contact_email._uri, _contacts_contact_email.email, email_address, 1, &record)) != CONTACTS_ERROR_NONE) { if (contact_err != CONTACTS_ERROR_NO_DATA) /* no matching record found */ EM_DEBUG_EXCEPTION("emcore_search_contact_info_by_address failed [%d]", contact_err); @@ -3740,7 +3785,7 @@ INTERNAL_FUNC int emcore_get_mail_display_name(char *email_address, char **conta FINISH_OFF: - contacts_disconnect2(); +/* contacts_disconnect_on_thread(); */ if (record != NULL) contacts_record_destroy(record, false); @@ -3752,12 +3797,42 @@ FINISH_OFF: EM_SAFE_FREE(display); } - if (err_code != NULL) - *err_code = convert_contact_err_to_email_err(contact_err); + err = convert_contact_err_to_email_err(contact_err); - return ret; + return err; } +INTERNAL_FUNC int emcore_connect_contacts_service() +{ + EM_DEBUG_FUNC_BEGIN(); + int contact_err = 0; + int err = EMAIL_ERROR_NONE; + + if ((contact_err = contacts_connect()) != CONTACTS_ERROR_NONE) { + EM_DEBUG_EXCEPTION("contacts_connect failed : [%d]", contact_err); + } + + err = convert_contact_err_to_email_err(contact_err); + + EM_DEBUG_FUNC_END(); + return err; +} + +INTERNAL_FUNC int emcore_disconnect_contacts_service() +{ + EM_DEBUG_FUNC_BEGIN(); + int contact_err = 0; + int err = EMAIL_ERROR_NONE; + + if ((contact_err = contacts_disconnect()) != CONTACTS_ERROR_NONE) { + EM_DEBUG_EXCEPTION("contacts_connect failed : [%d]", contact_err); + } + + err = convert_contact_err_to_email_err(contact_err); + + EM_DEBUG_FUNC_END(); + return err; +} #ifdef __FEATURE_BLOCKING_MODE__ @@ -3787,7 +3862,65 @@ INTERNAL_FUNC void emcore_set_blocking_mode_status(int blocking_mode) blocking_mode_status = blocking_mode; } -INTERNAL_FUNC int emcore_check_blocking_mode(char *sender_address, int *blocking_status) +INTERNAL_FUNC int emcore_check_blocking_mode (char *sender_address, int *blocking_status) +{ + if ( !sender_address || !blocking_status ) { + EM_DEBUG_EXCEPTION ("NULL_PARAM sender_address[%p] blocking_status[%p]", + sender_address, blocking_status); + return EMAIL_ERROR_INVALID_PARAM; + } + + + GError *gerror = NULL; + GVariant *result = NULL; + int ret = EMAIL_ERROR_NONE; + + g_type_init (); + GDBusProxy* bproxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM, + G_DBUS_PROXY_FLAGS_NONE, + NULL, + EMAIL_SERVICE_NAME, + EMAIL_SERVICE_PATH, + EMAIL_SERVICE_NAME, + NULL, + &gerror); + if (!bproxy) { + EM_DEBUG_EXCEPTION ("g_dbus_proxy_new_for_bus_sync error [%s]", + gerror->message); + ret = EMAIL_ERROR_IPC_PROTOCOL_FAILURE; + goto FINISH_OFF; + } + + result = g_dbus_proxy_call_sync (bproxy, + "CheckBlockingMode", + g_variant_new ("(s)", sender_address), + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, + &gerror); + + + if (!result) { + EM_DEBUG_EXCEPTION ("g_dbus_proxy_call_sync 'SetContactsLog' error [%s]", + gerror->message); + ret = EMAIL_ERROR_IPC_PROTOCOL_FAILURE; + goto FINISH_OFF; + } + + g_variant_get (result, "(ii)", blocking_status, &ret); + g_variant_unref (result); + +FINISH_OFF: + + if (bproxy) + g_object_unref (bproxy); + if (gerror) + g_error_free (gerror); + + return ret; +} + +INTERNAL_FUNC int emcore_check_blocking_mode_internal (char *sender_address, int *blocking_status) { EM_DEBUG_FUNC_BEGIN(); int err = EMAIL_ERROR_NONE; @@ -3800,8 +3933,8 @@ INTERNAL_FUNC int emcore_check_blocking_mode(char *sender_address, int *blocking contacts_record_h record = NULL; if (!blocking_mode_of_setting) { - EM_DEBUG_LOG("Blocking mode is OFF"); - return err; + + return err; } if (vconf_get_int(VCONFKEY_SETAPPL_BLOCKINGMODE_ALLOWED_CONTACT_TYPE, &allowed_contact_type) != 0) { @@ -3810,11 +3943,12 @@ INTERNAL_FUNC int emcore_check_blocking_mode(char *sender_address, int *blocking goto FINISH_OFF; } - if ((contact_error = contacts_connect2()) != CONTACTS_ERROR_NONE) { +/* + if ((contact_error = contacts_connect_on_thread()) != CONTACTS_ERROR_NONE) { EM_DEBUG_EXCEPTION("Open connect service failed [%d]", contact_error); goto FINISH_OFF; } - +*/ switch (allowed_contact_type) { case ALLOWED_CONTACT_TYPE_NONE : EM_DEBUG_LOG("allowed_contact_type is none : bloacking all(notification)"); @@ -3831,7 +3965,7 @@ INTERNAL_FUNC int emcore_check_blocking_mode(char *sender_address, int *blocking if (record == NULL) { EM_DEBUG_LOG("No search contact info"); - goto FINISH_OFF; + goto FINISH_OFF; } *blocking_status = false; @@ -3845,7 +3979,7 @@ INTERNAL_FUNC int emcore_check_blocking_mode(char *sender_address, int *blocking if (record == NULL) { EM_DEBUG_LOG("No search contact info"); - goto FINISH_OFF; + goto FINISH_OFF; } *blocking_status = false; @@ -3856,7 +3990,7 @@ INTERNAL_FUNC int emcore_check_blocking_mode(char *sender_address, int *blocking if (person_id_string == NULL) { EM_DEBUG_LOG("Custom allowed contact type is NULL"); goto FINISH_OFF; - } + } if ((contact_error = emcore_search_contact_info_by_address(_contacts_person_email._uri, _contacts_person_email.email, sender_address, 1, &record)) != CONTACTS_ERROR_NONE) { if (contact_error != CONTACTS_ERROR_NO_DATA) /* no matching record found */ @@ -3866,11 +4000,11 @@ INTERNAL_FUNC int emcore_check_blocking_mode(char *sender_address, int *blocking if (record == NULL) { EM_DEBUG_LOG("No search contact info"); - goto FINISH_OFF; - } + goto FINISH_OFF; + } if (contacts_record_get_int(record, _contacts_contact_email.person_id, &person_id) != CONTACTS_ERROR_NONE) { - EM_DEBUG_EXCEPTION("contacts_record_get_str failed"); + EM_DEBUG_EXCEPTION("contacts_record_get_int failed"); goto FINISH_OFF; } @@ -3878,7 +4012,7 @@ INTERNAL_FUNC int emcore_check_blocking_mode(char *sender_address, int *blocking do { if (person_id == atoi(token)) { *blocking_status = false; - break; + break; } } while ((token = strtok_r(NULL, ",", &str))); @@ -3889,13 +4023,16 @@ INTERNAL_FUNC int emcore_check_blocking_mode(char *sender_address, int *blocking *blocking_status = true; err = EMAIL_ERROR_INVALID_PARAM; } - -FINISH_OFF : - contacts_disconnect2(); +FINISH_OFF : +/* + contacts_disconnect_on_thread(); +*/ err = convert_contact_err_to_email_err(contact_error); + EM_SAFE_FREE(person_id_string); + EM_DEBUG_FUNC_END(); return err; } @@ -3910,7 +4047,7 @@ INTERNAL_FUNC char *emcore_set_mime_entity(char *mime_path) char *mime_entity = NULL; char *mime_entity_path = NULL; char temp_buffer[255] = {0,}; - int err; + int err = EMAIL_ERROR_NONE; int searched = 0; if (!emcore_get_temp_file_name(&mime_entity_path, &err)) { @@ -3920,20 +4057,20 @@ INTERNAL_FUNC char *emcore_set_mime_entity(char *mime_path) /* get mime entity */ if (mime_path != NULL) { - fp_read = fopen(mime_path, "r"); - if (fp_read == NULL) { - EM_DEBUG_EXCEPTION_SEC("File open(read) is failed : filename [%s]", mime_path); + err = em_fopen(mime_path, "r", &fp_read); + if (err != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION_SEC("File em_fopen(read) is failed : filename [%s]", mime_path); goto FINISH_OFF; } - fp_write = fopen(mime_entity_path, "w"); - if (fp_write == NULL) { - EM_DEBUG_EXCEPTION_SEC("File open(write) is failed : filename [%s]", mime_entity_path); + err = em_fopen(mime_entity_path, "w", &fp_write); + if (err != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION_SEC("File em_fopen(write) is failed : filename [%s]", mime_entity_path); goto FINISH_OFF; } fseek(fp_read, 0, SEEK_SET); - fseek(fp_write, 0, SEEK_SET); + fseek(fp_write, 0, SEEK_SET); while (fgets(temp_buffer, 255, fp_read) != NULL) { mime_entity = strcasestr(temp_buffer, "content-type"); @@ -3944,7 +4081,7 @@ INTERNAL_FUNC char *emcore_set_mime_entity(char *mime_path) fprintf(fp_write, "%s", temp_buffer); } } - } + } FINISH_OFF: if (fp_read) @@ -3959,4 +4096,385 @@ FINISH_OFF: return mime_entity_path; } +/* Feedback LED api */ +INTERNAL_FUNC void emcore_set_flash_noti() +{ + EM_DEBUG_FUNC_BEGIN(); + int flash_error = FEEDBACK_ERROR_NONE; + + flash_error = feedback_initialize(); + if (flash_error != FEEDBACK_ERROR_NONE) { + EM_DEBUG_EXCEPTION("feedback_initialize failed : [%d]", flash_error); + return; + } + + flash_error = feedback_play_type(FEEDBACK_TYPE_LED, FEEDBACK_PATTERN_EMAIL); + if (flash_error != FEEDBACK_ERROR_NONE) { + EM_DEBUG_EXCEPTION("feedback_play_type failed : [%d]", flash_error); + } + + flash_error = feedback_deinitialize(); + if (flash_error != FEEDBACK_ERROR_NONE) { + EM_DEBUG_EXCEPTION("feedback_play_type failed : [%d]", flash_error); + } + + EM_DEBUG_FUNC_END(); +} + +INTERNAL_FUNC int emcore_get_content_from_file(char *filename, char **contents, int *length) +{ + EM_DEBUG_FUNC_BEGIN("filename[%s], contents[%p], length[%p]", filename, contents, length); + + struct stat stat_buf; + int fd = 0; + int bytes_read = 0; + int size = 0; + int alloc_size = 0; + int err = EMAIL_ERROR_NONE; + char *buf = NULL; + char errno_buf[ERRNO_BUF_SIZE] = {0}; + + if (filename == NULL || contents == NULL || length == NULL) { + err = EMAIL_ERROR_INVALID_PARAM; + EM_DEBUG_EXCEPTION("Invalid parameter"); + goto FINISH_OFF; + } + + err = em_open(filename, O_RDONLY, 0 ,&fd); + if (err != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("em_open error [%s][%d]", filename, err); + goto FINISH_OFF; + } + + if (fstat (fd, &stat_buf) < 0) { + EM_DEBUG_EXCEPTION("fstat failed for fd [%d]", fd); + err = EMAIL_ERROR_SYSTEM_FAILURE; + goto FINISH_OFF; + } + + if (stat_buf.st_size > 0 && S_ISREG(stat_buf.st_mode)) { + size = stat_buf.st_size; + alloc_size = size + 1; + buf = em_malloc(alloc_size); + if (buf == NULL) { + EM_DEBUG_EXCEPTION("malloc failed..."); + err = EMAIL_ERROR_OUT_OF_MEMORY; + goto FINISH_OFF; + } + + bytes_read = 0; + errno = 0; + + while (bytes_read < size) { + ssize_t rd_size = 0; + rd_size = read (fd, buf + bytes_read, size - bytes_read); + + if (rd_size < 0) { + if (errno != EINTR) { + EM_DEBUG_EXCEPTION("read failed: %s", EM_STRERROR(errno_buf)); + err = EMAIL_ERROR_SYSTEM_FAILURE; + goto FINISH_OFF; + } + } + else if (rd_size == 0) + break; + else + bytes_read += rd_size; + } + + buf[bytes_read] = '\0'; + + if (length) + *length = bytes_read; + + *contents = buf; + } + EM_SAFE_CLOSE (fd); /* prevent 39093 */ + + EM_DEBUG_FUNC_END(); + return err; + +FINISH_OFF: + + EM_SAFE_FREE(buf); + EM_SAFE_CLOSE (fd); /* prevent 39093 */ + EM_DEBUG_FUNC_END (); + + return err; +} + +INTERNAL_FUNC int emcore_set_content_to_file(const char *contents, char *dest_path, int length) +{ + EM_DEBUG_FUNC_BEGIN("contents[%p], dest_path[%s], length[%d]", contents, dest_path, length); + int fd = 0; + int err = EMAIL_ERROR_NONE; + char *tmp_path = NULL; + char errno_buf[ERRNO_BUF_SIZE] = {0}; + int byte_written = 0; /* 39063 */ + + if (contents == NULL || dest_path == NULL || length <= 0) { + err = EMAIL_ERROR_INVALID_PARAM; + EM_DEBUG_EXCEPTION("Invalid parameter"); + goto FINISH_OFF; + } + + tmp_path = emcore_mime_get_save_file_name(&err); + if (!tmp_path) { /* prevent 39114 */ + EM_DEBUG_EXCEPTION ("tmp_path NULL"); + goto FINISH_OFF; + } + + err = em_open(tmp_path, O_CREAT|O_WRONLY|O_TRUNC, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH, &fd); + if (err != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("em_open error [%s][%d]", tmp_path, err); + goto FINISH_OFF; + } + + errno = 0; + while(length > 0 && contents && errno == 0) { + byte_written = write(fd, (void *)contents, length); + if (byte_written < 0) { + /* interrupted by a signal */ + if (errno == EINTR) { + errno = 0; + continue; + } + EM_DEBUG_EXCEPTION("write failed: %s", EM_STRERROR(errno_buf)); + err = EMAIL_ERROR_SYSTEM_FAILURE; + goto FINISH_OFF; + } + + EM_DEBUG_LOG("NWRITTEN [%d]", byte_written); + length -= byte_written; + contents += byte_written; + } + + errno = 0; + if (fsync(fd) != 0){ + EM_DEBUG_EXCEPTION("fsync failed: %s", EM_STRERROR(errno_buf)); + err = EMAIL_ERROR_SYSTEM_FAILURE; + } + + errno = 0; + if (tmp_path && dest_path && rename(tmp_path, dest_path) != 0) { + EM_DEBUG_EXCEPTION("rename failed: %s", EM_STRERROR(errno_buf)); + err = EMAIL_ERROR_SYSTEM_FAILURE; + goto FINISH_OFF; + } + +FINISH_OFF: + + EM_SAFE_FREE(tmp_path); + EM_SAFE_CLOSE (fd); /* prevent 39114, 39136*/ + EM_DEBUG_FUNC_END(); + return err; +} + +#ifdef __FEATURE_UPDATE_DB_TABLE_SCHEMA__ + +INTERNAL_FUNC int emcore_update_db_table_schema() +{ + EM_DEBUG_FUNC_BEGIN(); + int err = EMAIL_ERROR_NONE; + + err = emstorage_update_db_table_schema(); + + EM_DEBUG_FUNC_END("err[%d]", err); + return err; +} + +#endif /* __FEATURE_UPDATE_DB_TABLE_SCHEMA__ */ + +INTERNAL_FUNC int emcore_unescape_from_url(char *input_url, char **output_url) +{ + EM_DEBUG_FUNC_BEGIN("input_url[%p] output_url[%p]", input_url, output_url); + int err = EMAIL_ERROR_NONE; + int input_length = 0; + int output_length = 0; + char *result_string = NULL; + CURL *curl = NULL; + + if (input_url == NULL|| output_url == NULL) { + err = EMAIL_ERROR_INVALID_PARAM; + EM_DEBUG_EXCEPTION("Invalid parameter"); + goto FINISH_OFF; + } + + *output_url = NULL; + curl = curl_easy_init(); + + input_length = EM_SAFE_STRLEN(input_url); + + result_string = curl_easy_unescape(curl, input_url, input_length, &output_length); + + if (output_length) + *output_url = EM_SAFE_STRDUP(result_string); + +FINISH_OFF: + if (result_string) + curl_free(result_string); + + if(curl) + curl_easy_cleanup(curl); + + EM_DEBUG_FUNC_END("err[%d]", err); + return err; +} + +INTERNAL_FUNC char *__em_get_month_in_string(int month) +{ + EM_DEBUG_FUNC_BEGIN("month [%d]", month); + + char *mon = NULL; + + switch (month){ + case 0: + mon = strdup("jan"); + break; + case 1: + mon = strdup("feb"); + break; + case 2: + mon = strdup("mar"); + break; + case 3: + mon = strdup("apr"); + break; + case 4: + mon = strdup("may"); + break; + case 5: + mon = strdup("jun"); + break; + case 6: + mon = strdup("jul"); + break; + case 7: + mon = strdup("aug"); + break; + case 8: + mon = strdup("sep"); + break; + case 9: + mon = strdup("oct"); + break; + case 10: + mon = strdup("nov"); + break; + case 11: + mon = strdup("dec"); + break; + } + return mon; +} + +INTERNAL_FUNC int emcore_make_date_string_for_search(time_t input_time, char *output_date_string) +{ + EM_DEBUG_FUNC_BEGIN("input_time[%p] output_date_string[%p]", input_time, output_date_string); + int err = EMAIL_ERROR_NONE; + struct tm *timeinfo = NULL; + char *mon = NULL; + + EM_DEBUG_LOG("RawTime Info [%lu]", input_time); + + timeinfo = localtime (&input_time); + + EM_DEBUG_LOG(">>>>>Time %d %d %d %d %d %d", 1900+timeinfo->tm_year, timeinfo->tm_mon+1, timeinfo->tm_mday); + + memset(output_date_string, 0x00, 20); + + mon = __em_get_month_in_string(timeinfo->tm_mon); + + if (mon){ + snprintf(output_date_string, 16, "%d-%s-%04d", timeinfo->tm_mday, mon, 1900 + timeinfo->tm_year); + EM_DEBUG_LOG("DATE IS [ %s ] ", output_date_string); + EM_SAFE_FREE(mon); + } + + EM_DEBUG_FUNC_END("err [%d]", err); + return err; +} + +INTERNAL_FUNC int emcore_make_uid_range_string(emcore_uid_list *uid_list, int total, char **output_uid_range_string) +{ + EM_DEBUG_FUNC_BEGIN("uid_list[%p] total[%d] output_uid_range_string[%p]", uid_list, total, output_uid_range_string); + int err = EMAIL_ERROR_NONE; + emcore_uid_list *uid_list_prev = NULL; + emcore_uid_list *uid_list_fast = uid_list; + int index = 0; + int msg_count = total; + int uid_range_size = msg_count * 8 + 1000; + char *uid_range = NULL; + + if (uid_list == NULL || total == 0 || output_uid_range_string == NULL) { + EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM"); + err = EMAIL_ERROR_INVALID_PARAM; + goto FINISH_OFF; + } + + 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 = EMAIL_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)); + EM_DEBUG_LOG("uid_range [%d]", uid_range); + } + 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; + } + } + } + EM_DEBUG_LOG("index [%d]", index); + + *output_uid_range_string = uid_range; + +FINISH_OFF: + + EM_DEBUG_FUNC_END("err [%d]", err); + return err; +} /* EOF */ diff --git a/email-core/email-device/email-device.c b/email-core/email-device/email-device.c index ec1d671..85d6a79 100755 --- a/email-core/email-device/email-device.c +++ b/email-core/email-device/email-device.c @@ -25,33 +25,52 @@ #include <stdlib.h> #include <time.h> #include <sys/types.h> -#include "pmapi.h" +#include "device/power.h" #include "email-device.h" #include "email-debug-log.h" +int stay_awake_flag[STAY_AWAKE_FLAG_MAX] = { 0, }; +static pthread_mutex_t stay_awake_flag_lock = PTHREAD_MUTEX_INITIALIZER; - -INTERNAL_FUNC int emdevice_set_sleep_on_off(int on, int *error_code) +INTERNAL_FUNC int emdevice_set_sleep_on_off(email_stay_awake_flag_owner_t input_flag_owner, int input_allow_to_sleep, int *error_code) { - EM_DEBUG_FUNC_BEGIN("on[%d], err_code[%p]", on, error_code); + EM_DEBUG_FUNC_BEGIN("input_flag_owner[%d] input_allow_to_sleep[%d] err_code[%p]", input_flag_owner, input_allow_to_sleep, error_code); int result_from_pm_api = 0; - if(on == 1) { - result_from_pm_api = pm_unlock_state(LCD_OFF, PM_SLEEP_MARGIN); - EM_DEBUG_LOG("pm_unlock_state() returns [%d]", result_from_pm_api); + ENTER_CRITICAL_SECTION(stay_awake_flag_lock); + + stay_awake_flag[input_flag_owner] = !input_allow_to_sleep; + + if(input_allow_to_sleep == 1) { + int i = 0; + int allowed_to_sleep = 1; + + for (i = 0; i < STAY_AWAKE_FLAG_MAX; i++) { + if (stay_awake_flag[i] == 1) { + allowed_to_sleep = 0; + break; + } + } + + if (allowed_to_sleep) { + /* allowed to sleep */ + result_from_pm_api = device_power_release_lock(POWER_LOCK_CPU); + EM_DEBUG_LOG("display_unlock_state() returns [%d]", result_from_pm_api); + } + else { + EM_DEBUG_LOG("other worker[%d] is working on", i); + } } else { - result_from_pm_api = pm_lock_state(LCD_OFF, STAY_CUR_STATE, 0); - EM_DEBUG_LOG("pm_lock_state() returns [%d]", result_from_pm_api); + /* Stay awake */ + result_from_pm_api = device_power_request_lock(POWER_LOCK_CPU, 0); + EM_DEBUG_LOG("display_lock_state() returns [%d]", result_from_pm_api); } - EM_DEBUG_FUNC_END(); - return true; -} + LEAVE_CRITICAL_SECTION(stay_awake_flag_lock); -INTERNAL_FUNC int emdevice_set_dimming_on_off(int on, int *error_code) -{ - EM_DEBUG_FUNC_BEGIN("on[%d], err_code[%p]", on, error_code); EM_DEBUG_FUNC_END(); return true; } + + diff --git a/email-core/email-device/include/email-device.h b/email-core/email-device/include/email-device.h index 7bdd818..59a88e1 100755 --- a/email-core/email-device/include/email-device.h +++ b/email-core/email-device/include/email-device.h @@ -43,8 +43,15 @@ extern "C" #define DISPLAY_STATE_DIM 1 #define DISPLAY_STATE_ON 2 -INTERNAL_FUNC int emdevice_set_sleep_on_off(int on, int *error_code); -INTERNAL_FUNC int emdevice_set_dimming_on_off(int on, int *error_code); +typedef enum { + STAY_AWAKE_FLAG_FOR_RECEVING_WORKER = 0, + STAY_AWAKE_FLAG_FOR_SENDING_WORKER, + STAY_AWAKE_FLAG_FOR_PARTIAL_BODY_WORKER, + STAY_AWAKE_FLAG_FOR_ALARM_CALLBACK, + STAY_AWAKE_FLAG_MAX, +} email_stay_awake_flag_owner_t; + +INTERNAL_FUNC int emdevice_set_sleep_on_off(email_stay_awake_flag_owner_t input_flag_owner, int input_allow_to_sleep, int *error_code); #ifdef __cplusplus } diff --git a/email-core/email-network/email-network.c b/email-core/email-network/email-network.c index c75100b..04d44e8 100755 --- a/email-core/email-network/email-network.c +++ b/email-core/email-network/email-network.c @@ -57,49 +57,69 @@ #include "email-core-event.h" #endif +int network_status = 0; + /* _get_network_status - Get the data network status from vconf */ -static int _get_network_status(int *network_status) + +INTERNAL_FUNC void emnetwork_set_network_status(int input_network_status) { - EM_DEBUG_FUNC_BEGIN("network_status [%p]", network_status); + EM_DEBUG_FUNC_BEGIN(); + network_status = input_network_status; + EM_DEBUG_FUNC_END(); +} + +INTERNAL_FUNC int emnetwork_get_network_status() +{ + EM_DEBUG_FUNC_BEGIN(); + EM_DEBUG_FUNC_END(); + return network_status; +} - int value = 0; +/* Check code for SIM status */ +static int _get_sim_status(int *sim_status) +{ + EM_DEBUG_FUNC_BEGIN(); + int value; - if(!network_status) { + if(!sim_status) { EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM"); return EMAIL_ERROR_INVALID_PARAM; } - if (vconf_get_int(VCONFKEY_NETWORK_STATUS, &value)) { - EM_DEBUG_EXCEPTION("Failed vconf_get_int [VCONFKEY_NETWORK_STATUS]"); + if (vconf_get_int(VCONFKEY_TELEPHONY_SIM_SLOT, &value) != 0) { + EM_DEBUG_EXCEPTION("Failed vconf_get_int [VCONFKEY_TELEPHONY_SIM_SLOT]"); return EMAIL_ERROR_SYSTEM_FAILURE; } - *network_status = value; + *sim_status = value; - EM_DEBUG_FUNC_END("network_status [%d]", value); + EM_DEBUG_FUNC_END("status[%d]", value); return EMAIL_ERROR_NONE; } -/* Check code for SIM status */ -static int _get_sim_status(int *sim_status) +/* Check code for flight mode */ +static int _get_flight_mode(int *flight_mode) { EM_DEBUG_FUNC_BEGIN(); int value; - if(!sim_status) { + if(!flight_mode) { EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM"); return EMAIL_ERROR_INVALID_PARAM; } - if (vconf_get_int(VCONFKEY_TELEPHONY_SIM_SLOT, &value) != 0) { - EM_DEBUG_EXCEPTION("Failed vconf_get_int [VCONFKEY_TELEPHONY_SIM_SLOT]"); + if (vconf_get_bool(VCONFKEY_TELEPHONY_FLIGHT_MODE, &value) != 0) { + EM_DEBUG_EXCEPTION("Failed vconf_get_bool [VCONFKEY_TELEPHONY_FLIGHT_MODE]"); return EMAIL_ERROR_SYSTEM_FAILURE; } - *sim_status = value; + EM_DEBUG_LOG("flight_mode : [%d]", value); + + *flight_mode = value; EM_DEBUG_FUNC_END("status[%d]", value); return EMAIL_ERROR_NONE; + } INTERNAL_FUNC int emnetwork_get_wifi_status(int *wifi_status) @@ -128,20 +148,26 @@ INTERNAL_FUNC int emnetwork_get_wifi_status(int *wifi_status) INTERNAL_FUNC int emnetwork_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 flight_mode = 0; int err = EMAIL_ERROR_NONE; int ret = false; - if ( (err = _get_network_status(&network_status)) != EMAIL_ERROR_NONE) { - EM_DEBUG_EXCEPTION("_get_network_status failed [%d]", err); - goto FINISH_OFF; - } - if(network_status == 0) { EM_DEBUG_LOG("VCONFKEY_NETWORK_STATUS is 0"); + if ( (err = _get_flight_mode(&flight_mode)) != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("_get_flight_mode failed : [%d]", err); + goto FINISH_OFF; + } + + if (flight_mode) { + EM_DEBUG_LOG("Flight mode enable"); + err = EMAIL_ERROR_FLIGHT_MODE_ENABLE; + goto FINISH_OFF; + } + if ( (err = emnetwork_get_wifi_status(&wifi_status)) != EMAIL_ERROR_NONE) { EM_DEBUG_EXCEPTION("emnetwork_get_wifi_status failed [%d]", err); goto FINISH_OFF; diff --git a/email-core/email-network/include/email-network.h b/email-core/email-network/include/email-network.h index a5db10f..b932f90 100755 --- a/email-core/email-network/include/email-network.h +++ b/email-core/email-network/include/email-network.h @@ -42,6 +42,8 @@ INTERNAL_FUNC int emnetwork_check_network_status(int *err_code); INTERNAL_FUNC int emnetwork_get_roaming_status(int *output_roaming_status); INTERNAL_FUNC int emnetwork_get_wifi_status(int *wifi_status); INTERNAL_FUNC long emnetwork_callback_ssl_cert_query(char *reason, char *host, char *cert); +INTERNAL_FUNC void emnetwork_set_network_status(int input_network_status); +INTERNAL_FUNC int emnetwork_get_network_status(); #ifdef __cplusplus diff --git a/email-core/email-storage/email-storage.c b/email-core/email-storage/email-storage.c index 21a14a4..e41b066 100755 --- a/email-core/email-storage/email-storage.c +++ b/email-core/email-storage/email-storage.c @@ -47,7 +47,6 @@ #include <sys/mman.h> #include <ss_manager.h> #include <fcntl.h> -#include <db-util.h> #define __USE_UNIX98 #define __USE_GNU @@ -112,6 +111,7 @@ #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 ATTACHMENT_MIME_TYPE_LEN_IN_MAIL_ATTACHMENT_TBL 128 #define MAILBOX_LEN_IN_MAIL_TBL 128 #define SERVER_MAILBOX_LEN_IN_MAIL_TBL 128 @@ -144,35 +144,34 @@ /* this define is used for query to change data (delete, insert, update) */ #define EMSTORAGE_START_WRITE_TRANSACTION(transaction_flag, error_code) \ - if (transaction_flag)\ - {\ - _timedlock_shm_mutex(&mapped_for_db_lock, 2);\ - if (emstorage_begin_transaction(NULL, NULL, &error_code) == false) \ - {\ - EM_DEBUG_EXCEPTION("emstorage_begin_transaction() error[%d]", error_code);\ - goto FINISH_OFF;\ + do {\ + if (transaction_flag) {\ + if (emstorage_begin_transaction(NULL, NULL, &error_code) == false) {\ + EM_DEBUG_EXCEPTION("emstorage_begin_transaction error [%d]", error_code);\ + goto FINISH_OFF;\ + }\ }\ - } + } while(0) /* this define is used for query to change data (delete, insert, update) */ #define EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction_flag, result_code, error_code) \ - if (transaction_flag)\ - {\ - if (result_code == true)\ - {\ - if (emstorage_commit_transaction(NULL, NULL, NULL) == false)\ - {\ - error_code = EMAIL_ERROR_DB_FAILURE;\ - result_code = false;\ + do {\ + if (transaction_flag) {\ + if (result_code == true) {\ + if (emstorage_commit_transaction(NULL, NULL, NULL) == false) {\ + EM_DEBUG_EXCEPTION("emstorage_commit_transaction error");\ + error_code = EMAIL_ERROR_DB_FAILURE;\ + result_code = false;\ + }\ + }\ + else {\ + if (emstorage_rollback_transaction(NULL, NULL, NULL) == false) {\ + EM_DEBUG_EXCEPTION("emstorage_rollback_transaction error");\ + error_code = EMAIL_ERROR_DB_FAILURE;\ + }\ }\ }\ - else\ - {\ - if (emstorage_rollback_transaction(NULL, NULL, NULL) == false)\ - error_code = EMAIL_ERROR_DB_FAILURE;\ - }\ - _unlockshm_mutex(&mapped_for_db_lock);\ - } + } while(0) /* this define is used for query to read (select) */ #define EMSTORAGE_START_READ_TRANSACTION(transaction_flag) \ @@ -191,12 +190,13 @@ /* for safety DB operation */ static pthread_mutex_t _db_handle_lock = PTHREAD_MUTEX_INITIALIZER; +/* for safety secure-storage operation */ +static pthread_mutex_t _ss_handle_lock = PTHREAD_MUTEX_INITIALIZER; + #define _MULTIPLE_DB_HANDLE #ifdef _MULTIPLE_DB_HANDLE -#define _DISCONNECT_DB /* db_util_close(_db_handle); */ - typedef struct { pthread_t thread_id; @@ -305,9 +305,7 @@ sqlite3 *emstorage_get_db_connection() return emstorage_db_open(NULL); } - #else /* _MULTIPLE_DB_HANDLE */ -#define _DISCONNECT_DB /* db_util_close(_db_handle); */ sqlite3 *_db_handle = NULL; @@ -337,53 +335,90 @@ int shm_fd_for_generating_mail_id = 0; #ifdef __FEATURE_USE_SHARED_MUTEX_FOR_PROTECTED_FUNC_CALL__ #define EMSTORAGE_PROTECTED_FUNC_CALL(function_call, return_value) \ - { _timedlock_shm_mutex(&mapped_for_db_lock, 2); return_value = function_call; _unlockshm_mutex(&mapped_for_db_lock); } + do {\ + _timedlock_shm_mutex(&mapped_for_db_lock, 2);\ + return_value = function_call;\ + _unlockshm_mutex(&mapped_for_db_lock);\ + } while(0) + #else /* __FEATURE_USE_SHARED_MUTEX_FOR_PROTECTED_FUNC_CALL__ */ #define EMSTORAGE_PROTECTED_FUNC_CALL(function_call, return_value) \ { return_value = function_call; } #endif /* __FEATURE_USE_SHARED_MUTEX_FOR_PROTECTED_FUNC_CALL__ */ +static int emstorage_exec_query_by_prepare_v2(sqlite3 *local_db_handle, char *query_string) +{ + EM_DEBUG_FUNC_BEGIN("local_db_handle[%p] query_string[%p]", local_db_handle, query_string); + int error = EMAIL_ERROR_NONE; + int rc = 0; + DB_STMT db_statement = NULL; + + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, query_string, EM_SAFE_STRLEN(query_string), &db_statement, NULL), rc); + EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, + ("sqlite3_prepare failed [%d] [%s]", rc, query_string)); + + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(db_statement), rc); + EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, + ("sqlite3_step failed [%d] [%s]", rc, query_string)); + +FINISH_OFF : + + if (db_statement != NULL) { + rc = sqlite3_finalize(db_statement); + if (rc != SQLITE_OK) { + EM_DEBUG_EXCEPTION ("sqlite3_finalize error [%d]", rc); + error = EMAIL_ERROR_DB_FAILURE; + } + } + + return error; +} + INTERNAL_FUNC int emstorage_shm_file_init(const char *shm_file_name) { EM_DEBUG_FUNC_BEGIN("shm_file_name [%p]", shm_file_name); - char errno_buf[ERRNO_BUF_SIZE] = {0}; if(!shm_file_name) { EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM"); return EMAIL_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", EM_STRERROR(errno_buf)); - return EMAIL_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", EM_STRERROR(errno_buf)); - return EMAIL_ERROR_SYSTEM_FAILURE; - } + int fd = shm_open (shm_file_name, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP); /* note: permission is not working */ - m->data = 0; + if (fd < 0) { + EM_DEBUG_EXCEPTION("shm_open errno [%d]", errno); + return EMAIL_ERROR_SYSTEM_FAILURE; + } - pthread_mutexattr_t mattr; - pthread_mutexattr_init(&mattr); - pthread_mutexattr_setpshared(&mattr, PTHREAD_PROCESS_SHARED); - pthread_mutexattr_setrobust(&mattr, PTHREAD_MUTEX_ROBUST_NP); - pthread_mutex_init(&(m->mutex), &mattr); - pthread_mutexattr_destroy(&mattr); + fchmod(fd, 0666); + EM_DEBUG_LOG("** Create SHM FILE **"); + if (ftruncate(fd, sizeof(mmapped_t)) != 0) { + EM_DEBUG_EXCEPTION("ftruncate errno [%d]", errno); + return EMAIL_ERROR_SYSTEM_FAILURE; } - else { - EM_DEBUG_EXCEPTION("shm_open failed: %s", EM_STRERROR(errno_buf)); + + 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 errno [%d]", errno); return EMAIL_ERROR_SYSTEM_FAILURE; } - close(fd); + + m->data = 0; + + pthread_mutexattr_t mattr; + pthread_mutexattr_init(&mattr); + pthread_mutexattr_setpshared(&mattr, PTHREAD_PROCESS_SHARED); + pthread_mutexattr_setrobust(&mattr, PTHREAD_MUTEX_ROBUST_NP); + pthread_mutex_init(&(m->mutex), &mattr); + + pthread_mutexattr_destroy(&mattr); + pthread_mutex_destroy(&(m->mutex)); + + munmap(m, sizeof(mmapped_t)); + + EM_SAFE_CLOSE (fd); EM_DEBUG_FUNC_END(); + return EMAIL_ERROR_NONE; } @@ -403,7 +438,7 @@ int emstorage_shm_file_destroy(const char *shm_file_name) return EMAIL_ERROR_NONE; } -static int _initialize_shm_mutex(const char *shm_file_name, int *param_shm_fd, mmapped_t **param_mapped) +int _initialize_shm_mutex(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); char errno_buf[ERRNO_BUF_SIZE] = {0}; @@ -423,12 +458,22 @@ static int _initialize_shm_mutex(const char *shm_file_name, int *param_shm_fd, m return EMAIL_ERROR_SYSTEM_FAILURE; } } - mmapped_t *tmp = (mmapped_t *)mmap(NULL, sizeof(mmapped_t), PROT_READ|PROT_WRITE, MAP_SHARED, (*param_shm_fd), 0); + mmapped_t *tmp = (mmapped_t *)mmap(NULL, sizeof(mmapped_t), PROT_READ|PROT_WRITE, MAP_SHARED, (*param_shm_fd), 0); if (tmp == MAP_FAILED) { EM_DEBUG_EXCEPTION("mmap failed: %s", EM_STRERROR(errno_buf)); return EMAIL_ERROR_SYSTEM_FAILURE; } + + tmp->data = 0; + + pthread_mutexattr_t mattr; + pthread_mutexattr_init(&mattr); + pthread_mutexattr_setpshared(&mattr, PTHREAD_PROCESS_SHARED); + pthread_mutexattr_setrobust(&mattr, PTHREAD_MUTEX_ROBUST_NP); + pthread_mutex_init(&(tmp->mutex), &mattr); + pthread_mutexattr_destroy(&mattr); + *param_mapped = tmp; } @@ -436,7 +481,7 @@ static int _initialize_shm_mutex(const char *shm_file_name, int *param_shm_fd, m return EMAIL_ERROR_NONE; } -static int _timedlock_shm_mutex(mmapped_t **param_mapped, int sec) +int _timedlock_shm_mutex(mmapped_t **param_mapped, int sec) { EM_DEBUG_FUNC_BEGIN("param_mapped [%p], sec [%d]", param_mapped, sec); @@ -531,6 +576,12 @@ enum CREATE_TABLE_DUMMY_INDEX3, #endif +#ifdef __FEATURE_WIFI_AUTO_DOWNLOAD__ + CREATE_TABLE_MAIL_AUTO_DOWNLOAD_ACTIVITY_TBL, +#else + CREATE_TABLE_DUMMY_INDEX4, +#endif + /*CREATE INDEX*/ CREATE_TABLE_MAIL_ACCOUNT_IDX, CREATE_TABLE_MAIL_BOX_IDX, @@ -679,6 +730,7 @@ enum TAG_ID_IDX_IN_MAIL_TBL, REPLIED_TIME_IDX_IN_MAIL_TBL, FORWARDED_TIME_IDX_IN_MAIL_TBL, + DEFAULT_CHARSET_IDX_IN_MAIL_TBL, EAS_DATA_LENGTH_IDX_IN_MAIL_TBL, EAS_DATA_IDX_IN_MAIL_TBL, FIELD_COUNT_OF_MAIL_TBL, /* End of mail_tbl */ @@ -689,6 +741,7 @@ enum ATTACHMENT_ID_IDX_IN_MAIL_ATTACHMENT_TBL = 0, ATTACHMENT_NAME_IDX_IN_MAIL_ATTACHMENT_TBL, ATTACHMENT_PATH_IDX_IN_MAIL_ATTACHMENT_TBL, + CONTENT_ID_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, @@ -722,6 +775,18 @@ enum { #endif }; +#ifdef __FEATURE_WIFI_AUTO_DOWNLOAD__ +enum +{ + ACTIVITY_ID_IDX_MAIL_AUTO_DOWNLOAD_ACTIVITY_TBL = 0, + STATUS_IDX_MAIL_AUTO_DOWNLOAD_ACTIVITY_TBL, + ACCOUNT_ID_IDX_MAIL_AUTO_DOWNLOAD_ACTIVITY_TBL, + MAIL_ID_IDX_MAIL_AUTO_DOWNLOAD_ACTIVITY_TBL, + SERVER_MAIL_ID_IDX_MAIL_AUTO_DOWNLOAD_ACTIVITY_TBL, + MAILBOX_ID_IDX_MAIL_AUTO_DOWNLOAD_ACTIVITY_TBL, +}; +#endif + /* sowmya.kr 03032010, changes for get list of mails for given addr list */ typedef struct _em_mail_id_list { int mail_id; @@ -755,6 +820,7 @@ static char *g_test_query[] = { " keep_mails_on_pop_server_after_download, " " auto_resend_times, " " outgoing_server_size_limit, " + " wifi_auto_download, " " pop_before_smtp, " " incoming_server_requires_apop," " logo_icon_path, " @@ -774,6 +840,11 @@ static char *g_test_query[] = { " add_signature, " " signature" ", add_my_address_to_bcc" + ", notification_status " + ", vibrate_status " + ", display_content_status " + ", default_ringtone_status " + ", alert_ringtone_path " ", account_svc_id " ", index_color " ", sync_status " @@ -946,14 +1017,6 @@ static char *g_test_query[] = { " filepath, " " password " " FROM mail_certificate_tbl ", -#ifdef __FEATURE_BODY_SEARCH__ - "SELECT " - " mail_id, " - " account_id, " - " mailbox_id, " - " body_text " - " FROM mail_text_tbl ", -#endif "SELECT " " task_id, " " task_type, " @@ -963,6 +1026,24 @@ static char *g_test_query[] = { " task_parameter , " " date_time " " FROM mail_task_tbl ", +#ifdef __FEATURE_BODY_SEARCH__ + "SELECT " + " mail_id, " + " account_id, " + " mailbox_id, " + " body_text " + " FROM mail_text_tbl ", +#endif +#ifdef __FEATURE_WIFI_AUTO_DOWNLOAD__ + "SELECT " + " activity_id, " + " status, " + " account_id, " + " mail_id, " + " server_mail_id, " + " mailbox_id, " + " FROM mail_auto_download_activity_tbl ", +#endif NULL, }; @@ -1575,11 +1656,15 @@ INTERNAL_FUNC int em_db_open(sqlite3 **sqlite_handle, int *err_code) } /* db open */ - EMSTORAGE_PROTECTED_FUNC_CALL(db_util_open(EMAIL_SERVICE_DB_FILE_PATH, sqlite_handle, DB_UTIL_REGISTER_HOOK_METHOD), rc); + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_open(EMAIL_SERVICE_DB_FILE_PATH, sqlite_handle), rc); if (SQLITE_OK != rc) { - EM_DEBUG_EXCEPTION("db_util_open fail:%d -%s", rc, sqlite3_errmsg(*sqlite_handle)); - error = EMAIL_ERROR_DB_FAILURE; - db_util_close(*sqlite_handle); + EM_DEBUG_EXCEPTION("sqlite3_open fail:%d -%s", rc, sqlite3_errmsg(*sqlite_handle)); + if (SQLITE_PERM == rc || SQLITE_CANTOPEN == rc) { + error = EMAIL_ERROR_PERMISSION_DENIED; + } else { + error = EMAIL_ERROR_DB_FAILURE; + } + sqlite3_close(*sqlite_handle); *sqlite_handle = NULL; if (SQLITE_CORRUPT == rc) /* SQLITE_CORRUPT : The database disk image is malformed */ {/* Recovery DB file */ @@ -1590,11 +1675,15 @@ INTERNAL_FUNC int em_db_open(sqlite3 **sqlite_handle, int *err_code) } EM_DEBUG_LOG("Open DB again"); - EMSTORAGE_PROTECTED_FUNC_CALL(db_util_open(EMAIL_SERVICE_DB_FILE_PATH, sqlite_handle, DB_UTIL_REGISTER_HOOK_METHOD), rc); + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_open(EMAIL_SERVICE_DB_FILE_PATH, sqlite_handle), rc); if (SQLITE_OK != rc) { - EM_DEBUG_EXCEPTION("db_util_open fail:%d -%s", rc, sqlite3_errmsg(*sqlite_handle)); - error = EMAIL_ERROR_DB_FAILURE; - db_util_close(*sqlite_handle); + EM_DEBUG_EXCEPTION("sqlite3_open fail:%d -%s", rc, sqlite3_errmsg(*sqlite_handle)); + if (SQLITE_PERM == rc) { + error = EMAIL_ERROR_PERMISSION_DENIED; + } else { + error = EMAIL_ERROR_DB_FAILURE; + } + sqlite3_close(*sqlite_handle); *sqlite_handle = NULL; goto FINISH_OFF; /*prevent 33351*/ } @@ -1609,12 +1698,11 @@ INTERNAL_FUNC int em_db_open(sqlite3 **sqlite_handle, int *err_code) if (SQLITE_OK != rc) { EM_DEBUG_EXCEPTION("sqlite3_busy_handler fail:%d -%s", rc, sqlite3_errmsg(*sqlite_handle)); error = EMAIL_ERROR_DB_FAILURE; - db_util_close(*sqlite_handle); + sqlite3_close(*sqlite_handle); *sqlite_handle = NULL; goto FINISH_OFF; } - ret = true; FINISH_OFF: @@ -1670,10 +1758,9 @@ INTERNAL_FUNC int emstorage_db_close(int *err_code) int ret = false; if (_db_handle) { - ret = db_util_close(_db_handle); - + ret = sqlite3_close(_db_handle); if (ret != SQLITE_OK) { - EM_DEBUG_EXCEPTION(" db_util_close fail - %d", ret); + EM_DEBUG_EXCEPTION(" sqlite3_close fail - %d", ret); error = EMAIL_ERROR_DB_FAILURE; ret = false; goto FINISH_OFF; @@ -1707,7 +1794,7 @@ INTERNAL_FUNC int emstorage_open(int *err_code) retValue = mkdir(DB_PATH, DIRECTORY_PERMISSION); EM_DEBUG_LOG("mkdir return- %d", retValue); - EM_DEBUG_LOG("emstorage_open - before db_util_open - pid = %d", getpid()); + EM_DEBUG_LOG("emstorage_open - before sqlite3_open - pid = %d", getpid()); if (emstorage_db_open(&error) == NULL) { EM_DEBUG_EXCEPTION("emstorage_db_open failed[%d]", error); @@ -1836,6 +1923,7 @@ INTERNAL_FUNC int emstorage_create_table(emstorage_create_db_type_t type, int *e char *sql; char **result = NULL; + /* 1. create mail_account_tbl */ sql = "SELECT count(name) FROM sqlite_master WHERE name='mail_account_tbl';"; EMSTORAGE_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; }, @@ -1849,17 +1937,20 @@ INTERNAL_FUNC int emstorage_create_table(emstorage_create_db_type_t type, int *e ("SQL(BEGIN EXCLUSIVE) exec fail:%d -%s", rc, sqlite3_errmsg(local_db_handle))); EM_DEBUG_LOG("CREATE TABLE mail_account_tbl"); - EM_SAFE_STRNCPY(sql_query_string, create_table_query[CREATE_TABLE_MAIL_ACCOUNT_TBL], sizeof(sql_query_string)-1); /*prevent 21984*/ - - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc); - EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); + if (error != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; + } /* create mail_account_tbl unique index */ SNPRINTF(sql_query_string, sizeof(sql_query_string), "%s", create_table_query[CREATE_TABLE_MAIL_ACCOUNT_IDX]); - - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc); - EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); + if (error != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; + } EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, "END;", NULL, NULL, NULL), rc); } /* mail_account_tbl */ @@ -1886,17 +1977,19 @@ INTERNAL_FUNC int emstorage_create_table(emstorage_create_db_type_t type, int *e EM_DEBUG_LOG("CREATE TABLE mail_box_tbl"); EM_SAFE_STRNCPY(sql_query_string, create_table_query[CREATE_TABLE_MAIL_BOX_TBL], sizeof(sql_query_string)-1); /*prevent 21984*/ - - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc); - EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, - ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); + if (error != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; + } /* create mail_local_mailbox_tbl unique index */ SNPRINTF(sql_query_string, sizeof(sql_query_string), "%s", create_table_query[CREATE_TABLE_MAIL_BOX_IDX]); - - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc); - EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, - ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); + if (error != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; + } EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, "END;", NULL, NULL, NULL), rc); } /* mail_box_tbl */ @@ -1923,17 +2016,20 @@ INTERNAL_FUNC int emstorage_create_table(emstorage_create_db_type_t type, int *e EM_DEBUG_LOG("CREATE TABLE mail_read_mail_uid_tbl"); EM_SAFE_STRNCPY(sql_query_string, create_table_query[CREATE_TABLE_MAIL_READ_MAIL_UID_TBL], sizeof(sql_query_string)-1); /*prevent 21984*/ - - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc); - EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, - ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); + if (error != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; + } /* create mail_read_mail_uid_tbl unique index */ SNPRINTF(sql_query_string, sizeof(sql_query_string), "%s", create_table_query[CREATE_TABLE_MAIL_READ_MAIL_UID_IDX]); + error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); + if (error != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; + } - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc); - EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, - ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, "END;", NULL, NULL, NULL), rc); } /* mail_read_mail_uid_tbl */ else if (type == EMAIL_CREATE_DB_CHECK) { @@ -1959,10 +2055,12 @@ INTERNAL_FUNC int emstorage_create_table(emstorage_create_db_type_t type, int *e EM_DEBUG_LOG("CREATE TABLE mail_rule_tbl"); EM_SAFE_STRNCPY(sql_query_string, create_table_query[CREATE_TABLE_MAIL_RULE_TBL], sizeof(sql_query_string)-1); /*prevent 21984*/ + error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); + if (error != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; + } - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc); - EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, - ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, "END;", NULL, NULL, NULL), rc); } /* mail_rule_tbl */ else if (type == EMAIL_CREATE_DB_CHECK) { @@ -1986,28 +2084,35 @@ INTERNAL_FUNC int emstorage_create_table(emstorage_create_db_type_t type, int *e EM_DEBUG_LOG("CREATE TABLE mail_tbl"); EM_SAFE_STRNCPY(sql_query_string, create_table_query[CREATE_TABLE_MAIL_TBL], sizeof(sql_query_string)-1); /*prevent 21984*/ - - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc); - EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, - ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); + if (error != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; + } /* create mail_tbl unique index */ SNPRINTF(sql_query_string, sizeof(sql_query_string), "%s", create_table_query[CREATE_TABLE_MAIL_IDX]); - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc); - EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, - ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); + if (error != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; + } /* create mail_tbl index for date_time */ SNPRINTF(sql_query_string, sizeof(sql_query_string), "%s", create_table_query[CREATE_TABLE_MAIL_DATETIME_IDX]); - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc); - EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, - ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); + if (error != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; + } /* create mail_tbl index for thread_item_count */ SNPRINTF(sql_query_string, sizeof(sql_query_string), "%s", create_table_query[CREATE_TABLE_MAIL_THREAD_IDX]); - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc); - EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, - ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); + if (error != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; + } EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, "END;", NULL, NULL, NULL), rc); /* just one time call */ @@ -2031,20 +2136,24 @@ INTERNAL_FUNC int emstorage_create_table(emstorage_create_db_type_t type, int *e EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, "BEGIN;", NULL, NULL, NULL), rc); EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {goto FINISH_OFF; }, ("SQL(BEGIN EXCLUSIVE) exec fail:%d -%s", rc, sqlite3_errmsg(local_db_handle))); + EM_DEBUG_LOG("CREATE TABLE mail_attachment_tbl"); EM_SAFE_STRNCPY(sql_query_string, create_table_query[CREATE_TABLE_MAIL_ATTACHMENT_TBL], sizeof(sql_query_string)-1); /*prevent 21984*/ - - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc); - EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, - ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); + if (error != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; + } /* create mail_attachment_tbl unique index */ SNPRINTF(sql_query_string, sizeof(sql_query_string), "%s", create_table_query[CREATE_TABLE_MAIL_ATTACHMENT_IDX]); + error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); + if (error != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; + } - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc); - EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, - ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, "END;", NULL, NULL, NULL), rc); } /* mail_attachment_tbl */ else if (type == EMAIL_CREATE_DB_CHECK) { @@ -2071,10 +2180,12 @@ INTERNAL_FUNC int emstorage_create_table(emstorage_create_db_type_t type, int *e EM_DEBUG_LOG("CREATE TABLE mail_partial_body_activity_tbl"); EM_SAFE_STRNCPY(sql_query_string, create_table_query[CREATE_TABLE_MAIL_PARTIAL_BODY_ACTIVITY_TBL], sizeof(sql_query_string)-1); /*prevent 21984*/ + error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); + if (error != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; + } - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc); - EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, - ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, "END;", NULL, NULL, NULL), rc); } /* mail_rule_tbl */ else if (type == EMAIL_CREATE_DB_CHECK) { @@ -2101,15 +2212,19 @@ INTERNAL_FUNC int emstorage_create_table(emstorage_create_db_type_t type, int *e EM_DEBUG_LOG("CREATE TABLE mail_meeting_tbl"); EM_SAFE_STRNCPY(sql_query_string, create_table_query[CREATE_TABLE_MAIL_MEETING_TBL], sizeof(sql_query_string)-1); /*prevent 21984*/ + error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); + if (error != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; + } - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc); - EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_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), "%s", create_table_query[CREATE_TABLE_MAIL_MEETING_IDX]); + error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); + if (error != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; + } - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc); - EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, - ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, "END;", NULL, NULL, NULL), rc); } /* mail_contact_sync_tbl */ else if (type == EMAIL_CREATE_DB_CHECK) { @@ -2136,10 +2251,12 @@ INTERNAL_FUNC int emstorage_create_table(emstorage_create_db_type_t type, int *e 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]); + error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); + if (error != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; + } - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc); - EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, - ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, "END;", NULL, NULL, NULL), rc); } /* mail_rule_tbl */ else if (type == EMAIL_CREATE_DB_CHECK) { @@ -2164,9 +2281,12 @@ INTERNAL_FUNC int emstorage_create_table(emstorage_create_db_type_t type, int *e EM_DEBUG_LOG("CREATE TABLE mail_certificate_tbl"); EM_SAFE_STRNCPY(sql_query_string, create_table_query[CREATE_TABLE_MAIL_CERTIFICATE_TBL], sizeof(sql_query_string)-1); /*prevent 21984*/ + error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); + if (error != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; + } - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc); - EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, "END;", NULL, NULL, NULL), rc); } /* mail_contact_sync_tbl */ else if (type == EMAIL_CREATE_DB_CHECK) { @@ -2189,13 +2309,19 @@ INTERNAL_FUNC int emstorage_create_table(emstorage_create_db_type_t type, int *e EM_DEBUG_LOG("CREATE TABLE mail_task_tbl"); EM_SAFE_STRNCPY(sql_query_string, create_table_query[CREATE_TABLE_MAIL_TASK_TBL], sizeof(sql_query_string)-1); /*prevent 21984 */ + error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); + if (error != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; + } - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc); - EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_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), "%s", create_table_query[CREATE_TABLE_MAIL_TASK_IDX]); + error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); + if (error != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; + } - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc); - EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, "END;", NULL, NULL, NULL), rc); } /* mail_task_tbl */ else if (type == EMAIL_CREATE_DB_CHECK) { @@ -2219,9 +2345,11 @@ INTERNAL_FUNC int emstorage_create_table(emstorage_create_db_type_t type, int *e EM_DEBUG_LOG("CREATE TABLE mail_text_tbl"); EM_SAFE_STRNCPY(sql_query_string, create_table_query[CREATE_TABLE_MAIL_TEXT_TBL], sizeof(sql_query_string)-1); /*prevent 21984 */ - - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc); - EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); + if (error != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; + } EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, "END;", NULL, NULL, NULL), rc); } /* mail_text_tbl */ @@ -2235,6 +2363,37 @@ INTERNAL_FUNC int emstorage_create_table(emstorage_create_db_type_t type, int *e #endif +#ifdef __FEATURE_WIFI_AUTO_DOWNLOAD__ + /* create mail_auto_download_activity_tbl */ + sql = "SELECT count(name) FROM sqlite_master WHERE name='mail_auto_download_activity_tbl';"; + EMSTORAGE_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) { + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, "BEGIN;", NULL, NULL, NULL), rc); + EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {goto FINISH_OFF; }, ("SQL(BEGIN EXCLUSIVE) exec fail:%d -%s", rc, sqlite3_errmsg(local_db_handle))); + + EM_DEBUG_LOG("CREATE TABLE mail_auto_download_activity_tbl"); + + EM_SAFE_STRNCPY(sql_query_string, create_table_query[CREATE_TABLE_MAIL_AUTO_DOWNLOAD_ACTIVITY_TBL], sizeof(sql_query_string)-1); + error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); + if (error != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; + } + + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, "END;", NULL, NULL, NULL), rc); + } /* mail_auto_download_activity_tbl */ + else if (type == EMAIL_CREATE_DB_CHECK) { + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, g_test_query[CREATE_TABLE_MAIL_AUTO_DOWNLOAD_ACTIVITY_TBL], NULL, NULL, NULL), rc); + EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, ("SQL(%s) exec fail:%d -%s", g_test_query[CREATE_TABLE_MAIL_AUTO_DOWNLOAD_ACTIVITY_TBL], rc, sqlite3_errmsg(local_db_handle))); + } + + sqlite3_free_table(result); + result = NULL; +#endif + + ret = true; FINISH_OFF: @@ -2248,8 +2407,6 @@ FINISH_OFF: EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, "rollback", NULL, NULL, NULL), rc); } - _DISCONNECT_DB; - FINISH_OFF2: if (create_table_query) { int i = 0; @@ -2274,9 +2431,10 @@ INTERNAL_FUNC int emstorage_query_mail_count(const char *input_conditional_claus { EM_DEBUG_FUNC_BEGIN("input_conditional_clause[%p], input_transaction[%d], output_total_mail_count[%p], output_unseen_mail_count[%p]", input_conditional_clause, input_transaction, output_total_mail_count, output_unseen_mail_count); int rc = -1; + int query_size = 0; int error = EMAIL_ERROR_NONE; DB_STMT hStmt = NULL; - char sql_query_string[QUERY_SIZE] = {0, }; + char *sql_query_string = NULL; char **result; sqlite3 *local_db_handle = NULL; @@ -2285,12 +2443,19 @@ INTERNAL_FUNC int emstorage_query_mail_count(const char *input_conditional_claus return EMAIL_ERROR_INVALID_PARAM; } - memset(&sql_query_string, 0x00, sizeof(sql_query_string)); + query_size = EM_SAFE_STRLEN(input_conditional_clause) + QUERY_SIZE; + sql_query_string = em_malloc(query_size); + if (sql_query_string == NULL) { + EM_DEBUG_EXCEPTION("em_malloc failed"); + error = EMAIL_ERROR_OUT_OF_MEMORY; + goto FINISH_OFF; + } + local_db_handle = emstorage_get_db_connection(); EMSTORAGE_START_READ_TRANSACTION(input_transaction); - SNPRINTF(sql_query_string, QUERY_SIZE, "SELECT COUNT(*) FROM mail_tbl"); + SNPRINTF(sql_query_string, query_size, "SELECT COUNT(*) FROM mail_tbl"); EM_SAFE_STRCAT(sql_query_string, (char*)input_conditional_clause); if (output_total_mail_count) { @@ -2320,13 +2485,14 @@ FINISH_OFF: if (hStmt != NULL) { rc = sqlite3_finalize(hStmt); if (rc != SQLITE_OK) { - EM_DEBUG_LOG("sqlite3_finalize failed [%d]", rc); + EM_DEBUG_EXCEPTION ("sqlite3_finalize error [%d]", rc); error = EMAIL_ERROR_DB_FAILURE; } } EMSTORAGE_FINISH_READ_TRANSACTION(input_transaction); - _DISCONNECT_DB; + + EM_SAFE_FREE(sql_query_string); EM_DEBUG_FUNC_END("error [%d]", error); return error; @@ -2341,23 +2507,32 @@ INTERNAL_FUNC int emstorage_query_mail_id_list(const char *input_conditional_cla int rc = -1; int cur_query = 0; int col_index; + int query_size = 0; int error = EMAIL_ERROR_NONE; int *result_mail_id_list = NULL; char **result = NULL; - char sql_query_string[QUERY_SIZE] = {0, }; + char *sql_query_string = NULL; sqlite3 *local_db_handle = emstorage_get_db_connection(); EM_IF_NULL_RETURN_VALUE(input_conditional_clause, EMAIL_ERROR_INVALID_PARAM); EM_IF_NULL_RETURN_VALUE(output_mail_id_list, EMAIL_ERROR_INVALID_PARAM); EM_IF_NULL_RETURN_VALUE(output_mail_id_count, EMAIL_ERROR_INVALID_PARAM); + query_size = strlen(input_conditional_clause) + strlen("SELECT mail_id FROM mail_tbl ") + 10; // 10 is extra space + sql_query_string = em_malloc(query_size); + if (sql_query_string == NULL) { + EM_DEBUG_EXCEPTION("em_malloc failed"); + error = EMAIL_ERROR_OUT_OF_MEMORY; + goto FINISH_OFF; + } + EMSTORAGE_START_READ_TRANSACTION(input_transaction); /* Composing query */ - SNPRINTF_OFFSET(sql_query_string, cur_query, QUERY_SIZE, "SELECT mail_id FROM mail_tbl "); + SNPRINTF_OFFSET(sql_query_string, cur_query, query_size, "SELECT mail_id FROM mail_tbl "); EM_SAFE_STRCAT(sql_query_string, (char*)input_conditional_clause); - EM_DEBUG_LOG("query[%s].", sql_query_string); + EM_DEBUG_LOG_SEC("query[%s].", sql_query_string); /* Performing query */ EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, &count, 0, NULL), rc); @@ -2397,7 +2572,8 @@ FINISH_OFF: sqlite3_free_table(result); EMSTORAGE_FINISH_READ_TRANSACTION(input_transaction); - _DISCONNECT_DB; + + EM_SAFE_FREE(sql_query_string); if(error != EMAIL_ERROR_NONE) EM_SAFE_FREE(result_mail_id_list); @@ -2563,8 +2739,6 @@ FINISH_OFF: sqlite3_db_release_memory(local_db_handle); - _DISCONNECT_DB; - EM_SAFE_FREE(sql_query_string); EM_SAFE_FREE(date_time_string); @@ -2672,6 +2846,7 @@ INTERNAL_FUNC int emstorage_query_mail_tbl(const char *conditional_clause, int t _get_table_field_data_int (result, (int*)&(p_data_tbl[i].tag_id), col_index++); _get_table_field_data_int (result, (int*)&(p_data_tbl[i].replied_time), col_index++); _get_table_field_data_int (result, (int*)&(p_data_tbl[i].forwarded_time), col_index++); + _get_table_field_data_string(result, &(p_data_tbl[i].default_charset), 0, col_index++); _get_table_field_data_int (result, (int*)&(p_data_tbl[i].eas_data_length), col_index++); _get_table_field_data_blob (result, (void**)&(p_data_tbl[i].eas_data), p_data_tbl[i].eas_data_length, col_index++); } @@ -2695,8 +2870,6 @@ FINISH_OFF: sqlite3_db_release_memory(local_db_handle); - _DISCONNECT_DB; - if (err_code != NULL) *err_code = error; @@ -2731,7 +2904,7 @@ INTERNAL_FUNC int emstorage_query_mail_text_tbl(const char *conditional_clause, SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT * FROM mail_text_tbl %s", conditional_clause); - EM_DEBUG_LOG("Query [%s]", sql_query_string); + EM_DEBUG_LOG_SEC("Query [%s]", sql_query_string); EMSTORAGE_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 = EMAIL_ERROR_DB_FAILURE; sqlite3_free_table(result); goto FINISH_OFF; }, @@ -2776,8 +2949,6 @@ FINISH_OFF: sqlite3_db_release_memory(local_db_handle); - _DISCONNECT_DB; - if (err_code != NULL) *err_code = error; @@ -2811,7 +2982,7 @@ INTERNAL_FUNC int emstorage_query_mailbox_tbl(const char *input_conditional_clau } else { /* with read count and total count */ col_index = 17; - SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT %s, total, read FROM mail_box_tbl AS MBT LEFT OUTER JOIN (SELECT mailbox_id, count(mail_id) AS total, SUM(flags_seen_field) AS read FROM mail_tbl GROUP BY mailbox_id) AS MT ON MBT.mailbox_id = MT.mailbox_id %s %s", fields, input_conditional_clause, input_ordering_clause); + SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT %s, total, read FROM mail_box_tbl AS MBT LEFT OUTER JOIN (SELECT mailbox_id, count(mail_id) AS total, SUM(flags_seen_field) AS read FROM mail_tbl WHERE flags_deleted_field = 0 GROUP BY mailbox_id) AS MT ON MBT.mailbox_id = MT.mailbox_id %s %s", fields, input_conditional_clause, input_ordering_clause); } EM_DEBUG_LOG_DEV ("query[%s]", sql_query_string); @@ -2823,7 +2994,7 @@ INTERNAL_FUNC int emstorage_query_mailbox_tbl(const char *input_conditional_clau EM_DEBUG_LOG_DEV ("result count [%d]", count); if(count == 0) { - EM_DEBUG_LOG ("Can't find mailbox"); + EM_DEBUG_LOG_SEC ("Can't find mailbox query[%s]", sql_query_string); error = EMAIL_ERROR_MAILBOX_NOT_FOUND; goto FINISH_OFF; } @@ -2874,8 +3045,6 @@ FINISH_OFF: sqlite3_db_release_memory(local_db_handle); - _DISCONNECT_DB; - EM_DEBUG_FUNC_END("error [%d]", error); return error; } @@ -2917,7 +3086,7 @@ INTERNAL_FUNC int emstorage_check_duplicated_account(email_account_t* account, i account->incoming_server_user_name, account->incoming_server_type, account->incoming_server_address, account->outgoing_server_user_name, account->outgoing_server_type, account->outgoing_server_address ); - EM_DEBUG_LOG("Query[%s]", sql_query_string); + EM_DEBUG_LOG_SEC("Query[%s]", sql_query_string); EMSTORAGE_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 = EMAIL_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))); @@ -2940,7 +3109,6 @@ INTERNAL_FUNC int emstorage_check_duplicated_account(email_account_t* account, i FINISH_OFF: EMSTORAGE_FINISH_READ_TRANSACTION(transaction); - _DISCONNECT_DB; if (err_code != NULL) *err_code = error; @@ -2965,13 +3133,13 @@ INTERNAL_FUNC int emstorage_get_account_count(int *count, int transaction, int * DB_STMT hStmt = NULL; char sql_query_string[QUERY_SIZE] = {0, }; - char err_msg[1024]; + sqlite3 *local_db_handle = emstorage_get_db_connection(); EMSTORAGE_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); - EMSTORAGE_PROTECTED_FUNC_CALL (sqlite3_prepare_v2 (local_db_handle, sql_query_string, + EM_DEBUG_LOG_SEC("SQL STMT [%s]", sql_query_string); + EMSTORAGE_PROTECTED_FUNC_CALL (sqlite3_prepare_v2 (local_db_handle, sql_query_string, EM_SAFE_STRLEN (sql_query_string), &hStmt, NULL), rc); EM_DEBUG_LOG("Before sqlite3_prepare hStmt = %p", hStmt); EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, @@ -2988,19 +3156,15 @@ INTERNAL_FUNC int emstorage_get_account_count(int *count, int transaction, int * 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); + EM_DEBUG_EXCEPTION ("sqlite3_finalize error [%d]", rc); error = EMAIL_ERROR_DB_FAILURE; } - EM_DEBUG_LOG("sqlite3_finalize- %d", rc); } EMSTORAGE_FINISH_READ_TRANSACTION(transaction); - _DISCONNECT_DB; if (err_code != NULL) *err_code = error; @@ -3016,6 +3180,7 @@ INTERNAL_FUNC int emstorage_get_account_list(int *select_num, emstorage_account_ int i = 0, count = 0, rc = -1, ret = false; int field_index = 0; + int sql_len = 0; int error = EMAIL_ERROR_NONE; emstorage_account_tbl_t *p_data_tbl = NULL; char sql_query_string[QUERY_SIZE] = {0, }; @@ -3049,7 +3214,81 @@ INTERNAL_FUNC int emstorage_get_account_list(int *select_num, emstorage_account_ ret = true; goto FINISH_OFF; } - SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT * FROM mail_account_tbl ORDER BY account_id"); + SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT "); + sql_len = EM_SAFE_STRLEN(sql_query_string); + + SNPRINTF(sql_query_string + sql_len, sizeof(sql_query_string) - sql_len, + "account_id, " + "account_name, " + "logo_icon_path, " + "user_data, " + "user_data_length, " + "account_svc_id, " + "sync_status, " + "sync_disabled, " + "default_mail_slot_size, " + "roaming_option, " + "color_label, " + "user_display_name, " + "user_email_address, " + "reply_to_address, " + "return_address, " + "incoming_server_type, " + "incoming_server_address, " + "incoming_server_port_number, " + "incoming_server_user_name, " + "incoming_server_password, " + "incoming_server_secure_connection, " + "incoming_server_authentication_method, " + "retrieval_mode, " + "keep_mails_on_pop_server_after_download, " + "check_interval, " + "auto_download_size, " + "peak_interval, " + "peak_days, " + "peak_start_time, " + "peak_end_time, " + "outgoing_server_type, " + "outgoing_server_address, " + "outgoing_server_port_number, " + "outgoing_server_user_name, " + "outgoing_server_password, " + "outgoing_server_secure_connection, " + "outgoing_server_need_authentication, " + "outgoing_server_use_same_authenticator, " + "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, " + "notification_status, " + "vibrate_status, " + "display_content_status, " + "default_ringtone_status, " + "alert_ringtone_path, " + "auto_resend_times, " + "outgoing_server_size_limit, " + "wifi_auto_download, " + "pop_before_smtp, " + "incoming_server_requires_apop, " + "smime_type, " + "certificate_path, " + "cipher_type, " + "digest_type" + ); + + sql_len = EM_SAFE_STRLEN(sql_query_string); + + SNPRINTF(sql_query_string + sql_len, sizeof(sql_query_string) - sql_len, " FROM mail_account_tbl ORDER BY account_id"); EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); @@ -3088,6 +3327,7 @@ INTERNAL_FUNC int emstorage_get_account_list(int *select_num, emstorage_account_ _get_stmt_field_data_int(hStmt, (int*)&(p_data_tbl[i].sync_disabled), field_index++); _get_stmt_field_data_int(hStmt, (int*)&(p_data_tbl[i].default_mail_slot_size), field_index++); _get_stmt_field_data_int(hStmt, (int*)&(p_data_tbl[i].roaming_option), field_index++); + _get_stmt_field_data_int(hStmt, (int*)&(p_data_tbl[i].color_label), field_index++); _get_stmt_field_data_string(hStmt, &(p_data_tbl[i].user_display_name), 0, field_index++); _get_stmt_field_data_string(hStmt, &(p_data_tbl[i].user_email_address), 0, field_index++); _get_stmt_field_data_string(hStmt, &(p_data_tbl[i].reply_to_address), 0, field_index++); @@ -3129,8 +3369,14 @@ INTERNAL_FUNC int emstorage_get_account_list(int *select_num, emstorage_account_ _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].options.add_signature), field_index++); _get_stmt_field_data_string(hStmt, &(p_data_tbl[i].options.signature), 0, field_index++); _get_stmt_field_data_int(hStmt, (int*)&(p_data_tbl[i].options.add_my_address_to_bcc), field_index++); + _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].options.notification_status), field_index++); + _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].options.vibrate_status), field_index++); + _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].options.display_content_status), field_index++); + _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].options.default_ringtone_status), field_index++); + _get_stmt_field_data_string(hStmt, &(p_data_tbl[i].options.alert_ringtone_path), 0, field_index++); _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].auto_resend_times), field_index++); _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].outgoing_server_size_limit), field_index++); + _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].wifi_auto_download), field_index++); _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].pop_before_smtp), field_index++); _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].incoming_server_requires_apop), field_index++); _get_stmt_field_data_int(hStmt, (int *)&(p_data_tbl[i].smime_type), field_index++); @@ -3141,28 +3387,36 @@ INTERNAL_FUNC int emstorage_get_account_list(int *select_num, emstorage_account_ /* EAS passwd is not accessible */ if (with_password == true && p_data_tbl[i].incoming_server_type != EMAIL_SERVER_TYPE_ACTIVE_SYNC) { /* get password from the secure storage */ - char recv_password_file_name[MAX_PW_FILE_NAME_LENGTH]; - char send_password_file_name[MAX_PW_FILE_NAME_LENGTH]; + char recv_password_file_name[MAX_PW_FILE_NAME_LENGTH] = {0}; + char send_password_file_name[MAX_PW_FILE_NAME_LENGTH] = {0}; EM_SAFE_FREE(p_data_tbl[i].incoming_server_password); EM_SAFE_FREE(p_data_tbl[i].outgoing_server_password); /* get password file name */ - if ((error = _get_password_file_name(p_data_tbl[i].account_id, recv_password_file_name, send_password_file_name)) != EMAIL_ERROR_NONE) { - EM_DEBUG_EXCEPTION("_get_password_file_name failed. [%d]", error); + error = _get_password_file_name (p_data_tbl[i].account_id, + recv_password_file_name, + send_password_file_name); + if (error != EMAIL_ERROR_NONE){ + EM_DEBUG_EXCEPTION("_get_password_file_name error [%d]", error); error = EMAIL_ERROR_SECURED_STORAGE_FAILURE; goto FINISH_OFF; } /* read password from secure storage */ - if ((error = _read_password_from_secure_storage(recv_password_file_name, &(p_data_tbl[i].incoming_server_password))) < 0 ) { - EM_DEBUG_EXCEPTION("_read_password_from_secure_storage() failed. [%d]", error); + error = _read_password_from_secure_storage (recv_password_file_name, + &(p_data_tbl[i].incoming_server_password)); + if (error < 0 ) { + EM_DEBUG_EXCEPTION("_read_password_from_secure_storage()[%s] error [%d]", + recv_password_file_name, error); error = EMAIL_ERROR_SECURED_STORAGE_FAILURE; goto FINISH_OFF; } - - if ((error = _read_password_from_secure_storage(send_password_file_name, &(p_data_tbl[i].outgoing_server_password))) < 0) { - EM_DEBUG_EXCEPTION("_read_password_from_secure_storage() failed. [%d]", error); + error = _read_password_from_secure_storage (send_password_file_name, + &(p_data_tbl[i].outgoing_server_password)); + if (error < 0) { + EM_DEBUG_EXCEPTION("_read_password_from_secure_storage()[%s] error [%d]", + send_password_file_name, error); error = EMAIL_ERROR_SECURED_STORAGE_FAILURE; goto FINISH_OFF; } @@ -3186,18 +3440,15 @@ FINISH_OFF: emstorage_free_account(&p_data_tbl, count, NULL); if (hStmt != NULL) { - EM_DEBUG_LOG_DEV("Before sqlite3_finalize hStmt = %p", hStmt); - rc = sqlite3_finalize(hStmt); hStmt = NULL; if (rc != SQLITE_OK) { - EM_DEBUG_EXCEPTION("sqlite3_finalize failed - %d", rc); + EM_DEBUG_EXCEPTION("sqlite3_finalize error [%d]", rc); error = EMAIL_ERROR_DB_FAILURE; } } EMSTORAGE_FINISH_READ_TRANSACTION(transaction); - _DISCONNECT_DB; if (err_code != NULL) *err_code = error; @@ -3257,12 +3508,7 @@ static int _write_conditional_clause_for_getting_mail_list(int account_id, int m } /* 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, 8)"): - SNPRINTF_OFFSET(conditional_clause_string, cur_clause, buffer_size - cur_clause, " AND mailbox_type not in (3, 5, 7, 8)"); - } - else { + if (account_id != ALL_ACCOUNT) { 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); @@ -3273,11 +3519,6 @@ static int _write_conditional_clause_for_getting_mail_list(int account_id, int m SNPRINTF_OFFSET(conditional_clause_string, cur_clause, buffer_size - cur_clause, " WHERE mailbox_id = %d", mailbox_id): SNPRINTF_OFFSET(conditional_clause_string, cur_clause, buffer_size - cur_clause, " AND mailbox_id = %d", mailbox_id); } - 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, 8)"): - SNPRINTF_OFFSET(conditional_clause_string, cur_clause, buffer_size - cur_clause, " AND mailbox_type not in (3, 5, 7, 8)"); - } if (thread_id > 0) { cur_clause += (conditional_clause_count++ == 0)? @@ -3567,41 +3808,18 @@ static int _read_password_from_secure_storage(char *file_name, char **password) return EMAIL_ERROR_INVALID_PARAM; } - size_t buf_len = 0, read_len = 0; - ssm_file_info_t sfi; - char *temp_password = NULL; int error_code_from_ssm = 0; int ret = EMAIL_ERROR_NONE; - if ( (error_code_from_ssm = ssm_getinfo(file_name, &sfi, SSM_FLAG_SECRET_OPERATION, NULL)) < 0) { - EM_DEBUG_EXCEPTION("ssm_getinfo() failed. [%d]", error_code_from_ssm); - ret = EMAIL_ERROR_SECURED_STORAGE_FAILURE; - goto FINISH_OFF; - } - - buf_len = sfi.originSize; - EM_DEBUG_LOG_DEV ("password buf_len[%d]", buf_len); - if ((temp_password = (char *)malloc(buf_len + 1)) == NULL) { - EM_DEBUG_EXCEPTION("malloc failed..."); - ret = EMAIL_ERROR_OUT_OF_MEMORY; - goto FINISH_OFF; - } - memset(temp_password, 0x00, buf_len + 1); - - if ( (error_code_from_ssm = ssm_read(file_name, temp_password, buf_len, &read_len, SSM_FLAG_SECRET_OPERATION, NULL)) < 0) { - EM_DEBUG_EXCEPTION("ssm_read() failed. [%d]", error_code_from_ssm); + /* Genral secure sotrage */ + ENTER_CRITICAL_SECTION(_ss_handle_lock); + error_code_from_ssm = ssa_get (file_name, password, ACCOUNT_PASSWORD_SS_GROUP_ID, NULL); + LEAVE_CRITICAL_SECTION(_ss_handle_lock); + if (error_code_from_ssm < 0) { + EM_DEBUG_EXCEPTION("ssa_get[%s] error [%d]", file_name, error_code_from_ssm); ret = EMAIL_ERROR_SECURED_STORAGE_FAILURE; - goto FINISH_OFF; } - EM_DEBUG_LOG_DEV("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; } @@ -3664,11 +3882,13 @@ INTERNAL_FUNC int emstorage_get_account_by_id(int account_id, int pulloption, em "outgoing_server_use_same_authenticator," "auto_resend_times," "outgoing_server_size_limit," + "wifi_auto_download," "pop_before_smtp," "incoming_server_requires_apop," "logo_icon_path," "user_data," "user_data_length," + "color_label," "check_interval," "sync_status,"); sql_len = EM_SAFE_STRLEN(sql_query_string); @@ -3696,6 +3916,11 @@ INTERNAL_FUNC int emstorage_get_account_by_id(int account_id, int pulloption, em "add_signature," "signature," "add_my_address_to_bcc," + "notification_status," + "vibrate_status," + "display_content_status," + "default_ringtone_status," + "alert_ringtone_path," "account_svc_id," "sync_disabled," "default_mail_slot_size," @@ -3712,7 +3937,7 @@ INTERNAL_FUNC int emstorage_get_account_by_id(int account_id, int pulloption, em 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); + EM_DEBUG_LOG_SEC("query = [%s]", sql_query_string); /* execute a sql and count rows */ EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); @@ -3767,11 +3992,13 @@ INTERNAL_FUNC int emstorage_get_account_by_id(int account_id, int pulloption, em _get_stmt_field_data_int(hStmt, &(p_data_tbl->outgoing_server_use_same_authenticator), col_index++); _get_stmt_field_data_int(hStmt, &(p_data_tbl->auto_resend_times), col_index++); _get_stmt_field_data_int(hStmt, &(p_data_tbl->outgoing_server_size_limit), col_index++); + _get_stmt_field_data_int(hStmt, &(p_data_tbl->wifi_auto_download), col_index++); _get_stmt_field_data_int(hStmt, &(p_data_tbl->pop_before_smtp), col_index++); _get_stmt_field_data_int(hStmt, &(p_data_tbl->incoming_server_requires_apop), col_index++); _get_stmt_field_data_string(hStmt, &(p_data_tbl->logo_icon_path), 0, col_index++); _get_stmt_field_data_blob(hStmt, &p_data_tbl->user_data, col_index++); _get_stmt_field_data_int(hStmt, &p_data_tbl->user_data_length, col_index++); + _get_stmt_field_data_int(hStmt, &p_data_tbl->color_label, col_index++); _get_stmt_field_data_int(hStmt, &(p_data_tbl->check_interval), col_index++); _get_stmt_field_data_int(hStmt, &(p_data_tbl->sync_status), col_index++); } @@ -3794,11 +4021,13 @@ INTERNAL_FUNC int emstorage_get_account_by_id(int account_id, int pulloption, em EM_DEBUG_LOG_DEV ("recv_password_file_name[%s], password[%s]", recv_password_file_name, p_data_tbl->incoming_server_password); - if ((error = _read_password_from_secure_storage(send_password_file_name, &(p_data_tbl->outgoing_server_password))) < 0) { - EM_DEBUG_EXCEPTION(" _read_password_from_secure_storage failed [%d]", error); - goto FINISH_OFF; + if (p_data_tbl->outgoing_server_use_same_authenticator == 0) { + if ((error = _read_password_from_secure_storage(send_password_file_name, &(p_data_tbl->outgoing_server_password))) < 0) { + EM_DEBUG_EXCEPTION(" _read_password_from_secure_storage failed [%d]", error); + goto FINISH_OFF; + } + EM_DEBUG_LOG_DEV ("send_password_file_name[%s], password[%s]", send_password_file_name, p_data_tbl->outgoing_server_password); } - EM_DEBUG_LOG_DEV ("send_password_file_name[%s], password[%s]", send_password_file_name, p_data_tbl->outgoing_server_password); } if (pulloption & EMAIL_ACC_GET_OPT_OPTIONS) { @@ -3816,6 +4045,11 @@ INTERNAL_FUNC int emstorage_get_account_by_id(int account_id, int pulloption, em _get_stmt_field_data_int(hStmt, &(p_data_tbl->options.add_signature), col_index++); _get_stmt_field_data_string(hStmt, &(p_data_tbl->options.signature), 0, col_index++); _get_stmt_field_data_int(hStmt, (int*)&(p_data_tbl->options.add_my_address_to_bcc), col_index++); + _get_stmt_field_data_int(hStmt, (int*)&(p_data_tbl->options.notification_status), col_index++); + _get_stmt_field_data_int(hStmt, (int*)&(p_data_tbl->options.vibrate_status), col_index++); + _get_stmt_field_data_int(hStmt, (int*)&(p_data_tbl->options.display_content_status), col_index++); + _get_stmt_field_data_int(hStmt, (int*)&(p_data_tbl->options.default_ringtone_status), col_index++); + _get_stmt_field_data_string(hStmt, &(p_data_tbl->options.alert_ringtone_path), 0, col_index++); _get_stmt_field_data_int(hStmt, &(p_data_tbl->account_svc_id), col_index++); _get_stmt_field_data_int(hStmt, (int*)&(p_data_tbl->sync_disabled), col_index++); _get_stmt_field_data_int(hStmt, (int*)&(p_data_tbl->default_mail_slot_size), col_index++); @@ -3838,13 +4072,12 @@ FINISH_OFF: if (hStmt != NULL) { rc = sqlite3_finalize(hStmt); if (rc != SQLITE_OK) { - EM_DEBUG_EXCEPTION("sqlite3_finalize failed - %d", rc); + EM_DEBUG_EXCEPTION("sqlite3_finalize error [%d]", rc); error = EMAIL_ERROR_DB_FAILURE; } } EMSTORAGE_FINISH_READ_TRANSACTION(transaction); - _DISCONNECT_DB; if (err_code != NULL) *err_code = error; @@ -3920,7 +4153,7 @@ INTERNAL_FUNC int emstorage_update_account_password(int input_account_id, char * char recv_password_file_name[MAX_PW_FILE_NAME_LENGTH]; char send_password_file_name[MAX_PW_FILE_NAME_LENGTH]; - if(input_incoming_server_password == NULL || input_outgoing_server_password == NULL) { + if(input_incoming_server_password == NULL && input_outgoing_server_password == NULL) { EM_DEBUG_EXCEPTION_SEC("Invalid param"); err = EMAIL_ERROR_INVALID_PARAM; goto FINISH_OFF; @@ -3935,29 +4168,35 @@ INTERNAL_FUNC int emstorage_update_account_password(int input_account_id, char * EM_DEBUG_LOG_SEC("recv_password_file_name [%s] input_incoming_server_password [%s]", recv_password_file_name, input_incoming_server_password); EM_DEBUG_LOG_SEC("send_password_file_name [%s] input_outgoing_server_password [%s]", send_password_file_name, input_outgoing_server_password); - if ((err_from_ssm = ssm_delete_file(recv_password_file_name, SSM_FLAG_SECRET_OPERATION, NULL)) < 0) { - EM_DEBUG_EXCEPTION_SEC(" ssm_delete_file failed -recv password : file[%s]", recv_password_file_name); - err = EMAIL_ERROR_SYSTEM_FAILURE; - goto FINISH_OFF; - } - - /* save passwords to the secure storage */ - if ((err_from_ssm = ssm_write_buffer(input_incoming_server_password, EM_SAFE_STRLEN(input_incoming_server_password), recv_password_file_name, SSM_FLAG_SECRET_OPERATION, NULL)) < 0) { - EM_DEBUG_EXCEPTION_SEC(" ssm_write_buffer failed [%d] -recv incoming_server_password : file[%s]", err_from_ssm, recv_password_file_name); - err = EMAIL_ERROR_SYSTEM_FAILURE; - goto FINISH_OFF; - } - - if ((err_from_ssm = ssm_delete_file(send_password_file_name, SSM_FLAG_SECRET_OPERATION, NULL)) < 0) { - EM_DEBUG_EXCEPTION_SEC(" ssm_delete_file failed -send password : file[%s]", send_password_file_name); - err = EMAIL_ERROR_SYSTEM_FAILURE; - goto FINISH_OFF; + /* general secure-storage */ + if (input_incoming_server_password) { + ENTER_CRITICAL_SECTION(_ss_handle_lock); + err_from_ssm = ssa_put (recv_password_file_name, + input_incoming_server_password, + strlen (input_incoming_server_password)+1, /*must include null*/ + ACCOUNT_PASSWORD_SS_GROUP_ID, + NULL); + LEAVE_CRITICAL_SECTION(_ss_handle_lock); + if (err_from_ssm < 0) { + EM_DEBUG_EXCEPTION_SEC("ssa_put[%s] error[%d]", recv_password_file_name, err_from_ssm); + err = EMAIL_ERROR_SECURED_STORAGE_FAILURE; + goto FINISH_OFF; + } } - if ((err_from_ssm = ssm_write_buffer(input_outgoing_server_password, EM_SAFE_STRLEN(input_outgoing_server_password), send_password_file_name, SSM_FLAG_SECRET_OPERATION, NULL)) < 0) { - EM_DEBUG_EXCEPTION_SEC(" ssm_write_buffer failed [%d] -send password : file[%s]", err_from_ssm, send_password_file_name); - err = EMAIL_ERROR_SYSTEM_FAILURE; - goto FINISH_OFF; + if (input_outgoing_server_password) { + ENTER_CRITICAL_SECTION(_ss_handle_lock); + err_from_ssm = ssa_put (send_password_file_name, + input_outgoing_server_password, + strlen(input_outgoing_server_password)+1, /*must include null*/ + ACCOUNT_PASSWORD_SS_GROUP_ID, + NULL); + LEAVE_CRITICAL_SECTION(_ss_handle_lock); + if (err_from_ssm < 0) { + EM_DEBUG_EXCEPTION_SEC("ssa_put[%s] error[%d]", send_password_file_name, err_from_ssm); + err = EMAIL_ERROR_SECURED_STORAGE_FAILURE; + goto FINISH_OFF; + } } FINISH_OFF: @@ -3997,6 +4236,7 @@ INTERNAL_FUNC int emstorage_update_account(int account_id, emstorage_account_tbl ", sync_disabled = ?" ", default_mail_slot_size = ?" ", roaming_option = ?" + ", color_label = ?" ", user_display_name = ?" ", user_email_address = ?" ", reply_to_address = ?" @@ -4036,8 +4276,14 @@ INTERNAL_FUNC int emstorage_update_account(int account_id, emstorage_account_tbl ", add_signature = ?" ", signature = ?" ", add_my_address_to_bcc = ?" + ", notification_status = ?" + ", vibrate_status = ?" + ", display_content_status = ?" + ", default_ringtone_status = ?" + ", alert_ringtone_path = ?" ", auto_resend_times = ?" ", outgoing_server_size_limit = ?" + ", wifi_auto_download = ?" ", pop_before_smtp = ?" ", incoming_server_requires_apop = ?" ", smime_type = ?" @@ -4048,7 +4294,7 @@ INTERNAL_FUNC int emstorage_update_account(int account_id, emstorage_account_tbl EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); EM_DEBUG_LOG("After sqlite3_prepare hStmt = %p", hStmt); - EM_DEBUG_LOG("SQL[%s]", sql_query_string); + EM_DEBUG_LOG_SEC("SQL[%s]", sql_query_string); EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, ("sqlite3_prepare fail:(%d) %s", rc, sqlite3_errmsg(local_db_handle))); @@ -4063,6 +4309,7 @@ INTERNAL_FUNC int emstorage_update_account(int account_id, emstorage_account_tbl _bind_stmt_field_data_int(hStmt, i++, account_tbl->sync_disabled); _bind_stmt_field_data_int(hStmt, i++, account_tbl->default_mail_slot_size); _bind_stmt_field_data_int(hStmt, i++, account_tbl->roaming_option); + _bind_stmt_field_data_int(hStmt, i++, account_tbl->color_label); _bind_stmt_field_data_string(hStmt, i++, (char *)account_tbl->user_display_name, 0, DISPLAY_NAME_LEN_IN_MAIL_ACCOUNT_TBL); _bind_stmt_field_data_string(hStmt, i++, (char *)account_tbl->user_email_address, 0, EMAIL_ADDR_LEN_IN_MAIL_ACCOUNT_TBL); _bind_stmt_field_data_string(hStmt, i++, (char *)account_tbl->reply_to_address, 0, REPLY_TO_ADDR_LEN_IN_MAIL_ACCOUNT_TBL); @@ -4102,8 +4349,14 @@ INTERNAL_FUNC int emstorage_update_account(int account_id, emstorage_account_tbl _bind_stmt_field_data_int(hStmt, i++, account_tbl->options.add_signature); _bind_stmt_field_data_string(hStmt, i++, account_tbl->options.signature, 0, SIGNATURE_LEN_IN_MAIL_ACCOUNT_TBL); _bind_stmt_field_data_int(hStmt, i++, account_tbl->options.add_my_address_to_bcc); + _bind_stmt_field_data_int(hStmt, i++, account_tbl->options.notification_status); + _bind_stmt_field_data_int(hStmt, i++, account_tbl->options.vibrate_status); + _bind_stmt_field_data_int(hStmt, i++, account_tbl->options.display_content_status); + _bind_stmt_field_data_int(hStmt, i++, account_tbl->options.default_ringtone_status); + _bind_stmt_field_data_string(hStmt, i++, account_tbl->options.alert_ringtone_path, 0, CERTIFICATE_PATH_LEN_IN_MAIL_ACCOUNT_TBL); _bind_stmt_field_data_int(hStmt, i++, account_tbl->auto_resend_times); _bind_stmt_field_data_int(hStmt, i++, account_tbl->outgoing_server_size_limit); + _bind_stmt_field_data_int(hStmt, i++, account_tbl->wifi_auto_download); _bind_stmt_field_data_int(hStmt, i++, account_tbl->pop_before_smtp); _bind_stmt_field_data_int(hStmt, i++, account_tbl->incoming_server_requires_apop); _bind_stmt_field_data_int(hStmt, i++, account_tbl->smime_type); @@ -4126,23 +4379,22 @@ INTERNAL_FUNC int emstorage_update_account(int account_id, emstorage_account_tbl goto FINISH_OFF; } - if((error = emstorage_update_account_password(account_id, account_tbl->incoming_server_password, account_tbl->outgoing_server_password)) != EMAIL_ERROR_NONE) { - EM_DEBUG_EXCEPTION("emstorage_update_account_password failed [%d]", error); - goto FINISH_OFF; + if (account_tbl->incoming_server_password || account_tbl->outgoing_server_password) { + if((error = emstorage_update_account_password(account_id, account_tbl->incoming_server_password, account_tbl->outgoing_server_password)) != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emstorage_update_account_password failed [%d]", error); + goto FINISH_OFF; + } } ret = true; FINISH_OFF: EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error); - _DISCONNECT_DB; 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); + EM_DEBUG_EXCEPTION ("sqlite3_finalize error [%d]", rc); error = EMAIL_ERROR_DB_FAILURE; } } @@ -4163,7 +4415,6 @@ INTERNAL_FUNC int emstorage_set_field_of_accounts_with_integer_value(int account { EM_DEBUG_FUNC_BEGIN_SEC("account_id[%d], field_name[%s], value[%d], transaction[%d]", account_id, field_name, value, transaction); int error = EMAIL_ERROR_NONE; - int rc = 0; int result = 0; char sql_query_string[QUERY_SIZE] = {0, }; sqlite3 *local_db_handle = NULL; @@ -4178,13 +4429,17 @@ INTERNAL_FUNC int emstorage_set_field_of_accounts_with_integer_value(int account /* Write query string */ SNPRINTF(sql_query_string, QUERY_SIZE, "UPDATE mail_account_tbl SET %s = %d WHERE account_id = %d", field_name, value, account_id); - EM_DEBUG_LOG("sql_query_string [%s]", sql_query_string); + EM_DEBUG_LOG_SEC("sql_query_string [%s]", sql_query_string); /* Execute query */ EMSTORAGE_START_WRITE_TRANSACTION(transaction, error); - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc); - EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, - ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + + error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); + if (error != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; + } + if (sqlite3_changes(local_db_handle) == 0) EM_DEBUG_LOG("no mail matched..."); @@ -4192,7 +4447,6 @@ INTERNAL_FUNC int emstorage_set_field_of_accounts_with_integer_value(int account FINISH_OFF: result = (error == EMAIL_ERROR_NONE) ? true : false; EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, result, error); - _DISCONNECT_DB; if (error == EMAIL_ERROR_NONE) { if (!emcore_notify_storage_event (NOTI_ACCOUNT_UPDATE, account_id, 0, field_name, value)) @@ -4249,7 +4503,6 @@ INTERNAL_FUNC int emstorage_get_sync_status_of_account(int account_id, int *resu FINISH_OFF: - _DISCONNECT_DB; if (err_code != NULL) *err_code = error; @@ -4295,11 +4548,13 @@ INTERNAL_FUNC int emstorage_update_sync_status_of_account(int account_id, email_ else SNPRINTF(sql_query_string, sizeof(sql_query_string), "UPDATE mail_account_tbl SET sync_status = %d WHERE incoming_server_type <> 5", set_value); - EM_DEBUG_LOG("sql_query_string [%s]", sql_query_string); + EM_DEBUG_LOG_SEC("sql_query_string [%s]", sql_query_string); - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc); - EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, - ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); + if (error != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; + } rc = sqlite3_changes(local_db_handle); @@ -4313,7 +4568,6 @@ INTERNAL_FUNC int emstorage_update_sync_status_of_account(int account_id, email_ FINISH_OFF: EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error); - _DISCONNECT_DB; if (error == EMAIL_ERROR_NONE) { if (!emcore_notify_storage_event (NOTI_ACCOUNT_UPDATE_SYNC_STATUS, account_id, set_value, NULL, 0)) @@ -4383,6 +4637,7 @@ INTERNAL_FUNC int emstorage_add_account(emstorage_account_tbl_t* account_tbl, in " , ? " /* sync_disabled */ " , ? " /* default_mail_slot_size */ " , ? " /* roaming_option */ + " , ? " /* color_label */ " , ? " /* user_display_name */ " , ? " /* user_email_address */ " , ? " /* reply_to_address */ @@ -4426,19 +4681,24 @@ INTERNAL_FUNC int emstorage_add_account(emstorage_account_tbl_t* account_tbl, in " , ? " /* add_my_address_to_bcc */ " , ? " /* auto_resend_times */ " , ? " /* outgoing_server_size_limit */ + " , ? " /* wifi_auto_download */ " , ? " /* pop_before_smtp */ " , ? " /* incoming_server_requires_apop */ " , ? " /* smime_type */ " , ? " /* certificate_path */ " , ? " /* cipher_type */ " , ? " /* digest_type */ + " , ? " /* notification_status */ + " , ? " /* vibrate_status */ + " , ? " /* display_content_status */ + " , ? " /* default_ringtone_status */ + " , ? " /* alert_ringtone_path */ ") "); EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); - EM_DEBUG_LOG(">>>> SQL STMT [ %s ] ", sql_query_string); int i = 0; _bind_stmt_field_data_int(hStmt, i++, account_tbl->account_id); @@ -4451,6 +4711,7 @@ INTERNAL_FUNC int emstorage_add_account(emstorage_account_tbl_t* account_tbl, in _bind_stmt_field_data_int(hStmt, i++, account_tbl->sync_disabled); _bind_stmt_field_data_int(hStmt, i++, account_tbl->default_mail_slot_size); _bind_stmt_field_data_int(hStmt, i++, account_tbl->roaming_option); + _bind_stmt_field_data_int(hStmt, i++, account_tbl->color_label); _bind_stmt_field_data_string(hStmt, i++, (char *)account_tbl->user_display_name, 0, DISPLAY_NAME_LEN_IN_MAIL_ACCOUNT_TBL); _bind_stmt_field_data_string(hStmt, i++, (char *)account_tbl->user_email_address, 0, EMAIL_ADDR_LEN_IN_MAIL_ACCOUNT_TBL); _bind_stmt_field_data_string(hStmt, i++, (char *)account_tbl->reply_to_address, 0, REPLY_TO_ADDR_LEN_IN_MAIL_ACCOUNT_TBL); @@ -4494,12 +4755,18 @@ INTERNAL_FUNC int emstorage_add_account(emstorage_account_tbl_t* account_tbl, in _bind_stmt_field_data_int(hStmt, i++, account_tbl->options.add_my_address_to_bcc); _bind_stmt_field_data_int(hStmt, i++, account_tbl->auto_resend_times); _bind_stmt_field_data_int(hStmt, i++, account_tbl->outgoing_server_size_limit); + _bind_stmt_field_data_int(hStmt, i++, account_tbl->wifi_auto_download); _bind_stmt_field_data_int(hStmt, i++, account_tbl->pop_before_smtp); _bind_stmt_field_data_int(hStmt, i++, account_tbl->incoming_server_requires_apop); _bind_stmt_field_data_int(hStmt, i++, account_tbl->smime_type); _bind_stmt_field_data_string(hStmt, i++, account_tbl->certificate_path, 0, FILE_NAME_LEN_IN_MAIL_CERTIFICATE_TBL); _bind_stmt_field_data_int(hStmt, i++, account_tbl->cipher_type); _bind_stmt_field_data_int(hStmt, i++, account_tbl->digest_type); + _bind_stmt_field_data_int(hStmt, i++, account_tbl->options.notification_status); + _bind_stmt_field_data_int(hStmt, i++, account_tbl->options.vibrate_status); + _bind_stmt_field_data_int(hStmt, i++, account_tbl->options.display_content_status); + _bind_stmt_field_data_int(hStmt, i++, account_tbl->options.default_ringtone_status); + _bind_stmt_field_data_string(hStmt, i++, account_tbl->options.alert_ringtone_path, 0, CERTIFICATE_PATH_LEN_IN_MAIL_ACCOUNT_TBL); EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc); @@ -4511,14 +4778,25 @@ INTERNAL_FUNC int emstorage_add_account(emstorage_account_tbl_t* account_tbl, in /* save passwords to the secure storage */ EM_DEBUG_LOG_SEC("save to the secure storage : recv_file[%s], send_file[%s]", recv_password_file_name, send_password_file_name); - if ( (error_from_ssm = ssm_write_buffer(account_tbl->incoming_server_password, EM_SAFE_STRLEN(account_tbl->incoming_server_password), recv_password_file_name, SSM_FLAG_SECRET_OPERATION, NULL)) < 0) { - EM_DEBUG_EXCEPTION_SEC("ssm_write_buffer failed [%d] - recv password : file[%s]", error_from_ssm, recv_password_file_name); - error = EMAIL_ERROR_SYSTEM_FAILURE; + + error_from_ssm = ssa_put (recv_password_file_name, + account_tbl->incoming_server_password, + EM_SAFE_STRLEN(account_tbl->incoming_server_password)+1, /*must include null*/ + ACCOUNT_PASSWORD_SS_GROUP_ID, NULL); + if (error_from_ssm < 0) { + EM_DEBUG_EXCEPTION("ssa_put[%s] error [%d]", recv_password_file_name, error_from_ssm); + error = EMAIL_ERROR_SECURED_STORAGE_FAILURE; goto FINISH_OFF; } - if ( (error_from_ssm = ssm_write_buffer(account_tbl->outgoing_server_password, EM_SAFE_STRLEN(account_tbl->outgoing_server_password), send_password_file_name, SSM_FLAG_SECRET_OPERATION, NULL)) < 0) { - EM_DEBUG_EXCEPTION_SEC("ssm_write_buffer failed [%d] - send password : file[%s]", error_from_ssm, send_password_file_name); - error = EMAIL_ERROR_SYSTEM_FAILURE; + + error_from_ssm = ssa_put (send_password_file_name, + account_tbl->outgoing_server_password, + EM_SAFE_STRLEN(account_tbl->outgoing_server_password)+1, /*must include null*/ + ACCOUNT_PASSWORD_SS_GROUP_ID, + NULL); + if (error_from_ssm < 0) { + EM_DEBUG_EXCEPTION("ssa_put[%s] error [%d]", send_password_file_name, error_from_ssm); + error = EMAIL_ERROR_SECURED_STORAGE_FAILURE; goto FINISH_OFF; } @@ -4526,12 +4804,11 @@ INTERNAL_FUNC int emstorage_add_account(emstorage_account_tbl_t* account_tbl, in FINISH_OFF: EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error); - _DISCONNECT_DB; if (hStmt != NULL) { rc = sqlite3_finalize(hStmt); if (rc != SQLITE_OK) { - EM_DEBUG_LOG("sqlite3_finalize failed [%d]", rc); + EM_DEBUG_EXCEPTION ("sqlite3_finalize error [%d]", rc); error = EMAIL_ERROR_DB_FAILURE; } } @@ -4563,11 +4840,11 @@ INTERNAL_FUNC int emstorage_delete_account(int account_id, int transaction, int int rc = -1, ret = false; int error = EMAIL_ERROR_NONE; + int ssa_err = 0; sqlite3 *local_db_handle = emstorage_get_db_connection(); EMSTORAGE_START_WRITE_TRANSACTION(transaction, error); /* 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]; @@ -4581,12 +4858,11 @@ INTERNAL_FUNC int emstorage_delete_account(int account_id, int transaction, int /* 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); - - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc); - EM_DEBUG_DB_EXEC((rc == SQLITE_FULL), {error = EMAIL_ERROR_MAIL_MEMORY_FULL;goto FINISH_OFF; }, - ("sqlite3_exec fail:%d", rc)); - EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, - ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); + if (error != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; + } /* validate account existence */ rc = sqlite3_changes(local_db_handle); @@ -4596,30 +4872,25 @@ INTERNAL_FUNC int emstorage_delete_account(int account_id, int transaction, int goto FINISH_OFF; } - /* delete from secure storage */ - if (ssm_delete_file(recv_password_file_name, SSM_FLAG_SECRET_OPERATION, NULL) < 0) { - EM_DEBUG_EXCEPTION_SEC(" ssm_delete_file failed -recv password : file[%s]", recv_password_file_name); - error = EMAIL_ERROR_SYSTEM_FAILURE; + /* delete from secure storage */ + ssa_err = ssa_delete (recv_password_file_name, ACCOUNT_PASSWORD_SS_GROUP_ID); + if (ssa_err < 0) { + EM_DEBUG_EXCEPTION_SEC("ss_delete[%s] error[%d]", recv_password_file_name, ssa_err); + error = EMAIL_ERROR_SECURED_STORAGE_FAILURE; goto FINISH_OFF; } - if (ssm_delete_file(send_password_file_name, SSM_FLAG_SECRET_OPERATION, NULL) < 0) { - EM_DEBUG_EXCEPTION_SEC(" ssm_delete_file failed -send password : file[%s]", send_password_file_name); - error = EMAIL_ERROR_SYSTEM_FAILURE; + + ssa_err = ssa_delete(send_password_file_name, ACCOUNT_PASSWORD_SS_GROUP_ID); + if (ssa_err < 0) { + EM_DEBUG_EXCEPTION_SEC("ss_delete[%s] error[%d]", send_password_file_name, ssa_err); + error = EMAIL_ERROR_SECURED_STORAGE_FAILURE; goto FINISH_OFF; } + ret = true; FINISH_OFF: EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error); - _DISCONNECT_DB; - - if (hStmt != NULL) { - rc = sqlite3_finalize(hStmt); - if (rc != SQLITE_OK) { - EM_DEBUG_LOG(" sqlite3_finalize failed - %d", rc); - error = EMAIL_ERROR_DB_FAILURE; - } - } if (err_code != NULL) *err_code = error; @@ -4662,6 +4933,7 @@ INTERNAL_FUNC int emstorage_free_account(emstorage_account_tbl_t** account_list, 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[i].options.alert_ringtone_path); EM_SAFE_FREE(p[i].certificate_path); } @@ -4715,7 +4987,6 @@ INTERNAL_FUNC int emstorage_get_mailbox_count(int account_id, int local_yn, int FINISH_OFF: EMSTORAGE_FINISH_READ_TRANSACTION(transaction); - _DISCONNECT_DB; if (err_code != NULL) *err_code = error; @@ -4856,7 +5127,7 @@ INTERNAL_FUNC int emstorage_get_child_mailbox_list(int account_id, char *parent_ } sqlite3_snprintf(sizeof(conditional_clause_string), conditional_clause_string, "WHERE account_id = %d AND UPPER(mailbox_name) LIKE UPPER('%q%%')", account_id, parent_mailbox_name); - EM_DEBUG_LOG("conditional_clause_string", conditional_clause_string); + EM_DEBUG_LOG("conditional_clause_string[%s]", conditional_clause_string); if( (error = emstorage_query_mailbox_tbl(conditional_clause_string, " ORDER BY mailbox_name DESC ", 0, transaction, mailbox_list, select_num)) != EMAIL_ERROR_NONE) { EM_DEBUG_EXCEPTION("emstorage_query_mailbox_tbl failed [%d]", error); @@ -4915,7 +5186,6 @@ INTERNAL_FUNC int emstorage_stamp_last_sync_time_of_mailbox(int input_mailbox_id int result_code = false; int error = EMAIL_ERROR_NONE; - int rc; time_t current_time = 0; char sql_query_string[QUERY_SIZE] = {0, }; sqlite3 *local_db_handle = NULL; @@ -4938,11 +5208,12 @@ INTERNAL_FUNC int emstorage_stamp_last_sync_time_of_mailbox(int input_mailbox_id , (int)current_time , input_mailbox_id); - EM_DEBUG_LOG("sql_query_string [%s]", sql_query_string); - - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc); - EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, - ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + EM_DEBUG_LOG_SEC("sql_query_string [%s]", sql_query_string); + error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); + if (error != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; + } FINISH_OFF: @@ -4950,7 +5221,6 @@ FINISH_OFF: result_code = true; EMSTORAGE_FINISH_WRITE_TRANSACTION(input_transaction, result_code, error); - _DISCONNECT_DB; EM_DEBUG_FUNC_END("error [%d]", error); return error; @@ -5044,7 +5314,7 @@ INTERNAL_FUNC int emstorage_get_mailbox_by_mailbox_type(int account_id, email_ma EM_DEBUG_LOG("conditional_clause_string = [%s]", conditional_clause_string); if( (error = emstorage_query_mailbox_tbl(conditional_clause_string, "", true, false, &result_mailbox, &result_count)) != EMAIL_ERROR_NONE) { - EM_DEBUG_EXCEPTION("emstorage_query_mailbox_tbl failed [%d]", ret); + EM_DEBUG_EXCEPTION("emstorage_query_mailbox_tbl error [%d]", error); goto FINISH_OFF; } @@ -5160,7 +5430,7 @@ INTERNAL_FUNC int emstorage_get_mailbox_id_by_mailbox_type(int account_id, email SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT mailbox_id FROM mail_box_tbl WHERE account_id = %d AND mailbox_type = %d ", account_id, mailbox_type); - EM_DEBUG_LOG("query = [%s]", sql_query_string); + EM_DEBUG_LOG_SEC("query = [%s]", sql_query_string); EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); @@ -5185,11 +5455,10 @@ INTERNAL_FUNC int emstorage_get_mailbox_id_by_mailbox_type(int account_id, email FINISH_OFF: EMSTORAGE_FINISH_READ_TRANSACTION(transaction); - _DISCONNECT_DB; if (hStmt != NULL) { rc = sqlite3_finalize(hStmt); if (rc != SQLITE_OK) { - EM_DEBUG_EXCEPTION(" sqlite3_finalize failed - %d", rc); + EM_DEBUG_EXCEPTION ("sqlite3_finalize error [%d]", rc); error = EMAIL_ERROR_DB_FAILURE; } } @@ -5231,7 +5500,7 @@ INTERNAL_FUNC int emstorage_get_mailbox_name_by_mailbox_type(int account_id, ema 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_DEBUG_LOG_SEC("query = [%s]", sql_query_string); EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); @@ -5258,13 +5527,12 @@ FINISH_OFF: if (hStmt != NULL) { rc = sqlite3_finalize(hStmt); if (rc != SQLITE_OK) { - EM_DEBUG_EXCEPTION(" sqlite3_finalize failed - %d", rc); + EM_DEBUG_EXCEPTION ("sqlite3_finalize error [%d]", rc); error = EMAIL_ERROR_DB_FAILURE; } } EMSTORAGE_FINISH_READ_TRANSACTION(transaction); - _DISCONNECT_DB; if (err_code != NULL) *err_code = error; @@ -5276,12 +5544,12 @@ FINISH_OFF: INTERNAL_FUNC int emstorage_update_mailbox_modifiable_yn(int account_id, int local_yn, char *mailbox_name, int modifiable_yn, int transaction, int *err_code) { 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 ret = false; int error = EMAIL_ERROR_NONE; char sql_query_string[QUERY_SIZE] = {0, }; char *replaced_mailbox_name = NULL; - if (mailbox_name) { + if (mailbox_name) { if (strstr(mailbox_name, "'")) { replaced_mailbox_name = em_replace_all_string(mailbox_name, "'", "''"); } else { @@ -5303,17 +5571,19 @@ INTERNAL_FUNC int emstorage_update_mailbox_modifiable_yn(int account_id, int loc , account_id , local_yn , replaced_mailbox_name); - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc); - EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, - ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + + error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); + if (error != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; + } ret = true; FINISH_OFF: EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error); - _DISCONNECT_DB; - EM_SAFE_FREE(replaced_mailbox_name); + EM_SAFE_FREE(replaced_mailbox_name); if (err_code != NULL) *err_code = error; @@ -5327,7 +5597,7 @@ FINISH_OFF: INTERNAL_FUNC int emstorage_update_mailbox_total_count(int account_id, int input_mailbox_id, int total_count_on_server, int transaction, int *err_code) { EM_DEBUG_FUNC_BEGIN("account_id[%d], input_mailbox_id[%d], total_count_on_server[%d], transaction[%d], err_code[%p]", account_id, input_mailbox_id, total_count_on_server, transaction, err_code); - int rc, ret = false; + int ret = false; int error = EMAIL_ERROR_NONE; char sql_query_string[QUERY_SIZE] = {0, }; @@ -5351,16 +5621,18 @@ INTERNAL_FUNC int emstorage_update_mailbox_total_count(int account_id, int input , total_count_on_server , account_id , input_mailbox_id); - EM_DEBUG_LOG("query[%s]", sql_query_string); - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc); - EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, - ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + + EM_DEBUG_LOG_SEC("query[%s]", sql_query_string); + error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); + if (error != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; + } ret = true; FINISH_OFF: EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error); - _DISCONNECT_DB; if (err_code != NULL) *err_code = error; @@ -5454,12 +5726,11 @@ INTERNAL_FUNC int emstorage_update_mailbox(int account_id, int local_yn, int inp FINISH_OFF: EMSTORAGE_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); + EM_DEBUG_EXCEPTION ("sqlite3_finalize error [%d]", rc); error = EMAIL_ERROR_DB_FAILURE; } } @@ -5519,14 +5790,14 @@ INTERNAL_FUNC int emstorage_update_mailbox_type(int account_id, int local_yn, in , input_mailbox_id); } - EM_DEBUG_LOG("SQL(%s)", sql_query_string); + EM_DEBUG_LOG_SEC("SQL(%s)", sql_query_string); EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt_box_tbl, NULL), rc); if(SQLITE_OK != rc) { EM_DEBUG_EXCEPTION("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)); error = EMAIL_ERROR_DB_FAILURE; - goto FINISH_OFF; + goto FINISH_OFF; } _bind_stmt_field_data_int(hStmt_box_tbl, i++, new_mailbox_type); @@ -5537,15 +5808,15 @@ INTERNAL_FUNC int emstorage_update_mailbox_type(int account_id, int local_yn, in if(rc == SQLITE_FULL) { EM_DEBUG_EXCEPTION("sqlite3_step fail:%d", rc); error = EMAIL_ERROR_MAIL_MEMORY_FULL; - goto FINISH_OFF; + goto FINISH_OFF; } - + if(rc != SQLITE_ROW && rc != SQLITE_DONE) { EM_DEBUG_EXCEPTION("sqlite3_step fail:%d", rc); error = EMAIL_ERROR_DB_FAILURE; - goto FINISH_OFF; + goto FINISH_OFF; } - + /* Update mail_tbl */ i = 0; @@ -5557,40 +5828,39 @@ INTERNAL_FUNC int emstorage_update_mailbox_type(int account_id, int local_yn, in , account_id , input_mailbox_id); - EM_DEBUG_LOG("SQL[%s]", sql_query_string); + EM_DEBUG_LOG_SEC("SQL[%s]", sql_query_string); EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt_mail_tbl, NULL), rc); if(SQLITE_OK != rc) { EM_DEBUG_EXCEPTION("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)); error = EMAIL_ERROR_DB_FAILURE; - goto FINISH_OFF; + goto FINISH_OFF; } - + _bind_stmt_field_data_int(hStmt_mail_tbl, i++, new_mailbox_type); EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt_mail_tbl), rc); if(rc == SQLITE_FULL) { EM_DEBUG_EXCEPTION("sqlite3_step fail:%d", rc); error = EMAIL_ERROR_MAIL_MEMORY_FULL; - goto FINISH_OFF; + goto FINISH_OFF; } - + if(rc != SQLITE_ROW && rc != SQLITE_DONE){ EM_DEBUG_EXCEPTION("sqlite3_step fail:%d", rc); error = EMAIL_ERROR_DB_FAILURE; - goto FINISH_OFF; + goto FINISH_OFF; } ret = true; FINISH_OFF: EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error); - _DISCONNECT_DB; if (hStmt_box_tbl != NULL) { rc = sqlite3_finalize(hStmt_box_tbl); if (rc != SQLITE_OK) { - EM_DEBUG_EXCEPTION(" sqlite3_finalize failed - %d", rc); + EM_DEBUG_EXCEPTION ("sqlite3_finalize error [%d]", rc); error = EMAIL_ERROR_DB_FAILURE; } } @@ -5598,7 +5868,7 @@ FINISH_OFF: if (hStmt_mail_tbl != NULL) { rc = sqlite3_finalize(hStmt_mail_tbl); if (rc != SQLITE_OK) { - EM_DEBUG_EXCEPTION(" sqlite3_finalize failed - %d", rc); + EM_DEBUG_EXCEPTION ("sqlite3_finalize error [%d]", rc); error = EMAIL_ERROR_DB_FAILURE; } } @@ -5639,7 +5909,7 @@ INTERNAL_FUNC int emstorage_set_local_mailbox(int input_mailbox_id, int input_is " WHERE mailbox_id = %d" , input_mailbox_id); - EM_DEBUG_LOG("SQL(%s)", sql_query_string); + EM_DEBUG_LOG_SEC("SQL(%s)", sql_query_string); EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, @@ -5652,26 +5922,25 @@ INTERNAL_FUNC int emstorage_set_local_mailbox(int input_mailbox_id, int input_is ("sqlite3_step fail:%d", rc)); EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_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); + EM_DEBUG_EXCEPTION ("sqlite3_finalize error [%d]", rc); error = EMAIL_ERROR_DB_FAILURE; } hStmt = NULL; } - +*/ ret = true; FINISH_OFF: EMSTORAGE_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); + EM_DEBUG_EXCEPTION ("sqlite3_finalize error [%d]", rc); error = EMAIL_ERROR_DB_FAILURE; } } @@ -5685,7 +5954,6 @@ INTERNAL_FUNC int emstorage_set_field_of_mailbox_with_integer_value(int input_ac EM_DEBUG_FUNC_BEGIN("input_account_id [%d] input_mailbox_id_array[%p] input_mailbox_id_count[%d] input_field_name[%p] input_value[%d] err_code[%p]", input_account_id, input_mailbox_id_array, input_mailbox_id_count, input_field_name, input_value, transaction); int i = 0; int err = EMAIL_ERROR_NONE; - int rc = 0; int result = false; int cur_mailbox_id_string = 0; int mailbox_id_string_buffer_length = 0; @@ -5732,13 +6000,16 @@ INTERNAL_FUNC int emstorage_set_field_of_mailbox_with_integer_value(int input_ac /* Write query string */ SNPRINTF(sql_query_string, QUERY_SIZE, "UPDATE mail_box_tbl SET %s = %d WHERE mailbox_id in (%s) ", input_field_name, input_value, mailbox_id_string_buffer); - EM_DEBUG_LOG("sql_query_string [%s]", sql_query_string); + EM_DEBUG_LOG_SEC("sql_query_string [%s]", sql_query_string); /* Execute query */ EMSTORAGE_START_WRITE_TRANSACTION(transaction, err); - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc); - EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {err = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, - ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + err = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); + if (err != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", err); + goto FINISH_OFF; + } + if (sqlite3_changes(local_db_handle) == 0) EM_DEBUG_LOG("no mail matched..."); @@ -5746,11 +6017,10 @@ INTERNAL_FUNC int emstorage_set_field_of_mailbox_with_integer_value(int input_ac FINISH_OFF: EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, result, err); - _DISCONNECT_DB; if (err == EMAIL_ERROR_NONE && parameter_string) { if (!emcore_notify_storage_event (NOTI_MAILBOX_FIELD_UPDATE, input_account_id, 0, parameter_string, input_value)) - EM_DEBUG_EXCEPTION_SEC ("emcore_notify_storage_event failed : NOTI_MAILBOX_FIELD_UPDATE [%s,%d]", + EM_DEBUG_EXCEPTION_SEC ("emcore_notify_storage_event failed : NOTI_MAILBOX_FIELD_UPDATE [%s,%d]", input_field_name, input_value); } @@ -5850,19 +6120,16 @@ INTERNAL_FUNC int emstorage_add_mailbox(emstorage_mailbox_tbl_t* mailbox_tbl, in FINISH_OFF: EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error); - _DISCONNECT_DB; if (hStmt != NULL) { - EM_DEBUG_LOG_DEV ("before sqlite3_finalize hStmt = %p", hStmt); - rc = sqlite3_finalize(hStmt); if (rc != SQLITE_OK) { - EM_DEBUG_EXCEPTION("sqlite3_finalize failed - %d", rc); + EM_DEBUG_EXCEPTION ("sqlite3_finalize error [%d]", rc); error = EMAIL_ERROR_DB_FAILURE; } } - if (error == EMAIL_ERROR_NONE) { - if (!emcore_notify_storage_event (NOTI_MAILBOX_ADD, mailbox_tbl->account_id, mailbox_tbl->mailbox_id, + if (error == EMAIL_ERROR_NONE) { + if (!emcore_notify_storage_event (NOTI_MAILBOX_ADD, mailbox_tbl->account_id, mailbox_tbl->mailbox_id, mailbox_tbl->mailbox_name, mailbox_tbl->mailbox_type)) EM_DEBUG_EXCEPTION ("emcore_notify_storage_event[ NOTI_MAILBOX_ADD] : Notification Failed"); } @@ -5889,16 +6156,17 @@ INTERNAL_FUNC int emstorage_set_all_mailbox_modifiable_yn(int account_id, int mo int rc, ret = false; int error = EMAIL_ERROR_NONE; char sql_query_string[QUERY_SIZE] = {0,}; - sqlite3 *local_db_handle = emstorage_get_db_connection(); EMSTORAGE_START_WRITE_TRANSACTION(transaction, error); SNPRINTF(sql_query_string, sizeof(sql_query_string), "UPDATE mail_box_tbl SET modifiable_yn = %d WHERE account_id = %d", modifiable_yn, account_id); - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc); - EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, - ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); + if (error != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; + } rc = sqlite3_changes(local_db_handle); if (rc == 0) @@ -5909,7 +6177,6 @@ INTERNAL_FUNC int emstorage_set_all_mailbox_modifiable_yn(int account_id, int mo FINISH_OFF: EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error); - _DISCONNECT_DB; if (err_code != NULL) *err_code = error; @@ -5934,7 +6201,6 @@ INTERNAL_FUNC int emstorage_delete_mailbox(int account_id, int local_yn, int inp int rc, ret = false; int error = EMAIL_ERROR_NONE; char sql_query_string[QUERY_SIZE] = {0, }; - sqlite3 *local_db_handle = emstorage_get_db_connection(); EMSTORAGE_START_WRITE_TRANSACTION(transaction, error); @@ -5947,10 +6213,12 @@ INTERNAL_FUNC int emstorage_delete_mailbox(int account_id, int local_yn, int inp SNPRINTF(sql_query_string + EM_SAFE_STRLEN(sql_query_string), sizeof(sql_query_string)-(1+ EM_SAFE_STRLEN(sql_query_string)), "AND mailbox_id = %d", input_mailbox_id); } - EM_DEBUG_LOG("mailbox sql_query_string [%s]", sql_query_string); - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc); - EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, - ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + EM_DEBUG_LOG_SEC("mailbox sql_query_string [%s]", sql_query_string); + error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); + if (error != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; + } rc = sqlite3_changes(local_db_handle); if (rc == 0) { @@ -5963,7 +6231,6 @@ INTERNAL_FUNC int emstorage_delete_mailbox(int account_id, int local_yn, int inp FINISH_OFF: EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error); - _DISCONNECT_DB; if(error == EMAIL_ERROR_NONE) { if (!emcore_notify_storage_event (NOTI_MAILBOX_DELETE, account_id, input_mailbox_id, NULL, 0)) @@ -6043,7 +6310,7 @@ INTERNAL_FUNC int emstorage_get_count_read_mail_uid(int account_id, char *mailbo sqlite3 *local_db_handle = emstorage_get_db_connection(); EMSTORAGE_START_READ_TRANSACTION(transaction); SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT COUNT(*) FROM mail_read_mail_uid_tbl WHERE account_id = %d AND mailbox_name = '%s' ", account_id, replaced_mailbox_name); - EM_DEBUG_LOG(">>> SQL [ %s ] ", sql_query_string); + EM_DEBUG_LOG_SEC(">>> SQL [ %s ] ", sql_query_string); char **result; @@ -6058,7 +6325,6 @@ INTERNAL_FUNC int emstorage_get_count_read_mail_uid(int account_id, char *mailbo FINISH_OFF: EMSTORAGE_FINISH_READ_TRANSACTION(transaction); - _DISCONNECT_DB; EM_SAFE_FREE(replaced_mailbox_name); @@ -6124,7 +6390,6 @@ INTERNAL_FUNC int emstorage_check_read_mail_uid(int account_id, char *mailbox_na FINISH_OFF: EMSTORAGE_FINISH_READ_TRANSACTION(transaction); - _DISCONNECT_DB; EM_SAFE_FREE(replaced_mailbox_name); @@ -6190,16 +6455,14 @@ INTERNAL_FUNC int emstorage_get_downloaded_mail(int mail_id, emstorage_mail_tbl_ 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); + EM_DEBUG_EXCEPTION ("sqlite3_finalize error [%d]", rc); error = EMAIL_ERROR_DB_FAILURE; } } EMSTORAGE_FINISH_READ_TRANSACTION(transaction); - _DISCONNECT_DB; if (err_code != NULL) *err_code = error; @@ -6237,7 +6500,7 @@ INTERNAL_FUNC int emstorage_get_downloaded_list(int account_id, int mailbox_id, 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_DEBUG_LOG_SEC(" sql_query_string : %s", sql_query_string); @@ -6297,17 +6560,14 @@ FINISH_OFF: emstorage_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); - + EM_DEBUG_EXCEPTION ("sqlite3_finalize error [%d]", rc); error = EMAIL_ERROR_DB_FAILURE; } } EMSTORAGE_FINISH_READ_TRANSACTION(transaction); - _DISCONNECT_DB; if (err_code != NULL) *err_code = error; @@ -6392,14 +6652,12 @@ FINISH_OFF: if (hStmt != NULL) { rc = sqlite3_finalize(hStmt); if (rc != SQLITE_OK) { - EM_DEBUG_LOG(" sqlite3_finalize failed - %d", rc); - + EM_DEBUG_EXCEPTION ("sqlite3_finalize error [%d]", rc); error = EMAIL_ERROR_DB_FAILURE; } } EMSTORAGE_FINISH_READ_TRANSACTION(transaction); - _DISCONNECT_DB; if (err_code != NULL) *err_code = error; @@ -6462,13 +6720,10 @@ INTERNAL_FUNC int emstorage_add_downloaded_mail(emstorage_read_mail_uid_tbl_t* r goto FINISH_OFF; } - EM_DEBUG_LOG("account_id VALUE [%d] ", read_mail_uid->account_id); - EM_DEBUG_LOG("mailbox_id VALUE [%d] ", read_mail_uid->mailbox_id); - EM_DEBUG_LOG("local_uid VALUE [%d] ", read_mail_uid->local_uid); - EM_DEBUG_LOG_SEC("mailbox_name VALUE [%s] ", read_mail_uid->mailbox_name); - EM_DEBUG_LOG("server_uid VALUE [%s] ", read_mail_uid->server_uid); - EM_DEBUG_LOG("data1 VALUE [%d] ", read_mail_uid->rfc822_size); - EM_DEBUG_LOG("rc VALUE [%d] ", rc); + EM_DEBUG_LOG("account_id[%d] mailbox_id[%d] local_uid [%d]" + "server_uid[%s] rfc822_size[%d] rc[%d]", + read_mail_uid->account_id, read_mail_uid->mailbox_id,read_mail_uid->local_uid, + read_mail_uid->server_uid, read_mail_uid->rfc822_size, rc); _bind_stmt_field_data_int(hStmt, ACCOUNT_ID_IDX_IN_MAIL_READ_MAIL_UID_TBL, read_mail_uid->account_id); _bind_stmt_field_data_int(hStmt, LOCAL_MAILBOX_ID_IDX_IN_MAIL_READ_MAIL_UID_TBL, read_mail_uid->mailbox_id); @@ -6492,13 +6747,10 @@ INTERNAL_FUNC int emstorage_add_downloaded_mail(emstorage_read_mail_uid_tbl_t* r FINISH_OFF: EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error); - _DISCONNECT_DB; 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); + EM_DEBUG_EXCEPTION ("sqlite3_finalize error [%d]", rc); error = EMAIL_ERROR_DB_FAILURE; } } @@ -6554,10 +6806,9 @@ INTERNAL_FUNC int emstorage_add_mail_text(emstorage_mail_text_tbl_t* mail_text, goto FINISH_OFF; } - EM_DEBUG_LOG("mail_id VALUE [%d] ", mail_text->mail_id); - EM_DEBUG_LOG("account_id VALUE [%d] ", mail_text->account_id); - EM_DEBUG_LOG("mailbox_id VALUE [%d] ", mail_text->mailbox_id); - EM_DEBUG_LOG("body_text VALUE [%s] ", mail_text->body_text); + EM_DEBUG_LOG ("mail_id[%d] account_id[%d] mailbox_id[%d]", mail_text->mail_id, + mail_text->account_id, mail_text->mailbox_id); + EM_DEBUG_LOG_DEV ("body_text VALUE [%s] ", mail_text->body_text); _bind_stmt_field_data_int(hStmt, MAIL_ID_IDX_IN_MAIL_TEXT_TBL, mail_text->mail_id); _bind_stmt_field_data_int(hStmt, ACCOUNT_ID_IDX_IN_MAIL_TEXT_TBL, mail_text->account_id); @@ -6574,13 +6825,10 @@ INTERNAL_FUNC int emstorage_add_mail_text(emstorage_mail_text_tbl_t* mail_text, FINISH_OFF: EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error); - _DISCONNECT_DB; 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); + EM_DEBUG_EXCEPTION ("sqlite3_finalize error [%d]", rc); error = EMAIL_ERROR_DB_FAILURE; } } @@ -6662,14 +6910,10 @@ INTERNAL_FUNC int emstorage_change_read_mail_uid(int account_id, int mailbox_id, FINISH_OFF: EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error); - _DISCONNECT_DB; 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); - + EM_DEBUG_EXCEPTION ("sqlite3_finalize error [%d]", rc); error = EMAIL_ERROR_DB_FAILURE; } } @@ -6693,11 +6937,10 @@ INTERNAL_FUNC int emstorage_remove_downloaded_mail(int account_id, char *mailbox return false; } - int rc, ret = false; + int ret = false; int error = EMAIL_ERROR_NONE; char sql_query_string[QUERY_SIZE] = {0, }; char *replaced_mailbox_name = NULL; - sqlite3 *local_db_handle = emstorage_get_db_connection(); EMSTORAGE_START_WRITE_TRANSACTION(transaction, error); @@ -6718,16 +6961,16 @@ INTERNAL_FUNC int emstorage_remove_downloaded_mail(int account_id, char *mailbox SNPRINTF(sql_query_string+EM_SAFE_STRLEN(sql_query_string), sizeof(sql_query_string) - (1 + EM_SAFE_STRLEN(sql_query_string)), "AND server_uid='%s' ", uid); } - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc); - EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, - ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); - + error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); + if (error != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; + } ret = true; FINISH_OFF: EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error); - _DISCONNECT_DB; EM_SAFE_FREE(replaced_mailbox_name); @@ -6778,7 +7021,7 @@ INTERNAL_FUNC int emstorage_get_rule_count_by_account_id(int account_id, int *co { EM_DEBUG_FUNC_BEGIN("account_id [%d], count[%p], transaction[%d], err_code[%p]", count, transaction, err_code); - if (!count) { + if (!count) { EM_DEBUG_EXCEPTION("count[%p]", count); if (err_code != NULL) @@ -6793,7 +7036,7 @@ INTERNAL_FUNC int emstorage_get_rule_count_by_account_id(int account_id, int *co sqlite3 *local_db_handle = emstorage_get_db_connection(); EMSTORAGE_START_READ_TRANSACTION(transaction); - if (account_id != ALL_ACCOUNT) + if (account_id != ALL_ACCOUNT) SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT COUNT(*) FROM mail_rule_tbl where account_id = %d", account_id); else SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT COUNT(*) FROM mail_rule_tbl"); @@ -6811,7 +7054,6 @@ INTERNAL_FUNC int emstorage_get_rule_count_by_account_id(int account_id, int *co FINISH_OFF: EMSTORAGE_FINISH_READ_TRANSACTION(transaction); - _DISCONNECT_DB; if (err_code != NULL) *err_code = error; @@ -6923,18 +7165,14 @@ FINISH_OFF: emstorage_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); + EM_DEBUG_EXCEPTION ("sqlite3_finalize error [%d]", rc); error = EMAIL_ERROR_DB_FAILURE; } } - EMSTORAGE_FINISH_READ_TRANSACTION(transaction); - _DISCONNECT_DB; if (err_code != NULL) *err_code = error; @@ -7006,18 +7244,14 @@ FINISH_OFF: *rule = 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_LOG(" sqlite3_finalize failed - %d", rc); - + EM_DEBUG_EXCEPTION ("sqlite3_finalize error [%d]", rc); error = EMAIL_ERROR_DB_FAILURE; } } EMSTORAGE_FINISH_READ_TRANSACTION(transaction); - _DISCONNECT_DB; if (err_code != NULL) *err_code = error; @@ -7048,7 +7282,7 @@ INTERNAL_FUNC int emstorage_change_rule(int rule_id, emstorage_rule_tbl_t* new_r SNPRINTF(sql_query_string, sizeof(sql_query_string), "UPDATE mail_rule_tbl SET" - " filter_name = ?" + " filter_name = ?" ", type = ?" ", value = ?" ", value2 = ?" @@ -7056,8 +7290,10 @@ INTERNAL_FUNC int emstorage_change_rule(int rule_id, emstorage_rule_tbl_t* new_r ", target_mailbox_id = ?" ", flag1 = ?" ", flag2 = ?" - " WHERE account_id = ?" - " AND rule_id = ?"); + ", account_id = ?" + ", rule_id = ?" + " WHERE rule_id = %d" + , rule_id); EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); @@ -7087,14 +7323,10 @@ INTERNAL_FUNC int emstorage_change_rule(int rule_id, emstorage_rule_tbl_t* new_r FINISH_OFF: EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error); - _DISCONNECT_DB; 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); - + EM_DEBUG_EXCEPTION ("sqlite3_finalize error [%d]", rc); error = EMAIL_ERROR_DB_FAILURE; } } @@ -7177,17 +7409,14 @@ INTERNAL_FUNC int emstorage_find_rule(emstorage_rule_tbl_t* rule, int transactio 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); + EM_DEBUG_EXCEPTION ("sqlite3_finalize error [%d]", rc); error = EMAIL_ERROR_DB_FAILURE; } } EMSTORAGE_FINISH_READ_TRANSACTION(transaction); - _DISCONNECT_DB; if (err_code) *err_code = error; @@ -7273,14 +7502,10 @@ INTERNAL_FUNC int emstorage_add_rule(emstorage_rule_tbl_t* rule, int transaction FINISH_OFF: EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error); - _DISCONNECT_DB; 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); - + EM_DEBUG_EXCEPTION ("sqlite3_finalize error [%d]", rc); error = EMAIL_ERROR_DB_FAILURE; } } @@ -7307,15 +7532,16 @@ INTERNAL_FUNC int emstorage_delete_rule(int rule_id, int transaction, int *err_c int rc, ret = false; int error = EMAIL_ERROR_NONE; char sql_query_string[QUERY_SIZE] = {0, }; - sqlite3 *local_db_handle = emstorage_get_db_connection(); EMSTORAGE_START_WRITE_TRANSACTION(transaction, error); SNPRINTF(sql_query_string, sizeof(sql_query_string), "DELETE FROM mail_rule_tbl WHERE rule_id = %d", rule_id); + error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); + if (error != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; + } - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc); - EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_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..."); @@ -7328,7 +7554,6 @@ INTERNAL_FUNC int emstorage_delete_rule(int rule_id, int transaction, int *err_c FINISH_OFF: EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error); - _DISCONNECT_DB; if (err_code != NULL) *err_code = error; @@ -7385,7 +7610,6 @@ INTERNAL_FUNC int emstorage_get_mail_count(int account_id, int mailbox_id, int * int error = EMAIL_ERROR_NONE; DB_STMT hStmt = NULL; char sql_query_string[QUERY_SIZE] = {0, }; - char err_msg[1024]; char *replaced_mailbox_name = NULL; memset(&sql_query_string, 0x00, sizeof(sql_query_string)); @@ -7455,14 +7679,13 @@ FINISH_OFF2: if (hStmt != NULL) { rc = sqlite3_finalize(hStmt); if (rc != SQLITE_OK) { - EM_DEBUG_LOG(" EDBStmtClearRow failed - %d: %s", rc, err_msg); + EM_DEBUG_EXCEPTION ("sqlite3_finalize error [%d]", rc); error = EMAIL_ERROR_DB_FAILURE; } } #endif EMSTORAGE_FINISH_READ_TRANSACTION(transaction); - _DISCONNECT_DB; EM_SAFE_FREE(replaced_mailbox_name); @@ -7531,7 +7754,7 @@ INTERNAL_FUNC int emstorage_get_mail_field_by_id(int mail_id, int type, emstorag goto FINISH_OFF; } - EM_DEBUG_LOG("Query [%s]", sql_query_string); + EM_DEBUG_LOG_SEC("Query [%s]", sql_query_string); EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, @@ -7593,18 +7816,15 @@ FINISH_OFF: emstorage_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); + EM_DEBUG_EXCEPTION ("sqlite3_finalize error [%d]", rc); error = EMAIL_ERROR_DB_FAILURE; } } EMSTORAGE_FINISH_READ_TRANSACTION(transaction); - _DISCONNECT_DB; if (err_code != NULL) *err_code = error; @@ -7656,8 +7876,8 @@ INTERNAL_FUNC int emstorage_get_mail_field_by_multiple_mail_id(int mail_ids[], i switch (type) { case RETRIEVE_SUMMARY: cur_sql_query_string = SNPRINTF(sql_query_string, query_string_length, - "SELECT account_id, mail_id, server_mail_status, server_mailbox_name, server_mail_id, 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 = 12; + "SELECT account_id, mail_id, mailbox_id, server_mail_status, server_mailbox_name, server_mail_id, file_path_plain, file_path_html, subject, flags_seen_field, save_status, lock_status, thread_id, thread_item_count FROM mail_tbl WHERE mail_id in ("); + field_count = 14; break; case RETRIEVE_FIELDS_FOR_DELETE: @@ -7674,8 +7894,8 @@ INTERNAL_FUNC int emstorage_get_mail_field_by_multiple_mail_id(int mail_ids[], i case RETRIEVE_FLAG: cur_sql_query_string = SNPRINTF(sql_query_string, query_string_length, - "SELECT account_id, mailbox_id, flags_seen_field, thread_id FROM mail_tbl WHERE mail_id in ("); - field_count = 4; + "SELECT account_id, mail_id, mailbox_id, flags_seen_field, thread_id FROM mail_tbl WHERE mail_id in ("); + field_count = 5; break; default : @@ -7688,7 +7908,7 @@ INTERNAL_FUNC int emstorage_get_mail_field_by_multiple_mail_id(int mail_ids[], i cur_sql_query_string += SNPRINTF_OFFSET(sql_query_string, cur_sql_query_string, QUERY_SIZE, "%d,", mail_ids[i]); sql_query_string[EM_SAFE_STRLEN(sql_query_string) - 1] = ')'; - EM_DEBUG_LOG("Query [%s], Length [%d]", sql_query_string, EM_SAFE_STRLEN(sql_query_string)); + EM_DEBUG_LOG_SEC("Query [%s], Length [%d]", sql_query_string, EM_SAFE_STRLEN(sql_query_string)); EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, &item_count, 0, NULL), rc); if (SQLITE_OK != rc && -1 != rc) { @@ -7718,11 +7938,13 @@ INTERNAL_FUNC int emstorage_get_mail_field_by_multiple_mail_id(int mail_ids[], i case RETRIEVE_SUMMARY: _get_table_field_data_int(result, &(p_data_tbl[i].account_id), col_index++); _get_table_field_data_int(result, &(p_data_tbl[i].mail_id), col_index++); + _get_table_field_data_int(result, &(p_data_tbl[i].mailbox_id), col_index++); _get_table_field_data_int(result, &(p_data_tbl[i].server_mail_status), col_index++); _get_table_field_data_string(result, &(p_data_tbl[i].server_mailbox_name), 0, col_index++); _get_table_field_data_string(result, &(p_data_tbl[i].server_mail_id), 0, col_index++); _get_table_field_data_string(result, &(p_data_tbl[i].file_path_plain), 0, col_index++); _get_table_field_data_string(result, &(p_data_tbl[i].file_path_html), 0, col_index++); + _get_table_field_data_string(result, &(p_data_tbl[i].subject), 0, col_index++); _get_table_field_data_char(result, &(p_data_tbl[i].flags_seen_field), col_index++); _get_table_field_data_int(result, (int*)&(p_data_tbl[i].save_status), col_index++); _get_table_field_data_int(result, &(p_data_tbl[i].lock_status), col_index++); @@ -7744,6 +7966,7 @@ INTERNAL_FUNC int emstorage_get_mail_field_by_multiple_mail_id(int mail_ids[], i case RETRIEVE_FLAG: _get_table_field_data_int(result, &(p_data_tbl[i].account_id), col_index++); + _get_table_field_data_int(result, &(p_data_tbl[i].mail_id), col_index++); _get_table_field_data_int(result, &(p_data_tbl[i].mailbox_id), col_index++); _get_table_field_data_char(result, &(p_data_tbl[i].flags_seen_field), col_index++); _get_table_field_data_int(result, &(p_data_tbl[i].thread_id), col_index++); @@ -7763,7 +7986,6 @@ FINISH_OFF: sqlite3_free_table(result); EMSTORAGE_FINISH_READ_TRANSACTION(transaction); - _DISCONNECT_DB; EM_SAFE_FREE(sql_query_string); @@ -7790,7 +8012,7 @@ INTERNAL_FUNC int emstorage_get_mail_by_id(int mail_id, emstorage_mail_tbl_t** m emstorage_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); + EM_DEBUG_LOG_SEC("query = [%s]", conditional_clause); if(!emstorage_query_mail_tbl(conditional_clause, transaction, &p_data_tbl, &count, &error)) { EM_DEBUG_EXCEPTION("emstorage_query_mail_tbl [%d]", error); @@ -7831,7 +8053,7 @@ INTERNAL_FUNC int emstorage_get_mail_text_by_id(int mail_id, emstorage_mail_text emstorage_mail_text_tbl_t *p_data_tbl = NULL; SNPRINTF(conditional_clause, QUERY_SIZE, "WHERE mail_id = %d", mail_id); - EM_DEBUG_LOG("query = [%s]", conditional_clause); + EM_DEBUG_LOG_SEC("query = [%s]", conditional_clause); if(!emstorage_query_mail_text_tbl(conditional_clause, transaction, &p_data_tbl, &count, &error)) { EM_DEBUG_EXCEPTION("emstorage_query_mail_tbl [%d]", error); @@ -7854,9 +8076,9 @@ FINISH_OFF: } #endif -INTERNAL_FUNC int emstorage_mail_search_start(emstorage_search_filter_t* search, int account_id, char *mailbox_name, int sorting, int *search_handle, int *searched, int transaction, int *err_code) +INTERNAL_FUNC int emstorage_mail_search_start(emstorage_search_filter_t* search, int account_id, int mailbox_id, int sorting, int *search_handle, int *searched, int transaction, int *err_code) { - EM_DEBUG_FUNC_BEGIN("search[%p], account_id[%d], mailbox_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); + EM_DEBUG_FUNC_BEGIN("search[%p], account_id[%d], mailbox_id[%d], sorting[%d], search_handle[%p], searched[%p], transaction[%d], err_code[%p]", search, account_id, mailbox_id, sorting, search_handle, searched, transaction, err_code); if (!search_handle || !searched) { if (err_code != NULL) @@ -7872,7 +8094,6 @@ INTERNAL_FUNC int emstorage_mail_search_start(emstorage_search_filter_t* search, char sql_query_string[QUERY_SIZE] = {0, }; int rc, ret = false; int and = false, mail_count = 0; - char *replaced_mailbox_name = NULL; sqlite3 *local_db_handle = emstorage_get_db_connection(); EMSTORAGE_START_READ_TRANSACTION(transaction); @@ -7884,14 +8105,8 @@ INTERNAL_FUNC int emstorage_mail_search_start(emstorage_search_filter_t* search, and = true; } - if (mailbox_name) { - if (strstr(mailbox_name, "'")) { - replaced_mailbox_name = em_replace_all_string(mailbox_name, "'", "''"); - } else { - replaced_mailbox_name = strdup(mailbox_name); - } - - SNPRINTF(sql_query_string + EM_SAFE_STRLEN(sql_query_string), sizeof(sql_query_string)-(EM_SAFE_STRLEN(sql_query_string)+1), " %s mailbox_name = '%s'", and ? "AND" : "WHERE", replaced_mailbox_name); + if (mailbox_id) { + SNPRINTF(sql_query_string + EM_SAFE_STRLEN(sql_query_string), sizeof(sql_query_string)-(EM_SAFE_STRLEN(sql_query_string)+1), " %s mailbox_id = %d", and ? "AND" : "WHERE", mailbox_id); and = true; } @@ -7921,7 +8136,7 @@ INTERNAL_FUNC int emstorage_mail_search_start(emstorage_search_filter_t* search, if (sorting) SNPRINTF(sql_query_string + EM_SAFE_STRLEN(sql_query_string), sizeof(sql_query_string)-(EM_SAFE_STRLEN(sql_query_string)+1), " ORDER BY date_time"); - EM_DEBUG_LOG("sql_query_string [%s]", sql_query_string); + EM_DEBUG_LOG_SEC("sql_query_string [%s]", sql_query_string); EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); @@ -7953,17 +8168,14 @@ FINISH_OFF: if (hStmt != NULL) { rc = sqlite3_finalize(hStmt); if (rc != SQLITE_OK) { - EM_DEBUG_EXCEPTION("sqlite3_finalize failed - %d", rc); + EM_DEBUG_EXCEPTION ("sqlite3_finalize error [%d]", rc); error = EMAIL_ERROR_DB_FAILURE; } } EMSTORAGE_FINISH_READ_TRANSACTION(transaction); - _DISCONNECT_DB; } - EM_SAFE_FREE(replaced_mailbox_name); - if (err_code != NULL) *err_code = error; @@ -8045,6 +8257,7 @@ INTERNAL_FUNC int emstorage_mail_search_result(int search_handle, emstorage_mail _get_stmt_field_data_string(hStmt, &(p_data_tbl->preview_text), 1, PREVIEW_TEXT_IDX_IN_MAIL_TBL); _get_stmt_field_data_int (hStmt, (int*)&(p_data_tbl->replied_time), REPLIED_TIME_IDX_IN_MAIL_TBL); _get_stmt_field_data_int (hStmt, (int*)&(p_data_tbl->forwarded_time), FORWARDED_TIME_IDX_IN_MAIL_TBL); + _get_stmt_field_data_string(hStmt, &(p_data_tbl->default_charset), 0, DEFAULT_CHARSET_IDX_IN_MAIL_TBL); } if (p_data_tbl->body_download_status) { @@ -8133,11 +8346,10 @@ INTERNAL_FUNC int emstorage_mail_search_end(int search_handle, int transaction, 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); + EM_DEBUG_EXCEPTION ("sqlite3_finalize error [%d]", rc); error = EMAIL_ERROR_DB_FAILURE; } @@ -8145,7 +8357,6 @@ INTERNAL_FUNC int emstorage_mail_search_end(int search_handle, int transaction, FINISH_OFF: EMSTORAGE_FINISH_READ_TRANSACTION(transaction); - _DISCONNECT_DB; if (err_code != NULL) *err_code = error; @@ -8218,6 +8429,7 @@ INTERNAL_FUNC int emstorage_change_mail(int mail_id, emstorage_mail_tbl_t* mail, ", tag_id = ?" ", replied_time = ?" ", forwarded_time = ?" + ", default_charset = ?" ", eas_data_length = ?" ", eas_data = ?" " WHERE mail_id = %d AND account_id != 0 " @@ -8267,6 +8479,7 @@ INTERNAL_FUNC int emstorage_change_mail(int mail_id, emstorage_mail_tbl_t* mail, _bind_stmt_field_data_int (hStmt, i++, mail->tag_id); _bind_stmt_field_data_int (hStmt, i++, mail->replied_time); _bind_stmt_field_data_int (hStmt, i++, mail->forwarded_time); + _bind_stmt_field_data_string(hStmt, i++, (char *)mail->default_charset, 0, TEXT_2_LEN_IN_MAIL_TBL); _bind_stmt_field_data_int (hStmt, i++, mail->eas_data_length); _bind_stmt_field_data_blob (hStmt, i++, (void*)mail->eas_data, mail->eas_data_length); @@ -8285,12 +8498,10 @@ INTERNAL_FUNC int emstorage_change_mail(int mail_id, emstorage_mail_tbl_t* mail, FINISH_OFF: EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error); - _DISCONNECT_DB; 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); + EM_DEBUG_EXCEPTION ("sqlite3_finalize error [%d]", rc); error = EMAIL_ERROR_DB_FAILURE; } } @@ -8328,11 +8539,13 @@ INTERNAL_FUNC int emstorage_clean_save_status(int save_status, int *err_code) memset(sql_query_string, 0x00, sizeof(sql_query_string)); SNPRINTF(sql_query_string, sizeof(sql_query_string), "UPDATE mail_tbl SET save_status = %d WHERE save_status = %d", save_status, EMAIL_MAIL_STATUS_SENDING); - EM_DEBUG_LOG("Query [%s]", sql_query_string); - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc); - EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, - ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + EM_DEBUG_LOG_SEC("Query [%s]", sql_query_string); + error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); + if (error != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; + } rc = sqlite3_changes(local_db_handle); if (rc == 0) { @@ -8356,7 +8569,6 @@ INTERNAL_FUNC int emstorage_set_field_of_mails_with_integer_value(int account_id EM_DEBUG_FUNC_BEGIN_SEC("account_id [%d], mail_ids[%p], mail_ids_count[%d], field_name[%s], value[%d], transaction[%d], err_code[%p]", account_id, mail_ids, mail_ids_count, field_name, value, transaction, err_code); int i = 0; int error = EMAIL_ERROR_NONE; - int rc = 0; int ret = false; int cur_mail_id_string = 0; int mail_id_string_buffer_length = 0; @@ -8418,9 +8630,12 @@ INTERNAL_FUNC int emstorage_set_field_of_mails_with_integer_value(int account_id /* Execute query */ EMSTORAGE_START_WRITE_TRANSACTION(transaction, error); - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc); - EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, - ("sqlite3_exec failed [%d] [%s]", rc, sql_query_string)); + error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); + if (error != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; + } + if (sqlite3_changes(local_db_handle) == 0) EM_DEBUG_LOG("no mail matched..."); @@ -8428,7 +8643,6 @@ INTERNAL_FUNC int emstorage_set_field_of_mails_with_integer_value(int account_id FINISH_OFF: EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error); - _DISCONNECT_DB; if (error == EMAIL_ERROR_NONE && parameter_string) { if (!emcore_notify_storage_event (NOTI_MAIL_FIELD_UPDATE, account_id, target_mail_attribute_type, parameter_string, value)) @@ -8473,7 +8687,7 @@ INTERNAL_FUNC int emstorage_change_mail_text_field(int mail_id, emstorage_mail_t " body_text = ?" " WHERE mail_id = %d AND account_id != 0" , mail_id); - EM_DEBUG_LOG("Query [%s]", sql_query_string); + EM_DEBUG_LOG_SEC("Query [%s]", sql_query_string); EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, @@ -8499,12 +8713,11 @@ INTERNAL_FUNC int emstorage_change_mail_text_field(int mail_id, emstorage_mail_t FINISH_OFF: EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error); - _DISCONNECT_DB; if (hStmt != NULL) { rc = sqlite3_finalize(hStmt); if (rc != SQLITE_OK) { - EM_DEBUG_LOG(" sqlite3_finalize failed - %d", rc); + EM_DEBUG_EXCEPTION ("sqlite3_finalize error [%d]", rc); error = EMAIL_ERROR_DB_FAILURE; } hStmt = NULL; @@ -8644,7 +8857,7 @@ INTERNAL_FUNC int emstorage_change_mail_field(int mail_id, email_mail_change_typ , mail->flags_draft_field , mail->flags_forwarded_field , mail_id); - EM_DEBUG_LOG("Query [%s]", sql_query_string); + EM_DEBUG_LOG_SEC("Query [%s]", sql_query_string); EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); @@ -8668,7 +8881,7 @@ INTERNAL_FUNC int emstorage_change_mail_field(int mail_id, email_mail_change_typ , mail->report_status , mail->DRM_status , mail_id); - EM_DEBUG_LOG("Query [%s]", sql_query_string); + EM_DEBUG_LOG_SEC("Query [%s]", sql_query_string); EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); @@ -8683,7 +8896,7 @@ INTERNAL_FUNC int emstorage_change_mail_field(int mail_id, email_mail_change_typ " WHERE mail_id = %d AND account_id != 0" , mail->lock_status , mail_id); - EM_DEBUG_LOG("Query [%s]", sql_query_string); + EM_DEBUG_LOG_SEC("Query [%s]", sql_query_string); EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); @@ -8731,6 +8944,7 @@ INTERNAL_FUNC int emstorage_change_mail_field(int mail_id, email_mail_change_typ ", tag_id = ?" ", replied_time = ?" ", forwarded_time = ?" + ", default_charset = ?" ", eas_data_length = ?" ", eas_data = ?" " WHERE mail_id = %d AND account_id != 0" @@ -8779,6 +8993,7 @@ INTERNAL_FUNC int emstorage_change_mail_field(int mail_id, email_mail_change_typ _bind_stmt_field_data_int (hStmt, i++, mail->tag_id); _bind_stmt_field_data_int (hStmt, i++, mail->replied_time); _bind_stmt_field_data_int (hStmt, i++, mail->forwarded_time); + _bind_stmt_field_data_string(hStmt, i++, (char*)mail->default_charset, 0, TEXT_2_LEN_IN_MAIL_TBL); _bind_stmt_field_data_int (hStmt, i++, mail->eas_data_length); _bind_stmt_field_data_blob (hStmt, i++, (void*)mail->eas_data, mail->eas_data_length); break; @@ -8863,7 +9078,9 @@ INTERNAL_FUNC int emstorage_change_mail_field(int mail_id, email_mail_change_typ ", file_path_html = ?" ", attachment_count = ?" ", inline_content_count = ?" - ", preview_text= ?" + ", preview_text = ?" + ", digest_type = ?" + ", smime_type = ?" " WHERE mail_id = %d" , mail_id); @@ -8879,6 +9096,8 @@ INTERNAL_FUNC int emstorage_change_mail_field(int mail_id, email_mail_change_typ _bind_stmt_field_data_int(hStmt, i++, mail->attachment_count); _bind_stmt_field_data_int(hStmt, i++, mail->inline_content_count); _bind_stmt_field_data_nstring(hStmt, i++, (char *)mail->preview_text, 0, PREVIEWBODY_LEN_IN_MAIL_TBL); + _bind_stmt_field_data_int(hStmt, i++, mail->digest_type); + _bind_stmt_field_data_int(hStmt, i++, mail->smime_type); break; @@ -8940,12 +9159,11 @@ INTERNAL_FUNC int emstorage_change_mail_field(int mail_id, email_mail_change_typ FINISH_OFF: EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error); - _DISCONNECT_DB; if (hStmt != NULL) { rc = sqlite3_finalize(hStmt); if (rc != SQLITE_OK) { - EM_DEBUG_LOG(" sqlite3_finalize failed - %d", rc); + EM_DEBUG_EXCEPTION ("sqlite3_finalize error [%d]", rc); error = EMAIL_ERROR_DB_FAILURE; } hStmt = NULL; @@ -9019,7 +9237,6 @@ INTERNAL_FUNC int emstorage_increase_mail_id(int *mail_id, int transaction, int ret = true; FINISH_OFF: - _DISCONNECT_DB; if (err_code != NULL) *err_code = error; @@ -9055,8 +9272,14 @@ INTERNAL_FUNC int emstorage_add_mail(emstorage_mail_tbl_t *mail_tbl_data, int ge char **result; EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql, &result, NULL, NULL, NULL), rc); - EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; }, - ("SQL[%s] sqlite3_get_table fail[%d] [%s]", sql, rc, sqlite3_errmsg(local_db_handle))); +/* EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_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 (rc != SQLITE_OK) { + EM_DEBUG_EXCEPTION ("SQL[%s] sqlite3_get_table fail[%d] [%s]", sql, rc, sqlite3_errmsg(local_db_handle)); + error = EMAIL_ERROR_DB_FAILURE; + sqlite3_free_table(result); + goto FINISH_OFF; + } if (NULL == result[1]) rc = 1; @@ -9079,129 +9302,167 @@ INTERNAL_FUNC int emstorage_add_mail(emstorage_mail_tbl_t *mail_tbl_data, int ge ", ?" /* mailbox_id */ ", ?" /* mailbox_type */ ", ?" /* subject */ + ", ?" /* date_time */ ", ?" /* server_mail_status */ ", ?" /* server_mailbox_name */ ", ?" /* server_mail_id */ ", ?" /* message_id */ + ", ?" /* reference_mail_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 */ ", ?" /* file_path_mime_entity */ + ", ?" /* 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 */ ", ?" /* message_class */ + ", ?" /* digest_type */ ", ?" /* smime_type */ ", ?" /* scheduled_sending_time */ ", ?" /* remaining_resend_times */ ", ?" /* tag_id */ + ", ?" /* replied_time */ ", ?" /* forwarded_time */ + ", ?" /* default charset */ ", ?" /* eas_data_length */ ", ?" /* eas_data */ ")"); - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); - EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, - ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, + sql_query_string, + EM_SAFE_STRLEN(sql_query_string), + &hStmt, + NULL), + rc); + if (rc != SQLITE_OK) { + EM_DEBUG_EXCEPTION ("sqlite3_prepare error [%d] [%s] SQL(%s) ", + sql_query_string, rc, sqlite3_errmsg(local_db_handle)); + error = EMAIL_ERROR_DB_FAILURE; + goto FINISH_OFF; + } _bind_stmt_field_data_int (hStmt, MAIL_ID_IDX_IN_MAIL_TBL, mail_tbl_data->mail_id); _bind_stmt_field_data_int (hStmt, ACCOUNT_ID_IDX_IN_MAIL_TBL, mail_tbl_data->account_id); _bind_stmt_field_data_int (hStmt, MAILBOX_ID_IDX_IN_MAIL_TBL, mail_tbl_data->mailbox_id); _bind_stmt_field_data_int (hStmt, MAILBOX_TYPE_IDX_IN_MAIL_TBL, mail_tbl_data->mailbox_type); _bind_stmt_field_data_string(hStmt, SUBJECT_IDX_IN_MAIL_TBL, (char*)mail_tbl_data->subject, 1, SUBJECT_LEN_IN_MAIL_TBL); + _bind_stmt_field_data_int (hStmt, DATETIME_IDX_IN_MAIL_TBL, mail_tbl_data->date_time); _bind_stmt_field_data_int (hStmt, SERVER_MAIL_STATUS_IDX_IN_MAIL_TBL, mail_tbl_data->server_mail_status); _bind_stmt_field_data_string(hStmt, SERVER_MAILBOX_NAME_IDX_IN_MAIL_TBL, (char*)mail_tbl_data->server_mailbox_name, 0, SERVER_MAILBOX_LEN_IN_MAIL_TBL); _bind_stmt_field_data_string(hStmt, SERVER_MAIL_ID_IDX_IN_MAIL_TBL, (char*)mail_tbl_data->server_mail_id, 0, SERVER_MAIL_ID_LEN_IN_MAIL_TBL); _bind_stmt_field_data_string(hStmt, MESSAGE_ID_IDX_IN_MAIL_TBL, (char*)mail_tbl_data->message_id, 0, MESSAGE_ID_LEN_IN_MAIL_TBL); + _bind_stmt_field_data_int (hStmt, REFERENCE_ID_IDX_IN_MAIL_TBL, mail_tbl_data->reference_mail_id); _bind_stmt_field_data_string(hStmt, FULL_ADDRESS_FROM_IDX_IN_MAIL_TBL, (char*)mail_tbl_data->full_address_from, 1, FROM_LEN_IN_MAIL_TBL); _bind_stmt_field_data_string(hStmt, FULL_ADDRESS_REPLY_IDX_IN_MAIL_TBL, (char*)mail_tbl_data->full_address_reply, 1, REPLY_TO_LEN_IN_MAIL_TBL); _bind_stmt_field_data_string(hStmt, FULL_ADDRESS_TO_IDX_IN_MAIL_TBL, (char*)mail_tbl_data->full_address_to, 1, TO_LEN_IN_MAIL_TBL); _bind_stmt_field_data_string(hStmt, FULL_ADDRESS_CC_IDX_IN_MAIL_TBL, (char*)mail_tbl_data->full_address_cc, 1, CC_LEN_IN_MAIL_TBL); + _bind_stmt_field_data_string(hStmt, FULL_ADDRESS_BCC_IDX_IN_MAIL_TBL, (char*)mail_tbl_data->full_address_bcc, 1, BCC_LEN_IN_MAIL_TBL); _bind_stmt_field_data_string(hStmt, FULL_ADDRESS_RETURN_IDX_IN_MAIL_TBL, (char*)mail_tbl_data->full_address_return, 1, RETURN_PATH_LEN_IN_MAIL_TBL); _bind_stmt_field_data_string(hStmt, EMAIL_ADDRESS_SENDER_IDX_IN_MAIL_TBL, (char*)mail_tbl_data->email_address_sender, 1, FROM_EMAIL_ADDRESS_LEN_IN_MAIL_TBL); _bind_stmt_field_data_string(hStmt, EMAIL_ADDRESS_RECIPIENT_IDX_IN_MAIL_TBL, (char*)mail_tbl_data->email_address_recipient, 1, TO_EMAIL_ADDRESS_LEN_IN_MAIL_TBL); _bind_stmt_field_data_string(hStmt, ALIAS_SENDER_IDX_IN_MAIL_TBL, (char*)mail_tbl_data->alias_sender, 1, FROM_CONTACT_NAME_LEN_IN_MAIL_TBL); + _bind_stmt_field_data_string(hStmt, ALIAS_RECIPIENT_IDX_IN_MAIL_TBL, (char*)mail_tbl_data->alias_recipient, 1, FROM_CONTACT_NAME_LEN_IN_MAIL_TBL); _bind_stmt_field_data_int (hStmt, BODY_DOWNLOAD_STATUS_IDX_IN_MAIL_TBL, mail_tbl_data->body_download_status); _bind_stmt_field_data_string(hStmt, FILE_PATH_PLAIN_IDX_IN_MAIL_TBL, (char*)mail_tbl_data->file_path_plain, 0, TEXT_1_LEN_IN_MAIL_TBL); _bind_stmt_field_data_string(hStmt, FILE_PATH_HTML_IDX_IN_MAIL_TBL, (char*)mail_tbl_data->file_path_html, 0, TEXT_2_LEN_IN_MAIL_TBL); _bind_stmt_field_data_string(hStmt, FILE_PATH_MIME_ENTITY_IDX_IN_MAIL_TBL, (char*)mail_tbl_data->file_path_mime_entity, 0, MIME_ENTITY_LEN_IN_MAIL_TBL); + _bind_stmt_field_data_int (hStmt, MAIL_SIZE_IDX_IN_MAIL_TBL, mail_tbl_data->mail_size); _bind_stmt_field_data_int (hStmt, FLAGS_SEEN_FIELD_IDX_IN_MAIL_TBL, mail_tbl_data->flags_seen_field); _bind_stmt_field_data_int (hStmt, FLAGS_DELETED_FIELD_IDX_IN_MAIL_TBL, mail_tbl_data->flags_deleted_field); _bind_stmt_field_data_int (hStmt, FLAGS_FLAGGED_FIELD_IDX_IN_MAIL_TBL, mail_tbl_data->flags_flagged_field); _bind_stmt_field_data_int (hStmt, FLAGS_ANSWERED_FIELD_IDX_IN_MAIL_TBL, mail_tbl_data->flags_answered_field); + _bind_stmt_field_data_int (hStmt, FLAGS_RECENT_FIELD_IDX_IN_MAIL_TBL, mail_tbl_data->flags_recent_field); _bind_stmt_field_data_int (hStmt, FLAGS_DRAFT_FIELD_IDX_IN_MAIL_TBL, mail_tbl_data->flags_draft_field); _bind_stmt_field_data_int (hStmt, FLAGS_FORWARDED_FIELD_IDX_IN_MAIL_TBL, mail_tbl_data->flags_forwarded_field); _bind_stmt_field_data_int (hStmt, DRM_STATUS_IDX_IN_MAIL_TBL, mail_tbl_data->DRM_status); _bind_stmt_field_data_int (hStmt, PRIORITY_IDX_IN_MAIL_TBL, mail_tbl_data->priority); + _bind_stmt_field_data_int (hStmt, SAVE_STATUS_IDX_IN_MAIL_TBL, mail_tbl_data->save_status); _bind_stmt_field_data_int (hStmt, LOCK_STATUS_IDX_IN_MAIL_TBL, mail_tbl_data->lock_status); _bind_stmt_field_data_int (hStmt, REPORT_STATUS_IDX_IN_MAIL_TBL, mail_tbl_data->report_status); _bind_stmt_field_data_int (hStmt, ATTACHMENT_COUNT_IDX_IN_MAIL_TBL, mail_tbl_data->attachment_count); _bind_stmt_field_data_int (hStmt, INLINE_CONTENT_COUNT_IDX_IN_MAIL_TBL, mail_tbl_data->inline_content_count); + _bind_stmt_field_data_int (hStmt, THREAD_ID_IDX_IN_MAIL_TBL, mail_tbl_data->thread_id); _bind_stmt_field_data_int (hStmt, THREAD_ITEM_COUNT_IDX_IN_MAIL_TBL, mail_tbl_data->thread_item_count); _bind_stmt_field_data_nstring(hStmt, PREVIEW_TEXT_IDX_IN_MAIL_TBL, (char*)mail_tbl_data->preview_text, 1, PREVIEWBODY_LEN_IN_MAIL_TBL); _bind_stmt_field_data_int (hStmt, MEETING_REQUEST_STATUS_IDX_IN_MAIL_TBL, mail_tbl_data->meeting_request_status); _bind_stmt_field_data_int (hStmt, MESSAGE_CLASS_IDX_IN_MAIL_TBL, mail_tbl_data->message_class); + _bind_stmt_field_data_int (hStmt, DIGEST_TYPE_IDX_IN_MAIL_TBL, mail_tbl_data->digest_type); _bind_stmt_field_data_int (hStmt, SMIME_TYPE_IDX_IN_MAIL_TBL, mail_tbl_data->smime_type); _bind_stmt_field_data_int (hStmt, SCHEDULED_SENDING_TIME_IDX_IN_MAIL_TBL, mail_tbl_data->scheduled_sending_time); _bind_stmt_field_data_int (hStmt, REMAINING_RESEND_TIMES_IDX_IN_MAIL_TBL, mail_tbl_data->remaining_resend_times); _bind_stmt_field_data_int (hStmt, TAG_ID_IDX_IN_MAIL_TBL, mail_tbl_data->tag_id); + _bind_stmt_field_data_int (hStmt, REPLIED_TIME_IDX_IN_MAIL_TBL, mail_tbl_data->replied_time); _bind_stmt_field_data_int (hStmt, FORWARDED_TIME_IDX_IN_MAIL_TBL, mail_tbl_data->forwarded_time); + _bind_stmt_field_data_string(hStmt, DEFAULT_CHARSET_IDX_IN_MAIL_TBL, (char*)mail_tbl_data->default_charset, 0, TEXT_2_LEN_IN_MAIL_TBL); _bind_stmt_field_data_int (hStmt, EAS_DATA_LENGTH_IDX_IN_MAIL_TBL, mail_tbl_data->eas_data_length); _bind_stmt_field_data_blob (hStmt, EAS_DATA_IDX_IN_MAIL_TBL, (void*)mail_tbl_data->eas_data, mail_tbl_data->eas_data_length); EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc); - EM_DEBUG_DB_EXEC((rc == SQLITE_FULL), {error = EMAIL_ERROR_MAIL_MEMORY_FULL;goto FINISH_OFF; }, ("sqlite3_step fail:%d", rc)); - EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, ("sqlite3_step fail:%d", rc)); + if (rc == SQLITE_FULL) { + EM_DEBUG_EXCEPTION ("sqlite3_step error [%d]", rc); + error = EMAIL_ERROR_MAIL_MEMORY_FULL; + goto FINISH_OFF; + } + if (rc != SQLITE_ROW && rc != SQLITE_DONE) { + EM_DEBUG_EXCEPTION ("sqlite3_step error [%d]", rc); + error = EMAIL_ERROR_DB_FAILURE; + goto FINISH_OFF; + } ret = true; FINISH_OFF: EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error); - _DISCONNECT_DB; if (hStmt != NULL) { rc = sqlite3_finalize(hStmt); if (rc != SQLITE_OK) { - EM_DEBUG_LOG("sqlite3_finalize failed [%d]", rc); + EM_DEBUG_EXCEPTION ("sqlite3_finalize error [%d]", rc); error = EMAIL_ERROR_DB_FAILURE; } } @@ -9218,7 +9479,7 @@ INTERNAL_FUNC int emstorage_move_multiple_mails_on_db(int input_source_account_i { EM_DEBUG_FUNC_BEGIN("input_source_account_id [%d], input_mailbox_id [%d], mail_ids[%p], number_of_mails [%d], transaction[%d], err_code[%p]", input_source_account_id, input_mailbox_id, mail_ids, number_of_mails, transaction, err_code); - int rc, ret = false, i, cur_conditional_clause = 0; + int ret = false, i, cur_conditional_clause = 0; int error = EMAIL_ERROR_NONE; int target_account_id; char sql_query_string[QUERY_SIZE] = {0, }, conditional_clause[QUERY_SIZE] = {0, }; @@ -9269,39 +9530,44 @@ INTERNAL_FUNC int emstorage_move_multiple_mails_on_db(int input_source_account_i memset(sql_query_string, 0x00, QUERY_SIZE); SNPRINTF(sql_query_string, QUERY_SIZE, "UPDATE mail_tbl SET mailbox_type = %d, mailbox_id = %d, account_id = %d %s", target_mailbox_type, input_mailbox_id, target_account_id, conditional_clause); - EM_DEBUG_LOG("Query [%s]", sql_query_string); + EM_DEBUG_LOG_SEC("Query [%s]", sql_query_string); - EMSTORAGE_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))); + error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); + if (error != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; + } /* Updating a mail_attachment_tbl */ memset(sql_query_string, 0x00, QUERY_SIZE); SNPRINTF(sql_query_string, QUERY_SIZE, "UPDATE mail_attachment_tbl SET mailbox_id = '%d', account_id = %d %s", input_mailbox_id, target_account_id, conditional_clause); - EM_DEBUG_LOG("Query [%s]", sql_query_string); - - EMSTORAGE_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))); + EM_DEBUG_LOG_SEC("Query [%s]", sql_query_string); + error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); + if (error != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; + } /* Updating a mail_meeting_tbl */ memset(sql_query_string, 0x00, QUERY_SIZE); SNPRINTF(sql_query_string, QUERY_SIZE, "UPDATE mail_meeting_tbl SET mailbox_id = %d, account_id = %d %s", input_mailbox_id, target_account_id, conditional_clause); - EM_DEBUG_LOG("Query [%s]", sql_query_string); - - EMSTORAGE_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))); + EM_DEBUG_LOG_SEC("Query [%s]", sql_query_string); + error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); + if (error != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; + } #ifdef __FEATURE_BODY_SEARCH__ /* Updating mail_text_tbl */ memset(sql_query_string, 0x00, QUERY_SIZE); SNPRINTF(sql_query_string, QUERY_SIZE, "UPDATE mail_text_tbl SET mailbox_id = %d, account_id = %d %s", input_mailbox_id, target_account_id, conditional_clause); - EM_DEBUG_LOG("Query [%s]", sql_query_string); - - EMSTORAGE_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))); + EM_DEBUG_LOG_SEC("Query [%s]", sql_query_string); + error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); + if (error != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; + } #endif /* Updating a mail_read_mail_uid_tbl */ @@ -9317,17 +9583,17 @@ INTERNAL_FUNC int emstorage_move_multiple_mails_on_db(int input_source_account_i memset(sql_query_string, 0x00, QUERY_SIZE); SNPRINTF(sql_query_string, QUERY_SIZE, "UPDATE mail_read_mail_uid_tbl SET mailbox_name = '%s', mailbox_id = %d, account_id = %d %s", target_mailbox_name, input_mailbox_id, target_account_id, conditional_clause); - EM_DEBUG_LOG("Query [%s]", sql_query_string); - - EMSTORAGE_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))); + EM_DEBUG_LOG_SEC("Query [%s]", sql_query_string); + error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); + if (error != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; + } ret = true; FINISH_OFF: EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error); - _DISCONNECT_DB; EM_SAFE_FREE(target_mailbox_name); @@ -9349,28 +9615,26 @@ INTERNAL_FUNC int emstorage_delete_mail(int mail_id, int from_server, int transa return false; } - int rc, ret = false; + int ret = false; int error = EMAIL_ERROR_NONE; char sql_query_string[QUERY_SIZE] = {0, }; - sqlite3 *local_db_handle = emstorage_get_db_connection(); EMSTORAGE_START_WRITE_TRANSACTION(transaction, error); 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); - - - EMSTORAGE_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))); + EM_DEBUG_LOG_SEC("Query [%s]", sql_query_string); + error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); + if (error != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; + } ret = true; FINISH_OFF: EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error); - _DISCONNECT_DB; if (err_code != NULL) *err_code = error; @@ -9383,7 +9647,7 @@ INTERNAL_FUNC int emstorage_delete_multiple_mails(int mail_ids[], int number_of_ { 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 ret = false, i, cur_sql_query_string = 0; int error = EMAIL_ERROR_NONE; char sql_query_string[QUERY_SIZE] = {0, }; @@ -9406,11 +9670,12 @@ INTERNAL_FUNC int emstorage_delete_multiple_mails(int mail_ids[], int number_of_ char *last_comma = rindex(sql_query_string, ','); *last_comma = ')'; /* replace , with ) */ - EM_DEBUG_LOG("Query [%s]", sql_query_string); - - EMSTORAGE_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))); + EM_DEBUG_LOG_SEC("Query [%s]", sql_query_string); + error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); + if (error != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; + } #ifdef __FEATURE_BODY_SEARCH__ /* delete mail_text from mail_text_tbl */ @@ -9422,18 +9687,18 @@ INTERNAL_FUNC int emstorage_delete_multiple_mails(int mail_ids[], int number_of_ last_comma = rindex(sql_query_string, ','); *last_comma = ')'; /* replace , with ) */ - EM_DEBUG_LOG("Query [%s]", sql_query_string); - - EMSTORAGE_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))); + EM_DEBUG_LOG_SEC("Query [%s]", sql_query_string); + error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); + if (error != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; + } #endif ret = true; FINISH_OFF: EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error); - _DISCONNECT_DB; if (err_code != NULL) *err_code = error; @@ -9462,11 +9727,12 @@ INTERNAL_FUNC int emstorage_delete_mail_by_account(int account_id, int transacti EMSTORAGE_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); - - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc); - EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, - ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + EM_DEBUG_LOG_SEC("Query [%s]", sql_query_string); + error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); + if (error != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; + } rc = sqlite3_changes(local_db_handle); if (rc == 0) { @@ -9476,11 +9742,12 @@ INTERNAL_FUNC int emstorage_delete_mail_by_account(int account_id, int transacti /* 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); - - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc); - EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, - ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + EM_DEBUG_LOG_SEC("Query [%s]", sql_query_string); + error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); + if (error != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; + } rc = sqlite3_changes(local_db_handle); if (rc == 0) { @@ -9491,11 +9758,12 @@ INTERNAL_FUNC int emstorage_delete_mail_by_account(int account_id, int transacti #ifdef __FEATURE_BODY_SEARCH__ /* Delete all mail_text in mail_text_tbl table based on account id */ SNPRINTF(sql_query_string, sizeof(sql_query_string), "DELETE FROM mail_text_tbl WHERE account_id = %d", account_id); - EM_DEBUG_LOG("Query [%s]", sql_query_string); - - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc); - EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + EM_DEBUG_LOG_SEC("Query [%s]", sql_query_string); + error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); + if (error != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; + } rc = sqlite3_changes(local_db_handle); if (rc == 0) { @@ -9508,7 +9776,6 @@ INTERNAL_FUNC int emstorage_delete_mail_by_account(int account_id, int transacti FINISH_OFF: EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error); - _DISCONNECT_DB; if (error == EMAIL_ERROR_NONE) { if (!emcore_notify_storage_event (NOTI_MAIL_DELETE_WITH_ACCOUNT, account_id, 0 , NULL, 0)) @@ -9522,58 +9789,76 @@ FINISH_OFF: return ret; } -INTERNAL_FUNC int emstorage_delete_mail_by_mailbox(int account_id, int mailbox_id, int transaction, int *err_code) +INTERNAL_FUNC int emstorage_delete_mail_by_mailbox(emstorage_mailbox_tbl_t *mailbox, int transaction, int *err_code) { - EM_DEBUG_FUNC_BEGIN("account_id[%d], mailbox[%d], transaction[%d], err_code[%p]", account_id, mailbox_id, transaction, err_code); + EM_DEBUG_FUNC_BEGIN("mailbox[%p], transaction[%d], err_code[%p]", mailbox, transaction, err_code); - if (account_id < FIRST_ACCOUNT_ID || mailbox_id == 0) { - EM_DEBUG_EXCEPTION(" account_id[%d], mailbox_id[%d]", account_id, mailbox_id); + if (mailbox == NULL) { + EM_DEBUG_EXCEPTION("mailbox [%p]", mailbox); if (err_code != NULL) *err_code = EMAIL_ERROR_INVALID_PARAM; return false; } - int rc, ret = false; + int ret = false; int error = EMAIL_ERROR_NONE; char sql_query_string[QUERY_SIZE] = {0, }; - sqlite3 *local_db_handle = emstorage_get_db_connection(); EMSTORAGE_START_WRITE_TRANSACTION(transaction, error); - SNPRINTF(sql_query_string, sizeof(sql_query_string), "DELETE FROM mail_tbl WHERE account_id = %d AND mailbox_id = '%d'", account_id, mailbox_id); - EM_DEBUG_LOG("Query [%s]", sql_query_string); - - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc); - EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, - ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); - + if (strcmp(mailbox->mailbox_name, EMAIL_SEARCH_RESULT_MAILBOX_NAME) == 0) { + SNPRINTF(sql_query_string, sizeof(sql_query_string), "DELETE FROM mail_tbl WHERE account_id = %d AND mailbox_type = %d", mailbox->account_id, mailbox->mailbox_type); + EM_DEBUG_LOG_SEC("Query [%s]", sql_query_string); + error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); + if (error != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; + } - /* 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_id = '%d'", account_id, mailbox_id); - EM_DEBUG_LOG("Query [%s]", sql_query_string); + /* 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'", mailbox->account_id, mailbox->mailbox_name); + EM_DEBUG_LOG_SEC("Query [%s]", sql_query_string); + error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); + if (error != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; + } + } else { + SNPRINTF(sql_query_string, sizeof(sql_query_string), "DELETE FROM mail_tbl WHERE account_id = %d AND mailbox_id = %d", mailbox->account_id, mailbox->mailbox_id); + EM_DEBUG_LOG_SEC("Query [%s]", sql_query_string); + error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); + if (error != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; + } - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc); - EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_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_id = %d", mailbox->account_id, mailbox->mailbox_id); + EM_DEBUG_LOG_SEC("Query [%s]", sql_query_string); + error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); + if (error != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; + } #ifdef __FEATURE_BODY_SEARCH__ - /* Delete Mails from mail_text_tbl */ - SNPRINTF(sql_query_string, sizeof(sql_query_string), "DELETE FROM mail_text_tbl WHERE account_id = %d AND mailbox_id = %d", account_id, mailbox_id); - EM_DEBUG_LOG("Query [%s]", sql_query_string); - - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc); - EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_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_text_tbl */ + SNPRINTF(sql_query_string, sizeof(sql_query_string), "DELETE FROM mail_text_tbl WHERE account_id = %d AND mailbox_id = %d", mailbox->account_id, mailbox->mailbox_id); + EM_DEBUG_LOG_SEC("Query [%s]", sql_query_string); + error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); + if (error != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; + } #endif - + } ret = true; FINISH_OFF: EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error); - _DISCONNECT_DB; if (error == EMAIL_ERROR_NONE) { - if (!emcore_notify_storage_event(NOTI_MAIL_DELETE_ALL, account_id, mailbox_id , 0, 0)) + if (!emcore_notify_storage_event(NOTI_MAIL_DELETE_ALL, mailbox->account_id, mailbox->mailbox_id , mailbox->mailbox_name, 0)) EM_DEBUG_EXCEPTION(" emcore_notify_storage_event Failed [ NOTI_MAIL_DELETE_ALL ] >>>> "); } @@ -9619,6 +9904,8 @@ INTERNAL_FUNC int emstorage_free_mail(emstorage_mail_tbl_t** mail_list, int coun EM_SAFE_FREE(p->preview_text); EM_SAFE_FREE(p->alias_sender); EM_SAFE_FREE(p->alias_recipient); + EM_SAFE_FREE(p->default_charset); + EM_SAFE_FREE(p->pgp_password); EM_SAFE_FREE(p->eas_data); } EM_SAFE_FREE(*mail_list); @@ -9689,7 +9976,6 @@ INTERNAL_FUNC int emstorage_get_attachment_count(int mail_id, int *count, int tr FINISH_OFF: EMSTORAGE_FINISH_READ_TRANSACTION(transaction); - _DISCONNECT_DB; if (err_code != NULL) *err_code = error; @@ -9739,7 +10025,7 @@ INTERNAL_FUNC int emstorage_get_attachment_list(int input_mail_id, int input_tra } 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_DEBUG_LOG_SEC("sql_query_string [%s]", sql_query_string); EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); @@ -9756,6 +10042,7 @@ INTERNAL_FUNC int emstorage_get_attachment_list(int input_mail_id, int input_tra _get_stmt_field_data_int (hStmt, &(p_data_tbl[i].attachment_id), ATTACHMENT_ID_IDX_IN_MAIL_ATTACHMENT_TBL); _get_stmt_field_data_string(hStmt, &(p_data_tbl[i].attachment_name), 0, ATTACHMENT_NAME_IDX_IN_MAIL_ATTACHMENT_TBL); _get_stmt_field_data_string(hStmt, &(p_data_tbl[i].attachment_path), 0, ATTACHMENT_PATH_IDX_IN_MAIL_ATTACHMENT_TBL); + _get_stmt_field_data_string(hStmt, &(p_data_tbl[i].content_id), 0, CONTENT_ID_IDX_IN_MAIL_ATTACHMENT_TBL); _get_stmt_field_data_int (hStmt, &(p_data_tbl[i].attachment_size), ATTACHMENT_SIZE_IDX_IN_MAIL_ATTACHMENT_TBL); _get_stmt_field_data_int (hStmt, &(p_data_tbl[i].mail_id), MAIL_ID_IDX_IN_MAIL_ATTACHMENT_TBL); _get_stmt_field_data_int (hStmt, &(p_data_tbl[i].account_id), ACCOUNT_ID_IDX_IN_MAIL_ATTACHMENT_TBL); @@ -9781,13 +10068,14 @@ FINISH_OFF: if (hStmt) { rc = sqlite3_finalize(hStmt); if (rc != SQLITE_OK) { - EM_DEBUG_EXCEPTION("sqlite3_finalize failed [%d]", rc); + EM_DEBUG_EXCEPTION ("sqlite3_finalize error [%d]", rc); error = EMAIL_ERROR_DB_FAILURE; + if (*output_attachment_list) + emstorage_free_attachment(output_attachment_list, *output_attachment_count, NULL); /* prevent */ } } EMSTORAGE_FINISH_READ_TRANSACTION(input_transaction); - _DISCONNECT_DB; EM_DEBUG_FUNC_END("error [%d]", error); return error; @@ -9842,6 +10130,7 @@ INTERNAL_FUNC int emstorage_get_attachment(int attachment_id, emstorage_attachme _get_stmt_field_data_int(hStmt, &(p_data_tbl->attachment_id), ATTACHMENT_ID_IDX_IN_MAIL_ATTACHMENT_TBL); _get_stmt_field_data_string(hStmt, &(p_data_tbl->attachment_name), 0, ATTACHMENT_NAME_IDX_IN_MAIL_ATTACHMENT_TBL); _get_stmt_field_data_string(hStmt, &(p_data_tbl->attachment_path), 0, ATTACHMENT_PATH_IDX_IN_MAIL_ATTACHMENT_TBL); + _get_stmt_field_data_string(hStmt, &(p_data_tbl->content_id), 0, CONTENT_ID_IDX_IN_MAIL_ATTACHMENT_TBL); _get_stmt_field_data_int(hStmt, &(p_data_tbl->attachment_size), ATTACHMENT_SIZE_IDX_IN_MAIL_ATTACHMENT_TBL); _get_stmt_field_data_int(hStmt, &(p_data_tbl->mail_id), MAIL_ID_IDX_IN_MAIL_ATTACHMENT_TBL); _get_stmt_field_data_int(hStmt, &(p_data_tbl->account_id), ACCOUNT_ID_IDX_IN_MAIL_ATTACHMENT_TBL); @@ -9864,8 +10153,6 @@ FINISH_OFF: *attachment = p_data_tbl; if (hStmt != NULL) { - EM_DEBUG_LOG_DEV ("Before sqlite3_finalize hStmt = %p", hStmt); - rc = sqlite3_finalize(hStmt); if (rc != SQLITE_OK) { EM_DEBUG_EXCEPTION("sqlite3_finalize failed [%d]", rc); @@ -9874,7 +10161,6 @@ FINISH_OFF: } EMSTORAGE_FINISH_READ_TRANSACTION(transaction); - _DISCONNECT_DB; if (err_code != NULL) *err_code = error; @@ -9905,7 +10191,7 @@ INTERNAL_FUNC int emstorage_get_attachment_nth(int mail_id, int nth, emstorage_a EMSTORAGE_START_READ_TRANSACTION(transaction); SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT * FROM mail_attachment_tbl WHERE mail_id = %d ORDER BY attachment_id LIMIT %d, 1", mail_id, (nth - 1)); - EM_DEBUG_LOG("query = [%s]", sql_query_string); + EM_DEBUG_LOG_SEC("query = [%s]", sql_query_string); DB_STMT hStmt = NULL; @@ -9919,7 +10205,7 @@ INTERNAL_FUNC int emstorage_get_attachment_nth(int mail_id, int nth, emstorage_a ("sqlite3_step fail:%d", rc)); if (rc == SQLITE_DONE) { - EM_DEBUG_EXCEPTION(" no matched attachment found..."); + EM_DEBUG_EXCEPTION("no matched attachment found: mail_id[%d] nth[%d]", mail_id, nth); error = EMAIL_ERROR_ATTACHMENT_NOT_FOUND; goto FINISH_OFF; } @@ -9935,6 +10221,8 @@ INTERNAL_FUNC int emstorage_get_attachment_nth(int mail_id, int nth, emstorage_a p_data_tbl->attachment_name = cpy_str(p); if ((p = (char *)sqlite3_column_text(hStmt, ATTACHMENT_PATH_IDX_IN_MAIL_ATTACHMENT_TBL)) && (int)EM_SAFE_STRLEN(p)) p_data_tbl->attachment_path = cpy_str(p); + if ((p = (char *)sqlite3_column_text(hStmt, CONTENT_ID_IDX_IN_MAIL_ATTACHMENT_TBL)) && (int)EM_SAFE_STRLEN(p)) + p_data_tbl->content_id = 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); @@ -9957,17 +10245,102 @@ FINISH_OFF: *attachment_tbl = 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 error [%d]", rc); + error = EMAIL_ERROR_DB_FAILURE; + } + } + + EMSTORAGE_FINISH_READ_TRANSACTION(transaction); + + if (err_code != NULL) + *err_code = error; + + EM_DEBUG_FUNC_END("ret [%d]", ret); + return ret; +} + +INTERNAL_FUNC int emstorage_get_attachment_by_attachment_path(char *attachment_path, emstorage_attachment_tbl_t** attachment, int transaction, int *err_code) +{ + EM_DEBUG_FUNC_BEGIN("attachment_path[%p], attachment[%p], transaction[%d], err_code[%p]", attachment_path, attachment, transaction, err_code); + + if (attachment_path == NULL || !attachment) { + EM_DEBUG_EXCEPTION("attachment_path[%p], attachment[%p]", attachment_path, attachment); + if (err_code != NULL) + *err_code = EMAIL_ERROR_INVALID_PARAM; + return false; + } + emstorage_attachment_tbl_t* p_data_tbl = NULL; + int rc, ret = false; + int error = EMAIL_ERROR_NONE; + char sql_query_string[QUERY_SIZE] = {0, }; + + sqlite3 *local_db_handle = emstorage_get_db_connection(); + EMSTORAGE_START_READ_TRANSACTION(transaction); + + SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT * FROM mail_attachment_tbl WHERE attachment_path = '%s'", attachment_path); + + sqlite3_stmt* hStmt = NULL; + + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); + EM_DEBUG_LOG_DEV ("before sqlite3_prepare hStmt = %p", hStmt); + + EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, + ("sqlite3_prepare failed [%d] [%s]", rc, sql_query_string)); + + + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc); + EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, + ("sqlite3_step failed [%d] [%s]", rc, sql_query_string)); + + if (rc == SQLITE_DONE) { + EM_DEBUG_LOG ("no matched attachment found..."); + error = EMAIL_ERROR_ATTACHMENT_NOT_FOUND; + goto FINISH_OFF; + } + + if (!(p_data_tbl = (emstorage_attachment_tbl_t*)em_malloc(sizeof(emstorage_attachment_tbl_t) * 1))) { + EM_DEBUG_EXCEPTION("malloc failed..."); + error = EMAIL_ERROR_OUT_OF_MEMORY; + goto FINISH_OFF; + } + + _get_stmt_field_data_int(hStmt, &(p_data_tbl->attachment_id), ATTACHMENT_ID_IDX_IN_MAIL_ATTACHMENT_TBL); + _get_stmt_field_data_string(hStmt, &(p_data_tbl->attachment_name), 0, ATTACHMENT_NAME_IDX_IN_MAIL_ATTACHMENT_TBL); + _get_stmt_field_data_string(hStmt, &(p_data_tbl->attachment_path), 0, ATTACHMENT_PATH_IDX_IN_MAIL_ATTACHMENT_TBL); + _get_stmt_field_data_string(hStmt, &(p_data_tbl->content_id), 0, CONTENT_ID_IDX_IN_MAIL_ATTACHMENT_TBL); + _get_stmt_field_data_int(hStmt, &(p_data_tbl->attachment_size), ATTACHMENT_SIZE_IDX_IN_MAIL_ATTACHMENT_TBL); + _get_stmt_field_data_int(hStmt, &(p_data_tbl->mail_id), MAIL_ID_IDX_IN_MAIL_ATTACHMENT_TBL); + _get_stmt_field_data_int(hStmt, &(p_data_tbl->account_id), ACCOUNT_ID_IDX_IN_MAIL_ATTACHMENT_TBL); + _get_stmt_field_data_int(hStmt, &(p_data_tbl->mailbox_id), MAILBOX_ID_IDX_IN_MAIL_ATTACHMENT_TBL); + _get_stmt_field_data_int(hStmt, &(p_data_tbl->attachment_save_status), ATTACHMENT_SAVE_STATUS_IDX_IN_MAIL_ATTACHMENT_TBL); + _get_stmt_field_data_int(hStmt, &(p_data_tbl->attachment_drm_type), ATTACHMENT_DRM_TYPE_IDX_IN_MAIL_ATTACHMENT_TBL); + _get_stmt_field_data_int(hStmt, &(p_data_tbl->attachment_drm_method), ATTACHMENT_DRM_METHOD_IDX_IN_MAIL_ATTACHMENT_TBL); + _get_stmt_field_data_int(hStmt, &(p_data_tbl->attachment_inline_content_status), ATTACHMENT_INLINE_CONTENT_STATUS_IDX_IN_MAIL_ATTACHMENT_TBL); + _get_stmt_field_data_string(hStmt, &(p_data_tbl->attachment_mime_type), 0, ATTACHMENT_MIME_TYPE_IDX_IN_MAIL_ATTACHMENT_TBL); + +#ifdef __ATTACHMENT_OPTI__ + _get_stmt_field_data_int(hStmt, &(p_data_tbl->encoding), ENCODING_IDX_IN_MAIL_ATTACHMENT_TBL); + _get_stmt_field_data_string(hStmt, &(p_data_tbl->section), 0, SECTION_IDX_IN_MAIL_ATTACHMENT_TBL); +#endif + + ret = true; + +FINISH_OFF: + if (ret == true) + *attachment = p_data_tbl; + + if (hStmt != NULL) { rc = sqlite3_finalize(hStmt); if (rc != SQLITE_OK) { - EM_DEBUG_EXCEPTION("sqlite3_finalize failed - %d", rc); + EM_DEBUG_EXCEPTION("sqlite3_finalize failed [%d]", rc); error = EMAIL_ERROR_DB_FAILURE; } } EMSTORAGE_FINISH_READ_TRANSACTION(transaction); - _DISCONNECT_DB; if (err_code != NULL) *err_code = error; @@ -10028,7 +10401,7 @@ INTERNAL_FUNC int emstorage_change_attachment_field(int mail_id, email_mail_chan SNPRINTF(sql_query_string, sizeof(sql_query_string), "UPDATE mail_attachment_tbl SET" " attachment_size = ?" - ", attachment_save_status = 1" + ", attachment_save_status = ?" ", attachment_path = ?" " WHERE mail_id = %d" " AND attachment_id = %d" @@ -10042,6 +10415,7 @@ INTERNAL_FUNC int emstorage_change_attachment_field(int mail_id, email_mail_chan ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); _bind_stmt_field_data_int(hStmt, i++, attachment->attachment_size); + _bind_stmt_field_data_int(hStmt, i++, attachment->attachment_save_status); _bind_stmt_field_data_string(hStmt, i++, (char *)attachment->attachment_path, 0, ATTACHMENT_PATH_LEN_IN_MAIL_ATTACHMENT_TBL); break; @@ -10050,7 +10424,7 @@ INTERNAL_FUNC int emstorage_change_attachment_field(int mail_id, email_mail_chan error = EMAIL_ERROR_INVALID_PARAM; goto FINISH_OFF; } - EM_DEBUG_LOG("query = [%s]", sql_query_string); + EM_DEBUG_LOG_SEC("query = [%s]", sql_query_string); EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc); EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, @@ -10058,18 +10432,17 @@ INTERNAL_FUNC int emstorage_change_attachment_field(int mail_id, email_mail_chan ret = true; FINISH_OFF: + + EMSTORAGE_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_LOG(" sqlite3_finalize failed - %d", rc); + EM_DEBUG_EXCEPTION("sqlite3_finalize error [%d]", rc); error = EMAIL_ERROR_DB_FAILURE; } } - EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error); - _DISCONNECT_DB; - if (err_code != NULL) *err_code = error; EM_DEBUG_FUNC_END("ret [%d]", ret); @@ -10118,6 +10491,13 @@ INTERNAL_FUNC int emstorage_rename_mailbox(int input_mailbox_id, char *input_new EM_SAFE_FREE (replaced_alias); return error; } + + if (old_mailbox_data == NULL) { + EM_DEBUG_LOG("old_mailbox_data is NULL"); + error = EMAIL_ERROR_MAILBOX_NOT_FOUND; + goto FINISH_OFF; + } + account_id = old_mailbox_data->account_id; EMSTORAGE_START_WRITE_TRANSACTION(input_transaction, error); @@ -10173,7 +10553,6 @@ INTERNAL_FUNC int emstorage_rename_mailbox(int input_mailbox_id, char *input_new FINISH_OFF: EMSTORAGE_FINISH_WRITE_TRANSACTION(input_transaction, ret, error); - _DISCONNECT_DB; if (error == EMAIL_ERROR_NONE) { if (!emcore_notify_storage_event (NOTI_MAILBOX_RENAME, account_id, input_mailbox_id, input_new_mailbox_name, 0)) EM_DEBUG_EXCEPTION ("emcore_notify_storage_event Failed [ NOTI_MAILBOX_RENAME ] >>>> "); @@ -10192,7 +10571,7 @@ FINISH_OFF: if (hStmt != NULL) { rc = sqlite3_finalize(hStmt); if (rc != SQLITE_OK) { - EM_DEBUG_EXCEPTION(" sqlite3_finalize failed - %d", rc); + EM_DEBUG_EXCEPTION("sqlite3_finalize error [%d]", rc); error = EMAIL_ERROR_DB_FAILURE; } } @@ -10237,7 +10616,6 @@ INTERNAL_FUNC int emstorage_get_new_attachment_no(int *attachment_no, int *err_c ret = true; FINISH_OFF: - _DISCONNECT_DB; if (err_code != NULL) *err_code = error; @@ -10254,8 +10632,9 @@ INTERNAL_FUNC int emstorage_add_attachment(emstorage_attachment_tbl_t* attachmen char **result; int rc, ret = false; int error = EMAIL_ERROR_NONE; - DB_STMT hStmt = NULL; char sql_query_string[QUERY_SIZE] = {0, }; + + DB_STMT hStmt = NULL; sqlite3 *local_db_handle = emstorage_get_db_connection(); if (!attachment_tbl) { @@ -10284,6 +10663,7 @@ INTERNAL_FUNC int emstorage_add_attachment(emstorage_attachment_tbl_t* attachmen "( ?" /* attachment_id */ ", ?" /* attachment_name */ ", ?" /* attachment_path */ + ", ?" /* content_id */ ", ?" /* attachment_size */ ", ?" /* mail_id */ ", ?" /* account_id */ @@ -10307,6 +10687,7 @@ INTERNAL_FUNC int emstorage_add_attachment(emstorage_attachment_tbl_t* attachmen _bind_stmt_field_data_int (hStmt, ATTACHMENT_ID_IDX_IN_MAIL_ATTACHMENT_TBL, attachment_tbl->attachment_id); _bind_stmt_field_data_string(hStmt, ATTACHMENT_NAME_IDX_IN_MAIL_ATTACHMENT_TBL, (char*)attachment_tbl->attachment_name, 0, ATTACHMENT_NAME_LEN_IN_MAIL_ATTACHMENT_TBL); _bind_stmt_field_data_string(hStmt, ATTACHMENT_PATH_IDX_IN_MAIL_ATTACHMENT_TBL, (char*)attachment_tbl->attachment_path, 0, ATTACHMENT_PATH_LEN_IN_MAIL_ATTACHMENT_TBL); + _bind_stmt_field_data_string(hStmt, CONTENT_ID_IDX_IN_MAIL_ATTACHMENT_TBL, (char*)attachment_tbl->content_id, 0, CONTENT_ID_LEN_IN_MAIL_ATTACHMENT_TBL); _bind_stmt_field_data_int (hStmt, ATTACHMENT_SIZE_IDX_IN_MAIL_ATTACHMENT_TBL, attachment_tbl->attachment_size); _bind_stmt_field_data_int (hStmt, MAIL_ID_IDX_IN_MAIL_ATTACHMENT_TBL, attachment_tbl->mail_id); _bind_stmt_field_data_int (hStmt, ACCOUNT_ID_IDX_IN_MAIL_ATTACHMENT_TBL, attachment_tbl->account_id); @@ -10327,17 +10708,7 @@ INTERNAL_FUNC int emstorage_add_attachment(emstorage_attachment_tbl_t* attachmen ("sqlite3_step fail:%d", rc)); EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_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); - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc); - - EM_DEBUG_DB_EXEC((SQLITE_FULL == rc), {error = EMAIL_ERROR_MAIL_MEMORY_FULL;goto FINISH_OFF; }, - ("sqlite3_exec fail:%d", rc)); - EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_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 found..."); @@ -10349,11 +10720,11 @@ INTERNAL_FUNC int emstorage_add_attachment(emstorage_attachment_tbl_t* attachmen FINISH_OFF: EMSTORAGE_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); + EM_DEBUG_EXCEPTION("sqlite3_finalize error [%d]", rc); error = EMAIL_ERROR_DB_FAILURE; } } @@ -10376,7 +10747,7 @@ INTERNAL_FUNC int emstorage_update_attachment(emstorage_attachment_tbl_t* attach if (!attachment_tbl) { EM_DEBUG_EXCEPTION(" attachment_tbl[%p] ", attachment_tbl); - if (err_code) + if (err_code) *err_code = EMAIL_ERROR_INVALID_PARAM; return false; } @@ -10389,6 +10760,7 @@ INTERNAL_FUNC int emstorage_update_attachment(emstorage_attachment_tbl_t* attach "UPDATE mail_attachment_tbl SET " " attachment_name = ?" ", attachment_path = ?" + ", content_id = ?" ", attachment_size = ?" ", mail_id = ?" ", account_id = ?" @@ -10408,6 +10780,7 @@ INTERNAL_FUNC int emstorage_update_attachment(emstorage_attachment_tbl_t* attach _bind_stmt_field_data_string(hStmt, field_idx++ , (char*)attachment_tbl->attachment_name, 0, ATTACHMENT_NAME_LEN_IN_MAIL_ATTACHMENT_TBL); _bind_stmt_field_data_string(hStmt, field_idx++ , (char*)attachment_tbl->attachment_path, 0, ATTACHMENT_PATH_LEN_IN_MAIL_ATTACHMENT_TBL); + _bind_stmt_field_data_string(hStmt, field_idx++ , (char*)attachment_tbl->content_id, 0, CONTENT_ID_LEN_IN_MAIL_ATTACHMENT_TBL); _bind_stmt_field_data_int (hStmt, field_idx++ , attachment_tbl->attachment_size); _bind_stmt_field_data_int (hStmt, field_idx++ , attachment_tbl->mail_id); _bind_stmt_field_data_int (hStmt, field_idx++ , attachment_tbl->account_id); @@ -10425,17 +10798,7 @@ INTERNAL_FUNC int emstorage_update_attachment(emstorage_attachment_tbl_t* attach ("sqlite3_step fail:%d", rc)); EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_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); - - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc); - EM_DEBUG_DB_EXEC((SQLITE_FULL == rc), {error = EMAIL_ERROR_MAIL_MEMORY_FULL;goto FINISH_OFF; }, - ("sqlite3_exec fail:%d", rc)); - EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_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 found..."); @@ -10447,11 +10810,10 @@ INTERNAL_FUNC int emstorage_update_attachment(emstorage_attachment_tbl_t* attach FINISH_OFF: EMSTORAGE_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); + EM_DEBUG_EXCEPTION("sqlite3_finalize error [%d]", rc); error = EMAIL_ERROR_DB_FAILURE; } } @@ -10474,25 +10836,25 @@ INTERNAL_FUNC int emstorage_delete_attachment_on_db(int attachment_id, int trans return false; } - int rc, ret = false; + int ret = false; int error = EMAIL_ERROR_NONE; char sql_query_string[QUERY_SIZE] = {0, }; - sqlite3 *local_db_handle = emstorage_get_db_connection(); EMSTORAGE_START_WRITE_TRANSACTION(transaction, error); SNPRINTF(sql_query_string, sizeof(sql_query_string), "DELETE FROM mail_attachment_tbl WHERE attachment_id = %d", attachment_id); - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc); - EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, - ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); + if (error != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; + } ret = true; FINISH_OFF: EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error); - _DISCONNECT_DB; if (err_code) *err_code = error; @@ -10504,7 +10866,7 @@ FINISH_OFF: INTERNAL_FUNC int emstorage_delete_all_attachments_of_mail(int mail_id, int transaction, int *err_code) { EM_DEBUG_FUNC_BEGIN("mail_id[%d], transaction[%d], err_code[%p]", mail_id, transaction, err_code); - int rc, ret = false; + int ret = false; int error = EMAIL_ERROR_NONE; char sql_query_string[QUERY_SIZE] = {0, }; sqlite3 *local_db_handle = NULL; @@ -10521,16 +10883,16 @@ INTERNAL_FUNC int emstorage_delete_all_attachments_of_mail(int mail_id, int tran EMSTORAGE_START_WRITE_TRANSACTION(transaction, error); SNPRINTF(sql_query_string, sizeof(sql_query_string), "DELETE FROM mail_attachment_tbl WHERE mail_id = %d", mail_id); - - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc); - EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, - ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); + if (error != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; + } ret = true; FINISH_OFF: EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error); - _DISCONNECT_DB; if (err_code) *err_code = error; @@ -10544,10 +10906,9 @@ INTERNAL_FUNC int emstorage_delete_attachment_all_on_db(int account_id, char *ma EM_DEBUG_FUNC_BEGIN("account_id[%d], mailbox[%p], transaction[%d], err_code[%p]", account_id, mailbox, transaction, err_code); int error = EMAIL_ERROR_NONE; - int rc, ret = false; + int ret = false; char sql_query_string[QUERY_SIZE] = {0, }; char *replaced_mailbox = NULL; - sqlite3 *local_db_handle = emstorage_get_db_connection(); EMSTORAGE_START_WRITE_TRANSACTION(transaction, error); @@ -10567,15 +10928,17 @@ INTERNAL_FUNC int emstorage_delete_attachment_all_on_db(int account_id, char *ma SNPRINTF(sql_query_string + EM_SAFE_STRLEN(sql_query_string), sizeof(sql_query_string)-(EM_SAFE_STRLEN(sql_query_string)+1), " %s mailbox_name = '%s'", account_id != ALL_ACCOUNT ? "AND" : "WHERE", replaced_mailbox); EM_SAFE_FREE(replaced_mailbox); /*prevent 49434*/ } - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc); - EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, - ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + + error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); + if (error != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; + } ret = true; FINISH_OFF: EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error); - _DISCONNECT_DB; if (err_code != NULL) *err_code = error; @@ -10602,6 +10965,7 @@ INTERNAL_FUNC int emstorage_free_attachment(emstorage_attachment_tbl_t** attachm for (i = 0; i < count; i++) { EM_SAFE_FREE(p[i].attachment_name); EM_SAFE_FREE(p[i].attachment_path); + EM_SAFE_FREE(p[i].content_id); EM_SAFE_FREE(p[i].attachment_mime_type); #ifdef __ATTACHMENT_OPTI__ EM_SAFE_FREE(p[i].section); @@ -10625,6 +10989,8 @@ INTERNAL_FUNC int emstorage_begin_transaction(void *d1, void *d2, int *err_code) EM_PROFILE_BEGIN(emStorageBeginTransaction); int ret = true; + _timedlock_shm_mutex(&mapped_for_db_lock, 2); + sqlite3 *local_db_handle = emstorage_get_db_connection(); int rc; EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, "BEGIN immediate;", NULL, NULL, NULL), rc); @@ -10654,6 +11020,8 @@ INTERNAL_FUNC int emstorage_commit_transaction(void *d1, void *d2, int *err_code if (ret == false && err_code != NULL) *err_code = EMAIL_ERROR_DB_FAILURE; + _unlockshm_mutex(&mapped_for_db_lock); + EM_DEBUG_FUNC_END("ret [%d]", ret); return ret; } @@ -10672,6 +11040,8 @@ INTERNAL_FUNC int emstorage_rollback_transaction(void *d1, void *d2, int *err_co if (ret == false && err_code != NULL) *err_code = EMAIL_ERROR_DB_FAILURE; + _unlockshm_mutex(&mapped_for_db_lock); + EM_DEBUG_FUNC_END("ret [%d]", ret); return ret; } @@ -10723,13 +11093,11 @@ INTERNAL_FUNC int emstorage_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 ret = false; int error = EMAIL_ERROR_NONE; char sql_query_string[QUERY_SIZE] = {0, }; - const email_db_object_t* tables = _g_db_tables; const email_db_object_t* indexes = _g_db_indexes; - sqlite3 *local_db_handle = emstorage_get_db_connection(); EMSTORAGE_START_WRITE_TRANSACTION(transaction, error); @@ -10746,9 +11114,11 @@ INTERNAL_FUNC int emstorage_clear_mail_data(int transaction, int *err_code) while (indexes->object_name) { if (indexes->data_flag) { SNPRINTF(sql_query_string, sizeof(sql_query_string), "DROP index %s", indexes->object_name); - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc); - EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, - ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); + if (error != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; + } } indexes++; } @@ -10756,9 +11126,11 @@ INTERNAL_FUNC int emstorage_clear_mail_data(int transaction, int *err_code) while (tables->object_name) { if (tables->data_flag) { SNPRINTF(sql_query_string, sizeof(sql_query_string), "DROP table %s", tables->object_name); - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc); - EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, - ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); + if (error != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; + } } tables++; @@ -10767,7 +11139,6 @@ INTERNAL_FUNC int emstorage_clear_mail_data(int transaction, int *err_code) FINISH_OFF: EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error); - _DISCONNECT_DB; if (err_code != NULL) *err_code = error; @@ -10800,7 +11171,7 @@ INTERNAL_FUNC char *emstorage_make_directory_path_from_file_path(char *file_name return result; } -INTERNAL_FUNC int emstorage_get_save_name(int account_id, int mail_id, int atch_id, char *fname, char *name_buf, int *err_code) +INTERNAL_FUNC int emstorage_get_save_name(int account_id, int mail_id, int atch_id, char *fname, char *name_buf, int maxlen, int *err_code) { EM_DEBUG_FUNC_BEGIN_SEC("account_id[%d], mail_id[%d], atch_id[%d], fname[%s], name_buf[%p], err_code[%p]", account_id, mail_id, atch_id, fname, name_buf, err_code); EM_PROFILE_BEGIN(profile_emstorage_get_save_name); @@ -10834,7 +11205,7 @@ INTERNAL_FUNC int emstorage_get_save_name(int account_id, int mail_id, int atch_ } if (dir_name) { - sprintf(create_dir, "%s%s%s", name_buf, DIR_SEPERATOR, dir_name); + snprintf(create_dir, sizeof(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(dir_name); @@ -10842,7 +11213,46 @@ INTERNAL_FUNC int emstorage_get_save_name(int account_id, int mail_id, int atch_ if (fname) { EM_DEBUG_LOG_DEV(">>>>> fname [%s]", fname); - sprintf(name_buf+EM_SAFE_STRLEN(name_buf), "%s%s", DIR_SEPERATOR, fname); + if (EM_SAFE_STRLEN(fname) + EM_SAFE_STRLEN(name_buf) + EM_SAFE_STRLEN(DIR_SEPERATOR) > maxlen - 1) { + char *modified_name = NULL; + int remain_len = (maxlen - 1) - EM_SAFE_STRLEN(name_buf) - EM_SAFE_STRLEN(DIR_SEPERATOR); + + if (remain_len <= 0) { + error = EMAIL_ERROR_MAX_EXCEEDED; + goto FINISH_OFF; + } + + if (remain_len > MAX_FILENAME) { + remain_len = MAX_FILENAME; + } + + modified_name = em_shrink_filename(fname, remain_len); + + if (!modified_name) { + error = EMAIL_ERROR_MAX_EXCEEDED; + goto FINISH_OFF; + } + + sprintf(name_buf+EM_SAFE_STRLEN(name_buf), "%s%s", DIR_SEPERATOR, modified_name); + EM_DEBUG_LOG(">>>>> Modified fname [%s]", modified_name); + EM_SAFE_FREE(modified_name); + } else { + if (EM_SAFE_STRLEN(fname) > MAX_FILENAME - 1) { + char *modified_name = NULL; + + modified_name = em_shrink_filename(fname, MAX_FILENAME); + if (!modified_name) { + error = EMAIL_ERROR_MAX_EXCEEDED; + goto FINISH_OFF; + } + + sprintf(name_buf+EM_SAFE_STRLEN(name_buf), "%s%s", DIR_SEPERATOR, modified_name); + EM_DEBUG_LOG(">>>>> Modified fname [%s]", modified_name); + EM_SAFE_FREE(modified_name); + } else { + sprintf(name_buf+EM_SAFE_STRLEN(name_buf), "%s%s", DIR_SEPERATOR, fname); + } + } } EM_DEBUG_LOG_SEC(">>>>> name_buf [%s]", name_buf); @@ -10929,7 +11339,7 @@ INTERNAL_FUNC int emstorage_create_dir(int account_id, int mail_id, int atch_id, goto FINISH_OFF; } - SNPRINTF(buf+EM_SAFE_STRLEN(buf), sizeof(buf), "%s%d", DIR_SEPERATOR, mail_id); + SNPRINTF(buf+EM_SAFE_STRLEN(buf), sizeof(buf)-(EM_SAFE_STRLEN(buf)+1), "%s%d", DIR_SEPERATOR, mail_id); if (stat(buf, &sbuf) == 0) { if ((sbuf.st_mode & S_IFMT) != S_IFDIR) { @@ -11002,8 +11412,7 @@ INTERNAL_FUNC int emstorage_copy_file(char *src_file, char *dst_file, int sync_s int fp_src = 0; int fp_dst = 0; int nread = 0; - char *buf = NULL; - int buf_size = 0; + char buf[FILE_MAX_BUFFER_SIZE] = {0}; char errno_buf[ERRNO_BUF_SIZE] = {0}; if (!src_file || !dst_file) { @@ -11020,74 +11429,65 @@ INTERNAL_FUNC int emstorage_copy_file(char *src_file, char *dst_file, int sync_s 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 = EMAIL_ERROR_OUT_OF_MEMORY; - goto FINISH_OFF; - } - - if (buf) { - if ((fp_src = open(src_file, O_RDONLY))<0) { /*prevent 24474*/ - EM_DEBUG_EXCEPTION(">>>> Source Fail open %s Failed: %s", src_file, EM_STRERROR(errno_buf)); - error = EMAIL_ERROR_SYSTEM_FAILURE; - goto FINISH_OFF; - } - - if ((fp_dst = open(dst_file, O_CREAT | O_WRONLY | O_TRUNC, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH))<0) { /*prevent 24474*/ - EM_DEBUG_EXCEPTION(">>>> Destination Fail open %s: %s", dst_file, EM_STRERROR(errno_buf)); - error = EMAIL_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); - char *buf_ptr; - ssize_t byte_written = 0; - size_t remain_byte = nread; - buf_ptr = buf; - errno = 0; - - while(remain_byte > 0 && buf_ptr && errno == 0) { - byte_written = write(fp_dst, buf_ptr, remain_byte); - - if (byte_written < 0) { - /* interrupted by a signal */ - if (errno == EINTR) { - errno = 0; - continue; - } - - EM_DEBUG_EXCEPTION("fwrite failed: %s", EM_STRERROR(errno_buf)); - error = EMAIL_ERROR_UNKNOWN; - goto FINISH_OFF; - } - EM_DEBUG_LOG("NWRITTEN [%d]", byte_written); - remain_byte -= byte_written; - buf_ptr += byte_written; - } - } - } + error = em_open(src_file, O_RDONLY, 0, &fp_src); + if (error != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION(">>>> Source Fail em_open %s Failed: %d", src_file, error); + goto FINISH_OFF; + } + + error = em_open(dst_file, O_CREAT | O_WRONLY | O_TRUNC, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH, &fp_dst); /*prevent 24474*/ + if (error != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION(">>>> Destination Fail em_open %s: %d", dst_file, error); + goto FINISH_OFF; + } + + memset(buf, 0x00, FILE_MAX_BUFFER_SIZE); + + while ((nread = read(fp_src, buf, FILE_MAX_BUFFER_SIZE)) > 0) { + if (nread > 0 && nread <= FILE_MAX_BUFFER_SIZE) { + EM_DEBUG_LOG("Nread Value [%d]", nread); + char *buf_ptr; + ssize_t byte_written = 0; + size_t remain_byte = nread; + buf_ptr = buf; + errno = 0; + + while(remain_byte > 0 && buf_ptr && errno == 0) { + byte_written = write(fp_dst, buf_ptr, remain_byte); + + if (byte_written < 0) { + /* interrupted by a signal */ + if (errno == EINTR) { + errno = 0; + continue; + } + + EM_DEBUG_EXCEPTION("fwrite failed: %s", EM_STRERROR(errno_buf)); + error = EMAIL_ERROR_UNKNOWN; + goto FINISH_OFF; + } + EM_DEBUG_LOG("NWRITTEN [%d]", byte_written); + remain_byte -= byte_written; + buf_ptr += byte_written; + } + } + + memset(buf, 0x00, FILE_MAX_BUFFER_SIZE); } ret = true; FINISH_OFF: - if (fp_src>0) /*prevent 24474*/ - close(fp_src); + EM_SAFE_CLOSE (fp_src); - if (fp_dst>0) { /*prevent 24474*/ + if (fp_dst >=0) { /*prevent 24474*/ if (sync_status) { EM_DEBUG_LOG("Before fsync"); fsync(fp_dst); } - close(fp_dst); + close (fp_dst); } - EM_SAFE_FREE(buf); + if (nread < 0 || error == EMAIL_ERROR_UNKNOWN) remove(dst_file); @@ -11108,6 +11508,7 @@ INTERNAL_FUNC void emstorage_create_dir_if_delete() EM_DEBUG_FUNC_END(); } + static int _get_temp_file_name(char **filename, int *err_code) { EM_DEBUG_FUNC_BEGIN("filename[%p], err_code[%p]", filename, err_code); @@ -11168,7 +11569,6 @@ INTERNAL_FUNC int emstorage_add_content_type(char *file_path, char *char_set, in 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; @@ -11176,15 +11576,12 @@ INTERNAL_FUNC int emstorage_add_content_type(char *file_path, char *char_set, in if (stat(file_path, &st_buf) < 0) { EM_DEBUG_EXCEPTION_SEC(" stat(\"%s\") failed...", file_path); - - error = EMAIL_ERROR_SYSTEM_FAILURE; /* EMAIL_ERROR_INVALID_PATH; */ + error = EMAIL_ERROR_SYSTEM_FAILURE; 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) { @@ -11192,71 +11589,55 @@ INTERNAL_FUNC int emstorage_add_content_type(char *file_path, char *char_set, in goto FINISH_OFF; } - if (!(fp_src = fopen(file_path, "rb"))) { - EM_DEBUG_EXCEPTION_SEC(" file_path fopen failed - %s", file_path); - - error = EMAIL_ERROR_SYSTEM_FAILURE; - goto FINISH_OFF; - } - - 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, EM_SAFE_STRLEN(char_set) + strlen(" \" /></head>") +1); /*prevent 34359*/ - - strncat(low_char_set, char_set, EM_SAFE_STRLEN(char_set)); - - EM_DEBUG_LOG(">>>> CHAR SET [ %s ] ", low_char_set); + error = em_fopen(file_path, "rb", &fp_src); + if (error != EMAIL_ERROR_NONE || fp_src == NULL) { + EM_DEBUG_EXCEPTION_SEC(" file_path fopen failed - %s [%d]", file_path, error); + goto FINISH_OFF; + } - strncat(low_char_set, " \" /></head>", strlen(" \" /></head>")); /*prevent 34359*/ + if ((nread = fread(buf, 1, buf_size, fp_src)) > 0) { + if (nread > 0 && nread <= buf_size) { + EM_DEBUG_LOG(">>>> Nread Value [ %d ] ", nread); - EM_DEBUG_LOG(">>> CHARSET [ %s ] ", low_char_set); + /** + * 1.Add check for whether content type is there. + * 2. If not based on the character set, Append it in File + **/ - EM_DEBUG_LOG(">>>>emstorage_add_content_type 1 "); + low_char_set = calloc(1, EM_SAFE_STRLEN(char_set) + strlen(" \" /></head>") +1); /*prevent 34359*/ - match_str = strstr(buf, CONTENT_TYPE_DATA); - EM_DEBUG_LOG(">>>>emstorage_add_content_type 2 "); + strncat(low_char_set, char_set, EM_SAFE_STRLEN(char_set)); + EM_DEBUG_LOG(">>>> CHAR SET [ %s ] ", low_char_set); + strncat(low_char_set, " \" /></head>", strlen(" \" /></head>")); /*prevent 34359*/ + EM_DEBUG_LOG(">>> CHARSET [ %s ] ", low_char_set); + match_str = strstr(buf, CONTENT_TYPE_DATA); - if (match_str == NULL) { - EM_DEBUG_LOG(">>>>emstorage_add_content_type 3 "); - if (fp_src !=NULL) { - fclose(fp_src);fp_src = NULL; - } + if (match_str == NULL) { + EM_DEBUG_LOG(">>>>emstorage_add_content_type 3 "); + if (fp_src !=NULL) { + fclose(fp_src);fp_src = NULL; + } data_count_to_written = EM_SAFE_STRLEN(low_char_set)+strlen(CONTENT_DATA)+1; /*prevent 34359*/ - EM_DEBUG_LOG(">>>>emstorage_add_content_type 4 "); buf1 = (char *)calloc(1, data_count_to_written); - EM_DEBUG_LOG(">>>>emstorage_add_content_type 5 "); - - if (buf1) { - EM_DEBUG_LOG(">>>>emstorage_add_content_type 6 "); - strncat(buf1, CONTENT_DATA, strlen(CONTENT_DATA)); /*prevent 34359*/ - - EM_DEBUG_LOG(">>>>> BUF 1 [ %s ] ", buf1); - - strncat(buf1, low_char_set, EM_SAFE_STRLEN(low_char_set)); - - EM_DEBUG_LOG(">>>> HTML TAG DATA [ %s ] ", buf1); + if (buf1) { + strncat(buf1, CONTENT_DATA, strlen(CONTENT_DATA)); /*prevent 34359*/ + EM_DEBUG_LOG(">>>>> BUF 1 [ %s ] ", buf1); + strncat(buf1, low_char_set, EM_SAFE_STRLEN(low_char_set)); + EM_DEBUG_LOG(">>>> HTML TAG DATA [ %s ] ", buf1); /* 1. Create a temporary file name */ if (!_get_temp_file_name(&temp_file_name, &err)) { EM_DEBUG_EXCEPTION(" emcore_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_SEC(">>>>>>> 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_SEC(" fopen failed - %s", temp_file_name); - error = EMAIL_ERROR_SYSTEM_FAILURE; + error = em_fopen(temp_file_name, "ab", &fp_dest); + if (error != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION_SEC(" fopen failed - %s [%d]", temp_file_name, error); goto FINISH_OFF; } @@ -11289,15 +11670,10 @@ INTERNAL_FUNC int emstorage_add_content_type(char *file_path, char *char_set, in error = EMAIL_ERROR_SYSTEM_FAILURE; goto FINISH_OFF; } - - } - } - EM_DEBUG_LOG(">>>>emstorage_add_content_type 15 "); - - } } + } ret = true; FINISH_OFF: @@ -11305,6 +11681,7 @@ FINISH_OFF: EM_SAFE_FREE(buf); EM_SAFE_FREE(buf1); EM_SAFE_FREE(low_char_set); + EM_SAFE_FREE(temp_file_name); if (fp_src != NULL) { fclose(fp_src); @@ -11315,6 +11692,8 @@ FINISH_OFF: fclose(fp_dest); fp_dest = NULL; } + if (err_code) + *err_code = error; EM_DEBUG_FUNC_END("ret [%d]", ret); return ret; @@ -11334,7 +11713,7 @@ INTERNAL_FUNC int emstorage_move_file(char *src_file, char *dst_file, int sync_s goto FINISH_OFF; } - EM_DEBUG_LOG("src_file[%s], dst_file[%s]", src_file, dst_file); + EM_DEBUG_LOG_SEC("src_file[%s], dst_file[%s]", src_file, dst_file); if (strcmp(src_file, dst_file) != 0) { if (rename(src_file, dst_file) != 0) { @@ -11372,7 +11751,7 @@ INTERNAL_FUNC int emstorage_move_file(char *src_file, char *dst_file, int sync_s } } else { - EM_DEBUG_LOG("src[%s] = dst[%d]", src_file, dst_file); + EM_DEBUG_LOG("src[%s] = dst[%s]", src_file, dst_file); } ret = true; @@ -11514,36 +11893,35 @@ INTERNAL_FUNC int emstorage_delete_dir(char *src_dir, int *err_code) INTERNAL_FUNC int emstorage_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 ret = false; int error = EMAIL_ERROR_NONE; char sql_query_string[QUERY_SIZE] = {0, }; - int transaction = true; if (!old_server_uid || !new_server_uid) { EM_DEBUG_EXCEPTION("Invalid parameters"); - if (err_code) + if (err_code) *err_code = EMAIL_ERROR_INVALID_PARAM; return false; } + sqlite3 *local_db_handle = emstorage_get_db_connection(); EMSTORAGE_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); - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc); - EM_DEBUG_DB_EXEC((SQLITE_FULL == rc), {error = EMAIL_ERROR_MAIL_MEMORY_FULL;goto FINISH_OFF; }, - ("sqlite3_exec fail:%d", rc)); - EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, - ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); + if (error != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; + } ret = true; FINISH_OFF: EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error); - _DISCONNECT_DB; if (err_code != NULL) *err_code = error; @@ -11557,10 +11935,9 @@ INTERNAL_FUNC int emstorage_update_read_mail_uid(int mail_id, char *new_server_u { EM_DEBUG_FUNC_BEGIN_SEC("mail_id[%d], new_server_uid[%s], mbox_name[%s]", mail_id, new_server_uid, mbox_name); - int rc, ret = false; + int ret = false; int error = EMAIL_ERROR_NONE; char sql_query_string[QUERY_SIZE] = {0, }; - int transaction = true; if (!mail_id || !new_server_uid || !mbox_name) { @@ -11569,21 +11946,25 @@ INTERNAL_FUNC int emstorage_update_read_mail_uid(int mail_id, char *new_server_u *err_code = EMAIL_ERROR_INVALID_PARAM; return false; } + sqlite3 *local_db_handle = emstorage_get_db_connection(); EMSTORAGE_START_WRITE_TRANSACTION(transaction, error); SNPRINTF(sql_query_string, sizeof(sql_query_string), "UPDATE mail_read_mail_uid_tbl SET server_uid=\'%s\', mailbox_id=\'%s\', mailbox_name=\'%s\' WHERE local_uid=%d ", new_server_uid, mbox_name, mbox_name, mail_id); - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc); - EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, - ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + + error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); + if (error != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; + } + ret = true; FINISH_OFF: EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error); - _DISCONNECT_DB; if (err_code != NULL) *err_code = error; @@ -11593,13 +11974,50 @@ FINISH_OFF: } +INTERNAL_FUNC int emstorage_update_save_status(int account_id, int *err_code) +{ + EM_DEBUG_FUNC_BEGIN(); + + int ret = false; + int transaction = true; + int error = EMAIL_ERROR_NONE; + char sql_query_string[QUERY_SIZE] = {0,}; + + sqlite3 *local_db_handle = emstorage_get_db_connection(); + EMSTORAGE_START_WRITE_TRANSACTION(transaction, error); + + memset(sql_query_string, 0x00, sizeof(sql_query_string)); + + if (account_id <= ALL_ACCOUNT) + SNPRINTF(sql_query_string, sizeof(sql_query_string), "UPDATE mail_tbl SET save_status = %d WHERE (save_status = %d or save_status = %d)", EMAIL_MAIL_STATUS_NONE, EMAIL_MAIL_STATUS_NOTI_WAITED, EMAIL_MAIL_STATUS_RECEIVED); + else + SNPRINTF(sql_query_string, sizeof(sql_query_string), "UPDATE mail_tbl SET save_status = %d WHERE (save_status = %d or save_status = %d) and account_id = %d ", EMAIL_MAIL_STATUS_NONE, EMAIL_MAIL_STATUS_NOTI_WAITED, EMAIL_MAIL_STATUS_RECEIVED, account_id); + + error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); + if (error != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; + } + + ret = true; + +FINISH_OFF: + EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error); + + if (err_code != NULL) + *err_code = error; -int emstorage_get_latest_unread_mailid(int account_id, int *mail_id, int *err_code) + EM_DEBUG_FUNC_END("ret [%d]", ret); + return ret; + +} + +int emstorage_get_unread_mailid(int account_id, int vip_mode, int **mail_ids, int *mail_number, 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 ((!mail_ids) ||(account_id <= 0 && account_id != -1)) { + EM_DEBUG_EXCEPTION(" mail_id[%p], account_id[%d] ", mail_ids, account_id); if (err_code != NULL) *err_code = EMAIL_ERROR_INVALID_PARAM; return false; @@ -11608,11 +12026,15 @@ int emstorage_get_latest_unread_mailid(int account_id, int *mail_id, int *err_co int ret = false; int rc = -1; int error = EMAIL_ERROR_NONE; - DB_STMT hStmt = NULL; int count = 0; - int mailid = 0; + int i = 0; + int col_index = 0; + int *p_mail_ids = NULL; int transaction = false; + char **result = NULL; char sql_query_string[QUERY_SIZE] = {0, }; + char temp_query_string[QUERY_SIZE] = {0,}; + char sql_select_query_string[QUERY_SIZE] = {0, }; sqlite3 *local_db_handle = emstorage_get_db_connection(); EMSTORAGE_START_READ_TRANSACTION(transaction); @@ -11620,26 +12042,26 @@ int emstorage_get_latest_unread_mailid(int account_id, int *mail_id, int *err_co 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"); + SNPRINTF(sql_select_query_string, sizeof(sql_select_query_string), "SELECT mail_id FROM mail_tbl WHERE flags_seen_field = 0 AND (save_status = %d or save_status = %d)", EMAIL_MAIL_STATUS_NOTI_WAITED, EMAIL_MAIL_STATUS_RECEIVED); 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); + SNPRINTF(sql_select_query_string, sizeof(sql_select_query_string), "SELECT mail_id FROM mail_tbl WHERE account_id = %d AND flags_seen_field = 0 AND (save_status = %d or save_status = %d)", account_id, EMAIL_MAIL_STATUS_NOTI_WAITED, EMAIL_MAIL_STATUS_RECEIVED); - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); - EM_DEBUG_LOG(" sqlite3_prepare hStmt = %p", hStmt); - EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, - ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + if (vip_mode) { + SNPRINTF(temp_query_string, sizeof(temp_query_string), "%s AND tag_id < 0", sql_select_query_string); + } else { + SNPRINTF(temp_query_string, sizeof(temp_query_string), "%s", sql_select_query_string); + } - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc); - EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, - ("sqlite3_step fail:%d", rc)); + SNPRINTF(sql_query_string, sizeof(sql_query_string), "%s ORDER BY date_time ASC", temp_query_string); - char **result; + EM_DEBUG_LOG_SEC("query: [%s]", sql_query_string); EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, &count, NULL, NULL), rc); EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; }, ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); - sqlite3_free_table(result); + EM_DEBUG_LOG("Count : %d", count); + if (count == 0) { EM_DEBUG_EXCEPTION("no Mails found..."); ret = false; @@ -11647,27 +12069,40 @@ int emstorage_get_latest_unread_mailid(int account_id, int *mail_id, int *err_co goto FINISH_OFF; } - _get_stmt_field_data_int(hStmt, &mailid, 0); - EM_DEBUG_LOG("mailid [%d]", mailid); + p_mail_ids = em_malloc(count * sizeof(int)); + if (p_mail_ids == NULL) { + EM_DEBUG_EXCEPTION("em_malloc failed..."); + error = EMAIL_ERROR_OUT_OF_MEMORY; + goto FINISH_OFF; + } + + col_index = 1; + + for (i = 0; i < count; i++) { + _get_table_field_data_int(result, &(p_mail_ids[i]), col_index++); + } 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); + if (result) + sqlite3_free_table(result); - error = EMAIL_ERROR_DB_FAILURE; - } - } EMSTORAGE_FINISH_READ_TRANSACTION(transaction); - _DISCONNECT_DB; - if (mail_id != NULL) - *mail_id = mailid; + sqlite3_db_release_memory(local_db_handle); + + + if (ret == true) { + if (mail_ids != NULL) + *mail_ids = p_mail_ids; + + if (mail_number != NULL) + *mail_number = count; + } else { + EM_SAFE_FREE(p_mail_ids); + } if (err_code != NULL) *err_code = error; @@ -11752,11 +12187,9 @@ INTERNAL_FUNC int emstorage_mail_get_total_diskspace_usage(unsigned long *total_ goto FINISH_OFF; } - fp = fopen(SETTING_MEMORY_TEMP_FILE_PATH, "r"); - if (fp == NULL) { + error = em_fopen(SETTING_MEMORY_TEMP_FILE_PATH, "r", &fp); + if (error != EMAIL_ERROR_NONE) { perror(SETTING_MEMORY_TEMP_FILE_PATH); - - error = EMAIL_ERROR_SYSTEM_FAILURE; goto FINISH_OFF; } @@ -11857,6 +12290,7 @@ INTERNAL_FUNC int emstorage_test(int mail_id, int account_id, char *full_address ", ?" /* tag_id */ ", ?" /* replied_time */ ", ?" /* forwarded_time */ + ", ?" /* default_charset */ ", ?" /* eas_data_length */ ", ?" /* eas_data */ ")"); @@ -11922,6 +12356,7 @@ INTERNAL_FUNC int emstorage_test(int mail_id, int account_id, char *full_address _bind_stmt_field_data_int(hStmt, TAG_ID_IDX_IN_MAIL_TBL, 0); _bind_stmt_field_data_int(hStmt, REPLIED_TIME_IDX_IN_MAIL_TBL, 0); _bind_stmt_field_data_int(hStmt, FORWARDED_TIME_IDX_IN_MAIL_TBL, 0); + _bind_stmt_field_data_string(hStmt, DEFAULT_CHARSET_IDX_IN_MAIL_TBL, "UTF-8", 0, TEXT_2_LEN_IN_MAIL_TBL); _bind_stmt_field_data_int(hStmt, EAS_DATA_LENGTH_IDX_IN_MAIL_TBL, 0); _bind_stmt_field_data_blob(hStmt, EAS_DATA_IDX_IN_MAIL_TBL, NULL, 0); @@ -11934,11 +12369,10 @@ INTERNAL_FUNC int emstorage_test(int mail_id, int account_id, char *full_address FINISH_OFF: EMSTORAGE_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); + EM_DEBUG_EXCEPTION("sqlite3_finalize error [%d]", rc); error = EMAIL_ERROR_DB_FAILURE; } } @@ -11967,7 +12401,6 @@ INTERNAL_FUNC int emstorage_get_thread_id_of_thread_mails(emstorage_mail_tbl_t * int err_code = EMAIL_ERROR_NONE; int count = 0, result_thread_id = -1, latest_mail_id_in_thread = -1; time_t latest_date_time = 0; - time_t date_time = 0; char *subject = NULL; 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_id = %d"; @@ -11977,7 +12410,7 @@ INTERNAL_FUNC int emstorage_get_thread_id_of_thread_mails(emstorage_mail_tbl_t * char stripped_subject[STRIPPED_SUBJECT_BUFFER_SIZE]; sqlite3 *local_db_handle = emstorage_get_db_connection(); - EM_DEBUG_LOG("subject: [%p], mail_id: [%d]", subject, mail_tbl->mail_id); + EM_DEBUG_LOG_SEC("subject: [%p], mail_id: [%d]", subject, mail_tbl->mail_id); EM_IF_NULL_RETURN_VALUE(mail_tbl, EMAIL_ERROR_INVALID_PARAM); EM_IF_NULL_RETURN_VALUE(thread_id, EMAIL_ERROR_INVALID_PARAM); @@ -11986,23 +12419,30 @@ INTERNAL_FUNC int emstorage_get_thread_id_of_thread_mails(emstorage_mail_tbl_t * account_id = mail_tbl->account_id; subject = mail_tbl->subject; - date_time = mail_tbl->date_time; - EM_DEBUG_LOG("subject: [%s]", subject); + EM_DEBUG_LOG_SEC("subject: [%s]", subject); + + if (EM_SAFE_STRLEN(subject) == 0 && mail_tbl->mail_id != 0) { + result_thread_id = mail_tbl->mail_id; + count = 1; + goto FINISH_OFF; + } if (em_find_pos_stripped_subject_for_thread_view(subject, stripped_subject, STRIPPED_SUBJECT_BUFFER_SIZE) != EMAIL_ERROR_NONE) { - EM_DEBUG_EXCEPTION("em_find_pos_stripped_subject_for_thread_view is failed"); + EM_DEBUG_EXCEPTION("em_find_pos_stripped_subject_for_thread_view is failed"); err_code = EMAIL_ERROR_UNKNOWN; result_thread_id = -1; goto FINISH_OFF; } + EM_DEBUG_LOG_SEC("stripped_subject: [%s]", stripped_subject); + if (EM_SAFE_STRLEN(stripped_subject) < 2) { result_thread_id = -1; goto FINISH_OFF; } - EM_DEBUG_LOG("em_find_pos_stripped_subject_for_thread_view returns[len = %d] = %s", EM_SAFE_STRLEN(stripped_subject), stripped_subject); + EM_DEBUG_LOG_SEC("em_find_pos_stripped_subject_for_thread_view returns[len = %d] = %s", EM_SAFE_STRLEN(stripped_subject), stripped_subject); if (account_id > 0) { query_size_account = 3 + EM_SAFE_STRLEN(sql_format_account); @@ -12033,7 +12473,7 @@ INTERNAL_FUNC int emstorage_get_thread_id_of_thread_mails(emstorage_mail_tbl_t * strcat(sql_query_string, sql_format_order_by); strcat(sql_query_string, ";"); - EM_DEBUG_LOG("Query : %s", sql_query_string); + EM_DEBUG_LOG_SEC("Query : %s", sql_query_string); EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, &count, NULL, NULL), rc); @@ -12074,6 +12514,107 @@ FINISH_OFF: return err_code; } +INTERNAL_FUNC int emstorage_get_thread_id_from_mailbox(int account_id, int mailbox_id, char *mail_subject, int *thread_id, int *thread_item_count) +{ + EM_DEBUG_FUNC_BEGIN("mailbox_id [%d], subject [%p], thread_id [%p], thread_item_count [%p]", mailbox_id, mail_subject, thread_id, thread_item_count); + EM_PROFILE_BEGIN(profile_emstorage_get_thread_id_of_thread_mails); + + int rc = 0; + int query_size = 0; + int query_size_account = 0; + int err_code = EMAIL_ERROR_NONE; + int count = 0; + int result_thread_id = -1; + char *sql_query_string = NULL; + char *sql_account = NULL; + char *sql_format = "SELECT thread_id FROM mail_tbl WHERE subject like \'%%%q\' AND mailbox_id = %d"; + char *sql_format_account = " AND account_id = %d "; + char *sql_format_order_by = " ORDER BY date_time DESC "; + char **result = NULL; + char stripped_subject[STRIPPED_SUBJECT_BUFFER_SIZE]; + sqlite3 *local_db_handle = emstorage_get_db_connection(); + + EM_IF_NULL_RETURN_VALUE(mail_subject, EMAIL_ERROR_INVALID_PARAM); + EM_IF_NULL_RETURN_VALUE(thread_id, EMAIL_ERROR_INVALID_PARAM); + EM_IF_NULL_RETURN_VALUE(thread_item_count, EMAIL_ERROR_INVALID_PARAM); + + EM_DEBUG_LOG_SEC("subject: [%s]", mail_subject); + + if (em_find_pos_stripped_subject_for_thread_view(mail_subject, stripped_subject, STRIPPED_SUBJECT_BUFFER_SIZE) != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("em_find_pos_stripped_subject_for_thread_view is failed"); + err_code = EMAIL_ERROR_UNKNOWN; + result_thread_id = -1; + goto FINISH_OFF; + } + + if (EM_SAFE_STRLEN(stripped_subject) < 2) { + result_thread_id = -1; + goto FINISH_OFF; + } + + EM_DEBUG_LOG("em_find_pos_stripped_subject_for_thread_view returns[len = %d] = %s", EM_SAFE_STRLEN(stripped_subject), stripped_subject); + + if (account_id > 0) { + query_size_account = 3 + EM_SAFE_STRLEN(sql_format_account); + 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 = EMAIL_ERROR_OUT_OF_MEMORY; + goto FINISH_OFF; + } + snprintf(sql_account, query_size_account, sql_format_account, account_id); + } + + query_size = EM_SAFE_STRLEN(sql_format) + EM_SAFE_STRLEN(stripped_subject)*2 + 50 + query_size_account + EM_SAFE_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 = EMAIL_ERROR_OUT_OF_MEMORY; + goto FINISH_OFF; + } + + sqlite3_snprintf(query_size, sql_query_string, sql_format, stripped_subject, mailbox_id); + + 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_SEC("Query : %s", sql_query_string); + + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, &count, NULL, NULL), rc); + + EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {err_code = EMAIL_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 { + _get_table_field_data_int (result, &result_thread_id, 1); + } + +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_emstorage_get_thread_id_of_thread_mails); + + return err_code; +} + INTERNAL_FUNC int emstorage_get_thread_information(int thread_id, emstorage_mail_tbl_t** mail_tbl, int transaction, int *err_code) { @@ -12188,7 +12729,7 @@ INTERNAL_FUNC int emstorage_get_sender_list(int account_id, int mailbox_id, int "GROUP BY email_address_sender " "ORDER BY UPPER(alias_sender) "); - EM_DEBUG_LOG("query[%s]", sql_query_string); + EM_DEBUG_LOG_SEC("query[%s]", sql_query_string); EMSTORAGE_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 = EMAIL_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; }, @@ -12226,7 +12767,6 @@ FINISH_OFF: EM_DEBUG_LOG(">>>> COUNT : %d >>", count); } - _DISCONNECT_DB; if (err_code != NULL) *err_code = error; @@ -12378,7 +12918,7 @@ INTERNAL_FUNC int emstorage_add_pbd_activity(email_event_partial_body_thd* local EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); - EM_DEBUG_LOG(">>>> SQL STMT [ %s ]", sql_query_string); + _bind_stmt_field_data_int(hStmt, i++, local_activity->account_id); _bind_stmt_field_data_int(hStmt, i++, local_activity->mail_id); @@ -12400,14 +12940,11 @@ INTERNAL_FUNC int emstorage_add_pbd_activity(email_event_partial_body_thd* local FINISH_OFF: EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error); - _DISCONNECT_DB; 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); + EM_DEBUG_EXCEPTION("sqlite3_finalize error [%d]", rc); error = EMAIL_ERROR_DB_FAILURE; } } @@ -12424,7 +12961,7 @@ INTERNAL_FUNC int emstorage_get_pbd_mailbox_list(int account_id, int **mailbox_l { 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) { + if (account_id < FIRST_ACCOUNT_ID || NULL == mailbox_list || *mailbox_list == NULL|| 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 = EMAIL_ERROR_INVALID_PARAM; @@ -12467,12 +13004,12 @@ INTERNAL_FUNC int emstorage_get_pbd_mailbox_list(int account_id, int **mailbox_l /* 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_id FROM mail_partial_body_activity_tbl WHERE account_id = %d order by mailbox_id", account_id); - EM_DEBUG_LOG(" Query [%s]", sql_query_string); + EM_DEBUG_LOG_SEC(" Query [%s]", sql_query_string); EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); - EM_DEBUG_LOG(" Bbefore sqlite3_prepare hStmt = %p", hStmt); + EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); @@ -12481,7 +13018,8 @@ INTERNAL_FUNC int emstorage_get_pbd_mailbox_list(int account_id, int **mailbox_l EM_DEBUG_DB_EXEC((rc != SQLITE_ROW), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, ("sqlite3_step fail:%d", rc)); - if (NULL == (mbox_list = (int *)em_malloc(sizeof(int *) * (*count)))) { + mbox_list = (int *)em_malloc(sizeof(int) * (*count)); + if (NULL == mbox_list) { EM_DEBUG_EXCEPTION(" em_malloc failed..."); error = EMAIL_ERROR_OUT_OF_MEMORY; goto FINISH_OFF; @@ -12495,7 +13033,7 @@ INTERNAL_FUNC int emstorage_get_pbd_mailbox_list(int account_id, int **mailbox_l /* EM_DEBUG_LOG("In emstorage_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 = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, ("sqlite3_step fail:%d", rc)); - EM_DEBUG_LOG("mbox_list %d", mbox_list + i); + EM_DEBUG_LOG("mbox_list %d", mbox_list[i]); } ret = true; @@ -12507,18 +13045,15 @@ FINISH_OFF: EM_SAFE_FREE(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); + EM_DEBUG_EXCEPTION("sqlite3_finalize error [%d]", rc); error = EMAIL_ERROR_DB_FAILURE; } } EMSTORAGE_FINISH_READ_TRANSACTION(transaction); - _DISCONNECT_DB; if (err_code != NULL) *err_code = error; EM_DEBUG_FUNC_END("ret [%d]", ret); @@ -12528,10 +13063,10 @@ FINISH_OFF: INTERNAL_FUNC int emstorage_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); + EM_DEBUG_FUNC_BEGIN("account_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 (NULL == account_list || NULL == count) { + EM_DEBUG_EXCEPTION("account_list[%p], count[%p] err_code[%p]", account_list, count, err_code); if (err_code != NULL) *err_code = EMAIL_ERROR_INVALID_PARAM; return false; @@ -12539,21 +13074,16 @@ INTERNAL_FUNC int emstorage_get_pbd_account_list(int **account_list, int *count, int ret = false; int error = EMAIL_ERROR_NONE; - char *sql; + char *sql = "SELECT count(distinct account_id) FROM mail_partial_body_activity_tbl"; 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 = emstorage_get_db_connection(); EMSTORAGE_START_READ_TRANSACTION(transaction); - - sql = "SELECT count(distinct account_id) FROM mail_partial_body_activity_tbl"; - - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql, &result, NULL, NULL, NULL), rc); EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; }, ("SQL(%s) sqlite3_get_table fail:%d -%s", sql, rc, sqlite3_errmsg(local_db_handle))); @@ -12574,7 +13104,7 @@ INTERNAL_FUNC int emstorage_get_pbd_account_list(int **account_list, int *count, 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_DEBUG_LOG_SEC("Query [%s]", sql_query_string); EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); @@ -12614,18 +13144,15 @@ FINISH_OFF: EM_SAFE_FREE(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); + EM_DEBUG_EXCEPTION("sqlite3_finalize error [%d]", rc); error = EMAIL_ERROR_DB_FAILURE; } } EMSTORAGE_FINISH_READ_TRANSACTION(transaction); - _DISCONNECT_DB; if (err_code != NULL) *err_code = error; EM_DEBUG_FUNC_END("ret [%d]", ret); @@ -12670,7 +13197,7 @@ INTERNAL_FUNC int emstorage_get_pbd_activity_data(int account_id, int input_mail *count = atoi(result[1]); sqlite3_free_table(result); - EM_DEBUG_LOG("Query = [%s]", sql_query_string); + EM_DEBUG_LOG_SEC("Query = [%s]", sql_query_string); if (!*count) { EM_DEBUG_LOG("No matched activity found in mail_partial_body_activity_tbl"); @@ -12683,7 +13210,7 @@ INTERNAL_FUNC int emstorage_get_pbd_activity_data(int account_id, int input_mail 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_id = '%d' order by activity_id", account_id, input_mailbox_id); - EM_DEBUG_LOG("Query [%s]", sql_query_string); + EM_DEBUG_LOG_SEC("Query [%s]", sql_query_string); EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); @@ -12736,18 +13263,15 @@ 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_LOG("sqlite3_finalize failed - %d", rc); + EM_DEBUG_EXCEPTION("sqlite3_finalize error [%d]", rc); error = EMAIL_ERROR_DB_FAILURE; } } EMSTORAGE_FINISH_READ_TRANSACTION(transaction); - _DISCONNECT_DB; if (err_code != NULL) *err_code = error; @@ -12774,7 +13298,6 @@ INTERNAL_FUNC int emstorage_delete_pbd_activity(int account_id, int mail_id, int int ret = false; int error = EMAIL_ERROR_NONE; char sql_query_string[QUERY_SIZE] = {0, }; - sqlite3 *local_db_handle = emstorage_get_db_connection(); EMSTORAGE_START_WRITE_TRANSACTION(transaction, error); @@ -12785,13 +13308,12 @@ INTERNAL_FUNC int emstorage_delete_pbd_activity(int account_id, int mail_id, int 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); - - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc); - EM_DEBUG_DB_EXEC((rc == SQLITE_FULL), {error = EMAIL_ERROR_MAIL_MEMORY_FULL;goto FINISH_OFF; }, - ("sqlite3_exec fail:%d", rc)); - EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, - ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + EM_DEBUG_LOG_SEC("Query [%s]", sql_query_string); + error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); + if (error != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; + } /* validate activity existence */ rc = sqlite3_changes(local_db_handle); @@ -12806,7 +13328,7 @@ INTERNAL_FUNC int emstorage_delete_pbd_activity(int account_id, int mail_id, int FINISH_OFF: EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error); - _DISCONNECT_DB; + if (err_code != NULL) *err_code = error; @@ -12838,7 +13360,7 @@ INTERNAL_FUNC int emstorage_get_mailbox_pbd_activity_count(int account_id, int i SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT count(*) FROM mail_partial_body_activity_tbl WHERE account_id = %d and mailbox_id = '%d'", account_id, input_mailbox_id); - EM_DEBUG_LOG(" Query [%s]", sql_query_string); + EM_DEBUG_LOG_SEC(" Query [%s]", sql_query_string); EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); @@ -12860,18 +13382,15 @@ INTERNAL_FUNC int emstorage_get_mailbox_pbd_activity_count(int account_id, int i 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); + EM_DEBUG_EXCEPTION("sqlite3_finalize error [%d]", rc); error = EMAIL_ERROR_DB_FAILURE; } - EM_DEBUG_LOG("sqlite3_finalize- %d", rc); } EMSTORAGE_FINISH_READ_TRANSACTION(transaction); - _DISCONNECT_DB; if (err_code != NULL) *err_code = error; @@ -12927,19 +13446,15 @@ 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); + EM_DEBUG_EXCEPTION("sqlite3_finalize error [%d]", rc); error = EMAIL_ERROR_DB_FAILURE; } -/* EM_DEBUG_LOG("sqlite3_finalize- %d", rc); */ } EMSTORAGE_FINISH_READ_TRANSACTION(transaction); - _DISCONNECT_DB; if (err_code != NULL) *err_code = error; @@ -12961,20 +13476,17 @@ INTERNAL_FUNC int emstorage_delete_full_pbd_activity_data(int account_id, int tr int ret = false; int error = EMAIL_ERROR_NONE; char sql_query_string[QUERY_SIZE] = {0, }; - sqlite3 *local_db_handle = emstorage_get_db_connection(); EMSTORAGE_START_WRITE_TRANSACTION(transaction, error); 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); - - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc); - EM_DEBUG_DB_EXEC((rc == SQLITE_FULL), {error = EMAIL_ERROR_MAIL_MEMORY_FULL;goto FINISH_OFF; }, - ("sqlite3_exec fail:%d", rc)); - EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, - ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); - + EM_DEBUG_LOG_SEC("Query [%s]", sql_query_string); + error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); + if (error != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; + } rc = sqlite3_changes(local_db_handle); if (rc == 0) { @@ -12988,7 +13500,7 @@ INTERNAL_FUNC int emstorage_delete_full_pbd_activity_data(int account_id, int tr FINISH_OFF: EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error); - _DISCONNECT_DB; + if (err_code != NULL) *err_code = error; @@ -13016,31 +13528,29 @@ INTERNAL_FUNC int emstorage_update_pbd_activity(char *old_server_uid, char *new_ } sqlite3 *local_db_handle = emstorage_get_db_connection(); + EMSTORAGE_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); - - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc); - EM_DEBUG_DB_EXEC((rc == SQLITE_FULL), {error = EMAIL_ERROR_MAIL_MEMORY_FULL;goto FINISH_OFF; }, - ("sqlite3_exec fail:%d", rc)); - EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, - ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + EM_DEBUG_LOG_SEC("Query [%s]", sql_query_string); + error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); + if (error != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; + } rc = sqlite3_changes(local_db_handle); if (rc == 0) { - EM_DEBUG_EXCEPTION("No matching found in mail_partial_body_activity_tbl"); - error = EMAIL_ERROR_DATA_NOT_FOUND; - goto FINISH_OFF; + EM_DEBUG_LOG("No matching found in mail_partial_body_activity_tbl"); } ret = true; FINISH_OFF: EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error); - _DISCONNECT_DB; + if (err_code != NULL) *err_code = error; @@ -13064,14 +13574,9 @@ INTERNAL_FUNC int emstorage_create_file(char *data_string, size_t file_size, cha goto FINISH_OFF; } - fp_dst = fopen(dst_file_name, "w"); - - if (!fp_dst) { - EM_DEBUG_EXCEPTION_SEC("fopen failed - %s: %s", dst_file_name, EM_STRERROR(errno_buf)); - if (errno == 28) - error = EMAIL_ERROR_MAIL_MEMORY_FULL; - else - error = EMAIL_ERROR_SYSTEM_FAILURE; + error = em_fopen(dst_file_name, "w", &fp_dst); + if (error != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION_SEC("em_fopen failed - %s: %d", dst_file_name, error); goto FINISH_OFF; } @@ -13127,30 +13632,27 @@ INTERNAL_FUNC int emstorage_update_read_mail_uid_by_server_uid(char *old_server_ SNPRINTF(sql_query_string, sizeof(sql_query_string), "UPDATE mail_read_mail_uid_tbl SET server_uid=\'%s\' , mailbox_name=\'%s\' WHERE server_uid=%s ", new_server_uid, mbox_name, old_server_uid); - EM_DEBUG_LOG(" Query [%s]", sql_query_string); - - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc); - EM_DEBUG_DB_EXEC((rc == SQLITE_FULL), {error = EMAIL_ERROR_MAIL_MEMORY_FULL;goto FINISH_OFF; }, - ("sqlite3_exec fail:%d", rc)); - EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, - ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); - + EM_DEBUG_LOG_SEC(" Query [%s]", sql_query_string); + error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); + if (error != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; + } - rc = sqlite3_changes(local_db_handle); - if (rc == 0) - { - EM_DEBUG_EXCEPTION("No matching found in mail_partial_body_activity_tbl"); - error = EMAIL_ERROR_DATA_NOT_FOUND; - goto FINISH_OFF; - } + rc = sqlite3_changes(local_db_handle); + if (rc == 0) + { + EM_DEBUG_EXCEPTION("No matching found in mail_partial_body_activity_tbl"); + error = EMAIL_ERROR_DATA_NOT_FOUND; + goto FINISH_OFF; + } - ret = true; + ret = true; FINISH_OFF: EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error); - _DISCONNECT_DB; - if (err_code != NULL) + if (err_code != NULL) *err_code = error; EM_DEBUG_FUNC_END("ret [%d]", ret); @@ -13204,7 +13706,7 @@ INTERNAL_FUNC int emstorage_get_id_set_from_mail_ids(char *mail_ids, email_id_se SNPRINTF(sql_query_string, space_left_in_query_buffer, "SELECT local_uid, server_uid FROM mail_read_mail_uid_tbl WHERE local_uid in (%s) ORDER BY server_uid", mail_ids); - EM_DEBUG_LOG("SQL Query formed [%s] ", sql_query_string); + EM_DEBUG_LOG_SEC("SQL Query formed [%s] ", sql_query_string); /* rc = sqlite3_get_table(local_db_handle, sql_query_string, &result, &count, 0, NULL); */ EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, &count, 0, NULL), rc); @@ -13246,7 +13748,7 @@ INTERNAL_FUNC int emstorage_get_id_set_from_mail_ids(char *mail_ids, email_id_se ret = true; - FINISH_OFF: +FINISH_OFF: if (ret == true) { *idset = p_id_set; @@ -13256,7 +13758,6 @@ INTERNAL_FUNC int emstorage_get_id_set_from_mail_ids(char *mail_ids, email_id_se else EM_SAFE_FREE(p_id_set); - _DISCONNECT_DB; if (err_code != NULL) *err_code = error; @@ -13274,37 +13775,37 @@ INTERNAL_FUNC int emstorage_get_id_set_from_mail_ids(char *mail_ids, email_id_se INTERNAL_FUNC int emstorage_delete_triggers_from_lucene() { EM_DEBUG_FUNC_BEGIN(); - int rc, ret = true, transaction = true; + int ret = true, transaction = true; int error = EMAIL_ERROR_NONE; char sql_query_string[QUERY_SIZE] = {0, }; - sqlite3 *local_db_handle = emstorage_get_db_connection(); EMSTORAGE_START_WRITE_TRANSACTION(transaction, error); SNPRINTF(sql_query_string, sizeof(sql_query_string), "DROP TRIGGER triggerDelete;"); - - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc); - EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, - ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); + if (error != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; + } SNPRINTF(sql_query_string, sizeof(sql_query_string), "DROP TRIGGER triggerInsert;"); - - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc); - EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, - ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); - + error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); + if (error != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; + } SNPRINTF(sql_query_string, sizeof(sql_query_string), "DROP TRIGGER triggerUpdate;"); - - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc); - EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, - ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); + if (error != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; + } ret = true; FINISH_OFF: EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error); - _DISCONNECT_DB; EM_DEBUG_FUNC_END("ret [%d]", ret); return ret; @@ -13313,10 +13814,9 @@ FINISH_OFF: INTERNAL_FUNC int emstorage_update_tag_id(int old_filter_id, int new_filter_id, int *err_code) { EM_DEBUG_FUNC_BEGIN("new_filter_id[%d], old_filter_id[%d]", new_filter_id, old_filter_id); - int rc, ret = false; + int ret = false; int error = EMAIL_ERROR_NONE; char sql_query_string[QUERY_SIZE] = {0, }; - int transaction = true; if (old_filter_id < 0 || new_filter_id < 0) { @@ -13325,24 +13825,24 @@ INTERNAL_FUNC int emstorage_update_tag_id(int old_filter_id, int new_filter_id, *err_code = EMAIL_ERROR_INVALID_PARAM; return false; } + sqlite3 *local_db_handle = emstorage_get_db_connection(); EMSTORAGE_START_WRITE_TRANSACTION(transaction, error); SNPRINTF(sql_query_string, sizeof(sql_query_string), "UPDATE mail_tbl SET tag_id=%d WHERE tag_id=%d ", new_filter_id, old_filter_id); - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc); - EM_DEBUG_DB_EXEC((SQLITE_FULL == rc), {error = EMAIL_ERROR_MAIL_MEMORY_FULL;goto FINISH_OFF; }, - ("sqlite3_exec fail:%d", rc)); - EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, - ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); + if (error != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; + } ret = true; FINISH_OFF: EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error); - _DISCONNECT_DB; if (err_code != NULL) *err_code = error; @@ -13368,12 +13868,11 @@ INTERNAL_FUNC int emstorage_filter_mails_by_rule(int account_id, int dest_mailbo int tag_id = rule->rule_id; char **result = NULL, *where_pararaph = NULL; char sql_query_string[QUERY_SIZE] = {0, }; - sqlite3 *local_db_handle = emstorage_get_db_connection(); SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT mail_id FROM mail_tbl "); - where_pararaph_length = EM_SAFE_STRLEN(rule->value) + EM_SAFE_STRLEN(rule->value2) + 100; + where_pararaph_length = EM_SAFE_STRLEN(rule->value) + 2 * (EM_SAFE_STRLEN(rule->value2)) + 100; where_pararaph = em_malloc(sizeof(char) * where_pararaph_length); if (where_pararaph == NULL) { EM_DEBUG_EXCEPTION("malloc failed for where_pararaph."); @@ -13381,10 +13880,10 @@ INTERNAL_FUNC int emstorage_filter_mails_by_rule(int account_id, int dest_mailbo goto FINISH_OFF; } - if (account_id != ALL_ACCOUNT) - SNPRINTF(where_pararaph, where_pararaph_length, "WHERE account_id = %d AND mailbox_type NOT in (3,5)", account_id); + if (account_id != ALL_ACCOUNT) + SNPRINTF(where_pararaph, where_pararaph_length, "WHERE account_id = %d AND mailbox_type NOT in (0)", account_id); else - SNPRINTF(where_pararaph, where_pararaph_length, "WHERE mailbox_type NOT in (3,5)"); + SNPRINTF(where_pararaph, where_pararaph_length, "WHERE mailbox_type NOT in (0)"); if (rule->type & EMAIL_FILTER_SUBJECT) { if (rule->flag2 == RULE_TYPE_INCLUDES) @@ -13396,6 +13895,10 @@ INTERNAL_FUNC int emstorage_filter_mails_by_rule(int account_id, int dest_mailbo if (rule->type & EMAIL_FILTER_FROM) { if (rule->flag2 == RULE_TYPE_INCLUDES) sqlite3_snprintf(where_pararaph_length - (EM_SAFE_STRLEN(where_pararaph) + 1), where_pararaph + EM_SAFE_STRLEN(where_pararaph), " AND full_address_from like \'%%%q%%\'", rule->value2); +#ifdef __FEATURE_COMPARE_DOMAIN__ + else if (rule->flag2 == RULE_TYPE_COMPARE_DOMAIN) + sqlite3_snprintf(where_pararaph_length - (EM_SAFE_STRLEN(where_pararaph) + 1), where_pararaph + EM_SAFE_STRLEN(where_pararaph), " AND (full_address_from like \'@%%%q\' OR full_address_from like \'@%%%q>%%\')", rule->value2, rule->value2); +#endif /*__FEATURE_COMPARE_DOMAIN__ */ else /* RULE_TYPE_EXACTLY */ sqlite3_snprintf(where_pararaph_length - (EM_SAFE_STRLEN(where_pararaph) + 1), where_pararaph + EM_SAFE_STRLEN(where_pararaph), " AND full_address_from = \'%q\'", rule->value2); } @@ -13404,7 +13907,7 @@ INTERNAL_FUNC int emstorage_filter_mails_by_rule(int account_id, int dest_mailbo if (rule->flag2 == RULE_TYPE_INCLUDES) sqlite3_snprintf(where_pararaph_length - (EM_SAFE_STRLEN(where_pararaph) + 1), where_pararaph + EM_SAFE_STRLEN(where_pararaph), " AND full_address_from like \'%%%q%%\'", rule->value2); else /* RULE_TYPE_EXACTLY */ - sqlite3_snprintf(where_pararaph_length - (EM_SAFE_STRLEN(where_pararaph) + 1), where_pararaph + EM_SAFE_STRLEN(where_pararaph), " AND full_address_from = \'%q\'", rule->value2); + sqlite3_snprintf(where_pararaph_length - (EM_SAFE_STRLEN(where_pararaph) + 1), where_pararaph + EM_SAFE_STRLEN(where_pararaph), " AND full_address_from = \'%q\' OR email_address_sender = \'%q\'", rule->value2, rule->value2); tag_id = PRIORITY_SENDER_TAG_ID; } @@ -13413,7 +13916,7 @@ INTERNAL_FUNC int emstorage_filter_mails_by_rule(int account_id, int dest_mailbo if (strlen(sql_query_string) + strlen(where_pararaph) < QUERY_SIZE) strcat(sql_query_string, where_pararaph); - EM_DEBUG_LOG("query[%s]", sql_query_string); + EM_DEBUG_LOG_SEC("query[%s]", sql_query_string); /* rc = sqlite3_get_table(local_db_handle, sql_query_string, &result, &count, 0, NULL); */ EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, &count, 0, NULL), rc); @@ -13465,9 +13968,11 @@ INTERNAL_FUNC int emstorage_filter_mails_by_rule(int account_id, int dest_mailbo if(strlen(sql_query_string) + strlen(where_pararaph) < QUERY_SIZE) strcat(sql_query_string, where_pararaph); - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc); - EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, - ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); + if (error != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; + } #ifdef __FEATURE_BODY_SEARCH__ /* Updating mail_text_tbl */ @@ -13476,11 +13981,13 @@ INTERNAL_FUNC int emstorage_filter_mails_by_rule(int account_id, int dest_mailbo SNPRINTF(sql_query_string, QUERY_SIZE, "UPDATE mail_text_tbl SET mailbox_id = %d ", dest_mailbox_id); if(strlen(sql_query_string) + strlen(where_pararaph) < QUERY_SIZE) strcat(sql_query_string, where_pararaph); - EM_DEBUG_LOG("Query [%s]", sql_query_string); - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc); - EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, - ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + EM_DEBUG_LOG_SEC("Query [%s]", sql_query_string); + error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); + if (error != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; + } } #endif } @@ -13495,13 +14002,12 @@ FINISH_OFF: if (count_of_mails) *count_of_mails = count; - } else + } else EM_SAFE_FREE(mail_list); sqlite3_free_table(result); result = NULL; - _DISCONNECT_DB; EM_SAFE_FREE(where_pararaph); @@ -13517,7 +14023,7 @@ FINISH_OFF: INTERNAL_FUNC int emstorage_set_mail_slot_size(int account_id, int mailbox_id, int new_slot_size, int transaction, int *err_code) { EM_DEBUG_FUNC_BEGIN("account_id[%d], mailbox_id[%p] new_slot_size[%d], err_code[%p]", account_id, mailbox_id, new_slot_size, err_code); - int rc = -1, ret = false, err = EMAIL_ERROR_NONE; + int ret = false, err = EMAIL_ERROR_NONE; int where_pararaph_length = 0; char *where_pararaph = NULL; char sql_query_string[QUERY_SIZE] = {0, }; @@ -13562,24 +14068,24 @@ INTERNAL_FUNC int emstorage_set_mail_slot_size(int account_id, int mailbox_id, i SNPRINTF(where_pararaph + EM_SAFE_STRLEN(where_pararaph), where_pararaph_length - EM_SAFE_STRLEN(where_pararaph), " %s total_mail_count_on_server > mail_slot_size ", (and ? "AND" : "WHERE")); if (strlen(sql_query_string) + EM_SAFE_STRLEN(where_pararaph) < QUERY_SIZE) /* prevent 34363 */ - strcat(sql_query_string, where_pararaph); + strncat(sql_query_string, where_pararaph, EM_SAFE_STRLEN(where_pararaph)); else { EM_DEBUG_EXCEPTION("Query buffer overflowed !!!"); err = EMAIL_ERROR_OUT_OF_MEMORY; goto FINISH_OFF; } - EM_DEBUG_LOG("query[%s]", sql_query_string); - - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc); - EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {err = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, - ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + EM_DEBUG_LOG_SEC("query[%s]", sql_query_string); + err = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); + if (err != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", err); + goto FINISH_OFF; + } ret = true; FINISH_OFF: EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, err); - _DISCONNECT_DB; EM_SAFE_FREE(where_pararaph); @@ -13696,13 +14202,10 @@ INTERNAL_FUNC int emstorage_add_meeting_request(int account_id, int input_mailbo FINISH_OFF: EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error); - _DISCONNECT_DB; 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); + EM_DEBUG_EXCEPTION("sqlite3_finalize error [%d]", rc); error = EMAIL_ERROR_DB_FAILURE; } } @@ -13745,7 +14248,7 @@ INTERNAL_FUNC int emstorage_query_meeting_request(const char *conditional_clause SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT * FROM mail_meeting_tbl %s", conditional_clause); - EM_DEBUG_LOG("Query [%s]", sql_query_string); + EM_DEBUG_LOG_SEC("Query [%s]", sql_query_string); EMSTORAGE_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), {err = EMAIL_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; }, @@ -13790,10 +14293,10 @@ INTERNAL_FUNC int emstorage_query_meeting_request(const char *conditional_clause FINISH_OFF: - if(result) + if (result) sqlite3_free_table(result); - if (err == EMAIL_ERROR_NONE) { + if (err == EMAIL_ERROR_NONE) { if (p_temp_meeting_req) *output_meeting_req = p_temp_meeting_req; *output_result_count = count; @@ -13803,9 +14306,8 @@ FINISH_OFF: EMSTORAGE_FINISH_READ_TRANSACTION(transaction); - sqlite3_db_release_memory(local_db_handle); - - _DISCONNECT_DB; + if (local_db_handle) + sqlite3_db_release_memory(local_db_handle); EM_DEBUG_FUNC_END("err [%d]", err); return err; @@ -13898,7 +14400,7 @@ INTERNAL_FUNC int emstorage_update_meeting_request(email_meeting_request_t* meet "WHERE mail_id = %d", meeting_req->mail_id); - EM_DEBUG_LOG("SQL(%s)", sql_query_string); + EM_DEBUG_LOG_SEC("SQL(%s)", sql_query_string); EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, @@ -13946,15 +14448,11 @@ INTERNAL_FUNC int emstorage_update_meeting_request(email_meeting_request_t* meet FINISH_OFF: EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error); - _DISCONNECT_DB; 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); - + EM_DEBUG_EXCEPTION("sqlite3_finalize error [%d]", rc); error = EMAIL_ERROR_DB_FAILURE; } } @@ -13978,7 +14476,6 @@ INTERNAL_FUNC int emstorage_delete_meeting_request(int account_id, int mail_id, return false; } - int rc; int ret = false; int error = EMAIL_ERROR_NONE; int and = false; @@ -14001,15 +14498,16 @@ INTERNAL_FUNC int emstorage_delete_meeting_request(int account_id, int mail_id, SNPRINTF(sql_query_string + EM_SAFE_STRLEN(sql_query_string), sizeof(sql_query_string)-(EM_SAFE_STRLEN(sql_query_string)+1), " %s mailbox_id = '%d'", (and ? "AND" : "WHERE"), input_mailbox_id); } - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc); - EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, - ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); + if (error != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; + } ret = true; FINISH_OFF: EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error); - _DISCONNECT_DB; if (err_code) *err_code = error; @@ -14032,7 +14530,7 @@ INTERNAL_FUNC void emstorage_free_meeting_request(email_meeting_request_t *meeti } -INTERNAL_FUNC int emstorage_get_overflowed_mail_id_list(int account_id, int input_mailbox_id, int mail_slot_size, int **mail_id_list, int *mail_id_count, int transaction, int *err_code) +INTERNAL_FUNC int emstorage_get_overflowed_mail_id_list(int account_id, int input_mailbox_id, int input_mailbox_type, int mail_slot_size, int **mail_id_list, int *mail_id_count, int transaction, int *err_code) { EM_DEBUG_FUNC_BEGIN("account_id [%d], input_mailbox_id [%d], mail_slot_size [%d], mail_id_list [%p], mail_id_count [%p], transaction [%d], err_code [%p]", account_id, input_mailbox_id, mail_slot_size, mail_id_list, mail_id_count, transaction, err_code); EM_PROFILE_BEGIN(profile_emstorage_get_overflowed_mail_id_list); @@ -14051,9 +14549,9 @@ INTERNAL_FUNC int emstorage_get_overflowed_mail_id_list(int account_id, int inpu return false; } - SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT mail_id FROM mail_tbl WHERE account_id = %d AND mailbox_id = %d ORDER BY date_time DESC LIMIT %d, 10000", account_id, input_mailbox_id, mail_slot_size); + SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT mail_id FROM mail_tbl WHERE account_id = %d AND mailbox_id = %d AND mailbox_type = %d ORDER BY date_time DESC LIMIT %d, 10000", account_id, input_mailbox_id, input_mailbox_type, mail_slot_size); - EM_DEBUG_LOG("query[%s].", sql_query_string); + EM_DEBUG_LOG_SEC("query[%s].", sql_query_string); sqlite3 *local_db_handle = emstorage_get_db_connection(); EMSTORAGE_START_READ_TRANSACTION(transaction); @@ -14101,7 +14599,6 @@ FINISH_OFF: EM_SAFE_FREE(result_mail_id_list); EMSTORAGE_FINISH_READ_TRANSACTION(transaction); - _DISCONNECT_DB; if (err_code != NULL) *err_code = error; @@ -14154,7 +14651,6 @@ INTERNAL_FUNC int emstorage_get_thread_id_by_mail_id(int mail_id, int *thread_id ret = true; FINISH_OFF: - _DISCONNECT_DB; if (err_code != NULL) *err_code = err; @@ -14163,10 +14659,9 @@ FINISH_OFF: return ret; } - -INTERNAL_FUNC int emstorage_update_latest_thread_mail(int account_id, int thread_id, int latest_mail_id, int thread_item_count, int transaction, int *err_code) +INTERNAL_FUNC int emstorage_update_latest_thread_mail(int account_id, int mailbox_id, int thread_id, int *updated_thread_id, int latest_mail_id, int thread_item_count, int noti_type, int transaction, int *err_code) { - 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); + EM_DEBUG_FUNC_BEGIN("account_id [%d], mailbox_id [%d], thread_id[%d], updated_thread_id[%p], latest_mail_id [%d], thread_item_count[%d], err_code[%p]", account_id, mailbox_id, thread_id, updated_thread_id, latest_mail_id, thread_item_count, err_code); int rc = -1, ret = false; int err = EMAIL_ERROR_NONE; @@ -14183,9 +14678,9 @@ INTERNAL_FUNC int emstorage_update_latest_thread_mail(int account_id, int thread sqlite3 *local_db_handle = emstorage_get_db_connection(); - if (thread_item_count == 0 || latest_mail_id == 0) { + 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); + SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT mail_id, count(*) FROM (SELECT account_id, mail_id, thread_id, mailbox_id FROM mail_tbl ORDER BY date_time) WHERE account_id = %d AND thread_id = %d AND mailbox_id = %d", account_id, thread_id, mailbox_id); /* rc = sqlite3_get_table(local_db_handle, sql_query_string, &result, &result_count, 0, NULL); */ EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, &result_count, 0, NULL), rc); @@ -14212,30 +14707,115 @@ INTERNAL_FUNC int emstorage_update_latest_thread_mail(int account_id, int thread EMSTORAGE_START_WRITE_TRANSACTION(transaction, err); - /* if (thread_item_count > 1) */ - /* { */ + if (thread_item_count < 0) + { memset(sql_query_string, 0, QUERY_SIZE); SNPRINTF(sql_query_string, sizeof(sql_query_string), "UPDATE mail_tbl SET thread_item_count = 0 WHERE account_id = %d AND thread_id = %d", account_id, thread_id); - EM_DEBUG_LOG("query[%s]", sql_query_string); + EM_DEBUG_LOG_SEC("query[%s]", sql_query_string); + err = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); + if (err != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", err); + goto FINISH_OFF; + } + } else if (thread_id != latest_mail_id) { + /* Initialize the thread id */ + memset(sql_query_string, 0, QUERY_SIZE); + SNPRINTF(sql_query_string, sizeof(sql_query_string), "UPDATE mail_tbl SET thread_item_count = 0, thread_id = %d WHERE account_id = %d AND mailbox_id = %d AND thread_id = %d", latest_mail_id, account_id, mailbox_id, thread_id); + err = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); + if (err != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", err); + goto FINISH_OFF; + } - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc); - EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {err = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, - ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); - /* } */ + /* update the thread item count */ + 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); + err = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); + if (err != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", err); + goto FINISH_OFF; + } - 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); - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc); - EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {err = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, - ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + } else { + 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_SEC("query[%s]", sql_query_string); + err = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); + if (err != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", err); + goto FINISH_OFF; + } + } + ret = true; + +FINISH_OFF: + EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, err); + + if (thread_id != latest_mail_id) + { + if(err == EMAIL_ERROR_NONE) + { + EM_DEBUG_LOG("noti_type[%d]", noti_type); + + if (latest_mail_id > 0 && thread_id > 0 && noti_type > 0) { + char mailbox_id_str[25] = {0,}; + snprintf(mailbox_id_str, sizeof(mailbox_id_str), "%d", mailbox_id); + if (!emcore_notify_storage_event(noti_type, thread_id, latest_mail_id, mailbox_id_str, account_id)) + EM_DEBUG_EXCEPTION(" emcore_notify_storage_event failed [NOTI_THREAD_ID_CHANGED] >>>> "); + + if (updated_thread_id) *updated_thread_id = latest_mail_id; + } + } + }else if(thread_item_count >= 0) + { + if(err == EMAIL_ERROR_NONE) + { + char parameter_string[500] = {0,}; + SNPRINTF(parameter_string, sizeof(parameter_string), "%s%c%d", "thread_item_count", 0x01, latest_mail_id); + if (!emcore_notify_storage_event(NOTI_MAIL_FIELD_UPDATE, account_id, EMAIL_MAIL_ATTRIBUTE_THREAD_ITEM_COUNT, parameter_string, thread_item_count)) + EM_DEBUG_EXCEPTION(" emcore_notify_storage_event failed [NOTI_MAIL_FIELD_UPDATE] >>>> "); + } + } + + if (err_code != NULL) + *err_code = err; + + EM_DEBUG_FUNC_END("ret [%d]", ret); + return ret; +} + +INTERNAL_FUNC int emstorage_update_thread_id_of_mail(int account_id, int mailbox_id, int mail_id, int thread_id, int thread_item_count, int transaction, int *err_code) +{ + EM_DEBUG_FUNC_BEGIN("account_id [%d], mailbox_id [%d], mail_id[%d], thread_id[%d], thread_item_count[%d], err_code[%p]", account_id, mailbox_id, mail_id, thread_id, thread_item_count, err_code); + + int ret = false; + int err = EMAIL_ERROR_NONE; + char sql_query_string[QUERY_SIZE] = {0, }; + + if (thread_id == 0) { + EM_DEBUG_EXCEPTION("Invalid Parameter"); + if (err_code) + *err_code = EMAIL_ERROR_INVALID_PARAM; + return false; + } + + sqlite3 *local_db_handle = emstorage_get_db_connection(); + + EMSTORAGE_START_WRITE_TRANSACTION(transaction, err); + + memset(sql_query_string, 0, QUERY_SIZE); + SNPRINTF(sql_query_string, sizeof(sql_query_string), "UPDATE mail_tbl SET thread_item_count = %d, thread_id = %d WHERE account_id = %d AND mail_id = %d", thread_item_count, thread_id, account_id, mail_id); + err = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); + if (err != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", err); + goto FINISH_OFF; + } ret = true; FINISH_OFF: EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, err); - _DISCONNECT_DB; if (err_code != NULL) *err_code = err; @@ -14288,14 +14868,14 @@ INTERNAL_FUNC int emstorage_add_activity(emstorage_activity_tbl_t* local_activit 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_DEBUG_LOG_SEC(">>>> SQL STMT [ %s ] ", sql_query_string); EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); - EM_DEBUG_LOG(">>>> SQL STMT [ %s ] ", sql_query_string); + EM_DEBUG_LOG_SEC(">>>> SQL STMT [ %s ] ", sql_query_string); _bind_stmt_field_data_int(hStmt, i++, local_activity->activity_id); _bind_stmt_field_data_int(hStmt, i++, local_activity->account_id); @@ -14317,13 +14897,11 @@ INTERNAL_FUNC int emstorage_add_activity(emstorage_activity_tbl_t* local_activit FINISH_OFF: EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error); - _DISCONNECT_DB; if (hStmt != NULL) { rc = sqlite3_finalize(hStmt); if (rc != SQLITE_OK) { - EM_DEBUG_LOG(" sqlite3_finalize failed - %d", rc); - + EM_DEBUG_EXCEPTION("sqlite3_finalize error [%d]", rc); error = EMAIL_ERROR_DB_FAILURE; } } @@ -14375,7 +14953,7 @@ INTERNAL_FUNC int emstorage_get_activity(int account_id, int activityid, emstora 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); + EM_DEBUG_LOG_SEC("Query [%s]", sql_query_string); @@ -14469,7 +15047,7 @@ INTERNAL_FUNC int emstorage_get_next_activity_id(int *activity_id, int *err_code if (NULL == activity_id) { EM_DEBUG_EXCEPTION(" activity_id[%p]", activity_id); - if (err_code) + if (err_code) *err_code = EMAIL_ERROR_INVALID_PARAM; return false; } @@ -14533,7 +15111,7 @@ INTERNAL_FUNC int emstorage_get_activity_id_list(int account_id, int ** activity 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); + EM_DEBUG_LOG_SEC(" Query [%s]", sql_query_string); EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, &count, NULL, NULL), rc); @@ -14640,7 +15218,7 @@ INTERNAL_FUNC int emstorage_delete_local_activity(emstorage_activity_tbl_t* loca SNPRINTF(sql_query_string, sizeof(sql_query_string), "DELETE FROM mail_local_activity_tbl "); - EM_DEBUG_LOG(">>> Query [ %s ] ", sql_query_string); + EM_DEBUG_LOG_SEC(">>> Query [ %s ] ", sql_query_string); if (local_activity->account_id) { SNPRINTF(sql_query_string + EM_SAFE_STRLEN(sql_query_string), sizeof(sql_query_string)-(EM_SAFE_STRLEN(sql_query_string)+1), @@ -14679,11 +15257,12 @@ INTERNAL_FUNC int emstorage_delete_local_activity(emstorage_activity_tbl_t* loca } - EM_DEBUG_LOG(">>>>> Query [ %s ] ", sql_query_string); - - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc); - EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {err = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, - ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + EM_DEBUG_LOG_SEC(">>>>> Query [ %s ] ", sql_query_string); + error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); + if (error != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; + } rc = sqlite3_changes(local_db_handle); if (rc == 0) { @@ -14695,6 +15274,15 @@ INTERNAL_FUNC int emstorage_delete_local_activity(emstorage_activity_tbl_t* loca FINISH_OFF: EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error); + + if (hStmt != NULL) { + rc = sqlite3_finalize(hStmt); + if (rc != SQLITE_OK) { + EM_DEBUG_EXCEPTION ("sqlite3_finalize error [%d]", rc); + error = EMAIL_ERROR_DB_FAILURE; + } + } + if (err_code != NULL) *err_code = err; EM_DEBUG_FUNC_END("ret [%d]", ret); @@ -14730,7 +15318,7 @@ INTERNAL_FUNC int emstorage_free_local_activity(emstorage_activity_tbl_t **local EM_SAFE_FREE (p[i].server_mailid); } - EM_SAFE_FREE (p); + EM_SAFE_FREE (p); *local_activity_list = NULL; } } @@ -14984,19 +15572,20 @@ static int _make_filter_attach_rule_string(email_list_filter_rule_attach_t *inpu { EM_DEBUG_FUNC_BEGIN("input_list_filter_rule [%p], output_string [%p]", input_list_filter_rule, output_string); - int ret = EMAIL_ERROR_NONE; char *field_name_string = NULL; char key_value_string[QUERY_SIZE] = {0,}; char result_rule_string[QUERY_SIZE] = {0,}; - int rc = -1; int count = 0; + int query_size = 0; + int cur_query = 0; int col_index = 0; int error = EMAIL_ERROR_NONE; char **result = NULL; char sql_query_string[QUERY_SIZE] = {0,}; - char sql_query_string2[QUERY_SIZE] = {0,}; + char *sql_query_string2 = NULL; sqlite3 *local_db_handle = NULL; + int *mail_ids = NULL; if(input_list_filter_rule == NULL || output_string == NULL) { EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM"); @@ -15018,7 +15607,7 @@ static int _make_filter_attach_rule_string(email_list_filter_rule_attach_t *inpu default : EM_DEBUG_EXCEPTION("Invalid rule_type [%d]", input_list_filter_rule->rule_type); - ret = EMAIL_ERROR_INVALID_PARAM; + error = EMAIL_ERROR_INVALID_PARAM; goto FINISH_OFF; } @@ -15034,7 +15623,6 @@ static int _make_filter_attach_rule_string(email_list_filter_rule_attach_t *inpu if (!count) { EM_DEBUG_LOG("No mail found..."); - ret = true; error= EMAIL_ERROR_MAIL_NOT_FOUND; *output_string = strdup("mail_id IN ( ) "); goto FINISH_OFF; @@ -15042,7 +15630,6 @@ static int _make_filter_attach_rule_string(email_list_filter_rule_attach_t *inpu EM_DEBUG_LOG_DEV (">>>> DATA ASSIGN START >>"); int i = 0; - int *mail_ids = NULL; if (!(mail_ids = (int *)em_malloc(sizeof(int) * count))) { EM_DEBUG_EXCEPTION("malloc for mail_ids failed..."); error = EMAIL_ERROR_OUT_OF_MEMORY; @@ -15060,41 +15647,48 @@ static int _make_filter_attach_rule_string(email_list_filter_rule_attach_t *inpu sqlite3_db_release_memory(local_db_handle); - _DISCONNECT_DB; - int cur_query = 0; - cur_query += SNPRINTF_OFFSET(sql_query_string2, cur_query, QUERY_SIZE, "mail_id IN ( "); + query_size = (10 * count) + strlen("mail_id IN ( ) "); + + sql_query_string2 = em_malloc(query_size); + if (sql_query_string2 == NULL) { + EM_DEBUG_EXCEPTION("em_malloc failed"); + error = EMAIL_ERROR_OUT_OF_MEMORY; + goto FINISH_OFF; + } + + cur_query += SNPRINTF_OFFSET(sql_query_string2, cur_query, query_size, "mail_id IN ( "); for (i = 0; i < count-1; i++) { - cur_query += SNPRINTF_OFFSET(sql_query_string2, cur_query, QUERY_SIZE, "%d, ", mail_ids[i]); + cur_query += SNPRINTF_OFFSET(sql_query_string2, cur_query, query_size, "%d, ", mail_ids[i]); } - cur_query += SNPRINTF_OFFSET(sql_query_string2, cur_query, QUERY_SIZE, "%d ) ", mail_ids[count-1]); + cur_query += SNPRINTF_OFFSET(sql_query_string2, cur_query, query_size, "%d ) ", mail_ids[count-1]); *output_string = strdup(sql_query_string2); - EM_SAFE_FREE(mail_ids); /*prevent 50929*/ - FINISH_OFF: + + EM_SAFE_FREE(mail_ids); /* prevent */ + EM_SAFE_FREE(sql_query_string2); EM_SAFE_FREE(field_name_string); - EM_DEBUG_FUNC_END("ret [%d]", ret); - return ret; + EM_DEBUG_FUNC_END("error [%d]", error); + return error; } static int _make_filter_fts_rule_string(email_list_filter_rule_fts_t *input_list_filter_rule, char **output_string) { EM_DEBUG_FUNC_BEGIN("input_list_filter_rule [%p], output_string [%p]", input_list_filter_rule, output_string); - - int ret = EMAIL_ERROR_NONE; char *field_name_string = NULL; char key_value_string[QUERY_SIZE] = {0,}; char result_rule_string[QUERY_SIZE] = {0,}; - int rc = -1; int count = 0; int col_index = 0; + int query_size = 0; int error = EMAIL_ERROR_NONE; char **result = NULL; char sql_query_string[QUERY_SIZE] = {0,}; - char sql_query_string2[QUERY_SIZE] = {0,}; + char *sql_query_string2 = NULL; sqlite3 *local_db_handle = NULL; + int *mail_ids = NULL; if(input_list_filter_rule == NULL || output_string == NULL) { EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM"); @@ -15116,7 +15710,7 @@ static int _make_filter_fts_rule_string(email_list_filter_rule_fts_t *input_list default : EM_DEBUG_EXCEPTION("Invalid rule_type [%d]", input_list_filter_rule->rule_type); - ret = EMAIL_ERROR_INVALID_PARAM; + error = EMAIL_ERROR_INVALID_PARAM; goto FINISH_OFF; } @@ -15132,7 +15726,6 @@ static int _make_filter_fts_rule_string(email_list_filter_rule_fts_t *input_list if (!count) { EM_DEBUG_LOG("No mail found..."); - ret = true; error= EMAIL_ERROR_MAIL_NOT_FOUND; *output_string = strdup("mail_id IN ( ) "); goto FINISH_OFF; @@ -15140,7 +15733,7 @@ static int _make_filter_fts_rule_string(email_list_filter_rule_fts_t *input_list EM_DEBUG_LOG_DEV (">>>> DATA ASSIGN START >>"); int i = 0; - int *mail_ids = NULL; + if (!(mail_ids = (int *)em_malloc(sizeof(int) * count))) { EM_DEBUG_EXCEPTION("malloc for mail_ids failed..."); error = EMAIL_ERROR_OUT_OF_MEMORY; @@ -15158,22 +15751,29 @@ static int _make_filter_fts_rule_string(email_list_filter_rule_fts_t *input_list sqlite3_db_release_memory(local_db_handle); - _DISCONNECT_DB; + query_size = (10 * count) + strlen("mail_id IN ( ) "); + sql_query_string2 = em_malloc(query_size); + if (sql_query_string2 == NULL) { + EM_DEBUG_EXCEPTION("em_malloc failed"); + error = EMAIL_ERROR_OUT_OF_MEMORY; + goto FINISH_OFF; + } int cur_query = 0; - cur_query += SNPRINTF_OFFSET(sql_query_string2, cur_query, QUERY_SIZE, "mail_id IN ( "); + cur_query += SNPRINTF_OFFSET(sql_query_string2, cur_query, query_size, "mail_id IN ( "); for (i = 0; i < count-1; i++) { - cur_query += SNPRINTF_OFFSET(sql_query_string2, cur_query, QUERY_SIZE, "%d, ", mail_ids[i]); + cur_query += SNPRINTF_OFFSET(sql_query_string2, cur_query, query_size, "%d, ", mail_ids[i]); } - cur_query += SNPRINTF_OFFSET(sql_query_string2, cur_query, QUERY_SIZE, "%d ) ", mail_ids[count-1]); + cur_query += SNPRINTF_OFFSET(sql_query_string2, cur_query, query_size, "%d ) ", mail_ids[count-1]); *output_string = strdup(sql_query_string2); - EM_SAFE_FREE(mail_ids); /*prevent 50929*/ FINISH_OFF: + EM_SAFE_FREE(mail_ids); /* prevent */ + EM_SAFE_FREE(sql_query_string2); EM_SAFE_FREE(field_name_string); - EM_DEBUG_FUNC_END("ret [%d]", ret); - return ret; + EM_DEBUG_FUNC_END("error [%d]", error); + return error; } static int _make_order_rule_string(email_list_sorting_rule_t *input_sorting_rule, char **output_string) { @@ -15190,11 +15790,10 @@ static int _make_order_rule_string(email_list_sorting_rule_t *input_sorting_rule char *tmp_str2 = NULL; char query_per_account[QUERY_SIZE] = { 0 , }; - if(input_sorting_rule->force_boolean_check) { + if (input_sorting_rule->force_boolean_check) SNPRINTF(result_rule_string, QUERY_SIZE, "%s = 0 ", emcore_get_mail_field_name_by_attribute_type(input_sorting_rule->target_attribute)); - } else - EM_SAFE_STRCPY(result_rule_string, emcore_get_mail_field_name_by_attribute_type(input_sorting_rule->target_attribute)); + SNPRINTF(result_rule_string, QUERY_SIZE, "%s", emcore_get_mail_field_name_by_attribute_type(input_sorting_rule->target_attribute)); switch (input_sorting_rule->sort_order) { case EMAIL_SORT_ORDER_ASCEND : @@ -15205,6 +15804,14 @@ static int _make_order_rule_string(email_list_sorting_rule_t *input_sorting_rule EM_SAFE_STRCAT(result_rule_string, " DESC "); break; + case EMAIL_SORT_ORDER_NOCASE_ASCEND : + EM_SAFE_STRCAT(result_rule_string, " COLLATE NOCASE ASC "); + break; + + case EMAIL_SORT_ORDER_NOCASE_DESCEND : + EM_SAFE_STRCAT(result_rule_string, " COLLATE NOCASE DESC "); + break; + case EMAIL_SORT_ORDER_TO_CCBCC : memset(result_rule_string, 0, QUERY_SIZE); if (input_sorting_rule->key_value.string_type_value) @@ -15261,6 +15868,22 @@ static int _make_order_rule_string(email_list_sorting_rule_t *input_sorting_rule emstorage_free_account(&account_tbl_array, count, NULL); break; + case EMAIL_SORT_ORDER_LOCALIZE_ASCEND : + memset(result_rule_string, 0, QUERY_SIZE); + sqlite3_snprintf(QUERY_SIZE, result_rule_string, + " CASE WHEN %s GLOB \'[][~`!@#$%%^&*()_-+=|\\{}:;<>,.?/ ]*\' THEN 1 ELSE 2 END ASC, %s COLLATE NOCASE ASC ", + emcore_get_mail_field_name_by_attribute_type(input_sorting_rule->target_attribute), + emcore_get_mail_field_name_by_attribute_type(input_sorting_rule->target_attribute)); + break; + + case EMAIL_SORT_ORDER_LOCALIZE_DESCEND : + memset(result_rule_string, 0, QUERY_SIZE); + sqlite3_snprintf(QUERY_SIZE, result_rule_string, + " CASE WHEN %s GLOB \'[][~`!@#$%%^&*()_-+=|\\{}:;<>,.?/ ]*\' THEN 1 ELSE 2 END DESC, %s COLLATE NOCASE DESC ", + emcore_get_mail_field_name_by_attribute_type(input_sorting_rule->target_attribute), + emcore_get_mail_field_name_by_attribute_type(input_sorting_rule->target_attribute)); + break; + default : EM_DEBUG_EXCEPTION("Invalid sort_order [%d]", input_sorting_rule->sort_order); ret = EMAIL_ERROR_INVALID_PARAM; @@ -15280,7 +15903,9 @@ INTERNAL_FUNC int emstorage_write_conditional_clause_for_getting_mail_list(email int ret = EMAIL_ERROR_NONE; int i = 0; int string_offset = 0; - char conditional_clause_string[QUERY_SIZE] = {0, }; + int query_size = 0; + int new_query_size = 0; + char *conditional_clause_string = NULL; char *result_string_for_a_item = NULL; if ( (input_filter_count > 0 && !input_filter_list) || (input_sorting_rule_count > 0 && !input_sorting_rule_list) || output_conditional_clause == NULL) { @@ -15288,7 +15913,14 @@ INTERNAL_FUNC int emstorage_write_conditional_clause_for_getting_mail_list(email return EMAIL_ERROR_INVALID_PARAM; } + conditional_clause_string = em_malloc(QUERY_SIZE); + if (conditional_clause_string == NULL) { + EM_DEBUG_EXCEPTION("Memory is full"); + return EMAIL_ERROR_OUT_OF_MEMORY; + } + if(input_filter_count > 0) { + query_size = QUERY_SIZE; strcpy(conditional_clause_string, " WHERE "); for ( i = 0; i < input_filter_count; i++) { @@ -15338,11 +15970,19 @@ INTERNAL_FUNC int emstorage_write_conditional_clause_for_getting_mail_list(email goto FINISH_OFF; } - if(strlen(conditional_clause_string) + EM_SAFE_STRLEN(result_string_for_a_item) >= QUERY_SIZE) { /* prevent 34364 */ - EM_DEBUG_EXCEPTION("Query is too long"); - ret = EMAIL_ERROR_DATA_TOO_LONG; - goto FINISH_OFF; + if(strlen(conditional_clause_string) + EM_SAFE_STRLEN(result_string_for_a_item) >= query_size) { /* prevent 34364 */ + EM_DEBUG_LOG("QUERY is too long"); + new_query_size = EM_SAFE_STRLEN(result_string_for_a_item) + EM_SAFE_STRLEN(conditional_clause_string) + QUERY_SIZE; + conditional_clause_string = realloc(conditional_clause_string, new_query_size); + if (conditional_clause_string == NULL) { + EM_DEBUG_EXCEPTION("realloc failed"); + ret = EMAIL_ERROR_OUT_OF_MEMORY; + goto FINISH_OFF; + } + + query_size = new_query_size; } + strcat(conditional_clause_string, result_string_for_a_item); EM_SAFE_FREE(result_string_for_a_item); } @@ -15365,15 +16005,16 @@ INTERNAL_FUNC int emstorage_write_conditional_clause_for_getting_mail_list(email if (input_start_index != -1 && input_limit_count != -1) { string_offset = strlen(conditional_clause_string); - SNPRINTF_OFFSET(conditional_clause_string, string_offset, QUERY_SIZE, " LIMIT %d, %d", input_start_index, input_limit_count); + SNPRINTF_OFFSET(conditional_clause_string, string_offset, query_size, " LIMIT %d, %d", input_start_index, input_limit_count); } *output_conditional_clause = strdup(conditional_clause_string); FINISH_OFF: EM_SAFE_FREE(result_string_for_a_item); + EM_SAFE_FREE(conditional_clause_string); - EM_DEBUG_FUNC_END("ret [%d]", ret); + EM_DEBUG_FUNC_END("ret [%d]", ret); return ret; } @@ -15388,7 +16029,10 @@ INTERNAL_FUNC int emstorage_free_list_filter(email_list_filter_t **input_filter_ for ( i = 0; i < input_filter_count; i++) { temp_filter_list = (*input_filter_list) + i; - if(temp_filter_list && temp_filter_list->list_filter_item_type == EMAIL_LIST_FILTER_ITEM_RULE) { + if(!temp_filter_list) { + continue; + } + if(temp_filter_list->list_filter_item_type == EMAIL_LIST_FILTER_ITEM_RULE) { switch(temp_filter_list->list_filter_item.rule.target_attribute) { case EMAIL_MAIL_ATTRIBUTE_MAILBOX_NAME : case EMAIL_MAIL_ATTRIBUTE_SUBJECT : @@ -15408,6 +16052,12 @@ INTERNAL_FUNC int emstorage_free_list_filter(email_list_filter_t **input_filter_ break; } } + else if(temp_filter_list->list_filter_item_type == EMAIL_LIST_FILTER_ITEM_RULE_FTS && temp_filter_list->list_filter_item.rule_fts.target_attribute == EMAIL_MAIL_TEXT_ATTRIBUTE_FULL_TEXT) { + EM_SAFE_FREE(temp_filter_list->list_filter_item.rule_fts.key_value.string_type_value); + } + else if(temp_filter_list->list_filter_item_type == EMAIL_LIST_FILTER_ITEM_RULE_ATTACH && temp_filter_list->list_filter_item.rule_attach.target_attribute == EMAIL_MAIL_ATTACH_ATTRIBUTE_ATTACHMENT_NAME) { + EM_SAFE_FREE(temp_filter_list->list_filter_item.rule_attach.key_value.string_type_value); + } } EM_SAFE_FREE (*input_filter_list); @@ -15429,6 +16079,7 @@ INTERNAL_FUNC int emstorage_add_certificate(emstorage_certificate_tbl_t *certifi int rc = -1, ret = false; int error = EMAIL_ERROR_NONE; +// int ssa_err = 0; DB_STMT hStmt = NULL; char sql_query_string[QUERY_SIZE] = {0, }; #ifdef __FEATURE_SUPPORT_PRIVATE_CERTIFICATE__ @@ -15480,7 +16131,7 @@ INTERNAL_FUNC int emstorage_add_certificate(emstorage_certificate_tbl_t *certifi EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); - EM_DEBUG_LOG(">>>> SQL STMT [ %s ] ", sql_query_string); + EM_DEBUG_LOG_SEC(">>>> SQL STMT [ %s ] ", sql_query_string); _bind_stmt_field_data_int(hStmt, CERTFICATE_BIND_TYPE_IDX_IN_MAIL_CERTIFICATE_TBL, certificate->certificate_id); _bind_stmt_field_data_int(hStmt, ISSUE_YEAR_IDX_IN_MAIL_CERTIFICATE_TBL, certificate->issue_year); _bind_stmt_field_data_int(hStmt, ISSUE_MONTH_IDX_IN_MAIL_CERTIFICATE_TBL, certificate->issue_month); @@ -15499,23 +16150,15 @@ INTERNAL_FUNC int emstorage_add_certificate(emstorage_certificate_tbl_t *certifi ("sqlite3_step fail:%d", rc)); EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, ("sqlite3_step fail:%d, errmsg = %s.", rc, sqlite3_errmsg(local_db_handle))); -#ifdef __FEATURE_SUPPORT_PRIVATE_CERTIFICATE__ - if (ssm_write_buffer(certificate->password, EM_SAFE_STRLEN(certificate->password), cert_password_file_name, SSM_FLAG_SECRET_OPERATION, NULL) < 0) { - EM_DEBUG_EXCEPTION_SEC("ssm_write_buffer failed - Private certificate password : [%s]", cert_password_file_name); - error = EMAIL_ERROR_SYSTEM_FAILURE; - goto FINISH_OFF; - } -#endif - ret = true; + ret = true; FINISH_OFF: EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error); - _DISCONNECT_DB; if (hStmt != NULL) { rc = sqlite3_finalize(hStmt); if (rc != SQLITE_OK) { - EM_DEBUG_LOG("sqlite3_finalize failed - %d", rc); + EM_DEBUG_EXCEPTION("sqlite3_finalize error [%d]", rc); error = EMAIL_ERROR_DB_FAILURE; } } @@ -15691,18 +16334,15 @@ FINISH_OFF: else if (p_data_tbl != NULL) emstorage_free_certificate(&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); + EM_DEBUG_EXCEPTION("sqlite3_finalize error [%d]", rc); error = EMAIL_ERROR_DB_FAILURE; } } EMSTORAGE_FINISH_READ_TRANSACTION(transaction); - _DISCONNECT_DB; if (err_code != NULL) *err_code = error; @@ -15743,7 +16383,7 @@ INTERNAL_FUNC int emstorage_get_certificate_by_email_address(char *email_address SNPRINTF(sql_query_string + sql_len, sizeof(sql_query_string) - sql_len, "* FROM mail_certificate_tbl WHERE email_address = '%s'", email_address); /* FROM clause */ - EM_DEBUG_LOG("query = [%s]", sql_query_string); + EM_DEBUG_LOG_SEC("query = [%s]", sql_query_string); /* execute a sql and count rows */ EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); @@ -15805,13 +16445,12 @@ FINISH_OFF: if (hStmt != NULL) { rc = sqlite3_finalize(hStmt); if (rc != SQLITE_OK) { - EM_DEBUG_EXCEPTION("sqlite3_finalize failed - %d", rc); + EM_DEBUG_EXCEPTION("sqlite3_finalize error [%d]", rc); error = EMAIL_ERROR_DB_FAILURE; } } EMSTORAGE_FINISH_READ_TRANSACTION(transaction); - _DISCONNECT_DB; if (err_code != NULL) *err_code = error; @@ -15852,7 +16491,7 @@ INTERNAL_FUNC int emstorage_get_certificate_by_index(int index, emstorage_certif SNPRINTF(sql_query_string + sql_len, sizeof(sql_query_string) - sql_len, "* FROM mail_certificate_tbl WHERE certificate_id = %d", index); /* FROM clause */ - EM_DEBUG_LOG("query = [%s]", sql_query_string); + EM_DEBUG_LOG_SEC("query = [%s]", sql_query_string); /* execute a sql and count rows */ EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); @@ -15915,13 +16554,12 @@ FINISH_OFF: if (hStmt != NULL) { rc = sqlite3_finalize(hStmt); if (rc != SQLITE_OK) { - EM_DEBUG_EXCEPTION("sqlite3_finalize failed - %d", rc); + EM_DEBUG_EXCEPTION("sqlite3_finalize error [%d]", rc); error = EMAIL_ERROR_DB_FAILURE; } } EMSTORAGE_FINISH_READ_TRANSACTION(transaction); - _DISCONNECT_DB; if (err_code != NULL) *err_code = error; @@ -15947,7 +16585,6 @@ INTERNAL_FUNC int emstorage_delete_certificate(int certificate_id, int transacti EMSTORAGE_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, }; #ifdef __FEATURE_SUPPORT_PRIVATE_CERTIFICATE__ char cert_password_file_name[MAX_PW_FILE_NAME_LENGTH]; @@ -15960,12 +16597,11 @@ INTERNAL_FUNC int emstorage_delete_certificate(int certificate_id, int transacti /* delete from db */ memset(sql_query_string, 0x00, sizeof(sql_query_string)); SNPRINTF(sql_query_string, sizeof(sql_query_string), "DELETE FROM mail_certificate_tbl WHERE certificate_id = %d", certificate_id); - - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc); - EM_DEBUG_DB_EXEC((rc == SQLITE_FULL), {error = EMAIL_ERROR_MAIL_MEMORY_FULL;goto FINISH_OFF; }, - ("sqlite3_exec fail:%d", rc)); - EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, - ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); + if (error != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; + } /* validate account existence */ rc = sqlite3_changes(local_db_handle); @@ -15974,27 +16610,11 @@ INTERNAL_FUNC int emstorage_delete_certificate(int certificate_id, int transacti error = EMAIL_ERROR_ACCOUNT_NOT_FOUND; goto FINISH_OFF; } -#ifdef __FEATURE_SUPPORT_PRIVATE_CERTIFICATE__ - /* delete from secure storage */ - if (ssm_delete_file(cert_password_file_name, SSM_FLAG_SECRET_OPERATION, NULL) < 0) { - EM_DEBUG_EXCEPTION_SEC(" ssm_delete_file failed -cert password : file[%s]", cert_password_file_name); - error = EMAIL_ERROR_SYSTEM_FAILURE; - goto FINISH_OFF; - } -#endif + ret = true; FINISH_OFF: EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error); - _DISCONNECT_DB; - - if (hStmt != NULL) { - rc = sqlite3_finalize(hStmt); - if (rc != SQLITE_OK) { - EM_DEBUG_LOG(" sqlite3_finalize failed - %d", rc); - error = EMAIL_ERROR_DB_FAILURE; - } - } if (err_code != NULL) *err_code = error; @@ -16072,33 +16692,15 @@ INTERNAL_FUNC int emstorage_update_certificate(int certificate_id, emstorage_cer goto FINISH_OFF; } -#ifdef __FEATURE_SUPPORT_PRIVATE_CERTIFICATE__ - /* get password file name */ - if ((error = _get_cert_password_file_name(certificate->certificate_id, cert_password_file_name)) != EMAIL_ERROR_NONE) { - EM_DEBUG_EXCEPTION("em_storage_get_password_file_name failed."); - goto FINISH_OFF; - } - - /* save passwords to the secure storage */ - if (ssm_write_buffer(certificate->password, EM_SAFE_STRLEN(certificate->password), cert_password_file_name, SSM_FLAG_SECRET_OPERATION, NULL) < 0) { - EM_DEBUG_EXCEPTION_SEC("ssm_write_buffer failed - Private certificate password : [%s]", cert_password_file_name); - error = EMAIL_ERROR_SYSTEM_FAILURE; - goto FINISH_OFF; - } -#endif - ret = true; FINISH_OFF: EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error); - _DISCONNECT_DB; 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); + EM_DEBUG_EXCEPTION("sqlite3_finalize error [%d]", rc); error = EMAIL_ERROR_DB_FAILURE; } } @@ -16168,7 +16770,7 @@ INTERNAL_FUNC int emstorage_add_task(email_task_type_t input_task_type, email_ta EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {err = EMAIL_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); + EM_DEBUG_LOG_SEC(">>>> SQL STMT [%s] ", sql_query_string); _bind_stmt_field_data_int(hStmt, i++, task_id); @@ -16190,12 +16792,11 @@ INTERNAL_FUNC int emstorage_add_task(email_task_type_t input_task_type, email_ta FINISH_OFF: EMSTORAGE_FINISH_WRITE_TRANSACTION(input_transaction, ret, err); - _DISCONNECT_DB; if (hStmt != NULL) { rc = sqlite3_finalize(hStmt); if (rc != SQLITE_OK) { - EM_DEBUG_LOG("sqlite3_finalize failed [%d]", rc); + EM_DEBUG_EXCEPTION("sqlite3_finalize error [%d]", rc); err = EMAIL_ERROR_DB_FAILURE; } } @@ -16207,9 +16808,10 @@ FINISH_OFF: INTERNAL_FUNC int emstorage_delete_task(int task_id, int transaction) { EM_DEBUG_FUNC_BEGIN("task_id[%d], transaction[%d]", task_id, transaction); - int rc, ret = false; + int ret = false; int err = EMAIL_ERROR_NONE; char sql_query_string[QUERY_SIZE] = {0, }; + sqlite3 *local_db_handle = NULL; if (task_id < 0) { @@ -16222,16 +16824,16 @@ INTERNAL_FUNC int emstorage_delete_task(int task_id, int transaction) EMSTORAGE_START_WRITE_TRANSACTION(transaction, err); SNPRINTF(sql_query_string, sizeof(sql_query_string), "DELETE FROM mail_task_tbl WHERE task_id = %d", task_id); - - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc); - EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {err = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, - ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + err = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); + if (err != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", err); + goto FINISH_OFF; + } ret = true; FINISH_OFF: EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, err); - _DISCONNECT_DB; EM_DEBUG_FUNC_END("err [%d]", err); return err; @@ -16240,10 +16842,9 @@ FINISH_OFF: INTERNAL_FUNC int emstorage_update_task_status(int task_id, email_task_status_type_t task_status, int transaction) { EM_DEBUG_FUNC_BEGIN("task_id[%d] task_status[%d] transaction[%d]", task_id, task_status, transaction); - int rc, ret = false; + int ret = false; int err = EMAIL_ERROR_NONE; char sql_query_string[QUERY_SIZE] = {0, }; - sqlite3 *local_db_handle = emstorage_get_db_connection(); EMSTORAGE_START_WRITE_TRANSACTION(transaction, err); @@ -16253,16 +16854,16 @@ INTERNAL_FUNC int emstorage_update_task_status(int task_id, email_task_status_ty " WHERE task_id = %d" , task_status , task_id); - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc); - EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {err = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, - ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + err = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); + if (err != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", err); + goto FINISH_OFF; + } ret = true; FINISH_OFF: EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, err); - _DISCONNECT_DB; - EM_DEBUG_FUNC_END("err [%d]", err); return err; @@ -16288,7 +16889,7 @@ INTERNAL_FUNC int emstorage_query_task(const char *input_conditional_clause, con local_db_handle = emstorage_get_db_connection(); SNPRINTF_OFFSET(sql_query_string, cur_query, QUERY_SIZE, "SELECT COUNT(*) FROM mail_task_tbl %s", input_conditional_clause); - EM_DEBUG_LOG("emstorage_query_mail_list : query[%s].", sql_query_string); + EM_DEBUG_LOG_SEC("emstorage_query_mail_list : query[%s].", sql_query_string); EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, NULL, NULL, NULL), rc); EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {err = EMAIL_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; }, @@ -16306,7 +16907,7 @@ INTERNAL_FUNC int emstorage_query_task(const char *input_conditional_clause, con } SNPRINTF_OFFSET(sql_query_string, cur_query, QUERY_SIZE, "SELECT %s FROM mail_task_tbl %s %s", field_list, input_conditional_clause, input_ordering_clause); - EM_DEBUG_LOG("emstorage_query_mail_list : query[%s].", sql_query_string); + EM_DEBUG_LOG_SEC("emstorage_query_mail_list : query[%s].", sql_query_string); EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); @@ -16354,20 +16955,21 @@ FINISH_OFF: *output_task_list = task_item_from_tbl; *output_task_count = count; } - else - EM_SAFE_FREE(task_item_from_tbl); - + else { + for (i = 0; i < count; i++) { + EM_SAFE_FREE(task_item_from_tbl[i].task_parameter); + } + EM_SAFE_FREE(task_item_from_tbl); + } if (hStmt != NULL) { - 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); + EM_DEBUG_EXCEPTION("sqlite3_finalize error [%d]", rc); err = EMAIL_ERROR_DB_FAILURE; } } - _DISCONNECT_DB; EM_DEBUG_FUNC_END("err [%d]", err); return err; @@ -16391,7 +16993,6 @@ INTERNAL_FUNC int emstorage_check_and_update_server_uid_by_message_id(int accoun char *where_pararaph = NULL; char sql_query_string[QUERY_SIZE] = {0, }; char **result = NULL; - sqlite3 *local_db_handle = emstorage_get_db_connection(); SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT mail_id from mail_tbl "); @@ -16412,7 +17013,7 @@ INTERNAL_FUNC int emstorage_check_and_update_server_uid_by_message_id(int accoun if (strlen(sql_query_string) + strlen(where_pararaph) < QUERY_SIZE) strcat(sql_query_string, where_pararaph); - EM_DEBUG_LOG("query[%s]", sql_query_string); + EM_DEBUG_LOG_SEC("query[%s]", sql_query_string); EMSTORAGE_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), {err = EMAIL_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; }, @@ -16431,9 +17032,11 @@ INTERNAL_FUNC int emstorage_check_and_update_server_uid_by_message_id(int accoun if(strlen(sql_query_string) + strlen(where_pararaph) < QUERY_SIZE) strcat(sql_query_string, where_pararaph); - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc); - EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {err = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, - ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + err = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); + if (err != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", err); + goto FINISH_OFF; + } } else { err = EMAIL_ERROR_MAIL_NOT_FOUND; @@ -16444,7 +17047,6 @@ FINISH_OFF: sqlite3_free_table(result); result = NULL; - _DISCONNECT_DB; EM_SAFE_FREE(where_pararaph); @@ -16456,4 +17058,1067 @@ FINISH_OFF: } /* Tasks --------------------------------------------------------------------------*/ +#ifdef __FEATURE_WIFI_AUTO_DOWNLOAD__ +INTERNAL_FUNC int emstorage_add_auto_download_activity(email_event_auto_download *local_activity, int *activity_id, int transaction, int *err_code) +{ + 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], activity_id[%p]", local_activity, activity_id); + if (err_code != NULL) + *err_code = EMAIL_ERROR_INVALID_PARAM; + return false; + } + + int rc = -1; + int ret = false; + int error = EMAIL_ERROR_NONE; + int i = 0; + + char sql_query_string[QUERY_SIZE] = {0, }; + DB_STMT hStmt = NULL; + sqlite3 *local_db_handle = emstorage_get_db_connection(); + EMSTORAGE_START_WRITE_TRANSACTION(transaction, error); + memset(sql_query_string, 0x00, sizeof(sql_query_string)); + SNPRINTF(sql_query_string, sizeof(sql_query_string), + "INSERT INTO mail_auto_download_activity_tbl VALUES " + "( " + "? " /* Activity ID */ + ",?" /* Status */ + ",?" /* Account ID */ + ",?" /* Local Mail ID */ + ",?" /* Server mail ID */ + ",?" /* Mailbox ID*/ + ") "); + + char *sql = "SELECT max(rowid) FROM mail_auto_download_activity_tbl;"; + char **result = NULL; + + + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql, &result, NULL, NULL, NULL), rc); + + EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; }, + ("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_SEC(">>>>> ACTIVITY ID [%d], MAIL ID [%d], SERVER MAIL ID [%lu]", + local_activity->activity_id, local_activity->mail_id, local_activity->server_mail_id); + + if (local_activity->mailbox_id) + EM_DEBUG_LOG(" MAILBOX ID [%d]", local_activity->mailbox_id); + + + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); + EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, + ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + + + _bind_stmt_field_data_int(hStmt, i++, local_activity->activity_id); + _bind_stmt_field_data_int(hStmt, i++, local_activity->status); + _bind_stmt_field_data_int(hStmt, i++, local_activity->account_id); + _bind_stmt_field_data_int(hStmt, i++, local_activity->mail_id); + _bind_stmt_field_data_int(hStmt, i++, local_activity->server_mail_id); + _bind_stmt_field_data_int(hStmt, i++, local_activity->mailbox_id); + + + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc); + + EM_DEBUG_DB_EXEC((rc == SQLITE_FULL), {error = EMAIL_ERROR_MAIL_MEMORY_FULL;goto FINISH_OFF; }, + ("sqlite3_step fail:%d", rc)); + EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, + ("sqlite3_step fail:%d, errmsg = %s.", rc, sqlite3_errmsg(local_db_handle))); + + ret = true; + +FINISH_OFF: + EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error); + if (hStmt != NULL) { + rc = sqlite3_finalize(hStmt); + hStmt = NULL; + if (rc != SQLITE_OK) { + EM_DEBUG_EXCEPTION("sqlite3_finalize error [%d]", rc); + error = EMAIL_ERROR_DB_FAILURE; + } + } + + if (err_code != NULL) + *err_code = error; + + EM_DEBUG_FUNC_END("ret [%d]", ret); + return ret; +} + + +INTERNAL_FUNC int emstorage_delete_auto_download_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 = EMAIL_ERROR_INVALID_PARAM; + return false; + } + + int rc = -1; + int ret = false; + int error = EMAIL_ERROR_NONE; + char sql_query_string[QUERY_SIZE] = {0, }; + sqlite3 *local_db_handle = emstorage_get_db_connection(); + + EMSTORAGE_START_WRITE_TRANSACTION(transaction, error); + memset(sql_query_string, 0x00, sizeof(sql_query_string)); + + if (activity_id == 0) + SNPRINTF(sql_query_string, sizeof(sql_query_string), "DELETE FROM mail_auto_download_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_auto_download_activity_tbl WHERE account_id = %d AND activity_id = %d", account_id, activity_id); + + EM_DEBUG_LOG_SEC("Query [%s]", sql_query_string); + error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); + if (error != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; + } + + /* validate activity existence */ + rc = sqlite3_changes(local_db_handle); + if (rc == 0) { + EM_DEBUG_EXCEPTION("No matching activity found"); + error = EMAIL_ERROR_DATA_NOT_FOUND; + ret = true; + goto FINISH_OFF; + } + + ret = true; + +FINISH_OFF: + EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error); + + if (err_code != NULL) + *err_code = error; + + EM_DEBUG_FUNC_END("ret [%d]", ret); + return ret; +} + + +INTERNAL_FUNC int emstorage_delete_all_auto_download_activity(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 = EMAIL_ERROR_INVALID_PARAM; + return false; + } + + int rc = -1; + int ret = false; + int error = EMAIL_ERROR_NONE; + char sql_query_string[QUERY_SIZE] = {0, }; + sqlite3 *local_db_handle = emstorage_get_db_connection(); + EMSTORAGE_START_WRITE_TRANSACTION(transaction, error); + memset(sql_query_string, 0x00, sizeof(sql_query_string)); + SNPRINTF(sql_query_string, sizeof(sql_query_string), "DELETE FROM mail_auto_download_activity_tbl WHERE account_id = %d", account_id); + + EM_DEBUG_LOG_SEC("Query [%s]", sql_query_string); + error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); + if (error != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; + } + + rc = sqlite3_changes(local_db_handle); + if (rc == 0) { + EM_DEBUG_EXCEPTION("No matching activities found in mail_auto_download_activity_tbl"); + error = EMAIL_ERROR_DATA_NOT_FOUND; + ret = true; + goto FINISH_OFF; + } + + ret = true; + +FINISH_OFF: + EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error); + + if (err_code != NULL) + *err_code = error; + + EM_DEBUG_FUNC_END("ret [%d]", ret); + return ret; +} + + +INTERNAL_FUNC int emstorage_delete_auto_download_activity_by_mailbox(int account_id, int mailbox_id, int transaction, int *err_code) +{ + EM_DEBUG_FUNC_BEGIN("account_id[%d], mailbox_id[%d], transaction[%d], err_code[%p]", account_id, mailbox_id, transaction, err_code); + + if (account_id < FIRST_ACCOUNT_ID || mailbox_id < 0) { + EM_DEBUG_EXCEPTION("account_id[%d], mailbox_id[%d], transaction[%d], err_code[%p]", account_id, mailbox_id, transaction, err_code); + if (err_code != NULL) + *err_code = EMAIL_ERROR_INVALID_PARAM; + return false; + } + + int rc = -1; + int ret = false; + int error = EMAIL_ERROR_NONE; + char sql_query_string[QUERY_SIZE] = {0, }; + sqlite3 *local_db_handle = emstorage_get_db_connection(); + EMSTORAGE_START_WRITE_TRANSACTION(transaction, error); + memset(sql_query_string, 0x00, sizeof(sql_query_string)); + SNPRINTF(sql_query_string, sizeof(sql_query_string), "DELETE FROM mail_auto_download_activity_tbl WHERE account_id = %d AND mailbox_id = %d", account_id, mailbox_id); + + EM_DEBUG_LOG_SEC("Query [%s]", sql_query_string); + error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); + if (error != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; + } + + rc = sqlite3_changes(local_db_handle); + if (rc == 0) { + EM_DEBUG_EXCEPTION("No matching activities found in mail_auto_download_activity_tbl"); + error = EMAIL_ERROR_DATA_NOT_FOUND; + ret = true; + goto FINISH_OFF; + } + + ret = true; + +FINISH_OFF: + EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error); + + if (err_code != NULL) + *err_code = error; + + EM_DEBUG_FUNC_END("ret [%d]", ret); + return ret; +} + + +INTERNAL_FUNC int emstorage_get_auto_download_activity(int account_id, int input_mailbox_id, email_event_auto_download **event_start, int *count, int transaction, int *err_code) +{ + 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 || !event_start || input_mailbox_id <= 0 || !count) { + EM_DEBUG_EXCEPTION("account_id[%d], event_start[%p], input_mailbox_id[%d], count[%p], err_code[%p]", account_id, event_start, input_mailbox_id, count, err_code); + + if (err_code != NULL) + *err_code = EMAIL_ERROR_INVALID_PARAM; + return false; + } + + int rc = -1; + int ret = false; + char **result; + int error = EMAIL_ERROR_NONE; + int i = 0; + DB_STMT hStmt = NULL; + email_event_auto_download *event_list = NULL; + char sql_query_string[QUERY_SIZE] = {0, }; + + sqlite3 *local_db_handle = emstorage_get_db_connection(); + + EMSTORAGE_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_auto_download_activity_tbl WHERE account_id = %d AND mailbox_id = '%d' order by activity_id", account_id, input_mailbox_id); + + + EMSTORAGE_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 = EMAIL_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_SEC("Query = [%s]", sql_query_string); + + if (!*count) { + EM_DEBUG_LOG("No matched activity found in mail_auto_download_activity_tbl"); + error = EMAIL_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_auto_download_activity_tbl WHERE account_id = %d AND mailbox_id = '%d' order by activity_id", account_id, input_mailbox_id); + + EM_DEBUG_LOG_SEC("Query [%s]", sql_query_string); + + + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); + + EM_DEBUG_LOG(" Bbefore sqlite3_prepare hStmt = %p", hStmt); + EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, + ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + + + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc); + EM_DEBUG_DB_EXEC((rc != SQLITE_ROW), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, + ("sqlite3_step fail:%d", rc)); + + if (!(event_list = (email_event_auto_download *)em_malloc(sizeof(email_event_auto_download)*(*count)))) { + EM_DEBUG_EXCEPTION("Malloc failed"); + + error = EMAIL_ERROR_OUT_OF_MEMORY; + goto FINISH_OFF; + } + + for (i=0; i < (*count); i++) { + _get_stmt_field_data_int(hStmt, &(event_list[i].activity_id), ACTIVITY_ID_IDX_MAIL_AUTO_DOWNLOAD_ACTIVITY_TBL); + _get_stmt_field_data_int(hStmt, &(event_list[i].status), STATUS_IDX_MAIL_AUTO_DOWNLOAD_ACTIVITY_TBL); + _get_stmt_field_data_int(hStmt, &(event_list[i].account_id), ACCOUNT_ID_IDX_MAIL_AUTO_DOWNLOAD_ACTIVITY_TBL); + _get_stmt_field_data_int(hStmt, &(event_list[i].mail_id), MAIL_ID_IDX_MAIL_AUTO_DOWNLOAD_ACTIVITY_TBL); + _get_stmt_field_data_int(hStmt, (int *)&(event_list[i].server_mail_id), SERVER_MAIL_ID_IDX_MAIL_AUTO_DOWNLOAD_ACTIVITY_TBL); + _get_stmt_field_data_int(hStmt, &(event_list[i].mailbox_id), MAILBOX_ID_IDX_MAIL_AUTO_DOWNLOAD_ACTIVITY_TBL); + + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc); + EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF;}, + ("sqlite3_step fail:%d", rc)); + } + + ret = true; + +FINISH_OFF: + + if (true == ret) + *event_start = event_list; + else { + EM_SAFE_FREE(event_list); + *event_start = NULL; + *count = 0; + } + + if (hStmt != NULL) { + rc = sqlite3_finalize(hStmt); + hStmt = NULL; + if (rc != SQLITE_OK) { + EM_DEBUG_EXCEPTION("sqlite3_finalize error [%d]", rc); + error = EMAIL_ERROR_DB_FAILURE; + } + } + + EMSTORAGE_FINISH_READ_TRANSACTION(transaction); + if (err_code != NULL) + *err_code = error; + + EM_DEBUG_FUNC_END("ret [%d]", ret); + return ret; +} + + +INTERNAL_FUNC int emstorage_get_auto_download_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 (!activity_count || !err_code) { + EM_DEBUG_EXCEPTION("activity_count[%p], err_code[%p]", activity_count, err_code); + if (err_code != NULL) + *err_code = EMAIL_ERROR_INVALID_PARAM; + return false; + } + + int rc = -1; + int ret = false; + int error = EMAIL_ERROR_NONE; + DB_STMT hStmt = NULL; + char sql_query_string[QUERY_SIZE] = {0, }; + + sqlite3 *local_db_handle = emstorage_get_db_connection(); + + EMSTORAGE_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_auto_download_activity_tbl;"); + + EM_DEBUG_LOG_DEV(" Query [%s]", sql_query_string); + + + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); + EM_DEBUG_LOG_DEV ("before sqlite3_prepare hStmt = %p", hStmt); + EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF;}, + ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + + + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc); + EM_DEBUG_DB_EXEC((rc != SQLITE_ROW), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF;}, + ("sqlite3_step fail:%d", rc)); + + _get_stmt_field_data_int(hStmt, activity_count, 0); + + EM_DEBUG_LOG("counts of activities in activity table [%d]", *activity_count); + + ret = true; + +FINISH_OFF: + + if (hStmt != NULL) { + rc = sqlite3_finalize(hStmt); + hStmt=NULL; + if (rc != SQLITE_OK) { + EM_DEBUG_EXCEPTION("sqlite3_finalize error [%d]", rc); + error = EMAIL_ERROR_DB_FAILURE; + } + } + + EMSTORAGE_FINISH_READ_TRANSACTION(transaction); + if (err_code != NULL) + *err_code = error; + + EM_DEBUG_FUNC_END("ret [%d]", ret); + return ret; +} + + +INTERNAL_FUNC int emstorage_get_auto_download_account_list(int **account_list, int *count, int transaction, int *err_code) +{ + EM_DEBUG_FUNC_BEGIN("account_list[%p], count[%p] err_code[%p]", account_list, count, err_code); + + if (!account_list || !count) { + EM_DEBUG_EXCEPTION("account_list[%p], count[%p]", account_list, count); + if (err_code != NULL) + *err_code = EMAIL_ERROR_INVALID_PARAM; + return false; + } + + int ret = false; + int error = EMAIL_ERROR_NONE; + char *sql = "SELECT count(distinct account_id) FROM mail_auto_download_activity_tbl"; + 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 = emstorage_get_db_connection(); + + EMSTORAGE_START_READ_TRANSACTION(transaction); + + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql, &result, NULL, NULL, NULL), rc); + EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; }, + ("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 = EMAIL_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_auto_download_activity_tbl"); + + EM_DEBUG_LOG_SEC("Query [%s]", sql_query_string); + + + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); + + EM_DEBUG_LOG("Before sqlite3_prepare hStmt = %p", hStmt); + EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF;}, + ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + + + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc); + EM_DEBUG_DB_EXEC((rc != SQLITE_ROW), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, + ("sqlite3_step fail:%d", rc)); + + if (NULL == (result_account_list = (int *)em_malloc(sizeof(int)*(*count)))) { + EM_DEBUG_EXCEPTION(" em_malloc failed..."); + error = EMAIL_ERROR_OUT_OF_MEMORY; + goto FINISH_OFF; + } + + for (i = 0; i < (*count); i++) { + _get_stmt_field_data_int(hStmt, result_account_list + i, 0); + + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc); + EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_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; + else + EM_SAFE_FREE(result_account_list); + + if (hStmt != NULL) { + rc = sqlite3_finalize(hStmt); + hStmt = NULL; + if (rc != SQLITE_OK) { + EM_DEBUG_EXCEPTION("sqlite3_finalize error [%d]", rc); + error = EMAIL_ERROR_DB_FAILURE; + } + } + + EMSTORAGE_FINISH_READ_TRANSACTION(transaction); + if (err_code != NULL) + *err_code = error; + EM_DEBUG_FUNC_END("ret [%d]", ret); + return ret; +} + + +INTERNAL_FUNC int emstorage_get_auto_download_mailbox_list(int account_id, int **mailbox_list, int *count, int transaction, int *err_code) +{ + EM_DEBUG_FUNC_BEGIN("account_id[%d], mailbox_list[%p], count[%p] err_code[%p]", account_id, mailbox_list, count, err_code); + + if (account_id < FIRST_ACCOUNT_ID || !mailbox_list || !count) { + EM_DEBUG_EXCEPTION("account_id[%d], mailbox_list[%p], count[%p]", account_id, mailbox_list, count); + if (err_code != NULL) + *err_code = EMAIL_ERROR_INVALID_PARAM; + return false; + } + + int ret = false; + int error = EMAIL_ERROR_NONE; + char **result; + int i = 0, rc = -1; + int *mbox_list = NULL; + DB_STMT hStmt = NULL; + char sql_query_string[QUERY_SIZE] = {0, }; + + sqlite3 *local_db_handle = emstorage_get_db_connection(); + + EMSTORAGE_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_id) FROM mail_auto_download_activity_tbl WHERE account_id = %d order by mailbox_id", account_id); + + + EMSTORAGE_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 = EMAIL_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 = EMAIL_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(sql_query_string, sizeof(sql_query_string), "SELECT distinct mailbox_id FROM mail_auto_download_activity_tbl WHERE account_id = %d order by mailbox_id", account_id); + + EM_DEBUG_LOG_SEC(" Query [%s]", sql_query_string); + + + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); + + + EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, + ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + + + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc); + EM_DEBUG_DB_EXEC((rc != SQLITE_ROW), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, + ("sqlite3_step fail:%d", rc)); + + mbox_list = (int *)em_malloc(sizeof(int)*(*count)); /* prevent */ + if (mbox_list == NULL) { + EM_DEBUG_EXCEPTION(" em_malloc failed..."); + error = EMAIL_ERROR_OUT_OF_MEMORY; + goto FINISH_OFF; + } + + for (i = 0; i < (*count); i++) { + _get_stmt_field_data_int(hStmt, mbox_list + i, 0); + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc); + + EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, + ("sqlite3_step fail:%d", rc)); + EM_DEBUG_LOG("mbox_list %d", mbox_list[i]); + } + + ret = true; + +FINISH_OFF: + + if (ret == true) + *mailbox_list = mbox_list; + else + EM_SAFE_FREE(mbox_list); + + if (hStmt != NULL) { + rc = sqlite3_finalize(hStmt); + hStmt = NULL; + if (rc != SQLITE_OK) { + EM_DEBUG_EXCEPTION("sqlite3_finalize error [%d]", rc); + error = EMAIL_ERROR_DB_FAILURE; + } + } + + EMSTORAGE_FINISH_READ_TRANSACTION(transaction); + if (err_code != NULL) + *err_code = error; + EM_DEBUG_FUNC_END("ret [%d]", ret); + return ret; +} + + +INTERNAL_FUNC int emstorage_get_auto_download_activity_count_by_mailbox(int account_id, int input_mailbox_id, int *activity_count, int transaction, int *err_code) +{ + 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 || !activity_count || !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 = EMAIL_ERROR_INVALID_PARAM; + return false; + } + + int rc = -1; + int ret = false; + int error = EMAIL_ERROR_NONE; + char sql_query_string[QUERY_SIZE] = {0, }; + DB_STMT hStmt = NULL; + sqlite3 *local_db_handle = emstorage_get_db_connection(); + + EMSTORAGE_START_READ_TRANSACTION(transaction); + memset(sql_query_string, 0x00, sizeof(sql_query_string)); + SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT count(*) FROM mail_auto_download_activity_tbl WHERE account_id = %d and mailbox_id = '%d'", account_id, input_mailbox_id); + + EM_DEBUG_LOG_SEC(" Query [%s]", sql_query_string); + + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); + EM_DEBUG_LOG("before sqlite3_prepare hStmt = %p", hStmt); + EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, + ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc); + EM_DEBUG_DB_EXEC((rc != SQLITE_ROW), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, + ("sqlite3_step fail:%d", rc)); + + _get_stmt_field_data_int(hStmt, activity_count, 0); + + EM_DEBUG_LOG("count of activities in activity table [%d]", *activity_count); + + ret = true; + +FINISH_OFF: + + if (hStmt != NULL) { + rc = sqlite3_finalize(hStmt); + hStmt=NULL; + if (rc != SQLITE_OK) { + EM_DEBUG_EXCEPTION("sqlite3_finalize error [%d]", rc); + error = EMAIL_ERROR_DB_FAILURE; + } + } + + EMSTORAGE_FINISH_READ_TRANSACTION(transaction); + + if (err_code != NULL) + *err_code = error; + + EM_DEBUG_FUNC_END("ret [%d]", ret); + return ret; +} + + +INTERNAL_FUNC int emstorage_update_auto_download_activity(char *old_server_uid, char *new_server_uid, char *mailbox_name, int mailbox_id, int *err_code) +{ + EM_DEBUG_FUNC_BEGIN_SEC("old_server_uid[%s], new_server_uid[%s], mailbox_id[%d]", old_server_uid, new_server_uid, mailbox_id); + + int rc = -1, ret = false; + int error = EMAIL_ERROR_NONE; + char sql_query_string[QUERY_SIZE] = {0, }; + int transaction = true; + + if (!old_server_uid || !new_server_uid || (!mailbox_name && mailbox_id < 0)) { + EM_DEBUG_EXCEPTION("Invalid parameters"); + error = EMAIL_ERROR_INVALID_PARAM; + return false; + } + + sqlite3 *local_db_handle = emstorage_get_db_connection(); + + EMSTORAGE_START_WRITE_TRANSACTION(transaction, error); + memset(sql_query_string, 0x00, sizeof(sql_query_string)); + + if (mailbox_id > 0) + SNPRINTF(sql_query_string, sizeof(sql_query_string), + "UPDATE mail_auto_download_activity_tbl SET server_mail_id = %s , mailbox_id ='%d' WHERE server_mail_id = %s ", new_server_uid, mailbox_id, old_server_uid); + else if (mailbox_name) + SNPRINTF(sql_query_string, sizeof(sql_query_string), + "UPDATE mail_auto_download_activity_tbl SET server_mail_id = %s WHERE server_mail_id = %s ", new_server_uid, old_server_uid); + + EM_DEBUG_LOG_SEC("Query [%s]", sql_query_string); + error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); + if (error != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; + } + + rc = sqlite3_changes(local_db_handle); + if (rc == 0) { + EM_DEBUG_LOG("No matching found in mail_auto_download_activity_tbl"); + } + + ret = true; + +FINISH_OFF: + + EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error); + + if (err_code != NULL) + *err_code = error; + + EM_DEBUG_FUNC_END("ret [%d]", ret); + return ret; +} + +#endif + +#ifdef __FEATURE_UPDATE_DB_TABLE_SCHEMA__ + +typedef struct { + char *column_name; + char *column_type; +} email_column_info_t; + +static int get_column_information_from_table_callback(void *arg1, int argc, char **argv, char **input_column_name) +{ + EM_DEBUG_FUNC_BEGIN("arg1[%p] argc[%d] argv[%p] column_name[%p]", arg1, argc, argv, input_column_name); + + int i = 0; + int validated = 0; + char *column_name = NULL; + char *column_type = NULL; + GList *new_list = *((GList**)arg1); + email_column_info_t *column_info_item = NULL; + + for (i = 0; i < argc; ++i) { + /* EM_DEBUG_LOG("%s = %s", input_column_name[i], argv[i]); */ + if (EM_SAFE_STRCMP(input_column_name[i], "name") == 0) { + column_name = EM_SAFE_STRDUP(argv[i]); + validated = 1; + } + else if (EM_SAFE_STRCMP(input_column_name[i], "type") == 0) { + column_type = EM_SAFE_STRDUP(argv[i]); + } + } + + if (validated) { + EM_DEBUG_LOG("column_name[%s] column_type[%s]", column_name, column_type); + column_info_item = em_malloc(sizeof(email_column_info_t)); + if (column_info_item == NULL) { + EM_DEBUG_EXCEPTION("em_malloc failed"); + goto FINISH_OFF; + } + + column_info_item->column_name = EM_SAFE_STRDUP(column_name); + column_info_item->column_type = EM_SAFE_STRDUP(column_type); + new_list = g_list_append(new_list, (gpointer)column_info_item); + *((GList**)arg1) = new_list; + } + +FINISH_OFF: + + EM_SAFE_FREE(column_name); + EM_SAFE_FREE(column_type); + + EM_DEBUG_FUNC_END(); + return 0; +} + +static int emstorage_get_column_information_from_table(const char *input_table_name, GList **output_column_info) +{ + EM_DEBUG_FUNC_BEGIN("input_table_name[%p] output_column_info[%p]", input_table_name, output_column_info); + int err = EMAIL_ERROR_NONE; + int result_from_sqlite = 0; + char *error_message_from_sqlite = NULL; + char sql_query_string[QUERY_SIZE] = {0, }; + GList *new_list = NULL; + sqlite3 *local_db_handle = emstorage_get_db_connection(); + + SNPRINTF(sql_query_string, QUERY_SIZE, "pragma table_info(%s);", input_table_name); + + result_from_sqlite = sqlite3_exec(local_db_handle, sql_query_string, get_column_information_from_table_callback, &new_list, &error_message_from_sqlite); + + if (result_from_sqlite != SQLITE_OK) + EM_DEBUG_EXCEPTION("sqlite3_exec returns [%d]", result_from_sqlite); + + EM_DEBUG_LOG("new_list[%p] output_column_info[%p]", new_list, output_column_info); + + if (new_list && output_column_info) { + EM_DEBUG_LOG("g_list_length[%d]", g_list_length(new_list)); + *output_column_info = new_list; + } + + EM_DEBUG_FUNC_END("err [%d]", err); + return err; +} + +static int emstorage_create_renamed_table(char **input_full_query, int input_query_index, char *input_source_table_name, char *input_new_table_name) +{ + EM_DEBUG_FUNC_BEGIN("input_full_query [%p] input_query_index[%d] input_source_table_name[%p] input_new_table_name[%p]", input_full_query, input_query_index, input_source_table_name, input_new_table_name); + int error = EMAIL_ERROR_NONE; + int rc = -1; + sqlite3 *local_db_handle = NULL; + char sql_query_string[QUERY_SIZE] = {0, }; + + if (input_full_query == NULL || input_source_table_name == NULL || input_new_table_name == NULL) { + EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM"); + error = EMAIL_ERROR_INVALID_PARAM; + goto FINISH_OFF; + } + + local_db_handle = emstorage_get_db_connection(); + + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, "BEGIN;", NULL, NULL, NULL), rc); + EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {goto FINISH_OFF; }, ("SQL(BEGIN EXCLUSIVE) exec fail:%d -%s", rc, sqlite3_errmsg(local_db_handle))); + + EM_DEBUG_LOG("[%s] will be replaced by [%s]", input_source_table_name, input_new_table_name); + + EM_SAFE_STRNCPY(sql_query_string, input_full_query[input_query_index], sizeof(sql_query_string)-1); /*prevent 21984*/ + reg_replace(sql_query_string, input_source_table_name, input_new_table_name); + + error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); +FINISH_OFF: + + if (error == EMAIL_ERROR_NONE) { + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, "END;", NULL, NULL, NULL), rc); + } + else { + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, "rollback", NULL, NULL, NULL), rc); + } + + EM_DEBUG_FUNC_END("error [%d]", error); + return error; +} + +static int emstorage_add_column(char *input_table_name, email_column_info_t *input_new_column) +{ + EM_DEBUG_FUNC_BEGIN("input_table_name[%p] input_new_column[%p]", input_table_name, input_new_column); + int error = EMAIL_ERROR_NONE; + int rc = -1; + sqlite3 *local_db_handle = NULL; + char sql_query_string[QUERY_SIZE] = {0, }; + + if (input_table_name == NULL || input_new_column == NULL) { + EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM"); + error = EMAIL_ERROR_INVALID_PARAM; + goto FINISH_OFF; + } + + local_db_handle = emstorage_get_db_connection(); + + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, "BEGIN;", NULL, NULL, NULL), rc); + EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {goto FINISH_OFF; }, ("SQL(BEGIN EXCLUSIVE) exec fail:%d -%s", rc, sqlite3_errmsg(local_db_handle))); + SNPRINTF(sql_query_string, QUERY_SIZE, "ALTER TABLE %s ADD COLUMN %s %s;", input_table_name, input_new_column->column_name, input_new_column->column_type); + error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); +FINISH_OFF: + + if (error == EMAIL_ERROR_NONE) { + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, "END;", NULL, NULL, NULL), rc); + } + else { + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, "rollback", NULL, NULL, NULL), rc); + } + + EM_DEBUG_FUNC_END("error [%d]", error); + return error; +} + +static int emstorage_drop_table(char *input_table_name) +{ + EM_DEBUG_FUNC_BEGIN("input_table_name[%p]", input_table_name); + int error = EMAIL_ERROR_NONE; + int rc = -1; + sqlite3 *local_db_handle = NULL; + char sql_query_string[QUERY_SIZE] = {0, }; + + if (input_table_name == NULL) { + EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM"); + error = EMAIL_ERROR_INVALID_PARAM; + goto FINISH_OFF; + } + + local_db_handle = emstorage_get_db_connection(); + + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, "BEGIN;", NULL, NULL, NULL), rc); + EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {goto FINISH_OFF; }, ("SQL(BEGIN EXCLUSIVE) exec fail:%d -%s", rc, sqlite3_errmsg(local_db_handle))); + SNPRINTF(sql_query_string, QUERY_SIZE, "DROP TABLE %s;", input_table_name); + error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); +FINISH_OFF: + + if (error == EMAIL_ERROR_NONE) { + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, "END;", NULL, NULL, NULL), rc); + } + else { + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, "rollback", NULL, NULL, NULL), rc); + } + + EM_DEBUG_FUNC_END("error [%d]", error); + return error; +} + +gint glist_compare_column_name(gconstpointer old_column_info, gconstpointer new_column_info) +{ + EM_DEBUG_FUNC_BEGIN("old_column_info[%p] new_column_info[%p]", old_column_info, new_column_info); + email_column_info_t *left_one = (email_column_info_t*)old_column_info; + email_column_info_t *right_one = (email_column_info_t*)new_column_info; + + if (old_column_info == NULL || new_column_info == NULL) + return -1; + + return EM_SAFE_STRCMP((char*)left_one->column_name, (char*)right_one->column_name); +} + +INTERNAL_FUNC int emstorage_update_db_table_schema() +{ + EM_DEBUG_FUNC_BEGIN(); + int i = 0; + int j = 0; + int error = EMAIL_ERROR_NONE; + int query_len = 0; + email_column_info_t *new_column_info = NULL; + email_column_info_t *p_column_info = NULL; + char **create_table_query = NULL; + GList *found_data = NULL; + GList *column_list_of_old_table = NULL; + GList *column_list_of_new_table = NULL; + char table_names[CREATE_TABLE_MAX][2][50] = { { "mail_account_tbl", "mail_account_tbl_new" }, + { "mail_box_tbl", "mail_box_tbl_new" }, + { "mail_read_mail_uid_tbl", "mail_read_mail_uid_tbl_new" }, + { "mail_rule_tbl", "mail_rule_tbl_new" }, + { "mail_tbl", "mail_tbl_new" }, + { "mail_attachment_tbl", "mail_attachment_tbl_new" }, +#ifdef __FEATURE_PARTIAL_BODY_DOWNLOAD__ + { "mail_partial_body_activity_tbl", "mail_partial_body_activity_tbl_new" }, +#else + { "", "" }, +#endif + { "mail_meeting_tbl", "mail_meeting_tbl_new" }, +#ifdef __FEATURE_LOCAL_ACTIVITY__ + { "mail_local_activity_tbl", "mail_local_activity_tbl_new" }, +#else + { "", "" }, +#endif + { "mail_certificate_tbl", "mail_certificate_tbl_new" }, + { "mail_task_tbl", "mail_task_tbl_new" }, +#ifdef __FEATURE_BODY_SEARCH__ + { "mail_text_tbl", "mail_text_tbl_new" }, +#else + { "", "" }, +#endif + +#ifdef __FEATURE_WIFI_AUTO_DOWNLOAD__ + { "mail_auto_download_activity_tbl", "mail_auto_download_activity_tbl_new" } +#else + { "", "" } +#endif + + }; + + error = emcore_load_query_from_file(EMAIL_SERVICE_CREATE_TABLE_QUERY_FILE_PATH, &create_table_query, &query_len); + + if (error != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emcore_load_sql_from_file failed [%d]", error); + goto FINISH_OFF; + } + + if (query_len < CREATE_TABLE_MAX) { + EM_DEBUG_EXCEPTION("SQL string array length is difference from CREATE_TABLE_MAX"); + error = EMAIL_ERROR_SYSTEM_FAILURE; + goto FINISH_OFF; + } + + for (i = CREATE_TABLE_MAIL_ACCOUNT_TBL; i < CREATE_TABLE_MAX; i++) { + EM_DEBUG_LOG("table [%s] new_table [%s]", table_names[i][0], table_names[i][1]); + if (EM_SAFE_STRLEN(table_names[i][0]) && EM_SAFE_STRLEN(table_names[i][1])) { + /* Check existing of _new table */ + emstorage_drop_table(table_names[i][1]); + error = emstorage_create_renamed_table(create_table_query, i, table_names[i][0], table_names[i][1]); + if (error != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emstorage_create_renamed_table failed [%d]", error); + goto FINISH_OFF; + } + + emstorage_get_column_information_from_table(table_names[i][0], &column_list_of_old_table); + emstorage_get_column_information_from_table(table_names[i][1], &column_list_of_new_table); + + /* Compare fields and add new field */ + for (j = 0; j < g_list_length(column_list_of_new_table); j++) { + new_column_info = (email_column_info_t*)g_list_nth_data(column_list_of_new_table, j); + found_data = g_list_find_custom(column_list_of_old_table, (gconstpointer)new_column_info, glist_compare_column_name); + if (found_data == NULL) { + /* add new field*/ + emstorage_add_column(table_names[i][0], new_column_info); + } + } + + emstorage_drop_table(table_names[i][1]); + } + else + EM_DEBUG_LOG("Skipped"); + } + +FINISH_OFF: + if (create_table_query) { + int i = 0; + for (i = 0; i < query_len; i++) { + if (create_table_query[i]) { + EM_SAFE_FREE(create_table_query[i]); + } + } + EM_SAFE_FREE(create_table_query); + } + + found_data = g_list_first(column_list_of_old_table); + while(found_data != NULL) { + p_column_info = (email_column_info_t *)found_data->data; + EM_SAFE_FREE(p_column_info->column_name); + EM_SAFE_FREE(p_column_info->column_type); + EM_SAFE_FREE(p_column_info); + + found_data = g_list_next(found_data); + } + g_list_free(column_list_of_old_table); + + found_data = g_list_first(column_list_of_new_table); + while(found_data != NULL) { + p_column_info = (email_column_info_t *)found_data->data; + EM_SAFE_FREE(p_column_info->column_name); + EM_SAFE_FREE(p_column_info->column_type); + EM_SAFE_FREE(p_column_info); + + found_data = g_list_next(found_data); + } + g_list_free(column_list_of_new_table); + + EM_DEBUG_FUNC_END("error [%d]", error); + return error; +} + + +#endif /* __FEATURE_UPDATE_DB_TABLE_SCHEMA__ */ + /*EOF*/ diff --git a/email-core/email-storage/include/email-storage.h b/email-core/email-storage/include/email-storage.h index 7b4b313..679f537 100755 --- a/email-core/email-storage/include/email-storage.h +++ b/email-core/email-storage/include/email-storage.h @@ -4,7 +4,7 @@ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> -* +* * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -24,9 +24,9 @@ * File : email-storage.h * Desc : email-core Storage Library Header * - * Auth : + * Auth : * - * History : + * History : * 2006.07.28 : created *****************************************************************************/ #ifndef __EMAIL_STORAGE_H__ @@ -42,16 +42,20 @@ extern "C" #include "email-types.h" #include "email-core-tasks.h" #include "email-internal-types.h" +#ifdef __FEATURE_WIFI_AUTO_DOWNLOAD__ +#include "email-core-auto-download.h" +#endif #define FIRST_ACCOUNT_ID 1 -#define EMAIL_SERVICE_CREATE_TABLE_QUERY_FILE_PATH "/opt/usr/data/email/res/email-service.sql" +#define EMAIL_SERVICE_CREATE_TABLE_QUERY_FILE_PATH "/usr/share/email-service/email-service.sql" #ifdef __FEATURE_BULK_DELETE_MOVE_UPDATE_REQUEST_OPTI__ #define QUERY_SIZE 8192 #define MAX_INTEGER_LENGTH 5 /* 32767 -> 5 bytes */ +#define FILE_MAX_BUFFER_SIZE 16 * 1024 /* 16 Kbyte */ -typedef struct +typedef struct { int mail_id; unsigned long server_mail_id; @@ -60,7 +64,7 @@ typedef struct #endif /* __FEATURE_BULK_DELETE_MOVE_UPDATE_REQUEST_OPTI__ */ -typedef struct +typedef struct { /* Account information */ int account_id; /* Account id */ @@ -71,6 +75,7 @@ typedef struct int sync_disabled; /* If this attriube is set as true, email-service will not synchronize this account. */ int default_mail_slot_size; email_roaming_option_t roaming_option; /* roaming option */ + int color_label; /* Account color label */ void *user_data; /* binary user data */ int user_data_length; /* user data length */ @@ -113,6 +118,9 @@ typedef struct int auto_resend_times; /* Auto retry count for sending a email */ int outgoing_server_size_limit; /* Mail size limitation for SMTP sending*/ + /* Auto download */ + int wifi_auto_download; /* auto attachment download in wifi connection */ + /* Authentication Options */ int pop_before_smtp; /* POP before SMTP Authentication */ int incoming_server_requires_apop; /* APOP authentication */ @@ -125,7 +133,7 @@ typedef struct email_digest_type digest_type; /* Sepeifies the digest algorithm*/ } emstorage_account_tbl_t; -typedef struct +typedef struct { int certificate_id; int issue_year; @@ -141,7 +149,7 @@ typedef struct char *password; } emstorage_certificate_tbl_t; -typedef struct +typedef struct { int account_id; /* MUST BE '0' : currently, only global rule supported. */ int rule_id; @@ -156,7 +164,7 @@ typedef struct } emstorage_rule_tbl_t; /* mail_box_tbl table entity */ -typedef struct +typedef struct { int mailbox_id; int account_id; @@ -178,7 +186,7 @@ typedef struct } emstorage_mailbox_tbl_t; /* mail_read_uid_tbl table entity */ -typedef struct +typedef struct { int account_id; int mailbox_id; @@ -201,7 +209,7 @@ typedef struct } emstorage_mail_text_tbl_t; #endif -typedef struct +typedef struct { int mail_id; int account_id; @@ -255,16 +263,19 @@ typedef struct int tag_id; time_t replied_time; time_t forwarded_time; + char *default_charset; int eas_data_length; char *eas_data; + char *pgp_password; } emstorage_mail_tbl_t; /* mail_attachment_tbl entity */ -typedef struct +typedef struct { int attachment_id; char *attachment_name; char *attachment_path; + char *content_id; int attachment_size; int mail_id; int account_id; @@ -274,10 +285,10 @@ typedef struct int attachment_drm_method; /* 0 : none, 1 : FL, 2 : CD, 3 : SSD, 4 : SD */ int attachment_inline_content_status; /* 1 : inline content , 0 : not inline content */ char *attachment_mime_type; -#ifdef __ATTACHMENT_OPTI__ +#ifdef __ATTACHMENT_OPTI__ int encoding; - char *section; -#endif + char *section; +#endif } emstorage_attachment_tbl_t; @@ -299,8 +310,8 @@ typedef struct _emstorage_search_filter_t { } emstorage_search_filter_t; typedef enum { - EMAIL_CREATE_DB_NORMAL = 0, - EMAIL_CREATE_DB_CHECK, + EMAIL_CREATE_DB_NORMAL = 0, + EMAIL_CREATE_DB_CHECK, } emstorage_create_db_type_t; @@ -314,8 +325,8 @@ typedef enum { typedef enum { ACTIVITY_FETCHIMAPFOLDER = 1, /* Fetch Mail server Activity */ - ACTIVITY_DELETEMAIL, /* Delete Mail Activity */ - ACTIVITY_MODIFYFLAG, /* Modify Mail flag 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 */ @@ -336,7 +347,7 @@ typedef struct 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 *src_mbox; /* Source Mailbox in case of mail_move */ char *dest_mbox; /* Destination Mailbox name in case of Mail move operation */ } emstorage_activity_tbl_t; @@ -356,9 +367,9 @@ INTERNAL_FUNC int em_db_open(sqlite3 **sqlite_handle, int *err_code); /* * emstorage_db_open * - * description : open db and set global variable sqlite_emmb - * arguments : - * return : + * description : open db and set global variable sqlite_emmb + * arguments : + * return : */ INTERNAL_FUNC sqlite3* emstorage_db_open(int *err_code); @@ -366,8 +377,8 @@ INTERNAL_FUNC sqlite3* emstorage_db_open(int *err_code); * emstorage_db_close * * description : close db with global variable sqlite_emmb - * arguments : - * return : + * arguments : + * return : */ INTERNAL_FUNC int emstorage_db_close(int *err_code); @@ -375,8 +386,8 @@ INTERNAL_FUNC int emstorage_db_close(int *err_code); * emstorage_open * * description : initialize storage manager - * arguments : - * return : + * arguments : + * return : */ INTERNAL_FUNC int emstorage_open(int *err_code); @@ -384,8 +395,8 @@ INTERNAL_FUNC int emstorage_open(int *err_code); * emstorage_close * * description : cleanup storage manager - * arguments : - * return : + * arguments : + * return : */ INTERNAL_FUNC int emstorage_close(int *err_code); @@ -393,8 +404,8 @@ INTERNAL_FUNC int emstorage_close(int *err_code); * emstorage_create_table * * description : create account/address table in database. - * arguments : - * return : + * arguments : + * return : */ INTERNAL_FUNC int emstorage_create_table(emstorage_create_db_type_t type, int *err_code); @@ -404,11 +415,11 @@ INTERNAL_FUNC int emstorage_initialize_field_count(); /** * Check whether there is the same account information in the db * - * @param[in] account account that + * @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 + * @return This function returns true if there is no duplicated account. returns false and set error code if there are duplicated accounts or error */ INTERNAL_FUNC int emstorage_check_duplicated_account(email_account_t *account, int transaction, int *err_code); @@ -439,13 +450,13 @@ INTERNAL_FUNC int emstorage_get_account_list(int *select_num, emstorage_account_ * emstorage_get_account_by_name * * description : get account from account table by account name - * arguments : + * 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 : + * return : */ /* sowmya.kr, 281209 Adding signature to options in email_account_t changes */ @@ -470,10 +481,10 @@ INTERNAL_FUNC int emstorage_update_account_password(int input_account_id, char * * emstorage_update_account * * description : change a account from account table - * arguments : + * arguments : * account_id : account id * account : buffer to hold selected account - * return : + * return : */ INTERNAL_FUNC int emstorage_update_account(int account_id, emstorage_account_tbl_t *account, int transaction, int *err_code); @@ -484,10 +495,10 @@ INTERNAL_FUNC int emstorage_set_field_of_accounts_with_integer_value(int account * emstorage_get_sync_status_of_account * * description : get a sync status field from account table - * arguments : + * arguments : * account_id : account id * result_sync_status : sync status value - * return : + * return : */ INTERNAL_FUNC int emstorage_get_sync_status_of_account(int account_id, int *result_sync_status,int *err_code); @@ -496,11 +507,11 @@ INTERNAL_FUNC int emstorage_get_sync_status_of_account(int account_id, int *resu * emstorage_update_sync_status_of_account * * description : update a sync status field from account table - * arguments : + * arguments : * account_id : account id * set_operator : set operater. refer email_set_type_t * sync_status : sync status value - * return : + * return : */ INTERNAL_FUNC int emstorage_update_sync_status_of_account(int account_id, email_set_type_t set_operator, int sync_status, int transaction, int *err_code); @@ -509,8 +520,8 @@ INTERNAL_FUNC int emstorage_update_sync_status_of_account(int account_id, email_ * emstorage_add_account * * description : add a account to account table - * arguments : - * return : + * arguments : + * return : */ INTERNAL_FUNC int emstorage_add_account(emstorage_account_tbl_t *account, int transaction, int *err_code); @@ -518,10 +529,10 @@ INTERNAL_FUNC int emstorage_add_account(emstorage_account_tbl_t *account, int tr * emstorage_delete_account * * description : delete a account from account table - * arguments : + * arguments : * db : database pointer * account_id : account id to be deteted - * return : + * return : */ INTERNAL_FUNC int emstorage_delete_account(int account_id, int transaction, int *err_code); @@ -529,10 +540,10 @@ INTERNAL_FUNC int emstorage_delete_account(int account_id, int transaction, int * emstorage_free_account * * description : free local accout memory - * arguments : + * arguments : * account_list : double pointer * count : count of local account - * return : + * return : */ INTERNAL_FUNC int emstorage_free_account(emstorage_account_tbl_t **account_list, int count, int *err_code); @@ -543,10 +554,10 @@ INTERNAL_FUNC int emstorage_free_account(emstorage_account_tbl_t **account_list, * emstorage_get_mailbox_count * * description : get number of mailbox from local mailbox table - * arguments : + * arguments : * db : database pointer * count : number of accounts - * return : + * return : */ INTERNAL_FUNC int emstorage_get_mailbox_count(int account_id, int local_yn, int *count, int transaction, int *err_code); @@ -554,27 +565,27 @@ INTERNAL_FUNC int emstorage_get_mailbox_count(int account_id, int local_yn, int * emstorage_get_mailbox * * description : get local mailbox from local mailbox table - * arguments : + * 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 : + * return : */ INTERNAL_FUNC int emstorage_get_mailbox_list(int account_id, int local_yn, email_mailbox_sort_type_t sort_type, int *select_num, emstorage_mailbox_tbl_t **mailbox_list, int transaction, int *err_code); /* * emstorage_get_child_mailbox_list * - * description : get child mailbox list from given mailbox - * arguments : + * 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 + * mailbox_list - out : list of mailboxes * err_code - out : error code, if any */ @@ -585,12 +596,12 @@ INTERNAL_FUNC int emstorage_get_child_mailbox_list(int account_id, char *parent_ * emstorage_get_mailbox_by_name * * description : get local mailbox from local mailbox table by mailbox name - * arguments : + * 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 : + * return : */ INTERNAL_FUNC int emstorage_get_mailbox_by_name(int account_id, int local_yn, char *mailbox_name, emstorage_mailbox_tbl_t **mailbox, int transaction, int *err_code); INTERNAL_FUNC int emstorage_get_mailbox_by_mailbox_type(int account_id, email_mailbox_type_e mailbox_type, emstorage_mailbox_tbl_t **mailbox, int transaction, int *err_code); @@ -607,11 +618,11 @@ INTERNAL_FUNC int emstorage_update_mailbox_total_count(int account_id, int input * emstorage_update_mailbox * * description : change a account from account table - * arguments : + * arguments : * db : database pointer * mailbox_name : mailbox name * mailbox : buffer to hold selected local mailbox - * return : + * return : */ INTERNAL_FUNC int emstorage_update_mailbox(int account_id, int local_yn, int input_mailbox_id, emstorage_mailbox_tbl_t *mailbox, int transaction, int *err_code); @@ -619,8 +630,8 @@ INTERNAL_FUNC int emstorage_update_mailbox(int account_id, int local_yn, int inp * emstorage_update_mailbox_type * * description : change a mailbox from mailbox tbl - * arguments : - * return : + * arguments : + * return : */ INTERNAL_FUNC int emstorage_update_mailbox_type(int account_id, int local_yn, int input_mailbox_id, email_mailbox_type_e new_mailbox_type, int transaction, int *err_code); @@ -639,8 +650,8 @@ INTERNAL_FUNC int emstorage_set_field_of_mailbox_with_integer_value(int input_ac * emstorage_add_mailbox * * description : add a local mailbox to local mailbox table - * arguments : - * return : + * arguments : + * return : */ INTERNAL_FUNC int emstorage_add_mailbox(emstorage_mailbox_tbl_t *mailbox, int transaction, int *err_code); @@ -648,15 +659,15 @@ INTERNAL_FUNC int emstorage_add_mailbox(emstorage_mailbox_tbl_t *mailbox, int tr * emstorage_delete_mailbox * * description : delete a local mailbox from local mailbox table - * arguments : + * arguments : * db : database pointer * mailbox_name : mailbox name of record to be deteted - * return : + * return : */ INTERNAL_FUNC int emstorage_delete_mailbox(int account_id, int local_yn, int input_mailbox_id, int transaction, int *err_code); INTERNAL_FUNC int emstorage_rename_mailbox(int input_mailbox_id, char *input_new_mailbox_name, char *input_new_mailbox_alias, void *input_eas_data, int input_eas_data_length, int input_transaction); -INTERNAL_FUNC int emstorage_get_overflowed_mail_id_list(int account_id, int input_mailbox_id, int mail_slot_size, int **mail_id_list, int *mail_id_count, int transaction, int *err_code); +INTERNAL_FUNC int emstorage_get_overflowed_mail_id_list(int account_id, int input_mailbox_id, int input_mailbox_type, int mail_slot_size, int **mail_id_list, int *mail_id_count, int transaction, int *err_code); INTERNAL_FUNC int emstorage_set_mail_slot_size(int account_id, int mailbox_id, int new_slot_size, int transaction, int *err_code); INTERNAL_FUNC int emstorage_set_all_mailbox_modifiable_yn(int account_id, int modifiable_yn, int transaction, int *err_code); @@ -667,10 +678,10 @@ INTERNAL_FUNC int emstorage_stamp_last_sync_time_of_mailbox(int input_mailbox_id * emstorage_free_mailbox * * description : free local mailbox memory - * arguments : + * arguments : * mailbox_list : double pointer * count : count of local mailbox - * return : + * return : */ INTERNAL_FUNC int emstorage_free_mailbox(emstorage_mailbox_tbl_t **mailbox_list, int count, int *err_code); @@ -686,12 +697,12 @@ INTERNAL_FUNC int emstorage_get_count_read_mail_uid(int account_id, char *mailbo * emstorage_check_read_mail_uid * * description : check that this uid exists in uid table - * arguments : + * arguments : * db : database pointer * mailbox_name : mailbox name * uid : uid string to be checked * exist : variable to hold checking result. (0 : not exist, 1 : exist) - * return : + * return : */ INTERNAL_FUNC int emstorage_check_read_mail_uid(int account_id, char *mailbox_name, char *uid, int *exist, int transaction, int *err_code); @@ -699,14 +710,14 @@ INTERNAL_FUNC int emstorage_check_read_mail_uid(int account_id, char *mailbox_na * emstorage_get_read_mail_size * * description : get mail size from read mail uid - * arguments : + * arguments : * db : database pointer * mailbox_id : local mailbox id * 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 : + * return : */ INTERNAL_FUNC int emstorage_get_downloaded_list(int account_id, int mailbox_id, emstorage_read_mail_uid_tbl_t **read_mail_uid, int *count, int transaction, int *err_code); @@ -716,12 +727,12 @@ INTERNAL_FUNC int emstorage_get_downloaded_mail(int mail_id, emstorage_mail_tbl_ * emstorage_get_read_mail_size * * description : get mail size from read mail uid - * arguments : + * arguments : * db : database pointer * mailbox_name : mailbox name * s_uid : mail uid string * size : variable to hold mail size - * return : + * return : */ INTERNAL_FUNC int emstorage_get_downloaded_mail_size(int account_id, char *local_mbox, int local_uid, char *mailbox_name, char *uid, int *mail_size, int transaction, int *err_code); @@ -729,8 +740,8 @@ INTERNAL_FUNC int emstorage_get_downloaded_mail_size(int account_id, char *local * emstorage_add_downloaded_mail * * description : add read mail uid - * arguments : - * return : + * arguments : + * return : */ INTERNAL_FUNC int emstorage_add_downloaded_mail(emstorage_read_mail_uid_tbl_t *read_mail_uid, int transaction, int *err_code); @@ -749,8 +760,8 @@ INTERNAL_FUNC int emstorage_add_mail_text(emstorage_mail_text_tbl_t* mail_text, * emstorage_change_read_mail_uid * * description : modify read mail uid - * arguments : - * return : + * arguments : + * return : */ INTERNAL_FUNC int emstorage_change_read_mail_uid(int account_id, int local_mailbox_id, int local_uid, char *mailbox_name, char *uid, emstorage_read_mail_uid_tbl_t *read_mail_uid, int transaction, int *err_code); @@ -758,9 +769,9 @@ INTERNAL_FUNC int emstorage_change_read_mail_uid(int account_id, int local_mailb /* * emstorage_remove_downloaded_mail * - * description : - * arguments : - * return : + * description : + * arguments : + * return : */ INTERNAL_FUNC int emstorage_remove_downloaded_mail(int account_id, char *mailbox_name, char *uid, int transaction, int *err_code); @@ -780,10 +791,10 @@ INTERNAL_FUNC int emstorage_free_read_mail_uid(emstorage_read_mail_uid_tbl_t **r * emstorage_get_rule_count_by_account_id * * description : get number of rules from rule table - * arguments : + * arguments : * db : database pointer * count : number of accounts - * return : + * return : */ INTERNAL_FUNC int emstorage_get_rule_count_by_account_id(int account_id, int *count, int transaction, int *err_code); @@ -791,13 +802,13 @@ INTERNAL_FUNC int emstorage_get_rule_count_by_account_id(int account_id, int *co * emstorage_get_rule * * description : get rules from rule table - * arguments : + * 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 : + * is_completed : is completed ? + * return : */ INTERNAL_FUNC int emstorage_get_rule(int account_id, int type, int start_idx, int *select_num, int *is_completed, emstorage_rule_tbl_t **rule_list, int transaction, int *err_code); @@ -805,8 +816,8 @@ INTERNAL_FUNC int emstorage_get_rule(int account_id, int type, int start_idx, in * emstorage_get_rule * * description : get rules from rule table - * arguments : - * return : + * arguments : + * return : */ INTERNAL_FUNC int emstorage_get_rule_by_id(int rule_id, emstorage_rule_tbl_t **rule, int transaction, int *err_code); @@ -814,11 +825,11 @@ INTERNAL_FUNC int emstorage_get_rule_by_id(int rule_id, emstorage_rule_tbl_t **r * emstorage_change_rule * * description : change a account from account table - * arguments : + * arguments : * db : database pointer * mailbox_name : mailbox name * rule : buffer to hold selected rule - * return : + * return : */ INTERNAL_FUNC int emstorage_change_rule(int rule_id, emstorage_rule_tbl_t *rule, int transaction, int *err_code); @@ -826,8 +837,8 @@ INTERNAL_FUNC int emstorage_change_rule(int rule_id, emstorage_rule_tbl_t *rule, * emstorage_find_rule * * description : find a rule already exists - * arguments : - * return : + * arguments : + * return : */ INTERNAL_FUNC int emstorage_find_rule(emstorage_rule_tbl_t *rule, int transaction, int *err_code); @@ -835,8 +846,8 @@ INTERNAL_FUNC int emstorage_find_rule(emstorage_rule_tbl_t *rule, int transactio * emstorage_add_rule * * description : add a rule to rule table - * arguments : - * return : + * arguments : + * return : */ INTERNAL_FUNC int emstorage_add_rule(emstorage_rule_tbl_t *rule, int transaction, int *err_code); @@ -844,10 +855,10 @@ INTERNAL_FUNC int emstorage_add_rule(emstorage_rule_tbl_t *rule, int transaction * emstorage_delete_rule * * description : delete a rule from rule table - * arguments : + * arguments : * db : database pointer * rule : rule to be deteted - * return : + * return : */ INTERNAL_FUNC int emstorage_delete_rule(int rule_id, int transaction, int *err_code); @@ -855,9 +866,9 @@ INTERNAL_FUNC int emstorage_delete_rule(int rule_id, int transaction, int *err_c * emstorage_free_rule * * description : free rule memory - * arguments : + * arguments : * count : count of rule - * return : + * return : */ INTERNAL_FUNC int emstorage_free_rule(emstorage_rule_tbl_t **rule_list, int count, int *err_code); @@ -868,10 +879,10 @@ INTERNAL_FUNC int emstorage_free_rule(emstorage_rule_tbl_t **rule_list, int coun * emstorage_get_mail_count * * description : get mail total and unseen count from mail table - * arguments : + * arguments : * total : total count * unseen : unseen mail count - * return : + * return : */ INTERNAL_FUNC int emstorage_get_mail_count(int account_id, int mailbox_id, int *total, int *unseen, int transaction, int *err_code); @@ -879,10 +890,10 @@ INTERNAL_FUNC int emstorage_get_mail_count(int account_id, int mailbox_id, int * * emstorage_get_mail_by_id * * description : get mail from mail table by mail id - * arguments : + * arguments : * mail_id : mail id * mail : double pointer to hold mail - * return : + * return : */ INTERNAL_FUNC int emstorage_get_mail_by_id(int mail_id, emstorage_mail_tbl_t **mail, int transaction, int *err_code); @@ -903,27 +914,27 @@ INTERNAL_FUNC int emstorage_get_mail_text_by_id(int mail_id, emstorage_mail_text * emstorage_get_mail * * description : get mail from mail table by mail sequence - * arguments : + * arguments : * account_id : account id * mailbox : mailbox name * mail_no : mail sequence number (not mail id) * mail : double pointer to hold mail - * return : + * return : */ INTERNAL_FUNC int emstorage_get_mail_field_by_id(int mail_id, int type, emstorage_mail_tbl_t **mail, int transaction, int *err_code); /* * emstorage_get_mail_field_by_multiple_mail_id * - * description : - * arguments : - * mail_ids : - * number_of_mails : - * type : - * mail : + * description : + * arguments : + * mail_ids : + * number_of_mails : + * type : + * mail : * transaction : * err_code : - * return : + * return : */ INTERNAL_FUNC int emstorage_get_mail_field_by_multiple_mail_id(int mail_ids[], int number_of_mails, int type, emstorage_mail_tbl_t** mail, int transaction, int *err_code); @@ -987,7 +998,8 @@ INTERNAL_FUNC int emstorage_get_mail_list(int account_id, int mailbox_id, email_ INTERNAL_FUNC int emstorage_get_mails(int account_id, int mailbox_id, email_email_address_list_t* addr_list, int thread_id, int start_index, int limit_count, email_sort_type_t sorting, int transaction, emstorage_mail_tbl_t** mail_list, int *result_count, int *err_code); INTERNAL_FUNC int emstorage_get_searched_mail_list(int account_id, int mailbox_id, int thread_id, int search_type, const char *search_value, int start_index, int limit_count, email_sort_type_t sorting, int transaction, email_mail_list_item_t **mail_list, int *result_count, int *err_code); INTERNAL_FUNC int emstorage_get_maildata_by_servermailid(int account_id, char *server_mail_id, emstorage_mail_tbl_t **mail, int transaction, int *err_code); -INTERNAL_FUNC int emstorage_get_latest_unread_mailid(int account_id, int *mail_id, int *err_code); +INTERNAL_FUNC int emstorage_get_unread_mailid(int account_id, int vip_mode, int **mail_ids, int *mail_number, int *err_code); +INTERNAL_FUNC int emstorage_update_save_status(int account_id, int *err_code); /** @@ -995,23 +1007,23 @@ INTERNAL_FUNC int emstorage_get_latest_unread_mailid(int account_id, int *mail_i * * @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] mailbox_id Specifies the mailbox ID. 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. */ -INTERNAL_FUNC int emstorage_mail_search_start(emstorage_search_filter_t *search, int account_id, char *mailbox, int sorting, int *search_handle, int *searched, int transaction, int *err_code); +INTERNAL_FUNC int emstorage_mail_search_start(emstorage_search_filter_t *search, int account_id, int mailbox_id, int sorting, int *search_handle, int *searched, int transaction, int *err_code); /* * emstorage_mail_search_result * * description : retrieve mail as searching result - * arguments : + * arguments : * search_handle : handle to been gotten from emstorage_mail_search_start * mail : double pointer to hold mail - * return : + * return : */ INTERNAL_FUNC int emstorage_mail_search_result(int search_handle, emstorage_mail_field_type_t type, void **data, int transaction, int *err_code); @@ -1019,9 +1031,9 @@ INTERNAL_FUNC int emstorage_mail_search_result(int search_handle, emstorage_mail * emstorage_mail_search_end * * description : finish searching - * arguments : + * arguments : * search_handle : handle to be finished - * return : + * return : */ INTERNAL_FUNC int emstorage_mail_search_end(int search_handle, int transaction, int *err_code); @@ -1031,13 +1043,13 @@ INTERNAL_FUNC int emstorage_mail_search_end(int search_handle, int transaction, * emstorage_set_field_of_mails_with_integer_value * * description : update a filed of mail - * arguments : - * account_id : Specifies the account id. + * 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 : + * return : */ INTERNAL_FUNC int emstorage_set_field_of_mails_with_integer_value(int account_id, int mail_ids[], int mail_ids_count, char *field_name, int value, int transaction, int *err_code); @@ -1058,11 +1070,11 @@ INTERNAL_FUNC int emstorage_change_mail_text_field(int mail_id, emstorage_mail_t * emstorage_change_mail_field * * description : update partial mail data - * arguments : + * arguments : * mail_id : mail id * type : changing type * mail : mail pointer - * return : + * return : */ INTERNAL_FUNC int emstorage_change_mail_field(int mail_id, email_mail_change_type_t type, emstorage_mail_tbl_t *mail, int transaction, int *err_code); @@ -1070,19 +1082,19 @@ INTERNAL_FUNC int emstorage_change_mail_field(int mail_id, email_mail_change_typ * emstorage_increase_mail_id * * description : increase unique mail id - * arguments : + * arguments : * mail_id : pointer to store the unique id - * return : + * return : */ /* * emstorage_change_mail * * description : update mail - * arguments : + * arguments : * mail_id : mail id to be changed * mail : mail pointer - * return : + * return : */ INTERNAL_FUNC int emstorage_change_mail(int mail_id, emstorage_mail_tbl_t *mail, int transaction, int *err_code); INTERNAL_FUNC int emstorage_clean_save_status(int save_status, int *err_code); @@ -1094,10 +1106,10 @@ INTERNAL_FUNC int emstorage_increase_mail_id(int *mail_id, int transaction, int * emstorage_add_mail * * description : add a mail to mail table - * arguments : + * arguments : * mail : mail pointer to be inserted * get_id : must get uinque id in function - * return : + * return : */ INTERNAL_FUNC int emstorage_add_mail(emstorage_mail_tbl_t *mail, int get_id, int transaction, int *err_code); @@ -1105,14 +1117,14 @@ INTERNAL_FUNC int emstorage_add_mail(emstorage_mail_tbl_t *mail, int get_id, int * emstorage_move_multiple_mails_on_db * * description : - * arguments : - * account_id : + * arguments : + * account_id : * input_mailbox_id : * mail_ids : * number_of_mails : * transaction : * err_code : - * return : + * return : */ INTERNAL_FUNC int emstorage_move_multiple_mails_on_db(int account_id, int input_mailbox_id, int mail_ids[], int number_of_mails, int transaction, int *err_code); @@ -1120,10 +1132,10 @@ INTERNAL_FUNC int emstorage_move_multiple_mails_on_db(int account_id, int input_ * emstorage_delete_mail * * description : delete mail from mail table - * arguments : + * arguments : * mail_id : mail id to be deleted. if 0, all mail will be deleted. * from_server : delete mail on server. - * return : + * return : */ INTERNAL_FUNC int emstorage_delete_mail(int mail_id, int from_server, int transaction, int *err_code); @@ -1131,33 +1143,32 @@ INTERNAL_FUNC int emstorage_delete_mail(int mail_id, int from_server, int transa * emstorage_delete_mail_by_account * * description : delete mail from mail table by account id - * arguments : + * arguments : * account_id : account id. - * return : + * return : */ INTERNAL_FUNC int emstorage_delete_mail_by_account(int account_id, int transaction, int *err_code); /* - * emstorage_delete_mail + * emstorage_delete_mail_by_mailbox * * description : delete mail from mail table - * arguments : - * account_id : account id. - * mailbox : mail box - * return : + * arguments : + * mailbox : mailbox + * return : */ -INTERNAL_FUNC int emstorage_delete_mail_by_mailbox(int account_id, int mailbox_id, int transaction, int *err_code); +INTERNAL_FUNC int emstorage_delete_mail_by_mailbox(emstorage_mailbox_tbl_t *mailbox, int transaction, int *err_code); /* * emstorage_delete_multiple_mails * - * description : - * arguments : + * description : + * arguments : * mail_ids : * number_of_mails : * transaction : * err_code : - * return : + * return : */ INTERNAL_FUNC int emstorage_delete_multiple_mails(int mail_ids[], int number_of_mails, int transaction, int *err_code); @@ -1165,10 +1176,10 @@ INTERNAL_FUNC int emstorage_delete_multiple_mails(int mail_ids[], int number_of_ * emstorage_free_mail * * description : free memory - * arguments : + * arguments : * mail_list : mail array * count : the number of array element - * return : + * return : */ INTERNAL_FUNC int emstorage_free_mail(emstorage_mail_tbl_t **mail_list, int count, int *err_code); @@ -1189,11 +1200,11 @@ INTERNAL_FUNC void emstorage_free_mail_text(emstorage_mail_text_tbl_t** mail_tex * emstorage_get_attachment * * description : get attachment from attachment table - * arguments : + * arguments : * mail_id : mail id * no : attachment sequence * attachment : double pointer to hold attachment data - * return : + * return : */ INTERNAL_FUNC int emstorage_get_attachment_count(int mail_id, int *count, int transaction, int *err_code); @@ -1201,13 +1212,13 @@ INTERNAL_FUNC int emstorage_get_attachment_count(int mail_id, int *count, int tr * emstorage_get_attachment_list * * description : get attachment list from attachment table - * arguments : + * arguments : * input_mail_id : mail id * input_transaction : transaction option * attachment_list : result attachment list * output_attachment_count : result attachment count * return : This function returns EMAIL_ERROR_NONE on success or error code (refer to EMAIL_ERROR__XXX) on failure. - * + * */ INTERNAL_FUNC int emstorage_get_attachment_list(int input_mail_id, int input_transaction, emstorage_attachment_tbl_t** output_attachment_list, int *output_attachment_count); @@ -1216,10 +1227,10 @@ INTERNAL_FUNC int emstorage_get_attachment_list(int input_mail_id, int input_tra * emstorage_get_attachment * * description : get attachment from attachment table - * arguments : + * arguments : * attachment_id : attachment id * attachment : double pointer to hold attachment data - * return : + * return : */ INTERNAL_FUNC int emstorage_get_attachment(int attachment_id, emstorage_attachment_tbl_t **attachment, int transaction, int *err_code); @@ -1227,23 +1238,34 @@ INTERNAL_FUNC int emstorage_get_attachment(int attachment_id, emstorage_attachme * emstorage_get_attachment * * description : get nth-attachment from attachment table - * arguments : + * arguments : * mail_id : mail id * nth : index of the desired attachment (min : 1) * attachment : double pointer to hold attachment data - * return : + * return : */ INTERNAL_FUNC int emstorage_get_attachment_nth(int mail_id, int nth, emstorage_attachment_tbl_t **attachment, int transaction, int *err_code); /* + * emstorage_get_attachment + * + * description : get attachment from attachment table + * arguments : + * attachment_path : attachment path + * attachment : double pointer to hold attachment data + * return : + */ +INTERNAL_FUNC int emstorage_get_attachment_by_attachment_path(char *attachment_path, emstorage_attachment_tbl_t **attachment, int transaction, int *err_code); + +/* * emstorage_change_attachment_field * * description : update partial mail attachment data - * arguments : + * arguments : * mail_id : mail id * type : changing type * mail : mail pointer - * return : + * return : */ INTERNAL_FUNC int emstorage_change_attachment_field(int mail_id, email_mail_change_type_t type, emstorage_attachment_tbl_t *attachment, int transaction, int *err_code); @@ -1252,9 +1274,9 @@ INTERNAL_FUNC int emstorage_change_attachment_field(int mail_id, email_mail_chan * emstorage_get_new_attachment_no * * description : Get new attachment id - * arguments : + * arguments : * attachment_no : attachment id pointer - * return : + * return : */ INTERNAL_FUNC int emstorage_get_new_attachment_no(int *attachment_no, int *err_code); @@ -1264,9 +1286,9 @@ INTERNAL_FUNC int emstorage_get_new_attachment_no(int *attachment_no, int *err_c * emstorage_add_attachment * * description : insert a attachment to attachment table - * arguments : + * arguments : * attachment : attachment pointer - * return : + * return : */ INTERNAL_FUNC int emstorage_add_attachment(emstorage_attachment_tbl_t *attachment, int iscopy, int transaction, int *err_code); @@ -1278,9 +1300,9 @@ INTERNAL_FUNC int emstorage_update_attachment(emstorage_attachment_tbl_t *attach * emstorage_delete_attachment_on_db * * description : delete attachment from attachment table - * arguments : + * arguments : * attachment_id : attachment id - * return : + * return : */ INTERNAL_FUNC int emstorage_delete_attachment_on_db(int attachment_id, int transaction, int *err_code); @@ -1290,10 +1312,10 @@ INTERNAL_FUNC int emstorage_delete_all_attachments_of_mail(int mail_id, int tran * emstorage_delete_attachment_all_on_db * * description : delete attachment from mail table - * arguments : + * arguments : * account_id : account id. * mailbox : mail box - * return : + * return : */ INTERNAL_FUNC int emstorage_delete_attachment_all_on_db(int account_id, char *mailbox, int transaction, int *err_code); @@ -1301,10 +1323,10 @@ INTERNAL_FUNC int emstorage_delete_attachment_all_on_db(int account_id, char *ma * emstorage_free_attachment * * description : free memory - * arguments : + * arguments : * mail_list : mail array * count : the number of array element - * return : + * return : */ INTERNAL_FUNC int emstorage_free_attachment(emstorage_attachment_tbl_t **attachment_list, int count, int *err_code); @@ -1349,8 +1371,8 @@ INTERNAL_FUNC int emstorage_rollback_transaction(void *d1, void *d2, int *err_co /** * clear mail data from db. * - * @param[in] transaction - * @param[out] err_code + * @param[in] transaction + * @param[out] err_code * @remarks N/A * @return This function returns 0 on success or error code on failure. */ @@ -1364,27 +1386,27 @@ INTERNAL_FUNC char *emstorage_make_directory_path_from_file_path(char *file_name * emstorage_get_save_name * * description : get file name for saving data - * arguments : + * 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 : + * return : */ -INTERNAL_FUNC int emstorage_get_save_name(int account_id, int mail_id, int atch_id, char *fname, char *name_buf, int *err_code); +INTERNAL_FUNC int emstorage_get_save_name(int account_id, int mail_id, int atch_id, char *fname, char *name_buf, int maxlen, int *err_code); /* * emstorage_get_dele_name * * description : get a name for deleting contents from file system. - * arguments : + * 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 : + * return : */ INTERNAL_FUNC int emstorage_get_dele_name(int account_id, int mail_id, int atch_id, char *fname, char *name_buf, int *err_code); @@ -1392,10 +1414,10 @@ INTERNAL_FUNC int emstorage_get_dele_name(int account_id, int mail_id, int atch_ * emstorage_create_dir * * description : create directory - * arguments : + * arguments : * name_buf : buffer to hold file name. (MAX : 512Bytes) * no : attachment no. - * return : + * return : */ INTERNAL_FUNC int emstorage_create_dir(int account_id, int mail_id, int atch_id, int *err_code); @@ -1403,10 +1425,10 @@ INTERNAL_FUNC int emstorage_create_dir(int account_id, int mail_id, int atch_id, * emstorage_copy_file * * description : copy a attachment file - * arguments : + * arguments : * src_file : source file * dst_file : destination file - * return : + * return : */ INTERNAL_FUNC int emstorage_copy_file(char *src_file, char *dst_file, int sync_file, int *err_code); @@ -1414,10 +1436,10 @@ INTERNAL_FUNC int emstorage_copy_file(char *src_file, char *dst_file, int sync_f * emstorage_move_file * * description : move a file - * arguments : + * arguments : * src_file : source file * dst_file : destination file - * return : + * return : */ INTERNAL_FUNC int emstorage_move_file(char *src_file, char *dst_file, int sync_status, int *err_code); @@ -1425,9 +1447,9 @@ INTERNAL_FUNC int emstorage_move_file(char *src_file, char *dst_file, int sync_s * emstorage_move_file * * description : delete a file - * arguments : + * arguments : * src_file : file to be deleted - * return : + * return : */ INTERNAL_FUNC int emstorage_delete_file(char *src_file, int *err_code); @@ -1435,9 +1457,9 @@ INTERNAL_FUNC int emstorage_delete_file(char *src_file, int *err_code); * emstorage_delete_dir * * description : delete a directory - * arguments : + * arguments : * src_dir : directory to be deleted - * return : + * return : */ INTERNAL_FUNC int emstorage_delete_dir(char *src_dir, int *err_code); @@ -1453,19 +1475,20 @@ INTERNAL_FUNC int emstorage_free_sender_list(email_sender_list_t **sender_list, INTERNAL_FUNC int emstorage_get_thread_information(int thread_id, emstorage_mail_tbl_t **mail_table_data, int transaction, int *err_code); INTERNAL_FUNC int emstorage_get_thread_id_of_thread_mails(emstorage_mail_tbl_t *mail_table_data, int *thread_id, int *result_latest_mail_id_in_thread, int *thread_item_count); INTERNAL_FUNC int emstorage_get_thread_id_by_mail_id(int mail_id, int *thread_id, int *err_code); -INTERNAL_FUNC int emstorage_update_latest_thread_mail(int account_id, int thread_id, int latest_mail_id, int thread_item_count, int transaction, int *err_code); - +INTERNAL_FUNC int emstorage_update_latest_thread_mail(int account_id, int mailbox_id, int thread_id, int *updated_thread_id, int latest_mail_id, int thread_item_count, int noti_type, int transaction, int *err_code); +INTERNAL_FUNC int emstorage_get_thread_id_from_mailbox(int account_id, int mailbox_id, char *mail_subject, int *thread_id, int *thread_item_count); +INTERNAL_FUNC int emstorage_update_thread_id_of_mail(int account_id, int mailbox_id, int mail_id, int thread_id, int thread_item_count, int transaction, int *err_code); #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_ID_IDX_IN_MAIL_PARTIAL_BODY_ACTIVITY_TBL, + 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_ID_IDX_IN_MAIL_PARTIAL_BODY_ACTIVITY_TBL, MAILBOX_NAME_IDX_IN_MAIL_PARTIAL_BODY_ACTIVITY_TBL, }; @@ -1481,7 +1504,7 @@ INTERNAL_FUNC int emstorage_get_mailbox_pbd_activity_count(int account_id, int INTERNAL_FUNC int emstorage_update_pbd_activity(char *old_server_uid, char *new_server_uid, char *mbox_name, int *err_code); INTERNAL_FUNC int emstorage_create_file(char *buf, size_t file_size, char *dst_file, int *err_code); -#endif +#endif INTERNAL_FUNC int emstorage_free_address_info_list(email_address_info_list_t **address_info_list); @@ -1500,7 +1523,7 @@ INTERNAL_FUNC int emstorage_update_read_mail_uid_by_server_uid(char *old_server_ * @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 : + * @remarks An Example of Query to be exexuted in this API : * SELECT local_uid, server_uid from mail_read_mail_uid_tbl where local_uid in (12, 13, 56, 78); * @return This function returns true on success or false on failure. */ @@ -1511,19 +1534,19 @@ INTERNAL_FUNC int emstorage_get_id_set_from_mail_ids(char *mail_ids, email_id_se /** * @fn emstorage_filter_mails_by_rule(int account_id, int dest_mailbox_id, int dst_mailbox_type, int reset, email_rule_t *rule, int **filtered_mail_id_list, int *count_of_mails, int err_code) - * Move mails by specified rule for spam filtering. + * 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_id Mailbox id of spam mailbox. * @param[in] dest_mailbox_type Mailbox id of spam mailbox. - * @param[in] reset Tag id reset which when deleting the rule + * @param[in] reset Tag id reset which when deleting the rule * @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 + * @remarks * @return This function returns true on success or false on failure. */ INTERNAL_FUNC int emstorage_filter_mails_by_rule(int account_id, int dest_mailbox_id, int dest_mailbox_type, int reset, emstorage_rule_tbl_t *rule, int **filtered_mail_id_list, int *count_of_mails, int *err_code); @@ -1550,8 +1573,8 @@ INTERNAL_FUNC int emstorage_get_next_activity_id(int *activity_id, int *err_code /* *emstorage_get_activity_id_list *description : get the list of activity ids - *arguments : - *return : + *arguments : + *return : * */ INTERNAL_FUNC int emstorage_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); @@ -1559,8 +1582,8 @@ INTERNAL_FUNC int emstorage_get_activity_id_list(int account_id, int **activity_ * emstorage_add_activity * * description : add an activity to activity table - * arguments : - * return : + * arguments : + * return : */ INTERNAL_FUNC int emstorage_add_activity(emstorage_activity_tbl_t *local_activity, int transaction, int *err_code); @@ -1579,14 +1602,14 @@ INTERNAL_FUNC int emstorage_delete_local_activity(emstorage_activity_tbl_t *loca /** * emstorage_free_local_activity - Free the allocated Activity data - * + * * */ INTERNAL_FUNC int emstorage_free_local_activity(emstorage_activity_tbl_t **local_activity_list, int count, int *err_code); /** * emstorage_free_activity_id_list - Free the allocated Activity List data - * + * * */ INTERNAL_FUNC int emstorage_free_activity_id_list(int *activity_id_list, int *error_code); @@ -1617,6 +1640,23 @@ INTERNAL_FUNC int emstorage_query_task(const char *input_conditional_clause, con INTERNAL_FUNC int emstorage_check_and_update_server_uid_by_message_id(int account_id, email_mailbox_type_e input_mailbox_type, char *message_id, char *server_uid, int *searched_mail_id); +#ifdef __FEATURE_WIFI_AUTO_DOWNLOAD__ +INTERNAL_FUNC int emstorage_add_auto_download_activity(email_event_auto_download *local_activity, int *activity_id, int transaction, int *err_code); +INTERNAL_FUNC int emstorage_delete_auto_download_activity(int account_id, int mail_id, int activity_id, int transaction, int *err_code); +INTERNAL_FUNC int emstorage_delete_all_auto_download_activity(int account_id, int transaction, int *err_code); +INTERNAL_FUNC int emstorage_delete_auto_download_activity_by_mailbox(int account_id, int mailbox_id, int transaction, int *err_code); +INTERNAL_FUNC int emstorage_get_auto_download_activity(int account_id, int input_mailbox_id, email_event_auto_download **event_start, int *count, int transaction, int *err_code); +INTERNAL_FUNC int emstorage_get_auto_download_activity_count(int *activity_count, int transaction, int *err_code); +INTERNAL_FUNC int emstorage_get_auto_download_account_list(int **account_list, int *count, int transaction, int *err_code); +INTERNAL_FUNC int emstorage_get_auto_download_mailbox_list(int account_id, int **mailbox_list, int *count, int transaction, int *err_code); +INTERNAL_FUNC int emstorage_get_auto_download_activity_count_by_mailbox(int account_id, int input_mailbox_id, int *activity_count, int transaction, int *err_code); +INTERNAL_FUNC int emstorage_update_auto_download_activity(char *old_server_uid, char *new_server_uid, char *mailbox_name, int mailbox_id, int *err_code); +#endif + +#ifdef __FEATURE_UPDATE_DB_TABLE_SCHEMA__ +INTERNAL_FUNC int emstorage_update_db_table_schema(); +#endif /* __FEATURE_UPDATE_DB_TABLE_SCHEMA__ */ + #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/email-core/include/email-core-account.h b/email-core/include/email-core-account.h index 748bfc6..3636eba 100755 --- a/email-core/include/email-core-account.h +++ b/email-core/include/email-core-account.h @@ -40,13 +40,13 @@ extern "C" { #endif /* __cplusplus */ -INTERNAL_FUNC int emcore_validate_account(int account_id, int *err_code); +INTERNAL_FUNC int emcore_validate_account(int account_id, int handle, int *err_code); -INTERNAL_FUNC int emcore_validate_account_with_account_info(email_account_t *account, email_event_type_t event_type, int *err_code); +INTERNAL_FUNC int emcore_validate_account_with_account_info(email_account_t *account, email_event_type_t event_type, char **output_imap_cap_string, int event_handle, int *err_code); -INTERNAL_FUNC int emcore_create_account(email_account_t *account, int *err_code); +INTERNAL_FUNC int emcore_create_account(email_account_t *account, int add_account_to_account_svc, int *err_code); -INTERNAL_FUNC int emcore_delete_account(int account_id, int *err_code); +INTERNAL_FUNC int emcore_delete_account(int account_id, int input_delete_from_account_svc, int *err_code); INTERNAL_FUNC int emcore_free_account_list(email_account_t **account_list, int count, int *err_code); @@ -58,16 +58,14 @@ INTERNAL_FUNC void emcore_duplicate_account(const email_account_t *account, emai INTERNAL_FUNC int emcore_init_account_reference(); +INTERNAL_FUNC int emcore_add_account_reference(email_account_t *account); + INTERNAL_FUNC int emcore_free_account_reference(); INTERNAL_FUNC email_account_t *emcore_get_account_reference(int account_id); INTERNAL_FUNC int emcore_get_account_reference_list(email_account_t **account_list, int *count, int *err_code); -INTERNAL_FUNC int emcore_query_server_info(const char* domain_name, email_server_info_t **result_server_info); - -INTERNAL_FUNC int emcore_free_server_info(email_server_info_t **target_server_info); - INTERNAL_FUNC int emcore_save_default_account_id(int input_account_id); INTERNAL_FUNC int emcore_load_default_account_id(int *output_account_id); @@ -82,7 +80,7 @@ INTERNAL_FUNC int emcore_refresh_xoauth2_access_token(int input_account_id); #ifdef __FEATURE_BACKUP_ACCOUNT__ INTERNAL_FUNC int emcore_backup_accounts(const char *file_path, int *error_code); -INTERNAL_FUNC int emcore_restore_accounts(const char *file_path, int *error_code); +INTERNAL_FUNC int emcore_restore_accounts(const char *file_path); #endif /* __FEATURE_BACKUP_ACCOUNT_ */ #ifdef __cplusplus diff --git a/email-core/include/email-core-alarm.h b/email-core/include/email-core-alarm.h index 25f747d..df2ce6c 100755 --- a/email-core/include/email-core-alarm.h +++ b/email-core/include/email-core-alarm.h @@ -46,12 +46,12 @@ typedef struct _email_alarm_data_t { email_alarm_class_t class_id;
int reference_id;
time_t trigger_at_time;
- int (*alarm_callback)(int, void *);
+ int (*alarm_callback)(struct _email_alarm_data_t*, void *);
void *user_data;
} email_alarm_data_t;
-INTERNAL_FUNC int emcore_add_alarm(time_t input_trigger_at_time, email_alarm_class_t input_class_id, int input_reference_id, int (*input_alarm_callback)(int, void *), void *input_user_data);
+INTERNAL_FUNC int emcore_add_alarm(time_t input_trigger_at_time, email_alarm_class_t input_class_id, int input_reference_id, int (*input_alarm_callback)(email_alarm_data_t*, void *), void *input_user_data);
INTERNAL_FUNC int emcore_delete_alram_data_from_alarm_data_list(email_alarm_data_t *input_alarm_data);
INTERNAL_FUNC int emcore_delete_alram_data_by_reference_id(email_alarm_class_t input_class_id, int input_reference_id);
diff --git a/email-core/include/email-core-auto-download.h b/email-core/include/email-core-auto-download.h new file mode 100755 index 0000000..268b571 --- /dev/null +++ b/email-core/include/email-core-auto-download.h @@ -0,0 +1,58 @@ +/* +* email-service +* +* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. +* +* Contact: Minsoo Kim <minnsoo.kim@samsung.com>, 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 __EMAIL_CORE_AUTO_DOWNLOAD_H__ +#define __EMAIL_CORE_AUTO_DOWNLOAD_H__ + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +typedef struct auto_download_t +{ + int activity_id; + int status; + int account_id; + int mail_id; + unsigned long server_mail_id; + int mailbox_id; +} email_event_auto_download; + +INTERNAL_FUNC int emcore_start_auto_download_loop(int *err_code); +INTERNAL_FUNC int emcore_auto_download_loop_continue(void); +INTERNAL_FUNC int emcore_stop_auto_download_loop(int *err_code); +INTERNAL_FUNC int emcore_insert_auto_download_event(email_event_auto_download *event_data, int *err_code); +INTERNAL_FUNC int emcore_retrieve_auto_download_event(email_event_auto_download **event_data, int *err_code); +INTERNAL_FUNC int emcore_is_auto_download_queue_empty(void); +INTERNAL_FUNC int emcore_is_auto_download_queue_full(void); +INTERNAL_FUNC int emcore_clear_auto_download_queue(void); + +INTERNAL_FUNC int emcore_insert_auto_download_job(int account_id, int mailbox_id, int mail_id, int auto_download_on, char *uid, int *err_code); +INTERNAL_FUNC int emcore_insert_auto_download_activity(email_event_auto_download *local_activity, int *activity_id, int *err_code); +INTERNAL_FUNC int emcore_delete_auto_download_activity(int account_id, int mail_id, int activity_id, int *err_code); +#endif + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +/* EOF */ diff --git a/email-core/include/email-core-cert.h b/email-core/include/email-core-cert.h index 12e87b1..c0732f7 100644..100755 --- a/email-core/include/email-core-cert.h +++ b/email-core/include/email-core-cert.h @@ -53,4 +53,5 @@ INTERNAL_FUNC int emcore_load_PFX_file(char *certificate, char *password, EVP_PK */ INTERNAL_FUNC int emcore_load_PFX_file(char *certificate, EVP_PKEY **pri_key, X509 **cert, STACK_OF(X509) **ca, int *err_code); +INTERNAL_FUNC int emcore_load_PFX_file_from_string(char *certificate, char **key_string, int *key_size, int *err_code); #endif diff --git a/email-core/include/email-core-event.h b/email-core/include/email-core-event.h index 3654c2f..43a8ec2 100755 --- a/email-core/include/email-core-event.h +++ b/email-core/include/email-core-event.h @@ -53,7 +53,7 @@ INTERNAL_FUNC int emcore_cancel_all_thread(int *err_code); INTERNAL_FUNC int emcore_send_event_loop_stop(int *err_code); INTERNAL_FUNC int emcore_cancel_send_mail_thread(int handle, void *arg, int *err_code); INTERNAL_FUNC int emcore_cancel_all_send_mail_thread(int *err_code); -INTERNAL_FUNC int emcore_check_thread_status(void); +INTERNAL_FUNC int emcore_check_event_thread_status(int *event_type, int handle); INTERNAL_FUNC int emcore_check_send_mail_thread_status(void); INTERNAL_FUNC void emcore_get_event_queue_status(int *on_sending, int *on_receiving); INTERNAL_FUNC int emcore_insert_event_for_sending_mails(email_event_t *event_data, int *handle, int *err_code); @@ -64,6 +64,8 @@ INTERNAL_FUNC int emcore_get_task_information(email_task_information_t INTERNAL_FUNC void emcore_initialize_event_callback_table(); INTERNAL_FUNC int emcore_event_loop_continue(void); +INTERNAL_FUNC int emcore_is_event_queue_empty(void); +INTERNAL_FUNC int emcore_is_send_event_queue_empty(void); INTERNAL_FUNC int emcore_retrieve_event(email_event_t **event_data, int *err_code); INTERNAL_FUNC int emcore_return_handle(int handle); INTERNAL_FUNC int emcore_retrieve_send_event(email_event_t **event_data, int *err_code); @@ -73,6 +75,21 @@ INTERNAL_FUNC int emcore_mail_partial_body_download(email_event_partial_body_thd INTERNAL_FUNC void emcore_pb_thd_set_local_activity_continue(int flag); INTERNAL_FUNC int emcore_pb_thd_can_local_activity_continue(); INTERNAL_FUNC int emcore_set_pbd_thd_state(int flag); +INTERNAL_FUNC void emcore_get_sync_fail_event_data(email_event_t **event_data); + +/* +NOTE: The event is subject to event thread worker. + Don't be confused with other events +*/ +#define FINISH_OFF_IF_EVENT_CANCELED(err, handle) \ + do {\ + int type=0;\ + if (!emcore_check_event_thread_status(&type, handle)) {\ + EM_DEBUG_LOG ("CANCELED EVENT: type [%d]", type);\ + err = EMAIL_ERROR_CANCELLED;\ + goto FINISH_OFF;\ + }\ + } while(0) #ifdef __FEATURE_PARTIAL_BODY_DOWNLOAD__ diff --git a/email-core/include/email-core-gmime.h b/email-core/include/email-core-gmime.h index b27c733..e542b3c 100644 --- a/email-core/include/email-core-gmime.h +++ b/email-core/include/email-core-gmime.h @@ -23,13 +23,54 @@ #define __EMAIL_CORE_GMIME_H__ #include "email-core-mail.h" +#include <gmime/gmime.h> + +#include "c-client.h" +#include "lnx_inc.h" #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ -int emcore_gmime_parse_mime(char *eml_path, struct _m_content_info *cnt_info, int *err_code); +typedef struct _search_section { + GMimeObject *section_object; + char *section; +} search_section; + +INTERNAL_FUNC void emcore_gmime_init(void); +INTERNAL_FUNC void emcore_gmime_shutdown(void); + +INTERNAL_FUNC int emcore_gmime_pop3_parse_mime(char *eml_path, struct _m_content_info *cnt_info, int *err_code); +INTERNAL_FUNC int emcore_gmime_imap_parse_mime_partial(char *rfc822header_str, char *bodytext_str, struct _m_content_info *cnt_info); +INTERNAL_FUNC int emcore_gmime_eml_parse_mime(char *eml_path, struct _rfc822header *rfc822_header, struct _m_content_info *cnt_info, int *err_code); + +INTERNAL_FUNC void emcore_gmime_imap_parse_foreach_cb(GMimeObject *parent, GMimeObject *part, gpointer user_data); +INTERNAL_FUNC void emcore_gmime_imap_parse_full_foreach_cb(GMimeObject *parent, GMimeObject *part, gpointer user_data); +INTERNAL_FUNC void emcore_gmime_imap_parse_bodystructure_foreach_cb(GMimeObject *parent, GMimeObject *part, gpointer user_data); + +INTERNAL_FUNC void emcore_gmime_get_body_sections_foreach_cb(GMimeObject *parent, GMimeObject *part, gpointer user_data); +INTERNAL_FUNC void emcore_gmime_get_attachment_section_foreach_cb(GMimeObject *parent, GMimeObject *part, gpointer user_data); +INTERNAL_FUNC void emcore_gmime_search_section_foreach_cb(GMimeObject *parent, GMimeObject *part, gpointer user_data); + +INTERNAL_FUNC void emcore_gmime_construct_multipart (GMimeMultipart *multipart, BODY *body, const char *spec, int *total_mail_size); +INTERNAL_FUNC void emcore_gmime_construct_part (GMimePart *part, BODY *body, const char *spec, int *total_mail_size); +INTERNAL_FUNC int emcore_gmime_construct_mime_part_with_bodystructure(BODY *mbody, GMimeMessage **message, const char *spec, int *total_mail_size); + +INTERNAL_FUNC int emcore_gmime_get_body_sections_from_message(GMimeMessage *message, struct _m_content_info *cnt_info, char **sections_to_fetch); +INTERNAL_FUNC int emcore_gmime_get_attachment_section_from_message(GMimeMessage *message, + struct _m_content_info *cnt_info, int nth, char **section_to_fetch); + +INTERNAL_FUNC int emcore_gmime_fetch_imap_body_sections(MAILSTREAM *stream, int msg_uid, int mail_id, + struct _m_content_info *cnt_info, GMimeMessage *message, int event_handle, int auto_download, int *err_code); + +INTERNAL_FUNC int emcore_gmime_fetch_imap_attachment_section(MAILSTREAM *stream, + int mail_id, int uid, int nth, struct _m_content_info *cnt_info, + GMimeMessage *message, int auto_download, int event_handle, int *err_code); + +INTERNAL_FUNC int emcore_gmime_check_filename_duplication(char *source_filename, struct _m_content_info *cnt_info); +INTERNAL_FUNC char *emcore_gmime_get_modified_filename_in_duplication(char *source_filename); +INTERNAL_FUNC char *emcore_gmime_get_encoding_to_utf8(const char *text); #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/email-core/include/email-core-imap-idle.h b/email-core/include/email-core-imap-idle.h index 30fd18e..96b3ab0 100755 --- a/email-core/include/email-core-imap-idle.h +++ b/email-core/include/email-core-imap-idle.h @@ -34,24 +34,21 @@ /** - * @fn emcore_create_imap_idle_thread(int *err_code) + * @fn emcore_create_imap_idle_thread() * @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. + * @return Specifies the error code returned. */ -INTERNAL_FUNC int emcore_create_imap_idle_thread(int accountID, int *err_code); +INTERNAL_FUNC int emcore_create_imap_idle_thread(); /** - * @fn emcore_kill_imap_idle_thread(int *err_code) + * @fn emcore_refresh_imap_idle_thread(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. + * @return Specifies the error code returned. */ -INTERNAL_FUNC int emcore_kill_imap_idle_thread(int *err_code); +INTERNAL_FUNC int emcore_refresh_imap_idle_thread(); diff --git a/email-core/include/email-core-imap-mailbox.h b/email-core/include/email-core-imap-mailbox.h index 1c17bd4..58c557d 100755 --- a/email-core/include/email-core-imap-mailbox.h +++ b/email-core/include/email-core-imap-mailbox.h @@ -50,7 +50,7 @@ extern "C" * @remarks N/A * @return This function returns true on success or false on failure. */ -INTERNAL_FUNC int emcore_sync_mailbox_list(int account_id, char *mailbox, int handle, int *err_code); +INTERNAL_FUNC int emcore_sync_mailbox_list(int account_id, char *mailbox, int event_handle, int *err_code); /** * Download mailbox list from imap server. diff --git a/email-core/include/email-core-mail.h b/email-core/include/email-core-mail.h index 5a48918..83fb206 100755 --- a/email-core/include/email-core-mail.h +++ b/email-core/include/email-core-mail.h @@ -32,13 +32,12 @@ #ifndef __EMAIL_CORE_MESSAGE_H__ #define __EMAIL_CORE_MESSAGE_H__ -#include "email-storage.h" -#include <contacts.h> - #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ +#include "email-storage.h" + #ifdef __FEATURE_BULK_DELETE_MOVE_UPDATE_REQUEST_OPTI__ #define MAX_SUBSET_STRING_SIZE 260 @@ -58,41 +57,191 @@ typedef struct _emf_uid_range_set #endif +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 */ + char *attachment_mime_type; /* attachment mime type */ + char *content_id; /* mime content id */ + int save_status; +#ifdef __ATTACHMENT_OPTI__ + int encoding; /* encoding */ + char *section; /* section number */ +#endif + struct attachment_info *next; +}; + +/* + 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 value */ + struct _parameter *next; /* next paramete */ +}; + +/* Content-Disposition */ +struct _disposition { + char *type; /* "inline" "attachment */ + struct _parameter *parameter; /* "filename", .. */ +}; + +/* RFC822 Header */ +struct _rfc822header { + char *return_path; /* error return path */ + 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 *message_id; + char *content_type; + char *others; +}; + +/* MIME Part Header */ +struct _m_part_header { + char *type; /* text, image, audio, video, application, multipart, message */ + char *subtype; /* plain, html, jpeg, .. */ + char *encoding; /* encoding typ */ + struct _parameter *parameter; /* content-type parameter : "boundary" "charset" .. */ + char *desc; /* description */ + 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 */ + char *priority; /* Priority : 1, 3, 5 */ + char *ms_priority; /* MS-Priority : HIGH, NORMAL, LOW */ +}; + +/* MIME Message Header */ +struct _m_mesg_header { + char *version; /* MIME Version */ + struct _m_part_header *part_header; /* MIME Part Header */ + /* char *message_context; */ /* Message-Context : Voice-message, Video-message, Fax-message... */ + /* int content_duration; */ /* Content-Duration */ + /* int x_content_pages; */ /* X-Content-Pages */ + /* char *sensitivity; */ /* Sensitivity */ +}; + +/* MIME Multipart Body linked list */ +typedef struct _m_body _m_body_t; +struct _m_part{ + _m_body_t *body; /* part body */ + struct _m_part *next; /* the next found part */ +}; + +/* MIME Multipart Body */ +struct _m_body { + struct _m_part_header *part_header; /* MIME Part Header */ + struct _m_part nested; /* nested structure if contain multipart */ + char *text; /* text if not contain multipart */ + int size; /* text size if not contain multipart */ + char *holdingfile; +}; + +/* MIME Message */ +struct _m_mesg { + struct _rfc822header *rfc822header; /* RFC822 Header */ + struct _m_mesg_header *header; /* MIME Message Header */ + struct _m_part nested; /* nested structure if contain multipart */ + char *text; /* text if not contain multipart */ + int size; /* text size if not contain multipart */ +}; 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 */ + 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 */ + int total_mail_size; + int total_body_size; + int total_attachment_size; + int attachment_only; + char *sections; struct text_data { - char *plain; /* body plain text */ - char *plain_charset; /* charset of body text */ - char *html; /* body html text */ - char *html_charset; /* charset of html text */ + int plain_save_status; + char *plain; /* body plain text */ + char *plain_charset; /* charset of body text */ + int html_save_status; + char *html; /* body html text */ + char *html_charset; /* charset of 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 */ - char *attachment_mime_type; /* attachment mime type */ - char *content_id; /* mime content id */ - int save_status; -#ifdef __ATTACHMENT_OPTI__ - int encoding; /* encoding */ - char *section; /* section number */ -#endif - struct attachment_info *next; - } *file; + struct attachment_info *file; + struct attachment_info *inline_file; /* only used for IMAP partial body download */ }; +typedef enum { + IMAP4_CMD_EXPUNGE, + IMAP4_CMD_NOOP +} imap4_cmd_t; + +typedef enum { + POP3_CMD_NOOP +} pop3_cmd_t; + /** * Download email body from server. * @@ -109,7 +258,15 @@ struct _m_content_info * @return This function returns true on success or false on failure. */ -INTERNAL_FUNC int emcore_download_body_multi_sections_bulk(void *mail_stream, int account_id, int mail_id, int verbose, int with_attach, int limited_size, int event_handle , int *err_code); +INTERNAL_FUNC int emcore_download_body_multi_sections_bulk ( void *mail_stream, + int account_id, + int mail_id, + int verbose, + int with_attach, + int limited_size, + int event_handle, + int cancellable, + int *err_code); /** @@ -124,7 +281,7 @@ INTERNAL_FUNC int emcore_download_body_multi_sections_bulk(void *mail_stream, in * @remarks This function is used for only IMAP mail. * @return This function returns true on success or false on failure. */ -INTERNAL_FUNC int emcore_download_attachment(int acconut_id, int mail_id, int nth, int *err_code); +INTERNAL_FUNC int emcore_download_attachment (int acconut_id, int mail_id, int nth, int cancellable, int event_handle, int *err_code); INTERNAL_FUNC int emcore_add_attachment(int mail_id, email_attachment_data_t *attachment, int *err_code); /* TODO : Remove duplicated function */ INTERNAL_FUNC int emcore_add_attachment_data(int input_mail_id, email_attachment_data_t *input_attachment_data); /* TODO : Remove duplicated function */ INTERNAL_FUNC int emcore_delete_mail_attachment(int attachment_id, int *err_code); @@ -132,6 +289,12 @@ INTERNAL_FUNC int emcore_get_attachment_info(int attachment_id, email_attachment INTERNAL_FUNC int emcore_get_attachment_data_list(int input_mail_id, email_attachment_data_t **output_attachment_data, int *output_attachment_count); INTERNAL_FUNC int emcore_free_attachment_data(email_attachment_data_t **attachment_data_list, int attachment_data_count, int *err_code); +INTERNAL_FUNC int emcore_gmime_download_attachment(int mail_id, int nth, + int cancellable, int event_handle, int auto_download, int *err_code); + +INTERNAL_FUNC int emcore_gmime_download_body_sections(void *mail_stream, + int account_id, int mail_id, int with_attach, int limited_size, + int event_handle, int cancellable, int auto_download, int *err_code); INTERNAL_FUNC int emcore_move_mail(int mail_ids[], int num, int dst_mailbox_id, int noti_param_1, int noti_param_2, int *err_code); @@ -151,7 +314,9 @@ INTERNAL_FUNC int emcore_set_sent_contacts_log(emstorage_mail_tbl_t *input_mail_ INTERNAL_FUNC int emcore_set_received_contacts_log(emstorage_mail_tbl_t *input_mail_data); INTERNAL_FUNC int emcore_delete_contacts_log(int input_account_id); -INTERNAL_FUNC int emcore_get_mail_display_name(char *email_address, char **contact_display_name, int *err_code); + +INTERNAL_FUNC int emcore_get_mail_display_name(char *email_address, char **contact_display_name); +INTERNAL_FUNC int emcore_get_mail_display_name_internal (char *email_address, char **contact_display_name); INTERNAL_FUNC int emcore_get_mail_data(int input_mail_id, email_mail_data_t **output_mail_data); INTERNAL_FUNC int emcore_update_mail(email_mail_data_t *input_mail_data, email_attachment_data_t *input_attachment_data_list, int input_attachment_count, email_meeting_request_t* input_meeting_request, int sync_server); @@ -195,14 +360,15 @@ INTERNAL_FUNC void emcore_free_content_info(struct _m_content_info *cnt_info); INTERNAL_FUNC void emcore_free_attachment_info(struct attachment_info *attchment); INTERNAL_FUNC int emcore_move_mail_on_server(int account_id, int src_mailbox_id, int mail_ids[], int num, char *dest_mailbox, int *error_code); +INTERNAL_FUNC int emcore_move_mail_on_server_by_server_mail_id(void *mail_stream, char *server_mail_id, char *dest_mailbox_name); INTERNAL_FUNC int emcore_move_mail_to_another_account(int input_mail_id, int input_source_mailbox_id, int input_target_mailbox_id, int input_task_id); -INTERNAL_FUNC int emcore_sync_flag_with_server(int mail_id, int *err_code); -INTERNAL_FUNC int emcore_sync_seen_flag_with_server(int mail_ids[], int num, int *err_code); +INTERNAL_FUNC int emcore_sync_flag_with_server(int mail_id, int event_handle, int *err_code); +INTERNAL_FUNC int emcore_sync_seen_flag_with_server(int mail_ids[], int num, int event_handle, int *err_code); INTERNAL_FUNC int emcore_set_flags_field(int account_id, int mail_ids[], int num, email_flags_field_type field_type, int value, int *err_code); INTERNAL_FUNC char* emcore_convert_mutf7_to_utf8(char *mailbox_name); INTERNAL_FUNC int emcore_convert_string_to_structure(const char *encoded_string, void **struct_var, email_convert_struct_type_e type); -INTERNAL_FUNC int emcore_save_mail_file(int account_id, int mail_id, int attachment_id, char *src_file_path, char *file_name, char *full_path, int *err_code); +INTERNAL_FUNC int emcore_save_mail_file(int account_id, int mail_id, int attachment_id, char *src_file_path, char *file_name, char *full_path, int max_path_len, int *err_code); #ifdef __FEATURE_BULK_DELETE_MOVE_UPDATE_REQUEST_OPTI__ INTERNAL_FUNC int emcore_sync_flags_field_with_server(int mail_ids[], int num, email_flags_field_type field_type, int value, int *err_code); @@ -210,9 +376,13 @@ INTERNAL_FUNC int emcore_move_mail_on_server_ex(int account_id, int src_mailbo #endif #ifdef __ATTACHMENT_OPTI__ -INTERNAL_FUNC int emcore_download_attachment_bulk(/*email_mailbox_t *mailbox, */ int account_id, int mail_id, char *nth, int *err_code); +INTERNAL_FUNC int emcore_download_attachment_bulk(/*email_mailbox_t *mailbox, */ int account_id, int mail_id, char *nth, int event_handle, int *err_code); #endif INTERNAL_FUNC int emcore_mail_filter_by_rule(email_rule_t *filter_info, int *err_code); +INTERNAL_FUNC int emcore_add_rule(email_rule_t *filter_info); +INTERNAL_FUNC int emcore_update_rule(int filter_id, email_rule_t *filter_info); +INTERNAL_FUNC int emcore_delete_rule(int filter_id); + #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/email-core/include/email-core-mailbox-sync.h b/email-core/include/email-core-mailbox-sync.h index de17e48..9383257 100755 --- a/email-core/include/email-core-mailbox-sync.h +++ b/email-core/include/email-core-mailbox-sync.h @@ -34,6 +34,7 @@ #include "email-types.h" #include "email-storage.h" +#include "email-core-mail.h" #include "c-client.h" #ifdef __cplusplus @@ -56,27 +57,23 @@ typedef struct typedef struct { - char *header; - int header_len; - char *body; - int body_len; + char *bodystructure; + int bodystructure_len; + char *rfc822header; + int rfc822header_len; + char *bodytext; + int bodytext_len; unsigned long uid_no; } email_partial_buffer; #endif -typedef struct emcore_uid_elem { - int msgno; - char *uid; - email_mail_flag_t flag; - struct emcore_uid_elem *next; -} emcore_uid_list; int pop3_mail_calc_rfc822_size(MAILSTREAM *stream, int msgno, int *size, int *err_code); int pop3_mailbox_get_uids(MAILSTREAM *stream, emcore_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, emcore_uid_list** uid_list, int *err_code); +int imap4_mailbox_get_uids(MAILSTREAM *stream, char *input_target_uid_string, emcore_uid_list** uid_list, int *err_code); int emcore_check_rule(const char *input_full_address_from, const char *input_subject, emstorage_rule_tbl_t *rule, int rule_len, int *priority_sender, int *blocked, int *err_code); @@ -99,7 +96,16 @@ int emcore_add_mail_text(emstorage_mailbox_tbl_t *input_maibox_data, emstorage_m * @remarks N/A * @return This function returns true on success or false on failure. */ -INTERNAL_FUNC int emcore_sync_header(emstorage_mailbox_tbl_t *input_mailbox_tbl, void **stream, emcore_uid_list **input_uid_list, int *mail_count, int *unread_mail, int *err_code); +INTERNAL_FUNC int emcore_sync_header (emstorage_mailbox_tbl_t *input_mailbox_tbl, + void **stream, + emcore_uid_list **input_uid_list, + int *mail_count, + int *unread_mail, + int *vip_mail_count, + int *vip_unread_mail, + int cancellable, /*if event thread calls, set it*/ + int event_handle, + int *err_code); typedef enum { @@ -173,6 +179,7 @@ int emcore_free_uids(emcore_uid_list *uid_list, int *err_code); INTERNAL_FUNC char *emcore_guess_charset(char *source_string); INTERNAL_FUNC int emcore_sync_mail_from_client_to_server(int mail_id); +INTERNAL_FUNC int emcore_update_attachment_except_inline(struct _m_content_info *cnt_info, int account_id, int mail_id, int mailbox_id, int *output_total_attachment_size, int *output_attachment_count, int *output_inline_attachment_count); #ifdef __FEATURE_PARTIAL_BODY_DOWNLOAD__ INTERNAL_FUNC int emcore_download_bulk_partial_mail_body(MAILSTREAM *stream, email_event_partial_body_thd *pbd_event, int count, int *error); diff --git a/email-core/include/email-core-mailbox.h b/email-core/include/email-core-mailbox.h index 037f58d..6d9babc 100755 --- a/email-core/include/email-core-mailbox.h +++ b/email-core/include/email-core-mailbox.h @@ -65,7 +65,7 @@ INTERNAL_FUNC void emcore_reset_streams(); INTERNAL_FUNC int emcore_get_mailbox_list_to_be_sync(int account_id, email_mailbox_t **mailbox_list, int *p_count, int *err_code); INTERNAL_FUNC int emcore_get_mailbox_list(int account_id, email_mailbox_t **mailbox_list, int *p_count, int *err_code); INTERNAL_FUNC int emcore_get_mail_count(email_mailbox_t *mailbox, int *total, int *unseen, int *err_code); -INTERNAL_FUNC int emcore_create_mailbox(email_mailbox_t *new_mailbox, int on_server, int *err_code); +INTERNAL_FUNC int emcore_create_mailbox(email_mailbox_t *new_mailbox, int on_server, int server_type, int slot_size, int *err_code); INTERNAL_FUNC int emcore_delete_mailbox(int input_mailbox_id, int input_on_server, int input_recursive); INTERNAL_FUNC int emcore_delete_mailbox_ex(int input_account_id, int *input_mailbox_id_array, int input_mailbox_id_count, int input_on_server, int input_recursive); INTERNAL_FUNC int emcore_delete_mailbox_all(email_mailbox_t *mailbox, int *err_code); @@ -81,7 +81,8 @@ INTERNAL_FUNC void emcore_bind_mailbox_type(email_internal_mailbox_t *mailbox_li INTERNAL_FUNC int emcore_free_internal_mailbox(email_internal_mailbox_t **mailbox_list, int count, int *err_code); - +INTERNAL_FUNC void emcore_close_recv_stream_list (void); +INTERNAL_FUNC MAILSTREAM** emcore_get_recv_stream (int account_id, int mailbox_id, int *error); #ifdef __FEATURE_LOCAL_ACTIVITY__ INTERNAL_FUNC int emcore_local_activity_sync(int account_id, int *err_code); diff --git a/email-core/include/email-core-mime.h b/email-core/include/email-core-mime.h index a619132..0cbee55 100755 --- a/email-core/include/email-core-mime.h +++ b/email-core/include/email-core-mime.h @@ -48,7 +48,7 @@ INTERNAL_FUNC int emcore_get_content_type_from_mime_string(char *input_mime_st INTERNAL_FUNC int emcore_get_content_type_from_mail_bodystruct(BODY *input_body, int input_buffer_length, char *output_content_type); INTERNAL_FUNC int emcore_get_attribute_value_of_body_part(PARAMETER *input_param, char *atribute_name, char *output_value, int output_buffer_length, int with_rfc2047_text, int *err_code); INTERNAL_FUNC int emcore_get_body_part_list_full(MAILSTREAM *stream, int msg_uid, int account_id, int mail_id, BODY *body, struct _m_content_info *cnt_info, int *err_code, PARTLIST * section_list, int event_handle); -INTERNAL_FUNC int emcore_get_body(MAILSTREAM *stream, int account_id, int mail_id, int msg_uid, BODY *body, struct _m_content_info *cnt_info, int *err_code); +INTERNAL_FUNC int emcore_get_body(MAILSTREAM *stream, int account_id, int mail_id, int msg_uid, BODY *body, char *part_body_type, struct _m_content_info *cnt_info, int *err_code); INTERNAL_FUNC int emcore_get_body_structure(MAILSTREAM *stream, int msg_uid, BODY **body, int *err_code); INTERNAL_FUNC char *emcore_decode_rfc2047_text(char *rfc2047_text, int *err_code); INTERNAL_FUNC int emcore_decode_body_text(char *enc_buf, int enc_len, int enc_type, int *dec_len, int *err_code); @@ -57,6 +57,7 @@ INTERNAL_FUNC int emcore_parse_mime_file_to_mail(char *eml_file_path, email_ma INTERNAL_FUNC int emcore_delete_parsed_data(email_mail_data_t *input_mail_data, int *err_code); INTERNAL_FUNC int emcore_get_mime_entity(char *mime_path, char **mime_entity, int *err_code); INTERNAL_FUNC int emcore_get_utf8_address(char **dest, ADDRESS *address, int *err_code); +INTERNAL_FUNC int emcore_get_digest_type(char *micalg_value); #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/email-core/include/email-core-pgp.h b/email-core/include/email-core-pgp.h new file mode 100644 index 0000000..b7d2288 --- /dev/null +++ b/email-core/include/email-core-pgp.h @@ -0,0 +1,50 @@ +/* +* email-service +* +* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. +* +* Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +*/ + + +/****************************************************************************** + * File : email-core-smime.h + * Desc : Mail Operation Header + * + * Auth : + * + * History : + * 2006.08.16 : created + *****************************************************************************/ + +#ifndef EM_CORE_GPG_H_ +#define EM_CORE_GPG_H_ + +#include <cert-service.h> + +#include "email-types.h" + +INTERNAL_FUNC int emcore_pgp_set_signed_message(char *certificate, char *password, char *mime_entity, char *user_id, email_digest_type digest_type, char **file_path); + +INTERNAL_FUNC int emcore_pgp_set_encrypted_message(char *recipient_list, char *certificate, char *password, char *mime_entity, char *user_id, email_digest_type digest_type, char **file_path); + +INTERNAL_FUNC int emcore_pgp_set_signed_and_encrypted_message(char *recipient_list, char *certificate, char *password, char *mime_entity, char *user_id, email_digest_type digest_type, char **file_path); + +INTERNAL_FUNC int emcore_pgp_get_verify_signature(char *signature_path, char *mime_entity, email_digest_type digest_type, int *verify); + +INTERNAL_FUNC int emcore_pgp_get_decrypted_message(char *encrypted_message, char *password, int sign, char **decrypted_file, int *verify); + +#endif /* EM_CORE_GPG_H_ */ diff --git a/email-core/include/email-core-smime.h b/email-core/include/email-core-smime.h index c1b84f7..0c95e92 100755 --- a/email-core/include/email-core-smime.h +++ b/email-core/include/email-core-smime.h @@ -45,9 +45,11 @@ INTERNAL_FUNC int emcore_smime_set_signed_and_encrypt_message(char *recipient_li INTERNAL_FUNC int emcore_smime_verify_signed_message(char *signed_message, char *ca_file, char *ca_path, int *verify); -INTERNAL_FUNC int emcore_smime_set_decrypt_message(char *encrypt_message, char *from_address, char **decrypt_message, int *err_code); +INTERNAL_FUNC int emcore_smime_get_decrypt_message(char *encrypt_message, char *from_address, char **decrypt_message, int *err_code); INTERNAL_FUNC int emcore_convert_mail_data_to_smime_data(emstorage_account_tbl_t *account_tbl_item, email_mail_data_t *input_mail_data, email_attachment_data_t *input_attachment_data_list, int input_attachment_count, email_mail_data_t **output_mail_data, email_attachment_data_t **output_attachment_data_list, int *output_attachment_count); +INTERNAL_FUNC void emcore_init_openssl_library(); +INTERNAL_FUNC void emcore_clean_openssl_library(); #endif /* EM_CORE_SMIME_H_ */ diff --git a/email-core/include/email-core-smtp.h b/email-core/include/email-core-smtp.h index 77eefb8..b0dafc5 100755 --- a/email-core/include/email-core-smtp.h +++ b/email-core/include/email-core-smtp.h @@ -52,7 +52,7 @@ INTERNAL_FUNC int emcore_schedule_sending_mail(int input_mail_id, time_t input_t INTERNAL_FUNC int emcore_make_rfc822_file_from_mail(emstorage_mail_tbl_t *input_mail_tbl_data, emstorage_attachment_tbl_t *input_attachment_tbl_t, int input_attachment_count, ENVELOPE **env, char **file_path, email_option_t *sending_option, int *err_code); -INTERNAL_FUNC int emcore_make_rfc822_file(email_mail_data_t *input_mail_tbl_data, email_attachment_data_t *input_attachment_tbl, int input_attachment_count, char **file_path, int *err_code); +INTERNAL_FUNC int emcore_make_rfc822_file(email_mail_data_t *input_mail_tbl_data, email_attachment_data_t *input_attachment_tbl, int input_attachment_count, int mime_entity_status, char **file_path, int *err_code); INTERNAL_FUNC int emcore_add_mail(email_mail_data_t *input_mail_data, email_attachment_data_t *input_attachment_data_list, int input_attachment_count, email_meeting_request_t *input_meeting_request, int input_from_eas, int move_flag); @@ -64,6 +64,10 @@ INTERNAL_FUNC int emcore_create_alarm_for_auto_resend(int input_alarm_interval_i INTERNAL_FUNC int emcore_query_mail_size_limit(int account_id, int handle, int *err_code); +INTERNAL_FUNC void emcore_close_smtp_stream_list (void); + +INTERNAL_FUNC SENDSTREAM** emcore_get_smtp_stream (int account_id, int *error); + #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/email-core/include/email-core-sound.h b/email-core/include/email-core-sound.h deleted file mode 100755 index 9c98d7e..0000000 --- a/email-core/include/email-core-sound.h +++ /dev/null @@ -1,64 +0,0 @@ -/* -* email-service -* -* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. -* -* Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -* -*/ - - -#include <vconf-keys.h> -#include <vconf.h> - -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_NONE, -} 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; - -typedef enum -{ - SETTING_NOTI_STATUS_OFF = 0, - SETTING_NOTI_STATUS_GLOBAL = 1, - SETTING_NOTI_STATUS_EMAIL = 2, -} EMAIL_NOTI_STATUS; - -#ifdef Min -#undef Min -#endif - -INTERNAL_FUNC int emcore_get_alert_policy(EMAIL_ALERT_TYPE *output_alert_type, char **output_alert_tone_path); - diff --git a/email-core/include/email-core-utils.h b/email-core/include/email-core-utils.h index 832324d..3e8e53d 100755 --- a/email-core/include/email-core-utils.h +++ b/email-core/include/email-core-utils.h @@ -61,7 +61,7 @@ INTERNAL_FUNC int emcore_get_file_size(char *path, int *size, int *err_code); int emcore_get_actual_mail_size(char *pBodyPlane, char *pBodyHtml, struct attachment_info *pAttachment, int *error_code); int emcore_calc_mail_size(email_mail_data_t *mail_data_src, email_attachment_data_t *attachment_data_src, int attachment_count, int *error_code); int emcore_get_address_count(char *addr_str, int *to_num, int *err_code); -INTERNAL_FUNC int emcore_is_storage_full(int *error); +INTERNAL_FUNC int emcore_is_storage_full(); int emcore_get_long_encoded_path_with_account_info(email_account_t *account, char *path, int delimiter, char **long_enc_path, int *err_code); void emcore_fill_address_information_of_mail_tbl(emstorage_mail_tbl_t *mail_data); @@ -72,10 +72,12 @@ INTERNAL_FUNC int emcore_get_preview_text_from_file(const char *input_plain_path #ifdef __FEATURE_BODY_SEARCH__ INTERNAL_FUNC int emcore_strip_mail_body_from_file(emstorage_mail_tbl_t *mail, char **stripped_text, int *err_code); #endif +INTERNAL_FUNC int emcore_get_first_address(const char *full_address, char **alias, char **address); -int reg_replace (char *input_source_text, char *input_old_pattern_string, char *input_new_string); -int reg_replace_new (char **input_source_text, char *input_old_pattern_string, char *input_new_string); -int emcore_strip_HTML(char **source_string); + +INTERNAL_FUNC int reg_replace (char *input_source_text, char *input_old_pattern_string, char *input_new_string); +INTERNAL_FUNC int reg_replace_new (char **input_source_text, char *input_old_pattern_string, char *input_new_string); +int emcore_strip_HTML_tag(const char *input_html_file_path, char *encoding_type, char *output_result_buffer, int input_result_buffer_legnth); int emcore_send_noti_for_new_mail(int account_id, char *mailbox_name, char *subject, char *from, char *uid, char *datetime); int emcore_make_attachment_file_name_with_extension(char *source_file_name, char *sub_type, char *result_file_name, int result_file_name_buffer_length, int *err_code); @@ -89,7 +91,7 @@ INTERNAL_FUNC int emcore_get_mail_count_by_query(int account_id, int mailbox_typ INTERNAL_FUNC int emcore_check_drm_file(char *path, int *err_code); INTERNAL_FUNC int emcore_check_drm_is_ringtone(char *ringtone_path, int *err_code); -INTERNAL_FUNC int emcore_display_unread_in_badge(); +INTERNAL_FUNC void emcore_display_unread_in_badge(void *data); INTERNAL_FUNC int emcore_display_badge_count(int count); INTERNAL_FUNC int emcore_set_network_error(int err_code); @@ -102,16 +104,21 @@ INTERNAL_FUNC int emcore_delete_transaction_info_by_mailId(int mail_id); /* For notification bar */ INTERNAL_FUNC int emcore_update_notification_for_unread_mail(int account_id); -INTERNAL_FUNC int emcore_clear_all_notifications(); +INTERNAL_FUNC int emcore_clear_notifications(int account_id); //INTERNAL_FUNC int emcore_add_notification_for_unread_mail(emstorage_mail_tbl_t *input_mail_tbl_data); -INTERNAL_FUNC int emcore_add_notification(int account_id, int mail_id, int unread_mail_count, int input_play_alert_tone, int sending_error, unsigned long display); +INTERNAL_FUNC int emcore_add_notification(int account_id, int mail_id, int unread_mail_count, int vip_unread_mail_count, int input_play_alert_tone, int sending_error, unsigned long display); INTERNAL_FUNC int emcore_add_notification_for_send(int account_id, int mail_id, email_action_t action, int sending_error, unsigned long display); INTERNAL_FUNC void emcore_update_notification_for_send(int account_id, int mail_id, double progress); INTERNAL_FUNC int emcore_delete_notification_for_read_mail(int mail_id); INTERNAL_FUNC int emcore_delete_notification_by_account(int account_id, int with_noti_tray); +INTERNAL_FUNC void emcore_set_flash_noti(); + INTERNAL_FUNC int emcore_show_user_message(int id, email_action_t action, int error); +INTERNAL_FUNC int emcore_connect_contacts_service(); +INTERNAL_FUNC int emcore_disconnect_contacts_service(); + #ifdef __FEATURE_BULK_DELETE_MOVE_UPDATE_REQUEST_OPTI__ /** @@ -208,7 +215,7 @@ INTERNAL_FUNC int emcore_search_string_from_file(char *file_path, char *search_s INTERNAL_FUNC int emcore_load_query_from_file(char *file_path, char ***query_array, int *array_len); -INTERNAL_FUNC int emcore_start_driving_mode(int account_id); +INTERNAL_FUNC int emcore_start_driving_mode(int mail_id); #ifdef __FEATURE_BLOCKING_MODE__ INTERNAL_FUNC bool emcore_init_blocking_mode_status(); @@ -216,9 +223,20 @@ INTERNAL_FUNC void emcore_set_blocking_mode_of_setting(int input_blocking_mode_o INTERNAL_FUNC int emcore_get_blocking_mode_status(); INTERNAL_FUNC void emcore_set_blocking_mode_status(int blocking_mode); INTERNAL_FUNC int emcore_check_blocking_mode(char *sender_address, int *blocking_status); +INTERNAL_FUNC int emcore_check_blocking_mode_internal (char *sender_address, int *blocking_status); #endif /* __FEATURE_BLOCKING_MODE__ */ INTERNAL_FUNC char *emcore_set_mime_entity(char *mime_path); +INTERNAL_FUNC int emcore_get_content_from_file(char *filename, char **contents, int *length); +INTERNAL_FUNC int emcore_set_content_to_file(const char *contents, char *dest_path, int length); + +#ifdef __FEATURE_UPDATE_DB_TABLE_SCHEMA__ +INTERNAL_FUNC int emcore_update_db_table_schema(); +#endif /* #ifdef __FEATURE_UPDATE_DB_TABLE_SCHEMA__ */ +INTERNAL_FUNC int emcore_unescape_from_url(char *input_url, char **output_url); +INTERNAL_FUNC char *__em_get_month_in_string(int month); +INTERNAL_FUNC int emcore_make_date_string_for_search(time_t input_time, char *output_date_string); +INTERNAL_FUNC int emcore_make_uid_range_string(emcore_uid_list *uid_list, int total, char **output_uid_range_string); #ifdef __cplusplus } diff --git a/email-daemon/CMakeLists.txt b/email-daemon/CMakeLists.txt index 06ec746..9c51115 100755 --- a/email-daemon/CMakeLists.txt +++ b/email-daemon/CMakeLists.txt @@ -15,6 +15,8 @@ ADD_DEFINITIONS("-DSSL_CERT_DIRECTORY=\"/opt/etc/ssl/certs\"") ADD_DEFINITIONS("-DSSL_KEY_DIRECTORY=\"/opt/etc/ssl/certs\"") SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${VISIBILITY} -fvisibility=hidden") +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wl,--gc-sections") + ########################################################## # Define Execute File @@ -46,19 +48,23 @@ INCLUDE_DIRECTORIES( ) INCLUDE(FindPkgConfig) -pkg_check_modules(main_pkgs REQUIRED glib-2.0 dlog dbus-1 gthread-2.0 db-util +pkg_check_modules(main_pkgs REQUIRED glib-2.0 dlog dbus-1 gthread-2.0 openssl uw-imap-toolkit vconf vconf-internal-keys contacts-service2 - alarm-service mm-player drm-client feedback msg-service - libwbxml2 libsmack notification) + alarm-service msg-service + libwbxml2 libsmack notification capi-network-connection gmime-2.6) FOREACH(flag ${main_pkgs_CFLAGS}) SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") ENDFOREACH(flag) +IF(_FEATURE_OPCO_DOCOMO) + ADD_DEFINITIONS("-D__FEATURE_OMA_EMN__") +ENDIF(_FEATURE_OPCO_DOCOMO) + 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-core-sound email-storage email-network email-ipc email-common-use email-device email-smime) +TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${main_pkgs_LDFLAGS} dl ssl email-core email-storage email-network email-ipc email-common-use email-device email-smime) INSTALL(TARGETS ${PROJECT_NAME} DESTINATION bin) diff --git a/email-daemon/email-daemon-account.c b/email-daemon/email-daemon-account.c index 11c1088..039636d 100755 --- a/email-daemon/email-daemon-account.c +++ b/email-daemon/email-daemon-account.c @@ -41,10 +41,12 @@ #include "email-daemon-account.h" #include "email-daemon-auto-poll.h" #include <contacts.h> +#include <contacts_internal.h> #include "email-types.h" #include "email-core-account.h" #include "email-core-event.h" #include "email-core-utils.h" +#include "email-core-imap-idle.h" #include "email-utilities.h" #include "email-convert.h" @@ -88,13 +90,11 @@ INTERNAL_FUNC int emdaemon_create_account(email_account_t* account, int* err_cod int ret = false; int err = EMAIL_ERROR_NONE; - if (!emcore_create_account(account, &err)) { + if (!emcore_create_account(account, false, &err)) { EM_DEBUG_EXCEPTION(" emcore_account_add failed [%d]", err); goto FINISH_OFF; } - emcore_init_account_reference(); - ret = true; FINISH_OFF: if (err_code) @@ -109,7 +109,7 @@ INTERNAL_FUNC int emdaemon_delete_account(int account_id, int* err_code) EM_DEBUG_FUNC_BEGIN("account_id[%d] err_code[%p]", account_id, err_code); int ret = false; - ret = emcore_delete_account(account_id, err_code); + ret = emcore_delete_account(account_id, false, err_code); EM_DEBUG_FUNC_END("ret[%d]", ret); return ret; @@ -303,7 +303,7 @@ INTERNAL_FUNC int emdaemon_update_account(int account_id, email_account_t* new_a int ret = false; int err = EMAIL_ERROR_NONE; emstorage_account_tbl_t *new_account_tbl = NULL; - email_account_t old_account_info = {0}; + email_account_t *old_account_info = NULL; if ((account_id <= 0) || !new_account) { EM_DEBUG_EXCEPTION("Invalid Parameters."); @@ -311,19 +311,26 @@ INTERNAL_FUNC int emdaemon_update_account(int account_id, email_account_t* new_a goto FINISH_OFF; } - if(!emdaemon_get_account(account_id, GET_FULL_DATA, &old_account_info, &err)) { - EM_DEBUG_EXCEPTION("emdaemon_get_account failed "); + if((old_account_info = emcore_get_account_reference(account_id)) == NULL) { + EM_DEBUG_EXCEPTION("emcore_get_account_reference failed "); goto FINISH_OFF; } - EM_DEBUG_LOG_SEC("new_account->email_addr[%s]", new_account->user_email_address); if(new_account->user_email_address) { - if ((err = em_verify_email_address (new_account->user_email_address, true)) != EMAIL_ERROR_NONE) { + if ((err = em_verify_email_address (new_account->user_email_address)) != EMAIL_ERROR_NONE) { EM_DEBUG_EXCEPTION("em_verify_email_address error [%d]", err); goto FINISH_OFF; } } + if (EM_SAFE_STRCMP(new_account->incoming_server_password, old_account_info->incoming_server_password) == 0) { + EM_SAFE_FREE(new_account->incoming_server_password); + } + + if (EM_SAFE_STRCMP(new_account->outgoing_server_password, old_account_info->outgoing_server_password) == 0) { + EM_SAFE_FREE(new_account->outgoing_server_password); + } + new_account_tbl = em_malloc(sizeof(emstorage_account_tbl_t)); if(!new_account_tbl) { EM_DEBUG_EXCEPTION("allocation failed [%d]", err); @@ -333,7 +340,7 @@ INTERNAL_FUNC int emdaemon_update_account(int account_id, email_account_t* new_a em_convert_account_to_account_tbl(new_account, new_account_tbl); if (!emstorage_update_account(account_id, new_account_tbl, true, &err)) { - EM_DEBUG_EXCEPTION("emstorage_update_account falied [%d]", err); + EM_DEBUG_EXCEPTION("emstorage_update_account failed [%d]", err); goto FINISH_OFF; } @@ -342,17 +349,26 @@ INTERNAL_FUNC int emdaemon_update_account(int account_id, email_account_t* new_a #ifdef __FEATURE_AUTO_POLLING__ int change_in_auto_polling_option = 0; - change_in_auto_polling_option = (old_account_info.check_interval != new_account->check_interval) || - (old_account_info.peak_interval != new_account->peak_interval) || - (old_account_info.peak_start_time != new_account->peak_start_time) || - (old_account_info.peak_end_time != new_account->peak_end_time); + change_in_auto_polling_option = (old_account_info->check_interval != new_account->check_interval) || + (old_account_info->peak_interval != new_account->peak_interval) || + (old_account_info->peak_start_time != new_account->peak_start_time) || + (old_account_info->peak_end_time != new_account->peak_end_time); + + EM_DEBUG_LOG("change_in_auto_polling_option [%d]", change_in_auto_polling_option); +#endif + +#ifdef __FEATURE_AUTO_POLLING__ if(change_in_auto_polling_option) { if(!emdaemon_remove_polling_alarm(account_id)) EM_DEBUG_LOG("emdaemon_remove_polling_alarm failed"); if(!emdaemon_add_polling_alarm(account_id)) EM_DEBUG_EXCEPTION("emdaemon_add_polling_alarm failed"); + +#ifdef __FEATURE_IMAP_IDLE__ + emcore_refresh_imap_idle_thread(); +#endif /* __FEATURE_IMAP_IDLE__ */ } #endif @@ -360,11 +376,14 @@ INTERNAL_FUNC int emdaemon_update_account(int account_id, email_account_t* new_a FINISH_OFF: - emcore_free_account(&old_account_info); - if(new_account_tbl) emstorage_free_account(&new_account_tbl, 1, NULL); + if (old_account_info) { + emcore_free_account(old_account_info); + EM_SAFE_FREE(old_account_info); + } + if (err_code) *err_code = err; @@ -643,41 +662,12 @@ INTERNAL_FUNC int emdaemon_add_filter(email_rule_t* filter_info) goto FINISH_OFF; } - if (!emstorage_find_rule((emstorage_rule_tbl_t*)filter_info, true, &err)) { - EM_DEBUG_EXCEPTION("emstorage_find_rule failed [%d]", err); + err = emcore_add_rule(filter_info); + if (err != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emcore_add_rule failed : [%d]", err); goto FINISH_OFF; - } else { - if (err != EMAIL_ERROR_FILTER_NOT_FOUND) { - EM_DEBUG_LOG("filter already exist"); - err = EMAIL_ERROR_ALREADY_EXISTS; - goto FINISH_OFF; - } } - switch (filter_info->faction) { - case EMAIL_FILTER_MOVE : - if (filter_info->account_id < 0) { - EM_DEBUG_EXCEPTION("Invalid Param : target_mailbox_id[%d], account_id[%d]", filter_info->target_mailbox_id, filter_info->account_id); - err = EMAIL_ERROR_INVALID_PARAM; - goto FINISH_OFF; - } - break; - case EMAIL_FILTER_BLOCK : - filter_info->account_id = ALL_ACCOUNT; - break; - case EMAIL_FILTER_DELETE : - default: - EM_DEBUG_LOG("filter_faction : [%d]", filter_info->faction); - break; - } - - if (!emstorage_add_rule((emstorage_rule_tbl_t*)filter_info, true, &err)) { - EM_DEBUG_EXCEPTION("emstorage_add_rule failed [%d]", err); - goto FINISH_OFF; - } - - EM_DEBUG_LOG("filter_id : [%d]", filter_info->filter_id); - FINISH_OFF: EM_DEBUG_FUNC_END(); @@ -703,10 +693,11 @@ INTERNAL_FUNC int emdaemon_update_filter(int filter_id, email_rule_t* filter_inf goto FINISH_OFF; } - if (!emstorage_change_rule(filter_id, (emstorage_rule_tbl_t*)filter_info, true, &err)) { - EM_DEBUG_EXCEPTION("emstorage_change_rule falied [%d]", err); - goto FINISH_OFF; - } + err = emcore_update_rule(filter_id, filter_info); + if (err != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emcore_update_rule failed : [%d]", err); + goto FINISH_OFF; + } ret = true; @@ -724,7 +715,6 @@ INTERNAL_FUNC int emdaemon_delete_filter(int filter_id, int* err_code) /* default variable */ int ret = false; int err = EMAIL_ERROR_NONE; - emstorage_rule_tbl_t *p_rule_tbl = NULL; if (filter_id <= 0) { EM_DEBUG_EXCEPTION(" fliter_id[%d]", filter_id); @@ -732,18 +722,9 @@ INTERNAL_FUNC int emdaemon_delete_filter(int filter_id, int* err_code) goto FINISH_OFF; } - if (!emstorage_get_rule_by_id(filter_id, &p_rule_tbl, false, &err)) { - EM_DEBUG_EXCEPTION("emstorage_get_rule_by_id failed : [%d]", err); - goto FINISH_OFF; - } - - if (!emstorage_filter_mails_by_rule(p_rule_tbl->account_id, p_rule_tbl->target_mailbox_id, false, true, p_rule_tbl, NULL, NULL, &err)) { - EM_DEBUG_EXCEPTION("emstorage_filter_mails_by_rule failed : [%d]", err); - goto FINISH_OFF; - } - - if (!emstorage_delete_rule(filter_id, true, &err)) { - EM_DEBUG_EXCEPTION(" emstorage_delete_rule failed [%d]", err); + err = emcore_delete_rule(filter_id); + if (err != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emcore_delete_rule failed : [%d]", err); goto FINISH_OFF; } @@ -835,6 +816,7 @@ int emdaemon_initialize_account_reference() if ((err = emcore_init_account_reference()) != EMAIL_ERROR_NONE) { if (err == EMAIL_ERROR_SECURED_STORAGE_FAILURE) { + EM_DEBUG_EXCEPTION("EMAIL_ERROR_SECURED_STORAGE_FAILURE occured."); if ((err = emcore_recover_from_secured_storage_failure()) != EMAIL_ERROR_NONE) { EM_DEBUG_EXCEPTION("emcore_recover_from_secured_storage_failure failed [%d]", err); goto FINISH_OFF; diff --git a/email-daemon/email-daemon-auto-poll.c b/email-daemon/email-daemon-auto-poll.c index fa4f9a3..301afb0 100755 --- a/email-daemon/email-daemon-auto-poll.c +++ b/email-daemon/email-daemon-auto-poll.c @@ -43,7 +43,7 @@ #include "email-utilities.h" -static int _emdaemon_get_polling_account_and_timeinterval(alarm_id_t alarm_id, int *account_id, int *timer_interval); +static int _emdaemon_get_polling_account_and_timeinterval(email_alarm_data_t *alarm_data, int *account_id, int *timer_interval); static int _emdaemon_create_alarm_for_auto_polling(int input_account_id); INTERNAL_FUNC int emdaemon_add_polling_alarm(int input_account_id) @@ -103,9 +103,9 @@ FINISH_OFF: return err; } -INTERNAL_FUNC int emdaemon_alarm_polling_cb(alarm_id_t alarm_id, void* user_param) +INTERNAL_FUNC int emdaemon_alarm_polling_cb(email_alarm_data_t *alarm_data, void* user_param) { - EM_DEBUG_FUNC_BEGIN("alarm_id [%d] user_param [%d]", alarm_id, user_param); + EM_DEBUG_FUNC_BEGIN("alarm_data [%p] user_param [%d]", alarm_data, user_param); int ret = false; int err = EMAIL_ERROR_NONE; @@ -117,18 +117,11 @@ INTERNAL_FUNC int emdaemon_alarm_polling_cb(alarm_id_t alarm_id, void* user_para int wifi_status = 0; email_account_t *ref_account = NULL; - EM_DEBUG_ALARM_LOG("alarm_id [%d]", alarm_id); - - if(!_emdaemon_get_polling_account_and_timeinterval(alarm_id, &account_id, &timer_interval)) { + if(!_emdaemon_get_polling_account_and_timeinterval(alarm_data, &account_id, &timer_interval)) { EM_DEBUG_EXCEPTION("email_get_polling_account failed"); return false; } - /* delete from list */ - if ((err = emdaemon_remove_polling_alarm(account_id)) != EMAIL_ERROR_NONE) { - EM_DEBUG_EXCEPTION("email_get_polling_account failed [%d]", err); - } - EM_DEBUG_LOG("target account_id [%d]",account_id); /* create alarm, for polling */ @@ -189,24 +182,18 @@ FINISH_OFF : } -static int _emdaemon_get_polling_account_and_timeinterval(alarm_id_t alarm_id, int *account_id, int *timer_interval) +static int _emdaemon_get_polling_account_and_timeinterval(email_alarm_data_t *alarm_data, int *account_id, int *timer_interval) { - EM_DEBUG_FUNC_BEGIN("alarm_id [%d] account_id[%p] timer_interval[%p]", alarm_id, account_id, timer_interval); + EM_DEBUG_FUNC_BEGIN("alarm_data [%p] account_id[%p] timer_interval[%p]", alarm_data, account_id, timer_interval); int err = EMAIL_ERROR_NONE; - email_alarm_data_t *alarm_data = NULL; email_account_t *account = NULL; - if(!alarm_id || !account_id) { + if(!alarm_data || !account_id) { EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM"); err = EMAIL_ERROR_INVALID_PARAM; goto FINISH_OFF; } - if (((err = emcore_get_alarm_data_by_alarm_id(alarm_id, &alarm_data)) != EMAIL_ERROR_NONE) || alarm_data == NULL) { - EM_DEBUG_EXCEPTION("emcore_add_alarm failed [%d]",err); - goto FINISH_OFF; - } - account = emcore_get_account_reference(alarm_data->reference_id); if (account == NULL) { EM_DEBUG_EXCEPTION("emcore_get_account_reference failed [%d]",err); diff --git a/email-daemon/email-daemon-emn.c b/email-daemon/email-daemon-emn.c index d193b8f..9e9831c 100755 --- a/email-daemon/email-daemon-emn.c +++ b/email-daemon/email-daemon-emn.c @@ -574,7 +574,7 @@ static int emdaemon_register_wap_push_callback(msg_handle_t *input_msg_handle, c msg_error_t msg_err = MSG_SUCCESS; msg_struct_t msg_struct = NULL; char *content_type = "application/vnd.wap.emn+wbxml"; - char *pkg_name = "com.samsung.email"; + char *pkg_name = "org.tizen.email"; bool bLaunch = false; if(input_msg_handle == NULL || input_app_id == NULL) { diff --git a/email-daemon/email-daemon-etc.c b/email-daemon/email-daemon-etc.c index 073c1bd..ae44aba 100755 --- a/email-daemon/email-daemon-etc.c +++ b/email-daemon/email-daemon-etc.c @@ -36,6 +36,7 @@ #include <vconf.h> #include <vconf-keys.h> #include <glib.h> +#include <gio/gio.h> #include <glib-object.h> #include <sys/smack.h> #include <notification.h> @@ -50,10 +51,10 @@ #include "email-core-utils.h" #include "email-core-alarm.h" #include "email-core-smtp.h" -#include "email-core-sound.h" #include "email-utilities.h" #include "email-storage.h" #include "email-ipc.h" +#include "email-dbus-activation.h" extern pthread_mutex_t sound_mutex; extern pthread_cond_t sound_condition; @@ -98,7 +99,6 @@ INTERNAL_FUNC int emdaemon_cancel_sending_mail_job(int account_id, int mail_id, int ret = false; int err = EMAIL_ERROR_NONE; int handle = 0; - email_account_t* ref_account = NULL; if (account_id <= 0) { EM_DEBUG_EXCEPTION("account_id[%d], mail_id[%d]", account_id, mail_id); @@ -108,6 +108,8 @@ INTERNAL_FUNC int emdaemon_cancel_sending_mail_job(int account_id, int mail_id, #ifdef __FEATURE_PROGRESS_IN_OUTBOX__ + /* Removed below code, as it is causing struck in composer */ +#if 0 /* h.gahlaut@samsung.com: Moved this code from email_cancel_sending_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 */ @@ -136,6 +138,7 @@ INTERNAL_FUNC int emdaemon_cancel_sending_mail_job(int account_id, int mail_id, } +#endif if ((err = emcore_delete_alram_data_by_reference_id(EMAIL_ALARM_CLASS_SCHEDULED_SENDING, mail_id)) != EMAIL_ERROR_NONE) { EM_DEBUG_LOG("emcore_delete_alram_data_by_reference_id failed [%d]",err); @@ -143,21 +146,14 @@ INTERNAL_FUNC int emdaemon_cancel_sending_mail_job(int account_id, int mail_id, #endif - if(!emcore_get_handle_by_mailId_from_transaction_info(mail_id , &handle )) { + if(!emcore_get_handle_by_mailId_from_transaction_info(mail_id , &handle)) { EM_DEBUG_EXCEPTION("emcore_get_handle_by_mailId_from_transaction_info failed for mail_id[%d]", mail_id); - err = EMAIL_ERROR_HANDLE_NOT_FOUND; - goto FINISH_OFF; - } - - if (!(ref_account = emcore_get_account_reference(account_id))) { - EM_DEBUG_EXCEPTION("emcore_get_account_reference failed [%d]", account_id); - err = EMAIL_ERROR_INVALID_ACCOUNT; + ret = true; goto FINISH_OFF; } - if (!emcore_cancel_send_mail_thread(handle, NULL, &err)) { + if (!emcore_cancel_send_mail_thread(handle, NULL, &err)) { EM_DEBUG_EXCEPTION("emcore_cancel_send_mail_thread failed [%d]", err); - goto FINISH_OFF; } if(!emcore_delete_transaction_info_by_mailId(mail_id)) @@ -168,205 +164,16 @@ INTERNAL_FUNC int emdaemon_cancel_sending_mail_job(int account_id, int mail_id, FINISH_OFF: if(err_code != NULL) *err_code = err; - - if (ref_account) { - emcore_free_account(ref_account); - EM_SAFE_FREE(ref_account); - } - +#if 0 #ifdef __FEATURE_PROGRESS_IN_OUTBOX__ if(!emstorage_free_mail(&mail_tbl_data, 1, &err)) EM_DEBUG_EXCEPTION("emcore_free_mail Failed [%d ]", err); - +#endif #endif EM_DEBUG_FUNC_END(); return ret; } -static char *_make_time_string_to_time_t(time_t time) -{ - char *time_string = NULL; - struct tm *struct_time = NULL; - - if (!time) { - EM_DEBUG_EXCEPTION("Invalid paramter"); - return NULL; - } - - time_string = em_malloc(MAX_DATETIME_STRING_LENGTH); - if (time_string == NULL) { - EM_DEBUG_EXCEPTION("em_malloc failed"); - return NULL; - } - - struct_time = localtime(&time); - SNPRINTF(time_string, MAX_DATETIME_STRING_LENGTH, "%d/%d/%d", struct_time->tm_mon + 1, struct_time->tm_mday, struct_time->tm_year + 1900); - - EM_DEBUG_LOG("time string = [%s]", time_string); - return time_string; -} - -static char *_make_criteria_to_search_filter(email_search_filter_t *search_filter, int search_filter_count, int *err_code) -{ - EM_DEBUG_FUNC_BEGIN("search_filter : [%p], search_filter_count : [%d]", search_filter, search_filter_count); - - int i = 0; - int err = EMAIL_ERROR_NONE; - char *criteria = NULL; - char *temp_criteria = NULL; - char *time_string = NULL; - - if (search_filter == NULL || search_filter_count < 0) { - EM_DEBUG_EXCEPTION("Invalid paramter"); - err = EMAIL_ERROR_INVALID_PARAM; - goto FINISH_OFF; - } - - criteria = (char *)em_malloc(STRING_LENGTH_FOR_DISPLAY * search_filter_count); - if (criteria == NULL) { - EM_DEBUG_EXCEPTION("em_malloc failed"); - err = EMAIL_ERROR_OUT_OF_MEMORY; - goto FINISH_OFF; - } - - temp_criteria = (char *)em_malloc(STRING_LENGTH_FOR_DISPLAY); - if (temp_criteria == NULL) { - EM_DEBUG_EXCEPTION("em_malloc failed"); - err = EMAIL_ERROR_OUT_OF_MEMORY; - goto FINISH_OFF; - } - - for (i = 0; i < search_filter_count; i++) { - EM_DEBUG_LOG("search_filter_type [%d]", search_filter[i].search_filter_type); - memset(temp_criteria, 0x00, STRING_LENGTH_FOR_DISPLAY); - - switch (search_filter[i].search_filter_type) { - case EMAIL_SEARCH_FILTER_TYPE_MESSAGE_NO : - case EMAIL_SEARCH_FILTER_TYPE_UID : - case EMAIL_SEARCH_FILTER_TYPE_SIZE_LARSER : - case EMAIL_SEARCH_FILTER_TYPE_SIZE_SMALLER : - case EMAIL_SEARCH_FILTER_TYPE_FLAGS_ANSWERED : - case EMAIL_SEARCH_FILTER_TYPE_FLAGS_DELETED : - case EMAIL_SEARCH_FILTER_TYPE_FLAGS_DRAFT : - case EMAIL_SEARCH_FILTER_TYPE_FLAGS_FLAGED : - case EMAIL_SEARCH_FILTER_TYPE_FLAGS_RECENT : - case EMAIL_SEARCH_FILTER_TYPE_FLAGS_SEEN : - EM_DEBUG_LOG("integer_type_key_value [%d]", search_filter[i].search_filter_key_value.integer_type_key_value); - break; - - case EMAIL_SEARCH_FILTER_TYPE_BCC : - case EMAIL_SEARCH_FILTER_TYPE_CC : - case EMAIL_SEARCH_FILTER_TYPE_TO : - case EMAIL_SEARCH_FILTER_TYPE_MESSAGE_ID : - EM_DEBUG_LOG("string_type_key_value [%s]", search_filter[i].search_filter_key_value.string_type_key_value); - break; - - case EMAIL_SEARCH_FILTER_TYPE_FROM : - EM_DEBUG_LOG("string_type_key_value [%s]", search_filter[i].search_filter_key_value.string_type_key_value); - SNPRINTF(temp_criteria, STRING_LENGTH_FOR_DISPLAY, "from %s ", search_filter[i].search_filter_key_value.string_type_key_value); - strncat(criteria, temp_criteria, EM_SAFE_STRLEN(temp_criteria)); - break; - - case EMAIL_SEARCH_FILTER_TYPE_SUBJECT : - EM_DEBUG_LOG("string_type_key_value [%s]", search_filter[i].search_filter_key_value.string_type_key_value); - SNPRINTF(temp_criteria, STRING_LENGTH_FOR_DISPLAY, "subject %s ", search_filter[i].search_filter_key_value.string_type_key_value); - strncat(criteria, temp_criteria, EM_SAFE_STRLEN(temp_criteria)); - break; - - case EMAIL_SEARCH_FILTER_TYPE_KEYWORD : - EM_DEBUG_LOG("string_type_key_value [%s]", search_filter[i].search_filter_key_value.string_type_key_value); - SNPRINTF(temp_criteria, STRING_LENGTH_FOR_DISPLAY, "keyword %s ", search_filter[i].search_filter_key_value.string_type_key_value); - strncat(criteria, temp_criteria, EM_SAFE_STRLEN(temp_criteria)); - break; - - case EMAIL_SEARCH_FILTER_TYPE_SENT_DATE_BEFORE : - EM_DEBUG_LOG("time_type_key_value [%d]", search_filter[i].search_filter_key_value.time_type_key_value); - time_string = _make_time_string_to_time_t(search_filter[i].search_filter_key_value.time_type_key_value); - SNPRINTF(temp_criteria, STRING_LENGTH_FOR_DISPLAY, "before %s ", time_string); - strncat(criteria, temp_criteria, EM_SAFE_STRLEN(temp_criteria)); - break; - - case EMAIL_SEARCH_FILTER_TYPE_SENT_DATE_ON : - EM_DEBUG_LOG("time_type_key_value [%d]", search_filter[i].search_filter_key_value.time_type_key_value); - break; - - case EMAIL_SEARCH_FILTER_TYPE_SENT_DATE_SINCE : - EM_DEBUG_LOG("time_type_key_value [%d]", search_filter[i].search_filter_key_value.time_type_key_value); - time_string = _make_time_string_to_time_t(search_filter[i].search_filter_key_value.time_type_key_value); - SNPRINTF(temp_criteria, STRING_LENGTH_FOR_DISPLAY, "since %s ", time_string); - strncat(criteria, temp_criteria, EM_SAFE_STRLEN(temp_criteria)); - break; - - default : - EM_DEBUG_EXCEPTION("Invalid list_filter_item_type [%d]", search_filter); - err = EMAIL_ERROR_INVALID_PARAM; - goto FINISH_OFF; - } - EM_SAFE_FREE(time_string); /*prevent 26258*/ - } - -FINISH_OFF: - - EM_SAFE_FREE(temp_criteria); - EM_SAFE_FREE(time_string); - - if (err_code != NULL) - *err_code = err; - - EM_DEBUG_FUNC_END(); - return criteria; -} - -INTERNAL_FUNC int emdaemon_search_mail_on_server(int input_account_id, int input_mailbox_id, email_search_filter_t *input_search_filter, int input_search_filter_count, unsigned int *output_handle, int *err_code) -{ - EM_DEBUG_FUNC_BEGIN("input_account_id [%d], mailbox_id [%d], input_search_filter [%p], input_search_filter_count [%d], output_handle [%p]", input_account_id, input_mailbox_id, input_search_filter, input_search_filter_count, output_handle); - int error = EMAIL_ERROR_NONE; - int ret = false; - char *criteria = NULL; - email_event_t *event_data = NULL; - - if (input_mailbox_id == 0 || input_account_id < 0) { - EM_DEBUG_EXCEPTION("Invalid parameter"); - error = EMAIL_ERROR_INVALID_PARAM; - return false; - } - - criteria = _make_criteria_to_search_filter(input_search_filter, input_search_filter_count, &error); - if (criteria == NULL) { - EM_DEBUG_EXCEPTION("_make_criteria_to_search_filter failed"); - goto FINISH_OFF; - } - - event_data = em_malloc(sizeof(email_event_t)); - event_data->type = EMAIL_EVENT_SEARCH_ON_SERVER; - event_data->account_id = input_account_id; - event_data->event_param_data_1 = EM_SAFE_STRDUP(criteria); - event_data->event_param_data_4 = input_mailbox_id; - - if (!emcore_insert_event(event_data, (int *)output_handle, &error)) { - EM_DEBUG_EXCEPTION("emcore_insert_event failed [%d]", error); - error = EMAIL_ERROR_NONE; - goto FINISH_OFF; - } - - ret = true; - -FINISH_OFF: - - if (ret == false && event_data) { - emcore_free_event(event_data); - EM_SAFE_FREE(event_data); - } - - EM_SAFE_FREE(criteria); - - if (err_code != NULL) - *err_code = error; - - EM_DEBUG_FUNC_END("error [%d]", error); - return ret; -} - INTERNAL_FUNC int emdaemon_reschedule_sending_mail() { EM_DEBUG_FUNC_BEGIN(); @@ -429,6 +236,7 @@ INTERNAL_FUNC int emdaemon_reschedule_sending_mail() } FINISH_OFF: + EM_SAFE_FREE (conditional_clause_string); /* detected by valgrind */ EM_SAFE_FREE(result_mail_list); EM_DEBUG_FUNC_END("err [%d]", err); @@ -453,7 +261,7 @@ INTERNAL_FUNC int emdaemon_clear_all_mail_data(int* err_code) return false; } - emcore_display_unread_in_badge(); + emcore_display_unread_in_badge(NULL); ret = true; @@ -468,36 +276,12 @@ INTERNAL_FUNC int emdaemon_clear_all_mail_data(int* err_code) return ret; } -INTERNAL_FUNC int emdaemon_kill_daemon_if_no_account() -{ - EM_DEBUG_FUNC_BEGIN(); - int err = EMAIL_ERROR_NONE; - email_account_t *account_list = NULL; - int account_count = 0; - - if (!emcore_get_account_reference_list(&account_list, &account_count, &err)) { - EM_DEBUG_LOG("emcore_get_account_reference_list failed [%d]", err); - } - - EM_DEBUG_LOG("account_count [%d]", account_count); - - if (account_count == 0) { - EM_DEBUG_LOG("kill email-service daemon"); - exit(44); /* exit with exit code 44 to prevent restarting */ - } - - if(account_list) - emcore_free_account_list(&account_list, account_count, NULL); - - EM_DEBUG_FUNC_END("err [%d]", err); - return err; -} INTERNAL_FUNC int emdaemon_check_smack_rule(int app_sockfd, char *file_path) { EM_DEBUG_FUNC_BEGIN_SEC("app_sockfd[%d], file_path[%s]", app_sockfd, file_path); - if (app_sockfd <= 0 || !file_path) { + if (app_sockfd < 0 || !file_path) { EM_DEBUG_LOG("Invalid parameter"); return false; } @@ -584,7 +368,7 @@ INTERNAL_FUNC int emdaemon_set_smack_label(char *file_path, char *label) return result; } -INTERNAL_FUNC int emdaemon_finalize_sync(int account_id, int total_mail_count, int unread_mail_count, int *error) +INTERNAL_FUNC int emdaemon_finalize_sync(int account_id, int total_mail_count, int unread_mail_count, int vip_total_mail_count, int vip_unread_mail_count, int input_from_eas, int *error) { EM_DEBUG_FUNC_BEGIN("account_id [%d], total_mail_count [%d], unread_mail_count [%d], error [%p]", account_id, total_mail_count, unread_mail_count, error); int err = EMAIL_ERROR_NONE, ret = true, result_sync_status = SYNC_STATUS_FINISHED; @@ -593,43 +377,45 @@ INTERNAL_FUNC int emdaemon_finalize_sync(int account_id, int total_mail_count, i if ((err = emcore_update_sync_status_of_account(account_id, SET_TYPE_MINUS, SYNC_STATUS_SYNCING)) != EMAIL_ERROR_NONE) EM_DEBUG_EXCEPTION("emcore_update_sync_status_of_account failed [%d]", err); - if (!emstorage_get_sync_status_of_account(ALL_ACCOUNT, &result_sync_status, &err)) + if (!emstorage_get_sync_status_of_account(account_id, &result_sync_status, &err)) EM_DEBUG_EXCEPTION("emstorage_get_sync_status_of_account failed [%d]", err); /* Check the topmost of email app */ - if (vconf_get_int(VCONF_KEY_TOPMOST_WINDOW, &topmost) != 0) { - EM_DEBUG_EXCEPTION("vconf_get_int failed"); + if (input_from_eas) { + if (vconf_get_int(VCONF_KEY_TOPMOST_WINDOW, &topmost) != 0) { + EM_DEBUG_EXCEPTION("vconf_get_int failed"); + } } - +/* if (result_sync_status == SYNC_STATUS_SYNCING) { if (topmost) { EM_DEBUG_LOG("The email app is topmost"); + if (!emstorage_update_save_status(account_id, &err)) { + EM_DEBUG_EXCEPTION("emstorage_update_save_status failed : [%d]", err); + } } else { - if ((err = emcore_add_notification(account_id, 0, total_mail_count, 0, EMAIL_ERROR_NONE, NOTIFICATION_DISPLAY_APP_ALL^NOTIFICATION_DISPLAY_APP_TICKER)) != EMAIL_ERROR_NONE) + if ((err = emcore_add_notification(account_id, 0, unread_mail_count, vip_unread_mail_count, 0, EMAIL_ERROR_NONE, NOTIFICATION_DISPLAY_APP_ALL^NOTIFICATION_DISPLAY_APP_TICKER)) != EMAIL_ERROR_NONE) EM_DEBUG_EXCEPTION("emcore_add_notification failed : [%d]", err); } - } else if (result_sync_status == SYNC_STATUS_HAVE_NEW_MAILS) { + } else*/ if (result_sync_status == SYNC_STATUS_HAVE_NEW_MAILS) { if (topmost) { EM_DEBUG_LOG("The email app is topmost"); } else { - if ((err = emcore_add_notification(account_id, 0, total_mail_count, 1, EMAIL_ERROR_NONE, NOTIFICATION_DISPLAY_APP_ALL)) != EMAIL_ERROR_NONE) + emcore_set_flash_noti(); + + if ((err = emcore_add_notification(account_id, 0, unread_mail_count, vip_unread_mail_count, 1, EMAIL_ERROR_NONE, NOTIFICATION_DISPLAY_APP_ALL)) != EMAIL_ERROR_NONE) EM_DEBUG_EXCEPTION("emcore_add_notification failed : [%d]", err); #ifdef __FEATURE_BLOCKING_MODE__ emcore_set_blocking_mode_status(false); #endif /* __FEATURE_BLOCKING_MODE__ */ - if ((err = emcore_start_driving_mode(account_id)) != EMAIL_ERROR_NONE) { - EM_DEBUG_EXCEPTION("emcore_start_driving_mode failed : [%d]", err); - } + + if ((err = emcore_update_sync_status_of_account(account_id, SET_TYPE_MINUS, SYNC_STATUS_HAVE_NEW_MAILS)) != EMAIL_ERROR_NONE) + EM_DEBUG_EXCEPTION("emcore_update_sync_status_of_account failed [%d]", err); } - if (!emcore_display_unread_in_badge()) - EM_DEBUG_EXCEPTION("emcore_display_unread_in_badge failed"); - - if ((err = emcore_update_sync_status_of_account(account_id, SET_TYPE_MINUS, SYNC_STATUS_HAVE_NEW_MAILS)) != EMAIL_ERROR_NONE) - EM_DEBUG_EXCEPTION("emcore_update_sync_status_of_account failed [%d]", err); } else { EM_DEBUG_LOG("sync status : [%d]", result_sync_status); } diff --git a/email-daemon/email-daemon-event.c b/email-daemon/email-daemon-event.c index 7b96345..55ae974 100755 --- a/email-daemon/email-daemon-event.c +++ b/email-daemon/email-daemon-event.c @@ -26,6 +26,7 @@ #include <vconf.h> #include <signal.h> #include <contacts.h> +#include <contacts_internal.h> #include "c-client.h" #include "email-convert.h" #include "email-storage.h" @@ -44,7 +45,6 @@ #include "email-core-mailbox-sync.h" #include "email-core-smtp.h" #include "email-core-utils.h" -#include "email-core-sound.h" #include "email-core-signal.h" #include "email-debug-log.h" @@ -60,6 +60,10 @@ extern GQueue *g_event_que; extern int g_event_loop; extern int recv_thread_run; +#ifdef __FEATURE_WIFI_AUTO_DOWNLOAD__ +extern pthread_cond_t _auto_downalod_available_signal; +#endif + static void *worker_event_queue(void *arg); static int event_handler_EMAIL_EVENT_SYNC_HEADER(int input_account_id, int input_mailbox_id, int handle_to_be_published, int *error); static int event_handler_EMAIL_EVENT_VALIDATE_AND_CREATE_ACCOUNT(email_account_t *account, int handle_to_be_published, int *error); @@ -74,13 +78,12 @@ static int event_handler_EMAIL_EVENT_VALIDATE_ACCOUNT(int account_id, int handle static int event_handler_EMAIL_EVENT_UPDATE_MAIL(email_mail_data_t *input_mail_data, email_attachment_data_t *input_attachment_data_list, int input_attachment_count, email_meeting_request_t* input_meeting_request, int input_from_eas, int handle_to_be_published); static int event_handler_EMAIL_EVENT_SAVE_MAIL(int input_account_id, int input_mail_id, int input_handle_to_be_published); static int event_handler_EMAIL_EVENT_MOVE_MAIL(int account_id, int *mail_ids, int mail_id_count, int dest_mailbox_id, int src_mailbox_id, int handle_to_be_published, int *error); -static int event_handler_EMAIL_EVENT_DELETE_MAILBOX(int mailbox_id, int on_server, int recursive, int handle_to_be_published, int *error); -static int event_handler_EMAIL_EVENT_CREATE_MAILBOX(email_mailbox_t *input_new_mailbox, int on_server, int handle_to_be_published, int *error); -static int event_handler_EMAIL_EVENT_SYNC_MAIL_FLAG_TO_SERVER(int mail_id, int *error); +static int event_handler_EMAIL_EVENT_DELETE_MAILBOX(int mailbox_id, int on_server, int recursive, int handle_to_be_published); +static int event_handler_EMAIL_EVENT_CREATE_MAILBOX(email_mailbox_t *input_new_mailbox, int on_server, int handle_to_be_published); +static int event_handler_EMAIL_EVENT_SYNC_MAIL_FLAG_TO_SERVER(int mail_id, int event_handle, int *error); static int event_handler_EMAIL_EVENT_DELETE_MAIL_ALL(int input_account_id, int input_mailbox_id, int input_from_server, int *error); -static int event_handler_EMAIL_EVENT_DELETE_MAIL(int account_id, int *mail_id_list, int mail_id_count, int *error); +static int event_handler_EMAIL_EVENT_DELETE_MAIL(int account_id, int *mail_id_list, int mail_id_count, int from_server, int *error); static int event_hanlder_EMAIL_EVENT_SYNC_HEADER_OMA(int account_id, char *maibox_name, int handle_to_be_published, int *error); -static int event_handler_EMAIL_EVENT_SEARCH_ON_SERVER(int account_id, int mailbox_id, char *criteria, int handle_to_be_published, int *error); static int event_handler_EMAIL_EVENT_RENAME_MAILBOX_ON_IMAP_SERVER(int input_account_id, int input_mailbox_id, char *input_old_mailbox_path, char *input_new_mailbox_path, char *input_new_mailbox_alias, int handle_to_be_published); static void* worker_send_event_queue(void *arg); @@ -101,13 +104,77 @@ extern pthread_mutex_t _partial_body_thd_event_queue_lock; extern email_event_partial_body_thd g_partial_body_thd_event_que[TOTAL_PARTIAL_BODY_EVENTS]; extern email_event_partial_body_thd g_partial_body_bulk_dwd_que[BULK_PARTIAL_BODY_DOWNLOAD_COUNT]; extern int g_partial_body_thd_next_event_idx; -extern int g_partial_body_thd_loop; +//extern int g_partial_body_thd_loop; extern int g_partial_body_thd_queue_empty; extern int g_partial_body_thd_queue_full; extern int g_partial_body_bulk_dwd_queue_empty; +extern email_event_t *sync_failed_event_data; + static gpointer partial_body_download_thread(gpointer data); +#ifdef __FEATURE_OPEN_SSL_MULTIHREAD_HANDLE__ + +#include <openssl/crypto.h> + +#define MAX_THREAD_NUMBER 100 + +static pthread_mutex_t *lock_cs; +static long *lock_count; + +void pthreads_locking_callback(int mode, int type, char *file, int line) +{ + if (mode & CRYPTO_LOCK) { + pthread_mutex_lock(&(lock_cs[type])); + lock_count[type]++; + } + else { + pthread_mutex_unlock(&(lock_cs[type])); + } +} + +unsigned long pthreads_thread_id(void) +{ + return (unsigned long)pthread_self(); +} + +INTERNAL_FUNC void emdaemon_setup_handler_for_open_ssl_multithread(void) +{ + EM_DEBUG_FUNC_BEGIN(); + int i = 0; + + lock_cs = OPENSSL_malloc(CRYPTO_num_locks() * sizeof(pthread_mutex_t)); + lock_count = OPENSSL_malloc(CRYPTO_num_locks() * sizeof(long)); + + for (i = 0; i < CRYPTO_num_locks(); i++) { + lock_count[i] = 0; + pthread_mutex_init(&(lock_cs[i]),NULL); + } + + CRYPTO_set_id_callback((unsigned long (*)())pthreads_thread_id); + CRYPTO_set_locking_callback((void (*)())pthreads_locking_callback); + EM_DEBUG_FUNC_END(); +} + +INTERNAL_FUNC void emdaemon_cleanup_handler_for_open_ssl_multithread(void) +{ + EM_DEBUG_FUNC_BEGIN(); + int i = 0; + + CRYPTO_set_locking_callback(NULL); + for (i = 0; i < CRYPTO_num_locks(); i++) + { + pthread_mutex_destroy(&(lock_cs[i])); + EM_DEBUG_LOG("%8ld:%s",lock_count[i], CRYPTO_get_lock_name(i)); + } + OPENSSL_free(lock_cs); + OPENSSL_free(lock_count); + + EM_DEBUG_FUNC_END(); +} + +#endif /* __FEATURE_OPEN_SSL_MULTIHREAD_HANDLE__ */ + /* start api event_data loop */ INTERNAL_FUNC int emdaemon_start_event_loop(int *err_code) { @@ -208,6 +275,8 @@ static void* worker_event_queue(void *arg) email_event_t *started_event = NULL; emstorage_account_tbl_t *account_tbl = NULL; int handle_to_be_published = 0; + int pbd_thd_state = 0; + int send_event_que_state = 0; if (!emstorage_open(&err)) { EM_DEBUG_EXCEPTION("emstorage_open falied [%d]", err); @@ -217,6 +286,9 @@ static void* worker_event_queue(void *arg) /* check that event_data loop is continuous */ while (emcore_event_loop_continue()) { + pbd_thd_state = emcore_get_pbd_thd_state(); + send_event_que_state = emcore_is_send_event_queue_empty(); + /* get a event_data from event_data queue */ ENTER_RECURSIVE_CRITICAL_SECTION(_event_queue_lock); if (!emcore_retrieve_event(&event_data, &err)) { @@ -227,7 +299,20 @@ static void* worker_event_queue(void *arg) } recv_thread_run = 0; - emdevice_set_sleep_on_off(true, NULL); + emdevice_set_sleep_on_off(STAY_AWAKE_FLAG_FOR_RECEVING_WORKER, true, NULL); + +#ifdef __FEATURE_WIFI_AUTO_DOWNLOAD__ + int wifi_status = 0; + if ((err = emnetwork_get_wifi_status(&wifi_status)) != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emnetwork_get_wifi_status failed [%d]", err); + } + + EM_DEBUG_LOG("WIFI Status [%d]", wifi_status); + + if (!pbd_thd_state && send_event_que_state && wifi_status > 1) { + WAKE_CONDITION_VARIABLE(_auto_downalod_available_signal); + } +#endif //go to sleep when queue is empty SLEEP_CONDITION_VARIABLE(_event_available_signal, *_event_queue_lock); @@ -238,7 +323,7 @@ static void* worker_event_queue(void *arg) LEAVE_RECURSIVE_CRITICAL_SECTION(_event_queue_lock); EM_DEBUG_LOG_DEV(">>>>>>>>>>>>>>> Got event_data !!! <<<<<<<<<<<<<<<"); - emdevice_set_sleep_on_off(false, NULL); + emdevice_set_sleep_on_off(STAY_AWAKE_FLAG_FOR_RECEVING_WORKER, false, NULL); handle_to_be_published = event_data->handle; EM_DEBUG_LOG("Handle to be Published [%d]", handle_to_be_published); @@ -251,7 +336,7 @@ static void* worker_event_queue(void *arg) event_data->type == EMAIL_EVENT_DOWNLOAD_BODY || event_data->type == EMAIL_EVENT_DOWNLOAD_ATTACHMENT) { - if (emcore_is_storage_full(&err)) { + if ((err = emcore_is_storage_full()) == EMAIL_ERROR_MAIL_MEMORY_FULL) { EM_DEBUG_EXCEPTION("Storage is full"); switch (event_data->type) { case EMAIL_EVENT_SYNC_HEADER: @@ -317,7 +402,7 @@ static void* worker_event_queue(void *arg) break; case EMAIL_EVENT_DELETE_MAIL: /* delete mails */ - event_handler_EMAIL_EVENT_DELETE_MAIL(event_data->account_id, (int*)event_data->event_param_data_3, event_data->event_param_data_4, &err); + event_handler_EMAIL_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_5, &err); break; case EMAIL_EVENT_DELETE_MAIL_ALL: /* delete all mails */ @@ -325,21 +410,16 @@ static void* worker_event_queue(void *arg) break; #ifdef __FEATURE_SYNC_CLIENT_TO_SERVER__ case EMAIL_EVENT_SYNC_MAIL_FLAG_TO_SERVER: - event_handler_EMAIL_EVENT_SYNC_MAIL_FLAG_TO_SERVER((int)event_data->event_param_data_4, &err); + event_handler_EMAIL_EVENT_SYNC_MAIL_FLAG_TO_SERVER((int)event_data->event_param_data_4, handle_to_be_published, &err); break; #endif - case EMAIL_EVENT_CREATE_MAILBOX: { - email_mailbox_t *new_mailbox = (email_mailbox_t*)event_data->event_param_data_1; - - if(new_mailbox) { - event_handler_EMAIL_EVENT_CREATE_MAILBOX(new_mailbox, event_data->event_param_data_4, handle_to_be_published, &err); - } - } + case EMAIL_EVENT_CREATE_MAILBOX: + err = event_handler_EMAIL_EVENT_CREATE_MAILBOX((email_mailbox_t *)event_data->event_param_data_1, event_data->event_param_data_4, handle_to_be_published); break; case EMAIL_EVENT_DELETE_MAILBOX: - event_handler_EMAIL_EVENT_DELETE_MAILBOX(event_data->event_param_data_4, event_data->event_param_data_5, event_data->event_param_data_6,handle_to_be_published, &err); + err = event_handler_EMAIL_EVENT_DELETE_MAILBOX(event_data->event_param_data_4, event_data->event_param_data_5, event_data->event_param_data_6,handle_to_be_published); break; case EMAIL_EVENT_SAVE_MAIL: @@ -386,14 +466,10 @@ static void* worker_event_queue(void *arg) #ifdef __FEATURE_LOCAL_ACTIVITY__ case EMAIL_EVENT_LOCAL_ACTIVITY: - event_handler_EMAIL_EVENT_LOCAL_ACTIVITY(event_data->account_id, &err); + event_handler_EMAIL_EVENT_LOCAL_ACTIVITY(event_data->account_id, handle_to_be_published, &err); break; #endif /* __FEATURE_LOCAL_ACTIVITY__*/ - case EMAIL_EVENT_SEARCH_ON_SERVER: - event_handler_EMAIL_EVENT_SEARCH_ON_SERVER(event_data->account_id, event_data->event_param_data_4, (char *)event_data->event_param_data_1, handle_to_be_published, &err); - break; - case EMAIL_EVENT_RENAME_MAILBOX_ON_IMAP_SERVER: err = event_handler_EMAIL_EVENT_RENAME_MAILBOX_ON_IMAP_SERVER(event_data->account_id, event_data->event_param_data_4, (char*)event_data->event_param_data_1, (char*)event_data->event_param_data_2, (char*)event_data->event_param_data_3, handle_to_be_published); break; @@ -408,6 +484,32 @@ static void* worker_event_queue(void *arg) } } + if ((event_data->type == EMAIL_EVENT_SYNC_HEADER || event_data->type == EMAIL_EVENT_SYNC_IMAP_MAILBOX) && (err != EMAIL_ERROR_NONE)) { + /* for the retry syncing */ + if (sync_failed_event_data) { + emcore_free_event(sync_failed_event_data); + EM_SAFE_FREE(sync_failed_event_data); + sync_failed_event_data = NULL; + } + + sync_failed_event_data = em_malloc(sizeof(email_event_t)); + + if (event_data->type == EMAIL_EVENT_SYNC_IMAP_MAILBOX) { + sync_failed_event_data->type = EMAIL_EVENT_SYNC_IMAP_MAILBOX; + sync_failed_event_data->account_id = event_data->account_id; + sync_failed_event_data->status = EMAIL_EVENT_STATUS_WAIT; + sync_failed_event_data->event_param_data_3 = EM_SAFE_STRDUP(event_data->event_param_data_3); + } + + if (event_data->type == EMAIL_EVENT_SYNC_HEADER) { + sync_failed_event_data->type = EMAIL_EVENT_SYNC_HEADER; + sync_failed_event_data->account_id = event_data->account_id; + sync_failed_event_data->status = EMAIL_EVENT_STATUS_WAIT; + sync_failed_event_data->event_param_data_5 = event_data->event_param_data_5; + sync_failed_event_data->event_param_data_4 = event_data->event_param_data_4; + } + } + /* free internals in event */ emcore_free_event(event_data); /*detected by valgrind*/ @@ -437,6 +539,7 @@ static void* worker_event_queue(void *arg) if (!emstorage_close(&err)) EM_DEBUG_EXCEPTION("emstorage_close falied [%d]", err); + emcore_close_recv_stream_list(); EM_DEBUG_FUNC_END(); return SUCCESS; } @@ -451,6 +554,8 @@ static int event_handler_EMAIL_EVENT_SYNC_HEADER (int input_account_id, int inpu int mailbox_count = 0, account_count = 0; int counter, account_index; int unread = 0, total_unread = 0; + int vip_unread = 0, vip_total_unread = 0; + int vip_mail_count = 0, vip_total_mail = 0; int mail_count = 0, total_mail = 0; emcore_uid_list *uid_list = NULL; emstorage_account_tbl_t *account_tbl_array = NULL; @@ -464,6 +569,25 @@ static int event_handler_EMAIL_EVENT_SYNC_HEADER (int input_account_id, int inpu if (input_mailbox_id == 0) sync_type = EMAIL_SYNC_ALL_MAILBOX; else { + email_account_t *ref_account = NULL; + int sync_disabled = 0; + + ref_account = emcore_get_account_reference(input_account_id); + + if (ref_account) { + sync_disabled = ref_account->sync_disabled; + emcore_free_account(ref_account); + EM_SAFE_FREE(ref_account); + } + + EM_DEBUG_LOG("sync_disabled[%d]", sync_disabled); + + if (sync_disabled) { + err = EMAIL_ERROR_ACCOUNT_SYNC_IS_DISALBED; + EM_DEBUG_LOG("Sync disabled for this account. Do not sync."); + goto FINISH_OFF; + } + if (!emstorage_get_mailbox_by_id(input_mailbox_id, &mailbox_tbl_target) || !mailbox_tbl_target) { EM_DEBUG_EXCEPTION("emstorage_get_mailbox_by_id failed [%d]", err); goto FINISH_OFF; @@ -489,7 +613,8 @@ static int event_handler_EMAIL_EVENT_SYNC_HEADER (int input_account_id, int inpu if ((err = emcore_update_sync_status_of_account(input_account_id, SET_TYPE_SET, SYNC_STATUS_SYNCING)) != EMAIL_ERROR_NONE) EM_DEBUG_EXCEPTION("emcore_update_sync_status_of_account failed [%d]", err); - if (!emcore_sync_header (mailbox_tbl_target, (void**) &stream, &uid_list, &mail_count, &unread, &err)) { + if (!emcore_sync_header (mailbox_tbl_target, (void**) &stream, + &uid_list, &mail_count, &unread, &vip_mail_count, &vip_unread, 1, handle_to_be_published, &err)) { EM_DEBUG_EXCEPTION("emcore_sync_header failed [%d]", err); if (!emcore_notify_network_event(NOTI_DOWNLOAD_FAIL, mailbox_tbl_target->account_id, mailbox_id_param_string, handle_to_be_published, err)) EM_DEBUG_EXCEPTION(" emcore_notify_network_event [NOTI_DOWNLOAD_FAIL] Failed >>>> "); @@ -499,17 +624,37 @@ static int event_handler_EMAIL_EVENT_SYNC_HEADER (int input_account_id, int inpu if (!emcore_notify_network_event(NOTI_DOWNLOAD_FINISH, mailbox_tbl_target->account_id, mailbox_id_param_string, handle_to_be_published, 0)) EM_DEBUG_EXCEPTION("emcore_notify_network_event [NOTI_DOWNLOAD_FINISH] Failed >>>> "); } + stream = mail_close (stream); - total_unread += unread; - total_mail += mail_count; - if (total_unread > 0 && (err = emcore_update_sync_status_of_account(input_account_id, SET_TYPE_UNION, SYNC_STATUS_HAVE_NEW_MAILS)) != EMAIL_ERROR_NONE) - EM_DEBUG_EXCEPTION("emcore_update_sync_status_of_account failed [%d]", err); + total_unread += unread; + vip_total_unread += vip_unread; + total_mail += mail_count; + vip_total_mail += vip_mail_count; + + if (total_unread > 0 && (emcore_update_sync_status_of_account(input_account_id, SET_TYPE_UNION, SYNC_STATUS_HAVE_NEW_MAILS)) != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emcore_update_sync_status_of_account failed"); + } else { + if ((err = emcore_update_sync_status_of_account(input_account_id, SET_TYPE_MINUS, SYNC_STATUS_SYNCING)) != EMAIL_ERROR_NONE) + EM_DEBUG_EXCEPTION("emcore_update_sync_status_of_account failed [%d]", err); + } + + if (!emstorage_get_account_by_id(input_account_id, EMAIL_ACC_GET_OPT_DEFAULT, &account_tbl_array, true, &err)) { + EM_DEBUG_EXCEPTION("emstorage_get_account_by_id failed [ %d ] ", err); + } - if (!emdaemon_finalize_sync(input_account_id, total_mail, total_unread, &err)) - EM_DEBUG_EXCEPTION("emdaemon_finalize_sync failed [%d]", err); + if (account_tbl_array && account_tbl_array->auto_download_size == 0) { + if (!emdaemon_finalize_sync(input_account_id, 0, 0, 0, 0, true, NULL)) + EM_DEBUG_EXCEPTION("emdaemon_finalize_sync failed"); + } + + if (account_tbl_array) + emstorage_free_account(&account_tbl_array, 1, NULL); + + if (mailbox_tbl_target->mailbox_type == EMAIL_MAILBOX_TYPE_INBOX) + emcore_display_unread_in_badge(NULL); } - else /* All Foder */ { + else /* All Folder */ { EM_DEBUG_LOG ("sync start for all mailbox: account_id [%d]", input_account_id); /* Sync of all mailbox */ @@ -543,6 +688,11 @@ static int event_handler_EMAIL_EVENT_SYNC_HEADER (int input_account_id, int inpu continue; } + if (account_tbl_array[account_index].sync_disabled == 1) { + EM_DEBUG_LOG ("account[%d] is sync-disabled. Skip ", account_index); + continue; + } +/* folder sync is also necessary */ if (!emstorage_get_mailbox_list (account_tbl_array[account_index].account_id, 0, EMAIL_MAILBOX_SORT_BY_TYPE_ASC, &mailbox_count, &mailbox_tbl_list, true, &err) || mailbox_count <= 0) { @@ -579,7 +729,7 @@ static int event_handler_EMAIL_EVENT_SYNC_HEADER (int input_account_id, int inpu for (counter = 0; counter < mailbox_count; counter++) { EM_DEBUG_LOG_SEC("mailbox_name [%s], mailbox_id [%d], mailbox_type [%d]", mailbox_tbl_list[counter].mailbox_name, mailbox_tbl_list[counter].mailbox_id, mailbox_tbl_list[counter].mailbox_type); - unread = mail_count = 0; + vip_unread = unread = mail_count = 0; if ( mailbox_tbl_list[counter].mailbox_type == EMAIL_MAILBOX_TYPE_ALL_EMAILS || mailbox_tbl_list[counter].mailbox_type == EMAIL_MAILBOX_TYPE_TRASH /*|| mailbox_tbl_list[counter].mailbox_type == EMAIL_MAILBOX_TYPE_SPAMBOX */) { @@ -589,11 +739,17 @@ static int event_handler_EMAIL_EVENT_SYNC_HEADER (int input_account_id, int inpu else if (!mailbox_tbl_list[counter].local_yn) { EM_DEBUG_LOG_SEC("[%s] Syncing...", mailbox_tbl_list[counter].mailbox_name); #ifdef __FEATURE_KEEP_CONNECTION__ - if (!emcore_sync_header ((mailbox_tbl_list + counter), (void **)&stream, &uid_list, - &mail_count, &unread, &err)) + if (!emcore_sync_header ((mailbox_tbl_list + counter), + (void **)&stream, + &uid_list, + &mail_count, + &unread, &vip_mail_count, &vip_unread, 1, handle_to_be_published, &err)) #else /* __FEATURE_KEEP_CONNECTION__ */ - if (!emcore_sync_header ((mailbox_tbl_list + counter), (void **)&stream, &uid_list, - &mail_count, &unread, &err)) + if (!emcore_sync_header ((mailbox_tbl_list + counter), + (void **)&stream, + &uid_list, + &mail_count, + &unread, &vip_mail_count, &vip_unread, 1, handle_to_be_published, &err)) #endif /* __FEATURE_KEEP_CONNECTION__ */ { EM_DEBUG_EXCEPTION_SEC ("emcore_sync_header for %s(mailbox_id = %d) failed [%d]", @@ -617,19 +773,34 @@ static int event_handler_EMAIL_EVENT_SYNC_HEADER (int input_account_id, int inpu } EM_DEBUG_LOG_SEC("---mailbox %s has unread %d / %d", mailbox_tbl_list[counter].mailbox_name, unread, mail_count); - total_unread += unread; - total_mail += mail_count; + total_unread += unread; + vip_total_unread += vip_unread; + total_mail += mail_count; + vip_total_mail += vip_mail_count; + + if (mailbox_tbl_list[counter].mailbox_type == EMAIL_MAILBOX_TYPE_INBOX) + emcore_display_unread_in_badge(NULL); + } EM_DEBUG_LOG_SEC("Sync for account_id(%d) is completed....! (unread %d/%d)", account_tbl_array[account_index].account_id, total_unread, total_mail); + EM_DEBUG_LOG_SEC("Sync for account_id(%d) is completed....! (vip_unread %d/%d)", account_tbl_array[account_index].account_id, vip_total_unread, vip_total_mail); + if ((err == EMAIL_ERROR_NONE) && !emcore_notify_network_event(NOTI_DOWNLOAD_FINISH, account_tbl_array[account_index].account_id, NULL, handle_to_be_published, 0)) EM_DEBUG_EXCEPTION(" emcore_notify_network_event [ NOTI_DOWNLOAD_FINISH] Failed >>>> "); - if ((total_unread > 0) && (err = emcore_update_sync_status_of_account(account_tbl_array[account_index].account_id, SET_TYPE_UNION, SYNC_STATUS_HAVE_NEW_MAILS)) != EMAIL_ERROR_NONE) - EM_DEBUG_EXCEPTION("emcore_update_sync_status_of_account failed [%d]", err); + if ((total_unread > 0) && (emcore_update_sync_status_of_account(account_tbl_array[account_index].account_id, SET_TYPE_UNION, SYNC_STATUS_HAVE_NEW_MAILS)) != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emcore_update_sync_status_of_account failed"); + } else { + if ((err = emcore_update_sync_status_of_account(input_account_id, SET_TYPE_MINUS, SYNC_STATUS_SYNCING)) != EMAIL_ERROR_NONE) + EM_DEBUG_EXCEPTION("emcore_update_sync_status_of_account failed [%d]", err); + } + + if (account_tbl_array[account_index].auto_download_size == 0) { + if (!emdaemon_finalize_sync(account_tbl_array[account_index].account_id, 0, 0, 0, 0, true, NULL)) + EM_DEBUG_EXCEPTION("emdaemon_finalize_sync failed"); + } - if (!emdaemon_finalize_sync(account_tbl_array[account_index].account_id, total_mail, total_unread, &err)) - EM_DEBUG_EXCEPTION("emdaemon_finalize_sync failed [%d]", err); #ifndef __FEATURE_KEEP_CONNECTION__ if (stream) stream = mail_close (stream); @@ -650,6 +821,9 @@ FINISH_OFF: if (stream) stream = mail_close (stream); #endif + if (error) + *error = err; + if(mailbox_tbl_target) emstorage_free_mailbox(&mailbox_tbl_target, 1, NULL); @@ -667,6 +841,7 @@ static int event_handler_EMAIL_EVENT_VALIDATE_AND_CREATE_ACCOUNT(email_account_t { EM_DEBUG_FUNC_BEGIN("account [%p]", account); int err, ret = false; + char *imap_cap_string = NULL; if(!account) { EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM"); @@ -686,7 +861,7 @@ static int event_handler_EMAIL_EVENT_VALIDATE_AND_CREATE_ACCOUNT(email_account_t else { EM_DEBUG_LOG_SEC("incoming_server_address : %s", account->incoming_server_address); - if (!emcore_validate_account_with_account_info(account, EMAIL_EVENT_VALIDATE_AND_CREATE_ACCOUNT, &err)) { + if (!emcore_validate_account_with_account_info(account, EMAIL_EVENT_VALIDATE_AND_CREATE_ACCOUNT, &imap_cap_string, handle_to_be_published, &err)) { emcore_delete_account_from_unvalidated_account_list(account->account_id); EM_DEBUG_EXCEPTION("emcore_validate_account_with_account_info failed err : %d", err); if (err == EMAIL_ERROR_CANCELLED) { @@ -701,26 +876,25 @@ static int event_handler_EMAIL_EVENT_VALIDATE_AND_CREATE_ACCOUNT(email_account_t else { emcore_delete_account_from_unvalidated_account_list(account->account_id); - if (emcore_create_account(account, &err) == false) { + if (emcore_create_account(account, false, &err) == false) { EM_DEBUG_EXCEPTION(" emdaemon_create_account failed - %d", err); goto FINISH_OFF; } emcore_init_account_reference(); - EM_DEBUG_LOG("incoming_server_type [%d]", account->incoming_server_type); if ((EMAIL_SERVER_TYPE_IMAP4 == account->incoming_server_type)) { if (!emcore_sync_mailbox_list(account->account_id, "", handle_to_be_published, &err)) { EM_DEBUG_EXCEPTION("emcore_get_mailbox_list_to_be_sync failed [%d]", err); /* delete account whose mailbox couldn't be obtained from server */ - emcore_delete_account(account->account_id, NULL); + emcore_delete_account(account->account_id, false, NULL); goto FINISH_OFF; } } EM_DEBUG_LOG("validating and creating an account are succeeded for account id [%d] err [%d]", account->account_id, err); - if (!emcore_notify_network_event(NOTI_VALIDATE_AND_CREATE_ACCOUNT_FINISH, account->account_id, NULL, handle_to_be_published, err)) + if (!emcore_notify_network_event(NOTI_VALIDATE_AND_CREATE_ACCOUNT_FINISH, account->account_id, imap_cap_string, handle_to_be_published, err)) EM_DEBUG_EXCEPTION("emcore_notify_network_event [ NOTI_VALIDATE_ACCOUNT_FINISH] Success"); } } @@ -733,6 +907,8 @@ FINISH_OFF: EM_DEBUG_EXCEPTION(" emcore_notify_network_event [ NOTI_VALIDATE_AND_CREATE_ACCOUNT_FAIL] Failed"); } + EM_SAFE_FREE(imap_cap_string); + if (error) *error = err; @@ -744,6 +920,7 @@ static int event_handler_EMAIL_EVENT_VALIDATE_ACCOUNT_EX(email_account_t *input_ { EM_DEBUG_FUNC_BEGIN("input_account [%p]", input_account); int err = EMAIL_ERROR_NONE; + char *server_capability_string = NULL; if(!input_account) { EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM"); @@ -763,7 +940,7 @@ static int event_handler_EMAIL_EVENT_VALIDATE_ACCOUNT_EX(email_account_t *input_ else { EM_DEBUG_LOG_SEC("incoming_server_address : %s", input_account->incoming_server_address); - if (!emcore_validate_account_with_account_info(input_account, EMAIL_EVENT_VALIDATE_ACCOUNT_EX, &err)) { + if (!emcore_validate_account_with_account_info(input_account, EMAIL_EVENT_VALIDATE_ACCOUNT_EX, &server_capability_string, input_handle_to_be_published, &err)) { emcore_delete_account_from_unvalidated_account_list(input_account->account_id); EM_DEBUG_EXCEPTION("emcore_validate_account_with_account_info failed err : %d", err); @@ -781,7 +958,7 @@ static int event_handler_EMAIL_EVENT_VALIDATE_ACCOUNT_EX(email_account_t *input_ emcore_delete_account_from_unvalidated_account_list(input_account->account_id); EM_DEBUG_LOG("validating an account are succeeded for account id [%d] err [%d]", input_account->account_id, err); - if (!emcore_notify_network_event(NOTI_VALIDATE_ACCOUNT_FINISH, input_account->account_id, NULL, input_handle_to_be_published, err)) + if (!emcore_notify_network_event(NOTI_VALIDATE_ACCOUNT_FINISH, input_account->account_id, server_capability_string, input_handle_to_be_published, err)) EM_DEBUG_EXCEPTION("emcore_notify_network_event [ NOTI_VALIDATE_ACCOUNT_FINISH] Success"); } } @@ -792,6 +969,8 @@ FINISH_OFF: EM_DEBUG_EXCEPTION(" emcore_notify_network_event [ NOTI_VALIDATE_ACCOUNT_FAIL] Failed"); } + EM_SAFE_FREE(server_capability_string); + EM_DEBUG_FUNC_END("err[%d]", err); return err; } @@ -800,7 +979,9 @@ static int event_handler_EMAIL_EVENT_VALIDATE_AND_UPDATE_ACCOUNT(int account_id, { EM_DEBUG_FUNC_BEGIN("account_id [%d], new_account_info [%p]", account_id, new_account_info); int err, ret = false; + char *imap_cap_string = NULL; emstorage_account_tbl_t *old_account_tbl = NULL, *new_account_tbl = NULL; + email_account_t *duplicated_account_info = NULL, *old_account_info = NULL; if (!new_account_info) { EM_DEBUG_EXCEPTION("Invalid Parameter"); @@ -811,18 +992,62 @@ static int event_handler_EMAIL_EVENT_VALIDATE_AND_UPDATE_ACCOUNT(int account_id, if (!emnetwork_check_network_status(&err)) { EM_DEBUG_EXCEPTION("emnetwork_check_network_status failed [%d]", err); - if (!emcore_notify_network_event(NOTI_VALIDATE_AND_UPDATE_ACCOUNT_FAIL, new_account_info->account_id, NULL, handle_to_be_published, err)) + if (!emcore_notify_network_event(NOTI_VALIDATE_AND_UPDATE_ACCOUNT_FAIL, account_id, NULL, handle_to_be_published, err)) EM_DEBUG_EXCEPTION("emcore_notify_network_event [ NOTI_VALIDATE_AND_UPDATE_ACCOUNT_FAIL] Failed >>>> "); goto FINISH_OFF; } else { EM_DEBUG_LOG_SEC("incoming_server_address: (%s)", new_account_info->incoming_server_address); - if (!emcore_validate_account_with_account_info(new_account_info, EMAIL_EVENT_VALIDATE_AND_UPDATE_ACCOUNT, &err)) { + /* If the password fields are empty, fill the fields with password of old information*/ + if((old_account_info = emcore_get_account_reference(account_id)) == NULL) { + EM_DEBUG_EXCEPTION("emcore_get_account_reference failed "); + goto FINISH_OFF; + } + + EM_DEBUG_LOG_SEC("old_account_info->incoming_server_password [%s]", old_account_info->incoming_server_password); + + if( EM_SAFE_STRLEN (new_account_info->incoming_server_password) == 0 ) { + EM_SAFE_FREE(new_account_info->incoming_server_password); /* be allocated but has zero length */ + EM_DEBUG_LOG_SEC("old_account_info->incoming_server_password [%s]", old_account_info->incoming_server_password); + new_account_info->incoming_server_password = EM_SAFE_STRDUP(old_account_info->incoming_server_password); + if(new_account_info->incoming_server_password == NULL) { + EM_DEBUG_EXCEPTION("allocation for new_account_info->password failed"); + err = EMAIL_ERROR_OUT_OF_MEMORY; + goto FINISH_OFF; + } + } + + EM_DEBUG_LOG_SEC("old_account_info->outgoing_server_password [%s]", old_account_info->outgoing_server_password); + + if( EM_SAFE_STRLEN (new_account_info->outgoing_server_password) == 0 ) { + EM_SAFE_FREE(new_account_info->outgoing_server_password); + if(old_account_info->outgoing_server_password) { + new_account_info->outgoing_server_password = EM_SAFE_STRDUP(old_account_info->outgoing_server_password); + if(new_account_info->outgoing_server_password == NULL) { + EM_DEBUG_EXCEPTION("allocation for new_account_info->outgoing_server_password failed"); + err = EMAIL_ERROR_OUT_OF_MEMORY; + goto FINISH_OFF; + } + } + } + + emcore_duplicate_account(new_account_info, &duplicated_account_info, &err); + if (err != EMAIL_ERROR_NONE ) { + EM_DEBUG_EXCEPTION("emcore_duplicate_account failed [%d]", err); + goto FINISH_OFF; + } + + if((err = emcore_add_account_to_unvalidated_account_list(duplicated_account_info)) != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emcore_add_account_to_unvalidated_account_list failed [%d]", err); + goto FINISH_OFF; + } + + if (!emcore_validate_account_with_account_info(duplicated_account_info, EMAIL_EVENT_VALIDATE_AND_UPDATE_ACCOUNT, &imap_cap_string, handle_to_be_published, &err)) { EM_DEBUG_EXCEPTION("emcore_validate_account_with_account_info() failed err : %d", err); if (err == EMAIL_ERROR_CANCELLED) { EM_DEBUG_EXCEPTION(" notify : NOTI_VALIDATE_AND_CREATE_ACCOUNT_CANCEL "); - if (!emcore_notify_network_event(NOTI_VALIDATE_AND_UPDATE_ACCOUNT_CANCEL, new_account_info->account_id, NULL, handle_to_be_published, err)) + if (!emcore_notify_network_event(NOTI_VALIDATE_AND_UPDATE_ACCOUNT_CANCEL, account_id, NULL, handle_to_be_published, err)) EM_DEBUG_EXCEPTION("emcore_notify_network_event [ NOTI_VALIDATE_AND_UPDATE_ACCOUNT_CANCEL] Failed"); goto FINISH_OFF; } @@ -835,6 +1060,7 @@ static int event_handler_EMAIL_EVENT_VALIDATE_AND_UPDATE_ACCOUNT(int account_id, EM_DEBUG_EXCEPTION("emstorage_get_account_by_id failed [%d]", err); /* goto FINISH_OFF; */ } + duplicated_account_info->account_id = account_id; new_account_tbl = em_malloc(sizeof(emstorage_account_tbl_t)); if (!new_account_tbl) { @@ -842,14 +1068,14 @@ static int event_handler_EMAIL_EVENT_VALIDATE_AND_UPDATE_ACCOUNT(int account_id, goto FINISH_OFF; } - em_convert_account_to_account_tbl(new_account_info, new_account_tbl); + em_convert_account_to_account_tbl(duplicated_account_info, new_account_tbl); if (emstorage_update_account(account_id, new_account_tbl, true, &err)) { emcore_init_account_reference(); } - EM_DEBUG_LOG("validating and updating an account are succeeded for account id [%d], err [%d]", new_account_info->account_id, err); - if (!emcore_notify_network_event(NOTI_VALIDATE_AND_UPDATE_ACCOUNT_FINISH, new_account_info->account_id, NULL, handle_to_be_published, err)) + EM_DEBUG_LOG("validating and updating an account are succeeded for account id [%d], err [%d]", duplicated_account_info->account_id, err); + if (!emcore_notify_network_event(NOTI_VALIDATE_AND_UPDATE_ACCOUNT_FINISH, new_account_info->account_id, imap_cap_string, handle_to_be_published, err)) EM_DEBUG_EXCEPTION(" emcore_notify_network_event [NOTI_VALIDATE_AND_UPDATE_ACCOUNT_FINISH] Success"); } } @@ -857,16 +1083,33 @@ static int event_handler_EMAIL_EVENT_VALIDATE_AND_UPDATE_ACCOUNT(int account_id, ret = true; FINISH_OFF: + + if (duplicated_account_info) { + if (duplicated_account_info->account_id < 0) + emcore_delete_account_from_unvalidated_account_list(duplicated_account_info->account_id); + else { + emcore_free_account(duplicated_account_info); + EM_SAFE_FREE(duplicated_account_info); + } + } + + if (old_account_info) { + emcore_free_account(old_account_info); + EM_SAFE_FREE(old_account_info); + } + if (old_account_tbl) emstorage_free_account(&old_account_tbl, 1, NULL); if (new_account_tbl) emstorage_free_account(&new_account_tbl, 1, NULL); - if (ret == false && err != EMAIL_ERROR_CANCELLED && new_account_info) { - if (!emcore_notify_network_event(NOTI_VALIDATE_AND_UPDATE_ACCOUNT_FAIL, new_account_info->account_id, NULL, handle_to_be_published, err)) + if (ret == false && err != EMAIL_ERROR_CANCELLED) { + if (!emcore_notify_network_event(NOTI_VALIDATE_AND_UPDATE_ACCOUNT_FAIL, account_id, NULL, handle_to_be_published, err)) EM_DEBUG_EXCEPTION(" emcore_notify_network_event [ NOTI_VALIDATE_AND_CREATE_ACCOUNT_FAIL] Failed"); } + EM_SAFE_FREE(imap_cap_string); + if (error) *error = err; @@ -906,7 +1149,7 @@ FINISH_OFF: } #ifdef __FEATURE_LOCAL_ACTIVITY__ -static int event_handler_EMAIL_EVENT_LOCAL_ACTIVITY(int account_id, int *error) +static int event_handler_EMAIL_EVENT_LOCAL_ACTIVITY(int account_id, int event,handle, int *error) { EM_DEBUG_FUNC_BEGIN(); @@ -1043,17 +1286,57 @@ static int event_handler_EMAIL_EVENT_DOWNLOAD_BODY(int account_id, int mail_id, emcore_notify_network_event(NOTI_DOWNLOAD_BODY_FAIL, mail_id, NULL, handle_to_be_published, err); } else { +#ifdef __FEATURE_USE_GMIME__ + emstorage_mail_tbl_t *mail = NULL; + MAILSTREAM *tmp_stream = NULL; + + if (!emstorage_get_mail_by_id (mail_id, &mail, true, &err) || !mail) { + EM_DEBUG_EXCEPTION("emstorage_get_mail_by_id failed [%d]", err); + emcore_notify_network_event(NOTI_DOWNLOAD_BODY_FAIL, mail_id, NULL, handle_to_be_published, err); + goto FINISH_OFF; + } + + + if (!emcore_connect_to_remote_mailbox(account_id, mail->mailbox_id, (void **)&tmp_stream, &err) || !tmp_stream) { + EM_DEBUG_EXCEPTION("emcore_connect_to_remote_mailbox failed [%d]", err); + if(err == EMAIL_ERROR_NO_SUCH_HOST) + err = EMAIL_ERROR_CONNECTION_FAILURE; + + if (mail) + emstorage_free_mail(&mail, 1, NULL); + + emcore_notify_network_event(NOTI_DOWNLOAD_BODY_FAIL, mail_id, NULL, handle_to_be_published, err); + + goto FINISH_OFF; + } + + if (!emcore_gmime_download_body_sections(tmp_stream, mailbox.account_id, mail_id, + option & 0x01, NO_LIMITATION, handle_to_be_published, 1, 0, &err)) + EM_DEBUG_EXCEPTION("emcore_gmime_download_body_sections failed - %d", err); + + if (tmp_stream) { + tmp_stream = mail_close (tmp_stream); + } + + if (mail) + emstorage_free_mail(&mail, 1, NULL); + +#else if (!emcore_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)) + 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, + 1, /* cancel enabled */ + &err)) EM_DEBUG_EXCEPTION("emcore_download_body_multi_sections_bulk failed - %d", err); +#endif } +FINISH_OFF: + if (error) *error = err; @@ -1076,12 +1359,19 @@ static int event_handler_EMAIL_EVENT_DOWNLOAD_ATTACHMENT(int account_id, int mai else { #ifdef __ATTACHMENT_OPTI__ - if (!emcore_download_attachment_bulk(account_id, mail_id, attachment_no, &err)) + if (!emcore_download_attachment_bulk(account_id, mail_id, attachment_no, handle_to_be_published, &err)) EM_DEBUG_EXCEPTION("\t emcore_download_attachment failed [%d]", err); #else - if (!emcore_download_attachment(account_id, mail_id, attachment_no, &err)) + +#ifdef __FEATURE_USE_GMIME__ + if (!emcore_gmime_download_attachment(mail_id, attachment_no, 1, handle_to_be_published, 0, &err)) + EM_DEBUG_EXCEPTION("emcore_gmime_download_attachment failed [%d]", err); +#else + if (!emcore_download_attachment (account_id, mail_id, attachment_no, 1, handle_to_be_published, &err)) EM_DEBUG_EXCEPTION("\t emcore_download_attachment failed [%d]", err); #endif + +#endif } if (error) @@ -1123,7 +1413,7 @@ static int event_handler_EMAIL_EVENT_VALIDATE_ACCOUNT(int account_id, int handle } else { - if (!emcore_validate_account(account_id, &err)) { + if (!emcore_validate_account(account_id, handle_to_be_published, &err)) { EM_DEBUG_EXCEPTION("emcore_validate_account failed account id : %d err : %d", account_id, err); if (err == EMAIL_ERROR_CANCELLED) { @@ -1143,8 +1433,11 @@ static int event_handler_EMAIL_EVENT_VALIDATE_ACCOUNT(int account_id, int handle if (account_ref) { EM_DEBUG_LOG("account_ref->incoming_server_type[%d]", account_ref->incoming_server_type); if ( EMAIL_SERVER_TYPE_IMAP4 == account_ref->incoming_server_type ) { - if (!emcore_check_thread_status()) + int dummy=0; + if (!emcore_check_event_thread_status(&dummy, handle_to_be_published)) { + EM_DEBUG_LOG("canceled type [%d]", dummy); err = EMAIL_ERROR_CANCELLED; + } else if (!emcore_sync_mailbox_list(account_id, "", handle_to_be_published, &err)) EM_DEBUG_EXCEPTION("\t emcore_get_mailbox_list_to_be_sync falied - %d", err); } @@ -1240,46 +1533,31 @@ FINISH_OFF: return ret; } -static int event_handler_EMAIL_EVENT_DELETE_MAILBOX(int mailbox_id, int on_server, int recursive, int handle_to_be_published, int *error) +static int event_handler_EMAIL_EVENT_DELETE_MAILBOX(int mailbox_id, int on_server, int recursive, int handle_to_be_published) { - EM_DEBUG_FUNC_BEGIN("mailbox_id[%d] on_server[%d] recursive[%d] handle_to_be_published[%d] error[%p]", mailbox_id, on_server, recursive, handle_to_be_published, error); + EM_DEBUG_FUNC_BEGIN("mailbox_id[%d] on_server[%d] recursive[%d] handle_to_be_published[%d]", mailbox_id, on_server, recursive, handle_to_be_published); int err = EMAIL_ERROR_NONE; - if (!emnetwork_check_network_status(&err)) - EM_DEBUG_EXCEPTION("emnetwork_check_network_status failed [%d]", err); - else { - if (( err = emcore_delete_mailbox(mailbox_id, on_server, recursive)) != EMAIL_ERROR_NONE) - EM_DEBUG_EXCEPTION("emcore_delete failed [%d]", err); - } - - if (error) - *error = err; + if ((err = emcore_delete_mailbox(mailbox_id, on_server, recursive)) != EMAIL_ERROR_NONE) + EM_DEBUG_EXCEPTION("emcore_delete failed [%d]", err); - EM_DEBUG_FUNC_END(); - return true; + EM_DEBUG_FUNC_END("err [%d]", err); + return err; } -static int event_handler_EMAIL_EVENT_CREATE_MAILBOX(email_mailbox_t *input_new_mailbox, int on_server, int handle_to_be_published, int *error) +static int event_handler_EMAIL_EVENT_CREATE_MAILBOX(email_mailbox_t *input_new_mailbox, int on_server, int handle_to_be_published) { EM_DEBUG_FUNC_BEGIN(); int err = EMAIL_ERROR_NONE; - if (!emnetwork_check_network_status(&err)) { - EM_DEBUG_EXCEPTION("emnetwork_check_network_status failed [%d]", err); - } - else { - if (!emcore_create_mailbox(input_new_mailbox, on_server, &err)) - EM_DEBUG_EXCEPTION("emcore_create failed - %d", err); - } - - if (error) - *error = err; + if (!emcore_create_mailbox(input_new_mailbox, on_server, -1, -1, &err)) + EM_DEBUG_EXCEPTION("emcore_create failed - %d", err); - EM_DEBUG_FUNC_END(); - return true; + EM_DEBUG_FUNC_END("err [%d]", err); + return err; } -static int event_handler_EMAIL_EVENT_SYNC_MAIL_FLAG_TO_SERVER(int mail_id, int *error) +static int event_handler_EMAIL_EVENT_SYNC_MAIL_FLAG_TO_SERVER(int mail_id, int event_handle, int *error) { EM_DEBUG_FUNC_BEGIN("mail_id [%d], error [%p]", mail_id, error); @@ -1288,7 +1566,7 @@ static int event_handler_EMAIL_EVENT_SYNC_MAIL_FLAG_TO_SERVER(int mail_id, int * if (!emnetwork_check_network_status(&err)) EM_DEBUG_EXCEPTION("emnetwork_check_network_status failed [%d]", err); else { - if (!emcore_sync_flag_with_server(mail_id, &err)) + if (!emcore_sync_flag_with_server(mail_id, event_handle, &err)) EM_DEBUG_EXCEPTION("emcore_sync_flag_with_server failed [%d]", err); #ifdef __FEATURE_LOCAL_ACTIVITY__ else { @@ -1329,7 +1607,7 @@ static int event_handler_EMAIL_EVENT_DELETE_MAIL_ALL(int input_account_id, int i return true; } -static int event_handler_EMAIL_EVENT_DELETE_MAIL(int account_id, int *mail_id_list, int mail_id_count, int *error) +static int event_handler_EMAIL_EVENT_DELETE_MAIL(int account_id, int *mail_id_list, int mail_id_count, int from_server, int *error) { EM_DEBUG_FUNC_BEGIN(); int err = EMAIL_ERROR_NONE; @@ -1342,7 +1620,7 @@ static int event_handler_EMAIL_EVENT_DELETE_MAIL(int account_id, int *mail_id_li goto FINISH_OFF; } - if (!emcore_delete_mail(account_id, mail_id_list, mail_id_count, EMAIL_DELETE_FROM_SERVER, EMAIL_DELETED_BY_COMMAND, false, &err)) { + if (!emcore_delete_mail(account_id, mail_id_list, mail_id_count, from_server, EMAIL_DELETED_BY_COMMAND, false, &err)) { EM_DEBUG_EXCEPTION("emcore_delete_mail failed [%d]", err); goto FINISH_OFF; } @@ -1385,141 +1663,6 @@ static int event_hanlder_EMAIL_EVENT_SYNC_HEADER_OMA(int account_id, char *maibo return true; } -static int event_handler_EMAIL_EVENT_SEARCH_ON_SERVER(int account_id, int mailbox_id, char *criteria, - int handle_to_be_published, int *error) -{ - EM_DEBUG_FUNC_BEGIN_SEC("account_id : [%d], mailbox_id : [%d], criteria : [%s]", account_id, mailbox_id, criteria); - - int err = EMAIL_ERROR_NONE; - int i = 0; - int mail_id = 0; - int thread_id = 0; - char temp_uid_string[20] = {0,}; - - emcore_uid_list uid_elem; - emstorage_mailbox_tbl_t *search_mailbox = NULL; - emstorage_mail_tbl_t *new_mail_tbl_data = NULL; - - MAILSTREAM *stream = NULL; - MESSAGECACHE *mail_cache_element = NULL; - ENVELOPE *env = NULL; - emstorage_mailbox_tbl_t* local_mailbox = NULL; - char mailbox_id_param_string[10] = {0,}; - - if (account_id < 0 || mailbox_id == 0) { - EM_DEBUG_EXCEPTION("Invalid parameter"); - err = EMAIL_ERROR_INVALID_PARAM; - goto FINISH_OFF; - } - - if ( (err = emstorage_get_mailbox_by_id(mailbox_id, &local_mailbox)) != EMAIL_ERROR_NONE || !local_mailbox) { - EM_DEBUG_EXCEPTION("emstorage_get_mailbox_by_id failed [%d]", err); - goto FINISH_OFF; - } - - SNPRINTF(mailbox_id_param_string, 10, "%d", local_mailbox->mailbox_id); - - if (!emcore_notify_network_event(NOTI_SEARCH_ON_SERVER_START, account_id, mailbox_id_param_string, handle_to_be_published, 0)) - EM_DEBUG_EXCEPTION("emcore_notify_network_event [NOTI_SEARCH_ON_SERVER_START] failed >>>>"); - - if (!emnetwork_check_network_status(&err)) { - EM_DEBUG_EXCEPTION("emnetwork_check_network_status failed [%d]", err); - if (!emcore_notify_network_event(NOTI_SEARCH_ON_SERVER_FAIL, account_id, mailbox_id_param_string, 0, err)) - EM_DEBUG_EXCEPTION("emcore_notify_network_event [NOTI_DOWNLOAD_FAIL] Failed"); - goto FINISH_OFF; - } - - if (!emcore_connect_to_remote_mailbox(account_id, mailbox_id, (void **)&stream, &err)) { - EM_DEBUG_EXCEPTION("emcore_connect_to_remote_mailbox failed"); - if (!emcore_notify_network_event(NOTI_SEARCH_ON_SERVER_FAIL, account_id, mailbox_id_param_string, handle_to_be_published, err)) - EM_DEBUG_EXCEPTION("emcore_notify_network_event [NOTI_SEARCH_ON_SERVER_FAIL] Failed >>>>"); - goto FINISH_OFF; - } - - if (!mail_search_full(stream, NIL, mail_criteria(criteria), SE_FREE)) { - EM_DEBUG_EXCEPTION("mail_search failed"); - if (!emcore_notify_network_event(NOTI_SEARCH_ON_SERVER_FAIL, account_id, mailbox_id_param_string, handle_to_be_published, err)) - EM_DEBUG_EXCEPTION("emcore_notify_network_event [NOTI_SEARCH_ON_SERVER_FAIL] Failed >>>>"); - goto FINISH_OFF; - } - - for (i = 1; i <= stream->nmsgs; ++i) { - mail_cache_element = mail_elt(stream, i); - if (mail_cache_element->searched) { - env = mail_fetchstructure_full(stream, i, NULL, FT_PEEK); - - memset(&uid_elem, 0x00, sizeof(uid_elem)); - - uid_elem.msgno = mail_cache_element->msgno; - SNPRINTF(temp_uid_string, 20, "%4lu", mail_cache_element->private.uid); - uid_elem.uid = temp_uid_string; - uid_elem.flag.seen = mail_cache_element->seen; - - if (!emcore_make_mail_tbl_data_from_envelope(account_id, stream, env, &uid_elem, &new_mail_tbl_data, &err) || !new_mail_tbl_data) { - EM_DEBUG_EXCEPTION("emcore_make_mail_tbl_data_from_envelope failed [%d]", err); - if (!emcore_notify_network_event(NOTI_SEARCH_ON_SERVER_FAIL, account_id, mailbox_id_param_string, handle_to_be_published, err)) - EM_DEBUG_EXCEPTION("emcore_notify_network_event [NOTI_SEARCH_ON_SERVER_FAIL] Failed >>>>"); - goto FINISH_OFF; - } - - search_mailbox = em_malloc(sizeof(emstorage_mailbox_tbl_t)); - if (search_mailbox == NULL) { - EM_DEBUG_EXCEPTION("em_malloc failed"); - err = EMAIL_ERROR_OUT_OF_MEMORY; - if (!emcore_notify_network_event(NOTI_SEARCH_ON_SERVER_FAIL, account_id, mailbox_id_param_string, handle_to_be_published, err)) - EM_DEBUG_EXCEPTION("emcore_notify_network_event [NOTI_SEARCH_ON_SERVER_FAIL] Failed >>>>"); - goto FINISH_OFF; - } - - search_mailbox->account_id = account_id; - search_mailbox->mailbox_id = mailbox_id; - search_mailbox->mailbox_name = EM_SAFE_STRDUP(EMAIL_SEARCH_RESULT_MAILBOX_NAME); - search_mailbox->mailbox_type = EMAIL_MAILBOX_TYPE_SEARCH_RESULT; - - if ((err = emcore_add_mail_to_mailbox(search_mailbox, new_mail_tbl_data, &mail_id, &thread_id)) != EMAIL_ERROR_NONE) { - EM_DEBUG_EXCEPTION("emcore_add_mail_to_mailbox failed [%d]", err); - if (!emcore_notify_network_event(NOTI_SEARCH_ON_SERVER_FAIL, account_id, mailbox_id_param_string, handle_to_be_published, err)) - EM_DEBUG_EXCEPTION("emcore_notify_network_event [NOTI_SEARCH_ON_SERVER_FAIL] Failed >>>>"); - goto FINISH_OFF; - } - memset(mailbox_id_param_string, 0, 10); - SNPRINTF(mailbox_id_param_string, 10, "%d", search_mailbox->mailbox_id); - if (!emcore_notify_storage_event(NOTI_MAIL_ADD, account_id, mail_id, mailbox_id_param_string, thread_id)) { - EM_DEBUG_EXCEPTION("emcore_notify_storage_event [NOTI_MAIL_ADD] failed"); - } - - if (new_mail_tbl_data) { - emstorage_free_mail(&new_mail_tbl_data, 1, NULL); - new_mail_tbl_data = NULL; - } - - emstorage_free_mailbox(&search_mailbox, 1, NULL); /*prevent 17942*/ - } - } - - if (err == EMAIL_ERROR_NONE && !emcore_notify_network_event(NOTI_SEARCH_ON_SERVER_FINISH, account_id, NULL, handle_to_be_published, 0)) - EM_DEBUG_EXCEPTION("emcore_notify_network_event[NOTI_SEARCH_ON_SERVER_FINISH] Failed >>>>>"); - -FINISH_OFF: - if (stream) - mail_close (stream); - - if (search_mailbox != NULL) - emstorage_free_mailbox(&search_mailbox, 1, NULL); - - if (new_mail_tbl_data) - emstorage_free_mail(&new_mail_tbl_data, 1, NULL); - - if (local_mailbox) - emstorage_free_mailbox(&local_mailbox, 1, NULL); - - if (error) - *error = err; - - EM_DEBUG_FUNC_END(); - return true; -} - static int event_handler_EMAIL_EVENT_RENAME_MAILBOX_ON_IMAP_SERVER(int input_account_id, int input_mailbox_id, char *input_old_mailbox_path, char *input_new_mailbox_path, char *input_new_mailbox_alias, int handle_to_be_published) { EM_DEBUG_FUNC_BEGIN_SEC("input_account_id [%d], input_mailbox_id [%d], input_old_mailbox_path %s], input_new_mailbox_path [%s], input_new_mailbox_alias [%s], handle_to_be_published [%d]", input_account_id, input_mailbox_id, input_old_mailbox_path, input_new_mailbox_path, input_new_mailbox_alias, handle_to_be_published); @@ -1542,6 +1685,8 @@ static void* worker_send_event_queue(void *arg) int err = EMAIL_ERROR_NONE; email_event_t *event_data = NULL; email_event_t *started_event = NULL; + int pbd_thd_state = 0; + int event_que_state = 0; if (!emstorage_open(&err)) { EM_DEBUG_EXCEPTION("emstorage_open falied [%d]", err); @@ -1549,6 +1694,10 @@ static void* worker_send_event_queue(void *arg) } while (g_send_event_loop) { + + pbd_thd_state = emcore_get_pbd_thd_state(); + event_que_state = emcore_is_event_queue_empty(); + /* get a event_data from event_data send queue */ ENTER_RECURSIVE_CRITICAL_SECTION(_send_event_queue_lock); if (!emcore_retrieve_send_event(&event_data, &err)) { @@ -1560,7 +1709,19 @@ static void* worker_send_event_queue(void *arg) send_thread_run = 0; - emdevice_set_sleep_on_off(true, NULL); + emdevice_set_sleep_on_off(STAY_AWAKE_FLAG_FOR_SENDING_WORKER, true, NULL); + +#ifdef __FEATURE_WIFI_AUTO_DOWNLOAD__ + int wifi_status = 0; + if ((err = emnetwork_get_wifi_status(&wifi_status)) != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emnetwork_get_wifi_status failed [%d]", err); + } + EM_DEBUG_LOG("WIFI Status [%d]", wifi_status); + + if (!pbd_thd_state && event_que_state && wifi_status > 1) { + WAKE_CONDITION_VARIABLE(_auto_downalod_available_signal); + } +#endif //go to sleep when queue is empty SLEEP_CONDITION_VARIABLE(_send_event_available_signal, *_send_event_queue_lock); @@ -1569,7 +1730,7 @@ static void* worker_send_event_queue(void *arg) } else { LEAVE_RECURSIVE_CRITICAL_SECTION(_send_event_queue_lock); EM_DEBUG_LOG(">>>>>>>>>>>>>>Got SEND event_data>>>>>>>>>>>>>>>>"); - emdevice_set_sleep_on_off(false, NULL); + emdevice_set_sleep_on_off(STAY_AWAKE_FLAG_FOR_SENDING_WORKER, false, NULL); send_thread_run = 1; switch (event_data->type) { @@ -1671,6 +1832,7 @@ static void* worker_send_event_queue(void *arg) if (!emstorage_close(&err)) EM_DEBUG_EXCEPTION("emstorage_close falied [%d]", err); + emcore_close_smtp_stream_list(); EM_DEBUG_FUNC_END("err [%d]", err); return NULL; } @@ -1698,7 +1860,7 @@ INTERNAL_FUNC int emdaemon_start_thread_for_downloading_partial_body(int *err_co } g_partial_body_thd_next_event_idx = 0; - g_partial_body_thd_loop = 1; +// g_partial_body_thd_loop = 1; g_partial_body_thd_queue_empty = true; g_partial_body_thd_queue_full = false; @@ -1730,6 +1892,10 @@ static gpointer partial_body_download_thread(gpointer data) int err = EMAIL_ERROR_NONE; email_session_t *session = NULL; email_event_partial_body_thd partial_body_thd_event; + int i, account_count = 0; + emstorage_account_tbl_t *account_list = NULL; + int event_que_state = 0; + int send_event_que_state = 0; EM_DEBUG_LOG_DEV(" ************ PB THREAD ID IS ALIVE. ID IS [%d] ********************" , THREAD_SELF()); @@ -1740,125 +1906,157 @@ static gpointer partial_body_download_thread(gpointer data) return false; } - /* Start the continuous loop */ + /* refactoring session required */ + if (!emcore_get_empty_session(&session)) { + EM_DEBUG_EXCEPTION("emcore_get_empty_session failed..."); + } - while (g_partial_body_thd_loop) { - /* Get an empty session */ - /* TODO : Mutex should be used in session APIs */ + while (1) { - if (false == emcore_get_empty_session(&session)) - EM_DEBUG_EXCEPTION("emcore_get_empty_session failed..."); - else { /* Get and Event from the Partial Body thread Event Queue */ - memset(&partial_body_thd_event, 0x00, sizeof(email_event_partial_body_thd)); + memset(&partial_body_thd_event, 0, sizeof(email_event_partial_body_thd)); - if (false == emcore_retrieve_partial_body_thread_event(&partial_body_thd_event, &err)) { - if (EMAIL_ERROR_EVENT_QUEUE_EMPTY != err) - EM_DEBUG_EXCEPTION("emcore_retrieve_partial_body_thread_event failed [%d]", err); - else { - EM_DEBUG_LOG(" partial body thread event_data queue is empty."); + if (false == emcore_retrieve_partial_body_thread_event(&partial_body_thd_event, &err)) { + if (EMAIL_ERROR_EVENT_QUEUE_EMPTY != err) + EM_DEBUG_EXCEPTION("emcore_retrieve_partial_body_thread_event failed [%d]", err); + else { + EM_DEBUG_LOG(" partial body thread event_data queue is empty."); - /* 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_id = g_partial_body_bulk_dwd_que[0].mailbox_id; - partial_body_thd_event.mailbox_name = EM_SAFE_STRDUP(g_partial_body_bulk_dwd_que[0].mailbox_name); /* need to be freed */ +#ifdef __FEATURE_WIFI_AUTO_DOWNLOAD__ + int wifi_status = 0; +#endif - if (false == emcore_mail_partial_body_download(&partial_body_thd_event, &err)) - EM_DEBUG_EXCEPTION("emcore_mail_partial_body_download from event_data queue failed [%d]", err); + /* 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_id = g_partial_body_bulk_dwd_que[0].mailbox_id; + partial_body_thd_event.mailbox_name = EM_SAFE_STRDUP(g_partial_body_bulk_dwd_que[0].mailbox_name); /* need to be freed */ - emcore_pb_thd_set_local_activity_continue(true); - } + if (false == emcore_mail_partial_body_download(&partial_body_thd_event, &err)) + EM_DEBUG_EXCEPTION("emcore_mail_partial_body_download from event_data queue failed [%d]", err); - if (true == emcore_pb_thd_can_local_activity_continue()) { - /*Check for local Activities */ - int is_local_activity_event_inserted = false; + emcore_pb_thd_set_local_activity_continue(true); + } - if (false == emcore_partial_body_thd_local_activity_sync(&is_local_activity_event_inserted, &err)) { - EM_DEBUG_EXCEPTION("emcore_partial_body_thd_local_activity_sync failed [%d]", err); - } - else { - if (true == is_local_activity_event_inserted) { - emcore_pb_thd_set_local_activity_continue(false); + if (true == emcore_pb_thd_can_local_activity_continue()) { + /*Check for local Activities */ + int is_local_activity_event_inserted = false; - emcore_clear_session(session); + if (false == emcore_partial_body_thd_local_activity_sync(&is_local_activity_event_inserted, &err)) { + EM_DEBUG_EXCEPTION("emcore_partial_body_thd_local_activity_sync failed [%d]", err); + } + else { + if (true == is_local_activity_event_inserted) { + emcore_pb_thd_set_local_activity_continue(false); - if (false == emcore_free_partial_body_thd_event(&partial_body_thd_event, &err)) - EM_DEBUG_EXCEPTION("emcore_free_partial_body_thd_event_cell failed [%d]", err); +/* emcore_clear_session(session);*/ - continue; - } + if (false == emcore_free_partial_body_thd_event(&partial_body_thd_event, &err)) + EM_DEBUG_EXCEPTION("emcore_free_partial_body_thd_event_cell failed [%d]", err); + + continue; } } + } + + EM_DEBUG_LOG_DEV(" Partial Body Thread is going to sleep"); + + /* finalize sync */ + account_count = 0; + account_list = NULL; - EM_DEBUG_LOG_DEV(" Partial Body Thread is going to sleep"); + if (!emstorage_get_account_list(&account_count, &account_list, false, false, &err)) { + EM_DEBUG_EXCEPTION("emstorage_get_account_list failed : [%d]", err); + } - emcore_set_pbd_thd_state(false); - /*check: refactoring required*/ - 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); + for (i = 0; i < account_count; i++) { + if (!emdaemon_finalize_sync(account_list[i].account_id, 0, 0, 0, 0, true, NULL)) + EM_DEBUG_EXCEPTION("emdaemon_finalize_sync failed"); + } - EM_DEBUG_LOG(" Partial Body Thread wakes up "); + if (account_list) + emstorage_free_account(&account_list, account_count, NULL); + + emcore_set_pbd_thd_state(false); - emcore_set_pbd_thd_state(true); +#ifdef __FEATURE_WIFI_AUTO_DOWNLOAD__ + if ((err = emnetwork_get_wifi_status(&wifi_status)) != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emnetwork_get_wifi_status failed [%d]", err); } + EM_DEBUG_LOG("WIFI Status [%d]", wifi_status); + + event_que_state = emcore_is_event_queue_empty(); + send_event_que_state = emcore_is_send_event_queue_empty(); +#endif + /*check: refactoring required*/ + ENTER_CRITICAL_SECTION(_partial_body_thd_event_queue_lock); +#ifdef __FEATURE_WIFI_AUTO_DOWNLOAD__ + if (event_que_state && send_event_que_state && wifi_status > 1) { + WAKE_CONDITION_VARIABLE(_auto_downalod_available_signal); + } +#endif + 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 "); + + emcore_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*/ + } + else { + EM_DEBUG_LOG(" Event Received from Partial Body Event Queue "); - emdevice_set_sleep_on_off(false, NULL); + /* Since all events are network operations dnet init and sleep control is + done before entering switch block*/ - if (!emnetwork_check_network_status( &err)) { - EM_DEBUG_EXCEPTION("emnetwork_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); + emdevice_set_sleep_on_off(STAY_AWAKE_FLAG_FOR_PARTIAL_BODY_WORKER, false, NULL); - switch (partial_body_thd_event.event_type) { - case EMAIL_EVENT_BULK_PARTIAL_BODY_DOWNLOAD: { - if (false == emcore_mail_partial_body_download(&partial_body_thd_event, &err)) { - EM_DEBUG_EXCEPTION("emcore_mail_partial_body_download from event_data queue failed [%d]", err); - } - break; - } - case EMAIL_EVENT_LOCAL_ACTIVITY_SYNC_BULK_PBD: { - partial_body_thd_event.event_type = 0; + if (!emnetwork_check_network_status( &err)) { + EM_DEBUG_EXCEPTION("emnetwork_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); - /* 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 == emcore_is_partial_body_thd_que_empty()) - break; - if (!g_partial_body_bulk_dwd_queue_empty) - break; + switch (partial_body_thd_event.event_type) { + case EMAIL_EVENT_BULK_PARTIAL_BODY_DOWNLOAD: { + if (false == emcore_mail_partial_body_download(&partial_body_thd_event, &err)) { + EM_DEBUG_EXCEPTION("emcore_mail_partial_body_download from event_data queue failed [%d]", err); + } + break; + } + case EMAIL_EVENT_LOCAL_ACTIVITY_SYNC_BULK_PBD: { + partial_body_thd_event.event_type = 0; - if (false == emcore_mail_partial_body_download(&partial_body_thd_event, &err)) - EM_DEBUG_EXCEPTION("emcore_mail_partial_body_download from activity table failed [%d]", err); + /* 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 == emcore_is_partial_body_thd_que_empty()) break; - } - default: - EM_DEBUG_EXCEPTION(" Warning : Default case entered. This should not happen "); + if (!g_partial_body_bulk_dwd_queue_empty) break; + + if (false == emcore_mail_partial_body_download(&partial_body_thd_event, &err)) + EM_DEBUG_EXCEPTION("emcore_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 == emcore_free_partial_body_thd_event(&partial_body_thd_event, &err)) - EM_DEBUG_EXCEPTION("emcore_free_partial_body_thd_event_cell failed [%d]", err); - - emdevice_set_sleep_on_off(true, NULL); } - emcore_clear_session(session); + if (false == emcore_free_partial_body_thd_event(&partial_body_thd_event, NULL)) + EM_DEBUG_EXCEPTION("emcore_free_partial_body_thd_event_cell failed"); + + emdevice_set_sleep_on_off(STAY_AWAKE_FLAG_FOR_PARTIAL_BODY_WORKER, true, NULL); } + +/* emcore_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 emcore_partial_body_thd_loop_stop to release resources and call it - here to end thread */ + emcore_close_recv_stream_list(); + emcore_clear_session(session); return SUCCESS; } diff --git a/email-daemon/email-daemon-init.c b/email-daemon/email-daemon-init.c index c54aa02..222723d 100755 --- a/email-daemon/email-daemon-init.c +++ b/email-daemon/email-daemon-init.c @@ -4,7 +4,7 @@ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> -* +* * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -39,6 +39,7 @@ #include <vconf-internal-account-keys.h> #include <dbus/dbus.h> #include <dlfcn.h> /* added for Disabling the Pthread flag log */ +#include <net_connection.h> #include "email-daemon.h" #include "email-storage.h" @@ -49,19 +50,25 @@ #include "email-daemon-event.h" #include "email-core-utils.h" #include "email-core-mail.h" -#include "email-core-event.h" +#include "email-core-event.h" #include "email-core-account.h" #include "email-core-mailbox.h" #include "email-core-smtp.h" #include "email-core-global.h" +#include "email-core-imap-idle.h" #include "email-storage.h" -#include "email-core-sound.h" #include "email-core-task-manager.h" #include "email-core-alarm.h" +#ifdef __FEATURE_WIFI_AUTO_DOWNLOAD__ +#include "email-core-auto-download.h" +#endif #include "email-daemon-emn.h" #include "email-network.h" #include "email-device.h" #include "c-client.h" +#include "email-core-smime.h" + +connection_h conn = NULL; extern void * pop3_parameters(long function, void *value); @@ -72,6 +79,10 @@ INTERNAL_FUNC int g_client_count = 0; extern int blocking_mode_of_setting; extern GList *alarm_data_list; +#ifdef __FEATURE_WIFI_AUTO_DOWNLOAD__ +extern pthread_cond_t _auto_downalod_available_signal; +#endif + static int default_alarm_callback(int input_timer_id, void *user_parameter); /* static functions */ @@ -85,6 +96,10 @@ static int _emdaemon_load_email_core() if (!emdaemon_core_init(&err)) goto FINISH_OFF; +#ifdef __FEATURE_OPEN_SSL_MULTIHREAD_HANDLE__ + emdaemon_setup_handler_for_open_ssl_multithread(); +#endif /* __FEATURE_OPEN_SSL_MULTIHREAD_HANDLE__ */ + if (emdaemon_start_event_loop(&err) < 0) goto FINISH_OFF; @@ -111,8 +126,14 @@ static int _emdaemon_load_email_core() emdaemon_init_blocking_mode_status(); #endif /* __FEATURE_BLOCKING_MODE__ */ +#ifdef __FEATURE_WIFI_AUTO_DOWNLOAD__ + if (!emcore_start_auto_download_loop(&err)) + goto FINISH_OFF; +#endif + FINISH_OFF: + EM_DEBUG_FUNC_END("err [%d]", err); return err; } @@ -125,6 +146,14 @@ static int _emdaemon_unload_email_core() emcore_stop_event_loop(&err); emcore_stop_task_manager_loop(); +#ifdef __FEATURE_WIFI_AUTO_DOWNLOAD__ + emcore_stop_auto_download_loop(&err); +#endif + +#ifdef __FEATURE_OPEN_SSL_MULTIHREAD_HANDLE__ + emdaemon_cleanup_handler_for_open_ssl_multithread(); +#endif /* __FEATURE_OPEN_SSL_MULTIHREAD_HANDLE__ */ + EM_DEBUG_FUNC_END("err [%d]", err); return err; } @@ -221,27 +250,55 @@ FINISH_OFF: EM_DEBUG_FUNC_END(); } -static void callback_for_NETWORK_STATUS(keynode_t *input_node, void *input_user_data) +static void callback_for_NETWORK_STATUS(connection_type_e new_conn_type, void *input_user_data) { - EM_DEBUG_FUNC_BEGIN("input_node [%p], input_user_data [%p]", input_node, input_user_data); + EM_DEBUG_FUNC_BEGIN("new_conn_type [%p], input_user_data [%p]", new_conn_type, input_user_data); int err = EMAIL_ERROR_NONE; int i = 0; int total = 0; int unseen = 0; - int network_status = 0; int account_count = 0; + int conn_type = 0; + int handle = 0; + int send_saved_handle = 0; + email_event_t *event_data = NULL; email_account_t *account_list = NULL; email_account_t *account_info = NULL; emstorage_mailbox_tbl_t *local_mailbox = NULL; - if (input_node) - network_status = vconf_keynode_get_int(input_node); + conn_type = emnetwork_get_network_status(); - if (network_status == VCONFKEY_NETWORK_OFF) { - EM_DEBUG_EXCEPTION("Network is OFF"); - goto FINISH_OFF; + switch (new_conn_type) { + case CONNECTION_TYPE_WIFI: + case CONNECTION_TYPE_CELLULAR: + if(conn_type != new_conn_type) { + EM_DEBUG_LOG("Network type changed from [%d] to [%d]", conn_type, new_conn_type); + emnetwork_set_network_status(new_conn_type); + } + break; + + case CONNECTION_TYPE_DISCONNECTED: + EM_DEBUG_LOG("Network is disconnected. [%d]", new_conn_type); + emnetwork_set_network_status(new_conn_type); + goto FINISH_OFF; + + default: + EM_DEBUG_LOG("Unexpected value came. Set disconnectted network. [%d]", new_conn_type); + emnetwork_set_network_status(CONNECTION_TYPE_DISCONNECTED); + goto FINISH_OFF; } + emcore_get_sync_fail_event_data(&event_data); + + if (event_data != NULL) { + if (!emcore_insert_event(event_data, &handle, &err)) { + EM_DEBUG_LOG("emcore_insert_event failed : %d", err); + } + } + + if (false == emcore_is_partial_body_thd_que_empty()) + emcore_pb_thd_set_local_activity_continue(true); + if (!emdaemon_get_account_list(&account_list, &account_count, &err)) { EM_DEBUG_EXCEPTION("emdaemon_get_account_list failed [%d]", err); goto FINISH_OFF; @@ -249,28 +306,31 @@ static void callback_for_NETWORK_STATUS(keynode_t *input_node, void *input_user_ for (i = 0; i < account_count ; i++) { account_info = account_list + i; + /* check if inbox folder sync is finished */ + if (!emstorage_get_mailbox_by_mailbox_type (account_info->account_id, EMAIL_MAILBOX_TYPE_INBOX, &local_mailbox, false, &err)) { + if (err == EMAIL_ERROR_MAILBOX_NOT_FOUND) { + int handle = 0; + emdaemon_get_imap_mailbox_list(account_info->account_id, "", &handle, &err); + if (err != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emdaemon_get_imap_mailbox_list error [%d]", err); + } + } + } - if (!emstorage_get_mailbox_by_mailbox_type(account_info->account_id, EMAIL_MAILBOX_TYPE_OUTBOX, &local_mailbox, false, &err)) { - EM_DEBUG_EXCEPTION("emstorage_get_mailbox_by_mailbox_type failed [%d]", err); - goto FINISH_OFF; + if (!emstorage_free_mailbox(&local_mailbox, 1, &err)) { + EM_DEBUG_EXCEPTION("emstorage_free_mailbox error [%d]", err); } - if (!emstorage_get_mail_count(account_info->account_id, local_mailbox->mailbox_id, &total, &unseen, false, &err)) { - EM_DEBUG_EXCEPTION("emstorage_get_mail_count failed [%d]", err); - goto FINISH_OFF; + /* send mails in outbox */ + if (!emcore_get_mail_count_by_query(account_info->account_id, EMAIL_MAILBOX_TYPE_OUTBOX, 0, &total, &unseen, &err)) { + EM_DEBUG_EXCEPTION("emstorage_get_mail_count_by_query failed [%d]", err); } if (total <= 0) continue; - if (!emcore_send_saved_mail(account_info->account_id, local_mailbox->mailbox_name, &err)) { - EM_DEBUG_EXCEPTION("emcore_send_saved_mail failed [%d]", err); - goto FINISH_OFF; - } - - if (!emstorage_free_mailbox(&local_mailbox, 1, &err)) { - EM_DEBUG_EXCEPTION("emstorage_free_mailbox failed [%d]", err); - goto FINISH_OFF; + if (!emdaemon_send_mail_saved(account_info->account_id, &send_saved_handle, &err)) { + EM_DEBUG_EXCEPTION("emdaemon_send_mail_saved failed : [%d]", err); } } @@ -295,7 +355,7 @@ INTERNAL_FUNC void callback_for_BLOCKING_MODE_STATUS(keynode_t *input_node, void EM_DEBUG_EXCEPTION("Invalid param"); return; } - + blocking_mode_of_setting = vconf_keynode_get_bool(input_node); emcore_set_blocking_mode_of_setting(blocking_mode_of_setting); @@ -304,6 +364,7 @@ INTERNAL_FUNC void callback_for_BLOCKING_MODE_STATUS(keynode_t *input_node, void } #endif /* __FEATURE_BLOCKING_MODE__ */ +#ifdef __FEATURE_OMA_EMN__ static void callback_for_VCONFKEY_MSG_SERVER_READY(keynode_t *input_node, void *input_user_data) { EM_DEBUG_FUNC_BEGIN(); @@ -324,6 +385,7 @@ static void callback_for_VCONFKEY_MSG_SERVER_READY(keynode_t *input_node, void * return; } +#endif /* __FEATURE_OMA_EMN__ */ static void callback_for_VCONFKEY_GLOBAL_BADGE_STATUS(keynode_t *input_node, void *input_user_data) { @@ -340,8 +402,7 @@ static void callback_for_VCONFKEY_GLOBAL_BADGE_STATUS(keynode_t *input_node, voi noti_status = vconf_keynode_get_bool(input_node); if (noti_status) { - if (!emcore_display_unread_in_badge()) - EM_DEBUG_EXCEPTION("emcore_display_unread_in_badge failed"); + emcore_display_unread_in_badge(NULL); } else { if (vconf_get_bool(VCONF_VIP_NOTI_BADGE_TICKER, &badge_ticker) != 0) { EM_DEBUG_EXCEPTION("vconf_get_bool failed"); @@ -350,13 +411,12 @@ static void callback_for_VCONFKEY_GLOBAL_BADGE_STATUS(keynode_t *input_node, voi } /* if priority sender is on, show the priority sender unread */ if (badge_ticker) { - if (!emcore_display_unread_in_badge()) - EM_DEBUG_EXCEPTION("emcore_display_unread_in_badge failed"); + emcore_display_unread_in_badge(NULL); goto FINISH_OFF; } /* reset badge */ - if ((err = emcore_display_badge_count(0)) != EMAIL_ERROR_NONE) + if ((err = emcore_display_badge_count(0)) != EMAIL_ERROR_NONE) EM_DEBUG_EXCEPTION("emcore_display_badge_count failed : [%d]", err); } @@ -380,8 +440,7 @@ static void callback_for_VCONFKEY_PRIORITY_BADGE_STATUS(keynode_t *input_node, v noti_status = vconf_keynode_get_bool(input_node); if (noti_status) { - if (!emcore_display_unread_in_badge()) - EM_DEBUG_EXCEPTION("emcore_display_unread_in_badge failed"); + emcore_display_unread_in_badge(NULL); } else { if (vconf_get_bool(VCONFKEY_TICKER_NOTI_BADGE_EMAIL, &badge_ticker) != 0) { @@ -392,12 +451,11 @@ static void callback_for_VCONFKEY_PRIORITY_BADGE_STATUS(keynode_t *input_node, v /*if global badge is on, show the global unread*/ if (badge_ticker) { - if (!emcore_display_unread_in_badge()) - EM_DEBUG_EXCEPTION("emcore_display_unread_in_badge failed"); + emcore_display_unread_in_badge(NULL); goto FINISH_OFF; } /* if all badges are off, reset badge count */ - if ((err = emcore_display_badge_count(0)) != EMAIL_ERROR_NONE) + if ((err = emcore_display_badge_count(0)) != EMAIL_ERROR_NONE) EM_DEBUG_EXCEPTION("emcore_display_badge_count failed : [%d]", err); } @@ -432,20 +490,48 @@ static void callback_for_VCONFKEY_TELEPHONY_ZONE_TYPE(keynode_t *input_node, voi EM_DEBUG_FUNC_END(); } +#ifdef __FEATURE_WIFI_AUTO_DOWNLOAD__ +static void callback_for_VCONFKEY_WIFI_STATE(keynode_t *input_node, void *input_user_data) +{ + EM_DEBUG_FUNC_BEGIN(); + int wifi_status = 0; + + if (!input_node) { + EM_DEBUG_EXCEPTION("Invalid param"); + return; + } + + wifi_status = vconf_keynode_get_int(input_node); + + EM_DEBUG_LOG("wifi_status [%d]", wifi_status); + + if (wifi_status > 1) { + if (!emcore_get_pbd_thd_state() && + emcore_is_event_queue_empty() && + emcore_is_send_event_queue_empty()) { + WAKE_CONDITION_VARIABLE(_auto_downalod_available_signal); + } + } + + EM_DEBUG_FUNC_END(); +} +#endif + INTERNAL_FUNC int emdaemon_initialize(int* err_code) { EM_DEBUG_FUNC_BEGIN(); - + /* default variable */ int ret = false; int err = EMAIL_ERROR_NONE; - + connection_type_e net_state = CONNECTION_TYPE_DISCONNECTED; + if (g_client_count > 0) { EM_DEBUG_LOG("Initialization was already done. increased counter=[%d]", g_client_count); g_client_count++; return true; } - else + else EM_DEBUG_LOG("************* start email service build time [%s %s] ************* ", __DATE__, __TIME__); dbus_threads_init_default(); @@ -464,18 +550,21 @@ INTERNAL_FUNC int emdaemon_initialize(int* err_code) goto FINISH_OFF; } + if ((err = emstorage_update_db_table_schema()) != EMAIL_ERROR_NONE) + EM_DEBUG_EXCEPTION("emstorage_update_db_table_schema failed [%d]", err); + if (!emstorage_clean_save_status(EMAIL_MAIL_STATUS_SAVED, &err)) EM_DEBUG_EXCEPTION("emstorage_check_mail_status Failed [%d]", err ); - - g_client_count = 0; - + + g_client_count = 0; + if (!emdaemon_initialize_account_reference()) { EM_DEBUG_EXCEPTION("emdaemon_initialize_account_reference fail..."); err = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; } EM_DEBUG_LOG("emdaemon_initialize_account_reference over - g_client_count [%d]", g_client_count); - + if ((err = _emdaemon_load_email_core()) != EMAIL_ERROR_NONE) { EM_DEBUG_EXCEPTION("_emdaemon_load_email_core failed [%d]", err); goto FINISH_OFF; @@ -496,29 +585,66 @@ INTERNAL_FUNC int emdaemon_initialize(int* err_code) } #endif /* __FEATURE_AUTO_RETRY_SEND__ */ + /* Start auto polling */ +#ifdef __FEATURE_AUTO_POLLING__ + emdaemon_start_auto_polling(&err); +#endif + +#ifdef __FEATURE_IMAP_IDLE__ + emcore_create_imap_idle_thread(1); +#endif /* __FEATURE_IMAP_IDLE__ */ + /* Subscribe Events */ +#ifdef __FEATURE_SYNC_STATUS__ + vconf_notify_key_changed(VCONFKEY_ACCOUNT_SYNC_ALL_STATUS_INT, callback_for_SYNC_ALL_STATUS_from_account_svc, NULL); + vconf_notify_key_changed(VCONFKEY_ACCOUNT_AUTO_SYNC_STATUS_INT, callback_for_AUTO_SYNC_STATUS_from_account_svc, NULL); +#endif /* __FEATURE_SYNC_STATUS__ */ + + int error_from_connection = 0; + + if ((error_from_connection = connection_create(&conn)) == CONNECTION_ERROR_NONE) { + if (connection_get_type(conn, &net_state) != CONNECTION_ERROR_NONE) { + EM_DEBUG_EXCEPTION("connection_get_type failed"); + } else { + emnetwork_set_network_status(net_state); + } + + if (connection_set_type_changed_cb(conn, callback_for_NETWORK_STATUS, NULL) != CONNECTION_ERROR_NONE) + EM_DEBUG_EXCEPTION("connection_set_type_changed_cb failed"); + } + else { + EM_DEBUG_EXCEPTION("connection_create failed[%d]", error_from_connection); + } - vconf_notify_key_changed(VCONFKEY_NETWORK_STATUS, callback_for_NETWORK_STATUS, NULL); #ifdef __FEATURE_BLOCKING_MODE__ vconf_notify_key_changed(VCONFKEY_SETAPPL_BLOCKINGMODE_NOTIFICATIONS, callback_for_BLOCKING_MODE_STATUS, NULL); #endif vconf_notify_key_changed(VCONFKEY_TICKER_NOTI_BADGE_EMAIL, callback_for_VCONFKEY_GLOBAL_BADGE_STATUS, NULL); vconf_notify_key_changed(VCONF_VIP_NOTI_BADGE_TICKER, callback_for_VCONFKEY_PRIORITY_BADGE_STATUS, NULL); + + vconf_notify_key_changed(VCONFKEY_SETAPPL_STATE_TICKER_NOTI_EMAIL_BOOL, callback_for_VCONFKEY_GLOBAL_BADGE_STATUS, NULL); + + vconf_notify_key_changed(VCONF_VIP_NOTI_NOTIFICATION_TICKER, callback_for_VCONFKEY_PRIORITY_BADGE_STATUS, NULL); + /* VCONFKEY_TELEPHONY_SVC_ROAM */ - /*vconf_notify_key_changed(VCONFKEY_TELEPHONY_ZONE_TYPE, callback_for_VCONFKEY_TELEPHONY_ZONE_TYPE, NULL);*/ - - emcore_display_unread_in_badge(); - + vconf_notify_key_changed(VCONFKEY_TELEPHONY_ZONE_TYPE, callback_for_VCONFKEY_TELEPHONY_ZONE_TYPE, NULL); + +#ifdef __FEATURE_WIFI_AUTO_DOWNLOAD__ + vconf_notify_key_changed(VCONFKEY_WIFI_STATE, callback_for_VCONFKEY_WIFI_STATE, NULL); +#endif + + emcore_display_unread_in_badge(NULL); + ret = true; - + FINISH_OFF: if (ret == true) g_client_count = 1; if (err_code) *err_code = err; - + EM_DEBUG_FUNC_END("ret [%d], g_client_count [%d]", ret, g_client_count); return ret; } @@ -526,40 +652,36 @@ FINISH_OFF: INTERNAL_FUNC int emdaemon_finalize(int* err_code) { EM_DEBUG_FUNC_BEGIN(); - + /* default variable */ int ret = false; int err = EMAIL_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 = EMAIL_ERROR_CLOSE_FAILURE; - goto FINISH_OFF; - } - + if ( (err = _emdaemon_unload_email_core()) != EMAIL_ERROR_NONE) { EM_DEBUG_EXCEPTION("_emdaemon_unload_email_core failed [%d]", err); goto FINISH_OFF; } - + + connection_destroy(conn); + /* free account reference list */ emcore_free_account_reference(); - + /* close database */ if (!emstorage_close(&err)) { EM_DEBUG_EXCEPTION("emstorage_close failed [%d]", err); goto FINISH_OFF; } - - g_client_count = 0; + + /* Openssl clean up */ + emcore_clean_openssl_library(); ret = true; - + FINISH_OFF: if (err_code) *err_code = err; - + return ret; } @@ -567,7 +689,7 @@ FINISH_OFF: INTERNAL_FUNC int emdaemon_start_auto_polling(int* err_code) { EM_DEBUG_FUNC_BEGIN(); - + /* default variable */ int ret = false, count = 0, i= 0; int err = EMAIL_ERROR_NONE; @@ -575,26 +697,26 @@ INTERNAL_FUNC int emdaemon_start_auto_polling(int* err_code) /* get account list */ if (!emstorage_get_account_list(&count, &account_list, false, false, &err)) { - EM_DEBUG_EXCEPTION("emstorage_get_account_list failed [%d]", err); + EM_DEBUG_EXCEPTION("emstorage_get_account_list failed [%d]", err); goto FINISH_OFF; } for (i = 0; i < count; i++) { /* start auto polling, if check_interval not zero */ - if(account_list[i].check_interval > 0 || (account_list[i].peak_days && account_list[i].peak_interval > 0)) { + if(account_list[i].check_interval > 0 || ((account_list[i].peak_days > 0) && account_list[i].peak_interval > 0)) { if(!emdaemon_add_polling_alarm( account_list[i].account_id)) EM_DEBUG_EXCEPTION("emdaemon_add_polling_alarm failed"); } } ret = true; -FINISH_OFF: +FINISH_OFF: if (account_list) emstorage_free_account(&account_list, count, NULL); - + if (err_code != NULL) *err_code = err; - + EM_DEBUG_FUNC_END("ret[%d]", ret); return ret; } @@ -626,41 +748,42 @@ INTERNAL_FUNC int emdaemon_core_init(int *err_code) mail_parameters(NIL, SET_DISABLEPLAINTEXT, (void *) 2); /* Set max trials for login */ - imap_parameters(SET_MAXLOGINTRIALS, (void *)3); - pop3_parameters(SET_MAXLOGINTRIALS, (void *)3); - smtp_parameters(SET_MAXLOGINTRIALS, (void *)3); + imap_parameters(SET_MAXLOGINTRIALS, (void *)2); /* 3-> 2*/ + pop3_parameters(SET_MAXLOGINTRIALS, (void *)2); /* 3-> 2*/ + smtp_parameters(SET_MAXLOGINTRIALS, (void *)1); /* 3-> 2*/ mail_parameters(NIL, SET_SSLCERTIFICATEQUERY, (void *)emnetwork_callback_ssl_cert_query); mail_parameters(NIL, SET_SSLCAPATH, (void *)SSL_CERT_DIRECTORY); /* Set time out in second */ mail_parameters(NIL, SET_OPENTIMEOUT , (void *)50); - mail_parameters(NIL, SET_READTIMEOUT , (void *)180); - mail_parameters(NIL, SET_WRITETIMEOUT , (void *)180); - mail_parameters(NIL, SET_CLOSETIMEOUT , (void *)30); + mail_parameters(NIL, SET_READTIMEOUT , (void *)60); /* 180 -> 15 */ + mail_parameters(NIL, SET_WRITETIMEOUT , (void *)20); /* 180 -> 15 */ + mail_parameters(NIL, SET_CLOSETIMEOUT , (void *)20); /* 30 -> 15 */ emdaemon_init_alarm_data_list(); + /* Openssl library init */ + emcore_init_openssl_library(); + if (err_code) *err_code = EMAIL_ERROR_NONE; return true; } -#ifdef __FEATURE_BLOCKING_MODE__ INTERNAL_FUNC bool emdaemon_init_blocking_mode_status() { EM_DEBUG_FUNC_BEGIN("blocking_mode_of_setting : [%d]", blocking_mode_of_setting); - /*if (vconf_get_bool(VCONFKEY_SETAPPL_BLOCKINGMODE_NOTIFICATIONS, &blocking_mode_of_setting) != 0) { + if (vconf_get_bool(VCONFKEY_SETAPPL_BLOCKINGMODE_NOTIFICATIONS, &blocking_mode_of_setting) != 0) { EM_DEBUG_EXCEPTION("vconf_get_bool failed"); return false; - }*/ + } EM_DEBUG_FUNC_END(); - return false; + return true; } -#endif INTERNAL_FUNC int emdaemon_init_alarm_data_list() { @@ -695,27 +818,30 @@ static int default_alarm_callback(int input_timer_id, void *user_parameter) EM_DEBUG_ALARM_LOG("default_alarm_callback input_timer_id[%d]", input_timer_id); - emdevice_set_sleep_on_off(false, NULL); + emdevice_set_sleep_on_off(STAY_AWAKE_FLAG_FOR_ALARM_CALLBACK, false, NULL); if ((err = emcore_get_alarm_data_by_alarm_id(input_timer_id, &alarm_data)) != EMAIL_ERROR_NONE || alarm_data == NULL) { EM_DEBUG_EXCEPTION("emcore_get_alarm_data_by_alarm_id failed [%d]", err); goto FINISH_OFF; } - if ((err = alarm_data->alarm_callback(input_timer_id, user_parameter)) != EMAIL_ERROR_NONE) { + emcore_delete_alram_data_from_alarm_data_list(alarm_data); + + if ((err = alarm_data->alarm_callback(alarm_data, user_parameter)) != EMAIL_ERROR_NONE) { EM_DEBUG_EXCEPTION("alarm_callback failed [%d]", err); goto FINISH_OFF; } - emcore_delete_alram_data_from_alarm_data_list(alarm_data); - EM_SAFE_FREE(alarm_data); - FINISH_OFF: - if(err != EMAIL_ERROR_NONE) { - emdevice_set_sleep_on_off(true, NULL); + if (alarm_data) { + EM_SAFE_FREE(alarm_data->user_data); + EM_SAFE_FREE(alarm_data); } + emdevice_set_sleep_on_off(STAY_AWAKE_FLAG_FOR_ALARM_CALLBACK, true, NULL); + + EM_DEBUG_FUNC_END("err [%d]", err); return err; } diff --git a/email-daemon/email-daemon-mail.c b/email-daemon/email-daemon-mail.c index f422ac5..0549de7 100755 --- a/email-daemon/email-daemon-mail.c +++ b/email-daemon/email-daemon-mail.c @@ -219,8 +219,8 @@ INTERNAL_FUNC int emdaemon_send_mail_saved(int account_id, int *handle, int* err event_data->account_id = account_id; event_data->event_param_data_3 = EM_SAFE_STRDUP(mailbox_name); - if (!emcore_insert_event(event_data, (int*)handle, &err)) { - EM_DEBUG_EXCEPTION("emcore_insert_event failed [%d]", err); + if (!emcore_insert_event_for_sending_mails(event_data, (int *)handle, &err)) { + EM_DEBUG_EXCEPTION(" emcore_insert_event failed [%d]", err); goto FINISH_OFF; } @@ -660,7 +660,8 @@ FINISH_OFF: EM_SAFE_FREE(ref_account); } - if (thread_error != 0) { + if (err != EMAIL_ERROR_NONE || thread_error != 0) { + emcore_free_event(event_data); EM_SAFE_FREE(event_data); EM_SAFE_FREE(p); } @@ -840,7 +841,7 @@ INTERNAL_FUNC int emdaemon_move_mail_all_mails(int src_mailbox_id, int dst_mailb int *p = NULL; int i = 0; int num = 0; - int thread_error; + int thread_error = 0; email_account_t *ref_account = NULL; email_mail_list_item_t *mail_list = NULL; email_event_t *event_data = NULL; @@ -943,6 +944,7 @@ INTERNAL_FUNC int emdaemon_move_mail_all_mails(int src_mailbox_id, int dst_mailb #endif /* __FEATURE_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 */ + EM_DEBUG_LOG("thread_error [%d]", thread_error); ret = true; FINISH_OFF: @@ -972,6 +974,11 @@ FINISH_OFF: if(mails != NULL ) EM_SAFE_FREE(mails); + if (err != EMAIL_ERROR_NONE || thread_error != 0) { + emcore_free_event(event_data); + EM_SAFE_FREE(event_data); + EM_SAFE_FREE(p); + } EM_DEBUG_FUNC_END("ret [%d]", ret); return ret; @@ -982,7 +989,7 @@ INTERNAL_FUNC int emdaemon_move_mail(int mail_ids[], int num, int dst_mailbox_id EM_DEBUG_FUNC_BEGIN("mail_ids[%p], num[%d], dst_mailbox_id[%d], err_code[%p]", mail_ids, num, dst_mailbox_id, err_code); /* default variable */ - int mail_id = 0, *p = NULL, thread_error; + int mail_id = 0, *p = NULL, thread_error = 0; int ret = false, err = EMAIL_ERROR_NONE; emstorage_mail_tbl_t* mail_table_data = NULL; email_account_t* ref_account = NULL; @@ -1069,6 +1076,7 @@ INTERNAL_FUNC int emdaemon_move_mail(int mail_ids[], int num, int dst_mailbox_id #endif /* __FEATURE_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 */ + EM_DEBUG_LOG("thread_error [%d]", thread_error); ret = true; FINISH_OFF: @@ -1089,6 +1097,12 @@ FINISH_OFF: if (dest_mailbox_tbl) emstorage_free_mailbox(&dest_mailbox_tbl, 1, NULL); + if (err != EMAIL_ERROR_NONE || thread_error != 0) { + emcore_free_event(event_data); + EM_SAFE_FREE(event_data); + EM_SAFE_FREE(p); + } + EM_DEBUG_FUNC_END("ret [%d]", ret); return ret; } @@ -1167,8 +1181,6 @@ FINISH_OFF: INTERNAL_FUNC int emdaemon_update_mail(email_mail_data_t *input_mail_data, email_attachment_data_t *input_attachment_data_list, int input_attachment_count, email_meeting_request_t *input_meeting_request, int input_from_eas) { EM_DEBUG_FUNC_BEGIN("input_mail_data[%p], input_attachment_data_list[%p], input_attachment_count [%d], input_meeting_req [%p], input_from_eas[%d]", input_mail_data, input_attachment_data_list, input_attachment_count, input_meeting_request, input_from_eas); - - int ret = false; int err = EMAIL_ERROR_NONE; /*email_event_t *event_data = NULL;*/ email_account_t *ref_account = NULL; @@ -1212,16 +1224,8 @@ INTERNAL_FUNC int emdaemon_update_mail(email_mail_data_t *input_mail_data, email */ #endif - ret = true; - FINISH_OFF: -/*prevent 64298*/ -/* if (ret == false && event_data) { - emcore_free_event(event_data); - EM_SAFE_FREE(event_data); - } -*/ if (ref_account) { emcore_free_account(ref_account); EM_SAFE_FREE(ref_account); @@ -1505,7 +1509,6 @@ FINISH_OFF: INTERNAL_FUNC int emdaemon_expunge_mails_deleted_flagged(int input_mailbox_id, int input_on_server, int *output_handle) { EM_DEBUG_FUNC_BEGIN("input_mailbox_id [%d], input_on_server [%d], output_handle [%p]", input_mailbox_id, input_on_server, output_handle); - int ret = false; int err = EMAIL_ERROR_NONE; int handle = 0; int event_insert = false; @@ -1551,8 +1554,6 @@ INTERNAL_FUNC int emdaemon_expunge_mails_deleted_flagged(int input_mailbox_id, i goto FINISH_OFF; } - ret = true; - FINISH_OFF: if (event_insert == false && event_data) { diff --git a/email-daemon/email-daemon-mailbox.c b/email-daemon/email-daemon-mailbox.c index 86926f9..859e77f 100755 --- a/email-daemon/email-daemon-mailbox.c +++ b/email-daemon/email-daemon-mailbox.c @@ -55,7 +55,6 @@ INTERNAL_FUNC int emdaemon_get_imap_mailbox_list(int account_id, char* mailbox, int ret = false; int err = EMAIL_ERROR_NONE; - email_account_t *ref_account = NULL; email_event_t *event_data = NULL; if (account_id <= 0 ||!mailbox) { @@ -64,14 +63,6 @@ INTERNAL_FUNC int emdaemon_get_imap_mailbox_list(int account_id, char* mailbox, goto FINISH_OFF; } - ref_account = emcore_get_account_reference(account_id); - - if (!ref_account) { - EM_DEBUG_EXCEPTION("emcore_get_account_reference failed [%d]", account_id); - err = EMAIL_ERROR_INVALID_ACCOUNT; - goto FINISH_OFF; - } - event_data = em_malloc(sizeof(email_event_t)); event_data->type = EMAIL_EVENT_SYNC_IMAP_MAILBOX; event_data->account_id = account_id; @@ -91,11 +82,6 @@ FINISH_OFF: EM_SAFE_FREE(event_data); } - if (ref_account) { - emcore_free_account(ref_account); - EM_SAFE_FREE(ref_account); - } - if (err_code) *err_code = err; EM_DEBUG_FUNC_END(); @@ -252,7 +238,7 @@ INTERNAL_FUNC int emdaemon_add_mailbox(email_mailbox_t* new_mailbox, int on_serv goto FINISH_OFF; } } else { /* sync */ - if (!emcore_create_mailbox(new_mailbox, on_server, &err)) { + if (!emcore_create_mailbox(new_mailbox, on_server, -1, -1, &err)) { EM_DEBUG_EXCEPTION("emcore_create failed [%d]", err); goto FINISH_OFF; } @@ -376,6 +362,7 @@ INTERNAL_FUNC int emdaemon_delete_mailbox(int input_mailbox_id, int on_server, i /* on_server is allowed to be only 0 when server_type is EMAIL_SERVER_TYPE_ACTIVE_SYNC */ if ( ref_account->incoming_server_type == EMAIL_SERVER_TYPE_ACTIVE_SYNC ) { on_server = 0; + recursive = 0; } if ( on_server ) { /* async */ diff --git a/email-daemon/include/email-daemon-auto-poll.h b/email-daemon/include/email-daemon-auto-poll.h index b3fa69b..90e08e4 100755 --- a/email-daemon/include/email-daemon-auto-poll.h +++ b/email-daemon/include/email-daemon-auto-poll.h @@ -44,7 +44,6 @@ extern "C" INTERNAL_FUNC int emdaemon_add_polling_alarm(int account_id); INTERNAL_FUNC int emdaemon_remove_polling_alarm(int account_id); INTERNAL_FUNC int emdaemon_check_auto_polling_started(int account_id); -INTERNAL_FUNC int emdaemon_alarm_polling_cb(alarm_id_t alarm_id, void* user_param); INTERNAL_FUNC int emdaemon_free_account_alarm_binder_list(); #ifdef __cplusplus diff --git a/email-daemon/include/email-daemon-emn.h b/email-daemon/include/email-daemon-emn.h index edb9982..fe8b435 100755 --- a/email-daemon/include/email-daemon-emn.h +++ b/email-daemon/include/email-daemon-emn.h @@ -32,11 +32,6 @@ #ifndef __EMAIL_DAEMON_EMN_H__ #define __EMAIL_DAEMON_EMN_H__ -/** -* @ingroup EMAIL_SERVICE -* @defgroup EMN EMN -* @{ -*/ #include "email-internal-types.h" @@ -93,10 +88,6 @@ typedef int (*email_emn_noti_cb)( } #endif /* __cplusplus */ -/** -* @} @} -*/ - #endif /* __EMAIL_DAEMON_EMN_H__ */ /* EOF */ diff --git a/email-daemon/include/email-daemon-event.h b/email-daemon/include/email-daemon-event.h index e4faa77..799338e 100755 --- a/email-daemon/include/email-daemon-event.h +++ b/email-daemon/include/email-daemon-event.h @@ -34,6 +34,10 @@ INTERNAL_FUNC int emdaemon_start_event_loop(int *err_code); INTERNAL_FUNC int emdaemon_start_event_loop_for_sending_mails(int *err_code); INTERNAL_FUNC int emdaemon_start_thread_for_downloading_partial_body(int *err_code); +#ifdef __FEATURE_OPEN_SSL_MULTIHREAD_HANDLE__ +INTERNAL_FUNC void emdaemon_setup_handler_for_open_ssl_multithread(void); +INTERNAL_FUNC void emdaemon_cleanup_handler_for_open_ssl_multithread(void); +#endif /* __FEATURE_OPEN_SSL_MULTIHREAD_HANDLE__ */ #ifdef __cplusplus } diff --git a/email-daemon/include/email-daemon-init.h b/email-daemon/include/email-daemon-init.h index 9524e37..c15cf49 100755 --- a/email-daemon/include/email-daemon-init.h +++ b/email-daemon/include/email-daemon-init.h @@ -41,9 +41,7 @@ extern "C" INTERNAL_FUNC int emdaemon_core_init(int *err_code); -#ifdef __FEATURE_BLOCKING_MODE__ INTERNAL_FUNC bool emdaemon_init_blocking_mode_status(); -#endif INTERNAL_FUNC int emdaemon_init_alarm_data_list(); diff --git a/email-daemon/include/email-daemon.h b/email-daemon/include/email-daemon.h index e82347c..cda4b71 100755 --- a/email-daemon/include/email-daemon.h +++ b/email-daemon/include/email-daemon.h @@ -31,17 +31,6 @@ #ifndef __EMAIL_DAEMON_H__ #define __EMAIL_DAEMON_H__ -/** -* @defgroup EMAIL_SERVICE EmailFW -* @{ -*/ - -/** -* @ingroup EMAIL_SERVICE -* @defgroup EMAIL_SERVICE Email Service -* @{ -*/ - #include "email-types.h" #include "email-internal-types.h" @@ -644,15 +633,13 @@ INTERNAL_FUNC int emdaemon_modify_seen_flag_of_thread(int thread_id, int seen_fl INTERNAL_FUNC int emdaemon_expunge_mails_deleted_flagged(int input_mailbox_id, int input_on_server, int *output_handle); -INTERNAL_FUNC int emdaemon_kill_daemon_if_no_account(); - INTERNAL_FUNC int emdaemon_check_smack_rule(int app_sockfd, char *file_path); INTERNAL_FUNC int emdaemon_set_smack_label(char *file_path, char *label); INTERNAL_FUNC void emdaemon_start_alert(void); -INTERNAL_FUNC int emdaemon_finalize_sync(int account_id, int total_mail_count, int unread_mail_count, int *error); +INTERNAL_FUNC int emdaemon_finalize_sync(int account_id, int total_mail_count, int unread_mail_count, int vip_total_mail_count, int vip_unread_mail_count, int from_app, int *error); INTERNAL_FUNC int emdaemon_query_smtp_mail_size_limit(int account_id, int *handle, int* err_code); #ifdef __cplusplus diff --git a/email-daemon/main.c b/email-daemon/main.c index 5a01c29..3955382 100755 --- a/email-daemon/main.c +++ b/email-daemon/main.c @@ -31,6 +31,7 @@ #include <sys/types.h> #include <signal.h> #include <time.h> +#include <gio/gio.h> #include "email-daemon.h" #include "email-ipc.h" @@ -50,9 +51,12 @@ #include "email-core-mailbox.h" #include "email-core-utils.h" #include "email-core-smime.h" +#include "email-core-pgp.h" #include "email-core-cert.h" #include "email-core-task-manager.h" #include "email-core-signal.h" +#include "email-core-imap-idle.h" +#include "email-core-gmime.h" #include "email-storage.h" #include "email-dbus-activation.h" @@ -89,14 +93,16 @@ void stb_create_account(HIPC_API a_hAPI) #ifdef __FEATURE_AUTO_POLLING__ /* start auto polling, if check_interval not zero */ - if(account.check_interval > 0 || (account.peak_days && account.peak_interval > 0)) { + if(account.check_interval > 0 || (account.peak_days > 0 && account.peak_interval > 0)) { if(!emdaemon_add_polling_alarm(account.account_id)) EM_DEBUG_EXCEPTION("emdaemon_add_polling_alarm[NOTI_ACCOUNT_ADD] : start auto poll failed >>> "); } -#endif +#ifdef __FEATURE_IMAP_IDLE__ + else if(account.check_interval == 0 || (account.peak_days > 0 && account.peak_interval == 0)) + emcore_refresh_imap_idle_thread(); +#endif /* __FEATURE_IMAP_IDLE__ */ - /* add account details to contact DB */ - emdaemon_insert_accountinfo_to_contact(&account); +#endif local_result = 1; if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &local_result, sizeof(int))) @@ -108,22 +114,31 @@ void stb_create_account(HIPC_API a_hAPI) if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &(account.account_id), sizeof(int))) EM_DEBUG_EXCEPTION("emipc_add_parameter failed "); - /* pass result to app */ - if (!emipc_execute_stub_api(a_hAPI)) - EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed "); + emcore_add_account_reference(&account); FINISH_OFF: - + if ( local_result == 0 ) { if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &local_result, sizeof(int))) EM_DEBUG_EXCEPTION("emipc_add_parameter failed : local_result "); if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int))) EM_DEBUG_EXCEPTION("emipc_add_parameter failed : err"); - if (!emipc_execute_stub_api(a_hAPI)) - EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed "); } + if (!emipc_execute_stub_api(a_hAPI)) + EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed "); emcore_free_account(&account); /* valgrind */ + + //emcore_init_account_reference(); + + if (local_result == 1) { + if (!emcore_notify_storage_event (NOTI_ACCOUNT_ADD_FINISH, account.account_id, 0, NULL, 0)) + EM_DEBUG_EXCEPTION("emcore_notify_storage_event[NOTI_ACCOUNT_ADD] : Notification failed"); + } else { + if (!emcore_notify_storage_event (NOTI_ACCOUNT_ADD_FAIL, account.account_id, 0, NULL, 0)) + EM_DEBUG_EXCEPTION("emcore_notify_storage_event[NOTI_ACCOUNT_ADD] : Notification failed"); + } + EM_DEBUG_FUNC_END(); } @@ -142,7 +157,7 @@ void stb_delete_account(HIPC_API a_hAPI) err = EMAIL_ERROR_IPC_SOCKET_FAILURE; goto FINISH_OFF; } - + if(!emdaemon_delete_account(account_id, &err)) { if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &local_result, sizeof(int))) EM_DEBUG_LOG("emipc_add_parameter failed "); @@ -169,6 +184,10 @@ void stb_delete_account(HIPC_API a_hAPI) if (!emipc_execute_stub_api(a_hAPI)) EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed"); + /* if file is not deleted, main thread kills the thread */ + emcore_send_signal_for_del_account (EMAIL_SIGNAL_DB_DELETED); + EM_DEBUG_LOG ("publish db of account deleted"); + FINISH_OFF: EM_DEBUG_FUNC_END(); @@ -177,11 +196,10 @@ FINISH_OFF: void stb_update_account(HIPC_API a_hAPI) { EM_DEBUG_FUNC_BEGIN(); - int account_id = 0, buffer_size = 0, local_result = 0, with_validation = 0; + int account_id = 0, buffer_size = 0, with_validation = 0; int *ret_nth_value = NULL; char* local_account_stream = NULL; email_account_t new_account_info = {0}; - email_account_t old_account_info = {0}; int err = EMAIL_ERROR_NONE; int handle = 0; @@ -205,79 +223,32 @@ void stb_update_account(HIPC_API a_hAPI) goto FINISH_OFF; } - if(!emdaemon_get_account(account_id, EMAIL_ACC_GET_OPT_FULL_DATA, &old_account_info, &err)) { - EM_DEBUG_EXCEPTION("emdaemon_get_account failed "); - goto FINISH_OFF; - } - - - if( EM_SAFE_STRLEN (new_account_info.incoming_server_password) == 0 ) { - EM_SAFE_FREE(new_account_info.incoming_server_password); /* be allocated but has zero length */ - EM_DEBUG_LOG_SEC("old_account_info->incoming_server_password [%s]", old_account_info.incoming_server_password); - new_account_info.incoming_server_password = EM_SAFE_STRDUP(old_account_info.incoming_server_password); - if(new_account_info.incoming_server_password == NULL) { - EM_DEBUG_EXCEPTION("allocation for new_account_info->password failed"); - err = EMAIL_ERROR_OUT_OF_MEMORY; - goto FINISH_OFF; - } - } - - - if( EM_SAFE_STRLEN (new_account_info.outgoing_server_password) == 0 ) { - EM_SAFE_FREE(new_account_info.outgoing_server_password); - if(old_account_info.outgoing_server_password) { - new_account_info.outgoing_server_password = strdup (old_account_info.outgoing_server_password); - if(new_account_info.outgoing_server_password == NULL) { - EM_DEBUG_EXCEPTION("allocation for new_account_info->outgoing_server_password failed"); - err = EMAIL_ERROR_OUT_OF_MEMORY; - goto FINISH_OFF; - } - } - } - if(with_validation) { - emdaemon_validate_account_and_update(account_id, &new_account_info, &handle, &err); - local_result = 1; + if(!emdaemon_validate_account_and_update(account_id, &new_account_info, &handle, &err)){ + EM_DEBUG_EXCEPTION("emdaemon_validate_account_and_update failed [%d]", err); + goto FINISH_OFF; + } } else { - if(emdaemon_update_account(account_id, &new_account_info, &err)) { - emdaemon_update_accountinfo_to_contact(&old_account_info, &new_account_info); - local_result = 1; - } - else { + if(!emdaemon_update_account(account_id, &new_account_info, &err)) { EM_DEBUG_EXCEPTION("emdaemon_update_account failed [%d]", err); goto FINISH_OFF; } } - if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &local_result, sizeof(int))) - EM_DEBUG_EXCEPTION("emipc_add_parameter for result failed"); +FINISH_OFF: - if(with_validation) { - if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &handle, sizeof(int))) - EM_DEBUG_EXCEPTION("emipc_add_parameter for handle failed"); - } + if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int))) + EM_DEBUG_EXCEPTION("emipc_add_parameter failed"); if (!emipc_execute_stub_api(a_hAPI)) EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed"); -FINISH_OFF: - if ( local_result == 0 ) { - if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &local_result, sizeof(int))) - EM_DEBUG_EXCEPTION("emipc_add_parameter failed"); - - if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int))) - EM_DEBUG_EXCEPTION("emipc_add_parameter failed"); - - if (!emipc_execute_stub_api(a_hAPI)) - EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed"); - } - - emcore_free_account(&old_account_info); - emcore_free_account(&new_account_info); + emcore_init_account_reference(); + EM_DEBUG_FUNC_END(); } @@ -620,7 +591,7 @@ void stb_rename_mailbox(HIPC_API a_hAPI) if(buffer_size > 0) { mailbox_path = (char*)em_malloc(buffer_size); emipc_get_parameter(a_hAPI, ePARAMETER_IN, 1, buffer_size, mailbox_path); - EM_DEBUG_LOG("mailbox_path [%s]", mailbox_path); + EM_DEBUG_LOG_SEC("mailbox_path [%s]", mailbox_path); } buffer_size = emipc_get_parameter_length(a_hAPI, ePARAMETER_IN, 2); @@ -628,7 +599,7 @@ void stb_rename_mailbox(HIPC_API a_hAPI) if(buffer_size > 0) { mailbox_alias = (char*)em_malloc(buffer_size); emipc_get_parameter(a_hAPI, ePARAMETER_IN, 2, buffer_size, mailbox_alias); - EM_DEBUG_LOG("mailbox_alias [%s]", mailbox_alias); + EM_DEBUG_LOG_SEC("mailbox_alias [%s]", mailbox_alias); } emipc_get_parameter(a_hAPI, ePARAMETER_IN, 3, sizeof(int), &on_server); @@ -674,7 +645,7 @@ void stb_rename_mailbox_ex(HIPC_API a_hAPI) if(buffer_size > 0) { mailbox_path = (char*)em_malloc(buffer_size); emipc_get_parameter(a_hAPI, ePARAMETER_IN, 1, buffer_size, mailbox_path); - EM_DEBUG_LOG("mailbox_path [%s]", mailbox_path); + EM_DEBUG_LOG_SEC("mailbox_path [%s]", mailbox_path); } buffer_size = emipc_get_parameter_length(a_hAPI, ePARAMETER_IN, 2); @@ -682,7 +653,7 @@ void stb_rename_mailbox_ex(HIPC_API a_hAPI) if(buffer_size > 0) { mailbox_alias = (char*)em_malloc(buffer_size); emipc_get_parameter(a_hAPI, ePARAMETER_IN, 2, buffer_size, mailbox_alias); - EM_DEBUG_LOG("mailbox_alias [%s]", mailbox_alias); + EM_DEBUG_LOG_SEC("mailbox_alias [%s]", mailbox_alias); } eas_data_length = emipc_get_parameter_length(a_hAPI, ePARAMETER_IN, 3); @@ -903,19 +874,21 @@ FINISH_OFF: EM_DEBUG_FUNC_END(); } + void stb_clear_mail_data (HIPC_API a_hAPI) { EM_DEBUG_FUNC_BEGIN(); int err = EMAIL_ERROR_NONE; + if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int))) + EM_DEBUG_EXCEPTION("emipc_add_parameter failed : err"); + if (!emipc_execute_stub_api(a_hAPI)) + EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed "); + if(emdaemon_clear_all_mail_data(&err)) { EM_DEBUG_LOG(">>> stb_clear_mail_data Success [ %d] >> ", err); } - if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int))) - EM_DEBUG_EXCEPTION("emipc_add_parameter failed : err"); - if (!emipc_execute_stub_api(a_hAPI)) - EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed "); EM_DEBUG_FUNC_END(); } @@ -975,9 +948,9 @@ void stb_get_rule(HIPC_API a_hAPI) emdaemon_get_filter(filter_id, &rule, &err); } else { - err = EMAIL_ERROR_IPC_SOCKET_FAILURE; + err = EMAIL_ERROR_IPC_SOCKET_FAILURE; } - + if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int))) EM_DEBUG_EXCEPTION("emipc_add_parameter failed "); @@ -1243,12 +1216,12 @@ void stb_add_mail(HIPC_API a_hAPI) int param_index = 0; int sync_server = 0; int err = EMAIL_ERROR_NONE; - int mdm_err = EMAIL_ERROR_NONE; int i = 0; email_mail_data_t result_mail_data = {0}; email_attachment_data_t *result_attachment_data = NULL; email_meeting_request_t result_meeting_request = {0}; emipc_email_api_info *api_info = (emipc_email_api_info *)a_hAPI; + email_account_server_t account_server_type = EMAIL_SERVER_TYPE_NONE; /* email_mail_data_t */; @@ -1261,8 +1234,13 @@ void stb_add_mail(HIPC_API a_hAPI) em_convert_byte_stream_to_mail_data(stream, buffer_size, &result_mail_data); } + if (em_get_account_server_type_by_account_id(result_mail_data.account_id, &account_server_type, true, &err) == false) { + EM_DEBUG_EXCEPTION("em_get_account_server_type_by_account_id failed[%d]", err); + goto FINISH_OFF; + } + /* check smack rule for accessing file path */ - if (result_mail_data.file_path_html) { + if ((account_server_type != EMAIL_SERVER_TYPE_ACTIVE_SYNC) && result_mail_data.file_path_html) { if (!emdaemon_check_smack_rule(api_info->response_id, result_mail_data.file_path_html)) { EM_DEBUG_EXCEPTION("emdaemon_check_smack_rule fail"); err = EMAIL_ERROR_NO_SMACK_RULE; @@ -1270,7 +1248,7 @@ void stb_add_mail(HIPC_API a_hAPI) } } - if (result_mail_data.file_path_plain) { + if ((account_server_type != EMAIL_SERVER_TYPE_ACTIVE_SYNC) && result_mail_data.file_path_plain) { if (!emdaemon_check_smack_rule(api_info->response_id, result_mail_data.file_path_plain)) { EM_DEBUG_EXCEPTION("emdaemon_check_smack_rule fail"); err = EMAIL_ERROR_NO_SMACK_RULE; @@ -1278,7 +1256,7 @@ void stb_add_mail(HIPC_API a_hAPI) } } - if (result_mail_data.file_path_mime_entity) { + if ((account_server_type != EMAIL_SERVER_TYPE_ACTIVE_SYNC) && result_mail_data.file_path_mime_entity) { if (!emdaemon_check_smack_rule(api_info->response_id, result_mail_data.file_path_mime_entity)) { EM_DEBUG_EXCEPTION("emdaemon_check_smack_rule fail"); err = EMAIL_ERROR_NO_SMACK_RULE; @@ -1304,13 +1282,13 @@ void stb_add_mail(HIPC_API a_hAPI) err = EMAIL_ERROR_ON_PARSING; goto FINISH_OFF; } - param_index++; } } + param_index++; /* check smack rule for accessing file path */ for (i = 0; i < result_attachment_data_count ; i++) { - if (result_attachment_data[i].attachment_path) { + if ((account_server_type != EMAIL_SERVER_TYPE_ACTIVE_SYNC) && result_attachment_data[i].attachment_path && result_attachment_data[i].save_status) { if (!emdaemon_check_smack_rule(api_info->response_id, result_attachment_data[i].attachment_path)) { EM_DEBUG_EXCEPTION("emdaemon_check_smack_rule fail"); err = EMAIL_ERROR_NO_SMACK_RULE; @@ -1434,9 +1412,9 @@ void stb_update_mail(HIPC_API a_hAPI) err = EMAIL_ERROR_ON_PARSING; goto FINISH_OFF; } - param_index++; } } + param_index++; /* check smack rule for accessing file path */ for (i = 0; i < result_attachment_data_count ; i++) { @@ -1832,6 +1810,7 @@ void stb_get_imap_mailbox_list(HIPC_API a_hAPI) /* account_id */ emipc_get_parameter(a_hAPI, ePARAMETER_IN, 0, sizeof(int), &account_id); + /*need to check: why err value is changed? */ if(emdaemon_get_imap_mailbox_list(account_id, "", &handle, &err)) err = EMAIL_ERROR_NONE; @@ -2030,110 +2009,6 @@ void stb_cancel_send_mail_job(HIPC_API a_hAPI) EM_DEBUG_FUNC_END(); } -void stb_search_mail_on_server(HIPC_API a_hAPI) -{ - EM_DEBUG_FUNC_BEGIN(); - int i = 0; - int err = EMAIL_ERROR_NONE; - int account_id = 0; - int mailbox_id = 0; - int buffer_size = 0; - int search_filter_count = 0; - char *stream_for_search_filter_list = NULL; - unsigned int job_handle = 0; - email_search_filter_t *search_filter_list = NULL; - - /* account_id */ - emipc_get_parameter(a_hAPI, ePARAMETER_IN, 0, sizeof(int), &account_id); - EM_DEBUG_LOG("account_id [%d]", account_id); - - /* mailbox_id */ - emipc_get_parameter(a_hAPI, ePARAMETER_IN, 1, sizeof(int), &mailbox_id); - EM_DEBUG_LOG("mailbox_id [%d]", mailbox_id); - - /* search_filter_list */ - buffer_size = emipc_get_parameter_length(a_hAPI, ePARAMETER_IN, 2); - - if(buffer_size > 0) { - stream_for_search_filter_list = (char*)em_malloc(buffer_size); - EM_NULL_CHECK_FOR_VOID(stream_for_search_filter_list); - emipc_get_parameter(a_hAPI, ePARAMETER_IN, 2, buffer_size, stream_for_search_filter_list); - em_convert_byte_stream_to_search_filter(stream_for_search_filter_list, &search_filter_list, &search_filter_count); - EM_SAFE_FREE(stream_for_search_filter_list); - } - - if(!emdaemon_search_mail_on_server(account_id ,mailbox_id, search_filter_list, search_filter_count, &job_handle, &err)) - EM_DEBUG_LOG("success"); - - if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int))) - EM_DEBUG_EXCEPTION("emipc_add_parameter failed"); - - if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &job_handle, sizeof(int))) - EM_DEBUG_EXCEPTION("emipc_add_parameter failed "); - - if (!emipc_execute_stub_api(a_hAPI)) - EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed"); - - if(search_filter_list) { - for(i = 0; i < search_filter_count; i++) { - switch(search_filter_list[i].search_filter_type) { - case EMAIL_SEARCH_FILTER_TYPE_BCC : - case EMAIL_SEARCH_FILTER_TYPE_CC : - case EMAIL_SEARCH_FILTER_TYPE_FROM : - case EMAIL_SEARCH_FILTER_TYPE_KEYWORD : - case EMAIL_SEARCH_FILTER_TYPE_SUBJECT : - case EMAIL_SEARCH_FILTER_TYPE_TO : - case EMAIL_SEARCH_FILTER_TYPE_MESSAGE_ID : - EM_SAFE_FREE(search_filter_list[i].search_filter_key_value.string_type_key_value); - break; - default : - break; - } - } - } - - EM_SAFE_FREE(search_filter_list); - - EM_DEBUG_FUNC_END(); -} - -void stb_clear_result_of_search_mail_on_server(HIPC_API a_hAPI) -{ - EM_DEBUG_FUNC_BEGIN(); - int err = EMAIL_ERROR_NONE; - int account_id = 0; - emstorage_mailbox_tbl_t *mailbox_tbl = NULL; - - /* account_id */ - emipc_get_parameter(a_hAPI, ePARAMETER_IN, 0, sizeof(int), &account_id); - - EM_DEBUG_LOG("account_id [%d]", account_id); - - if (!emstorage_get_mailbox_by_mailbox_type(account_id, EMAIL_MAILBOX_TYPE_SEARCH_RESULT, &mailbox_tbl, true, &err)) { - EM_DEBUG_EXCEPTION(" emstorage_get_mailbox_by_mailbox_type failed [%d]", err); - goto FINISH_OFF; - } - - if (!emstorage_delete_mail_by_mailbox(account_id, mailbox_tbl->mailbox_id, true, &err)) - EM_DEBUG_EXCEPTION(" emstorage_get_mailbox_by_mailbox_type failed [%d]", err); - -FINISH_OFF: - - if (mailbox_tbl) { - emstorage_free_mailbox(&mailbox_tbl, 1, NULL); - } - - if (!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int))) - EM_DEBUG_EXCEPTION("emipc_add_parameter failed"); - - if (!emipc_execute_stub_api(a_hAPI)) - EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed"); - - EM_DEBUG_FUNC_END(); -} - - - void stb_add_account_with_validation(HIPC_API a_hAPI) { EM_DEBUG_FUNC_BEGIN(); @@ -2192,10 +2067,14 @@ void stb_add_account_with_validation(HIPC_API a_hAPI) } #ifdef __FEATURE_AUTO_POLLING__ /* start auto polling, if check_interval not zero */ - if(ref_check_interval > 0 || (ref_account->peak_days && ref_account->peak_interval > 0)) { + if(ref_check_interval > 0 || (ref_account->peak_days > 0 && ref_account->peak_interval > 0)) { if(!emdaemon_add_polling_alarm(ref_account_id)) EM_DEBUG_EXCEPTION("emdaemon_add_polling_alarm[NOTI_ACCOUNT_ADD] : start auto poll failed >>> "); } +#ifdef __FEATURE_IMAP_IDLE__ + else if(ref_check_interval == 0 || (ref_account->peak_days > 0 && ref_account->peak_interval == 0)) + emcore_refresh_imap_idle_thread(); +#endif /* __FEATURE_IMAP_IDLE__ */ #endif /* __FEATURE_AUTO_POLLING__ */ /* add account details to contact DB */ /* emdaemon_insert_accountinfo_to_contact(account); */ @@ -2264,7 +2143,7 @@ void stb_restore_account(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; + int result = 0, err_code = 0, handle = 0, file_path_length = 0; /* file_path_length */ file_path_length = emipc_get_parameter_length(a_hAPI, ePARAMETER_IN, 0); @@ -2273,20 +2152,24 @@ void stb_restore_account(HIPC_API a_hAPI) file_path = em_malloc(file_path_length); emipc_get_parameter(a_hAPI, ePARAMETER_IN, 0, file_path_length, file_path); EM_DEBUG_LOG_SEC("file_path [%s]", file_path); - local_result = emcore_restore_accounts((const char*)file_path, &err_code); } - if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &local_result, sizeof(int))) + /* file_path could be NULL */ + err_code = emcore_restore_accounts((const char*)file_path); + + result = (err_code == EMAIL_ERROR_NONE)?1:0; + + if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &result, sizeof(int))) EM_DEBUG_LOG("emipc_add_parameter failed "); if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err_code, sizeof(int))) - EM_DEBUG_EXCEPTION("emipc_add_parameter failed "); + EM_DEBUG_EXCEPTION("emipc_add_parameter failed "); if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &handle, sizeof(int))) EM_DEBUG_EXCEPTION("emipc_add_parameter result failed "); if (!emipc_execute_stub_api(a_hAPI)) - EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed "); + EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed"); EM_SAFE_FREE(file_path); #endif /* __FEATURE_BACKUP_ACCOUNT__ */ @@ -2440,9 +2323,9 @@ void stb_delete_certificate(HIPC_API a_hAPI) if (!emipc_execute_stub_api(a_hAPI)) EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed"); - + EM_SAFE_FREE(email_address); - EM_DEBUG_FUNC_END(); + EM_DEBUG_FUNC_END(); } void stb_verify_signature(HIPC_API a_hAPI) @@ -2477,16 +2360,24 @@ void stb_verify_signature(HIPC_API a_hAPI) goto FINISH_OFF; } - for (count = 0; count < attachment_tbl_count; count++) { - if (strcasestr(attachment_tbl_list[count].attachment_name, "p7s") == NULL) - continue; - - break; + for (count = 0; count < attachment_tbl_count ; count++) { + if (attachment_tbl_list[count].attachment_mime_type && strcasestr(attachment_tbl_list[count].attachment_mime_type, "SIGNATURE")) + break; } - if (!emcore_verify_signature(attachment_tbl_list[count].attachment_path, mail_data->file_path_mime_entity, &verify, &err)) { - EM_DEBUG_EXCEPTION("emcore_verify_signature failed"); - goto FINISH_OFF; + if (mail_data->smime_type == EMAIL_SMIME_SIGNED) { + if (!emcore_verify_signature(attachment_tbl_list[count].attachment_path, mail_data->file_path_mime_entity, &verify, &err)) { + EM_DEBUG_EXCEPTION("emcore_verify_signature failed"); + goto FINISH_OFF; + } + } else if (mail_data->smime_type == EMAIL_PGP_SIGNED) { + if ((err = emcore_pgp_get_verify_signature(attachment_tbl_list[count].attachment_path, mail_data->file_path_mime_entity, mail_data->digest_type, &verify)) != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emcore_pgp_get_verify_signature failed : [%d]", err); + goto FINISH_OFF; + } + } else { + EM_DEBUG_LOG("Invalid signed mail"); + err = EMAIL_ERROR_INVALID_PARAM; } FINISH_OFF: @@ -2540,8 +2431,8 @@ void stb_verify_certificate(HIPC_API a_hAPI) if (!emipc_execute_stub_api(a_hAPI)) EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed "); - EM_SAFE_FREE(cert_file_path); - EM_DEBUG_FUNC_END(); + EM_SAFE_FREE(cert_file_path); + EM_DEBUG_FUNC_END(); } void stb_ping_service(HIPC_API a_hAPI) @@ -2563,6 +2454,7 @@ void stb_update_notification_bar_for_unread_mail(HIPC_API a_hAPI) EM_DEBUG_FUNC_BEGIN(); int err = EMAIL_ERROR_NONE, account_id; int total_mail_count = 0, unread_mail_count = 0; + int input_from_eas = 0; /* account_id */ emipc_get_parameter(a_hAPI, ePARAMETER_IN, 0, sizeof(int), &account_id); @@ -2574,7 +2466,12 @@ void stb_update_notification_bar_for_unread_mail(HIPC_API a_hAPI) emipc_get_parameter(a_hAPI, ePARAMETER_IN, 2, sizeof(int), &unread_mail_count); EM_DEBUG_LOG("unread_mail_count [%d]", unread_mail_count); - if(!emdaemon_finalize_sync(account_id, total_mail_count, unread_mail_count, &err)) { + emipc_get_parameter(a_hAPI, ePARAMETER_IN, 3, sizeof(int), &input_from_eas); + EM_DEBUG_LOG("unread_mail_count [%d]", input_from_eas); + + emcore_display_unread_in_badge(NULL); + + if(!emdaemon_finalize_sync(account_id, total_mail_count, unread_mail_count, 0, 0, input_from_eas, &err)) { EM_DEBUG_EXCEPTION("emdaemon_finalize_sync failed [%d]", err); } @@ -2586,6 +2483,26 @@ void stb_update_notification_bar_for_unread_mail(HIPC_API a_hAPI) EM_DEBUG_FUNC_END(); } +void stb_clear_notification_bar(HIPC_API a_hAPI) +{ + EM_DEBUG_FUNC_BEGIN(); + int err = EMAIL_ERROR_NONE, account_id; + + /* account_id */ + emipc_get_parameter(a_hAPI, ePARAMETER_IN, 0, sizeof(int), &account_id); + EM_DEBUG_LOG("account_id [%d]", account_id); + + if((err = emcore_clear_notifications(account_id)) != EMAIL_ERROR_NONE) + EM_DEBUG_EXCEPTION("emdaemon_finalize_sync failed [%d]", err); + + if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int))) + EM_DEBUG_EXCEPTION("emipc_add_parameter failed "); + + if (!emipc_execute_stub_api(a_hAPI)) + EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed "); + EM_DEBUG_FUNC_END(); +} + void stb_show_user_message(HIPC_API a_hAPI) { EM_DEBUG_FUNC_BEGIN(); @@ -2606,8 +2523,8 @@ void stb_show_user_message(HIPC_API a_hAPI) emipc_get_parameter(a_hAPI, ePARAMETER_IN, 2, sizeof(int), ¶m_error); EM_DEBUG_LOG("param_error [%d]", param_error); - if( (err = emcore_show_user_message(param_id, param_action, param_error)) != EMAIL_ERROR_NONE) { - EM_DEBUG_EXCEPTION("emcore_show_user_message failed [%d]", err); + if(!emcore_show_user_message(param_id, param_action, param_error)) { + EM_DEBUG_EXCEPTION("emcore_show_user_message failed"); } if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int))) @@ -2622,179 +2539,14 @@ void stb_show_user_message(HIPC_API a_hAPI) void stb_write_mime_file(HIPC_API a_hAPI) { EM_DEBUG_FUNC_BEGIN(); - int i = 0; - int exist_file_path = 0; - int buffer_size = 0; - int local_result = 0; - int result_attachment_data_count = 0; - int param_index = 0; int err = EMAIL_ERROR_NONE; - int ret = EMAIL_ERROR_NONE; - char *file_path = NULL; - char *output_file_path = NULL; - email_mail_data_t result_mail_data = {0}; - email_attachment_data_t *result_attachment_data = NULL; - emstorage_mail_tbl_t *input_mail_tbl_data = NULL; - emstorage_attachment_tbl_t *input_attachment_tbl_data = NULL; - emipc_email_api_info *api_info = (emipc_email_api_info *)a_hAPI; - - /* email_mail_data_t */; - buffer_size = emipc_get_nth_parameter_length(a_hAPI, ePARAMETER_IN, param_index); - EM_DEBUG_LOG("email_mail_data_t buffer_size[%d]", buffer_size); - - /* mail_data */ - if(buffer_size > 0) { - char *stream = (char*) emipc_get_nth_parameter_data(a_hAPI, ePARAMETER_IN, param_index++); - em_convert_byte_stream_to_mail_data(stream, buffer_size, &result_mail_data); - } - - /* check smack rule for accessing file path */ - if (result_mail_data.file_path_html) { - if (!emdaemon_check_smack_rule(api_info->response_id, result_mail_data.file_path_html)) { - EM_DEBUG_EXCEPTION("emdaemon_check_smack_rule fail"); - err = EMAIL_ERROR_NO_SMACK_RULE; - goto FINISH_OFF; - } - } - - if (result_mail_data.file_path_plain) { - if (!emdaemon_check_smack_rule(api_info->response_id, result_mail_data.file_path_plain)) { - EM_DEBUG_EXCEPTION("emdaemon_check_smack_rule fail"); - err = EMAIL_ERROR_NO_SMACK_RULE; - goto FINISH_OFF; - } - } - - if (result_mail_data.file_path_mime_entity) { - if (!emdaemon_check_smack_rule(api_info->response_id, result_mail_data.file_path_mime_entity)) { - EM_DEBUG_EXCEPTION("emdaemon_check_smack_rule fail"); - err = EMAIL_ERROR_NO_SMACK_RULE; - goto FINISH_OFF; - } - } - /* check smack rule - END */ - - /* attachment */ - buffer_size = emipc_get_nth_parameter_length(a_hAPI, ePARAMETER_IN, param_index); - EM_DEBUG_LOG("email_attachment_data_t buffer_size[%d]", buffer_size); - - if(buffer_size > 0) { - char *stream = (char*) emipc_get_nth_parameter_data(a_hAPI, ePARAMETER_IN, param_index); - em_convert_byte_stream_to_attachment_data(stream, buffer_size, &result_attachment_data, &result_attachment_data_count); - - EM_DEBUG_LOG("result_attachment_data_count[%d]", result_attachment_data_count); - if (!result_attachment_data_count) { - EM_DEBUG_LOG("Not include attachment data"); - } else { - if(!result_attachment_data) { - EM_DEBUG_EXCEPTION("em_convert_byte_stream_to_attachment_data failed"); - err = EMAIL_ERROR_ON_PARSING; - goto FINISH_OFF; - } - param_index++; - } - } - - /* check smack rule for accessing file path */ - for (i = 0; i < result_attachment_data_count ; i++) { - if (result_attachment_data[i].attachment_path && result_attachment_data[i].save_status) { - if (!emdaemon_check_smack_rule(api_info->response_id, result_attachment_data[i].attachment_path)) { - EM_DEBUG_EXCEPTION("emdaemon_check_smack_rule fail"); - err = EMAIL_ERROR_NO_SMACK_RULE; - goto FINISH_OFF; - } - } - } - - buffer_size = emipc_get_nth_parameter_length(a_hAPI, ePARAMETER_IN, param_index); - if (buffer_size > 0) { - output_file_path = (char *)emipc_get_nth_parameter_data(a_hAPI, ePARAMETER_IN, param_index); - EM_DEBUG_LOG_SEC("output_file_path : [%s]", output_file_path); - } - - /* Convert mail_data to mail_tbl */ - if (!em_convert_mail_data_to_mail_tbl(&result_mail_data, 1, &input_mail_tbl_data, &err)) { - EM_DEBUG_EXCEPTION("em_convert_mail_data_to_mail_tbl failed"); - goto FINISH_OFF; - } - - /* Convert attachment_data to attachment_tbl */ - if (result_attachment_data_count > 0) { - input_attachment_tbl_data = (emstorage_attachment_tbl_t *)em_malloc(sizeof(emstorage_attachment_tbl_t) * result_attachment_data_count); - if (input_attachment_tbl_data == NULL) { - EM_DEBUG_EXCEPTION("em_malloc failed"); - err = EMAIL_ERROR_OUT_OF_MEMORY; - goto FINISH_OFF; - } - } - - for (i = 0; i < result_attachment_data_count ; i++) { - input_attachment_tbl_data[i].attachment_id = result_attachment_data[i].attachment_id; - input_attachment_tbl_data[i].attachment_name = EM_SAFE_STRDUP(result_attachment_data[i].attachment_name); - input_attachment_tbl_data[i].attachment_path = EM_SAFE_STRDUP(result_attachment_data[i].attachment_path); - input_attachment_tbl_data[i].attachment_size = result_attachment_data[i].attachment_size; - input_attachment_tbl_data[i].mail_id = result_attachment_data[i].mail_id; - input_attachment_tbl_data[i].account_id = result_attachment_data[i].account_id; - input_attachment_tbl_data[i].mailbox_id = result_attachment_data[i].mailbox_id; - input_attachment_tbl_data[i].attachment_save_status = result_attachment_data[i].save_status; - input_attachment_tbl_data[i].attachment_drm_type = result_attachment_data[i].drm_status; - input_attachment_tbl_data[i].attachment_inline_content_status = result_attachment_data[i].inline_content_status; - input_attachment_tbl_data[i].attachment_mime_type = EM_SAFE_STRDUP(result_attachment_data[i].attachment_mime_type); - } - - if (!emcore_make_rfc822_file_from_mail(input_mail_tbl_data, input_attachment_tbl_data, result_attachment_data_count, NULL, &file_path, NULL, &err)) { - EM_DEBUG_EXCEPTION("emcore_make_rfc822_file_from_mail failed"); - goto FINISH_OFF; - } - - if (output_file_path) { - if (!emstorage_move_file(file_path, output_file_path, false, &err)) { - EM_DEBUG_EXCEPTION("emstorage_move_file failed : [%d]", err); - goto FINISH_OFF; - } - } else { - exist_file_path = 1; - output_file_path = EM_SAFE_STRDUP(file_path); - } - - if (!emdaemon_set_smack_label(output_file_path, "system::media")) { - EM_DEBUG_EXCEPTION("emdaemon_set_smack_label failed"); - } - local_result = 1; - -FINISH_OFF: - if ( local_result == 0 ) { - if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int))) - EM_DEBUG_EXCEPTION("emipc_add_parameter failed"); - } else { - if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int))) - EM_DEBUG_EXCEPTION("emipc_add_parameter failed"); - - if (!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, (char *)output_file_path, EM_SAFE_STRLEN(output_file_path) + 1)) { - EM_DEBUG_EXCEPTION("emipc_add_parameter failed"); - err = EMAIL_ERROR_NULL_VALUE; - goto FINISH_OFF; - } - } + if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int))) + EM_DEBUG_EXCEPTION("emipc_add_parameter failed "); if (!emipc_execute_stub_api(a_hAPI)) - EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed"); - - emstorage_free_attachment(&input_attachment_tbl_data, result_attachment_data_count, &ret); - - emstorage_free_mail(&input_mail_tbl_data, 1, &ret); - - emcore_free_mail_data(&result_mail_data); - - if(result_attachment_data) - emcore_free_attachment_data(&result_attachment_data, result_attachment_data_count, NULL); - - EM_SAFE_FREE(file_path); - if (exist_file_path) - EM_SAFE_FREE(output_file_path); + EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed "); - em_flush_memory(); EM_DEBUG_FUNC_END(); } @@ -2969,6 +2721,7 @@ FINISH_OFF: EM_SAFE_FREE(task_param->mail_id_array); EM_SAFE_FREE(task_param); + emcore_close_recv_stream_list(); EM_DEBUG_FUNC_END("err [%d]", err); return SUCCESS; } @@ -3161,7 +2914,7 @@ FINISH_OFF: /* Free task parameter */ EM_SAFE_FREE(task_param); - + emcore_close_smtp_stream_list(); EM_DEBUG_FUNC_END("err [%d]", err); return SUCCESS; } @@ -3423,14 +3176,6 @@ void stb_API_mapper(HIPC_API a_hAPI) stb_cancel_send_mail_job(a_hAPI); break; - case _EMAIL_API_SEARCH_MAIL_ON_SERVER : - stb_search_mail_on_server(a_hAPI); - break; - - case _EMAIL_API_CLEAR_RESULT_OF_SEARCH_MAIL_ON_SERVER : - stb_clear_result_of_search_mail_on_server(a_hAPI); - break; - case _EMAIL_API_ADD_ACCOUNT_WITH_VALIDATION : stb_add_account_with_validation(a_hAPI); break; @@ -3475,6 +3220,10 @@ void stb_API_mapper(HIPC_API a_hAPI) stb_update_notification_bar_for_unread_mail(a_hAPI); break; + case _EMAIL_API_CLEAR_NOTIFICATION_BAR : + stb_clear_notification_bar(a_hAPI); + break; + case _EMAIL_API_SHOW_USER_MESSAGE : stb_show_user_message(a_hAPI); break; @@ -3509,6 +3258,33 @@ void stb_API_mapper(HIPC_API a_hAPI) GMainLoop *g_mainloop = NULL; +/* this func should be called in main_loop */ +INTERNAL_FUNC int kill_daemon_if_no_account() +{ + EM_DEBUG_FUNC_BEGIN(); + int err = EMAIL_ERROR_NONE; + email_account_t *account_list = NULL; + int account_count = 0; + + if (!emcore_get_account_reference_list(&account_list, &account_count, &err)) { + EM_DEBUG_LOG("emcore_get_account_reference_list failed [%d]", err); + } + + EM_DEBUG_LOG("account_count [%d]", account_count); + + if (account_count == 0) { + EM_DEBUG_LOG("email-service is going to shutdown"); + g_main_loop_quit (g_mainloop); + } + + if(account_list) + emcore_free_account_list(&account_list, account_count, NULL); + + EM_DEBUG_FUNC_END("err [%d]", err); + return err; +} + + static void callback_for_sigterm(int signum) { EM_DEBUG_FUNC_BEGIN("signum [%d]", signum); @@ -3519,12 +3295,14 @@ static void callback_for_sigterm(int signum) EM_DEBUG_FUNC_END(); } -gboolean callback_for_timeout(gpointer user_data) +extern int launch_pid; + +gboolean callback_for_shutdown(gpointer user_data) { EM_DEBUG_FUNC_BEGIN("user_data[%p]", user_data); - if(emipc_get_launch_method() != EMAIL_LAUNCHED_BY_DBUS_ACTIVATION) { - emdaemon_kill_daemon_if_no_account(); + if (launch_pid == 0) { + kill_daemon_if_no_account(); } EM_DEBUG_FUNC_END(); @@ -3547,25 +3325,115 @@ gboolean callback_for_del_account (GIOChannel *ch, GIOCondition cond, gpointer d } EM_DEBUG_LOG ("callback_for_del_account called file_del[%d] db_del[%d]", file_del, db_del); - /* if called twice, process termination begins. + /* if called twice, process termination begins. two threads should complete the delete task */ if (file_del && db_del) { - emdaemon_kill_daemon_if_no_account(); + kill_daemon_if_no_account(); file_del = db_del = 0; /* if there is an account, reset status */ } return TRUE; } +/* gdbus variables */ +static GDBusNodeInfo *introspection_data = NULL; +extern gchar introspection_xml[]; + +static void +handle_method_call (GDBusConnection *connection, + const gchar *sender, + const gchar *object_path, + const gchar *interface_name, + const gchar *method_name, + GVariant *parameters, + GDBusMethodInvocation *invocation, + gpointer user_data) +{ + /* called by emipc_launch_email_service */ + if (g_strcmp0 (method_name, "Launch") == 0) { + int caller_pid = 0; + g_variant_get (parameters, "(i)", &caller_pid); + + launch_pid = caller_pid; + g_dbus_method_invocation_return_value (invocation, g_variant_new ("(i)", EMAIL_ERROR_NONE)); + EM_DEBUG_LOG ("email-service launched by pid [%d]", caller_pid); + } +/* + else if (g_strcmp0 (method_name, "SetContactsLog") == 0) { + GVariant* ret = em_gdbus_set_contact_log(parameters); + g_dbus_method_invocation_return_value (invocation, ret); + } + else if (g_strcmp0 (method_name, "DeleteContactsLog") == 0) { + GVariant* ret = em_gdbus_delete_contact_log(parameters); + g_dbus_method_invocation_return_value (invocation, ret); + } +*/ + else if (g_strcmp0 (method_name, "GetDisplayName") == 0) { + GVariant* ret = em_gdbus_get_display_name(parameters); + g_dbus_method_invocation_return_value (invocation, ret); + } + else if (g_strcmp0 (method_name, "CheckBlockingMode") == 0) { + GVariant* ret = em_gdbus_check_blocking_mode(parameters); + g_dbus_method_invocation_return_value (invocation, ret); + } +} + +static const +GDBusInterfaceVTable interface_vtable = +{ + handle_method_call, + NULL, + NULL +}; + +static void +on_bus_acquired (GDBusConnection *connection, const gchar *name, gpointer user_data) +{ + EM_DEBUG_LOG ("on_bus_acquired begin"); + + guint reg_id; + GError *error = NULL; + + reg_id = g_dbus_connection_register_object (connection, + EMAIL_SERVICE_PATH, + introspection_data->interfaces[0], + &interface_vtable, + NULL, /* user_data */ + NULL, /* user_data_free_func */ + &error); /* GError** */ + if (reg_id == 0) { + EM_DEBUG_EXCEPTION ("g_dbus_connection_register_object error[%s]",error->message); + g_error_free (error); + } + EM_DEBUG_LOG ("on_bus_acquired end [%d]", reg_id); +} + +static void on_name_acquired (GDBusConnection *connection, + const gchar *name, + gpointer user_data) +{ + EM_DEBUG_LOG ("on_name_acquired [%s]", name); +} + +static void on_name_lost (GDBusConnection *connection, + const gchar *name, + gpointer user_data) +{ + EM_DEBUG_EXCEPTION ("on_name_lost [%p] [%s]", connection, name); +} + INTERNAL_FUNC int main(int argc, char *argv[]) { - /* Do the email-service Initialization + /* Do the email-service Initialization 1. Create all DB tables and load the email engine */ EM_DEBUG_LOG("Email service begin"); int err = 0, ret; - GMainLoop *mainloop; + GMainLoop *mainloop = NULL; + int owner_id = 0; + + g_type_init(); EM_DEBUG_LOG("ipcEmailStub_Initialize Start"); - + ret = emipc_initialize_stub(stb_API_mapper); if(ret == true) @@ -3576,28 +3444,64 @@ INTERNAL_FUNC int main(int argc, char *argv[]) signal(SIGPIPE, SIG_IGN); /* to ignore signal 13(SIGPIPE) */ signal(SIGTERM, callback_for_sigterm); /* to handle signal 15(SIGTERM) - power off case*/ + emcore_connect_contacts_service(); + + emcore_gmime_init(); + emdaemon_initialize(&err); - /* Start auto polling */ -#ifdef __FEATURE_AUTO_POLLING__ - emdaemon_start_auto_polling(&err); -#endif + g_timeout_add(5000, callback_for_shutdown, NULL); + + /* pipe between main and del account thread */ + int *pipefd = emcore_init_pipe_for_del_account (); + /* main loop uses IO channel for listening an event */ + GIOChannel *ch = g_io_channel_unix_new (pipefd[0]); + /* non-blocking mode */ + g_io_channel_set_flags (ch, g_io_channel_get_flags (ch) | G_IO_FLAG_NONBLOCK, NULL); + /* main loop watches the IO, and call the cb when data is ready */ + g_io_add_watch (ch, G_IO_IN, &callback_for_del_account, NULL); + + EM_DEBUG_LOG ("main pipe[%d][%d]", pipefd[0], pipefd[1]); + + /* gdbus setup */ + GError *error = NULL; + introspection_data = g_dbus_node_info_new_for_xml (introspection_xml, &error); + if (!introspection_data) { + /* introspection_xml may be invalid */ + EM_DEBUG_EXCEPTION ("g_dbus_node_info_new_for_xml error [%s]", error->message); + g_error_free (error); + } + + owner_id = g_bus_own_name (G_BUS_TYPE_SYSTEM, + EMAIL_SERVICE_NAME, + G_BUS_NAME_OWNER_FLAGS_NONE, + on_bus_acquired, + on_name_acquired, + on_name_lost, + NULL, + NULL); + if (!owner_id) { + EM_DEBUG_EXCEPTION ("g_bus_own_name error"); + } + EM_DEBUG_LOG ("owner_id [%d]", owner_id); mainloop = g_main_loop_new(NULL, 0); g_mainloop = mainloop; - g_type_init(); - g_main_loop_run(mainloop); - + /* Clean up resources */ + g_bus_unown_name (owner_id); g_main_loop_unref(mainloop); g_mainloop = NULL; emipc_finalize_stub(); emdaemon_finalize(NULL); + emcore_gmime_shutdown(); + EM_DEBUG_LOG ("Goodbye, world"); EM_DEBUG_FUNC_END(); + exit(44); /* exit with exit code 44 to prevent restarting */ return 0; } diff --git a/email-ipc/CMakeLists.txt b/email-ipc/CMakeLists.txt index 2baadd4..1b50a60 100755 --- a/email-ipc/CMakeLists.txt +++ b/email-ipc/CMakeLists.txt @@ -11,6 +11,8 @@ MESSAGE("") MESSAGE(">>> current directory: ${CMAKE_CURRENT_SOURCE_DIR}") MESSAGE(">>> Build type: ${CMAKE_BUILD_TYPE}") +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wl,--gc-sections") + SET(IPC-LIB "email-ipc") SET(IPC-SRCS ${CMAKE_SOURCE_DIR}/email-ipc/email-ipc-api.c @@ -46,7 +48,7 @@ INCLUDE_DIRECTORIES( ) INCLUDE(FindPkgConfig) -pkg_check_modules(ipc_pkgs REQUIRED dlog dbus-1 glib-2.0 libsystemd-daemon) +pkg_check_modules(ipc_pkgs REQUIRED dlog dbus-1 glib-2.0 libsystemd-daemon contacts-service2) FOREACH(flag ${ipc_pkgs_CFLAGS}) SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") @@ -59,20 +61,12 @@ ADD_DEFINITIONS("-DBRSDK_VER=\"2\"") SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed") -MESSAGE("Before DBUS binding") - -FIND_PROGRAM(DBUS_BINDING_TOOL NAMES dbus-binding-tool) -EXEC_PROGRAM("${DBUS_BINDING_TOOL}" ARGS "--prefix=email_service ${CMAKE_CURRENT_SOURCE_DIR}/email-activation/email-service.xml --mode=glib-client --output=${CMAKE_CURRENT_SOURCE_DIR}/email-activation/include/email-service-glue.h") -EXEC_PROGRAM("${DBUS_BINDING_TOOL}" ARGS "--prefix=email_service ${CMAKE_CURRENT_SOURCE_DIR}/email-activation/email-service.xml --mode=glib-server --output=${CMAKE_CURRENT_SOURCE_DIR}/email-activation/include/email-service-binding.h") - -MESSAGE("After DBUS binding") - ADD_LIBRARY(${IPC-LIB} SHARED ${IPC-SRCS}) TARGET_LINK_LIBRARIES(${IPC-LIB} ${ipc_pkgs_LDFLAGS} email-common-use pthread) SET_TARGET_PROPERTIES(${IPC-LIB} PROPERTIES SOVERSION ${VERSION_MAJOR}) SET_TARGET_PROPERTIES(${IPC-LIB} PROPERTIES VERSION ${VERSION}) INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/email-activation/email-service.service DESTINATION share/dbus-1/services) -INSTALL(TARGETS ${IPC-LIB} DESTINATION ${LIB_INSTALL_DIR} COMPONENT RuntimeLibraries) +INSTALL(TARGETS ${IPC-LIB} DESTINATION lib COMPONENT RuntimeLibraries) diff --git a/email-ipc/email-activation/email-dbus-activation.c b/email-ipc/email-activation/email-dbus-activation.c index e0438db..e8cc7bb 100755 --- a/email-ipc/email-activation/email-dbus-activation.c +++ b/email-ipc/email-activation/email-dbus-activation.c @@ -1,182 +1,193 @@ -/*
-* email-service
-*
-* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
-*
-* Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com>
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*
-*/
-
-#include <glib.h>
-#include <pthread.h>
-#include <dbus/dbus-glib.h>
-#include <dbus/dbus-glib-bindings.h>
-#include <sys/utsname.h>
-#include "email-types.h"
-#include "email-debug-log.h"
-#include "email-dbus-activation.h"
-#include "email-daemon-init.h"
-#include "email-service-binding.h"
-#include "email-service-glue.h"
-#include <unistd.h>
-
-
-G_DEFINE_TYPE(EmailService, email_service, G_TYPE_OBJECT)
-
-int _launch_method = EMAIL_LAUNCHED_BY_UNKNOWN_METHOD;
-
-EXPORT_API void emipc_set_launch_method(int input_launch_method)
-{
- EM_DEBUG_LOG("input_launch_method [%d]", input_launch_method);
- _launch_method = input_launch_method;
-}
-
-EXPORT_API int emipc_get_launch_method()
-{
- EM_DEBUG_LOG("_launch_method[%d]", _launch_method);
- return _launch_method;
-}
-
-static void email_service_init(EmailService *email_service)
-{
- EM_DEBUG_LOG("email_service_init entered");
-}
-
-static void email_service_class_init(EmailServiceClass *email_service_class)
-{
- EM_DEBUG_LOG("email_service_class_init entered");
-
- dbus_g_object_type_install_info(EMAIL_SERVICE_TYPE, &dbus_glib_email_service_object_info);
-}
-
-gboolean daemon_launched = false;
-
-gboolean callback_for_timeout (void *arg)
-{
- if (!daemon_launched)
- EM_DEBUG_EXCEPTION ("org_tizen_email_service_launch is not responding");
- return FALSE;
-}
-
-EXPORT_API int emipc_launch_email_service()
-{
- EM_DEBUG_FUNC_BEGIN();
- int err = EMAIL_ERROR_NONE;
-
- DBusGConnection *connection = NULL;
- DBusGProxy *proxy = NULL;
- GError *error = NULL;
- guint dbus_result = 0;
-
- g_type_init();
-
- connection = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error);
- if (!connection) {
- if (error) {
- EM_DEBUG_EXCEPTION("Unable to connect to dbus: %s", error->message);
- g_error_free(error);
- err = EMAIL_ERROR_IPC_PROTOCOL_FAILURE;
- return err;
- }
- }
-
- proxy = dbus_g_proxy_new_for_name(connection, EMAIL_SERVICE_NAME, EMAIL_SERVICE_PATH, EMAIL_SERVICE_NAME);
- if (!proxy) {
- EM_DEBUG_EXCEPTION("dbus_g_proxy_new_for_name failed");
- err = EMAIL_ERROR_IPC_PROTOCOL_FAILURE;
- return err;
- }
-
- //will trigger activation if the service does not exist
- if (org_tizen_email_service_launch(proxy, &dbus_result, &error) == false) {
- if (error) {
- EM_DEBUG_EXCEPTION("email_service_launch failed : [%s]", error->message);
- g_error_free(error);
- err = EMAIL_ERROR_IPC_PROTOCOL_FAILURE;
- return err;
- }
- }
-
- EM_DEBUG_LOG("org_tizen_email_service_launch : [%d]", dbus_result);
-
- g_object_unref(proxy);
- EM_DEBUG_FUNC_END("ret [%d]", err);
- return err;
-}
-
-EXPORT_API int emipc_init_dbus_connection()
-{
- EM_DEBUG_FUNC_BEGIN();
-
- EmailService *object;
- DBusGProxy *proxy = NULL;
- DBusGConnection *connection = NULL;
- GError *error = NULL;
-
- guint request_ret = 0;
- int err = EMAIL_ERROR_NONE;
-
- g_type_init();
-
- //init dbus connection
- connection = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error);
- if (!connection) {
- if (error) {
- EM_DEBUG_EXCEPTION("Unable to connect to dbus: %s", error->message);
- g_error_free(error);
- err = EMAIL_ERROR_IPC_PROTOCOL_FAILURE;
- return err;
- }
- }
-
- //create email_service object
- object = g_object_new(EMAIL_SERVICE_TYPE, NULL);
-
- //register dbus path
- dbus_g_connection_register_g_object(connection, EMAIL_SERVICE_PATH, G_OBJECT(object));
-
- //register the service name
- proxy = dbus_g_proxy_new_for_name(connection, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS);
- if (!proxy) {
- EM_DEBUG_EXCEPTION("dbus_g_proxy_new_for_name failed");
- err = EMAIL_ERROR_IPC_PROTOCOL_FAILURE;
- return err;
- }
-
- if (!org_freedesktop_DBus_request_name(proxy, EMAIL_SERVICE_NAME, 0, &request_ret, &error)) {
- if (error) {
- EM_DEBUG_EXCEPTION("Unable to register service: %s", error->message);
- g_error_free(error);
- err = EMAIL_ERROR_IPC_PROTOCOL_FAILURE;
- }
- }
-
- g_object_unref(proxy);
-
- EM_DEBUG_FUNC_END("err [%d]", err);
- return err;
-}
-
-gboolean email_service_launch(EmailService *email_service, guint *result_val, GError **error)
-{
- EM_DEBUG_LOG("email_service_launch entered");
- EM_DEBUG_LOG("email_service_launch PID=[%ld]" , getpid());
- EM_DEBUG_LOG("email_service_launch TID=[%ld]" , pthread_self());
-
- if (result_val)
- *result_val = TRUE;
-
- return TRUE;
-}
+/* +* email-service +* +* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. +* +* Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +*/ + +#include <glib.h> +#include "email-types.h" +#include "email-debug-log.h" +#include "email-dbus-activation.h" +#include "email-utilities.h" +#include "email-core-account.h" +#include "email-core-utils.h" + +EXPORT_API int launch_pid = 0; +EXPORT_API const gchar introspection_xml[] = +"<node>" +" <interface name='org.tizen.email_service'>" +" <method name='Launch'>" +" <arg type='i' name='caller_pid' direction='in' />" +" <arg type='i' name='ret' direction='out' />" +" </method>" +" <method name='SetContactsLog'>" +" <arg type='i' name='account_id' direction='in'/>" +" <arg type='s' name='email_address' direction='in'/>" +" <arg type='s' name='subject' direction='in'/>" +" <arg type='i' name='date_time' direction='in'/>" +" <arg type='i' name='action' direction='in'/>" +" <arg type='i' name='err' direction='out'/>" +" </method>" +" <method name='DeleteContactsLog'>" +" <arg type='i' name='account_id' direction='in' />" +" <arg type='i' name='ret' direction='out' />" +" </method>" +" <method name='GetDisplayName'>" +" <arg type='s' name='email_address' direction='in' />" +" <arg type='s' name='contact_display_name' direction='out' />" +" <arg type='i' name='ret' direction='out' />" +" </method>" +" <method name='CheckBlockingMode'>" +" <arg type='s' name='sender_address' direction='in' />" +" <arg type='i' name='blocking_mode' direction='out' />" +" <arg type='i' name='ret' direction='out' />" +" </method>" +" <method name='QueryServerInfo'>" +" <arg type='i' name='pid' direction='in'/>" +" <arg type='s' name='domain_name' direction='in'/>" + /* err, email_server_info_t */ +" <arg type='(i((sii)a(iisiii)))' name='query_ret' direction='out'/>" +" </method>" +" </interface>" +"</node>"; + +static gboolean on_timer_proxy_new(gpointer userdata) +{ + EM_DEBUG_LOG("on_timer_proxy_new"); + GCancellable *proxy_cancel = (GCancellable *)userdata; + + if (proxy_cancel) { + if (!g_cancellable_is_cancelled (proxy_cancel)) + g_cancellable_cancel(proxy_cancel); + } + + return false; +} + +/* called from clients */ +EXPORT_API int emipc_launch_email_service() +{ + EM_DEBUG_LOG("emipc_launch_email_service"); + GError *gerror = NULL; + int ret = EMAIL_ERROR_NONE; + guint timer_tag = 0; + + g_type_init (); + + GCancellable *proxy_cancel = g_cancellable_new(); + timer_tag = g_timeout_add(5000, on_timer_proxy_new, proxy_cancel); + GDBusProxy* bproxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM, + G_DBUS_PROXY_FLAGS_NONE, + NULL, + EMAIL_SERVICE_NAME, + EMAIL_SERVICE_PATH, + EMAIL_SERVICE_NAME, + proxy_cancel, + &gerror); + + g_source_remove(timer_tag); + + if (!bproxy) { + EM_DEBUG_EXCEPTION ("g_dbus_proxy_new_for_bus_sync error [%s]", + gerror->message); + ret = EMAIL_ERROR_IPC_PROTOCOL_FAILURE; + goto FINISH_OFF; + } + + GVariant *result = g_dbus_proxy_call_sync (bproxy, + "Launch", + g_variant_new ("(i)", getpid()), + G_DBUS_CALL_FLAGS_NONE, + 5000, /* msec, 5s*/ + NULL, + &gerror); + + + if (!result) { + EM_DEBUG_EXCEPTION ("g_dbus_proxy_call_sync 'Launch' error [%s]", + gerror->message); + ret = EMAIL_ERROR_IPC_PROTOCOL_FAILURE; + goto FINISH_OFF; + } + + g_variant_get (result, "(&d)", &ret); + +FINISH_OFF: + EM_DEBUG_LOG ("ret [%d]\n", ret); + if (bproxy) + g_object_unref (bproxy); + + if (proxy_cancel) + g_object_unref(proxy_cancel); + + if (gerror) + g_error_free (gerror); + + return ret; +} + +void cancellable_connect_cb () +{ + EM_DEBUG_LOG ("Cancellable is now canceled"); +} + +EXPORT_API GCancellable *cancel = NULL; + + +GVariant* em_gdbus_get_display_name (GVariant *parameters) +{ + char *email_address = NULL; + char *contact_display_name = NULL; + g_variant_get (parameters, "(s)", &email_address); + + /* replace "" to NULL */ + if (!g_strcmp0(email_address,"")) + EM_SAFE_FREE (email_address); + + int err = emcore_get_mail_display_name_internal (email_address, &contact_display_name); + + /* make return_val */ + if (!contact_display_name) { + contact_display_name = strdup(""); + } + GVariant* ret = g_variant_new ("(si)", contact_display_name, err); + + /* clean-up */ + EM_SAFE_FREE (email_address); + EM_SAFE_FREE (contact_display_name); + + return ret; +} + +GVariant* em_gdbus_check_blocking_mode (GVariant *parameters) +{ + char *sender_address = NULL; + int blocking_mode = 0; + g_variant_get (parameters, "(s)", &sender_address); + + int err = emcore_check_blocking_mode_internal (sender_address, &blocking_mode); + + /* make return_val */ + GVariant* ret = g_variant_new ("(ii)", blocking_mode, err); + + /* clean-up string */ + EM_SAFE_FREE (sender_address); + + return ret; +} + diff --git a/email-ipc/email-activation/email-service.service b/email-ipc/email-activation/email-service.service index de17fe1..a41c9ca 100755 --- a/email-ipc/email-activation/email-service.service +++ b/email-ipc/email-activation/email-service.service @@ -1,4 +1,5 @@ [D-BUS Service] Name=org.tizen.email_service -Exec=/usr/bin/email-service +Exec=/bin/false +SystemdService=email-service.service User=root
\ No newline at end of file diff --git a/email-ipc/email-activation/include/email-dbus-activation.h b/email-ipc/email-activation/include/email-dbus-activation.h index 7e32541..82c16ea 100755 --- a/email-ipc/email-activation/include/email-dbus-activation.h +++ b/email-ipc/email-activation/include/email-dbus-activation.h @@ -22,46 +22,35 @@ #ifndef __EMAIL_DBUS_ACTIVATION_H__
#define __EMAIL_DBUS_ACTIVATION_H__
-/* standard library header */
-#include <glib-object.h>
-
-typedef struct _email_service_t EmailService;
-typedef struct _email_service_class_t EmailServiceClass;
+#include <gio/gio.h>
#define EMAIL_SERVICE_NAME "org.tizen.email_service"
#define EMAIL_SERVICE_PATH "/org/tizen/email_service"
-GType email_service_get_type(void);
-
-struct _email_service_t {
- GObject parent;
- int status;
-};
-
-struct _email_service_class_t {
- GObjectClass parent;
-};
-
-#define EMAIL_SERVICE_TYPE (email_service_get_type())
-#define EMAIL_SERVICE(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), EMAIL_SERVICE_TYPE, EmailService))
-#define EMAIL_SERVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), EMAIL_SERVICE_TYPE, EmailServiceClass))
-#define IS_EMAIL_SERVICE(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), EMAIL_SERVICE_TYPE))
-#define IS_EMAIL_SERVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), EMAIL_SERVICE_TYPE))
-#define EMAIL_SERVICE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), EMAIL_SERVICE_TYPE, EmailServiceClass))
-
-typedef enum {
- NFC_SERVICE_ERROR_INVALID_PRAM
-} email_servcie_error;
+/*
+note: it is not safe freeing the return-val
+*/
+#define EM_GDBUS_STR_NEW(str) (str? str:"")
+/* input string is released in case of dummy val */
+#define EM_GDBUS_STR_GET(str) \
+ ({\
+ char* ret;\
+ if (g_strcmp0(str, "")) {\
+ ret = str;\
+ }\
+ else {\
+ g_free(str);\
+ str = NULL;\
+ ret = NULL;\
+ }\
+ ret;\
+ })
-/**
- * launch the email-service
- */
-gboolean email_service_launch(EmailService *email_service, guint *result_val, GError **error);
-EXPORT_API int emipc_init_dbus_connection();
EXPORT_API int emipc_launch_email_service();
-
-EXPORT_API void emipc_set_launch_method(int input_launch_method);
-EXPORT_API int emipc_get_launch_method();
-
+EXPORT_API GVariant* em_gdbus_set_contact_log (GVariant *parameters);
+EXPORT_API GVariant* em_gdbus_delete_contact_log (GVariant *parameters);
+EXPORT_API GVariant* em_gdbus_get_display_name (GVariant *parameters);
+EXPORT_API GVariant* em_gdbus_check_blocking_mode (GVariant *parameters);
#endif /* __EMAIL_DBUS_ACTIVATION_H__ */
+
diff --git a/email-ipc/email-ipc-api/email-ipc-api-info.c b/email-ipc/email-ipc-api/email-ipc-api-info.c index bf8e263..76e1ee4 100755 --- a/email-ipc/email-ipc-api/email-ipc-api-info.c +++ b/email-ipc/email-ipc-api/email-ipc-api-info.c @@ -104,24 +104,13 @@ EXPORT_API void *emipc_get_parameters_of_api_info(emipc_email_api_info *api_info return api_info->params[direction]; } -EXPORT_API bool emipc_free_api_info(emipc_email_api_info *api_info) +EXPORT_API void emipc_free_api_info(emipc_email_api_info *api_info) { - if (!api_info) { - EM_DEBUG_EXCEPTION("Invalid parameter"); - return false; - } - - if (!emipc_destroy_param_list(api_info->params[ePARAMETER_IN])) { - EM_DEBUG_EXCEPTION("emipc_destroy_param_list failed : ePARAMETER[%d]", ePARAMETER_IN); - return false; - } - - if (!emipc_destroy_param_list(api_info->params[ePARAMETER_OUT])) { - EM_DEBUG_EXCEPTION("emipc_destroy_param_list failed : ePARAMETER[%d]", ePARAMETER_OUT); - return false; - } + if (!api_info) + return; - return true; + emipc_destroy_param_list (api_info->params[ePARAMETER_IN]); + emipc_destroy_param_list (api_info->params[ePARAMETER_OUT]); } diff --git a/email-ipc/email-ipc-api/email-ipc-param-list.c b/email-ipc/email-ipc-api/email-ipc-param-list.c index bfec354..aeb471e 100755 --- a/email-ipc/email-ipc-api/email-ipc-param-list.c +++ b/email-ipc/email-ipc-api/email-ipc-param-list.c @@ -50,21 +50,19 @@ EXPORT_API emipc_param_list *emipc_create_param_list() return new_param_list; } -EXPORT_API bool emipc_destroy_param_list(emipc_param_list *param_list) +EXPORT_API void emipc_destroy_param_list(emipc_param_list *param_list) { int count = 10; int index = 0; - if (!param_list) { - return false; - } + if (!param_list) + return; for (index = 0; index < count; index++) { emipc_free_param(param_list->params[index]); } EM_SAFE_FREE(param_list->byte_stream); EM_SAFE_FREE(param_list); - return true; } /* making stream into param length and param data */ diff --git a/email-ipc/email-ipc-api/include/email-ipc-api-info.h b/email-ipc/email-ipc-api/include/email-ipc-api-info.h index 35fcb66..d11ad64 100755 --- a/email-ipc/email-ipc-api/include/email-ipc-api-info.h +++ b/email-ipc/email-ipc-api/include/email-ipc-api-info.h @@ -45,7 +45,7 @@ EXPORT_API unsigned char *emipc_serialize_api_info(emipc_email_api_info *api_inf EXPORT_API void *emipc_get_parameters_of_api_info(emipc_email_api_info *api_info, EPARAMETER_DIRECTION direction); -EXPORT_API bool emipc_free_api_info(emipc_email_api_info *api_info); +EXPORT_API void emipc_free_api_info(emipc_email_api_info *api_info); /* don't insert empty line */ #define EM_APIID_TO_STR(nAPIID) \ @@ -71,6 +71,9 @@ EXPORT_API bool emipc_free_api_info(emipc_email_api_info *api_info); case _EMAIL_API_RENAME_MAILBOX:\ s = "_EMAIL_API_RENAME_MAILBOX";\ break;\ + case _EMAIL_API_RENAME_MAILBOX_EX:\ + s = "_EMAIL_API_RENAME_MAILBOX_EX";\ + break;\ case _EMAIL_API_SET_MAILBOX_TYPE:\ s = "_EMAIL_API_SET_MAILBOX_TYPE";\ break;\ @@ -191,9 +194,6 @@ EXPORT_API bool emipc_free_api_info(emipc_email_api_info *api_info); case _EMAIL_API_SEND_MAIL_CANCEL_JOB :\ s = "_EMAIL_API_SEND_MAIL_CANCEL_JOB";\ break;\ - case _EMAIL_API_SEARCH_MAIL_ON_SERVER :\ - s = "_EMAIL_API_SEARCH_MAIL_ON_SERVER";\ - break;\ case _EMAIL_API_ADD_ACCOUNT_WITH_VALIDATION :\ s = "_EMAIL_API_ADD_ACCOUNT_WITH_VALIDATION";\ break;\ @@ -209,6 +209,9 @@ EXPORT_API bool emipc_free_api_info(emipc_email_api_info *api_info); case _EMAIL_API_UPDATE_NOTIFICATION_BAR_FOR_UNREAD_MAIL :\ s = "_EMAIL_API_UPDATE_NOTIFICATION_BAR_FOR_UNREAD_MAIL";\ break;\ + case _EMAIL_API_CLEAR_NOTIFICATION_BAR :\ + s = "_EMAIL_API_CLEAR_NOTIFICATION_BAR";\ + break;\ case _EMAIL_API_GET_PASSWORD_LENGTH_OF_ACCOUNT:\ s = "_EMAIL_API_GET_PASSWORD_LENGTH_OF_ACCOUNT";\ break;\ diff --git a/email-ipc/email-ipc-api/include/email-ipc-param-list.h b/email-ipc/email-ipc-api/include/email-ipc-param-list.h index 4706596..e12c17b 100755 --- a/email-ipc/email-ipc-api/include/email-ipc-param-list.h +++ b/email-ipc/email-ipc-api/include/email-ipc-param-list.h @@ -43,7 +43,7 @@ typedef struct { EXPORT_API emipc_param_list *emipc_create_param_list(); -EXPORT_API bool emipc_destroy_param_list(emipc_param_list *param_list); +EXPORT_API void emipc_destroy_param_list(emipc_param_list *param_list); EXPORT_API bool emipc_parse_stream_of_param_list(emipc_param_list *param_list, void *stream_data); diff --git a/email-ipc/email-ipc-proxy.c b/email-ipc/email-ipc-proxy.c index ccc117f..b0c4342 100755 --- a/email-ipc/email-ipc-proxy.c +++ b/email-ipc/email-ipc-proxy.c @@ -33,6 +33,7 @@ #include "email-internal-types.h" #include "email-dbus-activation.h" #include "email-storage.h" +#include "email-core-task-manager.h" EXPORT_API int emipc_initialize_proxy () { @@ -56,6 +57,11 @@ EXPORT_API int emipc_finalize_proxy() return emipc_finalize_proxy_main(); } +#define ALLOW_TO_LAUNCH_DAEMON(api_id) \ + ((api_id) == _EMAIL_API_ADD_ACCOUNT ||\ + (api_id) == _EMAIL_API_VALIDATE_ACCOUNT_EX ||\ + (api_id) == _EMAIL_API_RESTORE_ACCOUNTS) + EXPORT_API int emipc_execute_proxy_api(HIPC_API api) { EM_DEBUG_FUNC_BEGIN(); @@ -70,26 +76,27 @@ EXPORT_API int emipc_execute_proxy_api(HIPC_API api) return EMAIL_ERROR_INVALID_PARAM; } - EM_DEBUG_LOG_SEC("Request: API_ID[%s] RES_ID[%d] APP_ID[%d]",\ - EM_APIID_TO_STR(api_info->api_id), api_info->response_id, api_info->app_id); + EM_DEBUG_LOG_SEC("Request: API_ID[%s][0x%x] RES_ID[%d] APP_ID[%d]",\ + EM_APIID_TO_STR(api_info->api_id), + api_info->api_id, + api_info->response_id, + api_info->app_id); ret = emipc_execute_api_of_proxy_main(api_info); /* connection retry */ if (!ret) { - EM_DEBUG_LOG("Connection retry"); - emipc_finalize_proxy(); - + emipc_end_proxy_socket(); + EM_DEBUG_LOG("Launch email-service daemon"); err = emipc_initialize_proxy(); if (err != EMAIL_ERROR_NONE) { - EM_DEBUG_EXCEPTION("Failed to open the socket : [%d]", err); - err = EMAIL_ERROR_CONNECTION_FAILURE; - goto FINISH_OFF; + EM_DEBUG_EXCEPTION ("emipc_initialize_proxy [%d]", err); + goto FINISH_OFF; } - ret = emipc_execute_api_of_proxy_main(api_info); - if (!ret) { - EM_DEBUG_EXCEPTION("emipc_execute_api_of_proxy_main failed [%d]", err); + err = emipc_execute_api_of_proxy_main(api_info); + if (!err) { + EM_DEBUG_EXCEPTION("emipc_execute_api_of_proxy_main error"); err = EMAIL_ERROR_CONNECTION_FAILURE; goto FINISH_OFF; } diff --git a/email-ipc/email-proxy/email-proxy-main.c b/email-ipc/email-proxy/email-proxy-main.c index af730a9..de0e048 100755 --- a/email-ipc/email-proxy/email-proxy-main.c +++ b/email-ipc/email-proxy/email-proxy-main.c @@ -36,6 +36,7 @@ EXPORT_API int emipc_initialize_proxy_main() { EM_DEBUG_FUNC_BEGIN(); + int err = EMAIL_ERROR_NONE; int sock_fd = 0; sock_fd = emipc_get_proxy_socket_id(); @@ -45,14 +46,17 @@ EXPORT_API int emipc_initialize_proxy_main() return EMAIL_ERROR_IPC_ALREADY_INITIALIZED; } - if (!emipc_start_proxy_socket()) { + if ((err = emipc_start_proxy_socket()) != EMAIL_ERROR_NONE) { EM_DEBUG_EXCEPTION("Socket start failed"); + if (err == EMAIL_ERROR_PERMISSION_DENIED) + return err; + return EMAIL_ERROR_IPC_CONNECTION_FAILURE; } EM_DEBUG_LOG("Socket ID : %d", emipc_get_proxy_socket_id()); EM_DEBUG_FUNC_END(); - return EMAIL_ERROR_NONE; + return err; } EXPORT_API int emipc_finalize_proxy_main() diff --git a/email-ipc/email-proxy/email-proxy-socket.c b/email-ipc/email-proxy/email-proxy-socket.c index 6d5fa5a..f9c2452 100644..100755 --- a/email-ipc/email-proxy/email-proxy-socket.c +++ b/email-ipc/email-proxy/email-proxy-socket.c @@ -46,7 +46,7 @@ typedef struct { GList *socket_head = NULL; pthread_mutex_t proxy_mutex = PTHREAD_MUTEX_INITIALIZER; -EXPORT_API bool emipc_start_proxy_socket() +EXPORT_API int emipc_start_proxy_socket() { EM_DEBUG_FUNC_BEGIN(); int ret = true; @@ -58,19 +58,10 @@ EXPORT_API bool emipc_start_proxy_socket() return false; } -#ifdef __FEATURE_ACCESS_CONTROL__ - int err = EMAIL_ERROR_NONE; - err = em_check_socket_privilege_by_pid(getpid()); - if (err == EMAIL_ERROR_PERMISSION_DENIED) { - EM_DEBUG_LOG("permission denied"); - return false; - } -#endif - ret = emipc_connect_email_socket(socket_fd); - if (!ret) { + if (ret != EMAIL_ERROR_NONE) { EM_DEBUG_EXCEPTION("emipc_connect_email_socket failed"); - return false; + return ret; } thread_socket_t* cur = (thread_socket_t*) em_malloc(sizeof(thread_socket_t)); @@ -104,15 +95,6 @@ EXPORT_API bool emipc_end_proxy_socket() /* close the socket of current thread */ if( tid == cur_socket->tid ) { -#ifdef __FEATURE_ACCESS_CONTROL__ - int err = EMAIL_ERROR_NONE; - err = em_check_socket_privilege_by_pid(cur_socket->pid); - if (err == EMAIL_ERROR_PERMISSION_DENIED) { - LEAVE_CRITICAL_SECTION(proxy_mutex); /*prevent 30968*/ - EM_DEBUG_LOG("permission denied"); - return false; - } -#endif emipc_close_email_socket(&cur_socket->socket_fd); EM_SAFE_FREE(cur_socket); GList *del = cur; @@ -142,16 +124,6 @@ EXPORT_API bool emipc_end_all_proxy_sockets() /* close all sockets of the pid */ if( pid == cur_socket->pid ) { -#ifdef __FEATURE_ACCESS_CONTROL__ - int err = EMAIL_ERROR_NONE; - err = em_check_socket_privilege_by_pid(cur_socket->pid); - if (err == EMAIL_ERROR_PERMISSION_DENIED) { - LEAVE_CRITICAL_SECTION(proxy_mutex); /*prevent 30967*/ - EM_DEBUG_LOG("permission denied"); - return false; - } -#endif - emipc_close_email_socket(&cur_socket->socket_fd); EM_SAFE_FREE(cur_socket); GList *del = cur; @@ -220,12 +192,11 @@ EXPORT_API int emipc_get_proxy_socket_id() */ static bool wait_for_reply (int fd) { - int return_from_select = -1; + int err = -1; fd_set fds; struct timeval tv; - char errno_buf[ERRNO_BUF_SIZE] = {0}; - if (fd == 0) { + if (fd < 0) { EM_DEBUG_EXCEPTION("Invalid file description : [%d]", fd); return false; } @@ -237,13 +208,13 @@ static bool wait_for_reply (int fd) tv.tv_usec = 0; EM_DEBUG_LOG_DEV ("wait for response [%d]", fd); - - if ((return_from_select = select(fd + 1, &fds, NULL, NULL, &tv)) == -1) { - EM_DEBUG_EXCEPTION("[IPCLib] select failed: %s", EM_STRERROR(errno_buf)); + err = select(fd + 1, &fds, NULL, NULL, &tv); + if (err == -1) { + EM_DEBUG_EXCEPTION("[IPCLib] select error[%d] fd[%d]", errno, fd); return false; } - else if (return_from_select == 0) { - EM_DEBUG_EXCEPTION("[IPCLib] select: timeout"); + else if (err == 0) { + EM_DEBUG_EXCEPTION("[IPCLib] select timeout fd[%d]", fd); return false; } diff --git a/email-ipc/email-proxy/include/email-proxy-socket.h b/email-ipc/email-proxy/include/email-proxy-socket.h index c89917e..83b49c1 100755 --- a/email-ipc/email-proxy/include/email-proxy-socket.h +++ b/email-ipc/email-proxy/include/email-proxy-socket.h @@ -26,7 +26,7 @@ #include "email-types.h" -EXPORT_API bool emipc_start_proxy_socket(); +EXPORT_API int emipc_start_proxy_socket(); EXPORT_API bool emipc_end_proxy_socket(); diff --git a/email-ipc/email-socket/email-ipc-socket.c b/email-ipc/email-socket/email-ipc-socket.c index cc494c8..610286f 100755 --- a/email-ipc/email-socket/email-ipc-socket.c +++ b/email-ipc/email-socket/email-ipc-socket.c @@ -38,6 +38,7 @@ #include <errno.h> #include <unistd.h> +#include <sys/smack.h> #include <systemd/sd-daemon.h> EXPORT_API bool emipc_init_email_socket(int *fd) @@ -45,7 +46,7 @@ EXPORT_API bool emipc_init_email_socket(int *fd) bool ret = true; char errno_buf[ERRNO_BUF_SIZE] = {0}; - *fd = socket(AF_UNIX, SOCK_STREAM, 0); + *fd = socket(AF_UNIX, SOCK_SEQPACKET, 0); if (*fd < 0) { EM_DEBUG_EXCEPTION("socket failed: %s", EM_STRERROR(errno_buf)); ret = false; @@ -60,8 +61,7 @@ EXPORT_API bool emipc_init_email_socket(int *fd) EXPORT_API void emipc_close_email_socket(int* fd) { EM_DEBUG_LOG("fd %d removal done", *fd); - close(*fd); - *fd = 0; + EM_SAFE_CLOSE (*fd); } /* returns positive write length, @@ -71,12 +71,11 @@ static int emipc_writen(int fd, const char *buf, int len) { int length = len; int passed_len = 0; - char errno_buf[ERRNO_BUF_SIZE] = {0}; while (length > 0) { passed_len = send(fd, (const void *)buf, length, MSG_NOSIGNAL); if (passed_len == -1) { - EM_DEBUG_LOG("write : %s", EM_STRERROR(errno_buf)); + EM_DEBUG_EXCEPTION ("send error [%d]", errno); if (errno == EINTR) continue; else if (errno == EPIPE) return 0; /* connection closed */ else return passed_len; /* -1 */ @@ -104,8 +103,9 @@ EXPORT_API int emipc_send_email_socket(int fd, unsigned char *buf, int len) EM_DEBUG_LOG("Sending %dB data to [fd = %d]", len, fd); int write_len = emipc_writen(fd, (char*) buf, len); - if ( write_len != len) { - if ( write_len == 0 ) return 0; + if (write_len == 0) /* connection closed */ + return 0; + if (write_len != len) { EM_DEBUG_LOG("WARNING: buf_size [%d] != write_len[%d]", len, write_len); return EMAIL_ERROR_IPC_SOCKET_FAILURE; } @@ -117,13 +117,13 @@ static int emipc_readn(int fd, char *buf, int len) { int length = len; int read_len = 0; - char errno_buf[ERRNO_BUF_SIZE] = {0}; while (length > 0) { read_len = read(fd, (void *)buf, length); if (read_len < 0) { - EM_DEBUG_EXCEPTION("Read : %s", EM_STRERROR(errno_buf)); + EM_DEBUG_EXCEPTION("read err %d", errno); if (errno == EINTR) continue; + else if (errno == EPIPE) return 0; /* connection closed */ return read_len; } else if (read_len == 0) break; @@ -169,6 +169,8 @@ EXPORT_API int emipc_recv_email_socket(int fd, char **buf) EM_DEBUG_LOG_DEV("[IPC Socket] Receiving [%d] bytes", read_len); int len = emipc_readn(fd, *buf, read_len); + if (len == 0) /* connection closed */ + return 0; if (read_len != len) { EM_SAFE_FREE(*buf); EM_DEBUG_LOG("WARNING: buf_size [%d] != read_len[%d]", read_len, len); @@ -212,8 +214,8 @@ EXPORT_API int emipc_open_email_socket(int fd, const char *path) if (strcmp(path, EM_SOCKET_PATH) == 0 && sd_listen_fds(1) == 1 && - sd_is_socket_unix(SD_LISTEN_FDS_START, SOCK_STREAM, -1, EM_SOCKET_PATH, 0) > 0) { - close(fd); + sd_is_socket_unix(SD_LISTEN_FDS_START, SOCK_SEQPACKET, -1, EM_SOCKET_PATH, 0) > 0) { + EM_SAFE_CLOSE (fd); sock_fd = SD_LISTEN_FDS_START + 0; return sock_fd; } @@ -258,6 +260,18 @@ EXPORT_API int emipc_open_email_socket(int fd, const char *path) return EMAIL_ERROR_IPC_SOCKET_FAILURE; } +#if 0 + if (smack_setlabel(path, "*", SMACK_LABEL_IPIN) != 0) { + EM_DEBUG_EXCEPTION("smack_setlabel error"); + return EMAIL_ERROR_SYSTEM_FAILURE; + } + + if (smack_setlabel(path, "@", SMACK_LABEL_IPOUT) != 0) { + EM_DEBUG_EXCEPTION("smack_setlabel error"); + return EMAIL_ERROR_SYSTEM_FAILURE; + } +#endif + if (listen(fd, 10) == -1) { EM_DEBUG_LOG("listen: %s", EM_STRERROR(errno_buf)); return EMAIL_ERROR_IPC_SOCKET_FAILURE; @@ -267,9 +281,11 @@ EXPORT_API int emipc_open_email_socket(int fd, const char *path) return fd; } -EXPORT_API bool emipc_connect_email_socket(int fd) +EXPORT_API int emipc_connect_email_socket(int fd) { EM_DEBUG_FUNC_BEGIN(); + int err = EMAIL_ERROR_NONE; + int p_errno = 0; struct sockaddr_un server; memset(&server, 0, sizeof(server)); server.sun_family = AF_UNIX; @@ -278,10 +294,17 @@ EXPORT_API bool emipc_connect_email_socket(int fd) if (connect(fd, (struct sockaddr *)&server, sizeof(server)) < 0) { EM_DEBUG_EXCEPTION ("connect failed: [%s][errno=%d][fd=%d]", EM_STRERROR(errno_buf), errno, fd); - return false; + + p_errno = errno; + if (p_errno == EACCES || p_errno == EPERM) + err = EMAIL_ERROR_PERMISSION_DENIED; + else + err = EMAIL_ERROR_SYSTEM_FAILURE; + + return err; } EM_DEBUG_FUNC_END(); - return true; + return err; } diff --git a/email-ipc/email-socket/include/email-ipc-socket.h b/email-ipc/email-socket/include/email-ipc-socket.h index 10bfff7..4cc5717 100755 --- a/email-ipc/email-socket/include/email-ipc-socket.h +++ b/email-ipc/email-socket/include/email-ipc-socket.h @@ -46,7 +46,7 @@ EXPORT_API int emipc_accept_email_socket(int fd); EXPORT_API int emipc_open_email_socket(int fd, const char *path); -EXPORT_API bool emipc_connect_email_socket(int fd); +EXPORT_API int emipc_connect_email_socket(int fd); #endif /* _IPC_SOCKET_H_ */ diff --git a/email-ipc/email-stub/email-stub-main.c b/email-ipc/email-stub/email-stub-main.c index 3a8027f..0cde0a5 100755 --- a/email-ipc/email-stub/email-stub-main.c +++ b/email-ipc/email-stub/email-stub-main.c @@ -53,8 +53,6 @@ EXPORT_API bool emipc_initialize_stub_main(PFN_EXECUTE_API fn_api_mapper) return false; } - emipc_init_dbus_connection(); - EM_DEBUG_FUNC_END(); return true; } @@ -95,8 +93,11 @@ EXPORT_API bool emipc_execute_api_stub_to_proxy(emipc_email_api_info *api_info) { EM_DEBUG_FUNC_BEGIN("api_info [%p]", api_info); EM_IF_NULL_RETURN_VALUE(api_info, false); - EM_DEBUG_LOG_SEC ("Response: API_ID [%s], RES_ID [%d], APP_ID [%d]",\ - EM_APIID_TO_STR(api_info->api_id), api_info->response_id, api_info->app_id); + EM_DEBUG_LOG_SEC ("Response: API_ID [%s][0x%x], RES_ID [%d], APP_ID [%d]",\ + EM_APIID_TO_STR(api_info->api_id), + api_info->api_id, + api_info->response_id, + api_info->app_id); unsigned char *stream = NULL; int stream_length = 0; diff --git a/email-ipc/email-stub/email-stub-socket.c b/email-ipc/email-stub/email-stub-socket.c index 9450d20..c59a129 100755 --- a/email-ipc/email-stub/email-stub-socket.c +++ b/email-ipc/email-stub/email-stub-socket.c @@ -26,6 +26,7 @@ #include <errno.h> #include <malloc.h> #include <sys/epoll.h> +#include <sys/socket.h> #include <pthread.h> #include "email-ipc-build.h" @@ -104,21 +105,11 @@ static void *emipc_stub_socket_thread_proc() return NULL; } -static int emipc_check_connected(int fd) -{ - EM_DEBUG_FUNC_BEGIN ("fd[%d]", fd); - int found = (g_list_find (connected_fd, (gpointer)fd))? true : false; - EM_DEBUG_FUNC_END ("fd found?? [%d]", found); - return found; -} - - EXPORT_API void emipc_wait_for_ipc_request() { struct epoll_event ev = {0}; int epfd = 0; int event_num = 0; - char errno_buf[ERRNO_BUF_SIZE] = {0}; struct epoll_event events[MAX_EPOLL_EVENT] = {{0}, }; if (!stub_socket) { @@ -130,8 +121,8 @@ EXPORT_API void emipc_wait_for_ipc_request() epfd = epoll_create(MAX_EPOLL_EVENT); if (epfd < 0) { - EM_DEBUG_EXCEPTION("epoll_ctl failed: %s[%d]", EM_STRERROR(errno_buf), errno); - EM_DEBUG_CRITICAL_EXCEPTION("epoll_create failed: %s[%d]", EM_STRERROR(errno_buf), errno); + EM_DEBUG_EXCEPTION("epoll_ctl error [%d]", errno); + EM_DEBUG_CRITICAL_EXCEPTION("epoll_create error [%d]", errno); return; } @@ -139,8 +130,8 @@ EXPORT_API void emipc_wait_for_ipc_request() ev.data.fd = stub_socket; if (epoll_ctl(epfd, EPOLL_CTL_ADD, stub_socket, &ev) == -1) { - EM_DEBUG_EXCEPTION("epoll_ctl failed: %s[%d]", EM_STRERROR(errno_buf), errno); - EM_DEBUG_CRITICAL_EXCEPTION("epoll_ctl failed:%s[%d]", EM_STRERROR(errno_buf), errno); + EM_DEBUG_EXCEPTION("epoll_ctl error [%d]", errno); + EM_DEBUG_CRITICAL_EXCEPTION("epoll_ctl error [%d]", errno); } while (!stop_thread) { int i = 0; @@ -153,26 +144,31 @@ EXPORT_API void emipc_wait_for_ipc_request() } if (event_num == -1) { - EM_DEBUG_EXCEPTION("epoll_wait failed: %s[%d]", EM_STRERROR(errno_buf), errno); - EM_DEBUG_CRITICAL_EXCEPTION("epoll_wait failed: %s[%d]", EM_STRERROR(errno_buf), errno); - } else { + if (errno != EINTR ) { + EM_DEBUG_EXCEPTION("epoll_wait error [%d]", errno); + EM_DEBUG_CRITICAL_EXCEPTION("epoll_wait error [%d]", errno); + } + } + else { for (i = 0; i < event_num; i++) { int event_fd = events[i].data.fd; if (event_fd == stub_socket) { /* if it is socket connection request */ int cfd = emipc_accept_email_socket (stub_socket); if (cfd < 0) { - EM_DEBUG_EXCEPTION ("emipc_accept_email_socket failed [%d]", cfd); + EM_DEBUG_EXCEPTION ("emipc_accept_email_socket error [%d]", cfd); /* EM_DEBUG_CRITICAL_EXCEPTION ("accept failed: %s[%d]", EM_STRERROR(errno_buf), errno);*/ + continue; } ev.events = EPOLLIN; ev.data.fd = cfd; if (epoll_ctl(epfd, EPOLL_CTL_ADD, cfd, &ev) == -1) { - EM_DEBUG_EXCEPTION("epoll_ctl failed [%s][%d]", EM_STRERROR(errno_buf), errno); + EM_DEBUG_EXCEPTION("epoll_ctl error [%d]", errno); /*EM_DEBUG_CRITICAL_EXCEPTION("epoll_ctl failed:%s[%d]", EM_STRERROR(errno_buf), errno);*/ + continue; } - connected_fd = g_list_prepend (connected_fd, (gpointer)cfd); - } else { + } + else { int recv_len; char *sz_buf = NULL; @@ -183,18 +179,37 @@ EXPORT_API void emipc_wait_for_ipc_request() /* IPC request stream is at least 16byte */ if (recv_len >= sizeof(long) * eSTREAM_DATA) { - emipc_create_task((unsigned char *)sz_buf, event_fd); - } else + int ret = 0; + ret = emipc_create_task((unsigned char *)sz_buf, event_fd); + if (ret == EMAIL_ERROR_PERMISSION_DENIED) { + if (epoll_ctl(epfd, EPOLL_CTL_DEL, event_fd, events) == -1) { + EM_DEBUG_EXCEPTION("epoll_ctl error [%d]", errno); + EM_DEBUG_CRITICAL_EXCEPTION("epoll_ctl error [%d]", errno); + } + EM_SAFE_CLOSE (event_fd); + } + } + else EM_DEBUG_LOG("[IPCLib] Stream size is less than default size"); - } else if( recv_len == 0 ) { + } + else if( recv_len == 0 ) { /* client shut down connection */ EM_DEBUG_LOG("[IPCLib] Client closed connection [%d]", event_fd); if (epoll_ctl(epfd, EPOLL_CTL_DEL, event_fd, events) == -1) { - EM_DEBUG_EXCEPTION("epoll_ctl failed: %s[%d]", EM_STRERROR(errno_buf), errno); - EM_DEBUG_CRITICAL_EXCEPTION("epoll_ctl failed: %s[%d]", EM_STRERROR(errno_buf), errno); + EM_DEBUG_EXCEPTION("epoll_ctl error [%d]", errno); + EM_DEBUG_CRITICAL_EXCEPTION("epoll_ctl error [%d]", errno); } - connected_fd = g_list_remove (connected_fd, (gpointer)event_fd); - close(event_fd); + emipc_close_fd_in_task_queue (event_fd); + EM_SAFE_CLOSE (event_fd); } + else { /* read errs */ + EM_DEBUG_EXCEPTION ("[IPCLib] read err[%d] fd[%d]", recv_len, event_fd); + if (epoll_ctl(epfd, EPOLL_CTL_DEL, event_fd, events) == -1) { + EM_DEBUG_EXCEPTION("epoll_ctl error [%d]", errno); + EM_DEBUG_CRITICAL_EXCEPTION("epoll_ctl error [%d]", errno); + } + emipc_close_fd_in_task_queue (event_fd); + EM_SAFE_CLOSE (event_fd); + } EM_SAFE_FREE(sz_buf); } } @@ -225,12 +240,12 @@ EXPORT_API int emipc_send_stub_socket(int sock_fd, void *data, int len) EM_DEBUG_FUNC_BEGIN("Stub socket sending %d bytes", len); int sending_bytes = 0; - if (emipc_check_connected(sock_fd)) { /* client may be shut down and the sock_fd can be reused by another module */ + if (sock_fd >= 0) { sending_bytes = emipc_send_email_socket(sock_fd, data, len); } - if (sending_bytes == 0) { - EM_DEBUG_LOG ("sending byte for fd [%d] is zero", sock_fd); + if (sending_bytes <= 0) { + EM_DEBUG_EXCEPTION ("emipc_send_email_socket error [%d] fd [%d]", sending_bytes, sock_fd); } EM_DEBUG_FUNC_END("sending_bytes = %d", sending_bytes); diff --git a/email-ipc/email-stub/email-stub-task-manager.c b/email-ipc/email-stub/email-stub-task-manager.c index 3774d2a..5b8185b 100755 --- a/email-ipc/email-stub/email-stub-task-manager.c +++ b/email-ipc/email-stub/email-stub-task-manager.c @@ -33,6 +33,7 @@ #include "email-debug-log.h" #include "email-api.h" #include "email-internal-types.h" +#include "email-utilities.h" static pthread_t task_thread = 0; static bool stop_flag = false; @@ -95,11 +96,16 @@ EXPORT_API void *emipc_do_task_thread() break; } - task = (emipc_email_task *)g_queue_pop_head(task_queue); + task = (emipc_email_task *)g_queue_peek_head(task_queue); LEAVE_CRITICAL_SECTION(ipc_task_mutex); if (task) { emipc_run_task(task); + + ENTER_CRITICAL_SECTION(ipc_task_mutex); + task = (emipc_email_task *)g_queue_pop_head(task_queue); + LEAVE_CRITICAL_SECTION(ipc_task_mutex); + emipc_free_email_task(task); EM_SAFE_FREE(task); } @@ -109,33 +115,63 @@ EXPORT_API void *emipc_do_task_thread() } /* code for ipc handler */ -EXPORT_API bool emipc_create_task(unsigned char *task_stream, int response_channel) +EXPORT_API int emipc_create_task(unsigned char *task_stream, int response_channel) { emipc_email_task *task = NULL; - bool ret = true; + int err = EMAIL_ERROR_NONE; task = (emipc_email_task *)malloc(sizeof(emipc_email_task)); if (task == NULL) { EM_DEBUG_EXCEPTION("Malloc failed."); - ret = false; + err = EMAIL_ERROR_OUT_OF_MEMORY; } else { if (!emipc_parse_stream_email_task(task, task_stream, response_channel)) { EM_DEBUG_EXCEPTION("emipc_parse_stream_email_task failed"); - return false; + emipc_free_email_task(task); + EM_SAFE_FREE(task); + return err; } EM_DEBUG_LOG_DEV ("[IPCLib] ======================================================"); - EM_DEBUG_LOG_SEC ("[IPCLib] Register new task: API_ID[%s][0x%x] RES_ID[%d] APP_ID[%d]", EM_APIID_TO_STR(task->api_info->api_id),\ - task->api_info->api_id,\ - task->api_info->response_id,\ - task->api_info->app_id); + EM_DEBUG_LOG_SEC ("[IPCLib] Register new task: API_ID[%s][0x%x] RES_ID[%d] APP_ID[%d]", + EM_APIID_TO_STR(task->api_info->api_id), + task->api_info->api_id, + task->api_info->response_id, + task->api_info->app_id); EM_DEBUG_LOG_DEV ("[IPCLib] ======================================================"); + /*check privilege*/ +#ifdef __FEATURE_ACCESS_CONTROL__ + err = em_check_db_privilege_by_pid(task->api_info->app_id); + if (err == EMAIL_ERROR_PERMISSION_DENIED) { + EM_DEBUG_LOG("permission denied"); + emipc_free_email_task(task); + EM_SAFE_FREE(task); + return err; + } +#endif + ENTER_CRITICAL_SECTION(ipc_task_mutex); g_queue_push_tail(task_queue, (void *)task); WAKE_CONDITION_VARIABLE(ipc_task_cond); LEAVE_CRITICAL_SECTION(ipc_task_mutex); } - return ret; + return err; +} + + +EXPORT_API void emipc_close_fd_in_task_queue (int fd) +{ + emipc_email_task *task = NULL; + int i = 0; + ENTER_CRITICAL_SECTION(ipc_task_mutex); + while ( (task = g_queue_peek_nth (task_queue, i++)) ) { + if (task->api_info->response_id == fd) { + task->api_info->response_id = -1; + } + } + LEAVE_CRITICAL_SECTION(ipc_task_mutex); } + + diff --git a/email-ipc/email-stub/email-stub-task.c b/email-ipc/email-stub/email-stub-task.c index 45937f4..f00f078 100755 --- a/email-ipc/email-stub/email-stub-task.c +++ b/email-ipc/email-stub/email-stub-task.c @@ -84,8 +84,8 @@ EXPORT_API bool emipc_run_task(emipc_email_task *task) int app_id = task->api_info->app_id; int res_id = task->api_info->response_id; - EM_DEBUG_LOG_SEC("[IPCLib] Processing task: API_ID[%s][0x%x] RES_ID[%d] APP_ID[%d] ", EM_APIID_TO_STR(api_id),\ - api_id, res_id, app_id); + EM_DEBUG_LOG_SEC("[IPCLib] Processing task: API_ID[%s][0x%x] RES_ID[%d] APP_ID[%d] ", + EM_APIID_TO_STR (api_id), api_id, res_id, app_id); if (!emipc_execute_api_proxy_to_stub(task->api_info)) { EM_DEBUG_EXCEPTION("emipc_execute_api_proxy_to_stub failed"); diff --git a/email-ipc/email-stub/include/email-stub-task-manager.h b/email-ipc/email-stub/include/email-stub-task-manager.h index 95c17df..b4a278d 100755 --- a/email-ipc/email-stub/include/email-stub-task-manager.h +++ b/email-ipc/email-stub/include/email-stub-task-manager.h @@ -35,7 +35,9 @@ EXPORT_API bool emipc_stop_task_thread(); EXPORT_API void *emipc_do_task_thread(); -EXPORT_API bool emipc_create_task(unsigned char *task_stream, int response_channel); +EXPORT_API int emipc_create_task(unsigned char *task_stream, int response_channel); + +EXPORT_API void emipc_close_fd_in_task_queue (int fd); #endif /* _IPC_TASK_MANAGER_H_ */ diff --git a/email-service.manifest b/email-service.manifest index 2830d9b..91b023b 100644..100755 --- a/email-service.manifest +++ b/email-service.manifest @@ -16,7 +16,6 @@ </request> <permit> <smack permit="system::use_internet" type="rwx"/> - <smack permit="webkit2-efl" type="rx"/> </permit> --> <request> diff --git a/email-service.pc.in b/email-service.pc.in index c4750ef..ce54513 100755 --- a/email-service.pc.in +++ b/email-service.pc.in @@ -1,9 +1,9 @@ prefix=/usr
-libdir=@LIB_INSTALL_DIR@
+libdir=${prefix}/lib
includedir=${prefix}/include
Name: email-service library
Description: email-service library 1.0
Version: $version
-Libs: -L${libdir} -lemail-storage -lemail-core -lemail-common-use -lemail-ipc -lemail-api -lemail-network -lemail-smime-api
+Libs: -L${libdir} -lemail-storage -lemail-core -lemail-common-use -lemail-ipc -lemail-api -lemail-network -lemail-smime-api
Cflags: -I${includedir}/email-service
diff --git a/email-service.rule b/email-service.rule index 9b45e1b..319e29b 100644 --- a/email-service.rule +++ b/email-service.rule @@ -1,25 +1,20 @@ -email-service email-service::db rw -email-service _ w -email-service system::share rwx -email-service msg-service w -email-service calender-service x -email-service deviced w -email-service system::use_internet w -email-service system::vconf arwxt -email-service system::vconf_inhouse rw -email-service system::vconf_setting r -email-service data-provider-master rw -email-service secure-storage::pkcs12 r -email-service data-provider-master::notification rw -email-service data-provider-master::badge rw -email-service device::app_logging w -email-service device::sys_logging w - -system::use_internet email-service rwx -system::share email-service rwx -webkit2-efl email-service rx - -com.samsung.quickpanel email-service rx -com.samsung.indicator email-service rwx -com.samsung.lockscreen email-service rx -com.samsung.dropbox pkgmgr::db rw +email-service email-service::db rw---- ------ +email-service system::use_internet -w---- ------ +email-service system::vconf rwxat- ------ +email-service system::vconf_inhouse rw---- ------ +email-service system::vconf_setting r----- ------ +email-service data-provider-master rw---- ------ +email-service secure-storage::pkcs12 r----- ------ +email-service security-server::api-privilege-by-pid -w---- ------ +system::use_internet email-service rwx--- ------ +system::share email-service rwx--- ------ +org.tizen.quickpanel email-service r-x--- ------ +org.tizen.indicator email-service rwx--- ------ +org.tizen.lockscreen email-service r-x--- ------ +org.tizen.app-selector email-service --x--- ------ +org.tizen.dropbox pkgmgr::db rw---- ------ +email-service deviced::display rw---- ------ +email-service connman rw---- ------ +email-service connman::set rw---- ------ +email-service connman::get rw---- ------ +email-service telephony_framework::api_ps_public rw---- ------ diff --git a/email-service_PG.h b/email-service_PG.h index f29981a..109b7cb 100755 --- a/email-service_PG.h +++ b/email-service_PG.h @@ -230,8 +230,7 @@ account->outgoing_server_user_name = strdup("tom@gmail.com"); account->sending_password = strdup("tioimi"); account->auto_resend_times = 3; account->incoming_server_requires_apop = 0; -account->flag1 = 2; -account->flag2 = 1; +account->incoming_server_authentication_method = 0; account->is_preset_account = 1; account->logo_icon_path = strdup("Logo Icon Path"); account->options.priority = 3; diff --git a/packaging/email-service.service b/packaging/email-service.service new file mode 100755 index 0000000..4c74dd1 --- /dev/null +++ b/packaging/email-service.service @@ -0,0 +1,13 @@ +[Unit] +Description=Email service +After=graphical.target + +[Service] +Type=dbus +BusName=org.tizen.email_service +ExecStart=/usr/bin/email-service +Restart=on-failure +SuccessExitStatus=0 44 + +[Install] +WantedBy=graphical.target diff --git a/packaging/email-service.spec b/packaging/email-service.spec index 8777128..533f210 100755 --- a/packaging/email-service.spec +++ b/packaging/email-service.spec @@ -1,39 +1,37 @@ Name: email-service Summary: E-mail Framework Middleware package -Version: 0.13.7 +Version: 0.15.6 Release: 1 Group: System/Libraries -License: Apache License, Version 2.0, BSD +License: Apache License, Version 2.0 Source0: %{name}-%{version}.tar.gz Source1: email.service +Source10: email-service.service Requires: connman -Requires: webkit2-efl +Requires: gmime Requires(post): /sbin/ldconfig Requires(post): systemd Requires(post): /usr/bin/sqlite3 Requires(post): /usr/bin/vconftool -Requires(post): libss-client -Requires(post): ss-server +Requires(post): contacts-service2 +Requires(post): msg-service Requires(preun): systemd Requires(postun): /sbin/ldconfig Requires(postun): systemd BuildRequires: cmake +BuildRequires: pkgconfig(gmime-2.6) BuildRequires: pkgconfig(glib-2.0) BuildRequires: pkgconfig(gthread-2.0) BuildRequires: pkgconfig(aul) BuildRequires: pkgconfig(vconf-internal-keys) BuildRequires: pkgconfig(vconf) BuildRequires: pkgconfig(dlog) -BuildRequires: pkgconfig(db-util) BuildRequires: pkgconfig(dbus-1) BuildRequires: pkgconfig(dbus-glib-1) BuildRequires: pkgconfig(contacts-service2) BuildRequires: pkgconfig(uw-imap-toolkit) -BuildRequires: pkgconfig(drm-client) BuildRequires: pkgconfig(openssl) BuildRequires: pkgconfig(alarm-service) -BuildRequires: pkgconfig(mm-player) -BuildRequires: pkgconfig(mm-session) BuildRequires: pkgconfig(secure-storage) BuildRequires: pkgconfig(notification) BuildRequires: pkgconfig(accounts-svc) @@ -41,20 +39,20 @@ BuildRequires: pkgconfig(libsystemd-daemon) BuildRequires: pkgconfig(capi-base-common) BuildRequires: pkgconfig(libcurl) BuildRequires: pkgconfig(libxml-2.0) -BuildRequires: pkgconfig(gconf-2.0) BuildRequires: pkgconfig(cert-svc) BuildRequires: pkgconfig(badge) BuildRequires: pkgconfig(feedback) BuildRequires: pkgconfig(capi-appfw-application) BuildRequires: pkgconfig(libwbxml2) BuildRequires: pkgconfig(msg-service) -BuildRequires: pkgconfig(pmapi) -BuildRequires: pkgconfig(libsmack) BuildRequires: pkgconfig(security-server) -BuildRequires: pkgconfig(deviced) BuildRequires: pkgconfig(icu-i18n) +BuildRequires: pkgconfig(storage) +BuildRequires: pkgconfig(capi-network-connection) +BuildRequires: pkgconfig(capi-system-device) -%description + +%description E-mail Framework Middleware Library/Binary package @@ -72,11 +70,24 @@ E-mail Framework Middleware Development package %build -export CFLAGS="${CFLAGS} -fPIC -Wall -g -fvisibility=hidden" +export CFLAGS="${CFLAGS} -fPIC -Wall -g -fvisibility=hidden -fdata-sections -ffunction-sections" export CXXFLAGS="${CXXFLAGS} -fPIC -Wall -g -fvisibility=hidden" -export LDFLAGS="${LDFLAGS} -Wl,--hash-style=both -Wl,--rpath=%{_libdir} -Wl,--as-needed" +export LDFLAGS="${LDFLAGS} -Wl,--hash-style=both -Wl,--rpath=%{_prefix}/lib -Wl,--as-needed" + + +#%if 0%{?tizen_build_binary_release_type_eng} +#export CFLAGS="$CFLAGS -DTIZEN_ENGINEER_MODE" +#export CXXFLAGS="$CXXFLAGS -DTIZEN_ENGINEER_MODE" +#export FFLAGS="$FFLAGS -DTIZEN_ENGINEER_MODE" +#%endif + +%if 0%{?sec_build_binary_debug_enable} +export CFLAGS="$CFLAGS -DTIZEN_DEBUG_ENABLE" +export CXXFLAGS="$CXXFLAGS -DTIZEN_DEBUG_ENABLE" +export FFLAGS="$FFLAGS -DTIZEN_DEBUG_ENABLE" +%endif -%cmake . +cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} \ make %{?_smp_mflags} @@ -84,9 +95,12 @@ make %{?_smp_mflags} mkdir -p %{buildroot}/usr/share/license %make_install -mkdir -p %{buildroot}/usr/lib/systemd/user/tizen-middleware.target.wants -install -m 0644 %SOURCE1 %{buildroot}/usr/lib/systemd/user/ -ln -sf ../email.service %{buildroot}/usr/lib/systemd/user/tizen-middleware.target.wants/ +mkdir -p %{buildroot}%{_libdir}/systemd/user/tizen-middleware.target.wants +mkdir -p %{buildroot}%{_libdir}/systemd/system/graphical.target.wants +install -m 0644 %SOURCE1 %{buildroot}%{_libdir}/systemd/user/ +install -D -m 0644 %{SOURCE10} %{buildroot}%{_libdir}/systemd/system/ +ln -sf ../email.service %{buildroot}%{_libdir}/systemd/user/tizen-middleware.target.wants/ +ln -sf ../email-service.service %{buildroot}%{_libdir}/systemd/system/graphical.target.wants/ %post @@ -100,40 +114,40 @@ echo "[EMAIL-SERVICE] Start adding preset account information..." ################################################################################################ # for active sync -vconftool set -t int db/email_handle/active_sync_handle "0" -g 6514 -s "email::vconf_active_sync_handle" +vconftool set -t int db/email_handle/active_sync_handle "0" -g 5000 -s "email::vconf_active_sync_handle" # for default mail slot szie -vconftool set -t int db/private/email-service/slot_size "100" -g 6514 -s "email::vconf_slot_size" +vconftool set -t int db/private/email-service/slot_size "100" -g 5000 -s "email::vconf_slot_size" # for latest mail id -vconftool set -t int db/private/email-service/latest_mail_id "0" -g 6514 -s "email::vconf_latest_mail_id" +vconftool set -t int db/private/email-service/latest_mail_id "0" -g 5000 -s "email::vconf_latest_mail_id" # for default account id -vconftool set -t int db/private/email-service/default_account_id "0" -g 6514 -s "email::vconf_default_account_id" +vconftool set -t int db/private/email-service/default_account_id "0" -g 5000 -s "email::vconf_default_account_id" # for default account id -vconftool set -t int memory/sync/email "0" -i -g 6514 -s "email::vconf_sync_status" +vconftool set -t int memory/sync/email "0" -i -g 5000 -s "email::vconf_sync_status" # for priority send -vconftool set -t string db/private/email-service/noti_ringtone_path "/opt/usr/share/settings/Alerts/Over the horizon.mp3" -g 6514 -s "email::vconf_ringtone_path" -vconftool set -t int db/private/email-service/noti_rep_type "0" -g 6514 -s "email::vconf_rep_type" -vconftool set -t bool db/private/email-service/noti_notification_ticker "0" -g 6514 -s "email::vconf_notification" -vconftool set -t bool db/private/email-service/noti_display_content_ticker "0" -g 6514 -s "email::vconf_display_content" -vconftool set -t bool db/private/email-service/noti_badge_ticker "0" -i -g 6514 -s "system::vconf_system" -vconftool set -t int db/private/email-service/noti_private_id/1 "0" -i -g 6514 -vconftool set -t int db/private/email-service/noti_private_id/2 "0" -i -g 6514 -vconftool set -t int db/private/email-service/noti_private_id/3 "0" -i -g 6514 -vconftool set -t int db/private/email-service/noti_private_id/4 "0" -i -g 6514 -vconftool set -t int db/private/email-service/noti_private_id/5 "0" -i -g 6514 -vconftool set -t int db/private/email-service/noti_private_id/6 "0" -i -g 6514 -vconftool set -t int db/private/email-service/noti_private_id/7 "0" -i -g 6514 -vconftool set -t int db/private/email-service/noti_private_id/8 "0" -i -g 6514 -vconftool set -t int db/private/email-service/noti_private_id/9 "0" -i -g 6514 -vconftool set -t int db/private/email-service/noti_private_id/10 "0" -i -g 6514 -vconftool set -t bool db/private/email-service/noti_vibration_status "0" -g 6514 -s "email::vconf_vibration" -vconftool set -t bool db/private/email-service/noti_vip_vibration_status "0" -g 6514 -s "email::vconf_vip_vibration" -vconftool set -t bool db/private/email-service/noti_use_default_ringtone "1" -g 6514 -s "email::vconf_use_default_ringtone" -vconftool set -t bool db/private/email-service/noti_vip_use_default_ringtone "1" -g 6514 -s "email::vconf_vip_use_default_ringtone" +vconftool set -t string db/private/email-service/noti_ringtone_path "/opt/usr/share/settings/Alerts/Over the horizon.mp3" -g 5000 -s "email::vconf_ringtone_path" +vconftool set -t int db/private/email-service/noti_rep_type "0" -g 5000 -s "email::vconf_rep_type" +vconftool set -t bool db/private/email-service/noti_notification_ticker "0" -g 5000 -s "email::vconf_notification" +vconftool set -t bool db/private/email-service/noti_display_content_ticker "0" -g 5000 -s "email::vconf_display_content" +vconftool set -t bool db/private/email-service/noti_badge_ticker "0" -i -g 5000 -s "email::vconf_badge" +vconftool set -t int db/private/email-service/noti_private_id/1 "0" -i -g 5000 -s "email-service" +vconftool set -t int db/private/email-service/noti_private_id/2 "0" -i -g 5000 -s "email-service" +vconftool set -t int db/private/email-service/noti_private_id/3 "0" -i -g 5000 -s "email-service" +vconftool set -t int db/private/email-service/noti_private_id/4 "0" -i -g 5000 -s "email-service" +vconftool set -t int db/private/email-service/noti_private_id/5 "0" -i -g 5000 -s "email-service" +vconftool set -t int db/private/email-service/noti_private_id/6 "0" -i -g 5000 -s "email-service" +vconftool set -t int db/private/email-service/noti_private_id/7 "0" -i -g 5000 -s "email-service" +vconftool set -t int db/private/email-service/noti_private_id/8 "0" -i -g 5000 -s "email-service" +vconftool set -t int db/private/email-service/noti_private_id/9 "0" -i -g 5000 -s "email-service" +vconftool set -t int db/private/email-service/noti_private_id/10 "0" -i -g 5000 -s "email-service" +vconftool set -t bool db/private/email-service/noti_vibration_status "0" -g 5000 -s "email::vconf_vibration" +vconftool set -t bool db/private/email-service/noti_vip_vibration_status "0" -g 5000 -s "email::vconf_vip_vibration" +vconftool set -t bool db/private/email-service/noti_use_default_ringtone "1" -g 5000 -s "email::vconf_use_default_ringtone" +vconftool set -t bool db/private/email-service/noti_vip_use_default_ringtone "1" -g 5000 -s "email::vconf_vip_use_default_ringtone" ################################################################# @@ -141,9 +155,8 @@ vconftool set -t bool db/private/email-service/noti_vip_use_default_ringtone " ################################################################# 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 'PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin' >> ${EMAIL_SERVICE_EXEC_SCRIPT} echo 'account_count=$(sqlite3 /opt/usr/dbspace/.email-service.db "select COUNT(*) from mail_account_tbl")' >> ${EMAIL_SERVICE_EXEC_SCRIPT} echo 'if [ "$(echo "$account_count" | cut -c0-1)" == "0" ]' >> ${EMAIL_SERVICE_EXEC_SCRIPT} echo 'then' >> ${EMAIL_SERVICE_EXEC_SCRIPT} @@ -155,10 +168,6 @@ echo 'else' >> ${EMAIL_SERVICE_EXEC_SCRIPT} echo ' /usr/bin/email-service & ' >> ${EMAIL_SERVICE_EXEC_SCRIPT} echo 'fi' >> ${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 ..." ################################################################# @@ -169,24 +178,24 @@ mkdir -p /opt/usr mkdir -p /opt/usr/dbspace sqlite3 /opt/usr/dbspace/.email-service.db 'PRAGMA journal_mode = PERSIST;' -sqlite3 /opt/usr/dbspace/.email-service.db < /opt/usr/data/email/res/email-service.sql +sqlite3 /opt/usr/dbspace/.email-service.db < /usr/share/email-service/email-service.sql echo "[EMAIL-SERVICE] Finish Creating Email Tables." -chgrp 6006 /opt/usr/dbspace/.email-service.db* +chgrp 5000 /opt/usr/dbspace/.email-service.db* chmod 664 /opt/usr/dbspace/.email-service.db chmod 664 /opt/usr/dbspace/.email-service.db-journal mkdir -m775 -p /opt/usr/data/email/.email_data -chgrp 6006 /opt/usr/data/email/.email_data +chgrp 5000 /opt/usr/data/email/.email_data chsmack -a 'email-service' /opt/usr/data/email/.email_data mkdir -m775 -p /opt/usr/data/email/.email_data/tmp -chgrp 6006 /opt/usr/data/email/.email_data/tmp +chgrp 5000 /opt/usr/data/email/.email_data/tmp chsmack -a 'email-service' /opt/usr/data/email/.email_data/tmp mkdir -p /opt/share/cert-svc/certs/trusteduser/email -chgrp 6006 /opt/share/cert-svc/certs/trusteduser/email +chgrp 5000 /opt/share/cert-svc/certs/trusteduser/email if [ -f /opt/usr/dbspace/.email-service.db ] then @@ -208,18 +217,20 @@ fi systemctl daemon-reload -%files +%files %manifest email-service.manifest -%exclude /usr/bin/email-test-app +%{_bindir}/email-test-app %{_bindir}/email-service -/opt/usr/data/email/res/* +/usr/share/email-service/* %{_libdir}/lib*.so.* -/usr/lib/systemd/user/email.service -/usr/lib/systemd/user/tizen-middleware.target.wants/email.service +%{_libdir}/systemd/user/email.service +%{_libdir}/systemd/user/tizen-middleware.target.wants/email.service +%{_libdir}/systemd/system/email-service.service +%{_libdir}/systemd/system/graphical.target.wants/email-service.service /usr/share/dbus-1/services/email-service.service /usr/share/license/email-service -/opt/etc/smack/accesses.d/email-service.rule +/etc/smack/accesses.d/email-service.rule %files devel %{_includedir}/email-service/*.h diff --git a/packaging/email.service b/packaging/email.service index 30f64ec..f12277f 100644 --- a/packaging/email.service +++ b/packaging/email.service @@ -1,12 +1,13 @@ + [Unit] Description=Start the Email service [Service] ExecStart=/usr/bin/email-service Nice=5 -EnvironmentFile=/run/tizen-mobile-ui OOMScoreAdjust=100 -Restart=always +MemoryLimit=30M [Install] WantedBy=tizen-middleware.target +EnvironmentFile=/run/tizen-mobile-ui diff --git a/res/Q02_Notification_email.png b/res/Q02_Notification_email.png Binary files differdeleted file mode 100755 index f2c4701..0000000 --- a/res/Q02_Notification_email.png +++ /dev/null diff --git a/res/email-service.sql b/res/email-service.sql index ff46c40..1d7f8d1 100755 --- a/res/email-service.sql +++ b/res/email-service.sql @@ -10,6 +10,7 @@ CREATE TABLE mail_account_tbl sync_disabled INTEGER, default_mail_slot_size INTEGER, roaming_option INTEGER, + color_label INTEGER, user_display_name VARCHAR(31), user_email_address VARCHAR(129), reply_to_address VARCHAR(129), @@ -53,12 +54,18 @@ CREATE TABLE mail_account_tbl add_my_address_to_bcc INTEGER, auto_resend_times INTEGER, outgoing_server_size_limit INTEGER, + wifi_auto_download INTEGER, pop_before_smtp INTEGER, incoming_server_requires_apop INTEGER, smime_type INTEGER, certificate_path VARCHAR(256), cipher_type INTEGER, - digest_type INTEGER + digest_type INTEGER, + notification_status INTEGER, + vibrate_status INTEGER, + display_content_status INTEGER, + default_ringtone_status INTEGER, + alert_ringtone_path VARCHAR(256) ); CREATE TABLE mail_box_tbl ( @@ -123,8 +130,8 @@ CREATE TABLE mail_tbl full_address_cc TEXT, full_address_bcc TEXT, full_address_return TEXT, - email_address_sender TEXT collation user1, - email_address_recipient TEXT collation user1, + email_address_sender TEXT, + email_address_recipient TEXT, alias_sender TEXT, alias_recipient TEXT, body_download_status INTEGER, @@ -158,6 +165,7 @@ CREATE TABLE mail_tbl tag_id INTEGER, replied_time DATETIME, forwarded_time DATETIME, + default_charset VARCHAR(257), eas_data_length INTEGER, eas_data BLOB, FOREIGN KEY(account_id) REFERENCES mail_account_tbl(account_id) @@ -167,6 +175,7 @@ CREATE TABLE mail_attachment_tbl attachment_id INTEGER PRIMARY KEY, attachment_name VARCHAR(257), attachment_path VARCHAR(257), + content_id VARCHAR(257), attachment_size INTEGER, mail_id INTEGER, account_id INTEGER, @@ -247,6 +256,15 @@ CREATE VIRTUAL TABLE mail_text_tbl USING fts4 mailbox_id INTEGER, body_text TEXT ); +CREATE TABLE mail_auto_download_activity_tbl +( + activity_id INTEGER PRIMARY KEY, + status INTEGER, + account_id INTEGER, + mail_id INTEGER, + server_mail_id INTEGER, + mailbox_id INTEGER +); CREATE UNIQUE INDEX mail_account_idx1 ON mail_account_tbl (account_id); CREATE UNIQUE INDEX mail_box_idx1 ON mail_box_tbl (mailbox_id); CREATE UNIQUE INDEX mail_read_mail_uid_idx1 ON mail_read_mail_uid_tbl (account_id, mailbox_id, local_uid, mailbox_name, server_uid); @@ -264,3 +282,7 @@ CREATE TRIGGER update_flags_flagged_field UPDATE OF flags_flagged_field ON mail_ BEGIN UPDATE mail_read_mail_uid_tbl SET flags_flagged_field = new.flags_flagged_field WHERE local_uid = old.mail_id; END; +CREATE TRIGGER update_mailbox_id_field UPDATE OF mailbox_id ON mail_tbl + BEGIN + UPDATE mail_auto_download_activity_tbl SET mailbox_id = new.mailbox_id WHERE mail_id = old.mail_id; + END; diff --git a/res/noti_email_delivery_report.png b/res/noti_email_delivery_report.png Binary files differnew file mode 100755 index 0000000..bce75dd --- /dev/null +++ b/res/noti_email_delivery_report.png diff --git a/res/noti_email_read_report.png b/res/noti_email_read_report.png Binary files differnew file mode 100755 index 0000000..7c48be0 --- /dev/null +++ b/res/noti_email_read_report.png diff --git a/res/noti_email_scheduled.png b/res/noti_email_scheduled.png Binary files differnew file mode 100755 index 0000000..4bb4570 --- /dev/null +++ b/res/noti_email_scheduled.png diff --git a/res/noti_multi_email.png b/res/noti_multi_email.png Binary files differnew file mode 100755 index 0000000..c90f373 --- /dev/null +++ b/res/noti_multi_email.png diff --git a/res/noti_single_email.png b/res/noti_single_email.png Binary files differnew file mode 100755 index 0000000..4259c38 --- /dev/null +++ b/res/noti_single_email.png diff --git a/res/noti_single_indicator_email.png b/res/noti_single_indicator_email.png Binary files differnew file mode 100755 index 0000000..e5bb114 --- /dev/null +++ b/res/noti_single_indicator_email.png diff --git a/systemd/email.service b/systemd/email.service deleted file mode 100644 index 5c5ecab..0000000 --- a/systemd/email.service +++ /dev/null @@ -1,14 +0,0 @@ - -[Unit] -Description=Start the Email service - -[Service] -Type=notify -ExecStart=/usr/bin/email-service -Nice=5 -OOMScoreAdjust=100 -Restart=always - -[Install] -WantedBy=tizen-middleware.target - diff --git a/systemd/email.socket b/systemd/email.socket deleted file mode 100644 index a1d9920..0000000 --- a/systemd/email.socket +++ /dev/null @@ -1,7 +0,0 @@ -[Socket] -ListenStream=/tmp/.emailfw_socket -SocketMode=0777 - -[Install] -WantedBy=sockets.target - diff --git a/utilities/CMakeLists.txt b/utilities/CMakeLists.txt index 2a04870..3ab5c74 100755 --- a/utilities/CMakeLists.txt +++ b/utilities/CMakeLists.txt @@ -13,6 +13,7 @@ MESSAGE(">>> Build type: ${CMAKE_BUILD_TYPE}") SET(VISIBILITY "-DEXPORT_API=\"__attribute__((visibility(\\\"default\\\")))\"") SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${VISIBILITY} -fvisibility=hidden") +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wl,--gc-sections") ########################################################## # Define Test App @@ -28,6 +29,7 @@ SET(TEST-APP-SRCS ${CMAKE_SOURCE_DIR}/utilities/test-application/testapp-rule.c ${CMAKE_SOURCE_DIR}/utilities/test-application/testapp-thread.c ${CMAKE_SOURCE_DIR}/utilities/test-application/testapp-others.c +# ${CMAKE_SOURCE_DIR}/utilities/test-application/testapp-gmime.c ) INCLUDE_DIRECTORIES( @@ -40,7 +42,7 @@ INCLUDE_DIRECTORIES( ) INCLUDE(FindPkgConfig) -pkg_check_modules(test_app_pkgs REQUIRED glib-2.0 gthread-2.0 vconf db-util uw-imap-toolkit contacts-service2 drm-client pmapi) +pkg_check_modules(test_app_pkgs REQUIRED glib-2.0 gthread-2.0 vconf uw-imap-toolkit contacts-service2) FOREACH(flag ${test_app_pkgs_CFLAGS}) SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") diff --git a/utilities/test-application/include/testapp-gmime.h b/utilities/test-application/include/testapp-gmime.h new file mode 100755 index 0000000..0aeafee --- /dev/null +++ b/utilities/test-application/include/testapp-gmime.h @@ -0,0 +1,31 @@ +/* +* email-service +* +* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. +* +* Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +*/ + + + +#ifndef EMAIL_TEST_GMIME_H +#define EMAIL_TEST_GMIME_H + +/* export API */ +void testapp_gmime_main(void); + +#endif + diff --git a/utilities/test-application/main.c b/utilities/test-application/main.c index 27cbfdd..de02f6b 100755 --- a/utilities/test-application/main.c +++ b/utilities/test-application/main.c @@ -44,7 +44,6 @@ #ifdef __FEATURE_USE_GMIME__ #include "testapp-gmime.h" #endif /* __FEATURE_USE_GMIME__ */ -#include "db-util.h" /* function prototype */ static void testapp_system_signal_handler (int signal_number); @@ -184,19 +183,17 @@ int main (int argc, char *argv[]) { gboolean go_to_loop = TRUE; int menu_number = 0; - int result_from_scanf = 0; if ( testapp_initialize_testing() == FALSE ) { - testapp_print ("email-serivce is not ready\n"); + testapp_print ("email-service is not ready\n"); exit(0); } while (go_to_loop) { testapp_show_menu (EMAIL_MAIN_MENU); testapp_show_prompt (EMAIL_MAIN_MENU); - - result_from_scanf = scanf ("%d", &menu_number); - + if (0 >= scanf ("%d", &menu_number)) + testapp_print("Invalid input"); go_to_loop = testapp_interpret_command (menu_number); } diff --git a/utilities/test-application/testapp-account.c b/utilities/test-application/testapp-account.c index c1b121b..1cc5d1f 100755 --- a/utilities/test-application/testapp-account.c +++ b/utilities/test-application/testapp-account.c @@ -63,7 +63,6 @@ gboolean testapp_create_account_object(email_account_t **result_account) char id_string[100] = { 0, }, password_string[1000] = { 0, }, address_string[100] = { 0, }; char accesss_token[1000] = { 0, }, refresh_token[1000] = { 0, }; int samsung3g_account_index; - int result_from_scanf = 0; int account_type; testapp_print("1. Gawab\n"); @@ -83,14 +82,17 @@ gboolean testapp_create_account_object(email_account_t **result_account) testapp_print("16. mopera\n"); testapp_print("Choose server type: "); - result_from_scanf = scanf("%d",&account_type); + + if (0 >= scanf("%d",&account_type)) + testapp_print("Invalid input. "); switch(account_type) { case 4 : case 5 : do { testapp_print("Enter your account index [1~10] : "); - result_from_scanf = scanf("%d",&samsung3g_account_index); + if (0 >= scanf("%d",&samsung3g_account_index)) + testapp_print("Invalid input. "); }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); @@ -98,26 +100,32 @@ gboolean testapp_create_account_object(email_account_t **result_account) break; case 14 : testapp_print("Enter email address : "); - result_from_scanf = scanf("%s", address_string); + if (0 >= scanf("%s", address_string)) + testapp_print("Invalid input. "); strcpy(id_string, address_string); testapp_print("Enter access token : "); - result_from_scanf = scanf("%s", accesss_token); + if (0 >= scanf("%s", accesss_token)) + testapp_print("Invalid input. "); testapp_print("Enter refresh token : "); - result_from_scanf = scanf("%s", refresh_token); + if (0 >= scanf("%s", refresh_token)) + testapp_print("Invalid input. "); snprintf(password_string, 100, "%s\001%s\001", accesss_token, refresh_token); break; default: testapp_print("Enter email address : "); - result_from_scanf = scanf("%s", address_string); + if (0 >= scanf("%s", address_string)) + testapp_print("Invalid input. "); testapp_print("Enter id : "); - result_from_scanf = scanf("%s", id_string); + if (0 >= scanf("%s", id_string)) + testapp_print("Invalid input. "); testapp_print("Enter password_string : "); - result_from_scanf = scanf("%s", password_string); + if (0 >= scanf("%s", password_string)) + testapp_print("Invalid input. "); break; } @@ -144,6 +152,7 @@ gboolean testapp_create_account_object(email_account_t **result_account) account->incoming_server_requires_apop = 0; account->incoming_server_authentication_method = 0; account->logo_icon_path = NULL; + account->color_label = (128 << 16) | (128 << 8) | (128); account->user_data = malloc (data_length); memcpy( account->user_data, (void*) &data, data_length ); account->user_data_length = data_length; @@ -390,19 +399,18 @@ static gboolean testapp_test_add_account_with_validation() static gboolean testapp_test_update_account() { - int result_from_scanf = 0; int account_id; email_account_t *account = NULL; - char account_name[256]; + //char account_name[256]; int err = EMAIL_ERROR_NONE; - char signature[100] = {0}; - char user_email_address[256] = {0,}; - int add_my_address_to_bcc = 0; - int account_svc_id = 0, with_validation = 0; - + //char signature[100] = {0}; + //char user_email_address[256] = {0,}; + //int add_my_address_to_bcc = 0; + int with_validation = 0; //account_svc_id = 0, - testapp_print("\n>> Enter Account No: "); - result_from_scanf = scanf("%d",&account_id); + testapp_print("\n>> Enter Account ID: "); + if (0 >= scanf("%d",&account_id)) + testapp_print("Invalid input. "); if( (err = email_get_account(account_id, GET_FULL_DATA,&account)) != EMAIL_ERROR_NONE) { testapp_print ("email_get_account failed - %d\n", err); @@ -410,54 +418,56 @@ static gboolean testapp_test_update_account() } testapp_print ("email_get_account result account_name - %s \n", account->account_name); + testapp_print ("email_get_account result address - %s \n", account->user_email_address); 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:"); - result_from_scanf = scanf("%s",account_name); - - testapp_print("\n Enter new email addr:"); - result_from_scanf = scanf("%s",user_email_address); -#ifdef __FEATURE_AUTO_POLLING__ testapp_print("\n Enter new check interval (in mins):"); - result_from_scanf = scanf("%d",&(account->check_interval)); - + if (0 >= scanf("%d",&(account->check_interval))) + testapp_print("Invalid input. "); +/* testapp_print("\n Enter new peak interval (in mins):"); - result_from_scanf = scanf("%d",&(account->peak_interval)); + if (0 >= scanf("%d",&(account->peak_interval)); testapp_print("\n Enter new peak days:"); - result_from_scanf = scanf("%d",&(account->peak_days)); + if (0 >= scanf("%d",&(account->peak_days)); testapp_print("\n Enter new peak start time:"); - result_from_scanf = scanf("%d",&(account->peak_start_time)); + if (0 >= scanf("%d",&(account->peak_start_time)); testapp_print("\n Enter new peak end time:"); - result_from_scanf = scanf("%d",&(account->peak_end_time)); -#endif + if (0 >= scanf("%d",&(account->peak_end_time)); +*/ + +/* + testapp_print("\n Enter new Account name:"); + if (0 >= scanf("%s",account_name); + + testapp_print("\n Enter new email addr:"); + if (0 >= scanf("%s",user_email_address); + testapp_print("\n Enter new signature:"); - result_from_scanf = scanf("%s",signature); + if (0 >= scanf("%s",signature); testapp_print("\n>> Enter add_my_address_to_bcc:(0:off, 1:on) "); - result_from_scanf = scanf("%d",&add_my_address_to_bcc); + if (0 >= scanf("%d",&add_my_address_to_bcc); testapp_print("\n>> Enter account_svc_id: "); - result_from_scanf = scanf("%d",&account_svc_id); + if (0 >= scanf("%d",&account_svc_id); testapp_print("\n>> With validation ? (0: No, 1:Yes) "); - result_from_scanf = scanf("%d",&with_validation); - + if (0 >= scanf("%d",&with_validation); +*/ if( account ) { - account->account_name = strdup(account_name); testapp_print("\n Assigning New Account name: (%s)", account->account_name); + testapp_print("\n Assigning New Signature: (%s)\n", account->options.signature); + /* + account->account_name = strdup(account_name); account->user_email_address = strdup(user_email_address); account->options.signature = strdup(signature); - testapp_print("\n Assigning New Signature: (%s)\n", account->options.signature); account->options.add_my_address_to_bcc = add_my_address_to_bcc; account->account_svc_id = account_svc_id; + */ if(with_validation) { if((err = email_update_account_with_validation(account_id, account)) != EMAIL_ERROR_NONE){ @@ -482,10 +492,10 @@ static gboolean testapp_test_delete_account () int account_id; email_account_t *account=NULL; int err = EMAIL_ERROR_NONE; - int result_from_scanf = 0; testapp_print("\n>> Enter Account No: "); - result_from_scanf = scanf("%d",&account_id); + if (0 >= scanf("%d",&account_id)) + testapp_print("Invalid input. "); /* sowmya.kr, 281209 Adding signature to options in email_account_t changes */ if( (err = email_get_account(account_id, WITHOUT_OPTION,&account)) < 0) { @@ -531,16 +541,17 @@ static gboolean testapp_test_validate_account () static gboolean testapp_test_cancel_validate_account () { - int result_from_scanf = 0; int account_id = 0; int err_code = EMAIL_ERROR_NONE; unsigned account_handle = 0; testapp_print("\n > Enter account_id: "); - result_from_scanf = scanf("%d", &account_id); + if (0 >= scanf("%d", &account_id)) + testapp_print("Invalid input. "); testapp_print("\n > Enter handle: "); - result_from_scanf = scanf("%d", &account_handle); + if (0 >= scanf("%d", &account_handle)) + testapp_print("Invalid input. "); err_code = email_cancel_job(account_id, account_handle, EMAIL_CANCELED_BY_USER); if(err_code == 0) @@ -553,12 +564,12 @@ static gboolean testapp_test_cancel_validate_account () static gboolean testapp_test_get_account() { - int result_from_scanf = 0; int account_id; email_account_t *account=NULL; int err_code = EMAIL_ERROR_NONE; testapp_print("\n>> Enter Account No: "); - result_from_scanf = scanf("%d",&account_id); + if (0 >= scanf("%d",&account_id)) + testapp_print("Invalid input. "); typedef struct { int is_preset_account; @@ -595,11 +606,16 @@ static gboolean testapp_test_get_account() "digest_type %d\n" "auto_resend_times %d\n" "roaming_option %d\n" - "peak_interval %d\n" "peak_days %d\n" "peak_start_time %d\n" "peak_end_time %d\n" + "color_label %d\n" + "notification_status %d\n" + "vibrate_status %d\n" + "display_content_status %d\n" + "default_ringtone_status %d\n" + "alert_ringtone_path %s\n" , account->account_name, account->user_email_address, @@ -622,7 +638,13 @@ static gboolean testapp_test_get_account() account->peak_interval, account->peak_days, account->peak_start_time, - account->peak_end_time + account->peak_end_time, + account->color_label, + account->options.notification_status, + account->options.vibrate_status, + account->options.display_content_status, + account->options.default_ringtone_status, + account->options.alert_ringtone_path ); err_code = email_free_account(&account, 1); @@ -719,12 +741,12 @@ static gboolean testapp_test_get_account_list () static gboolean testapp_test_update_check_interval() { int account_id = 0; - int result_from_scanf = 0; int err_code = EMAIL_ERROR_NONE; email_account_t *account = NULL; testapp_print("\n Enter account id :"); - result_from_scanf = scanf("%d",&account_id); + if (0 >= scanf("%d",&account_id)) + testapp_print("Invalid input. "); if( (err_code = email_get_account(account_id, GET_FULL_DATA_WITHOUT_PASSWORD, &account)) != EMAIL_ERROR_NONE) { testapp_print ("email_get_account failed [%d]\n", err_code); @@ -732,7 +754,8 @@ static gboolean testapp_test_update_check_interval() } testapp_print("\n Enter new check interval (in mins):"); - result_from_scanf = scanf("%d",&(account->check_interval)); + if (0 >= scanf("%d",&(account->check_interval))) + testapp_print("Invalid input. "); if((err_code = email_update_account(account_id, account)) != EMAIL_ERROR_NONE) { testapp_print ("email_update_account failed [%d]\n", err_code); @@ -750,7 +773,7 @@ FINISH_OFF: static gboolean testapp_test_backup_account() { - char *file_name = "accounts_file"; + char *file_name = "/opt/usr/data/email/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); @@ -758,7 +781,7 @@ static gboolean testapp_test_backup_account() } static gboolean testapp_test_restore_account() { - char *file_name = "accounts_file"; + char *file_name = "/opt/usr/data/email/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); @@ -767,30 +790,56 @@ static gboolean testapp_test_restore_account() static gboolean testapp_test_get_password_length_of_account() { - int result_from_scanf = 0; - int error_code, password_length, account_id; + int password_length, account_id; testapp_print("\n input account id\n"); - result_from_scanf = scanf("%d", &account_id); - error_code = email_get_password_length_of_account(account_id, &password_length); + if (0 >= scanf("%d", &account_id)) + testapp_print("Invalid input. "); + email_get_password_length_of_account(account_id, EMAIL_GET_INCOMING_PASSWORD_LENGTH, &password_length); testapp_print("testapp_test_get_password_length_of_account returned [%d]\n",password_length); return FALSE; } -static gboolean testapp_test_query_server_info() +static gboolean testapp_test_update_notification() { - int result_from_scanf = 0; int error_code; - char domain_name[255]; - email_server_info_t *result_server_info; + int account_id = 0; + int t_mail_count = 0; + int input_from_eas = 0; + int unread_mail_count = 0; + + testapp_print("\n Input account ID:\n"); + if (0 >= scanf("%d", &account_id)) + testapp_print("Invalid input. "); + + testapp_print("\n Input mail count:\n"); + if (0 >= scanf("%d", &t_mail_count)) + testapp_print("Invalid input. "); + + testapp_print("\n Input unread mail count:\n"); + if (0 >= scanf("%d", &unread_mail_count)) + testapp_print("Invalid input. "); - testapp_print("\n input domain name\n"); - result_from_scanf = scanf("%s", domain_name); + testapp_print("\n Input From eas:\n"); + if (0 >= scanf("%d", &input_from_eas)) + testapp_print("Invalid input. "); - error_code = email_query_server_info(domain_name, &result_server_info); - testapp_print("email_query_server_info returned [%d]\n",error_code); - if(error_code == EMAIL_ERROR_NONE) - testapp_print("service_name [%s]\n", result_server_info->service_name); + error_code = email_update_notification_bar(account_id, t_mail_count, unread_mail_count, input_from_eas); + testapp_print("email_update_notification_bar returned [%d]\n",error_code); + return FALSE; +} + +static gboolean testapp_test_clear_notification() +{ + int account_id = 0; + int error_code; + + testapp_print("\n Input account ID:\n"); + if (0 >= scanf("%d", &account_id)) + testapp_print("Invalid input. "); + + error_code = email_clear_notification_bar(account_id); + testapp_print("email_clear_notification_bar returned [%d]\n",error_code); return FALSE; } @@ -798,20 +847,20 @@ 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); + error_code = email_clear_notification_bar(ALL_ACCOUNT); + testapp_print("email_clear_notification_bar returned [%d]\n",error_code); return FALSE; } static gboolean testapp_test_save_default_account_id() { - int result_from_scanf = 0; int error_code; int account_id = 0; testapp_print ("\nInput default account id : "); - result_from_scanf = scanf("%d", &account_id); + if (0 >= scanf("%d", &account_id)) + testapp_print("Invalid input. "); error_code = email_save_default_account_id(account_id); @@ -833,16 +882,17 @@ static gboolean testapp_test_load_default_account_id() static gboolean testapp_test_add_certificate() { - int result_from_scanf = 0; int ret = 0; char save_name[50] = {0, }; char certificate_path[255] = {0, }; testapp_print("Input cert path : "); - result_from_scanf = scanf("%s", certificate_path); + if (0 >= scanf("%s", certificate_path)) + testapp_print("Invalid input. "); testapp_print("Input cert email-address : "); - result_from_scanf = scanf("%s", save_name); + if (0 >= scanf("%s", save_name)) + testapp_print("Invalid input. "); testapp_print("cert path : [%s]", certificate_path); testapp_print("email-address : [%s]", save_name); @@ -859,13 +909,13 @@ static gboolean testapp_test_add_certificate() static gboolean testapp_test_get_certificate() { - int result_from_scanf = 0; int ret = 0; char save_name[20] = {0, }; email_certificate_t *certificate = NULL; testapp_print("Input cert email-address : "); - result_from_scanf = scanf("%s", save_name); + if (0 >= scanf("%s", save_name)) + testapp_print("Invalid input. "); ret = email_get_certificate(save_name, &certificate); if (ret != EMAIL_ERROR_NONE) { @@ -893,12 +943,12 @@ static gboolean testapp_test_get_certificate() static gboolean testapp_test_delete_certificate() { - int result_from_scanf = 0; int ret = 0; char save_name[20] = {0, }; testapp_print("Input cert email-address : "); - result_from_scanf = scanf("%s", save_name); + if (0 >= scanf("%s", save_name)) + testapp_print("Invalid input. "); ret = email_delete_certificate(save_name); if (ret != EMAIL_ERROR_NONE) { @@ -936,13 +986,13 @@ static gboolean testapp_test_add_account() static gboolean testapp_test_update_peak_schedule() { - int result_from_scanf = 0; int account_id; email_account_t *account = NULL; int err = EMAIL_ERROR_NONE; testapp_print("\n>> Enter Account No: "); - result_from_scanf = scanf("%d",&account_id); + if (0 >= scanf("%d",&account_id)) + testapp_print("Invalid input. "); if( (err = email_get_account(account_id, GET_FULL_DATA, &account)) != EMAIL_ERROR_NONE) { testapp_print ("email_get_account failed [%d]\n", err); @@ -952,27 +1002,32 @@ static gboolean testapp_test_update_peak_schedule() testapp_print ("old check_interval - %d \n", account->check_interval); testapp_print("\n Enter new check interval (in mins):"); - result_from_scanf = scanf("%d",&(account->check_interval)); + if (0 >= scanf("%d",&(account->check_interval))) + testapp_print("Invalid input. "); testapp_print ("old peak_interval - %d \n", account->peak_interval); testapp_print("\n Enter new peak interval (in mins):"); - result_from_scanf = scanf("%d",&(account->peak_interval)); + if (0 >= scanf("%d",&(account->peak_interval))) + testapp_print("Invalid input. "); testapp_print ("old peak_days - %d \n", account->peak_days); testapp_print("\n Enter new peak days:"); - result_from_scanf = scanf("%d",&(account->peak_days)); + if (0 >= scanf("%d",&(account->peak_days))) + testapp_print("Invalid input. "); testapp_print ("old peak_start_time - %d \n", account->peak_start_time); testapp_print("\n Enter new peak start time:"); - result_from_scanf = scanf("%d",&(account->peak_start_time)); + if (0 >= scanf("%d",&(account->peak_start_time))) + testapp_print("Invalid input. "); testapp_print ("old peak_end_time - %d \n", account->peak_start_time); testapp_print("\n Enter new peak end time:"); - result_from_scanf = scanf("%d",&(account->peak_end_time)); + if (0 >= scanf("%d",&(account->peak_end_time))) + testapp_print("Invalid input. "); if( account ) { if((err = email_update_account(account_id, account)) != EMAIL_ERROR_NONE) { @@ -1033,39 +1088,43 @@ static gboolean testapp_test_interpret_command (int selected_number) testapp_test_get_password_length_of_account(); break; - case 12: - testapp_test_query_server_info(); + case 13: + testapp_test_update_notification(); break; - case 13: + case 14: + testapp_test_clear_notification(); + break; + + case 15: testapp_test_clear_all_notification(); break; - case 14: + case 16: testapp_test_save_default_account_id(); break; - case 15: + case 17: testapp_test_load_default_account_id(); break; - case 16: + case 18: testapp_test_add_certificate(); break; - case 17: + case 19: testapp_test_get_certificate(); break; - case 18: + case 20: testapp_test_delete_certificate(); break; - case 19: + case 21: testapp_test_add_account(); break; - case 20: + case 22: testapp_test_update_peak_schedule(); break; @@ -1084,13 +1143,13 @@ void testapp_account_main () { gboolean go_to_loop = TRUE; int menu_number = 0; - int result_from_scanf = 0; while (go_to_loop) { testapp_show_menu (EMAIL_ACCOUNT_MENU); testapp_show_prompt (EMAIL_ACCOUNT_MENU); - - result_from_scanf = scanf ("%d", &menu_number); + + if (0 >= scanf("%d", &menu_number)) + testapp_print("Invalid input"); go_to_loop = testapp_test_interpret_command (menu_number); } diff --git a/utilities/test-application/testapp-gmime.c b/utilities/test-application/testapp-gmime.c new file mode 100644 index 0000000..8493160 --- /dev/null +++ b/utilities/test-application/testapp-gmime.c @@ -0,0 +1,188 @@ +#include <glib.h> +#include <gmime/gmime.h> + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <unistd.h> +#include <fcntl.h> +#include <errno.h> + +#include "testapp-utility.h" +#include "testapp-gmime.h" + + +#define TEST_EML_PATH "/tmp/test.eml" + +static void print_depth(int depth) +{ + int i; + for (i = 0; i < depth; i++) + testapp_print(" \n"); +} + +static void print_mime_struct(GMimeObject *part, int depth) +{ + const GMimeContentType *type; + GMimeMultipart *multipart; + GMimeObject *subpart; + int i, n; + + print_depth(depth); + type = g_mime_object_get_content_type(part); + testapp_print("Content-Type: %s/%s\n", type->type, type->subtype); + + if (GMIME_IS_MULTIPART(part)) { + multipart = (GMimeMultipart *)part; + + n = g_mime_multipart_get_count(multipart); + for (i = 0; i < n; i++) { + subpart = g_mime_multipart_get_part(multipart, i); + print_mime_struct(subpart, depth + 1); + g_object_unref(subpart); + } + } +} + +static void +test_eml_parsing_foreach_callback(GMimeObject *parent, GMimeObject *part, gpointer user_data) +{ + int *cnt= user_data; + + (*cnt)++; + + if (GMIME_IS_PART(part)) { + testapp_print ("Part\n"); + GMimePart *leaf_part = NULL; + leaf_part = (GMimePart *)part; + + testapp_print("Content ID:%s\n", g_mime_part_get_content_id(leaf_part)); + testapp_print("Description:%s\n", g_mime_part_get_content_description(leaf_part)); + testapp_print("MD5:%s\n", g_mime_part_get_content_md5(leaf_part)); + testapp_print("Location:%s\n", g_mime_part_get_content_location(leaf_part)); + + GMimeContentEncoding enc = g_mime_part_get_content_encoding(leaf_part); + switch(enc) { + case GMIME_CONTENT_ENCODING_DEFAULT: + testapp_print("Encoding:ENCODING_DEFAULT\n"); + break; + case GMIME_CONTENT_ENCODING_7BIT: + testapp_print("Encoding:ENCODING_7BIT\n"); + break; + case GMIME_CONTENT_ENCODING_8BIT: + testapp_print("Encoding:ENCODING_8BIT\n"); + break; + case GMIME_CONTENT_ENCODING_BINARY: + testapp_print("Encoding:ENCODING_BINARY\n"); + break; + case GMIME_CONTENT_ENCODING_BASE64: + testapp_print("Encoding:ENCODING_BASE64\n"); + break; + case GMIME_CONTENT_ENCODING_QUOTEDPRINTABLE: + testapp_print("Encoding:ENCODING_QUOTEDPRINTABLE\n"); + break; + case GMIME_CONTENT_ENCODING_UUENCODE: + testapp_print("Encoding:ENCODING_UUENCODE\n"); + break; + + default: + break; + } + + testapp_print("File name:%s\n\n\n", g_mime_part_get_filename(leaf_part)); + GMimeDataWrapper *data = g_mime_part_get_content_object(leaf_part); + + if (data) { + char tmp_path[50] = {0,}; + snprintf(tmp_path, sizeof(tmp_path), "/tmp/gmime_content%d", *cnt); + + int fd; + if ((fd = open(tmp_path, O_RDWR|O_CREAT, 0)) == -1) { + testapp_print ("open fail\n"); + } + GMimeStream *out_stream; + out_stream = g_mime_stream_fs_new(fd); + g_mime_data_wrapper_write_to_stream(data, out_stream); + g_object_unref(out_stream); + } + } +} + +static gboolean testapp_test_gmime_eml_parsing(void) +{ + GMimeMessage *message; + GMimeParser *parser; + GMimeStream *stream; + int fd; + int count = 0; + + if ((fd = open(TEST_EML_PATH, O_RDONLY, 0)) == -1) { + testapp_print ("open fail\n"); + return 0; + } + + /* init the gmime library */ + g_mime_init(0); + + /* create a stream to read from the file descriptor */ + stream = g_mime_stream_fs_new(fd); + + /* create a new parser object to parse the stream */ + parser = g_mime_parser_new_with_stream(stream); + + /* unref the stream (parser owns a ref, so this object does not actually get free'd until we destroy the parser) */ + g_object_unref(stream); + + /* parse the message from the stream */ + message = g_mime_parser_construct_message(parser); + + /* free the parser (and the stream) */ + g_object_unref(parser); + + testapp_print("Sender:%s\n", g_mime_message_get_sender(message)); + testapp_print("Reply To:%s\n", g_mime_message_get_reply_to(message)); + testapp_print("Subject:%s\n", g_mime_message_get_subject(message)); + testapp_print("Date:%s\n", g_mime_message_get_date_as_string(message)); + testapp_print("Message ID:%s\n", g_mime_message_get_message_id(message)); + + GMimeObject *po = (GMimeObject *)message; + testapp_print("Header String:%s\n\n\n\n", g_mime_header_list_to_string(po->headers)); + + g_mime_message_foreach(message, test_eml_parsing_foreach_callback, &count); +} + +static gboolean testapp_test_interpret_command (int menu_number) +{ + gboolean go_to_loop = TRUE; + + switch (menu_number) { + case 1: + testapp_test_gmime_eml_parsing(); + break; + + case 0: + go_to_loop = FALSE; + break; + default: + break; + } + + return go_to_loop; +} + +void testapp_gmime_main() +{ + gboolean go_to_loop = TRUE; + int menu_number = 0; + + while (go_to_loop) { + testapp_show_menu (EMAIL_GMIME_MENU); + testapp_show_prompt (EMAIL_GMIME_MENU); + + result_from_scanf = scanf ("%d", &menu_number); + + go_to_loop = testapp_test_interpret_command (menu_number); + } +} diff --git a/utilities/test-application/testapp-mail.c b/utilities/test-application/testapp-mail.c index add534f..8192482 100755 --- a/utilities/test-application/testapp-mail.c +++ b/utilities/test-application/testapp-mail.c @@ -112,24 +112,27 @@ static void testapp_test_print_mail_list_item(email_mail_list_item_t *mail_list_ static gboolean testapp_add_mail_for_sending (int *result_mail_id) { - int result_from_scanf = 0; int i = 0; int account_id = 0; int err = EMAIL_ERROR_NONE; int smime_type = 0; - char receipient_address[300] = { 0 , }; + char recipient_address[300] = { 0 , }; char from_address[300] = { 0 , }; + char passpharse[300] = {0, }; const char *body_file_path = MAIL_TEMP_BODY; + email_account_t *account_data = NULL; email_mailbox_t *mailbox_data = NULL; email_mail_data_t *test_mail_data = NULL; FILE *body_file; testapp_print("\n > Enter account id : "); - result_from_scanf = scanf("%d", &account_id); + if (0 >= scanf("%d", &account_id)) + testapp_print("Invalid input. "); - testapp_print("\n > Enter receipient address : "); - result_from_scanf = scanf("%s", receipient_address); + testapp_print("\n > Enter recipient address : "); + if (0 >= scanf("%s", recipient_address)) + testapp_print("Invalid input. "); email_get_account(account_id, GET_FULL_DATA_WITHOUT_PASSWORD, &account_data); @@ -148,7 +151,7 @@ static gboolean testapp_add_mail_for_sending (int *result_mail_id) test_mail_data->mailbox_id = mailbox_data->mailbox_id; test_mail_data->mailbox_type = mailbox_data->mailbox_type; test_mail_data->full_address_from = strdup(from_address); - test_mail_data->full_address_to = strdup(receipient_address); + test_mail_data->full_address_to = strdup(recipient_address); test_mail_data->subject = strdup("Read receipt request from TIZEN"); test_mail_data->remaining_resend_times = 3; test_mail_data->report_status = EMAIL_MAIL_REQUEST_DSN | EMAIL_MAIL_REQUEST_MDN; @@ -168,10 +171,18 @@ static gboolean testapp_add_mail_for_sending (int *result_mail_id) fflush(body_file); fclose(body_file); - testapp_print(" > Select smime? [0: Normal, 1: sign, 2: Encrpyt, 3: sing + encrypt] : "); - result_from_scanf = scanf("%d", &smime_type); + testapp_print(" > Select smime? [0: Normal, 1: sign, 2: Encrpyt, 3: sing + encrypt, 4: pgp sign, 5: pgp encrypted, 6: pgp sign + encrypt] : "); + if (0 >= scanf("%d", &smime_type)) + testapp_print("Invalid input. "); test_mail_data->smime_type = smime_type; + if (smime_type >= EMAIL_PGP_SIGNED) { + testapp_print(" > passpharse : "); + if (0 >= scanf("%s", passpharse)) + testapp_print("Invalid input. "); + test_mail_data->pgp_password = strdup(passpharse); + } + if((err = email_add_mail(test_mail_data, NULL, 0, NULL, 0)) != EMAIL_ERROR_NONE) testapp_print("email_add_mail failed. [%d]\n", err); else @@ -191,7 +202,6 @@ static gboolean testapp_add_mail_for_sending (int *result_mail_id) static gboolean testapp_test_add_mail (int *result_mail_id) { - int result_from_scanf = 0; int i = 0; int account_id = 0; int mailbox_id = 0; @@ -208,12 +218,13 @@ static gboolean testapp_test_add_mail (int *result_mail_id) FILE *body_file; testapp_print("\n > Enter account id : "); - result_from_scanf = scanf("%d", &account_id); + if (0 >= scanf("%d", &account_id)) + testapp_print("Invalid input. "); - memset(arg, 0x00, 50); testapp_print("\n > Enter mailbox id : "); - result_from_scanf = scanf("%d", &mailbox_id); + if (0 >= scanf("%d", &mailbox_id)) + testapp_print("Invalid input. "); email_get_mailbox_by_mailbox_id(mailbox_id, &mailbox_data); @@ -221,7 +232,8 @@ static gboolean testapp_test_add_mail (int *result_mail_id) memset(test_mail_data, 0x00, sizeof(email_mail_data_t)); testapp_print("\n From EAS? [0/1]> "); - result_from_scanf = scanf("%d", &from_eas); + if (0 >= scanf("%d", &from_eas)) + testapp_print("Invalid input. "); test_mail_data->account_id = account_id; test_mail_data->save_status = 1; @@ -256,11 +268,13 @@ static gboolean testapp_test_add_mail (int *result_mail_id) fclose(body_file); testapp_print(" > Select smime? [0: Normal, 1: sign, 2: Encrypt, 3: sing + encrypt] : "); - result_from_scanf = scanf("%d", &smime_type); + if (0 >= scanf("%d", &smime_type)) + testapp_print("Invalid input. "); test_mail_data->smime_type = smime_type; testapp_print(" > How many file attachment? [>=0] : "); - result_from_scanf = scanf("%d",&attachment_count); + if (0 >= scanf("%d",&attachment_count)) + testapp_print("Invalid input. "); test_mail_data->attachment_count = attachment_count; if ( attachment_count > 0 ) @@ -270,13 +284,15 @@ static gboolean testapp_test_add_mail (int *result_mail_id) for ( i = 0; i < attachment_count ; i++ ) { memset(arg, 0x00, 50); testapp_print("\n > Enter attachment name : "); - result_from_scanf = scanf("%s", arg); + if (0 >= scanf("%s", arg)) + testapp_print("Invalid input. "); attachment_data[i].attachment_name = strdup(arg); memset(arg, 0x00, 50); testapp_print("\n > Enter attachment absolute path : "); - result_from_scanf = scanf("%s",arg); + if (0 >= scanf("%s",arg)) + testapp_print("Invalid input. "); attachment_data[i].attachment_path = strdup(arg); attachment_data[i].save_status = 1; @@ -284,7 +300,8 @@ static gboolean testapp_test_add_mail (int *result_mail_id) } testapp_print("\n > Meeting Request? [0: no, 1: yes (request from server), 2: yes (response from local)]"); - result_from_scanf = scanf("%d", (int*)&(test_mail_data->meeting_request_status)); + if (0 >= scanf("%d", (int*)&(test_mail_data->meeting_request_status))) + testapp_print("Invalid input. "); if ( test_mail_data->meeting_request_status == 1 || test_mail_data->meeting_request_status == 2 ) { @@ -336,7 +353,6 @@ static gboolean testapp_test_add_mail (int *result_mail_id) static gboolean testapp_test_update_mail() { - int result_from_scanf = 0; int mail_id = 0; int err = EMAIL_ERROR_NONE; int test_attachment_data_count = 0; @@ -347,7 +363,8 @@ static gboolean testapp_test_update_mail() email_meeting_request_t *meeting_req = NULL; testapp_print("\n > Enter mail id : "); - result_from_scanf = scanf("%d", &mail_id); + if (0 >= scanf("%d", &mail_id)) + testapp_print("Invalid input. "); email_get_mail_data(mail_id, &test_mail_data); @@ -357,7 +374,8 @@ static gboolean testapp_test_update_mail() } testapp_print("\n > Enter Subject: "); - result_from_scanf = scanf("%s", arg); + if (0 >= scanf("%s", arg)) + testapp_print("Invalid input. "); test_mail_data->subject= strdup(arg); @@ -378,7 +396,8 @@ static gboolean testapp_test_update_mail() } testapp_print("\n > Enter meeting response: "); - result_from_scanf = scanf("%d", (int*)&(meeting_req->meeting_response)); + if (0 >= scanf("%d", (int*)&(meeting_req->meeting_response))) + testapp_print("Invalid input. "); } if ( (err = email_update_mail(test_mail_data, test_attachment_data_list, test_attachment_data_count, meeting_req, 0)) != EMAIL_ERROR_NONE) @@ -419,29 +438,34 @@ static gboolean testapp_test_get_mails() int to_get_count = 0; int is_for_thread_view = 0; int list_type; - int result_from_scanf = 0; struct tm *temp_time_info; testapp_print("\n > Enter Account_id (0 = all accounts) : "); - result_from_scanf = scanf("%d",&account_id); - + if (0 >= scanf("%d",&account_id)) + testapp_print("Invalid input. "); testapp_print("\n > Enter Mailbox id (0 = all mailboxes) :"); - result_from_scanf = scanf("%d", &mailbox_id); + if (0 >= scanf("%d", &mailbox_id)) + testapp_print("Invalid input. "); testapp_print("\n > Enter Sorting : "); - result_from_scanf = scanf("%d",&sorting); + if (0 >= scanf("%d",&sorting)) + testapp_print("Invalid input. "); testapp_print("\n > Enter Start index (starting at 0): "); - result_from_scanf = scanf("%d",&start_index); + if (0 >= scanf("%d",&start_index)) + testapp_print("Invalid input. "); testapp_print("\n > Enter max_count : "); - result_from_scanf = scanf("%d",&limit_count); + if (0 >= scanf("%d",&limit_count)) + testapp_print("Invalid input. "); testapp_print("\n > For thread view : "); - result_from_scanf = scanf("%d",&is_for_thread_view); + if (0 >= scanf("%d",&is_for_thread_view)) + testapp_print("Invalid input. "); testapp_print("\n > Mail count only (0:list 1:count): "); - result_from_scanf = scanf("%d",&to_get_count); + if (0 >= scanf("%d",&to_get_count)) + testapp_print("Invalid input. "); if(to_get_count) mails_pointer = NULL; @@ -549,6 +573,7 @@ static gboolean testapp_test_get_mail_list_ex() int result_mail_count = 0; int err = EMAIL_ERROR_NONE; int i = 0; + int sort_order = 0; filter_rule_count = 3; @@ -649,10 +674,17 @@ static gboolean testapp_test_get_mail_list_ex() sorting_rule_list = malloc(sizeof(email_list_sorting_rule_t) * sorting_rule_count); memset(sorting_rule_list, 0 , sizeof(email_list_sorting_rule_t) * sorting_rule_count); - +/* sorting_rule_list[0].target_attribute = EMAIL_MAIL_ATTRIBUTE_RECIPIENT_ADDRESS; sorting_rule_list[0].key_value.string_type_value = strdup("minsoo.kimn@gmail.com"); sorting_rule_list[0].sort_order = EMAIL_SORT_ORDER_TO_CCBCC; +*/ + testapp_print("\n Enter the sort_order :"); + if (0 >= scanf("%d", &sort_order)) + testapp_print("Invalid input."); + + sorting_rule_list[0].target_attribute = EMAIL_MAIL_ATTRIBUTE_SUBJECT; + sorting_rule_list[0].sort_order = sort_order; sorting_rule_list[1].target_attribute = EMAIL_MAIL_ATTRIBUTE_DATE_TIME; sorting_rule_list[1].sort_order = EMAIL_SORT_ORDER_DESCEND; @@ -683,10 +715,10 @@ static gboolean testapp_test_send_cancel () int j = 0; int *mailIdList = NULL; int mail_id = 0; - int result_from_scanf = 0; testapp_print("\n > Enter total Number of mail want to send: "); - result_from_scanf = scanf("%d", &num); + if (0 >= scanf("%d", &num)) + testapp_print("Invalid input. "); mailIdList = (int *)malloc(sizeof(int)*num); if(!mailIdList) return false ; @@ -701,10 +733,12 @@ static gboolean testapp_test_send_cancel () mail_id = 0; testapp_print("\n > Do you want to cancel the send mail job '1' or '0': "); - result_from_scanf = scanf("%d", &Y); + if (0 >= scanf("%d", &Y)) + testapp_print("Invalid input. "); if(Y == 1) { testapp_print("\n >Enter mail-id[1-%d] ",i); - result_from_scanf = scanf("%d", &j); + if (0 >= scanf("%d", &j)) + testapp_print("Invalid input. "); testapp_print("\n mailIdList[%d] ",mailIdList[j]); if(email_cancel_sending_mail( mailIdList[j]) < 0) testapp_print("email_cancel_sending_mail failed..!"); @@ -721,19 +755,22 @@ static gboolean testapp_test_delete() int mailbox_id = 0; int err = EMAIL_ERROR_NONE; int from_server = 0; - int result_from_scanf = 0; testapp_print("\n > Enter Account_id: "); - result_from_scanf = scanf("%d", &account_id); + if (0 >= scanf("%d", &account_id)) + testapp_print("Invalid input. "); testapp_print("\n > Enter Mail_id: "); - result_from_scanf = scanf("%d", &mail_id); + if (0 >= scanf("%d", &mail_id)) + testapp_print("Invalid input. "); testapp_print("\n > Enter Mailbox id: "); - result_from_scanf = scanf("%d", &mailbox_id); + if (0 >= scanf("%d", &mailbox_id)) + testapp_print("Invalid input. "); testapp_print("\n > Enter from_server: "); - result_from_scanf = scanf("%d", &from_server); + if (0 >= scanf("%d", &from_server)) + testapp_print("Invalid input. "); /* delete message */ if( (err = email_delete_mail(mailbox_id, &mail_id, 1, from_server)) < 0) @@ -751,21 +788,24 @@ static gboolean testapp_test_update_mail_attribute() int account_id = 0; int *mail_id_array = NULL; int mail_id_count = 0; - int result_from_scanf = 0; email_mail_attribute_type attribute_type; email_mail_attribute_value_t attribute_value; testapp_print("\n > Enter account_id: "); - result_from_scanf = scanf("%d", &account_id); + if (0 >= scanf("%d", &account_id)) + testapp_print("Invalid input. "); testapp_print("\n > Enter attribute_type: "); - result_from_scanf = scanf("%d", (int*)&attribute_type); + if (0 >= scanf("%d", (int*)&attribute_type)) + testapp_print("Invalid input. "); testapp_print("\n > Enter integer type value: "); - result_from_scanf = scanf("%d", (int*)&(attribute_value.integer_type_value)); + if (0 >= scanf("%d", (int*)&(attribute_value.integer_type_value))) + testapp_print("Invalid input. "); testapp_print("\n > Enter mail_id_count: "); - result_from_scanf = scanf("%d", &mail_id_count); + if (0 >= scanf("%d", &mail_id_count)) + testapp_print("Invalid input. "); mail_id_count = (mail_id_count < 5000)?mail_id_count:5000; @@ -775,7 +815,8 @@ static gboolean testapp_test_update_mail_attribute() for (i = 0; i < mail_id_count; i++) { testapp_print("\n > Enter mail id: "); - result_from_scanf = scanf("%d", (mail_id_array + i)); + if (0 >= scanf("%d", (mail_id_array + i))) + testapp_print("Invalid input. "); } /* delete message */ @@ -795,15 +836,16 @@ static gboolean testapp_test_move() int mail_id[3]; int i = 0; int mailbox_id = 0; - int result_from_scanf = 0; for(i = 0; i< 3; i++) { testapp_print("\n > Enter mail_id: "); - result_from_scanf = scanf("%d",&mail_id[i]); + if (0 >= scanf("%d",&mail_id[i])) + testapp_print("Invalid input. "); } testapp_print("\n > Enter mailbox_id: "); - result_from_scanf = scanf("%d", &mailbox_id); + if (0 >= scanf("%d", &mailbox_id)) + testapp_print("Invalid input. "); /* move mail */ email_move_mail_to_mailbox(mail_id, 3, mailbox_id); @@ -814,10 +856,10 @@ static gboolean testapp_test_delete_all() { int mailbox_id =0; int err = EMAIL_ERROR_NONE; - int result_from_scanf = 0; testapp_print("\n > Enter mailbox_id: "); - result_from_scanf = scanf("%d",&mailbox_id); + if (0 >= scanf("%d",&mailbox_id)) + testapp_print("Invalid input. "); /* delete all message */ if ( (err = email_delete_all_mails_in_mailbox(mailbox_id, 0)) < 0) @@ -832,23 +874,25 @@ static gboolean testapp_test_delete_all() static gboolean testapp_test_add_attachment() { int mail_id = 0; - int result_from_scanf = 0; char arg[100]; email_attachment_data_t attachment; testapp_print("\n > Enter Mail Id: "); - result_from_scanf = scanf("%d", &mail_id); + if (0 >= scanf("%d", &mail_id)) + testapp_print("Invalid input. "); memset(&attachment, 0x00, sizeof(email_attachment_data_t)); memset(arg, 0x00, 100); testapp_print("\n > Enter attachment name: "); - result_from_scanf = scanf("%s",arg); + if (0 >= scanf("%s",arg)) + testapp_print("Invalid input. "); attachment.attachment_name = strdup(arg); memset(arg, 0x00, 100); testapp_print("\n > Enter attachment absolute path: "); - result_from_scanf = scanf("%s",arg); + if (0 >= scanf("%s",arg)) + testapp_print("Invalid input. "); attachment.save_status = true; attachment.attachment_path = strdup(arg); @@ -869,14 +913,15 @@ static gboolean testapp_test_set_deleted_flag() int mail_ids[100] = { 0, }; int temp_mail_id = 0; int err_code = EMAIL_ERROR_NONE; - int result_from_scanf = 0; testapp_print("\n >>> Input target account id: "); - result_from_scanf = scanf("%d", &account_id); + if (0 >= scanf("%d", &account_id)) + testapp_print("Invalid input. "); do { testapp_print("\n >>> Input target mail id ( Input 0 to terminate ) [MAX = 100]: "); - result_from_scanf = scanf("%d", &temp_mail_id); + if (0 >= scanf("%d", &temp_mail_id)) + testapp_print("Invalid input. "); mail_ids[index++] = temp_mail_id; } while (temp_mail_id != 0); @@ -892,13 +937,14 @@ static gboolean testapp_test_expunge_mails_deleted_flagged() int on_server = 0; int err_code = EMAIL_ERROR_NONE; int handle = 0; - int result_from_scanf = 0; testapp_print("\n >>> Input target mailbox id: "); - result_from_scanf = scanf("%d", &mailbox_id); + if (0 >= scanf("%d", &mailbox_id)) + testapp_print("Invalid input. "); testapp_print("\n >>> Expunge on server?: "); - result_from_scanf = scanf("%d", &on_server); + if (0 >= scanf("%d", &on_server)) + testapp_print("Invalid input. "); err_code = email_expunge_mails_deleted_flagged(mailbox_id, on_server, &handle); @@ -912,11 +958,11 @@ static gboolean testapp_test_send_read_receipt() int read_mail_id = 0; int receipt_mail_id = 0; int err_code = EMAIL_ERROR_NONE; - int result_from_scanf = 0; int handle = 0; testapp_print("\n >>> Input read mail id: "); - result_from_scanf = scanf("%d", &read_mail_id); + if (0 >= scanf("%d", &read_mail_id)) + testapp_print("Invalid input. "); err_code = email_add_read_receipt(read_mail_id, &receipt_mail_id); @@ -937,10 +983,10 @@ static gboolean testapp_test_delete_attachment() { int attachment_id = 0; int err_code = EMAIL_ERROR_NONE; - int result_from_scanf = 0; testapp_print("\n >>> Input attachment id: "); - result_from_scanf = scanf("%d", &attachment_id); + if (0 >= scanf("%d", &attachment_id)) + testapp_print("Invalid input. "); if( (err_code = email_delete_attachment(attachment_id)) != EMAIL_ERROR_NONE) { testapp_print("email_delete_attachment failed[%d]\n", err_code); @@ -964,28 +1010,34 @@ static gboolean testapp_test_get_mail_list() int is_for_thread_view = 0; int list_type; struct tm *temp_time_info; - int result_from_scanf = 0; testapp_print("\n > Enter Account_id (0 = all accounts) : "); - result_from_scanf = scanf("%d",&account_id); + if (0 >= scanf("%d",&account_id)) + testapp_print("Invalid input. "); testapp_print("\n > Enter Mailbox id (0 = all mailboxes) :"); - result_from_scanf = scanf("%d", &mailbox_id); + if (0 >= scanf("%d", &mailbox_id)) + testapp_print("Invalid input. "); testapp_print("\n > Enter Sorting : "); - result_from_scanf = scanf("%d",&sorting); + if (0 >= scanf("%d",&sorting)) + testapp_print("Invalid input. "); testapp_print("\n > Enter Start index (starting at 0): "); - result_from_scanf = scanf("%d",&start_index); + if (0 >= scanf("%d",&start_index)) + testapp_print("Invalid input. "); testapp_print("\n > Enter max_count : "); - result_from_scanf = scanf("%d",&limit_count); + if (0 >= scanf("%d",&limit_count)) + testapp_print("Invalid input. "); testapp_print("\n > For thread view : "); - result_from_scanf = scanf("%d",&is_for_thread_view); + if (0 >= scanf("%d",&is_for_thread_view)) + testapp_print("Invalid input. "); testapp_print("\n > Count mails?(1: YES):"); - result_from_scanf = scanf("%d",&to_get_count); + if (0 >= scanf("%d",&to_get_count)) + testapp_print("Invalid input. "); if(to_get_count) mail_list_pointer = NULL; @@ -1060,15 +1112,16 @@ static gboolean testapp_test_get_mail_list_for_thread_view() int count = 0, i = 0; int account_id = 0; int mailbox_id = 0; - int result_from_scanf; int err_code = EMAIL_ERROR_NONE; struct tm *time_info; testapp_print("\nEnter account id\n"); - result_from_scanf = scanf("%d",&account_id); + if (0 >= scanf("%d",&account_id)) + testapp_print("Invalid input. "); testapp_print("\nEnter mailbox id\n"); - result_from_scanf = scanf("%d",&mailbox_id); + if (0 >= scanf("%d",&mailbox_id)) + testapp_print("Invalid input. "); /* Get mail list */ @@ -1142,16 +1195,18 @@ static gboolean testapp_test_move_mails_to_mailbox_of_another_account() int target_mailbox_id = 0; int task_id = 0; int i = 0; - int result_from_scanf = 0; testapp_print("\n > Enter source mailbox id: "); - result_from_scanf = scanf("%d", &source_mailbox_id); + if (0 >= scanf("%d", &source_mailbox_id)) + testapp_print("Invalid input. "); testapp_print("\n > Enter target mailbox id: "); - result_from_scanf = scanf("%d", &target_mailbox_id); + if (0 >= scanf("%d", &target_mailbox_id)) + testapp_print("Invalid input. "); testapp_print("\n > Enter mail count: "); - result_from_scanf = scanf("%d", &mail_id_count); + if (0 >= scanf("%d", &mail_id_count)) + testapp_print("Invalid input. "); mail_id_count = (mail_id_count < 5000)?mail_id_count:5000; @@ -1161,7 +1216,8 @@ static gboolean testapp_test_move_mails_to_mailbox_of_another_account() for(i = 0; i < mail_id_count; i++) { testapp_print("\n > Enter mail id: "); - result_from_scanf = scanf("%d", (mail_id_array + i)); + if (0 >= scanf("%d", (mail_id_array + i))) + testapp_print("Invalid input. "); } err = email_move_mails_to_mailbox_of_another_account(source_mailbox_id, mail_id_array, mail_id_count, target_mailbox_id, &task_id); @@ -1174,7 +1230,6 @@ static gboolean copy_file(char *input_source_path, char *input_dest_path) { int childExitStatus; pid_t pid; - int status; if (!input_source_path || !input_dest_path) { return FALSE; } @@ -1196,7 +1251,7 @@ static gboolean copy_file(char *input_source_path, char *input_dest_path) if( WIFEXITED(childExitStatus)) /* exit code in childExitStatus */ { - status = WEXITSTATUS(childExitStatus); /* zero is normal exit */ + WEXITSTATUS(childExitStatus); /* zero is normal exit */ testapp_print("WEXITSTATUS\n"); /* handle non-zero as you wish */ } @@ -1218,7 +1273,6 @@ static gboolean testapp_test_send_mail_with_downloading_attachment_of_original_m { int err = EMAIL_ERROR_NONE; int original_mail_id = 0; - int result_from_scanf = 0; int original_attachment_count = 0; int i = 0; int handle = 0; @@ -1231,7 +1285,8 @@ static gboolean testapp_test_send_mail_with_downloading_attachment_of_original_m email_attachment_data_t *original_attachment_array = NULL; testapp_print("\n > Enter original mail id: "); - result_from_scanf = scanf("%d", &original_mail_id); + if (0 >= scanf("%d", &original_mail_id)) + testapp_print("Invalid input. "); /* Get original mail */ if((err = email_get_mail_data(original_mail_id, &original_mail_data)) != EMAIL_ERROR_NONE || !original_mail_data) { @@ -1343,11 +1398,11 @@ static gboolean testapp_test_get_mail_data() { int err = EMAIL_ERROR_NONE; int mail_id = 0; - int result_from_scanf = 0; email_mail_data_t *mail_data = NULL; testapp_print("\n > Enter mail id: "); - result_from_scanf = scanf("%d", &mail_id); + if (0 >= scanf("%d", &mail_id)) + testapp_print("Invalid input. "); /* Get original mail */ if((err = email_get_mail_data(mail_id, &mail_data)) != EMAIL_ERROR_NONE || !mail_data) { @@ -1476,13 +1531,14 @@ static gboolean testapp_test_set_flags_field () { int account_id = 0; int mail_id = 0; - int result_from_scanf = 0; testapp_print("\n > Enter Account ID: "); - result_from_scanf = scanf("%d", &account_id); + if (0 >= scanf("%d", &account_id)) + testapp_print("Invalid input. "); testapp_print("\n > Enter Mail ID: "); - result_from_scanf = scanf("%d", &mail_id); + if (0 >= scanf("%d", &mail_id)) + testapp_print("Invalid input. "); if(email_set_flags_field(account_id, &mail_id, 1, EMAIL_FLAGS_FLAGGED_FIELD, 1, 1) < 0) testapp_print("email_set_flags_field failed"); @@ -1496,10 +1552,10 @@ static gboolean testapp_test_download_body () { int mail_id = 0; int handle = 0, err; - int result_from_scanf = 0; testapp_print("\n > Enter Mail Id: "); - result_from_scanf = scanf("%d", &mail_id); + if (0 >= scanf("%d", &mail_id)) + testapp_print("Invalid input. "); err = email_download_body(mail_id, 0, &handle); if(err < 0) testapp_print("email_download_body failed"); @@ -1517,23 +1573,25 @@ static gboolean testapp_test_cancel_download_body () int account_id = 0; int yes = 0; int handle = 0; - int result_from_scanf = 0; email_mailbox_t mailbox; memset(&mailbox, 0x00, sizeof(email_mailbox_t)); testapp_print("\n > Enter account_id: "); - result_from_scanf = scanf("%d", &account_id); + if (0 >= scanf("%d", &account_id)) + testapp_print("Invalid input. "); testapp_print("\n > Enter mail id: "); - result_from_scanf = scanf("%d", &mail_id); + if (0 >= scanf("%d", &mail_id)) + testapp_print("Invalid input. "); if( email_download_body(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"); - result_from_scanf = scanf("%d",&yes); + if (0 >= scanf("%d",&yes)) + testapp_print("Invalid input. "); if(1 == yes) { if(email_cancel_job(account_id, handle , EMAIL_CANCELED_BY_USER) < 0) testapp_print("email_cancel_job failed..!"); @@ -1551,13 +1609,14 @@ static gboolean testapp_test_download_attachment () int mail_id = 0; int attachment_no = 0; int handle = 0; - int result_from_scanf = 0; testapp_print("\n > Enter Mail Id: "); - result_from_scanf = scanf("%d", &mail_id); + if (0 >= scanf("%d", &mail_id)) + testapp_print("Invalid input. "); testapp_print("\n > Enter attachment number: "); - result_from_scanf = scanf("%d", &attachment_no); + if (0 >= scanf("%d", &attachment_no)) + testapp_print("Invalid input. "); if( email_download_attachment(mail_id, attachment_no ,&handle) < 0) testapp_print("email_download_attachment failed"); @@ -1574,12 +1633,12 @@ static gboolean testapp_test_get_attachment_data_list() int err = EMAIL_ERROR_NONE; int i = 0; int mail_id = 0; - int result_from_scanf = 0; int test_attachment_data_count; email_attachment_data_t *test_attachment_data_list = NULL; testapp_print("\n > Enter Mail id: "); - result_from_scanf = scanf("%d", &mail_id); + if (0 >= scanf("%d", &mail_id)) + testapp_print("Invalid input. "); if ( (err = email_get_attachment_data_list(mail_id, &test_attachment_data_list, &test_attachment_data_count)) != EMAIL_ERROR_NONE ) { testapp_print("email_get_attachment_data_list() failed [%d]\n", err); @@ -1605,12 +1664,12 @@ FINISH_OFF: static gboolean testapp_test_get_meeting_request() { int mail_id = 0; - int result_from_scanf = 0; int err = EMAIL_ERROR_NONE; email_meeting_request_t *meeting_request; testapp_print("\n > Enter Mail Id: "); - result_from_scanf = scanf("%d", &mail_id); + if (0 >= scanf("%d", &mail_id)) + testapp_print("Invalid input. "); err = email_get_meeting_request(mail_id, &meeting_request); @@ -1630,16 +1689,17 @@ static gboolean testapp_test_retry_send() { int mail_id = 0; int timeout = 0; - int result_from_scanf = 0; email_mailbox_t mailbox; memset(&mailbox, 0x00, sizeof(email_mailbox_t)); testapp_print("\n > Enter Mail Id: "); - result_from_scanf = scanf("%d", &mail_id); + if (0 >= scanf("%d", &mail_id)) + testapp_print("Invalid input. "); testapp_print("\n > Enter timeout in seconds: "); - result_from_scanf = scanf("%d", &timeout); + if (0 >= scanf("%d", &timeout)) + testapp_print("Invalid input. "); if( email_retry_sending_mail(mail_id, timeout) < 0) testapp_print("email_retry_sending_mail failed"); @@ -1649,11 +1709,11 @@ static gboolean testapp_test_retry_send() static gboolean testapp_test_get_attachment_data() { int attachment_id = 0; - int result_from_scanf = 0; email_attachment_data_t *attachment = NULL; testapp_print("\n > Enter attachment id: "); - result_from_scanf = scanf("%d", &attachment_id); + if (0 >= scanf("%d", &attachment_id)) + testapp_print("Invalid input. "); email_get_attachment_data(attachment_id, &attachment); @@ -1671,15 +1731,16 @@ static gboolean testapp_test_get_attachment_data() static gboolean testapp_test_move_all_mails_to_mailbox() { int err = EMAIL_ERROR_NONE; - int result_from_scanf = 0; int src_mailbox_id; int dest_mailbox_id; testapp_print("src mailbox id> "); - result_from_scanf = scanf("%d", &src_mailbox_id); + if (0 >= scanf("%d", &src_mailbox_id)) + testapp_print("Invalid input. "); testapp_print("dest mailbox id> "); - result_from_scanf = scanf("%d", &dest_mailbox_id); + if (0 >= scanf("%d", &dest_mailbox_id)) + testapp_print("Invalid input. "); err = email_move_all_mails_to_mailbox(src_mailbox_id, dest_mailbox_id); if ( err < 0 ) { @@ -1711,7 +1772,6 @@ static gboolean testapp_test_get_totaldiskusage() static gboolean testapp_test_db_test() { int err = EMAIL_ERROR_NONE; - int result_from_scanf = 0; int mail_id; int account_id; char *to = NULL; @@ -1727,15 +1787,20 @@ static gboolean testapp_test_db_test() memset(bcc, 0x00, sizeof(to)); testapp_print("Input Mail id:\n"); - result_from_scanf = scanf("%d", &mail_id); + if (0 >= scanf("%d", &mail_id)) + testapp_print("Invalid input. "); testapp_print("Input Account id:\n"); - result_from_scanf = scanf("%d", &account_id); + if (0 >= scanf("%d", &account_id)) + testapp_print("Invalid input. "); testapp_print("Input TO field:\n"); - result_from_scanf = scanf("%s", to); + if (0 >= scanf("%s", to)) + testapp_print("Invalid input. "); testapp_print("Input CC field:\n"); - result_from_scanf = scanf("%s", cc); + if (0 >= scanf("%s", cc)) + testapp_print("Invalid input. "); testapp_print("Input BCC field:\n"); - result_from_scanf = scanf("%s", bcc); + if (0 >= scanf("%s", bcc)) + testapp_print("Invalid input. "); if ( emstorage_test(mail_id, account_id, to, cc, bcc, &err) == true ) { testapp_print(">> Saving Succeeded\n"); @@ -1811,7 +1876,7 @@ static gboolean testapp_test_address_format_check_test() testapp_print("Select input method:\n"); testapp_print("1. Test data\n"); testapp_print("2. Keyboard\n"); - result_from_scanf = scanf("%d", &type); + if (0 >= scanf("%d", &type); switch ( type ) { case 1: @@ -1821,12 +1886,12 @@ static gboolean testapp_test_address_format_check_test() address_count++; } testapp_print("Choose address to be tested:[99:quit]\n"); - result_from_scanf = scanf("%d", &index); + if (0 >= scanf("%d", &index); if ( index == 99 ) break; testapp_print(">> [%d] Checking? (1:Yes, Other:No) [%s]\n", index, address_list[index]); - result_from_scanf = scanf("%d", &check_yn); + if (0 >= scanf("%d", &check_yn); if ( check_yn == 1 ) { pAddress = strdup(address_list[index]); if ( em_verify_email_address(pAddress, false, &err ) == true ) { @@ -1848,7 +1913,7 @@ static gboolean testapp_test_address_format_check_test() break; case 2: testapp_print("Input address: \n"); - result_from_scanf = scanf("%s", input_address); + if (0 >= scanf("%s", input_address); if ( em_verify_email_address(input_address, false, &err ) == true ) { testapp_print(">> Saving Succeeded : addr[%s]\n", input_address); } @@ -1870,9 +1935,9 @@ static gboolean testapp_test_get_max_mail_count() int err = EMAIL_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); + testapp_print("\n\t>>>>> email_get_max_mail_count() return [%d][%d]\n\n", max_count, err); - return false; + return TRUE; } #include "email-storage.h" @@ -1900,7 +1965,6 @@ static gboolean testapp_test_get_address_info_list() char buf[1024]; int i = 0; int mail_id = 0; - int result_from_scanf = 0; email_address_info_list_t *address_info_list= NULL; email_address_info_t *p_address_info = NULL; GList *list = NULL; @@ -1908,7 +1972,8 @@ static gboolean testapp_test_get_address_info_list() memset(buf, 0x00, sizeof(buf)); testapp_print("\n > Enter mail_id: "); - result_from_scanf = scanf("%d",&mail_id); + if (0 >= scanf("%d",&mail_id)) + testapp_print("Invalid input. "); email_get_address_info_list(mail_id, &address_info_list); @@ -1953,102 +2018,6 @@ static gboolean testapp_test_get_address_info_list() return TRUE; } -static gboolean testapp_test_search_mail_on_server() -{ - testapp_print(" >>> testapp_test_search_mail_on_server : Entered \n"); - - int err_code = EMAIL_ERROR_NONE; - int account_id = 0; - int mailbox_id = 0; - int search_key_value_integer = 0; - int result_from_scanf = 0; - email_search_filter_type search_filter_type = 0; - email_search_filter_t search_filter; - int handle = 0; - time_t current_time = 0; - char search_key_value_string[MAX_EMAIL_ADDRESS_LENGTH]; - - testapp_print("input account id : "); - result_from_scanf = scanf("%d",&account_id); - - testapp_print("input mailbox id : "); - result_from_scanf = scanf("%d", &mailbox_id); - - testapp_print( - " EMAIL_SEARCH_FILTER_TYPE_MESSAGE_NO = 1, ( integet type ) \n" - " EMAIL_SEARCH_FILTER_TYPE_UID = 2, ( integet type ) \n" - " EMAIL_SEARCH_FILTER_TYPE_BCC = 7, ( string type ) \n" - " EMAIL_SEARCH_FILTER_TYPE_CC = 9, ( string type ) \n" - " EMAIL_SEARCH_FILTER_TYPE_FROM = 10, ( string type ) \n" - " EMAIL_SEARCH_FILTER_TYPE_KEYWORD = 11, ( string type ) \n" - " EMAIL_SEARCH_FILTER_TYPE_SUBJECT = 13, ( string type ) \n" - " EMAIL_SEARCH_FILTER_TYPE_TO = 15, ( string type ) \n" - " EMAIL_SEARCH_FILTER_TYPE_SIZE_LARSER = 16, ( integet type ) \n" - " EMAIL_SEARCH_FILTER_TYPE_SIZE_SMALLER = 17, ( integet type ) \n" - " EMAIL_SEARCH_FILTER_TYPE_SENT_DATE_BEFORE = 20, ( time type ) \n" - " EMAIL_SEARCH_FILTER_TYPE_SENT_DATE_ON = 21, ( time type ) \n" - " EMAIL_SEARCH_FILTER_TYPE_SENT_DATE_SINCE = 22, ( time type ) \n" - " EMAIL_SEARCH_FILTER_TYPE_FLAGS_ANSWERED = 26, ( integet type ) \n" - " EMAIL_SEARCH_FILTER_TYPE_FLAGS_DELETED = 28, ( integet type ) \n" - " EMAIL_SEARCH_FILTER_TYPE_FLAGS_DRAFT = 30, ( integet type ) \n" - " EMAIL_SEARCH_FILTER_TYPE_FLAGS_FLAGED = 32, ( integet type ) \n" - " EMAIL_SEARCH_FILTER_TYPE_FLAGS_RECENT = 34, ( integet type ) \n" - " EMAIL_SEARCH_FILTER_TYPE_FLAGS_SEEN = 36, ( integet type ) \n" - " EMAIL_SEARCH_FILTER_TYPE_MESSAGE_ID = 43, ( string type ) \n"); - testapp_print("input search filter type : "); - result_from_scanf = scanf("%d", (int*)&search_filter_type); - - search_filter.search_filter_type = search_filter_type; - - switch(search_filter_type) { - case EMAIL_SEARCH_FILTER_TYPE_MESSAGE_NO : - case EMAIL_SEARCH_FILTER_TYPE_UID : - case EMAIL_SEARCH_FILTER_TYPE_SIZE_LARSER : - case EMAIL_SEARCH_FILTER_TYPE_SIZE_SMALLER : - case EMAIL_SEARCH_FILTER_TYPE_FLAGS_ANSWERED : - case EMAIL_SEARCH_FILTER_TYPE_FLAGS_DELETED : - case EMAIL_SEARCH_FILTER_TYPE_FLAGS_DRAFT : - case EMAIL_SEARCH_FILTER_TYPE_FLAGS_FLAGED : - case EMAIL_SEARCH_FILTER_TYPE_FLAGS_RECENT : - case EMAIL_SEARCH_FILTER_TYPE_FLAGS_SEEN : - testapp_print("input search filter key value : "); - result_from_scanf = scanf("%d", &search_key_value_integer); - search_filter.search_filter_key_value.integer_type_key_value = search_key_value_integer; - break; - - case EMAIL_SEARCH_FILTER_TYPE_BCC : - case EMAIL_SEARCH_FILTER_TYPE_CC : - case EMAIL_SEARCH_FILTER_TYPE_FROM : - case EMAIL_SEARCH_FILTER_TYPE_KEYWORD : - case EMAIL_SEARCH_FILTER_TYPE_SUBJECT : - case EMAIL_SEARCH_FILTER_TYPE_TO : - case EMAIL_SEARCH_FILTER_TYPE_MESSAGE_ID : - testapp_print("input search filter key value : "); - result_from_scanf = scanf("%s", search_key_value_string); - search_filter.search_filter_key_value.string_type_key_value = search_key_value_string; - break; - - case EMAIL_SEARCH_FILTER_TYPE_SENT_DATE_BEFORE : - case EMAIL_SEARCH_FILTER_TYPE_SENT_DATE_ON : - case EMAIL_SEARCH_FILTER_TYPE_SENT_DATE_SINCE : - time(¤t_time); - /* TODO : write codes for converting string to time */ - /* search_filter.search_filter_key_value.time_type_key_value = search_key_value_string; */ - search_filter.search_filter_key_value.time_type_key_value = current_time; - break; - default : - testapp_print("Invalid filter type [%d]", search_filter_type); - return FALSE; - } - - if( (err_code = email_search_mail_on_server(account_id, mailbox_id, &search_filter,1, &handle)) != EMAIL_ERROR_NONE) { - testapp_print("email_search_mail_on_server failed [%d]", err_code); - } - - testapp_print(" >>> testapp_test_search_mail_on_server : END \n"); - return TRUE; -} - static gboolean testapp_test_add_mail_to_search_result_box() { int i = 0; @@ -2056,7 +2025,6 @@ static gboolean testapp_test_add_mail_to_search_result_box() int from_eas = 0; int attachment_count = 0; int err = EMAIL_ERROR_NONE; - int result_from_scanf = 0; char arg[50] = { 0 , }; char *body_file_path = MAIL_TEMP_BODY; email_mailbox_t *mailbox_data = NULL; @@ -2066,7 +2034,8 @@ static gboolean testapp_test_add_mail_to_search_result_box() FILE *body_file = NULL; testapp_print("\n > Enter account id : "); - result_from_scanf = scanf("%d", &account_id); + if (0 >= scanf("%d", &account_id)) + testapp_print("Invalid input. "); email_get_mailbox_by_mailbox_type(account_id, EMAIL_MAILBOX_TYPE_SEARCH_RESULT, &mailbox_data); @@ -2074,7 +2043,8 @@ static gboolean testapp_test_add_mail_to_search_result_box() memset(test_mail_data, 0x00, sizeof(email_mail_data_t)); testapp_print("\n From EAS? [0/1]> "); - result_from_scanf = scanf("%d", &from_eas); + if (0 >= scanf("%d", &from_eas)) + testapp_print("Invalid input. "); test_mail_data->account_id = account_id; test_mail_data->save_status = 1; @@ -2098,12 +2068,14 @@ static gboolean testapp_test_add_mail_to_search_result_box() fclose(body_file); testapp_print(" > Attach file? [0/1] : "); - result_from_scanf = scanf("%d",&attachment_count); + if (0 >= scanf("%d",&attachment_count)) + testapp_print("Invalid input. "); if ( attachment_count ) { memset(arg, 0x00, 50); testapp_print("\n > Enter attachment name : "); - result_from_scanf = scanf("%s", arg); + if (0 >= scanf("%s", arg)) + testapp_print("Invalid input. "); attachment_data = malloc(sizeof(email_attachment_data_t)); @@ -2111,7 +2083,8 @@ static gboolean testapp_test_add_mail_to_search_result_box() memset(arg, 0x00, 50); testapp_print("\n > Enter attachment absolute path : "); - result_from_scanf = scanf("%s",arg); + if (0 >= scanf("%s",arg)) + testapp_print("Invalid input. "); attachment_data->attachment_path = strdup(arg); attachment_data->save_status = 1; @@ -2119,7 +2092,8 @@ static gboolean testapp_test_add_mail_to_search_result_box() } testapp_print("\n > Meeting Request? [0: no, 1: yes (request from server), 2: yes (response from local)]"); - result_from_scanf = scanf("%d", (int*)&(test_mail_data->meeting_request_status)); + if (0 >= scanf("%d", (int*)&(test_mail_data->meeting_request_status))) + testapp_print("Invalid input. "); if ( test_mail_data->meeting_request_status == 1 || test_mail_data->meeting_request_status == 2 ) { @@ -2169,21 +2143,24 @@ static gboolean testapp_test_add_mail_to_search_result_box() static gboolean testapp_test_email_parse_mime_file() { - email_mail_data_t *mail_data = NULL; - email_attachment_data_t *mail_attachment_data = NULL; int i = 0; int attachment_count = 0; + int output_attachment_count = 0; int verify = 0; int err = EMAIL_ERROR_NONE; - int result_from_scanf = 0; char eml_file_path[255] = {0, }; struct tm *struct_time; + email_mail_data_t *mail_data = NULL; + email_attachment_data_t *mail_attachment_data = NULL; + email_mail_data_t *output_mail_data = NULL; + email_attachment_data_t *output_mail_attachment_data = NULL; + testapp_print("Input eml file path : "); - result_from_scanf = scanf("%s", eml_file_path); + if (0 >= scanf("%s", eml_file_path)) + testapp_print("Invalid input. "); - if ((err = email_parse_mime_file(eml_file_path, &mail_data, &mail_attachment_data, &attachment_count)) != EMAIL_ERROR_NONE) - { + if ((err = email_parse_mime_file(eml_file_path, &mail_data, &mail_attachment_data, &attachment_count)) != EMAIL_ERROR_NONE) { testapp_print("email_parse_mime_file failed : [%d]\n", err); return false; } @@ -2204,6 +2181,7 @@ static gboolean testapp_test_email_parse_mime_file() testapp_print("Return-Path: %s\n", mail_data->full_address_return); testapp_print("To: %s\n", mail_data->full_address_to); testapp_print("Subject: %s\n", mail_data->subject); + testapp_print("Priority: %d\n", mail_data->priority); testapp_print("From: %s\n", mail_data->full_address_from); testapp_print("Reply-To: %s\n", mail_data->full_address_reply); testapp_print("Sender: %s\n", mail_data->email_address_sender); @@ -2211,27 +2189,35 @@ static gboolean testapp_test_email_parse_mime_file() testapp_print("attachment_count: %d\n", mail_data->attachment_count); testapp_print("SMIME type : %d\n", mail_data->smime_type); testapp_print("inline content count : %d\n", mail_data->inline_content_count); + testapp_print("mail_size : %d\n", mail_data->mail_size); testapp_print("download_body_status : %d\n", mail_data->body_download_status); for (i = 0;i < attachment_count ; i++) { + testapp_print("%d attachment\n", i); testapp_print("attachment_id: %d\n", mail_attachment_data[i].attachment_id); + testapp_print("attachment_size: %d\n", mail_attachment_data[i].attachment_size); testapp_print("inline_attachment_status: %d\n", mail_attachment_data[i].inline_content_status); testapp_print("attachment_name: %s\n", mail_attachment_data[i].attachment_name); testapp_print("attachment_path: %s\n", mail_attachment_data[i].attachment_path); + testapp_print("attachment_save_status: %d\n", mail_attachment_data[i].save_status); + testapp_print("content_id: %s\n", mail_attachment_data[i].content_id); testapp_print("mailbox_id: %d\n", mail_attachment_data[i].mailbox_id); } testapp_print("Success : Open eml file\n"); - if (mail_data->smime_type == EMAIL_SMIME_SIGNED) { - if (!email_verify_signature_ex(mail_data, mail_attachment_data, attachment_count, &verify)) { - testapp_print("email_verify_signature_ex failed\n"); - } - + if (mail_data->smime_type != EMAIL_SMIME_NONE) { + if (mail_data->smime_type == EMAIL_SMIME_SIGNED || mail_data->smime_type == EMAIL_PGP_SIGNED) { + if (!email_verify_signature_ex(mail_data, mail_attachment_data, attachment_count, &verify)) + testapp_print("email_verify_signature_ex failed\n"); + } else { + if ((err = email_get_decrypt_message_ex(mail_data, mail_attachment_data, attachment_count, &output_mail_data, &output_mail_attachment_data, &output_attachment_count)) != EMAIL_ERROR_NONE) + testapp_print("email_get_decrypt_message_ex failed\n"); + } + testapp_print("verify : [%d]\n", verify); } - if ((err = email_delete_parsed_data(mail_data)) != EMAIL_ERROR_NONE) { testapp_print("email_delete_eml_data failed : [%d]\n", err); @@ -2258,27 +2244,18 @@ static gboolean testapp_test_email_write_mime_file() { int err = EMAIL_ERROR_NONE; int mail_id = 0; - int ret_scanf = 0; - int is_file_path = 0; int attachment_count = 0; - int account_id = 0; char *file_path = NULL; email_mail_data_t *mail_data = NULL; email_attachment_data_t *mail_attachment_data = NULL; - testapp_print("Is file path (0 or 1): "); - ret_scanf = scanf("%d", &is_file_path); - - if (is_file_path) { - file_path = malloc(512); - memset(file_path, 0x00, 512); - testapp_print("Input output file path : "); - ret_scanf = scanf("%s", file_path); - } - testapp_print("Input mail id : "); - ret_scanf = scanf("%d", &mail_id); + file_path = malloc(512); + memset(file_path, 0x00, 512); + testapp_print("Input mail id : "); + if (0 >= scanf("%d", &mail_id)) + testapp_print("Invalid input. "); err = email_get_mail_data(mail_id, &mail_data); if (err != EMAIL_ERROR_NONE || mail_data == NULL) { @@ -2292,10 +2269,7 @@ static gboolean testapp_test_email_write_mime_file() return false; } - testapp_print("Input Account id : "); - ret_scanf = scanf("%d", &account_id); - - mail_data->account_id = account_id; + snprintf(file_path, 512, "/opt/usr/data/email/.email_data/tmp/%d_%8d.eml", mail_id, (int)time(NULL)); err = email_write_mime_file(mail_data, mail_attachment_data, attachment_count, &file_path); if (err != EMAIL_ERROR_NONE) { @@ -2320,12 +2294,12 @@ static gboolean testapp_test_email_write_mime_file() static gboolean testapp_test_smime_verify_signature() { int mail_id = 0; - int ret_scanf = 0; int verify = 0; int err = EMAIL_ERROR_NONE; testapp_print("input mail_id :"); - ret_scanf = scanf("%d", &mail_id); + if (0 >= scanf("%d", &mail_id)) + testapp_print("Invalid input. "); err = email_verify_signature(mail_id, &verify); if (err != EMAIL_ERROR_NONE) { @@ -2337,6 +2311,208 @@ static gboolean testapp_test_smime_verify_signature() return true; } +static gboolean testapp_test_email_add_mail_with_multiple_recipient() +{ + int i = 0; + int account_id = 0; + int err = EMAIL_ERROR_NONE; +// int smime_type = 0; + int recipient_addresses_count = 0; + char *recipient_addresses = NULL; + char recipient_address[234] = { 0, }; + char from_address[300] = { 0 , }; + const char *body_file_path = MAIL_TEMP_BODY; + email_account_t *account_data = NULL; + email_mailbox_t *mailbox_data = NULL; + email_mail_data_t *test_mail_data = NULL; + FILE *body_file; + + testapp_print("\n > Enter account id : "); + if (0 >= scanf("%d", &account_id)) + testapp_print("Invalid input. "); + + testapp_print("\n > Enter recipient address count : "); + if (0 >= scanf("%d", &recipient_addresses_count)) + testapp_print("Invalid input. "); + + if(recipient_addresses_count < 1) + return TRUE; + + recipient_addresses = malloc(sizeof(char) * 234 * recipient_addresses_count); + + for (i = 0; i < recipient_addresses_count; i++) { + snprintf(recipient_address, 234, "\"mailtest%05d\" <mailtest%05d@a1234567890b1234567890.com>; ", i, i); + strcat(recipient_addresses, recipient_address); + } + + email_get_account(account_id, GET_FULL_DATA_WITHOUT_PASSWORD, &account_data); + + email_get_mailbox_by_mailbox_type(account_id, EMAIL_MAILBOX_TYPE_OUTBOX, &mailbox_data); + + test_mail_data = malloc(sizeof(email_mail_data_t)); + memset(test_mail_data, 0x00, sizeof(email_mail_data_t)); + + SNPRINTF(from_address, 300, "<%s>", account_data->user_email_address); + + test_mail_data->account_id = account_id; + test_mail_data->save_status = EMAIL_MAIL_STATUS_SEND_DELAYED; + test_mail_data->body_download_status = 1; + test_mail_data->flags_seen_field = 1; + test_mail_data->file_path_plain = strdup(body_file_path); + test_mail_data->mailbox_id = mailbox_data->mailbox_id; + test_mail_data->mailbox_type = mailbox_data->mailbox_type; + test_mail_data->full_address_from = strdup(from_address); + test_mail_data->full_address_to = recipient_addresses; + test_mail_data->subject = strdup("Read receipt request from TIZEN"); + test_mail_data->remaining_resend_times = 3; + test_mail_data->report_status = EMAIL_MAIL_REQUEST_DSN | EMAIL_MAIL_REQUEST_MDN; + test_mail_data->smime_type = 0; + + body_file = fopen(body_file_path, "w"); + + testapp_print("\n body_file [%p]\n", body_file); + + if(body_file == NULL) { + testapp_print("\n fopen [%s]failed\n", body_file_path); + return FALSE; + } + + for(i = 0; i < 100; i++) + fprintf(body_file, "Mail sending Test. [%d]\n", i); + + fflush(body_file); + fclose(body_file); + + + if((err = email_add_mail(test_mail_data, NULL, 0, NULL, 0)) != EMAIL_ERROR_NONE) + testapp_print("email_add_mail failed. [%d]\n", err); + else + testapp_print("email_add_mail success.\n"); + + testapp_print("saved mail id = [%d]\n", test_mail_data->mail_id); + + email_free_mail_data(&test_mail_data, 1); + email_free_mailbox(&mailbox_data, 1); + email_free_account(&account_data, 1); + + return FALSE; +} + +static gboolean testapp_test_send_mails_every_x_minutes() +{ + int added_mail_id = 0; + int err = EMAIL_ERROR_NONE; + int handle = 0; + time_t time_to_send; + int i = 0; + int j = 0; + int account_id = 0; + int send_interval_in_minutes = 0; + int number_of_mails = 0; + char recipient_address[300] = { 0 , }; + char from_address[300] = { 0 , }; + char subject_form[1024] = { 0 , }; + const char *body_file_path = MAIL_TEMP_BODY; + struct tm *time_to_send_tm; + email_account_t *account_data = NULL; + email_mailbox_t *mailbox_data = NULL; + email_mail_data_t *test_mail_data = NULL; + FILE *body_file; + + testapp_print("\n > Enter account id : "); + if (0 >= scanf("%d", &account_id)) + testapp_print("Invalid input. "); + + testapp_print("\n > Enter recipient address : "); + if (0 >= scanf("%s", recipient_address)) + testapp_print("Invalid input. "); + + testapp_print("\n > Enter number of mails: "); + if (0 >= scanf("%d", &number_of_mails)) + testapp_print("Invalid input. "); + + testapp_print("\n > Enter send interval in minutes: "); + if (0 >= scanf("%d", &send_interval_in_minutes)) + testapp_print("Invalid input. "); + + email_get_account(account_id, GET_FULL_DATA_WITHOUT_PASSWORD, &account_data); + + email_get_mailbox_by_mailbox_type(account_id, EMAIL_MAILBOX_TYPE_OUTBOX, &mailbox_data); + + test_mail_data = malloc(sizeof(email_mail_data_t)); + memset(test_mail_data, 0x00, sizeof(email_mail_data_t)); + + SNPRINTF(from_address, 300, "<%s>", account_data->user_email_address); + + test_mail_data->account_id = account_id; + test_mail_data->save_status = EMAIL_MAIL_STATUS_SEND_DELAYED; + test_mail_data->body_download_status = 1; + test_mail_data->flags_seen_field = 1; + test_mail_data->file_path_plain = strdup(body_file_path); + test_mail_data->mailbox_id = mailbox_data->mailbox_id; + test_mail_data->mailbox_type = mailbox_data->mailbox_type; + test_mail_data->full_address_from = strdup(from_address); + test_mail_data->full_address_to = strdup(recipient_address); + test_mail_data->remaining_resend_times = 3; + test_mail_data->report_status = EMAIL_MAIL_REPORT_NONE; + + + for (i = 0; i < number_of_mails; i++) { + if (test_mail_data->subject) + free(test_mail_data->subject); + + time(&time_to_send); + time_to_send += (60 * send_interval_in_minutes) * (i + 1); + time_to_send_tm = localtime(&time_to_send); + + strftime(subject_form, 1024, "[%H:%M] TEST.", time_to_send_tm); + test_mail_data->subject = strdup(subject_form); + + body_file = fopen(body_file_path, "w"); + + testapp_print("\n body_file [%p]\n", body_file); + + if(body_file == NULL) { + testapp_print("\n fopen [%s]failed\n", body_file_path); + return FALSE; + } + + for(j = 0; j < 100; j++) + fprintf(body_file, "Mail sending Test. [%d]\n", j); + + fflush(body_file); + fclose(body_file); + + if((err = email_add_mail(test_mail_data, NULL, 0, NULL, 0)) != EMAIL_ERROR_NONE) { + testapp_print("email_add_mail failed. [%d]\n", err); + added_mail_id = 0; + } + else { + testapp_print("email_add_mail success.\n"); + added_mail_id = test_mail_data->mail_id; + } + + testapp_print("saved mail id = [%d]\n", added_mail_id); + + if(added_mail_id) { + testapp_print("Calling email_schedule_sending_mail...\n"); + + if( email_schedule_sending_mail(added_mail_id, time_to_send) < 0) { + testapp_print("email_schedule_sending_mail failed[%d]\n", err); + } + else { + testapp_print("Start sending. handle[%d]\n", handle); + } + } + } + + email_free_mail_data(&test_mail_data, 1); + email_free_mailbox(&mailbox_data, 1); + email_free_account(&account_data, 1); + + return TRUE; +} + /* internal functions */ static gboolean testapp_test_interpret_command (int menu_number) { @@ -2454,20 +2630,23 @@ static gboolean testapp_test_interpret_command (int menu_number) case 57: testapp_test_update_mail(); break; - case 58: - testapp_test_search_mail_on_server(); - break; case 59: testapp_test_add_mail_to_search_result_box(); break; case 60: testapp_test_email_parse_mime_file(); break; + case 61: + testapp_test_email_write_mime_file(); + break; case 62: testapp_test_smime_verify_signature(); break; - case 61: - testapp_test_email_write_mime_file(); + case 63: + testapp_test_email_add_mail_with_multiple_recipient(); + break; + case 64: + testapp_test_send_mails_every_x_minutes(); break; case 0: go_to_loop = FALSE; @@ -2483,13 +2662,13 @@ void testapp_mail_main() { gboolean go_to_loop = TRUE; int menu_number = 0; - int result_from_scanf = 0; while (go_to_loop) { testapp_show_menu(EMAIL_MAIL_MENU); testapp_show_prompt(EMAIL_MAIL_MENU); - result_from_scanf = scanf("%d", &menu_number); + if (0 >= scanf("%d", &menu_number)) + testapp_print("Invalid input"); go_to_loop = testapp_test_interpret_command (menu_number); } diff --git a/utilities/test-application/testapp-mailbox.c b/utilities/test-application/testapp-mailbox.c index 6caee04..5540da4 100755 --- a/utilities/test-application/testapp-mailbox.c +++ b/utilities/test-application/testapp-mailbox.c @@ -79,30 +79,34 @@ static gboolean testapp_test_add_mailbox() char arg[500]; int ret; int handle; - int result_from_scanf = 0; memset(&mailbox, 0, sizeof(email_mailbox_t)); memset(arg, 0x00, 500); testapp_print("\n> Enter mailbox name: "); - result_from_scanf = scanf("%s",arg); + if (0 >= scanf("%s",arg)) + testapp_print("Invalid input. "); mailbox.mailbox_name = strdup(arg); memset(arg, 0x00, 500); testapp_print("> Enter mailbox alias name: "); - result_from_scanf = scanf("%s",arg); + if (0 >= scanf("%s",arg)) + testapp_print("Invalid input. "); mailbox.alias = strdup(arg); testapp_print("> Enter account id: "); - result_from_scanf = scanf("%d", &account_id); + if (0 >= scanf("%d", &account_id)) + testapp_print("Invalid input. "); mailbox.account_id = account_id; testapp_print("> Enter local_yn (1/0): "); - result_from_scanf = scanf("%d", &local_yn); + if (0 >= scanf("%d", &local_yn)) + testapp_print("Invalid input. "); mailbox.local= local_yn; testapp_print("> Enter mailbox type: "); - result_from_scanf = scanf("%d", &mailbox_type); + if (0 >= scanf("%d", &mailbox_type)) + testapp_print("Invalid input. "); mailbox.mailbox_type= mailbox_type; mailbox.eas_data = strdup("EAS DATA TEST"); @@ -130,13 +134,14 @@ static gboolean testapp_test_delete_mailbox() int on_server = 0; int ret; int handle; - int result_from_scanf = 0; testapp_print("\n> Enter mailbox id:"); - result_from_scanf = scanf("%d", &mailbox_id); + if (0 >= scanf("%d", &mailbox_id)) + testapp_print("Invalid input"); testapp_print("> Enter on_server (1/0): "); - result_from_scanf = scanf("%d", &on_server); + if (0 >= scanf("%d", &on_server)) + testapp_print("Invalid input"); ret = email_delete_mailbox(mailbox_id, on_server, &handle); @@ -158,17 +163,19 @@ static gboolean testapp_test_rename_mailbox() char mailbox_name[500] = { 0, }; char mailbox_alias[500] = { 0, }; int err; - int result_from_scanf = 0; int handle = 0; testapp_print("> Enter mailbox id: "); - result_from_scanf = scanf("%d", &mailbox_id); + if (0 >= scanf("%d", &mailbox_id)) + testapp_print("Invalid input"); testapp_print("> Enter new mailbox name: "); - result_from_scanf = scanf("%s", mailbox_name); + if (0 >= scanf("%s", mailbox_name)) + testapp_print("Invalid input"); testapp_print("> Enter new mailbox name: "); - result_from_scanf = scanf("%s", mailbox_alias); + if (0 >= scanf("%s", mailbox_alias)) + testapp_print("Invalid input"); if ( (err = email_rename_mailbox(mailbox_id, mailbox_name, mailbox_alias, true, &handle)) < 0) { @@ -185,10 +192,10 @@ static gboolean testapp_test_get_imap_mailbox_list() { int account_id = 0; int handle = 0; - int result_from_scanf = 0; testapp_print("> Enter account id: "); - result_from_scanf = scanf("%d", &account_id); + if (0 >= scanf("%d", &account_id)) + testapp_print("Invalid input"); if( email_sync_imap_mailbox_list(account_id, &handle) < 0) testapp_print("email_sync_imap_mailbox_list failed"); @@ -201,13 +208,14 @@ static gboolean testapp_test_set_local_mailbox() { int mailbox_id = 0; int is_local_mailbox = 0; - int result_from_scanf = 0; testapp_print("> Enter mailbox id: "); - result_from_scanf = scanf("%d", &mailbox_id); + if (0 >= scanf("%d", &mailbox_id)) + testapp_print("Invalid input"); testapp_print("> Enter local: "); - result_from_scanf = scanf("%d", &is_local_mailbox); + if (0 >= scanf("%d", &is_local_mailbox)) + testapp_print("Invalid input"); if( email_set_local_mailbox(mailbox_id, is_local_mailbox) < 0) testapp_print("email_set_local_mailbox failed"); @@ -224,16 +232,18 @@ static gboolean testapp_test_delete_mailbox_ex() int on_server = 0; int handle = 0; int i = 0; - int result_from_scanf = 0; testapp_print("\n > Enter account_id: "); - result_from_scanf = scanf("%d", &account_id); + if (0 >= scanf("%d", &account_id)) + testapp_print("Invalid input"); testapp_print("\n > Enter mailbox_id_count: "); - result_from_scanf = scanf("%d", &mailbox_id_count); + if (0 >= scanf("%d", &mailbox_id_count)) + testapp_print("Invalid input"); testapp_print("\n > Enter on_server: "); - result_from_scanf = scanf("%d", &on_server); + if (0 >= scanf("%d", &on_server)) + testapp_print("Invalid input"); mailbox_id_count = (mailbox_id_count < 5000)?mailbox_id_count:5000; @@ -243,7 +253,8 @@ static gboolean testapp_test_delete_mailbox_ex() for(i = 0; i < mailbox_id_count; i++) { testapp_print("\n > Enter mailbox id: "); - result_from_scanf = scanf("%d", (mailbox_id_array + i)); + if (0 >= scanf("%d", (mailbox_id_array + i))) + testapp_print("Invalid input"); } err = email_delete_mailbox_ex(account_id, mailbox_id_array, mailbox_id_count, on_server, &handle); @@ -260,15 +271,16 @@ static gboolean testapp_test_get_mailbox_by_type() int account_id =0; int err_code = EMAIL_ERROR_NONE; - int result_from_scanf = 0; email_mailbox_t *mailbox =NULL; email_mailbox_type_e mailbox_type =0; testapp_print("\n > Enter account id: "); - result_from_scanf = scanf("%d", &account_id); + if (0 >= scanf("%d", &account_id)) + testapp_print("Invalid input"); testapp_print("\n > Enter mailbox_type: "); - result_from_scanf = scanf("%d", (int*)&mailbox_type); + if (0 >= scanf("%d", (int*)&mailbox_type)) + testapp_print("Invalid input"); 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); @@ -286,13 +298,14 @@ static gboolean testapp_test_set_mailbox_type() int mailbox_id = 0; int mailbox_type = 0; int err_code = EMAIL_ERROR_NONE; - int result_from_scanf = 0; testapp_print("\n > Enter mailbox id : "); - result_from_scanf = scanf("%d", &mailbox_id); + if (0 >= scanf("%d", &mailbox_id)) + testapp_print("Invalid input"); testapp_print("\n > Enter mailbox type : "); - result_from_scanf = scanf("%d", &mailbox_type); + if (0 >= scanf("%d", &mailbox_type)) + testapp_print("Invalid input"); if( (err_code = email_set_mailbox_type(mailbox_id, mailbox_type) ) != EMAIL_ERROR_NONE) { testapp_print("\nemail_set_mailbox_type error : %d\n", err_code); @@ -307,16 +320,18 @@ static gboolean testapp_test_set_mail_slot_size () int mailbox_id = 0; int mail_slot_size = 0; int err_code = EMAIL_ERROR_NONE; - int result_from_scanf = 0; testapp_print("\n > Enter account id (0: All account): "); - result_from_scanf = scanf("%d", &account_id); + if (0 >= scanf("%d", &account_id)) + testapp_print("Invalid input"); testapp_print("\n> Enter mailbox id (0 : All mailboxes):"); - result_from_scanf = scanf("%d", &mailbox_id); + if (0 >= scanf("%d", &mailbox_id)) + testapp_print("Invalid input"); testapp_print("\n > Enter mailbox slot size: "); - result_from_scanf = scanf("%d", &mail_slot_size); + if (0 >= scanf("%d", &mail_slot_size)) + testapp_print("Invalid input"); if( (err_code = email_set_mail_slot_size(account_id, mailbox_id, mail_slot_size) ) < 0) { testapp_print(" testapp_test_set_mail_slot_size error : %d\n", err_code); @@ -328,16 +343,17 @@ static gboolean testapp_test_set_mail_slot_size () static gboolean testapp_test_get_mailbox_list () { - int result_from_scanf = 0; int account_id =0; int mailbox_sync_type; int count = 0; int error_code = EMAIL_ERROR_NONE; email_mailbox_t *mailbox_list=NULL; testapp_print("\n > Enter account id: "); - result_from_scanf = scanf("%d", &account_id); + if (0 >= scanf("%d", &account_id)) + testapp_print("Invalid input"); testapp_print("\n > Enter mailbox_sync_type\n[-1 :for all mailboxes, 0 : for mailboxes from server, 1 : local mailboxes\n : "); - result_from_scanf = scanf("%d", &mailbox_sync_type); + if (0 >= scanf("%d", &mailbox_sync_type)) + testapp_print("Invalid input"); 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); @@ -361,17 +377,18 @@ static gboolean testapp_test_get_mailbox_list () static gboolean testapp_test_get_mailbox_list_by_keyword () { - int result_from_scanf = 0; int account_id =0; int count = 0; char keyword[500] = { 0, }; int error_code = EMAIL_ERROR_NONE; email_mailbox_t *mailbox_list = NULL; testapp_print("\n > Enter account id: "); - result_from_scanf = scanf("%d", &account_id); + if (0 >= scanf("%d", &account_id)) + testapp_print("Invalid input"); testapp_print("> Enter keyword: "); - result_from_scanf = scanf("%s", keyword); + if (0 >= scanf("%s", keyword)) + testapp_print("Invalid input"); if ((error_code = email_get_mailbox_list_by_keyword(account_id, keyword, &mailbox_list, &count)) < 0) { testapp_print(" email_get_mailbox_list_by_keyword error %d\n", error_code); @@ -388,16 +405,17 @@ static gboolean testapp_test_get_mailbox_list_by_keyword () static gboolean testapp_test_sync_mailbox() { - int result_from_scanf = 0; int account_id = 0; int handle = 0; int mailbox_id = 0; testapp_print("\n > Enter Account id (0: for all account) : "); - result_from_scanf = scanf("%d",&account_id); + if (0 >= scanf("%d",&account_id)) + testapp_print("Invalid input"); testapp_print("\n > Enter Mailbox id (0: for all mailboxes) : "); - result_from_scanf = scanf("%d",&mailbox_id); + if (0 >= scanf("%d",&mailbox_id)) + testapp_print("Invalid input"); if(account_id == ALL_ACCOUNT) { if(email_sync_header_for_all_account(&handle) < 0) @@ -417,11 +435,11 @@ static gboolean testapp_test_sync_mailbox() static gboolean testapp_test_stamp_sync_time() { - int result_from_scanf; int input_mailbox_id = 0; testapp_print("\n > Enter Mailbox id : "); - result_from_scanf = scanf("%d",&input_mailbox_id); + if (0 >= scanf("%d",&input_mailbox_id)) + testapp_print("Invalid input"); email_stamp_sync_time_of_mailbox(input_mailbox_id); @@ -436,18 +454,19 @@ static gboolean testapp_test_rename_mailbox_ex() char mailbox_alias[500] = { 0, }; char eas_data[500] = "OK. Done"; int err; - int result_from_scanf = 0; int handle = 0; testapp_print("> Enter mailbox id: "); - result_from_scanf = scanf("%d", &mailbox_id); + if (0 >= scanf("%d", &mailbox_id)) + testapp_print("Invalid input. "); testapp_print("> Enter new mailbox name: "); - result_from_scanf = scanf("%s", mailbox_name); + if (0 >= scanf("%s", mailbox_name)) + testapp_print("Invalid input. "); testapp_print("> Enter new mailbox alias: "); - result_from_scanf = scanf("%s", mailbox_alias); - + if (0 >= scanf("%s", mailbox_alias)) + testapp_print("Invalid input. "); if ( (err = email_rename_mailbox_ex(mailbox_id, mailbox_name, mailbox_alias, eas_data, strlen(eas_data), false, &handle)) < 0) { testapp_print("\n email_rename_mailbox failed[%d]\n", err); @@ -533,13 +552,13 @@ void email_test_mailbox_main() { gboolean go_to_loop = TRUE; int menu_number = 0; - int result_from_scanf = 0; while (go_to_loop) { testapp_show_menu (EMAIL_MAILBOX_MENU); testapp_show_prompt (EMAIL_MAILBOX_MENU); - result_from_scanf = scanf("%d", &menu_number); + if (0 >= scanf("%d", &menu_number)) + testapp_print("Invalid input. "); go_to_loop = testapp_test_interpret_command (menu_number); } diff --git a/utilities/test-application/testapp-others.c b/utilities/test-application/testapp-others.c index e24d32e..d108870 100755 --- a/utilities/test-application/testapp-others.c +++ b/utilities/test-application/testapp-others.c @@ -54,19 +54,28 @@ static gboolean testapp_test_cancel_job () { int account_id = 0; int handle = 0; - int result_from_scanf = 0; testapp_print("\n > Enter account_id (0: all account): "); - result_from_scanf = scanf("%d", &account_id); + if (0 >= scanf("%d", &account_id)) + testapp_print("Invalid input. "); testapp_print("\n > Enter handle: "); - result_from_scanf = scanf("%d", &handle); + if (0 >= scanf("%d", &handle)) + testapp_print("Invalid input. "); if(email_cancel_job(account_id, handle, EMAIL_CANCELED_BY_USER) < 0) testapp_print("email_cancel_job failed..!"); return FALSE; } +static gboolean testapp_test_init_storage() +{ + if(email_init_storage() < 0) + testapp_print("email_init_storaege failed..!"); + + return FALSE; +} + static gboolean testapp_test_set_dnet_proper_profile_type() { testapp_print("NOT Support\n"); @@ -83,12 +92,12 @@ static gboolean testapp_test_get_dnet_proper_profile_type() static gboolean testapp_test_get_preview_text_from_file() { - int result_from_scanf; char *preview_buffer = NULL; char html_file_path[1024] = { 0, }; testapp_print("\n > Enter file path : "); - result_from_scanf = scanf("%s", html_file_path); + if (0 >= scanf("%s", html_file_path)) + testapp_print("Invalid input. "); emcore_get_preview_text_from_file(NULL, html_file_path, 1024, &preview_buffer); @@ -361,10 +370,10 @@ static gboolean email_test_dtt_Datastore_C() static gboolean testapp_test_show_user_message() { int mail_id; - int result_from_scanf = 0; testapp_print("\n > Enter mail id : "); - result_from_scanf = scanf("%d", &mail_id); + if (0 >= scanf("%d", &mail_id)) + testapp_print("Invalid input. "); email_show_user_message(mail_id, EMAIL_ACTION_SEND_MAIL, EMAIL_ERROR_NETWORK_NOT_AVAILABLE); return FALSE; @@ -373,11 +382,11 @@ static gboolean testapp_test_show_user_message() static gboolean testapp_test_get_mime_entity() { char mime_path[512] = {0, }; - int result_from_scanf = 0; char *mime_entity = NULL; testapp_print("\n > Enter mime path for parsing : "); - result_from_scanf = scanf("%s", mime_path); + if (0 >= scanf("%s", mime_path)) + testapp_print("Invalid input. "); email_get_mime_entity(mime_path, &mime_entity); @@ -387,15 +396,32 @@ static gboolean testapp_test_get_mime_entity() static gboolean testapp_test_query_smtp_mail_size_limit() { - int result_from_scanf = 0; int account_id = 0; testapp_print("\n > Enter account id : "); - result_from_scanf = scanf("%d", &account_id); + if (0 >= scanf("%d", &account_id)) + testapp_print("Invalid input. "); email_query_smtp_mail_size_limit(account_id, NULL); return true; } +static gboolean testapp_test_verify_email_address() +{ + int err = EMAIL_ERROR_NONE; + char email_address[512] = {0, }; + + testapp_print("\n > Enter mime path for parsing : "); + if (0 >= scanf("%s", email_address)) + testapp_print("Invalid input. "); + + err = email_verify_email_address(email_address); + + testapp_print("\nemail_verify_email_address returns [%d]\n", err); + return true; +} + + + static gboolean testapp_test_interpret_command (int menu_number) { gboolean go_to_loop = TRUE; @@ -404,6 +430,9 @@ static gboolean testapp_test_interpret_command (int menu_number) case 1: testapp_test_ping_service(); break; + case 2: + testapp_test_init_storage(); + break; case 3: testapp_test_cancel_job (); break; @@ -439,6 +468,9 @@ static gboolean testapp_test_interpret_command (int menu_number) case 17: testapp_test_query_smtp_mail_size_limit(); break; + case 18: + testapp_test_verify_email_address(); + break; case 0: go_to_loop = FALSE; break; @@ -453,13 +485,13 @@ void testapp_others_main() { gboolean go_to_loop = TRUE; int menu_number = 0; - int result_from_scanf = 0; while (go_to_loop) { testapp_show_menu (EMAIL_OTHERS_MENU); testapp_show_prompt (EMAIL_OTHERS_MENU); - result_from_scanf = scanf ("%d", &menu_number); + if (0 >= scanf ("%d", &menu_number)) + testapp_print("Invalid input. "); go_to_loop = testapp_test_interpret_command (menu_number); } diff --git a/utilities/test-application/testapp-rule.c b/utilities/test-application/testapp-rule.c index 9cb6519..e963b2e 100755 --- a/utilities/test-application/testapp-rule.c +++ b/utilities/test-application/testapp-rule.c @@ -45,38 +45,44 @@ static gboolean testapp_test_add_rule() int type = 0; int flag = 0; char arg[500]; - int result_from_scanf = 0; rule = malloc(sizeof(email_rule_t)); testapp_print("> Enter account id: "); - result_from_scanf = scanf("%d", &account_id); + if (0 >= scanf("%d", &account_id)) + testapp_print("Invalid input. "); rule->account_id = account_id; testapp_print("> Enter Type(FROM - 1 / SUBJECT - 2): "); - result_from_scanf = scanf("%d", &type); + if (0 >= scanf("%d", &type)) + testapp_print("Invalid input. "); rule->type= type; memset(arg, 0x00, 500); testapp_print("\n> Enter Filtering Value:"); - result_from_scanf = scanf("%s",arg); + if (0 >= scanf("%s",arg)) + testapp_print("Invalid input. "); rule->value= strdup(arg); testapp_print("> Enter Action(MOVE - 1, BLOCK - 2, DELETE - 3): "); - result_from_scanf = scanf("%d", &action); + if (0 >= scanf("%d", &action)) + testapp_print("Invalid input. "); rule->faction= action; if (action == 1) { testapp_print("\n> Enter target mailbox id:"); - result_from_scanf = scanf("%d", &target_mailbox_id); + if (0 >= scanf("%d", &target_mailbox_id)) + testapp_print("Invalid input. "); rule->target_mailbox_id = target_mailbox_id; } - testapp_print("> Enter Flag1 value: "); - result_from_scanf = scanf("%d", &flag); + testapp_print("> Enter Flag1 value [On/Off]: "); + if (0 >= scanf("%d", &flag)) + testapp_print("Invalid input. "); rule->flag1= flag; - testapp_print("> Enter Flag2 value: "); - result_from_scanf = scanf("%d", &flag); + testapp_print("> Enter Flag2 value [0:Exactly same as, 1:Include, 2:Compare Domain] : "); + if (0 >= scanf("%d", &flag)) + testapp_print("Invalid input. "); rule->flag2= flag; if (email_add_rule(rule) < 0) @@ -94,11 +100,11 @@ static gboolean testapp_test_add_rule() static gboolean testapp_test_delete_rule() { - int result_from_scanf = 0; int filter_id = 0; testapp_print("> Enter filter id: "); - result_from_scanf = scanf("%d", &filter_id); + if (0 >= scanf("%d", &filter_id)) + testapp_print("Invalid input. "); if(email_delete_rule(filter_id) < 0) testapp_print("email_delete_rule failed..! "); @@ -109,7 +115,6 @@ static gboolean testapp_test_delete_rule() static gboolean testapp_test_update_rule() { - int result_from_scanf = 0; email_rule_t* rule = NULL; int account_id = 0; int target_mailbox_id = 0; @@ -122,37 +127,45 @@ static gboolean testapp_test_update_rule() rule = malloc(sizeof(email_rule_t)); memset(rule,0X00,sizeof(email_rule_t)); testapp_print("> Enter filter id: "); - result_from_scanf = scanf("%d", &filter_id); + if (0 >= scanf("%d", &filter_id)) + testapp_print("Invalid input. "); testapp_print("> Enter account id: "); - result_from_scanf = scanf("%d", &account_id); + if (0 >= scanf("%d", &account_id)) + testapp_print("Invalid input. "); rule->account_id = account_id; testapp_print("> Enter Type(FROM - 1 / SUBJECT - 2): "); - result_from_scanf = scanf("%d", &type); + if (0 >= scanf("%d", &type)) + testapp_print("Invalid input. "); rule->type= type; memset(arg, 0x00, 500); testapp_print("\n> Enter Filtering Value:"); - result_from_scanf = scanf("%s",arg); + if (0 >= scanf("%s",arg)) + testapp_print("Invalid input. "); rule->value= strdup(arg); testapp_print("> Enter Action(MOVE - 1, BLOCK - 2, DELETE - 3): "); - result_from_scanf = scanf("%d", &action); + if (0 >= scanf("%d", &action)) + testapp_print("Invalid input. "); rule->faction= action; if (action == 1) { testapp_print("\n> Enter target mailbox id:"); - result_from_scanf = scanf("%d", &target_mailbox_id); + if (0 >= scanf("%d", &target_mailbox_id)) + testapp_print("Invalid input. "); rule->target_mailbox_id = target_mailbox_id; } testapp_print("> Enter Flag1 value: "); - result_from_scanf = scanf("%d", &flag); + if (0 >= scanf("%d", &flag)) + testapp_print("Invalid input. "); rule->flag1= flag; testapp_print("> Enter Flag2 value: "); - result_from_scanf = scanf("%d", &flag); + if (0 >= scanf("%d", &flag)) + testapp_print("Invalid input. "); rule->flag2= flag; if( !email_update_rule(filter_id, rule) < 0) @@ -168,10 +181,10 @@ static gboolean testapp_test_get_rule(void) { email_rule_t* rule = NULL; int filter_id = 0; - int result_from_scanf = 0; testapp_print("> Enter filter id: "); - result_from_scanf = scanf("%d", &filter_id); + if (0 >= scanf("%d", &filter_id)) + testapp_print("Invalid input. "); 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); @@ -242,13 +255,13 @@ void email_test_rule_main() { gboolean go_to_loop = TRUE; int menu_number = 0; - int result_from_scanf = 0; while (go_to_loop) { testapp_show_menu (EMAIL_RULE_MENU); testapp_show_prompt (EMAIL_RULE_MENU); - result_from_scanf = scanf("%d", &menu_number); + if (0 >= scanf("%d", &menu_number)) + testapp_print("Invalid input. "); go_to_loop = testapp_test_interpret_command (menu_number); } diff --git a/utilities/test-application/testapp-thread.c b/utilities/test-application/testapp-thread.c index 34b913e..cfad6e2 100755 --- a/utilities/test-application/testapp-thread.c +++ b/utilities/test-application/testapp-thread.c @@ -41,19 +41,20 @@ static gboolean testapp_test_move_thread() { int thread_id, move_always_flag; int target_mailbox_id; - int result; - int result_from_scanf = 0; testapp_print("\n > Enter thread_id: "); - result_from_scanf = scanf("%d", &thread_id); + if (0 >= scanf("%d", &thread_id)) + testapp_print("Invalid input. "); testapp_print("\n > Enter target_mailbox_id: "); - result_from_scanf = scanf("%d", &target_mailbox_id); + if (0 >= scanf("%d", &target_mailbox_id)) + testapp_print("Invalid input. "); testapp_print("\n > Enter move_always_flag: "); - result_from_scanf = scanf("%d", &move_always_flag); + if (0 >= scanf("%d", &move_always_flag)) + testapp_print("Invalid input. "); - result = email_move_thread_to_mailbox(thread_id, target_mailbox_id, move_always_flag); + email_move_thread_to_mailbox(thread_id, target_mailbox_id, move_always_flag); return FALSE; } @@ -61,16 +62,16 @@ static gboolean testapp_test_move_thread() static gboolean testapp_test_delete_thread() { int thread_id, delete_always_flag; - int result; - int result_from_scanf = 0; testapp_print("\n > Enter thread_id: "); - result_from_scanf = scanf("%d", &thread_id); + if (0 >= scanf("%d", &thread_id)) + testapp_print("Invalid input. "); testapp_print("\n > Enter delete_always_flag: "); - result_from_scanf = scanf("%d", &delete_always_flag); + if (0 >= scanf("%d", &delete_always_flag)) + testapp_print("Invalid input. "); - result = email_delete_thread(thread_id, delete_always_flag); + email_delete_thread(thread_id, delete_always_flag); return FALSE; } @@ -78,19 +79,20 @@ static gboolean testapp_test_delete_thread() static gboolean testapp_test_set_seen_flag_of_thread() { int thread_id, seen_flag, on_server; - int result; - int result_from_scanf = 0; testapp_print("\n > Enter thread_id: "); - result_from_scanf = scanf("%d", &thread_id); + if (0 >= scanf("%d", &thread_id)) + testapp_print("Invalid input. "); testapp_print("\n > Enter seen_flag: "); - result_from_scanf = scanf("%d", &seen_flag); + if (0 >= scanf("%d", &seen_flag)) + testapp_print("Invalid input. "); testapp_print("\n > Enter on_server: "); - result_from_scanf = scanf("%d", &on_server); + if (0 >= scanf("%d", &on_server)) + testapp_print("Invalid input. "); - result = email_modify_seen_flag_of_thread(thread_id, seen_flag, on_server); + email_modify_seen_flag_of_thread(thread_id, seen_flag, on_server); return FALSE; } @@ -126,13 +128,13 @@ void testapp_thread_main() { gboolean go_to_loop = TRUE; int menu_number = 0; - int result_from_scanf = 0; while (go_to_loop) { testapp_show_menu (EMAIL_THREAD_MENU); testapp_show_prompt (EMAIL_THREAD_MENU); - result_from_scanf = scanf("%d", &menu_number); + if (0 >= scanf("%d", &menu_number)) + testapp_print("Invalid input. "); go_to_loop = testapp_test_interpret_command (menu_number); } diff --git a/utilities/test-application/testapp-utility.c b/utilities/test-application/testapp-utility.c index c834b7e..910b85a 100755 --- a/utilities/test-application/testapp-utility.c +++ b/utilities/test-application/testapp-utility.c @@ -76,15 +76,16 @@ void testapp_show_menu (eEMAIL_MENU menu) testapp_print (" 9. Backup All accounts\n"); testapp_print (" 10. Restore accounts\n"); testapp_print (" 11. Get password length of account\n"); - testapp_print (" 12. Query server info\n"); - testapp_print (" 13. Clear all notifications\n"); - testapp_print (" 14. Save default account ID\n"); - testapp_print (" 15. Load default account ID\n"); - testapp_print (" 16. Add certificate\n"); - testapp_print (" 17. Get certificate\n"); - testapp_print (" 18. Delete certificate\n"); - testapp_print (" 19. Add Account\n"); - testapp_print (" 20. Update peak schedule\n"); + testapp_print (" 13. Update notifications\n"); + testapp_print (" 14. Clear notifications\n"); + testapp_print (" 15. Clear all notifications\n"); + testapp_print (" 16. Save default account ID\n"); + testapp_print (" 17. Load default account ID\n"); + testapp_print (" 18. Add certificate\n"); + testapp_print (" 19. Get certificate\n"); + testapp_print (" 20. Delete certificate\n"); + testapp_print (" 21. Add Account\n"); + testapp_print (" 22. Update peak schedule\n"); testapp_print (" 0. Go to Main Menu\n"); testapp_print ("------------------------------------------\n"); break; @@ -134,6 +135,8 @@ void testapp_show_menu (eEMAIL_MENU menu) testapp_print ("59. Add mail to search result table\n"); testapp_print ("60. Parse mime file\n"); testapp_print ("61. Write mime file\n"); + testapp_print ("63. Add mail with multiple recipient\n"); + testapp_print ("64. Send mails every x minutes\n"); testapp_print ("0. Go to Main Menu\n"); testapp_print ("------------------------------------------\n"); break; @@ -189,6 +192,7 @@ void testapp_show_menu (eEMAIL_MENU menu) testapp_print (" OTHERS\n"); testapp_print ("==========================================\n"); testapp_print ("1. Ping service\n"); + testapp_print ("2. Init storage\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"); @@ -200,6 +204,7 @@ void testapp_show_menu (eEMAIL_MENU menu) testapp_print ("15. Show User Message\n"); testapp_print ("16. Get mime entity in signed file\n"); testapp_print ("17. Query SMTP mail size limit\n"); + testapp_print ("18. Verify email address\n"); testapp_print ("0. Go to Main Menu\n"); testapp_print ("------------------------------------------\n"); break; |