diff options
author | Kyuho Jo <kyuho.jo@samsung.com> | 2013-01-18 15:50:57 +0900 |
---|---|---|
committer | Kyuho Jo <kyuho.jo@samsung.com> | 2013-01-18 15:50:57 +0900 |
commit | 0b97074a52983231657bafecab16154924847414 (patch) | |
tree | a1dd11351fc648bf3de6b229f8fead8ca9f87c5c | |
parent | 897f751a35ec5df1a93fc3e1e32ff1d154d5b51f (diff) | |
parent | bdcb6e160907caff4ce2207d0073a151df741f1e (diff) | |
download | email-service-0b97074a52983231657bafecab16154924847414.tar.gz email-service-0b97074a52983231657bafecab16154924847414.tar.bz2 email-service-0b97074a52983231657bafecab16154924847414.zip |
Merge branch 'master' into tizen_2.0
133 files changed, 5104 insertions, 4435 deletions
@@ -1,4 +1,4 @@ -Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. Apache License Version 2.0, January 2004 diff --git a/email-api/email-api-account.c b/email-api/email-api-account.c index 7127667..3acfd66 100755 --- a/email-api/email-api-account.c +++ b/email-api/email-api-account.c @@ -1,7 +1,7 @@ /* * email-service * -* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> * diff --git a/email-api/email-api-etc.c b/email-api/email-api-etc.c index 1a289ad..72a9e98 100755 --- a/email-api/email-api-etc.c +++ b/email-api/email-api-etc.c @@ -1,7 +1,7 @@ /* * email-service * -* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> * diff --git a/email-api/email-api-init.c b/email-api/email-api-init.c index 31ca758..0adc2c3 100755 --- a/email-api/email-api-init.c +++ b/email-api/email-api-init.c @@ -1,7 +1,7 @@ /* * email-service * -* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> * diff --git a/email-api/email-api-mail.c b/email-api/email-api-mail.c index 76ccbac..6e18a51 100755 --- a/email-api/email-api-mail.c +++ b/email-api/email-api-mail.c @@ -1,7 +1,7 @@ /* * email-service * -* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> * diff --git a/email-api/email-api-mailbox.c b/email-api/email-api-mailbox.c index 790a6fe..94edec3 100755 --- a/email-api/email-api-mailbox.c +++ b/email-api/email-api-mailbox.c @@ -1,7 +1,7 @@ /* * email-service * -* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> * diff --git a/email-api/email-api-network.c b/email-api/email-api-network.c index ffa5290..3d86f48 100755 --- a/email-api/email-api-network.c +++ b/email-api/email-api-network.c @@ -1,7 +1,7 @@ /* * email-service * -* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> * @@ -141,6 +141,86 @@ FINISH_OFF: return err; } +EXPORT_API int email_send_mail_with_downloading_attachment_of_original_mail(int input_mail_id, int *output_handle) +{ + EM_DEBUG_FUNC_BEGIN("input_mail_id[%d], output_handle[%p]", input_mail_id, output_handle); + + int err = EMAIL_ERROR_NONE; + emstorage_mail_tbl_t* mail_table_data = NULL; + email_account_server_t account_server_type; + HIPC_API hAPI = NULL; + task_parameter_EMAIL_ASYNC_TASK_SEND_MAIL_WITH_DOWNLOADING_ATTACHMENT_OF_ORIGINAL_MAIL task_parameter; + + if(input_mail_id <= 0) { + EM_DEBUG_EXCEPTION("mail_id is not valid"); + err= EMAIL_ERROR_INVALID_PARAM; + goto FINISH_OFF; + } + + if(!emstorage_get_mail_by_id(input_mail_id, &mail_table_data, true, &err) || !mail_table_data) { + EM_DEBUG_EXCEPTION("Failed to get mail by mail_id [%d]", err); + goto FINISH_OFF; + } + + if (mail_table_data->account_id <= 0) { + EM_DEBUG_EXCEPTION ("EM_IF_ACCOUNT_ID_NULL: Account ID [ %d ] ", mail_table_data->account_id); + emstorage_free_mail(&mail_table_data, 1, NULL); + return EMAIL_ERROR_INVALID_PARAM; + } + + EM_DEBUG_LOG("mail_table_data->account_id[%d], mail_table_data->mailbox_name[%s]", mail_table_data->account_id, mail_table_data->mailbox_name); + + /* check account bind type and branch off */ + if ( em_get_account_server_type_by_account_id(mail_table_data->account_id, &account_server_type, false, &err) == false ) { + EM_DEBUG_EXCEPTION("em_get_account_server_type_by_account_id failed[%d]", err); + err = EMAIL_ERROR_ACTIVE_SYNC_NOTI_FAILURE; + goto FINISH_OFF; + } + + if ( account_server_type == EMAIL_SERVER_TYPE_ACTIVE_SYNC ) { + int as_handle; + ASNotiData as_noti_data; + + memset(&as_noti_data, 0x00, sizeof(ASNotiData)); + + if ( em_get_handle_for_activesync(&as_handle, &err) == false ) { + EM_DEBUG_EXCEPTION("em_get_handle_for_activesync failed[%d].", err); + err = EMAIL_ERROR_ACTIVE_SYNC_NOTI_FAILURE; + goto FINISH_OFF; + } + + /* noti to active sync */ + as_noti_data.send_mail_with_downloading_attachment_of_original_mail.handle = as_handle; + as_noti_data.send_mail_with_downloading_attachment_of_original_mail.mail_id = input_mail_id; + + if ( em_send_notification_to_active_sync_engine(ACTIVE_SYNC_NOTI_SEND_MAIL_WITH_DOWNLOADING_OF_ORIGINAL_MAIL, &as_noti_data) == 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 { + task_parameter.mail_id = input_mail_id; + + if((err = emipc_execute_proxy_task(EMAIL_ASYNC_TASK_SEND_MAIL_WITH_DOWNLOADING_ATTACHMENT_OF_ORIGINAL_MAIL, &task_parameter)) != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("execute_proxy_task failed [%d]", err); + goto FINISH_OFF; + } + } + +FINISH_OFF: + emipc_destroy_email_api(hAPI); + hAPI = (HIPC_API)NULL; + + emstorage_free_mail(&mail_table_data, 1, NULL); + + EM_DEBUG_FUNC_END("err [%d]", err); + return err; +} + EXPORT_API int email_send_saved(int account_id, int *handle) { EM_DEBUG_FUNC_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 2e16050..74db35e 100755 --- a/email-api/email-api-rule.c +++ b/email-api/email-api-rule.c @@ -1,7 +1,7 @@ /* * email-service * -* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> * diff --git a/email-api/email-api-smime.c b/email-api/email-api-smime.c index 66b78b6..ade7f9c 100755 --- a/email-api/email-api-smime.c +++ b/email-api/email-api-smime.c @@ -1,7 +1,7 @@ /* * email-service * -* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> * diff --git a/email-api/include/email-api-account.h b/email-api/include/email-api-account.h index 5b0d1aa..0744bf9 100755 --- a/email-api/include/email-api-account.h +++ b/email-api/include/email-api-account.h @@ -1,7 +1,7 @@ /* * email-service * -* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> * diff --git a/email-api/include/email-api-etc.h b/email-api/include/email-api-etc.h index 6ac7262..f397fd9 100755 --- a/email-api/include/email-api-etc.h +++ b/email-api/include/email-api-etc.h @@ -1,7 +1,7 @@ /* * email-service * -* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> * diff --git a/email-api/include/email-api-init.h b/email-api/include/email-api-init.h index f00da57..96ee737 100755 --- a/email-api/include/email-api-init.h +++ b/email-api/include/email-api-init.h @@ -1,7 +1,7 @@ /* * email-service * -* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> * diff --git a/email-api/include/email-api-mail.h b/email-api/include/email-api-mail.h index afb1b9b..12b1233 100755 --- a/email-api/include/email-api-mail.h +++ b/email-api/include/email-api-mail.h @@ -1,7 +1,7 @@ /* * email-service * -* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> * diff --git a/email-api/include/email-api-mailbox.h b/email-api/include/email-api-mailbox.h index fa7dca8..aefe23b 100755 --- a/email-api/include/email-api-mailbox.h +++ b/email-api/include/email-api-mailbox.h @@ -1,7 +1,7 @@ /* * email-service * -* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> * diff --git a/email-api/include/email-api-network.h b/email-api/include/email-api-network.h index d7162c6..10375ea 100755 --- a/email-api/include/email-api-network.h +++ b/email-api/include/email-api-network.h @@ -1,7 +1,7 @@ /* * email-service * -* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> * @@ -178,6 +178,8 @@ extern "C" { */ EXPORT_API int email_send_mail(int mail_id, int *handle); +EXPORT_API int email_send_mail_with_downloading_attachment_of_original_mail(int input_mail_id, int *output_handle); + /** diff --git a/email-api/include/email-api-rule.h b/email-api/include/email-api-rule.h index 6b4b9fd..84df72c 100755 --- a/email-api/include/email-api-rule.h +++ b/email-api/include/email-api-rule.h @@ -1,7 +1,7 @@ /* * email-service * -* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> * diff --git a/email-api/include/email-api-smime.h b/email-api/include/email-api-smime.h index 7af32e3..5188cd3 100755 --- a/email-api/include/email-api-smime.h +++ b/email-api/include/email-api-smime.h @@ -1,7 +1,7 @@ /* * email-service * -* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> * diff --git a/email-api/include/email-api.h b/email-api/include/email-api.h index b7b294d..8da1b26 100755 --- a/email-api/include/email-api.h +++ b/email-api/include/email-api.h @@ -1,7 +1,7 @@ /* * email-service * -* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> * diff --git a/email-common-use/email-convert.c b/email-common-use/email-convert.c index e576d01..2c1e730 100755 --- a/email-common-use/email-convert.c +++ b/email-common-use/email-convert.c @@ -1,7 +1,7 @@ /* * email-service * -* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> * diff --git a/email-common-use/email-utilities.c b/email-common-use/email-utilities.c index 0325e97..a4b430f 100755 --- a/email-common-use/email-utilities.c +++ b/email-common-use/email-utilities.c @@ -1,7 +1,7 @@ /* * email-service * -* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> * @@ -207,14 +207,14 @@ INTERNAL_FUNC char* em_replace_all_string(char *source_string, char *old_string, int i = 0, count = 0; int old_str_length = 0; int new_str_length = 0; - + EM_IF_NULL_RETURN_VALUE(source_string, NULL); EM_IF_NULL_RETURN_VALUE(old_string, NULL); EM_IF_NULL_RETURN_VALUE(new_string, NULL); old_str_length = EM_SAFE_STRLEN(old_string); new_str_length = EM_SAFE_STRLEN(new_string); - + if (old_str_length != new_str_length) { for (i = 0; source_string[i] != '\0';) { if (memcmp(&source_string[i], old_string, old_str_length) == 0) { @@ -229,7 +229,7 @@ INTERNAL_FUNC char* em_replace_all_string(char *source_string, char *old_string, } result_buffer = (char *)malloc(i + 1 + count*(new_str_length-old_str_length)); - if (result_buffer == NULL) + if (result_buffer == NULL) return NULL; p = result_buffer; @@ -243,7 +243,7 @@ INTERNAL_FUNC char* em_replace_all_string(char *source_string, char *old_string, } } *p = '\0'; - + EM_DEBUG_FUNC_END("result_buffer : %s", result_buffer); return result_buffer; } @@ -536,7 +536,7 @@ INTERNAL_FUNC int em_get_content_type_from_extension_string(const char *extensio } i++; } - + switch (i) { case EXTENSION_JPEG: case EXTENSION_JPG: @@ -1096,6 +1096,11 @@ INTERNAL_FUNC int em_send_notification_to_active_sync_engine(int subType, ASNoti dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->delete_mailbox_ex.handle), DBUS_TYPE_INVALID); break; + case ACTIVE_SYNC_NOTI_SEND_MAIL_WITH_DOWNLOADING_OF_ORIGINAL_MAIL: + dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->send_mail_with_downloading_attachment_of_original_mail.handle), DBUS_TYPE_INVALID); + dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->send_mail_with_downloading_attachment_of_original_mail.mail_id), DBUS_TYPE_INVALID); + break; + default: EM_DEBUG_EXCEPTION("Invalid Notification type of Active Sync : subType[%d]", subType); return FAILURE; diff --git a/email-common-use/include/email-convert.h b/email-common-use/include/email-convert.h index 0488eb4..cb345fd 100755 --- a/email-common-use/include/email-convert.h +++ b/email-common-use/include/email-convert.h @@ -1,7 +1,7 @@ /* * email-service * -* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> * diff --git a/email-common-use/include/email-debug-log.h b/email-common-use/include/email-debug-log.h index 5eecb68..b568293 100755 --- a/email-common-use/include/email-debug-log.h +++ b/email-common-use/include/email-debug-log.h @@ -1,7 +1,7 @@ /* * email-service * -* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> * diff --git a/email-common-use/include/email-errors.h b/email-common-use/include/email-errors.h index 3fcb365..2110457 100755 --- a/email-common-use/include/email-errors.h +++ b/email-common-use/include/email-errors.h @@ -1,7 +1,7 @@ /* * email-service * -* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> * @@ -41,6 +41,7 @@ #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 */ @@ -138,6 +139,8 @@ #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 + /* Error codes for certificate */ #define EMAIL_ERROR_LOAD_CERTIFICATE_FAILURE -3001 /* Cannot load the certificate */ #define EMAIL_ERROR_INVALID_CERTIFICATE -3002 /* invalid certificate */ diff --git a/email-common-use/include/email-internal-types.h b/email-common-use/include/email-internal-types.h index baa9c31..8ab5945 100755 --- a/email-common-use/include/email-internal-types.h +++ b/email-common-use/include/email-internal-types.h @@ -1,7 +1,7 @@ /* * email-service * -* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> * @@ -45,6 +45,7 @@ extern "C" /* ----------------------------------------------------------------------------- */ /* Feature definitions */ +#define __FEATURE_USING_ACCOUNT_SVC__ #define __FEATURE_BACKUP_ACCOUNT__ #define __FEATURE_MOVE_TO_OUTBOX_FIRST__ /* #define __FEATURE_PARTIAL_BODY_FOR_POP3__ */ @@ -68,6 +69,7 @@ extern "C" /* #define __FEATURE_USE_SHARED_MUTEX_FOR_PROTECTED_FUNC_CALL__ */ /* #define __FEATURE_IMAP_IDLE__ */ + /* ----------------------------------------------------------------------------- */ /* Macro */ #ifndef NULL @@ -117,7 +119,7 @@ extern "C" #define SHM_FILE_FOR_DB_LOCK "/.email_shm_db_lock" -#define NATIVE_EMAIL_APPLICATION_PKG "org.tizen.email" +#define NATIVE_EMAIL_APPLICATION_PKG "com.samsung.email" #define IMAP_ID_OS "TIZEN" #define IMAP_ID_OS_VERSION "2.0b" @@ -187,11 +189,11 @@ typedef pthread_t thread_t; #define SMTP_RESPONSE_OK 250 #define SMTP_RESPONSE_READY 354 +#define SMTP_RESPONSE_CONNECTION_BROKEN 421 #define SMTP_RESPONSE_WANT_AUTH 505 #define SMTP_RESPONSE_WANT_AUTH2 530 #define SMTP_RESPONSE_UNAVAIL 550 -#define VCONF_KEY_DEFAULT_SLOT_SIZE "db/private/email-service/slot_size" #define VCONF_KEY_LATEST_MAIL_ID "db/private/email-service/latest_mail_id" #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" diff --git a/email-common-use/include/email-types.h b/email-common-use/include/email-types.h index 4d36781..efe62ba 100755 --- a/email-common-use/include/email-types.h +++ b/email-common-use/include/email-types.h @@ -1,7 +1,7 @@ /* * email-service * -* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> * @@ -1576,26 +1576,27 @@ 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, /* 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 */ } eactivesync_noti_t; typedef union @@ -1729,6 +1730,11 @@ typedef union int on_server; } delete_mailbox_ex; + struct _send_mail_with_downloading_attachment_of_original_mail + { + int handle; + int mail_id; + } send_mail_with_downloading_attachment_of_original_mail; } ASNotiData; /* types for noti string */ @@ -1741,26 +1747,26 @@ typedef enum typedef enum { /* Sync tasks */ /* 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, + 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, + 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_GET_ATTACHMENT = 13010, - EMAIL_SYNC_CLEAR_RESULT_OF_SEARCH_MAIL_ON_SERVER = 13020, + EMAIL_SYNC_GET_ATTACHMENT = 13010, + EMAIL_SYNC_CLEAR_RESULT_OF_SEARCH_MAIL_ON_SERVER = 13020, /* Sync tasks for mail thread - from 14000 */ @@ -1769,47 +1775,48 @@ typedef enum { /* Sync tasks for etc - from 16000 */ /* Async tasks */ - EMAIL_ASYNC_TASK_BOUNDARY = 60000, + EMAIL_ASYNC_TASK_BOUNDARY = 60000, /* Async tasks for account - from 61000 */ - EMAIL_ASYNC_TASK_VALIDATE_ACCOUNT = 61010, - EMAIL_ASYNC_TASK_ADD_ACCOUNT_WITH_VALIDATION = 61020, + 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, + 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_ADD_MAIL = 63010, + EMAIL_ASYNC_TASK_ADD_READ_RECEIPT = 63020, - EMAIL_ASYNC_TASK_UPDATE_MAIL = 63030, + 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_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_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 = 63100, + EMAIL_ASYNC_TASK_SET_FLAGS_FIELD = 63300, - EMAIL_ASYNC_TASK_DOWNLOAD_MAIL_LIST = 63110, - EMAIL_ASYNC_TASK_DOWNLOAD_BODY = 63120, - EMAIL_ASYNC_TASK_DOWNLOAD_ATTACHMENT = 63130, + EMAIL_ASYNC_TASK_DOWNLOAD_MAIL_LIST = 63400, + EMAIL_ASYNC_TASK_DOWNLOAD_BODY = 63410, + EMAIL_ASYNC_TASK_DOWNLOAD_ATTACHMENT = 63420, - EMAIL_ASYNC_TASK_SEND_MAIL = 63140, - EMAIL_ASYNC_TASK_SEND_SAVED = 63150, + 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 = 63160, + 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, + 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 */ diff --git a/email-common-use/include/email-utilities.h b/email-common-use/include/email-utilities.h index 1008dc6..0472528 100755 --- a/email-common-use/include/email-utilities.h +++ b/email-common-use/include/email-utilities.h @@ -1,7 +1,7 @@ /* * email-service * -* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> * diff --git a/email-core/email-core-account.c b/email-core/email-core-account.c index 929782e..6ed5d1f 100755 --- a/email-core/email-core-account.c +++ b/email-core/email-core-account.c @@ -1,7 +1,7 @@ /* * email-service * -* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> * @@ -51,6 +51,11 @@ #include "email-core-signal.h" #include "email-core-imap-mailbox.h" +#ifdef __FEATURE_USING_ACCOUNT_SVC__ +#include "account.h" +#include "account-types.h" +#endif /* __FEATURE_USING_ACCOUNT_SVC__ */ + char *g_default_mbox_alias[MAILBOX_COUNT] = { EMAIL_INBOX_DISPLAY_NAME, @@ -329,6 +334,23 @@ INTERNAL_FUNC int emcore_delete_account(int account_id, int *err_code) #endif +#ifdef __FEATURE_USING_ACCOUNT_SVC__ + { + int error_code; + 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); + } + } +#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; @@ -456,6 +478,59 @@ INTERNAL_FUNC int emcore_create_account(email_account_t *account, int *err_code) } } +#ifdef __FEATURE_USING_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_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_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; + } + + account_set_user_name(account_handle, account->incoming_server_user_name); + account_set_domain_name(account_handle, account->account_name); + account_set_email_address(account_handle, account->user_email_address); + account_set_source(account_handle, "SLP EMAIL"); + account_set_package_name(account_handle, "email-setting-efl"); + /* account_set_capability(account_handle , ACCOUNT_CAPABILITY_EMAIL, ACCOUNT_CAPABILITY_ENABLED); OLD API */ + account_set_capability(account_handle , ACCOUNT_SUPPORTS_CAPABILITY_EMAIL , ACCOUNT_CAPABILITY_ENABLED); + account_set_sync_support(account_handle, ACCOUNT_SYNC_STATUS_IDLE); /* This means "The account is supporting 'sync' and initialized as idle status" */ + if (account->logo_icon_path) + account_set_icon_path(account_handle, account->logo_icon_path); + error_code = account_insert_to_db(account_handle, &account_svc_id); + + if (error_code != ACCOUNT_ERROR_NONE) { + EM_DEBUG_EXCEPTION("account_insert_to_db failed [%d]", error_code); + err = error_code; + if (account_handle) + account_destroy(account_handle); + + account_disconnect(); + goto FINISH_OFF; + } + + account->account_svc_id = account_svc_id; + + EM_DEBUG_LOG("account_insert_to_db succeed"); + + if (account_handle) + account_destroy(account_handle); + account_disconnect(); + } +#endif /* __FEATURE_USING_ACCOUNT_SVC__ */ + temp_account_tbl = em_malloc(sizeof(emstorage_account_tbl_t)); if (!temp_account_tbl) { EM_DEBUG_EXCEPTION("allocation failed [%d]", err); @@ -484,7 +559,7 @@ INTERNAL_FUNC int emcore_create_account(email_account_t *account, int *err_code) local_mailbox.local = EMAIL_MAILBOX_FROM_LOCAL; } local_mailbox.alias = g_default_mbox_alias[i]; - emcore_get_default_mail_slot_count(&local_mailbox.mail_slot_size, NULL); + local_mailbox.mail_slot_size = temp_account_tbl->default_mail_slot_size; if (!emcore_create_mailbox(&local_mailbox, 0, &err)) { EM_DEBUG_EXCEPTION("emcore_create failed - %d", err); @@ -1007,10 +1082,13 @@ FINISH_OFF: #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("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; } @@ -1167,12 +1245,40 @@ INTERNAL_FUNC int emcore_update_sync_status_of_account(int input_account_id, ema EM_DEBUG_FUNC_BEGIN("input_account_id [%d], input_set_operator [%d], input_sync_status [%d]", input_account_id, input_set_operator, input_sync_status); int err = EMAIL_ERROR_NONE; +#ifdef __FEATURE_USING_ACCOUNT_SVC__ + int err_from_account_svc = 0; + emstorage_account_tbl_t *account_tbl_data = NULL; + if (input_account_id != ALL_ACCOUNT && (input_sync_status == SYNC_STATUS_SYNCING)) { + if (!emstorage_get_account_by_id(input_account_id, EMAIL_ACC_GET_OPT_DEFAULT | EMAIL_ACC_GET_OPT_OPTIONS, &account_tbl_data, true, &err)) { + EM_DEBUG_EXCEPTION("emstorage_get_account_by_id failed [%d]", err); + goto FINISH_OFF; + } + err_from_account_svc = account_connect(); + EM_DEBUG_LOG("account_connect returns [%d]", err_from_account_svc); + + EM_DEBUG_LOG("account_tbl_data->account_svc_id [%d]", account_tbl_data->account_svc_id); + + if (input_set_operator == SET_TYPE_SET) + err_from_account_svc = account_update_sync_status_by_id(account_tbl_data->account_svc_id, ACCOUNT_SYNC_STATUS_RUNNING); + 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]", err_from_account_svc); + + err_from_account_svc = account_disconnect(); + EM_DEBUG_LOG("account_disconnect returns [%d]", err_from_account_svc); + } +#endif /* __FEATURE_USING_ACCOUNT_SVC__ */ if (!emstorage_update_sync_status_of_account(input_account_id, input_set_operator, input_sync_status, true, &err)) EM_DEBUG_EXCEPTION("emstorage_update_sync_status_of_account failed [%d]", err); - +#ifdef __FEATURE_USING_ACCOUNT_SVC__ +FINISH_OFF: + if (account_tbl_data) + emstorage_free_account(&account_tbl_data, 1, NULL); +#endif /* __FEATURE_USING_ACCOUNT_SVC__ */ EM_DEBUG_FUNC_END("err [%d]", err); return err; diff --git a/email-core/email-core-api.c b/email-core/email-core-api.c index 384809b..0ca382f 100755 --- a/email-core/email-core-api.c +++ b/email-core/email-core-api.c @@ -1,7 +1,7 @@ /* * email-service * -* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> * diff --git a/email-core/email-core-cert.c b/email-core/email-core-cert.c index 7e691fb..c0891b1 100755 --- a/email-core/email-core-cert.c +++ b/email-core/email-core-cert.c @@ -1,7 +1,7 @@ /* * email-service * -* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> * diff --git a/email-core/email-core-event.c b/email-core/email-core-event.c index 8115da3..6fba15b 100755 --- a/email-core/email-core-event.c +++ b/email-core/email-core-event.c @@ -1,10 +1,10 @@ /* * email-service * -* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* 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-event_data.h * Desc : Mail Engine Event * - * Auth : + * Auth : * - * History : + * History : * 2006.08.16 : created *****************************************************************************/ #include <stdio.h> @@ -70,7 +70,7 @@ static email_event_partial_body_thd g_partial_body_thd_event_que[TOTAL_PARTIAL_B static int g_partial_body_thd_next_event_idx = 0; /* Index of Next Event to be processed in the queue*/ static int g_partial_body_thd_loop = 1; /* Variable to make a continuos while loop */ static int g_partial_body_thd_queue_empty = true; /* Variable to determine if event queue is empty.True means empty*/ -static int g_partial_body_thd_queue_full = false; /* Variable to determine if event queue is full. True means full*/ +static int g_partial_body_thd_queue_full = false; /* Variable to determine if event queue is full. True means full*/ static int g_pb_thd_local_activity_continue = true; /* Variable to control local activity sync */ int g_pbd_thd_state = false; /* false : thread is sleeping , true : thread is working */ @@ -110,7 +110,7 @@ INTERNAL_FUNC int g_save_local_activity_run = 0; #define EVENT_QUEUE_MAX 32 -typedef struct EVENT_CALLBACK_ELEM +typedef struct EVENT_CALLBACK_ELEM { email_event_callback callback; void *event_data; @@ -120,7 +120,7 @@ typedef struct EVENT_CALLBACK_ELEM static pthread_mutex_t _event_available_lock = PTHREAD_MUTEX_INITIALIZER; static pthread_cond_t _event_available_signal = PTHREAD_COND_INITIALIZER; static pthread_mutex_t *_event_callback_table_lock = NULL; -static pthread_mutex_t *_event_queue_lock = NULL; +static pthread_mutex_t *_event_queue_lock = NULL; static EVENT_CALLBACK_LIST *_event_callback_table[EMAIL_ACTION_NUM]; /* array of singly-linked list for event callbacks */ void *thread_func_branch_command(void *arg); @@ -160,14 +160,14 @@ INTERNAL_FUNC int emcore_get_current_thread_type() #ifdef __FEATURE_PARTIAL_BODY_DOWNLOAD__ else if (thread_id == g_partial_body_thd) thread_type = _SERVICE_THREAD_TYPE_PBD; -#endif +#endif EM_DEBUG_FUNC_END("thread_type [%d]", thread_type); - return thread_type; + return thread_type; } static int is_gdk_lock_needed() { - if (g_event_loop) { + if (g_event_loop) { return (THREAD_SELF() == g_srv_thread); } return false; @@ -176,37 +176,37 @@ static int is_gdk_lock_needed() INTERNAL_FUNC int emcore_get_pending_event(email_action_t action, int account_id, int mail_id, email_event_status_type_t *status) { EM_DEBUG_FUNC_BEGIN("action[%d], account_id[%d], mail_id[%d]", action, account_id, mail_id); - + int found = false; int i; - + ENTER_RECURSIVE_CRITICAL_SECTION(_event_queue_lock); - + for (i = 1; i < EVENT_QUEUE_MAX; i++) { switch (g_event_que[i].type) { - case EMAIL_EVENT_SEND_MAIL: - case EMAIL_EVENT_SEND_MAIL_SAVED: + case EMAIL_EVENT_SEND_MAIL: + case EMAIL_EVENT_SEND_MAIL_SAVED: if (action == EMAIL_ACTION_SEND_MAIL && account_id == g_event_que[i].account_id && mail_id == g_event_que[i].event_param_data_4) { found = true; goto EXIT; } break; - - case EMAIL_EVENT_SYNC_HEADER: + + case EMAIL_EVENT_SYNC_HEADER: if (action == EMAIL_ACTION_SYNC_HEADER && account_id == g_event_que[i].account_id) { found = true; goto EXIT; } break; - + case EMAIL_EVENT_SYNC_HEADER_OMA: if (action == EMAIL_ACTION_SYNC_HEADER_OMA && account_id == g_event_que[i].account_id) { found = true; goto EXIT; } break; - - case EMAIL_EVENT_DOWNLOAD_BODY: + + case EMAIL_EVENT_DOWNLOAD_BODY: if (action == EMAIL_ACTION_DOWNLOAD_BODY && account_id == g_event_que[i].account_id && mail_id == g_event_que[i].event_param_data_4) { found = true; goto EXIT; @@ -216,21 +216,21 @@ INTERNAL_FUNC int emcore_get_pending_event(email_action_t action, int account_id if (action == EMAIL_ACTION_SYNC_MAIL_FLAG_TO_SERVER && account_id == g_event_que[i].account_id && mail_id == g_event_que[i].event_param_data_4) { found = true; goto EXIT; - } + } break; case EMAIL_EVENT_SYNC_FLAGS_FIELD_TO_SERVER: if (action == EMAIL_ACTION_SYNC_FLAGS_FIELD_TO_SERVER && account_id == g_event_que[i].account_id && mail_id == g_event_que[i].event_param_data_4) { found = true; goto EXIT; - } + } break; - case EMAIL_EVENT_DOWNLOAD_ATTACHMENT: + case EMAIL_EVENT_DOWNLOAD_ATTACHMENT: if (action == EMAIL_ACTION_DOWNLOAD_ATTACHMENT && account_id == g_event_que[i].account_id && mail_id == g_event_que[i].event_param_data_4) { found = true; goto EXIT; } break; - case EMAIL_EVENT_DELETE_MAIL: + case EMAIL_EVENT_DELETE_MAIL: case EMAIL_EVENT_DELETE_MAIL_ALL: if (action == EMAIL_ACTION_DELETE_MAIL && account_id == g_event_que[i].account_id) { found = true; @@ -238,56 +238,56 @@ INTERNAL_FUNC int emcore_get_pending_event(email_action_t action, int account_id } break; - case EMAIL_EVENT_CREATE_MAILBOX: + case EMAIL_EVENT_CREATE_MAILBOX: if (action == EMAIL_ACTION_CREATE_MAILBOX && account_id == g_event_que[i].account_id) { found = true; goto EXIT; } break; - case EMAIL_EVENT_DELETE_MAILBOX: + case EMAIL_EVENT_DELETE_MAILBOX: if (action == EMAIL_ACTION_DELETE_MAILBOX && account_id == g_event_que[i].account_id) { found = true; goto EXIT; } break; - case EMAIL_EVENT_MOVE_MAIL: + case EMAIL_EVENT_MOVE_MAIL: if (action == EMAIL_ACTION_MOVE_MAIL && account_id == g_event_que[i].account_id && mail_id == g_event_que[i].event_param_data_4) { found = true; goto EXIT; } break; - case EMAIL_EVENT_VALIDATE_ACCOUNT: + case EMAIL_EVENT_VALIDATE_ACCOUNT: if (action == EMAIL_ACTION_VALIDATE_ACCOUNT && account_id == g_event_que[i].account_id) { found = true; goto EXIT; } break; - case EMAIL_EVENT_VALIDATE_AND_UPDATE_ACCOUNT: + case EMAIL_EVENT_VALIDATE_AND_UPDATE_ACCOUNT: if (action == EMAIL_ACTION_VALIDATE_AND_UPDATE_ACCOUNT && account_id == 0) { found = true; goto EXIT; } break; - - case EMAIL_EVENT_VALIDATE_AND_CREATE_ACCOUNT: + + case EMAIL_EVENT_VALIDATE_AND_CREATE_ACCOUNT: if (action == EMAIL_ACTION_VALIDATE_AND_CREATE_ACCOUNT && account_id == 0) { found = true; goto EXIT; } break; - + case EMAIL_EVENT_UPDATE_MAIL: if (action == EMAIL_ACTION_UPDATE_MAIL) { found = true; goto EXIT; } break; - - case EMAIL_EVENT_SET_MAIL_SLOT_SIZE: + + case EMAIL_EVENT_SET_MAIL_SLOT_SIZE: if (action == EMAIL_ACTION_SET_MAIL_SLOT_SIZE) { found = true; goto EXIT; @@ -300,13 +300,13 @@ INTERNAL_FUNC int emcore_get_pending_event(email_action_t action, int account_id goto EXIT; } break; - + case EMAIL_EVENT_SEARCH_ON_SERVER: if (action == EMAIL_ACTION_SEARCH_ON_SERVER && account_id == g_event_que[i].account_id) { found = true; goto EXIT; } - break; + break; case EMAIL_EVENT_RENAME_MAILBOX_ON_IMAP_SERVER: if (action == EMAIL_ACTION_MOVE_MAILBOX && account_id == g_event_que[i].account_id) { @@ -315,21 +315,21 @@ INTERNAL_FUNC int emcore_get_pending_event(email_action_t action, int account_id } break; - default: + default: break; } } - + EXIT: LEAVE_RECURSIVE_CRITICAL_SECTION(_event_queue_lock); - + if (found) { if (status) *status = g_event_que[i].status; - + return i; } - + return FAILURE; } @@ -337,7 +337,7 @@ INTERNAL_FUNC void emcore_get_event_queue_status(int *on_sending, int *on_receiv { if (on_sending != NULL) *on_sending = g_sending_busy_cnt; - + if (on_receiving != NULL) *on_receiving = g_receiving_busy_cnt; } @@ -365,66 +365,66 @@ static void _receiving_busy_unref(void) static void waiting_status_notify(email_event_t *event_data, int queue_idx) { EM_DEBUG_FUNC_BEGIN("event_data[%p], queue_idx[%d]", event_data, queue_idx); - + int account_id = event_data->account_id; int mail_id = event_data->event_param_data_4; /* NOT ALWAYS */ - + switch (event_data->type) { - case EMAIL_EVENT_SEND_MAIL: + case EMAIL_EVENT_SEND_MAIL: emcore_execute_event_callback(EMAIL_ACTION_SEND_MAIL, 0, 0, EMAIL_SEND_WAITING, account_id, mail_id, queue_idx, EMAIL_ERROR_NONE); break; - - case EMAIL_EVENT_SYNC_HEADER: + + case EMAIL_EVENT_SYNC_HEADER: emcore_execute_event_callback(EMAIL_ACTION_SYNC_HEADER, 0, 0, EMAIL_LIST_WAITING, account_id, 0, queue_idx, EMAIL_ERROR_NONE); break; case EMAIL_EVENT_SYNC_HEADER_OMA: emcore_execute_event_callback(EMAIL_ACTION_SYNC_HEADER_OMA, 0, 0, EMAIL_LIST_WAITING, account_id, 0, queue_idx, EMAIL_ERROR_NONE); break; - - case EMAIL_EVENT_DOWNLOAD_BODY: + + case EMAIL_EVENT_DOWNLOAD_BODY: emcore_execute_event_callback(EMAIL_ACTION_DOWNLOAD_BODY, 0, 0, EMAIL_DOWNLOAD_WAITING, account_id, mail_id, queue_idx, EMAIL_ERROR_NONE); break; #ifdef __FEATURE_SYNC_CLIENT_TO_SERVER__ case EMAIL_EVENT_SYNC_MAIL_FLAG_TO_SERVER: emcore_execute_event_callback(EMAIL_ACTION_SYNC_MAIL_FLAG_TO_SERVER, 0, 0, EMAIL_SYNC_WAITING, account_id, mail_id, queue_idx, EMAIL_ERROR_NONE); - break; + break; #endif - - case EMAIL_EVENT_DOWNLOAD_ATTACHMENT: + + case EMAIL_EVENT_DOWNLOAD_ATTACHMENT: emcore_execute_event_callback(EMAIL_ACTION_DOWNLOAD_ATTACHMENT, 0, 0, EMAIL_DOWNLOAD_WAITING, account_id, mail_id, queue_idx, EMAIL_ERROR_NONE); break; - case EMAIL_EVENT_DELETE_MAIL: + case EMAIL_EVENT_DELETE_MAIL: case EMAIL_EVENT_DELETE_MAIL_ALL: emcore_execute_event_callback(EMAIL_ACTION_DELETE_MAIL, 0, 0, EMAIL_DELETE_WAITING, account_id, 0, queue_idx, EMAIL_ERROR_NONE); break; - case EMAIL_EVENT_VALIDATE_ACCOUNT: + case EMAIL_EVENT_VALIDATE_ACCOUNT: emcore_execute_event_callback(EMAIL_ACTION_VALIDATE_ACCOUNT, 0, 0, EMAIL_VALIDATE_ACCOUNT_WAITING, account_id, 0, queue_idx, EMAIL_ERROR_NONE); break; - case EMAIL_EVENT_VALIDATE_AND_CREATE_ACCOUNT: + case EMAIL_EVENT_VALIDATE_AND_CREATE_ACCOUNT: emcore_execute_event_callback(EMAIL_ACTION_VALIDATE_AND_CREATE_ACCOUNT, 0, 0, EMAIL_VALIDATE_ACCOUNT_WAITING, account_id, 0, queue_idx, EMAIL_ERROR_NONE); break; - case EMAIL_EVENT_MOVE_MAIL: + case EMAIL_EVENT_MOVE_MAIL: emcore_execute_event_callback(EMAIL_ACTION_MOVE_MAIL, 0, 0, EMAIL_LIST_WAITING, account_id, 0, queue_idx, EMAIL_ERROR_NONE); break; - case EMAIL_EVENT_CREATE_MAILBOX: + case EMAIL_EVENT_CREATE_MAILBOX: emcore_execute_event_callback(EMAIL_ACTION_CREATE_MAILBOX, 0, 0, EMAIL_LIST_WAITING, account_id, 0, queue_idx, EMAIL_ERROR_NONE); break; - case EMAIL_EVENT_VALIDATE_AND_UPDATE_ACCOUNT: + case EMAIL_EVENT_VALIDATE_AND_UPDATE_ACCOUNT: emcore_execute_event_callback(EMAIL_ACTION_VALIDATE_AND_UPDATE_ACCOUNT, 0, 0, EMAIL_VALIDATE_ACCOUNT_WAITING, account_id, 0, queue_idx, EMAIL_ERROR_NONE); break; case EMAIL_EVENT_UPDATE_MAIL: break; - case EMAIL_EVENT_SET_MAIL_SLOT_SIZE: + case EMAIL_EVENT_SET_MAIL_SLOT_SIZE: emcore_execute_event_callback(EMAIL_ACTION_SET_MAIL_SLOT_SIZE, 0, 0, EMAIL_SET_SLOT_SIZE_WAITING, account_id, 0, queue_idx, EMAIL_ERROR_NONE); break; @@ -440,7 +440,7 @@ static void waiting_status_notify(email_event_t *event_data, int queue_idx) /* emcore_execute_event_callback(EMAIL_ACTION_CREATE_MAILBOX, 0, 0, EMAIL_LIST_WAITING, account_id, 0, queue_idx, EMAIL_ERROR_NONE); */ break; - default: + default: break; } EM_DEBUG_FUNC_END(); @@ -459,61 +459,61 @@ static void fail_status_notify(email_event_t *event_data, int error) mail_id = event_data->event_param_data_4; EM_DEBUG_LOG("account_id[%d], mail_id[%d], error[%d]", account_id, mail_id, error); - + switch (event_data->type) { - case EMAIL_EVENT_SEND_MAIL: + case EMAIL_EVENT_SEND_MAIL: /* case EMAIL_EVENT_SEND_MAIL_SAVED: */ /* emcore_execute_event_callback(EMAIL_ACTION_SEND_MAIL, 0, 0, EMAIL_SEND_FAIL, account_id, mail_id, -1, error); */ emcore_show_user_message(mail_id, EMAIL_ACTION_SEND_MAIL, error); break; - - case EMAIL_EVENT_SYNC_HEADER: + + case EMAIL_EVENT_SYNC_HEADER: emcore_execute_event_callback(EMAIL_ACTION_SYNC_HEADER, 0, 0, EMAIL_LIST_FAIL, account_id, 0, -1, error); emcore_show_user_message(account_id, EMAIL_ACTION_SYNC_HEADER, error); break; - - case EMAIL_EVENT_DOWNLOAD_BODY: + + case EMAIL_EVENT_DOWNLOAD_BODY: emcore_execute_event_callback(EMAIL_ACTION_DOWNLOAD_BODY, 0, 0, EMAIL_DOWNLOAD_FAIL, account_id, mail_id, -1, error); emcore_show_user_message(account_id, EMAIL_ACTION_DOWNLOAD_BODY, error); break; - - case EMAIL_EVENT_DOWNLOAD_ATTACHMENT: + + case EMAIL_EVENT_DOWNLOAD_ATTACHMENT: emcore_execute_event_callback(EMAIL_ACTION_DOWNLOAD_ATTACHMENT, 0, 0, EMAIL_DOWNLOAD_FAIL, account_id, mail_id, -1, error); emcore_show_user_message(account_id, EMAIL_ACTION_DOWNLOAD_ATTACHMENT, error); break; - - case EMAIL_EVENT_DELETE_MAIL: + + case EMAIL_EVENT_DELETE_MAIL: case EMAIL_EVENT_DELETE_MAIL_ALL: emcore_execute_event_callback(EMAIL_ACTION_DELETE_MAIL, 0, 0, EMAIL_DELETE_FAIL, account_id, 0, -1, error); emcore_show_user_message(account_id, EMAIL_ACTION_DELETE_MAIL, error); break; - case EMAIL_EVENT_VALIDATE_ACCOUNT: + case EMAIL_EVENT_VALIDATE_ACCOUNT: emcore_execute_event_callback(EMAIL_ACTION_VALIDATE_ACCOUNT, 0, 0, EMAIL_VALIDATE_ACCOUNT_FAIL, account_id, 0, -1, error); emcore_show_user_message(account_id, EMAIL_ACTION_VALIDATE_ACCOUNT, error); break; - case EMAIL_EVENT_VALIDATE_AND_CREATE_ACCOUNT: + case EMAIL_EVENT_VALIDATE_AND_CREATE_ACCOUNT: emcore_execute_event_callback(EMAIL_ACTION_VALIDATE_AND_CREATE_ACCOUNT, 0, 0, EMAIL_VALIDATE_ACCOUNT_FAIL, account_id, 0, -1, error); emcore_show_user_message(account_id, EMAIL_ACTION_VALIDATE_AND_CREATE_ACCOUNT, error); break; - case EMAIL_EVENT_CREATE_MAILBOX: + case EMAIL_EVENT_CREATE_MAILBOX: emcore_execute_event_callback(EMAIL_ACTION_CREATE_MAILBOX, 0, 0, EMAIL_LIST_FAIL, account_id, 0, -1, error); emcore_show_user_message(account_id, EMAIL_ACTION_CREATE_MAILBOX, error); break; - case EMAIL_EVENT_DELETE_MAILBOX: + case EMAIL_EVENT_DELETE_MAILBOX: emcore_execute_event_callback(EMAIL_ACTION_DELETE_MAILBOX, 0, 0, EMAIL_LIST_FAIL, account_id, 0, -1, error); emcore_show_user_message(account_id, EMAIL_ACTION_DELETE_MAILBOX, error); break; - case EMAIL_EVENT_VALIDATE_AND_UPDATE_ACCOUNT: + case EMAIL_EVENT_VALIDATE_AND_UPDATE_ACCOUNT: emcore_execute_event_callback(EMAIL_ACTION_VALIDATE_AND_UPDATE_ACCOUNT, 0, 0, EMAIL_VALIDATE_ACCOUNT_FAIL, account_id, 0, -1, error); emcore_show_user_message(account_id, EMAIL_ACTION_VALIDATE_AND_UPDATE_ACCOUNT, error); break; - case EMAIL_EVENT_SET_MAIL_SLOT_SIZE: + case EMAIL_EVENT_SET_MAIL_SLOT_SIZE: emcore_execute_event_callback(EMAIL_ACTION_SET_MAIL_SLOT_SIZE, 0, 0, EMAIL_SET_SLOT_SIZE_FAIL, account_id, 0, -1, EMAIL_ERROR_NONE); break; @@ -526,7 +526,7 @@ static void fail_status_notify(email_event_t *event_data, int error) 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); break; - + case EMAIL_EVENT_UPDATE_MAIL: emcore_execute_event_callback(EMAIL_ACTION_UPDATE_MAIL, 0, 0, EMAIL_UPDATE_MAIL_FAIL, account_id, 0, -1, EMAIL_ERROR_NONE); break; @@ -534,8 +534,8 @@ static void fail_status_notify(email_event_t *event_data, int error) case EMAIL_EVENT_EXPUNGE_MAILS_DELETED_FLAGGED: emcore_execute_event_callback(EMAIL_ACTION_EXPUNGE_MAILS_DELETED_FLAGGED, 0, 0, EMAIL_EXPUNGE_MAILS_DELETED_FLAGGED_FAIL, account_id, event_data->event_param_data_4, -1, EMAIL_ERROR_NONE); break; - - default: + + default: break; } EM_DEBUG_FUNC_END(); @@ -545,51 +545,51 @@ static void fail_status_notify(email_event_t *event_data, int error) static void emcore_initialize_event_callback_table() { ENTER_RECURSIVE_CRITICAL_SECTION(_event_callback_table_lock); - + int i; - + for (i = 0; i < EMAIL_ACTION_NUM; i++) _event_callback_table[i] = NULL; - + LEAVE_RECURSIVE_CRITICAL_SECTION(_event_callback_table_lock); } int emcore_register_event_callback(email_action_t action, email_event_callback callback, void *event_data) { EM_DEBUG_FUNC_BEGIN("action[%d], callback[%p], event_data[%p]", action, callback, event_data); - + if (callback == NULL) return false; - + int ret = false; - + ENTER_RECURSIVE_CRITICAL_SECTION(_event_callback_table_lock); - + EVENT_CALLBACK_LIST *node = _event_callback_table[action]; - + while (node != NULL) { if (node->callback == callback && node->event_data == event_data) /* already registered */ goto EXIT; - + node = node->next; } - + /* not found, so keep going */ - + node = em_malloc(sizeof(EVENT_CALLBACK_LIST)); if (node == NULL) /* not enough memory */ goto EXIT; - + node->callback = callback; node->event_data = event_data; node->next = _event_callback_table[action]; - + _event_callback_table[action] = node; ret = true; - -EXIT : + +EXIT : LEAVE_RECURSIVE_CRITICAL_SECTION(_event_callback_table_lock); EM_DEBUG_FUNC_END(); return ret; @@ -601,31 +601,31 @@ int emcore_unregister_event_callback(email_action_t action, email_event_callback if (callback == NULL) return false; - + int ret = false; - + ENTER_RECURSIVE_CRITICAL_SECTION(_event_callback_table_lock); - + EVENT_CALLBACK_LIST *prev = NULL; EVENT_CALLBACK_LIST *node = _event_callback_table[action]; - + while (node != NULL) { if (node->callback == callback) { if (prev != NULL) prev->next = node->next; else _event_callback_table[action] = node->next; - + free(node); - + ret = true; break; } - + prev = node; node = node->next; } - + LEAVE_RECURSIVE_CRITICAL_SECTION(_event_callback_table_lock); EM_DEBUG_FUNC_END(); return ret; @@ -634,18 +634,18 @@ int emcore_unregister_event_callback(email_action_t action, email_event_callback void emcore_execute_event_callback(email_action_t action, int total, int done, int status, int account_id, int mail_id, int handle, int error) { EM_DEBUG_FUNC_BEGIN("action[%d], total[%d], done[%d], status[%d], account_id[%d], mail_id[%d], handle[%d], error[%d]", action, total, done, status, account_id, mail_id, handle, error); - + int lock_needed = 0; lock_needed = is_gdk_lock_needed(); - + if (lock_needed) { /* Todo : g_thread_yield */ } - + ENTER_RECURSIVE_CRITICAL_SECTION(_event_callback_table_lock); EVENT_CALLBACK_LIST *node = _event_callback_table[action]; - + while (node != NULL) { if (node->callback != NULL) node->callback(total, done, status, account_id, mail_id, (handle == -1 ? emcore_get_active_queue_idx() : handle), node->event_data, error); @@ -653,7 +653,7 @@ void emcore_execute_event_callback(email_action_t action, int total, int done, i } LEAVE_RECURSIVE_CRITICAL_SECTION(_event_callback_table_lock); - + if (lock_needed) { } EM_DEBUG_FUNC_END(); @@ -663,7 +663,7 @@ void emcore_execute_event_callback(email_action_t action, int total, int done, i INTERNAL_FUNC int emcore_insert_event(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); - + if (!event_data) { EM_DEBUG_EXCEPTION("Invalid Parameter"); if (err_code != NULL) @@ -677,39 +677,39 @@ INTERNAL_FUNC int emcore_insert_event(email_event_t *event_data, int *handle, in *err_code = EMAIL_ERROR_LOAD_ENGINE_FAILURE; return false; } - + int ret = true; int error = EMAIL_ERROR_NONE; - + ENTER_RECURSIVE_CRITICAL_SECTION(_event_queue_lock); - + if (!g_event_que[g_event_que_idx].type) { /* if current buffer has not event, insert event data to current buffer */ EM_DEBUG_LOG("Current buffer has not a event. [%d]", g_event_que_idx); memcpy(g_event_que+g_event_que_idx, event_data, sizeof(email_event_t)); g_event_que[g_event_que_idx].status = EMAIL_EVENT_STATUS_WAIT; waiting_status_notify(event_data, g_event_que_idx); - if (handle) + if (handle) *handle = g_event_que_idx; } else { /* if current buffer has event, find the empty buffer */ EM_DEBUG_LOG("Current buffer has a event. [%d]", g_event_que_idx); - int i, j = g_event_que_idx + 1; - + int i, j = g_event_que_idx + 1; + for (i = 1; i < EVENT_QUEUE_MAX; i++, j++) { - if (j >= EVENT_QUEUE_MAX) + if (j >= EVENT_QUEUE_MAX) j = 1; - if (!g_event_que[j].type) + if (!g_event_que[j].type) break; - } + } if (i < EVENT_QUEUE_MAX) { - EM_DEBUG_LOG("I found available buffer. [%d]", g_event_que + j); + EM_DEBUG_LOG("I found available buffer. [%d]", g_event_que + j); memcpy(g_event_que+j, event_data, sizeof(email_event_t)); g_event_que[j].status = EMAIL_EVENT_STATUS_WAIT; waiting_status_notify(event_data, j); - - if (handle) + + if (handle) *handle = j; } else { @@ -718,52 +718,52 @@ INTERNAL_FUNC int emcore_insert_event(email_event_t *event_data, int *handle, in ret = false; } } - + LEAVE_RECURSIVE_CRITICAL_SECTION(_event_queue_lock); - + if (ret == true) { event_data->event_param_data_1 = NULL; /* MUST BE - to prevent double-free */ - + switch (event_data->type) { - case EMAIL_EVENT_SEND_MAIL: - case EMAIL_EVENT_SEND_MAIL_SAVED: + case EMAIL_EVENT_SEND_MAIL: + case EMAIL_EVENT_SEND_MAIL_SAVED: _sending_busy_ref(); break; - - case EMAIL_EVENT_SYNC_HEADER: - case EMAIL_EVENT_DOWNLOAD_BODY: - case EMAIL_EVENT_DOWNLOAD_ATTACHMENT: + + case EMAIL_EVENT_SYNC_HEADER: + case EMAIL_EVENT_DOWNLOAD_BODY: + case EMAIL_EVENT_DOWNLOAD_ATTACHMENT: case EMAIL_EVENT_SYNC_MAIL_FLAG_TO_SERVER: case EMAIL_EVENT_SYNC_FLAGS_FIELD_TO_SERVER: case EMAIL_EVENT_ISSUE_IDLE: - case EMAIL_EVENT_SYNC_IMAP_MAILBOX: - case EMAIL_EVENT_VALIDATE_ACCOUNT: + case EMAIL_EVENT_SYNC_IMAP_MAILBOX: + case EMAIL_EVENT_VALIDATE_ACCOUNT: case EMAIL_EVENT_VALIDATE_AND_CREATE_ACCOUNT: case EMAIL_EVENT_SAVE_MAIL: - case EMAIL_EVENT_MOVE_MAIL: - case EMAIL_EVENT_DELETE_MAIL: + case EMAIL_EVENT_MOVE_MAIL: + case EMAIL_EVENT_DELETE_MAIL: case EMAIL_EVENT_DELETE_MAIL_ALL: case EMAIL_EVENT_SYNC_HEADER_OMA: - case EMAIL_EVENT_CREATE_MAILBOX: - case EMAIL_EVENT_DELETE_MAILBOX: - case EMAIL_EVENT_VALIDATE_AND_UPDATE_ACCOUNT: - case EMAIL_EVENT_SET_MAIL_SLOT_SIZE: + case EMAIL_EVENT_CREATE_MAILBOX: + case EMAIL_EVENT_DELETE_MAILBOX: + case EMAIL_EVENT_VALIDATE_AND_UPDATE_ACCOUNT: + 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: _receiving_busy_ref(); break; - default: + default: break; } - + ENTER_CRITICAL_SECTION(_event_available_lock); WAKE_CONDITION_VARIABLE(_event_available_signal); LEAVE_CRITICAL_SECTION(_event_available_lock); } - -#ifdef __FEATURE_PARTIAL_BODY_DOWNLOAD__ + +#ifdef __FEATURE_PARTIAL_BODY_DOWNLOAD__ { int is_local_activity_event_inserted = false; @@ -775,10 +775,10 @@ INTERNAL_FUNC int emcore_insert_event(email_event_t *event_data, int *handle, in } } #endif - + if (err_code != NULL) *err_code = error; - + EM_DEBUG_LOG("Finish with [%d]", ret); return ret; } @@ -787,16 +787,16 @@ INTERNAL_FUNC int emcore_insert_event(email_event_t *event_data, int *handle, in static int emcore_retrieve_event(email_event_t *event_data, int *err_code) { EM_DEBUG_FUNC_BEGIN("event_data[%p], err_code[%p]", event_data, err_code); - + int ret = false; int error = EMAIL_ERROR_NONE; - + ENTER_RECURSIVE_CRITICAL_SECTION(_event_queue_lock); - + /* get a event_data if this queue is not empty */ if (g_event_que[g_event_que_idx].type) { memcpy(event_data, g_event_que+g_event_que_idx, sizeof(email_event_t)); - + if (event_data->status != EMAIL_EVENT_STATUS_WAIT) { /* EMAIL_EVENT_STATUS_CANCELED */ memset(g_event_que+g_event_que_idx, 0x00, sizeof(email_event_t)); g_active_que = 0; @@ -807,17 +807,17 @@ static int emcore_retrieve_event(email_event_t *event_data, int *err_code) g_active_que = g_event_que_idx; ret = true; } - + if (++g_event_que_idx >= EVENT_QUEUE_MAX) g_event_que_idx = 1; - + EM_DEBUG_LOG("g_event_que[%d].type [%d]", g_active_que, g_event_que[g_active_que].type); } else { g_active_que = 0; error = EMAIL_ERROR_EVENT_QUEUE_EMPTY; } - + LEAVE_RECURSIVE_CRITICAL_SECTION(_event_queue_lock); if (err_code != NULL) @@ -838,45 +838,45 @@ static int emcore_event_loop_continue() 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); - + if (!event_data) { EM_DEBUG_EXCEPTION("\t event_data[%p], handle[%p]", event_data, handle); - + if (err_code != NULL) *err_code = EMAIL_ERROR_INVALID_PARAM; return false; } - + int ret = true; int error = EMAIL_ERROR_NONE; - + ENTER_RECURSIVE_CRITICAL_SECTION(_send_event_queue_lock); - - if (!g_send_event_que[g_send_event_que_idx].type) { - /* if current buffer has not event_data, insert event_data data to current buffer */ + + if (!g_send_event_que[g_send_event_que_idx].type) { + /* if current buffer has not event_data, insert event_data data to current buffer */ EM_DEBUG_LOG("Current buffer has not a event_data. [%d]", g_send_event_que_idx); memcpy(g_send_event_que+g_send_event_que_idx, event_data, sizeof(email_event_t)); - + g_send_event_que[g_send_event_que_idx].status = EMAIL_EVENT_STATUS_WAIT; - - if (handle) + + if (handle) *handle = g_send_event_que_idx; } - else { + else { /* if current buffer has event_data, find the empty buffer */ EM_DEBUG_LOG("Current buffer has a event_data. [%d]", g_send_event_que_idx); - int i, j = g_send_event_que_idx + 1; - + int i, j = g_send_event_que_idx + 1; + for (i = 1; i < EVENT_QUEUE_MAX; i++, j++) { - if (j >= EVENT_QUEUE_MAX) + if (j >= EVENT_QUEUE_MAX) j = 1; - if (!g_send_event_que[j].type) + if (!g_send_event_que[j].type) break; - } - + } + if (i < EVENT_QUEUE_MAX) { - EM_DEBUG_LOG("I found available buffer. [%d]", j); + EM_DEBUG_LOG("I found available buffer. [%d]", j); memcpy(g_send_event_que+j, event_data, sizeof(email_event_t)); g_send_event_que[j].status = EMAIL_EVENT_STATUS_WAIT; if (handle) *handle = j; @@ -887,9 +887,9 @@ INTERNAL_FUNC int emcore_insert_event_for_sending_mails(email_event_t *event_dat ret = false; } } - + LEAVE_RECURSIVE_CRITICAL_SECTION(_send_event_queue_lock); - + if (ret == true) { ENTER_CRITICAL_SECTION(_send_event_available_lock); WAKE_CONDITION_VARIABLE(_send_event_available_signal); @@ -901,7 +901,7 @@ INTERNAL_FUNC int emcore_insert_event_for_sending_mails(email_event_t *event_dat if (err_code != NULL) *err_code = error; - + /* EM_DEBUG_FUNC_BEGIN(); */ return ret; } @@ -910,16 +910,16 @@ INTERNAL_FUNC int emcore_insert_event_for_sending_mails(email_event_t *event_dat static int emcore_retrieve_send_event(email_event_t *event_data, int *err_code) { EM_DEBUG_FUNC_BEGIN(); - + int ret = false; int error = EMAIL_ERROR_NONE; - + ENTER_RECURSIVE_CRITICAL_SECTION(_send_event_queue_lock); /* get a event_data if this queue is not empty */ if (g_send_event_que[g_send_event_que_idx].type) { memcpy(event_data, g_send_event_que+g_send_event_que_idx, sizeof(email_event_t)); - if (event_data->status != EMAIL_EVENT_STATUS_WAIT) { + if (event_data->status != EMAIL_EVENT_STATUS_WAIT) { memset(g_send_event_que+g_send_event_que_idx, 0x00, sizeof(email_event_t)); g_send_active_que = 0; } @@ -927,7 +927,7 @@ static int emcore_retrieve_send_event(email_event_t *event_data, int *err_code) g_send_event_que[g_send_event_que_idx].status = EMAIL_EVENT_STATUS_STARTED; EM_DEBUG_LOG("g_send_event_que_idx[%d]", g_send_event_que_idx); g_send_active_que = g_send_event_que_idx; - + ret = true; } @@ -946,7 +946,7 @@ static int emcore_retrieve_send_event(email_event_t *event_data, int *err_code) if (err_code != NULL) *err_code = error; - + return ret; } @@ -964,13 +964,13 @@ void* thread_func_branch_command_for_sending_mails(void *arg) } while (g_send_event_loop) { - if (!emcore_get_empty_session(&session)) + if (!emcore_get_empty_session(&session)) EM_DEBUG_EXCEPTION("\t SEND THREAD emcore_get_empty_session failed..."); if (!emcore_retrieve_send_event(&event_data, NULL)) { EM_DEBUG_LOG(">>>> waiting for send event_data>>>>>>>>>"); -#ifdef __FEATURE_LOCAL_ACTIVITY__ - if (send_thread_run && g_save_local_activity_run) { +#ifdef __FEATURE_LOCAL_ACTIVITY__ + if (send_thread_run && g_save_local_activity_run) { emstorage_account_tbl_t *account_list = NULL; int count = 0, i; if (!emstorage_get_account_list(&count, &account_list, true, true, &err)) { @@ -987,16 +987,16 @@ void* thread_func_branch_command_for_sending_mails(void *arg) } emstorage_free_account(&account_list, count, &err); - + if (!g_save_local_activity_run) { continue; - } + } } } -#endif +#endif send_thread_run = 0; - - ENTER_CRITICAL_SECTION(_send_event_available_lock); + + ENTER_CRITICAL_SECTION(_send_event_available_lock); SLEEP_CONDITION_VARIABLE(_send_event_available_signal, _send_event_available_lock); LEAVE_CRITICAL_SECTION(_send_event_available_lock); } @@ -1007,35 +1007,35 @@ void* thread_func_branch_command_for_sending_mails(void *arg) if (!emnetwork_check_network_status( &err)) { EM_DEBUG_EXCEPTION("emnetwork_check_network_status failed [%d]", err); - + emcore_show_user_message(event_data.event_param_data_4, EMAIL_ACTION_SEND_MAIL, err); if (!emcore_notify_network_event(NOTI_SEND_FAIL, event_data.account_id, NULL , event_data.event_param_data_4, err)) EM_DEBUG_EXCEPTION(" emcore_notify_network_event [ NOTI_SEND_FAIL] Failed >>>> "); - goto FINISH_OFF; + goto FINISH_OFF; } switch (event_data.type) { - - case EMAIL_EVENT_SEND_MAIL: + + case EMAIL_EVENT_SEND_MAIL: emdevice_set_dimming_on_off(false, NULL); - + if (!emcore_send_mail(event_data.account_id, event_data.event_param_data_5, event_data.event_param_data_4, &err)) EM_DEBUG_EXCEPTION("emcore_send_mail failed [%d]", err); - + emdevice_set_dimming_on_off(true, NULL); break; - + case EMAIL_EVENT_SEND_MAIL_SAVED: /* send mails to been saved in off-line mode */ emdevice_set_dimming_on_off(false, NULL); - + if (!emcore_send_saved_mail(event_data.account_id, event_data.event_param_data_3, &err)) EM_DEBUG_EXCEPTION("emcore_send_saved_mail failed - %d", err); - + emdevice_set_dimming_on_off(true, NULL); break; #ifdef __FEATURE_LOCAL_ACTIVITY__ - + case EMAIL_EVENT_LOCAL_ACTIVITY: { emdevice_set_dimming_on_off(false, NULL); emstorage_activity_tbl_t *local_activity = NULL; @@ -1074,13 +1074,13 @@ void* thread_func_branch_command_for_sending_mails(void *arg) } } break; - + default: { EM_DEBUG_LOG(">>>> No such Local Activity Handled by this thread [ %d ] >>> ", local_activity[0].activity_type); } break; } - + emstorage_free_local_activity(&local_activity, activity_chunk_count, NULL); if (g_save_local_activity_run == 1) { @@ -1098,23 +1098,23 @@ void* thread_func_branch_command_for_sending_mails(void *arg) emdevice_set_dimming_on_off(true, NULL); } break; -#endif /* __FEATURE_LOCAL_ACTIVITY__ */ - default: +#endif /* __FEATURE_LOCAL_ACTIVITY__ */ + default: EM_DEBUG_LOG("Others not supported by Send Thread..! [%d]", event_data.type); break; } - + ENTER_RECURSIVE_CRITICAL_SECTION(_send_event_queue_lock); memset(g_send_event_que+g_send_active_que, 0x00, sizeof(email_event_t)); LEAVE_RECURSIVE_CRITICAL_SECTION(_send_event_queue_lock); -FINISH_OFF: +FINISH_OFF: ; } emcore_clear_session(session); - } + } - if (!emstorage_close(&err)) + if (!emstorage_close(&err)) EM_DEBUG_EXCEPTION("emstorage_close falied [%d]", err); EM_DEBUG_FUNC_END("err [%d]", err); @@ -1154,12 +1154,12 @@ int event_handler_EMAIL_EVENT_SYNC_HEADER(int input_account_id, int input_mailbo if (!emcore_notify_network_event(NOTI_DOWNLOAD_START, input_account_id, input_mailbox_id_str, handle_to_be_published, 0)) EM_DEBUG_EXCEPTION("emcore_notify_network_event [ NOTI_DOWNLOAD_START] Failed >>>> "); - + if (!emnetwork_check_network_status(&err)) { EM_DEBUG_EXCEPTION("emnetwork_check_network_status failed [%d]", err); - + if (!emcore_notify_network_event(NOTI_DOWNLOAD_FAIL, input_account_id, input_mailbox_id_str, handle_to_be_published, err)) - EM_DEBUG_EXCEPTION(" emcore_notify_network_event [ NOTI_DOWNLOAD_FAIL] Failed >>>> "); + EM_DEBUG_EXCEPTION(" emcore_notify_network_event [ NOTI_DOWNLOAD_FAIL] Failed >>>> "); } else { if (sync_type != EMAIL_SYNC_ALL_MAILBOX) { /* Sync only particular mailbox */ @@ -1174,12 +1174,12 @@ int event_handler_EMAIL_EVENT_SYNC_HEADER(int input_account_id, int input_mailbo if (!emcore_sync_header(mailbox_tbl_target, mailbox_tbl_spam, NULL, &uid_list, &unread, &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 >>>> "); + EM_DEBUG_EXCEPTION(" emcore_notify_network_event [NOTI_DOWNLOAD_FAIL] Failed >>>> "); } else { EM_DEBUG_LOG("emcore_sync_header succeeded [%d]", err); 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 >>>> "); + EM_DEBUG_EXCEPTION("emcore_notify_network_event [NOTI_DOWNLOAD_FINISH] Failed >>>> "); } total_unread += unread; @@ -1201,37 +1201,37 @@ int event_handler_EMAIL_EVENT_SYNC_HEADER(int input_account_id, int input_mailbo if (!emstorage_get_account_list(&account_count, &account_tbl_array , true, false, &err)) { EM_DEBUG_EXCEPTION("emstorage_get_account_list failed [ %d ] ", err); if (!emcore_notify_network_event(NOTI_DOWNLOAD_FAIL, input_account_id, NULL, handle_to_be_published, err)) - EM_DEBUG_EXCEPTION(" emcore_notify_network_event [ NOTI_DOWNLOAD_FAIL] Failed >>>> "); + EM_DEBUG_EXCEPTION(" emcore_notify_network_event [ NOTI_DOWNLOAD_FAIL] Failed >>>> "); goto FINISH_OFF; } } else { - EM_DEBUG_LOG("Sync all mailbox of an account[%d].", input_account_id); + EM_DEBUG_LOG("Sync all mailbox of an account[%d].", input_account_id); 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 (!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 (!emcore_notify_network_event(NOTI_DOWNLOAD_FAIL, input_account_id, input_mailbox_id_str, handle_to_be_published, err)) - EM_DEBUG_EXCEPTION(" emcore_notify_network_event [ NOTI_DOWNLOAD_FAIL] Failed >>>> "); + EM_DEBUG_EXCEPTION(" emcore_notify_network_event [ NOTI_DOWNLOAD_FAIL] Failed >>>> "); goto FINISH_OFF; } account_count = 1; } - + for (account_index = 0 ; account_index < account_count; account_index++) { if (account_tbl_array[account_index].incoming_server_type == EMAIL_SERVER_TYPE_ACTIVE_SYNC) { EM_DEBUG_LOG("account[%d] is for ActiveSync. Skip ", account_index); continue; } - - 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) { + + 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) { EM_DEBUG_EXCEPTION("emstorage_get_mailbox failed [%d]", err); - + if (!emcore_notify_network_event(NOTI_DOWNLOAD_FAIL, account_tbl_array[account_index].account_id, input_mailbox_id_str, handle_to_be_published, err)) - EM_DEBUG_EXCEPTION(" emcore_notify_network_event [ NOTI_DOWNLOAD_FAIL] Failed >>>> "); - + EM_DEBUG_EXCEPTION(" emcore_notify_network_event [ NOTI_DOWNLOAD_FAIL] Failed >>>> "); + continue; } @@ -1259,22 +1259,22 @@ int event_handler_EMAIL_EVENT_SYNC_HEADER(int input_account_id, int input_mailbo EM_DEBUG_EXCEPTION("EMAIL_ERROR_LOGIN_FAILURE "); /* continue; */ if (!emcore_notify_network_event(NOTI_DOWNLOAD_FAIL, account_tbl_array[account_index].account_id, mailbox_id_param_string, handle_to_be_published, err)) - EM_DEBUG_EXCEPTION(" emcore_notify_network_event [NOTI_DOWNLOAD_FAIL] Failed >>>> "); + EM_DEBUG_EXCEPTION(" emcore_notify_network_event [NOTI_DOWNLOAD_FAIL] Failed >>>> "); continue; } EM_DEBUG_LOG("emcore_connect_to_remote_mailbox returns [%d] : ", err); } - else + else stream = NULL; #endif } - + for (counter = 0; counter < mailbox_count; counter++) { EM_DEBUG_LOG("maiblox_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); - if ( mailbox_tbl_list[counter].mailbox_type == EMAIL_MAILBOX_TYPE_ALL_EMAILS - || mailbox_tbl_list[counter].mailbox_type == EMAIL_MAILBOX_TYPE_TRASH + 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 */) EM_DEBUG_LOG("Skipped for all emails or trash"); else if (!mailbox_tbl_list[counter].local_yn) { @@ -1283,13 +1283,13 @@ int event_handler_EMAIL_EVENT_SYNC_HEADER(int input_account_id, int input_mailbo if (!emcore_sync_header((mailbox_tbl_list + counter) , mailbox_tbl_spam, NULL, &uid_list, &unread, &err)) { #else /* __FEATURE_KEEP_CONNECTION__ */ if (!emcore_sync_header((mailbox_tbl_list + counter) , mailbox_tbl_spam, (void *)stream, &uid_list, &unread, &err)) { -#endif /* __FEATURE_KEEP_CONNECTION__ */ +#endif /* __FEATURE_KEEP_CONNECTION__ */ EM_DEBUG_EXCEPTION("emcore_sync_header for %s(mailbox_id = %d) failed [%d]", mailbox_tbl_list[counter].mailbox_name, mailbox_tbl_list[counter].mailbox_id, err); #ifndef __FEATURE_KEEP_CONNECTION__ - if (err == EMAIL_ERROR_CONNECTION_BROKEN || err == EMAIL_ERROR_NO_SUCH_HOST || err == EMAIL_ERROR_SOCKET_FAILURE) + if (err == EMAIL_ERROR_CONNECTION_BROKEN || err == EMAIL_ERROR_NO_SUCH_HOST || err == EMAIL_ERROR_SOCKET_FAILURE) stream = NULL; /* Don't retry to connect for broken connection. It might cause crash. */ -#endif /* __FEATURE_KEEP_CONNECTION__ */ +#endif /* __FEATURE_KEEP_CONNECTION__ */ memset(mailbox_id_param_string, 0, 10); SNPRINTF(mailbox_id_param_string, 10, "%d", mailbox_tbl_list[counter].mailbox_id); if (!emcore_notify_network_event(NOTI_DOWNLOAD_FAIL, account_tbl_array[account_index].account_id, mailbox_id_param_string, handle_to_be_published, err)) @@ -1300,10 +1300,10 @@ int event_handler_EMAIL_EVENT_SYNC_HEADER(int input_account_id, int input_mailbo } total_unread += unread; } - + EM_DEBUG_LOG("Sync for account_id(%d) is completed....!", account_tbl_array[account_index].account_id); 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 >>>> "); + 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); @@ -1326,10 +1326,10 @@ int event_handler_EMAIL_EVENT_SYNC_HEADER(int input_account_id, int input_mailbo ret = true; -FINISH_OFF: +FINISH_OFF: #ifndef __FEATURE_KEEP_CONNECTION__ - if (stream) + if (stream) emcore_close_mailbox(0, stream); #endif if(mailbox_tbl_target) @@ -1339,7 +1339,7 @@ FINISH_OFF: emstorage_free_mailbox(&mailbox_tbl_list, mailbox_count, NULL); if (account_tbl_array) - emstorage_free_account(&account_tbl_array, account_count, NULL); + emstorage_free_account(&account_tbl_array, account_count, NULL); } EM_DEBUG_FUNC_END(); @@ -1358,12 +1358,12 @@ int event_handler_EMAIL_EVENT_VALIDATE_AND_CREATE_ACCOUNT(email_account_t *accou } EM_DEBUG_LOG("incoming_server_address : %s", account->incoming_server_address); - + if (!emnetwork_check_network_status(&err)) { EM_DEBUG_EXCEPTION("emnetwork_check_network_status failed [%d]", err); if (!emcore_notify_network_event(NOTI_VALIDATE_AND_CREATE_ACCOUNT_FAIL, account->account_id, NULL, handle_to_be_published, err)) - EM_DEBUG_EXCEPTION(" emcore_notify_network_event [ NOTI_VALIDATE_ACCOUNT_FAIL] Failed >>>> "); + EM_DEBUG_EXCEPTION(" emcore_notify_network_event [ NOTI_VALIDATE_ACCOUNT_FAIL] Failed >>>> "); goto FINISH_OFF; } else { @@ -1384,12 +1384,12 @@ int event_handler_EMAIL_EVENT_VALIDATE_AND_CREATE_ACCOUNT(email_account_t *accou emcore_delete_account_from_unvalidated_account_list(account->account_id); if (emcore_create_account(account, &err) == false) { - EM_DEBUG_EXCEPTION(" emdaemon_create_account failed - %d", err); + EM_DEBUG_EXCEPTION(" emdaemon_create_account failed - %d", err); goto FINISH_OFF; - } + } emcore_refresh_account_reference(); - + EM_DEBUG_LOG("incoming_server_type [%d]", account->incoming_server_type); if ((EMAIL_SERVER_TYPE_IMAP4 == account->incoming_server_type)) { @@ -1398,22 +1398,22 @@ int event_handler_EMAIL_EVENT_VALIDATE_AND_CREATE_ACCOUNT(email_account_t *accou /* delete account whose mailbox couldn't be obtained from server */ emcore_delete_account(account->account_id, 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)) - EM_DEBUG_EXCEPTION("emcore_notify_network_event [ NOTI_VALIDATE_ACCOUNT_FINISH] Success"); + EM_DEBUG_EXCEPTION("emcore_notify_network_event [ NOTI_VALIDATE_ACCOUNT_FINISH] Success"); } } ret = true; -FINISH_OFF: +FINISH_OFF: if (ret == false && err != EMAIL_ERROR_CANCELLED && account) { if (!emcore_notify_network_event(NOTI_VALIDATE_AND_CREATE_ACCOUNT_FAIL, account->account_id, NULL, handle_to_be_published, err)) - EM_DEBUG_EXCEPTION(" emcore_notify_network_event [ NOTI_VALIDATE_AND_CREATE_ACCOUNT_FAIL] Failed"); + EM_DEBUG_EXCEPTION(" emcore_notify_network_event [ NOTI_VALIDATE_AND_CREATE_ACCOUNT_FAIL] Failed"); } if (error) @@ -1427,7 +1427,7 @@ int event_handler_EMAIL_EVENT_VALIDATE_AND_UPDATE_ACCOUNT(int account_id, email_ { EM_DEBUG_FUNC_BEGIN("account_id [%d], new_account_info [%p]", account_id, new_account_info); int err, ret = false; - emstorage_account_tbl_t *old_account_tbl = NULL, *new_account_tbl = NULL; + emstorage_account_tbl_t *old_account_tbl = NULL, *new_account_tbl = NULL; if (!new_account_info) { EM_DEBUG_EXCEPTION("Invalid Parameter"); @@ -1439,7 +1439,7 @@ int event_handler_EMAIL_EVENT_VALIDATE_AND_UPDATE_ACCOUNT(int account_id, email_ 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)) - EM_DEBUG_EXCEPTION("emcore_notify_network_event [ NOTI_VALIDATE_AND_UPDATE_ACCOUNT_FAIL] Failed >>>> "); + EM_DEBUG_EXCEPTION("emcore_notify_network_event [ NOTI_VALIDATE_AND_UPDATE_ACCOUNT_FAIL] Failed >>>> "); goto FINISH_OFF; } else { @@ -1474,10 +1474,10 @@ int event_handler_EMAIL_EVENT_VALIDATE_AND_UPDATE_ACCOUNT(int account_id, email_ if (emstorage_update_account(account_id, new_account_tbl, true, &err)) { emcore_refresh_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_EXCEPTION(" emcore_notify_network_event [NOTI_VALIDATE_AND_UPDATE_ACCOUNT_FINISH] Success"); + EM_DEBUG_EXCEPTION(" emcore_notify_network_event [NOTI_VALIDATE_AND_UPDATE_ACCOUNT_FINISH] Success"); } } @@ -1488,15 +1488,15 @@ FINISH_OFF: 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)) - EM_DEBUG_EXCEPTION(" emcore_notify_network_event [ NOTI_VALIDATE_AND_CREATE_ACCOUNT_FAIL] Failed"); + EM_DEBUG_EXCEPTION(" emcore_notify_network_event [ NOTI_VALIDATE_AND_CREATE_ACCOUNT_FAIL] Failed"); } if (error) *error = err; - + EM_DEBUG_FUNC_END(); return ret; } @@ -1532,7 +1532,7 @@ FINISH_OFF: return err; } -#ifdef __FEATURE_LOCAL_ACTIVITY__ +#ifdef __FEATURE_LOCAL_ACTIVITY__ int event_handler_EMAIL_EVENT_LOCAL_ACTIVITY(int account_id, int *error) { EM_DEBUG_FUNC_BEGIN(); @@ -1545,94 +1545,94 @@ int event_handler_EMAIL_EVENT_LOCAL_ACTIVITY(int account_id, int *error) int *activity_id_list = NULL; int i = 0; - if (!emnetwork_check_network_status(&err)) + if (!emnetwork_check_network_status(&err)) EM_DEBUG_EXCEPTION("emnetwork_check_network_status failed [%d]", err); else { if (false == emstorage_get_activity_id_list(account_id, &activity_id_list, &activity_id_count, ACTIVITY_DELETEMAIL, ACTIVITY_COPYMAIL, true, &err)) { EM_DEBUG_EXCEPTION("emstorage_get_activity_id_list failed [%d]", err); } - else { + else { for (i = 0; i < activity_id_count; ++i) { if ((false == emstorage_get_activity(account_id , activity_id_list[i], &local_activity, &activity_chunk_count, true, &err)) || (NULL == local_activity) || (0 == activity_chunk_count)) EM_DEBUG_EXCEPTION(" emstorage_get_activity Failed [ %d] or local_activity is NULL [%p] or activity_chunk_count is 0[%d]", err, local_activity, activity_chunk_count); - else { - EM_DEBUG_LOG("Found local activity type - %d", local_activity[0].activity_type); - switch (local_activity[0].activity_type) { + else { + EM_DEBUG_LOG("Found local activity type - %d", local_activity[0].activity_type); + switch (local_activity[0].activity_type) { case ACTIVITY_MODIFYFLAG: { if (emcore_sync_flag_with_server(local_activity[0].mail_id , &err)) { if (!emcore_delete_activity(&local_activity[0], &err)) EM_DEBUG_EXCEPTION(">>>>>>Local Activity [ACTIVITY_MODIFYFLAG] [%d] ", err); - } + } } break; - - case ACTIVITY_DELETEMAIL: - case ACTIVITY_MOVEMAIL: - case ACTIVITY_MODIFYSEENFLAG: + + case ACTIVITY_DELETEMAIL: + case ACTIVITY_MOVEMAIL: + case ACTIVITY_MODIFYSEENFLAG: case ACTIVITY_COPYMAIL: { - + int j = 0, k = 0; int total_mail_ids = activity_chunk_count; - + int *mail_id_list = NULL; mail_id_list = (int *)em_malloc(sizeof(int) * total_mail_ids); - + if (NULL == mail_id_list) { EM_DEBUG_EXCEPTION("malloc failed... "); break; } - + do { - + for (j = 0; j < BULK_OPERATION_COUNT && (k < total_mail_ids); ++j, ++k) - mail_id_list[j] = local_activity[k].mail_id; + mail_id_list[j] = local_activity[k].mail_id; switch (local_activity[k-1].activity_type) { case ACTIVITY_DELETEMAIL: { - if (!emcore_delete_mail(local_activity[k-1].account_id, - mail_id_list, - j, - EMAIL_DELETE_LOCAL_AND_SERVER, + if (!emcore_delete_mail(local_activity[k-1].account_id, + mail_id_list, + j, + EMAIL_DELETE_LOCAL_AND_SERVER, EMAIL_DELETED_BY_COMMAND, false, - &err)) + &err)) EM_DEBUG_LOG("\t emcore_delete_mail failed - %d", err); } break; - + case ACTIVITY_MOVEMAIL: { - if (!emcore_move_mail_on_server_ex(local_activity[k-1].account_id , - local_activity[k-1].src_mbox, - mail_id_list, - j, - local_activity[k-1].dest_mbox, + if (!emcore_move_mail_on_server_ex(local_activity[k-1].account_id , + local_activity[k-1].src_mbox, + mail_id_list, + j, + local_activity[k-1].dest_mbox, &err)) EM_DEBUG_LOG("\t emcore_move_mail_on_server_ex failed - %d", err); - } + } break; - case ACTIVITY_MODIFYSEENFLAG: { + case ACTIVITY_MODIFYSEENFLAG: { int seen_flag = atoi(local_activity[0].src_mbox); if (!emcore_sync_seen_flag_with_server_ex(mail_id_list, j , seen_flag , &err)) /* local_activity[0].src_mbox points to the seen flag */ EM_DEBUG_EXCEPTION("\t emcore_sync_seen_flag_with_server_ex failed - %d", err); } break; } - + } while (k < total_mail_ids); EM_SAFE_FREE(mail_id_list); - } - + } + break; - - default: + + default: EM_DEBUG_LOG(">>>> No such Local Activity Handled by this thread [ %d ] >>> ", local_activity[0].activity_type); break; } - + emstorage_free_local_activity(&local_activity, activity_chunk_count, NULL); - + if (g_local_activity_run == 1) { EM_DEBUG_LOG(" Network event_data found.. Local sync Stopped..! "); break; @@ -1645,7 +1645,7 @@ int event_handler_EMAIL_EVENT_LOCAL_ACTIVITY(int account_id, int *error) if (false == emstorage_free_activity_id_list(activity_id_list, &err)) EM_DEBUG_EXCEPTION("emstorage_free_activity_id_list failed"); } - + if (error) *error = err; @@ -1661,27 +1661,27 @@ int event_handler_EMAIL_EVENT_DOWNLOAD_BODY(int account_id, int mail_id, int opt int err = EMAIL_ERROR_NONE; email_mailbox_t mailbox; - + memset(&mailbox, 0x00, sizeof(mailbox)); mailbox.account_id = account_id; - + if (!emnetwork_check_network_status(&err)) { EM_DEBUG_EXCEPTION("emnetwork_check_network_status failed [%d]", err); emcore_notify_network_event(NOTI_DOWNLOAD_BODY_FAIL, mail_id, NULL, handle_to_be_published, err); } else { - if (!emcore_download_body_multi_sections_bulk(NULL, - mailbox.account_id, - mail_id, + 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, + NO_LIMITATION, + handle_to_be_published, &err)) EM_DEBUG_EXCEPTION("emcore_download_body_multi_sections_bulk failed - %d", err); - } - + } + if (error) *error = err; @@ -1696,7 +1696,7 @@ int event_handler_EMAIL_EVENT_DOWNLOAD_ATTACHMENT(int account_id, int mail_id, i int err = EMAIL_ERROR_NONE; EM_DEBUG_LOG("attachment_no is %d", attachment_no); - + if (!emnetwork_check_network_status(&err)) { EM_DEBUG_EXCEPTION("emnetwork_check_network_status failed [%d]", err); emcore_notify_network_event(NOTI_DOWNLOAD_ATTACH_FAIL, mail_id, NULL, attachment_no, err); @@ -1710,8 +1710,8 @@ int event_handler_EMAIL_EVENT_DOWNLOAD_ATTACHMENT(int account_id, int mail_id, i if (!emcore_download_attachment(account_id, mail_id, attachment_no, &err)) EM_DEBUG_EXCEPTION("\t emcore_download_attachment failed [%d]", err); #endif - } - + } + if (error) *error = err; @@ -1724,10 +1724,10 @@ int event_handler_EMAIL_EVENT_SYNC_FLAGS_FIELD_TO_SERVER(int mail_ids[], int num EM_DEBUG_FUNC_BEGIN(); int err = EMAIL_ERROR_NONE; - - if (!emnetwork_check_network_status(&err)) + + if (!emnetwork_check_network_status(&err)) EM_DEBUG_EXCEPTION("dnet_init failed [%d]", err); - else if (!emcore_sync_flags_field_with_server(mail_ids, num, field_type, value, &err)) + else if (!emcore_sync_flags_field_with_server(mail_ids, num, field_type, value, &err)) EM_DEBUG_EXCEPTION("emcore_sync_flags_field_with_server failed [%d]", err); if (error) @@ -1745,12 +1745,12 @@ int event_handler_EMAIL_EVENT_VALIDATE_ACCOUNT(int account_id, int handle_to_be_ if (!emnetwork_check_network_status(&err)) { EM_DEBUG_EXCEPTION("emnetwork_check_network_status failed [%d]", err); - + if (!emcore_notify_network_event(NOTI_VALIDATE_ACCOUNT_FAIL, account_id, NULL, handle_to_be_published, err)) - EM_DEBUG_EXCEPTION("emcore_notify_network_event [ NOTI_VALIDATE_ACCOUNT_FAIL] Failed >>>>"); + EM_DEBUG_EXCEPTION("emcore_notify_network_event [ NOTI_VALIDATE_ACCOUNT_FAIL] Failed >>>>"); } else { - + if (!emcore_validate_account(account_id, &err)) { EM_DEBUG_EXCEPTION("emcore_validate_account failed account id : %d err : %d", account_id, err); @@ -1761,7 +1761,7 @@ int event_handler_EMAIL_EVENT_VALIDATE_ACCOUNT(int account_id, int handle_to_be_ } else { if (!emcore_notify_network_event(NOTI_VALIDATE_ACCOUNT_FAIL, account_id, NULL, handle_to_be_published, err)) - EM_DEBUG_EXCEPTION("emcore_notify_network_event [ NOTI_VALIDATE_ACCOUNT_FAIL] Failed >>>> "); + EM_DEBUG_EXCEPTION("emcore_notify_network_event [ NOTI_VALIDATE_ACCOUNT_FAIL] Failed >>>> "); } } else { @@ -1771,16 +1771,16 @@ int event_handler_EMAIL_EVENT_VALIDATE_ACCOUNT(int account_id, int handle_to_be_ 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()) + if (!emcore_check_thread_status()) 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); } - + if (err > 0) { EM_DEBUG_EXCEPTION("emcore_validate_account succeeded account id : %d err : %d", account_id, err); if (!emcore_notify_network_event(NOTI_VALIDATE_ACCOUNT_FINISH, account_id, NULL, handle_to_be_published, err)) - EM_DEBUG_EXCEPTION("emcore_notify_network_event [ NOTI_VALIDATE_ACCOUNT_FINISH] Success >>>>"); + EM_DEBUG_EXCEPTION("emcore_notify_network_event [ NOTI_VALIDATE_ACCOUNT_FINISH] Success >>>>"); } } } @@ -1798,7 +1798,7 @@ int event_handler_EMAIL_EVENT_UPDATE_MAIL(email_mail_data_t *input_mail_data, em 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); int err = EMAIL_ERROR_NONE; - if ( (err = emcore_update_mail(input_mail_data, input_attachment_data_list, input_attachment_count, input_meeting_request, input_from_eas)) != EMAIL_ERROR_NONE) + if ( (err = emcore_update_mail(input_mail_data, input_attachment_data_list, input_attachment_count, input_meeting_request, input_from_eas)) != EMAIL_ERROR_NONE) EM_DEBUG_EXCEPTION("emcore_update_mail failed [%d]", err); if(input_mail_data) @@ -1846,7 +1846,7 @@ int event_handler_EMAIL_EVENT_MOVE_MAIL(int account_id, int *mail_ids, int mail_ if (account_ref->incoming_server_type == EMAIL_SERVER_TYPE_IMAP4) { /* Move mail on server */ - if (!emnetwork_check_network_status(&err)) + if (!emnetwork_check_network_status(&err)) EM_DEBUG_EXCEPTION("emnetwork_check_network_status failed [%d]", err); else { #ifdef __FEATURE_BULK_DELETE_MOVE_UPDATE_REQUEST_OPTI__ @@ -1873,8 +1873,8 @@ int event_handler_EMAIL_EVENT_DELETE_MAILBOX(int mailbox_id, int on_server, int { EM_DEBUG_FUNC_BEGIN("mailbox_id [%d], on_server [%d], handle_to_be_published [%d], error [%p]", mailbox_id, on_server, handle_to_be_published, error); int err = EMAIL_ERROR_NONE; - - if (!emnetwork_check_network_status(&err)) + + if (!emnetwork_check_network_status(&err)) EM_DEBUG_EXCEPTION("emnetwork_check_network_status failed [%d]", err); else { if (!emcore_delete_mailbox(mailbox_id, on_server, &err)) @@ -1900,12 +1900,12 @@ int event_handler_EMAIL_EVENT_CREATE_MAILBOX(int account_id, char *mailbox_name, mailbox.mailbox_name = mailbox_name; mailbox.alias = mailbox_alias; mailbox.mailbox_type = mailbox_type; - + if (!emnetwork_check_network_status(&err)) { EM_DEBUG_EXCEPTION("emnetwork_check_network_status failed [%d]", err); } else { - if (!emcore_create_mailbox(&mailbox, on_server, &err)) + if (!emcore_create_mailbox(&mailbox, on_server, &err)) EM_DEBUG_EXCEPTION("emcore_create failed - %d", err); } @@ -1923,7 +1923,7 @@ int event_handler_EMAIL_EVENT_SYNC_MAIL_FLAG_TO_SERVER(int mail_id, int *error) int err = EMAIL_ERROR_NONE; - if (!emnetwork_check_network_status(&err)) + 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)) @@ -1938,10 +1938,10 @@ int event_handler_EMAIL_EVENT_SYNC_MAIL_FLAG_TO_SERVER(int mail_id, int *error) new_activity.dest_mbox = NULL; new_activity.server_mailid = NULL; new_activity.src_mbox = NULL; - + if (!emcore_delete_activity(&new_activity, &err)) EM_DEBUG_EXCEPTION(">>>>>>Local Activity [ACTIVITY_MODIFYFLAG] [%d] ", err); - } + } #endif /* __FEATURE_LOCAL_ACTIVITY__ */ } @@ -1956,7 +1956,7 @@ int event_handler_EMAIL_EVENT_DELETE_MAIL_ALL(int input_account_id, int input_ma { EM_DEBUG_FUNC_BEGIN("input_account_id [%d] input_mailbox_id [%d], input_from_server [%d], error [%p]", input_account_id, input_mailbox_id, input_from_server, error); int err = EMAIL_ERROR_NONE; - + if (!emcore_delete_all_mails_of_mailbox(input_account_id, input_mailbox_id, input_from_server, &err)) EM_DEBUG_EXCEPTION("emcore_delete_all_mails_of_mailbox failed [%d]", err); @@ -1999,11 +1999,11 @@ int event_hanlder_EMAIL_EVENT_SYNC_HEADER_OMA(int account_id, char *maibox_name, { 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); if (!emcore_notify_network_event(NOTI_DOWNLOAD_FAIL, account_id, maibox_name, 0, err)) - EM_DEBUG_EXCEPTION("emcore_notify_network_event [NOTI_DOWNLOAD_FAIL] Failed"); + EM_DEBUG_EXCEPTION("emcore_notify_network_event [NOTI_DOWNLOAD_FAIL] Failed"); } else { EM_DEBUG_LOG("Sync of all mailbox"); @@ -2031,7 +2031,7 @@ int event_handler_EMAIL_EVENT_SEARCH_ON_SERVER(int account_id, int mailbox_id, c 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; @@ -2053,7 +2053,7 @@ int event_handler_EMAIL_EVENT_SEARCH_ON_SERVER(int account_id, int mailbox_id, c 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)) @@ -2067,7 +2067,7 @@ int event_handler_EMAIL_EVENT_SEARCH_ON_SERVER(int account_id, int mailbox_id, c 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)) @@ -2079,21 +2079,21 @@ int event_handler_EMAIL_EVENT_SEARCH_ON_SERVER(int account_id, int mailbox_id, c 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(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"); @@ -2107,7 +2107,7 @@ int event_handler_EMAIL_EVENT_SEARCH_ON_SERVER(int account_id, int mailbox_id, c 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)) @@ -2127,14 +2127,14 @@ int event_handler_EMAIL_EVENT_SEARCH_ON_SERVER(int account_id, int mailbox_id, c } } - if (err == EMAIL_ERROR_NONE && !emcore_notify_network_event(NOTI_SEARCH_ON_SERVER_FINISH, account_id, NULL, handle_to_be_published, 0)) + 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 (search_mailbox != NULL) - emstorage_free_mailbox(&search_mailbox, 1, NULL); - + if (search_mailbox != NULL) + emstorage_free_mailbox(&search_mailbox, 1, NULL); + if (new_mail_tbl_data) emstorage_free_mail(&new_mail_tbl_data, 1, NULL); @@ -2142,7 +2142,7 @@ FINISH_OFF: emstorage_free_mailbox(&local_mailbox, 1, NULL); if (error) - *error = err; + *error = err; EM_DEBUG_FUNC_END(); return true; @@ -2176,7 +2176,7 @@ static int event_handler_EMAIL_EVENT_RENAME_MAILBOX_ON_IMAP_SERVER(int input_acc void* thread_func_branch_command(void *arg) { EM_DEBUG_FUNC_BEGIN(); - + int err = EMAIL_ERROR_NONE; int is_storage_full = false; int noti_id = 0; @@ -2192,13 +2192,13 @@ void* thread_func_branch_command(void *arg) /* check that event_data loop is continuous */ while (emcore_event_loop_continue()) { - if (!emcore_get_empty_session(&session)) + if (!emcore_get_empty_session(&session)) EM_DEBUG_EXCEPTION("emcore_get_empty_session failed..."); - + /* get a event_data from event_data queue */ if (!emcore_retrieve_event(&event_data, NULL)) { /* no event_data pending */ EM_DEBUG_LOG("For handle g_event_que[g_event_que_idx].type [%d], g_event_que_idx [%d]", g_event_que[g_event_que_idx].type, g_event_que_idx); -#ifdef ENABLE_IMAP_IDLE_THREAD +#ifdef ENABLE_IMAP_IDLE_THREAD if ( !emnetwork_check_network_status(&err)) { EM_DEBUG_LOG(">>>> Data Networking ON "); if (g_client_run) { @@ -2213,12 +2213,12 @@ void* thread_func_branch_command(void *arg) } } #endif /* ENABLE_IMAP_IDLE_THREAD */ -#ifdef __FEATURE_LOCAL_ACTIVITY__ +#ifdef __FEATURE_LOCAL_ACTIVITY__ /* Local activity sync */ - if (g_client_run && g_local_activity_run) { + if (g_client_run && g_local_activity_run) { emstorage_account_tbl_t *account_list = NULL; int count = 0, i; - if (!emstorage_get_account_list(&count, &account_list, true, true, &err)) + if (!emstorage_get_account_list(&count, &account_list, true, true, &err)) EM_DEBUG_EXCEPTION("emstorage_get_account_list failed [%d]", err); else { for (i = 0; i < count; i++) { @@ -2229,9 +2229,9 @@ void* thread_func_branch_command(void *arg) emcore_clear_session(session); } } - + emstorage_free_account(&account_list, count, &err); - + if (!g_local_activity_run) continue; } @@ -2239,7 +2239,7 @@ void* thread_func_branch_command(void *arg) #endif recv_thread_run = 0; - + ENTER_CRITICAL_SECTION(_event_available_lock); SLEEP_CONDITION_VARIABLE(_event_available_signal, _event_available_lock); EM_DEBUG_LOG("Wake up by _event_available_signal"); @@ -2253,34 +2253,34 @@ void* thread_func_branch_command(void *arg) handle_to_be_published = 31; else handle_to_be_published = g_event_que_idx - 1 ; - + EM_DEBUG_LOG("Handle to be Published [%d]", handle_to_be_published); recv_thread_run = 1; g_client_run = 1; /* Handling storage full */ is_storage_full = false; - if (event_data.type == EMAIL_EVENT_SYNC_HEADER || event_data.type == EMAIL_EVENT_SYNC_HEADER_OMA || + if (event_data.type == EMAIL_EVENT_SYNC_HEADER || event_data.type == EMAIL_EVENT_SYNC_HEADER_OMA || event_data.type == EMAIL_EVENT_DOWNLOAD_BODY || event_data.type == EMAIL_EVENT_DOWNLOAD_ATTACHMENT) { if (emcore_is_storage_full(&err) == true) { EM_DEBUG_EXCEPTION("Storage is full"); switch (event_data.type) { - case EMAIL_EVENT_SYNC_HEADER: + case EMAIL_EVENT_SYNC_HEADER: case EMAIL_EVENT_SYNC_HEADER_OMA: noti_id = NOTI_DOWNLOAD_FAIL; break; - case EMAIL_EVENT_DOWNLOAD_BODY: + case EMAIL_EVENT_DOWNLOAD_BODY: noti_id = NOTI_DOWNLOAD_BODY_FAIL; break; - case EMAIL_EVENT_DOWNLOAD_ATTACHMENT: + case EMAIL_EVENT_DOWNLOAD_ATTACHMENT: noti_id = NOTI_DOWNLOAD_ATTACH_FAIL; break; - default: + default: break; } - + if (!emcore_notify_network_event(noti_id, event_data.account_id, NULL, handle_to_be_published, err)) - EM_DEBUG_EXCEPTION(" emcore_notify_network_event [NOTI_DOWNLOAD_FAIL] Failed >>>> "); + EM_DEBUG_EXCEPTION(" emcore_notify_network_event [NOTI_DOWNLOAD_FAIL] Failed >>>> "); is_storage_full = true; } } @@ -2436,50 +2436,50 @@ void* thread_func_branch_command(void *arg) emdevice_set_dimming_on_off(true, NULL); em_flush_memory(); - + switch (event_data.type) { - case EMAIL_EVENT_SEND_MAIL: - case EMAIL_EVENT_SEND_MAIL_SAVED: + case EMAIL_EVENT_SEND_MAIL: + case EMAIL_EVENT_SEND_MAIL_SAVED: _sending_busy_unref(); break; - - case EMAIL_EVENT_SYNC_HEADER: + + case EMAIL_EVENT_SYNC_HEADER: case EMAIL_EVENT_SYNC_HEADER_OMA: - case EMAIL_EVENT_DOWNLOAD_BODY: - case EMAIL_EVENT_DOWNLOAD_ATTACHMENT: + case EMAIL_EVENT_DOWNLOAD_BODY: + case EMAIL_EVENT_DOWNLOAD_ATTACHMENT: case EMAIL_EVENT_SYNC_MAIL_FLAG_TO_SERVER: case EMAIL_EVENT_SYNC_FLAGS_FIELD_TO_SERVER: - case EMAIL_EVENT_DELETE_MAIL: + case EMAIL_EVENT_DELETE_MAIL: case EMAIL_EVENT_DELETE_MAIL_ALL: - case EMAIL_EVENT_VALIDATE_ACCOUNT: - case EMAIL_EVENT_SYNC_IMAP_MAILBOX: + case EMAIL_EVENT_VALIDATE_ACCOUNT: + case EMAIL_EVENT_SYNC_IMAP_MAILBOX: case EMAIL_EVENT_SAVE_MAIL: - case EMAIL_EVENT_MOVE_MAIL: - case EMAIL_EVENT_CREATE_MAILBOX: - case EMAIL_EVENT_DELETE_MAILBOX: + case EMAIL_EVENT_MOVE_MAIL: + 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_SEARCH_ON_SERVER: case EMAIL_EVENT_RENAME_MAILBOX_ON_IMAP_SERVER: _receiving_busy_unref(); break; - default: + default: break; } - + event_data.type = 0; - + ENTER_RECURSIVE_CRITICAL_SECTION(_event_queue_lock); memset(g_event_que+g_active_que, 0x00, sizeof(email_event_t)); LEAVE_RECURSIVE_CRITICAL_SECTION(_event_queue_lock); } - + emcore_clear_session(session); } - if (!emstorage_close(&err)) + if (!emstorage_close(&err)) EM_DEBUG_EXCEPTION("emstorage_close falied [%d]", err); - + EM_DEBUG_FUNC_END(); return SUCCESS; } @@ -2489,14 +2489,14 @@ INTERNAL_FUNC int emcore_start_event_loop_for_sending_mails(int *err_code) EM_DEBUG_FUNC_BEGIN(); int thread_error = -1; - if (err_code != NULL) + if (err_code != NULL) *err_code = EMAIL_ERROR_NONE; memset(&g_send_event_que, 0x00, sizeof(g_send_event_que)); if (g_send_srv_thread) { EM_DEBUG_EXCEPTION("\t send service thread is already running..."); - if (err_code != NULL) + if (err_code != NULL) *err_code = EMAIL_ERROR_UNKNOWN; return true; } @@ -2515,12 +2515,12 @@ INTERNAL_FUNC int emcore_start_event_loop_for_sending_mails(int *err_code) if (thread_error != 0) { EM_DEBUG_EXCEPTION("cannot make thread..."); - if (err_code != NULL) + if (err_code != NULL) *err_code = EMAIL_ERROR_UNKNOWN; return FAILURE; } - if (err_code != NULL) + if (err_code != NULL) *err_code = EMAIL_ERROR_NONE; EM_DEBUG_FUNC_END(); return SUCCESS; @@ -2531,11 +2531,11 @@ INTERNAL_FUNC int emcore_send_event_loop_stop(int *err_code) { EM_DEBUG_FUNC_BEGIN(); - if (err_code != NULL) + if (err_code != NULL) *err_code = EMAIL_ERROR_NONE; if (!g_send_srv_thread) { - if (err_code != NULL) + if (err_code != NULL) *err_code = EMAIL_ERROR_UNKNOWN; return false; } @@ -2547,20 +2547,20 @@ INTERNAL_FUNC int emcore_send_event_loop_stop(int *err_code) ENTER_CRITICAL_SECTION(_send_event_available_lock); WAKE_CONDITION_VARIABLE(_send_event_available_signal); /* MUST BE HERE */ LEAVE_CRITICAL_SECTION(_send_event_available_lock); - + /* wait for thread finished */ THREAD_JOIN(g_send_srv_thread); - + g_send_srv_thread = 0; DELETE_RECURSIVE_CRITICAL_SECTION(_send_event_queue_lock); DELETE_CRITICAL_SECTION(_send_event_available_lock); DELETE_CONDITION_VARIABLE(_send_event_available_signal); - + g_send_event_que_idx = 1; g_send_active_que = 0; - if (err_code != NULL) + if (err_code != NULL) *err_code = EMAIL_ERROR_NONE; return true; @@ -2572,14 +2572,14 @@ INTERNAL_FUNC int emcore_start_event_loop(int *err_code) EM_DEBUG_FUNC_BEGIN(); int thread_error; - if (err_code != NULL) + if (err_code != NULL) *err_code = EMAIL_ERROR_NONE; memset(&g_event_que, 0x00, sizeof(g_event_que)); - + if (g_srv_thread) { EM_DEBUG_EXCEPTION("service thread is already running..."); - if (err_code != NULL) + if (err_code != NULL) *err_code = EMAIL_ERROR_UNKNOWN; return true; } @@ -2587,24 +2587,24 @@ INTERNAL_FUNC int emcore_start_event_loop(int *err_code) g_event_que_idx = 1; g_event_loop = 1; g_active_que = 0; - + /* initialize lock */ INITIALIZE_RECURSIVE_CRITICAL_SECTION(_event_queue_lock); INITIALIZE_RECURSIVE_CRITICAL_SECTION(_event_callback_table_lock); emcore_initialize_event_callback_table(); - + /* create thread */ THREAD_CREATE(g_srv_thread, thread_func_branch_command, NULL, thread_error); if (thread_error != 0) { EM_DEBUG_EXCEPTION("cannot create thread"); - if (err_code != NULL) + if (err_code != NULL) *err_code = EMAIL_ERROR_SYSTEM_FAILURE; return FAILURE; } - if (err_code != NULL) + if (err_code != NULL) *err_code = EMAIL_ERROR_NONE; return false; @@ -2615,11 +2615,11 @@ INTERNAL_FUNC int emcore_stop_event_loop(int *err_code) { EM_DEBUG_FUNC_BEGIN(); - if (err_code != NULL) + if (err_code != NULL) *err_code = EMAIL_ERROR_NONE; if (!g_srv_thread) { - if (err_code != NULL) + if (err_code != NULL) *err_code = EMAIL_ERROR_UNKNOWN; return false; } @@ -2629,14 +2629,14 @@ INTERNAL_FUNC int emcore_stop_event_loop(int *err_code) /* pthread_kill(g_srv_thread, SIGINT); */ emcore_cancel_thread(g_active_que, NULL, err_code); - + ENTER_CRITICAL_SECTION(_event_available_lock); WAKE_CONDITION_VARIABLE(_event_available_signal); LEAVE_CRITICAL_SECTION(_event_available_lock); - + /* wait for thread finished */ THREAD_JOIN(g_srv_thread); - + g_srv_thread = 0; DELETE_RECURSIVE_CRITICAL_SECTION(_event_queue_lock); @@ -2647,7 +2647,7 @@ INTERNAL_FUNC int emcore_stop_event_loop(int *err_code) g_event_que_idx = 1; g_active_que = 0; - if (err_code != NULL) + if (err_code != NULL) *err_code = EMAIL_ERROR_NONE; EM_DEBUG_FUNC_END(); return true; @@ -2666,7 +2666,7 @@ INTERNAL_FUNC int emcore_check_thread_status() { if (g_active_que <= 0) return true; - + return (g_event_que[g_active_que].status == EMAIL_EVENT_STATUS_STARTED); } @@ -2674,80 +2674,80 @@ INTERNAL_FUNC int emcore_check_thread_status() INTERNAL_FUNC int emcore_cancel_thread(int handle, void *arg, int *err_code) { EM_DEBUG_FUNC_BEGIN("handle[%d], arg[%p], err_code[%p]", handle, arg, err_code); - + int ret = false; int err = EMAIL_ERROR_NONE; - + if (handle <= 0 || handle > (EVENT_QUEUE_MAX - 1)) { EM_DEBUG_EXCEPTION("handle[%d], arg[%p]", handle, arg); err = EMAIL_ERROR_INVALID_PARAM; goto FINISH_OFF; } - + ENTER_RECURSIVE_CRITICAL_SECTION(_event_queue_lock); - + EM_DEBUG_LOG("status[%d], type[%d], handle[%d]", g_event_que[handle].status, g_event_que[handle].type, handle); - + if (g_event_que[handle].status == EMAIL_EVENT_STATUS_WAIT) { fail_status_notify(&g_event_que[handle], EMAIL_ERROR_CANCELLED); - + switch (g_event_que[handle].type) { - case EMAIL_EVENT_SEND_MAIL: - case EMAIL_EVENT_SEND_MAIL_SAVED: + case EMAIL_EVENT_SEND_MAIL: + case EMAIL_EVENT_SEND_MAIL_SAVED: EM_DEBUG_LOG("EMAIL_EVENT_SEND_MAIL or EMAIL_EVENT_SEND_MAIL_SAVED"); _sending_busy_unref(); if (!emcore_notify_network_event(NOTI_SEND_CANCEL, g_event_que[handle].account_id, NULL , g_event_que[handle].event_param_data_4, err)) EM_DEBUG_EXCEPTION(" emcore_notify_network_event [ NOTI_SEND_CANCEL] Failed >>>> "); break; - case EMAIL_EVENT_DOWNLOAD_BODY: + case EMAIL_EVENT_DOWNLOAD_BODY: EM_DEBUG_LOG("EMAIL_EVENT_DOWNLOAD_BODY"); _receiving_busy_unref(); if (!emcore_notify_network_event(NOTI_DOWNLOAD_BODY_CANCEL, g_event_que[handle].account_id, NULL , g_event_que[handle].event_param_data_4, err)) EM_DEBUG_EXCEPTION(" emcore_notify_network_event [ NOTI_SEND_CANCEL] Failed >>>> "); break; - case EMAIL_EVENT_SYNC_HEADER: + case EMAIL_EVENT_SYNC_HEADER: case EMAIL_EVENT_SYNC_HEADER_OMA: - case EMAIL_EVENT_DOWNLOAD_ATTACHMENT: + case EMAIL_EVENT_DOWNLOAD_ATTACHMENT: case EMAIL_EVENT_SYNC_MAIL_FLAG_TO_SERVER: case EMAIL_EVENT_SYNC_FLAGS_FIELD_TO_SERVER: EM_DEBUG_LOG("EMAIL_EVENT_SYNC_HEADER, EMAIL_EVENT_DOWNLOAD_ATTACHMENT"); _receiving_busy_unref(); break; - - case EMAIL_EVENT_VALIDATE_ACCOUNT: + + case EMAIL_EVENT_VALIDATE_ACCOUNT: EM_DEBUG_LOG(" validate account waiting : cancel acc id : %d", g_event_que[handle].account_id); _receiving_busy_unref(); if (!emcore_notify_network_event(NOTI_VALIDATE_ACCOUNT_CANCEL, g_event_que[handle].account_id, NULL , g_event_que[handle].event_param_data_4, err)) EM_DEBUG_EXCEPTION(" emcore_notify_network_event [ NOTI_VALIDATE_ACCOUNT_CANCEL] Failed >>>> "); break; - case EMAIL_EVENT_DELETE_MAIL: + case EMAIL_EVENT_DELETE_MAIL: case EMAIL_EVENT_DELETE_MAIL_ALL: - case EMAIL_EVENT_SYNC_IMAP_MAILBOX: + case EMAIL_EVENT_SYNC_IMAP_MAILBOX: case EMAIL_EVENT_SAVE_MAIL: - case EMAIL_EVENT_MOVE_MAIL: - case EMAIL_EVENT_CREATE_MAILBOX: - case EMAIL_EVENT_DELETE_MAILBOX: - case EMAIL_EVENT_SET_MAIL_SLOT_SIZE: + case EMAIL_EVENT_MOVE_MAIL: + 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"); _receiving_busy_unref(); break; - default: + default: break; } } - + memset(g_event_que+handle, 0x00, sizeof(email_event_t)); - g_event_que[handle].status = EMAIL_EVENT_STATUS_CANCELED; + g_event_que[handle].status = EMAIL_EVENT_STATUS_CANCELED; LEAVE_RECURSIVE_CRITICAL_SECTION(_event_queue_lock); - + ret = true; - -FINISH_OFF: + +FINISH_OFF: if (err_code != NULL) *err_code = err; EM_DEBUG_FUNC_END(); @@ -2775,7 +2775,7 @@ INTERNAL_FUNC int emcore_cancel_all_threads_of_an_account(int account_id) int i, event_count = EVENT_QUEUE_MAX, exit_flag = 0, sleep_count = 0; for (i = 0 ; i < event_count; i++) { - if (g_event_que[i].type && g_event_que[i].status != EMAIL_EVENT_STATUS_UNUSED) { + if (g_event_que[i].type && g_event_que[i].status != EMAIL_EVENT_STATUS_UNUSED) { EM_DEBUG_LOG("There is a live thread. %d", i); if (g_event_que[i].account_id == account_id || g_event_que[i].account_id == ALL_ACCOUNT) { EM_DEBUG_LOG("And it is for account %d", g_event_que[i].account_id); @@ -2816,48 +2816,48 @@ INTERNAL_FUNC int emcore_cancel_all_threads_of_an_account(int account_id) INTERNAL_FUNC int emcore_cancel_send_mail_thread(int handle, void *arg, int *err_code) { EM_DEBUG_FUNC_BEGIN("handle[%d], arg[%p], err_code[%p]", handle, arg, err_code); - + int ret = false; int err = EMAIL_ERROR_NONE; - + if (handle <= 0 || handle > (EVENT_QUEUE_MAX - 1)) { EM_DEBUG_EXCEPTION("handle[%d], arg[%p]", handle, arg); err = EMAIL_ERROR_INVALID_PARAM; goto FINISH_OFF; } - + ENTER_RECURSIVE_CRITICAL_SECTION(_send_event_queue_lock); - + EM_DEBUG_LOG("event_data.status[%d], handle[%d]", g_send_event_que[handle].status, handle); - + if (g_send_event_que[handle].status == EMAIL_EVENT_STATUS_WAIT) { fail_status_notify(&g_send_event_que[handle], EMAIL_ERROR_CANCELLED); - + switch (g_send_event_que[handle].type) { - case EMAIL_EVENT_SEND_MAIL: - case EMAIL_EVENT_SEND_MAIL_SAVED: + case EMAIL_EVENT_SEND_MAIL: + case EMAIL_EVENT_SEND_MAIL_SAVED: _sending_busy_unref(); g_send_event_que[handle].status = EMAIL_EVENT_STATUS_CANCELED; if (!emcore_notify_network_event(NOTI_SEND_CANCEL, g_send_event_que[handle].account_id, NULL , g_send_event_que[handle].event_param_data_4, err)) EM_DEBUG_EXCEPTION(" emcore_notify_network_event [ NOTI_SEND_CANCEL] Failed >>>> "); - break; - default: + break; + default: break; } } - + EM_DEBUG_LOG("send_mail_cancel"); memset(g_send_event_que+handle, 0x00, sizeof(email_event_t)); g_send_event_que[handle].status = EMAIL_EVENT_STATUS_CANCELED; EM_DEBUG_LOG("event_data.status[%d], handle[%d]", g_send_event_que[handle].status, handle); - + LEAVE_RECURSIVE_CRITICAL_SECTION(_send_event_queue_lock); - + ret = true; - -FINISH_OFF: + +FINISH_OFF: if (err_code != NULL) *err_code = err; EM_DEBUG_FUNC_END("ret [%d]", ret); @@ -2870,15 +2870,15 @@ INTERNAL_FUNC int emcore_get_receiving_event_queue(email_event_t **event_queue, if (event_queue == NULL || event_active_queue == NULL) { EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM event_queue[%p] event_active_queue[%p]", event_queue, event_active_queue); - if (err) + if (err) *err = EMAIL_ERROR_INVALID_PARAM; - + return false; } *event_queue = g_event_que; *event_active_queue = g_active_que; - + return true; } @@ -2937,7 +2937,7 @@ static int emcore_clear_bulk_pbd_que(int *err_code) int ret = true; int error = EMAIL_ERROR_NONE; int i = 0; - + for (i = 0; i < BULK_PARTIAL_BODY_DOWNLOAD_COUNT; ++i) { if (g_partial_body_bulk_dwd_que[i].event_type) { if (false == emcore_free_partial_body_thd_event(g_partial_body_bulk_dwd_que + i, &error)) { @@ -2957,7 +2957,7 @@ static int emcore_clear_bulk_pbd_que(int *err_code) static void emcore_pb_thd_set_local_activity_continue(int flag) { EM_DEBUG_FUNC_BEGIN("flag [%d]", flag); - + ENTER_CRITICAL_SECTION(_partial_body_thd_event_queue_lock); g_pb_thd_local_activity_continue = flag; @@ -2970,7 +2970,7 @@ static void emcore_pb_thd_set_local_activity_continue(int flag) EM_DEBUG_FUNC_END(); } -static +static int emcore_pb_thd_can_local_activity_continue() { EM_DEBUG_FUNC_BEGIN(); @@ -2984,7 +2984,7 @@ int emcore_pb_thd_can_local_activity_continue() LEAVE_CRITICAL_SECTION(_partial_body_thd_event_queue_lock); EM_DEBUG_FUNC_END(); return ret; - + } INTERNAL_FUNC int emcore_clear_partial_body_thd_event_que(int *err_code) @@ -2994,7 +2994,7 @@ INTERNAL_FUNC int emcore_clear_partial_body_thd_event_que(int *err_code) int ret = true; int error = EMAIL_ERROR_NONE; int i = 0; - + ENTER_CRITICAL_SECTION(_partial_body_thd_event_queue_lock); if (true == g_partial_body_thd_queue_empty) { @@ -3027,11 +3027,11 @@ INTERNAL_FUNC int emcore_is_partial_body_thd_que_empty() EM_DEBUG_FUNC_BEGIN(); int ret = false; - + ENTER_CRITICAL_SECTION(_partial_body_thd_event_queue_lock); ret = g_partial_body_thd_queue_empty; - + LEAVE_CRITICAL_SECTION(_partial_body_thd_event_queue_lock); EM_DEBUG_FUNC_END("ret [%d]", ret); return ret; @@ -3041,24 +3041,24 @@ INTERNAL_FUNC int emcore_is_partial_body_thd_que_full() EM_DEBUG_FUNC_BEGIN(); int ret = false; - + ENTER_CRITICAL_SECTION(_partial_body_thd_event_queue_lock); ret = g_partial_body_thd_queue_full; - + LEAVE_CRITICAL_SECTION(_partial_body_thd_event_queue_lock); EM_DEBUG_FUNC_END(); return ret; } /* -Himanshu[h.gahalut] : If either src pointer or dest pointer points to a cell of global partial body thread event_data queue, -then emcore_copy_partial_body_thd_event API should only be called from a portion of code which is protected +Himanshu[h.gahalut] : If either src pointer or dest pointer points to a cell of global partial body thread event_data queue, +then emcore_copy_partial_body_thd_event API should only be called from a portion of code which is protected through _partial_body_thd_event_queue_lock mutex. -No mutex is used inside this API so that we can also use it to copy partial body events which are not a part of global event_data queue +No mutex is used inside this API so that we can also use it to copy partial body events which are not a part of global event_data queue -Precautions : +Precautions : _partial_body_thd_event_queue_lock mutex should never be used inside this API otherwise it will be a deadlock. Also never call any function from this API which uses _partial_body_thd_event_queue_lock mutex. @@ -3070,7 +3070,7 @@ static int emcore_copy_partial_body_thd_event(email_event_partial_body_thd *src, EM_DEBUG_FUNC_BEGIN(); int error = EMAIL_ERROR_NONE; int ret = false; - + if (NULL == src || NULL == dest) { EM_DEBUG_LOG(" Invalid Parameter src [%p] dest [%p]", src, dest); error = EMAIL_ERROR_INVALID_PARAM; @@ -3089,23 +3089,23 @@ static int emcore_copy_partial_body_thd_event(email_event_partial_body_thd *src, EM_DEBUG_LOG("dest->account_id[%d], dest->mail_id[%d], dest->server_mail_id [%lu]", dest->account_id, dest->mail_id , dest->server_mail_id); ret = true; - - FINISH_OFF: + + FINISH_OFF: if (NULL != error_code) *error_code = error; - + return ret; - + } /* -Himanshu[h.gahalut] : If emcore_free_partial_body_thd_event_cell API is used to free a cell of partial body thread event_data queue, +Himanshu[h.gahalut] : If emcore_free_partial_body_thd_event_cell API is used to free a cell of partial body thread event_data queue, it should only be called from a portion of code which is protected through _partial_body_thd_event_queue_lock mutex. -No mutex is used inside this API so that we can also use it to free partial body events which are not a part of global event_data queue +No mutex is used inside this API so that we can also use it to free partial body events which are not a part of global event_data queue -Precautions : +Precautions : _partial_body_thd_event_queue_lock mutex should never be used inside this API otherwise it will be a deadlock. Also never call any function from this API which uses _partial_body_thd_event_queue_lock mutex. @@ -3115,14 +3115,14 @@ Also never call any function from this API which uses _partial_body_thd_event_qu INTERNAL_FUNC int emcore_free_partial_body_thd_event(email_event_partial_body_thd *partial_body_thd_event, int *error_code) { EM_DEBUG_FUNC_BEGIN(); - + if (NULL == partial_body_thd_event) { *error_code = EMAIL_ERROR_INVALID_PARAM; return false; } email_event_partial_body_thd *pbd_event = partial_body_thd_event; - + /*Free character pointers in event_data cell */ EM_SAFE_FREE(pbd_event->mailbox_name); memset(pbd_event, 0x00, sizeof(email_event_partial_body_thd)); @@ -3133,22 +3133,22 @@ INTERNAL_FUNC int emcore_free_partial_body_thd_event(email_event_partial_body_th 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(); - + if (NULL == partial_body_thd_event) { EM_DEBUG_EXCEPTION("\t partial_body_thd_event [%p] ", partial_body_thd_event); - + if (error_code != NULL) { *error_code = EMAIL_ERROR_INVALID_PARAM; } return false; } - + int ret = false; int error = EMAIL_ERROR_NONE; int empty_cell_index = -1; int index = 0; int count = 0; - + ENTER_CRITICAL_SECTION(_partial_body_thd_event_queue_lock); /* find a cell in queue which is empty */ @@ -3163,8 +3163,8 @@ INTERNAL_FUNC int emcore_insert_partial_body_thread_event(email_event_partial_bo } } else { - /*Found empty Cell*/ - + /*Found empty Cell*/ + empty_cell_index = index; break; } @@ -3184,27 +3184,27 @@ INTERNAL_FUNC int emcore_insert_partial_body_thread_event(email_event_partial_bo } WAKE_CONDITION_VARIABLE(_partial_body_thd_cond); - + ret = true; } } else { 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); if (NULL != error_code) { *error_code = error; } - + return ret; - + } /* h.gahlaut : Return true only if event_data is retrieved successfully */ @@ -3215,16 +3215,16 @@ static int emcore_retrieve_partial_body_thread_event(email_event_partial_body_th int ret = false; int error = EMAIL_ERROR_NONE; - int index = 0; + int index = 0; /* Lock Mutex to protect event_data queue and associated global variables variables*/ - + ENTER_CRITICAL_SECTION(_partial_body_thd_event_queue_lock); index = g_partial_body_thd_next_event_idx; - + if (0 == g_partial_body_thd_event_que[index].event_type) { - error = EMAIL_ERROR_EVENT_QUEUE_EMPTY; + error = EMAIL_ERROR_EVENT_QUEUE_EMPTY; g_partial_body_thd_queue_empty = true; g_partial_body_thd_queue_full = false; } @@ -3236,14 +3236,14 @@ static int emcore_retrieve_partial_body_thread_event(email_event_partial_body_th if (false == emcore_free_partial_body_thd_event(g_partial_body_thd_event_que + index, &error)) EM_DEBUG_EXCEPTION("emcore_free_partial_body_thd_event_cell failed [%d]", error); else { - + g_partial_body_thd_queue_full = false; g_partial_body_thd_next_event_idx = ++index; - + if (g_partial_body_thd_next_event_idx == TOTAL_PARTIAL_BODY_EVENTS) g_partial_body_thd_next_event_idx = 0; - /* If the event_data retrieved was the only event_data present in queue, + /* If the event_data retrieved was the only event_data present in queue, we need to set g_partial_body_thd_queue_empty to true */ @@ -3257,14 +3257,14 @@ static int emcore_retrieve_partial_body_thread_event(email_event_partial_body_th } /* Unlock Mutex */ - + LEAVE_CRITICAL_SECTION(_partial_body_thd_event_queue_lock); if (error_code) *error_code = error; return ret; - + } gpointer partial_body_download_thread(gpointer data) @@ -3276,24 +3276,24 @@ gpointer partial_body_download_thread(gpointer data) email_event_partial_body_thd partial_body_thd_event; EM_DEBUG_LOG(" ************ PB THREAD ID IS ALIVE. ID IS [%d] ********************" , THREAD_SELF()); - + /* Open connection with DB */ - + if (false == emstorage_open(&err)) { EM_DEBUG_EXCEPTION("emstorage_open failed [%d]", err); return false; } /* Start the continuous loop */ - + while (g_partial_body_thd_loop) { /* Get an empty session */ /* TODO : Mutex should be used in session APIs */ - - if (false == emcore_get_empty_session(&session)) + + 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, 0x00, 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) @@ -3302,18 +3302,18 @@ gpointer partial_body_download_thread(gpointer data) 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) { + 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); - + 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); emcore_pb_thd_set_local_activity_continue(true); } - + if (true == emcore_pb_thd_can_local_activity_continue()) { /*Check for local Activities */ int is_local_activity_event_inserted = false; @@ -3324,13 +3324,13 @@ gpointer partial_body_download_thread(gpointer data) else { if (true == is_local_activity_event_inserted) { emcore_pb_thd_set_local_activity_continue(false); - + emcore_clear_session(session); continue; - } - } + } + } } - + EM_DEBUG_LOG(" Partial Body Thread is going to sleep"); emcore_set_pbd_thd_state(false); @@ -3343,23 +3343,23 @@ gpointer partial_body_download_thread(gpointer data) 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*/ emdevice_set_dimming_on_off(false, NULL); - + if (!emnetwork_check_network_status( &err)) { - EM_DEBUG_EXCEPTION("emnetwork_check_network_status failed [%d]", err);; + EM_DEBUG_EXCEPTION("emnetwork_check_network_status failed [%d]", err);; } - else { + else { /* Process events */ - EM_DEBUG_LOG("partial_body_thd_event.account_id[%d]", partial_body_thd_event.account_id); - + EM_DEBUG_LOG("partial_body_thd_event.account_id[%d]", partial_body_thd_event.account_id); + 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)) { @@ -3373,15 +3373,15 @@ gpointer partial_body_download_thread(gpointer data) /* 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; + break; 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: + default: EM_DEBUG_EXCEPTION(" Warning : Default case entered. This should not happen "); break; } @@ -3389,12 +3389,12 @@ gpointer partial_body_download_thread(gpointer data) 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_dimming_on_off(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 @@ -3411,7 +3411,7 @@ INTERNAL_FUNC int emcore_start_thread_for_downloading_partial_body(int *err_code /* Clear Partial Body Event Queue*/ memset(&g_partial_body_thd_event_que, 0x00, sizeof(g_partial_body_thd_event_que)); - + for (i = 0; i < TOTAL_PARTIAL_BODY_EVENTS; ++i) { g_partial_body_thd_event_que[i].mailbox_name = NULL; g_partial_body_thd_event_que[i].mailbox_id = 0; @@ -3419,14 +3419,14 @@ INTERNAL_FUNC int emcore_start_thread_for_downloading_partial_body(int *err_code if (g_partial_body_thd) { EM_DEBUG_EXCEPTION("partial body thread is already running..."); - if (err_code != NULL) + if (err_code != NULL) *err_code = EMAIL_ERROR_UNKNOWN; - + return true; } 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; @@ -3435,19 +3435,19 @@ INTERNAL_FUNC int emcore_start_thread_for_downloading_partial_body(int *err_code /* create thread */ /* THREAD_CREATE_JOINABLE(g_partial_body_thd, partial_body_download_thread, thread_error); */ THREAD_CREATE(g_partial_body_thd, partial_body_download_thread, NULL, thread_error); - + if (thread_error != 0) { EM_DEBUG_EXCEPTION("cannot make thread..."); - if (err_code != NULL) + if (err_code != NULL) *err_code = EMAIL_ERROR_UNKNOWN; return FAILURE; } - if (err_code != NULL) + if (err_code != NULL) *err_code = EMAIL_ERROR_NONE; - + return false; - + } /*Function to flush the bulk partial body download queue [santosh.br@samsung.com]*/ @@ -3472,21 +3472,21 @@ static int emcore_partial_body_bulk_flush(int *error_code) } ret = true; -FINISH_OFF: +FINISH_OFF: - emcore_close_mailbox(0, stream); + emcore_close_mailbox(0, stream); stream = NULL; g_partial_body_bulk_dwd_next_event_idx = 0; g_partial_body_bulk_dwd_queue_empty = true; - + if (false == emcore_clear_bulk_pbd_que(&error)) EM_DEBUG_EXCEPTION("emcore_clear_bulk_pbd_que failed [%d]", error); if (NULL != error_code) *error_code = error; - - EM_DEBUG_FUNC_END("ret [%d]", ret); + + EM_DEBUG_FUNC_END("ret [%d]", ret); return ret; } @@ -3512,11 +3512,11 @@ INTERNAL_FUNC int emcore_mail_partial_body_download(email_event_partial_body_thd error = EMAIL_ERROR_INVALID_PARAM; goto FINISH_OFF; } - + /*Check if the event_data is to flush the event_data que array */ if (EMAIL_EVENT_BULK_PARTIAL_BODY_DOWNLOAD == pbd_event->event_type) { EM_DEBUG_LOG("pbd_event->event_type is EMAIL_EVENT_BULK_PARTIAL_BODY_DOWNLOAD"); - /*Check if the mailbox name and account id for this event_data is same as the mailbox name and account id for earlier events saved in download que array + /*Check if the mailbox name and account id for this event_data is same as the mailbox name and account id for earlier events saved in download que array then append this event_data also to download que array */ if ((0 != g_partial_body_bulk_dwd_que[0].mailbox_id) && g_partial_body_bulk_dwd_que[0].mailbox_id == pbd_event->mailbox_id && \ (g_partial_body_bulk_dwd_que[0].account_id == pbd_event->account_id)) { @@ -3524,7 +3524,7 @@ INTERNAL_FUNC int emcore_mail_partial_body_download(email_event_partial_body_thd EM_DEBUG_LOG("Check if the download que reached its limit. If yes then first flush the que."); if (g_partial_body_bulk_dwd_next_event_idx == BULK_PARTIAL_BODY_DOWNLOAD_COUNT) { if (false == emcore_partial_body_bulk_flush(&error)) { - EM_DEBUG_EXCEPTION("Partial Body thread emcore_partial_body_bulk_flush failed - %d", error); + EM_DEBUG_EXCEPTION("Partial Body thread emcore_partial_body_bulk_flush failed - %d", error); goto FINISH_OFF; } } @@ -3535,21 +3535,21 @@ INTERNAL_FUNC int emcore_mail_partial_body_download(email_event_partial_body_thd EM_DEBUG_LOG("g_partial_body_bulk_dwd_queue_empty [%d]", g_partial_body_bulk_dwd_queue_empty); if (!g_partial_body_bulk_dwd_queue_empty) { if (false == emcore_partial_body_bulk_flush(&error)) { - EM_DEBUG_EXCEPTION("Partial Body thread emcore_partial_body_bulk_flush failed - %d", error); + EM_DEBUG_EXCEPTION("Partial Body thread emcore_partial_body_bulk_flush failed - %d", error); goto FINISH_OFF; } } } /*Add the event_data to the download que array */ if (false == emcore_copy_partial_body_thd_event(pbd_event, g_partial_body_bulk_dwd_que+(g_partial_body_bulk_dwd_next_event_idx), &error)) - EM_DEBUG_EXCEPTION("\t Partial Body thread emcore_copy_partial_body_thd_event failed - %d", error); + EM_DEBUG_EXCEPTION("\t Partial Body thread emcore_copy_partial_body_thd_event failed - %d", error); else { g_partial_body_bulk_dwd_queue_empty = false; g_partial_body_bulk_dwd_next_event_idx++; EM_DEBUG_LOG("g_partial_body_bulk_dwd_next_event_idx [%d]", g_partial_body_bulk_dwd_next_event_idx); } } - else if (pbd_event->activity_type) { + else if (pbd_event->activity_type) { int *account_list = NULL; int account_count = 0; @@ -3568,7 +3568,7 @@ INTERNAL_FUNC int emcore_mail_partial_body_download(email_event_partial_body_thd error = EMAIL_ERROR_MAILBOX_NOT_FOUND; goto FINISH_OFF; } - + for (i = 0; i < count; i++) { int k = 0; int activity_count = 0; @@ -3580,16 +3580,16 @@ INTERNAL_FUNC int emcore_mail_partial_body_download(email_event_partial_body_thd } stream = (MAILSTREAM *)tmp_stream; - + if (false == emstorage_get_mailbox_pbd_activity_count(account_list[m], mailbox_list[i], &activity_count, false, &error)) { EM_DEBUG_EXCEPTION(" emstorage_get_mailbox_pbd_activity_count failed.. [%d]", error); continue; } - + if (activity_count > 0) { int temp_error = EMAIL_ERROR_NONE; int j = 0; - int iter = 0; + int iter = 0; int remainder = 0; int num = BULK_PARTIAL_BODY_DOWNLOAD_COUNT; int index = 0; @@ -3604,7 +3604,7 @@ INTERNAL_FUNC int emcore_mail_partial_body_download(email_event_partial_body_thd remainder = num_activity%BULK_PARTIAL_BODY_DOWNLOAD_COUNT; iter = num_activity/BULK_PARTIAL_BODY_DOWNLOAD_COUNT + ((num_activity%BULK_PARTIAL_BODY_DOWNLOAD_COUNT) ? 1 : 0); - + for (j = 0; j < iter; j++) { if ((iter == (j+1)) && (remainder != 0)) num = remainder; @@ -3614,7 +3614,7 @@ INTERNAL_FUNC int emcore_mail_partial_body_download(email_event_partial_body_thd EM_DEBUG_EXCEPTION(" emcore_download_bulk_partial_mail_body failed.. [%d]", error); temp_error = EMAIL_ERROR_NO_RESPONSE; } - + for (k = 0; k < num; k++) { if (activity_data_list[index + k].activity_type) emcore_free_partial_body_thd_event(activity_data_list + index + k, &error); @@ -3622,7 +3622,7 @@ INTERNAL_FUNC int emcore_mail_partial_body_download(email_event_partial_body_thd break; } index += num; - + if (false == emcore_is_partial_body_thd_que_empty()) { ret = true; goto FINISH_OFF; /* Stop Local Activity Sync */ @@ -3633,15 +3633,15 @@ INTERNAL_FUNC int emcore_mail_partial_body_download(email_event_partial_body_thd } } } - } - emcore_close_mailbox(0, stream); + } + emcore_close_mailbox(0, stream); stream = NULL; tmp_stream = NULL; - } + } - /* After completing one cycle of local activity sync , + /* After completing one cycle of local activity sync , local activity continue variable should be set to false. */ - + emcore_pb_thd_set_local_activity_continue(false); } else /* Event-type is 0 which means Event is to flush the que when no more events are present in g_partial_body_thd_event_que */ { @@ -3652,15 +3652,15 @@ INTERNAL_FUNC int emcore_mail_partial_body_download(email_event_partial_body_thd goto FINISH_OFF; /* Stop Local Activity Sync */ } if (false == emcore_partial_body_bulk_flush(&error)) { - EM_DEBUG_EXCEPTION("\t Partial Body thread emcore_partial_body_bulk_flush failed - %d", error); + EM_DEBUG_EXCEPTION("\t Partial Body thread emcore_partial_body_bulk_flush failed - %d", error); goto FINISH_OFF; } } ret = true; - -FINISH_OFF: - + +FINISH_OFF: + EM_SAFE_FREE(mailbox_list); if (activity_data_list) { @@ -3672,12 +3672,12 @@ FINISH_OFF: } } - emcore_close_mailbox(0, stream); + emcore_close_mailbox(0, stream); stream = NULL; - + if (NULL != error_code) *error_code = error; - EM_DEBUG_FUNC_END("ret [%d]", ret); + EM_DEBUG_FUNC_END("ret [%d]", ret); return ret; } diff --git a/email-core/email-core-global.c b/email-core/email-core-global.c index 14699b7..33daecb 100755 --- a/email-core/email-core-global.c +++ b/email-core/email-core-global.c @@ -1,7 +1,7 @@ /* * email-service * -* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> * diff --git a/email-core/email-core-imap-idle.c b/email-core/email-core-imap-idle.c index 79f5e64..72350c8 100755 --- a/email-core/email-core-imap-idle.c +++ b/email-core/email-core-imap-idle.c @@ -1,7 +1,7 @@ /* * email-service * -* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> * diff --git a/email-core/email-core-imap-mailbox.c b/email-core/email-core-imap-mailbox.c index 82ec80e..14a8e0e 100755 --- a/email-core/email-core-imap-mailbox.c +++ b/email-core/email-core-imap-mailbox.c @@ -1,7 +1,7 @@ /* * email-service * -* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> * @@ -50,39 +50,30 @@ #include "email-debug-log.h" -INTERNAL_FUNC int emcore_get_default_mail_slot_count(int *output_count, int *err_code) +INTERNAL_FUNC int emcore_get_default_mail_slot_count(int input_account_id, int *output_count) { - EM_DEBUG_FUNC_BEGIN(); - EM_DEBUG_LOG("output_count[%p], err_code[%p]", output_count, err_code); + EM_DEBUG_FUNC_BEGIN("input_account_id [%d] output_count[%p]", input_account_id, output_count); int err = EMAIL_ERROR_NONE; - int mail_slot_count; - int ret = false, ret2; + int default_mail_slot_count = 25; + email_account_t *account_ref = NULL; if (output_count == NULL) { err = EMAIL_ERROR_INVALID_PARAM; goto FINISH_OFF; } - ret2 = vconf_get_int(VCONF_KEY_DEFAULT_SLOT_SIZE, &mail_slot_count); - - if (ret2 < 0) { - EM_DEBUG_EXCEPTION("vconf_get_int() Failed(%d)", ret2); - mail_slot_count = 100; - } - - ret = true; + account_ref = emcore_get_account_reference(input_account_id); + if (account_ref) + default_mail_slot_count = account_ref->default_mail_slot_size; FINISH_OFF: if (output_count) - *output_count = mail_slot_count; + *output_count = default_mail_slot_count; - if (err_code) - *err_code = err; - - return ret; - + EM_DEBUG_FUNC_END("err[%d]", err); + return err; } @@ -387,7 +378,7 @@ INTERNAL_FUNC int emcore_sync_mailbox_list(int account_id, char *mailbox_name, i } if (mailbox_list[i].mailbox_name) { EM_DEBUG_LOG("mailbox name - %s", mailbox_list[i].mailbox_name); - emcore_get_default_mail_slot_count(&(mailbox_list[i].mail_slot_size), NULL); + mailbox_list[i].mail_slot_size = ref_account->default_mail_slot_size; if(mailbox_list[i].mailbox_type == EMAIL_MAILBOX_TYPE_NONE) emcore_bind_mailbox_type(mailbox_list + i); @@ -428,7 +419,7 @@ INTERNAL_FUNC int emcore_sync_mailbox_list(int account_id, char *mailbox_name, i mailbox_tbl.deleted_flag = 0; mailbox_tbl.modifiable_yn = 1; mailbox_tbl.total_mail_count_on_server = 0; - emcore_get_default_mail_slot_count(&mailbox_tbl.mail_slot_size, NULL); + mailbox_tbl.mail_slot_size = ref_account->default_mail_slot_size; switch (counter) { case EMAIL_MAILBOX_TYPE_SENTBOX: diff --git a/email-core/email-core-mail.c b/email-core/email-core-mail.c index b43d916..61196d9 100755 --- a/email-core/email-core-mail.c +++ b/email-core/email-core-mail.c @@ -1,7 +1,7 @@ /* * email-service * -* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> * @@ -2307,8 +2307,8 @@ INTERNAL_FUNC int emcore_download_attachment(int account_id, int mail_id, int nt int err = EMAIL_ERROR_NONE; - if (mail_id < 1 || !nth) { - EM_DEBUG_EXCEPTION("mail_id[%d], nth[%d]", mail_id, nth); + if (mail_id < 1) { + EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM"); err = EMAIL_ERROR_INVALID_PARAM; if (err_code != NULL) @@ -2469,14 +2469,12 @@ INTERNAL_FUNC int emcore_download_attachment(int account_id, int mail_id, int nt /* select target attachment information. */ for (ai = cnt_info->file ; ai; ai = ai->next) { - if (ai->name) - EM_DEBUG_LOG("[in loop] %s, %d", ai->name, cnt_info->file_no); - + EM_DEBUG_LOG("[in loop] name[%s] save[%s] no[%d]", ai->save, ai->name, cnt_info->file_no); if (--cnt_info->file_no == 0) break; } - EM_DEBUG_LOG("cnt_info->file_no = %d, ai = %p", cnt_info->file_no, ai); + 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. */ @@ -2492,7 +2490,7 @@ INTERNAL_FUNC int emcore_download_attachment(int account_id, int mail_id, int nt 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; } @@ -2827,7 +2825,6 @@ 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) { 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); @@ -3132,7 +3129,7 @@ INTERNAL_FUNC int emcore_download_body_multi_sections_bulk(void *mail_stream, in mail->body_download_status = EMAIL_BODY_DOWNLOAD_STATUS_PARTIALLY_DOWNLOADED; else mail->body_download_status = EMAIL_BODY_DOWNLOAD_STATUS_FULLY_DOWNLOADED; - + /* 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 failedi : [%d]", err); @@ -5033,7 +5030,7 @@ FINISH_OFF: return err; } -static 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 *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); @@ -5058,7 +5055,6 @@ static int emcore_save_mail_file(int account_id, int mail_id, int attachment_id, if (strcmp(src_file_path, full_path) != 0) { if (!emstorage_copy_file(src_file_path, full_path, false, &err)) { EM_DEBUG_EXCEPTION("emstorage_copy_file failed [%d]", err); - goto FINISH_OFF; } } diff --git a/email-core/email-core-mailbox-sync.c b/email-core/email-core-mailbox-sync.c index fed099a..78b9b27 100755 --- a/email-core/email-core-mailbox-sync.c +++ b/email-core/email-core-mailbox-sync.c @@ -1,10 +1,10 @@ /* * email-service * -* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* 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-sync.c * Desc : Mail Header Sync * - * Auth : + * Auth : *****************************************************************************/ #include <stdio.h> #include <stdlib.h> @@ -42,7 +42,7 @@ #include "lnx_inc.h" #include "email-utilities.h" -#include "email-convert.h" +#include "email-convert.h" #include "email-core-mailbox-sync.h" #include "email-core-global.h" #include "email-core-imap-mailbox.h" @@ -52,7 +52,7 @@ #include "email-core-mime.h" #include "email-core-utils.h" #include "email-core-smtp.h" -#include "email-core-account.h" +#include "email-core-account.h" #include "email-storage.h" #include "email-core-signal.h" #include "flstring.h" @@ -78,56 +78,56 @@ static char g_append_uid_rsp[129]; /* added for getting server response */ int pop3_mail_calc_rfc822_size(MAILSTREAM *stream, int msgno, int *size, int *err_code) { EM_DEBUG_FUNC_BEGIN(); - + int ret = false; int err = EMAIL_ERROR_NONE; - + POP3LOCAL *pop3local = NULL; char command[16]; char *response = NULL; if (!stream || !size) { EM_DEBUG_EXCEPTION(" stream[%p], msgno[%d], size[%p]\n", stream, msgno, size); - + err = EMAIL_ERROR_INVALID_PARAM; goto FINISH_OFF; } - + if (!(pop3local = stream->local) || !pop3local->netstream) { err = EMAIL_ERROR_INVALID_STREAM; goto FINISH_OFF; } memset(command, 0x00, sizeof(command)); - + SNPRINTF(command, sizeof(command), "LIST %d\015\012", msgno); /* EM_DEBUG_LOG(" [POP3] >>> %s", command); */ - + /* send command : get rfc822 size by msgno */ if (!net_sout(pop3local->netstream, command, (int)EM_SAFE_STRLEN(command))) { EM_DEBUG_EXCEPTION(" net_sout failed..."); - + err = EMAIL_ERROR_INVALID_RESPONSE; goto FINISH_OFF; } - + /* receive response */ if (!(response = net_getline(pop3local->netstream))) { err = EMAIL_ERROR_CONNECTION_BROKEN; /* EMAIL_ERROR_UNKNOWN; */ goto FINISH_OFF; } - + /* EM_DEBUG_LOG(" [POP3] <<< %s", response); */ - + if (*response == '+') { /* "+ OK" */ char *p = NULL; - + if (!(p = strchr(response + strlen("+OK "), ' '))) { err = EMAIL_ERROR_INVALID_RESPONSE; goto FINISH_OFF; } - + *size = atoi(p + 1); } else if (*response == '-') { /* "- ERR" */ @@ -138,37 +138,37 @@ int pop3_mail_calc_rfc822_size(MAILSTREAM *stream, int msgno, int *size, int *er err = EMAIL_ERROR_INVALID_RESPONSE; goto FINISH_OFF; } - + ret = true; - -FINISH_OFF: + +FINISH_OFF: EM_SAFE_FREE(response); - + if (err_code != NULL) *err_code = err; - - EM_DEBUG_FUNC_END("ret [%d]", ret); + + EM_DEBUG_FUNC_END("ret [%d]", ret); return ret; } int imap4_mail_calc_rfc822_size(MAILSTREAM *stream, int msgno, int *size, int *err_code) { EM_DEBUG_FUNC_BEGIN(); - + int ret = false; int err = EMAIL_ERROR_NONE; - + IMAPLOCAL *imaplocal = NULL; char tag[32], command[128]; char *response = NULL; if (!stream || !size) { EM_DEBUG_EXCEPTION("stream[%p], msgno[%d], size[%p]", stream, msgno, size); - + err = EMAIL_ERROR_INVALID_PARAM; goto FINISH_OFF; } - + if (!(imaplocal = stream->local) || !imaplocal->netstream) { err = EMAIL_ERROR_INVALID_STREAM; goto FINISH_OFF; @@ -181,25 +181,25 @@ int imap4_mail_calc_rfc822_size(MAILSTREAM *stream, int msgno, int *size, int *e SNPRINTF(command, sizeof(command), "%s FETCH %d RFC822.SIZE\015\012", tag, msgno); /* EM_DEBUG_LOG(" [IMAP4] >>> %s", command); */ - + /* send command : get rfc822 size by msgno */ if (!net_sout(imaplocal->netstream, command, (int)EM_SAFE_STRLEN(command))) { EM_DEBUG_EXCEPTION(" net_sout failed..."); - + err = EMAIL_ERROR_INVALID_RESPONSE; goto FINISH_OFF; } - + while (imaplocal->netstream) { char *s = NULL; char *t = NULL; - + /* receive response */ if (!(response = net_getline(imaplocal->netstream))) break; - + /* EM_DEBUG_LOG(" [IMAP4] <<< %s", response); */ - + if (!strncmp(response, tag, EM_SAFE_STRLEN(tag))) { if (!strncmp(response + EM_SAFE_STRLEN(tag) + 1, "OK", 2)) { EM_SAFE_FREE(response); @@ -216,32 +216,32 @@ int imap4_mail_calc_rfc822_size(MAILSTREAM *stream, int msgno, int *size, int *e EM_SAFE_FREE(response); continue; } - + s = t + strlen("FETCH (RFC822.SIZE "); - + if (!(t = strchr(s, ' '))) { err = EMAIL_ERROR_INVALID_RESPONSE; goto FINISH_OFF; } - + *t = '\0'; - + *size = atoi(s); } } - + EM_SAFE_FREE(response); } - + ret = true; - -FINISH_OFF: + +FINISH_OFF: EM_SAFE_FREE(response); - + if (err_code != NULL) *err_code = err; - - EM_DEBUG_FUNC_END("ret [%d]", ret); + + EM_DEBUG_FUNC_END("ret [%d]", ret); return ret; } @@ -252,106 +252,106 @@ int pop3_mailbox_get_uids(MAILSTREAM *stream, emcore_uid_list** uid_list, int *e int ret = false; int err = EMAIL_ERROR_NONE; - + POP3LOCAL *pop3local = NULL; char command[64]; char *response = NULL; emcore_uid_list *uid_elem = NULL; - + if (!stream || !uid_list) { EM_DEBUG_EXCEPTION("stream[%p], uid_list[%p]n", stream, uid_list); err = EMAIL_ERROR_INVALID_PARAM; goto FINISH_OFF; } - + if (!(pop3local = stream->local) || !pop3local->netstream) { EM_DEBUG_EXCEPTION("invalid POP3 stream detected..."); err = EMAIL_ERROR_INVALID_STREAM; goto FINISH_OFF; } - + memset(command, 0x00, sizeof(command)); - + SNPRINTF(command, sizeof(command), "UIDL\015\012"); - + #ifdef FEATURE_CORE_DEBUG EM_DEBUG_LOG(" [POP3] >>> [%s]", command); #endif - + /* send command : get msgno/uid for all message */ if (!net_sout(pop3local->netstream, command, (int)EM_SAFE_STRLEN(command))) { EM_DEBUG_EXCEPTION("net_sout failed..."); err = EMAIL_ERROR_CONNECTION_BROKEN; /* EMAIL_ERROR_UNKNOWN; */ goto FINISH_OFF; } - + *uid_list = NULL; - + while (pop3local->netstream) { char *p = NULL; - + /* receive response */ if (!(response = net_getline(pop3local->netstream))) { EM_DEBUG_EXCEPTION("net_getline failed..."); err = EMAIL_ERROR_INVALID_RESPONSE; goto FINISH_OFF; } - + #ifdef FEATURE_CORE_DEBUG EM_DEBUG_LOG(" [POP3] <<< [%s]", response); #endif - + if (*response == '-') { /* "-ERR" */ err = EMAIL_ERROR_POP3_UIDL_FAILURE; /* EMAIL_ERROR_INVALID_RESPONSE; */ goto FINISH_OFF; } - + if (*response == '+') { /* "+OK" */ free(response); response = NULL; continue; } - + if (*response == '.') { free(response); response = NULL; break; } - - if ((p = strchr(response, ' '))) { + + if ((p = strchr(response, ' '))) { *p = '\0'; - + 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->msgno = atoi(response); uid_elem->uid = EM_SAFE_STRDUP(p + 1); - + if (*uid_list != NULL) uid_elem->next = *uid_list; /* prepend new data to table */ - + *uid_list = uid_elem; } else { err = EMAIL_ERROR_INVALID_RESPONSE; goto FINISH_OFF; } - + free(response); response = NULL; } - + ret = true; -FINISH_OFF: +FINISH_OFF: if (response != NULL) free(response); - + if (err_code != NULL) *err_code = err; - + EM_PROFILE_END(pop3MailboxGetuid); - EM_DEBUG_FUNC_END("ret [%d]", ret); + EM_DEBUG_FUNC_END("ret [%d]", ret); return ret; } @@ -362,64 +362,64 @@ int imap4_mailbox_get_uids(MAILSTREAM *stream, emcore_uid_list** uid_list, int * int ret = false; int err = EMAIL_ERROR_NONE; - + IMAPLOCAL *imaplocal = NULL; char tag[16], command[64]; char *response = NULL; emcore_uid_list *uid_elem = NULL; - + if (!stream || !uid_list) { EM_DEBUG_EXCEPTION("stream[%p], uid_list[%p]", stream, 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; } - + if (stream->nmsgs == 0){ err = EMAIL_ERROR_MAIL_NOT_FOUND_ON_SERVER; goto FINISH_OFF; } memset(tag, 0x00, sizeof(tag)); memset(command, 0x00, sizeof(command)); - + SNPRINTF(tag, sizeof(tag), "%08lx", 0xffffffff & (stream->gensym++)); SNPRINTF(command, sizeof(command), "%s FETCH 1:* (FLAGS UID)\015\012", tag); EM_DEBUG_LOG("COMMAND [%s] \n", command); #ifdef FEATURE_CORE_DEBUG EM_DEBUG_LOG(" [IMAP4] >>> [%s]", command); #endif - + /* send command : get msgno/uid for all message */ if (!net_sout(imaplocal->netstream, command, (int)EM_SAFE_STRLEN(command))) { EM_DEBUG_EXCEPTION(" net_sout failed...\n"); - err = EMAIL_ERROR_CONNECTION_BROKEN; + err = EMAIL_ERROR_CONNECTION_BROKEN; goto FINISH_OFF; } - + *uid_list = NULL; - + while (imaplocal->netstream) { char *p = NULL; char *s = NULL; int seen = 0; - int forwarded = 0; + int forwarded = 0; int draft = 0; /* receive response */ if (!(response = net_getline(imaplocal->netstream))) { EM_DEBUG_EXCEPTION("net_getline failed..."); - err = EMAIL_ERROR_INVALID_RESPONSE; + 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)) { free(response); response = NULL; @@ -430,29 +430,29 @@ int imap4_mailbox_get_uids(MAILSTREAM *stream, emcore_uid_list** uid_list, int * goto FINISH_OFF; } } - - if ((p = strstr(response, " FETCH ("))) { + + if ((p = strstr(response, " FETCH ("))) { if (!strstr(p, "\\Deleted")) { /* undeleted only */ *p = '\0'; p += strlen(" FETCH "); - + seen = strstr(p, "\\Seen") ? 1 : 0; draft = strstr(p, "\\Draft") ? 1 : 0; forwarded = strstr(p, "$Forwarded") ? 1 : 0; - + if ((p = strstr(p, "UID "))) { s = p + strlen("UID "); - + while (isdigit(*s)) s++; - + *s = '\0'; - + if (!(uid_elem = em_malloc(sizeof(emcore_uid_list)))) { EM_DEBUG_EXCEPTION("em_malloc failed..."); err = EMAIL_ERROR_OUT_OF_MEMORY; goto FINISH_OFF; } - + uid_elem->msgno = atoi(response + strlen("* ")); uid_elem->uid = EM_SAFE_STRDUP(p + strlen("UID ")); uid_elem->flag.seen = seen; @@ -460,7 +460,7 @@ int imap4_mailbox_get_uids(MAILSTREAM *stream, emcore_uid_list** uid_list, int * uid_elem->flag.forwarded = forwarded; if (*uid_list != NULL) uid_elem->next = *uid_list; /* prepend new data to list */ - + *uid_list = uid_elem; } else { @@ -473,20 +473,20 @@ int imap4_mailbox_get_uids(MAILSTREAM *stream, emcore_uid_list** uid_list, int * err = EMAIL_ERROR_INVALID_RESPONSE; goto FINISH_OFF; } - + EM_SAFE_FREE(response);; } - + ret = true; -FINISH_OFF: +FINISH_OFF: EM_SAFE_FREE(response); if (err_code != NULL) *err_code = err; - + EM_PROFILE_END(ImapMailboxGetUids); - EM_DEBUG_FUNC_END("ret [%d]", ret); + EM_DEBUG_FUNC_END("ret [%d]", ret); return ret; } @@ -536,7 +536,7 @@ static char *__em_get_month_in_string(int month) } return mon; } - + int imap4_mailbox_get_uids_by_timestamp(MAILSTREAM *stream, emcore_uid_list** uid_list, int *err_code) { EM_PROFILE_BEGIN(emCoreMailboxuidsbystamp); @@ -544,7 +544,7 @@ int imap4_mailbox_get_uids_by_timestamp(MAILSTREAM *stream, emcore_uid_list** ui int ret = false; int err = EMAIL_ERROR_NONE; - + IMAPLOCAL *imaplocal = NULL; char tag[16], command[64]; char *response = NULL; @@ -554,16 +554,16 @@ int imap4_mailbox_get_uids_by_timestamp(MAILSTREAM *stream, emcore_uid_list** ui struct tm *timeinfo = NULL; time_t RawTime = 0; - time_t week_before_RawTime = 0; + time_t week_before_RawTime = 0; char date_string[16]; char *mon = NULL; - + if (!stream || !uid_list) { EM_DEBUG_EXCEPTION(" stream[%p], uid_list[%p]", stream, uid_list); err = 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 */ @@ -596,14 +596,14 @@ int imap4_mailbox_get_uids_by_timestamp(MAILSTREAM *stream, emcore_uid_list** ui EM_DEBUG_LOG("DATE IS [ %s ] ", date_string); EM_SAFE_FREE(mon); } - + memset(tag, 0x00, sizeof(tag)); memset(command, 0x00, sizeof(command)); - + SNPRINTF(tag, sizeof(tag), "%08lx", 0xffffffff & (stream->gensym++)); SNPRINTF(command, sizeof(command), "%s UID SEARCH 1:* SINCE %s\015\012", tag, date_string); EM_DEBUG_LOG("COMMAND [%s] ", command); - + #ifdef FEATURE_CORE_DEBUG EM_DEBUG_LOG(" [IMAP4] >>> [%s]", command); #endif @@ -675,14 +675,14 @@ int imap4_mailbox_get_uids_by_timestamp(MAILSTREAM *stream, emcore_uid_list** ui ret = true; -FINISH_OFF: +FINISH_OFF: if (response != NULL) free(response); if (err_code != NULL) *err_code = err; EM_PROFILE_END(emCoreMailboxuidsbystamp); - EM_DEBUG_FUNC_END("ret [%d]", ret); + EM_DEBUG_FUNC_END("ret [%d]", ret); return ret; } @@ -691,77 +691,77 @@ static int emcore_parse_header(char *rfc822_header, int *req_read_receipt, int * { EM_DEBUG_FUNC_BEGIN("rfc822_header[%p], req_read_receipt[%p], priority[%p], err_code[%p]", rfc822_header, req_read_receipt, priority, err_code); - if (!rfc822_header || !priority) + if (!rfc822_header || !priority) return false; if (err_code) *err_code = EMAIL_ERROR_NONE; EM_PROFILE_BEGIN(emCoreMailboxParseHeader); - + char buf[PARSE_BUFFER_LENGTH]; int len, i, j; - + EM_DEBUG_LOG("Buffer length [%d]", PARSE_BUFFER_LENGTH); *priority = 3; - + memset(buf, 0x00, PARSE_BUFFER_LENGTH); - + for (len = EM_SAFE_STRLEN(rfc822_header), i = 0, j = 0; i < len; i++) { if (rfc822_header[i] == CR && rfc822_header[i+1] == LF){ if (j + 3 < PARSE_BUFFER_LENGTH) /* '3' include CR LF NULL */ - strncpy(buf + j, CRLF_STRING, PARSE_BUFFER_LENGTH - (j + 2)); /* '3' include CR LF */ + strncpy(buf + j, CRLF_STRING, PARSE_BUFFER_LENGTH - (j + 2)); /* '3' include CR LF */ else EM_DEBUG_EXCEPTION("buf is too small."); i++; j = 0; - + /* parsing data */ em_upper_string(buf); - + /* disposition_notification_to */ if (buf[0] == 'D' && buf[11] == '-' && buf[12] == 'N' && buf[24] == '-' && buf[25] == 'T') { - if (req_read_receipt) + if (req_read_receipt) *req_read_receipt = 1; memset(buf, 0x00, PARSE_BUFFER_LENGTH); continue; } - + /* x-priority */ if (buf[0] == 'X' && buf[2] == 'P' && buf[9] == 'Y'){ size_t len_2 = EM_SAFE_STRLEN(buf); - if (len_2 >= 12){ + if (len_2 >= 12){ buf[len_2 - 2] = '\0'; *priority = atoi(buf + 11); memset(buf, 0x00, PARSE_BUFFER_LENGTH); continue; } } - + /* x-msmail-priority */ if (buf[0] == 'X' && buf[2] == 'M' && buf[9] == 'P' && buf[16] == 'Y'){ - if (strstr(buf, "HIGH")) + if (strstr(buf, "HIGH")) *priority = 1; - if (strstr(buf, "NORMAL")) + if (strstr(buf, "NORMAL")) *priority = 3; - if (strstr(buf, "LOW")) + if (strstr(buf, "LOW")) *priority = 5; memset(buf, 0x00, PARSE_BUFFER_LENGTH); continue; } - + memset(buf, 0x00, PARSE_BUFFER_LENGTH); continue; } - + if (j + 1 < PARSE_BUFFER_LENGTH) buf[j++] = rfc822_header[i]; else EM_DEBUG_EXCEPTION("buf is too small."); } - + EM_PROFILE_END(emCoreMailboxParseHeader); if (err_code) @@ -775,12 +775,12 @@ static int emcore_get_mail_extra_info(MAILSTREAM *stream, int msgno, int *req_re { EM_PROFILE_BEGIN(emCoreMailGetExtraInfo); EM_DEBUG_FUNC_BEGIN("stream[%p], msgno[%d], req_read_receipt[%p], priority[%p], err_code[%p]", stream, msgno, req_read_receipt, priority, err_code); - + int ret = false; int err = EMAIL_ERROR_NONE; char *rfc822_header = NULL; unsigned long len = 0; - + EM_PROFILE_BEGIN(MaiFetchHeader); #ifdef __FEATURE_HEADER_OPTIMIZATION__ /* Check if header already available in cache */ @@ -804,20 +804,20 @@ static int emcore_get_mail_extra_info(MAILSTREAM *stream, int msgno, int *req_re err = EMAIL_ERROR_IMAP4_FETCH_UID_FAILURE; /* EMAIL_ERROR_UNKNOWN; */ goto FINISH_OFF; } - + if (!emcore_parse_header(rfc822_header, req_read_receipt, priority, &err)) { EM_DEBUG_EXCEPTION("emcore_parse_header falied - %d", err); goto FINISH_OFF; } ret = true; - -FINISH_OFF: - + +FINISH_OFF: + if (err_code != NULL) *err_code = err; EM_PROFILE_END(emCoreMailGetExtraInfo); - EM_DEBUG_FUNC_END("ret [%d]", ret); + EM_DEBUG_FUNC_END("ret [%d]", ret); return ret; } @@ -828,9 +828,9 @@ static int emcore_get_uids_to_download(MAILSTREAM *stream, email_account_t *acco int ret = false; int err = EMAIL_ERROR_NONE; - + emstorage_read_mail_uid_tbl_t *downloaded_uids = NULL; - int i = 0, j = 0, uid_count = 0, uid_to_be_downloaded_count = 0; + int i = 0, j = 0, uid_count = 0, uid_to_be_downloaded_count = 0; emcore_uid_list *uid_elem = NULL; emcore_uid_list *head_uid_elem = NULL, *end = NULL; emcore_uid_list *next_uid_elem = NULL; @@ -841,9 +841,9 @@ static int emcore_get_uids_to_download(MAILSTREAM *stream, email_account_t *acco err = EMAIL_ERROR_INVALID_PARAM; goto FINISH_OFF; } - + *uid_list = NULL; - + if (account->incoming_server_type == EMAIL_SERVER_TYPE_POP3) { if (!pop3_mailbox_get_uids(stream, uid_list, &err)) { EM_DEBUG_EXCEPTION("pop3_mailbox_get_uids failed - %d", err); @@ -852,7 +852,7 @@ 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); @@ -860,7 +860,7 @@ static int emcore_get_uids_to_download(MAILSTREAM *stream, email_account_t *acco goto FINISH_OFF; } } - + if (!emstorage_get_downloaded_list(input_mailbox_tbl->account_id, (account->incoming_server_type == EMAIL_SERVER_TYPE_POP3) ? 0 : input_mailbox_tbl->mailbox_id, &downloaded_uids, &j, true, &err)) { @@ -878,24 +878,24 @@ static int emcore_get_uids_to_download(MAILSTREAM *stream, email_account_t *acco downloaded_uids[i].reserved = 0; } } - - EM_PROFILE_BEGIN(emCoreGetUidsDownloadWhilwLoop); - + + EM_PROFILE_BEGIN(emCoreGetUidsDownloadWhilwLoop); + 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 (uid_elem->uid) free(uid_elem->uid); - + free(uid_elem); } else { int to_be_downloaded = 1; - + if (limit_count > 0 && uid_count >= limit_count){ /* EM_DEBUG_LOG("hit the limit[%d] for [%s]", limit_count, uid_elem->uid); */ - to_be_downloaded = 0; + to_be_downloaded = 0; } else{ for (i = j; i > 0; i--) { @@ -908,8 +908,8 @@ 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); */ - - if (to_be_downloaded) { + + if (to_be_downloaded) { if (retrieve_mode == EMAIL_SYNC_OLDEST_MAILS_FIRST){ uid_elem->next = head_uid_elem; head_uid_elem = uid_elem; @@ -917,33 +917,33 @@ static int emcore_get_uids_to_download(MAILSTREAM *stream, email_account_t *acco else{ /* if retrieve_mode is EMAIL_SYNC_LATEST_MAILS_FIRST, add uid elem to end so that latest mails are in front of list */ if (head_uid_elem == NULL){ uid_elem->next = head_uid_elem; - head_uid_elem = uid_elem; + head_uid_elem = uid_elem; end = head_uid_elem; } else{ end->next = uid_elem; uid_elem->next = NULL; - end = uid_elem; + end = uid_elem; } } uid_to_be_downloaded_count++; - + } else { if (uid_elem->uid) free(uid_elem->uid); free(uid_elem); } - + uid_count++; } uid_elem = next_uid_elem; } - EM_PROFILE_END(emCoreGetUidsDownloadWhilwLoop); - EM_PROFILE_BEGIN(emCoreGetUidsDownloadForLoop); - + EM_PROFILE_END(emCoreGetUidsDownloadWhilwLoop); + EM_PROFILE_BEGIN(emCoreGetUidsDownloadForLoop); + for (i = 0; i < j; i++) { /* EM_DEBUG_LOG("input_mailbox_tbl[%s] reserved[%d]", input_mailbox_tbl->name, downloaded_uids[i].reserved); */ if (downloaded_uids[i].reserved == 0) { /* deleted on server */ @@ -953,30 +953,30 @@ static int emcore_get_uids_to_download(MAILSTREAM *stream, email_account_t *acco continue; } } - + 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)) { 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(); + emcore_display_unread_in_badge(); } - + if (!emstorage_remove_downloaded_mail(input_mailbox_tbl->account_id, input_mailbox_tbl->mailbox_name, downloaded_uids[i].s_uid, true, &err)) { /* remove uid from uid list */ EM_DEBUG_EXCEPTION("emstorage_remove_downloaded_mail failed - %d", err); - + /* goto FINISH_OFF; */ } - + } - else if (account->incoming_server_type == EMAIL_SERVER_TYPE_IMAP4 && downloaded_uids[i].reserved == 1) { + else if (account->incoming_server_type == EMAIL_SERVER_TYPE_IMAP4 && downloaded_uids[i].reserved == 1) { /* unseen on server */ if (!emstorage_get_mail_by_id(downloaded_uids[i].local_uid, &mail, true, &err)){ EM_DEBUG_EXCEPTION("emstorage_get_mail_by_id failed for [%d] - [%d]", downloaded_uids[i].local_uid, err); continue; } - + if (mail) { if (mail->body_download_status && mail->flags_seen_field){ EM_DEBUG_LOG("Set flag as seen on server"); @@ -988,30 +988,30 @@ static int emcore_get_uids_to_download(MAILSTREAM *stream, email_account_t *acco emstorage_free_mail(&mail, 1, NULL); mail = NULL; } - EM_PROFILE_END(emCoreGetUidsDownloadForLoop); - + EM_PROFILE_END(emCoreGetUidsDownloadForLoop); + *uid_list = head_uid_elem; *uids = uid_to_be_downloaded_count; - + ret = true; - -FINISH_OFF: + +FINISH_OFF: if (ret == false){ if (head_uid_elem) emcore_free_uids(head_uid_elem, NULL); } - + if (downloaded_uids != NULL) emstorage_free_read_mail_uid(&downloaded_uids, j, NULL); if (mail != NULL) emstorage_free_mail(&mail, 1, NULL); - + if (err_code != NULL) *err_code = err; - + EM_PROFILE_END(emCoreGetUidsDownload); - EM_DEBUG_FUNC_END("ret [%d]", ret); + EM_DEBUG_FUNC_END("ret [%d]", ret); return ret; } @@ -1019,68 +1019,68 @@ FINISH_OFF: static int emcore_add_read_mail_uid(emstorage_mailbox_tbl_t *input_maibox_data, char *server_mailbox_name, int mail_id, char *uid, int rfc822_size, int rule_id, int *err_code) { EM_DEBUG_FUNC_BEGIN("input_maibox_data[%p], server_mailbox_name[%s], uid[%s], rfc822_size[%d], rule_id[%d], err_code[%p]", input_maibox_data, server_mailbox_name, uid, rfc822_size, rule_id, err_code); - + int ret = false; int err = EMAIL_ERROR_NONE; - + emstorage_read_mail_uid_tbl_t read_mail_uid = { 0 }; emstorage_mailbox_tbl_t *mailbox_tbl = NULL; - + if (!input_maibox_data || !uid) { EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM"); err = EMAIL_ERROR_INVALID_PARAM; goto FINISH_OFF; } - + read_mail_uid.account_id = input_maibox_data->account_id; - + if (!(input_maibox_data->mailbox_id) || !(server_mailbox_name)){ if (!emstorage_get_mailbox_by_mailbox_type(input_maibox_data->account_id, EMAIL_MAILBOX_TYPE_INBOX, &mailbox_tbl, false, &err)) { EM_DEBUG_EXCEPTION("emstorage_get_mailbox_by_mailbox_type failed [%d]", err); goto FINISH_OFF; } } - + if (input_maibox_data->mailbox_id) read_mail_uid.mailbox_id = input_maibox_data->mailbox_id; else 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); - + EM_DEBUG_LOG("MAIL ID [%d] LOCAL_UID [%d]", mail_id, read_mail_uid.local_uid); + if (server_mailbox_name) read_mail_uid.mailbox_name = server_mailbox_name; else read_mail_uid.mailbox_name = mailbox_tbl->mailbox_name; - + read_mail_uid.s_uid = uid; read_mail_uid.data1 = rfc822_size; read_mail_uid.flag = rule_id; - + if (!emstorage_add_downloaded_mail(&read_mail_uid, false, &err)) { EM_DEBUG_EXCEPTION("emstorage_add_downloaded_mail failed [%d]", err); goto FINISH_OFF; } - + ret = true; - -FINISH_OFF: + +FINISH_OFF: if (mailbox_tbl) emstorage_free_mailbox(&mailbox_tbl, 1, NULL); if (err_code) *err_code = err; - - EM_DEBUG_FUNC_END("ret [%d]", ret); + + EM_DEBUG_FUNC_END("ret [%d]", ret); return ret; } int emcore_add_mail_to_mailbox(emstorage_mailbox_tbl_t *input_maibox_data, emstorage_mail_tbl_t *input_new_mail_tbl_data, int *output_mail_id, int *output_thread_id) { EM_DEBUG_FUNC_BEGIN("input_maibox_data[%p], input_new_mail_tbl_data[%p], uid_elem[%p], output_mail_id[%p], output_thread_id[%p]", mail_stream, input_maibox_data, input_new_mail_tbl_data, output_mail_id, output_thread_id); - + int err = EMAIL_ERROR_NONE; int thread_id = -1; int thread_item_count = 0; @@ -1090,7 +1090,7 @@ int emcore_add_mail_to_mailbox(emstorage_mailbox_tbl_t *input_maibox_data, emsto EM_DEBUG_EXCEPTION("Invalid Parameter"); err = EMAIL_ERROR_INVALID_PARAM; goto FINISH_OFF; - } + } input_new_mail_tbl_data->account_id = input_maibox_data->account_id; input_new_mail_tbl_data->mailbox_id = input_maibox_data->mailbox_id; @@ -1116,13 +1116,13 @@ int emcore_add_mail_to_mailbox(emstorage_mailbox_tbl_t *input_maibox_data, emsto input_new_mail_tbl_data->thread_id = thread_id; thread_item_count++; } - + if (!emstorage_add_mail(input_new_mail_tbl_data, 0, false, &err)) { EM_DEBUG_EXCEPTION("emstorage_add_mail failed [%d]", err); emstorage_rollback_transaction(NULL, NULL, NULL); goto FINISH_OFF; } - + if (thread_item_count > 1){ if (!emstorage_update_latest_thread_mail(input_new_mail_tbl_data->account_id, input_new_mail_tbl_data->thread_id, 0, 0, false, &err)) { EM_DEBUG_EXCEPTION("emstorage_update_latest_thread_mail failed [%d]", err); @@ -1132,10 +1132,10 @@ int emcore_add_mail_to_mailbox(emstorage_mailbox_tbl_t *input_maibox_data, emsto } if (output_thread_id) *output_thread_id = input_new_mail_tbl_data->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); @@ -1144,10 +1144,10 @@ int emcore_add_mail_to_mailbox(emstorage_mailbox_tbl_t *input_maibox_data, emsto emstorage_rollback_transaction(NULL, NULL, NULL); goto FINISH_OFF; } - + emstorage_commit_transaction(NULL, NULL, NULL); - -FINISH_OFF: + +FINISH_OFF: EM_DEBUG_FUNC_END("err [%d]", err); return err; @@ -1156,21 +1156,21 @@ FINISH_OFF: int emcore_check_rule(const char *input_full_address_from, const char *input_subject, emstorage_rule_tbl_t *rule, int rule_len, int *matched, int *err_code) { EM_DEBUG_FUNC_BEGIN("input_full_address_from [%p], input_subject [%p], rule [%p], rule_len [%d], matched [%p], err_code [%p]", input_full_address_from, input_subject, rule, rule_len, matched, err_code); - + int ret = false, err = EMAIL_ERROR_NONE, i; size_t len = 0; char *src = NULL; /* string which will be compared with rules */ char *from_address = NULL; ADDRESS *addr = NULL; - + if (!matched || !input_full_address_from || !input_subject) { EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM"); err = EMAIL_ERROR_INVALID_PARAM; goto FINISH_OFF; } - + *matched = -1; - + rfc822_parse_adrlist(&addr, (char*)input_full_address_from, NULL); if(addr) { @@ -1205,7 +1205,7 @@ int emcore_check_rule(const char *input_full_address_from, const char *input_sub EM_DEBUG_LOG("rule[%d].flag1(rule id[%d]) is %d", i, rule[i].rule_id, rule[i].flag1); - if (rule[i].flag1){ + if (rule[i].flag1){ /* 'ON' */ EM_DEBUG_LOG("rule[%d].flag2(rule id[%d]) is %d", i, rule[i].rule_id, rule[i].flag2); switch (rule[i].type) { @@ -1215,7 +1215,7 @@ int emcore_check_rule(const char *input_full_address_from, const char *input_sub case EMAIL_FILTER_SUBJECT: src = (char*)input_subject; break; - case EMAIL_FILTER_BODY: + case EMAIL_FILTER_BODY: err = EMAIL_ERROR_NOT_SUPPORTED; goto FINISH_OFF; break; @@ -1225,13 +1225,13 @@ int emcore_check_rule(const char *input_full_address_from, const char *input_sub if (src && rule[i].value) { if (RULE_TYPE_INCLUDES == rule[i].flag2) { if (strstr(src, rule[i].value)) { - *matched = i; + *matched = i; break; } } else if (RULE_TYPE_EXACTLY == rule[i].flag2) { if (!strcmp(src, rule[i].value)) { - *matched = i; + *matched = i; break; } } @@ -1243,39 +1243,39 @@ int emcore_check_rule(const char *input_full_address_from, const char *input_sub ret = true; EM_DEBUG_LOG("i [%d], matched [%d]", i, *matched); -FINISH_OFF: +FINISH_OFF: EM_SAFE_FREE(from_address); - + if (addr != NULL) - mail_free_address(&addr); - + mail_free_address(&addr); + if (err_code != NULL) *err_code = err; - - EM_DEBUG_FUNC_END("ret [%d]", ret); + + EM_DEBUG_FUNC_END("ret [%d]", ret); return ret; } static int emcore_get_utf8_address(char **dest, ADDRESS *address, int *err_code) { EM_DEBUG_FUNC_BEGIN("dest[%p], address[%p], err_code[%p]", dest, address, err_code); - + if (!dest || !address) { EM_DEBUG_EXCEPTION("dest[%p], address[%p]", dest, address); if (err_code != NULL) *err_code = EMAIL_ERROR_INVALID_PARAM; return false; } - + int ret = false; int err = EMAIL_ERROR_NONE; - + gchar *concatenated = NULL; gchar *utf8_address = NULL; gchar *temp = NULL; char *nickname = NULL; - + while (address) { EM_DEBUG_LOG("address->mailbox[%s], address->host[%s]", address->mailbox, address->host); if (!address->mailbox || !address->host) { @@ -1289,18 +1289,18 @@ static int emcore_get_utf8_address(char **dest, ADDRESS *address, int *err_code) goto FINISH_OFF; } EM_DEBUG_LOG("nickname[%s]", nickname); - if (*nickname != '\0') + if (*nickname != '\0') utf8_address = g_strdup_printf("\"%s\" <%s@%s>", nickname, address->mailbox ? address->mailbox : "", address->host ? address->host : ""); else utf8_address = g_strdup_printf("<%s@%s>", address->mailbox ? address->mailbox : "", address->host ? address->host : ""); - + EM_SAFE_FREE(nickname); } else utf8_address = g_strdup_printf("<%s@%s>", address->mailbox ? address->mailbox : "", address->host ? address->host : ""); - + EM_DEBUG_LOG("utf8_address[%s]", utf8_address); - + if (concatenated != NULL) { temp = concatenated; concatenated = g_strdup_printf("%s; %s", temp, utf8_address); @@ -1308,17 +1308,17 @@ static int emcore_get_utf8_address(char **dest, ADDRESS *address, int *err_code) } else concatenated = g_strdup(utf8_address); - - g_free(utf8_address); + + g_free(utf8_address); utf8_address = NULL; - + address = address->next; } - + *dest = concatenated; - + ret = true; - + FINISH_OFF: EM_SAFE_FREE(nickname); EM_DEBUG_FUNC_END("ret[%d]", ret); @@ -1345,13 +1345,13 @@ int emcore_make_mail_tbl_data_from_envelope(MAILSTREAM *mail_stream, ENVELOPE *i err = EMAIL_ERROR_INVALID_PARAM; goto FINISH_OFF; } - + if (!(temp_mail_tbl_data = em_malloc(sizeof(emstorage_mail_tbl_t)))) { EM_DEBUG_EXCEPTION("em_malloc failed..."); err = EMAIL_ERROR_OUT_OF_MEMORY; goto FINISH_OFF; } - + if (!(mail_cache_element = mail_elt(mail_stream, input_uid_elem->msgno))) { EM_DEBUG_EXCEPTION("mail_elt failed..."); err = EMAIL_ERROR_UNKNOWN; @@ -1367,54 +1367,54 @@ int emcore_make_mail_tbl_data_from_envelope(MAILSTREAM *mail_stream, ENVELOPE *i temp_mail_tbl_data->subject = emcore_decode_rfc2047_text(input_envelope->subject, &err); EM_DEBUG_LOG("subject[%s]", temp_mail_tbl_data->subject); } - + if (input_envelope->from) { if (!emcore_get_utf8_address(&temp_mail_tbl_data->full_address_from, input_envelope->from, &err)) { EM_DEBUG_EXCEPTION("emcore_get_utf8_address failed [%d]", err); goto FINISH_OFF; } - + EM_DEBUG_LOG("full_address_from[%s]", temp_mail_tbl_data->full_address_from); } - + if (input_envelope->to) { EM_DEBUG_LOG("input_envelope->to"); if (!emcore_get_utf8_address(&temp_mail_tbl_data->full_address_to, input_envelope->to, &err)) { EM_DEBUG_EXCEPTION("emcore_get_utf8_address failed [%d]", err); goto FINISH_OFF; } - + EM_DEBUG_LOG("full_address_to[%s]", temp_mail_tbl_data->full_address_to); } - + if (input_envelope->cc) { EM_DEBUG_LOG("input_envelope->cc"); if (!emcore_get_utf8_address(&temp_mail_tbl_data->full_address_cc, input_envelope->cc, &err)) { EM_DEBUG_EXCEPTION("emcore_get_utf8_address failed [%d]", err); goto FINISH_OFF; } - + EM_DEBUG_LOG("full_address_cc [%s]", temp_mail_tbl_data->full_address_cc); } - + if (input_envelope->bcc) { if (!emcore_get_utf8_address(&temp_mail_tbl_data->full_address_bcc, input_envelope->bcc, &err)) { EM_DEBUG_EXCEPTION("emcore_get_utf8_address failed [%d]", err); goto FINISH_OFF; } - + EM_DEBUG_LOG("full_address_bcc [%s]", temp_mail_tbl_data->full_address_bcc); } - + if (input_envelope->reply_to) { if (!emcore_get_utf8_address(&temp_mail_tbl_data->full_address_reply, input_envelope->reply_to, &err)) { EM_DEBUG_EXCEPTION("emcore_get_utf8_address failed [%d]", err); goto FINISH_OFF; } - + EM_DEBUG_LOG("full_address_reply [%s]\n", temp_mail_tbl_data->full_address_reply); } - + if (input_envelope->return_path) { if (!emcore_get_utf8_address(&temp_mail_tbl_data->full_address_return , input_envelope->return_path, &err)) { EM_DEBUG_EXCEPTION("emcore_get_utf8_address failed [%d]", err); @@ -1422,15 +1422,15 @@ int emcore_make_mail_tbl_data_from_envelope(MAILSTREAM *mail_stream, ENVELOPE *i } EM_DEBUG_LOG("full_address_return[%s]", temp_mail_tbl_data->full_address_return); } - + temp_mail_tbl_data->message_id = EM_SAFE_STRDUP(input_envelope->message_id); - + 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); - + temp_time_info.tm_sec = mail_cache_element->seconds; temp_time_info.tm_min = mail_cache_element->minutes + mail_cache_element->zminutes; temp_time_info.tm_hour = mail_cache_element->hours - zone_hour; @@ -1465,19 +1465,19 @@ int emcore_make_mail_tbl_data_from_envelope(MAILSTREAM *mail_stream, ENVELOPE *i *output_mail_tbl_data = temp_mail_tbl_data; temp_mail_tbl_data = NULL; - + ret = true; - -FINISH_OFF: + +FINISH_OFF: if (ret != true) EM_SAFE_FREE(temp_mail_tbl_data); - + if (err_code != NULL) *err_code = err; - + EM_PROFILE_END(emCoreParseEnvelope); - EM_DEBUG_FUNC_END("ret [%d]", ret); + EM_DEBUG_FUNC_END("ret [%d]", ret); return ret; } @@ -1501,7 +1501,7 @@ INTERNAL_FUNC int emcore_sync_header(emstorage_mailbox_tbl_t *input_mailbox_tbl, void *stream = NULL; char *uid_range = NULL; char mailbox_id_param_string[10] = {0,}; - + if (!input_mailbox_tbl) { EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM:input_mailbox_tbl[%p]", input_mailbox_tbl); err = EMAIL_ERROR_INVALID_PARAM; @@ -1510,12 +1510,12 @@ INTERNAL_FUNC int emcore_sync_header(emstorage_mailbox_tbl_t *input_mailbox_tbl, account_id = input_mailbox_tbl->account_id; account_ref = emcore_get_account_reference(account_id); - if (!account_ref) { + if (!account_ref) { EM_DEBUG_EXCEPTION("emcore_get_account_reference failed - %d", account_id); err = EMAIL_ERROR_INVALID_ACCOUNT; 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; @@ -1523,7 +1523,7 @@ INTERNAL_FUNC int emcore_sync_header(emstorage_mailbox_tbl_t *input_mailbox_tbl, } FINISH_OFF_IF_CANCELED; - + #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); @@ -1535,50 +1535,50 @@ INTERNAL_FUNC int emcore_sync_header(emstorage_mailbox_tbl_t *input_mailbox_tbl, if (stream_recycle) stream = stream_recycle; /* set stream for recycling connection. */ #endif - + 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; goto FINISH_OFF; } - + FINISH_OFF_IF_CANCELED; - + /* 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)){ EM_DEBUG_EXCEPTION("emstorage_update_mailbox_total_count failed [%d]", err); goto FINISH_OFF; } - + /* 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); - + if (opt_ref->block_address || opt_ref->block_subject) { int is_completed = false; int type = 0; - + if (!opt_ref->block_address) type = EMAIL_FILTER_SUBJECT; else if (!opt_ref->block_subject) type = EMAIL_FILTER_FROM; - - if (!emstorage_get_rule(ALL_ACCOUNT, type, 0, &rule_len, &is_completed, &rule, true, &err) || !rule) + + if (!emstorage_get_rule(ALL_ACCOUNT, type, 0, &rule_len, &is_completed, &rule, true, &err) || !rule) EM_DEBUG_EXCEPTION("emstorage_get_rule failed - %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, &total, EMAIL_SYNC_LATEST_MAILS_FIRST, &err)){ EM_DEBUG_EXCEPTION("emcore_get_uids_to_download failed [%d]", err); - uid_list = NULL; + uid_list = NULL; goto FINISH_OFF; } - + FINISH_OFF_IF_CANCELED; - + if (input_uid_list && *input_uid_list){ - emcore_free_uids(*input_uid_list, NULL); + emcore_free_uids(*input_uid_list, NULL); *input_uid_list = uid_list; } uid_elem = uid_list; @@ -1592,7 +1592,7 @@ INTERNAL_FUNC int emcore_sync_header(emstorage_mailbox_tbl_t *input_mailbox_tbl, 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; + emcore_uid_list *uid_list_fast = uid_list; int index = 0; int msg_count = total; int uid_range_size = msg_count * 8 + 1000; @@ -1605,7 +1605,7 @@ INTERNAL_FUNC int emcore_sync_header(emstorage_mailbox_tbl_t *input_mailbox_tbl, err = EMAIL_ERROR_OUT_OF_MEMORY; goto FINISH_OFF; } - + uid_list_prev = uid_list_fast; if (uid_list_fast->next == NULL){ @@ -1622,7 +1622,7 @@ INTERNAL_FUNC int emcore_sync_header(emstorage_mailbox_tbl_t *input_mailbox_tbl, 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) @@ -1638,7 +1638,7 @@ INTERNAL_FUNC int emcore_sync_header(emstorage_mailbox_tbl_t *input_mailbox_tbl, 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; } @@ -1652,7 +1652,7 @@ INTERNAL_FUNC int emcore_sync_header(emstorage_mailbox_tbl_t *input_mailbox_tbl, } } } - + /* h.gahlaut : [Start] */ /* Adding this check here to check if application has called cancel job. */ /* This checking should be done because fetching 50 headers will take time */ @@ -1670,11 +1670,11 @@ INTERNAL_FUNC int emcore_sync_header(emstorage_mailbox_tbl_t *input_mailbox_tbl, EM_DEBUG_LOG("Uid List Null"); } EM_DEBUG_LOG("Calling ... mail_fetch_fast. uid_range [%s]", uid_range); - mail_fetch_fast(stream, uid_range, FT_UID | FT_PEEK | FT_NEEDENV); + mail_fetch_fast(stream, uid_range, FT_UID | FT_PEEK | FT_NEEDENV); EM_SAFE_FREE(uid_range); } #endif - + /* h.gahlaut@samsung.com : Clear the event queue of partial body download thread before starting fetching new headers */ #ifndef __PARTIAL_BODY_FOR_POP3__ if (account_ref->incoming_server_type == EMAIL_SERVER_TYPE_IMAP4){ @@ -1692,9 +1692,9 @@ INTERNAL_FUNC int emcore_sync_header(emstorage_mailbox_tbl_t *input_mailbox_tbl, env = NULL; if (uid_elem->msgno > ((MAILSTREAM *)stream)->nmsgs) - EM_DEBUG_EXCEPTION("Warnings! msgno[%d] can't be greater than nmsgs[%d]. It might cause crash.", uid_elem->msgno, ((MAILSTREAM *)stream)->nmsgs); + EM_DEBUG_EXCEPTION("Warnings! msgno[%d] can't be greater than nmsgs[%d]. It might cause crash.", uid_elem->msgno, ((MAILSTREAM *)stream)->nmsgs); else{ - + #ifdef __FEATURE_HEADER_OPTIMIZATION__ if (account_ref->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); @@ -1702,13 +1702,13 @@ INTERNAL_FUNC int emcore_sync_header(emstorage_mailbox_tbl_t *input_mailbox_tbl, env = mail_fetchstructure_full(stream, uid_elem->msgno, NULL, FT_PEEK, 1); #else env = mail_fetchstructure_full(stream, uid_elem->msgno, NULL, FT_PEEK); -#endif +#endif } FINISH_OFF_IF_CANCELED; - + if (env != NULL){ int matched = -1; - + if (!emcore_make_mail_tbl_data_from_envelope(stream, env, uid_elem, &new_mail_tbl_data, &err) || !new_mail_tbl_data) { EM_DEBUG_EXCEPTION("emcore_make_mail_tbl_data_from_envelope failed [%d]", err); goto FINISH_OFF; @@ -1718,29 +1718,29 @@ INTERNAL_FUNC int emcore_sync_header(emstorage_mailbox_tbl_t *input_mailbox_tbl, EM_DEBUG_EXCEPTION("emcore_check_rule failed [%d]", err); goto FINISH_OFF; } - + if (matched >= 0 && input_mailbox_tbl_spam){ /* add filtered mails to SPAMBOX */ EM_DEBUG_LOG("mail[%d] added to spambox", mail_id); - + if ( (err = emcore_add_mail_to_mailbox(input_mailbox_tbl_spam, new_mail_tbl_data, &mail_id, &thread_id)) != EMAIL_ERROR_NONE) { EM_DEBUG_EXCEPTION("emcore_add_mail_to_mailbox falied [%d]", err); goto FINISH_OFF; } - + 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, input_mailbox_tbl_spam->mailbox_name, &err)){ EM_DEBUG_EXCEPTION("emcore_move_mail_on_server falied [%d]", err); goto FINISH_OFF; } } - } else { + } else { /* add mails to specified mail box */ EM_DEBUG_LOG("mail[%d] moved to input_mailbox_tbl [%s]", mail_id, input_mailbox_tbl->mailbox_name); if ( (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 FINISH_OFF; } - + /*h.gahlaut : Start partial body dowload using partial body thread only for IMAP accounts*/ #ifndef __PARTIAL_BODY_FOR_POP3__ if (account_ref->incoming_server_type == EMAIL_SERVER_TYPE_IMAP4) { @@ -1755,9 +1755,9 @@ INTERNAL_FUNC int emcore_sync_header(emstorage_mailbox_tbl_t *input_mailbox_tbl, /* 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 (!uid_elem->flag.seen) unread++; @@ -1768,7 +1768,7 @@ INTERNAL_FUNC int emcore_sync_header(emstorage_mailbox_tbl_t *input_mailbox_tbl, 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"); } - + /* Set contact log */ switch (input_mailbox_tbl->mailbox_type) { case EMAIL_MAILBOX_TYPE_INBOX : @@ -1796,16 +1796,16 @@ INTERNAL_FUNC int emcore_sync_header(emstorage_mailbox_tbl_t *input_mailbox_tbl, FINISH_OFF_IF_CANCELED; } - + uid_elem = uid_elem->next; i++; EM_PROFILE_END(emCoreSyncHeaderEachMail); } EM_PROFILE_END(emCoreSyncHeaderwhileloop); } - + ret = true; -FINISH_OFF: +FINISH_OFF: *unread_mail = unread; @@ -1823,7 +1823,7 @@ FINISH_OFF: if (new_mail_tbl_data) emstorage_free_mail(&new_mail_tbl_data, 1, NULL); - + if (uid_list != NULL){ emcore_free_uids(uid_list, NULL); /* uid_list point to the same memory with input_mailbox_tbl->user_data. */ @@ -1834,22 +1834,22 @@ FINISH_OFF: EM_SAFE_FREE(uid_range); if (rule != NULL) - emstorage_free_rule(&rule, rule_len, NULL); + emstorage_free_rule(&rule, rule_len, NULL); -#ifdef __FEATURE_KEEP_CONNECTION__ +#ifdef __FEATURE_KEEP_CONNECTION__ if (stream != NULL) { #else /* __FEATURE_KEEP_CONNECTION__ */ if (stream != NULL && stream_recycle == NULL) { #endif /* __FEATURE_KEEP_CONNECTION__ */ - emcore_close_mailbox(0, stream); + emcore_close_mailbox(0, stream); stream = NULL; } if (err_code != NULL) *err_code = err; - + EM_PROFILE_END(emCoreSyncHeader); - EM_DEBUG_FUNC_END("ret [%d]", ret); + EM_DEBUG_FUNC_END("ret [%d]", ret); return ret; } @@ -1872,7 +1872,7 @@ emcore_uid_list *__ReverseList(emcore_uid_list *uid_list) return uid_list; } - + int emcore_download_uid_all(email_internal_mailbox_t *mailbox, emcore_uid_list** uid_list, int *total, emstorage_read_mail_uid_tbl_t *downloaded_uids, int count, emcore_get_uids_for_delete_t for_delete, int *err_code) { @@ -1880,7 +1880,7 @@ int emcore_download_uid_all(email_internal_mailbox_t *mailbox, emcore_uid_list** int ret = false; int err = EMAIL_ERROR_NONE; - + MAILSTREAM *stream = NULL; email_account_t *ref_account = NULL; emcore_uid_list *uid_elem = NULL; @@ -1891,14 +1891,14 @@ int emcore_download_uid_all(email_internal_mailbox_t *mailbox, emcore_uid_list** if (!mailbox || !uid_list) { EM_DEBUG_EXCEPTION("mailbox[%p], uid_list[%p], total[%p], downloaded_uids[%p], count[%d], for_delete[%d]", mailbox, uid_list, total, downloaded_uids, count, for_delete); - + err = EMAIL_ERROR_INVALID_PARAM; goto FINISH_OFF; } if (!(ref_account = emcore_get_account_reference(mailbox->account_id))) { EM_DEBUG_EXCEPTION("emcore_get_account_reference failed - %d", mailbox->account_id); - + err = EMAIL_ERROR_INVALID_ACCOUNT; goto FINISH_OFF; } @@ -1906,80 +1906,80 @@ int emcore_download_uid_all(email_internal_mailbox_t *mailbox, emcore_uid_list** if (!mailbox->mail_stream) { if (!emcore_connect_to_remote_mailbox(mailbox->account_id, mailbox->mailbox_id, (void **)&tmp_stream, &err)){ EM_DEBUG_EXCEPTION("emcore_connect_to_remote_mailbox failed..."); - + goto FINISH_OFF; } - + stream = (MAILSTREAM *)tmp_stream; - } - else + } + else stream = mailbox->mail_stream; - + if (ref_account->incoming_server_type == EMAIL_SERVER_TYPE_POP3) { /* POP3 */ POP3LOCAL *pop3local = NULL; - + if (!stream || !(pop3local = stream->local) || !pop3local->netstream) { err = EMAIL_ERROR_INVALID_PARAM; /* EMAIL_ERROR_UNKNOWN; */ goto FINISH_OFF; } - + /* send UIDL */ memset(cmd, 0x00, sizeof(cmd)); - + SNPRINTF(cmd, sizeof(cmd), "UIDL\015\012"); - + #ifdef FEATURE_CORE_DEBUG EM_DEBUG_LOG("[POP3] >>> [%s]", cmd); #endif if (!net_sout(pop3local->netstream, cmd, (int)EM_SAFE_STRLEN(cmd))) { EM_DEBUG_EXCEPTION("net_sout failed..."); - + err = EMAIL_ERROR_CONNECTION_BROKEN; goto FINISH_OFF; } - + /* get uid from replied data */ while (pop3local->netstream) { char *s = NULL; - + if (!(p = net_getline(pop3local->netstream))) break; - + #ifdef FEATURE_CORE_DEBUG EM_DEBUG_LOG(" [POP3] <<< [%s]", p); #endif - + /* replied error "-ERR" */ if (*p == '-') { - err = EMAIL_ERROR_MAIL_NOT_FOUND; + err = EMAIL_ERROR_MAIL_NOT_FOUND; goto FINISH_OFF; } - + /* replied success "+OK" */ if (*p == '+') { free(p); p = NULL; continue; } - + /* end of command */ if (*p == '.') break; - + /* EM_DEBUG_LOG("UID list [%s]", p); */ - + uid_elem = (emcore_uid_list *)malloc(sizeof(emcore_uid_list)); if (!uid_elem) { EM_DEBUG_EXCEPTION("malloc falied..."); - + err = EMAIL_ERROR_OUT_OF_MEMORY; goto FINISH_OFF; } - + memset(uid_elem, 0x00, sizeof(emcore_uid_list)); - + /* format : "1 AAA6FHEAAAQrB6c1ymXxty04yks7hcQ7" */ - + /* save uid */ s = strstr(p, " "); if (s) { @@ -1987,7 +1987,7 @@ int emcore_download_uid_all(email_internal_mailbox_t *mailbox, emcore_uid_list** uid_elem->msgno = atoi(p); uid_elem->uid = EM_SAFE_STRDUP(s+1); } - + /* check downloaded_uids */ if (downloaded_uids) { int i; @@ -1998,21 +1998,21 @@ int emcore_download_uid_all(email_internal_mailbox_t *mailbox, emcore_uid_list** } } } - + if (*uid_list) { fetch_data_p = *uid_list; - + while (fetch_data_p->next) fetch_data_p = fetch_data_p->next; - + fetch_data_p->next = uid_elem; } else *uid_list = uid_elem; - + if (total) ++(*total); - + free(p); p = NULL; } } @@ -2021,102 +2021,102 @@ int emcore_download_uid_all(email_internal_mailbox_t *mailbox, emcore_uid_list** char tag[16]; char *s = NULL; char *t = NULL; - + if (!stream || !(imaplocal = stream->local) || !imaplocal->netstream) { err = EMAIL_ERROR_INVALID_PARAM; /* EMAIL_ERROR_UNKNOWN; */ goto FINISH_OFF; } - + /* send FETCH UID */ memset(tag, 0x00, sizeof(tag)); memset(cmd, 0x00, sizeof(cmd)); - + SNPRINTF(tag, sizeof(tag), "%08lx", 0xffffffff & (stream->gensym++)); SNPRINTF(cmd, sizeof(cmd), "%s UID FETCH %d:* (FLAGS)\015\012", tag, 1); #ifdef FEATURE_CORE_DEBUG - EM_DEBUG_LOG("[IMAP] >>> %s", cmd); + EM_DEBUG_LOG("[IMAP] >>> %s", cmd); #endif if (!net_sout(imaplocal->netstream, cmd, (int)EM_SAFE_STRLEN(cmd))) { EM_DEBUG_EXCEPTION("net_sout failed..."); - + err = EMAIL_ERROR_CONNECTION_BROKEN; goto FINISH_OFF; } - + /* get uid from replied data */ while (imaplocal->netstream) { if (!(p = net_getline(imaplocal->netstream))) break; - + /* EM_DEBUG_LOG(" [IMAP] <<< %s", p); */ - + /* tagged line - end of command */ if (!strncmp(p, tag, EM_SAFE_STRLEN(tag))) break; - + /* check that reply is reply to our command */ /* format : "* 9 FETCH (UID 68)" */ if (!strstr(p, "FETCH (FLAGS")) { free(p); p = NULL; continue; } - + if (for_delete == EM_CORE_GET_UIDS_FOR_NO_DELETE) { if ((ref_account->retrieval_mode == EMAIL_IMAP4_RETRIEVAL_MODE_NEW) && (strstr(p, "\\Seen"))) { free(p); p = NULL; continue; } } - + uid_elem = (emcore_uid_list *)malloc(sizeof(emcore_uid_list)); if (!uid_elem) { EM_DEBUG_EXCEPTION("malloc failed..."); - + err = EMAIL_ERROR_OUT_OF_MEMORY; goto FINISH_OFF; } - + memset(uid_elem, 0x00, sizeof(emcore_uid_list)); /* parse uid, sequence, flags from replied data */ - + /* parse uid from replied data */ s = p+2; t = strchr(s, ' '); - + if (!t) { - err = EMAIL_ERROR_INVALID_RESPONSE; + err = EMAIL_ERROR_INVALID_RESPONSE; goto FINISH_OFF; } - + *t = '\0'; - + /* save sequence */ uid_elem->msgno = atoi(s); - - if (strstr(++t, "\\Deleted")) + + if (strstr(++t, "\\Deleted")) uid_elem->flag.deleted = 1; - + /* parse uid */ s = strstr(++t, "UID "); if (s) { s += strlen("UID "); t = strchr(s, ')'); - + if (!t) { - err = EMAIL_ERROR_INVALID_RESPONSE; + err = EMAIL_ERROR_INVALID_RESPONSE; goto FINISH_OFF; } - + *t = '\0'; } - else { - err = EMAIL_ERROR_INVALID_RESPONSE; + else { + err = EMAIL_ERROR_INVALID_RESPONSE; goto FINISH_OFF; } - + /* save uid */ uid_elem->uid = EM_SAFE_STRDUP(s); - + /* check downloaded_uids */ if (downloaded_uids) { int i; @@ -2129,46 +2129,46 @@ int emcore_download_uid_all(email_internal_mailbox_t *mailbox, emcore_uid_list** } } } - + if (uid_elem) { if (*uid_list) { fetch_data_p = *uid_list; - + while (fetch_data_p->next) fetch_data_p = fetch_data_p->next; - + fetch_data_p->next = uid_elem; } else { *uid_list = uid_elem; } - + if (total) ++(*total); } - + free(p); p = NULL; } } ret = true; -FINISH_OFF: - if (uid_elem && ret == false) +FINISH_OFF: + if (uid_elem && ret == false) free(uid_elem); - + if (p) free(p); - + if (mailbox && !mailbox->mail_stream) { emcore_close_mailbox(0, stream); stream = NULL; } - + if (err_code) *err_code = err; - EM_DEBUG_FUNC_END("ret [%d]", ret); + EM_DEBUG_FUNC_END("ret [%d]", ret); return ret; } @@ -2187,14 +2187,14 @@ int emcore_download_imap_msgno(email_internal_mailbox_t *mailbox, char *uid, int if (!mailbox || !uid) { EM_DEBUG_EXCEPTION("mailbox[%p], uid[%p], msgno[%p]", mailbox, uid, msgno); - + err = EMAIL_ERROR_INVALID_PARAM; goto FINISH_OFF; } if (!(ref_account = emcore_get_account_reference(mailbox->account_id))) { EM_DEBUG_EXCEPTION("emcore_get_account_reference failed [%d]", mailbox->account_id); - + err = EMAIL_ERROR_INVALID_ACCOUNT; goto FINISH_OFF; } @@ -2207,12 +2207,12 @@ int emcore_download_imap_msgno(email_internal_mailbox_t *mailbox, char *uid, int if (!mailbox->mail_stream) { if (!emcore_connect_to_remote_mailbox(mailbox->account_id, mailbox->mailbox_id, (void **)&tmp_stream, &err)) { EM_DEBUG_EXCEPTION("emcore_connect_to_remote_mailbox failed - %d", err); - + goto FINISH_OFF; } - + stream = (MAILSTREAM *)tmp_stream; - } + } else stream = mailbox->mail_stream; @@ -2230,7 +2230,7 @@ int emcore_download_imap_msgno(email_internal_mailbox_t *mailbox, char *uid, int 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; } @@ -2239,90 +2239,90 @@ int emcore_download_imap_msgno(email_internal_mailbox_t *mailbox, char *uid, int while (imaplocal->netstream) { if (!(p = net_getline(imaplocal->netstream))) break; - + /* tagged line - end of command */ if (!strncmp(p, tag, EM_SAFE_STRLEN(tag))) break; - + /* check that reply is reply to our command */ /* format : "* SEARCH 68", if not found, "* SEARCH" */ if (!strstr(p, "SEARCH ") || (p[9] < '0' || p[9] > '9')) { free(p); p = NULL; continue; } - + if (msgno) *msgno = atoi(p+9); - + free(p); p = NULL; - + ret = true; } - + if (ret != true) err = EMAIL_ERROR_MAIL_NOT_FOUND; - -FINISH_OFF: + +FINISH_OFF: if (p) free(p); - + if (mailbox && !mailbox->mail_stream){ - emcore_close_mailbox(0, stream); + emcore_close_mailbox(0, stream); stream = NULL; } - + if (err_code) *err_code = err; - - EM_DEBUG_FUNC_END("ret [%d]", ret); + + EM_DEBUG_FUNC_END("ret [%d]", ret); return ret; } int emcore_get_msgno(emcore_uid_list *uid_list, char *uid, int *msgno, int *err_code) { EM_DEBUG_FUNC_BEGIN("uid_list[%p], uid[%s], msgno[%p], err_code[%p]", uid_list, uid, msgno, err_code); - + int ret = false; int err = EMAIL_ERROR_MAIL_NOT_FOUND; /* EMAIL_ERROR_NONE; */ - + if (!uid || !msgno || !uid_list) { EM_DEBUG_EXCEPTION("uid_list[%p], uid[%p], msgno[%p]", uid_list, uid, msgno); - + err = EMAIL_ERROR_INVALID_PARAM; goto FINISH_OFF; } - + EM_DEBUG_LOG(" >> uid[%s]", uid); - + while (uid_list) { if (!strcmp(uid_list->uid, uid)) { *msgno = uid_list->msgno; - + EM_DEBUG_LOG("*msgno[%d]", *msgno); - + err = EMAIL_ERROR_NONE; - + ret = true; break; } - + uid_list = uid_list->next; } - -FINISH_OFF: + +FINISH_OFF: if (err_code != NULL) *err_code = err; - - EM_DEBUG_FUNC_END("ret [%d]", ret); + + EM_DEBUG_FUNC_END("ret [%d]", ret); return ret; } int emcore_get_uid(emcore_uid_list *uid_list, int msgno, char **uid, int *err_code) { EM_DEBUG_FUNC_BEGIN(); - + int ret = false, err = EMAIL_ERROR_NONE; - + if (!uid || msgno <= 0 || !uid_list){ err = EMAIL_ERROR_INVALID_PARAM; goto FINISH_OFF; @@ -2336,34 +2336,34 @@ int emcore_get_uid(emcore_uid_list *uid_list, int msgno, char **uid, int *err_co err = EMAIL_ERROR_OUT_OF_MEMORY; goto FINISH_OFF; } - + ret = true; break; } } - + uid_list = uid_list->next; } - + if (ret != true) err = EMAIL_ERROR_MAIL_NOT_FOUND; -FINISH_OFF: +FINISH_OFF: if (err_code) *err_code = err; - - EM_DEBUG_FUNC_END("ret [%d]", ret); + + EM_DEBUG_FUNC_END("ret [%d]", ret); return ret; } int emcore_free_uids(emcore_uid_list *uid_list, int *err_code) { EM_DEBUG_FUNC_BEGIN("uid_list[%p], err_code[%p]", uid_list, err_code); - + int ret = false; int err = EMAIL_ERROR_NONE; emcore_uid_list *p = NULL; - + if (!uid_list) { EM_DEBUG_EXCEPTION(" uid_list[%p]\n", uid_list); err = EMAIL_ERROR_INVALID_PARAM; @@ -2377,14 +2377,14 @@ int emcore_free_uids(emcore_uid_list *uid_list, int *err_code) free(p); p = NULL; } - + ret = true; -FINISH_OFF: +FINISH_OFF: if (err_code) *err_code = err; - EM_DEBUG_FUNC_END("ret [%d]", ret); + EM_DEBUG_FUNC_END("ret [%d]", ret); return ret; } @@ -2466,7 +2466,7 @@ INTERNAL_FUNC int emcore_sync_mail_from_client_to_server(int mail_id) if (!emcore_make_rfc822_file_from_mail(mail_table_data, attachment_tbl_data, attachment_tbl_count, &envelope, &fname, NULL, &err)){ EM_DEBUG_EXCEPTION(" emcore_make_rfc822_file_from_mail failed [%d]", err); - goto FINISH_OFF; + goto FINISH_OFF; } if (fname){ @@ -2541,7 +2541,7 @@ INTERNAL_FUNC int emcore_sync_mail_from_client_to_server(int mail_id) } -FINISH_OFF: +FINISH_OFF: #ifdef __FEATURE_LOCAL_ACTIVITY__ if (ret){ @@ -2558,7 +2558,7 @@ FINISH_OFF: EM_DEBUG_EXCEPTION(">>>>>>Local Activity [ACTIVITY_SAVEMAIL] [%d] ", err); } } -#endif /* __FEATURE_LOCAL_ACTIVITY__ */ +#endif /* __FEATURE_LOCAL_ACTIVITY__ */ EM_SAFE_FREE(data); EM_SAFE_FREE(long_enc_path); @@ -2584,8 +2584,8 @@ FINISH_OFF: } if (stream){ - emcore_close_mailbox(0, stream); - stream = NULL; + emcore_close_mailbox(0, stream); + stream = NULL; } EM_DEBUG_FUNC_END("err [%d]", err); @@ -2627,7 +2627,7 @@ static int emcore_initiate_pbd(MAILSTREAM *stream, int account_id, int mail_id, EM_DEBUG_EXCEPTION("emstorage_get_mailbox_by_id failed [%d]", err); goto FINISH_OFF; } - + pbd_event.mailbox_id = input_maibox_id; pbd_event.mail_id = mail_id; pbd_event.server_mail_id = strtoul(uid, NULL, 0); @@ -2636,7 +2636,7 @@ static int emcore_initiate_pbd(MAILSTREAM *stream, int account_id, int mail_id, EM_DEBUG_LOG("input_mailbox_name name [%d]", pbd_event.mailbox_id); EM_DEBUG_LOG("uid [%s]", uid); EM_DEBUG_LOG("pbd_event.account_id[%d], pbd_event.mail_id[%d], pbd_event.server_mail_id [%d]", pbd_event.account_id, pbd_event.mail_id , pbd_event.server_mail_id); - + if (!emcore_insert_pbd_activity(&pbd_event, &pbd_event.activity_id, &err)){ EM_DEBUG_EXCEPTION("Inserting Partial Body Download activity failed with error[%d]", err); goto FINISH_OFF; @@ -2644,12 +2644,12 @@ static int emcore_initiate_pbd(MAILSTREAM *stream, int account_id, int mail_id, else{ if (false == emcore_is_partial_body_thd_que_full()){ /* h.gahaut : Before inserting the event into event queue activity_type should be made 0 - Because partial body thread differentiates events coming from DB and event queue + Because partial body thread differentiates events coming from DB and event queue on the basis of activity_type and event_type fields */ pbd_event.activity_type = 0; pbd_event.event_type = EMAIL_EVENT_BULK_PARTIAL_BODY_DOWNLOAD; - + if (!emcore_insert_partial_body_thread_event(&pbd_event, &err)){ EM_DEBUG_EXCEPTION("Inserting Partial body thread event failed with error[%d]", err); goto FINISH_OFF; @@ -2665,8 +2665,8 @@ static int emcore_initiate_pbd(MAILSTREAM *stream, int account_id, int mail_id, } ret = true; - - FINISH_OFF: + + FINISH_OFF: if (mailbox) { emstorage_free_mailbox(&mailbox, 1, &err); @@ -2675,20 +2675,20 @@ static int emcore_initiate_pbd(MAILSTREAM *stream, int account_id, int mail_id, if (NULL != err_code) *err_code = err; - EM_DEBUG_FUNC_END("ret [%d]", ret); + EM_DEBUG_FUNC_END("ret [%d]", ret); return ret; } static int emcore_parse_bodystructure(void *stream, IMAPPARSEDREPLY *reply_from_server, char *bodystructure, BODY **body, struct _m_content_info **cnt_info, int *total_mail_size, unsigned long *uid_no) { EM_DEBUG_FUNC_BEGIN("stream:[%p], reply_from_server:[%p], bodystructure:[%p]", stream, reply_from_server, bodystructure); - + int err = EMAIL_ERROR_NONE; if (!stream || !reply_from_server || !bodystructure) { EM_DEBUG_EXCEPTION("Invalid paramter"); err = EMAIL_ERROR_INVALID_PARAM; - return err; + return err; } int p_total_mail_size = 0; @@ -2712,7 +2712,7 @@ static int emcore_parse_bodystructure(void *stream, IMAPPARSEDREPLY *reply_from_ /* Get the UID */ bodystructure_uid_start = strcasestr(bodystructure, "UID ") + strlen("UID "); - + uid_string = em_malloc((bodystructure_start - bodystructure_uid_start) + 1); if (uid_string == NULL) { EM_DEBUG_EXCEPTION("em_malloc failed"); @@ -2732,7 +2732,7 @@ static int emcore_parse_bodystructure(void *stream, IMAPPARSEDREPLY *reply_from_ err = EMAIL_ERROR_OUT_OF_MEMORY; goto FINISH_OFF; } - + imap_parse_body_structure(stream, p_body, (unsigned char **)&bodystructure_string, reply_from_server); /* Get the total mail size */ @@ -2764,17 +2764,17 @@ FINISH_OFF: emcore_free_content_info(p_cnt_info); if (body) - mail_free_body(&p_body); + mail_free_body(&p_body); } else { if (cnt_info) *cnt_info = p_cnt_info; if (body) *body = p_body; - + if (total_mail_size) *total_mail_size = p_total_mail_size; - + if (uid_no) *uid_no = p_uid_no; } @@ -2792,7 +2792,7 @@ static int emcore_update_attachment_except_inline(struct _m_content_info *cnt_in EM_DEBUG_EXCEPTION("Invalid parameter"); err = EMAIL_ERROR_INVALID_PARAM; return err; - + } if (!cnt_info->file || !cnt_info->file->name) { @@ -2815,7 +2815,7 @@ static int emcore_update_attachment_except_inline(struct _m_content_info *cnt_in if (attach_info->type == INLINE_ATTACHMENT) { EM_DEBUG_LOG("INLINE ATTACHMENT"); inline_attachment_count++; - continue; + continue; } total_attach_size += attach_info->size; @@ -2828,7 +2828,7 @@ static int emcore_update_attachment_except_inline(struct _m_content_info *cnt_in attachment_tbl.encoding = attach_info->encoding; attachment_tbl.section = attach_info->section; #endif - + EM_DEBUG_LOG("attachment_count [%d]", attachment_count); if (!emstorage_add_attachment(&attachment_tbl, 0, false, &err)) { @@ -2874,9 +2874,9 @@ static int emcore_parse_html_part_for_partial_body(char *start_header, char *bou do{ pHeaderStart--; } while (*pHeaderStart != LF && bufsendforparse < pHeaderStart); - + pHeaderStart++; - + memcpy(EncodingHeader, pHeaderStart, 25); if (strcasecmp(EncodingHeader, "Content-Transfer-Encoding") == 0){ @@ -2886,7 +2886,7 @@ static int emcore_parse_html_part_for_partial_body(char *start_header, char *bou } /* HTML Content found */ - + if(!start_header) { /*prevent 27448*/ EM_DEBUG_EXCEPTION("start_header NULL"); return false; @@ -2904,16 +2904,16 @@ static int emcore_parse_html_part_for_partial_body(char *start_header, char *bou multipart_related_boundry = pHeaderStart; else multipart_related_boundry = start_header; - + multipart_related_boundry = multipart_related_boundry - 3; multipart_related_boundry_end = multipart_related_boundry; - + while (bufsendforparse < multipart_related_boundry && *multipart_related_boundry != LF && *multipart_related_boundry != NULL_CHAR) multipart_related_boundry -= 1; - + multipart_related_boundry += 1; memcpy(multipart_boundary, multipart_related_boundry, multipart_related_boundry_end - multipart_related_boundry); - + EM_DEBUG_LOG("multipart_boundary [%s], boundary_string [%s]", multipart_boundary, boundary_string); if (strcmp(multipart_boundary, boundary_string) == 0) @@ -2927,18 +2927,18 @@ 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"); return false; - } + } else { if ((*(end-2) == CR) && (*(end-1) == LF)) end -= 2; - else if ((*(end-2) == CR) && (*(end-1) == LF) + else if ((*(end-2) == CR) && (*(end-1) == LF) && (*(end-4) == CR) && (*(end-3) == LF)) end -= 4; else @@ -2955,12 +2955,12 @@ static int emcore_parse_html_part_for_partial_body(char *start_header, char *bou enc_type = ENCBASE64; else if (strncasecmp(Encoding, "quoted-printable", strlen("quoted-printable")) == 0) enc_type = ENCQUOTEDPRINTABLE; - + EM_DEBUG_LOG("enc_type [%d]", enc_type); memcpy(text_html, start, end - txt_html); - - if (emcore_decode_body_text(text_html, end - txt_html, enc_type , &dec_len, &err) < 0) + + if (emcore_decode_body_text(text_html, end - txt_html, enc_type , &dec_len, &err) < 0) EM_DEBUG_EXCEPTION("emcore_decode_body_text failed [%d]", err); } else if ((temp_enc1 = (char *)strcasestr(start_header, "Content-transfer-encoding:")) && (temp_enc1 < end)){ /*prevent 27448*/ @@ -2980,14 +2980,14 @@ static int emcore_parse_html_part_for_partial_body(char *start_header, char *bou enc_type = ENCQUOTEDPRINTABLE; EM_DEBUG_LOG("enc_type [%d]", enc_type); - + memcpy(text_html, start, end - txt_html); - - if (emcore_decode_body_text(text_html, end - txt_html, enc_type , &dec_len, &err) < 0) + + 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); EM_DEBUG_LOG("start - %s", start); } @@ -3030,8 +3030,8 @@ static int emcore_parse_plain_part_for_partial_body(char *header_start_string, c EM_DEBUG_LOG("Content-Type : text/plain"); - pHeaderStart = header_start_string; - temp_text_boundary = start_header; + pHeaderStart = header_start_string; + temp_text_boundary = start_header; memcpy(EncodingHeader, pHeaderStart, 25); @@ -3040,7 +3040,7 @@ static int emcore_parse_plain_part_for_partial_body(char *header_start_string, c memcpy(Encoding, pHeaderStart + 27, pEncodingHeaderEnd - (pHeaderStart + 27)); iEncodingHeader = 1; } - + /* Plain text content found */ if(!start_header) { /*prevent 27450*/ EM_DEBUG_EXCEPTION("start_header NULL"); @@ -3051,26 +3051,26 @@ static int emcore_parse_plain_part_for_partial_body(char *header_start_string, c if (txt_plain != NULL){ txt_plain += EM_SAFE_STRLEN(CRLF_STRING CRLF_STRING); /* txt_plain points at plain text content */ - + /* Fix is done for mail having "Content-Type: text/plain" but there is no content but having only attachment. */ - + strcmpret = strncmp(txt_plain, boundary_string, EM_SAFE_STRLEN(boundary_string)); if (strcmpret == 0){ } else{ start = txt_plain; end = strstr(txt_plain, boundary_string); - + if (end == NULL){ EM_DEBUG_LOG("Text body contents exceeds limited Bytes"); end = txt_plain + body_size - (txt_plain - bufsendforparse); } else{ /* EM_DEBUG_LOG("pbd_event[temp_count].partial_body_complete - %d", partial_body_complete); */ - + if ((*(end-2) == CR) && (*(end-1) == LF)) end -= 2; - else if ((*(end-2) == CR) && (*(end-1) == LF) + else if ((*(end-2) == CR) && (*(end-1) == LF) && (*(end-4) == CR) && (*(end-3) == LF)) end -= 4; else @@ -3083,12 +3083,12 @@ static int emcore_parse_plain_part_for_partial_body(char *header_start_string, c enc_type = ENCBASE64; else if (strncasecmp(Encoding, "quoted-printable", strlen("quoted-printable")) == 0) enc_type = ENCQUOTEDPRINTABLE; - + EM_DEBUG_LOG("enc_type [%d]", enc_type); memcpy(text_plain, start, end - txt_plain); - - if (emcore_decode_body_text(text_plain, end - txt_plain, enc_type , &dec_len, &err) < 0) + + if (emcore_decode_body_text(text_plain, end - txt_plain, enc_type , &dec_len, &err) < 0) EM_DEBUG_EXCEPTION("emcore_decode_body_text failed [%d]", err); } else if (start_header && ((temp_enc1 = (char *)strcasestr(start_header, "Content-transfer-encoding:")) != NULL) && !(temp_enc1 && temp_enc1 >= end)){ @@ -3106,13 +3106,13 @@ static int emcore_parse_plain_part_for_partial_body(char *header_start_string, c enc_type = ENCBASE64; else if (strncasecmp(start_header, "quoted-printable", strlen("quoted-printable")) == 0) enc_type = ENCQUOTEDPRINTABLE; - + EM_DEBUG_LOG("enc_type [%d]", enc_type); memcpy(text_plain, start, end - txt_plain); - if (emcore_decode_body_text(text_plain, end - txt_plain, enc_type , &dec_len, &err) < 0) + if (emcore_decode_body_text(text_plain, end - txt_plain, enc_type , &dec_len, &err) < 0) EM_DEBUG_EXCEPTION("emcore_decode_body_text failed [%d]", err); } - + EM_DEBUG_LOG("Decoded length = %d", dec_len); /* EM_DEBUG_LOG("start - %s", start); */ /* print raw MIME content. */ } @@ -3133,7 +3133,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@org.tizen.slp.email> */ +/* Content-ID: <4b0d6810b17291f9438783a8eb9d5228@com.samsung.slp.email> */ /* Content-Disposition: inline; filename = Default.png */ static void emcore_free_email_image_data(email_image_data **image_data, int count) @@ -3188,17 +3188,17 @@ static int emcore_parse_image_part_for_partial_body(char *header_start_string, c image_boundary = start_header; image_boundary_end = image_boundary - 2; image_boundary = image_boundary - 2; - + EM_DEBUG_LOG("Content-type: image"); - + while (*image_boundary != LF) image_boundary--; - + image_boundary++; - + if (image_boundary != NULL && image_boundary_end != NULL) memcpy(temp_image_boundary, image_boundary, image_boundary_end-image_boundary); - + if ((char *)strcasestr((const char *)temp_image_boundary, "Content-type:") == NULL) boundary_string = temp_image_boundary; do { @@ -3237,16 +3237,16 @@ static int emcore_parse_image_part_for_partial_body(char *header_start_string, c temp_image = temp_name; if (*(temp_image+5) == '"') temp_image = temp_image+5; - + while (*temp_image != CR){ temp_image++; memcpy(image_data[i].image_file_name+ch_image, temp_image, 1); ch_image++; } - + if ((*(temp_name+4) == '=') && (*(temp_name+5) == '\"')) image_data[i].image_file_name[ch_image-2] = '\0'; - + if ((*(temp_name+4) == '=') && (*(temp_name+5) != '\"')) image_data[i].image_file_name[ch_image-1] = '\0'; @@ -3256,17 +3256,17 @@ static int emcore_parse_image_part_for_partial_body(char *header_start_string, c memcpy(image_data[i].image_file_name, decoded_filename, EM_SAFE_STRLEN(decoded_filename)); EM_SAFE_FREE(decoded_filename); } - } - + } + if (((temp_cid1 = (char *)strcasestr((const char *)start_header, "Content-ID: <")) != NULL)){ if (temp_cid1){ cid = temp_cid1; temp_image = temp_cid1; } - + cid += 13; cid_end = strstr(temp_image, "\076"); /* 076 == '>' */ - + image_data[i].content_id = (char *)em_malloc(cid_end-cid+5); if (image_data[i].content_id != NULL){ strcpy(image_data[i].content_id, "cid:"); @@ -3274,7 +3274,7 @@ static int emcore_parse_image_part_for_partial_body(char *header_start_string, c } else EM_DEBUG_EXCEPTION("em_malloc() failed"); - + if (image_data[i].image_file_name[0] == '\0') memcpy(image_data[i].image_file_name, cid, cid_end - cid); } @@ -3296,14 +3296,14 @@ static int emcore_parse_image_part_for_partial_body(char *header_start_string, c boundarylen = EM_SAFE_STRLEN(boundary_string); end -= 2; } - + if ((temp_enc1 = (char *)strcasestr((const char *)start_header, "Content-transfer-encoding:")) != NULL){ /*prevent 27449*/ if (temp_enc1) start_header = temp_enc1; start_header += strlen("Content-Transfer-Encoding:"); start_header = em_skip_whitespace_without_strdup(start_header); - + if (!start_header) EM_DEBUG_EXCEPTION(" Invalid parsing "); else{ @@ -3314,11 +3314,11 @@ static int emcore_parse_image_part_for_partial_body(char *header_start_string, c enc_type = ENCQUOTEDPRINTABLE; EM_DEBUG_LOG("enc_type [%d]", enc_type); - + image_data[i].text_image = (char *)em_malloc((end-txt_image)+1); if (image_data[i].text_image){ memcpy(image_data[i].text_image, start, end-txt_image); - if (emcore_decode_body_text(image_data[i].text_image, end-txt_image, enc_type , &(image_data[i].dec_len), &err) < 0) + 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; @@ -3326,7 +3326,7 @@ static int emcore_parse_image_part_for_partial_body(char *header_start_string, c else EM_DEBUG_EXCEPTION("em_malloc() failed"); } - + EM_DEBUG_LOG("Decoded length [%d]", dec_len); } else{ @@ -3335,7 +3335,7 @@ static int emcore_parse_image_part_for_partial_body(char *header_start_string, c memcpy(image_data[i].text_image, start, end - txt_image); else EM_DEBUG_EXCEPTION("em_malloc() failed"); - } + } } else{ donot_parse_next_image = 1; @@ -3372,7 +3372,7 @@ static int emcore_find_boundary_string_of_the_part(const char *whole_string, con do{ boundary_cur--; } while (whole_string < boundary_cur && *boundary_cur != LF && *boundary_cur != NULL_CHAR); - + boundary_cur++; if(boundary_end > boundary_cur && boundary_cur > whole_string) { @@ -3396,7 +3396,7 @@ static int emcore_find_boundary_string_of_the_part(const char *whole_string, con else { EM_DEBUG_EXCEPTION("There is no string before the part"); err = EMAIL_ERROR_ON_PARSING; - goto FINISH_OFF; + goto FINISH_OFF; } ret = true; FINISH_OFF: @@ -3406,7 +3406,7 @@ FINISH_OFF: EM_DEBUG_FUNC_END("ret[%d], err[%d]", ret, err); return ret; -} +} static int emcore_parse_body_for_imap(char *body_str, int body_size, struct _m_content_info *cnt_info, int encoding_type, char **output_text_plain, char **output_text_html, email_image_data **output_image_data) { @@ -3454,7 +3454,7 @@ static int emcore_parse_body_for_imap(char *body_str, int body_size, struct _m_c 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) { @@ -3471,13 +3471,13 @@ static int emcore_parse_body_for_imap(char *body_str, int body_size, struct _m_c 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 */ no_alternative_part_flag = 0; if (((temp_alternative_plain_header = (char *)strcasestr(p_body_str, "Content-type: multipart/alternative")) != NULL)) { /* Found 'alternative' */ - if (((temp_content_type = (char *)strcasestr(p_body_str, "Content-type: text/plain")) != NULL)) { - if (temp_content_type < temp_alternative_plain_header) { + if (((temp_content_type = (char *)strcasestr(p_body_str, "Content-type: text/plain")) != NULL)) { + if (temp_content_type < temp_alternative_plain_header) { /* This part is text/plain not alternative. */ no_html = 1; no_alternative_part_flag = 1; @@ -3487,7 +3487,7 @@ static int emcore_parse_body_for_imap(char *body_str, int body_size, struct _m_c if(!boundary_start) goto FINISH_OFF; /*prevent 37946 */ boundary_end = strcasestr(boundary_start, "Content-type:"); if(!boundary_end) goto FINISH_OFF; /*prevent 37946 */ - + boundary_string = em_malloc(boundary_end - boundary_start); if (boundary_string == NULL) { EM_DEBUG_EXCEPTION("em_malloc failed"); @@ -3499,14 +3499,14 @@ static int emcore_parse_body_for_imap(char *body_str, int body_size, struct _m_c } } } else - no_alternative_part_flag = 1; + no_alternative_part_flag = 1; if (no_alternative_part_flag) { boundary_start = strstr(p_body_str, "--") + strlen("--"); if(!boundary_start) goto FINISH_OFF; /*prevent 37946 */ boundary_end = strcasestr(boundary_start, "Content-type:"); if(!boundary_end) goto FINISH_OFF; /*prevent 37946 */ - + boundary_string = em_malloc(boundary_end - boundary_start); if (boundary_string == NULL) { EM_DEBUG_EXCEPTION("em_malloc failed"); @@ -3518,7 +3518,7 @@ 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); + EM_DEBUG_LOG("boundary_string : [%s]", boundary_string); if (((start_header = (char *)strcasestr(boundary_end, "Content-Type: text/html")) != NULL) && (no_html != 1) &&(((char *)strcasestr(boundary_end, "Content-Type: message/rfc822")) == NULL) && (((char *)strcasestr(boundary_end, "Content-Type: text/rfc822-headers")) == NULL)) @@ -3533,14 +3533,14 @@ static int emcore_parse_body_for_imap(char *body_str, int body_size, struct _m_c if(!internal_boundary_string) internal_boundary_string = EM_SAFE_STRDUP(boundary_string); - + emcore_parse_plain_part_for_partial_body(boundary_end, start_header, internal_boundary_string, p_body_str, text_plain, body_size); EM_SAFE_FREE(internal_boundary_string); } if (((start_header = (char *)strcasestr((const char *)boundary_end, "Content-type: image/jpeg")) != (char *)NULL) || ((start_header = (char *)strcasestr((const char *)boundary_end, "Content-Type: image/jpg")) != (char *)NULL) || - ((start_header = (char *)strcasestr((const char *)boundary_end, "Content-Type: image/gif")) != (char *)NULL) || + ((start_header = (char *)strcasestr((const char *)boundary_end, "Content-Type: image/gif")) != (char *)NULL) || ((start_header = (char *)strcasestr((const char *)boundary_end, "Content-Type: image/bmp")) != (char *)NULL) || ((start_header = (char *)strcasestr((const char *)boundary_end, "Content-Type: image/png")) != (char *)NULL)) { image_data = em_malloc(sizeof(email_image_data) * IMAGE_DISPLAY_PARTIAL_BODY_COUNT); @@ -3581,7 +3581,7 @@ FINISH_OFF: static int emcore_download_bulk_partial_mail_body_for_imap(MAILSTREAM *stream, int input_download_size, email_event_partial_body_thd *pbd_event, int item_count, int *error) { EM_DEBUG_FUNC_BEGIN("stream [%p], input_download_size[%d], pbd_event [%p], item_count [%d], error [%p]", stream, input_download_size, pbd_event, item_count, error); - + int ret = false, err = EMAIL_ERROR_NONE; int j = 0, i = 0; int i32_index = 0; @@ -3591,7 +3591,7 @@ static int emcore_download_bulk_partial_mail_body_for_imap(MAILSTREAM *stream, i char buf[512] = {0, }; char *text_plain = NULL; char *text_html = NULL; - char uid_range_string_to_be_downloaded[UID_RANGE_STRING_LENGTH] = {0, }; + char uid_range_string_to_be_downloaded[UID_RANGE_STRING_LENGTH] = {0, }; char imap_tag[TAG_LENGTH] = {0, }; char command[COMMAND_LENGTH] = {0, }; char *temp_data_html = NULL; @@ -3608,29 +3608,29 @@ static int emcore_download_bulk_partial_mail_body_for_imap(MAILSTREAM *stream, i 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); + 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++) - { + { EM_DEBUG_LOG("pbd_event[%d].account_id [%d], mail_id [%d], server_mail_id [%d], activity_id [%d]", \ - j, stSectionNo[j].account_id, stSectionNo[j].mail_id, stSectionNo[j].server_mail_id, stSectionNo[j].activity_id); - + j, stSectionNo[j].account_id, stSectionNo[j].mail_id, stSectionNo[j].server_mail_id, stSectionNo[j].activity_id); + if (i32_index >= UID_RANGE_STRING_LENGTH){ EM_DEBUG_EXCEPTION("String length exceeded its limitation!"); goto FINISH_OFF; - } + } if (j == item_count - 1) i32_index += SNPRINTF(uid_range_string_to_be_downloaded + i32_index, UID_RANGE_STRING_LENGTH, "%lu", stSectionNo[j].server_mail_id); else i32_index += SNPRINTF(uid_range_string_to_be_downloaded + i32_index, UID_RANGE_STRING_LENGTH, "%lu,", stSectionNo[j].server_mail_id); - } + } SNPRINTF(imap_tag, TAG_LENGTH, "%08lx", 0xffffffff & (stream->gensym++)); SNPRINTF(command, COMMAND_LENGTH, "%s UID FETCH %s (BODYSTRUCTURE BODY.PEEK[TEXT]<0.%d>)\015\012", imap_tag, uid_range_string_to_be_downloaded, input_download_size); @@ -3640,7 +3640,7 @@ static int emcore_download_bulk_partial_mail_body_for_imap(MAILSTREAM *stream, i /* 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; + err = EMAIL_ERROR_CONNECTION_BROKEN; goto FINISH_OFF; } @@ -3651,7 +3651,7 @@ static int emcore_download_bulk_partial_mail_body_for_imap(MAILSTREAM *stream, i 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; @@ -3666,7 +3666,7 @@ static int emcore_download_bulk_partial_mail_body_for_imap(MAILSTREAM *stream, i /* Search the account id of pbd_event */ for (temp_count = 0; temp_count <= item_count && pbd_event[temp_count].server_mail_id != uidno; temp_count++) continue; - + if (temp_count > item_count) { EM_DEBUG_EXCEPTION("Can't find proper server_mail_id"); goto FINISH_OFF; @@ -3685,7 +3685,7 @@ static int emcore_download_bulk_partial_mail_body_for_imap(MAILSTREAM *stream, i if (mail->body_download_status == EMAIL_BODY_DOWNLOAD_STATUS_FULLY_DOWNLOADED) { EM_DEBUG_LOG("Downloaded mail"); - continue; + continue; } /* Update the attachment info except inline attachment */ @@ -3709,17 +3709,17 @@ static int emcore_download_bulk_partial_mail_body_for_imap(MAILSTREAM *stream, i } 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, 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, cnt_info->text.plain_charset ? cnt_info->text.plain_charset : "UTF-8", buf, &err)) EM_DEBUG_EXCEPTION("emstorage_get_save_name failed [%d]", err); if (!emstorage_create_file(text_plain, EM_SAFE_STRLEN(text_plain), buf, &err)) EM_DEBUG_EXCEPTION("emstorage_create_file failed [%d]", err); - mail->file_path_plain = EM_SAFE_STRDUP(buf); + mail->file_path_plain = EM_SAFE_STRDUP(buf); EM_DEBUG_LOG("mail->file_path_plain [%s]", mail->file_path_plain); if (image_data != NULL && image_data[0].text_image != NULL && image_data[0].text_image[0] != NULL_CHAR) { @@ -3743,12 +3743,12 @@ 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, &err)) EM_DEBUG_EXCEPTION("emstorage_get_save_name failed [%d]", err); if (!emstorage_create_file(image_data[store_file].text_image, image_data[store_file].dec_len, buf, &err)) EM_DEBUG_EXCEPTION("emstorage_create_file failed [%d]", err); - + if (mail->body_download_status != EMAIL_BODY_DOWNLOAD_STATUS_PARTIALLY_DOWNLOADED){ memset(&attachment_tbl, 0x00, sizeof(emstorage_attachment_tbl_t)); attachment_tbl.mail_id = mail->mail_id; @@ -3763,25 +3763,25 @@ static int emcore_download_bulk_partial_mail_body_for_imap(MAILSTREAM *stream, i mail->attachment_count++; mail->inline_content_count++; if (!emstorage_add_attachment (&attachment_tbl, false, false, &err)) - EM_DEBUG_EXCEPTION("emstorage_add_attachment failed - %d", err); + EM_DEBUG_EXCEPTION("emstorage_add_attachment failed - %d", err); } - + store_file++; } while (image_data[store_file].text_image != NULL && image_data[store_file].text_image[0] != NULL_CHAR && (store_file < IMAGE_DISPLAY_PARTIAL_BODY_COUNT)); - + while (image_data[content_index].text_image != NULL && image_data[content_index].text_image[0] != NULL_CHAR && image_data[content_index].content_id && image_data[content_index].content_id[0] != NULL_CHAR && (content_index < IMAGE_DISPLAY_PARTIAL_BODY_COUNT)){ /* Finding CID in HTML and replacing with image name. */ result_string_of_replcaing = em_replace_string((char *)temp_data_html, (char *)image_data[content_index].content_id, (char *)image_data[content_index].image_file_name); - + EM_SAFE_STRNCPY(temp_data_html, result_string_of_replcaing, EM_SAFE_STRLEN(result_string_of_replcaing)); EM_SAFE_FREE(result_string_of_replcaing); if (strstr(temp_data_html, image_data[content_index].content_id) != NULL) continue; /* Replace content id on HTML with same file name one more time. */ - + content_index++; } - + memset(text_html, 0, imap_response[i].body_len + 1); if (temp_data_html != NULL) @@ -3789,7 +3789,7 @@ static int emcore_download_bulk_partial_mail_body_for_imap(MAILSTREAM *stream, i EM_SAFE_FREE(temp_data_html); } - + if (EM_SAFE_STRLEN(text_html) > 0) { memset(buf, 0x00, sizeof(buf)); char html_body[MAX_CHARSET_VALUE] = {0x00, }; @@ -3807,29 +3807,29 @@ 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, &err)) EM_DEBUG_EXCEPTION("emstorage_get_save_name failed [%d]", err); if (!emstorage_create_file(text_html, EM_SAFE_STRLEN(text_html), buf, &err)) EM_DEBUG_EXCEPTION("emstorage_create_file failed [%d]", err); - mail->file_path_html = EM_SAFE_STRDUP(buf); + mail->file_path_html = EM_SAFE_STRDUP(buf); /* free the plain, html, image data */ EM_SAFE_FREE(text_plain); EM_SAFE_FREE(text_html); if (image_data) emcore_free_email_image_data(&image_data, IMAGE_DISPLAY_PARTIAL_BODY_COUNT); - + } mail->body_download_status = (total_mail_size - total_attachment_size < input_download_size) ? 1 : 2; - EM_DEBUG_LOG("mail->body_download_status [%d]", mail->body_download_status); + EM_DEBUG_LOG("mail->body_download_status [%d]", mail->body_download_status); - /* Get preview text */ + /* 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); @@ -3844,8 +3844,8 @@ static int emcore_download_bulk_partial_mail_body_for_imap(MAILSTREAM *stream, i } ret = true; - -FINISH_OFF: + +FINISH_OFF: if (error) *error = err; @@ -3877,9 +3877,9 @@ FINISH_OFF: emstorage_free_mail(&mail, 1, NULL); if (imap_response) - emcore_free_email_partial_buffer(&imap_response, item_count); + emcore_free_email_partial_buffer(&imap_response, item_count); - EM_DEBUG_FUNC_END("ret [%d]", ret); + EM_DEBUG_FUNC_END("ret [%d]", ret); return ret; } @@ -3887,36 +3887,36 @@ INTERNAL_FUNC int emcore_download_bulk_partial_mail_body_for_pop3(MAILSTREAM *st { EM_DEBUG_FUNC_BEGIN("stream [%p], pbd_event [%p], item_count [%d], error [%p]", stream, pbd_event, item_count, error); int ret = false, err = EMAIL_ERROR_NONE; - int i; + int i; if (!stream || !pbd_event) { EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM"); - err = EMAIL_ERROR_INVALID_PARAM; + err = EMAIL_ERROR_INVALID_PARAM; goto FINISH_OFF; } - - for (i = 0; i < item_count; i++) { + + for (i = 0; i < item_count; i++) { EM_DEBUG_LOG("pbd_event[%d].account_id [%d], mail_id [%d], server_mail_id [%d], activity_id [%d]", \ - i, pbd_event[i].account_id, pbd_event[i].mail_id, pbd_event[i].server_mail_id, pbd_event[i].activity_id); + 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)){ EM_DEBUG_EXCEPTION("emcore_download_body_multi_sections_bulk failed"); goto FINISH_OFF; } - + 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); goto FINISH_OFF; } - } + } ret = true; -FINISH_OFF: +FINISH_OFF: if (error) *error = err; - EM_DEBUG_FUNC_END("ret [%d] err [%d]", ret, err); + EM_DEBUG_FUNC_END("ret [%d] err [%d]", ret, err); return ret; } @@ -3931,7 +3931,7 @@ INTERNAL_FUNC int emcore_download_bulk_partial_mail_body(MAILSTREAM *stream, ema if (!stream || !pbd_event) { EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM"); - err = EMAIL_ERROR_INVALID_PARAM; + err = EMAIL_ERROR_INVALID_PARAM; goto FINISH_OFF; } @@ -3946,17 +3946,17 @@ INTERNAL_FUNC int emcore_download_bulk_partial_mail_body(MAILSTREAM *stream, ema case EMAIL_SERVER_TYPE_IMAP4: ret = emcore_download_bulk_partial_mail_body_for_imap(stream, auto_download_size, pbd_event, item_count, &err); break; - case EMAIL_SERVER_TYPE_POP3: + 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: + default: err = EMAIL_ERROR_NOT_SUPPORTED; ret = false; break; - } + } ret = true; -FINISH_OFF: +FINISH_OFF: if (error) *error = err; @@ -3982,7 +3982,7 @@ static void emcore_free_email_partial_buffer(email_partial_buffer **partial_buff EM_SAFE_FREE(p->header); EM_SAFE_FREE(p->body); } - + EM_SAFE_FREE(*partial_buffer); EM_DEBUG_FUNC_END(); } @@ -4023,11 +4023,11 @@ static email_partial_buffer *emcore_get_response_from_server (NETSTREAM *nstream if (strcasestr(pline, "BODYSTRUCTURE") != NULL) { header_len = EM_SAFE_STRLEN(pline); header_start = true; - } + } - /* Search the end of header */ + /* Search the end of header */ if ((p = strcasestr(pline, "BODY[TEXT]")) != NULL && header_len > 0) { - /* Get the header content */ + /* Get the header content */ retPartialBuffer[count].header_len = (p - pline) + EM_SAFE_STRLEN(pre_content); retPartialBuffer[count].header = em_malloc(retPartialBuffer[count].header_len + 1); if (retPartialBuffer[count].header == NULL) { @@ -4043,7 +4043,7 @@ static email_partial_buffer *emcore_get_response_from_server (NETSTREAM *nstream /* Get the body content */ p += strlen("BODY[TEXT]<0> {"); body_size = atoi(p); - retPartialBuffer[count].body_len = (body_size > input_download_size) ? input_download_size : body_size ; + retPartialBuffer[count].body_len = (body_size > input_download_size) ? input_download_size : body_size ; retPartialBuffer[count].body = em_malloc(retPartialBuffer[count].body_len + 1); if (retPartialBuffer[count].body == NULL) { EM_DEBUG_EXCEPTION("em_malloc failed"); @@ -4057,7 +4057,7 @@ static email_partial_buffer *emcore_get_response_from_server (NETSTREAM *nstream count++; header_start = false; - } + } if (header_start) pre_content = EM_SAFE_STRDUP(pline); @@ -4072,27 +4072,27 @@ static email_partial_buffer *emcore_get_response_from_server (NETSTREAM *nstream if(reply) *reply = ret_reply; - + if (0 == strncmp(pline + EM_SAFE_STRLEN(tag) + 1, "OK", 2)) { ret_reply->line = (unsigned char*)EM_SAFE_STRDUP(tag); ret_reply->tag = (unsigned char*)EM_SAFE_STRDUP(tag); ret_reply->key = (unsigned char*)strdup("OK"); ret_reply->text = (unsigned char*)strdup("Success"); - EM_SAFE_FREE(pline); + EM_SAFE_FREE(pline); break; } else { - EM_DEBUG_EXCEPTION("Tagged Response not OK. IMAP4 Response -> [%s]", pline); + EM_DEBUG_EXCEPTION("Tagged Response not OK. IMAP4 Response -> [%s]", pline); ret_reply->line = (unsigned char*)EM_SAFE_STRDUP(tag); ret_reply->tag = (unsigned char*)EM_SAFE_STRDUP(tag); ret_reply->key = (unsigned char*)strdup("NO"); ret_reply->text = (unsigned char*)strdup("Fail"); goto FINISH_OFF; - - } - } - EM_SAFE_FREE(pline); + + } + } + EM_SAFE_FREE(pline); } ret = true; @@ -4103,12 +4103,12 @@ FINISH_OFF: EM_SAFE_FREE(pre_content); if (!ret) { - emcore_free_email_partial_buffer(&retPartialBuffer, item_count); + emcore_free_email_partial_buffer(&retPartialBuffer, item_count); } - - EM_DEBUG_FUNC_END("retPartialBuffer [%p]", retPartialBuffer); + + EM_DEBUG_FUNC_END("retPartialBuffer [%p]", retPartialBuffer); return retPartialBuffer; } - + #endif /* __FEATURE_PARTIAL_BODY_DOWNLOAD__ */ /* EOF */ diff --git a/email-core/email-core-mailbox.c b/email-core/email-core-mailbox.c index b8204af..30207f2 100755 --- a/email-core/email-core-mailbox.c +++ b/email-core/email-core-mailbox.c @@ -1,7 +1,7 @@ /* * email-service * -* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> * @@ -380,7 +380,7 @@ INTERNAL_FUNC int emcore_create_mailbox(email_mailbox_t *new_mailbox, int on_ser local_mailbox.unread_count = 0; local_mailbox.total_mail_count_on_local = 0; local_mailbox.total_mail_count_on_server = 0; - emcore_get_default_mail_slot_count(&local_mailbox.mail_slot_size, NULL); + emcore_get_default_mail_slot_count(local_mailbox.account_id, &local_mailbox.mail_slot_size); if (strncmp(new_mailbox->mailbox_name, EMAIL_INBOX_NAME, EM_SAFE_STRLEN(EMAIL_INBOX_NAME)) == 0 || strncmp(new_mailbox->mailbox_name, EMAIL_DRAFTBOX_NAME, EM_SAFE_STRLEN(EMAIL_DRAFTBOX_NAME)) == 0 || diff --git a/email-core/email-core-mime.c b/email-core/email-core-mime.c index 15226a9..65c476f 100755 --- a/email-core/email-core-mime.c +++ b/email-core/email-core-mime.c @@ -1,10 +1,10 @@ /* * email-service * -* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* 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 @@ -106,19 +106,19 @@ (part 0) multipart/related - (part 1) multipart/alternative - (part 1.1) text/plain <- text message - (part 1.2) text/html <- html message + (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 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 2.2) image/png(related) <- inline image (part 1.2) image/png(attachment) <- image attachment */ @@ -185,13 +185,13 @@ struct _m_part_header { struct _parameter *disp_parameter; /* disposition parameter : "filename", .. */ char *content_id; /* content id : it is inline */ char *content_location; /* content location : "inline" location */ -}; +}; /* MIME Message Header */ struct _m_mesg_header { char *version; /* MIME Versio */ struct _m_part_header *part_header; /* MIME Part Heade */ -}; +}; /* MIME Multipart Body linked list */ typedef struct _m_body _m_body_t; @@ -274,34 +274,34 @@ void emcore_mime_free_rfc822_header(struct _rfc822header *rfc822header); void emcore_mime_free_part(struct _m_part *part); void emcore_mime_free_part_body(struct _m_body *body); void emcore_mime_free_mime(struct _m_mesg *mmsg); -char *emcore_mime_get_line_from_sock(void *stream, char *buf, int size, int *err_code); +char *emcore_mime_get_line_from_sock(void *stream, char *buf, int size, int *err_code); char *emcore_mime_get_save_file_name(int *err_code); /* get content data and save buffer or fil */ /* mode - 1 : get the only siz */ /* 2 : save content to buffer (holder is buffer */ /* 3 : save content to file (holder is file name */ -static int emcore_mime_get_content_data(void *stream, - int is_file, - int is_text, - char *boundary_str, - char *content_encoding, +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, - int mode, - char **holder, + int mode, + char **holder, int *size, - void *callback, + 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); /* skip content data to boundary_str or end of fil */ -int emcore_mime_skip_content_data(void *stream, - int is_file, - char *boundary_str, - int *end_of_parsing, - int *size, - void *callback, +int emcore_mime_skip_content_data(void *stream, + int is_file, + char *boundary_str, + int *end_of_parsing, + int *size, + void *callback, int *err_code); static int emcore_get_file_pointer(BODY *body, bool input_check_duplicated_file_name, char *buf, struct _m_content_info *cnt_info , int *err); @@ -339,7 +339,7 @@ char *em_split_file_path(char *str) if (temp_cid == NULL) { EM_DEBUG_EXCEPTION(">>>> File Path Doesnot contain end line for CID "); next_decode_string = true; - EM_SAFE_FREE(buf); + EM_SAFE_FREE(buf); return temp_str; } temp_cid_data = em_malloc((temp_cid-temp_str)+1); @@ -360,7 +360,7 @@ char *em_split_file_path(char *str) result++; EM_DEBUG_LOG("content_id is [ %s ]", content_id); - if (strcasestr(content_id, ".bmp") || strcasestr(content_id, ".jpeg") || strcasestr(content_id, ".png") || + if (strcasestr(content_id, ".bmp") || strcasestr(content_id, ".jpeg") || strcasestr(content_id, ".png") || strcasestr(content_id, ".jpg") || strcasestr(content_id, ".gif")) snprintf(buf+EM_SAFE_STRLEN(buf), buf_length - EM_SAFE_STRLEN(buf), "%s\"", content_id); else @@ -397,7 +397,7 @@ static char *em_replace_string_with_split_file_path(char *source_string, char *o EM_IF_NULL_RETURN_VALUE(source_string, NULL); EM_IF_NULL_RETURN_VALUE(old_string, NULL); EM_IF_NULL_RETURN_VALUE(new_string, NULL); - + EM_DEBUG_LOG("source_string [%s] ", source_string); EM_DEBUG_LOG("old_string [%s] ", old_string); EM_DEBUG_LOG("new_string [%s] ", new_string); @@ -439,14 +439,14 @@ static char *em_replace_string_with_split_file_path(char *source_string, char *o EM_SAFE_FREE(buffer); return NULL; } - -FINISH_OFF: + +FINISH_OFF: EM_SAFE_FREE(split_str); EM_SAFE_FREE(buffer); EM_DEBUG_FUNC_END("Failed"); return NULL; - + } @@ -471,7 +471,7 @@ int emcore_mime_flush_receiving_buffer(void *stream, int is_file, char *boundary return false; } - if ((is_file == 0 && !emcore_mime_get_line_from_sock(stream, buf, MIME_LINE_LEN, err_code)) || + 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"); local_end_of_parsing = 0; @@ -481,17 +481,17 @@ int emcore_mime_flush_receiving_buffer(void *stream, int is_file, char *boundary if (boundary_string && boundary_end_string) { if (!strcmp(buf, boundary_string)) { EM_DEBUG_LOG("found boundary"); - local_end_of_parsing = 0; - break; + local_end_of_parsing = 0; + break; } else if (!strcmp(buf, boundary_end_string)) { EM_DEBUG_LOG("found boundary_end"); - local_end_of_parsing = 1; - break; + local_end_of_parsing = 1; + break; } } } - + if (end_of_parsing) *end_of_parsing = local_end_of_parsing; @@ -502,7 +502,7 @@ int emcore_mime_flush_receiving_buffer(void *stream, int is_file, char *boundary int emcore_parse_mime(void *stream, int is_file, struct _m_content_info *cnt_info, int *err_code) { EM_DEBUG_FUNC_BEGIN("stream[%p], is_file[%d], cnt_info[%p], err_code[%p]", stream, is_file, cnt_info, err_code); - + struct _m_mesg *mmsg = em_malloc(sizeof(struct _m_mesg)); if (!mmsg) return false; @@ -513,7 +513,7 @@ int emcore_parse_mime(void *stream, int is_file, struct _m_content_info *cnt_inf 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); - return false; + return false; } if (!emcore_check_thread_status()) { @@ -522,7 +522,7 @@ int emcore_parse_mime(void *stream, int is_file, struct _m_content_info *cnt_inf 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) { @@ -530,10 +530,10 @@ int emcore_parse_mime(void *stream, int is_file, struct _m_content_info *cnt_inf EM_DEBUG_LOG("value[%s]", mmsg->header->part_header->parameter->value); EM_DEBUG_LOG("next : %p", mmsg->header->part_header->parameter->next); } - + if (!emcore_mime_parse_body(stream, is_file, mmsg, cnt_info, NULL, err_code)) { EM_SAFE_FREE(mmsg); - return false; + return false; } /* 3. free memory */ @@ -549,17 +549,17 @@ int emcore_parse_mime(void *stream, int is_file, struct _m_content_info *cnt_inf } int emcore_mime_parse_header(void *stream, int is_file, struct _rfc822header **rfc822header, struct _m_mesg_header **header, int *err_code) -{ +{ EM_DEBUG_FUNC_BEGIN("stream[%p], is_file[%d], rfc822header[%p], header[%p], err_code[%p]", stream, is_file, rfc822header, header, err_code); - + struct _m_mesg_header *tmp_header = NULL; struct _rfc822header *tmp_rfc822header = NULL; char buf[MIME_LINE_LEN] = {0, }; char *name = NULL; char *value = NULL; char *pTemp = NULL; - int is_longheader; - + int is_longheader; + if (!emcore_check_thread_status()) { if (err_code != NULL) *err_code = EMAIL_ERROR_CANCELLED; @@ -567,44 +567,44 @@ int emcore_mime_parse_header(void *stream, int is_file, struct _rfc822header **r } - if ((is_file == 0 && !emcore_mime_get_line_from_sock(stream, buf, MIME_LINE_LEN, err_code)) || + if ((is_file == 0 && !emcore_mime_get_line_from_sock(stream, buf, MIME_LINE_LEN, err_code)) || (is_file == 1 && !emcore_get_line_from_file(stream, buf, MIME_LINE_LEN, err_code))) { return false; } - + if (!(tmp_header = em_malloc(sizeof(struct _m_mesg_header)))) { EM_DEBUG_EXCEPTION("malloc failed..."); if (err_code != NULL) *err_code = EMAIL_ERROR_OUT_OF_MEMORY; return false; } - + if (!emcore_check_thread_status()) { if (err_code != NULL) *err_code = EMAIL_ERROR_CANCELLED; return false; } - + while (TRUE) { EM_DEBUG_LOG("buf[%s]", buf); - + if (!strncmp(buf, CRLF_STRING, 2)) break; - + is_longheader = (buf[0] == ' ' || buf[0] == '\t') ? TRUE : FALSE; - - + + if (!is_longheader) { /* Normal header (format : "Name : Value" or "Name : Value; Parameters" */ if (name) { EM_SAFE_FREE(name); } - + /* EM_DEBUG_FUNC_BEGIN() */ if ((pTemp = strtok(buf, ":")) == NULL) break; - + name = EM_SAFE_STRDUP(pTemp); - + value = strtok(NULL, CRLF_STRING); em_upper_string(name); @@ -613,32 +613,32 @@ int emcore_mime_parse_header(void *stream, int is_file, struct _rfc822header **r value = strtok(buf, CRLF_STRING); em_trim_left(value); } - + /* --> 2007-05-08 by cy */ if (!name) break; - + EM_DEBUG_LOG("> name[%s]", name); EM_DEBUG_LOG("> value[%s]", value); - + /* MIME Part Heade */ if (memcmp(name, "CONTENT-", 8) == 0 && value) { EM_DEBUG_LINE; emcore_mime_set_part_header_value(&tmp_header->part_header, name, value, err_code); - + if (tmp_header->part_header && tmp_header->part_header->parameter) { EM_DEBUG_LOG("name[%s]", tmp_header->part_header->parameter->name); EM_DEBUG_LOG("value[%s]", tmp_header->part_header->parameter->value); EM_DEBUG_LOG("next : %p", tmp_header->part_header->parameter->next); } - + /* MIME Version Heade */ } else if (memcmp(name, "MIME-VERSION", 12) == 0) { /* EM_DEBUG_FUNC_BEGIN() */ /* ignored because we need only contents information */ /* tmp_header->version = EM_SAFE_STRDUP(value) */ - + /* RFC822 Heade */ } else { @@ -646,108 +646,108 @@ int emcore_mime_parse_header(void *stream, int is_file, struct _rfc822header **r if (is_file == 1) emcore_mime_set_rfc822_header_value(&tmp_rfc822header, name, value, err_code); } - + 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)) || + if ((is_file == 0 && !emcore_mime_get_line_from_sock(stream, buf, MIME_LINE_LEN, err_code)) || (is_file == 1 && !emcore_get_line_from_file(stream, buf, MIME_LINE_LEN, err_code))) { - + if (tmp_rfc822header) emcore_mime_free_rfc822_header(tmp_rfc822header); - - + + if (tmp_header) { emcore_mime_free_part_header(tmp_header->part_header); - + EM_SAFE_FREE(tmp_header->version); EM_SAFE_FREE(tmp_header); } - return false; + return false; } } - + *header = tmp_header; *rfc822header = tmp_rfc822header; - + EM_SAFE_FREE(name); EM_DEBUG_FUNC_END(); return true; } int emcore_mime_parse_part_header(void *stream, int is_file, struct _m_part_header **header, int *err_code) -{ +{ EM_DEBUG_FUNC_BEGIN("stream[%p], is_file[%d], header[%p], err_code[%p]", stream, is_file, header, err_code); - + struct _m_part_header *tmp_header = NULL; char buf[MIME_LINE_LEN] = {0x00}; char *name = NULL; - char *value = NULL; - char *p = NULL; - int is_longheader = false; - + char *value = NULL; + char *p = NULL; + int is_longheader = false; + 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)) || + if ((is_file == 0 && !emcore_mime_get_line_from_sock(stream, buf, MIME_LINE_LEN, err_code)) || (is_file == 1 && !emcore_get_line_from_file(stream, buf, MIME_LINE_LEN, err_code))) - return false; - + return false; + tmp_header = em_malloc(sizeof(struct _m_part_header)); if (!tmp_header) { EM_DEBUG_EXCEPTION("em_malloc failed"); return false; } - + memset(tmp_header, 0, sizeof(struct _m_part_header)); - + while (true) { - if (!strncmp(buf, CRLF_STRING, EM_SAFE_STRLEN(CRLF_STRING))) break; - + if (!strncmp(buf, CRLF_STRING, EM_SAFE_STRLEN(CRLF_STRING))) break; + is_longheader = (buf[0] == ' ' || buf[0] == TAB); - + if (!is_longheader) { /* Normal header (format : "Name : Value" or "Name : Value; Parameters" */ EM_SAFE_FREE(name); p = strtok(buf , ":"); - - if (p) { + + if (p) { name = EM_SAFE_STRDUP(p); value = strtok(NULL, CRLF_STRING); em_upper_string(name); } - } + } else /* Long header */ value = strtok(buf, CRLF_STRING); - + if (!name) break; - + emcore_mime_set_part_header_value(&tmp_header, name, value, err_code); - + 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)) || + + if ((is_file == 0 && !emcore_mime_get_line_from_sock(stream, buf, MIME_LINE_LEN, err_code)) || (is_file == 1 && !emcore_get_line_from_file(stream, buf, MIME_LINE_LEN, err_code))) { EM_SAFE_FREE(name); EM_SAFE_FREE(tmp_header); - - return false; + + return false; } - } - + } + *header = tmp_header; - + EM_SAFE_FREE(name); EM_DEBUG_FUNC_END(); return true; @@ -755,59 +755,59 @@ int emcore_mime_parse_part_header(void *stream, int is_file, struct _m_part_head int emcore_mime_parse_body(void *stream, int is_file, struct _m_mesg *mmsg, struct _m_content_info *cnt_info, void *callback, int *err_code) -{ +{ EM_DEBUG_FUNC_BEGIN("stream[%p], is_file[%d], mmsg[%p], cnt_info[%p], callback[%p], err_code[%p]", stream, is_file, mmsg, cnt_info, callback, err_code); - + char *content_type = NULL, *content_encoding = NULL, *holder = NULL, *attachment_name, *t = NULL; - int type = 0, end_of_parsing = 0, size, local_err_code = EMAIL_ERROR_NONE; + int type = 0, end_of_parsing = 0, size, local_err_code = EMAIL_ERROR_NONE; if (!emcore_check_thread_status()) { if (err_code != NULL) *err_code = EMAIL_ERROR_CANCELLED; return false; } - + if (mmsg->header) - content_type = emcore_mime_get_header_value(mmsg->header->part_header, CONTENT_TYPE, err_code); - if (!content_type) + content_type = emcore_mime_get_header_value(mmsg->header->part_header, CONTENT_TYPE, err_code); + if (!content_type) content_type = "TEXT/PLAIN"; - + if (mmsg->header) content_encoding = emcore_mime_get_header_value(mmsg->header->part_header, CONTENT_ENCODING, err_code); - if (!content_encoding) - content_encoding = "7BIT"; - - if (strstr(content_type, TEXT_STR)) type = TYPE_TEXT; - else if (strstr(content_type, IMAGE_STR)) type = TYPE_IMAGE; - else if (strstr(content_type, AUDIO_STR)) type = TYPE_AUDIO; - else if (strstr(content_type, VIDEO_STR)) type = TYPE_VIDEO; - else if (strstr(content_type, APPLICATION_STR)) type = TYPE_APPLICATION; - else if (strstr(content_type, MULTIPART_STR)) type = TYPE_MULTIPART; - else if (strstr(content_type, MESSAGE_STR)) type = TYPE_MESSAGE; - else type = TYPE_UNKNOWN; - + if (!content_encoding) + content_encoding = "7BIT"; + + if (strstr(content_type, TEXT_STR)) type = TYPE_TEXT; + else if (strstr(content_type, IMAGE_STR)) type = TYPE_IMAGE; + else if (strstr(content_type, AUDIO_STR)) type = TYPE_AUDIO; + else if (strstr(content_type, VIDEO_STR)) type = TYPE_VIDEO; + else if (strstr(content_type, APPLICATION_STR)) type = TYPE_APPLICATION; + else if (strstr(content_type, MULTIPART_STR)) type = TYPE_MULTIPART; + else if (strstr(content_type, MESSAGE_STR)) type = TYPE_MESSAGE; + else type = TYPE_UNKNOWN; + switch (type) { case TYPE_MULTIPART: if (mmsg->header && !emcore_mime_get_header_value(mmsg->header->part_header, CONTENT_BOUNDARY, err_code)) { EM_DEBUG_FUNC_END("false"); return false; } - + if (mmsg->header && !emcore_mime_parse_part(stream, is_file, mmsg->header->part_header, &mmsg->nested, cnt_info, &end_of_parsing, &local_err_code)) { EM_DEBUG_FUNC_END("false"); return false; } /* after finishing body parsing, make stream empty to get next mail. (get line from sock or file until '.' is read */ - if (end_of_parsing == true && local_err_code != EMAIL_ERROR_NO_MORE_DATA) + if (end_of_parsing == true && local_err_code != EMAIL_ERROR_NO_MORE_DATA) emcore_mime_flush_receiving_buffer(stream, is_file, NULL, NULL, NULL, err_code); - if (err_code) + if (err_code) *err_code = local_err_code; - - break; - - default: + + break; + + default: attachment_name = NULL; if (mmsg->header && emcore_mime_get_header_value(mmsg->header->part_header, CONTENT_DISPOSITION, err_code)) { @@ -839,13 +839,13 @@ int emcore_mime_parse_body(void *stream, int is_file, struct _m_mesg *mmsg, stru EM_DEBUG_EXCEPTION("emcore_mime_get_content_data failed : [%d]", err_code); return false; } - + EM_DEBUG_LOG("After emcore_mime_get_content_data"); char *charset = mmsg->header? emcore_mime_get_header_value(mmsg->header->part_header, CONTENT_CHARSET, err_code) : NULL; /* prevent 27453 */ - + EM_DEBUG_LOG(">>>> charset [%s]", charset); - + if (mmsg->header && mmsg->header->part_header && strstr((t = emcore_mime_get_header_value(mmsg->header->part_header, CONTENT_TYPE, err_code)) ? t : "", "HTML")) { if (!charset || !strncmp(charset, "X-UNKNOWN", strlen("X-UNKNOWN"))) cnt_info->text.plain_charset = strdup("UTF-8"); @@ -853,42 +853,42 @@ int emcore_mime_parse_body(void *stream, int is_file, struct _m_mesg *mmsg, stru cnt_info->text.plain_charset = EM_SAFE_STRDUP(charset); EM_DEBUG_LOG(">>>> cnt_info->text.plain_charset [%s]", cnt_info->text.plain_charset); - + cnt_info->text.html = holder; - + EM_DEBUG_LOG(">>>> cnt_info->text.plain [%s]", cnt_info->text.html); } else if (mmsg->header) { - + if (!charset || !strncmp(charset, "X-UNKNOWN", strlen("X-UNKNOWN"))) cnt_info->text.plain_charset = strdup("UTF-8"); else cnt_info->text.plain_charset = EM_SAFE_STRDUP(charset); - + EM_DEBUG_LOG(">>>> cnt_info->text.plain_charset [%s]", cnt_info->text.plain_charset); - + cnt_info->text.plain = holder; - + EM_DEBUG_LOG(">>>> cnt_info->text.plain [%s]", cnt_info->text.plain); } } - - break; - } + + break; + } EM_DEBUG_FUNC_END(); - return true; -} + return true; +} int emcore_mime_parse_part(void *stream, int is_file, struct _m_part_header *parent_header, struct _m_part *nested, struct _m_content_info *cnt_info, int *eop, int *err_code) { EM_DEBUG_FUNC_BEGIN("stream[%p], is_file[%d], parent_header[%p], nested[%p], cnt_info[%p], eop[%p], err_code[%p]", stream, is_file, parent_header, nested, cnt_info, eop, err_code); - + struct _m_body *tmp_body = NULL; struct _m_part **p = NULL; char buf[MIME_LINE_LEN] = {0x00, }; char boundary[BOUNDARY_LEN] = {0x00, }; - char boundary_end[BOUNDARY_LEN] = {0x00, }; + char boundary_end[BOUNDARY_LEN] = {0x00, }; char mime_type_buffer[128] = { 0, }; char *boundary_str = NULL; char *content_type = NULL; @@ -902,12 +902,12 @@ 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 is_skip = false; int result = 0; boundary_str = emcore_mime_get_header_value(parent_header, CONTENT_BOUNDARY, err_code); - SNPRINTF(boundary, BOUNDARY_LEN, "--%s%s", boundary_str, CRLF_STRING); + SNPRINTF(boundary, BOUNDARY_LEN, "--%s%s", boundary_str, CRLF_STRING); SNPRINTF(boundary_end, BOUNDARY_LEN, "--%s%s", boundary_str, "--\r\n"); nested->body = NULL; @@ -915,13 +915,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) { + while (true) { 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)) || + if ((is_file == 0 && !emcore_mime_get_line_from_sock(stream, buf, MIME_LINE_LEN, err_code)) || (is_file == 1 && !emcore_get_line_from_file(stream, buf, MIME_LINE_LEN, err_code))) { EM_DEBUG_EXCEPTION("emcore_mime_get_line_from_sock failed."); if (eop) @@ -929,57 +929,57 @@ int emcore_mime_parse_part(void *stream, int is_file, struct _m_part_header *par EM_DEBUG_FUNC_END("false"); return false; } - + if (!strcmp(buf, boundary)) - break; + break; } EM_DEBUG_LOG("Before second loop"); while (true) { if (!(tmp_body = em_malloc(sizeof(struct _m_body)))) { EM_DEBUG_EXCEPTION("em_malloc failed."); - if (nested->body) + if (nested->body) emcore_mime_free_part_body(nested->body); - if (nested->next) + if (nested->next) emcore_mime_free_part(nested->next); EM_DEBUG_FUNC_END("false"); return false; } - + memset(tmp_body, 0, sizeof(struct _m_body)); - + /* parsing MIME Header */ if (!emcore_mime_parse_part_header(stream, is_file, &tmp_body->part_header, err_code)) { EM_DEBUG_EXCEPTION("emcore_mime_parse_part_header failed."); - if (nested->body) + if (nested->body) emcore_mime_free_part_body(nested->body); - if (nested->next) + if (nested->next) emcore_mime_free_part(nested->next); - + emcore_mime_free_part_body(tmp_body); return false; } - + content_type = emcore_mime_get_header_value(tmp_body->part_header, CONTENT_TYPE, err_code); - if (!content_type) - content_type = "TEXT/PLAIN"; + if (!content_type) + content_type = "TEXT/PLAIN"; content_encoding = emcore_mime_get_header_value(tmp_body->part_header, CONTENT_ENCODING, err_code); if (!content_encoding) - content_encoding = "7BIT"; - - if (strstr(content_type, TEXT_STR)) type = TYPE_TEXT; - else if (strstr(content_type, IMAGE_STR)) type = TYPE_IMAGE; - else if (strstr(content_type, AUDIO_STR)) type = TYPE_AUDIO; - else if (strstr(content_type, VIDEO_STR)) type = TYPE_VIDEO; - else if (strstr(content_type, APPLICATION_STR)) type = TYPE_APPLICATION; - else if (strstr(content_type, MULTIPART_STR)) type = TYPE_MULTIPART; - else if (strstr(content_type, MESSAGE_STR)) type = TYPE_MESSAGE; + content_encoding = "7BIT"; + + if (strstr(content_type, TEXT_STR)) type = TYPE_TEXT; + else if (strstr(content_type, IMAGE_STR)) type = TYPE_IMAGE; + else if (strstr(content_type, AUDIO_STR)) type = TYPE_AUDIO; + else if (strstr(content_type, VIDEO_STR)) type = TYPE_VIDEO; + else if (strstr(content_type, APPLICATION_STR)) type = TYPE_APPLICATION; + else if (strstr(content_type, MULTIPART_STR)) type = TYPE_MULTIPART; + else if (strstr(content_type, MESSAGE_STR)) type = TYPE_MESSAGE; else type = TYPE_UNKNOWN; switch (type) { - case TYPE_MULTIPART: + case TYPE_MULTIPART: EM_DEBUG_LOG("TYPE_MULTIPART"); if (!emcore_mime_get_header_value(tmp_body->part_header, CONTENT_BOUNDARY, err_code)) { EM_DEBUG_EXCEPTION("emcore_mime_get_header_value failed."); @@ -987,20 +987,20 @@ int emcore_mime_parse_part(void *stream, int is_file, struct _m_part_header *par EM_DEBUG_FUNC_END("false"); return false; } - + emcore_mime_parse_part(stream, is_file, tmp_body->part_header, &tmp_body->nested, cnt_info, &end_of_parsing, &local_err_code); - - if (!nested->body) + + if (!nested->body) nested->body = tmp_body; else { p = &nested->next; - + while (*p && (*p)->next) *p = (*p)->next; - + if (*p) p = &(*p)->next; - + if (!(*p = em_malloc(sizeof(struct _m_part)))) { EM_DEBUG_EXCEPTION("em_malloc failed"); if (nested->body) emcore_mime_free_part_body(nested->body); @@ -1009,39 +1009,39 @@ int emcore_mime_parse_part(void *stream, int is_file, struct _m_part_header *par EM_DEBUG_FUNC_END("false"); return false; } - + (*p)->body = tmp_body; (*p)->next = NULL; } - + if (err_code) *err_code = local_err_code; - + if (end_of_parsing && local_err_code != EMAIL_ERROR_NO_MORE_DATA) /* working with imap */ /* if (!end_of_parsing) */ /* working with pop */ { EM_DEBUG_LOG("Enter flushing socket buffer."); emcore_mime_flush_receiving_buffer(stream, is_file, boundary, boundary_end, &end_of_parsing, err_code); } - - break; - - default: + + break; + + default: EM_DEBUG_LOG("default"); attachment_name = NULL; content_disposition = NULL; - if (type == TYPE_MESSAGE) + 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)) + 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 */ t = emcore_mime_get_header_value(tmp_body->part_header, CONTENT_TYPE, err_code); @@ -1064,10 +1064,10 @@ int emcore_mime_parse_part(void *stream, int is_file, struct _m_part_header *par attachment_name = emcore_mime_get_header_value(tmp_body->part_header, CONTENT_FILENAME, err_code); content_disposition_type = ATTACHMENT; - + } else { EM_DEBUG_EXCEPTION("Unknown mime type"); - } + } } else { if (!strcasecmp(content_disposition ? content_disposition : "", "attachment")) { attachment_name = emcore_mime_get_header_value(tmp_body->part_header, CONTENT_NAME, err_code); @@ -1083,7 +1083,7 @@ 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); - content_disposition_type = INLINE_ATTACHMENT; + content_disposition_type = INLINE_ATTACHMENT; } else if (strstr(content_type, "PKCS7")) { attachment_name = emcore_mime_get_header_value(tmp_body->part_header, CONTENT_NAME, err_code); EM_DEBUG_LOG_MIME(">> attachment = [%s]", attachment_name ? attachment_name : NIL); @@ -1110,7 +1110,7 @@ int emcore_mime_parse_part(void *stream, int is_file, struct _m_part_header *par /* get content and content information */ if (!attachment_name) { /* text */ /* get content by buffer */ - EM_DEBUG_LOG_MIME("attachment_name is NULL. It's a text message"); + 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)) { EM_DEBUG_EXCEPTION("emcore_mime_get_content_data failed [%d]", err_code); emcore_mime_free_part_body(tmp_body); @@ -1118,26 +1118,26 @@ int emcore_mime_parse_part(void *stream, int is_file, struct _m_part_header *par } EM_DEBUG_LOG("After emcore_mime_get_content_data"); - + if (cnt_info->grab_type & GRAB_TYPE_TEXT) { if (tmp_body->part_header && strstr(t ? t : "", "HTML")) { cnt_info->text.html = holder; - + EM_DEBUG_LOG(" cnt_info->text.html [%s]", cnt_info->text.html); } else { char *charset = emcore_mime_get_header_value(tmp_body->part_header, CONTENT_CHARSET, err_code); EM_DEBUG_LOG(" charset [%s]", charset); - + if (!charset || !strncmp(charset, "X-UNKNOWN", strlen("X-UNKNOWN"))) cnt_info->text.plain_charset = strdup("UTF-8"); else cnt_info->text.plain_charset = EM_SAFE_STRDUP(charset); - + EM_DEBUG_LOG(" cnt_info->text.plain_charset [%s]", cnt_info->text.plain_charset); - + cnt_info->text.plain = holder; - + EM_DEBUG_LOG(" cnt_info->text.plain [%s]", cnt_info->text.plain); } } @@ -1149,7 +1149,7 @@ int emcore_mime_parse_part(void *stream, int is_file, struct _m_part_header *par } } else { /* attachment */ - EM_DEBUG_LOG("attachment_name is not NULL. It's a attachment"); + EM_DEBUG_LOG("attachment_name is not NULL. It's a attachment"); struct attachment_info *file = NULL; struct attachment_info *temp_file = cnt_info->file; @@ -1164,18 +1164,18 @@ int emcore_mime_parse_part(void *stream, int is_file, struct _m_part_header *par file->type = content_disposition_type; EM_DEBUG_LOG("file->type : %d", file->type); - + file->name = EM_SAFE_STRDUP(attachment_name); file->content_id = EM_SAFE_STRDUP(tmp_body->part_header->content_id); if(tmp_body->part_header->type && tmp_body->part_header->subtype) { SNPRINTF(mime_type_buffer, 128, "%s/%s", tmp_body->part_header->type, tmp_body->part_header->subtype); file->attachment_mime_type = EM_SAFE_STRDUP(mime_type_buffer); } - + /* 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"); + 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)) { EM_DEBUG_EXCEPTION("emcore_mime_get_content_data failed [%d]", err_code); emcore_mime_free_part_body(tmp_body); @@ -1187,7 +1187,7 @@ int emcore_mime_parse_part(void *stream, int is_file, struct _m_part_header *par file->save = holder; } else { /* only get content size */ - EM_DEBUG_LOG_MIME("Pass downloading"); + 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)) { EM_DEBUG_EXCEPTION("emcore_mime_get_content_data failed [%d]", err_code); emcore_mime_free_part_body(tmp_body); @@ -1198,15 +1198,15 @@ int emcore_mime_parse_part(void *stream, int is_file, struct _m_part_header *par file->save = NULL; } - + if (err_code) EM_DEBUG_LOG("end_of_parsing [%d], err_code [%d]", end_of_parsing, *err_code); - + file->size = size; - + if (strstr(content_type, APPLICATION_STR)) { - pTemp = content_type + EM_SAFE_STRLEN(APPLICATION_STR); - + pTemp = content_type + EM_SAFE_STRLEN(APPLICATION_STR); + if (strcasecmp(pTemp, MIME_SUBTYPE_DRM_OBJECT) == 0) file->drm = EMAIL_ATTACHMENT_DRM_OBJECT; else if (strcasecmp(pTemp, MIME_SUBTYPE_DRM_RIGHTS) == 0) @@ -1223,7 +1223,7 @@ int emcore_mime_parse_part(void *stream, int is_file, struct _m_part_header *par else temp_file->next = file; } - + if (!emcore_check_thread_status()) { if (err_code != NULL) *err_code = EMAIL_ERROR_CANCELLED; @@ -1233,51 +1233,51 @@ int emcore_mime_parse_part(void *stream, int is_file, struct _m_part_header *par return false; } - if (!nested->body) + if (!nested->body) nested->body = tmp_body; else { p = &nested->next; - + while (*p && (*p)->next) p = &(*p)->next; - + if (*p) p = &(*p)->next; - + if (!(*p = em_malloc(sizeof(struct _m_part)))) { EM_DEBUG_EXCEPTION("em_malloc failed"); if (nested->body) emcore_mime_free_part_body(nested->body); if (nested->next) emcore_mime_free_part(nested->next); - + emcore_mime_free_part_body(tmp_body); EM_DEBUG_FUNC_END("false"); return false; } - + (*p)->body = tmp_body; (*p)->next = NULL; } - - break; + + break; } - + /* End of parsin */ if (end_of_parsing) - break; + break; } - + if (eop != NULL) *eop = end_of_parsing; EM_DEBUG_FUNC_END("end_of_parsing [%d]", end_of_parsing); - return true; -} + return true; +} /* set RFC822 Heade */ int emcore_mime_set_rfc822_header_value(struct _rfc822header **header, char *name, char *value, int *err_code) { EM_DEBUG_FUNC_BEGIN("header[%p], name[%s], value[%s], err_code[%p]", header, name, value, err_code); - + char **p = NULL; char *t = NULL; @@ -1285,7 +1285,7 @@ int emcore_mime_set_rfc822_header_value(struct _rfc822header **header, char *nam if (!*header) { *header = em_malloc(sizeof(struct _rfc822header)); - if (!*header) { + if (!*header) { EM_DEBUG_EXCEPTION("em_malloc failed"); return false; } @@ -1324,16 +1324,16 @@ int emcore_mime_set_rfc822_header_value(struct _rfc822header **header, char *nam return false; } - if (!*p) + if (!*p) *p = EM_SAFE_STRDUP(value); else { /* Long Header */ if (!(t = realloc(*p, strlen(*p) + strlen(value)+1))) /*prevent 34354*/ return false; - + strncat(t, value, strlen(value)); /*prevent 34354*/ *p = t; } - + return true; } @@ -1341,7 +1341,7 @@ int emcore_mime_set_rfc822_header_value(struct _rfc822header **header, char *nam int emcore_mime_set_part_header_value(struct _m_part_header **header, char *name, char *value, int *err_code) { EM_DEBUG_FUNC_BEGIN("header[%p], name[%s], value[%s], err_code[%p]", header, name, value, err_code); - + if (!name || !value) { EM_DEBUG_EXCEPTION("Invalid parameter"); if (err_code != NULL) @@ -1351,15 +1351,15 @@ int emcore_mime_set_part_header_value(struct _m_part_header **header, char *name struct _parameter *p = NULL; char *p_val = NULL; - + if (!*header) { *header = em_malloc(sizeof(struct _m_part_header)); - if (!(*header)) { + if (!(*header)) { EM_DEBUG_EXCEPTION("em_malloc failed..."); return false; } } - + em_upper_string(name); em_trim_left(value); em_trim_right(value); @@ -1373,14 +1373,14 @@ int emcore_mime_set_part_header_value(struct _m_part_header **header, char *name if (name) { if (strncmp(name, "CONTENT-TYPE", strlen("CONTENT-TYPE")) == 0) { p_val = strtok(value, ";"); - + if (p_val) { if (!(*header)->type) { /* Content-Type */ em_upper_string(p_val); - (*header)->type = EM_SAFE_STRDUP(p_val); - } + (*header)->type = EM_SAFE_STRDUP(p_val); + } else { /* Content-Type Parameter (format : "name =value" */ - if (emcore_mime_get_param_from_str(p_val, &p, err_code)) + if (emcore_mime_get_param_from_str(p_val, &p, err_code)) emcore_mime_add_param_to_list(&((*header)->parameter), p, err_code); else /* name= CRLF value */ { struct _parameter *t = (*header)->parameter; @@ -1401,24 +1401,24 @@ int emcore_mime_set_part_header_value(struct _m_part_header **header, char *name } 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))) + + if (!(utf8_text = emcore_decode_rfc2047_text(p_val, &err))) EM_DEBUG_EXCEPTION("emcore_decode_rfc2047_text failed [%d]", err); EM_DEBUG_LOG("utf8_text : [%s]", utf8_text); t->value = EM_SAFE_STRDUP(utf8_text); } } } - + } - + /* repeatedly get paramete */ while ((p_val = strtok(NULL, ";"))) { - if (emcore_mime_get_param_from_str(p_val, &p, err_code)) + if (emcore_mime_get_param_from_str(p_val, &p, err_code)) emcore_mime_add_param_to_list(&((*header)->parameter), p, err_code); } } @@ -1426,65 +1426,65 @@ int emcore_mime_set_part_header_value(struct _m_part_header **header, char *name else if (strncmp(name, "CONTENT-TRANSFER-ENCODING", strlen("CONTENT-TRANSFER-ENCODING")) == 0) { em_upper_string(value); (*header)->encoding = EM_SAFE_STRDUP(value); - } + } else if (strncmp(name, "CONTENT-DESCRPTION", strlen("CONTENT-DESCRPTION")) == 0) { em_upper_string(value); (*header)->desc = EM_SAFE_STRDUP(value); - } + } else if (strncmp(name, "CONTENT-DISPOSITION", strlen("CONTENT-DISPOSITION")) == 0) { p_val = strtok(value, ";"); - + if (p_val) { if (!(*header)->disp_type) { /* Content-Dispositio */ em_upper_string(p_val); - (*header)->disp_type = EM_SAFE_STRDUP(p_val); - } + (*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)) + if (emcore_mime_get_param_from_str(p_val, &p, err_code)) emcore_mime_add_param_to_list(&((*header)->disp_parameter), p, err_code); } - + /* repeatedly get paramete */ while ((p_val = strtok(NULL, ";"))) { - if (emcore_mime_get_param_from_str(p_val, &p, err_code)) + if (emcore_mime_get_param_from_str(p_val, &p, err_code)) emcore_mime_add_param_to_list(&((*header)->disp_parameter), p, err_code); } - } - } + } + } else if (strncmp(name, "CONTENT-ID", strlen("CONTENT-ID")) == 0) { size_t len = 0; len = EM_SAFE_STRLEN(value); /* em_upper_string(value) */ - + if ((len) && (value[0] == '<')) { ++value; --len; } - - if ((len > 1) && (value[len-1] == '>')) + + if ((len > 1) && (value[len-1] == '>')) value[len-1] = '\0'; - + (*header)->content_id = EM_SAFE_STRDUP(value); } - else if (strncmp(name, "CONTENT-LOCATION", strlen("CONTENT-LOCATION")) == 0) + else if (strncmp(name, "CONTENT-LOCATION", strlen("CONTENT-LOCATION")) == 0) (*header)->content_location = EM_SAFE_STRDUP(value); - } + } EM_DEBUG_FUNC_END(); return true; } - + /* get header parameter from string */ int emcore_mime_get_param_from_str(char *str, struct _parameter **param, int *err_code) { EM_DEBUG_FUNC_BEGIN("str[%s], param[%p], err_code[%p]", str, param, err_code); - + char *p_name, *p_val, *p; *param = NULL; /* Parameter Check */ if (!(p = strchr(str, '='))) return false; - + *p = '\0'; p_name = str; @@ -1492,11 +1492,11 @@ int emcore_mime_get_param_from_str(char *str, struct _parameter **param, int *er em_trim_left(p_name); em_trim_right(p_name); - + if (!*p_name) return false; if (!(*param = em_malloc(sizeof(struct _parameter)))) return false; - + (*param)->next = NULL; /* Name set */ @@ -1508,7 +1508,7 @@ int emcore_mime_get_param_from_str(char *str, struct _parameter **param, int *er em_trim_left(p_val); em_trim_right(p_val); - + if (!*p_val) { EM_DEBUG_LOG("Parameter value is NULL"); return true; @@ -1521,15 +1521,15 @@ int emcore_mime_get_param_from_str(char *str, struct _parameter **param, int *er } if ((p = strchr(p_val, '\"'))) *p = '\0'; - + if (strncmp(p_name, "BOUNDARY", strlen("BOUNDARY")) != 0 && !strstr(p_name, "NAME")) em_upper_string(p_val); - + /* = ? ENCODING_TYPE ? B(Q) ? ENCODED_STRING ? */ int err = EMAIL_ERROR_NONE; char *utf8_text = NULL; - - if (!(utf8_text = emcore_decode_rfc2047_text(p_val, &err))) + + if (!(utf8_text = emcore_decode_rfc2047_text(p_val, &err))) EM_DEBUG_EXCEPTION("emcore_decode_rfc2047_text failed [%d]", err); (*param)->value = utf8_text; } @@ -1541,11 +1541,11 @@ int emcore_mime_get_param_from_str(char *str, struct _parameter **param, int *er int emcore_mime_add_param_to_list(struct _parameter **param_list, struct _parameter *param, int *err_code) { struct _parameter **t = param_list; - - while (*t && (*t)->next) + + while (*t && (*t)->next) *t = (*t)->next; - - if (*t) + + if (*t) (*t)->next = param; else *t = param; @@ -1557,71 +1557,71 @@ int emcore_mime_add_param_to_list(struct _parameter **param_list, struct _parame char *emcore_mime_get_header_value(struct _m_part_header *header, int type, int *err_code) { EM_DEBUG_FUNC_BEGIN("header[%p], type[%d], err_code[%p]", header, type, err_code); - + struct _parameter *p = NULL; char *name = NULL; - + if (!header) { EM_DEBUG_EXCEPTION("header[%p], type[%d]", header, type); - + if (err_code != NULL) *err_code = EMAIL_ERROR_INVALID_PARAM; return NULL; } - + switch (type) { - case CONTENT_TYPE: + case CONTENT_TYPE: return header->type; - - case CONTENT_SUBTYPE: + + case CONTENT_SUBTYPE: return header->subtype; - - case CONTENT_ENCODING: + + case CONTENT_ENCODING: return header->encoding; - - case CONTENT_CHARSET: + + case CONTENT_CHARSET: name = "CHARSET"; p = header->parameter; break; - - case CONTENT_DISPOSITION: + + case CONTENT_DISPOSITION: return header->disp_type; - - case CONTENT_NAME: + + case CONTENT_NAME: name = "NAME"; p = header->parameter; break; - - case CONTENT_FILENAME: + + case CONTENT_FILENAME: name = "FILENAME"; p = header->disp_parameter; break; - - case CONTENT_BOUNDARY: + + case CONTENT_BOUNDARY: name = "BOUNDARY"; p = header->parameter; break; - - case CONTENT_REPORT_TYPE: + + case CONTENT_REPORT_TYPE: name = "REPORT-TYPE"; p = header->parameter; break; - - case CONTENT_ID: + + case CONTENT_ID: return header->content_id; - - case CONTENT_LOCATION: + + case CONTENT_LOCATION: return header->content_location; - - default: + + default: return NULL; } - + for (; p; p = p->next) { if (strcmp(p->name, name) == 0) break; } - + if (!p) return NULL; EM_DEBUG_FUNC_END(); @@ -1629,36 +1629,36 @@ char *emcore_mime_get_header_value(struct _m_part_header *header, int type, int } /* - * decode body text (quoted-printable, base64) + * decode body text (quoted-printable, base64) * enc_type : encoding type (base64/quotedprintable) */ INTERNAL_FUNC int emcore_decode_body_text(char *enc_buf, int enc_len, int enc_type, int *dec_len, int *err_code) { EM_DEBUG_FUNC_BEGIN("enc_buf[%p], enc_len[%d], enc_type[%d], dec_len[%p]", enc_buf, enc_len, enc_type, dec_len); unsigned char *content = NULL; - + /* too many called */ *dec_len = enc_len; - + switch (enc_type) { case ENCQUOTEDPRINTABLE: EM_DEBUG_LOG("ENCQUOTEDPRINTABLE"); content = rfc822_qprint((unsigned char *)enc_buf, (unsigned long)enc_len, (unsigned long *)dec_len); break; - + case ENCBASE64: EM_DEBUG_LOG("ENCBASE64"); content = rfc822_base64((unsigned char *)enc_buf, (unsigned long)enc_len, (unsigned long *)dec_len); break; - - case ENC7BIT: - case ENC8BIT: - case ENCBINARY: - case ENCOTHER: + + case ENC7BIT: + case ENC8BIT: + case ENCBINARY: + case ENCOTHER: default: break; } - + if (content) { if (enc_len < *dec_len) { EM_DEBUG_EXCEPTION("Decoded length is too big to store it"); @@ -1679,10 +1679,10 @@ 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, int is_text, char *boundary_str, char *content_encoding, int *end_of_parsing, int mode, char **holder, int *size, void *callback, int *err_code) +{ EM_DEBUG_FUNC_BEGIN("stream[%p], is_file[%d], boundary_str[%s], content_encoding[%s], end_of_parsing[%p], mode[%d], holder[%p], size[%p], callback[%p], err_code[%p]", stream, is_file, boundary_str, content_encoding, end_of_parsing, mode, holder, size, callback, err_code); - + int encoding = ENC7BIT; int error = EMAIL_ERROR_NONE, ret = false; int fd = 0; @@ -1691,20 +1691,20 @@ int emcore_mime_get_content_data(void *stream, int is_file, int is_text, char *b if ((mode == SAVE_TYPE_FILE || mode == SAVE_TYPE_BUFFER) && !holder) return false; - if (holder) + if (holder) *holder = NULL; - if (size) + if (size) *size = 0; EM_DEBUG_LOG("get content"); - + if (content_encoding) { switch (content_encoding[0]) { - case 'Q': + case 'Q': encoding = ENCQUOTEDPRINTABLE; break; /* qutoed-printabl */ - case 'B': + case 'B': if (content_encoding[1] == 'A') { encoding = ENCBASE64; break; /* base6 */ @@ -1715,13 +1715,13 @@ int emcore_mime_get_content_data(void *stream, int is_file, int is_text, char *b } encoding = ENC7BIT; break; - case '7': + case '7': encoding = ENC7BIT; break; /* 7bi */ - case '8': + case '8': encoding = ENC8BIT; break; /* 8bi */ - default: + default: encoding = ENCOTHER; break; /* unknow */ } @@ -1730,9 +1730,9 @@ int emcore_mime_get_content_data(void *stream, int is_file, int is_text, char *b /* saving type is file */ if (mode == SAVE_TYPE_FILE) { *holder = emcore_mime_get_save_file_name(&error); - + 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."); @@ -1759,7 +1759,7 @@ int emcore_mime_get_content_data(void *stream, int is_file, int is_text, char *b } ret = true; -FINISH_OFF: +FINISH_OFF: if (err_code != NULL) *err_code = error; @@ -1768,55 +1768,55 @@ FINISH_OFF: if (ret) { if (size) *size = sz; - } - + } + EM_DEBUG_FUNC_END("ret [%d], sz [%d]", ret, sz); - return ret; -} - -int emcore_mime_skip_content_data(void *stream, - int is_file, - char *boundary_str, - int *end_of_parsing, - int *size, - void *callback, - int *err_code) -{ + return ret; +} + +int emcore_mime_skip_content_data(void *stream, + int is_file, + char *boundary_str, + int *end_of_parsing, + int *size, + void *callback, + int *err_code) +{ EM_DEBUG_FUNC_BEGIN("stream[%p], is_file[%d], boundary_str[%s], end_of_parsing[%p], size[%p], callback[%p], err_code[%p]", stream, is_file, boundary_str, end_of_parsing, size, callback, err_code); - + char buf[MIME_LINE_LEN] = {0x00}, boundary[BOUNDARY_LEN], boundary_end[BOUNDARY_LEN]; - int sz = 0; + int sz = 0; - if (size) + if (size) *size = 0; EM_DEBUG_LOG(">>> skip content <<<<<<<<<<<<<"); if (!boundary_str) { /* if no boundary, this content is from current line to end of all multipart */ while (TRUE) { - + if (!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)) || + if ((is_file == 0 && !emcore_mime_get_line_from_sock(stream, buf, MIME_LINE_LEN, err_code)) || (is_file == 1 && !emcore_get_line_from_file(stream, buf, MIME_LINE_LEN, err_code))) { - *end_of_parsing = 1; - if (size) + *end_of_parsing = 1; + if (size) *size = sz; - return false; + return false; } sz += EM_SAFE_STRLEN(buf); } - } + } else { /* if there boundary, this content is from current line to ending boundary */ memset(boundary, 0x00, BOUNDARY_LEN); memset(boundary_end, 0x00, BOUNDARY_LEN); - - SNPRINTF(boundary, BOUNDARY_LEN, "--%s%s", boundary_str, CRLF_STRING); + + SNPRINTF(boundary, BOUNDARY_LEN, "--%s%s", boundary_str, CRLF_STRING); SNPRINTF(boundary_end, BOUNDARY_LEN, "--%s%s", boundary_str, "--\r\n"); - + while (TRUE) { if (!emcore_check_thread_status()) { @@ -1824,41 +1824,41 @@ int emcore_mime_skip_content_data(void *stream, *err_code = EMAIL_ERROR_CANCELLED; return false; } - if ((is_file == 0 && !emcore_mime_get_line_from_sock(stream, buf, MIME_LINE_LEN, err_code)) || + if ((is_file == 0 && !emcore_mime_get_line_from_sock(stream, buf, MIME_LINE_LEN, err_code)) || (is_file == 1 && !emcore_get_line_from_file(stream, buf, MIME_LINE_LEN, err_code))) { /* end of fil */ - *end_of_parsing = 1; - if (size) + *end_of_parsing = 1; + if (size) *size = sz; - return true; - } - + return true; + } + if (!strcmp(buf, boundary)) { /* the other part started. the parsing of other part will be started */ - *end_of_parsing = 0; - if (size) + *end_of_parsing = 0; + if (size) *size = sz; - return true; - } + return true; + } else if (!strcmp(buf, boundary_end)) { /* if ending boundary, the parsing of other multipart will be started */ - *end_of_parsing = 1; - if (size) + *end_of_parsing = 1; + if (size) *size = sz; - return true; - } - + return true; + } + sz += EM_SAFE_STRLEN(buf); - } - } + } + } - if (size) + if (size) *size = sz; EM_DEBUG_FUNC_END(); - return true; -} + return true; +} /* get temporary file name */ -char *emcore_mime_get_save_file_name(int *err_code) -{ +char *emcore_mime_get_save_file_name(int *err_code) +{ EM_DEBUG_FUNC_BEGIN(); char tempname[512]; struct timeval tv; @@ -1871,7 +1871,7 @@ char *emcore_mime_get_save_file_name(int *err_code) SNPRINTF(tempname, sizeof(tempname), "%s%s%d", MAILTEMP, DIR_SEPERATOR, rand()); EM_DEBUG_FUNC_END(); return EM_SAFE_STRDUP(tempname); -} +} /* get a line from file pointer */ char *emcore_get_line_from_file(void *stream, char *buf, int size, int *err_code) @@ -1892,16 +1892,16 @@ char *emcore_mime_get_line_from_sock(void *stream, char *buf, int size, int *err { EM_DEBUG_FUNC_BEGIN("stream[%p], buf[%p]", stream, buf); POP3LOCAL *p_pop3local = NULL; - + if (!stream || !buf) { EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM"); if (err_code != NULL) *err_code = EMAIL_ERROR_INVALID_PARAM; return NULL; } - + memset(buf, 0x00, size); - + p_pop3local = (POP3LOCAL *)(((MAILSTREAM *)stream)->local); if (!p_pop3local) { EM_DEBUG_EXCEPTION("stream->local[%p]", p_pop3local); @@ -1909,12 +1909,12 @@ char *emcore_mime_get_line_from_sock(void *stream, char *buf, int size, int *err *err_code = EMAIL_ERROR_INVALID_PARAM; return NULL; } - + if (!pop3_reply((MAILSTREAM *)stream)) { /* if TRUE, check respons */ EM_DEBUG_LOG("p_pop3local->response 1[%s]", p_pop3local->response); if (p_pop3local->response) { if (*p_pop3local->response == '.' && EM_SAFE_STRLEN(p_pop3local->response) == 1) { - free(p_pop3local->response); + free(p_pop3local->response); p_pop3local->response = NULL; if (err_code != NULL) *err_code = EMAIL_ERROR_NO_MORE_DATA; @@ -1924,16 +1924,16 @@ char *emcore_mime_get_line_from_sock(void *stream, char *buf, int size, int *err EM_DEBUG_LOG("Not end of response"); strncpy(buf, p_pop3local->response, size-1); strncat(buf, CRLF_STRING, size-(EM_SAFE_STRLEN(buf) + 1)); - - free(p_pop3local->response); + + free(p_pop3local->response); p_pop3local->response = NULL; goto FINISH_OFF; } } - + EM_DEBUG_LOG("p_pop3local->response 2[%s]", p_pop3local->response); - if (p_pop3local->response) + if (p_pop3local->response) { /* if response isn't NULL, check whether this response start with '+' */ /* if the first character is '+', return error because this response is normal data */ @@ -1950,7 +1950,7 @@ char *emcore_mime_get_line_from_sock(void *stream, char *buf, int size, int *err return NULL; } -FINISH_OFF: +FINISH_OFF: if (buf) { int received_percentage, last_notified_percentage; _pop3_received_body_size += EM_SAFE_STRLEN(buf); @@ -1960,7 +1960,7 @@ FINISH_OFF: EM_DEBUG_LOG("_pop3_received_body_size = %d, _pop3_total_body_size = %d", _pop3_received_body_size, _pop3_total_body_size); EM_DEBUG_LOG("received_percentage = %d, last_notified_percentage = %d", received_percentage, last_notified_percentage); - + if (received_percentage > last_notified_percentage + 5) { if (!emcore_notify_network_event(NOTI_DOWNLOAD_BODY_START, _pop3_receiving_mail_id, "dummy-file", _pop3_total_body_size, _pop3_received_body_size)) EM_DEBUG_EXCEPTION(" emcore_notify_network_event [NOTI_DOWNLOAD_BODY_START] Failed >>>> "); @@ -2023,7 +2023,7 @@ void emcore_mime_free_rfc822_header(struct _rfc822header *header) EM_SAFE_FREE(header->from); EM_SAFE_FREE(header->subject); EM_SAFE_FREE(header->sender); - EM_SAFE_FREE(header->to); + EM_SAFE_FREE(header->to); EM_SAFE_FREE(header->cc); EM_SAFE_FREE(header->bcc); free(header); header = NULL; @@ -2055,7 +2055,7 @@ void emcore_mime_free_part(struct _m_part *part) void emcore_mime_free_mime(struct _m_mesg *mmsg) { EM_DEBUG_FUNC_BEGIN(); - + if (!mmsg) return ; if (mmsg->header) emcore_mime_free_message_header(mmsg->header); if (mmsg->rfc822header) emcore_mime_free_rfc822_header(mmsg->rfc822header); @@ -2070,7 +2070,7 @@ 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); @@ -2112,11 +2112,11 @@ void emcore_free_attachment_info(struct attachment_info *attchment) static PARTLIST *emcore_get_allnested_part_full(MAILSTREAM *stream, int msg_uid, BODY *body, struct _m_content_info *cnt_info, int *err_code, PARTLIST *section_list) { EM_DEBUG_FUNC_BEGIN("stream[%p], msg_uid[%d], body[%p], cnt_info[%p], err_code[%p]", stream, msg_uid, body, cnt_info, err_code); - + PART *part_child = body->nested.part; - + while (part_child) { - section_list = emcore_get_body_full(stream, msg_uid, &part_child->body, cnt_info, err_code, section_list); + section_list = emcore_get_body_full(stream, msg_uid, &part_child->body, cnt_info, err_code, section_list); part_child = part_child->next; } @@ -2128,15 +2128,15 @@ static PARTLIST *emcore_get_allnested_part_full(MAILSTREAM *stream, int msg_uid, static PARTLIST *emcore_get_alternative_multi_part_full(MAILSTREAM *stream, int msg_uid, BODY *body, struct _m_content_info *cnt_info, int *err_code, PARTLIST *section_list) { EM_DEBUG_FUNC_BEGIN("stream[%p], msg_uid[%d], body[%p], cnt_info[%p], err_code[%p]", stream, msg_uid, body, cnt_info, err_code); - + PART *part_child = body->nested.part; /* find the best sub part we can show */ while (part_child) { - section_list = emcore_get_body_full(stream, msg_uid, &part_child->body, cnt_info, err_code, section_list); + section_list = emcore_get_body_full(stream, msg_uid, &part_child->body, cnt_info, err_code, section_list); part_child = part_child->next; } - + EM_DEBUG_FUNC_END("section_list[%p]", section_list); return section_list; } @@ -2150,10 +2150,10 @@ static PARTLIST *emcore_get_signed_multi_part_full(MAILSTREAM *stream, int msg_u /* find the best sub part we can show */ while (part_child) { - section_list = emcore_get_body_full(stream, msg_uid, &part_child->body, cnt_info, err_code, section_list); + section_list = emcore_get_body_full(stream, msg_uid, &part_child->body, cnt_info, err_code, section_list); part_child = part_child->next; } - + EM_DEBUG_FUNC_END(); return section_list; } @@ -2162,7 +2162,7 @@ static PARTLIST *emcore_get_signed_multi_part_full(MAILSTREAM *stream, int msg_u static PARTLIST *emcore_get_encrypted_multi_part_full(MAILSTREAM *stream, int msg_uid, BODY *body, struct _m_content_info *cnt_info, int *err_code, PARTLIST *section_list) { EM_DEBUG_FUNC_BEGIN("stream[%p], msg_uid[%d], body[%p], cnt_info[%p], err_code[%p]", stream, msg_uid, body, cnt_info, err_code); - + /* "protocol" = "application/pgp-encrypted */ EM_DEBUG_FUNC_END(); return section_list; @@ -2172,17 +2172,17 @@ static PARTLIST *emcore_get_encrypted_multi_part_full(MAILSTREAM *stream, int ms static PARTLIST *emcore_get_multi_part_full(MAILSTREAM *stream, int msg_uid, BODY *body, struct _m_content_info *cnt_info, int *err_code, PARTLIST *section_list) { EM_DEBUG_FUNC_BEGIN("stream[%p], msg_uid[%d], body[%p], cnt_info[%p], err_code[%p]", stream, msg_uid, body, cnt_info, err_code); - + switch (body->subtype[0]) { case 'A': /* ALTERNATIV */ return section_list = emcore_get_alternative_multi_part_full(stream, msg_uid, body, cnt_info, err_code, section_list); - + case 'S': /* SIGNE */ return section_list = emcore_get_signed_multi_part_full(stream, msg_uid, body, cnt_info, err_code, section_list); - + case 'E': /* ENCRYPTE */ return section_list = emcore_get_encrypted_multi_part_full(stream, msg_uid, body, cnt_info, err_code, section_list); - + default: /* process all unknown as MIXED (according to the RFC 2047 */ return section_list = emcore_get_allnested_part_full(stream, msg_uid, body, cnt_info, err_code, section_list); } @@ -2194,7 +2194,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) { EM_DEBUG_EXCEPTION("stream[%p], msg_uid[%d], body[%p], cnt_info[%p]", stream, msg_uid, body, cnt_info); if (err_code != NULL) @@ -2202,18 +2202,18 @@ PARTLIST* emcore_get_body_full(MAILSTREAM *stream, int msg_uid, BODY *body, stru EM_DEBUG_FUNC_END(); return NULL; } - + switch (body->type) { - case TYPEMULTIPART: + case TYPEMULTIPART: section_list = emcore_get_multi_part_full(stream, msg_uid, body, cnt_info, err_code, section_list); EM_DEBUG_FUNC_END("section_list [%p]", section_list); return section_list; - + case TYPEMESSAGE: break; - + case TYPETEXT: - case TYPEAPPLICATION: + case TYPEAPPLICATION: case TYPEAUDIO: case TYPEIMAGE: case TYPEVIDEO: @@ -2226,7 +2226,7 @@ PARTLIST* emcore_get_body_full(MAILSTREAM *stream, int msg_uid, BODY *body, stru char filename[512] = {0, }; struct attachment_info *current_ai = NULL; struct attachment_info *ai = NULL; - + if (emcore_get_file_pointer(body, true, filename, cnt_info, (int*)NULL) < 0) EM_DEBUG_EXCEPTION("emcore_get_file_pointer failed"); else { @@ -2240,20 +2240,20 @@ PARTLIST* emcore_get_body_full(MAILSTREAM *stream, int msg_uid, BODY *body, stru EM_DEBUG_EXCEPTION("em_malloc failed..."); if(err_code) *err_code = EMAIL_ERROR_OUT_OF_MEMORY; - return NULL; + 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 */ - + ai->name = EM_SAFE_STRDUP(filename); ai->size = body->size.bytes; ai->content_id = EM_SAFE_STRDUP(body->id); if (emcore_get_content_type_from_mail_bodystruct(body, 512, content_type_buffer) == EMAIL_ERROR_NONE) ai->attachment_mime_type = EM_SAFE_STRDUP(content_type_buffer); - + #ifdef __ATTACHMENT_OPTI__ ai->encoding = body->encoding; if (body->sparep) @@ -2261,7 +2261,7 @@ PARTLIST* emcore_get_body_full(MAILSTREAM *stream, int msg_uid, BODY *body, stru EM_DEBUG_LOG("Encoding - %d Section No - %s ", ai->encoding, ai->section); #endif - + EM_DEBUG_LOG("Type[%d], Name[%s], Path[%s] ", ai->type, ai->name, ai->save); if (body->type == TYPEAPPLICATION) { if (!strcasecmp(body->subtype, MIME_SUBTYPE_DRM_OBJECT)) @@ -2272,10 +2272,10 @@ PARTLIST* emcore_get_body_full(MAILSTREAM *stream, int msg_uid, BODY *body, stru ai->drm = EMAIL_ATTACHMENT_DRM_DCF; else if (!strcasecmp(body->subtype, "pkcs7-mime")) cnt_info->grab_type = cnt_info->grab_type | GRAB_TYPE_ATTACHMENT; - } - + } + if (current_ai == NULL) { - cnt_info->file = ai; + cnt_info->file = ai; } else { while(current_ai->next != NULL) current_ai = current_ai->next; @@ -2284,22 +2284,22 @@ PARTLIST* emcore_get_body_full(MAILSTREAM *stream, int msg_uid, BODY *body, stru } } } - + /* if (cnt_info->grab_type == GRAB_TYPE_ATTACHMENT */ if (cnt_info->grab_type & GRAB_TYPE_ATTACHMENT) { if (((body->disposition.type != NULL) && ((body->disposition.type[0] == 'a') || (body->disposition.type[0] == 'A'))) && (cnt_info->file != NULL)) { - PARAMETER *param = NULL; + PARAMETER *param = NULL; char *fn = NULL; param = body->parameter; - + while (param) { if (!strcasecmp(param->attribute, "NAME")) { - fn = EM_SAFE_STRDUP(param->value); + fn = EM_SAFE_STRDUP(param->value); break; } if (!strcasecmp(param->attribute, "FILENAME")) { - fn = EM_SAFE_STRDUP(param->value); + fn = EM_SAFE_STRDUP(param->value); break; } param = param->next; @@ -2310,7 +2310,7 @@ PARTLIST* emcore_get_body_full(MAILSTREAM *stream, int msg_uid, BODY *body, stru EM_DEBUG_EXCEPTION("adding node to section list failed"); if(err_code) *err_code = EMAIL_ERROR_OUT_OF_MEMORY; - EM_SAFE_FREE(fn); + EM_SAFE_FREE(fn); return NULL; } else { @@ -2320,7 +2320,7 @@ PARTLIST* emcore_get_body_full(MAILSTREAM *stream, int msg_uid, BODY *body, stru } } EM_SAFE_FREE(fn); - } + } } else { /* get a section list which has only plain, html and inline */ @@ -2334,10 +2334,10 @@ PARTLIST* emcore_get_body_full(MAILSTREAM *stream, int msg_uid, BODY *body, stru } } } - + break; - - default: + + default: break; } @@ -2352,15 +2352,15 @@ PARTLIST* emcore_get_body_full(MAILSTREAM *stream, int msg_uid, BODY *body, stru INTERNAL_FUNC int emcore_get_body_part_list_full(MAILSTREAM *stream, int msg_uid, int account_id, int mail_id, BODY *body, struct _m_content_info *cnt_info, int *err_code, PARTLIST *section_list, int event_handle) { EM_DEBUG_FUNC_BEGIN("stream[%p], msg_uid[%d], body[%p], cnt_info[%p], err_code[%p]", stream, msg_uid, body, cnt_info, err_code); - + if (!stream || !body || !cnt_info) { EM_DEBUG_EXCEPTION("stream[%p], msg_uid[%d], body[%p], cnt_info[%p]", stream, msg_uid, body, cnt_info); - + if (err_code != NULL) *err_code = EMAIL_ERROR_INVALID_PARAM; return FAILURE; } - section_list = emcore_get_body_full(stream, msg_uid, body, cnt_info, err_code, section_list); + section_list = emcore_get_body_full(stream, msg_uid, body, cnt_info, err_code, section_list); if (section_list == NULL) { /* assumed at least one body part exist */ @@ -2405,11 +2405,11 @@ static int emcore_write_response_into_file(char *filename, char *write_mode, cha if( err ) *err = EMAIL_ERROR_INVALID_PARAM; /* prevent 28347 */ return false; } - + EM_DEBUG_LOG("Encoded buffer length [%d]", EM_SAFE_STRLEN(encoded)); encoded_len = EM_SAFE_STRLEN(encoded); - + EM_DEBUG_LOG("encoding_type [%d]", encoding_type); switch (encoding_type) { case ENCQUOTEDPRINTABLE: { @@ -2418,11 +2418,11 @@ static int emcore_write_response_into_file(char *filename, char *write_mode, cha g_free(orignal); break; } - + case ENCBASE64: decoded = (char *)rfc822_base64((unsigned char *)encoded, encoded_len, &decoded_len); break; - + default: { unsigned char *orignal = (unsigned char *)g_strdup_printf("%s\r\n", encoded); decoded = em_malloc(encoded_len + 3); /*prevent 28347*/ @@ -2462,7 +2462,7 @@ static int emcore_write_response_into_file(char *filename, char *write_mode, cha EM_DEBUG_LOG("inline_count [%d], g_inline_count [%d]", inline_count, g_inline_count); body_inline = g_inline_list[inline_count]; param = body_inline->disposition.parameter; - param1 = body_inline->parameter; + param1 = body_inline->parameter; memset(body_inline_id, 0x00, 512); @@ -2483,11 +2483,11 @@ static int emcore_write_response_into_file(char *filename, char *write_mode, cha memset(save_file_name, 0x00, MAX_PATH); memset(html_cid_path, 0x00, MAX_PATH); - + /* Finding 'filename' attribute from content inf */ emcore_get_file_pointer(body_inline, true, save_file_name, NULL, &error); - if (EM_SAFE_STRLEN(save_file_name) > 0) { + if (EM_SAFE_STRLEN(save_file_name) > 0) { /* Content ID will be replaced with its file name in html */ memcpy(html_cid_path, decoded_content_id , strlen("cid:") + EM_SAFE_STRLEN(body_inline_id)); @@ -2546,10 +2546,10 @@ static int emcore_write_response_into_file(char *filename, char *write_mode, cha ret = true; -FINISH_OFF: +FINISH_OFF: if (err) *err = error; - + EM_SAFE_FREE(decoded); if (fp != NULL) @@ -2567,7 +2567,7 @@ static BODY *emcore_select_body_structure_from_section_list(PARTLIST *section_li BODY *body = NULL; while (temp != NULL) { - body = temp->body; + body = temp->body; if (!strcmp(section, body->sparep)) return body; temp = (PARTLIST *)temp->next; @@ -2582,7 +2582,7 @@ static int imap_mail_write_body_to_file(MAILSTREAM *stream, int account_id, int { EM_PROFILE_BEGIN(imapMailWriteBodyToFile); EM_DEBUG_FUNC_BEGIN("stream[%p], filepath[%s], uid[%d], section[%s], encoding[%d], decoded_total[%p], err_code[%p]", stream, filepath, uid, section, encoding, decoded_total, err_code); - + int ret = false; int err = EMAIL_ERROR_NONE; FILE *fp = NULL; @@ -2601,7 +2601,7 @@ static int imap_mail_write_body_to_file(MAILSTREAM *stream, int account_id, int unsigned char test_buffer[LOCAL_MAX_BUFFER_SIZE] = {0, }; int flag_first_write = true; int max_write_buffer_size = MAX_WRITE_BUFFER_SIZE; - + if (!stream || !filepath || !section) { EM_DEBUG_EXCEPTION("stream[%p], filepath[%s], uid[%d], section[%s], encoding[%d], decoded_total[%p]", stream, filepath, uid, section, encoding, decoded_total); err = EMAIL_ERROR_INVALID_PARAM; @@ -2613,60 +2613,60 @@ static int imap_mail_write_body_to_file(MAILSTREAM *stream, int account_id, int if (max_write_buffer_size > 0) { max_write_buffer_size *= 1024; /* KB -> byte */ if (!(write_buffer = em_malloc(sizeof(char) *max_write_buffer_size))) { - EM_DEBUG_EXCEPTION("em_malloc failed..."); - err = EMAIL_ERROR_OUT_OF_MEMORY; + EM_DEBUG_EXCEPTION("em_malloc failed..."); + err = EMAIL_ERROR_OUT_OF_MEMORY; goto FINISH_OFF; } } - FINISH_OFF_IF_CANCELED; - + FINISH_OFF_IF_CANCELED; + if (!(fp = fopen(filepath, "wb+"))) { EM_DEBUG_EXCEPTION("fopen failed - %s", filepath); err = EMAIL_ERROR_SYSTEM_FAILURE; /* EMAIL_ERROR_UNKNOWN */ goto FINISH_OFF; } - + imaplocal = stream->local; if (!imaplocal->netstream) { EM_DEBUG_EXCEPTION("invalid IMAP4 stream detected... %p", imaplocal->netstream); - err = EMAIL_ERROR_INVALID_STREAM; + err = EMAIL_ERROR_INVALID_STREAM; goto FINISH_OFF; } - + EM_DEBUG_LOG(" next_decode_string = false "); next_decode_string = false; memset(tag, 0x00, sizeof(tag)); memset(command, 0x00, sizeof(command)); - + SNPRINTF(tag, sizeof(tag), "%08lx", 0xffffffff & (stream->gensym++)); SNPRINTF(command, sizeof(command), "%s UID FETCH %d BODY.PEEK[%s]\015\012", tag, uid, section); - + EM_DEBUG_LOG("[IMAP4] >>> [%s]", command); - + /* send command : get msgno/uid for all messag */ if (!net_sout(imaplocal->netstream, command, (int)EM_SAFE_STRLEN(command))) { EM_DEBUG_EXCEPTION("net_sout failed..."); err = EMAIL_ERROR_CONNECTION_BROKEN; goto FINISH_OFF; } - + while (imaplocal->netstream) { char *p = NULL; char *s = NULL; - + if (!emcore_check_thread_status()) { EM_DEBUG_LOG("Canceled..."); /* Is it realy required ? It might cause crashes. - if (imaplocal->netstream) + if (imaplocal->netstream) net_close (imaplocal->netstream); */ imaplocal->netstream = NULL; err = EMAIL_ERROR_CANCELLED; goto FINISH_OFF; - } + } /* receive respons */ if (!(response = net_getline(imaplocal->netstream))) { @@ -2677,34 +2677,34 @@ static int imap_mail_write_body_to_file(MAILSTREAM *stream, int account_id, int #ifdef FEATURE_CORE_DEBUG EM_DEBUG_LOG("recv[%s]", response); #endif - + write_flag = false; if (response[0] == '*' && !server_response_yn) { /* start of respons */ - + if ((p = strstr(response, "BODY[")) /* || (p = strstr(s + 1, "BODY["))*/) { server_response_yn = 1; p += strlen("BODY["); s = p; - + while (*s != ']') s++; - + *s = '\0'; if (strcmp(section, p)) { err = EMAIL_ERROR_INVALID_RESPONSE; goto FINISH_OFF; } - - if ((p = strstr(s+1, " {"))) { + + if ((p = strstr(s+1, " {"))) { p += strlen(" {"); s = p; - + while (isdigit(*s)) s++; - + *s = '\0'; - + body_size = atoi(p); } else { /* no body length is replied */ @@ -2737,16 +2737,16 @@ static int imap_mail_write_body_to_file(MAILSTREAM *stream, int account_id, int 3. bodysize */ parse_file_path_to_filename(filepath, &file_id); - + filename = file_id; sprintf(server_uid, "%d", uid); - + EM_DEBUG_LOG("file_id [%s]", file_id); EM_DEBUG_LOG("filename [%p]-[%s]", filename, filename); EM_DEBUG_LOG("body_size [%d]", body_size); EM_DEBUG_LOG("server_uid [%s]", server_uid); EM_DEBUG_LOG("mail_id [%d]", mail_id); - + if (is_attachment) { EM_DEBUG_LOG("Attachment number [%d]", is_attachment); if (!emcore_notify_network_event(NOTI_DOWNLOAD_ATTACH_START, mail_id, filename, is_attachment, 0)) @@ -2769,8 +2769,8 @@ static int imap_mail_write_body_to_file(MAILSTREAM *stream, int account_id, int _imap4_download_noti_interval_value = body_size *DOWNLOAD_NOTI_INTERVAL_PERCENT / 100; _imap4_total_body_size = body_size; } - } - if (_imap4_download_noti_interval_value > DOWNLOAD_NOTI_INTERVAL_SIZE) { + } + if (_imap4_download_noti_interval_value > DOWNLOAD_NOTI_INTERVAL_SIZE) { _imap4_download_noti_interval_value = DOWNLOAD_NOTI_INTERVAL_SIZE; } if (body_size < DOWNLOAD_MAX_BUFFER_SIZE) { @@ -2787,7 +2787,7 @@ static int imap_mail_write_body_to_file(MAILSTREAM *stream, int account_id, int total = EM_SAFE_STRLEN((char *)encoded); EM_DEBUG_LOG("total = %d", total); - EM_DEBUG_LOG("write_response_into_file successful %s.....", filename); + EM_DEBUG_LOG("write_response_into_file successful %s.....", filename); if (((_imap4_last_notified_body_size + _imap4_download_noti_interval_value) <= _imap4_received_body_size) || (_imap4_received_body_size >= _imap4_total_body_size)) /* 100 */ { @@ -2797,13 +2797,13 @@ static int imap_mail_write_body_to_file(MAILSTREAM *stream, int account_id, int gap = total - body_size; _imap4_received_body_size -= gap; _imap4_last_notified_body_size = _imap4_received_body_size; - + if(body_size > 0) EM_DEBUG_LOG("DOWNLOADING STATUS NOTIFY : Encoded[%d] / [%d] = %d %% Completed. -- Total Decoded[%d]", total, body_size, 100*total/body_size, total); if(_imap4_total_body_size > 0) EM_DEBUG_LOG("DOWNLOADING STATUS NOTIFY : Total[%d] / [%d] = %d %% Completed.", _imap4_received_body_size, _imap4_total_body_size, 100*_imap4_received_body_size/_imap4_total_body_size); - + if (is_attachment) { if (_imap4_total_body_size && !emcore_notify_network_event(NOTI_DOWNLOAD_ATTACH_START, mail_id, filename, is_attachment, 100 *_imap4_received_body_size / _imap4_total_body_size)) EM_DEBUG_EXCEPTION(" emcore_notify_network_event [ NOTI_DOWNLOAD_ATTACH_START] Failed >>>> "); @@ -2823,33 +2823,33 @@ static int imap_mail_write_body_to_file(MAILSTREAM *stream, int account_id, int else { int temp_body_size = body_size; int x = 0; - + if (encoding == ENCBASE64) x = (sizeof(encoded)/78) *78; /* to solve base64 decoding pro */ else x = sizeof(encoded)-1; - - memset(test_buffer, 0x00, sizeof(test_buffer)); - while (temp_body_size && (total <body_size)) { - + + memset(test_buffer, 0x00, sizeof(test_buffer)); + while (temp_body_size && (total <body_size)) { + memset(test_buffer, 0x00, sizeof(test_buffer)); while ((total != body_size) && temp_body_size && ((EM_SAFE_STRLEN((char *)test_buffer) + x) < sizeof(test_buffer))) { - memset(encoded, 0x00, sizeof(encoded)); - + 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; + err = EMAIL_ERROR_NO_RESPONSE; goto FINISH_OFF; } - + temp_body_size = temp_body_size - x; strncat((char *)test_buffer, (char *)encoded, EM_SAFE_STRLEN((char *)encoded)); total = total + x; _imap4_received_body_size += EM_SAFE_STRLEN((char *)encoded); - + if ( !(temp_body_size/x) && temp_body_size%x) x = temp_body_size%x; - + if (((_imap4_last_notified_body_size + _imap4_download_noti_interval_value) <= _imap4_received_body_size) || (_imap4_received_body_size >= _imap4_total_body_size)) /* 100 */ { /* In some situation, total_encoded_len includes the length of dummy bytes. So it might be greater than body_size */ @@ -2858,10 +2858,10 @@ static int imap_mail_write_body_to_file(MAILSTREAM *stream, int account_id, int gap = total - body_size; _imap4_received_body_size -= gap; _imap4_last_notified_body_size = _imap4_received_body_size; - + /* EM_DEBUG_LOG("DOWNLOADING STATUS NOTIFY : Encoded[%d] / [%d] = %d %% Completed. -- Total Decoded[%d]", total, body_size, 100*total/body_size, total) */ EM_DEBUG_LOG("DOWNLOADING STATUS NOTIFY : Total[%d] / [%d] = %d %% Completed.", _imap4_received_body_size, _imap4_total_body_size, 100*_imap4_received_body_size/_imap4_total_body_size); - + if (is_attachment) { if (!emcore_notify_network_event(NOTI_DOWNLOAD_ATTACH_START, mail_id, filename, is_attachment, 100 *_imap4_received_body_size / _imap4_total_body_size)) EM_DEBUG_EXCEPTION(" emcore_notify_network_event [ NOTI_DOWNLOAD_ATTACH_START] Failed >>>> "); @@ -2881,7 +2881,7 @@ static int imap_mail_write_body_to_file(MAILSTREAM *stream, int account_id, int } - + if (flag_first_write == true) { if (!emcore_write_response_into_file(filepath, "wb+", (char *)test_buffer, encoding, section_subtype, account_id, mail_id, &err)) { EM_DEBUG_EXCEPTION("write_response_into_file %s failed [%d]", filepath, err); @@ -2895,7 +2895,7 @@ static int imap_mail_write_body_to_file(MAILSTREAM *stream, int account_id, int goto FINISH_OFF; } } - EM_DEBUG_LOG("%d has been written", EM_SAFE_STRLEN((char *)test_buffer)); + EM_DEBUG_LOG("%d has been written", EM_SAFE_STRLEN((char *)test_buffer)); /* notif */ } } @@ -2909,13 +2909,13 @@ static int imap_mail_write_body_to_file(MAILSTREAM *stream, int account_id, int } else if (!strncmp(response, tag, EM_SAFE_STRLEN(tag))) { /* end of respons */ if (!strncmp(response + EM_SAFE_STRLEN(tag) + 1, "OK", 2)) { - EM_SAFE_FREE(response); + EM_SAFE_FREE(response); } else { /* 'NO' or 'BAD */ err = EMAIL_ERROR_IMAP4_FETCH_UID_FAILURE; goto FINISH_OFF; } - + break; } else if (!strcmp(response, ")")) { @@ -2927,13 +2927,13 @@ static int imap_mail_write_body_to_file(MAILSTREAM *stream, int account_id, int if (decoded_total != NULL) *decoded_total = total; - + ret = true; -FINISH_OFF: +FINISH_OFF: EM_SAFE_FREE(decoded); EM_SAFE_FREE(response); - + if (fp != NULL) fclose(fp); @@ -2949,14 +2949,14 @@ FINISH_OFF: *err_code = err; EM_PROFILE_END(imapMailWriteBodyToFile); - + return ret; } static int emcore_get_body_part_imap_full(MAILSTREAM *stream, int msg_uid, int account_id, int mail_id, PARTLIST *section_list, struct _m_content_info *cnt_info, int *err_code, int event_handle) { EM_DEBUG_FUNC_BEGIN("stream[%p], msg_uid[%d], body[%p], cnt_info[%p], err_code[%p]", stream, msg_uid, section_list, cnt_info, err_code); - + int err = EMAIL_ERROR_NONE; char sections[IMAP_MAX_COMMAND_LENGTH] = { 0, }; IMAPLOCAL *imaplocal = NULL; @@ -2975,16 +2975,16 @@ static int emcore_get_body_part_imap_full(MAILSTREAM *stream, int msg_uid, int a struct attachment_info *ai = NULL; int i = 0; int total = 0; - int flag_first_write = 1; + int flag_first_write = 1; int imap4_total_body_download_progress = 0, progress = 0; - + if (!(imaplocal = stream->local) || !imaplocal->netstream || !section_list || !cnt_info) { EM_DEBUG_EXCEPTION("invalid IMAP4 stream detected..."); - err = EMAIL_ERROR_INVALID_PARAM; + err = EMAIL_ERROR_INVALID_PARAM; return_value = -1; goto FINISH_OFF; } - + if (section_list != NULL) { PARTLIST *temp = section_list; @@ -3024,23 +3024,23 @@ static int emcore_get_body_part_imap_full(MAILSTREAM *stream, int msg_uid, int a if (sections[EM_SAFE_STRLEN(sections)-1] == ' ') { sections[EM_SAFE_STRLEN(sections)-1] = '\0'; } - + EM_DEBUG_LOG("sections <%s>", sections); - + SNPRINTF(tag, sizeof(tag), "%08lx", 0xffffffff & (stream->gensym++)); SNPRINTF(command, sizeof(command), "%s UID FETCH %d (%s)\015\012", tag, msg_uid, sections); EM_DEBUG_LOG("command %s", command); - + if (EM_SAFE_STRLEN(command) == (sizeof(command)-1)) { EM_DEBUG_EXCEPTION("Too many body parts. IMAP command will fail."); return_value = -1; goto FINISH_OFF; } - + /* send command : get msgno/uid for all message */ if (!net_sout(imaplocal->netstream, command, (int)EM_SAFE_STRLEN(command))) { EM_DEBUG_EXCEPTION("net_sout failed..."); - err = EMAIL_ERROR_CONNECTION_BROKEN; + err = EMAIL_ERROR_CONNECTION_BROKEN; return_value = -1; goto FINISH_OFF; } @@ -3049,13 +3049,13 @@ static int emcore_get_body_part_imap_full(MAILSTREAM *stream, int msg_uid, int a /* receive respons */ if (!(response = net_getline(imaplocal->netstream))) { EM_DEBUG_EXCEPTION("net_getline failed..."); - err = EMAIL_ERROR_INVALID_RESPONSE; + err = EMAIL_ERROR_INVALID_RESPONSE; return_value = -1; goto FINISH_OFF; } - + if (strstr(response, "BODY[")) { - + if (!server_response_yn) /* start of response */ { if (response[0] != '*') { err = EMAIL_ERROR_INVALID_RESPONSE; @@ -3065,11 +3065,11 @@ static int emcore_get_body_part_imap_full(MAILSTREAM *stream, int msg_uid, int a } server_response_yn = 1; } - + flag_first_write = 1; total = 0; memset(encoded, 0x00, sizeof(encoded)); - + if (emcore_get_section_body_size(response, section, &body_size)<0) { EM_DEBUG_EXCEPTION("emcore_get_section_body_size failed [%d]", err); err = EMAIL_ERROR_INVALID_RESPONSE; @@ -3084,20 +3084,20 @@ static int emcore_get_body_part_imap_full(MAILSTREAM *stream, int msg_uid, int a err = EMAIL_ERROR_INVALID_RESPONSE; return_value = -1; goto FINISH_OFF; - } - encoding = body->encoding; - + } + encoding = body->encoding; + /* if (emcore_get_file_pointer(account_id, mail_id, body, buf, cnt_info , err)<0) { EM_DEBUG_EXCEPTION("emcore_get_file_pointer failed [%d]", err); goto FINISH_OFF; }*/ if (!emcore_get_temp_file_name(&buf, &err)) { - EM_DEBUG_EXCEPTION("emcore_get_temp_file_name failed [%d]", err); + EM_DEBUG_EXCEPTION("emcore_get_temp_file_name failed [%d]", err); goto FINISH_OFF; } - - EM_DEBUG_LOG("buf : %s", buf); + + EM_DEBUG_LOG("buf : %s", buf); /* notifying UI start */ /* parse_file_path_to_filename(buf, &file_id); */ @@ -3110,9 +3110,9 @@ static int emcore_get_body_part_imap_full(MAILSTREAM *stream, int msg_uid, int a cnt_info->text.plain = buf; PARAMETER *param = NULL; - + param = body->parameter; - + while (param) { if (!strcasecmp(param->attribute, "CHARSET")) { cnt_info->text.plain_charset = EM_SAFE_STRDUP(param->value); @@ -3126,13 +3126,13 @@ static int emcore_get_body_part_imap_full(MAILSTREAM *stream, int msg_uid, int a if (emcore_get_file_pointer(body, false, filename, cnt_info , &err)<0) { EM_DEBUG_EXCEPTION("emcore_get_file_pointer failed [%d]", err); goto FINISH_OFF; - } - + } + /* Search info from attachment list followed by inline attachment list */ ai = cnt_info->file; EM_DEBUG_LOG("ai - %p ", (ai)); - + /* For Inline content append to the end */ for (i = 1; ai; ai = ai->next, i++) { if (ai->save == NULL && (ai->content_id != NULL && EM_SAFE_STRCMP(ai->content_id, body->id) == 0)) { @@ -3142,13 +3142,13 @@ static int emcore_get_body_part_imap_full(MAILSTREAM *stream, int msg_uid, int a } } } - + FINISH_OFF_IF_CANCELED; - + if (cnt_info->grab_type == GRAB_TYPE_ATTACHMENT) { if (!emcore_notify_network_event(NOTI_DOWNLOAD_ATTACH_START, mail_id, buf, cnt_info->file_no, 0)) EM_DEBUG_EXCEPTION(" emcore_notify_network_event [ NOTI_DOWNLOAD_ATTACH_START] Failed >>>> "); - + _imap4_download_noti_interval_value = body_size *DOWNLOAD_NOTI_INTERVAL_PERCENT / 100; _imap4_total_body_size = body_size; } @@ -3157,26 +3157,26 @@ static int emcore_get_body_part_imap_full(MAILSTREAM *stream, int msg_uid, int a EM_DEBUG_LOG("Multipart body size is [%d]", multi_part_body_size); if (!emcore_notify_network_event(NOTI_DOWNLOAD_MULTIPART_BODY, mail_id, buf, multi_part_body_size, 0)) EM_DEBUG_EXCEPTION(" emcore_notify_network_event [ NOTI_DOWNLOAD_BODY_START] Failed >>>> "); - + _imap4_download_noti_interval_value = multi_part_body_size *DOWNLOAD_NOTI_INTERVAL_PERCENT / 100; } else { if (!emcore_notify_network_event(NOTI_DOWNLOAD_BODY_START, mail_id, buf, body_size, 0)) EM_DEBUG_EXCEPTION(" emcore_notify_network_event [ NOTI_DOWNLOAD_BODY_START] Failed >>>> "); - + _imap4_download_noti_interval_value = body_size *DOWNLOAD_NOTI_INTERVAL_PERCENT / 100; _imap4_total_body_size = body_size; } } - if (_imap4_download_noti_interval_value > DOWNLOAD_NOTI_INTERVAL_SIZE) { + if (_imap4_download_noti_interval_value > DOWNLOAD_NOTI_INTERVAL_SIZE) { _imap4_download_noti_interval_value = DOWNLOAD_NOTI_INTERVAL_SIZE; - } - + } + /* EM_SAFE_FREE(file_id) */ /* notifying UI end */ - + if (body_size < DOWNLOAD_MAX_BUFFER_SIZE) { if (net_getbuffer (imaplocal->netstream, (long)body_size, (char *)encoded) <= 0) { EM_DEBUG_EXCEPTION("net_getbuffer failed..."); @@ -3189,17 +3189,17 @@ static int emcore_get_body_part_imap_full(MAILSTREAM *stream, int msg_uid, int a return_value = -1; goto FINISH_OFF; } - + EM_DEBUG_LOG("total = %d", total); - EM_DEBUG_LOG("write_response_into_file successful %s.....", buf); + EM_DEBUG_LOG("write_response_into_file successful %s.....", buf); total = _imap4_received_body_size = EM_SAFE_STRLEN((char *)encoded); - + EM_DEBUG_LOG("_imap4_last_notified_body_size [%d]", _imap4_last_notified_body_size); EM_DEBUG_LOG("_imap4_download_noti_interval_value [%d]", _imap4_download_noti_interval_value); EM_DEBUG_LOG("_imap4_received_body_size [%d]", _imap4_received_body_size); EM_DEBUG_LOG("_imap4_total_body_size [%d] ", _imap4_total_body_size); - + if (((_imap4_last_notified_body_size + _imap4_download_noti_interval_value) <= _imap4_received_body_size) || (_imap4_received_body_size >= _imap4_total_body_size)) /* 100 */ { /* In some situation, total_encoded_len includes the length of dummy bytes. So it might be greater than body_size */ @@ -3215,15 +3215,15 @@ static int emcore_get_body_part_imap_full(MAILSTREAM *stream, int msg_uid, int a imap4_total_body_download_progress = _imap4_received_body_size; EM_DEBUG_LOG("3 : body_size %d", body_size); - + if (body_size) progress = 100*total/body_size; - else + else progress = body_size; EM_DEBUG_LOG("DOWNLOADING STATUS NOTIFY : Encoded[%d] / [%d] = %d %% Completed. -- Total Decoded[%d]", total, body_size, progress, total); EM_DEBUG_LOG("DOWNLOADING STATUS NOTIFY : Total[%d] / [%d] = %d %% Completed.", _imap4_received_body_size, _imap4_total_body_size, imap4_total_body_download_progress); - + if (cnt_info->grab_type == GRAB_TYPE_ATTACHMENT) { if (!emcore_notify_network_event(NOTI_DOWNLOAD_ATTACH_START, mail_id, buf, cnt_info->file_no, imap4_total_body_download_progress)) EM_DEBUG_EXCEPTION(" emcore_notify_network_event [ NOTI_DOWNLOAD_ATTACH_START] Failed >>>> "); @@ -3247,33 +3247,33 @@ static int emcore_get_body_part_imap_full(MAILSTREAM *stream, int msg_uid, int a else { int temp_body_size = body_size; int x = 0; - + if (encoding == ENCBASE64) x = (sizeof(encoded)/78) *78; /* to solve base64 decoding pro */ else x = sizeof(encoded)-1; - - memset(test_buffer, 0x00, sizeof(test_buffer)); - while (temp_body_size && (total <body_size)) { - + + memset(test_buffer, 0x00, sizeof(test_buffer)); + while (temp_body_size && (total <body_size)) { + memset(test_buffer, 0x00, sizeof(test_buffer)); while ((total != body_size) && temp_body_size && ((EM_SAFE_STRLEN((char *)test_buffer) + x) < sizeof(test_buffer))) { - memset(encoded, 0x00, sizeof(encoded)); - + 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; + err = EMAIL_ERROR_NO_RESPONSE; return_value = -1; goto FINISH_OFF; } - + temp_body_size = temp_body_size - x; strncat((char *)test_buffer, (char *)encoded, EM_SAFE_STRLEN((char *)encoded)); total = total + x; _imap4_received_body_size += EM_SAFE_STRLEN((char *)encoded); - + EM_DEBUG_LOG("total = %d", total); - + if ( !(temp_body_size/x) && temp_body_size%x) x = temp_body_size%x; @@ -3299,12 +3299,12 @@ static int emcore_get_body_part_imap_full(MAILSTREAM *stream, int msg_uid, int a if (body_size) progress = 100*total/body_size; - else + else progress = body_size; - + EM_DEBUG_LOG("DOWNLOADING STATUS NOTIFY : Encoded[%d] / [%d] = %d %% Completed. -- Total Decoded[%d]", total, body_size, progress, total); EM_DEBUG_LOG("DOWNLOADING STATUS NOTIFY : Total[%d] / [%d] = %d %% Completed.", _imap4_received_body_size, _imap4_total_body_size, imap4_total_body_download_progress); - + if (cnt_info->grab_type == GRAB_TYPE_ATTACHMENT) { if (!emcore_notify_network_event(NOTI_DOWNLOAD_ATTACH_START, mail_id, buf, cnt_info->file_no, imap4_total_body_download_progress)) EM_DEBUG_EXCEPTION(" emcore_notify_network_event [ NOTI_DOWNLOAD_ATTACH_START] Failed >>>> "); @@ -3342,28 +3342,28 @@ static int emcore_get_body_part_imap_full(MAILSTREAM *stream, int msg_uid, int a } } } - else if (!strncmp(response, tag, EM_SAFE_STRLEN(tag))) /* end of respons */ { - if (!strncmp(response + EM_SAFE_STRLEN(tag) + 1, "OK", 2)) + else if (!strncmp(response, tag, EM_SAFE_STRLEN(tag))) /* end of respons */ { + if (!strncmp(response + EM_SAFE_STRLEN(tag) + 1, "OK", 2)) EM_SAFE_FREE(response); else /* 'NO' or 'BAD */ { - err = EMAIL_ERROR_IMAP4_FETCH_UID_FAILURE; + err = EMAIL_ERROR_IMAP4_FETCH_UID_FAILURE; return_value = -1; goto FINISH_OFF; } - + break; } else if (!strcmp(response, ")")) { - + } - - free(response); - response = NULL; + + free(response); + response = NULL; } return_value = 0; - - FINISH_OFF: + + FINISH_OFF: if (err_code) *err_code = err; @@ -3462,7 +3462,7 @@ static int emcore_get_file_pointer(BODY *body, bool input_check_duplicated_file_ } cnt_info->text.html = EM_SAFE_STRDUP(output_file_name_string); } - else { + else { PARAMETER *param = body->parameter; char charset_string[512]; @@ -3472,10 +3472,10 @@ static int emcore_get_file_pointer(BODY *body, bool input_check_duplicated_file_ } else memcpy(output_file_name_string, "UTF-8", strlen("UTF-8")); - + cnt_info->text.plain = EM_SAFE_STRDUP(output_file_name_string); } - + } else if ((body->id != NULL) || ((body->disposition.type != NULL) && ((body->disposition.type[0] == 'i') || (body->disposition.type[0] == 'I')))) { /* body id is exising or disposition type is inline */ @@ -3503,9 +3503,9 @@ static int emcore_get_file_pointer(BODY *body, bool input_check_duplicated_file_ SNPRINTF(attachment_file_name, MAX_PATH, "%s", body->id+1); /* fname = em_parse_filename(body->id + 1 */ else SNPRINTF(attachment_file_name, MAX_PATH, "%s", body->id); /* fname = em_parse_filename(body->id */ - + len = EM_SAFE_STRLEN(attachment_file_name); - + if ((len > 1) && (attachment_file_name[len-1] == '>')) attachment_file_name[len - 1] = '\0'; decoded_filename = emcore_decode_rfc2047_text(attachment_file_name, &error); @@ -3518,7 +3518,7 @@ static int emcore_get_file_pointer(BODY *body, bool input_check_duplicated_file_ } else if (body->disposition.type != NULL) { /* disposition type is existing and not inline and body_id is nul */ - PARAMETER *param = body->parameter; + PARAMETER *param = body->parameter; if (!emcore_get_attribute_value_of_body_part(param, "NAME", attachment_file_name, MAX_PATH, true, &error)) emcore_get_attribute_value_of_body_part(param, "FILENAME", attachment_file_name, MAX_PATH, true, &error); memcpy(output_file_name_string, attachment_file_name, EM_SAFE_STRLEN(attachment_file_name)); @@ -3538,7 +3538,7 @@ static int emcore_get_file_pointer(BODY *body, bool input_check_duplicated_file_ } } -FINISH_OFF: +FINISH_OFF: EM_SAFE_FREE(decoded_filename); @@ -3555,12 +3555,12 @@ static PARTLIST *emcore_add_node(PARTLIST *section_list, BODY *body) PARTLIST *temp = (PARTLIST *)malloc(sizeof(PARTLIST)); if (temp == NULL) { - EM_DEBUG_EXCEPTION("PARTLIST node creation failed"); + EM_DEBUG_EXCEPTION("PARTLIST node creation failed"); return NULL; } temp->body = body; temp->next = NULL; - + if (section_list == NULL)/* first node in list */ { section_list = temp; } @@ -3573,8 +3573,8 @@ static PARTLIST *emcore_add_node(PARTLIST *section_list, BODY *body) /* in imap-2007e/c-client/mail.h PARTLIST{ - BODY *body; - PART *next; + BODY *body; + PART *next; }; */ } @@ -3599,40 +3599,40 @@ static int emcore_get_section_body_size(char *response, char *section, int *body 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, " {"); + p = strstr(s+1, " {"); if (p) { p += strlen(" {"); s = p; - + while (isdigit(*s)) s++; - + *s = '\0'; - + size = atoi(p); *body_size = size; - + /* sending progress noti to application. 1. mail_id 2. file_id 3. bodysize - */ - + */ + } else { return FAILURE; @@ -3652,18 +3652,18 @@ static char *em_parse_filename(char *filename) EM_DEBUG_EXCEPTION("filename is NULL "); return NULL; } - + char delims[] = "@"; char *result = NULL; static char parsed_filename[512] = {0, }; memset(parsed_filename, 0x00, 512); - + if (!strstr(filename, delims)) { EM_DEBUG_EXCEPTION("FileName does not contain @ "); return NULL; } - + result = strtok(filename, delims); if (strcasestr(result, ".bmp") || strcasestr(result, ".jpeg") || strcasestr(result, ".png") || strcasestr(result, ".jpg")) @@ -3811,15 +3811,15 @@ INTERNAL_FUNC int emcore_get_attribute_value_of_body_part(PARAMETER *input_param } memset(output_value, 0, output_buffer_length); - + while (temp_param) { EM_DEBUG_LOG("temp_param->attribute [%s]", temp_param->attribute); - if (!strcasecmp(temp_param->attribute, atribute_name)) { + if (!strcasecmp(temp_param->attribute, atribute_name)) { EM_DEBUG_LOG("temp_param->value [%s]", temp_param->value); if (temp_param->value) { if (with_rfc2047_text) { decoded_value = emcore_decode_rfc2047_text(temp_param->value, &err); - if (decoded_value) + if (decoded_value) result_value = decoded_value; else result_value = decoded_value; @@ -3843,9 +3843,9 @@ INTERNAL_FUNC int emcore_get_attribute_value_of_body_part(PARAMETER *input_param EM_DEBUG_EXCEPTION("buffer is too short"); err = EMAIL_ERROR_DATA_TOO_LONG; goto FINISH_OFF; - } + } } - + break; } temp_param = temp_param->next; @@ -3868,11 +3868,11 @@ FINISH_OFF: 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) { EM_DEBUG_FUNC_BEGIN("stream[%p], msg_uid[%d], body[%p], cnt_info[%p], err_code[%p]", stream, msg_uid, body, cnt_info, err_code); - + int err = EMAIL_ERROR_NONE, ret = -1; struct attachment_info **ai; struct attachment_info *prev_ai = NULL; - struct attachment_info *next_ai = NULL; + struct attachment_info *next_ai = NULL; char *savefile = NULL; char *o_data = NULL; char filename[MAX_PATH + 1] = { 0, }; @@ -3889,13 +3889,13 @@ static int emcore_get_body_part_imap(MAILSTREAM *stream, int account_id, int mai char *sparep = NULL; unsigned short encode = 0; int section_plain = 0; - int section_html = 0; + int section_html = 0; int is_pbd = (account_id == 0 && mail_id == 0) ? true : false; /* } is_pb */ EM_DEBUG_LOG("Grab Type [ %d ] ", cnt_info->grab_type); - /* unknown type */ + /* unknown type */ if (body->type > TYPEOTHER) { /* unknown type */ EM_DEBUG_EXCEPTION("Unknown type."); err = EMAIL_ERROR_NOT_SUPPORTED; @@ -3904,30 +3904,30 @@ static int emcore_get_body_part_imap(MAILSTREAM *stream, int account_id, int mai if (NULL == body->subtype) { EM_DEBUG_LOG("body->subtype is null. "); /* not exceptional case */ - if (err_code != NULL) + if (err_code != NULL) *err_code = EMAIL_ERROR_INVALID_PARAM; return FAILURE; } if (is_pbd) { if (!emcore_get_temp_file_name(&o_data, &err) || !o_data) { - EM_DEBUG_EXCEPTION("emcore_get_temp_file_name failed [%d]", err); - if (err_code != NULL) + EM_DEBUG_EXCEPTION("emcore_get_temp_file_name failed [%d]", err); + if (err_code != NULL) *err_code = err; return FAILURE; } - + if (body->subtype[0] == 'P') { /* Sub type is PLAIN_TEX */ if (cnt_info->text.plain != NULL) EM_SAFE_FREE(o_data); } - if (body->type == TYPETEXT && body->subtype && + if (body->type == TYPETEXT && body->subtype && (!body->disposition.type || (body->disposition.type && (body->disposition.type[0] == 'i' || body->disposition.type[0] == 'I')))) { if (body->subtype[0] == 'H') /* HTM */ cnt_info->text.html = o_data; - else + else cnt_info->text.plain = o_data; memset(charset_value_buffer, 0, 512); @@ -3949,7 +3949,7 @@ static int emcore_get_body_part_imap(MAILSTREAM *stream, int account_id, int mai EM_DEBUG_LOG("param1->attribute - %s ", param1->attribute); if (!strcasecmp(param1->attribute, "NAME")) { /* attribute is "NAME" */ char *extcheck = NULL; - + if (param1->value) { decoded_filename = emcore_decode_rfc2047_text(param1->value, &err); strncpy(filename, decoded_filename, MAX_PATH); @@ -3968,18 +3968,18 @@ static int emcore_get_body_part_imap(MAILSTREAM *stream, int account_id, int mai } else EM_DEBUG_EXCEPTION("UnKnown Extesnsion : _ ("); - + } - + break; } param1 = param1->next; } } - else if (body->disposition.type) { + else if (body->disposition.type) { PARAMETER *param = body->disposition.parameter; - + while (param) { EM_DEBUG_LOG(">>>>> body->disposition.parameter->attribute [ %s ] ", param->attribute); EM_DEBUG_LOG(">>>>> body->disposition.parameter->value [ %s ] ", param->value); @@ -3992,7 +3992,7 @@ static int emcore_get_body_part_imap(MAILSTREAM *stream, int account_id, int mai EM_DEBUG_LOG(">>>>> FILENAME [%s] ", filename); break; } - + param = param->next; } } @@ -4001,14 +4001,14 @@ static int emcore_get_body_part_imap(MAILSTREAM *stream, int account_id, int mai SNPRINTF(filename, MAX_PATH, "%s", body->id+1); else SNPRINTF(filename, MAX_PATH, "%s", body->id); - + len = EM_SAFE_STRLEN(filename); - + if ((len > 1) && (filename[len-1] == '>')) filename[len-1] = '\0'; } /* is_attachment = 1; */ - is_attachment = 0; + is_attachment = 0; } else if (body->location) { EM_DEBUG_LOG("body->location exist"); @@ -4017,7 +4017,7 @@ static int emcore_get_body_part_imap(MAILSTREAM *stream, int account_id, int mai strncpy(filename, decoded_filename, MAX_PATH); EM_SAFE_FREE(decoded_filename); EM_DEBUG_LOG("body->location [%s]", body->location); - } + } else if (is_pbd && (strncmp(body->subtype, "RFC822", strlen("RFC822")) == 0) && (cnt_info->grab_type == 0 || (cnt_info->grab_type & GRAB_TYPE_ATTACHMENT))) { EM_DEBUG_LOG("Beause subtype is RFC822. This is ttachment"); is_attachment = 1; @@ -4055,7 +4055,7 @@ static int emcore_get_body_part_imap(MAILSTREAM *stream, int account_id, int mai else continue; } - } + } } else strncpy(filename, "Unknown", MAX_PATH); @@ -4072,32 +4072,32 @@ static int emcore_get_body_part_imap(MAILSTREAM *stream, int account_id, int mai temp_body = &(part->body); } } - + if (temp_body) { - if (temp_body->subtype[0] == 'P') + if (temp_body->subtype[0] == 'P') section_plain = 1; else if (temp_body->subtype[0] == 'H') section_html = 1; - + sparep = temp_body->sparep; encode = temp_body->encoding; } - } + } } else if (body->disposition.type) /* if disposition exists, get filename from disposition parameter */ { /* "attachment" or "inline" or etc.. */ EM_DEBUG_LOG("body->disposition.type exist"); is_attachment = 1; - + if (emcore_get_attribute_value_of_body_part(body->disposition.parameter, "filename", filename, MAX_PATH, true, &err)) EM_DEBUG_LOG(">>>>> FILENAME [%s] ", filename); - + if (!*filename) { /* If the part has no filename, it may be report ms */ if ((body->disposition.type[0] == 'i' || body->disposition.type[0] == 'I') && body->parameter && body->parameter->attribute && strcasecmp(body->parameter->attribute, "NAME")) is_attachment = 0; else if (body->parameter) /* Fix for the MMS attachment File name as unknown */ { char *extcheck = NULL; - + if (emcore_get_attribute_value_of_body_part(body->parameter, "NAME", filename, MAX_PATH, true, &err)) EM_DEBUG_LOG("NAME [%s] ", filename); @@ -4123,11 +4123,11 @@ static int emcore_get_body_part_imap(MAILSTREAM *stream, int account_id, int mai } else { if ((body->disposition.type[0] == 'i' || body->disposition.type[0] == 'I')) - is_attachment = 0; + is_attachment = 0; } } - /* if (!is_pbd) */ { + /* if (!is_pbd) */ { EM_DEBUG_LOG("filename [%s]", filename); if (*filename) { decoded_filename = emcore_decode_rfc2047_text(filename, &err); @@ -4149,10 +4149,10 @@ static int emcore_get_body_part_imap(MAILSTREAM *stream, int account_id, int mai 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); + EM_DEBUG_EXCEPTION("emcore_get_temp_file_name failed [%d]", err); goto FINISH_OFF; } - + if (!imap_mail_write_body_to_file(stream, account_id, mail_id, 0, o_data, msg_uid, body->sparep, body->encoding, &o_data_len, body->subtype, &err)) { EM_DEBUG_EXCEPTION("imap_mail_write_body_to_file failed [%d]", err); if(err == EMAIL_ERROR_INVALID_STREAM) { @@ -4168,7 +4168,7 @@ 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') + if (body->subtype[0] == 'H') cnt_info->text.html = o_data; else { cnt_info->text.plain = o_data; @@ -4178,34 +4178,34 @@ static int emcore_get_body_part_imap(MAILSTREAM *stream, int account_id, int mai } break; case TYPEIMAGE: - case TYPEAPPLICATION: + case TYPEAPPLICATION: case TYPEAUDIO: case TYPEVIDEO: /* Inline Content - suspect of crash on partial body download */ if (!is_pbd) { EM_DEBUG_LOG("TYPEIMAGE or TYPEAPPLICATION : inline content"); ai = &(cnt_info->file); - + dec_len = body->size.bytes; - if ((cnt_info->grab_type & GRAB_TYPE_ATTACHMENT) && + if ((cnt_info->grab_type & GRAB_TYPE_ATTACHMENT) && (cnt_info->grab_type & GRAB_TYPE_TEXT)) { /* it is 'download all */ only_body_download = false; cnt_info->file_no = 1; } /* add attachment info to content info */ - if (!(*ai = em_malloc(sizeof(struct attachment_info)))) { - EM_DEBUG_EXCEPTION("em_malloc failed..."); - if (err_code != NULL) - *err_code = EMAIL_ERROR_OUT_OF_MEMORY; - return FAILURE; - } - + if (!(*ai = em_malloc(sizeof(struct attachment_info)))) { + EM_DEBUG_EXCEPTION("em_malloc failed..."); + if (err_code != NULL) + *err_code = EMAIL_ERROR_OUT_OF_MEMORY; + return FAILURE; + } + if (((body->id) || (body->location)) && body->type == TYPEIMAGE) (*ai)->type = 1; /* inline */ - else + else (*ai)->type = 2; /* attachment */ - + (*ai)->name = EM_SAFE_STRDUP(filename); (*ai)->size = body->size.bytes; (*ai)->save = o_data; @@ -4221,21 +4221,21 @@ static int emcore_get_body_part_imap(MAILSTREAM *stream, int account_id, int mai if (body->sparep) (*ai)->section = EM_SAFE_STRDUP(body->sparep); EM_DEBUG_LOG(" Encoding - %d Section No - %s ", (*ai)->encoding, (*ai)->section); -#endif - } +#endif + } break; case TYPEMESSAGE: /* RFC822 Message */ EM_DEBUG_EXCEPTION("MESSAGE/RFC822"); err = EMAIL_ERROR_NOT_SUPPORTED; goto FINISH_OFF; - - default: + + default: EM_DEBUG_EXCEPTION("Unknown type. body->type [%d]", body->type); err = EMAIL_ERROR_NOT_SUPPORTED; goto FINISH_OFF; } - + stream->text.data = NULL; /* ? ? ? ? ? ? ? ? */ } else { /* Attachment */ @@ -4261,10 +4261,10 @@ static int emcore_get_body_part_imap(MAILSTREAM *stream, int account_id, int mai prev_ai = (*ai); } } - + EM_DEBUG_LOG("i - %d next_ai - %p prev_ai - %p", i, next_ai, prev_ai); - - if ((cnt_info->grab_type & GRAB_TYPE_ATTACHMENT) && + + if ((cnt_info->grab_type & GRAB_TYPE_ATTACHMENT) && (cnt_info->grab_type & GRAB_TYPE_TEXT)) { /* it is 'download all */ EM_DEBUG_LOG("Download All"); only_body_download = false; @@ -4273,14 +4273,14 @@ 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("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 */ @@ -4291,7 +4291,7 @@ static int emcore_get_body_part_imap(MAILSTREAM *stream, int account_id, int mai if (only_body_download == false) { if (!emcore_get_temp_file_name(&savefile, &err)) { - EM_DEBUG_EXCEPTION("emcore_get_temp_file_name failed [%d]", err); + EM_DEBUG_EXCEPTION("emcore_get_temp_file_name failed [%d]", err); goto FINISH_OFF; } @@ -4304,7 +4304,7 @@ static int emcore_get_body_part_imap(MAILSTREAM *stream, int account_id, int mai } } - EM_DEBUG_LOG("attachment (dec) : %s %d bytes", filename, dec_len); + EM_DEBUG_LOG("attachment (dec) : %s %d bytes", filename, dec_len); /* add attachment info to content inf */ if (!(*ai = em_malloc(sizeof(struct attachment_info)))) { @@ -4332,7 +4332,7 @@ static int emcore_get_body_part_imap(MAILSTREAM *stream, int account_id, int mai (*ai)->size = dec_len; (*ai)->save = savefile; (*ai)->content_id = EM_SAFE_STRDUP(body->id); - + 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); @@ -4351,7 +4351,7 @@ static int emcore_get_body_part_imap(MAILSTREAM *stream, int account_id, int mai else if (!strcasecmp(body->subtype, MIME_SUBTYPE_DRM_DCF)) (*ai)->drm = EMAIL_ATTACHMENT_DRM_DCF; } - + /* All inline images information are stored at the end of list */ if ((*ai)->type != 1 && next_ai != NULL) { /* Means next_ai points to the inline attachment info structure */ @@ -4368,7 +4368,7 @@ static int emcore_get_body_part_imap(MAILSTREAM *stream, int account_id, int mai } ret = 0; -FINISH_OFF: +FINISH_OFF: if (err_code) *err_code = err; EM_DEBUG_FUNC_END("ret [%d]", ret); @@ -4380,11 +4380,11 @@ static int emcore_get_allnested_part(MAILSTREAM *stream, int account_id, int mai { EM_DEBUG_FUNC_BEGIN("stream[%p], msg_uid[%d], body[%p], cnt_info[%p], err_code[%p]", stream, msg_uid, body, cnt_info, err_code); PART *part_child = body->nested.part; - + while (part_child) { if (emcore_get_body(stream, account_id, mail_id, msg_uid, &part_child->body, cnt_info, err_code) < 0) return FAILURE; - + part_child = part_child->next; } @@ -4396,14 +4396,14 @@ static int emcore_get_allnested_part(MAILSTREAM *stream, int account_id, int mai static int emcore_get_alternative_multi_part(MAILSTREAM *stream, int account_id, int mail_id, int msg_uid, BODY *body, struct _m_content_info *cnt_info, int *err_code) { EM_DEBUG_FUNC_BEGIN("stream[%p], msg_uid[%d], body[%p], cnt_info[%p], err_code[%p]", stream, msg_uid, body, cnt_info, err_code); - + PART *part_child = body->nested.part; /* find the best sub part we can show */ while (part_child) { if (emcore_get_body(stream, account_id, mail_id, msg_uid, &part_child->body, cnt_info, err_code) < 0) return FAILURE; - + part_child = part_child->next; } EM_DEBUG_FUNC_END(); @@ -4425,7 +4425,7 @@ static int emcore_get_signed_multi_part(MAILSTREAM *stream, int account_id, int part_child = part_child->next; } - EM_DEBUG_FUNC_END(); + EM_DEBUG_FUNC_END(); return SUCCESS; } @@ -4453,15 +4453,15 @@ static int emcore_get_multi_part(MAILSTREAM *stream, int account_id, int mail_id case 'A': /* ALTERNATIVE */ EM_DEBUG_LOG("body->subtype[0] = ALTERNATIVE"); return emcore_get_alternative_multi_part(stream, account_id, mail_id, msg_uid, body, cnt_info, err_code); - + case 'S': /* SIGNED */ EM_DEBUG_LOG("body->subtype[0] = SIGNED"); return emcore_get_signed_multi_part(stream, account_id, mail_id, msg_uid, body, cnt_info, err_code); - + case 'E': /* ENCRYPTED */ EM_DEBUG_LOG("body->subtype[0] = ENCRYPTED"); return emcore_get_encrypted_multi_part(stream, account_id, mail_id, msg_uid, body, cnt_info, err_code); - + default: /* process all unknown as MIXED (according to the RFC 2047) */ EM_DEBUG_LOG("body->subtype[0] = [%c].", body->subtype[0]); return emcore_get_allnested_part(stream, account_id, mail_id, msg_uid, body, cnt_info, err_code); @@ -4474,28 +4474,28 @@ static int emcore_get_multi_part(MAILSTREAM *stream, int account_id, int mail_id 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) { EM_DEBUG_FUNC_BEGIN("stream[%p], msg_uid[%d], body[%p], cnt_info[%p], err_code[%p]", stream, msg_uid, body, cnt_info, err_code); - + if (!stream || !body || !cnt_info) { EM_DEBUG_EXCEPTION("Invalid parameter"); - + if (err_code != NULL) *err_code = EMAIL_ERROR_INVALID_PARAM; return FAILURE; } EM_DEBUG_LOG("body->type [%d]", body->type); - + switch (body->type) { - case TYPEMULTIPART: + case TYPEMULTIPART: return emcore_get_multi_part(stream, account_id, mail_id, msg_uid, body, cnt_info, err_code); - + case TYPEMESSAGE: /* not support */ if (strcasecmp(body->subtype, "RFC822") == 0) return emcore_get_body_part_imap(stream, account_id, mail_id, msg_uid, body, cnt_info, err_code); break; - + case TYPETEXT: - case TYPEAPPLICATION: + case TYPEAPPLICATION: case TYPEAUDIO: case TYPEIMAGE: case TYPEVIDEO: @@ -4503,8 +4503,8 @@ INTERNAL_FUNC int emcore_get_body(MAILSTREAM *stream, int account_id, int mail_i 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); - - default: + + default: break; } EM_DEBUG_FUNC_END(); @@ -4515,11 +4515,11 @@ INTERNAL_FUNC int emcore_get_body(MAILSTREAM *stream, int account_id, int mail_i INTERNAL_FUNC int emcore_get_body_structure(MAILSTREAM *stream, int msg_uid, BODY **body, int *err_code) { EM_DEBUG_FUNC_BEGIN("stream[%p], msg_uid[%d], body[%p], err_code[%p]", stream, msg_uid, body, err_code); - + EM_IF_NULL_RETURN_VALUE(stream, false); EM_IF_NULL_RETURN_VALUE(body, false); - -#ifdef __FEATURE_HEADER_OPTIMIZATION__ + +#ifdef __FEATURE_HEADER_OPTIMIZATION__ ENVELOPE *env = mail_fetch_structure(stream, msg_uid, body, FT_UID | FT_PEEK | FT_NOLOOKAHEAD, 1); #else ENVELOPE *env = mail_fetch_structure(stream, msg_uid, body, FT_UID | FT_PEEK | FT_NOLOOKAHEAD); @@ -4530,7 +4530,7 @@ INTERNAL_FUNC int emcore_get_body_structure(MAILSTREAM *stream, int msg_uid, BOD EM_DEBUG_EXCEPTION("mail_fetch_structure failed"); return FAILURE; } - + #ifdef FEATURE_CORE_DEBUG _print_body(*body, true); /* shasikala.p@partner.samsung.com */ #endif @@ -4551,14 +4551,14 @@ INTERNAL_FUNC int emcore_set_fetch_body_section(BODY *body, int enable_inline_li *err_code = EMAIL_ERROR_INVALID_PARAM; return FAILURE; } - + // body->id = cpystr("1"); /* top level body */ EM_DEBUG_LOG("body->id : [%s]", body->id); - + g_inline_count = 0; EM_SAFE_FREE(g_inline_list); emcore_set_fetch_part_section(body, (char *)NULL, 0, enable_inline_list, total_mail_size, err_code); - + if (body && body->id) EM_DEBUG_LOG(">>>>> FILE NAME [%s] ", body->id); else @@ -4572,10 +4572,10 @@ INTERNAL_FUNC int emcore_set_fetch_body_section(BODY *body, int enable_inline_li int emcore_set_fetch_part_section(BODY *body, char *section_pfx, int section_subno, int enable_inline_list, int *total_mail_size, int *err_code) { EM_DEBUG_FUNC_BEGIN("body[%p], section_pfx[%s], section_subno[%d], err_code[%p]", body, section_pfx, section_subno, err_code); - + PART *part = NULL; char section[64] = {0x00, }; - + /* multipart doesn't have a row to itself */ if (body->type == TYPEMULTIPART) { /* if not first time, extend prefix */ @@ -4591,11 +4591,11 @@ int emcore_set_fetch_part_section(BODY *body, char *section_pfx, int section_sub } else { if (!section_pfx) /* dummy prefix if top level */ - section_pfx = ""; + section_pfx = ""; SNPRINTF(section, sizeof(section), "%s%d", section_pfx, ++section_subno); - if (enable_inline_list && ((body->disposition.type && (body->disposition.type[0] == 'i' || body->disposition.type[0] == 'I')) || + if (enable_inline_list && ((body->disposition.type && (body->disposition.type[0] == 'i' || body->disposition.type[0] == 'I')) || (!body->disposition.type && body->id))) { BODY **temp = NULL; temp = realloc(g_inline_list, sizeof(BODY *) *(g_inline_count + 1)); @@ -4612,7 +4612,7 @@ int emcore_set_fetch_part_section(BODY *body, char *section_pfx, int section_sub EM_DEBUG_LOG("Update g_inline_list with inline count [%d]", g_inline_count); } - + /* if ((total_mail_size != NULL) && !(body->disposition.type && (body->disposition.type[0] == 'a' || body->disposition.type[0] == 'A')) */ if (total_mail_size != NULL) { *total_mail_size = *total_mail_size + (int)body->size.bytes; @@ -4632,7 +4632,7 @@ int emcore_set_fetch_part_section(BODY *body, char *section_pfx, int section_sub } else { /* set body section */ - if (body) + if (body) body->sparep = cpystr(section); } } @@ -4655,7 +4655,7 @@ static void parse_file_path_to_filename(char *src_string, char **out_string) do { prev2 = prev1; prev1 = token; - } while ((token = strtok_r(NULL , "/", &str))); + } while ((token = strtok_r(NULL , "/", &str))); *out_string = EM_SAFE_STRDUP(prev1); EM_SAFE_FREE(filepath); @@ -4681,7 +4681,7 @@ static char *emcore_decode_rfc2047_word(char *encoded_word, int *err_code) } strcpy(buffer, ""); - + /* encoding format : =?charset?encoding?encoded-text ?= */ /* charset : UTF-8, EUC-KR, ... */ /* encoding : b/B (BASE64), q/Q (QUOTED-PRINTABLE) */ @@ -4692,31 +4692,31 @@ static char *emcore_decode_rfc2047_word(char *encoded_word, int *err_code) start = strstr(current, "=?"); /* start of encoding */ end = strstr(current, "?="); /* end of encoding */ -#ifdef FEATURE_CORE_DEBUG +#ifdef FEATURE_CORE_DEBUG EM_DEBUG_LOG("current[%p][%s], start[%p][%s], end[%p][%s]", current, current, start, start, end, end); #endif if (start != NULL) { if (current != start) { /* copy the string between current and start to buffer */ strncat(buffer, current, start - current); current = start; -#ifdef FEATURE_CORE_DEBUG +#ifdef FEATURE_CORE_DEBUG EM_DEBUG_LOG("1 - Buffer[%s]", buffer); #endif } - + if (end) { /* decode text between start and end */ char *p = strstr(start, "?b?"); - + if (p || (p = strstr(start, "?B?"))) /* BASE64 */ base64_encoded = true; else { p = strstr(start, "?q?"); - + if (p || (p = strstr(start, "?Q?"))) /* QUOTED-PRINTABLE */ base64_encoded = false; else { EM_DEBUG_EXCEPTION("unknown encoding found..."); - + err = EMAIL_ERROR_UNKNOWN; goto FINISH_OFF; } @@ -4735,7 +4735,7 @@ static char *emcore_decode_rfc2047_word(char *encoded_word, int *err_code) } else { /* end flag is not found */ EM_DEBUG_EXCEPTION("emcore_decode_rfc2047_word decoding error : '?=' is not found..."); - + err = EMAIL_ERROR_UNKNOWN; goto FINISH_OFF; } @@ -4744,8 +4744,8 @@ static char *emcore_decode_rfc2047_word(char *encoded_word, int *err_code) encoded_text = g_strndup(p + 3, end - (p + 3)); } } - -#ifdef FEATURE_CORE_DEBUG + +#ifdef FEATURE_CORE_DEBUG EM_DEBUG_LOG("\t >>>>>>>>>>>>>>> CHARSET[%s]", charset); EM_DEBUG_LOG("\t >>>>>>>>>>>>>>> ENCODED_TEXT[%s]", encoded_text); #endif @@ -4760,16 +4760,16 @@ static char *emcore_decode_rfc2047_word(char *encoded_word, int *err_code) } else { g_strdelimit(encoded_text, "_", ' '); - + if (!(decoded_text = (char *)rfc822_qprint((unsigned char *)encoded_text, EM_SAFE_STRLEN(encoded_text), &len))) { EM_DEBUG_EXCEPTION("rfc822_base64 falied..."); goto FINISH_OFF; } } - + src.data = (unsigned char *)decoded_text; src.size = EM_SAFE_STRLEN(decoded_text); - + if (!utf8_text(&src, charset, &dst, 0)) { EM_DEBUG_EXCEPTION("utf8_text falied..."); if (src.data) @@ -4778,7 +4778,7 @@ static char *emcore_decode_rfc2047_word(char *encoded_word, int *err_code) if (dst.data) strncat(buffer, (char *)dst.data, dst.size); } -#ifdef FEATURE_CORE_DEBUG +#ifdef FEATURE_CORE_DEBUG EM_DEBUG_LOG("2 - Buffer[%s]", buffer); #endif @@ -4787,12 +4787,12 @@ static char *emcore_decode_rfc2047_word(char *encoded_word, int *err_code) EM_SAFE_FREE(dst.data); EM_SAFE_FREE(decoded_text); - + g_free(encoded_text); encoded_text = NULL; } if (charset != NULL) { - g_free(charset); + g_free(charset); charset = NULL; } @@ -4803,7 +4803,7 @@ static char *emcore_decode_rfc2047_word(char *encoded_word, int *err_code) length = EM_SAFE_STRLEN(start); strncat(buffer, start, length); current = start + length; -#ifdef FEATURE_CORE_DEBUG +#ifdef FEATURE_CORE_DEBUG EM_DEBUG_LOG("3 - Buffer[%s]", buffer); #endif } @@ -4813,7 +4813,7 @@ static char *emcore_decode_rfc2047_word(char *encoded_word, int *err_code) length = EM_SAFE_STRLEN(current); strncat(buffer, current, length); current = current + length; -#ifdef FEATURE_CORE_DEBUG +#ifdef FEATURE_CORE_DEBUG EM_DEBUG_LOG("4 - Buffer[%s]", buffer); #endif } @@ -4821,7 +4821,7 @@ static char *emcore_decode_rfc2047_word(char *encoded_word, int *err_code) decoded_word = EM_SAFE_STRDUP(buffer); -#ifdef FEATURE_CORE_DEBUG +#ifdef FEATURE_CORE_DEBUG EM_DEBUG_LOG(">>>>>>>>>>>>>>> DECODED_WORD[%s]", decoded_word); #endif @@ -4834,11 +4834,11 @@ FINISH_OFF: if (encoded_text != NULL) g_free(encoded_text); if (charset != NULL) - g_free(charset); - + g_free(charset); + if (err_code != NULL) *err_code = err; - + EM_DEBUG_FUNC_END(); return decoded_word; } @@ -4846,50 +4846,50 @@ FINISH_OFF: 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; - + if (!rfc2047_text) { EM_DEBUG_EXCEPTION("rfc2047_text[%p]", rfc2047_text); if (err_code != NULL) *err_code = EMAIL_ERROR_INVALID_PARAM; return NULL; } - + char *text = NULL; - + gchar **encoded_words = g_strsplit_set(rfc2047_text, " \t\r\n", -1); gchar **decoded_words = g_new0(char *, g_strv_length(encoded_words) + 1); - + /* EM_DEBUG_LOG("g_strv_length(encoded_words) [%d]", g_strv_length(encoded_words)); */ - + if (encoded_words != NULL) { int i = 0; - + while (encoded_words[i] != NULL) { if (!(decoded_words[i] = emcore_decode_rfc2047_word(encoded_words[i], &err))) { EM_DEBUG_EXCEPTION("emcore_decode_rfc2047_word falied [%d]", err); goto FINISH_OFF; } - + i++; } text = g_strjoinv(" ", decoded_words); } else text = EM_SAFE_STRDUP(rfc2047_text); - + #ifdef FEATURE_CORE_DEBUG EM_DEBUG_LOG(">>>>>>>>>>>>>>>>> TEXT[%s]", text); #endif /* FEATURE_CORE_DEBUG */ - + ret = true; - + FINISH_OFF: g_strfreev(decoded_words); g_strfreev(encoded_words); - + if (err_code != NULL) *err_code = err; EM_DEBUG_FUNC_END(); @@ -4919,7 +4919,7 @@ INTERNAL_FUNC int emcore_make_mail_data_from_mime_data(struct _m_mesg *mmsg, str if (!mmsg || !cnt_info || !output_mail_data || !output_attachment_data) { EM_DEBUG_EXCEPTION("Invalid parameter"); err = EMAIL_ERROR_INVALID_PARAM; - goto FINISH_OFF; + goto FINISH_OFF; } p_mail_data = (email_mail_data_t *)em_malloc(sizeof(email_mail_data_t)); @@ -4990,7 +4990,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); - EM_DEBUG_LOG("mail_data->file_path_plain [%s]", p_mail_data->file_path_plain); + EM_DEBUG_LOG("mail_data->file_path_plain [%s]", p_mail_data->file_path_plain); } if (cnt_info->text.html) { @@ -4998,7 +4998,7 @@ INTERNAL_FUNC int emcore_make_mail_data_from_mime_data(struct _m_mesg *mmsg, str EM_DEBUG_EXCEPTION("emstorage_create_dir failed [%d]", err); goto FINISH_OFF; } - + if (cnt_info->text.plain_charset != NULL) { SNPRINTF(html_body, MAX_PATH, "%s%s", cnt_info->text.plain_charset, HTML_EXTENSION_STRING); } @@ -5023,14 +5023,14 @@ INTERNAL_FUNC int emcore_make_mail_data_from_mime_data(struct _m_mesg *mmsg, str for (ai = cnt_info->file; ai; ai = ai->next, attachment_num++) {} EM_DEBUG_LOG("attachment_num : [%d]", attachment_num); - if (attachment_num > 0) { + if (attachment_num > 0) { attachment = (email_attachment_data_t *)em_malloc(sizeof(email_attachment_data_t) * attachment_num); if (attachment == NULL) { EM_DEBUG_EXCEPTION("em_malloc failed"); err = EMAIL_ERROR_OUT_OF_MEMORY; goto FINISH_OFF; } - + for (ai = cnt_info->file; ai; ai = ai->next, i++) { attachment[i].attachment_id = 0; attachment[i].attachment_size = ai->size; @@ -5113,7 +5113,7 @@ INTERNAL_FUNC int emcore_make_mail_data_from_mime_data(struct _m_mesg *mmsg, str FINISH_OFF: if (ret) { - if (output_mail_data) + if (output_mail_data) *output_mail_data = p_mail_data; if (output_attachment_data) @@ -5170,7 +5170,7 @@ INTERNAL_FUNC int emcore_parse_mime_file_to_mail(char *eml_file_path, email_mail mmsg = (struct _m_mesg *)em_malloc(sizeof(struct _m_mesg)); if (mmsg == NULL) { EM_DEBUG_EXCEPTION("em_malloc failed"); - err = EMAIL_ERROR_OUT_OF_MEMORY; + err = EMAIL_ERROR_OUT_OF_MEMORY; goto FINISH_OFF; } @@ -5188,7 +5188,7 @@ INTERNAL_FUNC int emcore_parse_mime_file_to_mail(char *eml_file_path, email_mail if (!mmsg->header->part_header) { EM_DEBUG_EXCEPTION("Invalid eml format"); - err = EMAIL_ERROR_INVALID_DATA; + err = EMAIL_ERROR_INVALID_DATA; goto FINISH_OFF; } @@ -5204,12 +5204,12 @@ INTERNAL_FUNC int emcore_parse_mime_file_to_mail(char *eml_file_path, email_mail } ret = true; - + FINISH_OFF: if (eml_fp) fclose(eml_fp); - + if (mmsg) emcore_mime_free_mime(mmsg); @@ -5260,10 +5260,10 @@ INTERNAL_FUNC int emcore_delete_parsed_data(email_mail_data_t *input_mail_data, ret = true; FINISH_OFF: - + if (err_code) *err_code = err; - + return ret; } @@ -5326,7 +5326,7 @@ INTERNAL_FUNC int emcore_get_mime_entity(char *mime_path, char **output_path, in EM_DEBUG_EXCEPTION("emcore_get_temp_file_name failed[%d]", err); goto FINISH_OFF; } - EM_DEBUG_LOG("mime_entity_path = %s", mime_entity_path); + EM_DEBUG_LOG("mime_entity_path = %s", mime_entity_path); fp_write = fopen(mime_entity_path, "w"); if (fp_write == NULL) { @@ -5345,7 +5345,7 @@ INTERNAL_FUNC int emcore_get_mime_entity(char *mime_path, char **output_path, in err = EMAIL_ERROR_INVALID_MAIL; break; } - + if (!strcmp(buf, boundary)) { search++; if (search == 1) { @@ -5386,17 +5386,17 @@ INTERNAL_FUNC int emcore_get_mime_entity(char *mime_path, char **output_path, in } fprintf(fp_write, "%s", p_mime_entity); - + ret = true; FINISH_OFF: if (fp_read) fclose(fp_read); - + if (fp_write) fclose(fp_write); - + if (mmsg) emcore_mime_free_mime(mmsg); @@ -5432,8 +5432,8 @@ int emcore_decode_body_text_from_file(FILE *stream, char *boundary_str, int enco /* if there boundary, this content is from current line to ending boundary */ memset(boundary, 0x00, BOUNDARY_LEN); memset(boundary_end, 0x00, BOUNDARY_LEN); - - SNPRINTF(boundary, BOUNDARY_LEN, "--%s%s", boundary_str, CRLF_STRING); + + SNPRINTF(boundary, BOUNDARY_LEN, "--%s%s", boundary_str, CRLF_STRING); SNPRINTF(boundary_end, BOUNDARY_LEN, "--%s%s", boundary_str, "--\r\n"); } @@ -5451,7 +5451,7 @@ 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 = 1; break; @@ -5465,7 +5465,7 @@ int emcore_decode_body_text_from_file(FILE *stream, char *boundary_str, int enco else if (!strcmp(buf, boundary_end)) { /* if ending boundary, the parsing of other multipart will be started */ *end_of_parsing = 1; break; - } + } } } @@ -5514,7 +5514,7 @@ int emcore_decode_body_text_from_file(FILE *stream, char *boundary_str, int enco if (write(fd, modified_body, modified_body_size) != modified_body_size) { EM_DEBUG_EXCEPTION("write failed"); error = EMAIL_ERROR_SYSTEM_FAILURE; - goto FINISH_OFF; + goto FINISH_OFF; } } } @@ -5545,8 +5545,8 @@ int emcore_decode_body_text_from_sock(void *stream, char *boundary_str, int enco /* if there boundary, this content is from current line to ending boundary */ memset(boundary, 0x00, BOUNDARY_LEN); memset(boundary_end, 0x00, BOUNDARY_LEN); - - SNPRINTF(boundary, BOUNDARY_LEN, "--%s%s", boundary_str, CRLF_STRING); + + SNPRINTF(boundary, BOUNDARY_LEN, "--%s%s", boundary_str, CRLF_STRING); SNPRINTF(boundary_end, BOUNDARY_LEN, "--%s%s", boundary_str, "--\r\n"); } @@ -5556,7 +5556,7 @@ int emcore_decode_body_text_from_sock(void *stream, char *boundary_str, int enco 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"); @@ -5565,14 +5565,14 @@ int emcore_decode_body_text_from_sock(void *stream, char *boundary_str, int enco } EM_DEBUG_LOG("This mail is partial body"); - + *end_of_parsing = 1; error = EMAIL_ERROR_NONE; - - break; - } - + + break; + } + if (boundary_str) { if (!strcmp(buf, boundary)) { /* the other part started. the parsing of other part will be started */ *end_of_parsing = 0; @@ -5581,7 +5581,7 @@ int emcore_decode_body_text_from_sock(void *stream, char *boundary_str, int enco else if (!strcmp(buf, boundary_end)) { /* if ending boundary, the parsing of other multipart will be started */ *end_of_parsing = 1; break; - } + } } /* parsing string started by '.' in POP3 */ @@ -5589,7 +5589,7 @@ int emcore_decode_body_text_from_sock(void *stream, char *boundary_str, int enco strncpy(buf, buf+1, MIME_LINE_LEN-1); buf[EM_SAFE_STRLEN(buf)] = NULL_CHAR; } - + if (encoding == ENCBASE64) { if (EM_SAFE_STRLEN(buf) >= 2) buf[EM_SAFE_STRLEN(buf)-2] = NULL_CHAR; @@ -5597,9 +5597,9 @@ int emcore_decode_body_text_from_sock(void *stream, char *boundary_str, int enco /* if (strcmp(buf, CRLF_STRING) == 0 */ /* continue */ } - + dec_len = EM_SAFE_STRLEN(buf); - + if (mode > SAVE_TYPE_SIZE) { /* decode content */ emcore_decode_body_text(buf, dec_len, encoding, &dec_len, &error); @@ -5622,22 +5622,22 @@ int emcore_decode_body_text_from_sock(void *stream, char *boundary_str, int enco EM_SAFE_FREE(*holder); EM_SAFE_FREE(result_buffer); - goto FINISH_OFF; + goto FINISH_OFF; } - else + else *holder = pTemp; - + memcpy(*holder + sz, result_buffer, result_buffer_size); (*holder)[sz + EM_SAFE_STRLEN(result_buffer) + 1] = NULL_CHAR; } else if (mode == SAVE_TYPE_FILE) { /* save content to file */ if (write(fd, result_buffer, result_buffer_size) != result_buffer_size) { EM_DEBUG_EXCEPTION("write failed"); error = EMAIL_ERROR_SYSTEM_FAILURE; - goto FINISH_OFF; + goto FINISH_OFF; } } - EM_SAFE_FREE(result_buffer); + EM_SAFE_FREE(result_buffer); } sz += dec_len; } diff --git a/email-core/email-core-mm-callbacks.c b/email-core/email-core-mm-callbacks.c index 042159a..e59c06c 100755 --- a/email-core/email-core-mm-callbacks.c +++ b/email-core/email-core-mm-callbacks.c @@ -1,7 +1,7 @@ /* * email-service * -* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> * diff --git a/email-core/email-core-signal.c b/email-core/email-core-signal.c index 1442096..50cb794 100755 --- a/email-core/email-core-signal.c +++ b/email-core/email-core-signal.c @@ -1,7 +1,7 @@ /*
* email-service
*
-* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
*
* Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com>
*
diff --git a/email-core/email-core-smime.c b/email-core/email-core-smime.c index 4d2c9ce..7783144 100755 --- a/email-core/email-core-smime.c +++ b/email-core/email-core-smime.c @@ -1,7 +1,7 @@ /* * email-service * -* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> * diff --git a/email-core/email-core-smtp.c b/email-core/email-core-smtp.c index f4e1f09..442eec9 100755 --- a/email-core/email-core-smtp.c +++ b/email-core/email-core-smtp.c @@ -1,10 +1,10 @@ /* * email-service * -* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* 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 @@ -38,7 +38,7 @@ #include "email-core-mail.h" #include "email-core-mime.h" #include "email-core-smime.h" -#include "email-core-account.h" +#include "email-core-account.h" #include "email-core-imap-mailbox.h" #include "email-core-mailbox-sync.h" #include "email-core-signal.h" @@ -75,13 +75,13 @@ extern long smtp_soutr_test(void *stream, char *s); void mail_send_notify(email_send_status_t status, int total, int sent, int account_id, int mail_id, int err_code) { EM_DEBUG_FUNC_BEGIN("status[%d], total[%d], sent[%d], account_id[%d], mail_id[%d], err_code[%d]", status, total, sent, account_id, mail_id, err_code); - + switch (status) { - case EMAIL_SEND_CONNECTION_FAIL: + case EMAIL_SEND_CONNECTION_FAIL: case EMAIL_SEND_FINISH: - case EMAIL_SEND_FAIL: + case EMAIL_SEND_FAIL: break; - + case EMAIL_SEND_PROGRESS: default: break; @@ -105,7 +105,7 @@ long buf_flush(void *stream, char *string) static char *emcore_find_img_tag(char *source_string) { EM_DEBUG_FUNC_BEGIN("source_string[%p]", source_string); - + int cur = 0, string_length; if (!source_string) return false; @@ -144,7 +144,7 @@ static char *emcore_replace_inline_image_path_with_content_id(char *source_strin goto FINISH_OFF; } - input_string = EM_SAFE_STRDUP(source_string); + input_string = EM_SAFE_STRDUP(source_string); cur_part = html_body->nested.part; @@ -185,7 +185,7 @@ FINISH_OFF: EM_SAFE_FREE(input_string); if (err_code) *err_code = err; - + EM_DEBUG_FUNC_END("ret[%s]", result_string); return result_string; } @@ -200,7 +200,7 @@ static int emcore_write_body(BODY *body, BODY *html_body, FILE *fp, int *err_cod char *replaced_string = NULL; int fd, nread, nwrite, error = EMAIL_ERROR_NONE; unsigned long len; - + file_path = body->sparep; if (!file_path || EM_SAFE_STRLEN(file_path) == 0) { @@ -213,18 +213,18 @@ static int emcore_write_body(BODY *body, BODY *html_body, FILE *fp, int *err_cod len = body->contents.text.size; break; } - - if (p) { + + if (p) { EM_DEBUG_LOG("p[%s]", p); fprintf(fp, "%s"CRLF_STRING CRLF_STRING, p); EM_SAFE_FREE(p); } - + EM_SAFE_FREE(body->sparep); EM_DEBUG_FUNC_END(); return true; } - + EM_DEBUG_LOG("Opening a file[%s]", file_path); fd = open(file_path, O_RDONLY); @@ -232,7 +232,7 @@ static int emcore_write_body(BODY *body, BODY *html_body, FILE *fp, int *err_cod EM_DEBUG_EXCEPTION("open(\"%s\") failed...", file_path); return false; } - + while (1) { memset(&buf, 0x00, RFC822_STRING_BUFFER_SIZE + 1); nread = read(fd, buf, (body->encoding == ENCBASE64 ? 57 : RFC822_READ_BLOCK_SIZE - 2)); @@ -247,7 +247,7 @@ static int emcore_write_body(BODY *body, BODY *html_body, FILE *fp, int *err_cod /* EM_DEBUG_LOG("body->type[%d], body->subtype[%c]", body->type, body->subtype[0]); */ - if (body->type == TYPETEXT && (body->subtype && (body->subtype[0] == 'H' || body->subtype[0] == 'h'))) { + if (body->type == TYPETEXT && (body->subtype && (body->subtype[0] == 'H' || body->subtype[0] == 'h'))) { EM_DEBUG_LOG("HTML Part"); img_tag_pos = emcore_find_img_tag(buf); @@ -276,8 +276,8 @@ static int emcore_write_body(BODY *body, BODY *html_body, FILE *fp, int *err_cod buf[len] = '\0'; break; } -// } - +// } + nwrite = fprintf(fp, "%s", (p ? p : buf)); if (nwrite != len) { fclose(fp); @@ -288,17 +288,17 @@ static int emcore_write_body(BODY *body, BODY *html_body, FILE *fp, int *err_cod } EM_SAFE_FREE(p); } - + if (body->encoding == ENCQUOTEDPRINTABLE || body->encoding == ENCBASE64) fprintf(fp, CRLF_STRING); - + fprintf(fp, CRLF_STRING); - + if (body->sparep) { free(body->sparep); body->sparep = NULL; } - + close(fd); EM_DEBUG_FUNC_END(); @@ -308,29 +308,29 @@ static int emcore_write_body(BODY *body, BODY *html_body, FILE *fp, int *err_cod static int emcore_write_rfc822_body(BODY *body, BODY *html_body, FILE *fp, int *err_code) { EM_DEBUG_FUNC_BEGIN("body[%p], html_body[%p], fp[%p], err_code[%p]", body, html_body, fp, err_code); - + PARAMETER *param = NULL; PART *part = NULL; char *p = NULL, *bndry = NULL, buf[1025]; int error = EMAIL_ERROR_NONE; - + switch (body->type) { case TYPEMULTIPART: EM_DEBUG_LOG("body->type = TYPEMULTIPART"); part = body->nested.part; - + for (param = body->parameter; param; param = param->next) { if (strcasecmp(param->attribute, "BOUNDARY") == 0) { bndry = param->value; break; } } - + do { p = buf; p[0] = '\0'; - + rfc822_write_body_header(&p, &part->body); - + fprintf(fp, "--%s"CRLF_STRING, bndry); if (body->subtype[0] == 'S' || body->subtype[0] == 's') { if (!emcore_write_body(body, html_body, fp, &error)) { @@ -344,10 +344,10 @@ static int emcore_write_rfc822_body(BODY *body, BODY *html_body, FILE *fp, int * emcore_write_rfc822_body(&part->body, html_body, fp, err_code); } while ((part = part->next)); - + fprintf(fp, "--%s--"CRLF_STRING, bndry); break; - + default: { EM_DEBUG_LOG("body->type is not TYPEMULTIPART"); @@ -355,7 +355,7 @@ static int emcore_write_rfc822_body(BODY *body, BODY *html_body, FILE *fp, int * EM_DEBUG_EXCEPTION("emcore_write_body failed : [%d]", error); return false; } - + break; } /* default: */ } @@ -366,50 +366,50 @@ static int emcore_write_rfc822_body(BODY *body, BODY *html_body, FILE *fp, int * static int emcore_write_rfc822(ENVELOPE *env, BODY *body, BODY *html_body, email_mail_priority_t input_priority, email_mail_report_t input_report_flag, char **data, int *err_code) { EM_DEBUG_FUNC_BEGIN("env[%p], body[%p], data[%p], err_code[%p]", env, body, data, err_code); - + int ret = false; int error = EMAIL_ERROR_NONE; - + FILE *fp = NULL; char *fname = NULL; char *p = NULL; size_t p_len = 0; - + if (!env || !data) { EM_DEBUG_EXCEPTION("Invalid Parameters"); error = 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; - + if (!(p = em_malloc(p_len))) { /* (env->subject ? EM_SAFE_STRLEN(env->subject) : 0) + 8192))) */ 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; - + /* rfc822_output_header(&buf, env, body, NIL, T); */ /* including BCC */ rfc822_output_header(&buf, env, body, NIL, NIL); /* Excluding BCC */ - + *buf.cur = '\0'; /* tie off buffer */ { gchar **tokens = g_strsplit(p, "CHARSET=X-UNKNOWN", 2); - + if (g_strv_length(tokens) > 1) { gchar *charset; @@ -426,24 +426,24 @@ static int emcore_write_rfc822(ENVELOPE *env, BODY *body, BODY *html_body, email } else EM_DEBUG_EXCEPTION("body->sparep is NULL"); - } - + } + g_strfreev(tokens); } { gchar **tokens = g_strsplit(p, "To: undisclosed recipients: ;\015\012", 2); - if (g_strv_length(tokens) > 1) + if (g_strv_length(tokens) > 1) SNPRINTF(p, p_len, "%s%s", tokens[0], tokens[1]); g_strfreev(tokens); } - + EM_DEBUG_LOG(" =============================================================================== " LF_STRING"%s"LF_STRING " =============================================================================== ", p); - if (EM_SAFE_STRLEN(p) > 2) + if (EM_SAFE_STRLEN(p) > 2) *(p + EM_SAFE_STRLEN(p) - 2) = '\0'; - + if (input_report_flag) { char buf[512] = {0x00, }; @@ -462,7 +462,7 @@ static int emcore_write_rfc822(ENVELOPE *env, BODY *body, BODY *html_body, email /* report-type= disposition-notification; */ /* boundary="----=_NextPart_000_004F_01C76EFF.54275C50" */ } - + if(input_report_flag & EMAIL_MAIL_REQUEST_MDN) { /* require read status */ rfc822_address(buf, env->from); @@ -470,10 +470,10 @@ static int emcore_write_rfc822(ENVELOPE *env, BODY *body, BODY *html_body, email SNPRINTF(p + EM_SAFE_STRLEN(p), p_len-(EM_SAFE_STRLEN(p)), "Disposition-Notification-To: %s"CRLF_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); - + 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); @@ -486,22 +486,22 @@ static int emcore_write_rfc822(ENVELOPE *env, BODY *body, BODY *html_body, email break; } } - + SNPRINTF(p + EM_SAFE_STRLEN(p), p_len-(EM_SAFE_STRLEN(p)), 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 (!(fp = fopen(fname, "w+"))) { EM_DEBUG_EXCEPTION("fopen failed[%s]", fname); error = EMAIL_ERROR_SYSTEM_FAILURE; goto FINISH_OFF; } - + fprintf(fp, "%s", p); - + if (body) { if (!emcore_write_rfc822_body(body, html_body, fp, &error)) { EM_DEBUG_EXCEPTION("emcore_write_rfc822_body failed[%d]", error); @@ -511,24 +511,24 @@ static int emcore_write_rfc822(ENVELOPE *env, BODY *body, BODY *html_body, email ret = true; - + FINISH_OFF: if (fp != NULL) fclose(fp); #ifdef USE_SYNC_LOG_FILE - emstorage_copy_file(fname, "/tmp/phone2pc.eml", false, NULL); + emstorage_copy_file(fname, "/tmp/phone2pc.eml", false, NULL); #endif - + if (ret == true) *data = fname; else if (fname != NULL) { remove(fname); EM_SAFE_FREE(fname); } - + EM_SAFE_FREE(p); - + if (err_code != NULL) *err_code = error; EM_DEBUG_FUNC_END(); @@ -538,7 +538,7 @@ FINISH_OFF: 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) { 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); - + 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, rule_matched = -1, local_attachment_count = 0, local_inline_content_count = 0; @@ -546,7 +546,7 @@ INTERNAL_FUNC int emcore_add_mail(email_mail_data_t *input_mail_data, email_atta char *ext = NULL; char name_buf[MAX_PATH] = {0x00, }; char *body_text_file_name = NULL; - + int attachment_count = 0; email_mail_data_t *mail_data = NULL; email_attachment_data_t *attachment_data_list = NULL; @@ -575,7 +575,7 @@ INTERNAL_FUNC int emcore_add_mail(email_mail_data_t *input_mail_data, email_atta err = EMAIL_ERROR_INVALID_ACCOUNT; goto FINISH_OFF; } - + if (input_from_eas == 0 && input_mail_data->smime_type && input_mail_data->mailbox_type != EMAIL_MAILBOX_TYPE_DRAFT) { if (!emcore_convert_mail_data_to_smime_data(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"); @@ -599,7 +599,7 @@ INTERNAL_FUNC int emcore_add_mail(email_mail_data_t *input_mail_data, email_atta goto FINISH_OFF; } } - + if (mail_data->file_path_html) { if (stat(mail_data->file_path_html, &st_buf) < 0) { EM_DEBUG_EXCEPTION("mail_data->file_path_html, stat(\"%s\") failed...", mail_data->file_path_html); @@ -607,20 +607,20 @@ INTERNAL_FUNC int emcore_add_mail(email_mail_data_t *input_mail_data, email_atta goto FINISH_OFF; } } - + if (attachment_count && attachment_data_list) { for (i = 0; i < attachment_count; i++) { if (attachment_data_list[i].save_status) { if (!attachment_data_list[i].attachment_path || stat(attachment_data_list[i].attachment_path, &st_buf) < 0) { EM_DEBUG_EXCEPTION("stat(\"%s\") failed...", attachment_data_list[i].attachment_path); - err = EMAIL_ERROR_INVALID_ATTACHMENT; + err = EMAIL_ERROR_INVALID_ATTACHMENT; goto FINISH_OFF; } } } } - if (!input_mail_data->full_address_from) + if (!input_mail_data->full_address_from) input_mail_data->full_address_from = EM_SAFE_STRDUP(account_tbl_item->user_email_address); /* check for email_address validation */ @@ -628,7 +628,7 @@ INTERNAL_FUNC int emcore_add_mail(email_mail_data_t *input_mail_data, email_atta 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 */ @@ -648,17 +648,17 @@ INTERNAL_FUNC int emcore_add_mail(email_mail_data_t *input_mail_data, email_atta else { /* For Spam handling */ 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) + + 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); } @@ -677,7 +677,7 @@ INTERNAL_FUNC int emcore_add_mail(email_mail_data_t *input_mail_data, email_atta if (rule_matched >= 0 && 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) { EM_DEBUG_EXCEPTION("emstorage_get_mailbox_by_id failed [%d]", err); goto FINISH_OFF; @@ -722,7 +722,7 @@ INTERNAL_FUNC int emcore_add_mail(email_mail_data_t *input_mail_data, email_atta EM_DEBUG_EXCEPTION("emstorage_get_save_name failed [%d]", err); goto FINISH_OFF; } - + if (!emstorage_move_file(mail_data->file_path_plain, name_buf, input_from_eas, &err)) { EM_DEBUG_EXCEPTION("emstorage_move_file failed [%d]", err); goto FINISH_OFF; @@ -751,7 +751,7 @@ INTERNAL_FUNC int emcore_add_mail(email_mail_data_t *input_mail_data, email_atta else 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)) { EM_DEBUG_EXCEPTION("emstorage_get_save_name failed [%d]", err); goto FINISH_OFF; @@ -772,21 +772,21 @@ 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("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)) { EM_DEBUG_EXCEPTION("emstorage_get_save_name failed [%d]", err); goto FINISH_OFF; } - + if (!emstorage_move_file(mail_data->file_path_mime_entity, name_buf, input_from_eas, &err)) { EM_DEBUG_EXCEPTION("emstorage_move_file failed [%d]", err); goto FINISH_OFF; } - + EM_SAFE_FREE(mail_data->file_path_mime_entity); mail_data->file_path_mime_entity = EM_SAFE_STRDUP(name_buf); } - + if (!mail_data->date_time) { /* time isn't set */ mail_data->date_time = time(NULL); @@ -823,7 +823,7 @@ INTERNAL_FUNC int emcore_add_mail(email_mail_data_t *input_mail_data, email_atta EM_DEBUG_EXCEPTION("em_convert_mail_data_to_mail_tbl failed [%d]", err); goto FINISH_OFF; } - + converted_mail_tbl->mailbox_id = mailbox_tbl->mailbox_id; converted_mail_tbl->mailbox_name = EM_SAFE_STRDUP(mailbox_tbl->mailbox_name); @@ -834,7 +834,7 @@ INTERNAL_FUNC int emcore_add_mail(email_mail_data_t *input_mail_data, email_atta if(mail_data->thread_id == 0) { if (emstorage_get_thread_id_of_thread_mails(converted_mail_tbl, &thread_id, &latest_mail_id_in_thread, &thread_item_count) != EMAIL_ERROR_NONE) EM_DEBUG_LOG(" emstorage_get_thread_id_of_thread_mails is failed"); - + if (thread_id == -1) { converted_mail_tbl->thread_id = mail_data->mail_id; converted_mail_tbl->thread_item_count = thread_item_count = 1; @@ -868,7 +868,7 @@ INTERNAL_FUNC int emcore_add_mail(email_mail_data_t *input_mail_data, email_atta if (!emstorage_update_latest_thread_mail(mail_data->account_id, converted_mail_tbl->thread_id, 0, 0, false, &err)) { EM_DEBUG_EXCEPTION("emstorage_update_latest_thread_mail failed [%d]", err); emstorage_rollback_transaction(NULL, NULL, NULL); - + goto FINISH_OFF; } } @@ -876,12 +876,12 @@ INTERNAL_FUNC int emcore_add_mail(email_mail_data_t *input_mail_data, email_atta /* Insert attachment information to DB */ for (i = 0; i < attachment_count; i++) { - if (attachment_data_list[i].attachment_size == 0) { + if (attachment_data_list[i].attachment_size == 0) { /* set attachment size */ - if(attachment_data_list[i].attachment_path && stat(attachment_data_list[i].attachment_path, &st_buf) < 0) + if(attachment_data_list[i].attachment_path && stat(attachment_data_list[i].attachment_path, &st_buf) < 0) attachment_data_list[i].attachment_size = st_buf.st_size; } - + if (!attachment_data_list[i].inline_content_status) { if (!emstorage_get_new_attachment_no(&attachment_id, &err)) { EM_DEBUG_EXCEPTION("emstorage_get_new_attachment_no failed [%d]", err); @@ -895,21 +895,21 @@ INTERNAL_FUNC int emcore_add_mail(email_mail_data_t *input_mail_data, email_atta emstorage_rollback_transaction(NULL, NULL, NULL); goto FINISH_OFF; } - + if (!emstorage_get_save_name(mail_data->account_id, mail_data->mail_id, attachment_data_list[i].inline_content_status ? 0 : attachment_id, attachment_data_list[i].attachment_name, name_buf, &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 (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 ((ext = strrchr(attachment_data_list[i].attachment_name, '.'))) { + + if ((ext = strrchr(attachment_data_list[i].attachment_name, '.'))) { if (!strncmp(ext, ".vcs", strlen(".vcs"))) remove(attachment_data_list[i].attachment_path); else if (!strncmp(ext, ".vcf", strlen(".vcf"))) @@ -933,7 +933,7 @@ INTERNAL_FUNC int emcore_add_mail(email_mail_data_t *input_mail_data, email_atta if (!emstorage_add_attachment(&attachment_tbl, 0, false, &err)) { EM_DEBUG_EXCEPTION("emstorage_add_attachment failed [%d]", err); emstorage_rollback_transaction(NULL, NULL, NULL); - + goto FINISH_OFF; } attachment_data_list[i].attachment_id = attachment_tbl.attachment_id; @@ -947,7 +947,7 @@ 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); - + goto FINISH_OFF; } } @@ -964,19 +964,19 @@ INTERNAL_FUNC int emcore_add_mail(email_mail_data_t *input_mail_data, email_atta err = EMAIL_ERROR_NONE; else EM_DEBUG_LOG("emcore_remove_overflowed_mails failed [%d]", err); - } + } } if ( input_from_eas && (mail_data->flags_seen_field == 0) - && mail_data->mailbox_type != EMAIL_MAILBOX_TYPE_TRASH - && mail_data->mailbox_type != EMAIL_MAILBOX_TYPE_SPAMBOX) { + && mail_data->mailbox_type != EMAIL_MAILBOX_TYPE_TRASH + && mail_data->mailbox_type != EMAIL_MAILBOX_TYPE_SPAMBOX) { if ((err = emcore_update_sync_status_of_account(mail_data->account_id, SET_TYPE_SET, SYNC_STATUS_SYNCING | SYNC_STATUS_HAVE_NEW_MAILS)) != EMAIL_ERROR_NONE) 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: + +FINISH_OFF: EM_SAFE_FREE(body_text_file_name); @@ -988,7 +988,7 @@ FINISH_OFF: if (converted_mail_tbl) emstorage_free_mail(&converted_mail_tbl, 1, NULL); - + EM_DEBUG_FUNC_END(); return err; } @@ -1134,7 +1134,7 @@ INTERNAL_FUNC int emcore_add_meeting_request(int account_id, int input_mailbox_i if (!meeting_req || meeting_req->mail_id <= 0) { if (meeting_req) EM_DEBUG_EXCEPTION("mail_id[%d]", meeting_req->mail_id); - + err = EMAIL_ERROR_INVALID_PARAM; goto FINISH_OFF; } @@ -1143,17 +1143,17 @@ INTERNAL_FUNC int emcore_add_meeting_request(int account_id, int input_mailbox_i EM_DEBUG_EXCEPTION(" emstorage_add_meeting_request failed [%d]", err); goto FINISH_OFF; - } + } ret = true; - -FINISH_OFF: - + +FINISH_OFF: + if (err_code) *err_code = err; EM_DEBUG_FUNC_END(); - return ret; + return ret; } /* send a mail */ @@ -1178,13 +1178,13 @@ INTERNAL_FUNC int emcore_send_mail(int account_id, int input_mailbox_id, int mai int sent_box = 0; emstorage_mailbox_tbl_t* local_mailbox = NULL; int dst_mailbox_id = 0; - + if (!account_id || !mail_id) { EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM"); err = EMAIL_ERROR_INVALID_PARAM; 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; @@ -1226,7 +1226,7 @@ INTERNAL_FUNC int emcore_send_mail(int account_id, int input_mailbox_id, int mai err = EMAIL_ERROR_CANCELLED; goto FINISH_OFF; } - + opt = &(ref_account->options); #ifdef __FEATURE_SUPPORT_VALIDATION_SYSTEM__ @@ -1238,19 +1238,19 @@ INTERNAL_FUNC int emcore_send_mail(int account_id, int input_mailbox_id, int mai #endif /* __FEATURE_SUPPORT_VALIDATION_SYSTEM__ */ /*Update status flag to DB*/ - + /* get rfc822 data */ if (!emcore_make_rfc822_file_from_mail(mail_tbl_data, attachment_tbl_data, attachment_tbl_count, &envelope, &fpath, opt, &err)) { EM_DEBUG_EXCEPTION("emcore_make_rfc822_file_from_mail failed [%d]", err); goto FINISH_OFF; } - + if (!envelope || (!envelope->to && !envelope->cc && !envelope->bcc)) { EM_DEBUG_EXCEPTION(" no recipients found..."); err = EMAIL_ERROR_NO_RECIPIENT; goto FINISH_OFF; } - + /* if there is no security option, unset security. */ if (!ref_account->outgoing_server_secure_connection) { stls = (sslstart_t)mail_parameters(NULL, GET_SSLSTART, NULL); @@ -1262,13 +1262,13 @@ INTERNAL_FUNC int emcore_send_mail(int account_id, int input_mailbox_id, int mai err = EMAIL_ERROR_CANCELLED; goto FINISH_OFF; } - + if (ref_account->pop_before_smtp != FALSE) { if (!emcore_connect_to_remote_mailbox(account_id, 0, (void **)&tmp_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; + err = EMAIL_ERROR_CANCELLED; goto FINISH_OFF; } } @@ -1284,14 +1284,13 @@ INTERNAL_FUNC int emcore_send_mail(int account_id, int input_mailbox_id, int mai 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; if (!emcore_check_send_mail_thread_status()) { @@ -1299,7 +1298,7 @@ INTERNAL_FUNC int emcore_send_mail(int account_id, int input_mailbox_id, int mai err = EMAIL_ERROR_CANCELLED; goto FINISH_OFF; } - + /* set request of delivery status. */ EM_DEBUG_LOG("opt->req_delivery_receipt [%d]", opt->req_delivery_receipt); EM_DEBUG_LOG("mail_tbl_data->report_status [%d]", mail_tbl_data->report_status); @@ -1311,7 +1310,7 @@ INTERNAL_FUNC int emcore_send_mail(int account_id, int input_mailbox_id, int mai stream->protocol.esmtp.dsn.notify.failure = 1; stream->protocol.esmtp.dsn.notify.success = 1; } - + mail_tbl_data->save_status = EMAIL_MAIL_STATUS_SENDING; /*Update status save_status to DB*/ @@ -1321,11 +1320,9 @@ INTERNAL_FUNC int emcore_send_mail(int account_id, int input_mailbox_id, int mai /* send mail to server. */ if (!emcore_send_mail_smtp(stream, envelope, fpath, account_id, mail_id, &err)) { EM_DEBUG_EXCEPTION(" emcore_send_mail_smtp failed [%d]", err); - #ifndef __FEATURE_MOVE_TO_OUTBOX_FIRST__ if (!emstorage_get_mailbox_by_mailbox_type(account_id, EMAIL_MAILBOX_TYPE_OUTBOX, &local_mailbox, false, &err)) { - EM_DEBUG_EXCEPTION(" emstorage_get_mailbox_by_mailbox_type failed [%d]", err); - + EM_DEBUG_EXCEPTION("emstorage_get_mailbox_by_mailbox_type failed [%d]", err); goto FINISH_OFF; } dst_mailbox_id = local_mailbox->mailbox_id; @@ -1336,10 +1333,10 @@ INTERNAL_FUNC int emcore_send_mail(int account_id, int input_mailbox_id, int mai /* unsent mail is moved to 'OUTBOX'. */ if (!emcore_move_mail(&mail_id, 1, dst_mailbox_id, EMAIL_MOVED_BY_COMMAND, 0, NULL)) EM_DEBUG_EXCEPTION(" emcore_mail_move falied..."); - goto FINISH_OFF; #endif + goto FINISH_OFF; } - + /* sent mail is moved to 'SENT' box or deleted. */ if (opt->keep_local_copy) { if (!emstorage_get_mailbox_by_mailbox_type(account_id, EMAIL_MAILBOX_TYPE_SENTBOX, &local_mailbox, true, &err)) { @@ -1350,13 +1347,13 @@ INTERNAL_FUNC int emcore_send_mail(int account_id, int input_mailbox_id, int mai if (!emcore_move_mail(&mail_id, 1, dst_mailbox_id, EMAIL_MOVED_AFTER_SENDING, 0, &err)) EM_DEBUG_EXCEPTION(" emcore_mail_move falied [%d]", err); -#ifdef __FEATURE_SYNC_CLIENT_TO_SERVER__ -#ifdef __FEATURE_LOCAL_ACTIVITY__ +#ifdef __FEATURE_SYNC_CLIENT_TO_SERVER__ +#ifdef __FEATURE_LOCAL_ACTIVITY__ else if (ref_account->incoming_server_type == EMAIL_SERVER_TYPE_IMAP4) /* To be synced to Sent box only IMAP not for POP */ { emstorage_activity_tbl_t new_activity; int activityid = 0; - + if (false == emcore_get_next_activity_id(&activityid, &err)) { EM_DEBUG_EXCEPTION(" emcore_get_next_activity_id Failed [%d] ", err); } @@ -1369,32 +1366,32 @@ INTERNAL_FUNC int emcore_send_mail(int account_id, int input_mailbox_id, int mai new_activity.activity_type = ACTIVITY_SAVEMAIL; new_activity.dest_mbox = NULL; new_activity.src_mbox = NULL; - + if (!emcore_add_activity(&new_activity, &err)) { EM_DEBUG_EXCEPTION(" emcore_add_activity Failed [%d] ", err); } - + if (!emcore_move_mail_on_server(dest_mbox.account_id, dst_mailbox_id, &mail_id, 1, dest_mbox.name, &err)) { EM_DEBUG_EXCEPTION(" emcore_move_mail_on_server falied [%d]", err); } else { /* Remove ACTIVITY_SAVEMAIL activity */ - new_activity.activity_id = activityid; + new_activity.activity_id = activityid; new_activity.activity_type = ACTIVITY_SAVEMAIL; new_activity.account_id = account_id; new_activity.mail_id = mail_id; new_activity.dest_mbox = NULL; new_activity.server_mailid = NULL; new_activity.src_mbox = NULL; - + if (!emcore_delete_activity(&new_activity, &err)) { EM_DEBUG_EXCEPTION(">>>>>>Local Activity [ACTIVITY_SAVEMAIL] [%d] ", err); } } - sent_box = 1; + sent_box = 1; } #endif -#endif +#endif /* On Successful Mail sent remove the Draft flag */ mail_tbl_data->flags_draft_field = 0; @@ -1402,7 +1399,7 @@ INTERNAL_FUNC int emcore_send_mail(int account_id, int input_mailbox_id, int mai if (!emstorage_set_field_of_mails_with_integer_value(account_id, &mail_id, 1, "flags_draft_field", mail_tbl_data->flags_draft_field, false, &err)) EM_DEBUG_EXCEPTION("Failed to modify extra flag [%d]", err); - sent_box = 1; + sent_box = 1; } else { if (!emcore_delete_mail(account_id, &mail_id, 1, EMAIL_DELETE_LOCALLY, EMAIL_DELETED_AFTER_SENDING, false, &err)) @@ -1423,8 +1420,8 @@ INTERNAL_FUNC int emcore_send_mail(int account_id, int input_mailbox_id, int mai EM_DEBUG_EXCEPTION(" emcore_delete_transaction_info_by_mailId failed for mail_id[%d]", mail_id); ret = true; - -FINISH_OFF: + +FINISH_OFF: if (ret == false && err != EMAIL_ERROR_INVALID_PARAM && mail_tbl_data) { if (err != EMAIL_ERROR_CANCELLED) { mail_tbl_data->save_status = EMAIL_MAIL_STATUS_SEND_FAILURE; @@ -1434,7 +1431,7 @@ FINISH_OFF: else { if (EMAIL_MAIL_STATUS_SEND_CANCELED == mail_tbl_data->save_status) EM_DEBUG_LOG("EMAIL_MAIL_STATUS_SEND_CANCELED Already set for "); - else { + else { mail_tbl_data->save_status = EMAIL_MAIL_STATUS_SEND_CANCELED; if (!emstorage_set_field_of_mails_with_integer_value(account_id, &mail_id, 1, "save_status", mail_tbl_data->save_status, false, &err2)) EM_DEBUG_EXCEPTION("emstorage_set_field_of_mails_with_integer_value failed [%d]", err2); @@ -1443,24 +1440,24 @@ FINISH_OFF: } #ifndef __FEATURE_KEEP_CONNECTION__ - if (stream) + if (stream) smtp_close(stream); #endif /* __FEATURE_KEEP_CONNECTION__ */ - if (stls) + if (stls) mail_parameters(NULL, SET_SSLSTART, (void *)stls); if (attachment_tbl_data) emstorage_free_attachment(&attachment_tbl_data, attachment_tbl_count, NULL); - if (envelope) + if (envelope) mail_free_envelope(&envelope); - + if (fpath) { EM_DEBUG_LOG("REMOVE TEMP FILE : %s", fpath); remove(fpath); free(fpath); } - + if(local_mailbox) emstorage_free_mailbox(&local_mailbox, 1, NULL); @@ -1481,7 +1478,7 @@ FINISH_OFF: #endif emcore_show_user_message(mail_id, EMAIL_ACTION_SEND_MAIL, err); } - + if (mail_tbl_data) emstorage_free_mail(&mail_tbl_data, 1, NULL); @@ -1496,7 +1493,7 @@ FINISH_OFF: INTERNAL_FUNC int emcore_send_saved_mail(int account_id, char *input_mailbox_name, int *err_code) { EM_DEBUG_FUNC_BEGIN("account_id[%d], input_mailbox_name[%p], err_code[%p]", account_id, input_mailbox_name, err_code); - + int ret = false; int err = EMAIL_ERROR_NONE; int status = EMAIL_SEND_FAIL; @@ -1522,18 +1519,18 @@ INTERNAL_FUNC int emcore_send_saved_mail(int account_id, char *input_mailbox_nam err = EMAIL_ERROR_INVALID_PARAM; 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; goto FINISH_OFF; } - + FINISH_OFF_IF_CANCELED; - + opt = &(ref_account->options); - + /* search mail. */ if (!emstorage_mail_search_start(NULL, account_id, input_mailbox_name, 0, &handle, &total, true, &err)) { EM_DEBUG_EXCEPTION("emstorage_mail_search_start failed [%d]", err); @@ -1560,12 +1557,12 @@ INTERNAL_FUNC int emcore_send_saved_mail(int account_id, char *input_mailbox_nam } handle = 0; - + mail_send_notify(EMAIL_SEND_PREPARE, 0, 0, account_id, mail_ids[total], err); for (i = 0; i < total; i++) { 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); goto FINISH_OFF; @@ -1592,14 +1589,14 @@ INTERNAL_FUNC int emcore_send_saved_mail(int account_id, char *input_mailbox_nam } searched_mail_tbl_data->save_status = EMAIL_MAIL_STATUS_SENDING; - + if (!emcore_make_rfc822_file_from_mail(searched_mail_tbl_data, attachment_tbl_data, attachment_tbl_count, &envelope, &fpath, opt, &err)) { EM_DEBUG_EXCEPTION("emcore_make_rfc822_file_from_mail falied [%d]", err); goto FINISH_OFF; } - + FINISH_OFF_IF_CANCELED; - + /* connect mail server. */ if (!stream) { /* if there no security option, unset security. */ @@ -1614,68 +1611,68 @@ INTERNAL_FUNC int emcore_send_saved_mail(int account_id, char *input_mailbox_nam if (err == EMAIL_ERROR_CONNECTION_BROKEN) err = EMAIL_ERROR_CANCELLED; - + status = EMAIL_SEND_CONNECTION_FAIL; goto FINISH_OFF; } - + stream = (SENDSTREAM *)tmp_stream; - + FINISH_OFF_IF_CANCELED; - + mail_send_notify(EMAIL_SEND_CONNECTION_SUCCEED, 0, 0, account_id, mail_ids[i], err); - + /* reqest of delivery status. */ - if (opt && opt->req_delivery_receipt == EMAIL_OPTION_REQ_DELIVERY_RECEIPT_ON) { + if (opt && opt->req_delivery_receipt == EMAIL_OPTION_REQ_DELIVERY_RECEIPT_ON) { stream->protocol.esmtp.dsn.want = 1; stream->protocol.esmtp.dsn.full = 0; stream->protocol.esmtp.dsn.notify.failure = 1; stream->protocol.esmtp.dsn.notify.success = 1; } - + mail_send_notify(EMAIL_SEND_START, 0, 0, account_id, mail_ids[i], err); } - + searched_mail_tbl_data->save_status = EMAIL_MAIL_STATUS_SENDING; - + /* update mail status to sending. */ if (!emstorage_change_mail_field(mail_ids[i], UPDATE_EXTRA_FLAG, searched_mail_tbl_data, true, &err)) { EM_DEBUG_EXCEPTION("emstorage_change_mail_field failed [%d]", err); - + goto FINISH_OFF; } - + if (!emcore_send_mail_smtp(stream, envelope, fpath, account_id, mail_ids[i], &err)) { EM_DEBUG_EXCEPTION("emcore_send_mail_smtp failed [%d]", err); - + searched_mail_tbl_data->save_status = EMAIL_MAIL_STATUS_SEND_FAILURE; - + /* update mail status to failure. */ if (!emstorage_change_mail_field(mail_ids[i], UPDATE_EXTRA_FLAG, searched_mail_tbl_data, true, &err)) EM_DEBUG_EXCEPTION("emstorage_change_mail_field failed [%d]", err); - + if (!emstorage_get_mailbox_by_mailbox_type(account_id, EMAIL_MAILBOX_TYPE_OUTBOX, &local_mailbox, true, &err)) { EM_DEBUG_EXCEPTION("emstorage_get_mailbox_by_mailbox_type failed [%d]", err); goto FINISH_OFF; } dst_mailbox_id = local_mailbox->mailbox_id; - + emcore_move_mail(&mail_ids[i], 1, dst_mailbox_id, EMAIL_MOVED_AFTER_SENDING, 0, NULL); - + if(local_mailbox) emstorage_free_mailbox(&local_mailbox, 1, NULL); goto FINISH_OFF; } - + searched_mail_tbl_data->save_status = EMAIL_MAIL_STATUS_SENT; - + /* update mail status to sent mail. */ if (!emstorage_change_mail_field(mail_ids[i], UPDATE_EXTRA_FLAG, searched_mail_tbl_data, true, &err)) { EM_DEBUG_EXCEPTION("emstorage_change_mail_field failed [%d]", err); goto FINISH_OFF; } - + /* sent mail is moved to 'SENT' box or deleted. */ if (opt->keep_local_copy) { if (!emstorage_get_mailbox_by_mailbox_type(account_id, EMAIL_MAILBOX_TYPE_SENTBOX, &local_mailbox, true, &err)) { @@ -1683,7 +1680,7 @@ INTERNAL_FUNC int emcore_send_saved_mail(int account_id, char *input_mailbox_nam goto FINISH_OFF; } dst_mailbox_id = local_mailbox->mailbox_id; - + if (!emcore_move_mail(&mail_ids[i], 1, dst_mailbox_id, EMAIL_MOVED_AFTER_SENDING, 0, &err)) EM_DEBUG_EXCEPTION("emcore_mail_move falied [%d]", err); @@ -1699,7 +1696,7 @@ INTERNAL_FUNC int emcore_send_saved_mail(int account_id, char *input_mailbox_nam if ((err = emcore_set_sent_contacts_log(searched_mail_tbl_data)) != EMAIL_ERROR_NONE) { EM_DEBUG_EXCEPTION("emcore_set_sent_contacts_log failed : [%d]", err); } - + if(searched_mail_tbl_data) { emstorage_free_mail(&searched_mail_tbl_data, 1, NULL); searched_mail_tbl_data = NULL; @@ -1709,24 +1706,24 @@ INTERNAL_FUNC int emcore_send_saved_mail(int account_id, char *input_mailbox_nam emstorage_free_attachment(&attachment_tbl_data, attachment_tbl_count, NULL); mail_free_envelope(&envelope); envelope = NULL; - + if (fpath) { remove(fpath); EM_SAFE_FREE(fpath); } } - - + + ret = true; -FINISH_OFF: - if (stream) +FINISH_OFF: + if (stream) smtp_close(stream); - if (stls) + if (stls) mail_parameters(NIL, SET_SSLSTART, (void *)stls); - if (envelope) + if (envelope) mail_free_envelope(&envelope); if (handle) { @@ -1748,7 +1745,7 @@ FINISH_OFF: if(local_mailbox) emstorage_free_mailbox(&local_mailbox, 1, NULL); - if (ret == true) + if (ret == true) mail_send_notify(EMAIL_SEND_FINISH, 0, 0, account_id, mail_ids[total], err); else { if(mail_ids) /* prevent 34385 */ @@ -1757,18 +1754,18 @@ FINISH_OFF: } EM_SAFE_FREE(mail_ids); - + if (err_code != NULL) *err_code = err; - + return ret; -} +} static int emcore_send_mail_smtp(SENDSTREAM *stream, ENVELOPE *env, char *data_file, int account_id, int mail_id, int *err_code) { EM_DEBUG_FUNC_BEGIN("stream[%p], env[%p], data_file[%s], account_id[%d], mail_id[%d], err_code[%p]", stream, env, data_file, account_id, mail_id, err_code); EM_PROFILE_BEGIN(profile_emcore_send_mail_smtp); - + int ret = false; int err = EMAIL_ERROR_NONE; int recipients = 0; @@ -1776,20 +1773,20 @@ static int emcore_send_mail_smtp(SENDSTREAM *stream, ENVELOPE *env, char *data_f char buf[2048] = { 0, }; email_account_t *ref_account = NULL; FILE *fp = NULL; - + if (!env || !env->from || (!env->to && !env->cc && !env->bcc)) { if (env != NULL) EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM"); err = EMAIL_ERROR_INVALID_PARAM; goto FINISH_OFF; } - + if (!env->from->mailbox || !env->from->host) { EM_DEBUG_EXCEPTION("env->from->mailbox[%p], env->from->host[%p]", env->from->mailbox, env->from->host); err = EMAIL_ERROR_INVALID_PARAM; 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; @@ -1803,56 +1800,60 @@ static int emcore_send_mail_smtp(SENDSTREAM *stream, ENVELOPE *env, char *data_f } else SNPRINTF(buf, sizeof(buf), "FROM:<%s>", ref_account->user_email_address); - + /* set DSN for ESMTP */ if (stream->protocol.esmtp.ok) { if (stream->protocol.esmtp.eightbit.ok && stream->protocol.esmtp.eightbit.want) strncat (buf, " BODY=8BITMIME", sizeof(buf)-(EM_SAFE_STRLEN(buf)+1)); EM_DEBUG_LOG("stream->protocol.esmtp.dsn.ok [%d]", stream->protocol.esmtp.dsn.ok); - + if (stream->protocol.esmtp.dsn.ok && stream->protocol.esmtp.dsn.want) { EM_DEBUG_LOG("stream->protocol.esmtp.dsn.want is required"); strncat (buf, stream->protocol.esmtp.dsn.full ? " RET=FULL" : " RET=HDRS", sizeof(buf)-EM_SAFE_STRLEN(buf)-1); - if (stream->protocol.esmtp.dsn.envid) + if (stream->protocol.esmtp.dsn.envid) SNPRINTF (buf + EM_SAFE_STRLEN (buf), sizeof(buf)-(EM_SAFE_STRLEN(buf)), " ENVID=%.100s", stream->protocol.esmtp.dsn.envid); } else EM_DEBUG_LOG("stream->protocol.esmtp.dsn.want is not required or DSN is not supported"); } - + EM_PROFILE_BEGIN(profile_prepare_and_head); send_ret = smtp_send(stream, "RSET", 0); EM_DEBUG_LOG("[SMTP] RSET --------> %s", stream->reply); - + if (send_ret != SMTP_RESPONSE_OK) { err = send_ret; goto FINISH_OFF; } - + send_ret = smtp_send(stream, "MAIL", buf); EM_DEBUG_LOG("[SMTP] MAIL %s --------> %s", buf, stream->reply); - + switch (send_ret) { case SMTP_RESPONSE_OK: break; - + case SMTP_RESPONSE_WANT_AUTH : case SMTP_RESPONSE_WANT_AUTH2: EM_DEBUG_EXCEPTION("SMTP error : authentication required..."); err = EMAIL_ERROR_AUTH_REQUIRED; goto FINISH_OFF; - + case SMTP_RESPONSE_UNAVAIL: EM_DEBUG_EXCEPTION("SMTP error : sending unavailable..."); err = EMAIL_ERROR_SMTP_SEND_FAILURE; goto FINISH_OFF; - - default: - err = send_ret; + case SMTP_RESPONSE_CONNECTION_BROKEN: + EM_DEBUG_EXCEPTION("SMTP error : SMTP connection broken..."); + err = EMAIL_ERROR_SMTP_SEND_FAILURE; + goto FINISH_OFF; + default: + EM_DEBUG_EXCEPTION("SMTP error : sending unavailable..."); + err = EMAIL_ERROR_SMTP_SEND_FAILURE; goto FINISH_OFF; } - + if (env->to) { send_ret = smtp_rcpt(stream, env->to, &send_err); EM_DEBUG_LOG("[SMTP] RCPT TO : <%s@%s> ... --------> %s", env->to->mailbox, env->to->host, env->to->error ? env->to->error : stream->reply); @@ -1860,11 +1861,11 @@ static int emcore_send_mail_smtp(SENDSTREAM *stream, ENVELOPE *env, char *data_f err = stream->replycode; goto FINISH_OFF; } - + if (!send_err) recipients++; } - + if (env->cc) { send_ret = smtp_rcpt(stream, env->cc, &send_err); EM_DEBUG_LOG("[SMTP] RCPT TO : <%s@%s> ... --------> %s", env->cc->mailbox, env->cc->host, env->cc->error ? env->cc->error : stream->reply); @@ -1872,11 +1873,11 @@ static int emcore_send_mail_smtp(SENDSTREAM *stream, ENVELOPE *env, char *data_f err = stream->replycode; goto FINISH_OFF; } - + if (!send_err) recipients++; } - + if (env->bcc) { send_ret = smtp_rcpt(stream, env->bcc, &send_err); EM_DEBUG_LOG("[SMTP] RCPT TO : <%s@%s> ... --------> %s", env->bcc->mailbox, env->bcc->host, env->bcc->error ? env->bcc->error : stream->reply); @@ -1884,43 +1885,43 @@ static int emcore_send_mail_smtp(SENDSTREAM *stream, ENVELOPE *env, char *data_f err = stream->replycode; goto FINISH_OFF; } - + if (!send_err) recipients++; } - - + + if (send_err) { EM_DEBUG_EXCEPTION("One or more recipients failed..."); err = EMAIL_ERROR_INVALID_ADDRESS; } - + if (!recipients) { EM_DEBUG_EXCEPTION("No valid recipients..."); - + switch (stream->replycode) { - case SMTP_RESPONSE_UNAVAIL: - case SMTP_RESPONSE_WANT_AUTH : - case SMTP_RESPONSE_WANT_AUTH2: + case SMTP_RESPONSE_UNAVAIL: + case SMTP_RESPONSE_WANT_AUTH : + case SMTP_RESPONSE_WANT_AUTH2: err = EMAIL_ERROR_AUTH_REQUIRED; break; - - default: + + default: err = EMAIL_ERROR_INVALID_ADDRESS; break; } goto FINISH_OFF; } - + send_ret = smtp_send(stream, "DATA", 0); EM_DEBUG_LOG("[SMTP] DATA --------> %s", stream->reply); - EM_PROFILE_END(profile_prepare_and_head); + EM_PROFILE_END(profile_prepare_and_head); if (send_ret != SMTP_RESPONSE_READY) { err = send_ret; goto FINISH_OFF; } - + if (data_file) { EM_PROFILE_BEGIN(profile_open_file); if (!(fp = fopen(data_file, "r+"))) { @@ -1929,13 +1930,13 @@ static int emcore_send_mail_smtp(SENDSTREAM *stream, ENVELOPE *env, char *data_f goto FINISH_OFF; } EM_PROFILE_END(profile_open_file); - -#ifdef __FEATURE_SEND_OPTMIZATION__ + +#ifdef __FEATURE_SEND_OPTMIZATION__ { char *data = NULL; int read_size, allocSize, dataSize, gMaxAllocSize = 40960; /* 40KB */ - + fseek(fp, 0, SEEK_END); total = ftell(fp); fseek(fp, 0, SEEK_SET); @@ -1948,7 +1949,7 @@ static int emcore_send_mail_smtp(SENDSTREAM *stream, ENVELOPE *env, char *data_f EM_PROFILE_BEGIN(profile_allocation); /* Allocate a buffer of max 2MB to read from file */ - data = (char *)em_malloc(allocSize); + data = (char *)em_malloc(allocSize); allocSize--; EM_PROFILE_END(profile_allocation); @@ -1962,11 +1963,11 @@ static int emcore_send_mail_smtp(SENDSTREAM *stream, ENVELOPE *env, char *data_f dataSize = total; else dataSize = allocSize; - + memset(data, 0x0, dataSize+1); read_size = fread(data, sizeof (char), dataSize, fp); - - if (read_size != dataSize) { + + if (read_size != dataSize) { /* read fail. */ EM_SAFE_FREE(data); EM_DEBUG_EXCEPTION("Read from file failed"); @@ -1981,7 +1982,7 @@ static int emcore_send_mail_smtp(SENDSTREAM *stream, ENVELOPE *env, char *data_f EM_DEBUG_EXCEPTION("Failed to send the data "); err = EMAIL_ERROR_SMTP_SEND_FAILURE; goto FINISH_OFF; - } + } else { sent_percent = (int) ((double)sent / (double)total * 100.0); if (last_sent_percent + 5 <= sent_percent) { @@ -2000,14 +2001,14 @@ static int emcore_send_mail_smtp(SENDSTREAM *stream, ENVELOPE *env, char *data_f fseek(fp, 0, SEEK_END); total = ftell(fp); fseek(fp, 0, SEEK_SET); - + while (fgets(buf, 1024, fp)) { #ifdef FEATURE_SEND_DATA_DEBUG EM_DEBUG_LOG("%s", buf); #endif sent += EM_SAFE_STRLEN(buf); - - if (!(send_ret = smtp_soutr(stream->netstream, buf))) + + if (!(send_ret = smtp_soutr(stream->netstream, buf))) break; /* Sending Progress Notification */ sent_percent = (int) ((double)sent / (double)total * 100.0); @@ -2019,7 +2020,7 @@ static int emcore_send_mail_smtp(SENDSTREAM *stream, ENVELOPE *env, char *data_f last_sent_percent = sent_percent; } } - + #endif if (!send_ret) { EM_DEBUG_EXCEPTION("smtp_soutr failed - %ld", send_ret); @@ -2027,26 +2028,26 @@ static int emcore_send_mail_smtp(SENDSTREAM *stream, ENVELOPE *env, char *data_f goto FINISH_OFF; } } - + send_ret = smtp_send(stream, ".", 0); EM_DEBUG_LOG("[SMTP] . --------> %s", stream->reply); - + if (send_ret != SMTP_RESPONSE_OK) { err = send_ret; goto FINISH_OFF; } - + ret = true; - -FINISH_OFF: + +FINISH_OFF: if (ret == false) smtp_send(stream, "RSET", 0); - + if (err_code) *err_code = err; - + if (fp) - fclose(fp); + fclose(fp); EM_PROFILE_END(profile_emcore_send_mail_smtp); EM_DEBUG_FUNC_END("ret [%d]", ret); return ret; @@ -2065,7 +2066,7 @@ char *emcore_generate_content_id_string(const char *hostname, int *err) *err = EMAIL_ERROR_INVALID_PARAM; return NULL; } - + int cid_length = RANDOM_NUMBER_LENGTH + EM_SAFE_STRLEN(hostname) + 2, random_number_1, random_number_2, random_number_3, random_number_4; char *cid_string = NULL; @@ -2086,7 +2087,7 @@ char *emcore_generate_content_id_string(const char *hostname, int *err) random_number_4 = rand() * rand(); SNPRINTF(cid_string, cid_length, "<%08x%08x%08x%08x@%s>", random_number_1, random_number_2, random_number_3, random_number_4, hostname); - + if (err) *err = EMAIL_ERROR_NONE; @@ -2103,7 +2104,7 @@ char *emcore_generate_content_id_string(const char *hostname, int *err) static int attach_part(BODY *body, const unsigned char *data, int data_len, char *filename, char *content_sub_type, int is_inline, int *err_code) { EM_DEBUG_FUNC_BEGIN("body[%p], data[%s], data_len[%d], filename[%s], content_sub_type[%s], err_code[%p]", body, data, data_len, filename, content_sub_type, err_code); - + int ret = false; int error = EMAIL_ERROR_NONE; int has_special_character = 0; @@ -2123,22 +2124,22 @@ static int attach_part(BODY *body, const unsigned char *data, int data_len, char SIZEDTEXT source_text; GError *glib_error = NULL; CHARSET *result_charset = NULL; - + if (!body) { EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM"); error = EMAIL_ERROR_INVALID_PARAM; goto FINISH_OFF; } - + if (body->nested.part) { last_part = body->nested.part; - + if (last_part != NULL) { while (last_part->next) last_part = last_part->next; } } - + /* PART */ part = mail_newbody_part(); if (part == NULL) { @@ -2146,26 +2147,26 @@ static int attach_part(BODY *body, const unsigned char *data, int data_len, char error = EMAIL_ERROR_OUT_OF_MEMORY; goto FINISH_OFF; } - + part->next = NULL; - - if (last_part) + + if (last_part) last_part->next = part; - else + else body->nested.part = part; - + last_part = part; - + /* set data.. */ /* content_data = (unsigned char *)fs_get(data_len + 1); */ /* memcpy(content_data, data, data_len); */ /* content_data[data_len] = 0; */ - + /* part->body.contents.text.data = content_data; */ /* part->body.contents.text.size = data_len; */ - + if (filename) { /* attachment */ - source_text.data = (unsigned char*)filename; + source_text.data = (unsigned char*)filename; source_text.size = EM_SAFE_STRLEN(filename); result_charset = (CHARSET*)utf8_infercharset(&source_text); @@ -2186,7 +2187,7 @@ static int attach_part(BODY *body, const unsigned char *data, int data_len, char if(has_special_character) encoded_file_name = (char*)g_convert (filename, -1, "UTF-8", "EUC-KR", &bytes_read, &bytes_written, &glib_error); } - + EM_DEBUG_LOG("encoded_file_name [%s]", encoded_file_name); if(encoded_file_name == NULL) @@ -2196,11 +2197,11 @@ static int attach_part(BODY *body, const unsigned char *data, int data_len, char EM_DEBUG_EXCEPTION("em_encode_base64 failed. error [%d]", error); goto FINISH_OFF; } - + result_file_name = em_replace_string(base64_file_name, "\015\012", ""); - + EM_DEBUG_LOG("base64_file_name_length [%d]", base64_file_name_length); - + if(result_file_name) { EM_SAFE_FREE(encoded_file_name); encoded_file_name = em_malloc(EM_SAFE_STRLEN(result_file_name) + 15); @@ -2232,12 +2233,12 @@ static int attach_part(BODY *body, const unsigned char *data, int data_len, char if (data) part->body.sparep = EM_SAFE_STRDUP((char *)data); /* file path */ else - part->body.sparep = NULL; - + part->body.sparep = NULL; + SNPRINTF(content_disposition, sizeof(content_disposition), "%s", "attachment"); - + part->body.disposition.type = cpystr(content_disposition); - + /* BODY PARAMETER */ /* another parameter or get parameter-list from this function-parameter */ param = mail_newbody_parameter(); @@ -2246,16 +2247,16 @@ static int attach_part(BODY *body, const unsigned char *data, int data_len, char error = EMAIL_ERROR_OUT_OF_MEMORY; goto FINISH_OFF; } - + param->attribute = cpystr("name"); param->value = cpystr(encoded_file_name); param->next = NULL; last_param = param; last_part->body.parameter = last_param; - if (is_inline) { + if (is_inline) { /* CONTENT-ID */ - part->body.id = emcore_generate_content_id_string("org.tizen.slp.email", &error); + part->body.id = emcore_generate_content_id_string("com.samsung.slp.email", &error); part->body.type = TYPEIMAGE; /* EM_SAFE_FREE(part->body.subtype); */ /* part->body.subtype = EM_SAFE_STRDUP(content_sub_type); */ @@ -2268,17 +2269,17 @@ static int attach_part(BODY *body, const unsigned char *data, int data_len, char error = EMAIL_ERROR_OUT_OF_MEMORY; goto FINISH_OFF; } - + param->attribute = cpystr("filename"); param->value = cpystr(encoded_file_name); param->next = NULL; last_param = param; last_part->body.disposition.parameter = last_param; - + if (is_inline) last_part->body.disposition.type = strdup("inline"); } - else { + else { /* text body (plain/html) */ part->body.type = TYPETEXT; part->body.size.bytes = data_len; @@ -2288,26 +2289,26 @@ static int attach_part(BODY *body, const unsigned char *data, int data_len, char else part->body.sparep = NULL; - + if (!content_sub_type) { /* Plain text body */ - part->body.encoding = ENC8BIT; + part->body.encoding = ENC8BIT; part->body.subtype = cpystr("plain"); last_param = part->body.parameter; - + if (last_param != NULL) { while (last_param->next) last_param = last_param->next; } - + param = mail_newbody_parameter(); - + if (param == NULL) { EM_DEBUG_EXCEPTION("mail_newbody_parameter failed..."); error = EMAIL_ERROR_OUT_OF_MEMORY; goto FINISH_OFF; } - + param->attribute = cpystr("CHARSET"); if (data != NULL) { @@ -2316,14 +2317,14 @@ static int attach_part(BODY *body, const unsigned char *data, int data_len, char param->value = cpystr(extract_charset_plain); g_free(extract_charset_plain); } - else + else param->value = cpystr("UTF-8"); if(!param->value) param->value = cpystr("UTF-8"); param->next = NULL; - + if (last_param != NULL) last_param->next = param; else @@ -2331,26 +2332,26 @@ static int attach_part(BODY *body, const unsigned char *data, int data_len, char } else { /* HTML text body */ - part->body.encoding = ENC8BIT; + part->body.encoding = ENC8BIT; part->body.subtype = cpystr(content_sub_type); last_param = part->body.parameter; - + if (last_param != NULL) { while (last_param->next) last_param = last_param->next; } - + param = mail_newbody_parameter(); - + if (param == NULL) { EM_DEBUG_EXCEPTION("mail_newbody_parameter failed..."); error = EMAIL_ERROR_OUT_OF_MEMORY; goto FINISH_OFF; } - + param->attribute = cpystr("CHARSET"); - + char *pHtml = NULL; if (data != NULL) { gchar *extract_charset = g_path_get_basename((const gchar *)data); @@ -2360,7 +2361,7 @@ static int attach_part(BODY *body, const unsigned char *data, int data_len, char param->value = cpystr(extract_charset); } } - + if(!param->value) param->value = cpystr("UTF-8"); @@ -2369,13 +2370,13 @@ static int attach_part(BODY *body, const unsigned char *data, int data_len, char 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) { @@ -2383,13 +2384,13 @@ static int attach_part(BODY *body, const unsigned char *data, int data_len, char part->body.disposition.type = cpystr(content_disposition); } } - + ret = true; - -FINISH_OFF: + +FINISH_OFF: EM_SAFE_FREE(encoded_file_name); EM_SAFE_FREE(result_file_name); /*prevent 26242*/ - EM_SAFE_FREE(base64_file_name); + EM_SAFE_FREE(base64_file_name); if (err_code != NULL) *err_code = error; EM_DEBUG_FUNC_END(); @@ -2399,94 +2400,94 @@ FINISH_OFF: static PART *attach_mutipart_with_sub_type(BODY *parent_body, char *sub_type, int *err_code) { EM_DEBUG_FUNC_BEGIN("parent_body[%p], sub_type [%s], err_code[%p]", parent_body, sub_type, err_code); - + int error = EMAIL_ERROR_NONE; - + PART *tail_part_cur = NULL; PART *new_part = NULL; - + if (!parent_body || !sub_type) { EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM"); error = EMAIL_ERROR_INVALID_PARAM; goto FINISH_OFF; } - + if (parent_body->nested.part) { tail_part_cur = parent_body->nested.part; - + if (tail_part_cur != NULL) { while (tail_part_cur->next) tail_part_cur = tail_part_cur->next; } } - + new_part = mail_newbody_part(); - + if (new_part == NULL) { EM_DEBUG_EXCEPTION("EMAIL_ERROR_OUT_OF_MEMORY"); error = EMAIL_ERROR_OUT_OF_MEMORY; goto FINISH_OFF; } - + new_part->next = NULL; new_part->body.type = TYPEMULTIPART; new_part->body.subtype = EM_SAFE_STRDUP(sub_type); - - if (tail_part_cur) + + if (tail_part_cur) tail_part_cur->next = new_part; - else + else parent_body->nested.part = new_part; -FINISH_OFF: +FINISH_OFF: if (err_code) *err_code = error; EM_DEBUG_FUNC_END(); - + return new_part; } -#ifdef __FEATURE_SUPPORT_REPORT_MAIL__ +#ifdef __FEATURE_SUPPORT_REPORT_MAIL__ static int attach_attachment_to_body(BODY **multipart_body, BODY *text_body, emstorage_attachment_tbl_t *input_attachment_tbl, int input_attachment_tbl_count, int *err_code) { EM_DEBUG_FUNC_BEGIN("multipart_body[%p], text_body[%p], input_attachment_tbl[%p], input_attachment_tbl_count [%d], err_code[%p]", multipart_body, text_body, input_attachment_tbl, input_attachment_tbl_count, err_code); - + int ret = false; int i = 0; int error = EMAIL_ERROR_NONE; BODY *frame_body = NULL; /* make multipart body(multipart frame_body..) .. that has not content.. */ - + if (!multipart_body || !text_body || !input_attachment_tbl) { EM_DEBUG_EXCEPTION(" multipart_body[%p], text_body[%p], input_attachment_tbl[%p]", multipart_body, text_body, input_attachment_tbl); error = EMAIL_ERROR_INVALID_PARAM; goto FINISH_OFF; } - + frame_body = mail_newbody(); if (frame_body == NULL) { EM_DEBUG_EXCEPTION("mail_newbody failed..."); error = EMAIL_ERROR_OUT_OF_MEMORY; goto FINISH_OFF; } - + frame_body->type = TYPEMULTIPART; frame_body->contents.text.data = NULL; frame_body->contents.text.size = 0; frame_body->size.bytes = 0; - + /* insert original text_body to frame_body.. */ if (!attach_part(frame_body, text_body->sparep, 0, NULL, NULL, false, &error)) { EM_DEBUG_EXCEPTION(" attach_part failed [%d]", error); goto FINISH_OFF; } - + /* insert files.. */ emstorage_attachment_tbl_t *temp_attachment_tbl = NULL; char *name = NULL; struct stat st_buf; - + for(i = 0; i < input_attachment_tbl_count; i++) { temp_attachment_tbl = input_attachment_tbl + i; @@ -2499,24 +2500,24 @@ static int attach_attachment_to_body(BODY **multipart_body, BODY *text_body, ems goto FINISH_OFF; } } - else + else name = temp_attachment_tbl->attachment_name; - + if (!attach_part(frame_body, (unsigned char *)temp_attachment_tbl->attachment_path, 0, name, NULL, false, &error)) { EM_DEBUG_EXCEPTION("attach_part failed [%d]", error); goto FINISH_OFF; } } } - + ret = true; - -FINISH_OFF: + +FINISH_OFF: if (ret == true) *multipart_body = frame_body; else if (frame_body != NULL) mail_free_body(&frame_body); - + if (err_code != NULL) *err_code = error; EM_DEBUG_FUNC_END(); @@ -2526,15 +2527,15 @@ FINISH_OFF: static char *emcore_encode_rfc2047_text(char *utf8_text, int *err_code) { EM_DEBUG_FUNC_BEGIN("utf8_text[%s], err_code[%p]", utf8_text, err_code); - + if (utf8_text == NULL) { if (err_code != NULL) *err_code = EMAIL_ERROR_INVALID_PARAM; return NULL; } - + gsize len = EM_SAFE_STRLEN(utf8_text); - + EM_DEBUG_FUNC_END(); if (len > 0) @@ -2546,7 +2547,7 @@ static char *emcore_encode_rfc2047_text(char *utf8_text, int *err_code) static void emcore_encode_rfc2047_address(ADDRESS *address, int *err_code) { EM_DEBUG_FUNC_BEGIN("address[%p], err_code[%p]", address, err_code); - + while (address) { if (address->personal) { char *rfc2047_personal = emcore_encode_rfc2047_text(address->personal, err_code); @@ -2726,7 +2727,7 @@ static int emcore_make_envelope_from_mail(emstorage_mail_tbl_t *input_mail_tbl_d rfc822_parse_adrlist(&envelope->cc, pAdd, NULL); EM_SAFE_FREE(pAdd); - pAdd = NULL ; + pAdd = NULL ; em_skip_whitespace(input_mail_tbl_data->full_address_bcc , &pAdd); rfc822_parse_adrlist(&envelope->bcc, pAdd, NULL); @@ -2780,7 +2781,7 @@ FINISH_OFF: INTERNAL_FUNC int emcore_make_rfc822_file_from_mail(emstorage_mail_tbl_t *input_mail_tbl_data, emstorage_attachment_tbl_t *input_attachment_tbl, int input_attachment_count, ENVELOPE **env, char **file_path, email_option_t *sending_option, int *err_code) { EM_DEBUG_FUNC_BEGIN("input_mail_tbl_data[%p], env[%p], file_path[%p], sending_option[%p], err_code[%p]", input_mail_tbl_data, env, file_path, sending_option, err_code); - + int ret = false; int error = EMAIL_ERROR_NONE; int i = 0; @@ -2798,7 +2799,7 @@ INTERNAL_FUNC int emcore_make_rfc822_file_from_mail(emstorage_mail_tbl_t *input_ 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; @@ -2809,7 +2810,7 @@ INTERNAL_FUNC int emcore_make_rfc822_file_from_mail(emstorage_mail_tbl_t *input_ EM_DEBUG_EXCEPTION("emcore_make_envelope_from_mail failed [%d]", error); goto FINISH_OFF; } - + EM_DEBUG_LOG("input_mail_tbl_data->file_path_plain[%s]", input_mail_tbl_data->file_path_plain); EM_DEBUG_LOG("input_mail_tbl_data->file_path_html[%s]", input_mail_tbl_data->file_path_html); EM_DEBUG_LOG("input_mail_tbl_data->file_path_mime_entity[%s]", input_mail_tbl_data->file_path_mime_entity); @@ -2825,7 +2826,7 @@ INTERNAL_FUNC int emcore_make_rfc822_file_from_mail(emstorage_mail_tbl_t *input_ error = EMAIL_ERROR_OUT_OF_MEMORY; goto FINISH_OFF; } - + param = mail_newbody_parameter(); if (param == NULL) { @@ -2844,10 +2845,10 @@ INTERNAL_FUNC int emcore_make_rfc822_file_from_mail(emstorage_mail_tbl_t *input_ } else if (input_mail_tbl_data->smime_type == EMAIL_SMIME_SIGNED) { PARAMETER *protocol_param = mail_newbody_parameter(); - + root_body->type = TYPEMULTIPART; root_body->subtype = strdup("SIGNED"); - + param->attribute = cpystr("micalg"); switch (input_mail_tbl_data->digest_type) { case DIGEST_TYPE_SHA1: @@ -2874,10 +2875,10 @@ INTERNAL_FUNC int emcore_make_rfc822_file_from_mail(emstorage_mail_tbl_t *input_ input_attachment_count = 1; } else { - + root_body->type = TYPEAPPLICATION; root_body->subtype = strdup("PKCS7-MIME"); - + param->attribute = cpystr("name"); param->value = cpystr("smime.p7m"); param->next = NULL; @@ -2893,7 +2894,7 @@ INTERNAL_FUNC int emcore_make_rfc822_file_from_mail(emstorage_mail_tbl_t *input_ root_body->contents.text.size = 0; root_body->size.bytes = 0; root_body->parameter = param; - + if (input_mail_tbl_data->smime_type == EMAIL_SMIME_NONE) { part_for_text = attach_mutipart_with_sub_type(root_body, "ALTERNATIVE", &error); @@ -2903,7 +2904,7 @@ INTERNAL_FUNC int emcore_make_rfc822_file_from_mail(emstorage_mail_tbl_t *input_ } 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("file_path_plain[%s]", input_mail_tbl_data->file_path_plain); @@ -2932,13 +2933,13 @@ INTERNAL_FUNC int emcore_make_rfc822_file_from_mail(emstorage_mail_tbl_t *input_ EM_DEBUG_LOG("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); } - + 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("attachment_name[%s], attachment_path[%s]", temp_attachment_tbl->attachment_name, temp_attachment_tbl->attachment_path); @@ -2973,7 +2974,7 @@ INTERNAL_FUNC int emcore_make_rfc822_file_from_mail(emstorage_mail_tbl_t *input_ if (text_body == NULL) { EM_DEBUG_EXCEPTION("mail_newbody failed..."); - + error = EMAIL_ERROR_OUT_OF_MEMORY; goto FINISH_OFF; } @@ -2999,7 +3000,7 @@ INTERNAL_FUNC int emcore_make_rfc822_file_from_mail(emstorage_mail_tbl_t *input_ EM_DEBUG_LOG("REPORT MAIL"); envelope->references = cpystr(input_mail_tbl_data->message_id); } - + if (file_path) { EM_DEBUG_LOG("write rfc822 : file_path[%p]", file_path); @@ -3010,24 +3011,24 @@ INTERNAL_FUNC int emcore_make_rfc822_file_from_mail(emstorage_mail_tbl_t *input_ EM_DEBUG_EXCEPTION("emcore_write_rfc822 failed [%d]", error); goto FINISH_OFF; } - + *file_path = fname; } - + ret = true; - -FINISH_OFF: + +FINISH_OFF: if ((ret == true) && (env != NULL)) *env = envelope; else if (envelope != NULL) mail_free_envelope(&envelope); - + if (text_body != NULL) mail_free_body(&text_body); - + if (root_body != NULL) mail_free_body(&root_body); - + if (err_code != NULL) *err_code = error; @@ -3038,7 +3039,7 @@ FINISH_OFF: 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) { 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; @@ -3060,42 +3061,42 @@ INTERNAL_FUNC int emcore_make_rfc822_file(email_mail_data_t *input_mail_tbl_data 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; + goto FINISH_OFF; } - if (!ref_account) { + 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; } - + if (!(envelope = mail_newenvelope())) { EM_DEBUG_EXCEPTION("mail_newenvelope failed..."); error = EMAIL_ERROR_OUT_OF_MEMORY; 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) { @@ -3109,11 +3110,11 @@ INTERNAL_FUNC int emcore_make_rfc822_file(email_mail_data_t *input_mail_tbl_data else envelope->from = rfc822_parse_mailbox(&p, NULL); - EM_SAFE_FREE(p); + EM_SAFE_FREE(p); if (!envelope->from) { EM_DEBUG_EXCEPTION("rfc822_parse_mailbox failed..."); error = EMAIL_ERROR_INVALID_ADDRESS; - goto FINISH_OFF; + goto FINISH_OFF; } else { @@ -3128,32 +3129,32 @@ INTERNAL_FUNC int emcore_make_rfc822_file(email_mail_data_t *input_mail_tbl_data 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] == ';') @@ -3162,14 +3163,14 @@ INTERNAL_FUNC int emcore_make_rfc822_file(email_mail_data_t *input_mail_tbl_data } em_skip_whitespace(input_mail_tbl_data->full_address_from , &pAdd); EM_DEBUG_LOG("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("address[pAdd][%s]", pAdd); - + rfc822_parse_adrlist(&envelope->return_path, pAdd, ref_account->outgoing_server_address); EM_SAFE_FREE(pAdd); pAdd = NULL ; @@ -3177,21 +3178,21 @@ INTERNAL_FUNC int emcore_make_rfc822_file(email_mail_data_t *input_mail_tbl_data { 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] == ';') @@ -3202,15 +3203,15 @@ INTERNAL_FUNC int emcore_make_rfc822_file(email_mail_data_t *input_mail_tbl_data em_skip_whitespace(input_mail_tbl_data->full_address_to , &pAdd); EM_DEBUG_LOG("address[pAdd][%s]", pAdd); - + rfc822_parse_adrlist(&envelope->to, pAdd, ref_account->outgoing_server_address); EM_SAFE_FREE(pAdd); pAdd = NULL ; - + EM_DEBUG_LOG("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("address[pAdd][%s]", pAdd); - + rfc822_parse_adrlist(&envelope->cc, pAdd, ref_account->outgoing_server_address); EM_SAFE_FREE(pAdd); pAdd = NULL ; @@ -3233,7 +3234,7 @@ INTERNAL_FUNC int emcore_make_rfc822_file(email_mail_data_t *input_mail_tbl_data char rfc822_date_string[DATE_STR_LENGTH] = { 0, }; char localtime_string[DATE_STR_LENGTH] = {0, }; - + rfc822_date(rfc822_date_string); if (!is_incomplete) { @@ -3246,7 +3247,7 @@ INTERNAL_FUNC int emcore_make_rfc822_file(email_mail_data_t *input_mail_tbl_data 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("input_mail_tbl_data->file_path_plain[%s]", input_mail_tbl_data->file_path_plain); EM_DEBUG_LOG("input_mail_tbl_data->file_path_html[%s]", input_mail_tbl_data->file_path_html); @@ -3281,7 +3282,7 @@ INTERNAL_FUNC int emcore_make_rfc822_file(email_mail_data_t *input_mail_tbl_data error = EMAIL_ERROR_OUT_OF_MEMORY; goto FINISH_OFF; } - + root_body->type = TYPEMULTIPART; root_body->subtype = strdup("MIXED"); root_body->contents.text.data = NULL; @@ -3296,7 +3297,7 @@ INTERNAL_FUNC int emcore_make_rfc822_file(email_mail_data_t *input_mail_tbl_data } 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("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)) { @@ -3304,7 +3305,7 @@ INTERNAL_FUNC int emcore_make_rfc822_file(email_mail_data_t *input_mail_tbl_data 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("file_path_html[%s]", input_mail_tbl_data->file_path_html); @@ -3319,13 +3320,13 @@ INTERNAL_FUNC int emcore_make_rfc822_file(email_mail_data_t *input_mail_tbl_data goto FINISH_OFF; } } - + if (input_attachment_tbl && input_attachment_count) { email_attachment_data_t *temp_attachment_tbl = NULL; char *name = NULL; - BODY *body_to_attach = 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("attachment_name[%s], attachment_path[%s]", temp_attachment_tbl->attachment_name, temp_attachment_tbl->attachment_path); @@ -3336,7 +3337,7 @@ INTERNAL_FUNC int emcore_make_rfc822_file(email_mail_data_t *input_mail_tbl_data continue; } } - else + else name = temp_attachment_tbl->attachment_name; EM_DEBUG_LOG("name[%s]", name); @@ -3344,7 +3345,7 @@ INTERNAL_FUNC int emcore_make_rfc822_file(email_mail_data_t *input_mail_tbl_data 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; @@ -3352,24 +3353,24 @@ INTERNAL_FUNC int emcore_make_rfc822_file(email_mail_data_t *input_mail_tbl_data } } } - text_body = NULL; + 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) @@ -3388,7 +3389,7 @@ INTERNAL_FUNC int emcore_make_rfc822_file(email_mail_data_t *input_mail_tbl_data EM_DEBUG_EXCEPTION("emcore_write_rfc822 failed [%d]", error); goto FINISH_OFF; } - + *file_path = fname; } @@ -3405,19 +3406,19 @@ INTERNAL_FUNC int emcore_make_rfc822_file(email_mail_data_t *input_mail_tbl_data goto FINISH_OFF; } } - + ret = true; - + FINISH_OFF: emstorage_free_account(&ref_account, 1, NULL); if (envelope != NULL) mail_free_envelope(&envelope); - + if (text_body != NULL) mail_free_body(&text_body); - + if (root_body != NULL) mail_free_body(&root_body); @@ -3432,10 +3433,10 @@ FINISH_OFF: static int emcore_get_report_mail_body(ENVELOPE *envelope, BODY **multipart_body, int *err_code) { EM_DEBUG_FUNC_BEGIN("envelope[%p], mulitpart_body[%p], err_code[%p]", envelope, multipart_body, err_code); - + int ret = false; int err = EMAIL_ERROR_NONE; - + BODY *m_body = NULL; BODY *p_body = NULL; BODY *text_body = NULL; @@ -3445,36 +3446,36 @@ static int emcore_get_report_mail_body(ENVELOPE *envelope, BODY **multipart_body char *fname = NULL; char buf[512] = {0x00, }; int sz = 0; - + if (!envelope || !multipart_body) { EM_DEBUG_EXCEPTION(" envelope[%p], mulitpart_body[%p]", envelope, multipart_body); err = EMAIL_ERROR_INVALID_PARAM; goto FINISH_OFF; } - + if (!(text_body = mail_newbody())) { EM_DEBUG_EXCEPTION(" mail_newbody failed..."); err = EMAIL_ERROR_OUT_OF_MEMORY; goto FINISH_OFF; } - + if (!emcore_get_temp_file_name(&fname, &err)) { EM_DEBUG_EXCEPTION(" emcore_get_temp_file_name failed [%d]", err); goto FINISH_OFF; } - + if (!(fp = fopen(fname, "wb+"))) { EM_DEBUG_EXCEPTION(" fopen failed - %s", fname); err = EMAIL_ERROR_SYSTEM_FAILURE; goto FINISH_OFF; } - + if (!envelope->from || !envelope->from->mailbox || !envelope->from->host) { if (!envelope->from) EM_DEBUG_EXCEPTION(" envelope->from[%p]", envelope->from); else EM_DEBUG_LOG(" envelope->from->mailbox[%p], envelope->from->host[%p]", envelope->from->mailbox, envelope->from->host); - + err = EMAIL_ERROR_INVALID_PARAM; goto FINISH_OFF; } @@ -3485,33 +3486,33 @@ static int emcore_get_report_mail_body(ENVELOPE *envelope, BODY **multipart_body else */ SNPRINTF(buf, sizeof(buf), "%s@%s", envelope->from->mailbox, envelope->from->host); - + fprintf(fp, "Your message has been read by %s"CRLF_STRING, buf); fprintf(fp, "Date : %s", envelope->date); - + fclose(fp); fp = NULL; - + if (!emcore_get_file_size(fname, &sz, &err)) { EM_DEBUG_EXCEPTION(" emcore_get_file_size failed [%d]", err); goto FINISH_OFF; } - + text_body->type = TYPETEXT; text_body->encoding = ENC8BIT; text_body->sparep = EM_SAFE_STRDUP(fname); text_body->size.bytes = (unsigned long)sz; - + if (!emcore_get_temp_file_name(&fname, &err)) { EM_DEBUG_EXCEPTION(" emcore_get_temp_file_name failed [%d]", err); goto FINISH_OFF; } - + if (!(fp = fopen(fname, "wb+"))) { EM_DEBUG_EXCEPTION(" fopen failed - %s", fname); err = EMAIL_ERROR_SYSTEM_FAILURE; /* EMAIL_ERROR_UNKNOWN; */ goto FINISH_OFF; } - + if (!envelope->references) { EM_DEBUG_EXCEPTION(" envelope->references[%p]", envelope->references); err = EMAIL_ERROR_INVALID_PARAM; @@ -3521,80 +3522,80 @@ static int emcore_get_report_mail_body(ENVELOPE *envelope, BODY **multipart_body fprintf(fp, "Final-Recipient : rfc822;%s@%s\r", envelope->from->mailbox, envelope->from->host); fprintf(fp, "Original-Message-ID: %s\r", envelope->references); fprintf(fp, "Disposition : manual-action/MDN-sent-manually; displayed"); - + fclose(fp); fp = NULL; - + memset(&temp_attachment_tbl, 0x00, sizeof(emstorage_attachment_tbl_t)); - + temp_attachment_tbl.attachment_path = EM_SAFE_STRDUP(fname); - + 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)) { EM_DEBUG_EXCEPTION(" attach_attachment_to_body failed [%d]", err); goto FINISH_OFF; } - + text_body->contents.text.data = NULL; - + /* change mail header */ - + /* set content-type to multipart/report */ m_body->subtype = strdup("report"); - + /* set report-type parameter in content-type */ param = em_malloc(sizeof(PARAMETER)); - if (!param) { + if (!param) { EM_DEBUG_EXCEPTION(" malloc failed..."); err = EMAIL_ERROR_OUT_OF_MEMORY; goto FINISH_OFF; } - + param->attribute = strdup("report-type"); param->value = strdup("disposition-notification"); param->next = m_body->parameter; - + m_body->parameter = param; - + /* change body-header */ - + p_body = &m_body->nested.part->next->body; - + /* set content-type to message/disposition-notification */ p_body->type = TYPEMESSAGE; p_body->encoding = ENC7BIT; - + EM_SAFE_FREE(p_body->subtype); - + p_body->subtype = strdup("disposition-notification"); - + /* set parameter */ mail_free_body_parameter(&p_body->parameter); mail_free_body_parameter(&p_body->disposition.parameter); - + EM_SAFE_FREE(p_body->disposition.type); - + p_body->disposition.type = strdup("inline"); - + ret = true; - -FINISH_OFF: + +FINISH_OFF: if ((ret == true) && (multipart_body != NULL)) *multipart_body = m_body; else if (m_body != NULL) mail_free_body(&m_body); - + if (text_body != NULL) mail_free_body(&text_body); - + if (fp != NULL) fclose(fp); - + EM_SAFE_FREE(fname); - + if (err_code != NULL) *err_code = err; @@ -3612,18 +3613,18 @@ INTERNAL_FUNC int emcore_get_body_buff(char *file_path, char **buff) int ret = false; char *read_buff = NULL; - + if (file_path) r_fp = fopen(file_path, "r"); if (!r_fp) { - EM_DEBUG_EXCEPTION(" Filename %s failed to open", file_path); + EM_DEBUG_EXCEPTION(" Filename %s failed to open", file_path); goto FINISH_OFF; } - - struct stat stbuf; - stat(file_path, &stbuf); + + struct stat stbuf; + stat(file_path, &stbuf); EM_DEBUG_LOG(" File Size [ %d ] ", stbuf.st_size); read_buff = calloc(1, (stbuf.st_size+ 1)); read_size = fread(read_buff, 1, stbuf.st_size, r_fp); @@ -3633,15 +3634,157 @@ INTERNAL_FUNC int emcore_get_body_buff(char *file_path, char **buff) EM_DEBUG_EXCEPTION("file read failed - %s", file_path); EM_SAFE_FREE(read_buff); goto FINISH_OFF; - } - - + } ret = true; *buff = read_buff; - - FINISH_OFF: + +FINISH_OFF: if (r_fp) fclose(r_fp); return ret; } + +static int emcore_copy_attachment_from_original_mail(int input_original_mail_id, int input_target_mail_id) +{ + EM_DEBUG_FUNC_BEGIN("input_original_mail_id[%d] input_target_mail_id[%d]", input_original_mail_id, input_target_mail_id); + int err = EMAIL_ERROR_NONE; + int i = 0, j = 0; + int original_mail_attachment_count = 0; + int target_mail_attachment_count = 0; + int attachment_id = 0; + char output_file_name[MAX_PATH] = { 0, }; + char output_file_path[MAX_PATH] = { 0, }; + emstorage_attachment_tbl_t *original_mail_attachment_array = NULL; + emstorage_attachment_tbl_t *target_mail_attachment_array = NULL; + emstorage_attachment_tbl_t *target_attach = NULL; + + if((err = emstorage_get_attachment_list(input_original_mail_id, false, &original_mail_attachment_array, &original_mail_attachment_count)) != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emstorage_get_attachment_list failed [%d]", err); + goto FINISH_OFF; + } + + if((err = emstorage_get_attachment_list(input_target_mail_id, false, &target_mail_attachment_array, &target_mail_attachment_count)) != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emstorage_get_attachment_list failed [%d]", err); + goto FINISH_OFF; + } + + for(i = 0; i < original_mail_attachment_count; i++) { + for(j = 0; j < target_mail_attachment_count; j++) { + if(strcmp(original_mail_attachment_array[i].attachment_name, target_mail_attachment_array[j].attachment_name) == 0 ) { + target_attach = target_mail_attachment_array + j; + + /* If attachment is inline content, fild path should not include attachment id */ + if(target_attach->attachment_inline_content_status == 1) + attachment_id = 0; + else + attachment_id = target_attach->attachment_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)) { + EM_DEBUG_EXCEPTION("emcore_save_mail_file failed [%d]", err); + goto FINISH_OFF; + } + + EM_SAFE_FREE(target_attach->attachment_path); + target_attach->attachment_path = EM_SAFE_STRDUP(output_file_path); + target_attach->attachment_save_status = 1; + + if(!emstorage_update_attachment(target_attach, false, &err)) { + EM_DEBUG_EXCEPTION("emstorage_update_attachment failed [%d]", err); + goto FINISH_OFF; + } + memset(output_file_path, 0, MAX_PATH); + memset(output_file_name, 0, MAX_PATH); + break; + } + } + } + +FINISH_OFF: + if(original_mail_attachment_array) + emstorage_free_attachment(&original_mail_attachment_array, original_mail_attachment_count, NULL); + if(target_mail_attachment_array) + emstorage_free_attachment(&target_mail_attachment_array, target_mail_attachment_count, NULL); + + + EM_DEBUG_FUNC_END("err[%d]", err); + return err; +} + +/* send a mail */ +INTERNAL_FUNC int emcore_send_mail_with_downloading_attachment_of_original_mail(int input_mail_id) +{ + EM_DEBUG_FUNC_BEGIN("input_mail_id[%d]", input_mail_id); + int err = EMAIL_ERROR_NONE; + int i = 0; + int attachment_count = 0; + email_mail_data_t *mail_to_be_sent = NULL; + email_mail_data_t *original_mail = NULL; + email_attachment_data_t *attachment_array = NULL; + + /* Get mail data */ + if((err = emcore_get_mail_data(input_mail_id, &mail_to_be_sent)) != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emcore_get_mail_data failed [%d]", err); + goto FINISH_OFF; + } + + if(mail_to_be_sent->reference_mail_id <= 0) { + err = EMAIL_ERROR_INVALID_REFERENCE_MAIL; + EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_REFERENCE_MAIL"); + goto FINISH_OFF; + } + + /* Get original mail data */ + if((err = emcore_get_mail_data(mail_to_be_sent->reference_mail_id, &original_mail)) != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emcore_get_mail_data failed [%d]", err); + goto FINISH_OFF; + } + + /* Check necessity of download */ + if((err = emcore_get_attachment_data_list(original_mail->mail_id, &attachment_array, &attachment_count)) != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emcore_get_attachment_data_list failed [%d]", err); + goto FINISH_OFF; + } + + /* 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)) { + EM_DEBUG_EXCEPTION("emcore_download_attachment failed [%d]", err); + goto FINISH_OFF; + } + } + } + + /* Copy attachment to the mail to be sent */ + if((err = emcore_copy_attachment_from_original_mail(original_mail->mail_id, mail_to_be_sent->mail_id)) != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emcore_download_attachment failed [%d]", err); + goto FINISH_OFF; + } + + /* Send the mail */ + if(!emcore_send_mail(mail_to_be_sent->account_id, mail_to_be_sent->mailbox_id, mail_to_be_sent->mail_id, &err)) { + EM_DEBUG_EXCEPTION("emcore_send_mail failed [%d]", err); + goto FINISH_OFF; + } +FINISH_OFF: + + if(attachment_array) + emcore_free_attachment_data(&attachment_array, attachment_count, NULL); + + if(mail_to_be_sent) { + emcore_free_mail_data(mail_to_be_sent); + EM_SAFE_FREE(mail_to_be_sent); + } + + if(original_mail) { + emcore_free_mail_data(original_mail); + EM_SAFE_FREE(original_mail); + } + + + EM_DEBUG_FUNC_END("err [%d]", err); + return err; +} diff --git a/email-core/email-core-sound.c b/email-core/email-core-sound.c index 8814b22..b57042a 100755 --- a/email-core/email-core-sound.c +++ b/email-core/email-core-sound.c @@ -1,7 +1,7 @@ /* * email-service * -* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> * diff --git a/email-core/email-core-task-manager.c b/email-core/email-core-task-manager.c index 730d187..14cf361 100755 --- a/email-core/email-core-task-manager.c +++ b/email-core/email-core-task-manager.c @@ -1,7 +1,7 @@ /*
* email-service
*
-* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
*
* Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com>
*
@@ -223,12 +223,12 @@ INTERNAL_FUNC int emcore_init_task_handler_array() EM_DEBUG_FUNC_BEGIN();
if (_task_handler_array == NULL) {
-
_task_handler_array = NULL;
_task_handler_array_size = 0;
REGISTER_TASK_BINDER(EMAIL_ASYNC_TASK_MOVE_MAILS_TO_MAILBOX_OF_ANOTHER_ACCOUNT);
REGISTER_TASK_BINDER(EMAIL_ASYNC_TASK_DELETE_MAILBOX_EX);
+ REGISTER_TASK_BINDER(EMAIL_ASYNC_TASK_SEND_MAIL_WITH_DOWNLOADING_ATTACHMENT_OF_ORIGINAL_MAIL);
}
EM_DEBUG_FUNC_END();
diff --git a/email-core/email-core-tasks.c b/email-core/email-core-tasks.c index a7fa5e4..65faf1d 100755 --- a/email-core/email-core-tasks.c +++ b/email-core/email-core-tasks.c @@ -1,7 +1,7 @@ /*
* email-service
*
-* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
*
* Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com>
*
@@ -248,3 +248,79 @@ INTERNAL_FUNC void* task_handler_EMAIL_ASYNC_TASK_DELETE_MAILBOX_EX(void *input_ return NULL;
}
/*-------------------------------------------------------------------------------------------*/
+/* to handle EMAIL_ASYNC_TASK_SEND_MAIL_WITH_DOWNLOADING_ATTACHMENT_OF_ORIGINAL_MAIL */
+#define task_parameter_format_EMAIL_ASYNC_TASK_SEND_MAIL_WITH_DOWNLOADING_ATTACHMENT_OF_ORIGINAL_MAIL "i"
+
+INTERNAL_FUNC int email_encode_task_parameter_EMAIL_ASYNC_TASK_SEND_MAIL_WITH_DOWNLOADING_ATTACHMENT_OF_ORIGINAL_MAIL(void *input_task_parameter_struct, char **output_byte_stream, int *output_stream_size)
+{
+ EM_DEBUG_FUNC_BEGIN("input_task_parameter_struct [%p] output_byte_stream [%p] output_stream_size [%p]", input_task_parameter_struct, output_byte_stream, output_stream_size);
+
+ int err = EMAIL_ERROR_NONE;
+ task_parameter_EMAIL_ASYNC_TASK_SEND_MAIL_WITH_DOWNLOADING_ATTACHMENT_OF_ORIGINAL_MAIL *task_parameter = input_task_parameter_struct;
+ tpl_node *tn = NULL;
+ void *result_data = NULL;
+ size_t result_data_length = 0;
+
+ if (task_parameter == NULL || output_byte_stream == NULL || output_stream_size == NULL) {
+ EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
+ err = EMAIL_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ tn = tpl_map(task_parameter_format_EMAIL_ASYNC_TASK_SEND_MAIL_WITH_DOWNLOADING_ATTACHMENT_OF_ORIGINAL_MAIL
+ , &task_parameter->mail_id);
+ tpl_pack(tn, 0);
+ tpl_dump(tn, TPL_MEM, &result_data, &result_data_length);
+ tpl_free(tn);
+
+ *output_byte_stream = result_data;
+ *output_stream_size = result_data_length;
+
+FINISH_OFF:
+
+ EM_DEBUG_FUNC_END("err [%d]", err);
+ return EMAIL_ERROR_NONE;
+}
+
+INTERNAL_FUNC int email_decode_task_parameter_EMAIL_ASYNC_TASK_SEND_MAIL_WITH_DOWNLOADING_ATTACHMENT_OF_ORIGINAL_MAIL(char *input_byte_stream, int input_stream_size, void **output_task_parameter_struct)
+{
+ EM_DEBUG_FUNC_BEGIN("input_byte_stream [%p] input_stream_size [%d] output_task_parameter_struct [%p]", input_byte_stream, input_stream_size, output_task_parameter_struct);
+ int err = EMAIL_ERROR_NONE;
+ tpl_node *tn = NULL;
+ task_parameter_EMAIL_ASYNC_TASK_SEND_MAIL_WITH_DOWNLOADING_ATTACHMENT_OF_ORIGINAL_MAIL *task_parameter = NULL;
+
+ if (input_byte_stream == NULL || input_stream_size == 0 || output_task_parameter_struct == NULL) {
+ EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
+ err = EMAIL_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ task_parameter = em_malloc(sizeof(task_parameter_EMAIL_ASYNC_TASK_SEND_MAIL_WITH_DOWNLOADING_ATTACHMENT_OF_ORIGINAL_MAIL));
+
+ if(task_parameter == NULL) {
+ EM_DEBUG_EXCEPTION("EMAIL_ERROR_OUT_OF_MEMORY");
+ err = EMAIL_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ tn = tpl_map(task_parameter_format_EMAIL_ASYNC_TASK_SEND_MAIL_WITH_DOWNLOADING_ATTACHMENT_OF_ORIGINAL_MAIL
+ , &task_parameter->mail_id);
+ tpl_load(tn, TPL_MEM, input_byte_stream, input_stream_size);
+ tpl_unpack(tn, 0);
+
+ *output_task_parameter_struct = task_parameter;
+
+FINISH_OFF:
+
+ if(tn)
+ tpl_free(tn);
+
+ EM_DEBUG_FUNC_END("err [%d]", err);
+ return EMAIL_ERROR_NONE;
+}
+
+INTERNAL_FUNC void* task_handler_EMAIL_ASYNC_TASK_SEND_MAIL_WITH_DOWNLOADING_ATTACHMENT_OF_ORIGINAL_MAIL(void *input_param)
+{
+ return NULL;
+}
+/*-------------------------------------------------------------------------------------------*/
diff --git a/email-core/email-core-timer.c b/email-core/email-core-timer.c index 641c7b5..04ceb95 100755 --- a/email-core/email-core-timer.c +++ b/email-core/email-core-timer.c @@ -1,7 +1,7 @@ /* * email-service * -* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> * diff --git a/email-core/email-core-utils.c b/email-core/email-core-utils.c index 3a4a56f..2324097 100755 --- a/email-core/email-core-utils.c +++ b/email-core/email-core-utils.c @@ -1,10 +1,10 @@ /* * email-service * -* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* 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 @@ -55,15 +55,15 @@ #include "email-core-mail.h" #include "email-core-event.h" #include "email-core-mailbox.h" -#include "email-core-account.h" -#include "email-core-mailbox-sync.h" +#include "email-core-account.h" +#include "email-core-mailbox-sync.h" #include "email-core-mime.h" -#include "email-core-sound.h" +#include "email-core-sound.h" #include "email-core-signal.h" #include "email-utilities.h" #include "email-convert.h" -#define LED_TIMEOUT_SECS 12 +#define LED_TIMEOUT_SECS 12 #define G_DISPLAY_LENGTH 256 #define DIR_SEPERATOR_CH '/' @@ -78,11 +78,11 @@ #define EMAIL_CH_SQUARE_BRACKET_E ']' #define EMAIL_CH_SPACE ' ' #define EMAIL_NOTI_ICON_PATH EMAILPATH"/res/image/Q02_Notification_email.png" -#define VCONF_KEY_UNREAD_MAIL_COUNT "db/badge/org.tizen.email" +#define VCONF_KEY_UNREAD_MAIL_COUNT "db/badge/com.samsung.email" typedef struct _em_transaction_info_type_t { int mail_id; - int handle; + int handle; struct _em_transaction_info_type_t *next; } em_transaction_info_type_t; @@ -116,47 +116,47 @@ int emcore_get_long_encoded_path_with_account_info(email_account_t *account, cha { EM_PROFILE_BEGIN(emCorelongEncodedpath); EM_DEBUG_FUNC_BEGIN("account[%p], path[%s], delimiter[%d], long_enc_path[%p], err_code[%p]", account, path, delimiter, long_enc_path, err_code); - + int ret = false; int error = EMAIL_ERROR_NONE; char *p = NULL; - + size_t long_enc_path_len = 0; - + if (path == NULL || (path && strncmp(path, ENCODED_PATH_SMTP, EM_SAFE_STRLEN(ENCODED_PATH_SMTP)) != 0)) { /* imap or pop3 */ EM_DEBUG_LOG("account->incoming_server_address[%p]", account->incoming_server_address); EM_DEBUG_LOG("account->incoming_server_address[%s]", account->incoming_server_address); - + if (!account->incoming_server_address) { EM_DEBUG_EXCEPTION("account->incoming_server_address is null"); error = EMAIL_ERROR_INVALID_ACCOUNT; goto FINISH_OFF; } - + long_enc_path_len = EM_SAFE_STRLEN(account->incoming_server_address) + EM_SAFE_STRLEN(path) + 64; /*prevent 34357*/ - + *long_enc_path = em_malloc(long_enc_path_len); if (!*long_enc_path) { EM_DEBUG_EXCEPTION("malloc failed..."); error = EMAIL_ERROR_OUT_OF_MEMORY; goto FINISH_OFF; } - + p = *long_enc_path; - + /* ex:"{mai.test.com:143/imap} or {mai.test.com:143/imap/tls}my-mailbox" */ SNPRINTF(p, long_enc_path_len, "{%s:%d/%s/user=%d", account->incoming_server_address, account->incoming_server_port_number, account->incoming_server_type == EMAIL_SERVER_TYPE_POP3 ? "pop3" : "imap", account->account_id); - + if (account->incoming_server_secure_connection & 0x01) { strncat(p, "/ssl", long_enc_path_len-(EM_SAFE_STRLEN(p)+1)); /* strcat(p, "/tryssl"); */ } - /* Currently, receiving servers doesn't require tls. + /* Currently, receiving servers doesn't require tls. if (account->incoming_server_secure_connection & 0x02) strncat(p, "/tls", long_enc_path_len-(EM_SAFE_STRLEN(p)+1)); else @@ -171,28 +171,28 @@ int emcore_get_long_encoded_path_with_account_info(email_account_t *account, cha } else { /* smtp */ long_enc_path_len = EM_SAFE_STRLEN(account->outgoing_server_address) + 64; - + *long_enc_path = em_malloc(EM_SAFE_STRLEN(account->outgoing_server_address) + 64); if (!*long_enc_path) { EM_DEBUG_EXCEPTION("\t malloc failed...\n"); - + error = EMAIL_ERROR_OUT_OF_MEMORY; goto FINISH_OFF; } - + p = *long_enc_path; - + /* ex:"mail.test.com:25/smtp" */ SNPRINTF(p, long_enc_path_len, "%s:%d/%s", account->outgoing_server_address, account->outgoing_server_port_number, "smtp"); - + if (account->outgoing_server_need_authentication) { SNPRINTF(p + EM_SAFE_STRLEN(p), long_enc_path_len-(EM_SAFE_STRLEN(p)), "/user=%d", account->account_id); } - + if (account->outgoing_server_secure_connection & 0x01) { strncat(p, "/ssl", long_enc_path_len-(EM_SAFE_STRLEN(p)+1)); /* strcat(p, "/tryssl"); */ @@ -205,29 +205,29 @@ int emcore_get_long_encoded_path_with_account_info(email_account_t *account, cha if (path == NULL || (path && strncmp(path, ENCODED_PATH_SMTP, EM_SAFE_STRLEN(ENCODED_PATH_SMTP)) != 0)) { strncat(p, "}", long_enc_path_len-(EM_SAFE_STRLEN(p)+1)); - + if (path != NULL) { char *enc_name = NULL; - + if (!emcore_get_encoded_mailbox_name(path, &enc_name, &error)) { EM_DEBUG_EXCEPTION("emcore_get_encoded_mailbox_name failed - %d", error); *long_enc_path = NULL; goto FINISH_OFF; } - + if (enc_name) { strncat(p, enc_name, long_enc_path_len-(EM_SAFE_STRLEN(p)+1)); EM_SAFE_FREE(enc_name); } } } - + ret = true; - + FINISH_OFF: if (ret != true) EM_SAFE_FREE(p); - + if (err_code != NULL) *err_code = error; EM_PROFILE_END(emCorelongEncodedpath); @@ -238,10 +238,10 @@ int emcore_get_long_encoded_path(int account_id, char *path, int delimiter, char { EM_PROFILE_BEGIN(emCorelongEncodedpath); EM_DEBUG_FUNC_BEGIN("account_id[%d], delimiter[%d], long_enc_path[%p], err_code[%p]", account_id, delimiter, long_enc_path, err_code); - + int ret = false; int error = EMAIL_ERROR_NONE; - + email_account_t *ref_account = emcore_get_account_reference(account_id); if (!ref_account) { EM_DEBUG_EXCEPTION("emcore_get_account_reference failed [%d]", account_id); @@ -255,7 +255,7 @@ int emcore_get_long_encoded_path(int account_id, char *path, int delimiter, char } ret = true; - + FINISH_OFF: if (err_code != NULL) *err_code = error; @@ -266,14 +266,14 @@ FINISH_OFF: int emcore_get_encoded_mailbox_name(char *name, char **enc_name, int *err_code) { EM_DEBUG_FUNC_BEGIN("name[%s], enc_name[%p], err_code[%p]", name, enc_name, err_code); - + if (!name || !enc_name) { if (err_code != NULL) *err_code = EMAIL_ERROR_INVALID_PARAM; EM_DEBUG_FUNC_END(); return false; } - + /* encoding mailbox name (Charset->UTF8->UTF7) */ *enc_name = em_malloc(EM_SAFE_STRLEN(name)+1); @@ -284,9 +284,9 @@ int emcore_get_encoded_mailbox_name(char *name, char **enc_name, int *err_code) EM_DEBUG_FUNC_END(); return false; } - + strcpy(*enc_name, name); - + if (err_code != NULL) *err_code = EMAIL_ERROR_NONE; @@ -297,37 +297,37 @@ int emcore_get_encoded_mailbox_name(char *name, char **enc_name, int *err_code) int emcore_get_temp_file_name(char **filename, int *err_code) { EM_DEBUG_FUNC_BEGIN("filename[%p], err_code[%p]", filename, err_code); - + int ret = false; int error = EMAIL_ERROR_NONE; - + if (filename == NULL) { EM_DEBUG_EXCEPTION("\t filename[%p]\n", filename); error = EMAIL_ERROR_INVALID_PARAM; goto FINISH_OFF; } - + char tempname[512] = {0x00, }; struct timeval tv; - + gettimeofday(&tv, NULL); srand(tv.tv_usec); /* Create Directory If deleted by user*/ emstorage_create_dir_if_delete(); - + SNPRINTF(tempname, sizeof(tempname), "%s%c%d", MAILTEMP, DIR_SEPERATOR_CH, rand()); - + char *p = EM_SAFE_STRDUP(tempname); if (p == NULL) { EM_DEBUG_EXCEPTION("\t strdup failed...\n"); error = EMAIL_ERROR_OUT_OF_MEMORY; goto FINISH_OFF; } - + *filename = p; - + ret = true; FINISH_OFF: @@ -340,28 +340,28 @@ FINISH_OFF: int emcore_get_file_name(char *path, char **filename, int *err_code) { EM_DEBUG_FUNC_BEGIN("path[%s], filename[%p], err_code[%p]", path, filename, err_code); - + int ret = false; int error = EMAIL_ERROR_NONE; - + if (!path || !filename) { EM_DEBUG_EXCEPTION("path[%p], filename[%p]", path, filename); - + error = EMAIL_ERROR_INVALID_PARAM; goto FINISH_OFF; } - + int i = (int)EM_SAFE_STRLEN(path); - + /* get filename */ for (; i >= 0; i--) if (path[i] == DIR_SEPERATOR_CH) break; - + *filename = path + i + 1; - + ret = true; - + FINISH_OFF: if (err_code != NULL) *err_code = error; @@ -372,30 +372,30 @@ FINISH_OFF: int emcore_get_file_size(char *path, int *size, int *err_code) { EM_DEBUG_FUNC_BEGIN("path[%s], size[%p], err_code[%p]", path, size, err_code); - + int ret = false; int error = EMAIL_ERROR_NONE; - + if ((path == NULL) || (size == NULL)) { EM_DEBUG_EXCEPTION("\t path[%p], size[%p]\n", path, size); - + error = EMAIL_ERROR_INVALID_PARAM; goto FINISH_OFF; } - + struct stat st_buf; - + if (stat(path, &st_buf) < 0) { EM_DEBUG_EXCEPTION("\t stat failed - %s\n", path); - + error = EMAIL_ERROR_SYSTEM_FAILURE; goto FINISH_OFF; } - + *size = st_buf.st_size; - + ret = true; - + FINISH_OFF: if (err_code != NULL) *err_code = error; @@ -417,10 +417,10 @@ static int _emcore_check_host(char *host) int emcore_get_address_count(char *addr_str, int *count, int *err_code) { EM_DEBUG_FUNC_BEGIN("addr_str[%s], count[%p], err_code[%p]", addr_str, count, err_code); - + int ret = false; int error = EMAIL_ERROR_NONE; - + ADDRESS *addr = NULL; ADDRESS *p_addr = NULL; int i = 0, j; @@ -432,30 +432,30 @@ int emcore_get_address_count(char *addr_str, int *count, int *err_code) error = EMAIL_ERROR_INVALID_PARAM; goto FINISH_OFF; } - + if (addr_str != NULL) { em_skip_whitespace(addr_str, &p); EM_DEBUG_LOG("em_skip_whitespace[p][%s]", p); - for (i = 0, j = EM_SAFE_STRLEN(p); i < j; i++) + for (i = 0, j = EM_SAFE_STRLEN(p); i < j; i++) if (p[i] == ';') p[i] = ','; rfc822_parse_adrlist(&addr, p, NULL); EM_SAFE_FREE(p); - + for (p_addr = addr, i = 0; p_addr; p_addr = p_addr->next, i++) { - if (p_addr->mailbox && p_addr->host) { + if (p_addr->mailbox && p_addr->host) { if (!strncmp(p_addr->mailbox, "UNEXPECTED_DATA_AFTER_ADDRESS", strlen("UNEXPECTED_DATA_AFTER_ADDRESS")) || !strncmp(p_addr->mailbox, "INVALID_ADDRESS", strlen("INVALID_ADDRESS")) || !strncmp(p_addr->host, ".SYNTAX-ERROR.", strlen(".SYNTAX-ERROR."))) { /*prevent 34356*/ EM_DEBUG_LOG("Invalid address "); continue; } - } + } if ((!p_addr->mailbox) || (_emcore_check_host(p_addr->host) == 0)) { EM_DEBUG_EXCEPTION("\t invalid address : mailbox[%s], host[%s]\n", p_addr->mailbox, p_addr->host); - + error = EMAIL_ERROR_INVALID_ADDRESS; /* goto FINISH_OFF; */ } @@ -465,11 +465,11 @@ int emcore_get_address_count(char *addr_str, int *count, int *err_code) *count = i; if (error != EMAIL_ERROR_INVALID_ADDRESS) ret = true; - + FINISH_OFF: - if (addr) + if (addr) mail_free_address(&addr); - + if (err_code != NULL) *err_code = error; EM_DEBUG_FUNC_END(); @@ -495,11 +495,11 @@ INTERNAL_FUNC int emcore_set_network_error(int err_code) int emcore_get_empty_session(email_session_t **session) { EM_DEBUG_FUNC_BEGIN("session[%p]", session); - + /* lock()... */ - + int i; - + for (i = 0; i < SESSION_MAX; i++) { if (!g_session_list[i].status) { memset(g_session_list+i, 0x00, sizeof(email_session_t)); @@ -508,9 +508,9 @@ int emcore_get_empty_session(email_session_t **session) break; } } - + /* unlock()... */ - + if (session != NULL) *session = (i != SESSION_MAX) ? &g_session_list[i] : NULL; EM_DEBUG_FUNC_END(); @@ -520,7 +520,7 @@ int emcore_get_empty_session(email_session_t **session) int emcore_clear_session(email_session_t *session) { EM_DEBUG_FUNC_BEGIN(); - + if (session) memset(session, 0x00, sizeof(email_session_t)); EM_DEBUG_FUNC_END(); @@ -530,18 +530,18 @@ int emcore_clear_session(email_session_t *session) 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; } } - + if (session) *session = (i != SESSION_MAX) ? g_session_list + i : NULL; EM_DEBUG_FUNC_END(); @@ -576,7 +576,7 @@ int emcore_get_mail_count_by_query(int account_id, int priority_sender, int *tot /* Make query for searching unread mail */ if (account_id != ALL_ACCOUNT) { - filter_count = (rule_count * 2) + 3; + filter_count = (rule_count * 2) + 3; } else { filter_count = (rule_count * 2) + 1; // 1 is unseen field. } @@ -621,7 +621,7 @@ int emcore_get_mail_count_by_query(int account_id, int priority_sender, int *tot EM_DEBUG_EXCEPTION("emstorage_write_conditional_clause_for_getting_mail_list failed[%d]", err); goto FINISH_OFF; } - + EM_DEBUG_LOG("conditional_clause_string[%s]", conditional_clause_string); /* Search the mail of priority sender in DB */ @@ -651,7 +651,7 @@ FINISH_OFF: if (total_mail) *total_mail = total_count; - + if (unread_mail) *unread_mail = unread_count; @@ -664,14 +664,14 @@ FINISH_OFF: int emcore_display_unread_in_badge() { EM_DEBUG_FUNC_BEGIN(); - + int ret = false; int err = EMAIL_ERROR_NONE; int total_unread_count = 0; int total_mail_count = 0; int badge_ticker = 0; int priority_sender = 0; - + /* Get the Global noti ticker */ if (vconf_get_bool(VCONFKEY_TICKER_NOTI_BADGE_EMAIL, &badge_ticker) != 0) { @@ -714,21 +714,21 @@ int emcore_display_unread_in_badge() badge_error_e badge_err = BADGE_ERROR_NONE; bool exist; - if((badge_err = badge_is_existing("org.tizen.email", &exist)) != BADGE_ERROR_NONE) { + if((badge_err = badge_is_existing("com.samsung.email", &exist)) != BADGE_ERROR_NONE) { EM_DEBUG_EXCEPTION("badge_is_existing failed [%d]", badge_err); err = EMAIL_ERROR_BADGE_API_FAILED; goto FINISH_OFF; } if (!exist) { /* create badge */ - if((badge_err = badge_create("org.tizen.email", "/usr/bin/email-service")) != BADGE_ERROR_NONE) { + if((badge_err = badge_create("com.samsung.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("org.tizen.email", total_unread_count)) != BADGE_ERROR_NONE) { + if((badge_err = badge_set_count("com.samsung.email", total_unread_count)) != BADGE_ERROR_NONE) { EM_DEBUG_EXCEPTION("badge_set_count failed [%d]", badge_err); err = EMAIL_ERROR_BADGE_API_FAILED; goto FINISH_OFF; @@ -861,7 +861,7 @@ static int emcore_add_notification(int account_id, int mail_id, email_action_t a int err = EMAIL_ERROR_NONE; EM_DEBUG_FUNC_END("ret [%d]", err); - return err; + return err; } INTERNAL_FUNC int emcore_show_user_message(int id, email_action_t action, int error) @@ -881,7 +881,7 @@ INTERNAL_FUNC int emcore_show_user_message(int id, email_action_t action, int er EM_DEBUG_LOG("Invalid mail_id"); return false; } - + if (!emstorage_get_mail_by_id(id, &mail_table_data, true, NULL)) { EM_DEBUG_LOG("Mail not found"); return false; @@ -898,25 +898,25 @@ INTERNAL_FUNC int emcore_show_user_message(int id, email_action_t action, int er if (!emstorage_free_mail(&mail_table_data, 1, NULL)) EM_DEBUG_EXCEPTION("emstorage_free_mail Failed"); - + ret = true; } EM_DEBUG_FUNC_END("ret [%d]", ret); return ret; } - + /* storage space handling - 210709 */ int emcore_get_storage_status(void) { EM_DEBUG_FUNC_BEGIN(); int storage_status = 0, nError = 0; - + g_type_init(); -#ifdef STORAGE_STATUS +#ifdef STORAGE_STATUS nError = vconf_get_int(PS_KEY_SYSTEM_STORAGE_MOVI_STATUS, - &storage_status); + &storage_status); #endif /* STORAGE_STATUS */ if (nError == -1) { @@ -924,17 +924,17 @@ int emcore_get_storage_status(void) return false; } EM_DEBUG_FUNC_END(); - return storage_status; + return storage_status; } int emcore_is_storage_full(int *err_code) { EM_DEBUG_FUNC_BEGIN(); - + int ret = false; int err = EMAIL_ERROR_NONE; - struct statfs buf = {0}; - + struct statfs buf = {0}; + if (statfs(DATA_PATH, &buf) == -1) { EM_DEBUG_EXCEPTION("statfs(\"%s\") failed - %d", DATA_PATH, errno); err = EMAIL_ERROR_SYSTEM_FAILURE; @@ -947,10 +947,10 @@ int emcore_is_storage_full(int *err_code) if (i_free < EMAIL_LIMITATION_FREE_SPACE) err = EMAIL_ERROR_MAIL_MEMORY_FULL; } - + if (err == EMAIL_ERROR_MAIL_MEMORY_FULL) ret = true; - + FINISH_OFF: if (err_code != NULL) *err_code = err; @@ -966,20 +966,20 @@ int emcore_calc_mail_size(email_mail_data_t *input_mail_data, email_attachment_d int mail_size = 0; /* size of the plain text body and attachments */ int err = EMAIL_ERROR_NONE; int i = 0; - - if (!input_mail_data || (input_attachment_count && !input_attachment_data_list) || (!input_attachment_count &&input_attachment_data_list) || !output_size) { + + if (!input_mail_data || (input_attachment_count && !input_attachment_data_list) || (!input_attachment_count &&input_attachment_data_list) || !output_size) { EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM"); err = EMAIL_ERROR_INVALID_PARAM; goto FINISH_OFF; } - + if (input_mail_data->file_path_plain != NULL) { if (stat(input_mail_data->file_path_plain, &st_buf) < 0) { EM_DEBUG_EXCEPTION("input_mail_data->file_path_plain : stat(\"%s\") failed...", input_mail_data->file_path_plain); err = EMAIL_ERROR_INVALID_MAIL; goto FINISH_OFF; } - + mail_size += st_buf.st_size; } @@ -990,10 +990,10 @@ int emcore_calc_mail_size(email_mail_data_t *input_mail_data, email_attachment_d err = EMAIL_ERROR_INVALID_MAIL; goto FINISH_OFF; } - + mail_size += st_buf.st_size; } - + for(i = 0; i < input_attachment_count; i++) { if (stat(input_attachment_data_list[i].attachment_path, &st_buf) < 0) { EM_DEBUG_EXCEPTION("stat(\"%s\") failed...", input_attachment_data_list[i].attachment_path); @@ -1004,9 +1004,9 @@ int emcore_calc_mail_size(email_mail_data_t *input_mail_data, email_attachment_d } *output_size = mail_size; - + FINISH_OFF: - + EM_DEBUG_FUNC_END("mail_size [%d]", mail_size); return err; } @@ -1022,11 +1022,11 @@ char *emcore_get_alias_of_mailbox(const char *mailbox_path) gchar **token_list = NULL; gchar *mailbox = NULL, *name = NULL; char *converted_name; - - + + mailbox = g_strdup(mailbox_path); token_list = g_strsplit_set(mailbox, "/", -1); - + if (mailbox) g_free(mailbox); @@ -1040,7 +1040,7 @@ char *emcore_get_alias_of_mailbox(const char *mailbox_path) g_strfreev(token_list); converted_name = emcore_convert_mutf7_to_utf8(name); - + if (name) g_free(name); @@ -1065,7 +1065,7 @@ static int emcore_get_first_address(const char *full_address, char **alias, char char *address_start = NULL; char *address_end = NULL; char *first_address = NULL; - + if (full_address){ s = (char *)strchr((char *)full_address, ';'); if (s == NULL) @@ -1075,7 +1075,7 @@ static int emcore_get_first_address(const char *full_address, char **alias, char /* get alias */ *alias = NULL; - if ((alias_start = (char *)strchr((char *)first_address, '\"'))){ + if ((alias_start = (char *)strchr((char *)first_address, '\"'))){ alias_start++; alias_cursor = alias_start; while ((alias_cursor = (char *)strchr((char *)(alias_cursor), '\"'))){ @@ -1085,7 +1085,7 @@ static int emcore_get_first_address(const char *full_address, char **alias, char break; } if (alias_end) { /* there is "alias" */ - *alias = strndup(alias_start, alias_end - alias_start); + *alias = strndup(alias_start, alias_end - alias_start); EM_DEBUG_LOG("alias [%s]", *alias); } } @@ -1096,7 +1096,7 @@ static int emcore_get_first_address(const char *full_address, char **alias, char s = first_address; else s = alias_end+1; - if ((address_start = (char *)strchr((char *)s, '<'))){ + 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)> ... */ @@ -1108,9 +1108,9 @@ static int emcore_get_first_address(const char *full_address, char **alias, char } EM_SAFE_FREE(first_address); - EM_DEBUG_FUNC_END(); + EM_DEBUG_FUNC_END(); return true; -} +} void emcore_fill_address_information_of_mail_tbl(emstorage_mail_tbl_t *mail_data) { @@ -1140,7 +1140,7 @@ void emcore_fill_address_information_of_mail_tbl(emstorage_mail_tbl_t *mail_data recipient = mail_data->full_address_cc; else if (mail_data->full_address_bcc != NULL) recipient = mail_data->full_address_bcc; - + if (emcore_get_first_address(recipient, &first_alias, &first_address) == true) { if (first_alias == NULL) mail_data->alias_recipient = EM_SAFE_STRDUP(first_address); @@ -1149,14 +1149,14 @@ void emcore_fill_address_information_of_mail_tbl(emstorage_mail_tbl_t *mail_data mail_data->email_address_recipient = first_address; } - EM_DEBUG_FUNC_END(); + EM_DEBUG_FUNC_END(); } int emcore_get_preview_text_from_file(const char *input_plain_path, const char *input_html_path, int input_preview_buffer_length, char **output_preview_buffer) { EM_DEBUG_FUNC_BEGIN("input_plain_path[%p], input_html_path[%p], input_preview_buffer_length [%d], output_preview_buffer[%p]", input_plain_path, input_html_path, input_preview_buffer_length, output_preview_buffer); - + int err = EMAIL_ERROR_NONE; unsigned int byte_read = 0; unsigned int byte_written = 0; @@ -1249,7 +1249,6 @@ int emcore_get_preview_text_from_file(const char *input_plain_path, const char * } goto FINISH_OFF; } - reg_replace(local_preview_text, CR_STRING, " "); reg_replace(local_preview_text, LF_STRING, " "); reg_replace(local_preview_text, TAB_STRING, " "); @@ -1270,7 +1269,7 @@ int emcore_get_preview_text_from_file(const char *input_plain_path, const char * EM_DEBUG_EXCEPTION("g_convert failed"); goto FINISH_OFF; } - + EM_DEBUG_LOG("Extract the preview text, again"); utf8_encoded_string = (char *)g_convert(local_preview_text, byte_read, "UTF-8", encoding_type, &byte_read, &byte_written, &glib_error); @@ -1279,7 +1278,7 @@ int emcore_get_preview_text_from_file(const char *input_plain_path, const char * goto FINISH_OFF; } - } + } EM_SAFE_FREE(local_preview_text); local_preview_text = utf8_encoded_string; } @@ -1292,7 +1291,7 @@ FINISH_OFF: EM_SAFE_FREE(local_preview_text); EM_SAFE_FREE(encoding_type); - + if (fp_html != NULL) fclose(fp_html); @@ -1314,7 +1313,7 @@ INTERNAL_FUNC int emcore_add_transaction_info(int mail_id, int handle , int *err EM_DEBUG_LOG("g_transaction_info_list[%p]", g_transaction_info_list); pTransinfo = g_transaction_info_list ; - + if (!(pTemp = em_malloc(sizeof(em_transaction_info_type_t)))) { EM_DEBUG_EXCEPTION("malloc failed..."); err = EMAIL_ERROR_OUT_OF_MEMORY; @@ -1322,7 +1321,7 @@ INTERNAL_FUNC int emcore_add_transaction_info(int mail_id, int handle , int *err } pTemp->mail_id = mail_id ; pTemp->handle = handle; - + if (!pTransinfo) { pTransinfo = pTemp ; g_transaction_info_list = pTransinfo ; @@ -1333,13 +1332,13 @@ INTERNAL_FUNC int emcore_add_transaction_info(int mail_id, int handle , int *err pTransinfo->next = pTemp; } ret = true ; - + FINISH_OFF: if (err_code) *err_code = err; EM_DEBUG_FUNC_END("g_transaction_info_list[%p]", g_transaction_info_list); - return ret; + return ret; } INTERNAL_FUNC int emcore_get_handle_by_mailId_from_transaction_info(int mail_id, int *pHandle) @@ -1348,7 +1347,7 @@ INTERNAL_FUNC int emcore_get_handle_by_mailId_from_transaction_info(int mail_id, int ret = false; em_transaction_info_type_t *pTransinfo = NULL ; - + if (g_transaction_info_list == NULL) { EM_DEBUG_EXCEPTION("g_transaction_info_list NULL"); return false; @@ -1404,7 +1403,7 @@ INTERNAL_FUNC int emcore_delete_transaction_info_by_mailId(int mail_id ) } else { pTransinfo = pTransinfo->next ; - } + } }while (pTransinfo); EM_DEBUG_FUNC_END(); @@ -1417,16 +1416,16 @@ INTERNAL_FUNC int emcore_delete_transaction_info_by_mailId(int mail_id ) int reg_replace (char *input_source_text, char *input_old_pattern_string, char *input_new_string) { EM_DEBUG_FUNC_BEGIN("input_source_text [%p], input_old_pattern_string [%p], input_new_string [%p]", input_source_text, input_old_pattern_string, input_new_string); - int error_code = EMAIL_ERROR_NONE; + int error_code = EMAIL_ERROR_NONE; char *pos = NULL; int so, n, nmatch, source_text_length, n_count = 1; - regmatch_t *pmatch = NULL; + regmatch_t *pmatch = NULL; regex_t reg_pattern; if(!input_source_text || !input_old_pattern_string || !input_new_string) { EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM"); error_code = EMAIL_ERROR_INVALID_PARAM; - goto FINISH_OFF; + goto FINISH_OFF; } source_text_length = EM_SAFE_STRLEN(input_source_text); @@ -1440,26 +1439,26 @@ int reg_replace (char *input_source_text, char *input_old_pattern_string, char * if(nmatch < 1) { EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_DATA"); error_code = EMAIL_ERROR_INVALID_DATA; - goto FINISH_OFF; + goto FINISH_OFF; } - + pmatch = (regmatch_t*)em_malloc(sizeof(regmatch_t) * nmatch); if(pmatch == NULL) { EM_DEBUG_EXCEPTION("EMAIL_ERROR_OUT_OF_MEMORY"); error_code = EMAIL_ERROR_OUT_OF_MEMORY; - goto FINISH_OFF; + goto FINISH_OFF; } - + for (pos = input_new_string; *pos ; pos++) { if (*pos == '\\' && *(pos + 1) > '0' && *(pos + 1) <= '9') { - + so = pmatch[*(pos + 1) - 48].rm_so; n = pmatch[*(pos + 1) - 48].rm_eo - so; EM_DEBUG_LOG("so [%d], n [%d]", so, n); - - if (so < 0 || EM_SAFE_STRLEN (input_new_string) + n - 1 > source_text_length) + + if (so < 0 || EM_SAFE_STRLEN (input_new_string) + n - 1 > source_text_length) break; memmove (pos + n, pos + 2, EM_SAFE_STRLEN (pos) - 1); @@ -1467,7 +1466,7 @@ int reg_replace (char *input_source_text, char *input_old_pattern_string, char * pos = pos + n - 2; } } - + for (pos = input_source_text; !regexec (®_pattern, pos, 1, pmatch, 0);) { n = pmatch[0].rm_eo - pmatch[0].rm_so; pos += pmatch[0].rm_so; @@ -1477,12 +1476,12 @@ int reg_replace (char *input_source_text, char *input_old_pattern_string, char * pos += EM_SAFE_STRLEN (input_new_string); n_count++; } - + FINISH_OFF: EM_SAFE_FREE(pmatch); regfree (®_pattern); - + EM_DEBUG_FUNC_END("error_code [%d]", error_code); return error_code; } @@ -1493,7 +1492,7 @@ int emcore_strip_HTML(char *source_string) EM_DEBUG_FUNC_BEGIN("source_string [%p]", source_string); int result = EMAIL_ERROR_NONE; - + reg_replace(source_string, CR_STRING, " "); reg_replace(source_string, LF_STRING, " "); reg_replace(source_string, "<head[^>]*>", "<head>"); /* "<()*head([^>])*>", "<head>" */ @@ -1599,7 +1598,7 @@ int emcore_update_notification_for_unread_mail(int account_id) int i, account_count = 0; int err = EMAIL_ERROR_NONE; emstorage_account_tbl_t *p_account_tbl = NULL; - + if (!emstorage_get_account_list(&account_count, &p_account_tbl, true, false, &err)) { EM_DEBUG_EXCEPTION("emstorage_get_account_list failed [%d]", err); goto FINISH_OFF; @@ -1638,7 +1637,7 @@ INTERNAL_FUNC int emcore_finalize_sync(int account_id, int *error) if (!emcore_update_notification_for_unread_mail(ALL_ACCOUNT)) EM_DEBUG_EXCEPTION("emcore_update_notification_for_unread_mail failed"); - if (!emcore_display_unread_in_badge()) + if (!emcore_display_unread_in_badge()) EM_DEBUG_EXCEPTION("emcore_display_unread_in_badge failed"); emcore_start_alert(); @@ -1656,7 +1655,7 @@ INTERNAL_FUNC int emcore_clear_all_notifications() 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; @@ -1683,7 +1682,7 @@ INTERNAL_FUNC int emcore_delete_notification_by_account(int account_id) int error_code = EMAIL_ERROR_NONE; int private_id = 0; char vconf_private_id[MAX_PATH] = {0, }; - + SNPRINTF(vconf_private_id, sizeof(vconf_private_id), "%s/%d", VCONF_KEY_NOTI_PRIVATE_ID, account_id); if (vconf_get_int(vconf_private_id, &private_id) != 0) { EM_DEBUG_EXCEPTION("vconf_get_int failed"); @@ -1701,14 +1700,14 @@ INTERNAL_FUNC int emcore_delete_notification_by_account(int account_id) *@author h.gahlaut@samsung.com * @param[in] id_set Specifies the array of mail_id and corresponding server_mail_id sorted by server_mail_ids in ascending order * @param[in] id_set_count Specifies the no. of cells in id_set array i.e. no. of sets of mail_ids and server_mail_ids - * @param[in] range_len Specifies the maximum length of string of range allowed. + * @param[in] range_len Specifies the maximum length of string of range allowed. * @param[out] uid_range_set Returns the uid_ranges formed in the form of a linked list with head stored in uid_range_set pointer * @param[out] err_code Returns the error code. - * @remarks An example of a uid_range formed is 2:6,8,10,14:15,89, + * @remarks An example of a uid_range formed is 2:6,8,10,14:15,89, * While using it the caller should remove the ending, (comma) * @return This function returns true on success or false on failure. */ - + INTERNAL_FUNC int emcore_convert_to_uid_range_set(email_id_set_t *id_set, int id_set_count, email_uid_range_set **uid_range_set, int range_len, int *err_code) { EM_DEBUG_FUNC_BEGIN(); @@ -1726,8 +1725,8 @@ INTERNAL_FUNC int emcore_convert_to_uid_range_set(email_id_set_t *id_set, int id unsigned long current_uid = 0; unsigned long first_uid = 0; unsigned long last_uid = 0; - const int max_subset_string_size = MAX_SUBSET_STRING_SIZE; - char subset_string[MAX_SUBSET_STRING_SIZE] = {0,}; + const int max_subset_string_size = MAX_SUBSET_STRING_SIZE; + char subset_string[MAX_SUBSET_STRING_SIZE] = {0,}; email_uid_range_set *current_node = NULL; /* current_node denotes the current node under processing in the linked list of uid_range_set that is to be formed*/ if (range_len < (max_subset_string_size + 1)) /* 1 for ending NULL character */ { @@ -1735,16 +1734,16 @@ INTERNAL_FUNC int emcore_convert_to_uid_range_set(email_id_set_t *id_set, int id error = EMAIL_ERROR_INVALID_PARAM; goto FINISH_OFF; } - + EM_DEBUG_LOG("id set count[%d] range_len[%d]", id_set_count, range_len); - + do { first_uid = last_uid = current_uid = id_set[i].server_mail_id; /* Start subset string by putting first server mail id in it from id_set*/ memset(subset_string, 0x00, max_subset_string_size); SNPRINTF(subset_string, max_subset_string_size, "%lu", first_uid); ++i; - + /* Check if only one server mail id was left in id_set */ if (i >= id_set_count) { /* No more server mail id left in id_set */ @@ -1760,24 +1759,24 @@ INTERNAL_FUNC int emcore_convert_to_uid_range_set(email_id_set_t *id_set, int id current_uid = id_set[i].server_mail_id; if (current_uid == (last_uid + 1)) { last_uid = current_uid; - ++i; + ++i; } - else { + else { memset(subset_string, 0x00, max_subset_string_size); if (first_uid != last_uid) /* Form subset string by first_uid:last_uid */ SNPRINTF(subset_string, max_subset_string_size, "%lu:%lu", first_uid, last_uid); else /* Form subset string by first_uid */ SNPRINTF(subset_string, max_subset_string_size, "%lu", first_uid); - + if (false == emcore_append_subset_string_to_uid_range(subset_string, ¤t_node, uid_range_set, range_len, first_uid, last_uid)) { EM_DEBUG_EXCEPTION("emcore_append_subset_string_to_uid_range failed"); goto FINISH_OFF; } /* To Start formation of new subset string break out of inner loop */ - break; + break; } - - } while (i < id_set_count); + + } while (i < id_set_count); /* Flow comes here in two cases : 1. id_set ended and has continuous numbers at end of id_set so form subset string by first_uid:last_uid . in this case last_uid == current_uid @@ -1785,10 +1784,10 @@ INTERNAL_FUNC int emcore_convert_to_uid_range_set(email_id_set_t *id_set, int id if (last_uid == current_uid) { /* Case 1 */ - + memset(subset_string, 0x00, max_subset_string_size); SNPRINTF(subset_string, max_subset_string_size, "%lu:%lu", first_uid, last_uid); - + if (false == emcore_append_subset_string_to_uid_range(subset_string, ¤t_node, uid_range_set, range_len, first_uid, last_uid)) { EM_DEBUG_EXCEPTION("emcore_append_subset_string_to_uid_range failed"); goto FINISH_OFF; @@ -1797,36 +1796,36 @@ INTERNAL_FUNC int emcore_convert_to_uid_range_set(email_id_set_t *id_set, int id else { /* Case 2: Do Nothing */ } - - } + + } } while (i < id_set_count); ret = true; - + FINISH_OFF: if (NULL != err_code) *err_code = error; EM_DEBUG_FUNC_END(); return ret; - -} + +} /** * @fn emcore_append_subset_string_to_uid_range(char *subset_string, email_uid_range_set **uid_range_set, int range_len, unsigned long luid, unsigned long huid) - * Appends the subset_string to uid range if the uid range has not exceeded maximum length(range_len), otherwise creates a new node in linked list of uid range set + * Appends the subset_string to uid range if the uid range has not exceeded maximum length(range_len), otherwise creates a new node in linked list of uid range set * and stores the subset_string in its uid_range. Also sets the lowest and highest uids for the corresponsing uid_range - * + * * @author h.gahlaut@samsung.com * @param[in] subset_string Specifies the subset string to be appended. A subset string can be like X:Y or X where X and Y are uids. - * @param[in] range_len Specifies the maximum length of range string allowed. + * @param[in] range_len Specifies the maximum length of range string allowed. * @param[in] luid Specifies the lowest uid in subset string * @param[in] huid Specifies the highest uid in subset string * @param[out] uid_range_set Returns the uid_ranges formed in the form of a linked list with head stored in uid_range_set pointer * @param[out] err_code Returns the error code. - * @remarks + * @remarks * @return This function returns true on success or false on failure. */ - + int emcore_append_subset_string_to_uid_range(char *subset_string, email_uid_range_set **current_node_adr, email_uid_range_set **uid_range_set, int range_len, unsigned long luid, unsigned long huid) { EM_DEBUG_FUNC_BEGIN(); @@ -1838,10 +1837,10 @@ int emcore_append_subset_string_to_uid_range(char *subset_string, email_uid_rang if (NULL == current_node) { EM_DEBUG_EXCEPTION("em_malloc failed"); return false; - } + } current_node->uid_range = (char *)em_malloc(range_len); - + if (NULL == current_node->uid_range) { EM_DEBUG_EXCEPTION("em_malloc failed"); EM_SAFE_FREE(current_node); @@ -1854,8 +1853,8 @@ int emcore_append_subset_string_to_uid_range(char *subset_string, email_uid_rang current_node->highest_uid = huid; (*uid_range_set) = current_node; - (*current_node_adr) = current_node; - + (*current_node_adr) = current_node; + } else { /* Apart from first call to this function flow will always come here */ @@ -1880,7 +1879,7 @@ int emcore_append_subset_string_to_uid_range(char *subset_string, email_uid_rang } /* Allocate uid_range of new node */ - + new_node->uid_range = (char *)em_malloc(range_len); if (NULL == new_node->uid_range) { @@ -1896,7 +1895,7 @@ int emcore_append_subset_string_to_uid_range(char *subset_string, email_uid_rang current_node->next = new_node; - (*current_node_adr) = new_node; + (*current_node_adr) = new_node; } } EM_DEBUG_FUNC_END(); @@ -1905,14 +1904,14 @@ int emcore_append_subset_string_to_uid_range(char *subset_string, email_uid_rang /** * void emcore_free_uid_range_set(email_uid_range_set **uid_range_head) - * Frees the linked list of uid ranges + * Frees the linked list of uid ranges * * @author h.gahlaut@samsung.com - * @param[in] uid_range_head Head pointer of linked list of uid ranges - * @remarks + * @param[in] uid_range_head Head pointer of linked list of uid ranges + * @remarks * @return This function does not return anything. */ - + INTERNAL_FUNC void emcore_free_uid_range_set(email_uid_range_set **uid_range_set) { @@ -1920,10 +1919,10 @@ void emcore_free_uid_range_set(email_uid_range_set **uid_range_set) email_uid_range_set *current_node = NULL; email_uid_range_set *uid_range_head = NULL; - + current_node = uid_range_head = (*uid_range_set); /* Make the current node and head ptr point to starting of uid_range_set */ - while (current_node) { + while (current_node) { uid_range_head = current_node->next; /* Move the head ptr to next node*/ EM_SAFE_FREE(current_node->uid_range); @@ -1939,11 +1938,11 @@ void emcore_free_uid_range_set(email_uid_range_set **uid_range_set) /** * @fn emcore_form_comma_separated_strings(int numbers[], int num_count, int max_string_len, char *** strings, int *string_count, int *err_code) - * Forms comma separated strings of a give max_string_len from an array of numbers - * + * Forms comma separated strings of a give max_string_len from an array of numbers + * * @author h.gahlaut@samsung.com * @param[in] numbers Specifies the array of numbers to be converted into comma separated strings. - * @param[in] num_count Specifies the count of numbers in numbers array. + * @param[in] num_count Specifies the count of numbers in numbers array. * @param[in] max_string_len Specifies the maximum length of comma separated strings that are to be formed. * @param[out] strings Returns the base address of a double dimension array which stores the strings. * @param[out] string_count Returns the number of strings formed. @@ -1987,23 +1986,23 @@ INTERNAL_FUNC int emcore_form_comma_separated_strings(int numbers[], int num_cou EM_DEBUG_EXCEPTION("em_malloc failed "); goto FINISH_OFF; } - + string_list[num_of_strings] = em_malloc(max_string_len); - + if (NULL == string_list[num_of_strings]) { EM_DEBUG_EXCEPTION("em_malloc failed "); goto FINISH_OFF; } - + ++num_of_strings; space_in_buffer = max_string_len; - + for (j = 0; j < num_count;++j) { memset(num, 0x00, MAX_INTEGER_LENGTH + 1); SNPRINTF(num, MAX_INTEGER_LENGTH + 1, "%d", numbers[j]); num_len = EM_SAFE_STRLEN(num); - + len_of_string_formed = EM_SAFE_STRLEN(string_list[num_of_strings - 1]); space_in_buffer = max_string_len - len_of_string_formed ; @@ -2012,11 +2011,11 @@ INTERNAL_FUNC int emcore_form_comma_separated_strings(int numbers[], int num_cou SNPRINTF(string_list[num_of_strings - 1] + len_of_string_formed, max_string_len, "%d,", numbers[j]); } else { /* Removing comma at end of string */ - string_list[num_of_strings - 1][len_of_string_formed-1] = '\0'; + string_list[num_of_strings - 1][len_of_string_formed-1] = '\0'; char **temp = NULL; temp = (char **)realloc(string_list, sizeof(char *) * (num_of_strings + 1)); /* Allocate new buffer to store a pointer to a new string */ - if (NULL == temp) { + if (NULL == temp) { EM_DEBUG_EXCEPTION("realloc failed"); goto FINISH_OFF; } @@ -2038,7 +2037,7 @@ INTERNAL_FUNC int emcore_form_comma_separated_strings(int numbers[], int num_cou /* Removing comma at end of string */ len_of_string_formed = EM_SAFE_STRLEN(string_list[num_of_strings - 1]); - string_list[num_of_strings - 1][len_of_string_formed-1] = '\0'; + string_list[num_of_strings - 1][len_of_string_formed-1] = '\0'; ret = true; FINISH_OFF: @@ -2052,7 +2051,7 @@ FINISH_OFF: *strings = string_list; *string_count = num_of_strings; } - + if (NULL != err_code) *err_code = error; @@ -2062,12 +2061,12 @@ FINISH_OFF: } /** * @fn emcore_free_comma_separated_strings(char *** string_list, int *string_count) - * Frees the double dimensional array of strings. + * Frees the double dimensional array of strings. * * @author h.gahlaut@samsung.com * @param[in] uid_range_head Address of base address of double dimensional array of strings. * @param[in] string_count Address of variable holding the count of strings. - * @remarks + * @remarks * @return This function does not return anything. */ INTERNAL_FUNC void emcore_free_comma_separated_strings(char *** string_list, int *string_count) @@ -2085,7 +2084,7 @@ INTERNAL_FUNC void emcore_free_comma_separated_strings(char *** string_list, int for (i = 0; i < count; ++i) EM_SAFE_FREE(str_list[i]); } - + EM_SAFE_FREE(str_list); *string_list = NULL; /* This makes the pointer to be freed as NULL in calling function and saves it from being a dangling pointer for sometime in calling function */ *string_count = 0; @@ -2111,7 +2110,7 @@ int emcore_make_attachment_file_name_with_extension(char *source_file_name, char err = EMAIL_ERROR_INVALID_PARAM; goto FINISH_OFF; } - + strncpy(attachment_file_name, source_file_name, MAX_PATH); extcheck = strchr(attachment_file_name, '.'); @@ -2143,13 +2142,13 @@ FINISH_OFF: INTERNAL_FUNC int emcore_add_activity(emstorage_activity_tbl_t *new_activity, int *err_code) { EM_DEBUG_FUNC_BEGIN(); - + EM_DEBUG_LOG("\t new_activity[%p], err_code[%p]", new_activity, err_code); /* default variable */ int ret = false; int err = EMAIL_ERROR_NONE; - + if (!new_activity) { EM_DEBUG_LOG("\t new_activity[%p]\n", new_activity); err = EMAIL_ERROR_INVALID_PARAM; @@ -2157,74 +2156,74 @@ INTERNAL_FUNC int emcore_add_activity(emstorage_activity_tbl_t *new_activity, in } if (!emstorage_add_activity(new_activity, false, &err)) { EM_DEBUG_LOG("\t emstorage_add_activity falied - %d\n", err); - + goto FINISH_OFF; } ret = true; - + FINISH_OFF: if (err_code) *err_code = err; - + return ret; } INTERNAL_FUNC int emcore_delete_activity(emstorage_activity_tbl_t *activity, int *err_code) { EM_DEBUG_FUNC_BEGIN(); - + EM_DEBUG_LOG("\t new_activity[%p], err_code[%p]", activity, err_code); - + /* default variable */ int ret = false; int err = EMAIL_ERROR_NONE; if (!activity) { EM_DEBUG_LOG("\t new_activity[%p]\n", activity); - + err = EMAIL_ERROR_INVALID_PARAM; goto FINISH_OFF; } if (!emstorage_delete_local_activity(activity, true, &err)) { EM_DEBUG_LOG("\t emstorage_delete_local_activity falied - %d\n", err); - + goto FINISH_OFF; } ret = true; - + FINISH_OFF: if (err_code) *err_code = err; - + return ret; } INTERNAL_FUNC int emcore_get_next_activity_id(int *activity_id, int *err_code) { EM_DEBUG_FUNC_BEGIN(); - + int ret = false; int err = EMAIL_ERROR_NONE; if (NULL == activity_id) { EM_DEBUG_EXCEPTION("\t activity_id[%p]", activity_id); - + err = EMAIL_ERROR_INVALID_PARAM; goto FINISH_OFF; } - + if (false == emstorage_get_next_activity_id(activity_id, &err)) { EM_DEBUG_LOG("\t emstorage_get_next_activity_id failed - %d\n", err); goto FINISH_OFF; } - + ret = true; - + FINISH_OFF: if (NULL != err_code) { *err_code = err; } - + return ret; } @@ -2295,11 +2294,11 @@ FINISH_OFF: EM_DEBUG_LOG("Search string[%s] not found",search_string); *result = p_result; - + if (fp) fclose(fp); - EM_SAFE_FREE(buf); + EM_SAFE_FREE(buf); EM_SAFE_FREE(stripped); /*prevent 35586*/ EM_DEBUG_FUNC_END("error:[%d]", error); diff --git a/email-core/email-device/email-device.c b/email-core/email-device/email-device.c index 6a6ebbd..9af7104 100755 --- a/email-core/email-device/email-device.c +++ b/email-core/email-device/email-device.c @@ -1,7 +1,7 @@ /* * email-service * -* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> * diff --git a/email-core/email-device/include/email-device.h b/email-core/email-device/include/email-device.h index 3e9a004..b4d056a 100755 --- a/email-core/email-device/include/email-device.h +++ b/email-core/email-device/include/email-device.h @@ -1,7 +1,7 @@ /* * email-service * -* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> * diff --git a/email-core/email-network/email-network.c b/email-core/email-network/email-network.c index c772cde..5bb3783 100755 --- a/email-core/email-network/email-network.c +++ b/email-core/email-network/email-network.c @@ -1,7 +1,7 @@ /* * email-service * -* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> * diff --git a/email-core/email-network/include/email-network.h b/email-core/email-network/include/email-network.h index 976be52..db56240 100755 --- a/email-core/email-network/include/email-network.h +++ b/email-core/email-network/include/email-network.h @@ -1,7 +1,7 @@ /* * email-service * -* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> * diff --git a/email-core/email-storage/email-storage.c b/email-core/email-storage/email-storage.c index bde1bec..c56df87 100755 --- a/email-core/email-storage/email-storage.c +++ b/email-core/email-storage/email-storage.c @@ -1,10 +1,10 @@ /* * email-service * -* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* 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 @@ -36,7 +36,7 @@ #include <stdbool.h> #include <time.h> #include <sys/types.h> -#include <sys/time.h> +#include <sys/time.h> #include <sys/wait.h> #include <glib.h> #include <sys/stat.h> @@ -138,7 +138,7 @@ #define STANDARD_NAME_LEN_IN_MAIL_MEETING_TBL 32 #define DAYLIGHT_NAME_LEN_IN_MAIL_MEETING_TBL 32 #define PREVIEWBODY_LEN_IN_MAIL_TBL 512 -#define CERTIFICATE_PATH_LEN_IN_MAIL_ACCOUNT_TBL 256 +#define CERTIFICATE_PATH_LEN_IN_MAIL_ACCOUNT_TBL 256 /* this define is used for query to change data (delete, insert, update) */ #define EMSTORAGE_START_WRITE_TRANSACTION(transaction_flag, error_code) \ @@ -211,7 +211,7 @@ typedef struct db_handle_t _db_handle_list[MAX_DB_CLIENT] = {{0, 0}, }; sqlite3 *emstorage_get_db_handle() -{ +{ EM_DEBUG_FUNC_BEGIN(); int i; pthread_t current_thread_id = THREAD_SELF(); @@ -226,7 +226,7 @@ sqlite3 *emstorage_get_db_handle() } } LEAVE_CRITICAL_SECTION(_db_handle_lock); - + if (!result_db_handle) EM_DEBUG_EXCEPTION("Can't find proper handle for [%d]", current_thread_id); @@ -235,7 +235,7 @@ sqlite3 *emstorage_get_db_handle() } int emstorage_set_db_handle(sqlite3 *db_handle) -{ +{ EM_DEBUG_FUNC_BEGIN(); int i, error_code = EMAIL_ERROR_MAX_EXCEEDED; pthread_t current_thread_id = THREAD_SELF(); @@ -260,7 +260,7 @@ int emstorage_set_db_handle(sqlite3 *db_handle) } int emstorage_remove_db_handle() -{ +{ EM_DEBUG_FUNC_BEGIN(); int i, error_code = EMAIL_ERROR_MAX_EXCEEDED; ENTER_CRITICAL_SECTION(_db_handle_lock); @@ -276,7 +276,7 @@ int emstorage_remove_db_handle() } } LEAVE_CRITICAL_SECTION(_db_handle_lock); - + if (error_code == EMAIL_ERROR_MAX_EXCEEDED) EM_DEBUG_EXCEPTION("Can't find proper thread_id"); @@ -286,7 +286,7 @@ int emstorage_remove_db_handle() int emstorage_reset_db_handle_list() -{ +{ EM_DEBUG_FUNC_BEGIN(); int i; @@ -297,16 +297,16 @@ int emstorage_reset_db_handle_list() _db_handle_list[i].db_handle = NULL; } LEAVE_CRITICAL_SECTION(_db_handle_lock) - + EM_DEBUG_FUNC_END(); return EMAIL_ERROR_NONE; } sqlite3 *emstorage_get_db_connection() { - sqlite3 *tmp_db_handle = emstorage_get_db_handle(); + sqlite3 *tmp_db_handle = emstorage_get_db_handle(); if (NULL == tmp_db_handle) - tmp_db_handle = emstorage_db_open(NULL); + tmp_db_handle = emstorage_db_open(NULL); return tmp_db_handle; } @@ -319,14 +319,14 @@ sqlite3 *_db_handle = NULL; sqlite3 *emstorage_get_db_connection() { if (NULL == _db_handle) - emstorage_db_open(NULL); + emstorage_db_open(NULL); return _db_handle; } #endif /* _MULTIPLE_DB_HANDLE */ /* ------------------------------------------------------------------------------ */ /* Mutex using shared memory */ -typedef struct +typedef struct { pthread_mutex_t mutex; int data; @@ -361,12 +361,12 @@ INTERNAL_FUNC int emstorage_shm_file_init(const char *shm_file_name) if (fd > 0) { fchmod(fd, 0666); - EM_DEBUG_LOG("** Create SHM FILE **"); + EM_DEBUG_LOG("** Create SHM FILE **"); if (ftruncate(fd, sizeof(mmapped_t)) != 0) { EM_DEBUG_EXCEPTION("ftruncate failed: %s", strerror(errno)); 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", strerror(errno)); @@ -375,7 +375,7 @@ INTERNAL_FUNC int emstorage_shm_file_init(const char *shm_file_name) m->data = 0; - pthread_mutexattr_t mattr; + pthread_mutexattr_t mattr; pthread_mutexattr_init(&mattr); pthread_mutexattr_setpshared(&mattr, PTHREAD_PROCESS_SHARED); pthread_mutexattr_setrobust(&mattr, PTHREAD_MUTEX_ROBUST_NP); @@ -408,7 +408,7 @@ int emstorage_shm_file_destroy(const char *shm_file_name) static 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); - + if(!shm_file_name || !param_shm_fd || !param_mapped) { EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM"); return EMAIL_ERROR_INVALID_PARAM; @@ -425,7 +425,7 @@ static int _initialize_shm_mutex(const char *shm_file_name, int *param_shm_fd, m } } mmapped_t *tmp = (mmapped_t *)mmap(NULL, sizeof(mmapped_t), PROT_READ|PROT_WRITE, MAP_SHARED, (*param_shm_fd), 0); - + if (tmp == MAP_FAILED) { EM_DEBUG_EXCEPTION("mmap failed: %s", strerror(errno)); return EMAIL_ERROR_SYSTEM_FAILURE; @@ -440,34 +440,34 @@ static int _initialize_shm_mutex(const char *shm_file_name, int *param_shm_fd, m static int _timedlock_shm_mutex(mmapped_t **param_mapped, int sec) { EM_DEBUG_FUNC_BEGIN("param_mapped [%p], sec [%d]", param_mapped, sec); - + if(!param_mapped) { EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM"); return EMAIL_ERROR_INVALID_PARAM; } - struct timespec abs_time; + struct timespec abs_time; clock_gettime(CLOCK_REALTIME, &abs_time); abs_time.tv_sec += sec; int err = pthread_mutex_timedlock(&((*param_mapped)->mutex), &abs_time); - + if (err == EOWNERDEAD) { err = pthread_mutex_consistent(&((*param_mapped)->mutex)); EM_DEBUG_EXCEPTION("Previous owner is dead with lock. Fix mutex : %s", EM_STRERROR(err)); - } + } else if (err != 0) { EM_DEBUG_EXCEPTION("ERROR : %s", EM_STRERROR(err)); return err; } - + EM_DEBUG_FUNC_END(); return EMAIL_ERROR_NONE; } void _unlockshm_mutex(mmapped_t **param_mapped) { - EM_DEBUG_FUNC_BEGIN(); + EM_DEBUG_FUNC_BEGIN(); pthread_mutex_unlock(&((*param_mapped)->mutex)); EM_DEBUG_FUNC_END(); } @@ -540,11 +540,11 @@ enum ISSUE_DAY_IDX_IN_MAIL_CERTIFICATE_TBL, EXPIRE_YEAR_IDX_IN_MAIL_CERTIFICATE_TBL, EXPIRE_MONTH_IDX_IN_MAIL_CERTIFICATE_TBL, - EXPIRE_DAY_IDX_IN_MAIL_CERTIFICATE_TBL, + EXPIRE_DAY_IDX_IN_MAIL_CERTIFICATE_TBL, ISSUE_ORGANIZATION_IDX_IN_MAIL_CERTIFICATE_TBL, EMAIL_ADDRESS_IDX_IN_MAIL_CERTIFICATE_TBL, - SUBJECT_STRING_IDX_IN_MAIL_CERTIFICATE_TBL, - FILE_PATH_IDX_IN_MAIL_CERTIFICATE_TBL, + SUBJECT_STRING_IDX_IN_MAIL_CERTIFICATE_TBL, + FILE_PATH_IDX_IN_MAIL_CERTIFICATE_TBL, }; enum @@ -553,7 +553,7 @@ enum CC_RECIPIENT, BCC_RECIPIENT, }; -enum +enum { ACCOUNT_ID_IDX_IN_MAIL_BOX_TBL = 0, LOCAL_YN_IDX_IN_MAIL_BOX_TBL, @@ -567,7 +567,7 @@ enum MAIL_SLOT_SIZE_IDX_IN_MAIL_BOX_TBL, }; -enum +enum { ACCOUNT_ID_IDX_IN_MAIL_READ_MAIL_UID_TBL = 0, LOCAL_MAILBOX_ID_IDX_IN_MAIL_READ_MAIL_UID_TBL, @@ -580,7 +580,7 @@ enum IDX_NUM_IDX_IN_MAIL_READ_MAIL_UID_TBL, /* unused */ }; -enum +enum { ACCOUNT_ID_IDX_IN_MAIL_RULE_TBL = 0, RULE_ID_IDX_IN_MAIL_RULE_TBL, @@ -592,7 +592,7 @@ enum FLAG2_IDX_IN_MAIL_RULE_TBL, }; -enum +enum { MAIL_ID_IDX_IN_MAIL_TBL = 0, ACCOUNT_ID_IDX_IN_MAIL_TBL, @@ -645,7 +645,7 @@ enum FIELD_COUNT_OF_MAIL_TBL, /* End of mail_tbl */ }; -enum +enum { ATTACHMENT_ID_IDX_IN_MAIL_ATTACHMENT_TBL = 0, ATTACHMENT_NAME_IDX_IN_MAIL_ATTACHMENT_TBL, @@ -659,10 +659,10 @@ enum ATTACHMENT_DRM_METHOD_IDX_IN_MAIL_ATTACHMENT_TBL, ATTACHMENT_INLINE_CONTENT_STATUS_IDX_IN_MAIL_ATTACHMENT_TBL, ATTACHMENT_MIME_TYPE_IDX_IN_MAIL_ATTACHMENT_TBL, -#ifdef __ATTACHMENT_OPTI__ +#ifdef __ATTACHMENT_OPTI__ ENCODING_IDX_IN_MAIL_ATTACHMENT_TBL, SECTION_IDX_IN_MAIL_ATTACHMENT_TBL, -#endif +#endif }; enum { @@ -685,7 +685,7 @@ enum { /* sowmya.kr 03032010, changes for get list of mails for given addr list */ typedef struct _em_mail_id_list { - int mail_id; + int mail_id; struct _em_mail_id_list *next; } em_mail_id_list; @@ -716,7 +716,7 @@ static char *g_test_query[] = { " flag1, " " flag2, " " pop_before_smtp, " - " incoming_server_requires_apop" + " incoming_server_requires_apop" ", logo_icon_path, " " is_preset_account, " " check_interval, " @@ -914,9 +914,9 @@ static int _get_table_field_data_char(char **table, char *buf, int index) *buf = (char)atoi(table[index]); return true; } - + /* EM_DEBUG_LOG("Empty field. Set as zero"); */ - + *buf = 0; return false; } @@ -932,9 +932,9 @@ static int _get_table_field_data_int(char **table, int *buf, int index) *buf = atoi(table[index]); return true; } - + /* EM_DEBUG_LOG("Empty field. Set as zero"); */ - + *buf = 0; return false; } @@ -965,10 +965,10 @@ static int _get_table_field_data_string(char **table, char **buf, int ucs2, int EM_DEBUG_EXCEPTION("table[%p], buf[%p], index[%d]", table, buf, index); return false; } - + char *pTemp = table[index]; - int sLen = 0; - if (pTemp == NULL) + int sLen = 0; + if (pTemp == NULL) *buf = NULL; else { sLen = EM_SAFE_STRLEN(pTemp); @@ -980,7 +980,7 @@ static int _get_table_field_data_string(char **table, char **buf, int ucs2, int } strncpy(*buf, pTemp, sLen); } - else + else *buf = NULL; } #ifdef _PRINT_STORAGE_LOG_ @@ -988,7 +988,7 @@ static int _get_table_field_data_string(char **table, char **buf, int ucs2, int EM_DEBUG_LOG("_get_table_field_data_string - buf[%s], index[%d]", *buf, index); else EM_DEBUG_LOG("_get_table_field_data_string - No string got "); -#endif +#endif ret = true; FINISH_OFF: @@ -1015,7 +1015,7 @@ static int _get_table_field_data_string_without_allocation(char **table, char *b EM_DEBUG_LOG("_get_table_field_data_string - buf[%s], index[%d]", buf, index); else EM_DEBUG_LOG("_get_table_field_data_string - No string got "); -#endif +#endif return true; } @@ -1066,7 +1066,7 @@ static int _get_stmt_field_data_char(DB_STMT hStmt, char *buf, int index) #endif return true; } - + EM_DEBUG_LOG("sqlite3_column_int fail. index [%d]", index); return false; @@ -1086,7 +1086,7 @@ static int _get_stmt_field_data_int(DB_STMT hStmt, int *buf, int index) #endif return true; } - + EM_DEBUG_LOG("sqlite3_column_int fail. index [%d]", index); return false; @@ -1118,7 +1118,7 @@ static int _get_stmt_field_data_string(DB_STMT hStmt, char **buf, int ucs2, int return false; } - int sLen = 0; + int sLen = 0; sLen = sqlite3_column_bytes(hStmt, index); #ifdef _PRINT_STORAGE_LOG_ @@ -1137,7 +1137,7 @@ static int _get_stmt_field_data_string(DB_STMT hStmt, char **buf, int ucs2, int EM_DEBUG_LOG("buf[%s], index[%d]", *buf, index); else EM_DEBUG_LOG("_get_stmt_field_data_string - No string got"); -#endif +#endif return false; } @@ -1172,7 +1172,7 @@ static int _get_stmt_field_data_string_without_allocation(DB_STMT hStmt, char *b return false; } - int sLen = 0; + int sLen = 0; sLen = sqlite3_column_bytes(hStmt, index); #ifdef _PRINT_STORAGE_LOG_ @@ -1188,8 +1188,8 @@ static int _get_stmt_field_data_string_without_allocation(DB_STMT hStmt, char *b #ifdef _PRINT_STORAGE_LOG_ EM_DEBUG_LOG("buf[%s], index[%d]", buf, index); -#endif - +#endif + return false; } @@ -1201,12 +1201,12 @@ static int _bind_stmt_field_data_char(DB_STMT hStmt, int index, char value) } int ret = sqlite3_bind_int(hStmt, index+1, (int)value); - + if (ret != SQLITE_OK) { EM_DEBUG_EXCEPTION("sqlite3_bind_int fail - %d", ret); return false; } - + return true; } @@ -1216,14 +1216,14 @@ static int _bind_stmt_field_data_int(DB_STMT hStmt, int index, int value) EM_DEBUG_EXCEPTION("index[%d]", index); return false; } - + int ret = sqlite3_bind_int(hStmt, index+1, value); - + if (ret != SQLITE_OK) { EM_DEBUG_EXCEPTION("sqlite3_bind_int fail - %d", ret); return false; } - + return true; } @@ -1258,7 +1258,7 @@ static int _bind_stmt_field_data_string(DB_STMT hStmt, int index, char *value, i int ret = 0; if (value != NULL) ret = sqlite3_bind_text(hStmt, index+1, value, -1, SQLITE_STATIC); - else + else ret = sqlite3_bind_text(hStmt, index+1, "", -1, NULL); if (ret != SQLITE_OK) { @@ -1297,31 +1297,31 @@ static int _bind_stmt_field_data_blob(DB_STMT hStmt, int index, void *blob, int static int _delete_temp_file(const char *path) { EM_DEBUG_FUNC_BEGIN("path[%p]", path); - + DIR *dp = NULL; struct dirent *entry = NULL; - + char buf[1024] = {0x00, }; - + if ((dp = opendir(path)) == NULL) { EM_DEBUG_EXCEPTION("opendir(\"%s\") failed...", path); return false; } - + while ((entry = readdir(dp)) != NULL) { SNPRINTF(buf, sizeof(buf), "%s/%s", path, entry->d_name); remove(buf); } - - closedir(dp); - EM_DEBUG_FUNC_END(); + + closedir(dp); + EM_DEBUG_FUNC_END(); return true; } char *cpy_str(char *src) { char *p = NULL; - + if (src) { if (!(p = em_malloc((int)EM_SAFE_STRLEN(src) + 1))) { EM_DEBUG_EXCEPTION("mailoc failed..."); @@ -1329,37 +1329,37 @@ char *cpy_str(char *src) } strncpy(p, src, EM_SAFE_STRLEN(src)); } - + return p; } static void _emstorage_close_once(void) { EM_DEBUG_FUNC_BEGIN(); - + DELETE_CRITICAL_SECTION(_transactionBeginLock); DELETE_CRITICAL_SECTION(_transactionEndLock); - + EM_DEBUG_FUNC_END(); } INTERNAL_FUNC int emstorage_close(int *err_code) { EM_DEBUG_FUNC_BEGIN(); - + int ret = false; int error = EMAIL_ERROR_NONE; - emstorage_db_close(&error); - + emstorage_db_close(&error); + if (--_open_counter == 0) _emstorage_close_once(); - + ret = true; if (err_code != NULL) *err_code = error; - + EM_DEBUG_FUNC_END("ret [%d]", ret); return ret; } @@ -1367,29 +1367,29 @@ INTERNAL_FUNC int emstorage_close(int *err_code) static void *_emstorage_open_once(int *err_code) { EM_DEBUG_FUNC_BEGIN(); - + int error = EMAIL_ERROR_NONE; - + mkdir(USERDATA_PATH, DIRECTORY_PERMISSION); mkdir(DATA_PATH, DIRECTORY_PERMISSION); mkdir(EMAILPATH, DIRECTORY_PERMISSION); mkdir(MAILHOME, DIRECTORY_PERMISSION); mkdir(MAILTEMP, DIRECTORY_PERMISSION); - + _delete_temp_file(MAILTEMP); - + g_transaction = false; - + if (!emstorage_create_table(EMAIL_CREATE_DB_NORMAL, &error)) { EM_DEBUG_EXCEPTION(" emstorage_create_table failed - %d", error); goto FINISH_OFF; } - + FINISH_OFF: if (err_code != NULL) *err_code = error; - - + + return NULL; } @@ -1402,7 +1402,7 @@ static int _callback_sqlite_busy_handler(void *pData, int count) usleep(200000); /* sleep time when SQLITE_LOCK */ /* retry will be stopped if busy handler return 0 */ - return EMAIL_STORAGE_MAX_RETRY_COUNT - count; + return EMAIL_STORAGE_MAX_RETRY_COUNT - count; } static int _delete_all_files_and_directories(int *err_code) @@ -1415,7 +1415,7 @@ static int _delete_all_files_and_directories(int *err_code) if (!emstorage_delete_file(EMAIL_SERVICE_DB_FILE_PATH, &error)) { if (error != EMAIL_ERROR_FILE_NOT_FOUND) { EM_DEBUG_EXCEPTION("remove failed - %s", EMAIL_SERVICE_DB_FILE_PATH); - goto FINISH_OFF; + goto FINISH_OFF; } } @@ -1439,7 +1439,7 @@ static int _recovery_from_malformed_db_file(int *err_code) int error = EMAIL_ERROR_NONE; int ret = false; - + /* Delete all files and directories */ if (!_delete_all_files_and_directories(&error)) { EM_DEBUG_EXCEPTION("_delete_all_files_and_directories failed [%d]", error); @@ -1519,15 +1519,15 @@ INTERNAL_FUNC int em_db_open(sqlite3 **sqlite_handle, int *err_code) goto FINISH_OFF; } - + ret = true; - + FINISH_OFF: if (err_code != NULL) - *err_code = error; + *err_code = error; EM_DEBUG_FUNC_END("ret [%d]", ret); - return ret; + return ret; } INTERNAL_FUNC sqlite3* emstorage_db_open(int *err_code) @@ -1536,7 +1536,7 @@ INTERNAL_FUNC sqlite3* emstorage_db_open(int *err_code) #ifdef _MULTIPLE_DB_HANDLE sqlite3 *_db_handle = NULL; #endif - + int error = EMAIL_ERROR_NONE; _initialize_shm_mutex(SHM_FILE_FOR_DB_LOCK, &shm_fd_for_db_lock, &mapped_for_db_lock); @@ -1553,13 +1553,13 @@ INTERNAL_FUNC sqlite3* emstorage_db_open(int *err_code) #ifdef _MULTIPLE_DB_HANDLE emstorage_set_db_handle(_db_handle); #endif - + FINISH_OFF: if (err_code != NULL) - *err_code = error; + *err_code = error; EM_DEBUG_FUNC_END("ret [%p]", _db_handle); - return _db_handle; + return _db_handle; } INTERNAL_FUNC int emstorage_db_close(int *err_code) @@ -1568,7 +1568,7 @@ INTERNAL_FUNC int emstorage_db_close(int *err_code) #ifdef _MULTIPLE_DB_HANDLE sqlite3 *_db_handle = emstorage_get_db_handle(); #endif - + int error = EMAIL_ERROR_NONE; int ret = false; @@ -1577,7 +1577,7 @@ INTERNAL_FUNC int emstorage_db_close(int *err_code) if (_db_handle) { ret = db_util_close(_db_handle); - + if (ret != SQLITE_OK) { EM_DEBUG_EXCEPTION(" db_util_close fail - %d", ret); error = EMAIL_ERROR_DB_FAILURE; @@ -1591,20 +1591,20 @@ INTERNAL_FUNC int emstorage_db_close(int *err_code) } ret = true; - + FINISH_OFF: if (err_code != NULL) - *err_code = error; + *err_code = error; EM_DEBUG_FUNC_END("ret [%d]", ret); - return ret; + return ret; } INTERNAL_FUNC int emstorage_open(int *err_code) { EM_DEBUG_FUNC_BEGIN(); - + int ret = false; int error = EMAIL_ERROR_NONE; @@ -1620,15 +1620,15 @@ INTERNAL_FUNC int emstorage_open(int *err_code) goto FINISH_OFF; } - + if (_open_counter++ == 0) _emstorage_open_once(&error); ret = true; - + FINISH_OFF: if (err_code != NULL) - *err_code = error; + *err_code = error; EM_DEBUG_FUNC_END("ret [%d]", ret); return ret; @@ -1638,7 +1638,7 @@ FINISH_OFF: INTERNAL_FUNC int emstorage_create_table(emstorage_create_db_type_t type, int *err_code) { EM_DEBUG_FUNC_BEGIN(); - + int error = EMAIL_ERROR_NONE; int rc = -1, ret = false; char sql_query_string[QUERY_SIZE] = {0, }; @@ -1795,7 +1795,7 @@ INTERNAL_FUNC int emstorage_create_table(emstorage_create_db_type_t type, int *e ", smime_type INTEGER \n" ", FOREIGN KEY(account_id) REFERENCES mail_account_tbl(account_id) \n" "); \n ", - + /* 6. create mail_attachment_tbl */ "CREATE TABLE mail_attachment_tbl \n" "(\n" @@ -1890,14 +1890,14 @@ INTERNAL_FUNC int emstorage_create_table(emstorage_create_db_type_t type, int *e "); \n", NULL, }; - + sqlite3 *local_db_handle = emstorage_get_db_connection(); - + EM_DEBUG_LOG("local_db_handle = %p.", local_db_handle); char *sql; char **result; - + sql = "SELECT count(name) FROM sqlite_master WHERE name='mail_account_tbl';"; 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; }, @@ -1909,9 +1909,9 @@ 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_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); @@ -1919,21 +1919,21 @@ INTERNAL_FUNC int emstorage_create_table(emstorage_create_db_type_t type, int *e /* create mail_account_tbl unique index */ SNPRINTF(sql_query_string, sizeof(sql_query_string), "CREATE UNIQUE INDEX mail_account_idx1 ON mail_account_tbl (account_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))); - + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, "END;", NULL, NULL, NULL), rc); } /* mail_account_tbl */ - else if (type == EMAIL_CREATE_DB_CHECK) { + else if (type == EMAIL_CREATE_DB_CHECK) { EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, g_test_query[CREATE_TABLE_MAIL_ACCOUNT_TBL], NULL, NULL, NULL), rc); EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, ("SQL(%s) exec fail:%d -%s", g_test_query[CREATE_TABLE_MAIL_ACCOUNT_TBL], rc, sqlite3_errmsg(local_db_handle))); } - sqlite3_free_table(result); - - + sqlite3_free_table(result); + + /* 2. create mail_box_tbl */ sql = "SELECT count(name) FROM sqlite_master WHERE name='mail_box_tbl';"; @@ -1947,115 +1947,115 @@ 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_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))); - + /* create mail_local_mailbox_tbl unique index */ SNPRINTF(sql_query_string, sizeof(sql_query_string), "CREATE UNIQUE INDEX mail_box_idx1 ON mail_box_tbl (account_id, local_yn, mailbox_name)"); - + 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_box_tbl */ - else if (type == EMAIL_CREATE_DB_CHECK) { + else if (type == EMAIL_CREATE_DB_CHECK) { rc = sqlite3_exec(local_db_handle, g_test_query[CREATE_TABLE_MAIL_BOX_TBL], NULL, NULL, NULL); EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, ("SQL(%s) exec fail:%d -%s", g_test_query[CREATE_TABLE_MAIL_BOX_TBL], rc, sqlite3_errmsg(local_db_handle))); } - sqlite3_free_table(result); - + sqlite3_free_table(result); + /* 3. create mail_read_mail_uid_tbl */ sql = "SELECT count(name) FROM sqlite_master WHERE name='mail_read_mail_uid_tbl';"; 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_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))); - + /* create mail_read_mail_uid_tbl unique index */ SNPRINTF(sql_query_string, sizeof(sql_query_string), "CREATE UNIQUE INDEX mail_read_mail_uid_idx1 ON mail_read_mail_uid_tbl (account_id, mailbox_id, local_uid, mailbox_name, 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))); 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) { + else if (type == EMAIL_CREATE_DB_CHECK) { EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, g_test_query[CREATE_TABLE_MAIL_READ_MAIL_UID_TBL], NULL, NULL, NULL), rc); EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, ("SQL(%s) exec fail:%d -%s", g_test_query[CREATE_TABLE_MAIL_READ_MAIL_UID_TBL], rc, sqlite3_errmsg(local_db_handle))); } sqlite3_free_table(result); - - + + /* 4. create mail_rule_tbl */ sql = "SELECT count(name) FROM sqlite_master WHERE name='mail_rule_tbl';"; 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_rule_tbl"); - + EM_SAFE_STRNCPY(sql_query_string, create_table_query[CREATE_TABLE_MAIL_RULE_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))); EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, "END;", NULL, NULL, NULL), rc); - + } /* mail_rule_tbl */ - else if (type == EMAIL_CREATE_DB_CHECK) { + else if (type == EMAIL_CREATE_DB_CHECK) { EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, g_test_query[CREATE_TABLE_MAIL_RULE_TBL], NULL, NULL, NULL), rc); EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, ("SQL(%s) exec fail:%d -%s", g_test_query[CREATE_TABLE_MAIL_RULE_TBL], rc, sqlite3_errmsg(local_db_handle))); } sqlite3_free_table(result); - - + + /* 5. create mail_tbl */ sql = "SELECT count(name) FROM sqlite_master WHERE name='mail_tbl';"; 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_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))); - + /* create mail_tbl unique index */ SNPRINTF(sql_query_string, sizeof(sql_query_string), "CREATE UNIQUE INDEX mail_idx1 ON mail_tbl (mail_id, account_id)"); EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc); @@ -2075,18 +2075,18 @@ INTERNAL_FUNC int emstorage_create_table(emstorage_create_db_type_t type, int *e ("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); - + /* just one time call */ /* EFTSInitFTSIndex(FTS_EMAIL_IDX); */ } /* mail_tbl */ - else if (type == EMAIL_CREATE_DB_CHECK) { + else if (type == EMAIL_CREATE_DB_CHECK) { EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, g_test_query[CREATE_TABLE_MAIL_TBL], NULL, NULL, NULL), rc); EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, ("SQL(%s) exec fail:%d -%s", g_test_query[CREATE_TABLE_MAIL_TBL], rc, sqlite3_errmsg(local_db_handle))); } sqlite3_free_table(result); - - + + /* 6. create mail_attachment_tbl */ sql = "SELECT count(name) FROM sqlite_master WHERE name='mail_attachment_tbl';"; EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql, &result, NULL, NULL, NULL), rc); @@ -2098,59 +2098,59 @@ INTERNAL_FUNC int emstorage_create_table(emstorage_create_db_type_t type, int *e 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))); - + /* create mail_attachment_tbl unique index */ SNPRINTF(sql_query_string, sizeof(sql_query_string), "CREATE UNIQUE INDEX mail_attachment_idx1 ON mail_attachment_tbl (mail_id, attachment_id) "); - + 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) { + else if (type == EMAIL_CREATE_DB_CHECK) { EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, g_test_query[CREATE_TABLE_MAIL_ATTACHMENT_TBL], NULL, NULL, NULL), rc); EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, ("SQL(%s) exec fail:%d -%s", g_test_query[CREATE_TABLE_MAIL_ATTACHMENT_TBL], rc, sqlite3_errmsg(local_db_handle))); } sqlite3_free_table(result); - + #ifdef __FEATURE_PARTIAL_BODY_DOWNLOAD__ sql = "SELECT count(name) FROM sqlite_master WHERE name='mail_partial_body_activity_tbl';"; 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_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*/ - + 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) { + else if (type == EMAIL_CREATE_DB_CHECK) { EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, g_test_query[CREATE_TABLE_MAIL_PARTIAL_BODY_ACTIVITY_TBL], NULL, NULL, NULL), rc); EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, ("SQL(%s) exec fail:%d -%s", g_test_query[CREATE_TABLE_MAIL_PARTIAL_BODY_ACTIVITY_TBL], rc, sqlite3_errmsg(local_db_handle))); } sqlite3_free_table(result); - + #endif /* __FEATURE_PARTIAL_BODY_DOWNLOAD__ */ /* create mail_meeting_tbl */ @@ -2158,28 +2158,28 @@ INTERNAL_FUNC int emstorage_create_table(emstorage_create_db_type_t type, int *e 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_meeting_tbl"); - + EM_SAFE_STRNCPY(sql_query_string, create_table_query[CREATE_TABLE_MAIL_MEETING_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))); SNPRINTF(sql_query_string, sizeof(sql_query_string), "CREATE UNIQUE INDEX mail_meeting_idx1 ON mail_meeting_tbl (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))); 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) { + else if (type == EMAIL_CREATE_DB_CHECK) { EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, g_test_query[CREATE_TABLE_MAIL_MEETING_TBL], NULL, NULL, NULL), rc); EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, ("SQL(%s) exec fail:%d -%s", g_test_query[CREATE_TABLE_MAIL_MEETING_TBL], rc, sqlite3_errmsg(local_db_handle))); @@ -2187,36 +2187,36 @@ INTERNAL_FUNC int emstorage_create_table(emstorage_create_db_type_t type, int *e sqlite3_free_table(result); #ifdef __FEATURE_LOCAL_ACTIVITY__ - + sql = "SELECT count(name) FROM sqlite_master WHERE name='mail_local_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_local_activity_tbl"); - + SNPRINTF(sql_query_string, sizeof(sql_query_string), create_table_query[CREATE_TABLE_MAIL_LOCAL_ACTIVITY_TBL]); - + 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) { + else if (type == EMAIL_CREATE_DB_CHECK) { rc = sqlite3_exec(local_db_handle, g_test_query[CREATE_TABLE_MAIL_LOCAL_ACTIVITY_TBL], NULL, NULL, NULL); EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, g_test_query[CREATE_TABLE_MAIL_LOCAL_ACTIVITY_TBL], NULL, NULL, NULL), rc); EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, ("SQL(%s) exec fail:%d -%s", g_test_query[CREATE_TABLE_MAIL_LOCAL_ACTIVITY_TBL], rc, sqlite3_errmsg(local_db_handle))); } sqlite3_free_table(result); - + #endif /* __FEATURE_LOCAL_ACTIVITY__ */ /* create mail_certificate_tbl */ sql = "SELECT count(name) FROM sqlite_master WHERE name='mail_certificate_tbl';"; @@ -2240,7 +2240,7 @@ INTERNAL_FUNC int emstorage_create_table(emstorage_create_db_type_t type, int *e 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) { + else if (type == EMAIL_CREATE_DB_CHECK) { EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, g_test_query[CREATE_TABLE_MAIL_CERTIFICATE_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_CERTIFICATE_TBL], rc, sqlite3_errmsg(local_db_handle))); } @@ -2274,7 +2274,7 @@ INTERNAL_FUNC int emstorage_create_table(emstorage_create_db_type_t type, int *e sqlite3_free_table(result); ret = true; - + FINISH_OFF: if (ret == true) { EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, "END;", NULL, NULL, NULL), rc); @@ -2282,9 +2282,9 @@ FINISH_OFF: else { EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, "rollback", NULL, NULL, NULL), rc); } - + _DISCONNECT_DB; - + if (err_code != NULL) *err_code = error; @@ -2435,7 +2435,7 @@ INTERNAL_FUNC int emstorage_query_mail_list(const char *conditional_clause, int { EM_DEBUG_FUNC_BEGIN(); EM_PROFILE_BEGIN(emstorage_query_mail_list_func); - + int i = 0, count = 0, rc = -1, to_get_count = (result_mail_list)?0:1; int local_inline_content_count = 0, local_attachment_count = 0; int cur_query = 0, base_count = 0, col_index; @@ -2450,7 +2450,7 @@ INTERNAL_FUNC int emstorage_query_mail_list(const char *conditional_clause, int EM_IF_NULL_RETURN_VALUE(result_count, false); EMSTORAGE_START_READ_TRANSACTION(transaction); - + /* select clause */ if (to_get_count) /* count only */ cur_query += SNPRINTF_OFFSET(sql_query_string, cur_query, QUERY_SIZE, "SELECT mail_id FROM mail_tbl"); @@ -2459,24 +2459,24 @@ INTERNAL_FUNC int emstorage_query_mail_list(const char *conditional_clause, int /* cur_query += SNPRINTF_OFFSET(sql_query_string, cur_query, QUERY_SIZE, conditional_clause); This code caused some crashes.*/ strncat(sql_query_string, conditional_clause, QUERY_SIZE - cur_query); - + EM_DEBUG_LOG("emstorage_query_mail_list : query[%s].", sql_query_string); - /* performing query */ + /* performing query */ EM_PROFILE_BEGIN(emstorage_query_mail_list_performing_query); 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; }, ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); EM_PROFILE_END(emstorage_query_mail_list_performing_query); - - if (!base_count) + + if (!base_count) base_count = ({ int i=0; char *tmp = field_list; for (i=0; tmp && *(tmp + 1); tmp = index(tmp + 1, ','), i++); i; }); col_index = base_count; EM_DEBUG_LOG("base_count [%d]", base_count); - if (to_get_count) { + if (to_get_count) { /* to get count */ if (!count) { EM_DEBUG_EXCEPTION("No mail found..."); @@ -2489,12 +2489,12 @@ INTERNAL_FUNC int emstorage_query_mail_list(const char *conditional_clause, int else { /* to get mail list */ if (!count) { - EM_DEBUG_EXCEPTION("No mail found..."); + EM_DEBUG_EXCEPTION("No mail found..."); ret = false; error= EMAIL_ERROR_MAIL_NOT_FOUND; goto FINISH_OFF; } - + EM_DEBUG_LOG("There are [%d] mails.", count); if (!(mail_list_item_from_tbl = (email_mail_list_item_t*)em_malloc(sizeof(email_mail_list_item_t) * count))) { EM_DEBUG_EXCEPTION("malloc for mail_list_item_from_tbl failed..."); @@ -2503,7 +2503,7 @@ INTERNAL_FUNC int emstorage_query_mail_list(const char *conditional_clause, int } EM_PROFILE_BEGIN(emstorage_query_mail_list_loop); - EM_DEBUG_LOG(">>>> DATA ASSIGN START >> "); + EM_DEBUG_LOG(">>>> DATA ASSIGN START >> "); for (i = 0; i < count; i++) { _get_table_field_data_int(result, &(mail_list_item_from_tbl[i].mail_id), col_index++); _get_table_field_data_int(result, &(mail_list_item_from_tbl[i].account_id), col_index++); @@ -2543,7 +2543,7 @@ INTERNAL_FUNC int emstorage_query_mail_list(const char *conditional_clause, int sqlite3_free_table(result); result = NULL; ret = true; - + FINISH_OFF: EM_DEBUG_LOG("COUNT [%d]", count); @@ -2555,7 +2555,7 @@ FINISH_OFF: *result_mail_list = mail_list_item_from_tbl; *result_count = count; } - else + else EM_SAFE_FREE(mail_list_item_from_tbl); } @@ -2564,7 +2564,7 @@ FINISH_OFF: sqlite3_release_memory(-1); _DISCONNECT_DB; - + EM_SAFE_FREE(date_time_string); if (err_code != NULL) @@ -2582,12 +2582,12 @@ INTERNAL_FUNC int emstorage_query_mail_tbl(const char *conditional_clause, int t if (!conditional_clause) { EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM"); - + if (err_code != NULL) *err_code = EMAIL_ERROR_INVALID_PARAM; return false; } - + int i, col_index = FIELD_COUNT_OF_MAIL_TBL, rc, ret = false, count; int error = EMAIL_ERROR_NONE; char **result = NULL, sql_query_string[QUERY_SIZE] = {0, }; @@ -2599,18 +2599,18 @@ INTERNAL_FUNC int emstorage_query_mail_tbl(const char *conditional_clause, int t SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT * FROM mail_tbl %s", conditional_clause); EM_DEBUG_LOG("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; }, ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); if (!count) { - EM_DEBUG_EXCEPTION("No mail found..."); + EM_DEBUG_EXCEPTION("No mail found..."); ret = false; error= EMAIL_ERROR_MAIL_NOT_FOUND; goto FINISH_OFF; } - + EM_DEBUG_LOG("There are [%d] mails.", count); if (!(p_data_tbl = (emstorage_mail_tbl_t*)em_malloc(sizeof(emstorage_mail_tbl_t) * count))) { EM_DEBUG_EXCEPTION("malloc for emstorage_mail_tbl_t failed..."); @@ -2618,7 +2618,7 @@ INTERNAL_FUNC int emstorage_query_mail_tbl(const char *conditional_clause, int t goto FINISH_OFF; } - EM_DEBUG_LOG(">>>> DATA ASSIGN START >> "); + EM_DEBUG_LOG(">>>> DATA ASSIGN START >> "); for (i = 0; i < count; i++) { _get_table_field_data_int (result, &(p_data_tbl[i].mail_id), col_index++); _get_table_field_data_int (result, &(p_data_tbl[i].account_id), col_index++); @@ -2671,7 +2671,7 @@ INTERNAL_FUNC int emstorage_query_mail_tbl(const char *conditional_clause, int t /* check real body file... */ if (p_data_tbl[i].body_download_status) { struct stat buf; - + if (p_data_tbl[i].file_path_html && EM_SAFE_STRLEN(p_data_tbl[i].file_path_html) > 0) { if (stat(p_data_tbl[i].file_path_html, &buf) == -1) { EM_DEBUG_LINE; @@ -2684,13 +2684,13 @@ INTERNAL_FUNC int emstorage_query_mail_tbl(const char *conditional_clause, int t p_data_tbl[i].body_download_status = 0; } } - else + else p_data_tbl[i].body_download_status = 0; } } - + ret = true; - + FINISH_OFF: if(result) sqlite3_free_table(result); @@ -2700,15 +2700,15 @@ FINISH_OFF: *result_mail_tbl = p_data_tbl; *result_count = count; } - else + else EM_SAFE_FREE(p_data_tbl); - + EMSTORAGE_FINISH_READ_TRANSACTION(transaction); sqlite3_release_memory(-1); _DISCONNECT_DB; - + if (err_code != NULL) *err_code = error; @@ -2813,13 +2813,13 @@ FINISH_OFF: INTERNAL_FUNC int emstorage_check_duplicated_account(email_account_t* account, int transaction, int *err_code) { EM_DEBUG_FUNC_BEGIN(); - + if (!account) { if (err_code != NULL) *err_code = EMAIL_ERROR_INVALID_PARAM; return false; } - + int rc = -1, ret = false; int error = EMAIL_ERROR_NONE; char **result; @@ -2862,12 +2862,12 @@ INTERNAL_FUNC int emstorage_check_duplicated_account(email_account_t* account, i EM_DEBUG_LOG("The same account already exists. Duplicated account: user_email_address[%s]", account->user_email_address); error = EMAIL_ERROR_ALREADY_EXISTS; } - + FINISH_OFF: EMSTORAGE_FINISH_READ_TRANSACTION(transaction); _DISCONNECT_DB; - + if (err_code != NULL) *err_code = error; @@ -2879,20 +2879,20 @@ FINISH_OFF: INTERNAL_FUNC int emstorage_get_account_count(int *count, int transaction, int *err_code) { EM_DEBUG_FUNC_BEGIN(); - + if (!count) { if (err_code != NULL) *err_code = EMAIL_ERROR_INVALID_PARAM; return false; } - + int rc = -1, ret = false; int error = EMAIL_ERROR_NONE; - + 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"); @@ -2905,11 +2905,11 @@ INTERNAL_FUNC int emstorage_get_account_count(int *count, int transaction, int * 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)); - + *count = sqlite3_column_int(hStmt, 0); - + ret = true; - + FINISH_OFF: if (hStmt != NULL) { @@ -2923,10 +2923,10 @@ FINISH_OFF: } EM_DEBUG_LOG("sqlite3_finalize- %d", rc); } - + EMSTORAGE_FINISH_READ_TRANSACTION(transaction); _DISCONNECT_DB; - + if (err_code != NULL) *err_code = error; @@ -2938,7 +2938,7 @@ FINISH_OFF: INTERNAL_FUNC int emstorage_get_account_list(int *select_num, emstorage_account_tbl_t** account_list, int transaction, int with_password, int *err_code) { EM_DEBUG_FUNC_BEGIN(); - + int i = 0, count = 0, rc = -1, ret = false; int field_index = 0; int error = EMAIL_ERROR_NONE; @@ -2955,10 +2955,10 @@ INTERNAL_FUNC int emstorage_get_account_list(int *select_num, emstorage_account_ *err_code = EMAIL_ERROR_INVALID_PARAM; return false; } - + 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))); @@ -2987,7 +2987,7 @@ INTERNAL_FUNC int emstorage_get_account_list(int *select_num, emstorage_account_ ("sqlite3_step fail:%d", rc)); if (rc == SQLITE_DONE) { EM_DEBUG_EXCEPTION("no account found..."); - + error = EMAIL_ERROR_ACCOUNT_NOT_FOUND; count = 0; ret = true; @@ -3069,14 +3069,14 @@ INTERNAL_FUNC int emstorage_get_account_list(int *select_num, emstorage_account_ 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 = 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 = EMAIL_ERROR_SECURED_STORAGE_FAILURE; @@ -3088,10 +3088,10 @@ INTERNAL_FUNC int emstorage_get_account_list(int *select_num, emstorage_account_ EM_DEBUG_LOG("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)); - } - + } + ret = true; - + FINISH_OFF: if (ret == true) { *account_list = p_data_tbl; @@ -3103,7 +3103,7 @@ FINISH_OFF: if (hStmt != NULL) { EM_DEBUG_LOG("Before sqlite3_finalize hStmt = %p", hStmt); - + rc = sqlite3_finalize(hStmt); hStmt = NULL; if (rc != SQLITE_OK) { @@ -3111,7 +3111,7 @@ FINISH_OFF: error = EMAIL_ERROR_DB_FAILURE; } } - + EMSTORAGE_FINISH_READ_TRANSACTION(transaction); _DISCONNECT_DB; @@ -3126,7 +3126,7 @@ FINISH_OFF: 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) { EM_DEBUG_FUNC_BEGIN("account_id [%d], server_mail_id[%s], mail[%p], transaction[%d], err_code[%p]", account_id, server_mail_id, mail, transaction, err_code); - + int ret = false, error = EMAIL_ERROR_NONE, result_count; char conditional_clause[QUERY_SIZE] = {0, }; emstorage_mail_tbl_t* p_data_tbl = NULL; @@ -3136,7 +3136,7 @@ INTERNAL_FUNC int emstorage_get_maildata_by_servermailid(int account_id, char *s error = EMAIL_ERROR_INVALID_PARAM; goto FINISH_OFF; } - + if (account_id == ALL_ACCOUNT) SNPRINTF(conditional_clause, QUERY_SIZE, "WHERE UPPER(server_mail_id) =UPPER('%s')", server_mail_id); else @@ -3148,13 +3148,13 @@ INTERNAL_FUNC int emstorage_get_maildata_by_servermailid(int account_id, char *s EM_DEBUG_EXCEPTION("emstorage_query_mail_tbl failed [%d]", error); goto FINISH_OFF; } - + ret = true; - + FINISH_OFF: if (ret == true) *mail = p_data_tbl; - + if (err_code != NULL) *err_code = error; @@ -3183,7 +3183,7 @@ 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 account_id = %d", account_id): SNPRINTF_OFFSET(conditional_clause_string, cur_clause, buffer_size - cur_clause, " AND account_id = %d", account_id); } - + if (mailbox_id > 0) { cur_clause += (conditional_clause_count++ == 0)? SNPRINTF_OFFSET(conditional_clause_string, cur_clause, buffer_size - cur_clause, " WHERE mailbox_id = %d", mailbox_id): @@ -3235,7 +3235,7 @@ static int _write_conditional_clause_for_getting_mail_list(int account_id, int m for (i = 1; i < addr_list->address_count; i++) cur_clause += SNPRINTF_OFFSET(conditional_clause_string, cur_clause, buffer_size - cur_clause, ",\"%s\"", addr_list->address_list[i]); - cur_clause += SNPRINTF_OFFSET(conditional_clause_string, cur_clause, buffer_size - cur_clause, ")"); + cur_clause += SNPRINTF_OFFSET(conditional_clause_string, cur_clause, buffer_size - cur_clause, ")"); } } @@ -3258,7 +3258,7 @@ static int _write_conditional_clause_for_getting_mail_list(int account_id, int m break; case EMAIL_SEARCH_FILTER_RECIPIENT: cur_clause += SNPRINTF_OFFSET(conditional_clause_string, cur_clause, buffer_size - cur_clause, - " %s ((UPPER(full_address_to) LIKE UPPER(\'%%%%%s%%%%\') ESCAPE '\\') " + " %s ((UPPER(full_address_to) LIKE UPPER(\'%%%%%s%%%%\') ESCAPE '\\') " " OR (UPPER(full_address_cc) LIKE UPPER(\'%%%%%s%%%%\') ESCAPE '\\') " " OR (UPPER(full_address_bcc) LIKE UPPER(\'%%%%%s%%%%\') ESCAPE '\\') " ") ", conditional_clause_count++ ? "AND" : "WHERE", search_value, search_value, search_value); @@ -3276,9 +3276,9 @@ static int _write_conditional_clause_for_getting_mail_list(int account_id, int m break; } } - + /* EM_DEBUG_LOG("where clause [%s]", conditional_clause_string); */ - static char sorting_str[][50] = { + static char sorting_str[][50] = { " ORDER BY date_time DESC", /* case EMAIL_SORT_DATETIME_HIGH: */ " ORDER BY date_time ASC", /* case EMAIL_SORT_DATETIME_LOW: */ " ORDER BY full_address_from DESC, date_time DESC", /* case EMAIL_SORT_SENDER_HIGH: */ @@ -3312,7 +3312,7 @@ static int _write_conditional_clause_for_getting_mail_list(int account_id, int m /** * emstorage_get_mail_list - Get the mail list information. - * + * * */ INTERNAL_FUNC int emstorage_get_mail_list(int account_id, int mailbox_id, email_email_address_list_t* addr_list, int thread_id, int start_index, int limit_count, int search_type, const char *search_value, email_sort_type_t sorting, int transaction, email_mail_list_item_t** mail_list, int *result_count, int *err_code) @@ -3330,7 +3330,7 @@ INTERNAL_FUNC int emstorage_get_mail_list(int account_id, int mailbox_id, email_ EM_IF_NULL_RETURN_VALUE(result_count, false); _write_conditional_clause_for_getting_mail_list(account_id, mailbox_id, addr_list, thread_id, start_index, limit_count, search_type, search_value, sorting, true, conditional_clause_string, QUERY_SIZE, &error); - + EM_DEBUG_LOG("conditional_clause_string[%s].", conditional_clause_string); if(!emstorage_query_mail_list(conditional_clause_string, transaction, mail_list, result_count, &error)) { @@ -3339,7 +3339,7 @@ INTERNAL_FUNC int emstorage_get_mail_list(int account_id, int mailbox_id, email_ } ret = true; - + FINISH_OFF: if (err_code != NULL) *err_code = error; @@ -3352,14 +3352,14 @@ FINISH_OFF: /** * emstorage_get_mails - Get the Mail list information based on mailbox_name name - * + * * */ 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) { EM_DEBUG_FUNC_BEGIN(); EM_PROFILE_BEGIN(emStorageGetMails); - + int count = 0, ret = false, error = EMAIL_ERROR_NONE; emstorage_mail_tbl_t *p_data_tbl = NULL; char conditional_clause_string[QUERY_SIZE] = {0, }; @@ -3384,7 +3384,7 @@ INTERNAL_FUNC int emstorage_get_mails(int account_id, int mailbox_id, email_emai } ret = true; - + FINISH_OFF: if (ret == true) { *mail_list = p_data_tbl; @@ -3393,7 +3393,7 @@ FINISH_OFF: } else if (p_data_tbl != NULL) emstorage_free_mail(&p_data_tbl, count, NULL); - + if (err_code != NULL) *err_code = error; @@ -3406,13 +3406,13 @@ FINISH_OFF: /** * emstorage_get_searched_mail_list - Get the mail list information after filtering - * + * * */ 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) { EM_DEBUG_FUNC_BEGIN(); - + int ret = false, error = EMAIL_ERROR_NONE; char conditional_clause[QUERY_SIZE] = {0, }; char *temp_search_value = NULL; @@ -3431,7 +3431,7 @@ INTERNAL_FUNC int emstorage_get_searched_mail_list(int account_id, int mailbox_i temp_search_value2 = em_replace_all_string(temp_search_value, "%", "\\%"); _write_conditional_clause_for_getting_mail_list(account_id, mailbox_id, NULL, thread_id, start_index, limit_count, search_type, temp_search_value2, sorting, true, conditional_clause, QUERY_SIZE, &error); - + EM_DEBUG_LOG("conditional_clause[%s]", conditional_clause); if(!emstorage_query_mail_list(conditional_clause, transaction, mail_list, result_count, &error)) { @@ -3440,10 +3440,10 @@ INTERNAL_FUNC int emstorage_get_searched_mail_list(int account_id, int mailbox_i } ret = true; - + FINISH_OFF: - EM_DEBUG_LOG("emstorage_get_searched_mail_list finish off"); - + EM_DEBUG_LOG("emstorage_get_searched_mail_list finish off"); + if (err_code != NULL) *err_code = error; @@ -3477,7 +3477,7 @@ static int _read_password_from_secure_storage(char *file_name, char **password) if (!file_name || !password) { EM_DEBUG_EXCEPTION("Invalid Parameter"); return EMAIL_ERROR_INVALID_PARAM; - } + } size_t buf_len = 0, read_len = 0; ssm_file_info_t sfi; @@ -3513,7 +3513,7 @@ static int _read_password_from_secure_storage(char *file_name, char **password) FINISH_OFF: EM_SAFE_FREE(temp_password); - + EM_DEBUG_FUNC_END("ret [%d]", ret); return ret; } @@ -3539,14 +3539,14 @@ INTERNAL_FUNC int emstorage_get_account_by_id(int account_id, int pulloption, em int sql_len = 0; char recv_password_file_name[MAX_PW_FILE_NAME_LENGTH]; char send_password_file_name[MAX_PW_FILE_NAME_LENGTH]; - + sqlite3 *local_db_handle = emstorage_get_db_connection(); EMSTORAGE_START_READ_TRANSACTION(transaction); /* Make query string */ SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT "); sql_len = EM_SAFE_STRLEN(sql_query_string); - + if (pulloption & EMAIL_ACC_GET_OPT_DEFAULT) { SNPRINTF(sql_query_string + sql_len, sizeof(sql_query_string) - sql_len, "incoming_server_type," @@ -3576,12 +3576,12 @@ INTERNAL_FUNC int emstorage_get_account_by_id(int account_id, int pulloption, em "user_data_length," "check_interval," "sync_status,"); - sql_len = EM_SAFE_STRLEN(sql_query_string); + sql_len = EM_SAFE_STRLEN(sql_query_string); } if (pulloption & EMAIL_ACC_GET_OPT_ACCOUNT_NAME) { SNPRINTF(sql_query_string + sql_len, sizeof(sql_query_string) - sql_len, " account_name, "); - sql_len = EM_SAFE_STRLEN(sql_query_string); + sql_len = EM_SAFE_STRLEN(sql_query_string); } /* get from secure storage, not from db */ @@ -3609,7 +3609,7 @@ INTERNAL_FUNC int emstorage_get_account_by_id(int account_id, int pulloption, em "cipher_type," "digest_type,"); - sql_len = EM_SAFE_STRLEN(sql_query_string); + sql_len = EM_SAFE_STRLEN(sql_query_string); } /* dummy value, FROM WHERE clause */ @@ -3622,7 +3622,7 @@ INTERNAL_FUNC int emstorage_get_account_by_id(int account_id, int pulloption, em 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 && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, ("sqlite3_step fail:%d", rc)); @@ -3681,7 +3681,7 @@ INTERNAL_FUNC int emstorage_get_account_by_id(int account_id, int pulloption, em if ((error = _get_password_file_name(p_data_tbl->account_id, recv_password_file_name, send_password_file_name)) != EMAIL_ERROR_NONE) { EM_DEBUG_EXCEPTION("_get_password_file_name failed. [%d]", error); goto FINISH_OFF; - } + } /* read password from secure storage */ if ((error = _read_password_from_secure_storage(recv_password_file_name, &(p_data_tbl->incoming_server_password))) < 0) { @@ -3690,7 +3690,7 @@ INTERNAL_FUNC int emstorage_get_account_by_id(int account_id, int pulloption, em } EM_DEBUG_LOG("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; @@ -3738,7 +3738,7 @@ FINISH_OFF: error = EMAIL_ERROR_DB_FAILURE; } } - + EMSTORAGE_FINISH_READ_TRANSACTION(transaction); _DISCONNECT_DB; @@ -3765,13 +3765,13 @@ INTERNAL_FUNC int emstorage_get_password_length_of_account(int account_id, int * char recv_password_file_name[MAX_PW_FILE_NAME_LENGTH]; char send_password_file_name[MAX_PW_FILE_NAME_LENGTH]; char *temp_password = NULL; - + /* get password file name */ if ((error = _get_password_file_name(account_id, recv_password_file_name, send_password_file_name)) != EMAIL_ERROR_NONE) { EM_DEBUG_EXCEPTION("_get_password_file_name failed."); goto FINISH_OFF; - } + } /* read password from secure storage */ if ((error = _read_password_from_secure_storage(recv_password_file_name, &temp_password)) < 0 || !temp_password) { @@ -3780,7 +3780,7 @@ INTERNAL_FUNC int emstorage_get_password_length_of_account(int account_id, int * } *password_length = EM_SAFE_STRLEN(temp_password); - + EM_DEBUG_LOG("recv_password_file_name[%s], *password_length[%d]", recv_password_file_name, *password_length); ret = true; @@ -3798,17 +3798,17 @@ FINISH_OFF: INTERNAL_FUNC int emstorage_update_account(int account_id, emstorage_account_tbl_t* account_tbl, int transaction, int *err_code) { EM_DEBUG_FUNC_BEGIN("account_id[%d], account[%p], transaction[%d], err_code[%p]", account_id, account_tbl, transaction, err_code); - + if (account_id < FIRST_ACCOUNT_ID || !account_tbl) { EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM"); if (err_code != NULL) *err_code = EMAIL_ERROR_INVALID_PARAM; return false; } - + int error = EMAIL_ERROR_NONE; int rc, ret = false; - + DB_STMT hStmt = NULL; char sql_query_string[QUERY_SIZE] = {0, }; char recv_password_file_name[MAX_PW_FILE_NAME_LENGTH]; @@ -3816,7 +3816,7 @@ INTERNAL_FUNC int emstorage_update_account(int account_id, emstorage_account_tbl sqlite3 *local_db_handle = emstorage_get_db_connection(); EMSTORAGE_START_WRITE_TRANSACTION(transaction, error); - + SNPRINTF(sql_query_string, sizeof(sql_query_string), "UPDATE mail_account_tbl SET" " account_name = ?" @@ -3867,14 +3867,14 @@ INTERNAL_FUNC int emstorage_update_account(int account_id, emstorage_account_tbl ", certificate_path = ?" ", cipher_type = ?" ", digest_type = ?" - " WHERE account_id = ?"); - + " WHERE account_id = ?"); + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); EM_DEBUG_LOG("After sqlite3_prepare hStmt = %p", hStmt); EM_DEBUG_LOG("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))); - + int i = 0; _bind_stmt_field_data_string(hStmt, i++, (char *)account_tbl->account_name, 0, ACCOUNT_NAME_LEN_IN_MAIL_ACCOUNT_TBL); @@ -3926,22 +3926,22 @@ INTERNAL_FUNC int emstorage_update_account(int account_id, emstorage_account_tbl _bind_stmt_field_data_int(hStmt, i++, account_tbl->cipher_type); _bind_stmt_field_data_int(hStmt, i++, account_tbl->digest_type); _bind_stmt_field_data_int(hStmt, i++, account_id); - + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc); EM_DEBUG_DB_EXEC((SQLITE_FULL == rc), {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)); - + /* validate account existence */ rc = sqlite3_changes(local_db_handle); if (rc == 0) { EM_DEBUG_EXCEPTION(" no matched account found..."); - + error = EMAIL_ERROR_ACCOUNT_NOT_FOUND; goto FINISH_OFF; } - + /* get password file name */ if ((error = _get_password_file_name(account_id, recv_password_file_name, send_password_file_name)) != EMAIL_ERROR_NONE) { EM_DEBUG_EXCEPTION("_get_password_file_name failed."); @@ -3954,7 +3954,7 @@ INTERNAL_FUNC int emstorage_update_account(int account_id, emstorage_account_tbl if (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(" ssm_write_buffer failed -recv incoming_server_password : file[%s]", recv_password_file_name); error = EMAIL_ERROR_SYSTEM_FAILURE; - goto FINISH_OFF; + goto FINISH_OFF; } } @@ -3962,16 +3962,16 @@ INTERNAL_FUNC int emstorage_update_account(int account_id, emstorage_account_tbl if (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(" ssm_write_buffer failed -send password : file[%s]", send_password_file_name); error = EMAIL_ERROR_SYSTEM_FAILURE; - goto FINISH_OFF; + goto FINISH_OFF; } } - + if (!emcore_notify_storage_event(NOTI_ACCOUNT_UPDATE, account_tbl->account_id, 0, NULL, 0)) EM_DEBUG_EXCEPTION(" emcore_notify_storage_event[ NOTI_ACCOUNT_UPDATE] : Notification Failed >>> "); ret = true; - + FINISH_OFF: - + if (hStmt != NULL) { EM_DEBUG_LOG(" Before sqlite3_finalize hStmt = %p", hStmt); @@ -3983,9 +3983,9 @@ FINISH_OFF: } EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error); - + _DISCONNECT_DB; - + if (err_code != NULL) *err_code = error; @@ -4035,7 +4035,7 @@ FINISH_OFF: return error; } -INTERNAL_FUNC int emstorage_get_sync_status_of_account(int account_id, int *result_sync_status,int *err_code) +INTERNAL_FUNC int emstorage_get_sync_status_of_account(int account_id, int *result_sync_status,int *err_code) { EM_DEBUG_FUNC_BEGIN("account_id[%d], result_sync_status [%p], err_code[%p]", account_id, result_sync_status, err_code); @@ -4045,17 +4045,17 @@ INTERNAL_FUNC int emstorage_get_sync_status_of_account(int account_id, int *resu *err_code = EMAIL_ERROR_INVALID_PARAM; return false; } - + int error = EMAIL_ERROR_NONE, rc, ret = false, sync_status, count, i, col_index; char sql_query_string[QUERY_SIZE] = {0, }; char **result = NULL; sqlite3 *local_db_handle = emstorage_get_db_connection(); if(account_id) - SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT sync_status FROM mail_account_tbl WHERE account_id = %d", account_id); + SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT sync_status FROM mail_account_tbl WHERE account_id = %d", account_id); else - SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT sync_status FROM mail_account_tbl"); - + SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT sync_status FROM mail_account_tbl"); + 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; }, ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); @@ -4073,17 +4073,17 @@ INTERNAL_FUNC int emstorage_get_sync_status_of_account(int account_id, int *resu _get_table_field_data_int(result, &sync_status, col_index++); *result_sync_status |= sync_status; } - + EM_DEBUG_LOG("sync_status [%d]", sync_status); sqlite3_free_table(result); ret = true; - + FINISH_OFF: - + _DISCONNECT_DB; - + if (err_code != NULL) *err_code = error; @@ -4094,7 +4094,7 @@ FINISH_OFF: 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) { EM_DEBUG_FUNC_BEGIN("account_id[%d], set_operator[%d], sync_status [%d], transaction[%d], err_code[%p]", account_id, set_operator, sync_status, transaction, err_code); - + int error = EMAIL_ERROR_NONE, rc, ret = false, set_value = sync_status, result_sync_status; char sql_query_string[QUERY_SIZE] = {0, }; sqlite3 *local_db_handle = emstorage_get_db_connection(); @@ -4122,16 +4122,16 @@ INTERNAL_FUNC int emstorage_update_sync_status_of_account(int account_id, email_ EMSTORAGE_START_WRITE_TRANSACTION(transaction, error); if(account_id) - SNPRINTF(sql_query_string, sizeof(sql_query_string), "UPDATE mail_account_tbl SET sync_status = %d WHERE account_id = %d", set_value, account_id); + SNPRINTF(sql_query_string, sizeof(sql_query_string), "UPDATE mail_account_tbl SET sync_status = %d WHERE account_id = %d", set_value, account_id); else - SNPRINTF(sql_query_string, sizeof(sql_query_string), "UPDATE mail_account_tbl SET sync_status = %d WHERE incoming_server_type <> 5", set_value); + 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); - + 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) { @@ -4139,17 +4139,17 @@ INTERNAL_FUNC int emstorage_update_sync_status_of_account(int account_id, email_ error = EMAIL_ERROR_ACCOUNT_NOT_FOUND; goto FINISH_OFF; } - + if (!emcore_notify_storage_event(NOTI_ACCOUNT_UPDATE_SYNC_STATUS, account_id, 0, NULL, 0)) EM_DEBUG_EXCEPTION("emcore_notify_storage_event[NOTI_ACCOUNT_UPDATE_SYNC_STATUS] : Notification failed"); ret = true; - + FINISH_OFF: EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error); - + _DISCONNECT_DB; - + if (err_code != NULL) *err_code = error; @@ -4160,14 +4160,14 @@ FINISH_OFF: INTERNAL_FUNC int emstorage_add_account(emstorage_account_tbl_t* account_tbl, int transaction, int *err_code) { EM_DEBUG_FUNC_BEGIN("account[%p], transaction[%d], err_code[%p]", account_tbl, transaction, err_code); - + if (!account_tbl) { EM_DEBUG_EXCEPTION("account[%p], transaction[%d], err_code[%p]", account_tbl, transaction, err_code); if (err_code != NULL) *err_code = EMAIL_ERROR_INVALID_PARAM; return false; } - + int rc = -1, ret = false; int error = EMAIL_ERROR_NONE; int error_from_ssm = 0; @@ -4175,14 +4175,14 @@ INTERNAL_FUNC int emstorage_add_account(emstorage_account_tbl_t* account_tbl, in char sql_query_string[QUERY_SIZE] = {0, }; char recv_password_file_name[MAX_PW_FILE_NAME_LENGTH]; char send_password_file_name[MAX_PW_FILE_NAME_LENGTH]; - + sqlite3 *local_db_handle = emstorage_get_db_connection(); EMSTORAGE_START_WRITE_TRANSACTION(transaction, error); char *sql = "SELECT max(rowid) FROM mail_account_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))); @@ -4255,7 +4255,7 @@ INTERNAL_FUNC int emstorage_add_account(emstorage_account_tbl_t* account_tbl, in " , ? " /* cipher_type */ " , ? " /* digest_type */ ") "); - + 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))); @@ -4314,26 +4314,26 @@ INTERNAL_FUNC int emstorage_add_account(emstorage_account_tbl_t* account_tbl, in _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); - + 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))); - + /* save passwords to the secure storage */ EM_DEBUG_LOG("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("ssm_write_buffer failed [%d] - recv password : file[%s]", error_from_ssm, recv_password_file_name); error = EMAIL_ERROR_SYSTEM_FAILURE; - goto FINISH_OFF; + 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("ssm_write_buffer failed [%d] - send password : file[%s]", error_from_ssm, send_password_file_name); error = EMAIL_ERROR_SYSTEM_FAILURE; - goto FINISH_OFF; + goto FINISH_OFF; } ret = true; @@ -4342,21 +4342,21 @@ INTERNAL_FUNC int emstorage_add_account(emstorage_account_tbl_t* account_tbl, in if (!emcore_notify_storage_event(NOTI_ACCOUNT_ADD, account_tbl->account_id, 0, NULL, 0)) EM_DEBUG_EXCEPTION("emcore_notify_storage_event[NOTI_ACCOUNT_ADD] : Notification failed"); - + FINISH_OFF: - + if (hStmt != NULL) { rc = sqlite3_finalize(hStmt); if (rc != SQLITE_OK) { EM_DEBUG_LOG("sqlite3_finalize failed [%d]", rc); error = EMAIL_ERROR_DB_FAILURE; - } + } } else EM_DEBUG_LOG("hStmt is NULL!!!"); - + _DISCONNECT_DB; - + if (err_code != NULL) *err_code = error; @@ -4368,15 +4368,15 @@ FINISH_OFF: INTERNAL_FUNC int emstorage_delete_account(int account_id, int transaction, int *err_code) { EM_DEBUG_FUNC_BEGIN("account_id[%d], transaction[%d], err_code[%p]", account_id, transaction, err_code); - - if (account_id < FIRST_ACCOUNT_ID) { + + if (account_id < FIRST_ACCOUNT_ID) { EM_DEBUG_EXCEPTION(" account_id[%d]", account_id); - + if (err_code != NULL) *err_code = EMAIL_ERROR_INVALID_PARAM; return false; } - + int rc = -1, ret = false; int error = EMAIL_ERROR_NONE; sqlite3 *local_db_handle = emstorage_get_db_connection(); @@ -4397,7 +4397,7 @@ 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)); @@ -4416,17 +4416,17 @@ INTERNAL_FUNC int emstorage_delete_account(int account_id, int transaction, int if (ssm_delete_file(recv_password_file_name, SSM_FLAG_SECRET_OPERATION, NULL) < 0) { EM_DEBUG_EXCEPTION(" ssm_delete_file failed -recv password : file[%s]", recv_password_file_name); error = EMAIL_ERROR_SYSTEM_FAILURE; - goto FINISH_OFF; + goto FINISH_OFF; } if (ssm_delete_file(send_password_file_name, SSM_FLAG_SECRET_OPERATION, NULL) < 0) { EM_DEBUG_EXCEPTION(" ssm_delete_file failed -send password : file[%s]", send_password_file_name); error = EMAIL_ERROR_SYSTEM_FAILURE; - goto FINISH_OFF; + goto FINISH_OFF; } ret = true; - + FINISH_OFF: - + if (hStmt != NULL) { rc = sqlite3_finalize(hStmt); if (rc != SQLITE_OK) { @@ -4449,20 +4449,20 @@ FINISH_OFF: INTERNAL_FUNC int emstorage_free_account(emstorage_account_tbl_t** account_list, int count, int *err_code) { EM_DEBUG_FUNC_BEGIN("account_list[%p], count[%d], err_code[%p]", account_list, count, err_code); - + int ret = false; int error = EMAIL_ERROR_NONE; - + if (count > 0) { if (!account_list || !*account_list) { EM_DEBUG_EXCEPTION("account_list[%p], count[%d]", account_list, count); error = EMAIL_ERROR_INVALID_PARAM; goto FINISH_OFF; } - + emstorage_account_tbl_t* p = *account_list; int i = 0; - + for (; i < count; i++) { EM_SAFE_FREE(p[i].account_name); EM_SAFE_FREE(p[i].incoming_server_address); @@ -4481,13 +4481,13 @@ INTERNAL_FUNC int emstorage_free_account(emstorage_account_tbl_t** account_list, EM_SAFE_FREE(p[i].options.signature); EM_SAFE_FREE(p[i].certificate_path); } - - EM_SAFE_FREE(p); + + EM_SAFE_FREE(p); *account_list = NULL; } - + ret = true; - + FINISH_OFF: if (err_code != NULL) *err_code = error; @@ -4499,24 +4499,24 @@ FINISH_OFF: INTERNAL_FUNC int emstorage_get_mailbox_count(int account_id, int local_yn, int *count, int transaction, int *err_code) { EM_DEBUG_FUNC_BEGIN("account_id[%d], local_yn[%d], count[%p], transaction[%d], err_code[%p]", account_id, local_yn, count, transaction, err_code); - + if ((account_id < FIRST_ACCOUNT_ID) || (count == NULL)) { EM_DEBUG_EXCEPTION(" account_list[%d], local_yn[%d], count[%p]", account_id, local_yn, count); - + if (err_code != NULL) *err_code = EMAIL_ERROR_INVALID_PARAM; return false; } - + int rc = -1, 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 COUNT(*) FROM mail_box_tbl WHERE account_id = %d AND local_yn = %d", account_id, local_yn); - + char **result; EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, NULL, NULL, NULL), rc); @@ -4525,15 +4525,15 @@ INTERNAL_FUNC int emstorage_get_mailbox_count(int account_id, int local_yn, int *count = atoi(result[1]); sqlite3_free_table(result); - + ret = true; - + FINISH_OFF: - + EMSTORAGE_FINISH_READ_TRANSACTION(transaction); _DISCONNECT_DB; - + if (err_code != NULL) *err_code = error; @@ -4544,10 +4544,10 @@ FINISH_OFF: 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) { EM_DEBUG_FUNC_BEGIN("account_id[%d], local_yn[%d], select_num[%p], mailbox_list[%p], transaction[%d], err_code[%p]", account_id, local_yn, select_num, mailbox_list, transaction, err_code); - + if (!select_num || !mailbox_list) { EM_DEBUG_EXCEPTION("Invalid parameters"); - + if (err_code != NULL) *err_code = EMAIL_ERROR_INVALID_PARAM; @@ -4558,7 +4558,7 @@ INTERNAL_FUNC int emstorage_get_mailbox_list(int account_id, int local_yn, email int error = EMAIL_ERROR_NONE; char conditional_clause_string[QUERY_SIZE] = {0, }; char ordering_clause_string[QUERY_SIZE] = {0, }; - + if (account_id == ALL_ACCOUNT) { if (local_yn == EMAIL_MAILBOX_FROM_SERVER || local_yn == EMAIL_MAILBOX_FROM_LOCAL) SNPRINTF(conditional_clause_string + EM_SAFE_STRLEN(conditional_clause_string), sizeof(conditional_clause_string)-(EM_SAFE_STRLEN(conditional_clause_string)+1), " WHERE local_yn = %d ", local_yn); @@ -4597,9 +4597,9 @@ INTERNAL_FUNC int emstorage_get_mailbox_list(int account_id, int local_yn, email } ret = true; - + FINISH_OFF: - + if (err_code != NULL) *err_code = error; @@ -4647,9 +4647,9 @@ INTERNAL_FUNC int emstorage_get_mailbox_list_ex(int account_id, int local_yn, in } ret = true; - + FINISH_OFF: - + if (err_code != NULL) *err_code = error; @@ -4662,7 +4662,7 @@ INTERNAL_FUNC int emstorage_get_child_mailbox_list(int account_id, char *parent_ EM_DEBUG_FUNC_BEGIN("account_id[%d], parent_mailbox_name[%p], select_num[%p], mailbox_list[%p], transaction[%d], err_code[%p]", account_id, parent_mailbox_name, select_num, mailbox_list, transaction, err_code); if (account_id < FIRST_ACCOUNT_ID || !select_num || !mailbox_list) { EM_DEBUG_EXCEPTION("account_id[%d], parent_mailbox_name[%p], select_num[%p], mailbox_list[%p]", account_id, parent_mailbox_name, select_num, mailbox_list); - + if (err_code != NULL) *err_code = EMAIL_ERROR_INVALID_PARAM; return false; @@ -4685,22 +4685,22 @@ INTERNAL_FUNC int emstorage_get_child_mailbox_list(int account_id, char *parent_ } ret = true; - + FINISH_OFF: - + if (err_code != NULL) *err_code = error; EM_DEBUG_FUNC_END("ret [%d]", ret); return ret; } - + INTERNAL_FUNC int emstorage_get_mailbox_by_modifiable_yn(int account_id, int local_yn, int *select_num, emstorage_mailbox_tbl_t** mailbox_list, int transaction, int *err_code) { EM_DEBUG_FUNC_BEGIN("account_id[%d], local_yn[%d], select_num[%p], mailbox_list[%p], transaction[%d], err_code[%p]", account_id, local_yn, select_num, mailbox_list, transaction, err_code); if (account_id < FIRST_ACCOUNT_ID || !select_num || !mailbox_list) { EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM"); - + if (err_code != NULL) *err_code = EMAIL_ERROR_INVALID_PARAM; @@ -4710,19 +4710,19 @@ INTERNAL_FUNC int emstorage_get_mailbox_by_modifiable_yn(int account_id, int loc int ret = false; int error = EMAIL_ERROR_NONE; char conditional_clause_string[QUERY_SIZE] = {0, }; - + SNPRINTF(conditional_clause_string, sizeof(conditional_clause_string), "WHERE account_id = %d AND modifiable_yn = 0", account_id); EM_DEBUG_LOG("conditional_clause_string [%s]", conditional_clause_string); - + if( (error = emstorage_query_mailbox_tbl(conditional_clause_string, " ORDER BY mailbox_name", 0, transaction, mailbox_list, select_num)) != EMAIL_ERROR_NONE) { EM_DEBUG_EXCEPTION("emstorage_query_mailbox_tbl failed [%d]", error); goto FINISH_OFF; } - + ret = true; - + FINISH_OFF: - + if (err_code != NULL) *err_code = error; @@ -4781,10 +4781,10 @@ INTERNAL_FUNC int emstorage_get_mailbox_by_name(int account_id, int local_yn, ch { EM_DEBUG_FUNC_BEGIN("account_id[%d], local_yn[%d], mailbox_name[%s], result_mailbox[%p], transaction[%d], err_code[%p]", account_id, local_yn, mailbox_name, result_mailbox, transaction, err_code); EM_PROFILE_BEGIN(profile_emstorage_get_mailbox_by_name); - + if (account_id < FIRST_ACCOUNT_ID || !mailbox_name || !result_mailbox) { EM_DEBUG_EXCEPTION(" account_id[%d], local_yn[%d], mailbox_name[%s], result_mailbox[%p]", account_id, local_yn, mailbox_name, result_mailbox); - + if (err_code != NULL) *err_code = EMAIL_ERROR_INVALID_PARAM; return false; @@ -4821,7 +4821,7 @@ INTERNAL_FUNC int emstorage_get_mailbox_by_name(int account_id, int local_yn, ch SNPRINTF(conditional_clause_string, sizeof(conditional_clause_string), "WHERE account_id = %d AND mailbox_name = '%s'", account_id, mailbox_name); else SNPRINTF(conditional_clause_string, sizeof(conditional_clause_string), "WHERE account_id = %d AND local_yn = %d AND mailbox_name = '%s'", account_id, local_yn, mailbox_name); - + EM_DEBUG_LOG("conditional_clause_string = [%s]", conditional_clause_string); if( (error = emstorage_query_mailbox_tbl(conditional_clause_string, "", 0, transaction, result_mailbox, &result_count)) != EMAIL_ERROR_NONE) { @@ -4831,7 +4831,7 @@ INTERNAL_FUNC int emstorage_get_mailbox_by_name(int account_id, int local_yn, ch } ret = true; - + FINISH_OFF: if (err_code != NULL) @@ -4849,7 +4849,7 @@ INTERNAL_FUNC int emstorage_get_mailbox_by_mailbox_type(int account_id, email_ma if (account_id < FIRST_ACCOUNT_ID || (mailbox_type < EMAIL_MAILBOX_TYPE_INBOX || mailbox_type > EMAIL_MAILBOX_TYPE_USER_DEFINED) || !mailbox_name) { EM_DEBUG_EXCEPTION(" account_id[%d], mailbox_type[%d], mailbox_name[%p]", account_id, mailbox_type, mailbox_name); - + if (err_code != NULL) *err_code = EMAIL_ERROR_INVALID_PARAM; return false; @@ -4862,10 +4862,10 @@ INTERNAL_FUNC int emstorage_get_mailbox_by_mailbox_type(int account_id, email_ma DB_STMT hStmt = NULL; char sql_query_string[QUERY_SIZE] = {0,}; char *fields = "mailbox_id, account_id, local_yn, mailbox_name, mailbox_type, alias, deleted_flag, modifiable_yn, total_mail_count_on_server, has_archived_mails, mail_slot_size, no_select, last_sync_time "; - + sqlite3 *local_db_handle = emstorage_get_db_connection(); EMSTORAGE_START_READ_TRANSACTION(transaction); - + /* validate account */ /* Check whether the account exists. */ if (!emstorage_get_account_by_id(account_id, EMAIL_ACC_GET_OPT_ACCOUNT_NAME, &account, true, &error) || !account) { @@ -4875,34 +4875,34 @@ INTERNAL_FUNC int emstorage_get_mailbox_by_mailbox_type(int account_id, email_ma if (account) emstorage_free_account(&account, 1, NULL); - + SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT %s FROM mail_box_tbl WHERE account_id = %d AND mailbox_type = %d ", fields, account_id, mailbox_type); EM_DEBUG_LOG("query = [%s]", sql_query_string); - - + + 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 && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, ("sqlite3_step fail:%d", rc)); - + if (rc == SQLITE_DONE) { EM_DEBUG_EXCEPTION(" no matched mailbox_name found..."); error = EMAIL_ERROR_MAILBOX_NOT_FOUND; goto FINISH_OFF; } - + if (!(p_data_tbl = (emstorage_mailbox_tbl_t*)malloc(sizeof(emstorage_mailbox_tbl_t)))) { EM_DEBUG_EXCEPTION(" malloc failed..."); error = EMAIL_ERROR_OUT_OF_MEMORY; goto FINISH_OFF; } - + memset(p_data_tbl, 0x00, sizeof(emstorage_mailbox_tbl_t)); - + int col_index = 0; _get_stmt_field_data_int(hStmt, &(p_data_tbl->mailbox_id), col_index++); @@ -4920,11 +4920,11 @@ INTERNAL_FUNC int emstorage_get_mailbox_by_mailbox_type(int account_id, email_ma _get_stmt_field_data_int(hStmt, (int*)&(p_data_tbl->last_sync_time), col_index++); ret = true; - + FINISH_OFF: if (ret == true) *mailbox_name = p_data_tbl; - + if (hStmt != NULL) { rc = sqlite3_finalize(hStmt); if (rc != SQLITE_OK) { @@ -4932,10 +4932,10 @@ FINISH_OFF: error = EMAIL_ERROR_DB_FAILURE; } } - + EMSTORAGE_FINISH_READ_TRANSACTION(transaction); _DISCONNECT_DB; - + if (err_code != NULL) *err_code = error; @@ -4986,7 +4986,7 @@ INTERNAL_FUNC int emstorage_get_mailbox_id_by_mailbox_type(int account_id, email emstorage_account_tbl_t* account = 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); @@ -4998,7 +4998,7 @@ INTERNAL_FUNC int emstorage_get_mailbox_id_by_mailbox_type(int account_id, email if (account ) emstorage_free_account(&account, 1, NULL); - + SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT mailbox_id FROM mail_box_tbl WHERE account_id = %d AND mailbox_type = %d ", account_id, mailbox_type); EM_DEBUG_LOG("query = [%s]", sql_query_string); @@ -5075,7 +5075,7 @@ INTERNAL_FUNC int emstorage_get_mailbox_name_by_mailbox_type(int account_id, ema EM_DEBUG_LOG("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; }, @@ -5085,17 +5085,17 @@ INTERNAL_FUNC int emstorage_get_mailbox_name_by_mailbox_type(int account_id, ema 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)); - + if (rc == SQLITE_DONE) { EM_DEBUG_EXCEPTION("no matched mailbox_name found..."); error = EMAIL_ERROR_MAILBOX_NOT_FOUND; goto FINISH_OFF; } - + _get_stmt_field_data_string(hStmt, mailbox_name, 0, 0); ret = true; - + FINISH_OFF: if (hStmt != NULL) { rc = sqlite3_finalize(hStmt); @@ -5104,10 +5104,10 @@ FINISH_OFF: error = EMAIL_ERROR_DB_FAILURE; } } - + EMSTORAGE_FINISH_READ_TRANSACTION(transaction); _DISCONNECT_DB; - + if (err_code != NULL) *err_code = error; @@ -5121,11 +5121,11 @@ INTERNAL_FUNC int emstorage_update_mailbox_modifiable_yn(int account_id, int loc 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" @@ -5139,13 +5139,13 @@ INTERNAL_FUNC int emstorage_update_mailbox_modifiable_yn(int account_id, int loc 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))); - + ret = true; FINISH_OFF: EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error); _DISCONNECT_DB; - + if (err_code != NULL) *err_code = error; @@ -5161,14 +5161,14 @@ INTERNAL_FUNC int emstorage_update_mailbox_total_count(int account_id, int input int rc, ret = false; int error = EMAIL_ERROR_NONE; char sql_query_string[QUERY_SIZE] = {0, }; - + if (account_id <= 0 || input_mailbox_id <= 0) { EM_DEBUG_EXCEPTION("account_id[%d], input_mailbox_id[%d]", account_id, input_mailbox_id); - + if (err_code != NULL) *err_code = EMAIL_ERROR_INVALID_PARAM; return false; - } + } sqlite3 *local_db_handle = emstorage_get_db_connection(); EMSTORAGE_START_WRITE_TRANSACTION(transaction, error); @@ -5185,13 +5185,13 @@ INTERNAL_FUNC int emstorage_update_mailbox_total_count(int account_id, int input 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))); - + ret = true; FINISH_OFF: EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error); _DISCONNECT_DB; - + if (err_code != NULL) *err_code = error; @@ -5204,24 +5204,24 @@ FINISH_OFF: INTERNAL_FUNC int emstorage_update_mailbox(int account_id, int local_yn, int input_mailbox_id, emstorage_mailbox_tbl_t* result_mailbox, int transaction, int *err_code) { EM_DEBUG_FUNC_BEGIN("account_id[%d], local_yn[%d], input_mailbox_id[%d], result_mailbox[%p], transaction[%d], err_code[%p]", account_id, local_yn, input_mailbox_id, result_mailbox, transaction, err_code); - + if (account_id < FIRST_ACCOUNT_ID || input_mailbox_id <= 0 || !result_mailbox) { EM_DEBUG_EXCEPTION(" account_id[%d], local_yn[%d], input_mailbox_id[%d], result_mailbox[%p]", account_id, local_yn, input_mailbox_id, result_mailbox); - + if (err_code != NULL) *err_code = EMAIL_ERROR_INVALID_PARAM; return false; } - + int rc, ret = false; int error = EMAIL_ERROR_NONE; char sql_query_string[QUERY_SIZE] = {0, }; DB_STMT hStmt = NULL; int i = 0; - + sqlite3 *local_db_handle = emstorage_get_db_connection(); EMSTORAGE_START_WRITE_TRANSACTION(transaction, error); - + if (local_yn != -1) { SNPRINTF(sql_query_string, sizeof(sql_query_string), "UPDATE mail_box_tbl SET" @@ -5257,8 +5257,8 @@ INTERNAL_FUNC int emstorage_update_mailbox(int account_id, int local_yn, int inp , input_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))); @@ -5271,7 +5271,7 @@ INTERNAL_FUNC int emstorage_update_mailbox(int account_id, int local_yn, int inp _bind_stmt_field_data_int(hStmt, i++, result_mailbox->modifiable_yn); _bind_stmt_field_data_int(hStmt, i++, result_mailbox->mail_slot_size); _bind_stmt_field_data_int(hStmt, i++, result_mailbox->total_mail_count_on_server); - + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc); EM_DEBUG_DB_EXEC((rc == SQLITE_FULL), {error = EMAIL_ERROR_MAIL_MEMORY_FULL;goto FINISH_OFF; }, @@ -5284,7 +5284,7 @@ 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) { @@ -5292,7 +5292,7 @@ FINISH_OFF: error = EMAIL_ERROR_DB_FAILURE; } } - + if (err_code != NULL) *err_code = error; @@ -5304,24 +5304,24 @@ FINISH_OFF: INTERNAL_FUNC int emstorage_update_mailbox_type(int account_id, int local_yn, char *mailbox_name, email_mailbox_type_e new_mailbox_type, int transaction, int *err_code) { EM_DEBUG_FUNC_BEGIN("account_id[%d], local_yn[%d], mailbox_name[%s], new_mailbox_type[%d], transaction[%d], err_code[%p]", account_id, local_yn, mailbox_name, new_mailbox_type, transaction, err_code); - + if (account_id < FIRST_ACCOUNT_ID || !mailbox_name) { EM_DEBUG_EXCEPTION(" account_id[%d], local_yn[%d], mailbox_name[%s]", account_id, local_yn, mailbox_name); - + if (err_code != NULL) *err_code = EMAIL_ERROR_INVALID_PARAM; return false; } - + 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); - + EM_DEBUG_LOG("emstorage_update_mailbox_type"); - + DB_STMT hStmt = NULL; int i = 0; @@ -5348,13 +5348,13 @@ INTERNAL_FUNC int emstorage_update_mailbox_type(int account_id, int local_yn, ch } EM_DEBUG_LOG("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; }, ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); _bind_stmt_field_data_int(hStmt, i++, new_mailbox_type); - + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc); EM_DEBUG_DB_EXEC((rc == SQLITE_FULL), {error = EMAIL_ERROR_MAIL_MEMORY_FULL;goto FINISH_OFF; }, @@ -5370,7 +5370,7 @@ INTERNAL_FUNC int emstorage_update_mailbox_type(int account_id, int local_yn, ch } hStmt = NULL; } - + /* Update mail_tbl */ i = 0; SNPRINTF(sql_query_string, sizeof(sql_query_string), @@ -5382,13 +5382,13 @@ INTERNAL_FUNC int emstorage_update_mailbox_type(int account_id, int local_yn, ch , mailbox_name); EM_DEBUG_LOG("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; }, ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); _bind_stmt_field_data_int(hStmt, i++, new_mailbox_type); - + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc); EM_DEBUG_DB_EXEC((rc == SQLITE_FULL), {error = EMAIL_ERROR_MAIL_MEMORY_FULL;goto FINISH_OFF; }, @@ -5401,7 +5401,7 @@ INTERNAL_FUNC int emstorage_update_mailbox_type(int account_id, int local_yn, ch FINISH_OFF: EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error); _DISCONNECT_DB; - + if (hStmt != NULL) { rc = sqlite3_finalize(hStmt); if (rc != SQLITE_OK) { @@ -5409,7 +5409,7 @@ FINISH_OFF: error = EMAIL_ERROR_DB_FAILURE; } } - + if (err_code != NULL) *err_code = error; @@ -5568,7 +5568,7 @@ FINISH_OFF: INTERNAL_FUNC int emstorage_add_mailbox(emstorage_mailbox_tbl_t* mailbox_tbl, int transaction, int *err_code) { EM_DEBUG_FUNC_BEGIN("mailbox_tbl[%p], transaction[%d], err_code[%p]", mailbox_tbl, transaction, err_code); - + if (!mailbox_tbl) { if (err_code != NULL) *err_code = EMAIL_ERROR_INVALID_PARAM; @@ -5583,7 +5583,7 @@ INTERNAL_FUNC int emstorage_add_mailbox(emstorage_mailbox_tbl_t* mailbox_tbl, in time_t current_time; sqlite3 *local_db_handle = emstorage_get_db_connection(); EMSTORAGE_START_WRITE_TRANSACTION(transaction, error); - + EM_SAFE_STRCPY(sql_query_string, "SELECT max(rowid) FROM mail_box_tbl;"); EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, NULL, NULL, NULL), rc); @@ -5617,8 +5617,8 @@ INTERNAL_FUNC int emstorage_add_mailbox(emstorage_mailbox_tbl_t* mailbox_tbl, in ", ?" /* mail_slot_size */ ", ?" /* no_select */ ", ? )");/* last_sync_time */ - - + + 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_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, @@ -5646,7 +5646,7 @@ INTERNAL_FUNC int emstorage_add_mailbox(emstorage_mailbox_tbl_t* mailbox_tbl, in ("sqlite3_step fail:%dn", rc)); ret = true; - + FINISH_OFF: if (hStmt != NULL) { EM_DEBUG_LOG("before sqlite3_finalize hStmt = %p", hStmt); @@ -5660,8 +5660,8 @@ FINISH_OFF: EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error); _DISCONNECT_DB; - - if (error == EMAIL_ERROR_NONE && !emcore_notify_storage_event(NOTI_MAILBOX_ADD, mailbox_tbl->account_id, mailbox_tbl->mailbox_id, mailbox_tbl->mailbox_name, 0)) + + if (error == EMAIL_ERROR_NONE && !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"); if (err_code != NULL) @@ -5674,11 +5674,11 @@ FINISH_OFF: INTERNAL_FUNC int emstorage_set_all_mailbox_modifiable_yn(int account_id, int modifiable_yn, int transaction, int *err_code) { EM_DEBUG_FUNC_BEGIN("account_id[%d], modifiable_yn[%d], err_code[%p]", account_id, modifiable_yn, err_code); - + if (account_id < FIRST_ACCOUNT_ID) { EM_DEBUG_EXCEPTION("account_id[%d]", account_id); - + if (err_code != NULL) *err_code = EMAIL_ERROR_INVALID_PARAM; return false; @@ -5692,18 +5692,18 @@ INTERNAL_FUNC int emstorage_set_all_mailbox_modifiable_yn(int account_id, int mo 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))); rc = sqlite3_changes(local_db_handle); - if (rc == 0) + if (rc == 0) EM_DEBUG_EXCEPTION("All mailbox_name modifiable_yn set to 0 already"); - - + + ret = true; - + FINISH_OFF: EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error); _DISCONNECT_DB; @@ -5712,43 +5712,43 @@ FINISH_OFF: *err_code = error; EM_DEBUG_FUNC_END("ret [%d]", ret); return ret; - + } INTERNAL_FUNC int emstorage_delete_mailbox(int account_id, int local_yn, int input_mailbox_id, int transaction, int *err_code) { EM_DEBUG_FUNC_BEGIN("account_id[%d], local_yn[%d], input_mailbox_id[%d], transaction[%d], err_code[%p]", account_id, local_yn, input_mailbox_id, transaction, err_code); - - if (account_id < FIRST_ACCOUNT_ID) { + + if (account_id < FIRST_ACCOUNT_ID) { EM_DEBUG_EXCEPTION(" account_id[%d], local_yn[%d], input_mailbox_id[%d]", account_id, local_yn, input_mailbox_id); - + if (err_code != NULL) *err_code = EMAIL_ERROR_INVALID_PARAM; return false; } - + 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); - + if (local_yn == -1) SNPRINTF(sql_query_string, sizeof(sql_query_string), "DELETE FROM mail_box_tbl WHERE account_id = %d ", account_id); else SNPRINTF(sql_query_string, sizeof(sql_query_string), "DELETE FROM mail_box_tbl WHERE account_id = %d AND local_yn = %d ", account_id, local_yn); - + if (input_mailbox_id > 0) { /* 0 means all mailbox_name */ 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))); - + rc = sqlite3_changes(local_db_handle); if (rc == 0) { EM_DEBUG_EXCEPTION(" no (matched) mailbox_name found..."); @@ -5756,12 +5756,12 @@ INTERNAL_FUNC int emstorage_delete_mailbox(int account_id, int local_yn, int inp ret = true; } ret = true; - + 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)) EM_DEBUG_EXCEPTION("emcore_notify_storage_event[ NOTI_MAILBOX_ADD] : Notification Failed"); @@ -5777,31 +5777,31 @@ FINISH_OFF: INTERNAL_FUNC int emstorage_free_mailbox(emstorage_mailbox_tbl_t** mailbox_list, int count, int *err_code) { EM_DEBUG_FUNC_BEGIN("mailbox_list[%p], count[%d], err_code[%p]", mailbox_list, count, err_code); - + int ret = false; int error = EMAIL_ERROR_NONE; - + if (count > 0) { if (!mailbox_list || !*mailbox_list) { EM_DEBUG_EXCEPTION(" mailbox_list[%p], count[%d]", mailbox_list, count); - + error = EMAIL_ERROR_INVALID_PARAM; goto FINISH_OFF; } - + emstorage_mailbox_tbl_t* p = *mailbox_list; int i = 0; - + for (; i < count; i++) { EM_SAFE_FREE(p[i].mailbox_name); EM_SAFE_FREE(p[i].alias); } - + EM_SAFE_FREE(p); *mailbox_list = NULL; } - + ret = true; - + FINISH_OFF: if (err_code != NULL) *err_code = error; @@ -5813,15 +5813,15 @@ FINISH_OFF: INTERNAL_FUNC int emstorage_get_count_read_mail_uid(int account_id, char *mailbox_name, int *count, int transaction, int *err_code) { EM_DEBUG_FUNC_BEGIN("account_id[%d], mailbox_name[%p], count[%p], transaction[%d], err_code[%p]", account_id, mailbox_name , count, transaction, err_code); - + if (account_id < FIRST_ACCOUNT_ID || !mailbox_name || !count) { EM_DEBUG_EXCEPTION(" account_id[%d], mailbox_name[%p], count[%p], exist[%p]", account_id, mailbox_name, count); - + if (err_code != NULL) *err_code = EMAIL_ERROR_INVALID_PARAM; return false; } - + int rc = -1, ret = false; int error = EMAIL_ERROR_NONE; char sql_query_string[QUERY_SIZE] = {0, }; @@ -5839,13 +5839,13 @@ INTERNAL_FUNC int emstorage_get_count_read_mail_uid(int account_id, char *mailbo *count = atoi(result[1]); sqlite3_free_table(result); - + ret = true; - + FINISH_OFF: EMSTORAGE_FINISH_READ_TRANSACTION(transaction); _DISCONNECT_DB; - + if (err_code != NULL) *err_code = error; @@ -5858,28 +5858,28 @@ FINISH_OFF: INTERNAL_FUNC int emstorage_check_read_mail_uid(int account_id, char *mailbox_name, char *uid, int *exist, int transaction, int *err_code) { EM_DEBUG_FUNC_BEGIN("account_id[%d], mailbox_name[%p], uid[%p], exist[%p], transaction[%d], err_code[%p]", account_id, mailbox_name , uid, exist, transaction, err_code); - - if (account_id < FIRST_ACCOUNT_ID || !uid || !exist) { + + if (account_id < FIRST_ACCOUNT_ID || !uid || !exist) { EM_DEBUG_EXCEPTION(" account_id[%d], mailbox_name[%p], uid[%p], exist[%p]", account_id, mailbox_name , uid, exist); - + if (err_code != NULL) *err_code = EMAIL_ERROR_INVALID_PARAM; return false; } - + int rc = -1, 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); - + if (mailbox_name) { SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT COUNT(*) FROM mail_read_mail_uid_tbl WHERE account_id = %d AND mailbox_name = '%s' AND s_uid = '%s' ", account_id, mailbox_name, uid); } else { SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT COUNT(*) FROM mail_read_mail_uid_tbl WHERE account_id = %d AND s_uid = '%s' ", account_id, uid); } - + char **result; EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, NULL, NULL, NULL), rc); @@ -5888,18 +5888,18 @@ INTERNAL_FUNC int emstorage_check_read_mail_uid(int account_id, char *mailbox_na *exist = atoi(result[1]); sqlite3_free_table(result); - + if (*exist > 0) - *exist = 1; + *exist = 1; else *exist = 0; - + ret = true; - + FINISH_OFF: EMSTORAGE_FINISH_READ_TRANSACTION(transaction); _DISCONNECT_DB; - + if (err_code != NULL) *err_code = error; @@ -5910,14 +5910,14 @@ FINISH_OFF: INTERNAL_FUNC int emstorage_get_downloaded_mail(int mail_id, emstorage_mail_tbl_t** mail, int transaction, int *err_code) { EM_DEBUG_FUNC_BEGIN("mail_id[%d], mail[%p], err_code[%p]", mail_id, mail, err_code); - + if (!mail) { EM_DEBUG_EXCEPTION(" mail_id[%d], mail[%p]", mail_id, mail); if (err_code != NULL) *err_code = EMAIL_ERROR_INVALID_PARAM; return false; } - + int rc, ret = false, temp_rule; int error = EMAIL_ERROR_NONE; DB_STMT hStmt = NULL; @@ -5925,9 +5925,9 @@ INTERNAL_FUNC int emstorage_get_downloaded_mail(int mail_id, emstorage_mail_tbl_ sqlite3 *local_db_handle = emstorage_get_db_connection(); EMSTORAGE_START_READ_TRANSACTION(transaction); - + SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT * FROM mail_read_mail_uid_tbl WHERE local_uid = %d", mail_id); - + 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); @@ -5956,11 +5956,11 @@ INTERNAL_FUNC int emstorage_get_downloaded_mail(int mail_id, emstorage_mail_tbl_ _get_stmt_field_data_string(hStmt, &((*mail)->server_mail_id), 0, S_UID_IDX_IN_MAIL_READ_MAIL_UID_TBL); _get_stmt_field_data_int(hStmt, &((*mail)->mail_size), DATA1_IDX_IN_MAIL_READ_MAIL_UID_TBL); _get_stmt_field_data_int(hStmt, &temp_rule, FLAG_IDX_IN_MAIL_READ_MAIL_UID_TBL); - + (*mail)->server_mail_status = 1; - + ret = true; - + FINISH_OFF: if (hStmt != NULL) { EM_DEBUG_LOG("before sqlite3_finalize hStmt = %p", hStmt); @@ -5970,10 +5970,10 @@ FINISH_OFF: error = EMAIL_ERROR_DB_FAILURE; } } - + EMSTORAGE_FINISH_READ_TRANSACTION(transaction); _DISCONNECT_DB; - + if (err_code != NULL) *err_code = error; @@ -5987,7 +5987,7 @@ INTERNAL_FUNC int emstorage_get_downloaded_list(int account_id, int mailbox_id, EM_DEBUG_FUNC_BEGIN("account_id[%d], mailbox_id[%d], read_mail_uid[%p], count[%p], transaction[%d], err_code[%p]", account_id, mailbox_id, read_mail_uid, count, transaction, err_code); if (account_id < FIRST_ACCOUNT_ID || !read_mail_uid || !count) { EM_DEBUG_EXCEPTION(" account_id[%d], mailbox_id[%s], read_mail_uid[%p], count[%p]", account_id, mailbox_id, read_mail_uid, count); - + if (err_code != NULL) *err_code = EMAIL_ERROR_INVALID_PARAM; return false; @@ -5995,13 +5995,13 @@ INTERNAL_FUNC int emstorage_get_downloaded_list(int account_id, int mailbox_id, int rc, ret = false; int error = EMAIL_ERROR_NONE; - + DB_STMT hStmt = NULL; char sql_query_string[QUERY_SIZE] = {0, }; - + emstorage_read_mail_uid_tbl_t* p_data_tbl = NULL; int i = 0; - + sqlite3 *local_db_handle = emstorage_get_db_connection(); EMSTORAGE_START_READ_TRANSACTION(transaction); @@ -6011,9 +6011,9 @@ INTERNAL_FUNC int emstorage_get_downloaded_list(int account_id, int mailbox_id, 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); - - - + + + 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; }, @@ -6023,7 +6023,7 @@ INTERNAL_FUNC int emstorage_get_downloaded_list(int account_id, int mailbox_id, 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)); - + char **result; /* rc = sqlite3_get_table(local_db_handle, sql_query_string, &result, count, NULL, NULL); */ EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, count, NULL, NULL), rc); @@ -6060,7 +6060,7 @@ INTERNAL_FUNC int emstorage_get_downloaded_list(int account_id, int mailbox_id, 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: @@ -6068,20 +6068,20 @@ FINISH_OFF: *read_mail_uid = p_data_tbl; else if (p_data_tbl) 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); - + error = EMAIL_ERROR_DB_FAILURE; } } - + EMSTORAGE_FINISH_READ_TRANSACTION(transaction); _DISCONNECT_DB; - + if (err_code != NULL) *err_code = error; @@ -6093,24 +6093,24 @@ FINISH_OFF: INTERNAL_FUNC int emstorage_get_downloaded_mail_size(int account_id, char *mailbox_id, int local_uid, char *mailbox_name, char *uid, int *mail_size, int transaction, int *err_code) { EM_DEBUG_FUNC_BEGIN("account_id[%d], mailbox_id[%p], locacal_uid[%d], mailbox_name[%p], uid[%p], mail_size[%p], transaction[%d], err_code[%p]", account_id, mailbox_id, local_uid, mailbox_name, uid, mail_size, transaction, err_code); - + if (account_id < FIRST_ACCOUNT_ID || !mail_size) { EM_DEBUG_EXCEPTION(" account_id[%d], mailbox_id[%p], locacal_uid[%d], mailbox_name[%p], uid[%p], mail_size[%p]", account_id, mailbox_id, local_uid, mailbox_name, uid, mail_size); - + if (err_code != NULL) *err_code = EMAIL_ERROR_INVALID_PARAM; return false; } - + int rc, 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); - + if (mailbox_name) { SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT IFNULL(MAX(data1), 0) FROM mail_read_mail_uid_tbl " @@ -6130,8 +6130,8 @@ INTERNAL_FUNC int emstorage_get_downloaded_mail_size(int account_id, char *mailb "AND s_uid = '%s'", account_id, mailbox_id, local_uid, uid); } - - + + 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))); @@ -6144,26 +6144,26 @@ INTERNAL_FUNC int emstorage_get_downloaded_mail_size(int account_id, char *mailb if (rc == SQLITE_DONE) { EM_DEBUG_EXCEPTION(" no matched mail found...."); error = EMAIL_ERROR_MAIL_NOT_FOUND; - goto FINISH_OFF; + goto FINISH_OFF; } - + _get_stmt_field_data_int(hStmt, mail_size, 0); - + ret = true; - + FINISH_OFF: if (hStmt != NULL) { rc = sqlite3_finalize(hStmt); if (rc != SQLITE_OK) { EM_DEBUG_LOG(" sqlite3_finalize failed - %d", rc); - + error = EMAIL_ERROR_DB_FAILURE; } } - + EMSTORAGE_FINISH_READ_TRANSACTION(transaction); _DISCONNECT_DB; - + if (err_code != NULL) *err_code = error; @@ -6174,22 +6174,22 @@ FINISH_OFF: INTERNAL_FUNC int emstorage_add_downloaded_mail(emstorage_read_mail_uid_tbl_t* read_mail_uid, int transaction, int *err_code) { EM_DEBUG_FUNC_BEGIN("read_mail_uid[%p], transaction[%d], err_code[%p]", read_mail_uid, transaction, err_code); - + if (!read_mail_uid) { EM_DEBUG_EXCEPTION("read_mail_uid[%p]", read_mail_uid); if (err_code != NULL) *err_code = EMAIL_ERROR_INVALID_PARAM; return false; } - + int rc, rc2, 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_WRITE_TRANSACTION(transaction, error); - + char *sql = "SELECT max(rowid) FROM mail_read_mail_uid_tbl;"; char **result = NULL; @@ -6201,7 +6201,7 @@ INTERNAL_FUNC int emstorage_add_downloaded_mail(emstorage_read_mail_uid_tbl_t* r if (NULL==result[1]) rc = 1; else rc = atoi(result[1])+1; sqlite3_free_table(result); - + SNPRINTF(sql_query_string, sizeof(sql_query_string), "INSERT INTO mail_read_mail_uid_tbl VALUES " "( ?" @@ -6213,13 +6213,13 @@ INTERNAL_FUNC int emstorage_add_downloaded_mail(emstorage_read_mail_uid_tbl_t* r ", ?" ", ?" ", ? )"); - - + + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc2); if (rc2 != SQLITE_OK) { EM_DEBUG_LOG("sqlite3_prepare hStmt = %p", hStmt); EM_DEBUG_EXCEPTION("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)); - + error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; } @@ -6251,9 +6251,9 @@ INTERNAL_FUNC int emstorage_add_downloaded_mail(emstorage_read_mail_uid_tbl_t* r EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, ("sqlite3_step fail[%d] [%s]", rc, sqlite3_errmsg(local_db_handle))); - + ret = true; - + FINISH_OFF: if (hStmt != NULL) { EM_DEBUG_LOG(" sqlite3_finalize hStmt = %p", hStmt); @@ -6264,10 +6264,10 @@ FINISH_OFF: error = EMAIL_ERROR_DB_FAILURE; } } - + EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error); _DISCONNECT_DB; - + if (err_code != NULL) *err_code = error; @@ -6278,24 +6278,24 @@ FINISH_OFF: INTERNAL_FUNC int emstorage_change_read_mail_uid(int account_id, int mailbox_id, int local_uid, char *mailbox_name, char *uid, emstorage_read_mail_uid_tbl_t* read_mail_uid, int transaction, int *err_code) { EM_DEBUG_FUNC_BEGIN("account_id[%d], mailbox_id[%d], local_uid[%d], mailbox_name[%p], uid[%p], read_mail_uid[%p], transaction[%d], err_code[%p]", account_id, mailbox_id, local_uid, mailbox_name, uid, read_mail_uid, transaction, err_code); - + if (account_id < FIRST_ACCOUNT_ID || !read_mail_uid) { EM_DEBUG_EXCEPTION(" account_id[%d], mailbox_id[%d], local_uid[%d], mailbox_name[%p], uid[%p], read_mail_uid[%p]", account_id, mailbox_id, local_uid, mailbox_name, uid, read_mail_uid); - + if (err_code != NULL) *err_code = EMAIL_ERROR_INVALID_PARAM; return false; } - + int rc, 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_WRITE_TRANSACTION(transaction, error); - + SNPRINTF(sql_query_string, sizeof(sql_query_string), "UPDATE mail_read_mail_uid_tbl SET" " account_id = ?" @@ -6312,15 +6312,15 @@ INTERNAL_FUNC int emstorage_change_read_mail_uid(int account_id, int mailbox_id, " AND mailbox_name= ?" " AND s_uid = ?"); - + 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))); - - + + int i = 0; - + _bind_stmt_field_data_int(hStmt, i++, read_mail_uid->account_id); _bind_stmt_field_data_int(hStmt, i++, read_mail_uid->mailbox_id); _bind_stmt_field_data_int(hStmt, i++, read_mail_uid->local_uid); @@ -6334,14 +6334,14 @@ INTERNAL_FUNC int emstorage_change_read_mail_uid(int account_id, int mailbox_id, _bind_stmt_field_data_int(hStmt, i++, local_uid); _bind_stmt_field_data_string(hStmt, i++, (char*)mailbox_name, 0, MAILBOX_NAME_LEN_IN_MAIL_READ_MAIL_UID_TBL); _bind_stmt_field_data_string(hStmt, i++, (char*)uid, 0, S_UID_LEN_IN_MAIL_READ_MAIL_UID_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 (hStmt != NULL) { EM_DEBUG_LOG("sqlite3_finalize hStmt = %p", hStmt); @@ -6349,14 +6349,14 @@ FINISH_OFF: rc = sqlite3_finalize(hStmt); if (rc != SQLITE_OK) { EM_DEBUG_LOG(" sqlite3_finalize failed - %d", rc); - + error = EMAIL_ERROR_DB_FAILURE; } } - + EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error); _DISCONNECT_DB; - + if (err_code != NULL) *err_code = error; @@ -6370,42 +6370,42 @@ INTERNAL_FUNC int emstorage_remove_downloaded_mail(int account_id, char *mailbox if (account_id < FIRST_ACCOUNT_ID) { EM_DEBUG_EXCEPTION(" account_id[%d], mailbox_name[%s], uid[%s]", account_id, mailbox_name, uid); - + if (err_code != NULL) *err_code = EMAIL_ERROR_INVALID_PARAM; return false; } - + 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_read_mail_uid_tbl WHERE account_id = %d ", account_id); - + if (mailbox_name) { /* NULL means all mailbox_name */ SNPRINTF(sql_query_string+EM_SAFE_STRLEN(sql_query_string), sizeof(sql_query_string) - (1 + EM_SAFE_STRLEN(sql_query_string)), "AND mailbox_name = '%s' ", mailbox_name); } - + if (uid) { /* NULL means all mail */ SNPRINTF(sql_query_string+EM_SAFE_STRLEN(sql_query_string), sizeof(sql_query_string) - (1 + EM_SAFE_STRLEN(sql_query_string)), "AND s_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))); - - + + ret = true; - + FINISH_OFF: - + EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error); _DISCONNECT_DB; - + if (err_code != NULL) *err_code = error; @@ -6416,32 +6416,32 @@ FINISH_OFF: INTERNAL_FUNC int emstorage_free_read_mail_uid(emstorage_read_mail_uid_tbl_t** read_mail_uid, int count, int *err_code) { EM_DEBUG_FUNC_BEGIN("read_mail_uid[%p], count[%d], err_code[%p]", read_mail_uid, count, err_code); - + int ret = false; int error = EMAIL_ERROR_NONE; - + if (count > 0) { - if (!read_mail_uid || !*read_mail_uid) { + if (!read_mail_uid || !*read_mail_uid) { EM_DEBUG_EXCEPTION(" read_mail_uid[%p], count[%d]", read_mail_uid, count); - + error = EMAIL_ERROR_INVALID_PARAM; goto FINISH_OFF; } - + emstorage_read_mail_uid_tbl_t* p = *read_mail_uid; int i; - + for (i = 0; i < count; i++) { EM_SAFE_FREE(p[i].mailbox_name); EM_SAFE_FREE(p[i].s_uid); EM_SAFE_FREE(p[i].data2); } - + EM_SAFE_FREE(p); *read_mail_uid = NULL; } - + ret = true; - + FINISH_OFF: if (err_code != NULL) *err_code = error; @@ -6453,24 +6453,24 @@ FINISH_OFF: INTERNAL_FUNC int emstorage_get_rule_count(int account_id, int *count, int transaction, int *err_code) { EM_DEBUG_FUNC_BEGIN("account_id[%d], count[%p], transaction[%d], err_code[%p]", account_id, count, transaction, err_code); - + if (account_id != ALL_ACCOUNT || !count) { /* only global rule supported. */ EM_DEBUG_EXCEPTION(" account_id[%d], count[%p]", account_id, count); - + if (err_code != NULL) *err_code = EMAIL_ERROR_INVALID_PARAM; return false; } - + int rc = -1, 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 COUNT(*) FROM mail_rule_tbl WHERE account_id = %d", account_id); - + char **result; EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, NULL, NULL, NULL), rc); @@ -6479,13 +6479,13 @@ INTERNAL_FUNC int emstorage_get_rule_count(int account_id, int *count, int trans *count = atoi(result[1]); sqlite3_free_table(result); - + ret = true; - + FINISH_OFF: EMSTORAGE_FINISH_READ_TRANSACTION(transaction); _DISCONNECT_DB; - + if (err_code != NULL) *err_code = error; @@ -6496,34 +6496,34 @@ FINISH_OFF: 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) { EM_DEBUG_FUNC_BEGIN("account_id[%d], type[%d], start_idx[%d], select_num[%p], is_completed[%p], rule_list[%p], transaction[%d], err_code[%p]", account_id, type, start_idx, select_num, is_completed, rule_list, transaction, err_code); - + if (account_id != ALL_ACCOUNT || !select_num || !is_completed || !rule_list) { /* only global rule supported. */ EM_DEBUG_EXCEPTION(" account_id[%d], type[%d], start_idx[%d], select_num[%p], is_completed[%p], rule_list[%p]", account_id, type, start_idx, select_num, is_completed, rule_list); - + if (err_code != NULL) *err_code = EMAIL_ERROR_INVALID_PARAM; return false; } - + int ret = false; int error = EMAIL_ERROR_NONE; - + emstorage_rule_tbl_t* p_data_tbl = NULL; int i = 0, count = 0; DB_STMT hStmt = NULL; char sql_query_string[QUERY_SIZE] = {0, }; - + int rc; - + sqlite3 *local_db_handle = emstorage_get_db_connection(); EMSTORAGE_START_READ_TRANSACTION(transaction); - + if (type) SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT * FROM mail_rule_tbl WHERE account_id = %d AND type = %d", account_id, type); else SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT * FROM mail_rule_tbl WHERE account_id = %d ORDER BY type", account_id); - - + + 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; }, @@ -6548,16 +6548,16 @@ INTERNAL_FUNC int emstorage_get_rule(int account_id, int type, int start_idx, in goto FINISH_OFF; } - + if (!(p_data_tbl = (emstorage_rule_tbl_t*)malloc(sizeof(emstorage_rule_tbl_t) * count))) { EM_DEBUG_EXCEPTION(" malloc failed..."); - + error = EMAIL_ERROR_OUT_OF_MEMORY; goto FINISH_OFF; } - + memset(p_data_tbl, 0x00, sizeof(emstorage_rule_tbl_t) * count); - + for (i = 0; i < count; i++) { _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].account_id), ACCOUNT_ID_IDX_IN_MAIL_RULE_TBL); _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].rule_id), RULE_ID_IDX_IN_MAIL_RULE_TBL); @@ -6572,9 +6572,9 @@ INTERNAL_FUNC int emstorage_get_rule(int account_id, int type, int start_idx, in 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: EM_DEBUG_LOG("[%d] rules found.", count); @@ -6585,7 +6585,7 @@ FINISH_OFF: } else if (p_data_tbl != NULL) emstorage_free_rule(&p_data_tbl, count, NULL); /* CID FIX */ - + if (hStmt != NULL) { EM_DEBUG_LOG(" sqlite3_finalize hStmt = %p", hStmt); @@ -6596,10 +6596,10 @@ FINISH_OFF: } } - + EMSTORAGE_FINISH_READ_TRANSACTION(transaction); _DISCONNECT_DB; - + if (err_code != NULL) *err_code = error; @@ -6611,26 +6611,26 @@ INTERNAL_FUNC int emstorage_get_rule_by_id(int account_id, int rule_id, emstorag { EM_DEBUG_FUNC_BEGIN("account_id[%d], rule_id[%d], rule[%p], transaction[%d], err_code[%p]", account_id, rule_id, rule, transaction, err_code); - if (account_id != ALL_ACCOUNT || !rule) { + if (account_id != ALL_ACCOUNT || !rule) { EM_DEBUG_EXCEPTION(" account_id[%d], rule_id[%d], rule[%p]", account_id, rule_id, rule); - + if (err_code != NULL) *err_code = EMAIL_ERROR_INVALID_PARAM; return false; } - + emstorage_rule_tbl_t* p_data_tbl = NULL; int rc, 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); - + SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT * FROM mail_rule_tbl WHERE account_id = %d AND rule_id = %d", account_id, rule_id); - - + + 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))); @@ -6645,13 +6645,13 @@ INTERNAL_FUNC int emstorage_get_rule_by_id(int account_id, int rule_id, emstorag error = EMAIL_ERROR_FILTER_NOT_FOUND; goto FINISH_OFF; } - + if (!(p_data_tbl = (emstorage_rule_tbl_t*)malloc(sizeof(emstorage_rule_tbl_t)))) { EM_DEBUG_EXCEPTION(" malloc failed..."); error = EMAIL_ERROR_OUT_OF_MEMORY; goto FINISH_OFF; } - + memset(p_data_tbl, 0x00, sizeof(emstorage_rule_tbl_t)); _get_stmt_field_data_int(hStmt, &(p_data_tbl->account_id), ACCOUNT_ID_IDX_IN_MAIL_RULE_TBL); _get_stmt_field_data_int(hStmt, &(p_data_tbl->rule_id), RULE_ID_IDX_IN_MAIL_RULE_TBL); @@ -6661,29 +6661,29 @@ INTERNAL_FUNC int emstorage_get_rule_by_id(int account_id, int rule_id, emstorag _get_stmt_field_data_int(hStmt, &(p_data_tbl->target_mailbox_id), TARGET_MAILBOX_ID_IDX_IN_MAIL_RULE_TBL); _get_stmt_field_data_int(hStmt, &(p_data_tbl->flag1), FLAG1_IDX_IN_MAIL_RULE_TBL); _get_stmt_field_data_int(hStmt, &(p_data_tbl->flag2), FLAG2_IDX_IN_MAIL_RULE_TBL); - + ret = true; - + FINISH_OFF: if (ret == true) *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); - + error = EMAIL_ERROR_DB_FAILURE; } } - - - + + + EMSTORAGE_FINISH_READ_TRANSACTION(transaction); _DISCONNECT_DB; - + if (err_code != NULL) *err_code = error; @@ -6697,20 +6697,20 @@ INTERNAL_FUNC int emstorage_change_rule(int account_id, int rule_id, emstorage_r if (account_id != ALL_ACCOUNT || !new_rule) { /* only global rule supported. */ EM_DEBUG_EXCEPTION(" account_id[%d], rule_id[%d], new_rule[%p]", account_id, rule_id, new_rule); - + if (err_code != NULL) *err_code = EMAIL_ERROR_INVALID_PARAM; return false; } - + int rc, 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_WRITE_TRANSACTION(transaction, error); - + SNPRINTF(sql_query_string, sizeof(sql_query_string), "UPDATE mail_rule_tbl SET" " type = ?" @@ -6721,15 +6721,15 @@ INTERNAL_FUNC int emstorage_change_rule(int account_id, int rule_id, emstorage_r ", flag2 = ?" " WHERE account_id = ?" " AND rule_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_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))); - + int i = 0; - + _bind_stmt_field_data_int(hStmt, i++, new_rule->type); _bind_stmt_field_data_string(hStmt, i++, (char *)new_rule->value, 0, VALUE_LEN_IN_MAIL_RULE_TBL); _bind_stmt_field_data_int(hStmt, i++, new_rule->action_type); @@ -6738,14 +6738,14 @@ INTERNAL_FUNC int emstorage_change_rule(int account_id, int rule_id, emstorage_r _bind_stmt_field_data_int(hStmt, i++, new_rule->flag2); _bind_stmt_field_data_int(hStmt, i++, account_id); _bind_stmt_field_data_int(hStmt, i++, rule_id); - + 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 (hStmt != NULL) { EM_DEBUG_LOG(" Before sqlite3_finalize hStmt = %p", hStmt); @@ -6753,14 +6753,14 @@ FINISH_OFF: rc = sqlite3_finalize(hStmt); if (rc != SQLITE_OK) { EM_DEBUG_LOG(" sqlite3_finalize failed - %d", rc); - + error = EMAIL_ERROR_DB_FAILURE; } } EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error); _DISCONNECT_DB; - + if (err_code != NULL) *err_code = error; @@ -6775,7 +6775,7 @@ INTERNAL_FUNC int emstorage_find_rule(emstorage_rule_tbl_t* rule, int transactio if (!rule || rule->account_id != ALL_ACCOUNT) { /* only global rule supported. */ if (rule != NULL) EM_DEBUG_EXCEPTION(" rule->account_id[%d]", rule->account_id); - + if (err_code != NULL) *err_code = EMAIL_ERROR_INVALID_PARAM; return false; @@ -6783,7 +6783,7 @@ INTERNAL_FUNC int emstorage_find_rule(emstorage_rule_tbl_t* rule, int transactio DB_STMT hStmt = NULL; char sql_query_string[QUERY_SIZE] = {0, }; - + int error = EMAIL_ERROR_NONE; int rc, ret = false; @@ -6793,8 +6793,8 @@ INTERNAL_FUNC int emstorage_find_rule(emstorage_rule_tbl_t* rule, int transactio SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT rule_id FROM mail_rule_tbl WHERE type = %d AND UPPER(value) = UPPER('%s')", rule->type, rule->value); - - + + 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))); @@ -6810,7 +6810,7 @@ INTERNAL_FUNC int emstorage_find_rule(emstorage_rule_tbl_t* rule, int transactio goto FINISH_OFF; } - + ret = true; FINISH_OFF: @@ -6823,8 +6823,8 @@ FINISH_OFF: error = EMAIL_ERROR_DB_FAILURE; } } - - + + EMSTORAGE_FINISH_READ_TRANSACTION(transaction); _DISCONNECT_DB; @@ -6842,22 +6842,22 @@ INTERNAL_FUNC int emstorage_add_rule(emstorage_rule_tbl_t* rule, int transaction if (!rule || rule->account_id != ALL_ACCOUNT) { /* only global rule supported. */ if (rule != NULL) EM_DEBUG_EXCEPTION(" rule->account_id[%d]", rule->account_id); - + if (err_code != NULL) *err_code = EMAIL_ERROR_INVALID_PARAM; return false; } - + int rc, rc_2, 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_WRITE_TRANSACTION(transaction, error); - + char *sql; char **result; sql = "SELECT max(rowid) FROM mail_rule_tbl;"; @@ -6865,10 +6865,10 @@ INTERNAL_FUNC int emstorage_add_rule(emstorage_rule_tbl_t* rule, int 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))); - + if (NULL==result[1]) rc = 1; - else + else rc = atoi(result[1])+1; sqlite3_free_table(result); @@ -6882,14 +6882,14 @@ INTERNAL_FUNC int emstorage_add_rule(emstorage_rule_tbl_t* rule, int transaction ", ?" /* target_mailbox_id */ ", ?" /* flag1 */ ", ?)"); /* flag2 */ - + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc_2); if (rc_2 != SQLITE_OK) { EM_DEBUG_EXCEPTION("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc_2, sqlite3_errmsg(local_db_handle)); error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; } - + _bind_stmt_field_data_int(hStmt, ACCOUNT_ID_IDX_IN_MAIL_RULE_TBL, rule->account_id); _bind_stmt_field_data_int(hStmt, RULE_ID_IDX_IN_MAIL_RULE_TBL, rc); _bind_stmt_field_data_int(hStmt, TYPE_IDX_IN_MAIL_RULE_TBL, rule->type); @@ -6898,13 +6898,13 @@ INTERNAL_FUNC int emstorage_add_rule(emstorage_rule_tbl_t* rule, int transaction _bind_stmt_field_data_int(hStmt, TARGET_MAILBOX_ID_IDX_IN_MAIL_RULE_TBL, rule->target_mailbox_id); _bind_stmt_field_data_int(hStmt, FLAG1_IDX_IN_MAIL_RULE_TBL, rule->flag1); _bind_stmt_field_data_int(hStmt, FLAG2_IDX_IN_MAIL_RULE_TBL, rule->flag2); - + 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 (hStmt != NULL) { EM_DEBUG_LOG(" Before sqlite3_finalize hStmt = %p", hStmt); @@ -6912,14 +6912,14 @@ FINISH_OFF: rc = sqlite3_finalize(hStmt); if (rc != SQLITE_OK) { EM_DEBUG_LOG(" sqlite3_finalize failed - %d", rc); - + error = EMAIL_ERROR_DB_FAILURE; } } EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error); _DISCONNECT_DB; - + if (err_code != NULL) *err_code = error; @@ -6930,22 +6930,22 @@ FINISH_OFF: INTERNAL_FUNC int emstorage_delete_rule(int account_id, int rule_id, int transaction, int *err_code) { EM_DEBUG_FUNC_BEGIN("account_id[%d], rule_id[%d], transaction[%d], err_code[%p]", account_id, rule_id, transaction, err_code); - + if (account_id != ALL_ACCOUNT) { /* only global rule supported. */ EM_DEBUG_EXCEPTION(" account_id[%d], rule_id[%d]", account_id, rule_id); - + if (err_code != NULL) *err_code = EMAIL_ERROR_INVALID_PARAM; return false; } - + 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 account_id = %d AND rule_id = %d", account_id, rule_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; }, @@ -6953,17 +6953,17 @@ INTERNAL_FUNC int emstorage_delete_rule(int account_id, int rule_id, int transac rc = sqlite3_changes(local_db_handle); if (rc == 0) { EM_DEBUG_EXCEPTION(" no matched rule found..."); - + error = EMAIL_ERROR_FILTER_NOT_FOUND; goto FINISH_OFF; } - + ret = true; - + FINISH_OFF: EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error); _DISCONNECT_DB; - + if (err_code != NULL) *err_code = error; @@ -6977,25 +6977,25 @@ INTERNAL_FUNC int emstorage_free_rule(emstorage_rule_tbl_t** rule_list, int coun int ret = false; int error = EMAIL_ERROR_NONE; - + if (count > 0) { if (!rule_list || !*rule_list) { EM_DEBUG_EXCEPTION(" rule_list[%p], conut[%d]", rule_list, count); - + error = EMAIL_ERROR_INVALID_PARAM; goto FINISH_OFF; } - + emstorage_rule_tbl_t* p = *rule_list; int i = 0; - + for (; i < count; i++) { EM_SAFE_FREE(p[i].value); } - + EM_SAFE_FREE(p); *rule_list = NULL; } - + FINISH_OFF: if (err_code != NULL) *err_code = error; @@ -7007,28 +7007,28 @@ FINISH_OFF: INTERNAL_FUNC int emstorage_get_mail_count(int account_id, const char *mailbox_name, int *total, int *unseen, int transaction, int *err_code) { EM_DEBUG_FUNC_BEGIN("account_id[%d], mailbox_name[%s], total[%p], unseen[%p], transaction[%d], err_code[%p]", account_id, mailbox_name, total, unseen, transaction, err_code); - + if (!total && !unseen) { EM_DEBUG_EXCEPTION(" accoun_id[%d], mailbox_name[%s], total[%p], unseen[%p]", account_id, mailbox_name, total, unseen); if (err_code != NULL) *err_code = EMAIL_ERROR_INVALID_PARAM; return false; } - + int rc = -1, ret = false; int error = EMAIL_ERROR_NONE; DB_STMT hStmt = NULL; char sql_query_string[QUERY_SIZE] = {0, }; char err_msg[1024]; - + memset(&sql_query_string, 0x00, sizeof(sql_query_string)); sqlite3 *local_db_handle = emstorage_get_db_connection(); EMSTORAGE_START_READ_TRANSACTION(transaction); - + if (total) { SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT COUNT(*) FROM mail_tbl"); - + if (account_id != ALL_ACCOUNT) { SNPRINTF(sql_query_string + EM_SAFE_STRLEN(sql_query_string), sizeof(sql_query_string)-(EM_SAFE_STRLEN(sql_query_string)+1), " WHERE account_id = %d", account_id); if (mailbox_name) @@ -7036,7 +7036,7 @@ INTERNAL_FUNC int emstorage_get_mail_count(int account_id, const char *mailbox_n } else if (mailbox_name) SNPRINTF(sql_query_string + EM_SAFE_STRLEN(sql_query_string), sizeof(sql_query_string)-(EM_SAFE_STRLEN(sql_query_string)+1), " WHERE UPPER(mailbox_name) = UPPER('%s')", mailbox_name); - + #ifdef USE_GET_RECORD_COUNT_API char **result; @@ -7047,7 +7047,7 @@ INTERNAL_FUNC int emstorage_get_mail_count(int account_id, const char *mailbox_n *total = atoi(result[1]); sqlite3_free_table(result); #else - + 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_OFF2; }, ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); @@ -7058,18 +7058,18 @@ INTERNAL_FUNC int emstorage_get_mail_count(int account_id, const char *mailbox_n _get_stmt_field_data_int(hStmt, total, 0); #endif /* USE_GET_RECORD_COUNT_API */ } - + if (unseen) { SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT COUNT(*) FROM mail_tbl WHERE flags_seen_field = 0"); /* fSEEN = 0x01 */ - + if (account_id != ALL_ACCOUNT) SNPRINTF(sql_query_string + EM_SAFE_STRLEN(sql_query_string), sizeof(sql_query_string)-(EM_SAFE_STRLEN(sql_query_string)+1), " AND account_id = %d", account_id); - + if (mailbox_name) SNPRINTF(sql_query_string + EM_SAFE_STRLEN(sql_query_string), sizeof(sql_query_string)-(EM_SAFE_STRLEN(sql_query_string)+1), " AND mailbox_name = '%s'", mailbox_name); else SNPRINTF(sql_query_string + EM_SAFE_STRLEN(sql_query_string), sizeof(sql_query_string)-(EM_SAFE_STRLEN(sql_query_string)+1), " AND mailbox_type NOT IN (3, 5)"); - + char **result; 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; }, @@ -7077,13 +7077,13 @@ INTERNAL_FUNC int emstorage_get_mail_count(int account_id, const char *mailbox_n *unseen = atoi(result[1]); sqlite3_free_table(result); - + } FINISH_OFF: ret = true; - + FINISH_OFF2: - + #ifndef USE_PREPARED_QUERY_ if (hStmt != NULL) { rc = sqlite3_finalize(hStmt); @@ -7096,7 +7096,7 @@ FINISH_OFF2: EMSTORAGE_FINISH_READ_TRANSACTION(transaction); _DISCONNECT_DB; - + if (err_code != NULL) *err_code = error; @@ -7107,14 +7107,14 @@ FINISH_OFF2: INTERNAL_FUNC int emstorage_get_mail_field_by_id(int mail_id, int type, emstorage_mail_tbl_t** mail, int transaction, int *err_code) { EM_DEBUG_FUNC_BEGIN("mail_id[%d], type[%d], mail[%p], transaction[%d], err_code[%p]", mail_id, type, mail, transaction, err_code); - - if (mail_id <= 0 || !mail) { + + if (mail_id <= 0 || !mail) { EM_DEBUG_EXCEPTION("mail_id[%d], mail[%p]", mail_id, mail); if (err_code != NULL) *err_code = EMAIL_ERROR_INVALID_PARAM; return false; } - + emstorage_mail_tbl_t* p_data_tbl = (emstorage_mail_tbl_t*)malloc(sizeof(emstorage_mail_tbl_t)); if (p_data_tbl == NULL) { @@ -7123,46 +7123,46 @@ INTERNAL_FUNC int emstorage_get_mail_field_by_id(int mail_id, int type, emstorag *err_code = EMAIL_ERROR_OUT_OF_MEMORY; return false; } - + memset(p_data_tbl, 0x00, sizeof(emstorage_mail_tbl_t)); DB_STMT hStmt = NULL; char sql_query_string[QUERY_SIZE] = {0, }; int rc, ret = false; int error = EMAIL_ERROR_NONE; - + sqlite3 *local_db_handle = emstorage_get_db_connection(); EMSTORAGE_START_READ_TRANSACTION(transaction); - + switch (type) { case RETRIEVE_SUMMARY: SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT account_id, mail_id, mailbox_id, mailbox_name, server_mail_status, server_mailbox_name, server_mail_id, file_path_plain, file_path_html, flags_seen_field, save_status, lock_status, thread_id, thread_item_count FROM mail_tbl WHERE mail_id = %d", mail_id); break; - + case RETRIEVE_FIELDS_FOR_DELETE: SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT account_id, mail_id, server_mail_status, server_mailbox_name, server_mail_id FROM mail_tbl WHERE mail_id = %d", mail_id); - break; - + break; + case RETRIEVE_ACCOUNT: SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT account_id FROM mail_tbl WHERE mail_id = %d", mail_id); break; - + case RETRIEVE_FLAG: SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT account_id, mailbox_name, flags_seen_field, thread_id, mailbox_id FROM mail_tbl WHERE mail_id = %d", mail_id); break; - + default : EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM : type [%d]", type); error = EMAIL_ERROR_INVALID_PARAM; goto FINISH_OFF; } - + EM_DEBUG_LOG("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))); @@ -7194,7 +7194,7 @@ INTERNAL_FUNC int emstorage_get_mail_field_by_id(int mail_id, int type, emstorag _get_stmt_field_data_int(hStmt, &(p_data_tbl->thread_id), 12); _get_stmt_field_data_int(hStmt, &(p_data_tbl->thread_item_count), 13); break; - + case RETRIEVE_FIELDS_FOR_DELETE: _get_stmt_field_data_int(hStmt, &(p_data_tbl->account_id), 0); _get_stmt_field_data_int(hStmt, &(p_data_tbl->mail_id), 1); @@ -7202,11 +7202,11 @@ INTERNAL_FUNC int emstorage_get_mail_field_by_id(int mail_id, int type, emstorag _get_stmt_field_data_string(hStmt, &(p_data_tbl->server_mailbox_name), 0, 3); _get_stmt_field_data_string(hStmt, &(p_data_tbl->server_mail_id), 0, 4); break; - + case RETRIEVE_ACCOUNT: _get_stmt_field_data_int(hStmt, &(p_data_tbl->account_id), 0); break; - + case RETRIEVE_FLAG: _get_stmt_field_data_int(hStmt, &(p_data_tbl->account_id), 0); _get_stmt_field_data_string(hStmt, &(p_data_tbl->mailbox_name), 0, 1); @@ -7215,9 +7215,9 @@ INTERNAL_FUNC int emstorage_get_mail_field_by_id(int mail_id, int type, emstorag _get_stmt_field_data_int(hStmt, &(p_data_tbl->mailbox_id), 4); break; } - + ret = true; - + FINISH_OFF: if (ret == true) *mail = p_data_tbl; @@ -7226,18 +7226,18 @@ FINISH_OFF: if (hStmt != NULL) { EM_DEBUG_LOG("Before sqlite3_finalize hStmt = %p", hStmt); - + rc = sqlite3_finalize(hStmt); if (rc != SQLITE_OK) { EM_DEBUG_EXCEPTION("sqlite3_finalize failed - %d", rc); error = EMAIL_ERROR_DB_FAILURE; } } - + EMSTORAGE_FINISH_READ_TRANSACTION(transaction); _DISCONNECT_DB; - + if (err_code != NULL) *err_code = error; @@ -7248,7 +7248,7 @@ FINISH_OFF: 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) { EM_DEBUG_FUNC_BEGIN("mail_ids[%p], number_of_mails [%d], type[%d], mail[%p], transaction[%d], err_code[%p]", mail_ids, number_of_mails, type, mail, transaction, err_code); - + DB_STMT hStmt = NULL; int ret = false; int error = EMAIL_ERROR_NONE; @@ -7259,13 +7259,13 @@ INTERNAL_FUNC int emstorage_get_mail_field_by_multiple_mail_id(int mail_ids[], i emstorage_mail_tbl_t* p_data_tbl = NULL; sqlite3 *local_db_handle = NULL; - if (number_of_mails <= 0 || !mail_ids) { + if (number_of_mails <= 0 || !mail_ids) { EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM"); if (err_code != NULL) *err_code = EMAIL_ERROR_INVALID_PARAM; return false; } - + p_data_tbl = (emstorage_mail_tbl_t*)em_malloc(sizeof(emstorage_mail_tbl_t) * number_of_mails); query_string_length = (sizeof(char) * 8 * number_of_mails) + 512; @@ -7281,9 +7281,9 @@ INTERNAL_FUNC int emstorage_get_mail_field_by_multiple_mail_id(int mail_ids[], i *err_code = EMAIL_ERROR_OUT_OF_MEMORY; return false; } - + local_db_handle = emstorage_get_db_connection(); - + EMSTORAGE_START_READ_TRANSACTION(transaction); switch (type) { @@ -7292,35 +7292,35 @@ INTERNAL_FUNC int emstorage_get_mail_field_by_multiple_mail_id(int mail_ids[], i "SELECT account_id, mail_id, mailbox_name, server_mail_status, server_mailbox_name, server_mail_id, file_path_plain, file_path_html, flags_seen_field, save_status, lock_status, thread_id, thread_item_count FROM mail_tbl WHERE mail_id in ("); field_count = 13; break; - + case RETRIEVE_FIELDS_FOR_DELETE: cur_sql_query_string = SNPRINTF(sql_query_string, query_string_length, "SELECT account_id, mail_id, server_mail_status, server_mailbox_name, server_mail_id FROM mail_tbl WHERE mail_id in ("); field_count = 5; - break; - + break; + case RETRIEVE_ACCOUNT: cur_sql_query_string = SNPRINTF(sql_query_string, query_string_length, "SELECT account_id FROM mail_tbl WHERE mail_id in ("); field_count = 1; break; - + case RETRIEVE_FLAG: cur_sql_query_string = SNPRINTF(sql_query_string, query_string_length, "SELECT account_id, mailbox_id, flags_seen_field, thread_id FROM mail_tbl WHERE mail_id in ("); field_count = 4; break; - + default : EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM : type [%d]", type); error = EMAIL_ERROR_INVALID_PARAM; goto FINISH_OFF; } - for(i = 0; i < number_of_mails; i++) + for(i = 0; i < number_of_mails; i++) cur_sql_query_string += SNPRINTF_OFFSET(sql_query_string, cur_sql_query_string, QUERY_SIZE, "%d,", mail_ids[i]); 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)); EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, &item_count, 0, NULL), rc); @@ -7360,7 +7360,7 @@ INTERNAL_FUNC int emstorage_get_mail_field_by_multiple_mail_id(int mail_ids[], i _get_table_field_data_int(result, &(p_data_tbl[i].thread_id), col_index++); _get_table_field_data_int(result, &(p_data_tbl[i].thread_item_count), col_index++); break; - + case RETRIEVE_FIELDS_FOR_DELETE: _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++); @@ -7368,11 +7368,11 @@ INTERNAL_FUNC int emstorage_get_mail_field_by_multiple_mail_id(int mail_ids[], i _get_table_field_data_string(result, &(p_data_tbl[i].server_mailbox_name), 0, col_index++); _get_table_field_data_string(result, &(p_data_tbl[i].server_mail_id), 0, col_index++); break; - + case RETRIEVE_ACCOUNT: _get_table_field_data_int(result, &(p_data_tbl[i].account_id), col_index++); break; - + 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].mailbox_id), col_index++); @@ -7385,7 +7385,7 @@ INTERNAL_FUNC int emstorage_get_mail_field_by_multiple_mail_id(int mail_ids[], i sqlite3_free_table(result); ret = true; - + FINISH_OFF: if (ret == true) *mail = p_data_tbl; @@ -7394,7 +7394,7 @@ 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); @@ -7404,7 +7404,7 @@ FINISH_OFF: EMSTORAGE_FINISH_READ_TRANSACTION(transaction); _DISCONNECT_DB; - + EM_SAFE_FREE(sql_query_string); if (err_code != NULL) @@ -7417,18 +7417,18 @@ FINISH_OFF: INTERNAL_FUNC int emstorage_get_mail_by_id(int mail_id, emstorage_mail_tbl_t** mail, int transaction, int *err_code) { EM_DEBUG_FUNC_BEGIN("mail_id[%d], mail[%p], transaction[%d], err_code[%p]", mail_id, mail, transaction, err_code); - - if (mail_id <= 0 || !mail) { + + if (mail_id <= 0 || !mail) { EM_DEBUG_EXCEPTION("mail_id[%d], mail[%p]", mail_id, mail); if (err_code != NULL) *err_code = EMAIL_ERROR_INVALID_PARAM; return false; } - + int ret = false, error = EMAIL_ERROR_NONE, count; char conditional_clause[QUERY_SIZE] = {0, }; 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); @@ -7438,13 +7438,13 @@ INTERNAL_FUNC int emstorage_get_mail_by_id(int mail_id, emstorage_mail_tbl_t** m } ret = true; - + FINISH_OFF: if (ret == true) *mail = p_data_tbl; else if (p_data_tbl != NULL) emstorage_free_mail(&p_data_tbl, 1, &error); - + if (err_code != NULL) *err_code = error; @@ -7456,36 +7456,36 @@ INTERNAL_FUNC int emstorage_mail_search_start(emstorage_search_filter_t* search, { EM_DEBUG_FUNC_BEGIN("search[%p], account_id[%d], mailbox_name[%p], sorting[%d], search_handle[%p], searched[%p], transaction[%d], err_code[%p]", search, account_id, mailbox_name, sorting, search_handle, searched, transaction, err_code); - if (!search_handle || !searched) { + if (!search_handle || !searched) { if (err_code != NULL) *err_code = EMAIL_ERROR_INVALID_PARAM; EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM"); EM_DEBUG_FUNC_END("false"); return false; } - + emstorage_search_filter_t* p = search; int error = EMAIL_ERROR_NONE; DB_STMT hStmt = NULL; char sql_query_string[QUERY_SIZE] = {0, }; int rc, ret = false; int and = false, mail_count = 0; - + sqlite3 *local_db_handle = emstorage_get_db_connection(); EMSTORAGE_START_READ_TRANSACTION(transaction); - + SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT * FROM mail_tbl"); - + if (account_id != ALL_ACCOUNT) { SNPRINTF(sql_query_string + EM_SAFE_STRLEN(sql_query_string), sizeof(sql_query_string)-(EM_SAFE_STRLEN(sql_query_string)+1), " WHERE account_id = %d", account_id); and = true; } - + if (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", mailbox_name); and = true; } - + while (p) { if (p->key_type) { @@ -7508,13 +7508,13 @@ INTERNAL_FUNC int emstorage_mail_search_start(emstorage_search_filter_t* search, p = p->next; } } - + 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); - + 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))); @@ -7523,7 +7523,7 @@ INTERNAL_FUNC int emstorage_mail_search_start(emstorage_search_filter_t* search, 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)); - + char **result; EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, &mail_count, NULL, NULL), rc); @@ -7531,9 +7531,9 @@ INTERNAL_FUNC int emstorage_mail_search_start(emstorage_search_filter_t* search, ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); sqlite3_free_table(result); - + ret = true; - + FINISH_OFF: if (ret == true) { *search_handle = (int)hStmt; @@ -7548,11 +7548,11 @@ FINISH_OFF: error = EMAIL_ERROR_DB_FAILURE; } } - + EMSTORAGE_FINISH_READ_TRANSACTION(transaction); _DISCONNECT_DB; } - + if (err_code != NULL) *err_code = error; @@ -7566,12 +7566,12 @@ INTERNAL_FUNC int emstorage_mail_search_result(int search_handle, emstorage_mail if (search_handle == 0 || !data) { EM_DEBUG_EXCEPTION(" search_handle[%d], type[%d], data[%p]", search_handle, type, data); - + if (err_code != NULL) *err_code = EMAIL_ERROR_INVALID_PARAM; return false; } - + emstorage_mail_tbl_t* p_data_tbl = NULL; DB_STMT hStmt = (DB_STMT)search_handle; int rc, ret = false; @@ -7581,16 +7581,16 @@ INTERNAL_FUNC int emstorage_mail_search_result(int search_handle, emstorage_mail case RETRIEVE_ID: _get_stmt_field_data_int(hStmt, (int *)data, MAIL_ID_IDX_IN_MAIL_TBL); break; - + case RETRIEVE_ENVELOPE: case RETRIEVE_ALL: if (!(p_data_tbl = em_malloc(sizeof(emstorage_mail_tbl_t)))) { EM_DEBUG_EXCEPTION(" em_malloc failed..."); - + error = EMAIL_ERROR_OUT_OF_MEMORY; goto FINISH_OFF; } - + _get_stmt_field_data_int (hStmt, &(p_data_tbl->mail_id), MAIL_ID_IDX_IN_MAIL_TBL); _get_stmt_field_data_int (hStmt, &(p_data_tbl->account_id), ACCOUNT_ID_IDX_IN_MAIL_TBL); _get_stmt_field_data_string(hStmt, &(p_data_tbl->mailbox_name), 0, MAILBOX_NAME_IDX_IN_MAIL_TBL); @@ -7615,7 +7615,7 @@ INTERNAL_FUNC int emstorage_mail_search_result(int search_handle, emstorage_mail _get_stmt_field_data_int (hStmt, (int*)&(p_data_tbl->message_class), MESSAGE_CLASS_IDX_IN_MAIL_TBL); _get_stmt_field_data_int (hStmt, (int*)&(p_data_tbl->digest_type), DIGEST_TYPE_IDX_IN_MAIL_TBL); _get_stmt_field_data_int (hStmt, (int*)&(p_data_tbl->smime_type), SMIME_TYPE_IDX_IN_MAIL_TBL); - + if (type == RETRIEVE_ALL) { _get_stmt_field_data_int (hStmt, &(p_data_tbl->server_mail_status), SERVER_MAIL_STATUS_IDX_IN_MAIL_TBL); _get_stmt_field_data_string(hStmt, &(p_data_tbl->server_mailbox_name), 0, SERVER_MAILBOX_NAME_IDX_IN_MAIL_TBL); @@ -7628,12 +7628,12 @@ INTERNAL_FUNC int emstorage_mail_search_result(int search_handle, emstorage_mail _get_stmt_field_data_string(hStmt, &(p_data_tbl->email_address_recipient), 1, EMAIL_ADDRESS_RECIPIENT_IDX_IN_MAIL_TBL); _get_stmt_field_data_int (hStmt, &(p_data_tbl->attachment_count), ATTACHMENT_COUNT_IDX_IN_MAIL_TBL); _get_stmt_field_data_string(hStmt, &(p_data_tbl->preview_text), 1, PREVIEW_TEXT_IDX_IN_MAIL_TBL); - + } - + if (p_data_tbl->body_download_status) { struct stat buf; - + if (p_data_tbl->file_path_html) { if (stat(p_data_tbl->file_path_html, &buf) == -1) p_data_tbl->body_download_status = 0; @@ -7642,60 +7642,60 @@ INTERNAL_FUNC int emstorage_mail_search_result(int search_handle, emstorage_mail if (stat(p_data_tbl->file_path_plain, &buf) == -1) p_data_tbl->body_download_status = 0; } - else + else p_data_tbl->body_download_status = 0; } - + *((emstorage_mail_tbl_t**)data) = p_data_tbl; break; - + case RETRIEVE_SUMMARY: if (!(p_data_tbl = malloc(sizeof(emstorage_mail_tbl_t)))) { EM_DEBUG_EXCEPTION(" malloc failed..."); - + error = EMAIL_ERROR_OUT_OF_MEMORY; goto FINISH_OFF; } - + memset(p_data_tbl, 0x00, sizeof(emstorage_mail_tbl_t)); - + _get_stmt_field_data_int (hStmt, &(p_data_tbl->mail_id), MAIL_ID_IDX_IN_MAIL_TBL); _get_stmt_field_data_int (hStmt, &(p_data_tbl->account_id), ACCOUNT_ID_IDX_IN_MAIL_TBL); _get_stmt_field_data_string(hStmt, &(p_data_tbl->mailbox_name), 0, MAILBOX_NAME_IDX_IN_MAIL_TBL); _get_stmt_field_data_int (hStmt, &(p_data_tbl->server_mail_status), SERVER_MAIL_STATUS_IDX_IN_MAIL_TBL); _get_stmt_field_data_string(hStmt, &(p_data_tbl->server_mailbox_name), 0, SERVER_MAILBOX_NAME_IDX_IN_MAIL_TBL); _get_stmt_field_data_string(hStmt, &(p_data_tbl->server_mail_id), 0, SERVER_MAIL_ID_IDX_IN_MAIL_TBL); - + *((emstorage_mail_tbl_t**)data) = p_data_tbl; break; - + case RETRIEVE_ADDRESS: if (!(p_data_tbl = malloc(sizeof(emstorage_mail_tbl_t)))) { EM_DEBUG_EXCEPTION(" malloc failed..."); error = EMAIL_ERROR_OUT_OF_MEMORY; goto FINISH_OFF; } - + memset(p_data_tbl, 0x00, sizeof(emstorage_mail_tbl_t)); _get_stmt_field_data_int(hStmt, &(p_data_tbl->mail_id), MAIL_ID_IDX_IN_MAIL_TBL); _get_stmt_field_data_string(hStmt, &(p_data_tbl->email_address_sender), 1, EMAIL_ADDRESS_SENDER_IDX_IN_MAIL_TBL); _get_stmt_field_data_string(hStmt, &(p_data_tbl->email_address_recipient), 1, EMAIL_ADDRESS_RECIPIENT_IDX_IN_MAIL_TBL); *((emstorage_mail_tbl_t**)data) = p_data_tbl; break; - + default: break; } - + 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 (err_code != NULL) *err_code = error; @@ -7706,10 +7706,10 @@ FINISH_OFF: INTERNAL_FUNC int emstorage_mail_search_end(int search_handle, int transaction, int *err_code) { EM_DEBUG_FUNC_BEGIN("search_handle[%d], transaction[%d], err_code[%p]", search_handle, transaction, err_code); - + int error = EMAIL_ERROR_NONE; int rc, ret = false; - + if (search_handle == 0) { EM_DEBUG_EXCEPTION(" search_handle[%d]", search_handle); error = EMAIL_ERROR_INVALID_PARAM; @@ -7717,7 +7717,7 @@ 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); @@ -7725,13 +7725,13 @@ INTERNAL_FUNC int emstorage_mail_search_end(int search_handle, int transaction, EM_DEBUG_EXCEPTION(" sqlite3_finalize failed - %d", rc); error = EMAIL_ERROR_DB_FAILURE; } - + ret = true; - + FINISH_OFF: EMSTORAGE_FINISH_READ_TRANSACTION(transaction); _DISCONNECT_DB; - + if (err_code != NULL) *err_code = error; @@ -7745,7 +7745,7 @@ INTERNAL_FUNC int emstorage_change_mail(int mail_id, emstorage_mail_tbl_t* mail, if (mail_id <= 0 || !mail) { EM_DEBUG_EXCEPTION(" mail_id[%d], mail[%p]", mail_id, mail); - + if (err_code != NULL) *err_code = EMAIL_ERROR_INVALID_PARAM; return false; @@ -7753,7 +7753,7 @@ INTERNAL_FUNC int emstorage_change_mail(int mail_id, emstorage_mail_tbl_t* mail, DB_STMT hStmt = NULL; char sql_query_string[QUERY_SIZE] = {0, }; - int rc = -1; + int rc = -1; int ret = false; int error = EMAIL_ERROR_NONE; int i = 0; @@ -7761,7 +7761,7 @@ INTERNAL_FUNC int emstorage_change_mail(int mail_id, emstorage_mail_tbl_t* mail, char mailbox_id_param_string[10] = {0,}; EMSTORAGE_START_WRITE_TRANSACTION(transaction, error); - + SNPRINTF(sql_query_string, sizeof(sql_query_string), "UPDATE mail_tbl SET" " mail_id = ?" @@ -7784,13 +7784,13 @@ INTERNAL_FUNC int emstorage_change_mail(int mail_id, emstorage_mail_tbl_t* mail, ", file_path_plain = ?" ", file_path_html = ?" ", date_time = ?" - ", flags_seen_field = ?" - ", flags_deleted_field = ?" - ", flags_flagged_field = ?" - ", flags_answered_field = ?" - ", flags_recent_field = ?" - ", flags_draft_field = ?" - ", flags_forwarded_field = ?" + ", 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 = ?" @@ -7802,11 +7802,11 @@ INTERNAL_FUNC int emstorage_change_mail(int mail_id, emstorage_mail_tbl_t* mail, " WHERE mail_id = %d AND account_id != 0 " , mail_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++, mail->mail_id); _bind_stmt_field_data_int (hStmt, i++, mail->account_id); _bind_stmt_field_data_int (hStmt, i++, mail->mailbox_id); @@ -7846,7 +7846,7 @@ INTERNAL_FUNC int emstorage_change_mail(int mail_id, emstorage_mail_tbl_t* mail, 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)); - + rc = sqlite3_changes(local_db_handle); if (rc == 0) { EM_DEBUG_EXCEPTION(" no matched mail found..."); @@ -7856,9 +7856,9 @@ INTERNAL_FUNC int emstorage_change_mail(int mail_id, emstorage_mail_tbl_t* mail, SNPRINTF(mailbox_id_param_string, 10, "%d", mail->mailbox_id); if (!emcore_notify_storage_event(NOTI_MAIL_UPDATE, mail->account_id, mail->mail_id, mailbox_id_param_string, 0)) EM_DEBUG_EXCEPTION(" emcore_notify_storage_event Failed [ NOTI_MAIL_UPDATE ] >>>> "); - + ret = true; - + FINISH_OFF: if (hStmt != NULL) { EM_DEBUG_LOG("Before sqlite3_finalize hStmt = %p", hStmt); @@ -7871,7 +7871,7 @@ FINISH_OFF: EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error); _DISCONNECT_DB; - + if (err_code != NULL) *err_code = error; @@ -7885,25 +7885,25 @@ INTERNAL_FUNC int emstorage_modify_mailbox_of_mails(char *old_mailbox_name, char if (!old_mailbox_name && !new_mailbox_name) { EM_DEBUG_EXCEPTION(" old_mailbox_name[%p], new_mailbox_name[%p]", old_mailbox_name, new_mailbox_name); - + if (err_code != NULL) *err_code = 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); EM_DEBUG_LOG("Old Mailbox Name [ %s ] , New Mailbox name [ %s ] ", old_mailbox_name, new_mailbox_name); - + SNPRINTF(sql_query_string, sizeof(sql_query_string), "UPDATE mail_tbl SET mailbox_name = '%s' WHERE mailbox_name = '%s'", new_mailbox_name, old_mailbox_name); - + 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))); @@ -7911,11 +7911,11 @@ INTERNAL_FUNC int emstorage_modify_mailbox_of_mails(char *old_mailbox_name, char rc = sqlite3_changes(local_db_handle); if (rc == 0) { EM_DEBUG_EXCEPTION(" no matched mail found..."); - + error = EMAIL_ERROR_MAIL_NOT_FOUND; goto FINISH_OFF; } - + EM_DEBUG_LOG(" Modification done in mail_read_mail_uid_tbl based on Mailbox name "); /* Modify the mailbox_name name in mail_read_mail_uid_tbl table */ SNPRINTF(sql_query_string, sizeof(sql_query_string), "UPDATE mail_read_mail_uid_tbl SET mailbox_name = '%s' WHERE mailbox_name = '%s'", new_mailbox_name, old_mailbox_name); @@ -7930,17 +7930,17 @@ INTERNAL_FUNC int emstorage_modify_mailbox_of_mails(char *old_mailbox_name, char error = EMAIL_ERROR_MAIL_NOT_FOUND; goto FINISH_OFF; } - + if (!emcore_notify_storage_event(NOTI_MAILBOX_UPDATE, 1, 0, new_mailbox_name, 0)) EM_DEBUG_EXCEPTION(" emcore_notify_storage_event[ NOTI_MAILBOX_UPDATE] : Notification Failed >>> "); - + ret = true; - + FINISH_OFF: EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error); _DISCONNECT_DB; - + if (err_code != NULL) *err_code = error; @@ -7978,11 +7978,11 @@ INTERNAL_FUNC int emstorage_clean_save_status(int save_status, int *err_code) EM_DEBUG_LOG(" No Matched Mail Exists "); error = EMAIL_ERROR_MAIL_NOT_FOUND; } - + ret = true; FINISH_OFF: - + if (err_code != NULL) *err_code = error; @@ -8004,7 +8004,7 @@ INTERNAL_FUNC int emstorage_set_field_of_mails_with_integer_value(int account_id char *parameter_string = NULL; sqlite3 *local_db_handle = emstorage_get_db_connection(); email_mail_attribute_type target_mail_attribute_type = 0; - + if (!mail_ids || !field_name || account_id == 0) { EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM"); if (err_code != NULL) @@ -8029,8 +8029,8 @@ INTERNAL_FUNC int emstorage_set_field_of_mails_with_integer_value(int account_id error = EMAIL_ERROR_OUT_OF_MEMORY; goto FINISH_OFF; } - - for(i = 0; i < mail_ids_count; i++) + + for(i = 0; i < mail_ids_count; i++) cur_mail_id_string += SNPRINTF_OFFSET(mail_id_string_buffer, cur_mail_id_string, mail_id_string_buffer_length, "%d,", mail_ids[i]); if(EM_SAFE_STRLEN(mail_id_string_buffer) > 1) @@ -8057,7 +8057,7 @@ INTERNAL_FUNC int emstorage_set_field_of_mails_with_integer_value(int 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))); - if (sqlite3_changes(local_db_handle) == 0) + if (sqlite3_changes(local_db_handle) == 0) EM_DEBUG_LOG("no mail matched..."); ret = true; @@ -8065,10 +8065,10 @@ 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 (ret && parameter_string && !emcore_notify_storage_event(NOTI_MAIL_FIELD_UPDATE, account_id, target_mail_attribute_type, parameter_string, value)) EM_DEBUG_EXCEPTION("emcore_notify_storage_event failed : NOTI_MAIL_FIELD_UPDATE [%s,%d]", field_name, value); - + EM_SAFE_FREE(mail_id_string_buffer); EM_SAFE_FREE(parameter_string); @@ -8082,14 +8082,14 @@ FINISH_OFF: 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) { EM_DEBUG_FUNC_BEGIN("mail_id[%d], type[%d], mail[%p], transaction[%d], err_code[%p]", mail_id, type, mail, transaction, err_code); - + if (mail_id <= 0 || !mail) { EM_DEBUG_EXCEPTION(" mail_id[%d], type[%d], mail[%p]", mail_id, type, mail); if (err_code != NULL) *err_code = EMAIL_ERROR_INVALID_PARAM; return false; } - + int ret = false; int error = EMAIL_ERROR_NONE; int move_flag = 0; @@ -8104,7 +8104,7 @@ INTERNAL_FUNC int emstorage_change_mail_field(int mail_id, email_mail_change_typ sqlite3 *local_db_handle = emstorage_get_db_connection(); EMSTORAGE_START_WRITE_TRANSACTION(transaction, error); - + switch (type) { case APPEND_BODY: SNPRINTF(sql_query_string, sizeof(sql_query_string), @@ -8112,13 +8112,13 @@ INTERNAL_FUNC int emstorage_change_mail_field(int mail_id, email_mail_change_typ " body_download_status = ?" ", file_path_plain = ?" ", file_path_html = ?" - ", flags_seen_field = ?" - ", flags_deleted_field = ?" - ", flags_flagged_field = ?" - ", flags_answered_field = ?" - ", flags_recent_field = ?" - ", flags_draft_field = ?" - ", flags_forwarded_field = ?" + ", flags_seen_field = ?" + ", flags_deleted_field = ?" + ", flags_flagged_field = ?" + ", flags_answered_field = ?" + ", flags_recent_field = ?" + ", flags_draft_field = ?" + ", flags_forwarded_field = ?" ", DRM_status = ?" ", attachment_count = ?" ", preview_text= ?" @@ -8129,12 +8129,12 @@ INTERNAL_FUNC int emstorage_change_mail_field(int mail_id, email_mail_change_typ " WHERE mail_id = %d AND account_id != 0" , mail_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))); i = 0; - + _bind_stmt_field_data_int(hStmt, i++, mail->body_download_status); _bind_stmt_field_data_string(hStmt, i++, (char *)mail->file_path_plain, 0, TEXT_1_LEN_IN_MAIL_TBL); _bind_stmt_field_data_string(hStmt, i++, (char *)mail->file_path_html, 0, TEXT_2_LEN_IN_MAIL_TBL); @@ -8153,14 +8153,14 @@ INTERNAL_FUNC int emstorage_change_mail_field(int mail_id, email_mail_change_typ _bind_stmt_field_data_int(hStmt, i++, mail->digest_type); _bind_stmt_field_data_int(hStmt, i++, mail->smime_type); break; - + case UPDATE_MAILBOX: { int err; emstorage_mailbox_tbl_t *mailbox_tbl; - + if (!emstorage_get_mailbox_by_name(mail->account_id, -1, mail->mailbox_name, &mailbox_tbl, false, &err)) { EM_DEBUG_EXCEPTION(" emstorage_get_mailbox_by_name failed - %d", err); - + goto FINISH_OFF; } @@ -8178,7 +8178,7 @@ INTERNAL_FUNC int emstorage_change_mail_field(int mail_id, email_mail_change_typ EM_DEBUG_LOG("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))); @@ -8186,7 +8186,7 @@ INTERNAL_FUNC int emstorage_change_mail_field(int mail_id, email_mail_change_typ emstorage_free_mailbox(&mailbox_tbl, 1, NULL); } break; - + case UPDATE_FLAG: SNPRINTF(sql_query_string, sizeof(sql_query_string), "UPDATE mail_tbl SET" @@ -8207,14 +8207,14 @@ INTERNAL_FUNC int emstorage_change_mail_field(int mail_id, email_mail_change_typ , mail->flags_forwarded_field , mail_id); EM_DEBUG_LOG("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))); break; - + case UPDATE_EXTRA_FLAG: SNPRINTF(sql_query_string, sizeof(sql_query_string), "UPDATE mail_tbl SET" @@ -8231,8 +8231,8 @@ INTERNAL_FUNC int emstorage_change_mail_field(int mail_id, email_mail_change_typ , mail->DRM_status , mail_id); EM_DEBUG_LOG("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))); @@ -8246,13 +8246,13 @@ INTERNAL_FUNC int emstorage_change_mail_field(int mail_id, email_mail_change_typ , mail->lock_status , mail_id); EM_DEBUG_LOG("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))); break; - + case UPDATE_MAIL: SNPRINTF(sql_query_string, sizeof(sql_query_string), "UPDATE mail_tbl SET" @@ -8290,13 +8290,13 @@ INTERNAL_FUNC int emstorage_change_mail_field(int mail_id, email_mail_change_typ ", smime_type = ?" " WHERE mail_id = %d AND account_id != 0" , mail_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_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))); - i = 0; + i = 0; _bind_stmt_field_data_string(hStmt, i++, (char*)mail->full_address_from, 1, FROM_LEN_IN_MAIL_TBL); _bind_stmt_field_data_string(hStmt, i++, (char*)mail->full_address_reply, 1, REPLY_TO_LEN_IN_MAIL_TBL); _bind_stmt_field_data_string(hStmt, i++, (char*)mail->full_address_to, 1, TO_LEN_IN_MAIL_TBL); @@ -8330,7 +8330,7 @@ INTERNAL_FUNC int emstorage_change_mail_field(int mail_id, email_mail_change_typ _bind_stmt_field_data_int (hStmt, i++, mail->digest_type); _bind_stmt_field_data_int (hStmt, i++, mail->smime_type); break; - + case UPDATE_DATETIME: { time_t now = time(NULL); @@ -8346,7 +8346,7 @@ INTERNAL_FUNC int emstorage_change_mail_field(int mail_id, email_mail_change_typ ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); break; } - + case UPDATE_FROM_CONTACT_INFO: EM_DEBUG_LOG("NVARCHAR : emstorage_change_mail_field - mail change type is UPDATE_FROM_CONTACT_INFO"); SNPRINTF(sql_query_string, sizeof(sql_query_string), @@ -8354,16 +8354,16 @@ INTERNAL_FUNC int emstorage_change_mail_field(int mail_id, email_mail_change_typ " email_address_sender = ?," " WHERE mail_id = %d", mail_id); - + 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_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))); i = 0; _bind_stmt_field_data_string(hStmt, i++, (char *)mail->email_address_sender, 1, FROM_EMAIL_ADDRESS_LEN_IN_MAIL_TBL); break; - + case UPDATE_TO_CONTACT_INFO: EM_DEBUG_LOG("NVARCHAR : emstorage_change_mail_field - mail change type is UPDATE_TO_CONTACT_INFO"); SNPRINTF(sql_query_string, sizeof(sql_query_string), @@ -8371,9 +8371,9 @@ INTERNAL_FUNC int emstorage_change_mail_field(int mail_id, email_mail_change_typ " email_address_recipient = ?," " WHERE mail_id = %d", mail_id); - + 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_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))); @@ -8391,7 +8391,7 @@ INTERNAL_FUNC int emstorage_change_mail_field(int mail_id, email_mail_change_typ mail_id); 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_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))); @@ -8400,7 +8400,7 @@ INTERNAL_FUNC int emstorage_change_mail_field(int mail_id, email_mail_change_typ _bind_stmt_field_data_string(hStmt, i++, (char *)mail->email_address_recipient, 1, TO_EMAIL_ADDRESS_LEN_IN_MAIL_TBL); break; - + #ifdef __FEATURE_PARTIAL_BODY_DOWNLOAD__ case UPDATE_PARTIAL_BODY_DOWNLOAD: @@ -8415,19 +8415,19 @@ INTERNAL_FUNC int emstorage_change_mail_field(int mail_id, email_mail_change_typ " WHERE mail_id = %d" , mail_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))); i = 0; - + _bind_stmt_field_data_int(hStmt, i++, mail->body_download_status); _bind_stmt_field_data_string(hStmt, i++, (char *)mail->file_path_plain, 0, TEXT_1_LEN_IN_MAIL_TBL); _bind_stmt_field_data_string(hStmt, i++, (char *)mail->file_path_html, 0, TEXT_2_LEN_IN_MAIL_TBL); _bind_stmt_field_data_int(hStmt, i++, mail->attachment_count); _bind_stmt_field_data_int(hStmt, i++, mail->inline_content_count); _bind_stmt_field_data_string(hStmt, i++, (char *)mail->preview_text, 0, PREVIEWBODY_LEN_IN_MAIL_TBL); - + break; #endif @@ -8450,14 +8450,14 @@ INTERNAL_FUNC int emstorage_change_mail_field(int mail_id, email_mail_change_typ _bind_stmt_field_data_string(hStmt, i++, (char*)mail->file_path_html, 0, TEXT_2_LEN_IN_MAIL_TBL); _bind_stmt_field_data_string(hStmt, i++, (char*)mail->file_path_mime_entity, 0, MIME_ENTITY_LEN_IN_MAIL_TBL); break; - + default: EM_DEBUG_LOG(" type[%d]", type); - + error = EMAIL_ERROR_INVALID_PARAM; goto FINISH_OFF; } - + if (hStmt != NULL) { EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc); @@ -8468,11 +8468,11 @@ INTERNAL_FUNC int emstorage_change_mail_field(int mail_id, email_mail_change_typ rc = sqlite3_changes(local_db_handle); if (rc == 0) { EM_DEBUG_EXCEPTION(" no matched mail found..."); - + error = EMAIL_ERROR_MAIL_NOT_FOUND; goto FINISH_OFF; } - } + } if (mail->account_id == 0) { emstorage_mail_tbl_t* mail_for_account_tbl = NULL; @@ -8487,7 +8487,7 @@ INTERNAL_FUNC int emstorage_change_mail_field(int mail_id, email_mail_change_typ } ret = true; - + FINISH_OFF: if (hStmt != NULL) { @@ -8503,7 +8503,7 @@ FINISH_OFF: _DISCONNECT_DB; /*h.gahlaut@samsung.com: Moving publication of notification after commiting transaction to DB */ - + if (ret == true && move_flag != 1) { if (!emstorage_get_mailbox_name_by_mailbox_type(mail->account_id, EMAIL_MAILBOX_TYPE_SENTBOX, &mailbox_name, false, &error)) EM_DEBUG_EXCEPTION(" emstorage_get_mailbox_name_by_mailbox_type failed - %d", error); @@ -8523,7 +8523,7 @@ FINISH_OFF: } EM_SAFE_FREE(mailbox_name); - + if (err_code != NULL) *err_code = error; @@ -8533,7 +8533,7 @@ FINISH_OFF: INTERNAL_FUNC int emstorage_increase_mail_id(int *mail_id, int transaction, int *err_code) { EM_DEBUG_FUNC_BEGIN("mail_id[%p], transaction[%d], err_code[%p]", mail_id, transaction, err_code); - + int rc, ret = false; int error = EMAIL_ERROR_NONE; int latest_mail_id = 0; @@ -8556,11 +8556,11 @@ INTERNAL_FUNC int emstorage_increase_mail_id(int *mail_id, int transaction, int ("SQL(%s) sqlite3_get_table fail:%d -%s", sql, rc, sqlite3_errmsg(local_db_handle))); if (NULL == result[1]) rc = 1; - else + else rc = atoi(result[1]) + 1; sqlite3_free_table(result); - latest_mail_id = rc; + latest_mail_id = rc; } latest_mail_id++; @@ -8575,13 +8575,13 @@ INTERNAL_FUNC int emstorage_increase_mail_id(int *mail_id, int transaction, int #endif /* __FEATURE_USE_SHARED_MUTEX_FOR_GENERATING_MAIL_ID__ */ ret = true; - + FINISH_OFF: _DISCONNECT_DB; - + if (err_code != NULL) *err_code = error; - + EM_DEBUG_FUNC_END("ret [%d]", ret); return ret; } @@ -8591,14 +8591,14 @@ INTERNAL_FUNC int emstorage_add_mail(emstorage_mail_tbl_t *mail_tbl_data, int ge { EM_PROFILE_BEGIN(profile_emstorage_add_mail); EM_DEBUG_FUNC_BEGIN("mail_tbl_data[%p], get_id[%d], transaction[%d], err_code[%p]", mail_tbl_data, get_id, transaction, err_code); - + if (!mail_tbl_data) { EM_DEBUG_EXCEPTION("mail_tbl_data[%p], get_id[%d]", mail_tbl_data, get_id); if (err_code != NULL) *err_code = EMAIL_ERROR_INVALID_PARAM; return false; } - + int rc, ret = false; int error = EMAIL_ERROR_NONE; char sql_query_string[QUERY_SIZE] = {0, }; @@ -8606,7 +8606,7 @@ INTERNAL_FUNC int emstorage_add_mail(emstorage_mail_tbl_t *mail_tbl_data, int ge sqlite3 *local_db_handle = emstorage_get_db_connection(); EMSTORAGE_START_WRITE_TRANSACTION(transaction, error); - + if (get_id) { /* increase unique id */ char *sql = "SELECT max(rowid) FROM mail_tbl;"; @@ -8618,7 +8618,7 @@ INTERNAL_FUNC int emstorage_add_mail(emstorage_mail_tbl_t *mail_tbl_data, int ge if (NULL == result[1]) rc = 1; - else + else rc = atoi(result[1])+1; sqlite3_free_table(result); @@ -8681,7 +8681,7 @@ INTERNAL_FUNC int emstorage_add_mail(emstorage_mail_tbl_t *mail_tbl_data, int ge ", ?" /* digest_type */ ", ?" /* smime_type */ ")"); - + 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))); @@ -8739,7 +8739,7 @@ INTERNAL_FUNC int emstorage_add_mail(emstorage_mail_tbl_t *mail_tbl_data, int ge 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)); ret = true; - + FINISH_OFF: if (hStmt != NULL) { @@ -8752,7 +8752,7 @@ FINISH_OFF: EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error); _DISCONNECT_DB; - + if (err_code != NULL) *err_code = error; @@ -8779,8 +8779,8 @@ INTERNAL_FUNC int emstorage_move_multiple_mails_on_db(int input_source_account_i if (err_code != NULL) *err_code = EMAIL_ERROR_INVALID_PARAM; return false; - } - + } + sqlite3 *local_db_handle = emstorage_get_db_connection(); if ((error = emstorage_get_mailbox_by_id(input_mailbox_id, &result_mailbox)) != EMAIL_ERROR_NONE || !result_mailbox) { @@ -8795,7 +8795,7 @@ INTERNAL_FUNC int emstorage_move_multiple_mails_on_db(int input_source_account_i cur_conditional_clause = SNPRINTF(conditional_clause, QUERY_SIZE, "WHERE mail_id in ("); - for(i = 0; i < number_of_mails; i++) + for(i = 0; i < number_of_mails; i++) cur_conditional_clause += SNPRINTF_OFFSET(conditional_clause, cur_conditional_clause, QUERY_SIZE, "%d,", mail_ids[i]); conditional_clause[EM_SAFE_STRLEN(conditional_clause) - 1] = ')'; @@ -8834,8 +8834,8 @@ INTERNAL_FUNC int emstorage_move_multiple_mails_on_db(int input_source_account_i /* Updating a mail_read_mail_uid_tbl */ memset(conditional_clause, 0x00, QUERY_SIZE); cur_conditional_clause = SNPRINTF(conditional_clause, QUERY_SIZE, "WHERE local_uid in ("); - - for(i = 0; i < number_of_mails; i++) + + for(i = 0; i < number_of_mails; i++) cur_conditional_clause += SNPRINTF_OFFSET(conditional_clause, cur_conditional_clause, QUERY_SIZE, "%d,", mail_ids[i]); /* prevent 34415 */ @@ -8851,11 +8851,11 @@ INTERNAL_FUNC int emstorage_move_multiple_mails_on_db(int input_source_account_i ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); ret = true; - + FINISH_OFF: EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error); _DISCONNECT_DB; - + EM_SAFE_FREE(target_mailbox_name); if (err_code != NULL) @@ -8864,7 +8864,7 @@ FINISH_OFF: EM_DEBUG_FUNC_END("ret [%d]", ret); return ret; } - + INTERNAL_FUNC int emstorage_delete_mail(int mail_id, int from_server, int transaction, int *err_code) { EM_DEBUG_FUNC_BEGIN("mail_id[%d], transaction[%d], err_code[%p]", mail_id, transaction, err_code); @@ -8874,31 +8874,31 @@ INTERNAL_FUNC int emstorage_delete_mail(int mail_id, int from_server, int transa if (err_code != NULL) *err_code = EMAIL_ERROR_INVALID_PARAM; return false; - } - + } + 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); - + 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))); - + ret = true; - + FINISH_OFF: EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error); _DISCONNECT_DB; - + if (err_code != NULL) *err_code = error; @@ -8919,32 +8919,32 @@ INTERNAL_FUNC int emstorage_delete_multiple_mails(int mail_ids[], int number_of_ if (err_code != NULL) *err_code = EMAIL_ERROR_INVALID_PARAM; return false; - } - + } + sqlite3 *local_db_handle = emstorage_get_db_connection(); EMSTORAGE_START_WRITE_TRANSACTION(transaction, error); - + cur_sql_query_string = SNPRINTF(sql_query_string, sizeof(sql_query_string), "DELETE FROM mail_tbl WHERE mail_id in ("); - - for(i = 0; i < number_of_mails; i++) + + for(i = 0; i < number_of_mails; i++) cur_sql_query_string += SNPRINTF_OFFSET(sql_query_string, cur_sql_query_string, QUERY_SIZE, "%d,", mail_ids[i]); /* prevent 34414 */ 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))); - + ret = true; - + FINISH_OFF: EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error); _DISCONNECT_DB; - + if (err_code != NULL) *err_code = error; @@ -8955,10 +8955,10 @@ FINISH_OFF: INTERNAL_FUNC int emstorage_delete_mail_by_account(int account_id, int transaction, int *err_code) { EM_DEBUG_FUNC_BEGIN("account_id[%d], transaction[%d], err_code[%p]", account_id, transaction, err_code); - + if (account_id < FIRST_ACCOUNT_ID) { EM_DEBUG_EXCEPTION("account_id[%d]", account_id); - + if (err_code != NULL) *err_code = EMAIL_ERROR_INVALID_PARAM; return false; @@ -8967,13 +8967,13 @@ INTERNAL_FUNC int emstorage_delete_mail_by_account(int account_id, int transacti 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_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))); @@ -8983,11 +8983,11 @@ INTERNAL_FUNC int emstorage_delete_mail_by_account(int account_id, int transacti EM_DEBUG_EXCEPTION(" no mail found..."); error = EMAIL_ERROR_MAIL_NOT_FOUND; } - + /* Delete all mails mail_read_mail_uid_tbl table based on account id */ SNPRINTF(sql_query_string, sizeof(sql_query_string), "DELETE FROM mail_read_mail_uid_tbl WHERE account_id = %d", account_id); EM_DEBUG_LOG("Query [%s]", sql_query_string); - + 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))); @@ -9000,14 +9000,14 @@ INTERNAL_FUNC int emstorage_delete_mail_by_account(int account_id, int transacti if (!emcore_notify_storage_event(NOTI_MAIL_DELETE_WITH_ACCOUNT, account_id, 0 , NULL, 0)) EM_DEBUG_EXCEPTION(" emcore_notify_storage_event Failed [ NOTI_MAIL_DELETE_ALL ]"); - + ret = true; - + FINISH_OFF: EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error); _DISCONNECT_DB; - + if (err_code != NULL) *err_code = error; @@ -9018,7 +9018,7 @@ FINISH_OFF: INTERNAL_FUNC int emstorage_delete_mail_by_mailbox(int account_id, char *mailbox, int transaction, int *err_code) { EM_DEBUG_FUNC_BEGIN("account_id[%d], mailbox[%p], transaction[%d], err_code[%p]", account_id, mailbox, transaction, err_code); - + if (account_id < FIRST_ACCOUNT_ID || !mailbox) { EM_DEBUG_EXCEPTION(" account_id[%d], mailbox[%p]", account_id, mailbox); if (err_code != NULL) @@ -9029,18 +9029,18 @@ INTERNAL_FUNC int emstorage_delete_mail_by_mailbox(int account_id, char *mailbox 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_tbl WHERE account_id = %d AND mailbox_name = '%s'", account_id, mailbox); 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_read_mail_uid_tbl */ SNPRINTF(sql_query_string, sizeof(sql_query_string), "DELETE FROM mail_read_mail_uid_tbl WHERE account_id = %d AND mailbox_name = '%s'", account_id, mailbox); @@ -9049,16 +9049,16 @@ INTERNAL_FUNC int emstorage_delete_mail_by_mailbox(int account_id, char *mailbox 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 (!emcore_notify_storage_event(NOTI_MAIL_DELETE_ALL, account_id, 0 , mailbox, 0)) EM_DEBUG_EXCEPTION(" emcore_notify_storage_event Failed [ NOTI_MAIL_DELETE_ALL ] >>>> "); - + ret = true; - + FINISH_OFF: EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error); _DISCONNECT_DB; - + if (err_code != NULL) *err_code = error; @@ -9069,11 +9069,11 @@ FINISH_OFF: INTERNAL_FUNC int emstorage_free_mail(emstorage_mail_tbl_t** mail_list, int count, int *err_code) { EM_DEBUG_FUNC_BEGIN("mail_list[%p], count[%d], err_code[%p]", mail_list, count, err_code); - + if (count > 0) { if ((mail_list == NULL) || (*mail_list == NULL)) { EM_DEBUG_EXCEPTION("mail_ilst[%p], count[%d]", mail_list, count); - + if (err_code) *err_code = EMAIL_ERROR_INVALID_PARAM; return false; @@ -9105,7 +9105,7 @@ INTERNAL_FUNC int emstorage_free_mail(emstorage_mail_tbl_t** mail_list, int coun } EM_SAFE_FREE(*mail_list); } - + if (err_code != NULL) *err_code = EMAIL_ERROR_NONE; @@ -9116,21 +9116,21 @@ INTERNAL_FUNC int emstorage_free_mail(emstorage_mail_tbl_t** mail_list, int coun INTERNAL_FUNC int emstorage_get_attachment_count(int mail_id, int *count, int transaction, int *err_code) { EM_DEBUG_FUNC_BEGIN("mail_id[%d], count[%p], transaction[%d], err_code[%p]", mail_id, count, transaction, err_code); - + if (mail_id <= 0 || !count) { EM_DEBUG_EXCEPTION("mail_id[%d], count[%p]", mail_id, count); if (err_code != NULL) *err_code = EMAIL_ERROR_INVALID_PARAM; return false; } - + int rc = -1, 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 COUNT(*) FROM mail_attachment_tbl WHERE mail_id = %d", mail_id); char **result; @@ -9141,14 +9141,14 @@ INTERNAL_FUNC int emstorage_get_attachment_count(int mail_id, int *count, int tr *count = atoi(result[1]); sqlite3_free_table(result); - + ret = true; - + FINISH_OFF: - + EMSTORAGE_FINISH_READ_TRANSACTION(transaction); _DISCONNECT_DB; - + if (err_code != NULL) *err_code = error; @@ -9158,13 +9158,13 @@ FINISH_OFF: 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) { - EM_DEBUG_FUNC_BEGIN("input_mail_id[%d], input_transaction[%d], output_attachment_list[%p], output_attachment_count[%p]", input_mail_id, output_attachment_list, input_transaction, output_attachment_count); - + EM_DEBUG_FUNC_BEGIN("input_mail_id[%d], input_transaction[%d], output_attachment_list[%p], output_attachment_count[%p]", input_mail_id, input_transaction, output_attachment_list, output_attachment_count); + if (input_mail_id <= 0 || !output_attachment_list || !output_attachment_count) { EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM"); return EMAIL_ERROR_INVALID_PARAM; } - + int error = EMAIL_ERROR_NONE; int i = 0; int rc = -1; @@ -9173,7 +9173,7 @@ INTERNAL_FUNC int emstorage_get_attachment_list(int input_mail_id, int input_tra emstorage_attachment_tbl_t* p_data_tbl = NULL; DB_STMT hStmt = NULL; sqlite3 *local_db_handle = emstorage_get_db_connection(); - + EMSTORAGE_START_READ_TRANSACTION(input_transaction); SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT COUNT(*) FROM mail_attachment_tbl WHERE mail_id = %d", input_mail_id); EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, NULL, NULL, NULL), rc); @@ -9182,23 +9182,23 @@ INTERNAL_FUNC int emstorage_get_attachment_list(int input_mail_id, int input_tra *output_attachment_count = atoi(result[1]); sqlite3_free_table(result); - + if(*output_attachment_count == 0) { error = EMAIL_ERROR_NONE; goto FINISH_OFF; } - + p_data_tbl = (emstorage_attachment_tbl_t*)em_malloc(sizeof(emstorage_attachment_tbl_t) * (*output_attachment_count)); - + if (!p_data_tbl) { EM_DEBUG_EXCEPTION("em_malloc failed..."); error = EMAIL_ERROR_OUT_OF_MEMORY; goto FINISH_OFF; } - + SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT * FROM mail_attachment_tbl WHERE mail_id = %d ORDER BY attachment_id", input_mail_id); EM_DEBUG_LOG("sql_query_string [%s]", sql_query_string); - + 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))); @@ -9223,12 +9223,12 @@ 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_drm_method), ATTACHMENT_DRM_METHOD_IDX_IN_MAIL_ATTACHMENT_TBL); _get_stmt_field_data_int (hStmt, &(p_data_tbl[i].attachment_inline_content_status), ATTACHMENT_INLINE_CONTENT_STATUS_IDX_IN_MAIL_ATTACHMENT_TBL); _get_stmt_field_data_string(hStmt, &(p_data_tbl[i].attachment_mime_type), 0, ATTACHMENT_MIME_TYPE_IDX_IN_MAIL_ATTACHMENT_TBL); - + EM_DEBUG_LOG("attachment[%d].attachment_id : %d", i, p_data_tbl[i].attachment_id); 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)); } - + FINISH_OFF: if (error == EMAIL_ERROR_NONE) @@ -9237,14 +9237,14 @@ FINISH_OFF: emstorage_free_attachment(&p_data_tbl, *output_attachment_count, NULL); rc = sqlite3_finalize(hStmt); - + if (rc != SQLITE_OK) { EM_DEBUG_EXCEPTION("sqlite3_finalize failed [%d]", rc); error = EMAIL_ERROR_DB_FAILURE; } - + EMSTORAGE_FINISH_READ_TRANSACTION(input_transaction); - + _DISCONNECT_DB; EM_DEBUG_FUNC_END("error [%d]", error); @@ -9254,7 +9254,7 @@ FINISH_OFF: INTERNAL_FUNC int emstorage_get_attachment(int attachment_id, emstorage_attachment_tbl_t** attachment, int transaction, int *err_code) { EM_DEBUG_FUNC_BEGIN("attachment_id[%d], attachment[%p], transaction[%d], err_code[%p]", attachment_id, attachment, transaction, err_code); - + if (attachment_id <= 0 || !attachment) { EM_DEBUG_EXCEPTION("attachment_id[%d], attachment[%p]", attachment_id, attachment); if (err_code != NULL) @@ -9266,20 +9266,20 @@ INTERNAL_FUNC int emstorage_get_attachment(int attachment_id, emstorage_attachme 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_id = %d", attachment_id); 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(" 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 && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, @@ -9313,10 +9313,10 @@ INTERNAL_FUNC int emstorage_get_attachment(int attachment_id, emstorage_attachme #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 - +#endif + ret = true; - + FINISH_OFF: if (ret == true) *attachment = p_data_tbl; @@ -9333,7 +9333,7 @@ FINISH_OFF: EMSTORAGE_FINISH_READ_TRANSACTION(transaction); _DISCONNECT_DB; - + if (err_code != NULL) *err_code = error; @@ -9347,26 +9347,26 @@ INTERNAL_FUNC int emstorage_get_attachment_nth(int mail_id, int nth, emstorage_a if (mail_id <= 0 || nth <= 0 || !attachment_tbl) { EM_DEBUG_EXCEPTION(" mail_id[%d], nth[%d], attachment[%p]", mail_id, nth, attachment_tbl); - + if (err_code != NULL) *err_code = EMAIL_ERROR_INVALID_PARAM; return false; } - + emstorage_attachment_tbl_t* p_data_tbl = NULL; char *p = 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 mail_id = %d ORDER BY attachment_id LIMIT %d, 1", mail_id, (nth - 1)); EM_DEBUG_LOG("query = [%s]", sql_query_string); - + DB_STMT hStmt = NULL; - + 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))); @@ -9381,7 +9381,7 @@ INTERNAL_FUNC int emstorage_get_attachment_nth(int mail_id, int nth, emstorage_a 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; @@ -9407,26 +9407,26 @@ INTERNAL_FUNC int emstorage_get_attachment_nth(int mail_id, int nth, emstorage_a p_data_tbl->encoding = sqlite3_column_int(hStmt, ENCODING_IDX_IN_MAIL_ATTACHMENT_TBL); if ((p = (char *)sqlite3_column_text(hStmt, SECTION_IDX_IN_MAIL_ATTACHMENT_TBL)) && (int)EM_SAFE_STRLEN(p)) p_data_tbl->section= cpy_str(p); -#endif +#endif ret = true; - + FINISH_OFF: if (ret == true) *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 failed - %d", rc); error = EMAIL_ERROR_DB_FAILURE; } } - + EMSTORAGE_FINISH_READ_TRANSACTION(transaction); _DISCONNECT_DB; - + if (err_code != NULL) *err_code = error; @@ -9437,25 +9437,25 @@ FINISH_OFF: 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) { EM_DEBUG_FUNC_BEGIN("mail_id[%d], type[%d], attachment[%p], transaction[%d], err_code[%p]", mail_id, type, attachment, transaction, err_code); - + if (mail_id <= 0 || !attachment) { EM_DEBUG_EXCEPTION(" mail_id[%d], type[%d], attachment[%p]", mail_id, type, attachment); if (err_code != NULL) *err_code = EMAIL_ERROR_INVALID_PARAM; return false;; } - + int rc, ret = false; int error = EMAIL_ERROR_NONE; DB_STMT hStmt = NULL; char sql_query_string[QUERY_SIZE] = {0, }; - + int i = 0; - + sqlite3 *local_db_handle = emstorage_get_db_connection(); EMSTORAGE_START_WRITE_TRANSACTION(transaction, error); - + switch (type) { case UPDATE_MAILBOX: EM_DEBUG_LOG("UPDATE_MAILBOX"); @@ -9474,7 +9474,7 @@ INTERNAL_FUNC int emstorage_change_attachment_field(int mail_id, email_mail_chan _bind_stmt_field_data_int(hStmt, i++, attachment->mailbox_id); break; - + case UPDATE_SAVENAME: EM_DEBUG_LOG("UPDATE_SAVENAME"); if (!attachment->attachment_path) { @@ -9492,17 +9492,17 @@ INTERNAL_FUNC int emstorage_change_attachment_field(int mail_id, email_mail_chan " AND attachment_id = %d" , attachment->mail_id , attachment->attachment_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_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))); - + _bind_stmt_field_data_int(hStmt, i++, attachment->attachment_size); _bind_stmt_field_data_string(hStmt, i++, (char *)attachment->attachment_path, 0, ATTACHMENT_PATH_LEN_IN_MAIL_ATTACHMENT_TBL); break; - + default: EM_DEBUG_LOG("type[%d]", type); error = EMAIL_ERROR_INVALID_PARAM; @@ -9514,7 +9514,7 @@ INTERNAL_FUNC int emstorage_change_attachment_field(int mail_id, email_mail_chan 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 (hStmt != NULL) { EM_DEBUG_LOG(" Before sqlite3_finalize hStmt = %p", hStmt); @@ -9527,7 +9527,7 @@ FINISH_OFF: EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error); _DISCONNECT_DB; - + if (err_code != NULL) *err_code = error; EM_DEBUG_FUNC_END("ret [%d]", ret); @@ -9592,11 +9592,11 @@ INTERNAL_FUNC int emstorage_rename_mailbox(int input_mailbox_id, char *input_new 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 (sqlite3_changes(local_db_handle) == 0) + if (sqlite3_changes(local_db_handle) == 0) EM_DEBUG_LOG("no mail matched..."); ret = true; - + FINISH_OFF: EMSTORAGE_FINISH_WRITE_TRANSACTION(input_transaction, ret, error); @@ -9618,7 +9618,7 @@ FINISH_OFF: EM_DEBUG_FUNC_END("error [%d]", error); return error; } - + INTERNAL_FUNC int emstorage_get_new_attachment_no(int *attachment_no, int *err_code) { EM_DEBUG_FUNC_BEGIN("attachment_no [%p], err_code[%p]", attachment_no, err_code); @@ -9626,7 +9626,7 @@ INTERNAL_FUNC int emstorage_get_new_attachment_no(int *attachment_no, int *err_c int error = EMAIL_ERROR_NONE; char *sql = "SELECT max(rowid) FROM mail_attachment_tbl;"; char **result; - + if (!attachment_no) { EM_DEBUG_EXCEPTION("Invalid attachment"); error = EMAIL_ERROR_INVALID_PARAM; @@ -9634,7 +9634,7 @@ INTERNAL_FUNC int emstorage_get_new_attachment_no(int *attachment_no, int *err_c } *attachment_no = -1; - + sqlite3 *local_db_handle = emstorage_get_db_connection(); @@ -9644,7 +9644,7 @@ INTERNAL_FUNC int emstorage_get_new_attachment_no(int *attachment_no, int *err_c if (NULL == result[1]) rc = 1; - else + else rc = atoi(result[1])+1; sqlite3_free_table(result); @@ -9652,17 +9652,17 @@ INTERNAL_FUNC int emstorage_get_new_attachment_no(int *attachment_no, int *err_c *attachment_no = rc; EM_DEBUG_LOG("attachment_no [%d]", *attachment_no); ret = true; - + FINISH_OFF: _DISCONNECT_DB; - + if (err_code != NULL) *err_code = error; EM_DEBUG_FUNC_END("ret [%d]", ret); return ret; } - + INTERNAL_FUNC int emstorage_add_attachment(emstorage_attachment_tbl_t* attachment_tbl, int iscopy, int transaction, int *err_code) { EM_DEBUG_FUNC_BEGIN("attachment_tbl[%p], iscopy[%d], transaction[%d], err_code[%p]", attachment_tbl, iscopy, transaction, err_code); @@ -9674,16 +9674,16 @@ INTERNAL_FUNC int emstorage_add_attachment(emstorage_attachment_tbl_t* attachmen DB_STMT hStmt = NULL; char sql_query_string[QUERY_SIZE] = {0, }; sqlite3 *local_db_handle = emstorage_get_db_connection(); - + if (!attachment_tbl) { EM_DEBUG_EXCEPTION("attachment_tbl[%p], iscopy[%d]", attachment_tbl, iscopy); if (err_code != NULL) *err_code = EMAIL_ERROR_INVALID_PARAM; return false; } - + EMSTORAGE_START_WRITE_TRANSACTION(transaction, error); - + sql = "SELECT max(rowid) FROM mail_attachment_tbl;"; EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql, &result, NULL, NULL, NULL), rc); @@ -9695,7 +9695,7 @@ INTERNAL_FUNC int emstorage_add_attachment(emstorage_attachment_tbl_t* attachmen sqlite3_free_table(result); attachment_tbl->attachment_id = rc; - + SNPRINTF(sql_query_string, sizeof(sql_query_string), "INSERT INTO mail_attachment_tbl VALUES " "( ?" /* attachment_id */ @@ -9713,14 +9713,14 @@ INTERNAL_FUNC int emstorage_add_attachment(emstorage_attachment_tbl_t* attachmen #ifdef __ATTACHMENT_OPTI__ ", ?" ", ?" -#endif +#endif ")"); - - + + 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, 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); @@ -9737,7 +9737,7 @@ INTERNAL_FUNC int emstorage_add_attachment(emstorage_attachment_tbl_t* attachmen _bind_stmt_field_data_int(hStmt, ENCODING_IDX_IN_MAIL_ATTACHMENT_TBL, attachment_tbl->encoding); _bind_stmt_field_data_string(hStmt, SECTION_IDX_IN_MAIL_ATTACHMENT_TBL, (char*)attachment_tbl->section, 0, ATTACHMENT_LEN_IN_MAIL_ATTACHMENT_TBL); #endif - + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc); EM_DEBUG_DB_EXEC((SQLITE_FULL == rc), {error = EMAIL_ERROR_MAIL_MEMORY_FULL;goto FINISH_OFF; }, @@ -9747,7 +9747,7 @@ INTERNAL_FUNC int emstorage_add_attachment(emstorage_attachment_tbl_t* attachmen /* 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; }, @@ -9761,9 +9761,9 @@ INTERNAL_FUNC int emstorage_add_attachment(emstorage_attachment_tbl_t* attachmen error = EMAIL_ERROR_MAIL_NOT_FOUND; goto FINISH_OFF; } - + ret = true; - + FINISH_OFF: if (hStmt != NULL) { rc = sqlite3_finalize(hStmt); @@ -9775,7 +9775,7 @@ FINISH_OFF: EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error); _DISCONNECT_DB; - + if (err_code != NULL) *err_code = error; @@ -9786,7 +9786,7 @@ FINISH_OFF: INTERNAL_FUNC int emstorage_update_attachment(emstorage_attachment_tbl_t* attachment_tbl, int transaction, int *err_code) { EM_DEBUG_FUNC_BEGIN("attachment_tbl[%p], transaction[%d], err_code[%p]", attachment_tbl, transaction, err_code); - + int rc, ret = false, field_idx = 0; int error = EMAIL_ERROR_NONE; DB_STMT hStmt = NULL; @@ -9797,14 +9797,14 @@ INTERNAL_FUNC int emstorage_update_attachment(emstorage_attachment_tbl_t* attach error = EMAIL_ERROR_INVALID_PARAM; goto FINISH_OFF; } - + sqlite3 *local_db_handle = emstorage_get_db_connection(); EMSTORAGE_START_WRITE_TRANSACTION(transaction, error); - + SNPRINTF(sql_query_string, sizeof(sql_query_string), "UPDATE mail_attachment_tbl SET " - " attachment_name = ?" + " attachment_name = ?" ", attachment_path = ?" ", attachment_size = ?" ", mail_id = ?" @@ -9816,8 +9816,8 @@ INTERNAL_FUNC int emstorage_update_attachment(emstorage_attachment_tbl_t* attach ", attachment_inline_content_status = ? " ", attachment_mime_type = ? " " WHERE attachment_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; }, @@ -9835,17 +9835,17 @@ INTERNAL_FUNC int emstorage_update_attachment(emstorage_attachment_tbl_t* attach _bind_stmt_field_data_int (hStmt, field_idx++ , attachment_tbl->attachment_inline_content_status); _bind_stmt_field_data_string(hStmt, field_idx++ , (char*)attachment_tbl->attachment_mime_type, 0, ATTACHMENT_MIME_TYPE_LEN_IN_MAIL_ATTACHMENT_TBL); _bind_stmt_field_data_int (hStmt, field_idx++ , attachment_tbl->attachment_id); - + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc); EM_DEBUG_DB_EXEC((SQLITE_FULL == rc), {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)); -/* +/* 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; }, @@ -9859,9 +9859,9 @@ INTERNAL_FUNC int emstorage_update_attachment(emstorage_attachment_tbl_t* attach error = EMAIL_ERROR_MAIL_NOT_FOUND; goto FINISH_OFF; } - + ret = true; - + FINISH_OFF: if (hStmt != NULL) { rc = sqlite3_finalize(hStmt); @@ -9873,7 +9873,7 @@ FINISH_OFF: EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error); _DISCONNECT_DB; - + if (err_code != NULL) *err_code = error; @@ -9884,22 +9884,22 @@ FINISH_OFF: INTERNAL_FUNC int emstorage_delete_attachment_on_db(int attachment_id, int transaction, int *err_code) { EM_DEBUG_FUNC_BEGIN("attachment_id[%d], transaction[%d], err_code[%p]", attachment_id, transaction, err_code); - + if (attachment_id < 0) { EM_DEBUG_EXCEPTION("attachment_id[%d]", attachment_id); if (err_code != NULL) *err_code = EMAIL_ERROR_INVALID_PARAM; return false; } - + 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_attachment_tbl WHERE attachment_id = %d", attachment_id); EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc); @@ -9945,14 +9945,14 @@ INTERNAL_FUNC int emstorage_delete_all_attachments_of_mail(int mail_id, int tran ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); ret = true; - + FINISH_OFF: EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error); _DISCONNECT_DB; - + if (err_code) *err_code = error; - + EM_DEBUG_FUNC_END("ret [%d]", ret); return ret; } @@ -9960,33 +9960,33 @@ FINISH_OFF: INTERNAL_FUNC int emstorage_delete_attachment_all_on_db(int account_id, char *mailbox, int transaction, int *err_code) { EM_DEBUG_FUNC_BEGIN("account_id[%d], mailbox[%p], transaction[%d], err_code[%p]", account_id, mailbox, transaction, err_code); - + int error = EMAIL_ERROR_NONE; int rc, ret = false; 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"); - + if (account_id != ALL_ACCOUNT) /* '0' means all account */ SNPRINTF(sql_query_string + EM_SAFE_STRLEN(sql_query_string), sizeof(sql_query_string)-(EM_SAFE_STRLEN(sql_query_string)+1), " WHERE account_id = %d", account_id); if (mailbox) /* NULL means all 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'", account_id != ALL_ACCOUNT ? "AND" : "WHERE", mailbox); - + 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))); ret = true; - + FINISH_OFF: EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error); _DISCONNECT_DB; - + if (err_code != NULL) *err_code = error; @@ -9997,7 +9997,7 @@ FINISH_OFF: INTERNAL_FUNC int emstorage_free_attachment(emstorage_attachment_tbl_t** attachment_tbl_list, int count, int *err_code) { EM_DEBUG_FUNC_BEGIN("attachment_tbl_list[%p], count[%d], err_code[%p]", attachment_tbl_list, count, err_code); - + if (count > 0) { if ((attachment_tbl_list == NULL) || (*attachment_tbl_list == NULL)) { EM_DEBUG_EXCEPTION(" attachment_tbl_list[%p], count[%d]", attachment_tbl_list, count); @@ -10005,23 +10005,23 @@ INTERNAL_FUNC int emstorage_free_attachment(emstorage_attachment_tbl_t** attachm *err_code = EMAIL_ERROR_INVALID_PARAM; return false; } - + emstorage_attachment_tbl_t* p = *attachment_tbl_list; int i; - + 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].attachment_mime_type); #ifdef __ATTACHMENT_OPTI__ EM_SAFE_FREE(p[i].section); -#endif +#endif } - - EM_SAFE_FREE(p); + + EM_SAFE_FREE(p); *attachment_tbl_list = NULL; } - + if (err_code != NULL) *err_code = EMAIL_ERROR_NONE; EM_DEBUG_FUNC_END(); @@ -10036,7 +10036,7 @@ INTERNAL_FUNC int emstorage_begin_transaction(void *d1, void *d2, int *err_code) int ret = true; ENTER_CRITICAL_SECTION(_transactionBeginLock); - + /* wait for the trnasaction authority to be changed. */ while (g_transaction) { EM_DEBUG_LOG(">>>>>>>> Wait for the transaction authority to be changed"); @@ -10047,7 +10047,7 @@ INTERNAL_FUNC int emstorage_begin_transaction(void *d1, void *d2, int *err_code) g_transaction = true; LEAVE_CRITICAL_SECTION(_transactionBeginLock); - + 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); @@ -10111,11 +10111,11 @@ INTERNAL_FUNC int emstorage_rollback_transaction(void *d1, void *d2, int *err_co INTERNAL_FUNC int emstorage_is_mailbox_full(int account_id, email_mailbox_t *mailbox, int *result, int *err_code) { EM_DEBUG_FUNC_BEGIN("account_id[%d], mailbox[%p], result[%p], err_code[%p]", account_id, mailbox, result, err_code); - + if (account_id < FIRST_ACCOUNT_ID || !mailbox || !result) { if (mailbox) EM_DEBUG_EXCEPTION("Invalid Parameter. accoun_id[%d], mailbox[%p]", account_id, mailbox); - + if (err_code != NULL) *err_code = EMAIL_ERROR_INVALID_PARAM; @@ -10130,7 +10130,7 @@ INTERNAL_FUNC int emstorage_is_mailbox_full(int account_id, email_mailbox_t *mai EM_DEBUG_EXCEPTION("emstorage_get_mail_count failed [%d]", error); goto FINISH_OFF; } - + if (mailbox) { EM_DEBUG_LOG("mail_count[%d] mail_slot_size[%d]", mail_count, mailbox->mail_slot_size); if (mail_count >= mailbox->mail_slot_size) @@ -10140,13 +10140,13 @@ INTERNAL_FUNC int emstorage_is_mailbox_full(int account_id, email_mailbox_t *mai ret = true; } - - ret = true; + + ret = true; FINISH_OFF: if (err_code != NULL) *err_code = error; - + EM_DEBUG_FUNC_END("ret [%d]", ret); return ret; } @@ -10158,22 +10158,22 @@ INTERNAL_FUNC int emstorage_clear_mail_data(int transaction, int *err_code) int rc, 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); - + if (!emstorage_delete_dir(MAILHOME, &error)) { EM_DEBUG_EXCEPTION(" emstorage_delete_dir failed - %d", error); goto FINISH_OFF; } - + mkdir(MAILHOME, DIRECTORY_PERMISSION); mkdir(MAILTEMP, DIRECTORY_PERMISSION); - + /* first clear index. */ while (indexes->object_name) { if (indexes->data_flag) { @@ -10184,7 +10184,7 @@ INTERNAL_FUNC int emstorage_clear_mail_data(int transaction, int *err_code) } indexes++; } - + while (tables->object_name) { if (tables->data_flag) { SNPRINTF(sql_query_string, sizeof(sql_query_string), "DROP table %s", tables->object_name); @@ -10192,15 +10192,15 @@ INTERNAL_FUNC int emstorage_clear_mail_data(int transaction, int *err_code) 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))); } - + tables++; } ret = true; - + FINISH_OFF: EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error); _DISCONNECT_DB; - + if (err_code != NULL) *err_code = error; @@ -10232,14 +10232,14 @@ INTERNAL_FUNC int emstorage_get_save_name(int account_id, int mail_id, int atch_ { EM_DEBUG_FUNC_BEGIN("account_id[%d], mail_id[%d], atch_id[%d], fname[%s], name_buf[%p], err_code[%p]", account_id, mail_id, atch_id, fname, name_buf, err_code); EM_PROFILE_BEGIN(profile_emstorage_get_save_name); - + int ret = false; int error = EMAIL_ERROR_NONE; char *dir_name = NULL; char create_dir[1024]={0}; char *temp_file = NULL; - - if (!name_buf || account_id < FIRST_ACCOUNT_ID || mail_id < 0 || atch_id < 0) { + + if (!name_buf || account_id < FIRST_ACCOUNT_ID || mail_id < 0 || atch_id < 0) { EM_DEBUG_EXCEPTION(" account_id[%d], mail_id[%d], atch_id[%d], fname[%p], name_buf[%p]", account_id, mail_id, atch_id, fname, name_buf); error = EMAIL_ERROR_INVALID_PARAM; goto FINISH_OFF; @@ -10247,7 +10247,7 @@ INTERNAL_FUNC int emstorage_get_save_name(int account_id, int mail_id, int atch_ sprintf(name_buf, "%s", MAILHOME); sprintf(name_buf+EM_SAFE_STRLEN(name_buf), "%s%d", DIR_SEPERATOR, account_id); - + if (mail_id > 0) sprintf(name_buf+EM_SAFE_STRLEN(name_buf), "%s%d", DIR_SEPERATOR, mail_id); @@ -10268,17 +10268,17 @@ INTERNAL_FUNC int emstorage_get_save_name(int account_id, int mail_id, int atch_ EM_SAFE_FREE(temp_file); } - + if (fname) { EM_DEBUG_LOG(">>>>> fname [ %s ]", fname); sprintf(name_buf+EM_SAFE_STRLEN(name_buf), "%s%s", DIR_SEPERATOR, fname); } - + EM_DEBUG_LOG(">>>>> name_buf [ %s ]", name_buf); - + ret = true; - + FINISH_OFF: EM_SAFE_FREE(temp_file); @@ -10293,7 +10293,7 @@ FINISH_OFF: INTERNAL_FUNC int emstorage_get_dele_name(int account_id, int mail_id, int atch_id, char *fname, char *name_buf, int *err_code) { EM_DEBUG_FUNC_BEGIN("account_id[%d], mail_id[%d], atch_id[%d], fname[%p], name_buf[%p], err_code[%p]", account_id, mail_id, atch_id, fname, name_buf, err_code); - + if (!name_buf || account_id < FIRST_ACCOUNT_ID) { EM_DEBUG_EXCEPTION(" account_id[%d], mail_id[%d], atch_id[%d], fname[%p], name_buf[%p]", account_id, mail_id, atch_id, fname, name_buf); if (err_code != NULL) @@ -10302,12 +10302,12 @@ INTERNAL_FUNC int emstorage_get_dele_name(int account_id, int mail_id, int atch_ } sprintf(name_buf+EM_SAFE_STRLEN(name_buf), "%s%s%d", MAILHOME, DIR_SEPERATOR, account_id); - + if (mail_id > 0) sprintf(name_buf+EM_SAFE_STRLEN(name_buf), "%s%d", DIR_SEPERATOR, mail_id); else goto FINISH_OFF; - + if (atch_id > 0) sprintf(name_buf+EM_SAFE_STRLEN(name_buf), "%s%d", DIR_SEPERATOR, atch_id); else @@ -10326,12 +10326,12 @@ INTERNAL_FUNC int emstorage_create_dir(int account_id, int mail_id, int atch_id, EM_PROFILE_BEGIN(profile_emcore_save_create_dir); int ret = false; int error = EMAIL_ERROR_NONE; - + char buf[512]; struct stat sbuf; - if (account_id >= FIRST_ACCOUNT_ID) { + if (account_id >= FIRST_ACCOUNT_ID) { SNPRINTF(buf, sizeof(buf), "%s%s%d", MAILHOME, DIR_SEPERATOR, account_id); - + if (stat(buf, &sbuf) == 0) { if ((sbuf.st_mode & S_IFMT) != S_IFDIR) { EM_DEBUG_EXCEPTION(" a object which isn't directory aleady exists"); @@ -10357,11 +10357,11 @@ INTERNAL_FUNC int emstorage_create_dir(int account_id, int mail_id, int atch_id, } SNPRINTF(buf+EM_SAFE_STRLEN(buf), sizeof(buf), "%s%d", DIR_SEPERATOR, mail_id); - + if (stat(buf, &sbuf) == 0) { if ((sbuf.st_mode & S_IFMT) != S_IFDIR) { EM_DEBUG_EXCEPTION(" a object which isn't directory aleady exists"); - + error = EMAIL_ERROR_SYSTEM_FAILURE; goto FINISH_OFF; } @@ -10379,17 +10379,17 @@ INTERNAL_FUNC int emstorage_create_dir(int account_id, int mail_id, int atch_id, if (atch_id > 0) { if (account_id < FIRST_ACCOUNT_ID || mail_id <= 0) { EM_DEBUG_EXCEPTION(" account_id[%d], mail_id[%d], atch_id[%d]", account_id, mail_id, atch_id); - + error = EMAIL_ERROR_INVALID_PARAM; goto FINISH_OFF; } SNPRINTF(buf+EM_SAFE_STRLEN(buf), sizeof(buf)-(EM_SAFE_STRLEN(buf)+1), "%s%d", DIR_SEPERATOR, atch_id); - + if (stat(buf, &sbuf) == 0) { if ((sbuf.st_mode & S_IFMT) != S_IFDIR) { EM_DEBUG_EXCEPTION(" a object which isn't directory aleady exists"); - + error = EMAIL_ERROR_SYSTEM_FAILURE; goto FINISH_OFF; } @@ -10404,7 +10404,7 @@ INTERNAL_FUNC int emstorage_create_dir(int account_id, int mail_id, int atch_id, } ret = true; - + FINISH_OFF: if (err_code != NULL) *err_code = error; @@ -10428,21 +10428,21 @@ INTERNAL_FUNC int emstorage_copy_file(char *src_file, char *dst_file, int sync_s int nwritten = 0; char *buf = NULL; int buf_size = 0; - + if (!src_file || !dst_file) { EM_DEBUG_EXCEPTION("src_file[%p], dst_file[%p]", src_file, dst_file); - + error = EMAIL_ERROR_INVALID_PARAM; goto FINISH_OFF; } - + if (stat(src_file, &st_buf) < 0) { EM_DEBUG_EXCEPTION("stat(\"%s\") failed...", src_file); - + error = EMAIL_ERROR_SYSTEM_FAILURE; /* EMAIL_ERROR_INVALID_PATH; */ goto FINISH_OFF; } - + buf_size = st_buf.st_size; EM_DEBUG_LOG(">>>> File Size [ %d ]", buf_size); buf = (char *)calloc(1, buf_size+1); @@ -10457,17 +10457,17 @@ INTERNAL_FUNC int emstorage_copy_file(char *src_file, char *dst_file, int sync_s if ((fp_src = open(src_file, O_RDONLY))<0) { /*prevent 24474*/ EM_DEBUG_EXCEPTION(">>>> Source Fail open %s Failed [ %d ] - Error [ %s ]", src_file, errno, strerror(errno)); error = EMAIL_ERROR_SYSTEM_FAILURE; - goto FINISH_OFF; + goto FINISH_OFF; } if ((fp_dst = open(dst_file, O_CREAT | O_WRONLY, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH))<0) { /*prevent 24474*/ EM_DEBUG_EXCEPTION(">>>> Destination Fail open %s Failed [ %d ] - Error [ %s ]", dst_file, errno, strerror(errno)); error = EMAIL_ERROR_SYSTEM_FAILURE; - goto FINISH_OFF; + goto FINISH_OFF; } while ((nread = read(fp_src, buf, buf_size)) > 0) { - if (nread > 0 && nread <= buf_size) { + if (nread > 0 && nread <= buf_size) { EM_DEBUG_LOG("Nread Value [%d]", nread); if ((nwritten = write(fp_dst, buf, nread)) != nread) { EM_DEBUG_EXCEPTION("fwrite failed...[%d] : [%s]", errno, strerror(errno)); @@ -10480,22 +10480,22 @@ INTERNAL_FUNC int emstorage_copy_file(char *src_file, char *dst_file, int sync_s } ret = true; - + FINISH_OFF: if (fp_src>0) /*prevent 24474*/ - close(fp_src); - + close(fp_src); + 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); - + if (err_code != NULL) *err_code = error; EM_DEBUG_FUNC_END("ret [%d]", ret); @@ -10516,39 +10516,39 @@ INTERNAL_FUNC void emstorage_create_dir_if_delete() static int _get_temp_file_name(char **filename, int *err_code) { EM_DEBUG_FUNC_BEGIN("filename[%p], err_code[%p]", filename, err_code); - + int ret = false; int error = EMAIL_ERROR_NONE; - + if (filename == NULL) { EM_DEBUG_EXCEPTION(" filename[%p]", filename); error = EMAIL_ERROR_INVALID_PARAM; goto FINISH_OFF; } - + char tempname[512] = {0x00, }; struct timeval tv; - + gettimeofday(&tv, NULL); srand(tv.tv_usec); - + SNPRINTF(tempname, sizeof(tempname), "%s%c%d", MAILTEMP, '/', rand()); - + char *p = EM_SAFE_STRDUP(tempname); if (p == NULL) { EM_DEBUG_EXCEPTION(" strdup failed..."); error = EMAIL_ERROR_OUT_OF_MEMORY; goto FINISH_OFF; } - + *filename = p; - + ret = true; FINISH_OFF: if (err_code != NULL) *err_code = error; - + EM_DEBUG_FUNC_END("ret [%d]", ret); return ret; } @@ -10573,15 +10573,15 @@ 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; - + if (stat(file_path, &st_buf) < 0) { EM_DEBUG_EXCEPTION(" stat(\"%s\") failed...", file_path); - + error = EMAIL_ERROR_SYSTEM_FAILURE; /* EMAIL_ERROR_INVALID_PATH; */ goto FINISH_OFF; } @@ -10599,35 +10599,35 @@ INTERNAL_FUNC int emstorage_add_content_type(char *file_path, char *char_set, in if (!(fp_src = fopen(file_path, "rb"))) { EM_DEBUG_EXCEPTION(" 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) { + if (nread > 0 && nread <= buf_size) { EM_DEBUG_LOG(">>>> Nread Value [ %d ] ", nread); - + /** - * 1.Add check for whether content type is there. + * 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); - + strncat(low_char_set, " \" /></head>", strlen(" \" /></head>")); /*prevent 34359*/ - + EM_DEBUG_LOG(">>> CHARSET [ %s ] ", low_char_set); EM_DEBUG_LOG(">>>>emstorage_add_content_type 1 "); - + match_str = strstr(buf, CONTENT_TYPE_DATA); EM_DEBUG_LOG(">>>>emstorage_add_content_type 2 "); - + if (match_str == NULL) { EM_DEBUG_LOG(">>>>emstorage_add_content_type 3 "); if (fp_src !=NULL) { @@ -10657,7 +10657,7 @@ INTERNAL_FUNC int emstorage_add_content_type(char *file_path, char *char_set, in goto FINISH_OFF; } EM_DEBUG_LOG(">>>>>>> TEMP APPEND FILE PATH [ %s ] ", temp_file_name); - + /* Open the Temp file in Append mode */ if (!(fp_dest = fopen(temp_file_name, "ab"))) { EM_DEBUG_EXCEPTION(" fopen failed - %s", temp_file_name); @@ -10687,20 +10687,20 @@ INTERNAL_FUNC int emstorage_add_content_type(char *file_path, char *char_set, in goto FINISH_OFF; } } - + } else { EM_DEBUG_EXCEPTION(" Error Occured while writing New data : [%d ] bytes written ", nwritten); error = EMAIL_ERROR_SYSTEM_FAILURE; goto FINISH_OFF; } - + } - + } EM_DEBUG_LOG(">>>>emstorage_add_content_type 15 "); - + } } @@ -10715,7 +10715,7 @@ FINISH_OFF: fclose(fp_src); fp_src = NULL; } - + if (fp_dest != NULL) { fclose(fp_dest); fp_dest = NULL; @@ -10728,16 +10728,16 @@ FINISH_OFF: INTERNAL_FUNC int emstorage_move_file(char *src_file, char *dst_file, int sync_status, int *err_code) { EM_DEBUG_FUNC_BEGIN("src_file[%p], dst_file[%p], err_code[%p]", src_file, dst_file, err_code); - + int ret = false; int error = EMAIL_ERROR_NONE; - + if (src_file == NULL || dst_file == NULL) { EM_DEBUG_EXCEPTION("src_file[%p], dst_file[%p]", src_file, dst_file); error = EMAIL_ERROR_INVALID_PARAM; goto FINISH_OFF; } - + EM_DEBUG_LOG("src_file[%s], dst_file[%s]", src_file, dst_file); if (strcmp(src_file, dst_file) != 0) { @@ -10751,7 +10751,7 @@ INTERNAL_FUNC int emstorage_move_file(char *src_file, char *dst_file, int sync_s } remove(src_file); EM_DEBUG_LOG("src[%s] removed", src_file); - + } else { if (errno == ENOENT) { @@ -10764,7 +10764,7 @@ INTERNAL_FUNC int emstorage_move_file(char *src_file, char *dst_file, int sync_s EM_DEBUG_EXCEPTION("no file found [%d]", errno); error = EMAIL_ERROR_FILE_NOT_FOUND; goto FINISH_OFF; - + } else { EM_DEBUG_EXCEPTION("rename failed [%d]", errno); @@ -10777,7 +10777,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); } - + ret = true; FINISH_OFF: @@ -10791,33 +10791,33 @@ FINISH_OFF: INTERNAL_FUNC int emstorage_delete_file(char *src_file, int *err_code) { EM_DEBUG_FUNC_BEGIN("src_file[%p], err_code[%p]", src_file, err_code); - + int ret = false; int error = EMAIL_ERROR_NONE; - + if (src_file == NULL) { EM_DEBUG_EXCEPTION(" src_file[%p]", src_file); - + error = EMAIL_ERROR_INVALID_PARAM; goto FINISH_OFF; } - + if (remove(src_file) != 0) { if (errno != ENOENT) { EM_DEBUG_EXCEPTION(" remove failed - %d", errno); - + error = EMAIL_ERROR_SYSTEM_FAILURE; goto FINISH_OFF; } else { EM_DEBUG_EXCEPTION(" no file found..."); - + error = EMAIL_ERROR_FILE_NOT_FOUND; } } - + ret = true; - + FINISH_OFF: if (err_code != NULL) *err_code = error; @@ -10830,24 +10830,24 @@ FINISH_OFF: INTERNAL_FUNC int emstorage_delete_dir(char *src_dir, int *err_code) { EM_DEBUG_FUNC_BEGIN("src_dir[%p], err_code[%p]", src_dir, err_code); - + if (src_dir == NULL) { EM_DEBUG_EXCEPTION(" src_dir[%p]", src_dir); - + if (err_code != NULL) *err_code = EMAIL_ERROR_INVALID_PARAM; return false; } - + int error = EMAIL_ERROR_NONE; - + DIR *dirp; struct dirent *dp; struct stat sbuf; char buf[512]; - + dirp = opendir(src_dir); - + if (dirp == NULL) { if (errno == ENOENT) { EM_DEBUG_EXCEPTION("directory[%s] does not exist...", src_dir); @@ -10866,15 +10866,15 @@ INTERNAL_FUNC int emstorage_delete_dir(char *src_dir, int *err_code) while ((dp=readdir(dirp))) { if (strncmp(dp->d_name, ".", 1) == 0 || strncmp(dp->d_name, "..", 2) == 0) /* prevent 34360 */ continue; - + SNPRINTF(buf, sizeof(buf), "%s/%s", src_dir, dp->d_name); - + if (lstat(buf, &sbuf) == 0 || stat(buf, &sbuf) == 0) { /* check directory */ if ((sbuf.st_mode & S_IFMT) == S_IFDIR) { /* directory */ /* recursive call */ if (!emstorage_delete_dir(buf, &error)) { - closedir(dirp); + closedir(dirp); if (err_code != NULL) *err_code = error; return false; @@ -10890,26 +10890,26 @@ INTERNAL_FUNC int emstorage_delete_dir(char *src_dir, int *err_code) } } } - else + else EM_DEBUG_EXCEPTION("content does not exist..."); } - + closedir(dirp); - + EM_DEBUG_LOG("remove direcotory [%s]", src_dir); - + /* EM_DEBUG_FUNC_BEGIN(); */ - + if (remove(src_dir) < 0) { EM_DEBUG_EXCEPTION("remove failed [%s]", src_dir); if (err_code != NULL) *err_code = EMAIL_ERROR_SYSTEM_FAILURE; return false; } - + if (err_code != NULL) *err_code = error; - + return true; } @@ -10922,8 +10922,8 @@ INTERNAL_FUNC int emstorage_update_server_uid(char *old_server_uid, char *new_se char sql_query_string[QUERY_SIZE] = {0, }; int transaction = true; - - if (!old_server_uid || !new_server_uid) { + + if (!old_server_uid || !new_server_uid) { EM_DEBUG_EXCEPTION("Invalid parameters"); error = EMAIL_ERROR_INVALID_PARAM; return false; @@ -10931,7 +10931,7 @@ INTERNAL_FUNC int emstorage_update_server_uid(char *old_server_uid, char *new_se 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); @@ -10940,19 +10940,19 @@ INTERNAL_FUNC int emstorage_update_server_uid(char *old_server_uid, char *new_se ("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))); - + ret = true; - + FINISH_OFF: EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error); _DISCONNECT_DB; if (err_code != NULL) *err_code = error; - + EM_DEBUG_FUNC_END("ret [%d]", ret); return ret; - + } INTERNAL_FUNC int emstorage_update_read_mail_uid(int mail_id, char *new_server_uid, char *mbox_name, int *err_code) @@ -10964,8 +10964,8 @@ INTERNAL_FUNC int emstorage_update_read_mail_uid(int mail_id, char *new_server_u char sql_query_string[QUERY_SIZE] = {0, }; int transaction = true; - - if (!mail_id || !new_server_uid || !mbox_name) { + + if (!mail_id || !new_server_uid || !mbox_name) { EM_DEBUG_EXCEPTION("Invalid parameters"); error = EMAIL_ERROR_INVALID_PARAM; return false; @@ -10973,14 +10973,14 @@ INTERNAL_FUNC int emstorage_update_read_mail_uid(int mail_id, char *new_server_u 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 s_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))); ret = true; - + FINISH_OFF: EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error); @@ -10988,10 +10988,10 @@ FINISH_OFF: if (err_code != NULL) *err_code = error; - + EM_DEBUG_FUNC_END("ret [%d]", ret); return ret; - + } @@ -11004,7 +11004,7 @@ int emstorage_get_latest_unread_mailid(int account_id, int *mail_id, int *err_co if (err_code != NULL) *err_code = EMAIL_ERROR_INVALID_PARAM; return false; - } + } int ret = false; int rc = -1; @@ -11024,7 +11024,7 @@ int emstorage_get_latest_unread_mailid(int account_id, int *mail_id, int *err_co SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT mail_id FROM mail_tbl WHERE flags_seen_field = 0 ORDER BY mail_id DESC"); else SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT mail_id FROM mail_tbl WHERE account_id = %d AND flags_seen_field = 0 ORDER BY mail_id DESC", account_id); - + 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; }, @@ -11047,7 +11047,7 @@ int emstorage_get_latest_unread_mailid(int account_id, int *mail_id, int *err_co error= EMAIL_ERROR_MAIL_NOT_FOUND; goto FINISH_OFF; } - + _get_stmt_field_data_int(hStmt, &mailid, 0); EM_DEBUG_LOG("mailid [%d]", mailid); @@ -11060,7 +11060,7 @@ FINISH_OFF: rc = sqlite3_finalize(hStmt); if (rc != SQLITE_OK) { EM_DEBUG_EXCEPTION("sqlite3_finalize failed - %d", rc); - + error = EMAIL_ERROR_DB_FAILURE; } } @@ -11093,7 +11093,7 @@ int setting_system_command(const char *command) if (pid == 0) { char *argv[4]; - + argv[0] = "sh"; argv[1] = "-c"; argv[2] = (char *)command; @@ -11122,7 +11122,7 @@ INTERNAL_FUNC int emstorage_mail_get_total_diskspace_usage(unsigned long *total_ if (!total_usage) { EM_DEBUG_EXCEPTION("total_usage[%p]", total_usage); - + if (err_code != NULL) *err_code = EMAIL_ERROR_INVALID_PARAM; return false; @@ -11141,26 +11141,26 @@ INTERNAL_FUNC int emstorage_mail_get_total_diskspace_usage(unsigned long *total_ EM_DEBUG_EXCEPTION("emstorage_mail_get_total_diskspace_usage : [Setting > Memory] System Command [%s] is failed", syscmd); error = EMAIL_ERROR_SYSTEM_FAILURE; - goto FINISH_OFF; + goto FINISH_OFF; } SNPRINTF(syscmd, sizeof(syscmd), "du -hsk %s > %s", EMAILPATH, SETTING_MEMORY_TEMP_FILE_PATH); EM_DEBUG_LOG(" cmd : %s", syscmd); if (setting_system_command(syscmd) == -1) { EM_DEBUG_EXCEPTION("emstorage_mail_get_total_diskspace_usage : Setting > Memory] System Command [%s] is failed", syscmd); - + error = EMAIL_ERROR_SYSTEM_FAILURE; - goto FINISH_OFF; + goto FINISH_OFF; } fp = fopen(SETTING_MEMORY_TEMP_FILE_PATH, "r"); if (fp == NULL) { perror(SETTING_MEMORY_TEMP_FILE_PATH); - + error = EMAIL_ERROR_SYSTEM_FAILURE; - goto FINISH_OFF; + goto FINISH_OFF; } - + line_from_file = fgets(line, sizeof(line), fp); if(line_from_file == NULL) { @@ -11175,14 +11175,14 @@ INTERNAL_FUNC int emstorage_mail_get_total_diskspace_usage(unsigned long *total_ if (setting_system_command(syscmd) == -1) { EM_DEBUG_EXCEPTION("emstorage_mail_get_total_diskspace_usage : [Setting > Memory] System Command [%s] is failed", syscmd); error = EMAIL_ERROR_SYSTEM_FAILURE; - goto FINISH_OFF; + goto FINISH_OFF; } EM_DEBUG_LOG("[Setting > Memory] @@@@@ Size of Directory [%s] is %ld KB", EMAILPATH, total_diskusage); ret = true; -FINISH_OFF: +FINISH_OFF: if (err_code != NULL) *err_code = error; @@ -11260,8 +11260,8 @@ INTERNAL_FUNC int emstorage_test(int mail_id, int account_id, char *full_address sqlite3 *local_db_handle = emstorage_get_db_connection(); EMSTORAGE_START_WRITE_TRANSACTION(transaction, error); - - + + 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))); @@ -11329,10 +11329,10 @@ FINISH_OFF: error = EMAIL_ERROR_DB_FAILURE; } } - + EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error); _DISCONNECT_DB; - + if (err_code != NULL) *err_code = error; @@ -11376,7 +11376,7 @@ INTERNAL_FUNC int emstorage_get_thread_id_of_thread_mails(emstorage_mail_tbl_t * mailbox_name = mail_tbl->mailbox_name; subject = mail_tbl->subject; date_time = mail_tbl->date_time; - + EM_DEBUG_LOG("subject : %s", subject); if (em_find_pos_stripped_subject_for_thread_view(subject, stripped_subject, STRIPPED_SUBJECT_BUFFER_SIZE) != EMAIL_ERROR_NONE) { @@ -11390,9 +11390,9 @@ INTERNAL_FUNC int emstorage_get_thread_id_of_thread_mails(emstorage_mail_tbl_t * 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); @@ -11403,12 +11403,12 @@ INTERNAL_FUNC int emstorage_get_thread_id_of_thread_mails(emstorage_mail_tbl_t * } snprintf(sql_account, query_size_account, sql_format_account, account_id); } - + /* prevent 34362 */ query_size = strlen(sql_format) + strlen(stripped_subject) + 50 + query_size_account + strlen(sql_format_order_by); /* + query_size_mailbox; */ - + sql_query_string = malloc(query_size); - + if (sql_query_string == NULL) { EM_DEBUG_EXCEPTION("malloc for sql is failed %d", query_size); err_code = EMAIL_ERROR_OUT_OF_MEMORY; @@ -11441,7 +11441,7 @@ INTERNAL_FUNC int emstorage_get_thread_id_of_thread_mails(emstorage_mail_tbl_t * if (latest_date_time < mail_tbl->date_time) *result_latest_mail_id_in_thread = latest_mail_id_in_thread; - else + else *result_latest_mail_id_in_thread = mail_tbl->mail_id; EM_DEBUG_LOG("latest_mail_id_in_thread [%d], mail_id [%d]", latest_mail_id_in_thread, mail_tbl->mail_id); } @@ -11449,7 +11449,7 @@ INTERNAL_FUNC int emstorage_get_thread_id_of_thread_mails(emstorage_mail_tbl_t * 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); @@ -11458,9 +11458,9 @@ FINISH_OFF: EM_SAFE_FREE(sql_query_string); sqlite3_free_table(result); - + EM_PROFILE_END(profile_emstorage_get_thread_id_of_thread_mails); - + return err_code; } @@ -11468,7 +11468,7 @@ FINISH_OFF: INTERNAL_FUNC int emstorage_get_thread_information(int thread_id, emstorage_mail_tbl_t** mail_tbl, int transaction, int *err_code) { EM_DEBUG_FUNC_BEGIN(); - + int count = 0, ret = false; int error = EMAIL_ERROR_NONE; emstorage_mail_tbl_t *p_data_tbl = NULL; @@ -11486,15 +11486,15 @@ INTERNAL_FUNC int emstorage_get_thread_information(int thread_id, emstorage_mail if(p_data_tbl) EM_DEBUG_LOG("thread_id : %d, thread_item_count : %d", p_data_tbl[0].thread_id, p_data_tbl[0].thread_item_count); - + ret = true; - + FINISH_OFF: - if (ret == true) + if (ret == true) *mail_tbl = p_data_tbl; else if (p_data_tbl != NULL) emstorage_free_mail(&p_data_tbl, 1, NULL); - + if (err_code != NULL) *err_code = error; @@ -11507,7 +11507,7 @@ INTERNAL_FUNC int emstorage_get_sender_list(int account_id, const char *mailbox_ { EM_DEBUG_FUNC_BEGIN("account_id [%d], mailbox_name [%p], search_type [%d], search_value [%p], sorting [%d], sender_list[%p], sender_count[%p] err_code[%p]" , account_id , mailbox_name , search_type , search_value , sorting , sender_list, sender_count, err_code); - + if ((!sender_list) ||(!sender_count)) { EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM"); if (err_code != NULL) @@ -11553,7 +11553,7 @@ INTERNAL_FUNC int emstorage_get_sender_list(int account_id, const char *mailbox_ break; case EMAIL_SEARCH_FILTER_RECIPIENT: SNPRINTF(sql_query_string + EM_SAFE_STRLEN(sql_query_string), QUERY_SIZE-(EM_SAFE_STRLEN(sql_query_string)+1), - " AND ((UPPER(full_address_to) LIKE UPPER(\'%%%%%s%%%%\')) " + " AND ((UPPER(full_address_to) LIKE UPPER(\'%%%%%s%%%%\')) " " OR (UPPER(full_address_cc) LIKE UPPER(\'%%%%%s%%%%\')) " " OR (UPPER(full_address_bcc) LIKE UPPER(\'%%%%%s%%%%\')) " ") ", search_value, search_value, search_value); @@ -11579,13 +11579,13 @@ INTERNAL_FUNC int emstorage_get_sender_list(int account_id, const char *mailbox_ "ORDER BY UPPER(alias_sender) "); EM_DEBUG_LOG("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; }, ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); EM_DEBUG_LOG("Count of Sender [%d]", count); - + if (!(p_sender_list = (email_sender_list_t*)em_malloc(sizeof(email_sender_list_t) * count))) { EM_DEBUG_EXCEPTION("em_malloc failed..."); error = EMAIL_ERROR_OUT_OF_MEMORY; @@ -11594,7 +11594,7 @@ INTERNAL_FUNC int emstorage_get_sender_list(int account_id, const char *mailbox_ col_index = 4; - EM_DEBUG_LOG(">>>> DATA ASSIGN START >>"); + EM_DEBUG_LOG(">>>> DATA ASSIGN START >>"); for (i = 0; i < count; i++) { _get_table_field_data_string(result, &(p_sender_list[i].address), 1, col_index++); _get_table_field_data_string(result, &(p_sender_list[i].display_name), 1, col_index++); @@ -11608,16 +11608,16 @@ INTERNAL_FUNC int emstorage_get_sender_list(int account_id, const char *mailbox_ result = NULL; ret = true; - + FINISH_OFF: if (ret == true) { *sender_list = p_sender_list; *sender_count = count; EM_DEBUG_LOG(">>>> COUNT : %d >>", count); } - + _DISCONNECT_DB; - + if (err_code != NULL) *err_code = error; @@ -11630,26 +11630,26 @@ INTERNAL_FUNC int emstorage_free_sender_list(email_sender_list_t **sender_list, EM_DEBUG_FUNC_BEGIN("sender_list[%p], count[%d]", sender_list, count); int err = EMAIL_ERROR_NONE; - + if (count > 0) { if (!sender_list || !*sender_list) { EM_DEBUG_EXCEPTION("sender_list[%p], count[%d]", sender_list, count); err = EMAIL_ERROR_INVALID_PARAM; return err; } - + email_sender_list_t* p = *sender_list; int i = 0; - + for (; i < count; i++) { EM_SAFE_FREE(p[i].address); EM_SAFE_FREE(p[i].display_name); } - - EM_SAFE_FREE(p); + + EM_SAFE_FREE(p); *sender_list = NULL; - } - + } + return err; } @@ -11663,7 +11663,7 @@ INTERNAL_FUNC int emstorage_free_address_info_list(email_address_info_list_t **a GList *list = NULL; GList *node = NULL; int i = 0; - + if (!address_info_list || !*address_info_list) { EM_DEBUG_EXCEPTION("address_info_list[%p]", address_info_list); err = EMAIL_ERROR_INVALID_PARAM; @@ -11694,12 +11694,12 @@ INTERNAL_FUNC int emstorage_free_address_info_list(email_address_info_list_t **a EM_SAFE_FREE(p_address_info->address); EM_SAFE_FREE(p_address_info->display_name); EM_SAFE_FREE(node->data); - + node = g_list_next(node); } } - EM_SAFE_FREE(*address_info_list); + EM_SAFE_FREE(*address_info_list); *address_info_list = NULL; EM_DEBUG_FUNC_END("err [%d]", err); @@ -11761,14 +11761,14 @@ INTERNAL_FUNC int emstorage_add_pbd_activity(email_event_partial_body_thd* local 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))); 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); _bind_stmt_field_data_int(hStmt, i++, local_activity->server_mail_id); @@ -11784,7 +11784,7 @@ INTERNAL_FUNC int emstorage_add_pbd_activity(email_event_partial_body_thd* local ("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: @@ -11830,7 +11830,7 @@ INTERNAL_FUNC int emstorage_get_pbd_mailbox_list(int account_id, int **mailbox_l 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)); @@ -11851,15 +11851,15 @@ INTERNAL_FUNC int emstorage_get_pbd_mailbox_list(int account_id, int **mailbox_l goto FINISH_OFF; } EM_DEBUG_LOG("Mailbox count = %d", *count); - + memset(sql_query_string, 0x00, sizeof(sql_query_string)); /* SNPRINTF(g_sql_query, sizeof(g_sql_query), "SELECT distinct mailbox_name FROM mail_partial_body_activity_tbl WHERE account_id = %d order by activity_id", account_id); */ SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT distinct mailbox_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); - - + + 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); @@ -11870,7 +11870,7 @@ INTERNAL_FUNC int emstorage_get_pbd_mailbox_list(int account_id, int **mailbox_l 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 == (mbox_list = (int *)em_malloc(sizeof(int *) * (*count)))) { EM_DEBUG_EXCEPTION(" em_malloc failed..."); error = EMAIL_ERROR_OUT_OF_MEMORY; @@ -11878,7 +11878,7 @@ INTERNAL_FUNC int emstorage_get_pbd_mailbox_list(int account_id, int **mailbox_l } memset(mbox_list, 0x00, sizeof(int) * (*count)); - + for (i = 0; i < (*count); i++) { _get_stmt_field_data_int(hStmt, mbox_list + i, 0); EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc); @@ -11937,11 +11937,11 @@ INTERNAL_FUNC int emstorage_get_pbd_account_list(int **account_list, int *count, 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"; + 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); @@ -11959,14 +11959,14 @@ INTERNAL_FUNC int emstorage_get_pbd_account_list(int **account_list, int *count, } EM_DEBUG_LOG("Account count [%d]", *count); - + memset(sql_query_string, 0x00, sizeof(sql_query_string)); SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT distinct account_id FROM mail_partial_body_activity_tbl"); EM_DEBUG_LOG("Query [%s]", sql_query_string); - - + + 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); @@ -11977,7 +11977,7 @@ INTERNAL_FUNC int emstorage_get_pbd_account_list(int **account_list, int *count, 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; @@ -11985,7 +11985,7 @@ INTERNAL_FUNC int emstorage_get_pbd_account_list(int **account_list, int *count, } memset(result_account_list, 0x00, sizeof(int) * (*count)); - + for (i = 0; i < (*count); i++) { _get_stmt_field_data_int(hStmt, result_account_list + i, 0); @@ -12046,12 +12046,12 @@ INTERNAL_FUNC int emstorage_get_pbd_activity_data(int account_id, int input_mail 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_partial_body_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; }, @@ -12070,13 +12070,13 @@ INTERNAL_FUNC int emstorage_get_pbd_activity_data(int account_id, int input_mail goto FINISH_OFF; } EM_DEBUG_LOG("Activity Count = %d", *count); - + memset(sql_query_string, 0x00, sizeof(sql_query_string)); SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT * FROM mail_partial_body_activity_tbl WHERE account_id = %d AND mailbox_id = '%d' order by activity_id", account_id, input_mailbox_id); EM_DEBUG_LOG("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); @@ -12087,7 +12087,7 @@ INTERNAL_FUNC int emstorage_get_pbd_activity_data(int account_id, int input_mail 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_partial_body_thd*)em_malloc(sizeof(email_event_partial_body_thd) * (*count)))) { EM_DEBUG_EXCEPTION("Malloc failed"); @@ -12095,7 +12095,7 @@ INTERNAL_FUNC int emstorage_get_pbd_activity_data(int account_id, int input_mail goto FINISH_OFF; } memset(event_list, 0x00, sizeof(email_event_partial_body_thd) * (*count)); - + for (i=0; i < (*count); i++) { _get_stmt_field_data_int(hStmt, &(event_list[i].account_id), ACCOUNT_IDX_MAIL_PARTIAL_BODY_ACTIVITY_TBL); _get_stmt_field_data_int(hStmt, &(event_list[i].mail_id), MAIL_IDX_IN_MAIL_PARTIAL_BODY_ACTIVITY_TBL); @@ -12161,12 +12161,12 @@ 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); memset(sql_query_string, 0x00, sizeof(sql_query_string)); - + if (activity_id == 0) SNPRINTF(sql_query_string, sizeof(sql_query_string), "DELETE FROM mail_partial_body_activity_tbl WHERE account_id = %d AND mail_id = %d", account_id, mail_id); else @@ -12192,9 +12192,9 @@ INTERNAL_FUNC int emstorage_delete_pbd_activity(int account_id, int mail_id, int ret = true; FINISH_OFF: - + EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error); - + _DISCONNECT_DB; if (err_code != NULL) *err_code = error; @@ -12224,12 +12224,12 @@ INTERNAL_FUNC int emstorage_get_mailbox_pbd_activity_count(int account_id, int i 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_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); - + 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; }, @@ -12261,7 +12261,7 @@ FINISH_OFF: EMSTORAGE_FINISH_READ_TRANSACTION(transaction); _DISCONNECT_DB; - + if (err_code != NULL) *err_code = error; @@ -12290,12 +12290,12 @@ INTERNAL_FUNC int emstorage_get_pbd_activity_count(int *activity_count, int tran 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_partial_body_activity_tbl;"); EM_DEBUG_LOG(" 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; }, @@ -12350,7 +12350,7 @@ 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)); @@ -12364,7 +12364,7 @@ INTERNAL_FUNC int emstorage_delete_full_pbd_activity_data(int account_id, int tr 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 matching activities found in mail_partial_body_activity_tbl"); @@ -12376,7 +12376,7 @@ INTERNAL_FUNC int emstorage_delete_full_pbd_activity_data(int account_id, int tr ret = true; FINISH_OFF: - + EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error); _DISCONNECT_DB; if (err_code != NULL) @@ -12418,7 +12418,7 @@ INTERNAL_FUNC int emstorage_update_pbd_activity(char *old_server_uid, char *new_ ("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_EXCEPTION("No matching found in mail_partial_body_activity_tbl"); @@ -12443,41 +12443,41 @@ FINISH_OFF: INTERNAL_FUNC int emstorage_create_file(char *data_string, size_t file_size, char *dst_file_name, int *err_code) { EM_DEBUG_FUNC_BEGIN("file_size[%d] , dst_file_name[%s], err_code[%p]", file_size, dst_file_name, err_code); - + int ret = false; int error = EMAIL_ERROR_NONE; - + FILE* fp_dst = NULL; - - if (!data_string || !dst_file_name) { + + if (!data_string || !dst_file_name) { EM_DEBUG_EXCEPTION("data_string[%p], dst_file_name[%p]", data_string, dst_file_name); error = EMAIL_ERROR_INVALID_PARAM; goto FINISH_OFF; } fp_dst = fopen(dst_file_name, "w"); - + if (!fp_dst) { EM_DEBUG_EXCEPTION("fopen failed - %s", dst_file_name); if (errno == 28) error = EMAIL_ERROR_MAIL_MEMORY_FULL; else error = EMAIL_ERROR_SYSTEM_FAILURE; - goto FINISH_OFF; + goto FINISH_OFF; } - + if (fwrite(data_string, 1, file_size, fp_dst) == 0) { EM_DEBUG_EXCEPTION("fwrite failed..."); error = EMAIL_ERROR_UNKNOWN; goto FINISH_OFF; } - + ret = true; - + FINISH_OFF: - + if (fp_dst != NULL) - fclose(fp_dst); + fclose(fp_dst); if (err_code != NULL) *err_code = error; @@ -12495,37 +12495,37 @@ FINISH_OFF: INTERNAL_FUNC int emstorage_update_read_mail_uid_by_server_uid(char *old_server_uid, char *new_server_uid, char *mbox_name, int *err_code) { EM_DEBUG_FUNC_BEGIN(); - int rc = -1; + int rc = -1; 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 || !mbox_name) { + + if (!old_server_uid || !new_server_uid || !mbox_name) { EM_DEBUG_EXCEPTION("Invalid parameters"); error = EMAIL_ERROR_INVALID_PARAM; return false; } EM_DEBUG_LOG("old_server_uid[%s], new_server_uid[%s], mbox_name[%s]", old_server_uid, new_server_uid, mbox_name); - + sqlite3 *local_db_handle = 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 s_uid=\'%s\' , mailbox_id=\'%s\', mailbox_name=\'%s\' WHERE s_uid=%s ", new_server_uid, mbox_name, mbox_name, old_server_uid); EM_DEBUG_LOG(" Query [%s]", sql_query_string); - + 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))); - - + + rc = sqlite3_changes(local_db_handle); if (rc == 0) { @@ -12534,20 +12534,20 @@ INTERNAL_FUNC int emstorage_update_read_mail_uid_by_server_uid(char *old_server_ goto FINISH_OFF; } - + ret = true; - + FINISH_OFF: - + EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error); _DISCONNECT_DB; if (err_code != NULL) *err_code = error; - + EM_DEBUG_FUNC_END("ret [%d]", ret); return ret; - + } @@ -12565,7 +12565,7 @@ FINISH_OFF: * SELECT local_uid, s_uid from mail_read_mail_uid_tbl where local_uid in (12, 13, 56, 78); * @return This function returns true on success or false on failure. */ - + INTERNAL_FUNC int emstorage_get_id_set_from_mail_ids(char *mail_ids, email_id_set_t** idset, int *id_set_count, int *err_code) { EM_DEBUG_FUNC_BEGIN(); @@ -12583,8 +12583,8 @@ INTERNAL_FUNC int emstorage_get_id_set_from_mail_ids(char *mail_ids, email_id_se char *server_mail_id = NULL; char **result = NULL; int col_index = 0; - - + + if (NULL == mail_ids || NULL == idset || NULL == id_set_count) { EM_DEBUG_EXCEPTION("Invalid Parameters mail_ids[%p] idset[%p] id_set_count [%p]", mail_ids, idset, id_set_count); error = EMAIL_ERROR_INVALID_PARAM; @@ -12596,7 +12596,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, s_uid FROM mail_read_mail_uid_tbl WHERE local_uid in (%s) ORDER BY s_uid", mail_ids); EM_DEBUG_LOG("SQL Query formed [%s] ", sql_query_string); - + /* rc = sqlite3_get_table(local_db_handle, sql_query_string, &result, &count, 0, NULL); */ 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; }, @@ -12620,12 +12620,12 @@ INTERNAL_FUNC int emstorage_get_id_set_from_mail_ids(char *mail_ids, email_id_se col_index = 2; EM_PROFILE_BEGIN(EmStorageGetIdSetFromMailIds_Loop); - EM_DEBUG_LOG(">>>> DATA ASSIGN START"); + EM_DEBUG_LOG(">>>> DATA ASSIGN START"); for (i = 0; i < count; i++) { _get_table_field_data_int(result, &(p_id_set[i].mail_id), col_index++); _get_table_field_data_string(result, &server_mail_id, 1, col_index++); p_id_set[i].server_mail_id = strtoul(server_mail_id, NULL, 10); - EM_SAFE_FREE(server_mail_id); + EM_SAFE_FREE(server_mail_id); } EM_DEBUG_LOG(">>>> DATA ASSIGN END [count : %d]", count); EM_PROFILE_END(EmStorageGetIdSetFromMailIds_Loop); @@ -12642,11 +12642,11 @@ INTERNAL_FUNC int emstorage_get_id_set_from_mail_ids(char *mail_ids, email_id_se *id_set_count = count; EM_DEBUG_LOG(" idset[%p] id_set_count [%d]", *idset, *id_set_count); } - else + else EM_SAFE_FREE(p_id_set); - + _DISCONNECT_DB; - + if (err_code != NULL) *err_code = error; @@ -12666,31 +12666,31 @@ INTERNAL_FUNC int emstorage_delete_triggers_from_lucene() int rc, 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))); 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))); - + 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))); - + ret = true; - + FINISH_OFF: EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error); @@ -12704,10 +12704,10 @@ FINISH_OFF: INTERNAL_FUNC int emstorage_filter_mails_by_rule(int account_id, int dest_mailbox_id, emstorage_rule_tbl_t *rule, int ** filtered_mail_id_list, int *count_of_mails, int *err_code) { EM_DEBUG_FUNC_BEGIN("account_id[%d], dest_mailbox_id[%d] rule[%p], filtered_mail_id_list[%p], count_of_mails[%p], err_code[%p]", account_id, dest_mailbox_id, rule, filtered_mail_id_list, count_of_mails, err_code); - + if ((account_id <= 0) || (dest_mailbox_id <= 0) || (!rule) || (!rule->value)|| (!filtered_mail_id_list) || (!count_of_mails)) { EM_DEBUG_EXCEPTION("Invalid Parameter"); - + if (err_code != NULL) *err_code = EMAIL_ERROR_INVALID_PARAM; return false; @@ -12717,11 +12717,11 @@ INTERNAL_FUNC int emstorage_filter_mails_by_rule(int account_id, int dest_mailbo int count = 0, col_index = 0, i = 0, where_pararaph_length = 0, *mail_list = NULL; char **result = NULL, *where_pararaph = NULL; char sql_query_string[QUERY_SIZE] = {0, }; - + sqlite3 *local_db_handle = emstorage_get_db_connection(); SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT mail_id FROM mail_tbl "); - + EM_DEBUG_LOG("rule->value [%s]", rule->value); where_pararaph_length = EM_SAFE_STRLEN(rule->value) + 100; @@ -12734,7 +12734,7 @@ INTERNAL_FUNC int emstorage_filter_mails_by_rule(int account_id, int dest_mailbo } memset(where_pararaph, 0, sizeof(char) * where_pararaph_length); - + EM_DEBUG_LOG("rule->type [%d], rule->flag2[%d]", rule->type, rule->flag2); if (rule->type == EMAIL_FILTER_FROM) { @@ -12754,13 +12754,13 @@ INTERNAL_FUNC int emstorage_filter_mails_by_rule(int account_id, int dest_mailbo EM_DEBUG_EXCEPTION("rule->type is invald"); goto FINISH_OFF; } - + /* prevent 34361 */ if (strlen(sql_query_string) + strlen(where_pararaph) < QUERY_SIZE) strcat(sql_query_string, where_pararaph); EM_DEBUG_LOG("query[%s]", sql_query_string); - + /* rc = sqlite3_get_table(local_db_handle, sql_query_string, &result, &count, 0, NULL); */ 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; }, @@ -12775,10 +12775,10 @@ INTERNAL_FUNC int emstorage_filter_mails_by_rule(int account_id, int dest_mailbo error = EMAIL_ERROR_OUT_OF_MEMORY; goto FINISH_OFF; } - + col_index = 1; - for (i = 0; i < count; i++) + for (i = 0; i < count; i++) _get_table_field_data_int(result, &(mail_list[i]), col_index++); SNPRINTF(sql_query_string, sizeof(sql_query_string), "UPDATE mail_tbl SET mailbox_id = %d, mailbox_type = 5 ", dest_mailbox_id); @@ -12791,7 +12791,7 @@ INTERNAL_FUNC int emstorage_filter_mails_by_rule(int account_id, int dest_mailbo 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))); } - + ret = true; FINISH_OFF: @@ -12872,7 +12872,7 @@ INTERNAL_FUNC int emstorage_set_mail_slot_size(int account_id, int mailbox_id, i else { EM_DEBUG_EXCEPTION("Query buffer overflowed !!!"); err = EMAIL_ERROR_OUT_OF_MEMORY; - goto FINISH_OFF; + goto FINISH_OFF; } EM_DEBUG_LOG("query[%s]", sql_query_string); @@ -12880,9 +12880,9 @@ INTERNAL_FUNC int emstorage_set_mail_slot_size(int account_id, int mailbox_id, i 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))); - + ret = true; - + FINISH_OFF: EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, err); @@ -12901,17 +12901,17 @@ FINISH_OFF: INTERNAL_FUNC int emstorage_add_meeting_request(int account_id, int input_mailbox_id, email_meeting_request_t* meeting_req, int transaction, int *err_code) { EM_DEBUG_FUNC_BEGIN("account_id[%d], input_mailbox_id[%d], meeting_req[%p], transaction[%d], err_code[%p]", account_id, input_mailbox_id, meeting_req, transaction, err_code); - + if (!meeting_req || meeting_req->mail_id <= 0) { if (meeting_req) EM_DEBUG_EXCEPTION("mail_id[%]d", meeting_req->mail_id); - + if (err_code != NULL) *err_code = EMAIL_ERROR_INVALID_PARAM; return false; } - + int rc = -1; int ret = false; int error = EMAIL_ERROR_NONE; @@ -12919,10 +12919,10 @@ INTERNAL_FUNC int emstorage_add_meeting_request(int account_id, int input_mailbo char sql_query_string[QUERY_SIZE] = {0, }; int col_index = 0; time_t temp_unix_time = 0; - + sqlite3 *local_db_handle = emstorage_get_db_connection(); EMSTORAGE_START_WRITE_TRANSACTION(transaction, error); - + SNPRINTF(sql_query_string, sizeof(sql_query_string), "INSERT INTO mail_meeting_tbl VALUES " "( ?" /* mail_id */ @@ -12941,12 +12941,12 @@ INTERNAL_FUNC int emstorage_add_meeting_request(int account_id, int input_mailbo ", ?" /* daylight_time_start_date */ ", ?" /* daylight_bias */ " )"); - + 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_LOG(" before sqlite3_prepare hStmt = %p", hStmt); EM_DEBUG_EXCEPTION("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)); - + error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; } @@ -12981,7 +12981,7 @@ INTERNAL_FUNC int emstorage_add_meeting_request(int account_id, int input_mailbo _bind_stmt_field_data_string(hStmt, col_index++, (char *)meeting_req->location, 0, LOCATION_LEN_IN_MAIL_MEETING_TBL); _bind_stmt_field_data_string(hStmt, col_index++, (char *)meeting_req->global_object_id, 0, GLOBAL_OBJECT_ID_LEN_IN_MAIL_MEETING_TBL); - + _bind_stmt_field_data_int(hStmt, col_index++, meeting_req->time_zone.offset_from_GMT); _bind_stmt_field_data_string(hStmt, col_index++, (char *)meeting_req->time_zone.standard_name, 0, STANDARD_NAME_LEN_IN_MAIL_MEETING_TBL); temp_unix_time = timegm(&(meeting_req->time_zone.standard_time_start_date)); @@ -12999,9 +12999,9 @@ INTERNAL_FUNC int emstorage_add_meeting_request(int account_id, int input_mailbo ("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)); - + ret = true; - + FINISH_OFF: if (hStmt != NULL) { EM_DEBUG_LOG("before sqlite3_finalize hStmt = %p", hStmt); @@ -13012,10 +13012,10 @@ FINISH_OFF: error = EMAIL_ERROR_DB_FAILURE; } } - + EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error); _DISCONNECT_DB; - + if (err_code != NULL) *err_code = error; @@ -13026,7 +13026,7 @@ FINISH_OFF: INTERNAL_FUNC int emstorage_get_meeting_request(int mail_id, email_meeting_request_t ** meeting_req, int transaction, int *err_code) { EM_DEBUG_FUNC_BEGIN(); - + int count = 0; int rc = -1; int ret = false; @@ -13049,7 +13049,7 @@ INTERNAL_FUNC int emstorage_get_meeting_request(int mail_id, email_meeting_reque " WHERE mail_id = %d", mail_id); EM_DEBUG_LOG("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; }, @@ -13059,7 +13059,7 @@ INTERNAL_FUNC int emstorage_get_meeting_request(int mail_id, email_meeting_reque 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)); - + if (rc == SQLITE_DONE) { EM_DEBUG_EXCEPTION(" no Meeting request found..."); count = 0; @@ -13067,7 +13067,7 @@ INTERNAL_FUNC int emstorage_get_meeting_request(int mail_id, email_meeting_reque error= EMAIL_ERROR_DATA_NOT_FOUND; goto FINISH_OFF; } - + if (!(p_temp_meeting_req = (email_meeting_request_t*)malloc(sizeof(email_meeting_request_t)))) { EM_DEBUG_EXCEPTION(" malloc failed..."); error = EMAIL_ERROR_OUT_OF_MEMORY; @@ -13075,7 +13075,7 @@ INTERNAL_FUNC int emstorage_get_meeting_request(int mail_id, email_meeting_reque } memset(p_temp_meeting_req, 0x00, sizeof(email_meeting_request_t)); - + col_index = 0; _get_stmt_field_data_int(hStmt, &(p_temp_meeting_req->mail_id), col_index++); @@ -13114,14 +13114,14 @@ INTERNAL_FUNC int emstorage_get_meeting_request(int mail_id, email_meeting_reque EM_DEBUG_LOG(">>>>> meeting_req->time_zone.daylight_bias[%d]", p_temp_meeting_req->time_zone.daylight_bias); */ ret = true; - + FINISH_OFF: - if (ret == true) + if (ret == true) *meeting_req = p_temp_meeting_req; - else { + else { EM_SAFE_FREE(p_temp_meeting_req); } - + if (hStmt != NULL) { EM_DEBUG_LOG("before sqlite3_finalize hStmt = %p", hStmt); @@ -13135,7 +13135,7 @@ FINISH_OFF: EMSTORAGE_FINISH_READ_TRANSACTION(transaction); _DISCONNECT_DB; - + if (err_code != NULL) *err_code = error; @@ -13147,7 +13147,7 @@ FINISH_OFF: INTERNAL_FUNC int emstorage_update_meeting_request(email_meeting_request_t* meeting_req, int transaction, int *err_code) { EM_DEBUG_FUNC_BEGIN("meeting_req[%p], transaction[%d], err_code[%p]", meeting_req, transaction, err_code); - + int ret = false; int error = EMAIL_ERROR_NONE; int rc; @@ -13160,7 +13160,7 @@ INTERNAL_FUNC int emstorage_update_meeting_request(email_meeting_request_t* meet error = EMAIL_ERROR_INVALID_PARAM; goto FINISH_OFF; } - + sqlite3 *local_db_handle = emstorage_get_db_connection(); EMSTORAGE_START_WRITE_TRANSACTION(transaction, error); @@ -13183,10 +13183,10 @@ INTERNAL_FUNC int emstorage_update_meeting_request(email_meeting_request_t* meet " daylight_time_start_date = ?, " " daylight_bias = ? " "WHERE mail_id = %d", - meeting_req->mail_id); - + meeting_req->mail_id); + EM_DEBUG_LOG("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; }, ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); @@ -13233,7 +13233,7 @@ INTERNAL_FUNC int emstorage_update_meeting_request(email_meeting_request_t* meet FINISH_OFF: EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error); - + if (hStmt != NULL) { EM_DEBUG_LOG("before sqlite3_finalize hStmt = %p", hStmt); @@ -13246,62 +13246,62 @@ FINISH_OFF: } _DISCONNECT_DB; - + if (err_code != NULL) *err_code = error; EM_DEBUG_FUNC_END("ret [%d]", ret); - return ret; + return ret; } INTERNAL_FUNC int emstorage_delete_meeting_request(int account_id, int mail_id, int input_mailbox_id, int transaction, int *err_code) { EM_DEBUG_FUNC_BEGIN("account_id[%d], mail_id[%d], input_mailbox_id[%d], transaction[%d], err_code[%p]", account_id, mail_id, input_mailbox_id, transaction, err_code); - + if (account_id < ALL_ACCOUNT || mail_id < 0) { EM_DEBUG_EXCEPTION(" account_id[%d], mail_id[%d]", account_id, mail_id); - + if (err_code != NULL) *err_code = EMAIL_ERROR_INVALID_PARAM; return false; } - + int rc; int ret = false; int error = EMAIL_ERROR_NONE; int and = false; 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_meeting_tbl "); if (account_id != ALL_ACCOUNT) { /* NOT '0' means a specific account. '0' means all account */ SNPRINTF(sql_query_string + EM_SAFE_STRLEN(sql_query_string), sizeof(sql_query_string)-(EM_SAFE_STRLEN(sql_query_string)+1), " WHERE account_id = %d", account_id); and = true; } - if (mail_id > 0) { + if (mail_id > 0) { SNPRINTF(sql_query_string + EM_SAFE_STRLEN(sql_query_string), sizeof(sql_query_string)-(EM_SAFE_STRLEN(sql_query_string)+1), " %s mail_id = %d", (and ? "AND" : "WHERE"), mail_id); and = true; } if (input_mailbox_id > 0) { /* 0 means all 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"), 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))); - ret = true; - + ret = true; + FINISH_OFF: EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error); _DISCONNECT_DB; - + if (err_code) *err_code = error; - + EM_DEBUG_FUNC_END("ret [%d]", ret); return ret; } @@ -13310,12 +13310,12 @@ FINISH_OFF: INTERNAL_FUNC void emstorage_free_meeting_request(email_meeting_request_t *meeting_req) { EM_DEBUG_FUNC_BEGIN(); - + if (!meeting_req ) { EM_DEBUG_EXCEPTION("NULL PARAM"); return; } - + EM_SAFE_FREE(meeting_req->location); EM_SAFE_FREE(meeting_req->global_object_id); @@ -13340,27 +13340,27 @@ INTERNAL_FUNC int emstorage_get_overflowed_mail_id_list(int account_id, int inpu error = EMAIL_ERROR_INVALID_PARAM; goto FINISH_OFF; } - + SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT mail_id FROM mail_tbl WHERE account_id = %d AND mailbox_id = %d ORDER BY date_time DESC LIMIT %d, 10000", account_id, input_mailbox_id, mail_slot_size); - + EM_DEBUG_LOG("query[%s].", sql_query_string); sqlite3 *local_db_handle = emstorage_get_db_connection(); EMSTORAGE_START_READ_TRANSACTION(transaction); - + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, &result_mail_id_count, 0, NULL), rc); EM_DEBUG_DB_EXEC((SQLITE_OK != rc && -1 != 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))); if (!result_mail_id_count) { - EM_DEBUG_LOG("No mail found..."); + EM_DEBUG_LOG("No mail found..."); ret = false; error= EMAIL_ERROR_MAIL_NOT_FOUND; goto FINISH_OFF; } - + EM_DEBUG_LOG("There are [%d] overflowed mails in mailbox_id [%d]", result_mail_id_count, input_mailbox_id); - + if (!(result_mail_id_list = (int *)malloc(sizeof(int) * result_mail_id_count))) { EM_DEBUG_EXCEPTION("malloc for result_mail_id_list failed..."); error = EMAIL_ERROR_OUT_OF_MEMORY; @@ -13372,11 +13372,11 @@ INTERNAL_FUNC int emstorage_get_overflowed_mail_id_list(int account_id, int inpu col_index = 1; - for (counter = 0; counter < result_mail_id_count; counter++) + for (counter = 0; counter < result_mail_id_count; counter++) _get_table_field_data_int(result, result_mail_id_list + counter, col_index++); ret = true; - + FINISH_OFF: EM_DEBUG_LOG("finish off [%d]", ret); @@ -13387,12 +13387,12 @@ FINISH_OFF: *mail_id_list = result_mail_id_list; *mail_id_count = result_mail_id_count; } - else + else EM_SAFE_FREE(result_mail_id_list); - + EMSTORAGE_FINISH_READ_TRANSACTION(transaction); _DISCONNECT_DB; - + if (err_code != NULL) *err_code = error; @@ -13405,7 +13405,7 @@ FINISH_OFF: INTERNAL_FUNC int emstorage_get_thread_id_by_mail_id(int mail_id, int *thread_id, int *err_code) { EM_DEBUG_FUNC_BEGIN("mail_id[%d], thread_id[%p], err_code[%p]", mail_id, thread_id, err_code); - + int rc = -1, ret = false; int err = EMAIL_ERROR_NONE; char sql_query_string[QUERY_SIZE] = {0, }; @@ -13430,7 +13430,7 @@ INTERNAL_FUNC int emstorage_get_thread_id_by_mail_id(int mail_id, int *thread_id ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); if (!result_count) { - EM_DEBUG_EXCEPTION("No mail found..."); + EM_DEBUG_EXCEPTION("No mail found..."); ret = false; err= EMAIL_ERROR_MAIL_NOT_FOUND; /* sqlite3_free_table(result); */ @@ -13440,9 +13440,9 @@ INTERNAL_FUNC int emstorage_get_thread_id_by_mail_id(int mail_id, int *thread_id _get_table_field_data_int(result, thread_id, 1); sqlite3_free_table(result); - + ret = true; - + FINISH_OFF: _DISCONNECT_DB; @@ -13458,7 +13458,7 @@ FINISH_OFF: 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) { 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); - + int rc = -1, ret = false; int err = EMAIL_ERROR_NONE; char sql_query_string[QUERY_SIZE] = {0, }; @@ -13471,7 +13471,7 @@ INTERNAL_FUNC int emstorage_update_latest_thread_mail(int account_id, int thread *err_code = EMAIL_ERROR_INVALID_PARAM; goto FINISH_OFF; } - + sqlite3 *local_db_handle = emstorage_get_db_connection(); if (thread_item_count == 0 || latest_mail_id == 0) { @@ -13484,7 +13484,7 @@ INTERNAL_FUNC int emstorage_update_latest_thread_mail(int account_id, int thread ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); EM_DEBUG_LOG("result_count[%d]", result_count); if (result_count == 0) { - EM_DEBUG_EXCEPTION("No mail found..."); + EM_DEBUG_EXCEPTION("No mail found..."); ret = false; err= EMAIL_ERROR_MAIL_NOT_FOUND; sqlite3_free_table(result); @@ -13520,15 +13520,15 @@ INTERNAL_FUNC int emstorage_update_latest_thread_mail(int account_id, int thread 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))); - + ret = true; - + FINISH_OFF: - + EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, err); - + _DISCONNECT_DB; - + if (err_code != NULL) *err_code = err; @@ -13550,7 +13550,7 @@ INTERNAL_FUNC void emstorage_flush_db_cache() INTERNAL_FUNC int emstorage_add_activity(emstorage_activity_tbl_t* local_activity, int transaction, int *err_code) { EM_DEBUG_FUNC_BEGIN(); - + EM_DEBUG_LOG(" local_activity[%p], transaction[%d], err_code[%p]", local_activity, transaction, err_code); int rc = -1, ret = false; @@ -13558,7 +13558,7 @@ INTERNAL_FUNC int emstorage_add_activity(emstorage_activity_tbl_t* local_activit DB_STMT hStmt = NULL; char sql_query_string[8192] = { 0x00, }; int i = 0; - + if (!local_activity) { EM_DEBUG_EXCEPTION(" local_activity[%p], transaction[%d], err_code[%p]", local_activity, transaction, err_code); if (err_code != NULL) @@ -13569,7 +13569,7 @@ INTERNAL_FUNC int emstorage_add_activity(emstorage_activity_tbl_t* local_activit sqlite3 *local_db_handle = emstorage_get_db_connection(); memset(sql_query_string, 0x00 , sizeof(sql_query_string)); EMSTORAGE_START_WRITE_TRANSACTION(transaction, error); - + SNPRINTF(sql_query_string, sizeof(sql_query_string), "INSERT INTO mail_local_activity_tbl VALUES (?, ?, ?, ?, ?, ?, ?)"); EM_DEBUG_LOG(">>>>> ACTIVITY ID [ %d ] ", local_activity->activity_id); @@ -13581,8 +13581,8 @@ INTERNAL_FUNC int emstorage_add_activity(emstorage_activity_tbl_t* local_activit EM_DEBUG_LOG(">>>>> DEST MAILBOX [ %s ] ", local_activity->dest_mbox); EM_DEBUG_LOG(">>>> 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))); @@ -13599,7 +13599,7 @@ INTERNAL_FUNC int emstorage_add_activity(emstorage_activity_tbl_t* local_activit _bind_stmt_field_data_string(hStmt, i++ , (char *)local_activity->server_mailid, 0, SERVER_MAIL_ID_LEN_IN_MAIL_TBL); _bind_stmt_field_data_string(hStmt, i++ , (char *)local_activity->src_mbox, 0, MAILBOX_NAME_LEN_IN_MAIL_BOX_TBL); _bind_stmt_field_data_string(hStmt, i++ , (char *)local_activity->dest_mbox, 0, MAILBOX_NAME_LEN_IN_MAIL_BOX_TBL); - + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc); @@ -13609,16 +13609,16 @@ INTERNAL_FUNC int emstorage_add_activity(emstorage_activity_tbl_t* local_activit ("sqlite3_step fail:%d, errmsg = %s.", rc, sqlite3_errmsg(local_db_handle))); ret = true; - + FINISH_OFF: - + if (hStmt != NULL) { rc = sqlite3_finalize(hStmt); if (rc != SQLITE_OK) { EM_DEBUG_LOG(" sqlite3_finalize failed - %d", rc); - + error = EMAIL_ERROR_DB_FAILURE; - } + } } else { EM_DEBUG_LOG(" >>>>>>>>>> hStmt is NULL!!!"); @@ -13627,7 +13627,7 @@ FINISH_OFF: EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error); _DISCONNECT_DB; - + if (err_code != NULL) *err_code = error; @@ -13637,13 +13637,13 @@ FINISH_OFF: /** * emstorage_get_activity - Get the Local activity Information - * + * * */ INTERNAL_FUNC int emstorage_get_activity(int account_id, int activityid, emstorage_activity_tbl_t** activity_list, int *select_num, int transaction, int *err_code) { EM_DEBUG_FUNC_BEGIN(); - + int i = 0, count = 0, rc = -1, ret = false; int error = EMAIL_ERROR_NONE; emstorage_activity_tbl_t *p_activity_tbl = NULL; @@ -13654,14 +13654,14 @@ INTERNAL_FUNC int emstorage_get_activity(int account_id, int activityid, emstora EM_IF_NULL_RETURN_VALUE(activity_list, false); EM_IF_NULL_RETURN_VALUE(select_num, false); - + if (!select_num || !activity_list || account_id <= 0 || activityid < 0) { EM_DEBUG_LOG(" select_num[%p], activity_list[%p] account_id [%d] activityid [%d] ", select_num, activity_list, account_id, activityid); if (err_code != NULL) *err_code = EMAIL_ERROR_INVALID_PARAM; return false; } - + EMSTORAGE_START_READ_TRANSACTION(transaction); memset(sql_query_string, 0x00, sizeof(sql_query_string)); @@ -13675,23 +13675,23 @@ INTERNAL_FUNC int emstorage_get_activity(int account_id, int activityid, emstora EM_DEBUG_LOG("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))); - + col_index = 7; - + if (!(p_activity_tbl = (emstorage_activity_tbl_t*)em_malloc(sizeof(emstorage_activity_tbl_t) * count))) { EM_DEBUG_EXCEPTION(" em_malloc failed..."); error = EMAIL_ERROR_OUT_OF_MEMORY; goto FINISH_OFF; } - + for (i = 0; i < count; i++) { EM_DEBUG_LOG("result[%d] - %s ", col_index, result[col_index]); if (result[col_index]) @@ -13720,7 +13720,7 @@ INTERNAL_FUNC int emstorage_get_activity(int account_id, int activityid, emstora if (result[col_index] && EM_SAFE_STRLEN(result[col_index])>0) p_activity_tbl[i].src_mbox = EM_SAFE_STRDUP(result[col_index++]); else - col_index++; + col_index++; EM_DEBUG_LOG("result[%d] - %s ", col_index, result[col_index]); if (result[col_index] && EM_SAFE_STRLEN(result[col_index])>0) @@ -13734,10 +13734,10 @@ INTERNAL_FUNC int emstorage_get_activity(int account_id, int activityid, emstora sqlite3_free_table(result); ret = true; - + FINISH_OFF: - + if (ret == true) { *activity_list = p_activity_tbl; *select_num = count; @@ -13746,7 +13746,7 @@ FINISH_OFF: else if (p_activity_tbl != NULL) { emstorage_free_local_activity(&p_activity_tbl, count, NULL); } - + EMSTORAGE_FINISH_READ_TRANSACTION(transaction); if (err_code != NULL) *err_code = error; @@ -13760,17 +13760,17 @@ INTERNAL_FUNC int emstorage_get_next_activity_id(int *activity_id, int *err_code { EM_DEBUG_FUNC_BEGIN(); - + int ret = false; int err = EMAIL_ERROR_NONE; int rc = -1; char *sql = NULL; - char **result = NULL; + char **result = NULL; if (NULL == activity_id) { EM_DEBUG_EXCEPTION(" activity_id[%p]", activity_id); - + err = EMAIL_ERROR_INVALID_PARAM; goto FINISH_OFF; } @@ -13778,29 +13778,29 @@ INTERNAL_FUNC int emstorage_get_next_activity_id(int *activity_id, int *err_code /* increase unique id */ sql = "SELECT max(rowid) FROM mail_local_activity_tbl;"; - + /* rc = sqlite3_get_table(local_db_handle, sql, &result, NULL, NULL, NULL); n EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql, &result, NULL, NULL, NULL), rc); */ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {err = EMAIL_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; }, ("SQL(%s) sqlite3_get_table fail:%d -%s", sql, rc, sqlite3_errmsg(local_db_handle))); if (NULL==result[1]) rc = 1; - else + else rc = atoi(result[1])+1; *activity_id = rc; if (result) sqlite3_free_table(result); - + ret = true; - + FINISH_OFF: - + if (NULL != err_code) { *err_code = err; } - + EM_DEBUG_FUNC_END("ret [%d]", ret); return ret; @@ -13810,15 +13810,15 @@ INTERNAL_FUNC int emstorage_get_activity_id_list(int account_id, int ** activity { EM_DEBUG_FUNC_BEGIN(); - + EM_DEBUG_LOG(" account_id[%d], activity_id_list[%p], activity_id_count[%p] err_code[%p]", account_id, activity_id_list, activity_id_count, err_code); - + if (account_id <= 0|| NULL == activity_id_list || NULL == activity_id_count ||lowest_activity_type <=0 || highest_activity_type <= 0) { if (err_code != NULL) *err_code = EMAIL_ERROR_INVALID_PARAM; return false; } - + int ret = false; int error = EMAIL_ERROR_NONE; int i = 0, rc = -1, count = 0; @@ -13826,11 +13826,11 @@ INTERNAL_FUNC int emstorage_get_activity_id_list(int account_id, int ** activity int *activity_ids = NULL; int col_index = 0; char **result = NULL; - + EMSTORAGE_START_READ_TRANSACTION(transaction); memset(sql_query_string, 0x00, sizeof(sql_query_string)); - + SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT distinct activity_id FROM mail_local_activity_tbl WHERE account_id = %d AND activity_type >= %d AND activity_type <= %d order by activity_id", account_id, lowest_activity_type, highest_activity_type); EM_DEBUG_LOG(" Query [%s]", sql_query_string); @@ -13855,20 +13855,20 @@ INTERNAL_FUNC int emstorage_get_activity_id_list(int account_id, int ** activity col_index++; EM_DEBUG_LOG("activity_id %d", activity_ids[i]); } - + ret = true; - + FINISH_OFF: - + if (ret == true) { *activity_id_count = count; *activity_id_list = activity_ids; - + } else if (activity_ids != NULL) /* Prevent defect - 216566 */ EM_SAFE_FREE(activity_ids); - + EMSTORAGE_FINISH_READ_TRANSACTION(transaction); if (err_code != NULL) { @@ -13896,7 +13896,7 @@ INTERNAL_FUNC int emstorage_free_activity_id_list(int *activity_id_list, int *er free(activity_id_list); activity_id_list = NULL; } - + ret= true; @@ -13921,14 +13921,14 @@ INTERNAL_FUNC int emstorage_delete_local_activity(emstorage_activity_tbl_t* loca EM_DEBUG_LOG(" local_activity[%p] ", local_activity); - + if (!local_activity) { EM_DEBUG_EXCEPTION(" local_activity[%p] ", local_activity); if (err_code != NULL) *err_code = EMAIL_ERROR_INVALID_PARAM; return false; - } - + } + int rc = -1, ret = false; /* Prevent_FIX */ int err = EMAIL_ERROR_NONE; int query_and = 0; @@ -13937,7 +13937,7 @@ INTERNAL_FUNC int emstorage_delete_local_activity(emstorage_activity_tbl_t* loca 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_local_activity_tbl "); EM_DEBUG_LOG(">>> Query [ %s ] ", sql_query_string); @@ -13959,13 +13959,13 @@ INTERNAL_FUNC int emstorage_delete_local_activity(emstorage_activity_tbl_t* loca if (local_activity->mail_id) { EM_DEBUG_LOG(">>>> MAIL ID [ %d ] , ACTIVITY TYPE [%d ]", local_activity->mail_id, local_activity->activity_type); - + SNPRINTF(sql_query_string + EM_SAFE_STRLEN(sql_query_string), sizeof(sql_query_string)-(EM_SAFE_STRLEN(sql_query_string)+1), " %s %s mail_id = %d ", query_where? "": "WHERE", query_and? "AND":"", local_activity->mail_id); - + query_and = 1; query_where = 1; - + } if (local_activity->activity_type > 0) { @@ -13977,14 +13977,14 @@ INTERNAL_FUNC int emstorage_delete_local_activity(emstorage_activity_tbl_t* loca SNPRINTF(sql_query_string + EM_SAFE_STRLEN(sql_query_string), sizeof(sql_query_string)-(EM_SAFE_STRLEN(sql_query_string)+1), " %s %s activity_id = %d ", query_where? "": "WHERE", query_and? "AND" : "" , local_activity->activity_id); - } + } EM_DEBUG_LOG(">>>>> Query [ %s ] ", sql_query_string); - + 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))); - + rc = sqlite3_changes(local_db_handle); if (rc == 0) { EM_DEBUG_EXCEPTION(" no (matched) mailbox_name found..."); @@ -13992,7 +13992,7 @@ INTERNAL_FUNC int emstorage_delete_local_activity(emstorage_activity_tbl_t* loca } ret = true; - + FINISH_OFF: EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error); if (err_code != NULL) @@ -14007,20 +14007,20 @@ FINISH_OFF: INTERNAL_FUNC int emstorage_free_local_activity(emstorage_activity_tbl_t **local_activity_list, int count, int *err_code) { EM_DEBUG_FUNC_BEGIN(); - + EM_DEBUG_LOG(" local_activity_list[%p], count[%d], err_code[%p]", local_activity_list, count, err_code); - + int ret = false; int error = EMAIL_ERROR_INVALID_PARAM; - + if (count > 0) { if (!local_activity_list || !*local_activity_list) { EM_DEBUG_EXCEPTION(" local_activity_list[%p], count[%d]", local_activity_list, count); - + error = EMAIL_ERROR_INVALID_PARAM; goto FINISH_OFF; } - + emstorage_activity_tbl_t* p = *local_activity_list; int i = 0; if (p) { @@ -14029,13 +14029,13 @@ INTERNAL_FUNC int emstorage_free_local_activity(emstorage_activity_tbl_t **local EM_SAFE_FREE(p[i].src_mbox); EM_SAFE_FREE(p[i].server_mailid); } - + free(p); *local_activity_list = NULL; } } - + ret = true; - + FINISH_OFF: if (err_code != NULL) *err_code = error; @@ -14312,7 +14312,7 @@ static int _make_filter_rule_string(email_list_filter_rule_t *input_list_filter_ SNPRINTF(result_rule_string, QUERY_SIZE, "%s = %s ", mod_field_name_string, mod_value_string); break; case EMAIL_LIST_FILTER_RULE_NOT_EQUAL : - SNPRINTF(result_rule_string, QUERY_SIZE, "%s = %s ", mod_field_name_string, mod_value_string); + SNPRINTF(result_rule_string, QUERY_SIZE, "%s != %s ", mod_field_name_string, mod_value_string); break; case EMAIL_LIST_FILTER_RULE_LESS_THAN : SNPRINTF(result_rule_string, QUERY_SIZE, "%s < %s ", mod_field_name_string, mod_value_string); @@ -14390,6 +14390,7 @@ INTERNAL_FUNC int emstorage_write_conditional_clause_for_getting_mail_list(email EM_DEBUG_FUNC_BEGIN("input_filter_list [%p], input_filter_count[%d], input_sorting_rule_list[%p], input_sorting_rule_count [%d], input_start_index [%d], input_limit_count [%d], output_conditional_clause [%p]", input_filter_list, input_filter_count, input_sorting_rule_list, input_sorting_rule_count, input_start_index, input_limit_count, output_conditional_clause); int ret = EMAIL_ERROR_NONE; int i = 0; + int string_offset = 0; char conditional_clause_string[QUERY_SIZE] = {0, }; char *result_string_for_a_item = NULL; @@ -14463,6 +14464,11 @@ 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); + } + *output_conditional_clause = strdup(conditional_clause_string); FINISH_OFF: @@ -14635,20 +14641,20 @@ FINISH_OFF: INTERNAL_FUNC int emstorage_free_certificate(emstorage_certificate_tbl_t **certificate_list, int count, int *err_code) { EM_DEBUG_FUNC_BEGIN("certificate_list[%p], count[%d], err_code[%p]", certificate_list, count, err_code); - + int ret = false; int error = EMAIL_ERROR_NONE; - + if (count > 0) { if (!certificate_list || !*certificate_list) { EM_DEBUG_EXCEPTION("certificate_list[%p], count[%d]", certificate_list, count); error = EMAIL_ERROR_INVALID_PARAM; goto FINISH_OFF; } - + emstorage_certificate_tbl_t *p = *certificate_list; int i = 0; - + for (; i < count; i++) { EM_SAFE_FREE(p[i].issue_organization_name); EM_SAFE_FREE(p[i].email_address); @@ -14656,13 +14662,13 @@ INTERNAL_FUNC int emstorage_free_certificate(emstorage_certificate_tbl_t **certi EM_SAFE_FREE(p[i].filepath); EM_SAFE_FREE(p[i].password); } - - EM_SAFE_FREE(p); + + EM_SAFE_FREE(p); *certificate_list = NULL; } - + ret = true; - + FINISH_OFF: if (err_code != NULL) *err_code = error; @@ -14831,14 +14837,14 @@ INTERNAL_FUNC int emstorage_get_certificate_by_email_address(char *email_address int sql_len = 0; #ifdef __FEATURE_SUPPORT_PRIVATE_CERTIFICATE__ char cert_password_file_name[MAX_PW_FILE_NAME_LENGTH]; -#endif +#endif sqlite3 *local_db_handle = emstorage_get_db_connection(); EMSTORAGE_START_READ_TRANSACTION(transaction); /* Make query string */ SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT "); sql_len = EM_SAFE_STRLEN(sql_query_string); - + /* dummy value, FROM WHERE clause */ SNPRINTF(sql_query_string + sql_len, sizeof(sql_query_string) - sql_len, "* FROM mail_certificate_tbl WHERE email_address = '%s'", email_address); @@ -14849,7 +14855,7 @@ INTERNAL_FUNC int emstorage_get_certificate_by_email_address(char *email_address 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 && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, ("sqlite3_step fail:%d", rc)); @@ -14886,7 +14892,7 @@ INTERNAL_FUNC int emstorage_get_certificate_by_email_address(char *email_address if ((error = _get_cert_password_file_name(p_data_tbl->certificate_id, cert_password_file_name)) != EMAIL_ERROR_NONE) { EM_DEBUG_EXCEPTION("em_storage_get_password_file_name failed."); goto FINISH_OFF; - } + } /* read password from secure storage */ if ((error = _read_password_from_secure_storage(cert_password_file_name, &(p_data_tbl->password))) != EMAIL_ERROR_NONE) { @@ -14909,7 +14915,7 @@ FINISH_OFF: error = EMAIL_ERROR_DB_FAILURE; } } - + EMSTORAGE_FINISH_READ_TRANSACTION(transaction); _DISCONNECT_DB; @@ -14940,14 +14946,14 @@ INTERNAL_FUNC int emstorage_get_certificate_by_index(int index, emstorage_certif int sql_len = 0; #ifdef __FEATURE_SUPPORT_PRIVATE_CERTIFICATE__ char cert_password_file_name[MAX_PW_FILE_NAME_LENGTH]; -#endif +#endif sqlite3 *local_db_handle = emstorage_get_db_connection(); EMSTORAGE_START_READ_TRANSACTION(transaction); /* Make query string */ SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT "); sql_len = EM_SAFE_STRLEN(sql_query_string); - + /* dummy value, FROM WHERE clause */ SNPRINTF(sql_query_string + sql_len, sizeof(sql_query_string) - sql_len, "* FROM mail_certificate_tbl WHERE certificate_id = %d", index); @@ -14958,7 +14964,7 @@ INTERNAL_FUNC int emstorage_get_certificate_by_index(int index, emstorage_certif 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 && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, ("sqlite3_step fail:%d", rc)); @@ -14996,7 +15002,7 @@ INTERNAL_FUNC int emstorage_get_certificate_by_index(int index, emstorage_certif if ((error = _get_cert_password_file_name(p_data_tbl->certificate_id, cert_password_file_name)) != EMAIL_ERROR_NONE) { EM_DEBUG_EXCEPTION("em_storage_get_password_file_name failed."); goto FINISH_OFF; - } + } /* read password from secure storage */ if ((error = _read_password_from_secure_storage(cert_password_file_name, &(p_data_tbl->password))) != EMAIL_ERROR_NONE) { @@ -15019,7 +15025,7 @@ FINISH_OFF: error = EMAIL_ERROR_DB_FAILURE; } } - + EMSTORAGE_FINISH_READ_TRANSACTION(transaction); _DISCONNECT_DB; @@ -15033,15 +15039,15 @@ FINISH_OFF: INTERNAL_FUNC int emstorage_delete_certificate(int certificate_id, int transaction, int *err_code) { EM_DEBUG_FUNC_BEGIN("certificate_id[%d], transaction[%d], err_code[%p]", certificate_id, transaction, err_code); - - if (certificate_id < 1) { + + if (certificate_id < 1) { EM_DEBUG_EXCEPTION(" certificate_id[%d]", certificate_id); - + if (err_code != NULL) *err_code = EMAIL_ERROR_INVALID_PARAM; return false; } - + int rc = -1, ret = false; int error = EMAIL_ERROR_NONE; sqlite3 *local_db_handle = emstorage_get_db_connection(); @@ -15050,7 +15056,7 @@ INTERNAL_FUNC int emstorage_delete_certificate(int certificate_id, int transacti /* 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__ +#ifdef __FEATURE_SUPPORT_PRIVATE_CERTIFICATE__ char cert_password_file_name[MAX_PW_FILE_NAME_LENGTH]; /* get password file name */ if ((error = _get_cert_password_file_name(certificate_id, cert_password_file_name)) != EMAIL_ERROR_NONE) { @@ -15061,7 +15067,7 @@ 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)); @@ -15075,18 +15081,18 @@ 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__ +#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(" ssm_delete_file failed -cert password : file[%s]", cert_password_file_name); error = EMAIL_ERROR_SYSTEM_FAILURE; - goto FINISH_OFF; + goto FINISH_OFF; } -#endif +#endif ret = true; FINISH_OFF: - + if (hStmt != NULL) { rc = sqlite3_finalize(hStmt); if (rc != SQLITE_OK) { @@ -15108,21 +15114,21 @@ FINISH_OFF: INTERNAL_FUNC int emstorage_update_certificate(int certificate_id, emstorage_certificate_tbl_t *certificate, int transaction, int *err_code) { EM_DEBUG_FUNC_BEGIN("certificate_id[%d], certificate[%p], transaction[%d], err_code[%p]", certificate_id, certificate, transaction, err_code); - - if (certificate_id < 1) { + + if (certificate_id < 1) { EM_DEBUG_EXCEPTION(" certificate_id[%d]", certificate_id); - + if (err_code != NULL) *err_code = EMAIL_ERROR_INVALID_PARAM; return false; } - + int error = EMAIL_ERROR_NONE; int rc, ret = false; - + DB_STMT hStmt = NULL; char sql_query_string[QUERY_SIZE] = {0, }; -#ifdef __FEATURE_SUPPORT_PRIVATE_CERTIFICATE__ +#ifdef __FEATURE_SUPPORT_PRIVATE_CERTIFICATE__ char cert_password_file_name[MAX_PW_FILE_NAME_LENGTH]; #endif sqlite3 *local_db_handle = emstorage_get_db_connection(); @@ -15142,12 +15148,12 @@ INTERNAL_FUNC int emstorage_update_certificate(int certificate_id, emstorage_cer ", filepath = ?" /* Organization of issue */ ", password = ?" " WHERE certificate_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_LOG("After 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))); - + _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); _bind_stmt_field_data_int(hStmt, ISSUE_DAY_IDX_IN_MAIL_CERTIFICATE_TBL, certificate->issue_day); @@ -15158,29 +15164,29 @@ INTERNAL_FUNC int emstorage_update_certificate(int certificate_id, emstorage_cer _bind_stmt_field_data_string(hStmt, EMAIL_ADDRESS_IDX_IN_MAIL_CERTIFICATE_TBL, certificate->email_address, 0, EMAIL_ADDRESS_LEN_IN_MAIL_CERTIFICATE_TBL); _bind_stmt_field_data_string(hStmt, SUBJECT_STRING_IDX_IN_MAIL_CERTIFICATE_TBL, certificate->subject_str, 0, SUBJECT_STRING_LEN_IN_MAIL_CERTIFICATE_TBL); _bind_stmt_field_data_string(hStmt, FILE_PATH_IDX_IN_MAIL_CERTIFICATE_TBL, certificate->filepath, 0, FILE_NAME_LEN_IN_MAIL_CERTIFICATE_TBL); - + /* rc = sqlite3_step(hStmt); */ EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc); EM_DEBUG_DB_EXEC((SQLITE_FULL == rc), {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)); - + /* validate account existence */ rc = sqlite3_changes(local_db_handle); if (rc == 0) { EM_DEBUG_EXCEPTION(" no matched account found..."); - + error = EMAIL_ERROR_ACCOUNT_NOT_FOUND; goto FINISH_OFF; } - -#ifdef __FEATURE_SUPPORT_PRIVATE_CERTIFICATE__ + +#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) { @@ -15188,14 +15194,14 @@ INTERNAL_FUNC int emstorage_update_certificate(int certificate_id, emstorage_cer error = EMAIL_ERROR_SYSTEM_FAILURE; goto FINISH_OFF; } -#endif +#endif if (!emcore_notify_storage_event(NOTI_CERTIFICATE_UPDATE, certificate->certificate_id, 0, NULL, 0)) EM_DEBUG_EXCEPTION(" emcore_notify_storage_event[ NOTI_CERTIFICATE_UPDATE] : Notification Failed >>> "); - + ret = true; - + FINISH_OFF: - + if (hStmt != NULL) { EM_DEBUG_LOG(" Before sqlite3_finalize hStmt = %p", hStmt); @@ -15207,9 +15213,9 @@ FINISH_OFF: } EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error); - + _DISCONNECT_DB; - + if (err_code != NULL) *err_code = error; diff --git a/email-core/email-storage/include/email-storage.h b/email-core/email-storage/include/email-storage.h index 946f4b7..d59f6ef 100755 --- a/email-core/email-storage/include/email-storage.h +++ b/email-core/email-storage/include/email-storage.h @@ -1,7 +1,7 @@ /* * email-service * -* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> * diff --git a/email-core/include/email-core-account.h b/email-core/include/email-core-account.h index 1ed302d..70c3e5b 100755 --- a/email-core/include/email-core-account.h +++ b/email-core/include/email-core-account.h @@ -1,7 +1,7 @@ /* * email-service * -* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> * diff --git a/email-core/include/email-core-api.h b/email-core/include/email-core-api.h index 3937b26..9605a72 100755 --- a/email-core/include/email-core-api.h +++ b/email-core/include/email-core-api.h @@ -1,7 +1,7 @@ /* * email-service * -* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> * diff --git a/email-core/include/email-core-cert.h b/email-core/include/email-core-cert.h index 4e86091..12e87b1 100644 --- a/email-core/include/email-core-cert.h +++ b/email-core/include/email-core-cert.h @@ -1,7 +1,7 @@ /* * email-service * -* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> * diff --git a/email-core/include/email-core-event.h b/email-core/include/email-core-event.h index 5476d2b..bf1bce2 100755 --- a/email-core/include/email-core-event.h +++ b/email-core/include/email-core-event.h @@ -1,7 +1,7 @@ /* * email-service * -* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> * diff --git a/email-core/include/email-core-global.h b/email-core/include/email-core-global.h index d51a14d..2ddfab3 100755 --- a/email-core/include/email-core-global.h +++ b/email-core/include/email-core-global.h @@ -1,7 +1,7 @@ /* * email-service * -* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> * diff --git a/email-core/include/email-core-imap-idle.h b/email-core/include/email-core-imap-idle.h index c524dc3..30fd18e 100755 --- a/email-core/include/email-core-imap-idle.h +++ b/email-core/include/email-core-imap-idle.h @@ -1,7 +1,7 @@ /* * email-service * -* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> * diff --git a/email-core/include/email-core-imap-mailbox.h b/email-core/include/email-core-imap-mailbox.h index 7700945..533892e 100755 --- a/email-core/include/email-core-imap-mailbox.h +++ b/email-core/include/email-core-imap-mailbox.h @@ -1,7 +1,7 @@ /* * email-service * -* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> * @@ -71,7 +71,7 @@ INTERNAL_FUNC int emcore_move_mailbox_on_imap_server(int input_account_id, char INTERNAL_FUNC int emcore_set_sync_imap_mailbox(email_internal_mailbox_t *mailbox, int synchronous, int *err_code); INTERNAL_FUNC int emcore_set_mail_slot_size(int account_id, int mailbox_id, int new_slot_size, int *err_code); INTERNAL_FUNC int emcore_remove_overflowed_mails(emstorage_mailbox_tbl_t *intput_mailbox_tbl, int *err_code); -INTERNAL_FUNC int emcore_get_default_mail_slot_count(int *output_count, int *err_code); +INTERNAL_FUNC int emcore_get_default_mail_slot_count(int input_account_id, int *output_count); #ifdef __cplusplus } diff --git a/email-core/include/email-core-mail.h b/email-core/include/email-core-mail.h index fe2e5c2..667df78 100755 --- a/email-core/include/email-core-mail.h +++ b/email-core/include/email-core-mail.h @@ -1,7 +1,7 @@ /* * email-service * -* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> * @@ -200,6 +200,7 @@ INTERNAL_FUNC int emcore_sync_seen_flag_with_server(int mail_ids[], int num, i 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); #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); diff --git a/email-core/include/email-core-mailbox-sync.h b/email-core/include/email-core-mailbox-sync.h index 3435be1..71848e9 100755 --- a/email-core/include/email-core-mailbox-sync.h +++ b/email-core/include/email-core-mailbox-sync.h @@ -1,7 +1,7 @@ /* * email-service * -* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> * diff --git a/email-core/include/email-core-mailbox.h b/email-core/include/email-core-mailbox.h index 1920c52..9ea5599 100755 --- a/email-core/include/email-core-mailbox.h +++ b/email-core/include/email-core-mailbox.h @@ -1,7 +1,7 @@ /* * email-service * -* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> * diff --git a/email-core/include/email-core-mime.h b/email-core/include/email-core-mime.h index 756fac6..8c110ec 100755 --- a/email-core/include/email-core-mime.h +++ b/email-core/include/email-core-mime.h @@ -1,7 +1,7 @@ /* * email-service * -* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> * diff --git a/email-core/include/email-core-signal.h b/email-core/include/email-core-signal.h index cb35e15..401bce0 100755 --- a/email-core/include/email-core-signal.h +++ b/email-core/include/email-core-signal.h @@ -1,7 +1,7 @@ /*
* email-service
*
-* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
*
* Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com>
*
diff --git a/email-core/include/email-core-smime.h b/email-core/include/email-core-smime.h index 013bc66..c1b84f7 100755 --- a/email-core/include/email-core-smime.h +++ b/email-core/include/email-core-smime.h @@ -1,7 +1,7 @@ /* * email-service * -* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> * diff --git a/email-core/include/email-core-smtp.h b/email-core/include/email-core-smtp.h index ace6c5c..23b920c 100755 --- a/email-core/include/email-core-smtp.h +++ b/email-core/include/email-core-smtp.h @@ -1,7 +1,7 @@ /* * email-service * -* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> * @@ -46,6 +46,8 @@ INTERNAL_FUNC int emcore_send_mail(int account_id, int input_mailbox_id, int mai INTERNAL_FUNC int emcore_send_saved_mail(int account_id, char *mailbox, int *err_code); +INTERNAL_FUNC int emcore_send_mail_with_downloading_attachment_of_original_mail(int input_mail_id); + INTERNAL_FUNC int emcore_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); diff --git a/email-core/include/email-core-sound.h b/email-core/include/email-core-sound.h index e7f0949..f51cead 100755 --- a/email-core/include/email-core-sound.h +++ b/email-core/include/email-core-sound.h @@ -1,7 +1,7 @@ /* * email-service * -* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> * diff --git a/email-core/include/email-core-task-manager.h b/email-core/include/email-core-task-manager.h index 9a1019d..9299cc6 100755 --- a/email-core/include/email-core-task-manager.h +++ b/email-core/include/email-core-task-manager.h @@ -1,7 +1,7 @@ /*
* email-service
*
-* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
*
* Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com>
*
diff --git a/email-core/include/email-core-tasks.h b/email-core/include/email-core-tasks.h index 3fe3409..033a621 100755 --- a/email-core/include/email-core-tasks.h +++ b/email-core/include/email-core-tasks.h @@ -1,7 +1,7 @@ /*
* email-service
*
-* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
*
* Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com>
*
@@ -81,5 +81,13 @@ typedef struct DECLARE_CONVERTER_FOR_TASK_PARAMETER(EMAIL_ASYNC_TASK_DELETE_MAILBOX_EX);
INTERNAL_FUNC void* task_handler_EMAIL_ASYNC_TASK_DELETE_MAILBOX_EX(void *input_param);
/*-------------------------------------------------------------------------------------------*/
+/* to handle EMAIL_ASYNC_TASK_SEND_MAIL_WITH_DOWNLOADING_ATTACHMENT_OF_ORIGINAL_MAIL */
+typedef struct
+{
+ int mail_id;
+} task_parameter_EMAIL_ASYNC_TASK_SEND_MAIL_WITH_DOWNLOADING_ATTACHMENT_OF_ORIGINAL_MAIL;
+DECLARE_CONVERTER_FOR_TASK_PARAMETER(EMAIL_ASYNC_TASK_SEND_MAIL_WITH_DOWNLOADING_ATTACHMENT_OF_ORIGINAL_MAIL);
+INTERNAL_FUNC void* task_handler_EMAIL_ASYNC_TASK_SEND_MAIL_WITH_DOWNLOADING_ATTACHMENT_OF_ORIGINAL_MAIL(void *input_param);
+/*-------------------------------------------------------------------------------------------*/
#endif /* EMAIL_CORE_TASKS_H_ */
diff --git a/email-core/include/email-core-timer.h b/email-core/include/email-core-timer.h index 7704c34..fd3f5bc 100755 --- a/email-core/include/email-core-timer.h +++ b/email-core/include/email-core-timer.h @@ -1,7 +1,7 @@ /* * email-service * -* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> * diff --git a/email-core/include/email-core-utils.h b/email-core/include/email-core-utils.h index 480e71b..07bf41e 100755 --- a/email-core/include/email-core-utils.h +++ b/email-core/include/email-core-utils.h @@ -1,7 +1,7 @@ /* * email-service * -* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> * diff --git a/email-daemon/email-daemon-account.c b/email-daemon/email-daemon-account.c index 595b5d4..1fa5162 100755 --- a/email-daemon/email-daemon-account.c +++ b/email-daemon/email-daemon-account.c @@ -1,7 +1,7 @@ /* * email-service * -* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> * diff --git a/email-daemon/email-daemon-auto-poll.c b/email-daemon/email-daemon-auto-poll.c index 0b4cee9..bedd7ff 100755 --- a/email-daemon/email-daemon-auto-poll.c +++ b/email-daemon/email-daemon-auto-poll.c @@ -1,10 +1,10 @@ /* * email-service * -* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* 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 @@ -85,7 +85,7 @@ INTERNAL_FUNC int emdaemon_add_polling_alarm(int account_id, int alarm_interval) EM_DEBUG_EXCEPTION("_emdaemon_create_alarm failed"); return false; } - + p_account_alarm_binder = (email_account_alarm_binder_list_t*)em_malloc(sizeof(email_account_alarm_binder_list_t)); if(!p_account_alarm_binder) { EM_DEBUG_EXCEPTION("malloc Failed "); @@ -95,10 +95,10 @@ INTERNAL_FUNC int emdaemon_add_polling_alarm(int account_id, int alarm_interval) p_account_alarm_binder->account_alarm_binder.account_id = account_id; p_account_alarm_binder->account_alarm_binder.alarm_id = alarmID; p_account_alarm_binder->account_alarm_binder.timer_interval = alarm_interval; - + _emdaemon_add_to_account_alarm_binder_list(p_account_alarm_binder); - return true; + return true; } @@ -126,7 +126,7 @@ INTERNAL_FUNC int emdaemon_remove_polling_alarm(int account_id) EM_DEBUG_LOG("ErrorCode :%d, Return Value:%d ",a_nErrorCode,retval); if(!retval) - return false; + return false; } /* delete from list */ @@ -152,7 +152,7 @@ INTERNAL_FUNC int emdaemon_check_auto_polling_started(int account_id) while(p_temp != NULL) { if(p_temp->account_alarm_binder.account_id == account_id) { - EM_DEBUG_EXCEPTION("account match found : polling already started"); + EM_DEBUG_EXCEPTION("account match found : polling already started"); match_found = true; break; } @@ -176,11 +176,11 @@ INTERNAL_FUNC int emdaemon_alarm_polling_cb(alarm_id_t alarm_id, void* user_par time_t ct = time(&ct); struct tm* lt = localtime(&ct); - + if (lt) { EM_DEBUG_LOG( "Current Time : [%d-%d-%d %d:%d:%d] ", lt->tm_year + 1900, lt->tm_mon + 1, lt->tm_mday, - lt->tm_hour, lt->tm_min, lt->tm_sec); + lt->tm_hour, lt->tm_min, lt->tm_sec); } if(!_emdaemon_get_polling_account_and_timeinterval(alarm_id,&account_id,&timer_interval)) { @@ -189,7 +189,7 @@ INTERNAL_FUNC int emdaemon_alarm_polling_cb(alarm_id_t alarm_id, void* user_par } EM_DEBUG_EXCEPTION(" emdaemon_alarm_polling_cb : account_id [%d]",account_id); - /* create alarm, for polling */ + /* create alarm, for polling */ if(!_emdaemon_create_alarm(timer_interval,&alarmID)) { EM_DEBUG_EXCEPTION("_emdaemon_create_alarm failed"); return false; @@ -212,7 +212,7 @@ INTERNAL_FUNC int emdaemon_alarm_polling_cb(alarm_id_t alarm_id, void* user_par mailbox.mailbox_name = mailbox_name; if (!emdaemon_sync_header(account_id, mailbox.mailbox_id, NULL, &err)) { - EM_DEBUG_EXCEPTION("emdaemon_sync_header falied [%d]", err); + EM_DEBUG_EXCEPTION("emdaemon_sync_header falied [%d]", err); goto FINISH_OFF; } @@ -229,7 +229,7 @@ static int _emdaemon_get_polling_alarm_and_timerinterval(int account_id, alarm_i EM_DEBUG_FUNC_BEGIN(); if(!account_id || !alarm_id) - return false; + return false; if(g_account_alarm_binder_list == NULL) { EM_DEBUG_EXCEPTION("g_account_alarm_binder_list NULL "); @@ -243,10 +243,10 @@ static int _emdaemon_get_polling_alarm_and_timerinterval(int account_id, alarm_i if(p_temp->account_alarm_binder.account_id == account_id) { EM_DEBUG_EXCEPTION("account match found "); *alarm_id = p_temp->account_alarm_binder.alarm_id; - + if(timer_interval) *timer_interval = p_temp->account_alarm_binder.timer_interval; - + match_found = true; break; } @@ -268,7 +268,7 @@ static int _emdaemon_get_polling_account_and_timeinterval(alarm_id_t alarm_id, EM_DEBUG_FUNC_BEGIN(); if(!alarm_id || !account_id) - return false; + return false; if(g_account_alarm_binder_list == NULL) { EM_DEBUG_EXCEPTION("g_account_alarm_binder_list NULL "); @@ -282,10 +282,10 @@ static int _emdaemon_get_polling_account_and_timeinterval(alarm_id_t alarm_id, if(p_temp->account_alarm_binder.alarm_id == alarm_id) { EM_DEBUG_EXCEPTION("aalrm match found "); *account_id = p_temp->account_alarm_binder.account_id; - + if(timer_interval) *timer_interval = p_temp->account_alarm_binder.timer_interval; - + match_found = true; break; } @@ -297,11 +297,11 @@ static int _emdaemon_get_polling_account_and_timeinterval(alarm_id_t alarm_id, EM_DEBUG_EXCEPTION("aalrm match not found "); return false; } - + return true; } -#define AUTO_POLL_DESTINATION "org.tizen.email-service" +#define AUTO_POLL_DESTINATION "com.samsung.email-service" static int _emdaemon_create_alarm(int alarm_interval, alarm_id_t *p_alarm_id) { EM_DEBUG_FUNC_BEGIN(); @@ -309,24 +309,24 @@ static int _emdaemon_create_alarm(int alarm_interval, alarm_id_t *p_alarm_id) /* tzset(); */ time_t ct = time(&ct); struct tm* lt = localtime(&ct); - + if (lt) { EM_DEBUG_LOG( "Current Time : [%d-%d-%d %d:%d:%d] ", lt->tm_year + 1900, lt->tm_mon + 1, lt->tm_mday, - lt->tm_hour, lt->tm_min, lt->tm_sec); + lt->tm_hour, lt->tm_min, lt->tm_sec); } /* alarm_info_t alarm_info = {0}; */ int a_nErrorCode = 0; - + if((alarm_interval <= 0) || !p_alarm_id) { EM_DEBUG_EXCEPTION("Invalid param "); return false; } - + /* time_t current_time = {0}; */ /* struct tm current_tm = {0}; */ - /* Fill alarm info */ + /* Fill alarm info */ /* int timeFormat = 0; */ /*0 means 12hrs , 1 means 24hrs*/ /* TO DO, need to findout header for DBG_MID_MSGPORTING_NORMAL and then we have to use this */ @@ -337,7 +337,7 @@ static int _emdaemon_create_alarm(int alarm_interval, alarm_id_t *p_alarm_id) EM_DEBUG_EXCEPTION("alarmmgr_init failed : ErrorCode[%d]",a_nErrorCode); return false; } - + a_nErrorCode = alarmmgr_set_cb(emdaemon_alarm_polling_cb, NULL); if (a_nErrorCode != ALARMMGR_RESULT_SUCCESS) { EM_DEBUG_EXCEPTION("alarmmgr_set_cb : ErrorCode[%d]",a_nErrorCode); @@ -357,9 +357,9 @@ INTERNAL_FUNC int emdaemon_free_account_alarm_binder_list() { EM_DEBUG_FUNC_BEGIN(); - email_account_alarm_binder_list_t *p = g_account_alarm_binder_list, *p_next = NULL; + email_account_alarm_binder_list_t *p = g_account_alarm_binder_list, *p_next = NULL; int a_nErrorCode = 0; - + /* delete alarm as well */ while (p) { /* delete alarm */ @@ -373,7 +373,7 @@ INTERNAL_FUNC int emdaemon_free_account_alarm_binder_list() } g_account_alarm_binder_list = NULL; - + return true; } @@ -406,7 +406,7 @@ static int _emdaemon_remove_from_account_alarm_binder_list(int account_id) { email_account_alarm_binder_list_t *p_temp = g_account_alarm_binder_list, *p_prev = NULL; int match_found = false; - + if(!account_id) { EM_DEBUG_EXCEPTION("Invalid param "); return false; @@ -420,20 +420,20 @@ static int _emdaemon_remove_from_account_alarm_binder_list(int account_id) EM_SAFE_FREE(p_temp); } else { - while(p_temp != NULL) { + while(p_temp != NULL) { if(p_temp->account_alarm_binder.account_id == account_id) { EM_DEBUG_EXCEPTION("account match found "); p_prev->next = p_temp->next; EM_SAFE_FREE(p_temp); - + match_found = true; break; } - + p_prev = p_temp; p_temp = p_temp->next; - } + } } if(!match_found) diff --git a/email-daemon/email-daemon-emn.c b/email-daemon/email-daemon-emn.c index 01219da..8c3aa2b 100755 --- a/email-daemon/email-daemon-emn.c +++ b/email-daemon/email-daemon-emn.c @@ -1,7 +1,7 @@ /* * email-service * -* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> * diff --git a/email-daemon/email-daemon-etc.c b/email-daemon/email-daemon-etc.c index 526684b..9374e3e 100755 --- a/email-daemon/email-daemon-etc.c +++ b/email-daemon/email-daemon-etc.c @@ -1,7 +1,7 @@ /* * email-service * -* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> * diff --git a/email-daemon/email-daemon-init.c b/email-daemon/email-daemon-init.c index 55a7184..f5fa2c4 100755 --- a/email-daemon/email-daemon-init.c +++ b/email-daemon/email-daemon-init.c @@ -1,7 +1,7 @@ /* * email-service * -* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> * @@ -283,7 +283,7 @@ INTERNAL_FUNC int emdaemon_initialize(int* err_code) EM_DEBUG_LOG("************* start email service build time [%s %s] ************* ", __DATE__, __TIME__); dbus_threads_init_default(); - + g_type_init(); emstorage_shm_file_init(SHM_FILE_FOR_DB_LOCK); diff --git a/email-daemon/email-daemon-mail.c b/email-daemon/email-daemon-mail.c index c117164..a744f0a 100755 --- a/email-daemon/email-daemon-mail.c +++ b/email-daemon/email-daemon-mail.c @@ -1,10 +1,10 @@ /* * email-service * -* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* 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,7 +25,7 @@ * File: email-daemon-mail.c * Desc: email-daemon Mail Operation * - * Auth: + * Auth: * * History: * 2006.08.16 : created @@ -49,10 +49,10 @@ #include "email-utilities.h" #include "email-core-account.h" #include "email-core-mail.h" -#include "email-core-mailbox.h" -#include "email-core-utils.h" -#include "email-core-smtp.h" -#include "email-core-timer.h" +#include "email-core-mailbox.h" +#include "email-core-utils.h" +#include "email-core-smtp.h" +#include "email-core-timer.h" #include "email-core-signal.h" #ifdef __FEATURE_LOCAL_ACTIVITY__ @@ -62,9 +62,9 @@ extern int g_save_local_activity_run; static int _emdaemon_check_mail_id(int mail_id, int* err_code); INTERNAL_FUNC int emdaemon_send_mail(int mail_id, int *handle, int* err_code) -{ +{ EM_DEBUG_FUNC_BEGIN("mail_id[%d], handle[%p], err_code[%p]", mail_id, handle, err_code); - + int ret = false, err = EMAIL_ERROR_NONE, err_2 = EMAIL_ERROR_NONE; int result_handle = 0, account_id = 0; email_event_t event_data = { 0, }; @@ -77,12 +77,12 @@ INTERNAL_FUNC int emdaemon_send_mail(int mail_id, int *handle, int* err_code) err= EMAIL_ERROR_INVALID_PARAM; goto FINISH_OFF; } - + if(!emstorage_get_mail_by_id(mail_id, &mail_table_data, true, &err)) { EM_DEBUG_EXCEPTION("Failed to get mail by mail_id [%d]", err); goto FINISH_OFF; } - + if (!mail_table_data || mail_table_data->mailbox_id <= 0 || mail_table_data->account_id <= 0) { if (mail_table_data != NULL) EM_DEBUG_EXCEPTION(" mail_table_data->mailbox_id[%d], mail_table_data->account_id[%d]", mail_table_data->mailbox_id, mail_table_data->account_id); @@ -92,9 +92,9 @@ INTERNAL_FUNC int emdaemon_send_mail(int mail_id, int *handle, int* err_code) emstorage_free_mail(&mail_table_data, 1, &err); return false; } - + account_id = mail_table_data->account_id; - + email_account_t* ref_account = emdaemon_get_account_reference(account_id); if (!ref_account) { @@ -120,7 +120,7 @@ INTERNAL_FUNC int emdaemon_send_mail(int mail_id, int *handle, int* err_code) if(!emcore_notify_network_event(NOTI_SEND_START, account_id, NULL, mail_id, 0)) EM_DEBUG_EXCEPTION(" emcore_notify_network_event [ NOTI_SEND_START] Failed >>>> "); - + /* set EMAIL_MAIL_STATUS_SEND_WAIT status */ if(!emstorage_set_field_of_mails_with_integer_value(account_id, &mail_id, 1, "save_status", EMAIL_MAIL_STATUS_SEND_WAIT, true, &err)) { @@ -143,15 +143,15 @@ INTERNAL_FUNC int emdaemon_send_mail(int mail_id, int *handle, int* err_code) EM_DEBUG_LOG("Setting g_save_local_activity_run "); g_save_local_activity_run = 1; #endif - + if ( handle ) *handle = result_handle; ret = true; - + FINISH_OFF: - if (ret == false) { - EM_DEBUG_EXCEPTION("emdaemon_send_mail failed [%d]", err); + if (ret == false) { + EM_DEBUG_EXCEPTION("emdaemon_send_mail failed [%d]", err); if(!emstorage_set_field_of_mails_with_integer_value(account_id, &mail_id, 1, "save_status", EMAIL_MAIL_STATUS_SAVED, true, &err)) EM_DEBUG_EXCEPTION("emstorage_set_field_of_mails_with_integer_value [%d]",err); @@ -176,20 +176,20 @@ FINISH_OFF: } INTERNAL_FUNC int emdaemon_send_mail_saved(int account_id, int *handle, int* err_code) -{ +{ EM_DEBUG_FUNC_BEGIN("account_id[%d],handle[%p], err_code[%p]", account_id, handle, err_code); - + int ret = false; int err = EMAIL_ERROR_NONE; email_event_t event_data = { 0 , }; - char *mailbox_name = NULL; - + char *mailbox_name = NULL; + if (account_id <= 0) { EM_DEBUG_EXCEPTION("account_id = %d", account_id); err = EMAIL_ERROR_INVALID_PARAM; goto FINISH_OFF; } - + email_account_t* ref_account = emdaemon_get_account_reference(account_id); if (!ref_account) { @@ -211,16 +211,16 @@ INTERNAL_FUNC int emdaemon_send_mail_saved(int account_id, int *handle, int* err EM_DEBUG_EXCEPTION("emcore_insert_event failed [%d]", err); goto FINISH_OFF; } - + ret = true; - + FINISH_OFF: if (ret == false) { EM_SAFE_FREE(event_data.event_param_data_3); } EM_SAFE_FREE(mailbox_name); - + if (err_code) *err_code = err; @@ -235,21 +235,21 @@ INTERNAL_FUNC int emdaemon_add_mail(email_mail_data_t *input_mail_data, email_at int err = EMAIL_ERROR_NONE; int handle = 0; email_event_t event_data = { 0 }; - + if (!input_mail_data || input_mail_data->account_id <= 0 || ( ((input_mail_data->report_status & EMAIL_MAIL_REPORT_MDN) != 0) && !input_mail_data->full_address_to)) { - EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM"); + EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM"); err = EMAIL_ERROR_INVALID_PARAM; goto FINISH_OFF; } - + email_account_t* ref_account = emdaemon_get_account_reference(input_mail_data->account_id); if (!ref_account) { EM_DEBUG_LOG(" emdaemon_get_account_reference failed [%d]", input_mail_data->account_id); err = EMAIL_ERROR_INVALID_ACCOUNT; goto FINISH_OFF; } - + if ((err = emcore_add_mail(input_mail_data, input_attachment_data_list, input_attachment_count, input_meeting_request, input_from_eas)) != EMAIL_ERROR_NONE) { EM_DEBUG_EXCEPTION("emcore_add_mail failed [%d]", err); goto FINISH_OFF; @@ -272,7 +272,7 @@ FINISH_OFF: EM_DEBUG_FUNC_END("err [%d]", err); return err; } - + INTERNAL_FUNC int emdaemon_add_meeting_request(int account_id, int input_mailbox_id, email_meeting_request_t *meeting_req, int* err_code) { @@ -281,22 +281,22 @@ INTERNAL_FUNC int emdaemon_add_meeting_request(int account_id, int input_mailbox /* default variable */ int ret = false; int err = EMAIL_ERROR_NONE; - + if ( account_id <= 0 || !meeting_req || meeting_req->mail_id <= 0 ) { if(meeting_req) EM_DEBUG_EXCEPTION("mail_id[%d]", meeting_req->mail_id); - + err = EMAIL_ERROR_INVALID_PARAM; goto FINISH_OFF; } - + if (!emcore_add_meeting_request(account_id, input_mailbox_id, meeting_req, &err)) { EM_DEBUG_EXCEPTION(" emcore_save_mail_meeting_request failed [%d]", err); goto FINISH_OFF; } ret = true; - + FINISH_OFF: if (err_code) *err_code = err; @@ -307,37 +307,37 @@ FINISH_OFF: INTERNAL_FUNC int emdaemon_download_body(int account_id, int mail_id, int verbose, int with_attachment, int *handle, int* err_code) { EM_DEBUG_FUNC_BEGIN("account_id[%d], mail_id[%d], verbose[%d], with_attachment[%d], handle[%p], err_code[%p]", account_id, mail_id, verbose, with_attachment, handle, err_code); - + /* default variable */ int ret = false; int err = EMAIL_ERROR_NONE; /* mpNewMail_StopAlertSound(); */ - + if (!_emdaemon_check_mail_id(mail_id, &err)) { EM_DEBUG_EXCEPTION("_emdaemon_check_mail_id failed [%d]", err); goto FINISH_OFF; } - + email_event_t event_data; - + memset(&event_data, 0x00, sizeof(email_event_t)); - + event_data.type = EMAIL_EVENT_DOWNLOAD_BODY; event_data.event_param_data_4 = mail_id; event_data.account_id = account_id; event_data.event_param_data_3 = GINT_TO_POINTER(verbose << 1 | with_attachment); - + if (!emcore_insert_event(&event_data, (int*)handle, &err)) { EM_DEBUG_EXCEPTION("emcore_insert_event failed [%d]", err); err = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; } -#ifdef __FEATURE_LOCAL_ACTIVITY__ +#ifdef __FEATURE_LOCAL_ACTIVITY__ EM_DEBUG_LOG("Setting g_local_activity_run "); - g_local_activity_run = 1; + g_local_activity_run = 1; #endif ret = true; - + FINISH_OFF: if (err_code) *err_code = err; @@ -348,24 +348,24 @@ FINISH_OFF: int emdaemon_get_attachment(int attachment_id, email_attachment_data_t** attachment, int* err_code) { EM_DEBUG_FUNC_BEGIN("attachment_id[%d], attachment[%p], err_code[%p]", attachment_id, attachment, err_code); - + /* default variable */ int ret = false; int err = EMAIL_ERROR_NONE; - + if (!attachment_id || !attachment) { EM_DEBUG_EXCEPTION("mail_id[%d], attachment_id[%d], attachment[%p]\n", attachment_id, attachment); err = EMAIL_ERROR_INVALID_PARAM; goto FINISH_OFF; } - + if (!emcore_get_attachment_info(attachment_id, attachment, &err) || !attachment) { EM_DEBUG_EXCEPTION("emcore_get_attachment_info failed [%d]", err); goto FINISH_OFF; } - + ret = true; - + FINISH_OFF: if (err_code) *err_code = err; @@ -376,7 +376,7 @@ FINISH_OFF: int emdaemon_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); - + /* default variable */ int ret = false; int err = EMAIL_ERROR_NONE; @@ -396,7 +396,7 @@ int emdaemon_add_attachment(int mail_id, email_attachment_data_t* attachment, in EM_DEBUG_EXCEPTION(" emcore_mail_add_attachment failed [%d]", err); goto FINISH_OFF; } - + ret = true; FINISH_OFF: @@ -409,24 +409,24 @@ FINISH_OFF: int emdaemon_delete_mail_attachment(int attachment_id, int* err_code) { EM_DEBUG_FUNC_BEGIN("attachment_id[%d], err_code[%p]", attachment_id, err_code); - + /* default variable */ int ret = false; int err = EMAIL_ERROR_NONE; - + if (!attachment_id) { EM_DEBUG_EXCEPTION("attachment_id[%d]", attachment_id); err = EMAIL_ERROR_INVALID_PARAM; goto FINISH_OFF; } - + if (!emcore_delete_mail_attachment(attachment_id, &err)) { EM_DEBUG_EXCEPTION(" emcore_delete_mail_attachment failed [%d]", err); goto FINISH_OFF; } - + ret = true; - + FINISH_OFF: if (err_code) *err_code = err; @@ -437,46 +437,46 @@ FINISH_OFF: INTERNAL_FUNC int emdaemon_download_attachment(int account_id, int mail_id, int nth, int *handle, int* err_code) { EM_DEBUG_FUNC_BEGIN("account_id[%d], mail_id[%d], nth[%d], handle[%p], err_code[%p]", account_id, mail_id, nth, handle, err_code); - + int ret = false; int err = EMAIL_ERROR_NONE; - + if (!nth) { EM_DEBUG_EXCEPTION("nth[%p] is invalid", nth); err = EMAIL_ERROR_INVALID_PARAM; goto FINISH_OFF; } - + if (!_emdaemon_check_mail_id(mail_id, &err)) { EM_DEBUG_EXCEPTION("_emdaemon_check_mail_id failed [%d]", err); goto FINISH_OFF; } - + email_event_t event_data; - + memset(&event_data, 0x00, sizeof(email_event_t)); - + event_data.type = EMAIL_EVENT_DOWNLOAD_ATTACHMENT; event_data.account_id = account_id; event_data.event_param_data_4 = mail_id; event_data.event_param_data_5 = nth; - + if (!emcore_insert_event(&event_data, (int*)handle, &err)) { EM_DEBUG_EXCEPTION("emcore_insert_event failed [%d]", err); goto FINISH_OFF; } -#ifdef __FEATURE_LOCAL_ACTIVITY__ +#ifdef __FEATURE_LOCAL_ACTIVITY__ EM_DEBUG_LOG("Setting g_local_activity_run "); - g_local_activity_run = 1; + g_local_activity_run = 1; #endif ret = true; - + FINISH_OFF: if (err_code) *err_code = err; - + return ret; } @@ -507,7 +507,7 @@ void* thread_func_to_delete_mail(void *thread_argument) EM_DEBUG_EXCEPTION(" emcore_delete_mail failed [%d]", err); goto FINISH_OFF; } - + if (from_server == EMAIL_DELETE_LOCAL_AND_SERVER || from_server == EMAIL_DELETE_FROM_SERVER) { if (!emcore_insert_event(event_data, (int*)handle, &err)) { EM_DEBUG_EXCEPTION("emcore_insert_event failed [%d]", err); @@ -515,7 +515,7 @@ void* thread_func_to_delete_mail(void *thread_argument) } } -FINISH_OFF: +FINISH_OFF: /* emcore_free_event(event_data); */ /* all of members will be freed after using in each event handler */ EM_SAFE_FREE(event_data->event_param_data_3); /*prevent 33692*/ EM_SAFE_FREE(event_data); @@ -527,7 +527,7 @@ FINISH_OFF: INTERNAL_FUNC int emdaemon_delete_mail(int mailbox_id, int mail_ids[], int mail_ids_count, int from_server, int *handle, int* err_code) { EM_DEBUG_FUNC_BEGIN("mailbox_id[%d], mail_ids[%p], mail_ids_count[%d], from_server[%d], handle[%p], err_code[%p]", mailbox_id, mail_ids, mail_ids_count, from_server, handle, err_code); - + int ret = false; int err = EMAIL_ERROR_NONE; int* p = NULL, thread_error; @@ -542,7 +542,7 @@ INTERNAL_FUNC int emdaemon_delete_mail(int mailbox_id, int mail_ids[], int mail_ err = EMAIL_ERROR_INVALID_PARAM; goto FINISH_OFF; } - + if ( (err = emstorage_get_mailbox_by_id(mailbox_id, &mailbox_tbl_data)) != EMAIL_ERROR_NONE) { EM_DEBUG_EXCEPTION("emstorage_get_mailbox_by_id failed [%err]", err); goto FINISH_OFF; @@ -553,7 +553,7 @@ INTERNAL_FUNC int emdaemon_delete_mail(int mailbox_id, int mail_ids[], int mail_ err = EMAIL_ERROR_OUT_OF_MEMORY; goto FINISH_OFF; } - + memcpy(p, mail_ids, sizeof(int) * mail_ids_count); if ((event_data = em_malloc(sizeof(email_event_t)) ) == NULL) { @@ -591,22 +591,22 @@ FINISH_OFF: if (ret == false) EM_SAFE_FREE(p); - + if (err_code) *err_code = err; - + return ret; } int emdaemon_delete_mail_all(int input_mailbox_id, int input_from_server, int *output_handle, int *output_err_code) { EM_DEBUG_FUNC_BEGIN("input_mailbox_id[%d], input_from_server[%d], handle[%p], err_code[%p]", input_mailbox_id, input_from_server, output_handle, output_err_code); - + int ret = false; int err = EMAIL_ERROR_NONE; emstorage_mailbox_tbl_t *mailbox_tbl = NULL; email_event_t event_data = { 0 }; - + if (!input_mailbox_id) { EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM"); err = EMAIL_ERROR_INVALID_PARAM; @@ -617,7 +617,7 @@ int emdaemon_delete_mail_all(int input_mailbox_id, int input_from_server, int *o EM_DEBUG_EXCEPTION("emstorage_get_mailbox_by_id failed [%d]", err); goto FINISH_OFF; } - + if(!emcore_delete_all_mails_of_mailbox(mailbox_tbl->account_id, input_mailbox_id, EMAIL_DELETE_LOCALLY, &err)) { EM_DEBUG_EXCEPTION("emcore_delete_all_mails_of_mailbox failed [%d]", err); goto FINISH_OFF; @@ -629,7 +629,7 @@ int emdaemon_delete_mail_all(int input_mailbox_id, int input_from_server, int *o event_data.account_id = mailbox_tbl->account_id; event_data.event_param_data_4 = input_mailbox_id; event_data.event_param_data_5 = input_from_server; - + if (!emcore_insert_event(&event_data, (int*)output_handle, &err)) { EM_DEBUG_EXCEPTION("emcore_insert_event falied [%d]", err); goto FINISH_OFF; @@ -640,22 +640,22 @@ int emdaemon_delete_mail_all(int input_mailbox_id, int input_from_server, int *o int *mail_ids = NULL; emstorage_activity_tbl_t new_activity; int activityid = 0; - + if (false == emcore_get_next_activity_id(&activityid,&err)) { EM_DEBUG_EXCEPTION(" emcore_get_next_activity_id Failed - %d ", err); } - + if (!emstorage_mail_search_start(NULL, mailbox->account_id, mailbox->mailbox_name, 0, &search_handle, &total, true, &err)) { EM_DEBUG_EXCEPTION(" emstorage_mail_search_start failed [%d]", err); - - + + goto FINISH_OFF; } mail_ids = em_malloc(sizeof(int) * total); if (mail_ids == NULL) { EM_DEBUG_EXCEPTION(" mailloc failed..."); - + err = EMAIL_ERROR_OUT_OF_MEMORY; goto FINISH_OFF; } @@ -664,7 +664,7 @@ int emdaemon_delete_mail_all(int input_mailbox_id, int input_from_server, int *o if (!emstorage_mail_search_result(search_handle, RETRIEVE_ID, (void**)&mail_ids[i], true, &err)) { EM_DEBUG_EXCEPTION(" emstorage_mail_search_result failed [%d]", err); - + EM_SAFE_FREE(mail_ids); goto FINISH_OFF; } @@ -689,11 +689,11 @@ int emdaemon_delete_mail_all(int input_mailbox_id, int input_from_server, int *o #endif } #endif /* __FEATURE_SYNC_CLIENT_TO_SERVER__ */ - + ret = true; - + FINISH_OFF: - + if (mailbox_tbl) emstorage_free_mailbox(&mailbox_tbl, 1, NULL); @@ -709,7 +709,6 @@ void* thread_func_to_move_mail(void *thread_argument) int *mail_ids = NULL, mail_ids_count, noti_param_1, noti_param_2, err; int handle = 0; email_event_t *event_data = (email_event_t*)thread_argument; - char *dst_mailbox_name = NULL; int dst_mailbox_id = 0; /* dst_mailbox_name = (char*)event_data->event_param_data_1; */ /*prevent 33693*/ @@ -741,7 +740,7 @@ FINISH_OFF: INTERNAL_FUNC int emdaemon_move_mail_all_mails(int src_mailbox_id, int dst_mailbox_id, int* err_code) { EM_DEBUG_FUNC_BEGIN("src_mailbox_id[%d], dst_mailbox_id[%d], err_code[%p]", src_mailbox_id, dst_mailbox_id, err_code); - + int ret = false; int err = EMAIL_ERROR_NONE; int select_num = 0; @@ -756,13 +755,13 @@ INTERNAL_FUNC int emdaemon_move_mail_all_mails(int src_mailbox_id, int dst_mailb thread_t move_thread; emstorage_mailbox_tbl_t *dst_mailbox_tbl = NULL; emstorage_mailbox_tbl_t *src_mailbox_tbl = NULL; - + if ( dst_mailbox_id <= 0|| src_mailbox_id <= 0) { EM_DEBUG_EXCEPTION("Invalid Parameter"); err = EMAIL_ERROR_INVALID_PARAM; goto FINISH_OFF; } - + if ((err = emstorage_get_mailbox_by_id(dst_mailbox_id, &dst_mailbox_tbl)) != EMAIL_ERROR_NONE || !dst_mailbox_tbl) { EM_DEBUG_EXCEPTION("emstorage_get_mailbox_by_id failed. [%d]", err); goto FINISH_OFF; @@ -795,7 +794,7 @@ INTERNAL_FUNC int emdaemon_move_mail_all_mails(int src_mailbox_id, int dst_mailb } memset(mails, 0x00, sizeof(int) * select_num); - + for(i = 0 ; i < select_num ; i++) { if( mail_list[i].save_status != EMAIL_MAIL_STATUS_SENDING ) { mails[num] = mail_list[i].mail_id; @@ -806,9 +805,9 @@ INTERNAL_FUNC int emdaemon_move_mail_all_mails(int src_mailbox_id, int dst_mailb if( num <= 0) { EM_DEBUG_EXCEPTION("can't find avalable mails. num = %d", num); err = EMAIL_ERROR_MAIL_NOT_FOUND; - goto FINISH_OFF; + goto FINISH_OFF; } - + if ((event_data = em_malloc(sizeof(email_event_t)) ) == NULL) { EM_DEBUG_EXCEPTION("em_malloc for event_data failed..."); err = EMAIL_ERROR_OUT_OF_MEMORY; @@ -853,7 +852,7 @@ INTERNAL_FUNC int emdaemon_move_mail_all_mails(int src_mailbox_id, int dst_mailb THREAD_CREATE(move_thread, thread_func_to_move_mail, (void*)event_data, thread_error); THREAD_DETACH(move_thread); /* free resources used for new thread */ ret = true; - + FINISH_OFF: #ifdef __FEATURE_LOCAL_ACTIVITY__ @@ -884,7 +883,7 @@ FINISH_OFF: INTERNAL_FUNC int emdaemon_move_mail(int mail_ids[], int num, int dst_mailbox_id, int noti_param_1, int noti_param_2, int* err_code) { 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 ret = false, err = EMAIL_ERROR_NONE; @@ -900,7 +899,7 @@ INTERNAL_FUNC int emdaemon_move_mail(int mail_ids[], int num, int dst_mailbox_id err = EMAIL_ERROR_INVALID_PARAM; goto FINISH_OFF; } - + if ((err = emstorage_get_mailbox_by_id(dst_mailbox_id, &dest_mailbox_tbl)) != EMAIL_ERROR_NONE || !dest_mailbox_tbl) { EM_DEBUG_EXCEPTION("emstorage_get_mailbox_by_id failed. [%d]", err); goto FINISH_OFF; @@ -922,7 +921,7 @@ INTERNAL_FUNC int emdaemon_move_mail(int mail_ids[], int num, int dst_mailbox_id goto FINISH_OFF; } - + if (src_mailbox_id == 0) src_mailbox_id = mail_table_data->mailbox_id; @@ -941,7 +940,7 @@ INTERNAL_FUNC int emdaemon_move_mail(int mail_ids[], int num, int dst_mailbox_id } memcpy(p, mail_ids, sizeof(int) * num); - + event_data->account_id = dest_mailbox_tbl->account_id; event_data->type = EMAIL_EVENT_MOVE_MAIL; event_data->event_param_data_3 = (char*)p; @@ -953,10 +952,10 @@ INTERNAL_FUNC int emdaemon_move_mail(int mail_ids[], int num, int dst_mailbox_id #ifdef __FEATURE_LOCAL_ACTIVITY__ int i = 0, activityid = 0; - + if (false == emcore_get_next_activity_id(&activityid,&err)) EM_DEBUG_EXCEPTION(" emcore_get_next_activity_id Failed - %d ", err); - + for (i =0; i < event_data.event_param_data_4; i++) { emstorage_activity_tbl_t new_activity; new_activity.activity_id = activityid; @@ -974,12 +973,12 @@ INTERNAL_FUNC int emdaemon_move_mail(int mail_ids[], int num, int dst_mailbox_id THREAD_CREATE(move_thread, thread_func_to_move_mail, (void*)event_data, thread_error); THREAD_DETACH(move_thread); /* free resources used for new thread */ ret = true; - + FINISH_OFF: -#ifdef __FEATURE_LOCAL_ACTIVITY__ +#ifdef __FEATURE_LOCAL_ACTIVITY__ EM_DEBUG_LOG("Setting g_local_activity_run "); - g_local_activity_run = 1; + g_local_activity_run = 1; #endif /* __FEATURE_LOCAL_ACTIVITY__ */ if (err_code) @@ -995,7 +994,7 @@ FINISH_OFF: INTERNAL_FUNC int emdaemon_set_flags_field(int account_id, int mail_ids[], int num, email_flags_field_type field_type, int value, int onserver, int* err_code) { EM_DEBUG_FUNC_BEGIN("mail_ids[%d], num[%d], field_type [%d], value[%d], err_code[%p]", mail_ids[0], num, field_type, value, err_code); - + int ret = false, err = EMAIL_ERROR_NONE; emstorage_account_tbl_t *account_tbl = NULL; @@ -1021,7 +1020,7 @@ INTERNAL_FUNC int emdaemon_set_flags_field(int account_id, int mail_ids[], int n int handle = 0; mail_id_array = em_malloc(sizeof(int) * num); - + if (mail_id_array == NULL) { EM_DEBUG_EXCEPTION("em_malloc failed..."); err = EMAIL_ERROR_OUT_OF_MEMORY; @@ -1029,7 +1028,7 @@ INTERNAL_FUNC int emdaemon_set_flags_field(int account_id, int mail_ids[], int n } memcpy(mail_id_array, mail_ids, sizeof(int) * num); - + event_data.type = EMAIL_EVENT_SYNC_FLAGS_FIELD_TO_SERVER; event_data.account_id = account_id; event_data.event_param_data_1 = NULL; @@ -1045,7 +1044,7 @@ INTERNAL_FUNC int emdaemon_set_flags_field(int account_id, int mail_ids[], int n } ret = true; - + FINISH_OFF: if (account_tbl) @@ -1066,21 +1065,21 @@ INTERNAL_FUNC int emdaemon_update_mail(email_mail_data_t *input_mail_data, email int handle = 0; email_event_t event_data = { 0 }; email_account_t *ref_account = NULL; - + if (!input_mail_data || input_mail_data->account_id <= 0 || input_mail_data->mail_id == 0 || (((input_mail_data->report_status & EMAIL_MAIL_REPORT_MDN) != 0) && !input_mail_data->full_address_to)) { - EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM"); + EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM"); err = EMAIL_ERROR_INVALID_PARAM; goto FINISH_OFF; } - + ref_account = emdaemon_get_account_reference(input_mail_data->account_id); if (!ref_account) { EM_DEBUG_LOG(" emdaemon_get_account_reference failed [%d]", input_mail_data->account_id); err = EMAIL_ERROR_INVALID_ACCOUNT; goto FINISH_OFF; } - + if ( (err = emcore_update_mail(input_mail_data, input_attachment_data_list, input_attachment_count, input_meeting_request, input_from_eas)) != EMAIL_ERROR_NONE) { EM_DEBUG_EXCEPTION("emcore_update_mail failed [%d]", err); goto FINISH_OFF; @@ -1104,7 +1103,7 @@ INTERNAL_FUNC int emdaemon_update_mail(email_mail_data_t *input_mail_data, email } #endif - + FINISH_OFF: EM_DEBUG_FUNC_END("err [%d]", err); @@ -1115,23 +1114,23 @@ FINISH_OFF: int _emdaemon_check_mail_id(int mail_id, int* err_code) { EM_DEBUG_FUNC_BEGIN("mail_id[%d], err_code[%p]", mail_id, err_code); - + int ret = false; int err = EMAIL_ERROR_NONE; - + emstorage_mail_tbl_t* mail = NULL; - + if (!emstorage_get_mail_field_by_id(mail_id, RETRIEVE_SUMMARY, &mail, true, &err)) { EM_DEBUG_EXCEPTION("emstorage_get_mail_field_by_id failed [%d]", err); goto FINISH_OFF; } - + ret = true; FINISH_OFF: if (mail != NULL) emstorage_free_mail(&mail, 1, NULL); - + if (err_code != NULL) *err_code = err; EM_DEBUG_FUNC_END(); @@ -1149,13 +1148,13 @@ INTERNAL_FUNC int emdaemon_send_mail_retry(int mail_id, int timeout_in_sec, int if (!_emdaemon_check_mail_id(mail_id, &err)) { EM_DEBUG_EXCEPTION("_emdaemon_check_mail_id failed [%d]", err); goto FINISH_OFF; - } - + } + if ( timeout_in_sec == 0 ) { if(!emdaemon_send_mail(mail_id, NULL, &err)) { EM_DEBUG_EXCEPTION("emdaemon_send_mail failed [%d]", err); goto FINISH_OFF; - } + } } else if ( timeout_in_sec > 0 ) { sprintf(mail_id_string,"%d",mail_id); @@ -1170,7 +1169,7 @@ INTERNAL_FUNC int emdaemon_send_mail_retry(int mail_id, int timeout_in_sec, int FINISH_OFF: if (err_code) *err_code = err; - + return ret; } @@ -1187,19 +1186,19 @@ INTERNAL_FUNC void _OnMailSendRetryTimerCB( void* data ) } mail_id = atoi((char*)data); - + if (!_emdaemon_check_mail_id(mail_id, &err)) { EM_DEBUG_EXCEPTION("_emdaemon_check_mail_id failed [%d]", err); goto FINISH_OFF; - } - + } + if(!emdaemon_send_mail(mail_id, NULL, &err)) { EM_DEBUG_EXCEPTION("emdaemon_send_mail failed [%d]", err); goto FINISH_OFF; } FINISH_OFF: - + EM_DEBUG_FUNC_END(); return; } @@ -1225,9 +1224,9 @@ INTERNAL_FUNC int emdaemon_move_mail_thread_to_mailbox(int thread_id, int target goto FINISH_OFF; } - + mail_id_list = em_malloc(sizeof(int) * result_count); - + if (mail_id_list == NULL) { EM_DEBUG_EXCEPTION("em_malloc failed..."); err = EMAIL_ERROR_OUT_OF_MEMORY; @@ -1262,13 +1261,13 @@ INTERNAL_FUNC int emdaemon_move_mail_thread_to_mailbox(int thread_id, int target EM_DEBUG_EXCEPTION("emdaemon_move_mail failed [%d]", err); goto FINISH_OFF; } - + SNPRINTF(mailbox_id_param_string, 10, "%d", target_mailbox->mailbox_id); - if (!emcore_notify_storage_event(NOTI_THREAD_MOVE, account_id, thread_id, mailbox_id_param_string, move_always_flag)) + if (!emcore_notify_storage_event(NOTI_THREAD_MOVE, account_id, thread_id, mailbox_id_param_string, move_always_flag)) EM_DEBUG_EXCEPTION(" emcore_notify_storage_event Failed [NOTI_MAIL_MOVE] >>>> "); ret = true; - + FINISH_OFF: emcore_free_mailbox_list(&target_mailbox_list, mailbox_count); EM_SAFE_FREE(mail_list); @@ -1294,9 +1293,9 @@ INTERNAL_FUNC int emdaemon_delete_mail_thread(int thread_id, int delete_always_f goto FINISH_OFF; } - + mail_id_list = em_malloc(sizeof(int) * result_count); - + if (mail_id_list == NULL) { EM_DEBUG_EXCEPTION("em_malloc failed..."); err = EMAIL_ERROR_OUT_OF_MEMORY; @@ -1310,18 +1309,18 @@ INTERNAL_FUNC int emdaemon_delete_mail_thread(int thread_id, int delete_always_f account_id = mail_list[0].account_id; mailbox_id = mail_list[0].mailbox_id; - // should remove requiring of mailbox information from this function. + // should remove requiring of mailbox information from this function. // email-service should find mailboxes itself by its mail id. if (!emdaemon_delete_mail(mailbox_id, mail_id_list, result_count, false, handle, &err)) { EM_DEBUG_EXCEPTION("emdaemon_delete_mail failed [%d]", err); goto FINISH_OFF; } - if (!emcore_notify_storage_event(NOTI_THREAD_DELETE, account_id, thread_id, NULL, delete_always_flag)) + if (!emcore_notify_storage_event(NOTI_THREAD_DELETE, account_id, thread_id, NULL, delete_always_flag)) EM_DEBUG_EXCEPTION(" emcore_notify_storage_event Failed [NOTI_THREAD_DELETE] >>>> "); ret = true; - + FINISH_OFF: EM_SAFE_FREE(mail_list); EM_SAFE_FREE(mail_id_list); @@ -1345,9 +1344,9 @@ INTERNAL_FUNC int emdaemon_modify_seen_flag_of_thread(int thread_id, int seen_fl goto FINISH_OFF; } - + mail_id_list = em_malloc(sizeof(int) * result_count); - + if (mail_id_list == NULL) { EM_DEBUG_EXCEPTION("em_malloc failed..."); err = EMAIL_ERROR_OUT_OF_MEMORY; @@ -1365,11 +1364,11 @@ INTERNAL_FUNC int emdaemon_modify_seen_flag_of_thread(int thread_id, int seen_fl goto FINISH_OFF; } - if (!emcore_notify_storage_event(NOTI_THREAD_MODIFY_SEEN_FLAG, account_id, thread_id, NULL, seen_flag)) + if (!emcore_notify_storage_event(NOTI_THREAD_MODIFY_SEEN_FLAG, account_id, thread_id, NULL, seen_flag)) EM_DEBUG_EXCEPTION(" emcore_notify_storage_event Failed [NOTI_MAIL_MOVE] >>>> "); ret = true; - + FINISH_OFF: EM_SAFE_FREE(mail_list); EM_SAFE_FREE(mail_id_list); diff --git a/email-daemon/email-daemon-mailbox.c b/email-daemon/email-daemon-mailbox.c index 18b7563..b4c32a4 100755 --- a/email-daemon/email-daemon-mailbox.c +++ b/email-daemon/email-daemon-mailbox.c @@ -1,7 +1,7 @@ /* * email-service * -* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> * @@ -174,9 +174,9 @@ INTERNAL_FUNC int emdaemon_add_mailbox(email_mailbox_t* new_mailbox, int on_serv err = EMAIL_ERROR_INVALID_PARAM; goto FINISH_OFF; } - + email_account_t* ref_account = emdaemon_get_account_reference(new_mailbox->account_id); - + if (!ref_account) { EM_DEBUG_EXCEPTION("emdaemon_get_account_reference failed [%d]", new_mailbox->account_id); err = EMAIL_ERROR_INVALID_ACCOUNT; @@ -227,15 +227,15 @@ INTERNAL_FUNC int emdaemon_update_mailbox(email_mailbox_t* old_mailbox, email_ma /* default variable */ int ret = false;; int err = EMAIL_ERROR_NONE; - - if (!old_mailbox || old_mailbox->account_id <= 0 || !old_mailbox->mailbox_name + + if (!old_mailbox || old_mailbox->account_id <= 0 || !old_mailbox->mailbox_name || !new_mailbox || new_mailbox->account_id <= 0 || !new_mailbox->mailbox_name) { EM_DEBUG_EXCEPTION("INVALID PARAM"); if (old_mailbox != NULL) EM_DEBUG_EXCEPTION("old_mailbox->account_id[%d], old_mailbox->mailbox_name[%p]", old_mailbox->account_id, old_mailbox->mailbox_name); if (new_mailbox != NULL) EM_DEBUG_EXCEPTION("new_mailbox->account_id[%d], new_mailbox->mailbox_name[%p]", new_mailbox->account_id, new_mailbox->mailbox_name); - + err = EMAIL_ERROR_INVALID_PARAM; goto FINISH_OFF; } @@ -327,12 +327,12 @@ FINISH_OFF: INTERNAL_FUNC int emdaemon_delete_mailbox(int input_mailbox_id, int on_server, int *handle, int* err_code) { EM_DEBUG_FUNC_BEGIN("input_mailbox_id[%d], err_code[%p]", input_mailbox_id, err_code); - + /* default variable */ int ret = false; int err = EMAIL_ERROR_NONE; emstorage_mailbox_tbl_t *mailbox_tbl = NULL; - + if ((err = emstorage_get_mailbox_by_id(input_mailbox_id, &mailbox_tbl)) != EMAIL_ERROR_NONE || !mailbox_tbl) { EM_DEBUG_EXCEPTION("emstorage_get_mailbox_by_id failed. [%d]", err); goto FINISH_OFF; @@ -344,9 +344,9 @@ INTERNAL_FUNC int emdaemon_delete_mailbox(int input_mailbox_id, int on_server, i err = EMAIL_ERROR_INVALID_PARAM; goto FINISH_OFF; } - + email_account_t* ref_account = emdaemon_get_account_reference(mailbox_tbl->account_id); - + if (!ref_account) { EM_DEBUG_EXCEPTION("emdaemon_get_account_reference failed [%d]", mailbox_tbl->account_id); @@ -433,14 +433,14 @@ FINISH_OFF: INTERNAL_FUNC int emdaemon_sync_header(int input_account_id, int input_mailbox_id, int *handle, int* err_code) { EM_DEBUG_FUNC_BEGIN("input_account_id[%d], input_mailbox_id[%d], handle[%p], err_code[%p]", input_account_id, input_mailbox_id, handle, err_code); - + /* default variable */ int ret = false; int err = EMAIL_ERROR_NONE; - + email_event_t event_data; email_account_t* ref_account = NULL; - + memset(&event_data, 0x00, sizeof(email_event_t)); if (input_mailbox_id < 0) { @@ -457,14 +457,14 @@ INTERNAL_FUNC int emdaemon_sync_header(int input_account_id, int input_mailbox_i /* In case of Mailbox NULL, we need to set arg as EMAIL_SYNC_ALL_MAILBOX */ if (input_mailbox_id == 0) event_data.event_param_data_4 = EMAIL_SYNC_ALL_MAILBOX; - + if (!emcore_insert_event(&event_data, (int*)handle, &err)) { EM_DEBUG_EXCEPTION("emcore_insert_event falied [%d]", err); goto FINISH_OFF; } } else { - + if (!(ref_account = emdaemon_get_account_reference(input_account_id))) { EM_DEBUG_EXCEPTION("emdaemon_get_account_reference failed [%d]", input_account_id); err = EMAIL_ERROR_INVALID_ACCOUNT; diff --git a/email-daemon/include/email-daemon-account.h b/email-daemon/include/email-daemon-account.h index 04f5836..b012586 100755 --- a/email-daemon/include/email-daemon-account.h +++ b/email-daemon/include/email-daemon-account.h @@ -1,7 +1,7 @@ /* * email-service * -* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> * diff --git a/email-daemon/include/email-daemon-auto-poll.h b/email-daemon/include/email-daemon-auto-poll.h index be30041..b165b18 100755 --- a/email-daemon/include/email-daemon-auto-poll.h +++ b/email-daemon/include/email-daemon-auto-poll.h @@ -1,7 +1,7 @@ /* * email-service * -* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> * diff --git a/email-daemon/include/email-daemon-emn.h b/email-daemon/include/email-daemon-emn.h index b11dc4d..a91bb65 100755 --- a/email-daemon/include/email-daemon-emn.h +++ b/email-daemon/include/email-daemon-emn.h @@ -1,7 +1,7 @@ /* * email-service * -* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> * diff --git a/email-daemon/include/email-daemon-init.h b/email-daemon/include/email-daemon-init.h index ad183c3..74760fc 100755 --- a/email-daemon/include/email-daemon-init.h +++ b/email-daemon/include/email-daemon-init.h @@ -1,7 +1,7 @@ /* * email-service * -* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> * diff --git a/email-daemon/include/email-daemon-mutex.h b/email-daemon/include/email-daemon-mutex.h index 0ab2cd8..3917473 100755 --- a/email-daemon/include/email-daemon-mutex.h +++ b/email-daemon/include/email-daemon-mutex.h @@ -1,7 +1,7 @@ /* * email-service * -* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> * diff --git a/email-daemon/include/email-daemon.h b/email-daemon/include/email-daemon.h index a7b37ef..0decfb2 100755 --- a/email-daemon/include/email-daemon.h +++ b/email-daemon/include/email-daemon.h @@ -1,7 +1,7 @@ /* * email-service * -* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> * diff --git a/email-daemon/main.c b/email-daemon/main.c index 8ed2f0e..005513a 100755 --- a/email-daemon/main.c +++ b/email-daemon/main.c @@ -1,7 +1,7 @@ /* * email-service * -* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> * @@ -870,7 +870,7 @@ void stb_get_rule(HIPC_API a_hAPI) if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, local_rule_stream, size)) EM_DEBUG_EXCEPTION("emipc_add_parameter failed "); - EM_SAFE_FREE( local_rule_stream ); + EM_SAFE_FREE(local_rule_stream); emcore_free_rule(rule); EM_SAFE_FREE(rule); } @@ -1130,19 +1130,19 @@ void stb_add_mail(HIPC_API a_hAPI) /* attachment */ if (result_mail_data.attachment_count > 0) { - buffer_size = emipc_get_nth_parameter_length(a_hAPI, ePARAMETER_IN, param_index); - EM_DEBUG_LOG("email_attachment_data_t buffer_size[%d]", buffer_size); + buffer_size = emipc_get_nth_parameter_length(a_hAPI, ePARAMETER_IN, param_index); + EM_DEBUG_LOG("email_attachment_data_t buffer_size[%d]", buffer_size); - if(buffer_size > 0) { - char *stream = (char*) emipc_get_nth_parameter_data(a_hAPI, ePARAMETER_IN, param_index); - em_convert_byte_stream_to_attachment_data(stream, buffer_size, &result_attachment_data, &result_attachment_data_count); + if(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); + EM_DEBUG_LOG("result_attachment_data_count[%d]", result_attachment_data_count); - if(result_attachment_data_count && !result_attachment_data) { - EM_DEBUG_EXCEPTION("em_convert_byte_stream_to_attachment_data failed"); - err = EMAIL_ERROR_ON_PARSING; - goto FINISH_OFF; + if(result_attachment_data_count && !result_attachment_data) { + EM_DEBUG_EXCEPTION("em_convert_byte_stream_to_attachment_data failed"); + err = EMAIL_ERROR_ON_PARSING; + goto FINISH_OFF; } } } @@ -2697,7 +2697,6 @@ void* thread_func_EMAIL_ASYNC_TASK_DELETE_MAILBOX_EX(void *input_param) EM_DEBUG_FUNC_BEGIN("input_param [%p]", input_param); int err = EMAIL_ERROR_NONE; int err_for_signal = EMAIL_ERROR_NONE; - int i = 0; int task_id = THREAD_SELF(); task_parameter_EMAIL_ASYNC_TASK_DELETE_MAILBOX_EX *task_param = input_param; @@ -2709,9 +2708,6 @@ void* thread_func_EMAIL_ASYNC_TASK_DELETE_MAILBOX_EX(void *input_param) EM_DEBUG_EXCEPTION("emcore_delete_mailbox_ex failed[%d]", err); goto FINISH_OFF; } - /* Send progress signal */ - if((err_for_signal = emcore_send_task_status_signal(EMAIL_ASYNC_TASK_DELETE_MAILBOX_EX, task_id, EMAIL_TASK_STATUS_IN_PROGRESS, i, task_param->mailbox_id_count)) != EMAIL_ERROR_NONE) - EM_DEBUG_LOG("emcore_send_task_status_signal failed [%d]", err_for_signal); FINISH_OFF: /* Send finish signal */ @@ -2783,6 +2779,92 @@ FINISH_OFF: EM_DEBUG_FUNC_END("err [%d]", err); } +void* thread_func_EMAIL_ASYNC_TASK_SEND_MAIL_WITH_DOWNLOADING_ATTACHMENT_OF_ORIGINAL_MAIL(void *input_param) +{ + EM_DEBUG_FUNC_BEGIN("input_param [%p]", input_param); + int err = EMAIL_ERROR_NONE; + int err_for_signal = EMAIL_ERROR_NONE; + int task_id = THREAD_SELF(); + task_parameter_EMAIL_ASYNC_TASK_SEND_MAIL_WITH_DOWNLOADING_ATTACHMENT_OF_ORIGINAL_MAIL *task_param = input_param; + + /* Send start signal */ + if((err_for_signal = emcore_send_task_status_signal(EMAIL_ASYNC_TASK_SEND_MAIL_WITH_DOWNLOADING_ATTACHMENT_OF_ORIGINAL_MAIL, task_id, EMAIL_TASK_STATUS_STARTED, EMAIL_ERROR_NONE, 0)) != EMAIL_ERROR_NONE) + EM_DEBUG_LOG("emcore_send_task_status_signal failed [%d]", err_for_signal); + + if((err = emcore_send_mail_with_downloading_attachment_of_original_mail(task_param->mail_id)) != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emcore_send_mail_with_downloading_attachment_of_original_mail failed [%d]", err); + goto FINISH_OFF; + } + +FINISH_OFF: + /* Send finish signal */ + if(err == EMAIL_ERROR_NONE) { + if((err_for_signal = emcore_send_task_status_signal(EMAIL_ASYNC_TASK_SEND_MAIL_WITH_DOWNLOADING_ATTACHMENT_OF_ORIGINAL_MAIL, task_id, EMAIL_TASK_STATUS_FINISHED, EMAIL_ERROR_NONE, 0)) != EMAIL_ERROR_NONE) + EM_DEBUG_LOG("emcore_send_task_status_signal failed [%d]", err_for_signal); + } + else { + if((err_for_signal = emcore_send_task_status_signal(EMAIL_ASYNC_TASK_SEND_MAIL_WITH_DOWNLOADING_ATTACHMENT_OF_ORIGINAL_MAIL, task_id, EMAIL_TASK_STATUS_FAILED, err, 0)) != EMAIL_ERROR_NONE) + EM_DEBUG_LOG("emcore_send_task_status_signal failed [%d]", err_for_signal); + } + + /* Free task parameter */ + EM_SAFE_FREE(task_param); + + EM_DEBUG_FUNC_END("err [%d]", err); + return SUCCESS; +} + +void stb_send_mail_with_downloading_attachment_of_original_mail(HIPC_API a_hAPI) +{ + EM_DEBUG_FUNC_BEGIN(); + int param_index = 0; + int err = EMAIL_ERROR_NONE; + int task_parameter_length = 0; + int thread_error = 0; + thread_t task_id; + char *task_parameter = NULL; + task_parameter_EMAIL_ASYNC_TASK_SEND_MAIL_WITH_DOWNLOADING_ATTACHMENT_OF_ORIGINAL_MAIL *decoded_parameter = NULL; + + /* task_parameter_length */; + task_parameter_length = emipc_get_nth_parameter_length(a_hAPI, ePARAMETER_IN, param_index); + + if(task_parameter_length <= 0) { + EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM : task_parameter_length [%d]", task_parameter_length); + err = EMAIL_ERROR_INVALID_PARAM; + goto FINISH_OFF; + } + + /* task_parameter */ + task_parameter = (char*) emipc_get_nth_parameter_data(a_hAPI, ePARAMETER_IN, param_index++); + + if((err = email_decode_task_parameter_EMAIL_ASYNC_TASK_SEND_MAIL_WITH_DOWNLOADING_ATTACHMENT_OF_ORIGINAL_MAIL(task_parameter, task_parameter_length, (void**)&decoded_parameter)) != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("email_decode_task_parameter_EMAIL_ASYNC_TASK_MOVE_MAILS_TO_MAILBOX_OF_ANOTHER_ACCOUNT failed[%d]", err); + goto FINISH_OFF; + } + + THREAD_CREATE(task_id, thread_func_EMAIL_ASYNC_TASK_SEND_MAIL_WITH_DOWNLOADING_ATTACHMENT_OF_ORIGINAL_MAIL, (void*)decoded_parameter, thread_error); + + if(thread_error != 0) { + EM_DEBUG_EXCEPTION("THREAD_CREATE failed [%d]", thread_error); + err = EMAIL_ERROR_SYSTEM_FAILURE; + goto FINISH_OFF; + } + + THREAD_DETACH(task_id); + +FINISH_OFF: + 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, &task_id, 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("err [%d]", err); +} + void stb_API_mapper(HIPC_API a_hAPI) { EM_DEBUG_FUNC_BEGIN(); @@ -3040,6 +3122,10 @@ void stb_API_mapper(HIPC_API a_hAPI) case EMAIL_ASYNC_TASK_DELETE_MAILBOX_EX : stb_delete_mailbox_ex(a_hAPI); break; + + case EMAIL_ASYNC_TASK_SEND_MAIL_WITH_DOWNLOADING_ATTACHMENT_OF_ORIGINAL_MAIL : + stb_send_mail_with_downloading_attachment_of_original_mail(a_hAPI); + break; } EM_DEBUG_FUNC_END(); } diff --git a/email-ipc/email-activation/email-dbus-activation.c b/email-ipc/email-activation/email-dbus-activation.c index 2929164..1f3d6ca 100755 --- a/email-ipc/email-activation/email-dbus-activation.c +++ b/email-ipc/email-activation/email-dbus-activation.c @@ -1,7 +1,7 @@ /*
* email-service
*
-* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
*
* Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com>
*
diff --git a/email-ipc/email-activation/include/email-dbus-activation.h b/email-ipc/email-activation/include/email-dbus-activation.h index 37b4e41..1341694 100755 --- a/email-ipc/email-activation/include/email-dbus-activation.h +++ b/email-ipc/email-activation/include/email-dbus-activation.h @@ -1,7 +1,7 @@ /*
* email-service
*
-* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
*
* Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com>
*
diff --git a/email-ipc/email-ipc-api.c b/email-ipc/email-ipc-api.c index ce84689..33fe936 100755 --- a/email-ipc/email-ipc-api.c +++ b/email-ipc/email-ipc-api.c @@ -1,7 +1,7 @@ /* * email-service * -* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> * 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 23dc135..bf8e263 100755 --- a/email-ipc/email-ipc-api/email-ipc-api-info.c +++ b/email-ipc/email-ipc-api/email-ipc-api-info.c @@ -1,7 +1,7 @@ /* * email-service * -* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> * 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 92b7ae6..388eba3 100755 --- a/email-ipc/email-ipc-api/email-ipc-param-list.c +++ b/email-ipc/email-ipc-api/email-ipc-param-list.c @@ -1,7 +1,7 @@ /* * email-service * -* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> * @@ -102,7 +102,7 @@ EXPORT_API bool emipc_parse_stream_of_param_list(emipc_param_list *param_list, v remain_len -= sizeof(int); if (remain_len > 0 && len > 0 && remain_len >= len) - emipc_add_param_to_param_list(param_list, (void*)cur, len); + emipc_add_param_to_param_list(param_list, (void*)cur, len); else { EM_DEBUG_EXCEPTION("data_len[%d] is not in the boundary of remain stream_len", len); return false; diff --git a/email-ipc/email-ipc-api/email-ipc-param.c b/email-ipc/email-ipc-api/email-ipc-param.c index b66d32a..2d9543e 100755 --- a/email-ipc/email-ipc-api/email-ipc-param.c +++ b/email-ipc/email-ipc-api/email-ipc-param.c @@ -1,7 +1,7 @@ /* * email-service * -* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> * 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 2ce7aa4..6a0b530 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 @@ -1,7 +1,7 @@ /* * email-service * -* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> * 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 5e7be71..4706596 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 @@ -1,7 +1,7 @@ /* * email-service * -* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> * diff --git a/email-ipc/email-ipc-api/include/email-ipc-param.h b/email-ipc/email-ipc-api/include/email-ipc-param.h index e80425a..7e619e1 100755 --- a/email-ipc/email-ipc-api/include/email-ipc-param.h +++ b/email-ipc/email-ipc-api/include/email-ipc-param.h @@ -1,7 +1,7 @@ /* * email-service * -* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> * diff --git a/email-ipc/email-ipc-build.c b/email-ipc/email-ipc-build.c index a554047..3f8d541 100755 --- a/email-ipc/email-ipc-build.c +++ b/email-ipc/email-ipc-build.c @@ -1,7 +1,7 @@ /* * email-service * -* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> * diff --git a/email-ipc/email-ipc-proxy.c b/email-ipc/email-ipc-proxy.c index 75d4fc8..ed11691 100755 --- a/email-ipc/email-ipc-proxy.c +++ b/email-ipc/email-ipc-proxy.c @@ -1,7 +1,7 @@ /* * email-service * -* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> * diff --git a/email-ipc/email-ipc-stub.c b/email-ipc/email-ipc-stub.c index f435d2a..2155050 100755 --- a/email-ipc/email-ipc-stub.c +++ b/email-ipc/email-ipc-stub.c @@ -1,7 +1,7 @@ /* * email-service * -* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> * diff --git a/email-ipc/email-proxy/email-proxy-callback-info.c b/email-ipc/email-proxy/email-proxy-callback-info.c index 5079b99..4f28ed6 100755 --- a/email-ipc/email-proxy/email-proxy-callback-info.c +++ b/email-ipc/email-proxy/email-proxy-callback-info.c @@ -1,7 +1,7 @@ /* * email-service * -* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> * diff --git a/email-ipc/email-proxy/email-proxy-main.c b/email-ipc/email-proxy/email-proxy-main.c index 7f49efd..5ba193e 100755 --- a/email-ipc/email-proxy/email-proxy-main.c +++ b/email-ipc/email-proxy/email-proxy-main.c @@ -1,7 +1,7 @@ /* * email-service * -* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> * diff --git a/email-ipc/email-proxy/email-proxy-socket.c b/email-ipc/email-proxy/email-proxy-socket.c index f9cf318..b4d8a8a 100644 --- a/email-ipc/email-proxy/email-proxy-socket.c +++ b/email-ipc/email-proxy/email-proxy-socket.c @@ -1,7 +1,7 @@ /* * email-service * -* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> * diff --git a/email-ipc/email-proxy/include/email-proxy-callback-info.h b/email-ipc/email-proxy/include/email-proxy-callback-info.h index 1b7b0c2..dbe8642 100755 --- a/email-ipc/email-proxy/include/email-proxy-callback-info.h +++ b/email-ipc/email-proxy/include/email-proxy-callback-info.h @@ -1,7 +1,7 @@ /* * email-service * -* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> * diff --git a/email-ipc/email-proxy/include/email-proxy-main.h b/email-ipc/email-proxy/include/email-proxy-main.h index c84dadc..b071fd4 100755 --- a/email-ipc/email-proxy/include/email-proxy-main.h +++ b/email-ipc/email-proxy/include/email-proxy-main.h @@ -1,7 +1,7 @@ /* * email-service * -* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> * diff --git a/email-ipc/email-proxy/include/email-proxy-socket.h b/email-ipc/email-proxy/include/email-proxy-socket.h index 3b62f22..cf2244b 100755 --- a/email-ipc/email-proxy/include/email-proxy-socket.h +++ b/email-ipc/email-proxy/include/email-proxy-socket.h @@ -1,7 +1,7 @@ /* * email-service * -* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> * diff --git a/email-ipc/email-socket/email-ipc-socket.c b/email-ipc/email-socket/email-ipc-socket.c index 0ff4453..55976df 100755 --- a/email-ipc/email-socket/email-ipc-socket.c +++ b/email-ipc/email-socket/email-ipc-socket.c @@ -1,7 +1,7 @@ /* * email-service * -* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> * diff --git a/email-ipc/email-socket/include/email-ipc-socket.h b/email-ipc/email-socket/include/email-ipc-socket.h index f3aef31..10bfff7 100755 --- a/email-ipc/email-socket/include/email-ipc-socket.h +++ b/email-ipc/email-socket/include/email-ipc-socket.h @@ -1,7 +1,7 @@ /* * email-service * -* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> * diff --git a/email-ipc/email-stub/email-stub-main.c b/email-ipc/email-stub/email-stub-main.c index 834ab75..523f762 100755 --- a/email-ipc/email-stub/email-stub-main.c +++ b/email-ipc/email-stub/email-stub-main.c @@ -1,7 +1,7 @@ /* * email-service * -* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> * diff --git a/email-ipc/email-stub/email-stub-socket.c b/email-ipc/email-stub/email-stub-socket.c index 247c201..2a788db 100755 --- a/email-ipc/email-stub/email-stub-socket.c +++ b/email-ipc/email-stub/email-stub-socket.c @@ -1,7 +1,7 @@ /* * email-service * -* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> * @@ -166,7 +166,7 @@ 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); + emipc_create_task((unsigned char *)sz_buf, event_fd); } else EM_DEBUG_LOG("[IPCLib] Stream size is less than default size"); } else if( recv_len == 0 ) { diff --git a/email-ipc/email-stub/email-stub-task-manager.c b/email-ipc/email-stub/email-stub-task-manager.c index 5dc0198..28ebba4 100755 --- a/email-ipc/email-stub/email-stub-task-manager.c +++ b/email-ipc/email-stub/email-stub-task-manager.c @@ -1,7 +1,7 @@ /* * email-service * -* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> * diff --git a/email-ipc/email-stub/email-stub-task.c b/email-ipc/email-stub/email-stub-task.c index b063301..eaa4c1b 100755 --- a/email-ipc/email-stub/email-stub-task.c +++ b/email-ipc/email-stub/email-stub-task.c @@ -1,7 +1,7 @@ /* * email-service * -* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> * diff --git a/email-ipc/email-stub/include/email-stub-main.h b/email-ipc/email-stub/include/email-stub-main.h index c11f148..4d26d5f 100755 --- a/email-ipc/email-stub/include/email-stub-main.h +++ b/email-ipc/email-stub/include/email-stub-main.h @@ -1,7 +1,7 @@ /* * email-service * -* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> * diff --git a/email-ipc/email-stub/include/email-stub-socket.h b/email-ipc/email-stub/include/email-stub-socket.h index 1542715..403f1d5 100755 --- a/email-ipc/email-stub/include/email-stub-socket.h +++ b/email-ipc/email-stub/include/email-stub-socket.h @@ -1,7 +1,7 @@ /* * email-service * -* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> * 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 cdc83ad..95c17df 100755 --- a/email-ipc/email-stub/include/email-stub-task-manager.h +++ b/email-ipc/email-stub/include/email-stub-task-manager.h @@ -1,7 +1,7 @@ /* * email-service * -* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> * diff --git a/email-ipc/email-stub/include/email-stub-task.h b/email-ipc/email-stub/include/email-stub-task.h index c87262b..d1d532a 100755 --- a/email-ipc/email-stub/include/email-stub-task.h +++ b/email-ipc/email-stub/include/email-stub-task.h @@ -1,7 +1,7 @@ /* * email-service * -* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> * diff --git a/email-ipc/include/email-ipc-build.h b/email-ipc/include/email-ipc-build.h index 0014b6a..f441d5d 100755 --- a/email-ipc/include/email-ipc-build.h +++ b/email-ipc/include/email-ipc-build.h @@ -1,7 +1,7 @@ /* * email-service * -* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> * diff --git a/email-ipc/include/email-ipc.h b/email-ipc/include/email-ipc.h index 493de64..f18ca3c 100755 --- a/email-ipc/include/email-ipc.h +++ b/email-ipc/include/email-ipc.h @@ -1,7 +1,7 @@ /* * email-service * -* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> * diff --git a/email-service.manifest b/email-service.manifest index fec577f..dfbc76f 100644 --- a/email-service.manifest +++ b/email-service.manifest @@ -6,11 +6,13 @@ </provide> <request> <smack request="email-service::db" type="rw"/> + <smack request="connman" type="w"/> <smack request="system::use_internet" type="w"/> </request> <permit> <smack permit="system::use_internet" type="rwx"/> <smack permit="webkit2-efl" type="rx"/> + <smack permit="connman" type="w"/> </permit> </define> <assign> diff --git a/packaging/email-service.spec b/packaging/email-service.spec index 71c0bc0..6982918 100755 --- a/packaging/email-service.spec +++ b/packaging/email-service.spec @@ -1,6 +1,6 @@ Name: email-service Summary: E-mail Framework Middleware package -Version: 0.10.20 +Version: 0.10.79 Release: 1 Group: System/Libraries License: TBD @@ -41,11 +41,11 @@ BuildRequires: pkgconfig(libcurl) BuildRequires: pkgconfig(libxml-2.0) BuildRequires: pkgconfig(gconf-2.0) BuildRequires: pkgconfig(cert-svc) +BuildRequires: pkgconfig(mdm) BuildRequires: pkgconfig(badge) BuildRequires: pkgconfig(feedback) -BuildRoot: %{_tmppath}/%{name}-%{version}-build %description E-mail Framework Middleware Library/Binary package @@ -71,36 +71,20 @@ export LDFLAGS="${LDFLAGS} -Wl,--hash-style=both -Wl,--rpath=%{_prefix}/lib -Wl, cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} -# Call make instruction with smp support -#make %{?jobs:-j%jobs} -make +make %{?_smp_mflags} %install +mkdir -p %{buildroot}/usr/share/license %make_install mkdir -p %{buildroot}%{_libdir}/systemd/user/tizen-middleware.target.wants install -m 0644 %SOURCE1 %{buildroot}%{_libdir}/systemd/user/ ln -sf ../email.service %{buildroot}%{_libdir}/systemd/user/tizen-middleware.target.wants/ -# FIXME: remove initscripts after systemd is ready -mkdir -p %{buildroot}%{_sysconfdir}/rc.d/init.d -cat << EOF > %{buildroot}%{_sysconfdir}/rc.d/init.d/email-service -#!/bin/sh -/usr/bin/email-service & -EOF - -mkdir -p %{buildroot}%{_sysconfdir}/rc.d/rc3.d -mkdir -p %{buildroot}%{_sysconfdir}/rc.d/rc5.d -ln -sf ../init.d/email-service %{buildroot}%{_sysconfdir}/rc.d/rc3.d/S70email-service -ln -sf ../init.d/email-service %{buildroot}%{_sysconfdir}/rc.d/rc5.d/S70email-service - -%clean -rm -rf %{buildroot} %post /sbin/ldconfig - ################################################################# # Add preset account information ################################################################# @@ -440,9 +424,6 @@ systemctl daemon-reload %files %manifest email-service.manifest %exclude /usr/bin/email-test-app -%attr(0755,root,root) %{_sysconfdir}/rc.d/init.d/email-service -%{_sysconfdir}/rc.d/rc3.d/S70email-service -%{_sysconfdir}/rc.d/rc5.d/S70email-service %{_bindir}/email-service /opt/usr/data/email/res/* %{_libdir}/lib*.so.* diff --git a/packaging/email.service b/packaging/email.service index 3580cb6..8d0cf15 100644 --- a/packaging/email.service +++ b/packaging/email.service @@ -1,14 +1,11 @@ + [Unit] Description=Start the Email service -After=xorg.target [Service] ExecStart=/usr/bin/email-service Nice=5 -OOMScoreAdjust=-100 -Restart=always -RestartSec=2 - +OOMScoreAdjust=100 [Install] WantedBy=tizen-middleware.target diff --git a/utilities/test-application/include/testapp-account.h b/utilities/test-application/include/testapp-account.h index 2f22aa0..1c19e78 100755 --- a/utilities/test-application/include/testapp-account.h +++ b/utilities/test-application/include/testapp-account.h @@ -1,7 +1,7 @@ /* * email-service * -* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> * diff --git a/utilities/test-application/include/testapp-mail.h b/utilities/test-application/include/testapp-mail.h index e7f3b40..3bd21fd 100755 --- a/utilities/test-application/include/testapp-mail.h +++ b/utilities/test-application/include/testapp-mail.h @@ -1,7 +1,7 @@ /* * email-service * -* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> * diff --git a/utilities/test-application/include/testapp-mailbox.h b/utilities/test-application/include/testapp-mailbox.h index 836a299..e3aae25 100755 --- a/utilities/test-application/include/testapp-mailbox.h +++ b/utilities/test-application/include/testapp-mailbox.h @@ -1,7 +1,7 @@ /* * email-service * -* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> * diff --git a/utilities/test-application/include/testapp-others.h b/utilities/test-application/include/testapp-others.h index 8c10989..9e4ce9e 100755 --- a/utilities/test-application/include/testapp-others.h +++ b/utilities/test-application/include/testapp-others.h @@ -1,7 +1,7 @@ /* * email-service * -* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> * diff --git a/utilities/test-application/include/testapp-rule.h b/utilities/test-application/include/testapp-rule.h index 61f6e4c..9fb79b7 100755 --- a/utilities/test-application/include/testapp-rule.h +++ b/utilities/test-application/include/testapp-rule.h @@ -1,7 +1,7 @@ /* * email-service * -* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> * diff --git a/utilities/test-application/include/testapp-thread.h b/utilities/test-application/include/testapp-thread.h index c3e81c5..4e8a8ec 100755 --- a/utilities/test-application/include/testapp-thread.h +++ b/utilities/test-application/include/testapp-thread.h @@ -1,7 +1,7 @@ /* * email-service * -* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> * diff --git a/utilities/test-application/include/testapp-utility.h b/utilities/test-application/include/testapp-utility.h index b88d69a..45f14e2 100755 --- a/utilities/test-application/include/testapp-utility.h +++ b/utilities/test-application/include/testapp-utility.h @@ -1,7 +1,7 @@ /* * email-service * -* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> * diff --git a/utilities/test-application/main.c b/utilities/test-application/main.c index 449d72c..7cdec48 100755 --- a/utilities/test-application/main.c +++ b/utilities/test-application/main.c @@ -1,7 +1,7 @@ /* * email-service * -* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> * diff --git a/utilities/test-application/testapp-account.c b/utilities/test-application/testapp-account.c index 2621578..b6e2fee 100755 --- a/utilities/test-application/testapp-account.c +++ b/utilities/test-application/testapp-account.c @@ -1,7 +1,7 @@ /* * email-service * -* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> * @@ -112,7 +112,7 @@ gboolean testapp_test_create_account_by_account_type(int account_type,int *accou memcpy( account->user_data, (void*) &data, data_length ); account->user_data_length = data_length; account->options.priority = 3; - account->options.keep_local_copy = 0; + account->options.keep_local_copy = 1; account->options.req_delivery_receipt = 0; account->options.req_read_receipt = 0; account->options.download_limit = 0; diff --git a/utilities/test-application/testapp-mail.c b/utilities/test-application/testapp-mail.c index d68ec59..1ee47ac 100755 --- a/utilities/test-application/testapp-mail.c +++ b/utilities/test-application/testapp-mail.c @@ -1,7 +1,7 @@ /* * email-service * -* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> * @@ -26,6 +26,7 @@ #include <string.h> #include <stdlib.h> #include <sys/stat.h> +#include <wait.h> /* open header */ #include <glib.h> @@ -44,7 +45,8 @@ #include "email-core-utils.h" #include "email-core-mime.h" -#define MAIL_TEMP_BODY "/tmp/mail.txt" +#define MAIL_TEMP_BODY "/tmp/utf8" +#define HTML_TEMP_BODY "/tmp/utf8.htm" /* static void testapp_test_print_sorting_menu() @@ -614,7 +616,7 @@ static gboolean testapp_test_get_mail_list_ex() sorting_rule_list[0].target_attribute = EMAIL_MAIL_ATTRIBUTE_DATE_TIME; sorting_rule_list[0].sort_order = EMAIL_SORT_ORDER_DESCEND; - err = email_get_mail_list_ex(filter_list, filter_rule_count, sorting_rule_list, sorting_rule_count, -1, -1, &result_mail_list, &result_mail_count); + err = email_get_mail_list_ex(filter_list, filter_rule_count, sorting_rule_list, sorting_rule_count, 0, 10, &result_mail_list, &result_mail_count); if(err == EMAIL_ERROR_NONE) { testapp_print("email_get_mail_list_ex succeed.\n"); @@ -1082,6 +1084,177 @@ static gboolean testapp_test_move_mails_to_mailbox_of_another_account() return 0; } +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; + } + testapp_print("copy_file started\n"); + + pid = fork(); + + if (pid == 0) { + testapp_print("Copying file [%s] [%s]\n", input_source_path, input_dest_path); + execl("/bin/cp", "/bin/cp", input_source_path, input_dest_path, (char *)0); + } + else { + testapp_print("Wating child process\n"); + pid_t ws = waitpid( pid, &childExitStatus, WNOHANG); + if (ws == -1) + { /* error - handle as you wish */ + testapp_print("waitpid returns error\n"); + } + + if( WIFEXITED(childExitStatus)) /* exit code in childExitStatus */ + { + status = WEXITSTATUS(childExitStatus); /* zero is normal exit */ + testapp_print("WEXITSTATUS\n"); + /* handle non-zero as you wish */ + } + else if (WIFSIGNALED(childExitStatus)) /* killed */ + { + testapp_print("WIFSIGNALED\n"); + } + else if (WIFSTOPPED(childExitStatus)) /* stopped */ + { + testapp_print("WIFSTOPPED\n"); + } + } + testapp_print("copy_file finished\n"); + return TRUE; +} + + +static gboolean testapp_test_send_mail_with_downloading_attachment_of_original_mail() +{ + 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; + char *plain_text_path = MAIL_TEMP_BODY; + char *html_file_path = HTML_TEMP_BODY; + char new_subject[4086] = { 0, }; +/* FILE *body_file; */ + email_mail_data_t *original_mail_data = NULL; + email_mailbox_t *outbox = NULL; + email_attachment_data_t *original_attachment_array = NULL; + + testapp_print("\n > Enter original mail id: "); + result_from_scanf = scanf("%d", &original_mail_id); + + /* Get original mail */ + if((err = email_get_mail_data(original_mail_id, &original_mail_data)) != EMAIL_ERROR_NONE || !original_mail_data) { + testapp_print("email_get_mail_data failed [%d]\n", err); + return FALSE; + } + + /* Get attachment of original mail */ + if((err = email_get_attachment_data_list(original_mail_id, &original_attachment_array, &original_attachment_count)) != EMAIL_ERROR_NONE || !original_attachment_array) { + testapp_print("email_get_attachment_data_list failed [%d]\n", err); + return FALSE; + } + + /* Remove attachment file path */ + for(i = 0; i < original_attachment_count; i++) { + original_attachment_array[i].save_status = 0; + if(original_attachment_array[i].attachment_path) + free(original_attachment_array[i].attachment_path); + original_attachment_array[i].attachment_path = NULL; + } + + /* Set reference mail id */ + original_mail_data->reference_mail_id = original_mail_data->mail_id; + original_mail_data->body_download_status = 1; + + /* Set from address */ + if(!original_mail_data->full_address_from) { + original_mail_data->full_address_from = strdup("<abc@abc.com>"); + } + + /* Rewrite subject */ + if(original_mail_data->subject) { + snprintf(new_subject, 4086, "Fw:%s", original_mail_data->subject); + free(original_mail_data->subject); + original_mail_data->subject = NULL; + } + else { + snprintf(new_subject, 4086, "Forward test"); + } + + original_mail_data->subject = strdup(new_subject); + + /* Set mailbox information */ + if((err = email_get_mailbox_by_mailbox_type(original_mail_data->account_id, EMAIL_MAILBOX_TYPE_OUTBOX, &outbox)) != EMAIL_ERROR_NONE || !outbox) { + testapp_print("email_get_mailbox_by_mailbox_type failed [%d]\n", err); + return FALSE; + } + original_mail_data->mailbox_id = outbox->mailbox_id; + original_mail_data->mailbox_type = outbox->mailbox_type; + + /* Copy body text */ + if(original_mail_data->file_path_html) { + copy_file(original_mail_data->file_path_html, html_file_path); + /*execl("/bin/cp", "/bin/cp", original_mail_data->file_path_html, html_file_path, (char *)0); */ + free(original_mail_data->file_path_html); + original_mail_data->file_path_html = strdup(html_file_path); + } + + if(original_mail_data->file_path_plain) { + copy_file(original_mail_data->file_path_plain, plain_text_path); + /*execl("/bin/cp", "/bin/cp", original_mail_data->file_path_plain, plain_text_path, (char *)0);*/ + free(original_mail_data->file_path_plain); + original_mail_data->file_path_plain = strdup(plain_text_path); + } + + + /* + 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); + */ + + /* Add mail */ + if((err = email_add_mail(original_mail_data, original_attachment_array, original_attachment_count, NULL, false)) != EMAIL_ERROR_NONE) { + testapp_print("email_get_attachment_data_list failed [%d]\n", err); + return FALSE; + } + + /* Send mail */ + if((err = email_send_mail_with_downloading_attachment_of_original_mail(original_mail_data->mail_id, &handle)) != EMAIL_ERROR_NONE) { + testapp_print("email_send_mail_with_downloading_attachment_of_original_mail failed [%d]\n", err); + return FALSE; + } + + if(original_mail_data) + email_free_mail_data(&original_mail_data, 1); + + if(outbox) + email_free_mailbox(&outbox, 1); + + if(original_attachment_array) + email_free_attachment_data(&original_attachment_array, original_attachment_count); + + return TRUE; +} + + + static gboolean testapp_test_set_flags_field () { int account_id = 0; @@ -1877,6 +2050,9 @@ static gboolean testapp_test_interpret_command (int menu_number) case 10: testapp_test_move_mails_to_mailbox_of_another_account(); break; + case 11: + testapp_test_send_mail_with_downloading_attachment_of_original_mail(); + break; case 14: testapp_test_delete(); break; diff --git a/utilities/test-application/testapp-mailbox.c b/utilities/test-application/testapp-mailbox.c index 768a940..915a11f 100755 --- a/utilities/test-application/testapp-mailbox.c +++ b/utilities/test-application/testapp-mailbox.c @@ -1,7 +1,7 @@ /* * email-service * -* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> * diff --git a/utilities/test-application/testapp-others.c b/utilities/test-application/testapp-others.c index f37229a..92f8e5a 100755 --- a/utilities/test-application/testapp-others.c +++ b/utilities/test-application/testapp-others.c @@ -1,7 +1,7 @@ /* * email-service * -* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> * diff --git a/utilities/test-application/testapp-rule.c b/utilities/test-application/testapp-rule.c index 45a4ea9..ca8dfed 100755 --- a/utilities/test-application/testapp-rule.c +++ b/utilities/test-application/testapp-rule.c @@ -1,7 +1,7 @@ /* * email-service * -* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> * diff --git a/utilities/test-application/testapp-thread.c b/utilities/test-application/testapp-thread.c index c035fce..34b913e 100755 --- a/utilities/test-application/testapp-thread.c +++ b/utilities/test-application/testapp-thread.c @@ -1,7 +1,7 @@ /* * email-service * -* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> * diff --git a/utilities/test-application/testapp-utility.c b/utilities/test-application/testapp-utility.c index 4a0f9f3..acf39ae 100755 --- a/utilities/test-application/testapp-utility.c +++ b/utilities/test-application/testapp-utility.c @@ -1,7 +1,7 @@ /* * email-service * -* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> * @@ -99,6 +99,7 @@ void testapp_show_menu (eEMAIL_MENU menu) testapp_print ("8. Delete attachment\n"); testapp_print ("9. Mail Count \n"); testapp_print ("10. Move mails to another account\n"); + testapp_print ("11. Send mail with downloading attachment of original mail\n"); testapp_print ("14. Delete a mail \n"); testapp_print ("16. Download mail body\n"); testapp_print ("17. Download an attachment\n"); |