summaryrefslogtreecommitdiff
path: root/email-common-use
diff options
context:
space:
mode:
Diffstat (limited to 'email-common-use')
-rwxr-xr-xemail-common-use/CMakeLists.txt3
-rwxr-xr-xemail-common-use/email-convert.c1287
-rwxr-xr-xemail-common-use/email-utilities.c1722
-rwxr-xr-xemail-common-use/include/email-convert.h65
-rwxr-xr-xemail-common-use/include/email-debug-log.h53
-rwxr-xr-xemail-common-use/include/email-errors.h260
-rwxr-xr-xemail-common-use/include/email-internal-types.h137
-rwxr-xr-xemail-common-use/include/email-types.h3091
-rwxr-xr-xemail-common-use/include/email-utilities.h136
-rw-r--r--email-common-use/include/tpl.h133
-rw-r--r--email-common-use/tpl.c2477
11 files changed, 6666 insertions, 2698 deletions
diff --git a/email-common-use/CMakeLists.txt b/email-common-use/CMakeLists.txt
index df3e34e..a1d63df 100755
--- a/email-common-use/CMakeLists.txt
+++ b/email-common-use/CMakeLists.txt
@@ -17,6 +17,7 @@ SET(COMMON-USE-LIB "email-common-use")
SET(COMMON-USE-SRCS
${CMAKE_SOURCE_DIR}/email-common-use/email-convert.c
${CMAKE_SOURCE_DIR}/email-common-use/email-utilities.c
+ ${CMAKE_SOURCE_DIR}/email-common-use/tpl.c
)
INCLUDE_DIRECTORIES(
@@ -27,7 +28,7 @@ INCLUDE_DIRECTORIES(
)
INCLUDE(FindPkgConfig)
-pkg_check_modules(common_pkgs REQUIRED glib-2.0 dlog vconf contacts-service uw-imap-toolkit)
+pkg_check_modules(common_pkgs REQUIRED glib-2.0 dlog dbus-1 vconf contacts-service uw-imap-toolkit)
FOREACH(flag ${common_pkgs_CFLAGS})
SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
diff --git a/email-common-use/email-convert.c b/email-common-use/email-convert.c
index 7b11f77..07834af 100755
--- a/email-common-use/email-convert.c
+++ b/email-common-use/email-convert.c
@@ -4,7 +4,7 @@
* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
*
* Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com>
-*
+*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@@ -28,7 +28,7 @@
#include "email-core-utils.h"
#include "email-utilities.h"
#include "email-storage.h"
-
+#include "tpl.h"
#define fSEEN 0x1
#define fDELETED 0x2
@@ -39,18 +39,18 @@
#define fATTACHMENT 0x40
#define fFORWARD 0x80
-INTERNAL_FUNC int em_convert_mail_flag_to_int(emf_mail_flag_t flag, int *i_flag, int *err_code)
+INTERNAL_FUNC int em_convert_mail_flag_to_int(email_mail_flag_t flag, int *i_flag, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("i_flag[%p], err_code[%p]", i_flag, err_code);
if (!i_flag) {
if (err_code != NULL)
- *err_code = EMF_ERROR_INVALID_PARAM;
+ *err_code = EMAIL_ERROR_INVALID_PARAM;
return false;
}
- *i_flag =
+ *i_flag =
(flag.seen ? fSEEN : 0) |
(flag.deleted ? fDELETED : 0) |
(flag.flagged ? fFLAGGED : 0) |
@@ -64,17 +64,17 @@ INTERNAL_FUNC int em_convert_mail_flag_to_int(emf_mail_flag_t flag, int *i_flag,
return true;
}
-INTERNAL_FUNC int em_convert_mail_int_to_flag(int i_flag, emf_mail_flag_t* flag, int* err_code)
+INTERNAL_FUNC int em_convert_mail_int_to_flag(int i_flag, email_mail_flag_t* flag, int* err_code)
{
EM_DEBUG_FUNC_BEGIN("i_flag[0x%02x], flag[%p], err_code[%p]", i_flag, flag, err_code);
-
+
if (!flag) {
- EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
+ EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
if (err_code != NULL)
- *err_code = EMF_ERROR_INVALID_PARAM;
+ *err_code = EMAIL_ERROR_INVALID_PARAM;
return false;
}
-
+
flag->seen = (i_flag & fSEEN ? 1 : 0);
flag->deleted = (i_flag & fDELETED ? 1 : 0);
flag->flagged = (i_flag & fFLAGGED ? 1 : 0);
@@ -93,15 +93,15 @@ INTERNAL_FUNC int em_convert_mail_int_to_flag(int i_flag, emf_mail_flag_t* flag,
INTERNAL_FUNC int em_convert_mail_tbl_to_mail_status(emstorage_mail_tbl_t *mail_tbl_data, int *result_mail_status, int* err_code)
{
EM_DEBUG_FUNC_BEGIN("mail_tbl_data[%p], result_mail_status [%p], err_code[%p]", mail_tbl_data, result_mail_status, err_code);
- int ret = false, error_code = EMF_ERROR_NONE;
+ int ret = false, error_code = EMAIL_ERROR_NONE;
int has_attachment = 0;
-
+
if(!mail_tbl_data || !result_mail_status) {
- EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
- error_code = EMF_ERROR_INVALID_PARAM;
+ EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
+ error_code = EMAIL_ERROR_INVALID_PARAM;
goto FINISH_OFF;
}
-
+
has_attachment = (mail_tbl_data->attachment_count > mail_tbl_data->inline_content_count) ? 1 : 0;
*result_mail_status = (mail_tbl_data->flags_seen_field ? fSEEN : 0) |
@@ -117,19 +117,19 @@ INTERNAL_FUNC int em_convert_mail_tbl_to_mail_status(emstorage_mail_tbl_t *mail_
FINISH_OFF:
if (err_code != NULL)
*err_code = error_code;
-
+
EM_DEBUG_FUNC_END("ret [%d]", ret);
return ret;
}
-
+
INTERNAL_FUNC int em_convert_mail_status_to_mail_tbl(int mail_status, emstorage_mail_tbl_t *result_mail_tbl_data, int* err_code)
{
EM_DEBUG_FUNC_BEGIN("mail_status[%d], result_mail_tbl_data [%p], err_code[%p]", mail_status, result_mail_tbl_data, err_code);
- int ret = false, error_code = EMF_ERROR_NONE;
+ int ret = false, error_code = EMAIL_ERROR_NONE;
if(!result_mail_tbl_data) {
- EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
- error_code = EMF_ERROR_INVALID_PARAM;
+ EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
+ error_code = EMAIL_ERROR_INVALID_PARAM;
goto FINISH_OFF;
}
@@ -145,19 +145,19 @@ INTERNAL_FUNC int em_convert_mail_status_to_mail_tbl(int mail_status, emstorage_
FINISH_OFF:
if (err_code != NULL)
*err_code = error_code;
-
+
EM_DEBUG_FUNC_END("ret [%d]", ret);
return ret;
}
-INTERNAL_FUNC int em_convert_mail_tbl_to_mail_flag(emstorage_mail_tbl_t *mail_tbl_data, emf_mail_flag_t *result_flag, int* err_code)
+INTERNAL_FUNC int em_convert_mail_tbl_to_mail_flag(emstorage_mail_tbl_t *mail_tbl_data, email_mail_flag_t *result_flag, int* err_code)
{
EM_DEBUG_FUNC_BEGIN("mail_tbl_data[%p], result_flag [%p], err_code[%p]", mail_tbl_data, result_flag, err_code);
- int ret = false, error_code = EMF_ERROR_NONE;
+ int ret = false, error_code = EMAIL_ERROR_NONE;
if(!mail_tbl_data || !result_flag) {
- EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
- error_code = EMF_ERROR_INVALID_PARAM;
+ EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
+ error_code = EMAIL_ERROR_INVALID_PARAM;
goto FINISH_OFF;
}
@@ -174,19 +174,19 @@ INTERNAL_FUNC int em_convert_mail_tbl_to_mail_flag(emstorage_mail_tbl_t *mail_tb
FINISH_OFF:
if (err_code != NULL)
*err_code = error_code;
-
+
EM_DEBUG_FUNC_END("ret [%d]", ret);
return ret;
}
-INTERNAL_FUNC int em_convert_mail_flag_to_mail_tbl(emf_mail_flag_t *flag, emstorage_mail_tbl_t *result_mail_tbl_data, int* err_code)
+INTERNAL_FUNC int em_convert_mail_flag_to_mail_tbl(email_mail_flag_t *flag, emstorage_mail_tbl_t *result_mail_tbl_data, int* err_code)
{
EM_DEBUG_FUNC_BEGIN("flag[%p], result_mail_tbl_data [%p], err_code[%p]", flag, result_mail_tbl_data, err_code);
- int ret = false, error_code = EMF_ERROR_NONE;
+ int ret = false, error_code = EMAIL_ERROR_NONE;
if(!flag || !result_mail_tbl_data) {
- EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
- error_code = EMF_ERROR_INVALID_PARAM;
+ EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
+ error_code = EMAIL_ERROR_INVALID_PARAM;
goto FINISH_OFF;
}
@@ -202,148 +202,203 @@ INTERNAL_FUNC int em_convert_mail_flag_to_mail_tbl(emf_mail_flag_t *flag, emstor
FINISH_OFF:
if (err_code != NULL)
*err_code = error_code;
-
+
EM_DEBUG_FUNC_END("ret [%d]", ret);
return ret;
}
-INTERNAL_FUNC int em_convert_account_to_account_tbl(emf_account_t *account, emstorage_account_tbl_t *account_tbl)
+INTERNAL_FUNC int em_convert_account_to_account_tbl(email_account_t *account, emstorage_account_tbl_t *account_tbl)
{
EM_DEBUG_FUNC_BEGIN("account[%p], account_tbl[%p]", account, account_tbl);
int ret = 1;
- account_tbl->account_bind_type = account->account_bind_type;
- account_tbl->account_name = EM_SAFE_STRDUP(account->account_name);
- account_tbl->receiving_server_type = account->receiving_server_type;
- account_tbl->receiving_server_addr = EM_SAFE_STRDUP(account->receiving_server_addr);
- account_tbl->email_addr = EM_SAFE_STRDUP(account->email_addr);
- account_tbl->user_name = EM_SAFE_STRDUP(account->user_name);
- account_tbl->password = EM_SAFE_STRDUP(account->password);
- account_tbl->retrieval_mode = account->retrieval_mode;
- account_tbl->port_num = account->port_num;
- account_tbl->use_security = account->use_security;
- account_tbl->sending_server_type = account->sending_server_type;
- account_tbl->sending_server_addr = EM_SAFE_STRDUP(account->sending_server_addr);
- account_tbl->sending_port_num = account->sending_port_num;
- account_tbl->sending_auth = account->sending_auth;
- account_tbl->sending_security = account->sending_security;
- account_tbl->sending_user = EM_SAFE_STRDUP(account->sending_user);
- account_tbl->sending_password = EM_SAFE_STRDUP(account->sending_password);
- account_tbl->display_name = EM_SAFE_STRDUP(account->display_name);
- account_tbl->reply_to_addr = EM_SAFE_STRDUP(account->reply_to_addr);
- account_tbl->return_addr = EM_SAFE_STRDUP(account->return_addr);
- account_tbl->account_id = account->account_id;
- account_tbl->keep_on_server = account->keep_on_server;
- account_tbl->flag1 = account->flag1;
- account_tbl->flag2 = account->flag2;
- account_tbl->pop_before_smtp = account->pop_before_smtp;
- account_tbl->apop = account->apop;
- account_tbl->logo_icon_path = EM_SAFE_STRDUP(account->logo_icon_path);
- account_tbl->preset_account = account->preset_account;
- account_tbl->options.priority = account->options.priority;
- account_tbl->options.keep_local_copy = account->options.keep_local_copy;
- account_tbl->options.req_delivery_receipt = account->options.req_delivery_receipt;
- account_tbl->options.req_read_receipt = account->options.req_read_receipt;
- account_tbl->options.download_limit = account->options.download_limit;
- account_tbl->options.block_address = account->options.block_address;
- account_tbl->options.block_subject = account->options.block_subject;
- account_tbl->options.display_name_from = EM_SAFE_STRDUP(account->options.display_name_from);
- account_tbl->options.reply_with_body = account->options.reply_with_body;
- account_tbl->options.forward_with_files = account->options.forward_with_files;
- account_tbl->options.add_myname_card = account->options.add_myname_card;
- account_tbl->options.add_signature = account->options.add_signature;
- account_tbl->options.signature = EM_SAFE_STRDUP(account->options.signature);
- account_tbl->options.add_my_address_to_bcc = account->options.add_my_address_to_bcc;
- account_tbl->target_storage = account->target_storage;
- account_tbl->check_interval = account->check_interval;
- account_tbl->my_account_id = account->my_account_id;
- account_tbl->index_color = account->index_color;
-
+ account_tbl->account_name = EM_SAFE_STRDUP(account->account_name);
+ account_tbl->incoming_server_type = account->incoming_server_type;
+ account_tbl->incoming_server_address = EM_SAFE_STRDUP(account->incoming_server_address);
+ account_tbl->user_email_address = EM_SAFE_STRDUP(account->user_email_address);
+ account_tbl->incoming_server_user_name = EM_SAFE_STRDUP(account->incoming_server_user_name);
+ account_tbl->incoming_server_password = EM_SAFE_STRDUP(account->incoming_server_password);
+ account_tbl->retrieval_mode = account->retrieval_mode;
+ account_tbl->incoming_server_port_number = account->incoming_server_port_number;
+ account_tbl->incoming_server_secure_connection = account->incoming_server_secure_connection;
+ account_tbl->outgoing_server_type = account->outgoing_server_type;
+ account_tbl->outgoing_server_address = EM_SAFE_STRDUP(account->outgoing_server_address);
+ account_tbl->outgoing_server_port_number = account->outgoing_server_port_number;
+ account_tbl->outgoing_server_need_authentication = account->outgoing_server_need_authentication;
+ account_tbl->outgoing_server_secure_connection = account->outgoing_server_secure_connection;
+ account_tbl->outgoing_server_user_name = EM_SAFE_STRDUP(account->outgoing_server_user_name);
+ account_tbl->outgoing_server_password = EM_SAFE_STRDUP(account->outgoing_server_password);
+ account_tbl->user_display_name = EM_SAFE_STRDUP(account->user_display_name);
+ account_tbl->reply_to_address = EM_SAFE_STRDUP(account->reply_to_address);
+ account_tbl->return_address = EM_SAFE_STRDUP(account->return_address);
+ account_tbl->account_id = account->account_id;
+ account_tbl->keep_mails_on_pop_server_after_download = account->keep_mails_on_pop_server_after_download;
+ account_tbl->auto_download_size = account->auto_download_size;
+ account_tbl->outgoing_server_use_same_authenticator = account->outgoing_server_use_same_authenticator;
+ account_tbl->pop_before_smtp = account->pop_before_smtp;
+ account_tbl->incoming_server_requires_apop = account->incoming_server_requires_apop;
+ account_tbl->logo_icon_path = EM_SAFE_STRDUP(account->logo_icon_path);
+
+ account_tbl->user_data = em_memdup(account->user_data, account->user_data_length);
+ account_tbl->user_data_length = account->user_data_length;
+
+ account_tbl->options.priority = account->options.priority;
+ account_tbl->options.keep_local_copy = account->options.keep_local_copy;
+ account_tbl->options.req_delivery_receipt = account->options.req_delivery_receipt;
+ account_tbl->options.req_read_receipt = account->options.req_read_receipt;
+ account_tbl->options.download_limit = account->options.download_limit;
+ account_tbl->options.block_address = account->options.block_address;
+ account_tbl->options.block_subject = account->options.block_subject;
+ account_tbl->options.display_name_from = EM_SAFE_STRDUP(account->options.display_name_from);
+ account_tbl->options.reply_with_body = account->options.reply_with_body;
+ account_tbl->options.forward_with_files = account->options.forward_with_files;
+ account_tbl->options.add_myname_card = account->options.add_myname_card;
+ account_tbl->options.add_signature = account->options.add_signature;
+ account_tbl->options.signature = EM_SAFE_STRDUP(account->options.signature);
+ account_tbl->options.add_my_address_to_bcc = account->options.add_my_address_to_bcc;
+ account_tbl->check_interval = account->check_interval;
+ account_tbl->account_svc_id = account->account_svc_id;
+ account_tbl->sync_status = account->sync_status;
+ account_tbl->sync_disabled = account->sync_disabled;
+ account_tbl->default_mail_slot_size = account->default_mail_slot_size;
+ account_tbl->smime_type = account->smime_type;
+ account_tbl->certificate_path = EM_SAFE_STRDUP(account->certificate_path);
+ account_tbl->cipher_type = account->cipher_type;
+ account_tbl->digest_type = account->digest_type;
+
+
EM_DEBUG_FUNC_END();
return ret;
}
-INTERNAL_FUNC int em_convert_account_tbl_to_account(emstorage_account_tbl_t *account_tbl, emf_account_t *account)
+INTERNAL_FUNC int em_convert_account_tbl_to_account(emstorage_account_tbl_t *account_tbl, email_account_t *account)
{
EM_DEBUG_FUNC_BEGIN("account_tbl[%p], account[%p]", account_tbl, account);
int ret = 1;
- account->account_bind_type = account_tbl->account_bind_type;
- account->account_name = EM_SAFE_STRDUP(account_tbl->account_name);
- account->receiving_server_type = account_tbl->receiving_server_type;
- account->receiving_server_addr = EM_SAFE_STRDUP(account_tbl->receiving_server_addr);
- account->email_addr = EM_SAFE_STRDUP(account_tbl->email_addr);
- account->user_name = EM_SAFE_STRDUP(account_tbl->user_name);
- account->password = EM_SAFE_STRDUP(account_tbl->password);
- account->retrieval_mode = account_tbl->retrieval_mode;
- account->port_num = account_tbl->port_num;
- account->use_security = account_tbl->use_security;
- account->sending_server_type = account_tbl->sending_server_type;
- account->sending_server_addr = EM_SAFE_STRDUP(account_tbl->sending_server_addr);
- account->sending_port_num = account_tbl->sending_port_num;
- account->sending_auth = account_tbl->sending_auth;
- account->sending_security = account_tbl->sending_security;
- account->sending_user = EM_SAFE_STRDUP(account_tbl->sending_user);
- account->sending_password = EM_SAFE_STRDUP(account_tbl->sending_password);
- account->display_name = EM_SAFE_STRDUP(account_tbl->display_name);
- account->reply_to_addr = EM_SAFE_STRDUP(account_tbl->reply_to_addr);
- account->return_addr = EM_SAFE_STRDUP(account_tbl->return_addr);
- account->account_id = account_tbl->account_id;
- account->keep_on_server = account_tbl->keep_on_server;
- account->flag1 = account_tbl->flag1;
- account->flag2 = account_tbl->flag2;
- account->pop_before_smtp = account_tbl->pop_before_smtp;
- account->apop = account_tbl->apop;
- account->logo_icon_path = EM_SAFE_STRDUP(account_tbl->logo_icon_path);
- account->preset_account = account_tbl->preset_account;
- account->options.priority = account_tbl->options.priority;
- account->options.keep_local_copy = account_tbl->options.keep_local_copy;
- account->options.req_delivery_receipt = account_tbl->options.req_delivery_receipt;
- account->options.req_read_receipt = account_tbl->options.req_read_receipt;
- account->options.download_limit = account_tbl->options.download_limit;
- account->options.block_address = account_tbl->options.block_address;
- account->options.block_subject = account_tbl->options.block_subject;
- account->options.display_name_from = EM_SAFE_STRDUP(account_tbl->options.display_name_from);
- account->options.reply_with_body = account_tbl->options.reply_with_body;
- account->options.forward_with_files = account_tbl->options.forward_with_files;
- account->options.add_myname_card = account_tbl->options.add_myname_card;
- account->options.add_signature = account_tbl->options.add_signature;
- account->options.signature = EM_SAFE_STRDUP(account_tbl->options.signature);
- account->options.add_my_address_to_bcc = account_tbl->options.add_my_address_to_bcc;
- account->target_storage = account_tbl->target_storage;
- account->check_interval = account_tbl->check_interval;
- account->my_account_id = account_tbl->my_account_id;
- account->index_color = account_tbl->index_color;
-
+ account->account_name = EM_SAFE_STRDUP(account_tbl->account_name);
+ account->incoming_server_type = account_tbl->incoming_server_type;
+ account->incoming_server_address = EM_SAFE_STRDUP(account_tbl->incoming_server_address);
+ account->user_email_address = EM_SAFE_STRDUP(account_tbl->user_email_address);
+ account->incoming_server_user_name = EM_SAFE_STRDUP(account_tbl->incoming_server_user_name);
+ account->incoming_server_password = EM_SAFE_STRDUP(account_tbl->incoming_server_password);
+ account->retrieval_mode = account_tbl->retrieval_mode;
+ account->incoming_server_port_number = account_tbl->incoming_server_port_number;
+ account->incoming_server_secure_connection = account_tbl->incoming_server_secure_connection;
+ account->outgoing_server_type = account_tbl->outgoing_server_type;
+ account->outgoing_server_address = EM_SAFE_STRDUP(account_tbl->outgoing_server_address);
+ account->outgoing_server_port_number = account_tbl->outgoing_server_port_number;
+ account->outgoing_server_need_authentication = account_tbl->outgoing_server_need_authentication;
+ account->outgoing_server_secure_connection = account_tbl->outgoing_server_secure_connection;
+ account->outgoing_server_user_name = EM_SAFE_STRDUP(account_tbl->outgoing_server_user_name);
+ account->outgoing_server_password = EM_SAFE_STRDUP(account_tbl->outgoing_server_password);
+ account->user_display_name = EM_SAFE_STRDUP(account_tbl->user_display_name);
+ account->reply_to_address = EM_SAFE_STRDUP(account_tbl->reply_to_address);
+ account->return_address = EM_SAFE_STRDUP(account_tbl->return_address);
+ account->account_id = account_tbl->account_id;
+ account->keep_mails_on_pop_server_after_download = account_tbl->keep_mails_on_pop_server_after_download;
+ account->auto_download_size = account_tbl->auto_download_size;
+ account->outgoing_server_use_same_authenticator = account_tbl->outgoing_server_use_same_authenticator;
+ account->pop_before_smtp = account_tbl->pop_before_smtp;
+ account->incoming_server_requires_apop = account_tbl->incoming_server_requires_apop;
+ account->logo_icon_path = EM_SAFE_STRDUP(account_tbl->logo_icon_path);
+ account->user_data = em_memdup(account_tbl->user_data, account_tbl->user_data_length);
+ account->user_data_length = account_tbl->user_data_length;
+ account->options.priority = account_tbl->options.priority;
+ account->options.keep_local_copy = account_tbl->options.keep_local_copy;
+ account->options.req_delivery_receipt = account_tbl->options.req_delivery_receipt;
+ account->options.req_read_receipt = account_tbl->options.req_read_receipt;
+ account->options.download_limit = account_tbl->options.download_limit;
+ account->options.block_address = account_tbl->options.block_address;
+ account->options.block_subject = account_tbl->options.block_subject;
+ account->options.display_name_from = EM_SAFE_STRDUP(account_tbl->options.display_name_from);
+ account->options.reply_with_body = account_tbl->options.reply_with_body;
+ account->options.forward_with_files = account_tbl->options.forward_with_files;
+ account->options.add_myname_card = account_tbl->options.add_myname_card;
+ account->options.add_signature = account_tbl->options.add_signature;
+ account->options.signature = EM_SAFE_STRDUP(account_tbl->options.signature);
+ account->options.add_my_address_to_bcc = account_tbl->options.add_my_address_to_bcc;
+ account->check_interval = account_tbl->check_interval;
+ account->account_svc_id = account_tbl->account_svc_id;
+ account->sync_status = account_tbl->sync_status;
+ account->sync_disabled = account_tbl->sync_disabled;
+ account->default_mail_slot_size = account_tbl->default_mail_slot_size;
+ account->smime_type = account_tbl->smime_type;
+ account->certificate_path = EM_SAFE_STRDUP(account_tbl->certificate_path);
+ account->cipher_type = account_tbl->cipher_type;
+ account->digest_type = account_tbl->digest_type;
+
+ EM_DEBUG_FUNC_END();
+ return ret;
+}
+
+INTERNAL_FUNC int em_convert_mailbox_to_mailbox_tbl(email_mailbox_t *mailbox, emstorage_mailbox_tbl_t *mailbox_tbl)
+{
+ EM_DEBUG_FUNC_BEGIN("mailbox[%p], mailbox_tbl[%p]", mailbox, mailbox_tbl);
+ int ret = 1;
+
+ mailbox_tbl->account_id = mailbox->account_id;
+ mailbox_tbl->mailbox_id = mailbox->mailbox_id;
+ mailbox_tbl->mailbox_name = EM_SAFE_STRDUP(mailbox->mailbox_name);
+ mailbox_tbl->alias = EM_SAFE_STRDUP(mailbox->alias);
+ mailbox_tbl->local_yn = mailbox->local;
+ mailbox_tbl->mailbox_type = mailbox->mailbox_type;
+ mailbox_tbl->unread_count = mailbox->unread_count;
+ mailbox_tbl->total_mail_count_on_local = mailbox->total_mail_count_on_local;
+ mailbox_tbl->total_mail_count_on_server = mailbox->total_mail_count_on_server;
+ mailbox_tbl->mail_slot_size = mailbox->mail_slot_size;
+
EM_DEBUG_FUNC_END();
return ret;
}
-INTERNAL_FUNC int em_convert_mail_tbl_to_mail_data(emstorage_mail_tbl_t *mail_table_data, int item_count, emf_mail_data_t **mail_data, int *error)
+INTERNAL_FUNC int em_convert_mailbox_tbl_to_mailbox(emstorage_mailbox_tbl_t *mailbox_tbl, email_mailbox_t *mailbox)
+{
+ EM_DEBUG_FUNC_BEGIN("mailbox_tbl[%p], mailbox[%p]", mailbox_tbl, mailbox);
+ int ret = 1;
+
+ mailbox->account_id = mailbox_tbl->account_id;
+ mailbox->mailbox_id = mailbox_tbl->mailbox_id;
+ mailbox->mailbox_name = EM_SAFE_STRDUP(mailbox_tbl->mailbox_name);
+ mailbox->alias = EM_SAFE_STRDUP(mailbox_tbl->alias);
+ mailbox->local = mailbox_tbl->local_yn;
+ mailbox->mailbox_type = mailbox_tbl->mailbox_type;
+ mailbox->unread_count = mailbox_tbl->unread_count;
+ mailbox->total_mail_count_on_local = mailbox_tbl->total_mail_count_on_local;
+ mailbox->total_mail_count_on_server = mailbox_tbl->total_mail_count_on_server;
+ mailbox->mail_slot_size = mailbox_tbl->mail_slot_size;
+ mailbox->last_sync_time = mailbox_tbl->last_sync_time;
+
+ EM_DEBUG_FUNC_END();
+ return ret;
+}
+
+
+INTERNAL_FUNC int em_convert_mail_tbl_to_mail_data(emstorage_mail_tbl_t *mail_table_data, int item_count, email_mail_data_t **mail_data, int *error)
{
EM_DEBUG_FUNC_BEGIN("mail_table_data[%p], item_count [%d], mail_data[%p]", mail_table_data, item_count, mail_data);
- int i, ret = false, err_code = EMF_ERROR_NONE;
- emf_mail_data_t *temp_mail_data = NULL;
+ int i, ret = false, err_code = EMAIL_ERROR_NONE;
+ email_mail_data_t *temp_mail_data = NULL;
if (!mail_table_data || !mail_data || !item_count) {
EM_DEBUG_EXCEPTION("Invalid parameter");
- err_code = EMF_ERROR_INVALID_PARAM;
+ err_code = EMAIL_ERROR_INVALID_PARAM;
goto FINISH_OFF;
}
- temp_mail_data = em_malloc(sizeof(emf_mail_data_t) * item_count);
-
+ temp_mail_data = em_malloc(sizeof(email_mail_data_t) * item_count);
+
if(!temp_mail_data) {
EM_DEBUG_EXCEPTION("em_malloc failed");
- err_code = EMF_ERROR_OUT_OF_MEMORY;
+ err_code = EMAIL_ERROR_OUT_OF_MEMORY;
goto FINISH_OFF;
}
for(i = 0; i < item_count; i++) {
temp_mail_data[i].mail_id = mail_table_data[i].mail_id;
temp_mail_data[i].account_id = mail_table_data[i].account_id;
- temp_mail_data[i].mailbox_name = EM_SAFE_STRDUP(mail_table_data[i].mailbox_name);
+ temp_mail_data[i].mailbox_id = mail_table_data[i].mailbox_id;
temp_mail_data[i].mailbox_type = mail_table_data[i].mailbox_type;
temp_mail_data[i].subject = EM_SAFE_STRDUP(mail_table_data[i].subject);
temp_mail_data[i].date_time = mail_table_data[i].date_time;
@@ -364,6 +419,7 @@ INTERNAL_FUNC int em_convert_mail_tbl_to_mail_data(emstorage_mail_tbl_t *mail_ta
temp_mail_data[i].body_download_status = mail_table_data[i].body_download_status;
temp_mail_data[i].file_path_plain = EM_SAFE_STRDUP(mail_table_data[i].file_path_plain);
temp_mail_data[i].file_path_html = EM_SAFE_STRDUP(mail_table_data[i].file_path_html);
+ temp_mail_data[i].file_path_mime_entity = EM_SAFE_STRDUP(mail_table_data[i].file_path_mime_entity);
temp_mail_data[i].mail_size = mail_table_data[i].mail_size;
temp_mail_data[i].flags_seen_field = mail_table_data[i].flags_seen_field;
temp_mail_data[i].flags_deleted_field = mail_table_data[i].flags_deleted_field;
@@ -383,6 +439,9 @@ INTERNAL_FUNC int em_convert_mail_tbl_to_mail_data(emstorage_mail_tbl_t *mail_ta
temp_mail_data[i].thread_item_count = mail_table_data[i].thread_item_count;
temp_mail_data[i].preview_text = EM_SAFE_STRDUP(mail_table_data[i].preview_text);
temp_mail_data[i].meeting_request_status = mail_table_data[i].meeting_request_status;
+ temp_mail_data[i].message_class = mail_table_data[i].message_class;
+ temp_mail_data[i].digest_type = mail_table_data[i].digest_type;
+ temp_mail_data[i].smime_type = mail_table_data[i].smime_type;
}
*mail_data = temp_mail_data;
@@ -391,36 +450,36 @@ INTERNAL_FUNC int em_convert_mail_tbl_to_mail_data(emstorage_mail_tbl_t *mail_ta
FINISH_OFF:
if(error)
- *error = err_code;
+ *error = err_code;
EM_DEBUG_FUNC_END();
return ret;
}
-INTERNAL_FUNC int em_convert_mail_data_to_mail_tbl(emf_mail_data_t *mail_data, int item_count, emstorage_mail_tbl_t **mail_table_data, int *error)
+INTERNAL_FUNC int em_convert_mail_data_to_mail_tbl(email_mail_data_t *mail_data, int item_count, emstorage_mail_tbl_t **mail_table_data, int *error)
{
EM_DEBUG_FUNC_BEGIN("mail_data[%p], item_count [%d], mail_table_data[%p]", mail_data, item_count, mail_table_data);
- int i, ret = false, err_code = EMF_ERROR_NONE;
+ int i, ret = false, err_code = EMAIL_ERROR_NONE;
emstorage_mail_tbl_t *temp_mail_tbl = NULL;
if (!mail_data || !mail_table_data || !item_count) {
EM_DEBUG_EXCEPTION("Invalid parameter");
- err_code = EMF_ERROR_INVALID_PARAM;
+ err_code = EMAIL_ERROR_INVALID_PARAM;
goto FINISH_OFF;
}
temp_mail_tbl = em_malloc(sizeof(emstorage_mail_tbl_t) * item_count);
-
+
if(!temp_mail_tbl) {
EM_DEBUG_EXCEPTION("em_malloc failed");
- err_code = EMF_ERROR_OUT_OF_MEMORY;
+ err_code = EMAIL_ERROR_OUT_OF_MEMORY;
goto FINISH_OFF;
}
for(i = 0; i < item_count; i++) {
temp_mail_tbl[i].mail_id = mail_data[i].mail_id;
temp_mail_tbl[i].account_id = mail_data[i].account_id;
- temp_mail_tbl[i].mailbox_name = EM_SAFE_STRDUP(mail_data[i].mailbox_name);
+ temp_mail_tbl[i].mailbox_id = mail_data[i].mailbox_id;
temp_mail_tbl[i].mailbox_type = mail_data[i].mailbox_type;
temp_mail_tbl[i].date_time = mail_data[i].date_time;
temp_mail_tbl[i].subject = EM_SAFE_STRDUP(mail_data[i].subject);
@@ -441,6 +500,7 @@ INTERNAL_FUNC int em_convert_mail_data_to_mail_tbl(emf_mail_data_t *mail_data,
temp_mail_tbl[i].body_download_status = mail_data[i].body_download_status;
temp_mail_tbl[i].file_path_plain = EM_SAFE_STRDUP(mail_data[i].file_path_plain);
temp_mail_tbl[i].file_path_html = EM_SAFE_STRDUP(mail_data[i].file_path_html);
+ temp_mail_tbl[i].file_path_mime_entity = EM_SAFE_STRDUP(mail_data[i].file_path_mime_entity);
temp_mail_tbl[i].mail_size = mail_data[i].mail_size;
temp_mail_tbl[i].flags_seen_field = mail_data[i].flags_seen_field;
temp_mail_tbl[i].flags_deleted_field = mail_data[i].flags_deleted_field;
@@ -460,6 +520,9 @@ INTERNAL_FUNC int em_convert_mail_data_to_mail_tbl(emf_mail_data_t *mail_data,
temp_mail_tbl[i].thread_item_count = mail_data[i].thread_item_count;
temp_mail_tbl[i].preview_text = EM_SAFE_STRDUP(mail_data[i].preview_text);
temp_mail_tbl[i].meeting_request_status = mail_data[i].meeting_request_status;
+ temp_mail_tbl[i].message_class = mail_data[i].message_class;
+ temp_mail_tbl[i].digest_type = mail_data[i].digest_type;
+ temp_mail_tbl[i].smime_type = mail_data[i].smime_type;
}
*mail_table_data = temp_mail_tbl;
@@ -472,7 +535,7 @@ FINISH_OFF:
EM_DEBUG_FUNC_END();
return ret;
-
+
}
@@ -486,7 +549,7 @@ INTERNAL_FUNC int em_convert_string_to_time_t(char *input_datetime_string, time_
if (!input_datetime_string || !output_time) {
EM_DEBUG_EXCEPTION("input_datetime_string[%p], output_time[%p]", input_datetime_string, output_time);
- return EMF_ERROR_INVALID_PARAM;
+ return EMAIL_ERROR_INVALID_PARAM;
}
memset(buf, 0x00, sizeof(buf));
@@ -517,8 +580,8 @@ INTERNAL_FUNC int em_convert_string_to_time_t(char *input_datetime_string, time_
EM_DEBUG_LOG("*output_time [%d", *output_time);
- EM_DEBUG_FUNC_END("err %d", EMF_ERROR_NONE);
- return EMF_ERROR_NONE;
+ EM_DEBUG_FUNC_END("err %d", EMAIL_ERROR_NONE);
+ return EMAIL_ERROR_NONE;
}
INTERNAL_FUNC int em_convert_time_t_to_string(time_t *input_time, char **output_datetime_string)
@@ -528,105 +591,146 @@ INTERNAL_FUNC int em_convert_time_t_to_string(time_t *input_time, char **output_
struct tm *temp_time_info;
if (!input_time || !output_datetime_string) {
- EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
- return EMF_ERROR_INVALID_PARAM;
+ EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
+ return EMAIL_ERROR_INVALID_PARAM;
}
temp_time_info = localtime(input_time);
if(!temp_time_info) {
EM_DEBUG_EXCEPTION("localtime failed.");
- return EMF_ERROR_SYSTEM_FAILURE;
+ return EMAIL_ERROR_SYSTEM_FAILURE;
}
SNPRINTF(temp_buffer, sizeof(temp_buffer), "%04d%02d%02d%02d%02d%02d",
temp_time_info->tm_year + 1970, temp_time_info->tm_mon, temp_time_info->tm_mday, temp_time_info->tm_hour, temp_time_info->tm_min, temp_time_info->tm_sec);
*output_datetime_string = EM_SAFE_STRDUP(temp_buffer);
- EM_DEBUG_FUNC_END("err %d", EMF_ERROR_NONE);
- return EMF_ERROR_NONE;
+ EM_DEBUG_FUNC_END("err %d", EMAIL_ERROR_NONE);
+ return EMAIL_ERROR_NONE;
}
-static char* append_sized_data_to_stream(char *input_stream, int *input_output_stream_length, char *input_sized_data, int input_data_size)
+static char* append_sized_data_to_stream(char *stream, int *stream_len, char *src, int src_len)
{
- EM_DEBUG_FUNC_BEGIN("input_stream [%p], input_output_stream_length [%p], input_sized_data [%p], input_data_size [%d]", input_stream, input_output_stream_length, input_sized_data, input_data_size);
+ /* EM_DEBUG_FUNC_BEGIN("input_stream [%p], input_output_stream_length [%p], input_sized_data [%p], input_data_size [%d]", input_stream, input_output_stream_length, input_sized_data, input_data_size); */
char *new_stream = NULL;
- int source_stream_length = 0;
- if( !input_output_stream_length || input_data_size == 0 || input_sized_data == NULL||
- (input_stream != NULL && *input_output_stream_length == 0) || (input_stream == NULL && *input_output_stream_length != 0) ) {
- EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
- return NULL;
+ if( !stream_len || src_len == 0 || src == NULL || (stream != NULL && *stream_len == 0) ||
+ (stream == NULL && *stream_len != 0) ) {
+ EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
+ return NULL;
}
- source_stream_length = *input_output_stream_length;
+ int old_stream_len = *stream_len;
- new_stream = (char*)em_malloc((source_stream_length) * sizeof(char) + input_data_size);
+ /*TODO: don't increase stream buffer incrementally when appending new data */
+ new_stream = (char*)em_malloc(old_stream_len + src_len);
if(!new_stream) {
- EM_DEBUG_EXCEPTION("EMF_ERROR_OUT_OF_MEMORY");
- return NULL;
+ EM_DEBUG_EXCEPTION("EMAIL_ERROR_OUT_OF_MEMORY");
+ return NULL;
}
- if(input_stream != NULL)
- memcpy(new_stream, input_stream, source_stream_length * sizeof(char));
+ if(stream != NULL)
+ memcpy(new_stream, stream, old_stream_len);
- memcpy(new_stream + source_stream_length, input_sized_data, input_data_size);
+ memcpy(new_stream + old_stream_len, src, src_len);
- *input_output_stream_length = source_stream_length + input_data_size;
-
- EM_SAFE_FREE(input_stream);
- EM_DEBUG_FUNC_END("*input_output_stream_length [%d]", *input_output_stream_length);
- return new_stream;
+ *stream_len = old_stream_len + src_len;
+
+ EM_SAFE_FREE(stream);
+ /* EM_DEBUG_FUNC_END("*input_output_stream_length [%d]", *input_output_stream_length); */
+ return new_stream;
}
+
static char* append_string_to_stream(char *input_stream, int *input_output_stream_length, char *input_source_string)
{
EM_DEBUG_FUNC_BEGIN("input_stream [%p], input_output_stream_length [%p] input_source_string[%p]", input_stream, input_output_stream_length, input_source_string);
char *new_stream = NULL;
int data_length = 0;
- int source_stream_length = 0;
- if( !input_output_stream_length || (input_stream != NULL && *input_output_stream_length == 0) || (input_stream == NULL && *input_output_stream_length != 0)) {
- EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
- return NULL;
+ if( !input_output_stream_length || (input_stream != NULL && *input_output_stream_length == 0) ||
+ (input_stream == NULL && *input_output_stream_length != 0) ) {
+ EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
+ return NULL;
}
- source_stream_length = *input_output_stream_length;
+ int source_stream_length = *input_output_stream_length;
- if(input_source_string != NULL)
- data_length = EM_SAFE_STRLEN(input_source_string);
+ data_length = EM_SAFE_STRLEN(input_source_string);
- new_stream = (char*)em_malloc((source_stream_length + data_length) * sizeof(char) + sizeof(int));
+ new_stream = (char*)em_malloc(source_stream_length + data_length + sizeof(int));
if(!new_stream) {
- EM_DEBUG_EXCEPTION("EMF_ERROR_OUT_OF_MEMORY");
- return NULL;
+ EM_DEBUG_EXCEPTION("EMAIL_ERROR_OUT_OF_MEMORY");
+ return NULL;
}
if(input_stream != NULL)
- memcpy(new_stream, input_stream, source_stream_length * sizeof(char));
+ memcpy(new_stream, input_stream, source_stream_length);
+ /* write string length */
memcpy(new_stream + source_stream_length, (char*)&data_length, sizeof(int));
- if(input_source_string)
+ /* write string */
+ if(input_source_string)
memcpy(new_stream + source_stream_length + sizeof(int), input_source_string, data_length);
+ /* for example, "abc" is written to stream buffer with "3abc" */
*input_output_stream_length = source_stream_length + sizeof(int) + data_length;
-
- EM_SAFE_FREE(input_stream);
+
+ EM_SAFE_FREE(input_stream);
EM_DEBUG_FUNC_END("*input_output_stream_length [%d]", *input_output_stream_length);
- return new_stream;
+ return new_stream;
+}
+
+#if 0
+static char* append_binary_to_stream(char *stream, int *stream_length, char *src, int src_size)
+{
+ /* EM_DEBUG_FUNC_BEGIN("input_stream [%p], input_output_stream_length [%p], input_sized_data [%p], input_data_size [%d]", input_stream, input_output_stream_length, input_sized_data, input_data_size); */
+ char *new_stream = NULL;
+
+ if( !stream_length || (stream && *stream_length == 0) || (!stream && *stream_length != 0) ||
+ src_size < 0 ) {
+ EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
+ return NULL;
+ }
+
+ /*TODO: don't increase stream buffer incrementally when appending new data */
+ new_stream = (char*)em_malloc(*stream_length + sizeof(int) + src_size);
+
+ if(!new_stream) {
+ EM_DEBUG_EXCEPTION("EMAIL_ERROR_OUT_OF_MEMORY");
+ return NULL;
+ }
+
+
+ if(stream != NULL)
+ memcpy(new_stream, stream, *stream_length);
+
+ memcpy(new_stream + *stream_length, &src_size, sizeof(int));
+
+ if( src_size > 0 )
+ memcpy(new_stream + *stream_length + sizeof(int), src, src_size);
+
+ *stream_length = *stream_length + sizeof(int) + src_size;
+
+ EM_SAFE_FREE(stream);
+ /* EM_DEBUG_FUNC_END("*input_output_stream_length [%d]", *input_output_stream_length); */
+
+ return new_stream;
}
+#endif
-static int fetch_sized_data_from_stream(char *input_stream, int *input_output_stream_offset, int input_data_size, char *output_data)
+static int fetch_sized_data_from_stream(char *input_stream, int *input_output_stream_offset, int input_data_size, char *output_data)
{
- EM_DEBUG_FUNC_BEGIN("input_stream [%p], input_output_stream_offset [%p] input_data_size [%d], output_data[%p]", input_stream, input_output_stream_offset, input_data_size, output_data);
+ /* EM_DEBUG_FUNC_BEGIN("input_stream [%p], input_output_stream_offset [%p] input_data_size [%d], output_data[%p]", input_stream, input_output_stream_offset, input_data_size, output_data); */
int stream_offset = 0;
if( !input_stream || !input_output_stream_offset || !input_data_size || !output_data) {
- EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
- return EMF_ERROR_INVALID_PARAM;
+ EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
+ return EMAIL_ERROR_INVALID_PARAM;
}
stream_offset = *input_output_stream_offset;
@@ -636,33 +740,30 @@ static int fetch_sized_data_from_stream(char *input_stream, int *input_output_st
*input_output_stream_offset = stream_offset;
- EM_DEBUG_FUNC_END("stream_offset [%d]", stream_offset);
- return EMF_ERROR_NONE;
+ /* EM_DEBUG_FUNC_END("stream_offset [%d]", stream_offset); */
+ return EMAIL_ERROR_NONE;
}
-static int fetch_string_from_stream(char *input_stream, int *input_output_stream_offset, char **output_string)
+
+static int fetch_string_from_stream(char *input_stream, int *input_output_stream_offset, char **output_string)
{
- EM_DEBUG_FUNC_BEGIN("input_stream [%p], input_output_stream_offset [%p] output_string[%p]", input_stream, input_output_stream_offset, output_string);
+ /* EM_DEBUG_FUNC_BEGIN("input_stream [%p], input_output_stream_offset [%p] output_string[%p]", input_stream, input_output_stream_offset, output_string); */
int string_length = 0;
int stream_offset = 0;
char *result_string = NULL;
if( !input_stream || !input_output_stream_offset || !output_string) {
- EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
- return EMF_ERROR_INVALID_PARAM;
+ EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
+ return EMAIL_ERROR_INVALID_PARAM;
}
stream_offset = *input_output_stream_offset;
- /*
- EM_DEBUG_LOG("stream_offset [%d]", stream_offset);
- */
+ /* EM_DEBUG_LOG("stream_offset [%d]", stream_offset); */
memcpy(&string_length, input_stream + stream_offset, sizeof(int));
stream_offset += sizeof(int);
- /*
- EM_DEBUG_LOG("string_length [%d]", string_length);
- */
+ /* EM_DEBUG_LOG("string_length [%d]", string_length); */
if(string_length != 0) {
result_string = (char*)em_malloc(string_length + 1);
@@ -678,47 +779,107 @@ static int fetch_string_from_stream(char *input_stream, int *input_output_stream
*output_string = result_string;
*input_output_stream_offset = stream_offset;
-
- EM_DEBUG_FUNC_END("stream_offset [%d]", stream_offset);
- return EMF_ERROR_NONE;
+
+ /* EM_DEBUG_FUNC_END("stream_offset [%d]", stream_offset); */
+ return EMAIL_ERROR_NONE;
}
-INTERNAL_FUNC char* em_convert_account_to_byte_stream(emf_account_t* input_account, int *output_stream_size)
+#if 0
+static int fetch_binary_from_stream(char *stream, int *stream_offset, void **dest)
{
+ /* EM_DEBUG_FUNC_BEGIN("input_stream [%p], input_output_stream_offset [%p] output_string[%p]", input_stream, input_output_stream_offset, output_string); */
+ int length = 0;
+
+ if( !stream || !stream_offset || !dest) {
+ EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
+ return EMAIL_ERROR_INVALID_PARAM;
+ }
+
+ int offset = *stream_offset;
+
+ memcpy((void*)&length, (void*) stream + offset, sizeof(int));
+ offset += sizeof(int);
+
+ *dest = NULL;
+ if(length > 0) {
+ *dest = (void*)em_malloc(length);
+ if(!*dest) {
+ EM_DEBUG_EXCEPTION("EMAIL_ERROR_OUT_OF_MEMORY");
+ return EMAIL_ERROR_OUT_OF_MEMORY;
+ }
+
+ memcpy(*dest, (void*) stream + offset, length);
+ offset += length;
+ }
+
+ *stream_offset = offset;
+
+ return EMAIL_ERROR_NONE;
+}
+#endif
+ /* divide struct at binary field (void* user_data)*/
+#define EMAIL_ACCOUNT_FMT "S(" "isiii" "is" ")" "B" "S(" "issss" "isiss" "iiiii" "isiss" "iii"\
+ "$(" "iiiii" "iisii" "iisi" ")" "iiisii" ")"
+
+
+INTERNAL_FUNC char* em_convert_account_to_byte_stream(email_account_t* account, int *stream_len)
+{
+ EM_DEBUG_FUNC_END();
+ EM_IF_NULL_RETURN_VALUE(account, NULL);
+
+ tpl_node *tn = NULL;
+ tpl_bin tb;
+
+ tn = tpl_map(EMAIL_ACCOUNT_FMT, account, &tb, &(account->user_data_length));
+ tb.sz = account->user_data_length;
+ tb.addr = account->user_data;
+ tpl_pack(tn, 0);
+
+ /* write account to buffer */
+ void *buf = NULL;
+ size_t len = 0;
+ tpl_dump(tn, TPL_MEM, &buf, &len);
+ tpl_free(tn);
+
+ *stream_len = len;
+ EM_DEBUG_FUNC_END();
+ return (char*) buf;
+
+#if 0
EM_DEBUG_FUNC_BEGIN("input_account [%p], output_stream_size [%p]", input_account, output_stream_size);
char *result_stream = NULL;
int stream_size = 0;
EM_IF_NULL_RETURN_VALUE(input_account, NULL);
-
- result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_account->account_bind_type), sizeof(int));
+
result_stream = append_string_to_stream(result_stream, &stream_size, input_account->account_name);
- result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_account->receiving_server_type), sizeof(int));
- result_stream = append_string_to_stream(result_stream, &stream_size, input_account->receiving_server_addr);
- result_stream = append_string_to_stream(result_stream, &stream_size, input_account->email_addr);
- result_stream = append_string_to_stream(result_stream, &stream_size, input_account->user_name);
- result_stream = append_string_to_stream(result_stream, &stream_size, input_account->password);
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_account->incoming_server_type), sizeof(int));
+ result_stream = append_string_to_stream(result_stream, &stream_size, input_account->incoming_server_address);
+ result_stream = append_string_to_stream(result_stream, &stream_size, input_account->user_email_address);
+ result_stream = append_string_to_stream(result_stream, &stream_size, input_account->incoming_server_user_name);
+ result_stream = append_string_to_stream(result_stream, &stream_size, input_account->incoming_server_password);
result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_account->retrieval_mode), sizeof(int));
- result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_account->port_num), sizeof(int));
- result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_account->use_security), sizeof(int));
- result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_account->sending_server_type), sizeof(int));
- result_stream = append_string_to_stream(result_stream, &stream_size, input_account->sending_server_addr);
- result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_account->sending_port_num), sizeof(int));
- result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_account->sending_auth), sizeof(int));
- result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_account->sending_security), sizeof(int));
- result_stream = append_string_to_stream(result_stream, &stream_size, input_account->sending_user);
- result_stream = append_string_to_stream(result_stream, &stream_size, input_account->sending_password);
- result_stream = append_string_to_stream(result_stream, &stream_size, input_account->display_name);
- result_stream = append_string_to_stream(result_stream, &stream_size, input_account->reply_to_addr);
- result_stream = append_string_to_stream(result_stream, &stream_size, input_account->return_addr);
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_account->incoming_server_port_number), sizeof(int));
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_account->incoming_server_secure_connection), sizeof(int));
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_account->outgoing_server_type), sizeof(int));
+ result_stream = append_string_to_stream(result_stream, &stream_size, input_account->outgoing_server_address);
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_account->outgoing_server_port_number), sizeof(int));
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_account->outgoing_server_need_authentication), sizeof(int));
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_account->outgoing_server_secure_connection), sizeof(int));
+ result_stream = append_string_to_stream(result_stream, &stream_size, input_account->outgoing_server_user_name);
+ result_stream = append_string_to_stream(result_stream, &stream_size, input_account->outgoing_server_password);
+ result_stream = append_string_to_stream(result_stream, &stream_size, input_account->user_display_name);
+ result_stream = append_string_to_stream(result_stream, &stream_size, input_account->reply_to_address);
+ result_stream = append_string_to_stream(result_stream, &stream_size, input_account->return_address);
result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_account->account_id), sizeof(int));
- result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_account->keep_on_server), sizeof(int));
- result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_account->flag1), sizeof(int));
- result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_account->flag2), sizeof(int));
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_account->keep_mails_on_pop_server_after_download), sizeof(int));
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_account->auto_download_size), sizeof(int));
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_account->outgoing_server_use_same_authenticator), sizeof(int));
result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_account->pop_before_smtp), sizeof(int));
- result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_account->apop), sizeof(int));
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_account->incoming_server_requires_apop), sizeof(int));
result_stream = append_string_to_stream(result_stream, &stream_size, input_account->logo_icon_path);
- result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_account->preset_account), sizeof(int));
+ result_stream = append_binary_to_stream(result_stream, &stream_size, input_account->user_data, input_account->user_data_length);
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*) &input_account->user_data_length, sizeof(int));
result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_account->options.priority), sizeof(int));
result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_account->options.keep_local_copy), sizeof(int));
result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_account->options.req_delivery_receipt), sizeof(int));
@@ -733,54 +894,78 @@ INTERNAL_FUNC char* em_convert_account_to_byte_stream(emf_account_t* input_accou
result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_account->options.add_signature), sizeof(int));
result_stream = append_string_to_stream(result_stream, &stream_size, input_account->options.signature);
result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_account->options.add_my_address_to_bcc), sizeof(int));
- result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_account->target_storage), sizeof(int));
result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_account->check_interval), sizeof(int));
- result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_account->my_account_id), sizeof(int));
- result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_account->index_color), sizeof(int));
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_account->account_svc_id), sizeof(int));
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_account->sync_status), sizeof(int));
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_account->sync_disabled), sizeof(int));
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_account->default_mail_slot_size), sizeof(int));
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_account->smime_type), sizeof(int));
+ result_stream = append_string_to_stream(result_stream, &stream_size, input_account->certificate_path);
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_account->cipher_type), sizeof(int));
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_account->digest_type), sizeof(int));
*output_stream_size = stream_size;
+
EM_DEBUG_FUNC_END("stream_size [%d]", stream_size);
return result_stream;
+#endif
}
-INTERNAL_FUNC void em_convert_byte_stream_to_account(char *input_stream, emf_account_t *output_account)
+INTERNAL_FUNC void em_convert_byte_stream_to_account(char *stream, int stream_len, email_account_t *account)
{
+ EM_DEBUG_FUNC_END();
+ EM_NULL_CHECK_FOR_VOID(stream);
+ EM_NULL_CHECK_FOR_VOID(account);
+
+ tpl_node *tn = NULL;
+ tpl_bin tb;
+
+ tn = tpl_map(EMAIL_ACCOUNT_FMT, account, &tb, &(account->user_data_length));
+ tpl_load(tn, TPL_MEM, stream, stream_len);
+ tpl_unpack(tn, 0);
+ tpl_free(tn);
+
+ /* tb will be destroyed at end of func, but tb.addr remains */
+ account->user_data = tb.addr;
+
+ EM_DEBUG_FUNC_END();
+#if 0
EM_DEBUG_FUNC_BEGIN();
int stream_offset = 0;
EM_NULL_CHECK_FOR_VOID(input_stream);
EM_NULL_CHECK_FOR_VOID(output_account);
- fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&output_account->account_bind_type);
fetch_string_from_stream(input_stream, &stream_offset, &output_account->account_name);
- fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&output_account->receiving_server_type);
- fetch_string_from_stream(input_stream, &stream_offset, &output_account->receiving_server_addr);
- fetch_string_from_stream(input_stream, &stream_offset, &output_account->email_addr);
- fetch_string_from_stream(input_stream, &stream_offset, &output_account->user_name);
- fetch_string_from_stream(input_stream, &stream_offset, &output_account->password);
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&output_account->incoming_server_type);
+ fetch_string_from_stream(input_stream, &stream_offset, &output_account->incoming_server_address);
+ fetch_string_from_stream(input_stream, &stream_offset, &output_account->user_email_address);
+ fetch_string_from_stream(input_stream, &stream_offset, &output_account->incoming_server_user_name);
+ fetch_string_from_stream(input_stream, &stream_offset, &output_account->incoming_server_password);
fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&output_account->retrieval_mode);
- fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&output_account->port_num);
- fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&output_account->use_security);
- fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&output_account->sending_server_type);
- fetch_string_from_stream(input_stream, &stream_offset, &output_account->sending_server_addr);
- fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&output_account->sending_port_num);
- fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&output_account->sending_auth);
- fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&output_account->sending_security);
- fetch_string_from_stream(input_stream, &stream_offset, &output_account->sending_user);
- fetch_string_from_stream(input_stream, &stream_offset, &output_account->sending_password);
- fetch_string_from_stream(input_stream, &stream_offset, &output_account->display_name);
- fetch_string_from_stream(input_stream, &stream_offset, &output_account->reply_to_addr);
- fetch_string_from_stream(input_stream, &stream_offset, &output_account->return_addr);
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&output_account->incoming_server_port_number);
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&output_account->incoming_server_secure_connection);
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&output_account->outgoing_server_type);
+ fetch_string_from_stream(input_stream, &stream_offset, &output_account->outgoing_server_address);
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&output_account->outgoing_server_port_number);
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&output_account->outgoing_server_need_authentication);
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&output_account->outgoing_server_secure_connection);
+ fetch_string_from_stream(input_stream, &stream_offset, &output_account->outgoing_server_user_name);
+ fetch_string_from_stream(input_stream, &stream_offset, &output_account->outgoing_server_password);
+ fetch_string_from_stream(input_stream, &stream_offset, &output_account->user_display_name);
+ fetch_string_from_stream(input_stream, &stream_offset, &output_account->reply_to_address);
+ fetch_string_from_stream(input_stream, &stream_offset, &output_account->return_address);
fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&output_account->account_id);
- fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&output_account->keep_on_server);
- fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&output_account->flag1);
- fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&output_account->flag2);
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&output_account->keep_mails_on_pop_server_after_download);
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&output_account->auto_download_size);
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&output_account->outgoing_server_use_same_authenticator);
fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&output_account->pop_before_smtp);
- fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&output_account->apop);
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&output_account->incoming_server_requires_apop);
fetch_string_from_stream(input_stream, &stream_offset, &output_account->logo_icon_path);
- fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&output_account->preset_account);
+ fetch_binary_from_stream(input_stream, &stream_offset, &output_account->user_data);
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&output_account->user_data_length);
fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&output_account->options.priority);
fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&output_account->options.keep_local_copy);
fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&output_account->options.req_delivery_receipt);
@@ -795,85 +980,51 @@ INTERNAL_FUNC void em_convert_byte_stream_to_account(char *input_stream, emf_ac
fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&output_account->options.add_signature);
fetch_string_from_stream(input_stream, &stream_offset, &output_account->options.signature);
fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&output_account->options.add_my_address_to_bcc);
- fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&output_account->target_storage);
fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&output_account->check_interval);
- fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&output_account->my_account_id);
- fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&output_account->index_color);
-
- EM_DEBUG_FUNC_END();
-}
-
-INTERNAL_FUNC char* em_convert_attachment_info_to_byte_stream(emf_attachment_info_t *input_attachment_info, int *output_stream_size)
-{
- EM_DEBUG_FUNC_BEGIN();
-
- char *result_stream = NULL;
- int stream_size = 0;
-
- EM_IF_NULL_RETURN_VALUE(input_attachment_info, NULL);
- EM_IF_NULL_RETURN_VALUE(output_stream_size, NULL);
-
- while(input_attachment_info) {
- result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&input_attachment_info->inline_content, sizeof(int));
- result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&input_attachment_info->attachment_id, sizeof(int));
- result_stream = append_string_to_stream(result_stream, &stream_size, input_attachment_info->name);
- result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&input_attachment_info->size, sizeof(int));
- result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&input_attachment_info->downloaded, sizeof(int));
- result_stream = append_string_to_stream(result_stream, &stream_size, input_attachment_info->savename);
- result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&input_attachment_info->drm, sizeof(int));
-
- input_attachment_info = input_attachment_info->next;
- }
-
- *output_stream_size = stream_size;
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&output_account->account_svc_id);
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&output_account->sync_status);
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&output_account->sync_disabled);
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&output_account->default_mail_slot_size);
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&output_account->smime_type);
+ fetch_string_from_stream(input_stream, &stream_offset, &output_account->certificate_path);
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&output_account->cipher_type);
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&output_account->digest_type);
EM_DEBUG_FUNC_END();
- return result_stream;
+#endif
}
-INTERNAL_FUNC void em_convert_byte_stream_to_attachment_info(char *input_stream, int attachment_count, emf_attachment_info_t **output_attachment_info)
+#define EMAIL_MAIL_DATA_FMT "S(" "iiiis" "iisss" "sssss" "sssss" "isssi"\
+ "ccccc" "cciii" "iiiii" "isiii" "i" ")"
+
+INTERNAL_FUNC char* em_convert_mail_data_to_byte_stream(email_mail_data_t *mail_data, int *stream_len)
{
- EM_DEBUG_FUNC_BEGIN();
+ EM_DEBUG_FUNC_END();
+ EM_IF_NULL_RETURN_VALUE(mail_data, NULL);
+ EM_IF_NULL_RETURN_VALUE(stream_len, NULL);
- int i = 0;
- int stream_offset = 0;
- emf_attachment_info_t *temp_attachment_info = NULL;
- emf_attachment_info_t *current_attachment_info = NULL;
+ tpl_node *tn = NULL;
- EM_NULL_CHECK_FOR_VOID(input_stream);
+ tn = tpl_map(EMAIL_MAIL_DATA_FMT, mail_data);
+ tpl_pack(tn, 0);
- for(i = 0; i < attachment_count; i++) {
- temp_attachment_info = (emf_attachment_info_t*)malloc(sizeof(emf_attachment_info_t));
+ /* write account to buffer */
+ void *buf = NULL;
+ size_t len = 0;
+ tpl_dump(tn, TPL_MEM, &buf, &len);
+ tpl_free(tn);
- if(i == 0)
- *output_attachment_info = current_attachment_info = temp_attachment_info;
- else {
- current_attachment_info->next = temp_attachment_info;
- current_attachment_info = temp_attachment_info;
- }
-
- fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&temp_attachment_info->inline_content);
- fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&temp_attachment_info->attachment_id);
- fetch_string_from_stream(input_stream, &stream_offset, &temp_attachment_info->name);
- fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&temp_attachment_info->size);
- fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&temp_attachment_info->downloaded);
- fetch_string_from_stream(input_stream, &stream_offset, &temp_attachment_info->savename);
- fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&temp_attachment_info->drm);
-
- temp_attachment_info->next = NULL;
- }
-
+ *stream_len = len;
EM_DEBUG_FUNC_END();
-}
+ return (char*) buf;
-INTERNAL_FUNC char* em_convert_mail_data_to_byte_stream(emf_mail_data_t *input_mail_data, int input_mail_data_count, int *output_stream_size)
-{
+#if 0
EM_DEBUG_FUNC_BEGIN("input_mail_data [%p], input_mail_data_count[%d], output_stream_size[%p]", input_mail_data, input_mail_data_count, output_stream_size);
-
+
char *result_stream = NULL;
int stream_size = 0;
int i = 0;
-
+
EM_IF_NULL_RETURN_VALUE(input_mail_data, NULL);
EM_IF_NULL_RETURN_VALUE(output_stream_size, NULL);
@@ -882,7 +1033,7 @@ INTERNAL_FUNC char* em_convert_mail_data_to_byte_stream(emf_mail_data_t *input_m
for(i = 0; i < input_mail_data_count; i++) {
result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_mail_data[i].mail_id), sizeof(int));
result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_mail_data[i].account_id), sizeof(int));
- result_stream = append_string_to_stream(result_stream, &stream_size, input_mail_data[i].mailbox_name);
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_mail_data[i].mailbox_id), sizeof(int));
result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_mail_data[i].mailbox_type), sizeof(int));
result_stream = append_string_to_stream(result_stream, &stream_size, input_mail_data[i].subject);
result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_mail_data[i].date_time), sizeof(int));
@@ -903,6 +1054,7 @@ INTERNAL_FUNC char* em_convert_mail_data_to_byte_stream(emf_mail_data_t *input_m
result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_mail_data[i].body_download_status), sizeof(int));
result_stream = append_string_to_stream(result_stream, &stream_size, input_mail_data[i].file_path_plain);
result_stream = append_string_to_stream(result_stream, &stream_size, input_mail_data[i].file_path_html);
+ result_stream = append_string_to_stream(result_stream, &stream_size, input_mail_data[i].file_path_mime_entity);
result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_mail_data[i].mail_size), sizeof(int));
result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_mail_data[i].flags_seen_field), sizeof(char));
result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_mail_data[i].flags_deleted_field), sizeof(char));
@@ -922,16 +1074,32 @@ INTERNAL_FUNC char* em_convert_mail_data_to_byte_stream(emf_mail_data_t *input_m
result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_mail_data[i].thread_item_count), sizeof(int));
result_stream = append_string_to_stream(result_stream, &stream_size, input_mail_data[i].preview_text);
result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_mail_data[i].meeting_request_status), sizeof(int));
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_mail_data[i].message_class), sizeof(int));
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_mail_data[i].digest_type), sizeof(int));
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_mail_data[i].smime_type), sizeof(int));
}
*output_stream_size = stream_size;
EM_DEBUG_FUNC_END("stream_size [%d]", stream_size);
return result_stream;
+#endif
}
-INTERNAL_FUNC void em_convert_byte_stream_to_mail_data(char *input_stream, emf_mail_data_t **output_mail_data, int *output_mail_data_count)
+INTERNAL_FUNC void em_convert_byte_stream_to_mail_data(char *stream, int stream_len, email_mail_data_t *mail_data)
{
+ EM_NULL_CHECK_FOR_VOID(stream);
+ EM_NULL_CHECK_FOR_VOID(mail_data);
+
+ tpl_node *tn = NULL;
+
+ tn = tpl_map(EMAIL_MAIL_DATA_FMT, mail_data);
+ tpl_load(tn, TPL_MEM, stream, stream_len);
+ tpl_unpack(tn, 0);
+ tpl_free(tn);
+
+ EM_DEBUG_FUNC_END();
+#if 0
EM_DEBUG_FUNC_BEGIN("input_stream [%p], output_mail_data[%p], output_mail_data_count[%p]", input_stream, output_mail_data, output_mail_data_count);
int stream_offset = 0;
@@ -950,7 +1118,7 @@ INTERNAL_FUNC void em_convert_byte_stream_to_mail_data(char *input_stream, emf_m
return;
}
- *output_mail_data = (emf_mail_data_t*)em_malloc(sizeof(emf_mail_data_t) * (*output_mail_data_count));
+ *output_mail_data = (email_mail_data_t*)em_malloc(sizeof(email_mail_data_t) * (*output_mail_data_count));
if(!*output_mail_data) {
EM_DEBUG_EXCEPTION("em_malloc failed");
@@ -960,7 +1128,7 @@ INTERNAL_FUNC void em_convert_byte_stream_to_mail_data(char *input_stream, emf_m
for(i = 0; i < *output_mail_data_count; i++) {
fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&(*output_mail_data)[i].mail_id);
fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&(*output_mail_data)[i].account_id);
- fetch_string_from_stream(input_stream, &stream_offset, &(*output_mail_data)[i].mailbox_name);
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&(*output_mail_data)[i].mailbox_id);
fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&(*output_mail_data)[i].mailbox_type);
fetch_string_from_stream(input_stream, &stream_offset, &(*output_mail_data)[i].subject);
fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&(*output_mail_data)[i].date_time);
@@ -981,6 +1149,7 @@ INTERNAL_FUNC void em_convert_byte_stream_to_mail_data(char *input_stream, emf_m
fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&(*output_mail_data)[i].body_download_status);
fetch_string_from_stream(input_stream, &stream_offset, &(*output_mail_data)[i].file_path_plain);
fetch_string_from_stream(input_stream, &stream_offset, &(*output_mail_data)[i].file_path_html);
+ fetch_string_from_stream(input_stream, &stream_offset, &(*output_mail_data)[i].file_path_mime_entity);
fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&(*output_mail_data)[i].mail_size);
fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(char), (char*)&(*output_mail_data)[i].flags_seen_field);
fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(char), (char*)&(*output_mail_data)[i].flags_deleted_field);
@@ -1000,15 +1169,57 @@ INTERNAL_FUNC void em_convert_byte_stream_to_mail_data(char *input_stream, emf_m
fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&(*output_mail_data)[i].thread_item_count);
fetch_string_from_stream(input_stream, &stream_offset, &(*output_mail_data)[i].preview_text);
fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&(*output_mail_data)[i].meeting_request_status);
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&(*output_mail_data)[i].message_class);
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&(*output_mail_data)[i].digest_type);
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&(*output_mail_data)[i].smime_type);
}
EM_DEBUG_FUNC_END();
+#endif
}
-INTERNAL_FUNC char* em_convert_attachment_data_to_byte_stream(emf_attachment_data_t *input_attachment_data, int input_attachment_count, int* output_stream_size)
+
+#define EMAIL_ATTACHMENT_DATA_FMT "A(S(" "issii" "iciii" "s" "))"
+
+INTERNAL_FUNC char* em_convert_attachment_data_to_byte_stream(email_attachment_data_t *attachment, int attachment_count, int* stream_len)
{
+ EM_DEBUG_FUNC_BEGIN();
+ EM_IF_NULL_RETURN_VALUE(stream_len, NULL);
+ if(!attachment) {
+ EM_DEBUG_LOG("no attachment to be included");
+ *stream_len = 0;
+ return NULL;
+ }
+
+
+ email_attachment_data_t cur = {0};
+ tpl_node *tn = NULL;
+
+ /* tpl_map adds value at 2nd param addr to packing buffer iterately */
+ /* 2nd param value (not addr via pointer) should be modified at each iteration */
+ tn = tpl_map(EMAIL_ATTACHMENT_DATA_FMT, &cur);
+ int i=0;
+ for( ; i < attachment_count ; i++ ) {
+ memcpy(&cur, attachment+i, sizeof(cur)); /* copy data to cur : swallow copy */
+ tpl_pack(tn, 1); /* pack data at &cur: deep copy */
+ }
+
+ /* write data to buffer */
+ void *buf = NULL;
+ size_t len = 0;
+ tpl_dump(tn, TPL_MEM, &buf, &len);
+ tpl_free(tn);
+
+ *stream_len = len;
+
+ EM_DEBUG_LOG("stream_len: %d", len);
+
+ EM_DEBUG_FUNC_END();
+ return (char*) buf;
+
+#if 0
EM_DEBUG_FUNC_BEGIN("input_attachment_data [%p], input_attachment_count [%d], output_stream_size [%p]", input_attachment_data, input_attachment_count, output_stream_size);
-
+
char *result_stream = NULL;
int stream_size = 0;
int i = 0;
@@ -1026,7 +1237,7 @@ INTERNAL_FUNC char* em_convert_attachment_data_to_byte_stream(emf_attachment_dat
result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&input_attachment_data[i].attachment_size, sizeof(int));
result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&input_attachment_data[i].mail_id, sizeof(int));
result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&input_attachment_data[i].account_id, sizeof(int));
- result_stream = append_string_to_stream(result_stream, &stream_size, input_attachment_data[i].mailbox_name);
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&input_attachment_data[i].mailbox_id, sizeof(int));
result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&input_attachment_data[i].save_status, sizeof(int));
result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&input_attachment_data[i].drm_status, sizeof(int));
result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&input_attachment_data[i].inline_content_status,sizeof(int));
@@ -1036,10 +1247,55 @@ INTERNAL_FUNC char* em_convert_attachment_data_to_byte_stream(emf_attachment_dat
EM_DEBUG_FUNC_END("stream_size [%d]", stream_size);
return result_stream;
+#endif
}
-INTERNAL_FUNC void em_convert_byte_stream_to_attachment_data(char *input_stream, emf_attachment_data_t **output_attachment_data, int *output_attachment_count)
+INTERNAL_FUNC void em_convert_byte_stream_to_attachment_data(char *stream, int stream_len, email_attachment_data_t **attachment_data, int *attachment_count)
{
+ EM_DEBUG_FUNC_BEGIN();
+ EM_NULL_CHECK_FOR_VOID(stream);
+ EM_NULL_CHECK_FOR_VOID(attachment_data);
+ EM_NULL_CHECK_FOR_VOID(attachment_count);
+
+
+ email_attachment_data_t cur = {0};
+ tpl_node *tn = NULL;
+ tn = tpl_map(EMAIL_ATTACHMENT_DATA_FMT, &cur);
+ tpl_load(tn, TPL_MEM, stream, stream_len);
+
+ /* tpl does not return the size of variable-length array, but we need variable-length array */
+ /* so, make list and get list count in the first phase, */
+ /* and then copy list to var array after allocating memory */
+ GList *head = NULL;
+ int count = 0;
+ while( tpl_unpack(tn, 1) > 0) {
+ email_attachment_data_t* pdata = (email_attachment_data_t*) em_malloc(sizeof(email_attachment_data_t));
+ memcpy(pdata, &cur, sizeof(email_attachment_data_t)); /* copy unpacked data to list item */
+ head = g_list_prepend(head, pdata); /* add it to list */
+ memset(&cur, 0, sizeof(email_attachment_data_t)); /* initialize variable, used for unpacking */
+ count++;
+ }
+ tpl_free(tn);
+
+ /*finally we get the list count and allocate var length array */
+ email_attachment_data_t *attached = (email_attachment_data_t*) em_malloc(sizeof(email_attachment_data_t)*count);
+
+ /*write glist item into variable array*/
+ head = g_list_reverse(head);
+ GList *p = g_list_first(head);
+ int i=0;
+ for( ; p ; p = g_list_next(p), i++ ) {
+ email_attachment_data_t* pdata = (email_attachment_data_t*) g_list_nth_data(p, 0);
+ memcpy( attached+i, pdata, sizeof(email_attachment_data_t));
+ EM_SAFE_FREE(pdata); /*now, list item is useless */
+ }
+
+ g_list_free(head);
+
+ *attachment_count = count;
+ *attachment_data = attached;
+ EM_DEBUG_FUNC_END();
+#if 0
EM_DEBUG_FUNC_BEGIN("input_stream [%p], output_attachment_data[%p]", input_stream, output_attachment_data);
int stream_offset = 0;
@@ -1058,7 +1314,7 @@ INTERNAL_FUNC void em_convert_byte_stream_to_attachment_data(char *input_stream,
return;
}
- *output_attachment_data = (emf_attachment_data_t*)em_malloc(sizeof(emf_attachment_data_t) * (*output_attachment_count));
+ *output_attachment_data = (email_attachment_data_t*)em_malloc(sizeof(email_attachment_data_t) * (*output_attachment_count));
if(!*output_attachment_data) {
EM_DEBUG_EXCEPTION("em_malloc failed");
@@ -1072,19 +1328,41 @@ INTERNAL_FUNC void em_convert_byte_stream_to_attachment_data(char *input_stream,
fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&((*output_attachment_data)[i].attachment_size));
fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&((*output_attachment_data)[i].mail_id));
fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&((*output_attachment_data)[i].account_id));
- fetch_string_from_stream(input_stream, &stream_offset, &(*output_attachment_data)[i].mailbox_name);
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&((*output_attachment_data)[i].mailbox_id));
fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&((*output_attachment_data)[i].save_status));
fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&((*output_attachment_data)[i].drm_status));
fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&((*output_attachment_data)[i].inline_content_status));
}
EM_DEBUG_FUNC_END();
+#endif
}
+#define EMAIL_MAILBOX_FMT "S(" "isisi" "iiiii" "i" ")"
-INTERNAL_FUNC char* em_convert_mailbox_to_byte_stream(emf_mailbox_t *input_mailbox_data, int *output_stream_size)
+INTERNAL_FUNC char* em_convert_mailbox_to_byte_stream(email_mailbox_t *mailbox_data, int *stream_len)
{
+ EM_DEBUG_FUNC_BEGIN();
+ EM_IF_NULL_RETURN_VALUE(mailbox_data, NULL);
+ EM_IF_NULL_RETURN_VALUE(stream_len, NULL);
+
+ tpl_node *tn = NULL;
+
+ tn = tpl_map(EMAIL_MAILBOX_FMT, mailbox_data);
+ tpl_pack(tn, 0);
+
+ /* write account to buffer */
+ void *buf = NULL;
+ size_t len = 0;
+ tpl_dump(tn, TPL_MEM, &buf, &len);
+ tpl_free(tn);
+
+ *stream_len = len;
+ EM_DEBUG_FUNC_END("serialized len: %d", len);
+ return (char*) buf;
+
+#if 0
EM_DEBUG_FUNC_BEGIN("input_mailbox_data [%p], output_stream_size [%p]", input_mailbox_data, output_stream_size);
char *result_stream = NULL;
@@ -1094,115 +1372,178 @@ INTERNAL_FUNC char* em_convert_mailbox_to_byte_stream(emf_mailbox_t *input_mailb
EM_IF_NULL_RETURN_VALUE(output_stream_size, NULL);
result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_mailbox_data->mailbox_id), sizeof(int));
- result_stream = append_string_to_stream(result_stream, &stream_size, input_mailbox_data->name);
+ result_stream = append_string_to_stream(result_stream, &stream_size, input_mailbox_data->mailbox_name);
result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_mailbox_data->mailbox_type), sizeof(int));
result_stream = append_string_to_stream(result_stream, &stream_size, input_mailbox_data->alias);
result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_mailbox_data->unread_count), sizeof(int));
result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_mailbox_data->total_mail_count_on_local), sizeof(int));
result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_mailbox_data->total_mail_count_on_server), sizeof(int));
- result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_mailbox_data->hold_connection), sizeof(int));
result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_mailbox_data->local), sizeof(int));
- result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_mailbox_data->synchronous), sizeof(int));
result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_mailbox_data->account_id), sizeof(int));
- result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_mailbox_data->user_data), sizeof(int));
- result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_mailbox_data->mail_stream), sizeof(int));
- result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_mailbox_data->has_archived_mails), sizeof(int));
result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_mailbox_data->mail_slot_size), sizeof(int));
- result_stream = append_string_to_stream(result_stream, &stream_size, input_mailbox_data->account_name);
*output_stream_size = stream_size;
EM_DEBUG_FUNC_END();
return result_stream;
+#endif
}
-INTERNAL_FUNC void em_convert_byte_stream_to_mailbox(char *input_stream, emf_mailbox_t *output_mailbox_data)
+INTERNAL_FUNC void em_convert_byte_stream_to_mailbox(char *stream, int stream_len, email_mailbox_t *mailbox_data)
{
- EM_DEBUG_FUNC_BEGIN("input_stream [%p], output_mailbox_data [%p]", input_stream, output_mailbox_data);
+ EM_DEBUG_FUNC_BEGIN();
+ EM_NULL_CHECK_FOR_VOID(stream);
+ EM_NULL_CHECK_FOR_VOID(mailbox_data);
+
+ tpl_node *tn = NULL;
+
+ tn = tpl_map(EMAIL_MAILBOX_FMT, mailbox_data);
+ tpl_load(tn, TPL_MEM, stream, stream_len);
+ tpl_unpack(tn, 0);
+ tpl_free(tn);
+
+ EM_DEBUG_FUNC_END("deserialized len %d", stream_len);
+
+/* EM_DEBUG_FUNC_BEGIN("input_stream [%p], output_mailbox_data [%p]", input_stream, output_mailbox_data);
int stream_offset = 0;
EM_NULL_CHECK_FOR_VOID(input_stream);
EM_NULL_CHECK_FOR_VOID(output_mailbox_data);
fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&(output_mailbox_data->mailbox_id));
- fetch_string_from_stream(input_stream, &stream_offset, &output_mailbox_data->name);
+ fetch_string_from_stream(input_stream, &stream_offset, &output_mailbox_data->mailbox_name);
fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&(output_mailbox_data->mailbox_type));
fetch_string_from_stream(input_stream, &stream_offset, &output_mailbox_data->alias);
fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&(output_mailbox_data->unread_count));
fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&(output_mailbox_data->total_mail_count_on_local));
fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&(output_mailbox_data->total_mail_count_on_server));
- fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&(output_mailbox_data->hold_connection));
fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&(output_mailbox_data->local));
- fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&(output_mailbox_data->synchronous));
fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&(output_mailbox_data->account_id));
- fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&(output_mailbox_data->user_data));
- fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&(output_mailbox_data->mail_stream));
- fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&(output_mailbox_data->has_archived_mails));
fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&(output_mailbox_data->mail_slot_size));
- fetch_string_from_stream(input_stream, &stream_offset, &output_mailbox_data->account_name);
EM_DEBUG_FUNC_END();
+*/
}
+#define EMAIL_OPTION_FMT "S(" "iiiii" "iisii" "iisi" ")"
-INTERNAL_FUNC char* em_convert_option_to_byte_stream(emf_option_t* input_option, int* output_stream_size)
+INTERNAL_FUNC char* em_convert_option_to_byte_stream(email_option_t* option, int* stream_len)
{
EM_DEBUG_FUNC_BEGIN();
+ EM_IF_NULL_RETURN_VALUE(option, NULL);
+ EM_IF_NULL_RETURN_VALUE(stream_len, NULL);
+
+ tpl_node *tn = NULL;
+
+ tn = tpl_map(EMAIL_OPTION_FMT, option);
+ tpl_pack(tn, 0);
+
+ /* write account to buffer */
+ void *buf = NULL;
+ size_t len = 0;
+ tpl_dump(tn, TPL_MEM, &buf, &len);
+ tpl_free(tn);
+
+ *stream_len = len;
+ EM_DEBUG_FUNC_END("serialized len: %d", len);
+ return (char*) buf;
+
+
+#if 0
+ EM_DEBUG_FUNC_BEGIN();
char *result_stream = NULL;
int stream_size = 0;
EM_IF_NULL_RETURN_VALUE(input_option, NULL);
result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_option->priority), sizeof(int));
- result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_option->keep_local_copy), sizeof(int));
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_option->keep_local_copy), sizeof(int));
result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_option->req_delivery_receipt), sizeof(int));
result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_option->req_read_receipt), sizeof(int));
result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_option->download_limit), sizeof(int));
- result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_option->block_address), sizeof(int));
- result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_option->block_subject), sizeof(int));
- result_stream = append_string_to_stream(result_stream, &stream_size, input_option->display_name_from);
- result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_option->reply_with_body), sizeof(int));
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_option->block_address), sizeof(int));
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_option->block_subject), sizeof(int));
+ result_stream = append_string_to_stream(result_stream, &stream_size, input_option->display_name_from);
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_option->reply_with_body), sizeof(int));
result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_option->forward_with_files), sizeof(int));
- result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_option->add_myname_card), sizeof(int));
- result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_option->add_signature), sizeof(int));
- result_stream = append_string_to_stream(result_stream, &stream_size, input_option->signature);
- result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_option->add_my_address_to_bcc), sizeof(int));
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_option->add_myname_card), sizeof(int));
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_option->add_signature), sizeof(int));
+ result_stream = append_string_to_stream(result_stream, &stream_size, input_option->signature);
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_option->add_my_address_to_bcc), sizeof(int));
*output_stream_size = stream_size;
EM_DEBUG_FUNC_END();
return result_stream;
-
+#endif
}
-INTERNAL_FUNC void em_convert_byte_stream_to_option(char *input_stream, emf_option_t *output_option)
+INTERNAL_FUNC void em_convert_byte_stream_to_option(char *stream, int stream_len, email_option_t *option)
{
EM_DEBUG_FUNC_BEGIN();
+ EM_NULL_CHECK_FOR_VOID(stream);
+ EM_NULL_CHECK_FOR_VOID(option);
+
+ tpl_node *tn = NULL;
+
+ tn = tpl_map(EMAIL_OPTION_FMT, option);
+ tpl_load(tn, TPL_MEM, stream, stream_len);
+ tpl_unpack(tn, 0);
+ tpl_free(tn);
+
+ EM_DEBUG_FUNC_END("deserialized len %d", stream_len);
+
+#if 0
+ EM_DEBUG_FUNC_BEGIN();
int stream_offset = 0;
EM_NULL_CHECK_FOR_VOID(input_stream);
fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&(output_option->priority));
- fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&(output_option->keep_local_copy));
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&(output_option->keep_local_copy));
fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&(output_option->req_delivery_receipt));
fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&(output_option->req_read_receipt));
fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&(output_option->download_limit));
- fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&(output_option->block_address));
- fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&(output_option->block_subject));
- fetch_string_from_stream(input_stream, &stream_offset, &output_option->display_name_from);
- fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&(output_option->reply_with_body));
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&(output_option->block_address));
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&(output_option->block_subject));
+ fetch_string_from_stream(input_stream, &stream_offset, &output_option->display_name_from);
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&(output_option->reply_with_body));
fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&(output_option->forward_with_files));
- fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&(output_option->add_myname_card));
- fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&(output_option->add_signature));
- fetch_string_from_stream(input_stream, &stream_offset, &output_option->signature);
- fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&(output_option->add_my_address_to_bcc));
-
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&(output_option->add_myname_card));
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&(output_option->add_signature));
+ fetch_string_from_stream(input_stream, &stream_offset, &output_option->signature);
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&(output_option->add_my_address_to_bcc));
EM_DEBUG_FUNC_END();
+#endif
}
-INTERNAL_FUNC char* em_convert_rule_to_byte_stream(emf_rule_t *input_rule, int *output_stream_size)
+
+#define EMAIL_RULE_FMT "S(" "iiisi" "iii" ")"
+
+INTERNAL_FUNC char* em_convert_rule_to_byte_stream(email_rule_t *rule, int *stream_len)
{
EM_DEBUG_FUNC_BEGIN();
+ EM_IF_NULL_RETURN_VALUE(rule, NULL);
+ EM_IF_NULL_RETURN_VALUE(stream_len, NULL);
+
+ tpl_node *tn = NULL;
+
+ tn = tpl_map(EMAIL_RULE_FMT, rule);
+ tpl_pack(tn, 0);
+
+ /* write account to buffer */
+ void *buf = NULL;
+ size_t len = 0;
+ tpl_dump(tn, TPL_MEM, &buf, &len);
+ tpl_free(tn);
+
+ *stream_len = len;
+ EM_DEBUG_FUNC_END("serialized len: %d", len);
+ return (char*) buf;
+
+
+#if 0
+ EM_DEBUG_FUNC_BEGIN();
char *result_stream = NULL;
int stream_size = 0;
@@ -1214,7 +1555,7 @@ INTERNAL_FUNC char* em_convert_rule_to_byte_stream(emf_rule_t *input_rule, int *
result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_rule->type), sizeof(int));
result_stream = append_string_to_stream(result_stream, &stream_size, input_rule->value);
result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_rule->faction), sizeof(int));
- result_stream = append_string_to_stream(result_stream, &stream_size, input_rule->mailbox);
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_rule->target_mailbox_id), sizeof(int));
result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_rule->flag1), sizeof(int));
result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_rule->flag2), sizeof(int));
@@ -1222,11 +1563,28 @@ INTERNAL_FUNC char* em_convert_rule_to_byte_stream(emf_rule_t *input_rule, int *
EM_DEBUG_FUNC_END();
return result_stream;
+#endif
}
-INTERNAL_FUNC void em_convert_byte_stream_to_rule(char *input_stream, emf_rule_t *output_rule)
+INTERNAL_FUNC void em_convert_byte_stream_to_rule(char *stream, int stream_len, email_rule_t *rule)
{
EM_DEBUG_FUNC_BEGIN();
+ EM_NULL_CHECK_FOR_VOID(stream);
+ EM_NULL_CHECK_FOR_VOID(rule);
+
+ tpl_node *tn = NULL;
+
+ tn = tpl_map(EMAIL_RULE_FMT, rule);
+ tpl_load(tn, TPL_MEM, stream, stream_len);
+ tpl_unpack(tn, 0);
+ tpl_free(tn);
+
+ EM_DEBUG_FUNC_END("deserialized len %d", stream_len);
+
+
+
+#if 0
+ EM_DEBUG_FUNC_BEGIN();
int stream_offset = 0;
EM_NULL_CHECK_FOR_VOID(input_stream);
@@ -1237,14 +1595,17 @@ INTERNAL_FUNC void em_convert_byte_stream_to_rule(char *input_stream, emf_rule_t
fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&(output_rule->type));
fetch_string_from_stream(input_stream, &stream_offset, &output_rule->value);
fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&(output_rule->faction));
- fetch_string_from_stream(input_stream, &stream_offset, &output_rule->mailbox);
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&(output_rule->target_mailbox_id));
fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&(output_rule->flag1));
fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&(output_rule->flag2));
-
+
EM_DEBUG_FUNC_END();
+#endif
}
-INTERNAL_FUNC char* em_convert_extra_flags_to_byte_stream(emf_extra_flag_t input_extra_flag, int *output_stream_size)
+
+#if 0
+INTERNAL_FUNC char* em_convert_extra_flags_to_byte_stream(email_extra_flag_t extra_flag, int *stream_len)
{
EM_DEBUG_FUNC_BEGIN();
char *result_stream = NULL;
@@ -1275,7 +1636,8 @@ INTERNAL_FUNC char* em_convert_extra_flags_to_byte_stream(emf_extra_flag_t input
return result_stream;
}
-INTERNAL_FUNC void em_convert_byte_stream_to_extra_flags(char *input_stream, emf_extra_flag_t *output_extra_flag)
+
+INTERNAL_FUNC void em_convert_byte_stream_to_extra_flags(char *input_stream, email_extra_flag_t *output_extra_flag)
{
EM_DEBUG_FUNC_BEGIN();
@@ -1302,9 +1664,56 @@ INTERNAL_FUNC void em_convert_byte_stream_to_extra_flags(char *input_stream, emf
EM_DEBUG_FUNC_END();
}
+#endif
+
-INTERNAL_FUNC char* em_convert_meeting_req_to_byte_stream(emf_meeting_request_t *input_meeting_req, int *output_stream_size)
+#define EMAIL_MEETING_REQUEST_FMT "iiBBs" "sic#Bi" "c#Bi"
+
+INTERNAL_FUNC char* em_convert_meeting_req_to_byte_stream(email_meeting_request_t *meeting_req, int *stream_len)
{
+
+ EM_DEBUG_FUNC_END();
+ EM_IF_NULL_RETURN_VALUE(meeting_req, NULL);
+
+ tpl_node *tn = NULL;
+ tpl_bin tb[4];
+
+ tn = tpl_map(EMAIL_MEETING_REQUEST_FMT,
+ &meeting_req->mail_id,
+ &meeting_req->meeting_response,
+ &tb[0],
+ &tb[1],
+ &meeting_req->location,
+ &meeting_req->global_object_id,
+ &meeting_req->time_zone.offset_from_GMT,
+ meeting_req->time_zone.standard_name, 32,
+ &tb[2],
+ &meeting_req->time_zone.standard_bias,
+ meeting_req->time_zone.daylight_name, 32,
+ &tb[3],
+ &meeting_req->time_zone.daylight_bias
+ );
+ tb[0].sz = tb[1].sz = tb[2].sz = tb[3].sz = sizeof(struct tm);
+ tb[0].addr = &meeting_req->start_time;
+ tb[1].addr = &meeting_req->end_time;
+ tb[2].addr = &meeting_req->time_zone.standard_time_start_date;
+ tb[3].addr = &meeting_req->time_zone.daylight_time_start_date;
+
+
+ tpl_pack(tn, 0);
+
+ /* write account to buffer */
+ void *buf = NULL;
+ size_t len = 0;
+ tpl_dump(tn, TPL_MEM, &buf, &len);
+ tpl_free(tn);
+
+ *stream_len = len;
+ EM_DEBUG_FUNC_END();
+ return (char*) buf;
+
+
+#if 0
EM_DEBUG_FUNC_BEGIN();
char *result_stream = NULL;
@@ -1312,7 +1721,7 @@ INTERNAL_FUNC char* em_convert_meeting_req_to_byte_stream(emf_meeting_request_t
EM_IF_NULL_RETURN_VALUE(input_meeting_req, NULL);
- result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_meeting_req->mail_id), sizeof(int));
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_meeting_req->mail_id), sizeof(int));
result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_meeting_req->meeting_response), sizeof(int));
result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_meeting_req->start_time), sizeof(struct tm));
result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_meeting_req->end_time), sizeof(struct tm));
@@ -1321,27 +1730,67 @@ INTERNAL_FUNC char* em_convert_meeting_req_to_byte_stream(emf_meeting_request_t
result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_meeting_req->time_zone.offset_from_GMT), sizeof(int));
result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&input_meeting_req->time_zone.standard_name, 32);
result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_meeting_req->time_zone.standard_time_start_date), sizeof(struct tm));
- result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_meeting_req->time_zone.standard_bias), sizeof(int));
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_meeting_req->time_zone.standard_bias), sizeof(int));
result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&input_meeting_req->time_zone.daylight_name, 32);
result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_meeting_req->time_zone.daylight_time_start_date), sizeof(struct tm));
- result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_meeting_req->time_zone.daylight_bias), sizeof(int));
+ result_stream = append_sized_data_to_stream(result_stream, &stream_size, (char*)&(input_meeting_req->time_zone.daylight_bias), sizeof(int));
*output_stream_size = stream_size;
EM_DEBUG_FUNC_END();
return result_stream;
+#endif
}
-INTERNAL_FUNC void em_convert_byte_stream_to_meeting_req(char *input_stream, emf_meeting_request_t *output_meeting_req)
+INTERNAL_FUNC void em_convert_byte_stream_to_meeting_req(char *stream, int stream_len, email_meeting_request_t *meeting_req)
{
+ EM_DEBUG_FUNC_END();
+ EM_NULL_CHECK_FOR_VOID(stream);
+ EM_NULL_CHECK_FOR_VOID(meeting_req);
+
+ tpl_node *tn = NULL;
+ tpl_bin tb[4];
+
+ tn = tpl_map(EMAIL_MEETING_REQUEST_FMT,
+ &meeting_req->mail_id,
+ &meeting_req->meeting_response,
+ &tb[0],
+ &tb[1],
+ &meeting_req->location,
+ &meeting_req->global_object_id,
+ &meeting_req->time_zone.offset_from_GMT,
+ meeting_req->time_zone.standard_name, 32,
+ &tb[2],
+ &meeting_req->time_zone.standard_bias,
+ meeting_req->time_zone.daylight_name, 32,
+ &tb[3],
+ &meeting_req->time_zone.daylight_bias
+ );
+ tpl_load(tn, TPL_MEM, stream, stream_len);
+ tpl_unpack(tn, 0);
+ tpl_free(tn);
+
+ /* tb will be destroyed at end of func, but tb.addr remains */
+ memcpy(&meeting_req->start_time, tb[0].addr, sizeof(struct tm));
+ memcpy(&meeting_req->end_time, tb[1].addr, sizeof(struct tm));
+ memcpy(&meeting_req->time_zone.standard_time_start_date, tb[2].addr, sizeof(struct tm));
+ memcpy(&meeting_req->time_zone.daylight_time_start_date, tb[3].addr, sizeof(struct tm));
+
+ int i=0;
+ for(i=0; i< 4 ; i++)
+ EM_SAFE_FREE(tb[i].addr);
+
+ EM_DEBUG_FUNC_END();
+
+#if 0
EM_DEBUG_FUNC_BEGIN();
int stream_offset = 0;
EM_NULL_CHECK_FOR_VOID(input_stream);
EM_NULL_CHECK_FOR_VOID(output_meeting_req);
- fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&(output_meeting_req->mail_id));
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&(output_meeting_req->mail_id));
fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&(output_meeting_req->meeting_response));
fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(struct tm), (char*)&(output_meeting_req->start_time));
fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(struct tm), (char*)&(output_meeting_req->end_time));
@@ -1350,15 +1799,17 @@ INTERNAL_FUNC void em_convert_byte_stream_to_meeting_req(char *input_stream, em
fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&(output_meeting_req->time_zone.offset_from_GMT));
fetch_sized_data_from_stream(input_stream, &stream_offset, 32, output_meeting_req->time_zone.standard_name);
fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(struct tm), (char*)&(output_meeting_req->time_zone.standard_time_start_date));
- fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&(output_meeting_req->time_zone.standard_bias));
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&(output_meeting_req->time_zone.standard_bias));
fetch_sized_data_from_stream(input_stream, &stream_offset, 32, output_meeting_req->time_zone.daylight_name);
fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(struct tm), (char*)&(output_meeting_req->time_zone.daylight_time_start_date));
- fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&(output_meeting_req->time_zone.daylight_bias));
+ fetch_sized_data_from_stream(input_stream, &stream_offset, sizeof(int), (char*)&(output_meeting_req->time_zone.daylight_bias));
EM_DEBUG_FUNC_END();
+#endif
}
-INTERNAL_FUNC char* em_convert_search_filter_to_byte_stream(email_search_filter_t *input_search_filter_list, int input_search_filter_count, int *output_stream_size)
+INTERNAL_FUNC char* em_convert_search_filter_to_byte_stream(email_search_filter_t *input_search_filter_list,
+ int input_search_filter_count, int *output_stream_size)
{
EM_DEBUG_FUNC_BEGIN("input_search_filter_list [%p] input_search_filter_count [%d]", input_search_filter_list, input_search_filter_count);
@@ -1413,7 +1864,8 @@ INTERNAL_FUNC char* em_convert_search_filter_to_byte_stream(email_search_filter_
return result_stream;
}
-INTERNAL_FUNC void em_convert_byte_stream_to_search_filter(char *input_stream, email_search_filter_t **output_search_filter_list, int *output_search_filter_count)
+INTERNAL_FUNC void em_convert_byte_stream_to_search_filter(char *input_stream,
+ email_search_filter_t **output_search_filter_list, int *output_search_filter_count)
{
EM_DEBUG_FUNC_BEGIN("input_stream [%p] output_search_filter_list [%p] output_search_filter_count [%p]", input_stream, output_search_filter_list, output_search_filter_count);
@@ -1485,3 +1937,68 @@ FINISH_OFF:
EM_DEBUG_FUNC_END();
}
+
+INTERNAL_FUNC int em_convert_certificate_tbl_to_certificate(emstorage_certificate_tbl_t *certificate_tbl, email_certificate_t **certificate, int *error)
+{
+ EM_DEBUG_FUNC_BEGIN("certficate_tbl[%p], certificate[%p]", certificate_tbl, certificate);
+
+ int err_code = EMAIL_ERROR_NONE;
+ int ret = false;
+ email_certificate_t *temp_certificate = NULL;
+
+ if (!certificate_tbl || !certificate) {
+ EM_DEBUG_EXCEPTION("Invalid parameter");
+ err_code = EMAIL_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ temp_certificate = em_malloc(sizeof(email_certificate_t)) ;
+ if (!temp_certificate) {
+ EM_DEBUG_EXCEPTION("em_malloc failed");
+ err_code = EMAIL_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ temp_certificate->certificate_id = certificate_tbl->certificate_id;
+ temp_certificate->issue_year = certificate_tbl->issue_year;
+ temp_certificate->issue_month = certificate_tbl->issue_month;
+ temp_certificate->issue_day = certificate_tbl->issue_day;
+ temp_certificate->expiration_year = certificate_tbl->expiration_year;
+ temp_certificate->expiration_month = certificate_tbl->expiration_month;
+ temp_certificate->expiration_day = certificate_tbl->expiration_day;
+ temp_certificate->issue_organization_name = EM_SAFE_STRDUP(certificate_tbl->issue_organization_name);
+ temp_certificate->email_address = EM_SAFE_STRDUP(certificate_tbl->email_address);
+ temp_certificate->subject_str = EM_SAFE_STRDUP(certificate_tbl->subject_str);
+ temp_certificate->filepath = EM_SAFE_STRDUP(certificate_tbl->filepath);
+
+ *certificate = temp_certificate;
+
+ ret = true;
+FINISH_OFF:
+ if (error)
+ *error = err_code;
+
+ EM_DEBUG_FUNC_END();
+ return true;
+}
+
+INTERNAL_FUNC int em_convert_certificate_to_certificate_tbl(email_certificate_t *certificate, emstorage_certificate_tbl_t *certificate_tbl)
+{
+ EM_DEBUG_FUNC_BEGIN("certficate[%p], certificate_tbl[%p]", certificate, certificate_tbl);
+
+ certificate_tbl->certificate_id = certificate->certificate_id;
+ certificate_tbl->issue_year = certificate->issue_year;
+ certificate_tbl->issue_month = certificate->issue_month;
+ certificate_tbl->issue_day = certificate->issue_day;
+ certificate_tbl->expiration_year = certificate->expiration_year;
+ certificate_tbl->expiration_month = certificate->expiration_month;
+ certificate_tbl->expiration_day = certificate->expiration_day;
+ certificate_tbl->issue_organization_name = EM_SAFE_STRDUP(certificate->issue_organization_name);
+ certificate_tbl->email_address = EM_SAFE_STRDUP(certificate->email_address);
+ certificate_tbl->subject_str = EM_SAFE_STRDUP(certificate->subject_str);
+ certificate_tbl->filepath = EM_SAFE_STRDUP(certificate->filepath);
+
+ EM_DEBUG_FUNC_END();
+ return true;
+}
+
diff --git a/email-common-use/email-utilities.c b/email-common-use/email-utilities.c
index 5cebaf9..d5ba501 100755
--- a/email-common-use/email-utilities.c
+++ b/email-common-use/email-utilities.c
@@ -1,643 +1,1079 @@
-/*
-* email-service
-*
-* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
-*
-* Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com>
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*
-*/
-
-/*
- * email-utilities.c
- *
- * Created on: 2012. 3. 6.
- * Author: kyuho.jo@samsung.com
- */
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <ctype.h>
-#include <errno.h>
-#include <sys/time.h>
-#include <sys/vfs.h>
-#include <unistd.h>
-#include <malloc.h>
-#include <pthread.h>
-#include <regex.h>
-
-#include "c-client.h"
-
-#include "email-types.h"
-#include "email-internal-types.h"
-#include "email-utilities.h"
-
-INTERNAL_FUNC void* em_malloc(unsigned len)
-{
- /* EM_DEBUG_LOG("Memory allocation size[%d] bytes", len); */
- void *p = NULL;
-
- if (len <= 0) {
- EM_DEBUG_EXCEPTION("len should be positive.[%d]", len);
- return NULL;
- }
-
- p = malloc(len);
-
- if (p)
- memset(p, 0x00, len);
- else
- EM_DEBUG_EXCEPTION("malloc failed");
- return p;
-}
-
-/* remove left space, tab, CR, L */
-INTERNAL_FUNC char *em_trim_left(char *str)
-{
- char *p, *temp_buffer = NULL;
-
- /* EM_DEBUG_FUNC_BEGIN() */
- if (!str) return NULL;
-
- p = str;
- while (*p && (*p == ' ' || *p == '\t' || *p == LF || *p == CR)) p++;
-
- if (!*p) return NULL;
-
- temp_buffer = EM_SAFE_STRDUP(p);
-
- strncpy(str, temp_buffer, strlen(str));
- str[strlen(temp_buffer)] = NULL_CHAR;
-
- EM_SAFE_FREE(temp_buffer);
-
- return str;
-}
-
-/* remove right space, tab, CR, L */
-INTERNAL_FUNC char *em_trim_right(char *str)
-{
- char *p;
-
- /* EM_DEBUG_FUNC_BEGIN() */
- if (!str) return NULL;
-
- p = str+strlen(str)-1;
- while (((int)p >= (int)str) && (*p == ' ' || *p == '\t' || *p == LF || *p == CR))
- *p --= '\0';
-
- if ((int) p < (int)str)
- return NULL;
-
- return str;
-}
-
-INTERNAL_FUNC char* em_upper_string(char *str)
-{
- char *p = str;
- while (*p) {
- *p = toupper(*p);
- p++;
- }
- return str;
-}
-
-INTERNAL_FUNC char* em_lower_string(char *str)
-{
- char *p = str;
- while (*p) {
- *p = tolower(*p);
- p++;
- }
- return str;
-}
-
-INTERNAL_FUNC int em_upper_path(char *path)
-{
- int i = 0, is_utf7 = 0, len = path ? (int)strlen(path) : -1;
- for (; i < len; i++) {
- if (path[i] == '&' || path[i] == 5) {
- is_utf7 = 1;
- }
- else {
- if (is_utf7) {
- if (path[i] == '-') is_utf7 = 0;
- }
- else {
- path[i] = toupper(path[i]);
- }
- }
- }
-
- return 1;
-}
-
-INTERNAL_FUNC void em_skip_whitespace(char *addr_str, char **pAddr)
-{
- EM_DEBUG_FUNC_BEGIN("addr_str[%p]", addr_str);
-
- if (!addr_str)
- return ;
- char *str = addr_str;
- char ptr[strlen(str)+1] ;
- int i, j = 0;
-
- str = addr_str ;
- for (i = 0; str[i] != NULL_CHAR ; i++) {
- if (str[i] != SPACE && str[i] != TAB && str[i] != CR && str[i] != LF)
- ptr[j++] = str[i];
- }
- ptr[j] = NULL_CHAR;
-
- *pAddr = EM_SAFE_STRDUP(ptr);
- EM_DEBUG_FUNC_END("ptr[%s]", ptr);
-}
-
-INTERNAL_FUNC char* em_skip_whitespace_without_strdup(char *source_string)
-{
- EM_DEBUG_FUNC_BEGIN("source_string[%p]", source_string);
-
- if (!source_string)
- return NULL;
- int i;
-
- for (i = 0; source_string[i] != NULL_CHAR ; i++) {
- if (source_string[i] != SPACE) /* || source_string[i] != TAB || source_string[i] != CR || source_string[i] || LF) */
- break;
- }
-
- EM_DEBUG_FUNC_END("i[%d]", i);
- return source_string + i;
-}
-
-INTERNAL_FUNC char* em_replace_string(char *source_string, char *old_string, char *new_string)
-{
- EM_DEBUG_FUNC_BEGIN();
- char *result_buffer = NULL;
- char *p = NULL;
- int buffer_length = 0;
-
- EM_IF_NULL_RETURN_VALUE(source_string, NULL);
- EM_IF_NULL_RETURN_VALUE(old_string, NULL);
- EM_IF_NULL_RETURN_VALUE(new_string, NULL);
-
- p = strstr(source_string, old_string);
-
- if (p == NULL) {
- EM_DEBUG_EXCEPTION("old_string not found in source_string");
- EM_DEBUG_FUNC_END("return NULL");
- return NULL;
- }
-
- buffer_length = strlen(source_string) + 1024;
- result_buffer = (char *)em_malloc(buffer_length);
-
- if (!result_buffer) {
- EM_DEBUG_EXCEPTION("em_malloc failed");
- return NULL;
- }
-
- strncpy(result_buffer, source_string, p - source_string);
- snprintf(result_buffer + strlen(result_buffer), buffer_length - strlen(result_buffer), "%s%s", new_string, p + strlen(old_string));
-
- EM_DEBUG_FUNC_END("result_buffer[%s]", result_buffer);
- return result_buffer;
-}
-
-/* Memory clean up */
-#include <sys/mman.h>
-
-/* #define GETSP() ({ unsigned int sp; asm volatile ("mov %0, sp " : "=r"(sp)); sp;}) */
-#define BUF_SIZE 256
-#define PAGE_SIZE (1 << 12)
-#define _ALIGN_UP(addr, size) (((addr)+((size)-1))&(~((size)-1)))
-#define _ALIGN_DOWN(addr, size) ((addr)&(~((size)-1)))
-#define PAGE_ALIGN(addr) _ALIGN_DOWN(addr, PAGE_SIZE)
-
-int stack_trim(void)
-{
- /*
- char buf[BUF_SIZE];
- FILE *file;
- unsigned int stacktop;
- int found = 0;
- unsigned int sp;
-
- asm volatile ("mov %0, sp " : "=r"(sp));
-
- sprintf(buf, "/proc/%d/maps", getpid());
- file = fopen(buf, "r");
- while (fgets(buf, BUF_SIZE, file) != NULL) {
- if (strstr(buf, "[stack]")) {
- found = 1;
- break;
- }
- }
-
- fclose(file);
-
- if (found) {
- sscanf(buf, "%x-", &stacktop);
- if (madvise((void *)PAGE_ALIGN(stacktop), PAGE_ALIGN(sp)-stacktop, MADV_DONTNEED) < 0)
- perror("stack madvise fail");
- }
- */
- return 1;
-}
-
-INTERNAL_FUNC void em_flush_memory()
-{
- EM_DEBUG_FUNC_BEGIN();
- /* flush memory in heap */
- malloc_trim(0);
-
- /* flush memory in stack */
- stack_trim();
-
- /* flush memory for sqlite */
- emstorage_flush_db_cache();
- EM_DEBUG_FUNC_END();
-}
-
-#define DATE_TIME_STRING_LEGNTH 14
-
-INTERNAL_FUNC char *em_get_extension_from_file_path(char *source_file_path, int *err_code)
-{
- EM_DEBUG_FUNC_BEGIN("source_file_path[%s]", source_file_path);
- int err = EMF_ERROR_NONE, pos_on_string = 0;
- char *extension = NULL;
-
- if (!source_file_path) {
- EM_DEBUG_EXCEPTION("Invalid Parameter");
- err = EMF_ERROR_INVALID_PARAM;
- goto FINISH_OFF;
- }
-
- pos_on_string = strlen(source_file_path) - 1;
-
- while(pos_on_string > 0 && source_file_path[pos_on_string--] != '.') ;
-
- if(pos_on_string > 0)
- extension = source_file_path + pos_on_string + 2;
-
- EM_DEBUG_LOG("*extension [%s] pos_on_string [%d]", extension, pos_on_string);
-
-FINISH_OFF:
- if (err_code)
- *err_code = err;
- EM_DEBUG_FUNC_END();
- return extension;
-}
-
-INTERNAL_FUNC int em_get_encoding_type_from_file_path(const char *input_file_path, char **output_encoding_type)
-{
- EM_DEBUG_FUNC_BEGIN("input_file_path[%d], output_encoding_type[%p]", input_file_path, output_encoding_type);
- int err = EMF_ERROR_NONE;
- int pos_of_filename = 0;
- int pos_of_dot = 0;
- int enf_of_string = 0;
- int result_string_length = 0;
- char *filename = NULL;
- char *result_encoding_type = NULL;
-
- if (!input_file_path || !output_encoding_type) {
- EM_DEBUG_EXCEPTION("Invalid Parameter");
- err = EMF_ERROR_INVALID_PARAM;
- goto FINISH_OFF;
- }
-
- enf_of_string = pos_of_filename = strlen(input_file_path) - 1;
-
- while(pos_of_filename >= 0 && input_file_path[pos_of_filename--] != '/') {
- if(input_file_path[pos_of_filename] == '.')
- pos_of_dot = pos_of_filename;
- }
-
- if(pos_of_filename != 0)
- pos_of_filename += 2;
-
- filename = (char*)input_file_path + pos_of_filename;
-
- if(pos_of_dot != 0 && pos_of_dot > pos_of_filename)
- result_string_length = pos_of_dot - pos_of_filename;
- else
- result_string_length = enf_of_string - pos_of_filename;
-
- EM_DEBUG_LOG("pos_of_dot [%d], pos_of_filename [%d], enf_of_string[%d],result_string_length [%d]", pos_of_dot, pos_of_filename, enf_of_string, result_string_length);
-
- if( !(result_encoding_type = em_malloc(sizeof(char) * (result_string_length + 1))) ) {
- EM_DEBUG_EXCEPTION("EMF_ERROR_OUT_OF_MEMORY");
- err = EMF_ERROR_OUT_OF_MEMORY;
- goto FINISH_OFF;
- }
-
- memcpy(result_encoding_type, input_file_path + pos_of_filename, result_string_length);
-
- EM_DEBUG_LOG("*result_encoding_type [%s]", result_encoding_type);
-
- *output_encoding_type = result_encoding_type;
-
-FINISH_OFF:
- EM_DEBUG_FUNC_END("err [%d]", err);
- return err;
-}
-
-INTERNAL_FUNC int em_get_content_type_from_extension_string(const char *extension_string, int *err_code)
-{
- EM_DEBUG_FUNC_BEGIN("extension_string[%s]", extension_string);
- int i = 0, err = EMF_ERROR_NONE, result_content_type = TYPEAPPLICATION;
- char *image_extension[] = { "jpeg", "jpg", "png", "gif", "bmp", "pic", "agif", "tif", "wbmp" , NULL};
-
- if (!extension_string) {
- EM_DEBUG_EXCEPTION("Invalid Parameter");
- err = EMF_ERROR_INVALID_PARAM;
- goto FINISH_OFF;
- }
-
- while(image_extension[i]) {
- EM_DEBUG_LOG("image_extension[%d] [%s]", i, image_extension[i]);
- if(strcasecmp(image_extension[i], extension_string) == 0) {
- result_content_type = TYPEIMAGE;
- break;
- }
- i++;
- }
-
-FINISH_OFF:
- if (err_code)
- *err_code = err;
- EM_DEBUG_FUNC_END();
- return result_content_type;
-}
-
-#define EMAIL_ACCOUNT_RGEX "([a-z0-9!#$%&'*+/=?^_`{|}~-]+.)*[a-z0-9!#$%&'*+/=?^_`{|}~-]+"
-#define EMAIL_DOMAIN_RGEX "([a-z0-9!#$%&'*+/=?^_`{|}~-]+.)+[a-z0-9!#$%&'*+/=?^_`{|}~-]+"
-
-#define EMAIL_ADDR_RGEX "[[:space:]]*<"EMAIL_ACCOUNT_RGEX"@"EMAIL_DOMAIN_RGEX">[[:space:]]*"
-#define EMAIL_ALIAS_RGEX "([[:space:]]*\"[^\"]*\")?"EMAIL_ADDR_RGEX
-#define EMAIL_ALIAS_LIST_RGEX "^("EMAIL_ALIAS_RGEX"[;,])*"EMAIL_ALIAS_RGEX"[;,]?[[:space:]]*$"
-
-#define EMAIL_ADDR_WITHOUT_BRACKET_RGEX "[[:space:]]*"EMAIL_ACCOUNT_RGEX"@"EMAIL_DOMAIN_RGEX"[[:space:]]*"
-#define EMAIL_ALIAS_WITHOUT_BRACKET_RGEX "([[:space:]]*\"[^\"]*\")?"EMAIL_ADDR_WITHOUT_BRACKET_RGEX
-#define EMAIL_ALIAS_LIST_WITHOUT_BRACKET_RGEX "("EMAIL_ALIAS_WITHOUT_BRACKET_RGEX"[;,])*"EMAIL_ADDR_WITHOUT_BRACKET_RGEX"[;,]?[[:space:]]*$"
-
-INTERNAL_FUNC int em_verify_email_address(char *address, int without_bracket, int *err_code)
-{
- EM_DEBUG_FUNC_BEGIN("address[%s] without_bracket[%d]", address, without_bracket);
-
- /* this following code verfies the email alias string using reg. exp. */
- regex_t alias_list_regex = {0};
- int ret = false, error = EMF_ERROR_NONE;
- char *reg_rule = NULL;
-
- if(!address || strlen(address) == 0) {
- EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
- if (err_code)
- *err_code = EMF_ERROR_INVALID_PARAM;
- return false;
- }
-
- if(without_bracket)
- reg_rule = EMAIL_ALIAS_LIST_WITHOUT_BRACKET_RGEX;
- else
- reg_rule = EMAIL_ALIAS_LIST_RGEX;
-
- if (regcomp(&alias_list_regex, reg_rule, REG_ICASE | REG_EXTENDED)) {
- EM_DEBUG_EXCEPTION("email alias regex unrecognized");
- if (err_code)
- *err_code = EMF_ERROR_UNKNOWN;
- return false;
- }
-
- int alias_len = strlen(address) + 1;
- regmatch_t pmatch[alias_len];
-
- bzero(pmatch, alias_len);
-
- if (regexec(&alias_list_regex, address, alias_len, pmatch, 0) == REG_NOMATCH)
- EM_DEBUG_LOG("failed :[%s]", address);
- else {
- EM_DEBUG_LOG("success :[%s]", address);
- ret = true;
- }
-
- regfree(&alias_list_regex);
-
- if (err_code)
- *err_code = error;
-
- EM_DEBUG_FUNC_END("ret [%d]", ret);
- return ret;
-}
-
-INTERNAL_FUNC int em_verify_email_address_of_mail_data(emf_mail_data_t *mail_data, int without_bracket, int *err_code)
-{
- EM_DEBUG_FUNC_BEGIN("mail_data[%p] without_bracket[%d]", mail_data, without_bracket);
- char *address_array[4] = { mail_data->full_address_from, mail_data->full_address_to, mail_data->full_address_cc, mail_data->full_address_bcc};
- int ret = false, err = EMF_ERROR_NONE, i;
-
- /* check for email_address validation */
- for (i = 0; i < 4; i++) {
- if (address_array[i] && address_array[i][0] != 0) {
- if (!em_verify_email_address(address_array[i] , without_bracket, &err)) {
- err = EMF_ERROR_INVALID_ADDRESS;
- EM_DEBUG_EXCEPTION("Invalid Email Address [%d][%s]", i, address_array[i]);
- goto FINISH_OFF;
- }
- }
- }
- ret = true;
-FINISH_OFF:
- EM_DEBUG_FUNC_END("ret [%d]", ret);
- return ret;
-}
-
-INTERNAL_FUNC int em_verify_email_address_of_mail_tbl(emstorage_mail_tbl_t *input_mail_tbl, int input_without_bracket)
-{
- EM_DEBUG_FUNC_BEGIN("input_mail_tbl[%p] input_without_bracket[%d]", input_mail_tbl, input_without_bracket);
- char *address_array[4] = { input_mail_tbl->full_address_to, input_mail_tbl->full_address_cc, input_mail_tbl->full_address_bcc, input_mail_tbl->full_address_from};
- int err = EMF_ERROR_NONE, i;
-
- /* check for email_address validation */
- for (i = 0; i < 4; i++) {
- if (address_array[i] && address_array[i][0] != 0) {
- if (!em_verify_email_address(address_array[i] , input_without_bracket, &err)) {
- err = EMF_ERROR_INVALID_ADDRESS;
- EM_DEBUG_EXCEPTION("Invalid Email Address [%d][%s]", i, address_array[i]);
- goto FINISH_OFF;
- }
- }
- }
-
-FINISH_OFF:
- EM_DEBUG_FUNC_END("err [%d]", err);
- return err;
-}
-
-INTERNAL_FUNC int em_find_tag_for_thread_view(char *subject, int *result)
-{
- EM_DEBUG_FUNC_BEGIN();
- int error_code = EMF_ERROR_NONE;
- char *copy_of_subject = NULL;
-
- EM_IF_NULL_RETURN_VALUE(subject, EMF_ERROR_INVALID_PARAM);
- EM_IF_NULL_RETURN_VALUE(result, EMF_ERROR_INVALID_PARAM);
-
- *result = FALSE;
-
- copy_of_subject = EM_SAFE_STRDUP(subject);
-
- if (copy_of_subject == NULL) {
- EM_DEBUG_EXCEPTION("strdup is failed.");
- goto FINISH_OFF;
- }
-
- em_upper_string(copy_of_subject);
- EM_DEBUG_LOG("em_upper_string result : %s\n", copy_of_subject);
-
- if (strstr(copy_of_subject, "RE:") == NULL) {
- if (strstr(copy_of_subject, "FWD:") == NULL) {
- if (strstr(copy_of_subject, "FW:") != NULL)
- *result = TRUE;
- }
- else
- *result = TRUE;
- }
- else
- *result = TRUE;
-
-FINISH_OFF:
- EM_SAFE_FREE(copy_of_subject);
-
- EM_DEBUG_FUNC_END("result : %d", *result);
-
- return error_code;
-}
-
-INTERNAL_FUNC int em_find_pos_stripped_subject_for_thread_view(char *subject, char *stripped_subject)
-{
- EM_DEBUG_FUNC_BEGIN();
- int error_code = EMF_ERROR_NONE;
- int gap;
- char *copy_of_subject = NULL, *curpos = NULL, *result;
-
- EM_IF_NULL_RETURN_VALUE(subject, EMF_ERROR_INVALID_PARAM);
- EM_IF_NULL_RETURN_VALUE(stripped_subject, EMF_ERROR_INVALID_PARAM);
-
- copy_of_subject = EM_SAFE_STRDUP(subject);
-
- if (copy_of_subject == NULL) {
- EM_DEBUG_EXCEPTION("strdup is failed");
- goto FINISH_OFF;
- }
-
- em_upper_string(copy_of_subject);
- curpos = copy_of_subject;
-
- EM_DEBUG_LOG("em_upper_string result : %s", copy_of_subject);
-
- while ((result = strstr(curpos, "RE:")) != NULL) {
- curpos = result + 3;
- EM_DEBUG_LOG("RE result : %s", curpos);
- }
-
- while ((result = strstr(curpos, "FWD:")) != NULL) {
- curpos = result + 4;
- EM_DEBUG_LOG("FWD result : %s", curpos);
- }
-
- while ((result = strstr(curpos, "FW:")) != NULL) {
- curpos = result + 3;
- EM_DEBUG_LOG("FW result : %s", curpos);
- }
-
- while (curpos != NULL && *curpos == ' ') {
- curpos++;
- }
-
- gap = curpos - copy_of_subject;
-
- strcpy(stripped_subject, subject + gap);
-
-FINISH_OFF:
- EM_SAFE_FREE(copy_of_subject);
-
- if (error_code == EMF_ERROR_NONE && stripped_subject)
- EM_DEBUG_LOG("result[%s]", stripped_subject);
-
- EM_DEBUG_FUNC_END("error_code[%d]", error_code);
- return error_code;
-}
-
-
-/*
- * encoding base64
- */
-INTERNAL_FUNC int em_encode_base64(char *src, unsigned long src_len, char **enc, unsigned long* enc_len, int *err_code)
-{
- EM_DEBUG_FUNC_BEGIN();
-
- unsigned char *content;
- int ret = true, err = EMF_ERROR_NONE;
-
- if (err_code != NULL) {
- *err_code = EMF_ERROR_NONE;
- }
-
- content = rfc822_binary(src, src_len, enc_len);
-
- if (content)
- *enc = (char *)content;
- else {
- err = EMF_ERROR_UNKNOWN;
- ret = false;
- }
-
- if (err_code)
- *err_code = err;
-
- EM_DEBUG_FUNC_END();
- return ret;
-}
-
-/*
- * decoding base64
- */
-INTERNAL_FUNC int em_decode_base64(unsigned char *enc_text, unsigned long enc_len, char **dec_text, unsigned long* dec_len, int *err_code)
-{
- unsigned char *text = enc_text;
- unsigned long size = enc_len;
- unsigned char *content;
- int ret = true, err = EMF_ERROR_NONE;
-
- if (err_code != NULL) {
- *err_code = EMF_ERROR_NONE;
- }
-
- EM_DEBUG_FUNC_BEGIN();
-
- content = rfc822_base64(text, size, dec_len);
- if (content)
- *dec_text = (char *)content;
- else
- {
- err = EMF_ERROR_UNKNOWN;
- ret = false;
- }
-
- if (err_code)
- *err_code = err;
-
- return ret;
-}
+/*
+* email-service
+*
+* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+*
+* Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com>
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*
+*/
+
+/*
+ * email-utilities.c
+ *
+ * Created on: 2012. 3. 6.
+ * Author: kyuho.jo@samsung.com
+ */
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+#include <errno.h>
+#include <sys/time.h>
+#include <sys/vfs.h>
+#include <unistd.h>
+#include <malloc.h>
+#include <pthread.h>
+#include <regex.h>
+
+#include "c-client.h"
+
+#include "email-types.h"
+#include "email-internal-types.h"
+#include "email-utilities.h"
+
+INTERNAL_FUNC void* em_malloc(int len)
+{
+ /* EM_DEBUG_LOG("Memory allocation size[%d] bytes", len); */
+ if (len <= 0) {
+ EM_DEBUG_EXCEPTION("len should be positive.[%d]", len);
+ return NULL;
+ }
+
+ void *p = calloc(1,len);
+ if (!p)
+ EM_DEBUG_PERROR("malloc failed");
+
+ return p;
+}
+
+
+INTERNAL_FUNC void* em_memdup(void* src, int len)
+{
+ /* EM_DEBUG_LOG("Memory allocation size[%d] bytes", len); */
+ if (len <= 0) {
+ EM_DEBUG_EXCEPTION("len should be positive.[%d]", len);
+ return NULL;
+ }
+
+ void *p = calloc(1,len);
+ if (!p)
+ EM_DEBUG_EXCEPTION("malloc failed");
+
+ memcpy(p, src, len);
+
+ return p;
+}
+
+
+/* remove left space, tab, CR, L */
+INTERNAL_FUNC char *em_trim_left(char *str)
+{
+ char *p, *temp_buffer = NULL;
+
+ /* EM_DEBUG_FUNC_BEGIN() */
+ if (!str) return NULL;
+
+ p = str;
+ while (*p && (*p == ' ' || *p == '\t' || *p == LF || *p == CR)) p++;
+
+ if (!*p) return NULL;
+
+ temp_buffer = EM_SAFE_STRDUP(p);
+
+ strncpy(str, temp_buffer, strlen(str));
+ str[strlen(temp_buffer)] = NULL_CHAR;
+
+ EM_SAFE_FREE(temp_buffer);
+
+ return str;
+}
+
+/* remove right space, tab, CR, L */
+INTERNAL_FUNC char *em_trim_right(char *str)
+{
+ char *p;
+
+ /* EM_DEBUG_FUNC_BEGIN() */
+ if (!str) return NULL;
+
+ p = str+strlen(str)-1;
+ while (((int)p >= (int)str) && (*p == ' ' || *p == '\t' || *p == LF || *p == CR))
+ *p --= '\0';
+
+ if ((int) p < (int)str)
+ return NULL;
+
+ return str;
+}
+
+INTERNAL_FUNC char* em_upper_string(char *str)
+{
+ char *p = str;
+ while (*p) {
+ *p = toupper(*p);
+ p++;
+ }
+ return str;
+}
+
+INTERNAL_FUNC char* em_lower_string(char *str)
+{
+ char *p = str;
+ while (*p) {
+ *p = tolower(*p);
+ p++;
+ }
+ return str;
+}
+
+INTERNAL_FUNC int em_upper_path(char *path)
+{
+ int i = 0, is_utf7 = 0, len = path ? (int)strlen(path) : -1;
+ for (; i < len; i++) {
+ if (path[i] == '&' || path[i] == 5) {
+ is_utf7 = 1;
+ }
+ else {
+ if (is_utf7) {
+ if (path[i] == '-') is_utf7 = 0;
+ }
+ else {
+ path[i] = toupper(path[i]);
+ }
+ }
+ }
+
+ return 1;
+}
+
+INTERNAL_FUNC void em_skip_whitespace(char *addr_str, char **pAddr)
+{
+ EM_DEBUG_FUNC_BEGIN("addr_str[%p]", addr_str);
+
+ if (!addr_str)
+ return ;
+ char *str = addr_str;
+ char ptr[strlen(str)+1] ;
+ int i, j = 0;
+
+ str = addr_str ;
+ for (i = 0; str[i] != NULL_CHAR ; i++) {
+ if (str[i] != SPACE && str[i] != TAB && str[i] != CR && str[i] != LF)
+ ptr[j++] = str[i];
+ }
+ ptr[j] = NULL_CHAR;
+
+ *pAddr = EM_SAFE_STRDUP(ptr);
+ EM_DEBUG_FUNC_END("ptr[%s]", ptr);
+}
+
+INTERNAL_FUNC char* em_skip_whitespace_without_strdup(char *source_string)
+{
+ EM_DEBUG_FUNC_BEGIN("source_string[%p]", source_string);
+
+ if (!source_string)
+ return NULL;
+ int i;
+
+ for (i = 0; source_string[i] != NULL_CHAR ; i++) {
+ if (source_string[i] != SPACE) /* || source_string[i] != TAB || source_string[i] != CR || source_string[i] || LF) */
+ break;
+ }
+
+ EM_DEBUG_FUNC_END("i[%d]", i);
+ return source_string + i;
+}
+
+
+INTERNAL_FUNC char* em_replace_all_string(char *source_string, char *old_string, char *new_string)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ char *result_buffer = NULL;
+ char *p = NULL;
+ 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 = strlen(old_string);
+ new_str_length = 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) {
+ count++;
+ i += old_str_length;
+ } else {
+ i++;
+ }
+ }
+ } else {
+ i = strlen(source_string);
+ }
+
+ result_buffer = (char *)malloc(i + 1 + count*(new_str_length-old_str_length));
+ if (result_buffer == NULL)
+ return NULL;
+
+ p = result_buffer;
+ while (*source_string) {
+ if (memcmp(source_string, old_string, old_str_length) == 0) {
+ memcpy(p, new_string, new_str_length);
+ p += new_str_length;
+ source_string += old_str_length;
+ } else {
+ *p++ = *source_string++;
+ }
+ }
+ *p = '\0';
+
+ EM_DEBUG_FUNC_END("result_buffer : %s", result_buffer);
+ return result_buffer;
+}
+
+INTERNAL_FUNC char* em_replace_string(char *source_string, char *old_string, char *new_string)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ char *result_buffer = NULL;
+ char *p = NULL;
+ int buffer_length = 0;
+
+ EM_IF_NULL_RETURN_VALUE(source_string, NULL);
+ EM_IF_NULL_RETURN_VALUE(old_string, NULL);
+ EM_IF_NULL_RETURN_VALUE(new_string, NULL);
+
+ p = strstr(source_string, old_string);
+
+ if (p == NULL) {
+ EM_DEBUG_EXCEPTION("old_string not found in source_string");
+ EM_DEBUG_FUNC_END("return NULL");
+ return NULL;
+ }
+
+ buffer_length = strlen(source_string) + 1024;
+ result_buffer = (char *)em_malloc(buffer_length);
+
+ if (!result_buffer) {
+ EM_DEBUG_EXCEPTION("em_malloc failed");
+ return NULL;
+ }
+
+ strncpy(result_buffer, source_string, p - source_string);
+ snprintf(result_buffer + strlen(result_buffer), buffer_length - strlen(result_buffer), "%s%s", new_string, p + strlen(old_string));
+
+ EM_DEBUG_FUNC_END("result_buffer[%s]", result_buffer);
+ return result_buffer;
+}
+
+/* Memory clean up */
+#include <sys/mman.h>
+
+/* #define GETSP() ({ unsigned int sp; asm volatile ("mov %0, sp " : "=r"(sp)); sp;}) */
+#define BUF_SIZE 256
+#define PAGE_SIZE (1 << 12)
+#define _ALIGN_UP(addr, size) (((addr)+((size)-1))&(~((size)-1)))
+#define _ALIGN_DOWN(addr, size) ((addr)&(~((size)-1)))
+#define PAGE_ALIGN(addr) _ALIGN_DOWN(addr, PAGE_SIZE)
+
+int stack_trim(void)
+{
+ /*
+ char buf[BUF_SIZE];
+ FILE *file;
+ unsigned int stacktop;
+ int found = 0;
+ unsigned int sp;
+
+ asm volatile ("mov %0, sp " : "=r"(sp));
+
+ sprintf(buf, "/proc/%d/maps", getpid());
+ file = fopen(buf, "r");
+ while (fgets(buf, BUF_SIZE, file) != NULL) {
+ if (strstr(buf, "[stack]")) {
+ found = 1;
+ break;
+ }
+ }
+
+ fclose(file);
+
+ if (found) {
+ sscanf(buf, "%x-", &stacktop);
+ if (madvise((void *)PAGE_ALIGN(stacktop), PAGE_ALIGN(sp)-stacktop, MADV_DONTNEED) < 0)
+ perror("stack madvise fail");
+ }
+ */
+ return 1;
+}
+
+INTERNAL_FUNC void em_flush_memory()
+{
+ EM_DEBUG_FUNC_BEGIN();
+ /* flush memory in heap */
+ malloc_trim(0);
+
+ /* flush memory in stack */
+ stack_trim();
+
+ /* flush memory for sqlite */
+ emstorage_flush_db_cache();
+ EM_DEBUG_FUNC_END();
+}
+
+INTERNAL_FUNC int em_get_file_name_and_extension_from_file_path(char *input_source_file_path, char **output_file_name, char **output_extension)
+{
+ EM_DEBUG_FUNC_BEGIN("input_source_file_path[%s], output_file_name [%p], output_extension [%p]", input_source_file_path, output_file_name, output_extension);
+ int err = EMAIL_ERROR_NONE;
+ int pos_on_string = 0;
+ int file_name_length = 0;
+ int extention_length = 0;
+ char *start_pos_of_file_name = NULL;
+ char *end_pos_of_file_name = NULL;
+ char *dot_pos_of_file_path = NULL;
+ char *end_pos_of_file_path = NULL;
+ char file_name_string[MAX_PATH] = { 0, };
+ char extension_string[MAX_PATH] = { 0, };
+
+ if (!input_source_file_path || !output_file_name || !output_extension) {
+ EM_DEBUG_EXCEPTION("Invalid Parameter");
+ err = EMAIL_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ pos_on_string = strlen(input_source_file_path) - 1;
+ end_pos_of_file_path = input_source_file_path + pos_on_string;
+ end_pos_of_file_name = end_pos_of_file_path;
+
+ while(pos_on_string >= 0 && input_source_file_path[pos_on_string] != '/') {
+ if(input_source_file_path[pos_on_string] == '.') {
+ if(dot_pos_of_file_path == NULL) {
+ end_pos_of_file_name = input_source_file_path + pos_on_string;
+ dot_pos_of_file_path = end_pos_of_file_name;
+ }
+ }
+ pos_on_string--;
+ }
+
+ pos_on_string++;
+
+ if(pos_on_string >= 0) {
+ start_pos_of_file_name = input_source_file_path + pos_on_string;
+ file_name_length = end_pos_of_file_name - start_pos_of_file_name;
+ memcpy(file_name_string, start_pos_of_file_name, file_name_length);
+ }
+
+ if(dot_pos_of_file_path != NULL) {
+ extention_length = (end_pos_of_file_path + 1) - (dot_pos_of_file_path + 1);
+ memcpy(extension_string, dot_pos_of_file_path + 1, extention_length);
+ }
+
+ EM_DEBUG_LOG("*file_name_string [%s] pos_on_string [%d]", file_name_string, pos_on_string);
+
+ *output_file_name = EM_SAFE_STRDUP(file_name_string);
+ *output_extension = EM_SAFE_STRDUP(extension_string);
+
+FINISH_OFF:
+ EM_DEBUG_FUNC_END("err = [%d]", err);
+ return err;
+}
+
+INTERNAL_FUNC char *em_get_extension_from_file_path(char *source_file_path, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("source_file_path[%s]", source_file_path);
+ int err = EMAIL_ERROR_NONE, pos_on_string = 0;
+ char *extension = NULL;
+
+ if (!source_file_path) {
+ EM_DEBUG_EXCEPTION("Invalid Parameter");
+ err = EMAIL_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ pos_on_string = strlen(source_file_path) - 1;
+
+ while(pos_on_string > 0 && source_file_path[pos_on_string--] != '.') ;
+
+ if(pos_on_string > 0)
+ extension = source_file_path + pos_on_string + 2;
+
+ EM_DEBUG_LOG("*extension [%s] pos_on_string [%d]", extension, pos_on_string);
+
+FINISH_OFF:
+ if (err_code)
+ *err_code = err;
+ EM_DEBUG_FUNC_END();
+ return extension;
+}
+
+INTERNAL_FUNC int em_get_encoding_type_from_file_path(const char *input_file_path, char **output_encoding_type)
+{
+ EM_DEBUG_FUNC_BEGIN("input_file_path[%d], output_encoding_type[%p]", input_file_path, output_encoding_type);
+ int err = EMAIL_ERROR_NONE;
+ int pos_of_filename = 0;
+ int pos_of_dot = 0;
+ int enf_of_string = 0;
+ int result_string_length = 0;
+ char *filename = NULL;
+ char *result_encoding_type = NULL;
+
+ if (!input_file_path || !output_encoding_type) {
+ EM_DEBUG_EXCEPTION("Invalid Parameter");
+ err = EMAIL_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ enf_of_string = pos_of_filename = strlen(input_file_path);
+
+ while(pos_of_filename >= 0 && input_file_path[pos_of_filename--] != '/') {
+ if(input_file_path[pos_of_filename] == '.')
+ pos_of_dot = pos_of_filename;
+ }
+
+ if(pos_of_filename != 0)
+ pos_of_filename += 2;
+
+ filename = (char*)input_file_path + pos_of_filename;
+
+ if(pos_of_dot != 0 && pos_of_dot > pos_of_filename)
+ result_string_length = pos_of_dot - pos_of_filename;
+ else
+ result_string_length = enf_of_string - pos_of_filename;
+
+ EM_DEBUG_LOG("pos_of_dot [%d], pos_of_filename [%d], enf_of_string[%d],result_string_length [%d]", pos_of_dot, pos_of_filename, enf_of_string, result_string_length);
+
+ if( !(result_encoding_type = em_malloc(sizeof(char) * (result_string_length + 1))) ) {
+ EM_DEBUG_EXCEPTION("EMAIL_ERROR_OUT_OF_MEMORY");
+ err = EMAIL_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ memcpy(result_encoding_type, input_file_path + pos_of_filename, result_string_length);
+
+ EM_DEBUG_LOG("*result_encoding_type [%s]", result_encoding_type);
+
+ *output_encoding_type = result_encoding_type;
+
+FINISH_OFF:
+ EM_DEBUG_FUNC_END("err [%d]", err);
+ return err;
+}
+
+INTERNAL_FUNC int em_get_content_type_from_extension_string(const char *extension_string, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("extension_string[%s]", extension_string);
+ int i = 0, err = EMAIL_ERROR_NONE, result_content_type = TYPEAPPLICATION;
+ char *image_extension[] = { "jpeg", "jpg", "png", "gif", "bmp", "pic", "agif", "tif", "wbmp" , NULL};
+
+ if (!extension_string) {
+ EM_DEBUG_EXCEPTION("Invalid Parameter");
+ err = EMAIL_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ while(image_extension[i]) {
+ EM_DEBUG_LOG("image_extension[%d] [%s]", i, image_extension[i]);
+ if(strcasecmp(image_extension[i], extension_string) == 0) {
+ result_content_type = TYPEIMAGE;
+ break;
+ }
+ i++;
+ }
+
+FINISH_OFF:
+ if (err_code)
+ *err_code = err;
+ EM_DEBUG_FUNC_END();
+ return result_content_type;
+}
+
+#define EMAIL_ACCOUNT_RGEX "([a-z0-9!#$%&'*+/=?^_`{|}~-]+.)*[a-z0-9!#$%&'*+/=?^_`{|}~-]+"
+#define EMAIL_DOMAIN_RGEX "([a-z0-9!#$%&'*+/=?^_`{|}~-]+.)+[a-z0-9!#$%&'*+/=?^_`{|}~-]+"
+
+#define EMAIL_ADDR_RGEX "[[:space:]]*<"EMAIL_ACCOUNT_RGEX"@"EMAIL_DOMAIN_RGEX">[[:space:]]*"
+#define EMAIL_ALIAS_RGEX "([[:space:]]*\"[^\"]*\")?"EMAIL_ADDR_RGEX
+#define EMAIL_ALIAS_LIST_RGEX "^("EMAIL_ALIAS_RGEX"[;,])*"EMAIL_ALIAS_RGEX"[;,]?[[:space:]]*$"
+
+#define EMAIL_ADDR_WITHOUT_BRACKET_RGEX "[[:space:]]*"EMAIL_ACCOUNT_RGEX"@"EMAIL_DOMAIN_RGEX"[[:space:]]*"
+#define EMAIL_ALIAS_WITHOUT_BRACKET_RGEX "([[:space:]]*\"[^\"]*\")?"EMAIL_ADDR_WITHOUT_BRACKET_RGEX
+#define EMAIL_ALIAS_LIST_WITHOUT_BRACKET_RGEX "("EMAIL_ALIAS_WITHOUT_BRACKET_RGEX"[;,])*"EMAIL_ADDR_WITHOUT_BRACKET_RGEX"[;,]?[[:space:]]*$"
+
+INTERNAL_FUNC int em_verify_email_address(char *address, int without_bracket, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("address[%s] without_bracket[%d]", address, without_bracket);
+
+ /* this following code verfies the email alias string using reg. exp. */
+ regex_t alias_list_regex = {0};
+ int ret = false, error = EMAIL_ERROR_NONE;
+ char *reg_rule = NULL;
+
+ if(!address || strlen(address) == 0) {
+ EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
+ if (err_code)
+ *err_code = EMAIL_ERROR_INVALID_PARAM;
+ return false;
+ }
+
+ if(without_bracket)
+ reg_rule = EMAIL_ALIAS_LIST_WITHOUT_BRACKET_RGEX;
+ else
+ reg_rule = EMAIL_ALIAS_LIST_RGEX;
+
+ if (regcomp(&alias_list_regex, reg_rule, REG_ICASE | REG_EXTENDED)) {
+ EM_DEBUG_EXCEPTION("email alias regex unrecognized");
+ if (err_code)
+ *err_code = EMAIL_ERROR_UNKNOWN;
+ return false;
+ }
+
+ int alias_len = strlen(address) + 1;
+ regmatch_t pmatch[alias_len];
+
+ bzero(pmatch, alias_len);
+
+ if (regexec(&alias_list_regex, address, alias_len, pmatch, 0) == REG_NOMATCH)
+ EM_DEBUG_LOG("failed :[%s]", address);
+ else {
+ EM_DEBUG_LOG("success :[%s]", address);
+ ret = true;
+ }
+
+ regfree(&alias_list_regex);
+
+ if (err_code)
+ *err_code = error;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+INTERNAL_FUNC int em_verify_email_address_of_mail_data(email_mail_data_t *mail_data, int without_bracket, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("mail_data[%p] without_bracket[%d]", mail_data, without_bracket);
+ char *address_array[4] = { mail_data->full_address_from, mail_data->full_address_to, mail_data->full_address_cc, mail_data->full_address_bcc};
+ int ret = false, err = EMAIL_ERROR_NONE, i;
+
+ /* check for email_address validation */
+ for (i = 0; i < 4; i++) {
+ if (address_array[i] && address_array[i][0] != 0) {
+ if (!em_verify_email_address(address_array[i] , without_bracket, &err)) {
+ err = EMAIL_ERROR_INVALID_ADDRESS;
+ EM_DEBUG_EXCEPTION("Invalid Email Address [%d][%s]", i, address_array[i]);
+ goto FINISH_OFF;
+ }
+ }
+ }
+ ret = true;
+FINISH_OFF:
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+INTERNAL_FUNC int em_verify_email_address_of_mail_tbl(emstorage_mail_tbl_t *input_mail_tbl, int input_without_bracket)
+{
+ EM_DEBUG_FUNC_BEGIN("input_mail_tbl[%p] input_without_bracket[%d]", input_mail_tbl, input_without_bracket);
+ char *address_array[4] = { input_mail_tbl->full_address_to, input_mail_tbl->full_address_cc, input_mail_tbl->full_address_bcc, input_mail_tbl->full_address_from};
+ int err = EMAIL_ERROR_NONE, i;
+
+ /* check for email_address validation */
+ for (i = 0; i < 4; i++) {
+ if (address_array[i] && address_array[i][0] != 0) {
+ if (!em_verify_email_address(address_array[i] , input_without_bracket, &err)) {
+ err = EMAIL_ERROR_INVALID_ADDRESS;
+ EM_DEBUG_EXCEPTION("Invalid Email Address [%d][%s]", i, address_array[i]);
+ goto FINISH_OFF;
+ }
+ }
+ }
+
+FINISH_OFF:
+ EM_DEBUG_FUNC_END("err [%d]", err);
+ return err;
+}
+
+INTERNAL_FUNC int em_find_tag_for_thread_view(char *subject, int *result)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int error_code = EMAIL_ERROR_NONE;
+ char *copy_of_subject = NULL;
+
+ EM_IF_NULL_RETURN_VALUE(subject, EMAIL_ERROR_INVALID_PARAM);
+ EM_IF_NULL_RETURN_VALUE(result, EMAIL_ERROR_INVALID_PARAM);
+
+ *result = FALSE;
+
+ copy_of_subject = EM_SAFE_STRDUP(subject);
+
+ if (copy_of_subject == NULL) {
+ EM_DEBUG_EXCEPTION("strdup is failed.");
+ goto FINISH_OFF;
+ }
+
+ em_upper_string(copy_of_subject);
+ EM_DEBUG_LOG("em_upper_string result : %s\n", copy_of_subject);
+
+ if (strstr(copy_of_subject, "RE:") == NULL) {
+ if (strstr(copy_of_subject, "FWD:") == NULL) {
+ if (strstr(copy_of_subject, "FW:") != NULL)
+ *result = TRUE;
+ }
+ else
+ *result = TRUE;
+ }
+ else
+ *result = TRUE;
+
+FINISH_OFF:
+ EM_SAFE_FREE(copy_of_subject);
+
+ EM_DEBUG_FUNC_END("result : %d", *result);
+
+ return error_code;
+}
+
+INTERNAL_FUNC int em_find_pos_stripped_subject_for_thread_view(char *subject, char *stripped_subject)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int error_code = EMAIL_ERROR_NONE;
+ int gap;
+ char *copy_of_subject = NULL, *curpos = NULL, *result;
+
+ EM_IF_NULL_RETURN_VALUE(subject, EMAIL_ERROR_INVALID_PARAM);
+ EM_IF_NULL_RETURN_VALUE(stripped_subject, EMAIL_ERROR_INVALID_PARAM);
+
+ copy_of_subject = EM_SAFE_STRDUP(subject);
+
+ if (copy_of_subject == NULL) {
+ EM_DEBUG_EXCEPTION("strdup is failed");
+ goto FINISH_OFF;
+ }
+
+ em_upper_string(copy_of_subject);
+ curpos = copy_of_subject;
+
+ EM_DEBUG_LOG("em_upper_string result : %s", copy_of_subject);
+
+ while ((result = strstr(curpos, "RE:")) != NULL) {
+ curpos = result + 3;
+ EM_DEBUG_LOG("RE result : %s", curpos);
+ }
+
+ while ((result = strstr(curpos, "FWD:")) != NULL) {
+ curpos = result + 4;
+ EM_DEBUG_LOG("FWD result : %s", curpos);
+ }
+
+ while ((result = strstr(curpos, "FW:")) != NULL) {
+ curpos = result + 3;
+ EM_DEBUG_LOG("FW result : %s", curpos);
+ }
+
+ while (curpos != NULL && *curpos == ' ') {
+ curpos++;
+ }
+
+ gap = curpos - copy_of_subject;
+
+ strcpy(stripped_subject, subject + gap);
+
+FINISH_OFF:
+ EM_SAFE_FREE(copy_of_subject);
+
+ if (error_code == EMAIL_ERROR_NONE && stripped_subject)
+ EM_DEBUG_LOG("result[%s]", stripped_subject);
+
+ EM_DEBUG_FUNC_END("error_code[%d]", error_code);
+ return error_code;
+}
+
+
+/*
+ * encoding base64
+ */
+INTERNAL_FUNC int em_encode_base64(char *src, unsigned long src_len, char **enc, unsigned long* enc_len, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ unsigned char *content;
+ int ret = true, err = EMAIL_ERROR_NONE;
+
+ if (err_code != NULL) {
+ *err_code = EMAIL_ERROR_NONE;
+ }
+
+ content = rfc822_binary(src, src_len, enc_len);
+
+ if (content)
+ *enc = (char *)content;
+ else {
+ err = EMAIL_ERROR_UNKNOWN;
+ ret = false;
+ }
+
+ if (err_code)
+ *err_code = err;
+
+ EM_DEBUG_FUNC_END();
+ return ret;
+}
+
+/*
+ * decoding base64
+ */
+INTERNAL_FUNC int em_decode_base64(unsigned char *enc_text, unsigned long enc_len, char **dec_text, unsigned long* dec_len, int *err_code)
+{
+ unsigned char *text = enc_text;
+ unsigned long size = enc_len;
+ unsigned char *content;
+ int ret = true, err = EMAIL_ERROR_NONE;
+
+ if (err_code != NULL) {
+ *err_code = EMAIL_ERROR_NONE;
+ }
+
+ EM_DEBUG_FUNC_BEGIN();
+
+ content = rfc822_base64(text, size, dec_len);
+ if (content)
+ *dec_text = (char *)content;
+ else
+ {
+ err = EMAIL_ERROR_UNKNOWN;
+ ret = false;
+ }
+
+ if (err_code)
+ *err_code = err;
+
+ return ret;
+}
+
+INTERNAL_FUNC int em_get_account_server_type_by_account_id(int account_id, email_account_server_t* account_server_type, int flag, int *error)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ emstorage_account_tbl_t *account_tbl_data = NULL;
+ int ret = false;
+ int err= EMAIL_ERROR_NONE;
+
+ if (account_server_type == NULL ) {
+ EM_DEBUG_EXCEPTION("account_server_type is NULL");
+ err = EMAIL_ERROR_INVALID_PARAM;
+ ret = false;
+ goto FINISH_OFF;
+ }
+
+ if( !emstorage_get_account_by_id(account_id, WITHOUT_OPTION, &account_tbl_data, false, &err)) {
+ EM_DEBUG_EXCEPTION ("emstorage_get_account_by_id failed [%d] ", err);
+ ret = false;
+ goto FINISH_OFF;
+ }
+
+ if ( flag == false ) { /* sending server */
+ *account_server_type = account_tbl_data->outgoing_server_type;
+ } else if ( flag == true ) { /* receiving server */
+ *account_server_type = account_tbl_data->incoming_server_type;
+ }
+
+ ret = true;
+
+FINISH_OFF:
+ if ( account_tbl_data != NULL ) {
+ emstorage_free_account(&account_tbl_data, 1, NULL);
+ }
+ if ( error != NULL ) {
+ *error = err;
+ }
+
+ return ret;
+}
+
+#include <vconf.h>
+#include <dbus/dbus.h>
+
+#define ACTIVE_SYNC_HANDLE_INIT_VALUE (-1)
+#define ACTIVE_SYNC_HANDLE_BOUNDARY (-100000000)
+
+
+INTERNAL_FUNC int em_get_handle_for_activesync(int *handle, int *error)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ static int next_handle = 0;
+ int ret = false;
+ int err = EMAIL_ERROR_NONE;
+
+ if ( handle == NULL ) {
+ EM_DEBUG_EXCEPTION("em_get_handle_for_activesync failed : handle is NULL");
+ err = EMAIL_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ if ( vconf_get_int(VCONFKEY_EMAIL_SERVICE_ACTIVE_SYNC_HANDLE, &next_handle) != 0 ) {
+ EM_DEBUG_EXCEPTION("vconf_get_int failed");
+ if ( next_handle != 0 ) {
+ err = EMAIL_ERROR_GCONF_FAILURE;
+ goto FINISH_OFF;
+ }
+ }
+
+ EM_DEBUG_LOG(">>>>>> VCONFKEY_EMAIL_SERVICE_ACTIVE_SYNC_HANDLE : get lastest handle[%d]", next_handle);
+
+ /* set the value of the handle for active sync */
+ next_handle--;
+ if ( next_handle < ACTIVE_SYNC_HANDLE_BOUNDARY ) {
+ next_handle = ACTIVE_SYNC_HANDLE_INIT_VALUE;
+ }
+ if ( vconf_set_int(VCONFKEY_EMAIL_SERVICE_ACTIVE_SYNC_HANDLE, next_handle) != 0) {
+ EM_DEBUG_EXCEPTION("vconf_set_int failed");
+ err = EMAIL_ERROR_GCONF_FAILURE;
+ goto FINISH_OFF;
+ }
+ ret = true;
+ *handle = next_handle;
+ EM_DEBUG_LOG(">>>>>> return next handle[%d]", *handle);
+
+FINISH_OFF:
+ if ( error != NULL ) {
+ *error = err;
+ }
+
+ return ret;
+}
+
+INTERNAL_FUNC int em_send_notification_to_active_sync_engine(int subType, ASNotiData *data)
+{
+ EM_DEBUG_FUNC_BEGIN("subType [%d], data [%p]", subType, data);
+
+ DBusConnection *connection;
+ DBusMessage *signal = NULL;
+ DBusError error;
+ const char *nullString = "";
+ int i = 0;
+
+ dbus_error_init (&error);
+ connection = dbus_bus_get(DBUS_BUS_SYSTEM, &error);
+
+ if(connection == NULL)
+ goto FINISH_OFF;
+
+ signal = dbus_message_new_signal("/User/Email/ActiveSync", EMAIL_ACTIVE_SYNC_NOTI, "email");
+
+ dbus_message_append_args(signal, DBUS_TYPE_INT32, &subType, DBUS_TYPE_INVALID);
+ switch ( subType ) {
+ case ACTIVE_SYNC_NOTI_SEND_MAIL:
+ EM_DEBUG_LOG("handle:[%d]", data->send_mail.handle);
+ EM_DEBUG_LOG("account_id:[%d]", data->send_mail.account_id);
+ EM_DEBUG_LOG("mail_id:[%d]", data->send_mail.mail_id);
+ EM_DEBUG_LOG("options.priority:[%d]", data->send_mail.options.priority);
+ EM_DEBUG_LOG("options.keep_local_copy:[%d]", data->send_mail.options.keep_local_copy);
+ EM_DEBUG_LOG("options.req_delivery_receipt:[%d]", data->send_mail.options.req_delivery_receipt);
+ EM_DEBUG_LOG("options.req_read_receipt:[%d]", data->send_mail.options.req_read_receipt);
+ /* download_limit, block_address, block_subject might not be needed */
+ EM_DEBUG_LOG("options.download_limit:[%d]", data->send_mail.options.download_limit);
+ EM_DEBUG_LOG("options.block_address:[%d]", data->send_mail.options.block_address);
+ EM_DEBUG_LOG("options.block_subject:[%d]", data->send_mail.options.block_subject);
+ EM_DEBUG_LOG("options.display_name_from:[%s]", data->send_mail.options.display_name_from);
+ EM_DEBUG_LOG("options.reply_with_body:[%d]", data->send_mail.options.reply_with_body);
+ EM_DEBUG_LOG("options.forward_with_files:[%d]", data->send_mail.options.forward_with_files);
+ EM_DEBUG_LOG("options.add_myname_card:[%d]", data->send_mail.options.add_myname_card);
+ EM_DEBUG_LOG("options.add_signature:[%d]", data->send_mail.options.add_signature);
+ EM_DEBUG_LOG("options.signature:[%s]", data->send_mail.options.signature);
+
+ dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->send_mail.handle), DBUS_TYPE_INVALID);
+ dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->send_mail.account_id), DBUS_TYPE_INVALID);
+ dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->send_mail.mail_id), DBUS_TYPE_INVALID);
+ dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->send_mail.options.priority), DBUS_TYPE_INVALID);
+ dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->send_mail.options.keep_local_copy), DBUS_TYPE_INVALID);
+ dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->send_mail.options.req_delivery_receipt), DBUS_TYPE_INVALID);
+ dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->send_mail.options.req_read_receipt), DBUS_TYPE_INVALID);
+ if ( data->send_mail.options.display_name_from == NULL )
+ dbus_message_append_args(signal, DBUS_TYPE_STRING, &(nullString), DBUS_TYPE_INVALID);
+ else
+ dbus_message_append_args(signal, DBUS_TYPE_STRING, &(data->send_mail.options.display_name_from), DBUS_TYPE_INVALID);
+
+ dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->send_mail.options.reply_with_body), DBUS_TYPE_INVALID);
+ dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->send_mail.options.forward_with_files), DBUS_TYPE_INVALID);
+ dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->send_mail.options.add_myname_card), DBUS_TYPE_INVALID);
+ dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->send_mail.options.add_signature), DBUS_TYPE_INVALID);
+ if ( data->send_mail.options.signature == NULL )
+ dbus_message_append_args(signal, DBUS_TYPE_STRING, &(nullString), DBUS_TYPE_INVALID);
+ else
+ dbus_message_append_args(signal, DBUS_TYPE_STRING, &(data->send_mail.options.signature), DBUS_TYPE_INVALID);
+
+ break;
+ case ACTIVE_SYNC_NOTI_SEND_SAVED: /* publish a send notification to ASE (active sync engine) */
+ EM_DEBUG_EXCEPTION("Not support yet : subType[ACTIVE_SYNC_NOTI_SEND_SAVED]", subType);
+ break;
+ case ACTIVE_SYNC_NOTI_SEND_REPORT:
+ EM_DEBUG_EXCEPTION("Not support yet : subType[ACTIVE_SYNC_NOTI_SEND_REPORT]", subType);
+ break;
+ case ACTIVE_SYNC_NOTI_SYNC_HEADER:
+ EM_DEBUG_LOG("handle:[%d]", data->sync_header.handle);
+ EM_DEBUG_LOG("account_id:[%d]", data->sync_header.account_id);
+ EM_DEBUG_LOG("mailbox_id:[%d]", data->sync_header.mailbox_id);
+
+ dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->sync_header.handle ), DBUS_TYPE_INVALID);
+ dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->sync_header.account_id ), DBUS_TYPE_INVALID);
+ dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->sync_header.mailbox_id ), DBUS_TYPE_INVALID);
+ break;
+ case ACTIVE_SYNC_NOTI_DOWNLOAD_BODY: /* publish a download body notification to ASE */
+ EM_DEBUG_LOG("handle:[%d]", data->download_body.handle);
+ EM_DEBUG_LOG("account_id:[%d]", data->download_body.account_id);
+ EM_DEBUG_LOG("mail_id:[%d]", data->download_body.mail_id);
+ EM_DEBUG_LOG("with_attachment:[%d]", data->download_body.with_attachment);
+
+ dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->download_body.handle ), DBUS_TYPE_INVALID);
+ dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->download_body.account_id ), DBUS_TYPE_INVALID);
+ dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->download_body.mail_id ), DBUS_TYPE_INVALID);
+ dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->download_body.with_attachment ), DBUS_TYPE_INVALID);
+ break;
+ case ACTIVE_SYNC_NOTI_DOWNLOAD_ATTACHMENT:
+ EM_DEBUG_LOG("handle:[%d]", data->download_attachment.handle);
+ EM_DEBUG_LOG("account_id:[%d]", data->download_attachment.account_id );
+ EM_DEBUG_LOG("mail_id:[%d]", data->download_attachment.mail_id);
+ EM_DEBUG_LOG("with_attachment:[%d]", data->download_attachment.attachment_order );
+
+ dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->download_attachment.handle ), DBUS_TYPE_INVALID);
+ dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->download_attachment.account_id ), DBUS_TYPE_INVALID);
+ dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->download_attachment.mail_id ), DBUS_TYPE_INVALID);
+ dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->download_attachment.attachment_order), DBUS_TYPE_INVALID);
+ break;
+ case ACTIVE_SYNC_NOTI_VALIDATE_ACCOUNT:
+ EM_DEBUG_EXCEPTION("Not support yet : subType[ACTIVE_SYNC_NOTI_VALIDATE_ACCOUNT]", subType);
+ break;
+ case ACTIVE_SYNC_NOTI_CANCEL_JOB:
+ EM_DEBUG_LOG("account_id:[%d]", data->cancel_job.account_id );
+ EM_DEBUG_LOG("handle to cancel:[%d]", data->cancel_job.handle);
+ EM_DEBUG_LOG("cancel_type:[%d]", data->cancel_job.cancel_type);
+
+ dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->cancel_job.account_id ), DBUS_TYPE_INVALID);
+ dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->cancel_job.handle ), DBUS_TYPE_INVALID);
+ dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->cancel_job.cancel_type ), DBUS_TYPE_INVALID);
+ break;
+ case ACTIVE_SYNC_NOTI_SEARCH_ON_SERVER:
+ EM_DEBUG_LOG("account_id:[%d]", data->search_mail_on_server.account_id );
+ EM_DEBUG_LOG("mailbox_id:[%d]", data->search_mail_on_server.mailbox_id );
+ EM_DEBUG_LOG("search_filter_count:[%d]", data->search_mail_on_server.search_filter_count );
+ EM_DEBUG_LOG("handle to cancel:[%d]", data->search_mail_on_server.handle);
+
+ dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->search_mail_on_server.account_id), DBUS_TYPE_INVALID);
+ dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->search_mail_on_server.mailbox_id), DBUS_TYPE_INVALID);
+ dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->search_mail_on_server.search_filter_count), DBUS_TYPE_INVALID);
+ for(i = 0; i < data->search_mail_on_server.search_filter_count; i++) {
+ dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->search_mail_on_server.search_filter_list[i].search_filter_type), DBUS_TYPE_INVALID);
+ switch(data->search_mail_on_server.search_filter_list[i].search_filter_type) {
+ case EMAIL_SEARCH_FILTER_TYPE_MESSAGE_NO :
+ case EMAIL_SEARCH_FILTER_TYPE_UID :
+ case EMAIL_SEARCH_FILTER_TYPE_SIZE_LARSER :
+ case EMAIL_SEARCH_FILTER_TYPE_SIZE_SMALLER :
+ case EMAIL_SEARCH_FILTER_TYPE_FLAGS_ANSWERED :
+ case EMAIL_SEARCH_FILTER_TYPE_FLAGS_DELETED :
+ case EMAIL_SEARCH_FILTER_TYPE_FLAGS_DRAFT :
+ case EMAIL_SEARCH_FILTER_TYPE_FLAGS_FLAGED :
+ case EMAIL_SEARCH_FILTER_TYPE_FLAGS_RECENT :
+ case EMAIL_SEARCH_FILTER_TYPE_FLAGS_SEEN :
+ dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->search_mail_on_server.search_filter_list[i].search_filter_key_value.integer_type_key_value), DBUS_TYPE_INVALID);
+ break;
+
+ case EMAIL_SEARCH_FILTER_TYPE_BCC :
+ case EMAIL_SEARCH_FILTER_TYPE_CC :
+ case EMAIL_SEARCH_FILTER_TYPE_FROM :
+ case EMAIL_SEARCH_FILTER_TYPE_KEYWORD :
+ case EMAIL_SEARCH_FILTER_TYPE_SUBJECT :
+ case EMAIL_SEARCH_FILTER_TYPE_TO :
+ case EMAIL_SEARCH_FILTER_TYPE_MESSAGE_ID :
+ dbus_message_append_args(signal, DBUS_TYPE_STRING, &(data->search_mail_on_server.search_filter_list[i].search_filter_key_value.string_type_key_value), DBUS_TYPE_INVALID);
+ break;
+
+ case EMAIL_SEARCH_FILTER_TYPE_SENT_DATE_BEFORE :
+ case EMAIL_SEARCH_FILTER_TYPE_SENT_DATE_ON :
+ case EMAIL_SEARCH_FILTER_TYPE_SENT_DATE_SINCE :
+ dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->search_mail_on_server.search_filter_list[i].search_filter_key_value.time_type_key_value), DBUS_TYPE_INVALID);
+ break;
+ default :
+ EM_DEBUG_EXCEPTION("Invalid filter type [%d]", data->search_mail_on_server.search_filter_list[i].search_filter_type);
+ break;
+ }
+ }
+ dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->search_mail_on_server.handle), DBUS_TYPE_INVALID);
+ break;
+
+ case ACTIVE_SYNC_NOTI_CLEAR_RESULT_OF_SEARCH_ON_SERVER :
+ EM_DEBUG_LOG("account_id:[%d]", data->clear_result_of_search_mail_on_server.account_id );
+ dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->search_mail_on_server.account_id), DBUS_TYPE_INVALID);
+ break;
+
+ case ACTIVE_SYNC_NOTI_EXPUNGE_MAILS_DELETED_FLAGGED :
+ dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->expunge_mails_deleted_flagged.mailbox_id ), DBUS_TYPE_INVALID);
+ dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->expunge_mails_deleted_flagged.on_server ), DBUS_TYPE_INVALID);
+ dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->expunge_mails_deleted_flagged.handle ), DBUS_TYPE_INVALID);
+ break;
+
+ case ACTIVE_SYNC_NOTI_RESOLVE_RECIPIENT :
+ dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->get_resolve_recipients.account_id), DBUS_TYPE_INVALID);
+ dbus_message_append_args(signal, DBUS_TYPE_STRING, &(data->get_resolve_recipients.email_address), DBUS_TYPE_INVALID);
+ dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->get_resolve_recipients.handle), DBUS_TYPE_INVALID);
+ break;
+
+ case ACTIVE_SYNC_NOTI_VALIDATE_CERTIFICATE :
+ dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->validate_certificate.account_id), DBUS_TYPE_INVALID);
+ dbus_message_append_args(signal, DBUS_TYPE_STRING, &(data->validate_certificate.email_address), DBUS_TYPE_INVALID);
+ dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->validate_certificate.handle), DBUS_TYPE_INVALID);
+ break;
+
+ case ACTIVE_SYNC_NOTI_ADD_MAILBOX :
+ dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->add_mailbox.account_id), DBUS_TYPE_INVALID);
+ dbus_message_append_args(signal, DBUS_TYPE_STRING, &(data->add_mailbox.mailbox_path), DBUS_TYPE_INVALID);
+ dbus_message_append_args(signal, DBUS_TYPE_STRING, &(data->add_mailbox.mailbox_alias), DBUS_TYPE_INVALID);
+ dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->add_mailbox.handle), DBUS_TYPE_INVALID);
+ break;
+
+ case ACTIVE_SYNC_NOTI_RENAME_MAILBOX :
+ dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->rename_mailbox.account_id), DBUS_TYPE_INVALID);
+ dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->rename_mailbox.mailbox_id), DBUS_TYPE_INVALID);
+ dbus_message_append_args(signal, DBUS_TYPE_STRING, &(data->rename_mailbox.mailbox_name), DBUS_TYPE_INVALID);
+ dbus_message_append_args(signal, DBUS_TYPE_STRING, &(data->rename_mailbox.mailbox_alias), DBUS_TYPE_INVALID);
+ dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->rename_mailbox.handle), DBUS_TYPE_INVALID);
+ break;
+
+ case ACTIVE_SYNC_NOTI_DELETE_MAILBOX :
+ dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->delete_mailbox.account_id), DBUS_TYPE_INVALID);
+ dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->delete_mailbox.mailbox_id), DBUS_TYPE_INVALID);
+ dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->delete_mailbox.handle), DBUS_TYPE_INVALID);
+ break;
+
+ default:
+ EM_DEBUG_EXCEPTION("Invalid Notification type of Active Sync : subType[%d]", subType);
+ return FAILURE;
+ }
+
+ if(!dbus_connection_send (connection, signal, NULL)) {
+ EM_DEBUG_EXCEPTION("dbus_connection_send is failed");
+ return FAILURE;
+ } else
+ EM_DEBUG_LOG("dbus_connection_send is successful");
+
+ dbus_connection_flush(connection);
+
+FINISH_OFF:
+
+ if(signal)
+ dbus_message_unref(signal);
+
+ EM_DEBUG_FUNC_END();
+ return true;
+}
diff --git a/email-common-use/include/email-convert.h b/email-common-use/include/email-convert.h
index 72bbd04..ba040f5 100755
--- a/email-common-use/include/email-convert.h
+++ b/email-common-use/include/email-convert.h
@@ -28,58 +28,65 @@
#include "email-storage.h"
/* Account */
-INTERNAL_FUNC char* em_convert_account_to_byte_stream(emf_account_t* account, int* nStreamSize);
-INTERNAL_FUNC void em_convert_byte_stream_to_account(char* pAccountStream, emf_account_t* account);
-INTERNAL_FUNC int em_convert_account_to_account_tbl(emf_account_t *account, emstorage_account_tbl_t *account_tbl);
-INTERNAL_FUNC int em_convert_account_tbl_to_account(emstorage_account_tbl_t *account_tbl, emf_account_t *account);
+INTERNAL_FUNC char* em_convert_account_to_byte_stream(email_account_t* account, int* stream_len);
+INTERNAL_FUNC void em_convert_byte_stream_to_account(char* stream, int stream_len, email_account_t* account);
+INTERNAL_FUNC int em_convert_account_to_account_tbl(email_account_t *account, emstorage_account_tbl_t *account_tbl);
+INTERNAL_FUNC int em_convert_account_tbl_to_account(emstorage_account_tbl_t *account_tbl, email_account_t *account);
/* Mail */
-INTERNAL_FUNC char* em_convert_mail_data_to_byte_stream(emf_mail_data_t *input_mail_data, int intput_mail_data_count, int *output_stream_size);
-INTERNAL_FUNC void em_convert_byte_stream_to_mail_data(char *intput_stream, emf_mail_data_t **output_mail_data, int *output_mail_data_count);
+INTERNAL_FUNC char* em_convert_mail_data_to_byte_stream(email_mail_data_t *mail_data, int *stream_size);
+INTERNAL_FUNC void em_convert_byte_stream_to_mail_data(char *stream, int stream_len, email_mail_data_t *mail_data);
-INTERNAL_FUNC int em_convert_mail_tbl_to_mail_data(emstorage_mail_tbl_t *mail_table_data, int item_count, emf_mail_data_t **mail_data, int *error);
-INTERNAL_FUNC int em_convert_mail_data_to_mail_tbl(emf_mail_data_t *mail_data, int item_count, emstorage_mail_tbl_t **mail_table_data, int *error);
+INTERNAL_FUNC int em_convert_mail_tbl_to_mail_data(emstorage_mail_tbl_t *mail_table_data, int item_count, email_mail_data_t **mail_data, int *error);
+INTERNAL_FUNC int em_convert_mail_data_to_mail_tbl(email_mail_data_t *mail_data, int item_count, emstorage_mail_tbl_t **mail_table_data, int *error);
/* Attachment */
-INTERNAL_FUNC char* em_convert_attachment_data_to_byte_stream(emf_attachment_data_t *input_attachment_data, int intput_attachment_count, int* output_stream_size);
-INTERNAL_FUNC void em_convert_byte_stream_to_attachment_data(char *intput_stream, emf_attachment_data_t **output_attachment_data, int *output_attachment_count);
-
-INTERNAL_FUNC char* em_convert_attachment_info_to_byte_stream(emf_attachment_info_t* mail_atch, int* nStreamSize);
-INTERNAL_FUNC void em_convert_byte_stream_to_attachment_info(char* pStream, int attachment_num, emf_attachment_info_t** mail_atch);
+INTERNAL_FUNC char* em_convert_attachment_data_to_byte_stream(email_attachment_data_t *attachment_data, int attachment_count, int* stream_len);
+INTERNAL_FUNC void em_convert_byte_stream_to_attachment_data(char *stream, int stream_len, email_attachment_data_t **attachment_data, int *attachment_count);
/* Mailbox */
-INTERNAL_FUNC char* em_convert_mailbox_to_byte_stream(emf_mailbox_t* pMailbox, int* nStreamSize);
-INTERNAL_FUNC void em_convert_byte_stream_to_mailbox(char* pStream, emf_mailbox_t* pMailbox);
+INTERNAL_FUNC int em_convert_mailbox_to_mailbox_tbl(email_mailbox_t *mailbox, emstorage_mailbox_tbl_t *mailbox_tbl);
+INTERNAL_FUNC int em_convert_mailbox_tbl_to_mailbox(emstorage_mailbox_tbl_t *mailbox_tbl, email_mailbox_t *mailbox);
+
+
+INTERNAL_FUNC char* em_convert_mailbox_to_byte_stream(email_mailbox_t* mailbox, int* stream_len);
+INTERNAL_FUNC void em_convert_byte_stream_to_mailbox(char* stream, int stream_len, email_mailbox_t* mailbox);
/* Rule */
-INTERNAL_FUNC char* em_convert_rule_to_byte_stream(emf_rule_t* pRule, int* nStreamSize);
-INTERNAL_FUNC void em_convert_byte_stream_to_rule(char* pStream, emf_rule_t* pMailbox);
+INTERNAL_FUNC char* em_convert_rule_to_byte_stream(email_rule_t* rule, int* stream_len);
+INTERNAL_FUNC void em_convert_byte_stream_to_rule(char *stream, int stream_len, email_rule_t *rule);
/* Sending options */
-INTERNAL_FUNC char* em_convert_option_to_byte_stream(emf_option_t* pOption, int* nStreamSize);
-INTERNAL_FUNC void em_convert_byte_stream_to_option(char* pStream, emf_option_t* pOption);
+INTERNAL_FUNC char* em_convert_option_to_byte_stream(email_option_t* option, int* stream_len);
+INTERNAL_FUNC void em_convert_byte_stream_to_option(char *stream, int stream_len, email_option_t *option);
/* time_t */
INTERNAL_FUNC int em_convert_string_to_time_t(char *input_datetime_string, time_t *output_time);
INTERNAL_FUNC int em_convert_time_t_to_string(time_t *input_time, char **output_datetime_string);
-/* emf_extra_flag_t */
-INTERNAL_FUNC char* em_convert_extra_flags_to_byte_stream(emf_extra_flag_t new_flag, int* StreamSize);
-INTERNAL_FUNC void em_convert_byte_stream_to_extra_flags(char* pStream, emf_extra_flag_t* new_flag);
+/* email_extra_flag_t */
+INTERNAL_FUNC char* em_convert_extra_flags_to_byte_stream(email_extra_flag_t new_flag, int* StreamSize);
+INTERNAL_FUNC void em_convert_byte_stream_to_extra_flags(char* pStream, email_extra_flag_t* new_flag);
-/* emf_meeting_request_t */
-INTERNAL_FUNC char* em_convert_meeting_req_to_byte_stream(emf_meeting_request_t* meeting_req, int* nStreamSize);
-INTERNAL_FUNC void em_convert_byte_stream_to_meeting_req(char* pStream, emf_meeting_request_t* meeting_req);
+/* email_meeting_request_t */
+INTERNAL_FUNC char* em_convert_meeting_req_to_byte_stream(email_meeting_request_t* meeting_req, int* nStreamSize);
+INTERNAL_FUNC void em_convert_byte_stream_to_meeting_req(char* stream, int stream_len, email_meeting_request_t* meeting_req);
-INTERNAL_FUNC int em_convert_mail_flag_to_int(emf_mail_flag_t flag, int* i_flag, int* err_code);
-INTERNAL_FUNC int em_convert_mail_int_to_flag(int i_flag, emf_mail_flag_t* flag, int* err_code);
+INTERNAL_FUNC int em_convert_mail_flag_to_int(email_mail_flag_t flag, int* i_flag, int* err_code);
+INTERNAL_FUNC int em_convert_mail_int_to_flag(int i_flag, email_mail_flag_t* flag, int* err_code);
INTERNAL_FUNC int em_convert_mail_status_to_mail_tbl(int mail_status, emstorage_mail_tbl_t *result_mail_tbl_data, int* err_code);
INTERNAL_FUNC int em_convert_mail_tbl_to_mail_status(emstorage_mail_tbl_t *mail_tbl_data, int *result_mail_status, int* err_code);
-INTERNAL_FUNC int em_convert_mail_tbl_to_mail_flag(emstorage_mail_tbl_t *mail_tbl_data, emf_mail_flag_t *result_flag, int* err_code);
-INTERNAL_FUNC int em_convert_mail_flag_to_mail_tbl(emf_mail_flag_t *flag, emstorage_mail_tbl_t *result_mail_tbl_data, int* err_code);
+INTERNAL_FUNC int em_convert_mail_tbl_to_mail_flag(emstorage_mail_tbl_t *mail_tbl_data, email_mail_flag_t *result_flag, int* err_code);
+INTERNAL_FUNC int em_convert_mail_flag_to_mail_tbl(email_mail_flag_t *flag, emstorage_mail_tbl_t *result_mail_tbl_data, int* err_code);
/* Search filter options */
INTERNAL_FUNC char* em_convert_search_filter_to_byte_stream(email_search_filter_t *input_search_filter_list, int input_search_filter_count, int *output_stream_size);
INTERNAL_FUNC void em_convert_byte_stream_to_search_filter(char *input_stream, email_search_filter_t **output_search_filter_list, int *output_search_filter_count);
+
+/* convert certificate */
+INTERNAL_FUNC int em_convert_certificate_tbl_to_certificate(emstorage_certificate_tbl_t *certificate_tbl, email_certificate_t **certificate, int *error);
+
+INTERNAL_FUNC int em_convert_certificate_to_certificate_tbl(email_certificate_t *certificate, emstorage_certificate_tbl_t *certificate_tbl);
+
#endif /* __EMAIL_CONVERT_H__ */
diff --git a/email-common-use/include/email-debug-log.h b/email-common-use/include/email-debug-log.h
index 3344215..84dffbe 100755
--- a/email-common-use/include/email-debug-log.h
+++ b/email-common-use/include/email-debug-log.h
@@ -4,7 +4,7 @@
* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
*
* Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com>
-*
+*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@@ -41,11 +41,12 @@ extern "C"
#include <stdio.h>
#include <string.h>
#include <dlog.h>
+#include <errno.h>
#define __FEATURE_DEBUG_LOG__
#ifdef __FEATURE_DEBUG_LOG__
-
+
/* definition of LOG_TAG */
#ifdef LOG_TAG
#undef LOG_TAG
@@ -53,13 +54,17 @@ extern "C"
#define LOG_TAG "email-service"
-#define EM_DEBUG_LOG(format, arg...) SLOGD("[%s:%s():%d] " format "\n", (rindex(__FILE__, '/')? rindex(__FILE__,'/')+1 : __FILE__ ), __FUNCTION__, __LINE__, ##arg)
-#define EM_DEBUG_EXCEPTION(format, arg...) SLOGE("[%s:%s():%d][EXCEPTION!!] " format "\n", (rindex(__FILE__, '/')? rindex(__FILE__,'/')+1 : __FILE__ ), __FUNCTION__, __LINE__, ##arg)
+#define EM_DEBUG_LOG(format, arg...) \
+ SLOGD("[%s() :%s:%d] " format "\n", __FUNCTION__, \
+ (rindex(__FILE__, '/')? rindex(__FILE__,'/')+1 : __FILE__ ), __LINE__, ##arg)
+#define EM_DEBUG_EXCEPTION(format, arg...) \
+ SLOGE("[%s() :%s:%d][EXCEPTION!!] " format "\n", __FUNCTION__, \
+ (rindex(__FILE__, '/')? rindex(__FILE__,'/')+1 : __FILE__ ), __LINE__, ##arg)
#ifdef _DEBUG_MIME_PARSE_
#define EM_DEBUG_LOG_MIME(format, arg...) EM_DEBUG_LOG(format, ##arg)
#else /* _DEBUG_MIME_PARSE */
-#define EM_DEBUG_LOG_MIME(format, arg...)
+#define EM_DEBUG_LOG_MIME(format, arg...)
#endif /* _DEBUG_MIME_PARSE */
#define EM_DEBUG_FUNC_BEGIN(format, arg...) EM_DEBUG_LOG("BEGIN - "format, ##arg)
@@ -68,9 +73,23 @@ extern "C"
#define EM_DEBUG_DB_EXEC(eval, expr, X) if (eval) { EM_DEBUG_LOG X; expr;} else {;}
#define EM_DEBUG_ERROR_FILE_PATH "/opt/data/email/.emfdata/.critical_error.log"
-#define EM_DEBUG_CRITICAL_EXCEPTION(format, arg...) { FILE *fp_error = NULL; fp_error = fopen(EM_DEBUG_ERROR_FILE_PATH, "a");\
- if(fp_error) {fprintf(fp_error, "[%s:%s():%d] " format "\n", (rindex(__FILE__, '/')? rindex(__FILE__,'/')+1 : __FILE__ ), __FUNCTION__, __LINE__, ##arg); \
- fclose(fp_error);}}
+#define EM_DEBUG_CRITICAL_EXCEPTION(format, arg...) \
+ {\
+ FILE *fp_error = NULL;\
+ fp_error = fopen(EM_DEBUG_ERROR_FILE_PATH, "a");\
+ if(fp_error) {\
+ fprintf(fp_error, "[%s() :%s:%d] " format "\n", \
+ __FUNCTION__, (rindex(__FILE__, '/')? rindex(__FILE__,'/')+1 : __FILE__ ),\
+ __LINE__, ##arg); \
+ fclose(fp_error);\
+ }\
+ }
+#define EM_DEBUG_PERROR(str) ({\
+ char buf[128] = {0};\
+ strerror_r(errno, buf, sizeof(buf));\
+ EM_DEBUG_EXCEPTION("%s: %s(%d)", str, buf, errno);\
+ })
+
#ifdef _USE_PROFILE_DEBUG_
#define EM_PROFILE_BEGIN(pfid) \
unsigned int __prf_l1_##pfid = __LINE__;\
@@ -78,10 +97,10 @@ extern "C"
struct timeval __prf_2_##pfid;\
do {\
gettimeofday(&__prf_1_##pfid, 0);\
- EM_DEBUG_LOG("**PROFILE BEGIN** [EMAILFW: %s: %s() %u ~ ] " #pfid \
+ EM_DEBUG_LOG("**PROFILE BEGIN** [EMAILFW: %s() :%s %u ~ ] " #pfid \
" -> Start Time: %u.%06u seconds\n",\
+ __FUNCTION__,\
rindex(__FILE__,'/')+1, \
- __FUNCTION__,\
__prf_l1_##pfid,\
(unsigned int)__prf_1_##pfid.tv_sec,\
(unsigned int)__prf_1_##pfid.tv_usec );\
@@ -94,10 +113,10 @@ extern "C"
long __ds = __prf_2_##pfid.tv_sec - __prf_1_##pfid.tv_sec;\
long __dm = __prf_2_##pfid.tv_usec - __prf_1_##pfid.tv_usec;\
if ( __dm < 0 ) { __ds--; __dm = 1000000 + __dm; } \
- EM_DEBUG_LOG("**PROFILE END** [EMAILFW: %s: %s() %u ~ %u] " #pfid \
+ EM_DEBUG_LOG("**PROFILE END** [EMAILFW: %s() :%s %u ~ %u] " #pfid \
" -> Elapsed Time: %u.%06u seconds\n",\
+ __FUNCTION__,\
rindex(__FILE__, '/')+1,\
- __FUNCTION__,\
__prf_l1_##pfid,\
__prf_l2_##pfid,\
(unsigned int)(__ds),\
@@ -109,12 +128,12 @@ extern "C"
#define EM_PROFILE_END(pfid)
#endif
-
-
+
+
#else /* __FEATURE_DEBUG_LOG__ */
-
+
#define EM_DEBUG_LINE
- #define EM_DEBUG_LOG(format, arg...)
+ #define EM_DEBUG_LOG(format, arg...)
#define EM_DEBUG_ASSERT(format, arg...)
#define EM_DEBUG_EXCEPTION(format, arg...)
@@ -211,7 +230,7 @@ extern "C"
return ret;\
}\
}
-
+
#define EM_STRERROR(err) ({ char buf[128]; strerror_r(err, buf, sizeof(buf));})
diff --git a/email-common-use/include/email-errors.h b/email-common-use/include/email-errors.h
index 2a8a718..491c916 100755
--- a/email-common-use/include/email-errors.h
+++ b/email-common-use/include/email-errors.h
@@ -1,129 +1,131 @@
-/*
-* email-service
-*
-* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
-*
-* Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com>
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*
-*/
-
-
-#ifndef __EMAIL_ERRORS_H__
-#define __EMAIL_ERRORS_H__
-
-/*****************************************************************************/
-/* Errors */
-/*****************************************************************************/
-
-
-#define EMF_ERROR_NONE 1 /* There is no error */
-#define EMF_ERROR_INVALID_PARAM -1001 /* invalid parameter was given. - Invalid input parameter */
-#define EMF_ERROR_INVALID_ACCOUNT -1002 /* invalid account information was given. - Unsupported account */
-#define EMF_ERROR_INVALID_USER -1003 /* invalid user ID was given. - Invalid user or password */
-#define EMF_ERROR_INVALID_PASSWORD -1004 /* invalid password was given. - Invalid user or password */
-#define EMF_ERROR_INVALID_SERVER -1005 /* invalid server information was given. - Server unavailable */
-#define EMF_ERROR_INVALID_MAIL -1006 /* invalid mail information was given */
-#define EMF_ERROR_INVALID_ADDRESS -1007 /* invalid address information was given. - Incorrect address */
-#define EMF_ERROR_INVALID_ATTACHMENT -1008 /* invalid attachment information was given */
-#define EMF_ERROR_INVALID_MAILBOX -1009 /* invalid mailbox information was given */
-#define EMF_ERROR_INVALID_FILTER -1010 /* invalid filter information was given */
-#define EMF_ERROR_INVALID_PATH -1011 /* invalid flle path was given */
-#define EMF_ERROR_INVALID_DATA -1012 /* invalid data */
-#define EMF_ERROR_INVALID_RESPONSE -1013 /* unexpected network response was given. - Invalid server response */
-#define EMF_ERROR_ACCOUNT_NOT_FOUND -1014 /* no matched account was found */
-#define EMF_ERROR_MAIL_NOT_FOUND -1015 /* no matched mail was found */
-#define EMF_ERROR_MAILBOX_NOT_FOUND -1016 /* no matched mailbox was found */
-#define EMF_ERROR_ATTACHMENT_NOT_FOUND -1017 /* no matched attachment was found */
-#define EMF_ERROR_FILTER_NOT_FOUND -1018 /* no matched filter was found */
-#define EMF_ERROR_CONTACT_NOT_FOUND -1019 /* no matched contact was found */
-#define EMF_ERROR_FILE_NOT_FOUND -1020 /* no matched file was found */
-#define EMF_ERROR_DATA_NOT_FOUND -1021 /* no matched data was found */
-#define EMF_ERROR_NO_MORE_DATA -1022 /* No more data available */
-#define EMF_ERROR_ALREADY_EXISTS -1023 /* data duplicated */
-#define EMF_ERROR_MAX_EXCEEDED -1024 /* Can't handle more data */
-#define EMF_ERROR_DATA_TOO_LONG -1025 /* Data is too long */
-#define EMF_ERROR_DATA_TOO_SMALL -1026 /* Data is too small */
-#define EMF_ERROR_NETWORK_TOO_BUSY -1027 /* Network is busy */
-#define EMF_ERROR_OUT_OF_MEMORY -1028 /* There is not enough memory */
-#define EMF_ERROR_DB_FAILURE -1029 /* database operation failed */
-#define EMF_ERROR_PROFILE_FAILURE -1030 /* no proper profile was found */
-#define EMF_ERROR_SOCKET_FAILURE -1031 /* socket operation failed */
-#define EMF_ERROR_CONNECTION_FAILURE -1032 /* network connection failed */
-#define EMF_ERROR_CONNECTION_BROKEN -1033 /* network connection was broken */
-#define EMF_ERROR_DISCONNECTED -1034 /* connection was disconnected */
-#define EMF_ERROR_LOGIN_FAILURE -1035 /* login failed */
-#define EMF_ERROR_NO_RESPONSE -1036 /* There is no server response */
-#define EMF_ERROR_MAILBOX_FAILURE -1037 /* The agent failed to scan mailboxes in server */
-#define EMF_ERROR_AUTH_NOT_SUPPORTED -1038 /* The server doesn't support authentication */
-#define EMF_ERROR_AUTHENTICATE -1039 /* The server failed to authenticate user */
-#define EMF_ERROR_TLS_NOT_SUPPORTED -1040 /* The server doesn't support TLS */
-#define EMF_ERROR_TLS_SSL_FAILURE -1041 /* The agent failed TLS/SSL */
-#define EMF_ERROR_APPEND_FAILURE -1042 /* The agent failed to append mail to server */
-#define EMF_ERROR_COMMAND_NOT_SUPPORTED -1043 /* The server doesn't support this command */
-#define EMF_ERROR_ANNONYM_NOT_SUPPORTED -1044 /* The server doesn't support anonymous user */
-#define EMF_ERROR_CERTIFICATE_FAILURE -1045 /* certificate failure - Invalid server certificate */
-#define EMF_ERROR_CANCELLED -1046 /* The job was canceled by user */
-#define EMF_ERROR_NOT_IMPLEMENTED -1047 /* The function was not implemented */
-#define EMF_ERROR_NOT_SUPPORTED -1048 /* The function is not supported */
-#define EMF_ERROR_MAIL_LOCKED -1049 /* The mail was locked */
-#define EMF_ERROR_SYSTEM_FAILURE -1050 /* There is a system error */
-#define EMF_ERROR_MAIL_MAX_COUNT -1052 /* The mailbox is full */
-#define EMF_ERROR_ACCOUNT_MAX_COUNT -1053 /* There is too many account */
-#define EMF_ERROR_MAIL_MEMORY_FULL -1054 /* There is no more storage */
-#define EMF_ERROR_MAIL_NOT_FOUND_ON_SERVER -1055 /* The expected mail is not found in server */
-#define EMF_ERROR_LOAD_ENGINE_FAILURE -1056 /* loading engine failed */
-#define EMF_ERROR_CLOSE_FAILURE -1057 /* engine is still used */
-#define EMF_ERROR_GCONF_FAILURE -1058 /* The error occurred on accessing Gconf */
-#define EMF_ERROR_NO_SUCH_HOST -1059 /* no such host was found */
-#define EMF_ERROR_EVENT_QUEUE_FULL -1060 /* event queue is full */
-#define EMF_ERROR_EVENT_QUEUE_EMPTY -1061 /* event queue is empty */
-#define EMF_ERROR_NO_RECIPIENT -1062 /* no recipients information was found */
-#define EMF_ERROR_SMTP_SEND_FAILURE -1063 /* SMTP send failed */
-#define EMF_ERROR_MAILBOX_OPEN_FAILURE -1064 /* accessing mailbox failed */
-#define EMF_ERROR_RETRIEVE_HEADER_DATA_FAILURE -1065 /* retrieving header failed */
-#define EMF_ERROR_XML_PARSER_FAILURE -1066 /* XML parsing failed */
-#define EMF_ERROR_SESSION_NOT_FOUND -1067 /* no matched session was found */
-#define EMF_ERROR_INVALID_STREAM -1068
-#define EMF_ERROR_AUTH_REQUIRED -1069 /* SMTP Authentication needed */
-#define EMF_ERROR_POP3_DELE_FAILURE -1100
-#define EMF_ERROR_POP3_UIDL_FAILURE -1101
-#define EMF_ERROR_POP3_LIST_FAILURE -1102
-#define EMF_ERROR_IMAP4_STORE_FAILURE -1200
-#define EMF_ERROR_IMAP4_EXPUNGE_FAILURE -1201
-#define EMF_ERROR_IMAP4_FETCH_UID_FAILURE -1202
-#define EMF_ERROR_IMAP4_FETCH_SIZE_FAILURE -1203
-#define EMF_ERROR_IMAP4_IDLE_FAILURE -1204 /* IDLE faile */
-#define EMF_ERROR_NO_SIM_INSERTED -1205
-#define EMF_ERROR_FLIGHT_MODE -1206
-#define EMF_ERROR_VALIDATE_ACCOUNT -1208
-#define EMF_ERROR_NO_MMC_INSERTED -1209
-#define EMF_ERROR_ACTIVE_SYNC_NOTI_FAILURE -1300
-#define EMF_ERROR_HANDLE_NOT_FOUND -1301
-#define EMF_ERROR_NULL_VALUE -1302
-#define EMF_ERROR_FAILED_BY_SECURITY_POLICY -1303
-#define EMF_ERROR_CANNOT_NEGOTIATE_TLS -1400 /* "Cannot negotiate TLS" */
-#define EMF_ERROR_STARTLS -1401 /* "STARTLS" */
-#define EMF_ERROR_IPC_CRASH -1500
-#define EMF_ERROR_IPC_CONNECTION_FAILURE -1501
-#define EMF_ERROR_IPC_SOCKET_FAILURE -1502
-#define EMF_ERROR_IPC_PROTOCOL_FAILURE -1503
-#define EMF_ERROR_LOGIN_ALLOWED_EVERY_15_MINS -1600 /* "login allowed only every 15 minutes" */
-#define EMF_ERROR_TOO_MANY_LOGIN_FAILURE -1601 /* "Too many login failure" */
-#define EMF_ERROR_ON_PARSING -1700
-#define EMF_ERROR_NETWORK_NOT_AVAILABLE -1800 /* WIFI not availble*/
-#define EMF_ERROR_CANNOT_STOP_THREAD -2000
-#define EMF_ERROR_UNKNOWN -8000 /* unknown error */
-
-#endif /* __EMAIL_ERRORS_H__ */
+/*
+* email-service
+*
+* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+*
+* Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com>
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*
+*/
+
+
+#ifndef __EMAIL_ERRORS_H__
+#define __EMAIL_ERRORS_H__
+
+/*****************************************************************************/
+/* Errors */
+/*****************************************************************************/
+
+
+#define EMAIL_ERROR_NONE 1 /* There is no error */
+#define EMAIL_ERROR_INVALID_PARAM -1001 /* invalid parameter was given. - Invalid input parameter */
+#define EMAIL_ERROR_INVALID_ACCOUNT -1002 /* invalid account information was given. - Unsupported account */
+#define EMAIL_ERROR_INVALID_USER -1003 /* invalid user ID was given. - Invalid user or password */
+#define EMAIL_ERROR_INVALID_PASSWORD -1004 /* invalid password was given. - Invalid user or password */
+#define EMAIL_ERROR_INVALID_SERVER -1005 /* invalid server information was given. - Server unavailable */
+#define EMAIL_ERROR_INVALID_MAIL -1006 /* invalid mail information was given */
+#define EMAIL_ERROR_INVALID_ADDRESS -1007 /* invalid address information was given. - Incorrect address */
+#define EMAIL_ERROR_INVALID_ATTACHMENT -1008 /* invalid attachment information was given */
+#define EMAIL_ERROR_INVALID_MAILBOX -1009 /* invalid mailbox information was given */
+#define EMAIL_ERROR_INVALID_FILTER -1010 /* invalid filter information was given */
+#define EMAIL_ERROR_INVALID_PATH -1011 /* invalid flle path was given */
+#define EMAIL_ERROR_INVALID_DATA -1012 /* invalid data */
+#define EMAIL_ERROR_INVALID_RESPONSE -1013 /* unexpected network response was given. - Invalid server response */
+#define EMAIL_ERROR_ACCOUNT_NOT_FOUND -1014 /* no matched account was found */
+#define EMAIL_ERROR_MAIL_NOT_FOUND -1015 /* no matched mail was found */
+#define EMAIL_ERROR_MAILBOX_NOT_FOUND -1016 /* no matched mailbox was found */
+#define EMAIL_ERROR_ATTACHMENT_NOT_FOUND -1017 /* no matched attachment was found */
+#define EMAIL_ERROR_FILTER_NOT_FOUND -1018 /* no matched filter was found */
+#define EMAIL_ERROR_CONTACT_NOT_FOUND -1019 /* no matched contact was found */
+#define EMAIL_ERROR_FILE_NOT_FOUND -1020 /* no matched file was found */
+#define EMAIL_ERROR_DATA_NOT_FOUND -1021 /* no matched data was found */
+#define EMAIL_ERROR_NO_MORE_DATA -1022 /* No more data available */
+#define EMAIL_ERROR_ALREADY_EXISTS -1023 /* data duplicated */
+#define EMAIL_ERROR_MAX_EXCEEDED -1024 /* Can't handle more data */
+#define EMAIL_ERROR_DATA_TOO_LONG -1025 /* Data is too long */
+#define EMAIL_ERROR_DATA_TOO_SMALL -1026 /* Data is too small */
+#define EMAIL_ERROR_NETWORK_TOO_BUSY -1027 /* Network is busy */
+#define EMAIL_ERROR_OUT_OF_MEMORY -1028 /* There is not enough memory */
+#define EMAIL_ERROR_DB_FAILURE -1029 /* database operation failed */
+#define EMAIL_ERROR_PROFILE_FAILURE -1030 /* no proper profile was found */
+#define EMAIL_ERROR_SOCKET_FAILURE -1031 /* socket operation failed */
+#define EMAIL_ERROR_CONNECTION_FAILURE -1032 /* network connection failed */
+#define EMAIL_ERROR_CONNECTION_BROKEN -1033 /* network connection was broken */
+#define EMAIL_ERROR_DISCONNECTED -1034 /* connection was disconnected */
+#define EMAIL_ERROR_LOGIN_FAILURE -1035 /* login failed */
+#define EMAIL_ERROR_NO_RESPONSE -1036 /* There is no server response */
+#define EMAIL_ERROR_MAILBOX_FAILURE -1037 /* The agent failed to scan mailboxes in server */
+#define EMAIL_ERROR_AUTH_NOT_SUPPORTED -1038 /* The server doesn't support authentication */
+#define EMAIL_ERROR_AUTHENTICATE -1039 /* The server failed to authenticate user */
+#define EMAIL_ERROR_TLS_NOT_SUPPORTED -1040 /* The server doesn't support TLS */
+#define EMAIL_ERROR_TLS_SSL_FAILURE -1041 /* The agent failed TLS/SSL */
+#define EMAIL_ERROR_APPEND_FAILURE -1042 /* The agent failed to append mail to server */
+#define EMAIL_ERROR_COMMAND_NOT_SUPPORTED -1043 /* The server doesn't support this command */
+#define EMAIL_ERROR_ANNONYM_NOT_SUPPORTED -1044 /* The server doesn't support anonymous user */
+#define EMAIL_ERROR_CERTIFICATE_FAILURE -1045 /* certificate failure - Invalid server certificate */
+#define EMAIL_ERROR_CANCELLED -1046 /* The job was canceled by user */
+#define EMAIL_ERROR_NOT_IMPLEMENTED -1047 /* The function was not implemented */
+#define EMAIL_ERROR_NOT_SUPPORTED -1048 /* The function is not supported */
+#define EMAIL_ERROR_MAIL_LOCKED -1049 /* The mail was locked */
+#define EMAIL_ERROR_SYSTEM_FAILURE -1050 /* There is a system error */
+#define EMAIL_ERROR_MAIL_MAX_COUNT -1052 /* The mailbox is full */
+#define EMAIL_ERROR_ACCOUNT_MAX_COUNT -1053 /* There is too many account */
+#define EMAIL_ERROR_MAIL_MEMORY_FULL -1054 /* There is no more storage */
+#define EMAIL_ERROR_MAIL_NOT_FOUND_ON_SERVER -1055 /* The expected mail is not found in server */
+#define EMAIL_ERROR_LOAD_ENGINE_FAILURE -1056 /* loading engine failed */
+#define EMAIL_ERROR_CLOSE_FAILURE -1057 /* engine is still used */
+#define EMAIL_ERROR_GCONF_FAILURE -1058 /* The error occurred on accessing Gconf */
+#define EMAIL_ERROR_NO_SUCH_HOST -1059 /* no such host was found */
+#define EMAIL_ERROR_EVENT_QUEUE_FULL -1060 /* event queue is full */
+#define EMAIL_ERROR_EVENT_QUEUE_EMPTY -1061 /* event queue is empty */
+#define EMAIL_ERROR_NO_RECIPIENT -1062 /* no recipients information was found */
+#define EMAIL_ERROR_SMTP_SEND_FAILURE -1063 /* SMTP send failed */
+#define EMAIL_ERROR_MAILBOX_OPEN_FAILURE -1064 /* accessing mailbox failed */
+#define EMAIL_ERROR_RETRIEVE_HEADER_DATA_FAILURE -1065 /* retrieving header failed */
+#define EMAIL_ERROR_XML_PARSER_FAILURE -1066 /* XML parsing failed */
+#define EMAIL_ERROR_SESSION_NOT_FOUND -1067 /* no matched session was found */
+#define EMAIL_ERROR_INVALID_STREAM -1068
+#define EMAIL_ERROR_AUTH_REQUIRED -1069 /* SMTP Authentication needed */
+#define EMAIL_ERROR_POP3_DELE_FAILURE -1100
+#define EMAIL_ERROR_POP3_UIDL_FAILURE -1101
+#define EMAIL_ERROR_POP3_LIST_FAILURE -1102
+#define EMAIL_ERROR_IMAP4_STORE_FAILURE -1200
+#define EMAIL_ERROR_IMAP4_EXPUNGE_FAILURE -1201
+#define EMAIL_ERROR_IMAP4_FETCH_UID_FAILURE -1202
+#define EMAIL_ERROR_IMAP4_FETCH_SIZE_FAILURE -1203
+#define EMAIL_ERROR_IMAP4_IDLE_FAILURE -1204 /* IDLE faile */
+#define EMAIL_ERROR_NO_SIM_INSERTED -1205
+#define EMAIL_ERROR_FLIGHT_MODE -1206
+#define EMAIL_ERROR_VALIDATE_ACCOUNT -1208
+#define EMAIL_ERROR_NO_MMC_INSERTED -1209
+#define EMAIL_ERROR_ACTIVE_SYNC_NOTI_FAILURE -1300
+#define EMAIL_ERROR_HANDLE_NOT_FOUND -1301
+#define EMAIL_ERROR_NULL_VALUE -1302
+#define EMAIL_ERROR_FAILED_BY_SECURITY_POLICY -1303
+#define EMAIL_ERROR_CANNOT_NEGOTIATE_TLS -1400 /* "Cannot negotiate TLS" */
+#define EMAIL_ERROR_STARTLS -1401 /* "STARTLS" */
+#define EMAIL_ERROR_IPC_CRASH -1500
+#define EMAIL_ERROR_IPC_CONNECTION_FAILURE -1501
+#define EMAIL_ERROR_IPC_SOCKET_FAILURE -1502
+#define EMAIL_ERROR_IPC_PROTOCOL_FAILURE -1503
+#define EMAIL_ERROR_IPC_ALREADY_INITIALIZED -1504
+#define EMAIL_ERROR_LOGIN_ALLOWED_EVERY_15_MINS -1600 /* "login allowed only every 15 minutes" */
+#define EMAIL_ERROR_TOO_MANY_LOGIN_FAILURE -1601 /* "Too many login failure" */
+#define EMAIL_ERROR_ON_PARSING -1700
+#define EMAIL_ERROR_NETWORK_NOT_AVAILABLE -1800 /* WIFI not availble*/
+#define EMAIL_ERROR_CANNOT_STOP_THREAD -2000
+#define EMAIL_ERROR_SECURED_STORAGE_FAILURE -2100 /* Error from secured storage */
+#define EMAIL_ERROR_UNKNOWN -8000 /* unknown error */
+
+#endif /* __EMAIL_ERRORS_H__ */
diff --git a/email-common-use/include/email-internal-types.h b/email-common-use/include/email-internal-types.h
index eb214fd..d0116c9 100755
--- a/email-common-use/include/email-internal-types.h
+++ b/email-common-use/include/email-internal-types.h
@@ -45,7 +45,6 @@ extern "C"
/* ----------------------------------------------------------------------------- */
/* Feature definitions */
-#define __FEATURE_USING_MY_ACCOUNT__
#define __FEATURE_BACKUP_ACCOUNT__
#define __FEATURE_MOVE_TO_OUTBOX_FIRST__
/* #define __FEATURE_PARTIAL_BODY_FOR_POP3__ */
@@ -60,11 +59,9 @@ extern "C"
#define __FEATURE_AUTO_POLLING__
#define __FEATURE_DEBUG_LOG__
#define __FEATURE_USE_SHARED_MUTEX_FOR_GENERATING_MAIL_ID__
+#define __FEATURE_XLIST_SUPPORT__
/* #define __FEATURE_USE_SHARED_MUTEX_FOR_PROTECTED_FUNC_CALL__ */
/* #define __FEATURE_IMAP_IDLE__ */
-#define __FEATURE_SUPPORT_ACTIVE_SYNC__
-#define __HEADER_OPTIMIZATION__ /* Will be removed */
-#define __DOWNLOAD_BODY_ATTACHMENT_OPTIMIZATION__ /* Will be removed */
/* ----------------------------------------------------------------------------- */
/* Macro */
@@ -80,8 +77,8 @@ extern "C"
#define PARTIAL_BODY_SIZE_IN_BYTES 15360 /* Partial Body download - 15K */
#define NO_LIMITATION 0
#define MAX_MAILBOX_TYPE 100
-#define EMF_SYNC_ALL_MAILBOX 1
-#define EMF_ATTACHMENT_MAX_COUNT 512
+#define EMAIL_SYNC_ALL_MAILBOX 1
+#define EMAIL_ATTACHMENT_MAX_COUNT 512
#define DOWNLOAD_MAX_BUFFER_SIZE 8000
#define LOCAL_MAX_BUFFER_SIZE 1000000
#define IMAP_MAX_COMMAND_LENGTH 1000
@@ -105,19 +102,13 @@ extern "C"
#define MAILHOME DATA_PATH"/email/.emfdata"
#define DIRECTORY_PERMISSION 0755
-#define VCONF_KEY_LAST_SYNC_TIME "db/email/last_sync_time"
-#define VCONF_KEY_DEFAULT_SLOT_SIZE "db/email/slot_size"
-#define VCONF_KEY_LATEST_MAIL_ID "db/email/latest_mail_id"
-#define VCONF_KEY_DEFAULT_ACCOUNT_ID "db/email/defaultaccount"
-#define VCONF_KEY_UNREAD_MAIL_COUNT "db/badge/com.samsung.email"
-
#define MIME_SUBTYPE_DRM_OBJECT "vnd.oma.drm.message"
#define MIME_SUBTYPE_DRM_RIGHTS "vnd.oma.drm.rights+xml"
#define MIME_SUBTYPE_DRM_DCF "vnd.oma.drm.dcf"
#define SHM_FILE_FOR_DB_LOCK "/.email_shm_db_lock"
-#define NATIVE_EMAIL_APPLICATION_PKG "com.samsung.email"
+#define NATIVE_EMAIL_APPLICATION_PKG "org.tizen.email"
#ifdef __FEATURE_USE_SHARED_MUTEX_FOR_GENERATING_MAIL_ID__
#define SHM_FILE_FOR_MAIL_ID_LOCK "/.email_shm_mail_id_lock"
@@ -133,10 +124,6 @@ extern "C"
#define LF_STRING "\n"
#define CRLF_STRING "\r\n"
-#define SYNC_STATUS_FINISHED 0 /* BIN 00000000 */
-#define SYNC_STATUS_SYNCING 1 /* BIN 00000001 */
-#define SYNC_STATUS_HAVE_NEW_MAILS 2 /* BIN 00000010 */
-
#define GRAB_TYPE_TEXT 1 /* retrieve text and attachment list */
#define GRAB_TYPE_ATTACHMENT 2 /* retrieve attachment */
@@ -144,7 +131,7 @@ extern "C"
#define SAVE_TYPE_BUFFER 2 /* save content to buffer */
#define SAVE_TYPE_FILE 3 /* save content to temporary file */
-#define FINISH_OFF_IF_CANCELED if (!emcore_check_thread_status()) { err = EMF_ERROR_CANCELLED; goto FINISH_OFF; }
+#define FINISH_OFF_IF_CANCELED if (!emcore_check_thread_status()) { err = EMAIL_ERROR_CANCELLED; goto FINISH_OFF; }
#define CHECK_JOB_CANCELED() {if (!emcore_check_thread_status()) goto JOB_CANCEL; }
#define SNPRINTF(buff, size, format, args...) snprintf(buff, size, format, ##args)
@@ -182,11 +169,16 @@ extern "C"
#define DELETE_RECURSIVE_CRITICAL_SECTION(cs) {EM_DEBUG_LOG("DELETE_RECURSIVE_CRITICAL_SECTION "#cs); if(cs) pthread_mutex_destroy(cs);}
typedef pthread_t thread_t;
-#define SMTP_RESPONSE_OK 250
-#define SMTP_RESPONSE_READY 354
-#define SMTP_RESPONSE_WANT_AUTH 505
-#define SMTP_RESPONSE_WANT_AUTH2 530
-#define SMTP_RESPONSE_UNAVAIL 550
+#define SMTP_RESPONSE_OK 250
+#define SMTP_RESPONSE_READY 354
+#define SMTP_RESPONSE_WANT_AUTH 505
+#define SMTP_RESPONSE_WANT_AUTH2 530
+#define SMTP_RESPONSE_UNAVAIL 550
+
+#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"
+
/* ----------------------------------------------------------------------------- */
/* Type */
typedef enum
@@ -197,23 +189,36 @@ typedef enum
#ifdef __FEATURE_PARTIAL_BODY_DOWNLOAD__
_SERVICE_THREAD_TYPE_PBD = 3,
#endif /* __FEATURE_PARTIAL_BODY_DOWNLOAD__ */
-} emf_service_thread_type;
+} email_service_thread_type;
typedef enum
{
- EMF_PROTOCOL_NONE = 0,
- EMF_PROTOCOL_POP3 = 1,
- EMF_PROTOCOL_IMAP = 2,
- EMF_PROTOCOL_SMTP = 3,
-} emf_protocol_type_t;
+ EMAIL_PROTOCOL_NONE = 0,
+ EMAIL_PROTOCOL_POP3 = 1,
+ EMAIL_PROTOCOL_IMAP = 2,
+ EMAIL_PROTOCOL_SMTP = 3,
+} email_protocol_type_t;
+typedef enum
+{
+ ACCOUNT_SVC_SYNC_STATUS_RUNNING = 0,
+ ACCOUNT_SVC_SYNC_STATUS_IDLE = 1,
+ ACCOUNT_SVC_SYNC_STATUS_OFF = 2,
+} email_account_svc_sync_status;
+
+typedef enum {
+ SET_TYPE_SET = 1,
+ SET_TYPE_UNION = 2,
+ SET_TYPE_MINUS = 3,
+ SET_TYPE_INTERSECT = 4 /* Not supported */
+} email_set_type_t;
#ifdef __FEATURE_KEEP_CONNECTION__
enum
{
- EMF_STREAM_STATUS_DISCONNECTED = 0,
- EMF_STREAM_STATUS_CONNECTED = 1
+ EMAIL_STREAM_STATUS_DISCONNECTED = 0,
+ EMAIL_STREAM_STATUS_CONNECTED = 1
} ;
#endif /* __FEATURE_KEEP_CONNECTION__ */
@@ -221,57 +226,92 @@ enum
typedef struct
{
int account_id; /* in general, account id */
- emf_event_type_t type;
- emf_event_status_type_t status;
- char *event_param_data_1; /* in general, mailbox name (exception in emcore_send_mail, emcore_send_saved_mail it is emf_option_t **/
+ email_event_type_t type;
+ email_event_status_type_t status;
+ char *event_param_data_1; /* in general, mailbox name (exception in emcore_send_mail, emcore_send_saved_mail it is email_option_t **/
char *event_param_data_2;
char *event_param_data_3;
int event_param_data_4;
int event_param_data_5;
int event_param_data_6; /* in general, notification parameter #1 */
int event_param_data_7; /* in general, notification parameter #2 */
-} emf_event_t;
+ int event_param_data_8;
+} email_event_t;
typedef struct
{
int num;
void *data;
-} emf_callback_holder_t;
+} email_callback_holder_t;
-typedef struct emf_search_key_t emf_search_key_t;
-struct emf_search_key_t
+typedef struct email_search_key_t email_search_key_t;
+struct email_search_key_t
{
int type;
char *value;
- emf_search_key_t *next;
+ email_search_key_t *next;
};
typedef struct
{
int tid;
- emf_protocol_type_t protocol;
+ email_protocol_type_t protocol;
void *stream;
int auth;
int network;
int error;
int status;
-} emf_session_t;
+} email_session_t;
+
+typedef struct
+{
+ int mailbox_id; /**< Unique id on mailbox table.*/
+ char *mailbox_name; /**< Specifies the path of mailbox.*/
+ email_mailbox_type_e mailbox_type; /**< Specifies the type of mailbox */
+ char *alias; /**< Specifies the display name of mailbox.*/
+ int unread_count; /**< Specifies the Unread Mail count in the mailbox.*/
+ int total_mail_count_on_local; /**< Specifies the total number of mails in the mailbox in the local DB.*/
+ int total_mail_count_on_server; /**< Specifies the total number of mails in the mailbox in the mail server.*/
+ int local; /**< Specifies the local mailbox.*/
+ int synchronous; /**< Specifies the mailbox with synchronized the server.*/
+ int account_id; /**< Specifies the account ID for mailbox.*/
+ int has_archived_mails; /**< Specifies the archived mails.*/
+ int mail_slot_size; /**< Specifies how many mails can be stored in local mailbox.*/
+ void *user_data; /**< Specifies the internal data.*/
+ void *mail_stream; /**< Specifies the internal data.*/
+} email_internal_mailbox_t;
#ifdef __FEATURE_KEEP_CONNECTION__
-typedef struct emf_connection_info
+typedef struct email_connection_info
{
int account_id;
int sending_server_stream_status;
void *sending_server_stream;
int receiving_server_stream_status;
void *receiving_server_stream;
- struct emf_connection_info *next;
-} emf_connection_info_t;
+ struct email_connection_info *next;
+} email_connection_info_t;
#endif /* __FEATURE_KEEP_CONNECTION__ */
-typedef void (*emf_event_callback)(int total, int done, int status, int account_id, int mail_id, int handle, void *user_data, int error);
+typedef struct
+{
+ char *contact_name;
+ char *email_address;
+ char *alias;
+ int storage_type;
+ int contact_id;
+} email_mail_contact_info_t;
+
+/* global account lis */
+typedef struct email_account_list
+{
+ email_account_t *account;
+ struct email_account_list *next;
+} email_account_list_t;
+
+typedef void (*email_event_callback)(int total, int done, int status, int account_id, int mail_id, int handle, void *user_data, int error);
/* ----------------------------------------------------------------------------- */
/* Please contact Himanshu [h.gahlaut@samsung.com] for any explanation in code here under __FEATURE_PARTIAL_BODY_DOWNLOAD__ MACRO */
@@ -281,7 +321,7 @@ typedef enum
ACTIVITY_PARTIAL_BODY_DOWNLOAD_IMAP4 = 1,
ACTIVITY_PARTIAL_BODY_DOWNLOAD_POP3_WAIT,
ACTIVITY_PARTIAL_BODY_DOWNLOAD_POP3_ACTIVE
-} emf_pdb_activity_type_e;
+} email_pdb_activity_type_e;
typedef struct
{
@@ -289,11 +329,12 @@ typedef struct
int mail_id;
unsigned long server_mail_id;
int activity_id;
+ int mailbox_id;
char *mailbox_name;
- emf_event_type_t event_type; /* Event Type Null means event is created from local activitys */
+ email_event_type_t event_type; /* Event Type Null means event is created from local activitys */
int activity_type; /* Activity Type Null means event is created from event queue */
-} emf_event_partial_body_thd;
+} email_event_partial_body_thd;
#endif /* __FEATURE_PARTIAL_BODY_DOWNLOAD__ */
#ifdef __cplusplus
diff --git a/email-common-use/include/email-types.h b/email-common-use/include/email-types.h
index bb02ab6..4a56377 100755
--- a/email-common-use/include/email-types.h
+++ b/email-common-use/include/email-types.h
@@ -1,1382 +1,1709 @@
-/*
-* email-service
-*
-* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
-*
-* Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com>
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*
-*/
-
-
-#ifndef __EMAIL_TYPES_H__
-#define __EMAIL_TYPES_H__
-
-/**
-* @defgroup EMAIL_SERVICE Email Service
-* @{
-*/
-
-/**
-* @ingroup EMAIL_SERVICE
-* @defgroup EMAIL_TYPES Email Types
-* @{
-*/
-/**
- * This file defines structures and enums of Email Framework.
- * @file email-types.h
- * @author Kyu-ho Jo(kyuho.jo@samsung.com)
- * @author Choongho Lee(ch715.lee@samsung.com)
- * @version 0.1
- * @brief This file is the header file of Email Framework library.
- */
-
-
-#ifdef __cplusplus
-extern "C"
-{
-#endif /* __cplusplus */
-
-#include <glib.h>
-#include <stdbool.h>
-#include "email-errors.h"
-
-
-/*****************************************************************************/
-/* Macros */
-/*****************************************************************************/
-
-#define MAILBOX_NAME_LENGTH 256
-#define MAX_EMAIL_ADDRESS_LENGTH 320 /* 64(user name) + 1(@) + 255(host name */
-#define MAX_DATETIME_STRING_LENGTH 20
-#define MAX_PREVIEW_TEXT_LENGTH 512
-#define STRING_LENGTH_FOR_DISPLAY 100
-#define MEETING_REQ_OBJECT_ID_LENGTH 256
-
-#define ALL_ACCOUNT 0
-#define NEW_ACCOUNT_ID 0xFFFFFFFE
-#define ALL_MAIL -1
-
-#define EMF_SEARCH_FILTER_NONE 0x00
-#define EMF_SEARCH_FILTER_SUBJECT 0x01
-#define EMF_SEARCH_FILTER_SENDER 0x02
-#define EMF_SEARCH_FILTER_RECIPIENT 0x04
-#define EMF_SEARCH_FILTER_ALL 0x07 /* EMF_SEARCH_FILTER_SUBJECT + EMF_SEARCH_FILTER_SENDER + EMF_SEARCH_FILTER_RECIPIEN */
-
-#define EMF_SUCCESS 0 /* we need to modify the success return valu */
-
-#define EMF_ACC_GET_OPT_DEFAULT 0x01 /**< Default values without account name */
-#define EMF_ACC_GET_OPT_ACCOUNT_NAME 0x02 /**< Account name */
-#define EMF_ACC_GET_OPT_PASSWORD 0x04 /**< With password */
-#define EMF_ACC_GET_OPT_OPTIONS 0x08 /**< Account options : emf_option_t */
-#define EMF_ACC_GET_OPT_FULL_DATA 0xFF /**< With all data of account */
-
-#define GET_FULL_DATA 0x00
-#define GET_FULL_DATA_WITHOUT_PASSWORD (EMF_ACC_GET_OPT_DEFAULT | EMF_ACC_GET_OPT_ACCOUNT_NAME | EMF_ACC_GET_OPT_OPTIONS )
-#define WITHOUT_OPTION (EMF_ACC_GET_OPT_DEFAULT | EMF_ACC_GET_OPT_ACCOUNT_NAME )
-#define ONLY_OPTION (EMF_ACC_GET_OPT_OPTIONS)
-
-#define THREAD_TYPE_RECEIVING 0 /**< for function 'email_activate_pdp' */
-#define THREAD_TYPE_SENDING 1 /**< for function 'email_activate_pdp' */
-
-#define EMF_IMAP_PORT 143 /**< Specifies the default IMAP port.*/
-#define EMF_POP3_PORT 110 /**< Specifies the default POP3 port.*/
-#define EMF_SMTP_PORT 25 /**< Specifies the default SMTP port.*/
-#define EMF_IMAPS_PORT 993 /**< Specifies the default IMAP SSL port.*/
-#define EMF_POP3S_PORT 995 /**< Specifies the default POP3 SSL port.*/
-#define EMF_SMTPS_PORT 465 /**< Specifies the default SMTP SSL port.*/
-#define EMF_ACCOUNT_MAX 10 /**< Specifies the MAX account.*/
-
-#define EMF_INBOX_NAME "INBOX" /**< Specifies the name of inbox.*/
-#define EMF_DRAFTBOX_NAME "DRAFTBOX" /**< Specifies the name of draftbox.*/
-#define EMF_OUTBOX_NAME "OUTBOX" /**< Specifies the name of outbox.*/
-#define EMF_SENTBOX_NAME "SENTBOX" /**< Specifies the name of sentbox.*/
-#define EMF_TRASH_NAME "TRASH" /**< Specifies the name of trash.*/
-#define EMF_SPAMBOX_NAME "SPAMBOX" /**< Specifies the name of spambox.*/
-
-#define EMF_INBOX_DISPLAY_NAME "Inbox" /**< Specifies the display name of inbox.*/
-#define EMF_DRAFTBOX_DISPLAY_NAME "Draftbox" /**< Specifies the display name of draftbox.*/
-#define EMF_OUTBOX_DISPLAY_NAME "Outbox" /**< Specifies the display name of outbox.*/
-#define EMF_SENTBOX_DISPLAY_NAME "Sentbox" /**< Specifies the display name of sentbox.*/
-#define EMF_TRASH_DISPLAY_NAME "Trash" /**< Specifies the display name of sentbox.*/
-#define EMF_SPAMBOX_DISPLAY_NAME "Spambox" /**< Specifies the display name of spambox.*/
-
-#define EMF_SEARCH_RESULT_MAILBOX_NAME "_`S1!E2@A3#R4$C5^H6&R7*E8(S9)U0-L=T_" /**< Specifies the name of search mailbox.*/
-
-#define FAILURE -1
-#define SUCCESS 0
-
-#define DAEMON_EXECUTABLE_PATH "/usr/bin/email-service"
-
-#ifndef EXPORT_API
-#define EXPORT_API __attribute__((visibility("default")))
-#endif
-
-#ifndef DEPRECATED
-#define DEPRECATED __attribute__((deprecated))
-#endif
-
-
-/* __FEATURE_LOCAL_ACTIVITY__ supported
-#define BULK_OPERATION_COUNT 50
-#define ALL_ACTIVITIES 0
-*/
-
-/*****************************************************************************/
-/* Enumerations */
-/*****************************************************************************/
-enum {
- // Account
- _EMAIL_API_ADD_ACCOUNT = 0x01000000,
- _EMAIL_API_DELETE_ACCOUNT = 0x01000001,
- _EMAIL_API_UPDATE_ACCOUNT = 0x01000002,
- _EMAIL_API_GET_ACCOUNT = 0x01000003,
- _EMAIL_API_GET_ACCOUNT_LIST = 0x01000005,
- _EMAIL_API_GET_MAILBOX_COUNT = 0x01000007,
- _EMAIL_API_VALIDATE_ACCOUNT = 0x01000008,
- _EMAIL_API_ADD_ACCOUNT_WITH_VALIDATION = 0x01000009,
- _EMAIL_API_BACKUP_ACCOUNTS = 0x0100000A,
- _EMAIL_API_RESTORE_ACCOUNTS = 0x0100000B,
- _EMAIL_API_GET_PASSWORD_LENGTH_OF_ACCOUNT = 0x0100000C,
-
- // Message
- _EMAIL_API_DELETE_MAIL = 0x01100002,
- _EMAIL_API_DELETE_ALL_MAIL = 0x01100004,
- _EMAIL_API_GET_MAILBOX_LIST = 0x01100006,
- _EMAIL_API_GET_SUBMAILBOX_LIST = 0x01100007,
- _EMAIL_API_CLEAR_DATA = 0x01100009,
- _EMAIL_API_MOVE_MAIL = 0x0110000A,
- _EMAIL_API_MOVE_ALL_MAIL = 0x0110000B,
- _EMAIL_API_ADD_ATTACHMENT = 0x0110000C,
- _EMAIL_API_GET_ATTACHMENT = 0x0110000D,
- _EMAIL_API_DELETE_ATTACHMENT = 0x0110000E,
- _EMAIL_API_MODIFY_MAIL_FLAG = 0x0110000F,
- _EMAIL_API_MODIFY_MAIL_EXTRA_FLAG = 0x01100011,
- _EMAIL_API_SET_FLAGS_FIELD = 0x01100016,
- _EMAIL_API_ADD_MAIL = 0x01100017,
- _EMAIL_API_UPDATE_MAIL = 0x01100018,
- _EMAIL_API_ADD_READ_RECEIPT = 0x01100019,
-
- // Thread
- _EMAIL_API_MOVE_THREAD_TO_MAILBOX = 0x01110000,
- _EMAIL_API_DELETE_THREAD = 0x01110001,
- _EMAIL_API_MODIFY_SEEN_FLAG_OF_THREAD = 0x01110002,
-
- // Mailbox
- _EMAIL_API_ADD_MAILBOX = 0x01200000,
- _EMAIL_API_DELETE_MAILBOX = 0x01200001,
- _EMAIL_API_UPDATE_MAILBOX = 0x01200002,
- _EMAIL_API_SET_MAIL_SLOT_SIZE = 0x01200007,
-
- // Network
- _EMAIL_API_SEND_MAIL = 0x01300000,
- _EMAIL_API_SYNC_HEADER = 0x01300001,
- _EMAIL_API_DOWNLOAD_BODY = 0x01300002,
- _EMAIL_API_DOWNLOAD_ATTACHMENT = 0x01300003,
- _EMAIL_API_NETWORK_GET_STATUS = 0x01300004,
- _EMAIL_API_SEND_SAVED = 0x01300005,
- _EMAIL_API_DELETE_EMAIL = 0x01300007,
- _EMAIL_API_DELETE_EMAIL_ALL = 0x01300008,
- _EMAIL_API_GET_IMAP_MAILBOX_LIST = 0x01300015,
- _EMAIL_API_SEND_MAIL_CANCEL_JOB = 0x01300017,
- _EMAIL_API_SEARCH_MAIL_ON_SERVER = 0x01300019,
-
- // Rule
- _EMAIL_API_ADD_RULE = 0x01400000,
- _EMAIL_API_GET_RULE = 0x01400001,
- _EMAIL_API_GET_RULE_LIST = 0x01400002,
- _EMAIL_API_FIND_RULE = 0x01400003,
- _EMAIL_API_DELETE_RULE = 0x01400004,
- _EMAIL_API_UPDATE_RULE = 0x01400005,
- _EMAIL_API_CANCEL_JOB = 0x01400006,
- _EMAIL_API_GET_PENDING_JOB = 0x01400007,
- _EMAIL_API_SEND_RETRY = 0x01400008,
- _EMAIL_API_UPDATE_ACTIVITY = 0x01400009,
- _EMAIL_API_SYNC_LOCAL_ACTIVITY = 0x0140000A,
- _EMAIL_API_PRINT_RECEIVING_EVENT_QUEUE = 0x0140000B,
-
- // Etc
- _EMAIL_API_PING_SERVICE = 0x01500000,
- _EMAIL_API_UPDATE_NOTIFICATION_BAR_FOR_UNREAD_MAIL = 0x01500001,
-};
-
-enum
-{
- EMF_DELETE_LOCALLY = 0, /**< Specifies Mail Delete local only */
- EMF_DELETE_LOCAL_AND_SERVER, /**< Specifies Mail Delete local & server */
- EMF_DELETE_FOR_SEND_THREAD, /**< Created to check which activity to delete in send thread */
-};
-
-typedef enum
-{
- NOTI_MAIL_ADD = 10000,
- NOTI_MAIL_DELETE = 10001,
- NOTI_MAIL_DELETE_ALL = 10002,
- NOTI_MAIL_DELETE_WITH_ACCOUNT = 10003,
- NOTI_MAIL_DELETE_FAIL = 10007,
- NOTI_MAIL_DELETE_FINISH = 10008,
-
- NOTI_MAIL_UPDATE = 10004,
- NOTI_MAIL_FIELD_UPDATE = 10020,
-
- NOTI_MAIL_MOVE = 10005,
- NOTI_MAIL_MOVE_FAIL = 10010,
- NOTI_MAIL_MOVE_FINISH = 10006,
-
- NOTI_THREAD_MOVE = 11000,
- NOTI_THREAD_DELETE = 11001,
- NOTI_THREAD_MODIFY_SEEN_FLAG = 11002,
-
- NOTI_ACCOUNT_ADD = 20000,
- NOTI_ACCOUNT_DELETE = 20001,
- NOTI_ACCOUNT_DELETE_FAIL = 20003,
- NOTI_ACCOUNT_UPDATE = 20002,
- NOTI_ACCOUNT_UPDATE_SYNC_STATUS = 20010,
-
-
- NOTI_MAILBOX_ADD = 40000,
- NOTI_MAILBOX_DELETE = 40001,
- NOTI_MAILBOX_UPDATE = 40002,
- /* To be added more */
-}emf_noti_on_storage_event;
-
-typedef enum
-{
- NOTI_SEND_START = 1002,
- NOTI_SEND_FINISH = 1004,
- NOTI_SEND_FAIL = 1005,
- NOTI_SEND_CANCEL = 1003,
-
- NOTI_DOWNLOAD_START = 2000,
- NOTI_DOWNLOAD_FINISH,
- NOTI_DOWNLOAD_FAIL,
- NOTI_DOWNLOAD_CANCEL = 2004,
- NOTI_DOWNLOAD_NEW_MAIL = 2003,
-
- NOTI_DOWNLOAD_BODY_START = 3000,
- NOTI_DOWNLOAD_BODY_FINISH = 3002,
- NOTI_DOWNLOAD_BODY_FAIL = 3004,
- NOTI_DOWNLOAD_BODY_CANCEL = 3003,
- NOTI_DOWNLOAD_MULTIPART_BODY = 3001,
-
- NOTI_DOWNLOAD_ATTACH_START = 4000,
- NOTI_DOWNLOAD_ATTACH_FINISH,
- NOTI_DOWNLOAD_ATTACH_FAIL,
- NOTI_DOWNLOAD_ATTACH_CANCEL,
-
- NOTI_MAIL_DELETE_ON_SERVER_FAIL = 5000,
- NOTI_MAIL_MOVE_ON_SERVER_FAIL,
-
- NOTI_VALIDATE_ACCOUNT_FINISH = 7000,
- NOTI_VALIDATE_ACCOUNT_FAIL,
- NOTI_VALIDATE_ACCOUNT_CANCEL,
-
- NOTI_VALIDATE_AND_CREATE_ACCOUNT_FINISH = 8000,
- NOTI_VALIDATE_AND_CREATE_ACCOUNT_FAIL,
- NOTI_VALIDATE_AND_CREATE_ACCOUNT_CANCEL,
-
- NOTI_VALIDATE_AND_UPDATE_ACCOUNT_FINISH = 9000,
- NOTI_VALIDATE_AND_UPDATE_ACCOUNT_FAIL,
- NOTI_VALIDATE_AND_UPDATE_ACCOUNT_CANCEL,
-
- /* To be added more */
-}emf_noti_on_network_event;
-
-
-/**
- * This enumeration specifies the mail type of account.
- */
-typedef enum
-{
- EMF_BIND_TYPE_DISABLE = 0, /**< Specifies the bind type for Disabled account.*/
- EMF_BIND_TYPE_EM_CORE = 1, /**< Specifies the bind type for Callia.*/
-} emf_account_bind_t;
-
-/**
- * This enumeration specifies the server type of account.
- */
-typedef enum
-{
- EMF_SERVER_TYPE_POP3 = 1, /**< Specifies the POP3 Server.*/
- EMF_SERVER_TYPE_IMAP4, /**< Specifies the IMAP4 Server.*/
- EMF_SERVER_TYPE_SMTP, /**< Specifies the SMTP Server.*/
- EMF_SERVER_TYPE_NONE, /**< Specifies the Local.*/
- EMF_SERVER_TYPE_ACTIVE_SYNC, /** < Specifies the Active Sync. */
-} emf_account_server_t;
-
-/**
- * This enumeration specifies the mode of retrieval.
- */
-typedef enum
-{
- EMF_IMAP4_RETRIEVAL_MODE_NEW = 0, /**< Specifies the retrieval mode for new email.*/
- EMF_IMAP4_RETRIEVAL_MODE_ALL, /**< Specifies the retrieval mode for all email.*/
-} emf_imap4_retrieval_mode_t;
-
-/**
- * This enumeration specifies the filtering type.
- */
-typedef enum
-{
- EMF_FILTER_FROM = 1, /**< Specifies the filtering of sender.*/
- EMF_FILTER_SUBJECT, /**< Specifies the filtering of email subject.*/
- EMF_FILTER_BODY, /** < Specifies the filterinf of email body.*/
-} emf_rule_type_t;
-
-
-/**
- * This enumeration specifies the rules for filtering type.
- */
-typedef enum
-{
- RULE_TYPE_INCLUDES = 1, /**< Specifies the filtering rule for includes.*/
- RULE_TYPE_EXACTLY, /**< Specifies the filtering rule for Exactly same as.*/
-} emf_filtering_type_t;
-
-
-/**
- * This enumeration specifies the action for filtering type.
- */
-typedef enum
-{
- EMF_FILTER_MOVE = 1, /**< Specifies the move of email.*/
- EMF_FILTER_BLOCK = 2, /**< Specifies the block of email.*/
- EMF_FILTER_DELETE = 3, /**< Specifies delete email.*/
-} emf_rule_action_t;
-
-/**
- * This enumeration specifies the email status.
- */
-typedef enum
-{
- EMF_MAIL_STATUS_NONE = 0, /**< The Mail is in No Operation state */
- EMF_MAIL_STATUS_RECEIVED, /**< The mail is a received mail.*/
- EMF_MAIL_STATUS_SENT, /**< The mail is a sent mail.*/
- EMF_MAIL_STATUS_SAVED, /**< The mail is a saved mail.*/
- EMF_MAIL_STATUS_SAVED_OFFLINE, /**< The mail is a saved mail in offline-mode.*/
- EMF_MAIL_STATUS_SENDING, /**< The mail is being sent.*/
- EMF_MAIL_STATUS_SEND_FAILURE, /**< The mail is a mail to been failed to send.*/
- EMF_MAIL_STATUS_SEND_CANCELED, /**< The mail is a cancelled mail.*/
- EMF_MAIL_STATUS_SEND_WAIT, /**< The mail is a mail to be send .*/
-} emf_mail_status_t;
-
-/**
- * This enumeration specifies the email priority.
- */
-typedef enum
-{
- EMF_MAIL_PRIORITY_HIGH = 1, /**< The priority is high.*/
- EMF_MAIL_PRIORITY_NORMAL = 3, /**< The priority is normal.*/
- EMF_MAIL_PRIORITY_LOW = 5, /**< The priority is low.*/
-} emf_mail_priority_t;
-
-/**
- * This enumeration specifies the email status.
- */
-typedef enum
-{
- EMF_MAIL_REPORT_NONE = 0, /**< The mail isn't report mail.*/
- EMF_MAIL_REPORT_DSN, /**< The mail is a delivery-status report mail.*/
- EMF_MAIL_REPORT_MDN, /**< The mail is a read-status report mail.*/
- EMF_MAIL_REPORT_REQUEST, /**< The mail require a read-status report mail.*/
-} emf_mail_report_t;
-
-/**
- * This enumeration specifies the DRM type
- */
-typedef enum
-{
- EMF_ATTACHMENT_DRM_NONE = 0, /**< The mail isn't DRM file.*/
- EMF_ATTACHMENT_DRM_OBJECT, /**< The mail is a DRM object.*/
- EMF_ATTACHMENT_DRM_RIGHTS, /**< The mail is a DRM rights as xml format.*/
- EMF_ATTACHMENT_DRM_DCF, /**< The mail is a DRM dcf.*/
-} emf_attachment_drm_t;
-
-/**
- * This enumeration specifies the meeting request type
- */
-typedef enum
-{
- EMF_MAIL_TYPE_NORMAL = 0, /**< NOT a meeting request mail. A Normal mail */
- EMF_MAIL_TYPE_MEETING_REQUEST = 1, /**< a meeting request mail from a serve */
- EMF_MAIL_TYPE_MEETING_RESPONSE = 2, /**< a response mail about meeting reques */
- EMF_MAIL_TYPE_MEETING_ORIGINATINGREQUEST = 3 /**< a originating mail about meeting reques */
-} emf_mail_type_t;
-
-/**
- * This enumeration specifies the meeting response type
- */
-typedef enum
-{
- EMF_MEETING_RESPONSE_NONE = 0, /**< NOT response */
- EMF_MEETING_RESPONSE_ACCEPT = 1, /**< The response is acceptance */
- EMF_MEETING_RESPONSE_TENTATIVE = 2, /**< The response is tentative */
- EMF_MEETING_RESPONSE_DECLINE = 3, /**< The response is decline */
- EMF_MEETING_RESPONSE_REQUEST = 4, /**< The response is request */
- EMF_MEETING_RESPONSE_CANCEL = 5, /**< The response is cancelation */
-} emf_meeting_response_t;
-
-typedef enum
-{
- EMF_ACTION_SEND_MAIL = 0,
- EMF_ACTION_SYNC_HEADER = 1,
- EMF_ACTION_DOWNLOAD_BODY = 2,
- EMF_ACTION_DOWNLOAD_ATTACHMENT = 3,
- EMF_ACTION_DELETE_MAIL = 4,
- EMF_ACTION_SEARCH_MAIL = 5,
- EMF_ACTION_SAVE_MAIL = 6,
- EMF_ACTION_SYNC_MAIL_FLAG_TO_SERVER = 7,
- EMF_ACTION_SYNC_FLAGS_FIELD_TO_SERVER = 8,
- EMF_ACTION_MOVE_MAIL = 9,
- EMF_ACTION_CREATE_MAILBOX = 10,
- EMF_ACTION_DELETE_MAILBOX = 11,
- EMF_ACTION_SYNC_HEADER_OMA = 12,
- EMF_ACTION_VALIDATE_ACCOUNT = 13,
- EMF_ACTION_VALIDATE_AND_CREATE_ACCOUNT = 14,
- EMF_ACTION_VALIDATE_AND_UPDATE_ACCOUNT = 15,
- EMF_ACTION_ACTIVATE_PDP = 20,
- EMF_ACTION_DEACTIVATE_PDP = 21,
- EMF_ACTION_UPDATE_MAIL = 30,
- EMF_ACTION_SET_MAIL_SLOT_SIZE = 31,
- EMF_ACTION_NUM,
-} emf_action_t;
-
-/**
- * This enumeration specifies the status of getting envelope list.
- */
-typedef enum
-{
- EMF_LIST_NONE = 0,
- EMF_LIST_WAITING,
- EMF_LIST_PREPARE, /**< Specifies the preparation.*/
- EMF_LIST_CONNECTION_START, /**< Specifies the connection start.*/
- EMF_LIST_CONNECTION_SUCCEED, /**< Specifies the success of connection.*/
- EMF_LIST_CONNECTION_FINISH, /**< Specifies the connection finish.*/
- EMF_LIST_CONNECTION_FAIL, /**< Specifies the connection failure.*/
- EMF_LIST_START, /**< Specifies the getting start.*/
- EMF_LIST_PROGRESS, /**< Specifies the status of getting.*/
- EMF_LIST_FINISH, /**< Specifies the getting complete.*/
- EMF_LIST_FAIL, /**< Specifies the download failure.*/
-} emf_envelope_list_status_t;
-
-/**
- * This enumeration specifies the downloaded status of email.
- */
-typedef enum
-{
- EMF_DOWNLOAD_NONE = 0,
- EMF_DOWNLOAD_WAITING,
- EMF_DOWNLOAD_PREPARE, /**< Specifies the preparation.*/
- EMF_DOWNLOAD_CONNECTION_START, /**< Specifies the connection start.*/
- EMF_DOWNLOAD_CONNECTION_SUCCEED, /**< Specifies the success of connection.*/
- EMF_DOWNLOAD_CONNECTION_FINISH, /**< Specifies the connection finish.*/
- EMF_DOWNLOAD_CONNECTION_FAIL, /**< Specifies the connection failure.*/
- EMF_DOWNLOAD_START, /**< Specifies the download start.*/
- EMF_DOWNLOAD_PROGRESS, /**< Specifies the status of download.*/
- EMF_DOWNLOAD_FINISH, /**< Specifies the download complete.*/
- EMF_DOWNLOAD_FAIL, /**< Specifies the download failure.*/
-} emf_download_status_t;
-
-/**
- * This enumeration specifies the status of sending email.
- */
-typedef enum
-{
- EMF_SEND_NONE = 0,
- EMF_SEND_WAITING,
- EMF_SEND_PREPARE, /**< Specifies the preparation.*/
- EMF_SEND_CONNECTION_START, /**< Specifies the connection start.*/
- EMF_SEND_CONNECTION_SUCCEED, /**< Specifies the success of connection.*/
- EMF_SEND_CONNECTION_FINISH, /**< Specifies the connection finish.*/
- EMF_SEND_CONNECTION_FAIL, /**< Specifies the connection failure.*/
- EMF_SEND_START, /**< Specifies the sending start.*/
- EMF_SEND_PROGRESS, /**< Specifies the status of sending.*/
- EMF_SEND_FINISH, /**< Specifies the sending complete.*/
- EMF_SEND_FAIL, /**< Specifies the sending failure.*/
- EMF_SAVE_WAITING, /**< Specfies the Waiting of Sync */
-} emf_send_status_t;
-
-typedef enum
-{
- EMF_SYNC_NONE = 0,
- EMF_SYNC_WAITING,
- EMF_SYNC_PREPARE,
- EMF_SYNC_CONNECTION_START,
- EMF_SYNC_CONNECTION_SUCCEED,
- EMF_SYNC_CONNECTION_FINISH,
- EMF_SYNC_CONNECTION_FAIL,
- EMF_SYNC_START,
- EMF_SYNC_PROGRESS,
- EMF_SYNC_FINISH,
- EMF_SYNC_FAIL,
-} emf_sync_status_t;
-
-/**
-* This enumeration specifies the deleting status of email.
-*/
-typedef enum
-{
- EMF_DELETE_NONE = 0,
- EMF_DELETE_WAITING,
- EMF_DELETE_PREPARE, /**< Specifies the preparation.*/
- EMF_DELETE_CONNECTION_START, /**< Specifies the connection start.*/
- EMF_DELETE_CONNECTION_SUCCEED, /**< Specifies the success of connection.*/
- EMF_DELETE_CONNECTION_FINISH, /**< Specifies the connection finish.*/
- EMF_DELETE_CONNECTION_FAIL, /**< Specifies the connection failure.*/
- EMF_DELETE_START, /**< Specifies the deletion start.*/
- EMF_DELETE_PROGRESS, /**< Specifies the status of deleting.*/
- EMF_DELETE_SERVER_PROGRESS, /**< Specifies the status of server deleting.*/
- EMF_DELETE_LOCAL_PROGRESS, /**< Specifies the status of local deleting.*/
- EMF_DELETE_FINISH, /**< Specifies the deletion complete.*/
- EMF_DELETE_FAIL, /**< Specifies the deletion failure.*/
-} emf_delete_status_t;
-
-/**
-* This enumeration specifies the status of validating account
-*/
-typedef enum
-{
- EMF_VALIDATE_ACCOUNT_NONE = 0,
- EMF_VALIDATE_ACCOUNT_WAITING,
- EMF_VALIDATE_ACCOUNT_PREPARE, /**< Specifies the preparation.*/
- EMF_VALIDATE_ACCOUNT_CONNECTION_START, /**< Specifies the connection start.*/
- EMF_VALIDATE_ACCOUNT_CONNECTION_SUCCEED, /**< Specifies the success of connection.*/
- EMF_VALIDATE_ACCOUNT_CONNECTION_FINISH, /**< Specifies the connection finish.*/
- EMF_VALIDATE_ACCOUNT_CONNECTION_FAIL, /**< Specifies the connection failure.*/
- EMF_VALIDATE_ACCOUNT_START, /**< Specifies the getting start.*/
- EMF_VALIDATE_ACCOUNT_PROGRESS, /**< Specifies the status of getting.*/
- EMF_VALIDATE_ACCOUNT_FINISH, /**< Specifies the getting complete.*/
- EMF_VALIDATE_ACCOUNT_FAIL, /**< Specifies the validation failure.*/
-} emf_validate_account_status_t;
-
-typedef enum
-{
- EMF_SET_SLOT_SIZE_NONE = 0,
- EMF_SET_SLOT_SIZE_WAITING,
- EMF_SET_SLOT_SIZE_START,
- EMF_SET_SLOT_SIZE_FINISH,
- EMF_SET_SLOT_SIZE_FAIL,
-}emf_set_slot_size_status_e;
-
-/**
-* This enumeration specifies the type of mailbox
-*/
-typedef enum
-{
- EMF_MAILBOX_TYPE_NONE = 0, /**< Unspecified mailbox type*/
- EMF_MAILBOX_TYPE_INBOX = 1, /**< Specified inbox type*/
- EMF_MAILBOX_TYPE_SENTBOX = 2, /**< Specified sent box type*/
- EMF_MAILBOX_TYPE_TRASH = 3, /**< Specified trash type*/
- EMF_MAILBOX_TYPE_DRAFT = 4, /**< Specified draft box type*/
- EMF_MAILBOX_TYPE_SPAMBOX = 5, /**< Specified spam box type*/
- EMF_MAILBOX_TYPE_OUTBOX = 6, /**< Specified outbox type*/
- EMF_MAILBOX_TYPE_ALL_EMAILS = 7, /**< Specified all emails type of gmail*/
- EMF_MAILBOX_TYPE_SEARCH_RESULT = 8, /**< Specified mailbox type for result of search on server */
- EMF_MAILBOX_TYPE_USER_DEFINED = 0xFF, /**< Specified mailbox type for all other mailboxes */
-}emf_mailbox_type_e;
-
-typedef enum
-{
- EMF_SYNC_LATEST_MAILS_FIRST = 0,
- EMF_SYNC_OLDEST_MAILS_FIRST,
- EMF_SYNC_ALL_MAILBOX_50_MAILS,
-} EMF_RETRIEVE_MODE;
-
-/* event typ */
-typedef enum
-{
- EMF_EVENT_NONE = 0,
- EMF_EVENT_SYNC_HEADER = 1, /* synchronize mail headers with server (network used) */
- EMF_EVENT_DOWNLOAD_BODY = 2, /* download mail body from server (network used)*/
- EMF_EVENT_DOWNLOAD_ATTACHMENT = 3, /* download mail attachment from server (network used) */
- EMF_EVENT_SEND_MAIL = 4, /* send a mail (network used) */
- EMF_EVENT_SEND_MAIL_SAVED = 5, /* send all mails in 'outbox' box (network used) */
- EMF_EVENT_SYNC_IMAP_MAILBOX = 6, /* download imap mailboxes from server (network used) */
- EMF_EVENT_DELETE_MAIL = 7, /* delete mails (network unused) */
- EMF_EVENT_DELETE_MAIL_ALL = 8, /* delete all mails (network unused) */
- EMF_EVENT_SYNC_MAIL_FLAG_TO_SERVER = 9, /* sync mail flag to server */
- EMF_EVENT_SYNC_FLAGS_FIELD_TO_SERVER = 10, /* sync a field of flags to server */
- EMF_EVENT_SAVE_MAIL = 11,
- EMF_EVENT_MOVE_MAIL = 12, /* move mails to specific mailbox on server */
- EMF_EVENT_CREATE_MAILBOX = 13,
- EMF_EVENT_UPDATE_MAILBOX = 14,
- EMF_EVENT_DELETE_MAILBOX = 15,
- EMF_EVENT_ISSUE_IDLE = 16,
- EMF_EVENT_SYNC_HEADER_OMA = 17,
- EMF_EVENT_VALIDATE_ACCOUNT = 18,
- EMF_EVENT_VALIDATE_AND_CREATE_ACCOUNT = 19,
- EMF_EVENT_VALIDATE_AND_UPDATE_ACCOUNT = 20,
-
- EMF_EVENT_ADD_MAIL = 10001,
- EMF_EVENT_UPDATE_MAIL_OLD = 10002,
- EMF_EVENT_UPDATE_MAIL = 10003,
- EMF_EVENT_SET_MAIL_SLOT_SIZE = 20000,
-
-/* EMF_EVENT_LOCAL_ACTIVITY, // __LOCAL_ACTIVITY_ */
-
- EMF_EVENT_BULK_PARTIAL_BODY_DOWNLOAD, /* __FEATURE_PARTIAL_BODY_DOWNLOAD__ supported */
- EMF_EVENT_LOCAL_ACTIVITY_SYNC_BULK_PBD, /* __FEATURE_PARTIAL_BODY_DOWNLOAD__ supported */
- EMF_EVENT_GET_PASSWORD_LENGTH /* get password length of an account */
-} emf_event_type_t;
-
-/* event statu */
-typedef enum
-{
- EMF_EVENT_STATUS_UNUSED = 0,
- EMF_EVENT_STATUS_WAIT,
- EMF_EVENT_STATUS_STARTED,
- EMF_EVENT_STATUS_CANCELED,
-} emf_event_status_type_t;
-
-
-/* sorting_orde */
-typedef enum
-{
- EMF_SORT_DATETIME_HIGH = 0,
- EMF_SORT_DATETIME_LOW,
- EMF_SORT_SENDER_HIGH,
- EMF_SORT_SENDER_LOW,
- EMF_SORT_RCPT_HIGH,
- EMF_SORT_RCPT_LOW,
- EMF_SORT_SUBJECT_HIGH,
- EMF_SORT_SUBJECT_LOW,
- EMF_SORT_PRIORITY_HIGH,
- EMF_SORT_PRIORITY_LOW,
- EMF_SORT_ATTACHMENT_HIGH,
- EMF_SORT_ATTACHMENT_LOW,
- EMF_SORT_FAVORITE_HIGH,
- EMF_SORT_FAVORITE_LOW,
- EMF_SORT_MAILBOX_NAME_HIGH,
- EMF_SORT_MAILBOX_NAME_LOW,
- EMF_SORT_FLAGGED_FLAG_HIGH,
- EMF_SORT_FLAGGED_FLAG_LOW,
- EMF_SORT_SEEN_FLAG_HIGH,
- EMF_SORT_SEEN_FLAG_LOW,
- EMF_SORT_END,
-}emf_sort_type_t;
-
-typedef enum
-{
- EMAIL_MAILBOX_SORT_BY_NAME_ASC = 0,
- EMAIL_MAILBOX_SORT_BY_NAME_DSC,
- EMAIL_MAILBOX_SORT_BY_TYPE_ASC,
- EMAIL_MAILBOX_SORT_BY_TYPE_DSC,
-} email_mailbox_sort_type_t;
-
-
-/**
-* This enumeration specifies the priority.
-*/
-enum
-{
- EMF_OPTION_PRIORITY_HIGH = 1, /**< Specifies the high priority.*/
- EMF_OPTION_PRIORITY_NORMAL = 3, /**< Specifies the normal priority*/
- EMF_OPTION_PRIORITY_LOW = 5, /**< Specifies the low priority.*/
-};
-
-/**
-* This enumeration specifies the saving save a copy after sending.
-*/
-enum
-{
- EMF_OPTION_KEEP_LOCAL_COPY_OFF = 0, /**< Specifies off the keeping local copy.*/
- EMF_OPTION_KEEP_LOCAL_COPY_ON = 1, /**< Specifies on the keeping local copy.*/
-};
-
-/**
-* This enumeration specifies the request of delivery report.
-*/
-enum
-{
- EMF_OPTION_REQ_DELIVERY_RECEIPT_OFF = 0, /**< Specifies off the requesting delivery receipt.*/
- EMF_OPTION_REQ_DELIVERY_RECEIPT_ON = 1, /**< Specifies on the requesting delivery receipt.*/
-};
-
-/**
-* This enumeration specifies the request of read receipt.
-*/
-enum
-{
- EMF_OPTION_REQ_READ_RECEIPT_OFF = 0, /**< Specifies off the requesting read receipt.*/
- EMF_OPTION_REQ_READ_RECEIPT_ON = 1, /**< Specifies on the requesting read receipt.*/
-};
-
-/**
-* This enumeration specifies the blocking of address.
-*/
-enum
-{
- EMF_OPTION_BLOCK_ADDRESS_OFF = 0, /**< Specifies off the blocking by address.*/
- EMF_OPTION_BLOCK_ADDRESS_ON = 1, /**< Specifies on the blocking by address.*/
-};
-
-/**
-* This enumeration specifies the blocking of subject.
-*/
-enum
-{
- EMF_OPTION_BLOCK_SUBJECT_OFF = 0, /**< Specifies off the blocking by subject.*/
- EMF_OPTION_BLOCK_SUBJECT_ON = 1, /**< Specifies on the blocking by subject.*/
-};
-
-enum
-{
- EMF_LIST_TYPE_UNREAD = -3,
- EMF_LIST_TYPE_LOCAL = -2,
- EMF_LIST_TYPE_THREAD = -1,
- EMF_LIST_TYPE_NORMAL = 0
-};
-
-/**
-* This enumeration specifies the mailbox sync type.
-*/
-enum
-{
- EMF_MAILBOX_ALL = -1, /**< All mailboxes.*/
- EMF_MAILBOX_FROM_SERVER = 0, /**< Mailboxes from server. */
- EMF_MAILBOX_FROM_LOCAL = 1, /**< Mailboxes from local. */
-};
-
-typedef enum
-{
- APPEND_BODY = 1,
- UPDATE_MAILBOX,
- UPDATE_ATTACHMENT_INFO,
- UPDATE_FLAG,
- UPDATE_SAVENAME,
- UPDATE_EXTRA_FLAG,
- UPDATE_MAIL,
- UPDATE_DATETIME,
- UPDATE_FROM_CONTACT_INFO,
- UPDATE_TO_CONTACT_INFO,
- UPDATE_ALL_CONTACT_NAME,
- UPDATE_ALL_CONTACT_INFO,
- UPDATE_STICKY_EXTRA_FLAG,
- UPDATE_PARTIAL_BODY_DOWNLOAD,
- UPDATE_MEETING,
- UPDATE_SEEN_FLAG_OF_THREAD,
-} emf_mail_change_type_t;
-
-
-/**
-* This enumeration specifies the address type.
-*/
-typedef enum
-{
- EMF_ADDRESS_TYPE_FROM = 1, /**< Specifies the from address.*/
- EMF_ADDRESS_TYPE_TO, /**< Specifies the to receipient address.*/
- EMF_ADDRESS_TYPE_CC, /**< Specifies the cc receipient address.*/
- EMF_ADDRESS_TYPE_BCC, /**< Specifies the bcc receipient address.*/
- EMF_ADDRESS_TYPE_REPLY, /**< Specifies the reply receipient address.*/
- EMF_ADDRESS_TYPE_RETURN, /**< Specifies the return receipient address.*/
-} emf_address_type_t;
-
-/**
- * This enumeration specifies the search type for searching mailbox.
- */
-typedef enum
-{
- EMF_MAILBOX_SEARCH_KEY_TYPE_SUBJECT, /**< The search key is for searching subject.*/
- EMF_MAILBOX_SEARCH_KEY_TYPE_FROM, /**< The search key is for searching sender address.*/
- EMF_MAILBOX_SEARCH_KEY_TYPE_BODY, /**< The search key is for searching body.*/
- EMF_MAILBOX_SEARCH_KEY_TYPE_TO, /**< The search key is for searching recipient address.*/
-} emf_mailbox_search_key_t;
-
-/**
- * This enumeration specifies the download status of mail body.
- */
-
-typedef enum
-{
- EMF_BODY_DOWNLOAD_STATUS_NONE = 0,
- EMF_BODY_DOWNLOAD_STATUS_FULLY_DOWNLOADED = 1,
- EMF_BODY_DOWNLOAD_STATUS_PARTIALLY_DOWNLOADED = 2,
-} emf_body_download_status_t;
-
-/**
- * This enumeration specifies the moving type.
- */
-typedef enum
-{
- EMF_MOVED_BY_COMMAND = 0,
- EMF_MOVED_BY_MOVING_THREAD,
- EMF_MOVED_AFTER_SENDING
-} emf_move_type;
-
-/**
- * This enumeration specifies the deletion type.
- */
-typedef enum
-{
- EMF_DELETED_BY_COMMAND = 0,
- EMF_DELETED_BY_OVERFLOW,
- EMF_DELETED_BY_DELETING_THREAD,
- EMF_DELETED_BY_MOVING_TO_OTHER_ACCOUNT,
- EMF_DELETED_AFTER_SENDING,
- EMF_DELETED_FROM_SERVER,
-} emf_delete_type;
-
-/**
- * This enumeration specifies the status field type.
- */
-typedef enum
-{
- EMF_FLAGS_SEEN_FIELD = 0,
- EMF_FLAGS_DELETED_FIELD,
- EMF_FLAGS_FLAGGED_FIELD,
- EMF_FLAGS_ANSWERED_FIELD,
- EMF_FLAGS_RECENT_FIELD,
- EMF_FLAGS_DRAFT_FIELD,
- EMF_FLAGS_FORWARDED_FIELD,
- EMF_FLAGS_FIELD_COUNT,
-} emf_flags_field_type;
-
-typedef enum {
- EMF_FLAG_NONE = 0,
- EMF_FLAG_FLAGED = 1,
- EMF_FLAG_TASK_STATUS_CLEAR = 2,
- EMF_FLAG_TASK_STATUS_ACTIVE = 3,
- EMF_FLAG_TASK_STATUS_COMPLETE = 4,
-} emf_flagged_type;
-
-typedef enum {
- EMAIL_SEARCH_FILTER_TYPE_MESSAGE_NO = 1, /* integer type */
- EMAIL_SEARCH_FILTER_TYPE_UID = 2, /* integer type */
- EMAIL_SEARCH_FILTER_TYPE_BCC = 7, /* string type */
- EMAIL_SEARCH_FILTER_TYPE_CC = 9, /* string type */
- EMAIL_SEARCH_FILTER_TYPE_FROM = 10, /* string type */
- EMAIL_SEARCH_FILTER_TYPE_KEYWORD = 11, /* string type */
- EMAIL_SEARCH_FILTER_TYPE_SUBJECT = 13, /* string type */
- EMAIL_SEARCH_FILTER_TYPE_TO = 15, /* string type */
- EMAIL_SEARCH_FILTER_TYPE_SIZE_LARSER = 16, /* integer type */
- EMAIL_SEARCH_FILTER_TYPE_SIZE_SMALLER = 17, /* integer type */
- EMAIL_SEARCH_FILTER_TYPE_SENT_DATE_BEFORE = 20, /* time type */
- EMAIL_SEARCH_FILTER_TYPE_SENT_DATE_ON = 21, /* time type */
- EMAIL_SEARCH_FILTER_TYPE_SENT_DATE_SINCE = 22, /* time type */
- EMAIL_SEARCH_FILTER_TYPE_FLAGS_ANSWERED = 26, /* integer type */
- EMAIL_SEARCH_FILTER_TYPE_FLAGS_DELETED = 28, /* integer type */
- EMAIL_SEARCH_FILTER_TYPE_FLAGS_DRAFT = 30, /* integer type */
- EMAIL_SEARCH_FILTER_TYPE_FLAGS_FLAGED = 32, /* integer type */
- EMAIL_SEARCH_FILTER_TYPE_FLAGS_RECENT = 34, /* integer type */
- EMAIL_SEARCH_FILTER_TYPE_FLAGS_SEEN = 36, /* integer type */
- EMAIL_SEARCH_FILTER_TYPE_MESSAGE_ID = 43, /* string type */
-} email_search_filter_type;
-
-typedef enum {
- EMAIL_DRM_TYPE_NONE = 0,
- EMAIL_DRM_TYPE_OBJECT = 1,
- EMAIL_DRM_TYPE_RIGHT = 2,
- EMAIL_DRM_TYPE_DCF = 3
-} email_drm_type;
-
-typedef enum {
- EMAIL_DRM_METHOD_NONE = 0,
- EMAIL_DRM_METHOD_FL = 1,
- EMAIL_DRM_METHOD_CD = 2,
- EMAIL_DRM_METHOD_SSD = 3,
- EMAIL_DRM_METHOD_SD = 4
-} email_drm_method;
-
-/*****************************************************************************/
-/* Data Structures */
-/*****************************************************************************/
-
-/**
- * This structure is used to save mail time.
- */
-typedef struct
-{
- unsigned short year; /**< Specifies the Year.*/
- unsigned short month; /**< Specifies the Month.*/
- unsigned short day; /**< Specifies the Day.*/
- unsigned short hour; /**< Specifies the Hour.*/
- unsigned short minute; /**< Specifies the Minute.*/
- unsigned short second; /**< Specifies the Second.*/
-} emf_datetime_t;
-
-/**
- * This structure is used to save the options.
- */
-typedef struct
-{
- int priority; /**< Specifies the prority. 1=high 3=normal 5=low.*/
- int keep_local_copy; /**< Specifies the saving save a copy after sending.*/
- int req_delivery_receipt; /**< Specifies the request of delivery report. 0=off 1=on*/
- int req_read_receipt; /**< Specifies the request of read receipt. 0=off 1=on*/
- int download_limit; /**< Specifies the limit of size for downloading.*/
- int block_address; /**< Specifies the blocking of address. 0=off 1=on*/
- int block_subject; /**< Specifies the blocking of subject. 0=off 1=on*/
- char *display_name_from; /**< Specifies the display name of from.*/
- int reply_with_body; /**< Specifies the replying with body 0=off 1=on*/
- int forward_with_files; /**< Specifies the fowarding with files 0=off 1=on*/
- int add_myname_card; /**< Specifies the adding name card 0=off 1=on*/
- int add_signature; /**< Specifies the adding signature 0=off 1=on*/
- char *signature; /**< Specifies the signature*/
- int add_my_address_to_bcc; /**< Specifies whether bcc field should be always filled with my address. 0=off 1=on*/
-} emf_option_t;
-
-/**
- * This structure is used to save the information of email account.
- */
-typedef struct
-{
- emf_account_bind_t account_bind_type; /**< Specifies the Bind Type.*/
- char *account_name; /**< Specifies the account name.*/
- emf_account_server_t receiving_server_type; /**< Specifies the receiving server type.*/
- char *receiving_server_addr; /**< Specifies the address of receiving server.*/
- char *email_addr; /**< Specifies the email adderee.*/
- char *user_name; /**< Specifies the user name.*/
- char *password; /**< Specifies the password.*/
- emf_imap4_retrieval_mode_t retrieval_mode; /**< Specifies the retrieval mode in IMAP case.*/
- int port_num; /**< Specifies the port number of receiving server.*/
- int use_security; /**< Specifies the security such as SSL.*/
- emf_account_server_t sending_server_type; /**< Specifies the type of sending server.*/
- char *sending_server_addr; /**< Specifies the address of sending server.*/
- int sending_port_num; /**< Specifies the port number of sending server.*/
- int sending_auth; /**< Specifies the authentication of sending server.*/
- int sending_security; /**< Specifies the security such as SSL.*/
- char *sending_user; /**< Specifies the user name of SMTP server.*/
- char *sending_password; /**< Specifies the user password of SMTP server.*/
- char *display_name; /**< Specifies the display name.*/
- char *reply_to_addr; /**< Specifies the reply email address.*/
- char *return_addr; /**< Specifies the email address for return.*/
- int account_id; /**< Specifies the ID of account. Especially, 1 is assigned to Local Account.*/
- int keep_on_server; /**< Specifies the keeping mail on server.*/
- int flag1; /**< Specifies the downloading option. 0 is subject only, 1 is text body, 2 is normal.*/
- int flag2; /**< Specifies the 'Same as POP3' option. 0 is none, 1 is 'Same as POP3'.*/
- int pop_before_smtp; /**< POP before SMTP authentication */
- int apop; /**< APOP Authentication */
- char *logo_icon_path; /**< Account logo icon */
- int preset_account; /**< Preset account or not */
- emf_option_t options; /**< Specifies the Sending options */
- int target_storage; /**< Specifies the targetStorage. 0 is phone, 1 is MMC */
- int check_interval; /**< Specifies the Check interval. Unit is minutes */
- int my_account_id; /**< Specifies accout id of my account */
- int index_color; /**< Specifies index color for displaying classifying accounts */
-}emf_account_t;
-
-/**
- * This structure is used to save the information of email server.
- */
-
-typedef struct
-{
- int configuration_id; /**< Specifies the id of configuration.*/
- emf_account_server_t protocol_type; /**< Specifies the type of configuration.*/
- char *server_addr; /**< Specifies the address of configuration.*/
- int port_number; /**< Specifies the port number of configuration.*/
- int security_type; /**< Specifies the security such as SSL.*/
- int auth_type; /**< Specifies the authentication type of configuration.*/
-} emf_protocol_config_t;
-
-typedef struct
-{
- char *service_name; /**< Specifies the name of service.*/
- int authname_format; /**< Specifies the type of user name for authentication.*/
- int protocol_conf_count; /**< Specifies count of protocol configurations.*/
- emf_protocol_config_t *protocol_config_array; /**< Specifies array of protocol configurations.*/
-} emf_server_info_t;
-
-typedef struct
-{
- int mailbox_type;
- char mailbox_name[MAILBOX_NAME_LENGTH];
-} emf_mailbox_type_item_t;
-
-/**
- * This structure is contains the Mail information.
- */
-
-typedef struct
-{
- int mail_id; /**< Specifies the Mail ID.*/
- int account_id; /**< Specifies the Account ID.*/
- char *mailbox_name; /**< Specifies the Mailbox Name.*/
- int mailbox_type; /**< Specifies the mailbox type of the mail. */
- char *subject; /**< Specifies the subject.*/
- time_t date_time; /**< Specifies the Date time.*/
- int server_mail_status; /**< Specifies the Whether sever mail or not.*/
- char *server_mailbox_name; /**< Specifies the server mailbox.*/
- char *server_mail_id; /**< Specifies the Server Mail ID.*/
- char *message_id; /**< Specifies the message id */
- char *full_address_from; /**< Specifies the From Addr.*/
- char *full_address_reply; /**< Specifies the Reply to addr */
- char *full_address_to; /**< Specifies the To addr.*/
- char *full_address_cc; /**< Specifies the CC addr.*/
- char *full_address_bcc; /**< Specifies the BCC addr*/
- char *full_address_return; /**< Specifies the return Path*/
- char *email_address_sender; /**< Specifies the email address of sender.*/
- char *email_address_recipient; /**< Specifies the email address of recipients.*/
- char *alias_sender; /**< Specifies the alias of sender. */
- char *alias_recipient; /**< Specifies the alias of recipients. */
- int body_download_status; /**< Specifies the Text donwloaded or not.*/
- char *file_path_plain; /**< Specifies the path of text mail body.*/
- char *file_path_html; /**< Specifies the path of HTML mail body.*/
- int mail_size; /**< Specifies the Mail Size.*/
- char flags_seen_field; /**< Specifies the seen flags*/
- char flags_deleted_field; /**< Specifies the deleted flags*/
- char flags_flagged_field; /**< Specifies the flagged flags*/
- char flags_answered_field; /**< Specifies the answered flags*/
- char flags_recent_field; /**< Specifies the recent flags*/
- char flags_draft_field; /**< Specifies the draft flags*/
- char flags_forwarded_field; /**< Specifies the forwarded flags*/
- int DRM_status; /**< Has the mail DRM content? (1 : true, 0 : false) */
- int priority; /**< Specifies the priority of the mail.*/
- int save_status; /**< Specifies the save status*/
- int lock_status; /**< Specifies the Locked*/
- int report_status; /**< Specifies the Mail Report.*/
- int attachment_count; /**< Specifies the attachment count. */
- int inline_content_count; /**< Specifies the inline content count. */
- int thread_id; /**< Specifies the thread id for thread view. */
- int thread_item_count; /**< Specifies the item count of specific thread. */
- char *preview_text; /**< Specifies the preview body. */
- int meeting_request_status; /**< Specifies the status of meeting request. */
-}emf_mail_data_t;
-
-/**
- * This structure is contains information for displaying mail list.
- */
-typedef struct
-{
- int mail_id; /**< Specifies the Mail ID.*/
- int account_id; /**< Specifies the Account ID.*/
- char mailbox_name[STRING_LENGTH_FOR_DISPLAY]; /**< Specifies the Mailbox Name.*/
- char from[STRING_LENGTH_FOR_DISPLAY]; /**< Specifies the from display name.*/
- char from_email_address[MAX_EMAIL_ADDRESS_LENGTH]; /**< Specifies the from email address.*/
- char recipients[STRING_LENGTH_FOR_DISPLAY]; /**< Specifies the recipients display name.*/
- char subject[STRING_LENGTH_FOR_DISPLAY]; /**< Specifies the subject.*/
- int is_text_downloaded; /**< Specifies the Text donwloaded or not.*/
- time_t date_time; /**< Specifies the Date time.*/
- char flags_seen_field; /**< Specifies the seen flags*/
- char flags_deleted_field; /**< Specifies the deleted flags*/
- char flags_flagged_field; /**< Specifies the flagged flags*/
- char flags_answered_field; /**< Specifies the answered flags*/
- char flags_recent_field; /**< Specifies the recent flags*/
- char flags_draft_field; /**< Specifies the draft flags*/
- char flags_forwarded_field; /**< Specifies the forwarded flags*/
- int priority; /**< Specifies the priority of Mails.*/
- int save_status; /**< Specifies the save status*/
- int is_locked; /**< Specifies the Locked*/
- int is_report_mail; /**< Specifies the Mail Report.*/
- int recipients_count; /**< Specifies the number of to Recipients*/
- int has_attachment; /**< the mail has attachments or not[ 0: none, 1: over one] */
- int has_drm_attachment; /**< the mail has drm attachment or not*/
- char previewBodyText[MAX_PREVIEW_TEXT_LENGTH]; /**< text for preview body*/
- int thread_id; /**< thread id for thread view*/
- int thread_item_count; /**< item count of specific thread */
- int is_meeting_request; /**< Whether the mail is a meeting request or not */
-}emf_mail_list_item_t;
-
-/**
- * This structure is used to save the filtering structure.
- */
-typedef struct
-{
- int account_id; /**< Specifies the account ID.*/
- int filter_id; /**< Specifies the filtering ID.*/
- emf_rule_type_t type; /**< Specifies the filtering type.*/
- char *value; /**< Specifies the filtering value.*/
- emf_rule_action_t faction; /**< Specifies the action type for filtering.*/
- char *mailbox; /**< Specifies the mail box if action type means move.*/
- int flag1; /**< Specifies the activation.*/
- int flag2; /**< Reserved.*/
-} emf_rule_t;
-
-/**
- * This structure is used to save the information of mail flag.
- */
-typedef struct
-{
- unsigned int seen : 1; /**< Specifies the read email.*/
- unsigned int deleted : 1; /**< Reserved.*/
- unsigned int flagged : 1; /**< Specifies the flagged email.*/
- unsigned int answered : 1; /**< Reserved.*/
- unsigned int recent : 1; /**< Reserved.*/
- unsigned int draft : 1; /**< Specifies the draft email.*/
- unsigned int has_attachment : 1; /**< Reserved.*/
- unsigned int forwarded : 1; /**< Reserved.*/
- unsigned int sticky : 1; /**< Sticky flagged mails cannot be deleted */
-} emf_mail_flag_t;
-
-
-/**
- * This structure is used to save the information of mail extra flag.
- */
-typedef struct
-{
- unsigned int priority : 3; /**< Specifies the mail priority.
- The value is greater than or equal to EMF_MAIL_PRIORITY_HIGH.
- The value is less than or eqult to EMF_MAIL_PRIORITY_LOW.*/
- unsigned int status : 4; /**< Specifies the mail status.
- The value is a value of enumeration emf_mail_status_t.*/
- unsigned int noti : 1; /**< Specifies the notified mail.*/
- unsigned int lock : 1; /**< Specifies the locked mail.*/
- unsigned int report : 2; /**< Specifies the MDN/DSN mail. The value is a value of enumeration emf_mail_report_t.*/
- unsigned int drm : 1; /**< Specifies the drm mail.*/
- unsigned int text_download_yn : 2; /**< body download y/n*/ /* To be removed */
-} emf_extra_flag_t;
-
-/**
- * This structure is used to save the information of attachment.
- */
-typedef struct st_emf_attachment_info
-{
- int inline_content;
- int attachment_id; /**< Specifies the attachment ID*/
- char *name; /**< Specifies the attachment name.*/
- int size; /**< Specifies the attachment size.*/
- int downloaded; /**< Specifies the download of attachment.*/
- char *savename; /**< Specifies the absolute path of attachment.*/
- int drm; /**< Specifies the drm type.*/
- char *attachment_mime_type; /**< Specifies the context mime type.*/
- struct st_emf_attachment_info *next; /**< Specifies the pointer of next attachment.*/
-} emf_attachment_info_t;
-
-typedef struct
-{
- int attachment_id;
- char *attachment_name;
- char *attachment_path;
- int attachment_size;
- int mail_id;
- int account_id;
- char *mailbox_name;
- int save_status;
- int drm_status;
- int inline_content_status;
- char *attachment_mime_type; /**< Specifies the context mime type.*/
-} emf_attachment_data_t;
-
-typedef struct
-{
- int offset_from_GMT;
- char standard_name[32];
- struct tm standard_time_start_date;
- int standard_bias;
- char daylight_name[32];
- struct tm daylight_time_start_date;
- int daylight_bias;
-} emf_time_zone_t;
-
-typedef struct
-{
- int mail_id; /**< Specifies the mail id of meeting request on DB. This is the primary key. */
- emf_meeting_response_t meeting_response; /**< Specifies the meeting response. */
- struct tm start_time;
- struct tm end_time;
- char *location; /**< Specifies the location of meeting. Maximum length of this string is 32768 */
- char *global_object_id; /**< Specifies the object id. */
- emf_time_zone_t time_zone;
-} emf_meeting_request_t;
-
-/**
- * This structure is used to save the informatioin of sender list with unread/total mail counts
- */
-typedef struct
-{
- char *address; /**< Specifies the address of a sender.*/
- char *display_name; /**< Specifies a display name. This may be one of contact name, alias in original mail and email address of sender. (Priority order : contact name, alias, email address) */
- int unread_count; /**< Specifies the number of unread mails received from sender address*/
- int total_count; /**< Specifies the total number of mails which are received from sender address*/
-} emf_sender_list_t;
-
-
-/* Creates a type name for structure emf_mailbox_st */
-typedef struct emf_mailbox_st emf_mailbox_t; /**< This is an information of mail box. */
-
-/**
- * This structure is used to save the information of mailbox.
- */
-struct emf_mailbox_st
-{
- int mailbox_id; /**< Unique id on mailbox table.*/
- char *name; /**< Specifies the path of mailbox.*/
- emf_mailbox_type_e mailbox_type;
- char *alias; /**< Specifies the display name of mailbox.*/
- int unread_count; /**< Specifies the Unread Mail count in the mailbox.*/
- int total_mail_count_on_local; /**< Specifies the total number of mails in the mailbox in the local DB.*/
- int total_mail_count_on_server; /**< Specifies the total number of mails in the mailbox in the mail server.*/
- int hold_connection; /**< Will have a valid socket descriptor when connection to server is active.. else 0>*/
- int local; /**< Specifies the local mailbox.*/
- int synchronous; /**< Specifies the mailbox with synchronized the server.*/
- int account_id; /**< Specifies the account ID for mailbox.*/
- void *user_data; /**< Specifies the internal data.*/
- void *mail_stream; /**< Specifies the internal data.*/
- int has_archived_mails; /**< Specifies the archived mails.*/
- int mail_slot_size; /**< Specifies how many mails can be stored.*/
- char *account_name; /**< Specifies the name of account.*/
- emf_mailbox_t *next; /**< Reserved.*/
-};
-
-
-typedef struct
-{
- char *contact_name;
- char *email_address;
- char *alias;
- int storage_type;
- int contact_id;
-} emf_mail_contact_info_t;
-
-typedef struct
-{
- emf_address_type_t address_type;
- char *address;
- char *display_name;
- int storage_type;
- int contact_id;
-} emf_address_info_t;
-
-typedef struct
-{
- GList *from;
- GList *to;
- GList *cc;
- GList *bcc;
-} emf_address_info_list_t;
-
-typedef struct
-{
- int address_type; /* type of mail (sender : 0, recipient : 1)*/
- int address_count; /* The number of email addresse */
- char **address_list; /* strings of email addresse */
-}emf_email_address_list_t;
-
-/* global account lis */
-typedef struct emf_account_list_t emf_account_list_t;
-struct emf_account_list_t
-{
- emf_account_t *account;
- emf_account_list_t *next;
-};
-
-
-typedef struct _email_search_filter_t {
- email_search_filter_type search_filter_type; /* type of search filter */
- union {
- int integer_type_key_value;
- struct tm time_type_key_value;
- char *string_type_key_value;
- } search_filter_key_value;
-} email_search_filter_t;
-
-
-/*****************************************************************************/
-/* For Active Sync */
-/*****************************************************************************/
-
-#define VCONFKEY_EMAIL_SERVICE_ACTIVE_SYNC_HANDLE "db/email_handle/active_sync_handle"
-#define EMF_ACTIVE_SYNC_NOTI "User.Email.ActiveSync"
-
-typedef enum
-{
- ACTIVE_SYNC_NOTI_SEND_MAIL, /* a sending notification to ASE (active sync engine */
- ACTIVE_SYNC_NOTI_SEND_SAVED, /* a sending notification to ASE (active sync engine), All saved mails should be sent */
- ACTIVE_SYNC_NOTI_SEND_REPORT, /* a sending notification to ASE (active sync engine), report should be sen */
- ACTIVE_SYNC_NOTI_SYNC_HEADER, /* a sync header - download mails from server. */
- /* It is depended on account/s flag1 field whether it excutes downloading header only or downloading header + body */
- /* downloading option : 0 is subject only, 1 is text body, 2 is normal */
- ACTIVE_SYNC_NOTI_DOWNLOAD_BODY, /* a downloading body notification to AS */
- ACTIVE_SYNC_NOTI_DOWNLOAD_ATTACHMENT, /* a downloading attachment notification to AS */
- ACTIVE_SYNC_NOTI_VALIDATE_ACCOUNT, /* a account validating notification to AS */
- ACTIVE_SYNC_NOTI_CANCEL_JOB, /* a cancling job notification to AS */
- ACTIVE_SYNC_NOTI_SEARCH_ON_SERVER, /* a searching on server notification to AS */
-} eactivesync_noti_t;
-
-typedef union
-{
- struct _send_mail
- {
- int handle;
- int account_id;
- char *mailbox_name;
- int mail_id;
- emf_option_t options;
- } send_mail;
-
- struct _send_mail_saved
- {/* not defined ye */
- int handle;
- int account_id;
- } send_mail_saved;
-
- struct _send_report
- {/* not defined ye */
- int handle;
- int account_id;
- } send_report;
-
- struct _sync_header
- {
- int handle;
- int account_id;
- char *mailbox_name;
- } sync_header;
-
- struct _download_body
- {
- int handle;
- int account_id;
- int mail_id;
- int with_attachment; /* 0: without attachments, 1: with attachment */
- } download_body;
-
- struct _download_attachment
- {
- int handle;
- int account_id;
- int mail_id;
- char *attachment_order;
- } download_attachment;
-
- struct _cancel_job
- {
- int account_id;
- int handle; /* job handle to be canceled. this value is issued by email-service (actually in Emf_Mapi_xxx() */
- } cancel_job;
-
- struct _validate_account
- {/* not defined yet */
- int handle;
- int account_id;
- } validate_account;
-
- struct _search_mail_on_server
- {
- int handle;
- int account_id;
- char *mailbox_name;
- email_search_filter_t *search_filter_list;
- int search_filter_count;
- } search_mail_on_server;
-
-} ASNotiData;
-
-
-/* types for noti string */
-typedef enum
-{
- EMF_CONVERT_STRUCT_TYPE_MAIL_LIST_ITEM, /** specifies emf_mail_list_t */
-} emf_convert_struct_type_e;
-
-#ifdef __cplusplus
-}
-#endif
-
-/**
-* @} @}
-*/
-
-#endif /* __EMF_LIB_H__ */
-
+/*
+* email-service
+*
+* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+*
+* Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com>
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*
+*/
+
+
+#ifndef __EMAIL_TYPES_H__
+#define __EMAIL_TYPES_H__
+
+/**
+* @defgroup EMAIL_SERVICE Email Service
+* @{
+*/
+
+/**
+* @ingroup EMAIL_SERVICE
+* @defgroup EMAIL_TYPES Email Types
+* @{
+*/
+/**
+ * This file defines structures and enums of Email Framework.
+ * @file email-types.h
+ * @author Kyu-ho Jo(kyuho.jo@samsung.com)
+ * @author Choongho Lee(ch715.lee@samsung.com)
+ * @version 0.1
+ * @brief This file is the header file of Email Framework library.
+ */
+
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif /* __cplusplus */
+
+#include <glib.h>
+#include <stdbool.h>
+#include "email-errors.h"
+
+
+/*****************************************************************************/
+/* Macros */
+/*****************************************************************************/
+
+#define MAILBOX_NAME_LENGTH 256
+#define MAX_EMAIL_ADDRESS_LENGTH 320 /* 64(user name) + 1(@) + 255(host name */
+#define MAX_DATETIME_STRING_LENGTH 20
+#define MAX_PREVIEW_TEXT_LENGTH 512
+#define STRING_LENGTH_FOR_DISPLAY 100
+#define MEETING_REQ_OBJECT_ID_LENGTH 256
+
+#define ALL_ACCOUNT 0
+#define NEW_ACCOUNT_ID 0xFFFFFFFE
+#define ALL_MAIL -1
+
+#define EMAIL_SEARCH_FILTER_NONE 0x00
+#define EMAIL_SEARCH_FILTER_SUBJECT 0x01
+#define EMAIL_SEARCH_FILTER_SENDER 0x02
+#define EMAIL_SEARCH_FILTER_RECIPIENT 0x04
+#define EMAIL_SEARCH_FILTER_ALL 0x07 /* EMAIL_SEARCH_FILTER_SUBJECT + EMAIL_SEARCH_FILTER_SENDER + EMAIL_SEARCH_FILTER_RECIPIEN */
+
+#define EMAIL_SUCCESS 0 /* we need to modify the success return valu */
+
+#define EMAIL_ACC_GET_OPT_DEFAULT 0x01 /**< Default values without account name */
+#define EMAIL_ACC_GET_OPT_ACCOUNT_NAME 0x02 /**< Account name */
+#define EMAIL_ACC_GET_OPT_PASSWORD 0x04 /**< With password */
+#define EMAIL_ACC_GET_OPT_OPTIONS 0x08 /**< Account options : email_option_t */
+#define EMAIL_ACC_GET_OPT_FULL_DATA 0xFF /**< With all data of account */
+
+#define GET_FULL_DATA (EMAIL_ACC_GET_OPT_FULL_DATA)
+#define GET_FULL_DATA_WITHOUT_PASSWORD (EMAIL_ACC_GET_OPT_DEFAULT | EMAIL_ACC_GET_OPT_ACCOUNT_NAME | EMAIL_ACC_GET_OPT_OPTIONS )
+#define WITHOUT_OPTION (EMAIL_ACC_GET_OPT_DEFAULT | EMAIL_ACC_GET_OPT_ACCOUNT_NAME )
+#define ONLY_OPTION (EMAIL_ACC_GET_OPT_OPTIONS)
+
+#define THREAD_TYPE_RECEIVING 0 /**< for function 'email_activate_pdp' */
+#define THREAD_TYPE_SENDING 1 /**< for function 'email_activate_pdp' */
+
+#define EMAIL_IMAP_PORT 143 /**< Specifies the default IMAP port.*/
+#define EMAIL_POP3_PORT 110 /**< Specifies the default POP3 port.*/
+#define EMAIL_SMTP_PORT 25 /**< Specifies the default SMTP port.*/
+#define EMAIL_IMAPS_PORT 993 /**< Specifies the default IMAP SSL port.*/
+#define EMAIL_POP3S_PORT 995 /**< Specifies the default POP3 SSL port.*/
+#define EMAIL_SMTPS_PORT 465 /**< Specifies the default SMTP SSL port.*/
+#define EMAIL_ACCOUNT_MAX 10 /**< Specifies the MAX account.*/
+
+#define EMAIL_INBOX_NAME "INBOX" /**< Specifies the name of inbox.*/
+#define EMAIL_DRAFTBOX_NAME "DRAFTBOX" /**< Specifies the name of draftbox.*/
+#define EMAIL_OUTBOX_NAME "OUTBOX" /**< Specifies the name of outbox.*/
+#define EMAIL_SENTBOX_NAME "SENTBOX" /**< Specifies the name of sentbox.*/
+#define EMAIL_TRASH_NAME "TRASH" /**< Specifies the name of trash.*/
+#define EMAIL_SPAMBOX_NAME "SPAMBOX" /**< Specifies the name of spambox.*/
+
+#define EMAIL_INBOX_DISPLAY_NAME "Inbox" /**< Specifies the display name of inbox.*/
+#define EMAIL_DRAFTBOX_DISPLAY_NAME "Draftbox" /**< Specifies the display name of draftbox.*/
+#define EMAIL_OUTBOX_DISPLAY_NAME "Outbox" /**< Specifies the display name of outbox.*/
+#define EMAIL_SENTBOX_DISPLAY_NAME "Sentbox" /**< Specifies the display name of sentbox.*/
+#define EMAIL_TRASH_DISPLAY_NAME "Trash" /**< Specifies the display name of sentbox.*/
+#define EMAIL_SPAMBOX_DISPLAY_NAME "Spambox" /**< Specifies the display name of spambox.*/
+
+#define EMAIL_SEARCH_RESULT_MAILBOX_NAME "_`S1!E2@A3#R4$C5^H6&R7*E8(S9)U0-L=T_" /**< Specifies the name of search result mailbox.*/
+
+#define SYNC_STATUS_FINISHED 0 /* BIN 00000000 */
+#define SYNC_STATUS_SYNCING 1 /* BIN 00000001 */
+#define SYNC_STATUS_HAVE_NEW_MAILS 2 /* BIN 00000010 */
+
+
+#define FAILURE -1
+#define SUCCESS 0
+
+#define DAEMON_EXECUTABLE_PATH "/usr/bin/email-service"
+
+#ifndef EXPORT_API
+#define EXPORT_API __attribute__((visibility("default")))
+#endif
+
+#ifndef DEPRECATED
+#define DEPRECATED __attribute__((deprecated))
+#endif
+
+/* __FEATURE_LOCAL_ACTIVITY__ supported
+#define BULK_OPERATION_COUNT 50
+#define ALL_ACTIVITIES 0
+*/
+
+/*****************************************************************************/
+/* Enumerations */
+/*****************************************************************************/
+enum {
+ /* Account */
+ _EMAIL_API_ADD_ACCOUNT = 0x01000000,
+ _EMAIL_API_DELETE_ACCOUNT = 0x01000001,
+ _EMAIL_API_UPDATE_ACCOUNT = 0x01000002,
+ _EMAIL_API_GET_ACCOUNT = 0x01000003,
+ _EMAIL_API_GET_ACCOUNT_LIST = 0x01000005,
+ _EMAIL_API_GET_MAILBOX_COUNT = 0x01000007,
+ _EMAIL_API_VALIDATE_ACCOUNT = 0x01000008,
+ _EMAIL_API_ADD_ACCOUNT_WITH_VALIDATION = 0x01000009,
+ _EMAIL_API_BACKUP_ACCOUNTS = 0x0100000A,
+ _EMAIL_API_RESTORE_ACCOUNTS = 0x0100000B,
+ _EMAIL_API_GET_PASSWORD_LENGTH_OF_ACCOUNT = 0x0100000C,
+
+ /* Mail */
+ _EMAIL_API_DELETE_MAIL = 0x01100002,
+ _EMAIL_API_DELETE_ALL_MAIL = 0x01100004,
+ _EMAIL_API_GET_MAILBOX_LIST = 0x01100006,
+ _EMAIL_API_GET_SUBMAILBOX_LIST = 0x01100007,
+ _EMAIL_API_CLEAR_DATA = 0x01100009,
+ _EMAIL_API_MOVE_MAIL = 0x0110000A,
+ _EMAIL_API_MOVE_ALL_MAIL = 0x0110000B,
+ _EMAIL_API_ADD_ATTACHMENT = 0x0110000C,
+ _EMAIL_API_GET_ATTACHMENT = 0x0110000D,
+ _EMAIL_API_DELETE_ATTACHMENT = 0x0110000E,
+ _EMAIL_API_MODIFY_MAIL_FLAG = 0x0110000F,
+ _EMAIL_API_MODIFY_MAIL_EXTRA_FLAG = 0x01100011,
+ _EMAIL_API_SET_FLAGS_FIELD = 0x01100016,
+ _EMAIL_API_ADD_MAIL = 0x01100017,
+ _EMAIL_API_UPDATE_MAIL = 0x01100018,
+ _EMAIL_API_ADD_READ_RECEIPT = 0x01100019,
+ _EMAIL_API_EXPUNGE_MAILS_DELETED_FLAGGED = 0x0110001A,
+
+ /* Thread */
+ _EMAIL_API_MOVE_THREAD_TO_MAILBOX = 0x01110000,
+ _EMAIL_API_DELETE_THREAD = 0x01110001,
+ _EMAIL_API_MODIFY_SEEN_FLAG_OF_THREAD = 0x01110002,
+
+ /* Mailbox */
+ _EMAIL_API_ADD_MAILBOX = 0x01200000,
+ _EMAIL_API_DELETE_MAILBOX = 0x01200001,
+ _EMAIL_API_UPDATE_MAILBOX = 0x01200002,
+ _EMAIL_API_SET_MAIL_SLOT_SIZE = 0x01200007,
+ _EMAIL_API_RENAME_MAILBOX = 0x01200008,
+ _EMAIL_API_SET_MAILBOX_TYPE = 0x01200009,
+
+ /* Network */
+ _EMAIL_API_SEND_MAIL = 0x01300000,
+ _EMAIL_API_SYNC_HEADER = 0x01300001,
+ _EMAIL_API_DOWNLOAD_BODY = 0x01300002,
+ _EMAIL_API_DOWNLOAD_ATTACHMENT = 0x01300003,
+ _EMAIL_API_NETWORK_GET_STATUS = 0x01300004,
+ _EMAIL_API_SEND_SAVED = 0x01300005,
+ _EMAIL_API_DELETE_EMAIL = 0x01300007,
+ _EMAIL_API_DELETE_EMAIL_ALL = 0x01300008,
+ _EMAIL_API_GET_IMAP_MAILBOX_LIST = 0x01300015,
+ _EMAIL_API_SEND_MAIL_CANCEL_JOB = 0x01300017,
+ _EMAIL_API_SEARCH_MAIL_ON_SERVER = 0x01300019,
+ _EMAIL_API_CLEAR_RESULT_OF_SEARCH_MAIL_ON_SERVER = 0x0130001A,
+
+ /* Rule */
+ _EMAIL_API_ADD_RULE = 0x01400000,
+ _EMAIL_API_GET_RULE = 0x01400001,
+ _EMAIL_API_GET_RULE_LIST = 0x01400002,
+ _EMAIL_API_FIND_RULE = 0x01400003,
+ _EMAIL_API_DELETE_RULE = 0x01400004,
+ _EMAIL_API_UPDATE_RULE = 0x01400005,
+ _EMAIL_API_CANCEL_JOB = 0x01400006,
+ _EMAIL_API_GET_PENDING_JOB = 0x01400007,
+ _EMAIL_API_SEND_RETRY = 0x01400008,
+ _EMAIL_API_UPDATE_ACTIVITY = 0x01400009,
+ _EMAIL_API_SYNC_LOCAL_ACTIVITY = 0x0140000A,
+ _EMAIL_API_PRINT_RECEIVING_EVENT_QUEUE = 0x0140000B,
+
+ /* Etc */
+ _EMAIL_API_PING_SERVICE = 0x01500000,
+ _EMAIL_API_UPDATE_NOTIFICATION_BAR_FOR_UNREAD_MAIL = 0x01500001,
+ _EMAIL_API_SHOW_USER_MESSAGE = 0x01500002,
+
+ /* Smime */
+ _EMAIL_API_ADD_CERTIFICATE = 0x01600000,
+ _EMAIL_API_DELETE_CERTIFICATE = 0x01600001,
+ _EMAIL_API_VERIFY_SIGNATURE = 0x01600002,
+ _EMAIL_API_VERIFY_CERTIFICATE = 0x01600003,
+};
+
+typedef enum
+{
+ EMAIL_DELETE_LOCALLY = 0, /**< Specifies Mail Delete local only */
+ EMAIL_DELETE_LOCAL_AND_SERVER, /**< Specifies Mail Delete local & server */
+ EMAIL_DELETE_FOR_SEND_THREAD, /**< Created to check which activity to delete in send thread */
+ EMAIL_DELETE_FROM_SERVER,
+} email_delete_option_t;
+
+typedef enum
+{
+ NOTI_MAIL_ADD = 10000,
+ NOTI_MAIL_DELETE = 10001,
+ NOTI_MAIL_DELETE_ALL = 10002,
+ NOTI_MAIL_DELETE_WITH_ACCOUNT = 10003,
+ NOTI_MAIL_DELETE_FAIL = 10007,
+ NOTI_MAIL_DELETE_FINISH = 10008,
+
+ NOTI_MAIL_UPDATE = 10004,
+ NOTI_MAIL_FIELD_UPDATE = 10020,
+
+ NOTI_MAIL_MOVE = 10005,
+ NOTI_MAIL_MOVE_FAIL = 10010,
+ NOTI_MAIL_MOVE_FINISH = 10006,
+
+ NOTI_THREAD_MOVE = 11000,
+ NOTI_THREAD_DELETE = 11001,
+ NOTI_THREAD_MODIFY_SEEN_FLAG = 11002,
+
+ NOTI_ACCOUNT_ADD = 20000,
+ NOTI_ACCOUNT_DELETE = 20001,
+ NOTI_ACCOUNT_DELETE_FAIL = 20003,
+ NOTI_ACCOUNT_UPDATE = 20002,
+ NOTI_ACCOUNT_UPDATE_SYNC_STATUS = 20010,
+
+ NOTI_MAILBOX_ADD = 40000,
+ NOTI_MAILBOX_DELETE = 40001,
+ NOTI_MAILBOX_UPDATE = 40002,
+
+ NOTI_MAILBOX_RENAME = 40010,
+ NOTI_MAILBOX_RENAME_FAIL = 40011,
+
+ NOTI_CERTIFICATE_ADD = 50000,
+ NOTI_CERTIFICATE_DELETE = 50001,
+ NOTI_CERTIFICATE_UPDATE = 50002,
+ /* To be added more */
+} email_noti_on_storage_event;
+
+typedef enum
+{
+ NOTI_SEND_START = 1002,
+ NOTI_SEND_FINISH = 1004,
+ NOTI_SEND_FAIL = 1005,
+ NOTI_SEND_CANCEL = 1003,
+
+ NOTI_DOWNLOAD_START = 2000,
+ NOTI_DOWNLOAD_FINISH,
+ NOTI_DOWNLOAD_FAIL,
+ NOTI_DOWNLOAD_CANCEL = 2004,
+ NOTI_DOWNLOAD_NEW_MAIL = 2003,
+
+ NOTI_DOWNLOAD_BODY_START = 3000,
+ NOTI_DOWNLOAD_BODY_FINISH = 3002,
+ NOTI_DOWNLOAD_BODY_FAIL = 3004,
+ NOTI_DOWNLOAD_BODY_CANCEL = 3003,
+ NOTI_DOWNLOAD_MULTIPART_BODY = 3001,
+
+ NOTI_DOWNLOAD_ATTACH_START = 4000,
+ NOTI_DOWNLOAD_ATTACH_FINISH,
+ NOTI_DOWNLOAD_ATTACH_FAIL,
+ NOTI_DOWNLOAD_ATTACH_CANCEL,
+
+ NOTI_MAIL_DELETE_ON_SERVER_FAIL = 5000,
+ NOTI_MAIL_MOVE_ON_SERVER_FAIL,
+
+ NOTI_SEARCH_ON_SERVER_START = 6000,
+ NOTI_SEARCH_ON_SERVER_FINISH = 6001,
+ NOTI_SEARCH_ON_SERVER_FAIL = 6002,
+ NOTI_SEARCH_ON_SERVER_CANCEL = 6003,
+
+ NOTI_VALIDATE_ACCOUNT_FINISH = 7000,
+ NOTI_VALIDATE_ACCOUNT_FAIL,
+ NOTI_VALIDATE_ACCOUNT_CANCEL,
+
+ NOTI_VALIDATE_AND_CREATE_ACCOUNT_FINISH = 8000,
+ NOTI_VALIDATE_AND_CREATE_ACCOUNT_FAIL,
+ NOTI_VALIDATE_AND_CREATE_ACCOUNT_CANCEL,
+
+ NOTI_VALIDATE_AND_UPDATE_ACCOUNT_FINISH = 9000,
+ NOTI_VALIDATE_AND_UPDATE_ACCOUNT_FAIL,
+ NOTI_VALIDATE_AND_UPDATE_ACCOUNT_CANCEL,
+
+ NOTI_VALIDATE_CERTIFICATE_FINISH = 10000,
+ NOTI_VALIDATE_CERTIFICATE_FAIL = 10001,
+ NOTI_VALIDATE_CERTIFICATE_CANCEL = 10002,
+
+ NOTI_RESOLVE_RECIPIENT_START = 11000,
+ NOTI_RESOLVE_RECIPIENT_FINISH,
+ NOTI_RESOLVE_RECIPIENT_FAIL,
+ NOTI_RESOLVE_RECIPIENT_CANCEL,
+
+ NOTI_RENAME_MAILBOX_START = 12000,
+ NOTI_RENAME_MAILBOX_FINISH,
+ NOTI_RENAME_MAILBOX_FAIL,
+ NOTI_RENAME_MAILBOX_CANCEL,
+
+ NOTI_ADD_MAILBOX_START = 12100,
+ NOTI_ADD_MAILBOX_FINISH,
+ NOTI_ADD_MAILBOX_FAIL,
+ NOTI_ADD_MAILBOX_CANCEL,
+
+ NOTI_DELETE_MAILBOX_START = 12200,
+ NOTI_DELETE_MAILBOX_FINISH,
+ NOTI_DELETE_MAILBOX_FAIL,
+ NOTI_DELETE_MAILBOX_CANCEL,
+
+ /* To be added more */
+} email_noti_on_network_event;
+
+typedef enum
+{
+ RESPONSE_SUCCEEDED = 0,
+ RESPONSE_FAILED = 1,
+ RESPONSE_CANCELED = 2
+ /* To be added more */
+} email_response_to_request;
+
+/**
+ * This enumeration specifies the mail type of account.
+ */
+typedef enum
+{
+ EMAIL_BIND_TYPE_DISABLE = 0, /**< Specifies the bind type for Disabled account.*/
+ EMAIL_BIND_TYPE_EM_CORE = 1, /**< Specifies the bind type for Callia.*/
+} email_account_bind_t DEPRECATED;
+
+/**
+ * This enumeration specifies the server type of account.
+ */
+typedef enum
+{
+ EMAIL_SERVER_TYPE_POP3 = 1, /**< Specifies the POP3 Server.*/
+ EMAIL_SERVER_TYPE_IMAP4, /**< Specifies the IMAP4 Server.*/
+ EMAIL_SERVER_TYPE_SMTP, /**< Specifies the SMTP Server.*/
+ EMAIL_SERVER_TYPE_NONE, /**< Specifies the Local.*/
+ EMAIL_SERVER_TYPE_ACTIVE_SYNC, /** < Specifies the Active Sync. */
+} email_account_server_t;
+
+/**
+ * This enumeration specifies the mode of retrieval.
+ */
+typedef enum
+{
+ EMAIL_IMAP4_RETRIEVAL_MODE_NEW = 0, /**< Specifies the retrieval mode for new email.*/
+ EMAIL_IMAP4_RETRIEVAL_MODE_ALL, /**< Specifies the retrieval mode for all email.*/
+} email_imap4_retrieval_mode_t;
+
+/**
+ * This enumeration specifies the filtering type.
+ */
+typedef enum
+{
+ EMAIL_FILTER_FROM = 1, /**< Specifies the filtering of sender.*/
+ EMAIL_FILTER_SUBJECT, /**< Specifies the filtering of email subject.*/
+ EMAIL_FILTER_BODY, /** < Specifies the filterinf of email body.*/
+} email_rule_type_t;
+
+
+/**
+ * This enumeration specifies the rules for filtering type.
+ */
+typedef enum
+{
+ RULE_TYPE_INCLUDES = 1, /**< Specifies the filtering rule for includes.*/
+ RULE_TYPE_EXACTLY, /**< Specifies the filtering rule for Exactly same as.*/
+} email_filtering_type_t;
+
+
+/**
+ * This enumeration specifies the action for filtering type.
+ */
+typedef enum
+{
+ EMAIL_FILTER_MOVE = 1, /**< Specifies the move of email.*/
+ EMAIL_FILTER_BLOCK = 2, /**< Specifies the block of email.*/
+ EMAIL_FILTER_DELETE = 3, /**< Specifies delete email.*/
+} email_rule_action_t;
+
+/**
+ * This enumeration specifies the email status.
+ */
+typedef enum
+{
+ EMAIL_MAIL_STATUS_NONE = 0, /**< The Mail is in No Operation state */
+ EMAIL_MAIL_STATUS_RECEIVED, /**< The mail is a received mail.*/
+ EMAIL_MAIL_STATUS_SENT, /**< The mail is a sent mail.*/
+ EMAIL_MAIL_STATUS_SAVED, /**< The mail is a saved mail.*/
+ EMAIL_MAIL_STATUS_SAVED_OFFLINE, /**< The mail is a saved mail in offline-mode.*/
+ EMAIL_MAIL_STATUS_SENDING, /**< The mail is being sent.*/
+ EMAIL_MAIL_STATUS_SEND_FAILURE, /**< The mail is a mail to been failed to send.*/
+ EMAIL_MAIL_STATUS_SEND_CANCELED, /**< The mail is a cancelled mail.*/
+ EMAIL_MAIL_STATUS_SEND_WAIT, /**< The mail is a mail to be send .*/
+} email_mail_status_t;
+
+/**
+ * This enumeration specifies the email priority.
+ */
+typedef enum
+{
+ EMAIL_MAIL_PRIORITY_HIGH = 1, /**< The priority is high.*/
+ EMAIL_MAIL_PRIORITY_NORMAL = 3, /**< The priority is normal.*/
+ EMAIL_MAIL_PRIORITY_LOW = 5, /**< The priority is low.*/
+} email_mail_priority_t;
+
+/**
+ * This enumeration specifies the email status.
+ */
+typedef enum
+{
+ EMAIL_MAIL_REPORT_NONE = 0, /**< The mail isn't report mail.*/
+ EMAIL_MAIL_REPORT_DSN, /**< The mail is a delivery-status report mail.*/
+ EMAIL_MAIL_REPORT_MDN, /**< The mail is a read-status report mail.*/
+ EMAIL_MAIL_REPORT_REQUEST, /**< The mail require a read-status report mail.*/
+} email_mail_report_t;
+
+/**
+ * This enumeration specifies the DRM type
+ */
+typedef enum
+{
+ EMAIL_ATTACHMENT_DRM_NONE = 0, /**< The mail isn't DRM file.*/
+ EMAIL_ATTACHMENT_DRM_OBJECT, /**< The mail is a DRM object.*/
+ EMAIL_ATTACHMENT_DRM_RIGHTS, /**< The mail is a DRM rights as xml format.*/
+ EMAIL_ATTACHMENT_DRM_DCF, /**< The mail is a DRM dcf.*/
+} email_attachment_drm_t;
+
+/**
+ * This enumeration specifies the meeting request type
+ */
+typedef enum
+{
+ EMAIL_MAIL_TYPE_NORMAL = 0, /**< NOT a meeting request mail. A Normal mail */
+ EMAIL_MAIL_TYPE_MEETING_REQUEST = 1, /**< a meeting request mail from a serve */
+ EMAIL_MAIL_TYPE_MEETING_RESPONSE = 2, /**< a response mail about meeting reques */
+ EMAIL_MAIL_TYPE_MEETING_ORIGINATINGREQUEST = 3 /**< a originating mail about meeting reques */
+} email_mail_type_t;
+
+/**
+ * This enumeration specifies the meeting response type
+ */
+typedef enum
+{
+ EMAIL_MEETING_RESPONSE_NONE = 0, /**< NOT response */
+ EMAIL_MEETING_RESPONSE_ACCEPT = 1, /**< The response is acceptance */
+ EMAIL_MEETING_RESPONSE_TENTATIVE = 2, /**< The response is tentative */
+ EMAIL_MEETING_RESPONSE_DECLINE = 3, /**< The response is decline */
+ EMAIL_MEETING_RESPONSE_REQUEST = 4, /**< The response is request */
+ EMAIL_MEETING_RESPONSE_CANCEL = 5, /**< The response is cancelation */
+} email_meeting_response_t;
+
+typedef enum
+{
+ EMAIL_ACTION_SEND_MAIL = 0,
+ EMAIL_ACTION_SYNC_HEADER = 1,
+ EMAIL_ACTION_DOWNLOAD_BODY = 2,
+ EMAIL_ACTION_DOWNLOAD_ATTACHMENT = 3,
+ EMAIL_ACTION_DELETE_MAIL = 4,
+ EMAIL_ACTION_SEARCH_MAIL = 5,
+ EMAIL_ACTION_SAVE_MAIL = 6,
+ EMAIL_ACTION_SYNC_MAIL_FLAG_TO_SERVER = 7,
+ EMAIL_ACTION_SYNC_FLAGS_FIELD_TO_SERVER = 8,
+ EMAIL_ACTION_MOVE_MAIL = 9,
+ EMAIL_ACTION_CREATE_MAILBOX = 10,
+ EMAIL_ACTION_DELETE_MAILBOX = 11,
+ EMAIL_ACTION_SYNC_HEADER_OMA = 12,
+ EMAIL_ACTION_VALIDATE_ACCOUNT = 13,
+ EMAIL_ACTION_VALIDATE_AND_CREATE_ACCOUNT = 14,
+ EMAIL_ACTION_VALIDATE_AND_UPDATE_ACCOUNT = 15,
+ EMAIL_ACTION_UPDATE_MAIL = 30,
+ EMAIL_ACTION_SET_MAIL_SLOT_SIZE = 31,
+ EMAIL_ACTION_EXPUNGE_MAILS_DELETED_FLAGGED = 32,
+ EMAIL_ACTION_SEARCH_ON_SERVER = 33,
+ EMAIL_ACTION_MOVE_MAILBOX = 34,
+ EMAIL_ACTION_NUM,
+} email_action_t;
+
+/**
+ * This enumeration specifies the status of getting envelope list.
+ */
+typedef enum
+{
+ EMAIL_LIST_NONE = 0,
+ EMAIL_LIST_WAITING,
+ EMAIL_LIST_PREPARE, /**< Specifies the preparation.*/
+ EMAIL_LIST_CONNECTION_START, /**< Specifies the connection start.*/
+ EMAIL_LIST_CONNECTION_SUCCEED, /**< Specifies the success of connection.*/
+ EMAIL_LIST_CONNECTION_FINISH, /**< Specifies the connection finish.*/
+ EMAIL_LIST_CONNECTION_FAIL, /**< Specifies the connection failure.*/
+ EMAIL_LIST_START, /**< Specifies the getting start.*/
+ EMAIL_LIST_PROGRESS, /**< Specifies the status of getting.*/
+ EMAIL_LIST_FINISH, /**< Specifies the getting complete.*/
+ EMAIL_LIST_FAIL, /**< Specifies the download failure.*/
+} email_envelope_list_status_t;
+
+/**
+ * This enumeration specifies the downloaded status of email.
+ */
+typedef enum
+{
+ EMAIL_DOWNLOAD_NONE = 0,
+ EMAIL_DOWNLOAD_WAITING,
+ EMAIL_DOWNLOAD_PREPARE, /**< Specifies the preparation.*/
+ EMAIL_DOWNLOAD_CONNECTION_START, /**< Specifies the connection start.*/
+ EMAIL_DOWNLOAD_CONNECTION_SUCCEED, /**< Specifies the success of connection.*/
+ EMAIL_DOWNLOAD_CONNECTION_FINISH, /**< Specifies the connection finish.*/
+ EMAIL_DOWNLOAD_CONNECTION_FAIL, /**< Specifies the connection failure.*/
+ EMAIL_DOWNLOAD_START, /**< Specifies the download start.*/
+ EMAIL_DOWNLOAD_PROGRESS, /**< Specifies the status of download.*/
+ EMAIL_DOWNLOAD_FINISH, /**< Specifies the download complete.*/
+ EMAIL_DOWNLOAD_FAIL, /**< Specifies the download failure.*/
+} email_download_status_t;
+
+/**
+ * This enumeration specifies the status of sending email.
+ */
+typedef enum
+{
+ EMAIL_SEND_NONE = 0,
+ EMAIL_SEND_WAITING,
+ EMAIL_SEND_PREPARE, /**< Specifies the preparation.*/
+ EMAIL_SEND_CONNECTION_START, /**< Specifies the connection start.*/
+ EMAIL_SEND_CONNECTION_SUCCEED, /**< Specifies the success of connection.*/
+ EMAIL_SEND_CONNECTION_FINISH, /**< Specifies the connection finish.*/
+ EMAIL_SEND_CONNECTION_FAIL, /**< Specifies the connection failure.*/
+ EMAIL_SEND_START, /**< Specifies the sending start.*/
+ EMAIL_SEND_PROGRESS, /**< Specifies the status of sending.*/
+ EMAIL_SEND_FINISH, /**< Specifies the sending complete.*/
+ EMAIL_SEND_FAIL, /**< Specifies the sending failure.*/
+ EMAIL_SAVE_WAITING, /**< Specfies the Waiting of Sync */
+} email_send_status_t;
+
+typedef enum
+{
+ EMAIL_SYNC_NONE = 0,
+ EMAIL_SYNC_WAITING,
+ EMAIL_SYNC_PREPARE,
+ EMAIL_SYNC_CONNECTION_START,
+ EMAIL_SYNC_CONNECTION_SUCCEED,
+ EMAIL_SYNC_CONNECTION_FINISH,
+ EMAIL_SYNC_CONNECTION_FAIL,
+ EMAIL_SYNC_START,
+ EMAIL_SYNC_PROGRESS,
+ EMAIL_SYNC_FINISH,
+ EMAIL_SYNC_FAIL,
+} email_sync_status_t;
+
+/**
+* This enumeration specifies the deleting status of email.
+*/
+typedef enum
+{
+ EMAIL_DELETE_NONE = 0,
+ EMAIL_DELETE_WAITING,
+ EMAIL_DELETE_PREPARE, /**< Specifies the preparation.*/
+ EMAIL_DELETE_CONNECTION_START, /**< Specifies the connection start.*/
+ EMAIL_DELETE_CONNECTION_SUCCEED, /**< Specifies the success of connection.*/
+ EMAIL_DELETE_CONNECTION_FINISH, /**< Specifies the connection finish.*/
+ EMAIL_DELETE_CONNECTION_FAIL, /**< Specifies the connection failure.*/
+ EMAIL_DELETE_START, /**< Specifies the deletion start.*/
+ EMAIL_DELETE_PROGRESS, /**< Specifies the status of deleting.*/
+ EMAIL_DELETE_SERVER_PROGRESS, /**< Specifies the status of server deleting.*/
+ EMAIL_DELETE_LOCAL_PROGRESS, /**< Specifies the status of local deleting.*/
+ EMAIL_DELETE_FINISH, /**< Specifies the deletion complete.*/
+ EMAIL_DELETE_FAIL, /**< Specifies the deletion failure.*/
+} email_delete_status_t;
+
+/**
+* This enumeration specifies the status of validating account
+*/
+typedef enum
+{
+ EMAIL_VALIDATE_ACCOUNT_NONE = 0,
+ EMAIL_VALIDATE_ACCOUNT_WAITING,
+ EMAIL_VALIDATE_ACCOUNT_PREPARE, /**< Specifies the preparation.*/
+ EMAIL_VALIDATE_ACCOUNT_CONNECTION_START, /**< Specifies the connection start.*/
+ EMAIL_VALIDATE_ACCOUNT_CONNECTION_SUCCEED, /**< Specifies the success of connection.*/
+ EMAIL_VALIDATE_ACCOUNT_CONNECTION_FINISH, /**< Specifies the connection finish.*/
+ EMAIL_VALIDATE_ACCOUNT_CONNECTION_FAIL, /**< Specifies the connection failure.*/
+ EMAIL_VALIDATE_ACCOUNT_START, /**< Specifies the getting start.*/
+ EMAIL_VALIDATE_ACCOUNT_PROGRESS, /**< Specifies the status of getting.*/
+ EMAIL_VALIDATE_ACCOUNT_FINISH, /**< Specifies the getting complete.*/
+ EMAIL_VALIDATE_ACCOUNT_FAIL, /**< Specifies the validation failure.*/
+} email_validate_account_status_t;
+
+typedef enum
+{
+ EMAIL_SET_SLOT_SIZE_NONE = 0,
+ EMAIL_SET_SLOT_SIZE_WAITING,
+ EMAIL_SET_SLOT_SIZE_START,
+ EMAIL_SET_SLOT_SIZE_FINISH,
+ EMAIL_SET_SLOT_SIZE_FAIL,
+}email_set_slot_size_status_e;
+
+typedef enum
+{
+ EMAIL_EXPUNGE_MAILS_DELETED_FLAGGED_NONE = 0,
+ EMAIL_EXPUNGE_MAILS_DELETED_FLAGGED_WAITING,
+ EMAIL_EXPUNGE_MAILS_DELETED_FLAGGED_START,
+ EMAIL_EXPUNGE_MAILS_DELETED_FLAGGED_FINISH,
+ EMAIL_EXPUNGE_MAILS_DELETED_FLAGGED_FAIL,
+}email_expunge_mails_deleted_flagged_status_e;
+
+typedef enum
+{
+ EMAIL_SEARCH_ON_SERVER_NONE = 0,
+ EMAIL_SEARCH_ON_SERVER_WAITING,
+ EMAIL_SEARCH_ON_SERVER_START,
+ EMAIL_SEARCH_ON_SERVER_FINISH,
+ EMAIL_SEARCH_ON_SERVER_FAIL,
+}email_search_on_server_status_e;
+
+typedef enum
+{
+ EMAIL_MOVE_MAILBOX_ON_IMAP_SERVER_NONE = 0,
+ EMAIL_MOVE_MAILBOX_ON_IMAP_SERVER_WAITING,
+ EMAIL_MOVE_MAILBOX_ON_IMAP_SERVER_START,
+ EMAIL_MOVE_MAILBOX_ON_IMAP_SERVER_FINISH,
+ EMAIL_MOVE_MAILBOX_ON_IMAP_SERVER_FAIL,
+}email_move_mailbox_status_e;
+
+typedef enum
+{
+ EMAIL_UPDATE_MAIL_NONE = 0,
+ EMAIL_UPDATE_MAIL_WAITING,
+ EMAIL_UPDATE_MAIL_START,
+ EMAIL_UPDATE_MAIL_FINISH,
+ EMAIL_UPDATE_MAIL_FAIL,
+}email_update_mail_status_e;
+
+/**
+* This enumeration specifies the type of mailbox
+*/
+typedef enum
+{
+ EMAIL_MAILBOX_TYPE_NONE = 0, /**< Unspecified mailbox type*/
+ EMAIL_MAILBOX_TYPE_INBOX = 1, /**< Specified inbox type*/
+ EMAIL_MAILBOX_TYPE_SENTBOX = 2, /**< Specified sent box type*/
+ EMAIL_MAILBOX_TYPE_TRASH = 3, /**< Specified trash type*/
+ EMAIL_MAILBOX_TYPE_DRAFT = 4, /**< Specified draft box type*/
+ EMAIL_MAILBOX_TYPE_SPAMBOX = 5, /**< Specified spam box type*/
+ EMAIL_MAILBOX_TYPE_OUTBOX = 6, /**< Specified outbox type*/
+ EMAIL_MAILBOX_TYPE_ALL_EMAILS = 7, /**< Specified all emails type of gmail*/
+ EMAIL_MAILBOX_TYPE_SEARCH_RESULT = 8, /**< Specified mailbox type for result of search on server */
+ EMAIL_MAILBOX_TYPE_FLAGGED = 9, /**< Specified flagged mailbox type on gmail */
+ EMAIL_MAILBOX_TYPE_USER_DEFINED = 0xFF, /**< Specified mailbox type for all other mailboxes */
+}email_mailbox_type_e;
+
+typedef enum
+{
+ EMAIL_SYNC_LATEST_MAILS_FIRST = 0,
+ EMAIL_SYNC_OLDEST_MAILS_FIRST,
+ EMAIL_SYNC_ALL_MAILBOX_50_MAILS,
+} EMAIL_RETRIEVE_MODE;
+
+/* event type */
+typedef enum
+{
+ EMAIL_EVENT_NONE = 0,
+ EMAIL_EVENT_SYNC_HEADER = 1, /* synchronize mail headers with server (network used) */
+ EMAIL_EVENT_DOWNLOAD_BODY = 2, /* download mail body from server (network used)*/
+ EMAIL_EVENT_DOWNLOAD_ATTACHMENT = 3, /* download mail attachment from server (network used) */
+ EMAIL_EVENT_SEND_MAIL = 4, /* send a mail (network used) */
+ EMAIL_EVENT_SEND_MAIL_SAVED = 5, /* send all mails in 'outbox' box (network used) */
+ EMAIL_EVENT_SYNC_IMAP_MAILBOX = 6, /* download imap mailboxes from server (network used) */
+ EMAIL_EVENT_DELETE_MAIL = 7, /* delete mails (network unused) */
+ EMAIL_EVENT_DELETE_MAIL_ALL = 8, /* delete all mails (network unused) */
+ EMAIL_EVENT_SYNC_MAIL_FLAG_TO_SERVER = 9, /* sync mail flag to server */
+ EMAIL_EVENT_SYNC_FLAGS_FIELD_TO_SERVER = 10, /* sync a field of flags to server */
+ EMAIL_EVENT_SAVE_MAIL = 11, /* Deprecated */
+ EMAIL_EVENT_MOVE_MAIL = 12, /* move mails to specific mailbox on server */
+ EMAIL_EVENT_CREATE_MAILBOX = 13,
+ EMAIL_EVENT_UPDATE_MAILBOX = 14,
+ EMAIL_EVENT_DELETE_MAILBOX = 15,
+ EMAIL_EVENT_ISSUE_IDLE = 16,
+ EMAIL_EVENT_SYNC_HEADER_OMA = 17,
+ EMAIL_EVENT_VALIDATE_ACCOUNT = 18,
+ EMAIL_EVENT_VALIDATE_AND_CREATE_ACCOUNT = 19,
+ EMAIL_EVENT_VALIDATE_AND_UPDATE_ACCOUNT = 20,
+ EMAIL_EVENT_SEARCH_ON_SERVER = 21,
+ EMAIL_EVENT_RENAME_MAILBOX_ON_IMAP_SERVER = 22,
+
+ EMAIL_EVENT_ADD_MAIL = 10001, /* Deprecated */
+ EMAIL_EVENT_UPDATE_MAIL_OLD = 10002, /* Deprecated */
+ EMAIL_EVENT_UPDATE_MAIL = 10003,
+ EMAIL_EVENT_SET_MAIL_SLOT_SIZE = 20000,
+ EMAIL_EVENT_EXPUNGE_MAILS_DELETED_FLAGGED = 20001,
+
+/* EMAIL_EVENT_LOCAL_ACTIVITY, __LOCAL_ACTIVITY_ */
+
+ EMAIL_EVENT_BULK_PARTIAL_BODY_DOWNLOAD = 20002, /* __FEATURE_PARTIAL_BODY_DOWNLOAD__ supported */
+ EMAIL_EVENT_LOCAL_ACTIVITY_SYNC_BULK_PBD = 20003, /* __FEATURE_PARTIAL_BODY_DOWNLOAD__ supported */
+ EMAIL_EVENT_GET_PASSWORD_LENGTH = 20004, /* get password length of an account */
+} email_event_type_t;
+
+/* event statu */
+typedef enum
+{
+ EMAIL_EVENT_STATUS_UNUSED = 0,
+ EMAIL_EVENT_STATUS_WAIT,
+ EMAIL_EVENT_STATUS_STARTED,
+ EMAIL_EVENT_STATUS_CANCELED,
+} email_event_status_type_t;
+
+
+/* sorting_orde */
+typedef enum
+{
+ EMAIL_SORT_DATETIME_HIGH = 0,
+ EMAIL_SORT_DATETIME_LOW,
+ EMAIL_SORT_SENDER_HIGH,
+ EMAIL_SORT_SENDER_LOW,
+ EMAIL_SORT_RCPT_HIGH,
+ EMAIL_SORT_RCPT_LOW,
+ EMAIL_SORT_SUBJECT_HIGH,
+ EMAIL_SORT_SUBJECT_LOW,
+ EMAIL_SORT_PRIORITY_HIGH,
+ EMAIL_SORT_PRIORITY_LOW,
+ EMAIL_SORT_ATTACHMENT_HIGH,
+ EMAIL_SORT_ATTACHMENT_LOW,
+ EMAIL_SORT_FAVORITE_HIGH,
+ EMAIL_SORT_FAVORITE_LOW,
+ EMAIL_SORT_MAILBOX_NAME_HIGH,
+ EMAIL_SORT_MAILBOX_NAME_LOW,
+ EMAIL_SORT_FLAGGED_FLAG_HIGH,
+ EMAIL_SORT_FLAGGED_FLAG_LOW,
+ EMAIL_SORT_SEEN_FLAG_HIGH,
+ EMAIL_SORT_SEEN_FLAG_LOW,
+ EMAIL_SORT_END,
+}email_sort_type_t;
+
+typedef enum
+{
+ EMAIL_MAILBOX_SORT_BY_NAME_ASC = 0,
+ EMAIL_MAILBOX_SORT_BY_NAME_DSC,
+ EMAIL_MAILBOX_SORT_BY_TYPE_ASC,
+ EMAIL_MAILBOX_SORT_BY_TYPE_DSC,
+} email_mailbox_sort_type_t;
+
+
+/**
+* This enumeration specifies the priority.
+*/
+enum
+{
+ EMAIL_OPTION_PRIORITY_HIGH = 1, /**< Specifies the high priority.*/
+ EMAIL_OPTION_PRIORITY_NORMAL = 3, /**< Specifies the normal priority*/
+ EMAIL_OPTION_PRIORITY_LOW = 5, /**< Specifies the low priority.*/
+};
+
+/**
+* This enumeration specifies the saving save a copy after sending.
+*/
+enum
+{
+ EMAIL_OPTION_KEEP_LOCAL_COPY_OFF = 0, /**< Specifies off the keeping local copy.*/
+ EMAIL_OPTION_KEEP_LOCAL_COPY_ON = 1, /**< Specifies on the keeping local copy.*/
+};
+
+/**
+* This enumeration specifies the request of delivery report.
+*/
+enum
+{
+ EMAIL_OPTION_REQ_DELIVERY_RECEIPT_OFF = 0, /**< Specifies off the requesting delivery receipt.*/
+ EMAIL_OPTION_REQ_DELIVERY_RECEIPT_ON = 1, /**< Specifies on the requesting delivery receipt.*/
+};
+
+/**
+* This enumeration specifies the request of read receipt.
+*/
+enum
+{
+ EMAIL_OPTION_REQ_READ_RECEIPT_OFF = 0, /**< Specifies off the requesting read receipt.*/
+ EMAIL_OPTION_REQ_READ_RECEIPT_ON = 1, /**< Specifies on the requesting read receipt.*/
+};
+
+/**
+* This enumeration specifies the blocking of address.
+*/
+enum
+{
+ EMAIL_OPTION_BLOCK_ADDRESS_OFF = 0, /**< Specifies off the blocking by address.*/
+ EMAIL_OPTION_BLOCK_ADDRESS_ON = 1, /**< Specifies on the blocking by address.*/
+};
+
+/**
+* This enumeration specifies the blocking of subject.
+*/
+enum
+{
+ EMAIL_OPTION_BLOCK_SUBJECT_OFF = 0, /**< Specifies off the blocking by subject.*/
+ EMAIL_OPTION_BLOCK_SUBJECT_ON = 1, /**< Specifies on the blocking by subject.*/
+};
+
+enum
+{
+ EMAIL_LIST_TYPE_UNREAD = -3,
+ EMAIL_LIST_TYPE_LOCAL = -2,
+ EMAIL_LIST_TYPE_THREAD = -1,
+ EMAIL_LIST_TYPE_NORMAL = 0
+};
+
+/**
+* This enumeration specifies the mailbox sync type.
+*/
+enum
+{
+ EMAIL_MAILBOX_ALL = -1, /**< All mailboxes.*/
+ EMAIL_MAILBOX_FROM_SERVER = 0, /**< Mailboxes from server. */
+ EMAIL_MAILBOX_FROM_LOCAL = 1, /**< Mailboxes from local. */
+};
+
+typedef enum
+{
+ APPEND_BODY = 1,
+ UPDATE_MAILBOX,
+ UPDATE_ATTACHMENT_INFO,
+ UPDATE_FLAG,
+ UPDATE_SAVENAME,
+ UPDATE_EXTRA_FLAG,
+ UPDATE_MAIL,
+ UPDATE_DATETIME,
+ UPDATE_FROM_CONTACT_INFO,
+ UPDATE_TO_CONTACT_INFO,
+ UPDATE_ALL_CONTACT_NAME,
+ UPDATE_ALL_CONTACT_INFO,
+ UPDATE_STICKY_EXTRA_FLAG,
+ UPDATE_PARTIAL_BODY_DOWNLOAD,
+ UPDATE_MEETING,
+ UPDATE_SEEN_FLAG_OF_THREAD,
+} email_mail_change_type_t;
+
+
+/**
+* This enumeration specifies the address type.
+*/
+typedef enum
+{
+ EMAIL_ADDRESS_TYPE_FROM = 1, /**< Specifies the from address.*/
+ EMAIL_ADDRESS_TYPE_TO, /**< Specifies the to receipient address.*/
+ EMAIL_ADDRESS_TYPE_CC, /**< Specifies the cc receipient address.*/
+ EMAIL_ADDRESS_TYPE_BCC, /**< Specifies the bcc receipient address.*/
+ EMAIL_ADDRESS_TYPE_REPLY, /**< Specifies the reply receipient address.*/
+ EMAIL_ADDRESS_TYPE_RETURN, /**< Specifies the return receipient address.*/
+} email_address_type_t;
+
+/**
+ * This enumeration specifies the search type for searching mailbox.
+ */
+typedef enum
+{
+ EMAIL_MAILBOX_SEARCH_KEY_TYPE_SUBJECT, /**< The search key is for searching subject.*/
+ EMAIL_MAILBOX_SEARCH_KEY_TYPE_FROM, /**< The search key is for searching sender address.*/
+ EMAIL_MAILBOX_SEARCH_KEY_TYPE_BODY, /**< The search key is for searching body.*/
+ EMAIL_MAILBOX_SEARCH_KEY_TYPE_TO, /**< The search key is for searching recipient address.*/
+} email_mailbox_search_key_t;
+
+/**
+ * This enumeration specifies the download status of mail body.
+ */
+
+typedef enum
+{
+ EMAIL_BODY_DOWNLOAD_STATUS_NONE = 0,
+ EMAIL_BODY_DOWNLOAD_STATUS_FULLY_DOWNLOADED = 1,
+ EMAIL_BODY_DOWNLOAD_STATUS_PARTIALLY_DOWNLOADED = 2,
+} email_body_download_status_t;
+
+/**
+ * This enumeration specifies the moving type.
+ */
+typedef enum
+{
+ EMAIL_MOVED_BY_COMMAND = 0,
+ EMAIL_MOVED_BY_MOVING_THREAD,
+ EMAIL_MOVED_AFTER_SENDING,
+ EMAIL_MOVED_CANCELATION_MAIL
+} email_move_type;
+
+/**
+ * This enumeration specifies the deletion type.
+ */
+typedef enum
+{
+ EMAIL_DELETED_BY_COMMAND = 0,
+ EMAIL_DELETED_BY_OVERFLOW,
+ EMAIL_DELETED_BY_DELETING_THREAD,
+ EMAIL_DELETED_BY_MOVING_TO_OTHER_ACCOUNT,
+ EMAIL_DELETED_AFTER_SENDING,
+ EMAIL_DELETED_FROM_SERVER,
+} email_delete_type;
+
+/**
+ * This enumeration specifies the status field type.
+ */
+typedef enum
+{
+ EMAIL_FLAGS_SEEN_FIELD = 0,
+ EMAIL_FLAGS_DELETED_FIELD,
+ EMAIL_FLAGS_FLAGGED_FIELD,
+ EMAIL_FLAGS_ANSWERED_FIELD,
+ EMAIL_FLAGS_RECENT_FIELD,
+ EMAIL_FLAGS_DRAFT_FIELD,
+ EMAIL_FLAGS_FORWARDED_FIELD,
+ EMAIL_FLAGS_FIELD_COUNT,
+} email_flags_field_type;
+
+typedef enum {
+ EMAIL_FLAG_NONE = 0,
+ EMAIL_FLAG_FLAGED = 1,
+ EMAIL_FLAG_TASK_STATUS_CLEAR = 2,
+ EMAIL_FLAG_TASK_STATUS_ACTIVE = 3,
+ EMAIL_FLAG_TASK_STATUS_COMPLETE = 4,
+} email_flagged_type;
+
+typedef enum {
+ EMAIL_SEARCH_FILTER_TYPE_MESSAGE_NO = 1, /* integer type */
+ EMAIL_SEARCH_FILTER_TYPE_UID = 2, /* integer type */
+ EMAIL_SEARCH_FILTER_TYPE_BCC = 7, /* string type */
+ EMAIL_SEARCH_FILTER_TYPE_CC = 9, /* string type */
+ EMAIL_SEARCH_FILTER_TYPE_FROM = 10, /* string type */
+ EMAIL_SEARCH_FILTER_TYPE_KEYWORD = 11, /* string type */
+ EMAIL_SEARCH_FILTER_TYPE_SUBJECT = 13, /* string type */
+ EMAIL_SEARCH_FILTER_TYPE_TO = 15, /* string type */
+ EMAIL_SEARCH_FILTER_TYPE_SIZE_LARSER = 16, /* integer type */
+ EMAIL_SEARCH_FILTER_TYPE_SIZE_SMALLER = 17, /* integer type */
+ EMAIL_SEARCH_FILTER_TYPE_SENT_DATE_BEFORE = 20, /* time type */
+ EMAIL_SEARCH_FILTER_TYPE_SENT_DATE_ON = 21, /* time type */
+ EMAIL_SEARCH_FILTER_TYPE_SENT_DATE_SINCE = 22, /* time type */
+ EMAIL_SEARCH_FILTER_TYPE_FLAGS_ANSWERED = 26, /* integer type */
+ EMAIL_SEARCH_FILTER_TYPE_FLAGS_DELETED = 28, /* integer type */
+ EMAIL_SEARCH_FILTER_TYPE_FLAGS_DRAFT = 30, /* integer type */
+ EMAIL_SEARCH_FILTER_TYPE_FLAGS_FLAGED = 32, /* integer type */
+ EMAIL_SEARCH_FILTER_TYPE_FLAGS_RECENT = 34, /* integer type */
+ EMAIL_SEARCH_FILTER_TYPE_FLAGS_SEEN = 36, /* integer type */
+ EMAIL_SEARCH_FILTER_TYPE_MESSAGE_ID = 43, /* string type */
+} email_search_filter_type;
+
+typedef enum {
+ EMAIL_DRM_TYPE_NONE = 0,
+ EMAIL_DRM_TYPE_OBJECT = 1,
+ EMAIL_DRM_TYPE_RIGHT = 2,
+ EMAIL_DRM_TYPE_DCF = 3
+} email_drm_type;
+
+typedef enum {
+ EMAIL_DRM_METHOD_NONE = 0,
+ EMAIL_DRM_METHOD_FL = 1,
+ EMAIL_DRM_METHOD_CD = 2,
+ EMAIL_DRM_METHOD_SSD = 3,
+ EMAIL_DRM_METHOD_SD = 4
+} email_drm_method;
+
+typedef enum {
+ EMAIL_CANCELED_BY_USER = 0,
+ EMAIL_CANCELED_BY_MDM = 1,
+} email_cancelation_type;
+
+typedef enum {
+ EMAIL_MAIL_ATTRIBUTE_MAIL_ID = 0, /* integer type */
+ EMAIL_MAIL_ATTRIBUTE_ACCOUNT_ID = 1, /* integer type */
+ EMAIL_MAIL_ATTRIBUTE_MAILBOX_ID = 2, /* integer type */
+ EMAIL_MAIL_ATTRIBUTE_MAILBOX_NAME = 3, /* string type */
+ EMAIL_MAIL_ATTRIBUTE_MAILBOX_TYPE = 4, /* integer type */
+ EMAIL_MAIL_ATTRIBUTE_SUBJECT = 5, /* string type */
+ EMAIL_MAIL_ATTRIBUTE_DATE_TIME = 6, /* datetime type */
+ EMAIL_MAIL_ATTRIBUTE_SERVER_MAIL_STATUS = 7, /* integer type */
+ EMAIL_MAIL_ATTRIBUTE_SERVER_MAILBOX_NAME = 8, /* string type */
+ EMAIL_MAIL_ATTRIBUTE_SERVER_MAIL_ID = 9, /* string type */
+ EMAIL_MAIL_ATTRIBUTE_MESSAGE_ID = 10, /* string type */
+ EMAIL_MAIL_ATTRIBUTE_FROM = 11, /* string type */
+ EMAIL_MAIL_ATTRIBUTE_TO = 12, /* string type */
+ EMAIL_MAIL_ATTRIBUTE_CC = 13, /* string type */
+ EMAIL_MAIL_ATTRIBUTE_BCC = 14, /* string type */
+ EMAIL_MAIL_ATTRIBUTE_BODY_DOWNLOAD_STATUS = 15, /* integer type */
+ EMAIL_MAIL_ATTRIBUTE_FILE_PATH_PLAIN = 16, /* string type */
+ EMAIL_MAIL_ATTRIBUTE_FILE_PATH_HTML = 17, /* string type */
+ EMAIL_MAIL_ATTRIBUTE_FILE_SIZE = 18, /* integer type */
+ EMAIL_MAIL_ATTRIBUTE_FLAGS_SEEN_FIELD = 19, /* integer type */
+ EMAIL_MAIL_ATTRIBUTE_FLAGS_DELETED_FIELD = 20, /* integer type */
+ EMAIL_MAIL_ATTRIBUTE_FLAGS_FLAGGED_FIELD = 21, /* integer type */
+ EMAIL_MAIL_ATTRIBUTE_FLAGS_ANSWERED_FIELD = 22, /* integer type */
+ EMAIL_MAIL_ATTRIBUTE_FLAGS_RECENT_FIELD = 23, /* integer type */
+ EMAIL_MAIL_ATTRIBUTE_FLAGS_DRAFT_FIELD = 24, /* integer type */
+ EMAIL_MAIL_ATTRIBUTE_FLAGS_FORWARDED_FIELD = 25, /* integer type */
+ EMAIL_MAIL_ATTRIBUTE_DRM_STATUS = 26, /* integer type */
+ EMAIL_MAIL_ATTRIBUTE_PRIORITY = 27, /* integer type */
+ EMAIL_MAIL_ATTRIBUTE_SAVE_STATUS = 28, /* integer type */
+ EMAIL_MAIL_ATTRIBUTE_LOCK_STATUS = 29, /* integer type */
+ EMAIL_MAIL_ATTRIBUTE_REPORT_STATUS = 30, /* integer type */
+ EMAIL_MAIL_ATTRIBUTE_ATTACHMENT_COUNT = 31, /* integer type */
+ EMAIL_MAIL_ATTRIBUTE_INLINE_CONTENT_COUNT = 32, /* integer type */
+ EMAIL_MAIL_ATTRIBUTE_THREAD_ID = 33, /* integer type */
+ EMAIL_MAIL_ATTRIBUTE_THREAD_ITEM_COUNT = 34, /* integer type */
+ EMAIL_MAIL_ATTRIBUTE_PREVIEW_TEXT = 35, /* string type */
+ EMAIL_MAIL_ATTRIBUTE_MEETING_REQUEST_STATUS = 36, /* integer type */
+ EMAIL_MAIL_ATTRIBUTE_MESSAGE_CLASS = 37, /* integer type */
+ EMAIL_MAIL_ATTRIBUTE_DIGEST_TYPE = 38, /* integer type */
+ EMAIL_MAIL_ATTRIBUTE_SMIME_TYPE = 39, /* integer type */
+ EMAIL_MAIL_ATTRIBUTE_END
+} email_mail_attribute_type;
+
+typedef enum {
+ EMAIL_ADD_MY_ADDRESS_OPTION_DO_NOT_ADD = 0,
+ EMAIL_ADD_MY_ADDRESS_OPTION_ALWAYS_ADD_TO_CC = 1,
+ EMAIL_ADD_MY_ADDRESS_OPTION_ALWAYS_ADD_TO_BCC = 2,
+} email_add_my_address_option_type;
+
+typedef enum {
+ EMAIL_MESSAGE_CLASS_UNSPECIFIED,
+ EMAIL_MESSAGE_CLASS_UNKNOWN,
+ EMAIL_MESSAGE_CLASS_NOTE,
+ EMAIL_MESSAGE_CLASS_NOTE_RULES_OF_TEMPLATE_MICROSOFT,
+ EMAIL_MESSAGE_CLASS_NOTE_SMIME,
+ EMAIL_MESSAGE_CLASS_NOTE_SMIME_MULTIPART_SIGNED,
+ EMAIL_MESSAGE_CLASS_NOTIFICATION_MEETING,
+ EMAIL_MESSAGE_CLASS_OCTEL_VOICE,
+ EMAIL_MESSAGE_CLASS_SCHEDULE_MEETING_REQUEST,
+ EMAIL_MESSAGE_CLASS_SCHEDULE_MEETING_CANCELED,
+ EMAIL_MESSAGE_CLASS_SCHEDULE_MEETING_RESP_POS,
+ EMAIL_MESSAGE_CLASS_SCHEDULE_MEETING_RESP_TENT,
+ EMAIL_MESSAGE_CLASS_SCHEDULE_MEETING_RESP_NEG,
+ EMAIL_MESSAGE_CLASS_POST,
+ EMAIL_MESSAGE_CLASS_INFO_PATH_FORM,
+ EMAIL_MESSAGE_CLASS_VOICE_NOTES,
+ EMAIL_MESSAGE_CLASS_SHARING,
+ EMAIL_MESSAGE_CLASS_NOTE_EXCHANGE_ACTIVE_SYNC_REMOTE_WIPE_CONFIRMATION,
+ EMAIL_MESSAGE_CLASS_VOICE_MAIL,
+ EMAIL_MESSAGE_CLASS_REPORT_DELIVERY_RECEIPT = 0x80000000,
+ EMAIL_MESSAGE_CLASS_REPORT_NON_DELIVERY_RECEIPT = 0x40000000,
+ EMAIL_MESSAGE_CLASS_REPORT_READ_REPORT = 0x20000000,
+ EMAIL_MESSAGE_CLASS_REPORT_NOT_READ_REPORT = 0x10000000
+} email_message_class;
+
+typedef enum{
+ EMAIL_SMIME_NONE = 0, /* Not use smime */
+ EMAIL_SMIME_SIGNED,
+ EMAIL_SMIME_ENCRYPTED,
+ EMAIL_SMIME_SIGNED_AND_ENCRYPTED,
+} email_smime_type;
+
+typedef enum {
+ CIPHER_TYPE_DES3 = 0,
+ CIPHER_TYPE_DES,
+ CIPHER_TYPE_RC2_128,
+ CIPHER_TYPE_RC2_64,
+ CIPHER_TYPE_RC2_40,
+} email_cipher_type;
+
+typedef enum {
+ DIGEST_TYPE_SHA1 = 0,
+ DIGEST_TYPE_MD5,
+} email_digest_type;
+
+/*****************************************************************************/
+/* Data Structures */
+/*****************************************************************************/
+
+/**
+ * This structure is used to save mail time.
+ */
+typedef struct
+{
+ unsigned short year; /**< Specifies the Year.*/
+ unsigned short month; /**< Specifies the Month.*/
+ unsigned short day; /**< Specifies the Day.*/
+ unsigned short hour; /**< Specifies the Hour.*/
+ unsigned short minute; /**< Specifies the Minute.*/
+ unsigned short second; /**< Specifies the Second.*/
+} email_datetime_t DEPRECATED;
+
+/**
+ * This structure is used to save the options.
+ */
+typedef struct
+{
+ email_mail_priority_t priority; /**< Specifies the prority. 1=high 3=normal 5=low.*/
+ int keep_local_copy; /**< Specifies the saving save a copy after sending.*/
+ int req_delivery_receipt; /**< Specifies the request of delivery report. 0=off 1=on*/
+ int req_read_receipt; /**< Specifies the request of read receipt. 0=off 1=on*/
+ int download_limit; /**< Specifies the limit of size for downloading.*/
+ int block_address; /**< Specifies the blocking of address. 0=off 1=on*/
+ int block_subject; /**< Specifies the blocking of subject. 0=off 1=on*/
+ char *display_name_from; /**< Specifies the display name of from.*/
+ int reply_with_body; /**< Specifies the replying with body 0=off 1=on*/
+ int forward_with_files; /**< Specifies the fowarding with files 0=off 1=on*/
+ int add_myname_card; /**< Specifies the adding name card 0=off 1=on*/
+ int add_signature; /**< Specifies the adding signature 0=off 1=on*/
+ char *signature; /**< Specifies the signature*/
+ email_add_my_address_option_type add_my_address_to_bcc; /**< Specifies whether cc or bcc field should be always filled with my address. */
+} email_option_t;
+
+/**
+ * This structure is used to save the information of email account.
+ */
+typedef struct
+{
+ /* General account information */
+ int account_id; /**< Account id */
+ char *account_name; /**< Account name */
+ int account_svc_id; /**< AccountSvc priv data: Specifies id from account-svc */
+ int sync_status; /**< Sync Status. SYNC_STATUS_FINISHED, SYNC_STATUS_SYNCING, SYNC_STATUS_HAVE_NEW_MAILS */
+ int sync_disabled; /**< If this attriube is set as true, email-service will not synchronize this account. */
+ int default_mail_slot_size;
+ char *logo_icon_path; /**< account logo icon (used by account svc and email app) */
+ void *user_data; /**< binary user data */
+ int user_data_length; /**< user data length */
+
+ /* User information */
+ char *user_display_name; /**< User's display */
+ char *user_email_address; /**< User's email address */
+ char *reply_to_address; /**< Email address for reply */
+ char *return_address; /**< Email address for error from server*/
+
+ /* Configuration for incoming server */
+ email_account_server_t incoming_server_type; /**< Incoming server type */
+ char *incoming_server_address; /**< Incoming server address */
+ int incoming_server_port_number; /**< Incoming server port number */
+ char *incoming_server_user_name; /**< Incoming server user name */
+ char *incoming_server_password; /**< Incoming server password */
+ int incoming_server_secure_connection; /**< Does incoming server requires secured connection? */
+
+ /* Options for incoming server */
+ email_imap4_retrieval_mode_t retrieval_mode; /**< Retrieval mode : EMAIL_IMAP4_RETRIEVAL_MODE_NEW or EMAIL_IMAP4_RETRIEVAL_MODE_ALL */
+ int keep_mails_on_pop_server_after_download; /**< Keep mails on POP server after download */
+ int check_interval; /**< Specifies the interval for checking new mail periodically */
+ int auto_download_size; /**< Specifies the size for auto download in bytes. -1 means entire mails body */
+
+ /* Configuration for outgoing server */
+ email_account_server_t outgoing_server_type; /**< Outgoing server type */
+ char *outgoing_server_address; /**< Outgoing server address */
+ int outgoing_server_port_number; /**< Outgoing server port number */
+ char *outgoing_server_user_name; /**< Outgoing server user name */
+ char *outgoing_server_password; /**< Outgoing server password */
+ int outgoing_server_secure_connection; /**< Does outgoing server requires secured connection? */
+ int outgoing_server_need_authentication; /**< Does outgoing server requires authentication? */
+ int outgoing_server_use_same_authenticator; /**< Use same authenticator for outgoing server */
+
+
+ /* Options for outgoing server */
+ email_option_t options;
+
+ /* Authentication Options */
+ int pop_before_smtp; /**< POP before SMTP Authentication */
+ int incoming_server_requires_apop; /**< APOP authentication */
+
+ /* S/MIME Options */
+ email_smime_type smime_type; /**< Sepeifies the smime type 0=Normal 1=Clear signed 2=encrypted 3=Signed + encrypted */
+ char *certificate_path; /**< Sepeifies the certificate path of private*/
+ email_cipher_type cipher_type; /**< Sepeifies the encryption algorithm*/
+ email_digest_type digest_type; /**< Sepeifies the digest algorithm*/
+} email_account_t;
+
+/**
+ * This structure is used to save the information of certificiate
+ */
+
+typedef struct
+{
+ int certificate_id;
+ int issue_year;
+ int issue_month;
+ int issue_day;
+ int expiration_year;
+ int expiration_month;
+ int expiration_day;
+ char *issue_organization_name;
+ char *email_address;
+ char *subject_str;
+ char *filepath;
+} email_certificate_t;
+
+/**
+ * This structure is used to save the information of email server.
+ */
+
+typedef struct
+{
+ int configuration_id; /**< Specifies the id of configuration.*/
+ email_account_server_t protocol_type; /**< Specifies the type of configuration.*/
+ char *server_addr; /**< Specifies the address of configuration.*/
+ int port_number; /**< Specifies the port number of configuration.*/
+ int security_type; /**< Specifies the security such as SSL.*/
+ int auth_type; /**< Specifies the authentication type of configuration.*/
+} email_protocol_config_t;
+
+typedef struct
+{
+ char *service_name; /**< Specifies the name of service.*/
+ int authname_format; /**< Specifies the type of user name for authentication.*/
+ int protocol_conf_count; /**< Specifies count of protocol configurations.*/
+ email_protocol_config_t *protocol_config_array; /**< Specifies array of protocol configurations.*/
+} email_server_info_t;
+
+typedef struct
+{
+ int mailbox_type;
+ char mailbox_name[MAILBOX_NAME_LENGTH];
+} email_mailbox_type_item_t;
+
+/**
+ * This structure is contains the Mail information.
+ */
+
+typedef struct
+{
+ int mail_id; /**< Specifies the Mail ID.*/
+ int account_id; /**< Specifies the Account ID.*/
+ int mailbox_id; /**< Specifies the Mailbox ID.*/
+ email_mailbox_type_e mailbox_type; /**< Specifies the mailbox type of the mail. */
+ char *subject; /**< Specifies the subject.*/
+ time_t date_time; /**< Specifies the Date time.*/
+ int server_mail_status; /**< Specifies the Whether sever mail or not.*/
+ char *server_mailbox_name; /**< Specifies the server mailbox.*/
+ char *server_mail_id; /**< Specifies the Server Mail ID.*/
+ char *message_id; /**< Specifies the message id */
+ char *full_address_from; /**< Specifies the From Addr.*/
+ char *full_address_reply; /**< Specifies the Reply to addr */
+ char *full_address_to; /**< Specifies the To addr.*/
+ char *full_address_cc; /**< Specifies the CC addr.*/
+ char *full_address_bcc; /**< Specifies the BCC addr*/
+ char *full_address_return; /**< Specifies the return Path*/
+ char *email_address_sender; /**< Specifies the email address of sender.*/
+ char *email_address_recipient; /**< Specifies the email address of recipients.*/
+ char *alias_sender; /**< Specifies the alias of sender. */
+ char *alias_recipient; /**< Specifies the alias of recipients. */
+ int body_download_status; /**< Specifies the Text donwloaded or not.*/
+ char *file_path_plain; /**< Specifies the path of text mail body.*/
+ char *file_path_html; /**< Specifies the path of HTML mail body.*/
+ char *file_path_mime_entity; /**< Specifies the path of mime entity. */
+ int mail_size; /**< Specifies the Mail Size.*/
+ char flags_seen_field; /**< Specifies the seen flags*/
+ char flags_deleted_field; /**< Specifies the deleted flags*/
+ char flags_flagged_field; /**< Specifies the flagged flags*/
+ char flags_answered_field; /**< Specifies the answered flags*/
+ char flags_recent_field; /**< Specifies the recent flags*/
+ char flags_draft_field; /**< Specifies the draft flags*/
+ char flags_forwarded_field; /**< Specifies the forwarded flags*/
+ int DRM_status; /**< Has the mail DRM content? (1 : true, 0 : false) */
+ email_mail_priority_t priority; /**< Specifies the priority of the mail.*/
+ int save_status; /**< Specifies the save status*/
+ int lock_status; /**< Specifies the Locked*/
+ int report_status; /**< Specifies the Mail Report.*/
+ int attachment_count; /**< Specifies the attachment count. */
+ int inline_content_count; /**< Specifies the inline content count. */
+ int thread_id; /**< Specifies the thread id for thread view. */
+ int thread_item_count; /**< Specifies the item count of specific thread. */
+ char *preview_text; /**< Specifies the preview body. */
+ int meeting_request_status; /**< Specifies the status of meeting request. */
+ email_message_class message_class;
+ email_digest_type digest_type; /**< Sepeifies the digest algorithm*/
+ email_smime_type smime_type; /**< Specifies the smime type. */
+} email_mail_data_t;
+
+/**
+ * This structure is contains information for displaying mail list.
+ */
+typedef struct
+{
+ int mail_id; /**< Specifies the mail id.*/
+ int account_id; /**< Specifies the account id.*/
+ int mailbox_id; /**< Specifies the mailbox id.*/
+ char from[STRING_LENGTH_FOR_DISPLAY]; /**< Specifies the from display name.*/
+ char from_email_address[MAX_EMAIL_ADDRESS_LENGTH]; /**< Specifies the from email address.*/
+ char recipients[STRING_LENGTH_FOR_DISPLAY]; /**< Specifies the recipients display name.*/
+ char subject[STRING_LENGTH_FOR_DISPLAY]; /**< Specifies the subject.*/
+ int is_text_downloaded; /**< Specifies the text donwloaded or not.*/
+ time_t date_time; /**< Specifies the date time.*/
+ char flags_seen_field; /**< Specifies the seen flags*/
+ char flags_deleted_field; /**< Specifies the deleted flags*/
+ char flags_flagged_field; /**< Specifies the flagged flags*/
+ char flags_answered_field; /**< Specifies the answered flags*/
+ char flags_recent_field; /**< Specifies the recent flags*/
+ char flags_draft_field; /**< Specifies the draft flags*/
+ char flags_forwarded_field; /**< Specifies the forwarded flags*/
+ int priority; /**< Specifies the priority of Mails.*/
+ int save_status; /**< Specifies the save status*/
+ int is_locked; /**< Specifies the locked*/
+ int is_report_mail; /**< Specifies the mail report.*/
+ int recipients_count; /**< Specifies the number of to Recipients*/
+ int has_attachment; /**< the mail has attachments or not[ 0: none, 1: over one] */
+ int has_drm_attachment; /**< the mail has drm attachment or not*/
+ char previewBodyText[MAX_PREVIEW_TEXT_LENGTH]; /**< text for preview body*/
+ int thread_id; /**< thread id for thread view*/
+ int thread_item_count; /**< item count of specific thread */
+ int is_meeting_request; /**< Whether the mail is a meeting request or not */
+ int message_class; /**< Specifies the message class */
+ int smime_type; /**< Specifies the smime type */
+} email_mail_list_item_t;
+
+/**
+ * This structure is used to save the filtering structure.
+ */
+typedef struct
+{
+ int account_id; /**< Specifies the account ID.*/
+ int filter_id; /**< Specifies the filtering ID.*/
+ email_rule_type_t type; /**< Specifies the filtering type.*/
+ char *value; /**< Specifies the filtering value.*/
+ email_rule_action_t faction; /**< Specifies the action type for filtering.*/
+ int target_mailbox_id; /**< Specifies the mail box if action type means move.*/
+ int flag1; /**< Specifies the activation.*/
+ int flag2; /**< Reserved.*/
+} email_rule_t;
+
+/**
+ * This structure is used to save the information of mail flag.
+ */
+typedef struct
+{
+ unsigned int seen : 1; /**< Specifies the read email.*/
+ unsigned int deleted : 1; /**< Reserved.*/
+ unsigned int flagged : 1; /**< Specifies the flagged email.*/
+ unsigned int answered : 1; /**< Reserved.*/
+ unsigned int recent : 1; /**< Reserved.*/
+ unsigned int draft : 1; /**< Specifies the draft email.*/
+ unsigned int has_attachment : 1; /**< Reserved.*/
+ unsigned int forwarded : 1; /**< Reserved.*/
+ unsigned int sticky : 1; /**< Sticky flagged mails cannot be deleted */
+} email_mail_flag_t /* DEPRECATED */;
+
+
+/**
+ * This structure is used to save the information of mail extra flag.
+ */
+typedef struct
+{
+ unsigned int priority : 3; /**< Specifies the mail priority.
+ The value is greater than or equal to EMAIL_MAIL_PRIORITY_HIGH.
+ The value is less than or eqult to EMAIL_MAIL_PRIORITY_LOW.*/
+ unsigned int status : 4; /**< Specifies the mail status.
+ The value is a value of enumeration email_mail_status_t.*/
+ unsigned int noti : 1; /**< Specifies the notified mail.*/
+ unsigned int lock : 1; /**< Specifies the locked mail.*/
+ unsigned int report : 2; /**< Specifies the MDN/DSN mail. The value is a value of enumeration email_mail_report_t.*/
+ unsigned int drm : 1; /**< Specifies the drm mail.*/
+ unsigned int text_download_yn : 2; /**< body download y/n*/
+} email_extra_flag_t /* DEPRECATED */;
+
+/**
+ * This structure is used to save the information of attachment.
+ */
+typedef struct
+{
+ int attachment_id;
+ char *attachment_name;
+ char *attachment_path;
+ int attachment_size;
+ int mail_id;
+ int account_id;
+ char mailbox_id;
+ int save_status;
+ int drm_status;
+ int inline_content_status;
+ char *attachment_mime_type; /**< Specifies the context mime type.*/
+} email_attachment_data_t;
+
+typedef struct
+{
+ int offset_from_GMT;
+ char standard_name[32];
+ struct tm standard_time_start_date;
+ int standard_bias;
+ char daylight_name[32];
+ struct tm daylight_time_start_date;
+ int daylight_bias;
+} email_time_zone_t;
+
+typedef struct
+{
+ int mail_id; /**< Specifies the mail id of meeting request on DB. This is the primary key. */
+ email_meeting_response_t meeting_response; /**< Specifies the meeting response. */
+ struct tm start_time;
+ struct tm end_time;
+ char *location; /**< Specifies the location of meeting. Maximum length of this string is 32768 */
+ char *global_object_id; /**< Specifies the object id. */
+ email_time_zone_t time_zone;
+} email_meeting_request_t;
+
+/**
+ * This structure is used to save the informatioin of sender list with unread/total mail counts
+ */
+typedef struct
+{
+ char *address; /**< Specifies the address of a sender.*/
+ char *display_name; /**< Specifies a display name. This may be one of contact name, alias in original mail and email address of sender. (Priority order : contact name, alias, email address) */
+ int unread_count; /**< Specifies the number of unread mails received from sender address*/
+ int total_count; /**< Specifies the total number of mails which are received from sender address*/
+} email_sender_list_t /* DEPRECATED */;
+
+
+/**
+ * This structure is used to save the information of mailbox.
+ */
+typedef struct
+{
+ int mailbox_id; /**< Unique id on mailbox table.*/
+ char *mailbox_name; /**< Specifies the path of mailbox.*/
+ email_mailbox_type_e mailbox_type; /**< Specifies the type of mailbox */
+ char *alias; /**< Specifies the display name of mailbox.*/
+ int unread_count; /**< Specifies the unread mail count in the mailbox.*/
+ int total_mail_count_on_local; /**< Specifies the total number of mails in the mailbox in the local DB.*/
+ int total_mail_count_on_server; /**< Specifies the total number of mails in the mailbox in the mail server.*/
+ int local; /**< Specifies the local mailbox.*/
+ int account_id; /**< Specifies the account ID for mailbox.*/
+ int mail_slot_size; /**< Specifies how many mails can be stored in local mailbox.*/
+ int no_select; /**< Specifies the 'no_select' attribute from xlist.*/
+ time_t last_sync_time;
+} email_mailbox_t;
+
+typedef struct
+{
+ email_address_type_t address_type;
+ char *address;
+ char *display_name;
+ int storage_type;
+ int contact_id;
+} email_address_info_t;
+
+typedef struct
+{
+ GList *from;
+ GList *to;
+ GList *cc;
+ GList *bcc;
+} email_address_info_list_t;
+
+typedef struct
+{
+ int address_type; /* type of mail (sender : 0, recipient : 1)*/
+ int address_count; /* The number of email addresse */
+ char **address_list; /* strings of email addresse */
+} email_email_address_list_t;
+
+
+typedef struct _email_search_filter_t {
+ email_search_filter_type search_filter_type; /* type of search filter */
+ union {
+ int integer_type_key_value;
+ time_t time_type_key_value;
+ char *string_type_key_value;
+ } search_filter_key_value;
+} email_search_filter_t;
+
+typedef enum {
+ EMAIL_LIST_FILTER_RULE_EQUAL = 0,
+ EMAIL_LIST_FILTER_RULE_NOT_EQUAL = 1,
+ EMAIL_LIST_FILTER_RULE_LESS_THAN = 2,
+ EMAIL_LIST_FILTER_RULE_GREATER_THAN = 3,
+ EMAIL_LIST_FILTER_RULE_LESS_THAN_OR_EQUAL = 4,
+ EMAIL_LIST_FILTER_RULE_GREATER_THAN_OR_EQUAL = 5,
+ EMAIL_LIST_FILTER_RULE_INCLUDE = 6,
+ EMAIL_LIST_FILTER_RULE_IN = 7,
+ EMAIL_LIST_FILTER_RULE_NOT_IN = 8
+} email_list_filter_rule_type_t;
+
+typedef enum {
+ EMAIL_CASE_SENSITIVE = 0,
+ EMAIL_CASE_INSENSITIVE = 1,
+} email_list_filter_case_sensitivity_t;
+
+typedef struct {
+ email_list_filter_rule_type_t rule_type;
+ email_mail_attribute_type target_attribute;
+
+ union {
+ int integer_type_value;
+ char *string_type_value;
+ time_t datetime_type_value;
+ } key_value;
+
+ email_list_filter_case_sensitivity_t case_sensitivity;
+} email_list_filter_rule_t;
+
+typedef enum {
+ EMAIL_LIST_FILTER_ITEM_RULE = 0,
+ EMAIL_LIST_FILTER_ITEM_OPERATOR = 1,
+} email_list_filter_item_type_t;
+
+typedef enum {
+ EMAIL_LIST_FILTER_OPERATOR_AND = 0,
+ EMAIL_LIST_FILTER_OPERATOR_OR = 1,
+ EMAIL_LIST_FILTER_OPERATOR_LEFT_PARENTHESIS = 2,
+ EMAIL_LIST_FILTER_OPERATOR_RIGHT_PARENTHESIS = 3
+} email_list_filter_operator_type_t;
+
+typedef struct {
+ email_list_filter_item_type_t list_filter_item_type;
+
+ union {
+ email_list_filter_rule_t rule;
+ email_list_filter_operator_type_t operator_type;
+ } list_filter_item;
+
+} email_list_filter_t;
+
+typedef enum {
+ EMAIL_SORT_ORDER_ASCEND = 0,
+ EMAIL_SORT_ORDER_DESCEND = 1
+} email_list_filter_sort_order_t;
+
+typedef struct {
+ email_mail_attribute_type target_attribute;
+ bool force_boolean_check;
+ email_list_filter_sort_order_t sort_order;
+} email_list_sorting_rule_t;
+
+/*****************************************************************************/
+/* For Active Sync */
+/*****************************************************************************/
+
+#define VCONFKEY_EMAIL_SERVICE_ACTIVE_SYNC_HANDLE "db/email_handle/active_sync_handle"
+#define EMAIL_ACTIVE_SYNC_NOTI "User.Email.ActiveSync"
+
+typedef enum
+{
+ ACTIVE_SYNC_NOTI_SEND_MAIL, /* a sending notification to ASE (active sync engine */
+ ACTIVE_SYNC_NOTI_SEND_SAVED, /* a sending notification to ASE (active sync engine), All saved mails should be sent */
+ ACTIVE_SYNC_NOTI_SEND_REPORT, /* a sending notification to ASE (active sync engine), report should be sen */
+ ACTIVE_SYNC_NOTI_SYNC_HEADER, /* a sync header - download mails from server. */
+ /* It is depended on account/s flag1 field whether it excutes downloading header only or downloading header + body */
+ /* downloading option : 0 is subject only, 1 is text body, 2 is normal */
+ ACTIVE_SYNC_NOTI_DOWNLOAD_BODY, /* a downloading body notification to AS */
+ ACTIVE_SYNC_NOTI_DOWNLOAD_ATTACHMENT, /* a downloading attachment notification to AS */
+ ACTIVE_SYNC_NOTI_VALIDATE_ACCOUNT, /* a account validating notification to AS */
+ ACTIVE_SYNC_NOTI_CANCEL_JOB, /* a cancling job notification to AS */
+ ACTIVE_SYNC_NOTI_SEARCH_ON_SERVER, /* a searching on server notification to AS */
+ 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 */
+} eactivesync_noti_t;
+
+typedef union
+{
+ struct _send_mail
+ {
+ int handle;
+ int account_id;
+ int mail_id;
+ email_option_t options;
+ } send_mail;
+
+ struct _send_mail_saved
+ {/* not defined ye */
+ int handle;
+ int account_id;
+ } send_mail_saved;
+
+ struct _send_report
+ {/* not defined ye */
+ int handle;
+ int account_id;
+ } send_report;
+
+ struct _sync_header
+ {
+ int handle;
+ int account_id;
+ int mailbox_id;
+ } sync_header;
+
+ struct _download_body
+ {
+ int handle;
+ int account_id;
+ int mail_id;
+ int with_attachment; /* 0: without attachments, 1: with attachment */
+ } download_body;
+
+ struct _download_attachment
+ {
+ int handle;
+ int account_id;
+ int mail_id;
+ int attachment_order;
+ } download_attachment;
+
+ struct _cancel_job
+ {
+ int account_id;
+ int handle; /* job handle to be canceled. this value is issued by email-service. */
+ int cancel_type;
+ } cancel_job;
+
+ struct _validate_account
+ {/* not defined yet */
+ int handle;
+ int account_id;
+ } validate_account;
+
+ struct _search_mail_on_server
+ {
+ int handle;
+ int account_id;
+ int mailbox_id;
+ email_search_filter_t *search_filter_list;
+ int search_filter_count;
+ } search_mail_on_server;
+
+ struct _clear_result_of_search_mail_on_server
+ {
+ int handle;
+ int account_id;
+ } clear_result_of_search_mail_on_server;
+
+ struct _expunge_mails_deleted_flagged
+ {
+ int handle;
+ int mailbox_id;
+ int on_server;
+ } expunge_mails_deleted_flagged;
+
+ struct _get_resolve_recipients
+ {
+ int handle;
+ int account_id;
+ char *email_address;
+ } get_resolve_recipients;
+
+ struct _validate_certificate
+ {
+ int handle;
+ int account_id;
+ char *email_address;
+ } validate_certificate;
+
+ struct _add_mailbox
+ {
+ int handle;
+ int account_id;
+ char *mailbox_path;
+ char *mailbox_alias;
+ } add_mailbox;
+
+ struct _rename_mailbox
+ {
+ int handle;
+ int account_id;
+ int mailbox_id;
+ char *mailbox_name;
+ char *mailbox_alias;
+ } rename_mailbox;
+
+ struct _delete_mailbox
+ {
+ int handle;
+ int account_id;
+ int mailbox_id;
+ } delete_mailbox;
+
+} ASNotiData;
+
+
+/* types for noti string */
+typedef enum
+{
+ EMAIL_CONVERT_STRUCT_TYPE_MAIL_LIST_ITEM, /** specifies email_mail_list_t */
+} email_convert_struct_type_e;
+
+#ifdef __cplusplus
+}
+#endif
+
+/**
+* @} @}
+*/
+
+#endif /* __EMAIL_TYPES_H__ */
diff --git a/email-common-use/include/email-utilities.h b/email-common-use/include/email-utilities.h
index 8f63cc3..87e7d5b 100755
--- a/email-common-use/include/email-utilities.h
+++ b/email-common-use/include/email-utilities.h
@@ -1,64 +1,72 @@
-/*
-* email-service
-*
-* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
-*
-* Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com>
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*
-*/
-
-/*
- * email-utilities.h
- *
- * Created on: 2012. 3. 6.
- * Author: kyuho.jo@samsung.com
- */
-
-#ifndef __EMAIL_UTILITIES_H__
-#define __EMAIL_UTILITIES_H__
-
-#include "email-types.h"
-#include "email-internal-types.h"
-#include "email-debug-log.h"
-#include "email-storage.h"
-
-INTERNAL_FUNC void* em_malloc(unsigned len);
-INTERNAL_FUNC char* em_trim_left(char *str);
-INTERNAL_FUNC char* em_trim_right(char *str);
-INTERNAL_FUNC char* em_upper_string(char *str);
-INTERNAL_FUNC char* em_lower_string(char *str);
-INTERNAL_FUNC int em_upper_path(char *path);
-
-INTERNAL_FUNC void em_skip_whitespace(char *addr_str , char **pAddr);
-INTERNAL_FUNC char* em_skip_whitespace_without_strdup(char *source_string);
-INTERNAL_FUNC char* em_replace_string(char *source_string, char *old_string, char *new_string);
-INTERNAL_FUNC void em_flush_memory();
-INTERNAL_FUNC char* em_get_extension_from_file_path(char *source_file_path, int *err_code);
-INTERNAL_FUNC int em_get_encoding_type_from_file_path(const char *input_file_path, char **output_encoding_type);
-INTERNAL_FUNC int em_get_content_type_from_extension_string(const char *extension_string, int *err_code);
-
-INTERNAL_FUNC int em_verify_email_address(char *address, int without_bracket, int *err_code);
-INTERNAL_FUNC int em_verify_email_address_of_mail_data(emf_mail_data_t *mail_data, int without_bracket, int *err_code);
-INTERNAL_FUNC int em_verify_email_address_of_mail_tbl(emstorage_mail_tbl_t *input_mail_tbl, int input_without_bracket);
-
-INTERNAL_FUNC int em_find_pos_stripped_subject_for_thread_view(char *subject, char *stripped_subject);
-INTERNAL_FUNC int em_find_tag_for_thread_view(char *subject, int *result);
-
-INTERNAL_FUNC int em_encode_base64(char *src, unsigned long src_len, char **enc, unsigned long* enc_len, int *err_code);
-INTERNAL_FUNC int em_decode_base64(unsigned char *enc_text, unsigned long enc_len, char **dec_text, unsigned long* dec_len, int *err_code);
-
-extern char* strcasestr(__const char *__haystack, __const char *__needle) __THROW __attribute_pure__ __nonnull ((1, 2));
-
-#endif /* __EMAIL_UTILITIES_H__ */
+/*
+* email-service
+*
+* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+*
+* Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com>
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*
+*/
+
+/*
+ * email-utilities.h
+ *
+ * Created on: 2012. 3. 6.
+ * Author: kyuho.jo@samsung.com
+ */
+
+#ifndef __EMAIL_UTILITIES_H__
+#define __EMAIL_UTILITIES_H__
+
+#include "email-types.h"
+#include "email-internal-types.h"
+#include "email-debug-log.h"
+#include "email-storage.h"
+
+INTERNAL_FUNC void* em_malloc(int len);
+INTERNAL_FUNC void* em_memdup(void* src, int len);
+INTERNAL_FUNC char* em_trim_left(char *str);
+INTERNAL_FUNC char* em_trim_right(char *str);
+INTERNAL_FUNC char* em_upper_string(char *str);
+INTERNAL_FUNC char* em_lower_string(char *str);
+INTERNAL_FUNC int em_upper_path(char *path);
+
+INTERNAL_FUNC void em_skip_whitespace(char *addr_str , char **pAddr);
+INTERNAL_FUNC char* em_skip_whitespace_without_strdup(char *source_string);
+INTERNAL_FUNC char* em_replace_all_string(char *source_string, char *old_string, char *new_string);
+INTERNAL_FUNC char* em_replace_string(char *source_string, char *old_string, char *new_string);
+INTERNAL_FUNC void em_flush_memory();
+INTERNAL_FUNC int em_get_file_name_and_extension_from_file_path(char *input_source_file_path, char **output_file_name, char **output_extention);
+INTERNAL_FUNC char* em_get_extension_from_file_path(char *source_file_path, int *err_code);
+INTERNAL_FUNC int em_get_encoding_type_from_file_path(const char *input_file_path, char **output_encoding_type);
+INTERNAL_FUNC int em_get_content_type_from_extension_string(const char *extension_string, int *err_code);
+
+INTERNAL_FUNC int em_verify_email_address(char *address, int without_bracket, int *err_code);
+INTERNAL_FUNC int em_verify_email_address_of_mail_data(email_mail_data_t *mail_data, int without_bracket, int *err_code);
+INTERNAL_FUNC int em_verify_email_address_of_mail_tbl(emstorage_mail_tbl_t *input_mail_tbl, int input_without_bracket);
+
+INTERNAL_FUNC int em_find_pos_stripped_subject_for_thread_view(char *subject, char *stripped_subject);
+INTERNAL_FUNC int em_find_tag_for_thread_view(char *subject, int *result);
+
+INTERNAL_FUNC int em_encode_base64(char *src, unsigned long src_len, char **enc, unsigned long* enc_len, int *err_code);
+INTERNAL_FUNC int em_decode_base64(unsigned char *enc_text, unsigned long enc_len, char **dec_text, unsigned long* dec_len, int *err_code);
+
+extern char* strcasestr(__const char *__haystack, __const char *__needle) __THROW __attribute_pure__ __nonnull ((1, 2));
+
+INTERNAL_FUNC int em_get_account_server_type_by_account_id(int account_id, email_account_server_t* account_server_type, int flag, int *error);
+
+INTERNAL_FUNC int em_get_handle_for_activesync(int *handle, int *error);
+INTERNAL_FUNC int em_send_notification_to_active_sync_engine(int subType, ASNotiData *data);
+
+#endif /* __EMAIL_UTILITIES_H__ */
diff --git a/email-common-use/include/tpl.h b/email-common-use/include/tpl.h
new file mode 100644
index 0000000..e23953b
--- /dev/null
+++ b/email-common-use/include/tpl.h
@@ -0,0 +1,133 @@
+/*
+Copyright (c) 2005-2010, Troy D. Hanson http://tpl.sourceforge.net
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
+OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#ifndef TPL_H
+#define TPL_H
+
+#include <stddef.h> /* size_t */
+
+#ifdef __INTEL_COMPILER
+#include <tbb/tbbmalloc_proxy.h>
+#endif /* Intel Compiler efficient memcpy etc */
+
+#ifdef _MSC_VER
+typedef unsigned int uint32_t;
+#else
+#include <inttypes.h> /* uint32_t */
+#endif
+
+#if defined __cplusplus
+extern "C" {
+#endif
+
+#ifdef _WIN32
+#ifdef TPL_EXPORTS
+#define TPL_API __declspec(dllexport)
+#else /* */
+#ifdef TPL_NOLIB
+#define TPL_API
+#else
+#define TPL_API __declspec(dllimport)
+#endif /* TPL_NOLIB */
+#endif /* TPL_EXPORTS*/
+#else
+#define TPL_API
+#endif
+
+/* bit flags (external) */
+#define TPL_FILE (1 << 0)
+#define TPL_MEM (1 << 1)
+#define TPL_PREALLOCD (1 << 2)
+#define TPL_EXCESS_OK (1 << 3)
+#define TPL_FD (1 << 4)
+#define TPL_UFREE (1 << 5)
+#define TPL_DATAPEEK (1 << 6)
+#define TPL_FXLENS (1 << 7)
+#define TPL_GETSIZE (1 << 8)
+/* do not add flags here without renumbering the internal flags! */
+
+/* flags for tpl_gather mode */
+#define TPL_GATHER_BLOCKING 1
+#define TPL_GATHER_NONBLOCKING 2
+#define TPL_GATHER_MEM 3
+
+/* Hooks for error logging, memory allocation functions and fatal */
+typedef int (tpl_print_fcn)(const char *fmt, ...);
+typedef void *(tpl_malloc_fcn)(size_t sz);
+typedef void *(tpl_realloc_fcn)(void *ptr, size_t sz);
+typedef void (tpl_free_fcn)(void *ptr);
+typedef void (tpl_fatal_fcn)(char *fmt, ...);
+
+typedef struct tpl_hook_t {
+ tpl_print_fcn *oops;
+ tpl_malloc_fcn *malloc;
+ tpl_realloc_fcn *realloc;
+ tpl_free_fcn *free;
+ tpl_fatal_fcn *fatal;
+ size_t gather_max;
+} tpl_hook_t;
+
+typedef struct tpl_node {
+ int type;
+ void *addr;
+ void *data; /* r:tpl_root_data*. A:tpl_atyp*. ow:szof type */
+ int num; /* length of type if its a C array */
+ size_t ser_osz; /* serialization output size for subtree */
+ struct tpl_node *children; /* my children; linked-list */
+ struct tpl_node *next,*prev; /* my siblings (next child of my parent) */
+ struct tpl_node *parent; /* my parent */
+} tpl_node;
+
+/* used when un/packing 'B' type (binary buffers) */
+typedef struct tpl_bin {
+ void *addr;
+ uint32_t sz;
+} tpl_bin;
+
+/* for async/piecemeal reading of tpl images */
+typedef struct tpl_gather_t {
+ char *img;
+ int len;
+} tpl_gather_t;
+
+/* Callback used when tpl_gather has read a full tpl image */
+typedef int (tpl_gather_cb)(void *img, size_t sz, void *data);
+
+/* Prototypes */
+TPL_API tpl_node *tpl_map(char *fmt,...); /* define tpl using format */
+TPL_API void tpl_free(tpl_node *r); /* free a tpl map */
+TPL_API int tpl_pack(tpl_node *r, int i); /* pack the n'th packable */
+TPL_API int tpl_unpack(tpl_node *r, int i); /* unpack the n'th packable */
+TPL_API int tpl_dump(tpl_node *r, int mode, ...); /* serialize to mem/file */
+TPL_API int tpl_load(tpl_node *r, int mode, ...); /* set mem/file to unpack */
+TPL_API int tpl_Alen(tpl_node *r, int i); /* array len of packable i */
+TPL_API char* tpl_peek(int mode, ...); /* sneak peek at format string */
+TPL_API int tpl_gather( int mode, ...); /* non-blocking image gather */
+TPL_API int tpl_jot(int mode, ...); /* quick write a simple tpl */
+
+#if defined __cplusplus
+ }
+#endif
+
+#endif /* TPL_H */
+
diff --git a/email-common-use/tpl.c b/email-common-use/tpl.c
new file mode 100644
index 0000000..60b3be8
--- /dev/null
+++ b/email-common-use/tpl.c
@@ -0,0 +1,2477 @@
+/*
+Copyright (c) 2005-2010, Troy D. Hanson http://tpl.sourceforge.net
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
+OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#define TPL_VERSION 1.5
+
+static const char id[]="$Id: tpl.c 192 2009-04-24 10:35:30Z thanson $";
+
+
+#include <stdlib.h> /* malloc */
+#include <stdarg.h> /* va_list */
+#include <string.h> /* memcpy, memset, strchr */
+#include <stdio.h> /* printf (tpl_hook.oops default function) */
+
+#ifndef _WIN32
+#include <unistd.h> /* for ftruncate */
+#else
+#include <io.h>
+#define ftruncate(x,y) _chsize(x,y)
+#endif
+#include <sys/types.h> /* for 'open' */
+#include <sys/stat.h> /* for 'open' */
+#include <fcntl.h> /* for 'open' */
+#include <errno.h>
+#ifndef _WIN32
+#include <inttypes.h> /* uint32_t, uint64_t, etc */
+#else
+typedef unsigned short ushort;
+typedef __int16 int16_t;
+typedef __int32 int32_t;
+typedef __int64 int64_t;
+typedef unsigned __int16 uint16_t;
+typedef unsigned __int32 uint32_t;
+typedef unsigned __int64 uint64_t;
+#endif
+
+
+#if ( defined __CYGWIN__ || defined __MINGW32__ || defined _WIN32 )
+#include "win/mman.h" /* mmap */
+#else
+#include <sys/mman.h> /* mmap */
+#endif
+
+#include "tpl.h"
+#include "email-debug-log.h"
+
+
+#define TPL_GATHER_BUFLEN 8192
+#define TPL_MAGIC "tpl"
+
+/* macro to add a structure to a doubly-linked list */
+#define DL_ADD(head,add) \
+ do { \
+ if (head) { \
+ (add)->prev = (head)->prev; \
+ (head)->prev->next = (add); \
+ (head)->prev = (add); \
+ (add)->next = NULL; \
+ } else { \
+ (head)=(add); \
+ (head)->prev = (head); \
+ (head)->next = NULL; \
+ } \
+ } while (0);
+
+#define fatal_oom() tpl_hook.fatal("out of memory\n")
+
+/* bit flags (internal). preceded by the external flags in tpl.h */
+#define TPL_WRONLY (1 << 9) /* app has initiated tpl packing */
+#define TPL_RDONLY (1 << 10) /* tpl was loaded (for unpacking) */
+#define TPL_XENDIAN (1 << 11) /* swap endianness when unpacking */
+#define TPL_OLD_STRING_FMT (1 << 12) /* tpl has strings in 1.2 format */
+
+/* values for the flags byte that appears after the magic prefix */
+#define TPL_SUPPORTED_BITFLAGS 3
+#define TPL_FL_BIGENDIAN (1 << 0)
+#define TPL_FL_NULLSTRINGS (1 << 1)
+
+/* char values for node type */
+#define TPL_TYPE_ROOT 0
+#define TPL_TYPE_INT32 1
+#define TPL_TYPE_UINT32 2
+#define TPL_TYPE_BYTE 3
+#define TPL_TYPE_STR 4
+#define TPL_TYPE_ARY 5
+#define TPL_TYPE_BIN 6
+#define TPL_TYPE_DOUBLE 7
+#define TPL_TYPE_INT64 8
+#define TPL_TYPE_UINT64 9
+#define TPL_TYPE_INT16 10
+#define TPL_TYPE_UINT16 11
+#define TPL_TYPE_POUND 12
+
+/* error codes */
+#define ERR_NOT_MINSIZE (-1)
+#define ERR_MAGIC_MISMATCH (-2)
+#define ERR_INCONSISTENT_SZ (-3)
+#define ERR_FMT_INVALID (-4)
+#define ERR_FMT_MISSING_NUL (-5)
+#define ERR_FMT_MISMATCH (-6)
+#define ERR_FLEN_MISMATCH (-7)
+#define ERR_INCONSISTENT_SZ2 (-8)
+#define ERR_INCONSISTENT_SZ3 (-9)
+#define ERR_INCONSISTENT_SZ4 (-10)
+#define ERR_UNSUPPORTED_FLAGS (-11)
+
+/* access to A(...) nodes by index */
+typedef struct tpl_pidx {
+ struct tpl_node *node;
+ struct tpl_pidx *next,*prev;
+} tpl_pidx;
+
+/* A(...) node datum */
+typedef struct tpl_atyp {
+ uint32_t num; /* num elements */
+ size_t sz; /* size of each backbone's datum */
+ struct tpl_backbone *bb,*bbtail;
+ void *cur;
+} tpl_atyp;
+
+/* backbone to extend A(...) lists dynamically */
+typedef struct tpl_backbone {
+ struct tpl_backbone *next;
+ /* when this structure is malloc'd, extra space is alloc'd at the
+ * end to store the backbone "datum", and data points to it. */
+#if __STDC_VERSION__ < 199901
+ char *data;
+#else
+ char data[];
+#endif
+} tpl_backbone;
+
+/* mmap record */
+typedef struct tpl_mmap_rec {
+ int fd;
+ void *text;
+ size_t text_sz;
+} tpl_mmap_rec;
+
+/* root node datum */
+typedef struct tpl_root_data {
+ int flags;
+ tpl_pidx *pidx;
+ tpl_mmap_rec mmap;
+ char *fmt;
+ int *fxlens, num_fxlens;
+} tpl_root_data;
+
+/* node type to size mapping */
+struct tpl_type_t {
+ char c;
+ int sz;
+};
+
+
+/* Internal prototypes */
+static tpl_node *tpl_node_new(tpl_node *parent);
+static tpl_node *tpl_find_i(tpl_node *n, int i);
+static void *tpl_cpv(void *datav, void *data, size_t sz);
+static void *tpl_extend_backbone(tpl_node *n);
+static char *tpl_fmt(tpl_node *r);
+static void *tpl_dump_atyp(tpl_node *n, tpl_atyp* at, void *dv);
+static size_t tpl_ser_osz(tpl_node *n);
+static void tpl_free_atyp(tpl_node *n,tpl_atyp *atyp);
+static int tpl_dump_to_mem(tpl_node *r, void *addr, size_t sz);
+static int tpl_mmap_file(char *filename, tpl_mmap_rec *map_rec);
+static int tpl_mmap_output_file(char *filename, size_t sz, void **text_out);
+static int tpl_cpu_bigendian(void);
+static int tpl_needs_endian_swap(void *);
+static void tpl_byteswap(void *word, int len);
+static void tpl_fatal(char *fmt, ...);
+static int tpl_serlen(tpl_node *r, tpl_node *n, void *dv, size_t *serlen);
+static int tpl_unpackA0(tpl_node *r);
+static int tpl_oops(const char *fmt, ...);
+static int tpl_gather_mem( char *buf, size_t len, tpl_gather_t **gs, tpl_gather_cb *cb, void *data);
+static int tpl_gather_nonblocking( int fd, tpl_gather_t **gs, tpl_gather_cb *cb, void *data);
+static int tpl_gather_blocking(int fd, void **img, size_t *sz);
+static tpl_node *tpl_map_va(char *fmt, va_list ap);
+
+/* This is used internally to help calculate padding when a 'double'
+ * follows a smaller datatype in a structure. Normally under gcc
+ * on x86, d will be aligned at +4, however use of -malign-double
+ * causes d to be aligned at +8 (this is actually faster on x86).
+ * Also SPARC and x86_64 seem to align always on +8.
+ */
+struct tpl_double_alignment_detector {
+ char a;
+ double d; /* some platforms align this on +4, others on +8 */
+};
+
+/* this is another case where alignment varies. mac os x/gcc was observed
+ * to align the int64_t at +4 under -m32 and at +8 under -m64 */
+struct tpl_int64_alignment_detector {
+ int i;
+ int64_t j; /* some platforms align this on +4, others on +8 */
+};
+
+typedef struct {
+ size_t inter_elt_len; /* padded inter-element len; i.e. &a[1].field - &a[0].field */
+ tpl_node *iter_start_node; /* node to jump back to, as we start each new iteration */
+ size_t iternum; /* current iteration number (total req'd. iter's in n->num) */
+} tpl_pound_data;
+
+/* Hooks for customizing tpl mem alloc, error handling, etc. Set defaults. */
+tpl_hook_t tpl_hook = {
+ /* .oops = */ tpl_oops,
+ /* .malloc = */ malloc,
+ /* .realloc = */ realloc,
+ /* .free = */ free,
+ /* .fatal = */ tpl_fatal,
+ /* .gather_max = */ 0 /* max tpl size (bytes) for tpl_gather */
+};
+
+static const char tpl_fmt_chars[] = "AS($)BiucsfIUjv#"; /* valid format chars */
+static const char tpl_S_fmt_chars[] = "iucsfIUjv#$()"; /* valid within S(...) */
+static const char tpl_datapeek_ok_chars[] = "iucsfIUjv"; /* valid in datapeek */
+static const struct tpl_type_t tpl_types[] = {
+ /* [TPL_TYPE_ROOT] = */ {'r', 0},
+ /* [TPL_TYPE_INT32] = */ {'i', sizeof(int32_t)},
+ /* [TPL_TYPE_UINT32] = */ {'u', sizeof(uint32_t)},
+ /* [TPL_TYPE_BYTE] = */ {'c', sizeof(char)},
+ /* [TPL_TYPE_STR] = */ {'s', sizeof(char*)},
+ /* [TPL_TYPE_ARY] = */ {'A', 0},
+ /* [TPL_TYPE_BIN] = */ {'B', 0},
+ /* [TPL_TYPE_DOUBLE] = */ {'f', 8}, /* not sizeof(double) as that varies */
+ /* [TPL_TYPE_INT64] = */ {'I', sizeof(int64_t)},
+ /* [TPL_TYPE_UINT64] = */ {'U', sizeof(uint64_t)},
+ /* [TPL_TYPE_INT16] = */ {'j', sizeof(int16_t)},
+ /* [TPL_TYPE_UINT16] = */ {'v', sizeof(uint16_t)},
+ /* [TPL_TYPE_POUND] = */ {'#', 0},
+};
+
+/* default error-reporting function. Just writes to stderr. */
+static int tpl_oops(const char *fmt, ...) {
+ char buf[256];
+ va_list ap;
+ va_start(ap,fmt);
+/* vfprintf(stderr,fmt,ap); */
+ snprintf(buf, sizeof(buf)-1, fmt, ap);
+ EM_DEBUG_EXCEPTION("%s", buf);
+ va_end(ap);
+ return 0;
+}
+
+
+static tpl_node *tpl_node_new(tpl_node *parent) {
+ tpl_node *n;
+ if ((n=tpl_hook.malloc(sizeof(tpl_node))) == NULL) {
+ fatal_oom();
+ }
+ n->addr=NULL;
+ n->data=NULL;
+ n->num=1;
+ n->ser_osz=0;
+ n->children=NULL;
+ n->next=NULL;
+ n->parent=parent;
+ return n;
+}
+
+/* Used in S(..) formats to pack several fields from a structure based on
+ * only the structure address. We need to calculate field addresses
+ * manually taking into account the size of the fields and intervening padding.
+ * The wrinkle is that double is not normally aligned on x86-32 but the
+ * -malign-double compiler option causes it to be. Double are aligned
+ * on Sparc, and apparently on 64 bit x86. We use a helper structure
+ * to detect whether double is aligned in this compilation environment.
+ */
+char *calc_field_addr(tpl_node *parent, int type,char *struct_addr, int ordinal) {
+ tpl_node *prev;
+ int offset;
+ int align_sz;
+
+ if (ordinal == 1) return struct_addr; /* first field starts on structure address */
+
+ /* generate enough padding so field addr is divisible by it's align_sz. 4, 8, etc */
+ prev = parent->children->prev;
+ switch(type) {
+ case TPL_TYPE_DOUBLE:
+ align_sz = sizeof(struct tpl_double_alignment_detector) > 12 ? 8 : 4;
+ break;
+ case TPL_TYPE_INT64:
+ case TPL_TYPE_UINT64:
+ align_sz = sizeof(struct tpl_int64_alignment_detector) > 12 ? 8 : 4;
+ break;
+ default:
+ align_sz = tpl_types[type].sz;
+ break;
+ }
+ offset = ((uintptr_t)prev->addr - (uintptr_t)struct_addr)
+ + (tpl_types[prev->type].sz * prev->num);
+ offset = (offset + align_sz - 1) / align_sz * align_sz;
+ return struct_addr + offset;
+}
+
+TPL_API tpl_node *tpl_map(char *fmt,...) {
+ va_list ap;
+ tpl_node *tn;
+
+ va_start(ap,fmt);
+ tn = tpl_map_va(fmt, ap);
+ va_end(ap);
+ return tn;
+}
+
+static tpl_node *tpl_map_va(char *fmt, va_list ap) {
+ int lparen_level=0,expect_lparen=0,t=0,in_structure=0,ordinal=0;
+ int in_nested_structure=0;
+ char *c, *peek, *struct_addr=NULL, *struct_next;
+ tpl_node *root,*parent,*n=NULL,*preceding,*iter_start_node=NULL,
+ *struct_widest_node=NULL, *np; tpl_pidx *pidx;
+ tpl_pound_data *pd;
+ int *fxlens, num_fxlens, pound_num, pound_prod, applies_to_struct;
+ int contig_fxlens[10]; /* temp space for contiguous fxlens */
+ int num_contig_fxlens, i, j;
+ ptrdiff_t inter_elt_len=0; /* padded element length of contiguous structs in array */
+
+
+ root = tpl_node_new(NULL);
+ root->type = TPL_TYPE_ROOT;
+ root->data = (tpl_root_data*)tpl_hook.malloc(sizeof(tpl_root_data));
+ if (!root->data) fatal_oom();
+ memset((tpl_root_data*)root->data,0,sizeof(tpl_root_data));
+
+ /* set up root nodes special ser_osz to reflect overhead of preamble */
+ root->ser_osz = sizeof(uint32_t); /* tpl leading length */
+ root->ser_osz += strlen(fmt) + 1; /* fmt + NUL-terminator */
+ root->ser_osz += 4; /* 'tpl' magic prefix + flags byte */
+
+ parent=root;
+
+ c=fmt;
+ while (*c != '\0') {
+ switch (*c) {
+ case 'c':
+ case 'i':
+ case 'u':
+ case 'j':
+ case 'v':
+ case 'I':
+ case 'U':
+ case 'f':
+ if (*c=='c') t=TPL_TYPE_BYTE;
+ else if (*c=='i') t=TPL_TYPE_INT32;
+ else if (*c=='u') t=TPL_TYPE_UINT32;
+ else if (*c=='j') t=TPL_TYPE_INT16;
+ else if (*c=='v') t=TPL_TYPE_UINT16;
+ else if (*c=='I') t=TPL_TYPE_INT64;
+ else if (*c=='U') t=TPL_TYPE_UINT64;
+ else if (*c=='f') t=TPL_TYPE_DOUBLE;
+
+ if (expect_lparen) goto fail;
+ n = tpl_node_new(parent);
+ n->type = t;
+ if (in_structure) {
+ if (ordinal == 1) {
+ /* for S(...)# iteration. Apply any changes to case 's' too!!! */
+ iter_start_node = n;
+ struct_widest_node = n;
+ }
+ if (tpl_types[n->type].sz > tpl_types[struct_widest_node->type].sz) {
+ struct_widest_node = n;
+ }
+ n->addr = calc_field_addr(parent,n->type,struct_addr,ordinal++);
+ } else n->addr = (void*)va_arg(ap,void*);
+ n->data = tpl_hook.malloc(tpl_types[t].sz);
+ if (!n->data) fatal_oom();
+ if (n->parent->type == TPL_TYPE_ARY)
+ ((tpl_atyp*)(n->parent->data))->sz += tpl_types[t].sz;
+ DL_ADD(parent->children,n);
+ break;
+ case 's':
+ if (expect_lparen) goto fail;
+ n = tpl_node_new(parent);
+ n->type = TPL_TYPE_STR;
+ if (in_structure) {
+ if (ordinal == 1) {
+ iter_start_node = n; /* for S(...)# iteration */
+ struct_widest_node = n;
+ }
+ if (tpl_types[n->type].sz > tpl_types[struct_widest_node->type].sz) {
+ struct_widest_node = n;
+ }
+ n->addr = calc_field_addr(parent,n->type,struct_addr,ordinal++);
+ } else n->addr = (void*)va_arg(ap,void*);
+ n->data = tpl_hook.malloc(sizeof(char*));
+ if (!n->data) fatal_oom();
+ *(char**)(n->data) = NULL;
+ if (n->parent->type == TPL_TYPE_ARY)
+ ((tpl_atyp*)(n->parent->data))->sz += sizeof(void*);
+ DL_ADD(parent->children,n);
+ break;
+ case '#':
+ /* apply a 'num' to preceding atom */
+ if (!parent->children) goto fail;
+ preceding = parent->children->prev; /* first child's prev is 'last child'*/
+ t = preceding->type;
+ applies_to_struct = (*(c-1) == ')') ? 1 : 0;
+ if (!applies_to_struct) {
+ if (!(t == TPL_TYPE_BYTE || t == TPL_TYPE_INT32 ||
+ t == TPL_TYPE_UINT32 || t == TPL_TYPE_DOUBLE ||
+ t == TPL_TYPE_UINT64 || t == TPL_TYPE_INT64 ||
+ t == TPL_TYPE_UINT16 || t == TPL_TYPE_INT16 ||
+ t == TPL_TYPE_STR )) goto fail;
+ }
+ /* count up how many contiguous # and form their product */
+ pound_prod=1;
+ num_contig_fxlens=0;
+ for(peek=c; *peek == '#'; peek++) {
+ pound_num = va_arg(ap, int);
+ if (pound_num < 1) {
+ tpl_hook.fatal("non-positive iteration count %d\n", pound_num);
+ }
+ if (num_contig_fxlens >= (sizeof(contig_fxlens)/sizeof(contig_fxlens[0]))) {
+ tpl_hook.fatal("contiguous # exceeds hardcoded limit\n");
+ }
+ contig_fxlens[num_contig_fxlens++] = pound_num;
+ pound_prod *= pound_num;
+ }
+ /* increment c to skip contiguous # so its points to last one */
+ c = peek-1;
+ /* differentiate atom-# from struct-# by noting preceding rparen */
+ if (applies_to_struct) { /* insert # node to induce looping */
+ n = tpl_node_new(parent);
+ n->type = TPL_TYPE_POUND;
+ n->num = pound_prod;
+ n->data = tpl_hook.malloc(sizeof(tpl_pound_data));
+ if (!n->data) fatal_oom();
+ pd = (tpl_pound_data*)n->data;
+ pd->inter_elt_len = inter_elt_len;
+ pd->iter_start_node = iter_start_node;
+ pd->iternum = 0;
+ DL_ADD(parent->children,n);
+ /* multiply the 'num' and data space on each atom in the structure */
+ for(np = iter_start_node; np != n; np = np->next) {
+ if (n->parent->type == TPL_TYPE_ARY) {
+ ((tpl_atyp*)(n->parent->data))->sz +=
+ tpl_types[np->type].sz * (np->num * (n->num - 1));
+ }
+ np->data = tpl_hook.realloc(np->data, tpl_types[np->type].sz *
+ np->num * n->num);
+ if (!np->data) fatal_oom();
+ memset(np->data, 0, tpl_types[np->type].sz * np->num * n->num);
+ }
+ } else { /* simple atom-# form does not require a loop */
+ preceding->num = pound_prod;
+ preceding->data = tpl_hook.realloc(preceding->data,
+ tpl_types[t].sz * preceding->num);
+ if (!preceding->data) fatal_oom();
+ memset(preceding->data,0,tpl_types[t].sz * preceding->num);
+ if (n->parent->type == TPL_TYPE_ARY) {
+ ((tpl_atyp*)(n->parent->data))->sz += tpl_types[t].sz *
+ (preceding->num-1);
+ }
+ }
+ root->ser_osz += (sizeof(uint32_t) * num_contig_fxlens);
+
+ j = ((tpl_root_data*)root->data)->num_fxlens; /* before incrementing */
+ (((tpl_root_data*)root->data)->num_fxlens) += num_contig_fxlens;
+ num_fxlens = ((tpl_root_data*)root->data)->num_fxlens; /* new value */
+ fxlens = ((tpl_root_data*)root->data)->fxlens;
+ fxlens = tpl_hook.realloc(fxlens, sizeof(int) * num_fxlens);
+ if (!fxlens) fatal_oom();
+ ((tpl_root_data*)root->data)->fxlens = fxlens;
+ for(i=0; i < num_contig_fxlens; i++) fxlens[j++] = contig_fxlens[i];
+
+ break;
+ case 'B':
+ if (expect_lparen) goto fail;
+ if (in_structure) goto fail;
+ n = tpl_node_new(parent);
+ n->type = TPL_TYPE_BIN;
+ n->addr = (tpl_bin*)va_arg(ap,void*);
+ n->data = tpl_hook.malloc(sizeof(tpl_bin*));
+ if (!n->data) fatal_oom();
+ *((tpl_bin**)n->data) = NULL;
+ if (n->parent->type == TPL_TYPE_ARY)
+ ((tpl_atyp*)(n->parent->data))->sz += sizeof(tpl_bin);
+ DL_ADD(parent->children,n);
+ break;
+ case 'A':
+ if (in_structure) goto fail;
+ n = tpl_node_new(parent);
+ n->type = TPL_TYPE_ARY;
+ DL_ADD(parent->children,n);
+ parent = n;
+ expect_lparen=1;
+ pidx = (tpl_pidx*)tpl_hook.malloc(sizeof(tpl_pidx));
+ if (!pidx) fatal_oom();
+ pidx->node = n;
+ pidx->next = NULL;
+ DL_ADD(((tpl_root_data*)(root->data))->pidx,pidx);
+ /* set up the A's tpl_atyp */
+ n->data = (tpl_atyp*)tpl_hook.malloc(sizeof(tpl_atyp));
+ if (!n->data) fatal_oom();
+ ((tpl_atyp*)(n->data))->num = 0;
+ ((tpl_atyp*)(n->data))->sz = 0;
+ ((tpl_atyp*)(n->data))->bb = NULL;
+ ((tpl_atyp*)(n->data))->bbtail = NULL;
+ ((tpl_atyp*)(n->data))->cur = NULL;
+ if (n->parent->type == TPL_TYPE_ARY)
+ ((tpl_atyp*)(n->parent->data))->sz += sizeof(void*);
+ break;
+ case 'S':
+ if (in_structure) goto fail;
+ expect_lparen=1;
+ ordinal=1; /* index upcoming atoms in S(..) */
+ in_structure=1+lparen_level; /* so we can tell where S fmt ends */
+ struct_addr = (char*)va_arg(ap,void*);
+ break;
+ case '$': /* nested structure */
+ if (!in_structure) goto fail;
+ expect_lparen=1;
+ in_nested_structure++;
+ break;
+ case ')':
+ lparen_level--;
+ if (lparen_level < 0) goto fail;
+ if (*(c-1) == '(') goto fail;
+ if (in_nested_structure) in_nested_structure--;
+ else if (in_structure && (in_structure-1 == lparen_level)) {
+ /* calculate delta between contiguous structures in array */
+ struct_next = calc_field_addr(parent, struct_widest_node->type,
+ struct_addr, ordinal++);
+ inter_elt_len = struct_next - struct_addr;
+ in_structure=0;
+ }
+ else parent = parent->parent; /* rparen ends A() type, not S() type */
+ break;
+ case '(':
+ if (!expect_lparen) goto fail;
+ expect_lparen=0;
+ lparen_level++;
+ break;
+ default:
+ tpl_hook.oops("unsupported option %c\n", *c);
+ goto fail;
+ }
+ c++;
+ }
+ if (lparen_level != 0) goto fail;
+
+ /* copy the format string, save for convenience */
+ ((tpl_root_data*)(root->data))->fmt = tpl_hook.malloc(strlen(fmt)+1);
+ if (((tpl_root_data*)(root->data))->fmt == NULL)
+ fatal_oom();
+ memcpy(((tpl_root_data*)(root->data))->fmt,fmt,strlen(fmt)+1);
+
+ return root;
+
+fail:
+ tpl_hook.oops("failed to parse %s\n", fmt);
+ tpl_free(root);
+ return NULL;
+}
+
+static int tpl_unmap_file( tpl_mmap_rec *mr) {
+
+ if ( munmap( mr->text, mr->text_sz ) == -1 ) {
+ tpl_hook.oops("Failed to munmap: %s\n", strerror(errno));
+ }
+ close(mr->fd);
+ mr->text = NULL;
+ mr->text_sz = 0;
+ return 0;
+}
+
+static void tpl_free_keep_map(tpl_node *r) {
+ int mmap_bits = (TPL_RDONLY|TPL_FILE);
+ int ufree_bits = (TPL_MEM|TPL_UFREE);
+ tpl_node *nxtc,*c;
+ int find_next_node=0,looking,i;
+ size_t sz;
+
+ /* For mmap'd files, or for 'ufree' memory images , do appropriate release */
+ if ((((tpl_root_data*)(r->data))->flags & mmap_bits) == mmap_bits) {
+ tpl_unmap_file( &((tpl_root_data*)(r->data))->mmap);
+ } else if ((((tpl_root_data*)(r->data))->flags & ufree_bits) == ufree_bits) {
+ tpl_hook.free( ((tpl_root_data*)(r->data))->mmap.text );
+ }
+
+ c = r->children;
+ if (c) {
+ while(c->type != TPL_TYPE_ROOT) { /* loop until we come back to root node */
+ switch (c->type) {
+ case TPL_TYPE_BIN:
+ /* free any binary buffer hanging from tpl_bin */
+ if ( *((tpl_bin**)(c->data)) ) {
+ if ( (*((tpl_bin**)(c->data)))->addr ) {
+ tpl_hook.free( (*((tpl_bin**)(c->data)))->addr );
+ }
+ *((tpl_bin**)c->data) = NULL; /* reset tpl_bin */
+ }
+ find_next_node=1;
+ break;
+ case TPL_TYPE_STR:
+ /* free any packed (copied) string */
+ for(i=0; i < c->num; i++) {
+ char *str = ((char**)c->data)[i];
+ if (str) {
+ tpl_hook.free(str);
+ ((char**)c->data)[i] = NULL;
+ }
+ }
+ find_next_node=1;
+ break;
+ case TPL_TYPE_INT32:
+ case TPL_TYPE_UINT32:
+ case TPL_TYPE_INT64:
+ case TPL_TYPE_UINT64:
+ case TPL_TYPE_BYTE:
+ case TPL_TYPE_DOUBLE:
+ case TPL_TYPE_INT16:
+ case TPL_TYPE_UINT16:
+ case TPL_TYPE_POUND:
+ find_next_node=1;
+ break;
+ case TPL_TYPE_ARY:
+ c->ser_osz = 0; /* zero out the serialization output size */
+
+ sz = ((tpl_atyp*)(c->data))->sz; /* save sz to use below */
+ tpl_free_atyp(c,c->data);
+
+ /* make new atyp */
+ c->data = (tpl_atyp*)tpl_hook.malloc(sizeof(tpl_atyp));
+ if (!c->data) fatal_oom();
+ ((tpl_atyp*)(c->data))->num = 0;
+ ((tpl_atyp*)(c->data))->sz = sz; /* restore bb datum sz */
+ ((tpl_atyp*)(c->data))->bb = NULL;
+ ((tpl_atyp*)(c->data))->bbtail = NULL;
+ ((tpl_atyp*)(c->data))->cur = NULL;
+
+ c = c->children;
+ break;
+ default:
+ tpl_hook.fatal("unsupported format character\n");
+ break;
+ }
+
+ if (find_next_node) {
+ find_next_node=0;
+ looking=1;
+ while(looking) {
+ if (c->next) {
+ nxtc=c->next;
+ c=nxtc;
+ looking=0;
+ } else {
+ if (c->type == TPL_TYPE_ROOT) break; /* root node */
+ else {
+ nxtc=c->parent;
+ c=nxtc;
+ }
+ }
+ }
+ }
+ }
+ }
+
+ ((tpl_root_data*)(r->data))->flags = 0; /* reset flags */
+}
+
+TPL_API void tpl_free(tpl_node *r) {
+ int mmap_bits = (TPL_RDONLY|TPL_FILE);
+ int ufree_bits = (TPL_MEM|TPL_UFREE);
+ tpl_node *nxtc,*c;
+ int find_next_node=0,looking,i;
+ tpl_pidx *pidx,*pidx_nxt;
+
+ /* For mmap'd files, or for 'ufree' memory images , do appropriate release */
+ if ((((tpl_root_data*)(r->data))->flags & mmap_bits) == mmap_bits) {
+ tpl_unmap_file( &((tpl_root_data*)(r->data))->mmap);
+ } else if ((((tpl_root_data*)(r->data))->flags & ufree_bits) == ufree_bits) {
+ tpl_hook.free( ((tpl_root_data*)(r->data))->mmap.text );
+ }
+
+ c = r->children;
+ if (c) {
+ while(c->type != TPL_TYPE_ROOT) { /* loop until we come back to root node */
+ switch (c->type) {
+ case TPL_TYPE_BIN:
+ /* free any binary buffer hanging from tpl_bin */
+ if ( *((tpl_bin**)(c->data)) ) {
+ if ( (*((tpl_bin**)(c->data)))->sz != 0 ) {
+ tpl_hook.free( (*((tpl_bin**)(c->data)))->addr );
+ }
+ tpl_hook.free(*((tpl_bin**)c->data)); /* free tpl_bin */
+ }
+ tpl_hook.free(c->data); /* free tpl_bin* */
+ find_next_node=1;
+ break;
+ case TPL_TYPE_STR:
+ /* free any packed (copied) string */
+ for(i=0; i < c->num; i++) {
+ char *str = ((char**)c->data)[i];
+ if (str) {
+ tpl_hook.free(str);
+ ((char**)c->data)[i] = NULL;
+ }
+ }
+ tpl_hook.free(c->data);
+ find_next_node=1;
+ break;
+ case TPL_TYPE_INT32:
+ case TPL_TYPE_UINT32:
+ case TPL_TYPE_INT64:
+ case TPL_TYPE_UINT64:
+ case TPL_TYPE_BYTE:
+ case TPL_TYPE_DOUBLE:
+ case TPL_TYPE_INT16:
+ case TPL_TYPE_UINT16:
+ case TPL_TYPE_POUND:
+ tpl_hook.free(c->data);
+ find_next_node=1;
+ break;
+ case TPL_TYPE_ARY:
+ tpl_free_atyp(c,c->data);
+ if (c->children) c = c->children; /* normal case */
+ else find_next_node=1; /* edge case, handle bad format A() */
+ break;
+ default:
+ tpl_hook.fatal("unsupported format character\n");
+ break;
+ }
+
+ if (find_next_node) {
+ find_next_node=0;
+ looking=1;
+ while(looking) {
+ if (c->next) {
+ nxtc=c->next;
+ tpl_hook.free(c);
+ c=nxtc;
+ looking=0;
+ } else {
+ if (c->type == TPL_TYPE_ROOT) break; /* root node */
+ else {
+ nxtc=c->parent;
+ tpl_hook.free(c);
+ c=nxtc;
+ }
+ }
+ }
+ }
+ }
+ }
+
+ /* free root */
+ for(pidx=((tpl_root_data*)(r->data))->pidx; pidx; pidx=pidx_nxt) {
+ pidx_nxt = pidx->next;
+ tpl_hook.free(pidx);
+ }
+ tpl_hook.free(((tpl_root_data*)(r->data))->fmt);
+ if (((tpl_root_data*)(r->data))->num_fxlens > 0) {
+ tpl_hook.free(((tpl_root_data*)(r->data))->fxlens);
+ }
+ tpl_hook.free(r->data); /* tpl_root_data */
+ tpl_hook.free(r);
+}
+
+
+/* Find the i'th packable ('A' node) */
+static tpl_node *tpl_find_i(tpl_node *n, int i) {
+ int j=0;
+ tpl_pidx *pidx;
+ if (n->type != TPL_TYPE_ROOT) return NULL;
+ if (i == 0) return n; /* packable 0 is root */
+ for(pidx=((tpl_root_data*)(n->data))->pidx; pidx; pidx=pidx->next) {
+ if (++j == i) return pidx->node;
+ }
+ return NULL;
+}
+
+static void *tpl_cpv(void *datav, void *data, size_t sz) {
+ if (sz>0) memcpy(datav,data,sz);
+ return (void*)((uintptr_t)datav + sz);
+}
+
+static void *tpl_extend_backbone(tpl_node *n) {
+ tpl_backbone *bb;
+ bb = (tpl_backbone*)tpl_hook.malloc(sizeof(tpl_backbone) +
+ ((tpl_atyp*)(n->data))->sz ); /* datum hangs on coattails of bb */
+ if (!bb) fatal_oom();
+#if __STDC_VERSION__ < 199901
+ bb->data = (char*)((uintptr_t)bb + sizeof(tpl_backbone));
+#endif
+ memset(bb->data,0,((tpl_atyp*)(n->data))->sz);
+ bb->next = NULL;
+ /* Add the new backbone to the tail, also setting head if necessary */
+ if (((tpl_atyp*)(n->data))->bb == NULL) {
+ ((tpl_atyp*)(n->data))->bb = bb;
+ ((tpl_atyp*)(n->data))->bbtail = bb;
+ } else {
+ ((tpl_atyp*)(n->data))->bbtail->next = bb;
+ ((tpl_atyp*)(n->data))->bbtail = bb;
+ }
+
+ ((tpl_atyp*)(n->data))->num++;
+ return bb->data;
+}
+
+/* Get the format string corresponding to a given tpl (root node) */
+static char *tpl_fmt(tpl_node *r) {
+ return ((tpl_root_data*)(r->data))->fmt;
+}
+
+/* Get the fmt # lengths as a contiguous buffer of ints (length num_fxlens) */
+static int *tpl_fxlens(tpl_node *r, int *num_fxlens) {
+ *num_fxlens = ((tpl_root_data*)(r->data))->num_fxlens;
+ return ((tpl_root_data*)(r->data))->fxlens;
+}
+
+/* called when serializing an 'A' type node into a buffer which has
+ * already been set up with the proper space. The backbone is walked
+ * which was obtained from the tpl_atyp header passed in.
+ */
+static void *tpl_dump_atyp(tpl_node *n, tpl_atyp* at, void *dv) {
+ tpl_backbone *bb;
+ tpl_node *c;
+ void *datav;
+ uint32_t slen;
+ tpl_bin *binp;
+ char *strp;
+ tpl_atyp *atypp;
+ tpl_pound_data *pd;
+ int i;
+ size_t itermax;
+
+ /* handle 'A' nodes */
+ dv = tpl_cpv(dv,&at->num,sizeof(uint32_t)); /* array len */
+ for(bb=at->bb; bb; bb=bb->next) {
+ datav = bb->data;
+ c=n->children;
+ while(c) {
+ switch (c->type) {
+ case TPL_TYPE_BYTE:
+ case TPL_TYPE_DOUBLE:
+ case TPL_TYPE_INT32:
+ case TPL_TYPE_UINT32:
+ case TPL_TYPE_INT64:
+ case TPL_TYPE_UINT64:
+ case TPL_TYPE_INT16:
+ case TPL_TYPE_UINT16:
+ dv = tpl_cpv(dv,datav,tpl_types[c->type].sz * c->num);
+ datav = (void*)((uintptr_t)datav + tpl_types[c->type].sz * c->num);
+ break;
+ case TPL_TYPE_BIN:
+ /* dump the buffer length followed by the buffer */
+ memcpy(&binp,datav,sizeof(tpl_bin*)); /* cp to aligned */
+ slen = binp->sz;
+ dv = tpl_cpv(dv,&slen,sizeof(uint32_t));
+ dv = tpl_cpv(dv,binp->addr,slen);
+ datav = (void*)((uintptr_t)datav + sizeof(tpl_bin*));
+ break;
+ case TPL_TYPE_STR:
+ /* dump the string length followed by the string */
+ for(i=0; i < c->num; i++) {
+ memcpy(&strp,datav,sizeof(char*)); /* cp to aligned */
+ slen = strp ? (strlen(strp)+1) : 0;
+ dv = tpl_cpv(dv,&slen,sizeof(uint32_t));
+ if (slen > 1) dv = tpl_cpv(dv,strp,slen-1);
+ datav = (void*)((uintptr_t)datav + sizeof(char*));
+ }
+ break;
+ case TPL_TYPE_ARY:
+ memcpy(&atypp,datav,sizeof(tpl_atyp*)); /* cp to aligned */
+ dv = tpl_dump_atyp(c,atypp,dv);
+ datav = (void*)((uintptr_t)datav + sizeof(void*));
+ break;
+ case TPL_TYPE_POUND:
+ /* iterate over the preceding nodes */
+ pd = (tpl_pound_data*)c->data;
+ itermax = c->num;
+ if (++(pd->iternum) < itermax) {
+ c = pd->iter_start_node;
+ continue;
+ } else { /* loop complete. */
+ pd->iternum = 0;
+ }
+ break;
+ default:
+ tpl_hook.fatal("unsupported format character\n");
+ break;
+ }
+ c=c->next;
+ }
+ }
+ return dv;
+}
+
+/* figure the serialization output size needed for tpl whose root is n*/
+static size_t tpl_ser_osz(tpl_node *n) {
+ tpl_node *c, *np;
+ size_t sz, itermax;
+ tpl_bin *binp;
+ char *strp;
+ tpl_pound_data *pd;
+ int i;
+
+ /* handle the root node ONLY (subtree's ser_osz have been bubbled-up) */
+ if (n->type != TPL_TYPE_ROOT) {
+ tpl_hook.fatal("internal error: tpl_ser_osz on non-root node\n");
+ }
+
+ sz = n->ser_osz; /* start with fixed overhead, already stored */
+ c=n->children;
+ while (c) {
+ switch (c->type) {
+ case TPL_TYPE_BYTE:
+ case TPL_TYPE_DOUBLE:
+ case TPL_TYPE_INT32:
+ case TPL_TYPE_UINT32:
+ case TPL_TYPE_INT64:
+ case TPL_TYPE_UINT64:
+ case TPL_TYPE_INT16:
+ case TPL_TYPE_UINT16:
+ sz += tpl_types[c->type].sz * c->num;
+ break;
+ case TPL_TYPE_BIN:
+ sz += sizeof(uint32_t); /* binary buf len */
+ memcpy(&binp,c->data,sizeof(tpl_bin*)); /* cp to aligned */
+ sz += binp->sz;
+ break;
+ case TPL_TYPE_STR:
+ for(i=0; i < c->num; i++) {
+ sz += sizeof(uint32_t); /* string len */
+ memcpy(&strp,&((char**)c->data)[i],sizeof(char*)); /* cp to aligned */
+ sz += strp ? strlen(strp) : 0;
+ }
+ break;
+ case TPL_TYPE_ARY:
+ sz += sizeof(uint32_t); /* array len */
+ sz += c->ser_osz; /* bubbled-up child array ser_osz */
+ break;
+ case TPL_TYPE_POUND:
+ /* iterate over the preceding nodes */
+ itermax = c->num;
+ pd = (tpl_pound_data*)c->data;
+ if (++(pd->iternum) < itermax) {
+ for(np=pd->iter_start_node; np != c; np = np->next) {
+ np->data = (char*)(np->data) +
+ (tpl_types[np->type].sz * np->num);
+ }
+ c = pd->iter_start_node;
+ continue;
+ } else { /* loop complete. */
+ pd->iternum = 0;
+ for(np=pd->iter_start_node; np != c; np = np->next) {
+ np->data = (char*)(np->data) - ((itermax-1) *
+ tpl_types[np->type].sz *
+ np->num);
+ }
+ }
+ break;
+ default:
+ tpl_hook.fatal("unsupported format character\n");
+ break;
+ }
+ c=c->next;
+ }
+ return sz;
+}
+
+
+TPL_API int tpl_dump(tpl_node *r, int mode, ...) {
+ va_list ap;
+ char *filename, *bufv;
+ void **addr_out,*buf, *pa_addr;
+ int fd,rc=0;
+ size_t sz,*sz_out, pa_sz;
+
+ if (((tpl_root_data*)(r->data))->flags & TPL_RDONLY) { /* unusual */
+ tpl_hook.oops("error: tpl_dump called for a loaded tpl\n");
+ return -1;
+ }
+
+ sz = tpl_ser_osz(r); /* compute the size needed to serialize */
+
+ va_start(ap,mode);
+ if (mode & TPL_FILE) {
+ filename = va_arg(ap,char*);
+ fd = tpl_mmap_output_file(filename, sz, &buf);
+ if (fd == -1) rc = -1;
+ else {
+ rc = tpl_dump_to_mem(r,buf,sz);
+ if (msync(buf,sz,MS_SYNC) == -1) {
+ tpl_hook.oops("msync failed on fd %d: %s\n", fd, strerror(errno));
+ }
+ if (munmap(buf, sz) == -1) {
+ tpl_hook.oops("munmap failed on fd %d: %s\n", fd, strerror(errno));
+ }
+ close(fd);
+ }
+ } else if (mode & TPL_FD) {
+ fd = va_arg(ap, int);
+ if ( (buf = tpl_hook.malloc(sz)) == NULL) fatal_oom();
+ tpl_dump_to_mem(r,buf,sz);
+ bufv = buf;
+ do {
+ rc = write(fd,bufv,sz);
+ if (rc > 0) {
+ sz -= rc;
+ bufv += rc;
+ } else if (rc == -1) {
+ if (errno == EINTR || errno == EAGAIN) continue;
+ tpl_hook.oops("error writing to fd %d: %s\n", fd, strerror(errno));
+ free(buf);
+ return -1;
+ }
+ } while (sz > 0);
+ free(buf);
+ rc = 0;
+ } else if (mode & TPL_MEM) {
+ if (mode & TPL_PREALLOCD) { /* caller allocated */
+ pa_addr = (void*)va_arg(ap, void*);
+ pa_sz = va_arg(ap, size_t);
+ if (pa_sz < sz) {
+ tpl_hook.oops("tpl_dump: buffer too small, need %d bytes\n", sz);
+ return -1;
+ }
+ rc=tpl_dump_to_mem(r,pa_addr,sz);
+ } else { /* we allocate */
+ addr_out = (void**)va_arg(ap, void*);
+ sz_out = va_arg(ap, size_t*);
+ if ( (buf = tpl_hook.malloc(sz)) == NULL) fatal_oom();
+ *sz_out = sz;
+ *addr_out = buf;
+ rc=tpl_dump_to_mem(r,buf,sz);
+ }
+ } else if (mode & TPL_GETSIZE) {
+ sz_out = va_arg(ap, size_t*);
+ *sz_out = sz;
+ } else {
+ tpl_hook.oops("unsupported tpl_dump mode %d\n", mode);
+ rc=-1;
+ }
+ va_end(ap);
+ return rc;
+}
+
+/* This function expects the caller to have set up a memory buffer of
+ * adequate size to hold the serialized tpl. The sz parameter must be
+ * the result of tpl_ser_osz(r).
+ */
+static int tpl_dump_to_mem(tpl_node *r,void *addr,size_t sz) {
+ uint32_t slen, sz32;
+ int *fxlens, num_fxlens, i;
+ void *dv;
+ char *fmt,flags;
+ tpl_node *c, *np;
+ tpl_pound_data *pd;
+ size_t itermax;
+
+ fmt = tpl_fmt(r);
+ flags = 0;
+ if (tpl_cpu_bigendian()) flags |= TPL_FL_BIGENDIAN;
+ if (strchr(fmt,'s')) flags |= TPL_FL_NULLSTRINGS;
+ sz32 = sz;
+
+ dv = addr;
+ dv = tpl_cpv(dv,TPL_MAGIC,3); /* copy tpl magic prefix */
+ dv = tpl_cpv(dv,&flags,1); /* copy flags byte */
+ dv = tpl_cpv(dv,&sz32,sizeof(uint32_t));/* overall length (inclusive) */
+ dv = tpl_cpv(dv,fmt,strlen(fmt)+1); /* copy format with NUL-term */
+ fxlens = tpl_fxlens(r,&num_fxlens);
+ dv = tpl_cpv(dv,fxlens,num_fxlens*sizeof(uint32_t));/* fmt # lengths */
+
+ /* serialize the tpl content, iterating over direct children of root */
+ c = r->children;
+ while (c) {
+ switch (c->type) {
+ case TPL_TYPE_BYTE:
+ case TPL_TYPE_DOUBLE:
+ case TPL_TYPE_INT32:
+ case TPL_TYPE_UINT32:
+ case TPL_TYPE_INT64:
+ case TPL_TYPE_UINT64:
+ case TPL_TYPE_INT16:
+ case TPL_TYPE_UINT16:
+ dv = tpl_cpv(dv,c->data,tpl_types[c->type].sz * c->num);
+ break;
+ case TPL_TYPE_BIN:
+ slen = (*(tpl_bin**)(c->data))->sz;
+ dv = tpl_cpv(dv,&slen,sizeof(uint32_t)); /* buffer len */
+ dv = tpl_cpv(dv,(*(tpl_bin**)(c->data))->addr,slen); /* buf */
+ break;
+ case TPL_TYPE_STR:
+ for(i=0; i < c->num; i++) {
+ char *str = ((char**)c->data)[i];
+ slen = str ? strlen(str)+1 : 0;
+ dv = tpl_cpv(dv,&slen,sizeof(uint32_t)); /* string len */
+ if (slen>1) dv = tpl_cpv(dv,str,slen-1); /*string*/
+ }
+ break;
+ case TPL_TYPE_ARY:
+ dv = tpl_dump_atyp(c,(tpl_atyp*)c->data,dv);
+ break;
+ case TPL_TYPE_POUND:
+ pd = (tpl_pound_data*)c->data;
+ itermax = c->num;
+ if (++(pd->iternum) < itermax) {
+
+ /* in start or midst of loop. advance data pointers. */
+ for(np=pd->iter_start_node; np != c; np = np->next) {
+ np->data = (char*)(np->data) +
+ (tpl_types[np->type].sz * np->num);
+ }
+ /* do next iteration */
+ c = pd->iter_start_node;
+ continue;
+
+ } else { /* loop complete. */
+
+ /* reset iteration index and addr/data pointers. */
+ pd->iternum = 0;
+ for(np=pd->iter_start_node; np != c; np = np->next) {
+ np->data = (char*)(np->data) - ((itermax-1) *
+ tpl_types[np->type].sz *
+ np->num);
+ }
+
+ }
+ break;
+ default:
+ tpl_hook.fatal("unsupported format character\n");
+ break;
+ }
+ c = c->next;
+ }
+
+ return 0;
+}
+
+static int tpl_cpu_bigendian() {
+ unsigned i = 1;
+ char *c;
+ c = (char*)&i;
+ return (c[0] == 1 ? 0 : 1);
+}
+
+
+/*
+ * algorithm for sanity-checking a tpl image:
+ * scan the tpl whilst not exceeding the buffer size (bufsz) ,
+ * formulating a calculated (expected) size of the tpl based
+ * on walking its data. When calcsize has been calculated it
+ * should exactly match the buffer size (bufsz) and the internal
+ * recorded size (intlsz)
+ */
+static int tpl_sanity(tpl_node *r, int excess_ok) {
+ uint32_t intlsz;
+ int found_nul=0,rc, octothorpes=0, num_fxlens, *fxlens, flen;
+ void *d, *dv;
+ char intlflags, *fmt, c, *mapfmt;
+ size_t bufsz, serlen;
+
+ d = ((tpl_root_data*)(r->data))->mmap.text;
+ bufsz = ((tpl_root_data*)(r->data))->mmap.text_sz;
+
+ dv = d;
+ if (bufsz < (4 + sizeof(uint32_t) + 1)) return ERR_NOT_MINSIZE; /* min sz: magic+flags+len+nul */
+ if (memcmp(dv,TPL_MAGIC, 3) != 0) return ERR_MAGIC_MISMATCH; /* missing tpl magic prefix */
+ if (tpl_needs_endian_swap(dv)) ((tpl_root_data*)(r->data))->flags |= TPL_XENDIAN;
+ dv = (void*)((uintptr_t)dv + 3);
+ memcpy(&intlflags,dv,sizeof(char)); /* extract flags */
+ if (intlflags & ~TPL_SUPPORTED_BITFLAGS) return ERR_UNSUPPORTED_FLAGS;
+ /* TPL1.3 stores strings with a "length+1" prefix to discern NULL strings from
+ empty strings from non-empty strings; TPL1.2 only handled the latter two.
+ So we need to be mindful of which string format we're reading from. */
+ if (!(intlflags & TPL_FL_NULLSTRINGS)) {
+ ((tpl_root_data*)(r->data))->flags |= TPL_OLD_STRING_FMT;
+ }
+ dv = (void*)((uintptr_t)dv + 1);
+ memcpy(&intlsz,dv,sizeof(uint32_t)); /* extract internal size */
+ if (((tpl_root_data*)(r->data))->flags & TPL_XENDIAN) tpl_byteswap(&intlsz, sizeof(uint32_t));
+ if (!excess_ok && (intlsz != bufsz)) return ERR_INCONSISTENT_SZ; /* inconsisent buffer/internal size */
+ dv = (void*)((uintptr_t)dv + sizeof(uint32_t));
+
+ /* dv points to the start of the format string. Look for nul w/in buf sz */
+ fmt = (char*)dv;
+ while ((uintptr_t)dv-(uintptr_t)d < bufsz && !found_nul) {
+ if ( (c = *(char*)dv) != '\0') {
+ if (strchr(tpl_fmt_chars,c) == NULL)
+ return ERR_FMT_INVALID; /* invalid char in format string */
+ if ( (c = *(char*)dv) == '#') octothorpes++;
+ dv = (void*)((uintptr_t)dv + 1);
+ }
+ else found_nul = 1;
+ }
+ if (!found_nul) return ERR_FMT_MISSING_NUL; /* runaway format string */
+ dv = (void*)((uintptr_t)dv + 1); /* advance to octothorpe lengths buffer */
+
+ /* compare the map format to the format of this tpl image */
+ mapfmt = tpl_fmt(r);
+ rc = strcmp(mapfmt,fmt);
+ if (rc != 0) return ERR_FMT_MISMATCH;
+
+ /* compare octothorpe lengths in image to the mapped values */
+ if ((((uintptr_t)dv + (octothorpes * 4)) - (uintptr_t)d) > bufsz) return ERR_INCONSISTENT_SZ4;
+ fxlens = tpl_fxlens(r,&num_fxlens); /* mapped fxlens */
+ while(num_fxlens--) {
+ memcpy(&flen,dv,sizeof(uint32_t)); /* stored flen */
+ if (((tpl_root_data*)(r->data))->flags & TPL_XENDIAN) tpl_byteswap(&flen, sizeof(uint32_t));
+ if (flen != *fxlens) return ERR_FLEN_MISMATCH;
+ dv = (void*)((uintptr_t)dv + sizeof(uint32_t));
+ fxlens++;
+ }
+
+ /* dv now points to beginning of data */
+ rc = tpl_serlen(r,r,dv,&serlen); /* get computed serlen of data part */
+ if (rc == -1) return ERR_INCONSISTENT_SZ2; /* internal inconsistency in tpl image */
+ serlen += ((uintptr_t)dv - (uintptr_t)d); /* add back serlen of preamble part */
+ if (excess_ok && (bufsz < serlen)) return ERR_INCONSISTENT_SZ3;
+ if (!excess_ok && (serlen != bufsz)) return ERR_INCONSISTENT_SZ3; /* buffer/internal sz exceeds serlen */
+ return 0;
+}
+
+static void *tpl_find_data_start(void *d) {
+ int octothorpes=0;
+ d = (void*)((uintptr_t)d + 4); /* skip TPL_MAGIC and flags byte */
+ d = (void*)((uintptr_t)d + 4); /* skip int32 overall len */
+ while(*(char*)d != '\0') {
+ if (*(char*)d == '#') octothorpes++;
+ d = (void*)((uintptr_t)d + 1);
+ }
+ d = (void*)((uintptr_t)d + 1); /* skip NUL */
+ d = (void*)((uintptr_t)d + (octothorpes * sizeof(uint32_t))); /* skip # array lens */
+ return d;
+}
+
+static int tpl_needs_endian_swap(void *d) {
+ char *c;
+ int cpu_is_bigendian;
+ c = (char*)d;
+ cpu_is_bigendian = tpl_cpu_bigendian();
+ return ((c[3] & TPL_FL_BIGENDIAN) == cpu_is_bigendian) ? 0 : 1;
+}
+
+static size_t tpl_size_for(char c) {
+ int i;
+ for(i=0; i < sizeof(tpl_types)/sizeof(tpl_types[0]); i++) {
+ if (tpl_types[i].c == c) return tpl_types[i].sz;
+ }
+ return 0;
+}
+
+TPL_API char* tpl_peek(int mode, ...) {
+ va_list ap;
+ int xendian=0,found_nul=0,old_string_format=0;
+ char *filename=NULL, *datapeek_f=NULL, *datapeek_c, *datapeek_s;
+ void *addr=NULL, *dv, *datapeek_p=NULL;
+ size_t sz=0, fmt_len, first_atom, num_fxlens=0;
+ uint32_t datapeek_ssz, datapeek_csz, datapeek_flen;
+ tpl_mmap_rec mr = {0,NULL,0};
+ char *fmt,*fmt_cpy=NULL,c;
+ uint32_t intlsz, **fxlens=NULL, *num_fxlens_out=NULL, *fxlensv;
+
+ va_start(ap,mode);
+ if ((mode & TPL_FXLENS) && (mode & TPL_DATAPEEK)) {
+ tpl_hook.oops("TPL_FXLENS and TPL_DATAPEEK mutually exclusive\n");
+ goto fail;
+ }
+ if (mode & TPL_FILE) filename = va_arg(ap,char *);
+ else if (mode & TPL_MEM) {
+ addr = va_arg(ap,void *);
+ sz = va_arg(ap,size_t);
+ } else {
+ tpl_hook.oops("unsupported tpl_peek mode %d\n", mode);
+ goto fail;
+ }
+ if (mode & TPL_DATAPEEK) {
+ datapeek_f = va_arg(ap, char*);
+ }
+ if (mode & TPL_FXLENS) {
+ num_fxlens_out = va_arg(ap,uint32_t *);
+ fxlens = va_arg(ap,uint32_t **);
+ *num_fxlens_out = 0;
+ *fxlens = NULL;
+ }
+
+ if (mode & TPL_FILE) {
+ if (tpl_mmap_file(filename, &mr) != 0) {
+ tpl_hook.oops("tpl_peek failed for file %s\n", filename);
+ goto fail;
+ }
+ addr = mr.text;
+ sz = mr.text_sz;
+ }
+
+ dv = addr;
+ if (sz < (4 + sizeof(uint32_t) + 1)) goto fail; /* min sz */
+ if (memcmp(dv,TPL_MAGIC, 3) != 0) goto fail; /* missing tpl magic prefix */
+ if (tpl_needs_endian_swap(dv)) xendian=1;
+ if ((((char*)dv)[3] & TPL_FL_NULLSTRINGS)==0) old_string_format=1;
+ dv = (void*)((uintptr_t)dv + 4);
+ memcpy(&intlsz,dv,sizeof(uint32_t)); /* extract internal size */
+ if (xendian) tpl_byteswap(&intlsz, sizeof(uint32_t));
+ if (intlsz != sz) goto fail; /* inconsisent buffer/internal size */
+ dv = (void*)((uintptr_t)dv + sizeof(uint32_t));
+
+ /* dv points to the start of the format string. Look for nul w/in buf sz */
+ fmt = (char*)dv;
+ while ((uintptr_t)dv-(uintptr_t)addr < sz && !found_nul) {
+ if ( (c = *(char*)dv) == '\0') {
+ found_nul = 1;
+ } else if (c == '#') {
+ num_fxlens++;
+ }
+ dv = (void*)((uintptr_t)dv + 1);
+ }
+ if (!found_nul) goto fail; /* runaway format string */
+ fmt_len = (char*)dv - fmt; /* include space for \0 */
+ fmt_cpy = tpl_hook.malloc(fmt_len);
+ if (fmt_cpy == NULL) {
+ fatal_oom();
+ }
+ memcpy(fmt_cpy, fmt, fmt_len);
+
+ /* retrieve the octothorpic lengths if requested */
+ if (num_fxlens > 0) {
+ if (sz < ((uintptr_t)dv + (num_fxlens * sizeof(uint32_t)) - (uintptr_t)addr)) {
+ goto fail;
+ }
+ }
+ if ((mode & TPL_FXLENS) && (num_fxlens > 0)) {
+ *fxlens = tpl_hook.malloc(num_fxlens * sizeof(uint32_t));
+ if (*fxlens == NULL) tpl_hook.fatal("out of memory");
+ *num_fxlens_out = num_fxlens;
+ fxlensv = *fxlens;
+ while(num_fxlens--) {
+ memcpy(fxlensv,dv,sizeof(uint32_t));
+ if (xendian) tpl_byteswap(fxlensv, sizeof(uint32_t));
+ dv = (void*)((uintptr_t)dv + sizeof(uint32_t));
+ fxlensv++;
+ }
+ }
+ /* if caller requested, peek into the specified data elements */
+ if (mode & TPL_DATAPEEK) {
+
+ first_atom = strspn(fmt, "S()"); /* skip any leading S() */
+
+ datapeek_flen = strlen(datapeek_f);
+ if (strspn(datapeek_f, tpl_datapeek_ok_chars) < datapeek_flen) {
+ tpl_hook.oops("invalid TPL_DATAPEEK format: %s\n", datapeek_f);
+ tpl_hook.free(fmt_cpy); fmt_cpy = NULL; /* fail */
+ goto fail;
+ }
+
+ if (strncmp( &fmt[first_atom], datapeek_f, datapeek_flen) != 0) {
+ tpl_hook.oops("TPL_DATAPEEK format mismatches tpl iamge\n");
+ tpl_hook.free(fmt_cpy); fmt_cpy = NULL; /* fail */
+ goto fail;
+ }
+
+ /* advance to data start, then copy out requested elements */
+ dv = (void*)((uintptr_t)dv + (num_fxlens * sizeof(uint32_t)));
+ for(datapeek_c = datapeek_f; *datapeek_c != '\0'; datapeek_c++) {
+ datapeek_p = va_arg(ap, void*);
+ if (*datapeek_c == 's') { /* special handling for strings */
+ if ((uintptr_t)dv-(uintptr_t)addr + sizeof(uint32_t) > sz) {
+ tpl_hook.oops("tpl_peek: tpl has insufficient length\n");
+ tpl_hook.free(fmt_cpy); fmt_cpy = NULL; /* fail */
+ goto fail;
+ }
+ memcpy(&datapeek_ssz,dv,sizeof(uint32_t)); /* get slen */
+ if (xendian) tpl_byteswap(&datapeek_ssz, sizeof(uint32_t));
+ if (old_string_format) datapeek_ssz++;
+ dv = (void*)((uintptr_t)dv + sizeof(uint32_t)); /* adv. to str */
+ if (datapeek_ssz == 0) datapeek_s = NULL;
+ else {
+ if ((uintptr_t)dv-(uintptr_t)addr + datapeek_ssz-1 > sz) {
+ tpl_hook.oops("tpl_peek: tpl has insufficient length\n");
+ tpl_hook.free(fmt_cpy); fmt_cpy = NULL; /* fail */
+ goto fail;
+ }
+ datapeek_s = tpl_hook.malloc(datapeek_ssz);
+ if (datapeek_s == NULL) fatal_oom();
+ memcpy(datapeek_s, dv, datapeek_ssz-1);
+ datapeek_s[datapeek_ssz-1] = '\0';
+ dv = (void*)((uintptr_t)dv + datapeek_ssz-1);
+ }
+ *(char**)datapeek_p = datapeek_s;
+ } else {
+ datapeek_csz = tpl_size_for(*datapeek_c);
+ if ((uintptr_t)dv-(uintptr_t)addr + datapeek_csz > sz) {
+ tpl_hook.oops("tpl_peek: tpl has insufficient length\n");
+ tpl_hook.free(fmt_cpy); fmt_cpy = NULL; /* fail */
+ goto fail;
+ }
+ memcpy(datapeek_p, dv, datapeek_csz);
+ if (xendian) tpl_byteswap(datapeek_p, datapeek_csz);
+ dv = (void*)((uintptr_t)dv + datapeek_csz);
+ }
+ }
+ }
+
+fail:
+ va_end(ap);
+ if ((mode & TPL_FILE) && mr.text != NULL) tpl_unmap_file( &mr );
+ return fmt_cpy;
+}
+
+/* tpl_jot(TPL_FILE, "file.tpl", "si", &s, &i); */
+/* tpl_jot(TPL_MEM, &buf, &sz, "si", &s, &i); */
+/* tpl_jot(TPL_FD, fd, "si", &s, &i); */
+TPL_API int tpl_jot(int mode, ...) {
+ va_list ap;
+ char *filename, *fmt;
+ size_t *sz;
+ int fd, rc=0;
+ void **buf;
+ tpl_node *tn;
+
+ va_start(ap,mode);
+ if (mode & TPL_FILE) {
+ filename = va_arg(ap,char*);
+ fmt = va_arg(ap,char*);
+ tn = tpl_map_va(fmt, ap);
+ if (tn == NULL) { rc=-1; goto fail;}
+ tpl_pack(tn, 0);
+ rc = tpl_dump(tn, TPL_FILE, filename);
+ tpl_free(tn);
+ } else if (mode & TPL_MEM) {
+ buf = va_arg(ap,void*);
+ sz = va_arg(ap,size_t*);
+ fmt = va_arg(ap,char*);
+ tn = tpl_map_va(fmt,ap);
+ if (tn == NULL) { rc=-1; goto fail;}
+ tpl_pack(tn,0);
+ rc = tpl_dump(tn, TPL_MEM, buf, sz);
+ tpl_free(tn);
+ } else if (mode & TPL_FD) {
+ fd = va_arg(ap,int);
+ fmt = va_arg(ap,char*);
+ tn = tpl_map_va(fmt,ap);
+ if (tn == NULL) { rc=-1; goto fail;}
+ tpl_pack(tn,0);
+ rc = tpl_dump(tn, TPL_FD, fd);
+ tpl_free(tn);
+ } else {
+ tpl_hook.fatal("invalid tpl_jot mode\n");
+ }
+
+fail:
+ va_end(ap);
+ return rc;
+}
+
+TPL_API int tpl_load(tpl_node *r, int mode, ...) {
+ va_list ap;
+ int rc=0,fd=0;
+ char *filename=NULL;
+ void *addr;
+ size_t sz;
+
+ va_start(ap,mode);
+ if (mode & TPL_FILE) filename = va_arg(ap,char *);
+ else if (mode & TPL_MEM) {
+ addr = va_arg(ap,void *);
+ sz = va_arg(ap,size_t);
+ } else if (mode & TPL_FD) {
+ fd = va_arg(ap,int);
+ } else {
+ tpl_hook.oops("unsupported tpl_load mode %d\n", mode);
+ return -1;
+ }
+ va_end(ap);
+
+ if (r->type != TPL_TYPE_ROOT) {
+ tpl_hook.oops("error: tpl_load to non-root node\n");
+ return -1;
+ }
+ if (((tpl_root_data*)(r->data))->flags & (TPL_WRONLY|TPL_RDONLY)) {
+ /* already packed or loaded, so reset it as if newly mapped */
+ tpl_free_keep_map(r);
+ }
+ if (mode & TPL_FILE) {
+ if (tpl_mmap_file(filename, &((tpl_root_data*)(r->data))->mmap) != 0) {
+ tpl_hook.oops("tpl_load failed for file %s\n", filename);
+ return -1;
+ }
+ if ( (rc = tpl_sanity(r, (mode & TPL_EXCESS_OK))) != 0) {
+ if (rc == ERR_FMT_MISMATCH) {
+ tpl_hook.oops("%s: format signature mismatch\n", filename);
+ } else if (rc == ERR_FLEN_MISMATCH) {
+ tpl_hook.oops("%s: array lengths mismatch\n", filename);
+ } else {
+ tpl_hook.oops("%s: not a valid tpl file\n", filename);
+ }
+ tpl_unmap_file( &((tpl_root_data*)(r->data))->mmap );
+ return -1;
+ }
+ ((tpl_root_data*)(r->data))->flags = (TPL_FILE | TPL_RDONLY);
+ } else if (mode & TPL_MEM) {
+ ((tpl_root_data*)(r->data))->mmap.text = addr;
+ ((tpl_root_data*)(r->data))->mmap.text_sz = sz;
+ if ( (rc = tpl_sanity(r, (mode & TPL_EXCESS_OK))) != 0) {
+ if (rc == ERR_FMT_MISMATCH) {
+ tpl_hook.oops("format signature mismatch\n");
+ } else {
+ tpl_hook.oops("not a valid tpl file\n");
+ }
+ return -1;
+ }
+ ((tpl_root_data*)(r->data))->flags = (TPL_MEM | TPL_RDONLY);
+ if (mode & TPL_UFREE) ((tpl_root_data*)(r->data))->flags |= TPL_UFREE;
+ } else if (mode & TPL_FD) {
+ /* if fd read succeeds, resulting mem img is used for load */
+ if (tpl_gather(TPL_GATHER_BLOCKING,fd,&addr,&sz) > 0) {
+ return tpl_load(r, TPL_MEM|TPL_UFREE, addr, sz);
+ } else return -1;
+ } else {
+ tpl_hook.oops("invalid tpl_load mode %d\n", mode);
+ return -1;
+ }
+ /* this applies to TPL_MEM or TPL_FILE */
+ if (tpl_needs_endian_swap(((tpl_root_data*)(r->data))->mmap.text))
+ ((tpl_root_data*)(r->data))->flags |= TPL_XENDIAN;
+ tpl_unpackA0(r); /* prepare root A nodes for use */
+ return 0;
+}
+
+TPL_API int tpl_Alen(tpl_node *r, int i) {
+ tpl_node *n;
+
+ n = tpl_find_i(r,i);
+ if (n == NULL) {
+ tpl_hook.oops("invalid index %d to tpl_unpack\n", i);
+ return -1;
+ }
+ if (n->type != TPL_TYPE_ARY) return -1;
+ return ((tpl_atyp*)(n->data))->num;
+}
+
+static void tpl_free_atyp(tpl_node *n, tpl_atyp *atyp) {
+ tpl_backbone *bb,*bbnxt;
+ tpl_node *c;
+ void *dv;
+ tpl_bin *binp;
+ tpl_atyp *atypp;
+ char *strp;
+ size_t itermax;
+ tpl_pound_data *pd;
+ int i;
+
+ bb = atyp->bb;
+ while (bb) {
+ bbnxt = bb->next;
+ dv = bb->data;
+ c=n->children;
+ while (c) {
+ switch (c->type) {
+ case TPL_TYPE_BYTE:
+ case TPL_TYPE_DOUBLE:
+ case TPL_TYPE_INT32:
+ case TPL_TYPE_UINT32:
+ case TPL_TYPE_INT64:
+ case TPL_TYPE_UINT64:
+ case TPL_TYPE_INT16:
+ case TPL_TYPE_UINT16:
+ dv = (void*)((uintptr_t)dv + tpl_types[c->type].sz*c->num);
+ break;
+ case TPL_TYPE_BIN:
+ memcpy(&binp,dv,sizeof(tpl_bin*)); /* cp to aligned */
+ if (binp->addr) tpl_hook.free( binp->addr ); /* free buf */
+ tpl_hook.free(binp); /* free tpl_bin */
+ dv = (void*)((uintptr_t)dv + sizeof(tpl_bin*));
+ break;
+ case TPL_TYPE_STR:
+ for(i=0; i < c->num; i++) {
+ memcpy(&strp,dv,sizeof(char*)); /* cp to aligned */
+ if (strp) tpl_hook.free(strp); /* free string */
+ dv = (void*)((uintptr_t)dv + sizeof(char*));
+ }
+ break;
+ case TPL_TYPE_POUND:
+ /* iterate over the preceding nodes */
+ itermax = c->num;
+ pd = (tpl_pound_data*)c->data;
+ if (++(pd->iternum) < itermax) {
+ c = pd->iter_start_node;
+ continue;
+ } else { /* loop complete. */
+ pd->iternum = 0;
+ }
+ break;
+ case TPL_TYPE_ARY:
+ memcpy(&atypp,dv,sizeof(tpl_atyp*)); /* cp to aligned */
+ tpl_free_atyp(c,atypp); /* free atyp */
+ dv = (void*)((uintptr_t)dv + sizeof(void*));
+ break;
+ default:
+ tpl_hook.fatal("unsupported format character\n");
+ break;
+ }
+ c=c->next;
+ }
+ tpl_hook.free(bb);
+ bb = bbnxt;
+ }
+ tpl_hook.free(atyp);
+}
+
+/* determine (by walking) byte length of serialized r/A node at address dv
+ * returns 0 on success, or -1 if the tpl isn't trustworthy (fails consistency)
+ */
+static int tpl_serlen(tpl_node *r, tpl_node *n, void *dv, size_t *serlen) {
+ uint32_t slen;
+ int num,fidx;
+ tpl_node *c;
+ size_t len=0, alen, buf_past, itermax;
+ tpl_pound_data *pd;
+
+ buf_past = ((uintptr_t)((tpl_root_data*)(r->data))->mmap.text +
+ ((tpl_root_data*)(r->data))->mmap.text_sz);
+
+ if (n->type == TPL_TYPE_ROOT) num = 1;
+ else if (n->type == TPL_TYPE_ARY) {
+ if ((uintptr_t)dv + sizeof(uint32_t) > buf_past) return -1;
+ memcpy(&num,dv,sizeof(uint32_t));
+ if (((tpl_root_data*)(r->data))->flags & TPL_XENDIAN)
+ tpl_byteswap(&num, sizeof(uint32_t));
+ dv = (void*)((uintptr_t)dv + sizeof(uint32_t));
+ len += sizeof(uint32_t);
+ } else tpl_hook.fatal("internal error in tpl_serlen\n");
+
+ while (num-- > 0) {
+ c=n->children;
+ while (c) {
+ switch (c->type) {
+ case TPL_TYPE_BYTE:
+ case TPL_TYPE_DOUBLE:
+ case TPL_TYPE_INT32:
+ case TPL_TYPE_UINT32:
+ case TPL_TYPE_INT64:
+ case TPL_TYPE_UINT64:
+ case TPL_TYPE_INT16:
+ case TPL_TYPE_UINT16:
+ for(fidx=0; fidx < c->num; fidx++) { /* octothorpe support */
+ if ((uintptr_t)dv + tpl_types[c->type].sz > buf_past) return -1;
+ dv = (void*)((uintptr_t)dv + tpl_types[c->type].sz);
+ len += tpl_types[c->type].sz;
+ }
+ break;
+ case TPL_TYPE_BIN:
+ len += sizeof(uint32_t);
+ if ((uintptr_t)dv + sizeof(uint32_t) > buf_past) return -1;
+ memcpy(&slen,dv,sizeof(uint32_t));
+ if (((tpl_root_data*)(r->data))->flags & TPL_XENDIAN)
+ tpl_byteswap(&slen, sizeof(uint32_t));
+ len += slen;
+ dv = (void*)((uintptr_t)dv + sizeof(uint32_t));
+ if ((uintptr_t)dv + slen > buf_past) return -1;
+ dv = (void*)((uintptr_t)dv + slen);
+ break;
+ case TPL_TYPE_STR:
+ for(fidx=0; fidx < c->num; fidx++) { /* octothorpe support */
+ len += sizeof(uint32_t);
+ if ((uintptr_t)dv + sizeof(uint32_t) > buf_past) return -1;
+ memcpy(&slen,dv,sizeof(uint32_t));
+ if (((tpl_root_data*)(r->data))->flags & TPL_XENDIAN)
+ tpl_byteswap(&slen, sizeof(uint32_t));
+ if (!(((tpl_root_data*)(r->data))->flags & TPL_OLD_STRING_FMT))
+ slen = (slen>1) ? (slen-1) : 0;
+ len += slen;
+ dv = (void*)((uintptr_t)dv + sizeof(uint32_t));
+ if ((uintptr_t)dv + slen > buf_past) return -1;
+ dv = (void*)((uintptr_t)dv + slen);
+ }
+ break;
+ case TPL_TYPE_ARY:
+ if ( tpl_serlen(r,c,dv, &alen) == -1) return -1;
+ dv = (void*)((uintptr_t)dv + alen);
+ len += alen;
+ break;
+ case TPL_TYPE_POUND:
+ /* iterate over the preceding nodes */
+ itermax = c->num;
+ pd = (tpl_pound_data*)c->data;
+ if (++(pd->iternum) < itermax) {
+ c = pd->iter_start_node;
+ continue;
+ } else { /* loop complete. */
+ pd->iternum = 0;
+ }
+ break;
+ default:
+ tpl_hook.fatal("unsupported format character\n");
+ break;
+ }
+ c=c->next;
+ }
+ }
+ *serlen = len;
+ return 0;
+}
+
+static int tpl_mmap_output_file(char *filename, size_t sz, void **text_out) {
+ void *text;
+ int fd,perms;
+
+#ifndef _WIN32
+ perms = S_IRUSR|S_IWUSR|S_IWGRP|S_IRGRP|S_IROTH; /* ug+w o+r */
+ fd=open(filename,O_CREAT|O_TRUNC|O_RDWR,perms);
+#else
+ perms = _S_IWRITE;
+ fd=_open(filename,_O_CREAT|_O_TRUNC|_O_RDWR,perms);
+#endif
+
+ if ( fd == -1 ) {
+ tpl_hook.oops("Couldn't open file %s: %s\n", filename, strerror(errno));
+ return -1;
+ }
+
+ text = mmap(0, sz, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
+ if (text == MAP_FAILED) {
+ tpl_hook.oops("Failed to mmap %s: %s\n", filename, strerror(errno));
+ close(fd);
+ return -1;
+ }
+ if (ftruncate(fd,sz) == -1) {
+ tpl_hook.oops("ftruncate failed: %s\n", strerror(errno));
+ munmap( text, sz );
+ close(fd);
+ return -1;
+ }
+ *text_out = text;
+ return fd;
+}
+
+static int tpl_mmap_file(char *filename, tpl_mmap_rec *mr) {
+ struct stat stat_buf;
+
+ if ( (mr->fd = open(filename, O_RDONLY)) == -1 ) {
+ tpl_hook.oops("Couldn't open file %s: %s\n", filename, strerror(errno));
+ return -1;
+ }
+
+ if ( fstat(mr->fd, &stat_buf) == -1) {
+ close(mr->fd);
+ tpl_hook.oops("Couldn't stat file %s: %s\n", filename, strerror(errno));
+ return -1;
+ }
+
+ mr->text_sz = (size_t)stat_buf.st_size;
+ mr->text = mmap(0, stat_buf.st_size, PROT_READ, MAP_PRIVATE, mr->fd, 0);
+ if (mr->text == MAP_FAILED) {
+ close(mr->fd);
+ tpl_hook.oops("Failed to mmap %s: %s\n", filename, strerror(errno));
+ return -1;
+ }
+
+ return 0;
+}
+
+TPL_API int tpl_pack(tpl_node *r, int i) {
+ tpl_node *n, *child, *np;
+ void *datav=NULL;
+ size_t sz, itermax;
+ uint32_t slen;
+ char *str;
+ tpl_bin *bin;
+ tpl_pound_data *pd;
+ int fidx;
+
+ n = tpl_find_i(r,i);
+ if (n == NULL) {
+ tpl_hook.oops("invalid index %d to tpl_pack\n", i);
+ return -1;
+ }
+
+ if (((tpl_root_data*)(r->data))->flags & TPL_RDONLY) {
+ /* convert to an writeable tpl, initially empty */
+ tpl_free_keep_map(r);
+ }
+
+ ((tpl_root_data*)(r->data))->flags |= TPL_WRONLY;
+
+ if (n->type == TPL_TYPE_ARY) datav = tpl_extend_backbone(n);
+ child = n->children;
+ while(child) {
+ switch(child->type) {
+ case TPL_TYPE_BYTE:
+ case TPL_TYPE_DOUBLE:
+ case TPL_TYPE_INT32:
+ case TPL_TYPE_UINT32:
+ case TPL_TYPE_INT64:
+ case TPL_TYPE_UINT64:
+ case TPL_TYPE_INT16:
+ case TPL_TYPE_UINT16:
+ /* no need to use fidx iteration here; we can copy multiple values in one memcpy */
+ memcpy(child->data,child->addr,tpl_types[child->type].sz * child->num);
+ if (datav) datav = tpl_cpv(datav,child->data,tpl_types[child->type].sz * child->num);
+ if (n->type == TPL_TYPE_ARY) n->ser_osz += tpl_types[child->type].sz * child->num;
+ break;
+ case TPL_TYPE_BIN:
+ /* copy the buffer to be packed */
+ slen = ((tpl_bin*)child->addr)->sz;
+ if (slen >0) {
+ str = tpl_hook.malloc(slen);
+ if (!str) fatal_oom();
+ memcpy(str,((tpl_bin*)child->addr)->addr,slen);
+ } else str = NULL;
+ /* and make a tpl_bin to point to it */
+ bin = tpl_hook.malloc(sizeof(tpl_bin));
+ if (!bin) fatal_oom();
+ bin->addr = str;
+ bin->sz = slen;
+ /* now pack its pointer, first deep freeing any pre-existing bin */
+ if (*(tpl_bin**)(child->data) != NULL) {
+ if ((*(tpl_bin**)(child->data))->sz != 0) {
+ tpl_hook.free( (*(tpl_bin**)(child->data))->addr );
+ }
+ tpl_hook.free(*(tpl_bin**)(child->data));
+ }
+ memcpy(child->data,&bin,sizeof(tpl_bin*));
+ if (datav) {
+ datav = tpl_cpv(datav, &bin, sizeof(tpl_bin*));
+ *(tpl_bin**)(child->data) = NULL;
+ }
+ if (n->type == TPL_TYPE_ARY) {
+ n->ser_osz += sizeof(uint32_t); /* binary buf len word */
+ n->ser_osz += bin->sz; /* binary buf */
+ }
+ break;
+ case TPL_TYPE_STR:
+ for(fidx=0; fidx < child->num; fidx++) {
+ /* copy the string to be packed. slen includes \0. this
+ block also works if the string pointer is NULL. */
+ char *caddr = ((char**)child->addr)[fidx];
+ char **cdata = &((char**)child->data)[fidx];
+ slen = caddr ? (strlen(caddr) + 1) : 0;
+ if (slen) {
+ str = tpl_hook.malloc(slen);
+ if (!str) fatal_oom();
+ memcpy(str,caddr,slen); /* include \0 */
+ } else {
+ str = NULL;
+ }
+ /* now pack its pointer, first freeing any pre-existing string */
+ if (*cdata != NULL) {
+ tpl_hook.free(*cdata);
+ }
+ memcpy(cdata,&str,sizeof(char*));
+ if (datav) {
+ datav = tpl_cpv(datav, &str, sizeof(char*));
+ *cdata = NULL;
+ }
+ if (n->type == TPL_TYPE_ARY) {
+ n->ser_osz += sizeof(uint32_t); /* string len word */
+ if (slen>1) n->ser_osz += slen-1;/* string (without nul) */
+ }
+ }
+ break;
+ case TPL_TYPE_ARY:
+ /* copy the child's tpl_atype* and reset it to empty */
+ if (datav) {
+ sz = ((tpl_atyp*)(child->data))->sz;
+ datav = tpl_cpv(datav, &child->data, sizeof(void*));
+ child->data = tpl_hook.malloc(sizeof(tpl_atyp));
+ if (!child->data) fatal_oom();
+ ((tpl_atyp*)(child->data))->num = 0;
+ ((tpl_atyp*)(child->data))->sz = sz;
+ ((tpl_atyp*)(child->data))->bb = NULL;
+ ((tpl_atyp*)(child->data))->bbtail = NULL;
+ }
+ /* parent is array? then bubble up child array's ser_osz */
+ if (n->type == TPL_TYPE_ARY) {
+ n->ser_osz += sizeof(uint32_t); /* array len word */
+ n->ser_osz += child->ser_osz; /* child array ser_osz */
+ child->ser_osz = 0; /* reset child array ser_osz */
+ }
+ break;
+
+ case TPL_TYPE_POUND:
+ /* we need to iterate n times over preceding nodes in S(...).
+ * we may be in the midst of an iteration each time or starting. */
+ pd = (tpl_pound_data*)child->data;
+ itermax = child->num;
+
+ /* itermax is total num of iterations needed */
+ /* pd->iternum is current iteration index */
+ /* pd->inter_elt_len is element-to-element len of contiguous structs */
+ /* pd->iter_start_node is where we jump to at each iteration. */
+
+ if (++(pd->iternum) < itermax) {
+
+ /* in start or midst of loop. advance addr/data pointers. */
+ for(np=pd->iter_start_node; np != child; np = np->next) {
+ np->data = (char*)(np->data) +
+ (tpl_types[np->type].sz * np->num);
+ np->addr = (char*)(np->addr) + pd->inter_elt_len;
+ }
+ /* do next iteration */
+ child = pd->iter_start_node;
+ continue;
+
+ } else { /* loop complete. */
+
+ /* reset iteration index and addr/data pointers. */
+ pd->iternum = 0;
+ for(np=pd->iter_start_node; np != child; np = np->next) {
+ np->data = (char*)(np->data) - ((itermax-1) *
+ tpl_types[np->type].sz *
+ np->num);
+ np->addr = (char*)(np->addr) - ((itermax-1) * pd->inter_elt_len);
+ }
+
+ }
+ break;
+ default:
+ tpl_hook.fatal("unsupported format character\n");
+ break;
+ }
+ child=child->next;
+ }
+ return 0;
+}
+
+TPL_API int tpl_unpack(tpl_node *r, int i) {
+ tpl_node *n, *c, *np;
+ uint32_t slen;
+ int rc=1, fidx;
+ char *str;
+ void *dv=NULL, *caddr;
+ size_t A_bytes, itermax;
+ tpl_pound_data *pd;
+ void *img;
+ size_t sz;
+
+
+ /* handle unusual case of tpl_pack,tpl_unpack without an
+ * intervening tpl_dump. do a dump/load implicitly. */
+ if (((tpl_root_data*)(r->data))->flags & TPL_WRONLY) {
+ if (tpl_dump(r,TPL_MEM,&img,&sz) != 0) return -1;
+ if (tpl_load(r,TPL_MEM|TPL_UFREE,img,sz) != 0) {
+ tpl_hook.free(img);
+ return -1;
+ };
+ }
+
+ n = tpl_find_i(r,i);
+ if (n == NULL) {
+ tpl_hook.oops("invalid index %d to tpl_unpack\n", i);
+ return -1;
+ }
+
+ /* either root node or an A node */
+ if (n->type == TPL_TYPE_ROOT) {
+ dv = tpl_find_data_start( ((tpl_root_data*)(n->data))->mmap.text );
+ } else if (n->type == TPL_TYPE_ARY) {
+ if (((tpl_atyp*)(n->data))->num <= 0) return 0; /* array consumed */
+ else rc = ((tpl_atyp*)(n->data))->num--;
+ dv = ((tpl_atyp*)(n->data))->cur;
+ if (!dv) tpl_hook.fatal("must unpack parent of node before node itself\n");
+ }
+
+ c = n->children;
+ while (c) {
+ switch (c->type) {
+ case TPL_TYPE_BYTE:
+ case TPL_TYPE_DOUBLE:
+ case TPL_TYPE_INT32:
+ case TPL_TYPE_UINT32:
+ case TPL_TYPE_INT64:
+ case TPL_TYPE_UINT64:
+ case TPL_TYPE_INT16:
+ case TPL_TYPE_UINT16:
+ /* unpack elements of cross-endian octothorpic array individually */
+ if (((tpl_root_data*)(r->data))->flags & TPL_XENDIAN) {
+ for(fidx=0; fidx < c->num; fidx++) {
+ caddr = (void*)((uintptr_t)c->addr + (fidx * tpl_types[c->type].sz));
+ memcpy(caddr,dv,tpl_types[c->type].sz);
+ tpl_byteswap(caddr, tpl_types[c->type].sz);
+ dv = (void*)((uintptr_t)dv + tpl_types[c->type].sz);
+ }
+ } else {
+ /* bulk unpack ok if not cross-endian */
+ memcpy(c->addr, dv, tpl_types[c->type].sz * c->num);
+ dv = (void*)((uintptr_t)dv + tpl_types[c->type].sz * c->num);
+ }
+ break;
+ case TPL_TYPE_BIN:
+ memcpy(&slen,dv,sizeof(uint32_t));
+ if (((tpl_root_data*)(r->data))->flags & TPL_XENDIAN)
+ tpl_byteswap(&slen, sizeof(uint32_t));
+ if (slen > 0) {
+ str = (char*)tpl_hook.malloc(slen);
+ if (!str) fatal_oom();
+ } else str=NULL;
+ dv = (void*)((uintptr_t)dv + sizeof(uint32_t));
+ if (slen>0) memcpy(str,dv,slen);
+ memcpy(&(((tpl_bin*)c->addr)->addr),&str,sizeof(void*));
+ memcpy(&(((tpl_bin*)c->addr)->sz),&slen,sizeof(uint32_t));
+ dv = (void*)((uintptr_t)dv + slen);
+ break;
+ case TPL_TYPE_STR:
+ for(fidx=0; fidx < c->num; fidx++) {
+ memcpy(&slen,dv,sizeof(uint32_t));
+ if (((tpl_root_data*)(r->data))->flags & TPL_XENDIAN)
+ tpl_byteswap(&slen, sizeof(uint32_t));
+ if (((tpl_root_data*)(r->data))->flags & TPL_OLD_STRING_FMT)
+ slen += 1;
+ dv = (void*)((uintptr_t)dv + sizeof(uint32_t));
+ if (slen) { /* slen includes \0 */
+ str = (char*)tpl_hook.malloc(slen);
+ if (!str) fatal_oom();
+ if (slen>1) memcpy(str,dv,slen-1);
+ str[slen-1] = '\0'; /* nul terminate */
+ dv = (void*)((uintptr_t)dv + slen-1);
+ } else str=NULL;
+ memcpy(&((char**)c->addr)[fidx],&str,sizeof(char*));
+ }
+ break;
+ case TPL_TYPE_POUND:
+ /* iterate over preceding nodes */
+ pd = (tpl_pound_data*)c->data;
+ itermax = c->num;
+ if (++(pd->iternum) < itermax) {
+ /* in start or midst of loop. advance addr/data pointers. */
+ for(np=pd->iter_start_node; np != c; np = np->next) {
+ np->addr = (char*)(np->addr) + pd->inter_elt_len;
+ }
+ /* do next iteration */
+ c = pd->iter_start_node;
+ continue;
+
+ } else { /* loop complete. */
+
+ /* reset iteration index and addr/data pointers. */
+ pd->iternum = 0;
+ for(np=pd->iter_start_node; np != c; np = np->next) {
+ np->addr = (char*)(np->addr) - ((itermax-1) * pd->inter_elt_len);
+ }
+
+ }
+ break;
+ case TPL_TYPE_ARY:
+ if (tpl_serlen(r,c,dv, &A_bytes) == -1)
+ tpl_hook.fatal("internal error in unpack\n");
+ memcpy( &((tpl_atyp*)(c->data))->num, dv, sizeof(uint32_t));
+ if (((tpl_root_data*)(r->data))->flags & TPL_XENDIAN)
+ tpl_byteswap(&((tpl_atyp*)(c->data))->num, sizeof(uint32_t));
+ ((tpl_atyp*)(c->data))->cur = (void*)((uintptr_t)dv+sizeof(uint32_t));
+ dv = (void*)((uintptr_t)dv + A_bytes);
+ break;
+ default:
+ tpl_hook.fatal("unsupported format character\n");
+ break;
+ }
+
+ c = c->next;
+ }
+ if (n->type == TPL_TYPE_ARY) ((tpl_atyp*)(n->data))->cur = dv; /* next element */
+ return rc;
+}
+
+/* Specialized function that unpacks only the root's A nodes, after tpl_load */
+static int tpl_unpackA0(tpl_node *r) {
+ tpl_node *n, *c;
+ uint32_t slen;
+ int rc=1,fidx,i;
+ void *dv;
+ size_t A_bytes, itermax;
+ tpl_pound_data *pd;
+
+ n = r;
+ dv = tpl_find_data_start( ((tpl_root_data*)(r->data))->mmap.text);
+
+ c=n->children;
+ while (c) {
+ switch (c->type) {
+ case TPL_TYPE_BYTE:
+ case TPL_TYPE_DOUBLE:
+ case TPL_TYPE_INT32:
+ case TPL_TYPE_UINT32:
+ case TPL_TYPE_INT64:
+ case TPL_TYPE_UINT64:
+ case TPL_TYPE_INT16:
+ case TPL_TYPE_UINT16:
+ for(fidx=0;fidx < c->num; fidx++) {
+ dv = (void*)((uintptr_t)dv + tpl_types[c->type].sz);
+ }
+ break;
+ case TPL_TYPE_BIN:
+ memcpy(&slen,dv,sizeof(uint32_t));
+ if (((tpl_root_data*)(r->data))->flags & TPL_XENDIAN)
+ tpl_byteswap(&slen, sizeof(uint32_t));
+ dv = (void*)((uintptr_t)dv + sizeof(uint32_t));
+ dv = (void*)((uintptr_t)dv + slen);
+ break;
+ case TPL_TYPE_STR:
+ for(i=0; i<c->num; i++) {
+ memcpy(&slen,dv,sizeof(uint32_t));
+ if (((tpl_root_data*)(r->data))->flags & TPL_XENDIAN)
+ tpl_byteswap(&slen, sizeof(uint32_t));
+ if (((tpl_root_data*)(r->data))->flags & TPL_OLD_STRING_FMT)
+ slen += 1;
+ dv = (void*)((uintptr_t)dv + sizeof(uint32_t));
+ if (slen>1) dv = (void*)((uintptr_t)dv + slen-1);
+ }
+ break;
+ case TPL_TYPE_POUND:
+ /* iterate over the preceding nodes */
+ itermax = c->num;
+ pd = (tpl_pound_data*)c->data;
+ if (++(pd->iternum) < itermax) {
+ c = pd->iter_start_node;
+ continue;
+ } else { /* loop complete. */
+ pd->iternum = 0;
+ }
+ break;
+ case TPL_TYPE_ARY:
+ if ( tpl_serlen(r,c,dv, &A_bytes) == -1)
+ tpl_hook.fatal("internal error in unpackA0\n");
+ memcpy( &((tpl_atyp*)(c->data))->num, dv, sizeof(uint32_t));
+ if (((tpl_root_data*)(r->data))->flags & TPL_XENDIAN)
+ tpl_byteswap(&((tpl_atyp*)(c->data))->num, sizeof(uint32_t));
+ ((tpl_atyp*)(c->data))->cur = (void*)((uintptr_t)dv+sizeof(uint32_t));
+ dv = (void*)((uintptr_t)dv + A_bytes);
+ break;
+ default:
+ tpl_hook.fatal("unsupported format character\n");
+ break;
+ }
+ c=c->next;
+ }
+ return rc;
+}
+
+/* In-place byte order swapping of a word of length "len" bytes */
+static void tpl_byteswap(void *word, int len) {
+ int i;
+ char c, *w;
+ w = (char*)word;
+ for(i=0; i<len/2; i++) {
+ c = w[i];
+ w[i] = w[len-1-i];
+ w[len-1-i] = c;
+ }
+}
+
+static void tpl_fatal(char *fmt, ...) {
+ va_list ap;
+ char exit_msg[100];
+
+ va_start(ap,fmt);
+ vsnprintf(exit_msg, 100, fmt, ap);
+ va_end(ap);
+
+ tpl_hook.oops("%s", exit_msg);
+ exit(-1);
+}
+
+TPL_API int tpl_gather(int mode, ...) {
+ va_list ap;
+ int fd,rc=0;
+ size_t *szp,sz;
+ void **img,*addr,*data;
+ tpl_gather_t **gs;
+ tpl_gather_cb *cb;
+
+ va_start(ap,mode);
+ switch (mode) {
+ case TPL_GATHER_BLOCKING:
+ fd = va_arg(ap,int);
+ img = va_arg(ap,void*);
+ szp = va_arg(ap,size_t*);
+ rc = tpl_gather_blocking(fd,img,szp);
+ break;
+ case TPL_GATHER_NONBLOCKING:
+ fd = va_arg(ap,int);
+ gs = (tpl_gather_t**)va_arg(ap,void*);
+ cb = (tpl_gather_cb*)va_arg(ap,tpl_gather_cb*);
+ data = va_arg(ap,void*);
+ rc = tpl_gather_nonblocking(fd,gs,cb,data);
+ break;
+ case TPL_GATHER_MEM:
+ addr = va_arg(ap,void*);
+ sz = va_arg(ap,size_t);
+ gs = (tpl_gather_t**)va_arg(ap,void*);
+ cb = (tpl_gather_cb*)va_arg(ap,tpl_gather_cb*);
+ data = va_arg(ap,void*);
+ rc = tpl_gather_mem(addr,sz,gs,cb,data);
+ break;
+ default:
+ tpl_hook.fatal("unsupported tpl_gather mode %d\n",mode);
+ break;
+ }
+ va_end(ap);
+ return rc;
+}
+
+/* dequeue a tpl by reading until one full tpl image is obtained.
+ * We take care not to read past the end of the tpl.
+ * This is intended as a blocking call i.e. for use with a blocking fd.
+ * It can be given a non-blocking fd, but the read spins if we have to wait.
+ */
+static int tpl_gather_blocking(int fd, void **img, size_t *sz) {
+ char preamble[8];
+ int i=0, rc;
+ uint32_t tpllen;
+
+ do {
+ rc = read(fd,&preamble[i],8-i);
+ i += (rc>0) ? rc : 0;
+ } while ((rc==-1 && (errno==EINTR||errno==EAGAIN)) || (rc>0 && i<8));
+
+ if (rc<0) {
+ tpl_hook.oops("tpl_gather_fd_blocking failed: %s\n", strerror(errno));
+ return -1;
+ } else if (rc == 0) {
+ /* tpl_hook.oops("tpl_gather_fd_blocking: eof\n"); */
+ return 0;
+ } else if (i != 8) {
+ tpl_hook.oops("internal error\n");
+ return -1;
+ }
+
+ if (preamble[0] == 't' && preamble[1] == 'p' && preamble[2] == 'l') {
+ memcpy(&tpllen,&preamble[4],4);
+ if (tpl_needs_endian_swap(preamble)) tpl_byteswap(&tpllen,4);
+ } else {
+ tpl_hook.oops("tpl_gather_fd_blocking: non-tpl input\n");
+ return -1;
+ }
+
+ /* malloc space for remainder of tpl image (overall length tpllen)
+ * and read it in
+ */
+ if (tpl_hook.gather_max > 0 &&
+ tpllen > tpl_hook.gather_max) {
+ tpl_hook.oops("tpl exceeds max length %d\n",
+ tpl_hook.gather_max);
+ return -2;
+ }
+ *sz = tpllen;
+ if ( (*img = tpl_hook.malloc(tpllen)) == NULL) {
+ fatal_oom();
+ }
+
+ memcpy(*img,preamble,8); /* copy preamble to output buffer */
+ i=8;
+ do {
+ rc = read(fd,&((*(char**)img)[i]),tpllen-i);
+ i += (rc>0) ? rc : 0;
+ } while ((rc==-1 && (errno==EINTR||errno==EAGAIN)) || (rc>0 && i<tpllen));
+
+ if (rc<0) {
+ tpl_hook.oops("tpl_gather_fd_blocking failed: %s\n", strerror(errno));
+ tpl_hook.free(*img);
+ return -1;
+ } else if (rc == 0) {
+ /* tpl_hook.oops("tpl_gather_fd_blocking: eof\n"); */
+ tpl_hook.free(*img);
+ return 0;
+ } else if (i != tpllen) {
+ tpl_hook.oops("internal error\n");
+ tpl_hook.free(*img);
+ return -1;
+ }
+
+ return 1;
+}
+
+/* Used by select()-driven apps which want to gather tpl images piecemeal */
+/* the file descriptor must be non-blocking for this functino to work. */
+static int tpl_gather_nonblocking( int fd, tpl_gather_t **gs, tpl_gather_cb *cb, void *data) {
+ char buf[TPL_GATHER_BUFLEN], *img, *tpl;
+ int rc, keep_looping, cbrc=0;
+ size_t catlen;
+ uint32_t tpllen;
+
+ while (1) {
+ rc = read(fd,buf,TPL_GATHER_BUFLEN);
+ if (rc == -1) {
+ if (errno == EINTR) continue; /* got signal during read, ignore */
+ if (errno == EAGAIN) return 1; /* nothing to read right now */
+ else {
+ tpl_hook.oops("tpl_gather failed: %s\n", strerror(errno));
+ if (*gs) {
+ tpl_hook.free((*gs)->img);
+ tpl_hook.free(*gs);
+ *gs = NULL;
+ }
+ return -1; /* error, caller should close fd */
+ }
+ } else if (rc == 0) {
+ if (*gs) {
+ tpl_hook.oops("tpl_gather: partial tpl image precedes EOF\n");
+ tpl_hook.free((*gs)->img);
+ tpl_hook.free(*gs);
+ *gs = NULL;
+ }
+ return 0; /* EOF, caller should close fd */
+ } else {
+ /* concatenate any partial tpl from last read with new buffer */
+ if (*gs) {
+ catlen = (*gs)->len + rc;
+ if (tpl_hook.gather_max > 0 &&
+ catlen > tpl_hook.gather_max) {
+ tpl_hook.free( (*gs)->img );
+ tpl_hook.free( (*gs) );
+ *gs = NULL;
+ tpl_hook.oops("tpl exceeds max length %d\n",
+ tpl_hook.gather_max);
+ return -2; /* error, caller should close fd */
+ }
+ if ( (img = tpl_hook.realloc((*gs)->img, catlen)) == NULL) {
+ fatal_oom();
+ }
+ memcpy(img + (*gs)->len, buf, rc);
+ tpl_hook.free(*gs);
+ *gs = NULL;
+ } else {
+ img = buf;
+ catlen = rc;
+ }
+ /* isolate any full tpl(s) in img and invoke cb for each */
+ tpl = img;
+ keep_looping = (tpl+8 < img+catlen) ? 1 : 0;
+ while (keep_looping) {
+ if (strncmp("tpl", tpl, 3) != 0) {
+ tpl_hook.oops("tpl prefix invalid\n");
+ if (img != buf) tpl_hook.free(img);
+ tpl_hook.free(*gs);
+ *gs = NULL;
+ return -3; /* error, caller should close fd */
+ }
+ memcpy(&tpllen,&tpl[4],4);
+ if (tpl_needs_endian_swap(tpl)) tpl_byteswap(&tpllen,4);
+ if (tpl+tpllen <= img+catlen) {
+ cbrc = (cb)(tpl,tpllen,data); /* invoke cb for tpl image */
+ tpl += tpllen; /* point to next tpl image */
+ if (cbrc < 0) keep_looping = 0;
+ else keep_looping = (tpl+8 < img+catlen) ? 1 : 0;
+ } else keep_looping=0;
+ }
+ /* check if app callback requested closure of tpl source */
+ if (cbrc < 0) {
+ tpl_hook.oops("tpl_fd_gather aborted by app callback\n");
+ if (img != buf) tpl_hook.free(img);
+ if (*gs) tpl_hook.free(*gs);
+ *gs = NULL;
+ return -4;
+ }
+ /* store any leftover, partial tpl fragment for next read */
+ if (tpl == img && img != buf) {
+ /* consumed nothing from img!=buf */
+ if ( (*gs = tpl_hook.malloc(sizeof(tpl_gather_t))) == NULL ) {
+ fatal_oom();
+ }
+ (*gs)->img = tpl;
+ (*gs)->len = catlen;
+ } else if (tpl < img+catlen) {
+ /* consumed 1+ tpl(s) from img!=buf or 0 from img==buf */
+ if ( (*gs = tpl_hook.malloc(sizeof(tpl_gather_t))) == NULL ) {
+ fatal_oom();
+ }
+ if ( ((*gs)->img = tpl_hook.malloc(img+catlen - tpl)) == NULL ) {
+ fatal_oom();
+ }
+ (*gs)->len = img+catlen - tpl;
+ memcpy( (*gs)->img, tpl, img+catlen - tpl);
+ /* free partially consumed concat buffer if used */
+ if (img != buf) tpl_hook.free(img);
+ } else { /* tpl(s) fully consumed */
+ /* free consumed concat buffer if used */
+ if (img != buf) tpl_hook.free(img);
+ }
+ }
+ }
+}
+
+/* gather tpl piecemeal from memory buffer (not fd) e.g., from a lower-level api */
+static int tpl_gather_mem( char *buf, size_t len, tpl_gather_t **gs, tpl_gather_cb *cb, void *data) {
+ char *img, *tpl;
+ int keep_looping, cbrc=0;
+ size_t catlen;
+ uint32_t tpllen;
+
+ /* concatenate any partial tpl from last read with new buffer */
+ if (*gs) {
+ catlen = (*gs)->len + len;
+ if (tpl_hook.gather_max > 0 &&
+ catlen > tpl_hook.gather_max) {
+ tpl_hook.free( (*gs)->img );
+ tpl_hook.free( (*gs) );
+ *gs = NULL;
+ tpl_hook.oops("tpl exceeds max length %d\n",
+ tpl_hook.gather_max);
+ return -2; /* error, caller should stop accepting input from source*/
+ }
+ if ( (img = tpl_hook.realloc((*gs)->img, catlen)) == NULL) {
+ fatal_oom();
+ }
+ memcpy(img + (*gs)->len, buf, len);
+ tpl_hook.free(*gs);
+ *gs = NULL;
+ } else {
+ img = buf;
+ catlen = len;
+ }
+ /* isolate any full tpl(s) in img and invoke cb for each */
+ tpl = img;
+ keep_looping = (tpl+8 < img+catlen) ? 1 : 0;
+ while (keep_looping) {
+ if (strncmp("tpl", tpl, 3) != 0) {
+ tpl_hook.oops("tpl prefix invalid\n");
+ if (img != buf) tpl_hook.free(img);
+ tpl_hook.free(*gs);
+ *gs = NULL;
+ return -3; /* error, caller should stop accepting input from source*/
+ }
+ memcpy(&tpllen,&tpl[4],4);
+ if (tpl_needs_endian_swap(tpl)) tpl_byteswap(&tpllen,4);
+ if (tpl+tpllen <= img+catlen) {
+ cbrc = (cb)(tpl,tpllen,data); /* invoke cb for tpl image */
+ tpl += tpllen; /* point to next tpl image */
+ if (cbrc < 0) keep_looping = 0;
+ else keep_looping = (tpl+8 < img+catlen) ? 1 : 0;
+ } else keep_looping=0;
+ }
+ /* check if app callback requested closure of tpl source */
+ if (cbrc < 0) {
+ tpl_hook.oops("tpl_mem_gather aborted by app callback\n");
+ if (img != buf) tpl_hook.free(img);
+ if (*gs) tpl_hook.free(*gs);
+ *gs = NULL;
+ return -4;
+ }
+ /* store any leftover, partial tpl fragment for next read */
+ if (tpl == img && img != buf) {
+ /* consumed nothing from img!=buf */
+ if ( (*gs = tpl_hook.malloc(sizeof(tpl_gather_t))) == NULL ) {
+ fatal_oom();
+ }
+ (*gs)->img = tpl;
+ (*gs)->len = catlen;
+ } else if (tpl < img+catlen) {
+ /* consumed 1+ tpl(s) from img!=buf or 0 from img==buf */
+ if ( (*gs = tpl_hook.malloc(sizeof(tpl_gather_t))) == NULL ) {
+ fatal_oom();
+ }
+ if ( ((*gs)->img = tpl_hook.malloc(img+catlen - tpl)) == NULL ) {
+ fatal_oom();
+ }
+ (*gs)->len = img+catlen - tpl;
+ memcpy( (*gs)->img, tpl, img+catlen - tpl);
+ /* free partially consumed concat buffer if used */
+ if (img != buf) tpl_hook.free(img);
+ } else { /* tpl(s) fully consumed */
+ /* free consumed concat buffer if used */
+ if (img != buf) tpl_hook.free(img);
+ }
+ return 1;
+}